Kaynağa Gözat

根据登录用户角色判断部门对应的道路

tags/v1.0.0^2
chengwang 1 yıl önce
ebeveyn
işleme
4ffa49a35f
9 değiştirilmiş dosya ile 208 ekleme ve 76 silme
  1. +9
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/controller/RoadInformationController.java
  2. +2
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/mapper/RoadDeptMapper.java
  3. +2
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/RoadInformationService.java
  4. +111
    -37
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/impl/RoadInformationServiceImpl.java
  5. +4
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/impl/StructureServiceImpl.java
  6. +1
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/road/query/QueryRoadListByDeptIdService.java
  7. +49
    -38
      tuoheng-service/tuoheng-admin/src/main/resources/mapper/RoadDeptMapper.xml
  8. +1
    -1
      tuoheng-service/tuoheng-admin/src/main/resources/mapper/RoadInformationMapper.xml
  9. +29
    -0
      tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/enums/UserTypeEnum.java

+ 9
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/controller/RoadInformationController.java Dosyayı Görüntüle

@@ -48,6 +48,15 @@ public class RoadInformationController {
return roadInformationService.getListByDeptId(deptId);
}

/**
* 根据登录人角色获取该部门下公路信息列表
* @return
*/
@GetMapping("/list/by/dept/UserType")
public JsonResult getListByUserType(){
return roadInformationService.getListByUserType();
}

/**
* 公路新增
* @param entity

+ 2
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/mapper/RoadDeptMapper.java Dosyayı Görüntüle

@@ -19,4 +19,6 @@ public interface RoadDeptMapper extends BaseMapper<RoadDept> {

void deleteBatchByMap(Map<String, Object> map);

List<RoadDept> selectListByDeptIdList(List<String> deptIdList);

}

+ 2
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/RoadInformationService.java Dosyayı Görüntüle

@@ -19,5 +19,7 @@ public interface RoadInformationService extends IBaseService<RoadInformation> {

JsonResult editInfo(RoadInformation entity);

JsonResult getListByUserType();

// JsonResult deleteRoadByIds(String[] ids);
}

+ 111
- 37
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/impl/RoadInformationServiceImpl.java Dosyayı Görüntüle

@@ -1,30 +1,32 @@
package com.tuoheng.admin.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
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.User;
import com.tuoheng.admin.mapper.RoadInformationMapper;
import com.tuoheng.admin.mapper.SectionMapper;
import com.tuoheng.admin.entity.*;
import com.tuoheng.admin.enums.UserTypeEnum;
import com.tuoheng.admin.mapper.*;
import com.tuoheng.admin.query.RoadInformationQuery;
import com.tuoheng.admin.service.RoadInformationService;
import com.tuoheng.admin.service.road.query.QueryRoadListByDeptIdService;
import com.tuoheng.common.core.common.BaseServiceImpl;
import com.tuoheng.common.core.enums.ServiceExceptionEnum;
import com.tuoheng.common.core.utils.DateUtils;
import com.tuoheng.common.core.utils.JsonResult;
import com.tuoheng.common.core.utils.StringUtils;
import com.tuoheng.common.core.utils.ThreadLocalUtil;
import com.tuoheng.common.core.exception.ServiceException;
import com.tuoheng.common.core.utils.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

/**
* @Author ChengWang
@@ -42,6 +44,15 @@ public class RoadInformationServiceImpl extends BaseServiceImpl<RoadInformationM
@Autowired
private QueryRoadListByDeptIdService queryRoadListByDeptIdService;

@Autowired
private UserMapper userMapper;

@Autowired
private DeptMapper deptMapper;

@Autowired
private RoadDeptMapper roadDeptMapper;

@Override
public JsonResult queryPage(RoadInformationQuery query) {
if (query.getLimit() == null && query.getPage() == null) {
@@ -112,34 +123,97 @@ public class RoadInformationServiceImpl extends BaseServiceImpl<RoadInformationM
return JsonResult.success();
}

// @Override
// public JsonResult deleteRoadByIds(String[] ids) {
// if (StringUtils.isNull(ids)) {
// return JsonResult.error("公路ID不能为空");
// }
// for (String id : ids) {
// RoadInformation roadInformation = roadInformationMapper.selectById(id);
// //判断公路是否关联路段
// List<Section> sectionList = sectionMapper.selectList(new LambdaQueryWrapper<Section>()
// .eq(Section::getMark, 1)
// .eq(Section::getTenantId, 1)
// .eq(Section::getRoadId, roadInformation.getId()));
// if (StringUtils.isEmpty(sectionList)) {
// super.deleteById(id);
// }
// //公路关联路段不为空,删除公路对应的路段
// for (Section section : sectionList) {
// LambdaUpdateWrapper<Section> qw = new LambdaUpdateWrapper<>();
// qw.set(Section::getMark, 0);
// qw.eq(Section::getId, section.getId());
// int update = sectionMapper.update(section, qw);
// if (update <= 0) {
// return JsonResult.error();
// }
// }
// }
// return JsonResult.success("删除成功");
// }
/**
* 根据登录人角色获取该部门下公路信息列表
* @return
*/
@Override
public JsonResult getListByUserType() {
//获取当前登录人信息 登录用户名
//String username = SecurityUserUtils.username();
String username="admin";
if(StringUtils.isEmpty(username)){
return JsonResult.error("登录用户名不存在");
}
User user = userMapper.selectOne(Wrappers.<User>lambdaQuery()
.eq(User::getMark, 1)
.eq(User::getUsername, username));
if(null == user){
return JsonResult.error("用户不存在");
}
//获取租户id
String tenantId = user.getTenantId();
//用户类型角色判断 1超级管理员 2 部门管理员 3普通用户
if(null == user.getType()){
throw new ServiceException(ServiceExceptionEnum.PARAMETER_IS_NULL);
}
//登录用户若为部门管理员或普通用户需要查询所在部门
String deptId = user.getDeptId();
//获取公路列表
List<RoadInformation> roadInformationList = new ArrayList<>();
if(null == deptId){
//超级管理员
if(UserTypeEnum.SUPER_ADMIN.getCode()== user.getType()){
roadInformationList = this.getAllRoadInformationList(tenantId);
}
}
//部门管理员
if(UserTypeEnum.ADMIN.getCode() == user.getType()){
//根据当前用户对应的部门id获取该部门及子部门的id集合
List<String> deptIdList = deptMapper.selectAllChildListById(deptId);
if(CollectionUtil.isEmpty(deptIdList)){
return null;
}
List<RoadDept> list = roadDeptMapper.selectListByDeptIdList(deptIdList);
roadInformationList = this.getRoadInformationList(tenantId, list);
}

//普通用户
if(UserTypeEnum.ORDINARY_USER.getCode() == user.getType()){
List<RoadDept> roadDeptList = roadDeptMapper.selectList(new LambdaQueryWrapper<RoadDept>()
.eq(RoadDept::getTenantId, tenantId)
.eq(RoadDept::getDeptId, deptId));
if (CollectionUtil.isEmpty(roadDeptList)) {
return null;
}
roadInformationList =this.getRoadInformationList(tenantId,roadDeptList);
}

return JsonResult.success(roadInformationList);
}

