doum
2025-09-12 7d28e7367852aaa35587e4fd1bf29674ac17d5f6
server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/thrid/WmsServiceImpl.java
@@ -11,14 +11,15 @@
import com.doumee.core.wms.model.request.*;
import com.doumee.core.wms.model.response.WmsBaseDataResponse;
import com.doumee.core.wms.model.response.WmsBaseResponse;
import com.doumee.core.wms.model.response.WmsBaseDataResponse;
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.model.*;
import com.doumee.dao.business.model.Member;
import com.doumee.dao.system.SystemUserMapper;
import com.doumee.dao.system.model.SystemUser;
import com.doumee.service.business.impl.SmsEmailServiceImpl;
@@ -27,6 +28,7 @@
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -72,6 +74,8 @@
    private RetentionMapper retentionMapper;
    @Autowired
    private WxNoticeConfigMapper wxNoticeConfigMapper;
    @Autowired
    private PlatformLogMapper platformLogMapper;
    /**
     * 入库通知任务业务处理
     * @param job 参数
@@ -80,7 +84,6 @@
    @Override
    public  WmsBaseResponse<WmsBaseDataResponse> orderPlatformBind(PlatformJob job) {
        if(StringUtils.isBlank(job.getBillCode()) || StringUtils.isBlank(job.getPlatformWmsCode())){
            return null;
        }
        int type = 0;
@@ -95,51 +98,79 @@
        }else{
            return null;
        }
        WmsOrderPlatformRequest  param  = new WmsOrderPlatformRequest();
         param.setData(new ArrayList<>());
        List<PlatformWmsDetail> platformWmsDetailList = platformWmsDetailMapper.selectList(new QueryWrapper<PlatformWmsDetail>().lambda()
                .eq(PlatformWmsDetail::getJobId,job.getId())
                .eq(PlatformWmsDetail::getIsdeleted,Constants.ZERO)
        );
        String url = type == 0?systemDictDataBiz.queryByCode(Constants.WMS_PARAM,Constants.WMS_INBOUND_PLATFROM_URL).getCode():
                systemDictDataBiz.queryByCode(Constants.WMS_PARAM,Constants.WMS_OUTBOUND_PLATFROM_URL).getCode();;
        String name = type ==0?"【WMS】入库作业单分配月台":"【WMS】出库作业的分配月台";
//        int sendSuccess = 0;
//        int sendError = 0;
        List<String> errorMassge = new ArrayList<>();
        List<String> successMassge = new ArrayList<>();
        WmsBaseResponse<WmsBaseDataResponse> response = null;
        if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(platformWmsDetailList)){
            for (PlatformWmsDetail platformWmsDetail:platformWmsDetailList) {
                if(StringUtils.isNotBlank(platformWmsDetail.getIocode())){
                    //只处理未发送的请求
                    WmsOrderPlatformRequest  param  = new WmsOrderPlatformRequest();
                    param.setData(new ArrayList<>());
                    WmsOrderPlatformInfoRequest o = new WmsOrderPlatformInfoRequest();
                    o.setCarrierBillCode(platformWmsDetail.getIocode());
                    o.setRailwayNo(job.getPlatformWmsCode());
                    param.getData().add(o);
                    response = sendHttpRequest(url,name,JSONObject.toJSONString(param),new TypeReference< WmsBaseResponse<WmsBaseDataResponse>>(){});
                    if(response!=null && response.getData() !=null
                            && response.getData().size()>0 && StringUtils.equals(response.getData().get(0).getSuccess(),WmsBaseResponse.CODE_SUCCESS)){
                        //如果成功
                        successMassge.add(o.getRailwayNo());
                    }else{
                        //如果失败
                        errorMassge.add(o.getRailwayNo());
                   }
                }
            }
        }
        if(successMassge.size()>0 || errorMassge.size()>0){
            PlatformJob update = new PlatformJob();
            update.setId(job.getId());
            update.setWmsSendDate(new Date());
            if(Objects.isNull(job.getWmsSendNum())){
                job.setWmsSendNum(1);
            }else{
                update.setWmsSendNum(job.getWmsSendNum() + 1);
            }
            update.setWmsSendPlatformCode(job.getPlatformWmsCode());
            if(successMassge.size()>0 && errorMassge.size() ==0){
                //如果成功
                update.setWmsSendStatus(Constants.ONE);
            }else if(successMassge.size()==0 && errorMassge.size() >1){
                //如果失败
                update.setWmsSendStatus(Constants.TWO);
            }
            Map<String ,Object> info= new HashMap<>();
            info.put("success", successMassge);
            info.put("error", errorMassge);
            update.setWmsSendInfo(JSONObject.toJSONString(info));
            platformJobMapper.updateById(update);
        }
         String url = type == 0?systemDictDataBiz.queryByCode(Constants.WMS_PARAM,Constants.WMS_INBOUND_PLATFROM_URL).getCode():
                 systemDictDataBiz.queryByCode(Constants.WMS_PARAM,Constants.WMS_OUTBOUND_PLATFROM_URL).getCode();;
         String name = type ==0?"【WMS】入库作业单分配月台":"【WMS】出库作业的分配月台";
         WmsBaseResponse<WmsBaseDataResponse> response = sendHttpRequest(url,name,JSONObject.toJSONString(param),new TypeReference< WmsBaseResponse<WmsBaseDataResponse>>(){});
         PlatformJob update = new PlatformJob();
         update.setId(job.getId());
         update.setWmsSendDate(new Date());
         if(Objects.isNull(job.getWmsSendNum())){
             job.setWmsSendNum(1);
         }else{
             update.setWmsSendNum(job.getWmsSendNum() + 1);
         }
         update.setWmsSendPlatformCode(job.getPlatformWmsCode());
         if(response!=null && response.getData() !=null
                && response.getData().size()>0 && StringUtils.equals(response.getData().get(0).getSuccess(),WmsBaseResponse.CODE_SUCCESS)){
            //如果成功
            update.setWmsSendStatus(Constants.ONE);
            update.setWmsSendInfo("通知WMS作业单分配月台成功");
         }else{
            //如果失败
            update.setWmsSendStatus(Constants.TWO);
            update.setWmsSendInfo("通知WMS作业单分配月台失败:"+(response!=null?JSONObject.toJSONString(response):"接口调用失败"));
         }
         platformJobMapper.updateById(update);
         return response;
    }
    private boolean notSendedCode(String iocode, List<String> doneIoCode) {
        if(doneIoCode!=null){
            for(String s : doneIoCode){
                if(StringUtils.equals(iocode,s)){
                    return false;
                }
            }
        }
        return  true;
    }
    /**
     * 入库通知任务业务处理
     * @return
@@ -242,6 +273,7 @@
                return returnFailReuslt("请求参数不正确,参数不能为空");
            }
            List<PlatformJob> jobList = new ArrayList<>();
            List<Integer> jobIdList = new ArrayList<>();
            List<PlatformWmsDetail> details = new ArrayList<>();
            List<String> iocodeList = new ArrayList<>();
            for(WmsInboundNoticeRequest param : list.getData()){
@@ -264,6 +296,7 @@
                    job.setIsdeleted(Constants.ZERO);
                    job.setIsNew(Constants.ONE);
                    job.setStatus(Constants.ONE);
                    job.setContractNum(param.getContractNum());
                    job.setCarryBillCode(param.getCarrierBillCode());
                    job.setIocode(param.getIoCode());
                    job.setCarrierName(param.getCarrierName());
@@ -277,6 +310,7 @@
                    platformWmsJobMapper.insert(job);
                    jobList.add(model);
                }
                jobIdList.add(job.getJobId());
                if(param.getDetails()!=null && param.getDetails().size()>0){
                    for(WmsInboundDetailRequest d :param.getDetails()){
                        PlatformWmsDetail entity = new PlatformWmsDetail();
@@ -284,10 +318,11 @@
                        entity.setIsdeleted(Constants.ZERO);
                        entity.setIocode(d.getIoCode());
                        entity.setJobId(job.getJobId());
                        entity.setContractNum(param.getContractNum());
                        entity.setWmsJobId(job.getId());
                        entity.setIoQty(d.getIoQty());
                        entity.setStatus(Constants.ZERO);
                        entity.setRate(d.getRate());
                        entity.setIoQty(Constants.formatBigdecimal(d.getIoQty()).multiply(Constants.formatBigdecimal( d.getRate())));
                        entity.setRate(Objects.nonNull(d.getRate())?Constants.formatBigdecimal(d.getRate()).doubleValue()+"":"1");
                        entity.setMaterialName(d.getMaterialName());
                        entity.setInRepertotyCode(d.getInRepertotyCode());
                        iocodeList.add(d.getIoCode());
@@ -307,6 +342,7 @@
            if(details.size()>0){
                platformWmsDetailMapper.insert(details);
            }
            list.setJobIdList(jobIdList);
            if(jobList.size()>0){
                startEndNoticeToDriver(jobList);
            }
@@ -339,7 +375,6 @@
                        wxPlatNotice.sendWmsTemplateNotice(systemDictDataBiz,
                                wxNoticeConfigMapper,job,
                                WxPlatConstants.platformJobContent.platformJobNewJob,
                                systemDictDataBiz.queryByCode(Constants.WX_PLATFORM,Constants.WX_PLATFORM_ACCESS_TOKEN).getCode(),
                                Arrays.asList(driver.getOpenid().split(","))
                        );
                    }
@@ -369,8 +404,17 @@
    private void dealCarPlatformAndDriverInfo(PlatformJob job,int type) {
        //查询车辆是否自有车,以及jobNum表示但求作业数量(非已离园的作业数)
        Cars car = carsMapper.selectOne(new QueryWrapper<Cars>()
                .select("*,(select count(1) from platform_job b where b.plate_num='"+job.getCarCodeFront()+"' and b.status in("+
                        Constants.PlatformJobStatus.LEAVED.getKey()+")) as jobNum")
                .select("*,(select count(1) from platform_job b where b.plate_num='"+job.getCarCodeFront()+"' " +
                        "and b.status in("+
                        Constants.PlatformJobStatus.WART_SIGN_IN.getKey()+","+
                        Constants.PlatformJobStatus.WART_SIGN_IN.getKey()+","+
                        Constants.PlatformJobStatus.WAIT_CALL.getKey()+","+
                        Constants.PlatformJobStatus.IN_WAIT.getKey()+","+
                        Constants.PlatformJobStatus.CALLED.getKey()+","+
                        Constants.PlatformJobStatus.TRANSFERING.getKey()+","+
                        Constants.PlatformJobStatus.OVER_NUMBER.getKey()+","+
                        Constants.PlatformJobStatus.EXCEPTION.getKey()+","+
                        Constants.PlatformJobStatus.WORKING.getKey()+")) as jobNum")
                .lambda()
                .eq(Cars::getIsdeleted,Constants.ZERO)
                .eq(Cars::getType,Constants.ONE)
@@ -379,8 +423,10 @@
            //如果是自有物流车
            job.setType(type==0?Constants.platformJobType.zycxh:Constants.platformJobType.zyczh);//自有车卸货/装货
            job.setCarCodeBack(job.getCarCodeFront());//自有车默认前后车牌一样
            if(retentionMapper.selectCount(new QueryWrapper<Retention>().lambda().eq(Retention::getType,Constants.THREE)
                    .eq(Retention::getCarNo,car.getCode()))>Constants.ZERO && car.getJobNum() == 0){
            if(job.getType() ==Constants.platformJobType.zyczh
                    && retentionMapper.selectCount(new QueryWrapper<Retention>().lambda().eq(Retention::getType,Constants.THREE)
                    .eq(Retention::getCarNo,car.getCode()))>Constants.ZERO
                    && car.getJobNum() == 0){
                //如果车辆在园
                job.setStatus(Constants.PlatformJobStatus.WAIT_CALL.getKey());//在园无作业状态,则自动【已签到】处理
                job.setArriveDate(new Date());
@@ -398,6 +444,7 @@
            }
        }
        PlatformGroup group = platformGroupMapper.selectOne(new QueryWrapper<PlatformGroup>().lambda()
                .eq(PlatformGroup::getIsVirtual,Constants.ZERO)//非虚拟月台
                .eq(PlatformGroup::getIsdeleted,Constants.ZERO)
                .eq(PlatformGroup::getType,type==0?Constants.ZERO:Constants.ONE)
                .last("limit 1") );//查询卸货月台组编码
@@ -415,6 +462,22 @@
            job.setCompanyNamePath(driver.getCompanyNamePath());
        }
        platformJobMapper.insert(job);
        if(car !=null){
            //存储操作日志
            PlatformLog platformLog = new PlatformLog();
            platformLog.setIsdeleted(Constants.ZERO);
            platformLog.setCreateDate(new Date());
            platformLog.setJobId(job.getId());
            platformLog.setObjType(Constants.PlatformJobLogType.SIGN.getKey());
            platformLog.setContent("自动签到");
            platformLog.setParam4(job.getCarCodeFront());
            platformLog.setAfterContent(JSONObject.toJSONString(job));
            platformLog.setObjId(job.getId().toString());
            platformLog.setParam3("0");
            platformLogMapper.insert(platformLog);
        }
    }
    private PlatformJob dealJobBizOutbound(WmsOutboundNoticeRequest param) {
@@ -481,10 +544,9 @@
                    job.setContractNum(param.getContractNum());
                    job.setDriverPhone(param.getDriverPhone());
                    job.setDriverName(param.getDriverName());
//                    job.setOrigin(Constants.ONE);
                    platformWmsJobMapper.insert(job);
                }
                jobIdList.add(job.getId());
                jobIdList.add(job.getJobId());
                if(param.getDetails()!=null && param.getDetails().size()>0){
                    for(WmsOutboundDetailRequest d :param.getDetails()){
                        PlatformWmsDetail entity = new PlatformWmsDetail();
@@ -493,11 +555,14 @@
                        entity.setIocode(d.getIoCode());
                        entity.setJobId(job.getJobId());
                        entity.setWmsJobId(job.getId());
                        entity.setIoQty(d.getIoQty());
                        entity.setRepertotyAddress(job.getRepertotyAddress());
                        entity.setContractNum(param.getContractNum());
                        entity.setRepertotyAddress(param.getRepertotyAddress());
                        entity.setWmsJobId(job.getId());
                        entity.setStatus(Constants.ZERO);
                        entity.setRate(d.getRate());
                        entity.setIoQty(Constants.formatBigdecimal(d.getIoQty()).multiply(Constants.formatBigdecimal( d.getRate())));
                        entity.setRate(Objects.nonNull(d.getRate())?Constants.formatBigdecimal(d.getRate()).doubleValue()+"":"1");
//                        entity.setIoQty(d.getIoQty());
//                        entity.setRate(d.getRate());
                        entity.setMaterialName(d.getMaterialName());
                        iocodeList.add(d.getIoCode());
                        details.add(entity);
@@ -517,8 +582,8 @@
            if(details.size()>0){
                platformWmsDetailMapper.insert(details);
            }
            list.setJobIdList(jobIdList);
            if(jobList.size()>0){
                list.setJobIdList(jobIdList);
                startEndNoticeToDriver(jobList);
            }
        }catch (Exception e){
@@ -594,8 +659,7 @@
                                WxPlatNotice wxPlatNotice = new WxPlatNotice();
                                wxPlatNotice.sendWmsCancelTemplateNotice(systemDictDataBiz,
                                        wxNoticeConfigMapper,job,
                                        WxPlatConstants.platformJobContent.platformJobCancel,
                                        systemDictDataBiz.queryByCode(Constants.WX_PLATFORM,Constants.WX_PLATFORM_ACCESS_TOKEN).getCode(),
                                        WxPlatConstants.platformJobContent.platformJobCancel,
                                        Arrays.asList(driver.getOpenid().split(","))
                                );
                            }
@@ -675,7 +739,6 @@
                                wxPlatNotice.sendWmsCancelTemplateNotice(systemDictDataBiz,
                                        wxNoticeConfigMapper,job,
                                        WxPlatConstants.platformJobContent.platformJobCancel,
                                        systemDictDataBiz.queryByCode(Constants.WX_PLATFORM,Constants.WX_PLATFORM_ACCESS_TOKEN).getCode(),
                                        Arrays.asList(driver.getOpenid().split(","))
                                );
                            }
@@ -708,14 +771,13 @@
                    .eq(PlatformWmsDetail::getIsdeleted, Constants.ZERO));
            if(details!=null && details.size()>0){
                for(PlatformWmsDetail d :details){
                   num.add(Constants.formatBigdecimal(d.getIoQty()));
                    num =  num.add(Constants.formatBigdecimal(d.getIoQty()));
                }
                platformJobMapper.update(null,new UpdateWrapper<PlatformJob>().lambda()
                        .set(PlatformJob::getTotalNum,num)
                        .eq(PlatformJob::getOrigin, Constants.ZERO)
                        .eq(PlatformJob::getId, jobId));
            }
            platformJobMapper.update(null,new UpdateWrapper<PlatformJob>().lambda()
                    .set(PlatformJob::getTotalNum,num)
                    .eq(PlatformJob::getOrigin, Constants.ONE)
                    .eq(PlatformJob::getId, jobId));
        }
    }
    /**