同步代码

This commit is contained in:
lulz1 2024-02-27 13:44:34 +08:00
parent 65593e353f
commit 8083483fa9
20 changed files with 380 additions and 13 deletions

View File

@ -0,0 +1,17 @@
package com.chint.application.dtos;
import lombok.Data;
@Data
public class LoginResponse {
private String redirectUrl;
private boolean success;
public static LoginResponse success(String redirectUrl){
LoginResponse loginResponse = new LoginResponse();
loginResponse.setSuccess(true);
loginResponse.setRedirectUrl(redirectUrl);
return loginResponse;
}
}

View File

@ -0,0 +1,18 @@
package com.chint.application.dtos;
import com.chint.domain.aggregates.user.User;
import lombok.Data;
@Data
public class UserDTO {
private String accountId;
private String mobile;
private String userName;
private String uid;
private String email;
// 构造函数和其他方法getter setter可以根据需要添加
// Getter Setter 方法
}

View File

@ -0,0 +1,32 @@
package com.chint.application.out;
import com.chint.application.dtos.LoginResponse;
import com.chint.domain.aggregates.user.User;
import com.chint.infrastructure.util.BaseContext;
import com.chint.infrastructure.util.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import static com.chint.infrastructure.constant.CommonMessageConstant.SUCCESS;
import static com.chint.infrastructure.constant.FSSCConstant.FSSC_LOGIN_PATH;
@RestController
@RequestMapping("/fssc")
public class FSSCController {
@Value("${FSSC.baseUrl}")
private String FSSCUrl;
@ApiOperation("单点登录到财务共享")
@PostMapping("/login")
public Result<LoginResponse> loginToFSSC() {
User currentUser = BaseContext.getCurrentUser();
return Result.Success(SUCCESS, LoginResponse.success(FSSCUrl +FSSC_LOGIN_PATH + currentUser.getEmployeeNo().toString()));
}
}

View File

@ -17,12 +17,10 @@ import com.chint.infrastructure.util.Result;
import com.chint.interfaces.rest.ctrip.CTripUserSaveRequest; import com.chint.interfaces.rest.ctrip.CTripUserSaveRequest;
import com.chint.interfaces.rest.ly.LYUserRequest; import com.chint.interfaces.rest.ly.LYUserRequest;
import com.chint.interfaces.rest.user.UserHttpRequest; import com.chint.interfaces.rest.user.UserHttpRequest;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
@ -45,6 +43,7 @@ public class LoginController {
@Autowired @Autowired
private SystemDomainService systemDomainService; private SystemDomainService systemDomainService;
@ApiOperation("财务共享登录")
@Transactional @Transactional
@GetMapping("/login") @GetMapping("/login")
public Result<UserLoginResult> login(@RequestParam("sfno") String sfno, public Result<UserLoginResult> login(@RequestParam("sfno") String sfno,
@ -96,4 +95,32 @@ public class LoginController {
} }
} }
@ApiOperation("商旅平台单点")
@Transactional
@PostMapping("/login/sso")
public Result<UserLoginResult> loginSSO(){
UserLoginParam userLoginParam = new UserLoginParam();
userLoginParam.setSfno("170717012");
UserLoginResult userLoginResult = authenticateService
.authenticateEmployeeNo(userLoginParam);
//异步执行更新用户信息到同程
User currentUser = userLoginResult.getUser();
CompletableFuture.runAsync(() -> {
BaseContext.setCurrentUser(currentUser);
lyUserRequest.saveCurrentUser();
BaseContext.removeCurrentUser();
});
//异步执行更新用户信息到携程
CompletableFuture.runAsync(() -> {
BaseContext.setCurrentUser(currentUser);
cTripUserSaveRequest.saveUserToCTrip();
BaseContext.removeCurrentUser();
});
//清除职级信息
userLoginResult.getUser().setProfLevel(null);
userLoginResult.getUser().setManaLevel(null);
return Result.Success(CommonMessageConstant.SUCCESS, userLoginResult);
}
} }

View File

