From 93a001ce6a925351a020cda8e81afc1a271d609e Mon Sep 17 00:00:00 2001 From: lulz1 Date: Sun, 25 Feb 2024 22:17:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=AF=AF=E5=88=A0=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rest/user/UserHttpRequestImpl.java | 146 +++++++++--------- src/test/java/com/chint/CTripTest.java | 2 +- src/test/java/com/chint/LYTest.java | 4 +- .../java/com/chint/RouteApplicationTests.java | 2 +- 4 files changed, 80 insertions(+), 74 deletions(-) diff --git a/src/main/java/com/chint/interfaces/rest/user/UserHttpRequestImpl.java b/src/main/java/com/chint/interfaces/rest/user/UserHttpRequestImpl.java index a94f4dcc..44a60ab4 100644 --- a/src/main/java/com/chint/interfaces/rest/user/UserHttpRequestImpl.java +++ b/src/main/java/com/chint/interfaces/rest/user/UserHttpRequestImpl.java @@ -1,9 +1,9 @@ package com.chint.interfaces.rest.user; -//import com.chint.dc.api.DataCenterResult; -//import com.chint.dc.api.dto.DataCenterOption; -//import com.chint.dc.api.service.DataCenterService; +import com.chint.dc.api.DataCenterResult; +import com.chint.dc.api.dto.DataCenterOption; +import com.chint.dc.api.service.DataCenterService; import com.chint.domain.aggregates.standards.Ranks; import com.chint.domain.aggregates.user.User; @@ -14,6 +14,7 @@ import com.chint.infrastructure.util.StringCheck; import com.chint.interfaces.rest.base.PostRequest; import com.chint.interfaces.rest.user.dto.*; import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.HttpClients; @@ -21,15 +22,20 @@ import org.apache.http.util.EntityUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.lang.reflect.Type; import java.util.LinkedHashMap; import java.util.List; +import java.util.Optional; + +import static com.chint.infrastructure.constant.SFConstant.OPENAI_BASE_URL; +import static com.chint.infrastructure.constant.SFConstant.USER_DATA_PATH; @Service public class UserHttpRequestImpl implements UserHttpRequest { private final String asSkUrl = SFConstant.AK_BASE_URL + SFConstant.GET_AK_URL + "?systemId=" + SFConstant.SYSTEM_ID; - private final String userUrl = SFConstant.OPENAI_BASE_URL + SFConstant.USER_DATA_PATH; + private final String userUrl = OPENAI_BASE_URL + USER_DATA_PATH; private final String travelRankUrl = SFConstant.TRAVEL_RANK_BASE_URL + SFConstant.TRAVEL_RANK_PATH; @Autowired @@ -72,73 +78,73 @@ public class UserHttpRequestImpl implements UserHttpRequest { } private User loadSFInfo(User user) { -// Gson gson = new Gson(); -// AccessKeyDTO akSkLoad = akSkLoad(); -// DataCenterOption option = new DataCenterOption(); -// option.setSk(akSkLoad.sk); -// option.setAk(akSkLoad.ak); -// option.setUrl(OPENAI_BASE_URL); -// DataCenterService dataCenterService = new DataCenterService(option); -// LinkedHashMap map = new LinkedHashMap(); -// map.put("LoginUsername", user.getEmployeeNo().toString()); -// map.put("start", 0); -// map.put("pageSize", 99); -// DataCenterResult result = dataCenterService.post(USER_DATA_PATH, map); -// Type type = new TypeToken>() { -// }.getType(); -// if (result.getData() != null) { -// String companyCode = user.getCompanyCode(); -// if (companyCode == null) { -// companyCode = BaseContext.getCurrentUser().getUserLoginParam().getCompanyCode(); -// } -// String newCompanyCode = companyCode; -// -// if (fromJson.size() == 1) { -// UserDataDTO userData = fromJson.get(0); -// user.setCompanyCode(userData.getCompany()); -// user.setWorkStatus(userData.getStatus()); -// user.setGender(userData.getGender()); -// user.setName(userData.getUname()); -// user.setPhoneNumber(userData.getMobilePhone()); -// user.setManaLevel(userData.getCust_manaLevel()); -// user.setProfLevel(userData.getCust_profLevel()); -// } else { -// Optional first; -// -// //这里进行判断如果是中文字段的CompanyCode需要用中文名进行匹配 -// if (StringCheck.isFirstCharacterChinese(newCompanyCode)) { -// first = fromJson.stream() -// .filter(userData -> userData.getCompany_cn().equals(newCompanyCode)) -// .findFirst(); -// -// } else { -// first = fromJson.stream() -// .filter(userData -> userData.getCompany().equals(newCompanyCode)) -// .findFirst(); -// } -// first.ifPresent( -// userData -> { -// user.setCompanyCode(userData.getCompany()); -// user.setWorkStatus(userData.getStatus()); -// user.setGender(userData.getGender()); -// user.setName(userData.getUname()); -// user.setPhoneNumber(userData.getMobilePhone()); -// } -// ); -// fromJson.stream() -// .filter(userData -> userData.getUserId().equals(userData.getPersonIdExternal())) -// .findFirst() -// .ifPresent(userData -> { -// user.setManaLevel(userData.getCust_manaLevel()); -// user.setProfLevel(userData.getCust_profLevel()); -// }); -// } -// return user; -// } else { -// throw new RuntimeException("用户数据不存在"); -// } + Gson gson = new Gson(); + AccessKeyDTO akSkLoad = akSkLoad(); + DataCenterOption option = new DataCenterOption(); + option.setSk(akSkLoad.sk); + option.setAk(akSkLoad.ak); + option.setUrl(OPENAI_BASE_URL); + DataCenterService dataCenterService = new DataCenterService(option); + LinkedHashMap map = new LinkedHashMap(); + map.put("LoginUsername", user.getEmployeeNo().toString()); + map.put("start", 0); + map.put("pageSize", 99); + DataCenterResult result = dataCenterService.post(USER_DATA_PATH, map); + Type type = new TypeToken>() { + }.getType(); + if (result.getData() != null) { + String companyCode = user.getCompanyCode(); + if (companyCode == null) { + companyCode = BaseContext.getCurrentUser().getUserLoginParam().getCompanyCode(); + } + String newCompanyCode = companyCode; + List fromJson = gson.fromJson(result.getData().toString(), type); + if (fromJson.size() == 1) { + UserDataDTO userData = fromJson.get(0); + user.setCompanyCode(userData.getCompany()); + user.setWorkStatus(userData.getStatus()); + user.setGender(userData.getGender()); + user.setName(userData.getUname()); + user.setPhoneNumber(userData.getMobilePhone()); + user.setManaLevel(userData.getCust_manaLevel()); + user.setProfLevel(userData.getCust_profLevel()); + } else { + Optional first; - return null; + //这里进行判断如果是中文字段的CompanyCode需要用中文名进行匹配 + if (StringCheck.isFirstCharacterChinese(newCompanyCode)) { + first = fromJson.stream() + .filter(userData -> userData.getCompany_cn().equals(newCompanyCode)) + .findFirst(); + + } else { + first = fromJson.stream() + .filter(userData -> userData.getCompany().equals(newCompanyCode)) + .findFirst(); + } + first.ifPresent( + userData -> { + user.setCompanyCode(userData.getCompany()); + user.setWorkStatus(userData.getStatus()); + user.setGender(userData.getGender()); + user.setName(userData.getUname()); + user.setPhoneNumber(userData.getMobilePhone()); + } + ); + fromJson.stream() + .filter(userData -> userData.getUserId().equals(userData.getPersonIdExternal())) + .findFirst() + .ifPresent(userData -> { + user.setManaLevel(userData.getCust_manaLevel()); + user.setProfLevel(userData.getCust_profLevel()); + }); + } + return user; + } else { + throw new RuntimeException("用户数据不存在"); + } + +// return null; } diff --git a/src/test/java/com/chint/CTripTest.java b/src/test/java/com/chint/CTripTest.java index 5b20ec64..8a01106d 100644 --- a/src/test/java/com/chint/CTripTest.java +++ b/src/test/java/com/chint/CTripTest.java @@ -149,7 +149,7 @@ public class CTripTest { System.out.println(response); } - @Test +// @Test void searchAndHandlerData(){ BaseContext.setCurrentUser(user); SupplierCallbackData supplierCallbackData = diff --git a/src/test/java/com/chint/LYTest.java b/src/test/java/com/chint/LYTest.java index 9c12266f..8eef54a3 100644 --- a/src/test/java/com/chint/LYTest.java +++ b/src/test/java/com/chint/LYTest.java @@ -293,7 +293,7 @@ public class LYTest { } //超标 - @Test +// @Test void exceedStandard() { BPMBaseRequest bpmRequest = new BPMBaseRequest(); Gson gson = new Gson(); @@ -318,7 +318,7 @@ public class LYTest { } //改签 - @Test +// @Test void reschedule() { BPMBaseRequest bpmRequest = new BPMBaseRequest(); Gson gson = new Gson(); diff --git a/src/test/java/com/chint/RouteApplicationTests.java b/src/test/java/com/chint/RouteApplicationTests.java index 766728ae..3592c006 100644 --- a/src/test/java/com/chint/RouteApplicationTests.java +++ b/src/test/java/com/chint/RouteApplicationTests.java @@ -43,7 +43,7 @@ class RouteApplicationTests { LocalDateTime parse = LocalDateTime.parse("2024-04-15 23:59:00", dateTimeFormatter); System.out.println(parse); } - @Test +// @Test void loginSign() { String sfno = "230615020"; String syscode = "abc";