Merge pull request 'demand: 组树添加南京分拨中心、柯桥分拨中心' (#86) from develop into master

Reviewed-on: http://git.xdadan.loc/tanex/emis-service/pulls/86
This commit is contained in:
heyu 2025-07-02 19:53:34 +08:00
commit e3c2fe6a92
4 changed files with 123 additions and 69 deletions

View File

@ -4030,7 +4030,8 @@ public class EmisBaseService {
for (EmisTransPlanRule rule : lineRules) {
if (rule.getProductType() != null) {
String[] types = rule.getProductType().split(",");
String[] typeNames = rule.getProductTypeName() != null ? rule.getProductTypeName().split(",") : new String[0];
String[] typeNames = rule.getProductTypeName() != null ? rule.getProductTypeName().split(",")
: new String[0];
for (int i = 0; i < types.length; i++) {
String type = types[i].trim();
if (!type.isEmpty()) {
@ -4069,7 +4070,8 @@ public class EmisBaseService {
Map<String, List<EmisTransPlanRule>> tempMap = new HashMap<>();
if (StringUtil.isNotBlank(emisTransPlanRule.getProductType())) {
Iterator<Map.Entry<String, List<EmisTransPlanRule>>> iterator = groupByProductType.entrySet().iterator();
Iterator<Map.Entry<String, List<EmisTransPlanRule>>> iterator = groupByProductType.entrySet()
.iterator();
while (iterator.hasNext()) {
Map.Entry<String, List<EmisTransPlanRule>> entry = iterator.next();
if (emisTransPlanRule.getProductType().equals(entry.getKey())) {
@ -4116,7 +4118,9 @@ public class EmisBaseService {
String siteCode1 = child.getStartSiteCode() + "," + child.getNextSiteCode();
String siteCode2 = parent.getStartSiteCode() + "," + parent.getNextSiteCode();
if (!parent.getChildren().contains(child) && !compareSiteCodes(siteCode1, siteCode2)) {
parent.getChildren().add(child);
if (!wouldFormCycle(parent, child)) {
parent.getChildren().add(child);
}
}
}
}
@ -4196,64 +4200,64 @@ public class EmisBaseService {
}
}
/**
* 深度复制节点及其子节点
*
* @param source 源节点
* @return 复制后的新节点
*/
private EmisTransPlanRule deepCopyNode(EmisTransPlanRule source) {
return deepCopyNode(source, new HashSet<>(), new ArrayList<>());
}
/**
* 深度复制节点及其子节点
*
* @param source 源节点
* @return 复制后的新节点
*/
private EmisTransPlanRule deepCopyNode(EmisTransPlanRule source) {
return deepCopyNode(source, new HashSet<>(), new ArrayList<>());
}
/**
* 深度复制节点及其子节点(带循环引用检测)
*
* @param source 源节点
* @param visitedIds 已访问的节点ID集合
* @param visitPath 访问路径,用于记录循环引用的路径
* @return 复制后的新节点
*/
private EmisTransPlanRule deepCopyNode(EmisTransPlanRule source, Set<Long> visitedIds, List<Long> visitPath) {
if (source == null) {
return null;
}
/**
* 深度复制节点及其子节点(带循环引用检测)
*
* @param source 源节点
* @param visitedIds 已访问的节点ID集合
* @param visitPath 访问路径,用于记录循环引用的路径
* @return 复制后的新节点
*/
private EmisTransPlanRule deepCopyNode(EmisTransPlanRule source, Set<Long> visitedIds, List<Long> visitPath) {
if (source == null) {
return null;
}
// 检查循环引用
if (visitedIds.contains(source.getId())) {
// 找到循环引用的起始位置
int cycleStartIndex = visitPath.indexOf(source.getId());
if (cycleStartIndex != -1) {
// 构建循环路径
List<Long> cyclePath = visitPath.subList(cycleStartIndex, visitPath.size());
cyclePath.add(source.getId());
// 检查循环引用
if (visitedIds.contains(source.getId())) {
// 找到循环引用的起始位置
int cycleStartIndex = visitPath.indexOf(source.getId());
if (cycleStartIndex != -1) {
// 构建循环路径
List<Long> cyclePath = visitPath.subList(cycleStartIndex, visitPath.size());
cyclePath.add(source.getId());
// 构建详细的错误信息
StringBuilder errorMsg = new StringBuilder();
errorMsg.append("检测到循环引用!循环路径:");
for (int i = 0; i < cyclePath.size(); i++) {
if (i > 0) {
errorMsg.append(" -> ");
}
Long id = cyclePath.get(i);
if (id == null) {
continue;
}
EmisTransPlanRule node = findNodeById(id);
if (node != null) {
errorMsg.append(node.getLineName()).append("-")
.append(node.getProductTypeName()).append("-")
.append(node.getStartSiteName()).append("-")
.append(node.getNextSiteName()).append("-")
.append(node.getSupplierName());
} else {
errorMsg.append("节点ID:").append(id);
}
}
// errorMsg.append("\n循环引用发生在节点,详细信息见上");
throw new RuntimeException(errorMsg.toString());
}
}
StringBuilder errorMsg = new StringBuilder();
errorMsg.append("检测到循环引用!循环路径:");
for (int i = 0; i < cyclePath.size(); i++) {
if (i > 0) {
errorMsg.append(" -> ");
}
Long id = cyclePath.get(i);
if (id == null) {
continue;
}
EmisTransPlanRule node = findNodeById(id);
if (node != null) {
errorMsg.append(node.getLineName()).append("-")
.append(node.getProductTypeName()).append("-")
.append(node.getStartSiteName()).append("-")
.append(node.getNextSiteName()).append("-")
.append(node.getSupplierName());
} else {
errorMsg.append("节点ID:").append(id);
}
}
// errorMsg.append("\n循环引用发生在节点,详细信息见上");
throw new RuntimeException(errorMsg.toString());
}
}
// 添加到已访问集合和路径中
visitedIds.add(source.getId());
@ -4285,6 +4289,22 @@ public class EmisBaseService {
return emisTransPlanRuleMapper.selectEmisTransPlanRuleById(id);
}
/**
* 判断添加child到parent后是否会形成环
*/
private boolean wouldFormCycle(EmisTransPlanRule parent, EmisTransPlanRule child) {
if (child == null)
return false;
if (child.getId() != null && parent.getId() != null && child.getId().equals(parent.getId()))
return true;
if (child.getChildren() == null || child.getChildren().isEmpty())
return false;
for (EmisTransPlanRule c : child.getChildren()) {
if (wouldFormCycle(parent, c))
return true;
}
return false;
}
/**
* 检查月结客户首次签约日期,首次签约之前开的不允许修改
*
@ -4849,6 +4869,9 @@ public class EmisBaseService {
if (currentLevelMatch) {
hasCurrentLevelMatch = true;
if (CollectionUtil.isEmpty(currentLevelRule.getChildren())) {
return true;
}
}
// 收集当前级节点的所有子节点到下一级集合中
@ -4943,6 +4966,13 @@ public class EmisBaseService {
Objects.equals(filterRule.getNextSiteCode(), levelRule.getNextSiteCode()) &&
compareSupplierCodes(filterRule.getSupplierCode(), levelRule.getSupplierCode())));
if (!matched && !group.isEmpty()) {
// if (CollectionUtil.isNotEmpty(missRecords)) {
// List<EmisTmsSiteBatchMiss> list = missRecords.stream().filter(i -> waybill.getBillCode().equals(i.getBillCode())).collect(Collectors.toList());
// if (CollectionUtil.isNotEmpty(list) && list.size() > 10) {
// break;
// }
// }
// 聚合supplierCode、supplierName等
String supplierCodes = group.stream().map(EmisTransPlanRule::getSupplierCode)
.filter(Objects::nonNull).distinct().collect(Collectors.joining(","));
@ -5026,7 +5056,11 @@ public class EmisBaseService {
}
public void scanProblemInfo(EmisWaybill emisWaybillSave, EmisWaybill emisWaybillOld) {
if ("078".equals(emisWaybillSave.getTransLineType())) {
Set<String> allowedTypes = new HashSet<>();
allowedTypes.add("078");
allowedTypes.add("012");
allowedTypes.add("014");
if (allowedTypes.contains(emisWaybillSave.getTransLineType())) {
return;
}
String dispatchOrSendManCode = "";
@ -5119,7 +5153,7 @@ public class EmisBaseService {
long count = Arrays.stream(virtualRemark.split(","))
.filter(s -> s != null && !s.trim().isEmpty())
.count();
if (count >= masterWaybill.getParcelQty()) {
if (("078".equals(emisWaybillSave.getTransLineType()) || "002".equals(emisWaybillSave.getTransLineType())) && count >= masterWaybill.getParcelQty()) {
throw new EmisBizError(EmisBizErrorType.FAIL,
emisWaybillSave.getMasterBillCode() + "最多只能绑定" + masterWaybill.getParcelQty() + "个虚拟单");
}
@ -5139,12 +5173,16 @@ public class EmisBaseService {
} else {
String masterBillCode = emisWaybillOld.getMasterBillCode();
if (StringUtil.isNotBlank(masterBillCode)) {
emisWaybillSave.setMasterBillCode(" ");
String virtualBillCode = emisWaybillSave.getBillCode();
EmisWaybill masterWaybill = emisWaybillMapper
.selectEmisWaybillByBillCode(masterBillCode);
List<String> filterVirtualRemark = Arrays.stream(masterWaybill.getVirtualRemark().split(","))
.filter(i -> !i.equals(virtualBillCode)).collect(Collectors.toList());
String virtualRemark = String.join(",", filterVirtualRemark);
if(StringUtil.isBlank(virtualRemark)) {
virtualRemark = " ";
}
masterWaybill.setVirtualRemark(virtualRemark);
emisWaybillMapper.updateEmisWaybill(masterWaybill);
if (!"078".equals(emisWaybillSave.getTransLineType())) {

View File

@ -47,6 +47,23 @@
<association property="nextSiteName" column="next_site_code" select="com.xdadan.erp.emis.mapper.EmisBaseMapper.selectSiteNameByCode"/>
</resultMap>
<resultMap type="EmisTmsSiteBatch" id="EmisTransPlanRuleSimpleResult">
<result property="id" column="id"/>
<result property="lineCode" column="line_code"/>
<result property="productType" column="product_type"/>
<result property="startSiteCode" column="start_site_code"/>
<result property="nextSiteCode" column="next_site_code"/>
<result property="manager" column="manager"/>
<result property="supplierCode" column="supplier_code"/>
<result property="startDate" column="start_date"/>
<result property="endDate" column="end_date"/>
<result property="etd" column="etd" />
<collection property="batchDtlList" ofType="com.xdadan.erp.emis.domain.EmisTmsSiteBatchDtl">
<result property="billCode" column="bill_code"/>
</collection>
</resultMap>
<resultMap type="EmisTmsSiteBatch" id="EmisTmsSiteBatchDtlResult" extends="EmisTmsSiteBatchResult">
<result property="id" column="id" />
<result property="batchNo" column="batch_no" />
@ -493,8 +510,8 @@
</delete>
<!-- 根据运单号列表查询组批次信息 -->
<select id="selectEmisTmsSiteBatchListByBillCodes" resultMap="EmisTmsSiteBatchDtlResult">
select distinct b.id, b.batch_no, b.supplier_code, b.trans_line_type, b.product_type, b.trans_type, b.start_site_code, b.next_site_code, b.etd
<select id="selectEmisTmsSiteBatchListByBillCodes" resultMap="EmisTransPlanRuleSimpleResult">
select distinct b.id, b.batch_no, b.supplier_code, b.trans_line_type, b.product_type, b.trans_type, b.start_site_code, b.next_site_code, b.etd, d.bill_code
from emis_tms_site_batch b
inner join emis_tms_site_batch_dtl d on b.batch_no = d.batch_no
where d.bill_code in

View File

@ -385,7 +385,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="emisTransPlanRule.supplierCode != null and emisTransPlanRule.supplierCode != ''">and ( FIND_IN_SET(#{emisTransPlanRule.supplierCode},r.supplier_code) )</if>
<if test="emisTransPlanRule.startDate != null">and r.start_date = #{emisTransPlanRule.startDate}</if>
<if test="emisTransPlanRule.endDate != null">and r.end_date = #{emisTransPlanRule.endDate}</if>
and r.line_code not in ('014','012','077')
-- and r.line_code not in ('014','012','077')
</where>
order by id desc
limit #{offset}, #{pageSize}
@ -404,7 +404,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="supplierCode != null and supplierCode != ''">and ( FIND_IN_SET(#{supplierCode},r.supplier_code) )</if>
<if test="startDate != null">and r.start_date = #{startDate}</if>
<if test="endDate != null">and r.end_date = #{endDate}</if>
and r.line_code not in ('014','012','077')
-- and r.line_code not in ('014','012','077')
</where>
</select>

View File

@ -3201,8 +3201,8 @@
<if test="blSensitive != null and blSensitive != ''">bl_sensitive = #{blSensitive},</if>
<if test="blOverLong != null and blOverLong != ''">bl_over_long = #{blOverLong},</if>
<if test="blVirtual != null and blVirtual != ''">bl_virtual = #{blVirtual},</if>
master_bill_code= #{masterBillCode},
virtual_remark= #{virtualRemark},
<if test="masterBillCode != null and masterBillCode != ''">master_bill_code= #{masterBillCode},</if>
<if test="virtualRemark != null and virtualRemark != ''">virtual_remark= #{virtualRemark},</if>
<if test="blBill != null and blBill != ''">bl_bill = #{blBill},</if>
<if test="blBillText != null and blBillText != ''">bl_bill_text = #{blBillText},</if>
<if test="blProfit != null and blProfit != ''">bl_profit = #{blProfit},</if>
@ -3390,8 +3390,8 @@
<if test="blSensitive != null and blSensitive != ''">bl_sensitive = #{blSensitive},</if>
<if test="blOverLong != null and blOverLong != ''">bl_over_long = #{blOverLong},</if>
<if test="blVirtual != null and blVirtual != ''">bl_virtual = #{blVirtual},</if>
master_bill_code= #{masterBillCode},
virtual_remark= #{virtualRemark},
<if test="masterBillCode != null and masterBillCode != ''">master_bill_code= #{masterBillCode},</if>
<if test="virtualRemark != null and virtualRemark != ''">virtual_remark= #{virtualRemark},</if>
<if test="blBill != null and blBill != ''">bl_bill = #{blBill},</if>
<if test="blBillText != null and blBillText != ''">bl_bill_text = #{blBillText},</if>
<if test="blProfit != null and blProfit != ''">bl_profit = #{blProfit},</if>
@ -3825,8 +3825,7 @@
from emis_waybill a
where a.del_flag = '0' and
a.problem_type in (173,170)
and (master_bill_code is null or master_bill_code='')
-- and a.bill_code ='T708030039025903'
and (master_bill_code is null or master_bill_code='' or master_bill_code=' ')
order by a.create_time desc
limit #{offset}, #{pageSize}
</select>