From bff2fbdfda25eb57dab169f28d48f1621beb981b Mon Sep 17 00:00:00 2001 From: 张晓波 <bingbo1993@126.com> Date: 星期五, 13 十月 2023 08:49:49 +0800 Subject: [PATCH] 删除大屏 mq --- hd/pipe/StaffManage/src/main/java/com/thhy/staff/utils/MqUtils.java | 52 +++++++++++++ hd/pipe/StaffManage/pom.xml | 6 + hd/pipe/StaffManage/src/main/java/com/thhy/staff/modules/biz/face/entity/UserFaceVo.java | 25 ++++++ hd/pipe/StaffManage/src/main/java/com/thhy/staff/modules/biz/face/service/impl/FaceServerImpl.java | 71 +++++++++++++++++ hd/pipe/StaffManage/src/main/resources/mapping/PlatUserMapper.xml | 25 ++++++ hd/pipe/StaffManage/src/main/java/com/thhy/staff/modules/biz/face/controller/FaceController.java | 28 +++++++ hd/pipe/StaffManage/src/main/java/com/thhy/staff/modules/biz/face/entity/FaceResult.java | 6 + hd/pipe/StaffManage/src/main/java/com/thhy/staff/modules/biz/face/service/FaceServer.java | 7 + hd/pipe/StaffManage/src/main/java/com/thhy/staff/modules/biz/platuser/mapper/PlatUserMapper.java | 9 ++ 9 files changed, 229 insertions(+), 0 deletions(-) diff --git a/hd/pipe/StaffManage/pom.xml b/hd/pipe/StaffManage/pom.xml index 82f5be1..8eb8a9a 100644 --- a/hd/pipe/StaffManage/pom.xml +++ b/hd/pipe/StaffManage/pom.xml @@ -82,6 +82,12 @@ <groupId>org.apache.rocketmq</groupId> <artifactId>rocketmq-spring-boot-starter</artifactId> </dependency> + + <dependency> + <groupId>org.eclipse.paho</groupId> + <artifactId>org.eclipse.paho.client.mqttv3</artifactId> + <version>1.2.2</version> + </dependency> </dependencies> <repositories> diff --git a/hd/pipe/StaffManage/src/main/java/com/thhy/staff/modules/biz/face/controller/FaceController.java b/hd/pipe/StaffManage/src/main/java/com/thhy/staff/modules/biz/face/controller/FaceController.java index c37c313..fe93497 100644 --- a/hd/pipe/StaffManage/src/main/java/com/thhy/staff/modules/biz/face/controller/FaceController.java +++ b/hd/pipe/StaffManage/src/main/java/com/thhy/staff/modules/biz/face/controller/FaceController.java @@ -1,7 +1,9 @@ package com.thhy.staff.modules.biz.face.controller; +import com.alibaba.fastjson.JSONObject; import com.thhy.general.common.BasicResult; import com.thhy.staff.modules.biz.face.entity.FaceResult; +import com.thhy.staff.modules.biz.face.service.FaceDeviceService; import com.thhy.staff.modules.biz.face.service.FaceServer; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestBody; @@ -15,9 +17,35 @@ @Autowired private FaceServer faceServer; + @Autowired + private FaceDeviceService deviceService; + @RequestMapping("/device/login") public FaceResult login(@RequestBody String mess){ FaceResult faceResult = faceServer.login(mess); return faceResult; } + + + @RequestMapping("/syncPerson") + public JSONObject syncPerson(@RequestBody String mess){ + JSONObject jsonObject = faceServer.syncPerson(mess); + return jsonObject; + } + + @RequestMapping("/syncPersonSingle") + public JSONObject syncPersonSingle(@RequestBody String mess){ + JSONObject jsonObject = faceServer.syncPersonSingle(mess); + return jsonObject; + } + + @RequestMapping("/sp/notify") + public JSONObject personNotify(@RequestBody String mess){ + faceServer.personNotify(mess); + JSONObject jsonObject = new JSONObject(); + jsonObject.put("code",0); + jsonObject.put("msg","OK"); + jsonObject.put("success",true); + return jsonObject; + } } diff --git a/hd/pipe/StaffManage/src/main/java/com/thhy/staff/modules/biz/face/entity/FaceResult.java b/hd/pipe/StaffManage/src/main/java/com/thhy/staff/modules/biz/face/entity/FaceResult.java index 7c1f1e2..480f63d 100644 --- a/hd/pipe/StaffManage/src/main/java/com/thhy/staff/modules/biz/face/entity/FaceResult.java +++ b/hd/pipe/StaffManage/src/main/java/com/thhy/staff/modules/biz/face/entity/FaceResult.java @@ -39,4 +39,10 @@ this.mqinfo.put("willContent",faceDevice.getDevSno()+"-offline"); this.token = UUIDUtils.create(); } + + public FaceResult(boolean success){ + this.success = success; + this.code = 0; + this.msg = "OK"; + } } diff --git a/hd/pipe/StaffManage/src/main/java/com/thhy/staff/modules/biz/face/entity/UserFaceVo.java b/hd/pipe/StaffManage/src/main/java/com/thhy/staff/modules/biz/face/entity/UserFaceVo.java new file mode 100644 index 0000000..f16b14b --- /dev/null +++ b/hd/pipe/StaffManage/src/main/java/com/thhy/staff/modules/biz/face/entity/UserFaceVo.java @@ -0,0 +1,25 @@ +package com.thhy.staff.modules.biz.face.entity; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.annotation.JSONField; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +@Data +public class UserFaceVo implements Serializable { + + @JSONField(name = "person_id") + private String userId; + + @JSONField(name = "person_name") + private String realName; + + @JSONField(name = "person_type") + private String personType = "4"; + + private int sex; + + private String templateImgUrl; +} diff --git a/hd/pipe/StaffManage/src/main/java/com/thhy/staff/modules/biz/face/service/FaceServer.java b/hd/pipe/StaffManage/src/main/java/com/thhy/staff/modules/biz/face/service/FaceServer.java index 0bb4b41..78a0f91 100644 --- a/hd/pipe/StaffManage/src/main/java/com/thhy/staff/modules/biz/face/service/FaceServer.java +++ b/hd/pipe/StaffManage/src/main/java/com/thhy/staff/modules/biz/face/service/FaceServer.java @@ -1,8 +1,15 @@ package com.thhy.staff.modules.biz.face.service; +import com.alibaba.fastjson.JSONObject; import com.thhy.staff.modules.biz.face.entity.FaceResult; public interface FaceServer { FaceResult login(String mess); + + JSONObject syncPerson(String mess); + + JSONObject syncPersonSingle(String mess); + + void personNotify(String mess); } diff --git a/hd/pipe/StaffManage/src/main/java/com/thhy/staff/modules/biz/face/service/impl/FaceServerImpl.java b/hd/pipe/StaffManage/src/main/java/com/thhy/staff/modules/biz/face/service/impl/FaceServerImpl.java index 2a02292..98cf8ac 100644 --- a/hd/pipe/StaffManage/src/main/java/com/thhy/staff/modules/biz/face/service/impl/FaceServerImpl.java +++ b/hd/pipe/StaffManage/src/main/java/com/thhy/staff/modules/biz/face/service/impl/FaceServerImpl.java @@ -1,24 +1,34 @@ package com.thhy.staff.modules.biz.face.service.impl; import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import com.alibaba.nacos.api.utils.StringUtils; import com.thhy.general.utils.DeepCopyUtils; import com.thhy.staff.config.EmqxConfig; import com.thhy.staff.config.EmqxProperties; import com.thhy.staff.modules.biz.face.entity.FaceDevice; import com.thhy.staff.modules.biz.face.entity.FaceResult; +import com.thhy.staff.modules.biz.face.entity.UserFaceVo; import com.thhy.staff.modules.biz.face.mapper.FaceDeviceMapper; import com.thhy.staff.modules.biz.face.service.FaceServer; +import com.thhy.staff.modules.biz.platuser.mapper.PlatUserMapper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; @Service public class FaceServerImpl implements FaceServer { @Autowired private FaceDeviceMapper faceDeviceMapper; + + @Autowired + private PlatUserMapper userMapper; @Autowired private EmqxConfig emqxConfig; @@ -40,4 +50,65 @@ FaceResult faceResult = new FaceResult(true,faceDevice,emqxConfig.toString()); return faceResult; } + + @Override + public JSONObject syncPerson(String mess) { + JSONObject reqJson = JSONObject.parseObject(mess); + JSONObject paramJson = reqJson.getJSONObject("path_params"); + + List<UserFaceVo> faceVoList = userMapper.queryUserFace(paramJson.getIntValue("offset"),paramJson.getIntValue("limit")); + + JSONObject jsonObject = new JSONObject(); + jsonObject.put("code",0); + jsonObject.put("msg","OK"); + jsonObject.put("success",true); + jsonObject.put("offset",paramJson.getIntValue("offset")+paramJson.getIntValue("limit")); + jsonObject.put("person_list",faceVoList); + return jsonObject; + } + + @Override + public JSONObject syncPersonSingle(String mess) { + JSONObject reqJson = JSONObject.parseObject(mess); + JSONObject paramJson = reqJson.getJSONObject("path_params"); + JSONArray userIdArray = paramJson.getJSONArray("person_list"); + String userId = userIdArray.getString(0); + + UserFaceVo userFaceVo = userMapper.queryUserFaceSingle(userId); + + JSONObject jsonObject = new JSONObject(); + jsonObject.put("code",0); + jsonObject.put("msg","OK"); + jsonObject.put("success",true); + jsonObject.put("offset",0); + List<UserFaceVo> faceVoList = new ArrayList<>(); + faceVoList.add(userFaceVo); + jsonObject.put("person_list",faceVoList); + return jsonObject; + } + + @Override + public void personNotify(String mess) { + JSONObject reqJson = JSONObject.parseObject(mess); + if(reqJson.containsKey("success")&&reqJson.getBooleanValue("success")){ + String userIds = reqJson.getString("successful"); + if(!StringUtils.isEmpty(userIds)){ + String[] userIdArray = new String[]{userIds}; + if(userIds.contains(",")){ + userIdArray = userIds.split(","); + } + userMapper.syncResult(1,userIdArray); + } + JSONArray failJsonArray = reqJson.getJSONArray("failed"); + if(failJsonArray.size()>0){ + for(Object obj : failJsonArray){ + JSONObject failUserInfo = JSON.parseObject(obj.toString()); + String userId = failUserInfo.getString("person_id"); + JSONArray failInfoArray = failUserInfo.getJSONArray("info"); + String failReason = failInfoArray.getJSONObject(0).getString("reason"); + userMapper.syncFail(userId,failReason); + } + } + } + } } diff --git a/hd/pipe/StaffManage/src/main/java/com/thhy/staff/modules/biz/platuser/mapper/PlatUserMapper.java b/hd/pipe/StaffManage/src/main/java/com/thhy/staff/modules/biz/platuser/mapper/PlatUserMapper.java index 63d930f..1111e32 100644 --- a/hd/pipe/StaffManage/src/main/java/com/thhy/staff/modules/biz/platuser/mapper/PlatUserMapper.java +++ b/hd/pipe/StaffManage/src/main/java/com/thhy/staff/modules/biz/platuser/mapper/PlatUserMapper.java @@ -2,6 +2,7 @@ import com.thhy.general.config.SysUserInfo; import com.thhy.staff.modules.biz.depart.entity.OtherUser; +import com.thhy.staff.modules.biz.face.entity.UserFaceVo; import com.thhy.staff.modules.biz.group.entity.GroupUser; import com.thhy.staff.modules.biz.platuser.entity.*; import org.apache.ibatis.annotations.Param; @@ -104,4 +105,12 @@ int countFaceRecordByGroup(String groupId); PlatUserFace queryFaceUserByJobNum(String jobNum); + + List<UserFaceVo> queryUserFace(@Param("offset") int offset,@Param("limit") int limit); + + UserFaceVo queryUserFaceSingle(String userId); + + void syncResult(@Param("syncSuccess") int syncSuccess,@Param("userIdArray")String[] userIdArray); + + void syncFail(@Param("user_id") String userId,@Param("syncFailReason")String syncFailReason); } diff --git a/hd/pipe/StaffManage/src/main/java/com/thhy/staff/utils/MqUtils.java b/hd/pipe/StaffManage/src/main/java/com/thhy/staff/utils/MqUtils.java new file mode 100644 index 0000000..31f6ae0 --- /dev/null +++ b/hd/pipe/StaffManage/src/main/java/com/thhy/staff/utils/MqUtils.java @@ -0,0 +1,52 @@ +package com.thhy.staff.utils; + +import com.thhy.general.utils.UUIDUtils; +import com.thhy.staff.config.EmqxConfig; +import org.eclipse.paho.client.mqttv3.MqttClient; +import org.eclipse.paho.client.mqttv3.MqttConnectOptions; +import org.eclipse.paho.client.mqttv3.MqttException; +import org.eclipse.paho.client.mqttv3.MqttMessage; +import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence; + +public class MqUtils { + + public static void createClient(EmqxConfig emqxConfig){ + String broker = "tcp://"+emqxConfig.getHost()+":"+emqxConfig.getPort(); + String clientId = UUIDUtils.create(); + MemoryPersistence persistence = new MemoryPersistence(); + + try { + MqttClient client = new MqttClient(broker, clientId, persistence); + + // MQTT 连接选项 + MqttConnectOptions connOpts = new MqttConnectOptions(); + connOpts.setUserName(emqxConfig.getUsername()); + connOpts.setPassword(emqxConfig.getPassword().toCharArray()); + // 保留会话 + connOpts.setCleanSession(true); + + // 设置回调 + //client.setCallback(new OnMessageCallback()); + + // 建立连接 + System.out.println("Connecting to broker: " + broker); + client.connect(connOpts); + + System.out.println("Connected"); + //System.out.println("Publishing message: " + content); + + // 订阅 + //client.subscribe(subTopic); + + // 消息发布所需参数 + /* MqttMessage message = new MqttMessage(content.getBytes()); + message.setQos(qos); + client.publish(pubTopic, message); + System.out.println("Message published");*/ + + client.disconnect(); + } catch (MqttException e) { + throw new RuntimeException(e); + } + } +} diff --git a/hd/pipe/StaffManage/src/main/resources/mapping/PlatUserMapper.xml b/hd/pipe/StaffManage/src/main/resources/mapping/PlatUserMapper.xml index 8ff8540..bca8d0f 100644 --- a/hd/pipe/StaffManage/src/main/resources/mapping/PlatUserMapper.xml +++ b/hd/pipe/StaffManage/src/main/resources/mapping/PlatUserMapper.xml @@ -888,4 +888,29 @@ where spu.job_num = #{jobNum} </select> + <select id="queryUserFace" resultType="com.thhy.staff.modules.biz.face.entity.UserFaceVo"> + select user_id as userId,real_name as realName,sex,photo as templateImgUrl + from sys_plat_user spu + limit #{offset},#{limit} + </select> + + <select id="queryUserFaceSingle" resultType="com.thhy.staff.modules.biz.face.entity.UserFaceVo"> + select user_id as userId,real_name as realName,sex,photo as templateImgUrl + from sys_plat_user spu + where user_id = #{userId} + </select> + + <update id="syncResult"> + update sys_plat_user set sync_success = #{syncSuccess} + <where> + <foreach item="item" index="index" collection="userIdArray" open="user_id in (" separator="," close=")"> + #{item} + </foreach> + </where> + </update> + + <update id="syncFail"> + update sys_plat_user set sync_success = 2,sync_fail_reason = #{syncFailReason} where user_id = #{userId} + </update> + </mapper> -- Gitblit v1.9.3