jiangping
2025-01-13 cc0d840070c24ceb20180a41f0323bdc0ee03347
server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/PlatformJobServiceImpl.java
@@ -10,16 +10,18 @@
import com.doumee.core.haikang.model.param.request.ParkReservationDelRequest;
import com.doumee.core.haikang.model.param.respose.ParkReservationAddResponse;
import com.doumee.core.haikang.service.HKService;
import com.doumee.core.model.LoginUserInfo;
import com.doumee.core.model.PageData;
import com.doumee.core.model.PageWrap;
import com.doumee.core.tms.model.request.TmsLockStatusQueryRequest;
import com.doumee.core.tms.model.response.TmsBaseResponse;
import com.doumee.core.tms.model.response.TmsLockStatusQueryResponse;
import com.doumee.service.business.third.WmsService;
import com.doumee.service.business.third.model.LoginUserInfo;
import com.doumee.service.business.third.model.PageData;
import com.doumee.service.business.third.model.PageWrap;
import com.doumee.service.business.third.model.request.TmsLockStatusQueryRequest;
import com.doumee.service.business.third.model.response.TmsBaseResponse;
import com.doumee.service.business.third.model.response.TmsLockStatusQueryResponse;
import com.doumee.core.utils.*;
import com.doumee.core.wx.wxPlat.WxPlatConstants;
import com.doumee.core.wx.wxPlat.WxPlatNotice;
import com.doumee.dao.business.*;
import com.doumee.dao.business.dao.MemberMapper;
import com.doumee.dao.business.dao.SmsConfigMapper;
import com.doumee.dao.business.dao.SmsEmailMapper;
import com.doumee.dao.business.join.PlatformJobJoinMapper;
@@ -29,6 +31,7 @@
import com.doumee.dao.openapi.request.*;
import com.doumee.dao.openapi.response.*;
import com.doumee.dao.system.SystemUserMapper;
import com.doumee.dao.system.model.SystemUser;
import com.doumee.dao.web.reqeust.*;
import com.doumee.dao.web.response.DriverHomeVO;
@@ -56,7 +59,6 @@
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.URLEncoder;
import java.util.*;
import java.util.Date;
import java.util.concurrent.TimeUnit;
@@ -129,6 +131,8 @@
    private MemberMapper memberMapper;
    @Autowired
    private WxNoticeConfigMapper wxNoticeConfigMapper;
    @Autowired
    private SystemUserMapper systemUserMapper;
    @Override
    public Integer create(PlatformJob platformJob) {
@@ -302,7 +306,7 @@
                .le(pageWrap.getModel().getCreateDateEnd() != null, PlatformWmsJob::getIoCreatedate, Utils.Date.getEnd(pageWrap.getModel().getCreateDateEnd()))
                .isNotNull(pageWrap.getModel().getJobType() != null && Constants.equalsInteger(Constants.ONE,pageWrap.getModel().getJobType()), PlatformJob::getContractNum)
                .isNull(pageWrap.getModel().getJobType() != null && Constants.equalsInteger(Constants.ZERO,pageWrap.getModel().getJobType()), PlatformJob::getContractNum)
        ;
                .exists(StringUtils.isNotBlank(pageWrap.getModel().getWmsContractNum()),"select tt.id from platfrom_wms_detail tt where tt.isdeleted=0 and tt.job_id=t.id");
        for(PageWrap.SortData sortData: pageWrap.getSorts()) {
            if (sortData.getDirection().equalsIgnoreCase(PageWrap.DESC)) {
@@ -513,6 +517,14 @@
                .leftJoin(Platform.class,Platform::getId,PlatformJob::getPlatformId)
                .eq(PlatformJob::getIsdeleted,Constants.ZERO)
                .eq(PlatformJob::getDrivierPhone,loginUserInfo.getMobile())
                .and(i->i.like(PlatformJob::getDoneDate,DateUtil.getCurrDate())
                        .or().in(PlatformJob::getStatus,Constants.PlatformJobStatus.WAIT_CALL.getKey()
                                ,Constants.PlatformJobStatus.WAIT_CONFIRM.getKey(),
                                Constants.PlatformJobStatus.WART_SIGN_IN.getKey(),
                                Constants.PlatformJobStatus.IN_WAIT.getKey(),
                                Constants.PlatformJobStatus.CALLED.getKey(),
                                Constants.PlatformJobStatus.WORKING.getKey())
                )
                .orderByDesc(PlatformJob::getId)
        );
        for (PlatformJob platformJob:platformJobList) {
@@ -523,7 +535,6 @@
        }
        driverHomeVO.setPlatformJobList(platformJobList);
        // 园区导览图  图片
        driverHomeVO.setReservationMap(systemDictDataBiz.queryByCode(Constants.PLATFORM,Constants.PLATFORM_GUIDEMAP).getCode());
        // 预约指南 文本
@@ -619,7 +630,8 @@
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"未在工作时间["+platformGroup.getStartTime() + "-" + platformGroup.getEndTime() +"],无法进行签到");
        }
        //查询今日最大的签到数
        List<PlatformJob> signList = platformJobMapper.selectList(new QueryWrapper<PlatformJob>().lambda().apply(" DATE(SIGN_DATE) = DATE(NOW()) and sign_date is not null  "));
        List<PlatformJob> signList = platformJobMapper.selectList(new QueryWrapper<PlatformJob>().lambda()
                .apply(" DATE(SIGN_DATE) = DATE(NOW()) and sign_date is not null  "));
        if(CollectionUtils.isEmpty(signList)){
            platformJob.setSignNum(Constants.ONE);
        } else{
@@ -733,6 +745,7 @@
                                ,PlatformJob::getId,lineUpDetailDTO.getJobId())
                        .in(PlatformJob::getStatus,Constants.PlatformJobStatus.WAIT_CALL.getKey(),
                                Constants.PlatformJobStatus.IN_WAIT.getKey(),
                                Constants.PlatformJobStatus.WORKING.getKey(),
                                Constants.PlatformJobStatus.CALLED.getKey())
                        .orderByDesc(PlatformJob::getStatus)
                        .orderByAsc(PlatformJob::getSignDate)
@@ -874,26 +887,62 @@
        
        //公众号模板消息
        if(Objects.nonNull(platformJob.getDriverId())) {
            Member member = memberMapper.selectById(platformJob.getDriverId());
            if (Objects.nonNull(member) && StringUtils.isNotBlank(member.getOpenid())) {
                WxPlatNotice wxPlatNotice = new WxPlatNotice();
                wxPlatNotice.sendPlatformJobTemplateNotice(
                        wxNoticeConfigMapper, platformJob,
                        WxPlatConstants.platformJobContent.platformJobCallIn,
                        systemDictDataBiz.queryByCode(Constants.WX_PLATFORM, Constants.WX_PLATFORM_ACCESS_TOKEN).getCode(),
                        Arrays.asList(member.getOpenid().split(","))
                );
            }
          this.sendWxNotice(WxPlatConstants.platformJobContent.platformJobCallIn,platformJob);
        }
        return platformJob;
    }
    public void sendWxNotice(String objCode,PlatformJob platformJob){
        SystemUser driver = systemUserMapper.selectOne(new QueryWrapper<SystemUser>().lambda()
                .eq(SystemUser::getDeleted, Constants.ZERO)
                .eq(SystemUser::getType, Constants.ZERO)
                .eq(SystemUser::getMobile,platformJob.getDrivierPhone())
                .last(" limit 1 "));
        if (Objects.nonNull(driver) && StringUtils.isNotBlank(driver.getOpenid())) {
            PlatformJob p = platformJobJoinMapper.selectJoinOne(PlatformJob.class,
                    new MPJLambdaWrapper<PlatformJob>()
                            .selectAll(PlatformJob.class)
                            .selectAs(Platform::getName,PlatformJob::getPlatformName)
                            .leftJoin(Platform.class,Platform::getId,PlatformJob::getPlatformId)
                            .eq(PlatformJob::getId,platformJob.getId())
                            .last(" limit 1")
            );
            WxPlatNotice wxPlatNotice = new WxPlatNotice();
            wxPlatNotice.sendPlatformJobTemplateNotice(systemDictDataBiz,
                    wxNoticeConfigMapper, p,
                    objCode,
                    systemDictDataBiz.queryByCode(Constants.WX_PLATFORM, Constants.WX_PLATFORM_ACCESS_TOKEN).getCode(),
                    Arrays.asList(driver.getOpenid().split(","))
            );
        }
    }
    private Logger logger = LoggerFactory.getLogger(PlatformJobServiceImpl.class);
    @Override
    public void sendInPark(PlatformJob platformJob){
        log.info("【下发停车场权限】================开始===="+platformJob.getCarCodeFront());
        if(Constants.equalsInteger(platformJob.getType(),Constants.THREE)
                && Constants.equalsInteger(platformJob.getStatus(),Constants.PlatformJobStatus.DONE.getKey()) ){
            //如果是已完成的外协车卸货作业,查询所有合同是否以上电子锁,如果没有,不自动授权离园
            List<PlatformWmsDetail> details = platformWmsDetailMapper.selectList(new QueryWrapper<PlatformWmsDetail>().lambda()
                     .select(PlatformWmsDetail::getLockStatus,PlatformWmsDetail::getId)
                    .eq(PlatformWmsDetail::getJobId,platformJob.getId())
                    .eq(PlatformWmsDetail::getIsdeleted,Constants.ZERO)
            );
            if(details!=null && details.size()>0){
                for(PlatformWmsDetail d : details){
                    if(Constants.equalsInteger(d.getLockStatus(),Constants.ZERO)){
                        //如果存在未上锁,不自动授权离园
                        return;
                    }
                }
            }
        }
        if(Constants.equalsInteger(platformJob.getType(),Constants.TWO)
                || Constants.equalsInteger(platformJob.getType(),Constants.THREE)
                || Constants.equalsInteger(platformJob.getType(),Constants.FOUR)){
@@ -975,6 +1024,10 @@
                    platformJob.setInHkdate(new Date());
                    if(sendStatus){
                        platformJob.setInHkstatus(Constants.TWO);
                        if(Constants.equalsInteger(platformJob.getStatus(),Constants.PlatformJobStatus.DONE.getKey())){
                            //如果已下发成功,标记已授权离园状态
                            platformJob.setStatus(Constants.PlatformJobStatus.AUTHED_LEAVE.getKey());
                        }
                    }else{
                        platformJob.setInHkstatus(Constants.THREE);
                    }
@@ -1084,17 +1137,8 @@
        );
        //公众号模板消息
        if(Objects.nonNull(platformJob.getDriverId())){
            Member member = memberMapper.selectById(platformJob.getDriverId());
            if(Objects.nonNull(member) && StringUtils.isNotBlank(member.getOpenid())){
                WxPlatNotice wxPlatNotice = new WxPlatNotice();
                wxPlatNotice.sendPlatformJobTemplateNotice(
                        wxNoticeConfigMapper,platformJob,
                        WxPlatConstants.platformJobContent.platformJobSingIn,
                        systemDictDataBiz.queryByCode(Constants.WX_PLATFORM,Constants.WX_PLATFORM_ACCESS_TOKEN).getCode(),
                        Arrays.asList(member.getOpenid().split(","))
                );
            }
        if(Objects.nonNull(platformJob.getDriverId())){
            this.sendWxNotice(WxPlatConstants.platformJobContent.platformJobSingIn,platformJob);
        }
@@ -1229,17 +1273,8 @@
        );
        //公众号模板消息
        if(Objects.nonNull(platformJob.getDriverId())) {
            Member member = memberMapper.selectById(platformJob.getDriverId());
            if (Objects.nonNull(member) && StringUtils.isNotBlank(member.getOpenid())) {
                WxPlatNotice wxPlatNotice = new WxPlatNotice();
                wxPlatNotice.sendPlatformJobTemplateNotice(
                        wxNoticeConfigMapper, platformJob,
                        WxPlatConstants.platformJobContent.platformJobMove,
                        systemDictDataBiz.queryByCode(Constants.WX_PLATFORM, Constants.WX_PLATFORM_ACCESS_TOKEN).getCode(),
                        Arrays.asList(member.getOpenid().split(","))
                );
            }
        if(Objects.nonNull(platformJob.getDriverId())) {
            this.sendWxNotice(WxPlatConstants.platformJobContent.platformJobMove,platformJob);
        }
        platformJob.setPlatformName(oldPlatform.getName());
@@ -1292,16 +1327,7 @@
        //公众号模板消息
        if(Objects.nonNull(platformJob.getDriverId())){
            Member member = memberMapper.selectById(platformJob.getDriverId());
            if(Objects.nonNull(member) && StringUtils.isNotBlank(member.getOpenid())){
                WxPlatNotice wxPlatNotice = new WxPlatNotice();
                wxPlatNotice.sendPlatformJobTemplateNotice(
                        wxNoticeConfigMapper,platformJob,
                        WxPlatConstants.platformJobContent.platformJobOverNum,
                        systemDictDataBiz.queryByCode(Constants.WX_PLATFORM,Constants.WX_PLATFORM_ACCESS_TOKEN).getCode(),
                        Arrays.asList(member.getOpenid().split(","))
                );
            }
            this.sendWxNotice(WxPlatConstants.platformJobContent.platformJobOverNum,platformJob);
        }
        platformJob.setPlatformName(platform.getName());
@@ -1353,16 +1379,7 @@
        //公众号模板消息
        if(Objects.nonNull(platformJob.getDriverId())) {
            Member member = memberMapper.selectById(platformJob.getDriverId());
            if (Objects.nonNull(member) && StringUtils.isNotBlank(member.getOpenid())) {
                WxPlatNotice wxPlatNotice = new WxPlatNotice();
                wxPlatNotice.sendPlatformJobTemplateNotice(
                        wxNoticeConfigMapper, platformJob,
                        WxPlatConstants.platformJobContent.platformJobError,
                        systemDictDataBiz.queryByCode(Constants.WX_PLATFORM, Constants.WX_PLATFORM_ACCESS_TOKEN).getCode(),
                        Arrays.asList(member.getOpenid().split(","))
                );
            }
            this.sendWxNotice(WxPlatConstants.platformJobContent.platformJobError,platformJob);
        }
        platformJob.setPlatformName(platform.getName());
@@ -1416,16 +1433,7 @@
        );
        //公众号模板消息
        if(Objects.nonNull(platformJob.getDriverId())) {
            Member member = memberMapper.selectById(platformJob.getDriverId());
            if (Objects.nonNull(member) && StringUtils.isNotBlank(member.getOpenid())) {
                WxPlatNotice wxPlatNotice = new WxPlatNotice();
                wxPlatNotice.sendPlatformJobTemplateNotice(
                        wxNoticeConfigMapper, platformJob,
                        WxPlatConstants.platformJobContent.platformJobWorking,
                        systemDictDataBiz.queryByCode(Constants.WX_PLATFORM, Constants.WX_PLATFORM_ACCESS_TOKEN).getCode(),
                        Arrays.asList(member.getOpenid().split(","))
                );
            }
            this.sendWxNotice(WxPlatConstants.platformJobContent.platformJobWorking,platformJob);
        }
        //广播 led通知
        platformJob.setPlatformName(platform.getName());
@@ -1435,7 +1443,8 @@
        return platformJob;
    }
    @Override
    public PlatformJob getLastWaitJob(String uuid, LoginUserInfo loginUser){
        String u = (String) redisTemplate.opsForValue().get(Constants.RedisKeys.BIGSCREEN_UUID);
        if(!StringUtils.equals(u,uuid)){
@@ -1449,6 +1458,7 @@
                .last(" limit 1 ") );
            return platformJob;
    }
    @Override
    @Transactional(rollbackFor = {Exception.class,BusinessException.class})
    public PlatformJob finishWork(JobOperateDTO jobOperateDTO){
@@ -1491,19 +1501,21 @@
                Date date = new Date();
                List<String> codeList =new ArrayList<>();
                for(PlatformWmsDetail d : details){
                    codeList.add(d.getIocode());
                    codeList.add(d.getContractNum());
                }
                TmsLockStatusQueryRequest tmsLock = new TmsLockStatusQueryRequest();
                tmsLock.setContractNumbers(codeList);
                TmsBaseResponse<List<TmsLockStatusQueryResponse>>  lockResult =  tmsService.lockStatusQuery(tmsLock);
                if(lockResult!=null && lockResult.isSuccess()&& lockResult.getData()!=null ){
                if(lockResult!=null && lockResult.getCode()!=null && lockResult.getCode().equals("0")&& lockResult.getData()!=null ){
                     for(TmsLockStatusQueryResponse s : lockResult.getData()){
                       if(StringUtils.isBlank(s.getContractNumber())){
                           continue;
                       }
                         platformWmsDetailMapper.update(null,new UpdateWrapper<PlatformWmsDetail>().lambda()
                                 .eq(PlatformWmsDetail::getIocode,s.getContractNumber())
                                 .eq(PlatformWmsDetail::getContractNum,s.getContractNumber())
                                 .set(PlatformWmsDetail::getEditDate,date)
                                 .set(PlatformWmsDetail::getLockDate,s.getOutDate())
                                 .set(PlatformWmsDetail::getLockStatus,Constants.ONE)
                                 .eq(PlatformWmsDetail::getJobId,platformJob.getId())
                                 .eq(PlatformWmsDetail::getIsdeleted,Constants.ZERO));
                     }
                }
@@ -1511,7 +1523,6 @@
        }else if(Constants.equalsInteger(platformJob.getType(),Constants.ONE) || Constants.equalsInteger(platformJob.getType(),Constants.FOUR)){
            //TODO 外协车卸货 或者 市公司车卸货 则根据任务情况
        }
@@ -1523,16 +1534,7 @@
        //公众号模板消息
        if(Objects.nonNull(platformJob.getDriverId())) {
            Member member = memberMapper.selectById(platformJob.getDriverId());
            if (Objects.nonNull(member) && StringUtils.isNotBlank(member.getOpenid())) {
                WxPlatNotice wxPlatNotice = new WxPlatNotice();
                wxPlatNotice.sendPlatformJobTemplateNotice(
                        wxNoticeConfigMapper, platformJob,
                        WxPlatConstants.platformJobContent.platformJobFinish,
                        systemDictDataBiz.queryByCode(Constants.WX_PLATFORM, Constants.WX_PLATFORM_ACCESS_TOKEN).getCode(),
                        Arrays.asList(member.getOpenid().split(","))
                );
            }
            this.sendWxNotice(WxPlatConstants.platformJobContent.platformJobFinish,platformJob);
        }
        //广播 led通知
@@ -1540,6 +1542,76 @@
        this.broadcastAndLEed(platformJob,Constants.PlatformLedContent.DONE.getInfo(),
                Constants.PlatformBroadcastContent.DONE.getInfo());
        return platformJob;
    }
    @Override
    public void checkWmsLockStatus(){
        List<PlatformWmsDetail> details = platformWmsDetailMapper.selectJoinList(PlatformWmsDetail.class,new MPJLambdaWrapper<PlatformWmsDetail>()
                .selectAll(PlatformWmsDetail.class)
                .leftJoin(PlatformJob.class,PlatformJob::getId,PlatformWmsDetail::getJobId)
                .eq(PlatformJob::getStatus,Constants.PlatformJobStatus.DONE.getKey())//查询已完成作业的
                .eq(PlatformJob::getIsdeleted,Constants.ZERO)
                .and(wr->{wr.isNull(PlatformWmsDetail::getLockStatus).or().eq(PlatformWmsDetail::getLockStatus,Constants.ZERO);})
                .eq(PlatformWmsDetail::getIsdeleted,Constants.ZERO));
       if(details !=null && details.size()>0){
           Date date = new Date();
           List<String> codeList =new ArrayList<>();
           for(PlatformWmsDetail d : details){
               codeList.add(d.getContractNum());
           }
           TmsLockStatusQueryRequest tmsLock = new TmsLockStatusQueryRequest();
           tmsLock.setContractNumbers(codeList);
           List<Integer> jobIds = new ArrayList<>();
           TmsBaseResponse<List<TmsLockStatusQueryResponse>>  lockResult =  tmsService.lockStatusQuery(tmsLock);
           if(lockResult!=null && lockResult.getCode()!=null && lockResult.getCode().equals("0")&& lockResult.getData()!=null ){
               for(TmsLockStatusQueryResponse s : lockResult.getData()){
                   try {
                       //异常处理,能处理一个是一个
                       platformWmsDetailMapper.update(null,new UpdateWrapper<PlatformWmsDetail>().lambda()
                               .eq(PlatformWmsDetail::getContractNum,s.getContractNumber())
                               .set(PlatformWmsDetail::getEditDate,date)
                               .set(PlatformWmsDetail::getLockDate,s.getOutDate())
                               .set(PlatformWmsDetail::getLockStatus,Constants.ONE)
                               .eq(PlatformWmsDetail::getIsdeleted,Constants.ZERO));
                       PlatformWmsDetail job = getJobByContractnumFromDetail(s.getContractNumber(),details);
                       if(job != null){
                           jobIds.add(job.getJobId());
                       }
                   }catch (Exception e){
                        logger.error("=============更新电子锁状态信息异常:"+e.getMessage());
                   }
               }
           }
           if(jobIds.size()>0){
               List<PlatformJob> list = platformJobMapper.selectJoinList(PlatformJob.class,new MPJLambdaWrapper<PlatformJob>()
                       .selectAll(PlatformJob.class)
                       .eq(PlatformJob::getStatus,Constants.PlatformJobStatus.DONE.getKey())
                       .in(PlatformJob::getId,jobIds)
               );
               if(list!=null){
                   for(PlatformJob platformJob : list){
                       sendInPark(platformJob);//检查是否需要自动授权离园
                   }
               }
           }
       }
    }
    private PlatformWmsJob getJobByContractnum(String contractNumber, List<PlatformWmsJob> details) {
        for(PlatformWmsJob d : details){
            if(StringUtils.equals(contractNumber,d.getContractNum())){
                return d;
            }
        }
        return  null;
    }
    private PlatformWmsDetail getJobByContractnumFromDetail(String contractNumber, List<PlatformWmsDetail> details) {
        for(PlatformWmsDetail d : details){
            if(StringUtils.equals(contractNumber,d.getContractNum())){
                return d;
            }
        }
        return  null;
    }
@@ -2125,7 +2197,7 @@
        String u =  UUID.randomUUID().toString();
        redisTemplate.opsForValue().set(Constants.RedisKeys.BIGSCREEN_UUID,u,3, TimeUnit.MINUTES);
        String url = Constants.getWxUrl(systemDictDataBiz.queryByCode(Constants.PLATFORM,Constants.WX_REDIRECT_URL).getCode(),Constants.WxUrlParams.BISCREEN_CODE,u);
        largeScreenDataVO.setQrCode(systemDictDataBiz.queryByCode(Constants.PLATFORM,Constants.SIGN_IN_QRCODE_PREFIX).getCode().replace( "${param}", url));
        largeScreenDataVO.setQrCode(url);
        largeScreenDataVO.setAttention(systemDictDataBiz.queryByCode(Constants.PLATFORM,Constants.SIGN_IN_ATTENTION).getCode());
        return largeScreenDataVO;
@@ -2233,7 +2305,6 @@
        }
    }