增加供应商供应商品的配置模块和取消规则配置功能

This commit is contained in:
lulz1 2024-04-12 17:32:27 +08:00
parent bf394ab564
commit 0183df184b
15 changed files with 287 additions and 31 deletions

View File

@ -115,6 +115,18 @@ public class OrderOutController {
return Result.Success(SUCCESS, orderQuery.queryNotSubmit(queryData)); return Result.Success(SUCCESS, orderQuery.queryNotSubmit(queryData));
} }
@ApiOperation("查询行程规划订单自定义字段")
@PostMapping("/query/custom/fields")
public Result<List<ApproveCustomField>> queryLeg(@RequestBody OrderQueryData queryData) {
RouteOrder routeOrder = routeRepository
.findByActualOrderNoAndSysCode(queryData.getActualOrderNo(), queryData.getSysCode());
List<ApproveCustomField> approveCustomFieldList = routeOrder.getRouteCustomExtensionFieldList()
.stream()
.map(ApproveCustomField::of)
.toList();
return Result.Success(SUCCESS, approveCustomFieldList);
}
@ApiOperation("查询能够同步的行程节点") @ApiOperation("查询能够同步的行程节点")
@PostMapping("/query/legs") @PostMapping("/query/legs")
@ -123,7 +135,7 @@ public class OrderOutController {
List<LegRes> legResList = legDomainService List<LegRes> legResList = legDomainService
.queryLegsCanSync(routeOrder, queryData.getSupplierName()).stream().map(LegRes::copyFrom).toList(); .queryLegsCanSync(routeOrder, queryData.getSupplierName()).stream().map(LegRes::copyFrom).toList();
legResList.forEach(it -> it.setUserName(userRepository.findByUserEmployeeNo(routeOrder.getUserId()).getName())); legResList.forEach(it -> it.setUserName(userRepository.findByUserEmployeeNo(routeOrder.getUserId()).getName()));
legDomainService.getSupplierName(legResList,routeOrder); legDomainService.getSupplierName(legResList, routeOrder);
return Result.Success(SUCCESS, legResList); return Result.Success(SUCCESS, legResList);
} }

View File

@ -20,4 +20,15 @@ public class RouteCustomExtensionField implements Serializable {
private Long routeOrderKey; private Long routeOrderKey;
private String fieldName; private String fieldName;
private String fieldValue; private String fieldValue;
private String extension;
private RouteCustomExtensionField(String fieldName, String fieldValue, String extension) {
this.fieldName = fieldName;
this.fieldValue = fieldValue;
this.extension = extension;
}
public static RouteCustomExtensionField of(String fieldName, String fieldValue, String extension) {
return new RouteCustomExtensionField(fieldName, fieldValue, extension);
}
} }

View File

@ -6,6 +6,7 @@ import com.chint.domain.factoriy.leg.LegFactory;
import com.chint.domain.service.OrderDomainService; import com.chint.domain.service.OrderDomainService;
import com.chint.domain.service.amount_estimate.EstimateAdapter; import com.chint.domain.service.amount_estimate.EstimateAdapter;
import com.chint.domain.service.supplier.SupplierConstantUtil; import com.chint.domain.service.supplier.SupplierConstantUtil;
import com.chint.domain.value_object.ApproveCustomField;
import com.chint.domain.value_object.ApproveRouteData; import com.chint.domain.value_object.ApproveRouteData;
import com.chint.domain.value_object.LegData; import com.chint.domain.value_object.LegData;
import com.chint.domain.value_object.OrderSaveData; import com.chint.domain.value_object.OrderSaveData;
@ -162,6 +163,22 @@ public class RouteOrder implements Serializable {
parseAndSetTime(data.getStartTime(), true); parseAndSetTime(data.getStartTime(), true);
parseAndSetTime(data.getEndTime(), false); parseAndSetTime(data.getEndTime(), false);
List<ApproveCustomField> approveCustomFieldList = data.getApproveCustomFieldList();
if (approveCustomFieldList != null && !approveCustomFieldList.isEmpty()) {
if (this.getRouteCustomExtensionFieldList() == null) {
this.routeCustomExtensionFieldList = new ArrayList<>();
}
for (ApproveCustomField approveCustomField : approveCustomFieldList) {
String fieldName = approveCustomField.getFieldName();
String fieldValue = approveCustomField.getFieldValue();
Optional<RouteCustomExtensionField> first = this.routeCustomExtensionFieldList
.stream()
.filter(it -> it.getFieldName().equals(fieldName))
.findFirst();
first.ifPresentOrElse(it -> it.setFieldValue(fieldValue),
() -> this.routeCustomExtensionFieldList.add(RouteCustomExtensionField.of(fieldName, fieldValue, null)));
}
}
return this; return this;
} }

View File

@ -0,0 +1,23 @@
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("supplier")
public class Supplier implements Serializable {
@Serial
private static final long serialVersionUID = 987635285619453614L;
@Id
private Long id;
private String name;
private String cnName;
@MappedCollection(idColumn = "supplier_id", keyColumn = "supplier_key")
private List<SupplierProduct> supplierProductList;
}

View File

@ -0,0 +1,23 @@
package com.chint.domain.aggregates.supplier;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.relational.core.mapping.Table;
import java.io.Serial;
import java.io.Serializable;
@Data
@Table("supplier_product")
public class SupplierProduct implements Serializable {
@Serial
private static final long serialVersionUID = 1296764923629924614L;
@Id
private Long id;
private Long supplierId;
private Long supplierKey;
private Integer productType;
private Integer ifCanOrder;
private String ifCanCancelRule;
}

View File

@ -0,0 +1,11 @@
package com.chint.domain.repository;
import com.chint.domain.aggregates.supplier.Supplier;
import java.util.Optional;
public interface SupplierRepository {
Supplier save(Supplier supplier);
Optional<Supplier> findById(Long id);
Optional<Supplier> findBySupplierName(String supplierName);
}

View File

@ -2,17 +2,17 @@ package com.chint.domain.service;
import com.chint.application.dtos.response.LegRes; import com.chint.application.dtos.response.LegRes;
import com.chint.domain.aggregates.order.*; import com.chint.domain.aggregates.order.*;
import com.chint.domain.aggregates.supplier.Supplier;
import com.chint.domain.aggregates.supplier.SupplierProduct;
import com.chint.domain.exceptions.LegEventException; import com.chint.domain.exceptions.LegEventException;
import com.chint.domain.factoriy.leg_event.LegEventFactory; import com.chint.domain.factoriy.leg_event.LegEventFactory;
import com.chint.domain.repository.LegRepository; import com.chint.domain.repository.*;
import com.chint.domain.repository.LocationRepository;
import com.chint.domain.repository.OrderDetailRepository;
import com.chint.domain.repository.RouteRepository;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Optional;
import static com.chint.infrastructure.constant.CommonMessageConstant.LEG_CHANGE_MAX_ERROR; import static com.chint.infrastructure.constant.CommonMessageConstant.LEG_CHANGE_MAX_ERROR;
import static com.chint.infrastructure.constant.LegConstant.*; import static com.chint.infrastructure.constant.LegConstant.*;
@ -41,6 +41,13 @@ public class LegDomainService {
@Autowired @Autowired
private OrderDomainService orderDomainService; private OrderDomainService orderDomainService;
@Autowired
private SupplierRepository supplierRepository;
@Autowired
private SupplierDomainService supplierDomainService;
public Leg legCheckOrder(Leg leg) { public Leg legCheckOrder(Leg leg) {
List<OrderDetail> orderDetailList = orderDetailRepository.findByLegId(leg.getLegId()); List<OrderDetail> orderDetailList = orderDetailRepository.findByLegId(leg.getLegId());
orderDetailList.forEach(OrderDetail::reloadStatus); orderDetailList.forEach(OrderDetail::reloadStatus);
@ -161,9 +168,8 @@ public class LegDomainService {
List<Leg> legItems = routeOrder.getLegItems(); List<Leg> legItems = routeOrder.getLegItems();
legItems = legItems.stream().filter(it -> !it.getLegType().equals(LEG_TYPE_OTHER)).toList(); legItems = legItems.stream().filter(it -> !it.getLegType().equals(LEG_TYPE_OTHER)).toList();
// if (supplierName.equals("CTrip")) { //通过查看供应商的商品类型来进行同步
// legItems = legItems.stream().filter(it -> !it.getLegType().equals(LEG_TYPE_TRAIN)).toList(); legItems = supplierDomainService.ifCanSync(legItems, supplierName);
// }
List<Long> alreadySyncLegs = routeOrder.getRouteRequestList() List<Long> alreadySyncLegs = routeOrder.getRouteRequestList()
.stream() .stream()

View File

@ -1,12 +1,15 @@
package com.chint.domain.service; package com.chint.domain.service;
import com.chint.domain.aggregates.order.*; import com.chint.domain.aggregates.order.*;
import com.chint.domain.aggregates.supplier.Supplier;
import com.chint.domain.aggregates.supplier.SupplierProduct;
import com.chint.domain.exceptions.CommandException; import com.chint.domain.exceptions.CommandException;
import com.chint.domain.factoriy.leg_event.LegEventFactory; import com.chint.domain.factoriy.leg_event.LegEventFactory;
import com.chint.domain.factoriy.order.RouteOrderFactory; import com.chint.domain.factoriy.order.RouteOrderFactory;
import com.chint.domain.repository.LegRepository; import com.chint.domain.repository.LegRepository;
import com.chint.domain.repository.RouteRepository; import com.chint.domain.repository.RouteRepository;
import com.chint.domain.repository.RouteRequestRepository; import com.chint.domain.repository.RouteRequestRepository;
import com.chint.domain.repository.SupplierRepository;
import com.chint.domain.service.order_sync.SyncAdapter; import com.chint.domain.service.order_sync.SyncAdapter;
import com.chint.domain.value_object.SyncLegData; import com.chint.domain.value_object.SyncLegData;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -44,6 +47,12 @@ public class RouteRequestDomainService {
@Autowired @Autowired
private LegEventFactory legEventFactory; private LegEventFactory legEventFactory;
@Autowired
private SupplierRepository supplierRepository;
@Autowired
private SupplierDomainService supplierDomainService;
// //这里增加一个判断 如果这个订单的行程为空那么就返回给用户提示 // //这里增加一个判断 如果这个订单的行程为空那么就返回给用户提示
// if (legItems == null || legItems.isEmpty()) { // if (legItems == null || legItems.isEmpty()) {
@ -98,6 +107,7 @@ public class RouteRequestDomainService {
return routeRequest; return routeRequest;
} }
public void cancelRouteRequest(SyncLegData syncLegData) { public void cancelRouteRequest(SyncLegData syncLegData) {
Long routeId = syncLegData.getRouteId(); Long routeId = syncLegData.getRouteId();
RouteOrder routeOrder = routeRepository.queryById(routeId); RouteOrder routeOrder = routeRepository.queryById(routeId);
@ -123,19 +133,18 @@ public class RouteRequestDomainService {
.map(RouteRequestLeg::getLeg) .map(RouteRequestLeg::getLeg)
.toList(); .toList();
Map<Boolean, List<Leg>> collect = legs Optional<Supplier> supplierOptional = supplierRepository.findBySupplierName(it.getSupplier());
Map<Boolean, List<Leg>> collect;
if (supplierOptional.isPresent()) {
collect = legs
.stream() .stream()
.collect(Collectors.partitioningBy(leg -> { .collect(Collectors.partitioningBy(leg -> supplierDomainService.ifCanCancel(leg,it.getSupplier())));
Integer legStatus = leg.reloadStatus().getLegStatus(); List<Leg> orderedLegs = collect.get(false);
return (legStatus.equals(LEG_STATUS_ORDERED) || legStatus.equals(LEG_STATUS_PAYED) || legStatus.equals(LEG_STATUS_FINISH))
&& leg.getLegType().equals(LEG_TYPE_AIRPLANE);
}));
List<Leg> orderedLegs = collect.get(true);
if (!orderedLegs.isEmpty()) { if (!orderedLegs.isEmpty()) {
it.reloadGenerateRequestLegs(orderedLegs); it.reloadGenerateRequestLegs(orderedLegs);
syncAdapter.of(it.getSupplier()).syncRouteRequest(it); syncAdapter.of(it.getSupplier()).syncRouteRequest(it);
it.addEvent(RouteRequestEvent.sync(it.getSupplier())); it.addEvent(RouteRequestEvent.sync(it.getSupplier()));
List<Leg> notOrderLegs = collect.get(false); List<Leg> notOrderLegs = collect.get(true);
notOrderLegs.forEach(leg -> leg.addEvent(legEventFactory.creatLegEvent(LEG_EVENT_APPROVAL))); notOrderLegs.forEach(leg -> leg.addEvent(legEventFactory.creatLegEvent(LEG_EVENT_APPROVAL)));
} else { } else {
it.addEvent(RouteRequestEvent.cancel(it.getSupplier())); it.addEvent(RouteRequestEvent.cancel(it.getSupplier()));
@ -144,6 +153,36 @@ public class RouteRequestDomainService {
it.getRouteRequestLegList() it.getRouteRequestLegList()
.forEach(requestLeg -> requestLeg.getLeg().addEvent(legEventFactory.creatLegEvent(LEG_EVENT_APPROVAL))); .forEach(requestLeg -> requestLeg.getLeg().addEvent(legEventFactory.creatLegEvent(LEG_EVENT_APPROVAL)));
} }
} else {
it.addEvent(RouteRequestEvent.cancel(it.getSupplier()));
getLegInfoFromRouteOrder(it, routeOrder);
syncAdapter.of(it.getSupplier()).cancelRouteRequest(it);
it.getRouteRequestLegList()
.forEach(requestLeg -> requestLeg.getLeg().addEvent(legEventFactory.creatLegEvent(LEG_EVENT_APPROVAL)));
}
// Map<Boolean, List<Leg>> collect = legs
// .stream()
// .collect(Collectors.partitioningBy(leg -> {
// Integer legStatus = leg.reloadStatus().getLegStatus();
// return (legStatus.equals(LEG_STATUS_ORDERED) || legStatus.equals(LEG_STATUS_PAYED) || legStatus.equals(LEG_STATUS_FINISH))
// && leg.getLegType().equals(LEG_TYPE_AIRPLANE);
// }));
// List<Leg> orderedLegs = collect.get(true);
// if (!orderedLegs.isEmpty()) {
// it.reloadGenerateRequestLegs(orderedLegs);
// syncAdapter.of(it.getSupplier()).syncRouteRequest(it);
// it.addEvent(RouteRequestEvent.sync(it.getSupplier()));
// List<Leg> notOrderLegs = collect.get(false);
// notOrderLegs.forEach(leg -> leg.addEvent(legEventFactory.creatLegEvent(LEG_EVENT_APPROVAL)));
// } else {
// it.addEvent(RouteRequestEvent.cancel(it.getSupplier()));
// getLegInfoFromRouteOrder(it, routeOrder);
// syncAdapter.of(it.getSupplier()).cancelRouteRequest(it);
// it.getRouteRequestLegList()
// .forEach(requestLeg -> requestLeg.getLeg().addEvent(legEventFactory.creatLegEvent(LEG_EVENT_APPROVAL)));
// }
}); });
routeRepository.save(routeOrder); routeRepository.save(routeOrder);
} }
@ -164,7 +203,6 @@ public class RouteRequestDomainService {
return optionalRouteRequest return optionalRouteRequest
.orElseGet(() -> routeOrderFactory.createRequestWithLeg(routeOrder, legIds, supplier)).reloadStatus(); .orElseGet(() -> routeOrderFactory.createRequestWithLeg(routeOrder, legIds, supplier)).reloadStatus();
} }
} }
//获取目前已经同步到供应商的差旅申请单 //获取目前已经同步到供应商的差旅申请单

