jiangping
2024-08-20 9ef944f83e337193293807cdcc6e7bbc1c494c25
server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/hksync/HkSyncVisitServiceImpl.java
@@ -52,7 +52,7 @@
    @Autowired
    private WxPlatNotice wxPlatNotice;
    /**
     * 同步海康访客信息,根据erp同步组织结果,定时检查需要下发到海康的组织信息
     * 同步海康访客信息是否已签离状态
     */
    @Override
    public void getOutTimeVisitRecord(){
@@ -219,7 +219,8 @@
            Date date = new Date();
            for(Visits c : list) {
                //发起海康预约接口(需要登记),根据预约返回接口封装申请记录更新字段
                getUpdateModelByResponse(c,date,roleList,path);
//                getUpdateModelByResponse(c,date,roleList,path);
                getUpdateModelByResponseIccm(c,date,roleList,path);
                visitsMapper.updateById(c);
                if(Objects.isNull(c.getParentId())){
                    wxPlatNotice.sendVisitAuditTemplateNotice(c,
@@ -266,7 +267,6 @@
     * @param c
     * @param date
     * @param date
     * @param type 0需要登记 1免登记
     */
    private void getUpdateModelByResponse(  Visits c,Date date, List<DeviceRole> roleList,String path ) {
        String code = null;
@@ -315,7 +315,6 @@
            }
            reson = response!=null?JSONObject.toJSONString(response):"";
        }
        if (code!= null && id!=null) {
            //海康下发成功
            c.setHkId( id);//预约标识
@@ -323,6 +322,67 @@
            c.setRemark("下发海康成功!");
            c.setStatus(Constants.VisitStatus.xfSuccess);//下发海康成功
        } else {
            //海康下发失败
            c.setRemark("下发海康失败,原因:"+ reson);
            c.setStatus(Constants.VisitStatus.xfFail);//下发海康失败
        }
        c.setHkStatus(Constants.ONE);
        c.setHkDate(date);
    }
    private void getUpdateModelByResponseIccm(  Visits c,Date date, List<DeviceRole> roleList,String path ) {
        String code = null;
        String id = null;
        String qrcode = null;
        String reson = "";
        //发起海康预约接口
        if(Constants.equalsInteger(c.getVisitType(),Constants.ZERO)){
            //(需要登记)
            c.setVisitType(Constants.ZERO);
            IccmAppointmentRequest request =  getHkRequestParaIccm(c,roleList,path);
            if(request == null){
                //海康下发成功
                c.setStatus(Constants.VisitStatus.xfFail);//下发海康失败
                c.setRemark("下发海康参数不正确!");
                c.setHkStatus(Constants.ONE);
                c.setHkDate(date);
                return;
            }
            BaseResponse<IccmAppointmentResponse> response =  HKService.iccmAppointment(request);
            code =response!=null ?response.getCode():null;
            if((response!=null && response.getData()!=null
                    && response.getData().getAppointmentInfoList() !=null
                    && response.getData().getAppointmentInfoList().size()>0)){
                id =response.getData().getOrderId();
                qrcode =response.getData().getAppointmentInfoList().get(0).getQRCode();
            }
            reson = response!=null?JSONObject.toJSONString(response):"";
        }else{
            //免登记
            c.setVisitType(Constants.ONE);
            IccmAppointmentMDJRequest request =getHkMDJRequestParamIccm(c,roleList,path);
            if(request == null){
                //海康下发成功
                c.setStatus(Constants.VisitStatus.xfFail);//下发海康失败
                c.setRemark("下发海康免登记参数不正确!");
                c.setHkStatus(Constants.ONE);
                c.setHkDate(date);
                return;
            }
            BaseResponse<IccmAppointmentMDJResponse> response = HKService.iccmAppiontmentMDJ(request );
            code =response!=null ?response.getCode():null;
            if(response!=null && response.getData()!=null){
                id = response.getData().getOrderId();
                qrcode =response.getData().getQRCode();
            }
            reson = response!=null?JSONObject.toJSONString(response):"";
        }
        if (code!= null && id!=null) {
            //海康下发成功
            c.setHkId( id);//预约标识
            c.setQrcode(qrcode);
            c.setRemark("下发海康成功!");
            c.setStatus(Constants.VisitStatus.xfSuccess);//下发海康成功
        }else {
            //海康下发失败
            c.setRemark("下发海康失败,原因:"+ reson);
            c.setStatus(Constants.VisitStatus.xfFail);//下发海康失败
@@ -359,6 +419,29 @@
        request.setVisitorPermissionSet(getVisitPermissonRequest(roleList,c));
        return  request;
    }
    private IccmAppointmentMDJRequest getHkMDJRequestParamIccm(Visits c,List<DeviceRole> roleList,String path) {
        IccmAppointmentMDJRequest request = new IccmAppointmentMDJRequest();
        IccmAppointmentVistorRequest info =getRequestInfoByVisitIccm(c,path);
        if(info == null ){
            //人脸为空,不能进行推送
            return  null;
        }
        request.setVisitStartTime(DateUtil.getISO8601Timestamp2(c.getStarttime()));
        request.setVisitEndTime(DateUtil.getISO8601Timestamp2(c.getEndtime()));
        request.setReceptionistId(c.getReceptMemberHkId());//被访人海康编码
        if(StringUtils.isNotBlank(c.getReason())){
            char[] charArray = c.getReason().toCharArray();
            int length = charArray.length;
            if(length>32){
                request.setVisitPurpose(c.getReason().substring(0,32));
            }else{
                request.setVisitPurpose(c.getReason());
            }
        }
        request.setVisitorInfo(info);
        request.setVisitorPermissionSet(getVisitPermissonRequestIccm(roleList,c));
        return  request;
    }
    /**
     * 访客权限组
@@ -368,6 +451,20 @@
     */
    private VisitAppointmentPermissonRequest getVisitPermissonRequest(List<DeviceRole> roleList, Visits c) {
        VisitAppointmentPermissonRequest p = new VisitAppointmentPermissonRequest();
        //获取权限组集合
        String[] roles = getHkRoles(c.getDoors(),roleList);
        if(roles==null || roles.length ==0){
            //使用默认访客权限组
            p.setDefaultPrivilegeGroupFlag(Constants.ONE+"");
        }else{
            //指定有效海康访客权限组数据
            p.setDefaultPrivilegeGroupFlag(Constants.ZERO+"");
            p.setPrivilegeGroupIds(roles);
        }
        return  p;
    }
    private IccmPermissionSetRequest getVisitPermissonRequestIccm(List<DeviceRole> roleList, Visits c) {
        IccmPermissionSetRequest p = new IccmPermissionSetRequest();
        //获取权限组集合
        String[] roles = getHkRoles(c.getDoors(),roleList);
        if(roles==null || roles.length ==0){
@@ -409,6 +506,34 @@
        request.setVisitorInfoList(infolist);
        return  request;
    }
    private IccmAppointmentRequest getHkRequestParaIccm(Visits c,List<DeviceRole> roleList,String path ) {
        IccmAppointmentRequest request = new IccmAppointmentRequest();
        //申请人信息
        IccmAppointmentVistorRequest info =getRequestInfoByVisitIccm(c,path);
        if(info == null ){
            //人脸为空,不能进行推送
            return  null;
        }
        request.setVisitStartTime(DateUtil.getISO8601Timestamp(c.getStarttime()));
        request.setVisitEndTime(DateUtil.getISO8601Timestamp(c.getEndtime()));
        request.setReceptionistId(c.getReceptMemberHkId());//被访人海康编码
        if(StringUtils.isNotBlank(c.getReason())){
            char[] charArray = c.getReason().toCharArray();
            int length = charArray.length;
            if(length>32){
                request.setVisitPurpose(c.getReason().substring(0,32));
            }else{
                request.setVisitPurpose(c.getReason());
            }
        }
        //获取权限组集合
        request.setVisitorPermissionSet(getVisitPermissonRequestIccm(roleList,c));
        List<IccmAppointmentVistorRequest> infolist = new ArrayList<>();
        infolist.add(info);
        request.setVisitorInfoList(infolist);
        return  request;
    }
    private VisitAppointmentVistorRequest getRequestInfoByVisit(Visits c,String path) {
        VisitAppointmentVistorRequest info = new VisitAppointmentVistorRequest();
@@ -456,6 +581,52 @@
        return info;
    }
    private IccmAppointmentVistorRequest getRequestInfoByVisitIccm(Visits c,String path) {
        IccmAppointmentVistorRequest info = new IccmAppointmentVistorRequest();
        //人脸数据
        if(StringUtils.isBlank(c.getName())
                ||StringUtils.isBlank(c.getPhone())
                || StringUtils.isBlank(c.getFaceImg()) ){
            return  null;
        }
        if(StringUtils.isNotBlank(c.getFaceImg())){
            info.setVisitorPhoto(ImageBase64Util.Image2Base64(path+c.getFaceImg()));
        }
        if(info.getVisitorPhoto() == null){
            return  null;
        }
        if(StringUtils.isNotBlank(c.getName())){
            char[] charArray = c.getName().toCharArray();
            int length = charArray.length;
            if(length>32){
                info.setVisitorName(c.getName().substring(0,32));
            }else{
                info.setVisitorName(c.getName());
            }
        }
        if(StringUtils.isNotBlank(c.getCompanyName())){
            char[] charArray = c.getCompanyName().toCharArray();
            int length = charArray.length;
            if(length>32){
                info.setVisitorWorkUnit(c.getCompanyName().substring(0,32));
            }else{
                info.setVisitorWorkUnit(c.getCompanyName());
            }
        }
        info.setPhoneNo(c.getPhone());
        info.setPlateNo(c.getCarNos());
        info.setGender(c.getSex()+"");
        if(Constants.equalsInteger(c.getIdcardType(),Constants.ZERO)){
            info.setCertificateType(HKConstants.CertificateType.SHENFENZHENG.getKey()+"");
            info.setCertificateNo(DESUtil.decrypt(Constants.EDS_PWD, c.getIdcardNo()));
        } else if(Constants.equalsInteger(c.getIdcardType(),Constants.TWO)){
            info.setCertificateType(HKConstants.CertificateType.HUZHAO.getKey()+"");
            info.setCertificateNo(DESUtil.decrypt(Constants.EDS_PWD,  c.getIdcardNo()));
        }
        return info;
    }
    private String[] getHkRoles(String doors, List<DeviceRole> roleList) {
        if(StringUtils.isBlank(doors) || roleList.size()==0|| roleList.size()==0){