【update】高德差旅申请调用方法功能实现

This commit is contained in:
nixj 2024-04-26 13:31:17 +08:00
parent 0c5f571e27
commit 3b0bbc9b6b
11 changed files with 174 additions and 72 deletions

View File

@ -0,0 +1,19 @@
package com.chint.domain.aggregates.supplier;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.relational.core.mapping.MappedCollection;
import org.springframework.data.relational.core.mapping.Table;
import java.io.Serial;
import java.io.Serializable;
import java.util.List;
@Data
@Table("amap_route_relationship")
public class AmapRouteRelationship implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
private String applyRecordId;
private String outApplyRecordId;
}

View File

@ -1,9 +1,47 @@
package com.chint.domain.service.order_sync;
import com.chint.domain.aggregates.order.RouteOrder;
import com.chint.domain.aggregates.order.RouteRequest;
import com.chint.domain.aggregates.order.*;
import com.chint.domain.aggregates.supplier.AmapRouteRelationship;
import com.chint.domain.aggregates.user.User;
import com.chint.domain.repository.UserRepository;
import com.chint.domain.service.LegDomainService;
import com.chint.infrastructure.repository.jdbc.JdbcAmapRouteRelationshipRepository;
import com.chint.interfaces.rest.amap.AmapLocationRequest;
import com.chint.interfaces.rest.amap.dto.travelapplication.ProcessContent;
import com.chint.interfaces.rest.amap.dto.travelapplication.TravelApplicationDto;
import com.chint.interfaces.rest.amap.dto.travelapplication.TravelApplicationDtoResponse;
import com.chint.interfaces.rest.amap.request.TravelApplicationRequest;
import com.chint.interfaces.rest.ctrip.dto.approval.ApprovalRequest;
import com.google.gson.Gson;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import static com.chint.infrastructure.constant.LegConstant.LEG_TYPE_TAXI;
@Slf4j
@Component
public class AmapOrderSyncAdapter implements SupplierOrderSync{
@Autowired
private UserRepository userRepository;
@Autowired
private AmapLocationRequest amapLocationRequest;
@Autowired
private TravelApplicationRequest travelApplicationRequest;
@Autowired
private JdbcAmapRouteRelationshipRepository jdbcAmapRouteRelationshipRepository;
@Autowired
private LegDomainService legDomainService;
@Override
public boolean syncSupplierOrder(RouteOrder order) {
return false;
@ -11,8 +49,60 @@ public class AmapOrderSyncAdapter implements SupplierOrderSync{
@Override
public boolean syncRouteRequest(RouteRequest routeRequest) {
TravelApplicationDto dto=new TravelApplicationDto();
RouteRequestFields routeRequestFields = routeRequest.getRouteRequestFields();
TravelApplicationDto travelApplicationDto=generateTravelApplicationInfo(dto,routeRequest,routeRequestFields);
TravelApplicationDtoResponse response=travelApplicationRequest.apply(travelApplicationDto);
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);
}
private TravelApplicationDto generateTravelApplicationInfo(TravelApplicationDto dto, RouteRequest routeRequest,RouteRequestFields routeRequestFields) {
dto.setOutApplyRecordId(routeRequest.getRouteRequestNo());
//公司信息写入备注
dto.setRemark(routeRequestFields.getAccountCompanyName()+"-"
+routeRequestFields.getAccountCompanyCode()+"-"
+routeRequestFields.getProjectName()+"-"
+routeRequestFields.getCostCenter()+"-"
+routeRequestFields.getSysCode()+"-"
+routeRequestFields.getActualOrderNo());
dto.setApplyEUserId(routeRequestFields.getUserId());
User user=userRepository.findByUserEmployeeNo(routeRequestFields.getUserId());
dto.setApplyMobile(user.getPhoneNumber());
dto.setApplyName(user.getName());
//审批单
List<Leg> legList=routeRequest.getRouteRequestLegList().stream().map(RouteRequestLeg::getLeg).toList();
legList=legList.stream().filter(u->u.getLegType().equals(LEG_TYPE_TAXI)).toList();
dto.setTemplateCode("travel");
ProcessContent processContent=new ProcessContent();
processContent.setStartTime(legList.stream().sorted(Comparator.comparing(Leg::getStartTime)).toList().get(0).getStartTime().toString());
processContent.setEndTime(legList.stream().sorted(Comparator.comparing(Leg::getEndTime).reversed()).toList().get(0).getEndTime().toString());
//areacode处理
List<LegExtensionField> legExtensionFields=legDomainService.queryLocation(legList).stream().map(Leg::getLegExtensionField).toList();
List<Location> locationList=new ArrayList<>();
for (LegExtensionField leg:legExtensionFields){
locationList.addAll(leg.getLocationList());
}
List<String> areaCodes=new ArrayList<>();
for (Location location:locationList){
areaCodes.add(amapLocationRequest.getACodeByLocationName(location.getLocationName()));
}
processContent.setValidCityList(areaCodes);
processContent.setAmountLimited(1);
processContent.setAllowCrossCity(1);
dto.setProcessContent(processContent);
dto.setStatus(routeRequest.getStatus().toString());
return dto;
}
@Override
public boolean cancelSyncSupplierOrder(RouteOrder order) {
@ -21,6 +111,17 @@ public class AmapOrderSyncAdapter implements SupplierOrderSync{
@Override
public boolean cancelRouteRequest(RouteRequest routeRequest) {
TravelApplicationDto dto=new TravelApplicationDto();
RouteRequestFields routeRequestFields = routeRequest.getRouteRequestFields();
TravelApplicationDto travelApplicationDto=generateTravelApplicationInfo(dto,routeRequest,routeRequestFields);
//查询关联表
AmapRouteRelationship amapRouteRelationship=jdbcAmapRouteRelationshipRepository.findAmapRouteRelationshipByApplyRecordId(routeRequest.getRouteRequestNo());
if (amapRouteRelationship==null){
log.info("无企业订单信息",dto.getOutApplyRecordId());
return false;
}
travelApplicationDto.setApplyRecordId(amapRouteRelationship.getApplyRecordId());
TravelApplicationDtoResponse response=travelApplicationRequest.modify(travelApplicationDto);
return response.getCode().equals(1);
}
}

View File

@ -17,11 +17,14 @@ public class SyncAdapter {
@Autowired
private LYOrderSyncAdapter lyOrderSyncAdapter;
@Autowired
private AmapOrderSyncAdapter amapOrderSyncAdapter;
public SupplierOrderSync of(String supplierName) {
return switch (supplierName) {
case SUPPLIER_C_TRIP -> cTripOrderSyncAdapter;
case SUPPLIER_L_Y -> lyOrderSyncAdapter;
case SUPPLIER_AMAP -> lyOrderSyncAdapter;
case SUPPLIER_AMAP -> amapOrderSyncAdapter;
default -> throw new NotFoundException(CommonMessageConstant.NOT_FOUND);
};
}

View File

@ -0,0 +1,10 @@
package com.chint.infrastructure.repository.jdbc;
import com.chint.domain.aggregates.supplier.AmapRouteRelationship;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface JdbcAmapRouteRelationshipRepository extends CrudRepository<AmapRouteRelationship,Long> {
AmapRouteRelationship findAmapRouteRelationshipByApplyRecordId(String applyRecordId);
}

View File

@ -32,6 +32,6 @@ public class AmapLocationRequest {
LocationResponse locationQuery = locationQuery(locationName);
Optional<LocationResponse.AmapCityInfo> amapCityInfo = Optional.ofNullable(locationQuery.getData())
.flatMap(it -> Optional.ofNullable(it.get(0)));
return amapCityInfo.map(LocationResponse.AmapCityInfo::getName).orElse(null);
return amapCityInfo.map(LocationResponse.AmapCityInfo::getAdcode).orElse(null);
}
}

View File

@ -0,0 +1,14 @@
package com.chint.interfaces.rest.amap.dto.travelapplication;
import lombok.Data;
/**
* 同行人
* @Authornxj
* @Date2024/4/25 13:03
*/
@Data
public class Companions {
private String outApplyRecordId;
private String applyEUserId;
}

View File

@ -1,58 +0,0 @@
package com.chint.interfaces.rest.amap.dto.travelapplication;
import com.chint.interfaces.rest.amap.BaseRequestParam;
import lombok.Data;
/**
* 提交申请单
* @Authornxj
* @Date2024/4/24 16:44
*/
@Data
public class ModifyTravelApplicationDto extends BaseRequestParam {
/**
* 必填
*/
//企业审批ID
private String outApplyRecordId;
//高德审批ID
private String applyRecordId;
//审批模板Code travel
private String templateCode;
/**
* 非必填
*/
//申请人手机号
private String applyMobile;
//申请人姓名
private String applyName;
//部门ID
private String departmentId;
//部门名称
private String departmentName;
//申请单审批模板内容(JSON格式)
private ProcessContent processContent;
//审批状态 1有效 0无效
private String status;
//申请备注/原因(长度限制256字符)
private String remark;
//申请单场景入口展示名称长度限制64字符
private String sceneName;
//是否占用个人月度限额 0 1 默认为0
private String usePersonalAmount;
/**
* 支持的叫车业务类型
*(1 实时单2 预约单3 接送机5 接送站6 代叫车
*可传多个多个参数逗号分隔1,2
*不传默认为 实时单+预约单)
*/
private String orderServiceType;
//企业自定义申请单名称长度限制5字符申请单入口标签名称
private String customSceneLabel;
}

View File

@ -17,9 +17,9 @@ public class ProcessContent {
//权限开始时间(yyyy-MM-dd)
private String startTime;
//单笔限额 -1 表示不限制单位分
private String amountLimited;
private Integer amountLimited;
//0-不允许跨城 1-允许跨城 2-不允许跨城但部分临近城市可以跨城用车
private String allowCrossCity;
private Integer allowCrossCity;
/**

View File

@ -3,6 +3,8 @@ package com.chint.interfaces.rest.amap.dto.travelapplication;
import com.chint.interfaces.rest.amap.BaseRequestParam;
import lombok.Data;
import java.util.List;
/**
* 提交申请单
* @Authornxj
@ -29,6 +31,12 @@ public class TravelApplicationDto extends BaseRequestParam {
//审批状态 1有效 0无效
private String status;
/**
* 修改必填
*/
//高德审批ID
private String applyRecordId;
/**
@ -64,5 +72,5 @@ public class TravelApplicationDto extends BaseRequestParam {
//企业自定义申请单名称长度限制5字符申请单入口标签名称
private String customSceneLabel;
//同行人信息(具体字段见同行人信息)
private String companions;
private List<Companions> companions;
}

View File

@ -68,7 +68,7 @@ public class AmapRequest {
return request.getSend(url, params, responseType);
}
public <V> V post(String url, BaseRequestParam baseRequestParam, Class<V> responseType) {
public <V> V post(String url,BaseRequestParam baseRequestParam, Class<V> responseType) {
baseRequestParam.setAppId(appId);
baseRequestParam.setEid(eid);
baseRequestParam.setEnt(4);

View File

@ -1,16 +1,21 @@
package com.chint.interfaces.rest.amap.request;
import com.chint.interfaces.rest.amap.dto.travelapplication.ModifyTravelApplicationDto;
import com.chint.interfaces.rest.amap.dto.travelapplication.TravelApplicationDto;
import com.chint.interfaces.rest.amap.dto.travelapplication.TravelApplicationDtoResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
/**
* 差旅
* @Authornxj
* @Date2024/4/24 16:40
*/
@Component
public class TravelApplicationRequest {
@Value("${amap.baseUrl}")
private String baseUrl;
//创建差旅申请单
private final static String APPLY_RECORD_CREATE="/ws/boss/enterprise/openapi/apply/record/create";
@ -21,10 +26,10 @@ public class TravelApplicationRequest {
private AmapRequest amapRequest;
public TravelApplicationDtoResponse apply(TravelApplicationDto dto){
return amapRequest.post(APPLY_RECORD_CREATE,dto, TravelApplicationDtoResponse.class);
return amapRequest.post(baseUrl+APPLY_RECORD_CREATE,dto, TravelApplicationDtoResponse.class);
}
public TravelApplicationDtoResponse modify(ModifyTravelApplicationDto dto){
return amapRequest.post(APPLY_RECORD_UPDATE,dto, TravelApplicationDtoResponse.class);
public TravelApplicationDtoResponse modify(TravelApplicationDto dto){
return amapRequest.post(baseUrl+APPLY_RECORD_UPDATE,dto, TravelApplicationDtoResponse.class);
}
}