This commit is contained in:
parent
99fc70cf0c
commit
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,135 @@ 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;
|
||||
int maxBackNumBackEnd = 0;
|
||||
int passNum = 0;
|
||||
int maintenanceNum = 0;
|
||||
int scrapNum = 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) {
|
||||
record.setTypeId(bai.getTypeId());
|
||||
int num = backReceiveMapper.getmaChineByCt(record);
|
||||
record.setNum(num);
|
||||
|
||||
//修改任务状态
|
||||
List<BackApplyInfo> list = totalList.stream().filter(o -> o.getTypeId().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("check001退料接收:{},{},{},{}", maxBackNumBackEnd, passNum, maintenanceNum, scrapNum);
|
||||
if (maxBackNumBackEnd < passNum + maintenanceNum + scrapNum) {
|
||||
throw new RuntimeException("提交退料数量大于最大退料数,可能您的退料已被别人退掉了");
|
||||
}
|
||||
|
||||
//更加退料接收的数据创建下一步流程
|
||||
//合格的插入入库记录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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
//维修的创建维修任务,插入任务协议表
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue