完成票务员查询功能 ,根据配置的票务员信息自动同步账期的结算数据

This commit is contained in:
lulz1 2024-05-14 10:49:17 +08:00
parent ff05e78348
commit b38b8ba3a3
20 changed files with 185 additions and 28 deletions

View File

@ -0,0 +1,8 @@
package com.chint.application.dtos;
import lombok.Data;
@Data
public class OrderRecordParam {
private String accountPeriod;
}

View File

@ -0,0 +1,29 @@
package com.chint.application.in;
import com.chint.application.dtos.OrderRecordParam;
import com.chint.domain.service.OrderRecordDomainService;
import com.chint.infrastructure.util.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import static com.chint.infrastructure.constant.CommonMessageConstant.SUCCESS;
@RestController
@RequestMapping("/record")
public class OrderRecordController {
@Autowired
private OrderRecordDomainService orderRecordDomainService;
@ApiOperation("根据配置同步票务员")
@PostMapping("/reload/clerk")
public Result<String> reloadClerk(@RequestBody OrderRecordParam orderRecordParam){
orderRecordDomainService.reloadClerkAndSave(orderRecordParam.getAccountPeriod());
return Result.Success();
}
}

View File

@ -132,7 +132,7 @@ public class OrderDetailQuery {
.ifPresentOrElse(record::setAccountCompanyName, () -> record.setAccountCompanyName(record.getAccountCompanyName()));
record.setReceiptsNum(QueryUtil.reGetReceiptsNum(record.getReceiptsNum()));
});
systemDomainService.generateRecordClerk(orderFlightRecordList);
// systemDomainService.generateRecordClerk(orderFlightRecordList);
return orderFlightRecordList;
}
@ -144,7 +144,7 @@ public class OrderDetailQuery {
.ifPresentOrElse(record::setAccountCompanyName, () -> record.setAccountCompanyName(record.getAccountCompanyName()));
record.setReceiptsNum(QueryUtil.reGetReceiptsNum(record.getReceiptsNum()));
});
systemDomainService.generateRecordClerk(orderHotelRecordList);
// systemDomainService.generateRecordClerk(orderHotelRecordList);
return orderHotelRecordList;
}
@ -155,7 +155,7 @@ public class OrderDetailQuery {
.ifPresentOrElse(record::setAccountCompanyName, () -> record.setAccountCompanyName(record.getAccountCompanyName()));
record.setReceiptsNum(QueryUtil.reGetReceiptsNum(record.getReceiptsNum()));
});
systemDomainService.generateRecordClerk(orderTrainRecordList);
// systemDomainService.generateRecordClerk(orderTrainRecordList);
return orderTrainRecordList;
}
@ -166,7 +166,7 @@ public class OrderDetailQuery {
.ifPresentOrElse(record::setAccountCompanyName, () -> record.setAccountCompanyName(record.getAccountCompanyName()));
record.setReceiptsNum(QueryUtil.reGetReceiptsNum(record.getReceiptsNum()));
});
systemDomainService.generateRecordClerk(orderCarRecordList);
// systemDomainService.generateRecordClerk(orderCarRecordList);
return orderCarRecordList;
}

View File

@ -12,6 +12,9 @@ import com.chint.interfaces.rest.amap.request.AmapOrderDetailRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
import java.math.RoundingMode;
import static com.chint.infrastructure.constant.BelongSystemConstant.TRAVAL_SYS_TYPE_AMAP;
import static com.chint.infrastructure.constant.FSSCConstant.FSSC_CAR_STATUS_SUCCESS;
import static com.chint.interfaces.rest.amap.util.AmapStatusUtil.mapFSSCOrderStatus;
@ -75,9 +78,11 @@ public class AmapOrderExtensionFactoryImpl implements OrderExtensionFactory {
carOrderDetail.setUserCode(data.getUserId());
carOrderDetail.setPhone(data.getPassengerPhone());
carOrderDetail.setBOOK_ORG_STRUCT_1(data.getDepartmentName());
carOrderDetail.setCreateTime(data.getRequestTime());
carOrderDetail.setOrderAmount(String.valueOf(data.getEnterpriseAmount() + data.getPersonAmount()));
//金额
BigDecimal amountCent = BigDecimal.valueOf(data.getEnterpriseAmount() + data.getPersonAmount());
carOrderDetail.setOrderAmount(String.valueOf(amountCent.divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP)));
carOrderDetail.setCompanyPaymentAmount(String.valueOf(data.getEnterpriseAmount()));
carOrderDetail.setPersonalPaymentAmount(String.valueOf(data.getPersonAmount()));
@ -97,8 +102,8 @@ public class AmapOrderExtensionFactoryImpl implements OrderExtensionFactory {
carOrderDetail.setStartTime(carOrderDetail.getCreateTime());
carOrderDetail.setArriveTime(carOrderDetail.getCreateTime());
}
carOrderDetail.setMileage(data.getMileage());
BigDecimal bigMile = new BigDecimal(data.getMileage());
carOrderDetail.setMileage(String.valueOf(bigMile.divide(BigDecimal.valueOf(1000), 2, RoundingMode.HALF_UP)));
carOrderDetail.setRunTime(data.getDuration());
carOrderDetail.setFromStationName(data.getStartName());
carOrderDetail.setToStationName(data.getEndName());

