feat(wms): 添加 MDM 主数据平台与 LMS 接口功能
- 新增 CommonResponseDto 类用于统一返回消息格式 - 添加 MdmToLmsController 控制器处理 MDM 与 LMS 之间的接口请求 - 实现 MdmToLmsService接口和 MdmToLmsServiceImpl 实现类,提供客户、供应商和物料信息的传输功能- 新增 ResponseItemsData 类用于封装响应项数据 - 定义 StatusEnum 枚举表示接口状态码 - 在 logback-spring.xml 中添加 MDM 日志配置
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,34 @@
|
|||||||
|
package org.nl.wms.ext.mdm.entity;
|
||||||
|
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author Eric.Yang
|
||||||
|
* @Version V1.1
|
||||||
|
* @Date 2025/5/29
|
||||||
|
* @Description 处理状态统一返回消息类
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class CommonResponseDto {
|
||||||
|
//状态
|
||||||
|
private String status;
|
||||||
|
//描述
|
||||||
|
private String message;
|
||||||
|
//处理结果集合
|
||||||
|
private List<ResponseItemsData> responseData;
|
||||||
|
|
||||||
|
/**
|
||||||
|
统一返回消息类 构造
|
||||||
|
*/
|
||||||
|
public static CommonResponseDto adapter(String status,String message,List<ResponseItemsData> responseData) {
|
||||||
|
CommonResponseDto commonResponseDto = new CommonResponseDto();
|
||||||
|
commonResponseDto.setStatus(status);
|
||||||
|
commonResponseDto.setMessage(message);
|
||||||
|
commonResponseDto.setResponseData(responseData);
|
||||||
|
return commonResponseDto;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package org.nl.wms.ext.mdm.entity;
|
||||||
|
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class ResponseItemsData {
|
||||||
|
//主数据唯一主键
|
||||||
|
private Long mdId;
|
||||||
|
//主数据编码
|
||||||
|
private String mdCode;
|
||||||
|
//主数据描述
|
||||||
|
private String mdDescription;
|
||||||
|
//处理状态
|
||||||
|
private String status;
|
||||||
|
//处理状态描述
|
||||||
|
private String message;
|
||||||
|
|
||||||
|
/**
|
||||||
|
统一构造方法
|
||||||
|
*/
|
||||||
|
public static ResponseItemsData adapter(Long mdId,String mdCode,String mdDescription,String status,String message){
|
||||||
|
ResponseItemsData responseItemsData = new ResponseItemsData();
|
||||||
|
responseItemsData.setMdId(mdId);
|
||||||
|
responseItemsData.setMdCode(mdCode);
|
||||||
|
responseItemsData.setMdDescription(mdDescription);
|
||||||
|
responseItemsData.setStatus(status);
|
||||||
|
responseItemsData.setMessage(message);
|
||||||
|
return responseItemsData;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package org.nl.wms.ext.mdm.entity;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author Eric.Yang
|
||||||
|
* @Version V1.1
|
||||||
|
* @Date 2025/6/10
|
||||||
|
* @Description 接口状态统一码
|
||||||
|
*/
|
||||||
|
public enum StatusEnum {
|
||||||
|
INSERT_SUCCESS("S", "新增成功"),
|
||||||
|
UPDATE_SUCCESS("S", "更新成功"),
|
||||||
|
ACCEPT_SUCCESS("S", "接受成功"),
|
||||||
|
ACCEPT_FAIL("E", "接受失败");
|
||||||
|
|
||||||
|
private String code;
|
||||||
|
private String message;
|
||||||
|
StatusEnum(String code, String message) {
|
||||||
|
this.code = code;
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
public String getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
public String getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
package org.nl.wms.ext.mdm.rest;
|
||||||
|
|
||||||
|
|
||||||
|
import cn.dev33.satoken.annotation.SaIgnore;
|
||||||
|
import cn.dev33.satoken.stp.StpUtil;
|
||||||
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.nl.modules.logging.annotation.Log;
|
||||||
|
import org.nl.wms.ext.mdm.entity.CommonResponseDto;
|
||||||
|
import org.nl.wms.ext.mdm.service.MdmToLmsService;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Eric.Yang
|
||||||
|
* @version V1.1
|
||||||
|
* @Date 2025/5/29
|
||||||
|
* @Description MDM主数据平台与LMS接口
|
||||||
|
*/
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/mdm")
|
||||||
|
@Slf4j
|
||||||
|
@SaIgnore
|
||||||
|
public class MdmToLmsController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private MdmToLmsService mdmToLmsService;
|
||||||
|
|
||||||
|
@PostMapping("/transCustomerInfo")
|
||||||
|
@Log("MDM给LMS推送客户信息")
|
||||||
|
public CommonResponseDto transCustomerInfo(@RequestBody JSONObject jsonData){
|
||||||
|
return mdmToLmsService.transCustomerInfo(jsonData);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@PostMapping("/transSupplierInfo")
|
||||||
|
@Log("MDM给LMS推送供应商信息")
|
||||||
|
public CommonResponseDto transSupplierInfo(@RequestBody JSONObject jsonData){
|
||||||
|
return mdmToLmsService.transSupplierInfo(jsonData);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/transMaterialInfo")
|
||||||
|
@Log("MDM给LMS推送物料主数据信息")
|
||||||
|
public CommonResponseDto transMaterialInfo(@RequestBody JSONObject jsonData){
|
||||||
|
return mdmToLmsService.transMaterialInfo(jsonData);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package org.nl.wms.ext.mdm.service;
|
||||||
|
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import org.nl.wms.ext.mdm.entity.CommonResponseDto;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface MdmToLmsService {
|
||||||
|
|
||||||
|
CommonResponseDto transCustomerInfo(JSONObject jsonData);
|
||||||
|
|
||||||
|
CommonResponseDto transSupplierInfo(JSONObject jsonData);
|
||||||
|
|
||||||
|
CommonResponseDto transMaterialInfo(JSONObject jsonData);
|
||||||
|
}
|
||||||
@@ -0,0 +1,327 @@
|
|||||||
|
package org.nl.wms.ext.mdm.service.impl;
|
||||||
|
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import cn.hutool.core.util.IdUtil;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.compress.utils.Lists;
|
||||||
|
import org.nl.common.utils.SecurityUtils;
|
||||||
|
import org.nl.modules.common.exception.BadRequestException;
|
||||||
|
import org.nl.modules.wql.core.bean.WQLObject;
|
||||||
|
import org.nl.wms.ext.mdm.entity.CommonResponseDto;
|
||||||
|
import org.nl.wms.ext.mdm.entity.ResponseItemsData;
|
||||||
|
import org.nl.wms.ext.mdm.entity.StatusEnum;
|
||||||
|
import org.nl.wms.ext.mdm.service.MdmToLmsService;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author Eric.Yang
|
||||||
|
* @Version V1.1
|
||||||
|
* @Date 2025/5/29
|
||||||
|
* @Description MDM数据对接接口业务实现类
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
public class MdmToLmsServiceImpl implements MdmToLmsService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: MDM客户主数据接口
|
||||||
|
* @Author Eric.Yang
|
||||||
|
* @Date: 2025/6/3 9:12
|
||||||
|
**/
|
||||||
|
@Override
|
||||||
|
public CommonResponseDto transCustomerInfo(JSONObject jsonData) {
|
||||||
|
log.info("MDM客户主数据业务请求参数为:{}", jsonData);
|
||||||
|
CommonResponseDto commonResponseDto = new CommonResponseDto();
|
||||||
|
boolean flag = true;
|
||||||
|
if(CollectionUtil.isEmpty(jsonData)){
|
||||||
|
commonResponseDto.setStatus("E");
|
||||||
|
commonResponseDto.setMessage("MDM传输数据为空!");
|
||||||
|
return commonResponseDto;
|
||||||
|
}
|
||||||
|
List<ResponseItemsData> responseItemsData = Lists.newArrayList();
|
||||||
|
JSONArray customers = jsonData.getJSONArray("customer");
|
||||||
|
if(CollectionUtil.isNotEmpty(customers)){
|
||||||
|
for (int i = 0; i < customers.size(); i++) {
|
||||||
|
JSONObject json = customers.getJSONObject(i);
|
||||||
|
//主编码主键
|
||||||
|
long mdId = json.getLongValue("mdId");
|
||||||
|
//客户编号
|
||||||
|
String mdCode = json.getString("mdCode");
|
||||||
|
//主数据描述
|
||||||
|
String mdDescription = json.getString("mdDescription");
|
||||||
|
try {
|
||||||
|
//客户名称
|
||||||
|
String customerName = json.getString("customerName");
|
||||||
|
//核心字段判断
|
||||||
|
if (StrUtil.isEmpty(mdCode) || StrUtil.isEmpty(customerName)) {
|
||||||
|
throw new BadRequestException("MDM->客户编码或名称不能为空!");
|
||||||
|
}
|
||||||
|
//客户简称
|
||||||
|
String abbreviation = json.getString("abbreviation");
|
||||||
|
//客户状态
|
||||||
|
String customerStatus = json.getString("customerStatus");
|
||||||
|
JSONArray salesOrgs = json.getJSONArray("salesOrg");
|
||||||
|
if (CollectionUtil.isEmpty(salesOrgs)) {
|
||||||
|
throw new BadRequestException("MDM->客户数据核心字段数据为空,缺失字段:[salesOrgs]!");
|
||||||
|
}
|
||||||
|
JSONObject salesOrg = salesOrgs.getJSONObject(0);
|
||||||
|
JSONArray salesList = salesOrg.getJSONArray("sales");
|
||||||
|
if (CollectionUtil.isEmpty(salesList)) {
|
||||||
|
throw new BadRequestException("MDM->客户数据核心字段数据为空,缺失字段:[sales]!");
|
||||||
|
}
|
||||||
|
JSONObject sales = salesList.getJSONObject(0);
|
||||||
|
JSONArray parList = sales.getJSONArray("par");
|
||||||
|
if (CollectionUtil.isEmpty(parList)) {
|
||||||
|
throw new BadRequestException("MDM->客户数据核心字段数据为空,缺失字段:[par]!");
|
||||||
|
}
|
||||||
|
JSONObject par = parList.getJSONObject(0);
|
||||||
|
//业务员工号
|
||||||
|
String empSupplier = par.getString("empSupplier");
|
||||||
|
//业务员名称
|
||||||
|
String empSupplierDesc = par.getString("empSupplierDesc");
|
||||||
|
|
||||||
|
//todo 后续确认这个步骤的作用,考虑是否移除该步骤
|
||||||
|
JSONObject jo = new JSONObject();
|
||||||
|
jo.put("id", mdId);
|
||||||
|
jo.put("customer_name", mdCode);
|
||||||
|
jo.put("description", customerName);
|
||||||
|
jo.put("company", abbreviation);
|
||||||
|
jo.put("mdm_status", customerStatus);
|
||||||
|
String sales_owner = StrUtil.join("|",empSupplier,empSupplierDesc);
|
||||||
|
jo.put("sales_owner", sales_owner);
|
||||||
|
WQLObject.getWQLObject("md_cs_customerbaseproc").insert(jo);
|
||||||
|
log.info("MDM客户接口表处理数据:{}", jo);
|
||||||
|
//插入客户表
|
||||||
|
String currentUserId = SecurityUtils.getCurrentUserId();
|
||||||
|
String now = DateUtil.now();
|
||||||
|
|
||||||
|
JSONObject customer_jo = WQLObject.getWQLObject("md_cs_customerbase").query("cust_code = '" + mdCode + "'").uniqueResult(0);
|
||||||
|
if (ObjectUtil.isEmpty(customer_jo)) {
|
||||||
|
customer_jo = new JSONObject();
|
||||||
|
customer_jo.put("cust_id", mdId);
|
||||||
|
customer_jo.put("cust_code", mdCode);
|
||||||
|
customer_jo.put("cust_name", customerName);
|
||||||
|
customer_jo.put("cust_simple_name", abbreviation);
|
||||||
|
customer_jo.put("mdm_status", customerStatus);
|
||||||
|
customer_jo.put("sales_owner", sales_owner);
|
||||||
|
customer_jo.put("create_id", currentUserId);
|
||||||
|
customer_jo.put("create_name", "mdmAdmin");
|
||||||
|
customer_jo.put("create_time", now);
|
||||||
|
WQLObject.getWQLObject("md_cs_customerbase").insert(customer_jo);
|
||||||
|
ResponseItemsData itemsData = ResponseItemsData.adapter(mdId, mdCode, mdDescription, StatusEnum.INSERT_SUCCESS.getCode(), StatusEnum.INSERT_SUCCESS.getMessage());
|
||||||
|
responseItemsData.add(itemsData);
|
||||||
|
} else {
|
||||||
|
customer_jo.put("cust_name", customerName);
|
||||||
|
customer_jo.put("cust_simple_name", abbreviation);
|
||||||
|
customer_jo.put("sales_owner", sales_owner);
|
||||||
|
customer_jo.put("update_optid", currentUserId);
|
||||||
|
customer_jo.put("update_optname", "mdmAdmin");
|
||||||
|
customer_jo.put("mdm_status", customerStatus);
|
||||||
|
customer_jo.put("update_time", now);
|
||||||
|
WQLObject.getWQLObject("md_cs_customerbase").update(customer_jo);
|
||||||
|
ResponseItemsData itemsData = ResponseItemsData.adapter(mdId, mdCode, mdDescription, StatusEnum.UPDATE_SUCCESS.getCode(), StatusEnum.UPDATE_SUCCESS.getMessage());
|
||||||
|
responseItemsData.add(itemsData);
|
||||||
|
}
|
||||||
|
}catch (Exception e) {
|
||||||
|
//获取抛出异常的信息
|
||||||
|
String message = e.getMessage();
|
||||||
|
flag= false;
|
||||||
|
ResponseItemsData itemsData = ResponseItemsData.adapter(mdId, mdCode, mdDescription, StatusEnum.ACCEPT_FAIL.getCode(),message.contains("MDM")?message:StatusEnum.ACCEPT_FAIL.getMessage());
|
||||||
|
responseItemsData.add(itemsData);
|
||||||
|
log.error("MDM客户数据接口业务实现类处理数据异常", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
commonResponseDto.setStatus(flag ? StatusEnum.ACCEPT_SUCCESS.getCode() : StatusEnum.ACCEPT_FAIL.getCode());
|
||||||
|
commonResponseDto.setMessage(flag ? StatusEnum.ACCEPT_SUCCESS.getMessage() : StatusEnum.ACCEPT_FAIL.getMessage());
|
||||||
|
commonResponseDto.setResponseData(responseItemsData);
|
||||||
|
return commonResponseDto;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: MDM供应商主数据接口
|
||||||
|
* @Author Eric.Yang
|
||||||
|
* @Date: 2025/6/5 9:12
|
||||||
|
**/
|
||||||
|
@Override
|
||||||
|
public CommonResponseDto transSupplierInfo(JSONObject jsonData) {
|
||||||
|
log.info("MDM供应商主数据请求参数为:{}", jsonData);
|
||||||
|
CommonResponseDto commonResponseDto = new CommonResponseDto();
|
||||||
|
boolean flag = true;
|
||||||
|
if(CollectionUtil.isEmpty(jsonData)){
|
||||||
|
commonResponseDto.setStatus("E");
|
||||||
|
commonResponseDto.setMessage("MDM传输数据为空!");
|
||||||
|
return commonResponseDto;
|
||||||
|
}
|
||||||
|
List<ResponseItemsData> responseItemsData = Lists.newArrayList();
|
||||||
|
JSONArray supplier = jsonData.getJSONArray("supplier");
|
||||||
|
if(CollectionUtil.isNotEmpty(supplier)){
|
||||||
|
for (int i = 0; i < supplier.size(); i++) {
|
||||||
|
JSONObject json = supplier.getJSONObject(i);
|
||||||
|
//主编码主键
|
||||||
|
long mdId = json.getLongValue("mdId");
|
||||||
|
//客户编号
|
||||||
|
String mdCode = json.getString("mdCode");
|
||||||
|
//主数据描述
|
||||||
|
String mdDescription = json.getString("mdDescription");
|
||||||
|
try {
|
||||||
|
//供应商名称
|
||||||
|
String supplierName = json.getString("supplierName");
|
||||||
|
//供应商简称
|
||||||
|
String abbreviation = json.getString("abbreviation");
|
||||||
|
//股份供应商状态
|
||||||
|
String gfSupplierStatus = json.getString("gfSupplierStatus");
|
||||||
|
//股份供应商状态_描述
|
||||||
|
String gfSupplierStatusDesc = json.getString("gfSupplierStatusDesc");
|
||||||
|
//插入客户表
|
||||||
|
String currentUserId = SecurityUtils.getCurrentUserId();
|
||||||
|
String now = DateUtil.now();
|
||||||
|
//核心字段判断
|
||||||
|
if (StrUtil.isEmpty(mdCode) || StrUtil.isEmpty(supplierName)) {
|
||||||
|
throw new BadRequestException("MDM->供应商编码或名称不能为空!");
|
||||||
|
}
|
||||||
|
JSONObject supplier_jo = WQLObject.getWQLObject("md_cs_transportationbase").query("cust_code = '" + mdCode + "'").uniqueResult(0);
|
||||||
|
if (ObjectUtil.isEmpty(supplier_jo)) {
|
||||||
|
supplier_jo = new JSONObject();
|
||||||
|
supplier_jo.put("cust_id", mdId);
|
||||||
|
supplier_jo.put("cust_code", mdCode);
|
||||||
|
supplier_jo.put("cust_name", supplierName);
|
||||||
|
supplier_jo.put("cust_simple_name", abbreviation);
|
||||||
|
supplier_jo.put("mdm_status", gfSupplierStatus);
|
||||||
|
supplier_jo.put("create_id", currentUserId);
|
||||||
|
supplier_jo.put("create_name", "mdmAdmin");
|
||||||
|
supplier_jo.put("create_time", now);
|
||||||
|
WQLObject.getWQLObject("md_cs_transportationbase").insert(supplier_jo);
|
||||||
|
ResponseItemsData itemsData = ResponseItemsData.adapter(mdId, mdCode, mdDescription, StatusEnum.INSERT_SUCCESS.getCode(), StatusEnum.INSERT_SUCCESS.getMessage());
|
||||||
|
responseItemsData.add(itemsData);
|
||||||
|
} else {
|
||||||
|
supplier_jo.put("cust_name", supplierName);
|
||||||
|
supplier_jo.put("cust_simple_name", abbreviation);
|
||||||
|
supplier_jo.put("update_optid", currentUserId);
|
||||||
|
supplier_jo.put("update_optname", "mdmAdmin");
|
||||||
|
supplier_jo.put("mdm_status", gfSupplierStatus);
|
||||||
|
supplier_jo.put("update_time", now);
|
||||||
|
WQLObject.getWQLObject("md_cs_transportationbase").update(supplier_jo);
|
||||||
|
ResponseItemsData itemsData = ResponseItemsData.adapter(mdId, mdCode, mdDescription, StatusEnum.UPDATE_SUCCESS.getCode(), StatusEnum.UPDATE_SUCCESS.getMessage());
|
||||||
|
responseItemsData.add(itemsData);
|
||||||
|
}
|
||||||
|
}catch (Exception e) {
|
||||||
|
//获取抛出异常的信息
|
||||||
|
String message = e.getMessage();
|
||||||
|
flag= false;
|
||||||
|
ResponseItemsData itemsData = ResponseItemsData.adapter(mdId, mdCode, mdDescription, StatusEnum.ACCEPT_FAIL.getCode(),message.contains("MDM")?message:StatusEnum.ACCEPT_FAIL.getMessage());
|
||||||
|
responseItemsData.add(itemsData);
|
||||||
|
log.error("MDM供应商数据接口数据异常", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
commonResponseDto.setStatus(flag ? StatusEnum.ACCEPT_SUCCESS.getCode() : StatusEnum.ACCEPT_FAIL.getCode());
|
||||||
|
commonResponseDto.setMessage(flag ? StatusEnum.ACCEPT_SUCCESS.getMessage() : StatusEnum.ACCEPT_FAIL.getMessage());
|
||||||
|
commonResponseDto.setResponseData(responseItemsData);
|
||||||
|
return commonResponseDto;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: MDM物料主数据接口
|
||||||
|
* @Author Eric.Yang
|
||||||
|
* @Date: 2025/6/3 9:12
|
||||||
|
**/
|
||||||
|
@Override
|
||||||
|
public CommonResponseDto transMaterialInfo(JSONObject jsonData) {
|
||||||
|
log.info("MDM物料主数据请求参数为:{}", jsonData);
|
||||||
|
CommonResponseDto commonResponseDto = new CommonResponseDto();
|
||||||
|
boolean flag = true;
|
||||||
|
if(CollectionUtil.isEmpty(jsonData)){
|
||||||
|
commonResponseDto.setStatus("E");
|
||||||
|
commonResponseDto.setMessage("MDM传输数据为空!");
|
||||||
|
return commonResponseDto;
|
||||||
|
}
|
||||||
|
List<ResponseItemsData> responseItemsData = Lists.newArrayList();
|
||||||
|
JSONArray materiels = jsonData.getJSONArray("materiels");
|
||||||
|
if(CollectionUtil.isNotEmpty(materiels)){
|
||||||
|
for (int i = 0; i < materiels.size(); i++) {
|
||||||
|
JSONObject json = materiels.getJSONObject(i);
|
||||||
|
//主编码主键
|
||||||
|
long mdId = json.getLongValue("mdId");
|
||||||
|
//物料编码
|
||||||
|
String mdCode = json.getString("mdCode");
|
||||||
|
//物料名称
|
||||||
|
String mdDescription = json.getString("mdDescription");
|
||||||
|
try {
|
||||||
|
//物料分类
|
||||||
|
String categoryCode = json.getString("categoryCode");
|
||||||
|
//计量单位
|
||||||
|
String meins = json.getString("meins");
|
||||||
|
//主数据状态
|
||||||
|
String mdStatusCode = json.getString("mdStatusCode");
|
||||||
|
//跨工厂的物料状态
|
||||||
|
String mstae = json.getString("mstae");
|
||||||
|
//跨工厂的物料状态_描述
|
||||||
|
String mstaeDesc = json.getString("mstaeDesc");
|
||||||
|
//插入客户表
|
||||||
|
String currentUserId = SecurityUtils.getCurrentUserId();
|
||||||
|
String now = DateUtil.now();
|
||||||
|
if (StrUtil.isEmpty(mdCode) || StrUtil.isEmpty(mdDescription)) {
|
||||||
|
throw new BadRequestException("MDM->物料编码或名称不能为空!");
|
||||||
|
}
|
||||||
|
//todo 后续确认这个步骤的作用,考虑是否移除该步骤
|
||||||
|
//todo 插入md_me_materialbaseext 物料基本信息接口表
|
||||||
|
|
||||||
|
JSONObject material_jo = WQLObject.getWQLObject("md_me_materialbase").query("material_code = '" + mdCode + "'").uniqueResult(0);
|
||||||
|
if (ObjectUtil.isEmpty(material_jo)) {
|
||||||
|
JSONObject unit = WQLObject.getWQLObject("md_pb_measureunit").query("unit_code = '" + meins + "'").uniqueResult(0);
|
||||||
|
if (ObjectUtil.isEmpty(unit)) {
|
||||||
|
throw new BadRequestException("MDM->未查询到相关计量单位,请进行维护!");
|
||||||
|
}
|
||||||
|
material_jo = new JSONObject();
|
||||||
|
material_jo.put("material_id", mdId);
|
||||||
|
material_jo.put("material_code", mdCode);
|
||||||
|
material_jo.put("material_name", mdDescription);
|
||||||
|
material_jo.put("base_unit_id", unit.getString("measure_unit_id"));
|
||||||
|
material_jo.put("mdm_status", mdStatusCode);
|
||||||
|
material_jo.put("create_id", currentUserId);
|
||||||
|
material_jo.put("create_name", "mdmAdmin");
|
||||||
|
material_jo.put("create_time", now);
|
||||||
|
WQLObject.getWQLObject("md_me_materialbase").insert(material_jo);
|
||||||
|
ResponseItemsData itemsData = ResponseItemsData.adapter(mdId, mdCode, mdDescription, StatusEnum.INSERT_SUCCESS.getCode(), StatusEnum.INSERT_SUCCESS.getMessage());
|
||||||
|
responseItemsData.add(itemsData);
|
||||||
|
} else {
|
||||||
|
JSONObject unit = WQLObject.getWQLObject("md_pb_measureunit").query("unit_code = '" + meins + "'").uniqueResult(0);
|
||||||
|
if (ObjectUtil.isEmpty(unit)) {
|
||||||
|
throw new BadRequestException("MDM->未查询到相关计量单位,请进行维护!");
|
||||||
|
}
|
||||||
|
material_jo.put("material_name", mdDescription);
|
||||||
|
material_jo.put("base_unit_id", unit.getString("measure_unit_id"));
|
||||||
|
material_jo.put("mdm_status", mdStatusCode);
|
||||||
|
material_jo.put("update_optid", currentUserId);
|
||||||
|
material_jo.put("update_optname", "mdmAdmin");
|
||||||
|
material_jo.put("update_time", now);
|
||||||
|
WQLObject.getWQLObject("md_me_materialbase").update(material_jo);
|
||||||
|
ResponseItemsData itemsData = ResponseItemsData.adapter(mdId, mdCode, mdDescription, StatusEnum.UPDATE_SUCCESS.getCode(), StatusEnum.UPDATE_SUCCESS.getMessage());
|
||||||
|
responseItemsData.add(itemsData);
|
||||||
|
}
|
||||||
|
}catch (Exception e) {
|
||||||
|
//获取抛出异常的信息
|
||||||
|
String message = e.getMessage();
|
||||||
|
flag= false;
|
||||||
|
ResponseItemsData itemsData = ResponseItemsData.adapter(mdId, mdCode, mdDescription, StatusEnum.ACCEPT_FAIL.getCode(),message.contains("MDM")?message:StatusEnum.ACCEPT_FAIL.getMessage());
|
||||||
|
responseItemsData.add(itemsData);
|
||||||
|
log.error("MDM物料主数据接口数据异常", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//todo 错误的定义,是有一个错就是状态为错误还是?
|
||||||
|
commonResponseDto.setStatus(flag ? StatusEnum.ACCEPT_SUCCESS.getCode() : StatusEnum.ACCEPT_FAIL.getCode());
|
||||||
|
commonResponseDto.setMessage(flag ? StatusEnum.ACCEPT_SUCCESS.getMessage() : StatusEnum.ACCEPT_FAIL.getMessage());
|
||||||
|
commonResponseDto.setResponseData(responseItemsData);
|
||||||
|
return commonResponseDto;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -25,7 +25,7 @@ https://juejin.cn/post/6844903775631572999
|
|||||||
<include resource="log/SapToLms.xml"/>
|
<include resource="log/SapToLms.xml"/>
|
||||||
<include resource="log/AcsToLMS.xml"/>
|
<include resource="log/AcsToLMS.xml"/>
|
||||||
<include resource="log/LmsToAcs.xml"/>
|
<include resource="log/LmsToAcs.xml"/>
|
||||||
|
<include resource="log/MdmToLms.xml"/>
|
||||||
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
|
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
<!-- 控制台高亮-->
|
<!-- 控制台高亮-->
|
||||||
<withJansi>true</withJansi>
|
<withJansi>true</withJansi>
|
||||||
|
|||||||
Reference in New Issue
Block a user