张晓波
2023-12-12 453e36702a81f459295d30841bab00010f9a6ae6
hd/pipe/StaffManage/src/main/java/com/thhy/staff/modules/biz/platuser/service/impl/PlatUserServiceImpl.java
@@ -9,33 +9,33 @@
import com.thhy.general.exception.BasicException;
import com.thhy.general.utils.ScreenMqUtils;
import com.thhy.general.utils.UserInfoUtils;
import com.thhy.staff.config.EmqxConfig;
import com.thhy.staff.config.FaceConfig;
import com.thhy.staff.modules.biz.applyhistory.entity.UserApplyHistory;
import com.thhy.staff.modules.biz.applyhistory.mapper.UserApplyHistoryMapper;
import com.thhy.staff.modules.biz.depart.entity.OtherUser;
import com.thhy.staff.modules.biz.face.entity.MqContent;
import com.thhy.staff.modules.biz.face.mapper.FaceDeviceMapper;
import com.thhy.staff.modules.biz.group.entity.GroupUser;
import com.thhy.staff.modules.biz.netty.NettyServerHandler;
import com.thhy.staff.modules.biz.platuser.controller.FaceServer;
import com.thhy.staff.modules.biz.platuser.entity.*;
import com.thhy.staff.modules.biz.platuser.mapper.PlatUserMapper;
import com.thhy.staff.modules.biz.platuser.service.PlatUserService;
import com.thhy.staff.modules.biz.platuser.service.SysUserService;
import com.thhy.staff.modules.biz.position.mapper.PositionMapper;
import com.thhy.staff.utils.MqUtils;
import com.thhy.staff.utils.ProcessFlag;
import com.thhy.staff.utils.StaffNoUtils;
import io.netty.channel.ChannelHandlerContext;
import net.bytebuddy.build.Plugin;
import org.checkerframework.checker.units.qual.A;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletRequest;
import javax.websocket.Session;
import java.io.IOException;
import java.io.Serializable;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.CopyOnWriteArraySet;
@@ -53,16 +53,19 @@
    private PlatUserMapper platUserMapper;
    @Autowired
    private SysUserService sysUserService;
    @Autowired
    private UserApplyHistoryMapper historyMapper;
    @Autowired
    private PositionMapper positionMapper;
    private ScreenMqUtils screenMqUtils;
    @Autowired
    private ScreenMqUtils screenMqUtils;
    private FaceDeviceMapper faceDeviceMapper;
    @Autowired
    private EmqxConfig emqxConfig;
    @Autowired
    private FaceConfig faceConfig;
    public PlatUser get(Serializable id){
        return platUserMapper.queryById(id);
@@ -387,6 +390,25 @@
        platUserMapper.updateFace(faceDto);
        if(faceDto.getSyncToDevice()==1){
            //下发
            List<String> sns = faceDeviceMapper.queryDevSn();
            MqContent mqContent = new MqContent("sync_person", faceConfig.getUrlPrefix()+faceConfig.getNotify());
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("path",faceConfig.getUrlPrefix()+faceConfig.getSinglePer());
            JSONObject pathParamJson = new JSONObject();
            pathParamJson.put("dev_sno","");
            pathParamJson.put("limit",10);
            pathParamJson.put("offset",0);
            pathParamJson.put("total",1);
            List<String> userIds = new ArrayList<>();
            userIds.add(faceDto.getUserId());
            pathParamJson.put("person_list",userIds);
            pathParamJson.put("person_type","4");
            jsonObject.put("path_params",pathParamJson);
            mqContent.setData(jsonObject);
            logger.info("下发人脸参数:"+JSON.toJSONString(mqContent));
            MqUtils.createClient(emqxConfig,sns,JSON.toJSONString(mqContent));
            /*Map<String,Object> map = AcsMain.addFace(fd.getJobNum(),filePrefix+"/"+fd.getPhoto());
            if(map.containsKey("code")){
                if(Integer.parseInt(map.get("code").toString())!=0){
@@ -409,7 +431,7 @@
                }
            });*/
            CopyOnWriteArraySet<ChannelHandlerContext> CTXS= NettyServerHandler.CTXS;
            /*CopyOnWriteArraySet<ChannelHandlerContext> CTXS= NettyServerHandler.CTXS;
            if(CTXS.size()<1){
                throw  new BasicException(new BasicMessage("99991","与门禁一体机失去链接"));
            }
@@ -425,59 +447,35 @@
                    ctx.flush();
                    logger.info("成功推送消息到局域网段");
                }
            });
            });*/
        }
    }
    @Override
    @Transactional
    public void delFace(FaceDto faceDto) {
        faceDto.setOp(2);
        String userIds = faceDto.getUserIds();
        if(StringUtils.isEmpty(userIds)){
            throw new BasicException(BasicStatus.ERROR);
        }
        List<String> sns = faceDeviceMapper.queryDevSn();
        String[] userIdArray = new String[]{userIds};
        if(userIds.contains(",")){
            userIdArray = userIds.split(",");
        }
        for(String userId : userIdArray){
            faceDto.setUserId(userId);
            faceDto.setSyncToDevice(2);
            platUserMapper.updateDelFace(faceDto);
            FaceDto fd = platUserMapper.queryJobNumByUserId(faceDto.getUserId());
            //删除下发
            /*FaceDto fd = platUserMapper.queryJobNumByUserId(userId);
            AcsMain.deleteFace(fd.getJobNum());*/
            /*CopyOnWriteArraySet<Session> SESSIONS = FaceServer.SESSIONS;
            if(SESSIONS.size()<1){
                throw  new BasicException(new BasicMessage("99991","与门禁一体机失去链接"));
            }
            SESSIONS.forEach(session ->{
                try {
                    if (session.isOpen()) {
                        faceDto.setPhoto(filePrefix+faceDto.getPhoto());
                        session.getBasicRemote().sendText(JSON.toJSONString(faceDto));
                        logger.info("成功推送消息到局域网段"+session.getId()+"___"+session.getRequestURI().getHost());
                    }
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            });*/
            CopyOnWriteArraySet<ChannelHandlerContext> CTXS= NettyServerHandler.CTXS;
            if(CTXS.size()<1){
                throw  new BasicException(new BasicMessage("99991","与门禁一体机失去链接"));
            }
            CTXS.forEach(ctx ->{
                if (!ctx.isRemoved()&&ctx.channel().isOpen()) {
                    faceDto.setJobNum(fd.getJobNum());
                    faceDto.setPhoto("https://pipe.thhy-tj.com/"+faceDto.getPhoto());
                    ctx.write(JSON.toJSONString(faceDto));
                    ctx.flush();
                    logger.info("删除人脸成功推送消息到局域网段");
                }
            });
        }
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("method","delete_person");
        jsonObject.put("notify",faceConfig.getUrlPrefix()+"deleteNotify");
        JSONObject userIdJSON = new JSONObject();
        userIdJSON.put("userIds",userIdArray);
        jsonObject.put("params",userIdJSON);
        JSONObject dataJson = new JSONObject();
        dataJson.put("person_list",userIdArray);
        dataJson.put("person_type","4");
        jsonObject.put("data",dataJson);
        String content = jsonObject.toJSONString();
        logger.info("删除指令打印"+content);
        MqUtils.createClient(emqxConfig,sns,content);
    }
    @Override
