feat:同步人员接口

release
gongquanlin 2 years ago
parent 21862134f8
commit 4e8b48be6e
  1. 29
      order-management-consumer/src/main/java/com/dxhy/order/consumer/modules/user/controller/SyncUserController.java
  2. 20
      order-management-consumer/src/main/java/com/dxhy/order/consumer/modules/user/domain/SyncUserDTO.java
  3. 9
      order-management-consumer/src/main/java/com/dxhy/order/consumer/modules/user/service/IUserService.java
  4. 30
      order-management-consumer/src/main/java/com/dxhy/order/consumer/modules/user/service/UserServiceImpl.java
  5. 4
      order-management-consumer/src/main/java/com/dxhy/order/consumer/openapi/api/InvoiceRestSDEnregy.java
  6. 8
      order-management-consumer/src/main/java/com/dxhy/order/consumer/openapi/service/ISDEnregyService.java
  7. 95
      order-management-consumer/src/main/java/com/dxhy/order/consumer/openapi/service/impl/SDEnregyServiceImpl.java

@ -0,0 +1,29 @@
package com.dxhy.order.consumer.modules.user.controller;
import com.dxhy.order.consumer.modules.user.domain.SyncUserDTO;
import com.dxhy.order.consumer.modules.user.service.IUserService;
import com.dxhy.order.model.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
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;
/**
* @Description 人员接口 主动拉取人员
* @Author 巩权林
* @Date 2023/3/22 08:18
**/
@RestController
@RequestMapping("/sync_user")
public class SyncUserController {
@Autowired
private IUserService userService;
@PostMapping("/sync")
public R sync(@RequestBody @Validated SyncUserDTO dto) {
return userService.syncUser(dto);
}
}

@ -0,0 +1,20 @@
package com.dxhy.order.consumer.modules.user.domain;
import lombok.Data;
import javax.validation.constraints.NotBlank;
/**
* @Description
* @Author 巩权林
* @Date 2023/3/22 08:28
**/
@Data
public class SyncUserDTO {
/**
* 自行编码
*/
@NotBlank(message = "人员编码不能为空!")
private String code;
}

@ -0,0 +1,9 @@
package com.dxhy.order.consumer.modules.user.service;
import com.dxhy.order.consumer.modules.user.domain.SyncUserDTO;
import com.dxhy.order.model.R;
public interface IUserService {
public R syncUser(SyncUserDTO dto);
}

@ -0,0 +1,30 @@
package com.dxhy.order.consumer.modules.user.service;
import com.dxhy.order.consumer.modules.user.domain.SyncUserDTO;
import com.dxhy.order.consumer.openapi.service.ISDEnregyService;
import com.dxhy.order.model.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* @Description 同步人员
* @Author 巩权林
* @Date 2023/3/22 08:28
**/
@Service
public class UserServiceImpl implements IUserService {
@Autowired
private ISDEnregyService sdEnregyService;
/**
* 同步人员
*
* @param dto
* @return
*/
@Override
public R syncUser(SyncUserDTO dto) {
return sdEnregyService.proactiveSyncMdmUser(dto.getCode());
}
}

