Browse Source

修改路段查看数据权限

tags/v1.0.0^2
chengwang 1 year ago
parent
commit
a66d29ce59
3 changed files with 143 additions and 21 deletions
  1. +45
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/enums/SectionEnum.java
  2. +87
    -21
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/impl/SectionServiceImpl.java
  3. +11
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/impl/StructureServiceImpl.java

+ 45
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/enums/SectionEnum.java View File

@@ -0,0 +1,45 @@
package com.tuoheng.admin.enums;

/**
* @Author ChengWang
* @Date 2022/12/21
*/
public enum SectionEnum {

QUERY_IS_FAILED(1220300, "获取数据失败"),
USER_IS_NOT_EXIST(1220301, "用户为空"),
DEPT_IS_NOT_EXIST(1220302, "部门不存在"),
SECTION_ID_IS_NULL(1220303, "路段id为空"),
SECTION_LIST_IS_NULL(1220304, "路段列表为空");

/**
* 错误码
*/
private int code;

/**
* 错误信息
*/
private String msg;

SectionEnum(int code, String msg){
this.code = code;
this.msg = msg;
}

public int getCode() {
return code;
}

public void setCode(int code) {
this.code = code;
}

public String getMsg() {
return msg;
}

public void setMsg(String msg) {
this.msg = msg;
}
}

+ 87
- 21
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/impl/SectionServiceImpl.java View File

@@ -1,6 +1,7 @@
package com.tuoheng.admin.service.impl;


import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
@@ -9,6 +10,10 @@ import com.tuoheng.admin.entity.RoadInformation;
import com.tuoheng.admin.entity.Section;

import com.tuoheng.admin.entity.SectionDept;
import com.tuoheng.admin.entity.User;
import com.tuoheng.admin.enums.SectionEnum;
import com.tuoheng.admin.enums.UserTypeEnum;
import com.tuoheng.admin.mapper.DeptMapper;
import com.tuoheng.admin.mapper.RoadInformationMapper;
import com.tuoheng.admin.mapper.SectionDeptMapper;
import com.tuoheng.admin.mapper.SectionMapper;
@@ -30,6 +35,7 @@ import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;


