完成高德差旅申请单同步和取消功能

This commit is contained in:
lulz1 2024-04-30 10:22:58 +08:00
parent 2ccf1e2158
commit cbcbda9153
7 changed files with 119 additions and 26 deletions

View File

@ -6,8 +6,6 @@ import com.chint.application.services.SupplierLoginService;
import com.chint.infrastructure.util.Result;
import com.chint.interfaces.rest.base.dto.H5LoginResponse;
import com.chint.interfaces.rest.base.dto.PCLoginResponse;
import com.chint.interfaces.rest.ctrip.dto.login.H5Response;
import com.chint.interfaces.rest.ctrip.dto.login.PCResponse;
import com.chint.interfaces.rest.ly.dto.login.LYRedirectUrlResponse;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
@ -66,4 +64,10 @@ public class SupplierLoginController {
return Result.Success(SUCCESS, supplierLoginService.cTripLoginPCHtml(supplierLoginParam));
}
@ApiOperation("单点登录高德-移动-Html")
@PostMapping("/Amap/login/ht")
public Result<H5LoginResponse> amapLoginHtml(@RequestBody SupplierLoginParam supplierLoginParam) {
return Result.Success(SUCCESS, supplierLoginService.amapLoginHtml(supplierLoginParam));
}
}

View File

@ -5,11 +5,10 @@ import com.chint.domain.aggregates.order.RouteOrder;
import com.chint.domain.aggregates.user.User;
import com.chint.domain.repository.RouteRepository;
import com.chint.infrastructure.util.BaseContext;
import com.chint.interfaces.rest.amap.AmapLoginRequest;
import com.chint.interfaces.rest.base.dto.H5LoginResponse;
import com.chint.interfaces.rest.base.dto.PCLoginResponse;
import com.chint.interfaces.rest.ctrip.CTripLoginRequest;
import com.chint.interfaces.rest.ctrip.dto.login.H5Response;
import com.chint.interfaces.rest.ctrip.dto.login.PCResponse;
import com.chint.interfaces.rest.ly.LYLoginRequest;
import com.chint.interfaces.rest.ly.dto.login.LYRedirectUrlResponse;
import org.springframework.beans.factory.annotation.Autowired;
@ -29,6 +28,9 @@ public class SupplierLoginService {
@Autowired
private RouteRepository routeRepository;
@Autowired
private AmapLoginRequest amapLoginRequest;
/**
* 登录接口
*/
@ -56,13 +58,17 @@ public class SupplierLoginService {
return cTripLoginRequest.authLoginHtml(getEmployeeNo(supplierLoginParam.getRouteId()));
}
public H5LoginResponse amapLoginHtml(SupplierLoginParam supplierLoginParam) {
return amapLoginRequest.h5LoginByEmployeeNo(getEmployeeNo(supplierLoginParam.getRouteId()));
}
private String getEmployeeNo(Long routeId) {
if (routeId != null) {
RouteOrder routeOrder = routeRepository.queryById(routeId);
return routeOrder.getUserId().toString();
return routeOrder.getUserId();
} else {
User currentUser = BaseContext.getCurrentUser();
return currentUser.getEmployeeNo().toString();
return currentUser.getEmployeeNo();
}
}
}

View File

@ -0,0 +1,13 @@
package com.chint.domain.repository;
import com.chint.domain.aggregates.supplier.AmapRouteRelationship;
import java.util.Optional;
public interface AmapRouteRelationshipRepository {
AmapRouteRelationship findAmapRouteRelationshipByApplyRecordId(String applyRecordId);
Optional<AmapRouteRelationship> findByOutApplyRecordId(String outApplyRecordId);
void removeByOutApplyRecordId(String outApplyRecordId);
AmapRouteRelationship save(AmapRouteRelationship routeRelationship);
}

View File

