demand: TMS-缅甸虚拟单调整

committer: heyu
This commit is contained in:
aike 2025-06-21 13:23:18 +08:00
parent c847446e44
commit 3c4dbf0311
10 changed files with 203 additions and 40 deletions

View File

@ -15,6 +15,7 @@ import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.xdadan.erp.emis.domain.exception.EmisBizError;
import com.xdadan.erp.emis.utils.WaybillHelper;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;

View File

@ -104,10 +104,11 @@ public interface EmisTransPlanRuleMapper {
* 根据产品类型名称查询产品类型信息
*
* @param productTypeNames 产品类型名称列表
* @param code 线路编码
* @param code 线路编码
* @return 产品类型信息列表
*/
public List<Map<String, String>> selectProductTypeInfoByNamesAndLineCode(@Param("productTypeNames") List<String> productTypeNames, @Param("lineCode") String code);
public List<Map<String, String>> selectProductTypeInfoByNamesAndLineCode(
@Param("productTypeNames") List<String> productTypeNames, @Param("lineCode") String code);
/**
* 根据网点名称查询网点信息
@ -139,4 +140,30 @@ public interface EmisTransPlanRuleMapper {
* @return
*/
List<EmisTransPlanRule> selectEmisTransPlanRuleByLineCodes(@Param("lineCodes") List<String> lineCodes);
/**
*
* @param emisTransPlanRule
* @return
*/
List<EmisTransPlanRule> selectRulesForAllScan(EmisTransPlanRule emisTransPlanRule);
/**
* 分页查询供应商线路规划(多线程用)
*
* @param emisTransPlanRule 查询条件
* @param offset 偏移量
* @param limit 每页数量
* @return 供应商线路规划集合
*/
List<EmisTransPlanRule> selectRulesForAllScanPaged(@Param("emisTransPlanRule") EmisTransPlanRule emisTransPlanRule,
@Param("offset") int offset, @Param("limit") int limit);
/**
* 查询总数(多线程分页用)
*
* @param emisTransPlanRule 查询条件
* @return 总数
*/
int countForAllScan(EmisTransPlanRule emisTransPlanRule);
}

View File