@@ -528,95 +526,25 @@
        platUserMapper.insertDoorLis(doorLis);
    }
    public static void main(String[] args) {
        String eventLog = "{\n" +
                "\t\"ipAddress\":\t\"192.168.1.12\",\n" +
                "\t\"ipv6Address\":\t\"240e:345:129e:cf00:e2ca:3cff:fef0:d933\",\n" +
                "\t\"portNo\":\t443,\n" +
                "\t\"protocol\":\t\"HTTPS\",\n" +
                "\t\"macAddress\":\t\"e0:ca:3c:f0:d9:33\",\n" +
                "\t\"channelID\":\t1,\n" +
                "\t\"dateTime\":\t\"2023-09-05T15:44:04+08:00\",\n" +
                "\t\"activePostCount\":\t1,\n" +
                "\t\"eventType\":\t\"AccessControllerEvent\",\n" +
                "\t\"eventState\":\t\"active\",\n" +
                "\t\"eventDescription\":\t\"Access Controller Event\",\n" +
                "\t\"AccessControllerEvent\":\t{\n" +
                "\t\t\"deviceName\":\t\"Access Controller\",\n" +
                "\t\t\"majorEventType\":\t5,\n" +
                "\t\t\"subEventType\":\t76,\n" +
                "\t\t\"cardReaderKind\":\t1,\n" +
                "\t\t\"cardReaderNo\":\t1,\n" +
                "\t\t\"verifyNo\":\t233,\n" +
                "\t\t\"serialNo\":\t437,\n" +
                "\t\t\"currentVerifyMode\":\t\"cardOrFace\",\n" +
                "\t\t\"frontSerialNo\":\t436,\n" +
                "\t\t\"attendanceStatus\":\t\"undefined\",\n" +
                "\t\t\"statusValue\":\t0,\n" +
                "\t\t\"mask\":\t\"no\",\n" +
                "\t\t\"helmet\":\t\"unknown\",\n" +
                "\t\t\"picturesNumber\":\t1,\n" +
                "\t\t\"purePwdVerifyEnable\":\ttrue,\n" +
                "\t\t\"FaceRect\":\t{\n" +
                "\t\t\t\"height\":\t0.116000,\n" +
                "\t\t\t\"width\":\t0.065000,\n" +
                "\t\t\t\"x\":\t0.546000,\n" +
                "\t\t\t\"y\":\t0.634000\n" +
                "\t\t}\n" +
                "\t}\n" +
                "}";
        JSONObject jsonObject = JSONObject.parseObject(eventLog);
        if(!jsonObject.containsKey("eventType")){
            //platUserMapper.addDoorHis(eventLog);
            return;
        }
        String eventType = jsonObject.getString("eventType");
        if(!"AccessControllerEvent".equals(eventType)){
            //platUserMapper.addDoorHis(eventLog);
            return;
        }
        JSONObject control = jsonObject.getJSONObject("AccessControllerEvent");
        String majorEventType = control.getString("majorEventType");
        if(!"1".equals(majorEventType)&&!"5".equals(majorEventType)){
            //platUserMapper.addDoorHis(eventLog);
            return;
        }
        DoorLis doorLis = new DoorLis();
        //doorLis.setOriStr(eventLog);
        doorLis.setIpAddress(jsonObject.getString("ipAddress"));
        doorLis.setMacAddress(jsonObject.getString("macAddress"));
        doorLis.setNoticeType(Integer.parseInt(majorEventType));
        if("5".equals(majorEventType)){
            String subEventType = control.getString("subEventType");
            if("75".equals(subEventType)){
                doorLis.setVerify(1);
                doorLis.setName(control.getString("name"));
                doorLis.setEmployeeNoString(control.getString("employeeNoString"));
            }else if("76".equals(subEventType)){
                doorLis.setVerify(2);
            }
        }
    }
    @Override
    public Map<String, Object> faceRecord(String token) {
        SysUserInfo userInfo = UserInfoUtils.getInstance().getUserInfo(token);
        int userCount = platUserMapper.queryPlatUser(userInfo.getCompanyId());
        Map<String, Object> map = new HashMap<>();
        map.put("mod","facerecord");
        map.put("totalUserCount",userCount);
        map.put("watchUserCount",0);
        map.put("dangerUserCount",0);
        //map.put("totalUserCount",userCount);
        //map.put("watchUserCount",0);
        //map.put("dangerUserCount",0);
        List<String> faceAreas = platUserMapper.faceArea();
        map.put("faceAreas",faceAreas);
        List<DoorUserVo> list = platUserMapper.queryDoorUser();
        map.put("doorUserList",list);
        PlatUserFace platUserFace = platUserMapper.queryFaceUserByJobNum(list.get(0).getJobNum());
        platUserFace.setPassTime(list.get(0).getCreateTime());
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        platUserFace.setPassTime(sdf.format(list.get(0).getCreateTime()));
        platUserFace.setRecordId(list.get(0).getId());
        map.put("firstUserInfo",platUserFace);
        return map;
    }
