张晓波
2023-10-13 bff2fbdfda25eb57dab169f28d48f1621beb981b
删除大屏 mq
已修改7个文件
已添加2个文件
229 ■■■■■ 文件已修改
hd/pipe/StaffManage/pom.xml 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
hd/pipe/StaffManage/src/main/java/com/thhy/staff/modules/biz/face/controller/FaceController.java 28 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
hd/pipe/StaffManage/src/main/java/com/thhy/staff/modules/biz/face/entity/FaceResult.java 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
hd/pipe/StaffManage/src/main/java/com/thhy/staff/modules/biz/face/entity/UserFaceVo.java 25 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
hd/pipe/StaffManage/src/main/java/com/thhy/staff/modules/biz/face/service/FaceServer.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
hd/pipe/StaffManage/src/main/java/com/thhy/staff/modules/biz/face/service/impl/FaceServerImpl.java 71 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
hd/pipe/StaffManage/src/main/java/com/thhy/staff/modules/biz/platuser/mapper/PlatUserMapper.java 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
hd/pipe/StaffManage/src/main/java/com/thhy/staff/utils/MqUtils.java 52 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
hd/pipe/StaffManage/src/main/resources/mapping/PlatUserMapper.xml 25 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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>
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;
    }
}
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";
    }
}
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;
}
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);
}
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);
                }
            }
        }
    }
}
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);
}
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);
        }
    }
}
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>