jiangping
2023-12-20 4b139bcb2b3c6bf1082aca29913caf5166ec8167
海康接口对接开发
已添加10个文件
已修改20个文件
1460 ■■■■ 文件已修改
server/dmvisit_admin/src/main/java/com/doumee/task/ScheduleTool.java 64 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/dmvisit_service/src/main/java/com/doumee/core/haikang/model/HKConstants.java 80 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/dmvisit_service/src/main/java/com/doumee/core/haikang/model/HKTools.java 24 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/dmvisit_service/src/main/java/com/doumee/core/haikang/model/param/request/AuthItemListPersonRequest.java 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/dmvisit_service/src/main/java/com/doumee/core/haikang/model/param/request/AuthItemListRequest.java 22 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/dmvisit_service/src/main/java/com/doumee/core/haikang/model/param/request/AuthItemListSortRequest.java 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/dmvisit_service/src/main/java/com/doumee/core/haikang/model/param/request/AuthItemListTimeRequest.java 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/dmvisit_service/src/main/java/com/doumee/core/haikang/model/param/request/TaskDataAdditionPersonRequest.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/dmvisit_service/src/main/java/com/doumee/core/haikang/model/param/request/TaskDataAdditionResourceRequest.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/dmvisit_service/src/main/java/com/doumee/core/haikang/model/param/respose/AuthItemListDetailResponse.java 23 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/dmvisit_service/src/main/java/com/doumee/core/haikang/model/param/respose/AuthItemListResponse.java 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/dmvisit_service/src/main/java/com/doumee/core/haikang/model/param/respose/AuthItemListTemplResponse.java 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/dmvisit_service/src/main/java/com/doumee/core/haikang/model/param/respose/TaskProgressDetailResponse.java 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/dmvisit_service/src/main/java/com/doumee/core/haikang/model/param/respose/TaskProgressNumResponse.java 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/dmvisit_service/src/main/java/com/doumee/core/haikang/model/param/respose/TaskProgressResponse.java 15 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/dmvisit_service/src/main/java/com/doumee/core/haikang/service/HKService.java 48 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/dmvisit_service/src/main/java/com/doumee/core/utils/Constants.java 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/dmvisit_service/src/main/java/com/doumee/core/utils/TestUtil.java 128 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/dmvisit_service/src/main/java/com/doumee/dao/business/model/Empower.java 16 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/dmvisit_service/src/main/java/com/doumee/dao/business/model/ParkBook.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/dmvisit_service/src/main/java/com/doumee/service/business/HkSyncService.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/dmvisit_service/src/main/java/com/doumee/service/business/impl/erp/ErpSyncServiceImpl.java 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/dmvisit_service/src/main/java/com/doumee/service/business/impl/hksync/HkSyncBaseServiceImpl.java 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/dmvisit_service/src/main/java/com/doumee/service/business/impl/hksync/HkSyncDeviceServiceImpl.java 132 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/dmvisit_service/src/main/java/com/doumee/service/business/impl/hksync/HkSyncDoorsServiceImpl.java 108 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/dmvisit_service/src/main/java/com/doumee/service/business/impl/hksync/HkSyncEmpowerServiceImpl.java 385 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/dmvisit_service/src/main/java/com/doumee/service/business/impl/hksync/HkSyncParkServiceImpl.java 163 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/dmvisit_service/src/main/java/com/doumee/service/business/impl/hksync/HkSyncPrivilegeServiceImpl.java 114 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/dmvisit_service/src/main/java/com/doumee/service/business/impl/hksync/HkSyncVisitServiceImpl.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/pom.xml 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/dmvisit_admin/src/main/java/com/doumee/task/ScheduleTool.java
@@ -1,6 +1,7 @@
package com.doumee.task;
import com.doumee.service.business.impl.hksync.HkSyncEmpowerServiceImpl;
import com.doumee.service.business.impl.hksync.HkSyncImgServiceImpl;
import com.doumee.service.business.impl.hksync.HkSyncOrgUserServiceImpl;
import com.doumee.service.business.impl.hksync.HkSyncVisitServiceImpl;
@@ -22,6 +23,8 @@
    @Autowired
    private HkSyncImgServiceImpl hkSyncImgService;
    @Autowired
    private HkSyncEmpowerServiceImpl hkSyncEmpowerService;
    @Autowired
    private HkSyncOrgUserServiceImpl hkSyncOrgUserService;
    @Autowired
@@ -45,25 +48,58 @@
     * å®šæ—¶åŒæ­¥ç»„织信息到海康系统
     * @throws Exception
     */
//    @Scheduled(fixedDelay= 60*1000)
//    public void syncOrgData() {
//        hkSyncOrgUserService.syncOrgData();
//    }
    /**
     * å®šæ—¶åŒæ­¥ç»„织信息到海康系统
     * @throws Exception
     */
    @Scheduled(fixedDelay= 60*1000)
    public void syncVisitData() {
        hkSyncVisitService.syncVisitData();
    public void syncOrgData() {
        hkSyncOrgUserService.syncOrgData();
    }
    /**
     * å®šæ—¶åŒæ­¥ç”¨æˆ·ä¿¡æ¯åˆ°æµ·åº·ç³»ç»Ÿ
     * @throws Exception
     */
//    @Scheduled(fixedDelay= 60*1000)
//    public void syncUserData()  {
//        hkSyncImgService.syncUserData();
//    }
    @Scheduled(fixedDelay= 60*1000)
    public void syncUserData()  {
        hkSyncOrgUserService.syncUserData();
    }
    /**
     * å®šæ—¶åŒæ­¥ç”³è¯·é€šè¿‡çš„访客数据到海康系统
     * @throws Exception
     */
    @Scheduled(fixedDelay= 60*1000)
    public void syncVisitData()  {
        hkSyncVisitService.syncVisitData();
    }
    /**
     * å®šæ—¶åŒæ­¥å†…部人员授权到海康系统
     * @throws Exception
     */
    @Scheduled(fixedDelay= 60*1000)
    public void syncEmpowerData()  {
        hkSyncEmpowerService.syncEmpowerData();
    }
    /**
     * å®šæ—¶æŸ¥è¯¢äººå‘˜ä¸‹å‘海康结果(任务是否已下载结束)
     * @throws Exception
     */
    @Scheduled(fixedDelay= 60*1000)
    public void syncEmpowerResultData()  {
        hkSyncEmpowerService.syncEmpowerResultData();
    }
    /**
     * å®šæ—¶æŸ¥è¯¢äººå‘˜å®žé™…下发权限结果,是否已经下载成功
     * @throws Exception
     */
    @Scheduled(fixedDelay= 60*1000)
    public void syncEmpowerDetailData()  {
        hkSyncEmpowerService.syncEmpowerDetailData();
    }
    /**
     * å®šæ—¶åŒæ­¥è½¦è¾†åŒ…期到海康系统
     * @throws Exception
     */
    @Scheduled(fixedDelay= 60*1000)
    public void syncParkBookData()  {
        hkSyncImgService.syncParkBookData();
    }
}
server/dmvisit_service/src/main/java/com/doumee/core/haikang/model/HKConstants.java
@@ -1,6 +1,7 @@
package com.doumee.core.haikang.model;
import com.doumee.core.utils.Constants;
import javafx.scene.effect.BlendMode;
import lombok.Data;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -61,10 +62,87 @@
        String taskAddition= "/api/acps/v1/authDownload/task/addition";//创建下载任务_根据人员与设备通道指定下载
        String taskDataAddition= "/api/acps/v1/authDownload/data/addition";//下载任务中添加数据_根据人员与设备通道指定下载
        String taskStart= "/api/acps/v1/authDownload/task/start";//开始下载任务
        String taskProgress= "/api/acps/v1/authDownload/task/progress";//查詢下载任务进度
        String taskProgressNum= "/api/acps/v1/authDownload/task/progress";//查詢下载任务进度
        String taskProgress= "/api/acps/v2/download_record/person/detail/search";//查询设备通道的人员权限下载详情总数v2
        String authItemList= "/api/acps/v1/auth_item/list/search";//查询权限条目列表
    }
    /**
     * ä»»å‹™é¡žåž‹
     */
    public  enum TASK_TYPE {
        CARD(1, "卡片"  ),
        FACE(2, "人脸"  )
        ;
        // æˆå‘˜å˜é‡
        private String name;
        private int key;
        // æž„造方法
        TASK_TYPE(int key, String name ) {
            this.name = name;
            this.key = key;
        }
        // get set æ–¹æ³•
        public String getName() {
            return name;
        }
        public void setName(String name) {
            this.name = name;
        }
        public int getKey() {
            return key;
        }
        public void setKey(int key) {
            this.key = key;
        }
    }
    /**
     * æ“ä½œç±»åž‹ï¼Œ0新增;1修改;2删除
     */
    public  enum OPERA_TYPE {
        ADD(0, "新增"  ),
        UDPATE(1, "修改"  ),
        DEL(2, "删除"  )
        ;
        // æˆå‘˜å˜é‡
        private String name;
        private int key;
        // æž„造方法
        OPERA_TYPE(int key, String name ) {
            this.name = name;
            this.key = key;
        }
        // get set æ–¹æ³•
        public String getName() {
            return name;
        }
        public void setName(String name) {
            this.name = name;
        }
        public int getKey() {
            return key;
        }
        public void setKey(int key) {
            this.key = key;
        }
    }
    /**
     * é¡”色枚举
     */
    public  enum EventTypes {
server/dmvisit_service/src/main/java/com/doumee/core/haikang/model/HKTools.java
@@ -467,12 +467,23 @@
        return  result;
    }
    /**
     *    æŸ¥è¯¢ä¸€å¡é€šæƒé™ä¸‹è½½ä»»åŠ¡è¿›åº¦
     *    æŸ¥è¯¢ä¸€å¡é€šæƒé™æŸ¥è¯¢è®¾å¤‡é€šé“的人员权限下载详情总数v2
     * @param body
     * @return
     */
    public static String taskProgress(String body) {
        Map<String, String> path = getPath(HKConstants.InterfacePath.taskProgress);
        String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, "application/json", null);// post请求application/json类型参数
        saveInterfaceLog(body,result,path);
        return  result;
    }
    /**
     *    æŸ¥è¯¢ä¸€å¡é€šæƒé™ä¸‹è½½ä»»åŠ¡è¿›åº¦
     * @param body
     * @return
     */
    public static String taskProgressNum(String body) {
        Map<String, String> path = getPath(HKConstants.InterfacePath.taskProgressNum);
        String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, "application/json", null);// post请求application/json类型参数
        saveInterfaceLog(body,result,path);
        return  result;
