diff --git a/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/app/mapper/BackReceiveMapper.java b/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/app/mapper/BackReceiveMapper.java
index 2a0e33d0..417908e4 100644
--- a/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/app/mapper/BackReceiveMapper.java
+++ b/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/app/mapper/BackReceiveMapper.java
@@ -213,4 +213,18 @@ public interface BackReceiveMapper {
int updateStatus(BackApplyInfo record);
int finishBackCheckDetails(BackApplyInfo record);
+
+ /**
+ * 修改退料记录表back_check_details为完成退料
+ * @param id
+ * @return
+ */
+ int updateBackCheckDetails(Long id);
+
+ /**
+ * 根据查询协议id
+ * @param record
+ * @return
+ */
+ String selectAgreementId(BackApplyInfo record);
}
\ No newline at end of file
diff --git a/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/app/service/impl/BackReceiveServiceImpl.java b/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/app/service/impl/BackReceiveServiceImpl.java
index 703391f0..815696f6 100644
--- a/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/app/service/impl/BackReceiveServiceImpl.java
+++ b/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/app/service/impl/BackReceiveServiceImpl.java
@@ -274,12 +274,35 @@ public class BackReceiveServiceImpl implements BackReceiveService {
int postStoreNum = backReceiveMapper.getmaChineByCt(record);
record.setPostStoreNum(postStoreNum);
}
+ // 修改退料记录表back_check_details为完成退料(1)
+ if (StringUtils.isNotBlank(record.getBadId())) {
+ res = updateBackCheckDetails(record);
+ if (res == 0) {
+ throw new RuntimeException("修改back_check_details表异常");
+ }
+ }
} else {
throw new RuntimeException("typeId为空");
}
return res;
}
+ /**
+ * 修改退料记录表back_check_details为完成退料(1)
+ * @param record
+ * @return
+ */
+ private int updateBackCheckDetails(BackApplyInfo record) {
+ int res = 0;
+ // 对record中的badId进行分割
+ String[] split = record.getBadId().split(",");
+ for (String s : split) {
+ long id = Long.parseLong(s);
+ res += backReceiveMapper.updateBackCheckDetails(id);
+ }
+ return res;
+ }
+
private int selectTaskStatus(int taskId) {
int taskStatus = backReceiveMapper.selectTaskStatus(taskId);
if (taskStatus == 40) {
@@ -525,6 +548,8 @@ public class BackReceiveServiceImpl implements BackReceiveService {
BackApplyInfo[] arr = record.getArr();
if (arr.length > 0) {
for (int i = 0; i < arr.length; i++) {
+ // 退料核查中
+ arr[i].setStatus("0");
res = backReceiveMapper.insertCheckDetails(arr[i]);
String manageType = arr[i].getManageType();
if ("0".equals(manageType)) {
diff --git a/sgzb-modules/sgzb-base/src/main/resources/mapper/app/BackReceiveMapper.xml b/sgzb-modules/sgzb-base/src/main/resources/mapper/app/BackReceiveMapper.xml
index 346803a3..9aa58839 100644
--- a/sgzb-modules/sgzb-base/src/main/resources/mapper/app/BackReceiveMapper.xml
+++ b/sgzb-modules/sgzb-base/src/main/resources/mapper/app/BackReceiveMapper.xml
@@ -302,6 +302,9 @@
back_status,
+
+ status,
+
create_by,
@@ -342,6 +345,9 @@
#{backStatus},
+
+ #{status},
+
#{createBy},
@@ -620,6 +626,11 @@
update back_check_details set is_finished = 1 where parent_id = #{parentId} and type_id = #{typeId} and (is_finished is null or is_finished != 1)
+
+
+ update back_check_details set status = '1' where id = #{id}
+
+
delete from back_check_details where parent_id = #{parentId} and type_id = #{typeId} and (is_finished is null or is_finished != 1)
@@ -720,7 +731,8 @@
mt.manage_type as manageType,
mt.company_id as companyId,
CONCAT('NSJJ',mt.`code`,mt.model_code) as `code`,
- mtk.userId as userId
+ mtk.userId as userId,
+ aa.badId as badId
FROM
back_apply_details bad
LEFT JOIN back_apply_info bai on bai.id=bad.parent_id
@@ -729,6 +741,7 @@
LEFT JOIN ma_type mt2 ON mt2.type_id=mt.parent_id
LEFT JOIN (
SELECT
+ GROUP_CONCAT(id) as badId,
type_id as typeId,
SUM(IFNULL(back_num,0)) as back_num
FROM
@@ -1163,4 +1176,13 @@
order by bad.create_time
+
+
\ No newline at end of file
diff --git a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/controller/BackApplyController.java b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/controller/BackApplyController.java
index c3f9ebae..cafe8780 100644
--- a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/controller/BackApplyController.java
+++ b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/controller/BackApplyController.java
@@ -157,6 +157,10 @@ public class BackApplyController extends BaseController {
return AjaxResult.error("参数错误");
}
try {
+ //查看本次退料申请是否合法,判断本次退料申请数量和之前的退料申请数量之和是否超过领料出库数量
+ if (!backApplyService.isBackApplyNumberCorrect(bean)) {
+ return AjaxResult.error("已申请退料数量加上本次退料申请数量,超过领料出库数量,请重试!");
+ }
//生成退料编码
String code = backApplyService.genderBackCode();
if (StringUtils.isEmpty(code)) {
diff --git a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/mapper/BackApplyMapper.java b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/mapper/BackApplyMapper.java
index db985384..88217ab6 100644
--- a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/mapper/BackApplyMapper.java
+++ b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/mapper/BackApplyMapper.java
@@ -1,9 +1,6 @@
package com.bonus.sgzb.material.mapper;
-import com.bonus.sgzb.material.domain.BackApplyDto;
-import com.bonus.sgzb.material.domain.BackApplyInfo;
-import com.bonus.sgzb.material.domain.ScrapApplyDetails;
-import com.bonus.sgzb.material.domain.TypeTreeNode;
+import com.bonus.sgzb.material.domain.*;
import com.bonus.sgzb.material.domain.po.BackApplyDetailsPo;
import com.bonus.sgzb.material.domain.po.BackApplyInfoPo;
import org.apache.ibatis.annotations.Mapper;
@@ -159,4 +156,18 @@ public interface BackApplyMapper {
void insertBackApplyDetails(BackApplyDetailsPo backApplyDetailsPoNew);
void updateBackApplyDetailsByParentId(BackApplyDetailsPo backApplyDetailsPoNew);
+
+ /**
+ * 获取退料申请统计
+ * @param bean
+ * @return
+ */
+ List getBackApplyDetailsTypeCount(BackApplyInfo bean);
+
+ /**
+ * 获取领料申请统计
+ * @param bean
+ * @return
+ */
+ List getLeaseApplyDetailsTypeCount(BackApplyInfo bean);
}
diff --git a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/service/BackApplyService.java b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/service/BackApplyService.java
index c3c8bac1..143d57cc 100644
--- a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/service/BackApplyService.java
+++ b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/service/BackApplyService.java
@@ -129,4 +129,11 @@ public interface BackApplyService {
* @return
*/
AjaxResult auditAll(BackApplyDto dto);
+
+ /**
+ * 退料申请提交
+ * @param bean
+ * @return
+ */
+ boolean isBackApplyNumberCorrect(BackApplyInfo bean);
}
diff --git a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/service/impl/BackApplyServiceImpl.java b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/service/impl/BackApplyServiceImpl.java
index 03494940..ab8e9718 100644
--- a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/service/impl/BackApplyServiceImpl.java
+++ b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/service/impl/BackApplyServiceImpl.java
@@ -17,6 +17,7 @@ import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat;
import java.util.*;
+import java.util.stream.Collectors;
/**
* @author hay
@@ -469,6 +470,63 @@ public class BackApplyServiceImpl implements BackApplyService {
}
}
+ /**
+ * 退料提交数据校验
+ * @param bean
+ * @return
+ */
+ @Override
+ public boolean isBackApplyNumberCorrect(BackApplyInfo bean) {
+ // 已建退料数据
+ Map oldBackMap = new HashMap<>();
+ // 已领出库数据
+ Map leaseMap = new HashMap<>();
+ // 本次退料数据
+ Map thisBackMap = new HashMap<>();
+ // 查看该协议已建立退料数据
+ List oldBackTypes = backApplyMapper.getBackApplyDetailsTypeCount(bean);
+ if (CollectionUtils.isNotEmpty(oldBackTypes)) {
+ oldBackMap = oldBackTypes.stream().collect(Collectors.groupingBy(BackApplyInfo::getTypeId,
+ Collectors.summingInt(BackApplyInfo::getBackNum)));
+ }
+ // 查看领料出库数据
+ List leaseTypes = backApplyMapper.getLeaseApplyDetailsTypeCount(bean);
+ if (CollectionUtils.isNotEmpty(leaseTypes)) {
+ leaseMap = leaseTypes.stream()
+ .collect(Collectors.groupingBy(
+ LeaseApplyDetails::getTypeId,
+ Collectors.mapping(
+ LeaseApplyDetails::getAlNum,
+ Collectors.collectingAndThen(
+ Collectors.summingDouble(Double::doubleValue),
+ Double::intValue
+ )
+ )
+ ));
+ }
+ // 本次退料数据
+ if (CollectionUtils.isNotEmpty(bean.getBackApplyDetails())) {
+ thisBackMap = bean.getBackApplyDetails().stream()
+ .collect(Collectors.groupingBy(
+ BackApplyInfo::getTypeId,
+ Collectors.mapping(
+ info -> Integer.parseInt(info.getNum()),
+ Collectors.summingInt(Integer::intValue)
+ )
+ ));
+ }
+ // 判断3个list是否具备合法性
+ for (Integer key : leaseMap.keySet()) {
+ int oldBackNum = Objects.isNull(oldBackMap.get(String.valueOf(key))) ? 0 : oldBackMap.get(String.valueOf(key));
+ int thisBackNum = Objects.isNull(thisBackMap.get(String.valueOf(key))) ? 0 : thisBackMap.get(String.valueOf(key));
+ int leaseNum = Objects.isNull(leaseMap.get(key)) ? 0 : leaseMap.get(key);
+ if (oldBackNum + thisBackNum > leaseNum) {
+ return false;
+ }
+ }
+ return true;
+ }
+
private int auditAllDetails(BackApplyDto dto) {
int re = 0;
if (CollUtil.isNotEmpty(dto.getBackApplyList())) {
diff --git a/sgzb-modules/sgzb-material/src/main/resources/mapper/material/BackApplyMapper.xml b/sgzb-modules/sgzb-material/src/main/resources/mapper/material/BackApplyMapper.xml
index f839ef13..e78a690a 100644
--- a/sgzb-modules/sgzb-material/src/main/resources/mapper/material/BackApplyMapper.xml
+++ b/sgzb-modules/sgzb-material/src/main/resources/mapper/material/BackApplyMapper.xml
@@ -1070,4 +1070,23 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+
+
+
\ No newline at end of file
diff --git a/sgzb-modules/sgzb-material/src/main/resources/mapper/material/StorageStatusMapper.xml b/sgzb-modules/sgzb-material/src/main/resources/mapper/material/StorageStatusMapper.xml
index 0f06c73c..d5eeea1e 100644
--- a/sgzb-modules/sgzb-material/src/main/resources/mapper/material/StorageStatusMapper.xml
+++ b/sgzb-modules/sgzb-material/src/main/resources/mapper/material/StorageStatusMapper.xml
@@ -87,6 +87,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
LEFT JOIN ma_type mt ON mt.type_id = bcd.type_id
LEFT JOIN ma_type mt2 ON mt2.type_id = mt.parent_id
LEFT JOIN ma_machine mm ON mm.ma_id = bcd.ma_id
+ where (bcd.status = '1' or bcd.status is null)
GROUP BY
mt.type_id
) AS subquery2 ON subquery1.type_id = subquery2.type_id