diff --git a/src/main/java/com/chint/domain/service/LegDomainService.java b/src/main/java/com/chint/domain/service/LegDomainService.java index 9cb903fd..40489c30 100644 --- a/src/main/java/com/chint/domain/service/LegDomainService.java +++ b/src/main/java/com/chint/domain/service/LegDomainService.java @@ -7,6 +7,7 @@ import com.chint.domain.aggregates.supplier.SupplierProduct; import com.chint.domain.exceptions.LegEventException; import com.chint.domain.factoriy.leg_event.LegEventFactory; import com.chint.domain.repository.*; +import com.chint.manage.entity.business.LegItinerary; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -180,6 +181,33 @@ public class LegDomainService { return list; } + public List queryLocationByLeg(List list) { + list.forEach(leg -> { + LegExtensionField legExtensionField = leg.getLegExtensionField(); + if (legExtensionField != null && legExtensionField.getLocationIds() != null) { + List locationIdsAsLong; + if (legExtensionField.getLocationIds().startsWith("[")) { + locationIdsAsLong = legExtensionField.getLocationIdsAsLongFromArray(); + } else { + locationIdsAsLong = legExtensionField.getLocationIdsAsLong(); + } + List locationList = legExtensionField.getLocationList(); + if (locationList == null || locationList.size() != locationIdsAsLong.size()) { + List byNameList = locationRepository.findByNameList(locationIdsAsLong); + legExtensionField.setLocationList(byNameList); + } + } + if (leg.getOriginId() != null && leg.getOriginLocation() == null) { + leg.setOriginLocation(locationRepository.findByLocationId(leg.getOriginId())); + } + + if (leg.getDestinationId() != null && leg.getDestinationLocation() == null) { + leg.setDestinationLocation(locationRepository.findByLocationId(leg.getDestinationId())); + } + }); + return list; + } + public RouteOrder checkLegIfStartApproval(RouteOrder routeOrder) { routeOrder.reloadStatus(); List legItems = routeOrder.getLegItems(); diff --git a/src/main/java/com/chint/domain/service/SystemDomainService.java b/src/main/java/com/chint/domain/service/SystemDomainService.java index 804f3b6d..deed1cf0 100644 --- a/src/main/java/com/chint/domain/service/SystemDomainService.java +++ b/src/main/java/com/chint/domain/service/SystemDomainService.java @@ -7,15 +7,12 @@ 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.aggregates.user.Role; import com.chint.domain.aggregates.user.RoleOrganization; -import com.chint.domain.aggregates.user.RoleUser; import com.chint.domain.aggregates.user.User; import com.chint.domain.exceptions.NotFoundException; import com.chint.domain.repository.*; import com.chint.domain.value_object.system.RoleOrganizationVO; import com.chint.infrastructure.echo_framework.annotation.ListenTo; -import com.chint.infrastructure.repository.cache.CacheRoleRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -166,12 +163,12 @@ public class SystemDomainService { @ListenTo(command = "UserRoleCommand", order = 0) public void loadUserRole(UserRoleCommand command) { User user = command.getUser(); - List byUserId = roleUserRepository.findByUserId(user.getUserId()); - List roleList = byUserId.stream().flatMap(it -> roleRepository - .findById(it.getRoleId()) - .stream()) - .toList(); - user.setRoleList(roleList); +// List byUserId = roleUserRepository.findByUserId(user.getUserId()); +// List roleList = byUserId.stream().flatMap(it -> roleRepository +// .findById(it.getRoleId()) +// .stream()) +// .toList(); +// user.setRoleList(roleList); roleRepository.loadUserRole(user); } diff --git a/src/main/java/com/chint/infrastructure/repository/RoleRepositoryImpl.java b/src/main/java/com/chint/infrastructure/repository/RoleRepositoryImpl.java index 467b64e6..57dfbec7 100644 --- a/src/main/java/com/chint/infrastructure/repository/RoleRepositoryImpl.java +++ b/src/main/java/com/chint/infrastructure/repository/RoleRepositoryImpl.java @@ -1,9 +1,7 @@ package com.chint.infrastructure.repository; import com.chint.application.dtos.system.RoleOrgParam; -import com.chint.domain.aggregates.system.SystemOrganization; import com.chint.domain.aggregates.user.Role; -import com.chint.domain.aggregates.user.RoleOrganization; import com.chint.domain.aggregates.user.RoleUser; import com.chint.domain.aggregates.user.User; import com.chint.domain.repository.RoleRepository; @@ -105,7 +103,6 @@ public class RoleRepositoryImpl implements RoleRepository { } user.setRoleOrgCodeList(orgCodeList); - // List orgCodeList = cacheRoleRepository // .roleOrgCodeList(userId, null); // List systemOrganizationVOList = cacheRoleRepository diff --git a/src/main/java/com/chint/manage/entity/business/LegItinerary.java b/src/main/java/com/chint/manage/entity/business/LegItinerary.java new file mode 100644 index 00000000..9f4dc5dd --- /dev/null +++ b/src/main/java/com/chint/manage/entity/business/LegItinerary.java @@ -0,0 +1,73 @@ +package com.chint.manage.entity.business; + +import com.chint.domain.aggregates.order.LegExtensionField; +import com.chint.domain.aggregates.order.Location; +import lombok.Data; +import org.springframework.data.annotation.Id; +import org.springframework.data.annotation.Transient; +import org.springframework.data.relational.core.mapping.MappedCollection; +import org.springframework.data.relational.core.mapping.Table; + +import java.io.Serial; +import java.io.Serializable; + +/** + * + * @author xx LegItinerary.java + * + **/ +@Data +@Table("leg") +public class LegItinerary implements Serializable { +@Serial +private static final long serialVersionUID = 1L; + @Id + private Long legId; + + /****/ + private java.time.LocalDateTime endTime; + + /****/ + private Integer legType; + + /****/ + private Integer sequence; + + /****/ + private java.time.LocalDateTime startTime; + + /****/ + private Long destinationId; + + /****/ + private Long originId; + + /****/ + private Long routeId; + + /****/ + private Long routeOrderKey; + + /****/ + private String estimateAmount; + + /****/ + private String legNo; + + /****/ + private java.time.LocalDateTime createTime; + + /****/ + private String currencyType; + + @Transient + private Location originLocation; + + @Transient + private Location destinationLocation; + + @MappedCollection(idColumn = "leg_id") + private LegExtensionField legExtensionField; + + +} diff --git a/src/main/java/com/chint/manage/entity/business/RouteOrderItinerary.java b/src/main/java/com/chint/manage/entity/business/RouteOrderItinerary.java new file mode 100644 index 00000000..36dc92d7 --- /dev/null +++ b/src/main/java/com/chint/manage/entity/business/RouteOrderItinerary.java @@ -0,0 +1,102 @@ +package com.chint.manage.entity.business; + +import com.chint.domain.aggregates.order.ApprovalEvent; +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; + +/** + * + * @author xx RouteOrderBasic.java + * + **/ +@Data +@Table("route_order") +public class RouteOrderItinerary implements Serializable { +@Serial +private static final long serialVersionUID = 1L; + @Id + private Long routeId; + + /****/ + private java.time.LocalDateTime bookingTime; + + /****/ + private String userId; + + /****/ + private java.time.LocalDateTime createTime; + + /****/ + private String createUser; + + /****/ + private Integer sort; + + /****/ + private Integer status; + + /****/ + private java.time.LocalDateTime updateTime; + + /****/ + private String updateUser; + + /****/ + private String fakeOrderNo; + + /****/ + private String actualOrderNo; + + /**差旅订单号**/ + private String routeOrderNo; + + /****/ + private String supplierName; + + /****/ + private String accountCompany; + + /****/ + private String sysCode; + + /****/ + private String instructions; + + /****/ + private String standardLevel; + + /****/ + private String creator; + + /****/ + private String accountCompanyName; + + /**入账公司64位编码**/ + private String accountCompanyCode; + + /****/ + private String projectName; + + /****/ + private String costCenter; + + /****/ + private java.time.LocalDateTime startTime; + + /****/ + private java.time.LocalDateTime endTime; + + @MappedCollection(idColumn = "route_id", keyColumn = "route_order_key") + private List approveEvents; + + @MappedCollection(idColumn = "route_id", keyColumn = "route_order_key") + private List legItems; + + +} diff --git a/src/main/java/com/chint/manage/entity/query/ConsumptionDetailQuery.java b/src/main/java/com/chint/manage/entity/query/ConsumptionDetailQuery.java index c57ff26a..b497c374 100644 --- a/src/main/java/com/chint/manage/entity/query/ConsumptionDetailQuery.java +++ b/src/main/java/com/chint/manage/entity/query/ConsumptionDetailQuery.java @@ -20,8 +20,9 @@ public class ConsumptionDetailQuery extends BaseQuery{ private Integer productType; private String userName=""; private String actualOrderNo=""; //申请单号 - private List orderIds=new ArrayList<>(); +// private List orderIds=new ArrayList<>(); private List orderNos=new ArrayList<>(); + private List companyCodes=new ArrayList<>(); public String getActualOrderNo() { return BaseUtil.extractAfterDash(actualOrderNo); diff --git a/src/main/java/com/chint/manage/entity/query/ItineraryPageQuery.java b/src/main/java/com/chint/manage/entity/query/ItineraryPageQuery.java index a2b4e568..7e6b719d 100644 --- a/src/main/java/com/chint/manage/entity/query/ItineraryPageQuery.java +++ b/src/main/java/com/chint/manage/entity/query/ItineraryPageQuery.java @@ -1,7 +1,6 @@ package com.chint.manage.entity.query; import com.chint.domain.value_object.BaseQuery; -import com.chint.infrastructure.util.PageResult; import com.chint.manage.util.BaseUtil; import lombok.Data; @@ -13,7 +12,7 @@ public class ItineraryPageQuery extends BaseQuery { private String applicant="";// 申请人 private String actualOrderNo=""; //申请单号 private List userIds=new ArrayList<>(); - private List routeIds=new ArrayList<>(); + private List companyCodes=new ArrayList<>(); public String getActualOrderNo() { diff --git a/src/main/java/com/chint/manage/entity/query/OrderPageQuery.java b/src/main/java/com/chint/manage/entity/query/OrderPageQuery.java index 485fcfcc..314e93db 100644 --- a/src/main/java/com/chint/manage/entity/query/OrderPageQuery.java +++ b/src/main/java/com/chint/manage/entity/query/OrderPageQuery.java @@ -28,11 +28,23 @@ public class OrderPageQuery extends BaseQuery { private List employeeNos=null; + private List companyCodes=null; + private List routeIds=null; + private boolean routeIdsEmpty; + private boolean employeeNosEmpty; + public boolean getRouteIdsEmpty() { + if(routeIds==null||routeIds.isEmpty()){ + return true; + }else { + return false; + } + } + public boolean getEmployeeNosEmpty() { if(employeeNos==null||employeeNos.isEmpty()){ return true; diff --git a/src/main/java/com/chint/manage/entity/query/StandardQuery.java b/src/main/java/com/chint/manage/entity/query/StandardQuery.java index cf2ac0b8..faa4a418 100644 --- a/src/main/java/com/chint/manage/entity/query/StandardQuery.java +++ b/src/main/java/com/chint/manage/entity/query/StandardQuery.java @@ -4,12 +4,16 @@ import com.chint.domain.value_object.BaseQuery; import com.chint.manage.util.BaseUtil; import lombok.Data; +import java.util.ArrayList; +import java.util.List; + @Data public class StandardQuery extends BaseQuery { private String applicant="";// 申请人 private String companyName=""; // 出差公司 private String orderNo=""; //订单号 private String actualOrderNo=""; //申请单号 + private List companyCods=new ArrayList(); public String getActualOrderNo() { return BaseUtil.extractAfterDash(actualOrderNo); diff --git a/src/main/java/com/chint/manage/mapper/JdbcOrderDetailBasicRepository.java b/src/main/java/com/chint/manage/mapper/JdbcOrderDetailBasicRepository.java index c3e8189d..00f290c8 100644 --- a/src/main/java/com/chint/manage/mapper/JdbcOrderDetailBasicRepository.java +++ b/src/main/java/com/chint/manage/mapper/JdbcOrderDetailBasicRepository.java @@ -36,24 +36,27 @@ public interface JdbcOrderDetailBasicRepository extends CrudRepository findAllOrderId(); - @Query("SELECT * FROM order_detail " + - "WHERE route_id IN (:#{#dto.routeIds}) " + -// "WHERE 1=1 " + - "AND (:#{#dto.orderNo} ='' OR order_no LIKE :#{#dto.orderNo}) " + - "AND (:#{#dto.startTime} IS NULL OR :#{#dto.endTime} IS NULL OR order_date BETWEEN :#{#dto.startTime} AND :#{#dto.endTime}) " + - "AND (:#{#dto.productType} ='' OR product_type = :#{#dto.productType}) " + - "AND (:#{#dto.employeeNo} ='' OR employee_no = :#{#dto.employeeNo}) " + - "AND (:#{#dto.employeeNosEmpty} = TRUE OR employee_no IN (:#{#dto.employeeNos}))" + + @Query("SELECT * FROM order_detail od " + + "LEFT JOIN route_order_extension_field roef ON roef.route_id=od.route_id "+ + "WHERE (roef.company_code IN (:#{#dto.companyCodes})) " + + "AND (:#{#dto.routeIdsEmpty} = TRUE OR roef.route_id IN (:#{#dto.routeIds})) " + + "AND (:#{#dto.orderNo} ='' OR od.order_no LIKE :#{#dto.orderNo}) " + + "AND (:#{#dto.startTime} IS NULL OR :#{#dto.endTime} IS NULL OR od.order_date BETWEEN :#{#dto.startTime} AND :#{#dto.endTime}) " + + "AND (:#{#dto.productType} ='' OR od.product_type = :#{#dto.productType}) " + + "AND (:#{#dto.employeeNo} ='' OR od.employee_no = :#{#dto.employeeNo}) " + + "AND (:#{#dto.employeeNosEmpty} = TRUE OR od.employee_no IN (:#{#dto.employeeNos})) " + "LIMIT :#{#pageRequest.pageSize} OFFSET :#{#pageRequest.pageNumber}") List listByCondition(@Param("dto") OrderPageQuery dto, @Param("pageRequest") PageRequest pageRequest); - @Query("SELECT COUNT(*) FROM order_detail " + - "WHERE route_id IN (:#{#dto.routeIds}) " + -// "WHERE 1=1 " + - "AND (:#{#dto.orderNo} ='' OR order_no LIKE :#{#dto.orderNo}) " + - "AND (:#{#dto.startTime} IS NULL OR :#{#dto.endTime} IS NULL OR order_date BETWEEN :#{#dto.startTime} AND :#{#dto.endTime} ) " + - "AND (:#{#dto.productType} ='' OR product_type = :#{#dto.productType}) "+ - "AND (:#{#dto.employeeNo} ='' OR employee_no = :#{#dto.employeeNo}) " + - "AND (:#{#dto.employeeNosEmpty} = TRUE OR employee_no IN (:#{#dto.employeeNos}))") + @Query("SELECT COUNT(*) FROM order_detail od " + + "LEFT JOIN route_order_extension_field roef ON roef.route_id=od.route_id "+ + "WHERE (roef.company_code IN (:#{#dto.companyCodes})) " + + "AND (:#{#dto.routeIdsEmpty} = TRUE OR roef.route_id IN (:#{#dto.routeIds})) " + + "AND (:#{#dto.orderNo} ='' OR od.order_no LIKE :#{#dto.orderNo}) " + + "AND (:#{#dto.startTime} IS NULL OR :#{#dto.endTime} IS NULL OR od.order_date BETWEEN :#{#dto.startTime} AND :#{#dto.endTime}) " + + "AND (:#{#dto.productType} ='' OR od.product_type = :#{#dto.productType}) " + + "AND (:#{#dto.employeeNo} ='' OR od.employee_no = :#{#dto.employeeNo}) " + + "AND (:#{#dto.employeeNosEmpty} = TRUE OR od.employee_no IN (:#{#dto.employeeNos}))" + ) Integer countByCondition(@Param("dto") OrderPageQuery dto); } \ No newline at end of file diff --git a/src/main/java/com/chint/manage/mapper/JdbcRouteOrderExtensionFieldBasicRepository.java b/src/main/java/com/chint/manage/mapper/JdbcRouteOrderExtensionFieldBasicRepository.java index 4ca962bb..e26e9c23 100644 --- a/src/main/java/com/chint/manage/mapper/JdbcRouteOrderExtensionFieldBasicRepository.java +++ b/src/main/java/com/chint/manage/mapper/JdbcRouteOrderExtensionFieldBasicRepository.java @@ -19,4 +19,7 @@ public interface JdbcRouteOrderExtensionFieldBasicRepository extends CrudReposit List findAllByBelongDeptCodeIn(@Param("belongDeptCode") List belongDeptCode); List findAllByCompanyCodeIn(@Param("code") List code); + + @Query("select * from route_order_extension_field") + List findAll(); } \ No newline at end of file diff --git a/src/main/java/com/chint/manage/mapper/JdbcRouteOrderItineraryRepository.java b/src/main/java/com/chint/manage/mapper/JdbcRouteOrderItineraryRepository.java new file mode 100644 index 00000000..cb28c62b --- /dev/null +++ b/src/main/java/com/chint/manage/mapper/JdbcRouteOrderItineraryRepository.java @@ -0,0 +1,20 @@ +package com.chint.manage.mapper; + +import com.chint.manage.entity.business.RouteOrderItinerary; +import org.springframework.data.repository.CrudRepository; +import org.springframework.stereotype.Repository; + +import java.util.List; + + +/** + * + * @author xx JdbcRouteOrderBasicRepository数据库操作接口类 + * + **/ +@Repository +public interface JdbcRouteOrderItineraryRepository extends CrudRepository { + + List findByRouteIdIn(List routeIds); + +} \ No newline at end of file diff --git a/src/main/java/com/chint/manage/mapper/ManageOrderDetailRepository.java b/src/main/java/com/chint/manage/mapper/ManageOrderDetailRepository.java new file mode 100644 index 00000000..4672617e --- /dev/null +++ b/src/main/java/com/chint/manage/mapper/ManageOrderDetailRepository.java @@ -0,0 +1,18 @@ +package com.chint.manage.mapper; + +import com.chint.manage.entity.OrderDetailBasic; +import com.chint.manage.entity.OrderExceedStandard; +import com.chint.manage.entity.RouteOrderExtensionFieldBasic; +import com.chint.manage.entity.query.StandardQuery; +import org.springframework.data.domain.Page; + +import java.util.List; + +public interface ManageOrderDetailRepository { + + List orderDetailBasicList(List routeIds); + + Page OrderExceedStandard(StandardQuery dto); + + List findAll(); +} diff --git a/src/main/java/com/chint/manage/mapper/impl/JdbcConsumptionDetailRepositoryImpl.java b/src/main/java/com/chint/manage/mapper/impl/JdbcConsumptionDetailRepositoryImpl.java index 4d94517e..b4f33898 100644 --- a/src/main/java/com/chint/manage/mapper/impl/JdbcConsumptionDetailRepositoryImpl.java +++ b/src/main/java/com/chint/manage/mapper/impl/JdbcConsumptionDetailRepositoryImpl.java @@ -45,19 +45,20 @@ public class JdbcConsumptionDetailRepositoryImpl implements JdbcConsumptionDetai @Override public Page itineraryPageQueryByDto(ItineraryPageQuery dto) { - String query = "SELECT * FROM route_order " + String query ="LEFT JOIN route_order_extension_field roef ON roef.route_id=ro.route_id " + "WHERE actual_order_no IS NOT NULL "; - if (!dto.getRouteIds().isEmpty()) { - query+="AND route_id IN (:routeIds) "; + if (!dto.getCompanyCodes().isEmpty()) { + query+="AND roef.company_code IN (:companyCodes) "; } if (!dto.getUserIds().isEmpty()) { - query+="AND user_id IN (:userIds) "; + query+="AND ro.user_id IN (:userIds) "; } if (!dto.getActualOrderNo().isEmpty()) { - query+="AND actual_order_no = :actualOrderNo "; + dto.setActualOrderNo(dto.getActualOrderNo()+"%"); + query+="AND ro.actual_order_no LIKE (:actualOrderNo) "; } Map params = new HashMap<>(); @@ -65,14 +66,15 @@ public class JdbcConsumptionDetailRepositoryImpl implements JdbcConsumptionDetai .of(dto.getPageNum() - 1, dto.getPageSize(), Sort.by("create_time").descending()); params.put("actualOrderNo", dto.getActualOrderNo()); params.put("userIds", dto.getUserIds()); - params.put("routeIds", dto.getRouteIds()); + params.put("companyCodes", dto.getCompanyCodes()); params.put("offset", pageRequest.getOffset()); params.put("limit", pageRequest.getPageSize()); - String pagedQuery = query + " LIMIT :limit OFFSET :offset"; - + String pagedQuery ="SELECT * FROM route_order ro "+ query + " LIMIT :limit OFFSET :offset"; List results = jdbcTemplate.query(pagedQuery, params, BeanPropertyRowMapper.newInstance(ItineraryPageDto.class)); - long count = jdbcTemplate.queryForObject("SELECT COUNT(*) FROM (" + query + ") AS count", params, Long.class); + + String countQuery="SELECT COUNT(*) FROM route_order ro "+query; + long count = jdbcTemplate.queryForObject(countQuery, params, Long.class); return new PageImpl<>(results, pageRequest, count); } @@ -80,10 +82,13 @@ public class JdbcConsumptionDetailRepositoryImpl implements JdbcConsumptionDetai @Override public PageResult pageConsumptionDetail(ConsumptionDetailQuery dto) { //数据权限 - List orderIds=baseUtil.getOrderIds(); - if (orderIds==null||orderIds.isEmpty()) { +// List orderIds=baseUtil.getOrderIds(); + List companyCodes =baseUtil.getCompanyCode(); + if (companyCodes==null||companyCodes.isEmpty()) { return PageResult.totalPageNum(0, new ArrayList<>()); } + dto.setCompanyCodes(companyCodes); + Page data=new PageImpl<>(Collections.emptyList()); //申请单查询 if (!dto.getActualOrderNo().isEmpty()){ @@ -105,53 +110,66 @@ public class JdbcConsumptionDetailRepositoryImpl implements JdbcConsumptionDetai private Page trainPageConsumptionDetail(ConsumptionDetailQuery dto){ - String query = "SELECT * FROM train_order_detail " - + "WHERE 1=1 "; + String query = "LEFT JOIN order_detail od ON tod.order_id=od.order_id " + + "LEFT JOIN route_order_extension_field roef ON roef.route_id=od.route_id "+ + "WHERE 1=1 "; Map params = new HashMap<>(); PageRequest pageRequest = PageRequest .of(dto.getPageNum() - 1, dto.getPageSize(), Sort.by("create_time").descending()); query = getString(dto, query, params, pageRequest); - String pagedQuery = query + " LIMIT :limit OFFSET :offset"; - long count = jdbcTemplate.queryForObject("SELECT COUNT(*) FROM (" + query + ") AS count", params, Long.class); + String pagedQuery ="SELECT * FROM train_order_detail tod " + + query + " LIMIT :limit OFFSET :offset"; List results = jdbcTemplate.query(pagedQuery, params, BeanPropertyRowMapper.newInstance(TrainOrderDetailExcel.class)); + + String countQuery = "SELECT COUNT(*) FROM train_order_detail tod " + query; + long count = jdbcTemplate.queryForObject(countQuery, params, Long.class); return new PageImpl<>(results, pageRequest, count); } private Page flightPageConsumptionDetail(ConsumptionDetailQuery dto){ - String query = "SELECT * FROM flight_order_detail " - + "WHERE 1=1 "; + String query = "LEFT JOIN order_detail od ON tod.order_id=od.order_id " + + "LEFT JOIN route_order_extension_field roef ON roef.route_id=od.route_id "+ + "WHERE 1=1 "; Map params = new HashMap<>(); PageRequest pageRequest = PageRequest .of(dto.getPageNum() - 1, dto.getPageSize(), Sort.by("create_time").descending()); query = getString(dto, query, params, pageRequest); - String pagedQuery = query + " LIMIT :limit OFFSET :offset"; - long count = jdbcTemplate.queryForObject("SELECT COUNT(*) FROM (" + query + ") AS count", params, Long.class); + String pagedQuery ="SELECT * FROM flight_order_detail tod " + + query + " LIMIT :limit OFFSET :offset"; List results = jdbcTemplate.query(pagedQuery, params, BeanPropertyRowMapper.newInstance(FlightOrderDetailExcel.class)); + + String countQuery = "SELECT COUNT(*) FROM flight_order_detail tod " + query; + long count = jdbcTemplate.queryForObject(countQuery, params, Long.class); return new PageImpl<>(results, pageRequest, count); } private Page hotelPageConsumptionDetail(ConsumptionDetailQuery dto){ - String query = "SELECT * FROM hotel_order_detail " - + "WHERE 1=1 "; + String query = "LEFT JOIN order_detail od ON tod.order_id=od.order_id " + + "LEFT JOIN route_order_extension_field roef ON roef.route_id=od.route_id "+ + "WHERE 1=1 "; Map params = new HashMap<>(); PageRequest pageRequest = PageRequest .of(dto.getPageNum() - 1, dto.getPageSize(), Sort.by("create_time").descending()); query = getString(dto, query, params, pageRequest); - String pagedQuery = query + " LIMIT :limit OFFSET :offset"; - long count = jdbcTemplate.queryForObject("SELECT COUNT(*) FROM (" + query + ") AS count", params, Long.class); + String pagedQuery ="SELECT * FROM hotel_order_detail tod " + + query + " LIMIT :limit OFFSET :offset"; List results = jdbcTemplate.query(pagedQuery, params, BeanPropertyRowMapper.newInstance(HotelOrderDetailExcel.class)); + + String countQuery = "SELECT COUNT(*) FROM hotel_order_detail tod " + query; + long count = jdbcTemplate.queryForObject(countQuery, params, Long.class); return new PageImpl<>(results, pageRequest, count); } private Page carPageConsumptionDetail(ConsumptionDetailQuery dto){ - String query = "SELECT * FROM car_order_detail " - + "WHERE 1=1 "; + String query = "LEFT JOIN order_detail od ON tod.order_id=od.order_id " + + "LEFT JOIN route_order_extension_field roef ON roef.route_id=od.route_id "+ + "WHERE 1=1 "; Map params = new HashMap<>(); PageRequest pageRequest = PageRequest @@ -159,29 +177,32 @@ public class JdbcConsumptionDetailRepositoryImpl implements JdbcConsumptionDetai query = getString(dto, query, params, pageRequest); - String pagedQuery = query + " LIMIT :limit OFFSET :offset"; - long count = jdbcTemplate.queryForObject("SELECT COUNT(*) FROM (" + query + ") AS count", params, Long.class); + String pagedQuery ="SELECT * FROM car_order_detail tod " + + query + " LIMIT :limit OFFSET :offset"; List results = jdbcTemplate.query(pagedQuery, params, BeanPropertyRowMapper.newInstance(CarOrderDetailExcel.class)); + + String countQuery = "SELECT COUNT(*) FROM car_order_detail tod " + query; + long count = jdbcTemplate.queryForObject(countQuery, params, Long.class); return new PageImpl<>(results, pageRequest, count); } private static String getString(ConsumptionDetailQuery dto, String query, Map params, PageRequest pageRequest) { if (!dto.getUserName().isEmpty()) { dto.setUserName(dto.getUserName()+"%"); - query +="AND user_name LIKE (:userName)"; + query +="AND tod.user_name LIKE (:userName)"; } - if (!dto.getOrderIds().isEmpty()) { - query +="AND order_id IN (:orderIds)"; + if (!dto.getCompanyCodes().isEmpty()) { + query +="AND roef.company_code IN (:companyCodes)"; } if (!dto.getOrderNos().isEmpty()) { - query +="AND order_no IN (:orderNos)"; + query +="AND tod.order_no IN (:orderNos)"; } params.put("userName", dto.getUserName()); params.put("orderNos", dto.getOrderNos()); - params.put("orderIds", dto.getOrderIds()); + params.put("companyCodes", dto.getCompanyCodes()); params.put("offset", pageRequest.getOffset()); params.put("limit", pageRequest.getPageSize()); diff --git a/src/main/java/com/chint/manage/mapper/impl/ManageOrderDetailRepositoryImpl.java b/src/main/java/com/chint/manage/mapper/impl/ManageOrderDetailRepositoryImpl.java new file mode 100644 index 00000000..1764c7aa --- /dev/null +++ b/src/main/java/com/chint/manage/mapper/impl/ManageOrderDetailRepositoryImpl.java @@ -0,0 +1,91 @@ +package com.chint.manage.mapper.impl; + +import com.chint.manage.entity.OrderDetailBasic; +import com.chint.manage.entity.OrderExceedStandard; +import com.chint.manage.entity.RouteOrderExtensionFieldBasic; +import com.chint.manage.entity.query.StandardQuery; +import com.chint.manage.mapper.ManageOrderDetailRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Sort; +import org.springframework.jdbc.core.BeanPropertyRowMapper; +import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; +import org.springframework.stereotype.Repository; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Repository +public class ManageOrderDetailRepositoryImpl implements ManageOrderDetailRepository { + + @Autowired + private NamedParameterJdbcTemplate jdbcTemplate; + + @Override + public List orderDetailBasicList(List routeIds) { + String query = "SELECT * FROM order_detail WHERE route_id IN (:routeIds)"; + Map params = new HashMap<>(); + params.put("routeIds", routeIds); + List results = jdbcTemplate.query(query, params, BeanPropertyRowMapper.newInstance(OrderDetailBasic.class)); + + return results; + } + + + @Override + public Page OrderExceedStandard(StandardQuery dto) { + String query ="LEFT JOIN order_detail od ON oes.order_no=od.order_no " + + "LEFT JOIN route_order_extension_field roef ON roef.route_id=od.route_id " + + "WHERE 1=1 "; + if (!dto.getApplicant().isEmpty()) { + dto.setApplicant(dto.getApplicant()+"%"); + query+="AND oes.applicat LIKE (:applicat) "; + } + + if (!dto.getOrderNo().isEmpty()) { + query+="AND oes.order_no LIKE (:orderNo) "; + } + + if (!dto.getActualOrderNo().isEmpty()) { + query+="AND oes.actual_order_no LIKE (:actualOrderNo) "; + } + + if (!dto.getCompanyName().isEmpty()) { + query+="AND oes.company_name LIKE (:companyName) "; + } + + if (!dto.getCompanyCods().isEmpty()) { + query+="AND roef.company_code IN (:companyCods) "; + } + + Map params = new HashMap<>(); + PageRequest pageRequest = PageRequest + .of(dto.getPageNum() - 1, dto.getPageSize(), Sort.by("id").descending()); + params.put("actualOrderNo", dto.getActualOrderNo()); + params.put("applicat", dto.getApplicant()); + params.put("companyName", dto.getCompanyName()); + params.put("companyCods", dto.getCompanyCods()); + params.put("orderNo", dto.getOrderNo()); + params.put("offset", pageRequest.getOffset()); + params.put("limit", pageRequest.getPageSize()); + + String pagedQuery ="SELECT * FROM order_exceed_standard oes "+ query + " LIMIT :limit OFFSET :offset"; + List results = jdbcTemplate.query(pagedQuery, params, BeanPropertyRowMapper.newInstance(OrderExceedStandard.class)); + + String countSql="SELECT COUNT(*) AS count FROM order_exceed_standard oes " + query ; + long count = jdbcTemplate.queryForObject(countSql, params, Long.class); + + return new PageImpl<>(results, pageRequest, count); + } + + @Override + public List findAll() { + Map params = new HashMap<>(); + List results = jdbcTemplate.query("select distinct(company_code) from route_order_extension_field", params, BeanPropertyRowMapper.newInstance(RouteOrderExtensionFieldBasic.class)); + return results; + } + +} diff --git a/src/main/java/com/chint/manage/service/impl/ManageServiceImpl.java b/src/main/java/com/chint/manage/service/impl/ManageServiceImpl.java index a057fa04..d9ce38b4 100644 --- a/src/main/java/com/chint/manage/service/impl/ManageServiceImpl.java +++ b/src/main/java/com/chint/manage/service/impl/ManageServiceImpl.java @@ -15,7 +15,9 @@ import com.chint.manage.entity.OrderDetailBasic; import com.chint.manage.entity.OrderDownloadRecord; import com.chint.manage.entity.OrderExceedStandard; import com.chint.manage.entity.RouteOrderExtensionFieldBasic; +import com.chint.manage.entity.business.LegItinerary; import com.chint.manage.entity.dto.ItineraryPageDto; +import com.chint.manage.entity.business.RouteOrderItinerary; import com.chint.manage.entity.excel.OrderPageExcel; import com.chint.manage.entity.excel.BaseExcel; import com.chint.manage.entity.excel.OrderExceedStandardExcel; @@ -31,8 +33,6 @@ import com.chint.manage.util.ExcelUtil; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Sort; import org.springframework.stereotype.Service; import java.io.File; @@ -61,6 +61,8 @@ public class ManageServiceImpl implements ManageService { @Autowired private JdbcRouteRepository jdbcRouteRepository; @Autowired + private JdbcRouteOrderItineraryRepository jdbcRouteOrderItineraryRepository; + @Autowired private JdbcUserRepository jdbcUserRepository; @Autowired private JdbcOrderDownloadRecordRepository jdbcOrderDownloadRecordRepository; @@ -80,6 +82,8 @@ public class ManageServiceImpl implements ManageService { private JdbcHotelOrderDetailRepository jdbcHotelOrderDetailRepository; @Autowired private JdbcCarOrderDetailRepository jdbcCarOrderDetailRepository; + @Autowired + private ManageOrderDetailRepository manageOrderDetailRepository; @Override public PageResult pageConsumptionDetail(ConsumptionDetailQuery dto) { @@ -98,19 +102,12 @@ public class ManageServiceImpl implements ManageService { @Override public PageResult standardQuery(StandardQuery dto) { //数据权限 - List orderNos=baseUtil.getOrderNos(); - if (orderNos==null||orderNos.isEmpty()) { + List companyCods=baseUtil.getCompanyCode(); + if (companyCods==null||companyCods.isEmpty()) { return PageResult.totalPageNum(0, new ArrayList<>()); } - - PageRequest pageRequest = PageRequest - .of(dto.getPageNum() - 1, dto.getPageSize(), Sort.by("id").descending()); - Page page=jdbcOrderExceedStandardRepository.findAllByApplicantContainsAndDeptNameContainsAndActualOrderNoContainsAndOrderNoContainsAndOrderNoIn(dto.getApplicant(), - dto.getCompanyName(), - dto.getActualOrderNo(), - dto.getOrderNo(), - orderNos, - pageRequest); + dto.setCompanyCods(companyCods); + Page page=manageOrderDetailRepository.OrderExceedStandard(dto); List excelList = getOrderExceedStandardExcels(page); return PageResult.totalPageNum(page.getTotalElements(), excelList); } @@ -127,11 +124,11 @@ public class ManageServiceImpl implements ManageService { @Override public PageResult itineraryPageQuery(ItineraryPageQuery dto) { //数据权限 - List routeIds=baseUtil.getRouteIds(); - if (routeIds==null||routeIds.isEmpty()) { + List companyCodes=baseUtil.getCompanyCode(); + if (companyCodes==null||companyCodes.isEmpty()) { return PageResult.totalPageNum(0, new ArrayList<>()); } - dto.setRouteIds(routeIds); + dto.setCompanyCodes(companyCodes); List users=new ArrayList<>(); if (!dto.getApplicant().isEmpty()){ @@ -146,13 +143,13 @@ public class ManageServiceImpl implements ManageService { List list=page.getContent(); //查询行程和审批单信息 List routeIdList=list.stream().map(ItineraryPageDto::getRouteId).toList(); - List routeOrders=jdbcRouteRepository.findByRouteIdIn(routeIdList); + List routeOrders=jdbcRouteOrderItineraryRepository.findByRouteIdIn(routeIdList); List orders = list .stream() .map(routeOrder -> { - RouteOrder order=routeOrders.stream().filter(s->s.getRouteId().equals(routeOrder.getRouteId())).toList().get(0); - legDomainService.queryLocation(order.getLegItems()); + RouteOrderItinerary order=routeOrders.stream().filter(s->s.getRouteId().equals(routeOrder.getRouteId())).toList().get(0); + legDomainService.queryLocationByLeg(order.getLegItems()); routeOrder.setApprovalStatus(routeOrder.getApprovalStatus(order.getApproveEvents())); User user = userRepository.findByUserEmployeeNo(routeOrder.getUserId()); return getRouteOrderPageRes(routeOrder, user,order.getLegItems()); @@ -177,11 +174,11 @@ public class ManageServiceImpl implements ManageService { @Override public PageResult orderPageQuery(OrderPageQuery dto) { //数据权限 - List dataRouteIds=baseUtil.getRouteIds(); - if (dataRouteIds==null||dataRouteIds.isEmpty()) { + List companyCodes=baseUtil.getCompanyCode(); + if (companyCodes==null||companyCodes.isEmpty()) { return PageResult.totalPageNum(0, new ArrayList<>()); } - dto.setRouteIds(dataRouteIds); + dto.setCompanyCodes(companyCodes); //预订人 if (!dto.getApplicant().equals("")){ @@ -360,7 +357,7 @@ public class ManageServiceImpl implements ManageService { return excelList; } - private static ItineraryPageDto getRouteOrderPageRes(ItineraryPageDto res, User user,List legItems) { + private static ItineraryPageDto getRouteOrderPageRes(ItineraryPageDto res, User user,List legItems) { List locationRes = legItems .stream() .flatMap(leg -> Stream.of(leg.getOriginLocation(), leg.getDestinationLocation())) diff --git a/src/main/java/com/chint/manage/util/BaseUtil.java b/src/main/java/com/chint/manage/util/BaseUtil.java index f413332c..8d484446 100644 --- a/src/main/java/com/chint/manage/util/BaseUtil.java +++ b/src/main/java/com/chint/manage/util/BaseUtil.java @@ -2,10 +2,6 @@ package com.chint.manage.util; import com.chint.domain.aggregates.user.User; import com.chint.infrastructure.util.BaseContext; -import com.chint.manage.entity.RouteOrderExtensionFieldBasic; -import com.chint.manage.mapper.JdbcOrderDetailBasicRepository; -import com.chint.manage.mapper.JdbcRouteOrderExtensionFieldBasicRepository; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.List; @@ -18,32 +14,16 @@ import java.util.Objects; */ @Component public class BaseUtil { - @Autowired - private JdbcRouteOrderExtensionFieldBasicRepository jdbcRouteOrderExtensionFieldBasicRepository; - @Autowired - private JdbcOrderDetailBasicRepository jdbcOrderDetailBasicRepository; public User getCurrentUser() { return BaseContext.getCurrentUser(); } - public List getRouteIds(){ + + public List getCompanyCode(){ List list = BaseContext.getCurrentUser().loadRoleOrg().getRoleOrgCodeList().stream().filter(Objects::nonNull).toList(); if (list.isEmpty()) return null; - List result= jdbcRouteOrderExtensionFieldBasicRepository.findAllByCompanyCodeIn(list); - return result.stream().map(RouteOrderExtensionFieldBasic::getRouteId).toList(); - } - - public List getOrderIds(){ - List routeIds = getRouteIds(); - if (routeIds==null||routeIds.isEmpty()) return null; - return jdbcOrderDetailBasicRepository.findAllOrderId(routeIds); - } - - public List getOrderNos(){ - List routeIds = getRouteIds(); - if (routeIds==null||routeIds.isEmpty()) return null; - return jdbcOrderDetailBasicRepository.findAllOrderNo(routeIds); + return list; } /** diff --git a/src/main/java/com/chint/manage/util/DataJdbcCreatorUtil.java b/src/main/java/com/chint/manage/util/DataJdbcCreatorUtil.java index 0d7a1b40..cdfe7913 100644 --- a/src/main/java/com/chint/manage/util/DataJdbcCreatorUtil.java +++ b/src/main/java/com/chint/manage/util/DataJdbcCreatorUtil.java @@ -16,7 +16,9 @@ import java.util.Map; public class DataJdbcCreatorUtil { //package路径 - private final String prefix="com.chint.manage"; + private final String PREFIX="com.chint.manage"; + + private final String BUSINESS="Itinerary"; public static void main(String[] args) { try { @@ -39,7 +41,7 @@ public class DataJdbcCreatorUtil { */ private List getTables() throws SQLException { List tables = new ArrayList(); - tables.add("crux_system_log"); + tables.add("leg"); return tables; } @@ -98,13 +100,13 @@ public class DataJdbcCreatorUtil { /** * package路径 */ - private final String bean_package = prefix+".entity"; + private final String bean_package = PREFIX+".entity"; - private final String mapper_package = prefix+".mapper"; + private final String mapper_package = PREFIX+".mapper"; - private final String service_package = prefix+".service"; + private final String service_package = PREFIX+".service"; - private final String service_impl_package = prefix+".service.impl"; + private final String service_impl_package = PREFIX+".service.impl"; /** * 数据库 @@ -149,7 +151,7 @@ public class DataJdbcCreatorUtil { temp = tables[i].trim(); sb.append(temp.substring(0, 1).toUpperCase()).append(temp.substring(1)); } - beanName = sb.toString()+"Basic"; + beanName = sb.toString()+BUSINESS; mapperName = "Jdbc"+beanName + "Repository"; _mapperName = shotFirst(mapperName); serviceName = beanName + "Service";