修改职级代码

This commit is contained in:
lulz1 2024-02-23 08:17:48 +08:00
parent 42946a89c6
commit 44c7cb1845
20 changed files with 156 additions and 57 deletions

View File

@ -1,5 +1,6 @@
package com.chint.application.commands;
import com.chint.domain.aggregates.user.User;
import com.chint.domain.value_object.UserLoginParam;
import com.chint.infrastructure.echo_framework.command.Command;
import lombok.Data;
@ -8,10 +9,10 @@ import lombok.EqualsAndHashCode;
@EqualsAndHashCode(callSuper = true)
@Data
public class OrderCreateCommand extends Command {
private UserLoginParam loginParam;
private User user;
public OrderCreateCommand of(UserLoginParam loginParam) {
this.loginParam = loginParam;
public OrderCreateCommand of(User user) {
this.user = user;
return this;
}
}

View File

@ -69,6 +69,4 @@ public class OrderController {
orderApplicationService.deleteLegToOrder(deleteLegData);
return Result.Success(SUCCESS);
}
}

View File

@ -60,7 +60,7 @@ public class LoginController {
throw new OrderException("companycode 不能为空");
}
//发送创建行程订单命令
Command.of(OrderCreateCommand.class).of(userLoginParam).sendToQueue();
Command.of(OrderCreateCommand.class).of(BaseContext.getCurrentUser()).sendToQueue();
}
//异步执行更新用户信息到同程

View File

