备份route聚合自定义字段

This commit is contained in:
lulz1 2024-04-11 17:39:04 +08:00
parent 13b248c9a3
commit 00c81d4023
13 changed files with 127 additions and 71 deletions

View File

@ -1,6 +1,7 @@
package com.chint.application.commands;
import com.chint.domain.value_object.ApprovalSimpleData;
import com.chint.domain.value_object.ApproveRouteData;
import com.chint.infrastructure.echo_framework.command.Command;
import lombok.Data;
@ -10,7 +11,7 @@ import static com.chint.infrastructure.constant.LegConstant.LEG_EVENT_REJECT;
public class LegRejectCommand extends Command {
private final Integer legEventType = LEG_EVENT_REJECT;
private Long routeId;
private ApprovalSimpleData data;
private ApproveRouteData data;
private String sysCode;
private String actualOrderNo;
@ -19,7 +20,7 @@ public class LegRejectCommand extends Command {
return this;
}
public LegRejectCommand data(ApprovalSimpleData data) {
public LegRejectCommand data(ApproveRouteData data) {
this.data = data;
return this;
}

View File

@ -10,9 +10,9 @@ import static com.chint.infrastructure.constant.LegConstant.LEG_EVENT_APPROVAL;
@Data
public class OrderApprovalRecoverCommand extends Command {
private Integer LegEventType = LEG_EVENT_APPROVAL;
private ApprovalSimpleData data;
private ApproveRouteData data;
public OrderApprovalRecoverCommand data(ApprovalSimpleData data) {
public OrderApprovalRecoverCommand data(ApproveRouteData data) {
this.data = data;
return this;
}

View File

@ -1,6 +1,7 @@
package com.chint.application.commands;
import com.chint.domain.value_object.ApprovalSimpleData;
import com.chint.domain.value_object.ApproveRouteData;
import com.chint.infrastructure.echo_framework.command.Command;
import lombok.Data;
@ -10,7 +11,7 @@ import static com.chint.infrastructure.constant.RouteConstant.APPROVAL_EVENT_SUC
public class OrderApprovalSuccessCommand extends Command {
private String actualNo;
private String sysCode;
private ApprovalSimpleData data;
private ApproveRouteData data;
private Integer type = APPROVAL_EVENT_SUCCESS;
public OrderApprovalSuccessCommand actualNo(String actualNo) {
@ -23,7 +24,7 @@ public class OrderApprovalSuccessCommand extends Command {
return this;
}
public OrderApprovalSuccessCommand data(ApprovalSimpleData data) {
public OrderApprovalSuccessCommand data(ApproveRouteData data) {
this.data = data;
return this;
}

View File

@ -51,15 +51,15 @@ public class OrderPublicController {
@Transactional
@ApiOperation("审批拒绝行程规划单")
@PostMapping("/reject")
public Result<String> rejectOrder(@RequestBody ApprovalSimpleData approvalLegData) {
orderApplicationService.reject(approvalLegData);
public Result<String> rejectOrder(@RequestBody ApproveRouteData approveRouteData) {
orderApplicationService.reject(approveRouteData);
return Result.Success(SUCCESS);
}
@Transactional
@ApiOperation("回复未同步行程规划单")
@PostMapping("/recover")
public Result<String> recoverOrder(@RequestBody ApprovalSimpleData approvalLegData) {
public Result<String> recoverOrder(@RequestBody ApproveRouteData approvalLegData) {
orderApplicationService.recover(approvalLegData);
return Result.Success(SUCCESS);
}
@ -67,7 +67,7 @@ public class OrderPublicController {
@Transactional
@ApiOperation("审批通过行程规划单")
@PostMapping("/success")
public Result<String> approvalOrder(@RequestBody ApprovalSimpleData approvalLegData) {
public Result<String> approvalOrder(@RequestBody ApproveRouteData approvalLegData) {
orderApplicationService.approvalSuccess(approvalLegData);
return Result.Success(SUCCESS);
}

View File

@ -254,12 +254,12 @@ public class OrderApplicationService {
}
@Transactional
public void reject(ApprovalSimpleData data) {
public void reject(ApproveRouteData data) {
Command.of(LegRejectCommand.class).data(data).sendToQueue();
}
@Transactional
public void approvalSuccess(ApprovalSimpleData data) {
public void approvalSuccess(ApproveRouteData data) {
Command.of(OrderApprovalSuccessCommand.class).data(data).sendToQueue();
}
@ -278,7 +278,7 @@ public class OrderApplicationService {
}
@Transactional
public void recover(ApprovalSimpleData data) {
public void recover(ApproveRouteData data) {
Command.of(OrderApprovalRecoverCommand.class).data(data).sendToQueue();
}

View File

@ -0,0 +1,23 @@
package com.chint.domain.aggregates.order;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.relational.core.mapping.Column;
import org.springframework.data.relational.core.mapping.Table;
import java.io.Serial;
import java.io.Serializable;
@Data
@Table("route_custom_extension_field")
public class RouteCustomExtensionField implements Serializable {
@Serial
private static final long serialVersionUID = 9027294639272719570L;
@Id
private Long id;
@Column("route_id")
private Long routeId;
private Long routeOrderKey;
private String fieldName;
private String fieldValue;
}

View File

@ -6,11 +6,11 @@ import com.chint.domain.factoriy.leg.LegFactory;
import com.chint.domain.service.OrderDomainService;
import com.chint.domain.service.amount_estimate.EstimateAdapter;
import com.chint.domain.service.supplier.SupplierConstantUtil;
import com.chint.domain.value_object.ApproveRouteData;
import com.chint.domain.value_object.LegData;
import com.chint.domain.value_object.OrderSaveData;
import com.chint.infrastructure.constant.LegConstant;
import com.chint.infrastructure.constant.RouteConstant;
import com.chint.infrastructure.constant.SupplierNameConstant;
import com.chint.infrastructure.echo_framework.command.Command;
import com.chint.infrastructure.echo_framework.dispatch.Properties;
import com.chint.infrastructure.echo_framework.dispatch.ResultContainer;
@ -27,6 +27,7 @@ import org.springframework.data.relational.core.mapping.Table;
import java.io.Serial;
import java.io.Serializable;
import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
@ -36,6 +37,7 @@ import static com.chint.infrastructure.constant.LegConstant.LEG_TYPE_TRAIN;
import static com.chint.infrastructure.constant.RouteConstant.*;
import static com.chint.infrastructure.constant.UtilConstant.KEEP_TWO_DECIMAL_ZERO;
import static com.chint.infrastructure.constant.UtilConstant.RESULT_ORDER_DETAIL;
import static com.chint.infrastructure.util.DateTimeUtil.formatterDate;
@Data
@Table("route_order")
@ -79,9 +81,14 @@ public class RouteOrder implements Serializable {
@Transient
private String supplierCNName;
//共有的扩展字段
@MappedCollection(idColumn = "route_id")
private RouterOrderExtensionField routerOrderExtensionField;
//自定义的扩展字段 用于适配个个产业公司的自定义字段
@MappedCollection(idColumn = "route_id", keyColumn = "route_order_key")
private List<RouteCustomExtensionField> routeCustomExtensionFieldList;
@MappedCollection(idColumn = "route_id", keyColumn = "route_order_key")
private List<Leg> legItems;
@ -118,22 +125,58 @@ public class RouteOrder implements Serializable {
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
public LocalDateTime updateTime;
// public void addItemAtPosition(Leg newItem) {
// Integer position = newItem.getSequence();
// if (position == null) {
// position = this.legItems.size() + 1;
// newItem.setSequence(position);
// }
// if (position < 0 || position > this.legItems.size() + 1) {
// throw new IllegalArgumentException(PARAM_ERROR);
// }
// Integer streamPosition = position;
// this.legItems.stream()
// .filter(item -> item.getSequence() >= streamPosition)
// .forEach(item -> item.setSequence(item.getSequence() + 1));
// newItem.setRouteId(this.getRouteId());
// newItem.reloadStatus();
// }
public RouteOrder updateApprovalData(ApproveRouteData data) {
//保存提交审批所提供的资料
ApproveOrderNo approveOrderNo = this.getApproveOrderNo();
if (data.getActualOrderNo() != null) {
approveOrderNo.setActualOrderNo(data.getActualOrderNo());
}
if (data.getInstructions() != null) {
approveOrderNo.setInstructions(data.getInstructions());
}
if (data.getCreator() != null) {
approveOrderNo.setCreator(data.getCreator());
}
if (data.getAccountCompany() != null) {
approveOrderNo.setAccountCompanyName(data.getAccountCompany());
}
if (data.getAccountCompanyCode() != null) {
approveOrderNo.setAccountCompanyCode(data.getAccountCompanyCode());
}
if (data.getProjectName() != null) {
approveOrderNo.setProjectName(data.getProjectName());
}
if (data.getCostCenter() != null) {
approveOrderNo.setCostCenter(data.getCostCenter());
}
RouterOrderExtensionField orderExtensionField = this.getRouterOrderExtensionField();
if (orderExtensionField == null) {
orderExtensionField = new RouterOrderExtensionField();
}
if (data.getBelongDeptCode() != null) {
orderExtensionField.setBelongDeptCode(data.getBelongDeptCode());
}
parseAndSetTime(data.getStartTime(), true);
parseAndSetTime(data.getEndTime(), false);
return this;
}
private void parseAndSetTime(String timeString, boolean isStartTime) {
if (timeString != null) {
LocalDate date = timeString.contains("T") ?
LocalDate.parse(timeString.substring(0, 10), formatterDate) :
LocalDate.parse(timeString, formatterDate);
if (isStartTime) {
this.setStartTime(date.atStartOfDay());
} else {
this.setEndTime(date.atStartOfDay().plusHours(23).plusMinutes(59).plusSeconds(59));
}
}
}
public List<Leg> legOrdered() {
return this.legItems.stream()

View File

@ -184,7 +184,7 @@ public class OrderDomainService {
@ListenTo(command = "OrderApprovalSuccessCommand", order = 0)
public void approvalOrder(OrderApprovalSuccessCommand command) {
ApprovalSimpleData data = command.getData();
ApproveRouteData data = command.getData();
Optional.ofNullable(routeRepository.findByActualOrderNoAndSysCode(data.getActualOrderNo(), data.getSysCode()))
.ifPresent(route -> {
ApprovalEvent approvalEvent = routeOrderFactory.createApprovalEvent(command.getType());
@ -195,18 +195,11 @@ public class OrderDomainService {
@ListenTo(command = "OrderApprovalRecoverCommand", order = 0)
public void routeRecover(OrderApprovalRecoverCommand command) {
ApprovalSimpleData data = command.getData();
ApproveRouteData data = command.getData();
Optional.ofNullable(routeRepository.findByActualOrderNoAndSysCode(data.getActualOrderNo(), data.getSysCode()))
.ifPresentOrElse(route -> {
//保存提交审批所提供的资料
ApproveOrderNo approveOrderNo = route.getApproveOrderNo();
approveOrderNo.setActualOrderNo(data.getActualOrderNo());
approveOrderNo.setInstructions(data.getInstructions());
approveOrderNo.setCreator(data.getCreator());
approveOrderNo.setAccountCompanyName(data.getAccountCompany());
approveOrderNo.setAccountCompanyCode(data.getAccountCompanyCode());
approveOrderNo.setProjectName(data.getProjectName());
approveOrderNo.setCostCenter(data.getCostCenter());
route.updateApprovalData(data);
LegEvent legEvent = legEventFactory.creatLegEvent(command.getLegEventType());
route.getLegItems().forEach(leg -> leg.addEvent(legEvent));
@ -215,8 +208,8 @@ public class OrderDomainService {
this.saveOrder(route);
}, () -> {
//如果没有找到该订单说明该订单可能是未提交的状态 这里执行和审批提交一样的操作
ApprovalSimpleData approvalSimpleData = command.getData();
Command.of(OrderApprovalStartCommand.class).data(BeanUtil.copyProperties(approvalSimpleData, ApproveRouteData.class)).sendToQueue();
ApproveRouteData approveRouteData = command.getData();
Command.of(OrderApprovalStartCommand.class).data(BeanUtil.copyProperties(approveRouteData, ApproveRouteData.class)).sendToQueue();
});
}

View File

@ -118,14 +118,8 @@ public class LegEventHandler implements LegEventService {
throw new OrderException(CommonMessageConstant.LEG_ERROR);
}
//保存提交审批所提供的资料
ApproveOrderNo approveOrderNo = routeOrder.getApproveOrderNo();
approveOrderNo.setActualOrderNo(data.getActualOrderNo());
approveOrderNo.setInstructions(data.getInstructions());
approveOrderNo.setCreator(data.getCreator());
approveOrderNo.setAccountCompanyName(data.getAccountCompany());
approveOrderNo.setAccountCompanyCode(data.getAccountCompanyCode());
approveOrderNo.setProjectName(data.getProjectName());
approveOrderNo.setCostCenter(data.getCostCenter());
routeOrder.updateApprovalData(data);
//这里order所有的leg触发approve事件
routeOrder.getLegItems().forEach(leg -> leg.getEventList().add(
legEventFactory.creatLegEvent(command.getLegEventType())
@ -135,10 +129,6 @@ public class LegEventHandler implements LegEventService {
ApprovalEvent approvalEvent = routeOrderFactory.createApprovalEvent(RouteConstant.APPROVAL_EVENT_ING);
routeOrder.addApprovalEvent(approvalEvent);
//根据项目需求当传入的时间 使用该时间保存到订单当中
String startTime = data.getStartTime();
String endTime = data.getEndTime();
//当sysCode为H3BPM的时候 实用单号更新行程规划单的单号
if (data.getSysCode().equals(H3_BPM)) {
String generate = OrderNo.generate(H3_BPM, data.getActualOrderNo());
@ -149,16 +139,6 @@ public class LegEventHandler implements LegEventService {
}
}
if (startTime != null && endTime != null) {
if (startTime.contains("T") && endTime.contains("T")) {
//如果包含T就截取时间信息前10位
routeOrder.setStartTime(LocalDate.parse(startTime.substring(0, 10), formatter).atStartOfDay());
routeOrder.setEndTime(LocalDate.parse(endTime.substring(0, 10), formatter).atStartOfDay().plusHours(23).plusMinutes(59).plusSeconds(59));
} else {
routeOrder.setStartTime(LocalDate.parse(startTime, formatter).atStartOfDay());
routeOrder.setEndTime(LocalDate.parse(endTime, formatter).atStartOfDay().plusHours(23).plusMinutes(59).plusSeconds(59));
}
}
//保存routeOrder的状态
RouteOrder save = routeRepository.save(routeOrder);
command.order(save);

View File

@ -182,7 +182,6 @@ public class CTripOrderSyncAdapter implements SupplierOrderSync {
private List<TrainEndorsementDetail> generateTrainList(List<Leg> legs, String employeeNo) {
List<TrainEndorsementDetail> trainList = new ArrayList<>();
legs.forEach(leg -> {
trainList.add(
TrainEndorsementDetail.of(List.of(
getCityId(locationDomainService.queryCityLocation(leg.getOriginLocation())).getCityId().toString()

View File

@ -5,6 +5,8 @@ import lombok.Data;
@Data
public class ApprovalSimpleData {
@ApiModelProperty("费用归属部门")
private String belongDeptCode;
@ApiModelProperty("实际财务共享订单号")
private String actualOrderNo;
@ApiModelProperty("临时财务共享订单号")
@ -28,3 +30,5 @@ public class ApprovalSimpleData {
@ApiModelProperty("结束时间")
private String endTime;
}

View File

@ -3,8 +3,12 @@ package com.chint.domain.value_object;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
@Data
public class ApproveRouteData {
@ApiModelProperty("费用归属部门")
private String belongDeptCode;
@ApiModelProperty("实际财务共享订单号")
private String actualOrderNo;
@ApiModelProperty("临时财务共享订单号")
@ -27,4 +31,13 @@ public class ApproveRouteData {
private String startTime;
@ApiModelProperty("结束时间")
private String endTime;
@ApiModelProperty("结束时间")
private List<ApproveCustomField> approveCustomFieldList;
@Data
private static class ApproveCustomField{
private String fieldName;
private String fieldValue;
}
}

View File

@ -9,12 +9,11 @@ import java.time.format.DateTimeFormatter;
public class DateTimeUtil {
private final static DateTimeFormatter formatterMM = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");
private final static DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
private final static DateTimeFormatter formatterDate = DateTimeFormatter.ofPattern("yyyy-MM-dd");
private final static DateTimeFormatter formatterDateYYYYMM = DateTimeFormatter.ofPattern("yyyyMM");
private final static DateTimeFormatter formatterDateYYYYMMDD = DateTimeFormatter.ofPattern("yyyyMMdd");
public final static DateTimeFormatter formatterMM = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");
public final static DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
public final static DateTimeFormatter formatterDate = DateTimeFormatter.ofPattern("yyyy-MM-dd");
public final static DateTimeFormatter formatterDateYYYYMM = DateTimeFormatter.ofPattern("yyyyMM");
public final static DateTimeFormatter formatterDateYYYYMMDD = DateTimeFormatter.ofPattern("yyyyMMdd");
public static String timeFromInstant(Long instant) {
LocalDateTime localDateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(instant), ZoneId.systemDefault());