feat:mdm主动拉取数据

release
gongquanlin 2 years ago
parent 9b20af79a8
commit e254454d22
  1. 6
      order-management-consumer/src/main/java/com/dxhy/order/consumer/modules/commodity/controller/GroupCommodityCodeController.java
  2. 20
      order-management-consumer/src/main/java/com/dxhy/order/consumer/modules/commodity/domain/dto/SyncGroupCommodityDTO.java
  3. 4
      order-management-consumer/src/main/java/com/dxhy/order/consumer/modules/commodity/service/IGroupCommodityCodeService.java
  4. 16
      order-management-consumer/src/main/java/com/dxhy/order/consumer/modules/commodity/service/impl/GroupCommodityCodeServiceImpl.java
  5. 16
      order-management-consumer/src/main/java/com/dxhy/order/consumer/openapi/service/ISDEnregyService.java
  6. 93
      order-management-consumer/src/main/java/com/dxhy/order/consumer/openapi/service/impl/SDEnregyServiceImpl.java

@ -3,6 +3,7 @@ package com.dxhy.order.consumer.modules.commodity.controller;
import cn.hutool.json.JSONObject; import cn.hutool.json.JSONObject;
import com.dxhy.order.consumer.modules.commodity.domain.dto.QueryGroupCommodityDTO; import com.dxhy.order.consumer.modules.commodity.domain.dto.QueryGroupCommodityDTO;
import com.dxhy.order.consumer.modules.commodity.domain.dto.QuoteGroupCommodityDTO; import com.dxhy.order.consumer.modules.commodity.domain.dto.QuoteGroupCommodityDTO;
import com.dxhy.order.consumer.modules.commodity.domain.dto.SyncGroupCommodityDTO;
import com.dxhy.order.consumer.modules.commodity.service.IGroupCommodityCodeService; import com.dxhy.order.consumer.modules.commodity.service.IGroupCommodityCodeService;
import com.dxhy.order.model.PageUtils; import com.dxhy.order.model.PageUtils;
import com.dxhy.order.model.R; import com.dxhy.order.model.R;
@ -48,4 +49,9 @@ public class GroupCommodityCodeController {
public R quote(@RequestBody @Validated QuoteGroupCommodityDTO dto) { public R quote(@RequestBody @Validated QuoteGroupCommodityDTO dto) {
return groupCommodityCodeService.quoteGroupCommodityCode(dto); return groupCommodityCodeService.quoteGroupCommodityCode(dto);
} }
@PostMapping("/sync")
public R sync(@RequestBody @Validated SyncGroupCommodityDTO dto) {
return groupCommodityCodeService.syncGroupCommodityDTO(dto);
}
} }

@ -0,0 +1,20 @@
package com.dxhy.order.consumer.modules.commodity.domain.dto;
import lombok.Data;
import javax.validation.constraints.NotBlank;
/**
* @Description 同步集团物料库
* @Author 巩权林
* @Date 2023/3/9 11:01
**/
@Data
public class SyncGroupCommodityDTO {
/**
* 自行编码
*/
@NotBlank(message = "物料编码不能为空!")
private String zxbm;
}

@ -2,6 +2,7 @@ package com.dxhy.order.consumer.modules.commodity.service;
import com.dxhy.order.consumer.modules.commodity.domain.dto.QueryGroupCommodityDTO; import com.dxhy.order.consumer.modules.commodity.domain.dto.QueryGroupCommodityDTO;
import com.dxhy.order.consumer.modules.commodity.domain.dto.QuoteGroupCommodityDTO; import com.dxhy.order.consumer.modules.commodity.domain.dto.QuoteGroupCommodityDTO;
import com.dxhy.order.consumer.modules.commodity.domain.dto.SyncGroupCommodityDTO;
import com.dxhy.order.model.PageUtils; import com.dxhy.order.model.PageUtils;
import com.dxhy.order.model.R; import com.dxhy.order.model.R;
@ -17,4 +18,7 @@ public interface IGroupCommodityCodeService {
PageUtils queryGroupCommodityCodeList(QueryGroupCommodityDTO queryGroupCommodityDTO); PageUtils queryGroupCommodityCodeList(QueryGroupCommodityDTO queryGroupCommodityDTO);
R quoteGroupCommodityCode(QuoteGroupCommodityDTO quoteGroupCommodityDTO); R quoteGroupCommodityCode(QuoteGroupCommodityDTO quoteGroupCommodityDTO);
R syncGroupCommodityDTO(SyncGroupCommodityDTO dto);
} }

