erp定时任务
This commit is contained in:
@@ -35,6 +35,7 @@ public class ErpConfig {
|
|||||||
* 调用ERP接口获取公司数据
|
* 调用ERP接口获取公司数据
|
||||||
*/
|
*/
|
||||||
public JSONArray fetchDataFromERP(String funcnr, Map<String, Object> req) {
|
public JSONArray fetchDataFromERP(String funcnr, Map<String, Object> req) {
|
||||||
|
try {
|
||||||
// 构建完整URL
|
// 构建完整URL
|
||||||
String url = "http://" + erpAddress + "/api/rfc/get";
|
String url = "http://" + erpAddress + "/api/rfc/get";
|
||||||
// 构建请求参数
|
// 构建请求参数
|
||||||
@@ -58,15 +59,13 @@ public class ErpConfig {
|
|||||||
|
|
||||||
// 解析响应结果
|
// 解析响应结果
|
||||||
String responseBody = response.getBody();
|
String responseBody = response.getBody();
|
||||||
if (responseBody == null) {
|
if (responseBody.isEmpty()) {
|
||||||
log.warn("ERP接口返回空响应");
|
log.warn("无所选条件的查询数据"+req);
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
JSONObject jsonResponse = JSON.parseObject(responseBody);
|
JSONObject jsonResponse = JSON.parseObject(responseBody);
|
||||||
if (jsonResponse == null) {
|
if (jsonResponse == null) {
|
||||||
log.warn("ERP接口响应无法解析为JSON");
|
log.warn("ERP接口响应无法解析为JSON");
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 正确获取E_DATA数组
|
// 正确获取E_DATA数组
|
||||||
@@ -77,6 +76,10 @@ public class ErpConfig {
|
|||||||
log.warn("ERP接口调用失败或返回错误标志");
|
log.warn("ERP接口调用失败或返回错误标志");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("调用ERP RFC接口失败: {}", e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -91,11 +94,29 @@ public class ErpConfig {
|
|||||||
// 提取有效的 BUKRS 编号
|
// 提取有效的 BUKRS 编号
|
||||||
List<String> existingNumbers = new ArrayList<>();
|
List<String> existingNumbers = new ArrayList<>();
|
||||||
if (dataArray != null) {
|
if (dataArray != null) {
|
||||||
|
// 将dataKey按"-"分割成多个部分
|
||||||
|
String[] keyParts = dataKey.split("-");
|
||||||
existingNumbers = dataArray.stream()
|
existingNumbers = dataArray.stream()
|
||||||
.filter(Objects::nonNull)
|
.filter(Objects::nonNull)
|
||||||
.map(dataJson -> ((JSONObject) dataJson).getString(dataKey))
|
.map(dataJson -> {
|
||||||
.filter(Objects::nonNull)
|
JSONObject jsonObject = (JSONObject) dataJson;
|
||||||
.map(String::trim) // 去除字符串首尾空格
|
// 根据每个部分逐级获取值并拼接
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
for (String part : keyParts) {
|
||||||
|
String value = jsonObject.getString(part);
|
||||||
|
if (value != null) {
|
||||||
|
if (sb.length() > 0) {
|
||||||
|
sb.append("-");
|
||||||
|
}
|
||||||
|
sb.append(value.trim());
|
||||||
|
} else {
|
||||||
|
// 如果某一部分为空,则整个值视为无效
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
})
|
||||||
|
.filter(Objects::nonNull) // 过滤掉无效值
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,4 +142,26 @@ public class ErpConfig {
|
|||||||
// 使用 Redis 更新缓存数据
|
// 使用 Redis 更新缓存数据
|
||||||
redisTemplate.opsForValue().set(key, allnumbers);
|
redisTemplate.opsForValue().set(key, allnumbers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<String> getRedisCache(String key) {
|
||||||
|
// 使用 Redis 更新缓存数据
|
||||||
|
return (List<String>)redisTemplate.opsForValue().get("erp"+key);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Map<String, String> numbersMap(String key) {
|
||||||
|
// 使用 Redis 获取缓存数据
|
||||||
|
Map<String, String> result = (Map<String, String>) redisTemplate.opsForValue().get(key);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// public void updateRedisCache(String key, List<String> allnumbers) {
|
||||||
|
// // 使用 Redis 更新缓存数据
|
||||||
|
// redisTemplate.opsForValue().set(key, allnumbers);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public List<String> getRedisCache(String key) {
|
||||||
|
// // 使用 Redis 更新缓存数据
|
||||||
|
// return (List<String>)redisTemplate.opsForValue().get("erp"+key);
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ public class OftenEnum {
|
|||||||
//接口编号枚举
|
//接口编号枚举
|
||||||
public enum FuncnrEnum {
|
public enum FuncnrEnum {
|
||||||
公司代码("001", "BUKRS", ""),
|
公司代码("001", "BUKRS", ""),
|
||||||
工厂信息("002", "", ""),
|
工厂信息("002", "WERKS", ""),
|
||||||
客商信息("003", "PARTNER", "DATUM"),
|
客商信息("003", "PARTNER", "DATUM"),
|
||||||
成本中心("004", "", ""),
|
成本中心("004", "", ""),
|
||||||
内部订单("005", "", ""),
|
内部订单("005", "", ""),
|
||||||
@@ -22,11 +22,11 @@ public class OftenEnum {
|
|||||||
采购组织("007", "", ""),
|
采购组织("007", "", ""),
|
||||||
销售组织("008", "", ""),
|
销售组织("008", "", ""),
|
||||||
合同信息("009", "", ""),
|
合同信息("009", "", ""),
|
||||||
资产卡片("010", "", ""),
|
资产卡片("010", "ANLN1-BUKRS", "ERDAT"),
|
||||||
库存信息("011", "", ""),
|
库存信息("011", "", ""),
|
||||||
辅组编码("012", "", ""),
|
辅组编码("012", "", ""),
|
||||||
生产订单("013", "", ""),
|
生产订单("013", "", ""),
|
||||||
BOM清单("014", "", ""),
|
BOM清单("014", "MATNR-STLAL-WERKS", ""),
|
||||||
工艺路线("015", "", ""),
|
工艺路线("015", "", ""),
|
||||||
生产版本("016", "", ""),
|
生产版本("016", "", ""),
|
||||||
生产投料("017", "", ""),
|
生产投料("017", "", ""),
|
||||||
|
|||||||
@@ -101,4 +101,11 @@ public class ErpAssetController {
|
|||||||
BeanUtils.toBean(list, ErpAssetRespVO.class));
|
BeanUtils.toBean(list, ErpAssetRespVO.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/getErpAssetTask")
|
||||||
|
@Operation(summary = "定时获得erp更新资产卡片")
|
||||||
|
@PreAuthorize("@ss.hasPermission('sply:erp-asset:query')")
|
||||||
|
public void getErpCompanyTask() {
|
||||||
|
erpAssetService.callErpRfcInterface();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -101,4 +101,11 @@ public class ErpBomController {
|
|||||||
BeanUtils.toBean(list, ErpBomRespVO.class));
|
BeanUtils.toBean(list, ErpBomRespVO.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/getErpBomTask")
|
||||||
|
@Operation(summary = "定时获得erp更新物料清单(BOM)")
|
||||||
|
@PreAuthorize("@ss.hasPermission('sply:erp-bom:query')")
|
||||||
|
public void getErpBomTask() {
|
||||||
|
erpBomService.callErpRfcInterface();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -101,4 +101,10 @@ public class ErpContractController {
|
|||||||
BeanUtils.toBean(list, ErpContractRespVO.class));
|
BeanUtils.toBean(list, ErpContractRespVO.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/getErpContractTask")
|
||||||
|
@Operation(summary = "定时获得erp更新合同")
|
||||||
|
@PreAuthorize("@ss.hasPermission('sply:erp-contract:query')")
|
||||||
|
public void getErpContractTask() {
|
||||||
|
erpContractService.callErpRfcInterface();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -101,4 +101,12 @@ public class ErpCostcenterController {
|
|||||||
BeanUtils.toBean(list, ErpCostcenterRespVO.class));
|
BeanUtils.toBean(list, ErpCostcenterRespVO.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/getErpCostcenterTask")
|
||||||
|
@Operation(summary = "定时获得erp更新成本中心")
|
||||||
|
@PreAuthorize("@ss.hasPermission('sply:erp-costcenter:query')")
|
||||||
|
public void getErpCostcenterTask() {
|
||||||
|
erpCostcenterService.callErpRfcInterface();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -101,4 +101,11 @@ public class ErpFactoryController {
|
|||||||
BeanUtils.toBean(list, ErpFactoryRespVO.class));
|
BeanUtils.toBean(list, ErpFactoryRespVO.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/getErpFactoryTask")
|
||||||
|
@Operation(summary = "定时获得erp工厂数据")
|
||||||
|
@PreAuthorize("@ss.hasPermission('sply:erp-factory:create')")
|
||||||
|
public void getErpFactoryTask() {
|
||||||
|
erpFactoryService.callErpRfcInterface();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -101,4 +101,11 @@ public class ErpInternalOrderController {
|
|||||||
BeanUtils.toBean(list, ErpInternalOrderRespVO.class));
|
BeanUtils.toBean(list, ErpInternalOrderRespVO.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/getErpInternalOrderTask")
|
||||||
|
@Operation(summary = "定时获得erp更新内部订单数据")
|
||||||
|
@PreAuthorize("@ss.hasPermission('sply:erp-internal-order:create')")
|
||||||
|
public void getErpInternalOrderTask() {
|
||||||
|
erpInternalOrderService.callErpRfcInterface();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -101,4 +101,11 @@ public class ErpProcessController {
|
|||||||
BeanUtils.toBean(list, ErpProcessRespVO.class));
|
BeanUtils.toBean(list, ErpProcessRespVO.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/getErpProcessTask")
|
||||||
|
@Operation(summary = "定时获得erp更新工艺路线")
|
||||||
|
@PreAuthorize("@ss.hasPermission('sply:erp-process:create')")
|
||||||
|
public void getErpProcessTask() {
|
||||||
|
erpProcessService.callErpRfcInterface();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -101,4 +101,11 @@ public class ErpProductiveOrderController {
|
|||||||
BeanUtils.toBean(list, ErpProductiveOrderRespVO.class));
|
BeanUtils.toBean(list, ErpProductiveOrderRespVO.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/getErpProductiveOrderTask")
|
||||||
|
@Operation(summary = "定时获得erp更新生产订单")
|
||||||
|
@PreAuthorize("@ss.hasPermission('sply:erp-productive-order:create')")
|
||||||
|
public void getErpProductiveOrderTask() {
|
||||||
|
erpProductiveOrderService.callErpRfcInterface();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -101,4 +101,11 @@ public class ErpProductiveVersionController {
|
|||||||
BeanUtils.toBean(list, ErpProductiveVersionRespVO.class));
|
BeanUtils.toBean(list, ErpProductiveVersionRespVO.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/getErpProductiveVersionTask")
|
||||||
|
@Operation(summary = "定时获得erp更新生产版本")
|
||||||
|
@PreAuthorize("@ss.hasPermission('sply:erp-productive-version:create')")
|
||||||
|
public void getErpProductiveVersionTask() {
|
||||||
|
erpProductiveVersionService.callErpRfcInterface();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -101,4 +101,11 @@ public class ErpPurchaseOrganizationController {
|
|||||||
BeanUtils.toBean(list, ErpPurchaseOrganizationRespVO.class));
|
BeanUtils.toBean(list, ErpPurchaseOrganizationRespVO.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/getErpPurchaseOrganizationTask")
|
||||||
|
@Operation(summary = "定时获得erp更新采购组织")
|
||||||
|
@PreAuthorize("@ss.hasPermission('sply:erp-purchase-organization:create')")
|
||||||
|
public void getErpPurchaseOrganizationTask() {
|
||||||
|
erpPurchaseOrganizationService.callErpRfcInterface();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -101,4 +101,11 @@ public class ErpSalesOrganizationController {
|
|||||||
BeanUtils.toBean(list, ErpSalesOrganizationRespVO.class));
|
BeanUtils.toBean(list, ErpSalesOrganizationRespVO.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/getErpSalesOrganizationTask")
|
||||||
|
@Operation(summary = "定时获得erp更新销售组织")
|
||||||
|
@PreAuthorize("@ss.hasPermission('sply:erp-sales-organization:create')")
|
||||||
|
public void getErpSalesOrganizationTask() {
|
||||||
|
erpSalesOrganizationService.callErpRfcInterface();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -101,4 +101,11 @@ public class ErpWarehouseController {
|
|||||||
BeanUtils.toBean(list, ErpWarehouseRespVO.class));
|
BeanUtils.toBean(list, ErpWarehouseRespVO.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/getErpWarehouseTask")
|
||||||
|
@Operation(summary = "定时获得erp更新库位")
|
||||||
|
@PreAuthorize("@ss.hasPermission('sply:erp-warehouse:create')")
|
||||||
|
public void getErpWarehouseTask() {
|
||||||
|
erpWarehouseService.callErpRfcInterface();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -54,8 +54,7 @@ public class ErpAssetPageReqVO extends PageParam {
|
|||||||
private LocalDateTime[] depreciationStartDate;
|
private LocalDateTime[] depreciationStartDate;
|
||||||
|
|
||||||
@Schema(description = "计划年使用期")
|
@Schema(description = "计划年使用期")
|
||||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
private String planYearDate;
|
||||||
private LocalDateTime[] planYearDate;
|
|
||||||
|
|
||||||
@Schema(description = "成本中心编码")
|
@Schema(description = "成本中心编码")
|
||||||
private String costcenterNumber;
|
private String costcenterNumber;
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ public class ErpAssetRespVO {
|
|||||||
|
|
||||||
@Schema(description = "计划年使用期")
|
@Schema(description = "计划年使用期")
|
||||||
@ExcelProperty("计划年使用期")
|
@ExcelProperty("计划年使用期")
|
||||||
private LocalDateTime planYearDate;
|
private String planYearDate;
|
||||||
|
|
||||||
@Schema(description = "成本中心编码")
|
@Schema(description = "成本中心编码")
|
||||||
@ExcelProperty("成本中心编码")
|
@ExcelProperty("成本中心编码")
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ public class ErpAssetSaveReqVO {
|
|||||||
private LocalDateTime depreciationStartDate;
|
private LocalDateTime depreciationStartDate;
|
||||||
|
|
||||||
@Schema(description = "计划年使用期")
|
@Schema(description = "计划年使用期")
|
||||||
private LocalDateTime planYearDate;
|
private String planYearDate;
|
||||||
|
|
||||||
@Schema(description = "成本中心编码")
|
@Schema(description = "成本中心编码")
|
||||||
private String costcenterNumber;
|
private String costcenterNumber;
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import java.math.BigDecimal;
|
|||||||
public class ErpBomPageReqVO extends PageParam {
|
public class ErpBomPageReqVO extends PageParam {
|
||||||
|
|
||||||
@Schema(description = "工厂编码")
|
@Schema(description = "工厂编码")
|
||||||
private BigDecimal factoryNumber;
|
private String factoryNumber;
|
||||||
|
|
||||||
@Schema(description = "顶层物料编码")
|
@Schema(description = "顶层物料编码")
|
||||||
private String upMaterial;
|
private String upMaterial;
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ public class ErpBomRespVO {
|
|||||||
|
|
||||||
@Schema(description = "工厂编码", requiredMode = Schema.RequiredMode.REQUIRED)
|
@Schema(description = "工厂编码", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
@ExcelProperty("工厂编码")
|
@ExcelProperty("工厂编码")
|
||||||
private BigDecimal factoryNumber;
|
private String factoryNumber;
|
||||||
|
|
||||||
@Schema(description = "顶层物料编码", requiredMode = Schema.RequiredMode.REQUIRED)
|
@Schema(description = "顶层物料编码", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
@ExcelProperty("顶层物料编码")
|
@ExcelProperty("顶层物料编码")
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ public class ErpBomSaveReqVO {
|
|||||||
|
|
||||||
@Schema(description = "工厂编码", requiredMode = Schema.RequiredMode.REQUIRED)
|
@Schema(description = "工厂编码", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
@NotNull(message = "工厂编码不能为空")
|
@NotNull(message = "工厂编码不能为空")
|
||||||
private BigDecimal factoryNumber;
|
private String factoryNumber;
|
||||||
|
|
||||||
@Schema(description = "顶层物料编码", requiredMode = Schema.RequiredMode.REQUIRED)
|
@Schema(description = "顶层物料编码", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
@NotEmpty(message = "顶层物料编码不能为空")
|
@NotEmpty(message = "顶层物料编码不能为空")
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import java.time.LocalDateTime;
|
|||||||
@TableName("sply_erp_ast")
|
@TableName("sply_erp_ast")
|
||||||
@KeySequence("sply_erp_ast_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
@KeySequence("sply_erp_ast_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode
|
||||||
@ToString(callSuper = true)
|
@ToString(callSuper = true)
|
||||||
@Builder
|
@Builder
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@@ -22,7 +22,7 @@ import java.time.LocalDateTime;
|
|||||||
/**
|
/**
|
||||||
* 支持业务基类继承:isBusiness=true 时继承 BusinessBaseDO,否则继承 BaseDO
|
* 支持业务基类继承:isBusiness=true 时继承 BusinessBaseDO,否则继承 BaseDO
|
||||||
*/
|
*/
|
||||||
public class ErpAssetDO extends BaseDO {
|
public class ErpAssetDO{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -95,7 +95,7 @@ public class ErpAssetDO extends BaseDO {
|
|||||||
* 计划年使用期
|
* 计划年使用期
|
||||||
*/
|
*/
|
||||||
@TableField("PLN_YR_DT")
|
@TableField("PLN_YR_DT")
|
||||||
private LocalDateTime planYearDate;
|
private String planYearDate;
|
||||||
/**
|
/**
|
||||||
* 成本中心编码
|
* 成本中心编码
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import com.baomidou.mybatisplus.annotation.*;
|
|||||||
import lombok.*;
|
import lombok.*;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ERP物料清单(BOM) DO
|
* ERP物料清单(BOM) DO
|
||||||
*
|
*
|
||||||
@@ -13,7 +15,7 @@ import java.math.BigDecimal;
|
|||||||
@TableName("sply_erp_bm")
|
@TableName("sply_erp_bm")
|
||||||
@KeySequence("sply_erp_bm_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
@KeySequence("sply_erp_bm_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode
|
||||||
@ToString(callSuper = true)
|
@ToString(callSuper = true)
|
||||||
@Builder
|
@Builder
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@@ -21,9 +23,7 @@ import java.math.BigDecimal;
|
|||||||
/**
|
/**
|
||||||
* 支持业务基类继承:isBusiness=true 时继承 BusinessBaseDO,否则继承 BaseDO
|
* 支持业务基类继承:isBusiness=true 时继承 BusinessBaseDO,否则继承 BaseDO
|
||||||
*/
|
*/
|
||||||
public class ErpBomDO extends BaseDO {
|
public class ErpBomDO {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 主键
|
* 主键
|
||||||
@@ -34,7 +34,7 @@ public class ErpBomDO extends BaseDO {
|
|||||||
* 工厂编码
|
* 工厂编码
|
||||||
*/
|
*/
|
||||||
@TableField("FACT_NUM")
|
@TableField("FACT_NUM")
|
||||||
private BigDecimal factoryNumber;
|
private String factoryNumber;
|
||||||
/**
|
/**
|
||||||
* 顶层物料编码
|
* 顶层物料编码
|
||||||
*/
|
*/
|
||||||
@@ -61,4 +61,7 @@ public class ErpBomDO extends BaseDO {
|
|||||||
@TableField("UNT")
|
@TableField("UNT")
|
||||||
private String unit;
|
private String unit;
|
||||||
|
|
||||||
|
@TableField(fill = FieldFill.INSERT)
|
||||||
|
private List<ErpBomDetailDO> erpBomDetailDOList;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -13,7 +13,7 @@ import java.math.BigDecimal;
|
|||||||
@TableName("sply_erp_bm_dtl")
|
@TableName("sply_erp_bm_dtl")
|
||||||
@KeySequence("sply_erp_bm_dtl_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
@KeySequence("sply_erp_bm_dtl_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode
|
||||||
@ToString(callSuper = true)
|
@ToString(callSuper = true)
|
||||||
@Builder
|
@Builder
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@@ -21,7 +21,7 @@ import java.math.BigDecimal;
|
|||||||
/**
|
/**
|
||||||
* 支持业务基类继承:isBusiness=true 时继承 BusinessBaseDO,否则继承 BaseDO
|
* 支持业务基类继承:isBusiness=true 时继承 BusinessBaseDO,否则继承 BaseDO
|
||||||
*/
|
*/
|
||||||
public class ErpBomDetailDO extends BaseDO {
|
public class ErpBomDetailDO {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import java.time.LocalDateTime;
|
|||||||
@TableName("sply_erp_cctr")
|
@TableName("sply_erp_cctr")
|
||||||
@KeySequence("sply_erp_cctr_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
@KeySequence("sply_erp_cctr_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode
|
||||||
@ToString(callSuper = true)
|
@ToString(callSuper = true)
|
||||||
@Builder
|
@Builder
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@@ -21,7 +21,7 @@ import java.time.LocalDateTime;
|
|||||||
/**
|
/**
|
||||||
* 支持业务基类继承:isBusiness=true 时继承 BusinessBaseDO,否则继承 BaseDO
|
* 支持业务基类继承:isBusiness=true 时继承 BusinessBaseDO,否则继承 BaseDO
|
||||||
*/
|
*/
|
||||||
public class ErpCostcenterDO extends BaseDO {
|
public class ErpCostcenterDO {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import lombok.*;
|
|||||||
@TableName("sply_erp_fact")
|
@TableName("sply_erp_fact")
|
||||||
@KeySequence("sply_erp_fact_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
@KeySequence("sply_erp_fact_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode
|
||||||
@ToString(callSuper = true)
|
@ToString(callSuper = true)
|
||||||
@Builder
|
@Builder
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@@ -19,7 +19,7 @@ import lombok.*;
|
|||||||
/**
|
/**
|
||||||
* 支持业务基类继承:isBusiness=true 时继承 BusinessBaseDO,否则继承 BaseDO
|
* 支持业务基类继承:isBusiness=true 时继承 BusinessBaseDO,否则继承 BaseDO
|
||||||
*/
|
*/
|
||||||
public class ErpFactoryDO extends BaseDO {
|
public class ErpFactoryDO {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -42,6 +42,6 @@ public class ErpFactoryDO extends BaseDO {
|
|||||||
* 公司编号
|
* 公司编号
|
||||||
*/
|
*/
|
||||||
@TableField("CPN_ID")
|
@TableField("CPN_ID")
|
||||||
private Long companyId;
|
private String companyId;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -11,7 +11,7 @@ import lombok.*;
|
|||||||
@TableName("sply_erp_intl_ord")
|
@TableName("sply_erp_intl_ord")
|
||||||
@KeySequence("sply_erp_intl_ord_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
@KeySequence("sply_erp_intl_ord_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode
|
||||||
@ToString(callSuper = true)
|
@ToString(callSuper = true)
|
||||||
@Builder
|
@Builder
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@@ -19,7 +19,7 @@ import lombok.*;
|
|||||||
/**
|
/**
|
||||||
* 支持业务基类继承:isBusiness=true 时继承 BusinessBaseDO,否则继承 BaseDO
|
* 支持业务基类继承:isBusiness=true 时继承 BusinessBaseDO,否则继承 BaseDO
|
||||||
*/
|
*/
|
||||||
public class ErpInternalOrderDO extends BaseDO {
|
public class ErpInternalOrderDO {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import java.math.BigDecimal;
|
|||||||
@TableName("sply_erp_prcs")
|
@TableName("sply_erp_prcs")
|
||||||
@KeySequence("sply_erp_prcs_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
@KeySequence("sply_erp_prcs_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode
|
||||||
@ToString(callSuper = true)
|
@ToString(callSuper = true)
|
||||||
@Builder
|
@Builder
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@@ -21,7 +21,7 @@ import java.math.BigDecimal;
|
|||||||
/**
|
/**
|
||||||
* 支持业务基类继承:isBusiness=true 时继承 BusinessBaseDO,否则继承 BaseDO
|
* 支持业务基类继承:isBusiness=true 时继承 BusinessBaseDO,否则继承 BaseDO
|
||||||
*/
|
*/
|
||||||
public class ErpProcessDO extends BaseDO {
|
public class ErpProcessDO {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import java.math.BigDecimal;
|
|||||||
@TableName("sply_erp_prcs_dtl")
|
@TableName("sply_erp_prcs_dtl")
|
||||||
@KeySequence("sply_erp_prcs_dtl_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
@KeySequence("sply_erp_prcs_dtl_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode
|
||||||
@ToString(callSuper = true)
|
@ToString(callSuper = true)
|
||||||
@Builder
|
@Builder
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@@ -21,7 +21,7 @@ import java.math.BigDecimal;
|
|||||||
/**
|
/**
|
||||||
* 支持业务基类继承:isBusiness=true 时继承 BusinessBaseDO,否则继承 BaseDO
|
* 支持业务基类继承:isBusiness=true 时继承 BusinessBaseDO,否则继承 BaseDO
|
||||||
*/
|
*/
|
||||||
public class ErpProcessDetailDO extends BaseDO {
|
public class ErpProcessDetailDO {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import java.time.LocalDateTime;
|
|||||||
@TableName("sply_erp_pdtv_ord")
|
@TableName("sply_erp_pdtv_ord")
|
||||||
@KeySequence("sply_erp_pdtv_ord_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
@KeySequence("sply_erp_pdtv_ord_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode
|
||||||
@ToString(callSuper = true)
|
@ToString(callSuper = true)
|
||||||
@Builder
|
@Builder
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@@ -21,7 +21,7 @@ import java.time.LocalDateTime;
|
|||||||
/**
|
/**
|
||||||
* 支持业务基类继承:isBusiness=true 时继承 BusinessBaseDO,否则继承 BaseDO
|
* 支持业务基类继承:isBusiness=true 时继承 BusinessBaseDO,否则继承 BaseDO
|
||||||
*/
|
*/
|
||||||
public class ErpProductiveOrderDO extends BaseDO {
|
public class ErpProductiveOrderDO{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import java.math.BigDecimal;
|
|||||||
@TableName("sply_erp_pdtv_ver")
|
@TableName("sply_erp_pdtv_ver")
|
||||||
@KeySequence("sply_erp_pdtv_ver_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
@KeySequence("sply_erp_pdtv_ver_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode
|
||||||
@ToString(callSuper = true)
|
@ToString(callSuper = true)
|
||||||
@Builder
|
@Builder
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@@ -21,7 +21,7 @@ import java.math.BigDecimal;
|
|||||||
/**
|
/**
|
||||||
* 支持业务基类继承:isBusiness=true 时继承 BusinessBaseDO,否则继承 BaseDO
|
* 支持业务基类继承:isBusiness=true 时继承 BusinessBaseDO,否则继承 BaseDO
|
||||||
*/
|
*/
|
||||||
public class ErpProductiveVersionDO extends BaseDO {
|
public class ErpProductiveVersionDO {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import lombok.*;
|
|||||||
@TableName("sply_erp_prch_orgz")
|
@TableName("sply_erp_prch_orgz")
|
||||||
@KeySequence("sply_erp_prch_orgz_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
@KeySequence("sply_erp_prch_orgz_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode
|
||||||
@ToString(callSuper = true)
|
@ToString(callSuper = true)
|
||||||
@Builder
|
@Builder
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@@ -19,7 +19,7 @@ import lombok.*;
|
|||||||
/**
|
/**
|
||||||
* 支持业务基类继承:isBusiness=true 时继承 BusinessBaseDO,否则继承 BaseDO
|
* 支持业务基类继承:isBusiness=true 时继承 BusinessBaseDO,否则继承 BaseDO
|
||||||
*/
|
*/
|
||||||
public class ErpPurchaseOrganizationDO extends BaseDO {
|
public class ErpPurchaseOrganizationDO {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import lombok.*;
|
|||||||
@TableName("sply_erp_sale_orgz")
|
@TableName("sply_erp_sale_orgz")
|
||||||
@KeySequence("sply_erp_sale_orgz_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
@KeySequence("sply_erp_sale_orgz_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode
|
||||||
@ToString(callSuper = true)
|
@ToString(callSuper = true)
|
||||||
@Builder
|
@Builder
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@@ -19,7 +19,7 @@ import lombok.*;
|
|||||||
/**
|
/**
|
||||||
* 支持业务基类继承:isBusiness=true 时继承 BusinessBaseDO,否则继承 BaseDO
|
* 支持业务基类继承:isBusiness=true 时继承 BusinessBaseDO,否则继承 BaseDO
|
||||||
*/
|
*/
|
||||||
public class ErpSalesOrganizationDO extends BaseDO {
|
public class ErpSalesOrganizationDO {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ public interface ErpAssetMapper extends BaseMapperX<ErpAssetDO> {
|
|||||||
.eqIfPresent(ErpAssetDO::getAssetDescription, reqVO.getAssetDescription())
|
.eqIfPresent(ErpAssetDO::getAssetDescription, reqVO.getAssetDescription())
|
||||||
.eqIfPresent(ErpAssetDO::getAssetDescriptionAttach, reqVO.getAssetDescriptionAttach())
|
.eqIfPresent(ErpAssetDO::getAssetDescriptionAttach, reqVO.getAssetDescriptionAttach())
|
||||||
.betweenIfPresent(ErpAssetDO::getDepreciationStartDate, reqVO.getDepreciationStartDate())
|
.betweenIfPresent(ErpAssetDO::getDepreciationStartDate, reqVO.getDepreciationStartDate())
|
||||||
.betweenIfPresent(ErpAssetDO::getPlanYearDate, reqVO.getPlanYearDate())
|
.eqIfPresent(ErpAssetDO::getPlanYearDate, reqVO.getPlanYearDate())
|
||||||
.eqIfPresent(ErpAssetDO::getCostcenterNumber, reqVO.getCostcenterNumber())
|
.eqIfPresent(ErpAssetDO::getCostcenterNumber, reqVO.getCostcenterNumber())
|
||||||
.eqIfPresent(ErpAssetDO::getDutyCostcenterNumber, reqVO.getDutyCostcenterNumber())
|
.eqIfPresent(ErpAssetDO::getDutyCostcenterNumber, reqVO.getDutyCostcenterNumber())
|
||||||
.orderByDesc(ErpAssetDO::getId));
|
.orderByDesc(ErpAssetDO::getId));
|
||||||
|
|||||||
@@ -5,7 +5,11 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
|||||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||||
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpFactoryPageReqVO;
|
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpFactoryPageReqVO;
|
||||||
import cn.iocoder.yudao.module.erp.dal.dataobject.erp.ErpFactoryDO;
|
import cn.iocoder.yudao.module.erp.dal.dataobject.erp.ErpFactoryDO;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ERP工厂 Mapper
|
* ERP工厂 Mapper
|
||||||
@@ -22,4 +26,6 @@ public interface ErpFactoryMapper extends BaseMapperX<ErpFactoryDO> {
|
|||||||
.orderByDesc(ErpFactoryDO::getId));
|
.orderByDesc(ErpFactoryDO::getId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void updateBatch(@Param("toUpdate") List<ErpFactoryDO> toUpdate);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -61,4 +61,5 @@ public interface ErpAssetService {
|
|||||||
*/
|
*/
|
||||||
PageResult<ErpAssetDO> getErpAssetPage(ErpAssetPageReqVO pageReqVO);
|
PageResult<ErpAssetDO> getErpAssetPage(ErpAssetPageReqVO pageReqVO);
|
||||||
|
|
||||||
|
void callErpRfcInterface();
|
||||||
}
|
}
|
||||||
@@ -3,19 +3,31 @@ package cn.iocoder.yudao.module.erp.service.erp;
|
|||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||||
|
import cn.iocoder.yudao.module.erp.common.conf.ErpConfig;
|
||||||
|
import cn.iocoder.yudao.module.erp.common.enums.OftenEnum;
|
||||||
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpAssetPageReqVO;
|
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpAssetPageReqVO;
|
||||||
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpAssetRespVO;
|
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpAssetRespVO;
|
||||||
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpAssetSaveReqVO;
|
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpAssetSaveReqVO;
|
||||||
import cn.iocoder.yudao.module.erp.dal.dataobject.erp.ErpAssetDO;
|
import cn.iocoder.yudao.module.erp.dal.dataobject.erp.ErpAssetDO;
|
||||||
import cn.iocoder.yudao.module.erp.dal.mysql.erp.ErpAssetMapper;
|
import cn.iocoder.yudao.module.erp.dal.mysql.erp.ErpAssetMapper;
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.xxl.job.core.handler.annotation.XxlJob;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.ERP_ASSET_NOT_EXISTS;
|
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.ERP_ASSET_NOT_EXISTS;
|
||||||
|
import static dm.jdbc.util.DriverUtil.log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ERP资产卡片 Service 实现类
|
* ERP资产卡片 Service 实现类
|
||||||
@@ -29,6 +41,9 @@ public class ErpAssetServiceImpl implements ErpAssetService {
|
|||||||
@Resource
|
@Resource
|
||||||
private ErpAssetMapper erpAssetMapper;
|
private ErpAssetMapper erpAssetMapper;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ErpConfig erpConfig;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ErpAssetRespVO createErpAsset(ErpAssetSaveReqVO createReqVO) {
|
public ErpAssetRespVO createErpAsset(ErpAssetSaveReqVO createReqVO) {
|
||||||
// 插入
|
// 插入
|
||||||
@@ -86,4 +101,128 @@ public class ErpAssetServiceImpl implements ErpAssetService {
|
|||||||
return erpAssetMapper.selectPage(pageReqVO);
|
return erpAssetMapper.selectPage(pageReqVO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
@XxlJob("getErpAssetTask")
|
||||||
|
public void callErpRfcInterface() {
|
||||||
|
try {
|
||||||
|
OftenEnum.FuncnrEnum funcnrEnum = OftenEnum.FuncnrEnum.资产卡片;
|
||||||
|
String funcnr = funcnrEnum.getFuncnr();
|
||||||
|
// 构建req参数
|
||||||
|
Map<String, Object> req = new HashMap<>();
|
||||||
|
List<Map<String, String>> datumList = new ArrayList<>();
|
||||||
|
Map<String, String> datumEntry = new HashMap<>();
|
||||||
|
datumEntry.put("sign", "I");
|
||||||
|
datumEntry.put("option", "EQ");
|
||||||
|
datumEntry.put("low", LocalDate.now().toString());
|
||||||
|
datumList.add(datumEntry);
|
||||||
|
req.put(funcnrEnum.getDatekey(), datumList);
|
||||||
|
|
||||||
|
JSONArray dataArrayALL = new JSONArray();
|
||||||
|
List<String> redisCache = erpConfig.getRedisCache(OftenEnum.FuncnrEnum.公司代码.getFuncnr());
|
||||||
|
if (CollUtil.isEmpty(redisCache)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (String number : redisCache) {
|
||||||
|
req.put("BUKRS", number);
|
||||||
|
// 1. 调用ERP接口获取数据
|
||||||
|
JSONArray dataArray = erpConfig.fetchDataFromERP(funcnr, req);
|
||||||
|
if (dataArray == null || dataArray.isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
dataArrayALL.addAll(dataArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 处理公司数据,区分新增和更新
|
||||||
|
ProcessingResult result = processData(dataArrayALL, funcnrEnum);
|
||||||
|
|
||||||
|
// 3. 批量保存数据
|
||||||
|
saveData(result);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("调用ERP RFC接口失败: {}", e);
|
||||||
|
throw new RuntimeException("调用ERP RFC接口失败: " + e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理数据,区分新增和更新
|
||||||
|
*/
|
||||||
|
private ProcessingResult processData(JSONArray dataArray, OftenEnum.FuncnrEnum funcnr) {
|
||||||
|
String key = "erp" + funcnr.getFuncnr();
|
||||||
|
Map<String, List<String>> numbers = erpConfig.numbers(dataArray, key, funcnr.getDatakey());
|
||||||
|
List<String> allnumbers = numbers.get("all");
|
||||||
|
List<String> comnumbers = numbers.get("com");
|
||||||
|
List<ErpAssetDO> toUpdate = new ArrayList<>();
|
||||||
|
List<ErpAssetDO> toInsert = new ArrayList<>();
|
||||||
|
|
||||||
|
for (int i = 0; i < dataArray.size(); i++) {
|
||||||
|
JSONObject dataJson = dataArray.getJSONObject(i);
|
||||||
|
if (dataJson != null) {
|
||||||
|
ErpAssetDO DO = new ErpAssetDO();
|
||||||
|
DO.setCompanyNumber(dataJson.getString("BUKRS"));
|
||||||
|
DO.setMainAssetNumber(dataJson.getString("ANLN1"));
|
||||||
|
if (!dataJson.getString("ERDAT").equals("0000-00-00")) {
|
||||||
|
DO.setRecordCreateDate(LocalDateTime.parse(dataJson.getString("ERDAT") + "T00:00:00"));
|
||||||
|
}
|
||||||
|
DO.setUpdateUserName(dataJson.getString("ERNAM"));
|
||||||
|
DO.setAssetTypeNumber(dataJson.getString("ANLKL"));
|
||||||
|
DO.setAssetTypeName(dataJson.getString("TXK20"));
|
||||||
|
if (!dataJson.getString("AKTIV").equals("0000-00-00")) {
|
||||||
|
DO.setAssetDate(LocalDateTime.parse(dataJson.getString("AKTIV") + "T00:00:00"));
|
||||||
|
}
|
||||||
|
DO.setUom(dataJson.getString("MEINS"));
|
||||||
|
DO.setQuantity(dataJson.getBigDecimal("MENGE"));
|
||||||
|
DO.setAssetDescription(dataJson.getString("TXT50"));
|
||||||
|
DO.setAssetDescriptionAttach(dataJson.getString("TXA50"));
|
||||||
|
if (!dataJson.getString("AFABG").equals("0000-00-00")) {
|
||||||
|
DO.setDepreciationStartDate(LocalDateTime.parse(dataJson.getString("AFABG") + "T00:00:00"));
|
||||||
|
}
|
||||||
|
DO.setPlanYearDate(dataJson.getString("NDJAR"));
|
||||||
|
DO.setCostcenterNumber(dataJson.getString("KOSTL"));
|
||||||
|
DO.setDutyCostcenterNumber(dataJson.getString("KOSTLV"));
|
||||||
|
if (comnumbers.contains(DO.getMainAssetNumber()+"-"+DO.getCompanyNumber())) {
|
||||||
|
// 更新
|
||||||
|
toUpdate.add(DO);
|
||||||
|
} else {
|
||||||
|
// 新增
|
||||||
|
toInsert.add(DO);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ProcessingResult(toUpdate, toInsert, key, allnumbers);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量保存数据
|
||||||
|
*/
|
||||||
|
private void saveData(ProcessingResult result) {
|
||||||
|
// 批量新增和更新
|
||||||
|
if (!result.toInsert.isEmpty()) {
|
||||||
|
erpAssetMapper.insertBatch(result.toInsert);
|
||||||
|
}
|
||||||
|
if (!result.toUpdate.isEmpty()) {
|
||||||
|
erpAssetMapper.updateBatch(result.toUpdate);
|
||||||
|
}
|
||||||
|
erpConfig.updateRedisCache(result.key, result.allnumbers);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据处理结果封装类
|
||||||
|
*/
|
||||||
|
private static class ProcessingResult {
|
||||||
|
private final List<ErpAssetDO> toUpdate;
|
||||||
|
private final List<ErpAssetDO> toInsert;
|
||||||
|
private final String key;
|
||||||
|
private final List<String> allnumbers;
|
||||||
|
|
||||||
|
public ProcessingResult(List<ErpAssetDO> toUpdate, List<ErpAssetDO> toInsert, String key, List<String> allnumbers) {
|
||||||
|
this.toUpdate = toUpdate;
|
||||||
|
this.toInsert = toInsert;
|
||||||
|
this.key = key;
|
||||||
|
this.allnumbers = allnumbers;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -61,4 +61,5 @@ public interface ErpBomService {
|
|||||||
*/
|
*/
|
||||||
PageResult<ErpBomDO> getErpBomPage(ErpBomPageReqVO pageReqVO);
|
PageResult<ErpBomDO> getErpBomPage(ErpBomPageReqVO pageReqVO);
|
||||||
|
|
||||||
|
void callErpRfcInterface();
|
||||||
}
|
}
|
||||||
@@ -3,19 +3,31 @@ package cn.iocoder.yudao.module.erp.service.erp;
|
|||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||||
|
import cn.iocoder.yudao.module.erp.common.conf.ErpConfig;
|
||||||
|
import cn.iocoder.yudao.module.erp.common.enums.OftenEnum;
|
||||||
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpBomPageReqVO;
|
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpBomPageReqVO;
|
||||||
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpBomRespVO;
|
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpBomRespVO;
|
||||||
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpBomSaveReqVO;
|
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpBomSaveReqVO;
|
||||||
import cn.iocoder.yudao.module.erp.dal.dataobject.erp.ErpBomDO;
|
import cn.iocoder.yudao.module.erp.dal.dataobject.erp.ErpBomDO;
|
||||||
|
import cn.iocoder.yudao.module.erp.dal.dataobject.erp.ErpBomDO;
|
||||||
|
import cn.iocoder.yudao.module.erp.dal.dataobject.erp.ErpBomDetailDO;
|
||||||
import cn.iocoder.yudao.module.erp.dal.mysql.erp.ErpBomMapper;
|
import cn.iocoder.yudao.module.erp.dal.mysql.erp.ErpBomMapper;
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.xxl.job.core.handler.annotation.XxlJob;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.ERP_BOM_NOT_EXISTS;
|
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.ERP_BOM_NOT_EXISTS;
|
||||||
|
import static dm.jdbc.util.DriverUtil.log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ERP物料清单(BOM) Service 实现类
|
* ERP物料清单(BOM) Service 实现类
|
||||||
@@ -29,6 +41,9 @@ public class ErpBomServiceImpl implements ErpBomService {
|
|||||||
@Resource
|
@Resource
|
||||||
private ErpBomMapper erpBomMapper;
|
private ErpBomMapper erpBomMapper;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ErpConfig erpConfig;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ErpBomRespVO createErpBom(ErpBomSaveReqVO createReqVO) {
|
public ErpBomRespVO createErpBom(ErpBomSaveReqVO createReqVO) {
|
||||||
// 插入
|
// 插入
|
||||||
@@ -86,4 +101,131 @@ public class ErpBomServiceImpl implements ErpBomService {
|
|||||||
return erpBomMapper.selectPage(pageReqVO);
|
return erpBomMapper.selectPage(pageReqVO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
@XxlJob("getErpBomTask")
|
||||||
|
public void callErpRfcInterface() {
|
||||||
|
try {
|
||||||
|
OftenEnum.FuncnrEnum funcnrEnum = OftenEnum.FuncnrEnum.BOM清单;
|
||||||
|
String funcnr = funcnrEnum.getFuncnr();
|
||||||
|
Map<String, Object> req = new HashMap<>();
|
||||||
|
JSONArray dataArrayALL = new JSONArray();
|
||||||
|
List<String> redisCache = erpConfig.getRedisCache(OftenEnum.FuncnrEnum.工厂信息.getFuncnr());
|
||||||
|
if (CollUtil.isEmpty(redisCache)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (String factoryNumber : redisCache) {
|
||||||
|
req.put("WERKS", factoryNumber);
|
||||||
|
// 1. 调用ERP接口获取数据
|
||||||
|
JSONArray dataArray = erpConfig.fetchDataFromERP(funcnr, req);
|
||||||
|
if (dataArray == null || dataArray.isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
dataArrayALL.addAll(dataArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 处理公司数据,区分新增和更新
|
||||||
|
ProcessingResult result = processData(dataArrayALL, funcnrEnum);
|
||||||
|
|
||||||
|
// 3. 批量保存数据
|
||||||
|
saveData(result);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("调用ERP RFC接口失败: {}", e);
|
||||||
|
throw new RuntimeException("调用ERP RFC接口失败: " + e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理数据,区分新增和更新
|
||||||
|
*/
|
||||||
|
private ProcessingResult processData(JSONArray dataArray, OftenEnum.FuncnrEnum funcnr) {
|
||||||
|
String key = "erp" + funcnr.getFuncnr();
|
||||||
|
Map<String, String> numbers = erpConfig.numbersMap(key);
|
||||||
|
Map<String, String> numberDels = erpConfig.numbersMap(key+"del");
|
||||||
|
List<ErpBomDO> toUpdate = new ArrayList<>();
|
||||||
|
List<ErpBomDO> toInsert = new ArrayList<>();
|
||||||
|
|
||||||
|
List<String> allnumbers = new ArrayList<>();
|
||||||
|
for (int i = 0; i < dataArray.size(); i++) {
|
||||||
|
JSONObject dataJson = dataArray.getJSONObject(i);
|
||||||
|
if (dataJson != null) {
|
||||||
|
ErpBomDO DO = new ErpBomDO();
|
||||||
|
DO.setFactoryNumber(dataJson.getString("WERKS"));
|
||||||
|
DO.setUpMaterial(dataJson.getString("MATNR"));
|
||||||
|
DO.setUseItem(dataJson.getString("STLAL"));
|
||||||
|
// DO.set(dataJson.getString("STLAN"));数据库无这个字段
|
||||||
|
DO.setMaterialDescription(dataJson.getString("MAKTX"));
|
||||||
|
DO.setQuantity(dataJson.getBigDecimal("BMENG"));
|
||||||
|
DO.setUnit(dataJson.getString("BMEIN"));
|
||||||
|
String number =DO.getUpMaterial()+"-"+DO.getUseItem()+"-"+DO.getFactoryNumber();
|
||||||
|
String domId = null;
|
||||||
|
if (numbers.get(number)!=null) {
|
||||||
|
// 更新
|
||||||
|
domId = numbers.get(number);
|
||||||
|
DO.setId(Long.valueOf(domId));
|
||||||
|
toUpdate.add(DO);
|
||||||
|
} else {
|
||||||
|
// 新增
|
||||||
|
toInsert.add(DO);
|
||||||
|
}
|
||||||
|
|
||||||
|
JSONArray dataJsonItem = dataJson.getJSONArray("ITEM");
|
||||||
|
if (dataJsonItem != null) {
|
||||||
|
List<ErpBomDetailDO> erpBomDetailDOList =new ArrayList<>();
|
||||||
|
for (int j = 0; j < dataJsonItem.size(); j++){
|
||||||
|
JSONObject dataJsonItemJson = dataJsonItem.getJSONObject(j);
|
||||||
|
ErpBomDetailDO detailDO = new ErpBomDetailDO();
|
||||||
|
String numberDel = number+dataJsonItemJson.getString("STVKN");
|
||||||
|
if (numberDels.get( numberDel) != null){
|
||||||
|
detailDO.setId(Long.valueOf(numberDels.get( numberDel)));
|
||||||
|
}
|
||||||
|
detailDO.setBomId(domId);
|
||||||
|
detailDO.setErpBomId(dataJsonItemJson.getString("STVKN"));
|
||||||
|
detailDO.setErpBomId(dataJsonItemJson.getString("IDNRK"));
|
||||||
|
detailDO.setErpBomId(dataJsonItemJson.getString("OJTXP"));
|
||||||
|
detailDO.setErpBomId(dataJsonItemJson.getString("POSTP"));
|
||||||
|
detailDO.setErpBomId(dataJsonItemJson.getString("MENGE"));
|
||||||
|
detailDO.setErpBomId(dataJsonItemJson.getString("MEINS"));
|
||||||
|
detailDO.setErpBomId(dataJsonItemJson.getString("WLCAT"));
|
||||||
|
erpBomDetailDOList.add(detailDO);
|
||||||
|
}
|
||||||
|
DO.setErpBomDetailDOList(erpBomDetailDOList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ProcessingResult(toUpdate, toInsert, key, allnumbers);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量保存数据
|
||||||
|
*/
|
||||||
|
private void saveData(ProcessingResult result) {
|
||||||
|
// 批量新增和更新
|
||||||
|
if (!result.toInsert.isEmpty()) {
|
||||||
|
erpBomMapper.insertBatch(result.toInsert);
|
||||||
|
}
|
||||||
|
if (!result.toUpdate.isEmpty()) {
|
||||||
|
erpBomMapper.updateBatch(result.toUpdate);
|
||||||
|
}
|
||||||
|
erpConfig.updateRedisCache(result.key, result.allnumbers);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据处理结果封装类
|
||||||
|
*/
|
||||||
|
private static class ProcessingResult {
|
||||||
|
private final List<ErpBomDO> toUpdate;
|
||||||
|
private final List<ErpBomDO> toInsert;
|
||||||
|
private final String key;
|
||||||
|
private final List<String> allnumbers;
|
||||||
|
|
||||||
|
public ProcessingResult(List<ErpBomDO> toUpdate, List<ErpBomDO> toInsert, String key, List<String> allnumbers) {
|
||||||
|
this.toUpdate = toUpdate;
|
||||||
|
this.toInsert = toInsert;
|
||||||
|
this.key = key;
|
||||||
|
this.allnumbers = allnumbers;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -61,4 +61,5 @@ public interface ErpContractService {
|
|||||||
*/
|
*/
|
||||||
PageResult<ErpContractDO> getErpContractPage(ErpContractPageReqVO pageReqVO);
|
PageResult<ErpContractDO> getErpContractPage(ErpContractPageReqVO pageReqVO);
|
||||||
|
|
||||||
|
void callErpRfcInterface();
|
||||||
}
|
}
|
||||||
@@ -3,19 +3,29 @@ package cn.iocoder.yudao.module.erp.service.erp;
|
|||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||||
|
import cn.iocoder.yudao.module.erp.common.conf.ErpConfig;
|
||||||
|
import cn.iocoder.yudao.module.erp.common.enums.OftenEnum;
|
||||||
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpContractPageReqVO;
|
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpContractPageReqVO;
|
||||||
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpContractRespVO;
|
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpContractRespVO;
|
||||||
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpContractSaveReqVO;
|
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpContractSaveReqVO;
|
||||||
import cn.iocoder.yudao.module.erp.dal.dataobject.erp.ErpContractDO;
|
import cn.iocoder.yudao.module.erp.dal.dataobject.erp.ErpContractDO;
|
||||||
|
import cn.iocoder.yudao.module.erp.dal.dataobject.erp.ErpContractDO;
|
||||||
import cn.iocoder.yudao.module.erp.dal.mysql.erp.ErpContractMapper;
|
import cn.iocoder.yudao.module.erp.dal.mysql.erp.ErpContractMapper;
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.xxl.job.core.handler.annotation.XxlJob;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.ERP_CONTRACT_NOT_EXISTS;
|
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.ERP_CONTRACT_NOT_EXISTS;
|
||||||
|
import static dm.jdbc.util.DriverUtil.log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ERP合同映射 Service 实现类
|
* ERP合同映射 Service 实现类
|
||||||
@@ -29,6 +39,9 @@ public class ErpContractServiceImpl implements ErpContractService {
|
|||||||
@Resource
|
@Resource
|
||||||
private ErpContractMapper erpContractMapper;
|
private ErpContractMapper erpContractMapper;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ErpConfig erpConfig;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ErpContractRespVO createErpContract(ErpContractSaveReqVO createReqVO) {
|
public ErpContractRespVO createErpContract(ErpContractSaveReqVO createReqVO) {
|
||||||
// 插入
|
// 插入
|
||||||
@@ -86,4 +99,93 @@ public class ErpContractServiceImpl implements ErpContractService {
|
|||||||
return erpContractMapper.selectPage(pageReqVO);
|
return erpContractMapper.selectPage(pageReqVO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
@XxlJob("getErpContractTask")
|
||||||
|
public void callErpRfcInterface() {
|
||||||
|
try {
|
||||||
|
OftenEnum.FuncnrEnum funcnrEnum =OftenEnum.FuncnrEnum.合同信息;
|
||||||
|
String funcnr = funcnrEnum.getFuncnr();
|
||||||
|
// 1. 调用ERP接口获取数据
|
||||||
|
JSONArray dataArray = erpConfig.fetchDataFromERP(funcnr, null);
|
||||||
|
if (dataArray == null || dataArray.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 处理公司数据,区分新增和更新
|
||||||
|
ProcessingResult result = processData(dataArray,funcnrEnum);
|
||||||
|
|
||||||
|
// 3. 批量保存数据
|
||||||
|
saveData(result);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("调用ERP RFC接口失败: {}", e);
|
||||||
|
throw new RuntimeException("调用ERP RFC接口失败: " + e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理数据,区分新增和更新
|
||||||
|
*/
|
||||||
|
private ProcessingResult processData(JSONArray dataArray, OftenEnum.FuncnrEnum funcnr) {
|
||||||
|
String key = "erp" + funcnr.getFuncnr();
|
||||||
|
Map<String,List<String>> numbers = erpConfig.numbers(dataArray, key,funcnr.getDatakey());
|
||||||
|
List<String> allnumbers = numbers.get("all");
|
||||||
|
List<String> comnumbers = numbers.get("com");
|
||||||
|
List<ErpContractDO> toUpdate = new ArrayList<>();
|
||||||
|
List<ErpContractDO> toInsert = new ArrayList<>();
|
||||||
|
|
||||||
|
for (int i = 0; i < dataArray.size(); i++) {
|
||||||
|
JSONObject dataJson = dataArray.getJSONObject(i);
|
||||||
|
if (dataJson != null) {
|
||||||
|
String number = dataJson.getString("BUKRS").trim();
|
||||||
|
if (number != null) {
|
||||||
|
ErpContractDO DO = new ErpContractDO();
|
||||||
|
// DO.setName(dataJson.getString("BUTXT"));
|
||||||
|
// DO.setNumber(number);
|
||||||
|
// DO.setCurrency(dataJson.getString("WAERS"));
|
||||||
|
if (comnumbers.contains(number)) {
|
||||||
|
// 更新
|
||||||
|
toUpdate.add(DO);
|
||||||
|
} else {
|
||||||
|
// 新增
|
||||||
|
toInsert.add(DO);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ProcessingResult(toUpdate, toInsert,key,allnumbers);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量保存数据
|
||||||
|
*/
|
||||||
|
private void saveData(ProcessingResult result) {
|
||||||
|
// 批量新增和更新
|
||||||
|
if (!result.toInsert.isEmpty()) {
|
||||||
|
erpContractMapper.insertBatch(result.toInsert);
|
||||||
|
}
|
||||||
|
if (!result.toUpdate.isEmpty()) {
|
||||||
|
erpContractMapper.updateBatch(result.toUpdate);
|
||||||
|
}
|
||||||
|
erpConfig.updateRedisCache(result.key,result.allnumbers);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据处理结果封装类
|
||||||
|
*/
|
||||||
|
private static class ProcessingResult {
|
||||||
|
private final List<ErpContractDO> toUpdate;
|
||||||
|
private final List<ErpContractDO> toInsert;
|
||||||
|
private final String key;
|
||||||
|
private final List<String> allnumbers;
|
||||||
|
|
||||||
|
public ProcessingResult(List<ErpContractDO> toUpdate, List<ErpContractDO> toInsert,String key,List<String> allnumbers) {
|
||||||
|
this.toUpdate = toUpdate;
|
||||||
|
this.toInsert = toInsert;
|
||||||
|
this.key = key;
|
||||||
|
this.allnumbers = allnumbers;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -61,4 +61,5 @@ public interface ErpCostcenterService {
|
|||||||
*/
|
*/
|
||||||
PageResult<ErpCostcenterDO> getErpCostcenterPage(ErpCostcenterPageReqVO pageReqVO);
|
PageResult<ErpCostcenterDO> getErpCostcenterPage(ErpCostcenterPageReqVO pageReqVO);
|
||||||
|
|
||||||
|
void callErpRfcInterface();
|
||||||
}
|
}
|
||||||
@@ -3,19 +3,31 @@ package cn.iocoder.yudao.module.erp.service.erp;
|
|||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||||
|
import cn.iocoder.yudao.module.erp.common.conf.ErpConfig;
|
||||||
|
import cn.iocoder.yudao.module.erp.common.enums.OftenEnum;
|
||||||
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpCostcenterPageReqVO;
|
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpCostcenterPageReqVO;
|
||||||
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpCostcenterRespVO;
|
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpCostcenterRespVO;
|
||||||
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpCostcenterSaveReqVO;
|
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpCostcenterSaveReqVO;
|
||||||
import cn.iocoder.yudao.module.erp.dal.dataobject.erp.ErpCostcenterDO;
|
import cn.iocoder.yudao.module.erp.dal.dataobject.erp.ErpCostcenterDO;
|
||||||
|
import cn.iocoder.yudao.module.erp.dal.dataobject.erp.ErpCostcenterDO;
|
||||||
import cn.iocoder.yudao.module.erp.dal.mysql.erp.ErpCostcenterMapper;
|
import cn.iocoder.yudao.module.erp.dal.mysql.erp.ErpCostcenterMapper;
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.xxl.job.core.handler.annotation.XxlJob;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.ERP_COSTCENTER_NOT_EXISTS;
|
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.ERP_COSTCENTER_NOT_EXISTS;
|
||||||
|
import static dm.jdbc.util.DriverUtil.log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ERP成本中心 Service 实现类
|
* ERP成本中心 Service 实现类
|
||||||
@@ -29,6 +41,9 @@ public class ErpCostcenterServiceImpl implements ErpCostcenterService {
|
|||||||
@Resource
|
@Resource
|
||||||
private ErpCostcenterMapper erpCostcenterMapper;
|
private ErpCostcenterMapper erpCostcenterMapper;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ErpConfig erpConfig;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ErpCostcenterRespVO createErpCostcenter(ErpCostcenterSaveReqVO createReqVO) {
|
public ErpCostcenterRespVO createErpCostcenter(ErpCostcenterSaveReqVO createReqVO) {
|
||||||
// 插入
|
// 插入
|
||||||
@@ -86,4 +101,110 @@ public class ErpCostcenterServiceImpl implements ErpCostcenterService {
|
|||||||
return erpCostcenterMapper.selectPage(pageReqVO);
|
return erpCostcenterMapper.selectPage(pageReqVO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
@XxlJob("getErpCostcenterTask")
|
||||||
|
public void callErpRfcInterface() {
|
||||||
|
try {
|
||||||
|
OftenEnum.FuncnrEnum funcnrEnum =OftenEnum.FuncnrEnum.成本中心;
|
||||||
|
String funcnr = funcnrEnum.getFuncnr();
|
||||||
|
|
||||||
|
Map<String, Object> req = new HashMap<>();
|
||||||
|
JSONArray dataArrayALL = new JSONArray();
|
||||||
|
List<String> redisCache = erpConfig.getRedisCache(OftenEnum.FuncnrEnum.公司代码.getFuncnr());
|
||||||
|
if (CollUtil.isEmpty(redisCache)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 1. 调用ERP接口获取数据
|
||||||
|
for (String number : redisCache) {
|
||||||
|
req.put("BUKRS", number);
|
||||||
|
// 1. 调用ERP接口获取数据
|
||||||
|
JSONArray dataArray = erpConfig.fetchDataFromERP(funcnr, req);
|
||||||
|
if (dataArray == null || dataArray.isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
dataArrayALL.addAll(dataArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 处理公司数据,区分新增和更新
|
||||||
|
ProcessingResult result = processData(dataArrayALL,funcnrEnum);
|
||||||
|
|
||||||
|
// 3. 批量保存数据
|
||||||
|
saveData(result);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("调用ERP RFC接口失败: {}", e);
|
||||||
|
throw new RuntimeException("调用ERP RFC接口失败: " + e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理数据,区分新增和更新
|
||||||
|
*/
|
||||||
|
private ProcessingResult processData(JSONArray dataArray, OftenEnum.FuncnrEnum funcnr) {
|
||||||
|
String key = "erp" + funcnr.getFuncnr();
|
||||||
|
Map<String,List<String>> numbers = erpConfig.numbers(dataArray, key,funcnr.getDatakey());
|
||||||
|
List<String> allnumbers = numbers.get("all");
|
||||||
|
List<String> comnumbers = numbers.get("com");
|
||||||
|
List<ErpCostcenterDO> toUpdate = new ArrayList<>();
|
||||||
|
List<ErpCostcenterDO> toInsert = new ArrayList<>();
|
||||||
|
|
||||||
|
for (int i = 0; i < dataArray.size(); i++) {
|
||||||
|
JSONObject dataJson = dataArray.getJSONObject(i);
|
||||||
|
if (dataJson != null) {
|
||||||
|
ErpCostcenterDO DO = new ErpCostcenterDO();
|
||||||
|
DO.setNumber(dataJson.getString("KOSTL"));
|
||||||
|
DO.setName(dataJson.getString("KTEX"));
|
||||||
|
DO.setIsUse(dataJson.getString("DRNAM"));
|
||||||
|
DO.setScopeNumber(dataJson.getString("FKBER"));
|
||||||
|
if (!dataJson.getString("AKTIV").equals("0000-00-00")) {
|
||||||
|
DO.setStartDate(LocalDateTime.parse(dataJson.getString("DATAB") + "T00:00:00"));
|
||||||
|
}
|
||||||
|
if (!dataJson.getString("AKTIV").equals("0000-00-00")) {
|
||||||
|
DO.setStartDate(LocalDateTime.parse(dataJson.getString("DATBI") + "T00:00:00"));
|
||||||
|
}
|
||||||
|
DO.setScopeName(dataJson.getString("FKBTX"));
|
||||||
|
if (comnumbers.contains(dataJson.getString("KOSTL"))) {
|
||||||
|
// 更新
|
||||||
|
toUpdate.add(DO);
|
||||||
|
} else {
|
||||||
|
// 新增
|
||||||
|
toInsert.add(DO);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ProcessingResult(toUpdate, toInsert,key,allnumbers);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量保存数据
|
||||||
|
*/
|
||||||
|
private void saveData(ProcessingResult result) {
|
||||||
|
// 批量新增和更新
|
||||||
|
if (!result.toInsert.isEmpty()) {
|
||||||
|
erpCostcenterMapper.insertBatch(result.toInsert);
|
||||||
|
}
|
||||||
|
if (!result.toUpdate.isEmpty()) {
|
||||||
|
erpCostcenterMapper.updateBatch(result.toUpdate);
|
||||||
|
}
|
||||||
|
erpConfig.updateRedisCache(result.key,result.allnumbers);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据处理结果封装类
|
||||||
|
*/
|
||||||
|
private static class ProcessingResult {
|
||||||
|
private final List<ErpCostcenterDO> toUpdate;
|
||||||
|
private final List<ErpCostcenterDO> toInsert;
|
||||||
|
private final String key;
|
||||||
|
private final List<String> allnumbers;
|
||||||
|
|
||||||
|
public ProcessingResult(List<ErpCostcenterDO> toUpdate, List<ErpCostcenterDO> toInsert,String key,List<String> allnumbers) {
|
||||||
|
this.toUpdate = toUpdate;
|
||||||
|
this.toInsert = toInsert;
|
||||||
|
this.key = key;
|
||||||
|
this.allnumbers = allnumbers;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -13,6 +13,7 @@ import cn.iocoder.yudao.module.erp.dal.dataobject.erp.ErpCustomerDO;
|
|||||||
import cn.iocoder.yudao.module.erp.dal.mysql.erp.ErpCustomerMapper;
|
import cn.iocoder.yudao.module.erp.dal.mysql.erp.ErpCustomerMapper;
|
||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.xxl.job.core.handler.annotation.XxlJob;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.springframework.data.redis.core.RedisTemplate;
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -108,6 +109,7 @@ public class ErpCustomerServiceImpl implements ErpCustomerService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
|
@XxlJob("getErpCustomerTask")
|
||||||
public void callErpRfcInterface() {
|
public void callErpRfcInterface() {
|
||||||
try {
|
try {
|
||||||
OftenEnum.FuncnrEnum funcnrEnum = OftenEnum.FuncnrEnum.客商信息;
|
OftenEnum.FuncnrEnum funcnrEnum = OftenEnum.FuncnrEnum.客商信息;
|
||||||
@@ -120,10 +122,8 @@ public class ErpCustomerServiceImpl implements ErpCustomerService {
|
|||||||
datumEntry.put("sign", "I");
|
datumEntry.put("sign", "I");
|
||||||
datumEntry.put("option", "EQ");
|
datumEntry.put("option", "EQ");
|
||||||
datumEntry.put("low", LocalDate.now().toString());
|
datumEntry.put("low", LocalDate.now().toString());
|
||||||
// datumEntry.put("low", "2021-05-17");
|
|
||||||
datumList.add(datumEntry);
|
datumList.add(datumEntry);
|
||||||
req.put(funcnrEnum.getDatekey(), datumList);
|
req.put(funcnrEnum.getDatekey(), datumList);
|
||||||
// req.put("BUKRS", "3001");
|
|
||||||
|
|
||||||
// 1. 调用ERP接口获取数据
|
// 1. 调用ERP接口获取数据
|
||||||
for (OftenEnum.ModeTypeEnum type : OftenEnum.ModeTypeEnum.values()) {
|
for (OftenEnum.ModeTypeEnum type : OftenEnum.ModeTypeEnum.values()) {
|
||||||
@@ -161,7 +161,7 @@ public class ErpCustomerServiceImpl implements ErpCustomerService {
|
|||||||
for (int i = 0; i < dataArray.size(); i++) {
|
for (int i = 0; i < dataArray.size(); i++) {
|
||||||
JSONObject dataJson = dataArray.getJSONObject(i);
|
JSONObject dataJson = dataArray.getJSONObject(i);
|
||||||
if (dataJson != null) {
|
if (dataJson != null) {
|
||||||
String number = dataJson.getString("PARTNER").trim();
|
String number = dataJson.getString(funcnrEnum.getDatakey()).trim();
|
||||||
if (number != null) {
|
if (number != null) {
|
||||||
ErpCustomerDO DO = new ErpCustomerDO();
|
ErpCustomerDO DO = new ErpCustomerDO();
|
||||||
DO.setName(dataJson.getString("NAME_ORG1"));
|
DO.setName(dataJson.getString("NAME_ORG1"));
|
||||||
|
|||||||
@@ -61,4 +61,5 @@ public interface ErpFactoryService {
|
|||||||
*/
|
*/
|
||||||
PageResult<ErpFactoryDO> getErpFactoryPage(ErpFactoryPageReqVO pageReqVO);
|
PageResult<ErpFactoryDO> getErpFactoryPage(ErpFactoryPageReqVO pageReqVO);
|
||||||
|
|
||||||
|
void callErpRfcInterface();
|
||||||
}
|
}
|
||||||
@@ -3,19 +3,30 @@ package cn.iocoder.yudao.module.erp.service.erp;
|
|||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||||
|
import cn.iocoder.yudao.module.erp.common.conf.ErpConfig;
|
||||||
|
import cn.iocoder.yudao.module.erp.common.enums.OftenEnum;
|
||||||
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpFactoryPageReqVO;
|
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpFactoryPageReqVO;
|
||||||
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpFactoryRespVO;
|
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpFactoryRespVO;
|
||||||
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpFactorySaveReqVO;
|
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpFactorySaveReqVO;
|
||||||
import cn.iocoder.yudao.module.erp.dal.dataobject.erp.ErpFactoryDO;
|
import cn.iocoder.yudao.module.erp.dal.dataobject.erp.ErpFactoryDO;
|
||||||
|
import cn.iocoder.yudao.module.erp.dal.dataobject.erp.ErpFactoryDO;
|
||||||
import cn.iocoder.yudao.module.erp.dal.mysql.erp.ErpFactoryMapper;
|
import cn.iocoder.yudao.module.erp.dal.mysql.erp.ErpFactoryMapper;
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.xxl.job.core.handler.annotation.XxlJob;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.ERP_FACTORY_NOT_EXISTS;
|
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.ERP_FACTORY_NOT_EXISTS;
|
||||||
|
import static dm.jdbc.util.DriverUtil.log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ERP工厂 Service 实现类
|
* ERP工厂 Service 实现类
|
||||||
@@ -29,6 +40,9 @@ public class ErpFactoryServiceImpl implements ErpFactoryService {
|
|||||||
@Resource
|
@Resource
|
||||||
private ErpFactoryMapper erpFactoryMapper;
|
private ErpFactoryMapper erpFactoryMapper;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ErpConfig erpConfig;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ErpFactoryRespVO createErpFactory(ErpFactorySaveReqVO createReqVO) {
|
public ErpFactoryRespVO createErpFactory(ErpFactorySaveReqVO createReqVO) {
|
||||||
// 插入
|
// 插入
|
||||||
@@ -85,5 +99,110 @@ public class ErpFactoryServiceImpl implements ErpFactoryService {
|
|||||||
public PageResult<ErpFactoryDO> getErpFactoryPage(ErpFactoryPageReqVO pageReqVO) {
|
public PageResult<ErpFactoryDO> getErpFactoryPage(ErpFactoryPageReqVO pageReqVO) {
|
||||||
return erpFactoryMapper.selectPage(pageReqVO);
|
return erpFactoryMapper.selectPage(pageReqVO);
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
@XxlJob("getErpFactoryTask")
|
||||||
|
public void callErpRfcInterface() {
|
||||||
|
try {
|
||||||
|
OftenEnum.FuncnrEnum funcnrEnum =OftenEnum.FuncnrEnum.工厂信息;
|
||||||
|
String funcnr = funcnrEnum.getFuncnr();
|
||||||
|
// 1. 调用ERP接口获取数据
|
||||||
|
Map<String, Object> req = new HashMap<>();
|
||||||
|
JSONArray dataArrayALL = new JSONArray();
|
||||||
|
List<String> redisCache = erpConfig.getRedisCache(OftenEnum.FuncnrEnum.公司代码.getFuncnr());
|
||||||
|
if (CollUtil.isEmpty(redisCache)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (String companyNumber : redisCache) {
|
||||||
|
req.put("BUKRS", companyNumber);
|
||||||
|
// 1. 调用ERP接口获取数据
|
||||||
|
JSONArray dataArray = erpConfig.fetchDataFromERP(funcnr, req);
|
||||||
|
if (dataArray == null || dataArray.isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// 往每个子项中添加BUKRS字段
|
||||||
|
for (int j = 0; j < dataArray.size(); j++) {
|
||||||
|
JSONObject item = dataArray.getJSONObject(j);
|
||||||
|
if (item != null) {
|
||||||
|
item.put("BUKRS", companyNumber);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dataArrayALL.addAll(dataArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 处理公司数据,区分新增和更新
|
||||||
|
ProcessingResult result = processData(dataArrayALL,funcnrEnum);
|
||||||
|
|
||||||
|
// 3. 批量保存数据
|
||||||
|
saveData(result);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("调用ERP RFC接口失败: {}", e);
|
||||||
|
throw new RuntimeException("调用ERP RFC接口失败: " + e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理数据,区分新增和更新
|
||||||
|
*/
|
||||||
|
private ProcessingResult processData(JSONArray dataArray, OftenEnum.FuncnrEnum funcnr) {
|
||||||
|
String key = "erp" + funcnr.getFuncnr();
|
||||||
|
Map<String,List<String>> numbers = erpConfig.numbers(dataArray, key,funcnr.getDatakey());
|
||||||
|
List<String> allnumbers = numbers.get("all");
|
||||||
|
List<String> comnumbers = numbers.get("com");
|
||||||
|
List<ErpFactoryDO> toUpdate = new ArrayList<>();
|
||||||
|
List<ErpFactoryDO> toInsert = new ArrayList<>();
|
||||||
|
|
||||||
|
for (int i = 0; i < dataArray.size(); i++) {
|
||||||
|
JSONObject dataJson = dataArray.getJSONObject(i);
|
||||||
|
if (dataJson != null) {
|
||||||
|
String number = dataJson.getString(funcnr.getDatakey()).trim();
|
||||||
|
ErpFactoryDO DO = new ErpFactoryDO();
|
||||||
|
DO.setName(dataJson.getString("NAME1"));
|
||||||
|
DO.setNumber(number);
|
||||||
|
DO.setCompanyId(dataJson.getString("BUKRS"));
|
||||||
|
if (comnumbers.contains(number)) {
|
||||||
|
// 更新
|
||||||
|
toUpdate.add(DO);
|
||||||
|
} else {
|
||||||
|
// 新增
|
||||||
|
toInsert.add(DO);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ProcessingResult(toUpdate, toInsert,key,allnumbers);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量保存数据
|
||||||
|
*/
|
||||||
|
private void saveData(ProcessingResult result) {
|
||||||
|
// 批量新增和更新
|
||||||
|
if (!result.toInsert.isEmpty()) {
|
||||||
|
erpFactoryMapper.insertBatch(result.toInsert);
|
||||||
|
}
|
||||||
|
if (!result.toUpdate.isEmpty()) {
|
||||||
|
erpFactoryMapper.updateBatch(result.toUpdate);
|
||||||
|
}
|
||||||
|
erpConfig.updateRedisCache(result.key,result.allnumbers);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据处理结果封装类
|
||||||
|
*/
|
||||||
|
private static class ProcessingResult {
|
||||||
|
private final List<ErpFactoryDO> toUpdate;
|
||||||
|
private final List<ErpFactoryDO> toInsert;
|
||||||
|
private final String key;
|
||||||
|
private final List<String> allnumbers;
|
||||||
|
|
||||||
|
public ProcessingResult(List<ErpFactoryDO> toUpdate, List<ErpFactoryDO> toInsert,String key,List<String> allnumbers) {
|
||||||
|
this.toUpdate = toUpdate;
|
||||||
|
this.toInsert = toInsert;
|
||||||
|
this.key = key;
|
||||||
|
this.allnumbers = allnumbers;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -61,4 +61,5 @@ public interface ErpInternalOrderService {
|
|||||||
*/
|
*/
|
||||||
PageResult<ErpInternalOrderDO> getErpInternalOrderPage(ErpInternalOrderPageReqVO pageReqVO);
|
PageResult<ErpInternalOrderDO> getErpInternalOrderPage(ErpInternalOrderPageReqVO pageReqVO);
|
||||||
|
|
||||||
|
void callErpRfcInterface();
|
||||||
}
|
}
|
||||||
@@ -3,19 +3,30 @@ package cn.iocoder.yudao.module.erp.service.erp;
|
|||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||||
|
import cn.iocoder.yudao.module.erp.common.conf.ErpConfig;
|
||||||
|
import cn.iocoder.yudao.module.erp.common.enums.OftenEnum;
|
||||||
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpInternalOrderPageReqVO;
|
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpInternalOrderPageReqVO;
|
||||||
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpInternalOrderRespVO;
|
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpInternalOrderRespVO;
|
||||||
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpInternalOrderSaveReqVO;
|
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpInternalOrderSaveReqVO;
|
||||||
import cn.iocoder.yudao.module.erp.dal.dataobject.erp.ErpInternalOrderDO;
|
import cn.iocoder.yudao.module.erp.dal.dataobject.erp.ErpInternalOrderDO;
|
||||||
|
import cn.iocoder.yudao.module.erp.dal.dataobject.erp.ErpInternalOrderDO;
|
||||||
import cn.iocoder.yudao.module.erp.dal.mysql.erp.ErpInternalOrderMapper;
|
import cn.iocoder.yudao.module.erp.dal.mysql.erp.ErpInternalOrderMapper;
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.xxl.job.core.handler.annotation.XxlJob;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.ERP_INTERNAL_ORDER_NOT_EXISTS;
|
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.ERP_INTERNAL_ORDER_NOT_EXISTS;
|
||||||
|
import static dm.jdbc.util.DriverUtil.log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ERP内部订单 Service 实现类
|
* ERP内部订单 Service 实现类
|
||||||
@@ -29,6 +40,9 @@ public class ErpInternalOrderServiceImpl implements ErpInternalOrderService {
|
|||||||
@Resource
|
@Resource
|
||||||
private ErpInternalOrderMapper erpInternalOrderMapper;
|
private ErpInternalOrderMapper erpInternalOrderMapper;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ErpConfig erpConfig;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ErpInternalOrderRespVO createErpInternalOrder(ErpInternalOrderSaveReqVO createReqVO) {
|
public ErpInternalOrderRespVO createErpInternalOrder(ErpInternalOrderSaveReqVO createReqVO) {
|
||||||
// 插入
|
// 插入
|
||||||
@@ -86,4 +100,104 @@ public class ErpInternalOrderServiceImpl implements ErpInternalOrderService {
|
|||||||
return erpInternalOrderMapper.selectPage(pageReqVO);
|
return erpInternalOrderMapper.selectPage(pageReqVO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
@XxlJob("getErpInternalOrderTask")
|
||||||
|
public void callErpRfcInterface() {
|
||||||
|
try {
|
||||||
|
OftenEnum.FuncnrEnum funcnrEnum =OftenEnum.FuncnrEnum.内部订单;
|
||||||
|
String funcnr = funcnrEnum.getFuncnr();
|
||||||
|
|
||||||
|
Map<String, Object> req = new HashMap<>();
|
||||||
|
JSONArray dataArrayALL = new JSONArray();
|
||||||
|
List<String> redisCache = erpConfig.getRedisCache(OftenEnum.FuncnrEnum.公司代码.getFuncnr());
|
||||||
|
if (CollUtil.isEmpty(redisCache)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 1. 调用ERP接口获取数据
|
||||||
|
for (String number : redisCache) {
|
||||||
|
req.put("BUKRS", number);
|
||||||
|
// 1. 调用ERP接口获取数据
|
||||||
|
JSONArray dataArray = erpConfig.fetchDataFromERP(funcnr, req);
|
||||||
|
if (dataArray == null || dataArray.isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
dataArrayALL.addAll(dataArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 处理公司数据,区分新增和更新
|
||||||
|
ProcessingResult result = processData(dataArrayALL,funcnrEnum);
|
||||||
|
|
||||||
|
// 3. 批量保存数据
|
||||||
|
saveData(result);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("调用ERP RFC接口失败: {}", e);
|
||||||
|
throw new RuntimeException("调用ERP RFC接口失败: " + e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理数据,区分新增和更新
|
||||||
|
*/
|
||||||
|
private ProcessingResult processData(JSONArray dataArray, OftenEnum.FuncnrEnum funcnr) {
|
||||||
|
String key = "erp" + funcnr.getFuncnr();
|
||||||
|
Map<String,List<String>> numbers = erpConfig.numbers(dataArray, key,funcnr.getDatakey());
|
||||||
|
List<String> allnumbers = numbers.get("all");
|
||||||
|
List<String> comnumbers = numbers.get("com");
|
||||||
|
List<ErpInternalOrderDO> toUpdate = new ArrayList<>();
|
||||||
|
List<ErpInternalOrderDO> toInsert = new ArrayList<>();
|
||||||
|
|
||||||
|
for (int i = 0; i < dataArray.size(); i++) {
|
||||||
|
JSONObject dataJson = dataArray.getJSONObject(i);
|
||||||
|
if (dataJson != null) {
|
||||||
|
ErpInternalOrderDO DO = new ErpInternalOrderDO();
|
||||||
|
DO.setName(dataJson.getString("KTEXT"));
|
||||||
|
DO.setNumber(dataJson.getString("AUFNR"));
|
||||||
|
DO.setType(dataJson.getString("AUART"));
|
||||||
|
DO.setIsOff(dataJson.getString("PHAS3"));
|
||||||
|
DO.setIsFinish(dataJson.getString("PHAS2"));
|
||||||
|
if (comnumbers.contains(dataJson.getString("AUFNR"))) {
|
||||||
|
// 更新
|
||||||
|
toUpdate.add(DO);
|
||||||
|
} else {
|
||||||
|
// 新增
|
||||||
|
toInsert.add(DO);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ProcessingResult(toUpdate, toInsert,key,allnumbers);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量保存数据
|
||||||
|
*/
|
||||||
|
private void saveData(ProcessingResult result) {
|
||||||
|
// 批量新增和更新
|
||||||
|
if (!result.toInsert.isEmpty()) {
|
||||||
|
erpInternalOrderMapper.insertBatch(result.toInsert);
|
||||||
|
}
|
||||||
|
if (!result.toUpdate.isEmpty()) {
|
||||||
|
erpInternalOrderMapper.updateBatch(result.toUpdate);
|
||||||
|
}
|
||||||
|
erpConfig.updateRedisCache(result.key,result.allnumbers);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据处理结果封装类
|
||||||
|
*/
|
||||||
|
private static class ProcessingResult {
|
||||||
|
private final List<ErpInternalOrderDO> toUpdate;
|
||||||
|
private final List<ErpInternalOrderDO> toInsert;
|
||||||
|
private final String key;
|
||||||
|
private final List<String> allnumbers;
|
||||||
|
|
||||||
|
public ProcessingResult(List<ErpInternalOrderDO> toUpdate, List<ErpInternalOrderDO> toInsert,String key,List<String> allnumbers) {
|
||||||
|
this.toUpdate = toUpdate;
|
||||||
|
this.toInsert = toInsert;
|
||||||
|
this.key = key;
|
||||||
|
this.allnumbers = allnumbers;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -13,6 +13,7 @@ import cn.iocoder.yudao.module.erp.dal.dataobject.erp.ErpMaterialDO;
|
|||||||
import cn.iocoder.yudao.module.erp.dal.mysql.erp.ErpMaterialMapper;
|
import cn.iocoder.yudao.module.erp.dal.mysql.erp.ErpMaterialMapper;
|
||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.xxl.job.core.handler.annotation.XxlJob;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
@@ -102,6 +103,7 @@ public class ErpMaterialServiceImpl implements ErpMaterialService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
|
@XxlJob("getErpMaterialTask")
|
||||||
public void callErpRfcInterface() {
|
public void callErpRfcInterface() {
|
||||||
try {
|
try {
|
||||||
OftenEnum.FuncnrEnum funcnrEnum =OftenEnum.FuncnrEnum.物料数据;
|
OftenEnum.FuncnrEnum funcnrEnum =OftenEnum.FuncnrEnum.物料数据;
|
||||||
@@ -150,7 +152,6 @@ public class ErpMaterialServiceImpl implements ErpMaterialService {
|
|||||||
JSONObject dataJson = dataArray.getJSONObject(i);
|
JSONObject dataJson = dataArray.getJSONObject(i);
|
||||||
if (dataJson != null) {
|
if (dataJson != null) {
|
||||||
String number = dataJson.getString("MATNR").trim();
|
String number = dataJson.getString("MATNR").trim();
|
||||||
if (number != null) {
|
|
||||||
ErpMaterialDO DO = new ErpMaterialDO();
|
ErpMaterialDO DO = new ErpMaterialDO();
|
||||||
DO.setDownCenterNumber(number);
|
DO.setDownCenterNumber(number);
|
||||||
DO.setCenterNumber(dataJson.getString("BISMT"));
|
DO.setCenterNumber(dataJson.getString("BISMT"));
|
||||||
@@ -175,7 +176,6 @@ public class ErpMaterialServiceImpl implements ErpMaterialService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return new ProcessingResult(toUpdate, toInsert,key,allnumbers);
|
return new ProcessingResult(toUpdate, toInsert,key,allnumbers);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,4 +61,5 @@ public interface ErpProcessService {
|
|||||||
*/
|
*/
|
||||||
PageResult<ErpProcessDO> getErpProcessPage(ErpProcessPageReqVO pageReqVO);
|
PageResult<ErpProcessDO> getErpProcessPage(ErpProcessPageReqVO pageReqVO);
|
||||||
|
|
||||||
|
void callErpRfcInterface();
|
||||||
}
|
}
|
||||||
@@ -3,19 +3,29 @@ package cn.iocoder.yudao.module.erp.service.erp;
|
|||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||||
|
import cn.iocoder.yudao.module.erp.common.conf.ErpConfig;
|
||||||
|
import cn.iocoder.yudao.module.erp.common.enums.OftenEnum;
|
||||||
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpProcessPageReqVO;
|
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpProcessPageReqVO;
|
||||||
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpProcessRespVO;
|
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpProcessRespVO;
|
||||||
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpProcessSaveReqVO;
|
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpProcessSaveReqVO;
|
||||||
import cn.iocoder.yudao.module.erp.dal.dataobject.erp.ErpProcessDO;
|
import cn.iocoder.yudao.module.erp.dal.dataobject.erp.ErpProcessDO;
|
||||||
|
import cn.iocoder.yudao.module.erp.dal.dataobject.erp.ErpProcessDO;
|
||||||
import cn.iocoder.yudao.module.erp.dal.mysql.erp.ErpProcessMapper;
|
import cn.iocoder.yudao.module.erp.dal.mysql.erp.ErpProcessMapper;
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.xxl.job.core.handler.annotation.XxlJob;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.ERP_PROCESS_NOT_EXISTS;
|
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.ERP_PROCESS_NOT_EXISTS;
|
||||||
|
import static dm.jdbc.util.DriverUtil.log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ERP工艺路线 Service 实现类
|
* ERP工艺路线 Service 实现类
|
||||||
@@ -29,6 +39,9 @@ public class ErpProcessServiceImpl implements ErpProcessService {
|
|||||||
@Resource
|
@Resource
|
||||||
private ErpProcessMapper erpProcessMapper;
|
private ErpProcessMapper erpProcessMapper;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ErpConfig erpConfig;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ErpProcessRespVO createErpProcess(ErpProcessSaveReqVO createReqVO) {
|
public ErpProcessRespVO createErpProcess(ErpProcessSaveReqVO createReqVO) {
|
||||||
// 插入
|
// 插入
|
||||||
@@ -86,4 +99,93 @@ public class ErpProcessServiceImpl implements ErpProcessService {
|
|||||||
return erpProcessMapper.selectPage(pageReqVO);
|
return erpProcessMapper.selectPage(pageReqVO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
@XxlJob("getErpProcessTask")
|
||||||
|
public void callErpRfcInterface() {
|
||||||
|
try {
|
||||||
|
OftenEnum.FuncnrEnum funcnrEnum =OftenEnum.FuncnrEnum.公司代码;
|
||||||
|
String funcnr = funcnrEnum.getFuncnr();
|
||||||
|
// 1. 调用ERP接口获取数据
|
||||||
|
JSONArray dataArray = erpConfig.fetchDataFromERP(funcnr, null);
|
||||||
|
if (dataArray == null || dataArray.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 处理公司数据,区分新增和更新
|
||||||
|
ProcessingResult result = processData(dataArray,funcnrEnum);
|
||||||
|
|
||||||
|
// 3. 批量保存数据
|
||||||
|
saveData(result);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("调用ERP RFC接口失败: {}", e);
|
||||||
|
throw new RuntimeException("调用ERP RFC接口失败: " + e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理数据,区分新增和更新
|
||||||
|
*/
|
||||||
|
private ProcessingResult processData(JSONArray dataArray, OftenEnum.FuncnrEnum funcnr) {
|
||||||
|
String key = "erp" + funcnr.getFuncnr();
|
||||||
|
Map<String,List<String>> numbers = erpConfig.numbers(dataArray, key,funcnr.getDatakey());
|
||||||
|
List<String> allnumbers = numbers.get("all");
|
||||||
|
List<String> comnumbers = numbers.get("com");
|
||||||
|
List<ErpProcessDO> toUpdate = new ArrayList<>();
|
||||||
|
List<ErpProcessDO> toInsert = new ArrayList<>();
|
||||||
|
|
||||||
|
for (int i = 0; i < dataArray.size(); i++) {
|
||||||
|
JSONObject dataJson = dataArray.getJSONObject(i);
|
||||||
|
if (dataJson != null) {
|
||||||
|
String number = dataJson.getString("BUKRS").trim();
|
||||||
|
if (number != null) {
|
||||||
|
ErpProcessDO DO = new ErpProcessDO();
|
||||||
|
// DO.setName(dataJson.getString("BUTXT"));
|
||||||
|
// DO.setNumber(number);
|
||||||
|
// DO.setCurrency(dataJson.getString("WAERS"));
|
||||||
|
if (comnumbers.contains(number)) {
|
||||||
|
// 更新
|
||||||
|
toUpdate.add(DO);
|
||||||
|
} else {
|
||||||
|
// 新增
|
||||||
|
toInsert.add(DO);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ProcessingResult(toUpdate, toInsert,key,allnumbers);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量保存数据
|
||||||
|
*/
|
||||||
|
private void saveData(ProcessingResult result) {
|
||||||
|
// 批量新增和更新
|
||||||
|
if (!result.toInsert.isEmpty()) {
|
||||||
|
erpProcessMapper.insertBatch(result.toInsert);
|
||||||
|
}
|
||||||
|
if (!result.toUpdate.isEmpty()) {
|
||||||
|
erpProcessMapper.updateBatch(result.toUpdate);
|
||||||
|
}
|
||||||
|
erpConfig.updateRedisCache(result.key,result.allnumbers);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据处理结果封装类
|
||||||
|
*/
|
||||||
|
private static class ProcessingResult {
|
||||||
|
private final List<ErpProcessDO> toUpdate;
|
||||||
|
private final List<ErpProcessDO> toInsert;
|
||||||
|
private final String key;
|
||||||
|
private final List<String> allnumbers;
|
||||||
|
|
||||||
|
public ProcessingResult(List<ErpProcessDO> toUpdate, List<ErpProcessDO> toInsert,String key,List<String> allnumbers) {
|
||||||
|
this.toUpdate = toUpdate;
|
||||||
|
this.toInsert = toInsert;
|
||||||
|
this.key = key;
|
||||||
|
this.allnumbers = allnumbers;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -61,4 +61,5 @@ public interface ErpProductiveOrderService {
|
|||||||
*/
|
*/
|
||||||
PageResult<ErpProductiveOrderDO> getErpProductiveOrderPage(ErpProductiveOrderPageReqVO pageReqVO);
|
PageResult<ErpProductiveOrderDO> getErpProductiveOrderPage(ErpProductiveOrderPageReqVO pageReqVO);
|
||||||
|
|
||||||
|
void callErpRfcInterface();
|
||||||
}
|
}
|
||||||
@@ -3,19 +3,31 @@ package cn.iocoder.yudao.module.erp.service.erp;
|
|||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||||
|
import cn.iocoder.yudao.module.erp.common.conf.ErpConfig;
|
||||||
|
import cn.iocoder.yudao.module.erp.common.enums.OftenEnum;
|
||||||
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpProductiveOrderPageReqVO;
|
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpProductiveOrderPageReqVO;
|
||||||
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpProductiveOrderRespVO;
|
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpProductiveOrderRespVO;
|
||||||
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpProductiveOrderSaveReqVO;
|
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpProductiveOrderSaveReqVO;
|
||||||
import cn.iocoder.yudao.module.erp.dal.dataobject.erp.ErpProductiveOrderDO;
|
import cn.iocoder.yudao.module.erp.dal.dataobject.erp.ErpProductiveOrderDO;
|
||||||
|
import cn.iocoder.yudao.module.erp.dal.dataobject.erp.ErpProductiveOrderDO;
|
||||||
import cn.iocoder.yudao.module.erp.dal.mysql.erp.ErpProductiveOrderMapper;
|
import cn.iocoder.yudao.module.erp.dal.mysql.erp.ErpProductiveOrderMapper;
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.xxl.job.core.handler.annotation.XxlJob;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.ERP_PRODUCTIVE_ORDER_NOT_EXISTS;
|
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.ERP_PRODUCTIVE_ORDER_NOT_EXISTS;
|
||||||
|
import static dm.jdbc.util.DriverUtil.log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ERP生产订单 Service 实现类
|
* ERP生产订单 Service 实现类
|
||||||
@@ -29,6 +41,9 @@ public class ErpProductiveOrderServiceImpl implements ErpProductiveOrderService
|
|||||||
@Resource
|
@Resource
|
||||||
private ErpProductiveOrderMapper erpProductiveOrderMapper;
|
private ErpProductiveOrderMapper erpProductiveOrderMapper;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ErpConfig erpConfig;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ErpProductiveOrderRespVO createErpProductiveOrder(ErpProductiveOrderSaveReqVO createReqVO) {
|
public ErpProductiveOrderRespVO createErpProductiveOrder(ErpProductiveOrderSaveReqVO createReqVO) {
|
||||||
// 插入
|
// 插入
|
||||||
@@ -86,4 +101,113 @@ public class ErpProductiveOrderServiceImpl implements ErpProductiveOrderService
|
|||||||
return erpProductiveOrderMapper.selectPage(pageReqVO);
|
return erpProductiveOrderMapper.selectPage(pageReqVO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
@XxlJob("getErpProductiveOrderTask")
|
||||||
|
public void callErpRfcInterface() {
|
||||||
|
try {
|
||||||
|
OftenEnum.FuncnrEnum funcnrEnum =OftenEnum.FuncnrEnum.生产订单;
|
||||||
|
String funcnr = funcnrEnum.getFuncnr();
|
||||||
|
|
||||||
|
Map<String, Object> req = new HashMap<>();
|
||||||
|
List<Map<String, String>> datumList = new ArrayList<>();
|
||||||
|
Map<String, String> datumEntry = new HashMap<>();
|
||||||
|
// 构建datum参数数组
|
||||||
|
datumEntry.put("sign", "I");
|
||||||
|
datumEntry.put("option", "EQ");
|
||||||
|
datumEntry.put("low", LocalDate.now().toString());
|
||||||
|
datumList.add(datumEntry);
|
||||||
|
req.put(funcnrEnum.getDatekey(), datumList);
|
||||||
|
JSONArray dataArrayALL = new JSONArray();
|
||||||
|
List<String> redisCache = erpConfig.getRedisCache(OftenEnum.FuncnrEnum.工厂信息.getFuncnr());
|
||||||
|
if (CollUtil.isEmpty(redisCache)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 1. 调用ERP接口获取数据
|
||||||
|
for (String number : redisCache) {
|
||||||
|
req.put("WERKS", number);
|
||||||
|
// 1. 调用ERP接口获取数据
|
||||||
|
JSONArray dataArray = erpConfig.fetchDataFromERP(funcnr, req);
|
||||||
|
if (dataArray == null || dataArray.isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
dataArrayALL.addAll(dataArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 处理公司数据,区分新增和更新
|
||||||
|
ProcessingResult result = processData(dataArrayALL,funcnrEnum);
|
||||||
|
|
||||||
|
// 3. 批量保存数据
|
||||||
|
saveData(result);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("调用ERP RFC接口失败: {}", e);
|
||||||
|
throw new RuntimeException("调用ERP RFC接口失败: " + e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理数据,区分新增和更新
|
||||||
|
*/
|
||||||
|
private ProcessingResult processData(JSONArray dataArray, OftenEnum.FuncnrEnum funcnr) {
|
||||||
|
String key = "erp" + funcnr.getFuncnr();
|
||||||
|
Map<String,List<String>> numbers = erpConfig.numbers(dataArray, key,funcnr.getDatakey());
|
||||||
|
List<String> allnumbers = numbers.get("all");
|
||||||
|
List<String> comnumbers = numbers.get("com");
|
||||||
|
List<ErpProductiveOrderDO> toUpdate = new ArrayList<>();
|
||||||
|
List<ErpProductiveOrderDO> toInsert = new ArrayList<>();
|
||||||
|
|
||||||
|
for (int i = 0; i < dataArray.size(); i++) {
|
||||||
|
JSONObject dataJson = dataArray.getJSONObject(i);
|
||||||
|
if (dataJson != null) {
|
||||||
|
String number = dataJson.getString("BUKRS").trim();
|
||||||
|
if (number != null) {
|
||||||
|
ErpProductiveOrderDO DO = new ErpProductiveOrderDO();
|
||||||
|
// DO.setName(dataJson.getString("BUTXT"));
|
||||||
|
// DO.setNumber(number);
|
||||||
|
// DO.setCurrency(dataJson.getString("WAERS"));
|
||||||
|
if (comnumbers.contains(number)) {
|
||||||
|
// 更新
|
||||||
|
toUpdate.add(DO);
|
||||||
|
} else {
|
||||||
|
// 新增
|
||||||
|
toInsert.add(DO);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ProcessingResult(toUpdate, toInsert,key,allnumbers);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量保存数据
|
||||||
|
*/
|
||||||
|
private void saveData(ProcessingResult result) {
|
||||||
|
// 批量新增和更新
|
||||||
|
if (!result.toInsert.isEmpty()) {
|
||||||
|
erpProductiveOrderMapper.insertBatch(result.toInsert);
|
||||||
|
}
|
||||||
|
if (!result.toUpdate.isEmpty()) {
|
||||||
|
erpProductiveOrderMapper.updateBatch(result.toUpdate);
|
||||||
|
}
|
||||||
|
erpConfig.updateRedisCache(result.key,result.allnumbers);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据处理结果封装类
|
||||||
|
*/
|
||||||
|
private static class ProcessingResult {
|
||||||
|
private final List<ErpProductiveOrderDO> toUpdate;
|
||||||
|
private final List<ErpProductiveOrderDO> toInsert;
|
||||||
|
private final String key;
|
||||||
|
private final List<String> allnumbers;
|
||||||
|
|
||||||
|
public ProcessingResult(List<ErpProductiveOrderDO> toUpdate, List<ErpProductiveOrderDO> toInsert,String key,List<String> allnumbers) {
|
||||||
|
this.toUpdate = toUpdate;
|
||||||
|
this.toInsert = toInsert;
|
||||||
|
this.key = key;
|
||||||
|
this.allnumbers = allnumbers;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -61,4 +61,5 @@ public interface ErpProductiveVersionService {
|
|||||||
*/
|
*/
|
||||||
PageResult<ErpProductiveVersionDO> getErpProductiveVersionPage(ErpProductiveVersionPageReqVO pageReqVO);
|
PageResult<ErpProductiveVersionDO> getErpProductiveVersionPage(ErpProductiveVersionPageReqVO pageReqVO);
|
||||||
|
|
||||||
|
void callErpRfcInterface();
|
||||||
}
|
}
|
||||||
@@ -3,19 +3,30 @@ package cn.iocoder.yudao.module.erp.service.erp;
|
|||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||||
|
import cn.iocoder.yudao.module.erp.common.conf.ErpConfig;
|
||||||
|
import cn.iocoder.yudao.module.erp.common.enums.OftenEnum;
|
||||||
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpProductiveVersionPageReqVO;
|
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpProductiveVersionPageReqVO;
|
||||||
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpProductiveVersionRespVO;
|
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpProductiveVersionRespVO;
|
||||||
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpProductiveVersionSaveReqVO;
|
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpProductiveVersionSaveReqVO;
|
||||||
import cn.iocoder.yudao.module.erp.dal.dataobject.erp.ErpProductiveVersionDO;
|
import cn.iocoder.yudao.module.erp.dal.dataobject.erp.ErpProductiveVersionDO;
|
||||||
|
import cn.iocoder.yudao.module.erp.dal.dataobject.erp.ErpProductiveVersionDO;
|
||||||
import cn.iocoder.yudao.module.erp.dal.mysql.erp.ErpProductiveVersionMapper;
|
import cn.iocoder.yudao.module.erp.dal.mysql.erp.ErpProductiveVersionMapper;
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.xxl.job.core.handler.annotation.XxlJob;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.ERP_PRODUCTIVE_VERSION_NOT_EXISTS;
|
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.ERP_PRODUCTIVE_VERSION_NOT_EXISTS;
|
||||||
|
import static dm.jdbc.util.DriverUtil.log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ERP生产版本 Service 实现类
|
* ERP生产版本 Service 实现类
|
||||||
@@ -29,6 +40,9 @@ public class ErpProductiveVersionServiceImpl implements ErpProductiveVersionServ
|
|||||||
@Resource
|
@Resource
|
||||||
private ErpProductiveVersionMapper erpProductiveVersionMapper;
|
private ErpProductiveVersionMapper erpProductiveVersionMapper;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ErpConfig erpConfig;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ErpProductiveVersionRespVO createErpProductiveVersion(ErpProductiveVersionSaveReqVO createReqVO) {
|
public ErpProductiveVersionRespVO createErpProductiveVersion(ErpProductiveVersionSaveReqVO createReqVO) {
|
||||||
// 插入
|
// 插入
|
||||||
@@ -86,4 +100,107 @@ public class ErpProductiveVersionServiceImpl implements ErpProductiveVersionServ
|
|||||||
return erpProductiveVersionMapper.selectPage(pageReqVO);
|
return erpProductiveVersionMapper.selectPage(pageReqVO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
@XxlJob("getErpProductiveVersionTask")
|
||||||
|
public void callErpRfcInterface() {
|
||||||
|
try {
|
||||||
|
OftenEnum.FuncnrEnum funcnrEnum =OftenEnum.FuncnrEnum.生产版本;
|
||||||
|
String funcnr = funcnrEnum.getFuncnr();
|
||||||
|
|
||||||
|
Map<String, Object> req = new HashMap<>();
|
||||||
|
JSONArray dataArrayALL = new JSONArray();
|
||||||
|
List<String> redisCache = erpConfig.getRedisCache(OftenEnum.FuncnrEnum.工厂信息.getFuncnr());
|
||||||
|
if (CollUtil.isEmpty(redisCache)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 1. 调用ERP接口获取数据
|
||||||
|
for (String number : redisCache) {
|
||||||
|
req.put("WERKS", number);
|
||||||
|
// 1. 调用ERP接口获取数据
|
||||||
|
JSONArray dataArray = erpConfig.fetchDataFromERP(funcnr, req);
|
||||||
|
if (dataArray == null || dataArray.isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
dataArrayALL.addAll(dataArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 处理公司数据,区分新增和更新
|
||||||
|
ProcessingResult result = processData(dataArrayALL,funcnrEnum);
|
||||||
|
|
||||||
|
// 3. 批量保存数据
|
||||||
|
saveData(result);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("调用ERP RFC接口失败: {}", e);
|
||||||
|
throw new RuntimeException("调用ERP RFC接口失败: " + e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理数据,区分新增和更新
|
||||||
|
*/
|
||||||
|
private ProcessingResult processData(JSONArray dataArray, OftenEnum.FuncnrEnum funcnr) {
|
||||||
|
String key = "erp" + funcnr.getFuncnr();
|
||||||
|
Map<String,List<String>> numbers = erpConfig.numbers(dataArray, key,funcnr.getDatakey());
|
||||||
|
List<String> allnumbers = numbers.get("all");
|
||||||
|
List<String> comnumbers = numbers.get("com");
|
||||||
|
List<ErpProductiveVersionDO> toUpdate = new ArrayList<>();
|
||||||
|
List<ErpProductiveVersionDO> toInsert = new ArrayList<>();
|
||||||
|
|
||||||
|
for (int i = 0; i < dataArray.size(); i++) {
|
||||||
|
JSONObject dataJson = dataArray.getJSONObject(i);
|
||||||
|
if (dataJson != null) {
|
||||||
|
String number = dataJson.getString("VERID").trim();
|
||||||
|
ErpProductiveVersionDO DO = new ErpProductiveVersionDO();
|
||||||
|
// DO.setFactoryNumber(dataJson.getString("MATNR"));
|
||||||
|
DO.setMaterialNumber(dataJson.getString("WERKS"));
|
||||||
|
DO.setProductiveVersionNumber(number);
|
||||||
|
DO.setProductiveVersionName(dataJson.getString("TEXT1"));
|
||||||
|
DO.setBomNumber(dataJson.getString("STLAL"));
|
||||||
|
DO.setBlineGroup(dataJson.getString("PLNNR"));
|
||||||
|
// DO.setGroupCount(dataJson.getString("ALNAL"));
|
||||||
|
if (comnumbers.contains(number)) {
|
||||||
|
// 更新
|
||||||
|
toUpdate.add(DO);
|
||||||
|
} else {
|
||||||
|
// 新增
|
||||||
|
toInsert.add(DO);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ProcessingResult(toUpdate, toInsert,key,allnumbers);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量保存数据
|
||||||
|
*/
|
||||||
|
private void saveData(ProcessingResult result) {
|
||||||
|
// 批量新增和更新
|
||||||
|
if (!result.toInsert.isEmpty()) {
|
||||||
|
erpProductiveVersionMapper.insertBatch(result.toInsert);
|
||||||
|
}
|
||||||
|
if (!result.toUpdate.isEmpty()) {
|
||||||
|
erpProductiveVersionMapper.updateBatch(result.toUpdate);
|
||||||
|
}
|
||||||
|
erpConfig.updateRedisCache(result.key,result.allnumbers);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据处理结果封装类
|
||||||
|
*/
|
||||||
|
private static class ProcessingResult {
|
||||||
|
private final List<ErpProductiveVersionDO> toUpdate;
|
||||||
|
private final List<ErpProductiveVersionDO> toInsert;
|
||||||
|
private final String key;
|
||||||
|
private final List<String> allnumbers;
|
||||||
|
|
||||||
|
public ProcessingResult(List<ErpProductiveVersionDO> toUpdate, List<ErpProductiveVersionDO> toInsert,String key,List<String> allnumbers) {
|
||||||
|
this.toUpdate = toUpdate;
|
||||||
|
this.toInsert = toInsert;
|
||||||
|
this.key = key;
|
||||||
|
this.allnumbers = allnumbers;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -61,4 +61,5 @@ public interface ErpPurchaseOrganizationService {
|
|||||||
*/
|
*/
|
||||||
PageResult<ErpPurchaseOrganizationDO> getErpPurchaseOrganizationPage(ErpPurchaseOrganizationPageReqVO pageReqVO);
|
PageResult<ErpPurchaseOrganizationDO> getErpPurchaseOrganizationPage(ErpPurchaseOrganizationPageReqVO pageReqVO);
|
||||||
|
|
||||||
|
void callErpRfcInterface();
|
||||||
}
|
}
|
||||||
@@ -3,19 +3,30 @@ package cn.iocoder.yudao.module.erp.service.erp;
|
|||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||||
|
import cn.iocoder.yudao.module.erp.common.conf.ErpConfig;
|
||||||
|
import cn.iocoder.yudao.module.erp.common.enums.OftenEnum;
|
||||||
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpPurchaseOrganizationPageReqVO;
|
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpPurchaseOrganizationPageReqVO;
|
||||||
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpPurchaseOrganizationRespVO;
|
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpPurchaseOrganizationRespVO;
|
||||||
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpPurchaseOrganizationSaveReqVO;
|
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpPurchaseOrganizationSaveReqVO;
|
||||||
import cn.iocoder.yudao.module.erp.dal.dataobject.erp.ErpPurchaseOrganizationDO;
|
import cn.iocoder.yudao.module.erp.dal.dataobject.erp.ErpPurchaseOrganizationDO;
|
||||||
|
import cn.iocoder.yudao.module.erp.dal.dataobject.erp.ErpPurchaseOrganizationDO;
|
||||||
import cn.iocoder.yudao.module.erp.dal.mysql.erp.ErpPurchaseOrganizationMapper;
|
import cn.iocoder.yudao.module.erp.dal.mysql.erp.ErpPurchaseOrganizationMapper;
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.xxl.job.core.handler.annotation.XxlJob;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.ERP_PURCHASE_ORGANIZATION_NOT_EXISTS;
|
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.ERP_PURCHASE_ORGANIZATION_NOT_EXISTS;
|
||||||
|
import static dm.jdbc.util.DriverUtil.log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ERP采购组织 Service 实现类
|
* ERP采购组织 Service 实现类
|
||||||
@@ -29,6 +40,9 @@ public class ErpPurchaseOrganizationServiceImpl implements ErpPurchaseOrganizati
|
|||||||
@Resource
|
@Resource
|
||||||
private ErpPurchaseOrganizationMapper erpPurchaseOrganizationMapper;
|
private ErpPurchaseOrganizationMapper erpPurchaseOrganizationMapper;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ErpConfig erpConfig;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ErpPurchaseOrganizationRespVO createErpPurchaseOrganization(ErpPurchaseOrganizationSaveReqVO createReqVO) {
|
public ErpPurchaseOrganizationRespVO createErpPurchaseOrganization(ErpPurchaseOrganizationSaveReqVO createReqVO) {
|
||||||
// 插入
|
// 插入
|
||||||
@@ -86,4 +100,101 @@ public class ErpPurchaseOrganizationServiceImpl implements ErpPurchaseOrganizati
|
|||||||
return erpPurchaseOrganizationMapper.selectPage(pageReqVO);
|
return erpPurchaseOrganizationMapper.selectPage(pageReqVO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
@XxlJob("getErpPurchaseOrganizationTask")
|
||||||
|
public void callErpRfcInterface() {
|
||||||
|
try {
|
||||||
|
OftenEnum.FuncnrEnum funcnrEnum =OftenEnum.FuncnrEnum.采购组织;
|
||||||
|
String funcnr = funcnrEnum.getFuncnr();
|
||||||
|
Map<String, Object> req = new HashMap<>();
|
||||||
|
JSONArray dataArrayALL = new JSONArray();
|
||||||
|
List<String> redisCache = erpConfig.getRedisCache(OftenEnum.FuncnrEnum.工厂信息.getFuncnr());
|
||||||
|
if (CollUtil.isEmpty(redisCache)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 1. 调用ERP接口获取数据
|
||||||
|
for (String number : redisCache) {
|
||||||
|
req.put("WERKS", number);
|
||||||
|
// 1. 调用ERP接口获取数据
|
||||||
|
JSONArray dataArray = erpConfig.fetchDataFromERP(funcnr, req);
|
||||||
|
if (dataArray == null || dataArray.isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
dataArrayALL.addAll(dataArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 处理公司数据,区分新增和更新
|
||||||
|
ProcessingResult result = processData(dataArrayALL,funcnrEnum);
|
||||||
|
|
||||||
|
// 3. 批量保存数据
|
||||||
|
saveData(result);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("调用ERP RFC接口失败: {}", e);
|
||||||
|
throw new RuntimeException("调用ERP RFC接口失败: " + e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理数据,区分新增和更新
|
||||||
|
*/
|
||||||
|
private ProcessingResult processData(JSONArray dataArray, OftenEnum.FuncnrEnum funcnr) {
|
||||||
|
String key = "erp" + funcnr.getFuncnr();
|
||||||
|
Map<String,List<String>> numbers = erpConfig.numbers(dataArray, key,funcnr.getDatakey());
|
||||||
|
List<String> allnumbers = numbers.get("all");
|
||||||
|
List<String> comnumbers = numbers.get("com");
|
||||||
|
List<ErpPurchaseOrganizationDO> toUpdate = new ArrayList<>();
|
||||||
|
List<ErpPurchaseOrganizationDO> toInsert = new ArrayList<>();
|
||||||
|
|
||||||
|
for (int i = 0; i < dataArray.size(); i++) {
|
||||||
|
JSONObject dataJson = dataArray.getJSONObject(i);
|
||||||
|
if (dataJson != null) {
|
||||||
|
String number = dataJson.getString("EKORG").trim();
|
||||||
|
ErpPurchaseOrganizationDO DO = new ErpPurchaseOrganizationDO();
|
||||||
|
DO.setName(dataJson.getString("EKOTX"));
|
||||||
|
DO.setNumber(number);
|
||||||
|
if (comnumbers.contains(number)) {
|
||||||
|
// 更新
|
||||||
|
toUpdate.add(DO);
|
||||||
|
} else {
|
||||||
|
// 新增
|
||||||
|
toInsert.add(DO);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ProcessingResult(toUpdate, toInsert,key,allnumbers);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量保存数据
|
||||||
|
*/
|
||||||
|
private void saveData(ProcessingResult result) {
|
||||||
|
// 批量新增和更新
|
||||||
|
if (!result.toInsert.isEmpty()) {
|
||||||
|
erpPurchaseOrganizationMapper.insertBatch(result.toInsert);
|
||||||
|
}
|
||||||
|
if (!result.toUpdate.isEmpty()) {
|
||||||
|
erpPurchaseOrganizationMapper.updateBatch(result.toUpdate);
|
||||||
|
}
|
||||||
|
erpConfig.updateRedisCache(result.key,result.allnumbers);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据处理结果封装类
|
||||||
|
*/
|
||||||
|
private static class ProcessingResult {
|
||||||
|
private final List<ErpPurchaseOrganizationDO> toUpdate;
|
||||||
|
private final List<ErpPurchaseOrganizationDO> toInsert;
|
||||||
|
private final String key;
|
||||||
|
private final List<String> allnumbers;
|
||||||
|
|
||||||
|
public ProcessingResult(List<ErpPurchaseOrganizationDO> toUpdate, List<ErpPurchaseOrganizationDO> toInsert,String key,List<String> allnumbers) {
|
||||||
|
this.toUpdate = toUpdate;
|
||||||
|
this.toInsert = toInsert;
|
||||||
|
this.key = key;
|
||||||
|
this.allnumbers = allnumbers;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -61,4 +61,5 @@ public interface ErpSalesOrganizationService {
|
|||||||
*/
|
*/
|
||||||
PageResult<ErpSalesOrganizationDO> getErpSalesOrganizationPage(ErpSalesOrganizationPageReqVO pageReqVO);
|
PageResult<ErpSalesOrganizationDO> getErpSalesOrganizationPage(ErpSalesOrganizationPageReqVO pageReqVO);
|
||||||
|
|
||||||
|
void callErpRfcInterface();
|
||||||
}
|
}
|
||||||
@@ -3,19 +3,30 @@ package cn.iocoder.yudao.module.erp.service.erp;
|
|||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||||
|
import cn.iocoder.yudao.module.erp.common.conf.ErpConfig;
|
||||||
|
import cn.iocoder.yudao.module.erp.common.enums.OftenEnum;
|
||||||
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpSalesOrganizationPageReqVO;
|
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpSalesOrganizationPageReqVO;
|
||||||
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpSalesOrganizationRespVO;
|
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpSalesOrganizationRespVO;
|
||||||
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpSalesOrganizationSaveReqVO;
|
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpSalesOrganizationSaveReqVO;
|
||||||
import cn.iocoder.yudao.module.erp.dal.dataobject.erp.ErpSalesOrganizationDO;
|
import cn.iocoder.yudao.module.erp.dal.dataobject.erp.ErpSalesOrganizationDO;
|
||||||
|
import cn.iocoder.yudao.module.erp.dal.dataobject.erp.ErpSalesOrganizationDO;
|
||||||
import cn.iocoder.yudao.module.erp.dal.mysql.erp.ErpSalesOrganizationMapper;
|
import cn.iocoder.yudao.module.erp.dal.mysql.erp.ErpSalesOrganizationMapper;
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.xxl.job.core.handler.annotation.XxlJob;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.ERP_SALES_ORGANIZATION_NOT_EXISTS;
|
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.ERP_SALES_ORGANIZATION_NOT_EXISTS;
|
||||||
|
import static dm.jdbc.util.DriverUtil.log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ERP销售组织 Service 实现类
|
* ERP销售组织 Service 实现类
|
||||||
@@ -29,6 +40,9 @@ public class ErpSalesOrganizationServiceImpl implements ErpSalesOrganizationServ
|
|||||||
@Resource
|
@Resource
|
||||||
private ErpSalesOrganizationMapper erpSalesOrganizationMapper;
|
private ErpSalesOrganizationMapper erpSalesOrganizationMapper;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ErpConfig erpConfig;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ErpSalesOrganizationRespVO createErpSalesOrganization(ErpSalesOrganizationSaveReqVO createReqVO) {
|
public ErpSalesOrganizationRespVO createErpSalesOrganization(ErpSalesOrganizationSaveReqVO createReqVO) {
|
||||||
// 插入
|
// 插入
|
||||||
@@ -86,4 +100,109 @@ public class ErpSalesOrganizationServiceImpl implements ErpSalesOrganizationServ
|
|||||||
return erpSalesOrganizationMapper.selectPage(pageReqVO);
|
return erpSalesOrganizationMapper.selectPage(pageReqVO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
@XxlJob("getErpSalesOrganizationTask")
|
||||||
|
public void callErpRfcInterface() {
|
||||||
|
try {
|
||||||
|
OftenEnum.FuncnrEnum funcnrEnum =OftenEnum.FuncnrEnum.销售组织;
|
||||||
|
String funcnr = funcnrEnum.getFuncnr();
|
||||||
|
Map<String, Object> req = new HashMap<>();
|
||||||
|
JSONArray dataArrayALL = new JSONArray();
|
||||||
|
List<String> redisCache = erpConfig.getRedisCache(OftenEnum.FuncnrEnum.公司代码.getFuncnr());
|
||||||
|
if (CollUtil.isEmpty(redisCache)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 1. 调用ERP接口获取数据
|
||||||
|
for (String number : redisCache) {
|
||||||
|
req.put("BUKRS", number);
|
||||||
|
// 1. 调用ERP接口获取数据
|
||||||
|
JSONArray dataArray = erpConfig.fetchDataFromERP(funcnr, req);
|
||||||
|
if (dataArray == null || dataArray.isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// 往每个子项中添加BUKRS字段
|
||||||
|
for (int j = 0; j < dataArray.size(); j++) {
|
||||||
|
JSONObject item = dataArray.getJSONObject(j);
|
||||||
|
if (item != null) {
|
||||||
|
item.put("BUKRS", number);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dataArrayALL.addAll(dataArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 处理公司数据,区分新增和更新
|
||||||
|
ProcessingResult result = processData(dataArrayALL,funcnrEnum);
|
||||||
|
|
||||||
|
// 3. 批量保存数据
|
||||||
|
saveData(result);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("调用ERP RFC接口失败: {}", e);
|
||||||
|
throw new RuntimeException("调用ERP RFC接口失败: " + e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理数据,区分新增和更新
|
||||||
|
*/
|
||||||
|
private ProcessingResult processData(JSONArray dataArray, OftenEnum.FuncnrEnum funcnr) {
|
||||||
|
String key = "erp" + funcnr.getFuncnr();
|
||||||
|
Map<String,List<String>> numbers = erpConfig.numbers(dataArray, key,funcnr.getDatakey());
|
||||||
|
List<String> allnumbers = numbers.get("all");
|
||||||
|
List<String> comnumbers = numbers.get("com");
|
||||||
|
List<ErpSalesOrganizationDO> toUpdate = new ArrayList<>();
|
||||||
|
List<ErpSalesOrganizationDO> toInsert = new ArrayList<>();
|
||||||
|
|
||||||
|
for (int i = 0; i < dataArray.size(); i++) {
|
||||||
|
JSONObject dataJson = dataArray.getJSONObject(i);
|
||||||
|
if (dataJson != null) {
|
||||||
|
String number = dataJson.getString("VKORG").trim();
|
||||||
|
ErpSalesOrganizationDO DO = new ErpSalesOrganizationDO();
|
||||||
|
DO.setName(dataJson.getString("VTEXT"));
|
||||||
|
DO.setNumber(number);
|
||||||
|
DO.setCompanyNumber(dataJson.getString("BUKRS"));
|
||||||
|
if (comnumbers.contains(number)) {
|
||||||
|
// 更新
|
||||||
|
toUpdate.add(DO);
|
||||||
|
} else {
|
||||||
|
// 新增
|
||||||
|
toInsert.add(DO);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ProcessingResult(toUpdate, toInsert,key,allnumbers);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量保存数据
|
||||||
|
*/
|
||||||
|
private void saveData(ProcessingResult result) {
|
||||||
|
// 批量新增和更新
|
||||||
|
if (!result.toInsert.isEmpty()) {
|
||||||
|
erpSalesOrganizationMapper.insertBatch(result.toInsert);
|
||||||
|
}
|
||||||
|
if (!result.toUpdate.isEmpty()) {
|
||||||
|
erpSalesOrganizationMapper.updateBatch(result.toUpdate);
|
||||||
|
}
|
||||||
|
erpConfig.updateRedisCache(result.key,result.allnumbers);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据处理结果封装类
|
||||||
|
*/
|
||||||
|
private static class ProcessingResult {
|
||||||
|
private final List<ErpSalesOrganizationDO> toUpdate;
|
||||||
|
private final List<ErpSalesOrganizationDO> toInsert;
|
||||||
|
private final String key;
|
||||||
|
private final List<String> allnumbers;
|
||||||
|
|
||||||
|
public ProcessingResult(List<ErpSalesOrganizationDO> toUpdate, List<ErpSalesOrganizationDO> toInsert,String key,List<String> allnumbers) {
|
||||||
|
this.toUpdate = toUpdate;
|
||||||
|
this.toInsert = toInsert;
|
||||||
|
this.key = key;
|
||||||
|
this.allnumbers = allnumbers;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -61,4 +61,5 @@ public interface ErpWarehouseService {
|
|||||||
*/
|
*/
|
||||||
PageResult<ErpWarehouseDO> getErpWarehousePage(ErpWarehousePageReqVO pageReqVO);
|
PageResult<ErpWarehouseDO> getErpWarehousePage(ErpWarehousePageReqVO pageReqVO);
|
||||||
|
|
||||||
|
void callErpRfcInterface();
|
||||||
}
|
}
|
||||||
@@ -3,19 +3,30 @@ package cn.iocoder.yudao.module.erp.service.erp;
|
|||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||||
|
import cn.iocoder.yudao.module.erp.common.conf.ErpConfig;
|
||||||
|
import cn.iocoder.yudao.module.erp.common.enums.OftenEnum;
|
||||||
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpWarehousePageReqVO;
|
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpWarehousePageReqVO;
|
||||||
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpWarehouseRespVO;
|
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpWarehouseRespVO;
|
||||||
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpWarehouseSaveReqVO;
|
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpWarehouseSaveReqVO;
|
||||||
import cn.iocoder.yudao.module.erp.dal.dataobject.erp.ErpWarehouseDO;
|
import cn.iocoder.yudao.module.erp.dal.dataobject.erp.ErpWarehouseDO;
|
||||||
|
import cn.iocoder.yudao.module.erp.dal.dataobject.erp.ErpWarehouseDO;
|
||||||
import cn.iocoder.yudao.module.erp.dal.mysql.erp.ErpWarehouseMapper;
|
import cn.iocoder.yudao.module.erp.dal.mysql.erp.ErpWarehouseMapper;
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.xxl.job.core.handler.annotation.XxlJob;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.ERP_WAREHOUSE_NOT_EXISTS;
|
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.ERP_WAREHOUSE_NOT_EXISTS;
|
||||||
|
import static dm.jdbc.util.DriverUtil.log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ERP库位 Service 实现类
|
* ERP库位 Service 实现类
|
||||||
@@ -29,6 +40,9 @@ public class ErpWarehouseServiceImpl implements ErpWarehouseService {
|
|||||||
@Resource
|
@Resource
|
||||||
private ErpWarehouseMapper erpWarehouseMapper;
|
private ErpWarehouseMapper erpWarehouseMapper;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ErpConfig erpConfig;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ErpWarehouseRespVO createErpWarehouse(ErpWarehouseSaveReqVO createReqVO) {
|
public ErpWarehouseRespVO createErpWarehouse(ErpWarehouseSaveReqVO createReqVO) {
|
||||||
// 插入
|
// 插入
|
||||||
@@ -86,4 +100,110 @@ public class ErpWarehouseServiceImpl implements ErpWarehouseService {
|
|||||||
return erpWarehouseMapper.selectPage(pageReqVO);
|
return erpWarehouseMapper.selectPage(pageReqVO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
@XxlJob("getErpWarehouseTask")
|
||||||
|
public void callErpRfcInterface() {
|
||||||
|
try {
|
||||||
|
OftenEnum.FuncnrEnum funcnrEnum =OftenEnum.FuncnrEnum.库位信息;
|
||||||
|
String funcnr = funcnrEnum.getFuncnr();
|
||||||
|
Map<String, Object> req = new HashMap<>();
|
||||||
|
JSONArray dataArrayALL = new JSONArray();
|
||||||
|
List<String> redisCache = erpConfig.getRedisCache(OftenEnum.FuncnrEnum.工厂信息.getFuncnr());
|
||||||
|
if (CollUtil.isEmpty(redisCache)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 1. 调用ERP接口获取数据
|
||||||
|
for (String number : redisCache) {
|
||||||
|
req.put("WERKS", number);
|
||||||
|
// 1. 调用ERP接口获取数据
|
||||||
|
JSONArray dataArray = erpConfig.fetchDataFromERP(funcnr, req);
|
||||||
|
if (dataArray == null || dataArray.isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// 往每个子项中添加BUKRS字段
|
||||||
|
for (int j = 0; j < dataArray.size(); j++) {
|
||||||
|
JSONObject item = dataArray.getJSONObject(j);
|
||||||
|
if (item != null) {
|
||||||
|
item.put("WERKS", number);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dataArrayALL.addAll(dataArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 处理公司数据,区分新增和更新
|
||||||
|
ProcessingResult result = processData(dataArrayALL,funcnrEnum);
|
||||||
|
|
||||||
|
// 3. 批量保存数据
|
||||||
|
saveData(result);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("调用ERP RFC接口失败: {}", e);
|
||||||
|
throw new RuntimeException("调用ERP RFC接口失败: " + e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理数据,区分新增和更新
|
||||||
|
*/
|
||||||
|
private ProcessingResult processData(JSONArray dataArray, OftenEnum.FuncnrEnum funcnr) {
|
||||||
|
String key = "erp" + funcnr.getFuncnr();
|
||||||
|
Map<String,List<String>> numbers = erpConfig.numbers(dataArray, key,funcnr.getDatakey());
|
||||||
|
List<String> allnumbers = numbers.get("all");
|
||||||
|
List<String> comnumbers = numbers.get("com");
|
||||||
|
List<ErpWarehouseDO> toUpdate = new ArrayList<>();
|
||||||
|
List<ErpWarehouseDO> toInsert = new ArrayList<>();
|
||||||
|
|
||||||
|
for (int i = 0; i < dataArray.size(); i++) {
|
||||||
|
JSONObject dataJson = dataArray.getJSONObject(i);
|
||||||
|
if (dataJson != null) {
|
||||||
|
String number = dataJson.getString("LGORT").trim();
|
||||||
|
ErpWarehouseDO DO = new ErpWarehouseDO();
|
||||||
|
DO.setName(dataJson.getString("LGOBE"));
|
||||||
|
DO.setNumber(number);
|
||||||
|
DO.setFactoryNumber(dataJson.getString("WERKS"));
|
||||||
|
if (comnumbers.contains(number)) {
|
||||||
|
// 更新
|
||||||
|
toUpdate.add(DO);
|
||||||
|
} else {
|
||||||
|
// 新增
|
||||||
|
toInsert.add(DO);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ProcessingResult(toUpdate, toInsert,key,allnumbers);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量保存数据
|
||||||
|
*/
|
||||||
|
private void saveData(ProcessingResult result) {
|
||||||
|
// 批量新增和更新
|
||||||
|
if (!result.toInsert.isEmpty()) {
|
||||||
|
erpWarehouseMapper.insertBatch(result.toInsert);
|
||||||
|
}
|
||||||
|
if (!result.toUpdate.isEmpty()) {
|
||||||
|
erpWarehouseMapper.updateBatch(result.toUpdate);
|
||||||
|
}
|
||||||
|
erpConfig.updateRedisCache(result.key,result.allnumbers);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据处理结果封装类
|
||||||
|
*/
|
||||||
|
private static class ProcessingResult {
|
||||||
|
private final List<ErpWarehouseDO> toUpdate;
|
||||||
|
private final List<ErpWarehouseDO> toInsert;
|
||||||
|
private final String key;
|
||||||
|
private final List<String> allnumbers;
|
||||||
|
|
||||||
|
public ProcessingResult(List<ErpWarehouseDO> toUpdate, List<ErpWarehouseDO> toInsert,String key,List<String> allnumbers) {
|
||||||
|
this.toUpdate = toUpdate;
|
||||||
|
this.toInsert = toInsert;
|
||||||
|
this.key = key;
|
||||||
|
this.allnumbers = allnumbers;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -8,5 +8,23 @@
|
|||||||
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
|
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
|
||||||
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
||||||
-->
|
-->
|
||||||
|
<update id="updateBatch">
|
||||||
|
UPDATE sply_erp_ast
|
||||||
|
<set>
|
||||||
|
NAME = CASE
|
||||||
|
<foreach collection="toUpdate" item="item">
|
||||||
|
WHEN CPN_NUM = #{item.companyNumber} AND MAIN_AST_NUM = #{item.mainAssetNumber} THEN #{item.name}
|
||||||
|
</foreach>
|
||||||
|
END,
|
||||||
|
CPN_ID = CASE
|
||||||
|
<foreach collection="toUpdate" item="item">
|
||||||
|
WHEN CPN_NUM = #{item.companyNumber} AND MAIN_AST_NUM = #{item.mainAssetNumber} THEN #{item.companyId}
|
||||||
|
</foreach>
|
||||||
|
END
|
||||||
|
</set>
|
||||||
|
WHERE (CPN_NUM, MAIN_AST_NUM) IN
|
||||||
|
<foreach collection="toUpdate" item="item" open="(" separator="," close=")">
|
||||||
|
#{item.companyNumber}, #{item.mainAssetNumber}
|
||||||
|
</foreach>
|
||||||
|
</update>
|
||||||
</mapper>
|
</mapper>
|
||||||
@@ -9,4 +9,14 @@
|
|||||||
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
||||||
-->
|
-->
|
||||||
|
|
||||||
|
<update id="updateBatch">
|
||||||
|
<foreach collection="toUpdate" item="item" separator=";">
|
||||||
|
UPDATE sply_erp_fact
|
||||||
|
<set>
|
||||||
|
<if test="item.name != null">NAME = #{item.name},</if>
|
||||||
|
<if test="item.number != null">CPN_ID = #{item.companyId},</if>
|
||||||
|
</set>
|
||||||
|
WHERE NUM = #{item.number}
|
||||||
|
</foreach>
|
||||||
|
</update>
|
||||||
</mapper>
|
</mapper>
|
||||||
@@ -9,4 +9,14 @@
|
|||||||
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
||||||
-->
|
-->
|
||||||
|
|
||||||
|
<update id="updateBatch">
|
||||||
|
<foreach collection="toUpdate" item="item" separator=";">
|
||||||
|
UPDATE sply_erp_fact
|
||||||
|
<set>
|
||||||
|
<if test="item.name != null">NAME = #{item.name},</if>
|
||||||
|
<if test="item.number != null">CPN_ID = #{item.companyId},</if>
|
||||||
|
</set>
|
||||||
|
WHERE NUM = #{item.number}
|
||||||
|
</foreach>
|
||||||
|
</update>
|
||||||
</mapper>
|
</mapper>
|
||||||
@@ -9,4 +9,14 @@
|
|||||||
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
||||||
-->
|
-->
|
||||||
|
|
||||||
|
<update id="updateBatch">
|
||||||
|
<foreach collection="toUpdate" item="item" separator=";">
|
||||||
|
UPDATE sply_erp_fact
|
||||||
|
<set>
|
||||||
|
<if test="item.name != null">NAME = #{item.name},</if>
|
||||||
|
<if test="item.number != null">CPN_ID = #{item.companyId},</if>
|
||||||
|
</set>
|
||||||
|
WHERE NUM = #{item.number}
|
||||||
|
</foreach>
|
||||||
|
</update>
|
||||||
</mapper>
|
</mapper>
|
||||||
@@ -9,4 +9,14 @@
|
|||||||
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
||||||
-->
|
-->
|
||||||
|
|
||||||
|
<update id="updateBatch">
|
||||||
|
<foreach collection="toUpdate" item="item" separator=";">
|
||||||
|
UPDATE sply_erp_fact
|
||||||
|
<set>
|
||||||
|
<if test="item.name != null">NAME = #{item.name},</if>
|
||||||
|
<if test="item.number != null">CPN_ID = #{item.companyId},</if>
|
||||||
|
</set>
|
||||||
|
WHERE NUM = #{item.number}
|
||||||
|
</foreach>
|
||||||
|
</update>
|
||||||
</mapper>
|
</mapper>
|
||||||
@@ -9,4 +9,14 @@
|
|||||||
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
||||||
-->
|
-->
|
||||||
|
|
||||||
|
<update id="updateBatch">
|
||||||
|
<foreach collection="toUpdate" item="item" separator=";">
|
||||||
|
UPDATE sply_erp_fact
|
||||||
|
<set>
|
||||||
|
<if test="item.name != null">NAME = #{item.name},</if>
|
||||||
|
<if test="item.number != null">CPN_ID = #{item.companyId},</if>
|
||||||
|
</set>
|
||||||
|
WHERE NUM = #{item.number}
|
||||||
|
</foreach>
|
||||||
|
</update>
|
||||||
</mapper>
|
</mapper>
|
||||||
@@ -9,4 +9,14 @@
|
|||||||
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
||||||
-->
|
-->
|
||||||
|
|
||||||
|
<update id="updateBatch">
|
||||||
|
<foreach collection="toUpdate" item="item" separator=";">
|
||||||
|
UPDATE sply_erp_fact
|
||||||
|
<set>
|
||||||
|
<if test="item.name != null">NAME = #{item.name},</if>
|
||||||
|
<if test="item.number != null">CPN_ID = #{item.companyId},</if>
|
||||||
|
</set>
|
||||||
|
WHERE NUM = #{item.number}
|
||||||
|
</foreach>
|
||||||
|
</update>
|
||||||
</mapper>
|
</mapper>
|
||||||
@@ -9,4 +9,14 @@
|
|||||||
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
||||||
-->
|
-->
|
||||||
|
|
||||||
|
<update id="updateBatch">
|
||||||
|
<foreach collection="toUpdate" item="item" separator=";">
|
||||||
|
UPDATE sply_erp_fact
|
||||||
|
<set>
|
||||||
|
<if test="item.name != null">NAME = #{item.name},</if>
|
||||||
|
<if test="item.number != null">CPN_ID = #{item.companyId},</if>
|
||||||
|
</set>
|
||||||
|
WHERE NUM = #{item.number}
|
||||||
|
</foreach>
|
||||||
|
</update>
|
||||||
</mapper>
|
</mapper>
|
||||||
@@ -9,4 +9,14 @@
|
|||||||
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
||||||
-->
|
-->
|
||||||
|
|
||||||
|
<update id="updateBatch">
|
||||||
|
<foreach collection="toUpdate" item="item" separator=";">
|
||||||
|
UPDATE sply_erp_fact
|
||||||
|
<set>
|
||||||
|
<if test="item.name != null">NAME = #{item.name},</if>
|
||||||
|
<if test="item.number != null">CPN_ID = #{item.companyId},</if>
|
||||||
|
</set>
|
||||||
|
WHERE NUM = #{item.number}
|
||||||
|
</foreach>
|
||||||
|
</update>
|
||||||
</mapper>
|
</mapper>
|
||||||
@@ -9,4 +9,14 @@
|
|||||||
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
||||||
-->
|
-->
|
||||||
|
|
||||||
|
<update id="updateBatch">
|
||||||
|
<foreach collection="toUpdate" item="item" separator=";">
|
||||||
|
UPDATE sply_erp_fact
|
||||||
|
<set>
|
||||||
|
<if test="item.name != null">NAME = #{item.name},</if>
|
||||||
|
<if test="item.number != null">CPN_ID = #{item.companyId},</if>
|
||||||
|
</set>
|
||||||
|
WHERE NUM = #{item.number}
|
||||||
|
</foreach>
|
||||||
|
</update>
|
||||||
</mapper>
|
</mapper>
|
||||||
@@ -9,4 +9,14 @@
|
|||||||
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
||||||
-->
|
-->
|
||||||
|
|
||||||
|
<update id="updateBatch">
|
||||||
|
<foreach collection="toUpdate" item="item" separator=";">
|
||||||
|
UPDATE sply_erp_fact
|
||||||
|
<set>
|
||||||
|
<if test="item.name != null">NAME = #{item.name},</if>
|
||||||
|
<if test="item.number != null">CPN_ID = #{item.companyId},</if>
|
||||||
|
</set>
|
||||||
|
WHERE NUM = #{item.number}
|
||||||
|
</foreach>
|
||||||
|
</update>
|
||||||
</mapper>
|
</mapper>
|
||||||
@@ -9,4 +9,14 @@
|
|||||||
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
||||||
-->
|
-->
|
||||||
|
|
||||||
|
<update id="updateBatch">
|
||||||
|
<foreach collection="toUpdate" item="item" separator=";">
|
||||||
|
UPDATE sply_erp_fact
|
||||||
|
<set>
|
||||||
|
<if test="item.name != null">NAME = #{item.name},</if>
|
||||||
|
<if test="item.number != null">CPN_ID = #{item.companyId},</if>
|
||||||
|
</set>
|
||||||
|
WHERE NUM = #{item.number}
|
||||||
|
</foreach>
|
||||||
|
</update>
|
||||||
</mapper>
|
</mapper>
|
||||||
@@ -9,4 +9,14 @@
|
|||||||
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
||||||
-->
|
-->
|
||||||
|
|
||||||
|
<update id="updateBatch">
|
||||||
|
<foreach collection="toUpdate" item="item" separator=";">
|
||||||
|
UPDATE sply_erp_fact
|
||||||
|
<set>
|
||||||
|
<if test="item.name != null">NAME = #{item.name},</if>
|
||||||
|
<if test="item.number != null">CPN_ID = #{item.companyId},</if>
|
||||||
|
</set>
|
||||||
|
WHERE NUM = #{item.number}
|
||||||
|
</foreach>
|
||||||
|
</update>
|
||||||
</mapper>
|
</mapper>
|
||||||
@@ -9,4 +9,14 @@
|
|||||||
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
||||||
-->
|
-->
|
||||||
|
|
||||||
|
<update id="updateBatch">
|
||||||
|
<foreach collection="toUpdate" item="item" separator=";">
|
||||||
|
UPDATE sply_erp_fact
|
||||||
|
<set>
|
||||||
|
<if test="item.name != null">NAME = #{item.name},</if>
|
||||||
|
<if test="item.number != null">CPN_ID = #{item.companyId},</if>
|
||||||
|
</set>
|
||||||
|
WHERE NUM = #{item.number}
|
||||||
|
</foreach>
|
||||||
|
</update>
|
||||||
</mapper>
|
</mapper>
|
||||||
@@ -9,4 +9,14 @@
|
|||||||
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
||||||
-->
|
-->
|
||||||
|
|
||||||
|
<update id="updateBatch">
|
||||||
|
<foreach collection="toUpdate" item="item" separator=";">
|
||||||
|
UPDATE sply_erp_fact
|
||||||
|
<set>
|
||||||
|
<if test="item.name != null">NAME = #{item.name},</if>
|
||||||
|
<if test="item.number != null">CPN_ID = #{item.companyId},</if>
|
||||||
|
</set>
|
||||||
|
WHERE NUM = #{item.number}
|
||||||
|
</foreach>
|
||||||
|
</update>
|
||||||
</mapper>
|
</mapper>
|
||||||
@@ -9,4 +9,14 @@
|
|||||||
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
||||||
-->
|
-->
|
||||||
|
|
||||||
|
<update id="updateBatch">
|
||||||
|
<foreach collection="toUpdate" item="item" separator=";">
|
||||||
|
UPDATE sply_erp_fact
|
||||||
|
<set>
|
||||||
|
<if test="item.name != null">NAME = #{item.name},</if>
|
||||||
|
<if test="item.number != null">CPN_ID = #{item.companyId},</if>
|
||||||
|
</set>
|
||||||
|
WHERE NUM = #{item.number}
|
||||||
|
</foreach>
|
||||||
|
</update>
|
||||||
</mapper>
|
</mapper>
|
||||||
Reference in New Issue
Block a user