View File

@ -0,0 +1,54 @@
package com.chint.domain.service;
import com.chint.domain.aggregates.order.Leg;
import com.chint.domain.aggregates.supplier.Supplier;
import com.chint.domain.aggregates.supplier.SupplierProduct;
import com.chint.domain.repository.SupplierRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Optional;
@Service
public class SupplierDomainService {
@Autowired
private SupplierRepository supplierRepository;
public boolean ifCanCancel(Leg leg, String supplierName) {
Optional<Supplier> supplierOptional = supplierRepository.findBySupplierName(supplierName);
if (supplierOptional.isPresent()) {
Supplier supplier = supplierOptional.get();
List<SupplierProduct> supplierProductList = supplier.getSupplierProductList();
for (SupplierProduct product : supplierProductList) {
if (product.getProductType().equals(leg.getLegType())) {
String ifCanCancelRule = product.getIfCanCancelRule();
String[] split = ifCanCancelRule.split(",");
for (String status : split) {
if (status.equals(String.valueOf(leg.getLegStatus()))) {
return true;
}
}
}
}
}
return false;
}
public List<Leg> ifCanSync(List<Leg> legs, String supplierName) {
Optional<Supplier> supplierOptional = supplierRepository.findBySupplierName(supplierName);
if (supplierOptional.isPresent()) {
Supplier supplier = supplierOptional.get();
List<Integer> productTypes = supplier
.getSupplierProductList()
.stream()
.filter(it->it.getIfCanOrder().equals(1))
.map(SupplierProduct::getProductType)
.toList();
return legs.stream().filter(it -> productTypes.contains(it.getLegType())).toList();
} else {
return legs;
}
}
}