@ -225,8 +225,10 @@ public class OrderQuery {
.findFirst().get(); .findFirst().get();
scheduleDetailBuilder scheduleDetailBuilder
.startCity(originCity.getCityName())
.startCityName(originCity.getCityName()) .startCityName(originCity.getCityName())
.startCityEnName(originCity.getCityename()) .startCityEnName(originCity.getCityename())
.endCityName(destinationCity.getCityName())
.endCity(destinationCity.getCityName()) .endCity(destinationCity.getCityName())
.endCityEnName(destinationCity.getCityename()); .endCityEnName(destinationCity.getCityename());
} }

View File

@ -2,7 +2,9 @@ package com.chint.application.services;
import com.chint.application.dtos.SupplierLoginParam; import com.chint.application.dtos.SupplierLoginParam;
import com.chint.domain.aggregates.order.RouteOrder; import com.chint.domain.aggregates.order.RouteOrder;
import com.chint.domain.aggregates.user.User;
import com.chint.domain.repository.RouteRepository; import com.chint.domain.repository.RouteRepository;
import com.chint.infrastructure.util.BaseContext;
import com.chint.interfaces.rest.ctrip.CTripLoginRequest; import com.chint.interfaces.rest.ctrip.CTripLoginRequest;
import com.chint.interfaces.rest.ctrip.dto.login.H5Response; import com.chint.interfaces.rest.ctrip.dto.login.H5Response;
import com.chint.interfaces.rest.ctrip.dto.login.PCResponse; import com.chint.interfaces.rest.ctrip.dto.login.PCResponse;
@ -45,7 +47,12 @@ public class SupplierLoginService {
} }
private String getEmployeeNo(Long routeId) { private String getEmployeeNo(Long routeId) {
if (routeId != null) {
RouteOrder routeOrder = routeRepository.queryById(routeId); RouteOrder routeOrder = routeRepository.queryById(routeId);
return routeOrder.getUserId().toString(); return routeOrder.getUserId().toString();
} else {
User currentUser = BaseContext.getCurrentUser();
return currentUser.getEmployeeNo().toString();
}
} }
} }

View File

@ -0,0 +1,21 @@
package com.chint.application.services.login;
import com.chint.domain.aggregates.user.User;
import org.springframework.stereotype.Component;
import java.util.Optional;
@Component
public class LocalLoginStrategy implements LoginStrategy {
@Override
public Optional<String> getAccessToken(String code) {
return Optional.empty();
}
@Override
public User getUserInfo(String accessToken) {
return null;
}
}

View File

@ -0,0 +1,5 @@
package com.chint.application.services.login;
public interface LoginService<T> {
T login(String username, String password);
}

View File

@ -0,0 +1,53 @@
package com.chint.application.services.login;
import com.chint.domain.aggregates.user.User;
import com.chint.domain.exceptions.AuthException;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public interface LoginStrategy {
Logger log = LoggerFactory.getLogger("UserService");
default User login(String code) {
Optional<String> accessToken = getAccessToken(code);
return getUserInfo(accessToken.orElseThrow(()-> new AuthException("Failed to obtain access token")));
}
Optional<String> getAccessToken(String code);
User getUserInfo(String accessToken);
static Optional<String> getAccessTokenMethod(HttpRequestBase request, String tokenName) {
String responseBody = null;
HttpClient client = HttpClients.createDefault();
try {
HttpResponse response = client.execute(request);
responseBody = EntityUtils.toString(response.getEntity(), "UTF-8");
} catch (IOException e) {
log.error(e.getMessage());
}
String pattern = "\"" + tokenName + "\":\"([^\"]+)\"";
if (responseBody == null) {
return Optional.empty();
}
Matcher matcher = Pattern.compile(pattern).matcher(responseBody);
if (matcher.find()) {
return Optional.of(matcher.group(1));
} else {
log.info(tokenName + " not found.");
return Optional.empty();
}
}
}

View File

