erp库位、物料优化

This commit is contained in:
liss
2025-10-10 19:11:48 +08:00
parent 9011d8fc5a
commit 72a9dff7c3
18 changed files with 228 additions and 61 deletions

View File

@@ -13,6 +13,9 @@ public interface ErrorCodeConstants {
ErrorCode ERP_CUSTOMER_NOT_EXISTS = new ErrorCode(1_001_000_001, "ERP客商主数据不存在"); ErrorCode ERP_CUSTOMER_NOT_EXISTS = new ErrorCode(1_001_000_001, "ERP客商主数据不存在");
ErrorCode ERP_MATERIAL_NOT_EXISTS = new ErrorCode(1_002_000_001, "ERP物料数据不存在"); ErrorCode ERP_MATERIAL_NOT_EXISTS = new ErrorCode(1_002_000_001, "ERP物料数据不存在");
ErrorCode ERP_MATERIAL_NOT_ALLOW_UPDATE = new ErrorCode(1_002_000_001, "只允许编辑状态为“供应链”的数据");
ErrorCode ERP_MATERIAL_NOT_ALLOW_DELETE = new ErrorCode(1_002_000_001, "不允许删除状态为“ERP”的数据");
ErrorCode ERP_MATERIAL_OTHER_NOT_ALLOW_DELETE = new ErrorCode(1_002_000_001, "只允许删除不存在配置关系的数据");
ErrorCode ERP_COMPANY_NOT_EXISTS = new ErrorCode(1_003_000_001, "ERP公司数据不存在"); ErrorCode ERP_COMPANY_NOT_EXISTS = new ErrorCode(1_003_000_001, "ERP公司数据不存在");
ErrorCode ERP_COMPANY_REDIS_NOT_EXISTS = new ErrorCode(1_003_000_002, "ERP公司代码缓存数据丢失,请重新同步公司代码"); ErrorCode ERP_COMPANY_REDIS_NOT_EXISTS = new ErrorCode(1_003_000_002, "ERP公司代码缓存数据丢失,请重新同步公司代码");
@@ -40,6 +43,7 @@ public interface ErrorCodeConstants {
ErrorCode ERP_SALES_ORGANIZATION_NOT_EXISTS = new ErrorCode(1_013_000_001, "ERP销售组织数据不存在"); ErrorCode ERP_SALES_ORGANIZATION_NOT_EXISTS = new ErrorCode(1_013_000_001, "ERP销售组织数据不存在");
ErrorCode ERP_WAREHOUSE_NOT_EXISTS = new ErrorCode(1_014_000_001, "ERP库位数据不存在"); ErrorCode ERP_WAREHOUSE_NOT_EXISTS = new ErrorCode(1_014_000_001, "ERP库位数据不存在");
ErrorCode ERP_WAREHOUSE_NOT_ALLOW_UPDATE = new ErrorCode(1_014_000_002, "只允许状态为“供应链”,且“禁用”的数据编辑");
ErrorCode ERP_ASSET_NOT_EXISTS = new ErrorCode(1_015_000_001, "ERP资产卡片数据不存在"); ErrorCode ERP_ASSET_NOT_EXISTS = new ErrorCode(1_015_000_001, "ERP资产卡片数据不存在");

View File

@@ -88,14 +88,6 @@ public class ErpFactoryController {
return success(BeanUtils.toBean(pageResult, ErpFactoryRespVO.class)); return success(BeanUtils.toBean(pageResult, ErpFactoryRespVO.class));
} }
@GetMapping("/pageByCpn")
@Operation(summary = "获得ERP工厂分页")
@PreAuthorize("@ss.hasPermission('base:erp-factory:query')")
public CommonResult<PageResult<ErpFactoryRespVO>> getErpFactoryPageByCpn(@Valid ErpFactoryPageReqVO pageReqVO) {
PageResult<ErpFactoryDO> pageResult = erpFactoryService.getErpFactoryPageByCpn(pageReqVO);
return success(BeanUtils.toBean(pageResult, ErpFactoryRespVO.class));
}
@GetMapping("/export-excel") @GetMapping("/export-excel")
@Operation(summary = "导出ERP工厂 Excel") @Operation(summary = "导出ERP工厂 Excel")
@PreAuthorize("@ss.hasPermission('base:erp-factory:export')") @PreAuthorize("@ss.hasPermission('base:erp-factory:export')")

View File

@@ -101,6 +101,14 @@ public class ErpWarehouseController {
BeanUtils.toBean(list, ErpWarehouseRespVO.class)); BeanUtils.toBean(list, ErpWarehouseRespVO.class));
} }
@PutMapping("/enable-list")
@Operation(summary = "批量更新")
@PreAuthorize("@ss.hasPermission('base:warehouse:update')")
public CommonResult<Boolean> enableWarehouseList(@RequestBody List<ErpWarehouseSaveReqVO> saveReqVOS) {
erpWarehouseService.enableWarehouseList(saveReqVOS);
return success(true);
}
@PostMapping("/getErpWarehouseTask") @PostMapping("/getErpWarehouseTask")
@Operation(summary = "定时获得erp更新库位") @Operation(summary = "定时获得erp更新库位")
@PreAuthorize("@ss.hasPermission('sply:erp-warehouse:create')") @PreAuthorize("@ss.hasPermission('sply:erp-warehouse:create')")

