【update】数据权限部分业务逻辑修改
This commit is contained in:
parent
e80b644f62
commit
7db999404b
|
@ -21,6 +21,5 @@ public class UserRes {
|
|||
private String rankCode;
|
||||
private String companyCode;
|
||||
private String workStatus;
|
||||
private List<SystemOrganizationVO> roleOrgList;
|
||||
private List<Role> roleList;
|
||||
}
|
||||
|
|
|
@ -82,8 +82,6 @@ public class User implements Serializable {
|
|||
@Transient
|
||||
private List<String> roleOrgCodeList;
|
||||
@Transient
|
||||
private List<SystemOrganizationVO> roleOrgList;
|
||||
@Transient
|
||||
private List<Role> roleList;
|
||||
|
||||
public User loadInfoFromDept() {
|
||||
|
|
|
@ -26,4 +26,6 @@ public interface SystemOrganizationRepository {
|
|||
SystemOrganization queryChild(SystemOrganization systemOrganization);
|
||||
|
||||
List<SystemOrganization> expandOrganizations(List<SystemOrganization> systemOrganizations);
|
||||
|
||||
List<String> queryOrgCodeListByUserId(Long userId);
|
||||
}
|
||||
|
|
|
@ -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<String> orgCodeList = cacheRoleRepository
|
||||
.roleOrgCodeList(userId, null);
|
||||
List<SystemOrganizationVO> systemOrganizationVOList = cacheRoleRepository
|
||||
.roleOrgList(userId, null);
|
||||
|
||||
if (systemOrganizationVOList == null || systemOrganizationVOList.isEmpty() ||
|
||||
orgCodeList == null || orgCodeList.isEmpty()) {
|
||||
List<Role> roleList = user.getRoleList();
|
||||
List<Long> orgListId = roleList
|
||||
.stream()
|
||||
.flatMap(role -> role.getRoleOrganizationList().stream())
|
||||
.map(RoleOrganization::getOrgId)
|
||||
.distinct()
|
||||
.toList();
|
||||
|
||||
// 获取所有的 SystemOrganization
|
||||
List<SystemOrganization> 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<String> orgCodeList = cacheRoleRepository
|
||||
// .roleOrgCodeList(userId, null);
|
||||
// List<SystemOrganizationVO> systemOrganizationVOList = cacheRoleRepository
|
||||
// .roleOrgList(userId, null);
|
||||
//
|
||||
// if (systemOrganizationVOList == null || systemOrganizationVOList.isEmpty() ||
|
||||
// orgCodeList == null || orgCodeList.isEmpty()) {
|
||||
// List<Role> roleList = user.getRoleList();
|
||||
// List<Long> orgListId = roleList
|
||||
// .stream()
|
||||
// .flatMap(role -> role.getRoleOrganizationList().stream())
|
||||
// .map(RoleOrganization::getOrgId)
|
||||
// .distinct()
|
||||
// .toList();
|
||||
//
|
||||
// // 获取所有的 SystemOrganization
|
||||
// List<SystemOrganization> 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -127,6 +127,11 @@ public class SystemOrganizationRepositoryImpl implements SystemOrganizationRepos
|
|||
return allOrganizations;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> queryOrgCodeListByUserId(Long userId) {
|
||||
return jdbcSystemOrganizationRepository.queryOrgCodeListByUserId(userId);
|
||||
}
|
||||
|
||||
private void expandOrganizationRecursively(SystemOrganization org,
|
||||
List<SystemOrganization> allOrganizations) {
|
||||
if (org == null) {
|
||||
|
|
|
@ -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<SystemO
|
|||
List<SystemOrganization> findByOrgLevelIsNullOrOrgLevel(String orgLevel);
|
||||
List<SystemOrganization> findByOrgShortCodeIn(Collection<String> orgCode);
|
||||
List<SystemOrganization> findByIdIn(Collection<Long> 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<String> queryOrgCodeListByUserId(Long userId);
|
||||
}
|
||||
|
|
|
@ -37,8 +37,8 @@ public interface JdbcOrderDetailBasicRepository extends CrudRepository<OrderDeta
|
|||
|
||||
|
||||
@Query("SELECT * 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}) " +
|
||||
|
@ -48,8 +48,8 @@ public interface JdbcOrderDetailBasicRepository extends CrudRepository<OrderDeta
|
|||
List<OrderDetailBasic> 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}) "+
|
||||
|
|
|
@ -21,6 +21,6 @@ public interface JdbcOrderExceedStandardRepository extends CrudRepository<OrderE
|
|||
|
||||
List<OrderExceedStandard> findAll();
|
||||
|
||||
// Page<OrderExceedStandard> findAllByApplicantContainsAndDeptNameContainsAndActualOrderNoContainsAndOrderNoContainsAndOrderNoIn(String applicant, String company, String actualOrderNo, String orderNo, List<String> orderNos, Pageable pageable);
|
||||
Page<OrderExceedStandard> findAllByApplicantContainsAndDeptNameContainsAndActualOrderNoContainsAndOrderNoContains(String applicant, String company, String actualOrderNo, String orderNo, Pageable pageable);
|
||||
Page<OrderExceedStandard> findAllByApplicantContainsAndDeptNameContainsAndActualOrderNoContainsAndOrderNoContainsAndOrderNoIn(String applicant, String company, String actualOrderNo, String orderNo, List<String> orderNos, Pageable pageable);
|
||||
//Page<OrderExceedStandard> findAllByApplicantContainsAndDeptNameContainsAndActualOrderNoContainsAndOrderNoContains(String applicant, String company, String actualOrderNo, String orderNo, Pageable pageable);
|
||||
}
|
||||
|
|
|
@ -80,10 +80,10 @@ public class JdbcConsumptionDetailRepositoryImpl implements JdbcConsumptionDetai
|
|||
@Override
|
||||
public PageResult<? extends BaseExcel> pageConsumptionDetail(ConsumptionDetailQuery dto) {
|
||||
//数据权限
|
||||
// List<Long> orderIds=baseUtil.getOrderIds();
|
||||
// if (orderIds==null||orderIds.isEmpty()) {
|
||||
// return PageResult.totalPageNum(0, new ArrayList<>());
|
||||
// }
|
||||
List<Long> orderIds=baseUtil.getOrderIds();
|
||||
if (orderIds==null||orderIds.isEmpty()) {
|
||||
return PageResult.totalPageNum(0, new ArrayList<>());
|
||||
}
|
||||
Page<? extends BaseExcel> data=new PageImpl<>(Collections.emptyList());
|
||||
//申请单查询
|
||||
if (!dto.getActualOrderNo().isEmpty()){
|
||||
|
|
|
@ -98,18 +98,18 @@ public class ManageServiceImpl implements ManageService {
|
|||
@Override
|
||||
public PageResult<OrderExceedStandardExcel> standardQuery(StandardQuery dto) {
|
||||
//数据权限
|
||||
// List<String> orderNos=baseUtil.getOrderNos();
|
||||
// if (orderNos==null||orderNos.isEmpty()) {
|
||||
// return PageResult.totalPageNum(0, new ArrayList<>());
|
||||
// }
|
||||
List<String> 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<OrderExceedStandard> page=jdbcOrderExceedStandardRepository.findAllByApplicantContainsAndDeptNameContainsAndActualOrderNoContainsAndOrderNoContains(dto.getApplicant(),
|
||||
Page<OrderExceedStandard> page=jdbcOrderExceedStandardRepository.findAllByApplicantContainsAndDeptNameContainsAndActualOrderNoContainsAndOrderNoContainsAndOrderNoIn(dto.getApplicant(),
|
||||
dto.getCompanyName(),
|
||||
dto.getActualOrderNo(),
|
||||
dto.getOrderNo(),
|
||||
// orderNos,
|
||||
orderNos,
|
||||
pageRequest);
|
||||
List<OrderExceedStandardExcel> excelList = getOrderExceedStandardExcels(page);
|
||||
return PageResult.totalPageNum(page.getTotalElements(), excelList);
|
||||
|
@ -127,11 +127,11 @@ public class ManageServiceImpl implements ManageService {
|
|||
@Override
|
||||
public PageResult<ItineraryPageDto> itineraryPageQuery(ItineraryPageQuery dto) {
|
||||
//数据权限
|
||||
// List<Long> routeIds=baseUtil.getRouteIds();
|
||||
// if (routeIds==null||routeIds.isEmpty()) {
|
||||
// return PageResult.totalPageNum(0, new ArrayList<>());
|
||||
// }
|
||||
// dto.setRouteIds(routeIds);
|
||||
List<Long> routeIds=baseUtil.getRouteIds();
|
||||
if (routeIds==null||routeIds.isEmpty()) {
|
||||
return PageResult.totalPageNum(0, new ArrayList<>());
|
||||
}
|
||||
dto.setRouteIds(routeIds);
|
||||
|
||||
List<User> 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<OrderPageExcel> orderPageQuery(OrderPageQuery dto) {
|
||||
//数据权限
|
||||
// List<Long> dataRouteIds=baseUtil.getRouteIds();
|
||||
// if (dataRouteIds==null||dataRouteIds.isEmpty()) {
|
||||
// return PageResult.totalPageNum(0, new ArrayList<>());
|
||||
// }
|
||||
// dto.setRouteIds(dataRouteIds);
|
||||
List<Long> dataRouteIds=baseUtil.getRouteIds();
|
||||
if (dataRouteIds==null||dataRouteIds.isEmpty()) {
|
||||
return PageResult.totalPageNum(0, new ArrayList<>());
|
||||
}
|
||||
dto.setRouteIds(dataRouteIds);
|
||||
|
||||
//预订人
|
||||
if (!dto.getApplicant().equals("")){
|
||||
|
|
|
@ -28,8 +28,7 @@ public class BaseUtil {
|
|||
}
|
||||
|
||||
public List<Long> getRouteIds(){
|
||||
List<String> list = BaseContext.getCurrentUser().loadRoleOrg().getRoleOrgList()
|
||||
.stream().filter(s->s.getOrgShortCode()!=null).map(SystemOrganizationVO::getOrgShortCode).toList();
|
||||
List<String> list = BaseContext.getCurrentUser().loadRoleOrg().getRoleOrgCodeList();
|
||||
List<RouteOrderExtensionFieldBasic> result= jdbcRouteOrderExtensionFieldBasicRepository.findAllByBelongDeptCodeIn(list);
|
||||
return result.stream().map(RouteOrderExtensionFieldBasic::getRouteId).toList();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue