cl
4 天以前 225f9914090016cbe0836a06fbb852da05333504
日志优化
1个文件已添加
2个文件已修改
130 ■■■■ 已修改文件
rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/LocItemServiceImpl.java 118 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
rsf-server/src/main/java/com/vincent/rsf/server/system/constant/GlobalConfigCode.java 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
version/db/sys_config_out_append_same_loc_task.sql 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/LocItemServiceImpl.java
@@ -16,7 +16,9 @@
import com.vincent.rsf.server.manager.mapper.LocItemMapper;
import com.vincent.rsf.server.manager.service.*;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.vincent.rsf.server.system.constant.GlobalConfigCode;
import com.vincent.rsf.server.system.constant.SerialRuleCode;
import com.vincent.rsf.server.system.service.ConfigService;
import com.vincent.rsf.server.system.utils.SerialRuleUtils;
import lombok.Synchronized;
import org.apache.commons.lang3.StringUtils;
@@ -36,6 +38,14 @@
public class LocItemServiceImpl extends ServiceImpl<LocItemMapper, LocItem> implements LocItemService {
    private static final BigDecimal FULL_OUT_QTY_TOLERANCE = new BigDecimal("0.000001");
    /** 可与 {@link TaskStsType#GENERATE_OUT}~{@link TaskStsType#WAVE_SEED} 衔接追加明细的出库任务类型 */
    private static final List<Integer> OUTBOUND_TASK_TYPES_FOR_APPEND = Arrays.asList(
            TaskType.TASK_TYPE_OUT.type,
            TaskType.TASK_TYPE_PICK_AGAIN_OUT.type,
            TaskType.TASK_TYPE_MERGE_OUT.type,
            TaskType.TASK_TYPE_CHECK_OUT.type
    );
    Logger logger = LoggerFactory.getLogger(LocItemServiceImpl.class);
@@ -61,6 +71,8 @@
    private MatnrService matnrService;
    @Autowired
    private AsnOrderItemService asnOrderItemService;
    @Autowired
    private ConfigService configService;
    /** 入库/出库保存前:若规格或型号为空则从物料带出 */
    private void fillSpecModelFromMatnr(LocItem item) {
        if (item == null || item.getMatnrId() == null) {
@@ -171,45 +183,73 @@
            order = new WkOrder();
        }
        final boolean appendSameLocEnabled = isOutAppendSameLocTaskEnabled();
        listMap.keySet().forEach(key -> {
            Task task = new Task();
            Loc loc = locService.getById(key);
            logger.info("库位:>{}", loc.getCode());
            if (Objects.isNull(loc)) {
                throw new CoolException("数据错误:所选库存信息不存在!!");
            }
            // 支持 F.在库 或 R.出库预约/拣货中 状态下分配(拣货中可追加同库位订单,分配量不超过已分配剩余)
            if (!loc.getUseStatus().equals(LocStsType.LOC_STS_TYPE_F.type)
                    && !loc.getUseStatus().equals(LocStsType.LOC_STS_TYPE_R.type)) {
            if (appendSameLocEnabled) {
                if (LocStsType.LOC_STS_TYPE_S.type.equals(loc.getUseStatus())) {
                    throw new CoolException("库位:" + loc.getCode() + " 处于S.入库预约,须待拣料/盘点入库回库至F.在库后再下发出库任务!!");
                }
                if (!LocStsType.LOC_STS_TYPE_F.type.equals(loc.getUseStatus())
                        && !LocStsType.LOC_STS_TYPE_R.type.equals(loc.getUseStatus())) {
                throw new CoolException("库位:" + loc.getCode() + ",不处于F.在库或R.出库预约状态,不可执行出库分配!!");
            }
            if (loc.getUseStatus().equals(LocStsType.LOC_STS_TYPE_F.type)) {
            } else {
                if (!LocStsType.LOC_STS_TYPE_F.type.equals(loc.getUseStatus())) {
                    throw new CoolException("库位:" + loc.getCode() + " 不处于F.在库状态,不可执行出库分配!!");
                }
            }
            final boolean startedAsReserved = LocStsType.LOC_STS_TYPE_R.type.equals(loc.getUseStatus());
            if (LocStsType.LOC_STS_TYPE_F.type.equals(loc.getUseStatus())) {
                loc.setUseStatus(LocStsType.LOC_STS_TYPE_R.type);
                if (!locService.updateById(loc)) {
                    throw new CoolException("库位状态更新失败!!");
                }
            }
            // 库位已为 R 时:计算该库位当前任务已分配量,新分配不能超过 (库位数量 - 已分配)
            Map<String, Double> allocatedByKey = new HashMap<>();
            List<Task> existTasks = new ArrayList<>();
            if (loc.getUseStatus().equals(LocStsType.LOC_STS_TYPE_R.type)) {
                existTasks = taskService.list(new LambdaQueryWrapper<Task>()
            List<Task> openOutboundOnLoc = taskService.list(new LambdaQueryWrapper<Task>()
                        .eq(Task::getOrgLoc, loc.getCode())
                        .in(Task::getTaskStatus, Arrays.asList(TaskStsType.GENERATE_OUT.id, TaskStsType.WAVE_SEED.id)));
                for (Task t : existTasks) {
                    .in(Task::getTaskType, OUTBOUND_TASK_TYPES_FOR_APPEND)
                    .ge(Task::getTaskStatus, TaskStsType.GENERATE_OUT.id)
                    .le(Task::getTaskStatus, TaskStsType.WAVE_SEED.id));
            boolean reuseExistingTask = false;
            Task task = null;
            if (appendSameLocEnabled && startedAsReserved) {
                if (openOutboundOnLoc.size() > 1) {
                    throw new CoolException("库位:" + loc.getCode() + " 出库预约下存在多笔未完结出库任务,不允许再生成任务,请待拣料回库至F后再分配!!");
                }
                if (openOutboundOnLoc.isEmpty()) {
                    throw new CoolException("库位:" + loc.getCode() + " 为R.出库预约但未找到未完结出库任务,库位数据异常,不可下发出库或波次!!");
                }
                task = openOutboundOnLoc.get(0);
                reuseExistingTask = true;
                if (StringUtils.isNotBlank(task.getTargSite())
                        && !StringUtils.equals(StringUtils.trimToEmpty(siteNo), StringUtils.trimToEmpty(task.getTargSite()))) {
                    throw new CoolException("库位:" + loc.getCode() + " 已有出库任务目标站点为" + task.getTargSite() + ",与本次站点不一致,不可追加明细!!");
                }
            }
            Map<String, Double> allocatedByKey = new HashMap<>();
            for (Task t : openOutboundOnLoc) {
                    List<TaskItem> existItems = taskItemService.list(new LambdaQueryWrapper<TaskItem>().eq(TaskItem::getTaskId, t.getId()));
                    for (TaskItem ti : existItems) {
                        String k = buildAllocKey(ti.getMatnrId(), ti.getBatch(), ti.getFieldsIndex());
                        allocatedByKey.put(k, allocatedByKey.getOrDefault(k, 0.0) + (ti.getAnfme() != null ? ti.getAnfme() : 0.0));
                    }
                }
            }
            // 料箱码:优先用库位;预约出库(R) 时若库位未绑定则从同库位已有任务带出并回写库位;再否则从本次分配明细带出
            String barcodeToUse = StringUtils.isNotBlank(loc.getBarcode()) ? loc.getBarcode() : null;
            if (barcodeToUse == null && !existTasks.isEmpty()) {
                barcodeToUse = existTasks.get(0).getBarcode();
            if (barcodeToUse == null && !openOutboundOnLoc.isEmpty()) {
                barcodeToUse = openOutboundOnLoc.get(0).getBarcode();
                if (StringUtils.isNotBlank(barcodeToUse)) {
                    Task refTask = existTasks.get(0);
                    Task refTask = openOutboundOnLoc.get(0);
                    LambdaUpdateWrapper<Loc> locUw = new LambdaUpdateWrapper<Loc>().eq(Loc::getId, loc.getId())
                            .set(Loc::getBarcode, barcodeToUse)
                            .set(Loc::getUpdateBy, loginUserId)
@@ -233,7 +273,10 @@
            if (barcodeToUse == null) {
                barcodeToUse = loc.getBarcode();
            }
            Task moveTask = new Task();
            if (!reuseExistingTask) {
                task = new Task();
            String ruleCode = SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_TASK_CODE, null);
            task.setOrgLoc(loc.getCode())
                    .setTaskCode(ruleCode)
@@ -262,9 +305,7 @@
            if (map.getType().equals(Constants.TASK_TYPE_OUT_STOCK)
                    || map.getType().equals(Constants.TASK_TYPE_ORDER_OUT_STOCK)
                    || map.getType().equals(Constants.TASK_TYPE_WAVE_OUT_STOCK)) {
                // 出库量达到库位库存(含容差)视为全板出库,避免浮点误差导致误判为拣料/部分出库
                if (orgQtyBd.subtract(outQtyBd).compareTo(FULL_OUT_QTY_TOLERANCE) > 0) {
                    // 拣料出库(部分出库)
                    DeviceSite deviceSite = deviceSiteService.getOne(new LambdaQueryWrapper<DeviceSite>()
                            .eq(DeviceSite::getSite, siteNo)
                            .eq(!Objects.isNull(loc.getChannel()),DeviceSite::getChannel, loc.getChannel())
@@ -274,7 +315,6 @@
                    }
                    task.setTaskType(TaskType.TASK_TYPE_PICK_AGAIN_OUT.type).setWarehType(deviceSite.getDevice());
                } else {
                    //全板出库
                    DeviceSite deviceSite = deviceSiteService.getOne(new LambdaQueryWrapper<DeviceSite>()
                            .eq(!Objects.isNull(loc.getChannel()), DeviceSite::getChannel, loc.getChannel())
                            .eq(DeviceSite::getSite, siteNo).eq(DeviceSite::getType, TaskType.TASK_TYPE_OUT.type));
@@ -285,7 +325,6 @@
                }
            } else if (map.getType().equals(Constants.TASK_TYPE_OUT_CHECK)) {
                //盘点出库
                DeviceSite deviceSite = deviceSiteService.getOne(new LambdaQueryWrapper<DeviceSite>()
                        .eq(!Objects.isNull(loc.getChannel()), DeviceSite::getChannel, loc.getChannel())
                        .eq(DeviceSite::getSite, siteNo)
@@ -298,6 +337,23 @@
            if (!taskService.save(task)) {
                throw new CoolException("任务创建失败!!");
                }
            } else {
                if (StringUtils.isNotBlank(task.getBarcode()) && StringUtils.isBlank(barcodeToUse)) {
                    barcodeToUse = task.getBarcode();
                    LambdaUpdateWrapper<Loc> locUw = new LambdaUpdateWrapper<Loc>().eq(Loc::getId, loc.getId())
                            .set(Loc::getBarcode, barcodeToUse)
                            .set(Loc::getUpdateBy, loginUserId)
                            .set(Loc::getUpdateTime, new Date());
                    if (task.getWeight() != null) {
                        locUw.set(Loc::getWeight, task.getWeight());
                    }
                    locService.update(locUw);
                }
                List<LocItem> locItemsVerify = this.list(new LambdaQueryWrapper<LocItem>().eq(LocItem::getLocId, key));
                if (locItemsVerify.isEmpty()) {
                    throw new CoolException("数据错误:所选库存明细不存在!!");
                }
            }
//            if (!LocUtils.isShallowLoc(loc.getCode())) {
@@ -333,6 +389,11 @@
                }
            }
            final Task outTask = task;
            if (outTask == null) {
                throw new CoolException("任务数据异常!!");
            }
            List<TaskItem> taskItems = new ArrayList<>();
            listMap.get(key).forEach(item -> {
                LocItem locItem = locItemService.getById(item.getId());
@@ -342,9 +403,7 @@
                if (item.getOutQty().compareTo(0.0) < 0) {
                    throw new CoolException("出库数里不能小于0!!");
                }
                // 预约出库/拣货中追加:新分配量不能超过 (库位数量 - 该物料已分配量)
                Double allocQty = item.getOutQty();
                if (!allocatedByKey.isEmpty()) {
                    String allocKey = buildAllocKey(locItem.getMatnrId(), locItem.getBatch(), locItem.getFieldsIndex());
                    Double already = allocatedByKey.getOrDefault(allocKey, 0.0);
                    Double available = Math.round((locItem.getAnfme() - already) * 1000000) / 1000000.0;
@@ -356,11 +415,10 @@
                        item.setOutQty(allocQty);
                    }
                    allocatedByKey.put(allocKey, already + allocQty);
                }
                TaskItem taskItem = new TaskItem();
                BeanUtils.copyProperties(item, taskItem);
                taskItem.setTaskId(task.getId())
                taskItem.setTaskId(outTask.getId())
                        .setAnfme(allocQty)
                        .setBatch(item.getBatch())
                        .setUpdateBy(loginUserId)
@@ -425,12 +483,11 @@
            if (!taskItemService.saveBatch(taskItems)) {
                throw new CoolException("任务明细生成失败!!");
            }
            List<TaskItem> persistedItems = taskItemService.list(new LambdaQueryWrapper<TaskItem>().eq(TaskItem::getTaskId, task.getId()));
            for (TaskItem ti : persistedItems) {
            for (TaskItem ti : taskItems) {
                if (ti.getAnfme() == null) {
                    throw new CoolException("任务明细数量异常");
                }
                taskService.enqueueCloudWmsOutNotifyLogEarly(task, ti, QuantityUtils.toScaledBigDecimal(ti.getAnfme()));
                taskService.enqueueCloudWmsOutNotifyLogEarly(outTask, ti, QuantityUtils.toScaledBigDecimal(ti.getAnfme()));
            }
        });
    }
@@ -622,4 +679,9 @@
    private static String buildAllocKey(Long matnrId, String batch, String fieldsIndex) {
        return (matnrId != null ? matnrId : "") + "|" + (batch != null ? batch : "") + "|" + (fieldsIndex != null ? fieldsIndex : "");
    }
    private boolean isOutAppendSameLocTaskEnabled() {
        Boolean v = configService.getVal(GlobalConfigCode.OUT_APPEND_SAME_LOC_TASK_ENABLED, Boolean.class);
        return Boolean.TRUE.equals(v);
    }
}
rsf-server/src/main/java/com/vincent/rsf/server/system/constant/GlobalConfigCode.java
@@ -21,6 +21,12 @@
    public final static String ORDER_INOF_REPORT_PLAT = "OrderInofReportPlat";
    /**波次自动下发任务*/
    public final static String WAVE_AUTO_EXCE_TASK = "WaveAutoExce";
    /**
     * 同库位出库任务明细追加(sys_config.type=1 布尔):true 时 R.出库预约下必须已有且仅一笔未完结出库任务(101~199),新分配追加该任务明细不合并行;R 却无任务视为库位异常不下发。
     * 关闭时仅允许 F.在库下发出库,不按预约出库追加。
     */
    public final static String OUT_APPEND_SAME_LOC_TASK_ENABLED = "OUT_APPEND_SAME_LOC_TASK_ENABLED";
    //是否自动下发任务
    public final static String AUTO_RUN_CHECK_ORDERS = "AUTO_RUN_CHECK_ORDERS";
version/db/sys_config_out_append_same_loc_task.sql
New file
@@ -0,0 +1,6 @@
-- 同库位出库任务明细追加(与 GlobalConfigCode.OUT_APPEND_SAME_LOC_TASK_ENABLED 一致)
-- type=1 布尔;val=false/0=仅 F.在库可分配;val=true/1=允许 R 下对单笔 101~199 出库任务追加明细;R 且无未完结出库任务、或多笔未完结、或库位 S 时拒绝
INSERT INTO `sys_config` (`uuid`, `name`, `flag`, `type`, `val`, `content`, `status`, `deleted`, `tenant_id`, `create_by`, `create_time`, `update_by`, `update_time`, `memo`)
SELECT UPPER(UUID()), '同库位出库任务明细追加', 'OUT_APPEND_SAME_LOC_TASK_ENABLED', 0, 'false',
       '同库位多单调 RCS 出库时是否追加至单笔未完结任务明细', 1, 0, 1, NULL, NOW(), NULL, NOW(), 'LocItemServiceImpl.generateTask'
WHERE NOT EXISTS (SELECT 1 FROM `sys_config` WHERE `flag` = 'OUT_APPEND_SAME_LOC_TASK_ENABLED' AND (`deleted` = 0 OR `deleted` IS NULL));