View File

@ -0,0 +1,18 @@
package com.chint.domain.value_object;
import cn.hutool.core.bean.BeanUtil;
import com.chint.domain.aggregates.order.RouteCustomExtensionField;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class ApproveCustomField {
@ApiModelProperty("自定义字段名")
private String fieldName;
@ApiModelProperty("自定义字段值")
private String fieldValue;
public static ApproveCustomField of(RouteCustomExtensionField routeCustomExtensionField) {
return BeanUtil.copyProperties(routeCustomExtensionField, ApproveCustomField.class);
}
}

View File

@ -31,13 +31,9 @@ public class ApproveRouteData {
private String startTime; private String startTime;
@ApiModelProperty("结束时间") @ApiModelProperty("结束时间")
private String endTime; private String endTime;
@ApiModelProperty("结束时间") @ApiModelProperty("自定义字段")
private List<ApproveCustomField> approveCustomFieldList; private List<ApproveCustomField> approveCustomFieldList;
@Data
private static class ApproveCustomField{
private String fieldName;
private String fieldValue;
}
} }

View File

@ -13,6 +13,7 @@ public class OrderQueryData extends BaseQuery {
@ApiModelProperty("需要同步的行程规划单ID") @ApiModelProperty("需要同步的行程规划单ID")
private Long routeId; private Long routeId;
private String billcode; private String billcode;
private String actualOrderNo;
private String sysCode; private String sysCode;
private List<Integer> approvalStatusCodes; private List<Integer> approvalStatusCodes;
private List<Integer> legTypes; private List<Integer> legTypes;

View File

@ -0,0 +1,33 @@
package com.chint.infrastructure.repository;
import com.chint.domain.aggregates.supplier.Supplier;
import com.chint.domain.repository.SupplierRepository;
import com.chint.infrastructure.repository.jdbc.JdbcSupplierRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Repository;
import java.util.Optional;
@Repository
public class SupplierRepositoryImpl implements SupplierRepository {
@Autowired
private JdbcSupplierRepository jdbcSupplierRepository;
@Override
public Supplier save(Supplier supplier) {
return jdbcSupplierRepository.save(supplier);
}
@Override
public Optional<Supplier> findById(Long id) {
return jdbcSupplierRepository.findById(id);
}
// @Cacheable(value = "supplier", key = "#supplierName")
@Override
public Optional<Supplier> findBySupplierName(String supplierName) {
return jdbcSupplierRepository.findByName(supplierName);
}
}

View File

@ -0,0 +1,13 @@
package com.chint.infrastructure.repository.jdbc;
import com.chint.domain.aggregates.supplier.Supplier;
import com.chint.domain.aggregates.system.SupplierCallBackLog;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import java.util.Optional;
@Repository
public interface JdbcSupplierRepository extends CrudRepository<Supplier,Long> {
Optional<Supplier> findByName(String name);
}

View File

@ -265,7 +265,7 @@ class RouteApplicationTests {
@Test @Test
void loginSign() { void loginSign() {
String sfno = "200529132"; String sfno = "240412063";
String syscode = "FSSC"; String syscode = "FSSC";
String billcode = "CLSQ240225000099"; String billcode = "CLSQ240225000099";
String companycode = "正泰集团股份有限公司"; String companycode = "正泰集团股份有限公司";
@ -280,7 +280,7 @@ class RouteApplicationTests {
@Test @Test
void loginSignProd() { void loginSignProd() {
String sfno = "200529132"; String sfno = "240412063";
String syscode = "FSSC"; String syscode = "FSSC";
String billcode = "CLSQ240225000099"; String billcode = "CLSQ240225000099";
String companycode = "正泰集团股份有限公司"; String companycode = "正泰集团股份有限公司";