@ -6,7 +6,9 @@ import com.dxhy.order.constant.ConfigureConstant;
import com.dxhy.order.consumer.dao.GroupCommodityCodeMapper; import com.dxhy.order.consumer.dao.GroupCommodityCodeMapper;
import com.dxhy.order.consumer.modules.commodity.domain.dto.QueryGroupCommodityDTO; import com.dxhy.order.consumer.modules.commodity.domain.dto.QueryGroupCommodityDTO;
import com.dxhy.order.consumer.modules.commodity.domain.dto.QuoteGroupCommodityDTO; import com.dxhy.order.consumer.modules.commodity.domain.dto.QuoteGroupCommodityDTO;
import com.dxhy.order.consumer.modules.commodity.domain.dto.SyncGroupCommodityDTO;
import com.dxhy.order.consumer.modules.commodity.service.IGroupCommodityCodeService; import com.dxhy.order.consumer.modules.commodity.service.IGroupCommodityCodeService;
import com.dxhy.order.consumer.openapi.service.ISDEnregyService;
import com.dxhy.order.model.PageUtils; import com.dxhy.order.model.PageUtils;
import com.dxhy.order.model.R; import com.dxhy.order.model.R;
import com.dxhy.order.utils.CommonUtils; import com.dxhy.order.utils.CommonUtils;
@ -40,6 +42,9 @@ public class GroupCommodityCodeServiceImpl implements IGroupCommodityCodeService
@Resource @Resource
private BaseService baseService; private BaseService baseService;
@Autowired
private ISDEnregyService sdEnregyService;
/** /**
* 查询集团物料库 * 查询集团物料库
* *
@ -113,4 +118,15 @@ public class GroupCommodityCodeServiceImpl implements IGroupCommodityCodeService
return R.error("引用失败"); return R.error("引用失败");
} }
} }
/**
* 同步集团物料库
*
* @param dto
* @return
*/
@Override
public R syncGroupCommodityDTO(SyncGroupCommodityDTO dto) {
return sdEnregyService.proactiveSyncMdmGroupTax(dto.getZxbm());
}
} }

@ -2,6 +2,7 @@ package com.dxhy.order.consumer.openapi.service;
import com.dxhy.order.consumer.openapi.protocol.AjaxResult; import com.dxhy.order.consumer.openapi.protocol.AjaxResult;
import com.dxhy.order.consumer.openapi.protocol.v6.sdenergy.*; import com.dxhy.order.consumer.openapi.protocol.v6.sdenergy.*;
import com.dxhy.order.model.R;
import java.util.List; import java.util.List;
import java.util.function.Function; import java.util.function.Function;
@ -21,6 +22,13 @@ public interface ISDEnregyService {
*/ */
public AjaxResult syncBuyerMessage(List<MdmGmfxxtbReqBO> mdmGmfxxtbReqBOS, String requestBody); public AjaxResult syncBuyerMessage(List<MdmGmfxxtbReqBO> mdmGmfxxtbReqBOS, String requestBody);
/**
* 同步物料
*
* @param mdmGmfxxtbReqBOS
* @param requestBody
* @return
*/
public AjaxResult syncMdmGroupTax(List<MdmSyncGroupTaxCodeReqBO> mdmGmfxxtbReqBOS, String requestBody); public AjaxResult syncMdmGroupTax(List<MdmSyncGroupTaxCodeReqBO> mdmGmfxxtbReqBOS, String requestBody);
/** /**
@ -32,5 +40,13 @@ public interface ISDEnregyService {
*/ */
public AjaxResult syncMdmUser(List<MdmSyncUserReqBO> mdmSyncUserReqBOS, String requestBody); public AjaxResult syncMdmUser(List<MdmSyncUserReqBO> mdmSyncUserReqBOS, String requestBody);
/**
* 主动同步物料库
*
* @param code
* @return
*/
public R proactiveSyncMdmGroupTax(String code);
public SDEnergyMdmBaseBO buildResult(SDEnergyMdmBaseBO baseBO, List respList, Function<Object, SDEnergyMdmBaseRespBO> handleFunction); public SDEnergyMdmBaseBO buildResult(SDEnergyMdmBaseBO baseBO, List respList, Function<Object, SDEnergyMdmBaseRespBO> handleFunction);
} }

