fix(wcs-service): 完善批量删除与更新校验逻辑

1. 修复空集合删除直接执行SQL的问题,提前拦截空集合参数
2. 替换不安全的布尔值判断为`Boolean.TRUE.equals(isValid)`避免空指针
3. 新增批量删除前的数据存在性校验,不存在时抛出业务异常
4. 补充单条数据更新前的存在性校验,避免更新不存在的数据
main
zch 4 weeks ago
parent 365731af39
commit 885df0f38d

@ -210,8 +210,15 @@ public class BaseDeviceHostServiceImpl implements IBaseDeviceHostService {
@CacheEvict(cacheNames = "wcs_cache", allEntries = true)
@DSTransactional
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
if(isValid){
//TODO 做一些业务上的校验,判断是否需要校验
if (ids == null || ids.isEmpty()) {
return false;
}
if (Boolean.TRUE.equals(isValid)) {
Long existCount = baseMapper.selectCount(Wrappers.<BaseDeviceHost>lambdaQuery()
.in(BaseDeviceHost::getObjId, ids));
if (existCount != ids.size()) {
throw new ServiceException("设备主机不存在或已删除,无法删除");
}
}
return baseMapper.deleteByIds(ids) > 0;
}

@ -164,6 +164,10 @@ public class BaseDeviceInfoServiceImpl implements IBaseDeviceInfoService {
@CacheEvict(cacheNames = "wcs_cache", key = "#bo.objId")
@DSTransactional
public Boolean updateByBo(BaseDeviceInfoBo bo) {
BaseDeviceInfo old = baseMapper.selectById(bo.getObjId());
if (old == null) {
throw new ServiceException("设备信息不存在,无法修改");
}
BaseDeviceInfo update = MapstructUtils.convert(bo, BaseDeviceInfo.class);
validEntityBeforeSave(update);
return baseMapper.updateById(update) > 0;
@ -203,8 +207,15 @@ public class BaseDeviceInfoServiceImpl implements IBaseDeviceInfoService {
@CacheEvict(cacheNames = "wcs_cache", allEntries = true)
@DSTransactional
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
if(isValid){
//TODO 做一些业务上的校验,判断是否需要校验
if (ids == null || ids.isEmpty()) {
return false;
}
if (Boolean.TRUE.equals(isValid)) {
Long existCount = baseMapper.selectCount(Wrappers.<BaseDeviceInfo>lambdaQuery()
.in(BaseDeviceInfo::getObjId, ids));
if (existCount != ids.size()) {
throw new ServiceException("设备信息不存在或已删除,无法删除");
}
}
return baseMapper.deleteByIds(ids) > 0;
}

@ -205,8 +205,15 @@ public class BaseDeviceParamServiceImpl implements IBaseDeviceParamService {
@CacheEvict(cacheNames = "wcs_cache", allEntries = true)
@DSTransactional
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
if(isValid){
//TODO 做一些业务上的校验,判断是否需要校验
if (ids == null || ids.isEmpty()) {
return false;
}
if (Boolean.TRUE.equals(isValid)) {
Long existCount = baseMapper.selectCount(Wrappers.<BaseDeviceParam>lambdaQuery()
.in(BaseDeviceParam::getObjId, ids));
if (existCount != ids.size()) {
throw new ServiceException("设备参数不存在或已删除,无法删除");
}
}
return baseMapper.deleteByIds(ids) > 0;
}

@ -171,6 +171,10 @@ public class BaseLocationInfoServiceImpl implements IBaseLocationInfoService {
@CacheEvict(cacheNames = "wcs_cache", key = "#bo.objId")
@DSTransactional
public Boolean updateByBo(BaseLocationInfoBo bo) {
BaseLocationInfo old = baseMapper.selectById(bo.getObjId());
if (old == null) {
throw new ServiceException("库位信息不存在,无法修改");
}
BaseLocationInfo update = MapstructUtils.convert(bo, BaseLocationInfo.class);
validEntityBeforeSave(update);
return baseMapper.updateById(update) > 0;
@ -214,8 +218,15 @@ public class BaseLocationInfoServiceImpl implements IBaseLocationInfoService {
@CacheEvict(cacheNames = "wcs_cache", allEntries = true)
@DSTransactional
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
if(isValid){
//TODO 做一些业务上的校验,判断是否需要校验
if (ids == null || ids.isEmpty()) {
return false;
}
if (Boolean.TRUE.equals(isValid)) {
Long existCount = baseMapper.selectCount(Wrappers.<BaseLocationInfo>lambdaQuery()
.in(BaseLocationInfo::getObjId, ids));
if (existCount != ids.size()) {
throw new ServiceException("库位信息不存在或已删除,无法删除");
}
}
return baseMapper.deleteByIds(ids) > 0;
}

@ -207,8 +207,15 @@ public class BaseMaterialInfoServiceImpl implements IBaseMaterialInfoService {
@CacheEvict(cacheNames = "wcs_cache", allEntries = true)
@DSTransactional
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
if(isValid){
//TODO 做一些业务上的校验,判断是否需要校验
if (ids == null || ids.isEmpty()) {
return false;
}
if (Boolean.TRUE.equals(isValid)) {
Long existCount = baseMapper.selectCount(Wrappers.<BaseMaterialInfo>lambdaQuery()
.in(BaseMaterialInfo::getObjId, ids));
if (existCount != ids.size()) {
throw new ServiceException("物料信息不存在或已删除,无法删除");
}
}
return baseMapper.deleteByIds(ids) > 0;
}

@ -195,8 +195,15 @@ public class BasePathDetailsServiceImpl implements IBasePathDetailsService {
@CacheEvict(cacheNames = "wcs_cache", allEntries = true)
@DSTransactional
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
if(isValid){
// TODO: 做一些业务上的校验,判断是否需要校验
if (ids == null || ids.isEmpty()) {
return false;
}
if (Boolean.TRUE.equals(isValid)) {
Long existCount = baseMapper.selectCount(Wrappers.<BasePathDetails>lambdaQuery()
.in(BasePathDetails::getObjId, ids));
if (existCount != ids.size()) {
throw new ServiceException("路径明细不存在或已删除,无法删除");
}
}
// 执行批量删除操作
return baseMapper.deleteByIds(ids) > 0;

@ -317,8 +317,12 @@ public class BasePathInfoServiceImpl implements IBasePathInfoService {
// 删除入口明确要求主键集合空集合直接返回避免拼出无意义SQL。
return false;
}
if(isValid){
// TODO: 做一些业务上的校验,判断是否需要校验
if (Boolean.TRUE.equals(isValid)) {
Long existCount = baseMapper.selectCount(Wrappers.<BasePathInfo>lambdaQuery()
.in(BasePathInfo::getObjId, ids));
if (existCount != ids.size()) {
throw new ServiceException("路径信息不存在或已删除,无法删除");
}
}
// 根据主键集合查询路径编号
List<String> pathCodes = baseMapper.selectPathCodesByIds(ids).stream()

@ -207,8 +207,15 @@ public class BaseStoreInfoServiceImpl implements IBaseStoreInfoService {
@CacheEvict(cacheNames = "wcs_cache", allEntries = true)
@DSTransactional
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
if(isValid){
//TODO 做一些业务上的校验,判断是否需要校验
if (ids == null || ids.isEmpty()) {
return false;
}
if (Boolean.TRUE.equals(isValid)) {
Long existCount = baseMapper.selectCount(Wrappers.<BaseStoreInfo>lambdaQuery()
.in(BaseStoreInfo::getObjId, ids));
if (existCount != ids.size()) {
throw new ServiceException("仓库信息不存在或已删除,无法删除");
}
}
return baseMapper.deleteByIds(ids) > 0;
}

@ -286,8 +286,12 @@ public class LiveTaskDetailServiceImpl implements ILiveTaskDetailService {
// 删除入口明确要求主键集合空集合直接返回避免拼出无意义SQL。
return false;
}
if(isValid){
// TODO: 做一些业务上的校验,判断是否需要校验
if (Boolean.TRUE.equals(isValid)) {
Long existCount = baseMapper.selectCount(Wrappers.<LiveTaskDetail>lambdaQuery()
.in(LiveTaskDetail::getObjId, ids));
if (existCount != ids.size()) {
throw new ServiceException("实时任务明细不存在或已删除,无法删除");
}
}
// 执行批量删除操作
return baseMapper.deleteByIds(ids) > 0;

@ -384,8 +384,12 @@ public class LiveTaskQueueServiceImpl implements ILiveTaskQueueService {
// 删除入口明确要求主键集合空集合直接返回避免拼出无意义SQL。
return false;
}
if(isValid){
// TODO: 做一些业务上的校验,判断是否需要校验
if (Boolean.TRUE.equals(isValid)) {
Long existCount = baseMapper.selectCount(Wrappers.<LiveTaskQueue>lambdaQuery()
.in(LiveTaskQueue::getObjId, ids));
if (existCount != ids.size()) {
throw new ServiceException("实时任务队列不存在或已删除,无法删除");
}
}
// 根据主键集合查询任务编号
List<String> taskCodes = baseMapper.selectTaskCodesByIds(ids).stream()

@ -29,68 +29,6 @@
<result property="updateByName" column="update_by_name"/>
</resultMap>
<resultMap id="LiveTaskQueueDetailResult" type="org.dromara.wcs.domain.vo.LiveTaskDetailVo" autoMapping="true">
<id property="objId" column="obj_id"/>
<result property="taskCode" column="task_code"/>
<result property="materialCode" column="material_code"/>
<result property="materialName" column="material_name"/>
<result property="palletBarcode" column="pallet_barcode"/>
<result property="materialBarcode" column="material_barcode"/>
<result property="materialCount" column="material_count"/>
<result property="taskType" column="task_type"/>
<result property="taskCategory" column="task_category"/>
<result property="startPoint" column="start_point"/>
<result property="endPoint" column="end_point"/>
<result property="isValidate" column="is_validate"/>
<result property="pathCode" column="path_code"/>
<result property="pathName" column="path_name"/>
<result property="taskStatus" column="task_status"/>
<result property="isFlag" column="is_flag"/>
<result property="remark" column="remark"/>
<result property="createBy" column="create_by"/>
<result property="createDept" column="create_dept"/>
<result property="createTime" column="create_time"/>
<result property="updateBy" column="update_by"/>
<result property="updateTime" column="update_time"/>
<result property="createByName" column="create_by_name"/>
<result property="updateByName" column="update_by_name"/>
</resultMap>
<select id="selectTaskDetailsByTaskCode" resultMap="LiveTaskQueueDetailResult">
select
d.obj_id,
d.task_code,
d.material_code,
m.material_name,
d.pallet_barcode,
d.material_barcode,
d.material_count,
d.task_type,
d.task_category,
d.start_point,
d.end_point,
d.is_validate,
d.path_code,
p.path_name,
d.task_status,
d.is_flag,
d.remark,
d.create_by,
d.create_dept,
d.create_time,
d.update_by,
d.update_time,
cu.user_name as create_by_name,
uu.user_name as update_by_name
from live_task_detail d
left join base_material_info m on d.material_code = m.material_code
left join base_path_info p on d.path_code = p.path_code
left join ${wcsSysUserTable} cu on d.create_by = cu.user_id
left join ${wcsSysUserTable} uu on d.update_by = uu.user_id
where d.task_code = #{taskCode}
order by d.obj_id asc
</select>
<sql id="selectLiveTaskQueueVoColumns">
select
t.obj_id,

Loading…
Cancel
Save