@ -3,9 +3,10 @@ package com.chint.domain.service.order_sync;
import com.chint.domain.aggregates.order.*;
import com.chint.domain.aggregates.supplier.AmapRouteRelationship;
import com.chint.domain.aggregates.user.User;
import com.chint.domain.exceptions.CommandException;
import com.chint.domain.repository.AmapRouteRelationshipRepository;
import com.chint.domain.repository.UserRepository;
import com.chint.domain.service.LegDomainService;
import com.chint.infrastructure.repository.jdbc.JdbcAmapRouteRelationshipRepository;
import com.chint.infrastructure.util.DateTimeUtil;
import com.chint.interfaces.rest.amap.AmapLocationRequest;
import com.chint.interfaces.rest.amap.dto.travelapplication.ProcessContent;
@ -21,6 +22,7 @@ import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import static com.chint.infrastructure.constant.LegConstant.LEG_TYPE_TAXI;
@ -38,7 +40,7 @@ public class AmapOrderSyncAdapter implements SupplierOrderSync {
private TravelApplicationRequest travelApplicationRequest;
@Autowired
private JdbcAmapRouteRelationshipRepository jdbcAmapRouteRelationshipRepository;
private AmapRouteRelationshipRepository amapRouteRelationshipRepository;
@Autowired
private LegDomainService legDomainService;
@ -55,17 +57,28 @@ public class AmapOrderSyncAdapter implements SupplierOrderSync {
TravelApplicationDto dto = new TravelApplicationDto();
RouteRequestFields routeRequestFields = routeRequest.getRouteRequestFields();
TravelApplicationDto travelApplicationDto = generateTravelApplicationInfo(dto, routeRequest, routeRequestFields);
TravelApplicationDtoResponse response = travelApplicationRequest.apply(travelApplicationDto);
Optional<AmapRouteRelationship> byOutApplyRecordId = amapRouteRelationshipRepository
.findByOutApplyRecordId(routeRequest.getRouteRequestNo());
TravelApplicationDtoResponse response;
if (byOutApplyRecordId.isPresent()) {
AmapRouteRelationship amapRouteRelationship = byOutApplyRecordId.get();
travelApplicationDto.setApplyRecordId(amapRouteRelationship.getApplyRecordId());
response = travelApplicationRequest.modify(travelApplicationDto);
} else {
response = travelApplicationRequest.apply(travelApplicationDto);
//存入关联表
AmapRouteRelationship amapRouteRelationship = new AmapRouteRelationship();
amapRouteRelationship.setApplyRecordId(response.getData());
amapRouteRelationship.setOutApplyRecordId(routeRequest.getRouteRequestNo());
amapRouteRelationshipRepository.save(amapRouteRelationship);
}
if (!response.getCode().equals(1)) {
Gson gson = new Gson();
log.error(gson.toJson(response));
return false;
}
//存入关联表
AmapRouteRelationship amapRouteRelationship = new AmapRouteRelationship();
amapRouteRelationship.setApplyRecordId(response.getData());
amapRouteRelationship.setOutApplyRecordId(routeRequest.getRouteRequestNo());
jdbcAmapRouteRelationshipRepository.save(amapRouteRelationship);
return response.getCode().equals(1);
}
@ -85,6 +98,11 @@ public class AmapOrderSyncAdapter implements SupplierOrderSync {
//审批单
List<Leg> legList = routeRequest.getRouteRequestLegList().stream().map(RouteRequestLeg::getLeg).toList();
legList = legList.stream().filter(u -> u.getLegType().equals(LEG_TYPE_TAXI)).toList();
if (legList.isEmpty()) {
throw new CommandException("差旅申请单不存在打车行程");
}
dto.setTemplateCode("travel");
ProcessContent processContent = new ProcessContent();
@ -132,13 +150,16 @@ public class AmapOrderSyncAdapter implements SupplierOrderSync {
TravelApplicationDto travelApplicationDto = generateTravelApplicationInfo(dto, routeRequest, routeRequestFields);
travelApplicationDto.setStatus("0");
//查询关联表
AmapRouteRelationship amapRouteRelationship = jdbcAmapRouteRelationshipRepository.findAmapRouteRelationshipByApplyRecordId(routeRequest.getRouteRequestNo());
if (amapRouteRelationship == null) {
log.info("无企业订单信息", dto.getOutApplyRecordId());
return false;
}
AmapRouteRelationship amapRouteRelationship = amapRouteRelationshipRepository
.findByOutApplyRecordId(routeRequest.getRouteRequestNo())
.orElseThrow(() -> new CommandException("请先创建差旅申请单再取消"));
String outApplyRecordId = amapRouteRelationship.getOutApplyRecordId();
travelApplicationDto.setApplyRecordId(amapRouteRelationship.getApplyRecordId());
TravelApplicationDtoResponse response = travelApplicationRequest.modify(travelApplicationDto);
return response.getCode().equals(1);
Integer code = response.getCode();
if(code.equals(1)){
amapRouteRelationshipRepository.removeByOutApplyRecordId(outApplyRecordId);
}
return code.equals(1);
}
}

View File

@ -0,0 +1,40 @@
package com.chint.infrastructure.repository;
import com.chint.domain.aggregates.supplier.AmapRouteRelationship;
import com.chint.domain.repository.AmapRouteRelationshipRepository;
import com.chint.infrastructure.repository.jdbc.JdbcAmapRouteRelationshipRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import java.util.Optional;
@Repository
public class AmapRouteRelationshipRepositoryImpl implements AmapRouteRelationshipRepository {
@Autowired
private JdbcAmapRouteRelationshipRepository jdbcAmapRouteRelationshipRepository;
@Override
public AmapRouteRelationship findAmapRouteRelationshipByApplyRecordId(String applyRecordId) {
return jdbcAmapRouteRelationshipRepository.findAmapRouteRelationshipByApplyRecordId(applyRecordId);
}
@Override
public Optional<AmapRouteRelationship> findByOutApplyRecordId(String outApplyRecordId) {
return jdbcAmapRouteRelationshipRepository.findByOutApplyRecordId(outApplyRecordId);
}
@Override
public void removeByOutApplyRecordId(String outApplyRecordId) {
findByOutApplyRecordId(outApplyRecordId)
.ifPresent(it->jdbcAmapRouteRelationshipRepository.delete(it));
}
@Override
public AmapRouteRelationship save(AmapRouteRelationship routeRelationship) {
return jdbcAmapRouteRelationshipRepository.save(routeRelationship);
}
}

View File

@ -4,7 +4,11 @@ import com.chint.domain.aggregates.supplier.AmapRouteRelationship;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import java.util.Optional;
@Repository
public interface JdbcAmapRouteRelationshipRepository extends CrudRepository<AmapRouteRelationship,Long> {
public interface JdbcAmapRouteRelationshipRepository extends CrudRepository<AmapRouteRelationship, Long> {
AmapRouteRelationship findAmapRouteRelationshipByApplyRecordId(String applyRecordId);
Optional<AmapRouteRelationship> findByOutApplyRecordId(String outApplyRecordId);
}

View File

@ -1,6 +1,7 @@
package com.chint.interfaces.rest.amap;
import com.chint.domain.aggregates.user.User;
import com.chint.domain.repository.UserRepository;
import com.chint.interfaces.rest.amap.dto.token.TokenResponse;
import com.chint.interfaces.rest.amap.request.AmapRequest;
import com.chint.interfaces.rest.amap.request.TokenRequest;
@ -9,10 +10,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import static com.chint.infrastructure.constant.AmapConstant.AMAP_LOGIN_PATH;
@Component
@ -24,6 +21,9 @@ public class AmapLoginRequest {
@Autowired
private AmapRequest amapRequest;
@Autowired
private UserRepository userRepository;
@Value("${amap.baseLoginUrl}")
private String baseLoginUrl;
@ -31,8 +31,13 @@ public class AmapLoginRequest {
public H5LoginResponse h5Login(User user) {
TokenResponse token = tokenRequest.getToken(user);
String tokenValue = token.getData().getToken();
String loginUrl = baseLoginUrl + AMAP_LOGIN_PATH;
String loginUrl = baseLoginUrl + AMAP_LOGIN_PATH + "?token=" + tokenValue;
return H5LoginResponse.Success(loginUrl).token(tokenValue);
}
public H5LoginResponse h5LoginByEmployeeNo(String employeeNo) {
User byUserEmployeeNo = userRepository.findByUserEmployeeNo(employeeNo);
return h5Login(byUserEmployeeNo);
}
}