View File

@@ -8,6 +8,9 @@ import lombok.Data;
@Data @Data
public class ErpWarehousePageReqVO extends PageParam { public class ErpWarehousePageReqVO extends PageParam {
@Schema(description = "工厂名称")
private String factoryName;
@Schema(description = "工厂编码;将查询参数存入") @Schema(description = "工厂编码;将查询参数存入")
private String factoryNumber; private String factoryNumber;
@@ -17,4 +20,8 @@ public class ErpWarehousePageReqVO extends PageParam {
@Schema(description = "库位编码") @Schema(description = "库位编码")
private String number; private String number;
@Schema(description = "类型")
private String type;
} }

View File

@@ -26,4 +26,16 @@ public class ErpWarehouseRespVO {
@ExcelProperty("库位编码") @ExcelProperty("库位编码")
private String number; private String number;
@Schema(description = "类别")
private String type;
@Schema(description = "绑定库位名")
private String relName;
@Schema(description = "绑定库位编码")
private String relnumber;
@Schema(description = "是否启用")
private String isEnable;
} }

View File

@@ -22,4 +22,16 @@ public class ErpWarehouseSaveReqVO {
@NotEmpty(message = "库位编码不能为空") @NotEmpty(message = "库位编码不能为空")
private String number; private String number;
@Schema(description = "类别")
private String type;
@Schema(description = "绑定库位名")
private String relName;
@Schema(description = "绑定库位编码")
private String relnumber;
@Schema(description = "是否启用")
private String isEnable;
} }

View File

