添加推送用户数据代码
This commit is contained in:
parent
b6374b78f2
commit
89e0e49b40
|
@ -186,7 +186,7 @@ public class LoginController {
|
|||
}
|
||||
}
|
||||
|
||||
private void asyncUser(User user) {
|
||||
public void asyncUser(User user) {
|
||||
// 如果超过一天,执行同步代码
|
||||
CompletableFuture.runAsync(() -> {
|
||||
BaseContext.setCurrentUser(user);
|
||||
|
|
|
@ -5,7 +5,9 @@ import com.chint.application.dtos.response.UserRes;
|
|||
import com.chint.domain.aggregates.user.User;
|
||||
import com.chint.infrastructure.util.BaseContext;
|
||||
import com.chint.infrastructure.util.Result;
|
||||
import com.chint.interfaces.rest.user.PushUser;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
@ -16,10 +18,21 @@ import static com.chint.infrastructure.constant.CommonMessageConstant.SUCCESS;
|
|||
@RequestMapping("/users")
|
||||
public class UserController {
|
||||
|
||||
@Autowired
|
||||
private PushUser pushUser;
|
||||
|
||||
@ApiOperation("根据Id查询用户信息")
|
||||
@PostMapping("/query")
|
||||
public Result<UserRes> getUserByEmployeeNo() {
|
||||
User currentUser = BaseContext.getCurrentUser();
|
||||
return Result.Success(SUCCESS, BeanUtil.copyProperties(currentUser, UserRes.class));
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation("根据Id查询用户信息")
|
||||
@PostMapping("/sync/public")
|
||||
public Result<UserRes> getUserSFDataFromOpenApiBatch() {
|
||||
pushUser.getUserSFDataFromOpenApiBatch();
|
||||
return Result.Success(SUCCESS);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,9 +7,7 @@ import com.chint.domain.repository.LocationRepository;
|
|||
import com.chint.domain.repository.OrderDetailRepository;
|
||||
import com.chint.domain.repository.RouteRepository;
|
||||
import com.chint.domain.repository.UserRepository;
|
||||
import com.chint.interfaces.rest.ctrip.dto.search.car.CarBasicInfo;
|
||||
import com.chint.interfaces.rest.ctrip.dto.search.car.*;
|
||||
import com.chint.interfaces.rest.ctrip.dto.search.car.CarQuickOrderInfoEntity;
|
||||
import com.chint.interfaces.rest.ctrip.dto.search.flight.*;
|
||||
import com.chint.interfaces.rest.ctrip.dto.search.hotel.ClientInfo;
|
||||
import com.chint.interfaces.rest.ctrip.dto.search.hotel.HotelOrderInfoEntity;
|
||||
|
@ -20,12 +18,11 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static com.chint.infrastructure.constant.BelongSystemConstant.*;
|
||||
import static com.chint.infrastructure.constant.CommonMessageConstant.NOT_FOUND;
|
||||
import static com.chint.infrastructure.constant.OrderConstant.ORDER_EVENT_ETA;
|
||||
import static com.chint.infrastructure.constant.UtilConstant.KEEP_TWO_DECIMAL_ZERO;
|
||||
|
||||
import static com.chint.infrastructure.constant.BelongSystemConstant.*;
|
||||
|
||||
@Component
|
||||
public class CTripOrderExtensionFactoryImpl implements OrderExtensionFactory {
|
||||
|
||||
|
@ -107,12 +104,11 @@ public class CTripOrderExtensionFactoryImpl implements OrderExtensionFactory {
|
|||
carOrderDetail.setOrderAmount(String.valueOf(carBasicInfo.getOrderAmount()));
|
||||
|
||||
|
||||
|
||||
|
||||
if (!carQuickOrderInfoEntity.getOrderFeeList().isEmpty()){
|
||||
if (!carQuickOrderInfoEntity.getOrderFeeList().isEmpty()) {
|
||||
OrderFee orderFee = carQuickOrderInfoEntity.getOrderFeeList().get(0);
|
||||
|
||||
if (carOrderDetail.getPaymentType().equals("ACCNT")) {
|
||||
String paymentType = carOrderDetail.getPaymentType();
|
||||
if (paymentType != null && paymentType.equals("ACCNT")) {
|
||||
carOrderDetail.setPaymentType("0");
|
||||
} else {
|
||||
carOrderDetail.setPaymentType("1");
|
||||
|
@ -120,18 +116,14 @@ public class CTripOrderExtensionFactoryImpl implements OrderExtensionFactory {
|
|||
carOrderDetail.setPersonalPaymentAmount(String.valueOf(orderFee.getAccntAmount()));
|
||||
carOrderDetail.setCompanyPaymentAmount(String.valueOf(orderFee.getPersonAmount()));
|
||||
|
||||
if (orderFee.getFeeName().equals("取消费")){
|
||||
if (orderFee.getFeeName().equals("取消费")) {
|
||||
carOrderDetail.setCancellationFee(orderFee.getAmount().toString());
|
||||
}else{
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
OrderProduct orderProduct = carQuickOrderInfoEntity.getOrderProduct();
|
||||
if (orderProduct != null) {
|
||||
carOrderDetail.setStartTime(orderProduct.getServiceBeginTime());
|
||||
|
@ -181,11 +173,9 @@ public class CTripOrderExtensionFactoryImpl implements OrderExtensionFactory {
|
|||
Optional<OrderEvent> first1 = orderDetail.getOrderEventList()
|
||||
.stream()
|
||||
.findFirst();
|
||||
if (first1 != null){
|
||||
carOrderDetail.setOverStandardReason(first1.get().getExtension());
|
||||
}
|
||||
first1.ifPresent(orderEvent -> carOrderDetail.setOverStandardReason(orderEvent.getExtension()));
|
||||
|
||||
// derDetail.setTollFee(tollFee);// 无
|
||||
// derDetail.setTollFee(tollFee);// 无
|
||||
|
||||
return carOrderDetail;
|
||||
}
|
||||
|
@ -231,10 +221,10 @@ public class CTripOrderExtensionFactoryImpl implements OrderExtensionFactory {
|
|||
// FlightRefundInfo flightRefundInfo = flightOrderInfoEntity.getRefundInfo().get(0);
|
||||
|
||||
List<FlightRefundInfo> flightRefundInfoList = flightOrderInfoEntity.getRefundInfo();
|
||||
FlightRefundInfo flightRefundInfo=new FlightRefundInfo();
|
||||
FlightRefundInfo flightRefundInfo = new FlightRefundInfo();
|
||||
|
||||
if (flightRefundInfoList != null && flightRefundInfoList.size() > 1) {
|
||||
flightRefundInfo = flightRefundInfoList.get(0);
|
||||
flightRefundInfo = flightRefundInfoList.get(0);
|
||||
}
|
||||
FlightOrderFeeDetail flightOrderFeeDetail = null;
|
||||
if (!flightOrderInfoEntity.getFlightOrderFeeDetailList().isEmpty()) {
|
||||
|
|
|
@ -22,7 +22,7 @@ public class RouteCacheService {
|
|||
|
||||
|
||||
public List<RouteOrder> preloadUserRoutes(String employeeNo) {
|
||||
List<RouteOrder> routeOrders = jdbcRouteRepository.findByUserIdAndApproveOrderNo_Creator(employeeNo, employeeNo);
|
||||
List<RouteOrder> routeOrders = jdbcRouteRepository.findByUserIdOrApproveOrderNo_Creator(employeeNo, employeeNo);
|
||||
for (RouteOrder routeOrder : routeOrders) {
|
||||
routeCacheManage.cacheRouteOrder(routeOrder);
|
||||
ApproveOrderNo approveOrderNo = routeOrder.getApproveOrderNo();
|
||||
|
|
|
@ -17,7 +17,7 @@ public interface JdbcRouteRepository extends CrudRepository<RouteOrder, Long> {
|
|||
List<RouteOrder> findByUserId(String employeeNo);
|
||||
|
||||
RouteOrder findByRouteId(Long routeId);
|
||||
List<RouteOrder> findByUserIdAndApproveOrderNo_Creator(String userId, String approveOrderNo_creator);
|
||||
List<RouteOrder> findByUserIdOrApproveOrderNo_Creator(String userId, String approveOrderNo_creator);
|
||||
|
||||
RouteOrder findByApproveOrderNo_FakeOrderNoAndApproveOrderNo_SysCode(String approveOrderNo_fakeOrderNo, String sysCode);
|
||||
|
||||
|
|
|
@ -74,6 +74,20 @@ public class CTripUserSaveRequest {
|
|||
postRequest.post(userUrl, authenticationListRequest, AuthenticationResponseList.class);
|
||||
}
|
||||
|
||||
public void saveUserToCTrip(User user) {
|
||||
String ticket = ticketRequest.loadTicket();
|
||||
AuthenticationEntity authenticationEntity = buildAuthenticationEntityWithUser(user);
|
||||
AuthenticationListRequest authenticationListRequest = new AuthenticationListRequest();
|
||||
authenticationListRequest.setAppkey(C_TRIP_APP_KEY);
|
||||
authenticationListRequest.setTicket(ticket);
|
||||
authenticationListRequest.setCorporationID(C_TRIP_CORP_ID);
|
||||
AuthenticationInfo authenticationInfo = new AuthenticationInfo();
|
||||
authenticationInfo.setSequence("0");
|
||||
authenticationInfo.setAuthentication(authenticationEntity);
|
||||
authenticationListRequest.setAuthenticationInfoList(List.of(authenticationInfo));
|
||||
postRequest.post(userUrl, authenticationListRequest, AuthenticationResponseList.class);
|
||||
}
|
||||
|
||||
|
||||
public AuthenticationEntity buildAuthenticationEntityWithUser(User user) {
|
||||
AuthenticationEntity authenticationEntity = new AuthenticationEntity();
|
||||
|
|
|
@ -242,6 +242,9 @@ public class CTripNoteController {
|
|||
case "WaitService" ->
|
||||
// "等待接驾"可能表示服务即将开始,但没有直接映射,可能需要新的状态常量
|
||||
OrderConstant.ORDER_EVENT_ORDERED;
|
||||
case "Successful" ->
|
||||
// 成功
|
||||
OrderConstant.ORDER_EVENT_ORDERED;
|
||||
case "Redispatched" ->
|
||||
// "改派中"可能需要新的状态常量,因为它没有直接映射
|
||||
OrderConstant.ORDER_EVENT_PAYED;
|
||||
|
|
|
@ -71,6 +71,14 @@ public class LYUserRequest {
|
|||
}
|
||||
}
|
||||
|
||||
public boolean saveCurrentUser(User user) {
|
||||
EmployeeEntity employeeEntity = user2LYEmployee(user);
|
||||
EmployeeRequest employeeData = new EmployeeRequest();
|
||||
employeeData.setParam(employeeEntity);
|
||||
UserResponse post = postRequest.post(userUrl, employeeData, UserResponse.class);
|
||||
return post.isSuccess();
|
||||
}
|
||||
|
||||
private EmployeeEntity user2LYEmployee(User user) {
|
||||
EmployeeEntity employeeEntity = new EmployeeEntity();
|
||||
employeeEntity.setOutEmployeeId(String.valueOf(user.getEmployeeNo()));
|
||||
|
|
|
@ -0,0 +1,165 @@
|
|||
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.domain.aggregates.user.User;
|
||||
import com.chint.domain.repository.StaffRankRepository;
|
||||
import com.chint.domain.repository.UserRepository;
|
||||
import com.chint.domain.service.JTCompanyDomainService;
|
||||
import com.chint.interfaces.rest.ctrip.CTripUserSaveRequest;
|
||||
import com.chint.interfaces.rest.ly.LYUserRequest;
|
||||
import com.chint.interfaces.rest.user.dto.AccessKeyDTO;
|
||||
import com.chint.interfaces.rest.user.dto.UserDataDTO;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static com.chint.infrastructure.constant.SFConstant.*;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class PushUser {
|
||||
|
||||
@Value("${sf.systemId}")
|
||||
private String systemId;
|
||||
|
||||
@Value("${sf.openApiBaseUrl}")
|
||||
private String OPENAI_BASE_URL;
|
||||
|
||||
@Autowired
|
||||
private LYUserRequest lyUserRequest;
|
||||
|
||||
@Autowired
|
||||
private CTripUserSaveRequest cTripUserSaveRequest;
|
||||
|
||||
@Autowired
|
||||
private UserRepository userRepository;
|
||||
|
||||
@Autowired
|
||||
private JTCompanyDomainService jtCompanyDomainService;
|
||||
|
||||
@Autowired
|
||||
private StaffRankRepository staffRankRepository;
|
||||
|
||||
@Autowired
|
||||
private UserSFRequest userSFRequest;
|
||||
|
||||
@Autowired
|
||||
private UserHttpRequestImpl userHttpRequest;
|
||||
|
||||
private AccessKeyDTO akSkLoad() {
|
||||
String asSkUrl = AK_BASE_URL + GET_AK_URL + "?systemId=" + systemId;
|
||||
HttpClient client = HttpClients.createDefault();
|
||||
HttpGet getMethod = new HttpGet(asSkUrl);
|
||||
getMethod.setHeader("Content-Type", "application/json");
|
||||
try {
|
||||
var response = client.execute(getMethod);
|
||||
var responseBody = EntityUtils.toString(response.getEntity(), "UTF-8");
|
||||
var gson = new Gson();
|
||||
return gson.fromJson(responseBody, AccessKeyDTO.class);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public List<User> getUserSFDataFromOpenApiBatch() {
|
||||
int start;
|
||||
int pageSize = 1000;
|
||||
int page = 1;
|
||||
List<User> list = new ArrayList<>();
|
||||
while (true) {
|
||||
log.info("Pull user. page={}", page);
|
||||
start = (page - 1) * 1000;
|
||||
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<String, Object>();
|
||||
map.put("start", start);
|
||||
map.put("pageSize", pageSize);
|
||||
DataCenterResult result = dataCenterService.post(USER_DATA_PATH, map);
|
||||
Type type = new TypeToken<List<UserDataDTO>>() {
|
||||
}.getType();
|
||||
List<UserDataDTO> userDataDTOs = gson.fromJson(result.getData().toString(), type);
|
||||
|
||||
List<User> users = userDataDTOs.stream().filter(it -> jtCompanyDomainService.ifCompanyInJT(null, it.getCompany())
|
||||
|| it.getCompany().equals("A70000056"))
|
||||
.map(userData -> {
|
||||
User user = new User();
|
||||
user.setCompanyCode(userData.getCompany());
|
||||
user.setWorkStatus(userData.getStatus());
|
||||
user.setGender(userData.getGender());
|
||||
user.setName(userData.getUname());
|
||||
user.setPhoneNumber(userData.getMobilePhone());
|
||||
user.setCompanyName(userData.getCompany_cn());
|
||||
user.setManaLevel(userData.getCust_manaLevel());
|
||||
user.setProfLevel(userData.getCust_profLevel());
|
||||
user.setQualityLevel(userData.getCust_qualityLevel());
|
||||
return user;
|
||||
})
|
||||
.toList();
|
||||
if (isNullOrEmpty(users)) {
|
||||
break;
|
||||
}
|
||||
if (page % 10 == 0) {
|
||||
log.info("Pull user wating...");
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
users.forEach(user -> userHttpRequest.loadRankCode(user));
|
||||
page++;
|
||||
|
||||
list.addAll(users);
|
||||
}
|
||||
|
||||
list = list.stream().filter(user -> user.getEmployeeNo() != null).toList();
|
||||
|
||||
for (User user : list) {
|
||||
Optional.ofNullable(userRepository.findByUserEmployeeNo(user.getEmployeeNo())).ifPresent(
|
||||
this::asyncUser
|
||||
);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
public void asyncUser(User user) {
|
||||
lyUserRequest.saveCurrentUser(user);
|
||||
cTripUserSaveRequest.saveUserToCTrip(user);
|
||||
// 发送保存用户同步时间
|
||||
user.setSyncTime(LocalDateTime.now());
|
||||
userRepository.save(user);
|
||||
}
|
||||
|
||||
|
||||
public static <T> boolean isNullOrEmpty(List<T> list) {
|
||||
if (list == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return list.isEmpty();
|
||||
}
|
||||
}
|
|
@ -1,25 +1,46 @@
|
|||
package com.chint.interfaces.rest.user;
|
||||
|
||||
|
||||
import com.chint.application.out.LoginController;
|
||||
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;
|
||||
import com.chint.domain.repository.StaffRankRepository;
|
||||
import com.chint.domain.repository.UserRepository;
|
||||
import com.chint.domain.service.JTCompanyDomainService;
|
||||
import com.chint.domain.service.RankDomainService;
|
||||
import com.chint.infrastructure.constant.SFConstant;
|
||||
import com.chint.infrastructure.util.BaseContext;
|
||||
import com.chint.infrastructure.util.StringCheck;
|
||||
import com.chint.interfaces.rest.base.PostRequest;
|
||||
import com.chint.interfaces.rest.ctrip.CTripUserSaveRequest;
|
||||
import com.chint.interfaces.rest.ly.LYUserRequest;
|
||||
import com.chint.interfaces.rest.user.dto.AccessKeyDTO;
|
||||
import com.chint.interfaces.rest.user.dto.UserDataDTO;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import static com.chint.infrastructure.constant.RankConstant.*;
|
||||
import static com.chint.infrastructure.constant.SFConstant.GET_AK_URL;
|
||||
import static com.chint.infrastructure.constant.SFConstant.USER_DATA_PATH;
|
||||
|
||||
|
||||
@Slf4j
|
||||
|
@ -50,13 +71,19 @@ public class UserHttpRequestImpl implements UserHttpRequest {
|
|||
@Autowired
|
||||
private UserSFRequest userSFRequest;
|
||||
|
||||
|
||||
|
||||
|
||||
@Value("${sf.systemId}")
|
||||
private String systemId;
|
||||
|
||||
@Override
|
||||
public User loadUserInfo(User user) {
|
||||
loadSFInfo(user);
|
||||
return loadRankCode(user);
|
||||
}
|
||||
|
||||
private User loadRankCode(User user) {
|
||||
public User loadRankCode(User user) {
|
||||
String rankName;
|
||||
if (user.getManaLevel() != null) {
|
||||
rankName = user.getManaLevel();
|
||||
|
@ -174,4 +201,5 @@ public class UserHttpRequestImpl implements UserHttpRequest {
|
|||
user.setQualityLevel(userData.getCust_qualityLevel());
|
||||
return user;
|
||||
}
|
||||
|
||||
}
|
|
@ -78,34 +78,5 @@ public class UserSFRequest {
|
|||
}
|
||||
|
||||
|
||||
public List<User> getUserSFDataFromOpenApiBatch() {
|
||||
int start;
|
||||
int pageSize = 1000;
|
||||
int page = 1;
|
||||
|
||||
while (true){
|
||||
start = (page - 1) * 1000;
|
||||
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<String, Object>();
|
||||
map.put("start", start);
|
||||
map.put("pageSize", pageSize);
|
||||
DataCenterResult result = dataCenterService.post(USER_DATA_PATH, map);
|
||||
Type type = new TypeToken<List<UserDataDTO>>() {
|
||||
}.getType();
|
||||
List<UserDataDTO> userDataDTOs = gson.fromJson(result.getData().toString(), type);
|
||||
|
||||
userDataDTOs.stream().filter(it-> jtCompanyDomainService.ifCompanyInJT(null, it.getCompany()));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// return userDataDTOs.stream().toList().stream().map(UserDataDTO::getLoginUsername).toList();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue