feat(warehouse): 新增批量生成库位功能
- 新增WmsActualWarehouseBatchGenerateBo类作为参数封装 - 在IWmsActualWarehouseService接口中定义batchGenerateLocations方法 - 在WmsActualWarehouseServiceImpl实现批量生成库位的逻辑 - 预生成候选编码,并过滤已存在的编码避免重复 - 支持根据行、列、层和前缀参数自动生成库位编码 - 在WmsActualWarehouseController中新增接口generateLocations - 接口添加日志记录和防重提交校验
This commit is contained in:
@@ -11,6 +11,7 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import com.klp.domain.bo.WmsActualWarehouseBo;
|
||||
import com.klp.domain.bo.WmsActualWarehouseHierarchyBo;
|
||||
import com.klp.domain.bo.WmsActualWarehouseBatchGenerateBo;
|
||||
import com.klp.domain.vo.WmsActualWarehouseTreeVo;
|
||||
import com.klp.domain.vo.WmsActualWarehouseImportVo;
|
||||
import com.klp.domain.vo.WmsActualWarehouseVo;
|
||||
@@ -41,6 +42,66 @@ public class WmsActualWarehouseServiceImpl implements IWmsActualWarehouseService
|
||||
return baseMapper.selectVoById(actualWarehouseId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int batchGenerateLocations(WmsActualWarehouseBatchGenerateBo bo) {
|
||||
if (bo == null) {
|
||||
throw new ServiceException("参数不能为空");
|
||||
}
|
||||
Integer rows = bo.getRowCount();
|
||||
Integer cols = bo.getColumnCount();
|
||||
Integer layers = bo.getLayerCount();
|
||||
String prefix = bo.getPrefix();
|
||||
Long parentId = bo.getParentId();
|
||||
if (rows == null || cols == null || layers == null || rows < 1 || cols < 1 || layers < 1) {
|
||||
throw new ServiceException("行/列/层必须为正整数");
|
||||
}
|
||||
if (StringUtils.isBlank(prefix)) {
|
||||
throw new ServiceException("前缀不能为空");
|
||||
}
|
||||
|
||||
// 预生成候选编码
|
||||
List<String> codes = new ArrayList<>(rows * cols * layers);
|
||||
for (int c = 1; c <= cols; c++) {
|
||||
for (int r = 1; r <= rows; r++) {
|
||||
String rStr = r < 10 ? ("0" + r) : String.valueOf(r);
|
||||
for (int l = 1; l <= layers; l++) {
|
||||
String code = prefix + c + rStr + '-' + l;
|
||||
codes.add(code);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 去重:过滤同父级下已存在的编码
|
||||
List<WmsActualWarehouse> exists = baseMapper.selectList(Wrappers.<WmsActualWarehouse>lambdaQuery()
|
||||
.eq(WmsActualWarehouse::getParentId, parentId)
|
||||
.in(!codes.isEmpty(), WmsActualWarehouse::getActualWarehouseCode, codes));
|
||||
Set<String> existCodes = exists.stream().map(WmsActualWarehouse::getActualWarehouseCode).collect(Collectors.toSet());
|
||||
|
||||
List<WmsActualWarehouse> toInsert = new ArrayList<>();
|
||||
for (String code : codes) {
|
||||
if (existCodes.contains(code)) {
|
||||
continue;
|
||||
}
|
||||
WmsActualWarehouse e = new WmsActualWarehouse();
|
||||
e.setParentId(parentId);
|
||||
e.setActualWarehouseType(2L);
|
||||
e.setActualWarehouseCode(code);
|
||||
e.setActualWarehouseName(code);
|
||||
e.setSortNo(0L);
|
||||
e.setIsEnabled(1);
|
||||
toInsert.add(e);
|
||||
}
|
||||
if (toInsert.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
boolean ok = baseMapper.insertBatch(toInsert);
|
||||
if (!ok) {
|
||||
throw new ServiceException("批量生成失败");
|
||||
}
|
||||
return toInsert.size();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询实际库区/库位自关联列表
|
||||
|
||||
Reference in New Issue
Block a user