mirror of
https://gitee.com/orangeform/orange-admin.git
synced 2026-01-17 18:46:36 +08:00
created
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
package com.orange.admin;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class MyApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(MyApplication.class, args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.orange.admin.app.controller;
|
||||
|
||||
import cn.jimmyshi.beanquery.BeanQuery;
|
||||
import com.orange.admin.app.model.AreaCode;
|
||||
import com.orange.admin.app.service.AreaCodeService;
|
||||
import com.orange.admin.common.core.object.ResponseResult;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 行政区划数据访问接口类。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/admin/app/areaCode")
|
||||
public class AreaCodeController {
|
||||
|
||||
@Autowired
|
||||
private AreaCodeService areaCodeService;
|
||||
|
||||
/**
|
||||
* 按照字典的形式返回行政区划列表。
|
||||
*
|
||||
* @return 字典形式的行政区划列表。
|
||||
*/
|
||||
@GetMapping("/listDictAreaCode")
|
||||
public ResponseResult<?> listDictAreaCode() {
|
||||
List<AreaCode> resultList = areaCodeService.getAllList();
|
||||
return ResponseResult.success(BeanQuery.select(
|
||||
"parentId as parentId", "areaId as id", "areaName as name").executeFrom(resultList));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据上级行政区划Id获取其下级行政区划列表。
|
||||
*
|
||||
* @param parentId 上级行政区划Id。
|
||||
* @return 按照字典的形式返回下级行政区划列表。
|
||||
*/
|
||||
@GetMapping("/listDictAreaCodeByParentId")
|
||||
public ResponseResult<?> listDictAreaCodeByParentId(@RequestParam(required = false) Long parentId) {
|
||||
Collection<AreaCode> resultList = areaCodeService.getListByParentId(parentId);
|
||||
if (CollectionUtils.isEmpty(resultList)) {
|
||||
return ResponseResult.success(new LinkedList<>());
|
||||
}
|
||||
return ResponseResult.success(BeanQuery.select(
|
||||
"parentId as parentId", "areaId as id", "areaName as name").executeFrom(resultList));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,199 @@
|
||||
package com.orange.admin.app.controller;
|
||||
|
||||
import cn.jimmyshi.beanquery.BeanQuery;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.orange.admin.app.model.*;
|
||||
import com.orange.admin.app.service.*;
|
||||
import com.orange.admin.upms.model.*;
|
||||
import com.orange.admin.common.core.object.*;
|
||||
import com.orange.admin.common.core.util.*;
|
||||
import com.orange.admin.common.core.constant.ErrorCodeEnum;
|
||||
import com.orange.admin.common.core.annotation.MyRequestBody;
|
||||
import com.orange.admin.common.core.validator.UpdateGroup;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.*;
|
||||
import javax.validation.groups.Default;
|
||||
|
||||
/**
|
||||
* 老师数据源操作控制器类。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/admin/app/teacher")
|
||||
public class TeacherController {
|
||||
|
||||
@Autowired
|
||||
private TeacherService teacherService;
|
||||
|
||||
/**
|
||||
* 新增老师数据源数据。
|
||||
*
|
||||
* @param teacher 新增对象。
|
||||
* @return 应答结果对象,包含新增对象主键Id。
|
||||
*/
|
||||
@PostMapping("/add")
|
||||
public ResponseResult<?> add(@MyRequestBody Teacher teacher) {
|
||||
ErrorCodeEnum errorCodeEnum = ErrorCodeEnum.NO_ERROR;
|
||||
String errorMessage;
|
||||
JSONObject responseData = null;
|
||||
do {
|
||||
errorMessage = MyCommonUtil.getModelValidationError(teacher);
|
||||
if (errorMessage != null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_VALIDATAED_FAILED;
|
||||
break;
|
||||
}
|
||||
// 验证关联Id的数据合法性
|
||||
VerifyResult verifyResult = teacherService.verifyRelatedData(teacher, null);
|
||||
if (!verifyResult.isSuccess()) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_VALIDATAED_FAILED;
|
||||
errorMessage = verifyResult.getErrorMessage();
|
||||
break;
|
||||
}
|
||||
teacher = teacherService.saveNew(teacher);
|
||||
responseData = new JSONObject();
|
||||
responseData.put("teacherId", teacher.getTeacherId());
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage, responseData);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新老师数据源数据。
|
||||
*
|
||||
* @param teacher 更新对象。
|
||||
* @return 应答结果对象。
|
||||
*/
|
||||
@PostMapping("/update")
|
||||
public ResponseResult<?> update(@MyRequestBody Teacher teacher) {
|
||||
ErrorCodeEnum errorCodeEnum = ErrorCodeEnum.NO_ERROR;
|
||||
String errorMessage;
|
||||
do {
|
||||
errorMessage = MyCommonUtil.getModelValidationError(teacher, Default.class, UpdateGroup.class);
|
||||
if (errorMessage != null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_VALIDATAED_FAILED;
|
||||
break;
|
||||
}
|
||||
// 验证关联Id的数据合法性
|
||||
Teacher originalTeacher = teacherService.getById(teacher.getTeacherId());
|
||||
if (originalTeacher == null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
//TODO 修改下面方括号中的话述
|
||||
errorMessage = "数据验证失败,当前 [数据] 并不存在,请刷新后重试!";
|
||||
break;
|
||||
}
|
||||
// 验证关联Id的数据合法性
|
||||
VerifyResult verifyResult = teacherService.verifyRelatedData(teacher, originalTeacher);
|
||||
if (!verifyResult.isSuccess()) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_VALIDATAED_FAILED;
|
||||
errorMessage = verifyResult.getErrorMessage();
|
||||
break;
|
||||
}
|
||||
if (!teacherService.update(teacher, originalTeacher)) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
break;
|
||||
}
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除老师数据源数据。
|
||||
*
|
||||
* @param teacherId 删除对象主键Id。
|
||||
* @return 应答结果对象。
|
||||
*/
|
||||
@PostMapping("/delete")
|
||||
public ResponseResult<?> delete(@MyRequestBody Long teacherId) {
|
||||
ErrorCodeEnum errorCodeEnum = ErrorCodeEnum.NO_ERROR;
|
||||
String errorMessage = null;
|
||||
do {
|
||||
if (MyCommonUtil.existBlankArgument(teacherId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.ARGUMENT_NULL_EXIST;
|
||||
break;
|
||||
}
|
||||
// 验证关联Id的数据合法性
|
||||
Teacher originalTeacher = teacherService.getById(teacherId);
|
||||
if (originalTeacher == null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
//TODO 修改下面方括号中的话述
|
||||
errorMessage = "数据验证失败,当前 [对象] 并不存在,请刷新后重试!";
|
||||
break;
|
||||
}
|
||||
if (!teacherService.remove(teacherId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
errorMessage = "数据操作失败,删除的对象不存在,请刷新后重试!";
|
||||
break;
|
||||
}
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 列出符合过滤条件的老师数据源列表。
|
||||
*
|
||||
* @param teacherFilter 过滤对象。
|
||||
* @param sysDeptFilter 一对一从表过滤对象。
|
||||
* @param orderParam 排序参数。
|
||||
* @param pageParam 分页参数。
|
||||
* @return 应答结果对象,包含查询结果集。
|
||||
*/
|
||||
@PostMapping("/list")
|
||||
public ResponseResult<?> list(
|
||||
@MyRequestBody Teacher teacherFilter,
|
||||
@MyRequestBody SysDept sysDeptFilter,
|
||||
@MyRequestBody MyOrderParam orderParam,
|
||||
@MyRequestBody MyPageParam pageParam) {
|
||||
if (pageParam != null) {
|
||||
PageHelper.startPage(pageParam.getPageNum(), pageParam.getPageSize());
|
||||
}
|
||||
String orderBy = MyOrderParam.buildOrderBy(orderParam, Teacher.class);
|
||||
List<Teacher> resultList =
|
||||
teacherService.getTeacherListWithRelation(teacherFilter, sysDeptFilter, orderBy);
|
||||
return ResponseResult.success(MyPageUtil.makeResponseData(resultList));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看指定老师数据源对象详情。
|
||||
*
|
||||
* @param teacherId 指定对象主键Id。
|
||||
* @return 应答结果对象,包含对象详情。
|
||||
*/
|
||||
@GetMapping("/view")
|
||||
public ResponseResult<Teacher> view(@RequestParam Long teacherId) {
|
||||
ErrorCodeEnum errorCodeEnum = ErrorCodeEnum.NO_ERROR;
|
||||
String errorMessage = null;
|
||||
Teacher teacher = null;
|
||||
do {
|
||||
if (MyCommonUtil.existBlankArgument(teacherId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.ARGUMENT_NULL_EXIST;
|
||||
break;
|
||||
}
|
||||
teacher = teacherService.getByIdWithRelation(teacherId);
|
||||
if (teacher == null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
break;
|
||||
}
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage, teacher);
|
||||
}
|
||||
|
||||
/**
|
||||
* 以字典形式返回全部老师数据源数据集合。字典的键值为[teacherId, teacherName]。
|
||||
* 白名单接口,登录用户均可访问。
|
||||
*
|
||||
* @param filter 过滤对象。
|
||||
* @return 应答结果对象,包含的数据为 List<Map<String, String>>,map中包含两条记录,key的值分别是id和name,value对应具体数据。
|
||||
*/
|
||||
@GetMapping("/listDictTeacher")
|
||||
public ResponseResult<?> listDictTeacher(Teacher filter) {
|
||||
List<Teacher> resultList = teacherService.getListByFilter(filter);
|
||||
return ResponseResult.success(BeanQuery.select(
|
||||
"teacherId as id", "teacherName as name").executeFrom(resultList));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
package com.orange.admin.app.controller;
|
||||
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.orange.admin.app.model.*;
|
||||
import com.orange.admin.app.service.*;
|
||||
import com.orange.admin.common.core.object.*;
|
||||
import com.orange.admin.common.core.util.*;
|
||||
import com.orange.admin.common.core.constant.ErrorCodeEnum;
|
||||
import com.orange.admin.common.core.annotation.MyRequestBody;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 老师流水统计操作控制器类。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/admin/app/teacherTransStats")
|
||||
public class TeacherTransStatsController {
|
||||
|
||||
@Autowired
|
||||
private TeacherTransStatsService teacherTransStatsService;
|
||||
|
||||
/**
|
||||
* 列出符合过滤条件的老师流水统计列表。
|
||||
*
|
||||
* @param teacherTransStatsFilter 过滤对象。
|
||||
* @param orderParam 排序参数。
|
||||
* @param pageParam 分页参数。
|
||||
* @return 应答结果对象,包含查询结果集。
|
||||
*/
|
||||
@PostMapping("/list")
|
||||
public ResponseResult<?> list(
|
||||
@MyRequestBody TeacherTransStats teacherTransStatsFilter,
|
||||
@MyRequestBody MyOrderParam orderParam,
|
||||
@MyRequestBody MyPageParam pageParam) {
|
||||
if (pageParam != null) {
|
||||
PageHelper.startPage(pageParam.getPageNum(), pageParam.getPageSize());
|
||||
}
|
||||
String orderBy = MyOrderParam.buildOrderBy(orderParam, TeacherTransStats.class);
|
||||
List<TeacherTransStats> resultList = teacherTransStatsService.getTeacherTransStatsListWithRelation(teacherTransStatsFilter, orderBy);
|
||||
return ResponseResult.success(MyPageUtil.makeResponseData(resultList));
|
||||
}
|
||||
|
||||
/**
|
||||
* 分组列出符合过滤条件的老师流水统计列表。
|
||||
*
|
||||
* @param teacherTransStatsFilter 过滤对象。
|
||||
* @param groupParam 分组参数。
|
||||
* @param orderParam 排序参数。
|
||||
* @param pageParam 分页参数。
|
||||
* @return 应答结果对象,包含查询结果集。
|
||||
*/
|
||||
@PostMapping("/listWithGroup")
|
||||
public ResponseResult<?> listWithGroup(
|
||||
@MyRequestBody TeacherTransStats teacherTransStatsFilter,
|
||||
@MyRequestBody MyGroupParam groupParam,
|
||||
@MyRequestBody MyOrderParam orderParam,
|
||||
@MyRequestBody MyPageParam pageParam) {
|
||||
String orderBy = MyOrderParam.buildOrderBy(orderParam, TeacherTransStats.class);
|
||||
groupParam = MyGroupParam.buildGroupBy(groupParam, TeacherTransStats.class);
|
||||
if (groupParam == null) {
|
||||
return ResponseResult.error(
|
||||
ErrorCodeEnum.INVALID_ARGUMENT_FORMAT, "数据参数错误,分组参数不能为空!");
|
||||
}
|
||||
if (pageParam != null) {
|
||||
PageHelper.startPage(pageParam.getPageNum(), pageParam.getPageSize());
|
||||
}
|
||||
MyGroupCriteria criteria = groupParam.getGroupCriteria();
|
||||
List<TeacherTransStats> resultList = teacherTransStatsService.getGroupedTeacherTransStatsListWithRelation(
|
||||
teacherTransStatsFilter, criteria.getGroupSelect(), criteria.getGroupBy(), orderBy);
|
||||
return ResponseResult.success(MyPageUtil.makeResponseData(resultList));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看指定老师流水统计对象详情。
|
||||
*
|
||||
* @param statsId 指定对象主键Id。
|
||||
* @return 应答结果对象,包含对象详情。
|
||||
*/
|
||||
@GetMapping("/view")
|
||||
public ResponseResult<TeacherTransStats> view(@RequestParam Long statsId) {
|
||||
ErrorCodeEnum errorCodeEnum = ErrorCodeEnum.NO_ERROR;
|
||||
String errorMessage = null;
|
||||
TeacherTransStats teacherTransStats = null;
|
||||
do {
|
||||
if (MyCommonUtil.existBlankArgument(statsId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.ARGUMENT_NULL_EXIST;
|
||||
break;
|
||||
}
|
||||
teacherTransStats = teacherTransStatsService.getByIdWithRelation(statsId);
|
||||
if (teacherTransStats == null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
break;
|
||||
}
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage, teacherTransStats);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.orange.admin.app.dao;
|
||||
|
||||
import com.orange.admin.common.core.base.dao.BaseDaoMapper;
|
||||
import com.orange.admin.app.model.AreaCode;
|
||||
|
||||
/**
|
||||
* 行政区划数据操作访问接口。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
*/
|
||||
public interface AreaCodeMapper extends BaseDaoMapper<AreaCode> {
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.orange.admin.app.dao;
|
||||
|
||||
import com.orange.admin.common.core.annotation.EnableDataPerm;
|
||||
import com.orange.admin.common.core.base.dao.BaseDaoMapper;
|
||||
import com.orange.admin.app.model.Teacher;
|
||||
import com.orange.admin.upms.model.SysDept;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 老师数据源数据操作访问接口。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
*/
|
||||
@EnableDataPerm
|
||||
public interface TeacherMapper extends BaseDaoMapper<Teacher> {
|
||||
|
||||
/**
|
||||
* 获取过滤后的对象列表。
|
||||
*
|
||||
* @param teacherFilter 主表过滤对象。
|
||||
* @param orderBy 排序字符串,order by从句的参数。
|
||||
* @return 对象列表。
|
||||
*/
|
||||
List<Teacher> getTeacherList(
|
||||
@Param("teacherFilter") Teacher teacherFilter, @Param("orderBy") String orderBy);
|
||||
|
||||
/**
|
||||
* 获取过滤后的对象列表。同时支持基于一对一从表字段的过滤条件。
|
||||
*
|
||||
* @param teacherFilter 主表过滤对象。
|
||||
* @param sysDeptFilter 一对一从表过滤对象。
|
||||
* @param orderBy 排序字符串,order by从句的参数。
|
||||
* @return 对象列表。
|
||||
*/
|
||||
List<Teacher> getTeacherListEx(
|
||||
@Param("teacherFilter") Teacher teacherFilter,
|
||||
@Param("sysDeptFilter") SysDept sysDeptFilter,
|
||||
@Param("orderBy") String orderBy);
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.orange.admin.app.dao;
|
||||
|
||||
import com.orange.admin.common.core.annotation.EnableDataPerm;
|
||||
import com.orange.admin.common.core.base.dao.BaseDaoMapper;
|
||||
import com.orange.admin.app.model.TeacherTransStats;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 老师流水统计数据操作访问接口。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
*/
|
||||
@EnableDataPerm
|
||||
public interface TeacherTransStatsMapper extends BaseDaoMapper<TeacherTransStats> {
|
||||
|
||||
/**
|
||||
* 获取分组计算后的数据对象列表。
|
||||
*
|
||||
* @param teacherTransStatsFilter 主表过滤对象。
|
||||
* @param groupSelect 分组显示字段列表字符串,SELECT从句的参数。
|
||||
* @param groupBy 分组字段列表字符串,GROUP BY从句的参数。
|
||||
* @param orderBy 排序字符串,ORDER BY从句的参数。
|
||||
* @return 对象列表。
|
||||
*/
|
||||
List<TeacherTransStats> getGroupedTeacherTransStatsList(
|
||||
@Param("teacherTransStatsFilter") TeacherTransStats teacherTransStatsFilter,
|
||||
@Param("groupSelect") String groupSelect,
|
||||
@Param("groupBy") String groupBy,
|
||||
@Param("orderBy") String orderBy);
|
||||
|
||||
/**
|
||||
* 获取过滤后的对象列表。
|
||||
*
|
||||
* @param teacherTransStatsFilter 主表过滤对象。
|
||||
* @param orderBy 排序字符串,order by从句的参数。
|
||||
* @return 对象列表。
|
||||
*/
|
||||
List<TeacherTransStats> getTeacherTransStatsList(
|
||||
@Param("teacherTransStatsFilter") TeacherTransStats teacherTransStatsFilter, @Param("orderBy") String orderBy);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?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.orange.admin.app.dao.AreaCodeMapper">
|
||||
<resultMap id="BaseResultMap" type="com.orange.admin.app.model.AreaCode">
|
||||
<id column="area_id" jdbcType="BIGINT" property="areaId"/>
|
||||
<result column="area_name" jdbcType="VARCHAR" property="areaName"/>
|
||||
<result column="area_level" jdbcType="INTEGER" property="areaLevel"/>
|
||||
<result column="parent_id" jdbcType="BIGINT" property="parentId"/>
|
||||
</resultMap>
|
||||
</mapper>
|
||||
@@ -0,0 +1,80 @@
|
||||
<?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.orange.admin.app.dao.TeacherMapper">
|
||||
<resultMap id="BaseResultMap" type="com.orange.admin.app.model.Teacher">
|
||||
<id column="teacher_id" jdbcType="BIGINT" property="teacherId"/>
|
||||
<result column="teacher_name" jdbcType="VARCHAR" property="teacherName"/>
|
||||
<result column="birthday" jdbcType="DATE" property="birthday"/>
|
||||
<result column="gender" jdbcType="INTEGER" property="gender"/>
|
||||
<result column="subject_id" jdbcType="INTEGER" property="subjectId"/>
|
||||
<result column="level" jdbcType="INTEGER" property="level"/>
|
||||
<result column="flower_count" jdbcType="INTEGER" property="flowerCount"/>
|
||||
<result column="school_id" jdbcType="BIGINT" property="schoolId"/>
|
||||
<result column="user_id" jdbcType="BIGINT" property="userId"/>
|
||||
<result column="register_date" jdbcType="TIMESTAMP" property="registerDate"/>
|
||||
<result column="available" jdbcType="BIT" property="available"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="filterRef">
|
||||
<if test="teacherFilter != null">
|
||||
<if test="teacherFilter.teacherName != null and teacherFilter.teacherName != ''">
|
||||
<bind name = "safeTeacherName" value = "'%' + teacherFilter.teacherName + '%'" />
|
||||
AND zz_teacher.teacher_name LIKE #{safeTeacherName}
|
||||
</if>
|
||||
<if test="teacherFilter.birthdayStart != null and teacherFilter.birthdayStart != ''">
|
||||
AND zz_teacher.birthday >= #{teacherFilter.birthdayStart}
|
||||
</if>
|
||||
<if test="teacherFilter.birthdayEnd != null and teacherFilter.birthdayEnd != ''">
|
||||
AND zz_teacher.birthday <= #{teacherFilter.birthdayEnd}
|
||||
</if>
|
||||
<if test="teacherFilter.gender != null">
|
||||
AND zz_teacher.gender = #{teacherFilter.gender}
|
||||
</if>
|
||||
<if test="teacherFilter.subjectId != null">
|
||||
AND zz_teacher.subject_id = #{teacherFilter.subjectId}
|
||||
</if>
|
||||
<if test="teacherFilter.level != null">
|
||||
AND zz_teacher.level = #{teacherFilter.level}
|
||||
</if>
|
||||
<if test="teacherFilter.schoolId != null">
|
||||
AND zz_teacher.school_id = #{teacherFilter.schoolId}
|
||||
</if>
|
||||
<if test="teacherFilter.registerDateStart != null and teacherFilter.registerDateStart != ''">
|
||||
AND zz_teacher.register_date >= #{teacherFilter.registerDateStart}
|
||||
</if>
|
||||
<if test="teacherFilter.registerDateEnd != null and teacherFilter.registerDateEnd != ''">
|
||||
AND zz_teacher.register_date <= #{teacherFilter.registerDateEnd}
|
||||
</if>
|
||||
<if test="teacherFilter.available != null">
|
||||
AND zz_teacher.available = #{teacherFilter.available}
|
||||
</if>
|
||||
</if>
|
||||
</sql>
|
||||
|
||||
<select id="getTeacherList" resultMap="BaseResultMap" parameterType="com.orange.admin.app.model.Teacher">
|
||||
SELECT * FROM zz_teacher
|
||||
<where>
|
||||
<include refid="filterRef"/>
|
||||
</where>
|
||||
<if test="orderBy != null">
|
||||
ORDER BY ${orderBy}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<!-- 支持基于一对一从表字段过滤的SQL_ID -->
|
||||
<select id="getTeacherListEx" resultMap="BaseResultMap" >
|
||||
SELECT
|
||||
zz_teacher.*
|
||||
FROM
|
||||
zz_teacher
|
||||
LEFT JOIN
|
||||
zz_sys_dept ON zz_teacher.school_id = zz_sys_dept.dept_id
|
||||
<where>
|
||||
<include refid="filterRef"/>
|
||||
<include refid="com.orange.admin.upms.dao.SysDeptMapper.filterRef"/>
|
||||
</where>
|
||||
<if test="orderBy != null">
|
||||
ORDER BY ${orderBy}
|
||||
</if>
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,62 @@
|
||||
<?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.orange.admin.app.dao.TeacherTransStatsMapper">
|
||||
<resultMap id="BaseResultMap" type="com.orange.admin.app.model.TeacherTransStats">
|
||||
<id column="stats_id" jdbcType="BIGINT" property="statsId"/>
|
||||
<result column="stats_date" jdbcType="DATE" property="statsDate"/>
|
||||
<result column="stats_month" jdbcType="DATE" property="statsMonth"/>
|
||||
<result column="province_id" jdbcType="BIGINT" property="provinceId"/>
|
||||
<result column="city_id" jdbcType="BIGINT" property="cityId"/>
|
||||
<result column="school_id" jdbcType="BIGINT" property="schoolId"/>
|
||||
<result column="school_name" jdbcType="VARCHAR" property="schoolName"/>
|
||||
<result column="teacher_id" jdbcType="BIGINT" property="teacherId"/>
|
||||
<result column="teacher_name" jdbcType="VARCHAR" property="teacherName"/>
|
||||
<result column="video_watch_count" jdbcType="INTEGER" property="videoWatchCount"/>
|
||||
<result column="flower_count" jdbcType="INTEGER" property="flowerCount"/>
|
||||
<result column="new_student" jdbcType="INTEGER" property="newStudent"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="filterRef">
|
||||
<if test="teacherTransStatsFilter != null">
|
||||
<if test="teacherTransStatsFilter.statsDateStart != null and teacherTransStatsFilter.statsDateStart != ''">
|
||||
AND zz_teacher_trans_stats.stats_date >= #{teacherTransStatsFilter.statsDateStart}
|
||||
</if>
|
||||
<if test="teacherTransStatsFilter.statsDateEnd != null and teacherTransStatsFilter.statsDateEnd != ''">
|
||||
AND zz_teacher_trans_stats.stats_date <= #{teacherTransStatsFilter.statsDateEnd}
|
||||
</if>
|
||||
<if test="teacherTransStatsFilter.schoolId != null">
|
||||
AND zz_teacher_trans_stats.school_id = #{teacherTransStatsFilter.schoolId}
|
||||
</if>
|
||||
<if test="teacherTransStatsFilter.teacherId != null">
|
||||
AND zz_teacher_trans_stats.teacher_id = #{teacherTransStatsFilter.teacherId}
|
||||
</if>
|
||||
</if>
|
||||
</sql>
|
||||
|
||||
<select id="getGroupedTeacherTransStatsList" resultMap="BaseResultMap" parameterType="com.orange.admin.app.model.TeacherTransStats">
|
||||
SELECT * FROM
|
||||
(SELECT
|
||||
SUM(video_watch_count) video_watch_count,
|
||||
SUM(flower_count) flower_count,
|
||||
SUM(new_student) new_student,
|
||||
${groupSelect}
|
||||
FROM zz_teacher_trans_stats
|
||||
<where>
|
||||
<include refid="filterRef"/>
|
||||
</where>
|
||||
GROUP BY ${groupBy}) zz_teacher_trans_stats
|
||||
<if test="orderBy != null">
|
||||
ORDER BY ${orderBy}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<select id="getTeacherTransStatsList" resultMap="BaseResultMap" parameterType="com.orange.admin.app.model.TeacherTransStats">
|
||||
SELECT * FROM zz_teacher_trans_stats
|
||||
<where>
|
||||
<include refid="filterRef"/>
|
||||
</where>
|
||||
<if test="orderBy != null">
|
||||
ORDER BY ${orderBy}
|
||||
</if>
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.orange.admin.app.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
@Data
|
||||
@Table(name = "zz_area_code")
|
||||
public class AreaCode {
|
||||
|
||||
/**
|
||||
* 行政区划主键Id
|
||||
*/
|
||||
@Id
|
||||
@Column(name = "area_id")
|
||||
private Long areaId;
|
||||
|
||||
/**
|
||||
* 行政区划名称
|
||||
*/
|
||||
@Column(name = "area_name")
|
||||
private String areaName;
|
||||
|
||||
/**
|
||||
* 行政区划级别 (1: 省级别 2: 市级别 3: 区级别)
|
||||
*/
|
||||
@Column(name = "area_level")
|
||||
private Integer areaLevel;
|
||||
|
||||
/**
|
||||
* 父级行政区划Id
|
||||
*/
|
||||
@Column(name = "parent_id")
|
||||
private Long parentId;
|
||||
}
|
||||
@@ -0,0 +1,179 @@
|
||||
package com.orange.admin.app.model;
|
||||
|
||||
import com.orange.admin.upms.model.SysDept;
|
||||
import com.orange.admin.upms.model.SysUser;
|
||||
import com.orange.admin.app.model.constant.Gender;
|
||||
import com.orange.admin.common.biz.constant.Subject;
|
||||
import com.orange.admin.app.model.constant.TeacherLevelType;
|
||||
import com.orange.admin.common.biz.constant.YesNo;
|
||||
import com.orange.admin.common.core.annotation.RelationDict;
|
||||
import com.orange.admin.common.core.annotation.RelationConstDict;
|
||||
import com.orange.admin.common.core.annotation.RelationOneToOne;
|
||||
import com.orange.admin.common.core.annotation.DeptFilterColumn;
|
||||
import com.orange.admin.common.core.annotation.UserFilterColumn;
|
||||
import com.orange.admin.common.core.validator.UpdateGroup;
|
||||
import com.orange.admin.common.core.validator.ConstDictRef;
|
||||
import lombok.Data;
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
@Data
|
||||
@Table(name = "zz_teacher")
|
||||
public class Teacher {
|
||||
|
||||
/**
|
||||
* 主键Id。
|
||||
*/
|
||||
@NotNull(message = "数据验证失败,主键Id不能为空!", groups = {UpdateGroup.class})
|
||||
@Id
|
||||
@UserFilterColumn
|
||||
@Column(name = "teacher_id")
|
||||
private Long teacherId;
|
||||
|
||||
/**
|
||||
* 教师名称。
|
||||
*/
|
||||
@NotBlank(message = "数据验证失败,教师名称不能为空!")
|
||||
@Column(name = "teacher_name")
|
||||
private String teacherName;
|
||||
|
||||
/**
|
||||
* 教师生日。
|
||||
*/
|
||||
@NotNull(message = "数据验证失败,出生日期不能为空!")
|
||||
private Date birthday;
|
||||
|
||||
/**
|
||||
* 教师性别(0: 女 1: 男)。
|
||||
*/
|
||||
@NotNull(message = "数据验证失败,性别不能为空!")
|
||||
@ConstDictRef(constDictClass = Gender.class, message = "数据验证失败,性别为无效值!")
|
||||
private Integer gender;
|
||||
|
||||
/**
|
||||
* 所教的科目Id。
|
||||
*/
|
||||
@NotNull(message = "数据验证失败,所教科目不能为空!")
|
||||
@ConstDictRef(constDictClass = Subject.class, message = "数据验证失败,所教科目为无效值!")
|
||||
@Column(name = "subject_id")
|
||||
private Integer subjectId;
|
||||
|
||||
/**
|
||||
* 教师职级(0: 初级 1: 中级 2: 高级)。
|
||||
*/
|
||||
@NotNull(message = "数据验证失败,职级不能为空!")
|
||||
@ConstDictRef(constDictClass = TeacherLevelType.class, message = "数据验证失败,职级为无效值!")
|
||||
private Integer level;
|
||||
|
||||
/**
|
||||
* 鲜花数量。
|
||||
*/
|
||||
@Column(name = "flower_count")
|
||||
private Integer flowerCount;
|
||||
|
||||
/**
|
||||
* 校区Id。
|
||||
*/
|
||||
@NotNull(message = "数据验证失败,所属校区不能为空!")
|
||||
@DeptFilterColumn
|
||||
@Column(name = "school_id")
|
||||
private Long schoolId;
|
||||
|
||||
/**
|
||||
* 用户Id。
|
||||
*/
|
||||
@NotNull(message = "数据验证失败,绑定用户不能为空!")
|
||||
@Column(name = "user_id")
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 入职时间。
|
||||
*/
|
||||
@Column(name = "register_date")
|
||||
private Date registerDate;
|
||||
|
||||
/**
|
||||
* 是否在职。
|
||||
*/
|
||||
@NotNull(message = "数据验证失败,是否在职不能为空!")
|
||||
@ConstDictRef(constDictClass = YesNo.class, message = "数据验证失败,是否在职为无效值!")
|
||||
private Integer available;
|
||||
|
||||
/**
|
||||
* birthday 范围过滤起始值(>=)。
|
||||
*/
|
||||
@Transient
|
||||
private String birthdayStart;
|
||||
|
||||
/**
|
||||
* birthday 范围过滤结束值(<=)。
|
||||
*/
|
||||
@Transient
|
||||
private String birthdayEnd;
|
||||
|
||||
/**
|
||||
* registerDate 范围过滤起始值(>=)。
|
||||
*/
|
||||
@Transient
|
||||
private String registerDateStart;
|
||||
|
||||
/**
|
||||
* registerDate 范围过滤结束值(<=)。
|
||||
*/
|
||||
@Transient
|
||||
private String registerDateEnd;
|
||||
|
||||
@RelationOneToOne(
|
||||
masterIdField = "schoolId",
|
||||
slaveServiceName = "sysDeptService",
|
||||
slaveModelClass = SysDept.class,
|
||||
slaveIdField = "deptId")
|
||||
@Transient
|
||||
private SysDept sysDept;
|
||||
|
||||
@RelationDict(
|
||||
masterIdField = "schoolId",
|
||||
slaveServiceName = "sysDeptService",
|
||||
equalOneToOneRelationField = "sysDept",
|
||||
slaveModelClass = SysDept.class,
|
||||
slaveIdField = "deptId",
|
||||
slaveNameField = "deptName")
|
||||
@Transient
|
||||
private Map<String, Object> schoolIdDictMap;
|
||||
|
||||
@RelationDict(
|
||||
masterIdField = "userId",
|
||||
slaveServiceName = "sysUserService",
|
||||
slaveModelClass = SysUser.class,
|
||||
slaveIdField = "userId",
|
||||
slaveNameField = "loginName")
|
||||
@Transient
|
||||
private Map<String, Object> userIdDictMap;
|
||||
|
||||
@RelationConstDict(
|
||||
masterIdField = "gender",
|
||||
constantDictClass = Gender.class)
|
||||
@Transient
|
||||
private Map<String, Object> genderDictMap;
|
||||
|
||||
@RelationConstDict(
|
||||
masterIdField = "subjectId",
|
||||
constantDictClass = Subject.class)
|
||||
@Transient
|
||||
private Map<String, Object> subjectIdDictMap;
|
||||
|
||||
@RelationConstDict(
|
||||
masterIdField = "level",
|
||||
constantDictClass = TeacherLevelType.class)
|
||||
@Transient
|
||||
private Map<String, Object> levelDictMap;
|
||||
|
||||
@RelationConstDict(
|
||||
masterIdField = "available",
|
||||
constantDictClass = YesNo.class)
|
||||
@Transient
|
||||
private Map<String, Object> availableDictMap;
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
package com.orange.admin.app.model;
|
||||
|
||||
import com.orange.admin.upms.model.SysDept;
|
||||
import com.orange.admin.common.core.annotation.RelationDict;
|
||||
import com.orange.admin.common.core.annotation.RelationOneToOne;
|
||||
import com.orange.admin.common.core.annotation.DeptFilterColumn;
|
||||
import com.orange.admin.common.core.annotation.UserFilterColumn;
|
||||
import com.orange.admin.common.core.validator.UpdateGroup;
|
||||
import lombok.Data;
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
@Data
|
||||
@Table(name = "zz_teacher_trans_stats")
|
||||
public class TeacherTransStats {
|
||||
|
||||
/**
|
||||
* 主键Id。
|
||||
*/
|
||||
@NotNull(message = "数据验证失败,主键Id不能为空!", groups = {UpdateGroup.class})
|
||||
@Id
|
||||
@Column(name = "stats_id")
|
||||
private Long statsId;
|
||||
|
||||
/**
|
||||
* 统计日期。
|
||||
*/
|
||||
@NotNull(message = "数据验证失败,统计日期不能为空!")
|
||||
@Column(name = "stats_date")
|
||||
private Date statsDate;
|
||||
|
||||
/**
|
||||
* 统计月份。
|
||||
*/
|
||||
@NotNull(message = "数据验证失败,统计月份不能为空!")
|
||||
@Column(name = "stats_month")
|
||||
private Date statsMonth;
|
||||
|
||||
/**
|
||||
* 省份Id。
|
||||
*/
|
||||
@NotNull(message = "数据验证失败,省份不能为空!")
|
||||
@Column(name = "province_id")
|
||||
private Long provinceId;
|
||||
|
||||
/**
|
||||
* 城市Id。
|
||||
*/
|
||||
@NotNull(message = "数据验证失败,城市不能为空!")
|
||||
@Column(name = "city_id")
|
||||
private Long cityId;
|
||||
|
||||
/**
|
||||
* 学校Id。
|
||||
*/
|
||||
@NotNull(message = "数据验证失败,校区不能为空!")
|
||||
@DeptFilterColumn
|
||||
@Column(name = "school_id")
|
||||
private Long schoolId;
|
||||
|
||||
/**
|
||||
* 学校名称。
|
||||
*/
|
||||
@NotBlank(message = "数据验证失败,学校名称不能为空!")
|
||||
@Column(name = "school_name")
|
||||
private String schoolName;
|
||||
|
||||
/**
|
||||
* 老师Id。
|
||||
*/
|
||||
@NotNull(message = "数据验证失败,老师不能为空!")
|
||||
@UserFilterColumn
|
||||
@Column(name = "teacher_id")
|
||||
private Long teacherId;
|
||||
|
||||
/**
|
||||
* 老师名称。
|
||||
*/
|
||||
@NotBlank(message = "数据验证失败,老师名称不能为空!")
|
||||
@Column(name = "teacher_name")
|
||||
private String teacherName;
|
||||
|
||||
/**
|
||||
* 视频观看数量。
|
||||
*/
|
||||
@NotNull(message = "数据验证失败,视频观看数量不能为空!")
|
||||
@Column(name = "video_watch_count")
|
||||
private Integer videoWatchCount;
|
||||
|
||||
/**
|
||||
* 献花数量。
|
||||
*/
|
||||
@NotNull(message = "数据验证失败,献花数量不能为空!")
|
||||
@Column(name = "flower_count")
|
||||
private Integer flowerCount;
|
||||
|
||||
/**
|
||||
* 新增学生数量。
|
||||
*/
|
||||
@NotNull(message = "数据验证失败,新增学生数量不能为空!")
|
||||
@Column(name = "new_student")
|
||||
private Integer newStudent;
|
||||
|
||||
/**
|
||||
* statsDate 范围过滤起始值(>=)。
|
||||
*/
|
||||
@Transient
|
||||
private String statsDateStart;
|
||||
|
||||
/**
|
||||
* statsDate 范围过滤结束值(<=)。
|
||||
*/
|
||||
@Transient
|
||||
private String statsDateEnd;
|
||||
|
||||
@RelationOneToOne(
|
||||
masterIdField = "schoolId",
|
||||
slaveServiceName = "sysDeptService",
|
||||
slaveModelClass = SysDept.class,
|
||||
slaveIdField = "deptId")
|
||||
@Transient
|
||||
private SysDept sysDept;
|
||||
|
||||
@RelationOneToOne(
|
||||
masterIdField = "teacherId",
|
||||
slaveServiceName = "teacherService",
|
||||
slaveModelClass = Teacher.class,
|
||||
slaveIdField = "teacherId")
|
||||
@Transient
|
||||
private Teacher teacher;
|
||||
|
||||
@RelationDict(
|
||||
masterIdField = "provinceId",
|
||||
slaveServiceName = "areaCodeService",
|
||||
slaveModelClass = AreaCode.class,
|
||||
slaveIdField = "areaId",
|
||||
slaveNameField = "areaName")
|
||||
@Transient
|
||||
private Map<String, Object> provinceIdDictMap;
|
||||
|
||||
@RelationDict(
|
||||
masterIdField = "cityId",
|
||||
slaveServiceName = "areaCodeService",
|
||||
slaveModelClass = AreaCode.class,
|
||||
slaveIdField = "areaId",
|
||||
slaveNameField = "areaName")
|
||||
@Transient
|
||||
private Map<String, Object> cityIdDictMap;
|
||||
|
||||
@RelationDict(
|
||||
masterIdField = "schoolId",
|
||||
slaveServiceName = "sysDeptService",
|
||||
equalOneToOneRelationField = "sysDept",
|
||||
slaveModelClass = SysDept.class,
|
||||
slaveIdField = "deptId",
|
||||
slaveNameField = "deptName")
|
||||
@Transient
|
||||
private Map<String, Object> schoolIdDictMap;
|
||||
|
||||
@RelationDict(
|
||||
masterIdField = "teacherId",
|
||||
slaveServiceName = "teacherService",
|
||||
equalOneToOneRelationField = "teacher",
|
||||
slaveModelClass = Teacher.class,
|
||||
slaveIdField = "teacherId",
|
||||
slaveNameField = "teacherName")
|
||||
@Transient
|
||||
private Map<String, Object> teacherIdDictMap;
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.orange.admin.app.model.constant;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public final class Gender {
|
||||
|
||||
/**
|
||||
* 男。
|
||||
*/
|
||||
public static final int MALE = 1;
|
||||
/**
|
||||
* 女。
|
||||
*/
|
||||
public static final int FEMALE = 0;
|
||||
|
||||
public static final Map<Object, String> DICT_MAP = new HashMap<>(2);
|
||||
static {
|
||||
DICT_MAP.put(MALE, "男");
|
||||
DICT_MAP.put(FEMALE, "女");
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断参数是否为当前常量字典的合法值。
|
||||
*
|
||||
* @param value 待验证的参数值。
|
||||
* @return 合法返回true,否则false。
|
||||
*/
|
||||
public static boolean isValid(int value) {
|
||||
return DICT_MAP.containsKey(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 私有构造函数,明确标识该常量类的作用。
|
||||
*/
|
||||
private Gender() {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.orange.admin.app.model.constant;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public final class TeacherLevelType {
|
||||
|
||||
/**
|
||||
* 初级。
|
||||
*/
|
||||
public static final int LOWER = 0;
|
||||
/**
|
||||
* 中级。
|
||||
*/
|
||||
public static final int NORMAL = 1;
|
||||
/**
|
||||
* 高级。
|
||||
*/
|
||||
public static final int HIGH = 2;
|
||||
|
||||
public static final Map<Object, String> DICT_MAP = new HashMap<>(3);
|
||||
static {
|
||||
DICT_MAP.put(LOWER, "初级");
|
||||
DICT_MAP.put(NORMAL, "中级");
|
||||
DICT_MAP.put(HIGH, "高级");
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断参数是否为当前常量字典的合法值。
|
||||
*
|
||||
* @param value 待验证的参数值。
|
||||
* @return 合法返回true,否则false。
|
||||
*/
|
||||
public static boolean isValid(int value) {
|
||||
return DICT_MAP.containsKey(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 私有构造函数,明确标识该常量类的作用。
|
||||
*/
|
||||
private TeacherLevelType() {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.orange.admin.app.service;
|
||||
|
||||
import com.orange.admin.app.dao.AreaCodeMapper;
|
||||
import com.orange.admin.app.model.AreaCode;
|
||||
import com.orange.admin.common.core.cache.MapTreeDictionaryCache;
|
||||
import com.orange.admin.common.core.base.service.BaseDictService;
|
||||
import com.orange.admin.common.core.base.dao.BaseDaoMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import tk.mybatis.mapper.entity.Example;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 行政区划的Service类。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
*/
|
||||
@Service
|
||||
public class AreaCodeService extends BaseDictService<AreaCode, Long> {
|
||||
|
||||
@Autowired
|
||||
private AreaCodeMapper areaCodeMapper;
|
||||
|
||||
public AreaCodeService() {
|
||||
super();
|
||||
this.dictionaryCache = MapTreeDictionaryCache.create(AreaCode::getAreaId, AreaCode::getParentId);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BaseDaoMapper<AreaCode> mapper() {
|
||||
return areaCodeMapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载数据库数据到内存缓存。
|
||||
*/
|
||||
@Override
|
||||
public void loadCachedData() {
|
||||
Example e = new Example(AreaCode.class);
|
||||
e.orderBy("areaLevel");
|
||||
List<AreaCode> areaCodeList = areaCodeMapper.selectByExample(e);
|
||||
dictionaryCache.putAll(areaCodeList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据上级行政区划Id,获取其下级行政区划列表。
|
||||
*
|
||||
* @param parentId 上级行政区划Id。
|
||||
* @return 下级行政区划列表。
|
||||
*/
|
||||
public Collection<AreaCode> getListByParentId(Long parentId) {
|
||||
return ((MapTreeDictionaryCache<Long, AreaCode>) dictionaryCache).getListByParentId(parentId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
package com.orange.admin.app.service;
|
||||
|
||||
import com.orange.admin.app.dao.*;
|
||||
import com.orange.admin.app.model.*;
|
||||
import com.orange.admin.upms.model.*;
|
||||
import com.orange.admin.upms.service.SysUserService;
|
||||
import com.orange.admin.upms.service.SysDeptService;
|
||||
import com.orange.admin.common.core.base.service.BaseService;
|
||||
import com.orange.admin.common.core.base.dao.BaseDaoMapper;
|
||||
import com.orange.admin.common.core.object.MyWhereCriteria;
|
||||
import com.orange.admin.common.core.object.VerifyResult;
|
||||
import com.orange.admin.common.biz.util.BasicIdGenerator;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import tk.mybatis.mapper.entity.Example;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 老师数据源数据操作服务类。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
*/
|
||||
@Service
|
||||
public class TeacherService extends BaseService<Teacher, Long> {
|
||||
|
||||
@Autowired
|
||||
private TeacherMapper teacherMapper;
|
||||
@Autowired
|
||||
private SysDeptService sysDeptService;
|
||||
@Autowired
|
||||
private SysUserService sysUserService;
|
||||
@Autowired
|
||||
private BasicIdGenerator idGenerator;
|
||||
|
||||
/**
|
||||
* 返回当前Service的主表Mapper对象。
|
||||
*
|
||||
* @return 主表Mapper对象。
|
||||
*/
|
||||
@Override
|
||||
protected BaseDaoMapper<Teacher> mapper() {
|
||||
return teacherMapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存新增对象。
|
||||
*
|
||||
* @param teacher 新增对象。
|
||||
* @return 返回新增对象。
|
||||
*/
|
||||
@Transactional
|
||||
public Teacher saveNew(Teacher teacher) {
|
||||
teacher.setTeacherId(idGenerator.nextLongId());
|
||||
teacher.setRegisterDate(new Date());
|
||||
teacherMapper.insert(teacher);
|
||||
return teacher;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新数据对象。
|
||||
*
|
||||
* @param teacher 更新的对象。
|
||||
* @param originalTeacher 原有数据对象。
|
||||
* @return 成功返回true,否则false。
|
||||
*/
|
||||
@Transactional
|
||||
public boolean update(Teacher teacher, Teacher originalTeacher) {
|
||||
teacher.setRegisterDate(originalTeacher.getRegisterDate());
|
||||
return teacherMapper.updateByPrimaryKey(teacher) == 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定数据。
|
||||
*
|
||||
* @param teacherId 主键Id。
|
||||
* @return 成功返回true,否则false。
|
||||
*/
|
||||
@Transactional
|
||||
public boolean remove(Long teacherId) {
|
||||
Teacher teacher = teacherMapper.selectByPrimaryKey(teacherId);
|
||||
if (teacher == null) {
|
||||
return false;
|
||||
}
|
||||
// 这里先删除主数据
|
||||
if (teacherMapper.deleteByPrimaryKey(teacherId) == 0) {
|
||||
return false;
|
||||
}
|
||||
// 这里可继续删除关联数据。
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单表查询结果。由于没有关联数据查询,因此在仅仅获取单表数据的场景下,效率更高。
|
||||
* 如果需要同时获取关联数据,请移步(getTeacherListWithRelation)方法。
|
||||
*
|
||||
* @param filter 过滤对象。
|
||||
* @param orderBy 排序参数。
|
||||
* @return 查询结果集。
|
||||
*/
|
||||
public List<Teacher> getTeacherList(Teacher filter, String orderBy) {
|
||||
return teacherMapper.getTeacherList(filter, orderBy);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取主表的查询结果,以及主表关联的字典数据和一对一从表数据,以及一对一从表的字典数据。
|
||||
* 如果仅仅需要获取主表数据,请移步(getTeacherList),以便获取更好的查询性能。
|
||||
*
|
||||
* @param filter 主表过滤对象。
|
||||
* @param sysDeptFilter 一对一从表过滤对象。
|
||||
* @param orderBy 排序参数。
|
||||
* @return 查询结果集。
|
||||
*/
|
||||
public List<Teacher> getTeacherListWithRelation(Teacher filter, SysDept sysDeptFilter, String orderBy) {
|
||||
List<Teacher> resultList =
|
||||
teacherMapper.getTeacherListEx(filter, sysDeptFilter, orderBy);
|
||||
Map<String, List<MyWhereCriteria>> criteriaMap = buildAggregationAdditionalWhereCriteria();
|
||||
this.buildAllRelationForDataList(resultList, false, criteriaMap);
|
||||
return resultList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据最新对象和原有对象的数据对比,判断关联的字典数据和多对一主表数据是否都是合法数据。
|
||||
*
|
||||
* @param teacher 最新数据对象。
|
||||
* @param originalTeacher 原有数据对象。
|
||||
* @return 数据全部正确返回true,否则false。
|
||||
*/
|
||||
public VerifyResult verifyRelatedData(Teacher teacher, Teacher originalTeacher) {
|
||||
String errorMessage = null;
|
||||
do {
|
||||
//这里是基于字典的验证。
|
||||
if (this.needToVerify(teacher, originalTeacher, Teacher::getSchoolId)) {
|
||||
if (!sysDeptService.existId(teacher.getSchoolId())) {
|
||||
errorMessage = "数据验证失败,关联的所属校区并不存在,请刷新后重试!";
|
||||
break;
|
||||
}
|
||||
}
|
||||
//这里是基于字典的验证。
|
||||
if (this.needToVerify(teacher, originalTeacher, Teacher::getUserId)) {
|
||||
if (!sysUserService.existId(teacher.getUserId())) {
|
||||
errorMessage = "数据验证失败,关联的绑定用户并不存在,请刷新后重试!";
|
||||
break;
|
||||
}
|
||||
}
|
||||
} while (false);
|
||||
return VerifyResult.create(errorMessage);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package com.orange.admin.app.service;
|
||||
|
||||
import com.orange.admin.app.dao.*;
|
||||
import com.orange.admin.app.model.*;
|
||||
import com.orange.admin.upms.service.SysDeptService;
|
||||
import com.orange.admin.common.core.base.service.BaseService;
|
||||
import com.orange.admin.common.core.base.dao.BaseDaoMapper;
|
||||
import com.orange.admin.common.core.object.MyWhereCriteria;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 老师流水统计数据操作服务类。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
*/
|
||||
@Service
|
||||
public class TeacherTransStatsService extends BaseService<TeacherTransStats, Long> {
|
||||
|
||||
@Autowired
|
||||
private TeacherTransStatsMapper teacherTransStatsMapper;
|
||||
@Autowired
|
||||
private AreaCodeService areaCodeService;
|
||||
@Autowired
|
||||
private SysDeptService sysDeptService;
|
||||
@Autowired
|
||||
private TeacherService teacherService;
|
||||
|
||||
/**
|
||||
* 返回当前Service的主表Mapper对象。
|
||||
*
|
||||
* @return 主表Mapper对象。
|
||||
*/
|
||||
@Override
|
||||
protected BaseDaoMapper<TeacherTransStats> mapper() {
|
||||
return teacherTransStatsMapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单表查询结果。由于没有关联数据查询,因此在仅仅获取单表数据的场景下,效率更高。
|
||||
* 如果需要同时获取关联数据,请移步(getTeacherTransStatsListWithRelation)方法。
|
||||
*
|
||||
* @param filter 过滤对象。
|
||||
* @param orderBy 排序参数。
|
||||
* @return 查询结果集。
|
||||
*/
|
||||
public List<TeacherTransStats> getTeacherTransStatsList(TeacherTransStats filter, String orderBy) {
|
||||
return teacherTransStatsMapper.getTeacherTransStatsList(filter, orderBy);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取主表的查询结果,以及主表关联的字典数据和一对一从表数据,以及一对一从表的字典数据。
|
||||
* 如果仅仅需要获取主表数据,请移步(getTeacherTransStatsList),以便获取更好的查询性能。
|
||||
*
|
||||
* @param filter 主表过滤对象。
|
||||
* @param orderBy 排序参数。
|
||||
* @return 查询结果集。
|
||||
*/
|
||||
public List<TeacherTransStats> getTeacherTransStatsListWithRelation(TeacherTransStats filter, String orderBy) {
|
||||
List<TeacherTransStats> resultList = teacherTransStatsMapper.getTeacherTransStatsList(filter, orderBy);
|
||||
Map<String, List<MyWhereCriteria>> criteriaMap = buildAggregationAdditionalWhereCriteria();
|
||||
this.buildAllRelationForDataList(resultList, false, criteriaMap);
|
||||
return resultList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分组过滤后的数据查询结果,以及关联的字典数据和一对一从表数据,以及一对一从表的字典数据。
|
||||
*
|
||||
* @param filter 过滤对象。
|
||||
* @param groupSelect 分组显示列表参数。位于SQL语句SELECT的后面。
|
||||
* @param groupBy 分组参数。位于SQL语句的GROUP BY后面。
|
||||
* @param orderBy 排序字符串,ORDER BY从句的参数。
|
||||
* @return 分组过滤结果集。
|
||||
*/
|
||||
public List<TeacherTransStats> getGroupedTeacherTransStatsListWithRelation(
|
||||
TeacherTransStats filter, String groupSelect, String groupBy, String orderBy) {
|
||||
List<TeacherTransStats> resultList =
|
||||
teacherTransStatsMapper.getGroupedTeacherTransStatsList(filter, groupSelect, groupBy, orderBy);
|
||||
// NOTE: 这里只是包含了关联数据,聚合计算数据没有包含。
|
||||
// 主要原因是,由于聚合字段通常被视为普通字段使用,不会在group by的从句中出现,语义上也不会在此关联。
|
||||
this.buildRelationForDataList(resultList, false);
|
||||
return resultList;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.orange.admin.config;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* 应用程序自定义的程序属性配置文件。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
*/
|
||||
@Data
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "application")
|
||||
public class ApplicationConfig {
|
||||
|
||||
/**
|
||||
* token的Http Request Header的key
|
||||
*/
|
||||
private String tokenHeaderKey;
|
||||
/**
|
||||
* token在过期之前,但是已经需要被刷新时,response返回的header信息的key。
|
||||
*/
|
||||
private String refreshedTokenHeaderKey;
|
||||
/**
|
||||
* token 加密用的密钥
|
||||
*/
|
||||
private String tokenSigningKey;
|
||||
/**
|
||||
* 用户密码加密用的salt值。
|
||||
*/
|
||||
private String passwordSalt;
|
||||
/**
|
||||
* 用户密码被重置之后的缺省密码
|
||||
*/
|
||||
private String defaultUserPassword;
|
||||
/**
|
||||
* 上传文件的基础目录
|
||||
*/
|
||||
private String uploadFileBaseDir;
|
||||
/**
|
||||
* 授信ip列表,没有填写表示全部信任。多个ip之间逗号分隔,如: http://10.10.10.1:8080,http://10.10.10.2:8080
|
||||
*/
|
||||
private String credentialIpList;
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
package com.orange.admin.config;
|
||||
|
||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.cache.caffeine.CaffeineCache;
|
||||
import org.springframework.cache.support.SimpleCacheManager;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 使用Caffeine作为本地缓存库
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
*/
|
||||
@Configuration
|
||||
@EnableCaching
|
||||
public class CacheConfig {
|
||||
|
||||
private static final int DEFAULT_MAXSIZE = 10000;
|
||||
private static final int DEFAULT_TTL = 3600;
|
||||
|
||||
/**
|
||||
* 定义cache名称、超时时长秒、最大个数
|
||||
* 每个cache缺省3600秒过期,最大个数1000
|
||||
*/
|
||||
public enum CacheEnum {
|
||||
/**
|
||||
* 专门存储用户权限的缓存。
|
||||
*/
|
||||
UserPermissionCache(1800),
|
||||
/**
|
||||
* 专门存储用户数据权限的缓存。
|
||||
*/
|
||||
DataPermissionCache(7200),
|
||||
/**
|
||||
* 缺省全局缓存(时间是24小时)。
|
||||
*/
|
||||
GlobalCache(86400,20000);
|
||||
|
||||
CacheEnum() {
|
||||
}
|
||||
|
||||
CacheEnum(int ttl) {
|
||||
this.ttl = ttl;
|
||||
}
|
||||
|
||||
CacheEnum(int ttl, int maxSize) {
|
||||
this.ttl = ttl;
|
||||
this.maxSize = maxSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* 缓存的最大数量。
|
||||
*/
|
||||
private int maxSize = DEFAULT_MAXSIZE;
|
||||
/**
|
||||
* 缓存的时长(单位:秒)
|
||||
*/
|
||||
private int ttl = DEFAULT_TTL;
|
||||
|
||||
public int getMaxSize() {
|
||||
return maxSize;
|
||||
}
|
||||
|
||||
public void setMaxSize(int maxSize) {
|
||||
this.maxSize = maxSize;
|
||||
}
|
||||
|
||||
public int getTtl() {
|
||||
return ttl;
|
||||
}
|
||||
|
||||
public void setTtl(int ttl) {
|
||||
this.ttl = ttl;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 个性化配置缓存
|
||||
*/
|
||||
@Bean
|
||||
public CacheManager cacheManager() {
|
||||
SimpleCacheManager manager = new SimpleCacheManager();
|
||||
//把各个cache注册到cacheManager中,CaffeineCache实现了org.springframework.cache.Cache接口
|
||||
ArrayList<CaffeineCache> caches = new ArrayList<>();
|
||||
for (CacheEnum c : CacheEnum.values()) {
|
||||
caches.add(new CaffeineCache(c.name(),
|
||||
Caffeine.newBuilder().recordStats()
|
||||
.expireAfterAccess(c.getTtl(), TimeUnit.SECONDS)
|
||||
.maximumSize(c.getMaxSize())
|
||||
.build())
|
||||
);
|
||||
}
|
||||
manager.setCaches(caches);
|
||||
return manager;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.orange.admin.config;
|
||||
|
||||
import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
import tk.mybatis.spring.annotation.MapperScan;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
/**
|
||||
* 数据源配置Bean对象。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
*/
|
||||
@Configuration
|
||||
@EnableTransactionManagement
|
||||
@MapperScan(value = {"com.orange.admin.*.dao"})
|
||||
public class DataSourceConfig {
|
||||
|
||||
@Bean(initMethod = "init", destroyMethod = "close")
|
||||
@Primary
|
||||
@ConfigurationProperties(prefix = "spring.datasource.druid")
|
||||
public DataSource druidDataSource() {
|
||||
return DruidDataSourceBuilder.create().build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.orange.admin.config;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.cors.CorsConfiguration;
|
||||
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
||||
import org.springframework.web.filter.CorsFilter;
|
||||
|
||||
import javax.servlet.Filter;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/**
|
||||
* 这里主要配置Web的各种过滤器和监听器等Servlet容器组件。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
*/
|
||||
@Configuration
|
||||
public class FilterConfig {
|
||||
|
||||
@Autowired
|
||||
private ApplicationConfig applicationConfig;
|
||||
|
||||
/**
|
||||
* 配置Ajax跨域过滤器
|
||||
*/
|
||||
@Bean
|
||||
public CorsFilter corsFilterRegistration() {
|
||||
UrlBasedCorsConfigurationSource configSource = new UrlBasedCorsConfigurationSource();
|
||||
CorsConfiguration corsConfiguration = new CorsConfiguration();
|
||||
if (StringUtils.isNotBlank(applicationConfig.getCredentialIpList())) {
|
||||
String[] credentialIpList = StringUtils.split(applicationConfig.getCredentialIpList(), ",");
|
||||
if (credentialIpList.length == 0) {
|
||||
corsConfiguration.addAllowedOrigin("*");
|
||||
} else {
|
||||
for (String ip : credentialIpList) {
|
||||
corsConfiguration.addAllowedOrigin(ip);
|
||||
}
|
||||
}
|
||||
corsConfiguration.addAllowedHeader("*");
|
||||
corsConfiguration.addAllowedMethod("*");
|
||||
corsConfiguration.addExposedHeader(applicationConfig.getRefreshedTokenHeaderKey());
|
||||
corsConfiguration.setAllowCredentials(true);
|
||||
configSource.registerCorsConfiguration("/**", corsConfiguration);
|
||||
}
|
||||
return new CorsFilter(configSource);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public FilterRegistrationBean<Filter> characterEncodingFilterRegistration() {
|
||||
FilterRegistrationBean<Filter> filterRegistrationBean = new FilterRegistrationBean<>(
|
||||
new org.springframework.web.filter.CharacterEncodingFilter());
|
||||
filterRegistrationBean.addUrlPatterns("/*");
|
||||
filterRegistrationBean.addInitParameter("encoding", StandardCharsets.UTF_8.name());
|
||||
// forceEncoding强制response也被编码,另外即使request中已经设置encoding,forceEncoding也会重新设置
|
||||
filterRegistrationBean.addInitParameter("forceEncoding", "true");
|
||||
filterRegistrationBean.setAsyncSupported(true);
|
||||
return filterRegistrationBean;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.orange.admin.config;
|
||||
|
||||
import com.orange.admin.interceptor.AuthenticationInterceptor;
|
||||
import com.orange.admin.common.biz.interceptor.AccessInterceptor;
|
||||
import com.orange.admin.common.biz.interceptor.MyRequestArgumentResolver;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.http.converter.StringHttpMessageConverter;
|
||||
import org.springframework.validation.beanvalidation.MethodValidationPostProcessor;
|
||||
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 所有的项目拦截器都在这里集中配置
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
*/
|
||||
@Configuration
|
||||
public class InterceptorConfig implements WebMvcConfigurer {
|
||||
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
registry.addInterceptor(new AuthenticationInterceptor()).addPathPatterns("/**");
|
||||
registry.addInterceptor(new AccessInterceptor()).addPathPatterns("/**");
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MethodValidationPostProcessor methodValidationPostProcessor() {
|
||||
return new MethodValidationPostProcessor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
|
||||
// 添加MyRequestBody参数解析器
|
||||
argumentResolvers.add(new MyRequestArgumentResolver());
|
||||
}
|
||||
|
||||
@Bean
|
||||
public HttpMessageConverter<String> responseBodyConverter() {
|
||||
return new StringHttpMessageConverter(StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
|
||||
converters.add(responseBodyConverter());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
package com.orange.admin.interceptor;
|
||||
|
||||
import com.orange.admin.config.CacheConfig;
|
||||
import com.orange.admin.config.ApplicationConfig;
|
||||
import com.orange.admin.upms.model.SysPermWhitelist;
|
||||
import com.orange.admin.upms.service.SysPermWhitelistService;
|
||||
import com.orange.admin.upms.service.SysPermService;
|
||||
import com.orange.admin.common.core.annotation.NoAuthInterface;
|
||||
import com.orange.admin.common.core.constant.ErrorCodeEnum;
|
||||
import com.orange.admin.common.core.object.ResponseResult;
|
||||
import com.orange.admin.common.core.object.TokenData;
|
||||
import com.orange.admin.common.core.util.ApplicationContextHolder;
|
||||
import com.orange.admin.common.core.util.JwtUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import io.jsonwebtoken.Claims;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.web.method.HandlerMethod;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
import org.springframework.cache.Cache;
|
||||
import org.springframework.cache.CacheManager;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Set;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 登录用户Token验证、生成和权限验证的拦截器。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
*/
|
||||
@Slf4j
|
||||
public class AuthenticationInterceptor implements HandlerInterceptor {
|
||||
|
||||
private ApplicationConfig applicationConfig =
|
||||
ApplicationContextHolder.getBean("applicationConfig");
|
||||
|
||||
private CacheManager cacheManager =
|
||||
ApplicationContextHolder.getBean("cacheManager");
|
||||
|
||||
private SysPermService sysPermService =
|
||||
ApplicationContextHolder.getBean("sysPermService");
|
||||
|
||||
private static SysPermWhitelistService sysPermWhilelistService =
|
||||
ApplicationContextHolder.getBean("sysPermWhitelistService");
|
||||
|
||||
private static Set<String> whitelistPermSet;
|
||||
|
||||
static {
|
||||
List<SysPermWhitelist> sysPermWhitelistList = sysPermWhilelistService.getAllList();
|
||||
whitelistPermSet = sysPermWhitelistList.stream()
|
||||
.map(SysPermWhitelist::getPermUrl).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
|
||||
throws Exception {
|
||||
String url = request.getRequestURI();
|
||||
// 如果接口方法标记NoAuthInterface注解,可以直接跳过Token鉴权验证,这里主要为了测试接口方便
|
||||
if (handler instanceof HandlerMethod) {
|
||||
HandlerMethod hm = (HandlerMethod) handler;
|
||||
if (hm.getBeanType().getAnnotation(NoAuthInterface.class) != null
|
||||
|| hm.getMethodAnnotation(NoAuthInterface.class) != null) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
String token = request.getHeader(applicationConfig.getTokenHeaderKey());
|
||||
if (StringUtils.isBlank(token)) {
|
||||
token = request.getParameter(applicationConfig.getTokenHeaderKey());
|
||||
}
|
||||
Claims c = JwtUtil.parseToken(token, applicationConfig.getTokenSigningKey());
|
||||
if (JwtUtil.isNullOrExpired(c)) {
|
||||
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
|
||||
this.outputResponseMessage(response,
|
||||
ResponseResult.error(ErrorCodeEnum.UNAUTHORIZED_LOGIN, "用户会话已过期,请重新登录!"));
|
||||
return false;
|
||||
}
|
||||
String sessionId = (String) c.get("sessionId");
|
||||
Cache cache = cacheManager.getCache(CacheConfig.CacheEnum.GlobalCache.name());
|
||||
TokenData tokenData = cache.get(sessionId, TokenData.class);
|
||||
if (tokenData == null) {
|
||||
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
|
||||
this.outputResponseMessage(response,
|
||||
ResponseResult.error(ErrorCodeEnum.UNAUTHORIZED_LOGIN, "用户会话已失效,请重新登录!"));
|
||||
return false;
|
||||
}
|
||||
TokenData.addToRequest(tokenData);
|
||||
if (!tokenData.getIsAdmin()) {
|
||||
// 如果url在权限资源白名单中,则不需要进行鉴权操作
|
||||
if (!whitelistPermSet.contains(url)) {
|
||||
Set<String> urlSet = sysPermService.getCacheableSysPermSetByUserId(
|
||||
tokenData.getSessionId(), tokenData.getUserId());
|
||||
if (!urlSet.contains(url)) {
|
||||
response.setStatus(HttpServletResponse.SC_FORBIDDEN);
|
||||
this.outputResponseMessage(response,
|
||||
ResponseResult.error(ErrorCodeEnum.NO_OPERATION_PERMISSION));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (JwtUtil.needToRefresh(c)) {
|
||||
String refreshedToken = JwtUtil.generateToken(c, applicationConfig.getTokenSigningKey());
|
||||
response.addHeader(applicationConfig.getRefreshedTokenHeaderKey(), refreshedToken);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
|
||||
ModelAndView modelAndView) throws Exception {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
|
||||
throws Exception {
|
||||
}
|
||||
|
||||
private void outputResponseMessage(HttpServletResponse response, ResponseResult<Object> respObj) {
|
||||
PrintWriter out;
|
||||
try {
|
||||
out = response.getWriter();
|
||||
} catch (IOException e) {
|
||||
log.error("Failed to call OutputResponseMessage.", e);
|
||||
return;
|
||||
}
|
||||
response.setContentType("application/json; charset=utf-8");
|
||||
out.print(JSONObject.toJSONString(respObj));
|
||||
out.flush();
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,279 @@
|
||||
package com.orange.admin.interceptor;
|
||||
|
||||
import cn.hutool.core.util.ReflectUtil;
|
||||
import com.orange.admin.common.core.constant.DataPermRuleType;
|
||||
import com.orange.admin.common.core.annotation.DeptFilterColumn;
|
||||
import com.orange.admin.common.core.annotation.UserFilterColumn;
|
||||
import com.orange.admin.common.core.annotation.EnableDataPerm;
|
||||
import com.orange.admin.common.core.object.GlobalThreadLocal;
|
||||
import com.orange.admin.common.core.object.TokenData;
|
||||
import com.orange.admin.common.core.util.ApplicationContextHolder;
|
||||
import com.orange.admin.common.core.util.ContextUtil;
|
||||
import com.orange.admin.common.core.util.MyModelUtil;
|
||||
import com.orange.admin.config.CacheConfig;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.sf.jsqlparser.expression.operators.conditional.AndExpression;
|
||||
import net.sf.jsqlparser.parser.CCJSqlParserUtil;
|
||||
import net.sf.jsqlparser.statement.select.FromItem;
|
||||
import net.sf.jsqlparser.statement.select.PlainSelect;
|
||||
import net.sf.jsqlparser.statement.select.Select;
|
||||
import net.sf.jsqlparser.statement.select.SubSelect;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.ibatis.executor.statement.RoutingStatementHandler;
|
||||
import org.apache.ibatis.executor.statement.StatementHandler;
|
||||
import org.apache.ibatis.mapping.BoundSql;
|
||||
import org.apache.ibatis.mapping.MappedStatement;
|
||||
import org.apache.ibatis.mapping.SqlCommandType;
|
||||
import org.apache.ibatis.plugin.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.Cache;
|
||||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.dao.PermissionDeniedDataAccessException;
|
||||
import org.springframework.stereotype.Component;
|
||||
import tk.mybatis.mapper.common.Mapper;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.sql.Connection;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Mybatis拦截器。目前用于数据权限的统一拦截和注入处理。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
*/
|
||||
@Intercepts({@Signature(type = StatementHandler.class, method = "prepare", args = {Connection.class, Integer.class})})
|
||||
@Slf4j
|
||||
@Component
|
||||
public class MybatisDataPermInterceptor implements Interceptor {
|
||||
|
||||
@Autowired
|
||||
private CacheManager cacheManager;
|
||||
|
||||
/**
|
||||
* HTTP Head或HTTP Request Parameter中菜单Id数据的KEY名称。
|
||||
*/
|
||||
private final static String MENU_ID_HEADER_KEY = "MenuId";
|
||||
/**
|
||||
* 对象缓存。由于Set是排序后的,因为在查找排除方法名称时效率更高。
|
||||
* 在应用服务启动的监听器中(LoadDataPermMapperListener),会调用当前对象的(loadMappersWithDataPerm)方法,加载缓存。
|
||||
*/
|
||||
private Map<String, ModelDataPermInfo> cacheMap = new HashMap<>();
|
||||
|
||||
/**
|
||||
* 预先加载需要数据权限过滤的Mapper到缓存,该函数会在(LoadDataPermMapperListener)监听器中调用。
|
||||
*/
|
||||
public void loadMappersWithDataPerm() {
|
||||
Map<String, Mapper> mapperMap =
|
||||
ApplicationContextHolder.getApplicationContext().getBeansOfType(Mapper.class);
|
||||
for (Mapper<?> mapperProxy : mapperMap.values()) {
|
||||
// 优先处理jdk的代理
|
||||
Object proxy = ReflectUtil.getFieldValue(mapperProxy, "h");
|
||||
// 如果不是jdk的代理,再看看cjlib的代理。
|
||||
if (proxy == null) {
|
||||
proxy = ReflectUtil.getFieldValue(mapperProxy, "CGLIB$CALLBACK_0");
|
||||
}
|
||||
Class<?> mapperClass =
|
||||
(Class<?>) ReflectUtil.getFieldValue(proxy, "mapperInterface");
|
||||
EnableDataPerm rule = mapperClass.getAnnotation(EnableDataPerm.class);
|
||||
if (rule != null) {
|
||||
// 由于给数据权限Mapper添加@EnableDataPerm,将会导致无限递归,因此这里检测到之后,
|
||||
// 会在系统启动加载监听器的时候,及时抛出异常。
|
||||
if ("SysDataPermMapper".equals(mapperClass.getSimpleName())) {
|
||||
throw new IllegalStateException("Add @EnableDataPerm annotation to SysDataPermMapper is ILLEGAL!");
|
||||
}
|
||||
// 这里开始获取当前Mapper已经声明的的SqlId中,有哪些是需要排除在外的。
|
||||
// 排除在外的将不进行数据过滤。
|
||||
Set<String> excludeMethodNameSet = null;
|
||||
String[] excludes = rule.excluseMethodName();
|
||||
if (excludes.length > 0) {
|
||||
excludeMethodNameSet = new HashSet<>();
|
||||
for (String excludeName : excludes) {
|
||||
excludeMethodNameSet.add(excludeName);
|
||||
// 这里是给tk.mapper和pagehelper中,分页查询先获取数据总量的查询。
|
||||
excludeMethodNameSet.add(excludeName + "_COUNT");
|
||||
}
|
||||
}
|
||||
// 获取Mapper关联的主表信息,包括表名,user过滤字段名和dept过滤字段名。
|
||||
Class<?> modelClazz = (Class<?>)
|
||||
((ParameterizedType) mapperClass.getGenericInterfaces()[0]).getActualTypeArguments()[0];
|
||||
Field[] fields = ReflectUtil.getFields(modelClazz);
|
||||
Field userFilterField = null, deptFilterField = null;
|
||||
for (Field field : fields) {
|
||||
if (null != field.getAnnotation(UserFilterColumn.class)) {
|
||||
userFilterField = field;
|
||||
}
|
||||
if (null != field.getAnnotation(DeptFilterColumn.class)) {
|
||||
deptFilterField = field;
|
||||
}
|
||||
if (userFilterField != null && deptFilterField != null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
// 通过注解解析与Mapper关联的Model,并获取与数据权限关联的信息,并将结果缓存。
|
||||
ModelDataPermInfo info = new ModelDataPermInfo();
|
||||
info.setMainTableName(MyModelUtil.mapToTableName(modelClazz));
|
||||
info.setExcludeMethodNameSet(excludeMethodNameSet);
|
||||
if (userFilterField != null) {
|
||||
info.setUserFilterColumn(MyModelUtil.mapToColumnName(userFilterField, modelClazz));
|
||||
}
|
||||
if (deptFilterField != null) {
|
||||
info.setDeptFilterColumn(MyModelUtil.mapToColumnName(deptFilterField, modelClazz));
|
||||
}
|
||||
String className = mapperClass.getName();
|
||||
cacheMap.put(mapperClass.getName(), info);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Object intercept(Invocation invocation) throws Throwable {
|
||||
// 只有在HttpServletRequest场景下,该拦截器才起作用,对于系统级别的预加载数据不会应用数据权限。
|
||||
if (!ContextUtil.hasRequestContext()) {
|
||||
return invocation.proceed();
|
||||
}
|
||||
// 判断当前线程本地存储中,业务操作是否禁用了数据权限过滤,如果禁用,则不进行后续的数据过滤处理了。
|
||||
if (!GlobalThreadLocal.enabledDataPerm()) {
|
||||
return invocation.proceed();
|
||||
}
|
||||
RoutingStatementHandler handler = (RoutingStatementHandler) invocation.getTarget();
|
||||
StatementHandler delegate =
|
||||
(StatementHandler) ReflectUtil.getFieldValue(handler, "delegate");
|
||||
//通过反射获取delegate父类BaseStatementHandler的mappedStatement属性
|
||||
MappedStatement mappedStatement =
|
||||
(MappedStatement) ReflectUtil.getFieldValue(delegate, "mappedStatement");
|
||||
SqlCommandType commandType = mappedStatement.getSqlCommandType();
|
||||
TokenData tokenData = TokenData.takeFromRequest();
|
||||
// 数据过滤权限中,只是过滤SELECT语句。如果是管理员则不参与数据权限的数据过滤,显示全部数据。
|
||||
if (commandType != SqlCommandType.SELECT || tokenData == null || tokenData.getIsAdmin()) {
|
||||
return invocation.proceed();
|
||||
}
|
||||
String sqlId = mappedStatement.getId();
|
||||
int pos = StringUtils.lastIndexOf(sqlId, ".");
|
||||
String className = StringUtils.substring(sqlId, 0, pos);
|
||||
String methodName = StringUtils.substring(sqlId, pos + 1);
|
||||
// 先从缓存中查找当前Mapper是否存在。
|
||||
ModelDataPermInfo info = cacheMap.get(className);
|
||||
if (info != null) {
|
||||
// 再次查找当前方法是否为排除方法,如果不是,就参与数据权限注入过滤。
|
||||
if (info.getExcludeMethodNameSet() == null
|
||||
|| !info.getExcludeMethodNameSet().contains(methodName)) {
|
||||
String menuId = ContextUtil.getHttpRequest().getHeader(MENU_ID_HEADER_KEY);
|
||||
if (StringUtils.isBlank(menuId)) {
|
||||
menuId = ContextUtil.getHttpRequest().getParameter(MENU_ID_HEADER_KEY);
|
||||
if (StringUtils.isBlank(menuId)) {
|
||||
throw new IllegalStateException(
|
||||
"No [ MENU_ID ] key found in Http Header for SQL_ID [ " + sqlId + " ].");
|
||||
}
|
||||
}
|
||||
Cache cache = cacheManager.getCache(CacheConfig.CacheEnum.DataPermissionCache.name());
|
||||
Map<Object, Map<Integer, String>> menuIdAndDataPermMap =
|
||||
(Map<Object, Map<Integer, String>>) cache.get(tokenData.getSessionId(), Map.class);
|
||||
if (menuIdAndDataPermMap == null) {
|
||||
throw new PermissionDeniedDataAccessException(
|
||||
"No Related DataPerm found with SESSION_ID [ " + tokenData.getSessionId() + " ].", null);
|
||||
}
|
||||
Map<Integer, String> dataPermMap = menuIdAndDataPermMap.get(Long.valueOf(menuId));
|
||||
if (MapUtils.isEmpty(dataPermMap)) {
|
||||
throw new PermissionDeniedDataAccessException(
|
||||
"No Related DataPerm found with MENU_ID [ " + menuId + " ] for SQL_ID [ " + sqlId + " ].", null);
|
||||
}
|
||||
if (dataPermMap.containsKey(DataPermRuleType.TYPE_ALL)) {
|
||||
return invocation.proceed();
|
||||
}
|
||||
BoundSql boundSql = delegate.getBoundSql();
|
||||
String sql = boundSql.getSql();
|
||||
Select select = (Select) CCJSqlParserUtil.parse(sql);
|
||||
PlainSelect selectBody = (PlainSelect) select.getSelectBody();
|
||||
FromItem fromItem = selectBody.getFromItem();
|
||||
PlainSelect subSelect = null;
|
||||
if (fromItem instanceof SubSelect) {
|
||||
subSelect = (PlainSelect) ((SubSelect) fromItem).getSelectBody();
|
||||
}
|
||||
List<String> criteriaList = new LinkedList<>();
|
||||
for (Map.Entry<Integer, String> entry : dataPermMap.entrySet()) {
|
||||
Integer ruleType = entry.getKey();
|
||||
if (ruleType == DataPermRuleType.TYPE_USER_ONLY) {
|
||||
if (StringUtils.isNotBlank(info.getUserFilterColumn())) {
|
||||
StringBuilder filter = new StringBuilder(64);
|
||||
filter.append(info.getMainTableName())
|
||||
.append(".")
|
||||
.append(info.getUserFilterColumn())
|
||||
.append(" = ")
|
||||
.append(tokenData.getUserId());
|
||||
criteriaList.add(filter.toString());
|
||||
}
|
||||
} else {
|
||||
if (StringUtils.isNotBlank(info.getDeptFilterColumn())) {
|
||||
StringBuilder filter = new StringBuilder(128);
|
||||
if (ruleType == DataPermRuleType.TYPE_DEPT_ONLY) {
|
||||
filter.append(info.getMainTableName())
|
||||
.append(".")
|
||||
.append(info.getDeptFilterColumn())
|
||||
.append(" = ")
|
||||
.append(tokenData.getDeptId());
|
||||
} else if (ruleType == DataPermRuleType.TYPE_CUSTOM_DETP_LIST) {
|
||||
filter.append(info.getMainTableName())
|
||||
.append(".")
|
||||
.append(info.getDeptFilterColumn())
|
||||
.append(" IN (")
|
||||
.append(entry.getValue())
|
||||
.append(") ");
|
||||
}
|
||||
criteriaList.add(filter.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (criteriaList.size() > 0) {
|
||||
StringBuilder filterBuilder = new StringBuilder(128);
|
||||
filterBuilder.append("(");
|
||||
filterBuilder.append(StringUtils.join(criteriaList, " OR "));
|
||||
filterBuilder.append(")");
|
||||
String dataFilter = filterBuilder.toString();
|
||||
if (subSelect != null) {
|
||||
if (subSelect.getWhere() == null) {
|
||||
subSelect.setWhere(CCJSqlParserUtil.parseCondExpression(dataFilter));
|
||||
} else {
|
||||
AndExpression and = new AndExpression(
|
||||
CCJSqlParserUtil.parseCondExpression(dataFilter), subSelect.getWhere());
|
||||
subSelect.setWhere(and);
|
||||
}
|
||||
} else {
|
||||
if (selectBody.getWhere() == null) {
|
||||
selectBody.setWhere(CCJSqlParserUtil.parseCondExpression(dataFilter));
|
||||
} else {
|
||||
AndExpression and = new AndExpression(
|
||||
CCJSqlParserUtil.parseCondExpression(dataFilter), selectBody.getWhere());
|
||||
selectBody.setWhere(and);
|
||||
}
|
||||
}
|
||||
}
|
||||
sql = select.toString();
|
||||
ReflectUtil.setFieldValue(boundSql, "sql", sql);
|
||||
}
|
||||
}
|
||||
return invocation.proceed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object plugin(Object target) {
|
||||
return Plugin.wrap(target, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProperties(Properties properties) {
|
||||
|
||||
}
|
||||
|
||||
@Data
|
||||
private static final class ModelDataPermInfo {
|
||||
private Set<String> excludeMethodNameSet;
|
||||
private String userFilterColumn;
|
||||
private String deptFilterColumn;
|
||||
private String mainTableName;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.orange.admin.listener;
|
||||
|
||||
import com.orange.admin.interceptor.MybatisDataPermInterceptor;
|
||||
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 应用服务启动监听器。
|
||||
* 目前主要功能是调用DataPermInterceptor中的loadMappersWithEnableDataPerm方法,
|
||||
* 将标记有数据权限规则注解的Mapper对象,加载到缓存,以提升系统运行时效率。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
*/
|
||||
@Component
|
||||
public class LoadDataPermMapperListener implements ApplicationListener<ApplicationReadyEvent> {
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(ApplicationReadyEvent applicationReadyEvent) {
|
||||
MybatisDataPermInterceptor interceptor =
|
||||
applicationReadyEvent.getApplicationContext().getBean(MybatisDataPermInterceptor.class);
|
||||
interceptor.loadMappersWithDataPerm();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
package com.orange.admin.upms.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import com.orange.admin.config.ApplicationConfig;
|
||||
import com.orange.admin.config.CacheConfig;
|
||||
import com.orange.admin.upms.service.*;
|
||||
import com.orange.admin.upms.model.SysMenu;
|
||||
import com.orange.admin.upms.model.SysUser;
|
||||
import com.orange.admin.upms.model.constant.SysUserStatus;
|
||||
import com.orange.admin.upms.model.constant.SysUserType;
|
||||
import com.orange.admin.common.core.annotation.NoAuthInterface;
|
||||
import com.orange.admin.common.core.constant.ErrorCodeEnum;
|
||||
import com.orange.admin.common.core.object.ResponseResult;
|
||||
import com.orange.admin.common.core.object.TokenData;
|
||||
import com.orange.admin.common.core.util.JwtUtil;
|
||||
import com.orange.admin.common.core.util.MyCommonUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.cache.Cache;
|
||||
import org.springframework.cache.CacheManager;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 登录接口控制器类。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/admin/login")
|
||||
public class LoginController {
|
||||
|
||||
@Autowired
|
||||
private SysUserService sysUserService;
|
||||
@Autowired
|
||||
private SysMenuService sysMenuService;
|
||||
@Autowired
|
||||
private SysPermCodeService sysPermCodeService;
|
||||
@Autowired
|
||||
private SysPermService sysPermService;
|
||||
@Autowired
|
||||
private SysDataPermService sysDataPermService;
|
||||
@Autowired
|
||||
private ApplicationConfig appConfig;
|
||||
@Autowired
|
||||
private CacheManager cacheManager;
|
||||
|
||||
/**
|
||||
* 登录接口。
|
||||
*
|
||||
* @param loginName 登录名。
|
||||
* @param password 密码。
|
||||
* @return 应答结果对象,其中包括JWT的Token数据,以及菜单列表。
|
||||
*/
|
||||
@NoAuthInterface
|
||||
@GetMapping("/doLogin")
|
||||
public ResponseResult<?> doLogin(@RequestParam String loginName, @RequestParam String password) {
|
||||
ErrorCodeEnum errorCodeEnum = ErrorCodeEnum.NO_ERROR;
|
||||
String errorMessage = null;
|
||||
JSONObject jsonData = new JSONObject();
|
||||
do {
|
||||
if (MyCommonUtil.existBlankArgument(loginName, password)) {
|
||||
errorCodeEnum = ErrorCodeEnum.ARGUMENT_NULL_EXIST;
|
||||
break;
|
||||
}
|
||||
SysUser user = sysUserService.getSysUserByLoginName(loginName);
|
||||
if (user == null
|
||||
|| !user.getPassword().equals(MyCommonUtil.encrptedPassword(password, appConfig.getPasswordSalt()))) {
|
||||
errorCodeEnum = ErrorCodeEnum.INVALID_USERNAME_PASSWORD;
|
||||
break;
|
||||
}
|
||||
if (user.getUserStatus() == SysUserStatus.STATUS_LOCKED) {
|
||||
errorCodeEnum = ErrorCodeEnum.INVALID_USER_STATUS;
|
||||
errorMessage = "登录失败,用户账号被锁定!";
|
||||
break;
|
||||
}
|
||||
boolean isAdmin = user.getUserType() == SysUserType.TYPE_ADMIN;
|
||||
Map<String, Object> claims = new HashMap<>(3);
|
||||
String sessionId = MyCommonUtil.generateUuid();
|
||||
claims.put("sessionId", sessionId);
|
||||
String token = JwtUtil.generateToken(claims, appConfig.getTokenSigningKey());
|
||||
jsonData.put(TokenData.REQUEST_ATTRIBUTE_NAME, token);
|
||||
jsonData.put("showName", user.getShowName());
|
||||
jsonData.put("isAdmin", isAdmin);
|
||||
TokenData tokenData = new TokenData();
|
||||
tokenData.setSessionId(sessionId);
|
||||
tokenData.setUserId(user.getUserId());
|
||||
tokenData.setDeptId(user.getDeptId());
|
||||
tokenData.setShowName(user.getShowName());
|
||||
tokenData.setIsAdmin(isAdmin);
|
||||
Cache sessionCache = cacheManager.getCache(CacheConfig.CacheEnum.GlobalCache.name());
|
||||
sessionCache.put(sessionId, tokenData);
|
||||
List<SysMenu> menuList;
|
||||
if (isAdmin) {
|
||||
menuList = sysMenuService.getAllMenuList();
|
||||
} else {
|
||||
menuList = sysMenuService.getMenuListByUserId(user.getUserId());
|
||||
List<String> permCodeList = sysPermCodeService.getPermCodeListByUserId(user.getUserId());
|
||||
jsonData.put("permCodeList", permCodeList);
|
||||
}
|
||||
jsonData.put("menuList", menuList);
|
||||
if (user.getUserType() != SysUserType.TYPE_ADMIN) {
|
||||
// 缓存用户的权限资源
|
||||
sysPermService.putUserSysPermCache(sessionId, user.getUserId(), isAdmin);
|
||||
sysDataPermService.putDataPermCache(sessionId, user.getUserId(), user.getDeptId(), isAdmin);
|
||||
}
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage, jsonData);
|
||||
}
|
||||
|
||||
/**
|
||||
* 登出操作。同时将Session相关的信息从缓存中删除。
|
||||
*
|
||||
* @return 应答结果对象。
|
||||
*/
|
||||
@PostMapping("/doLogout")
|
||||
public ResponseResult<?> doLogout() {
|
||||
TokenData tokenData = TokenData.takeFromRequest();
|
||||
sysPermService.removeUserSysPermCache(tokenData.getSessionId());
|
||||
sysDataPermService.removeDataPermCache(tokenData.getSessionId());
|
||||
return ResponseResult.success();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,338 @@
|
||||
package com.orange.admin.upms.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import com.orange.admin.upms.model.SysDataPermMenu;
|
||||
import com.orange.admin.upms.model.SysDataPerm;
|
||||
import com.orange.admin.upms.model.SysUser;
|
||||
import com.orange.admin.upms.service.SysDataPermService;
|
||||
import com.orange.admin.upms.service.SysUserService;
|
||||
import com.orange.admin.common.core.validator.UpdateGroup;
|
||||
import com.orange.admin.common.core.constant.ErrorCodeEnum;
|
||||
import com.orange.admin.common.core.object.VerifyResult;
|
||||
import com.orange.admin.common.core.object.MyOrderParam;
|
||||
import com.orange.admin.common.core.object.MyPageParam;
|
||||
import com.orange.admin.common.core.object.ResponseResult;
|
||||
import com.orange.admin.common.core.util.MyCommonUtil;
|
||||
import com.orange.admin.common.core.util.MyPageUtil;
|
||||
import com.orange.admin.common.core.annotation.MyRequestBody;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.groups.Default;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 数据权限接口控制器对象。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/admin/upms/sysDataPerm")
|
||||
public class SysDataPermController {
|
||||
|
||||
@Autowired
|
||||
private SysDataPermService sysDataPermService;
|
||||
@Autowired
|
||||
private SysUserService sysUserService;
|
||||
|
||||
/**
|
||||
* 添加新数据权限操作。
|
||||
*
|
||||
* @param sysDataPerm 新增对象。
|
||||
* @param deptIdListString 数据权限关联的部门Id列表,多个之间逗号分隔。
|
||||
* @param menuIdListString 数据权限关联的菜单Id列表,多个之间逗号分隔。
|
||||
* @return 应答结果对象。包含新增数据权限对象的主键Id。
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@PostMapping("/add")
|
||||
public ResponseResult<?> add(
|
||||
@MyRequestBody SysDataPerm sysDataPerm,
|
||||
@MyRequestBody String deptIdListString,
|
||||
@MyRequestBody String menuIdListString) {
|
||||
ErrorCodeEnum errorCodeEnum = ErrorCodeEnum.NO_ERROR;
|
||||
String errorMessage = null;
|
||||
JSONObject responseData = null;
|
||||
do {
|
||||
if (MyCommonUtil.existBlankArgument(menuIdListString)) {
|
||||
errorCodeEnum = ErrorCodeEnum.ARGUMENT_NULL_EXIST;
|
||||
break;
|
||||
}
|
||||
errorMessage = MyCommonUtil.getModelValidationError(sysDataPerm);
|
||||
if (errorMessage != null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_VALIDATAED_FAILED;
|
||||
break;
|
||||
}
|
||||
VerifyResult result = sysDataPermService.verifyRelatedData(sysDataPerm, deptIdListString, menuIdListString);
|
||||
if (!result.isSuccess()) {
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_VALIDATAED_FAILED, result.getErrorMessage());
|
||||
}
|
||||
List<SysDataPermMenu> dataPermMenuList = null;
|
||||
Set<Long> deptIdSet = null;
|
||||
if (result.getData() != null) {
|
||||
dataPermMenuList = (List<SysDataPermMenu>) result.getData().get("dataPermMenuList");
|
||||
deptIdSet = (Set<Long>) result.getData().get("deptIdSet");
|
||||
}
|
||||
sysDataPermService.saveNew(sysDataPerm, deptIdSet, dataPermMenuList);
|
||||
responseData = new JSONObject();
|
||||
responseData.put("dataPermId", sysDataPerm.getDataPermId());
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage, responseData);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新数据权限操作。
|
||||
*
|
||||
* @param sysDataPerm 更新的数据权限对象。
|
||||
* @param deptIdListString 数据权限关联的部门Id列表,多个之间逗号分隔。
|
||||
* @param menuIdListString 数据权限关联的菜单Id列表,多个之间逗号分隔
|
||||
* @return 应答结果对象。
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@PostMapping("/update")
|
||||
public ResponseResult<?> update(
|
||||
@MyRequestBody SysDataPerm sysDataPerm,
|
||||
@MyRequestBody String deptIdListString,
|
||||
@MyRequestBody String menuIdListString) {
|
||||
ErrorCodeEnum errorCodeEnum = ErrorCodeEnum.NO_ERROR;
|
||||
String errorMessage = null;
|
||||
do {
|
||||
if (MyCommonUtil.existBlankArgument(menuIdListString)) {
|
||||
errorCodeEnum = ErrorCodeEnum.ARGUMENT_NULL_EXIST;
|
||||
break;
|
||||
}
|
||||
errorMessage = MyCommonUtil.getModelValidationError(sysDataPerm, Default.class, UpdateGroup.class);
|
||||
if (errorMessage != null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_VALIDATAED_FAILED;
|
||||
break;
|
||||
}
|
||||
SysDataPerm originalSysDataPerm = sysDataPermService.getById(sysDataPerm.getDataPermId());
|
||||
if (originalSysDataPerm == null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
errorMessage = "数据验证失败,当前数据权限并不存在,请刷新后重试!";
|
||||
break;
|
||||
}
|
||||
VerifyResult result = sysDataPermService.verifyRelatedData(sysDataPerm, deptIdListString, menuIdListString);
|
||||
if (!result.isSuccess()) {
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_VALIDATAED_FAILED, result.getErrorMessage());
|
||||
}
|
||||
List<SysDataPermMenu> dataPermMenuList = null;
|
||||
Set<Long> deptIdSet = null;
|
||||
if (result.getData() != null) {
|
||||
dataPermMenuList = (List<SysDataPermMenu>) result.getData().get("dataPermMenuList");
|
||||
deptIdSet = (Set<Long>) result.getData().get("deptIdSet");
|
||||
}
|
||||
if (!sysDataPermService.update(sysDataPerm, originalSysDataPerm, deptIdSet, dataPermMenuList)) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
errorMessage = "更新失败,数据不存在,请刷新后重试!";
|
||||
break;
|
||||
}
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除数据权限操作。
|
||||
*
|
||||
* @param dataPermId 待删除数据权限主键Id。
|
||||
* @return 应答数据结果。
|
||||
*/
|
||||
@PostMapping("/delete")
|
||||
public ResponseResult<?> delete(@MyRequestBody Long dataPermId) {
|
||||
ErrorCodeEnum errorCodeEnum = ErrorCodeEnum.NO_ERROR;
|
||||
String errorMessage = null;
|
||||
do {
|
||||
if (MyCommonUtil.existBlankArgument(dataPermId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.ARGUMENT_NULL_EXIST;
|
||||
break;
|
||||
}
|
||||
if (!sysDataPermService.remove(dataPermId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
errorMessage = "数据操作失败,数据权限不存在,请刷新后重试!";
|
||||
break;
|
||||
}
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看数据权限列表。
|
||||
*
|
||||
* @param sysDataPermFilter 数据权限查询过滤对象。
|
||||
* @param orderParam 排序参数。
|
||||
* @param pageParam 分页参数。
|
||||
* @return 应答结果对象。包含数据权限列表。
|
||||
*/
|
||||
@PostMapping("/list")
|
||||
public ResponseResult<?> list(
|
||||
@MyRequestBody SysDataPerm sysDataPermFilter,
|
||||
@MyRequestBody MyOrderParam orderParam,
|
||||
@MyRequestBody MyPageParam pageParam) {
|
||||
if (pageParam != null) {
|
||||
PageHelper.startPage(pageParam.getPageNum(), pageParam.getPageSize());
|
||||
}
|
||||
String orderBy = MyOrderParam.buildOrderBy(orderParam, SysDataPerm.class);
|
||||
List<SysDataPerm> resultList = sysDataPermService.getSysDataPermList(sysDataPermFilter, orderBy);
|
||||
return ResponseResult.success(MyPageUtil.makeResponseData(resultList));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看单条数据权限详情。
|
||||
*
|
||||
* @param dataPermId 数据权限的主键Id。
|
||||
* @return 应答结果对象,包含数据权限的详情。
|
||||
*/
|
||||
@GetMapping("/view")
|
||||
public ResponseResult<SysDataPerm> view(@RequestParam Long dataPermId) {
|
||||
ErrorCodeEnum errorCodeEnum = ErrorCodeEnum.NO_ERROR;
|
||||
String errorMessage = null;
|
||||
SysDataPerm dataPerm = null;
|
||||
do {
|
||||
if (MyCommonUtil.existBlankArgument(dataPermId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.ARGUMENT_NULL_EXIST;
|
||||
break;
|
||||
}
|
||||
dataPerm = sysDataPermService.getSysDataPermWithRelation(dataPermId);
|
||||
if (dataPerm == null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
break;
|
||||
}
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage, dataPerm);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取不包含指定数据权限Id的用户列表。
|
||||
* 用户和数据权限是多对多关系,当前接口将返回没有赋值指定DataPermId的用户列表。可用于给数据权限添加新用户。
|
||||
*
|
||||
* @param dataPermId 数据权限主键Id。
|
||||
* @param sysUserFilter 用户数据的过滤对象。
|
||||
* @param orderParam 排序参数。
|
||||
* @param pageParam 分页参数。
|
||||
* @return 应答结果对象,包含用户列表数据。
|
||||
*/
|
||||
@PostMapping("/listNotInDataPermUser")
|
||||
public ResponseResult<?> listNotInDataPermUser(
|
||||
@MyRequestBody Long dataPermId,
|
||||
@MyRequestBody SysUser sysUserFilter,
|
||||
@MyRequestBody MyOrderParam orderParam,
|
||||
@MyRequestBody MyPageParam pageParam) {
|
||||
ErrorCodeEnum errorCodeEnum = ErrorCodeEnum.NO_ERROR;
|
||||
String errorMessage = null;
|
||||
JSONObject responseData = null;
|
||||
do {
|
||||
if (MyCommonUtil.existBlankArgument(dataPermId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.ARGUMENT_NULL_EXIST;
|
||||
break;
|
||||
}
|
||||
if (!sysDataPermService.existId(dataPermId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.INVALID_RELATED_RECORD_ID;
|
||||
break;
|
||||
}
|
||||
if (pageParam != null) {
|
||||
PageHelper.startPage(pageParam.getPageNum(), pageParam.getPageSize());
|
||||
}
|
||||
String orderBy = MyOrderParam.buildOrderBy(orderParam, SysUser.class);
|
||||
List<SysUser> resultList =
|
||||
sysUserService.getNotInSysUserListByDataPermId(dataPermId, sysUserFilter, orderBy);
|
||||
responseData = MyPageUtil.makeResponseData(resultList);
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage, responseData);
|
||||
}
|
||||
|
||||
/**
|
||||
* 拥有指定数据权限的用户列表。
|
||||
*
|
||||
* @param dataPermId 数据权限主键Id。
|
||||
* @param sysUserFilter 用户过滤对象。
|
||||
* @param orderParam 排序参数。
|
||||
* @param pageParam 分页参数。
|
||||
* @return 应答结果对象,包含用户列表数据。
|
||||
*/
|
||||
@PostMapping("/listDataPermUser")
|
||||
public ResponseResult<?> listDataPermUser(
|
||||
@MyRequestBody Long dataPermId,
|
||||
@MyRequestBody SysUser sysUserFilter,
|
||||
@MyRequestBody MyOrderParam orderParam,
|
||||
@MyRequestBody MyPageParam pageParam) {
|
||||
ErrorCodeEnum errorCodeEnum = ErrorCodeEnum.NO_ERROR;
|
||||
String errorMessage = null;
|
||||
JSONObject responseData = null;
|
||||
do {
|
||||
if (MyCommonUtil.existBlankArgument(dataPermId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.ARGUMENT_NULL_EXIST;
|
||||
break;
|
||||
}
|
||||
if (!sysDataPermService.existId(dataPermId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.INVALID_RELATED_RECORD_ID;
|
||||
break;
|
||||
}
|
||||
if (pageParam != null) {
|
||||
PageHelper.startPage(pageParam.getPageNum(), pageParam.getPageSize());
|
||||
}
|
||||
String orderBy = MyOrderParam.buildOrderBy(orderParam, SysUser.class);
|
||||
List<SysUser> resultList =
|
||||
sysUserService.getSysUserListByDataPermId(dataPermId, sysUserFilter, orderBy);
|
||||
responseData = MyPageUtil.makeResponseData(resultList);
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage, responseData);
|
||||
}
|
||||
|
||||
/**
|
||||
* 为指定数据权限添加用户列表。该操作可同时给一批用户赋值数据权限,并在同一事务内完成。
|
||||
*
|
||||
* @param dataPermId 数据权限主键Id。
|
||||
* @param userIdListString 逗号分隔的用户Id列表。
|
||||
* @return 应答结果对象。
|
||||
*/
|
||||
@PostMapping("/addDataPermUser")
|
||||
public ResponseResult<?> addDataPermUser(
|
||||
@MyRequestBody Long dataPermId, @MyRequestBody String userIdListString) {
|
||||
ErrorCodeEnum errorCodeEnum = ErrorCodeEnum.NO_ERROR;
|
||||
String errorMessage = null;
|
||||
do {
|
||||
if (MyCommonUtil.existBlankArgument(dataPermId, userIdListString)) {
|
||||
errorCodeEnum = ErrorCodeEnum.ARGUMENT_NULL_EXIST;
|
||||
break;
|
||||
}
|
||||
Set<Long> userIdSet =
|
||||
Arrays.stream(userIdListString.split(",")).map(Long::valueOf).collect(Collectors.toSet());
|
||||
if (!sysDataPermService.existId(dataPermId)
|
||||
|| !sysUserService.existUniqueKeyList("userId", userIdSet)) {
|
||||
errorCodeEnum = ErrorCodeEnum.INVALID_RELATED_RECORD_ID;
|
||||
break;
|
||||
}
|
||||
sysDataPermService.addDataPermUserList(dataPermId, userIdSet);
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 为指定用户移除指定数据权限。
|
||||
*
|
||||
* @param dataPermId 指定数据权限主键Id。
|
||||
* @param userId 指定用户主键Id。
|
||||
* @return 应答数据结果。
|
||||
*/
|
||||
@PostMapping("/deleteDataPermUser")
|
||||
public ResponseResult<?> deleteDataPermUser(
|
||||
@MyRequestBody Long dataPermId, @MyRequestBody Long userId) {
|
||||
ErrorCodeEnum errorCodeEnum = ErrorCodeEnum.NO_ERROR;
|
||||
String errorMessage = null;
|
||||
do {
|
||||
if (MyCommonUtil.existBlankArgument(dataPermId, userId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.ARGUMENT_NULL_EXIST;
|
||||
break;
|
||||
}
|
||||
if (!sysDataPermService.removeDataPermUser(dataPermId, userId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
break;
|
||||
}
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
package com.orange.admin.upms.controller;
|
||||
|
||||
import cn.jimmyshi.beanquery.BeanQuery;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.orange.admin.upms.model.*;
|
||||
import com.orange.admin.upms.service.*;
|
||||
import com.orange.admin.common.core.object.*;
|
||||
import com.orange.admin.common.core.util.*;
|
||||
import com.orange.admin.common.core.constant.ErrorCodeEnum;
|
||||
import com.orange.admin.common.core.annotation.MyRequestBody;
|
||||
import com.orange.admin.common.core.validator.UpdateGroup;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.*;
|
||||
import javax.validation.groups.Default;
|
||||
|
||||
/**
|
||||
* 部门管理操作控制器类。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/admin/upms/sysDept")
|
||||
public class SysDeptController {
|
||||
|
||||
@Autowired
|
||||
private SysDeptService sysDeptService;
|
||||
|
||||
/**
|
||||
* 新增部门管理数据。
|
||||
*
|
||||
* @param sysDept 新增对象。
|
||||
* @return 应答结果对象,包含新增对象主键Id。
|
||||
*/
|
||||
@PostMapping("/add")
|
||||
public ResponseResult<?> add(@MyRequestBody SysDept sysDept) {
|
||||
ErrorCodeEnum errorCodeEnum = ErrorCodeEnum.NO_ERROR;
|
||||
String errorMessage;
|
||||
JSONObject responseData = null;
|
||||
do {
|
||||
errorMessage = MyCommonUtil.getModelValidationError(sysDept);
|
||||
if (errorMessage != null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_VALIDATAED_FAILED;
|
||||
break;
|
||||
}
|
||||
sysDept = sysDeptService.saveNew(sysDept);
|
||||
responseData = new JSONObject();
|
||||
responseData.put("deptId", sysDept.getDeptId());
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage, responseData);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新部门管理数据。
|
||||
*
|
||||
* @param sysDept 更新对象。
|
||||
* @return 应答结果对象。
|
||||
*/
|
||||
@PostMapping("/update")
|
||||
public ResponseResult<?> update(@MyRequestBody SysDept sysDept) {
|
||||
ErrorCodeEnum errorCodeEnum = ErrorCodeEnum.NO_ERROR;
|
||||
String errorMessage;
|
||||
do {
|
||||
errorMessage = MyCommonUtil.getModelValidationError(sysDept, Default.class, UpdateGroup.class);
|
||||
if (errorMessage != null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_VALIDATAED_FAILED;
|
||||
break;
|
||||
}
|
||||
// 验证关联Id的数据合法性
|
||||
SysDept originalSysDept = sysDeptService.getById(sysDept.getDeptId());
|
||||
if (originalSysDept == null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
//TODO 修改下面方括号中的话述
|
||||
errorMessage = "数据验证失败,当前 [数据] 并不存在,请刷新后重试!";
|
||||
break;
|
||||
}
|
||||
if (!sysDeptService.update(sysDept, originalSysDept)) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
break;
|
||||
}
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除部门管理数据。
|
||||
*
|
||||
* @param deptId 删除对象主键Id。
|
||||
* @return 应答结果对象。
|
||||
*/
|
||||
@PostMapping("/delete")
|
||||
public ResponseResult<?> delete(@MyRequestBody Long deptId) {
|
||||
ErrorCodeEnum errorCodeEnum = ErrorCodeEnum.NO_ERROR;
|
||||
String errorMessage = null;
|
||||
do {
|
||||
if (MyCommonUtil.existBlankArgument(deptId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.ARGUMENT_NULL_EXIST;
|
||||
break;
|
||||
}
|
||||
// 验证关联Id的数据合法性
|
||||
SysDept originalSysDept = sysDeptService.getById(deptId);
|
||||
if (originalSysDept == null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
//TODO 修改下面方括号中的话述
|
||||
errorMessage = "数据验证失败,当前 [对象] 并不存在,请刷新后重试!";
|
||||
break;
|
||||
}
|
||||
if (!sysDeptService.remove(deptId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
errorMessage = "数据操作失败,删除的对象不存在,请刷新后重试!";
|
||||
break;
|
||||
}
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 列出符合过滤条件的部门管理列表。
|
||||
*
|
||||
* @param sysDeptFilter 过滤对象。
|
||||
* @param orderParam 排序参数。
|
||||
* @param pageParam 分页参数。
|
||||
* @return 应答结果对象,包含查询结果集。
|
||||
*/
|
||||
@PostMapping("/list")
|
||||
public ResponseResult<?> list(
|
||||
@MyRequestBody SysDept sysDeptFilter,
|
||||
@MyRequestBody MyOrderParam orderParam,
|
||||
@MyRequestBody MyPageParam pageParam) {
|
||||
if (pageParam != null) {
|
||||
PageHelper.startPage(pageParam.getPageNum(), pageParam.getPageSize());
|
||||
}
|
||||
String orderBy = MyOrderParam.buildOrderBy(orderParam, SysDept.class);
|
||||
List<SysDept> resultList = sysDeptService.getSysDeptListWithRelation(sysDeptFilter, orderBy);
|
||||
return ResponseResult.success(MyPageUtil.makeResponseData(resultList));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看指定部门管理对象详情。
|
||||
*
|
||||
* @param deptId 指定对象主键Id。
|
||||
* @return 应答结果对象,包含对象详情。
|
||||
*/
|
||||
@GetMapping("/view")
|
||||
public ResponseResult<SysDept> view(@RequestParam Long deptId) {
|
||||
ErrorCodeEnum errorCodeEnum = ErrorCodeEnum.NO_ERROR;
|
||||
String errorMessage = null;
|
||||
SysDept sysDept = null;
|
||||
do {
|
||||
if (MyCommonUtil.existBlankArgument(deptId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.ARGUMENT_NULL_EXIST;
|
||||
break;
|
||||
}
|
||||
sysDept = sysDeptService.getByIdWithRelation(deptId);
|
||||
if (sysDept == null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
break;
|
||||
}
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage, sysDept);
|
||||
}
|
||||
|
||||
/**
|
||||
* 以字典形式返回全部部门管理数据集合。字典的键值为[deptId, deptName]。
|
||||
* 白名单接口,登录用户均可访问。
|
||||
*
|
||||
* @param filter 过滤对象。
|
||||
* @return 应答结果对象,包含的数据为 List<Map<String, String>>,map中包含两条记录,key的值分别是id和name,value对应具体数据。
|
||||
*/
|
||||
@GetMapping("/listDictSysDept")
|
||||
public ResponseResult<?> listDictSysDept(SysDept filter) {
|
||||
List<SysDept> resultList = sysDeptService.getListByFilter(filter);
|
||||
return ResponseResult.success(BeanQuery.select(
|
||||
"deptId as id", "deptName as name").executeFrom(resultList));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,184 @@
|
||||
package com.orange.admin.upms.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import com.orange.admin.upms.model.SysMenu;
|
||||
import com.orange.admin.upms.service.SysMenuService;
|
||||
import com.orange.admin.upms.service.SysPermCodeService;
|
||||
import com.orange.admin.common.core.constant.ErrorCodeEnum;
|
||||
import com.orange.admin.common.core.object.VerifyResult;
|
||||
import com.orange.admin.common.core.object.ResponseResult;
|
||||
import com.orange.admin.common.core.util.MyCommonUtil;
|
||||
import com.orange.admin.common.core.validator.UpdateGroup;
|
||||
import com.orange.admin.common.core.annotation.MyRequestBody;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.groups.Default;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 菜单管理接口控制器类。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/admin/upms/sysMenu")
|
||||
public class SysMenuController {
|
||||
|
||||
@Autowired
|
||||
private SysMenuService sysMenuService;
|
||||
@Autowired
|
||||
private SysPermCodeService sysPermCodeService;
|
||||
|
||||
/**
|
||||
* 添加新菜单操作。
|
||||
*
|
||||
* @param sysMenu 新菜单对象。
|
||||
* @param permCodeIdListString 与当前菜单Id绑定的权限Id列表,多个权限之间逗号分隔。
|
||||
* @return 应答结果对象,包含新增菜单的主键Id。
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@PostMapping("/add")
|
||||
public ResponseResult<?> add(@MyRequestBody SysMenu sysMenu, @MyRequestBody String permCodeIdListString) {
|
||||
ErrorCodeEnum errorCodeEnum = ErrorCodeEnum.NO_ERROR;
|
||||
String errorMessage;
|
||||
JSONObject responseData = null;
|
||||
do {
|
||||
errorMessage = MyCommonUtil.getModelValidationError(sysMenu);
|
||||
if (errorMessage != null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_VALIDATAED_FAILED;
|
||||
break;
|
||||
}
|
||||
VerifyResult result = sysMenuService.verifyRelatedData(sysMenu, null, permCodeIdListString);
|
||||
if (!result.isSuccess()) {
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_VALIDATAED_FAILED, result.getErrorMessage());
|
||||
}
|
||||
Set<Long> permCodeIdSet = null;
|
||||
if (result.getData() != null) {
|
||||
permCodeIdSet = (Set<Long>) result.getData().get("permCodeIdSet");
|
||||
}
|
||||
sysMenuService.saveNew(sysMenu, permCodeIdSet);
|
||||
responseData = new JSONObject();
|
||||
responseData.put("sysMenuId", sysMenu.getMenuId());
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage, responseData);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新菜单数据操作。
|
||||
*
|
||||
* @param sysMenu 更新菜单对象。
|
||||
* @param permCodeIdListString 与当前菜单Id绑定的权限Id列表,多个权限之间逗号分隔。
|
||||
* @return 应答结果对象。
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@PostMapping("/update")
|
||||
public ResponseResult<?> update(@MyRequestBody SysMenu sysMenu, @MyRequestBody String permCodeIdListString) {
|
||||
ErrorCodeEnum errorCodeEnum = ErrorCodeEnum.NO_ERROR;
|
||||
String errorMessage;
|
||||
do {
|
||||
errorMessage = MyCommonUtil.getModelValidationError(sysMenu, Default.class, UpdateGroup.class);
|
||||
if (errorMessage != null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_VALIDATAED_FAILED;
|
||||
break;
|
||||
}
|
||||
SysMenu originalSysMenu = sysMenuService.getById(sysMenu.getMenuId());
|
||||
if (originalSysMenu == null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
errorMessage = "数据验证失败,当前菜单并不存在,请刷新后重试!";
|
||||
break;
|
||||
}
|
||||
VerifyResult result = sysMenuService.verifyRelatedData(sysMenu, originalSysMenu, permCodeIdListString);
|
||||
if (!result.isSuccess()) {
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_VALIDATAED_FAILED, result.getErrorMessage());
|
||||
}
|
||||
Set<Long> permCodeIdSet = null;
|
||||
if (result.getData() != null) {
|
||||
permCodeIdSet = (Set<Long>) result.getData().get("permCodeIdSet");
|
||||
}
|
||||
if (!sysMenuService.update(sysMenu, originalSysMenu, permCodeIdSet)) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
errorMessage = "数据验证失败,当前权限字并不存在,请刷新后重试!";
|
||||
}
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定菜单操作。
|
||||
*
|
||||
* @param menuId 指定菜单主键Id。
|
||||
* @return 应答结果对象。
|
||||
*/
|
||||
@PostMapping("/delete")
|
||||
public ResponseResult<?> delete(@MyRequestBody Long menuId) {
|
||||
ErrorCodeEnum errorCodeEnum = ErrorCodeEnum.NO_ERROR;
|
||||
String errorMessage = null;
|
||||
do {
|
||||
if (MyCommonUtil.existBlankArgument(menuId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.ARGUMENT_NULL_EXIST;
|
||||
break;
|
||||
}
|
||||
if (sysMenuService.hasChildren(menuId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.HAS_CHILDREN_DATA;
|
||||
errorMessage = "数据验证失败,当前菜单存在下级菜单!";
|
||||
break;
|
||||
}
|
||||
if (!sysMenuService.remove(menuId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
errorMessage = "数据操作失败,菜单不存在,请刷新后重试!";
|
||||
}
|
||||
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取全部菜单列表。
|
||||
*
|
||||
* @return 应答结果对象,包含全部菜单数据列表。
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
public ResponseResult<List<SysMenu>> list() {
|
||||
return ResponseResult.success(sysMenuService.getAllListByOrder("showOrder"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看指定菜单数据详情。
|
||||
*
|
||||
* @param menuId 指定菜单主键Id。
|
||||
* @return 应答结果对象,包含菜单详情。
|
||||
*/
|
||||
@GetMapping("/view")
|
||||
public ResponseResult<SysMenu> view(@RequestParam Long menuId) {
|
||||
ErrorCodeEnum errorCodeEnum = ErrorCodeEnum.NO_ERROR;
|
||||
String errorMessage = null;
|
||||
SysMenu sysMenu = null;
|
||||
do {
|
||||
if (MyCommonUtil.existBlankArgument(menuId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.ARGUMENT_NULL_EXIST;
|
||||
break;
|
||||
}
|
||||
sysMenu = sysMenuService.getSysMenuWithRelation(menuId);
|
||||
if (sysMenu == null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
break;
|
||||
}
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage, sysMenu);
|
||||
}
|
||||
|
||||
/**
|
||||
* 列出与指定菜单关联的权限字和权限资源,便于管理员排查配置中的错误。
|
||||
*
|
||||
* @param menuId 菜单Id。
|
||||
* @return 与菜单关联的权限字和权限资源列表。
|
||||
*/
|
||||
@GetMapping("/listMenuPerm")
|
||||
public ResponseResult<List<Map<String, Object>>> listMenuPerm(@RequestParam Long menuId) {
|
||||
return ResponseResult.success(sysPermCodeService.getPermCodeListByMenuId(menuId));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,209 @@
|
||||
package com.orange.admin.upms.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import com.orange.admin.upms.model.SysPermCode;
|
||||
import com.orange.admin.upms.service.SysPermCodeService;
|
||||
import com.orange.admin.common.core.constant.ErrorCodeEnum;
|
||||
import com.orange.admin.common.core.object.ResponseResult;
|
||||
import com.orange.admin.common.core.object.VerifyResult;
|
||||
import com.orange.admin.common.core.object.MyPageParam;
|
||||
import com.orange.admin.common.core.util.MyCommonUtil;
|
||||
import com.orange.admin.common.core.util.MyPageUtil;
|
||||
import com.orange.admin.common.core.validator.UpdateGroup;
|
||||
import com.orange.admin.common.core.annotation.MyRequestBody;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.DuplicateKeyException;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.groups.Default;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 权限字管理接口控制器类。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/admin/upms/sysPermCode")
|
||||
public class SysPermCodeController {
|
||||
|
||||
@Autowired
|
||||
private SysPermCodeService sysPermCodeService;
|
||||
|
||||
/**
|
||||
* 新增权限字操作。
|
||||
*
|
||||
* @param sysPermCode 新增权限字对象。
|
||||
* @param permIdListString 与当前权限Id绑定的权限资源Id列表,多个权限资源之间逗号分隔。
|
||||
* @return 应答结果对象,包含新增权限字的主键Id。
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@PostMapping("/add")
|
||||
public ResponseResult<?> add(@MyRequestBody SysPermCode sysPermCode, @MyRequestBody String permIdListString) {
|
||||
ErrorCodeEnum errorCodeEnum = ErrorCodeEnum.NO_ERROR;
|
||||
String errorMessage;
|
||||
JSONObject responseData = null;
|
||||
do {
|
||||
errorMessage = MyCommonUtil.getModelValidationError(sysPermCode);
|
||||
if (errorMessage != null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_VALIDATAED_FAILED;
|
||||
break;
|
||||
}
|
||||
VerifyResult result = sysPermCodeService.verifyRelatedData(sysPermCode, null, permIdListString);
|
||||
if (!result.isSuccess()) {
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_VALIDATAED_FAILED, result.getErrorMessage());
|
||||
}
|
||||
Set<Long> permIdSet = null;
|
||||
if (result.getData() != null) {
|
||||
permIdSet = (Set<Long>) result.getData().get("permIdSet");
|
||||
}
|
||||
sysPermCode = sysPermCodeService.saveNew(sysPermCode, permIdSet);
|
||||
responseData = new JSONObject();
|
||||
responseData.put("sysPermCodeId", sysPermCode.getPermCodeId());
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage, responseData);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新权限字操作。
|
||||
*
|
||||
* @param sysPermCode 更新权限字对象。
|
||||
* @param permIdListString 与当前权限Id绑定的权限资源Id列表,多个权限资源之间逗号分隔。
|
||||
* @return 应答结果对象。
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@PostMapping("/update")
|
||||
public ResponseResult<?> update(@MyRequestBody SysPermCode sysPermCode, @MyRequestBody String permIdListString) {
|
||||
ErrorCodeEnum errorCodeEnum = ErrorCodeEnum.NO_ERROR;
|
||||
String errorMessage;
|
||||
do {
|
||||
errorMessage = MyCommonUtil.getModelValidationError(sysPermCode, Default.class, UpdateGroup.class);
|
||||
if (errorMessage != null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_VALIDATAED_FAILED;
|
||||
break;
|
||||
}
|
||||
SysPermCode originalSysPermCode = sysPermCodeService.getById(sysPermCode.getPermCodeId());
|
||||
if (originalSysPermCode == null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
errorMessage = "数据验证失败,当前权限字并不存在,请刷新后重试!";
|
||||
break;
|
||||
}
|
||||
VerifyResult result = sysPermCodeService.verifyRelatedData(sysPermCode, originalSysPermCode, permIdListString);
|
||||
if (!result.isSuccess()) {
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_VALIDATAED_FAILED, result.getErrorMessage());
|
||||
}
|
||||
Set<Long> permIdSet = null;
|
||||
if (result.getData() != null) {
|
||||
permIdSet = (Set<Long>) result.getData().get("permIdSet");
|
||||
}
|
||||
try {
|
||||
if (!sysPermCodeService.update(sysPermCode, originalSysPermCode, permIdSet)) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
errorMessage = "数据验证失败,当前权限字并不存在,请刷新后重试!";
|
||||
}
|
||||
} catch (DuplicateKeyException e) {
|
||||
errorCodeEnum = ErrorCodeEnum.DUPLICATED_UNIQUE_KEY;
|
||||
errorMessage = "数据操作失败,权限字编码已经存在!";
|
||||
}
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定权限字操作。
|
||||
*
|
||||
* @param permCodeId 指定的权限字主键Id。
|
||||
* @return 应答结果对象。
|
||||
*/
|
||||
@PostMapping("/delete")
|
||||
public ResponseResult<?> delete(@MyRequestBody Long permCodeId) {
|
||||
ErrorCodeEnum errorCodeEnum = ErrorCodeEnum.NO_ERROR;
|
||||
String errorMessage = null;
|
||||
do {
|
||||
if (MyCommonUtil.existBlankArgument(permCodeId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.ARGUMENT_NULL_EXIST;
|
||||
break;
|
||||
}
|
||||
if (sysPermCodeService.hasChildren(permCodeId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.HAS_CHILDREN_DATA;
|
||||
errorMessage = "数据验证失败,当前权限字存在下级权限字!";
|
||||
break;
|
||||
}
|
||||
if (!sysPermCodeService.remove(permCodeId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
errorMessage = "数据操作失败,权限字不存在,请刷新后重试!";
|
||||
}
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看权限字列表。
|
||||
*
|
||||
* @return 应答结果对象,包含权限字列表。
|
||||
*/
|
||||
@PostMapping("/list")
|
||||
public ResponseResult<?> list() {
|
||||
return ResponseResult.success(sysPermCodeService.getAllListByOrder("permCodeType", "showOrder"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看权限字对象详情。
|
||||
*
|
||||
* @param permCodeId 指定权限字主键Id。
|
||||
* @return 应答结果对象,包含权限字对象详情。
|
||||
*/
|
||||
@GetMapping("/view")
|
||||
public ResponseResult<SysPermCode> view(@RequestParam Long permCodeId) {
|
||||
ErrorCodeEnum errorCodeEnum = ErrorCodeEnum.NO_ERROR;
|
||||
String errorMessage = null;
|
||||
SysPermCode sysPermCode = null;
|
||||
do {
|
||||
if (MyCommonUtil.existBlankArgument(permCodeId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.ARGUMENT_NULL_EXIST;
|
||||
break;
|
||||
}
|
||||
sysPermCode = sysPermCodeService.getSysPermCodeWithRelation(permCodeId);
|
||||
if (sysPermCode == null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
break;
|
||||
}
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage, sysPermCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看用户关联的权限字列表。
|
||||
*
|
||||
* @param loginName 精确匹配用户登录名。
|
||||
* @param permCode 模糊匹配的权限字名,LIKE %permCode%。
|
||||
* @param pageParam 分页对象。
|
||||
* @return 应答结果对象,包含该用户的全部权限资源列表。
|
||||
*/
|
||||
@PostMapping("/listAllPermCodesByUserFilter")
|
||||
public ResponseResult<?> listAllPermCodesByUserFilter(
|
||||
@MyRequestBody String loginName,
|
||||
@MyRequestBody String permCode,
|
||||
@MyRequestBody MyPageParam pageParam) {
|
||||
ErrorCodeEnum errorCodeEnum = ErrorCodeEnum.NO_ERROR;
|
||||
String errorMessage = null;
|
||||
JSONObject responseData = null;
|
||||
do {
|
||||
if (MyCommonUtil.existBlankArgument(loginName)) {
|
||||
errorCodeEnum = ErrorCodeEnum.ARGUMENT_NULL_EXIST;
|
||||
break;
|
||||
}
|
||||
if (pageParam != null) {
|
||||
PageHelper.startPage(pageParam.getPageNum(), pageParam.getPageSize());
|
||||
}
|
||||
List<SysPermCode> permCodeList =
|
||||
sysPermCodeService.getUserPermCodeListByFilter(loginName, permCode);
|
||||
responseData = MyPageUtil.makeResponseData(permCodeList);
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage, responseData);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,240 @@
|
||||
package com.orange.admin.upms.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import com.orange.admin.upms.model.SysPerm;
|
||||
import com.orange.admin.upms.model.SysPermModule;
|
||||
import com.orange.admin.upms.service.SysPermService;
|
||||
import com.orange.admin.common.core.constant.ErrorCodeEnum;
|
||||
import com.orange.admin.common.core.object.ResponseResult;
|
||||
import com.orange.admin.common.core.object.VerifyResult;
|
||||
import com.orange.admin.common.core.object.MyPageParam;
|
||||
import com.orange.admin.common.core.util.MyCommonUtil;
|
||||
import com.orange.admin.common.core.util.MyPageUtil;
|
||||
import com.orange.admin.common.core.validator.UpdateGroup;
|
||||
import com.orange.admin.common.core.annotation.MyRequestBody;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.groups.Default;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 权限资源管理接口控制器类。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/admin/upms/sysPerm")
|
||||
public class SysPermController {
|
||||
|
||||
@Autowired
|
||||
private SysPermService sysPermService;
|
||||
|
||||
/**
|
||||
* 新增权限资源操作。
|
||||
*
|
||||
* @param sysPerm 新增权限资源对象。
|
||||
* @return 应答结果对象,包含新增权限资源的主键Id。
|
||||
*/
|
||||
@PostMapping("/add")
|
||||
public ResponseResult<?> add(@MyRequestBody SysPerm sysPerm) {
|
||||
ErrorCodeEnum errorCodeEnum = ErrorCodeEnum.NO_ERROR;
|
||||
String errorMessage;
|
||||
JSONObject responseData = null;
|
||||
do {
|
||||
errorMessage = MyCommonUtil.getModelValidationError(sysPerm);
|
||||
if (errorMessage != null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_VALIDATAED_FAILED;
|
||||
break;
|
||||
}
|
||||
VerifyResult result = sysPermService.verifyRelatedData(sysPerm, null);
|
||||
if (!result.isSuccess()) {
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_VALIDATAED_FAILED, result.getErrorMessage());
|
||||
}
|
||||
sysPerm = sysPermService.saveNew(sysPerm);
|
||||
responseData = new JSONObject();
|
||||
responseData.put("permId", sysPerm.getPermId());
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage, responseData);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新权限资源操作。
|
||||
*
|
||||
* @param sysPerm 更新权限资源对象。
|
||||
* @return 应答结果对象,包含更新权限资源的主键Id。
|
||||
*/
|
||||
@PostMapping("/update")
|
||||
public ResponseResult<?> update(@MyRequestBody SysPerm sysPerm) {
|
||||
ErrorCodeEnum errorCodeEnum = ErrorCodeEnum.NO_ERROR;
|
||||
String errorMessage;
|
||||
do {
|
||||
errorMessage = MyCommonUtil.getModelValidationError(sysPerm, Default.class, UpdateGroup.class);
|
||||
if (errorMessage != null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_VALIDATAED_FAILED;
|
||||
break;
|
||||
}
|
||||
SysPerm originalPerm = sysPermService.getById(sysPerm.getPermId());
|
||||
if (originalPerm == null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
errorMessage = "数据验证失败,当前权限资源并不存在,请刷新后重试!";
|
||||
break;
|
||||
}
|
||||
VerifyResult result = sysPermService.verifyRelatedData(sysPerm, originalPerm);
|
||||
if (!result.isSuccess()) {
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_VALIDATAED_FAILED, result.getErrorMessage());
|
||||
}
|
||||
if (result.getData() != null) {
|
||||
SysPermModule permModule = (SysPermModule) result.getData().get("permModule");
|
||||
sysPerm.setModuleId(permModule.getModuleId());
|
||||
}
|
||||
sysPermService.update(sysPerm, originalPerm);
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定权限资源操作。
|
||||
*
|
||||
* @param permId 指定的权限资源主键Id。
|
||||
* @return 应答结果对象。
|
||||
*/
|
||||
@PostMapping("/delete")
|
||||
public ResponseResult<?> delete(@MyRequestBody Long permId) {
|
||||
ErrorCodeEnum errorCodeEnum = ErrorCodeEnum.NO_ERROR;
|
||||
String errorMessage = null;
|
||||
do {
|
||||
if (MyCommonUtil.existBlankArgument(permId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.ARGUMENT_NULL_EXIST;
|
||||
break;
|
||||
}
|
||||
if (!sysPermService.remove(permId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
errorMessage = "数据操作失败,权限不存在,请刷新后重试!";
|
||||
break;
|
||||
}
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看权限资源对象详情。
|
||||
*
|
||||
* @param permId 指定权限资源主键Id。
|
||||
* @return 应答结果对象,包含权限资源对象详情。
|
||||
*/
|
||||
@GetMapping("/view")
|
||||
public ResponseResult<SysPerm> view(@RequestParam Long permId) {
|
||||
ErrorCodeEnum errorCodeEnum = ErrorCodeEnum.NO_ERROR;
|
||||
String errorMessage = null;
|
||||
SysPerm perm = null;
|
||||
do {
|
||||
if (MyCommonUtil.existBlankArgument(permId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.ARGUMENT_NULL_EXIST;
|
||||
break;
|
||||
}
|
||||
perm = sysPermService.getById(permId);
|
||||
if (perm == null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
break;
|
||||
}
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage, perm);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看权限资源列表。
|
||||
*
|
||||
* @param sysPermFilter 过滤对象。
|
||||
* @param pageParam 分页参数。
|
||||
* @return 应答结果对象,包含权限资源列表。
|
||||
*/
|
||||
@PostMapping("/list")
|
||||
public ResponseResult<?> list(@MyRequestBody SysPerm sysPermFilter, @MyRequestBody MyPageParam pageParam) {
|
||||
if (pageParam != null) {
|
||||
PageHelper.startPage(pageParam.getPageNum(), pageParam.getPageSize());
|
||||
}
|
||||
List<SysPerm> resultList = sysPermService.getPermListWithRelation(sysPermFilter);
|
||||
return ResponseResult.success(MyPageUtil.makeResponseData(resultList));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看用户关联的权限资源列表。
|
||||
*
|
||||
* @param loginName 精确匹配用户登录名。
|
||||
* @param moduleId 精确匹配权限模块Id。
|
||||
* @param url 模糊匹配的url过滤条件。
|
||||
* @param pageParam 分页对象。
|
||||
* @return 应答结果对象,包含该用户的全部权限资源列表。
|
||||
*/
|
||||
@PostMapping("/listAllPermsByUserFilter")
|
||||
public ResponseResult<?> listAllPermsByUserFilter(
|
||||
@MyRequestBody String loginName,
|
||||
@MyRequestBody Long moduleId,
|
||||
@MyRequestBody String url,
|
||||
@MyRequestBody MyPageParam pageParam) {
|
||||
ErrorCodeEnum errorCodeEnum = ErrorCodeEnum.NO_ERROR;
|
||||
String errorMessage = null;
|
||||
JSONObject responseData = null;
|
||||
do {
|
||||
if (MyCommonUtil.existBlankArgument(loginName)) {
|
||||
errorCodeEnum = ErrorCodeEnum.ARGUMENT_NULL_EXIST;
|
||||
break;
|
||||
}
|
||||
if (pageParam != null) {
|
||||
PageHelper.startPage(pageParam.getPageNum(), pageParam.getPageSize());
|
||||
}
|
||||
List<Map<String, Object>> userPermMapList =
|
||||
sysPermService.getUserPermListByFilter(loginName, moduleId, url);
|
||||
responseData = MyPageUtil.makeResponseData(userPermMapList);
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage, responseData);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看拥有指定权限资源的所有用户数据列表。
|
||||
*
|
||||
* @param permId 指定权限资源主键Id。
|
||||
* @return 应答结果对象,包含用户数据列表。
|
||||
*/
|
||||
@PostMapping("/listAllUsers")
|
||||
public ResponseResult<?> listAllUsers(@MyRequestBody Long permId) {
|
||||
ErrorCodeEnum errorCodeEnum = ErrorCodeEnum.NO_ERROR;
|
||||
String errorMessage = null;
|
||||
List<Map<String, Object>> permUserMapList = null;
|
||||
do {
|
||||
if (MyCommonUtil.existBlankArgument(permId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.ARGUMENT_NULL_EXIST;
|
||||
break;
|
||||
}
|
||||
permUserMapList = sysPermService.getPermUserListById(permId);
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage, permUserMapList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看拥有指定权限资源的所有角色数据列表。
|
||||
*
|
||||
* @param permId 指定权限资源主键Id。
|
||||
* @return 应答结果对象,包含角色数据列表。
|
||||
*/
|
||||
@PostMapping("/listAllRoles")
|
||||
public ResponseResult<?> listAllRoles(@MyRequestBody Long permId) {
|
||||
ErrorCodeEnum errorCodeEnum = ErrorCodeEnum.NO_ERROR;
|
||||
String errorMessage = null;
|
||||
List<Map<String, Object>> permRoleMapList = null;
|
||||
do {
|
||||
if (MyCommonUtil.existBlankArgument(permId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.ARGUMENT_NULL_EXIST;
|
||||
break;
|
||||
}
|
||||
permRoleMapList = sysPermService.getPermRoleListById(permId);
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage, permRoleMapList);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
package com.orange.admin.upms.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import com.orange.admin.upms.model.SysPerm;
|
||||
import com.orange.admin.upms.model.SysPermModule;
|
||||
import com.orange.admin.upms.service.SysPermModuleService;
|
||||
import com.orange.admin.common.core.constant.ErrorCodeEnum;
|
||||
import com.orange.admin.common.core.object.ResponseResult;
|
||||
import com.orange.admin.common.core.util.MyCommonUtil;
|
||||
import com.orange.admin.common.core.validator.UpdateGroup;
|
||||
import com.orange.admin.common.core.annotation.MyRequestBody;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.groups.Default;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 权限资源模块管理接口控制器类。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/admin/upms/sysPermModule")
|
||||
public class SysPermModuleController {
|
||||
|
||||
@Autowired
|
||||
private SysPermModuleService sysPermModuleService;
|
||||
|
||||
/**
|
||||
* 新增权限资源模块操作。
|
||||
*
|
||||
* @param sysPermModule 新增权限资源模块对象。
|
||||
* @return 应答结果对象,包含新增权限资源模块的主键Id。
|
||||
*/
|
||||
@PostMapping("/add")
|
||||
public ResponseResult<?> add(@MyRequestBody SysPermModule sysPermModule) {
|
||||
ErrorCodeEnum errorCodeEnum = ErrorCodeEnum.NO_ERROR;
|
||||
String errorMessage;
|
||||
JSONObject responseData = null;
|
||||
do {
|
||||
errorMessage = MyCommonUtil.getModelValidationError(sysPermModule);
|
||||
if (errorMessage != null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_VALIDATAED_FAILED;
|
||||
break;
|
||||
}
|
||||
if (sysPermModule.getParentId() != null) {
|
||||
if (sysPermModuleService.getById(sysPermModule.getParentId()) == null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_PARENT_ID_NOT_EXIST;
|
||||
errorMessage = "数据验证失败,关联的上级权限模块并不存在,请刷新后重试!";
|
||||
break;
|
||||
}
|
||||
}
|
||||
sysPermModuleService.saveNew(sysPermModule);
|
||||
responseData = new JSONObject();
|
||||
responseData.put("permModuleId", sysPermModule.getModuleId());
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage, responseData);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新权限资源模块操作。
|
||||
*
|
||||
* @param sysPermModule 更新权限资源模块对象。
|
||||
* @return 应答结果对象,包含新增权限资源模块的主键Id。
|
||||
*/
|
||||
@PostMapping("/update")
|
||||
public ResponseResult<?> update(@MyRequestBody SysPermModule sysPermModule) {
|
||||
ErrorCodeEnum errorCodeEnum = ErrorCodeEnum.NO_ERROR;
|
||||
String errorMessage;
|
||||
do {
|
||||
errorMessage = MyCommonUtil.getModelValidationError(sysPermModule, Default.class, UpdateGroup.class);
|
||||
if (errorMessage != null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_VALIDATAED_FAILED;
|
||||
break;
|
||||
}
|
||||
SysPermModule originalPermModule = sysPermModuleService.getById(sysPermModule.getModuleId());
|
||||
if (originalPermModule == null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
break;
|
||||
}
|
||||
if (sysPermModule.getParentId() != null
|
||||
&& !sysPermModule.getParentId().equals(originalPermModule.getParentId())) {
|
||||
if (sysPermModuleService.getById(sysPermModule.getParentId()) == null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_PARENT_ID_NOT_EXIST;
|
||||
errorMessage = "数据验证失败,关联的上级权限模块并不存在,请刷新后重试!";
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!sysPermModuleService.update(sysPermModule, originalPermModule)) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
errorMessage = "数据验证失败,当前模块并不存在,请刷新后重试!";
|
||||
}
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定权限资源模块操作。
|
||||
*
|
||||
* @param moduleId 指定的权限资源模块主键Id。
|
||||
* @return 应答结果对象。
|
||||
*/
|
||||
@PostMapping("/delete")
|
||||
public ResponseResult<?> delete(@MyRequestBody Long moduleId) {
|
||||
ErrorCodeEnum errorCodeEnum = ErrorCodeEnum.NO_ERROR;
|
||||
String errorMessage = null;
|
||||
do {
|
||||
if (MyCommonUtil.existBlankArgument(moduleId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.ARGUMENT_NULL_EXIST;
|
||||
break;
|
||||
}
|
||||
if (sysPermModuleService.hasChildren(moduleId)
|
||||
|| sysPermModuleService.hasModulePerms(moduleId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.HAS_CHILDREN_DATA;
|
||||
errorMessage = "数据验证失败,当前权限模块存在子模块或权限资源,请先删除关联数据!";
|
||||
break;
|
||||
}
|
||||
if (!sysPermModuleService.remove(moduleId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
errorMessage = "数据操作失败,权限模块不存在,请刷新后重试!";
|
||||
}
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看全部权限资源模块列表。
|
||||
*
|
||||
* @return 应答结果对象,包含权限资源模块列表。
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
public ResponseResult<List<SysPermModule>> list() {
|
||||
return ResponseResult.success(sysPermModuleService.getAllListByOrder("showOrder"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 列出全部权限资源模块及其下级关联的权限资源列表。
|
||||
*
|
||||
* @return 应答结果对象,包含树状列表,结构为权限资源模块和权限资源之间的树状关系。
|
||||
*/
|
||||
@GetMapping("/listAll")
|
||||
public ResponseResult<?> listAll() {
|
||||
List<SysPermModule> sysPermModuleList = sysPermModuleService.getPermModuleAndPermList();
|
||||
List<Map<String, Object>> resultList = new LinkedList<>();
|
||||
for (SysPermModule sysPermModule : sysPermModuleList) {
|
||||
Map<String, Object> permModuleMap = new HashMap<>(5);
|
||||
permModuleMap.put("id", sysPermModule.getModuleId());
|
||||
permModuleMap.put("name", sysPermModule.getModuleName());
|
||||
permModuleMap.put("type", sysPermModule.getModuleType());
|
||||
permModuleMap.put("isPerm", false);
|
||||
if (MyCommonUtil.isNotBlankOrNull(sysPermModule.getParentId())) {
|
||||
permModuleMap.put("parentId", sysPermModule.getParentId());
|
||||
}
|
||||
resultList.add(permModuleMap);
|
||||
if (CollectionUtils.isNotEmpty(sysPermModule.getSysPermList())) {
|
||||
for (SysPerm sysPerm : sysPermModule.getSysPermList()) {
|
||||
Map<String, Object> permMap = new HashMap<>(4);
|
||||
permMap.put("id", sysPerm.getPermId());
|
||||
permMap.put("name", sysPerm.getPermName());
|
||||
permMap.put("isPerm", true);
|
||||
permMap.put("url", sysPerm.getUrl());
|
||||
permMap.put("parentId", sysPermModule.getModuleId());
|
||||
resultList.add(permMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
return ResponseResult.success(resultList);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,380 @@
|
||||
package com.orange.admin.upms.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import com.orange.admin.upms.model.SysRole;
|
||||
import com.orange.admin.upms.model.SysUser;
|
||||
import com.orange.admin.upms.model.SysUserRole;
|
||||
import com.orange.admin.upms.service.SysRoleService;
|
||||
import com.orange.admin.upms.service.SysUserService;
|
||||
import com.orange.admin.common.core.validator.UpdateGroup;
|
||||
import com.orange.admin.common.core.util.MyCommonUtil;
|
||||
import com.orange.admin.common.core.constant.ErrorCodeEnum;
|
||||
import com.orange.admin.common.core.object.MyOrderParam;
|
||||
import com.orange.admin.common.core.object.MyPageParam;
|
||||
import com.orange.admin.common.core.object.ResponseResult;
|
||||
import com.orange.admin.common.core.object.VerifyResult;
|
||||
import com.orange.admin.common.core.util.MyPageUtil;
|
||||
import com.orange.admin.common.core.annotation.MyRequestBody;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.groups.Default;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 角色管理接口控制器类。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/admin/upms/sysRole")
|
||||
public class SysRoleController {
|
||||
|
||||
@Autowired
|
||||
private SysRoleService sysRoleService;
|
||||
@Autowired
|
||||
private SysUserService sysUserService;
|
||||
|
||||
/**
|
||||
* 新增角色操作。
|
||||
*
|
||||
* @param sysRole 新增角色对象。
|
||||
* @param menuIdListString 与当前角色Id绑定的menuId列表,多个menuId之间逗号分隔。
|
||||
* @return 应答结果对象,包含新增角色的主键Id。
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@PostMapping("/add")
|
||||
public ResponseResult<?> add(@MyRequestBody SysRole sysRole, @MyRequestBody String menuIdListString) {
|
||||
ErrorCodeEnum errorCodeEnum = ErrorCodeEnum.NO_ERROR;
|
||||
String errorMessage;
|
||||
JSONObject responseData = null;
|
||||
do {
|
||||
errorMessage = MyCommonUtil.getModelValidationError(sysRole);
|
||||
if (errorMessage != null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_VALIDATAED_FAILED;
|
||||
break;
|
||||
}
|
||||
VerifyResult result = sysRoleService.verifyRelatedData(sysRole, null, menuIdListString);
|
||||
if (!result.isSuccess()) {
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_VALIDATAED_FAILED, result.getErrorMessage());
|
||||
}
|
||||
Set<Long> menuIdSet = null;
|
||||
if (result.getData() != null) {
|
||||
menuIdSet = (Set<Long>) result.getData().get("menuIdSet");
|
||||
}
|
||||
sysRoleService.saveNew(sysRole, menuIdSet);
|
||||
responseData = new JSONObject();
|
||||
responseData.put("roleId", sysRole.getRoleId());
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage, responseData);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新角色操作。
|
||||
*
|
||||
* @param sysRole 更新角色对象。
|
||||
* @param menuIdListString 与当前角色Id绑定的menuId列表,多个menuId之间逗号分隔。
|
||||
* @return 应答结果对象。
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@PostMapping("/update")
|
||||
public ResponseResult<?> update(@MyRequestBody SysRole sysRole, @MyRequestBody String menuIdListString) {
|
||||
ErrorCodeEnum errorCodeEnum = ErrorCodeEnum.NO_ERROR;
|
||||
String errorMessage;
|
||||
do {
|
||||
errorMessage = MyCommonUtil.getModelValidationError(sysRole, Default.class, UpdateGroup.class);
|
||||
if (errorMessage != null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_VALIDATAED_FAILED;
|
||||
break;
|
||||
}
|
||||
SysRole originalSysRole = sysRoleService.getById(sysRole.getRoleId());
|
||||
if (originalSysRole == null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
errorMessage = "数据验证失败,当前角色并不存在,请刷新后重试!";
|
||||
break;
|
||||
}
|
||||
VerifyResult result = sysRoleService.verifyRelatedData(sysRole, originalSysRole, menuIdListString);
|
||||
if (!result.isSuccess()) {
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_VALIDATAED_FAILED, result.getErrorMessage());
|
||||
}
|
||||
Set<Long> menuIdSet = null;
|
||||
if (result.getData() != null) {
|
||||
menuIdSet = (Set<Long>) result.getData().get("menuIdSet");
|
||||
}
|
||||
if (!sysRoleService.update(sysRole, originalSysRole, menuIdSet)) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
errorMessage = "更新失败,数据不存在,请刷新后重试!";
|
||||
break;
|
||||
}
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定角色操作。
|
||||
*
|
||||
* @param roleId 指定角色主键Id。
|
||||
* @return 应答结果对象。
|
||||
*/
|
||||
@PostMapping("/delete")
|
||||
public ResponseResult<?> delete(@MyRequestBody Long roleId) {
|
||||
ErrorCodeEnum errorCodeEnum = ErrorCodeEnum.NO_ERROR;
|
||||
String errorMessage = null;
|
||||
do {
|
||||
if (MyCommonUtil.existBlankArgument(roleId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.ARGUMENT_NULL_EXIST;
|
||||
break;
|
||||
}
|
||||
if (!sysRoleService.remove(roleId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
errorMessage = "数据操作失败,角色不存在,请刷新后重试!";
|
||||
break;
|
||||
}
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看角色列表。
|
||||
*
|
||||
* @param sysRoleFilter 角色过滤对象。
|
||||
* @param orderParam 排序参数。
|
||||
* @param pageParam 分页参数。
|
||||
* @return 应答结果对象,包含角色列表。
|
||||
*/
|
||||
@PostMapping("/list")
|
||||
public ResponseResult<?> list(
|
||||
@MyRequestBody SysRole sysRoleFilter,
|
||||
@MyRequestBody MyOrderParam orderParam,
|
||||
@MyRequestBody MyPageParam pageParam) {
|
||||
if (pageParam != null) {
|
||||
PageHelper.startPage(pageParam.getPageNum(), pageParam.getPageSize());
|
||||
}
|
||||
List<SysRole> roleList = sysRoleService.getSysRoleList(
|
||||
sysRoleFilter, MyOrderParam.buildOrderBy(orderParam, SysRole.class));
|
||||
return ResponseResult.success(MyPageUtil.makeResponseData(roleList));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看角色详情。
|
||||
*
|
||||
* @param roleId 指定角色主键Id。
|
||||
* @return 应答结果对象,包含角色详情对象。
|
||||
*/
|
||||
@GetMapping("/view")
|
||||
public ResponseResult<SysRole> view(@RequestParam Long roleId) {
|
||||
ErrorCodeEnum errorCodeEnum = ErrorCodeEnum.NO_ERROR;
|
||||
String errorMessage = null;
|
||||
SysRole sysRole = null;
|
||||
do {
|
||||
if (MyCommonUtil.existBlankArgument(roleId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.ARGUMENT_NULL_EXIST;
|
||||
break;
|
||||
}
|
||||
sysRole = sysRoleService.getSysRoleWithRelation(roleId);
|
||||
if (sysRole == null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
break;
|
||||
}
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage, sysRole);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取不包含指定角色Id的用户列表。
|
||||
* 用户和角色是多对多关系,当前接口将返回没有赋值指定RoleId的用户列表。可用于给角色添加新用户。
|
||||
*
|
||||
* @param roleId 角色主键Id。
|
||||
* @param sysUserFilter 用户过滤对象。
|
||||
* @param orderParam 排序参数。
|
||||
* @param pageParam 分页参数。
|
||||
* @return 应答结果对象,包含用户列表数据。
|
||||
*/
|
||||
@PostMapping("/listNotInUserRole")
|
||||
public ResponseResult<?> listNotInUserRole(
|
||||
@MyRequestBody Long roleId,
|
||||
@MyRequestBody SysUser sysUserFilter,
|
||||
@MyRequestBody MyOrderParam orderParam,
|
||||
@MyRequestBody MyPageParam pageParam) {
|
||||
ErrorCodeEnum errorCodeEnum = ErrorCodeEnum.NO_ERROR;
|
||||
String errorMessage = null;
|
||||
JSONObject responseData = null;
|
||||
do {
|
||||
if (MyCommonUtil.existBlankArgument(roleId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.ARGUMENT_NULL_EXIST;
|
||||
break;
|
||||
}
|
||||
if (!sysRoleService.existId(roleId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.INVALID_RELATED_RECORD_ID;
|
||||
break;
|
||||
}
|
||||
if (pageParam != null) {
|
||||
PageHelper.startPage(pageParam.getPageNum(), pageParam.getPageSize());
|
||||
}
|
||||
String orderBy = MyOrderParam.buildOrderBy(orderParam, SysUser.class);
|
||||
List<SysUser> resultList =
|
||||
sysUserService.getNotInSysUserListByRoleId(roleId, sysUserFilter, orderBy);
|
||||
responseData = MyPageUtil.makeResponseData(resultList);
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage, responseData);
|
||||
}
|
||||
|
||||
/**
|
||||
* 拥有指定角色的用户列表。
|
||||
*
|
||||
* @param roleId 角色主键Id。
|
||||
* @param sysUserFilter 用户过滤对象。
|
||||
* @param orderParam 排序参数。
|
||||
* @param pageParam 分页参数。
|
||||
* @return 应答结果对象,包含用户列表数据。
|
||||
*/
|
||||
@PostMapping("/listUserRole")
|
||||
public ResponseResult<?> listUserRole(
|
||||
@MyRequestBody Long roleId,
|
||||
@MyRequestBody SysUser sysUserFilter,
|
||||
@MyRequestBody MyOrderParam orderParam,
|
||||
@MyRequestBody MyPageParam pageParam) {
|
||||
ErrorCodeEnum errorCodeEnum = ErrorCodeEnum.NO_ERROR;
|
||||
String errorMessage = null;
|
||||
JSONObject responseData = null;
|
||||
do {
|
||||
if (MyCommonUtil.existBlankArgument(roleId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.ARGUMENT_NULL_EXIST;
|
||||
break;
|
||||
}
|
||||
if (!sysRoleService.existId(roleId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.INVALID_RELATED_RECORD_ID;
|
||||
break;
|
||||
}
|
||||
if (pageParam != null) {
|
||||
PageHelper.startPage(pageParam.getPageNum(), pageParam.getPageSize());
|
||||
}
|
||||
String orderBy = MyOrderParam.buildOrderBy(orderParam, SysUser.class);
|
||||
List<SysUser> resultList = sysUserService.getSysUserListByRoleId(roleId, sysUserFilter, orderBy);
|
||||
responseData = MyPageUtil.makeResponseData(resultList);
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage, responseData);
|
||||
}
|
||||
|
||||
/**
|
||||
* 为指定角色添加用户列表。该操作可同时给一批用户赋值角色,并在同一事务内完成。
|
||||
*
|
||||
* @param roleId 角色主键Id。
|
||||
* @param userIdListString 逗号分隔的用户Id列表。
|
||||
* @return 应答结果对象。
|
||||
*/
|
||||
@PostMapping("/addUserRole")
|
||||
public ResponseResult<?> addUserRole(
|
||||
@MyRequestBody Long roleId, @MyRequestBody String userIdListString) {
|
||||
ErrorCodeEnum errorCodeEnum = ErrorCodeEnum.NO_ERROR;
|
||||
String errorMessage = null;
|
||||
do {
|
||||
if (MyCommonUtil.existBlankArgument(roleId, userIdListString)) {
|
||||
errorCodeEnum = ErrorCodeEnum.ARGUMENT_NULL_EXIST;
|
||||
break;
|
||||
}
|
||||
Set<Long> userIdSet = Arrays.stream(
|
||||
userIdListString.split(",")).map(Long::valueOf).collect(Collectors.toSet());
|
||||
if (!sysRoleService.existId(roleId)
|
||||
|| !sysUserService.existUniqueKeyList("userId", userIdSet)) {
|
||||
errorCodeEnum = ErrorCodeEnum.INVALID_RELATED_RECORD_ID;
|
||||
break;
|
||||
}
|
||||
List<SysUserRole> userRoleList = new LinkedList<>();
|
||||
for (Long userId : userIdSet) {
|
||||
SysUserRole userRole = new SysUserRole();
|
||||
userRole.setRoleId(roleId);
|
||||
userRole.setUserId(userId);
|
||||
userRoleList.add(userRole);
|
||||
}
|
||||
sysRoleService.addUserRoleList(userRoleList);
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 为指定用户移除指定角色。
|
||||
*
|
||||
* @param roleId 指定角色主键Id。
|
||||
* @param userId 指定用户主键Id。
|
||||
* @return 应答数据结果。
|
||||
*/
|
||||
@PostMapping("/deleteUserRole")
|
||||
public ResponseResult<?> deleteUserRole(
|
||||
@MyRequestBody Long roleId, @MyRequestBody Long userId) {
|
||||
ErrorCodeEnum errorCodeEnum = ErrorCodeEnum.NO_ERROR;
|
||||
String errorMessage = null;
|
||||
do {
|
||||
if (MyCommonUtil.existBlankArgument(roleId, userId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.ARGUMENT_NULL_EXIST;
|
||||
break;
|
||||
}
|
||||
if (!sysRoleService.removeUserRole(roleId, userId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
break;
|
||||
}
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过权限字Id获取拥有改权限的所有角色。
|
||||
* 开发人员调试用接口。
|
||||
*
|
||||
* @param permCodeId 查询的权限字Id。
|
||||
* @param pageParam 分页对象。
|
||||
* @return 符合条件的角色列表。
|
||||
*/
|
||||
@PostMapping("/listAllRolesByPermCode")
|
||||
public ResponseResult<?> listAllRolesByPermCode(
|
||||
@MyRequestBody Long permCodeId, @MyRequestBody MyPageParam pageParam) {
|
||||
ErrorCodeEnum errorCodeEnum = ErrorCodeEnum.NO_ERROR;
|
||||
String errorMessage = null;
|
||||
JSONObject responseData = null;
|
||||
do {
|
||||
if (MyCommonUtil.existBlankArgument(permCodeId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.ARGUMENT_NULL_EXIST;
|
||||
break;
|
||||
}
|
||||
if (pageParam != null) {
|
||||
PageHelper.startPage(pageParam.getPageNum(), pageParam.getPageSize());
|
||||
}
|
||||
List<SysRole> roleList = sysRoleService.getSysRoleListByPermCodeId(permCodeId);
|
||||
responseData = MyPageUtil.makeResponseData(roleList);
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage, responseData);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过权限资源url,模糊搜索拥有改权限的所有角色。
|
||||
* 开发人员调试用接口。
|
||||
*
|
||||
* @param url 用于模糊搜索的url。
|
||||
* @param pageParam 分页对象。
|
||||
* @return 符合条件的角色列表。
|
||||
*/
|
||||
@PostMapping("/listAllRolesByPerm")
|
||||
public ResponseResult<?> listAllRolesByPerm(
|
||||
@MyRequestBody String url, @MyRequestBody MyPageParam pageParam) {
|
||||
ErrorCodeEnum errorCodeEnum = ErrorCodeEnum.NO_ERROR;
|
||||
String errorMessage = null;
|
||||
JSONObject responseData = null;
|
||||
do {
|
||||
if (MyCommonUtil.existBlankArgument(url)) {
|
||||
errorCodeEnum = ErrorCodeEnum.ARGUMENT_NULL_EXIST;
|
||||
break;
|
||||
}
|
||||
if (pageParam != null) {
|
||||
PageHelper.startPage(pageParam.getPageNum(), pageParam.getPageSize());
|
||||
}
|
||||
List<SysRole> roleList = sysRoleService.getSysRoleListByPerm(url);
|
||||
responseData = MyPageUtil.makeResponseData(roleList);
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage, responseData);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,236 @@
|
||||
package com.orange.admin.upms.controller;
|
||||
|
||||
import cn.jimmyshi.beanquery.BeanQuery;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.orange.admin.upms.model.*;
|
||||
import com.orange.admin.upms.service.*;
|
||||
import com.orange.admin.common.core.object.*;
|
||||
import com.orange.admin.common.core.util.*;
|
||||
import com.orange.admin.common.core.constant.ErrorCodeEnum;
|
||||
import com.orange.admin.common.core.annotation.MyRequestBody;
|
||||
import com.orange.admin.common.core.validator.UpdateGroup;
|
||||
import com.orange.admin.config.ApplicationConfig;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.*;
|
||||
import javax.validation.groups.Default;
|
||||
|
||||
/**
|
||||
* 用户管理操作控制器类。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/admin/upms/sysUser")
|
||||
public class SysUserController {
|
||||
|
||||
@Autowired
|
||||
private SysUserService sysUserService;
|
||||
@Autowired
|
||||
private ApplicationConfig applicationConfig;
|
||||
|
||||
/**
|
||||
* 新增用户操作。
|
||||
*
|
||||
* @param sysUser 新增用户对象。
|
||||
* @param roleIdListString 逗号分隔的角色Id列表。
|
||||
* @param dataPermIdListString 逗号分隔的数据权限Id列表。
|
||||
* @return 应答结果对象,包含新增用户的主键Id。
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@PostMapping("/add")
|
||||
public ResponseResult<?> add(
|
||||
@MyRequestBody SysUser sysUser,
|
||||
@MyRequestBody String roleIdListString,
|
||||
@MyRequestBody String dataPermIdListString) {
|
||||
ErrorCodeEnum errorCodeEnum = ErrorCodeEnum.NO_ERROR;
|
||||
String errorMessage;
|
||||
JSONObject responseData = null;
|
||||
do {
|
||||
errorMessage = MyCommonUtil.getModelValidationError(sysUser);
|
||||
if (errorMessage != null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_VALIDATAED_FAILED;
|
||||
break;
|
||||
}
|
||||
VerifyResult result = sysUserService.verifyRelatedData(
|
||||
sysUser, null, roleIdListString, dataPermIdListString);
|
||||
if (!result.isSuccess()) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_VALIDATAED_FAILED;
|
||||
errorMessage = result.getErrorMessage();
|
||||
break;
|
||||
}
|
||||
Set<Long> roleIdSet = (Set<Long>) result.getData().get("roleIdSet");
|
||||
Set<Long> dataPermIdSet = (Set<Long>) result.getData().get("dataPermIdSet");
|
||||
sysUserService.saveNew(sysUser, roleIdSet, dataPermIdSet, applicationConfig.getPasswordSalt());
|
||||
responseData = new JSONObject();
|
||||
responseData.put("userId", sysUser.getUserId());
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage, responseData);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新用户操作。
|
||||
*
|
||||
* @param sysUser 更新用户对象。
|
||||
* @param roleIdListString 逗号分隔的角色Id列表。
|
||||
* @param dataPermIdListString 逗号分隔的数据权限Id列表。
|
||||
* @return 应答结果对象。
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@PostMapping("/update")
|
||||
public ResponseResult<?> update(
|
||||
@MyRequestBody SysUser sysUser,
|
||||
@MyRequestBody String roleIdListString,
|
||||
@MyRequestBody String dataPermIdListString) {
|
||||
ErrorCodeEnum errorCodeEnum = ErrorCodeEnum.NO_ERROR;
|
||||
String errorMessage;
|
||||
do {
|
||||
errorMessage = MyCommonUtil.getModelValidationError(sysUser, Default.class, UpdateGroup.class);
|
||||
if (errorMessage != null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_VALIDATAED_FAILED;
|
||||
break;
|
||||
}
|
||||
SysUser originalUser = sysUserService.getById(sysUser.getUserId());
|
||||
if (originalUser == null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
break;
|
||||
}
|
||||
VerifyResult result = sysUserService.verifyRelatedData(
|
||||
sysUser, originalUser, roleIdListString, dataPermIdListString);
|
||||
if (!result.isSuccess()) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_VALIDATAED_FAILED;
|
||||
errorMessage = result.getErrorMessage();
|
||||
break;
|
||||
}
|
||||
Set<Long> roleIdSet = (Set<Long>) result.getData().get("roleIdSet");
|
||||
Set<Long> dataPermIdSet = (Set<Long>) result.getData().get("dataPermIdSet");
|
||||
if (!sysUserService.update(sysUser, originalUser, roleIdSet, dataPermIdSet)) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
errorMessage = "更新失败,数据不存在,请刷新后重试!";
|
||||
break;
|
||||
}
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置密码操作。
|
||||
*
|
||||
* @param userId 指定用户主键Id。
|
||||
* @return 应答结果对象。
|
||||
*/
|
||||
@PostMapping("/resetPassword")
|
||||
public ResponseResult<?> resetPassword(@MyRequestBody Long userId) {
|
||||
ErrorCodeEnum errorCodeEnum = ErrorCodeEnum.NO_ERROR;
|
||||
String errorMessage = null;
|
||||
do {
|
||||
if (MyCommonUtil.existBlankArgument(userId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.ARGUMENT_NULL_EXIST;
|
||||
break;
|
||||
}
|
||||
if (!sysUserService.resetPassword(
|
||||
userId, applicationConfig.getDefaultUserPassword(), applicationConfig.getPasswordSalt())) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
break;
|
||||
}
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除用户管理数据。
|
||||
*
|
||||
* @param userId 删除对象主键Id。
|
||||
* @return 应答结果对象。
|
||||
*/
|
||||
@PostMapping("/delete")
|
||||
public ResponseResult<?> delete(@MyRequestBody Long userId) {
|
||||
ErrorCodeEnum errorCodeEnum = ErrorCodeEnum.NO_ERROR;
|
||||
String errorMessage = null;
|
||||
do {
|
||||
if (MyCommonUtil.existBlankArgument(userId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.ARGUMENT_NULL_EXIST;
|
||||
break;
|
||||
}
|
||||
// 验证关联Id的数据合法性
|
||||
SysUser originalSysUser = sysUserService.getById(userId);
|
||||
if (originalSysUser == null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
//TODO 修改下面方括号中的话述
|
||||
errorMessage = "数据验证失败,当前 [对象] 并不存在,请刷新后重试!";
|
||||
break;
|
||||
}
|
||||
if (!sysUserService.remove(userId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
errorMessage = "数据操作失败,删除的对象不存在,请刷新后重试!";
|
||||
break;
|
||||
}
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 列出符合过滤条件的用户管理列表。
|
||||
*
|
||||
* @param sysUserFilter 过滤对象。
|
||||
* @param orderParam 排序参数。
|
||||
* @param pageParam 分页参数。
|
||||
* @return 应答结果对象,包含查询结果集。
|
||||
*/
|
||||
@PostMapping("/list")
|
||||
public ResponseResult<?> list(
|
||||
@MyRequestBody SysUser sysUserFilter,
|
||||
@MyRequestBody MyOrderParam orderParam,
|
||||
@MyRequestBody MyPageParam pageParam) {
|
||||
if (pageParam != null) {
|
||||
PageHelper.startPage(pageParam.getPageNum(), pageParam.getPageSize());
|
||||
}
|
||||
String orderBy = MyOrderParam.buildOrderBy(orderParam, SysUser.class);
|
||||
List<SysUser> resultList = sysUserService.getSysUserListWithRelation(sysUserFilter, orderBy);
|
||||
return ResponseResult.success(MyPageUtil.makeResponseData(resultList));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看指定用户管理对象详情。
|
||||
*
|
||||
* @param userId 指定对象主键Id。
|
||||
* @return 应答结果对象,包含对象详情。
|
||||
*/
|
||||
@GetMapping("/view")
|
||||
public ResponseResult<SysUser> view(@RequestParam Long userId) {
|
||||
ErrorCodeEnum errorCodeEnum = ErrorCodeEnum.NO_ERROR;
|
||||
String errorMessage = null;
|
||||
SysUser sysUser = null;
|
||||
do {
|
||||
if (MyCommonUtil.existBlankArgument(userId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.ARGUMENT_NULL_EXIST;
|
||||
break;
|
||||
}
|
||||
sysUser = sysUserService.getByIdWithRelation(userId);
|
||||
if (sysUser == null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
break;
|
||||
}
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage, sysUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* 以字典形式返回全部用户管理数据集合。字典的键值为[userId, loginName]。
|
||||
* 白名单接口,登录用户均可访问。
|
||||
*
|
||||
* @param filter 过滤对象。
|
||||
* @return 应答结果对象,包含的数据为 List<Map<String, String>>,map中包含两条记录,key的值分别是id和name,value对应具体数据。
|
||||
*/
|
||||
@GetMapping("/listDictSysUser")
|
||||
public ResponseResult<?> listDictSysUser(SysUser filter) {
|
||||
List<SysUser> resultList = sysUserService.getListByFilter(filter);
|
||||
return ResponseResult.success(BeanQuery.select(
|
||||
"userId as id", "loginName as name").executeFrom(resultList));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.orange.admin.upms.dao;
|
||||
|
||||
import com.orange.admin.common.core.base.dao.BaseDaoMapper;
|
||||
import com.orange.admin.upms.model.SysDataPermDept;
|
||||
|
||||
/**
|
||||
* 数据权限与部门关系数据访问操作接口。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
*/
|
||||
public interface SysDataPermDeptMapper extends BaseDaoMapper<SysDataPermDept> {
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.orange.admin.upms.dao;
|
||||
|
||||
import com.orange.admin.common.core.base.dao.BaseDaoMapper;
|
||||
import com.orange.admin.upms.model.SysDataPerm;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 数据权限数据访问操作接口。
|
||||
* NOTE: 该对象一定不能被 @EnableDataPerm 注解标注,否则会导致无限递归。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
*/
|
||||
public interface SysDataPermMapper extends BaseDaoMapper<SysDataPerm> {
|
||||
|
||||
/**
|
||||
* 获取数据权限列表。
|
||||
*
|
||||
* @param sysDataPermFilter 过滤对象。
|
||||
* @param orderBy 排序字符串。
|
||||
* @return 过滤后的数据权限列表。
|
||||
*/
|
||||
List<SysDataPerm> getSysDataPermList(
|
||||
@Param("sysDataPermFilter") SysDataPerm sysDataPermFilter, @Param("orderBy") String orderBy);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.orange.admin.upms.dao;
|
||||
|
||||
import com.orange.admin.common.core.base.dao.BaseDaoMapper;
|
||||
import com.orange.admin.upms.model.SysDataPermMenu;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 数据权限与菜单关系数据访问操作接口。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
*/
|
||||
public interface SysDataPermMenuMapper extends BaseDaoMapper<SysDataPermMenu> {
|
||||
|
||||
/**
|
||||
* 获取指定用户Id的数据权限列表。
|
||||
*
|
||||
* @param userId 指定的用户Id。
|
||||
* @return 数据权限列表。
|
||||
*/
|
||||
List<SysDataPermMenu> getSysDataPermMenuListByUserId(@Param("userId") Long userId);
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.orange.admin.upms.dao;
|
||||
|
||||
import com.orange.admin.common.core.base.dao.BaseDaoMapper;
|
||||
import com.orange.admin.upms.model.SysDataPermUser;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 数据权限与用户关系数据访问操作接口。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
*/
|
||||
public interface SysDataPermUserMapper extends BaseDaoMapper<SysDataPermUser> {
|
||||
|
||||
/**
|
||||
* 获取用户的数据权限Id列表。
|
||||
*
|
||||
* @param userId 用户Id。
|
||||
* @return 数据权限Id列表。
|
||||
*/
|
||||
List<Long> getDataPermIdListByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* 批量添加数据权限和用户关系的列表。
|
||||
*
|
||||
* @param dataPermUserList 数据权限用户关系列表。
|
||||
*/
|
||||
void addDataPermUserList(List<SysDataPermUser> dataPermUserList);
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.orange.admin.upms.dao;
|
||||
|
||||
import com.orange.admin.common.core.base.dao.BaseDaoMapper;
|
||||
import com.orange.admin.upms.model.SysDept;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 部门管理数据操作访问接口。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
*/
|
||||
public interface SysDeptMapper extends BaseDaoMapper<SysDept> {
|
||||
|
||||
/**
|
||||
* 获取过滤后的对象列表。
|
||||
*
|
||||
* @param sysDeptFilter 主表过滤对象。
|
||||
* @param orderBy 排序字符串,order by从句的参数。
|
||||
* @return 对象列表。
|
||||
*/
|
||||
List<SysDept> getSysDeptList(
|
||||
@Param("sysDeptFilter") SysDept sysDeptFilter, @Param("orderBy") String orderBy);
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.orange.admin.upms.dao;
|
||||
|
||||
import com.orange.admin.common.core.base.dao.BaseDaoMapper;
|
||||
import com.orange.admin.upms.model.SysMenu;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 菜单数据访问操作接口。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
*/
|
||||
public interface SysMenuMapper extends BaseDaoMapper<SysMenu> {
|
||||
|
||||
/**
|
||||
* 获取登录用户的菜单列表。
|
||||
*
|
||||
* @param userId 登录用户。
|
||||
* @return 菜单列表。
|
||||
*/
|
||||
List<SysMenu> getMenuListByUserId(Long userId);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.orange.admin.upms.dao;
|
||||
|
||||
import com.orange.admin.common.core.base.dao.BaseDaoMapper;
|
||||
import com.orange.admin.upms.model.SysMenuPermCode;
|
||||
|
||||
/**
|
||||
* 菜单与权限字关系数据访问操作接口。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
*/
|
||||
public interface SysMenuPermCodeMapper extends BaseDaoMapper<SysMenuPermCode> {
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.orange.admin.upms.dao;
|
||||
|
||||
import com.orange.admin.common.core.base.dao.BaseDaoMapper;
|
||||
import com.orange.admin.upms.model.SysPermCode;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 权限字数据访问操作接口。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
*/
|
||||
public interface SysPermCodeMapper extends BaseDaoMapper<SysPermCode> {
|
||||
|
||||
/**
|
||||
* 获取用户的所有权限字列表。
|
||||
*
|
||||
* @param userId 用户Id。
|
||||
* @return 该用户的权限字列表。
|
||||
*/
|
||||
List<String> getPermCodeListByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* 获取该菜单的权限字和关联的权限资源列表。
|
||||
*
|
||||
* @param menuId 菜单Id。
|
||||
* @return 权限字和关联的权限资源列表。
|
||||
*/
|
||||
List<Map<String, Object>> getPermCodeListByMenuId(Long menuId);
|
||||
|
||||
/**
|
||||
* 获取指定用户的权限字列表。
|
||||
*
|
||||
* @param loginName 精确匹配用户登录名。
|
||||
* @param permCode 模糊匹配的权限字名,LIKE %permCode%。
|
||||
* @return 权限字列表。
|
||||
*/
|
||||
List<SysPermCode> getUserPermCodeListByFilter(
|
||||
@Param("loginName") String loginName, @Param("permCode") String permCode);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.orange.admin.upms.dao;
|
||||
|
||||
import com.orange.admin.common.core.base.dao.BaseDaoMapper;
|
||||
import com.orange.admin.upms.model.SysPermCodePerm;
|
||||
|
||||
/**
|
||||
* 权限字与权限资源关系数据访问操作接口。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
*/
|
||||
public interface SysPermCodePermMapper extends BaseDaoMapper<SysPermCodePerm> {
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.orange.admin.upms.dao;
|
||||
|
||||
import com.orange.admin.common.core.base.dao.BaseDaoMapper;
|
||||
import com.orange.admin.upms.model.SysPerm;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 权限资源数据访问操作接口。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
*/
|
||||
public interface SysPermMapper extends BaseDaoMapper<SysPerm> {
|
||||
|
||||
/**
|
||||
* 获取用户的权限列表。
|
||||
*
|
||||
* @param userId 用户Id。
|
||||
* @return 该用户的权限标识列表。
|
||||
*/
|
||||
List<SysPerm> getPermListByUserId(@Param("userId") Long userId);
|
||||
|
||||
/**
|
||||
* 获取指定用户Id的权限列表。
|
||||
*
|
||||
* @param loginName 精确匹配用户登录名。
|
||||
* @param moduleId 精确匹配权限模块Id。
|
||||
* @param url 权限的url过滤条件,LIKE %url%。
|
||||
* @return 权限列表。
|
||||
*/
|
||||
List<Map<String, Object>> getUserPermListByFilter(
|
||||
@Param("loginName") String loginName, @Param("moduleId") Long moduleId, @Param("url") String url);
|
||||
|
||||
/**
|
||||
* 根据关联权限字主键Id,获取权限资源数据列表。
|
||||
*
|
||||
* @param permCodeId 关联权限字主键Id。
|
||||
* @param orderBy 排序字符串,ORDER BY从句的参数。
|
||||
* @return 从表数据列表。
|
||||
*/
|
||||
List<SysPerm> getPermListByPermCodeId(@Param("permCodeId") Long permCodeId, @Param("orderBy") String orderBy);
|
||||
|
||||
/**
|
||||
* 获取指定权限的用户列表。
|
||||
*
|
||||
* @param permId 指定权限。
|
||||
* @return 用户列表。
|
||||
*/
|
||||
List<Map<String, Object>> getPermUserListById(@Param("permId") Long permId);
|
||||
|
||||
/**
|
||||
* 获取指定权限的角色列表。
|
||||
*
|
||||
* @param permId 指定权限。
|
||||
* @return 角色列表。
|
||||
*/
|
||||
List<Map<String, Object>> getPermRoleListById(@Param("permId") Long permId);
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.orange.admin.upms.dao;
|
||||
|
||||
import com.orange.admin.common.core.base.dao.BaseDaoMapper;
|
||||
import com.orange.admin.upms.model.SysPermModule;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 权限资源模块数据访问操作接口。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
*/
|
||||
public interface SysPermModuleMapper extends BaseDaoMapper<SysPermModule> {
|
||||
|
||||
/**
|
||||
* 获取整个权限模块和权限关联后的全部数据。
|
||||
*
|
||||
* @return 关联的权限模块和权限资源列表。
|
||||
*/
|
||||
List<SysPermModule> getPermModuleAndPermList();
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.orange.admin.upms.dao;
|
||||
|
||||
import com.orange.admin.common.core.base.dao.BaseDaoMapper;
|
||||
import com.orange.admin.upms.model.SysPermWhitelist;
|
||||
|
||||
/**
|
||||
* 权限资源白名单数据访问操作接口。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
*/
|
||||
public interface SysPermWhitelistMapper extends BaseDaoMapper<SysPermWhitelist> {
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.orange.admin.upms.dao;
|
||||
|
||||
import com.orange.admin.common.core.base.dao.BaseDaoMapper;
|
||||
import com.orange.admin.upms.model.SysRole;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 角色数据访问操作接口。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
*/
|
||||
public interface SysRoleMapper extends BaseDaoMapper<SysRole> {
|
||||
|
||||
/**
|
||||
* 获取对象列表,过滤条件中包含like和between条件。
|
||||
*
|
||||
* @param sysRoleFilter 过滤对象。
|
||||
* @param orderBy 排序字符串,order by从句的参数。
|
||||
* @return 对象列表。
|
||||
*/
|
||||
List<SysRole> getSysRoleList(@Param("sysRoleFilter") SysRole sysRoleFilter, @Param("orderBy") String orderBy);
|
||||
|
||||
/**
|
||||
* 根据权限字Id获取关联的角色列表。
|
||||
*
|
||||
* @param permCodeId 权限字Id。
|
||||
* @return 关联的角色列表。
|
||||
*/
|
||||
List<SysRole> getSysRoleListByPermCodeId(@Param("permCodeId") Long permCodeId);
|
||||
|
||||
/**
|
||||
* 根据url模糊查询关联的角色列表。
|
||||
*
|
||||
* @param url url片段。
|
||||
* @return 关联的角色列表。
|
||||
*/
|
||||
List<SysRole> getSysRoleListByPerm(@Param("url") String url);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.orange.admin.upms.dao;
|
||||
|
||||
import com.orange.admin.common.core.base.dao.BaseDaoMapper;
|
||||
import com.orange.admin.upms.model.SysRoleMenu;
|
||||
|
||||
/**
|
||||
* 角色与菜单操作关联关系数据访问操作接口。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
*/
|
||||
public interface SysRoleMenuMapper extends BaseDaoMapper<SysRoleMenu> {
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package com.orange.admin.upms.dao;
|
||||
|
||||
import com.orange.admin.common.core.base.dao.BaseDaoMapper;
|
||||
import com.orange.admin.upms.model.SysUser;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 用户管理数据操作访问接口。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
*/
|
||||
public interface SysUserMapper extends BaseDaoMapper<SysUser> {
|
||||
|
||||
/**
|
||||
* 获取过滤后的对象列表。
|
||||
*
|
||||
* @param sysUserFilter 主表过滤对象。
|
||||
* @param orderBy 排序字符串,order by从句的参数。
|
||||
* @return 对象列表。
|
||||
*/
|
||||
List<SysUser> getSysUserList(
|
||||
@Param("sysUserFilter") SysUser sysUserFilter, @Param("orderBy") String orderBy);
|
||||
|
||||
/**
|
||||
* 根据角色Id,获取关联的用户Id列表。
|
||||
*
|
||||
* @param roleId 关联的角色Id。
|
||||
* @param sysUserFilter 用户过滤条件对象。
|
||||
* @param orderBy order by从句的参数。
|
||||
* @return 和RoleId关联的用户列表。
|
||||
*/
|
||||
List<SysUser> getSysUserListByRoleId(
|
||||
@Param("roleId") Long roleId,
|
||||
@Param("sysUserFilter") SysUser sysUserFilter,
|
||||
@Param("orderBy") String orderBy);
|
||||
|
||||
/**
|
||||
* 根据角色Id,获取和当前角色Id没有建立多对多关联关系的用户Id列表。
|
||||
*
|
||||
* @param roleId 关联的角色Id。
|
||||
* @param sysUserFilter 用户过滤条件对象。
|
||||
* @param orderBy order by从句的参数。
|
||||
* @return 和RoleId没有建立关联关系的用户列表。
|
||||
*/
|
||||
List<SysUser> getNotInSysUserListByRoleId(
|
||||
@Param("roleId") Long roleId,
|
||||
@Param("sysUserFilter") SysUser sysUserFilter,
|
||||
@Param("orderBy") String orderBy);
|
||||
|
||||
/**
|
||||
* 根据数据权限Id,获取关联的用户Id列表。
|
||||
*
|
||||
* @param dataPermId 关联的数据权限Id。
|
||||
* @param sysUserFilter 用户过滤条件对象。
|
||||
* @param orderBy order by从句的参数。
|
||||
* @return 和DataPermId关联的用户列表。
|
||||
*/
|
||||
List<SysUser> getSysUserListByDataPermId(
|
||||
@Param("dataPermId") Long dataPermId,
|
||||
@Param("sysUserFilter") SysUser sysUserFilter,
|
||||
@Param("orderBy") String orderBy);
|
||||
|
||||
/**
|
||||
* 根据数据权限Id,获取和当前数据权限Id没有建立多对多关联关系的用户Id列表。
|
||||
*
|
||||
* @param dataPermId 关联的数据权限Id。
|
||||
* @param sysUserFilter 用户过滤条件对象。
|
||||
* @param orderBy order by从句的参数。
|
||||
* @return 和DataPermId没有建立关联关系的用户列表。
|
||||
*/
|
||||
List<SysUser> getNotInSysUserListByDataPermId(
|
||||
@Param("dataPermId") Long dataPermId,
|
||||
@Param("sysUserFilter") SysUser sysUserFilter,
|
||||
@Param("orderBy") String orderBy);
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.orange.admin.upms.dao;
|
||||
|
||||
import com.orange.admin.common.core.base.dao.BaseDaoMapper;
|
||||
import com.orange.admin.upms.model.SysUserRole;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户与角色关联关系数据访问操作接口。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
*/
|
||||
public interface SysUserRoleMapper extends BaseDaoMapper<SysUserRole> {
|
||||
|
||||
/**
|
||||
* 获取用户的角色Id列表。
|
||||
*
|
||||
* @param userId 用户Id。
|
||||
* @return 角色Id列表。
|
||||
*/
|
||||
List<Long> getRoleIdListByUserId(@Param("userId") Long userId);
|
||||
|
||||
/**
|
||||
* 批量插入用户角色信息,如果用户角色已经存在,则不会重复插入。
|
||||
*
|
||||
* @param userRoleList 待插入的角色用户列表。
|
||||
*/
|
||||
void addUserRoleList(List<SysUserRole> userRoleList);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
<?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.orange.admin.upms.dao.SysDataPermDeptMapper">
|
||||
<resultMap id="BaseResultMap" type="com.orange.admin.upms.model.SysDataPermDept">
|
||||
<result column="data_perm_id" jdbcType="BIGINT" property="dataPermId"/>
|
||||
<result column="dept_id" jdbcType="BIGINT" property="deptId"/>
|
||||
</resultMap>
|
||||
</mapper>
|
||||
@@ -0,0 +1,47 @@
|
||||
<?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.orange.admin.upms.dao.SysDataPermMapper">
|
||||
<resultMap id="BaseResultMap" type="com.orange.admin.upms.model.SysDataPerm">
|
||||
<id column="data_perm_id" jdbcType="BIGINT" property="dataPermId"/>
|
||||
<result column="data_perm_name" jdbcType="VARCHAR" property="dataPermName"/>
|
||||
<result column="rule_type" jdbcType="INTEGER" property="ruleType"/>
|
||||
<result column="create_user_id" jdbcType="BIGINT" property="createUserId"/>
|
||||
<result column="create_username" jdbcType="VARCHAR" property="createUsername"/>
|
||||
<result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
|
||||
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
|
||||
<result column="deleted_flag" jdbcType="INTEGER" property="deletedFlag"/>
|
||||
</resultMap>
|
||||
|
||||
<resultMap id="BaseResultMapEx" type="com.orange.admin.upms.model.SysDataPerm" extends="BaseResultMap">
|
||||
<collection property="dataPermDeptList" column="data_perm_id" javaType="ArrayList"
|
||||
ofType="com.orange.admin.upms.model.SysDataPermDept" notNullColumn="dept_id"
|
||||
resultMap="com.orange.admin.upms.dao.SysDataPermDeptMapper.BaseResultMap">
|
||||
</collection>
|
||||
</resultMap>
|
||||
|
||||
<sql id="filterRef">
|
||||
<if test="sysDataPermFilter != null">
|
||||
<if test="sysDataPermFilter.ruleType != null">
|
||||
AND zz_sys_data_perm.rule_type = #{sysDataPermFilter.ruleType}
|
||||
</if>
|
||||
<if test="sysDataPermFilter.searchString != null and sysDataPermFilter.searchString != ''">
|
||||
<bind name= "safeSearchString" value= "'%' + sysDataPermFilter.searchString + '%'" />
|
||||
AND IFNULL(zz_sys_data_perm.data_perm_name, '') LIKE #{safeSearchString}
|
||||
</if>
|
||||
</if>
|
||||
AND zz_sys_data_perm.deleted_flag = ${@com.orange.admin.common.core.constant.GlobalDeletedFlag@NORMAL}
|
||||
</sql>
|
||||
|
||||
<select id="getSysDataPermList" resultMap="BaseResultMap" parameterType="com.orange.admin.upms.model.SysDataPerm">
|
||||
SELECT
|
||||
zz_sys_data_perm.*
|
||||
FROM
|
||||
zz_sys_data_perm
|
||||
<where>
|
||||
<include refid="filterRef"/>
|
||||
</where>
|
||||
<if test="orderBy != null">
|
||||
ORDER BY ${orderBy}
|
||||
</if>
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,27 @@
|
||||
<?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.orange.admin.upms.dao.SysDataPermMenuMapper">
|
||||
<resultMap id="BaseResultMap" type="com.orange.admin.upms.model.SysDataPermMenu">
|
||||
<result column="data_perm_id" jdbcType="BIGINT" property="dataPermId"/>
|
||||
<result column="menu_id" jdbcType="BIGINT" property="menuId"/>
|
||||
</resultMap>
|
||||
|
||||
<resultMap id="BaseResultMapEx" type="com.orange.admin.upms.model.SysDataPermMenu" extends="BaseResultMap">
|
||||
<result column="rule_type" jdbcType="INTEGER" property="ruleType"/>
|
||||
</resultMap>
|
||||
|
||||
<select id="getSysDataPermMenuListByUserId" resultMap="BaseResultMapEx" >
|
||||
SELECT
|
||||
dpm.*, dp.rule_type
|
||||
FROM
|
||||
zz_sys_data_perm_user dpu
|
||||
INNER JOIN
|
||||
zz_sys_data_perm dp ON dpu.data_perm_id = dp.data_perm_id
|
||||
LEFT JOIN
|
||||
zz_sys_data_perm_menu dpm ON dpu.data_perm_id = dpm.data_perm_id
|
||||
<where>
|
||||
AND dpu.user_id = #{userId}
|
||||
AND dp.deleted_flag = ${@com.orange.admin.common.core.constant.GlobalDeletedFlag@NORMAL}
|
||||
</where>
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,19 @@
|
||||
<?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.orange.admin.upms.dao.SysDataPermUserMapper">
|
||||
<resultMap id="BaseResultMap" type="com.orange.admin.upms.model.SysDataPermUser">
|
||||
<result column="data_perm_id" jdbcType="BIGINT" property="dataPermId"/>
|
||||
<result column="user_id" jdbcType="BIGINT" property="userId"/>
|
||||
</resultMap>
|
||||
|
||||
<select id="getDataPermIdListByUserId" resultType="java.lang.Long">
|
||||
SELECT data_perm_id FROM zz_sys_data_perm_user WHERE user_id = #{userId}
|
||||
</select>
|
||||
|
||||
<insert id="addDataPermUserList">
|
||||
REPLACE INTO zz_sys_data_perm_user(data_perm_id, user_id) VALUES
|
||||
<foreach collection="list" index="index" item="item" separator=",">
|
||||
(#{item.dataPermId}, #{item.userId})
|
||||
</foreach>
|
||||
</insert>
|
||||
</mapper>
|
||||
@@ -0,0 +1,34 @@
|
||||
<?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.orange.admin.upms.dao.SysDeptMapper">
|
||||
<resultMap id="BaseResultMap" type="com.orange.admin.upms.model.SysDept">
|
||||
<id column="dept_id" jdbcType="BIGINT" property="deptId"/>
|
||||
<result column="dept_name" jdbcType="VARCHAR" property="deptName"/>
|
||||
<result column="show_order" jdbcType="INTEGER" property="showOrder"/>
|
||||
<result column="deleted_flag" jdbcType="INTEGER" property="deletedFlag"/>
|
||||
<result column="create_user_id" jdbcType="BIGINT" property="createUserId"/>
|
||||
<result column="create_username" jdbcType="VARCHAR" property="createUsername"/>
|
||||
<result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
|
||||
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="filterRef">
|
||||
<if test="sysDeptFilter != null">
|
||||
<if test="sysDeptFilter.deptName != null and sysDeptFilter.deptName != ''">
|
||||
<bind name = "safeDeptName" value = "'%' + sysDeptFilter.deptName + '%'" />
|
||||
AND zz_sys_dept.dept_name LIKE #{safeDeptName}
|
||||
</if>
|
||||
</if>
|
||||
AND zz_sys_dept.deleted_flag = ${@com.orange.admin.common.core.constant.GlobalDeletedFlag@NORMAL}
|
||||
</sql>
|
||||
|
||||
<select id="getSysDeptList" resultMap="BaseResultMap" parameterType="com.orange.admin.upms.model.SysDept">
|
||||
SELECT * FROM zz_sys_dept
|
||||
<where>
|
||||
<include refid="filterRef"/>
|
||||
</where>
|
||||
<if test="orderBy != null">
|
||||
ORDER BY ${orderBy}
|
||||
</if>
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,35 @@
|
||||
<?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.orange.admin.upms.dao.SysMenuMapper">
|
||||
<resultMap id="BaseResultMap" type="com.orange.admin.upms.model.SysMenu">
|
||||
<id column="menu_id" jdbcType="BIGINT" property="menuId"/>
|
||||
<result column="parent_id" jdbcType="BIGINT" property="parentId"/>
|
||||
<result column="menu_name" jdbcType="VARCHAR" property="menuName"/>
|
||||
<result column="menu_type" jdbcType="INTEGER" property="menuType"/>
|
||||
<result column="form_router_name" jdbcType="VARCHAR" property="formRouterName"/>
|
||||
<result column="show_order" jdbcType="INTEGER" property="showOrder"/>
|
||||
<result column="icon" jdbcType="VARCHAR" property="icon"/>
|
||||
<result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
|
||||
<result column="deleted_flag" jdbcType="INTEGER" property="deletedFlag"/>
|
||||
</resultMap>
|
||||
|
||||
<select id="getMenuListByUserId" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
DISTINCT m.*
|
||||
FROM
|
||||
zz_sys_user u,
|
||||
zz_sys_user_role ur,
|
||||
zz_sys_role_menu rm,
|
||||
zz_sys_menu m
|
||||
<where>
|
||||
AND u.user_id = #{userId}
|
||||
AND u.deleted_flag = ${@com.orange.admin.common.core.constant.GlobalDeletedFlag@NORMAL}
|
||||
AND u.user_id = ur.user_id
|
||||
AND ur.role_id = rm.role_id
|
||||
AND rm.menu_id = m.menu_id
|
||||
AND m.menu_type <= ${@com.orange.admin.upms.model.constant.SysMenuType@TYPE_MENU}
|
||||
AND m.deleted_flag = ${@com.orange.admin.common.core.constant.GlobalDeletedFlag@NORMAL}
|
||||
</where>
|
||||
ORDER BY m.show_order
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,8 @@
|
||||
<?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.orange.admin.upms.dao.SysMenuPermCodeMapper">
|
||||
<resultMap id="BaseResultMap" type="com.orange.admin.upms.model.SysMenuPermCode">
|
||||
<result column="menu_id" jdbcType="BIGINT" property="menuId"/>
|
||||
<result column="perm_cod_id" jdbcType="BIGINT" property="permCodeId"/>
|
||||
</resultMap>
|
||||
</mapper>
|
||||
@@ -0,0 +1,84 @@
|
||||
<?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.orange.admin.upms.dao.SysPermCodeMapper">
|
||||
<resultMap id="BaseResultMap" type="com.orange.admin.upms.model.SysPermCode">
|
||||
<id column="perm_code_id" jdbcType="BIGINT" property="permCodeId"/>
|
||||
<result column="parent_id" jdbcType="BIGINT" property="parentId"/>
|
||||
<result column="perm_code" jdbcType="VARCHAR" property="permCode"/>
|
||||
<result column="perm_code_type" jdbcType="INTEGER" property="permCodeType"/>
|
||||
<result column="show_name" jdbcType="VARCHAR" property="showName"/>
|
||||
<result column="show_order" jdbcType="INTEGER" property="showOrder"/>
|
||||
<result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
|
||||
<result column="deleted_flag" jdbcType="INTEGER" property="deletedFlag"/>
|
||||
</resultMap>
|
||||
|
||||
<select id="getPermCodeListByUserId" resultType="java.lang.String">
|
||||
SELECT
|
||||
DISTINCT pc.perm_code
|
||||
FROM
|
||||
zz_sys_user u,
|
||||
zz_sys_user_role ur,
|
||||
zz_sys_role_menu rm,
|
||||
zz_sys_menu_perm_code mpc,
|
||||
zz_sys_perm_code pc
|
||||
<where>
|
||||
AND u.user_id = #{userId}
|
||||
AND u.deleted_flag = ${@com.orange.admin.common.core.constant.GlobalDeletedFlag@NORMAL}
|
||||
AND u.user_id = ur.user_id
|
||||
AND ur.role_id = rm.role_id
|
||||
AND rm.menu_id = mpc.menu_id
|
||||
AND mpc.perm_code_id = pc.perm_code_id
|
||||
AND pc.deleted_flag = ${@com.orange.admin.common.core.constant.GlobalDeletedFlag@NORMAL}
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="getUserPermCodeListByFilter" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
DISTINCT pc.*
|
||||
FROM
|
||||
zz_sys_user u,
|
||||
zz_sys_user_role ur,
|
||||
zz_sys_role_menu rm,
|
||||
zz_sys_menu_perm_code mpc,
|
||||
zz_sys_perm_code pc
|
||||
<where>
|
||||
AND u.login_name = #{loginName}
|
||||
AND u.deleted_flag = ${@com.orange.admin.common.core.constant.GlobalDeletedFlag@NORMAL}
|
||||
AND u.user_id = ur.user_id
|
||||
AND ur.role_id = rm.role_id
|
||||
AND rm.menu_id = mpc.menu_id
|
||||
AND mpc.perm_code_id = pc.perm_code_id
|
||||
AND pc.deleted_flag = ${@com.orange.admin.common.core.constant.GlobalDeletedFlag@NORMAL}
|
||||
<if test="permCode != null and permCode != ''">
|
||||
<bind name= "safePermCode" value= "'%' + permCode + '%'" />
|
||||
AND pc.perm_code LIKE #{safePermCode}
|
||||
</if>
|
||||
</where>
|
||||
ORDER BY pc.create_time
|
||||
</select>
|
||||
|
||||
<select id="getPermCodeListByMenuId" resultType="map">
|
||||
SELECT
|
||||
pc.perm_code_id permCodeId,
|
||||
pc.show_name showName,
|
||||
pc.perm_code_type permCodeType,
|
||||
pc.perm_code permCode,
|
||||
p.perm_id permId,
|
||||
p.perm_name permName,
|
||||
p.url
|
||||
FROM
|
||||
zz_sys_menu_perm_code mpc,
|
||||
zz_sys_perm_code_perm pcp,
|
||||
zz_sys_perm_code pc,
|
||||
zz_sys_perm p
|
||||
<where>
|
||||
AND mpc.menu_id = #{menuId}
|
||||
AND mpc.perm_code_id = pc.perm_code_id
|
||||
AND mpc.perm_code_id = pcp.perm_code_id
|
||||
AND pcp.perm_id = p.perm_id
|
||||
AND pc.deleted_flag = ${@com.orange.admin.common.core.constant.GlobalDeletedFlag@NORMAL}
|
||||
AND p.deleted_flag = ${@com.orange.admin.common.core.constant.GlobalDeletedFlag@NORMAL}
|
||||
</where>
|
||||
ORDER BY pc.perm_code_id, p.show_order
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,8 @@
|
||||
<?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.orange.admin.upms.dao.SysPermCodePermMapper">
|
||||
<resultMap id="BaseResultMap" type="com.orange.admin.upms.model.SysPermCodePerm">
|
||||
<id column="perm_code_id" jdbcType="BIGINT" property="permCodeId"/>
|
||||
<id column="perm_id" jdbcType="BIGINT" property="permId"/>
|
||||
</resultMap>
|
||||
</mapper>
|
||||
@@ -0,0 +1,134 @@
|
||||
<?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.orange.admin.upms.dao.SysPermMapper">
|
||||
<resultMap id="BaseResultMap" type="com.orange.admin.upms.model.SysPerm">
|
||||
<id column="perm_id" jdbcType="BIGINT" property="permId"/>
|
||||
<result column="module_id" jdbcType="BIGINT" property="moduleId"/>
|
||||
<result column="perm_name" jdbcType="VARCHAR" property="permName"/>
|
||||
<result column="url" jdbcType="VARCHAR" property="url"/>
|
||||
<result column="show_order" jdbcType="INTEGER" property="showOrder"/>
|
||||
<result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
|
||||
<result column="deleted_flag" jdbcType="INTEGER" property="deletedFlag"/>
|
||||
</resultMap>
|
||||
|
||||
<select id="getPermListByUserId" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
p.*
|
||||
FROM
|
||||
zz_sys_user u,
|
||||
zz_sys_user_role ur,
|
||||
zz_sys_role_menu rm,
|
||||
zz_sys_menu_perm_code mpc,
|
||||
zz_sys_perm_code_perm pcp,
|
||||
zz_sys_perm p
|
||||
<where>
|
||||
AND u.user_id = #{userId}
|
||||
AND u.deleted_flag = ${@com.orange.admin.common.core.constant.GlobalDeletedFlag@NORMAL}
|
||||
AND u.user_id = ur.user_id
|
||||
AND ur.role_id = rm.role_id
|
||||
AND rm.menu_id = mpc.menu_id
|
||||
AND mpc.perm_code_id = pcp.perm_code_id
|
||||
AND pcp.perm_id = p.perm_id
|
||||
AND p.deleted_flag = ${@com.orange.admin.common.core.constant.GlobalDeletedFlag@NORMAL}
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="getUserPermListByFilter" resultType="map">
|
||||
SELECT
|
||||
pm.module_id moduleId,
|
||||
pm.module_name moduleName,
|
||||
p.perm_id permId,
|
||||
p.perm_name permName,
|
||||
p.create_time createTime,
|
||||
p.url
|
||||
FROM
|
||||
zz_sys_user u,
|
||||
zz_sys_user_role ur,
|
||||
zz_sys_role_menu rm,
|
||||
zz_sys_menu_perm_code mpc,
|
||||
zz_sys_perm_code_perm pcp,
|
||||
zz_sys_perm p,
|
||||
zz_sys_perm_module pm
|
||||
<where>
|
||||
AND u.login_name = #{loginName}
|
||||
AND u.deleted_flag = ${@com.orange.admin.common.core.constant.GlobalDeletedFlag@NORMAL}
|
||||
AND u.user_id = ur.user_id
|
||||
AND ur.role_id = rm.role_id
|
||||
AND rm.menu_id = mpc.menu_id
|
||||
AND mpc.perm_code_id = pcp.perm_code_id
|
||||
AND pcp.perm_id = p.perm_id
|
||||
AND p.module_id = pm.module_id
|
||||
AND p.deleted_flag = ${@com.orange.admin.common.core.constant.GlobalDeletedFlag@NORMAL}
|
||||
AND pm.deleted_flag = ${@com.orange.admin.common.core.constant.GlobalDeletedFlag@NORMAL}
|
||||
<if test="url != null and url != ''">
|
||||
<bind name= "safeUrl" value= "'%' + url + '%'" />
|
||||
AND p.url LIKE #{safeUrl}
|
||||
</if>
|
||||
<if test="moduleId != null">
|
||||
AND p.module_id = #{moduleId}
|
||||
</if>
|
||||
</where>
|
||||
ORDER BY pm.module_id, p.create_time
|
||||
</select>
|
||||
|
||||
<select id="getPermListByPermCodeId" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
p.*
|
||||
FROM
|
||||
zz_sys_perm_code_perm pcp,
|
||||
zz_sys_perm p
|
||||
<where>
|
||||
AND pcp.perm_code_id = #{permCodeId}
|
||||
AND pcp.perm_id = p.perm_id
|
||||
AND p.deleted_flag = ${@com.orange.admin.common.core.constant.GlobalDeletedFlag@NORMAL}
|
||||
</where>
|
||||
<if test="orderBy != null">
|
||||
ORDER BY ${orderBy}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<select id="getPermUserListById" resultType="map">
|
||||
SELECT
|
||||
u.user_id,
|
||||
u.login_name
|
||||
u.show_name
|
||||
FROM
|
||||
zz_sys_perm p,
|
||||
zz_sys_perm_code_perm pcp,
|
||||
zz_sys_menu_perm_code mpc,
|
||||
zz_sys_role_menu rm,
|
||||
zz_sys_user_role ur,
|
||||
zz_sys_user u
|
||||
<where>
|
||||
AND p.perm_id = #{permId}
|
||||
AND p.perm_id = pcp.perm_id
|
||||
AND pcp.perm_code_id = mpc.perm_code_id
|
||||
AND mpc.menu_id = rm.menu_id
|
||||
AND rm.role_id = ur.role_id
|
||||
AND ur.user_id = u.user_id
|
||||
AND u.deleted_flag = ${@com.orange.admin.common.core.constant.GlobalDeletedFlag@NORMAL}
|
||||
AND p.deleted_flag = ${@com.orange.admin.common.core.constant.GlobalDeletedFlag@NORMAL}
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="getPermRoleListById" resultType="map">
|
||||
SELECT
|
||||
r.role_id,
|
||||
r.role_name
|
||||
FROM
|
||||
zz_sys_perm p,
|
||||
zz_sys_perm_code_perm pcp,
|
||||
zz_sys_menu_perm_code mpc,
|
||||
zz_sys_role_menu rm,
|
||||
zz_sys_role r
|
||||
<where>
|
||||
AND p.perm_id = #{permId}
|
||||
AND p.perm_id = pcp.perm_id
|
||||
AND p.deleted_flag = ${@com.orange.admin.common.core.constant.GlobalDeletedFlag@NORMAL}
|
||||
AND r.deleted_flag = ${@com.orange.admin.common.core.constant.GlobalDeletedFlag@NORMAL}
|
||||
AND pcp.perm_code_id = mpc.perm_code_id
|
||||
AND mpc.menu_id = rm.menu_id
|
||||
AND rm.role_id = r.role_id
|
||||
</where>
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,42 @@
|
||||
<?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.orange.admin.upms.dao.SysPermModuleMapper">
|
||||
<resultMap id="BaseResultMap" type="com.orange.admin.upms.model.SysPermModule">
|
||||
<result column="module_id" jdbcType="BIGINT" property="moduleId"/>
|
||||
<result column="parent_id" jdbcType="BIGINT" property="parentId"/>
|
||||
<result column="module_name" jdbcType="VARCHAR" property="moduleName"/>
|
||||
<result column="module_type" jdbcType="INTEGER" property="moduleType"/>
|
||||
<result column="show_order" jdbcType="INTEGER" property="showOrder"/>
|
||||
<result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
|
||||
<result column="deleted_flag" jdbcType="INTEGER" property="deletedFlag"/>
|
||||
</resultMap>
|
||||
|
||||
<resultMap id="BaseResultMapEx" type="com.orange.admin.upms.model.SysPermModule" extends="BaseResultMap">
|
||||
<collection property="sysPermList" column="module_id" javaType="ArrayList"
|
||||
ofType="com.orange.admin.upms.model.SysPerm" notNullColumn="perm_id"
|
||||
resultMap="com.orange.admin.upms.dao.SysPermMapper.BaseResultMap">
|
||||
</collection>
|
||||
</resultMap>
|
||||
|
||||
<select id="getPermModuleAndPermList" resultMap="BaseResultMapEx">
|
||||
SELECT
|
||||
pm.module_id,
|
||||
pm.module_name,
|
||||
pm.parent_id,
|
||||
pm.module_type,
|
||||
p.perm_id,
|
||||
p.perm_name,
|
||||
p.module_id,
|
||||
p.url
|
||||
FROM
|
||||
zz_sys_perm_module pm
|
||||
LEFT JOIN
|
||||
zz_sys_perm p ON pm.module_id = p.module_id
|
||||
<where>
|
||||
AND p.deleted_flag = ${@com.orange.admin.common.core.constant.GlobalDeletedFlag@NORMAL}
|
||||
AND pm.deleted_flag = ${@com.orange.admin.common.core.constant.GlobalDeletedFlag@NORMAL}
|
||||
</where>
|
||||
ORDER BY
|
||||
pm.show_order, p.show_order
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,9 @@
|
||||
<?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.orange.admin.upms.dao.SysPermWhitelistMapper">
|
||||
<resultMap id="BaseResultMap" type="com.orange.admin.upms.model.SysPermWhitelist">
|
||||
<id column="perm_url" jdbcType="VARCHAR" property="permUrl"/>
|
||||
<result column="module_name" jdbcType="VARCHAR" property="moduleName"/>
|
||||
<result column="perm_name" jdbcType="VARCHAR" property="permName"/>
|
||||
</resultMap>
|
||||
</mapper>
|
||||
@@ -0,0 +1,67 @@
|
||||
<?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.orange.admin.upms.dao.SysRoleMapper">
|
||||
<resultMap id="BaseResultMap" type="com.orange.admin.upms.model.SysRole">
|
||||
<id column="role_id" jdbcType="BIGINT" property="roleId"/>
|
||||
<result column="role_name" jdbcType="VARCHAR" property="roleName"/>
|
||||
<result column="create_user_id" jdbcType="BIGINT" property="createUserId"/>
|
||||
<result column="create_username" jdbcType="VARCHAR" property="createUsername"/>
|
||||
<result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
|
||||
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
|
||||
<result column="deleted_flag" jdbcType="INTEGER" property="deletedFlag"/>
|
||||
</resultMap>
|
||||
|
||||
<select id="getSysRoleList" resultMap="BaseResultMap" parameterType="com.orange.admin.upms.model.SysRole">
|
||||
SELECT * FROM zz_sys_role
|
||||
<where>
|
||||
<if test="sysRoleFilter != null">
|
||||
<if test="sysRoleFilter.searchString != null and sysRoleFilter.searchString != ''">
|
||||
<bind name= "safeSearchString" value= "'%' + sysRoleFilter.searchString + '%'"/>
|
||||
AND IFNULL(role_name,'') LIKE #{safeSearchString}
|
||||
</if>
|
||||
</if>
|
||||
AND deleted_flag = ${@com.orange.admin.common.core.constant.GlobalDeletedFlag@NORMAL}
|
||||
</where>
|
||||
<if test="orderBy != null">
|
||||
ORDER BY ${orderBy}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<select id="getSysRoleListByPermCodeId" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
DISTINCT r.*
|
||||
FROM
|
||||
my_sys_role r,
|
||||
my_sys_role_menu rm,
|
||||
my_sys_menu_perm_code mpc
|
||||
<where>
|
||||
mpc.perm_code_id = #{permCodeId}
|
||||
AND mpc.menu_id = rm.menu_id
|
||||
AND rm.role_id = r.role_id
|
||||
AND r.deleted_flag = ${@com.orange.admin.common.core.constant.GlobalDeletedFlag@NORMAL}
|
||||
</where>
|
||||
ORDER BY r.create_time
|
||||
</select>
|
||||
|
||||
<select id="getSysRoleListByPerm" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
DISTINCT r.*
|
||||
FROM
|
||||
my_sys_role r,
|
||||
my_sys_role_menu rm,
|
||||
my_sys_menu_perm_code mpc,
|
||||
my_sys_perm_code_perm pcp,
|
||||
my_sys_perm p
|
||||
<where>
|
||||
<bind name= "safeUrl" value= "'%' + url + '%'"/>
|
||||
p.url LIKE #{safeUrl}
|
||||
AND p.perm_id = pcp.perm_id
|
||||
AND pcp.perm_code_id = mpc.perm_code_id
|
||||
AND mpc.menu_id = rm.menu_id
|
||||
AND rm.role_id = r.role_id
|
||||
AND r.deleted_flag = ${@com.orange.admin.common.core.constant.GlobalDeletedFlag@NORMAL}
|
||||
AND p.deleted_flag = ${@com.orange.admin.common.core.constant.GlobalDeletedFlag@NORMAL}
|
||||
</where>
|
||||
ORDER BY r.create_time
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,8 @@
|
||||
<?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.orange.admin.upms.dao.SysRoleMenuMapper">
|
||||
<resultMap id="BaseResultMap" type="com.orange.admin.upms.model.SysRoleMenu">
|
||||
<id column="role_id" jdbcType="BIGINT" property="roleId"/>
|
||||
<id column="menu_id" jdbcType="BIGINT" property="menuId"/>
|
||||
</resultMap>
|
||||
</mapper>
|
||||
@@ -0,0 +1,111 @@
|
||||
<?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.orange.admin.upms.dao.SysUserMapper">
|
||||
<resultMap id="BaseResultMap" type="com.orange.admin.upms.model.SysUser">
|
||||
<id column="user_id" jdbcType="BIGINT" property="userId"/>
|
||||
<result column="login_name" jdbcType="VARCHAR" property="loginName"/>
|
||||
<result column="password" jdbcType="VARCHAR" property="password"/>
|
||||
<result column="show_name" jdbcType="VARCHAR" property="showName"/>
|
||||
<result column="dept_id" jdbcType="BIGINT" property="deptId"/>
|
||||
<result column="user_type" jdbcType="INTEGER" property="userType"/>
|
||||
<result column="head_image_url" jdbcType="VARCHAR" property="headImageUrl"/>
|
||||
<result column="user_status" jdbcType="INTEGER" property="userStatus"/>
|
||||
<result column="deleted_flag" jdbcType="INTEGER" property="deletedFlag"/>
|
||||
<result column="create_user_id" jdbcType="BIGINT" property="createUserId"/>
|
||||
<result column="create_username" jdbcType="VARCHAR" property="createUsername"/>
|
||||
<result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
|
||||
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="filterRef">
|
||||
<if test="sysUserFilter != null">
|
||||
<if test="sysUserFilter.loginName != null and sysUserFilter.loginName != ''">
|
||||
<bind name = "safeLoginName" value = "'%' + sysUserFilter.loginName + '%'" />
|
||||
AND zz_sys_user.login_name LIKE #{safeLoginName}
|
||||
</if>
|
||||
<if test="sysUserFilter.showName != null and sysUserFilter.showName != ''">
|
||||
<bind name = "safeShowName" value = "'%' + sysUserFilter.showName + '%'" />
|
||||
AND zz_sys_user.show_name LIKE #{safeShowName}
|
||||
</if>
|
||||
<if test="sysUserFilter.deptId != null">
|
||||
AND zz_sys_user.dept_id = #{sysUserFilter.deptId}
|
||||
</if>
|
||||
<if test="sysUserFilter.userStatus != null">
|
||||
AND zz_sys_user.user_status = #{sysUserFilter.userStatus}
|
||||
</if>
|
||||
<if test="sysUserFilter.createTimeStart != null and sysUserFilter.createTimeStart != ''">
|
||||
AND zz_sys_user.create_time >= #{sysUserFilter.createTimeStart}
|
||||
</if>
|
||||
<if test="sysUserFilter.createTimeEnd != null and sysUserFilter.createTimeEnd != ''">
|
||||
AND zz_sys_user.create_time <= #{sysUserFilter.createTimeEnd}
|
||||
</if>
|
||||
</if>
|
||||
AND zz_sys_user.deleted_flag = ${@com.orange.admin.common.core.constant.GlobalDeletedFlag@NORMAL}
|
||||
</sql>
|
||||
|
||||
<select id="getSysUserList" resultMap="BaseResultMap" parameterType="com.orange.admin.upms.model.SysUser">
|
||||
SELECT * FROM zz_sys_user
|
||||
<where>
|
||||
<include refid="filterRef"/>
|
||||
</where>
|
||||
<if test="orderBy != null">
|
||||
ORDER BY ${orderBy}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<select id="getSysUserListByRoleId" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
zz_sys_user.*
|
||||
FROM
|
||||
zz_sys_user_role,
|
||||
zz_sys_user
|
||||
<where>
|
||||
AND zz_sys_user_role.role_id = #{roleId}
|
||||
AND zz_sys_user_role.user_id = zz_sys_user.user_id
|
||||
<include refid="filterRef"/>
|
||||
</where>
|
||||
<if test="orderBy != null">
|
||||
ORDER BY ${orderBy}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<select id="getNotInSysUserListByRoleId" resultMap="BaseResultMap">
|
||||
SELECT * FROM zz_sys_user
|
||||
<where>
|
||||
NOT EXISTS (SELECT * FROM zz_sys_user_role
|
||||
WHERE zz_sys_user_role.role_id = #{roleId} AND zz_sys_user_role.user_id = zz_sys_user.user_id)
|
||||
<include refid="filterRef"/>
|
||||
</where>
|
||||
<if test="orderBy != null">
|
||||
ORDER BY ${orderBy}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<select id="getSysUserListByDataPermId" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
zz_sys_user.*
|
||||
FROM
|
||||
zz_sys_data_perm_user,
|
||||
zz_sys_user
|
||||
<where>
|
||||
AND zz_sys_data_perm_user.data_perm_id = #{dataPermId}
|
||||
AND zz_sys_data_perm_user.user_id = zz_sys_user.user_id
|
||||
<include refid="filterRef"/>
|
||||
</where>
|
||||
<if test="orderBy != null">
|
||||
ORDER BY ${orderBy}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<select id="getNotInSysUserListByDataPermId" resultMap="BaseResultMap">
|
||||
SELECT * FROM zz_sys_user
|
||||
<where>
|
||||
NOT EXISTS (SELECT * FROM zz_sys_data_perm_user
|
||||
WHERE zz_sys_data_perm_user.data_perm_id = #{dataPermId} AND zz_sys_data_perm_user.user_id = zz_sys_user.user_id)
|
||||
<include refid="filterRef"/>
|
||||
</where>
|
||||
<if test="orderBy != null">
|
||||
ORDER BY ${orderBy}
|
||||
</if>
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,19 @@
|
||||
<?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.orange.admin.upms.dao.SysUserRoleMapper">
|
||||
<resultMap id="BaseResultMap" type="com.orange.admin.upms.model.SysUserRole">
|
||||
<id column="user_id" jdbcType="BIGINT" property="userId"/>
|
||||
<id column="role_id" jdbcType="BIGINT" property="roleId"/>
|
||||
</resultMap>
|
||||
|
||||
<select id="getRoleIdListByUserId" resultType="java.lang.Long">
|
||||
SELECT role_id FROM zz_sys_user_role WHERE user_id = #{userId}
|
||||
</select>
|
||||
|
||||
<insert id="addUserRoleList">
|
||||
REPLACE INTO zz_sys_user_role(user_id, role_id) VALUES
|
||||
<foreach collection="list" index="index" item="item" separator=",">
|
||||
(#{item.userId}, #{item.roleId})
|
||||
</foreach>
|
||||
</insert>
|
||||
</mapper>
|
||||
@@ -0,0 +1,89 @@
|
||||
package com.orange.admin.upms.model;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.orange.admin.common.core.annotation.DeletedFlagColumn;
|
||||
import com.orange.admin.common.core.validator.ConstDictRef;
|
||||
import com.orange.admin.common.core.validator.UpdateGroup;
|
||||
import com.orange.admin.common.core.constant.DataPermRuleType;
|
||||
import com.orange.admin.common.core.annotation.JobUpdateTimeColumn;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.*;
|
||||
import java.util.*;
|
||||
|
||||
@Data
|
||||
@Table(name = "zz_sys_data_perm")
|
||||
public class SysDataPerm {
|
||||
|
||||
/**
|
||||
* 主键Id。
|
||||
*/
|
||||
@NotNull(message = "数据权限Id不能为空!", groups = {UpdateGroup.class})
|
||||
@Id
|
||||
@Column(name = "data_perm_id")
|
||||
private Long dataPermId;
|
||||
|
||||
/**
|
||||
* 显示名称。
|
||||
*/
|
||||
@NotBlank(message = "数据权限名称不能为空!")
|
||||
@Column(name = "data_perm_name")
|
||||
private String dataPermName;
|
||||
|
||||
/**
|
||||
* 数据权限规则类型(0: 全部可见 1: 只看自己 2: 只看本部门 3: 本部门及子部门 4: 多部门及子部门 5: 自定义部门列表)。
|
||||
*/
|
||||
@NotNull(message = "数据权限规则类型不能为空!")
|
||||
@ConstDictRef(constDictClass = DataPermRuleType.class)
|
||||
@Column(name = "rule_type")
|
||||
private Integer ruleType;
|
||||
|
||||
/**
|
||||
* 创建者。
|
||||
*/
|
||||
@Column(name = "create_user_id")
|
||||
private Long createUserId;
|
||||
|
||||
/**
|
||||
* 创建者显示名称。
|
||||
*/
|
||||
@Column(name = "create_username")
|
||||
private String createUsername;
|
||||
|
||||
/**
|
||||
* 创建时间。
|
||||
*/
|
||||
@Column(name = "create_time")
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 更新时间。
|
||||
*/
|
||||
@JobUpdateTimeColumn
|
||||
@Column(name = "update_time")
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* 逻辑删除标记字段(1: 正常 -1: 已删除)。
|
||||
*/
|
||||
@JSONField(serialize = false)
|
||||
@DeletedFlagColumn
|
||||
@Column(name = "deleted_flag")
|
||||
private Integer deletedFlag;
|
||||
|
||||
@Transient
|
||||
private List<SysDataPermDept> dataPermDeptList;
|
||||
|
||||
@Transient
|
||||
private List<SysDataPermMenu> dataPermMenuList;
|
||||
|
||||
@Transient
|
||||
private String createTimeStart;
|
||||
|
||||
@Transient
|
||||
private String createTimeEnd;
|
||||
|
||||
@Transient
|
||||
private String searchString;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.orange.admin.upms.model;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Data
|
||||
@ToString(of = {"deptId"})
|
||||
@Table(name = "zz_sys_data_perm_dept")
|
||||
public class SysDataPermDept {
|
||||
|
||||
/**
|
||||
* 数据权限Id。
|
||||
*/
|
||||
@Id
|
||||
@Column(name = "data_perm_id")
|
||||
private Long dataPermId;
|
||||
|
||||
/**
|
||||
* 关联部门Id。
|
||||
*/
|
||||
@Id
|
||||
@Column(name = "dept_id")
|
||||
private Long deptId;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.orange.admin.upms.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
@Data
|
||||
@Table(name = "zz_sys_data_perm_menu")
|
||||
public class SysDataPermMenu {
|
||||
|
||||
/**
|
||||
* 数据权限Id。
|
||||
*/
|
||||
@Id
|
||||
@Column(name = "data_perm_id")
|
||||
private Long dataPermId;
|
||||
|
||||
/**
|
||||
* 关联菜单Id。
|
||||
*/
|
||||
@Id
|
||||
@Column(name = "menu_id")
|
||||
private Long menuId;
|
||||
|
||||
@Transient
|
||||
private Integer ruleType;
|
||||
|
||||
@Transient
|
||||
private String deptIdListString;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.orange.admin.upms.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
@Data
|
||||
@Table(name = "zz_sys_data_perm_user")
|
||||
public class SysDataPermUser {
|
||||
|
||||
/**
|
||||
* 数据权限Id。
|
||||
*/
|
||||
@Id
|
||||
@Column(name = "data_perm_id")
|
||||
private Long dataPermId;
|
||||
|
||||
/**
|
||||
* 用户Id。
|
||||
*/
|
||||
@Id
|
||||
@Column(name = "user_id")
|
||||
private Long userId;
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package com.orange.admin.upms.model;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.orange.admin.common.core.annotation.DeletedFlagColumn;
|
||||
import com.orange.admin.common.core.annotation.JobUpdateTimeColumn;
|
||||
import com.orange.admin.common.core.validator.UpdateGroup;
|
||||
import lombok.Data;
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
@Table(name = "zz_sys_dept")
|
||||
public class SysDept {
|
||||
|
||||
/**
|
||||
* 部门Id。
|
||||
*/
|
||||
@NotNull(message = "数据验证失败,部门Id不能为空!", groups = {UpdateGroup.class})
|
||||
@Id
|
||||
@Column(name = "dept_id")
|
||||
private Long deptId;
|
||||
|
||||
/**
|
||||
* 部门名称。
|
||||
*/
|
||||
@NotBlank(message = "数据验证失败,部门名称不能为空!")
|
||||
@Column(name = "dept_name")
|
||||
private String deptName;
|
||||
|
||||
/**
|
||||
* 显示顺序。
|
||||
*/
|
||||
@NotNull(message = "数据验证失败,显示顺序不能为空!")
|
||||
@Column(name = "show_order")
|
||||
private Integer showOrder;
|
||||
|
||||
/**
|
||||
* 逻辑删除标记字段(1: 正常 -1: 已删除)。
|
||||
*/
|
||||
@JSONField(serialize = false)
|
||||
@DeletedFlagColumn
|
||||
@Column(name = "deleted_flag")
|
||||
private Integer deletedFlag;
|
||||
|
||||
/**
|
||||
* 创建用户Id。
|
||||
*/
|
||||
@Column(name = "create_user_id")
|
||||
private Long createUserId;
|
||||
|
||||
/**
|
||||
* 创建用户名。
|
||||
*/
|
||||
@Column(name = "create_username")
|
||||
private String createUsername;
|
||||
|
||||
/**
|
||||
* 创建时间。
|
||||
*/
|
||||
@Column(name = "create_time")
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 更新时间。
|
||||
*/
|
||||
@JobUpdateTimeColumn
|
||||
@Column(name = "update_time")
|
||||
private Date updateTime;
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package com.orange.admin.upms.model;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.orange.admin.common.core.annotation.DeletedFlagColumn;
|
||||
import com.orange.admin.common.core.validator.ConstDictRef;
|
||||
import com.orange.admin.common.core.validator.UpdateGroup;
|
||||
import com.orange.admin.upms.model.constant.SysMenuType;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.*;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@Table(name = "zz_sys_menu")
|
||||
public class SysMenu {
|
||||
|
||||
/**
|
||||
* 主键Id。
|
||||
*/
|
||||
@NotNull(message = "菜单Id不能为空!", groups = {UpdateGroup.class})
|
||||
@Id
|
||||
@Column(name = "menu_id")
|
||||
private Long menuId;
|
||||
|
||||
/**
|
||||
* 父菜单Id,目录菜单的父菜单为null。
|
||||
*/
|
||||
@Column(name = "parent_id")
|
||||
private Long parentId;
|
||||
|
||||
/**
|
||||
* 菜单显示名称。
|
||||
*/
|
||||
@NotBlank(message = "菜单显示名称不能为空!")
|
||||
@Column(name = "menu_name")
|
||||
private String menuName;
|
||||
|
||||
/**
|
||||
* 菜单类型(0: 目录 1: 菜单 2: 按钮 3: UI片段)。
|
||||
*/
|
||||
@NotNull(message = "菜单类型不能为空!")
|
||||
@ConstDictRef(constDictClass = SysMenuType.class, message = "数据验证失败,菜单类型为无效值!")
|
||||
@Column(name = "menu_type")
|
||||
private Integer menuType;
|
||||
|
||||
/**
|
||||
* 前端表单路由名称,仅用于menu_type为1的菜单类型。
|
||||
*/
|
||||
@Column(name = "form_router_name")
|
||||
private String formRouterName;
|
||||
|
||||
/**
|
||||
* 菜单显示顺序 (值越小,排序越靠前)。
|
||||
*/
|
||||
@NotNull(message = "菜单显示顺序不能为空!")
|
||||
@Column(name = "show_order")
|
||||
private Integer showOrder;
|
||||
|
||||
/**
|
||||
* 菜单图标。
|
||||
*/
|
||||
private String icon;
|
||||
|
||||
/**
|
||||
* 创建时间。
|
||||
*/
|
||||
@Column(name = "create_time")
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 逻辑删除标记字段(1: 正常 -1: 已删除)。
|
||||
*/
|
||||
@JSONField(serialize = false)
|
||||
@DeletedFlagColumn
|
||||
@Column(name = "deleted_flag")
|
||||
private Integer deletedFlag;
|
||||
|
||||
@Transient
|
||||
private List<Long> permCodeIdList;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.orange.admin.upms.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
@Data
|
||||
@Table(name = "zz_sys_menu_perm_code")
|
||||
public class SysMenuPermCode {
|
||||
|
||||
/**
|
||||
* 关联菜单Id。
|
||||
*/
|
||||
@Id
|
||||
@Column(name = "menu_id")
|
||||
private Long menuId;
|
||||
|
||||
/**
|
||||
* 关联权限字Id。
|
||||
*/
|
||||
@Id
|
||||
@Column(name = "perm_code_id")
|
||||
private Long permCodeId;
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package com.orange.admin.upms.model;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.orange.admin.common.core.annotation.DeletedFlagColumn;
|
||||
import com.orange.admin.common.core.annotation.RelationDict;
|
||||
import com.orange.admin.common.core.validator.UpdateGroup;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.*;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
@Data
|
||||
@Table(name = "zz_sys_perm")
|
||||
public class SysPerm {
|
||||
|
||||
/**
|
||||
* 权限Id。
|
||||
*/
|
||||
@NotNull(message = "权限Id不能为空!", groups = {UpdateGroup.class})
|
||||
@Id
|
||||
@Column(name = "perm_id")
|
||||
private Long permId;
|
||||
|
||||
/**
|
||||
* 权限所在的权限模块Id。
|
||||
*/
|
||||
@NotNull(message = "权限模块Id不能为空!")
|
||||
@Column(name = "module_id")
|
||||
private Long moduleId;
|
||||
|
||||
/**
|
||||
* 权限名称。
|
||||
*/
|
||||
@NotBlank(message = "权限名称不能为空!")
|
||||
@Column(name = "perm_name")
|
||||
private String permName;
|
||||
|
||||
/**
|
||||
* 关联的URL。
|
||||
*/
|
||||
@NotBlank(message = "权限关联的url不能为空!")
|
||||
private String url;
|
||||
|
||||
/**
|
||||
* 权限在当前模块下的顺序,由小到大。
|
||||
*/
|
||||
@NotNull(message = "权限显示顺序不能为空!")
|
||||
@Column(name = "show_order")
|
||||
private Integer showOrder;
|
||||
|
||||
/**
|
||||
* 创建时间。
|
||||
*/
|
||||
@Column(name = "create_time")
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 逻辑删除标记字段(1: 正常 -1: 已删除)。
|
||||
*/
|
||||
@JSONField(serialize = false)
|
||||
@DeletedFlagColumn
|
||||
@Column(name = "deleted_flag")
|
||||
private Integer deletedFlag;
|
||||
|
||||
@RelationDict(
|
||||
masterIdField = "moduleId",
|
||||
slaveServiceName = "SysPermModuleService",
|
||||
slaveModelClass = SysPermModule.class,
|
||||
slaveIdField = "moduleId",
|
||||
slaveNameField = "moduleName")
|
||||
@Transient
|
||||
private Map<String, Object> moduleIdDictMap;
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package com.orange.admin.upms.model;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.orange.admin.common.core.annotation.DeletedFlagColumn;
|
||||
import com.orange.admin.common.core.validator.ConstDictRef;
|
||||
import com.orange.admin.common.core.validator.UpdateGroup;
|
||||
import com.orange.admin.upms.model.constant.SysPermCodeType;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.*;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@Table(name = "zz_sys_perm_code")
|
||||
public class SysPermCode {
|
||||
|
||||
/**
|
||||
* 主键Id。
|
||||
*/
|
||||
@NotNull(message = "权限字Id不能为空!", groups = {UpdateGroup.class})
|
||||
@Id
|
||||
@Column(name = "perm_code_id")
|
||||
private Long permCodeId;
|
||||
|
||||
/**
|
||||
* 上级权限字Id。
|
||||
*/
|
||||
@Column(name = "parent_id")
|
||||
private Long parentId;
|
||||
|
||||
/**
|
||||
* 权限字标识(一般为有含义的英文字符串)。
|
||||
*/
|
||||
@NotBlank(message = "权限字编码不能为空!")
|
||||
@Column(name = "perm_code")
|
||||
private String permCode;
|
||||
|
||||
/**
|
||||
* 权限类型(0: 表单 1: UI片段 2: 操作)。
|
||||
*/
|
||||
@NotNull(message = "权限字类型不能为空!")
|
||||
@ConstDictRef(constDictClass = SysPermCodeType.class, message = "数据验证失败,权限类型为无效值!")
|
||||
@Column(name = "perm_code_type")
|
||||
private Integer permCodeType;
|
||||
|
||||
/**
|
||||
* 显示名称。
|
||||
*/
|
||||
@NotBlank(message = "权限字显示名称不能为空!")
|
||||
@Column(name = "show_name")
|
||||
private String showName;
|
||||
|
||||
/**
|
||||
* 显示顺序(数值越小,越靠前)。
|
||||
*/
|
||||
@NotNull(message = "权限字显示顺序不能为空!")
|
||||
@Column(name = "show_order")
|
||||
private Integer showOrder;
|
||||
|
||||
/**
|
||||
* 创建时间。
|
||||
*/
|
||||
@Column(name = "create_time")
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 逻辑删除标记字段(1: 正常 -1: 已删除)。
|
||||
*/
|
||||
@JSONField(serialize = false)
|
||||
@DeletedFlagColumn
|
||||
@Column(name = "deleted_flag")
|
||||
private Integer deletedFlag;
|
||||
|
||||
@Transient
|
||||
private List<Long> permIdList;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.orange.admin.upms.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
@Data
|
||||
@Table(name = "zz_sys_perm_code_perm")
|
||||
public class SysPermCodePerm {
|
||||
|
||||
/**
|
||||
* 权限字Id。
|
||||
*/
|
||||
@Id
|
||||
@Column(name = "perm_code_id")
|
||||
private Long permCodeId;
|
||||
|
||||
/**
|
||||
* 权限Id。
|
||||
*/
|
||||
@Id
|
||||
@Column(name = "perm_id")
|
||||
private Long permId;
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package com.orange.admin.upms.model;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.orange.admin.common.core.annotation.DeletedFlagColumn;
|
||||
import com.orange.admin.common.core.validator.ConstDictRef;
|
||||
import com.orange.admin.common.core.validator.UpdateGroup;
|
||||
import com.orange.admin.upms.model.constant.SysPermModuleType;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.*;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@Table(name = "zz_sys_perm_module")
|
||||
public class SysPermModule {
|
||||
|
||||
/**
|
||||
* 权限模块Id。
|
||||
*/
|
||||
@NotNull(message = "权限模块Id不能为空!", groups = {UpdateGroup.class})
|
||||
@Id
|
||||
@Column(name = "module_id")
|
||||
private Long moduleId;
|
||||
|
||||
/**
|
||||
* 上级权限模块Id。
|
||||
*/
|
||||
@Column(name = "parent_id")
|
||||
private Long parentId;
|
||||
|
||||
/**
|
||||
* 权限模块名称。
|
||||
*/
|
||||
@NotBlank(message = "权限模块名称不能为空!")
|
||||
@Column(name = "module_name")
|
||||
private String moduleName;
|
||||
|
||||
/**
|
||||
* 权限模块类型(0: 普通模块 1: Controller模块)。
|
||||
*/
|
||||
@NotNull(message = "模块类型不能为空!")
|
||||
@ConstDictRef(constDictClass = SysPermModuleType.class, message = "数据验证失败,权限模块类型为无效值!")
|
||||
@Column(name = "module_type")
|
||||
private Integer moduleType;
|
||||
|
||||
/**
|
||||
* 权限模块在当前层级下的顺序,由小到大。
|
||||
*/
|
||||
@NotNull(message = "权限模块显示顺序不能为空!")
|
||||
@Column(name = "show_order")
|
||||
private Integer showOrder;
|
||||
|
||||
/**
|
||||
* 创建时间。
|
||||
*/
|
||||
@Column(name = "create_time")
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 逻辑删除标记字段(1: 正常 -1: 已删除)。
|
||||
*/
|
||||
@JSONField(serialize = false)
|
||||
@DeletedFlagColumn
|
||||
@Column(name = "deleted_flag")
|
||||
private Integer deletedFlag;
|
||||
|
||||
@Transient
|
||||
private List<SysPerm> sysPermList;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.orange.admin.upms.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
@Data
|
||||
@Table(name = "zz_sys_perm_whitelist")
|
||||
public class SysPermWhitelist {
|
||||
|
||||
/**
|
||||
* 权限资源的URL。
|
||||
*/
|
||||
@Id
|
||||
@Column(name = "perm_url")
|
||||
private String permUrl;
|
||||
|
||||
/**
|
||||
* 权限资源所属模块名字(通常是Controller的名字)。
|
||||
*/
|
||||
@Column(name = "module_name")
|
||||
private String moduleName;
|
||||
|
||||
/**
|
||||
* 权限的名称。
|
||||
*/
|
||||
@Column(name = "perm_name")
|
||||
private String permName;
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package com.orange.admin.upms.model;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.orange.admin.common.core.annotation.DeletedFlagColumn;
|
||||
import com.orange.admin.common.core.validator.UpdateGroup;
|
||||
import com.orange.admin.common.core.annotation.JobUpdateTimeColumn;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.*;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@Table(name = "zz_sys_role")
|
||||
public class SysRole {
|
||||
|
||||
/**
|
||||
* 主键Id。
|
||||
*/
|
||||
@NotNull(message = "角色Id不能为空!", groups = {UpdateGroup.class})
|
||||
@Id
|
||||
@Column(name = "role_id")
|
||||
private Long roleId;
|
||||
|
||||
/**
|
||||
* 角色名称。
|
||||
*/
|
||||
@NotBlank(message = "角色名称不能为空!")
|
||||
@Column(name = "role_name")
|
||||
private String roleName;
|
||||
|
||||
/**
|
||||
* 创建者。
|
||||
*/
|
||||
@Column(name = "create_user_id")
|
||||
private Long createUserId;
|
||||
|
||||
/**
|
||||
* 创建者显示名称。
|
||||
*/
|
||||
@Column(name = "create_username")
|
||||
private String createUsername;
|
||||
|
||||
/**
|
||||
* 创建时间。
|
||||
*/
|
||||
@Column(name = "create_time")
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 更新时间。
|
||||
*/
|
||||
@JobUpdateTimeColumn
|
||||
@Column(name = "update_time")
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* 逻辑删除标记字段(1: 正常 -1: 已删除)。
|
||||
*/
|
||||
@JSONField(serialize = false)
|
||||
@DeletedFlagColumn
|
||||
@Column(name = "deleted_flag")
|
||||
private Integer deletedFlag;
|
||||
|
||||
@Transient
|
||||
private List<Long> menuIdList;
|
||||
|
||||
@Transient
|
||||
private String createTimeStart;
|
||||
|
||||
@Transient
|
||||
private String createTimeEnd;
|
||||
|
||||
@Transient
|
||||
private String searchString;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.orange.admin.upms.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
@Data
|
||||
@Table(name = "zz_sys_role_menu")
|
||||
public class SysRoleMenu {
|
||||
|
||||
/**
|
||||
* 角色Id。
|
||||
*/
|
||||
@Id
|
||||
@Column(name = "role_id")
|
||||
private Long roleId;
|
||||
|
||||
/**
|
||||
* 菜单Id。
|
||||
*/
|
||||
@Id
|
||||
@Column(name = "menu_id")
|
||||
private Long menuId;
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
package com.orange.admin.upms.model;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.orange.admin.upms.model.constant.SysUserType;
|
||||
import com.orange.admin.upms.model.constant.SysUserStatus;
|
||||
import com.orange.admin.common.core.annotation.RelationConstDict;
|
||||
import com.orange.admin.common.core.annotation.DeletedFlagColumn;
|
||||
import com.orange.admin.common.core.annotation.JobUpdateTimeColumn;
|
||||
import com.orange.admin.common.core.validator.UpdateGroup;
|
||||
import com.orange.admin.common.core.validator.ConstDictRef;
|
||||
import lombok.Data;
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@Table(name = "zz_sys_user")
|
||||
public class SysUser {
|
||||
|
||||
/**
|
||||
* 用户Id。
|
||||
*/
|
||||
@NotNull(message = "数据验证失败,用户Id不能为空!", groups = {UpdateGroup.class})
|
||||
@Id
|
||||
@Column(name = "user_id")
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 登录用户名。
|
||||
*/
|
||||
@NotBlank(message = "数据验证失败,登录用户名不能为空!")
|
||||
@Column(name = "login_name")
|
||||
private String loginName;
|
||||
|
||||
/**
|
||||
* 用户密码。
|
||||
*/
|
||||
@NotBlank(message = "数据验证失败,用户密码不能为空!")
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 用户显示名称。
|
||||
*/
|
||||
@NotBlank(message = "数据验证失败,用户显示名称不能为空!")
|
||||
@Column(name = "show_name")
|
||||
private String showName;
|
||||
|
||||
/**
|
||||
* 用户部门Id。
|
||||
*/
|
||||
@NotNull(message = "数据验证失败,用户部门Id不能为空!")
|
||||
@Column(name = "dept_id")
|
||||
private Long deptId;
|
||||
|
||||
/**
|
||||
* 用户类型(0: 管理员 1: 系统管理用户 2: 系统业务用户)。
|
||||
*/
|
||||
@NotNull(message = "数据验证失败,用户类型(0: 管理员 1: 系统管理用户 2: 系统业务用户)不能为空!")
|
||||
@ConstDictRef(constDictClass = SysUserType.class, message = "数据验证失败,用户类型(0: 管理员 1: 系统管理用户 2: 系统业务用户)为无效值!")
|
||||
@Column(name = "user_type")
|
||||
private Integer userType;
|
||||
|
||||
/**
|
||||
* 用户头像的Url。
|
||||
*/
|
||||
@Column(name = "head_image_url")
|
||||
private String headImageUrl;
|
||||
|
||||
/**
|
||||
* 用户状态(0: 正常 1: 锁定)。
|
||||
*/
|
||||
@NotNull(message = "数据验证失败,用户状态(0: 正常 1: 锁定)不能为空!")
|
||||
@ConstDictRef(constDictClass = SysUserStatus.class, message = "数据验证失败,用户状态(0: 正常 1: 锁定)为无效值!")
|
||||
@Column(name = "user_status")
|
||||
private Integer userStatus;
|
||||
|
||||
/**
|
||||
* 逻辑删除标记字段(1: 正常 -1: 已删除)。
|
||||
*/
|
||||
@JSONField(serialize = false)
|
||||
@DeletedFlagColumn
|
||||
@Column(name = "deleted_flag")
|
||||
private Integer deletedFlag;
|
||||
|
||||
/**
|
||||
* 创建用户Id。
|
||||
*/
|
||||
@Column(name = "create_user_id")
|
||||
private Long createUserId;
|
||||
|
||||
/**
|
||||
* 创建用户名。
|
||||
*/
|
||||
@Column(name = "create_username")
|
||||
private String createUsername;
|
||||
|
||||
/**
|
||||
* 创建时间。
|
||||
*/
|
||||
@Column(name = "create_time")
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 更新时间。
|
||||
*/
|
||||
@JobUpdateTimeColumn
|
||||
@Column(name = "update_time")
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* createTime 范围过滤起始值(>=)。
|
||||
*/
|
||||
@Transient
|
||||
private String createTimeStart;
|
||||
|
||||
/**
|
||||
* createTime 范围过滤结束值(<=)。
|
||||
*/
|
||||
@Transient
|
||||
private String createTimeEnd;
|
||||
|
||||
/**
|
||||
* 与当前用户关联的角色Id集合。
|
||||
*/
|
||||
@Transient
|
||||
private List<Long> roleIdList;
|
||||
|
||||
/**
|
||||
* 与当前用户关联的数据权限Id集合。
|
||||
*/
|
||||
@Transient
|
||||
private List<Long> dataPermIdList;
|
||||
|
||||
@RelationConstDict(
|
||||
masterIdField = "userType",
|
||||
constantDictClass = SysUserType.class)
|
||||
@Transient
|
||||
private Map<String, Object> userTypeDictMap;
|
||||
|
||||
@RelationConstDict(
|
||||
masterIdField = "userStatus",
|
||||
constantDictClass = SysUserStatus.class)
|
||||
@Transient
|
||||
private Map<String, Object> userStatusDictMap;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.orange.admin.upms.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
@Data
|
||||
@Table(name = "zz_sys_user_role")
|
||||
public class SysUserRole {
|
||||
|
||||
/**
|
||||
* 用户Id。
|
||||
*/
|
||||
@Id
|
||||
@Column(name = "user_id")
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 角色Id。
|
||||
*/
|
||||
@Id
|
||||
@Column(name = "role_id")
|
||||
private Long roleId;
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.orange.admin.upms.model.constant;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 菜单类型常量对象。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
*/
|
||||
public final class SysMenuType {
|
||||
|
||||
/**
|
||||
* 目录菜单。
|
||||
*/
|
||||
public static final int TYPE_DIRECTORY = 0;
|
||||
/**
|
||||
* 普通菜单。
|
||||
*/
|
||||
public static final int TYPE_MENU = 1;
|
||||
/**
|
||||
* 表单片段类型。
|
||||
*/
|
||||
public static final int TYPE_UI_FRAGMENT = 2;
|
||||
/**
|
||||
* 按钮类型。
|
||||
*/
|
||||
public static final int TYPE_BUTTON = 3;
|
||||
|
||||
public static final Map<Object, String> DICT_MAP = new HashMap<>(4);
|
||||
static {
|
||||
DICT_MAP.put(0, "目录菜单");
|
||||
DICT_MAP.put(1, "普通菜单");
|
||||
DICT_MAP.put(2, "表单片段类型");
|
||||
DICT_MAP.put(3, "按钮类型");
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断参数是否为当前常量字典的合法值。
|
||||
*
|
||||
* @param value 待验证的参数值。
|
||||
* @return 合法返回true,否则false。
|
||||
*/
|
||||
public static boolean isValid(int value) {
|
||||
return DICT_MAP.containsKey(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 私有构造函数,明确标识该常量类的作用。
|
||||
*/
|
||||
private SysMenuType() {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.orange.admin.upms.model.constant;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 权限字类型常量对象。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
*/
|
||||
public final class SysPermCodeType {
|
||||
|
||||
/**
|
||||
* 表单权限字。
|
||||
*/
|
||||
public static final int TYPE_FORM = 0;
|
||||
/**
|
||||
* 表单片段布局权限字。
|
||||
*/
|
||||
public static final int TYPE_FRAGMENT = 1;
|
||||
/**
|
||||
* 操作权限字。
|
||||
*/
|
||||
public static final int TYPE_OPERATION = 2;
|
||||
|
||||
public static final Map<Object, String> DICT_MAP = new HashMap<>(3);
|
||||
static {
|
||||
DICT_MAP.put(0, "表单权限字");
|
||||
DICT_MAP.put(1, "表单片段布局权限字");
|
||||
DICT_MAP.put(2, "操作权限字");
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断参数是否为当前常量字典的合法值。
|
||||
*
|
||||
* @param value 待验证的参数值。
|
||||
* @return 合法返回true,否则false。
|
||||
*/
|
||||
public static boolean isValid(int value) {
|
||||
return DICT_MAP.containsKey(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 私有构造函数,明确标识该常量类的作用。
|
||||
*/
|
||||
private SysPermCodeType() {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.orange.admin.upms.model.constant;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 权限资源模块类型常量对象。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
*/
|
||||
public final class SysPermModuleType {
|
||||
|
||||
/**
|
||||
* 普通模块。
|
||||
*/
|
||||
public static final int TYPE_NORMAL = 0;
|
||||
/**
|
||||
* controller接口模块。
|
||||
*/
|
||||
public static final int TYPE_CONTROLLER = 1;
|
||||
|
||||
public static final Map<Object, String> DICT_MAP = new HashMap<>(2);
|
||||
static {
|
||||
DICT_MAP.put(0, "普通模块");
|
||||
DICT_MAP.put(1, "controller接口模块");
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断参数是否为当前常量字典的合法值。
|
||||
*
|
||||
* @param value 待验证的参数值。
|
||||
* @return 合法返回true,否则false。
|
||||
*/
|
||||
public static boolean isValid(int value) {
|
||||
return DICT_MAP.containsKey(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 私有构造函数,明确标识该常量类的作用。
|
||||
*/
|
||||
private SysPermModuleType() {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.orange.admin.upms.model.constant;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public final class SysUserStatus {
|
||||
|
||||
/**
|
||||
* 正常状态。
|
||||
*/
|
||||
public static final int STATUS_NORMAL = 0;
|
||||
/**
|
||||
* 锁定状态。
|
||||
*/
|
||||
public static final int STATUS_LOCKED = 1;
|
||||
|
||||
public static final Map<Object, String> DICT_MAP = new HashMap<>(2);
|
||||
static {
|
||||
DICT_MAP.put(STATUS_NORMAL, "正常状态");
|
||||
DICT_MAP.put(STATUS_LOCKED, "锁定状态");
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断参数是否为当前常量字典的合法值。
|
||||
*
|
||||
* @param value 待验证的参数值。
|
||||
* @return 合法返回true,否则false。
|
||||
*/
|
||||
public static boolean isValid(int value) {
|
||||
return DICT_MAP.containsKey(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 私有构造函数,明确标识该常量类的作用。
|
||||
*/
|
||||
private SysUserStatus() {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.orange.admin.upms.model.constant;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public final class SysUserType {
|
||||
|
||||
/**
|
||||
* 管理员。
|
||||
*/
|
||||
public static final int TYPE_ADMIN = 0;
|
||||
/**
|
||||
* 系统操作员。
|
||||
*/
|
||||
public static final int TYPE_SYSTEM = 1;
|
||||
/**
|
||||
* 普通操作员。
|
||||
*/
|
||||
public static final int TYPE_OPERATOR = 2;
|
||||
|
||||
public static final Map<Object, String> DICT_MAP = new HashMap<>(3);
|
||||
static {
|
||||
DICT_MAP.put(TYPE_ADMIN, "管理员");
|
||||
DICT_MAP.put(TYPE_SYSTEM, "系统操作员");
|
||||
DICT_MAP.put(TYPE_OPERATOR, "普通操作员");
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断参数是否为当前常量字典的合法值。
|
||||
*
|
||||
* @param value 待验证的参数值。
|
||||
* @return 合法返回true,否则false。
|
||||
*/
|
||||
public static boolean isValid(int value) {
|
||||
return DICT_MAP.containsKey(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 私有构造函数,明确标识该常量类的作用。
|
||||
*/
|
||||
private SysUserType() {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,366 @@
|
||||
package com.orange.admin.upms.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.orange.admin.common.biz.util.BasicIdGenerator;
|
||||
import com.orange.admin.common.core.constant.DataPermRuleType;
|
||||
import com.orange.admin.common.core.base.dao.BaseDaoMapper;
|
||||
import com.orange.admin.common.core.base.service.BaseService;
|
||||
import com.orange.admin.common.core.constant.GlobalDeletedFlag;
|
||||
import com.orange.admin.common.core.object.TokenData;
|
||||
import com.orange.admin.common.core.object.VerifyResult;
|
||||
import com.orange.admin.upms.dao.SysDataPermDeptMapper;
|
||||
import com.orange.admin.upms.dao.SysDataPermMapper;
|
||||
import com.orange.admin.upms.dao.SysDataPermUserMapper;
|
||||
import com.orange.admin.upms.dao.SysDataPermMenuMapper;
|
||||
import com.orange.admin.upms.model.*;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.CachePut;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import tk.mybatis.mapper.entity.Example;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 数据权限数据服务类。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
*/
|
||||
@Service
|
||||
public class SysDataPermService extends BaseService<SysDataPerm, Long> {
|
||||
|
||||
@Autowired
|
||||
private SysDataPermMapper sysDataPermMapper;
|
||||
@Autowired
|
||||
private SysDataPermDeptMapper sysDataPermDeptMapper;
|
||||
@Autowired
|
||||
private SysDataPermMenuMapper sysDataPermMenuMapper;
|
||||
@Autowired
|
||||
private SysMenuService sysMenuService;
|
||||
@Autowired
|
||||
private SysDataPermUserMapper sysDataPermUserMapper;
|
||||
@Autowired
|
||||
private SysDeptService sysDeptService;
|
||||
@Autowired
|
||||
private BasicIdGenerator idGenerator;
|
||||
|
||||
/**
|
||||
* 返回主对象的Mapper对象。
|
||||
*
|
||||
* @return 主对象的Mapper对象。
|
||||
*/
|
||||
@Override
|
||||
protected BaseDaoMapper<SysDataPerm> mapper() {
|
||||
return sysDataPermMapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存新增的数据权限对象。
|
||||
*
|
||||
* @param dataPerm 新增的数据权限对象。
|
||||
* @param deptIdSet 关联的部门Id列表。
|
||||
* @param dataPermMenuList 关联的菜单对象列表。
|
||||
* @return 新增后的数据权限对象。
|
||||
*/
|
||||
@Transactional
|
||||
public SysDataPerm saveNew(SysDataPerm dataPerm, Set<Long> deptIdSet, List<SysDataPermMenu> dataPermMenuList) {
|
||||
dataPerm.setDataPermId(idGenerator.nextLongId());
|
||||
TokenData tokenData = TokenData.takeFromRequest();
|
||||
dataPerm.setCreateUserId(tokenData.getUserId());
|
||||
dataPerm.setCreateUsername(tokenData.getShowName());
|
||||
dataPerm.setDeletedFlag(GlobalDeletedFlag.NORMAL);
|
||||
Date now = new Date();
|
||||
dataPerm.setCreateTime(now);
|
||||
dataPerm.setUpdateTime(now);
|
||||
sysDataPermMapper.insert(dataPerm);
|
||||
this.insertRelationData(dataPerm, deptIdSet, dataPermMenuList);
|
||||
return dataPerm;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新数据权限对象。
|
||||
*
|
||||
* @param dataPerm 更新的数据权限对象。
|
||||
* @param originalDataPerm 原有的数据权限对象。
|
||||
* @param deptIdSet 关联的部门Id列表。
|
||||
* @param dataPermMenuList 关联的菜单对象列表。
|
||||
* @return 更新成功返回true,否则false。
|
||||
*/
|
||||
@Transactional
|
||||
public boolean update(
|
||||
SysDataPerm dataPerm,
|
||||
SysDataPerm originalDataPerm,
|
||||
Set<Long> deptIdSet,
|
||||
List<SysDataPermMenu> dataPermMenuList) {
|
||||
dataPerm.setUpdateTime(new Date());
|
||||
dataPerm.setCreateTime(originalDataPerm.getCreateTime());
|
||||
dataPerm.setCreateUserId(originalDataPerm.getCreateUserId());
|
||||
dataPerm.setCreateUsername(originalDataPerm.getCreateUsername());
|
||||
dataPerm.setDeletedFlag(GlobalDeletedFlag.NORMAL);
|
||||
if (sysDataPermMapper.updateByPrimaryKey(dataPerm) != 1) {
|
||||
return false;
|
||||
}
|
||||
SysDataPermMenu dataPermMenu = new SysDataPermMenu();
|
||||
dataPermMenu.setDataPermId(dataPerm.getDataPermId());
|
||||
sysDataPermMenuMapper.delete(dataPermMenu);
|
||||
SysDataPermDept dataPermDept = new SysDataPermDept();
|
||||
dataPermDept.setDataPermId(dataPerm.getDataPermId());
|
||||
sysDataPermDeptMapper.delete(dataPermDept);
|
||||
this.insertRelationData(dataPerm, deptIdSet, dataPermMenuList);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定数据权限。
|
||||
*
|
||||
* @param dataPermId 数据权限主键Id。
|
||||
* @return 删除成功返回true,否则false。
|
||||
*/
|
||||
@Transactional
|
||||
public boolean remove(Long dataPermId) {
|
||||
SysDataPerm dataPerm = new SysDataPerm();
|
||||
dataPerm.setDataPermId(dataPermId);
|
||||
dataPerm.setDeletedFlag(GlobalDeletedFlag.DELETED);
|
||||
if (sysDataPermMapper.updateByPrimaryKeySelective(dataPerm) != 1) {
|
||||
return false;
|
||||
}
|
||||
SysDataPermMenu dataPermMenu = new SysDataPermMenu();
|
||||
dataPermMenu.setDataPermId(dataPermId);
|
||||
sysDataPermMenuMapper.delete(dataPermMenu);
|
||||
SysDataPermDept dataPermDept = new SysDataPermDept();
|
||||
dataPermDept.setDataPermId(dataPermId);
|
||||
sysDataPermDeptMapper.delete(dataPermDept);
|
||||
SysDataPermUser dataPermUser = new SysDataPermUser();
|
||||
dataPermUser.setDataPermId(dataPermId);
|
||||
sysDataPermUserMapper.delete(dataPermUser);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据权限列表。
|
||||
*
|
||||
* @param filter 数据权限过滤对象。
|
||||
* @param orderBy 排序参数。
|
||||
* @return 数据权限查询列表。
|
||||
*/
|
||||
public List<SysDataPerm> getSysDataPermList(SysDataPerm filter, String orderBy) {
|
||||
return sysDataPermMapper.getSysDataPermList(filter, orderBy);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定数据权限,同时包含其关联数据。
|
||||
*
|
||||
* @param dataPermId 数据权限主键Id。
|
||||
* @return 数据权限对象。
|
||||
*/
|
||||
public SysDataPerm getSysDataPermWithRelation(Long dataPermId) {
|
||||
SysDataPerm dataPerm = this.getById(dataPermId);
|
||||
if (dataPerm != null) {
|
||||
SysDataPermDept dataPermDept = new SysDataPermDept();
|
||||
dataPermDept.setDataPermId(dataPermId);
|
||||
List<SysDataPermDept> dataPermDeptList = sysDataPermDeptMapper.select(dataPermDept);
|
||||
dataPerm.setDataPermDeptList(dataPermDeptList);
|
||||
SysDataPermMenu dataPermMenu = new SysDataPermMenu();
|
||||
dataPermMenu.setDataPermId(dataPermId);
|
||||
List<SysDataPermMenu> dataPermMenuList = sysDataPermMenuMapper.select(dataPermMenu);
|
||||
dataPerm.setDataPermMenuList(dataPermMenuList);
|
||||
}
|
||||
return dataPerm;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将指定用户的指定会话的数据权限集合存入缓存。
|
||||
*
|
||||
* @param sessionId 会话Id。
|
||||
* @param userId 用户主键Id。
|
||||
* @param deptId 用户所属部门主键Id。
|
||||
* @param isAdmin 是否是管理员。
|
||||
* @return 查询并缓存后的数据权限集合。返回格式为,Map<MenuId, Map<RuleType, DeptIdString>>。
|
||||
*/
|
||||
@CachePut(value = "DataPermissionCache", key = "#sessionId")
|
||||
public Map<Object, Map<Integer, String>> putDataPermCache(
|
||||
String sessionId, Long userId, Long deptId, boolean isAdmin) {
|
||||
// 管理员账户返回空对象,便于缓存的统一处理。
|
||||
return isAdmin ? new HashMap<>(1) : this.getSysDataPermMenuListByUserId(userId, deptId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将指定会话的数据权限集合从缓存中移除。
|
||||
*
|
||||
* @param sessionId 会话Id。
|
||||
*/
|
||||
@CacheEvict(value = "DataPermissionCache", key = "#sessionId")
|
||||
public void removeDataPermCache(String sessionId) {
|
||||
// 空实现即可,只是通过注解将当前sessionId从cache中删除。
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定用户Id的数据权限列表。并基于菜单Id和权限规则类型进行了一级和二级的分组。
|
||||
*
|
||||
* @param userId 指定的用户Id。
|
||||
* @param deptId 用户所属部门主键Id。
|
||||
* @return 合并优化后的数据权限列表。返回格式为,Map<MenuId, Map<RuleType, DeptIdString>>。
|
||||
*/
|
||||
public Map<Object, Map<Integer, String>> getSysDataPermMenuListByUserId(Long userId, Long deptId) {
|
||||
List<SysDataPermMenu> dataPermMenuList = sysDataPermMenuMapper.getSysDataPermMenuListByUserId(userId);
|
||||
if (dataPermMenuList.size() == 0) {
|
||||
return new HashMap<>(1);
|
||||
}
|
||||
// 这里用代码的方式把deptId组装到SysDataPermMenu中。
|
||||
Set<Long> dataPermIdSet = dataPermMenuList.stream()
|
||||
.map(SysDataPermMenu::getDataPermId).collect(Collectors.toSet());
|
||||
Example e = new Example(SysDataPermDept.class);
|
||||
e.createCriteria().andIn("dataPermId", dataPermIdSet);
|
||||
List<SysDataPermDept> dataPermDeptList = sysDataPermDeptMapper.selectByExample(e);
|
||||
Map<Long, List<SysDataPermDept>> deptMap =
|
||||
dataPermDeptList.stream().collect(Collectors.groupingBy(SysDataPermDept::getDataPermId));
|
||||
for (SysDataPermMenu dataPermMenu : dataPermMenuList) {
|
||||
List<SysDataPermDept> deptList = deptMap.get(dataPermMenu.getDataPermId());
|
||||
if (CollectionUtils.isNotEmpty(deptList)) {
|
||||
Set<Long> deptIdSet = deptList.stream().map(SysDataPermDept::getDeptId).collect(Collectors.toSet());
|
||||
dataPermMenu.setDeptIdListString(StringUtils.join(deptIdSet, ","));
|
||||
}
|
||||
}
|
||||
// 由于同一用户可能属于多个数据权限,所以需要先进行基于menuId的权限合并。
|
||||
Map<Object, List<SysDataPermMenu>> menuMap =
|
||||
dataPermMenuList.stream().collect(Collectors.groupingBy(SysDataPermMenu::getMenuId));
|
||||
Map<Object, Map<Integer, String>> resultMap = new HashMap<>(menuMap.size());
|
||||
// 这里menuMap的key是menuId
|
||||
for (Map.Entry<Object, List<SysDataPermMenu>> entry : menuMap.entrySet()) {
|
||||
Object menuId = entry.getKey();
|
||||
// 为了更方便进行后续的合并优化处理,这里再基于规则类型进行分组。ruleMap的key是规则类型。
|
||||
Map<Integer, List<SysDataPermMenu>> ruleMap =
|
||||
entry.getValue().stream().collect(Collectors.groupingBy(SysDataPermMenu::getRuleType));
|
||||
Map<Integer, String> m = new HashMap<>(1);
|
||||
// 如有有ALL存在,就可以直接退出了,没有必要在处理后续的规则了。
|
||||
if (ruleMap.containsKey(DataPermRuleType.TYPE_ALL)) {
|
||||
m.put(DataPermRuleType.TYPE_ALL, "null");
|
||||
resultMap.put(menuId, m);
|
||||
continue;
|
||||
}
|
||||
// 合并自定义部门了。
|
||||
List<SysDataPermMenu> customDeptList = ruleMap.get(DataPermRuleType.TYPE_CUSTOM_DETP_LIST);
|
||||
if (customDeptList != null) {
|
||||
Set<Long> deptIdSet = new HashSet<>();
|
||||
for (SysDataPermMenu customDept : customDeptList) {
|
||||
deptIdSet.addAll(Arrays.stream(StringUtils.split(
|
||||
customDept.getDeptIdListString(), ",")).map(Long::valueOf).collect(Collectors.toSet()));
|
||||
}
|
||||
if (ruleMap.containsKey(DataPermRuleType.TYPE_DEPT_ONLY)) {
|
||||
deptIdSet.add(deptId);
|
||||
ruleMap.remove(DataPermRuleType.TYPE_DEPT_ONLY);
|
||||
}
|
||||
m.put(DataPermRuleType.TYPE_CUSTOM_DETP_LIST, StringUtils.join(deptIdSet, ','));
|
||||
}
|
||||
// 最后处理当前部门和当前用户。
|
||||
if (ruleMap.get(DataPermRuleType.TYPE_DEPT_ONLY) != null) {
|
||||
m.put(DataPermRuleType.TYPE_DEPT_ONLY, "null");
|
||||
}
|
||||
if (ruleMap.get(DataPermRuleType.TYPE_USER_ONLY) != null) {
|
||||
m.put(DataPermRuleType.TYPE_USER_ONLY, "null");
|
||||
}
|
||||
resultMap.put(menuId, m);
|
||||
}
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加用户和数据权限之间的多对多关联关系。
|
||||
*
|
||||
* @param dataPermId 数据权限Id。
|
||||
* @param userIdSet 关联的用户Id列表。
|
||||
*/
|
||||
@Transactional
|
||||
public void addDataPermUserList(Long dataPermId, Set<Long> userIdSet) {
|
||||
List<SysDataPermUser> dataPermUserList = new LinkedList<>();
|
||||
for (Long userId : userIdSet) {
|
||||
SysDataPermUser dataPermUser = new SysDataPermUser();
|
||||
dataPermUser.setDataPermId(dataPermId);
|
||||
dataPermUser.setUserId(userId);
|
||||
dataPermUserList.add(dataPermUser);
|
||||
}
|
||||
sysDataPermUserMapper.addDataPermUserList(dataPermUserList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除用户和数据权限之间的多对多关联关系。
|
||||
*
|
||||
* @param dataPermId 数据权限主键Id。
|
||||
* @param userId 用户主键Id。
|
||||
*/
|
||||
@Transactional
|
||||
public boolean removeDataPermUser(Long dataPermId, Long userId) {
|
||||
SysDataPermUser dataPermUser = new SysDataPermUser();
|
||||
dataPermUser.setDataPermId(dataPermId);
|
||||
dataPermUser.setUserId(userId);
|
||||
return sysDataPermUserMapper.delete(dataPermUser) == 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证数据权限对象关联菜单数据是否都合法。
|
||||
*
|
||||
* @param dataPerm 数据权限关对象。
|
||||
* @param deptIdListString 与数据权限关联的部门Id列表。
|
||||
* @param menuIdListString 与数据权限关联的菜单Id列表。
|
||||
* @return 验证结果。
|
||||
*/
|
||||
public VerifyResult verifyRelatedData(SysDataPerm dataPerm, String deptIdListString, String menuIdListString) {
|
||||
String errorMessage = null;
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
do {
|
||||
if (dataPerm.getRuleType() == DataPermRuleType.TYPE_CUSTOM_DETP_LIST) {
|
||||
if (StringUtils.isBlank(deptIdListString)) {
|
||||
errorMessage = "数据验证失败,部门列表不能为空!";
|
||||
break;
|
||||
}
|
||||
Set<Long> deptIdSet = Arrays.stream(StringUtils.split(
|
||||
deptIdListString, ",")).map(Long::valueOf).collect(Collectors.toSet());
|
||||
if (!sysDeptService.existUniqueKeyList("deptId", deptIdSet)) {
|
||||
errorMessage = "数据验证失败,存在不合法的部门数据,请刷新后重试!";
|
||||
break;
|
||||
}
|
||||
jsonObject.put("deptIdSet", deptIdSet);
|
||||
}
|
||||
String[] menuIdArray = StringUtils.split(menuIdListString, ",");
|
||||
Set<Long> menuIdSet = Arrays.stream(menuIdArray).map(Long::valueOf).collect(Collectors.toSet());
|
||||
// 验证菜单Id的合法性
|
||||
if (!sysMenuService.existUniqueKeyList("menuId", menuIdSet)) {
|
||||
errorMessage = "数据验证失败,存在不合法的菜单,请刷新后重试!";
|
||||
break;
|
||||
}
|
||||
List<SysDataPermMenu> dataPermMenuList = new LinkedList<>();
|
||||
for (Long menuId : menuIdSet) {
|
||||
SysDataPermMenu dataPermMenu = new SysDataPermMenu();
|
||||
dataPermMenu.setMenuId(menuId);
|
||||
dataPermMenuList.add(dataPermMenu);
|
||||
}
|
||||
jsonObject.put("dataPermMenuList", dataPermMenuList);
|
||||
} while (false);
|
||||
return VerifyResult.create(errorMessage, jsonObject);
|
||||
}
|
||||
|
||||
private void insertRelationData(
|
||||
SysDataPerm dataPerm, Set<Long> deptIdSet, List<SysDataPermMenu> dataPermMenuList) {
|
||||
if (CollectionUtils.isNotEmpty(deptIdSet)) {
|
||||
List<SysDataPermDept> dataPermDeptList = new LinkedList<>();
|
||||
for (Long deptId : deptIdSet) {
|
||||
SysDataPermDept dataPermDept = new SysDataPermDept();
|
||||
dataPermDept.setDataPermId(dataPerm.getDataPermId());
|
||||
dataPermDept.setDeptId(deptId);
|
||||
dataPermDeptList.add(dataPermDept);
|
||||
}
|
||||
sysDataPermDeptMapper.insertList(dataPermDeptList);
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(dataPermMenuList)) {
|
||||
for (SysDataPermMenu dataPermMenu : dataPermMenuList) {
|
||||
dataPermMenu.setDataPermId(dataPerm.getDataPermId());
|
||||
}
|
||||
sysDataPermMenuMapper.insertList(dataPermMenuList);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
package com.orange.admin.upms.service;
|
||||
|
||||
import com.orange.admin.upms.dao.*;
|
||||
import com.orange.admin.upms.model.*;
|
||||
import com.orange.admin.common.core.base.service.BaseService;
|
||||
import com.orange.admin.common.core.base.dao.BaseDaoMapper;
|
||||
import com.orange.admin.common.core.constant.GlobalDeletedFlag;
|
||||
import com.orange.admin.common.core.object.TokenData;
|
||||
import com.orange.admin.common.core.object.MyWhereCriteria;
|
||||
import com.orange.admin.common.biz.util.BasicIdGenerator;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import tk.mybatis.mapper.entity.Example;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 部门管理数据操作服务类。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
*/
|
||||
@Service
|
||||
public class SysDeptService extends BaseService<SysDept, Long> {
|
||||
|
||||
@Autowired
|
||||
private SysDeptMapper sysDeptMapper;
|
||||
@Autowired
|
||||
private SysDataPermDeptMapper sysDataPermDeptMapper;
|
||||
@Autowired
|
||||
private BasicIdGenerator idGenerator;
|
||||
|
||||
/**
|
||||
* 返回当前Service的主表Mapper对象。
|
||||
*
|
||||
* @return 主表Mapper对象。
|
||||
*/
|
||||
@Override
|
||||
protected BaseDaoMapper<SysDept> mapper() {
|
||||
return sysDeptMapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存新增的部门对象。
|
||||
*
|
||||
* @param sysDept 新增的部门对象。
|
||||
* @return 新增后的部门对象。
|
||||
*/
|
||||
@Transactional
|
||||
public SysDept saveNew(SysDept sysDept) {
|
||||
sysDept.setDeptId(idGenerator.nextLongId());
|
||||
sysDept.setDeletedFlag(GlobalDeletedFlag.NORMAL);
|
||||
TokenData tokenData = TokenData.takeFromRequest();
|
||||
sysDept.setCreateUserId(tokenData.getUserId());
|
||||
sysDept.setCreateUsername(tokenData.getShowName());
|
||||
Date now = new Date();
|
||||
sysDept.setCreateTime(now);
|
||||
sysDept.setUpdateTime(now);
|
||||
sysDeptMapper.insert(sysDept);
|
||||
return sysDept;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新部门对象。
|
||||
*
|
||||
* @param sysDept 更新的部门对象。
|
||||
* @param originalSysDept 原有的部门对象。
|
||||
* @return 更新成功返回true,否则false。
|
||||
*/
|
||||
@Transactional
|
||||
public boolean update(SysDept sysDept, SysDept originalSysDept) {
|
||||
sysDept.setCreateUserId(originalSysDept.getCreateUserId());
|
||||
sysDept.setCreateUsername(originalSysDept.getCreateUsername());
|
||||
sysDept.setCreateTime(originalSysDept.getCreateTime());
|
||||
sysDept.setUpdateTime(new Date());
|
||||
sysDept.setDeletedFlag(GlobalDeletedFlag.NORMAL);
|
||||
return sysDeptMapper.updateByPrimaryKey(sysDept) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定数据。
|
||||
*
|
||||
* @param deptId 主键Id。
|
||||
* @return 成功返回true,否则false。
|
||||
*/
|
||||
@Transactional
|
||||
public boolean remove(Long deptId) {
|
||||
Example sysDeptExample = new Example(SysDept.class);
|
||||
Example.Criteria c = sysDeptExample.createCriteria();
|
||||
c.andEqualTo("deptId", deptId);
|
||||
c.andEqualTo("deletedFlag", GlobalDeletedFlag.NORMAL);
|
||||
// 这里先删除主数据
|
||||
SysDept deletedObject = new SysDept();
|
||||
deletedObject.setDeletedFlag(GlobalDeletedFlag.DELETED);
|
||||
if (sysDeptMapper.updateByExampleSelective(deletedObject, sysDeptExample) == 0) {
|
||||
return false;
|
||||
}
|
||||
// 这里可继续删除关联数据。
|
||||
Example dataPermDeptExample = new Example(SysDataPermDept.class);
|
||||
dataPermDeptExample.createCriteria().andEqualTo("deptId", deptId);
|
||||
sysDataPermDeptMapper.deleteByExample(dataPermDeptExample);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单表查询结果。由于没有关联数据查询,因此在仅仅获取单表数据的场景下,效率更高。
|
||||
* 如果需要同时获取关联数据,请移步(getSysDeptListWithRelation)方法。
|
||||
*
|
||||
* @param filter 过滤对象。
|
||||
* @param orderBy 排序参数。
|
||||
* @return 查询结果集。
|
||||
*/
|
||||
public List<SysDept> getSysDeptList(SysDept filter, String orderBy) {
|
||||
return sysDeptMapper.getSysDeptList(filter, orderBy);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取主表的查询结果,以及主表关联的字典数据和一对一从表数据,以及一对一从表的字典数据。
|
||||
* 如果仅仅需要获取主表数据,请移步(getSysDeptList),以便获取更好的查询性能。
|
||||
*
|
||||
* @param filter 主表过滤对象。
|
||||
* @param orderBy 排序参数。
|
||||
* @return 查询结果集。
|
||||
*/
|
||||
public List<SysDept> getSysDeptListWithRelation(SysDept filter, String orderBy) {
|
||||
List<SysDept> resultList = sysDeptMapper.getSysDeptList(filter, orderBy);
|
||||
Map<String, List<MyWhereCriteria>> criteriaMap = buildAggregationAdditionalWhereCriteria();
|
||||
this.buildAllRelationForDataList(resultList, false, criteriaMap);
|
||||
return resultList;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,263 @@
|
||||
package com.orange.admin.upms.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.orange.admin.common.biz.util.BasicIdGenerator;
|
||||
import com.orange.admin.common.core.base.dao.BaseDaoMapper;
|
||||
import com.orange.admin.common.core.base.service.BaseService;
|
||||
import com.orange.admin.common.core.constant.GlobalDeletedFlag;
|
||||
import com.orange.admin.common.core.object.VerifyResult;
|
||||
import com.orange.admin.upms.dao.SysMenuMapper;
|
||||
import com.orange.admin.upms.dao.SysMenuPermCodeMapper;
|
||||
import com.orange.admin.upms.dao.SysRoleMenuMapper;
|
||||
import com.orange.admin.upms.dao.SysDataPermMenuMapper;
|
||||
import com.orange.admin.upms.model.SysDataPermMenu;
|
||||
import com.orange.admin.upms.model.SysMenu;
|
||||
import com.orange.admin.upms.model.SysMenuPermCode;
|
||||
import com.orange.admin.upms.model.SysRoleMenu;
|
||||
import com.orange.admin.upms.model.constant.SysMenuType;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import tk.mybatis.mapper.entity.Example;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 菜单数据服务类。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
*/
|
||||
@Service
|
||||
public class SysMenuService extends BaseService<SysMenu, Long> {
|
||||
|
||||
@Autowired
|
||||
private SysMenuMapper sysMenuMapper;
|
||||
@Autowired
|
||||
private SysRoleMenuMapper sysRoleMenuMapper;
|
||||
@Autowired
|
||||
private SysMenuPermCodeMapper sysMenuPermCodeMapper;
|
||||
@Autowired
|
||||
private SysPermCodeService sysPermCodeService;
|
||||
@Autowired
|
||||
private SysDataPermMenuMapper sysDataPermMenuMapper;
|
||||
@Autowired
|
||||
private BasicIdGenerator idGenerator;
|
||||
|
||||
/**
|
||||
* 返回主对象的Mapper对象。
|
||||
*
|
||||
* @return 主对象的Mapper对象。
|
||||
*/
|
||||
@Override
|
||||
protected BaseDaoMapper<SysMenu> mapper() {
|
||||
return sysMenuMapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存新增的菜单对象。
|
||||
*
|
||||
* @param sysMenu 新增的菜单对象。
|
||||
* @param permCodeIdSet 权限字Id列表。
|
||||
* @return 新增后的菜单对象。
|
||||
*/
|
||||
@Transactional
|
||||
public SysMenu saveNew(SysMenu sysMenu, Set<Long> permCodeIdSet) {
|
||||
sysMenu.setMenuId(idGenerator.nextLongId());
|
||||
sysMenu.setCreateTime(new Date());
|
||||
sysMenu.setDeletedFlag(GlobalDeletedFlag.NORMAL);
|
||||
sysMenuMapper.insert(sysMenu);
|
||||
if (permCodeIdSet != null) {
|
||||
List<SysMenuPermCode> sysMenuPermCodeList = new LinkedList<>();
|
||||
for (Long permCodeId : permCodeIdSet) {
|
||||
SysMenuPermCode menuPermCode = new SysMenuPermCode();
|
||||
menuPermCode.setMenuId(sysMenu.getMenuId());
|
||||
menuPermCode.setPermCodeId(permCodeId);
|
||||
sysMenuPermCodeList.add(menuPermCode);
|
||||
}
|
||||
sysMenuPermCodeMapper.insertList(sysMenuPermCodeList);
|
||||
}
|
||||
return sysMenu;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新菜单对象。
|
||||
*
|
||||
* @param sysMenu 更新的菜单对象。
|
||||
* @param originalSysMenu 原有的菜单对象。
|
||||
* @param permCodeIdSet 权限字Id列表。
|
||||
* @return 更新成功返回true,否则false。
|
||||
*/
|
||||
@Transactional
|
||||
public boolean update(SysMenu sysMenu, SysMenu originalSysMenu, Set<Long> permCodeIdSet) {
|
||||
sysMenu.setCreateTime(originalSysMenu.getCreateTime());
|
||||
sysMenu.setMenuType(originalSysMenu.getMenuType());
|
||||
sysMenu.setDeletedFlag(GlobalDeletedFlag.NORMAL);
|
||||
if (sysMenuMapper.updateByPrimaryKey(sysMenu) != 1) {
|
||||
return false;
|
||||
}
|
||||
Example e = new Example(SysMenuPermCode.class);
|
||||
e.createCriteria().andEqualTo("menuId", sysMenu.getMenuId());
|
||||
sysMenuPermCodeMapper.deleteByExample(e);
|
||||
if (permCodeIdSet != null) {
|
||||
List<SysMenuPermCode> sysMenuPermCodeList = new LinkedList<>();
|
||||
for (Long permCodeId : permCodeIdSet) {
|
||||
SysMenuPermCode menuPermCode = new SysMenuPermCode();
|
||||
menuPermCode.setMenuId(sysMenu.getMenuId());
|
||||
menuPermCode.setPermCodeId(permCodeId);
|
||||
sysMenuPermCodeList.add(menuPermCode);
|
||||
}
|
||||
sysMenuPermCodeMapper.insertList(sysMenuPermCodeList);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定的菜单。
|
||||
*
|
||||
* @param menuId 菜单主键Id。
|
||||
* @return 删除成功返回true,否则false。
|
||||
*/
|
||||
@Transactional
|
||||
public boolean remove(Long menuId) {
|
||||
SysMenu menu = new SysMenu();
|
||||
menu.setMenuId(menuId);
|
||||
menu.setDeletedFlag(GlobalDeletedFlag.DELETED);
|
||||
if (sysMenuMapper.updateByPrimaryKeySelective(menu) != 1) {
|
||||
return false;
|
||||
}
|
||||
Example roleMenuExample = new Example(SysRoleMenu.class);
|
||||
roleMenuExample.createCriteria().andEqualTo("menuId", menuId);
|
||||
sysRoleMenuMapper.deleteByExample(roleMenuExample);
|
||||
Example menuPermCodeExample = new Example(SysMenuPermCode.class);
|
||||
menuPermCodeExample.createCriteria().andEqualTo("menuId", menuId);
|
||||
sysMenuPermCodeMapper.deleteByExample(menuPermCodeExample);
|
||||
Example dataPermMenuExample = new Example(SysDataPermMenu.class);
|
||||
dataPermMenuExample.createCriteria().andEqualTo("menuId", menuId);
|
||||
sysDataPermMenuMapper.deleteByExample(dataPermMenuExample);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取全部菜单列表。
|
||||
*
|
||||
* @return 全部菜单列表。
|
||||
*/
|
||||
public List<SysMenu> getAllMenuList() {
|
||||
Example e = new Example(SysMenu.class);
|
||||
e.orderBy("showOrder");
|
||||
Example.Criteria c = e.createCriteria();
|
||||
c.andIn("menuType", Arrays.asList(SysMenuType.TYPE_MENU, SysMenuType.TYPE_DIRECTORY));
|
||||
c.andEqualTo("deletedFlag", GlobalDeletedFlag.NORMAL);
|
||||
return sysMenuMapper.selectByExample(e);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定用户Id的菜单列表。
|
||||
*
|
||||
* @param userId 用户主键Id。
|
||||
* @return 用户关联的菜单列表。
|
||||
*/
|
||||
public List<SysMenu> getMenuListByUserId(Long userId) {
|
||||
return sysMenuMapper.getMenuListByUserId(userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定菜单的详情对象。
|
||||
*
|
||||
* @param menuId 菜单主键Id。
|
||||
* @return 菜单对象。
|
||||
*/
|
||||
public SysMenu getSysMenuWithRelation(Long menuId) {
|
||||
SysMenu sysMenu = this.getById(menuId);
|
||||
if (sysMenu != null) {
|
||||
Example e = new Example(SysMenuPermCode.class);
|
||||
e.createCriteria().andEqualTo("menuId", menuId);
|
||||
List<SysMenuPermCode> sysMenuPermCodeList = sysMenuPermCodeMapper.selectByExample(e);
|
||||
if (sysMenuPermCodeList.size() > 0) {
|
||||
List<Long> permCodeIdList =
|
||||
sysMenuPermCodeList.stream().map(SysMenuPermCode::getPermCodeId).collect(Collectors.toList());
|
||||
sysMenu.setPermCodeIdList(permCodeIdList);
|
||||
}
|
||||
}
|
||||
return sysMenu;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断当前菜单是否存在子菜单。
|
||||
*
|
||||
* @param menuId 菜单主键Id。
|
||||
* @return 存在返回true,否则false。
|
||||
*/
|
||||
public boolean hasChildren(Long menuId) {
|
||||
SysMenu menu = new SysMenu();
|
||||
menu.setParentId(menuId);
|
||||
return this.getCountByFilter(menu) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证菜单对象关联的数据是否都合法。
|
||||
*
|
||||
* @param sysMenu 当前操作的对象。
|
||||
* @param originalSysMenu 原有对象。
|
||||
* @param permCodeIdListString 逗号分隔的权限Id列表。
|
||||
* @return 验证结果。
|
||||
*/
|
||||
public VerifyResult verifyRelatedData(SysMenu sysMenu, SysMenu originalSysMenu, String permCodeIdListString) {
|
||||
String errorMessage = null;
|
||||
JSONObject jsonObject = null;
|
||||
do {
|
||||
if (this.needToVerify(sysMenu, originalSysMenu, SysMenu::getParentId)) {
|
||||
// 1. menu、ui fragment和button类型的menu不能没有parentId
|
||||
if (sysMenu.getParentId() == null) {
|
||||
if (sysMenu.getMenuType() != SysMenuType.TYPE_DIRECTORY) {
|
||||
errorMessage = "数据验证失败,当前类型菜单项的上级菜单不能为空!";
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// 2. 判断父节点是否存在
|
||||
SysMenu parentSysMenu = getById(sysMenu.getParentId());
|
||||
if (parentSysMenu == null) {
|
||||
errorMessage = "数据验证失败,关联的上级菜单并不存在,请刷新后重试!";
|
||||
break;
|
||||
}
|
||||
// 3. 逐个判断每种类型的菜单,他的父菜单的合法性,先从目录类型和菜单类型开始
|
||||
if (sysMenu.getMenuType() == SysMenuType.TYPE_DIRECTORY
|
||||
|| sysMenu.getMenuType() == SysMenuType.TYPE_MENU) {
|
||||
// 他们的上级只能是目录
|
||||
if (parentSysMenu.getMenuType() != SysMenuType.TYPE_DIRECTORY) {
|
||||
errorMessage = "数据验证失败,当前类型菜单项的上级菜单只能是目录类型!";
|
||||
break;
|
||||
}
|
||||
} else if (sysMenu.getMenuType() == SysMenuType.TYPE_UI_FRAGMENT) {
|
||||
// ui fragment的上级只能是menu类型
|
||||
if (parentSysMenu.getMenuType() != SysMenuType.TYPE_MENU) {
|
||||
errorMessage = "数据验证失败,当前类型菜单项的上级菜单只能是菜单类型和按钮类型!";
|
||||
break;
|
||||
}
|
||||
} else if (sysMenu.getMenuType() == SysMenuType.TYPE_BUTTON) {
|
||||
// button的上级只能是menu和ui fragment
|
||||
if (parentSysMenu.getMenuType() != SysMenuType.TYPE_MENU
|
||||
&& parentSysMenu.getMenuType() != SysMenuType.TYPE_UI_FRAGMENT) {
|
||||
errorMessage = "数据验证失败,当前类型菜单项的上级菜单只能是菜单类型和UI片段类型!";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (StringUtils.isNotBlank(permCodeIdListString)) {
|
||||
Set<Long> permCodeIdSet = Arrays.stream(
|
||||
permCodeIdListString.split(",")).map(Long::valueOf).collect(Collectors.toSet());
|
||||
if (!sysPermCodeService.existUniqueKeyList("permCodeId", permCodeIdSet)) {
|
||||
errorMessage = "数据验证失败,存在不合法的权限字,请刷新后重试!";
|
||||
break;
|
||||
}
|
||||
jsonObject = new JSONObject();
|
||||
jsonObject.put("permCodeIdSet", permCodeIdSet);
|
||||
}
|
||||
} while (false);
|
||||
return VerifyResult.create(errorMessage, jsonObject);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,232 @@
|
||||
package com.orange.admin.upms.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.orange.admin.common.biz.util.BasicIdGenerator;
|
||||
import com.orange.admin.common.core.base.dao.BaseDaoMapper;
|
||||
import com.orange.admin.common.core.base.service.BaseService;
|
||||
import com.orange.admin.common.core.constant.GlobalDeletedFlag;
|
||||
import com.orange.admin.common.core.object.VerifyResult;
|
||||
import com.orange.admin.upms.dao.SysMenuPermCodeMapper;
|
||||
import com.orange.admin.upms.dao.SysPermCodeMapper;
|
||||
import com.orange.admin.upms.dao.SysPermCodePermMapper;
|
||||
import com.orange.admin.upms.model.SysMenuPermCode;
|
||||
import com.orange.admin.upms.model.SysPermCode;
|
||||
import com.orange.admin.upms.model.SysPermCodePerm;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import tk.mybatis.mapper.entity.Example;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 权限字数据服务类。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
*/
|
||||
@Service
|
||||
public class SysPermCodeService extends BaseService<SysPermCode, Long> {
|
||||
|
||||
@Autowired
|
||||
private SysPermCodeMapper sysPermCodeMapper;
|
||||
@Autowired
|
||||
private SysPermCodePermMapper sysPermCodePermMapper;
|
||||
@Autowired
|
||||
private SysMenuPermCodeMapper sysMenuPermCodeMapper;
|
||||
@Autowired
|
||||
private SysPermService sysPermService;
|
||||
@Autowired
|
||||
private BasicIdGenerator idGenerator;
|
||||
|
||||
/**
|
||||
* 返回主对象的Mapper对象。
|
||||
*
|
||||
* @return 主对象的Mapper对象。
|
||||
*/
|
||||
@Override
|
||||
protected BaseDaoMapper<SysPermCode> mapper() {
|
||||
return sysPermCodeMapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定用户的权限字列表。
|
||||
*
|
||||
* @param userId 用户主键Id。
|
||||
* @return 用户关联的权限字列表。
|
||||
*/
|
||||
public List<String> getPermCodeListByUserId(Long userId) {
|
||||
return sysPermCodeMapper.getPermCodeListByUserId(userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存新增的权限字对象。
|
||||
*
|
||||
* @param sysPermCode 新增的权限字对象。
|
||||
* @param permIdSet 权限资源Id列表。
|
||||
* @return 新增后的权限字对象。
|
||||
*/
|
||||
@Transactional
|
||||
public SysPermCode saveNew(SysPermCode sysPermCode, Set<Long> permIdSet) {
|
||||
sysPermCode.setPermCodeId(idGenerator.nextLongId());
|
||||
sysPermCode.setCreateTime(new Date());
|
||||
sysPermCode.setDeletedFlag(GlobalDeletedFlag.NORMAL);
|
||||
sysPermCodeMapper.insert(sysPermCode);
|
||||
if (permIdSet != null) {
|
||||
List<SysPermCodePerm> sysPermCodePermList = new LinkedList<>();
|
||||
for (Long permId : permIdSet) {
|
||||
SysPermCodePerm permCodePerm = new SysPermCodePerm();
|
||||
permCodePerm.setPermCodeId(sysPermCode.getPermCodeId());
|
||||
permCodePerm.setPermId(permId);
|
||||
sysPermCodePermList.add(permCodePerm);
|
||||
}
|
||||
sysPermCodePermMapper.insertList(sysPermCodePermList);
|
||||
}
|
||||
return sysPermCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新权限字对象。
|
||||
*
|
||||
* @param sysPermCode 更新的权限字对象。
|
||||
* @param originalSysPermCode 原有的权限字对象。
|
||||
* @param permIdSet 权限资源Id列表。
|
||||
* @return 更新成功返回true,否则false。
|
||||
*/
|
||||
@Transactional
|
||||
public boolean update(SysPermCode sysPermCode, SysPermCode originalSysPermCode, Set<Long> permIdSet) {
|
||||
sysPermCode.setCreateTime(originalSysPermCode.getCreateTime());
|
||||
sysPermCode.setParentId(originalSysPermCode.getParentId());
|
||||
sysPermCode.setDeletedFlag(GlobalDeletedFlag.NORMAL);
|
||||
if (sysPermCodeMapper.updateByPrimaryKey(sysPermCode) != 1) {
|
||||
return false;
|
||||
}
|
||||
Example e = new Example(SysPermCodePerm.class);
|
||||
e.createCriteria().andEqualTo("permCodeId", sysPermCode.getPermCodeId());
|
||||
sysPermCodePermMapper.deleteByExample(e);
|
||||
if (permIdSet != null) {
|
||||
List<SysPermCodePerm> sysPermCodePermList = new LinkedList<>();
|
||||
for (Long permId : permIdSet) {
|
||||
SysPermCodePerm permCodePerm = new SysPermCodePerm();
|
||||
permCodePerm.setPermCodeId(sysPermCode.getPermCodeId());
|
||||
permCodePerm.setPermId(permId);
|
||||
sysPermCodePermList.add(permCodePerm);
|
||||
}
|
||||
sysPermCodePermMapper.insertList(sysPermCodePermList);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定的权限字。
|
||||
*
|
||||
* @param permCodeId 权限字主键Id。
|
||||
* @return 删除成功返回true,否则false。
|
||||
*/
|
||||
@Transactional
|
||||
public boolean remove(Long permCodeId) {
|
||||
SysPermCode permCode = new SysPermCode();
|
||||
permCode.setPermCodeId(permCodeId);
|
||||
permCode.setDeletedFlag(GlobalDeletedFlag.DELETED);
|
||||
if (sysPermCodeMapper.updateByPrimaryKeySelective(permCode) != 1) {
|
||||
return false;
|
||||
}
|
||||
Example menuPermCodeExample = new Example(SysMenuPermCode.class);
|
||||
menuPermCodeExample.createCriteria().andEqualTo("permCodeId", permCodeId);
|
||||
sysMenuPermCodeMapper.deleteByExample(menuPermCodeExample);
|
||||
Example permCodePermExample = new Example(SysPermCodePerm.class);
|
||||
permCodePermExample.createCriteria().andEqualTo("permCodeId", permCodeId);
|
||||
sysPermCodePermMapper.deleteByExample(permCodePermExample);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定权限字对象数据,该对象将包含其关联数据。
|
||||
*
|
||||
* @param permCodeId 权限字主键Id。
|
||||
* @return 权限字对象。
|
||||
*/
|
||||
public SysPermCode getSysPermCodeWithRelation(Long permCodeId) {
|
||||
SysPermCode sysPermCode = this.getById(permCodeId);
|
||||
if (sysPermCode != null) {
|
||||
Example e = new Example(SysPermCodePerm.class);
|
||||
e.createCriteria().andEqualTo("permCodeId", permCodeId);
|
||||
List<SysPermCodePerm> sysPermCodePermList = sysPermCodePermMapper.selectByExample(e);
|
||||
if (sysPermCodePermList.size() > 0) {
|
||||
List<Long> permIdList =
|
||||
sysPermCodePermList.stream().map(SysPermCodePerm::getPermId).collect(Collectors.toList());
|
||||
sysPermCode.setPermIdList(permIdList);
|
||||
}
|
||||
}
|
||||
return sysPermCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定用户的权限字列表。
|
||||
*
|
||||
* @param loginName 精确匹配用户登录名。
|
||||
* @param permCode 模糊匹配的权限字名,LIKE %permCode%。
|
||||
* @return 权限字列表。
|
||||
*/
|
||||
public List<SysPermCode> getUserPermCodeListByFilter(String loginName, String permCode) {
|
||||
return sysPermCodeMapper.getUserPermCodeListByFilter(loginName, permCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取该菜单的权限字,及其权限字关联的权限资源列表。
|
||||
*
|
||||
* @param menuId 菜单Id。
|
||||
* @return 关联了权限资源的权限字列表。
|
||||
*/
|
||||
public List<Map<String, Object>> getPermCodeListByMenuId(Long menuId) {
|
||||
return sysPermCodeMapper.getPermCodeListByMenuId(menuId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断当前权限字是否存在下级权限字对象。
|
||||
*
|
||||
* @param permCodeId 权限字主键Id。
|
||||
* @return 存在返回true,否则false。
|
||||
*/
|
||||
public boolean hasChildren(Long permCodeId) {
|
||||
SysPermCode permCode = new SysPermCode();
|
||||
permCode.setParentId(permCodeId);
|
||||
return this.getCountByFilter(permCode) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证权限字对象关联的数据是否都合法。
|
||||
*
|
||||
* @param sysPermCode 当前操作的对象。
|
||||
* @param originalSysPermCode 原有对象。
|
||||
* @param permIdListString 逗号分隔的权限资源Id列表。
|
||||
* @return 验证结果。
|
||||
*/
|
||||
public VerifyResult verifyRelatedData(
|
||||
SysPermCode sysPermCode, SysPermCode originalSysPermCode, String permIdListString) {
|
||||
String errorMessage = null;
|
||||
JSONObject jsonObject = null;
|
||||
Map<String, Object> resultMap = new HashMap<>(2);
|
||||
do {
|
||||
if (this.needToVerify(sysPermCode, originalSysPermCode, SysPermCode::getParentId)) {
|
||||
if (getById(sysPermCode.getParentId()) == null) {
|
||||
errorMessage = "数据验证失败,关联的上级权限字并不存在,请刷新后重试!";
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (StringUtils.isNotBlank(permIdListString)) {
|
||||
Set<Long> permIdSet = Arrays.stream(
|
||||
permIdListString.split(",")).map(Long::valueOf).collect(Collectors.toSet());
|
||||
if (!sysPermService.existUniqueKeyList("permId", permIdSet)) {
|
||||
errorMessage = "数据验证失败,存在不合法的权限资源,请刷新后重试!";
|
||||
break;
|
||||
}
|
||||
jsonObject = new JSONObject();
|
||||
jsonObject.put("permIdSet", permIdSet);
|
||||
}
|
||||
} while (false);
|
||||
return VerifyResult.create(errorMessage, jsonObject);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
package com.orange.admin.upms.service;
|
||||
|
||||
import com.orange.admin.common.biz.util.BasicIdGenerator;
|
||||
import com.orange.admin.common.core.base.dao.BaseDaoMapper;
|
||||
import com.orange.admin.common.core.base.service.BaseService;
|
||||
import com.orange.admin.common.core.constant.GlobalDeletedFlag;
|
||||
import com.orange.admin.upms.dao.SysPermModuleMapper;
|
||||
import com.orange.admin.upms.model.SysPerm;
|
||||
import com.orange.admin.upms.model.SysPermModule;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 权限资源模块数据服务类。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
*/
|
||||
@Service
|
||||
public class SysPermModuleService extends BaseService<SysPermModule, Long> {
|
||||
|
||||
@Autowired
|
||||
private SysPermModuleMapper sysPermModuleMapper;
|
||||
@Autowired
|
||||
private SysPermService sysPermService;
|
||||
@Autowired
|
||||
private BasicIdGenerator idGenerator;
|
||||
|
||||
/**
|
||||
* 返回主对象的Mapper对象。
|
||||
*
|
||||
* @return 主对象的Mapper对象。
|
||||
*/
|
||||
@Override
|
||||
protected BaseDaoMapper<SysPermModule> mapper() {
|
||||
return sysPermModuleMapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存新增的权限资源模块对象。
|
||||
*
|
||||
* @param sysPermModule 新增的权限资源模块对象。
|
||||
* @return 新增后的权限资源模块对象。
|
||||
*/
|
||||
@Transactional
|
||||
public SysPermModule saveNew(SysPermModule sysPermModule) {
|
||||
sysPermModule.setModuleId(idGenerator.nextLongId());
|
||||
sysPermModule.setCreateTime(new Date());
|
||||
sysPermModule.setDeletedFlag(GlobalDeletedFlag.NORMAL);
|
||||
sysPermModuleMapper.insert(sysPermModule);
|
||||
return sysPermModule;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新权限资源模块对象。
|
||||
*
|
||||
* @param sysPermModule 更新的权限资源模块对象。
|
||||
* @param originalSysPermModule 原有的权限资源模块对象。
|
||||
* @return 更新成功返回true,否则false
|
||||
*/
|
||||
@Transactional
|
||||
public boolean update(SysPermModule sysPermModule, SysPermModule originalSysPermModule) {
|
||||
sysPermModule.setCreateTime(originalSysPermModule.getCreateTime());
|
||||
sysPermModule.setDeletedFlag(GlobalDeletedFlag.NORMAL);
|
||||
return sysPermModuleMapper.updateByPrimaryKey(sysPermModule) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定的权限资源模块。
|
||||
*
|
||||
* @param moduleId 权限资源模块主键Id。
|
||||
* @return 删除成功返回true,否则false。
|
||||
*/
|
||||
@Transactional
|
||||
public boolean remove(Long moduleId) {
|
||||
SysPermModule permModule = new SysPermModule();
|
||||
permModule.setModuleId(moduleId);
|
||||
permModule.setDeletedFlag(GlobalDeletedFlag.DELETED);
|
||||
return sysPermModuleMapper.updateByPrimaryKeySelective(permModule) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取权限模块资源及其关联的权限资源列表。
|
||||
*
|
||||
* @return 权限资源模块及其关联的权限资源列表。
|
||||
*/
|
||||
public List<SysPermModule> getPermModuleAndPermList() {
|
||||
return sysPermModuleMapper.getPermModuleAndPermList();
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否存在下级权限资源模块。
|
||||
*
|
||||
* @param moduleId 权限资源模块主键Id。
|
||||
* @return 存在返回true,否则false。
|
||||
*/
|
||||
public boolean hasChildren(Long moduleId) {
|
||||
SysPermModule permModule = new SysPermModule();
|
||||
permModule.setParentId(moduleId);
|
||||
return this.getCountByFilter(permModule) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否存在权限数据。
|
||||
*
|
||||
* @param moduleId 权限资源模块主键Id。
|
||||
* @return 存在返回true,否则false。
|
||||
*/
|
||||
public boolean hasModulePerms(Long moduleId) {
|
||||
SysPerm filter = new SysPerm();
|
||||
filter.setModuleId(moduleId);
|
||||
return sysPermService.getCountByFilter(filter) > 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,260 @@
|
||||
package com.orange.admin.upms.service;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.orange.admin.common.biz.util.BasicIdGenerator;
|
||||
import com.orange.admin.common.core.base.dao.BaseDaoMapper;
|
||||
import com.orange.admin.common.core.base.service.BaseService;
|
||||
import com.orange.admin.common.core.constant.GlobalDeletedFlag;
|
||||
import com.orange.admin.common.core.object.VerifyResult;
|
||||
import com.orange.admin.upms.dao.SysPermCodePermMapper;
|
||||
import com.orange.admin.upms.dao.SysPermMapper;
|
||||
import com.orange.admin.upms.model.SysPerm;
|
||||
import com.orange.admin.upms.model.SysPermCodePerm;
|
||||
import com.orange.admin.upms.model.SysPermModule;
|
||||
import com.orange.admin.upms.model.SysUser;
|
||||
import com.orange.admin.upms.model.constant.SysUserType;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.CachePut;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import tk.mybatis.mapper.entity.Example;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 权限资源数据服务类。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
*/
|
||||
@Service
|
||||
public class SysPermService extends BaseService<SysPerm, Long> {
|
||||
|
||||
@Autowired
|
||||
private SysPermMapper sysPermMapper;
|
||||
@Autowired
|
||||
private SysPermCodePermMapper sysPermCodePermMapper;
|
||||
@Autowired
|
||||
private SysPermModuleService sysPermModuleService;
|
||||
@Autowired
|
||||
private SysUserService sysUserService;
|
||||
@Autowired
|
||||
private BasicIdGenerator idGenerator;
|
||||
|
||||
/**
|
||||
* 返回主对象的Mapper对象。
|
||||
*
|
||||
* @return 主对象的Mapper对象。
|
||||
*/
|
||||
@Override
|
||||
protected BaseDaoMapper<SysPerm> mapper() {
|
||||
return sysPermMapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存新增的权限资源对象。
|
||||
*
|
||||
* @param perm 新增的权限资源对象。
|
||||
* @return 新增后的权限资源对象。
|
||||
*/
|
||||
@Transactional
|
||||
public SysPerm saveNew(SysPerm perm) {
|
||||
perm.setPermId(idGenerator.nextLongId());
|
||||
perm.setCreateTime(new Date());
|
||||
perm.setDeletedFlag(GlobalDeletedFlag.NORMAL);
|
||||
sysPermMapper.insert(perm);
|
||||
return perm;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新权限资源对象。
|
||||
*
|
||||
* @param perm 更新的权限资源对象。
|
||||
* @param originalPerm 更新的权限资源对象。
|
||||
* @return 更新成功返回true,否则false。
|
||||
*/
|
||||
@Transactional
|
||||
public boolean update(SysPerm perm, SysPerm originalPerm) {
|
||||
perm.setCreateTime(originalPerm.getCreateTime());
|
||||
perm.setDeletedFlag(GlobalDeletedFlag.NORMAL);
|
||||
return sysPermMapper.updateByPrimaryKeySelective(perm) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除权限资源。
|
||||
*
|
||||
* @param permId 权限资源主键Id。
|
||||
* @return 删除成功返回true,否则false。
|
||||
*/
|
||||
@Transactional
|
||||
public boolean remove(Long permId) {
|
||||
SysPerm perm = new SysPerm();
|
||||
perm.setPermId(permId);
|
||||
perm.setDeletedFlag(GlobalDeletedFlag.DELETED);
|
||||
if (sysPermMapper.updateByPrimaryKeySelective(perm) != 1) {
|
||||
return false;
|
||||
}
|
||||
Example e = new Example(SysPermCodePerm.class);
|
||||
e.createCriteria().andEqualTo("permId", permId);
|
||||
sysPermCodePermMapper.deleteByExample(e);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取权限数据列表。
|
||||
*
|
||||
* @param sysPermFilter 过滤对象。
|
||||
* @return 权限列表。
|
||||
*/
|
||||
public List<SysPerm> getPermListWithRelation(SysPerm sysPermFilter) {
|
||||
Example e = new Example(SysPerm.class);
|
||||
e.orderBy("permId");
|
||||
Example.Criteria c = e.createCriteria();
|
||||
if (ObjectUtil.isNotNull(sysPermFilter.getModuleId())) {
|
||||
c.andEqualTo("moduleId", sysPermFilter.getModuleId());
|
||||
}
|
||||
if (ObjectUtil.isNotNull(sysPermFilter.getUrl())) {
|
||||
c.andLike("url", "%" + sysPermFilter.getUrl() + "%");
|
||||
}
|
||||
c.andEqualTo("deletedFlag", GlobalDeletedFlag.NORMAL);
|
||||
List<SysPerm> permList = sysPermMapper.selectByExample(e);
|
||||
// 这里因为权限只有字典数据,所以仅仅做字典关联。
|
||||
this.buildRelationForDataList(permList, true);
|
||||
return permList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定用户的权限资源集合,并存储于缓存,从而提升后续读取效率。
|
||||
*
|
||||
* @param sessionId 用户会话Id。
|
||||
* @param userId 用户主键Id。
|
||||
* @return 当前用户权限集合。
|
||||
*/
|
||||
@Cacheable(value = "UserPermissionCache", key = "#sessionId", unless = "#result == null")
|
||||
public Set<String> getCacheableSysPermSetByUserId(String sessionId, Long userId) {
|
||||
// 这里可以防止非法的userId直接访问权限受限的url
|
||||
SysUser user = sysUserService.getById(userId);
|
||||
if (user == null) {
|
||||
return null;
|
||||
}
|
||||
// 管理员账户返回空对象,便于缓存的统一处理。
|
||||
return user.getUserType() == SysUserType.TYPE_ADMIN
|
||||
? new HashSet<>(1) : this.getSysPermSetByUserId(userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将指定用户的指定会话的权限集合存入缓存。
|
||||
*
|
||||
* @param sessionId 会话Id。
|
||||
* @param userId 用户主键Id。
|
||||
* @param isAdmin 是否是管理员。
|
||||
* @return 查询并缓存后的权限集合。
|
||||
*/
|
||||
@CachePut(value = "UserPermissionCache", key = "#sessionId")
|
||||
public Set<String> putUserSysPermCache(String sessionId, Long userId, boolean isAdmin) {
|
||||
// 管理员账户返回空对象,便于缓存的统一处理。
|
||||
return isAdmin ? new HashSet<>(1) : this.getSysPermSetByUserId(userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将指定会话的权限集合从缓存中移除。
|
||||
*
|
||||
* @param sessionId 会话Id。
|
||||
*/
|
||||
@CacheEvict(value = "UserPermissionCache", key = "#sessionId")
|
||||
public void removeUserSysPermCache(String sessionId) {
|
||||
// 空实现即可,只是通过注解将当前sessionId从cache中删除。
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定用户的权限集合,这里之所以为公有方法,因为spring cache的技术要求,私有方法数据不能缓存。
|
||||
*
|
||||
* @param userId 用户主键Id。
|
||||
* @return 用户权限集合。
|
||||
*/
|
||||
public Set<String> getSysPermSetByUserId(Long userId) {
|
||||
List<SysPerm> permList = this.getPermListByUserId(userId);
|
||||
return permList.stream().map(SysPerm::getUrl).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取与指定权限字关联的权限资源列表。
|
||||
*
|
||||
* @param permCodeId 关联的权限字主键Id。
|
||||
* @param orderBy 排序参数。
|
||||
* @return 与指定权限字Id关联的权限资源列表。
|
||||
*/
|
||||
public List<SysPerm> getPermListByPermCodeId(Long permCodeId, String orderBy) {
|
||||
return sysPermMapper.getPermListByPermCodeId(permCodeId, orderBy);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取与指定用户关联的权限资源列表。
|
||||
*
|
||||
* @param userId 关联的用户主键Id。
|
||||
* @return 与指定用户Id关联的权限资源列表。
|
||||
*/
|
||||
public List<SysPerm> getPermListByUserId(Long userId) {
|
||||
return sysPermMapper.getPermListByUserId(userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定用户的用户权限关联列表。
|
||||
*
|
||||
* @param loginName 精确匹配用户登录名。
|
||||
* @param moduleId 精确匹配权限模块Id。
|
||||
* @param url 模糊匹配的url过滤条件。
|
||||
* @return 用户权限关联列表。
|
||||
*/
|
||||
public List<Map<String, Object>> getUserPermListByFilter(String loginName, Long moduleId, String url) {
|
||||
return sysPermMapper.getUserPermListByFilter(loginName, moduleId, url);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定权限资源的权限用户关联数据列表。
|
||||
*
|
||||
* @param permId 权限资源主键Id。
|
||||
* @return 用户和权限资源关联列表。
|
||||
*/
|
||||
public List<Map<String, Object>> getPermUserListById(Long permId) {
|
||||
return sysPermMapper.getPermUserListById(permId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定权限资源的权限角色关联数据列表。
|
||||
*
|
||||
* @param permId 权限资源主键Id。
|
||||
* @return 角色和权限资源关联列表。
|
||||
*/
|
||||
public List<Map<String, Object>> getPermRoleListById(Long permId) {
|
||||
return sysPermMapper.getPermRoleListById(permId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证权限资源对象关联的数据是否都合法。
|
||||
*
|
||||
* @param sysPerm 当前操作的对象。
|
||||
* @param originalSysPerm 原有对象。
|
||||
* @return 验证结果。
|
||||
*/
|
||||
public VerifyResult verifyRelatedData(SysPerm sysPerm, SysPerm originalSysPerm) {
|
||||
String errorMessage = null;
|
||||
JSONObject jsonObject = null;
|
||||
do {
|
||||
if (this.needToVerify(sysPerm, originalSysPerm, SysPerm::getModuleId)) {
|
||||
SysPermModule permModule = sysPermModuleService.getById(sysPerm.getModuleId());
|
||||
if (permModule == null) {
|
||||
errorMessage = "数据验证失败,关联的权限模块Id并不存在,请刷新后重试!";
|
||||
break;
|
||||
}
|
||||
jsonObject = new JSONObject();
|
||||
jsonObject.put("permModule", permModule);
|
||||
}
|
||||
} while (false);
|
||||
return VerifyResult.create(errorMessage, jsonObject);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.orange.admin.upms.service;
|
||||
|
||||
import com.orange.admin.common.core.base.dao.BaseDaoMapper;
|
||||
import com.orange.admin.common.core.base.service.BaseService;
|
||||
import com.orange.admin.upms.dao.SysPermWhitelistMapper;
|
||||
import com.orange.admin.upms.model.SysPermWhitelist;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 权限资源白名单数据服务类。
|
||||
* 白名单中的权限资源,可以不受权限控制,任何用户皆可访问,一般用于常用的字典数据列表接口。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
*/
|
||||
@Service
|
||||
public class SysPermWhitelistService extends BaseService<SysPermWhitelist, String> {
|
||||
|
||||
@Autowired
|
||||
private SysPermWhitelistMapper sysPermWhitelistMapper;
|
||||
|
||||
/**
|
||||
* 返回主对象的Mapper对象。
|
||||
*
|
||||
* @return 主对象的Mapper对象。
|
||||
*/
|
||||
@Override
|
||||
protected BaseDaoMapper<SysPermWhitelist> mapper() {
|
||||
return sysPermWhitelistMapper;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,247 @@
|
||||
package com.orange.admin.upms.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.orange.admin.common.biz.util.BasicIdGenerator;
|
||||
import com.orange.admin.common.core.base.dao.BaseDaoMapper;
|
||||
import com.orange.admin.common.core.base.service.BaseService;
|
||||
import com.orange.admin.common.core.constant.GlobalDeletedFlag;
|
||||
import com.orange.admin.common.core.object.TokenData;
|
||||
import com.orange.admin.common.core.object.VerifyResult;
|
||||
import com.orange.admin.upms.dao.SysRoleMapper;
|
||||
import com.orange.admin.upms.dao.SysRoleMenuMapper;
|
||||
import com.orange.admin.upms.dao.SysUserRoleMapper;
|
||||
import com.orange.admin.upms.model.SysRole;
|
||||
import com.orange.admin.upms.model.SysRoleMenu;
|
||||
import com.orange.admin.upms.model.SysUserRole;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import tk.mybatis.mapper.entity.Example;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 角色数据服务类。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
*/
|
||||
@Service
|
||||
public class SysRoleService extends BaseService<SysRole, Long> {
|
||||
|
||||
@Autowired
|
||||
private SysRoleMapper sysRoleMapper;
|
||||
@Autowired
|
||||
private SysRoleMenuMapper sysRoleMenuMapper;
|
||||
@Autowired
|
||||
private SysUserRoleMapper sysUserRoleMapper;
|
||||
@Autowired
|
||||
private SysMenuService sysMenuService;
|
||||
@Autowired
|
||||
private BasicIdGenerator idGenerator;
|
||||
|
||||
/**
|
||||
* 返回主对象的Mapper对象。
|
||||
*
|
||||
* @return 主对象的Mapper对象。
|
||||
*/
|
||||
@Override
|
||||
protected BaseDaoMapper<SysRole> mapper() {
|
||||
return sysRoleMapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存新增的角色对象。
|
||||
*
|
||||
* @param role 新增的角色对象。
|
||||
* @param menuIdSet 菜单Id列表。
|
||||
* @return 新增后的角色对象。
|
||||
*/
|
||||
@Transactional
|
||||
public SysRole saveNew(SysRole role, Set<Long> menuIdSet) {
|
||||
role.setRoleId(idGenerator.nextLongId());
|
||||
TokenData tokenData = TokenData.takeFromRequest();
|
||||
role.setCreateUserId(tokenData.getUserId());
|
||||
role.setCreateUsername(tokenData.getShowName());
|
||||
Date now = new Date();
|
||||
role.setCreateTime(now);
|
||||
role.setUpdateTime(now);
|
||||
role.setDeletedFlag(GlobalDeletedFlag.NORMAL);
|
||||
sysRoleMapper.insert(role);
|
||||
if (menuIdSet != null) {
|
||||
List<SysRoleMenu> roleMenuList = new LinkedList<>();
|
||||
for (Long menuId : menuIdSet) {
|
||||
SysRoleMenu roleMenu = new SysRoleMenu();
|
||||
roleMenu.setRoleId(role.getRoleId());
|
||||
roleMenu.setMenuId(menuId);
|
||||
roleMenuList.add(roleMenu);
|
||||
}
|
||||
sysRoleMenuMapper.insertList(roleMenuList);
|
||||
}
|
||||
return role;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新角色对象。
|
||||
*
|
||||
* @param role 更新的角色对象。
|
||||
* @param originalRole 原有的角色对象。
|
||||
* @param menuIdSet 菜单Id列表。
|
||||
* @return 更新成功返回true,否则false。
|
||||
*/
|
||||
@Transactional
|
||||
public boolean update(SysRole role, SysRole originalRole, Set<Long> menuIdSet) {
|
||||
SysRole updateRole = new SysRole();
|
||||
BeanUtils.copyProperties(role, updateRole, "createUserId", "createUsername", "createTime");
|
||||
updateRole.setUpdateTime(new Date());
|
||||
updateRole.setDeletedFlag(GlobalDeletedFlag.NORMAL);
|
||||
if (sysRoleMapper.updateByPrimaryKeySelective(updateRole) != 1) {
|
||||
return false;
|
||||
}
|
||||
Example e = new Example(SysRoleMenu.class);
|
||||
e.createCriteria().andEqualTo("roleId", role.getRoleId());
|
||||
sysRoleMenuMapper.deleteByExample(e);
|
||||
if (menuIdSet != null) {
|
||||
List<SysRoleMenu> roleMenuList = new LinkedList<>();
|
||||
for (Long menuId : menuIdSet) {
|
||||
SysRoleMenu roleMenu = new SysRoleMenu();
|
||||
roleMenu.setRoleId(role.getRoleId());
|
||||
roleMenu.setMenuId(menuId);
|
||||
roleMenuList.add(roleMenu);
|
||||
}
|
||||
sysRoleMenuMapper.insertList(roleMenuList);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定角色。
|
||||
*
|
||||
* @param roleId 角色主键Id。
|
||||
* @return 删除成功返回true,否则false。
|
||||
*/
|
||||
@Transactional
|
||||
public boolean remove(Long roleId) {
|
||||
SysRole role = new SysRole();
|
||||
role.setRoleId(roleId);
|
||||
role.setDeletedFlag(GlobalDeletedFlag.DELETED);
|
||||
if (sysRoleMapper.updateByPrimaryKeySelective(role) != 1) {
|
||||
return false;
|
||||
}
|
||||
Example sysRoleMenuExample = new Example(SysRoleMenu.class);
|
||||
sysRoleMenuExample.createCriteria().andEqualTo("roleId", roleId);
|
||||
sysRoleMenuMapper.deleteByExample(sysRoleMenuExample);
|
||||
Example sysUserRoleExample = new Example(SysUserRole.class);
|
||||
sysUserRoleExample.createCriteria().andEqualTo("roleId", roleId);
|
||||
sysUserRoleMapper.deleteByExample(sysUserRoleExample);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取角色列表。
|
||||
*
|
||||
* @param filter 角色过滤对象。
|
||||
* @param orderBy 排序参数。
|
||||
* @return 角色列表。
|
||||
*/
|
||||
public List<SysRole> getSysRoleList(SysRole filter, String orderBy) {
|
||||
return sysRoleMapper.getSysRoleList(filter, orderBy);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定角色对象。
|
||||
*
|
||||
* @param roleId 角色主键Id。
|
||||
* @return 查询后的角色对象。
|
||||
*/
|
||||
public SysRole getSysRoleWithRelation(Long roleId) {
|
||||
SysRole sysRole = this.getById(roleId);
|
||||
if (sysRole != null) {
|
||||
Example e = new Example(SysRoleMenu.class);
|
||||
e.createCriteria().andEqualTo("roleId", roleId);
|
||||
List<SysRoleMenu> sysRoleMenuList = sysRoleMenuMapper.selectByExample(e);
|
||||
if (sysRoleMenuList.size() > 0) {
|
||||
List<Long> menuIdList =
|
||||
sysRoleMenuList.stream().map(SysRoleMenu::getMenuId).collect(Collectors.toList());
|
||||
sysRole.setMenuIdList(menuIdList);
|
||||
}
|
||||
}
|
||||
return sysRole;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过权限字Id获取拥有改权限的所有角色。
|
||||
* 开发人员调试用接口。
|
||||
*
|
||||
* @param permCodeId 查询的权限字Id。
|
||||
* @return 符合条件的角色列表。
|
||||
*/
|
||||
public List<SysRole> getSysRoleListByPermCodeId(Long permCodeId) {
|
||||
return sysRoleMapper.getSysRoleListByPermCodeId(permCodeId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过权限资源url,模糊搜索拥有改权限的所有角色。
|
||||
* 开发人员调试用接口。
|
||||
*
|
||||
* @param url 用于模糊搜索的url。
|
||||
* @return 符合条件的角色列表。
|
||||
*/
|
||||
public List<SysRole> getSysRoleListByPerm(String url) {
|
||||
return sysRoleMapper.getSysRoleListByPerm(url);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量新增用户角色关联。
|
||||
*
|
||||
* @param userRoleList 用户角色关系数据列表。
|
||||
*/
|
||||
@Transactional
|
||||
public void addUserRoleList(List<SysUserRole> userRoleList) {
|
||||
sysUserRoleMapper.addUserRoleList(userRoleList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除指定用户和指定角色的关联关系。
|
||||
*
|
||||
* @param roleId 角色主键Id。
|
||||
* @param userId 用户主键Id。
|
||||
* @return 移除成功返回true,否则false。
|
||||
*/
|
||||
@Transactional
|
||||
public boolean removeUserRole(Long roleId, Long userId) {
|
||||
SysUserRole userRole = new SysUserRole();
|
||||
userRole.setRoleId(roleId);
|
||||
userRole.setUserId(userId);
|
||||
return sysUserRoleMapper.delete(userRole) == 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证角色对象关联的数据是否都合法。
|
||||
*
|
||||
* @param sysRole 当前操作的对象。
|
||||
* @param originalSysRole 原有对象。
|
||||
* @param menuIdListString 逗号分隔的menuId列表。
|
||||
* @return 验证结果。
|
||||
*/
|
||||
public VerifyResult verifyRelatedData(SysRole sysRole, SysRole originalSysRole, String menuIdListString) {
|
||||
String errorMessage = null;
|
||||
JSONObject jsonObject = null;
|
||||
do {
|
||||
if (StringUtils.isNotBlank(menuIdListString)) {
|
||||
Set<Long> menuIdSet = Arrays.stream(
|
||||
menuIdListString.split(",")).map(Long::valueOf).collect(Collectors.toSet());
|
||||
if (!sysMenuService.existUniqueKeyList("menuId", menuIdSet)) {
|
||||
errorMessage = "数据验证失败,存在不合法的菜单权限,请刷新后重试!";
|
||||
break;
|
||||
}
|
||||
jsonObject = new JSONObject();
|
||||
jsonObject.put("menuIdSet", menuIdSet);
|
||||
}
|
||||
} while (false);
|
||||
return VerifyResult.create(errorMessage, jsonObject);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,342 @@
|
||||
package com.orange.admin.upms.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.orange.admin.upms.dao.*;
|
||||
import com.orange.admin.upms.model.*;
|
||||
import com.orange.admin.upms.model.constant.SysUserStatus;
|
||||
import com.orange.admin.common.core.base.service.BaseService;
|
||||
import com.orange.admin.common.core.base.dao.BaseDaoMapper;
|
||||
import com.orange.admin.common.core.constant.GlobalDeletedFlag;
|
||||
import com.orange.admin.common.core.object.TokenData;
|
||||
import com.orange.admin.common.core.object.MyWhereCriteria;
|
||||
import com.orange.admin.common.core.object.VerifyResult;
|
||||
import com.orange.admin.common.core.util.MyCommonUtil;
|
||||
import com.orange.admin.common.biz.util.BasicIdGenerator;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import tk.mybatis.mapper.entity.Example;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 用户管理数据操作服务类。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
*/
|
||||
@Service
|
||||
public class SysUserService extends BaseService<SysUser, Long> {
|
||||
|
||||
@Autowired
|
||||
private SysUserMapper sysUserMapper;
|
||||
@Autowired
|
||||
private SysUserRoleMapper sysUserRoleMapper;
|
||||
@Autowired
|
||||
private SysDataPermUserMapper sysDataPermUserMapper;
|
||||
@Autowired
|
||||
private SysRoleService sysRoleService;
|
||||
@Autowired
|
||||
private SysDataPermService sysDataPermService;
|
||||
@Autowired
|
||||
private BasicIdGenerator idGenerator;
|
||||
|
||||
/**
|
||||
* 返回当前Service的主表Mapper对象。
|
||||
*
|
||||
* @return 主表Mapper对象。
|
||||
*/
|
||||
@Override
|
||||
protected BaseDaoMapper<SysUser> mapper() {
|
||||
return sysUserMapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定登录名的用户对象。
|
||||
*
|
||||
* @param loginName 指定登录用户名。
|
||||
* @return 用户对象。
|
||||
*/
|
||||
public SysUser getSysUserByLoginName(String loginName) {
|
||||
Example e = new Example(SysUser.class);
|
||||
Example.Criteria c = e.createCriteria();
|
||||
c.andEqualTo("loginName", loginName);
|
||||
c.andEqualTo("deletedFlag", GlobalDeletedFlag.NORMAL);
|
||||
return sysUserMapper.selectOneByExample(e);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存新增的用户对象。
|
||||
*
|
||||
* @param user 新增的用户对象。
|
||||
* @param roleIdSet 用户角色Id集合。
|
||||
* @param dataPermIdSet 数据权限Id集合。
|
||||
* @param passwdSalt 密码的盐。
|
||||
* @return 新增后的用户对象。
|
||||
*/
|
||||
@Transactional
|
||||
public SysUser saveNew(SysUser user, Set<Long> roleIdSet, Set<Long> dataPermIdSet, String passwdSalt) {
|
||||
user.setUserId(idGenerator.nextLongId());
|
||||
user.setPassword(MyCommonUtil.encrptedPassword(user.getPassword(), passwdSalt));
|
||||
user.setUserStatus(SysUserStatus.STATUS_NORMAL);
|
||||
user.setDeletedFlag(GlobalDeletedFlag.NORMAL);
|
||||
TokenData tokenData = TokenData.takeFromRequest();
|
||||
user.setCreateUserId(tokenData.getUserId());
|
||||
user.setCreateUsername(tokenData.getShowName());
|
||||
Date now = new Date();
|
||||
user.setCreateTime(now);
|
||||
user.setUpdateTime(now);
|
||||
sysUserMapper.insert(user);
|
||||
if (CollectionUtils.isNotEmpty(roleIdSet)) {
|
||||
List<SysUserRole> userRoleList = new LinkedList<>();
|
||||
for (Long roleId : roleIdSet) {
|
||||
SysUserRole userRole = new SysUserRole();
|
||||
userRole.setUserId(user.getUserId());
|
||||
userRole.setRoleId(roleId);
|
||||
userRoleList.add(userRole);
|
||||
}
|
||||
sysUserRoleMapper.insertList(userRoleList);
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(dataPermIdSet)) {
|
||||
List<SysDataPermUser> dataPermUserList = new LinkedList<>();
|
||||
for (Long dataPermId : dataPermIdSet) {
|
||||
SysDataPermUser dataPermUser = new SysDataPermUser();
|
||||
dataPermUser.setDataPermId(dataPermId);
|
||||
dataPermUser.setUserId(user.getUserId());
|
||||
dataPermUserList.add(dataPermUser);
|
||||
}
|
||||
sysDataPermUserMapper.insertList(dataPermUserList);
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新用户对象。
|
||||
*
|
||||
* @param user 更新的用户对象。
|
||||
* @param originalUser 原有的用户对象。
|
||||
* @param roleIdSet 用户角色Id列表。
|
||||
* @param dataPermIdSet 数据权限Id集合。
|
||||
* @return 更新成功返回true,否则false。
|
||||
*/
|
||||
@Transactional
|
||||
public boolean update(SysUser user, SysUser originalUser, Set<Long> roleIdSet, Set<Long> dataPermIdSet) {
|
||||
user.setLoginName(originalUser.getLoginName());
|
||||
user.setPassword(originalUser.getPassword());
|
||||
user.setCreateUserId(originalUser.getCreateUserId());
|
||||
user.setCreateUsername(originalUser.getCreateUsername());
|
||||
user.setCreateTime(originalUser.getCreateTime());
|
||||
user.setUpdateTime(new Date());
|
||||
if (sysUserMapper.updateByPrimaryKeySelective(user) != 1) {
|
||||
return false;
|
||||
}
|
||||
// 先删除原有的User-Role关联关系,再重新插入新的关联关系
|
||||
Example e = new Example(SysUserRole.class);
|
||||
e.createCriteria().andEqualTo("userId", user.getUserId());
|
||||
sysUserRoleMapper.deleteByExample(e);
|
||||
if (CollectionUtils.isNotEmpty(roleIdSet)) {
|
||||
List<SysUserRole> userRoleList = new LinkedList<>();
|
||||
for (Long roleId : roleIdSet) {
|
||||
SysUserRole userRole = new SysUserRole();
|
||||
userRole.setUserId(user.getUserId());
|
||||
userRole.setRoleId(roleId);
|
||||
userRoleList.add(userRole);
|
||||
}
|
||||
sysUserRoleMapper.insertList(userRoleList);
|
||||
}
|
||||
// 先删除原有的DataPerm-User关联关系,在重新插入新的关联关系
|
||||
Example e2 = new Example(SysDataPermUser.class);
|
||||
e2.createCriteria().andEqualTo("userId", user.getUserId());
|
||||
sysDataPermUserMapper.deleteByExample(e2);
|
||||
if (CollectionUtils.isNotEmpty(dataPermIdSet)) {
|
||||
List<SysDataPermUser> dataPermUserList = new LinkedList<>();
|
||||
for (Long dataPermId : dataPermIdSet) {
|
||||
SysDataPermUser dataPermUser = new SysDataPermUser();
|
||||
dataPermUser.setDataPermId(dataPermId);
|
||||
dataPermUser.setUserId(user.getUserId());
|
||||
dataPermUserList.add(dataPermUser);
|
||||
}
|
||||
sysDataPermUserMapper.insertList(dataPermUserList);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置用户密码。
|
||||
* @param userId 用户主键Id。
|
||||
* @param defaultPasswd 缺省密码。
|
||||
* @param passwdSalt 密码的盐。
|
||||
* @return 成功返回true,否则false。
|
||||
*/
|
||||
@Transactional
|
||||
public boolean resetPassword(Long userId, String defaultPasswd, String passwdSalt) {
|
||||
Example e = new Example(SysUser.class);
|
||||
e.createCriteria().andEqualTo("userId", userId);
|
||||
e.createCriteria().andEqualTo("deletedFlag", GlobalDeletedFlag.NORMAL);
|
||||
SysUser updatedUser = new SysUser();
|
||||
updatedUser.setPassword(MyCommonUtil.encrptedPassword(defaultPasswd, passwdSalt));
|
||||
return sysUserMapper.updateByExampleSelective(updatedUser, e) == 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定数据。
|
||||
*
|
||||
* @param userId 主键Id。
|
||||
* @return 成功返回true,否则false。
|
||||
*/
|
||||
@Transactional
|
||||
public boolean remove(Long userId) {
|
||||
Example sysUserExample = new Example(SysUser.class);
|
||||
Example.Criteria c = sysUserExample.createCriteria();
|
||||
c.andEqualTo("userId", userId);
|
||||
c.andEqualTo("deletedFlag", GlobalDeletedFlag.NORMAL);
|
||||
// 这里先删除主数据
|
||||
SysUser deletedObject = new SysUser();
|
||||
deletedObject.setDeletedFlag(GlobalDeletedFlag.DELETED);
|
||||
if (sysUserMapper.updateByExampleSelective(deletedObject, sysUserExample) == 0) {
|
||||
return false;
|
||||
}
|
||||
// 这里可继续删除关联数据。
|
||||
Example userRoleExample = new Example(SysUserRole.class);
|
||||
userRoleExample.createCriteria().andEqualTo("userId", userId);
|
||||
sysUserRoleMapper.deleteByExample(userRoleExample);
|
||||
Example dataPermUserExample = new Example(SysDataPermUser.class);
|
||||
dataPermUserExample.createCriteria().andEqualTo("userId", userId);
|
||||
sysDataPermUserMapper.deleteByExample(dataPermUserExample);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定用户的详情数据。
|
||||
*
|
||||
* @param userId 用户主键Id。
|
||||
* @return 用户详情数据。
|
||||
*/
|
||||
@Override
|
||||
public SysUser getByIdWithRelation(Long userId) {
|
||||
SysUser user = super.getByIdWithRelation(userId);
|
||||
if (user != null) {
|
||||
user.setRoleIdList(sysUserRoleMapper.getRoleIdListByUserId(userId));
|
||||
user.setDataPermIdList(sysDataPermUserMapper.getDataPermIdListByUserId(userId));
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单表查询结果。由于没有关联数据查询,因此在仅仅获取单表数据的场景下,效率更高。
|
||||
* 如果需要同时获取关联数据,请移步(getSysUserListWithRelation)方法。
|
||||
*
|
||||
* @param filter 过滤对象。
|
||||
* @param orderBy 排序参数。
|
||||
* @return 查询结果集。
|
||||
*/
|
||||
public List<SysUser> getSysUserList(SysUser filter, String orderBy) {
|
||||
return sysUserMapper.getSysUserList(filter, orderBy);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取主表的查询结果,以及主表关联的字典数据和一对一从表数据,以及一对一从表的字典数据。
|
||||
* 如果仅仅需要获取主表数据,请移步(getSysUserList),以便获取更好的查询性能。
|
||||
*
|
||||
* @param filter 主表过滤对象。
|
||||
* @param orderBy 排序参数。
|
||||
* @return 查询结果集。
|
||||
*/
|
||||
public List<SysUser> getSysUserListWithRelation(SysUser filter, String orderBy) {
|
||||
List<SysUser> resultList = sysUserMapper.getSysUserList(filter, orderBy);
|
||||
Map<String, List<MyWhereCriteria>> criteriaMap = buildAggregationAdditionalWhereCriteria();
|
||||
this.buildAllRelationForDataList(resultList, false, criteriaMap);
|
||||
return resultList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定角色的用户列表。
|
||||
*
|
||||
* @param roleId 角色主键Id。
|
||||
* @param filter 用户过滤对象。
|
||||
* @param orderBy 排序参数。
|
||||
* @return 用户列表。
|
||||
*/
|
||||
public List<SysUser> getSysUserListByRoleId(Long roleId, SysUser filter, String orderBy) {
|
||||
return sysUserMapper.getSysUserListByRoleId(roleId, filter, orderBy);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取不属于指定角色的用户列表。
|
||||
*
|
||||
* @param roleId 角色主键Id。
|
||||
* @param filter 用户过滤对象。
|
||||
* @param orderBy 排序参数。
|
||||
* @return 用户列表。
|
||||
*/
|
||||
public List<SysUser> getNotInSysUserListByRoleId(Long roleId, SysUser filter, String orderBy) {
|
||||
return sysUserMapper.getNotInSysUserListByRoleId(roleId, filter, orderBy);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定数据权限的用户列表。
|
||||
*
|
||||
* @param dataPermId 数据权限主键Id。
|
||||
* @param filter 用户过滤对象。
|
||||
* @param orderBy 排序参数。
|
||||
* @return 用户列表。
|
||||
*/
|
||||
public List<SysUser> getSysUserListByDataPermId(Long dataPermId, SysUser filter, String orderBy) {
|
||||
return sysUserMapper.getSysUserListByDataPermId(dataPermId, filter, orderBy);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取不属于指定数据权限的用户列表。
|
||||
*
|
||||
* @param dataPermId 数据权限主键Id。
|
||||
* @param filter 用户过滤对象。
|
||||
* @param orderBy 排序参数。
|
||||
* @return 用户列表。
|
||||
*/
|
||||
public List<SysUser> getNotInSysUserListByDataPermId(Long dataPermId, SysUser filter, String orderBy) {
|
||||
return sysUserMapper.getNotInSysUserListByDataPermId(dataPermId, filter, orderBy);
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证用户对象关联的数据是否都合法。
|
||||
*
|
||||
* @param sysUser 当前操作的对象。
|
||||
* @param originalSysUser 原有对象。
|
||||
* @param roleIdListString 逗号分隔的角色Id列表字符串。
|
||||
* @param dataPermIdListString 逗号分隔的数据权限Id列表字符串。
|
||||
* @return 验证结果。
|
||||
*/
|
||||
public VerifyResult verifyRelatedData(
|
||||
SysUser sysUser, SysUser originalSysUser, String roleIdListString, String dataPermIdListString) {
|
||||
String errorMessage = null;
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
do {
|
||||
if (StringUtils.isBlank(roleIdListString)) {
|
||||
errorMessage = "数据验证失败,用户的角色数据不能为空!";
|
||||
break;
|
||||
}
|
||||
Set<Long> roleIdSet = Arrays.stream(
|
||||
roleIdListString.split(",")).map(Long::valueOf).collect(Collectors.toSet());
|
||||
if (!sysRoleService.existUniqueKeyList("roleId", roleIdSet)) {
|
||||
errorMessage = "数据验证失败,存在不合法的用户角色,请刷新后重试!";
|
||||
break;
|
||||
}
|
||||
jsonObject.put("roleIdSet", roleIdSet);
|
||||
if (StringUtils.isBlank(dataPermIdListString)) {
|
||||
errorMessage = "数据验证失败,用户的数据权限不能为空!";
|
||||
break;
|
||||
}
|
||||
Set<Long> dataPermIdSet = Arrays.stream(
|
||||
dataPermIdListString.split(",")).map(Long::valueOf).collect(Collectors.toSet());
|
||||
if (!sysDataPermService.existUniqueKeyList("dataPermId", dataPermIdSet)) {
|
||||
errorMessage = "数据验证失败,存在不合法的数据权限,请刷新后重试!";
|
||||
break;
|
||||
}
|
||||
jsonObject.put("dataPermIdSet", dataPermIdSet);
|
||||
} while (false);
|
||||
return VerifyResult.create(errorMessage, jsonObject);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,189 @@
|
||||
logging:
|
||||
level:
|
||||
# 这里设置的日志级别优先于log4j2.xml文件Loggers中的日志级别。
|
||||
com.orange.admin: info
|
||||
|
||||
server:
|
||||
tomcat:
|
||||
uri-encoding: UTF-8
|
||||
max-threads: 100
|
||||
min-spare-threads: 10
|
||||
port: 8082
|
||||
|
||||
# spring相关配置
|
||||
spring:
|
||||
application:
|
||||
name: application
|
||||
profiles:
|
||||
active: dev
|
||||
servlet:
|
||||
multipart:
|
||||
max-file-size: 50MB
|
||||
max-request-size: 50MB
|
||||
http:
|
||||
converters:
|
||||
preferred-json-mapper: fastjson
|
||||
encoding:
|
||||
force: true
|
||||
charset: UTF-8
|
||||
enabled: true
|
||||
freemarker:
|
||||
template-loader-path: classpath:/template/
|
||||
cache: false
|
||||
charset: UTF-8
|
||||
check-template-location: true
|
||||
content-type: text/html
|
||||
expose-request-attributes: false
|
||||
expose-session-attributes: false
|
||||
request-context-attribute: request
|
||||
suffix: .ftl
|
||||
|
||||
# mybatis的基本配置
|
||||
mybatis:
|
||||
mapperLocations: classpath:com/orange/admin/*/dao/mapper/*Mapper.xml
|
||||
typeAliasesPackage: com.orange.admin.*.model
|
||||
|
||||
# mybatis的通用mapper的配置
|
||||
mapper:
|
||||
mappers: tk.mybatis.mapper.common.Mapper,tk.mybatis.mapper.additional.insert.InsertListMapper
|
||||
not-empty: false
|
||||
identity: MYSQL
|
||||
|
||||
# 自动分页的配置
|
||||
pagehelper:
|
||||
helperDialect: mysql
|
||||
reasonable: true
|
||||
supportMethodsArguments: false
|
||||
params: count=countSql
|
||||
|
||||
# 暴露监控端点
|
||||
management:
|
||||
endpoints:
|
||||
web:
|
||||
exposure:
|
||||
include: '*'
|
||||
endpoint:
|
||||
health:
|
||||
show-details: always
|
||||
configprops:
|
||||
# 在/actuator/configprops中,所有包含password的配置,将用 * 隐藏。
|
||||
# 如果不想隐藏任何配置项的值,可以直接使用如下被注释的空值。
|
||||
# keys-to-sanitize:
|
||||
keys-to-sanitize: password
|
||||
server:
|
||||
servlet:
|
||||
context-path: "/"
|
||||
|
||||
# 开发数据库相关配置
|
||||
---
|
||||
spring:
|
||||
profiles: dev
|
||||
datasource:
|
||||
type: com.alibaba.druid.pool.DruidDataSource
|
||||
druid:
|
||||
url: jdbc:mysql://localhost:3306/zz-orange-admin?characterEncoding=utf8&useSSL=true&serverTimezone=Asia/Shanghai
|
||||
username: root
|
||||
password: 123456
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
name: application
|
||||
initialSize: 10
|
||||
minIdle: 10
|
||||
maxActive: 50
|
||||
maxWait: 60000
|
||||
timeBetweenEvictionRunsMillis: 60000
|
||||
minEvictableIdleTimeMillis: 300000
|
||||
poolPreparedStatements: true
|
||||
maxPoolPreparedStatementPerConnectionSize: 20
|
||||
maxOpenPreparedStatements: 20
|
||||
validationQuery: SELECT 'x'
|
||||
testWhileIdle: true
|
||||
testOnBorrow: false
|
||||
testOnReturn: false
|
||||
connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
|
||||
filters: stat,wall
|
||||
useGlobalDataSourceStat: true
|
||||
web-stat-filter:
|
||||
enabled: true
|
||||
url-pattern: /*
|
||||
exclusions: "*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*"
|
||||
stat-view-servlet:
|
||||
enabled: true
|
||||
urlPattern: /druid/*
|
||||
resetEnable: true
|
||||
|
||||
application:
|
||||
# common-biz 主要包含通用配置项,由common-biz包的CommonBizConfig读取。
|
||||
common-biz:
|
||||
# Snowflake 分布式Id生成算法所需的WorkNode参数值。
|
||||
snowflakeWorkNode: 1
|
||||
# Jwt令牌加密的签名值。
|
||||
tokenSigningKey: OrangeAdmin
|
||||
# Jwt令牌在Http Header中的键名称。
|
||||
tokenHeaderKey: Authorization
|
||||
# Jwt令牌刷新后在Http Header中的键名称。
|
||||
refreshedTokenHeaderKey: RefreshedToken
|
||||
# 密码加密的盐值。
|
||||
passwordSalt: OrangeAdmin-passwd-salt
|
||||
# 初始化密码。
|
||||
defaultUserPassword: 123456
|
||||
# 缺省的文件上传根目录。
|
||||
uploadFileBaseDir: ./upload-files/app
|
||||
# 跨域的IP白名单列表,多个IP之间逗号分隔(* 表示全部信任,空白表示禁用跨域信任)。
|
||||
credentialIpList: "*"
|
||||
|
||||
# 发布数据库相关配置
|
||||
---
|
||||
spring:
|
||||
profiles: product
|
||||
datasource:
|
||||
type: com.alibaba.druid.pool.DruidDataSource
|
||||
druid:
|
||||
url: jdbc:mysql://localhost:3306/zz-orange-admin?characterEncoding=utf8&useSSL=true&serverTimezone=Asia/Shanghai
|
||||
username: root
|
||||
password: 123456
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
name: application
|
||||
initialSize: 10
|
||||
minIdle: 10
|
||||
maxActive: 50
|
||||
maxWait: 60000
|
||||
timeBetweenEvictionRunsMillis: 60000
|
||||
minEvictableIdleTimeMillis: 300000
|
||||
poolPreparedStatements: true
|
||||
maxPoolPreparedStatementPerConnectionSize: 20
|
||||
maxOpenPreparedStatements: 20
|
||||
validationQuery: SELECT 'x'
|
||||
testWhileIdle: true
|
||||
testOnBorrow: false
|
||||
testOnReturn: false
|
||||
connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
|
||||
filters: stat,wall
|
||||
useGlobalDataSourceStat: true
|
||||
web-stat-filter:
|
||||
enabled: true
|
||||
url-pattern: /*
|
||||
exclusions: "*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*"
|
||||
stat-view-servlet:
|
||||
enabled: true
|
||||
urlPattern: /druid/*
|
||||
resetEnable: true
|
||||
|
||||
application:
|
||||
# common-biz 主要包含通用配置项,由common-biz包的CommonBizConfig读取。
|
||||
common-biz:
|
||||
# Snowflake 分布式Id生成算法所需的WorkNode参数值。
|
||||
snowflakeWorkNode: 1
|
||||
# Jwt令牌加密的签名值。
|
||||
tokenSigningKey: OrangeAdmin
|
||||
# Jwt令牌在Http Header中的键名称。
|
||||
tokenHeaderKey: Authorization
|
||||
# Jwt令牌刷新后在Http Header中的键名称。
|
||||
refreshedTokenHeaderKey: RefreshedToken
|
||||
# 密码加密的盐值。
|
||||
passwordSalt: OrangeAdmin-passwd-salt
|
||||
# 初始化密码。
|
||||
defaultUserPassword: 123456
|
||||
# 缺省的文件上传根目录。
|
||||
uploadFileBaseDir: ./upload-files/app
|
||||
# 跨域的IP白名单列表,多个IP之间逗号分隔(* 表示全部信任,空白表示禁用跨域信任)。
|
||||
credentialIpList: "*"
|
||||
@@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE generatorConfiguration
|
||||
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
|
||||
|
||||
<generatorConfiguration>
|
||||
<context id="Mysql" targetRuntime="MyBatis3Simple" defaultModelType="flat">
|
||||
<property name="javaFileEncoding" value="UTF-8"/>
|
||||
<property name="beginningDelimiter" value="`"/>
|
||||
<property name="endingDelimiter" value="`"/>
|
||||
|
||||
<plugin type="tk.mybatis.mapper.generator.MapperPlugin">
|
||||
<property name="mappers" value="tk.mybatis.mapper.common.Mapper"/>
|
||||
</plugin>
|
||||
|
||||
<jdbcConnection driverClass="com.mysql.cj.jdbc.Driver"
|
||||
connectionURL="jdbc:mysql://localhost:3306/zz-orangle-admin?useSSL=true&serverTimezone=Asia/Shanghai"
|
||||
userId="root"
|
||||
password="123456">
|
||||
</jdbcConnection>
|
||||
|
||||
<javaModelGenerator targetPackage="com.orange.admin.app.model" targetProject="src/main/java"/>
|
||||
|
||||
<sqlMapGenerator targetPackage="com.orange.admin.app.dao.mapper" targetProject="src/main/java"/>
|
||||
|
||||
<javaClientGenerator targetPackage="com.orange.admin.app.dao" targetProject="src/main/java" type="XMLMAPPER"/>
|
||||
|
||||
<!--<table tableName="bbc_system_role_user" domainObjectName="SystemRoleUser">-->
|
||||
<!--</table>-->
|
||||
|
||||
<!-- 执行 mvn mybatis-generator:generate 即可生成 -->
|
||||
</context>
|
||||
</generatorConfiguration>
|
||||
@@ -0,0 +1,66 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!-- 本项目全部使用log4j2性能上有很大提升 -->
|
||||
|
||||
<!--monitorInterval="60" 自动检测配置文件更改时间 单位为秒 最小值为5 -->
|
||||
<!--Configuration后面的status,这个用于设置log4j2自身内部的信息输出,可以不设置,当设置成trace时,你会看到log4j2内部各种详细输出。 -->
|
||||
<configuration monitorInterval="20" status="OFF">
|
||||
<!--日志变量 -->
|
||||
<properties>
|
||||
<!-- 日志主目录 ,需要保存到文件时请自己配置-->
|
||||
<property name="LOG_HOME">./zzlogs</property>
|
||||
<!-- 日志备份目录 -->
|
||||
<property name="BACKUP_HOME">./zzlogs/backup</property>
|
||||
<!-- 日志输出级别 -->
|
||||
<property name="OUTPUT_LOG_LEVEL">info</property>
|
||||
<!-- 日志输出格式 -->
|
||||
<property name="LOG_PATTERN">
|
||||
<!-- 输出格式%d{HH:mm:ss}时间24小时制 -->
|
||||
<!-- %-5p日志级别 5位左对齐 [%t]线程名 [%c]类名 -->
|
||||
<!--%l:输出日志事件的发生位置,相当于%c.%M(%F:%L)的组合,包括类全名、方法、文件名以及在代码中的行数。例如:test.TestLog4j.main(TestLog4j.java:10)。 -->
|
||||
<!-- 另一种输出风格<PatternLayout pattern="级别%-5p [%d{YYYY-MM-dd HH:mm:ss}] [%t] 位置[%l] - 信息:%msg%n" /> -->
|
||||
<!-- [%-5p][%d{yy-MM-dd HH:mm:ss}][%t]==>%m==>%c==>%L%n -->
|
||||
<!--[%-5p] 时间[%d{YYYY-MM-dd HH:mm:ss}] 线程[%t] 位置[%l] ==> %msg%n-->
|
||||
[%-5p] 时间[%d{YYYY-MM-dd HH:mm:ss}] 线程[%t] ==> %msg%n
|
||||
</property>
|
||||
<!-- 日志保留天数 -->
|
||||
<property name="EVERY_FILE_COUNT">31</property>
|
||||
<!-- 日志切割的最小单位 -->
|
||||
<property name="EVERY_FILE_SIZE">20M</property>
|
||||
</properties>
|
||||
|
||||
<appenders>
|
||||
<!--控制台输出 -->
|
||||
<console name="console" target="SYSTEM_OUT">
|
||||
<PatternLayout pattern="${LOG_PATTERN}"/>
|
||||
</console>
|
||||
<!-- console_log级别日志文件 -->
|
||||
<!--每次大小超过size,则这size大小的日志会自动进行压缩,作为存档 -->
|
||||
<rollingFile name="file_log" fileName="${LOG_HOME}/server/server.log"
|
||||
filePattern="${LOG_HOME}/server/server-%d{yyyy-MM-dd}-%i.log.gz">
|
||||
<PatternLayout charset="UTF-8" pattern="${LOG_PATTERN}"/>
|
||||
<!-- 日志切割的最小单位 -->
|
||||
<SizeBasedTriggeringPolicy size="${EVERY_FILE_SIZE}"/>
|
||||
<!-- 默认的日志文件数量 -->
|
||||
<DefaultRolloverStrategy max="${EVERY_FILE_COUNT}"/>
|
||||
</rollingFile>
|
||||
</appenders>
|
||||
|
||||
<!-- 然后定义logger,只有定义了logger并引入的appender,appender才会生效 -->
|
||||
<!-- 这里我们把输出到控制台appender的日志级别设置为DEBUG,便于调试。但是输出文件我们缺省为INFO,两者均可随时修改。-->
|
||||
<Loggers>
|
||||
<root level="${OUTPUT_LOG_LEVEL}">
|
||||
<AppenderRef ref="console"/>
|
||||
</root>
|
||||
<Logger name="com.orange.admin" additivity="false" level="info">
|
||||
<AppenderRef ref="console"/>
|
||||
<AppenderRef ref="file_log"/>
|
||||
</Logger>
|
||||
<!-- 这里将dao的日志级别设置为DEBUG,是为了SQL语句的输出 -->
|
||||
<Logger name="com.orange.admin.app.dao" additivity="false" level="debug">
|
||||
<AppenderRef ref="console"/>
|
||||
</Logger>
|
||||
<Logger name="com.orange.admin.upms.dao" additivity="false" level="debug">
|
||||
<AppenderRef ref="console"/>
|
||||
</Logger>
|
||||
</Loggers>
|
||||
</configuration>
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user