/**
@@ -54,37 +60,97 @@ public class SectionServiceImpl extends BaseServiceImpl<SectionMapper, Section>
@Autowired
private QuerySectionListByRoadIdService querySectionListByRoadIdService;

@Autowired
private DeptMapper deptMapper;


/**
* 获取路段列表(分页)
* @param query
* @return
*/
@Override
public JsonResult queryPage(SectionQuery query) {
if(null==query.getLimit() && null == query.getPage()){
throw new ServiceException(ServiceExceptionEnum.PARAMETER_IS_NULL);
}
//获取当前登录用户信息
User user = CurrentUserUtil.getUserInfo();
if(ObjectUtil.isNull(user)){
return JsonResult.error(SectionEnum.USER_IS_NOT_EXIST.getCode(),SectionEnum.USER_IS_NOT_EXIST.getMsg());
}
String tenantId = CurrentUserUtil.getTenantId();
//获取分页数据
IPage<Section> page = new Page<>(query.getPage(),query.getLimit());
IPage<Section> pageData = sectionMapper.selectPage(page, Wrappers.<Section>lambdaQuery()
.eq(Section::getMark, 1)
.eq(Section::getTenantId, tenantId)
.orderByDesc(Section::getCreateTime));
List<Section> records = pageData.getRecords();
List<Section> list = new ArrayList<>();
for (Section record : records) {
//获取每条路段对应的公路id
RoadInformation roadInformation = roadInformationMapper.selectOne(Wrappers.<RoadInformation>lambdaQuery()
.eq(RoadInformation::getId, record.getRoadId())
.eq(RoadInformation::getMark, 1));
if(StringUtils.isNotNull(roadInformation)){
if(StringUtils.isNotEmpty(roadInformation.getCode())){
record.setCode(roadInformation.getCode());
IPage<Section> pageData = new Page<>(query.getPage(),query.getLimit());
//数据权限 超级管理员可以查看全部路段
if(UserTypeEnum.SUPER_ADMIN.getCode() == user.getType()){
//获取分页数据
IPage<Section> page = new Page<>(query.getPage(),query.getLimit());
pageData = sectionMapper.selectPage(page, Wrappers.<Section>lambdaQuery()
.eq(Section::getMark, 1)
.eq(Section::getTenantId, tenantId)
.orderByDesc(Section::getCreateTime));
List<Section> records = pageData.getRecords();
List<Section> list = new ArrayList<>();
for (Section record : records) {
//获取每条路段对应的公路id
RoadInformation roadInformation = roadInformationMapper.selectOne(Wrappers.<RoadInformation>lambdaQuery()
.eq(RoadInformation::getId, record.getRoadId())
.eq(RoadInformation::getMark, 1));
if(StringUtils.isNotNull(roadInformation)){
if(StringUtils.isNotEmpty(roadInformation.getCode())){
record.setCode(roadInformation.getCode());
}
}
//判断路段是否关联部门
SectionRelation(record);
list.add(record);
}
//判断路段是否关联部门
SectionRelation(record);
list.add(record);
pageData.setRecords(list);
}
//部门管理员和普通用户 查看本部门及下属部门
if(UserTypeEnum.ADMIN.getCode() == user.getType() || UserTypeEnum.ORDINARY_USER.getCode() == user.getType()){
//获取分页数据
IPage<Section> page = new Page<>(query.getPage(),query.getLimit());
//获取当前部门及其子部门列表
String deptId = user.getDeptId();
if(StringUtils.isEmpty(deptId)){
JsonResult.error(SectionEnum.DEPT_IS_NOT_EXIST.getCode(),SectionEnum.DEPT_IS_NOT_EXIST.getMsg());
}
List<String> deptList = deptMapper.selectAllChildListById(deptId);
//根据部门列表查对应的部门路段数据列表
List<SectionDept> sectionDeptList = sectionDeptMapper.selectList(Wrappers.<SectionDept>lambdaQuery()
.eq(SectionDept::getTenantId, tenantId)
.in(SectionDept::getDeptId, deptList));
//查询对应的路段列表
List<String> sectionIdList = sectionDeptList.stream().map(t -> t.getSectionId()).collect(Collectors.toList());
if(StringUtils.isEmpty(sectionIdList)){
JsonResult.error(SectionEnum.SECTION_ID_IS_NULL.getCode(),SectionEnum.SECTION_ID_IS_NULL.getMsg());
}
//根据路段id列表获取对应的路段信息
List<Section> sectionList = sectionMapper.selectList(new LambdaQueryWrapper<Section>()
.eq(Section::getMark, 1)
.eq(Section::getTenantId, tenantId)
.in(Section::getId, sectionIdList));
if(StringUtils.isEmpty(sectionList)){
JsonResult.error(SectionEnum.SECTION_LIST_IS_NULL.getCode(),SectionEnum.SECTION_LIST_IS_NULL.getMsg());
}
List<Section> list = new ArrayList<>();
for (Section section : sectionList) {
//获取每条路段对应的公路id
RoadInformation roadInformation = roadInformationMapper.selectOne(Wrappers.<RoadInformation>lambdaQuery()
.eq(RoadInformation::getId, section.getRoadId())
.eq(RoadInformation::getMark, 1));
if(ObjectUtil.isNotNull(roadInformation)){
if(StringUtils.isNotEmpty(roadInformation.getCode())){
section.setCode(roadInformation.getCode());
}
}
//判断路段是否关联部门
SectionRelation(section);
list.add(section);
}
pageData.setRecords(list);
}
pageData.setRecords(list);

return JsonResult.success(pageData);
}


+ 11
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/impl/StructureServiceImpl.java View File

@@ -8,12 +8,14 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tuoheng.admin.entity.RoadInformation;
import com.tuoheng.admin.entity.Section;
import com.tuoheng.admin.entity.Structure;
import com.tuoheng.admin.entity.User;
import com.tuoheng.admin.mapper.RoadInformationMapper;
import com.tuoheng.admin.mapper.SectionMapper;
import com.tuoheng.admin.mapper.StructureMapper;
import com.tuoheng.admin.mapper.UserMapper;
import com.tuoheng.admin.query.StructureQuery;
import com.tuoheng.admin.service.IStructureService;
import com.tuoheng.admin.utils.CurrentUserUtil;
import com.tuoheng.admin.vo.StructureInfoVo;
import com.tuoheng.common.core.common.BaseServiceImpl;
import com.tuoheng.common.core.config.common.CommonConfig;
@@ -54,6 +56,15 @@ public class StructureServiceImpl extends BaseServiceImpl<StructureMapper, Struc
if(null==(query.getPage()) && null == query.getLimit()){
throw new ServiceException(ServiceExceptionEnum.PARAMETER_IS_NULL);
}
//获取登录信息
User user = CurrentUserUtil.getUserInfo();
if(ObjectUtil.isNull(user)){
throw new ServiceException(ServiceExceptionEnum.PARAMETER_IS_NULL);
}
//获取用户角色
Integer type = user.getType();
//如果是超级管理员,查看所有构造物
//如果是部门管理员或普通用户,查询本部门的构造物及下属部门的构造物
//数据分页
IPage<Structure> page = new Page<>(query.getPage(),query.getLimit());


Loading…
Cancel
Save