完善关联请购单中的数量计算逻辑
This commit is contained in:
@@ -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 = "抱歉,关联请购单号和关联订单号不能同时录入";
|
||||
|
||||
/**
|
||||
* 单据明细信息
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user