opt:西门子优化
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package org.nl.wms.sch.group.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.date.DateUnit;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
@@ -24,6 +25,7 @@ import org.nl.common.domain.query.PageQuery;
|
||||
import org.nl.common.enums.GoodsEnum;
|
||||
import org.nl.common.exception.BadRequestException;
|
||||
import org.nl.common.utils.SecurityUtils;
|
||||
import org.nl.system.service.logicflow.dao.StageImage;
|
||||
import org.nl.wms.database.material.service.IMdBaseMaterialService;
|
||||
import org.nl.wms.database.material.service.dao.MdBaseMaterial;
|
||||
import org.nl.wms.database.vehicle.service.IMdBaseVehicleService;
|
||||
@@ -41,6 +43,7 @@ import org.nl.wms.sch.task.service.ISchBaseTaskService;
|
||||
import org.nl.wms.sch.task_manage.task.tasks.pcoperation.PcOperationCMTask;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import sun.misc.BASE64Encoder;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
@@ -157,10 +160,118 @@ public class SchBaseVehiclematerialgroupServiceImpl extends ServiceImpl<SchBaseV
|
||||
vehiclematerialgroupMapper.updateById(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 核心方法:入参是合并后的group_id集合,删除对应的合并前所有原始group_id数据
|
||||
* 入参格式完全不变(Set<String> ids),内部完成反推+删除原始数据
|
||||
* @param ids 合并后的group_id集合
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class) // 事务保障,避免删一半数据
|
||||
public void deleteAll(Set<String> ids) {
|
||||
// 真删除
|
||||
vehiclematerialgroupMapper.deleteBatchIds(ids);
|
||||
// 1. 入参校验:空集合直接返回,避免无效操作
|
||||
if (CollectionUtil.isEmpty(ids)) {
|
||||
return;
|
||||
}
|
||||
// 过滤空值id,避免查询/删除异常
|
||||
Set<String> validMergedIds = ids.stream()
|
||||
.filter(StrUtil::isNotEmpty)
|
||||
.collect(Collectors.toSet());
|
||||
if (CollectionUtil.isEmpty(validMergedIds)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. 第一步:根据合并后的group_id,查询出对应的合并后记录(获取5个合并条件字段)
|
||||
LambdaQueryWrapper<SchBaseVehiclematerialgroup> mergedQueryWrapper = Wrappers.lambdaQuery(SchBaseVehiclematerialgroup.class)
|
||||
.in(SchBaseVehiclematerialgroup::getGroup_id, validMergedIds);
|
||||
List<SchBaseVehiclematerialgroup> mergedList = vehiclematerialgroupMapper.selectList(mergedQueryWrapper);
|
||||
if (CollectionUtil.isEmpty(mergedList)) {
|
||||
return; // 无合并后记录,无需删除原始数据
|
||||
}
|
||||
|
||||
// 3. 第二步:从合并后记录中提取5个合并条件(vehicle_code+region_code+job_name+order_code+material_id)
|
||||
List<MergeCondition> mergeConditions = new ArrayList<>();
|
||||
for (SchBaseVehiclematerialgroup mergedItem : mergedList) {
|
||||
// 补全region_code(和你原合并逻辑一致,空值替换为"未知")
|
||||
String regionCode = StrUtil.isEmpty(mergedItem.getRegion_code()) ? "未知" : mergedItem.getRegion_code();
|
||||
mergeConditions.add(new MergeCondition(
|
||||
mergedItem.getVehicle_code(),
|
||||
regionCode,
|
||||
mergedItem.getJob_name(),
|
||||
mergedItem.getOrder_code(),
|
||||
mergedItem.getMaterial_id()
|
||||
));
|
||||
}
|
||||
|
||||
// 4. 第三步:批量查询所有合并前的原始group_id(仅1次数据库交互,无循环查库)
|
||||
Set<String> originalGroupIds = queryOriginalGroupIdsByMergeConditions(mergeConditions);
|
||||
if (CollectionUtil.isEmpty(originalGroupIds)) {
|
||||
return; // 无原始数据可删
|
||||
}
|
||||
|
||||
// 5. 第四步:删除合并前的原始数据(入参仍是合并后的ids,但实际删的是原始ids)
|
||||
vehiclematerialgroupMapper.deleteBatchIds(originalGroupIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 辅助方法:根据合并条件批量查询所有合并前的原始group_id(性能优化:批量查询)
|
||||
* @param mergeConditions 5个合并条件的集合
|
||||
* @return 合并前的原始group_id集合
|
||||
*/
|
||||
private Set<String> queryOriginalGroupIdsByMergeConditions(List<MergeCondition> mergeConditions) {
|
||||
if (CollectionUtil.isEmpty(mergeConditions)) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
// 构建批量查询条件:(条件1) OR (条件2) OR ...
|
||||
LambdaQueryWrapper<SchBaseVehiclematerialgroup> batchQueryWrapper = Wrappers.lambdaQuery(SchBaseVehiclematerialgroup.class);
|
||||
MergeCondition first = mergeConditions.get(0);
|
||||
// 第一个条件组
|
||||
batchQueryWrapper.and(w -> w.eq(SchBaseVehiclematerialgroup::getVehicle_code, first.getVehicleCode())
|
||||
.eq(!"未知".equals(first.getRegionCode()),SchBaseVehiclematerialgroup::getRegion_code, first.getRegionCode())
|
||||
.eq(SchBaseVehiclematerialgroup::getJob_name, first.getJobName())
|
||||
.eq(SchBaseVehiclematerialgroup::getOrder_code, first.getOrderCode())
|
||||
.eq(SchBaseVehiclematerialgroup::getMaterial_id, first.getMaterialId()));
|
||||
|
||||
// 剩余条件组用OR拼接
|
||||
for (int i = 1; i < mergeConditions.size(); i++) {
|
||||
MergeCondition cond = mergeConditions.get(i);
|
||||
batchQueryWrapper.or(w -> w.eq(SchBaseVehiclematerialgroup::getVehicle_code, cond.getVehicleCode())
|
||||
.eq(!"未知".equals(cond.getRegionCode()),SchBaseVehiclematerialgroup::getRegion_code, cond.getRegionCode())
|
||||
.eq(SchBaseVehiclematerialgroup::getJob_name, cond.getJobName())
|
||||
.eq(SchBaseVehiclematerialgroup::getOrder_code, cond.getOrderCode())
|
||||
.eq(SchBaseVehiclematerialgroup::getMaterial_id, cond.getMaterialId()));
|
||||
}
|
||||
|
||||
// 一次性查询所有原始记录,提取group_id
|
||||
List<SchBaseVehiclematerialgroup> originalList = vehiclematerialgroupMapper.selectList(batchQueryWrapper);
|
||||
return originalList.stream()
|
||||
.map(SchBaseVehiclematerialgroup::getGroup_id)
|
||||
.filter(StrUtil::isNotEmpty)
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
// 内部辅助类:封装5个合并条件字段(仅用于批量查询)
|
||||
private static class MergeCondition {
|
||||
private final String vehicleCode;
|
||||
private final String regionCode;
|
||||
private final String jobName;
|
||||
private final String orderCode;
|
||||
private final String materialId;
|
||||
|
||||
public MergeCondition(String vehicleCode, String regionCode, String jobName, String orderCode, String materialId) {
|
||||
this.vehicleCode = vehicleCode;
|
||||
this.regionCode = regionCode;
|
||||
this.jobName = jobName;
|
||||
this.orderCode = orderCode;
|
||||
this.materialId = materialId;
|
||||
}
|
||||
|
||||
// getter方法
|
||||
public String getVehicleCode() { return vehicleCode; }
|
||||
public String getRegionCode() { return regionCode; }
|
||||
public String getJobName() { return jobName; }
|
||||
public String getOrderCode() { return orderCode; }
|
||||
public String getMaterialId() { return materialId; }
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,6 +16,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.google.gson.Gson;
|
||||
@@ -900,6 +901,7 @@ public class SchBasePointServiceImpl extends ServiceImpl<SchBasePointMapper, Sch
|
||||
.eq(SchBasePoint::getPoint_status, GoodsEnum.EMPTY_PALLETS.getValue())
|
||||
.eq(SchBasePoint::getCan_vehicle_type, vehicleType)
|
||||
.eq(SchBasePoint::getIs_used, true)
|
||||
.orderByDesc("G01".equals(vehicleType), SchBasePoint::getPoint_type)
|
||||
// 添加行锁+LIMIT 1
|
||||
.last("LIMIT 1 FOR UPDATE"));
|
||||
if (CollectionUtils.isEmpty(schBasePoints)) {
|
||||
@@ -909,6 +911,7 @@ public class SchBasePointServiceImpl extends ServiceImpl<SchBasePointMapper, Sch
|
||||
.eq(SchBasePoint::getPoint_status, GoodsEnum.EMPTY_PALLETS.getValue())
|
||||
.eq(SchBasePoint::getCan_vehicle_type, vehicleType)
|
||||
.eq(SchBasePoint::getIs_used, true)
|
||||
.orderByDesc("G01".equals(vehicleType), SchBasePoint::getPoint_type)
|
||||
// 添加行锁+LIMIT 1
|
||||
.last("LIMIT 1 FOR UPDATE"));
|
||||
}
|
||||
|
||||
@@ -145,4 +145,6 @@ public class SchBaseTask implements Serializable {
|
||||
private String next_wait_point;
|
||||
private String startcode_name;
|
||||
private String finishcode_name;
|
||||
|
||||
private String car_type;
|
||||
}
|
||||
|
||||
@@ -103,6 +103,8 @@ public abstract class AbstractTask {
|
||||
|
||||
taskDto.setRoute_plan_code("normal");
|
||||
taskDto.setStart_device_code(task.getPoint_code1());
|
||||
taskDto.setCar_type(task.getCar_type());
|
||||
|
||||
//如果存在等待点,任务下发目标点给等待点
|
||||
if (ObjectUtil.isEmpty(task.getPoint_code2())) {
|
||||
taskDto.setNext_device_code(task.getNext_wait_point());
|
||||
|
||||
@@ -32,5 +32,7 @@ public class AcsTaskDto {
|
||||
private String params;
|
||||
//路由类型
|
||||
private String route_plan_code;
|
||||
//车辆类型
|
||||
private String car_type;
|
||||
|
||||
}
|
||||
|
||||
@@ -64,6 +64,16 @@ public class CombineSourceStoreInTask extends AbstractTask {
|
||||
}
|
||||
SchBasePoint schBasePoint = schBasePointService.selectByGroundPoint(regionCode,
|
||||
GoodsEnum.OUT_OF_STOCK.getValue(), vehicle_type, 1, 0);
|
||||
|
||||
//只有钢托盘才有这个策略
|
||||
if (StrUtil.isNotBlank(vehicle_type) && VehicleTypeEnum.TRAY.getVehicleCode().equals(vehicle_type)) {
|
||||
//搜一下有木有满拖点位,有空的,允许放
|
||||
if (ObjectUtil.isEmpty(schBasePoint)) {
|
||||
schBasePoint = schBasePointService.selectByGroundPoint(regionCode,
|
||||
GoodsEnum.OUT_OF_STOCK.getValue(), vehicle_type, 1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (ObjectUtil.isEmpty(schBasePoint)) {
|
||||
task.setRemark("未找到所需点位!");
|
||||
taskService.updateById(task);
|
||||
|
||||
@@ -70,11 +70,14 @@ public class RackTask extends AbstractTask {
|
||||
SchBasePoint schBasePoint = schBasePointService.selectByGroundPoint(regionCode,
|
||||
GoodsEnum.OUT_OF_STOCK.getValue(), vehicle_type, 1, 0);
|
||||
|
||||
// //搜一下有木有满拖点位,有空的,允许放
|
||||
// if (ObjectUtil.isEmpty(schBasePoint)) {
|
||||
// schBasePoint = schBasePointService.selectByGroundPoint(regionCode,
|
||||
// GoodsEnum.OUT_OF_STOCK.getValue(), vehicle_type, 1, 1);
|
||||
// }
|
||||
//只有钢托盘才有这个策略
|
||||
if (StrUtil.isNotBlank(vehicle_type) && VehicleTypeEnum.TRAY.getVehicleCode().equals(vehicle_type)) {
|
||||
//搜一下有木有满拖点位,有空的,允许放
|
||||
if (ObjectUtil.isEmpty(schBasePoint)) {
|
||||
schBasePoint = schBasePointService.selectByGroundPoint(regionCode,
|
||||
GoodsEnum.OUT_OF_STOCK.getValue(), vehicle_type, 1, 1);
|
||||
}
|
||||
}
|
||||
if (ObjectUtil.isEmpty(schBasePoint)) {
|
||||
task.setRemark("未找到所需点位!");
|
||||
taskService.updateById(task);
|
||||
|
||||
@@ -69,6 +69,14 @@ public class PcOperationSNTTask extends AbstractTask {
|
||||
//查询地面点位的载具编码
|
||||
// 根据对接位查找对应的载具类型
|
||||
SchBasePoint schBasePoint = schBasePointService.selectByRegionCode(sendVehicleVo.getRegion_code(), task.getVehicle_code(), "0");
|
||||
|
||||
//如果没找到 则放到有货的货架
|
||||
if (ObjectUtil.isEmpty(schBasePoint)) {
|
||||
schBasePoint = schBasePointService.selectByRegionCode(sendVehicleVo.getRegion_code(), task.getVehicle_code(), "1");
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (ObjectUtil.isEmpty(schBasePoint)) {
|
||||
task.setRemark("未找到所需点位!");
|
||||
taskService.updateById(task);
|
||||
|
||||
Reference in New Issue
Block a user