zouxuan 5 лет назад
Родитель
Сommit
4cf377489c

+ 4 - 0
edu-user/edu-user-server/pom.xml

@@ -20,6 +20,10 @@
 			<groupId>org.springframework.cloud</groupId>
 			<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
 		</dependency>
+		<dependency>
+			<groupId>org.springframework.boot</groupId>
+			<artifactId>spring-boot-starter-websocket</artifactId>
+		</dependency>
 
 		<dependency>
 			<groupId>org.springframework.cloud</groupId>

+ 14 - 0
edu-user/edu-user-server/src/main/java/com/keao/edu/user/config/WebSocketConfig.java

@@ -0,0 +1,14 @@
+package com.keao.edu.user.config;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.socket.server.standard.ServerEndpointExporter;
+
+@Configuration
+public class WebSocketConfig {
+
+    @Bean
+    public ServerEndpointExporter serverEndpointExporter () {
+        return new ServerEndpointExporter();
+    }
+}

+ 1 - 2
edu-user/edu-user-server/src/main/java/com/keao/edu/user/controller/SysConfigController.java

@@ -40,8 +40,7 @@ public class SysConfigController extends BaseController {
 		Map<String,Object> params = new HashMap<String, Object>();
 		params.put("group", group);
 		params.put("tenantId", tenantId);
-		List<SysConfig> configs = sysConfigService.findAll(params);
-		return succeed(configs);
+		return succeed(sysConfigService.findAll(params));
 	}
 
 	@ApiOperation(value = "修改参数")

+ 2 - 2
edu-user/edu-user-server/src/main/java/com/keao/edu/user/controller/TeacherController.java

