上架管理物料条码显示
This commit is contained in:
+15
-3
@@ -51,12 +51,24 @@ public class MaterialInventoryApplicationService {
|
||||
|
||||
public List<MaterialInventoryPO> queryList(MaterialInventoryDO materialInventoryDO) {
|
||||
LoginUser loginUser = SecurityUtils.getLoginUser();
|
||||
if (loginUser != null){
|
||||
if (loginUser != null && loginUser.getUserPo() != null){
|
||||
Long userOrganizationId = loginUser.getUserPo().getOrganizationId();
|
||||
// 当前登录用户组织ID为2827时,查询所有组织的数据
|
||||
if (userOrganizationId != null && userOrganizationId == 2827L) {
|
||||
// 不设置organizationId,查询所有组织的数据
|
||||
materialInventoryDO.setOrganizationId(null);
|
||||
} else {
|
||||
// 其他情况,只查询当前登录用户所属组织的数据
|
||||
if (userOrganizationId != null) {
|
||||
materialInventoryDO.setOrganizationId(userOrganizationId);
|
||||
}
|
||||
}
|
||||
// 处理topOrganizationId逻辑
|
||||
Long topOrganizationId = loginUser.getUserPo().getTopOrganizationId();
|
||||
if (topOrganizationId != null && topOrganizationId != 1){
|
||||
materialInventoryDO.setTopOrganizationId(loginUser.getUserPo().getTopOrganizationId());
|
||||
materialInventoryDO.setTopOrganizationId(topOrganizationId);
|
||||
}
|
||||
// 前端有传warehouseId则优先使用传参;未传时才使用“用户关联仓库”作为默认值
|
||||
// 前端有传warehouseId则优先使用传参;未传时才使用"用户关联仓库"作为默认值
|
||||
if (materialInventoryDO.getWarehouseId() == null) {
|
||||
AssociationWarehouseCacheDO associationWarehouseCacheDO =
|
||||
SystemServiceCacheUtil.getAssociationWarehouseCache(loginUser.getUserid());
|
||||
|
||||
+43
-10
@@ -75,26 +75,54 @@ public class MaterialBarCodeImpl extends ServiceImpl<MaterialBarCodeMapper, Mate
|
||||
}
|
||||
LoginUser loginUser = SecurityUtils.getLoginUser();
|
||||
UserPo userPo = loginUser.getUserPo();
|
||||
//标记之前的数据删除
|
||||
materialBarCodeMapper.update(null, new UpdateWrapper<MaterialBarCode>().lambda()
|
||||
.set(MaterialBarCode::getDelFlag, 2)
|
||||
.set(MaterialBarCode::getUpdateBy, loginUser.getUserid())
|
||||
.set(MaterialBarCode::getUpdateByName, loginUser.getUsername())
|
||||
.set(MaterialBarCode::getUpdateTime, new Date())
|
||||
.eq(MaterialBarCode::getMaterialBaseInfoId, materialBarCodeDOList.get(0).getMaterialBaseInfoId())
|
||||
.eq(MaterialBarCode::getDelFlag, 1));
|
||||
Long materialBaseInfoId = materialBarCodeDOList.get(0).getMaterialBaseInfoId();
|
||||
|
||||
// 先物理删除该物料的所有旧条码记录(包括已标记删除的),避免唯一性约束冲突
|
||||
// 因为唯一性约束 IDX_MATERIAL_BASE_ID_BAR_CODE 可能检查所有记录(包括 delFlag=2 的记录)
|
||||
// 使用 Mapper 的 delete 方法进行物理删除,绕过逻辑删除拦截器
|
||||
materialBarCodeMapper.delete(new QueryWrapper<MaterialBarCode>().lambda()
|
||||
.eq(MaterialBarCode::getMaterialBaseInfoId, materialBaseInfoId));
|
||||
|
||||
// 去重处理:确保没有重复的 material_base_info_id + bar_code 组合
|
||||
// 使用 LinkedHashMap 保持顺序,对所有记录进行去重
|
||||
// 对于 barCode 为 null 的记录,使用 packDetailId 来区分(因为唯一性约束可能不允许多个 null)
|
||||
java.util.Map<String, MaterialBarCode> uniqueMap = new java.util.LinkedHashMap<>();
|
||||
List<MaterialBarCode> materialBarCodeList = new ArrayList<>();
|
||||
|
||||
for (MaterialBarCodeDO materialBarCodeDO : materialBarCodeDOList){
|
||||
String barCode = materialBarCodeDO.getBarCode();
|
||||
String key;
|
||||
// 构建唯一性 key:material_base_info_id + bar_code
|
||||
// 如果 barCode 为 null 或空,使用 packDetailId 来区分,避免多条 null 值违反唯一性约束
|
||||
if (barCode != null && !barCode.trim().isEmpty()) {
|
||||
key = materialBaseInfoId + "_" + barCode.trim();
|
||||
} else {
|
||||
// barCode 为 null 或空时,使用 packDetailId 来区分
|
||||
// 如果 packDetailId 也为 null,则使用固定值(只保留第一条)
|
||||
Long packDetailId = materialBarCodeDO.getPackDetailId();
|
||||
key = materialBaseInfoId + "_null_" + (packDetailId != null ? packDetailId : "empty");
|
||||
}
|
||||
// 如果已存在相同的组合,跳过(保留第一个),避免违反唯一性约束
|
||||
if (uniqueMap.containsKey(key)) {
|
||||
continue;
|
||||
}
|
||||
// 创建新的条码记录
|
||||
MaterialBarCode materialBarCode = new MaterialBarCode();
|
||||
BeanUtils.copyProperties(materialBarCodeDO,materialBarCode);
|
||||
BeanUtils.copyProperties(materialBarCodeDO, materialBarCode);
|
||||
materialBarCode.setOrganizationId(userPo.getOrganizationId());
|
||||
materialBarCode.setOrganizationName(userPo.getOrganizationName());
|
||||
materialBarCode.setTopOrganizationId(userPo.getTopOrganizationId());
|
||||
materialBarCode.setCreateBy(loginUser.getUserid());
|
||||
materialBarCode.setCreateByName(loginUser.getUsername());
|
||||
materialBarCode.setCreateTime(new Date());
|
||||
materialBarCode.setDelFlag(1);
|
||||
// 添加到去重 Map 和列表
|
||||
uniqueMap.put(key, materialBarCode);
|
||||
materialBarCodeList.add(materialBarCode);
|
||||
}
|
||||
if (CollectionUtils.isEmpty(materialBarCodeList)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return this.saveBatch(materialBarCodeList);
|
||||
}
|
||||
@@ -157,7 +185,12 @@ public class MaterialBarCodeImpl extends ServiceImpl<MaterialBarCodeMapper, Mate
|
||||
return null;
|
||||
}
|
||||
List<MaterialBarCodePO> materialBarCodePOList = new ArrayList<>();
|
||||
BeanUtils.copyProperties(materialBarCodeList,materialBarCodePOList);
|
||||
// 遍历列表,逐个复制每个对象的属性
|
||||
for (MaterialBarCode materialBarCode : materialBarCodeList) {
|
||||
MaterialBarCodePO materialBarCodePO = new MaterialBarCodePO();
|
||||
BeanUtils.copyProperties(materialBarCode, materialBarCodePO);
|
||||
materialBarCodePOList.add(materialBarCodePO);
|
||||
}
|
||||
return materialBarCodePOList;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user