@ -129,7 +129,7 @@ public class InvoiceRestSDEnregy {
@PostMapping("/sync_user") @PostMapping("/sync_user")
public String syncUser(@RequestBody String requestBody) { public String syncUser(@RequestBody String requestBody) {
String logUUID = UUID.randomUUID().toString(); String logUUID = UUID.randomUUID().toString();
log.info("{}[syncMdmGroupTax],uuid:{},收到请求报文:{}", LOGGER_MSG, logUUID, requestBody); log.info("{}[syncMdmUser],uuid:{},收到请求报文:{}", LOGGER_MSG, logUUID, requestBody);
// 接收请求报文,然后进行入库 // 接收请求报文,然后进行入库
SDEnergyMdmBaseBO baseBO = JSONObject.parseObject(requestBody, SDEnergyMdmBaseBO.class); SDEnergyMdmBaseBO baseBO = JSONObject.parseObject(requestBody, SDEnergyMdmBaseBO.class);
List<MdmSyncUserReqBO> mdmSyncUserReqBO = (List<MdmSyncUserReqBO>) Optional.of(baseBO) List<MdmSyncUserReqBO> mdmSyncUserReqBO = (List<MdmSyncUserReqBO>) Optional.of(baseBO)
@ -147,7 +147,7 @@ public class InvoiceRestSDEnregy {
AjaxResult syncMdmGroupTax = isdEnregyService.syncMdmUser(mdmSyncUserReqBO, requestBody); AjaxResult syncMdmGroupTax = isdEnregyService.syncMdmUser(mdmSyncUserReqBO, requestBody);
if (syncMdmGroupTax.isError()) { if (syncMdmGroupTax.isError()) {
log.info("{}[syncMdmGroupTax],uuid:{},请求处理失败,原因:{}", LOGGER_MSG, logUUID, syncMdmGroupTax.getMsg()); log.info("{}[syncMdmUser],uuid:{},请求处理失败,原因:{}", LOGGER_MSG, logUUID, syncMdmGroupTax.getMsg());
return syncMdmGroupTax.getMsg(); return syncMdmGroupTax.getMsg();
} }

@ -48,6 +48,14 @@ public interface ISDEnregyService {
*/ */
public R proactiveSyncMdmGroupTax(String code); public R proactiveSyncMdmGroupTax(String code);
/**
* 主动同步人员
*
* @param code
* @return
*/
public R proactiveSyncMdmUser(String code);
/** /**
* 主动同步用户信息 * 主动同步用户信息

@ -19,6 +19,7 @@ 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.HttpUtils;
import com.dxhy.order.utils.JsonUtils; import com.dxhy.order.utils.JsonUtils;
import lombok.extern.slf4j.Slf4j;
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.beans.factory.annotation.Value;
@ -36,6 +37,7 @@ import java.util.stream.Collectors;
* @Date 2023/2/23 14:24 * @Date 2023/2/23 14:24
**/ **/
@Service @Service
@Slf4j
public class SDEnregyServiceImpl extends SDEnregyServiceAbstract { public class SDEnregyServiceImpl extends SDEnregyServiceAbstract {
@Autowired @Autowired
@ -74,21 +76,28 @@ public class SDEnregyServiceImpl extends SDEnregyServiceAbstract {
@Value("${mdm.buyer.url}") @Value("${mdm.buyer.url}")
private String buyerUrl; private String buyerUrl;
// 物料主动查询用户名 // 客商主动查询用户名
@Value("${mdm.buyer.usercode}") @Value("${mdm.buyer.usercode}")
private String buyerUsercode; private String buyerUsercode;
// 物料主动查询密码 // 客商主动查询密码
@Value("${mdm.buyer.password}") @Value("${mdm.buyer.password}")
private String buyerPassword; private String buyerPassword;
// ===========客商相关结束=========== // ===========客商相关结束===========
// // 客商主动查询接口 // ===========人员相关开始===========
// @Value("${mdm.buyerUrl}") @Value("${mdm.user.url}")
// private String buyerUrl; private String userUrl;
// // 人员主动查询接口
// @Value("${mdm.userUrl}") // 物料主动查询用户名
// private String userUrl; @Value("${mdm.user.usercode}")
private String userUsercode;
// 物料主动查询密码
@Value("${mdm.user.password}")
private String userPassword;
// ===========人员相关结束===========
@Override @Override
public AjaxResult syncBuyerMessage(List<MdmGmfxxtbReqBO> mdmGmfxxtbReqBOS, String requestBody) { public AjaxResult syncBuyerMessage(List<MdmGmfxxtbReqBO> mdmGmfxxtbReqBOS, String requestBody) {
@ -411,8 +420,8 @@ public class SDEnregyServiceImpl extends SDEnregyServiceAbstract {
HttpResponse response = HttpRequest.post(buyerUrl) HttpResponse response = HttpRequest.post(buyerUrl)
.timeout(20000) // 设置请求超时时间 .timeout(20000) // 设置请求超时时间
.header("Content-Type", "application/json") .header("Content-Type", "application/json")
.header("usercode", groupTaxCodeUsercode) .header("usercode", userUsercode)
.header("password", groupTaxCodePassword) .header("password", userPassword)
.body(requestBody) // 设置请求体内容 .body(requestBody) // 设置请求体内容
.execute(); .execute();
String resp = response.body(); String resp = response.body();
@ -438,4 +447,70 @@ public class SDEnregyServiceImpl extends SDEnregyServiceAbstract {
return R.error(syncResult.getMsg()); return R.error(syncResult.getMsg());
} }
} }
/**
* 主动同步人员
*
* @param code
* @return
*/
@Override
public R proactiveSyncMdmUser(String code) {
// 向mdm主动发送请求
if (StringUtils.isEmpty(userUrl)) {
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();
log.debug("同步人员信息返回结果:{}", resp);
SDEnergyMdmBaseBO baseBO = JSONObject.parseObject(resp, SDEnergyMdmBaseBO.class);
List<MdmSyncUserReqBO> mdmSyncUserReqBO = (List<MdmSyncUserReqBO>) Optional.of(baseBO)
.map(SDEnergyMdmBaseBO::getESB)
.map(ESBBO::getDATA)
.map(DATABO::getDATAINFOS)
.map(DATAINFOSBO::getDATAINFO)
.map(i -> {
// 转成List<MdmSyncUserReqBO>
return i.stream().map(j -> {
return JSONObject.parseObject(JSONObject.toJSONString(j), MdmSyncUserReqBO.class);
}).collect(Collectors.toList());
})
.orElse(new ArrayList<MdmSyncGroupTaxCodeReqBO>());
AjaxResult syncMdmUserResult = this.syncMdmUser(mdmSyncUserReqBO, resp);
if (syncMdmUserResult.isSuccess()) {
return R.ok();
} else {
return R.error(syncMdmUserResult.getMsg());
}
}
} }

Loading…
Cancel
Save