rk
2026-06-09 c467370d8741bc05ca7c22d4253c58ac0a979ef5
server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/hksync/HkSyncEmpowerServiceImpl.java
@@ -24,12 +24,14 @@
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.Executor;
/**
 * 海康门禁授权业务Service实现
@@ -50,12 +52,17 @@
    @Autowired
    private MemberCardMapper memberCardMapper;
    @Autowired
    @Qualifier("asyncExecutor")
    private Executor asyncExecutor;
    /**
     * 定时查询权限下发任务进度执行结果
     */
    @Override
    public  Integer   syncEmpowerDetailData(Integer endId){
        log.error("");
        long startTime = System.currentTimeMillis();
        log.info("syncEmpowerDetailData执行开始, endId={}", endId);
//        if(Constants.DEALING_HK_EMPOWER_DETAIL){
//            return   ;
//        }
@@ -63,13 +70,12 @@
            //查询所有完成下载,待查询结果的数据记录
            List<Empower>  list = getDealListDetail(endId);
           if(list == null || list.size() ==0){
               log.info("syncEmpowerDetailData无待处理数据, 耗时{}ms", System.currentTimeMillis() - startTime);
               return null;
           }
        Thread t1=new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    for(Empower c : list){
        asyncExecutor.execute(() -> {
            try {
                for(Empower c : list){
                        AuthResultPageRequest param = new AuthResultPageRequest();
                        param.setPageNo(1);
                        param.setPageSize(999);
@@ -201,11 +207,10 @@
                        }
                    }
                }catch (Exception e){
                    e.printStackTrace();
                    log.error("syncEmpowerDetailData执行异常", e);
                }
            }
        });
        t1.start();
         log.info("syncEmpowerDetailData执行结束, 耗时{}ms", System.currentTimeMillis() - startTime);
         return list.get(list.size()-1).getId();
    }
@@ -345,18 +350,15 @@
     */
    @Override
    public  Integer syncEmpowerResultData(Integer endId){
//        if(Constants.DEALING_HK_EMPOWER_RESULT){
//            return  null ;
//        }
//        Constants.DEALING_HK_EMPOWER_RESULT=true;
        long startTime = System.currentTimeMillis();
        log.info("syncEmpowerResultData执行开始, endId={}", endId);
            //查询所有执行中得数据
         List<Empower>  list = getIngTaskListResult(Constants.formatIntegerNum(endId));
           if(list == null || list.size() ==0){
               log.info("syncEmpowerResultData无待处理数据, 耗时{}ms", System.currentTimeMillis() - startTime);
               return null;
           }
            Thread t1=new Thread(new Runnable() {
                @Override
                public void run() {
            asyncExecutor.execute(() -> {
                    try {
                        for(Empower c : list){
                            TaskProgressRequest param = new TaskProgressRequest();
@@ -389,13 +391,10 @@
                            }
                        }
                    }catch (Exception e1){
                        e1.printStackTrace();
                    }finally {
                        Constants.DEALING_HK_EMPOWER_RESULT =false;
                        log.error("syncEmpowerResultData执行异常", e1);
                    }
                }
            });
            t1.start();
                });
            log.info("syncEmpowerResultData执行结束, 耗时{}ms", System.currentTimeMillis() - startTime);
            return list.get(list.size()-1).getId();
    }
@@ -407,6 +406,8 @@
     */
    @Override
    public  Integer syncEmpowerFailData(Integer endId) {
        long startTime = System.currentTimeMillis();
        log.info("syncEmpowerFailData执行开始, endId={}", endId);
        List<Empower> allList =getAllFailDealList( endId);
        if(allList!=null && allList.size()>0){
            Date date = new Date();
@@ -446,6 +447,7 @@
            }
            return allList.get(allList.size()-1).getId();
        }
        log.info("syncEmpowerFailData执行结束, 耗时{}ms", System.currentTimeMillis() - startTime);
        return null;
    }
    /**
@@ -453,33 +455,28 @@
     */
    @Override
    public  Integer syncEmpowerData(Integer endId) {
//        if(Constants.DEALING_HK_EMPOWER){
//            return  null ;
//        }
//        Constants.DEALING_HK_EMPOWER =true;
        long startTime = System.currentTimeMillis();
        log.info("syncEmpowerData执行开始, endId={}", endId);
            //先删除所有需要取消授权的数据
            if(empowerMapper.selectCount(new QueryWrapper<Empower>().lambda()
                    .eq(Empower::getSendStatus,Constants.EmpowerStatus.ing)) > 1000){
                //如果当前任务大于1000个(大概10个任务)
                log.info("syncEmpowerData任务队列已满(>1000), 跳过, 耗时{}ms", System.currentTimeMillis() - startTime);
                return endId;
            }
            List<Empower> allList =getAllWaitDealList( endId);
            if(allList !=null && allList.size()>0){
                //查询所有需要同步的数据,重新下发最新人员权限即可
                Thread t1=new Thread(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            dealAllListTask(allList);
                        }catch (Exception e){
                            log.info("======================下发授权异常:"+e.getMessage());
                            e.printStackTrace();
                        }
                asyncExecutor.execute(() -> {
                    try {
                        dealAllListTask(allList);
                    }catch (Exception e){
                        log.error("======================下发授权异常", e);
                    }
                });
                t1.start();
                log.info("syncEmpowerData提交{}条数据, 耗时{}ms", allList.size(), System.currentTimeMillis() - startTime);
                return allList.get(allList.size()-1).getId();
            }
        log.info("syncEmpowerData无待处理数据, 耗时{}ms", System.currentTimeMillis() - startTime);
        return null;
    }
    @Override