@ -0,0 +1,118 @@
package com.chint.application.services.login.strategy;
import com.alibaba.fastjson.JSON;
import com.chint.application.dtos.UserDTO;
import com.chint.application.services.login.LoginStrategy;
import com.chint.domain.aggregates.user.User;
import com.chint.domain.exceptions.AuthException;
import com.chint.domain.factoriy.user.UserFactory;
import com.chint.domain.repository.UserRepository;
import com.chint.interfaces.rest.user.UserHttpRequest;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
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.io.IOException;
import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import static com.chint.infrastructure.constant.CommonMessageConstant.NOT_FOUND;
@Slf4j
@Component
public class PailaLoginStrategy implements LoginStrategy {
@Value("${paila.base-url}")
private String baseUrl;
@Value("${paila.client-id}")
private String clientId;
@Value("${paila.client-secret}")
private String clientSecret;
@Value("${paila.redirect-url}")
private String redirectUri;
@Autowired
private UserRepository userRepository;
@Autowired
private UserHttpRequest userHttpRequest;
@Autowired
private UserFactory userFactory;
@Override
public Optional<String> getAccessToken(String code) {
log.info("开始执行登录");
List<NameValuePair> parameters = Arrays.asList(
new BasicNameValuePair("client_id", clientId),
new BasicNameValuePair("client_secret", clientSecret),
new BasicNameValuePair("redirect_uri", redirectUri),
new BasicNameValuePair("code", code)
);
HttpGet getMethod = getRequest("/profile/oauth2/accessToken", parameters);
return LoginStrategy.getAccessTokenMethod(getMethod, "access_token");
}
@Override
public User getUserInfo(String accessToken) {
List<NameValuePair> userInfoParams = Collections.singletonList(
new BasicNameValuePair("access_token", accessToken)
);
HttpGet getMethodUserInfo = getRequest("/profile/oauth2/profile", userInfoParams);
String userInfoResBody = null;
HttpClient client = HttpClients.createDefault();
try {
HttpResponse userInfoRes = client.execute(getMethodUserInfo);
userInfoResBody = EntityUtils.toString(userInfoRes.getEntity(), "UTF-8");
} catch (IOException e) {
log.error(e.getMessage());
}
UserDTO userDTO = JSON.parseObject(userInfoResBody, UserDTO.class);
User user;
if (userDTO != null) {
user = userRepository.findByUserEmployeeNo(Long.parseLong(userDTO.getUid()));
if (user == null) {
user = userFactory.create(userDTO.getUid());
userHttpRequest.loadUserInfo(user);
userRepository.save(user);
}
} else {
throw new AuthException(NOT_FOUND);
}
return user;
}
private HttpGet getRequest(String path, List<NameValuePair> parameters) {
String userInfoUrl = null;
try {
userInfoUrl = new URIBuilder(baseUrl).setPath(path)
.setParameters(parameters).build().toString();
} catch (URISyntaxException e) {
log.error(e.getMessage());
}
HttpGet request = new HttpGet(userInfoUrl);
request.setHeader("Content-Type", "application/json");
return request;
}
}

View File