@ -1,5 +1,7 @@
package com.dxhy.order.consumer.openapi.service.impl; package com.dxhy.order.consumer.openapi.service.impl;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.dxhy.order.baseservice.module.base.service.BaseService; import com.dxhy.order.baseservice.module.base.service.BaseService;
import com.dxhy.order.baseservice.module.buyer.dao.BuyerMapper; import com.dxhy.order.baseservice.module.buyer.dao.BuyerMapper;
@ -13,17 +15,18 @@ import com.dxhy.order.consumer.openapi.protocol.AjaxResult;
import com.dxhy.order.consumer.openapi.protocol.v6.sdenergy.*; import com.dxhy.order.consumer.openapi.protocol.v6.sdenergy.*;
import com.dxhy.order.model.R; import com.dxhy.order.model.R;
import com.dxhy.order.utils.DistributedKeyMaker; import com.dxhy.order.utils.DistributedKeyMaker;
import com.dxhy.order.utils.HttpUtils;
import com.dxhy.order.utils.JsonUtils; import com.dxhy.order.utils.JsonUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList; import java.util.*;
import java.util.Date; import java.util.stream.Collectors;
import java.util.List;
/** /**
* @Description * @Description
@ -48,6 +51,26 @@ public class SDEnregyServiceImpl extends SDEnregyServiceAbstract {
@Resource @Resource
private BaseService baseService; private BaseService baseService;
// 物料主动查询接口
@Value("${mdm.groupTaxCode.url}")
private String groupTaxCodeUrl;
// 物料主动查询用户名
@Value("${mdm.groupTaxCode.usercode}")
private String groupTaxCodeUsercode;
// 物料主动查询密码
@Value("${mdm.groupTaxCode.password}")
private String groupTaxCodePassword;
// // 客商主动查询接口
// @Value("${mdm.buyerUrl}")
// private String buyerUrl;
// // 人员主动查询接口
// @Value("${mdm.userUrl}")
// private String userUrl;
@Override @Override
public AjaxResult syncBuyerMessage(List<MdmGmfxxtbReqBO> mdmGmfxxtbReqBOS, String requestBody) { public AjaxResult syncBuyerMessage(List<MdmGmfxxtbReqBO> mdmGmfxxtbReqBOS, String requestBody) {
// 存表 // 存表
@ -243,4 +266,68 @@ public class SDEnregyServiceImpl extends SDEnregyServiceAbstract {
String resp = JsonUtils.getInstance().toJsonStringNullToEmpty(result); String resp = JsonUtils.getInstance().toJsonStringNullToEmpty(result);
return AjaxResult.success("success", resp); return AjaxResult.success("success", resp);
} }
/**
* 主动同步物料库
*
* @param code
* @return
*/
@Override
public R proactiveSyncMdmGroupTax(String code) {
// 向mdm主动发送请求
if (StringUtils.isEmpty(groupTaxCodeUrl)) {
return R.error("请配置物料主动查询地址");
}
String requestBody = " \n" +
"{\n" +
" \"ESB\":{\n" +
" \"DATA\":{\n" +
" \"DATAINFOS\":{\n" +
" \"DATAINFO\":[\n" +
" {\n" +
" \"CODE\":\"" + code + "\"\n" +
" }\n" +
" ],\n" +
" \"PUUID\":\"" + UUID.randomUUID().toString() + "\"\n" +
" },\n" +
" \"SPLITPAGE\":{\n" +
" \"COUNTPERPAGE\":\"100\",\n" +
" \"CURRENTPAGE\":\"1\"\n" +
" }\n" +
" }\n" +
" }\n" +
"}";
// 发送POST请求
HttpResponse response = HttpRequest.post(groupTaxCodeUrl)
.timeout(20000) // 设置请求超时时间
.header("Content-Type", "application/json")
.header("usercode", groupTaxCodeUsercode)
.header("password", groupTaxCodePassword)
.body(requestBody) // 设置请求体内容
.execute();
String resp = response.body();
SDEnergyMdmBaseBO baseBO = JSONObject.parseObject(resp, SDEnergyMdmBaseBO.class);
List<MdmSyncGroupTaxCodeReqBO> mdmGmfxxtbReqBOS = (List<MdmSyncGroupTaxCodeReqBO>) Optional.of(baseBO)
.map(SDEnergyMdmBaseBO::getESB)
.map(ESBBO::getDATA)
.map(DATABO::getDATAINFOS)
.map(DATAINFOSBO::getDATAINFO)
.map(i -> {
// 转成List<MdmSyncGroupTaxCodeReqBO>
return i.stream().map(j -> {
return JSONObject.parseObject(JSONObject.toJSONString(j), MdmSyncGroupTaxCodeReqBO.class);
}).collect(Collectors.toList());
})
.orElse(new ArrayList<MdmSyncGroupTaxCodeReqBO>());
AjaxResult syncResult = this.syncMdmGroupTax(mdmGmfxxtbReqBOS, resp);
if (syncResult.isSuccess()) {
return R.ok();
} else {
return R.error(syncResult.getMsg());
}
}
} }

Loading…
Cancel
Save