@@ -499,6 +510,17 @@
        saveInterfaceLog(body,result,path);
        return  result;
    }
    /**
     * æŸ¥è¯¢æƒé™æ¡ç›®åˆ—表
     * @param body
     * @return
     */
    public static String authItemList(String body) {
        Map<String, String> path = getPath(HKConstants.InterfacePath.authItemList);
        String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, "application/json", null);// post请求application/json类型参数
        saveInterfaceLog(body,result,path);
        return  result;
    }
server/dmvisit_service/src/main/java/com/doumee/core/haikang/model/param/request/AuthItemListPersonRequest.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,12 @@
package com.doumee.core.haikang.model.param.request;
import lombok.Data;
import java.util.List;
@Data
public class AuthItemListPersonRequest {
   private String personIds;//string    True    ä¸‹è½½ä»»åŠ¡å”¯ä¸€æ ‡è¯†
}
server/dmvisit_service/src/main/java/com/doumee/core/haikang/model/param/request/AuthItemListRequest.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,22 @@
package com.doumee.core.haikang.model.param.request;
import lombok.Data;
import java.util.List;
@Data
public class AuthItemListRequest {
   private List<AuthItemListPersonRequest> personIds;//string    True
   private TaskDataAdditionResourceRequest resourceInfos;//    object[]    False    èµ„源设备对象信息
   private String queryType    ;//string    True    æŸ¥è¯¢èµ„源类型,参考附录A.50 è®¾å¤‡é€šé“类型
   private Integer[]   personStatus;//    number[]    False    äººå‘˜çŠ¶æ€0:已配置未下载1:更新待下载2:更新待删除3:已下载4:未配置
   private Integer[]   cardStatus;//    number[]    False    å¡ç‰‡çŠ¶æ€0:已配置未下载1:更新待下载2:更新待删除3:已下载4:未配置
   private Integer[]   faceStatus    ;//number[]    False    äººè„¸çŠ¶æ€0:已配置未下载1:更新待下载2:更新待删除3:已下载4:未配置
   private AuthItemListTimeRequest  configTime;//;    object    False    é…ç½®æ—¶é—´æŸ¥è¯¢å¯¹è±¡
   private AuthItemListSortRequest sortObjects    ;//object[]    False    ç›®å‰åªæ”¯æŒé…ç½®æ—¶é—´
   private Integer pageNo    ;//number    True    é¡µç ,pageNo>0
   private Integer pageSize    ;//number    True    é¡µå¤§å°,0<pageSize<=1000
}
server/dmvisit_service/src/main/java/com/doumee/core/haikang/model/param/request/AuthItemListSortRequest.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,11 @@
package com.doumee.core.haikang.model.param.request;
import lombok.Data;
@Data
public class AuthItemListSortRequest {
    private String startTime;//    string    False    å¼€å§‹æ—¥æœŸ,采用ISO8601时间格式,最大长度32个字符,如2018-09-03T17:30:08.000+08:00
    private String endTime    ;//string    False    ç»“束日期,采用ISO8601时间格式,最大长度32个字符,如2018-09-03T17:30:08.000+08:00
}
server/dmvisit_service/src/main/java/com/doumee/core/haikang/model/param/request/AuthItemListTimeRequest.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,11 @@
package com.doumee.core.haikang.model.param.request;
import lombok.Data;
@Data
public class AuthItemListTimeRequest {
    private String startTime;//    string    False    å¼€å§‹æ—¥æœŸ,采用ISO8601时间格式,最大长度32个字符,如2018-09-03T17:30:08.000+08:00
    private String endTime    ;//string    False    ç»“束日期,采用ISO8601时间格式,最大长度32个字符,如2018-09-03T17:30:08.000+08:00
}
server/dmvisit_service/src/main/java/com/doumee/core/haikang/model/param/request/TaskDataAdditionPersonRequest.java
@@ -6,7 +6,7 @@
public class TaskDataAdditionPersonRequest {
   private String  personId    ;//string    True    äººå‘˜Id,系统内人员从获取人员列表v2 æŽ¥å£èŽ·å–è¿”å›žå‚æ•°ä¸­personId,系统外人员,人员Id由调用方指定,作为人员唯一标志,最大长度为64,包含数字、字母(小写)和中划线(-)
   private String operatorType    ;//number    True    æ“ä½œç±»åž‹ï¼Œ0新增;1修改;2删除
   private Integer operatorType    ;//number    True    æ“ä½œç±»åž‹ï¼Œ0新增;1修改;2删除
   private String  startTime    ;//string    False    å¼€å§‹æ—¥æœŸï¼Œé…ç½®äººå‘˜æƒé™çš„æœ‰æ•ˆæœŸï¼Œä¸ºç©ºæ—¶é»˜è®¤é•¿æœŸæœ‰æ•ˆã€‚采用ISO8601时间格式,最大长度32个字符,如2018-09-03T17:30:08.000+08:00
   private String endTime;//    string    False    ç»“束日期,配置人员权限的有效期,为空时默认长期有效。采用ISO8601时间格式,最大长度32个字符,如2018-09-03T17:30:08.000+08:00
   private String personType;//    number    False    äººå‘˜ç±»åž‹ï¼Œé»˜è®¤ä¸º11. ç³»ç»Ÿå†…人员2. ç³»ç»Ÿå¤–人员           ä¸‹è½½ç³»ç»Ÿå¤–人员时必填
server/dmvisit_service/src/main/java/com/doumee/core/haikang/model/param/request/TaskDataAdditionResourceRequest.java
@@ -7,5 +7,5 @@
   private String resourceIndexCode;//    string    True    èµ„源的唯一标识,32位数字+字母(小写)字符串,资源为设备,根据获取资源列表v2接口获取返回参数indexCode
   private String  resourceType;//    string    True    èµ„源类型,参考附录A.50 è®¾å¤‡é€šé“类型
   private Integer[] channelNos    ;//number[]    True    èµ„源通道号
   private String[] channelNos    ;//number[]    True    èµ„源通道号
}
server/dmvisit_service/src/main/java/com/doumee/core/haikang/model/param/respose/AuthItemListDetailResponse.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,23 @@
package com.doumee.core.haikang.model.param.respose;
import com.doumee.core.haikang.model.param.request.AuthItemListTimeRequest;
import lombok.Data;
@Data
public class AuthItemListDetailResponse {
   private String  personId    ;//string    False    äººå‘˜ID
  private String resourceIndexCode;//    string    False    èµ„源的唯一标识
  private Integer channelNo;//    number    False    é€šé“号
  private String channelIndexCode    ;//string    False    èµ„源通道唯一标识(在权限下载和配置接口入参时对应查询接口会返回,不作为查询接口的查询条件)
             private AuthItemListTimeRequest templateConfigInfos;//    Object[]    False    è®¡åˆ’模板信息
  private Integer personStatus;//    number    False    äººå‘˜çŠ¶æ€,0:已配置未下载1:更新待下载2:更新待删除3:已下载4:未配置
  private Integer cardStatus    ;//number    False    å¡ç‰‡çŠ¶æ€,0:已配置未下载1:更新待下载2:更新待删除3:已下载4:未配置
  private Integer faceStatus    ;//number    False    äººè„¸çŠ¶æ€,0:已配置未下载1:更新待下载2:更新待删除3:已下载4:未配置
  private String cardJson    ;//string    False    è®°å½•已下载到设备的卡号(Map格式(卡号:状态),其中状态(0改变表示下载后卡片的信息又变化了,1已下载))
             private String configTime    ;//string    False    é…ç½®æ—¶é—´,采用ISO8601时间格式,最大长度32个字符,如2018-09-03T17:30:08.000+08:00
             private String startTime;//    string    False    äººå‘˜æƒé™æœ‰æ•ˆæœŸï¼ˆä»¥äººä¸ºä¸­å¿ƒè®¾å¤‡æ—¶ä½¿ç”¨ï¼‰,开始时间,采用ISO8601时间格式,最大长度32个字符,如2018-09-03T17:30:08.000+08:00
             private String endTime    ;//string    False    äººå‘˜æƒé™æœ‰æ•ˆæœŸï¼ˆä»¥äººä¸ºä¸­å¿ƒè®¾å¤‡æ—¶ä½¿ç”¨ï¼‰,开始日期,采用ISO8601时间格式,最大长度32个字符,如2018-09-03T17:30:08.000+08:00
             private String personExtendJson;//    body    string    å¦
}
server/dmvisit_service/src/main/java/com/doumee/core/haikang/model/param/respose/AuthItemListResponse.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,13 @@
package com.doumee.core.haikang.model.param.respose;
import lombok.Data;
import java.util.List;
@Data
public class AuthItemListResponse {
   private Integer  total;//    number    False    æ€»æ¡æ•°
   private List<AuthItemListDetailResponse> list;//object[]    False    è®¾å¤‡é€šé“的下载记录
}
server/dmvisit_service/src/main/java/com/doumee/core/haikang/model/param/respose/AuthItemListTemplResponse.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,10 @@
package com.doumee.core.haikang.model.param.respose;
import lombok.Data;
@Data
public class AuthItemListTemplResponse {
    private Integer dimension    ;//number    False    ç»´åº¦,范围:1-4,支持4维度计划模板配置
    private String templateId;//    string    False    è®¡åˆ’模板Id,全天候计划模板为1
}
server/dmvisit_service/src/main/java/com/doumee/core/haikang/model/param/respose/TaskProgressDetailResponse.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,11 @@
package com.doumee.core.haikang.model.param.respose;
import lombok.Data;
@Data
public class TaskProgressDetailResponse {
   private String downloadResultId;//    string    False    ä¸‹è½½è®°å½•唯一ID
   private String  personId;//    string    False    äººå‘˜ç¼–码
   private String  persondownloadResult;//    string    False    ä¸‹è½½è®°å½•状态(只有成功/失败状态,0:成功,1:失败)
   private String  downloadTime    ;//string    False    ä¸‹è½½æ—¶é—´ï¼Œé‡‡ç”¨ISO8601时间格式,最大长度32个字符,如2018-09-
}
server/dmvisit_service/src/main/java/com/doumee/core/haikang/model/param/respose/TaskProgressNumResponse.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,19 @@
package com.doumee.core.haikang.model.param.respose;
import lombok.Data;
@Data
public class TaskProgressNumResponse {
   private String taskId    ;//string    False    ä¸‹è½½ä»»åŠ¡å”¯ä¸€æ ‡è¯†ï¼Œ32位数字+字母字符串
   private String tagId;//    string    False    æ ‡ç­¾,用于区分不同业务组件,建议使用组件标识。只支持1-32个数字和小写字母。
   private Integer  taskType;//    number    False    ä¸‹è½½ä»»åŠ¡ç±»åž‹ ,参考附录A.53 ä»»åŠ¡ä¸‹è½½ç±»åž‹è¯´æ˜Ž
   private Integer taskOptType;//number    False    ä»»åŠ¡æ“ä½œç±»åž‹0:初始化下载,、1:异动下载,  2:指定下载-普通任务, 3:指定下载-快速任务,4自动下载, 5:同步下载
   private String startTime    ;//string    False    ä¸‹è½½å¼€å§‹æ—¶é—´ é‡‡ç”¨ISO8601时间格式,最大长度32个字符,如2018-09-03T17:30:08.000+08:00
   private Integer totalPercent    ;//number    False    ä¸‹è½½æ€»è¿›åº¦
   private Integer leftTime;//    number    False    ä¸‹è½½å‰©ä½™æ—¶é—´
   private Integer consumeTime    ;//number    False    ä¸‹è½½æ€»ç”¨æ—¶
   private Boolean isDownloadFinished;//    boolean    False    ä¸‹è½½æ˜¯å¦ç»“束
}
server/dmvisit_service/src/main/java/com/doumee/core/haikang/model/param/respose/TaskProgressResponse.java
@@ -2,19 +2,12 @@
import lombok.Data;
import java.util.List;
@Data
public class TaskProgressResponse {
   private String taskId    ;//string    False    ä¸‹è½½ä»»åŠ¡å”¯ä¸€æ ‡è¯†ï¼Œ32位数字+字母字符串
   private String tagId;//    string    False    æ ‡ç­¾,用于区分不同业务组件,建议使用组件标识。只支持1-32个数字和小写字母。
   private Integer  taskType;//    number    False    ä¸‹è½½ä»»åŠ¡ç±»åž‹ ,参考附录A.53 ä»»åŠ¡ä¸‹è½½ç±»åž‹è¯´æ˜Ž
   private Integer taskOptType;//number    False    ä»»åŠ¡æ“ä½œç±»åž‹0:初始化下载,、1:异动下载,  2:指定下载-普通任务, 3:指定下载-快速任务,4自动下载, 5:同步下载
   private String startTime    ;//string    False    ä¸‹è½½å¼€å§‹æ—¶é—´ é‡‡ç”¨ISO8601时间格式,最大长度32个字符,如2018-09-03T17:30:08.000+08:00
   private Integer totalPercent    ;//number    False    ä¸‹è½½æ€»è¿›åº¦
   private Integer leftTime;//    number    False    ä¸‹è½½å‰©ä½™æ—¶é—´
   private Integer consumeTime    ;//number    False    ä¸‹è½½æ€»ç”¨æ—¶
   private Boolean isDownloadFinished;//    boolean    False    ä¸‹è½½æ˜¯å¦ç»“束
   private String resourceDownloadProgress;//    object[]    False    èµ„源下载详情
   private Integer  total;//    number    False    æ€»æ¡æ•°
   private List<TaskProgressDetailResponse> list;//object[]    False    è®¾å¤‡é€šé“的下载记录
}
server/dmvisit_service/src/main/java/com/doumee/core/haikang/service/HKService.java
@@ -602,18 +602,60 @@
     *海康一卡通任务进度查询
     * @return
     */
    public  static  BaseResponse<TaskProgressResponse>    taskDataAddition(TaskProgressRequest param){
    public  static  BaseResponse<TaskProgressNumResponse>    taskProgressNum(TaskProgressRequest param){
        log.info("【海康一卡通任务进度查询】================开始===="+JSONObject.toJSONString(param));
        String res = null;
        try {
            res = HKTools.taskProgressNum(JSONObject.toJSONString(param));
            TypeReference typeReference =
                    new TypeReference< BaseResponse<TaskProgressNumResponse> >(){};
            BaseResponse<TaskProgressNumResponse>   result = JSONObject.parseObject(res, typeReference.getType());
            logResult(result,"海康一卡通任务进度查询");
            return  result;
        }catch (Exception e){
            log.error("【海康一卡通任务进度查询】================失败====:\n"+ e.getMessage());
        }finally {
           // saveInterfaceLog(param,res);
        }
        return  null;
    }
    /**
     *海康一卡通设备通道的人员权限下载详情总数v2
     * @return
     */
    public  static  BaseResponse<TaskProgressResponse>    taskProgress(TaskProgressRequest param){
        log.info("【海康一卡通设备通道的人员权限下载详情总数】================开始===="+JSONObject.toJSONString(param));
        String res = null;
        try {
            res = HKTools.taskProgress(JSONObject.toJSONString(param));
            TypeReference typeReference =
                    new TypeReference< BaseResponse<TaskProgressResponse> >(){};
            BaseResponse<TaskProgressResponse>   result = JSONObject.parseObject(res, typeReference.getType());
            logResult(result,"海康一卡通任务进度查询");
            logResult(result,"海康一卡通设备通道的人员权限下载详情总数");
            return  result;
        }catch (Exception e){
            log.error("【海康一卡通任务进度查询】================失败====:\n"+ e.getMessage());
            log.error("【海康一卡通设备通道的人员权限下载详情总数】================失败====:\n"+ e.getMessage());
        }finally {
           // saveInterfaceLog(param,res);
        }
        return  null;
    }
    /**
     *海康查询权限条目列表
     * @return
     */
    public  static  BaseResponse<AuthItemListResponse>    authItemList(AuthItemListRequest param){
        log.info("【海康查询权限条目列表】================开始===="+JSONObject.toJSONString(param));
        String res = null;
        try {
            res = HKTools.authItemList(JSONObject.toJSONString(param));
            TypeReference typeReference =
                    new TypeReference< BaseResponse<AuthItemListResponse> >(){};
            BaseResponse<AuthItemListResponse>   result = JSONObject.parseObject(res, typeReference.getType());
            logResult(result,"海康查询权限条目列表");
            return  result;
        }catch (Exception e){
            log.error("【海康查询权限条目列表】================失败====:\n"+ e.getMessage());
        }finally {
           // saveInterfaceLog(param,res);
        }
server/dmvisit_service/src/main/java/com/doumee/core/utils/Constants.java
@@ -62,12 +62,17 @@
    public static final String ERP_USERSTATUS_RL ="ERP_USERSTATUS_RL" ;
    public static final String ERP ="ERP" ;
    public static final Integer THREE =3 ;
    public static  boolean DEALING_HK_SYNCPRIVILEGE= false;
    public static  boolean DEALING_HK_SYNCDEVICE = false;
    public static  boolean DEALING_HK_SYNCPARK = false;
    public static  boolean DEALING_HK_IMG = false;
    public static  boolean DEALING_HK_ORG = false;
    public static  boolean DEALING_HK_USER = false;
    public static  boolean DEALING_HK_VISIT = false;
    public static  boolean DEALING_HK_EMPOWER = false;
    public static  boolean DEALING_HK_EMPOWER_DETAIL = false;
    public static  boolean DEALING_HK_EMPOWER_RESULT = false;
    public static  boolean DEALING_HK_PARKBOOK = false;
    // ERP接口配置
    public static final String ERP_CONFIG = "ERP_CONFIG";
    // ERP ACCESS_KEY
@@ -165,6 +170,15 @@
         int xfFail = 6;
         int signout = 7;
    }
    public interface EmpowerStatus{
        //一卡通授权下发状态 0待下发 1已下发 2下发成功   3已取消 4下发失败 5任务下载已结束
         int wait = 0;
         int ing = 1;
         int pass = 2;
         int cancel = 3;
         int fail = 4;
         int downloaded = 5;
    }
    public interface DOOR_ROLE_TYPE{
         int lw = 0;
         int fk = 1;
server/dmvisit_service/src/main/java/com/doumee/core/utils/TestUtil.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,128 @@
//package com.doumee.core.utils;
//
//import java.awt.image.BufferedImage;
//import java.io.ByteArrayOutputStream;
//import java.io.File;
//import java.io.FileOutputStream;
//import java.io.IOException;
//import java.net.URL;
//import java.util.stream.IntStream;
//import javax.imageio.ImageIO;
//import org.apache.poi.ss.usermodel.Cell;
//import org.apache.poi.ss.usermodel.Row;
//import org.apache.poi.ss.usermodel.Sheet;
//import org.apache.poi.ss.usermodel.Workbook;
//import org.apache.poi.ss.usermodel.WorkbookFactory;
//import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
//import org.apache.poi.xssf.usermodel.XSSFDrawing;
//import org.apache.poi.xssf.usermodel.XSSFGraphicFrame;
//import org.apache.poi.xssf.usermodel.XSSFShape;
//import org.apache.poi.xssf.usermodel.XSSFSheet;
//import org.apache.poi.xssf.usermodel.XSSFWorkbook;
//import com.itextpdf.text.BaseColor;
//import com.itextpdf.text.Document;
//import com.itextpdf.text.DocumentException;
//import com.itextpdf.text.Element;
//import com.itextpdf.text.Font;
//import com.itextpdf.text.Image;
//import com.itextpdf.text.PageSize;
//import com.itextpdf.text.Paragraph;
//import com.itextpdf.text.pdf.PdfPCell;
//import com.itextpdf.text.pdf.PdfPTable;
//import com.itextpdf.text.pdf.PdfWriter;
//
//public class TestUtil {
//    public static void main(String[] args) {
//        try (Workbook workbook = WorkbookFactory.create(new File("example.xlsx"));
//            FileOutputStream fos = new FileOutputStream("example.pdf")) {
//            Document document = new Document(PageSize.A4, 50, 50, 50, 50);
//            PdfWriter writer = PdfWriter.getInstance(document, fos);
//            document.open();
//            for (Sheet sheet : workbook) {
//                PdfPTable table = new PdfPTable(sheet.getRow(0).getLastCellNum());
//                table.setHeaderRows(1);
//                table.setWidths(IntStream.range(0, sheet.getRow(0).getLastCellNum()).mapToDouble(i -> 1).toArray());
//                table.setWidthPercentage(100);
//                Paragraph title = new Paragraph(sheet.getSheetName(), new Font(BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED), 16, Font.BOLD));
//                title.setAlignment(Element.ALIGN_CENTER);
//                document.add(title);
//                sheet.forEach(row -> {
//                    IntStream.range(0, row.getLastCellNum()).forEach(i -> {
//                        Cell cell = row.getCell(i);
//                        PdfPCell pdfCell = null;
//                        try {
//                            pdfCell = new PdfPCell(new Paragraph(cell.getStringCellValue(), new Font(BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED), 12)));
//                        } catch (DocumentException e) {
//                            throw new RuntimeException(e);
//                        } catch (IOException e) {
//                            throw new RuntimeException(e);
//                        }
//                        pdfCell.setBorderWidth(1f);
//                        pdfCell.setBorderColor(BaseColor.BLACK);
//                        pdfCell.setPadding(5f);
//                        if (row.getRowNum() == 0) {
//                            pdfCell.setBackgroundColor(BaseColor.LIGHT_GRAY);
//                        }
//                        table.addCell(pdfCell);
//                        if (cell.getCellType() == CellType.BLANK || cell.getCellType() == CellType.FORMULA || cell.getCellType() == CellType.ERROR || cell.getCellType() == CellType.STRING && cell.getStringCellValue().trim().isEmpty() || cell.getCellType() == CellType.NUMERIC && cell.getNumericCellValue() == 0 || cell.getCellType() == CellType.BOOLEAN && !cell.getBooleanCellValue() || cell.getCellType() == CellType.STRING && cell.getStringCellValue().startsWith("#") || cell.getCellType() == CellType.FORMULA && cell.getCellFormula().startsWith("#") || cell.getCellType() == CellType.STRING && cell.getStringCellValue().startsWith("=") || cell.getCellType() == CellType.FORMULA && cell.getCellFormula().startsWith("=") || cell.getCellType() == CellType.STRING && cell.getStringCellValue().startsWith("@") || cell.getCellType() == CellType.FORMULA && cell.getCellFormula().startsWith("@") || cell.getCellType() == CellType.STRING && cell.getStringCellValue().startsWith("'") || cell.getCellType() == CellType.FORMULA && cell.getCellFormula().startsWith("'")) {
//                            return;
//                        }
//                        if (cell.getCellType() == CellType.STRING && cell.getStringCellValue().startsWith("http")) {
//                            try {
//                                BufferedImage image = ImageIO.read(new URL(cell.getStringCellValue()));
//                                if (image != null) {
//                                    addImageToTable(table, image);
//                                }
//                            } catch (Exception e) {
//                                e.printStackTrace();
//                            }
//                        } else {
//                            if (sheet instanceof XSSFSheet) {
//                                XSSFSheet xssfSheet = (XSSFSheet) sheet;
//                                XSSFDrawing drawing = xssfSheet.createDrawingPatriarch();
//                                for (XSSFShape shape : drawing.getShapes()) {
//                                    if (shape instanceof XSSFClientAnchor) {
//                                        XSSFClientAnchor anchor = (XSSFClientAnchor) shape.getAnchor();
//                                        if (anchor.getRow1() == cell.getRowIndex() && anchor.getCol1() == cell.getColumnIndex()) {
//                                            if (shape instanceof XSSFGraphicFrame) {
//                                                XSSFGraphicFrame frame = (XSSFGraphicFrame) shape;
//                                                BufferedImage image = frame.getGraphic().getBufferedImage();
//                                                try {
//                                                    addImageToTable(table, image);
//                                                } catch (Exception e) {
//                                                    throw new RuntimeException(e);
//                                                }
//                                            }
//                                        }
//                                    }
//                                }
//                            }
//                        }
//                    });
//                });
//                table.setSpacingBefore(20f);
//                table.setSpacingAfter(20f);
//                table.setKeepTogether(true);
//                document.add(table);
//            }
//            document.close();
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//    }
//
//    private static void addImageToTable(PdfPTable table, BufferedImage image) throws Exception {
//        ByteArrayOutputStream baos = new ByteArrayOutputStream();
//        ImageIO.write(image, "png", baos);
//        baos.flush();
//        byte[] imageData = baos.toByteArray();
//        baos.close();
//        Image pdfImage = Image.getInstance(imageData);
//        pdfImage.scaleToFit(100f, 100f);
//        PdfPCell imageCell = new PdfPCell(pdfImage, true);
//        imageCell.setBorderWidth(1f);
//        imageCell.setBorderColor(BaseColor.BLACK);
//        imageCell.setPadding(5f);
//        table.addCell(imageCell);
//    }
//}
server/dmvisit_service/src/main/java/com/doumee/dao/business/model/Empower.java
@@ -118,8 +118,8 @@
    @TableField(exist = false)
    private String createrName;
    @ApiModelProperty(value = "下发状态 0待下发 1已下发 2已取消", example = "1")
    @ExcelColumn(name="下发状态",index= 8,valueMapping ="0=待下发;1=已下发;2=已取消" )
    @ApiModelProperty(value = "下发状态 0待下发 1已下发 2下发成功  3已取消 4下发失败 ", example = "1")
    @ExcelColumn(name="下发状态",index= 8,valueMapping ="0=待下发;1=已下发;2=下发成功;3=已取消;4=下发失败" )
    private Integer sendStatus;
    @ApiModelProperty(value = "下发类型 0实时 1定时 ", example = "1")
@@ -147,5 +147,17 @@
    @ApiModelProperty(value = "时间段0,7,30")
    @TableField(exist = false)
    private Integer timeDn;
    @ApiModelProperty(value = "时间段0,7,30")
    @TableField(exist = false)
    private String deviceChannelNo;
    @ApiModelProperty(value = "海康设备类型code")
    @TableField(exist = false)
    private String deviceType;
    @ApiModelProperty(value = "海康设备ode")
    @TableField(exist = false)
    private String deviceIndexCode;
    @ApiModelProperty(value = "人员海康编码")
    @TableField(exist = false)
    private String memberHkId;
}
server/dmvisit_service/src/main/java/com/doumee/dao/business/model/ParkBook.java
@@ -132,5 +132,9 @@
    @ExcelColumn(name="部门")
    @TableField(exist = false)
    private String companyName;
    @ApiModelProperty(value = "停车库海康编码", example = "1")
    @ExcelColumn(name="停车库海康编码")
    @TableField(exist = false)
    private String parkHkId;
}
server/dmvisit_service/src/main/java/com/doumee/service/business/HkSyncService.java
@@ -60,4 +60,7 @@
    void syncVisitData();
    void syncEmpowerData();
    void syncParkBookData();
    void syncEmpowerResultData();
    void syncEmpowerDetailData();
}
server/dmvisit_service/src/main/java/com/doumee/service/business/impl/erp/ErpSyncServiceImpl.java
@@ -814,10 +814,13 @@
     */
    private void dealMemberRoleEmpower(Member member, List<Integer> doorIds,Date startTime,Date endTime ) {
        //删除所有老的授权信息
        empowerMapper.update(null,new UpdateWrapper<Empower>().lambda()
//        empowerMapper.update(null,new UpdateWrapper<Empower>().lambda()
//                .eq(Empower::getMemberId,member.getId())
//                .set(Empower::getIsdeleted,Constants.ONE)
//                .set(Empower::getSendStatus,Constants.ZERO)
//                );
        empowerMapper.delete(new UpdateWrapper<Empower>().lambda()
                .eq(Empower::getMemberId,member.getId())
                .set(Empower::getIsdeleted,Constants.ONE)
                .set(Empower::getSendStatus,Constants.ZERO)
                );
        if(doorIds==null || doorIds.size() == 0){
          return;
@@ -949,8 +952,7 @@
        try{
            if(Objects.isNull(param)
                    ||Objects.isNull(param.getId())
                    ||Objects.isNull(param.getStatus())
            ){
                    ||Objects.isNull(param.getStatus())){
                throw new BusinessException(ResponseStatus.BAD_REQUEST);
            }
            if(!(param.getStatus()==Constants.ZERO||param.getStatus()==Constants.ONE)){
server/dmvisit_service/src/main/java/com/doumee/service/business/impl/hksync/HkSyncBaseServiceImpl.java
@@ -85,5 +85,14 @@
    @Override
    public  void syncEmpowerData() {
    }
    @Override
    public  void syncParkBookData() {
    }
    @Override
    public     void syncEmpowerResultData() {
    }
    @Override
    public     void syncEmpowerDetailData() {
    }
}
server/dmvisit_service/src/main/java/com/doumee/service/business/impl/hksync/HkSyncDeviceServiceImpl.java
@@ -7,10 +7,9 @@
import com.doumee.core.haikang.model.HKConstants;
import com.doumee.core.haikang.model.param.BaseResponse;
import com.doumee.core.haikang.model.param.request.AcsDeviceListRequest;
import com.doumee.core.haikang.model.param.request.DoorsListRequest;
import com.doumee.core.haikang.model.param.request.ParkListRequest;
import com.doumee.core.haikang.model.param.respose.AcsDeviceInfoResponse;
import com.doumee.core.haikang.model.param.respose.AcsDeviceListResponse;
import com.doumee.core.haikang.model.param.respose.ParkListResponse;
import com.doumee.core.haikang.model.param.respose.*;
import com.doumee.core.haikang.service.HKService;
import com.doumee.core.utils.Constants;
import com.doumee.core.utils.DateUtil;
@@ -45,26 +44,85 @@
    @Override
//    @Async
    public String syncHkDevices(AcsDeviceListRequest param){
        List<Device> deleteList = new ArrayList<>();
        List<Device> addList = new ArrayList<>();
        List<Device> editList = new ArrayList<>();
        List<AcsDeviceInfoResponse> allHkList = new ArrayList<>();
        if(Constants.DEALING_HK_SYNCDEVICE){
            throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "同步任务正在执行哦,请稍后查看结果!") ;
        }
        Constants.DEALING_HK_SYNCDEVICE =true;
        try {
            List<Device> deleteList = new ArrayList<>();
            List<Device> addList = new ArrayList<>();
            List<Device> editList = new ArrayList<>();
            List<AcsDeviceInfoResponse> allHkList = new ArrayList<>();
            Date date = new Date();
            //查询全部门禁设备数据
            List<Device> allList = deviceMapper.selectList(null);
            boolean hasNext = true;
            int curTotal = 0;
            int curPage = 1;
            while (hasNext){
                //分页遍历循环查询所有门禁设备数据
                param = new AcsDeviceListRequest();
                param.setPageNo(curPage);
                param.setPageSize(100);
                BaseResponse<AcsDeviceListResponse> response = HKService.acsDeviceList(param);
                if(response == null || !StringUtils.equals(response.getCode(), HKConstants.RESPONSE_SUCCEE)){
                    throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "对不起,海康同步数据失败~");
                }
                AcsDeviceListResponse r = response.getData();
                curTotal += 100;
                if(curTotal >= r.getTotal()){
                    hasNext = false;
                }
                if(r.getList() == null || r.getList().size()==0){
                    hasNext =false;
                }else{
                    allHkList.addAll(r.getList());
                }
                curPage++;
            }
            /**
             * èŽ·å–å¢žåˆ æ”¹æ•°æ®é›†åˆ
             */
            getDataChangeList(allList,allHkList,addList,editList,deleteList,date);
            if(deleteList.size()>0){
                //逻辑删除
                for(Device d : deleteList){
                    deviceMapper.updateById(d);
                }
            }
            if(addList.size()>0){
                deviceMapper.insertBatchSomeColumn(addList);
            }
            if(editList.size()>0){
                for(Device d : editList){
                    deviceMapper.updateById(d);
                }
            }
            return "同步数据:新增【"+addList.size()+"】条,更新【"+editList.size()+"】条,删除【"+deleteList.size()+"】条";
        }catch (Exception e){
            e.printStackTrace();
            throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "同步失败!");
        }finally {
            Constants.DEALING_HK_SYNCDEVICE =false;
        }
    }
    public  List<DoorsInfoResponse>  getAllDoorList(){
        List<DoorsInfoResponse> allDoorList = new ArrayList<>();
        Date date = new Date();
        //查询全部门禁设备数据
        List<Device> allList = deviceMapper.selectList(null);
        boolean hasNext = true;
        int curTotal = 0;
        int curPage = 1;
        while (hasNext){
            //分页遍历循环查询所有门禁设备数据
            param = new AcsDeviceListRequest();
            DoorsListRequest param = new DoorsListRequest();
            param.setPageNo(curPage);
            param.setPageSize(100);
            BaseResponse<AcsDeviceListResponse> response = HKService.acsDeviceList(param);
            BaseResponse<DoorsListResponse> response = HKService.doorSearch(param);
            if(response == null || !StringUtils.equals(response.getCode(), HKConstants.RESPONSE_SUCCEE)){
                throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "对不起,海康同步数据失败~");
            }
            AcsDeviceListResponse r = response.getData();
            DoorsListResponse r = response.getData();
            curTotal += 100;
            if(curTotal >= r.getTotal()){
                hasNext = false;
@@ -72,43 +130,27 @@
            if(r.getList() == null || r.getList().size()==0){
                hasNext =false;
            }else{
                allHkList.addAll(r.getList());
                allDoorList.addAll(r.getList());
            }
            curPage++;
        }
        /**
         * èŽ·å–å¢žåˆ æ”¹æ•°æ®é›†åˆ
         */
        getDataChangeList(allList,allHkList,addList,editList,deleteList,date);
        if(deleteList.size()>0){
            //逻辑删除
            for(Device d : deleteList){
                deviceMapper.updateById(d);
            }
        }
        if(addList.size()>0){
            deviceMapper.insertBatchSomeColumn(addList);
        }
        if(editList.size()>0){
            for(Device d : editList){
                deviceMapper.updateById(d);
            }
        }
        return "同步数据:新增【"+addList.size()+"】条,更新【"+editList.size()+"】条,删除【"+deleteList.size()+"】条";
        return  allDoorList;
    }
    private void getDataChangeList(List<Device> allList, List<AcsDeviceInfoResponse> allHkList, List<Device> addList, List<Device> editList,List<Device> deleteList, Date date) {
        if(allHkList!=null && allHkList.size()>0){
            //获取海康全部门禁组数据
            List<DoorsInfoResponse> hkDoorList = getAllDoorList();
            for(AcsDeviceInfoResponse device : allHkList){
                Device model = getExistedDevice(device,allList);
                if(model !=null){
                    //如果已存在,则更新数据
                    model =  initDataByHkData(model,device,date);
                    model =  initDataByHkData(model,device,date,hkDoorList);
                    editList.add(model);
                }else{
                    //如果不存在,则新增数据
                    model = new Device();
                    model =  initDataByHkData(model,device,date);
                    model =  initDataByHkData(model,device,date,hkDoorList);
                    addList.add(model);
                }
            }
@@ -124,7 +166,7 @@
     * @param date
     * @return
     */
    private Device initDataByHkData(Device model, AcsDeviceInfoResponse device,Date date) {
    private Device initDataByHkData(Device model, AcsDeviceInfoResponse device,Date date, List<DoorsInfoResponse> hkDoorList) {
        model.setIsdeleted(Constants.ZERO);
        model.setIp(device.getIp());
        model.setHkDate(date);
@@ -137,7 +179,7 @@
        model.setManufature(device.getManufacturer());
        model.setType(Constants.ZERO);
//        model.setNo(device.getDevSerialNum());
//        model.setChannelNo(device);
        model.setChannelNo(getChannelNo(device.getIndexCode(),hkDoorList));
        model.setResourceType(device.getResourceType());
        model.setDevTypeCode(device.getDevTypeCode());
        model.setManufature(device.getManufacturer());
@@ -146,6 +188,24 @@
        return  model;
    }
    private String getChannelNo(String indexCode, List<DoorsInfoResponse> hkDoorList) {
        String str = "";
        if(hkDoorList!=null && hkDoorList.size()>0){
            for(DoorsInfoResponse info : hkDoorList){
                if(StringUtils.equals(indexCode,info.getParentIndexCode())){
                    if(StringUtils.isBlank(info.getChannelNo())){
                        continue;
                    }
                    if(StringUtils.isNotBlank(str)){
                        str += ",";
                    }
                    str+=info.getChannelNo();
                }
            }
        }
        return str;
    }
    private Device getExistedDevice(AcsDeviceInfoResponse device, List<Device> allList) {
        if(allList.size()>0){
            for(Device r : allList){
server/dmvisit_service/src/main/java/com/doumee/service/business/impl/hksync/HkSyncDoorsServiceImpl.java
@@ -7,10 +7,8 @@
import com.doumee.core.haikang.model.param.BaseResponse;
import com.doumee.core.haikang.model.param.request.AcsDeviceListRequest;
import com.doumee.core.haikang.model.param.request.DoorsListRequest;
import com.doumee.core.haikang.model.param.respose.*;
import com.doumee.core.haikang.model.param.respose.DoorsInfoResponse;
import com.doumee.core.haikang.model.param.respose.AcsDeviceListResponse;
import com.doumee.core.haikang.model.param.respose.DoorsInfoResponse;
import com.doumee.core.haikang.model.param.respose.DoorsListResponse;
import com.doumee.core.haikang.service.HKService;
import com.doumee.core.utils.Constants;
import com.doumee.core.utils.DateUtil;
@@ -43,56 +41,68 @@
    @Override
//    @Async
    public String syncDoors(DoorsListRequest param){
        List<Device> deleteList = new ArrayList<>();
        List<Device> addList = new ArrayList<>();
        List<Device> editList = new ArrayList<>();
        List<DoorsInfoResponse> allHkList = new ArrayList<>();
        Date date = new Date();
        //查询全部门禁设备数据
        List<Device> allList = deviceMapper.selectList(null);
        boolean hasNext = true;
        int curTotal = 0;
        int curPage = 1;
        while (hasNext){
            //分页遍历循环查询所有门禁设备数据
            param = new DoorsListRequest();
            param.setPageNo(curPage);
            param.setPageSize(100);
            BaseResponse<DoorsListResponse> response = HKService.doorSearch(param);
            if(response == null || !StringUtils.equals(response.getCode(), HKConstants.RESPONSE_SUCCEE)){
                throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "对不起,海康同步数据失败~");
            }
            DoorsListResponse r = response.getData();
            curTotal += 100;
            if(curTotal >= r.getTotal()){
                hasNext = false;
            }
            if(r.getList() == null || r.getList().size()==0){
                hasNext =false;
            }else{
                allHkList.addAll(r.getList());
            }
            curPage++;
        if(Constants.DEALING_HK_SYNCDEVICE){
            throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "同步任务正在执行哦,请稍后查看结果!") ;
        }
        /**
         * èŽ·å–å¢žåˆ æ”¹æ•°æ®é›†åˆ
         */
        getDataChangeList(allList,allHkList,addList,editList,deleteList,date);
        if(deleteList.size()>0){
            //逻辑删除
            for(Device d : deleteList){
                deviceMapper.updateById(d);
        Constants.DEALING_HK_SYNCDEVICE =true;
        try {
            List<Device> deleteList = new ArrayList<>();
            List<Device> addList = new ArrayList<>();
            List<Device> editList = new ArrayList<>();
            List<DoorsInfoResponse> allHkList = new ArrayList<>();
            Date date = new Date();
            //查询全部门禁设备数据
            List<Device> allList = deviceMapper.selectList(null);
            boolean hasNext = true;
            int curTotal = 0;
            int curPage = 1;
            while (hasNext){
                //分页遍历循环查询所有门禁设备数据
                param = new DoorsListRequest();
                param.setPageNo(curPage);
                param.setPageSize(100);
                BaseResponse<DoorsListResponse> response = HKService.doorSearch(param);
                if(response == null || !StringUtils.equals(response.getCode(), HKConstants.RESPONSE_SUCCEE)){
                    throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "对不起,海康同步数据失败~");
                }
                DoorsListResponse r = response.getData();
                curTotal += 100;
                if(curTotal >= r.getTotal()){
                    hasNext = false;
                }
                if(r.getList() == null || r.getList().size()==0){
                    hasNext =false;
                }else{
                    allHkList.addAll(r.getList());
                }
                curPage++;
            }
        }
        if(addList.size()>0){
            deviceMapper.insertBatchSomeColumn(addList);
        }
        if(editList.size()>0){
            for(Device d : editList){
                deviceMapper.updateById(d);
            /**
             * èŽ·å–å¢žåˆ æ”¹æ•°æ®é›†åˆ
             */
            getDataChangeList(allList,allHkList,addList,editList,deleteList,date);
            if(deleteList.size()>0){
                //逻辑删除
                for(Device d : deleteList){
                    deviceMapper.updateById(d);
                }
            }
            if(addList.size()>0){
                deviceMapper.insertBatchSomeColumn(addList);
            }
            if(editList.size()>0){
                for(Device d : editList){
                    deviceMapper.updateById(d);
                }
            }
            return "同步数据:新增【"+addList.size()+"】条,更新【"+editList.size()+"】条,删除【"+deleteList.size()+"】条";
        }catch (Exception e){
            e.printStackTrace();
            throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "同步失败!");
        }finally {
            Constants.DEALING_HK_SYNCDEVICE =false;
        }
        return "同步数据:新增【"+addList.size()+"】条,更新【"+editList.size()+"】条,删除【"+deleteList.size()+"】条";
    }
    private void getDataChangeList(List<Device> allList, List<DoorsInfoResponse> allHkList, List<Device> addList, List<Device> editList,List<Device> deleteList, Date date) {
server/dmvisit_service/src/main/java/com/doumee/service/business/impl/hksync/HkSyncEmpowerServiceImpl.java
@@ -1,14 +1,20 @@
package com.doumee.service.business.impl.hksync;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.exception.BusinessException;
import com.doumee.core.haikang.model.HKConstants;
import com.doumee.core.haikang.model.param.BaseResponse;
import com.doumee.core.haikang.model.param.request.VisitAppointmentRequest;
import com.doumee.core.haikang.model.param.respose.VisitAppointmentResponse;
import com.doumee.core.haikang.model.param.request.*;
import com.doumee.core.haikang.model.param.respose.*;
import com.doumee.core.haikang.service.HKService;
import com.doumee.core.utils.Constants;
import com.doumee.core.utils.DateUtil;
import com.doumee.dao.business.DeviceMapper;
import com.doumee.dao.business.join.EmpowerJoinMapper;
import com.doumee.dao.business.join.VisitsJoinMapper;
import com.doumee.dao.business.model.Device;
import com.doumee.dao.business.model.Empower;
import com.doumee.dao.business.model.Member;
import com.doumee.dao.business.model.Visits;
@@ -18,6 +24,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@@ -30,48 +37,119 @@
@Slf4j
public class HkSyncEmpowerServiceImpl extends HkSyncBaseServiceImpl {
    @Autowired
    private EmpowerJoinMapper empowerJoinMapper;
    private EmpowerJoinMapper empowerMapper;
    @Autowired
    private DeviceMapper deviceMapper;
    /**
     * åŒæ­¥æµ·åº·ç»„织信息,根据erp同步组织结果,定时检查需要下发到海康的组织信息
     * å®šæ—¶æŸ¥è¯¢æƒé™ä¸‹å‘任务进度执行结果
     */
    @Override
    public  void syncEmpowerData(){
    public  void syncEmpowerDetailData(){
        if(Constants.DEALING_HK_EMPOWER_DETAIL){
            return   ;
        }
        Constants.DEALING_HK_EMPOWER_DETAIL = true;
        try {
            //查询所有完成下载,待查询结果的数据记录
            List<Empower>  list = getDealListDetail();
           if(list == null || list.size() ==0){
               return;
           }
           for(Empower c : list){
               AuthItemListRequest param = new AuthItemListRequest();
               param.setPageNo(1);
               param.setPageSize(100);
               param.setPersonIds(new ArrayList<>());
               AuthItemListPersonRequest p = new AuthItemListPersonRequest();
               p.setPersonIds(c.getMemberHkId());
               param.getPersonIds().add(p);
               TaskDataAdditionResourceRequest rec = new TaskDataAdditionResourceRequest();
               rec.setResourceIndexCode(c.getDeviceIndexCode());
               rec.setResourceType(c.getDeviceType());
               rec.setChannelNos(c.getDeviceChannelNo().split(","));
               param.setResourceInfos(rec);
               //查询已下载
               param.setPersonStatus(new Integer[]{3});
               //查询下发状态
               BaseResponse<AuthItemListResponse> response = HKService.authItemList(param);
               if(response!=null
                       && StringUtils.equals(response.getCode(),HKConstants.RESPONSE_SUCCEE)
                       && response.getData()!=null
                       && response.getData().getList() != null
                       && response.getData().getList().size()>0 ){
                   //更新已完成下载任务
                   empowerMapper.update(null,new UpdateWrapper<Empower>()
                           .lambda()
                           .eq(Empower::getHkId,c.getHkId() )
                           .set(Empower::getSendStatus,Constants.EmpowerStatus.pass) );
               }
           }
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            Constants.DEALING_HK_EMPOWER_DETAIL=false;
        }
    }
    /**
     * å®šæ—¶æŸ¥è¯¢æƒé™ä¸‹å‘任务进度执行结果
     */
    @Override
    public  void syncEmpowerResultData(){
        if(Constants.DEALING_HK_EMPOWER_RESULT){
            return   ;
        }
        Constants.DEALING_HK_EMPOWER_RESULT=true;
        try {
            //查询所有执行中得数据
            List<Empower>  list = getIngTaskListResult();
           if(list == null || list.size() ==0){
               return;
           }
           for(Empower c : list){
               TaskProgressRequest param = new TaskProgressRequest();
               param.setTaskId(c.getHkId());
               //查询下发状态
               BaseResponse<TaskProgressNumResponse> response = HKService.taskProgressNum(param);
               if(response!=null
                       && StringUtils.equals(response.getCode(),HKConstants.RESPONSE_SUCCEE)
                       && response.getData()!=null
                       && response.getData().getIsDownloadFinished() != null
                       && response.getData().getIsDownloadFinished() ){
                   //更新已完成下载任务
                   empowerMapper.update(null,new UpdateWrapper<Empower>()
                           .lambda()
                           .eq(Empower::getHkId,c.getHkId() )
                           .set(Empower::getSendStatus,Constants.EmpowerStatus.downloaded) );
               }
           }
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            Constants.DEALING_HK_EMPOWER_RESULT =false;
        }
    }
    /**
     * å¤„理人员授权数据,定时下发
     */
    @Override
    public  void syncEmpowerData() {
        if(Constants.DEALING_HK_EMPOWER){
            return   ;
        }
        Constants.DEALING_HK_EMPOWER =true;
        try {
            //查询所有需要同步的企业数据
            MPJLambdaWrapper<Empower> queryWrapper = new MPJLambdaWrapper<>();
            queryWrapper.selectAll(Empower.class);
            queryWrapper.selectAs(Member::getName,Visits::getReceptMemberName)
                        .select("t1.hk_id as receptMemberHkId")
                        .leftJoin(Member.class,Member::getId,Visits::getReceptMemberId);
            queryWrapper.eq(Visits::getStatus,Constants.VisitStatus.pass)//审批通过
                    .eq(Visits::getHkStatus,Constants.ZERO)//未同步到海康
                    .orderByAsc(Visits::getCreateDate);
            List<Empower> list = empowerJoinMapper.selectJoinList(Empower.class,queryWrapper);
            if(list ==null || list.size()==0){
                return;
            }
            Date date = new Date();
            for(Empower c : list) {
                //删除的数据,进行删除
                VisitAppointmentRequest request = new VisitAppointmentRequest();
                BaseResponse<VisitAppointmentResponse> response = HKService.visitAppiontment(request);
                if (response != null
                        && StringUtils.equals(response.getCode(), HKConstants.RESPONSE_SUCCEE)
                        &&response.getData()!=null
                        &&StringUtils.isNotBlank(response.getData().getAppointRecordId())) {
                    //海康下发成功
                    c.setHkId( response.getData().getAppointRecordId());//预约标识
                } else {
                    //海康下发成功
                }
                empowerJoinMapper.updateById(c);
            }
            //先删除所有需要取消授权的数据
//            dealDelListTask(getDealList(Constants.ONE));
            //查询所有需要同步的数据
            dealNewListTask(getDealList(Constants.ZERO));
        }catch (Exception e){
            e.printStackTrace();
        }finally {
@@ -79,4 +157,241 @@
        }
    }
    private void dealDelListTask(List<Empower> list) {
        //按照父级申请分批处理每次申请数据
        if(list ==null || list.size()==0){
            return;
        }
        Date date = new Date();
        //创建任务
        String taskId = hkTaskAddtion();
        List<Empower> successList = new ArrayList<>();
        List<Empower> errorList = new ArrayList<>();
        for(Empower c : list) {
            //向任务添加人员、设备信息数据
            if(addTaskData(c,taskId,HKConstants.OPERA_TYPE.DEL.getKey())){
                successList.add(c);
            }else{
                errorList.add(c);
            }
        }
        if(successList.size()>0){
            //开始执行下发
            boolean status = startTask(taskId);
            for(Empower model : successList){
                Empower update = new Empower();
                update.setId(model.getId());
                update.setSendDate(date);
                update.setEditDate(date);
                update.setHkId(taskId);
                update.setRemark(status?"下发任务成功":"下发任务失败");
                //下发中
                update.setSendStatus(status?Constants.EmpowerStatus.ing:Constants.EmpowerStatus.fail);
            }
        }
        for(Empower model : errorList){
            Empower update = new Empower();
            update.setId(model.getId());
            update.setSendDate(date);
            update.setEditDate(date);
            update.setHkId(taskId);
            update.setSendStatus(Constants.EmpowerStatus.fail);
            update.setRemark( "添加下发任务数据刪除授权失败");
            empowerMapper.updateById(update);
        }
    }
    private void dealNewListTask(List<Empower> list) {
        //按照父级申请分批处理每次申请数据
        if(list ==null || list.size()==0){
            return;
        }
        clearAllEmpowerFirst(list);
        Date date = new Date();
        //创建任务
        String taskId = hkTaskAddtion();
        List<Empower> successList = new ArrayList<>();
        List<Empower> errorList = new ArrayList<>();
        for(Empower c : list) {
            //向任务添加人员、设备信息数据
            if(addTaskData(c,taskId,HKConstants.OPERA_TYPE.ADD.getKey())){
                successList.add(c);
            }else{
                errorList.add(c);
            }
        }
        if(successList.size()>0){
            //开始执行下发
            boolean status = startTask(taskId);
            for(Empower model : successList){
                Empower update = new Empower();
                update.setId(model.getId());
                update.setSendDate(date);
                update.setEditDate(date);
                update.setHkId(taskId);
                update.setRemark(status?"下发任务成功":"下发任务失败");
                //下发中
                update.setSendStatus(status?Constants.EmpowerStatus.ing:Constants.EmpowerStatus.fail);
                empowerMapper.updateById(update);
            }
        }
        for(Empower model : errorList){
            Empower update = new Empower();
            update.setId(model.getId());
            update.setSendDate(date);
            update.setEditDate(date);
            update.setHkId(taskId);
            update.setSendStatus(Constants.EmpowerStatus.fail);
            update.setRemark( "添加下发任务数据失败");
            empowerMapper.updateById(update);
        }
    }
    private void clearAllEmpowerFirst(List<Empower> list) {
        //查询全部数据
        List<Device> allDevice = deviceMapper.selectList(new QueryWrapper<Device>().lambda().isNotNull(Device::getHkId));
        //创建任务
        String taskId = hkTaskAddtion();
        for(Empower c : list) {
            //向任务添加人员、设备信息数据
            addTaskDataAll(c,taskId,allDevice);
        }
        startTask(taskId);
    }
    private boolean addTaskData(Empower c,String taskId,int type) {
        if(StringUtils.isBlank(c.getMemberHkId() )
                ||StringUtils.isBlank(c.getDeviceChannelNo())
                ||StringUtils.isBlank(c.getDeviceType())
                ||StringUtils.isBlank(c.getDeviceIndexCode())){
            //必填参数校验
            return  false;
        }
        TaskDataAdditionRequest param = new TaskDataAdditionRequest();
        param.setTaskId(taskId);
        List<TaskDataAdditionResourceRequest> resourceInfos = new ArrayList<>();//    object[]    True    èµ„源对象
        TaskDataAdditionResourceRequest res = new TaskDataAdditionResourceRequest();
        res.setChannelNos(c.getDeviceChannelNo().split(","));
        res.setResourceType(c.getDeviceType());
        res.setResourceIndexCode(c.getDeviceIndexCode());
        resourceInfos.add(res);
        List<TaskDataAdditionPersonRequest> personInfos = new ArrayList<>();
        TaskDataAdditionPersonRequest pinfo = new TaskDataAdditionPersonRequest();
        pinfo.setName(c.getMemberName());
        pinfo.setEndTime(DateUtil.getISO8601Timestamp(c.getEndTime()));
        pinfo.setStartTime(DateUtil.getISO8601Timestamp(c.getStartTime()));
        pinfo.setOperatorType(type);
        pinfo.setPersonId(c.getMemberHkId());
        param.setResourceInfos(resourceInfos);
        param.setPersonInfos(personInfos);
        BaseResponse response =  HKService.taskDataAddition(param);
        if(response!=null
                && StringUtils.equals(response.getCode(),HKConstants.RESPONSE_SUCCEE)){
            return true;
        }else{
            return  false;
        }
    }
    private boolean addTaskDataAll(Empower c,String taskId,List<Device> deviceList) {
        if(StringUtils.isBlank(c.getMemberHkId() )
                ||StringUtils.isBlank(c.getDeviceChannelNo())
                ||StringUtils.isBlank(c.getDeviceType())
                ||StringUtils.isBlank(c.getDeviceIndexCode())){
            //必填参数校验
            return  false;
        }
        TaskDataAdditionRequest param = new TaskDataAdditionRequest();
        param.setTaskId(taskId);
        List<TaskDataAdditionResourceRequest> resourceInfos = new ArrayList<>();//    object[]    True    èµ„源对象
        for(Device d:deviceList){
            TaskDataAdditionResourceRequest res = new TaskDataAdditionResourceRequest();
            res.setChannelNos(d.getChannelNo().split(","));
            res.setResourceType(d.getResourceType());
            res.setResourceIndexCode(c.getDeviceIndexCode());
            resourceInfos.add(res);
        }
        List<TaskDataAdditionPersonRequest> personInfos = new ArrayList<>();
        TaskDataAdditionPersonRequest pinfo = new TaskDataAdditionPersonRequest();
        pinfo.setName(c.getMemberName());
        pinfo.setEndTime(DateUtil.getISO8601Timestamp(c.getEndTime()));
        pinfo.setStartTime(DateUtil.getISO8601Timestamp(c.getStartTime()));
        pinfo.setOperatorType(HKConstants.OPERA_TYPE.DEL.getKey());
        pinfo.setPersonId(c.getMemberHkId());
        param.setResourceInfos(resourceInfos);
        param.setPersonInfos(personInfos);
        BaseResponse response =  HKService.taskDataAddition(param);
        if(response!=null
                && StringUtils.equals(response.getCode(),HKConstants.RESPONSE_SUCCEE)){
            return true;
        }else{
            return  false;
        }
    }
    private boolean startTask(String taskId) {
        TaskProgressRequest param = new TaskProgressRequest();
        param.setTaskId(taskId);
        BaseResponse response =  HKService.taskStart(param);
        if(response!=null
                && StringUtils.equals(response.getCode(),HKConstants.RESPONSE_SUCCEE)){
            return true;
        }else{
            return  false;
        }
    }
    private String hkTaskAddtion() {
        TaskAdditionRequest param = new TaskAdditionRequest();
        param.setTaskType(HKConstants.TASK_TYPE.FACE.getKey());
        BaseResponse<TaskAdditionResponse> response = HKService.taskAddition(param);
        if(response!=null
                && StringUtils.equals(response.getCode(),HKConstants.RESPONSE_SUCCEE)
                && response.getData()!=null
                && StringUtils.isNotBlank(response.getData().getTaskId())){
            return  response.getData().getTaskId();
        }else{
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "海康创建下载任务失败==================");
        }
    }
    private List<Empower> getDealList(int del ) {
        MPJLambdaWrapper<Empower> queryWrapper = new MPJLambdaWrapper<>();
        queryWrapper.selectAll(Empower.class);
        queryWrapper.selectAs(Device::getChannelNo,Empower::getDeviceChannelNo);
        queryWrapper.selectAs(Member::getHkId,Empower::getMemberHkId);
        queryWrapper.selectAs(Device::getHkId,Empower::getDeviceIndexCode);
        queryWrapper.selectAs(Device::getResourceType,Empower::getDeviceType);
        queryWrapper.leftJoin(Device.class,Device::getId,Empower::getDeviceId);
        queryWrapper.leftJoin(Member.class,Member::getId,Empower::getMemberId);
        queryWrapper.eq(Empower::getSendStatus,Constants.EmpowerStatus.wait);
//        queryWrapper.eq( Empower::getIsdeleted,del);
//        queryWrapper.last("limit 100");//每次限制下发100个
        List<Empower> list = empowerMapper.selectJoinList(Empower.class,queryWrapper);
        return list;
    }
    private List<Empower> getDealListDetail() {
        MPJLambdaWrapper<Empower> queryWrapper = new MPJLambdaWrapper<>();
        queryWrapper.selectAll(Empower.class);
        queryWrapper.selectAs(Device::getChannelNo,Empower::getDeviceChannelNo);
        queryWrapper.selectAs(Member::getHkId,Empower::getMemberHkId);
        queryWrapper.leftJoin(Member.class,Member::getId,Empower::getMemberId);
        queryWrapper.selectAs(Device::getHkId,Empower::getDeviceIndexCode);
        queryWrapper.selectAs(Device::getDevTypeCode,Empower::getDeviceType);
        queryWrapper.leftJoin(Device.class,Device::getId,Empower::getDeviceId);
        queryWrapper.eq(Empower::getSendStatus,Constants.EmpowerStatus.downloaded);
        List<Empower> list = empowerMapper.selectJoinList(Empower.class,queryWrapper);
        return list;
    }
    private List<Empower> getIngTaskListResult() {
        MPJLambdaWrapper<Empower> queryWrapper = new MPJLambdaWrapper<>();
        queryWrapper.selectAll(Empower.class);
        queryWrapper.eq(Empower::getSendStatus,Constants.EmpowerStatus.ing);
        queryWrapper.groupBy(Empower::getHkId);
        List<Empower> list = empowerMapper.selectJoinList(Empower.class,queryWrapper);
        return list;
    }
}
server/dmvisit_service/src/main/java/com/doumee/service/business/impl/hksync/HkSyncParkServiceImpl.java
@@ -1,10 +1,13 @@
package com.doumee.service.business.impl.hksync;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.exception.BusinessException;
import com.doumee.core.haikang.model.HKConstants;
import com.doumee.core.haikang.model.param.BaseResponse;
import com.doumee.core.haikang.model.param.request.AcsDeviceListRequest;
import com.doumee.core.haikang.model.param.request.CarChargeAddRequest;
import com.doumee.core.haikang.model.param.request.CarChargeDelRequest;
import com.doumee.core.haikang.model.param.request.ParkListRequest;
import com.doumee.core.haikang.model.param.respose.AcsDeviceInfoResponse;
import com.doumee.core.haikang.model.param.respose.AcsDeviceListResponse;
@@ -13,9 +16,12 @@
import com.doumee.core.utils.Constants;
import com.doumee.core.utils.DateUtil;
import com.doumee.dao.business.DeviceMapper;
import com.doumee.dao.business.ParkBookMapper;
import com.doumee.dao.business.ParksMapper;
import com.doumee.dao.business.model.Device;
import com.doumee.dao.business.model.Parks;
import com.doumee.dao.business.join.ParkBookJoinMapper;
import com.doumee.dao.business.join.ParksJoinMapper;
import com.doumee.dao.business.model.*;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -34,7 +40,97 @@
    @Autowired
    private ParksMapper parksMapper;
    @Autowired
    private ParkBookJoinMapper parkBookMapper;
    @Override
    public  void syncParkBookData() {
        if(Constants.DEALING_HK_PARKBOOK){
            return   ;
        }
        Constants.DEALING_HK_PARKBOOK =true;
        try {
            //查询所有需要同步的数据
            List<ParkBook> list =getDealList ();
            if(list ==null || list.size()==0){
                return;
            }
            Date date = new Date();
            //先出所有需要取消包期的数据记录
            for(ParkBook c : list) {
                if(Constants.equalsObject(c.getIsdeleted(),Constants.ONE)){
                    //如果取消预约,则进行取消包期
                    if(StringUtils.isNotBlank(c.getParkHkId())
                            && StringUtils.isNotBlank(c.getCarCode())){
                       boolean result =  cancelParkBookHk(c);
                        c.setHkStatus(result?Constants.ONE:Constants.TWO);
                    }else{
                        c.setHkStatus(Constants.TWO);//下发失败
                    }
                    c.setHkDate(date);
                    parkBookMapper.updateById(c);
                }
            }
            //处理所有需要包期的车辆数据记录
            for(ParkBook c : list) {
                if(Constants.equalsObject(c.getIsdeleted(),Constants.ONE)) {
                    //删除的已处理,跳过处理
                    continue;
                }
                //数据不合法,直接提示下发失败
                if(StringUtils.isNotBlank(c.getParkHkId())
                        && StringUtils.isNotBlank(c.getCarCode())){
                    boolean result =  addParkBookHk(c);
                    c.setHkStatus(result?Constants.ONE:Constants.TWO);
                }else{
                    c.setHkStatus(Constants.TWO);
                }
                c.setHkDate(date);
                parkBookMapper.updateById(c);
            }
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            Constants.DEALING_HK_PARKBOOK =false;
        }
    }
    private boolean addParkBookHk(ParkBook c) {
        CarChargeAddRequest param = new CarChargeAddRequest();
        param.setPlateNo(c.getCarCode());
        param.setParkSyscode(c.getParkHkId());
        param.setStartTime(DateUtil.getISO8601Timestamp(c.getStartTime()));
        param.setEndTime(DateUtil.getISO8601Timestamp(c.getEndTime()));
        BaseResponse response = HKService.carChargeAddtion(param);
        if(response!=null
                && StringUtils.equals(response.getCode(),HKConstants.RESPONSE_SUCCEE)){
            return true;
        }else{
            return  false;
        }
    }
    private boolean cancelParkBookHk(ParkBook c) {
        CarChargeDelRequest param = new CarChargeDelRequest();
        param.setPlateNo(c.getCarCode());
        param.setParkSyscode(c.getParkHkId());
        BaseResponse response = HKService.carChargeDeletion(param);
        if(response!=null
                && StringUtils.equals(response.getCode(),HKConstants.RESPONSE_SUCCEE)){
            return true;
        }else{
            return  false;
        }
    }
    private List<ParkBook> getDealList() {
        MPJLambdaWrapper<ParkBook> queryWrapper = new MPJLambdaWrapper<>();
        queryWrapper.selectAll(ParkBook.class);
        queryWrapper.selectAs(Parks::getHkId,ParkBook::getParkHkId);
        queryWrapper.leftJoin(Parks.class,Parks::getId,ParkBook::getParkId);
        queryWrapper.selectAs(Device::getHkId,Empower::getDeviceIndexCode);
        List<ParkBook> list = parkBookMapper.selectJoinList(ParkBook.class,queryWrapper);
        return list;
    }
    /**
     * åŒæ­¥æµ·åº·åœè½¦åº“数据
     * @param param
@@ -43,36 +139,47 @@
    @Override
//    @Async
    public   String syncHkParks(ParkListRequest param){
        List<Parks> deleteList = new ArrayList<>();
        List<Parks> addList = new ArrayList<>();
        List<Parks> editList = new ArrayList<>();
        Date date = new Date();
        //查询全部当前数据
        List<Parks> allList = parksMapper.selectList(null);
        if(Constants.DEALING_HK_SYNCPRIVILEGE){
            throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "同步任务正在执行哦,请稍后查看结果!") ;
        }
        Constants.DEALING_HK_SYNCPRIVILEGE =true;
        try {
            List<Parks> deleteList = new ArrayList<>();
            List<Parks> addList = new ArrayList<>();
            List<Parks> editList = new ArrayList<>();
            Date date = new Date();
            //查询全部当前数据
            List<Parks> allList = parksMapper.selectList(null);
            //分页遍历循环查询所有门禁设备数据
        param = new ParkListRequest();
        BaseResponse<List<ParkListResponse>> response = HKService.parkList(param);
        if(response == null || !StringUtils.equals(response.getCode(), HKConstants.RESPONSE_SUCCEE)){
            throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "对不起,海康同步数据失败~");
        }
        List<ParkListResponse> allHkList = response.getData();
         // èŽ·å–å¢žåˆ æ”¹æ•°æ®é›†åˆ
        getDataChangeList(allList,allHkList,addList,editList,deleteList,date);
        if(deleteList.size()>0){
            //逻辑删除
            for(Parks d : deleteList){
                parksMapper.updateById(d);
            param = new ParkListRequest();
            BaseResponse<List<ParkListResponse>> response = HKService.parkList(param);
            if(response == null || !StringUtils.equals(response.getCode(), HKConstants.RESPONSE_SUCCEE)){
                throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "对不起,海康同步数据失败~");
            }
        }
        if(addList.size()>0){
            parksMapper.insertBatchSomeColumn(addList);
        }
        if(editList.size()>0){
            for(Parks d : editList){
                parksMapper.updateById(d);
            List<ParkListResponse> allHkList = response.getData();
            // èŽ·å–å¢žåˆ æ”¹æ•°æ®é›†åˆ
            getDataChangeList(allList,allHkList,addList,editList,deleteList,date);
            if(deleteList.size()>0){
                //逻辑删除
                for(Parks d : deleteList){
                    parksMapper.updateById(d);
                }
            }
            if(addList.size()>0){
                parksMapper.insertBatchSomeColumn(addList);
            }
            if(editList.size()>0){
                for(Parks d : editList){
                    parksMapper.updateById(d);
                }
            }
            return "同步数据:新增【"+addList.size()+"】条,更新【"+editList.size()+"】条,删除【"+deleteList.size()+"】条";
        }catch (Exception e){
            e.printStackTrace();
            throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "同步失败!");
        }finally {
            Constants.DEALING_HK_SYNCPRIVILEGE =false;
        }
        return "同步数据:新增【"+addList.size()+"】条,更新【"+editList.size()+"】条,删除【"+deleteList.size()+"】条";
    }
    private void getDataChangeList(List<Parks> allList, List<ParkListResponse> allHkList, List<Parks> addList, List<Parks> editList,List<Parks> deleteList, Date date) {
        if(allHkList!=null && allHkList.size()>0){
server/dmvisit_service/src/main/java/com/doumee/service/business/impl/hksync/HkSyncPrivilegeServiceImpl.java
@@ -5,12 +5,16 @@
import com.doumee.core.exception.BusinessException;
import com.doumee.core.haikang.model.HKConstants;
import com.doumee.core.haikang.model.param.BaseResponse;
import com.doumee.core.haikang.model.param.request.AcsDeviceListRequest;
import com.doumee.core.haikang.model.param.request.PrivilegeGroupRequest;
import com.doumee.core.haikang.model.param.respose.AcsDeviceInfoResponse;
import com.doumee.core.haikang.model.param.respose.AcsDeviceListResponse;
import com.doumee.core.haikang.model.param.respose.PrivilegeGroupInfoResponse;
import com.doumee.core.haikang.model.param.respose.PrivilegeGroupListResponse;
import com.doumee.core.haikang.service.HKService;
import com.doumee.core.utils.Constants;
import com.doumee.dao.business.DeviceRoleMapper;
import com.doumee.dao.business.model.Device;
import com.doumee.dao.business.model.DeviceRole;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
@@ -38,59 +42,71 @@
    @Override
//    @Async
    public String syncPrivilege(PrivilegeGroupRequest param){
        List<DeviceRole> deleteList = new ArrayList<>();
        List<DeviceRole> addList = new ArrayList<>();
        List<DeviceRole> editList = new ArrayList<>();
        List<PrivilegeGroupInfoResponse> allHkList = new ArrayList<>();
        Date date = new Date();
        //查询全部现有数据,只管理同步 è®¿å®¢ç»„
        List<Integer> types = new ArrayList<>();
        types.add(Constants.DOOR_ROLE_TYPE.fk);
        types.add(Constants.DOOR_ROLE_TYPE.lw);
        List<DeviceRole> allList = DeviceRoleMapper.selectList(new QueryWrapper<DeviceRole>().lambda().in(DeviceRole::getType,types));
        boolean hasNext = true;
        int curTotal = 0;
        int curPage = 1;
        while (hasNext){
            //分页遍历循环查询所有门禁设备数据
            param = new PrivilegeGroupRequest();
            param.setPageNo(curPage);
            param.setPageSize(100);
            BaseResponse<PrivilegeGroupListResponse> response = HKService.privilegeGroup(param);
            if(response == null || !StringUtils.equals(response.getCode(), HKConstants.RESPONSE_SUCCEE)){
                throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "对不起,海康同步数据失败~");
            }
            PrivilegeGroupListResponse r = response.getData();
            curTotal += 100;
            if(curTotal >= r.getTotal()){
                hasNext = false;
            }
            if(r.getList() == null || r.getList().size()==0){
                hasNext =false;
            }else{
                allHkList.addAll(r.getList());
            }
            curPage ++;
        if(Constants.DEALING_HK_SYNCDEVICE){
            throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "同步任务正在执行哦,请稍后查看结果!") ;
        }
        /**
         * èŽ·å–å¢žåˆ æ”¹æ•°æ®é›†åˆ
         */
        getDataChangeList(allList,allHkList,addList,editList,deleteList,date);
        if(deleteList.size()>0){
            //逻辑删除
            for(DeviceRole d : deleteList){
                DeviceRoleMapper.updateById(d);
        Constants.DEALING_HK_SYNCDEVICE =true;
        try {
            List<DeviceRole> deleteList = new ArrayList<>();
            List<DeviceRole> addList = new ArrayList<>();
            List<DeviceRole> editList = new ArrayList<>();
            List<PrivilegeGroupInfoResponse> allHkList = new ArrayList<>();
            Date date = new Date();
            //查询全部现有数据,只管理同步 è®¿å®¢ç»„
            List<Integer> types = new ArrayList<>();
            types.add(Constants.DOOR_ROLE_TYPE.fk);
            types.add(Constants.DOOR_ROLE_TYPE.lw);
            List<DeviceRole> allList = DeviceRoleMapper.selectList(new QueryWrapper<DeviceRole>().lambda().in(DeviceRole::getType,types));
            boolean hasNext = true;
            int curTotal = 0;
            int curPage = 1;
            while (hasNext){
                //分页遍历循环查询所有门禁设备数据
                param = new PrivilegeGroupRequest();
                param.setPageNo(curPage);
                param.setPageSize(100);
                BaseResponse<PrivilegeGroupListResponse> response = HKService.privilegeGroup(param);
                if(response == null || !StringUtils.equals(response.getCode(), HKConstants.RESPONSE_SUCCEE)){
                    throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "对不起,海康同步数据失败~");
                }
                PrivilegeGroupListResponse r = response.getData();
                curTotal += 100;
                if(curTotal >= r.getTotal()){
                    hasNext = false;
                }
                if(r.getList() == null || r.getList().size()==0){
                    hasNext =false;
                }else{
                    allHkList.addAll(r.getList());
                }
                curPage ++;
            }
        }
        if(addList.size()>0){
            DeviceRoleMapper.insertBatchSomeColumn(addList);
        }
        if(editList.size()>0){
            for(DeviceRole d : editList){
                DeviceRoleMapper.updateById(d);
            /**
             * èŽ·å–å¢žåˆ æ”¹æ•°æ®é›†åˆ
             */
            getDataChangeList(allList,allHkList,addList,editList,deleteList,date);
            if(deleteList.size()>0){
                //逻辑删除
                for(DeviceRole d : deleteList){
                    DeviceRoleMapper.updateById(d);
                }
            }
            if(addList.size()>0){
                DeviceRoleMapper.insertBatchSomeColumn(addList);
            }
            if(editList.size()>0){
                for(DeviceRole d : editList){
                    DeviceRoleMapper.updateById(d);
                }
            }
            return "同步数据:新增【"+addList.size()+"】条,更新【"+editList.size()+"】条,删除【"+deleteList.size()+"】条";
        }catch (Exception e){
            e.printStackTrace();
            throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "同步失败!");
        }finally {
            Constants.DEALING_HK_SYNCDEVICE =false;
        }
        return "同步数据:新增【"+addList.size()+"】条,更新【"+editList.size()+"】条,删除【"+deleteList.size()+"】条";
    }
    private void getDataChangeList(List<DeviceRole> allList, List<PrivilegeGroupInfoResponse> allHkList, List<DeviceRole> addList, List<DeviceRole> editList,List<DeviceRole> deleteList, Date date) {
server/dmvisit_service/src/main/java/com/doumee/service/business/impl/hksync/HkSyncVisitServiceImpl.java
@@ -118,6 +118,7 @@
     * æ ¹æ®é¢„约返回接口封装申请记录更新字段
     * @param c
     * @param date
     * @param date
     * @param type 0需要登记 1免登记
     */
    private void getUpdateModelByResponse(  Visits c,Date date,String type,List<DeviceRole> roleList,String path ) {
server/pom.xml
@@ -280,6 +280,8 @@
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-data-redis</artifactId>
    </dependency>
  </dependencies>
  <build>
    <plugins>