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); } }