数据库唯一校验

This commit is contained in:
潘荣晟
2026-01-14 15:50:07 +08:00
parent 3e93981058
commit 97b71a1e8c
9 changed files with 68 additions and 48 deletions

View File

@@ -58,41 +58,41 @@ public class MaterialDestroyDO extends BusinessBaseDO {
*/ */
@TableField("OPTN") @TableField("OPTN")
private String operation; private String operation;
/** // /**
* 公司编号 // * 公司编号
*/ // */
@TableField("COMPANY_ID") // @TableField("COMPANY_ID")
private Long companyId; // private Long companyId;
/** // /**
* 公司名称 // * 公司名称
*/ // */
@TableField("COMPANY_NAME") // @TableField("COMPANY_NAME")
private String companyName; // private String companyName;
/** // /**
* 部门编号 // * 部门编号
*/ // */
@TableField("DEPT_ID") // @TableField("DEPT_ID")
private Long deptId; // private Long deptId;
/** // /**
* 部门名称 // * 部门名称
*/ // */
@TableField("DEPT_NAME") // @TableField("DEPT_NAME")
private String deptName; // private String deptName;
/** // /**
* 岗位编号 // * 岗位编号
*/ // */
@TableField("POST_ID") // @TableField("POST_ID")
private Long postId; // private Long postId;
/** // /**
* 创建人名称 // * 创建人名称
*/ // */
@TableField("CREATOR_NAME") // @TableField("CREATOR_NAME")
private String creatorName; // private String creatorName;
/** // /**
* 更新人名称 // * 更新人名称
*/ // */
@TableField("UPDATER_NAME") // @TableField("UPDATER_NAME")
private String updaterName; // private String updaterName;
/** /**
* 供应商编码 * 供应商编码
*/ */

View File

@@ -37,7 +37,7 @@ public class ElementServiceImpl implements ElementService {
// 插入 // 插入
ElementDO element = BeanUtils.toBean(createReqVO, ElementDO.class); ElementDO element = BeanUtils.toBean(createReqVO, ElementDO.class);
// 校验存在 // 校验存在
validateElementCodeExists(createReqVO.getAbbreviation()); validateElementCodeExists(createReqVO.getAbbreviation(),"insert",null);
//金属编码自动生成,格式 JSYS-00001,依次新增 //金属编码自动生成,格式 JSYS-00001,依次新增
String maxCode = elementMapper.selectMaxCode(); String maxCode = elementMapper.selectMaxCode();
if (maxCode == null) { if (maxCode == null) {
@@ -59,7 +59,7 @@ public class ElementServiceImpl implements ElementService {
// 校验存在 // 校验存在
validateElementExists(updateReqVO.getId()); validateElementExists(updateReqVO.getId());
// 校验存在 // 校验存在
validateElementCodeExists(updateReqVO.getAbbreviation()); validateElementCodeExists(updateReqVO.getAbbreviation(),"update",updateReqVO.getId());
// 更新 // 更新
ElementDO updateObj = BeanUtils.toBean(updateReqVO, ElementDO.class); ElementDO updateObj = BeanUtils.toBean(updateReqVO, ElementDO.class);
elementMapper.updateById(updateObj); elementMapper.updateById(updateObj);
@@ -94,9 +94,11 @@ public class ElementServiceImpl implements ElementService {
} }
} }
private void validateElementCodeExists(String code) { private void validateElementCodeExists(String code,String type,Long id) {
ElementDO elementDO = elementMapper.getElementName(code); ElementDO elementDO = elementMapper.getElementName(code);
if (elementDO != null) { if (elementDO != null&&type.equals("insert")) {
throw exception(ELEMENT_EXISTS);
}else if (elementDO != null&&type.equals("update")&& !elementDO.getId().equals(id)) {
throw exception(ELEMENT_EXISTS); throw exception(ELEMENT_EXISTS);
} }
} }

View File

@@ -34,6 +34,9 @@ public class MaterialDestroyServiceImpl implements MaterialDestroyService {
public MaterialDestroyRespVO createMaterialDestroy(MaterialDestroySaveReqVO createReqVO) { public MaterialDestroyRespVO createMaterialDestroy(MaterialDestroySaveReqVO createReqVO) {
// 插入 // 插入
MaterialDestroyDO materialDestroy = BeanUtils.toBean(createReqVO, MaterialDestroyDO.class); MaterialDestroyDO materialDestroy = BeanUtils.toBean(createReqVO, MaterialDestroyDO.class);
if (materialDestroy.getIsEnable()==null||materialDestroy.getIsEnable().isEmpty()) {
materialDestroy.setIsEnable("1");
}
materialDestroyMapper.insert(materialDestroy); materialDestroyMapper.insert(materialDestroy);
// 返回 // 返回
return BeanUtils.toBean(materialDestroy, MaterialDestroyRespVO.class); return BeanUtils.toBean(materialDestroy, MaterialDestroyRespVO.class);

View File

@@ -59,6 +59,6 @@ public interface ErrorCodeConstants {
ErrorCode MATERIAL_ERROR = new ErrorCode( 1_017_000_009, "主物料信息错误"); ErrorCode MATERIAL_ERROR = new ErrorCode( 1_017_000_009, "主物料信息错误");
ErrorCode INTERNAL_WAREHOUSE_NOT_EXISTS= new ErrorCode(1_017_000_011,"内部仓库不存在"); ErrorCode INTERNAL_WAREHOUSE_NOT_EXISTS= new ErrorCode(1_017_000_011,"内部仓库不存在");
ErrorCode INTERNAL_WAREHOUSE_EXISTS=new ErrorCode(1_017_000_012,"内部仓库已存在");
ErrorCode WAREHOUSE_FACTORY_NOT_EXISTS=new ErrorCode(1_017_000_010,"库位与工厂信息不存在"); ErrorCode WAREHOUSE_FACTORY_NOT_EXISTS=new ErrorCode(1_017_000_010,"库位与工厂信息不存在");
} }

View File

@@ -155,17 +155,15 @@ public class ErpMaterialController {
@PostMapping("/api-erp-material") @PostMapping("/api-erp-material")
@Operation(summary = "通过接口查询物料") @Operation(summary = "通过接口查询物料")
@PreAuthorize("@ss.hasPermission('sply:erp-material:query')") @PreAuthorize("@ss.hasPermission('sply:erp-material:query')")
public CommonResult<List<ErpMaterialRespVO>> getErpMaterialByApi(@RequestBody MaterialInfomationApiVO vo) { public CommonResult<PageResult<ErpMaterialRespVO>> getErpMaterialByApi(@RequestBody MaterialInfomationApiVO vo) {
MaterialInfomationPageReqDTO material = new MaterialInfomationPageReqDTO(); MaterialInfomationPageReqDTO material = new MaterialInfomationPageReqDTO();
material.setCode(vo.getMaterialNumber()); material.setCode(vo.getMaterialNumber());
material.setName(vo.getMaterialName()); material.setName(vo.getMaterialName());
material.setPageSize(vo.getPageSize()); material.setPageSize(vo.getPageSize());
material.setPageNo(vo.getPageNo()); material.setPageNo(vo.getPageNo());
List<ErpMaterialDO> erpMaterial = erpMaterialService.getErpMaterialByApi(material); PageResult<ErpMaterialDO> erpMaterialByApi = erpMaterialService.getErpMaterialByApi(material);
return success(BeanUtils.toBean(erpMaterial, ErpMaterialRespVO.class)); return success(BeanUtils.toBean(erpMaterialByApi, ErpMaterialRespVO.class));
} }
//通过主物料查询子物料信息 //通过主物料查询子物料信息
@GetMapping("/erpMaterial-mainMaterial-code") @GetMapping("/erpMaterial-mainMaterial-code")
@Operation(summary = "通过主物料编号查询子物料信息") @Operation(summary = "通过主物料编号查询子物料信息")

View File

@@ -6,9 +6,11 @@ import com.zt.plat.framework.common.pojo.PageResult;
import com.zt.plat.framework.mybatis.core.query.LambdaQueryWrapperX; import com.zt.plat.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.zt.plat.framework.mybatis.core.mapper.BaseMapperX; import com.zt.plat.framework.mybatis.core.mapper.BaseMapperX;
import com.zt.plat.framework.tenant.core.aop.TenantIgnore;
import com.zt.plat.module.erp.controller.admin.erp.internalwarehouse.vo.InternalWarehousePageReqVO; import com.zt.plat.module.erp.controller.admin.erp.internalwarehouse.vo.InternalWarehousePageReqVO;
import com.zt.plat.module.erp.dal.dataobject.erp.internalwarehouse.InternalWarehouseDO; import com.zt.plat.module.erp.dal.dataobject.erp.internalwarehouse.InternalWarehouseDO;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
/** /**
@@ -33,5 +35,8 @@ public interface InternalWarehouseMapper extends BaseMapperX<InternalWarehouseDO
.eqIfPresent(InternalWarehouseDO::getCompanyNameCustom, reqVO.getCompanyNameCustom()) .eqIfPresent(InternalWarehouseDO::getCompanyNameCustom, reqVO.getCompanyNameCustom())
.orderByDesc(InternalWarehouseDO::getId)); .orderByDesc(InternalWarehouseDO::getId));
} }
@Select("SELECT COUNT(*) AS total FROM bse_intl_wrh WHERE NUM = #{number}")
@TenantIgnore
Long selectCountByNumber(String number);
} }

View File

@@ -79,7 +79,7 @@ public interface ErpMaterialService {
List<ErpMaterialDO> getErpMaterialByMainMaterial(Long mainMaterialId); List<ErpMaterialDO> getErpMaterialByMainMaterial(Long mainMaterialId);
List<ErpMaterialDO> getErpMaterialByApi( MaterialInfomationPageReqDTO material); PageResult<ErpMaterialDO> getErpMaterialByApi( MaterialInfomationPageReqDTO material);
ErpMaterialDO getErpMaterialByMainMaterialByCode(String code); ErpMaterialDO getErpMaterialByMainMaterialByCode(String code);

View File

@@ -279,7 +279,7 @@ public class ErpMaterialServiceImpl implements ErpMaterialService {
} }
@Override @Override
public List<ErpMaterialDO> getErpMaterialByApi(MaterialInfomationPageReqDTO material) { public PageResult<ErpMaterialDO> getErpMaterialByApi(MaterialInfomationPageReqDTO material) {
CommonResult<PageResult<MaterialInfomationRespDTO>> materialInfomationPage = materialInfomationApi.getMaterialInfomationPage(material); CommonResult<PageResult<MaterialInfomationRespDTO>> materialInfomationPage = materialInfomationApi.getMaterialInfomationPage(material);
List<ErpMaterialDO> erpMaterialDOList = new ArrayList<>(); List<ErpMaterialDO> erpMaterialDOList = new ArrayList<>();
if (materialInfomationPage.getData() != null && materialInfomationPage.getData().getList() != null && !materialInfomationPage.getData().getList().isEmpty()) { if (materialInfomationPage.getData() != null && materialInfomationPage.getData().getList() != null && !materialInfomationPage.getData().getList().isEmpty()) {
@@ -290,7 +290,7 @@ public class ErpMaterialServiceImpl implements ErpMaterialService {
} }
); );
} }
return erpMaterialDOList; return new PageResult<>(erpMaterialDOList, materialInfomationPage.getData().getTotal());
} }
@Override @Override

View File

@@ -1,6 +1,8 @@
package com.zt.plat.module.erp.service.erp.internalwarehouse; package com.zt.plat.module.erp.service.erp.internalwarehouse;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import com.zt.plat.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.zt.plat.framework.tenant.core.aop.TenantIgnore;
import com.zt.plat.module.erp.controller.admin.erp.internalwarehouse.vo.InternalWarehouseEnableDisableReqVO; import com.zt.plat.module.erp.controller.admin.erp.internalwarehouse.vo.InternalWarehouseEnableDisableReqVO;
import com.zt.plat.module.erp.controller.admin.erp.internalwarehouse.vo.InternalWarehousePageReqVO; import com.zt.plat.module.erp.controller.admin.erp.internalwarehouse.vo.InternalWarehousePageReqVO;
import com.zt.plat.module.erp.controller.admin.erp.internalwarehouse.vo.InternalWarehouseRespVO; import com.zt.plat.module.erp.controller.admin.erp.internalwarehouse.vo.InternalWarehouseRespVO;
@@ -23,6 +25,7 @@ import com.zt.plat.framework.common.util.object.BeanUtils;
import static com.zt.plat.framework.common.exception.util.ServiceExceptionUtil.exception; import static com.zt.plat.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.zt.plat.framework.common.util.collection.CollectionUtils.convertList; import static com.zt.plat.framework.common.util.collection.CollectionUtils.convertList;
import static com.zt.plat.framework.common.util.collection.CollectionUtils.diffList; import static com.zt.plat.framework.common.util.collection.CollectionUtils.diffList;
import static com.zt.plat.module.erp.enums.ErrorCodeConstants.INTERNAL_WAREHOUSE_EXISTS;
import static com.zt.plat.module.erp.enums.ErrorCodeConstants.INTERNAL_WAREHOUSE_NOT_EXISTS; import static com.zt.plat.module.erp.enums.ErrorCodeConstants.INTERNAL_WAREHOUSE_NOT_EXISTS;
@@ -42,11 +45,20 @@ public class InternalWarehouseServiceImpl implements InternalWarehouseService {
public InternalWarehouseRespVO createInternalWarehouse(InternalWarehouseSaveReqVO createReqVO) { public InternalWarehouseRespVO createInternalWarehouse(InternalWarehouseSaveReqVO createReqVO) {
// 插入 // 插入
InternalWarehouseDO internalWarehouse = BeanUtils.toBean(createReqVO, InternalWarehouseDO.class); InternalWarehouseDO internalWarehouse = BeanUtils.toBean(createReqVO, InternalWarehouseDO.class);
//校验所绑定的库位是否已经存在
validateInternalWarehouseExists(createReqVO.getNumber());
internalWarehouseMapper.insert(internalWarehouse); internalWarehouseMapper.insert(internalWarehouse);
// 返回 // 返回
return BeanUtils.toBean(internalWarehouse, InternalWarehouseRespVO.class); return BeanUtils.toBean(internalWarehouse, InternalWarehouseRespVO.class);
} }
public void validateInternalWarehouseExists(String number){
if (internalWarehouseMapper.selectCountByNumber(number)>0) {
throw exception(INTERNAL_WAREHOUSE_EXISTS);
}
}
@Override @Override
public void updateInternalWarehouse(InternalWarehouseSaveReqVO updateReqVO) { public void updateInternalWarehouse(InternalWarehouseSaveReqVO updateReqVO) {
// 校验存在 // 校验存在