Compare commits
8 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
31b70ce42e | |
|
|
c0831402b0 | |
|
|
63439f1c73 | |
|
|
f15593e866 | |
|
|
98a45fd27e | |
|
|
4b8923c8cc | |
|
|
2082e43f19 | |
|
|
adf408ae8e |
|
|
@ -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<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> list = backReceiveMapper.receiveView4Backend(record);
|
||||
if (!CollectionUtils.isEmpty(list)) {
|
||||
for (BackApplyInfo backApplyInfo : list) {
|
||||
maxBackNumBackEnd += (int) backApplyInfo.getMaxBackNumBackend();
|
||||
}
|
||||
}
|
||||
List<BackApplyInfo> hgList = backReceiveMapper.getHgList(record);
|
||||
if (hgList != null && hgList.size() > 0) {
|
||||
for (BackApplyInfo bi : hgList) {
|
||||
passNum += bi.getBackNum();
|
||||
}
|
||||
}
|
||||
List<BackApplyInfo> wxList = backReceiveMapper.getWxList(record);
|
||||
if (wxList != null && wxList.size() > 0) {
|
||||
for (BackApplyInfo bi : wxList) {
|
||||
maintenanceNum += bi.getBackNum();
|
||||
}
|
||||
}
|
||||
List<BackApplyInfo> 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<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修改状态");
|
||||
}
|
||||
}
|
||||
//更加退料接收的数据创建下一步流程
|
||||
//合格的插入入库记录input_apply_details,修改库存ma_type,修改机具状态
|
||||
if (hgList != null && hgList.size() > 0) {
|
||||
res = insertIad(hgList);
|
||||
if (res == 0) {
|
||||
throw new RuntimeException("input_apply_details");
|
||||
}
|
||||
// 如果是成套的机具,成套机具的库存也要添加
|
||||
List<BackApplyInfo> 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<BackApplyInfo> 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<BackApplyInfo> hgList = backReceiveMapper.getHgList(record);
|
||||
if (hgList != null && hgList.size() > 0) {
|
||||
for (BackApplyInfo bi : hgList) {
|
||||
passNum += bi.getBackNum();
|
||||
}
|
||||
}
|
||||
List<BackApplyInfo> wxList = backReceiveMapper.getWxList(record);
|
||||
if (wxList != null && wxList.size() > 0) {
|
||||
for (BackApplyInfo bi : wxList) {
|
||||
maintenanceNum += bi.getBackNum();
|
||||
}
|
||||
}
|
||||
List<BackApplyInfo> 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<BackApplyInfo> 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<BackApplyInfo> 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<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;
|
||||
}
|
||||
private int updateSlt4Bean(BackApplyInfo record, BackApplyInfo bean) {
|
||||
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;
|
||||
}
|
||||
} 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);
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue