领料需求发布量更改

This commit is contained in:
mashuai 2025-11-26 14:19:33 +08:00
parent ca6e97dab7
commit b9e55c1619
6 changed files with 186 additions and 25 deletions

View File

@ -212,6 +212,8 @@ public class LeaseApplyDetails extends BaseEntity {
@ApiModelProperty(value = "任务唯一标识单号") @ApiModelProperty(value = "任务唯一标识单号")
private String keyId; private String keyId;
private List<String> oldTypeIdList;
@ApiModelProperty(value = "领料物资名称汇总") @ApiModelProperty(value = "领料物资名称汇总")
private String maTypeNames; private String maTypeNames;
public LeaseApplyDetails(Long id, Long parentId, Long typeId, BigDecimal preNum, BigDecimal auditNum, BigDecimal alNum, String status, Long companyId) { public LeaseApplyDetails(Long id, Long parentId, Long typeId, BigDecimal preNum, BigDecimal auditNum, BigDecimal alNum, String status, Long companyId) {

View File

@ -240,4 +240,11 @@ public interface LeaseApplyDetailsMapper {
List<LeaseApplyDetailExport> selectLeaseApplyLL(LeaseApplyInfo bean); List<LeaseApplyDetailExport> selectLeaseApplyLL(LeaseApplyInfo bean);
List<LeaseApplyDetailExport> selectLeaseApplyLY(LeaseApplyInfo bean); List<LeaseApplyDetailExport> selectLeaseApplyLY(LeaseApplyInfo bean);
/**
* 根据oldTypeId和parentId查询领用待发布数量
* @param detail
* @return
*/
LeaseApplyDetails getPublishNum(LeaseApplyDetails detail);
} }

View File

@ -247,7 +247,7 @@ public interface LeaseApplyInfoMapper {
* @param leaseApplyDetails * @param leaseApplyDetails
* @return * @return
*/ */
LeaseApplyDetails getPublishNum(LeaseApplyDetails leaseApplyDetails); List<LeaseApplyDetails> getPublishNum(LeaseApplyDetails leaseApplyDetails);
/** /**
* 修改领用单的领用单出库数量 * 修改领用单的领用单出库数量
@ -319,4 +319,32 @@ public interface LeaseApplyInfoMapper {
* @return * @return
*/ */
List<Long> selectPublishSignList(LeaseApplyInfo applyInfo); List<Long> selectPublishSignList(LeaseApplyInfo applyInfo);
/**
* 根据parentId及newTypeId查询发布数量
* @param leaseApplyDetails
* @return
*/
List<LeaseApplyDetails> getPublishNumTwo(LeaseApplyDetails leaseApplyDetails);
/**
* 删除该条发布数据
* @param publishDetails
* @return
*/
int deletePublish(LeaseApplyDetails publishDetails);
/**
* 减去该条发布数据
* @param publishDetails
* @return
*/
int subtractLeasePublish(LeaseApplyDetails publishDetails);
/**
* 修改该条发布数据
* @param publishDetails
* @return
*/
int updateLeaseApplyDetails(LeaseApplyDetails publishDetails);
} }

View File

@ -227,6 +227,17 @@ public class LeaseApplyInfoServiceImpl implements ILeaseApplyInfoService {
LeaseApplyDetails pendingOutNum = mapper.selectPendingOutNum(detail); LeaseApplyDetails pendingOutNum = mapper.selectPendingOutNum(detail);
detail.setPendingOutNum(pendingOutNum.getPendingOutNum()); detail.setPendingOutNum(pendingOutNum.getPendingOutNum());
detail.setStorageNum(pendingOutNum.getStorageNum()); detail.setStorageNum(pendingOutNum.getStorageNum());
if (StringUtils.isNotBlank(publishTask)) {
// 根据oldTypeId和parentId查询领用待发布数量
if (StringUtils.isNotBlank(detail.getOldTypeId())) {
List<String> oldTypeIdList = Arrays.asList(detail.getOldTypeId().split(","));
detail.setOldTypeIdList(oldTypeIdList);
}
LeaseApplyDetails applyDetails = leaseApplyDetailsMapper.getPublishNum(detail);
if (applyDetails != null) {
detail.setPendingPublishNum(applyDetails.getPendingPublishNum().add(detail.getPreNum()));
}
}
} }
} }
stepTimes.put("领用发布查询", System.currentTimeMillis() - step81Start); stepTimes.put("领用发布查询", System.currentTimeMillis() - step81Start);
@ -1103,22 +1114,76 @@ public class LeaseApplyInfoServiceImpl implements ILeaseApplyInfoService {
public AjaxResult updateLeaseNum(LeaseApplyDetails leaseApplyDetails) { public AjaxResult updateLeaseNum(LeaseApplyDetails leaseApplyDetails) {
try { try {
if (leaseApplyDetails.getNewTypeId()!= null) { if (leaseApplyDetails.getNewTypeId()!= null) {
// 根据parentId查询发布数量 // 根据parentId及oldTypeIdList查询需求数量
//LeaseApplyDetails applyDetails = leaseApplyInfoMapper.getPublishNum(leaseApplyDetails); List<LeaseApplyDetails> applyDetailsList = leaseApplyInfoMapper.getPublishNum(leaseApplyDetails);
// 根据传入的值判断少了多少发布数量 // 根据parentId及newTypeId查询发布及待发布数量
leaseApplyDetails.setPublishNum(leaseApplyDetails.getPreNum()); List<LeaseApplyDetails> publishDetailsList = leaseApplyInfoMapper.getPublishNumTwo(leaseApplyDetails);
int res = leaseApplyInfoMapper.updateLeaseNum(leaseApplyDetails); // 根据传入的值判断发布数量是增加还是减少
if (res <= 0){ // 新数量
return AjaxResult.error("修改领用表失败"); BigDecimal preNum = leaseApplyDetails.getPreNum();
// 老数量
BigDecimal publishNum = leaseApplyDetails.getPublishNum();
if (preNum.compareTo(publishNum) > 0) {
// 差值
BigDecimal subtractNum = preNum.subtract(publishNum);
for (LeaseApplyDetails applyDetails : applyDetailsList) {
// 待发布数量
BigDecimal subNum = applyDetails.getPendingNum();
if (subtractNum.compareTo(subNum) <= 0) {
applyDetails.setPendingNum(subtractNum);
leaseApplyInfoMapper.updateLeaseNum(applyDetails);
break;
} else if (subtractNum.compareTo(subNum) > 0) {
subtractNum = subtractNum.subtract(subNum);
applyDetails.setPendingNum(subtractNum);
leaseApplyInfoMapper.updateLeaseNum(applyDetails);
}
}
// 差值
BigDecimal leaseSubtractNum = preNum.subtract(publishNum);
for (LeaseApplyDetails publishDetails : publishDetailsList) {
// 待发布数量
BigDecimal pendingNum = publishDetails.getPendingNum();
if (leaseSubtractNum.compareTo(pendingNum) <= 0) {
publishDetails.setPendingNum(leaseSubtractNum);
leaseApplyInfoMapper.updateLeasePublish(publishDetails);
break;
} else if (leaseSubtractNum.compareTo(pendingNum) > 0) {
leaseSubtractNum = leaseSubtractNum.subtract(pendingNum);
publishDetails.setPendingNum(leaseSubtractNum);
leaseApplyInfoMapper.updateLeasePublish(publishDetails);
}
}
} else if (preNum.compareTo(publishNum) < 0) {
// 差值
BigDecimal leaseSubtractNum = publishNum.subtract(preNum);
for (LeaseApplyDetails publishDetails : publishDetailsList) {
// 发布数量
BigDecimal num = publishDetails.getPublishNum();
if (leaseSubtractNum.compareTo(num) == 0) {
//删除该条发布数据
leaseApplyInfoMapper.deletePublish(publishDetails);
//处理lease_apply_details表数据
leaseApplyInfoMapper.updateLeaseApplyDetails(publishDetails);
break;
} else if (leaseSubtractNum.compareTo(num) > 0) {
leaseSubtractNum = leaseSubtractNum.subtract(num);
leaseApplyInfoMapper.deletePublish(publishDetails);
//处理lease_apply_details表数据
leaseApplyInfoMapper.updateLeaseApplyDetails(publishDetails);
} else if (leaseSubtractNum.compareTo(num) < 0) {
publishDetails.setPublishNum(leaseSubtractNum);
leaseApplyInfoMapper.subtractLeasePublish(publishDetails);
//处理lease_apply_details表数据
leaseApplyInfoMapper.updateLeaseApplyDetails(publishDetails);
break;
}
} }
res = leaseApplyInfoMapper.updateLeasePublish(leaseApplyDetails);
if (res <= 0){
return AjaxResult.error("修改领料发布表失败");
} }
} else { } else {
int res = leaseApplyInfoMapper.updateLeaseNumTwo(leaseApplyDetails); int result = leaseApplyInfoMapper.updateLeaseNumTwo(leaseApplyDetails);
if (res <= 0){ if (result <= 0) {
return AjaxResult.error("修改领料表失败"); throw new Exception("修改领料表失败");
} }
} }
return AjaxResult.success("修改成功"); return AjaxResult.success("修改成功");

View File

@ -89,7 +89,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
lad.create_by, lad.create_time, lad.update_by, lad.update_time, lad.remark, lad.company_id, lad.create_by, lad.create_time, lad.update_by, lad.update_time, lad.remark, lad.company_id,
mt4.type_id as firstId, mt4.type_id as firstId,
su.sign_url as signUrl, su.sign_url as signUrl,
su.sign_type as signType su.sign_type as signType,
IFNULL(lad.pre_num,0) as pendingPublishNum
from from
lease_apply_details lad lease_apply_details lad
left join left join
@ -893,4 +894,18 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
order by lpd.id order by lpd.id
</select> </select>
<select id="getPublishNum" resultType="com.bonus.material.lease.domain.LeaseApplyDetails">
SELECT
parent_id as parentId,
GREATEST(SUM(IFNULL(pre_num, 0)) - SUM(IFNULL(publish_num, 0)), 0 ) AS pendingPublishNum
FROM
lease_apply_details
WHERE
parent_id = #{parentId}
AND type_id IN
<foreach item="item" collection="oldTypeIdList" open="(" separator="," close=")">
#{item}
</foreach>
</select>
</mapper> </mapper>

View File

@ -279,6 +279,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</foreach> </foreach>
</delete> </delete>
<delete id="deletePublish">
delete from lease_publish_details where id = #{id}
</delete>
<select id="getTaskId" resultType="java.lang.String"> <select id="getTaskId" resultType="java.lang.String">
select task_id select task_id
from lease_apply_info from lease_apply_info
@ -840,9 +844,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<update id="updateLeaseNum"> <update id="updateLeaseNum">
update lease_apply_details update lease_apply_details
set publish_num=#{publishNum} set publish_num = IFNULL(publish_num, 0) + #{pendingNum}
where parent_id = #{parentId} where id = #{id}
AND new_type = #{newTypeId}
</update> </update>
<update id="updateLeaseNumTwo"> <update id="updateLeaseNumTwo">
@ -854,10 +857,21 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<update id="updateLeasePublish"> <update id="updateLeasePublish">
update lease_publish_details update lease_publish_details
set num = #{preNum} set num = num + #{pendingNum}
where id = #{id}
</update>
<update id="subtractLeasePublish">
update lease_publish_details
set num = num - #{publishNum}
where id = #{id}
</update>
<update id="updateLeaseApplyDetails">
update lease_apply_details
set publish_num = IFNULL(publish_num, 0) - #{publishNum}
where parent_id = #{parentId} where parent_id = #{parentId}
AND new_type = #{newTypeId} and type_id = #{typeId}
AND publish_task = #{publishTask}
</update> </update>
<select id="getUserList" resultMap="LeaseApplyInfoResult"> <select id="getUserList" resultMap="LeaseApplyInfoResult">
@ -987,14 +1001,23 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select> </select>
<select id="getPublishNum" resultType="com.bonus.material.lease.domain.LeaseApplyDetails"> <select id="getPublishNum" resultType="com.bonus.material.lease.domain.LeaseApplyDetails">
SELECT SELECT
id AS id,
parent_id AS parentId, parent_id AS parentId,
type_id AS typeId, type_id AS typeId,
publish_num AS publishNum pre_num AS preNum,
publish_num AS publishNum,
pre_num - IFNULL( publish_num, 0 ) AS pendingNum
FROM FROM
lease_apply_details lease_apply_details
WHERE WHERE
parent_id = #{parentId} parent_id = #{parentId}
and new_type = #{newTypeId} AND type_id IN
<foreach item="item" collection="oldTypeIdList" open="(" separator="," close=")">
#{item}
</foreach>
GROUP BY
parent_id,
type_id
</select> </select>
<select id="getSignPublishList" resultType="com.bonus.common.biz.domain.lease.LeaseApplyInfo"> <select id="getSignPublishList" resultType="com.bonus.common.biz.domain.lease.LeaseApplyInfo">
@ -1259,4 +1282,25 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</if> </if>
</where> </where>
</select> </select>
<select id="getPublishNumTwo" resultType="com.bonus.material.lease.domain.LeaseApplyDetails">
SELECT
lpd.id as id,
lpd.parent_id as parentId,
lpd.type_id as typeId,
lpd.new_type as newTypeId,
lad.pre_num - IFNULL( lad.publish_num, 0 ) as pendingNum,
lpd.num as publishNum
FROM
lease_publish_details lpd
LEFT JOIN lease_apply_details lad ON lpd.parent_id = lad.parent_id
AND lpd.type_id = lad.type_id
WHERE
lpd.new_type = #{newTypeId}
AND lpd.parent_id = #{parentId}
AND lpd.publish_task = #{publishTask}
GROUP BY
lpd.parent_id,
lpd.type_id
</select>
</mapper> </mapper>