数据库唯一校验
This commit is contained in:
@@ -58,41 +58,41 @@ public class MaterialDestroyDO extends BusinessBaseDO {
|
||||
*/
|
||||
@TableField("OPTN")
|
||||
private String operation;
|
||||
/**
|
||||
* 公司编号
|
||||
*/
|
||||
@TableField("COMPANY_ID")
|
||||
private Long companyId;
|
||||
/**
|
||||
* 公司名称
|
||||
*/
|
||||
@TableField("COMPANY_NAME")
|
||||
private String companyName;
|
||||
/**
|
||||
* 部门编号
|
||||
*/
|
||||
@TableField("DEPT_ID")
|
||||
private Long deptId;
|
||||
/**
|
||||
* 部门名称
|
||||
*/
|
||||
@TableField("DEPT_NAME")
|
||||
private String deptName;
|
||||
/**
|
||||
* 岗位编号
|
||||
*/
|
||||
@TableField("POST_ID")
|
||||
private Long postId;
|
||||
/**
|
||||
* 创建人名称
|
||||
*/
|
||||
@TableField("CREATOR_NAME")
|
||||
private String creatorName;
|
||||
/**
|
||||
* 更新人名称
|
||||
*/
|
||||
@TableField("UPDATER_NAME")
|
||||
private String updaterName;
|
||||
// /**
|
||||
// * 公司编号
|
||||
// */
|
||||
// @TableField("COMPANY_ID")
|
||||
// private Long companyId;
|
||||
// /**
|
||||
// * 公司名称
|
||||
// */
|
||||
// @TableField("COMPANY_NAME")
|
||||
// private String companyName;
|
||||
// /**
|
||||
// * 部门编号
|
||||
// */
|
||||
// @TableField("DEPT_ID")
|
||||
// private Long deptId;
|
||||
// /**
|
||||
// * 部门名称
|
||||
// */
|
||||
// @TableField("DEPT_NAME")
|
||||
// private String deptName;
|
||||
// /**
|
||||
// * 岗位编号
|
||||
// */
|
||||
// @TableField("POST_ID")
|
||||
// private Long postId;
|
||||
// /**
|
||||
// * 创建人名称
|
||||
// */
|
||||
// @TableField("CREATOR_NAME")
|
||||
// private String creatorName;
|
||||
// /**
|
||||
// * 更新人名称
|
||||
// */
|
||||
// @TableField("UPDATER_NAME")
|
||||
// private String updaterName;
|
||||
/**
|
||||
* 供应商编码
|
||||
*/
|
||||
|
||||
@@ -37,7 +37,7 @@ public class ElementServiceImpl implements ElementService {
|
||||
// 插入
|
||||
ElementDO element = BeanUtils.toBean(createReqVO, ElementDO.class);
|
||||
// 校验存在
|
||||
validateElementCodeExists(createReqVO.getAbbreviation());
|
||||
validateElementCodeExists(createReqVO.getAbbreviation(),"insert",null);
|
||||
//金属编码自动生成,格式 JSYS-00001,依次新增
|
||||
String maxCode = elementMapper.selectMaxCode();
|
||||
if (maxCode == null) {
|
||||
@@ -59,7 +59,7 @@ public class ElementServiceImpl implements ElementService {
|
||||
// 校验存在
|
||||
validateElementExists(updateReqVO.getId());
|
||||
// 校验存在
|
||||
validateElementCodeExists(updateReqVO.getAbbreviation());
|
||||
validateElementCodeExists(updateReqVO.getAbbreviation(),"update",updateReqVO.getId());
|
||||
// 更新
|
||||
ElementDO updateObj = BeanUtils.toBean(updateReqVO, ElementDO.class);
|
||||
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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,9 @@ public class MaterialDestroyServiceImpl implements MaterialDestroyService {
|
||||
public MaterialDestroyRespVO createMaterialDestroy(MaterialDestroySaveReqVO createReqVO) {
|
||||
// 插入
|
||||
MaterialDestroyDO materialDestroy = BeanUtils.toBean(createReqVO, MaterialDestroyDO.class);
|
||||
if (materialDestroy.getIsEnable()==null||materialDestroy.getIsEnable().isEmpty()) {
|
||||
materialDestroy.setIsEnable("1");
|
||||
}
|
||||
materialDestroyMapper.insert(materialDestroy);
|
||||
// 返回
|
||||
return BeanUtils.toBean(materialDestroy, MaterialDestroyRespVO.class);
|
||||
|
||||
@@ -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,"库位与工厂信息不存在");
|
||||
}
|
||||
@@ -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 = "通过主物料编号查询子物料信息")
|
||||
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
// 校验存在
|
||||
|
||||
Reference in New Issue
Block a user