完善关联请购单中的数量计算逻辑

This commit is contained in:
jishenghua
2024-04-23 00:44:25 +08:00
parent eeec934787
commit 6fad68f20c
8 changed files with 180 additions and 38 deletions

View File

@@ -424,6 +424,9 @@ public class ExceptionConstants {
//单据录入-单据中存在部分状态,需要到新增界面关联单据
public static final int DEPOT_ITEM_EXIST_PARTIALLY_STATUS_FAILED_CODE = 8500028;
public static final String DEPOT_ITEM_EXIST_PARTIALLY_STATUS_FAILED_MSG = "抱歉,单据:%s是部分%s状态需要到新增界面关联单据";
//单据录入-关联请购单号和关联订单号不能同时录入
public static final int DEPOT_ITEM_EXIST_REPEAT_NO_FAILED_CODE = 8500029;
public static final String DEPOT_ITEM_EXIST_REPEAT_NO_FAILED_MSG = "抱歉,关联请购单号和关联订单号不能同时录入";
/**
* 单据明细信息

View File

@@ -62,6 +62,8 @@ public class DepotHead {
private String linkNumber;
private String linkApply;
private Long tenantId;
private String deleteFlag;
@@ -298,6 +300,14 @@ public class DepotHead {
this.linkNumber = linkNumber == null ? null : linkNumber.trim();
}
public String getLinkApply() {
return linkApply;
}
public void setLinkApply(String linkApply) {
this.linkApply = linkApply == null ? null : linkApply.trim();
}
public Long getTenantId() {
return tenantId;
}

View File

@@ -1996,6 +1996,76 @@ public class DepotHeadExample {
return (Criteria) this;
}
public Criteria andLinkApplyIsNull() {
addCriterion("link_apply is null");
return (Criteria) this;
}
public Criteria andLinkApplyIsNotNull() {
addCriterion("link_apply is not null");
return (Criteria) this;
}
public Criteria andLinkApplyEqualTo(String value) {
addCriterion("link_apply =", value, "linkApply");
return (Criteria) this;
}
public Criteria andLinkApplyNotEqualTo(String value) {
addCriterion("link_apply <>", value, "linkApply");
return (Criteria) this;
}
public Criteria andLinkApplyGreaterThan(String value) {
addCriterion("link_apply >", value, "linkApply");
return (Criteria) this;
}
public Criteria andLinkApplyGreaterThanOrEqualTo(String value) {
addCriterion("link_apply >=", value, "linkApply");
return (Criteria) this;
}
public Criteria andLinkApplyLessThan(String value) {
addCriterion("link_apply <", value, "linkApply");
return (Criteria) this;
}
public Criteria andLinkApplyLessThanOrEqualTo(String value) {
addCriterion("link_apply <=", value, "linkApply");
return (Criteria) this;
}
public Criteria andLinkApplyLike(String value) {
addCriterion("link_apply like", value, "linkApply");
return (Criteria) this;
}
public Criteria andLinkApplyNotLike(String value) {
addCriterion("link_apply not like", value, "linkApply");
return (Criteria) this;
}
public Criteria andLinkApplyIn(List<String> values) {
addCriterion("link_apply in", values, "linkApply");
return (Criteria) this;
}
public Criteria andLinkApplyNotIn(List<String> values) {
addCriterion("link_apply not in", values, "linkApply");
return (Criteria) this;
}
public Criteria andLinkApplyBetween(String value1, String value2) {
addCriterion("link_apply between", value1, value2, "linkApply");
return (Criteria) this;
}
public Criteria andLinkApplyNotBetween(String value1, String value2) {
addCriterion("link_apply not between", value1, value2, "linkApply");
return (Criteria) this;
}
public Criteria andTenantIdIsNull() {
addCriterion("tenant_id is null");
return (Criteria) this;

View File

@@ -211,13 +211,15 @@ public interface DepotItemMapperEx {
BigDecimal getFinishNumber(
@Param("meId") Long meId,
@Param("linkId") Long linkId,
@Param("linkNumber") String linkNumber,
@Param("linkStr") String linkStr,
@Param("noType") String noType,
@Param("goToType") String goToType);
BigDecimal getRealFinishNumber(
@Param("meId") Long meId,
@Param("linkId") Long linkId,
@Param("linkNumber") String linkNumber,
@Param("linkStr") String linkStr,
@Param("linkType") String linkType,
@Param("currentHeaderId") Long currentHeaderId,
@Param("goToType") String goToType);
@@ -235,10 +237,11 @@ public interface DepotItemMapperEx {
@Param("depotId") Long depotId);
List<DepotItemVo4MaterialAndSum> getLinkBillDetailMaterialSum(
@Param("linkNumber") String linkNumber);
@Param("linkStr") String linkStr);
List<DepotItemVo4MaterialAndSum> getBatchBillDetailMaterialSum(
@Param("linkNumber") String linkNumber,
@Param("linkStr") String linkStr,
@Param("linkType") String linkType,
@Param("type") String type);
Long getCountByMaterialAndBatchNumber(

View File

@@ -514,7 +514,7 @@ public class DepotHeadService {
BusinessConstants.SUB_TYPE_PURCHASE_ORDER.equals(depotHead.getSubType())) {
DepotHead dh = new DepotHead();
//获取分批操作后单据的商品和商品数量(汇总)
List<DepotItemVo4MaterialAndSum> batchList = depotItemMapperEx.getBatchBillDetailMaterialSum(depotHead.getLinkNumber(), depotHead.getType());
List<DepotItemVo4MaterialAndSum> batchList = depotItemMapperEx.getBatchBillDetailMaterialSum(depotHead.getLinkNumber(), "normal", depotHead.getType());
if(batchList.size()>0) {
dh.setPurchaseStatus(BusinessConstants.PURCHASE_STATUS_SKIPING);
} else {
@@ -1004,6 +1004,11 @@ public class DepotHeadService {
throw new BusinessRunTimeException(ExceptionConstants.DEPOT_HEAD_BILL_NUMBER_EXIST_CODE,
String.format(ExceptionConstants.DEPOT_HEAD_BILL_NUMBER_EXIST_MSG));
}
//校验是否同时录入关联请购单号和关联订单号
if(StringUtil.isNotEmpty(depotHead.getLinkNumber()) && StringUtil.isNotEmpty(depotHead.getLinkApply())) {
throw new BusinessRunTimeException(ExceptionConstants.DEPOT_ITEM_EXIST_REPEAT_NO_FAILED_CODE,
String.format(ExceptionConstants.DEPOT_ITEM_EXIST_REPEAT_NO_FAILED_MSG));
}
String subType = depotHead.getSubType();
//结算账户校验
if("采购".equals(subType) || "采购退货".equals(subType) || "销售".equals(subType) || "销售退货".equals(subType)) {
@@ -1100,7 +1105,12 @@ public class DepotHeadService {
throw new BusinessRunTimeException(ExceptionConstants.DEPOT_HEAD_BILL_NUMBER_EXIST_CODE,
String.format(ExceptionConstants.DEPOT_HEAD_BILL_NUMBER_EXIST_MSG));
}
//校验单据状态,如何不是未审核则提示
//校验是否同时录入关联请购单号和关联订单号
if(StringUtil.isNotEmpty(depotHead.getLinkNumber()) && StringUtil.isNotEmpty(depotHead.getLinkApply())) {
throw new BusinessRunTimeException(ExceptionConstants.DEPOT_ITEM_EXIST_REPEAT_NO_FAILED_CODE,
String.format(ExceptionConstants.DEPOT_ITEM_EXIST_REPEAT_NO_FAILED_MSG));
}
//校验单据状态,如果不是未审核则提示
if(!"0".equals(getDepotHead(depotHead.getId()).getStatus())) {
throw new BusinessRunTimeException(ExceptionConstants.DEPOT_HEAD_BILL_CANNOT_EDIT_CODE,
String.format(ExceptionConstants.DEPOT_HEAD_BILL_CANNOT_EDIT_MSG));

View File

@@ -691,15 +691,21 @@ public class DepotItemService {
|| BusinessConstants.SUB_TYPE_OTHER.equals(depotHead.getSubType())) {
if(StringUtil.isNotEmpty(depotHead.getLinkNumber())) {
//单据状态:是否全部完成 2-全部完成 3-部分完成(针对订单的分批出入库)
String billStatus = getBillStatusByParam(depotHead);
changeBillStatus(depotHead, billStatus);
String billStatus = getBillStatusByParam(depotHead, depotHead.getLinkNumber(), "normal");
changeBillStatus(depotHead.getLinkNumber(), billStatus);
}
}
//如果关联单据号非空则更新订单的状态,此处针对销售订单转采购订单的场景
//当前单据类型为采购订单的逻辑
if(BusinessConstants.SUB_TYPE_PURCHASE_ORDER.equals(depotHead.getSubType())) {
//如果关联单据号非空则更新订单的状态,此处针对销售订单转采购订单的场景
if(StringUtil.isNotEmpty(depotHead.getLinkNumber())) {
String billStatus = getBillStatusByParam(depotHead);
changeBillPurchaseStatus(depotHead, billStatus);
String billStatus = getBillStatusByParam(depotHead, depotHead.getLinkNumber(), "normal");
changeBillPurchaseStatus(depotHead.getLinkNumber(), billStatus);
}
//如果关联单据号非空则更新订单的状态,此处针对请购单转采购订单的场景
if(StringUtil.isNotEmpty(depotHead.getLinkApply())) {
String billStatus = getBillStatusByParam(depotHead, depotHead.getLinkApply(), "apply");
changeBillStatus(depotHead.getLinkApply(), billStatus);
}
}
} else {
@@ -711,15 +717,16 @@ public class DepotItemService {
* 判断单据的状态
* 通过数组对比:原单据的商品和商品数量(汇总) 与 分批操作后单据的商品和商品数量(汇总)
* @param depotHead
* @param linkStr
* @return
*/
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public String getBillStatusByParam(DepotHead depotHead) {
public String getBillStatusByParam(DepotHead depotHead, String linkStr, String linkType) {
String res = BusinessConstants.BILLS_STATUS_SKIPED;
//获取原单据的商品和商品数量(汇总)
List<DepotItemVo4MaterialAndSum> linkList = depotItemMapperEx.getLinkBillDetailMaterialSum(depotHead.getLinkNumber());
List<DepotItemVo4MaterialAndSum> linkList = depotItemMapperEx.getLinkBillDetailMaterialSum(linkStr);
//获取分批操作后单据的商品和商品数量(汇总)
List<DepotItemVo4MaterialAndSum> batchList = depotItemMapperEx.getBatchBillDetailMaterialSum(depotHead.getLinkNumber(), depotHead.getType());
List<DepotItemVo4MaterialAndSum> batchList = depotItemMapperEx.getBatchBillDetailMaterialSum(linkStr, linkType, depotHead.getType());
//将分批操作后的单据的商品和商品数据构造成Map
Map<Long, BigDecimal> materialSumMap = new HashMap<>();
for(DepotItemVo4MaterialAndSum materialAndSum : batchList) {
@@ -743,16 +750,16 @@ public class DepotItemService {
/**
* 更新单据状态
* @param depotHead
* @param linkStr
* @param billStatus
*/
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public void changeBillStatus(DepotHead depotHead, String billStatus) {
public void changeBillStatus(String linkStr, String billStatus) {
DepotHead depotHeadOrders = new DepotHead();
depotHeadOrders.setStatus(billStatus);
DepotHeadExample example = new DepotHeadExample();
List<String> linkNumberList = StringUtil.strToStringList(depotHead.getLinkNumber());
example.createCriteria().andNumberIn(linkNumberList);
List<String> linkNoList = StringUtil.strToStringList(linkStr);
example.createCriteria().andNumberIn(linkNoList);
try{
depotHeadMapper.updateByExampleSelective(depotHeadOrders, example);
}catch(Exception e){
@@ -765,16 +772,16 @@ public class DepotItemService {
/**
* 更新单据状态,此处针对销售订单转采购订单的场景
* @param depotHead
* @param linkStr
* @param billStatus
*/
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public void changeBillPurchaseStatus(DepotHead depotHead, String billStatus) {
public void changeBillPurchaseStatus(String linkStr, String billStatus) {
DepotHead depotHeadOrders = new DepotHead();
depotHeadOrders.setPurchaseStatus(billStatus);
DepotHeadExample example = new DepotHeadExample();
List<String> linkNumberList = StringUtil.strToStringList(depotHead.getLinkNumber());
example.createCriteria().andNumberIn(linkNumberList);
List<String> linkNoList = StringUtil.strToStringList(linkStr);
example.createCriteria().andNumberIn(linkNoList);
try{
depotHeadMapper.updateByExampleSelective(depotHeadOrders, example);
}catch(Exception e){
@@ -1085,7 +1092,7 @@ public class DepotItemService {
Long linkId = id;
String goToType = "";
DepotHead depotHead =depotHeadMapper.selectByPrimaryKey(headerId);
String linkNumber = depotHead.getNumber(); //订单号
String linkStr = depotHead.getNumber(); //订单号
if("purchase".equals(linkType)) {
//针对以销定购的情况
if(BusinessConstants.SUB_TYPE_SALES_ORDER.equals(depotHead.getSubType())) {
@@ -1117,7 +1124,11 @@ public class DepotItemService {
goToType = BusinessConstants.SUB_TYPE_SALES_RETURN;
}
}
BigDecimal count = depotItemMapperEx.getFinishNumber(meId, linkId, linkNumber, goToType);
String noType = "normal";
if(linkStr.contains("QGD")) {
noType = "apply";
}
BigDecimal count = depotItemMapperEx.getFinishNumber(meId, linkId, linkStr, noType, goToType);
//根据多单位情况进行数量的转换
if(materialUnit.equals(unitInfo.getOtherUnit()) && unitInfo.getRatio()!=null && unitInfo.getRatio().compareTo(BigDecimal.ZERO)!=0) {
count = count.divide(unitInfo.getRatio(),2,BigDecimal.ROUND_HALF_UP);
@@ -1146,8 +1157,12 @@ public class DepotItemService {
public BigDecimal getRealFinishNumber(String currentSubType, Long meId, Long linkId, Long preHeaderId, Long currentHeaderId, Unit unitInfo, String materialUnit) {
String goToType = currentSubType;
DepotHead depotHead =depotHeadMapper.selectByPrimaryKey(preHeaderId);
String linkNumber = depotHead.getNumber(); //订单号
BigDecimal count = depotItemMapperEx.getRealFinishNumber(meId, linkId, linkNumber, currentHeaderId, goToType);
String linkStr = depotHead.getNumber(); //订单号
String linkType = "normal";
if(linkStr.contains("QGD")) {
linkType = "apply";
}
BigDecimal count = depotItemMapperEx.getRealFinishNumber(meId, linkId, linkStr, linkType, currentHeaderId, goToType);
//根据多单位情况进行数量的转换
if(materialUnit.equals(unitInfo.getOtherUnit()) && unitInfo.getRatio()!=null && unitInfo.getRatio().compareTo(BigDecimal.ZERO)!=0) {
count = count.divide(unitInfo.getRatio(),2,BigDecimal.ROUND_HALF_UP);

View File

@@ -31,6 +31,7 @@
<result column="purchase_status" jdbcType="VARCHAR" property="purchaseStatus" />
<result column="source" jdbcType="VARCHAR" property="source" />
<result column="link_number" jdbcType="VARCHAR" property="linkNumber" />
<result column="link_apply" jdbcType="VARCHAR" property="linkApply" />
<result column="tenant_id" jdbcType="BIGINT" property="tenantId" />
<result column="delete_flag" jdbcType="VARCHAR" property="deleteFlag" />
</resultMap>
@@ -97,7 +98,7 @@
account_id, change_amount, back_amount, total_price, pay_type, bill_type, remark,
file_name, sales_man, account_id_list, account_money_list, discount, discount_money,
discount_last_money, other_money, deposit, status, purchase_status, source, link_number,
tenant_id, delete_flag
link_apply, tenant_id, delete_flag
</sql>
<select id="selectByExample" parameterType="com.jsh.erp.datasource.entities.DepotHeadExample" resultMap="BaseResultMap">
select
@@ -139,8 +140,8 @@
account_id_list, account_money_list, discount,
discount_money, discount_last_money, other_money,
deposit, status, purchase_status,
source, link_number, tenant_id,
delete_flag)
source, link_number, link_apply,
tenant_id, delete_flag)
values (#{id,jdbcType=BIGINT}, #{type,jdbcType=VARCHAR}, #{subType,jdbcType=VARCHAR},
#{defaultNumber,jdbcType=VARCHAR}, #{number,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP},
#{operTime,jdbcType=TIMESTAMP}, #{organId,jdbcType=BIGINT}, #{creator,jdbcType=BIGINT},
@@ -150,8 +151,8 @@
#{accountIdList,jdbcType=VARCHAR}, #{accountMoneyList,jdbcType=VARCHAR}, #{discount,jdbcType=DECIMAL},
#{discountMoney,jdbcType=DECIMAL}, #{discountLastMoney,jdbcType=DECIMAL}, #{otherMoney,jdbcType=DECIMAL},
#{deposit,jdbcType=DECIMAL}, #{status,jdbcType=VARCHAR}, #{purchaseStatus,jdbcType=VARCHAR},
#{source,jdbcType=VARCHAR}, #{linkNumber,jdbcType=VARCHAR}, #{tenantId,jdbcType=BIGINT},
#{deleteFlag,jdbcType=VARCHAR})
#{source,jdbcType=VARCHAR}, #{linkNumber,jdbcType=VARCHAR}, #{linkApply,jdbcType=VARCHAR},
#{tenantId,jdbcType=BIGINT}, #{deleteFlag,jdbcType=VARCHAR})
</insert>
<insert id="insertSelective" parameterType="com.jsh.erp.datasource.entities.DepotHead">
insert into jsh_depot_head
@@ -243,6 +244,9 @@
<if test="linkNumber != null">
link_number,
</if>
<if test="linkApply != null">
link_apply,
</if>
<if test="tenantId != null">
tenant_id,
</if>
@@ -338,6 +342,9 @@
<if test="linkNumber != null">
#{linkNumber,jdbcType=VARCHAR},
</if>
<if test="linkApply != null">
#{linkApply,jdbcType=VARCHAR},
</if>
<if test="tenantId != null">
#{tenantId,jdbcType=BIGINT},
</if>
@@ -442,6 +449,9 @@
<if test="record.linkNumber != null">
link_number = #{record.linkNumber,jdbcType=VARCHAR},
</if>
<if test="record.linkApply != null">
link_apply = #{record.linkApply,jdbcType=VARCHAR},
</if>
<if test="record.tenantId != null">
tenant_id = #{record.tenantId,jdbcType=BIGINT},
</if>
@@ -484,6 +494,7 @@
purchase_status = #{record.purchaseStatus,jdbcType=VARCHAR},
source = #{record.source,jdbcType=VARCHAR},
link_number = #{record.linkNumber,jdbcType=VARCHAR},
link_apply = #{record.linkApply,jdbcType=VARCHAR},
tenant_id = #{record.tenantId,jdbcType=BIGINT},
delete_flag = #{record.deleteFlag,jdbcType=VARCHAR}
<if test="_parameter != null">
@@ -577,6 +588,9 @@
<if test="linkNumber != null">
link_number = #{linkNumber,jdbcType=VARCHAR},
</if>
<if test="linkApply != null">
link_apply = #{linkApply,jdbcType=VARCHAR},
</if>
<if test="tenantId != null">
tenant_id = #{tenantId,jdbcType=BIGINT},
</if>
@@ -616,6 +630,7 @@
purchase_status = #{purchaseStatus,jdbcType=VARCHAR},
source = #{source,jdbcType=VARCHAR},
link_number = #{linkNumber,jdbcType=VARCHAR},
link_apply = #{linkApply,jdbcType=VARCHAR},
tenant_id = #{tenantId,jdbcType=BIGINT},
delete_flag = #{deleteFlag,jdbcType=VARCHAR}
where id = #{id,jdbcType=BIGINT}

View File

@@ -944,8 +944,13 @@
in
(
select dh.id from jsh_depot_head dh
where
dh.link_number=#{linkNumber}
where 1=1
<if test="noType == 'normal'">
and dh.link_number=#{linkStr}
</if>
<if test="noType == 'apply'">
and dh.link_apply=#{linkStr}
</if>
and ifnull(dh.delete_flag,'0') !='1'
<if test="goToType != null and goToType !=''">
and dh.sub_type=#{goToType}
@@ -963,8 +968,13 @@
(
select dh.id from jsh_depot_head dh
where
dh.link_number=#{linkNumber}
and dh.id!=#{currentHeaderId}
dh.id!=#{currentHeaderId}
<if test="linkType == 'normal'">
and dh.link_number=#{linkStr}
</if>
<if test="linkType == 'apply'">
and dh.link_apply=#{linkStr}
</if>
and ifnull(dh.delete_flag,'0') !='1'
<if test="goToType != null and goToType !=''">
and dh.sub_type=#{goToType}
@@ -1017,7 +1027,7 @@
<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}
where dh.number=#{linkStr}
and ifnull(dh.delete_flag,'0') !='1'
group by di.material_extend_id
</select>
@@ -1025,8 +1035,14 @@
<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'
where dh.type=#{type}
<if test="linkType == 'normal'">
and dh.link_number=#{linkStr}
</if>
<if test="linkType == 'apply'">
and dh.link_apply=#{linkStr}
</if>
and ifnull(dh.delete_flag,'0') !='1'
group by di.material_extend_id
</select>