From 3b0bbc9b6b75e5bff2c6d24528e8085123f842db Mon Sep 17 00:00:00 2001 From: nixj Date: Fri, 26 Apr 2024 13:31:17 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90update=E3=80=91=E9=AB=98=E5=BE=B7?= =?UTF-8?q?=E5=B7=AE=E6=97=85=E7=94=B3=E8=AF=B7=E8=B0=83=E7=94=A8=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E5=8A=9F=E8=83=BD=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../supplier/AmapRouteRelationship.java | 19 +++ .../order_sync/AmapOrderSyncAdapter.java | 109 +++++++++++++++++- .../service/order_sync/SyncAdapter.java | 5 +- .../JdbcAmapRouteRelationshipRepository.java | 10 ++ .../rest/amap/AmapLocationRequest.java | 2 +- .../dto/travelapplication/Companions.java | 14 +++ .../ModifyTravelApplicationDto.java | 58 ---------- .../dto/travelapplication/ProcessContent.java | 4 +- .../TravelApplicationDto.java | 10 +- .../rest/amap/request/AmapRequest.java | 2 +- .../request/TravelApplicationRequest.java | 13 ++- 11 files changed, 174 insertions(+), 72 deletions(-) create mode 100644 src/main/java/com/chint/domain/aggregates/supplier/AmapRouteRelationship.java create mode 100644 src/main/java/com/chint/infrastructure/repository/jdbc/JdbcAmapRouteRelationshipRepository.java create mode 100644 src/main/java/com/chint/interfaces/rest/amap/dto/travelapplication/Companions.java delete mode 100644 src/main/java/com/chint/interfaces/rest/amap/dto/travelapplication/ModifyTravelApplicationDto.java diff --git a/src/main/java/com/chint/domain/aggregates/supplier/AmapRouteRelationship.java b/src/main/java/com/chint/domain/aggregates/supplier/AmapRouteRelationship.java new file mode 100644 index 00000000..8e16e49e --- /dev/null +++ b/src/main/java/com/chint/domain/aggregates/supplier/AmapRouteRelationship.java @@ -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; +} diff --git a/src/main/java/com/chint/domain/service/order_sync/AmapOrderSyncAdapter.java b/src/main/java/com/chint/domain/service/order_sync/AmapOrderSyncAdapter.java index 7db9e9c6..db1c0380 100644 --- a/src/main/java/com/chint/domain/service/order_sync/AmapOrderSyncAdapter.java +++ b/src/main/java/com/chint/domain/service/order_sync/AmapOrderSyncAdapter.java @@ -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,7 +49,59 @@ public class AmapOrderSyncAdapter implements SupplierOrderSync{ @Override public boolean syncRouteRequest(RouteRequest routeRequest) { - return false; + 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 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 legExtensionFields=legDomainService.queryLocation(legList).stream().map(Leg::getLegExtensionField).toList(); + List locationList=new ArrayList<>(); + for (LegExtensionField leg:legExtensionFields){ + locationList.addAll(leg.getLocationList()); + } + List 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 @@ -21,6 +111,17 @@ public class AmapOrderSyncAdapter implements SupplierOrderSync{ @Override public boolean cancelRouteRequest(RouteRequest routeRequest) { - return false; + 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); } } diff --git a/src/main/java/com/chint/domain/service/order_sync/SyncAdapter.java b/src/main/java/com/chint/domain/service/order_sync/SyncAdapter.java index 12ade713..acd94ae5 100644 --- a/src/main/java/com/chint/domain/service/order_sync/SyncAdapter.java +++ b/src/main/java/com/chint/domain/service/order_sync/SyncAdapter.java @@ -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); }; } diff --git a/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcAmapRouteRelationshipRepository.java b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcAmapRouteRelationshipRepository.java new file mode 100644 index 00000000..0055ba16 --- /dev/null +++ b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcAmapRouteRelationshipRepository.java @@ -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 findAmapRouteRelationshipByApplyRecordId(String applyRecordId); +} diff --git a/src/main/java/com/chint/interfaces/rest/amap/AmapLocationRequest.java b/src/main/java/com/chint/interfaces/rest/amap/AmapLocationRequest.java index eb1e40b1..83bb4ccb 100644 --- a/src/main/java/com/chint/interfaces/rest/amap/AmapLocationRequest.java +++ b/src/main/java/com/chint/interfaces/rest/amap/AmapLocationRequest.java @@ -32,6 +32,6 @@ public class AmapLocationRequest { LocationResponse locationQuery = locationQuery(locationName); Optional 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); } } diff --git a/src/main/java/com/chint/interfaces/rest/amap/dto/travelapplication/Companions.java b/src/main/java/com/chint/interfaces/rest/amap/dto/travelapplication/Companions.java new file mode 100644 index 00000000..ed3d30eb --- /dev/null +++ b/src/main/java/com/chint/interfaces/rest/amap/dto/travelapplication/Companions.java @@ -0,0 +1,14 @@ +package com.chint.interfaces.rest.amap.dto.travelapplication; + +import lombok.Data; + +/** + * 同行人 + * @Author:nxj + * @Date:2024/4/25 13:03 + */ +@Data +public class Companions { + private String outApplyRecordId; + private String applyEUserId; +} diff --git a/src/main/java/com/chint/interfaces/rest/amap/dto/travelapplication/ModifyTravelApplicationDto.java b/src/main/java/com/chint/interfaces/rest/amap/dto/travelapplication/ModifyTravelApplicationDto.java deleted file mode 100644 index bd4862fd..00000000 --- a/src/main/java/com/chint/interfaces/rest/amap/dto/travelapplication/ModifyTravelApplicationDto.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.chint.interfaces.rest.amap.dto.travelapplication; - -import com.chint.interfaces.rest.amap.BaseRequestParam; -import lombok.Data; - -/** - * 提交申请单 - * @Author:nxj - * @Date:2024/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; -} diff --git a/src/main/java/com/chint/interfaces/rest/amap/dto/travelapplication/ProcessContent.java b/src/main/java/com/chint/interfaces/rest/amap/dto/travelapplication/ProcessContent.java index 5fc0722e..91cf2b00 100644 --- a/src/main/java/com/chint/interfaces/rest/amap/dto/travelapplication/ProcessContent.java +++ b/src/main/java/com/chint/interfaces/rest/amap/dto/travelapplication/ProcessContent.java @@ -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; /** diff --git a/src/main/java/com/chint/interfaces/rest/amap/dto/travelapplication/TravelApplicationDto.java b/src/main/java/com/chint/interfaces/rest/amap/dto/travelapplication/TravelApplicationDto.java index 24e73f0d..9e0a35bc 100644 --- a/src/main/java/com/chint/interfaces/rest/amap/dto/travelapplication/TravelApplicationDto.java +++ b/src/main/java/com/chint/interfaces/rest/amap/dto/travelapplication/TravelApplicationDto.java @@ -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; + /** * 提交申请单 * @Author:nxj @@ -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; } diff --git a/src/main/java/com/chint/interfaces/rest/amap/request/AmapRequest.java b/src/main/java/com/chint/interfaces/rest/amap/request/AmapRequest.java index ff544bc5..4aa03b52 100644 --- a/src/main/java/com/chint/interfaces/rest/amap/request/AmapRequest.java +++ b/src/main/java/com/chint/interfaces/rest/amap/request/AmapRequest.java @@ -68,7 +68,7 @@ public class AmapRequest { return request.getSend(url, params, responseType); } - public V post(String url, BaseRequestParam baseRequestParam, Class responseType) { + public V post(String url,BaseRequestParam baseRequestParam, Class responseType) { baseRequestParam.setAppId(appId); baseRequestParam.setEid(eid); baseRequestParam.setEnt(4); diff --git a/src/main/java/com/chint/interfaces/rest/amap/request/TravelApplicationRequest.java b/src/main/java/com/chint/interfaces/rest/amap/request/TravelApplicationRequest.java index 08ff2d33..969912db 100644 --- a/src/main/java/com/chint/interfaces/rest/amap/request/TravelApplicationRequest.java +++ b/src/main/java/com/chint/interfaces/rest/amap/request/TravelApplicationRequest.java @@ -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; /** * 差旅 * @Author:nxj * @Date:2024/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); } }