@@ -671,4 +599,43 @@
        }
        platUserMapper.insertDoorListener(doorLisPic);
    }
    @Override
    public List<HashMap<String, Object>> queryGroups() {
        return platUserMapper.queryGroups();
    }
    @Override
    public List<HashMap<String, Object>> queryHelmetWarn() {
        return platUserMapper.queryHelmetWarn();
    }
    @Override
    public List<AreaAdmin> areaAdminInfo() {
        List<AreaAdmin> areaAdminList = platUserMapper.queryAreaInfo();
        for(AreaAdmin areaAdmin : areaAdminList){
            List<NamePhoneDepart> namePhoneDepartList = platUserMapper.queryAdminByArea(areaAdmin.getAreaId());
            areaAdmin.setNpdList(namePhoneDepartList);
        }
        return areaAdminList;
    }
    public static void main(String[] args) {
        MqContent mqContent = new MqContent("sync_person", "notify");
        String uu = "02d32ee86bec2b11e4b23eb6";
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("path","/path");
        JSONObject pathParamJson = new JSONObject();
        pathParamJson.put("dev_sno","");
        pathParamJson.put("limit",10);
        pathParamJson.put("offset",0);
        pathParamJson.put("total",1);
        pathParamJson.put("person_list","[\""+uu+"\"]");
        pathParamJson.put("person_type","4");
        jsonObject.put("path_params",pathParamJson);
        mqContent.setData(jsonObject);
        System.out.println(pathParamJson.toJSONString());
    }
}