diff --git a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/app/service/impl/BackReceiveServiceImpl.java b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/app/service/impl/BackReceiveServiceImpl.java index c38c4bc..9519029 100644 --- a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/app/service/impl/BackReceiveServiceImpl.java +++ b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/app/service/impl/BackReceiveServiceImpl.java @@ -21,6 +21,7 @@ import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.stream.Collectors; /** * @author hay @@ -151,129 +152,132 @@ public class BackReceiveServiceImpl implements BackReceiveService { @Transactional(rollbackFor = Exception.class) public int endBack(BackApplyInfo record) { int res = 0; -// try { int taskId = record.getTaskId(); - int maxBackNumBackEnd = 0; - int passNum = 0; - int maintenanceNum = 0; - int scrapNum = 0; - List allList1 = backReceiveMapper.getAllList(record); - if (allList1 != null && allList1.size() > 0) { - BackApplyInfo b = allList1.get(0); - record.setTypeId(b.getTypeId()); - int num = backReceiveMapper.getmaChineByCt(record); - record.setNum(num); - } - //先判断是否已经完成退料了 int taskStatus = selectTaskStatus(taskId); if (taskStatus == 0) { throw new RuntimeException("该退料单已完成退料"); } - //修改任务状态 - List list = backReceiveMapper.receiveView4Backend(record); - if (!CollectionUtils.isEmpty(list)) { - for (BackApplyInfo backApplyInfo : list) { - maxBackNumBackEnd += (int) backApplyInfo.getMaxBackNumBackend(); - } - } - List hgList = backReceiveMapper.getHgList(record); - if (hgList != null && hgList.size() > 0) { - for (BackApplyInfo bi : hgList) { - passNum += bi.getBackNum(); - } - } - List wxList = backReceiveMapper.getWxList(record); - if (wxList != null && wxList.size() > 0) { - for (BackApplyInfo bi : wxList) { - maintenanceNum += bi.getBackNum(); - } - } - List bfList = backReceiveMapper.getBfList(record); - if (bfList != null && bfList.size() > 0) { - for (BackApplyInfo bi : bfList) { - scrapNum += bi.getBackNum(); - } - } - log.error("check001退料接收:{},{},{},{}",maxBackNumBackEnd,passNum,maintenanceNum,scrapNum); - if (maxBackNumBackEnd < passNum + maintenanceNum + scrapNum) { - throw new RuntimeException("提交退料数量大于最大退料数,可能您的退料已被别人退掉了"); - } - boolean allZeros = list.stream().allMatch(n -> Double.valueOf(n.getNum()).intValue() == 0); + List allList1 = backReceiveMapper.getAllList(record); + res += getEndBackResult(record, allList1, taskId); + return res; + } + + private int getEndBackResult(BackApplyInfo record, List allList1, int taskId) { + int res = 0; + List totalList = backReceiveMapper.receiveView4Backend(record); + boolean allZeros = totalList.stream().allMatch(n -> Double.valueOf(n.getNum()).intValue() == 0); if (allZeros) { res = updateTaskStatus(taskId, 40); if (res == 0) { throw new RuntimeException("tm_task修改状态"); } } - //更加退料接收的数据创建下一步流程 - //合格的插入入库记录input_apply_details,修改库存ma_type,修改机具状态 - if (hgList != null && hgList.size() > 0) { - res = insertIad(hgList); - if (res == 0) { - throw new RuntimeException("input_apply_details"); - } - // 如果是成套的机具,成套机具的库存也要添加 - List ctList = backReceiveMapper.getCtList(record); - if (ctList.size() > 0) { - for (BackApplyInfo backApplyInfo : ctList) { - if ("2".equals(backApplyInfo.getManageType())) { - backReceiveMapper.updateMt(backApplyInfo); + + if (allList1 != null && allList1.size() > 0) { + for (BackApplyInfo bai : allList1) { + int maxBackNumBackEnd = 0; + int passNum = 0; + int maintenanceNum = 0; + int scrapNum = 0; + record.setTypeId(bai.getTypeId()); + int num = backReceiveMapper.getmaChineByCt(record); + record.setNum(num); + + //修改任务状态 + List list = totalList.stream().filter(o -> o.getModelId().equals(record.getTypeId())).collect(Collectors.toList()); + if (!CollectionUtils.isEmpty(totalList)) { + for (BackApplyInfo backApplyInfo : list) { + maxBackNumBackEnd += backApplyInfo.getMaxBackNumBackend(); } } - } - res = updateMt(hgList); - if (res == 0) { - throw new RuntimeException("ma_type"); - } - res = updateMaStatus(hgList); - if (res == 0) { - throw new RuntimeException("ma_machines"); + List hgList = backReceiveMapper.getHgList(record); + if (hgList != null && hgList.size() > 0) { + for (BackApplyInfo bi : hgList) { + passNum += bi.getBackNum(); + } + } + List wxList = backReceiveMapper.getWxList(record); + if (wxList != null && wxList.size() > 0) { + for (BackApplyInfo bi : wxList) { + maintenanceNum += bi.getBackNum(); + } + } + List bfList = backReceiveMapper.getBfList(record); + if (bfList != null && bfList.size() > 0) { + for (BackApplyInfo bi : bfList) { + scrapNum += bi.getBackNum(); + } + } + log.error("退料接收总数与详细数据对比结果:maxBackNumBackEnd={},passNum={},maintenanceNum={},scrapNum={}", maxBackNumBackEnd, passNum, maintenanceNum, scrapNum); + if (maxBackNumBackEnd < passNum + maintenanceNum + scrapNum) { + log.error("TypeId={}所提交的退料数量大于最大退料数,可能您的退料已被别人退掉了!", bai.getTypeId()); + continue; + } + + //更加退料接收的数据创建下一步流程 + //合格的插入入库记录input_apply_details,修改库存ma_type,修改机具状态 + if (hgList != null && hgList.size() > 0) { + res = insertIad(hgList); + if (res == 0) { + throw new RuntimeException("input_apply_details"); + } + // 如果是成套的机具,成套机具的库存也要添加 + List ctList = backReceiveMapper.getCtList(record); + if (ctList.size() > 0) { + for (BackApplyInfo backApplyInfo : ctList) { + if ("2".equals(backApplyInfo.getManageType())) { + backReceiveMapper.updateMt(backApplyInfo); + } + } + } + res = updateMt(hgList); + if (res == 0) { + throw new RuntimeException("ma_type"); + } + res = updateMaStatus(hgList); + if (res == 0) { + throw new RuntimeException("ma_machines"); + } + } + //维修的创建维修任务,插入任务协议表 + if (wxList != null && wxList.size() > 0) { + //插入任务表tm_task + int newTaskId = insertTt(wxList, TaskTypeEnum.MAINTENANCE_TASK.getCode(), record.getCreateBy()); + //插入协议任务表tm_task_agreement + res = insertTta(newTaskId, wxList); + //插入维修记录表repair_apply_details + res = insertRad(newTaskId, wxList); + } + //待报废的创建报废任务,插入任务协议表 + if (bfList != null && bfList.size() > 0) { + //插入任务表tm_task + int newTaskId = insertTt(bfList, TaskTypeEnum.SCRAP_TASK.getCode(), record.getCreateBy()); + //插入协议任务表tm_task_agreement + res = insertTta(newTaskId, bfList); + //插入维修记录表scrap_apply_details + res = insertSad(newTaskId, bfList); + } + + //更新结算表 slt_agreement_info + res = updateSlt4Bean(record, bai); + if (res == 0) { + throw new RuntimeException("该机具未被领料使用"); + } + + //完成退料的部分,更新 back_check_details 为 is_finished=1,此部分不支持撤回 + finishBackCheckDetails(record); + + //库存日志 + int postStoreNum = backReceiveMapper.getmaChineByCt(record); + record.setPostStoreNum(postStoreNum); + record.setBackNum(passNum + maintenanceNum + scrapNum); + record.setPassNum(passNum); + record.setMaintenanceNum(maintenanceNum); + record.setScrapNum(scrapNum); } } - //维修的创建维修任务,插入任务协议表 - if (wxList != null && wxList.size() > 0) { - //插入任务表tm_task - int newTaskId = insertTt(wxList, TaskTypeEnum.MAINTENANCE_TASK.getCode(), record.getCreateBy()); - //插入协议任务表tm_task_agreement - res = insertTta(newTaskId, wxList); - //插入维修记录表repair_apply_details - res = insertRad(newTaskId, wxList); - } - //待报废的创建报废任务,插入任务协议表 - if (bfList != null && bfList.size() > 0) { - //插入任务表tm_task - int newTaskId = insertTt(bfList, TaskTypeEnum.SCRAP_TASK.getCode(), record.getCreateBy()); - //插入协议任务表tm_task_agreement - res = insertTta(newTaskId, bfList); - //插入维修记录表scrap_apply_details - res = insertSad(newTaskId, bfList); - } - List allList = backReceiveMapper.getAllList(record); - if (allList != null && allList.size() > 0) { - res = updateSlt(record, allList); - if (res == 0) { - throw new RuntimeException("该机具未被领料使用"); - } - BackApplyInfo b = allList.get(0); - record.setTypeId(b.getTypeId()); - int postStoreNum = backReceiveMapper.getmaChineByCt(record); - record.setPostStoreNum(postStoreNum); - } - - //完成退料的部分,更新 back_check_details 为 is_finished=1,此部分不支持撤回 - finishBackCheckDetails(record); - - //库存日志 - record.setBackNum(passNum+maintenanceNum+scrapNum); - record.setPassNum(passNum); - record.setMaintenanceNum(maintenanceNum); - record.setScrapNum(scrapNum); - -// } catch (Exception e) { -// throw new RuntimeException(e.getMessage()); -// } return res; } @@ -286,33 +290,58 @@ public class BackReceiveServiceImpl implements BackReceiveService { } } - private int updateSlt(BackApplyInfo record, List hgList) { - for (BackApplyInfo bean : hgList) { - List infoList = backReceiveMapper.getStlInfo(bean); - if (infoList.size() > 0) { - Integer backNum = bean.getBackNum(); - for (SltAgreementInfo info : infoList) { - Integer num = info.getNum(); - if (backNum.equals(num)) { - backReceiveMapper.updateStlInfo(info, record); - break; - } else if (backNum > num) { - backNum = backNum - num; - backReceiveMapper.updateStlInfo(info, record); - } else if (backNum < num) { - Integer many = num - backNum; - backReceiveMapper.updateStlInfoTwo(info, record, backNum); - backReceiveMapper.insStlInfoTwo(info, many); - break; - } + private int updateSlt4Bean(BackApplyInfo record, BackApplyInfo bean) { + List infoList = backReceiveMapper.getStlInfo(bean); + if (infoList.size() > 0) { + Integer backNum = bean.getBackNum(); + for (SltAgreementInfo info : infoList) { + Integer num = info.getNum(); + if (backNum.equals(num)) { + backReceiveMapper.updateStlInfo(info, record); + break; + } else if (backNum > num) { + backNum = backNum - num; + backReceiveMapper.updateStlInfo(info, record); + } else if (backNum < num) { + Integer many = num - backNum; + backReceiveMapper.updateStlInfoTwo(info, record, backNum); + backReceiveMapper.insStlInfoTwo(info, many); + break; } - } else { - return 0; } + } else { + return 0; } return 1; } +// private int updateSlt(BackApplyInfo record, List hgList) { +// for (BackApplyInfo bean : hgList) { +// List infoList = backReceiveMapper.getStlInfo(bean); +// if (infoList.size() > 0) { +// Integer backNum = bean.getBackNum(); +// for (SltAgreementInfo info : infoList) { +// Integer num = info.getNum(); +// if (backNum.equals(num)) { +// backReceiveMapper.updateStlInfo(info, record); +// break; +// } else if (backNum > num) { +// backNum = backNum - num; +// backReceiveMapper.updateStlInfo(info, record); +// } else if (backNum < num) { +// Integer many = num - backNum; +// backReceiveMapper.updateStlInfoTwo(info, record, backNum); +// backReceiveMapper.insStlInfoTwo(info, many); +// break; +// } +// } +// } else { +// return 0; +// } +// } +// return 1; +// } + @Override public List codeQuery(BackApplyInfo record) { return backReceiveMapper.codeQuery(record); diff --git a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/service/impl/ScrapApplyDetailsServiceImpl.java b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/service/impl/ScrapApplyDetailsServiceImpl.java index db4ae17..cf1f53c 100644 --- a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/service/impl/ScrapApplyDetailsServiceImpl.java +++ b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/service/impl/ScrapApplyDetailsServiceImpl.java @@ -5,6 +5,7 @@ import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.Objects; import java.util.stream.Collectors; import cn.hutool.core.bean.BeanUtil; @@ -509,7 +510,7 @@ public class ScrapApplyDetailsServiceImpl implements IScrapApplyDetailsService { } BackApplyInfo backApplyInfo = new BackApplyInfo(); backApplyInfo.setAgreementId(tmTaskAgreement.getAgreementId().intValue()); - backApplyInfo.setMaId(bean.getMaId().intValue()); + backApplyInfo.setMaId(Objects.isNull(bean.getMaId()) ? 0 : bean.getMaId().intValue()); backApplyInfo.setTypeId(String.valueOf(bean.getTypeId())); backApplyInfo.setCompanyId(String.valueOf(bean.getCompanyId())); backApplyInfo.setBackNum(bean.getScrapNum().intValue()); diff --git a/sgzb-modules/sgzb-material/src/main/resources/mapper/app/BackReceiveMapper.xml b/sgzb-modules/sgzb-material/src/main/resources/mapper/app/BackReceiveMapper.xml index 79b53dd..f3f9b95 100644 --- a/sgzb-modules/sgzb-material/src/main/resources/mapper/app/BackReceiveMapper.xml +++ b/sgzb-modules/sgzb-material/src/main/resources/mapper/app/BackReceiveMapper.xml @@ -778,7 +778,24 @@ @@ -822,6 +840,7 @@ LEFT JOIN tm_task_agreement tta on tta.task_id=bai.task_id WHERE parent_id=#{parentId} + and bcd.type_id=#{typeId} and bcd.back_status='2' and (bcd.is_finished is null or bcd.is_finished != 1) @@ -842,6 +861,7 @@ LEFT JOIN tm_task_agreement tta on tta.task_id=bai.task_id WHERE parent_id=#{parentId} + and bcd.type_id=#{typeId} and bcd.back_status='3' and (bcd.is_finished is null or bcd.is_finished != 1) diff --git a/sgzb-modules/sgzb-material/src/main/resources/mapper/app/LeaseOutDetailsMapper.xml b/sgzb-modules/sgzb-material/src/main/resources/mapper/app/LeaseOutDetailsMapper.xml index 694e503..93664c4 100644 --- a/sgzb-modules/sgzb-material/src/main/resources/mapper/app/LeaseOutDetailsMapper.xml +++ b/sgzb-modules/sgzb-material/src/main/resources/mapper/app/LeaseOutDetailsMapper.xml @@ -450,7 +450,24 @@ mt.type_id = #{typeId}