@ -18,6 +18,7 @@ import com.chint.domain.value_object.*;
import com.chint.infrastructure.util.BaseContext;
import com.chint.infrastructure.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import java.time.format.DateTimeFormatter;
@ -53,15 +54,63 @@ public class OrderQuery {
}
public PageResult<RouteOrderPageRes> pageQuery(OrderQueryData queryData) {
//执行筛选分页查询
List<Integer> approvalStatusCodes = queryData.getApprovalStatusCodes();
List<Integer> legTypes = queryData.getLegTypes();
if (!approvalStatusCodes.isEmpty() || !legTypes.isEmpty()) {
Integer pageNum = queryData.getPageNum();
Integer pageSize = queryData.getPageSize();
List<RouteOrder> routeOrders = routeRepository.findByActualOrderNoNotNull();
if (!approvalStatusCodes.isEmpty()) {
routeOrders = routeOrders.stream()
.filter(routeOrder -> approvalStatusCodes.contains(routeOrder.getApprovalStatusCode()))
.toList();
}
if (!legTypes.isEmpty()) {
routeOrders = routeOrders.stream()
.filter(routeOrder -> {
List<Integer> list = new ArrayList<>(routeOrder.getLegItems().stream().map(Leg::getLegType).toList());
return list.retainAll(legTypes);
})
.toList();
}
int total = routeOrders.size();
List<RouteOrderPageRes> orders = routeOrders
.stream()
.skip((long) (pageNum - 1) * pageSize)
.limit(pageSize)
.map(OrderQuery::getRouteOrderPageRes)
.toList();
return new PageResult<>(total, orders);
}
if (queryData.getOrderNo() != null) {
Page<RouteOrder> byOrderNoFuzzy = routeRepository.findByOrderNoFuzzy(queryData);
return new PageResult<>(byOrderNoFuzzy.getTotalElements(),
byOrderNoFuzzy
.getContent()
.stream()
.map(OrderQuery::getRouteOrderPageRes)
.toList());
}
//执行普通分页查询
PageResult<RouteOrder> routeOrderPageResult = routeRepository.pageQuery(queryData);
routeOrderPageResult.getRecords().forEach(order -> {
orderDomainService.queryLocation(order.getLegItems());
});
User currentUser = BaseContext.getCurrentUser();
List<RouteOrderPageRes> routeOrderPageRes = routeOrderPageResult
.getRecords()
.stream()
.map(routeOrder -> {
.map(OrderQuery::getRouteOrderPageRes)
.toList();
return new PageResult<>(routeOrderPageResult.getTotal(), routeOrderPageRes);
}
private static RouteOrderPageRes getRouteOrderPageRes(RouteOrder routeOrder) {
User currentUser = BaseContext.getCurrentUser();
RouteOrderPageRes res = BeanUtil.copyProperties(routeOrder.reloadStatus(), RouteOrderPageRes.class);
List<LocationRes> locationRes = routeOrder.getLegItems()
.stream()
@ -72,9 +121,6 @@ public class OrderQuery {
res.setLocationResList(locationRes);
res.setUserName(currentUser.getName());
return res;
})
.toList();
return new PageResult<>(routeOrderPageResult.getTotal(), routeOrderPageRes);
}
public RouteOrder queryById(Long routeId) {

View File

@ -41,6 +41,8 @@ public class RouteOrder extends BaseEntity {
private LocalDateTime bookingTime;
private Long userId;
private String supplierName;
//差标等级
private String standardLevel;
//审批订单号
@Embedded.Nullable
private ApproveOrderNo approveOrderNo;

View File

@ -45,7 +45,8 @@ public class RouteOrderFactory implements OrderFactory {
@Override
public RouteOrder createRoute(OrderCreateCommand command) {
User currentUser = BaseContext.getCurrentUser();
UserLoginParam loginParam = command.getLoginParam();
User user = command.getUser();
UserLoginParam loginParam = user.getUserLoginParam();
RouteOrder routeOrder = new RouteOrder();
routeOrder.setRouteOrderNo(OrderNo.generate());
//根据项目需求需要保存假审批订单号真审批订单号 创建的时候保存假审批订单号

View File

@ -3,6 +3,9 @@ package com.chint.domain.repository;
import com.chint.domain.aggregates.order.RouteOrder;
import com.chint.domain.value_object.OrderQueryData;
import com.chint.infrastructure.util.PageResult;
import org.springframework.data.domain.Page;
import java.util.List;
public interface RouteRepository {
RouteOrder queryById(Long orderId);
@ -14,9 +17,12 @@ public interface RouteRepository {
RouteOrder findByActualOrderNoAndSysCode(String actualOrderNo,String sysCode);
RouteOrder findByOrderNo(String orderNo);
Page<RouteOrder> findByOrderNoFuzzy(OrderQueryData orderQueryData);
RouteOrder save(RouteOrder routeOrder);
PageResult<RouteOrder> pageQuery(OrderQueryData orderQueryData);
List<RouteOrder> findByActualOrderNoNotNull();
}

View File

@ -5,6 +5,5 @@ import com.chint.domain.aggregates.user.User;
public interface UserRepository {
User findById(Long id);
User findByUserEmployeeNo(Long employeeNo);
User save(User user);
}

View File

@ -18,6 +18,7 @@ import com.chint.domain.value_object.ApprovalLegData;
import com.chint.domain.value_object.UserLoginParam;
import com.chint.infrastructure.echo_framework.annotation.ListenTo;
import com.chint.infrastructure.util.BaseContext;
import com.chint.interfaces.rest.user.UserHttpRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -46,6 +47,9 @@ public class OrderDomainService {
@Autowired
private OrderDetailRepository orderDetailRepository;
@Autowired
private UserHttpRequest userHttpRequest;
public RouteOrder saveOrder(RouteOrder routeOrder) {
return routeRepository.save(routeOrder);
}
@ -60,13 +64,13 @@ public class OrderDomainService {
@ListenTo(command = "OrderCreateCommand", order = 0)
public RouteOrder createOrder(OrderCreateCommand command) {
UserLoginParam loginParam = command.getLoginParam();
User byUserEmployeeNo = userRepository.findByUserEmployeeNo(Long.valueOf(loginParam.getSfno()));
User user = command.getUser();
UserLoginParam loginParam = user.getUserLoginParam();
return Optional.ofNullable(routeRepository
.findByFakeOrderNoAndSysCode(loginParam.getBillcode(), loginParam.getSyscode()))
.orElseGet(() -> {
BaseContext.setCurrentUser(byUserEmployeeNo);
RouteOrder order = routeOrderFactory.createRoute(command);
order.setStandardLevel(user.getStandardLevel());
ApprovalEvent approvalEvent = routeOrderFactory.createApprovalEvent(APPROVAL_EVENT_PREPARE);
order.addApprovalEvent(approvalEvent);
this.saveOrder(order);
@ -75,7 +79,6 @@ public class OrderDomainService {
}
@ListenTo(command = "OrderApprovalCommand", order = 0)
public void approvalOrder(OrderApprovalCommand command) {
ApprovalLegData data = command.getData();

View File

@ -4,6 +4,7 @@ import com.chint.application.commands.*;
import com.chint.domain.aggregates.order.*;
import com.chint.domain.aggregates.user.User;
import com.chint.domain.exceptions.CommandException;
import com.chint.domain.exceptions.OrderException;
import com.chint.domain.factoriy.leg_event.LegEventFactory;
import com.chint.domain.factoriy.order.RouteOrderFactory;
import com.chint.domain.factoriy.order_detail.OrderDetailFactory;
@ -65,7 +66,9 @@ public class LegEventHandler implements LegEventService {
public void approveLeg(LegApprovalCommand command) {
ApproveLegData data = command.getData();
RouteOrder routeOrder = routeRepository.findByFakeOrderNoAndSysCode(data.getFakeOrderNo(), data.getSysCode()).reloadStatus();
if (routeOrder.getLegItems().isEmpty()) {
throw new OrderException(LEG_ERROR);
}
if (routeOrder.getOrderStatus().equals(ORDER_STATUS_PREPARE)) {
ApproveOrderNo approveOrderNo = routeOrder.getApproveOrderNo();
approveOrderNo.setActualOrderNo(data.getActualOrderNo());

View File

@ -2,10 +2,9 @@ package com.chint.domain.service.order_sync;
import com.chint.domain.aggregates.order.Leg;
import com.chint.domain.aggregates.order.RouteOrder;
import com.chint.domain.aggregates.user.User;
import com.chint.domain.repository.CityRepository;
import com.chint.domain.repository.UserRepository;
import com.chint.domain.service.OrderDomainService;
import com.chint.infrastructure.util.BaseContext;
import com.chint.interfaces.rest.ctrip.CTripApprovalRequest;
import com.chint.interfaces.rest.ctrip.dto.approval.ApprovalRequest;
import com.chint.interfaces.rest.ctrip.dto.approval.ApprovalResult;
@ -15,6 +14,7 @@ import com.chint.interfaces.rest.ctrip.dto.approval.hotel.HotelEndorsementDetail
import com.chint.interfaces.rest.ctrip.dto.approval.quick.CarQuickEndorsementDetail;
import com.chint.interfaces.rest.ctrip.dto.approval.quick.RankInfo;
import com.chint.interfaces.rest.ctrip.dto.approval.train.TrainEndorsementDetail;
import com.chint.interfaces.rest.user.UserHttpRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@ -37,6 +37,12 @@ public class CTripOrderSyncAdapter implements SupplierOrderSync {
@Autowired
private OrderDomainService orderDomainService;
@Autowired
private UserHttpRequest userHttpRequest;
@Autowired
private UserRepository userRepository;
@Override
public boolean syncSupplierOrder(RouteOrder order) {
System.out.println("开始同步协程订单");
@ -54,31 +60,32 @@ public class CTripOrderSyncAdapter implements SupplierOrderSync {
}
private ApprovalRequest getApprovalRequestParam(RouteOrder order) {
User currentUser = BaseContext.getCurrentUser();
RankInfo rankInfo = RankInfo.of(currentUser.getStandardLevel());
// RankInfo rankInfo = RankInfo.of(order.getStandardLevel());
RankInfo rankInfo = RankInfo.of("测试职级");
String employeeNo = String.valueOf(order.getUserId());
ApprovalRequest approvalRequestParam = ApprovalRequest
.buildApproval(order.getRouteOrderNo(), String.valueOf(currentUser.getEmployeeNo()), rankInfo);
.buildApproval(order.getRouteOrderNo(), String.valueOf(employeeNo), rankInfo);
Map<Integer, List<Leg>> collect = orderDomainService.queryLocation(order.getLegItems())
.stream().collect(Collectors.groupingBy(Leg::getLegType));
collect.forEach((k, v) -> {
switch (k) {
case LEG_TYPE_TRAIN -> approvalRequestParam.withTrain(generateTrainList(v));
case LEG_TYPE_HOTEL -> approvalRequestParam.withHotel(generateHotelList(v));
case LEG_TYPE_AIRPLANE -> approvalRequestParam.withAir(generateFilghtList(v));
case LEG_TYPE_TAXI -> approvalRequestParam.withQuickCar(generateCarList(v));
case LEG_TYPE_TRAIN -> approvalRequestParam.withTrain(generateTrainList(v, employeeNo));
case LEG_TYPE_HOTEL -> approvalRequestParam.withHotel(generateHotelList(v, employeeNo));
case LEG_TYPE_AIRPLANE -> approvalRequestParam.withAir(generateFilghtList(v, employeeNo));
case LEG_TYPE_TAXI -> approvalRequestParam.withQuickCar(generateCarList(v, employeeNo));
}
});
return approvalRequestParam;
}
private List<HotelEndorsementDetail> generateHotelList(List<Leg> legs) {
private List<HotelEndorsementDetail> generateHotelList(List<Leg> legs, String employeeNo) {
List<HotelEndorsementDetail> hotelList = new ArrayList<>();
legs.forEach(leg -> {
hotelList.add(
HotelEndorsementDetail.of(List.of(
cityRepository.findByCityName(leg.getOriginLocation().getLocationName()).getCity()
))
.passenger(PassengerDetail.of(String.valueOf(BaseContext.getCurrentUser().getEmployeeNo())))
.passenger(PassengerDetail.of(employeeNo))
.starTime(leg.getStartTime())
.endTime(leg.getEndTime())
);
@ -86,7 +93,7 @@ public class CTripOrderSyncAdapter implements SupplierOrderSync {
return hotelList;
}
private List<FlightEndorsementDetail> generateFilghtList(List<Leg> legs) {
private List<FlightEndorsementDetail> generateFilghtList(List<Leg> legs, String employeeNo) {
List<FlightEndorsementDetail> filghtList = new ArrayList<>();
legs.forEach(leg -> {
filghtList.add(
@ -95,7 +102,7 @@ public class CTripOrderSyncAdapter implements SupplierOrderSync {
), List.of(
cityRepository.findByCityName(leg.getDestinationLocation().getLocationName()).getCity()
))
.passenger(PassengerDetail.of(String.valueOf(BaseContext.getCurrentUser().getEmployeeNo())))
.passenger(PassengerDetail.of(employeeNo))
.starTime(leg.getStartTime())
.endTime(leg.getEndTime())
);
@ -103,7 +110,7 @@ public class CTripOrderSyncAdapter implements SupplierOrderSync {
return filghtList;
}
private List<TrainEndorsementDetail> generateTrainList(List<Leg> legs) {
private List<TrainEndorsementDetail> generateTrainList(List<Leg> legs, String employeeNo) {
List<TrainEndorsementDetail> trainList = new ArrayList<>();
legs.forEach(leg -> {
trainList.add(
@ -111,7 +118,7 @@ public class CTripOrderSyncAdapter implements SupplierOrderSync {
cityRepository.findByCityName(leg.getOriginLocation().getLocationName()).getCity()
), List.of(
cityRepository.findByCityName(leg.getDestinationLocation().getLocationName()).getCity()
)).passenger(PassengerDetail.of(String.valueOf(BaseContext.getCurrentUser().getEmployeeNo())))
)).passenger(PassengerDetail.of(employeeNo))
.starTime(leg.getStartTime())
.endTime(leg.getEndTime())
);
@ -119,13 +126,13 @@ public class CTripOrderSyncAdapter implements SupplierOrderSync {
return trainList;
}
private List<CarQuickEndorsementDetail> generateCarList(List<Leg> legs) {
private List<CarQuickEndorsementDetail> generateCarList(List<Leg> legs, String employeeNo) {
List<CarQuickEndorsementDetail> carList = new ArrayList<>();
legs.forEach(leg -> {
carList.add(
CarQuickEndorsementDetail.of(List.of(
cityRepository.findByCityName(leg.getOriginLocation().getLocationName()).getCity()
)).passenger(PassengerDetail.of(String.valueOf(BaseContext.getCurrentUser().getEmployeeNo())))
)).passenger(PassengerDetail.of(employeeNo))
.starTime(leg.getStartTime())
.endTime(leg.getEndTime())
);

View File

@ -4,12 +4,15 @@ package com.chint.domain.value_object;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.List;
@EqualsAndHashCode(callSuper = true)
@Data
public class OrderQueryData extends BaseQuery {
private Long routeId;
private String billcode;
private String sysCode;
private List<Integer> approvalStatusCodes;
private List<Integer> legTypes;
private String orderNo;
}

View File

@ -11,6 +11,7 @@ public class Constant {
public static final String INVALID_REQUEST = "无效的请求";
public static final String ACCESS_DENIED = "访问被拒绝";
public static final String SERVER_ERROR = "服务器错误";
public static final String LEG_ERROR = "行程错误";
// 数据相关消息
public static final String DATA_ALREADY_EXISTS = "数据已存在";

View File

@ -34,7 +34,7 @@ public class LocationRepositoryImpl implements LocationRepository {
return PageResult.totalPageNum(res.getTotalElements(), res.toList());
}
if (locationParam.getLevel() != null) {
Page<Location> res = jdbcLocationRepository.findAllByLevel(locationParam.getLevel(), pageResult);
Page<Location> res = jdbcLocationRepository.findAllByLevel(Integer.valueOf(locationParam.getLevel().toString()), pageResult);
return PageResult.totalPageNum(res.getTotalElements(), res.toList());
}
if (locationParam.getParentLocationId() != null) {

View File

@ -47,6 +47,16 @@ public class RouteRepositoryImpl implements RouteRepository {
return jdbcRouteRepository.findByRouteOrderNo(orderNo);
}
@Override
public Page<RouteOrder> findByOrderNoFuzzy(OrderQueryData orderQueryData) {
PageRequest sort = PageRequest
.of(orderQueryData.getPageNum() - 1, orderQueryData.getPageSize(), Sort.by("sort"));
User currentUser = BaseContext.getCurrentUser();
return jdbcRouteRepository
.findByCreateUserAndRouteOrderNoContaining(currentUser.getUserId().toString()
, orderQueryData.getOrderNo(), sort);
}
@Override
public RouteOrder save(RouteOrder routeOrder) {
return jdbcRouteRepository.save(routeOrder);
@ -63,4 +73,10 @@ public class RouteRepositoryImpl implements RouteRepository {
orders.forEach(RouteOrder::reloadStatus);
return new PageResult<>(byUserId.getTotalElements(), orders);
}
@Override
public List<RouteOrder> findByActualOrderNoNotNull() {
User currentUser = BaseContext.getCurrentUser();
return jdbcRouteRepository.findByCreateUserAndApproveOrderNo_ActualOrderNoNotNull(currentUser.getUserId().toString());
}
}

View File

@ -20,7 +20,9 @@ public class BeforeSaveCallbackImpl implements BeforeSaveCallback<BaseEntity> {
entity.setCreateUser(BaseContext.getCurrentUser().getUserId().toString());
}
entity.setUpdateTime(LocalDateTime.now());
if (BaseContext.getCurrentUser() != null) {
entity.setUpdateUser(BaseContext.getCurrentUser().getUserId().toString());
}
return entity;
}
}

View File

@ -16,7 +16,7 @@ public interface JdbcLocationRepository extends CrudRepository<Location, Long> {
Page<Location> findAllByParentLocationId(Long parentLocationId, Pageable pageable);
Page<Location> findAllByLevel(Long level, Pageable pageable);
Page<Location> findAllByLevel(Integer level, Pageable pageable);
List<Location> findByFirstPinYin(String firstPinYin);
List<Location> findByLocationNameContaining(String locationName);

View File

@ -3,10 +3,11 @@ package com.chint.infrastructure.repository.jdbc;
import com.chint.domain.aggregates.order.RouteOrder;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jdbc.repository.query.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface JdbcRouteRepository extends CrudRepository<RouteOrder, Long> {
Page<RouteOrder> findByCreateUser(String userId, Pageable pageable);
@ -21,4 +22,7 @@ public interface JdbcRouteRepository extends CrudRepository<RouteOrder, Long> {
RouteOrder findByRouteOrderNo(String routeOrderNo);
List<RouteOrder> findByCreateUserAndApproveOrderNo_ActualOrderNoNotNull(String createUser);
Page<RouteOrder> findByCreateUserAndRouteOrderNoContaining(String createUser, String routeOrderNo, Pageable pageable);
}

View File

@ -56,7 +56,8 @@ public class UserHttpRequestImpl implements UserHttpRequest {
}
Ranks ranks = rankDomainService.queryRanks(rankName, user.getCompanyCode());
if (ranks != null) {
user.setStandardLevel(ranks.getStandardLevel());
// user.setStandardLevel(ranks.getStandardLevel());
user.setStandardLevel("测试职级");
}
return user;
}

View File

@ -34,12 +34,12 @@ class RouteApplicationTests {
userHttpRequest.loadUserInfo(user);
}
// @Test
@Test
void loginSign() {
String sfno = "220322120";
String sfno = "230615020";
String syscode = "FFSC";
String billcode = "";
String companycode = "";
String billcode = "ABC10337191351";
String companycode = "A30000001";
String sec = "Superdandan";
String timespan = "987654321";
String s = Digest.md5(sfno + syscode + billcode + companycode + sec + timespan);
@ -76,5 +76,11 @@ class RouteApplicationTests {
routeRepository.deleteById(17L);
routeRepository.deleteById(18L);
routeRepository.deleteById(19L);
routeRepository.deleteById(19L);
routeRepository.deleteById(19L);
routeRepository.deleteById(19L);
routeRepository.deleteById(19L);
routeRepository.deleteById(19L);
routeRepository.deleteById(19L);
}
}