@@ -31,4 +31,13 @@ public interface DepartmentMaterialMapper extends BaseMapperX<DepartmentMaterial
|
||||
.orderByDesc(DepartmentMaterialDO::getId));
|
||||
}
|
||||
|
||||
default Long countExist(DepartmentMaterialDO reqVO) {
|
||||
return selectCount(new LambdaQueryWrapperX<DepartmentMaterialDO>()
|
||||
.eqIfPresent(DepartmentMaterialDO::getInfomationId, reqVO.getInfomationId())
|
||||
.eqIfPresent(DepartmentMaterialDO::getClassesId, reqVO.getClassesId())
|
||||
.eqIfPresent(DepartmentMaterialDO::getDeptId, reqVO.getDeptId())
|
||||
.eqIfPresent(DepartmentMaterialDO::getDictionaryDataValue, reqVO.getDictionaryDataValue())
|
||||
.neIfPresent(DepartmentMaterialDO::getId,reqVO.getId())); // 更新时判断要排除自身
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import com.zt.plat.module.base.dal.dataobject.materialproperties.MaterialPropert
|
||||
import com.zt.plat.module.base.service.masterdatasync.support.MasterDataPropertyDefinition;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import java.util.*;
|
||||
@@ -69,6 +70,7 @@ public class DepartmentMaterialServiceImpl implements DepartmentMaterialService
|
||||
public DepartmentMaterialRespVO createDepartmentMaterial(DepartmentMaterialSaveReqVO createReqVO) {
|
||||
// 插入
|
||||
DepartmentMaterialDO departmentMaterial = BeanUtils.toBean(createReqVO, DepartmentMaterialDO.class);
|
||||
validateNotExists(departmentMaterial); // 简单验证不存在相同分类物料
|
||||
departmentMaterialMapper.insert(departmentMaterial);
|
||||
// 构造完整响应,方便前端直接刷新数据
|
||||
return CollUtil.getFirst(decorateDepartmentMaterials(Collections.singletonList(departmentMaterial)));
|
||||
@@ -80,6 +82,7 @@ public class DepartmentMaterialServiceImpl implements DepartmentMaterialService
|
||||
validateDepartmentMaterialExists(updateReqVO.getId());
|
||||
// 更新
|
||||
DepartmentMaterialDO updateObj = BeanUtils.toBean(updateReqVO, DepartmentMaterialDO.class);
|
||||
validateNotExists(updateObj); // 简单验证不存在重复相同分类物料
|
||||
departmentMaterialMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@@ -106,6 +109,14 @@ public class DepartmentMaterialServiceImpl implements DepartmentMaterialService
|
||||
}
|
||||
}
|
||||
|
||||
public void validateNotExists(DepartmentMaterialDO departmentMaterial) {
|
||||
Long cnt = departmentMaterialMapper.countExist(departmentMaterial);
|
||||
if (cnt != null && cnt > 0) {
|
||||
// 已存在未删除的同一条
|
||||
throw exception(DEPARTMENT_MATERIAL_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
private void validateDepartmentMaterialExists(Long id) {
|
||||
if (departmentMaterialMapper.selectById(id) == null) {
|
||||
throw exception(DEPARTMENT_MATERIAL_NOT_EXISTS);
|
||||
|
||||
Reference in New Issue
Block a user