@@ -34,9 +34,9 @@ public class TeacherController extends BaseController {
 	@GetMapping(value = "list")
     @PreAuthorize("@pcs.hasPermissions('teacher/list')")
 	public HttpResponseResult<PageInfo<Teacher>> list(TeacherQueryInfo queryInfo) {
-		if(queryInfo.getOrganId() != null){
+		/*if(queryInfo.getOrganId() != null){
 			queryInfo.setOrganIds(organizationService.getChildOrganIds(queryInfo.getOrganId(),true));
-		}
+		}*/
 		return succeed(teacherService.queryTeacherPage(queryInfo));
 	}
 

+ 44 - 0
edu-user/edu-user-server/src/main/java/com/keao/edu/user/controller/WebSocketController.java

@@ -0,0 +1,44 @@
+package com.keao.edu.user.controller;
+
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.io.IOException;
+
+@RestController
+@RequestMapping("/api/ws")
+public class WebSocketController {
+
+    /**
+     * 群发消息内容
+     * @param message
+     * @return
+     */
+    @RequestMapping(value="/sendAll", method= RequestMethod.GET)
+    public String sendAllMessage(@RequestParam(required=true) String message){
+        try {
+            WebSocketServer.BroadCastInfo(message);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        return "ok";
+    }
+
+    /**
+     * 指定会话ID发消息
+     * @param message 消息内容
+     * @param id 连接会话ID
+     * @return
+     */
+    @RequestMapping(value="/sendOne", method=RequestMethod.GET)
+    public String sendOneMessage(@RequestParam(required=true) String message,@RequestParam(required=true) String id){
+        try {
+            WebSocketServer.SendMessage(message,id);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        return "ok";
+    }
+}

+ 122 - 0
edu-user/edu-user-server/src/main/java/com/keao/edu/user/controller/WebSocketServer.java

@@ -0,0 +1,122 @@
+package com.keao.edu.user.controller;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.PostConstruct;
+import javax.websocket.*;
+import javax.websocket.server.ServerEndpoint;
+import java.io.IOException;
+import java.util.concurrent.CopyOnWriteArraySet;
+import java.util.concurrent.atomic.AtomicInteger;
+
+@ServerEndpoint(value = "/ws/asset")
+@Component
+public class WebSocketServer {
+
+    @PostConstruct
+    public void init() {
+        System.out.println("websocket 加载");
+    }
+    private static Logger log = LoggerFactory.getLogger(WebSocketServer.class);
+    private static final AtomicInteger OnlineCount = new AtomicInteger(0);
+    // concurrent包的线程安全Set,用来存放每个客户端对应的Session对象。
+    private static CopyOnWriteArraySet<Session> SessionSet = new CopyOnWriteArraySet<Session>();
+
+
+    /**
+     * 连接建立成功调用的方法
+     */
+    @OnOpen
+    public void onOpen(Session session) {
+        SessionSet.add(session);
+        int cnt = OnlineCount.incrementAndGet(); // 在线数加1
+        log.info("有连接加入,当前连接数为:{}", cnt);
+        SendMessage(session, "连接成功");
+    }
+
+    /**
+     * 连接关闭调用的方法
+     */
+    @OnClose
+    public void onClose(Session session) {
+        SessionSet.remove(session);
+        int cnt = OnlineCount.decrementAndGet();
+        log.info("有连接关闭,当前连接数为:{}", cnt);
+    }
+
+    /**
+     * 收到客户端消息后调用的方法
+     *
+     * @param message
+     *            客户端发送过来的消息
+     */
+    @OnMessage
+    public void onMessage(String message, Session session) {
+        log.info("来自客户端的消息:{}",message);
+        SendMessage(session, "收到消息,消息内容:"+message);
+
+    }
+
+    /**
+     * 出现错误
+     * @param session
+     * @param error
+     */
+    @OnError
+    public void onError(Session session, Throwable error) {
+        log.error("发生错误:{},Session ID: {}",error.getMessage(),session.getId());
+        error.printStackTrace();
+    }
+
+    /**
+     * 发送消息,实践表明,每次浏览器刷新,session会发生变化。
+     * @param session
+     * @param message
+     */
+    public static void SendMessage(Session session, String message) {
+        try {
+            session.getBasicRemote().sendText(String.format("%s (From Server,Session ID=%s)",message,session.getId()));
+        } catch (IOException e) {
+            log.error("发送消息出错:{}", e.getMessage());
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * 群发消息
+     * @param message
+     * @throws IOException
+     */
+    public static void BroadCastInfo(String message) throws IOException {
+        for (Session session : SessionSet) {
+            if(session.isOpen()){
+                SendMessage(session, message);
+            }
+        }
+    }
+
+    /**
+     * 指定Session发送消息
+     * @param sessionId
+     * @param message
+     * @throws IOException
+     */
+    public static void SendMessage(String message,String sessionId) throws IOException {
+        Session session = null;
+        for (Session s : SessionSet) {
+            if(s.getId().equals(sessionId)){
+                session = s;
+                break;
+            }
+        }
+        if(session!=null){
+            SendMessage(session, message);
+        }
+        else{
+            log.warn("没有找到你指定ID的会话:{}",sessionId);
+        }
+    }
+
+}

+ 1 - 8
edu-user/edu-user-server/src/main/resources/config/mybatis/ExamLocationMapper.xml

@@ -12,7 +12,6 @@
 		<result column="contact_name_" property="contactName" />
 		<result column="contact_phone_" property="contactPhone" />
 		<result column="address_" property="address" />
-		<result column="is_available_" property="isAvailable" />
 		<result column="create_time_" property="createTime" />
 		<result column="update_time_" property="updateTime" />
 		<result column="tenant_id_" property="tenantId" />
@@ -44,9 +43,6 @@
 			<if test="isAvailable != null">
 				is_available_ = #{isAvailable},
 			</if>
-			<if test="id != null">
-				id_ = #{id},
-			</if>
 			<if test="contactPhone != null">
 				contact_phone_ = #{contactPhone},
 			</if>
@@ -59,9 +55,6 @@
 			<if test="delFlag!=null">
 				del_flag_=#{delFlag},
 			</if>
-			<if test="createTime != null">
-				create_time_ = #{createTime},
-			</if>
 			<if test="tenantId != null">
 				tenant_id_ = #{tenantId},
 			</if>
@@ -83,7 +76,7 @@
 			<if test="search!=null">
 				AND (id_=#{search} OR name_ LIKE CONCAT('%', #{serch}, '%'))
 			</if>
-			<if test="tenantId != null and tenantId != 0">
+			<if test="tenantId != null">
 				AND tenant_id_ = #{tenantId}
 			</if>
 		</where>

+ 1 - 1
edu-user/edu-user-server/src/main/resources/config/mybatis/ExamSongMapper.xml

@@ -76,7 +76,7 @@
 	<sql id="queryCondition">
 		<where>
 			es.del_flag_ = 0
-			<if test="tenantId != null and tenantId != 0">
+			<if test="tenantId != null">
 				AND es.tenant_id_ = #{tenantId}
 			</if>
 			<if test="subjectList!=null">

+ 1 - 1
edu-user/edu-user-server/src/main/resources/config/mybatis/MusicTheoryMapper.xml

@@ -68,7 +68,7 @@
 
 	<sql id="queryCondition">
 		<where>
-			<if test="tenantId != null and tenantId != 0">
+			<if test="tenantId != null">
 				tenant_id_ = #{tenantId}
 			</if>
 		</where>

+ 1 - 1
edu-user/edu-user-server/src/main/resources/config/mybatis/SubjectMapper.xml

@@ -108,7 +108,7 @@
 
     <sql id="querySubPageSql">
         <where>
-            <if test="tenantId != null and tenantId != 0">
+            <if test="tenantId != null">
                 AND s.tenant_id_ = #{tenantId}
             </if>
             <if test="parentId != null">

+ 2 - 5
edu-user/edu-user-server/src/main/resources/config/mybatis/TeacherMapper.xml

@@ -97,11 +97,8 @@
 			<if test="tenantId != null and tenantId != 0">
 				AND t.tenant_id_ = #{tenantId}
 			</if>
-			<if test="organIds != null">
-				AND t.organ_id_ IN
-				<foreach collection="organIds" item="organId" separator="," open="(" close=")">
-					#{organId}
-				</foreach>
+			<if test="organId != null">
+				AND t.organ_id_ = #{organId}
 			</if>
 			<if test="settlementType != null and settlementType != ''">
 				AND t.salary_settlement_type_ = #{settlementType}