@ -4788,6 +4788,10 @@ public class EmisBaseService {
}
updateMasterWaybill(emisWaybillSave);
// 做问题件录入
scanProblemInfo(emisWaybillSave);
}
public void scanProblemInfo(EmisWaybill emisWaybillSave) {
String dispatchOrSendManCode = "";
if ("1".equals(emisWaybillSave.getPickupMethod())) {
dispatchOrSendManCode = emisWaybillSave.getOperateEmployeeCode();
@ -4816,7 +4820,7 @@ public class EmisBaseService {
emisTmsScanRecordService.scan(scanInfoProm, dispatchOrSendManCode, emisWaybillSave.getSendSiteCode());
}
private void updateMasterWaybill(EmisWaybill emisWaybillSave) throws EmisBizError {
public void updateMasterWaybill(EmisWaybill emisWaybillSave) throws EmisBizError {
EmisWaybill masterWaybill = checkVirtualParam(emisWaybillSave);
String virtualRemark = masterWaybill.getVirtualRemark();
String virtualBillCode = emisWaybillSave.getBillCode();
@ -4849,9 +4853,12 @@ public class EmisBaseService {
throw new EmisBizError(EmisBizErrorType.FAIL, "主单号不存在");
}
if (!emisWaybillSave.getReceiveCountry().equals(masterWaybill.getReceiveCountry())
|| !emisWaybillSave.getTransLineType().equals(masterWaybill.getTransLineType())) {
|| !emisWaybillSave.getTransLineType().equals(masterWaybill.getTransLineType()) || !emisWaybillSave.getProductType().equals(masterWaybill.getProductType())) {
throw new EmisBizError(EmisBizErrorType.FAIL, "主单和虚拟单线路不一致");
}
if ("1".equals(masterWaybill.getBlVirtual())) {
throw new EmisBizError(EmisBizErrorType.FAIL, "虚拟单不能作为主单");
}
List<EmisTmsSiteBatch> batchList = emisTmsSiteBatchMapper.selectEmisTmsSiteBatchListByBillCodes(
Lists.newArrayList(Collections.singleton(emisWaybillSave.getMasterBillCode())));

View File

@ -48,9 +48,6 @@ public class EmisTmsSiteBatchMissServiceImpl extends EmisBaseService implements
@Autowired
private EmisTmsSiteBatchMissRecordMapper emisTmsSiteBatchMissRecordMapper;
private int totalBatchStatusRecords = 0;
private int totalMissRecords = 0;
/**
* 查询TMS漏组批次信息
*
@ -142,6 +139,8 @@ public class EmisTmsSiteBatchMissServiceImpl extends EmisBaseService implements
int totalProcessed = 0;
int successCount = 0;
int failCount = 0;
int totalBatchStatusRecords = 0;
int totalMissRecords = 0;
List<String> failedBillCodes = new ArrayList<>();
// 获取所有线路规划
@ -162,7 +161,8 @@ public class EmisTmsSiteBatchMissServiceImpl extends EmisBaseService implements
// 先查询所有数据
while (true) {
List<EmisWaybill> waybills = emisWaybillMapper.selectWaybillListBySiteBatchStatus(offset, pageSize,lineCode);
List<EmisWaybill> waybills = emisWaybillMapper.selectWaybillListBySiteBatchStatus(offset, pageSize,
lineCode);
if (waybills.isEmpty()) {
break;
}
@ -192,6 +192,10 @@ public class EmisTmsSiteBatchMissServiceImpl extends EmisBaseService implements
batches.add(allWaybills.subList(i, end));
}
if (CollectionUtil.isEmpty(batches)) {
return;
}
// 创建新的线程池处理数据
executorService = Executors.newFixedThreadPool(processors);
List<Future<ProcessResult>> processFutures = new ArrayList<>();
@ -201,44 +205,52 @@ public class EmisTmsSiteBatchMissServiceImpl extends EmisBaseService implements
}
// 收集处理结果
List<EmisWaybillBatchStatus> allBatchStatus = new ArrayList<>();
List<EmisTmsSiteBatchMiss> allMissRecords = new ArrayList<>();
for (Future<ProcessResult> future : processFutures) {
try {
ProcessResult result = future.get();
successCount += result.getSuccessCount();
failCount += result.getFailCount();
failedBillCodes.addAll(result.getFailedBillCodes());
// 批量插入运单组批次状态记录
if (!result.getBatchStatusList().isEmpty()) {
emisWaybillBatchStatusMapper.batchInsertEmisWaybillBatchStatus(result.getBatchStatusList());
totalBatchStatusRecords += result.getBatchStatusList().size();
}
// 批量保存漏组记录
if (!result.getMissRecords().isEmpty()) {
List<EmisTmsSiteBatchMiss> filteredRecords = result.getMissRecords().stream()
.collect(Collectors.collectingAndThen(
Collectors.toMap(
record -> record.getBillCode() + "_" + record.getMissReason(),
record -> record,
(existing, replacement) -> existing),
map -> new ArrayList<>(map.values())));
emisTmsSiteBatchMissMapper.batchInsertEmisTmsSiteBatchMiss(filteredRecords);
totalMissRecords += filteredRecords.size();
}
allBatchStatus.addAll(result.getBatchStatusList());
allMissRecords.addAll(result.getMissRecords());
} catch (Exception e) {
log.error("Error processing batch", e);
}
}
// 关闭线程池
executorService.shutdown();
// 全局去重
Map<String, EmisWaybillBatchStatus> batchStatusMap = allBatchStatus.stream()
.collect(Collectors.toMap(
EmisWaybillBatchStatus::getBillCode,
v -> v,
(existing, replacement) -> existing));
List<EmisWaybillBatchStatus> uniqueBatchStatus = new ArrayList<>(batchStatusMap.values());
Map<String, EmisTmsSiteBatchMiss> missMap = allMissRecords.stream()
.collect(Collectors.toMap(
r -> r.getBillCode() + "_" + r.getMissReason(),
v -> v,
(existing, replacement) -> existing));
List<EmisTmsSiteBatchMiss> uniqueMissRecords = new ArrayList<>(missMap.values());
// 批量插入
if (!uniqueBatchStatus.isEmpty()) {
emisWaybillBatchStatusMapper.batchInsertEmisWaybillBatchStatus(uniqueBatchStatus);
totalBatchStatusRecords += uniqueBatchStatus.size();
}
if (!uniqueMissRecords.isEmpty()) {
emisTmsSiteBatchMissMapper.batchInsertEmisTmsSiteBatchMiss(uniqueMissRecords);
totalMissRecords += uniqueMissRecords.size();
}
long endTime = System.currentTimeMillis();
long processTime = endTime - startTime;
// 保存扫描记录
saveRecord(totalProcessed, successCount, failCount, processTime, failedBillCodes);
saveRecord(totalProcessed, successCount, failCount, processTime, failedBillCodes, totalBatchStatusRecords,
totalMissRecords);
log.info(
"Auto scan completed. Total processed: {}, Success: {}, Failed: {}, Time taken: {}ms, Batch status records: {}, Miss records: {}",
@ -253,7 +265,7 @@ public class EmisTmsSiteBatchMissServiceImpl extends EmisBaseService implements
}
private void saveRecord(int totalProcessed, int successCount, int failCount, long processTime,
List<String> failedBillCodes) {
List<String> failedBillCodes, int totalBatchStatusRecords, int totalMissRecords) {
EmisTmsSiteBatchMissRecord record = new EmisTmsSiteBatchMissRecord();
record.setTotalProcessed(totalProcessed);
record.setSuccessCount(successCount);
@ -385,6 +397,10 @@ public class EmisTmsSiteBatchMissServiceImpl extends EmisBaseService implements
// 合并相同起始网点和下一网点的批次
Map<String, EmisTmsSiteBatch> mergedBatches = new HashMap<>();
for (EmisTmsSiteBatch batch : waybillBatches) {
if (StringUtils.isAnyBlank(batch.getStartSiteCode(), batch.getNextSiteCode(),
batch.getSupplierCode())) {
continue;
}
String key = batch.getStartSiteCode() + "_" + batch.getNextSiteCode();
if (mergedBatches.containsKey(key)) {
EmisTmsSiteBatch existingBatch = mergedBatches.get(key);
@ -426,11 +442,33 @@ public class EmisTmsSiteBatchMissServiceImpl extends EmisBaseService implements
}
public List<EmisTransPlanRule> selectEmisTransPlanRuleTree(String lineCode) {
log.info("Start querying supplier route plan tree");
log.info("Start querying supplier route plan tree (multi-threaded)");
EmisTransPlanRule emisTransPlanRule = new EmisTransPlanRule();
emisTransPlanRule.setLineCode(lineCode);
List<EmisTransPlanRule> list = emisTransPlanRuleMapper.selectEmisTransPlanRuleList(emisTransPlanRule);
List<EmisTransPlanRule> tree = buildTree(list);
int pageSize = 100;
int total = emisTransPlanRuleMapper.countForAllScan(emisTransPlanRule);
int pageCount = (total + pageSize - 1) / pageSize;
int processors = Runtime.getRuntime().availableProcessors();
ExecutorService executor = Executors.newFixedThreadPool(processors);
List<Future<List<EmisTransPlanRule>>> futures = new ArrayList<>();
for (int i = 0; i < pageCount; i++) {
int offset = i * pageSize;
futures.add(executor.submit(
() -> emisTransPlanRuleMapper.selectRulesForAllScanPaged(emisTransPlanRule, offset, pageSize)));
}
List<EmisTransPlanRule> allRules = new ArrayList<>();
for (Future<List<EmisTransPlanRule>> future : futures) {
try {
List<EmisTransPlanRule> rules = future.get();
if (rules != null) {
allRules.addAll(rules);
}
} catch (Exception e) {
log.error("Error getting trans plan rule results", e);
}
}
executor.shutdown();
List<EmisTransPlanRule> tree = buildTree(allRules);
log.info("Queried supplier route plan tree, node count={}", tree != null ? tree.size() : 0);
return tree;
}
@ -518,7 +556,7 @@ public class EmisTmsSiteBatchMissServiceImpl extends EmisBaseService implements
}
private boolean checkRule(EmisTransPlanRule rule, List<EmisTmsSiteBatch> waybillBatches,
List<EmisTransPlanRule> list) {
List<EmisTransPlanRule> list) {
// 检查当前节点是否匹配
boolean currentMatch = false;
for (EmisTmsSiteBatch batch : waybillBatches) {
@ -617,7 +655,7 @@ public class EmisTmsSiteBatchMissServiceImpl extends EmisBaseService implements
* 递归检查下一级节点
*/
private boolean checkNextLevel(Set<EmisTransPlanRule> currentLevelRules,
List<EmisTmsSiteBatch> waybillBatches, List<EmisTransPlanRule> list) {
List<EmisTmsSiteBatch> waybillBatches, List<EmisTransPlanRule> list) {
// 如果当前级为空,说明已经到底了,返回true
if (currentLevelRules.isEmpty()) {
return true;
@ -708,7 +746,8 @@ public class EmisTmsSiteBatchMissServiceImpl extends EmisBaseService implements
.anyMatch(
filterRule -> filterRule.getStartSiteCode().equals(childRule.getStartSiteCode()) &&
filterRule.getNextSiteCode().equals(childRule.getNextSiteCode()) &&
compareSupplierCodes(filterRule.getSupplierCode(), childRule.getSupplierCode())));
compareSupplierCodes(filterRule.getSupplierCode(),
childRule.getSupplierCode())));
if (!hasMatchedChild) {
// 如果所有子节点都不匹配,为每个子节点创建漏组记录

View File

@ -140,6 +140,9 @@ public class EmisWaybillAjustApplyServiceImpl extends EmisBaseService implements
checkUseQuotaCredit(emisWaybillOld, getEmisWaybillNewFromJson(emisWaybillAjustApply));
}
// 校验虚拟单逻辑
checkVirtualParam(getEmisWaybillNewFromJson(emisWaybillAjustApply));
// 插入数据
emisWaybillAjustApplyMapper.insertEmisWaybillAjustApply(emisWaybillAjustApply);

View File

@ -3116,6 +3116,11 @@ public class EmisWaybillServiceImpl extends EmisBaseService implements IEmisWayb
// 检查信用额度
checkUseQuotaCredit(null,emisWaybillSave);
// 虚拟件逻辑
if ("1".equals(emisWaybillSave.getBlVirtual())) {
updateMasterWaybill(emisWaybillSave);
}
//插入新单
emisWaybillMapper.insertEmisWaybill(emisWaybillSave);
@ -3220,7 +3225,7 @@ public class EmisWaybillServiceImpl extends EmisBaseService implements IEmisWayb
}
// 处理虚拟件逻辑
handleVirtual(emisWaybillSave);
scanProblemInfo(emisWaybillSave);
// 运单立即重新出账
try {

View File

@ -191,5 +191,6 @@
left join emis_tms_site_batch_dtl b on a.bill_code = b.bill_code and b.del_flag = '0'
where b.batch_no = #{batchNo}
and a.del_flag = '0'
and a.send_date <![CDATA[ > ]]> '2025-01-01 00:00:00'
</select>
</mapper>

View File

@ -154,7 +154,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</choose>
</if>
<if test="billCode != null and billCode != ''">
AND m.bill_code = #{billCode}
AND m.bill_code REGEXP REPLACE(#{billCode}, '\n', '|')
</if>
<if test="missReason != null and missReason != ''">
AND m.miss_reason like concat('%', #{missReason}, '%')

View File

@ -61,8 +61,46 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
order by id desc
</select>
<select id="selectRulesForAllScan" parameterType="EmisTransPlanRule" resultMap="EmisTransPlanRuleResult">
select r.id, r.line_code, r.product_type, r.start_site_code,r.next_site_code, s1.site_name as start_site_name,
s2.site_name as next_site_name,
r.manager, r.supplier_code, r.start_date, r.end_date, (SELECT GROUP_CONCAT(s.name)
FROM emis_supplier s
WHERE FIND_IN_SET(s.code, r.supplier_code)
AND s.del_flag = '0') as supplier_name
from emis_trans_plan_rule r
left join emis_site s1 on r.start_site_code = s1.site_code and s1.del_flag='0'
left join emis_site s2 on r.next_site_code = s2.site_code and s2.del_flag='0'
<where>
r.del_flag = '0'
<if test="lineCode != null and lineCode != ''">and r.line_code = #{lineCode}</if>
<if test="productType != null and productType != ''">and ( FIND_IN_SET(#{productType},r.product_type) )
</if>
<if test="startSiteCode != null and startSiteCode != ''">and r.start_site_code = #{startSiteCode}</if>
<if test="nextSiteCode != null and nextSiteCode != ''">and r.next_site_code = #{nextSiteCode}</if>
<if test="manager != null and manager != ''">and r.manager = #{manager}</if>
<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>
<if test="transManager != null and transManager != ''">
AND l.trans_manager like concat('%', #{transManager}, '%')
</if>
</where>
order by id desc
</select>
<select id="selectEmisTransPlanRuleByLineCodes" parameterType="list" resultMap="EmisTransPlanRuleResult">
<include refid="selectEmisTransPlanRuleVo"/>
select r.id, r.line_code, r.product_type, r.start_site_code,r.next_site_code, s1.site_name as start_site_name,
s2.site_name as next_site_name,
r.manager, r.supplier_code, r.start_date, r.end_date, (SELECT GROUP_CONCAT(s.name)
FROM emis_supplier s
WHERE FIND_IN_SET(s.code, r.supplier_code)
AND s.del_flag = '0') as supplier_name
from emis_trans_plan_rule r
left join emis_site s1 on r.start_site_code = s1.site_code and s1.del_flag='0'
left join emis_site s2 on r.next_site_code = s2.site_code and s2.del_flag='0'
<where>
r.del_flag = '0'
AND r.line_code in
@ -242,4 +280,45 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
AND del_flag = '0'
</select>
<select id="selectRulesForAllScanPaged" resultMap="EmisTransPlanRuleResult">
select r.id, r.line_code, r.product_type, r.start_site_code, r.next_site_code, s1.site_name as start_site_name,
s2.site_name as next_site_name,
r.manager, r.supplier_code, r.start_date, r.end_date, (SELECT GROUP_CONCAT(s.name)
FROM emis_supplier s
WHERE FIND_IN_SET(s.code, r.supplier_code)
AND s.del_flag = '0') as supplier_name
from emis_trans_plan_rule r
left join emis_site s1 on r.start_site_code = s1.site_code and s1.del_flag='0'
left join emis_site s2 on r.next_site_code = s2.site_code and s2.del_flag='0'
<where>
r.del_flag = '0'
<if test="emisTransPlanRule.lineCode != null and emisTransPlanRule.lineCode != ''">and r.line_code = #{emisTransPlanRule.lineCode}</if>
<if test="emisTransPlanRule.productType != null and emisTransPlanRule.productType != ''">and ( FIND_IN_SET(#{emisTransPlanRule.productType},r.product_type) )</if>
<if test="emisTransPlanRule.startSiteCode != null and emisTransPlanRule.startSiteCode != ''">and r.start_site_code = #{emisTransPlanRule.startSiteCode}</if>
<if test="emisTransPlanRule.nextSiteCode != null and emisTransPlanRule.nextSiteCode != ''">and r.next_site_code = #{emisTransPlanRule.nextSiteCode}</if>
<if test="emisTransPlanRule.manager != null and emisTransPlanRule.manager != ''">and r.manager = #{emisTransPlanRule.manager}</if>
<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>
</where>
order by id desc
limit #{limit} offset #{offset}
</select>
<select id="countForAllScan" resultType="int">
select count(1)
from emis_trans_plan_rule r
<where>
r.del_flag = '0'
<if test="lineCode != null and lineCode != ''">and r.line_code = #{lineCode}</if>
<if test="productType != null and productType != ''">and ( FIND_IN_SET(#{productType},r.product_type) )</if>
<if test="startSiteCode != null and startSiteCode != ''">and r.start_site_code = #{startSiteCode}</if>
<if test="nextSiteCode != null and nextSiteCode != ''">and r.next_site_code = #{nextSiteCode}</if>
<if test="manager != null and manager != ''">and r.manager = #{manager}</if>
<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>
</where>
</select>
</mapper>

View File

@ -3763,6 +3763,7 @@
<if test="lineCode != null and lineCode != ''">
and a.trans_line_type = #{lineCode}
</if>
and a.send_date <![CDATA[ > ]]> '2025-01-01 00:00:00'
and (a.virtual_remark is null or virtual_remark = '')
order by a.create_time desc
limit #{offset}, #{pageSize}