diff --git a/emis-biz-web/src/main/java/com/xdadan/erp/web/emis/EmisCommonController.java b/emis-biz-web/src/main/java/com/xdadan/erp/web/emis/EmisCommonController.java index 07072f950..3931021f1 100644 --- a/emis-biz-web/src/main/java/com/xdadan/erp/web/emis/EmisCommonController.java +++ b/emis-biz-web/src/main/java/com/xdadan/erp/web/emis/EmisCommonController.java @@ -966,46 +966,11 @@ public class EmisCommonController extends EmisBaseController // 这样即使异步任务没有正确清除状态,也会在30分钟后自动过期 redissonService.setStr(statusKey, "RUNNING", 1800); - // 如果lineCode为空,查询所有线路的lineCode,去重后循环调用 - if (StringUtils.isEmpty(lineCode)) { - log.info("lineCode is empty, querying all line codes"); - emisTmsSiteBatchMissMapper.deleteReally(lineCode); - EmisTransLine queryLine = new EmisTransLine(); -// queryLine.setStatus(1); // 只查询启用的线路 - List lineList = emisTransLineService.selectEmisTransLineList(queryLine); + // 异步执行任务 + emisTmsSiteBatchMissService.autoScanSiteBatch(lineCode); + log.info("autoScanSiteBatch async task started"); - // 提取lineCode并去重 - Set lineCodeSet = new LinkedHashSet<>(); - if (!CollectionUtils.isEmpty(lineList)) { - for (EmisTransLine line : lineList) { - if (StringUtils.isNotEmpty(line.getLineCode())) { - lineCodeSet.add(line.getLineCode()); - } - } - } - - log.info("Found {} unique line codes, starting batch processing", lineCodeSet.size()); - - // 循环调用 - for (String code : lineCodeSet) { - try { - emisTmsSiteBatchMissService.autoScanSiteBatch(code); - log.info("autoScanSiteBatch processed for lineCode: {}", code); - } catch (Exception e) { - log.error("autoScanSiteBatch failed for lineCode: {}, error: {}", code, e.getMessage()); - // 继续处理下一个,不中断整个流程 - } - } - - log.info("autoScanSiteBatch async task started for all line codes"); - return AjaxResult.success("异步任务已启动,共处理 " + lineCodeSet.size() + " 个线路,请稍后查看执行结果"); - } else { - emisTmsSiteBatchMissMapper.deleteReally(lineCode); - // 异步执行任务 - emisTmsSiteBatchMissService.autoScanSiteBatch(lineCode); - log.info("autoScanSiteBatch async task started for lineCode: {}", lineCode); - return AjaxResult.success("异步任务已启动,请稍后查看执行结果"); - } + return AjaxResult.success("异步任务已启动,请稍后查看执行结果"); } catch (Exception ex) { ex.printStackTrace(); diff --git a/emis-biz-web/src/main/java/com/xdadan/erp/web/emis/EmisTmsSiteBatchMissController.java b/emis-biz-web/src/main/java/com/xdadan/erp/web/emis/EmisTmsSiteBatchMissController.java index 11baca6d4..59252a96c 100644 --- a/emis-biz-web/src/main/java/com/xdadan/erp/web/emis/EmisTmsSiteBatchMissController.java +++ b/emis-biz-web/src/main/java/com/xdadan/erp/web/emis/EmisTmsSiteBatchMissController.java @@ -1,8 +1,13 @@ package com.xdadan.erp.web.emis; +import java.util.Arrays; +import java.util.HashSet; import java.util.List; +import java.util.Set; +import com.xdadan.erp.common.core.redis.RedissonService; import com.xdadan.erp.emis.domain.exception.EmisBizError; +import lombok.extern.slf4j.Slf4j; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; @@ -26,6 +31,7 @@ import com.xdadan.erp.common.core.page.TableDataInfo; * * @author heyu */ +@Slf4j @RestController @RequestMapping("/emis/emisTmsSiteBatchMiss") public class EmisTmsSiteBatchMissController extends EmisBaseController { @@ -33,6 +39,9 @@ public class EmisTmsSiteBatchMissController extends EmisBaseController { @Autowired private IEmisTmsSiteBatchMissService emisTmsSiteBatchMissService; + @Autowired + RedissonService redissonService; + /** * 查询TMS漏组批次信息列表 */ @@ -282,4 +291,50 @@ public class EmisTmsSiteBatchMissController extends EmisBaseController { emisTmsSiteBatchMissService.cancelConfirmBatchV2(billCodes); return AjaxResult.success("取消确认成功"); } + + /** + * 一键重算-V2 + * + * @return + */ + @GetMapping("/autoScanSiteBatchV2") + @PreAuthorize("@ss.hasPermi('emis:emisTmsSiteBatchMiss:autoScanSiteBatchV2')") + public AjaxResult autoScanSiteBatchV2(String lineCode) { + // 检查员工代码权限 + String empCode = getLoginUser().getUser().getEmpCode(); + Set allowedEmpCodes = new HashSet<>(Arrays.asList("88888059", "88888083", "88888102", "88888112")); + if (empCode == null || !allowedEmpCodes.contains(empCode)) { + log.warn("autoScanSiteBatchV2 access denied for empCode: {}", empCode); + return AjaxResult.error("您未被授权,如确有需要,请联系IT处理"); + } + + String statusKey = "autoScanSiteBatchV2_status"; + log.info("autoScanSiteBatchV2 start"); + + // 检查任务是否正在执行 + String currentStatus = redissonService.getStr(statusKey); + if ("RUNNING".equals(currentStatus)) { + log.warn("autoScanSiteBatchV2 is already running, request rejected"); + return AjaxResult.error("任务正在执行中,请稍后再试"); + } + + try { + // 设置任务状态为运行中,设置较长的过期时间(30分钟) + // 这样即使异步任务没有正确清除状态,也会在30分钟后自动过期 + redissonService.setStr(statusKey, "RUNNING", 1800); + + // 异步执行任务 + emisTmsSiteBatchMissService.autoScanSiteBatchV2(lineCode); + log.info("autoScanSiteBatchV2 async task started"); + + return AjaxResult.success("异步任务已启动,请稍后查看执行结果"); + + } catch (Exception ex) { + ex.printStackTrace(); + log.error("autoScanSiteBatchV2 exception:" + ex.getMessage()); + // 如果启动失败,清除状态 + redissonService.setStr(statusKey, "", 0); + return AjaxResult.error("任务启动失败:" + ex.getMessage()); + } + } } diff --git a/emis-biz-web/src/main/java/com/xdadan/erp/web/emis/EmisWaybillController.java b/emis-biz-web/src/main/java/com/xdadan/erp/web/emis/EmisWaybillController.java index d6e4f94ed..b1aaf6326 100644 --- a/emis-biz-web/src/main/java/com/xdadan/erp/web/emis/EmisWaybillController.java +++ b/emis-biz-web/src/main/java/com/xdadan/erp/web/emis/EmisWaybillController.java @@ -46,6 +46,7 @@ import com.xdadan.erp.emis.utils.WaybillHelper; import com.xdadan.erp.system.domain.SysFileInfo; import com.xdadan.erp.system.service.ISysFileInfoService; import com.xdadan.erp.system.service.ISysUserService; +import com.xdadan.erp.web.emis.annotation.WaybillLightCount; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.StringUtils; @@ -541,10 +542,11 @@ public class EmisWaybillController extends EmisBaseController */ @PreAuthorize("@ss.hasPermi('emis:emisWaybill:list')") @GetMapping("/list") + @WaybillLightCount public TableDataInfo list(EmisWaybill emisWaybill) { // 非总部只能查看自己的或者与自己相关的订单 - startPage(); +// startPage(); setPrivParams(emisWaybill); @@ -578,11 +580,12 @@ public class EmisWaybillController extends EmisBaseController */ @PreAuthorize("@ss.hasPermi('emis:emisWaybill:list')") @GetMapping("/listOrder") + @WaybillLightCount public TableDataInfo listOrder(EmisWaybill emisWaybill) { // 非总部只能查看自己的或者与自己相关的订单 - startPage(); +// startPage(); setPrivParams(emisWaybill); @@ -680,11 +683,12 @@ public class EmisWaybillController extends EmisBaseController */ @PreAuthorize("@ss.hasPermi('emis:emisWaybill:list')") @GetMapping("/querySignlist") + @WaybillLightCount public TableDataInfo querySignlist(EmisWaybill emisWaybill) { // 非总部只能查看自己的或者与自己相关的订单 - startPage(); +// startPage(); // 设置通用权限查询参数 setPrivParams(emisWaybill); @@ -891,9 +895,10 @@ public class EmisWaybillController extends EmisBaseController // ,"printManName" // },value= EmisWaybill.class,type= JacksonFilter.JscksonFilterType.RESPONSE) @GetMapping("/queryPrintListSimple") + @WaybillLightCount public TableDataInfo queryPrintListSimple(EmisWaybill emisWaybill) { - startPage(); +// startPage(); List list = null; // 如果单号不为空,则去除其他参数 diff --git a/emis-biz-web/src/main/java/com/xdadan/erp/web/emis/annotation/WaybillLightCount.java b/emis-biz-web/src/main/java/com/xdadan/erp/web/emis/annotation/WaybillLightCount.java new file mode 100644 index 000000000..51ce9fd0b --- /dev/null +++ b/emis-biz-web/src/main/java/com/xdadan/erp/web/emis/annotation/WaybillLightCount.java @@ -0,0 +1,14 @@ +package com.xdadan.erp.web.emis.annotation; + +import java.lang.annotation.*; + +/** + * 运单查询轻量 count 注解 + * - 在控制器方法上使用,统一采用轻量 count 查询 + */ +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface WaybillLightCount { +} + diff --git a/emis-biz-web/src/main/java/com/xdadan/erp/web/emis/aspect/WaybillLightCountAspect.java b/emis-biz-web/src/main/java/com/xdadan/erp/web/emis/aspect/WaybillLightCountAspect.java new file mode 100644 index 000000000..14c242e25 --- /dev/null +++ b/emis-biz-web/src/main/java/com/xdadan/erp/web/emis/aspect/WaybillLightCountAspect.java @@ -0,0 +1,81 @@ +package com.xdadan.erp.web.emis.aspect; + +import com.github.pagehelper.PageHelper; +import com.xdadan.erp.common.core.page.PageDomain; +import com.xdadan.erp.common.core.page.TableDataInfo; +import com.xdadan.erp.common.core.page.TableSupport; +import com.xdadan.erp.emis.domain.EmisWaybill; +import com.xdadan.erp.emis.service.IEmisWaybillService; +import com.xdadan.erp.web.emis.annotation.WaybillLightCount; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.annotation.Around; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Pointcut; +import org.springframework.stereotype.Component; + +/** + * 运单查询轻量 count 切面 + * - 统一关闭 PageHelper 自动 count + * - 使用轻量 count SQL 计算总数 + */ +@Aspect +@Component +@Slf4j +@RequiredArgsConstructor +public class WaybillLightCountAspect { + + private final IEmisWaybillService emisWaybillService; + + @Pointcut("@annotation(com.xdadan.erp.web.emis.annotation.WaybillLightCount)") + public void lightCountPointcut() {} + + @Around("lightCountPointcut()") + public Object around(ProceedingJoinPoint joinPoint) throws Throwable { + // 统一分页:禁用自动 count,保留 orderBy + PageDomain pageDomain = TableSupport.buildPageRequest(); + Integer pageNum = pageDomain.getPageNum(); + Integer pageSize = pageDomain.getPageSize(); + String orderBy = pageDomain.getOrderBy(); + if (pageNum != null && pageSize != null) { + PageHelper.startPage(pageNum, pageSize, false); + if (StringUtils.isNotEmpty(orderBy)) { + PageHelper.orderBy(orderBy); + } + } + + Object result = joinPoint.proceed(); + + if (!(result instanceof TableDataInfo)) { + return result; + } + + EmisWaybill param = null; + for (Object arg : joinPoint.getArgs()) { + if (arg instanceof EmisWaybill) { + param = (EmisWaybill) arg; + break; + } + } + + if (param == null) { + return result; + } + + long total = 0L; + try { + total = emisWaybillService.countWaybillList(param); + } catch (Exception ex) { + log.warn("Light count failed, fallback to current total. param={}", param.getBillCode(), ex); + } + + TableDataInfo table = (TableDataInfo) result; + if (total > 0) { + table.setTotal(total); + } + return table; + } +} + diff --git a/emis-biz/src/main/java/com/xdadan/erp/emis/mapper/EmisWaybillMapper.java b/emis-biz/src/main/java/com/xdadan/erp/emis/mapper/EmisWaybillMapper.java index ef98b061a..b83b67fa9 100644 --- a/emis-biz/src/main/java/com/xdadan/erp/emis/mapper/EmisWaybillMapper.java +++ b/emis-biz/src/main/java/com/xdadan/erp/emis/mapper/EmisWaybillMapper.java @@ -141,6 +141,11 @@ public interface EmisWaybillMapper extends BaseMapper public List selectPrintWaybillList(EmisWaybill emisWaybill); + /** + * 运单列表轻量计数 + */ + public long countWaybillList(EmisWaybill emisWaybill); + diff --git a/emis-biz/src/main/java/com/xdadan/erp/emis/service/IEmisWaybillService.java b/emis-biz/src/main/java/com/xdadan/erp/emis/service/IEmisWaybillService.java index 52ced9b71..bc9c499dd 100644 --- a/emis-biz/src/main/java/com/xdadan/erp/emis/service/IEmisWaybillService.java +++ b/emis-biz/src/main/java/com/xdadan/erp/emis/service/IEmisWaybillService.java @@ -251,6 +251,7 @@ public interface IEmisWaybillService extends IDataAuditService public List selectPrintWaybillList(EmisWaybill emisWaybill); + public long countWaybillList(EmisWaybill emisWaybill); public void genWarehouseInTplFileByOms(HttpServletResponse response, String orderSn,String fileType) throws EmisBizError ; public void genWarehouseInTplFile(HttpServletResponse response, String orderSn,String fileType) throws EmisBizError ; diff --git a/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisTmsSiteBatchMissServiceImpl.java b/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisTmsSiteBatchMissServiceImpl.java index 398ba4602..5c111effe 100644 --- a/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisTmsSiteBatchMissServiceImpl.java +++ b/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisTmsSiteBatchMissServiceImpl.java @@ -233,7 +233,7 @@ public class EmisTmsSiteBatchMissServiceImpl extends EmisBaseService implements } // 1) 逻辑删除漏组批次数据 - emisTmsSiteBatchMissMapper.deleteByBillCodes(billCodes); +// emisTmsSiteBatchMissMapper.deleteByBillCodes(billCodes); emisTmsSiteBatchMissMapper.deleteByBillCodesV2(billCodes); // 2) 新增运单组批次状态 site_batch_status=1(幂等:insert ignore) @@ -275,7 +275,7 @@ public class EmisTmsSiteBatchMissServiceImpl extends EmisBaseService implements // 3) 调用scanSiteBatchByWaybills重新扫描 if (!waybills.isEmpty()) { - this.scanSiteBatchByWaybills(waybills); +// this.scanSiteBatchByWaybills(waybills); this.scanSiteBatchByWaybillsV2(waybills); } } @@ -307,6 +307,7 @@ public class EmisTmsSiteBatchMissServiceImpl extends EmisBaseService implements public void autoScanSiteBatch(String lineCode) { ExecutorService executorService = null; try { + emisTmsSiteBatchMissMapper.deleteReally(lineCode); long startTime = System.currentTimeMillis(); int pageSize = 1000; int offset = 0; @@ -321,20 +322,6 @@ public class EmisTmsSiteBatchMissServiceImpl extends EmisBaseService implements List treeRules = this.selectEmisTransPlanRuleTree(lineCode); if (treeRules.isEmpty()) { log.info("No trans plan rules found, skip auto scan"); - List waybills = emisWaybillMapper.selectWaybillListBySiteBatchStatus(0, 100000, - lineCode); - if (waybills.isEmpty()) { - return; - } - List missRecords = waybills.stream().map(waybill -> { - EmisTmsSiteBatchMiss miss = createMissRecord(waybill); - miss.setMissReason("当前线路没有创建对应的线路规划"); - miss.setMissType("1"); - miss.setLineCode(waybill.getTransLineType()); - miss.setProductType(waybill.getProductType()); - return miss; - }).collect(Collectors.toList()); - emisTmsSiteBatchMissMapper.batchInsertEmisTmsSiteBatchMiss(missRecords); return; } diff --git a/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisTmsSiteBatchServiceImpl.java b/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisTmsSiteBatchServiceImpl.java index 902b73f4d..2cfb1a918 100644 --- a/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisTmsSiteBatchServiceImpl.java +++ b/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisTmsSiteBatchServiceImpl.java @@ -11,6 +11,7 @@ package com.xdadan.erp.emis.service.impl; import java.math.BigDecimal; +import java.text.SimpleDateFormat; import java.util.*; import java.util.stream.Collectors; import java.util.ArrayList; @@ -444,6 +445,36 @@ public class EmisTmsSiteBatchServiceImpl extends EmisBaseService implements IEmi if (CollectionUtil.isEmpty(filterList)) { throw new EmisBizError(EmisBizErrorType.FAIL, emisWaybill.getBillCode() + "组批次起始网点、下一网点、供应商与规则不匹配"); } + // 过滤有效期内的规则 + Date etd = oldSiteBatch.getEtd(); + if (etd != null) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + List validRanges = filterList.stream().map(i -> { + Date startDate = i.getStartDate(); + Date endDate = i.getEndDate(); + if (startDate == null || endDate == null) { + return null; + } + return sdf.format(startDate) + "~" + sdf.format(endDate); + }).filter(StringUtils::isNotBlank).distinct().collect(Collectors.toList()); + filterList = filterList.stream() + .filter(i -> { + Date startDate = i.getStartDate(); + Date endDate = i.getEndDate(); + if (startDate == null || endDate == null) { + return false; + } + // 判断etd是否在有效期内:startDate <= etd < endDate + return !etd.before(startDate) && etd.before(endDate); + }) + .collect(Collectors.toList()); + if (CollectionUtil.isEmpty(filterList)) { + String rangeMsg = CollectionUtil.isEmpty(validRanges) ? "暂无可用时间范围" + : String.join(",", validRanges); + throw new EmisBizError(EmisBizErrorType.FAIL, + emisWaybill.getBillCode() + "组批次发出时间不在规则有效期内(规则时间范围:" + rangeMsg + "),请选择正确的时间或联系it处理"); + } + } return list; } diff --git a/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisWaybillServiceImpl.java b/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisWaybillServiceImpl.java index 7910cbe62..e295c2bba 100644 --- a/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisWaybillServiceImpl.java +++ b/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisWaybillServiceImpl.java @@ -14,6 +14,7 @@ package com.xdadan.erp.emis.service.impl; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; + import com.beust.jcommander.internal.Lists; import com.deepoove.poi.XWPFTemplate; import com.deepoove.poi.config.Configure; import com.deepoove.poi.data.PictureType; @@ -1001,7 +1002,7 @@ public class EmisWaybillServiceImpl extends EmisBaseService implements IEmisWayb // 取件员或操作员 if ("1".equals(pickupMethod)) { - SysUser empUser = getEmisStaffBySiteCodeAndEmpName(getCurrentUser().getOwnerSiteCode(), emisWaybillSave.getOperateEmployeeCode()); + SysUser empUser = getEmisStaffBySiteCodeAndEmpName(emisWaybillSave.getStartSiteCode(), emisWaybillSave.getOperateEmployeeCode()); if (empUser == null) { throw new EmisBizError(EmisBizErrorType.NOT_EXISTS, "操作员不正确"); } @@ -1010,7 +1011,7 @@ public class EmisWaybillServiceImpl extends EmisBaseService implements IEmisWayb } emisWaybillSave.setOperateEmployeeCode(empUser.getEmpCode()); } else if ("2".equals(pickupMethod)) { - SysUser empUser = getEmisStaffBySiteCodeAndEmpName(getCurrentUser().getOwnerSiteCode(), emisWaybillSave.getOperateEmployeeCode()); + SysUser empUser = getEmisStaffBySiteCodeAndEmpName(emisWaybillSave.getStartSiteCode(), emisWaybillSave.getOperateEmployeeCode()); if (empUser == null) { throw new EmisBizError(EmisBizErrorType.NOT_EXISTS, "取件员不正确"); } @@ -3814,6 +3815,13 @@ public class EmisWaybillServiceImpl extends EmisBaseService implements IEmisWayb @Override public void reUpdateWayBill(EmisWaybill oldEmisWaybill,EmisWaybill emisWaybillSave,Boolean needUpdateAttach,Boolean isForce) throws EmisBizError { +// if(!emisWaybillSave.getProductType().equals(oldEmisWaybill.getProductType())){ +// List batchList = emisTmsSiteBatchMapper.selectEmisTmsSiteBatchListByBillCodes( +// Lists.newArrayList(Collections.singleton(emisWaybillSave.getBillCode()))); +// if (CollectionUtil.isNotEmpty(batchList)) { +// throw new EmisBizError(EmisBizErrorType.FAIL, "该单号已经录入批次,请先在组批次中剔除该运单"); +// } +// } // 公共计算部分 emisWaybillSave.setId(oldEmisWaybill.getId()); @@ -4549,6 +4557,11 @@ public class EmisWaybillServiceImpl extends EmisBaseService implements IEmisWayb return emisWaybillMapper.selectPrintWaybillList(emisWaybill); } + @Override + public long countWaybillList(EmisWaybill emisWaybill){ + return emisWaybillMapper.countWaybillList(emisWaybill); + } + @Override public void genWarehouseInTplFileByOms(HttpServletResponse response, String orderSn,String fileType) throws EmisBizError { diff --git a/emis-biz/src/main/resources/mapper/EmisWaybillMapper.xml b/emis-biz/src/main/resources/mapper/EmisWaybillMapper.xml index 46a2d875e..dbafce4cd 100644 --- a/emis-biz/src/main/resources/mapper/EmisWaybillMapper.xml +++ b/emis-biz/src/main/resources/mapper/EmisWaybillMapper.xml @@ -1568,6 +1568,356 @@ + +