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 54f99ad8..1a125bf5 100644 --- a/src/main/java/com/chint/domain/repository/SystemOrganizationRepository.java +++ b/src/main/java/com/chint/domain/repository/SystemOrganizationRepository.java @@ -26,4 +26,6 @@ public interface SystemOrganizationRepository { SystemOrganization queryChild(SystemOrganization systemOrganization); List expandOrganizations(List systemOrganizations); + + List queryOrgCodeListByUserId(Long userId); } 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 4a8e5f6e..c2913e9c 100644 --- a/src/main/java/com/chint/infrastructure/repository/SystemOrganizationRepositoryImpl.java +++ b/src/main/java/com/chint/infrastructure/repository/SystemOrganizationRepositoryImpl.java @@ -127,6 +127,11 @@ public class SystemOrganizationRepositoryImpl implements SystemOrganizationRepos return allOrganizations; } + @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/JdbcSystemOrganizationRepository.java b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcSystemOrganizationRepository.java index 1a4d2bca..ccea92b7 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,4 +16,10 @@ 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); } diff --git a/src/main/java/com/chint/manage/mapper/JdbcOrderDetailBasicRepository.java b/src/main/java/com/chint/manage/mapper/JdbcOrderDetailBasicRepository.java index fca7afed..c3e8189d 100644 --- a/src/main/java/com/chint/manage/mapper/JdbcOrderDetailBasicRepository.java +++ b/src/main/java/com/chint/manage/mapper/JdbcOrderDetailBasicRepository.java @@ -37,8 +37,8 @@ public interface JdbcOrderDetailBasicRepository extends CrudRepository listByCondition(@Param("dto") OrderPageQuery dto, @Param("pageRequest") PageRequest pageRequest); @Query("SELECT COUNT(*) FROM order_detail " + -// "WHERE route_id IN (:#{#dto.routeIds}) " + - "WHERE 1=1 " + + "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}) "+ diff --git a/src/main/java/com/chint/manage/mapper/JdbcOrderExceedStandardRepository.java b/src/main/java/com/chint/manage/mapper/JdbcOrderExceedStandardRepository.java index 8de1f15a..22217979 100644 --- a/src/main/java/com/chint/manage/mapper/JdbcOrderExceedStandardRepository.java +++ b/src/main/java/com/chint/manage/mapper/JdbcOrderExceedStandardRepository.java @@ -21,6 +21,6 @@ public interface JdbcOrderExceedStandardRepository extends CrudRepository 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); + 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/impl/JdbcConsumptionDetailRepositoryImpl.java b/src/main/java/com/chint/manage/mapper/impl/JdbcConsumptionDetailRepositoryImpl.java index cdaa38a2..57111b14 100644 --- a/src/main/java/com/chint/manage/mapper/impl/JdbcConsumptionDetailRepositoryImpl.java +++ b/src/main/java/com/chint/manage/mapper/impl/JdbcConsumptionDetailRepositoryImpl.java @@ -80,10 +80,10 @@ public class JdbcConsumptionDetailRepositoryImpl implements JdbcConsumptionDetai @Override public PageResult pageConsumptionDetail(ConsumptionDetailQuery dto) { //数据权限 -// List orderIds=baseUtil.getOrderIds(); -// if (orderIds==null||orderIds.isEmpty()) { -// return PageResult.totalPageNum(0, new ArrayList<>()); -// } + List orderIds=baseUtil.getOrderIds(); + if (orderIds==null||orderIds.isEmpty()) { + return PageResult.totalPageNum(0, new ArrayList<>()); + } Page data=new PageImpl<>(Collections.emptyList()); //申请单查询 if (!dto.getActualOrderNo().isEmpty()){ 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 959e9741..874eda08 100644 --- a/src/main/java/com/chint/manage/service/impl/ManageServiceImpl.java +++ b/src/main/java/com/chint/manage/service/impl/ManageServiceImpl.java @@ -98,18 +98,18 @@ public class ManageServiceImpl implements ManageService { @Override public PageResult standardQuery(StandardQuery dto) { //数据权限 -// List orderNos=baseUtil.getOrderNos(); -// if (orderNos==null||orderNos.isEmpty()) { -// return PageResult.totalPageNum(0, new ArrayList<>()); -// } + List orderNos=baseUtil.getOrderNos(); + if (orderNos==null||orderNos.isEmpty()) { + return PageResult.totalPageNum(0, new ArrayList<>()); + } PageRequest pageRequest = PageRequest .of(dto.getPageNum() - 1, dto.getPageSize(), Sort.by("id").descending()); - Page page=jdbcOrderExceedStandardRepository.findAllByApplicantContainsAndDeptNameContainsAndActualOrderNoContainsAndOrderNoContains(dto.getApplicant(), + Page page=jdbcOrderExceedStandardRepository.findAllByApplicantContainsAndDeptNameContainsAndActualOrderNoContainsAndOrderNoContainsAndOrderNoIn(dto.getApplicant(), dto.getCompanyName(), dto.getActualOrderNo(), dto.getOrderNo(), -// orderNos, + orderNos, pageRequest); List excelList = getOrderExceedStandardExcels(page); return PageResult.totalPageNum(page.getTotalElements(), excelList); @@ -127,11 +127,11 @@ public class ManageServiceImpl implements ManageService { @Override public PageResult itineraryPageQuery(ItineraryPageQuery dto) { //数据权限 -// List routeIds=baseUtil.getRouteIds(); -// if (routeIds==null||routeIds.isEmpty()) { -// return PageResult.totalPageNum(0, new ArrayList<>()); -// } -// dto.setRouteIds(routeIds); + List routeIds=baseUtil.getRouteIds(); + if (routeIds==null||routeIds.isEmpty()) { + return PageResult.totalPageNum(0, new ArrayList<>()); + } + dto.setRouteIds(routeIds); List users=new ArrayList<>(); if (!dto.getApplicant().isEmpty()){ @@ -163,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); } @@ -179,11 +177,11 @@ public class ManageServiceImpl implements ManageService { @Override public PageResult orderPageQuery(OrderPageQuery dto) { //数据权限 -// List dataRouteIds=baseUtil.getRouteIds(); -// if (dataRouteIds==null||dataRouteIds.isEmpty()) { -// return PageResult.totalPageNum(0, new ArrayList<>()); -// } -// dto.setRouteIds(dataRouteIds); + List dataRouteIds=baseUtil.getRouteIds(); + if (dataRouteIds==null||dataRouteIds.isEmpty()) { + return PageResult.totalPageNum(0, new ArrayList<>()); + } + dto.setRouteIds(dataRouteIds); //预订人 if (!dto.getApplicant().equals("")){ diff --git a/src/main/java/com/chint/manage/util/BaseUtil.java b/src/main/java/com/chint/manage/util/BaseUtil.java index b36690ff..6db0cdb2 100644 --- a/src/main/java/com/chint/manage/util/BaseUtil.java +++ b/src/main/java/com/chint/manage/util/BaseUtil.java @@ -28,8 +28,7 @@ public class BaseUtil { } public List getRouteIds(){ - List list = BaseContext.getCurrentUser().loadRoleOrg().getRoleOrgList() - .stream().filter(s->s.getOrgShortCode()!=null).map(SystemOrganizationVO::getOrgShortCode).toList(); + List list = BaseContext.getCurrentUser().loadRoleOrg().getRoleOrgCodeList(); List result= jdbcRouteOrderExtensionFieldBasicRepository.findAllByBelongDeptCodeIn(list); return result.stream().map(RouteOrderExtensionFieldBasic::getRouteId).toList(); }