/**
* 根据部门列表获取公路列表
* @param tenantId
* @param list
* @return
*/
private List<RoadInformation> getRoadInformationList(String tenantId, List<RoadDept> list) {
List<RoadInformation> roadInformationList;
List<String> roadIdList = list.stream().map(o -> o.getRoadId()).collect(Collectors.toList());
Map<String, Object> map = new HashMap<>();
map.put("tenantId", tenantId);
map.put("roadIdList", roadIdList);
map.put("mark",1);
roadInformationList = roadInformationMapper.getListByMap(map);
return roadInformationList;
}

/**
* 如果是顶级部门,则查询所有公路列表
*
* @param tenantId
* @return
*/
private List<RoadInformation> getAllRoadInformationList(String tenantId) {
List<RoadInformation> roadList = roadInformationMapper.selectList(new LambdaQueryWrapper<RoadInformation>()
.eq(RoadInformation::getTenantId, tenantId)
.eq(RoadInformation::getMark, 1));
if (CollectionUtil.isEmpty(roadList)) {
return null;
}
return roadList;
}

/**
* 判断公路是否关联路段

+ 4
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/impl/StructureServiceImpl.java Dosyayı Görüntüle

@@ -120,6 +120,10 @@ public class StructureServiceImpl extends BaseServiceImpl<StructureMapper, Struc
return JsonResult.success();
}

/**
* 当前登录人对应的公路所属的构造物
* @return
*/
@Override
public JsonResult getSectionInfo() {
//获取登录信息

+ 1
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/road/query/QueryRoadListByDeptIdService.java Dosyayı Görüntüle

@@ -129,6 +129,7 @@ public class QueryRoadListByDeptIdService {
Map<String, Object> map = new HashMap<>();
map.put("tenantId", tenantId);
map.put("roadIdList", roadIdList);
map.put("mark",1);
List<RoadInformation> roadInformationList = roadInformationMapper.getListByMap(map);
return roadInformationList;
}

+ 49
- 38
tuoheng-service/tuoheng-admin/src/main/resources/mapper/RoadDeptMapper.xml Dosyayı Görüntüle

@@ -1,39 +1,50 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.tuoheng.admin.mapper.RoadDeptMapper">
<resultMap type="com.tuoheng.admin.entity.RoadDept" id="RoadDeptResult">
<result property="tenantId" column="tenant_id" />
<result property="roadId" column="road_id" />
<result property="deptId" column="dept_id" />
</resultMap>
<sql id="Base_Column_List">
tenant_id, road_id, dept_id
</sql>
<!-- 批量新增数据 -->
<insert id="insertBatch" parameterType="com.tuoheng.admin.entity.RoadDept">
insert into th_road_dept
(<include refid="Base_Column_List"/>)
VALUES
<foreach collection="list" item="item" index="index" separator=",">
( #{item.tenantId, jdbcType=INTEGER}, #{item.roadId,jdbcType=VARCHAR}, #{item.deptId, jdbcType=VARCHAR} )
</foreach>
</insert>
<!-- 批量删除数据 -->
<delete id="deleteBatchByMap" parameterType="hashmap">
delete from th_road_dept
where tenant_id = #{tenantId} and dept_id = #{deptId}
<if test="roadIdList != null and roadIdList.size() >0 ">
and road_id in
<foreach collection="roadIdList" item="roadId" separator="," open="(" close=")">
#{roadId}
</foreach>
</if>
</delete>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.tuoheng.admin.mapper.RoadDeptMapper">
<resultMap type="com.tuoheng.admin.entity.RoadDept" id="RoadDeptResult">
<result property="tenantId" column="tenant_id" />
<result property="roadId" column="road_id" />
<result property="deptId" column="dept_id" />
</resultMap>

<sql id="Base_Column_List">
tenant_id, road_id, dept_id
</sql>

<!-- 批量新增数据 -->
<insert id="insertBatch" parameterType="com.tuoheng.admin.entity.RoadDept">
insert into th_road_dept
(<include refid="Base_Column_List"/>)
VALUES
<foreach collection="list" item="item" index="index" separator=",">
( #{item.tenantId, jdbcType=INTEGER}, #{item.roadId,jdbcType=VARCHAR}, #{item.deptId, jdbcType=VARCHAR} )
</foreach>
</insert>

<!-- 批量删除数据 -->
<delete id="deleteBatchByMap" parameterType="hashmap">
delete from th_road_dept
where tenant_id = #{tenantId} and dept_id = #{deptId}
<if test="roadIdList != null and roadIdList.size() >0 ">
and road_id in
<foreach collection="roadIdList" item="roadId" separator="," open="(" close=")">
#{roadId}
</foreach>
</if>
</delete>
<select id="selectListByDeptIdList" resultType="list" resultMap="RoadDeptResult">
select <include refid="Base_Column_List"/>
from th_road_dept
where dept_id in
<foreach collection="list" item="deptId" separator="," open="(" close=")">
#{deptId}
</foreach>


</select>


</mapper>

+ 1
- 1
tuoheng-service/tuoheng-admin/src/main/resources/mapper/RoadInformationMapper.xml Dosyayı Görüntüle

@@ -27,7 +27,7 @@
<select id="getListByMap" parameterType="hashmap" resultMap="RoadInformationResult">
select <include refid="Base_Column_List"/>
from th_road
where tenant_id = #{tenantId} and id in
where mark = #{mark} and tenant_id = #{tenantId} and id in
<foreach collection="roadIdList" item="roadId" separator="," open="(" close=")">
#{roadId}
</foreach>

+ 29
- 0
tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/enums/UserTypeEnum.java Dosyayı Görüntüle

@@ -0,0 +1,29 @@
package com.tuoheng.miniprogram.enums;

import lombok.Getter;

/**
* 用户类型
*
* @author wanjing
* @team tuoheng
* @date 2022-11-25
*/
public enum UserTypeEnum {

SUPER_ADMIN(1,"超级管理员"),
ADMIN(2,"管理员"),
ORDINARY_USER(3,"普通用户");

UserTypeEnum(int code, String description){
this.code = code;
this.description = description;
}

@Getter
private int code;

@Getter
private String description;

}

Yükleniyor…
İptal
Kaydet