数据库唯一校验

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

@@ -59,6 +59,6 @@ public interface ErrorCodeConstants {
ErrorCode MATERIAL_ERROR = new ErrorCode( 1_017_000_009, "主物料信息错误");
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,"库位与工厂信息不存在");
}

View File

@@ -155,17 +155,15 @@ public class ErpMaterialController {
@PostMapping("/api-erp-material")
@Operation(summary = "通过接口查询物料")
@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();
material.setCode(vo.getMaterialNumber());
material.setName(vo.getMaterialName());
material.setPageSize(vo.getPageSize());
material.setPageNo(vo.getPageNo());
List<ErpMaterialDO> erpMaterial = erpMaterialService.getErpMaterialByApi(material);
return success(BeanUtils.toBean(erpMaterial, ErpMaterialRespVO.class));
PageResult<ErpMaterialDO> erpMaterialByApi = erpMaterialService.getErpMaterialByApi(material);
return success(BeanUtils.toBean(erpMaterialByApi, ErpMaterialRespVO.class));
}
//通过主物料查询子物料信息
@GetMapping("/erpMaterial-mainMaterial-code")
@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.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.dal.dataobject.erp.internalwarehouse.InternalWarehouseDO;
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())
.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> getErpMaterialByApi( MaterialInfomationPageReqDTO material);
PageResult<ErpMaterialDO> getErpMaterialByApi( MaterialInfomationPageReqDTO material);
ErpMaterialDO getErpMaterialByMainMaterialByCode(String code);

View File

@@ -279,7 +279,7 @@ public class ErpMaterialServiceImpl implements ErpMaterialService {
}
@Override
public List<ErpMaterialDO> getErpMaterialByApi(MaterialInfomationPageReqDTO material) {
public PageResult<ErpMaterialDO> getErpMaterialByApi(MaterialInfomationPageReqDTO material) {
CommonResult<PageResult<MaterialInfomationRespDTO>> materialInfomationPage = materialInfomationApi.getMaterialInfomationPage(material);
List<ErpMaterialDO> erpMaterialDOList = new ArrayList<>();
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

View File

@@ -1,6 +1,8 @@
package com.zt.plat.module.erp.service.erp.internalwarehouse;
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.InternalWarehousePageReqVO;
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.util.collection.CollectionUtils.convertList;
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;
@@ -42,11 +45,20 @@ public class InternalWarehouseServiceImpl implements InternalWarehouseService {
public InternalWarehouseRespVO createInternalWarehouse(InternalWarehouseSaveReqVO createReqVO) {
// 插入
InternalWarehouseDO internalWarehouse = BeanUtils.toBean(createReqVO, InternalWarehouseDO.class);
//校验所绑定的库位是否已经存在
validateInternalWarehouseExists(createReqVO.getNumber());
internalWarehouseMapper.insert(internalWarehouse);
// 返回
return BeanUtils.toBean(internalWarehouse, InternalWarehouseRespVO.class);
}
public void validateInternalWarehouseExists(String number){
if (internalWarehouseMapper.selectCountByNumber(number)>0) {
throw exception(INTERNAL_WAREHOUSE_EXISTS);
}
}
@Override
public void updateInternalWarehouse(InternalWarehouseSaveReqVO updateReqVO) {
// 校验存在