@@ -1,6 +1,7 @@
package com.zt.plat.module.erp.dal.dataobject.erp; package com.zt.plat.module.erp.dal.dataobject.erp;
import com.baomidou.mybatisplus.annotation.*; import com.baomidou.mybatisplus.annotation.*;
import com.zt.plat.framework.mybatis.core.dataobject.BusinessBaseDO;
import lombok.*; import lombok.*;
/** /**
* ERP库位 DO * ERP库位 DO
@@ -18,7 +19,7 @@ import lombok.*;
/** /**
* 支持业务基类继承isBusiness=true 时继承 BusinessBaseDO否则继承 BaseDO * 支持业务基类继承isBusiness=true 时继承 BusinessBaseDO否则继承 BaseDO
*/ */
public class ErpWarehouseDO { public class ErpWarehouseDO extends BusinessBaseDO {
/** /**
* 主键 * 主键
@@ -30,6 +31,11 @@ public class ErpWarehouseDO {
*/ */
@TableField("FACT_NUM") @TableField("FACT_NUM")
private String factoryNumber; private String factoryNumber;
/**
* 工厂名称;将查询参数存入
*/
@TableField(exist = false)
private String factoryName;
/** /**
* 库位描述 * 库位描述
*/ */
@@ -47,4 +53,22 @@ public class ErpWarehouseDO {
@TableField("TP") @TableField("TP")
private String type; private String type;
/**
* 绑定库位名
*/
@TableField("REL_NAME")
private String relName;
/**
* 绑定库位编码
*/
@TableField("REL_NUM")
private String relnumber;
/**
* 类型
*/
@TableField("IS_ENB")
private String isEnable;
} }

View File

@@ -18,14 +18,6 @@ import java.util.List;
@Mapper @Mapper
public interface ErpFactoryMapper extends BaseMapperX<ErpFactoryDO> { public interface ErpFactoryMapper extends BaseMapperX<ErpFactoryDO> {
default PageResult<ErpFactoryDO> selectPage(ErpFactoryPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<ErpFactoryDO>()
.likeIfPresent(ErpFactoryDO::getName, reqVO.getName())
.eqIfPresent(ErpFactoryDO::getNumber, reqVO.getNumber())
.eqIfPresent(ErpFactoryDO::getType, reqVO.getType())
.orderByDesc(ErpFactoryDO::getId));
}
String selectMaxCode(); String selectMaxCode();
List<ErpFactoryDO> getPageByReq(ErpFactoryPageReqVO pageReqVO); List<ErpFactoryDO> getPageByReq(ErpFactoryPageReqVO pageReqVO);

View File

@@ -37,4 +37,8 @@ public interface ErpMaterialMapper extends BaseMapperX<ErpMaterialDO> {
} }
void updateBatchByNumber(@Param("toUpdate") List<ErpMaterialDO> toUpdate); void updateBatchByNumber(@Param("toUpdate") List<ErpMaterialDO> toUpdate);
String selectMaxCode();
Integer selectByErpMNumbers(List<String> erpMNumber);
} }

View File

