diff --git a/order-management-consumer/src/main/java/com/dxhy/order/consumer/modules/user/controller/SyncUserController.java b/order-management-consumer/src/main/java/com/dxhy/order/consumer/modules/user/controller/SyncUserController.java new file mode 100644 index 00000000..455ada45 --- /dev/null +++ b/order-management-consumer/src/main/java/com/dxhy/order/consumer/modules/user/controller/SyncUserController.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); + } +} diff --git a/order-management-consumer/src/main/java/com/dxhy/order/consumer/modules/user/domain/SyncUserDTO.java b/order-management-consumer/src/main/java/com/dxhy/order/consumer/modules/user/domain/SyncUserDTO.java new file mode 100644 index 00000000..d2cb955b --- /dev/null +++ b/order-management-consumer/src/main/java/com/dxhy/order/consumer/modules/user/domain/SyncUserDTO.java @@ -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; +} diff --git a/order-management-consumer/src/main/java/com/dxhy/order/consumer/modules/user/service/IUserService.java b/order-management-consumer/src/main/java/com/dxhy/order/consumer/modules/user/service/IUserService.java new file mode 100644 index 00000000..c50e0052 --- /dev/null +++ b/order-management-consumer/src/main/java/com/dxhy/order/consumer/modules/user/service/IUserService.java @@ -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); +} diff --git a/order-management-consumer/src/main/java/com/dxhy/order/consumer/modules/user/service/UserServiceImpl.java b/order-management-consumer/src/main/java/com/dxhy/order/consumer/modules/user/service/UserServiceImpl.java new file mode 100644 index 00000000..a29bec74 --- /dev/null +++ b/order-management-consumer/src/main/java/com/dxhy/order/consumer/modules/user/service/UserServiceImpl.java @@ -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()); + } +} diff --git a/order-management-consumer/src/main/java/com/dxhy/order/consumer/openapi/api/InvoiceRestSDEnregy.java b/order-management-consumer/src/main/java/com/dxhy/order/consumer/openapi/api/InvoiceRestSDEnregy.java index dbeb4f8d..63fde1e6 100644 --- a/order-management-consumer/src/main/java/com/dxhy/order/consumer/openapi/api/InvoiceRestSDEnregy.java +++ b/order-management-consumer/src/main/java/com/dxhy/order/consumer/openapi/api/InvoiceRestSDEnregy.java @@ -129,7 +129,7 @@ public class InvoiceRestSDEnregy { @PostMapping("/sync_user") public String syncUser(@RequestBody String requestBody) { 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); List mdmSyncUserReqBO = (List) Optional.of(baseBO) @@ -147,7 +147,7 @@ public class InvoiceRestSDEnregy { AjaxResult syncMdmGroupTax = isdEnregyService.syncMdmUser(mdmSyncUserReqBO, requestBody); if (syncMdmGroupTax.isError()) { - log.info("{}[syncMdmGroupTax],uuid:{},请求处理失败,原因:{}", LOGGER_MSG, logUUID, syncMdmGroupTax.getMsg()); + log.info("{}[syncMdmUser],uuid:{},请求处理失败,原因:{}", LOGGER_MSG, logUUID, syncMdmGroupTax.getMsg()); return syncMdmGroupTax.getMsg(); } diff --git a/order-management-consumer/src/main/java/com/dxhy/order/consumer/openapi/service/ISDEnregyService.java b/order-management-consumer/src/main/java/com/dxhy/order/consumer/openapi/service/ISDEnregyService.java index 2a36c781..3cf706b0 100644 --- a/order-management-consumer/src/main/java/com/dxhy/order/consumer/openapi/service/ISDEnregyService.java +++ b/order-management-consumer/src/main/java/com/dxhy/order/consumer/openapi/service/ISDEnregyService.java @@ -48,6 +48,14 @@ public interface ISDEnregyService { */ public R proactiveSyncMdmGroupTax(String code); + /** + * 主动同步人员 + * + * @param code + * @return + */ + public R proactiveSyncMdmUser(String code); + /** * 主动同步用户信息 diff --git a/order-management-consumer/src/main/java/com/dxhy/order/consumer/openapi/service/impl/SDEnregyServiceImpl.java b/order-management-consumer/src/main/java/com/dxhy/order/consumer/openapi/service/impl/SDEnregyServiceImpl.java index 14cf9903..66c930ff 100644 --- a/order-management-consumer/src/main/java/com/dxhy/order/consumer/openapi/service/impl/SDEnregyServiceImpl.java +++ b/order-management-consumer/src/main/java/com/dxhy/order/consumer/openapi/service/impl/SDEnregyServiceImpl.java @@ -19,6 +19,7 @@ import com.dxhy.order.model.R; import com.dxhy.order.utils.DistributedKeyMaker; import com.dxhy.order.utils.HttpUtils; import com.dxhy.order.utils.JsonUtils; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -36,6 +37,7 @@ import java.util.stream.Collectors; * @Date 2023/2/23 14:24 **/ @Service +@Slf4j public class SDEnregyServiceImpl extends SDEnregyServiceAbstract { @Autowired @@ -74,21 +76,28 @@ public class SDEnregyServiceImpl extends SDEnregyServiceAbstract { @Value("${mdm.buyer.url}") private String buyerUrl; - // 物料主动查询用户名 + // 客商主动查询用户名 @Value("${mdm.buyer.usercode}") private String buyerUsercode; - // 物料主动查询密码 + // 客商主动查询密码 @Value("${mdm.buyer.password}") private String buyerPassword; // ===========客商相关结束=========== - // // 客商主动查询接口 - // @Value("${mdm.buyerUrl}") - // private String buyerUrl; - // // 人员主动查询接口 - // @Value("${mdm.userUrl}") - // private String userUrl; + // ===========人员相关开始=========== + @Value("${mdm.user.url}") + private String userUrl; + + // 物料主动查询用户名 + @Value("${mdm.user.usercode}") + private String userUsercode; + + // 物料主动查询密码 + @Value("${mdm.user.password}") + private String userPassword; + // ===========人员相关结束=========== + @Override public AjaxResult syncBuyerMessage(List mdmGmfxxtbReqBOS, String requestBody) { @@ -411,8 +420,8 @@ public class SDEnregyServiceImpl extends SDEnregyServiceAbstract { HttpResponse response = HttpRequest.post(buyerUrl) .timeout(20000) // 设置请求超时时间 .header("Content-Type", "application/json") - .header("usercode", groupTaxCodeUsercode) - .header("password", groupTaxCodePassword) + .header("usercode", userUsercode) + .header("password", userPassword) .body(requestBody) // 设置请求体内容 .execute(); String resp = response.body(); @@ -438,4 +447,70 @@ public class SDEnregyServiceImpl extends SDEnregyServiceAbstract { 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 = (List) Optional.of(baseBO) + .map(SDEnergyMdmBaseBO::getESB) + .map(ESBBO::getDATA) + .map(DATABO::getDATAINFOS) + .map(DATAINFOSBO::getDATAINFO) + .map(i -> { + // 转成List + return i.stream().map(j -> { + return JSONObject.parseObject(JSONObject.toJSONString(j), MdmSyncUserReqBO.class); + }).collect(Collectors.toList()); + }) + .orElse(new ArrayList()); + + AjaxResult syncMdmUserResult = this.syncMdmUser(mdmSyncUserReqBO, resp); + if (syncMdmUserResult.isSuccess()) { + return R.ok(); + } else { + return R.error(syncMdmUserResult.getMsg()); + } + } }