Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
潘荣晟
2025-10-11 18:01:55 +08:00
46 changed files with 719 additions and 456 deletions

View File

@@ -1,5 +1,6 @@
package com.zt.plat.module.erp.api;
import com.zt.plat.module.erp.api.dto.ErpQueryReqDTO;
import com.zt.plat.module.erp.api.dto.ErpSubmitReqDTO;
import com.zt.plat.module.erp.utils.ErpConfig;
import jakarta.annotation.Resource;
@@ -7,6 +8,7 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.Map;
/**
* ERP Api 实现类
@@ -25,4 +27,11 @@ public class ErpExternalApiImpl implements ErpExternalApi {
public HashMap<String, String> submitDataToErp(ErpSubmitReqDTO reqDTO) {
return erpConfig.pushDataToErp(reqDTO);
}
@Override
public HashMap<String, Object> queryDataToErp(ErpQueryReqDTO reqDTO) {
String funcnr = reqDTO.getFuncnr();
Map<String, Object> req = new HashMap<>();
return erpConfig.fetchDataFromERP(funcnr, req);
}
}

View File

@@ -88,14 +88,6 @@ public class ErpFactoryController {
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")
@Operation(summary = "导出ERP工厂 Excel")
@PreAuthorize("@ss.hasPermission('base:erp-factory:export')")

View File

@@ -101,6 +101,14 @@ public class ErpWarehouseController {
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")
@Operation(summary = "定时获得erp更新库位")
@PreAuthorize("@ss.hasPermission('sply:erp-warehouse:create')")

View File

@@ -16,10 +16,10 @@ public class ErpFactoryPageReqVO extends PageParam {
private String number;
@Schema(description = "公司编号")
private String companyNumber;
private String erpCompanyNumber;
@Schema(description = "公司名称")
private String companyName;
private String erpCompanyName;
@Schema(description = "类型")
private String type;

View File

@@ -23,7 +23,10 @@ public class ErpFactoryRespVO {
private String number;
@Schema(description = "公司编号")
private String companyNumber;
private String erpCompanyNumber;
@Schema(description = "公司编号")
private String erpCompanyName;
@Schema(description = "类型")
private String type;

View File

@@ -20,10 +20,7 @@ public class ErpFactorySaveReqVO {
private String number;
@Schema(description = "公司编号")
private String companyNumber;
@Schema(description = "公司编号")
private String companyName;
private String erpCompanyNumber;
@Schema(description = "类型")
private String type;

View File

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

View File

@@ -2,6 +2,7 @@ package com.zt.plat.module.erp.controller.admin.erp.vo;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import com.baomidou.mybatisplus.annotation.TableField;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@@ -18,6 +19,9 @@ public class ErpWarehouseRespVO {
@ExcelProperty("工厂编码;将查询参数存入")
private String factoryNumber;
@Schema(description = "工厂名称")
private String factoryName;
@Schema(description = "库位描述", requiredMode = Schema.RequiredMode.REQUIRED, example = "张三")
@ExcelProperty("库位描述")
private String name;
@@ -26,4 +30,16 @@ public class ErpWarehouseRespVO {
@ExcelProperty("库位编码")
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 = "库位编码不能为空")
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

@@ -41,13 +41,13 @@ public class ErpFactoryDO extends BusinessBaseDO {
* 公司编号
*/
@TableField("CPN_ID")
private String companyNumber;
private String erpCompanyNumber;
/**
* 公司名称
*/
@TableField(exist = false)
private String companyName;
private String erpCompanyName;
/**
* 类型

View File

@@ -1,6 +1,7 @@
package com.zt.plat.module.erp.dal.dataobject.erp;
import com.baomidou.mybatisplus.annotation.*;
import com.zt.plat.framework.mybatis.core.dataobject.BusinessBaseDO;
import lombok.*;
/**
* ERP库位 DO
@@ -18,7 +19,7 @@ import lombok.*;
/**
* 支持业务基类继承isBusiness=true 时继承 BusinessBaseDO否则继承 BaseDO
*/
public class ErpWarehouseDO {
public class ErpWarehouseDO extends BusinessBaseDO {
/**
* 主键
@@ -30,6 +31,11 @@ public class ErpWarehouseDO {
*/
@TableField("FACT_NUM")
private String factoryNumber;
/**
* 工厂名称;将查询参数存入
*/
@TableField(exist = false)
private String factoryName;
/**
* 库位描述
*/
@@ -47,4 +53,22 @@ public class ErpWarehouseDO {
@TableField("TP")
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
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();
List<ErpFactoryDO> getPageByReq(ErpFactoryPageReqVO pageReqVO);

View File

@@ -37,4 +37,8 @@ public interface ErpMaterialMapper extends BaseMapperX<ErpMaterialDO> {
}
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 org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* ERP库位 Mapper
*
@@ -15,13 +17,7 @@ import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface ErpWarehouseMapper extends BaseMapperX<ErpWarehouseDO> {
default PageResult<ErpWarehouseDO> selectPage(ErpWarehousePageReqVO reqVO) {
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));
}
String selectMaxCode();
List<ErpWarehouseDO> getPageByReq(ErpWarehousePageReqVO pageReqVO);
}

View File

@@ -0,0 +1,9 @@
package com.zt.plat.module.erp.job;
public class erpJob {
public void execute() throws Exception {
// TODO Auto-generated method stub
}
}

View File

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

View File

@@ -50,6 +50,8 @@ public class ErpFactoryServiceImpl implements ErpFactoryService {
@Override
public ErpFactoryRespVO createErpFactory(ErpFactorySaveReqVO createReqVO) {
// 校验存在
validateErpFactoryExistsNumber(createReqVO.getNumber());
// 插入
ErpFactoryDO erpFactory = BeanUtils.toBean(createReqVO, ErpFactoryDO.class);
// 工厂编码自动生成,格式 GC-0001,依次新增
@@ -65,7 +67,7 @@ public class ErpFactoryServiceImpl implements ErpFactoryService {
erpFactory.setNumber(nextCode);
}
}
erpFactory.setType("供应链");
erpFactory.setType("SPLY");
erpFactory.setIsEnable("1");
erpFactoryMapper.insert(erpFactory);
// 返回
@@ -113,6 +115,14 @@ public class ErpFactoryServiceImpl implements ErpFactoryService {
}
}
private void validateErpFactoryExistsNumber(String number) {
List<ErpFactoryDO> list = erpFactoryMapper.selectList(new LambdaQueryWrapperX<ErpFactoryDO>())
.stream().filter(erpFactoryDO -> erpFactoryDO.getNumber().equals(number)).toList();
if (!list.isEmpty()) {
throw exception(ERP_FACTORY_EXISTS);
}
}
@Override
public ErpFactoryDO getErpFactory(Long id) {
return erpFactoryMapper.selectById(id);
@@ -120,20 +130,6 @@ public class ErpFactoryServiceImpl implements ErpFactoryService {
@Override
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);
if (list == null) {
@@ -155,6 +151,15 @@ public class ErpFactoryServiceImpl implements ErpFactoryService {
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
@Transactional
@XxlJob("getErpFactoryTask")
@@ -170,7 +175,7 @@ public class ErpFactoryServiceImpl implements ErpFactoryService {
// 1. 调用ERP接口获取数据
Map<String, Object> req = new HashMap<>();
JSONArray dataArrayALL = new JSONArray();
String companykey = "erp" + OftenEnum.FuncnrEnum.公司代码.getFuncnr();
String companykey = "erpMap" + OftenEnum.FuncnrEnum.公司代码.getFuncnr();
Map<String,Long> redisCache = myRedisConfig.getRedisCacheMap(companykey);
if (CollUtil.isEmpty(redisCache)) {
throw exception(ERP_COMPANY_REDIS_NOT_EXISTS);
@@ -225,7 +230,7 @@ public class ErpFactoryServiceImpl implements ErpFactoryService {
ErpFactoryDO DO = new ErpFactoryDO();
DO.setName(dataJson.getString("NAME1"));
DO.setNumber(number);
DO.setCompanyNumber(dataJson.getString("BUKRS"));
DO.setErpCompanyNumber(dataJson.getString("BUKRS"));
DO.setType("ERP");
if (numbers.get(number)!=null) {
// 更新

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.util.object.BeanUtils;
import com.zt.plat.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.zt.plat.module.erp.dal.dataobject.erp.ErpWarehouseDO;
import com.zt.plat.module.erp.utils.ErpConfig;
import com.zt.plat.module.erp.utils.MyRedisConfig;
import com.zt.plat.module.erp.enums.OftenEnum;
@@ -29,8 +30,7 @@ import java.util.Map;
import java.util.stream.Collectors;
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.ERP_MATERIAL_NOT_EXISTS;
import static com.zt.plat.module.erp.enums.ErrorCodeConstants.*;
import static dm.jdbc.util.DriverUtil.log;
/**
@@ -51,8 +51,24 @@ public class ErpMaterialServiceImpl implements ErpMaterialService {
@Override
public ErpMaterialRespVO createErpMaterial(ErpMaterialSaveReqVO createReqVO) {
// 校验存在
validateErpFactoryExistsNumber(createReqVO.getDownCenterNumber());
// 插入
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);
}
}
erpMaterial.setType("SPLY");
erpMaterialMapper.insert(erpMaterial);
// 返回
return BeanUtils.toBean(erpMaterial, ErpMaterialRespVO.class);
@@ -64,7 +80,11 @@ public class ErpMaterialServiceImpl implements ErpMaterialService {
validateErpMaterialExists(updateReqVO.getId());
// 更新
ErpMaterialDO updateObj = BeanUtils.toBean(updateReqVO, ErpMaterialDO.class);
erpMaterialMapper.updateById(updateObj);
if (updateObj.getType().equals("SPLY")) {
erpMaterialMapper.updateById(updateObj);
} else {
throw exception(ERP_MATERIAL_NOT_ALLOW_UPDATE);
}
}
@Override
@@ -76,18 +96,34 @@ public class ErpMaterialServiceImpl implements ErpMaterialService {
}
@Override
public void deleteErpMaterialListByIds(List<Long> ids) {
public void deleteErpMaterialListByIds(List<Long> ids) {
// 校验存在
validateErpMaterialExists(ids);
// 删除
erpMaterialMapper.deleteByIds(ids);
}
}
private void validateErpMaterialExists(List<Long> ids) {
List<ErpMaterialDO> list = erpMaterialMapper.selectByIds(ids);
if (CollUtil.isEmpty(list) || list.size() != ids.size()) {
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) {
@@ -96,6 +132,15 @@ public class ErpMaterialServiceImpl implements ErpMaterialService {
}
}
private void validateErpFactoryExistsNumber(String number) {
List<ErpMaterialDO> list = erpMaterialMapper.selectList(new LambdaQueryWrapperX<ErpMaterialDO>()).stream()
.filter(erpWarehouseDO -> erpWarehouseDO.getDownCenterNumber().equals(number))
.toList();
if (!list.isEmpty()) {
throw exception(ERP_MATERIAL_EXISTS);
}
}
@Override
public ErpMaterialDO getErpMaterial(Long id) {
return erpMaterialMapper.selectById(id);
@@ -111,11 +156,11 @@ public class ErpMaterialServiceImpl implements ErpMaterialService {
@XxlJob("getErpMaterialTask")
public void callErpRfcInterface() {
try {
OftenEnum.FuncnrEnum funcnrEnum =OftenEnum.FuncnrEnum.物料数据;
OftenEnum.FuncnrEnum funcnrEnum = OftenEnum.FuncnrEnum.物料数据;
String funcnr = funcnrEnum.getFuncnr();
//防止缓存数据丢失
String key = "erp" + funcnrEnum.getFuncnr();
if (myRedisConfig.getRedisCache(key)==null) {
if (myRedisConfig.getRedisCache(key) == null) {
initialize(key);
}
@@ -138,7 +183,7 @@ public class ErpMaterialServiceImpl implements ErpMaterialService {
}
// 2. 处理公司数据,区分新增和更新
ProcessingResult result = processData(dataArray,funcnrEnum);
ProcessingResult result = processData(dataArray, funcnrEnum);
// 3. 批量保存数据
saveData(result);
@@ -154,7 +199,7 @@ public class ErpMaterialServiceImpl implements ErpMaterialService {
*/
private ProcessingResult processData(JSONArray dataArray, OftenEnum.FuncnrEnum funcnr) {
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> comnumbers = numbers.get("com");
List<ErpMaterialDO> toUpdate = new ArrayList<>();
@@ -168,7 +213,7 @@ public class ErpMaterialServiceImpl implements ErpMaterialService {
DO.setDownCenterNumber(number);
DO.setCenterNumber(dataJson.getString("BISMT"));
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.setMaterialGroupDate(dataJson.getString("MATKL"));
@@ -192,7 +237,7 @@ public class ErpMaterialServiceImpl implements ErpMaterialService {
}
}
return new ProcessingResult(toUpdate, toInsert,key,allnumbers);
return new ProcessingResult(toUpdate, toInsert, key, allnumbers);
}
/**
@@ -206,7 +251,7 @@ public class ErpMaterialServiceImpl implements ErpMaterialService {
if (!result.toUpdate.isEmpty()) {
erpMaterialMapper.updateBatchByNumber(result.toUpdate);
}
myRedisConfig.updateRedisCache(result.key,result.allnumbers);
myRedisConfig.updateRedisCache(result.key, result.allnumbers);
}
/**
@@ -218,7 +263,7 @@ public class ErpMaterialServiceImpl implements ErpMaterialService {
private final String key;
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.toInsert = toInsert;
this.key = key;
@@ -228,7 +273,7 @@ public class ErpMaterialServiceImpl implements ErpMaterialService {
private void initialize(String key) {
List<String> existingNumbers = erpMaterialMapper.selectList(new LambdaQueryWrapperX<ErpMaterialDO>())
.stream( )
.stream()
.filter(ErpMaterialDO -> ErpMaterialDO.getType().equals("ERP"))
.map(ErpMaterialDO::getDownCenterNumber)
.collect(Collectors.toList());

View File

@@ -62,4 +62,6 @@ public interface ErpWarehouseService {
PageResult<ErpWarehouseDO> getErpWarehousePage(ErpWarehousePageReqVO pageReqVO);
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.util.object.BeanUtils;
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.MyRedisConfig;
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.mysql.erp.ErpWarehouseMapper;
import jakarta.annotation.Resource;
import org.apache.ibatis.executor.BatchResult;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
@@ -49,11 +51,28 @@ public class ErpWarehouseServiceImpl implements ErpWarehouseService {
@Override
public ErpWarehouseRespVO createErpWarehouse(ErpWarehouseSaveReqVO createReqVO) {
// 校验存在
validateErpFactoryExistsNumber(createReqVO.getNumber(), createReqVO.getFactoryNumber());
// 插入
ErpWarehouseDO erpWarehouse = BeanUtils.toBean(createReqVO, ErpWarehouseDO.class);
erpWarehouseMapper.insert(erpWarehouse);
ErpWarehouseDO warehouse = BeanUtils.toBean(createReqVO, ErpWarehouseDO.class);
// 库位编码自动生成,格式 KW-0001,依次新增
if (warehouse.getNumber() == null) {
String maxCode = erpWarehouseMapper.selectMaxCode();
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("SPLY");
warehouse.setIsEnable("1");
erpWarehouseMapper.insert(warehouse);
// 返回
return BeanUtils.toBean(erpWarehouse, ErpWarehouseRespVO.class);
return BeanUtils.toBean(warehouse, ErpWarehouseRespVO.class);
}
@Override
@@ -62,7 +81,11 @@ public class ErpWarehouseServiceImpl implements ErpWarehouseService {
validateErpWarehouseExists(updateReqVO.getId());
// 更新
ErpWarehouseDO updateObj = BeanUtils.toBean(updateReqVO, ErpWarehouseDO.class);
erpWarehouseMapper.updateById(updateObj);
if (updateObj.getType().equals("SPLY") && updateObj.getIsEnable().equals("0")) {
erpWarehouseMapper.updateById(updateObj);
} else {
throw exception(ERP_WAREHOUSE_NOT_ALLOW_UPDATE);
}
}
@Override
@@ -94,14 +117,52 @@ public class ErpWarehouseServiceImpl implements ErpWarehouseService {
}
}
private void validateErpFactoryExistsNumber(String number, String factoryNumber) {
List<ErpWarehouseDO> list = erpWarehouseMapper.selectList(new LambdaQueryWrapperX<ErpWarehouseDO>()).stream()
.filter(erpWarehouseDO -> erpWarehouseDO.getNumber().equals(number))
.filter(erpWarehouseDO -> erpWarehouseDO.getFactoryNumber().equals(factoryNumber))
.toList();
if (!list.isEmpty()) {
throw exception(ERP_WAREHOUSE_EXISTS);
}
}
@Override
public ErpWarehouseDO getErpWarehouse(Long 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
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
@@ -142,7 +203,7 @@ public class ErpWarehouseServiceImpl implements ErpWarehouseService {
}
dataArrayALL.addAll(dataArray);
}
if (dataArrayALL.isEmpty()){
if (dataArrayALL.isEmpty()) {
throw exception(ERP_WAREHOUSE_NOT_EXISTS);
}
@@ -191,7 +252,7 @@ public class ErpWarehouseServiceImpl implements ErpWarehouseService {
Map<String, Long> deleteNumbers = new HashMap<>();
for (String number : numbers.keySet()) {
if (!dataArrayNumbers.contains(number)) {
deleteNumbers.put(number,numbers.get(number));
deleteNumbers.put(number, numbers.get(number));
}
}
@@ -213,7 +274,7 @@ public class ErpWarehouseServiceImpl implements ErpWarehouseService {
);
Map<String, Long> numberIdMap = insertedRecords.stream()
.collect(Collectors.toMap(asset -> asset.getFactoryNumber() + "-" + asset.getNumber(), ErpWarehouseDO::getId));
myRedisConfig.addRedisCacheMap(result.key,numberIdMap);
myRedisConfig.addRedisCacheMap(result.key, numberIdMap);
}
if (!result.toUpdate.isEmpty()) {
erpWarehouseMapper.updateBatch(result.toUpdate);

View File

@@ -5,10 +5,8 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.zt.plat.module.erp.api.dto.ErpSubmitReqDTO;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
@@ -16,7 +14,6 @@ import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;
import java.util.*;
import java.util.stream.Collectors;
import static com.zt.plat.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.zt.plat.module.erp.enums.ErrorCodeConstants.*;
@@ -25,7 +22,6 @@ import static dm.jdbc.util.DriverUtil.log;
@Configuration
public class ErpConfig {
@Value("${erp.address}")
private String erpAddress;

View File

@@ -10,27 +10,35 @@
-->
<select id="getPageByReq" resultType="com.zt.plat.module.erp.dal.dataobject.erp.ErpFactoryDO">
select f.*, c.NAME as companyName
from sply_erp_fact f left join sply_erp_company c on f.CPN_ID = c.NUM;
select f.id,
f.name as name,
f.NUM as number,
f.CPN_ID as erpCompanyNumber,
f.TP as type,
f.REL_NAME as relName,
f.REL_NUM as relnumber,
f.IS_ENB as isEnable,
c.NAME as erpCompanyName
from sply_erp_fact f left join sply_erp_cpn c on f.CPN_ID = c.NUM
where f.DELETED = 0
<if test="reqVO.name != null">
and f.NAME like concat('%', #{reqVO.name}, '%')
<if test="name != null">
and f.NAME like concat('%', #{name}, '%')
</if>
<if test="reqVO.number != null">
and f.NUM like concat('%', #{reqVO.number}, '%')
<if test="number != null">
and f.NUM like concat('%', #{number}, '%')
</if>
<if test="reqVO.companyNumber != null">
and f.CPN_ID = like concat('%', #{reqVO.companyNumber}, '%')
<if test="erpCompanyNumber != null">
and f.CPN_ID like concat('%', #{erpCompanyNumber}, '%')
</if>
<if test="reqVO.companyName != null">
and c.NAME like concat('%', #{reqVO.companyName}, '%')
<if test="erpCompanyName != null">
and c.NAME like concat('%', #{erpCompanyName}, '%')
</if>
<if test="reqVO.type != null">
and f.TP like concat('%', #{reqVO.type}, '%')
<if test="type != null">
and f.TP like concat('%', #{type}, '%')
</if>
</select>
<select id="selectMaxCode" resultType="java.lang.String">
SELECT MAX(NUM) FROM sply_erp_fact where TP = '供应链'
SELECT MAX(NUM) FROM sply_erp_fact
</select>
</mapper>

View File

@@ -33,5 +33,21 @@
WHERE DOWN_CTR_NUM = #{item.downCenterNumber}
</foreach>
</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>

View File

@@ -9,4 +9,36 @@
文档可见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.id,
f.name as name,
f.NUM as number,
f.TP as type,
f.REL_NAME as relName,
f.REL_NUM as relnumber,
f.IS_ENB as isEnable,
f.FACT_NUM as factoryNumber,
c.NAME as factoryName
from sply_erp_wrh f left join sply_erp_fact c on f.FACT_NUM = c.NUM
where f.DELETED = 0
<if test="name != null">
and f.NAME like concat('%', #{name}, '%')
</if>
<if test="number != null">
and f.NUM like concat('%', #{number}, '%')
</if>
<if test="factoryNumber != null">
and f.FACT_NUM like concat('%', #{factoryNumber}, '%')
</if>
<if test="factoryName != null">
and c.NAME like concat('%', #{factoryName}, '%')
</if>
<if test="type != null">
and f.TP like concat('%', #{type}, '%')
</if>
</select>
</mapper>