@@ -7,6 +7,8 @@ import com.zt.plat.module.erp.controller.admin.erp.vo.ErpWarehousePageReqVO;
import com.zt.plat.module.erp.dal.dataobject.erp.ErpWarehouseDO; import com.zt.plat.module.erp.dal.dataobject.erp.ErpWarehouseDO;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/** /**
* ERP库位 Mapper * ERP库位 Mapper
* *
@@ -15,13 +17,7 @@ import org.apache.ibatis.annotations.Mapper;
@Mapper @Mapper
public interface ErpWarehouseMapper extends BaseMapperX<ErpWarehouseDO> { public interface ErpWarehouseMapper extends BaseMapperX<ErpWarehouseDO> {
default PageResult<ErpWarehouseDO> selectPage(ErpWarehousePageReqVO reqVO) { String selectMaxCode();
return selectPage(reqVO, new LambdaQueryWrapperX<ErpWarehouseDO>()
.eqIfPresent(ErpWarehouseDO::getFactoryNumber, reqVO.getFactoryNumber())
.likeIfPresent(ErpWarehouseDO::getName, reqVO.getName())
// .betweenIfPresent(ErpWarehouseDO::getCreateTime, reqVO.getCreateTime())
.eqIfPresent(ErpWarehouseDO::getNumber, reqVO.getNumber())
.orderByDesc(ErpWarehouseDO::getId));
}
List<ErpWarehouseDO> getPageByReq(ErpWarehousePageReqVO pageReqVO);
} }

View File

@@ -64,6 +64,4 @@ public interface ErpFactoryService {
void callErpRfcInterface(); void callErpRfcInterface();
void enableFactoryList(List<ErpFactoryRespVO> saveReqVOS); void enableFactoryList(List<ErpFactoryRespVO> saveReqVOS);
PageResult<ErpFactoryDO> getErpFactoryPageByCpn(ErpFactoryPageReqVO pageReqVO);
} }

View File

@@ -120,20 +120,6 @@ public class ErpFactoryServiceImpl implements ErpFactoryService {
@Override @Override
public PageResult<ErpFactoryDO> getErpFactoryPage(ErpFactoryPageReqVO pageReqVO) { public PageResult<ErpFactoryDO> getErpFactoryPage(ErpFactoryPageReqVO pageReqVO) {
return erpFactoryMapper.selectPage(pageReqVO);
}
@Override
public void enableFactoryList(List<ErpFactoryRespVO> saveReqVOS) {
List<ErpFactoryDO> updateObj = BeanUtils.toBean(saveReqVOS, ErpFactoryDO.class);
List<BatchResult> count = erpFactoryMapper.updateById(updateObj);
if (CollUtil.isEmpty(count)) {
throw exception(ERP_FACTORY_NOT_EXISTS);
}
}
@Override
public PageResult<ErpFactoryDO> getErpFactoryPageByCpn(ErpFactoryPageReqVO pageReqVO) {
// 获取分页数据 // 获取分页数据
List<ErpFactoryDO> list = erpFactoryMapper.getPageByReq(pageReqVO); List<ErpFactoryDO> list = erpFactoryMapper.getPageByReq(pageReqVO);
if (list == null) { if (list == null) {
@@ -155,6 +141,15 @@ public class ErpFactoryServiceImpl implements ErpFactoryService {
return new PageResult<>(pageList, (long) total); return new PageResult<>(pageList, (long) total);
} }
@Override
public void enableFactoryList(List<ErpFactoryRespVO> saveReqVOS) {
List<ErpFactoryDO> updateObj = BeanUtils.toBean(saveReqVOS, ErpFactoryDO.class);
List<BatchResult> count = erpFactoryMapper.updateById(updateObj);
if (CollUtil.isEmpty(count)) {
throw exception(ERP_FACTORY_NOT_EXISTS);
}
}
@Override @Override
@Transactional @Transactional
@XxlJob("getErpFactoryTask") @XxlJob("getErpFactoryTask")

View File

@@ -29,8 +29,7 @@ import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
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.module.erp.enums.ErrorCodeConstants.ERP_INTERNAL_ORDER_NOT_EXISTS; import static com.zt.plat.module.erp.enums.ErrorCodeConstants.*;
import static com.zt.plat.module.erp.enums.ErrorCodeConstants.ERP_MATERIAL_NOT_EXISTS;
import static dm.jdbc.util.DriverUtil.log; import static dm.jdbc.util.DriverUtil.log;
/** /**
@@ -53,6 +52,19 @@ public class ErpMaterialServiceImpl implements ErpMaterialService {
public ErpMaterialRespVO createErpMaterial(ErpMaterialSaveReqVO createReqVO) { public ErpMaterialRespVO createErpMaterial(ErpMaterialSaveReqVO createReqVO) {
// 插入 // 插入
ErpMaterialDO erpMaterial = BeanUtils.toBean(createReqVO, ErpMaterialDO.class); ErpMaterialDO erpMaterial = BeanUtils.toBean(createReqVO, ErpMaterialDO.class);
// 工厂编码自动生成,格式 GC-0001,依次新增
if (erpMaterial.getDownCenterNumber() == null) {
String maxCode = erpMaterialMapper.selectMaxCode();
if (maxCode == null) {
erpMaterial.setDownCenterNumber("WL-0001");
} else {
String prefix = "WL-";
String numberPart = maxCode.substring(prefix.length());
int nextNumber = Integer.parseInt(numberPart) + 1;
String nextCode = prefix + String.format("%04d", nextNumber);
erpMaterial.setDownCenterNumber(nextCode);
}
}
erpMaterialMapper.insert(erpMaterial); erpMaterialMapper.insert(erpMaterial);
// 返回 // 返回
return BeanUtils.toBean(erpMaterial, ErpMaterialRespVO.class); return BeanUtils.toBean(erpMaterial, ErpMaterialRespVO.class);
@@ -64,7 +76,11 @@ public class ErpMaterialServiceImpl implements ErpMaterialService {
validateErpMaterialExists(updateReqVO.getId()); validateErpMaterialExists(updateReqVO.getId());
// 更新 // 更新
ErpMaterialDO updateObj = BeanUtils.toBean(updateReqVO, ErpMaterialDO.class); ErpMaterialDO updateObj = BeanUtils.toBean(updateReqVO, ErpMaterialDO.class);
if (updateObj.getType().equals("供应链")) {
erpMaterialMapper.updateById(updateObj); erpMaterialMapper.updateById(updateObj);
} else {
throw exception(ERP_MATERIAL_NOT_ALLOW_UPDATE);
}
} }
@Override @Override
@@ -88,6 +104,22 @@ public class ErpMaterialServiceImpl implements ErpMaterialService {
if (CollUtil.isEmpty(list) || list.size() != ids.size()) { if (CollUtil.isEmpty(list) || list.size() != ids.size()) {
throw exception(ERP_MATERIAL_NOT_EXISTS); throw exception(ERP_MATERIAL_NOT_EXISTS);
} }
List<ErpMaterialDO> erpMaterialDOList = list.stream()
.filter(erpMaterialDO -> erpMaterialDO.getType().equals("ERP"))
.collect(Collectors.toList());
if (CollUtil.isEmpty(erpMaterialDOList)) {
throw exception(ERP_MATERIAL_NOT_ALLOW_DELETE);
}
// 优化成批量查询使用IN语句
List<String> downCenterNumbers = list.stream()
.map(ErpMaterialDO::getDownCenterNumber)
.collect(Collectors.toList());
// 使用IN语句批量查询所有物料编码的数量
Integer countMap = erpMaterialMapper.selectByErpMNumbers(downCenterNumbers);
if (countMap > 1) {
throw exception(ERP_MATERIAL_OTHER_NOT_ALLOW_DELETE);
}
} }
private void validateErpMaterialExists(Long id) { private void validateErpMaterialExists(Long id) {
@@ -111,11 +143,11 @@ public class ErpMaterialServiceImpl implements ErpMaterialService {
@XxlJob("getErpMaterialTask") @XxlJob("getErpMaterialTask")
public void callErpRfcInterface() { public void callErpRfcInterface() {
try { try {
OftenEnum.FuncnrEnum funcnrEnum =OftenEnum.FuncnrEnum.物料数据; OftenEnum.FuncnrEnum funcnrEnum = OftenEnum.FuncnrEnum.物料数据;
String funcnr = funcnrEnum.getFuncnr(); String funcnr = funcnrEnum.getFuncnr();
//防止缓存数据丢失 //防止缓存数据丢失
String key = "erp" + funcnrEnum.getFuncnr(); String key = "erp" + funcnrEnum.getFuncnr();
if (myRedisConfig.getRedisCache(key)==null) { if (myRedisConfig.getRedisCache(key) == null) {
initialize(key); initialize(key);
} }
@@ -138,7 +170,7 @@ public class ErpMaterialServiceImpl implements ErpMaterialService {
} }
// 2. 处理公司数据,区分新增和更新 // 2. 处理公司数据,区分新增和更新
ProcessingResult result = processData(dataArray,funcnrEnum); ProcessingResult result = processData(dataArray, funcnrEnum);
// 3. 批量保存数据 // 3. 批量保存数据
saveData(result); saveData(result);
@@ -154,7 +186,7 @@ public class ErpMaterialServiceImpl implements ErpMaterialService {
*/ */
private ProcessingResult processData(JSONArray dataArray, OftenEnum.FuncnrEnum funcnr) { private ProcessingResult processData(JSONArray dataArray, OftenEnum.FuncnrEnum funcnr) {
String key = "erp" + funcnr.getFuncnr(); String key = "erp" + funcnr.getFuncnr();
Map<String,List<String>> numbers = myRedisConfig.numbers(dataArray, key,funcnr.getDatakey()); Map<String, List<String>> numbers = myRedisConfig.numbers(dataArray, key, funcnr.getDatakey());
List<String> allnumbers = numbers.get("all"); List<String> allnumbers = numbers.get("all");
List<String> comnumbers = numbers.get("com"); List<String> comnumbers = numbers.get("com");
List<ErpMaterialDO> toUpdate = new ArrayList<>(); List<ErpMaterialDO> toUpdate = new ArrayList<>();
@@ -168,7 +200,7 @@ public class ErpMaterialServiceImpl implements ErpMaterialService {
DO.setDownCenterNumber(number); DO.setDownCenterNumber(number);
DO.setCenterNumber(dataJson.getString("BISMT")); DO.setCenterNumber(dataJson.getString("BISMT"));
if (!dataJson.getString("ERSDA").equals("0000-00-00")) { if (!dataJson.getString("ERSDA").equals("0000-00-00")) {
DO.setCreateDate(LocalDateTime.parse(dataJson.getString("ERSDA")+"T00:00:00")); DO.setCreateDate(LocalDateTime.parse(dataJson.getString("ERSDA") + "T00:00:00"));
} }
DO.setMaterialType(dataJson.getString("MTART")); DO.setMaterialType(dataJson.getString("MTART"));
DO.setMaterialGroupDate(dataJson.getString("MATKL")); DO.setMaterialGroupDate(dataJson.getString("MATKL"));
@@ -192,7 +224,7 @@ public class ErpMaterialServiceImpl implements ErpMaterialService {
} }
} }
return new ProcessingResult(toUpdate, toInsert,key,allnumbers); return new ProcessingResult(toUpdate, toInsert, key, allnumbers);
} }
/** /**
@@ -206,7 +238,7 @@ public class ErpMaterialServiceImpl implements ErpMaterialService {
if (!result.toUpdate.isEmpty()) { if (!result.toUpdate.isEmpty()) {
erpMaterialMapper.updateBatchByNumber(result.toUpdate); erpMaterialMapper.updateBatchByNumber(result.toUpdate);
} }
myRedisConfig.updateRedisCache(result.key,result.allnumbers); myRedisConfig.updateRedisCache(result.key, result.allnumbers);
} }
/** /**
@@ -218,7 +250,7 @@ public class ErpMaterialServiceImpl implements ErpMaterialService {
private final String key; private final String key;
private final List<String> allnumbers; private final List<String> allnumbers;
public ProcessingResult(List<ErpMaterialDO> toUpdate, List<ErpMaterialDO> toInsert,String key,List<String> allnumbers) { public ProcessingResult(List<ErpMaterialDO> toUpdate, List<ErpMaterialDO> toInsert, String key, List<String> allnumbers) {
this.toUpdate = toUpdate; this.toUpdate = toUpdate;
this.toInsert = toInsert; this.toInsert = toInsert;
this.key = key; this.key = key;
@@ -228,7 +260,7 @@ public class ErpMaterialServiceImpl implements ErpMaterialService {
private void initialize(String key) { private void initialize(String key) {
List<String> existingNumbers = erpMaterialMapper.selectList(new LambdaQueryWrapperX<ErpMaterialDO>()) List<String> existingNumbers = erpMaterialMapper.selectList(new LambdaQueryWrapperX<ErpMaterialDO>())
.stream( ) .stream()
.filter(ErpMaterialDO -> ErpMaterialDO.getType().equals("ERP")) .filter(ErpMaterialDO -> ErpMaterialDO.getType().equals("ERP"))
.map(ErpMaterialDO::getDownCenterNumber) .map(ErpMaterialDO::getDownCenterNumber)
.collect(Collectors.toList()); .collect(Collectors.toList());

View File

@@ -62,4 +62,6 @@ public interface ErpWarehouseService {
PageResult<ErpWarehouseDO> getErpWarehousePage(ErpWarehousePageReqVO pageReqVO); PageResult<ErpWarehouseDO> getErpWarehousePage(ErpWarehousePageReqVO pageReqVO);
void callErpRfcInterface(); void callErpRfcInterface();
void enableWarehouseList(List<ErpWarehouseSaveReqVO> saveReqVOS);
} }

View File

@@ -7,6 +7,7 @@ import com.xxl.job.core.handler.annotation.XxlJob;
import com.zt.plat.framework.common.pojo.PageResult; import com.zt.plat.framework.common.pojo.PageResult;
import com.zt.plat.framework.common.util.object.BeanUtils; import com.zt.plat.framework.common.util.object.BeanUtils;
import com.zt.plat.framework.mybatis.core.query.LambdaQueryWrapperX; import com.zt.plat.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.zt.plat.module.erp.dal.dataobject.erp.ErpFactoryDO;
import com.zt.plat.module.erp.utils.ErpConfig; import com.zt.plat.module.erp.utils.ErpConfig;
import com.zt.plat.module.erp.utils.MyRedisConfig; import com.zt.plat.module.erp.utils.MyRedisConfig;
import com.zt.plat.module.erp.enums.OftenEnum; import com.zt.plat.module.erp.enums.OftenEnum;
@@ -16,6 +17,7 @@ import com.zt.plat.module.erp.controller.admin.erp.vo.ErpWarehouseSaveReqVO;
import com.zt.plat.module.erp.dal.dataobject.erp.ErpWarehouseDO; import com.zt.plat.module.erp.dal.dataobject.erp.ErpWarehouseDO;
import com.zt.plat.module.erp.dal.mysql.erp.ErpWarehouseMapper; import com.zt.plat.module.erp.dal.mysql.erp.ErpWarehouseMapper;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.apache.ibatis.executor.BatchResult;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
@@ -50,10 +52,25 @@ public class ErpWarehouseServiceImpl implements ErpWarehouseService {
@Override @Override
public ErpWarehouseRespVO createErpWarehouse(ErpWarehouseSaveReqVO createReqVO) { public ErpWarehouseRespVO createErpWarehouse(ErpWarehouseSaveReqVO createReqVO) {
// 插入 // 插入
ErpWarehouseDO erpWarehouse = BeanUtils.toBean(createReqVO, ErpWarehouseDO.class); ErpWarehouseDO warehouse = BeanUtils.toBean(createReqVO, ErpWarehouseDO.class);
erpWarehouseMapper.insert(erpWarehouse); // 库位编码自动生成,格式 KW-0001,依次新增
String maxCode = erpWarehouseMapper.selectMaxCode();
if (warehouse.getNumber() == null){
if (maxCode == null) {
warehouse.setNumber("KW-0001");
} else {
String prefix = "KW-";
String numberPart = maxCode.substring(prefix.length());
int nextNumber = Integer.parseInt(numberPart) + 1;
String nextCode = prefix + String.format("%04d", nextNumber);
warehouse.setNumber(nextCode);
}
}
warehouse.setType("供应链");
warehouse.setIsEnable("1");
erpWarehouseMapper.insert(warehouse);
// 返回 // 返回
return BeanUtils.toBean(erpWarehouse, ErpWarehouseRespVO.class); return BeanUtils.toBean(warehouse, ErpWarehouseRespVO.class);
} }
@Override @Override
@@ -62,7 +79,11 @@ public class ErpWarehouseServiceImpl implements ErpWarehouseService {
validateErpWarehouseExists(updateReqVO.getId()); validateErpWarehouseExists(updateReqVO.getId());
// 更新 // 更新
ErpWarehouseDO updateObj = BeanUtils.toBean(updateReqVO, ErpWarehouseDO.class); ErpWarehouseDO updateObj = BeanUtils.toBean(updateReqVO, ErpWarehouseDO.class);
if (updateObj.getType().equals("供应链")&&updateObj.getIsEnable().equals("0")){
erpWarehouseMapper.updateById(updateObj); erpWarehouseMapper.updateById(updateObj);
}else {
throw exception(ERP_WAREHOUSE_NOT_ALLOW_UPDATE);
}
} }
@Override @Override
@@ -99,9 +120,37 @@ public class ErpWarehouseServiceImpl implements ErpWarehouseService {
return erpWarehouseMapper.selectById(id); return erpWarehouseMapper.selectById(id);
} }
@Override
public void enableWarehouseList(List<ErpWarehouseSaveReqVO> saveReqVOS) {
List<ErpWarehouseDO> updateObj = BeanUtils.toBean(saveReqVOS, ErpWarehouseDO.class);
List<BatchResult> count = erpWarehouseMapper.updateById(updateObj);
if (CollUtil.isEmpty(count)) {
throw exception(ERP_WAREHOUSE_NOT_EXISTS);
}
}
@Override @Override
public PageResult<ErpWarehouseDO> getErpWarehousePage(ErpWarehousePageReqVO pageReqVO) { public PageResult<ErpWarehouseDO> getErpWarehousePage(ErpWarehousePageReqVO pageReqVO) {
return erpWarehouseMapper.selectPage(pageReqVO); // 获取分页数据
List<ErpWarehouseDO> list = erpWarehouseMapper.getPageByReq(pageReqVO);
if (list == null) {
list = CollUtil.newArrayList();
}
// 分页处理
int pageNo = pageReqVO.getPageNo();
int pageSize = pageReqVO.getPageSize();
int total = list.size();
// 计算分页起始和结束位置
int fromIndex = (pageNo - 1) * pageSize;
int toIndex = Math.min(fromIndex + pageSize, total);
// 如果起始位置超出范围,则返回空列表
if (fromIndex >= total) {
return new PageResult<>(new ArrayList<>(), (long) total);
}
// 截取当前页数据
List<ErpWarehouseDO> pageList = list.subList(fromIndex, toIndex);
return new PageResult<>(pageList, (long) total);
} }
@Override @Override

View File

@@ -31,6 +31,6 @@
</select> </select>
<select id="selectMaxCode" resultType="java.lang.String"> <select id="selectMaxCode" resultType="java.lang.String">
SELECT MAX(NUM) FROM sply_erp_fact where TP = '供应链' SELECT MAX(NUM) FROM sply_erp_fact
</select> </select>
</mapper> </mapper>

View File

@@ -33,5 +33,21 @@
WHERE DOWN_CTR_NUM = #{item.downCenterNumber} WHERE DOWN_CTR_NUM = #{item.downCenterNumber}
</foreach> </foreach>
</update> </update>
<select id="selectMaxCode" resultType="java.lang.String">
SELECT MAX(MTRL_CODE) FROM SPLY_ERP_MTRL
</select>
<select id="selectByErpMId">
SELECT * FROM SPLY_ERP_MTRL WHERE MTRL_ID = #{erpMId}
</select>
<select id="selectByErpMNumbers" resultType="java.lang.Integer">
SELECT COUNT(*)
FROM sply_mtrl_oth
WHERE ERP_MTRL_NUM IN
<foreach item="erpMNumber" collection="erpMNumbers" open="(" separator="," close=")">
#{erpMNumber}
</foreach>
</select>
</mapper> </mapper>

View File

@@ -9,4 +9,28 @@
文档可见https://www.iocoder.cn/MyBatis/x-plugins/ 文档可见https://www.iocoder.cn/MyBatis/x-plugins/
--> -->
<select id="selectMaxCode" resultType="java.lang.String">
SELECT MAX(NUM) FROM sply_erp_wrh
</select>
<select id="getPageByReq" resultType="com.zt.plat.module.erp.dal.dataobject.erp.ErpWarehouseDO">
select f.*, c.NAME as f
from sply_erp_wrh f left join sply_erp_fact c on f.FACT_NUM = c.NUM;
where f.DELETED = 0
<if test="reqVO.name != null">
and f.NAME like concat('%', #{reqVO.name}, '%')
</if>
<if test="reqVO.number != null">
and f.NUM like concat('%', #{reqVO.number}, '%')
</if>
<if test="reqVO.factoryNumber != null">
and f.FACT_NUM = like concat('%', #{factoryNumber}, '%')
</if>
<if test="reqVO.factoryName != null">
and c.NAME like concat('%', #{factoryName}, '%')
</if>
<if test="reqVO.type != null">
and f.TP like concat('%', #{reqVO.type}, '%')
</if>
</select>
</mapper> </mapper>