diff --git a/src/main/java/com/chint/application/dtos/response/UserRes.java b/src/main/java/com/chint/application/dtos/response/UserRes.java index b837eb4a..f550a6e3 100644 --- a/src/main/java/com/chint/application/dtos/response/UserRes.java +++ b/src/main/java/com/chint/application/dtos/response/UserRes.java @@ -21,6 +21,5 @@ public class UserRes { private String rankCode; private String companyCode; private String workStatus; - private List roleOrgList; private List roleList; } diff --git a/src/main/java/com/chint/domain/aggregates/user/User.java b/src/main/java/com/chint/domain/aggregates/user/User.java index b2702496..34b3b542 100644 --- a/src/main/java/com/chint/domain/aggregates/user/User.java +++ b/src/main/java/com/chint/domain/aggregates/user/User.java @@ -82,8 +82,6 @@ public class User implements Serializable { @Transient private List roleOrgCodeList; @Transient - private List roleOrgList; - @Transient private List roleList; public User loadInfoFromDept() { diff --git a/src/main/java/com/chint/domain/repository/SystemOrganizationRepository.java b/src/main/java/com/chint/domain/repository/SystemOrganizationRepository.java index fd6c7573..5047f8c1 100644 --- a/src/main/java/com/chint/domain/repository/SystemOrganizationRepository.java +++ b/src/main/java/com/chint/domain/repository/SystemOrganizationRepository.java @@ -28,4 +28,6 @@ public interface SystemOrganizationRepository { List expandOrganizations(List systemOrganizations); Optional findByOrgCodeContainingOrOrgNameContaining(String orgCode, String orgName); + + List queryOrgCodeListByUserId(Long userId); } diff --git a/src/main/java/com/chint/domain/service/BPMOrderDomainService.java b/src/main/java/com/chint/domain/service/BPMOrderDomainService.java index aecf4e4a..be80a60b 100644 --- a/src/main/java/com/chint/domain/service/BPMOrderDomainService.java +++ b/src/main/java/com/chint/domain/service/BPMOrderDomainService.java @@ -122,7 +122,7 @@ public class BPMOrderDomainService { //保存超标报表 OrderExceedStandard orderExceedStandard = OrderExceedStandard.builder() .applicant(orderDetail.getSupplierName()) - .companyName(user.getCompanyName()) + .companyName(user.getDepartmentInfo().getCompanyName()) .deptName(user.getDepartmentInfo().getDepartmentNameOne()) .standardType(getProductTypeName(command.getProductType())) .sourceName(anExceedStandardDto.getSourceSystem()) @@ -161,7 +161,7 @@ public class BPMOrderDomainService { //保存超标报表 OrderExceedStandard orderExceedStandard = OrderExceedStandard.builder() .applicant(orderDetail.getSupplierName()) - .companyName(user.getCompanyName()) + .companyName(user.getDepartmentInfo().getCompanyName()) .deptName(user.getDepartmentInfo().getDepartmentNameOne()) .standardType(getProductTypeName(command.getProductType())) .sourceName(exceedStandardDto.getOrderSource()) diff --git a/src/main/java/com/chint/infrastructure/config/LogConfig/CruxLogInterceptor.java b/src/main/java/com/chint/infrastructure/config/LogConfig/CruxLogInterceptor.java new file mode 100644 index 00000000..22746f10 --- /dev/null +++ b/src/main/java/com/chint/infrastructure/config/LogConfig/CruxLogInterceptor.java @@ -0,0 +1,72 @@ +package com.chint.infrastructure.config.LogConfig; + +import com.chint.domain.aggregates.user.User; +import com.chint.infrastructure.util.BaseContext; +import com.chint.manage.entity.CruxSystemLogBasic; +import com.chint.manage.mapper.JdbcCruxSystemLogBasicRepository; +import com.chint.manage.util.IpAddressUtil; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.web.servlet.HandlerInterceptor; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.Objects; + +@Slf4j +@Component +public class CruxLogInterceptor implements HandlerInterceptor { + + @Autowired + private JdbcCruxSystemLogBasicRepository jdbcCruxSystemLogBasicRepository; + @Autowired + private IpAddressUtil ipAddressUtil; + + + @Override + public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception { + // 在请求处理之前进行拦截 + // 获取请求IP + String clientIP = ipAddressUtil.getIpAddress(request); + // 获取请求URL + String url = request.getRequestURL().toString(); + // 获取请求方法 + String method = request.getMethod(); + // 获取url中的请求参数 + String params = request.getQueryString() == null ? "" : request.getQueryString(); + //请求体数据 + String requestBody = ""; + if ("POST".equals(method)) { + requestBody = ContentCachingWrapperFilter.getRequestBody(request); + } + requestBody = requestBody.replaceAll("\\s+", ""); + + //如果有,获取用户 + User user = BaseContext.getCurrentUser(); + String employeeNo = ""; + String name = ""; + if (!Objects.isNull(user)) { + employeeNo = user.getEmployeeNo(); + name = user.getName(); + } + LocalDateTime now = LocalDateTime.now(); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + String accessTime = now.format(formatter); + + //构建对象 + CruxSystemLogBasic systemLog = CruxSystemLogBasic.builder() + .clientIp(clientIP) + .url(url) + .method(method) + .params(params) + .requestBody(requestBody) + .employeeNo(employeeNo) + .name(name) + .accessTime(accessTime).build(); + jdbcCruxSystemLogBasicRepository.save(systemLog); + + } +} \ No newline at end of file diff --git a/src/main/java/com/chint/infrastructure/config/webconfig/WebConfig.java b/src/main/java/com/chint/infrastructure/config/webconfig/WebConfig.java index 7cbded34..f7ca609f 100644 --- a/src/main/java/com/chint/infrastructure/config/webconfig/WebConfig.java +++ b/src/main/java/com/chint/infrastructure/config/webconfig/WebConfig.java @@ -1,10 +1,9 @@ package com.chint.infrastructure.config.webconfig; +import com.chint.infrastructure.config.LogConfig.CruxLogInterceptor; import com.chint.infrastructure.config.LogConfig.RequestLoggingInterceptor; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.web.servlet.HandlerInterceptor; import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @@ -24,6 +23,14 @@ public class WebConfig implements WebMvcConfigurer { return new RequestLoggingInterceptor(); } + /** + * 关键接口日志记录 + */ + @Bean + public CruxLogInterceptor getCruxLogInterceptor() { + return new CruxLogInterceptor(); + } + @Override public void addInterceptors(InterceptorRegistry registry) { registry.addInterceptor(new JwtTokenAdminInterceptor()) @@ -35,6 +42,14 @@ public class WebConfig implements WebMvcConfigurer { registry.addInterceptor(getMyRequestLoggingInterceptor()) .addPathPatterns("/**") .excludePathPatterns("/location/**", "/**/query/**", "/**/pageQuery/**"); + //关键接口日志记录 + registry.addInterceptor(getCruxLogInterceptor()) + //报表 + .addPathPatterns("/manage/consumption/export","/manage/standard/export","/manage/order/export", + //公告 + "/system/announcement/save","/system/announcement/update", + //权限 + "/users/add/role","/users/edit/role"); } @Override diff --git a/src/main/java/com/chint/infrastructure/repository/RoleRepositoryImpl.java b/src/main/java/com/chint/infrastructure/repository/RoleRepositoryImpl.java index dd55677e..467b64e6 100644 --- a/src/main/java/com/chint/infrastructure/repository/RoleRepositoryImpl.java +++ b/src/main/java/com/chint/infrastructure/repository/RoleRepositoryImpl.java @@ -20,6 +20,7 @@ import org.springframework.data.domain.Sort; import org.springframework.stereotype.Repository; import java.util.List; +import java.util.Objects; import java.util.Optional; @Repository @@ -94,43 +95,56 @@ public class RoleRepositoryImpl implements RoleRepository { Long userId = user.getUserId(); List orgCodeList = cacheRoleRepository .roleOrgCodeList(userId, null); - List systemOrganizationVOList = cacheRoleRepository - .roleOrgList(userId, null); - - if (systemOrganizationVOList == null || systemOrganizationVOList.isEmpty() || - orgCodeList == null || orgCodeList.isEmpty()) { - List roleList = user.getRoleList(); - List orgListId = roleList - .stream() - .flatMap(role -> role.getRoleOrganizationList().stream()) - .map(RoleOrganization::getOrgId) - .distinct() - .toList(); - - // 获取所有的 SystemOrganization - List rootOrganizations = systemOrganizationRepository.findByIdIn(orgListId); - - // 展开所有的 SystemOrganization - rootOrganizations = systemOrganizationRepository.expandOrganizations(rootOrganizations); - - orgCodeList = rootOrganizations.stream() - .map(SystemOrganization::getOrgShortCode) - .distinct() - .toList(); - - systemOrganizationVOList = rootOrganizations.stream() - .map(SystemOrganization::mapToVO) - .distinct() - .toList(); - + if (orgCodeList == null) { + orgCodeList=systemOrganizationRepository.queryOrgCodeListByUserId(userId); + if (!orgCodeList.isEmpty()) { + orgCodeList=orgCodeList.stream().filter(Objects::nonNull).toList(); + } cacheRoleRepository.evictRoleOrgCodeList(userId); cacheRoleRepository.roleOrgCodeList(userId, orgCodeList); - cacheRoleRepository.evictRoleOrgList(userId); - cacheRoleRepository.roleOrgList(userId, systemOrganizationVOList); } - - // 设置用户的角色组织列表 user.setRoleOrgCodeList(orgCodeList); - user.setRoleOrgList(systemOrganizationVOList); + + +// List orgCodeList = cacheRoleRepository +// .roleOrgCodeList(userId, null); +// List systemOrganizationVOList = cacheRoleRepository +// .roleOrgList(userId, null); +// +// if (systemOrganizationVOList == null || systemOrganizationVOList.isEmpty() || +// orgCodeList == null || orgCodeList.isEmpty()) { +// List roleList = user.getRoleList(); +// List orgListId = roleList +// .stream() +// .flatMap(role -> role.getRoleOrganizationList().stream()) +// .map(RoleOrganization::getOrgId) +// .distinct() +// .toList(); +// +// // 获取所有的 SystemOrganization +// List rootOrganizations = systemOrganizationRepository.findByIdIn(orgListId); +// +// // 展开所有的 SystemOrganization +// rootOrganizations = systemOrganizationRepository.expandOrganizations(rootOrganizations); +// +// orgCodeList = rootOrganizations.stream() +// .map(SystemOrganization::getOrgShortCode) +// .distinct() +// .toList(); +// +// systemOrganizationVOList = rootOrganizations.stream() +// .map(SystemOrganization::mapToVO) +// .distinct() +// .toList(); +// +// cacheRoleRepository.evictRoleOrgCodeList(userId); +// cacheRoleRepository.roleOrgCodeList(userId, orgCodeList); +// cacheRoleRepository.evictRoleOrgList(userId); +// cacheRoleRepository.roleOrgList(userId, systemOrganizationVOList); +// } +// +// // 设置用户的角色组织列表 +// user.setRoleOrgCodeList(orgCodeList); +// user.setRoleOrgList(systemOrganizationVOList); } } diff --git a/src/main/java/com/chint/infrastructure/repository/SystemOrganizationRepositoryImpl.java b/src/main/java/com/chint/infrastructure/repository/SystemOrganizationRepositoryImpl.java index 39e7e38b..f6a701ce 100644 --- a/src/main/java/com/chint/infrastructure/repository/SystemOrganizationRepositoryImpl.java +++ b/src/main/java/com/chint/infrastructure/repository/SystemOrganizationRepositoryImpl.java @@ -139,6 +139,11 @@ public class SystemOrganizationRepositoryImpl implements SystemOrganizationRepos .findFirst(); } + @Override + public List queryOrgCodeListByUserId(Long userId) { + return jdbcSystemOrganizationRepository.queryOrgCodeListByUserId(userId); + } + private void expandOrganizationRecursively(SystemOrganization org, List allOrganizations) { if (org == null) { diff --git a/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcOrderDetailRepository.java b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcOrderDetailRepository.java index 1889fff8..de97009d 100644 --- a/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcOrderDetailRepository.java +++ b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcOrderDetailRepository.java @@ -6,6 +6,7 @@ import com.chint.manage.entity.query.OrderPageQuery; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; +import org.springframework.data.jdbc.repository.query.Modifying; import org.springframework.data.jdbc.repository.query.Query; import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.query.Param; @@ -32,26 +33,4 @@ public interface JdbcOrderDetailRepository extends CrudRepository findByCreateTimeBetweenAndProductType(LocalDateTime createTime, LocalDateTime createTime2, Integer productType); List findByCreateTimeBetweenAndProductTypeAndOrderNoContaining(LocalDateTime createTime, LocalDateTime createTime2, Integer productType, String orderNo); List findByUpdateTimeBetween(LocalDateTime createTime, LocalDateTime createTime2); - - List findAllByRouteIdIn(List routeIds); - - - @Query("SELECT * FROM order_detail " + - "WHERE route_id IN (:#{#dto.routeIds}) " + - "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}))" + - "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}) " + - "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}))") - Integer countByCondition(@Param("dto") OrderPageQuery dto); } diff --git a/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcSystemOrganizationRepository.java b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcSystemOrganizationRepository.java index ff1eaba1..b899ff8d 100644 --- a/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcSystemOrganizationRepository.java +++ b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcSystemOrganizationRepository.java @@ -1,6 +1,7 @@ package com.chint.infrastructure.repository.jdbc; import com.chint.domain.aggregates.system.SystemOrganization; +import org.springframework.data.jdbc.repository.query.Query; import org.springframework.data.repository.CrudRepository; import org.springframework.stereotype.Repository; @@ -15,5 +16,11 @@ public interface JdbcSystemOrganizationRepository extends CrudRepository findByOrgLevelIsNullOrOrgLevel(String orgLevel); List findByOrgShortCodeIn(Collection orgCode); List findByIdIn(Collection id); + + @Query("select so.org_short_code from role_organization ro,system_organization so,role_user ru " + + "where ro.org_id = so.id " + + "and ro.role_id = ru.role_id " + + "and ru.user_id = :#{#userId}") + List queryOrgCodeListByUserId(Long userId); List findByOrgName(String orgName); } diff --git a/src/main/java/com/chint/manage/entity/CruxSystemLogBasic.java b/src/main/java/com/chint/manage/entity/CruxSystemLogBasic.java new file mode 100644 index 00000000..5d47bce2 --- /dev/null +++ b/src/main/java/com/chint/manage/entity/CruxSystemLogBasic.java @@ -0,0 +1,53 @@ +package com.chint.manage.entity; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.springframework.data.annotation.Id; +import org.springframework.data.relational.core.mapping.Table; +import java.io.Serial; +import java.io.Serializable; + +/** + * + * @author xx CruxSystemLogBasic.java + * + **/ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +@Table("crux_system_log") +public class CruxSystemLogBasic implements Serializable { +@Serial +private static final long serialVersionUID = 1L; + @Id + private Integer id; + + /**员工SF号**/ + private String employeeNo; + + /**员工姓名**/ + private String name; + + /**访问时间**/ + private String accessTime; + + /**请求IP**/ + private String clientIp; + + /**请求路径**/ + private String url; + + /**请求方法**/ + private String method; + + /**参数**/ + private String params; + + /**请求体**/ + private String requestBody; + + +} diff --git a/src/main/java/com/chint/manage/entity/OrderDetailBasic.java b/src/main/java/com/chint/manage/entity/OrderDetailBasic.java new file mode 100644 index 00000000..dd9cf6c9 --- /dev/null +++ b/src/main/java/com/chint/manage/entity/OrderDetailBasic.java @@ -0,0 +1,79 @@ +package com.chint.manage.entity; + +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; +import java.time.LocalDateTime; + +/** + * + * @author xx OrderDetailBasic.java + * + **/ +@Data +@Table("order_detail") +public class OrderDetailBasic implements Serializable { + @Serial + private static final long serialVersionUID = 1L; + @Id + private Long orderId; + + /****/ + private Long routeId; + + /****/ + private Long routeOrderKey; + + /****/ + private String orderNo; + + /****/ + private LocalDateTime startTime; + + /****/ + private LocalDateTime endTime; + + /****/ + private Long originId; + + /****/ + private Long destinationId; + + /****/ + private String supplierName; + + /**商品类型 0-火车 1飞机 2酒店 3打车 4其他**/ + private Integer productType; + + /****/ + private String price; + + /****/ + private LocalDateTime updateTime; + + /****/ + private LocalDateTime createTime; + + /****/ + private String currencyType; + + /****/ + private LocalDateTime orderDate; + + /****/ + private Long legId; + + /****/ + private Integer quantity; + + /****/ + private String employeeNo; + + /****/ + private Integer ifOrigin; + + +} diff --git a/src/main/java/com/chint/manage/entity/RouteOrderExtensionField.java b/src/main/java/com/chint/manage/entity/RouteOrderExtensionFieldBasic.java similarity index 87% rename from src/main/java/com/chint/manage/entity/RouteOrderExtensionField.java rename to src/main/java/com/chint/manage/entity/RouteOrderExtensionFieldBasic.java index f675445b..49fba22c 100644 --- a/src/main/java/com/chint/manage/entity/RouteOrderExtensionField.java +++ b/src/main/java/com/chint/manage/entity/RouteOrderExtensionFieldBasic.java @@ -13,7 +13,7 @@ import java.io.Serializable; **/ @Data @Table("route_order_extension_field") -public class RouteOrderExtensionField implements Serializable { +public class RouteOrderExtensionFieldBasic implements Serializable { @Serial private static final long serialVersionUID = 1L; /****/ 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 0e6f94f0..c57ff26a 100644 --- a/src/main/java/com/chint/manage/entity/query/ConsumptionDetailQuery.java +++ b/src/main/java/com/chint/manage/entity/query/ConsumptionDetailQuery.java @@ -4,6 +4,9 @@ import com.chint.domain.value_object.BaseQuery; import com.chint.manage.util.BaseUtil; import lombok.Data; +import java.util.ArrayList; +import java.util.List; + /** * * @Author:nxj @@ -17,6 +20,8 @@ public class ConsumptionDetailQuery extends BaseQuery{ private Integer productType; private String userName=""; private String actualOrderNo=""; //申请单号 + private List orderIds=new ArrayList<>(); + private List orderNos=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 4d743c9d..a2b4e568 100644 --- a/src/main/java/com/chint/manage/entity/query/ItineraryPageQuery.java +++ b/src/main/java/com/chint/manage/entity/query/ItineraryPageQuery.java @@ -13,7 +13,7 @@ public class ItineraryPageQuery extends BaseQuery { private String applicant="";// 申请人 private String actualOrderNo=""; //申请单号 private List userIds=new ArrayList<>(); - private List routeIds; + private List routeIds=new ArrayList<>(); public String getActualOrderNo() { diff --git a/src/main/java/com/chint/manage/mapper/JdbcCarOrderDetailRepository.java b/src/main/java/com/chint/manage/mapper/JdbcCarOrderDetailRepository.java index 9ce9e78e..0674ed1b 100644 --- a/src/main/java/com/chint/manage/mapper/JdbcCarOrderDetailRepository.java +++ b/src/main/java/com/chint/manage/mapper/JdbcCarOrderDetailRepository.java @@ -13,11 +13,5 @@ import java.util.List; @Repository public interface JdbcCarOrderDetailRepository extends CrudRepository { - Page findAllByUserNameContainsAndOrderNoContaining(String userName, String orderNo, Pageable pageable); - - Page findAllByUserNameContainsAndOrderNoInAndOrderIdIn(String userName, List orderNo,List orderIds, Pageable pageable); - - Page findAllByUserNameContainsAndOrderIdIn(String userName,List orderIds, Pageable pageable); - List findAllByOrderIdIn(List orderIds); } diff --git a/src/main/java/com/chint/manage/mapper/JdbcCruxSystemLogBasicRepository.java b/src/main/java/com/chint/manage/mapper/JdbcCruxSystemLogBasicRepository.java new file mode 100644 index 00000000..7eb878a5 --- /dev/null +++ b/src/main/java/com/chint/manage/mapper/JdbcCruxSystemLogBasicRepository.java @@ -0,0 +1,15 @@ +package com.chint.manage.mapper; +import com.chint.manage.entity.CruxSystemLogBasic; +import org.springframework.data.repository.CrudRepository; +import org.springframework.stereotype.Repository; + + +/** + * + * @author xx JdbcCruxSystemLogBasicRepository数据库操作接口类 + * + **/ +@Repository +public interface JdbcCruxSystemLogBasicRepository extends CrudRepository { + +} \ No newline at end of file diff --git a/src/main/java/com/chint/manage/mapper/JdbcFlightOrderDetailRepository.java b/src/main/java/com/chint/manage/mapper/JdbcFlightOrderDetailRepository.java index b60bd6e6..b34528d2 100644 --- a/src/main/java/com/chint/manage/mapper/JdbcFlightOrderDetailRepository.java +++ b/src/main/java/com/chint/manage/mapper/JdbcFlightOrderDetailRepository.java @@ -12,11 +12,5 @@ import java.util.List; @Repository public interface JdbcFlightOrderDetailRepository extends CrudRepository { - Page findAllByUserNameContainsAndOrderNoContaining(String userName, String orderNo, Pageable pageable); - - Page findAllByUserNameContainsAndOrderNoInAndOrderIdIn(String userName, List orderNo,List orderIds, Pageable pageable); - - Page findAllByUserNameContainsAndOrderIdIn(String userName,List orderIds, Pageable pageable); - List findAllByOrderIdIn(List orderIds); } diff --git a/src/main/java/com/chint/manage/mapper/JdbcHotelOrderDetailRepository.java b/src/main/java/com/chint/manage/mapper/JdbcHotelOrderDetailRepository.java index da1fe8db..7899649c 100644 --- a/src/main/java/com/chint/manage/mapper/JdbcHotelOrderDetailRepository.java +++ b/src/main/java/com/chint/manage/mapper/JdbcHotelOrderDetailRepository.java @@ -14,11 +14,5 @@ import java.util.List; @Repository public interface JdbcHotelOrderDetailRepository extends CrudRepository { - Page findAllByBookingNameContainsAndOrderNoContaining(String userName, String orderNo, Pageable pageable); - - Page findAllByBookingNameContainsAndOrderNoInAndOrderIdIn(String userName, List orderNo,List orderIds, Pageable pageable); - - Page findAllByBookingNameContainsAndOrderIdIn(String userName,List orderIds, Pageable pageable); - List findAllByOrderIdIn(List orderIds); } diff --git a/src/main/java/com/chint/manage/mapper/JdbcOrderDetailBasicRepository.java b/src/main/java/com/chint/manage/mapper/JdbcOrderDetailBasicRepository.java new file mode 100644 index 00000000..c3e8189d --- /dev/null +++ b/src/main/java/com/chint/manage/mapper/JdbcOrderDetailBasicRepository.java @@ -0,0 +1,59 @@ +package com.chint.manage.mapper; +import com.chint.domain.aggregates.order.OrderDetail; +import com.chint.manage.entity.OrderDetailBasic; +import com.chint.manage.entity.query.OrderPageQuery; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.jdbc.repository.query.Query; +import org.springframework.data.repository.CrudRepository; +import org.springframework.data.repository.query.Param; +import org.springframework.stereotype.Repository; + +import java.util.List; + + +/** + * + * @author xx JdbcOrderDetailBasicRepository数据库操作接口类 + * + **/ +@Repository +public interface JdbcOrderDetailBasicRepository extends CrudRepository { + + List findByRouteIdIn(List routeIds); + + @Query("SELECT order_no FROM order_detail " + + "WHERE route_id IN (:#{#routeIds})") + List findAllOrderNo(@Param("routeIds") List routeIds); + + @Query("SELECT order_id FROM order_detail " + + "WHERE route_id IN (:#{#routeIds})") + List findAllOrderId(@Param("routeIds") List routeIds); + + @Query("SELECT order_no FROM order_detail " ) + List findAllOrderNo(); + + @Query("SELECT order_id FROM order_detail ") + List 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}))" + + "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}))") + Integer countByCondition(@Param("dto") OrderPageQuery dto); +} \ No newline at end of file diff --git a/src/main/java/com/chint/manage/mapper/JdbcOrderExceedStandardRepository.java b/src/main/java/com/chint/manage/mapper/JdbcOrderExceedStandardRepository.java index b7cdff16..22217979 100644 --- a/src/main/java/com/chint/manage/mapper/JdbcOrderExceedStandardRepository.java +++ b/src/main/java/com/chint/manage/mapper/JdbcOrderExceedStandardRepository.java @@ -2,6 +2,7 @@ package com.chint.manage.mapper; import com.chint.manage.entity.OrderExceedStandard; import io.lettuce.core.dynamic.annotation.Param; +import org.jetbrains.annotations.NotNull; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jdbc.repository.query.Modifying; @@ -18,5 +19,8 @@ public interface JdbcOrderExceedStandardRepository extends CrudRepository findAllByApplicantContainsAndCompanyNameContainsAndActualOrderNoContainsAndOrderNoContainsAndOrderNoIn(String applicant, String company, String actualOrderNo, String orderNo, List orderNos, Pageable pageable); + List findAll(); + + Page findAllByApplicantContainsAndDeptNameContainsAndActualOrderNoContainsAndOrderNoContainsAndOrderNoIn(String applicant, String company, String actualOrderNo, String orderNo, List orderNos, Pageable pageable); +//Page findAllByApplicantContainsAndDeptNameContainsAndActualOrderNoContainsAndOrderNoContains(String applicant, String company, String actualOrderNo, String orderNo, Pageable pageable); } diff --git a/src/main/java/com/chint/manage/mapper/JdbcRouteOrderExtensionFieldBasicRepository.java b/src/main/java/com/chint/manage/mapper/JdbcRouteOrderExtensionFieldBasicRepository.java new file mode 100644 index 00000000..79caee82 --- /dev/null +++ b/src/main/java/com/chint/manage/mapper/JdbcRouteOrderExtensionFieldBasicRepository.java @@ -0,0 +1,20 @@ +package com.chint.manage.mapper; +import com.chint.manage.entity.RouteOrderExtensionFieldBasic; +import org.springframework.data.jdbc.repository.query.Query; +import org.springframework.data.repository.CrudRepository; +import org.springframework.data.repository.query.Param; +import org.springframework.stereotype.Repository; + +import java.util.List; + + +/** + * + * @author xx JdbcRouteOrderExtensionFieldRepository数据库操作接口类 + * + **/ +@Repository +public interface JdbcRouteOrderExtensionFieldBasicRepository extends CrudRepository { + + List findAllByBelongDeptCodeIn(@Param("belongDeptCode") List belongDeptCode); +} \ No newline at end of file diff --git a/src/main/java/com/chint/manage/mapper/JdbcRouteOrderExtensionFieldRepository.java b/src/main/java/com/chint/manage/mapper/JdbcRouteOrderExtensionFieldRepository.java deleted file mode 100644 index 84d46b78..00000000 --- a/src/main/java/com/chint/manage/mapper/JdbcRouteOrderExtensionFieldRepository.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.chint.manage.mapper; -import com.chint.manage.entity.RouteOrderExtensionField; -import org.springframework.data.repository.CrudRepository; -import org.springframework.stereotype.Repository; - -import java.util.List; - - -/** - * - * @author xx JdbcRouteOrderExtensionFieldRepository数据库操作接口类 - * - **/ -@Repository -public interface JdbcRouteOrderExtensionFieldRepository extends CrudRepository { - - List findByBelongDeptCodeIn(List belongDeptCode); -} \ No newline at end of file diff --git a/src/main/java/com/chint/manage/mapper/JdbcTrainOrderDetailRepository.java b/src/main/java/com/chint/manage/mapper/JdbcTrainOrderDetailRepository.java index befad4b5..db696b2e 100644 --- a/src/main/java/com/chint/manage/mapper/JdbcTrainOrderDetailRepository.java +++ b/src/main/java/com/chint/manage/mapper/JdbcTrainOrderDetailRepository.java @@ -11,11 +11,5 @@ import java.util.List; @Repository public interface JdbcTrainOrderDetailRepository extends CrudRepository { - Page findAllByUserNameContainsAndOrderNoContaining(String userName, String orderNo, Pageable pageable); - - Page findAllByUserNameContainsAndOrderNoInAndOrderIdIn(String userName, List orderNo,List orderIds ,Pageable pageable); - - Page findAllByUserNameContainsAndOrderIdIn(String userName,List orderIds, Pageable pageable); - List findAllByOrderIdIn(List orderIds); } 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 9fc13b84..57111b14 100644 --- a/src/main/java/com/chint/manage/mapper/impl/JdbcConsumptionDetailRepositoryImpl.java +++ b/src/main/java/com/chint/manage/mapper/impl/JdbcConsumptionDetailRepositoryImpl.java @@ -35,15 +35,6 @@ public class JdbcConsumptionDetailRepositoryImpl implements JdbcConsumptionDetai @Autowired private NamedParameterJdbcTemplate jdbcTemplate; - - @Autowired - private JdbcTrainOrderDetailRepository jdbcTrainOrderDetailRepository; - @Autowired - private JdbcCarOrderDetailRepository jdbcCarOrderDetailRepository; - @Autowired - private JdbcHotelOrderDetailRepository jdbcHotelOrderDetailRepository; - @Autowired - private JdbcFlightOrderDetailRepository jdbcFlightOrderDetailRepository; @Autowired private JdbcRouteRepository jdbcRouteRepository; @Autowired @@ -55,24 +46,26 @@ public class JdbcConsumptionDetailRepositoryImpl implements JdbcConsumptionDetai @Override public Page itineraryPageQueryByDto(ItineraryPageQuery dto) { String query = "SELECT * FROM route_order " - + "WHERE route_id IN (:routeIds) " - + "AND (:actualOrderNo IS NULL OR actual_order_no = :actualOrderNo ) " - + "AND actual_order_no IS NOT NULL "; + + "WHERE actual_order_no IS NOT NULL "; + + if (!dto.getRouteIds().isEmpty()) { + query+="AND route_id IN (:routeIds) "; + } if (!dto.getUserIds().isEmpty()) { - query+="AND user_id IN (:userIds)"; + query+="AND user_id IN (:userIds) "; + } + + if (!dto.getActualOrderNo().isEmpty()) { + query+="AND actual_order_no = :actualOrderNo "; } Map params = new HashMap<>(); - //设置null - if (dto.getActualOrderNo().isEmpty()){ - dto.setActualOrderNo(null); - } + PageRequest pageRequest = PageRequest + .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()); - PageRequest pageRequest = PageRequest - .of(dto.getPageNum() - 1, dto.getPageSize(), Sort.by("route_id").descending()); params.put("offset", pageRequest.getOffset()); params.put("limit", pageRequest.getPageSize()); @@ -91,9 +84,6 @@ public class JdbcConsumptionDetailRepositoryImpl implements JdbcConsumptionDetai if (orderIds==null||orderIds.isEmpty()) { return PageResult.totalPageNum(0, new ArrayList<>()); } - - PageRequest pageRequest = PageRequest - .of(dto.getPageNum() - 1, dto.getPageSize(), Sort.by("id").descending()); Page data=new PageImpl<>(Collections.emptyList()); //申请单查询 if (!dto.getActualOrderNo().isEmpty()){ @@ -101,79 +91,100 @@ public class JdbcConsumptionDetailRepositoryImpl implements JdbcConsumptionDetai if (orderNos.isEmpty()){ return new PageResult(0,new ArrayList<>()); } - switch (dto.getProductType()) { - case LEG_TYPE_TRAIN -> data=getOrderTrainRecord(jdbcTrainOrderDetailRepository.findAllByUserNameContainsAndOrderNoInAndOrderIdIn(dto.getUserName(),orderNos,orderIds,pageRequest)); - case LEG_TYPE_AIRPLANE -> data=getOrderFlightRecord(jdbcFlightOrderDetailRepository.findAllByUserNameContainsAndOrderNoInAndOrderIdIn(dto.getUserName(),orderNos,orderIds,pageRequest)); - case LEG_TYPE_HOTEL -> data=getOrderHotelRecord(jdbcHotelOrderDetailRepository.findAllByBookingNameContainsAndOrderNoInAndOrderIdIn(dto.getUserName(),orderNos,orderIds,pageRequest)); - case LEG_TYPE_TAXI -> data=getOrderCarRecord(jdbcCarOrderDetailRepository.findAllByUserNameContainsAndOrderNoInAndOrderIdIn(dto.getUserName(),orderNos,orderIds,pageRequest)); - } - return PageResult.totalPageNum(data.getTotalElements(), data.getContent()); + dto.setOrderNos(orderNos); } switch (dto.getProductType()) { - case LEG_TYPE_TRAIN -> data=getOrderTrainRecord(jdbcTrainOrderDetailRepository.findAllByUserNameContainsAndOrderIdIn(dto.getUserName(),orderIds,pageRequest)); - case LEG_TYPE_AIRPLANE -> data=getOrderFlightRecord(jdbcFlightOrderDetailRepository.findAllByUserNameContainsAndOrderIdIn(dto.getUserName(),orderIds,pageRequest)); - case LEG_TYPE_HOTEL -> data=getOrderHotelRecord(jdbcHotelOrderDetailRepository.findAllByBookingNameContainsAndOrderIdIn(dto.getUserName(),orderIds,pageRequest)); - case LEG_TYPE_TAXI -> data=getOrderCarRecord(jdbcCarOrderDetailRepository.findAllByUserNameContainsAndOrderIdIn(dto.getUserName(),orderIds,pageRequest)); + case LEG_TYPE_TRAIN -> data=trainPageConsumptionDetail(dto); + case LEG_TYPE_AIRPLANE -> data=flightPageConsumptionDetail(dto); + case LEG_TYPE_HOTEL -> data=hotelPageConsumptionDetail(dto); + case LEG_TYPE_TAXI -> data=carPageConsumptionDetail(dto); } return PageResult.totalPageNum(data.getTotalElements(), data.getContent()); } - public Page getOrderTrainRecord(Page page) { - List orderRecords = page.getContent(); - List trainOrderDetailExcels = new ArrayList<>(); - // 遍历 OrderBaseRecord,将其转换为 ConsumptionDetailExcel - for (TrainOrderDetail orderRecord : orderRecords) { - TrainOrderDetailExcel trainOrderDetailExcel = new TrainOrderDetailExcel(); - BeanUtils.copyProperties(orderRecord, trainOrderDetailExcel); - trainOrderDetailExcels.add(trainOrderDetailExcel); - } - // 构建一个新的 Page 对象并返回 - return new PageImpl<>(trainOrderDetailExcels, page.getPageable(), page.getTotalElements()); + + private Page trainPageConsumptionDetail(ConsumptionDetailQuery dto){ + String query = "SELECT * FROM train_order_detail " + + "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); + List results = jdbcTemplate.query(pagedQuery, params, BeanPropertyRowMapper.newInstance(TrainOrderDetailExcel.class)); + return new PageImpl<>(results, pageRequest, count); } - public Page getOrderFlightRecord(Page page) { - List orderRecords = page.getContent(); - List trainOrderDetailExcels = new ArrayList<>(); - for (FlightOrderDetail orderRecord : orderRecords) { - FlightOrderDetailExcel flightOrderDetailExcel = new FlightOrderDetailExcel(); - BeanUtils.copyProperties(orderRecord, flightOrderDetailExcel); - trainOrderDetailExcels.add(flightOrderDetailExcel); - } - // 构建一个新的 Page 对象并返回 - return new PageImpl<>(trainOrderDetailExcels, page.getPageable(), page.getTotalElements()); + private Page flightPageConsumptionDetail(ConsumptionDetailQuery dto){ + String query = "SELECT * FROM flight_order_detail " + + "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); + List results = jdbcTemplate.query(pagedQuery, params, BeanPropertyRowMapper.newInstance(FlightOrderDetailExcel.class)); + return new PageImpl<>(results, pageRequest, count); } - public Page getOrderHotelRecord(Page page) { - List orderRecords = page.getContent(); - List trainOrderDetailExcels = new ArrayList<>(); + private Page hotelPageConsumptionDetail(ConsumptionDetailQuery dto){ + String query = "SELECT * FROM hotel_order_detail " + + "WHERE 1=1 "; - for (HotelOrderDetail orderRecord : orderRecords) { - HotelOrderDetailExcel hotelOrderDetailExcel = new HotelOrderDetailExcel(); - BeanUtils.copyProperties(orderRecord, hotelOrderDetailExcel); - List customers=orderRecord.getCustomers(); - String userNames = customers.stream() - .map(HotelOrderDetailCustomer::getUserName) // 获取用户名 - .collect(Collectors.joining(",")); // 用逗号分隔拼接 - hotelOrderDetailExcel.setUserName(userNames); - trainOrderDetailExcels.add(hotelOrderDetailExcel); - } - // 构建一个新的 Page 对象并返回 - return new PageImpl<>(trainOrderDetailExcels, page.getPageable(), page.getTotalElements()); + 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); + List results = jdbcTemplate.query(pagedQuery, params, BeanPropertyRowMapper.newInstance(HotelOrderDetailExcel.class)); + return new PageImpl<>(results, pageRequest, count); } - public Page getOrderCarRecord(Page page) { - List orderRecords = page.getContent(); - List trainOrderDetailExcels = new ArrayList<>(); + private Page carPageConsumptionDetail(ConsumptionDetailQuery dto){ + String query = "SELECT * FROM car_order_detail " + + "WHERE 1=1 "; - // 遍历 OrderBaseRecord,将其转换为 ConsumptionDetailExcel - for (CarOrderDetail orderRecord : orderRecords) { - CarOrderDetailExcel carOrderDetailExcel = new CarOrderDetailExcel(); - BeanUtils.copyProperties(orderRecord, carOrderDetailExcel); - trainOrderDetailExcels.add(carOrderDetailExcel); + 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); + List results = jdbcTemplate.query(pagedQuery, params, BeanPropertyRowMapper.newInstance(CarOrderDetailExcel.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)"; } - // 构建一个新的 Page 对象并返回 - return new PageImpl<>(trainOrderDetailExcels, page.getPageable(), page.getTotalElements()); + if (!dto.getOrderIds().isEmpty()) { + query +="AND order_id IN (:orderIds)"; + } + + if (!dto.getOrderNos().isEmpty()) { + query +="AND order_no IN (:orderNos)"; + } + + params.put("userName", dto.getUserName()); + params.put("orderNos", dto.getOrderNos()); + params.put("orderIds", dto.getOrderIds()); + + params.put("offset", pageRequest.getOffset()); + params.put("limit", pageRequest.getPageSize()); + return query; } } 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 a8571bf4..874eda08 100644 --- a/src/main/java/com/chint/manage/service/impl/ManageServiceImpl.java +++ b/src/main/java/com/chint/manage/service/impl/ManageServiceImpl.java @@ -7,14 +7,14 @@ import com.chint.domain.exceptions.CommandException; import com.chint.domain.repository.UserRepository; import com.chint.domain.service.LegDomainService; import com.chint.infrastructure.repository.jdbc.JdbcLocationRepository; -import com.chint.infrastructure.repository.jdbc.JdbcOrderDetailRepository; import com.chint.infrastructure.repository.jdbc.JdbcRouteRepository; import com.chint.infrastructure.repository.jdbc.JdbcUserRepository; import com.chint.infrastructure.util.BaseContext; import com.chint.infrastructure.util.PageResult; +import com.chint.manage.entity.OrderDetailBasic; import com.chint.manage.entity.OrderDownloadRecord; import com.chint.manage.entity.OrderExceedStandard; -import com.chint.manage.entity.RouteOrderExtensionField; +import com.chint.manage.entity.RouteOrderExtensionFieldBasic; import com.chint.manage.entity.dto.ItineraryPageDto; import com.chint.manage.entity.excel.OrderPageExcel; import com.chint.manage.entity.excel.BaseExcel; @@ -67,11 +67,11 @@ public class ManageServiceImpl implements ManageService { @Autowired private BaseUtil baseUtil; @Autowired - private JdbcOrderDetailRepository jdbcOrderDetailRepository; + private JdbcOrderDetailBasicRepository jdbcOrderDetailBasicRepository; @Autowired private JdbcLocationRepository locationRepository; @Autowired - private JdbcRouteOrderExtensionFieldRepository jdbcRouteOrderExtensionFieldRepository; + private JdbcRouteOrderExtensionFieldBasicRepository jdbcRouteOrderExtensionFieldBasicRepository; @Autowired private JdbcTrainOrderDetailRepository jdbcTrainOrderDetailRepository; @Autowired @@ -105,13 +105,12 @@ public class ManageServiceImpl implements ManageService { PageRequest pageRequest = PageRequest .of(dto.getPageNum() - 1, dto.getPageSize(), Sort.by("id").descending()); - Page page=jdbcOrderExceedStandardRepository.findAllByApplicantContainsAndCompanyNameContainsAndActualOrderNoContainsAndOrderNoContainsAndOrderNoIn(dto.getApplicant(), + Page page=jdbcOrderExceedStandardRepository.findAllByApplicantContainsAndDeptNameContainsAndActualOrderNoContainsAndOrderNoContainsAndOrderNoIn(dto.getApplicant(), dto.getCompanyName(), dto.getActualOrderNo(), dto.getOrderNo(), orderNos, pageRequest); - List excelList = getOrderExceedStandardExcels(page); return PageResult.totalPageNum(page.getTotalElements(), excelList); } @@ -132,6 +131,7 @@ public class ManageServiceImpl implements ManageService { if (routeIds==null||routeIds.isEmpty()) { return PageResult.totalPageNum(0, new ArrayList<>()); } + dto.setRouteIds(routeIds); List users=new ArrayList<>(); if (!dto.getApplicant().isEmpty()){ @@ -140,7 +140,6 @@ public class ManageServiceImpl implements ManageService { return PageResult.totalPageNum(0, new ArrayList<>()); } } - dto.setRouteIds(routeIds); dto.setUserIds(users.stream().map(User::getEmployeeNo).toList()); Page page= jdbcConsumptionDetailRepository.itineraryPageQueryByDto(dto); //处理信息 @@ -164,9 +163,7 @@ public class ManageServiceImpl implements ManageService { @Override public void addOrderDownloadRecord(OrderDownloadRecord orderDownloadRecord) { -// User user= BaseContext.getCurrentUser(); - User user=new User(); - user.setEmployeeNo("123"); + User user= BaseContext.getCurrentUser(); orderDownloadRecord.setEmployeeNo(user.getEmployeeNo()); jdbcOrderDownloadRecordRepository.save(orderDownloadRecord); } @@ -212,12 +209,12 @@ public class ManageServiceImpl implements ManageService { } //部门 if (dto.getBelongDeptCode() != null && !dto.getBelongDeptCode().isEmpty()) { - List routeOrderExtensionFields = jdbcRouteOrderExtensionFieldRepository.findByBelongDeptCodeIn(dto.getBelongDeptCode()); - if (routeOrderExtensionFields == null || routeOrderExtensionFields.isEmpty()) { + List routeOrderExtensionFieldBasics = jdbcRouteOrderExtensionFieldBasicRepository.findAllByBelongDeptCodeIn(dto.getBelongDeptCode()); + if (routeOrderExtensionFieldBasics == null || routeOrderExtensionFieldBasics.isEmpty()) { return PageResult.totalPageNum(0, new ArrayList<>()); } - List routeOrderExtensionFieldIds = routeOrderExtensionFields.stream() - .map(RouteOrderExtensionField::getRouteId) + List routeOrderExtensionFieldIds = routeOrderExtensionFieldBasics.stream() + .map(RouteOrderExtensionFieldBasic::getRouteId) .collect(Collectors.toList()); List updatedRouteIds = dto.getRouteIds() == null ? routeOrderExtensionFieldIds @@ -235,18 +232,18 @@ public class ManageServiceImpl implements ManageService { dto.setApplicant("%"+dto.getApplicant()+"%"); } - List list=jdbcOrderDetailRepository.listByCondition(dto,dto.getPageResult()); + List list=jdbcOrderDetailBasicRepository.listByCondition(dto,dto.getPageResult()); //处理地点信息 - List locationIds = new ArrayList<>(list.stream().map(OrderDetail::getOriginId).toList()); - locationIds.addAll(list.stream().map(OrderDetail::getDestinationId).toList()); + List locationIds = new ArrayList<>(list.stream().map(OrderDetailBasic::getOriginId).toList()); + locationIds.addAll(list.stream().map(OrderDetailBasic::getDestinationId).toList()); locationIds=locationIds.stream().distinct().filter(Objects::nonNull).collect(Collectors.toList()); List locations=locationRepository.findByLocationIdIn(locationIds); //根据类型处理出行订单信息 Map orderPageDtoMap=new HashMap<>(); - Map> collect = list.stream().collect(Collectors.groupingBy(OrderDetail::getProductType)); - for (Map.Entry> entry : collect.entrySet()) { + Map> collect = list.stream().collect(Collectors.groupingBy(OrderDetailBasic::getProductType)); + for (Map.Entry> entry : collect.entrySet()) { int type = entry.getKey(); - List details = entry.getValue(); + List details = entry.getValue(); switch (type) { case LEG_TYPE_TRAIN -> dealOrderTrainRecord(details,orderPageDtoMap); case LEG_TYPE_AIRPLANE -> dealOrderFlightRecord(details,orderPageDtoMap); @@ -255,11 +252,11 @@ public class ManageServiceImpl implements ManageService { } } //处理行程单信息 - List routeIds=list.stream().map(OrderDetail::getRouteId).toList(); + List routeIds=list.stream().map(OrderDetailBasic::getRouteId).toList(); routeIds=routeIds.stream().distinct().filter(Objects::nonNull).collect(Collectors.toList()); List routeOrders=jdbcRouteRepository.findByRouteIdIn(routeIds); - List users=jdbcUserRepository.findAllByEmployeeNoIn(list.stream().map(OrderDetail::getEmployeeNo).collect(Collectors.toList())); + List users=jdbcUserRepository.findAllByEmployeeNoIn(list.stream().map(OrderDetailBasic::getEmployeeNo).collect(Collectors.toList())); List result = list.stream().map(temp -> { OrderPageExcel obj = orderPageDtoMap.get(temp.getOrderId()); @@ -287,7 +284,7 @@ public class ManageServiceImpl implements ManageService { } return finalObj; }).toList(); - Integer count=jdbcOrderDetailRepository.countByCondition(dto); + Integer count=jdbcOrderDetailBasicRepository.countByCondition(dto); return PageResult.totalPageNum(count, result); } @@ -300,9 +297,9 @@ public class ManageServiceImpl implements ManageService { return ExcelUtil.exportReport(orderPageQuery(dto).getRecords()); } - private void dealOrderTrainRecord(List entry,Map orderPageDtoMap){ + private void dealOrderTrainRecord(List entry,Map orderPageDtoMap){ if (entry!=null&&!entry.isEmpty()){ - List trainOrderDetails=jdbcTrainOrderDetailRepository.findAllByOrderIdIn(entry.stream().map(OrderDetail::getOrderId).toList()); + List trainOrderDetails=jdbcTrainOrderDetailRepository.findAllByOrderIdIn(entry.stream().map(OrderDetailBasic::getOrderId).toList()); for (TrainOrderDetail trainOrderDetail : trainOrderDetails) { OrderPageExcel orderPageDto=new OrderPageExcel(); orderPageDto.setStatus(trainOrderDetail.getOrderStatus()); @@ -312,9 +309,9 @@ public class ManageServiceImpl implements ManageService { } } - private void dealOrderFlightRecord(List entry,Map orderPageDtoMap){ + private void dealOrderFlightRecord(List entry,Map orderPageDtoMap){ if (entry!=null&&!entry.isEmpty()){ - List flightOrderDetails=jdbcFlightOrderDetailRepository.findAllByOrderIdIn(entry.stream().map(OrderDetail::getOrderId).toList()); + List flightOrderDetails=jdbcFlightOrderDetailRepository.findAllByOrderIdIn(entry.stream().map(OrderDetailBasic::getOrderId).toList()); for (FlightOrderDetail flightOrderDetail : flightOrderDetails) { OrderPageExcel orderPageDto=new OrderPageExcel(); orderPageDto.setStatus(flightOrderDetail.getOrderStatus()); @@ -324,9 +321,9 @@ public class ManageServiceImpl implements ManageService { } } - private void dealOrderHotelRecord(List entry,Map orderPageDtoMap){ + private void dealOrderHotelRecord(List entry,Map orderPageDtoMap){ if (entry!=null&&!entry.isEmpty()){ - List hotelOrderDetails=jdbcHotelOrderDetailRepository.findAllByOrderIdIn(entry.stream().map(OrderDetail::getOrderId).toList()); + List hotelOrderDetails=jdbcHotelOrderDetailRepository.findAllByOrderIdIn(entry.stream().map(OrderDetailBasic::getOrderId).toList()); for (HotelOrderDetail hotelOrderDetail : hotelOrderDetails) { OrderPageExcel orderPageDto=new OrderPageExcel(); orderPageDto.setStatus(hotelOrderDetail.getOrderStatus()); @@ -339,9 +336,9 @@ public class ManageServiceImpl implements ManageService { } } - private void dealOrderCarRecord(List entry,Map orderPageDtoMap){ + private void dealOrderCarRecord(List entry,Map orderPageDtoMap){ if (entry!=null&&!entry.isEmpty()){ - List carOrderDetails=jdbcCarOrderDetailRepository.findAllByOrderIdIn(entry.stream().map(OrderDetail::getOrderId).toList()); + List carOrderDetails=jdbcCarOrderDetailRepository.findAllByOrderIdIn(entry.stream().map(OrderDetailBasic::getOrderId).toList()); for (CarOrderDetail carOrderDetail : carOrderDetails) { OrderPageExcel orderPageDto=new OrderPageExcel(); orderPageDto.setStatus(carOrderDetail.getOrderStatus()); diff --git a/src/main/java/com/chint/manage/util/BaseUtil.java b/src/main/java/com/chint/manage/util/BaseUtil.java index 2bf5dffb..228c35b6 100644 --- a/src/main/java/com/chint/manage/util/BaseUtil.java +++ b/src/main/java/com/chint/manage/util/BaseUtil.java @@ -1,16 +1,15 @@ package com.chint.manage.util; -import com.chint.domain.aggregates.order.OrderDetail; import com.chint.domain.aggregates.user.User; -import com.chint.domain.value_object.system.SystemOrganizationVO; -import com.chint.infrastructure.repository.jdbc.JdbcOrderDetailRepository; import com.chint.infrastructure.util.BaseContext; -import com.chint.manage.entity.RouteOrderExtensionField; -import com.chint.manage.mapper.JdbcRouteOrderExtensionFieldRepository; +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; +import java.util.Objects; /** * 基础方法工具类 @@ -20,29 +19,31 @@ import java.util.List; @Component public class BaseUtil { @Autowired - private JdbcRouteOrderExtensionFieldRepository jdbcRouteOrderExtensionFieldRepository; + private JdbcRouteOrderExtensionFieldBasicRepository jdbcRouteOrderExtensionFieldBasicRepository; @Autowired - private JdbcOrderDetailRepository jdbcOrderDetailRepository; + private JdbcOrderDetailBasicRepository jdbcOrderDetailBasicRepository; public User getCurrentUser() { return BaseContext.getCurrentUser(); } public List getRouteIds(){ - List list = BaseContext.getCurrentUser().loadRoleOrg().getRoleOrgList() - .stream().filter(s->s.getOrgShortCode()!=null).map(SystemOrganizationVO::getOrgShortCode).toList(); - List result=jdbcRouteOrderExtensionFieldRepository.findByBelongDeptCodeIn(list); - return result.stream().map(RouteOrderExtensionField::getRouteId).toList(); + List list = BaseContext.getCurrentUser().loadRoleOrg().getRoleOrgCodeList().stream().filter(Objects::nonNull).toList(); + if (list.isEmpty()) return null; + List result= jdbcRouteOrderExtensionFieldBasicRepository.findAllByBelongDeptCodeIn(list); + return result.stream().map(RouteOrderExtensionFieldBasic::getRouteId).toList(); } public List getOrderIds(){ List routeIds = getRouteIds(); - return jdbcOrderDetailRepository.findAllByRouteIdIn(routeIds).stream().map(OrderDetail::getOrderId).toList(); + if (routeIds.isEmpty()) return null; + return jdbcOrderDetailBasicRepository.findAllOrderId(routeIds); } public List getOrderNos(){ List routeIds = getRouteIds(); - return jdbcOrderDetailRepository.findAllByRouteIdIn(routeIds).stream().map(OrderDetail::getOrderNo).toList(); + if (routeIds.isEmpty()) return null; + return jdbcOrderDetailBasicRepository.findAllOrderNo(routeIds); } /** diff --git a/src/main/java/com/chint/manage/util/DataJdbcCreatorUtil.java b/src/main/java/com/chint/manage/util/DataJdbcCreatorUtil.java index 9c762592..0d7a1b40 100644 --- a/src/main/java/com/chint/manage/util/DataJdbcCreatorUtil.java +++ b/src/main/java/com/chint/manage/util/DataJdbcCreatorUtil.java @@ -39,7 +39,7 @@ public class DataJdbcCreatorUtil { */ private List getTables() throws SQLException { List tables = new ArrayList(); - tables.add("route_order_extension_field"); + tables.add("crux_system_log"); return tables; } @@ -149,7 +149,7 @@ public class DataJdbcCreatorUtil { temp = tables[i].trim(); sb.append(temp.substring(0, 1).toUpperCase()).append(temp.substring(1)); } - beanName = sb.toString(); + beanName = sb.toString()+"Basic"; mapperName = "Jdbc"+beanName + "Repository"; _mapperName = shotFirst(mapperName); serviceName = beanName + "Service"; @@ -179,11 +179,11 @@ public class DataJdbcCreatorUtil { } else if (type.indexOf(type_int) > -1) { return "java.lang.Integer"; } else if (type.indexOf(type_date) > -1) { - return "java.util.Date"; + return "java.time.LocalDateTime"; } else if (type.indexOf(type_text) > -1) { return "java.lang.String"; } else if (type.indexOf(type_timestamp) > -1) { - return "java.util.Date"; + return "java.time.LocalDateTime"; } else if (type.indexOf(type_bit) > -1) { return "java.lang.Boolean"; } else if (type.indexOf(type_decimal) > -1) { @@ -203,11 +203,11 @@ public class DataJdbcCreatorUtil { } else if (type.indexOf(type_longtext) > -1) { return "java.lang.String"; } else if (type.indexOf(type_datetime) > -1) { - return "java.util.Date"; + return "java.time.LocalDateTime"; } else if (type.indexOf(type_binary) > -1) { return "java.lang.Long"; } else if (type.indexOf(type_time) > -1) { - return "java.util.Date"; + return "java.time.LocalDateTime"; } diff --git a/src/main/java/com/chint/manage/util/IpAddressUtil.java b/src/main/java/com/chint/manage/util/IpAddressUtil.java new file mode 100644 index 00000000..32fabd21 --- /dev/null +++ b/src/main/java/com/chint/manage/util/IpAddressUtil.java @@ -0,0 +1,64 @@ +package com.chint.manage.util; + + +import jakarta.servlet.http.HttpServletRequest; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +import java.util.List; + +/** +* 获取IP工具类 + * 如果是IP白名单限制应该直接使用request.getRemoteAddr() + * 这个无法伪造 +* @Author:nxj +* @Date:2020/6/24 9:20 +*/ +@Component +public class IpAddressUtil { + + private static final String LOCAL = "0:0:0:0:0:0:0:1"; + + + public String getIpAddress(HttpServletRequest request) { + String ip = null; + + //X-Forwarded-For:Squid 服务代理 + String ipAddresses = request.getHeader("X-Forwarded-For"); + String unknown = "unknown"; + if (ipAddresses == null || ipAddresses.length() == 0 || unknown.equalsIgnoreCase(ipAddresses)) { + //Proxy-Client-IP:apache 服务代理 + ipAddresses = request.getHeader("Proxy-Client-IP"); + } + + if (ipAddresses == null || ipAddresses.length() == 0 || unknown.equalsIgnoreCase(ipAddresses)) { + //WL-Proxy-Client-IP:weblogic 服务代理 + ipAddresses = request.getHeader("WL-Proxy-Client-IP"); + } + + if (ipAddresses == null || ipAddresses.length() == 0 || unknown.equalsIgnoreCase(ipAddresses)) { + //HTTP_CLIENT_IP:有些代理服务器 + ipAddresses = request.getHeader("HTTP_CLIENT_IP"); + } + + if (ipAddresses == null || ipAddresses.length() == 0 || unknown.equalsIgnoreCase(ipAddresses)) { + //X-Real-IP:nginx服务代理 + ipAddresses = request.getHeader("X-Real-IP"); + } + + //有些网络通过多层代理,那么获取到的ip就会有多个,一般都是通过逗号(,)分割开来,并且第一个ip为客户端的真实IP + if (ipAddresses != null && ipAddresses.length() != 0) { + ip = ipAddresses.split(",")[0]; + } + + //还是不能获取到,最后再通过request.getRemoteAddr();获取 + if (ip == null || ip.length() == 0 || unknown.equalsIgnoreCase(ipAddresses)) { + ip = request.getRemoteAddr(); + } + + if(LOCAL.equals(ip)){ + return "127.0.0.1"; + } + return ip; + } +}