diff --git a/client/pom.xml b/client/pom.xml
index 8a917b2..412e8d8 100644
--- a/client/pom.xml
+++ b/client/pom.xml
@@ -10,10 +10,25 @@
4.0.0
client
+ 客户端
17
17
+
+
+ com.canvas.web
+ common
+ 1.0-SNAPSHOT
+
+
+
+ com.canvas.web
+ system
+ 1.0-SNAPSHOT
+
+
+
\ No newline at end of file
diff --git a/client/src/main/java/com/canvas/web/modules/front/rest/FrontController.java b/client/src/main/java/com/canvas/web/modules/front/rest/FrontController.java
new file mode 100644
index 0000000..261664c
--- /dev/null
+++ b/client/src/main/java/com/canvas/web/modules/front/rest/FrontController.java
@@ -0,0 +1,16 @@
+package com.canvas.web.modules.front.rest;
+
+import io.swagger.annotations.Api;
+import lombok.RequiredArgsConstructor;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+@RequiredArgsConstructor
+@Api(tags = "画屏客户端")
+@RequestMapping("/api/front")
+public class FrontController {
+
+
+
+}
diff --git a/client/src/main/java/com/canvas/web/modules/front/rest/WebSocket.java b/client/src/main/java/com/canvas/web/modules/front/rest/WebSocket.java
new file mode 100644
index 0000000..bc433e5
--- /dev/null
+++ b/client/src/main/java/com/canvas/web/modules/front/rest/WebSocket.java
@@ -0,0 +1,172 @@
+package com.canvas.web.modules.front.rest;
+
+import com.canvas.web.modules.device.service.DeviceService;
+import org.springframework.stereotype.Component;
+
+import javax.websocket.*;
+import javax.websocket.server.PathParam;
+import javax.websocket.server.ServerEndpoint;
+import java.io.IOException;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.concurrent.ConcurrentHashMap;
+
+@ServerEndpoint("/websocket/{deviceId}")
+@Component
+public class WebSocket {
+
+ private DeviceService deviceService;
+
+ //静态变量,用来记录当前在线连接数。应该把它设计成线程安全的。
+ private static int onlineCount = 0;
+ //concurrent包的线程安全Set,用来存放每个客户端对应的MyWebSocket对象。若要实现服务端与单一客户端通信的话,可以使用Map来存放,其中Key可以为用户标识
+ private static ConcurrentHashMap webSocketSet = new ConcurrentHashMap();
+ //与某个客户端的连接会话,需要通过它来给客户端发送数据
+ private Session session;
+
+ //当前发消息的设备编号
+ private String deviceId = "";
+
+ public static WebSocket getWebSocket(String id) {
+ return webSocketSet.get(id);
+ }
+
+ /**
+ * 连接建立成功调用的方法
+ *
+ * @param session 可选的参数。session为与某个客户端的连接会话,需要通过它来给客户端发送数据
+ */
+ @OnOpen
+ public void onOpen(@PathParam(value = "deviceId") String param, Session session, EndpointConfig config) {
+ System.out.println(param);
+ deviceId = param;//接收到发送消息的设备编号
+ this.session = session;
+ webSocketSet.put(param, this);//加入map中
+ addOnlineCount(); //在线数加1
+ deviceService.updateState(deviceId,1);
+ System.out.println("有新连接加入!当前在线人数为" + getOnlineCount());
+ }
+
+ /**
+ * 连接关闭调用的方法
+ */
+ @OnClose
+ public void onClose() {
+ if (!deviceId.equals("")) {
+ webSocketSet.remove(deviceId); //从set中删除
+ subOnlineCount(); //在线数减1
+ deviceService.updateState(deviceId,2);
+ System.out.println("有一连接关闭!当前在线人数为" + getOnlineCount());
+ }
+ }
+
+ /**
+ * 收到客户端消息后调用的方法
+ *
+ * @param message 客户端发送过来的消息
+ */
+ @OnMessage
+ public void onMessage(String message) {
+ System.out.println("来自客户端的消息:" + message);
+// session.get
+ //群发消息
+ if (1 != 1) {
+ sendAll(message);
+ } else {
+ //给指定的人发消息
+ sendToUser(message);
+ }
+ }
+
+ /**
+ * 给指定的人发送消息
+ *
+ * @param message
+ */
+ private void sendToUser(String message) {
+ String sendUserno = message.split("[|]")[1];
+ String sendMessage = message.split("[|]")[0];
+ String now = getNowTime();
+ try {
+ if (webSocketSet.get(sendUserno) != null) {
+ webSocketSet.get(sendUserno).sendMessage(now + "用户" + deviceId + "发来消息:" + "
" + sendMessage);
+ } else {
+ System.out.println("当前用户不在线");
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * 给所有人发消息
+ *
+ * @param message
+ */
+ private void sendAll(String message) {
+ String now = getNowTime();
+ String sendMessage = message.split("[|]")[0];
+ //遍历HashMap
+ for (String key : webSocketSet.keySet()) {
+ try {
+ //判断接收用户是否是当前发消息的用户
+ if (!deviceId.equals(key)) {
+ webSocketSet.get(key).sendMessage(now + "用户" + deviceId + "发来消息:" + "
" + sendMessage);
+ System.out.println("key = " + key);
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ /**
+ * 获取当前时间
+ *
+ * @return
+ */
+ private String getNowTime() {
+ Date date = new Date();
+ DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ String time = format.format(date);
+ return time;
+ }
+
+ /**
+ * 发生错误时调用
+ *
+ * @param session
+ * @param error
+ */
+ @OnError
+ public void onError(Session session, Throwable error) {
+ System.out.println("发生错误");
+ error.printStackTrace();
+ }
+
+ /**
+ * 这个方法与上面几个方法不一样。没有用注解,是根据自己需要添加的方法。
+ *
+ * @param message
+ * @throws IOException
+ */
+ public void sendMessage(String message) throws IOException {
+ this.session.getBasicRemote().sendText(message);
+ //this.session.getAsyncRemote().sendText(message);
+ }
+
+
+ public static synchronized int getOnlineCount() {
+ return onlineCount;
+ }
+
+ public static synchronized void addOnlineCount() {
+ WebSocket.onlineCount++;
+ }
+
+ public static synchronized void subOnlineCount() {
+ WebSocket.onlineCount--;
+ }
+
+}
diff --git a/common/src/main/java/com/canvas/web/base/BaseEntity.java b/common/src/main/java/com/canvas/web/base/BaseEntity.java
index 95c584a..6cc0cc1 100644
--- a/common/src/main/java/com/canvas/web/base/BaseEntity.java
+++ b/common/src/main/java/com/canvas/web/base/BaseEntity.java
@@ -1,5 +1,7 @@
package com.canvas.web.base;
+import com.alibaba.fastjson.annotation.JSONField;
+import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
@@ -27,21 +29,29 @@ public class BaseEntity implements Serializable {
@CreatedBy
@Column(name = "create_by", updatable = false)
@ApiModelProperty(value = "创建人", hidden = true)
+ @JSONField(name="createBy")
+ @JsonProperty("create_by")
private String createBy;
@LastModifiedBy
@Column(name = "update_by")
@ApiModelProperty(value = "更新人", hidden = true)
+ @JSONField(name="updatedBy")
+ @JsonProperty("update_by")
private String updatedBy;
@CreationTimestamp
@Column(name = "create_time", updatable = false)
@ApiModelProperty(value = "创建时间", hidden = true)
+ @JSONField(name="createTime")
+ @JsonProperty("create_time")
private Timestamp createTime;
@UpdateTimestamp
@Column(name = "update_time")
@ApiModelProperty(value = "更新时间", hidden = true)
+ @JSONField(name="updateTime")
+ @JsonProperty("update_time")
private Timestamp updateTime;
/* 分组校验 */
diff --git a/system/src/main/java/com/canvas/web/modules/device/domain/Device.java b/system/src/main/java/com/canvas/web/modules/device/domain/Device.java
index 723993d..748e3a0 100644
--- a/system/src/main/java/com/canvas/web/modules/device/domain/Device.java
+++ b/system/src/main/java/com/canvas/web/modules/device/domain/Device.java
@@ -39,7 +39,7 @@ public class Device extends BaseEntity implements Serializable {
@Column(name = "orga_id")
@ApiModelProperty(value = "机构id")
- public String orgaId;
+ public Long orgaId;
@Column(name = "open_setting")
@ApiModelProperty(value = "开机设置 1.每天 2.每周")
diff --git a/system/src/main/java/com/canvas/web/modules/device/dto/DeviceDTO.java b/system/src/main/java/com/canvas/web/modules/device/dto/DeviceDTO.java
index 57ce204..ffc69a4 100644
--- a/system/src/main/java/com/canvas/web/modules/device/dto/DeviceDTO.java
+++ b/system/src/main/java/com/canvas/web/modules/device/dto/DeviceDTO.java
@@ -29,5 +29,5 @@ public class DeviceDTO implements Serializable {
@JSONField(name="orga_id")
@JsonProperty("orga_id")
- private String orgaId;
+ private Long orgaId;
}
diff --git a/system/src/main/java/com/canvas/web/modules/device/repository/DeviceRepository.java b/system/src/main/java/com/canvas/web/modules/device/repository/DeviceRepository.java
index e2eb5c4..f471160 100644
--- a/system/src/main/java/com/canvas/web/modules/device/repository/DeviceRepository.java
+++ b/system/src/main/java/com/canvas/web/modules/device/repository/DeviceRepository.java
@@ -17,7 +17,7 @@ public interface DeviceRepository extends JpaRepository {
countQuery = "select count(1) " +
"from device d left join organization o on d.orga_id = o.id " +
"where if(?1 is null,1=1,d.id like %?1%) and if(?2 is null,1=1,d.device_name like %?2%) " +
- "and if(?3 is null,1=1,d.is_state = ?3)",
+ "and if(?3 is null,1=1,d.is_state = ?3) and if(?4 is null,1=1,d.orga_id = ?4)",
value="select d.id as deviceId,d.account deviceAccount,d.device_name as deviceName,d.device_direction as deviceDirection," +
"o.name as organName,d.open_setting as openSetting,d.open_weekly as openWeekly,d.open_time as openTime," +
"d.close_setting as closeSetting,d.close_weekly as closeWeekly,d.close_time as closeTime," +
@@ -25,8 +25,8 @@ public interface DeviceRepository extends JpaRepository {
"d.is_del as isDel " +
"from device d left join organization o on d.orga_id = o.id " +
"where if(?1 is null,1=1,d.id like %?1%) and if(?2 is null,1=1,d.device_name like %?2%) " +
- "and if(?3 is null,1=1,d.is_state = ?3)")
- Page