退料接收多类型机具时的问题优化

This commit is contained in:
sxu 2024-09-08 13:27:36 +08:00
parent 99fc70cf0c
commit 352291ba23
4 changed files with 197 additions and 130 deletions

View File

@ -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,30 +152,43 @@ 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<BackApplyInfo> 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<BackApplyInfo> allList1 = backReceiveMapper.getAllList(record);
res += getEndBackResult(record, allList1, taskId);
return res;
}
private int getEndBackResult(BackApplyInfo record, List<BackApplyInfo> allList1, int taskId) {
int res = 0;
List<BackApplyInfo> 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修改状态");
}
}
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<BackApplyInfo> list = backReceiveMapper.receiveView4Backend(record);
if (!CollectionUtils.isEmpty(list)) {
List<BackApplyInfo> list = totalList.stream().filter(o -> o.getModelId().equals(record.getTypeId())).collect(Collectors.toList());
if (!CollectionUtils.isEmpty(totalList)) {
for (BackApplyInfo backApplyInfo : list) {
maxBackNumBackEnd += (int) backApplyInfo.getMaxBackNumBackend();
maxBackNumBackEnd += backApplyInfo.getMaxBackNumBackend();
}
}
List<BackApplyInfo> hgList = backReceiveMapper.getHgList(record);
@ -195,17 +209,12 @@ public class BackReceiveServiceImpl implements BackReceiveService {
scrapNum += bi.getBackNum();
}
}
log.error("check001退料接收:{},{},{},{}",maxBackNumBackEnd,passNum,maintenanceNum,scrapNum);
log.error("退料接收总数与详细数据对比结果:maxBackNumBackEnd={},passNum={},maintenanceNum={},scrapNum={}", maxBackNumBackEnd, passNum, maintenanceNum, scrapNum);
if (maxBackNumBackEnd < passNum + maintenanceNum + scrapNum) {
throw new RuntimeException("提交退料数量大于最大退料数,可能您的退料已被别人退掉了");
}
boolean allZeros = list.stream().allMatch(n -> Double.valueOf(n.getNum()).intValue() == 0);
if (allZeros) {
res = updateTaskStatus(taskId, 40);
if (res == 0) {
throw new RuntimeException("tm_task修改状态");
}
log.error("TypeId={}所提交的退料数量大于最大退料数,可能您的退料已被别人退掉了!", bai.getTypeId());
continue;
}
//更加退料接收的数据创建下一步流程
//合格的插入入库记录input_apply_details修改库存ma_type,修改机具状态
if (hgList != null && hgList.size() > 0) {
@ -250,30 +259,25 @@ public class BackReceiveServiceImpl implements BackReceiveService {
res = insertSad(newTaskId, bfList);
}
List<BackApplyInfo> allList = backReceiveMapper.getAllList(record);
if (allList != null && allList.size() > 0) {
res = updateSlt(record, allList);
//更新结算表 slt_agreement_info
res = updateSlt4Bean(record, bai);
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);
int postStoreNum = backReceiveMapper.getmaChineByCt(record);
record.setPostStoreNum(postStoreNum);
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,8 +290,7 @@ public class BackReceiveServiceImpl implements BackReceiveService {
}
}
private int updateSlt(BackApplyInfo record, List<BackApplyInfo> hgList) {
for (BackApplyInfo bean : hgList) {
private int updateSlt4Bean(BackApplyInfo record, BackApplyInfo bean) {
List<SltAgreementInfo> infoList = backReceiveMapper.getStlInfo(bean);
if (infoList.size() > 0) {
Integer backNum = bean.getBackNum();
@ -309,10 +312,36 @@ public class BackReceiveServiceImpl implements BackReceiveService {
} else {
return 0;
}
}
return 1;
}
// private int updateSlt(BackApplyInfo record, List<BackApplyInfo> hgList) {
// for (BackApplyInfo bean : hgList) {
// List<SltAgreementInfo> 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<BackApplyInfo> codeQuery(BackApplyInfo record) {
return backReceiveMapper.codeQuery(record);

View File

@ -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());

View File

@ -778,7 +778,24 @@
</select>
<select id="getmaChineByCt" resultType="java.lang.Integer">
select num from ma_type WHERE type_id = #{typeId}
SELECT
CASE mt.manage_type
WHEN 0 THEN
IFNULL(subquery0.num, 0)
ELSE
IFNULL(mt.num, 0)
END as num
FROM ma_type mt
left join (SELECT mt.type_id,
mt2.type_name AS typeName,
mt.type_name AS typeModelName,
count(mm.ma_id) num
FROM ma_machine mm
LEFT JOIN ma_type mt ON mt.type_id = mm.type_id
LEFT JOIN ma_type mt2 ON mt2.type_id = mt.parent_id
WHERE mm.ma_code is not null and mm.ma_status in (15)
GROUP BY mt.type_id) AS subquery0 ON subquery0.type_id = mt.type_id
WHERE mt.del_flag = '0' and mt.type_id = #{typeId}
</select>
<select id="selectTaskNumByMonthWx" resultType="java.lang.Integer">
@ -802,6 +819,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='1' and (bcd.is_finished is null or bcd.is_finished != 1)
</select>
@ -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)
</select>
@ -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)
</select>

View File

@ -450,7 +450,24 @@
mt.type_id = #{typeId}
</select>
<select id="getmaChineByCt" resultType="java.lang.Integer">
select num from ma_type WHERE type_id = #{typeId}
SELECT
CASE mt.manage_type
WHEN 0 THEN
IFNULL(subquery0.num, 0)
ELSE
IFNULL(mt.num, 0)
END as num
FROM ma_type mt
left join (SELECT mt.type_id,
mt2.type_name AS typeName,
mt.type_name AS typeModelName,
count(mm.ma_id) num
FROM ma_machine mm
LEFT JOIN ma_type mt ON mt.type_id = mm.type_id
LEFT JOIN ma_type mt2 ON mt2.type_id = mt.parent_id
WHERE mm.ma_code is not null and mm.ma_status in (15)
GROUP BY mt.type_id) AS subquery0 ON subquery0.type_id = mt.type_id
WHERE mt.del_flag = '0' and mt.type_id = #{typeId}
</select>
<select id="getLeaseApplyDetails" resultType="com.bonus.sgzb.app.domain.LeaseApplyDetails">
SELECT