@ -16,6 +16,7 @@ import java.util.List;
import java.util.Optional; import java.util.Optional;
import static com.chint.infrastructure.constant.OrderConstant.ORDER_DETAIL_STATUS_SUCCESS; import static com.chint.infrastructure.constant.OrderConstant.ORDER_DETAIL_STATUS_SUCCESS;
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.UtilConstant.KEEP_TWO_DECIMAL_ZERO;
@Component @Component
@ -94,10 +95,31 @@ public class CTripOrderExtensionFactoryImpl implements OrderExtensionFactory {
String orderNo = hotelOrderInfoEntity.getOrderID(); String orderNo = hotelOrderInfoEntity.getOrderID();
Optional<OrderDetail> byOrderNo = orderDetailRepository.findByOrderNo(orderNo); Optional<OrderDetail> byOrderNo = orderDetailRepository.findByOrderNo(orderNo);
String journeyNo = hotelOrderInfoEntity.getJourneyNo(); String journeyNo = hotelOrderInfoEntity.getJourneyNo();
RouteOrder routeOrder = routeRepository.findByOrderNo(journeyNo).reloadStatus(); RouteOrder routeOrder = routeRepository.findByOrderNo(journeyNo).reloadStatus();
ApproveOrderNo approveOrderNo = routeOrder.getApproveOrderNo(); ApproveOrderNo approveOrderNo = routeOrder.getApproveOrderNo();
HotelOrderDetail hotelOrderDetail = new HotelOrderDetail();
HotelOrderDetail hotelOrderDetail;
if (byOrderNo.isPresent()) {
if (byOrderNo.get().getHotelOrderDetail() == null) {
hotelOrderDetail = new HotelOrderDetail();
} else {
hotelOrderDetail = byOrderNo.get().getHotelOrderDetail();
}
} else {
hotelOrderDetail = new HotelOrderDetail();
}
if (byOrderNo.isPresent() && byOrderNo.get()
.getLastEvent()
.getEventType()
.equals(ORDER_EVENT_ETA)) {
hotelOrderDetail.setOverStandard("true");
} else {
hotelOrderDetail.setOverStandard("false");
}
hotelOrderDetail.setOrderNo(orderNo); //订单号 hotelOrderDetail.setOrderNo(orderNo); //订单号
hotelOrderDetail.setOverStandard(null); //是否超标 hotelOrderDetail.setOverStandard(null); //是否超标
hotelOrderDetail.setOrderStatus(ORDER_DETAIL_STATUS_SUCCESS); hotelOrderDetail.setOrderStatus(ORDER_DETAIL_STATUS_SUCCESS);
@ -126,8 +148,8 @@ public class CTripOrderExtensionFactoryImpl implements OrderExtensionFactory {
hotelOrderDetail.setStarRate(hotelOrderInfoEntity.getStar()); hotelOrderDetail.setStarRate(hotelOrderInfoEntity.getStar());
hotelOrderDetail.setCheckInDate(hotelOrderInfoEntity.getStartTime()); //入住日期 hotelOrderDetail.setCheckInDate(hotelOrderInfoEntity.getStartTime()); //入住日期
hotelOrderDetail.setDepartureDate(hotelOrderInfoEntity.getEndTime()); //离店日期 "2022-09-10" hotelOrderDetail.setDepartureDate(hotelOrderInfoEntity.getEndTime()); //离店日期 "2022-09-10"
hotelOrderDetail.setNightCount(hotelOrderInfoEntity.getQuantity()); //退订夜间数 hotelOrderDetail.setNightCount(hotelOrderInfoEntity.getRoomDays()); //退订夜间数
hotelOrderDetail.setRoomCount(hotelOrderInfoEntity.getQuantity()); //退订夜间数 hotelOrderDetail.setRoomCount(hotelOrderInfoEntity.getRoomQuantity()); //退订夜间数
hotelOrderDetail.setRoomTypeName(hotelOrderInfoEntity.getRoomName()); //房型 hotelOrderDetail.setRoomTypeName(hotelOrderInfoEntity.getRoomName()); //房型
hotelOrderDetail.setPaymentType("1"); //付款方式 0公司统付1个人付 2混付 hotelOrderDetail.setPaymentType("1"); //付款方式 0公司统付1个人付 2混付

View File

@ -13,6 +13,8 @@ public class LYOrderExtensionFactoryImpl implements OrderExtensionFactory{
@Override @Override
public TrainOrderDetail createTrainOrderDetail(Object trainOrderDetailData) { public TrainOrderDetail createTrainOrderDetail(Object trainOrderDetailData) {
return null; return null;
} }

View File

@ -43,6 +43,7 @@ public class AuthenticateServiceImpl implements AuthenticateService {
User user = userRepository.findByUserEmployeeNo(Long.parseLong(userLoginParam.getSfno())); User user = userRepository.findByUserEmployeeNo(Long.parseLong(userLoginParam.getSfno()));
if (user != null) { if (user != null) {
// 部分数据需要通过查询外部的http来获取 // 部分数据需要通过查询外部的http来获取
BaseContext.setCurrentUser(user);
user.setCompanyCode(userLoginParam.getCompanyCode()); user.setCompanyCode(userLoginParam.getCompanyCode());
user.setUserLoginParam(userLoginParam); user.setUserLoginParam(userLoginParam);
httpRequest.loadUserInfo(user); httpRequest.loadUserInfo(user);

View File

@ -21,6 +21,16 @@ public class UserLoginParam {
private String timespan; private String timespan;
private String code;
public UserLoginParam(String sfno, String syscode, String billcode, String companyCode, String timespan) {
this.sfno = sfno;
this.syscode = syscode;
this.billcode = billcode;
this.companyCode = companyCode;
this.timespan = timespan;
}
public static UserLoginParam of(String json) { public static UserLoginParam of(String json) {
Gson gson = new Gson(); Gson gson = new Gson();
return gson.fromJson(json, UserLoginParam.class); return gson.fromJson(json, UserLoginParam.class);

View File

@ -9,4 +9,5 @@ public class FSSCConstant {
public static final String TRIP_CALLBACK_HOTEL_TYPE = "Hotel";//申请单类型 public static final String TRIP_CALLBACK_HOTEL_TYPE = "Hotel";//申请单类型
public static final String TRIP_CALLBACK_TRAIN_TYPE = "Train";//申请单类型 public static final String TRIP_CALLBACK_TRAIN_TYPE = "Train";//申请单类型
public static final String TRIP_CALLBACK_OTHER_TYPE = "Other";//申请单类型 public static final String TRIP_CALLBACK_OTHER_TYPE = "Other";//申请单类型
public static final String FSSC_LOGIN_PATH = "/ecs-console/api/rest/loginWeaver?loginName=";//申请单类型
} }

View File

@ -66,7 +66,8 @@ public class HotelOrderInfoEntity {
private String HotelConfirmNo; // 酒店确认号 private String HotelConfirmNo; // 酒店确认号
private String JourneyNo; // 旅程编号 private String JourneyNo; // 旅程编号
private String CostCenter; // 成本中心 private String CostCenter; // 成本中心
private String Quantity; //夜间数量 private String RoomQuantity; //夜间数量
private String RoomDays; //夜间数量
private String Servicefee; private String Servicefee;
// 后续字段含义类似可根据实际情况添加注释 // 后续字段含义类似可根据实际情况添加注释
private List<ClientInfo> ClientInfo; // 客户信息列表 private List<ClientInfo> ClientInfo; // 客户信息列表

View File

@ -25,5 +25,16 @@ cTrip:
appSecurity: fI3}FZX+zUdxPa2W!R6I2gYO appSecurity: fI3}FZX+zUdxPa2W!R6I2gYO
requestSecret: zhengtai2024_nEbmKfOo requestSecret: zhengtai2024_nEbmKfOo
FSSC:
baseUrl: http://10.10.14.178:8080
paila:
client-id: 0053df85723db94491e8
client-secret: 7368bcec4c0f004c40585f6ed1087d887897
redirect-url: https://gxdev03.chint.com/businesstravel/
base-url: http://signin-test.chint.com
token-name: token
bpm: bpm:
H3BPMUrl: http://10.207.0.245:8012 H3BPMUrl: http://10.207.0.245:8012

View File

@ -20,3 +20,12 @@ cTrip:
appSecurity: fI3}FZX+zUdxPa2W!R6I2gYO appSecurity: fI3}FZX+zUdxPa2W!R6I2gYO
requestSecret: zhengtai2024_nEbmKfOo requestSecret: zhengtai2024_nEbmKfOo
FSSC:
baseUrl: http://10.10.14.178:8080
paila:
client-id: 0053df85723db94491e8
client-secret: 7368bcec4c0f004c40585f6ed1087d887897
redirect-url: https://gxdev03.chint.com/businesstravel/
base-url: http://signin-test.chint.com
token-name: token

View File

@ -39,5 +39,15 @@ cTrip:
appSecurity: fI3}FZX+zUdxPa2W!R6I2gYO appSecurity: fI3}FZX+zUdxPa2W!R6I2gYO
requestSecret: zhengtai2024_nEbmKfOo requestSecret: zhengtai2024_nEbmKfOo
FSSC:
baseUrl: http://10.10.14.178:8080
paila:
client-id: 0053df85723db94491e8
client-secret: 7368bcec4c0f004c40585f6ed1087d887897
redirect-url: https://gxdev03.chint.com/businesstravel/
base-url: http://signin-test.chint.com
token-name: token
bpm: bpm:
H3BPMUrl: http://10.207.0.245:8012 H3BPMUrl: http://10.207.0.245:8012

View File

@ -48,9 +48,9 @@ class RouteApplicationTests {
LocalDateTime parse = LocalDateTime.parse("2024-04-15 23:59:00", dateTimeFormatter); LocalDateTime parse = LocalDateTime.parse("2024-04-15 23:59:00", dateTimeFormatter);
System.out.println(parse); System.out.println(parse);
} }
// @Test @Test
void loginSign() { void loginSign() {
String sfno = "230615020"; String sfno = "170717012";
String syscode = "FSSC"; String syscode = "FSSC";
String billcode = "CLSQ240225000099"; String billcode = "CLSQ240225000099";
String companycode = "正泰集团股份有限公司"; String companycode = "正泰集团股份有限公司";