优化订单分批出入库的状态计算逻辑

This commit is contained in:
季圣华 2022-05-17 00:04:35 +08:00
parent ae216488fe
commit 8b88d0abc4
4 changed files with 89 additions and 9 deletions

View File

@ -0,0 +1,26 @@
package com.jsh.erp.datasource.entities;
import java.math.BigDecimal;
public class DepotItemVo4MaterialAndSum {
private Long materialExtendId;
private BigDecimal operNumber;
public Long getMaterialExtendId() {
return materialExtendId;
}
public void setMaterialExtendId(Long materialExtendId) {
this.materialExtendId = materialExtendId;
}
public BigDecimal getOperNumber() {
return operNumber;
}
public void setOperNumber(BigDecimal operNumber) {
this.operNumber = operNumber;
}
}

View File

@ -159,4 +159,11 @@ public interface DepotItemMapperEx {
Long getCountByMaterialAndDepot(
@Param("mId") Long mId,
@Param("depotId") Long depotId);
List<DepotItemVo4MaterialAndSum> getLinkBillDetailMaterialSum(
@Param("linkNumber") String linkNumber);
List<DepotItemVo4MaterialAndSum> getBatchBillDetailMaterialSum(
@Param("linkNumber") String linkNumber,
@Param("type") String type);
}

View File