View File

@ -14,6 +14,9 @@ import java.util.Optional;
public interface OrderCarRecordRepository {
List<OrderCarRecord> saveAll(List<OrderCarRecord> orderCarRecordList);
List<OrderCarRecord> findAll();
List<OrderCarRecord> findByAccountPeriod(String accountPeriod);
Optional<OrderCarRecord> findByDetailId(String detailId);
List<OrderCarRecord> findByDetailIdIn(List<String> detailIdList);

View File

@ -12,8 +12,11 @@ import java.util.Optional;
public interface OrderFlightRecordRepository {
List<OrderFlightRecord> saveAll(List<OrderFlightRecord> orderFlightRecordList);
List<OrderFlightRecord> findByAccountPeriod(String accountPeriod);
Optional<OrderFlightRecord> findByDetailId(String detailId);
List<OrderFlightRecord> findByDetailIdIn(List<String> detailId);
List<OrderFlightRecord> findByDetailIdIn(List<String> detailId);
PageResult<OrderFlightRecord> findByUpdateDataTime(LocalDateTime startTime,
LocalDateTime endTime,

View File

@ -12,6 +12,9 @@ import java.util.Optional;
public interface OrderHotelRecordRepository {
List<OrderHotelRecord> saveAll(List<OrderHotelRecord> orderHotelRecordList);
List<OrderHotelRecord> findAll();
List<OrderHotelRecord> findByAccountPeriod(String accountPeriod);
Optional<OrderHotelRecord> findByDetailId(String detailId);
List<OrderHotelRecord> findByDetailIdIn(List<String> detailIds);

View File

@ -17,6 +17,7 @@ public interface OrderTrainRecordRepository {
Optional<OrderTrainRecord> findByDetailId(String detailId);
List<OrderTrainRecord> findByDetailIdIn(List<String> detailIds);
List<OrderTrainRecord> findByAccountPeriod(String accountPeriod);
PageResult<OrderTrainRecord> findByUpdateDataTime(LocalDateTime startTime, LocalDateTime endTime,
Integer pageSize, Integer pageNum ,String systemType);

View File

@ -1,11 +1,18 @@
package com.chint.domain.service;
import com.chint.domain.aggregates.order.order_record.OrderCarRecord;
import com.chint.domain.aggregates.order.order_record.OrderFlightRecord;
import com.chint.domain.aggregates.order.order_record.OrderHotelRecord;
import com.chint.domain.aggregates.order.order_record.OrderTrainRecord;
import com.chint.domain.repository.OrderCarRecordRepository;
import com.chint.domain.repository.OrderFlightRecordRepository;
import com.chint.domain.repository.OrderHotelRecordRepository;
import com.chint.domain.repository.OrderTrainRecordRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Service
public class OrderRecordDomainService {
@ -19,5 +26,27 @@ public class OrderRecordDomainService {
@Autowired
private OrderTrainRecordRepository orderTrainRecordRepository;
@Autowired
private SystemDomainService systemDomainService;
@Transactional
public void reloadClerkAndSave(String accountPeriod) {
List<OrderCarRecord> orderCarRecordList = orderCarRecordRepository.findByAccountPeriod(accountPeriod);
List<OrderCarRecord> updatedRecords = (List<OrderCarRecord>) systemDomainService.generateRecordClerkAndNeedUpdate(orderCarRecordList);
orderCarRecordRepository.saveAll(updatedRecords);
List<OrderHotelRecord> orderHotelRecordList = orderHotelRecordRepository.findByAccountPeriod(accountPeriod);
List<OrderHotelRecord> updatedOrderHotelRecordList = (List<OrderHotelRecord>) systemDomainService.generateRecordClerkAndNeedUpdate(orderHotelRecordList);
orderHotelRecordRepository.saveAll(updatedOrderHotelRecordList);
List<OrderFlightRecord> orderFlightRecordList = orderFlightRecordRepository.findByAccountPeriod(accountPeriod);
List<OrderFlightRecord> updatedOrderFlightRecordList = (List<OrderFlightRecord>) systemDomainService.generateRecordClerkAndNeedUpdate(orderFlightRecordList);
orderFlightRecordRepository.saveAll(updatedOrderFlightRecordList);
List<OrderTrainRecord> orderTrainRecordList = orderTrainRecordRepository.findByAccountPeriod(accountPeriod);
List<OrderTrainRecord> updatedOrderTrainRecordList = (List<OrderTrainRecord>) systemDomainService.generateRecordClerkAndNeedUpdate(orderTrainRecordList);
orderTrainRecordRepository.saveAll(updatedOrderTrainRecordList);
}
}

View File

@ -5,6 +5,7 @@ import com.chint.domain.aggregates.order.order_record.OrderBaseRecord;
import com.chint.domain.aggregates.system.AccountCompany;
import com.chint.domain.aggregates.system.SystemCode;
import com.chint.domain.aggregates.system.SystemOrganization;
import com.chint.domain.aggregates.system.SystemOrganizationExtension;
import com.chint.domain.exceptions.NotFoundException;
import com.chint.domain.repository.AccountCompanyRepository;
import com.chint.domain.repository.SystemCodeRepository;
@ -15,6 +16,7 @@ import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
import static com.chint.infrastructure.constant.DataMessageConstant.SYS_CODE_ERROR;
import static com.chint.infrastructure.constant.SystemConstant.ORG_CLERK_FIELD_NAME;
@ -97,24 +99,52 @@ public class SystemDomainService {
public List<? extends OrderBaseRecord> generateRecordClerk(List<? extends OrderBaseRecord> recordList) {
List<String> orgCodeList = recordList.stream()
.map(OrderBaseRecord::getBelongDepart)
.distinct()
.filter(Objects::nonNull).toList();
List<SystemOrganization> organizationList =
systemOrganizationRepository.findByOrgCodeList(orgCodeList);
recordList.forEach(record -> organizationList
.stream()
.filter(org -> org.getOrgShortCode().equals(record.getBelongDepart()))
.findFirst()
.ifPresent(org -> record.setTicketClerk(
org.getSystemOrganizationExtensionList()
.stream()
.filter(field -> field.getFieldName().equals(ORG_CLERK_FIELD_NAME))
.findFirst()
.flatMap(field -> Optional.ofNullable(field.getFieldValue()))
.orElse(null)
)));
List<SystemOrganization> organizationList = queryOrgListByRecordList(recordList);
recordList.forEach(record -> updateRecordClerk(record, organizationList));
return recordList;
}
public List<? extends OrderBaseRecord> generateRecordClerkAndNeedUpdate(List<? extends OrderBaseRecord> recordList) {
List<SystemOrganization> organizations = queryOrgListByRecordList(recordList);
// 创建需要更新的记录列表
return recordList.stream()
.filter(record -> updateRecordClerk(record, organizations))
.collect(Collectors.toList());
}
private List<SystemOrganization> queryOrgListByRecordList(List<? extends OrderBaseRecord> recordList) {
// 获取所有独特的部门代码
List<String> orgCodeList = recordList.stream()
.map(OrderBaseRecord::getBelongDepart)
.filter(Objects::nonNull)
.distinct()
.collect(Collectors.toList());
// 获取与这些部门代码相关的组织
return systemOrganizationRepository.findByOrgCodeList(orgCodeList);
}
private boolean updateRecordClerk(OrderBaseRecord record, List<SystemOrganization> organizations) {
// 找到与记录所属部门匹配的组织
return organizations.stream()
.filter(org -> org.getOrgShortCode().equals(record.getBelongDepart()))
.findFirst()
.map(org -> {
String newClerk = findNewClerk(org);
String oldClerk = record.getTicketClerk();
record.setTicketClerk(newClerk);
// 只有当旧的业务员和新的业务员不同的时候才添加到需要更新的列表
return !Objects.equals(oldClerk, newClerk);
})
.orElse(false);
}
private String findNewClerk(SystemOrganization organization) {
// 从组织的扩展字段中找到新的业务员
return organization.getSystemOrganizationExtensionList().stream()
.filter(field -> ORG_CLERK_FIELD_NAME.equals(field.getFieldName()))
.map(SystemOrganizationExtension::getFieldValue)
.findFirst()
.orElse(null);
}
}

View File

@ -39,6 +39,19 @@ public class OrderCarRecordRepositoryImpl implements OrderCarRecordRepository {
return res;
}
@Override
public List<OrderCarRecord> findAll() {
List<OrderCarRecord> res = new ArrayList<>();
orderCarRecordRepository.findAll()
.forEach(res::add);
return res;
}
@Override
public List<OrderCarRecord> findByAccountPeriod(String accountPeriod) {
return orderCarRecordRepository.findByAccountPeriod(accountPeriod);
}
@Override
public Optional<OrderCarRecord> findByDetailId(String detailId) {
return orderCarRecordRepository.findByDetailId(detailId);

View File

@ -41,6 +41,11 @@ public class OrderFlightRecordRepositoryImpl implements OrderFlightRecordReposit
return res;
}
@Override
public List<OrderFlightRecord> findByAccountPeriod(String accountPeriod) {
return jdbcOrderFlightRecordRepository.findByAccountPeriod(accountPeriod);
}
@Override
public Optional<OrderFlightRecord> findByDetailId(String detailId) {
return jdbcOrderFlightRecordRepository.findByDetailId(detailId);

View File

@ -40,6 +40,19 @@ public class OrderHotelRecordRepositoryImpl implements OrderHotelRecordRepositor
return res;
}
@Override
public List<OrderHotelRecord> findAll() {
List<OrderHotelRecord> res = new ArrayList<>();
jdbcOrderHotelRecordRepository.findAll()
.forEach(res::add);
return res;
}
@Override
public List<OrderHotelRecord> findByAccountPeriod(String accountPeriod) {
return jdbcOrderHotelRecordRepository.findByAccountPeriod(accountPeriod);
}
@Override
public Optional<OrderHotelRecord> findByDetailId(String detailId) {
return jdbcOrderHotelRecordRepository.findByDetailId(detailId);

View File

@ -49,6 +49,11 @@ public class OrderTrainRecordRepositoryImpl implements OrderTrainRecordRepositor
return jdbcOrderTrainRecordRepository.findByDetailIdIn(detailIds);
}
@Override
public List<OrderTrainRecord> findByAccountPeriod(String accountPeriod) {
return jdbcOrderTrainRecordRepository.findByAccountPeriod(accountPeriod);
}
@Override
public PageResult<OrderTrainRecord> findByUpdateDataTime(LocalDateTime startTime, LocalDateTime endTime, Integer pageSize, Integer pageNum, String systemType) {
PageRequest pageRequest = PageRequest.of(pageNum - 1, pageSize, Sort.by("update_data_time").descending());

View File

@ -29,6 +29,7 @@ public interface JdbcOrderCarRecordRepository extends CrudRepository<OrderCarRec
Pageable pageable);
List<OrderCarRecord> findByDetailIdIn(Collection<String> detailId);
List<OrderCarRecord> findByAccountPeriod(String accountPeriod);
@Query("""

View File

@ -28,6 +28,7 @@ public interface JdbcOrderFlightRecordRepository extends CrudRepository<OrderFli
Pageable pageable);
List<OrderFlightRecord> findByDetailIdIn(Collection<String> detailId);
List<OrderFlightRecord> findByAccountPeriod(String accountPeriod);
@Query("""
select r1.* from order_flight_record r1

View File

@ -29,6 +29,7 @@ public interface JdbcOrderHotelRecordRepository extends CrudRepository<OrderHote
Pageable pageable);
List<OrderHotelRecord> findByDetailIdIn(Collection<String> detailId);
List<OrderHotelRecord> findByAccountPeriod(String accountPeriod);
@Query("""
select r1.* from order_hotel_record r1

View File

@ -28,6 +28,7 @@ public interface JdbcOrderTrainRecordRepository extends CrudRepository<OrderTrai
Pageable pageable);
List<OrderTrainRecord> findByDetailIdIn(Collection<String> detailId);
List<OrderTrainRecord> findByAccountPeriod(String accountPeriod);
@Query("""
select r1.* from order_train_record r1

View File

@ -48,12 +48,18 @@ public class Result<T> implements Serializable {
return new Result<T>(msg, RESULT_SUCCESS_CODE);
}
public static <T> Result<T> Success() {
return new Result<T>(SUCCESS, RESULT_SUCCESS_CODE);
}
public static <T> Result<T> error(String msg) {
return new Result<T>(msg, RESULT_ERROR_CODE);
}
public static <T> Result<T> tokenExpired(String msg) {
return new Result<T>(msg, "-1");
}
public static <T> Result<T> ssoLoginFail(String msg) {
return new Result<T>(msg, RESULT_SSO_LOGIN_ERROR_CODE);
}

View File

@ -246,7 +246,7 @@ public class CTripTest {
@Test
void search() {
BaseContext.setCurrentUser(user);
SearchOrderResponse response = orderSearchRequest.searchOrderResponseByOrderId("31685995618");
SearchOrderResponse response = orderSearchRequest.searchOrderResponseByOrderId("31445559547");
System.out.println(response);
}