@ -406,8 +406,6 @@ public class DepotItemService {
}
//删除单据的明细
deleteDepotItemHeadId(headerId);
//单据状态:是否全部完成 2-全部完成 3-部分完成针对订单的分批出入库
String billStatus = BusinessConstants.BILLS_STATUS_SKIPED;
JSONArray rowArr = JSONArray.parseArray(rows);
if (null != rowArr && rowArr.size()>0) {
for (int i = 0; i < rowArr.size(); i++) {
@ -460,16 +458,14 @@ public class DepotItemService {
depotItem.setBasicNumber(oNumber); //其他情况
}
}
//如果数量+已完成数量<原订单数量代表该单据状态为未全部完成出入库(判断前提是存在关联订单)
//如果数量+已完成数量>原订单数量给出预警(判断前提是存在关联订单)
if (StringUtil.isNotEmpty(depotHead.getLinkNumber())
&& StringUtil.isExist(rowObj.get("preNumber")) && StringUtil.isExist(rowObj.get("finishNumber"))) {
if("add".equals(actionType)) {
//在新增模式进行状态赋值
BigDecimal preNumber = rowObj.getBigDecimal("preNumber");
BigDecimal finishNumber = rowObj.getBigDecimal("finishNumber");
if(depotItem.getOperNumber().add(finishNumber).compareTo(preNumber)<0) {
billStatus = BusinessConstants.BILLS_STATUS_SKIPING;
} else if(depotItem.getOperNumber().add(finishNumber).compareTo(preNumber)>0) {
if(depotItem.getOperNumber().add(finishNumber).compareTo(preNumber)>0) {
throw new BusinessRunTimeException(ExceptionConstants.DEPOT_HEAD_NUMBER_NEED_EDIT_FAILED_CODE,
String.format(ExceptionConstants.DEPOT_HEAD_NUMBER_NEED_EDIT_FAILED_MSG, barCode));
}
@ -481,9 +477,7 @@ public class DepotItemService {
BigDecimal preNumber = getPreItemByHeaderIdAndMaterial(depotHead.getLinkNumber(), depotItem.getMaterialExtendId()).getOperNumber();
//除去此单据之外的已入库|已出库
BigDecimal realFinishNumber = getRealFinishNumber(depotItem.getMaterialExtendId(), preHeaderId, headerId, unitInfo, unit);
if(depotItem.getOperNumber().add(realFinishNumber).compareTo(preNumber)<0) {
billStatus = BusinessConstants.BILLS_STATUS_SKIPING;
} else if(depotItem.getOperNumber().add(realFinishNumber).compareTo(preNumber)>0) {
if(depotItem.getOperNumber().add(realFinishNumber).compareTo(preNumber)>0) {
throw new BusinessRunTimeException(ExceptionConstants.DEPOT_HEAD_NUMBER_NEED_EDIT_FAILED_CODE,
String.format(ExceptionConstants.DEPOT_HEAD_NUMBER_NEED_EDIT_FAILED_MSG, barCode));
}
@ -567,6 +561,8 @@ public class DepotItemService {
if(BusinessConstants.SUB_TYPE_PURCHASE.equals(depotHead.getSubType())
|| BusinessConstants.SUB_TYPE_SALES.equals(depotHead.getSubType())) {
if(StringUtil.isNotEmpty(depotHead.getLinkNumber())) {
//单据状态:是否全部完成 2-全部完成 3-部分完成针对订单的分批出入库
String billStatus = getBillStatusByParam(depotHead);
changeBillStatus(depotHead, billStatus);
}
}
@ -576,6 +572,36 @@ public class DepotItemService {
}
}
/**
* 判断单据的状态
* 通过数组对比原单据的商品和商品数量汇总 分批操作后单据的商品和商品数量汇总
* @param depotHead
* @return
*/
public String getBillStatusByParam(DepotHead depotHead) {
String res = BusinessConstants.BILLS_STATUS_SKIPED;
//获取原单据的商品和商品数量汇总
List<DepotItemVo4MaterialAndSum> linkList = depotItemMapperEx.getLinkBillDetailMaterialSum(depotHead.getLinkNumber());
//获取分批操作后单据的商品和商品数量汇总
List<DepotItemVo4MaterialAndSum> batchList = depotItemMapperEx.getBatchBillDetailMaterialSum(depotHead.getLinkNumber(), depotHead.getType());
//将分批操作后的单据的商品和商品数据构造成Map
Map<Long, BigDecimal> materialSumMap = new HashMap<>();
for(DepotItemVo4MaterialAndSum materialAndSum : batchList) {
materialSumMap.put(materialAndSum.getMaterialExtendId(), materialAndSum.getOperNumber());
}
for(DepotItemVo4MaterialAndSum materialAndSum : linkList) {
BigDecimal materialSum = materialSumMap.get(materialAndSum.getMaterialExtendId());
if(materialSum!=null) {
if(materialSum.compareTo(materialAndSum.getOperNumber()) != 0) {
res = BusinessConstants.BILLS_STATUS_SKIPING;
}
} else {
res = BusinessConstants.BILLS_STATUS_SKIPING;
}
}
return res;
}
/**
* 更新单据状态
* @param depotHead

View File

@ -90,6 +90,11 @@
<result column="total_num" jdbcType="VARCHAR" property="totalNum" />
</resultMap>
<resultMap id="materialSumMap" type="com.jsh.erp.datasource.entities.DepotItemVo4MaterialAndSum">
<result column="material_extend_id" jdbcType="VARCHAR" property="materialExtendId" />
<result column="oper_number" jdbcType="VARCHAR" property="operNumber" />
</resultMap>
<select id="selectByConditionDepotItem" parameterType="com.jsh.erp.datasource.entities.DepotItemExample" resultMap="com.jsh.erp.datasource.mappers.DepotItemMapper.BaseResultMap">
select *
FROM jsh_depot_item
@ -614,4 +619,20 @@
where di.material_id=#{mId} and di.depot_id=#{depotId}
and ifnull(di.delete_flag,'0') !='1'
</select>
<select id="getLinkBillDetailMaterialSum" resultMap="materialSumMap">
select di.material_extend_id, sum(di.oper_number) oper_number from jsh_depot_head dh
left join jsh_depot_item di on dh.id=di.header_id and ifnull(di.delete_flag,'0') !='1'
where dh.number=#{linkNumber}
and ifnull(dh.delete_flag,'0') !='1'
group by di.material_extend_id
</select>
<select id="getBatchBillDetailMaterialSum" resultMap="materialSumMap">
select di.material_extend_id, sum(di.oper_number) oper_number from jsh_depot_head dh
left join jsh_depot_item di on dh.id=di.header_id and ifnull(di.delete_flag,'0') !='1'
where dh.link_number=#{linkNumber} and dh.type=#{type}
and ifnull(dh.delete_flag,'0') !='1'
group by di.material_extend_id
</select>
</mapper>