mirror of
https://gitee.com/orangeform/orange-admin.git
synced 2026-01-17 10:36:31 +08:00
commit
This commit is contained in:
BIN
orange-admin-service/.DS_Store
vendored
BIN
orange-admin-service/.DS_Store
vendored
Binary file not shown.
@@ -3,4 +3,3 @@
|
||||
|
||||
在当前工程业务应用服务或Job服务启动前,需按如下顺序依次启动下列中间件。
|
||||
- XXL-Job (可选,仅当启动Job服务时使用)
|
||||
>细节请参考文档:[http://101.200.178.51/development-doc/environment/#xxl-job](http://101.200.178.51/development-doc/environment/#xxl-job)
|
||||
|
||||
BIN
orange-admin-service/application/.DS_Store
vendored
BIN
orange-admin-service/application/.DS_Store
vendored
Binary file not shown.
@@ -3,6 +3,12 @@ package com.orange.admin;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/**
|
||||
* 应用服务启动类。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
@SpringBootApplication
|
||||
public class MyApplication {
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ import java.util.*;
|
||||
* 行政区划数据访问接口类。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/admin/app/areaCode")
|
||||
@@ -32,7 +32,7 @@ public class AreaCodeController {
|
||||
* @return 字典形式的行政区划列表。
|
||||
*/
|
||||
@GetMapping("/listDictAreaCode")
|
||||
public ResponseResult<?> listDictAreaCode() {
|
||||
public ResponseResult<List<Map<String, Object>>> listDictAreaCode() {
|
||||
List<AreaCode> resultList = areaCodeService.getAllList();
|
||||
return ResponseResult.success(BeanQuery.select(
|
||||
"parentId as parentId", "areaId as id", "areaName as name").executeFrom(resultList));
|
||||
@@ -45,7 +45,7 @@ public class AreaCodeController {
|
||||
* @return 按照字典的形式返回下级行政区划列表。
|
||||
*/
|
||||
@GetMapping("/listDictAreaCodeByParentId")
|
||||
public ResponseResult<?> listDictAreaCodeByParentId(@RequestParam(required = false) Long parentId) {
|
||||
public ResponseResult<List<Map<String, Object>>> listDictAreaCodeByParentId(@RequestParam(required = false) Long parentId) {
|
||||
Collection<AreaCode> resultList = areaCodeService.getListByParentId(parentId);
|
||||
if (CollectionUtils.isEmpty(resultList)) {
|
||||
return ResponseResult.success(new LinkedList<>());
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.orange.admin.app.controller;
|
||||
|
||||
import cn.jimmyshi.beanquery.BeanQuery;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.page.PageMethod;
|
||||
import com.orange.admin.app.model.*;
|
||||
import com.orange.admin.app.service.*;
|
||||
import com.orange.admin.upms.model.*;
|
||||
@@ -22,7 +22,7 @@ import javax.validation.groups.Default;
|
||||
* 老师数据源操作控制器类。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@@ -39,28 +39,21 @@ public class TeacherController {
|
||||
* @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);
|
||||
public ResponseResult<JSONObject> add(@MyRequestBody Teacher teacher) {
|
||||
String errorMessage = MyCommonUtil.getModelValidationError(teacher);
|
||||
if (errorMessage != null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_VALIDATAED_FAILED;
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_VALIDATAED_FAILED, errorMessage);
|
||||
}
|
||||
// 验证关联Id的数据合法性
|
||||
VerifyResult verifyResult = teacherService.verifyRelatedData(teacher, null);
|
||||
if (!verifyResult.isSuccess()) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_VALIDATAED_FAILED;
|
||||
errorMessage = verifyResult.getErrorMessage();
|
||||
break;
|
||||
CallResult callResult = teacherService.verifyRelatedData(teacher, null);
|
||||
if (!callResult.isSuccess()) {
|
||||
errorMessage = callResult.getErrorMessage();
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_VALIDATAED_FAILED, errorMessage);
|
||||
}
|
||||
teacher = teacherService.saveNew(teacher);
|
||||
responseData = new JSONObject();
|
||||
JSONObject responseData = new JSONObject();
|
||||
responseData.put("teacherId", teacher.getTeacherId());
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage, responseData);
|
||||
return ResponseResult.success(responseData);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -70,36 +63,28 @@ public class TeacherController {
|
||||
* @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);
|
||||
public ResponseResult<Void> update(@MyRequestBody Teacher teacher) {
|
||||
String errorMessage = MyCommonUtil.getModelValidationError(teacher, Default.class, UpdateGroup.class);
|
||||
if (errorMessage != null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_VALIDATAED_FAILED;
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_VALIDATAED_FAILED, errorMessage);
|
||||
}
|
||||
// 验证关联Id的数据合法性
|
||||
Teacher originalTeacher = teacherService.getById(teacher.getTeacherId());
|
||||
if (originalTeacher == null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
//TODO 修改下面方括号中的话述
|
||||
//NOTE: 修改下面方括号中的话述
|
||||
errorMessage = "数据验证失败,当前 [数据] 并不存在,请刷新后重试!";
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST, errorMessage);
|
||||
}
|
||||
// 验证关联Id的数据合法性
|
||||
VerifyResult verifyResult = teacherService.verifyRelatedData(teacher, originalTeacher);
|
||||
if (!verifyResult.isSuccess()) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_VALIDATAED_FAILED;
|
||||
errorMessage = verifyResult.getErrorMessage();
|
||||
break;
|
||||
CallResult callResult = teacherService.verifyRelatedData(teacher, originalTeacher);
|
||||
if (!callResult.isSuccess()) {
|
||||
errorMessage = callResult.getErrorMessage();
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_VALIDATAED_FAILED, errorMessage);
|
||||
}
|
||||
if (!teacherService.update(teacher, originalTeacher)) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST);
|
||||
}
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage);
|
||||
return ResponseResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -109,29 +94,23 @@ public class TeacherController {
|
||||
* @return 应答结果对象。
|
||||
*/
|
||||
@PostMapping("/delete")
|
||||
public ResponseResult<?> delete(@MyRequestBody Long teacherId) {
|
||||
ErrorCodeEnum errorCodeEnum = ErrorCodeEnum.NO_ERROR;
|
||||
String errorMessage = null;
|
||||
do {
|
||||
public ResponseResult<Void> delete(@MyRequestBody Long teacherId) {
|
||||
String errorMessage;
|
||||
if (MyCommonUtil.existBlankArgument(teacherId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.ARGUMENT_NULL_EXIST;
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.ARGUMENT_NULL_EXIST);
|
||||
}
|
||||
// 验证关联Id的数据合法性
|
||||
Teacher originalTeacher = teacherService.getById(teacherId);
|
||||
if (originalTeacher == null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
//TODO 修改下面方括号中的话述
|
||||
// NOTE: 修改下面方括号中的话述
|
||||
errorMessage = "数据验证失败,当前 [对象] 并不存在,请刷新后重试!";
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST, errorMessage);
|
||||
}
|
||||
if (!teacherService.remove(teacherId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
errorMessage = "数据操作失败,删除的对象不存在,请刷新后重试!";
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST, errorMessage);
|
||||
}
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage);
|
||||
return ResponseResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -144,13 +123,13 @@ public class TeacherController {
|
||||
* @return 应答结果对象,包含查询结果集。
|
||||
*/
|
||||
@PostMapping("/list")
|
||||
public ResponseResult<?> list(
|
||||
public ResponseResult<JSONObject> list(
|
||||
@MyRequestBody Teacher teacherFilter,
|
||||
@MyRequestBody SysDept sysDeptFilter,
|
||||
@MyRequestBody MyOrderParam orderParam,
|
||||
@MyRequestBody MyPageParam pageParam) {
|
||||
if (pageParam != null) {
|
||||
PageHelper.startPage(pageParam.getPageNum(), pageParam.getPageSize());
|
||||
PageMethod.startPage(pageParam.getPageNum(), pageParam.getPageSize());
|
||||
}
|
||||
String orderBy = MyOrderParam.buildOrderBy(orderParam, Teacher.class);
|
||||
List<Teacher> resultList =
|
||||
@@ -166,21 +145,14 @@ public class TeacherController {
|
||||
*/
|
||||
@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;
|
||||
return ResponseResult.error(ErrorCodeEnum.ARGUMENT_NULL_EXIST);
|
||||
}
|
||||
teacher = teacherService.getByIdWithRelation(teacherId);
|
||||
Teacher teacher = teacherService.getByIdWithRelation(teacherId, MyRelationParam.full());
|
||||
if (teacher == null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST);
|
||||
}
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage, teacher);
|
||||
return ResponseResult.success(teacher);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -191,8 +163,8 @@ public class TeacherController {
|
||||
* @return 应答结果对象,包含的数据为 List<Map<String, String>>,map中包含两条记录,key的值分别是id和name,value对应具体数据。
|
||||
*/
|
||||
@GetMapping("/listDictTeacher")
|
||||
public ResponseResult<?> listDictTeacher(Teacher filter) {
|
||||
List<Teacher> resultList = teacherService.getListByFilter(filter);
|
||||
public ResponseResult<List<Map<String, Object>>> listDictTeacher(Teacher filter) {
|
||||
List<Teacher> resultList = teacherService.getListByFilter(filter, null);
|
||||
return ResponseResult.success(BeanQuery.select(
|
||||
"teacherId as id", "teacherName as name").executeFrom(resultList));
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.orange.admin.app.controller;
|
||||
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.page.PageMethod;
|
||||
import com.orange.admin.app.model.*;
|
||||
import com.orange.admin.app.service.*;
|
||||
import com.orange.admin.common.core.object.*;
|
||||
@@ -8,6 +8,7 @@ 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 com.alibaba.fastjson.JSONObject;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@@ -17,7 +18,7 @@ import java.util.*;
|
||||
* 老师流水统计操作控制器类。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@@ -36,12 +37,12 @@ public class TeacherTransStatsController {
|
||||
* @return 应答结果对象,包含查询结果集。
|
||||
*/
|
||||
@PostMapping("/list")
|
||||
public ResponseResult<?> list(
|
||||
public ResponseResult<JSONObject> list(
|
||||
@MyRequestBody TeacherTransStats teacherTransStatsFilter,
|
||||
@MyRequestBody MyOrderParam orderParam,
|
||||
@MyRequestBody MyPageParam pageParam) {
|
||||
if (pageParam != null) {
|
||||
PageHelper.startPage(pageParam.getPageNum(), pageParam.getPageSize());
|
||||
PageMethod.startPage(pageParam.getPageNum(), pageParam.getPageSize());
|
||||
}
|
||||
String orderBy = MyOrderParam.buildOrderBy(orderParam, TeacherTransStats.class);
|
||||
List<TeacherTransStats> resultList = teacherTransStatsService.getTeacherTransStatsListWithRelation(teacherTransStatsFilter, orderBy);
|
||||
@@ -58,7 +59,7 @@ public class TeacherTransStatsController {
|
||||
* @return 应答结果对象,包含查询结果集。
|
||||
*/
|
||||
@PostMapping("/listWithGroup")
|
||||
public ResponseResult<?> listWithGroup(
|
||||
public ResponseResult<JSONObject> listWithGroup(
|
||||
@MyRequestBody TeacherTransStats teacherTransStatsFilter,
|
||||
@MyRequestBody MyGroupParam groupParam,
|
||||
@MyRequestBody MyOrderParam orderParam,
|
||||
@@ -70,7 +71,7 @@ public class TeacherTransStatsController {
|
||||
ErrorCodeEnum.INVALID_ARGUMENT_FORMAT, "数据参数错误,分组参数不能为空!");
|
||||
}
|
||||
if (pageParam != null) {
|
||||
PageHelper.startPage(pageParam.getPageNum(), pageParam.getPageSize());
|
||||
PageMethod.startPage(pageParam.getPageNum(), pageParam.getPageSize());
|
||||
}
|
||||
MyGroupCriteria criteria = groupParam.getGroupCriteria();
|
||||
List<TeacherTransStats> resultList = teacherTransStatsService.getGroupedTeacherTransStatsListWithRelation(
|
||||
@@ -86,20 +87,13 @@ public class TeacherTransStatsController {
|
||||
*/
|
||||
@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;
|
||||
return ResponseResult.error(ErrorCodeEnum.ARGUMENT_NULL_EXIST);
|
||||
}
|
||||
teacherTransStats = teacherTransStatsService.getByIdWithRelation(statsId);
|
||||
TeacherTransStats teacherTransStats = teacherTransStatsService.getByIdWithRelation(statsId, MyRelationParam.full());
|
||||
if (teacherTransStats == null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST);
|
||||
}
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage, teacherTransStats);
|
||||
return ResponseResult.success(teacherTransStats);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import com.orange.admin.app.model.AreaCode;
|
||||
* 行政区划数据操作访问接口。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
public interface AreaCodeMapper extends BaseDaoMapper<AreaCode> {
|
||||
}
|
||||
@@ -12,7 +12,7 @@ import java.util.*;
|
||||
* 老师数据源数据操作访问接口。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
@EnableDataPerm
|
||||
public interface TeacherMapper extends BaseDaoMapper<Teacher> {
|
||||
|
||||
@@ -11,7 +11,7 @@ import java.util.*;
|
||||
* 老师流水统计数据操作访问接口。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
@EnableDataPerm
|
||||
public interface TeacherTransStatsMapper extends BaseDaoMapper<TeacherTransStats> {
|
||||
|
||||
@@ -4,6 +4,12 @@ import lombok.Data;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
/**
|
||||
* 行政区划实体对象。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
@Data
|
||||
@Table(name = "zz_area_code")
|
||||
public class AreaCode {
|
||||
|
||||
@@ -20,6 +20,12 @@ import javax.validation.constraints.*;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Teacher实体对象。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
@Data
|
||||
@Table(name = "zz_teacher")
|
||||
public class Teacher {
|
||||
|
||||
@@ -13,6 +13,12 @@ import javax.validation.constraints.*;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* TeacherTransStats实体对象。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
@Data
|
||||
@Table(name = "zz_teacher_trans_stats")
|
||||
public class TeacherTransStats {
|
||||
|
||||
@@ -3,6 +3,12 @@ package com.orange.admin.app.model.constant;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 性别常量字典对象。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
public final class Gender {
|
||||
|
||||
/**
|
||||
@@ -14,7 +20,7 @@ public final class Gender {
|
||||
*/
|
||||
public static final int FEMALE = 0;
|
||||
|
||||
public static final Map<Object, String> DICT_MAP = new HashMap<>(2);
|
||||
private static final Map<Object, String> DICT_MAP = new HashMap<>(2);
|
||||
static {
|
||||
DICT_MAP.put(MALE, "男");
|
||||
DICT_MAP.put(FEMALE, "女");
|
||||
@@ -26,8 +32,8 @@ public final class Gender {
|
||||
* @param value 待验证的参数值。
|
||||
* @return 合法返回true,否则false。
|
||||
*/
|
||||
public static boolean isValid(int value) {
|
||||
return DICT_MAP.containsKey(value);
|
||||
public static boolean isValid(Integer value) {
|
||||
return value != null && DICT_MAP.containsKey(value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,6 +3,12 @@ package com.orange.admin.app.model.constant;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 教师职级常量字典对象。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
public final class TeacherLevelType {
|
||||
|
||||
/**
|
||||
@@ -18,7 +24,7 @@ public final class TeacherLevelType {
|
||||
*/
|
||||
public static final int HIGH = 2;
|
||||
|
||||
public static final Map<Object, String> DICT_MAP = new HashMap<>(3);
|
||||
private static final Map<Object, String> DICT_MAP = new HashMap<>(3);
|
||||
static {
|
||||
DICT_MAP.put(LOWER, "初级");
|
||||
DICT_MAP.put(NORMAL, "中级");
|
||||
@@ -31,8 +37,8 @@ public final class TeacherLevelType {
|
||||
* @param value 待验证的参数值。
|
||||
* @return 合法返回true,否则false。
|
||||
*/
|
||||
public static boolean isValid(int value) {
|
||||
return DICT_MAP.containsKey(value);
|
||||
public static boolean isValid(Integer value) {
|
||||
return value != null && DICT_MAP.containsKey(value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,7 +16,7 @@ import java.util.List;
|
||||
* 行政区划的Service类。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
@Service
|
||||
public class AreaCodeService extends BaseDictService<AreaCode, Long> {
|
||||
|
||||
@@ -5,15 +5,15 @@ 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.core.object.MyRelationParam;
|
||||
import com.orange.admin.common.core.object.CallResult;
|
||||
import com.orange.admin.common.biz.base.service.BaseBizService;
|
||||
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.*;
|
||||
|
||||
@@ -21,10 +21,10 @@ import java.util.*;
|
||||
* 老师数据源数据操作服务类。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
@Service
|
||||
public class TeacherService extends BaseService<Teacher, Long> {
|
||||
public class TeacherService extends BaseBizService<Teacher, Long> {
|
||||
|
||||
@Autowired
|
||||
private TeacherMapper teacherMapper;
|
||||
@@ -51,7 +51,7 @@ public class TeacherService extends BaseService<Teacher, Long> {
|
||||
* @param teacher 新增对象。
|
||||
* @return 返回新增对象。
|
||||
*/
|
||||
@Transactional
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Teacher saveNew(Teacher teacher) {
|
||||
teacher.setTeacherId(idGenerator.nextLongId());
|
||||
teacher.setRegisterDate(new Date());
|
||||
@@ -66,7 +66,7 @@ public class TeacherService extends BaseService<Teacher, Long> {
|
||||
* @param originalTeacher 原有数据对象。
|
||||
* @return 成功返回true,否则false。
|
||||
*/
|
||||
@Transactional
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean update(Teacher teacher, Teacher originalTeacher) {
|
||||
teacher.setRegisterDate(originalTeacher.getRegisterDate());
|
||||
return teacherMapper.updateByPrimaryKey(teacher) == 1;
|
||||
@@ -78,18 +78,10 @@ public class TeacherService extends BaseService<Teacher, Long> {
|
||||
* @param teacherId 主键Id。
|
||||
* @return 成功返回true,否则false。
|
||||
*/
|
||||
@Transactional
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean remove(Long teacherId) {
|
||||
Teacher teacher = teacherMapper.selectByPrimaryKey(teacherId);
|
||||
if (teacher == null) {
|
||||
return false;
|
||||
}
|
||||
// 这里先删除主数据
|
||||
if (teacherMapper.deleteByPrimaryKey(teacherId) == 0) {
|
||||
return false;
|
||||
}
|
||||
return teacherMapper.deleteByPrimaryKey(teacherId) != 0;
|
||||
// 这里可继续删除关联数据。
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -117,7 +109,7 @@ public class TeacherService extends BaseService<Teacher, Long> {
|
||||
List<Teacher> resultList =
|
||||
teacherMapper.getTeacherListEx(filter, sysDeptFilter, orderBy);
|
||||
Map<String, List<MyWhereCriteria>> criteriaMap = buildAggregationAdditionalWhereCriteria();
|
||||
this.buildAllRelationForDataList(resultList, false, criteriaMap);
|
||||
this.buildRelationForDataList(resultList, MyRelationParam.normal(), criteriaMap);
|
||||
return resultList;
|
||||
}
|
||||
|
||||
@@ -128,24 +120,18 @@ public class TeacherService extends BaseService<Teacher, Long> {
|
||||
* @param originalTeacher 原有数据对象。
|
||||
* @return 数据全部正确返回true,否则false。
|
||||
*/
|
||||
public VerifyResult verifyRelatedData(Teacher teacher, Teacher originalTeacher) {
|
||||
String errorMessage = null;
|
||||
do {
|
||||
public CallResult verifyRelatedData(Teacher teacher, Teacher originalTeacher) {
|
||||
String errorMessageFormat = "数据验证失败,关联的%s并不存在,请刷新后重试!";
|
||||
//这里是基于字典的验证。
|
||||
if (this.needToVerify(teacher, originalTeacher, Teacher::getSchoolId)) {
|
||||
if (!sysDeptService.existId(teacher.getSchoolId())) {
|
||||
errorMessage = "数据验证失败,关联的所属校区并不存在,请刷新后重试!";
|
||||
break;
|
||||
}
|
||||
if (this.needToVerify(teacher, originalTeacher, Teacher::getSchoolId)
|
||||
&& !sysDeptService.existId(teacher.getSchoolId())) {
|
||||
return CallResult.error(String.format(errorMessageFormat, "所属校区"));
|
||||
}
|
||||
//这里是基于字典的验证。
|
||||
if (this.needToVerify(teacher, originalTeacher, Teacher::getUserId)) {
|
||||
if (!sysUserService.existId(teacher.getUserId())) {
|
||||
errorMessage = "数据验证失败,关联的绑定用户并不存在,请刷新后重试!";
|
||||
break;
|
||||
if (this.needToVerify(teacher, originalTeacher, Teacher::getUserId)
|
||||
&& !sysUserService.existId(teacher.getUserId())) {
|
||||
return CallResult.error(String.format(errorMessageFormat, "绑定用户"));
|
||||
}
|
||||
}
|
||||
} while (false);
|
||||
return VerifyResult.create(errorMessage);
|
||||
return CallResult.ok();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,10 @@ 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 com.orange.admin.common.core.object.MyRelationParam;
|
||||
import com.orange.admin.common.biz.base.service.BaseBizService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -15,10 +16,10 @@ import java.util.*;
|
||||
* 老师流水统计数据操作服务类。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
@Service
|
||||
public class TeacherTransStatsService extends BaseService<TeacherTransStats, Long> {
|
||||
public class TeacherTransStatsService extends BaseBizService<TeacherTransStats, Long> {
|
||||
|
||||
@Autowired
|
||||
private TeacherTransStatsMapper teacherTransStatsMapper;
|
||||
@@ -62,7 +63,7 @@ public class TeacherTransStatsService extends BaseService<TeacherTransStats, Lon
|
||||
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);
|
||||
this.buildRelationForDataList(resultList, MyRelationParam.normal(), criteriaMap);
|
||||
return resultList;
|
||||
}
|
||||
|
||||
@@ -81,7 +82,7 @@ public class TeacherTransStatsService extends BaseService<TeacherTransStats, Lon
|
||||
teacherTransStatsMapper.getGroupedTeacherTransStatsList(filter, groupSelect, groupBy, orderBy);
|
||||
// NOTE: 这里只是包含了关联数据,聚合计算数据没有包含。
|
||||
// 主要原因是,由于聚合字段通常被视为普通字段使用,不会在group by的从句中出现,语义上也不会在此关联。
|
||||
this.buildRelationForDataList(resultList, false);
|
||||
this.buildRelationForDataList(resultList, MyRelationParam.normal(), null);
|
||||
return resultList;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
* 应用程序自定义的程序属性配置文件。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
@Data
|
||||
@Configuration
|
||||
|
||||
@@ -15,7 +15,7 @@ import java.util.concurrent.TimeUnit;
|
||||
* 使用Caffeine作为本地缓存库
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
@Configuration
|
||||
@EnableCaching
|
||||
@@ -32,23 +32,19 @@ public class CacheConfig {
|
||||
/**
|
||||
* 专门存储用户权限的缓存。
|
||||
*/
|
||||
UserPermissionCache(1800),
|
||||
USER_PERMISSION_CACHE(1800, 10000),
|
||||
/**
|
||||
* 专门存储用户数据权限的缓存。
|
||||
*/
|
||||
DataPermissionCache(7200),
|
||||
DATA_PERMISSION_CACHE(7200, 10000),
|
||||
/**
|
||||
* 缺省全局缓存(时间是24小时)。
|
||||
*/
|
||||
GlobalCache(86400,20000);
|
||||
GLOBAL_CACHE(86400,20000);
|
||||
|
||||
CacheEnum() {
|
||||
}
|
||||
|
||||
CacheEnum(int ttl) {
|
||||
this.ttl = ttl;
|
||||
}
|
||||
|
||||
CacheEnum(int ttl, int maxSize) {
|
||||
this.ttl = ttl;
|
||||
this.maxSize = maxSize;
|
||||
@@ -67,17 +63,9 @@ public class CacheConfig {
|
||||
return maxSize;
|
||||
}
|
||||
|
||||
public void setMaxSize(int maxSize) {
|
||||
this.maxSize = maxSize;
|
||||
}
|
||||
|
||||
public int getTtl() {
|
||||
return ttl;
|
||||
}
|
||||
|
||||
public void setTtl(int ttl) {
|
||||
this.ttl = ttl;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -14,7 +14,7 @@ import javax.sql.DataSource;
|
||||
* 数据源配置Bean对象。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
@Configuration
|
||||
@EnableTransactionManagement
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
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;
|
||||
@@ -16,26 +15,21 @@ import java.nio.charset.StandardCharsets;
|
||||
* 这里主要配置Web的各种过滤器和监听器等Servlet容器组件。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
@Configuration
|
||||
public class FilterConfig {
|
||||
|
||||
@Autowired
|
||||
private ApplicationConfig applicationConfig;
|
||||
|
||||
/**
|
||||
* 配置Ajax跨域过滤器
|
||||
* 配置Ajax跨域过滤器。
|
||||
*/
|
||||
@Bean
|
||||
public CorsFilter corsFilterRegistration() {
|
||||
public CorsFilter corsFilterRegistration(ApplicationConfig applicationConfig) {
|
||||
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 {
|
||||
if (credentialIpList.length > 0) {
|
||||
for (String ip : credentialIpList) {
|
||||
corsConfiguration.addAllowedOrigin(ip);
|
||||
}
|
||||
|
||||
@@ -16,10 +16,10 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 所有的项目拦截器都在这里集中配置
|
||||
* 所有的项目拦截器都在这里集中配置。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
@Configuration
|
||||
public class InterceptorConfig implements WebMvcConfigurer {
|
||||
|
||||
@@ -33,7 +33,7 @@ import java.util.stream.Collectors;
|
||||
* 登录用户Token验证、生成和权限验证的拦截器。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
@Slf4j
|
||||
public class AuthenticationInterceptor implements HandlerInterceptor {
|
||||
@@ -82,7 +82,7 @@ public class AuthenticationInterceptor implements HandlerInterceptor {
|
||||
return false;
|
||||
}
|
||||
String sessionId = (String) c.get("sessionId");
|
||||
Cache cache = cacheManager.getCache(CacheConfig.CacheEnum.GlobalCache.name());
|
||||
Cache cache = cacheManager.getCache(CacheConfig.CacheEnum.GLOBAL_CACHE.name());
|
||||
TokenData tokenData = cache.get(sessionId, TokenData.class);
|
||||
if (tokenData == null) {
|
||||
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
|
||||
@@ -91,9 +91,8 @@ public class AuthenticationInterceptor implements HandlerInterceptor {
|
||||
return false;
|
||||
}
|
||||
TokenData.addToRequest(tokenData);
|
||||
if (!tokenData.getIsAdmin()) {
|
||||
// 如果url在权限资源白名单中,则不需要进行鉴权操作
|
||||
if (!whitelistPermSet.contains(url)) {
|
||||
if (!tokenData.getIsAdmin() && !whitelistPermSet.contains(url)) {
|
||||
Set<String> urlSet = sysPermService.getCacheableSysPermSetByUserId(
|
||||
tokenData.getSessionId(), tokenData.getUserId());
|
||||
if (!urlSet.contains(url)) {
|
||||
@@ -103,7 +102,6 @@ public class AuthenticationInterceptor implements HandlerInterceptor {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (JwtUtil.needToRefresh(c)) {
|
||||
String refreshedToken = JwtUtil.generateToken(c, applicationConfig.getTokenSigningKey());
|
||||
response.addHeader(applicationConfig.getRefreshedTokenHeaderKey(), refreshedToken);
|
||||
@@ -114,11 +112,13 @@ public class AuthenticationInterceptor implements HandlerInterceptor {
|
||||
@Override
|
||||
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
|
||||
ModelAndView modelAndView) throws Exception {
|
||||
// 这里需要空注解,否则sonar会不happy。
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
|
||||
throws Exception {
|
||||
// 这里需要空注解,否则sonar会不happy。
|
||||
}
|
||||
|
||||
private void outputResponseMessage(HttpServletResponse response, ResponseResult<Object> respObj) {
|
||||
|
||||
@@ -1,24 +1,29 @@
|
||||
package com.orange.admin.interceptor;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
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.exception.NoDataPermException;
|
||||
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 com.orange.admin.upms.dao.SysDataPermMapper;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.sf.jsqlparser.JSQLParserException;
|
||||
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.CollectionUtils;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.ibatis.executor.statement.RoutingStatementHandler;
|
||||
@@ -30,7 +35,6 @@ 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;
|
||||
|
||||
@@ -43,7 +47,7 @@ import java.util.*;
|
||||
* Mybatis拦截器。目前用于数据权限的统一拦截和注入处理。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
@Intercepts({@Signature(type = StatementHandler.class, method = "prepare", args = {Connection.class, Integer.class})})
|
||||
@Slf4j
|
||||
@@ -56,7 +60,7 @@ public class MybatisDataPermInterceptor implements Interceptor {
|
||||
/**
|
||||
* HTTP Head或HTTP Request Parameter中菜单Id数据的KEY名称。
|
||||
*/
|
||||
private final static String MENU_ID_HEADER_KEY = "MenuId";
|
||||
private static final String MENU_ID_HEADER_KEY = "MenuId";
|
||||
/**
|
||||
* 对象缓存。由于Set是排序后的,因为在查找排除方法名称时效率更高。
|
||||
* 在应用服务启动的监听器中(LoadDataPermMapperListener),会调用当前对象的(loadMappersWithDataPerm)方法,加载缓存。
|
||||
@@ -67,6 +71,7 @@ public class MybatisDataPermInterceptor implements Interceptor {
|
||||
* 预先加载需要数据权限过滤的Mapper到缓存,该函数会在(LoadDataPermMapperListener)监听器中调用。
|
||||
*/
|
||||
public void loadMappersWithDataPerm() {
|
||||
@SuppressWarnings("all")
|
||||
Map<String, Mapper> mapperMap =
|
||||
ApplicationContextHolder.getApplicationContext().getBeansOfType(Mapper.class);
|
||||
for (Mapper<?> mapperProxy : mapperMap.values()) {
|
||||
@@ -80,9 +85,15 @@ public class MybatisDataPermInterceptor implements Interceptor {
|
||||
(Class<?>) ReflectUtil.getFieldValue(proxy, "mapperInterface");
|
||||
EnableDataPerm rule = mapperClass.getAnnotation(EnableDataPerm.class);
|
||||
if (rule != null) {
|
||||
loadRules(mapperClass, rule);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void loadRules(Class<?> mapperClass, EnableDataPerm rule) {
|
||||
// 由于给数据权限Mapper添加@EnableDataPerm,将会导致无限递归,因此这里检测到之后,
|
||||
// 会在系统启动加载监听器的时候,及时抛出异常。
|
||||
if ("SysDataPermMapper".equals(mapperClass.getSimpleName())) {
|
||||
if (mapperClass.equals(SysDataPermMapper.class)) {
|
||||
throw new IllegalStateException("Add @EnableDataPerm annotation to SysDataPermMapper is ILLEGAL!");
|
||||
}
|
||||
// 这里开始获取当前Mapper已经声明的的SqlId中,有哪些是需要排除在外的。
|
||||
@@ -101,7 +112,8 @@ public class MybatisDataPermInterceptor implements Interceptor {
|
||||
Class<?> modelClazz = (Class<?>)
|
||||
((ParameterizedType) mapperClass.getGenericInterfaces()[0]).getActualTypeArguments()[0];
|
||||
Field[] fields = ReflectUtil.getFields(modelClazz);
|
||||
Field userFilterField = null, deptFilterField = null;
|
||||
Field userFilterField = null;
|
||||
Field deptFilterField = null;
|
||||
for (Field field : fields) {
|
||||
if (null != field.getAnnotation(UserFilterColumn.class)) {
|
||||
userFilterField = field;
|
||||
@@ -123,11 +135,8 @@ public class MybatisDataPermInterceptor implements Interceptor {
|
||||
if (deptFilterField != null) {
|
||||
info.setDeptFilterColumn(MyModelUtil.mapToColumnName(deptFilterField, modelClazz));
|
||||
}
|
||||
String className = mapperClass.getName();
|
||||
cacheMap.put(mapperClass.getName(), info);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
@@ -149,7 +158,7 @@ public class MybatisDataPermInterceptor implements Interceptor {
|
||||
SqlCommandType commandType = mappedStatement.getSqlCommandType();
|
||||
TokenData tokenData = TokenData.takeFromRequest();
|
||||
// 数据过滤权限中,只是过滤SELECT语句。如果是管理员则不参与数据权限的数据过滤,显示全部数据。
|
||||
if (commandType != SqlCommandType.SELECT || tokenData == null || tokenData.getIsAdmin()) {
|
||||
if (commandType != SqlCommandType.SELECT || tokenData == null || Boolean.TRUE.equals(tokenData.getIsAdmin())) {
|
||||
return invocation.proceed();
|
||||
}
|
||||
String sqlId = mappedStatement.getId();
|
||||
@@ -158,10 +167,8 @@ public class MybatisDataPermInterceptor implements Interceptor {
|
||||
String methodName = StringUtils.substring(sqlId, pos + 1);
|
||||
// 先从缓存中查找当前Mapper是否存在。
|
||||
ModelDataPermInfo info = cacheMap.get(className);
|
||||
if (info != null) {
|
||||
// 再次查找当前方法是否为排除方法,如果不是,就参与数据权限注入过滤。
|
||||
if (info.getExcludeMethodNameSet() == null
|
||||
|| !info.getExcludeMethodNameSet().contains(methodName)) {
|
||||
if (info != null && !CollUtil.contains(info.getExcludeMethodNameSet(), methodName)) {
|
||||
String menuId = ContextUtil.getHttpRequest().getHeader(MENU_ID_HEADER_KEY);
|
||||
if (StringUtils.isBlank(menuId)) {
|
||||
menuId = ContextUtil.getHttpRequest().getParameter(MENU_ID_HEADER_KEY);
|
||||
@@ -170,22 +177,28 @@ public class MybatisDataPermInterceptor implements Interceptor {
|
||||
"No [ MENU_ID ] key found in Http Header for SQL_ID [ " + sqlId + " ].");
|
||||
}
|
||||
}
|
||||
Cache cache = cacheManager.getCache(CacheConfig.CacheEnum.DataPermissionCache.name());
|
||||
Cache cache = cacheManager.getCache(CacheConfig.CacheEnum.DATA_PERMISSION_CACHE.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);
|
||||
throw new NoDataPermException(
|
||||
"No Related DataPerm found with SESSION_ID [ " + tokenData.getSessionId() + " ].");
|
||||
}
|
||||
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);
|
||||
throw new NoDataPermException(
|
||||
"No Related DataPerm found with MENU_ID [ " + menuId + " ] for SQL_ID [ " + sqlId + " ].");
|
||||
}
|
||||
processDataPerm(info, dataPermMap, delegate.getBoundSql());
|
||||
}
|
||||
if (dataPermMap.containsKey(DataPermRuleType.TYPE_ALL)) {
|
||||
return invocation.proceed();
|
||||
}
|
||||
BoundSql boundSql = delegate.getBoundSql();
|
||||
|
||||
private void processDataPerm(ModelDataPermInfo info, Map<Integer, String> dataPermMap, BoundSql boundSql)
|
||||
throws JSQLParserException {
|
||||
if (dataPermMap.containsKey(DataPermRuleType.TYPE_ALL)) {
|
||||
return;
|
||||
}
|
||||
String sql = boundSql.getSql();
|
||||
Select select = (Select) CCJSqlParserUtil.parse(sql);
|
||||
PlainSelect selectBody = (PlainSelect) select.getSelectBody();
|
||||
@@ -196,20 +209,40 @@ public class MybatisDataPermInterceptor implements Interceptor {
|
||||
}
|
||||
List<String> criteriaList = new LinkedList<>();
|
||||
for (Map.Entry<Integer, String> entry : dataPermMap.entrySet()) {
|
||||
Integer ruleType = entry.getKey();
|
||||
String filterClause = processDataPermRule(info, entry.getKey(), entry.getValue());
|
||||
if (StringUtils.isNotBlank(filterClause)) {
|
||||
criteriaList.add(filterClause);
|
||||
}
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(criteriaList)) {
|
||||
StringBuilder filterBuilder = new StringBuilder(128);
|
||||
filterBuilder.append("(");
|
||||
filterBuilder.append(StringUtils.join(criteriaList, " OR "));
|
||||
filterBuilder.append(")");
|
||||
String dataFilter = filterBuilder.toString();
|
||||
if (subSelect != null) {
|
||||
buildWhereClause(subSelect, dataFilter);
|
||||
} else {
|
||||
buildWhereClause(selectBody, dataFilter);
|
||||
}
|
||||
}
|
||||
sql = select.toString();
|
||||
ReflectUtil.setFieldValue(boundSql, "sql", sql);
|
||||
}
|
||||
|
||||
private String processDataPermRule(ModelDataPermInfo info, Integer ruleType, String deptIds) {
|
||||
TokenData tokenData = TokenData.takeFromRequest();
|
||||
StringBuilder filter = new StringBuilder(128);
|
||||
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(".")
|
||||
@@ -221,42 +254,22 @@ public class MybatisDataPermInterceptor implements Interceptor {
|
||||
.append(".")
|
||||
.append(info.getDeptFilterColumn())
|
||||
.append(" IN (")
|
||||
.append(entry.getValue())
|
||||
.append(deptIds)
|
||||
.append(") ");
|
||||
}
|
||||
criteriaList.add(filter.toString());
|
||||
}
|
||||
}
|
||||
return 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));
|
||||
|
||||
private void buildWhereClause(PlainSelect select, String dataFilter) throws JSQLParserException {
|
||||
if (select.getWhere() == null) {
|
||||
select.setWhere(CCJSqlParserUtil.parseCondExpression(dataFilter));
|
||||
} else {
|
||||
AndExpression and = new AndExpression(
|
||||
CCJSqlParserUtil.parseCondExpression(dataFilter), subSelect.getWhere());
|
||||
subSelect.setWhere(and);
|
||||
CCJSqlParserUtil.parseCondExpression(dataFilter), select.getWhere());
|
||||
select.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
|
||||
@@ -266,7 +279,7 @@ public class MybatisDataPermInterceptor implements Interceptor {
|
||||
|
||||
@Override
|
||||
public void setProperties(Properties properties) {
|
||||
|
||||
// 这里需要空注解,否则sonar会不happy。
|
||||
}
|
||||
|
||||
@Data
|
||||
|
||||
@@ -11,7 +11,7 @@ import org.springframework.stereotype.Component;
|
||||
* 将标记有数据权限规则注解的Mapper对象,加载到缓存,以提升系统运行时效率。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
@Component
|
||||
public class LoadDataPermMapperListener implements ApplicationListener<ApplicationReadyEvent> {
|
||||
|
||||
@@ -15,20 +15,21 @@ 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 com.orange.admin.common.core.util.RsaUtil;
|
||||
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;
|
||||
import java.net.URLDecoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 登录接口控制器类。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@@ -59,31 +60,32 @@ public class LoginController {
|
||||
*/
|
||||
@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 {
|
||||
public ResponseResult<JSONObject> doLogin(
|
||||
@RequestParam String loginName, @RequestParam String password) throws Exception {
|
||||
if (MyCommonUtil.existBlankArgument(loginName, password)) {
|
||||
errorCodeEnum = ErrorCodeEnum.ARGUMENT_NULL_EXIST;
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.ARGUMENT_NULL_EXIST);
|
||||
}
|
||||
//NOTE: 执行RsaUtil工具类中的main函数,可以生成新的公钥和私钥。
|
||||
String privateKey =
|
||||
"MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAKkLhAydtOtA4WuIkkIIUVaGWu4ElOEAQF9GTulHHWOwCHI1UvcKolvS1G+mdsKcmGtEAQ92AUde/kDRGu8Wn7kLDtCgUfo72soHz7Qfv5pVB4ohMxQd/9cxeKjKbDoirhB9Z3xGF20zUozp4ZPLxpTtI7azr0xzUtd5+D/HfLDrAgMBAAECgYEApESZhDz4YyeAJiPnpJ06lS8oS2VOWzsIUs0av5uoloeoHXtt7Lx7u2kroHeNrl3Hy2yg7ypH4dgQkGHin3VHrVAgjG3TxhgBXIqqntzzk2AGJKBeIIkRX86uTvtKZyp3flUgcwcGmpepAHS1V1DPY3aVYvbcqAmoL6DX6VYN0NECQQDQUitMdC76lEtAr5/ywS0nrZJDo6U7eQ7ywx/eiJ+YmrSye8oorlAj1VBWG+Cl6jdHOHtTQyYv/tu71fjzQiJTAkEAz7wb47/vcSUpNWQxItFpXz0o6rbJh71xmShn1AKP7XptOVZGlW9QRYEzHabV9m/DHqI00cMGhHrWZAhCiTkUCQJAFsJjaJ7o4weAkTieyO7B+CvGZw1h5/V55Jvcx3s1tH5yb22G0Jr6tm9/r2isSnQkReutzZLwgR3e886UvD7lcQJAAUcD2OOuQkDbPwPNtYwaHMbQgJj9JkOI9kskUE5vuiMdltOr/XFAyhygRtdmy2wmhAK1VnDfkmL6/IR8fEGImQJABOB0KCalb0M8CPnqqHzozrD8gPObnIIr4aVvLIPATN2g7MM2N6F7JbI4RZFiKa92LV6bhQCY8OvHi5K2cgFpbw==";
|
||||
SysUser user = sysUserService.getSysUserByLoginName(loginName);
|
||||
password = URLDecoder.decode(password, StandardCharsets.UTF_8.name());
|
||||
password = RsaUtil.decrypt(password, privateKey);
|
||||
if (user == null
|
||||
|| !user.getPassword().equals(MyCommonUtil.encrptedPassword(password, appConfig.getPasswordSalt()))) {
|
||||
errorCodeEnum = ErrorCodeEnum.INVALID_USERNAME_PASSWORD;
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.INVALID_USERNAME_PASSWORD);
|
||||
}
|
||||
String errorMessage;
|
||||
if (user.getUserStatus() == SysUserStatus.STATUS_LOCKED) {
|
||||
errorCodeEnum = ErrorCodeEnum.INVALID_USER_STATUS;
|
||||
errorMessage = "登录失败,用户账号被锁定!";
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.INVALID_USER_STATUS, errorMessage);
|
||||
}
|
||||
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());
|
||||
JSONObject jsonData = new JSONObject();
|
||||
jsonData.put(TokenData.REQUEST_ATTRIBUTE_NAME, token);
|
||||
jsonData.put("showName", user.getShowName());
|
||||
jsonData.put("isAdmin", isAdmin);
|
||||
@@ -93,7 +95,7 @@ public class LoginController {
|
||||
tokenData.setDeptId(user.getDeptId());
|
||||
tokenData.setShowName(user.getShowName());
|
||||
tokenData.setIsAdmin(isAdmin);
|
||||
Cache sessionCache = cacheManager.getCache(CacheConfig.CacheEnum.GlobalCache.name());
|
||||
Cache sessionCache = cacheManager.getCache(CacheConfig.CacheEnum.GLOBAL_CACHE.name());
|
||||
sessionCache.put(sessionId, tokenData);
|
||||
List<SysMenu> menuList;
|
||||
if (isAdmin) {
|
||||
@@ -109,8 +111,7 @@ public class LoginController {
|
||||
sysPermService.putUserSysPermCache(sessionId, user.getUserId(), isAdmin);
|
||||
sysDataPermService.putDataPermCache(sessionId, user.getUserId(), user.getDeptId(), isAdmin);
|
||||
}
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage, jsonData);
|
||||
return ResponseResult.success(jsonData);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -119,7 +120,7 @@ public class LoginController {
|
||||
* @return 应答结果对象。
|
||||
*/
|
||||
@PostMapping("/doLogout")
|
||||
public ResponseResult<?> doLogout() {
|
||||
public ResponseResult<Void> doLogout() {
|
||||
TokenData tokenData = TokenData.takeFromRequest();
|
||||
sysPermService.removeUserSysPermCache(tokenData.getSessionId());
|
||||
sysDataPermService.removeDataPermCache(tokenData.getSessionId());
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.orange.admin.upms.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.page.PageMethod;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import com.orange.admin.upms.model.SysDataPermMenu;
|
||||
import com.orange.admin.upms.model.SysDataPerm;
|
||||
@@ -10,10 +10,11 @@ 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.CallResult;
|
||||
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.MyRelationParam;
|
||||
import com.orange.admin.common.core.util.MyCommonUtil;
|
||||
import com.orange.admin.common.core.util.MyPageUtil;
|
||||
import com.orange.admin.common.core.annotation.MyRequestBody;
|
||||
@@ -28,7 +29,7 @@ import java.util.stream.Collectors;
|
||||
* 数据权限接口控制器对象。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@@ -50,24 +51,18 @@ public class SysDataPermController {
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@PostMapping("/add")
|
||||
public ResponseResult<?> add(
|
||||
public ResponseResult<JSONObject> 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;
|
||||
return ResponseResult.error(ErrorCodeEnum.ARGUMENT_NULL_EXIST);
|
||||
}
|
||||
errorMessage = MyCommonUtil.getModelValidationError(sysDataPerm);
|
||||
String errorMessage = MyCommonUtil.getModelValidationError(sysDataPerm);
|
||||
if (errorMessage != null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_VALIDATAED_FAILED;
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_VALIDATAED_FAILED, errorMessage);
|
||||
}
|
||||
VerifyResult result = sysDataPermService.verifyRelatedData(sysDataPerm, deptIdListString, menuIdListString);
|
||||
CallResult result = sysDataPermService.verifyRelatedData(sysDataPerm, deptIdListString, menuIdListString);
|
||||
if (!result.isSuccess()) {
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_VALIDATAED_FAILED, result.getErrorMessage());
|
||||
}
|
||||
@@ -78,10 +73,9 @@ public class SysDataPermController {
|
||||
deptIdSet = (Set<Long>) result.getData().get("deptIdSet");
|
||||
}
|
||||
sysDataPermService.saveNew(sysDataPerm, deptIdSet, dataPermMenuList);
|
||||
responseData = new JSONObject();
|
||||
JSONObject responseData = new JSONObject();
|
||||
responseData.put("dataPermId", sysDataPerm.getDataPermId());
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage, responseData);
|
||||
return ResponseResult.success(responseData);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -94,29 +88,23 @@ public class SysDataPermController {
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@PostMapping("/update")
|
||||
public ResponseResult<?> update(
|
||||
public ResponseResult<Void> 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;
|
||||
return ResponseResult.error(ErrorCodeEnum.ARGUMENT_NULL_EXIST);
|
||||
}
|
||||
errorMessage = MyCommonUtil.getModelValidationError(sysDataPerm, Default.class, UpdateGroup.class);
|
||||
String errorMessage = MyCommonUtil.getModelValidationError(sysDataPerm, Default.class, UpdateGroup.class);
|
||||
if (errorMessage != null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_VALIDATAED_FAILED;
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_VALIDATAED_FAILED, errorMessage);
|
||||
}
|
||||
SysDataPerm originalSysDataPerm = sysDataPermService.getById(sysDataPerm.getDataPermId());
|
||||
if (originalSysDataPerm == null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
errorMessage = "数据验证失败,当前数据权限并不存在,请刷新后重试!";
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST, errorMessage);
|
||||
}
|
||||
VerifyResult result = sysDataPermService.verifyRelatedData(sysDataPerm, deptIdListString, menuIdListString);
|
||||
CallResult result = sysDataPermService.verifyRelatedData(sysDataPerm, deptIdListString, menuIdListString);
|
||||
if (!result.isSuccess()) {
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_VALIDATAED_FAILED, result.getErrorMessage());
|
||||
}
|
||||
@@ -127,12 +115,10 @@ public class SysDataPermController {
|
||||
deptIdSet = (Set<Long>) result.getData().get("deptIdSet");
|
||||
}
|
||||
if (!sysDataPermService.update(sysDataPerm, originalSysDataPerm, deptIdSet, dataPermMenuList)) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
errorMessage = "更新失败,数据不存在,请刷新后重试!";
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST, errorMessage);
|
||||
}
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage);
|
||||
return ResponseResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -142,21 +128,15 @@ public class SysDataPermController {
|
||||
* @return 应答数据结果。
|
||||
*/
|
||||
@PostMapping("/delete")
|
||||
public ResponseResult<?> delete(@MyRequestBody Long dataPermId) {
|
||||
ErrorCodeEnum errorCodeEnum = ErrorCodeEnum.NO_ERROR;
|
||||
String errorMessage = null;
|
||||
do {
|
||||
public ResponseResult<Void> delete(@MyRequestBody Long dataPermId) {
|
||||
if (MyCommonUtil.existBlankArgument(dataPermId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.ARGUMENT_NULL_EXIST;
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.ARGUMENT_NULL_EXIST);
|
||||
}
|
||||
if (!sysDataPermService.remove(dataPermId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
errorMessage = "数据操作失败,数据权限不存在,请刷新后重试!";
|
||||
break;
|
||||
String errorMessage = "数据操作失败,数据权限不存在,请刷新后重试!";
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST, errorMessage);
|
||||
}
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage);
|
||||
return ResponseResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -168,12 +148,12 @@ public class SysDataPermController {
|
||||
* @return 应答结果对象。包含数据权限列表。
|
||||
*/
|
||||
@PostMapping("/list")
|
||||
public ResponseResult<?> list(
|
||||
public ResponseResult<JSONObject> list(
|
||||
@MyRequestBody SysDataPerm sysDataPermFilter,
|
||||
@MyRequestBody MyOrderParam orderParam,
|
||||
@MyRequestBody MyPageParam pageParam) {
|
||||
if (pageParam != null) {
|
||||
PageHelper.startPage(pageParam.getPageNum(), pageParam.getPageSize());
|
||||
PageMethod.startPage(pageParam.getPageNum(), pageParam.getPageSize());
|
||||
}
|
||||
String orderBy = MyOrderParam.buildOrderBy(orderParam, SysDataPerm.class);
|
||||
List<SysDataPerm> resultList = sysDataPermService.getSysDataPermList(sysDataPermFilter, orderBy);
|
||||
@@ -188,21 +168,14 @@ public class SysDataPermController {
|
||||
*/
|
||||
@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;
|
||||
return ResponseResult.error(ErrorCodeEnum.ARGUMENT_NULL_EXIST);
|
||||
}
|
||||
dataPerm = sysDataPermService.getSysDataPermWithRelation(dataPermId);
|
||||
SysDataPerm dataPerm = sysDataPermService.getByIdWithRelation(dataPermId, MyRelationParam.full());
|
||||
if (dataPerm == null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST);
|
||||
}
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage, dataPerm);
|
||||
return ResponseResult.success(dataPerm);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -216,32 +189,23 @@ public class SysDataPermController {
|
||||
* @return 应答结果对象,包含用户列表数据。
|
||||
*/
|
||||
@PostMapping("/listNotInDataPermUser")
|
||||
public ResponseResult<?> listNotInDataPermUser(
|
||||
public ResponseResult<JSONObject> 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;
|
||||
ResponseResult<Void> verifyResult = this.doDataPermUserVerify(dataPermId);
|
||||
if (!verifyResult.isSuccess()) {
|
||||
return ResponseResult.errorFrom(verifyResult);
|
||||
}
|
||||
if (pageParam != null) {
|
||||
PageHelper.startPage(pageParam.getPageNum(), pageParam.getPageSize());
|
||||
PageMethod.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);
|
||||
JSONObject responseData = MyPageUtil.makeResponseData(resultList);
|
||||
return ResponseResult.success(responseData);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -254,32 +218,33 @@ public class SysDataPermController {
|
||||
* @return 应答结果对象,包含用户列表数据。
|
||||
*/
|
||||
@PostMapping("/listDataPermUser")
|
||||
public ResponseResult<?> listDataPermUser(
|
||||
public ResponseResult<JSONObject> 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;
|
||||
ResponseResult<Void> verifyResult = this.doDataPermUserVerify(dataPermId);
|
||||
if (!verifyResult.isSuccess()) {
|
||||
return ResponseResult.errorFrom(verifyResult);
|
||||
}
|
||||
if (pageParam != null) {
|
||||
PageHelper.startPage(pageParam.getPageNum(), pageParam.getPageSize());
|
||||
PageMethod.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);
|
||||
JSONObject responseData = MyPageUtil.makeResponseData(resultList);
|
||||
return ResponseResult.success(responseData);
|
||||
}
|
||||
|
||||
private ResponseResult<Void> doDataPermUserVerify(Long dataPermId) {
|
||||
if (MyCommonUtil.existBlankArgument(dataPermId)) {
|
||||
return ResponseResult.error(ErrorCodeEnum.ARGUMENT_NULL_EXIST);
|
||||
}
|
||||
if (!sysDataPermService.existId(dataPermId)) {
|
||||
return ResponseResult.error(ErrorCodeEnum.INVALID_RELATED_RECORD_ID);
|
||||
}
|
||||
return ResponseResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -290,25 +255,19 @@ public class SysDataPermController {
|
||||
* @return 应答结果对象。
|
||||
*/
|
||||
@PostMapping("/addDataPermUser")
|
||||
public ResponseResult<?> addDataPermUser(
|
||||
public ResponseResult<Void> 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;
|
||||
return ResponseResult.error(ErrorCodeEnum.ARGUMENT_NULL_EXIST);
|
||||
}
|
||||
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;
|
||||
return ResponseResult.error(ErrorCodeEnum.INVALID_RELATED_RECORD_ID);
|
||||
}
|
||||
sysDataPermService.addDataPermUserList(dataPermId, userIdSet);
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage);
|
||||
return ResponseResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -319,20 +278,14 @@ public class SysDataPermController {
|
||||
* @return 应答数据结果。
|
||||
*/
|
||||
@PostMapping("/deleteDataPermUser")
|
||||
public ResponseResult<?> deleteDataPermUser(
|
||||
public ResponseResult<Void> 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;
|
||||
return ResponseResult.error(ErrorCodeEnum.ARGUMENT_NULL_EXIST);
|
||||
}
|
||||
if (!sysDataPermService.removeDataPermUser(dataPermId, userId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST);
|
||||
}
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage);
|
||||
return ResponseResult.success();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.orange.admin.upms.controller;
|
||||
|
||||
import cn.jimmyshi.beanquery.BeanQuery;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.page.PageMethod;
|
||||
import com.orange.admin.upms.model.*;
|
||||
import com.orange.admin.upms.service.*;
|
||||
import com.orange.admin.common.core.object.*;
|
||||
@@ -21,7 +21,7 @@ import javax.validation.groups.Default;
|
||||
* 部门管理操作控制器类。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@@ -38,21 +38,15 @@ public class SysDeptController {
|
||||
* @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);
|
||||
public ResponseResult<JSONObject> add(@MyRequestBody SysDept sysDept) {
|
||||
String errorMessage = MyCommonUtil.getModelValidationError(sysDept);
|
||||
if (errorMessage != null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_VALIDATAED_FAILED;
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_VALIDATAED_FAILED, errorMessage);
|
||||
}
|
||||
sysDept = sysDeptService.saveNew(sysDept);
|
||||
responseData = new JSONObject();
|
||||
JSONObject responseData = new JSONObject();
|
||||
responseData.put("deptId", sysDept.getDeptId());
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage, responseData);
|
||||
return ResponseResult.success(responseData);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -62,29 +56,22 @@ public class SysDeptController {
|
||||
* @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);
|
||||
public ResponseResult<Void> update(@MyRequestBody SysDept sysDept) {
|
||||
String errorMessage = MyCommonUtil.getModelValidationError(sysDept, Default.class, UpdateGroup.class);
|
||||
if (errorMessage != null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_VALIDATAED_FAILED;
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_VALIDATAED_FAILED, errorMessage);
|
||||
}
|
||||
// 验证关联Id的数据合法性
|
||||
SysDept originalSysDept = sysDeptService.getById(sysDept.getDeptId());
|
||||
if (originalSysDept == null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
//TODO 修改下面方括号中的话述
|
||||
//NOTE: 修改下面方括号中的话述
|
||||
errorMessage = "数据验证失败,当前 [数据] 并不存在,请刷新后重试!";
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST, errorMessage);
|
||||
}
|
||||
if (!sysDeptService.update(sysDept, originalSysDept)) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST);
|
||||
}
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage);
|
||||
return ResponseResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -94,29 +81,23 @@ public class SysDeptController {
|
||||
* @return 应答结果对象。
|
||||
*/
|
||||
@PostMapping("/delete")
|
||||
public ResponseResult<?> delete(@MyRequestBody Long deptId) {
|
||||
ErrorCodeEnum errorCodeEnum = ErrorCodeEnum.NO_ERROR;
|
||||
String errorMessage = null;
|
||||
do {
|
||||
public ResponseResult<Void> delete(@MyRequestBody Long deptId) {
|
||||
String errorMessage;
|
||||
if (MyCommonUtil.existBlankArgument(deptId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.ARGUMENT_NULL_EXIST;
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.ARGUMENT_NULL_EXIST);
|
||||
}
|
||||
// 验证关联Id的数据合法性
|
||||
SysDept originalSysDept = sysDeptService.getById(deptId);
|
||||
if (originalSysDept == null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
//TODO 修改下面方括号中的话述
|
||||
// NOTE: 修改下面方括号中的话述
|
||||
errorMessage = "数据验证失败,当前 [对象] 并不存在,请刷新后重试!";
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST, errorMessage);
|
||||
}
|
||||
if (!sysDeptService.remove(deptId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
errorMessage = "数据操作失败,删除的对象不存在,请刷新后重试!";
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST, errorMessage);
|
||||
}
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage);
|
||||
return ResponseResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -128,12 +109,12 @@ public class SysDeptController {
|
||||
* @return 应答结果对象,包含查询结果集。
|
||||
*/
|
||||
@PostMapping("/list")
|
||||
public ResponseResult<?> list(
|
||||
public ResponseResult<JSONObject> list(
|
||||
@MyRequestBody SysDept sysDeptFilter,
|
||||
@MyRequestBody MyOrderParam orderParam,
|
||||
@MyRequestBody MyPageParam pageParam) {
|
||||
if (pageParam != null) {
|
||||
PageHelper.startPage(pageParam.getPageNum(), pageParam.getPageSize());
|
||||
PageMethod.startPage(pageParam.getPageNum(), pageParam.getPageSize());
|
||||
}
|
||||
String orderBy = MyOrderParam.buildOrderBy(orderParam, SysDept.class);
|
||||
List<SysDept> resultList = sysDeptService.getSysDeptListWithRelation(sysDeptFilter, orderBy);
|
||||
@@ -148,21 +129,14 @@ public class SysDeptController {
|
||||
*/
|
||||
@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;
|
||||
return ResponseResult.error(ErrorCodeEnum.ARGUMENT_NULL_EXIST);
|
||||
}
|
||||
sysDept = sysDeptService.getByIdWithRelation(deptId);
|
||||
SysDept sysDept = sysDeptService.getByIdWithRelation(deptId, MyRelationParam.full());
|
||||
if (sysDept == null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST);
|
||||
}
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage, sysDept);
|
||||
return ResponseResult.success(sysDept);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -173,8 +147,8 @@ public class SysDeptController {
|
||||
* @return 应答结果对象,包含的数据为 List<Map<String, String>>,map中包含两条记录,key的值分别是id和name,value对应具体数据。
|
||||
*/
|
||||
@GetMapping("/listDictSysDept")
|
||||
public ResponseResult<?> listDictSysDept(SysDept filter) {
|
||||
List<SysDept> resultList = sysDeptService.getListByFilter(filter);
|
||||
public ResponseResult<List<Map<String, Object>>> listDictSysDept(SysDept filter) {
|
||||
List<SysDept> resultList = sysDeptService.getListByFilter(filter, null);
|
||||
return ResponseResult.success(BeanQuery.select(
|
||||
"deptId as id", "deptName as name").executeFrom(resultList));
|
||||
}
|
||||
|
||||
@@ -6,8 +6,9 @@ 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.CallResult;
|
||||
import com.orange.admin.common.core.object.ResponseResult;
|
||||
import com.orange.admin.common.core.object.MyRelationParam;
|
||||
import com.orange.admin.common.core.util.MyCommonUtil;
|
||||
import com.orange.admin.common.core.validator.UpdateGroup;
|
||||
import com.orange.admin.common.core.annotation.MyRequestBody;
|
||||
@@ -21,7 +22,7 @@ import java.util.*;
|
||||
* 菜单管理接口控制器类。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@@ -42,17 +43,12 @@ public class SysMenuController {
|
||||
*/
|
||||
@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);
|
||||
public ResponseResult<JSONObject> add(@MyRequestBody SysMenu sysMenu, @MyRequestBody String permCodeIdListString) {
|
||||
String errorMessage = MyCommonUtil.getModelValidationError(sysMenu);
|
||||
if (errorMessage != null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_VALIDATAED_FAILED;
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_VALIDATAED_FAILED, errorMessage);
|
||||
}
|
||||
VerifyResult result = sysMenuService.verifyRelatedData(sysMenu, null, permCodeIdListString);
|
||||
CallResult result = sysMenuService.verifyRelatedData(sysMenu, null, permCodeIdListString);
|
||||
if (!result.isSuccess()) {
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_VALIDATAED_FAILED, result.getErrorMessage());
|
||||
}
|
||||
@@ -61,10 +57,9 @@ public class SysMenuController {
|
||||
permCodeIdSet = (Set<Long>) result.getData().get("permCodeIdSet");
|
||||
}
|
||||
sysMenuService.saveNew(sysMenu, permCodeIdSet);
|
||||
responseData = new JSONObject();
|
||||
JSONObject responseData = new JSONObject();
|
||||
responseData.put("sysMenuId", sysMenu.getMenuId());
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage, responseData);
|
||||
return ResponseResult.success(responseData);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -76,22 +71,17 @@ public class SysMenuController {
|
||||
*/
|
||||
@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);
|
||||
public ResponseResult<Void> update(@MyRequestBody SysMenu sysMenu, @MyRequestBody String permCodeIdListString) {
|
||||
String errorMessage = MyCommonUtil.getModelValidationError(sysMenu, Default.class, UpdateGroup.class);
|
||||
if (errorMessage != null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_VALIDATAED_FAILED;
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_VALIDATAED_FAILED, errorMessage);
|
||||
}
|
||||
SysMenu originalSysMenu = sysMenuService.getById(sysMenu.getMenuId());
|
||||
if (originalSysMenu == null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
errorMessage = "数据验证失败,当前菜单并不存在,请刷新后重试!";
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST, errorMessage);
|
||||
}
|
||||
VerifyResult result = sysMenuService.verifyRelatedData(sysMenu, originalSysMenu, permCodeIdListString);
|
||||
CallResult result = sysMenuService.verifyRelatedData(sysMenu, originalSysMenu, permCodeIdListString);
|
||||
if (!result.isSuccess()) {
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_VALIDATAED_FAILED, result.getErrorMessage());
|
||||
}
|
||||
@@ -100,11 +90,10 @@ public class SysMenuController {
|
||||
permCodeIdSet = (Set<Long>) result.getData().get("permCodeIdSet");
|
||||
}
|
||||
if (!sysMenuService.update(sysMenu, originalSysMenu, permCodeIdSet)) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
errorMessage = "数据验证失败,当前权限字并不存在,请刷新后重试!";
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST, errorMessage);
|
||||
}
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage);
|
||||
return ResponseResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -114,26 +103,20 @@ public class SysMenuController {
|
||||
* @return 应答结果对象。
|
||||
*/
|
||||
@PostMapping("/delete")
|
||||
public ResponseResult<?> delete(@MyRequestBody Long menuId) {
|
||||
ErrorCodeEnum errorCodeEnum = ErrorCodeEnum.NO_ERROR;
|
||||
String errorMessage = null;
|
||||
do {
|
||||
public ResponseResult<Void> delete(@MyRequestBody Long menuId) {
|
||||
if (MyCommonUtil.existBlankArgument(menuId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.ARGUMENT_NULL_EXIST;
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.ARGUMENT_NULL_EXIST);
|
||||
}
|
||||
String errorMessage;
|
||||
if (sysMenuService.hasChildren(menuId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.HAS_CHILDREN_DATA;
|
||||
errorMessage = "数据验证失败,当前菜单存在下级菜单!";
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.HAS_CHILDREN_DATA, errorMessage);
|
||||
}
|
||||
if (!sysMenuService.remove(menuId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
errorMessage = "数据操作失败,菜单不存在,请刷新后重试!";
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST, errorMessage);
|
||||
}
|
||||
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage);
|
||||
return ResponseResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -154,21 +137,14 @@ public class SysMenuController {
|
||||
*/
|
||||
@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;
|
||||
return ResponseResult.error(ErrorCodeEnum.ARGUMENT_NULL_EXIST);
|
||||
}
|
||||
sysMenu = sysMenuService.getSysMenuWithRelation(menuId);
|
||||
SysMenu sysMenu = sysMenuService.getByIdWithRelation(menuId, MyRelationParam.full());
|
||||
if (sysMenu == null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST);
|
||||
}
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage, sysMenu);
|
||||
return ResponseResult.success(sysMenu);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
package com.orange.admin.upms.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.page.PageMethod;
|
||||
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.CallResult;
|
||||
import com.orange.admin.common.core.object.MyPageParam;
|
||||
import com.orange.admin.common.core.object.MyRelationParam;
|
||||
import com.orange.admin.common.core.util.MyCommonUtil;
|
||||
import com.orange.admin.common.core.util.MyPageUtil;
|
||||
import com.orange.admin.common.core.validator.UpdateGroup;
|
||||
@@ -24,7 +25,7 @@ import java.util.*;
|
||||
* 权限字管理接口控制器类。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@@ -43,17 +44,12 @@ public class SysPermCodeController {
|
||||
*/
|
||||
@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);
|
||||
public ResponseResult<JSONObject> add(@MyRequestBody SysPermCode sysPermCode, @MyRequestBody String permIdListString) {
|
||||
String errorMessage = MyCommonUtil.getModelValidationError(sysPermCode);
|
||||
if (errorMessage != null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_VALIDATAED_FAILED;
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_VALIDATAED_FAILED);
|
||||
}
|
||||
VerifyResult result = sysPermCodeService.verifyRelatedData(sysPermCode, null, permIdListString);
|
||||
CallResult result = sysPermCodeService.verifyRelatedData(sysPermCode, null, permIdListString);
|
||||
if (!result.isSuccess()) {
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_VALIDATAED_FAILED, result.getErrorMessage());
|
||||
}
|
||||
@@ -62,10 +58,9 @@ public class SysPermCodeController {
|
||||
permIdSet = (Set<Long>) result.getData().get("permIdSet");
|
||||
}
|
||||
sysPermCode = sysPermCodeService.saveNew(sysPermCode, permIdSet);
|
||||
responseData = new JSONObject();
|
||||
JSONObject responseData = new JSONObject();
|
||||
responseData.put("sysPermCodeId", sysPermCode.getPermCodeId());
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage, responseData);
|
||||
return ResponseResult.success(responseData);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -77,22 +72,17 @@ public class SysPermCodeController {
|
||||
*/
|
||||
@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);
|
||||
public ResponseResult<Void> update(@MyRequestBody SysPermCode sysPermCode, @MyRequestBody String permIdListString) {
|
||||
String errorMessage = MyCommonUtil.getModelValidationError(sysPermCode, Default.class, UpdateGroup.class);
|
||||
if (errorMessage != null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_VALIDATAED_FAILED;
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_VALIDATAED_FAILED, errorMessage);
|
||||
}
|
||||
SysPermCode originalSysPermCode = sysPermCodeService.getById(sysPermCode.getPermCodeId());
|
||||
if (originalSysPermCode == null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
errorMessage = "数据验证失败,当前权限字并不存在,请刷新后重试!";
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST, errorMessage);
|
||||
}
|
||||
VerifyResult result = sysPermCodeService.verifyRelatedData(sysPermCode, originalSysPermCode, permIdListString);
|
||||
CallResult result = sysPermCodeService.verifyRelatedData(sysPermCode, originalSysPermCode, permIdListString);
|
||||
if (!result.isSuccess()) {
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_VALIDATAED_FAILED, result.getErrorMessage());
|
||||
}
|
||||
@@ -102,15 +92,14 @@ public class SysPermCodeController {
|
||||
}
|
||||
try {
|
||||
if (!sysPermCodeService.update(sysPermCode, originalSysPermCode, permIdSet)) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
errorMessage = "数据验证失败,当前权限字并不存在,请刷新后重试!";
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST, errorMessage);
|
||||
}
|
||||
} catch (DuplicateKeyException e) {
|
||||
errorCodeEnum = ErrorCodeEnum.DUPLICATED_UNIQUE_KEY;
|
||||
errorMessage = "数据操作失败,权限字编码已经存在!";
|
||||
return ResponseResult.error(ErrorCodeEnum.DUPLICATED_UNIQUE_KEY, errorMessage);
|
||||
}
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage);
|
||||
return ResponseResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -120,25 +109,20 @@ public class SysPermCodeController {
|
||||
* @return 应答结果对象。
|
||||
*/
|
||||
@PostMapping("/delete")
|
||||
public ResponseResult<?> delete(@MyRequestBody Long permCodeId) {
|
||||
ErrorCodeEnum errorCodeEnum = ErrorCodeEnum.NO_ERROR;
|
||||
String errorMessage = null;
|
||||
do {
|
||||
public ResponseResult<Void> delete(@MyRequestBody Long permCodeId) {
|
||||
if (MyCommonUtil.existBlankArgument(permCodeId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.ARGUMENT_NULL_EXIST;
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.ARGUMENT_NULL_EXIST);
|
||||
}
|
||||
String errorMessage;
|
||||
if (sysPermCodeService.hasChildren(permCodeId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.HAS_CHILDREN_DATA;
|
||||
errorMessage = "数据验证失败,当前权限字存在下级权限字!";
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.HAS_CHILDREN_DATA, errorMessage);
|
||||
}
|
||||
if (!sysPermCodeService.remove(permCodeId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
errorMessage = "数据操作失败,权限字不存在,请刷新后重试!";
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST, errorMessage);
|
||||
}
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage);
|
||||
return ResponseResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -147,7 +131,7 @@ public class SysPermCodeController {
|
||||
* @return 应答结果对象,包含权限字列表。
|
||||
*/
|
||||
@PostMapping("/list")
|
||||
public ResponseResult<?> list() {
|
||||
public ResponseResult<List<SysPermCode>> list() {
|
||||
return ResponseResult.success(sysPermCodeService.getAllListByOrder("permCodeType", "showOrder"));
|
||||
}
|
||||
|
||||
@@ -159,21 +143,14 @@ public class SysPermCodeController {
|
||||
*/
|
||||
@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;
|
||||
return ResponseResult.error(ErrorCodeEnum.ARGUMENT_NULL_EXIST);
|
||||
}
|
||||
sysPermCode = sysPermCodeService.getSysPermCodeWithRelation(permCodeId);
|
||||
SysPermCode sysPermCode = sysPermCodeService.getByIdWithRelation(permCodeId, MyRelationParam.full());
|
||||
if (sysPermCode == null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST);
|
||||
}
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage, sysPermCode);
|
||||
return ResponseResult.success(sysPermCode);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -185,25 +162,19 @@ public class SysPermCodeController {
|
||||
* @return 应答结果对象,包含该用户的全部权限资源列表。
|
||||
*/
|
||||
@PostMapping("/listAllPermCodesByUserFilter")
|
||||
public ResponseResult<?> listAllPermCodesByUserFilter(
|
||||
public ResponseResult<JSONObject> 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;
|
||||
return ResponseResult.error(ErrorCodeEnum.ARGUMENT_NULL_EXIST);
|
||||
}
|
||||
if (pageParam != null) {
|
||||
PageHelper.startPage(pageParam.getPageNum(), pageParam.getPageSize());
|
||||
PageMethod.startPage(pageParam.getPageNum(), pageParam.getPageSize());
|
||||
}
|
||||
List<SysPermCode> permCodeList =
|
||||
sysPermCodeService.getUserPermCodeListByFilter(loginName, permCode);
|
||||
responseData = MyPageUtil.makeResponseData(permCodeList);
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage, responseData);
|
||||
JSONObject responseData = MyPageUtil.makeResponseData(permCodeList);
|
||||
return ResponseResult.success(responseData);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
package com.orange.admin.upms.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.page.PageMethod;
|
||||
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.CallResult;
|
||||
import com.orange.admin.common.core.object.MyPageParam;
|
||||
import com.orange.admin.common.core.util.MyCommonUtil;
|
||||
import com.orange.admin.common.core.util.MyPageUtil;
|
||||
@@ -25,7 +25,7 @@ import java.util.Map;
|
||||
* 权限资源管理接口控制器类。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@@ -42,25 +42,19 @@ public class SysPermController {
|
||||
* @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);
|
||||
public ResponseResult<JSONObject> add(@MyRequestBody SysPerm sysPerm) {
|
||||
String errorMessage = MyCommonUtil.getModelValidationError(sysPerm);
|
||||
if (errorMessage != null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_VALIDATAED_FAILED;
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_VALIDATAED_FAILED, errorMessage);
|
||||
}
|
||||
VerifyResult result = sysPermService.verifyRelatedData(sysPerm, null);
|
||||
CallResult result = sysPermService.verifyRelatedData(sysPerm, null);
|
||||
if (!result.isSuccess()) {
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_VALIDATAED_FAILED, result.getErrorMessage());
|
||||
}
|
||||
sysPerm = sysPermService.saveNew(sysPerm);
|
||||
responseData = new JSONObject();
|
||||
JSONObject responseData = new JSONObject();
|
||||
responseData.put("permId", sysPerm.getPermId());
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage, responseData);
|
||||
return ResponseResult.success(responseData);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -70,22 +64,17 @@ public class SysPermController {
|
||||
* @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);
|
||||
public ResponseResult<Void> update(@MyRequestBody SysPerm sysPerm) {
|
||||
String errorMessage = MyCommonUtil.getModelValidationError(sysPerm, Default.class, UpdateGroup.class);
|
||||
if (errorMessage != null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_VALIDATAED_FAILED;
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_VALIDATAED_FAILED, errorMessage);
|
||||
}
|
||||
SysPerm originalPerm = sysPermService.getById(sysPerm.getPermId());
|
||||
if (originalPerm == null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
errorMessage = "数据验证失败,当前权限资源并不存在,请刷新后重试!";
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST, errorMessage);
|
||||
}
|
||||
VerifyResult result = sysPermService.verifyRelatedData(sysPerm, originalPerm);
|
||||
CallResult result = sysPermService.verifyRelatedData(sysPerm, originalPerm);
|
||||
if (!result.isSuccess()) {
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_VALIDATAED_FAILED, result.getErrorMessage());
|
||||
}
|
||||
@@ -94,8 +83,7 @@ public class SysPermController {
|
||||
sysPerm.setModuleId(permModule.getModuleId());
|
||||
}
|
||||
sysPermService.update(sysPerm, originalPerm);
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage);
|
||||
return ResponseResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -105,21 +93,15 @@ public class SysPermController {
|
||||
* @return 应答结果对象。
|
||||
*/
|
||||
@PostMapping("/delete")
|
||||
public ResponseResult<?> delete(@MyRequestBody Long permId) {
|
||||
ErrorCodeEnum errorCodeEnum = ErrorCodeEnum.NO_ERROR;
|
||||
String errorMessage = null;
|
||||
do {
|
||||
public ResponseResult<Void> delete(@MyRequestBody Long permId) {
|
||||
if (MyCommonUtil.existBlankArgument(permId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.ARGUMENT_NULL_EXIST;
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.ARGUMENT_NULL_EXIST);
|
||||
}
|
||||
if (!sysPermService.remove(permId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
errorMessage = "数据操作失败,权限不存在,请刷新后重试!";
|
||||
break;
|
||||
String errorMessage = "数据操作失败,权限不存在,请刷新后重试!";
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST, errorMessage);
|
||||
}
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage);
|
||||
return ResponseResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -130,21 +112,14 @@ public class SysPermController {
|
||||
*/
|
||||
@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;
|
||||
return ResponseResult.error(ErrorCodeEnum.ARGUMENT_NULL_EXIST);
|
||||
}
|
||||
perm = sysPermService.getById(permId);
|
||||
SysPerm perm = sysPermService.getById(permId);
|
||||
if (perm == null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST);
|
||||
}
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage, perm);
|
||||
return ResponseResult.success(perm);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -155,9 +130,9 @@ public class SysPermController {
|
||||
* @return 应答结果对象,包含权限资源列表。
|
||||
*/
|
||||
@PostMapping("/list")
|
||||
public ResponseResult<?> list(@MyRequestBody SysPerm sysPermFilter, @MyRequestBody MyPageParam pageParam) {
|
||||
public ResponseResult<JSONObject> list(@MyRequestBody SysPerm sysPermFilter, @MyRequestBody MyPageParam pageParam) {
|
||||
if (pageParam != null) {
|
||||
PageHelper.startPage(pageParam.getPageNum(), pageParam.getPageSize());
|
||||
PageMethod.startPage(pageParam.getPageNum(), pageParam.getPageSize());
|
||||
}
|
||||
List<SysPerm> resultList = sysPermService.getPermListWithRelation(sysPermFilter);
|
||||
return ResponseResult.success(MyPageUtil.makeResponseData(resultList));
|
||||
@@ -173,27 +148,21 @@ public class SysPermController {
|
||||
* @return 应答结果对象,包含该用户的全部权限资源列表。
|
||||
*/
|
||||
@PostMapping("/listAllPermsByUserFilter")
|
||||
public ResponseResult<?> listAllPermsByUserFilter(
|
||||
public ResponseResult<JSONObject> 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;
|
||||
return ResponseResult.error(ErrorCodeEnum.ARGUMENT_NULL_EXIST);
|
||||
}
|
||||
if (pageParam != null) {
|
||||
PageHelper.startPage(pageParam.getPageNum(), pageParam.getPageSize());
|
||||
PageMethod.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);
|
||||
JSONObject responseData = MyPageUtil.makeResponseData(userPermMapList);
|
||||
return ResponseResult.success(responseData);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -203,18 +172,12 @@ public class SysPermController {
|
||||
* @return 应答结果对象,包含用户数据列表。
|
||||
*/
|
||||
@PostMapping("/listAllUsers")
|
||||
public ResponseResult<?> listAllUsers(@MyRequestBody Long permId) {
|
||||
ErrorCodeEnum errorCodeEnum = ErrorCodeEnum.NO_ERROR;
|
||||
String errorMessage = null;
|
||||
List<Map<String, Object>> permUserMapList = null;
|
||||
do {
|
||||
public ResponseResult<List<Map<String, Object>>> listAllUsers(@MyRequestBody Long permId) {
|
||||
if (MyCommonUtil.existBlankArgument(permId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.ARGUMENT_NULL_EXIST;
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.ARGUMENT_NULL_EXIST);
|
||||
}
|
||||
permUserMapList = sysPermService.getPermUserListById(permId);
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage, permUserMapList);
|
||||
List<Map<String, Object>> permUserMapList = sysPermService.getPermUserListById(permId);
|
||||
return ResponseResult.success(permUserMapList);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -224,17 +187,11 @@ public class SysPermController {
|
||||
* @return 应答结果对象,包含角色数据列表。
|
||||
*/
|
||||
@PostMapping("/listAllRoles")
|
||||
public ResponseResult<?> listAllRoles(@MyRequestBody Long permId) {
|
||||
ErrorCodeEnum errorCodeEnum = ErrorCodeEnum.NO_ERROR;
|
||||
String errorMessage = null;
|
||||
List<Map<String, Object>> permRoleMapList = null;
|
||||
do {
|
||||
public ResponseResult<List<Map<String, Object>>> listAllRoles(@MyRequestBody Long permId) {
|
||||
if (MyCommonUtil.existBlankArgument(permId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.ARGUMENT_NULL_EXIST;
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.ARGUMENT_NULL_EXIST);
|
||||
}
|
||||
permRoleMapList = sysPermService.getPermRoleListById(permId);
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage, permRoleMapList);
|
||||
List<Map<String, Object>> permRoleMapList = sysPermService.getPermRoleListById(permId);
|
||||
return ResponseResult.success(permRoleMapList);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ import java.util.Map;
|
||||
* 权限资源模块管理接口控制器类。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@@ -41,28 +41,20 @@ public class SysPermModuleController {
|
||||
* @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);
|
||||
public ResponseResult<JSONObject> add(@MyRequestBody SysPermModule sysPermModule) {
|
||||
String errorMessage = MyCommonUtil.getModelValidationError(sysPermModule);
|
||||
if (errorMessage != null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_VALIDATAED_FAILED;
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_VALIDATAED_FAILED, errorMessage);
|
||||
}
|
||||
if (sysPermModule.getParentId() != null) {
|
||||
if (sysPermModuleService.getById(sysPermModule.getParentId()) == null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_PARENT_ID_NOT_EXIST;
|
||||
if (sysPermModule.getParentId() != null
|
||||
&& sysPermModuleService.getById(sysPermModule.getParentId()) == null) {
|
||||
errorMessage = "数据验证失败,关联的上级权限模块并不存在,请刷新后重试!";
|
||||
break;
|
||||
}
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_PARENT_ID_NOT_EXIST, errorMessage);
|
||||
}
|
||||
sysPermModuleService.saveNew(sysPermModule);
|
||||
responseData = new JSONObject();
|
||||
JSONObject responseData = new JSONObject();
|
||||
responseData.put("permModuleId", sysPermModule.getModuleId());
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage, responseData);
|
||||
return ResponseResult.success(responseData);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -72,34 +64,27 @@ public class SysPermModuleController {
|
||||
* @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);
|
||||
public ResponseResult<Void> update(@MyRequestBody SysPermModule sysPermModule) {
|
||||
String errorMessage = MyCommonUtil.getModelValidationError(sysPermModule, Default.class, UpdateGroup.class);
|
||||
if (errorMessage != null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_VALIDATAED_FAILED;
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_VALIDATAED_FAILED, errorMessage);
|
||||
}
|
||||
SysPermModule originalPermModule = sysPermModuleService.getById(sysPermModule.getModuleId());
|
||||
if (originalPermModule == null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST);
|
||||
}
|
||||
if (sysPermModule.getParentId() != null
|
||||
&& !sysPermModule.getParentId().equals(originalPermModule.getParentId())) {
|
||||
if (sysPermModuleService.getById(sysPermModule.getParentId()) == null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_PARENT_ID_NOT_EXIST;
|
||||
errorMessage = "数据验证失败,关联的上级权限模块并不存在,请刷新后重试!";
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_PARENT_ID_NOT_EXIST, errorMessage);
|
||||
}
|
||||
}
|
||||
if (!sysPermModuleService.update(sysPermModule, originalPermModule)) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
errorMessage = "数据验证失败,当前模块并不存在,请刷新后重试!";
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST, errorMessage);
|
||||
}
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage);
|
||||
return ResponseResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -109,26 +94,21 @@ public class SysPermModuleController {
|
||||
* @return 应答结果对象。
|
||||
*/
|
||||
@PostMapping("/delete")
|
||||
public ResponseResult<?> delete(@MyRequestBody Long moduleId) {
|
||||
ErrorCodeEnum errorCodeEnum = ErrorCodeEnum.NO_ERROR;
|
||||
String errorMessage = null;
|
||||
do {
|
||||
public ResponseResult<Void> delete(@MyRequestBody Long moduleId) {
|
||||
if (MyCommonUtil.existBlankArgument(moduleId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.ARGUMENT_NULL_EXIST;
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.ARGUMENT_NULL_EXIST);
|
||||
}
|
||||
String errorMessage;
|
||||
if (sysPermModuleService.hasChildren(moduleId)
|
||||
|| sysPermModuleService.hasModulePerms(moduleId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.HAS_CHILDREN_DATA;
|
||||
errorMessage = "数据验证失败,当前权限模块存在子模块或权限资源,请先删除关联数据!";
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.HAS_CHILDREN_DATA, errorMessage);
|
||||
}
|
||||
if (!sysPermModuleService.remove(moduleId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
errorMessage = "数据操作失败,权限模块不存在,请刷新后重试!";
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST, errorMessage);
|
||||
}
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage);
|
||||
return ResponseResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -147,7 +127,7 @@ public class SysPermModuleController {
|
||||
* @return 应答结果对象,包含树状列表,结构为权限资源模块和权限资源之间的树状关系。
|
||||
*/
|
||||
@GetMapping("/listAll")
|
||||
public ResponseResult<?> listAll() {
|
||||
public ResponseResult<List<Map<String, Object>>> listAll() {
|
||||
List<SysPermModule> sysPermModuleList = sysPermModuleService.getPermModuleAndPermList();
|
||||
List<Map<String, Object>> resultList = new LinkedList<>();
|
||||
for (SysPermModule sysPermModule : sysPermModuleList) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.orange.admin.upms.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.page.PageMethod;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import com.orange.admin.upms.model.SysRole;
|
||||
import com.orange.admin.upms.model.SysUser;
|
||||
@@ -14,7 +14,8 @@ 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.object.CallResult;
|
||||
import com.orange.admin.common.core.object.MyRelationParam;
|
||||
import com.orange.admin.common.core.util.MyPageUtil;
|
||||
import com.orange.admin.common.core.annotation.MyRequestBody;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -28,7 +29,7 @@ import java.util.stream.Collectors;
|
||||
* 角色管理接口控制器类。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@@ -49,17 +50,12 @@ public class SysRoleController {
|
||||
*/
|
||||
@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);
|
||||
public ResponseResult<JSONObject> add(@MyRequestBody SysRole sysRole, @MyRequestBody String menuIdListString) {
|
||||
String errorMessage = MyCommonUtil.getModelValidationError(sysRole);
|
||||
if (errorMessage != null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_VALIDATAED_FAILED;
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_VALIDATAED_FAILED, errorMessage);
|
||||
}
|
||||
VerifyResult result = sysRoleService.verifyRelatedData(sysRole, null, menuIdListString);
|
||||
CallResult result = sysRoleService.verifyRelatedData(sysRole, null, menuIdListString);
|
||||
if (!result.isSuccess()) {
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_VALIDATAED_FAILED, result.getErrorMessage());
|
||||
}
|
||||
@@ -68,10 +64,9 @@ public class SysRoleController {
|
||||
menuIdSet = (Set<Long>) result.getData().get("menuIdSet");
|
||||
}
|
||||
sysRoleService.saveNew(sysRole, menuIdSet);
|
||||
responseData = new JSONObject();
|
||||
JSONObject responseData = new JSONObject();
|
||||
responseData.put("roleId", sysRole.getRoleId());
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage, responseData);
|
||||
return ResponseResult.success(responseData);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -83,22 +78,17 @@ public class SysRoleController {
|
||||
*/
|
||||
@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);
|
||||
public ResponseResult<Void> update(@MyRequestBody SysRole sysRole, @MyRequestBody String menuIdListString) {
|
||||
String errorMessage = MyCommonUtil.getModelValidationError(sysRole, Default.class, UpdateGroup.class);
|
||||
if (errorMessage != null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_VALIDATAED_FAILED;
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_VALIDATAED_FAILED, errorMessage);
|
||||
}
|
||||
SysRole originalSysRole = sysRoleService.getById(sysRole.getRoleId());
|
||||
if (originalSysRole == null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
errorMessage = "数据验证失败,当前角色并不存在,请刷新后重试!";
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST, errorMessage);
|
||||
}
|
||||
VerifyResult result = sysRoleService.verifyRelatedData(sysRole, originalSysRole, menuIdListString);
|
||||
CallResult result = sysRoleService.verifyRelatedData(sysRole, originalSysRole, menuIdListString);
|
||||
if (!result.isSuccess()) {
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_VALIDATAED_FAILED, result.getErrorMessage());
|
||||
}
|
||||
@@ -107,12 +97,10 @@ public class SysRoleController {
|
||||
menuIdSet = (Set<Long>) result.getData().get("menuIdSet");
|
||||
}
|
||||
if (!sysRoleService.update(sysRole, originalSysRole, menuIdSet)) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
errorMessage = "更新失败,数据不存在,请刷新后重试!";
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST, errorMessage);
|
||||
}
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage);
|
||||
return ResponseResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -122,21 +110,15 @@ public class SysRoleController {
|
||||
* @return 应答结果对象。
|
||||
*/
|
||||
@PostMapping("/delete")
|
||||
public ResponseResult<?> delete(@MyRequestBody Long roleId) {
|
||||
ErrorCodeEnum errorCodeEnum = ErrorCodeEnum.NO_ERROR;
|
||||
String errorMessage = null;
|
||||
do {
|
||||
public ResponseResult<Void> delete(@MyRequestBody Long roleId) {
|
||||
if (MyCommonUtil.existBlankArgument(roleId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.ARGUMENT_NULL_EXIST;
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.ARGUMENT_NULL_EXIST);
|
||||
}
|
||||
if (!sysRoleService.remove(roleId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
errorMessage = "数据操作失败,角色不存在,请刷新后重试!";
|
||||
break;
|
||||
String errorMessage = "数据操作失败,角色不存在,请刷新后重试!";
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST, errorMessage);
|
||||
}
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage);
|
||||
return ResponseResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -148,12 +130,12 @@ public class SysRoleController {
|
||||
* @return 应答结果对象,包含角色列表。
|
||||
*/
|
||||
@PostMapping("/list")
|
||||
public ResponseResult<?> list(
|
||||
public ResponseResult<JSONObject> list(
|
||||
@MyRequestBody SysRole sysRoleFilter,
|
||||
@MyRequestBody MyOrderParam orderParam,
|
||||
@MyRequestBody MyPageParam pageParam) {
|
||||
if (pageParam != null) {
|
||||
PageHelper.startPage(pageParam.getPageNum(), pageParam.getPageSize());
|
||||
PageMethod.startPage(pageParam.getPageNum(), pageParam.getPageSize());
|
||||
}
|
||||
List<SysRole> roleList = sysRoleService.getSysRoleList(
|
||||
sysRoleFilter, MyOrderParam.buildOrderBy(orderParam, SysRole.class));
|
||||
@@ -168,21 +150,14 @@ public class SysRoleController {
|
||||
*/
|
||||
@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;
|
||||
return ResponseResult.error(ErrorCodeEnum.ARGUMENT_NULL_EXIST);
|
||||
}
|
||||
sysRole = sysRoleService.getSysRoleWithRelation(roleId);
|
||||
SysRole sysRole = sysRoleService.getByIdWithRelation(roleId, MyRelationParam.full());
|
||||
if (sysRole == null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST);
|
||||
}
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage, sysRole);
|
||||
return ResponseResult.success(sysRole);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -196,32 +171,23 @@ public class SysRoleController {
|
||||
* @return 应答结果对象,包含用户列表数据。
|
||||
*/
|
||||
@PostMapping("/listNotInUserRole")
|
||||
public ResponseResult<?> listNotInUserRole(
|
||||
public ResponseResult<JSONObject> 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;
|
||||
ResponseResult<Void> verifyResult = this.doRoleUserVerify(roleId);
|
||||
if (!verifyResult.isSuccess()) {
|
||||
return ResponseResult.errorFrom(verifyResult);
|
||||
}
|
||||
if (pageParam != null) {
|
||||
PageHelper.startPage(pageParam.getPageNum(), pageParam.getPageSize());
|
||||
PageMethod.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);
|
||||
JSONObject responseData = MyPageUtil.makeResponseData(resultList);
|
||||
return ResponseResult.success(responseData);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -234,31 +200,32 @@ public class SysRoleController {
|
||||
* @return 应答结果对象,包含用户列表数据。
|
||||
*/
|
||||
@PostMapping("/listUserRole")
|
||||
public ResponseResult<?> listUserRole(
|
||||
public ResponseResult<JSONObject> 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;
|
||||
ResponseResult<Void> verifyResult = this.doRoleUserVerify(roleId);
|
||||
if (!verifyResult.isSuccess()) {
|
||||
return ResponseResult.errorFrom(verifyResult);
|
||||
}
|
||||
if (pageParam != null) {
|
||||
PageHelper.startPage(pageParam.getPageNum(), pageParam.getPageSize());
|
||||
PageMethod.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);
|
||||
JSONObject responseData = MyPageUtil.makeResponseData(resultList);
|
||||
return ResponseResult.success(responseData);
|
||||
}
|
||||
|
||||
private ResponseResult<Void> doRoleUserVerify(Long roleId) {
|
||||
if (MyCommonUtil.existBlankArgument(roleId)) {
|
||||
return ResponseResult.error(ErrorCodeEnum.ARGUMENT_NULL_EXIST);
|
||||
}
|
||||
if (!sysRoleService.existId(roleId)) {
|
||||
return ResponseResult.error(ErrorCodeEnum.INVALID_RELATED_RECORD_ID);
|
||||
}
|
||||
return ResponseResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -269,21 +236,16 @@ public class SysRoleController {
|
||||
* @return 应答结果对象。
|
||||
*/
|
||||
@PostMapping("/addUserRole")
|
||||
public ResponseResult<?> addUserRole(
|
||||
public ResponseResult<Void> 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;
|
||||
return ResponseResult.error(ErrorCodeEnum.ARGUMENT_NULL_EXIST);
|
||||
}
|
||||
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;
|
||||
return ResponseResult.error(ErrorCodeEnum.INVALID_RELATED_RECORD_ID);
|
||||
}
|
||||
List<SysUserRole> userRoleList = new LinkedList<>();
|
||||
for (Long userId : userIdSet) {
|
||||
@@ -293,8 +255,7 @@ public class SysRoleController {
|
||||
userRoleList.add(userRole);
|
||||
}
|
||||
sysRoleService.addUserRoleList(userRoleList);
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage);
|
||||
return ResponseResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -305,21 +266,15 @@ public class SysRoleController {
|
||||
* @return 应答数据结果。
|
||||
*/
|
||||
@PostMapping("/deleteUserRole")
|
||||
public ResponseResult<?> deleteUserRole(
|
||||
public ResponseResult<Void> 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;
|
||||
return ResponseResult.error(ErrorCodeEnum.ARGUMENT_NULL_EXIST);
|
||||
}
|
||||
if (!sysRoleService.removeUserRole(roleId, userId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST);
|
||||
}
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage);
|
||||
return ResponseResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -331,23 +286,17 @@ public class SysRoleController {
|
||||
* @return 符合条件的角色列表。
|
||||
*/
|
||||
@PostMapping("/listAllRolesByPermCode")
|
||||
public ResponseResult<?> listAllRolesByPermCode(
|
||||
public ResponseResult<JSONObject> 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;
|
||||
return ResponseResult.error(ErrorCodeEnum.ARGUMENT_NULL_EXIST);
|
||||
}
|
||||
if (pageParam != null) {
|
||||
PageHelper.startPage(pageParam.getPageNum(), pageParam.getPageSize());
|
||||
PageMethod.startPage(pageParam.getPageNum(), pageParam.getPageSize());
|
||||
}
|
||||
List<SysRole> roleList = sysRoleService.getSysRoleListByPermCodeId(permCodeId);
|
||||
responseData = MyPageUtil.makeResponseData(roleList);
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage, responseData);
|
||||
JSONObject responseData = MyPageUtil.makeResponseData(roleList);
|
||||
return ResponseResult.success(responseData);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -359,22 +308,16 @@ public class SysRoleController {
|
||||
* @return 符合条件的角色列表。
|
||||
*/
|
||||
@PostMapping("/listAllRolesByPerm")
|
||||
public ResponseResult<?> listAllRolesByPerm(
|
||||
public ResponseResult<JSONObject> 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;
|
||||
return ResponseResult.error(ErrorCodeEnum.ARGUMENT_NULL_EXIST);
|
||||
}
|
||||
if (pageParam != null) {
|
||||
PageHelper.startPage(pageParam.getPageNum(), pageParam.getPageSize());
|
||||
PageMethod.startPage(pageParam.getPageNum(), pageParam.getPageSize());
|
||||
}
|
||||
List<SysRole> roleList = sysRoleService.getSysRoleListByPerm(url);
|
||||
responseData = MyPageUtil.makeResponseData(roleList);
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage, responseData);
|
||||
JSONObject responseData = MyPageUtil.makeResponseData(roleList);
|
||||
return ResponseResult.success(responseData);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.orange.admin.upms.controller;
|
||||
|
||||
import cn.jimmyshi.beanquery.BeanQuery;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.page.PageMethod;
|
||||
import com.orange.admin.upms.model.*;
|
||||
import com.orange.admin.upms.service.*;
|
||||
import com.orange.admin.common.core.object.*;
|
||||
@@ -22,7 +22,7 @@ import javax.validation.groups.Default;
|
||||
* 用户管理操作控制器类。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@@ -44,33 +44,25 @@ public class SysUserController {
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@PostMapping("/add")
|
||||
public ResponseResult<?> add(
|
||||
public ResponseResult<JSONObject> 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);
|
||||
String errorMessage = MyCommonUtil.getModelValidationError(sysUser);
|
||||
if (errorMessage != null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_VALIDATAED_FAILED;
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_VALIDATAED_FAILED, errorMessage);
|
||||
}
|
||||
VerifyResult result = sysUserService.verifyRelatedData(
|
||||
CallResult result = sysUserService.verifyRelatedData(
|
||||
sysUser, null, roleIdListString, dataPermIdListString);
|
||||
if (!result.isSuccess()) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_VALIDATAED_FAILED;
|
||||
errorMessage = result.getErrorMessage();
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_VALIDATAED_FAILED, result.getErrorMessage());
|
||||
}
|
||||
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();
|
||||
JSONObject responseData = new JSONObject();
|
||||
responseData.put("userId", sysUser.getUserId());
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage, responseData);
|
||||
return ResponseResult.success(responseData);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -83,39 +75,29 @@ public class SysUserController {
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@PostMapping("/update")
|
||||
public ResponseResult<?> update(
|
||||
public ResponseResult<Void> 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);
|
||||
String errorMessage = MyCommonUtil.getModelValidationError(sysUser, Default.class, UpdateGroup.class);
|
||||
if (errorMessage != null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_VALIDATAED_FAILED;
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_VALIDATAED_FAILED, errorMessage);
|
||||
}
|
||||
SysUser originalUser = sysUserService.getById(sysUser.getUserId());
|
||||
if (originalUser == null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST);
|
||||
}
|
||||
VerifyResult result = sysUserService.verifyRelatedData(
|
||||
CallResult result = sysUserService.verifyRelatedData(
|
||||
sysUser, originalUser, roleIdListString, dataPermIdListString);
|
||||
if (!result.isSuccess()) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_VALIDATAED_FAILED;
|
||||
errorMessage = result.getErrorMessage();
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_VALIDATAED_FAILED, result.getErrorMessage());
|
||||
}
|
||||
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;
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST);
|
||||
}
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage);
|
||||
return ResponseResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -125,21 +107,15 @@ public class SysUserController {
|
||||
* @return 应答结果对象。
|
||||
*/
|
||||
@PostMapping("/resetPassword")
|
||||
public ResponseResult<?> resetPassword(@MyRequestBody Long userId) {
|
||||
ErrorCodeEnum errorCodeEnum = ErrorCodeEnum.NO_ERROR;
|
||||
String errorMessage = null;
|
||||
do {
|
||||
public ResponseResult<Void> resetPassword(@MyRequestBody Long userId) {
|
||||
if (MyCommonUtil.existBlankArgument(userId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.ARGUMENT_NULL_EXIST;
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.ARGUMENT_NULL_EXIST);
|
||||
}
|
||||
if (!sysUserService.resetPassword(
|
||||
userId, applicationConfig.getDefaultUserPassword(), applicationConfig.getPasswordSalt())) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST);
|
||||
}
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage);
|
||||
return ResponseResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -149,29 +125,23 @@ public class SysUserController {
|
||||
* @return 应答结果对象。
|
||||
*/
|
||||
@PostMapping("/delete")
|
||||
public ResponseResult<?> delete(@MyRequestBody Long userId) {
|
||||
ErrorCodeEnum errorCodeEnum = ErrorCodeEnum.NO_ERROR;
|
||||
String errorMessage = null;
|
||||
do {
|
||||
public ResponseResult<Void> delete(@MyRequestBody Long userId) {
|
||||
String errorMessage;
|
||||
if (MyCommonUtil.existBlankArgument(userId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.ARGUMENT_NULL_EXIST;
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.ARGUMENT_NULL_EXIST);
|
||||
}
|
||||
// 验证关联Id的数据合法性
|
||||
SysUser originalSysUser = sysUserService.getById(userId);
|
||||
if (originalSysUser == null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
//TODO 修改下面方括号中的话述
|
||||
// NOTE: 修改下面方括号中的话述
|
||||
errorMessage = "数据验证失败,当前 [对象] 并不存在,请刷新后重试!";
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST, errorMessage);
|
||||
}
|
||||
if (!sysUserService.remove(userId)) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
errorMessage = "数据操作失败,删除的对象不存在,请刷新后重试!";
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST, errorMessage);
|
||||
}
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage);
|
||||
return ResponseResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -183,12 +153,12 @@ public class SysUserController {
|
||||
* @return 应答结果对象,包含查询结果集。
|
||||
*/
|
||||
@PostMapping("/list")
|
||||
public ResponseResult<?> list(
|
||||
public ResponseResult<JSONObject> list(
|
||||
@MyRequestBody SysUser sysUserFilter,
|
||||
@MyRequestBody MyOrderParam orderParam,
|
||||
@MyRequestBody MyPageParam pageParam) {
|
||||
if (pageParam != null) {
|
||||
PageHelper.startPage(pageParam.getPageNum(), pageParam.getPageSize());
|
||||
PageMethod.startPage(pageParam.getPageNum(), pageParam.getPageSize());
|
||||
}
|
||||
String orderBy = MyOrderParam.buildOrderBy(orderParam, SysUser.class);
|
||||
List<SysUser> resultList = sysUserService.getSysUserListWithRelation(sysUserFilter, orderBy);
|
||||
@@ -203,21 +173,15 @@ public class SysUserController {
|
||||
*/
|
||||
@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;
|
||||
return ResponseResult.error(ErrorCodeEnum.ARGUMENT_NULL_EXIST);
|
||||
}
|
||||
sysUser = sysUserService.getByIdWithRelation(userId);
|
||||
// 这里查看用户数据时候,需要把用户多对多关联的角色和数据权限Id一并查出。
|
||||
SysUser sysUser = sysUserService.getByIdWithRelation(userId, MyRelationParam.full());
|
||||
if (sysUser == null) {
|
||||
errorCodeEnum = ErrorCodeEnum.DATA_NOT_EXIST;
|
||||
break;
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST);
|
||||
}
|
||||
} while (false);
|
||||
return ResponseResult.create(errorCodeEnum, errorMessage, sysUser);
|
||||
return ResponseResult.success(sysUser);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -228,8 +192,8 @@ public class SysUserController {
|
||||
* @return 应答结果对象,包含的数据为 List<Map<String, String>>,map中包含两条记录,key的值分别是id和name,value对应具体数据。
|
||||
*/
|
||||
@GetMapping("/listDictSysUser")
|
||||
public ResponseResult<?> listDictSysUser(SysUser filter) {
|
||||
List<SysUser> resultList = sysUserService.getListByFilter(filter);
|
||||
public ResponseResult<List<Map<String, Object>>> listDictSysUser(SysUser filter) {
|
||||
List<SysUser> resultList = sysUserService.getListByFilter(filter, null);
|
||||
return ResponseResult.success(BeanQuery.select(
|
||||
"userId as id", "loginName as name").executeFrom(resultList));
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import com.orange.admin.upms.model.SysDataPermDept;
|
||||
* 数据权限与部门关系数据访问操作接口。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
public interface SysDataPermDeptMapper extends BaseDaoMapper<SysDataPermDept> {
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import java.util.List;
|
||||
* NOTE: 该对象一定不能被 @EnableDataPerm 注解标注,否则会导致无限递归。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
public interface SysDataPermMapper extends BaseDaoMapper<SysDataPerm> {
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import java.util.List;
|
||||
* 数据权限与菜单关系数据访问操作接口。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
public interface SysDataPermMenuMapper extends BaseDaoMapper<SysDataPermMenu> {
|
||||
|
||||
|
||||
@@ -9,18 +9,10 @@ import java.util.List;
|
||||
* 数据权限与用户关系数据访问操作接口。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
public interface SysDataPermUserMapper extends BaseDaoMapper<SysDataPermUser> {
|
||||
|
||||
/**
|
||||
* 获取用户的数据权限Id列表。
|
||||
*
|
||||
* @param userId 用户Id。
|
||||
* @return 数据权限Id列表。
|
||||
*/
|
||||
List<Long> getDataPermIdListByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* 批量添加数据权限和用户关系的列表。
|
||||
*
|
||||
|
||||
@@ -10,7 +10,7 @@ import java.util.*;
|
||||
* 部门管理数据操作访问接口。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
public interface SysDeptMapper extends BaseDaoMapper<SysDept> {
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import java.util.List;
|
||||
* 菜单数据访问操作接口。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
public interface SysMenuMapper extends BaseDaoMapper<SysMenu> {
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import com.orange.admin.upms.model.SysMenuPermCode;
|
||||
* 菜单与权限字关系数据访问操作接口。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
public interface SysMenuPermCodeMapper extends BaseDaoMapper<SysMenuPermCode> {
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import java.util.Map;
|
||||
* 权限字数据访问操作接口。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
public interface SysPermCodeMapper extends BaseDaoMapper<SysPermCode> {
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import com.orange.admin.upms.model.SysPermCodePerm;
|
||||
* 权限字与权限资源关系数据访问操作接口。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
public interface SysPermCodePermMapper extends BaseDaoMapper<SysPermCodePerm> {
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import java.util.Map;
|
||||
* 权限资源数据访问操作接口。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
public interface SysPermMapper extends BaseDaoMapper<SysPerm> {
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import java.util.List;
|
||||
* 权限资源模块数据访问操作接口。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
public interface SysPermModuleMapper extends BaseDaoMapper<SysPermModule> {
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import com.orange.admin.upms.model.SysPermWhitelist;
|
||||
* 权限资源白名单数据访问操作接口。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
public interface SysPermWhitelistMapper extends BaseDaoMapper<SysPermWhitelist> {
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import java.util.List;
|
||||
* 角色数据访问操作接口。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
public interface SysRoleMapper extends BaseDaoMapper<SysRole> {
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import com.orange.admin.upms.model.SysRoleMenu;
|
||||
* 角色与菜单操作关联关系数据访问操作接口。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
public interface SysRoleMenuMapper extends BaseDaoMapper<SysRoleMenu> {
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import java.util.*;
|
||||
* 用户管理数据操作访问接口。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
public interface SysUserMapper extends BaseDaoMapper<SysUser> {
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ 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;
|
||||
|
||||
@@ -10,18 +9,10 @@ import java.util.List;
|
||||
* 用户与角色关联关系数据访问操作接口。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
public interface SysUserRoleMapper extends BaseDaoMapper<SysUserRole> {
|
||||
|
||||
/**
|
||||
* 获取用户的角色Id列表。
|
||||
*
|
||||
* @param userId 用户Id。
|
||||
* @return 角色Id列表。
|
||||
*/
|
||||
List<Long> getRoleIdListByUserId(@Param("userId") Long userId);
|
||||
|
||||
/**
|
||||
* 批量插入用户角色信息,如果用户角色已经存在,则不会重复插入。
|
||||
*
|
||||
|
||||
@@ -6,10 +6,6 @@
|
||||
<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=",">
|
||||
|
||||
@@ -6,10 +6,6 @@
|
||||
<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=",">
|
||||
|
||||
@@ -2,16 +2,23 @@ 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.annotation.RelationManyToMany;
|
||||
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.*;
|
||||
|
||||
/**
|
||||
* 数据权限实体对象。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
@Data
|
||||
@Table(name = "zz_sys_data_perm")
|
||||
public class SysDataPerm {
|
||||
@@ -72,9 +79,17 @@ public class SysDataPerm {
|
||||
@Column(name = "deleted_flag")
|
||||
private Integer deletedFlag;
|
||||
|
||||
@RelationManyToMany(
|
||||
relationMapperName = "sysDataPermDeptMapper",
|
||||
relationMasterIdField = "dataPermId",
|
||||
relationModelClass = SysDataPermDept.class)
|
||||
@Transient
|
||||
private List<SysDataPermDept> dataPermDeptList;
|
||||
|
||||
@RelationManyToMany(
|
||||
relationMapperName = "sysDataPermMenuMapper",
|
||||
relationMasterIdField = "dataPermId",
|
||||
relationModelClass = SysDataPermMenu.class)
|
||||
@Transient
|
||||
private List<SysDataPermMenu> dataPermMenuList;
|
||||
|
||||
|
||||
@@ -7,6 +7,12 @@ import javax.persistence.Column;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
/**
|
||||
* 数据权限与部门关联实体对象。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
@Data
|
||||
@ToString(of = {"deptId"})
|
||||
@Table(name = "zz_sys_data_perm_dept")
|
||||
|
||||
@@ -4,6 +4,12 @@ import lombok.Data;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
/**
|
||||
* 数据权限与菜单关联实体对象。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
@Data
|
||||
@Table(name = "zz_sys_data_perm_menu")
|
||||
public class SysDataPermMenu {
|
||||
|
||||
@@ -4,6 +4,12 @@ import lombok.Data;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
/**
|
||||
* 数据权限与用户关联实体对象。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
@Data
|
||||
@Table(name = "zz_sys_data_perm_user")
|
||||
public class SysDataPermUser {
|
||||
|
||||
@@ -10,6 +10,12 @@ import javax.validation.constraints.*;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* SysDept实体对象。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
@Data
|
||||
@Table(name = "zz_sys_dept")
|
||||
public class SysDept {
|
||||
|
||||
@@ -2,6 +2,7 @@ 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.RelationManyToMany;
|
||||
import com.orange.admin.common.core.validator.ConstDictRef;
|
||||
import com.orange.admin.common.core.validator.UpdateGroup;
|
||||
import com.orange.admin.upms.model.constant.SysMenuType;
|
||||
@@ -12,6 +13,12 @@ import javax.validation.constraints.*;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 菜单实体对象。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
@Data
|
||||
@Table(name = "zz_sys_menu")
|
||||
public class SysMenu {
|
||||
@@ -77,6 +84,10 @@ public class SysMenu {
|
||||
@Column(name = "deleted_flag")
|
||||
private Integer deletedFlag;
|
||||
|
||||
@RelationManyToMany(
|
||||
relationMapperName = "sysMenuPermCodeMapper",
|
||||
relationMasterIdField = "menuId",
|
||||
relationModelClass = SysMenuPermCode.class)
|
||||
@Transient
|
||||
private List<Long> permCodeIdList;
|
||||
private List<SysMenuPermCode> sysMenuPermCodeList;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,12 @@ import lombok.Data;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
/**
|
||||
* 菜单与权限字关联实体对象。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
@Data
|
||||
@Table(name = "zz_sys_menu_perm_code")
|
||||
public class SysMenuPermCode {
|
||||
|
||||
@@ -11,6 +11,12 @@ import javax.validation.constraints.*;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 权限资源实体对象。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
@Data
|
||||
@Table(name = "zz_sys_perm")
|
||||
public class SysPerm {
|
||||
|
||||
@@ -2,6 +2,7 @@ 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.RelationManyToMany;
|
||||
import com.orange.admin.common.core.validator.ConstDictRef;
|
||||
import com.orange.admin.common.core.validator.UpdateGroup;
|
||||
import com.orange.admin.upms.model.constant.SysPermCodeType;
|
||||
@@ -12,6 +13,12 @@ import javax.validation.constraints.*;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 权限字实体对象。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
@Data
|
||||
@Table(name = "zz_sys_perm_code")
|
||||
public class SysPermCode {
|
||||
@@ -73,6 +80,10 @@ public class SysPermCode {
|
||||
@Column(name = "deleted_flag")
|
||||
private Integer deletedFlag;
|
||||
|
||||
@RelationManyToMany(
|
||||
relationMapperName = "sysPermCodePermMapper",
|
||||
relationMasterIdField = "permCodeId",
|
||||
relationModelClass = SysPermCodePerm.class)
|
||||
@Transient
|
||||
private List<Long> permIdList;
|
||||
private List<SysPermCodePerm> sysPermCodePermList;
|
||||
}
|
||||
@@ -4,6 +4,12 @@ import lombok.Data;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
/**
|
||||
* 权限字与权限资源关联实体对象。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
@Data
|
||||
@Table(name = "zz_sys_perm_code_perm")
|
||||
public class SysPermCodePerm {
|
||||
|
||||
@@ -12,6 +12,12 @@ import javax.validation.constraints.*;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 权限模块实体对象。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
@Data
|
||||
@Table(name = "zz_sys_perm_module")
|
||||
public class SysPermModule {
|
||||
|
||||
@@ -4,6 +4,12 @@ import lombok.Data;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
/**
|
||||
* 白名单实体对象。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
@Data
|
||||
@Table(name = "zz_sys_perm_whitelist")
|
||||
public class SysPermWhitelist {
|
||||
|
||||
@@ -2,8 +2,9 @@ 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 com.orange.admin.common.core.annotation.RelationManyToMany;
|
||||
import com.orange.admin.common.core.validator.UpdateGroup;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.persistence.*;
|
||||
@@ -11,6 +12,12 @@ import javax.validation.constraints.*;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 角色实体对象。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
@Data
|
||||
@Table(name = "zz_sys_role")
|
||||
public class SysRole {
|
||||
@@ -63,8 +70,12 @@ public class SysRole {
|
||||
@Column(name = "deleted_flag")
|
||||
private Integer deletedFlag;
|
||||
|
||||
@RelationManyToMany(
|
||||
relationMapperName = "sysRoleMenuMapper",
|
||||
relationMasterIdField = "roleId",
|
||||
relationModelClass = SysRoleMenu.class)
|
||||
@Transient
|
||||
private List<Long> menuIdList;
|
||||
private List<SysRoleMenu> sysRoleMenuList;
|
||||
|
||||
@Transient
|
||||
private String createTimeStart;
|
||||
|
||||
@@ -4,6 +4,12 @@ import lombok.Data;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
/**
|
||||
* 角色菜单实体对象。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
@Data
|
||||
@Table(name = "zz_sys_role_menu")
|
||||
public class SysRoleMenu {
|
||||
|
||||
@@ -4,6 +4,7 @@ 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.RelationManyToMany;
|
||||
import com.orange.admin.common.core.annotation.DeletedFlagColumn;
|
||||
import com.orange.admin.common.core.annotation.JobUpdateTimeColumn;
|
||||
import com.orange.admin.common.core.validator.UpdateGroup;
|
||||
@@ -16,6 +17,12 @@ import java.util.Date;
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* SysUser实体对象。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
@Data
|
||||
@Table(name = "zz_sys_user")
|
||||
public class SysUser {
|
||||
@@ -123,16 +130,24 @@ public class SysUser {
|
||||
private String createTimeEnd;
|
||||
|
||||
/**
|
||||
* 与当前用户关联的角色Id集合。
|
||||
* 多对多用户角色数据集合。
|
||||
*/
|
||||
@RelationManyToMany(
|
||||
relationMapperName = "sysUserRoleMapper",
|
||||
relationMasterIdField = "userId",
|
||||
relationModelClass = SysUserRole.class)
|
||||
@Transient
|
||||
private List<Long> roleIdList;
|
||||
private List<SysUserRole> sysUserRoleList;
|
||||
|
||||
/**
|
||||
* 与当前用户关联的数据权限Id集合。
|
||||
* 多对多用户数据权限数据集合。
|
||||
*/
|
||||
@RelationManyToMany(
|
||||
relationMapperName = "sysDataPermUserMapper",
|
||||
relationMasterIdField = "userId",
|
||||
relationModelClass = SysDataPermUser.class)
|
||||
@Transient
|
||||
private List<Long> dataPermIdList;
|
||||
private List<SysDataPermUser> sysDataPermUserList;
|
||||
|
||||
@RelationConstDict(
|
||||
masterIdField = "userType",
|
||||
|
||||
@@ -4,6 +4,12 @@ import lombok.Data;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
/**
|
||||
* 用户角色实体对象。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
@Data
|
||||
@Table(name = "zz_sys_user_role")
|
||||
public class SysUserRole {
|
||||
|
||||
@@ -7,7 +7,7 @@ import java.util.Map;
|
||||
* 菜单类型常量对象。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
public final class SysMenuType {
|
||||
|
||||
@@ -28,7 +28,7 @@ public final class SysMenuType {
|
||||
*/
|
||||
public static final int TYPE_BUTTON = 3;
|
||||
|
||||
public static final Map<Object, String> DICT_MAP = new HashMap<>(4);
|
||||
private static final Map<Object, String> DICT_MAP = new HashMap<>(4);
|
||||
static {
|
||||
DICT_MAP.put(0, "目录菜单");
|
||||
DICT_MAP.put(1, "普通菜单");
|
||||
@@ -42,8 +42,8 @@ public final class SysMenuType {
|
||||
* @param value 待验证的参数值。
|
||||
* @return 合法返回true,否则false。
|
||||
*/
|
||||
public static boolean isValid(int value) {
|
||||
return DICT_MAP.containsKey(value);
|
||||
public static boolean isValid(Integer value) {
|
||||
return value != null && DICT_MAP.containsKey(value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,7 +7,7 @@ import java.util.Map;
|
||||
* 权限字类型常量对象。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
public final class SysPermCodeType {
|
||||
|
||||
@@ -24,7 +24,7 @@ public final class SysPermCodeType {
|
||||
*/
|
||||
public static final int TYPE_OPERATION = 2;
|
||||
|
||||
public static final Map<Object, String> DICT_MAP = new HashMap<>(3);
|
||||
private static final Map<Object, String> DICT_MAP = new HashMap<>(3);
|
||||
static {
|
||||
DICT_MAP.put(0, "表单权限字");
|
||||
DICT_MAP.put(1, "表单片段布局权限字");
|
||||
@@ -37,8 +37,8 @@ public final class SysPermCodeType {
|
||||
* @param value 待验证的参数值。
|
||||
* @return 合法返回true,否则false。
|
||||
*/
|
||||
public static boolean isValid(int value) {
|
||||
return DICT_MAP.containsKey(value);
|
||||
public static boolean isValid(Integer value) {
|
||||
return value != null && DICT_MAP.containsKey(value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,7 +7,7 @@ import java.util.Map;
|
||||
* 权限资源模块类型常量对象。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
public final class SysPermModuleType {
|
||||
|
||||
@@ -20,7 +20,7 @@ public final class SysPermModuleType {
|
||||
*/
|
||||
public static final int TYPE_CONTROLLER = 1;
|
||||
|
||||
public static final Map<Object, String> DICT_MAP = new HashMap<>(2);
|
||||
private static final Map<Object, String> DICT_MAP = new HashMap<>(2);
|
||||
static {
|
||||
DICT_MAP.put(0, "普通模块");
|
||||
DICT_MAP.put(1, "controller接口模块");
|
||||
@@ -32,8 +32,8 @@ public final class SysPermModuleType {
|
||||
* @param value 待验证的参数值。
|
||||
* @return 合法返回true,否则false。
|
||||
*/
|
||||
public static boolean isValid(int value) {
|
||||
return DICT_MAP.containsKey(value);
|
||||
public static boolean isValid(Integer value) {
|
||||
return value != null && DICT_MAP.containsKey(value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,6 +3,12 @@ package com.orange.admin.upms.model.constant;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 用户状态常量字典对象。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
public final class SysUserStatus {
|
||||
|
||||
/**
|
||||
@@ -14,7 +20,7 @@ public final class SysUserStatus {
|
||||
*/
|
||||
public static final int STATUS_LOCKED = 1;
|
||||
|
||||
public static final Map<Object, String> DICT_MAP = new HashMap<>(2);
|
||||
private static final Map<Object, String> DICT_MAP = new HashMap<>(2);
|
||||
static {
|
||||
DICT_MAP.put(STATUS_NORMAL, "正常状态");
|
||||
DICT_MAP.put(STATUS_LOCKED, "锁定状态");
|
||||
@@ -26,8 +32,8 @@ public final class SysUserStatus {
|
||||
* @param value 待验证的参数值。
|
||||
* @return 合法返回true,否则false。
|
||||
*/
|
||||
public static boolean isValid(int value) {
|
||||
return DICT_MAP.containsKey(value);
|
||||
public static boolean isValid(Integer value) {
|
||||
return value != null && DICT_MAP.containsKey(value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,6 +3,12 @@ package com.orange.admin.upms.model.constant;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 用户类型常量字典对象。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
public final class SysUserType {
|
||||
|
||||
/**
|
||||
@@ -18,7 +24,7 @@ public final class SysUserType {
|
||||
*/
|
||||
public static final int TYPE_OPERATOR = 2;
|
||||
|
||||
public static final Map<Object, String> DICT_MAP = new HashMap<>(3);
|
||||
private static final Map<Object, String> DICT_MAP = new HashMap<>(3);
|
||||
static {
|
||||
DICT_MAP.put(TYPE_ADMIN, "管理员");
|
||||
DICT_MAP.put(TYPE_SYSTEM, "系统操作员");
|
||||
@@ -31,8 +37,8 @@ public final class SysUserType {
|
||||
* @param value 待验证的参数值。
|
||||
* @return 合法返回true,否则false。
|
||||
*/
|
||||
public static boolean isValid(int value) {
|
||||
return DICT_MAP.containsKey(value);
|
||||
public static boolean isValid(Integer value) {
|
||||
return value != null && DICT_MAP.containsKey(value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package com.orange.admin.upms.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.orange.admin.common.biz.base.service.BaseBizService;
|
||||
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.common.core.object.CallResult;
|
||||
import com.orange.admin.upms.dao.SysDataPermDeptMapper;
|
||||
import com.orange.admin.upms.dao.SysDataPermMapper;
|
||||
import com.orange.admin.upms.dao.SysDataPermUserMapper;
|
||||
@@ -29,10 +29,10 @@ import java.util.stream.Collectors;
|
||||
* 数据权限数据服务类。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
@Service
|
||||
public class SysDataPermService extends BaseService<SysDataPerm, Long> {
|
||||
public class SysDataPermService extends BaseBizService<SysDataPerm, Long> {
|
||||
|
||||
@Autowired
|
||||
private SysDataPermMapper sysDataPermMapper;
|
||||
@@ -67,7 +67,7 @@ public class SysDataPermService extends BaseService<SysDataPerm, Long> {
|
||||
* @param dataPermMenuList 关联的菜单对象列表。
|
||||
* @return 新增后的数据权限对象。
|
||||
*/
|
||||
@Transactional
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public SysDataPerm saveNew(SysDataPerm dataPerm, Set<Long> deptIdSet, List<SysDataPermMenu> dataPermMenuList) {
|
||||
dataPerm.setDataPermId(idGenerator.nextLongId());
|
||||
TokenData tokenData = TokenData.takeFromRequest();
|
||||
@@ -91,7 +91,7 @@ public class SysDataPermService extends BaseService<SysDataPerm, Long> {
|
||||
* @param dataPermMenuList 关联的菜单对象列表。
|
||||
* @return 更新成功返回true,否则false。
|
||||
*/
|
||||
@Transactional
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean update(
|
||||
SysDataPerm dataPerm,
|
||||
SysDataPerm originalDataPerm,
|
||||
@@ -121,7 +121,7 @@ public class SysDataPermService extends BaseService<SysDataPerm, Long> {
|
||||
* @param dataPermId 数据权限主键Id。
|
||||
* @return 删除成功返回true,否则false。
|
||||
*/
|
||||
@Transactional
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean remove(Long dataPermId) {
|
||||
SysDataPerm dataPerm = new SysDataPerm();
|
||||
dataPerm.setDataPermId(dataPermId);
|
||||
@@ -152,27 +152,6 @@ public class SysDataPermService extends BaseService<SysDataPerm, Long> {
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将指定用户的指定会话的数据权限集合存入缓存。
|
||||
*
|
||||
@@ -182,7 +161,7 @@ public class SysDataPermService extends BaseService<SysDataPerm, Long> {
|
||||
* @param isAdmin 是否是管理员。
|
||||
* @return 查询并缓存后的数据权限集合。返回格式为,Map<MenuId, Map<RuleType, DeptIdString>>。
|
||||
*/
|
||||
@CachePut(value = "DataPermissionCache", key = "#sessionId")
|
||||
@CachePut(value = "DATA_PERMISSION_CACHE", key = "#sessionId")
|
||||
public Map<Object, Map<Integer, String>> putDataPermCache(
|
||||
String sessionId, Long userId, Long deptId, boolean isAdmin) {
|
||||
// 管理员账户返回空对象,便于缓存的统一处理。
|
||||
@@ -194,7 +173,7 @@ public class SysDataPermService extends BaseService<SysDataPerm, Long> {
|
||||
*
|
||||
* @param sessionId 会话Id。
|
||||
*/
|
||||
@CacheEvict(value = "DataPermissionCache", key = "#sessionId")
|
||||
@CacheEvict(value = "DATA_PERMISSION_CACHE", key = "#sessionId")
|
||||
public void removeDataPermCache(String sessionId) {
|
||||
// 空实现即可,只是通过注解将当前sessionId从cache中删除。
|
||||
}
|
||||
@@ -208,7 +187,7 @@ public class SysDataPermService extends BaseService<SysDataPerm, Long> {
|
||||
*/
|
||||
public Map<Object, Map<Integer, String>> getSysDataPermMenuListByUserId(Long userId, Long deptId) {
|
||||
List<SysDataPermMenu> dataPermMenuList = sysDataPermMenuMapper.getSysDataPermMenuListByUserId(userId);
|
||||
if (dataPermMenuList.size() == 0) {
|
||||
if (dataPermMenuList.isEmpty()) {
|
||||
return new HashMap<>(1);
|
||||
}
|
||||
// 这里用代码的方式把deptId组装到SysDataPermMenu中。
|
||||
@@ -226,7 +205,12 @@ public class SysDataPermService extends BaseService<SysDataPerm, Long> {
|
||||
dataPermMenu.setDeptIdListString(StringUtils.join(deptIdSet, ","));
|
||||
}
|
||||
}
|
||||
// 由于同一用户可能属于多个数据权限,所以需要先进行基于menuId的权限合并。
|
||||
// 由于同一用户可能属于多个数据权限,所以需要进行基于menuId的权限合并。
|
||||
return mergeDataPermMenuList(dataPermMenuList, deptId);
|
||||
}
|
||||
|
||||
private Map<Object, Map<Integer, String>> mergeDataPermMenuList(
|
||||
List<SysDataPermMenu> dataPermMenuList, Long deptId) {
|
||||
Map<Object, List<SysDataPermMenu>> menuMap =
|
||||
dataPermMenuList.stream().collect(Collectors.groupingBy(SysDataPermMenu::getMenuId));
|
||||
Map<Object, Map<Integer, String>> resultMap = new HashMap<>(menuMap.size());
|
||||
@@ -244,18 +228,9 @@ public class SysDataPermService extends BaseService<SysDataPerm, Long> {
|
||||
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, ','));
|
||||
String deptIds = processMultiDept(ruleMap, deptId);
|
||||
if (deptIds != null) {
|
||||
m.put(DataPermRuleType.TYPE_CUSTOM_DETP_LIST, deptIds);
|
||||
}
|
||||
// 最后处理当前部门和当前用户。
|
||||
if (ruleMap.get(DataPermRuleType.TYPE_DEPT_ONLY) != null) {
|
||||
@@ -269,13 +244,30 @@ public class SysDataPermService extends BaseService<SysDataPerm, Long> {
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
private String processMultiDept(Map<Integer, List<SysDataPermMenu>> ruleMap, Long deptId) {
|
||||
List<SysDataPermMenu> customDeptList = ruleMap.get(DataPermRuleType.TYPE_CUSTOM_DETP_LIST);
|
||||
if (customDeptList == null) {
|
||||
return 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);
|
||||
}
|
||||
return StringUtils.join(deptIdSet, ',');
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加用户和数据权限之间的多对多关联关系。
|
||||
*
|
||||
* @param dataPermId 数据权限Id。
|
||||
* @param userIdSet 关联的用户Id列表。
|
||||
*/
|
||||
@Transactional
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void addDataPermUserList(Long dataPermId, Set<Long> userIdSet) {
|
||||
List<SysDataPermUser> dataPermUserList = new LinkedList<>();
|
||||
for (Long userId : userIdSet) {
|
||||
@@ -293,7 +285,7 @@ public class SysDataPermService extends BaseService<SysDataPerm, Long> {
|
||||
* @param dataPermId 数据权限主键Id。
|
||||
* @param userId 用户主键Id。
|
||||
*/
|
||||
@Transactional
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean removeDataPermUser(Long dataPermId, Long userId) {
|
||||
SysDataPermUser dataPermUser = new SysDataPermUser();
|
||||
dataPermUser.setDataPermId(dataPermId);
|
||||
@@ -309,29 +301,24 @@ public class SysDataPermService extends BaseService<SysDataPerm, Long> {
|
||||
* @param menuIdListString 与数据权限关联的菜单Id列表。
|
||||
* @return 验证结果。
|
||||
*/
|
||||
public VerifyResult verifyRelatedData(SysDataPerm dataPerm, String deptIdListString, String menuIdListString) {
|
||||
String errorMessage = null;
|
||||
public CallResult verifyRelatedData(SysDataPerm dataPerm, String deptIdListString, String menuIdListString) {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
do {
|
||||
if (dataPerm.getRuleType() == DataPermRuleType.TYPE_CUSTOM_DETP_LIST) {
|
||||
if (StringUtils.isBlank(deptIdListString)) {
|
||||
errorMessage = "数据验证失败,部门列表不能为空!";
|
||||
break;
|
||||
return CallResult.error("数据验证失败,部门列表不能为空!");
|
||||
}
|
||||
Set<Long> deptIdSet = Arrays.stream(StringUtils.split(
|
||||
deptIdListString, ",")).map(Long::valueOf).collect(Collectors.toSet());
|
||||
if (!sysDeptService.existUniqueKeyList("deptId", deptIdSet)) {
|
||||
errorMessage = "数据验证失败,存在不合法的部门数据,请刷新后重试!";
|
||||
break;
|
||||
if (!sysDeptService.existAllPrimaryKeys(deptIdSet)) {
|
||||
return CallResult.error("数据验证失败,存在不合法的部门数据,请刷新后重试!");
|
||||
}
|
||||
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;
|
||||
if (!sysMenuService.existAllPrimaryKeys(menuIdSet)) {
|
||||
return CallResult.error("数据验证失败,存在不合法的菜单,请刷新后重试!");
|
||||
}
|
||||
List<SysDataPermMenu> dataPermMenuList = new LinkedList<>();
|
||||
for (Long menuId : menuIdSet) {
|
||||
@@ -340,8 +327,7 @@ public class SysDataPermService extends BaseService<SysDataPerm, Long> {
|
||||
dataPermMenuList.add(dataPermMenu);
|
||||
}
|
||||
jsonObject.put("dataPermMenuList", dataPermMenuList);
|
||||
} while (false);
|
||||
return VerifyResult.create(errorMessage, jsonObject);
|
||||
return CallResult.ok(jsonObject);
|
||||
}
|
||||
|
||||
private void insertRelationData(
|
||||
|
||||
@@ -2,11 +2,12 @@ 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.core.object.MyRelationParam;
|
||||
import com.orange.admin.common.biz.base.service.BaseBizService;
|
||||
import com.orange.admin.common.biz.util.BasicIdGenerator;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -19,10 +20,10 @@ import java.util.*;
|
||||
* 部门管理数据操作服务类。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
@Service
|
||||
public class SysDeptService extends BaseService<SysDept, Long> {
|
||||
public class SysDeptService extends BaseBizService<SysDept, Long> {
|
||||
|
||||
@Autowired
|
||||
private SysDeptMapper sysDeptMapper;
|
||||
@@ -47,7 +48,7 @@ public class SysDeptService extends BaseService<SysDept, Long> {
|
||||
* @param sysDept 新增的部门对象。
|
||||
* @return 新增后的部门对象。
|
||||
*/
|
||||
@Transactional
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public SysDept saveNew(SysDept sysDept) {
|
||||
sysDept.setDeptId(idGenerator.nextLongId());
|
||||
sysDept.setDeletedFlag(GlobalDeletedFlag.NORMAL);
|
||||
@@ -68,7 +69,7 @@ public class SysDeptService extends BaseService<SysDept, Long> {
|
||||
* @param originalSysDept 原有的部门对象。
|
||||
* @return 更新成功返回true,否则false。
|
||||
*/
|
||||
@Transactional
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean update(SysDept sysDept, SysDept originalSysDept) {
|
||||
sysDept.setCreateUserId(originalSysDept.getCreateUserId());
|
||||
sysDept.setCreateUsername(originalSysDept.getCreateUsername());
|
||||
@@ -84,12 +85,12 @@ public class SysDeptService extends BaseService<SysDept, Long> {
|
||||
* @param deptId 主键Id。
|
||||
* @return 成功返回true,否则false。
|
||||
*/
|
||||
@Transactional
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
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);
|
||||
c.andEqualTo(super.idFieldName, deptId);
|
||||
c.andEqualTo(super.deletedFlagFieldName, GlobalDeletedFlag.NORMAL);
|
||||
// 这里先删除主数据
|
||||
SysDept deletedObject = new SysDept();
|
||||
deletedObject.setDeletedFlag(GlobalDeletedFlag.DELETED);
|
||||
@@ -97,9 +98,9 @@ public class SysDeptService extends BaseService<SysDept, Long> {
|
||||
return false;
|
||||
}
|
||||
// 这里可继续删除关联数据。
|
||||
Example dataPermDeptExample = new Example(SysDataPermDept.class);
|
||||
dataPermDeptExample.createCriteria().andEqualTo("deptId", deptId);
|
||||
sysDataPermDeptMapper.deleteByExample(dataPermDeptExample);
|
||||
SysDataPermDept dataPermDept = new SysDataPermDept();
|
||||
dataPermDept.setDeptId(deptId);
|
||||
sysDataPermDeptMapper.delete(dataPermDept);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -126,7 +127,7 @@ public class SysDeptService extends BaseService<SysDept, Long> {
|
||||
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);
|
||||
this.buildRelationForDataList(resultList, MyRelationParam.normal(), criteriaMap);
|
||||
return resultList;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package com.orange.admin.upms.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.orange.admin.common.biz.base.service.BaseBizService;
|
||||
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.common.core.object.CallResult;
|
||||
import com.orange.admin.upms.dao.SysMenuMapper;
|
||||
import com.orange.admin.upms.dao.SysMenuPermCodeMapper;
|
||||
import com.orange.admin.upms.dao.SysRoleMenuMapper;
|
||||
@@ -28,10 +28,10 @@ import java.util.stream.Collectors;
|
||||
* 菜单数据服务类。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
@Service
|
||||
public class SysMenuService extends BaseService<SysMenu, Long> {
|
||||
public class SysMenuService extends BaseBizService<SysMenu, Long> {
|
||||
|
||||
@Autowired
|
||||
private SysMenuMapper sysMenuMapper;
|
||||
@@ -63,7 +63,7 @@ public class SysMenuService extends BaseService<SysMenu, Long> {
|
||||
* @param permCodeIdSet 权限字Id列表。
|
||||
* @return 新增后的菜单对象。
|
||||
*/
|
||||
@Transactional
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public SysMenu saveNew(SysMenu sysMenu, Set<Long> permCodeIdSet) {
|
||||
sysMenu.setMenuId(idGenerator.nextLongId());
|
||||
sysMenu.setCreateTime(new Date());
|
||||
@@ -90,7 +90,7 @@ public class SysMenuService extends BaseService<SysMenu, Long> {
|
||||
* @param permCodeIdSet 权限字Id列表。
|
||||
* @return 更新成功返回true,否则false。
|
||||
*/
|
||||
@Transactional
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean update(SysMenu sysMenu, SysMenu originalSysMenu, Set<Long> permCodeIdSet) {
|
||||
sysMenu.setCreateTime(originalSysMenu.getCreateTime());
|
||||
sysMenu.setMenuType(originalSysMenu.getMenuType());
|
||||
@@ -98,9 +98,9 @@ public class SysMenuService extends BaseService<SysMenu, Long> {
|
||||
if (sysMenuMapper.updateByPrimaryKey(sysMenu) != 1) {
|
||||
return false;
|
||||
}
|
||||
Example e = new Example(SysMenuPermCode.class);
|
||||
e.createCriteria().andEqualTo("menuId", sysMenu.getMenuId());
|
||||
sysMenuPermCodeMapper.deleteByExample(e);
|
||||
SysMenuPermCode deletedMenuPermCode = new SysMenuPermCode();
|
||||
deletedMenuPermCode.setMenuId(sysMenu.getMenuId());
|
||||
sysMenuPermCodeMapper.delete(deletedMenuPermCode);
|
||||
if (permCodeIdSet != null) {
|
||||
List<SysMenuPermCode> sysMenuPermCodeList = new LinkedList<>();
|
||||
for (Long permCodeId : permCodeIdSet) {
|
||||
@@ -120,7 +120,7 @@ public class SysMenuService extends BaseService<SysMenu, Long> {
|
||||
* @param menuId 菜单主键Id。
|
||||
* @return 删除成功返回true,否则false。
|
||||
*/
|
||||
@Transactional
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean remove(Long menuId) {
|
||||
SysMenu menu = new SysMenu();
|
||||
menu.setMenuId(menuId);
|
||||
@@ -128,15 +128,15 @@ public class SysMenuService extends BaseService<SysMenu, Long> {
|
||||
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);
|
||||
SysRoleMenu roleMenu = new SysRoleMenu();
|
||||
roleMenu.setMenuId(menuId);
|
||||
sysRoleMenuMapper.delete(roleMenu);
|
||||
SysMenuPermCode menuPermCode = new SysMenuPermCode();
|
||||
menuPermCode.setMenuId(menuId);
|
||||
sysMenuPermCodeMapper.delete(menuPermCode);
|
||||
SysDataPermMenu dataPermMenu = new SysDataPermMenu();
|
||||
dataPermMenu.setMenuId(menuId);
|
||||
sysDataPermMenuMapper.delete(dataPermMenu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -164,27 +164,6 @@ public class SysMenuService extends BaseService<SysMenu, Long> {
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断当前菜单是否存在子菜单。
|
||||
*
|
||||
@@ -205,59 +184,58 @@ public class SysMenuService extends BaseService<SysMenu, Long> {
|
||||
* @param permCodeIdListString 逗号分隔的权限Id列表。
|
||||
* @return 验证结果。
|
||||
*/
|
||||
public VerifyResult verifyRelatedData(SysMenu sysMenu, SysMenu originalSysMenu, String permCodeIdListString) {
|
||||
String errorMessage = null;
|
||||
public CallResult verifyRelatedData(SysMenu sysMenu, SysMenu originalSysMenu, String permCodeIdListString) {
|
||||
JSONObject jsonObject = null;
|
||||
do {
|
||||
if (this.needToVerify(sysMenu, originalSysMenu, SysMenu::getParentId)) {
|
||||
// 1. menu、ui fragment和button类型的menu不能没有parentId
|
||||
// menu、ui fragment和button类型的menu不能没有parentId
|
||||
if (sysMenu.getParentId() == null) {
|
||||
if (sysMenu.getMenuType() != SysMenuType.TYPE_DIRECTORY) {
|
||||
errorMessage = "数据验证失败,当前类型菜单项的上级菜单不能为空!";
|
||||
break;
|
||||
return CallResult.error("数据验证失败,当前类型菜单项的上级菜单不能为空!");
|
||||
}
|
||||
} 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;
|
||||
}
|
||||
String errorMessage = checkErrorOfNonDirectoryMenu(sysMenu);
|
||||
if (errorMessage != null) {
|
||||
return CallResult.error(errorMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (StringUtils.isNotBlank(permCodeIdListString)) {
|
||||
Set<Long> permCodeIdSet = Arrays.stream(
|
||||
permCodeIdListString.split(",")).map(Long::valueOf).collect(Collectors.toSet());
|
||||
if (!sysPermCodeService.existUniqueKeyList("permCodeId", permCodeIdSet)) {
|
||||
errorMessage = "数据验证失败,存在不合法的权限字,请刷新后重试!";
|
||||
break;
|
||||
if (!sysPermCodeService.existAllPrimaryKeys(permCodeIdSet)) {
|
||||
return CallResult.error("数据验证失败,存在不合法的权限字,请刷新后重试!");
|
||||
}
|
||||
jsonObject = new JSONObject();
|
||||
jsonObject.put("permCodeIdSet", permCodeIdSet);
|
||||
}
|
||||
} while (false);
|
||||
return VerifyResult.create(errorMessage, jsonObject);
|
||||
return CallResult.ok(jsonObject);
|
||||
}
|
||||
|
||||
private String checkErrorOfNonDirectoryMenu(SysMenu sysMenu) {
|
||||
// 判断父节点是否存在
|
||||
SysMenu parentSysMenu = getById(sysMenu.getParentId());
|
||||
if (parentSysMenu == null) {
|
||||
return "数据验证失败,关联的上级菜单并不存在,请刷新后重试!";
|
||||
}
|
||||
// 逐个判断每种类型的菜单,他的父菜单的合法性,先从目录类型和菜单类型开始
|
||||
if (sysMenu.getMenuType() == SysMenuType.TYPE_DIRECTORY
|
||||
|| sysMenu.getMenuType() == SysMenuType.TYPE_MENU) {
|
||||
// 他们的上级只能是目录
|
||||
if (parentSysMenu.getMenuType() != SysMenuType.TYPE_DIRECTORY) {
|
||||
return "数据验证失败,当前类型菜单项的上级菜单只能是目录类型!";
|
||||
}
|
||||
} else if (sysMenu.getMenuType() == SysMenuType.TYPE_UI_FRAGMENT) {
|
||||
// ui fragment的上级只能是menu类型
|
||||
if (parentSysMenu.getMenuType() != SysMenuType.TYPE_MENU) {
|
||||
return "数据验证失败,当前类型菜单项的上级菜单只能是菜单类型和按钮类型!";
|
||||
}
|
||||
} else if (sysMenu.getMenuType() == SysMenuType.TYPE_BUTTON) {
|
||||
// button的上级只能是menu和ui fragment
|
||||
if (parentSysMenu.getMenuType() != SysMenuType.TYPE_MENU
|
||||
&& parentSysMenu.getMenuType() != SysMenuType.TYPE_UI_FRAGMENT) {
|
||||
return "数据验证失败,当前类型菜单项的上级菜单只能是菜单类型和UI片段类型!";
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package com.orange.admin.upms.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.orange.admin.common.biz.base.service.BaseBizService;
|
||||
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.common.core.object.CallResult;
|
||||
import com.orange.admin.upms.dao.SysMenuPermCodeMapper;
|
||||
import com.orange.admin.upms.dao.SysPermCodeMapper;
|
||||
import com.orange.admin.upms.dao.SysPermCodePermMapper;
|
||||
@@ -16,7 +16,6 @@ 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;
|
||||
@@ -25,10 +24,10 @@ import java.util.stream.Collectors;
|
||||
* 权限字数据服务类。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
@Service
|
||||
public class SysPermCodeService extends BaseService<SysPermCode, Long> {
|
||||
public class SysPermCodeService extends BaseBizService<SysPermCode, Long> {
|
||||
|
||||
@Autowired
|
||||
private SysPermCodeMapper sysPermCodeMapper;
|
||||
@@ -68,7 +67,7 @@ public class SysPermCodeService extends BaseService<SysPermCode, Long> {
|
||||
* @param permIdSet 权限资源Id列表。
|
||||
* @return 新增后的权限字对象。
|
||||
*/
|
||||
@Transactional
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public SysPermCode saveNew(SysPermCode sysPermCode, Set<Long> permIdSet) {
|
||||
sysPermCode.setPermCodeId(idGenerator.nextLongId());
|
||||
sysPermCode.setCreateTime(new Date());
|
||||
@@ -95,7 +94,7 @@ public class SysPermCodeService extends BaseService<SysPermCode, Long> {
|
||||
* @param permIdSet 权限资源Id列表。
|
||||
* @return 更新成功返回true,否则false。
|
||||
*/
|
||||
@Transactional
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean update(SysPermCode sysPermCode, SysPermCode originalSysPermCode, Set<Long> permIdSet) {
|
||||
sysPermCode.setCreateTime(originalSysPermCode.getCreateTime());
|
||||
sysPermCode.setParentId(originalSysPermCode.getParentId());
|
||||
@@ -103,9 +102,9 @@ public class SysPermCodeService extends BaseService<SysPermCode, Long> {
|
||||
if (sysPermCodeMapper.updateByPrimaryKey(sysPermCode) != 1) {
|
||||
return false;
|
||||
}
|
||||
Example e = new Example(SysPermCodePerm.class);
|
||||
e.createCriteria().andEqualTo("permCodeId", sysPermCode.getPermCodeId());
|
||||
sysPermCodePermMapper.deleteByExample(e);
|
||||
SysPermCodePerm deletedPermCodePerm = new SysPermCodePerm();
|
||||
deletedPermCodePerm.setPermCodeId(sysPermCode.getPermCodeId());
|
||||
sysPermCodePermMapper.delete(deletedPermCodePerm);
|
||||
if (permIdSet != null) {
|
||||
List<SysPermCodePerm> sysPermCodePermList = new LinkedList<>();
|
||||
for (Long permId : permIdSet) {
|
||||
@@ -125,7 +124,7 @@ public class SysPermCodeService extends BaseService<SysPermCode, Long> {
|
||||
* @param permCodeId 权限字主键Id。
|
||||
* @return 删除成功返回true,否则false。
|
||||
*/
|
||||
@Transactional
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean remove(Long permCodeId) {
|
||||
SysPermCode permCode = new SysPermCode();
|
||||
permCode.setPermCodeId(permCodeId);
|
||||
@@ -133,36 +132,15 @@ public class SysPermCodeService extends BaseService<SysPermCode, Long> {
|
||||
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);
|
||||
SysMenuPermCode menuPermCode = new SysMenuPermCode();
|
||||
menuPermCode.setPermCodeId(permCodeId);
|
||||
sysMenuPermCodeMapper.delete(menuPermCode);
|
||||
SysPermCodePerm permCodePerm = new SysPermCodePerm();
|
||||
permCodePerm.setPermCodeId(permCodeId);
|
||||
sysPermCodePermMapper.delete(permCodePerm);
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定用户的权限字列表。
|
||||
*
|
||||
@@ -204,29 +182,23 @@ public class SysPermCodeService extends BaseService<SysPermCode, Long> {
|
||||
* @param permIdListString 逗号分隔的权限资源Id列表。
|
||||
* @return 验证结果。
|
||||
*/
|
||||
public VerifyResult verifyRelatedData(
|
||||
public CallResult 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;
|
||||
return CallResult.error("数据验证失败,关联的上级权限字并不存在,请刷新后重试!");
|
||||
}
|
||||
}
|
||||
JSONObject jsonObject = null;
|
||||
if (StringUtils.isNotBlank(permIdListString)) {
|
||||
Set<Long> permIdSet = Arrays.stream(
|
||||
permIdListString.split(",")).map(Long::valueOf).collect(Collectors.toSet());
|
||||
if (!sysPermService.existUniqueKeyList("permId", permIdSet)) {
|
||||
errorMessage = "数据验证失败,存在不合法的权限资源,请刷新后重试!";
|
||||
break;
|
||||
if (!sysPermService.existAllPrimaryKeys(permIdSet)) {
|
||||
return CallResult.error("数据验证失败,存在不合法的权限资源,请刷新后重试!");
|
||||
}
|
||||
jsonObject = new JSONObject();
|
||||
jsonObject.put("permIdSet", permIdSet);
|
||||
}
|
||||
} while (false);
|
||||
return VerifyResult.create(errorMessage, jsonObject);
|
||||
return CallResult.ok(jsonObject);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.orange.admin.upms.service;
|
||||
|
||||
import com.orange.admin.common.biz.base.service.BaseBizService;
|
||||
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;
|
||||
@@ -18,10 +18,10 @@ import java.util.List;
|
||||
* 权限资源模块数据服务类。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
@Service
|
||||
public class SysPermModuleService extends BaseService<SysPermModule, Long> {
|
||||
public class SysPermModuleService extends BaseBizService<SysPermModule, Long> {
|
||||
|
||||
@Autowired
|
||||
private SysPermModuleMapper sysPermModuleMapper;
|
||||
@@ -46,7 +46,7 @@ public class SysPermModuleService extends BaseService<SysPermModule, Long> {
|
||||
* @param sysPermModule 新增的权限资源模块对象。
|
||||
* @return 新增后的权限资源模块对象。
|
||||
*/
|
||||
@Transactional
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public SysPermModule saveNew(SysPermModule sysPermModule) {
|
||||
sysPermModule.setModuleId(idGenerator.nextLongId());
|
||||
sysPermModule.setCreateTime(new Date());
|
||||
@@ -62,7 +62,7 @@ public class SysPermModuleService extends BaseService<SysPermModule, Long> {
|
||||
* @param originalSysPermModule 原有的权限资源模块对象。
|
||||
* @return 更新成功返回true,否则false
|
||||
*/
|
||||
@Transactional
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean update(SysPermModule sysPermModule, SysPermModule originalSysPermModule) {
|
||||
sysPermModule.setCreateTime(originalSysPermModule.getCreateTime());
|
||||
sysPermModule.setDeletedFlag(GlobalDeletedFlag.NORMAL);
|
||||
@@ -75,7 +75,7 @@ public class SysPermModuleService extends BaseService<SysPermModule, Long> {
|
||||
* @param moduleId 权限资源模块主键Id。
|
||||
* @return 删除成功返回true,否则false。
|
||||
*/
|
||||
@Transactional
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean remove(Long moduleId) {
|
||||
SysPermModule permModule = new SysPermModule();
|
||||
permModule.setModuleId(moduleId);
|
||||
|
||||
@@ -2,11 +2,12 @@ package com.orange.admin.upms.service;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.orange.admin.common.biz.base.service.BaseBizService;
|
||||
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.object.MyRelationParam;
|
||||
import com.orange.admin.common.core.constant.GlobalDeletedFlag;
|
||||
import com.orange.admin.common.core.object.VerifyResult;
|
||||
import com.orange.admin.common.core.object.CallResult;
|
||||
import com.orange.admin.upms.dao.SysPermCodePermMapper;
|
||||
import com.orange.admin.upms.dao.SysPermMapper;
|
||||
import com.orange.admin.upms.model.SysPerm;
|
||||
@@ -29,10 +30,10 @@ import java.util.stream.Collectors;
|
||||
* 权限资源数据服务类。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
@Service
|
||||
public class SysPermService extends BaseService<SysPerm, Long> {
|
||||
public class SysPermService extends BaseBizService<SysPerm, Long> {
|
||||
|
||||
@Autowired
|
||||
private SysPermMapper sysPermMapper;
|
||||
@@ -61,7 +62,7 @@ public class SysPermService extends BaseService<SysPerm, Long> {
|
||||
* @param perm 新增的权限资源对象。
|
||||
* @return 新增后的权限资源对象。
|
||||
*/
|
||||
@Transactional
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public SysPerm saveNew(SysPerm perm) {
|
||||
perm.setPermId(idGenerator.nextLongId());
|
||||
perm.setCreateTime(new Date());
|
||||
@@ -74,10 +75,10 @@ public class SysPermService extends BaseService<SysPerm, Long> {
|
||||
* 更新权限资源对象。
|
||||
*
|
||||
* @param perm 更新的权限资源对象。
|
||||
* @param originalPerm 更新的权限资源对象。
|
||||
* @param originalPerm 原有的权限资源对象。
|
||||
* @return 更新成功返回true,否则false。
|
||||
*/
|
||||
@Transactional
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean update(SysPerm perm, SysPerm originalPerm) {
|
||||
perm.setCreateTime(originalPerm.getCreateTime());
|
||||
perm.setDeletedFlag(GlobalDeletedFlag.NORMAL);
|
||||
@@ -90,7 +91,7 @@ public class SysPermService extends BaseService<SysPerm, Long> {
|
||||
* @param permId 权限资源主键Id。
|
||||
* @return 删除成功返回true,否则false。
|
||||
*/
|
||||
@Transactional
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean remove(Long permId) {
|
||||
SysPerm perm = new SysPerm();
|
||||
perm.setPermId(permId);
|
||||
@@ -112,7 +113,7 @@ public class SysPermService extends BaseService<SysPerm, Long> {
|
||||
*/
|
||||
public List<SysPerm> getPermListWithRelation(SysPerm sysPermFilter) {
|
||||
Example e = new Example(SysPerm.class);
|
||||
e.orderBy("permId");
|
||||
e.orderBy("showOrder");
|
||||
Example.Criteria c = e.createCriteria();
|
||||
if (ObjectUtil.isNotNull(sysPermFilter.getModuleId())) {
|
||||
c.andEqualTo("moduleId", sysPermFilter.getModuleId());
|
||||
@@ -123,7 +124,7 @@ public class SysPermService extends BaseService<SysPerm, Long> {
|
||||
c.andEqualTo("deletedFlag", GlobalDeletedFlag.NORMAL);
|
||||
List<SysPerm> permList = sysPermMapper.selectByExample(e);
|
||||
// 这里因为权限只有字典数据,所以仅仅做字典关联。
|
||||
this.buildRelationForDataList(permList, true);
|
||||
this.buildRelationForDataList(permList, MyRelationParam.dictOnly(), null);
|
||||
return permList;
|
||||
}
|
||||
|
||||
@@ -134,12 +135,12 @@ public class SysPermService extends BaseService<SysPerm, Long> {
|
||||
* @param userId 用户主键Id。
|
||||
* @return 当前用户权限集合。
|
||||
*/
|
||||
@Cacheable(value = "UserPermissionCache", key = "#sessionId", unless = "#result == null")
|
||||
@Cacheable(value = "USER_PERMISSION_CACHE", 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 new HashSet<>(1);
|
||||
}
|
||||
// 管理员账户返回空对象,便于缓存的统一处理。
|
||||
return user.getUserType() == SysUserType.TYPE_ADMIN
|
||||
@@ -154,7 +155,7 @@ public class SysPermService extends BaseService<SysPerm, Long> {
|
||||
* @param isAdmin 是否是管理员。
|
||||
* @return 查询并缓存后的权限集合。
|
||||
*/
|
||||
@CachePut(value = "UserPermissionCache", key = "#sessionId")
|
||||
@CachePut(value = "USER_PERMISSION_CACHE", key = "#sessionId")
|
||||
public Set<String> putUserSysPermCache(String sessionId, Long userId, boolean isAdmin) {
|
||||
// 管理员账户返回空对象,便于缓存的统一处理。
|
||||
return isAdmin ? new HashSet<>(1) : this.getSysPermSetByUserId(userId);
|
||||
@@ -165,7 +166,7 @@ public class SysPermService extends BaseService<SysPerm, Long> {
|
||||
*
|
||||
* @param sessionId 会话Id。
|
||||
*/
|
||||
@CacheEvict(value = "UserPermissionCache", key = "#sessionId")
|
||||
@CacheEvict(value = "USER_PERMISSION_CACHE", key = "#sessionId")
|
||||
public void removeUserSysPermCache(String sessionId) {
|
||||
// 空实现即可,只是通过注解将当前sessionId从cache中删除。
|
||||
}
|
||||
@@ -241,20 +242,16 @@ public class SysPermService extends BaseService<SysPerm, Long> {
|
||||
* @param originalSysPerm 原有对象。
|
||||
* @return 验证结果。
|
||||
*/
|
||||
public VerifyResult verifyRelatedData(SysPerm sysPerm, SysPerm originalSysPerm) {
|
||||
String errorMessage = null;
|
||||
public CallResult verifyRelatedData(SysPerm sysPerm, SysPerm originalSysPerm) {
|
||||
JSONObject jsonObject = null;
|
||||
do {
|
||||
if (this.needToVerify(sysPerm, originalSysPerm, SysPerm::getModuleId)) {
|
||||
SysPermModule permModule = sysPermModuleService.getById(sysPerm.getModuleId());
|
||||
if (permModule == null) {
|
||||
errorMessage = "数据验证失败,关联的权限模块Id并不存在,请刷新后重试!";
|
||||
break;
|
||||
return CallResult.error("数据验证失败,关联的权限模块Id并不存在,请刷新后重试!");
|
||||
}
|
||||
jsonObject = new JSONObject();
|
||||
jsonObject.put("permModule", permModule);
|
||||
}
|
||||
} while (false);
|
||||
return VerifyResult.create(errorMessage, jsonObject);
|
||||
return CallResult.ok(jsonObject);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.orange.admin.upms.service;
|
||||
|
||||
import com.orange.admin.common.biz.base.service.BaseBizService;
|
||||
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;
|
||||
@@ -12,10 +12,10 @@ import org.springframework.stereotype.Service;
|
||||
* 白名单中的权限资源,可以不受权限控制,任何用户皆可访问,一般用于常用的字典数据列表接口。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
@Service
|
||||
public class SysPermWhitelistService extends BaseService<SysPermWhitelist, String> {
|
||||
public class SysPermWhitelistService extends BaseBizService<SysPermWhitelist, String> {
|
||||
|
||||
@Autowired
|
||||
private SysPermWhitelistMapper sysPermWhitelistMapper;
|
||||
@@ -29,5 +29,4 @@ public class SysPermWhitelistService extends BaseService<SysPermWhitelist, Strin
|
||||
protected BaseDaoMapper<SysPermWhitelist> mapper() {
|
||||
return sysPermWhitelistMapper;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package com.orange.admin.upms.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.orange.admin.common.biz.base.service.BaseBizService;
|
||||
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.common.core.object.CallResult;
|
||||
import com.orange.admin.upms.dao.SysRoleMapper;
|
||||
import com.orange.admin.upms.dao.SysRoleMenuMapper;
|
||||
import com.orange.admin.upms.dao.SysUserRoleMapper;
|
||||
@@ -18,7 +18,6 @@ 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;
|
||||
@@ -27,10 +26,10 @@ import java.util.stream.Collectors;
|
||||
* 角色数据服务类。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
@Service
|
||||
public class SysRoleService extends BaseService<SysRole, Long> {
|
||||
public class SysRoleService extends BaseBizService<SysRole, Long> {
|
||||
|
||||
@Autowired
|
||||
private SysRoleMapper sysRoleMapper;
|
||||
@@ -60,7 +59,7 @@ public class SysRoleService extends BaseService<SysRole, Long> {
|
||||
* @param menuIdSet 菜单Id列表。
|
||||
* @return 新增后的角色对象。
|
||||
*/
|
||||
@Transactional
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public SysRole saveNew(SysRole role, Set<Long> menuIdSet) {
|
||||
role.setRoleId(idGenerator.nextLongId());
|
||||
TokenData tokenData = TokenData.takeFromRequest();
|
||||
@@ -92,7 +91,7 @@ public class SysRoleService extends BaseService<SysRole, Long> {
|
||||
* @param menuIdSet 菜单Id列表。
|
||||
* @return 更新成功返回true,否则false。
|
||||
*/
|
||||
@Transactional
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean update(SysRole role, SysRole originalRole, Set<Long> menuIdSet) {
|
||||
SysRole updateRole = new SysRole();
|
||||
BeanUtils.copyProperties(role, updateRole, "createUserId", "createUsername", "createTime");
|
||||
@@ -101,9 +100,9 @@ public class SysRoleService extends BaseService<SysRole, Long> {
|
||||
if (sysRoleMapper.updateByPrimaryKeySelective(updateRole) != 1) {
|
||||
return false;
|
||||
}
|
||||
Example e = new Example(SysRoleMenu.class);
|
||||
e.createCriteria().andEqualTo("roleId", role.getRoleId());
|
||||
sysRoleMenuMapper.deleteByExample(e);
|
||||
SysRoleMenu deletedRoleMenu = new SysRoleMenu();
|
||||
deletedRoleMenu.setRoleId(role.getRoleId());
|
||||
sysRoleMenuMapper.delete(deletedRoleMenu);
|
||||
if (menuIdSet != null) {
|
||||
List<SysRoleMenu> roleMenuList = new LinkedList<>();
|
||||
for (Long menuId : menuIdSet) {
|
||||
@@ -123,7 +122,7 @@ public class SysRoleService extends BaseService<SysRole, Long> {
|
||||
* @param roleId 角色主键Id。
|
||||
* @return 删除成功返回true,否则false。
|
||||
*/
|
||||
@Transactional
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean remove(Long roleId) {
|
||||
SysRole role = new SysRole();
|
||||
role.setRoleId(roleId);
|
||||
@@ -131,12 +130,12 @@ public class SysRoleService extends BaseService<SysRole, Long> {
|
||||
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);
|
||||
SysRoleMenu roleMenu = new SysRoleMenu();
|
||||
roleMenu.setRoleId(roleId);
|
||||
sysRoleMenuMapper.delete(roleMenu);
|
||||
SysUserRole userRole = new SysUserRole();
|
||||
userRole.setRoleId(roleId);
|
||||
sysUserRoleMapper.delete(userRole);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -151,27 +150,6 @@ public class SysRoleService extends BaseService<SysRole, Long> {
|
||||
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获取拥有改权限的所有角色。
|
||||
* 开发人员调试用接口。
|
||||
@@ -199,7 +177,7 @@ public class SysRoleService extends BaseService<SysRole, Long> {
|
||||
*
|
||||
* @param userRoleList 用户角色关系数据列表。
|
||||
*/
|
||||
@Transactional
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void addUserRoleList(List<SysUserRole> userRoleList) {
|
||||
sysUserRoleMapper.addUserRoleList(userRoleList);
|
||||
}
|
||||
@@ -211,7 +189,7 @@ public class SysRoleService extends BaseService<SysRole, Long> {
|
||||
* @param userId 用户主键Id。
|
||||
* @return 移除成功返回true,否则false。
|
||||
*/
|
||||
@Transactional
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean removeUserRole(Long roleId, Long userId) {
|
||||
SysUserRole userRole = new SysUserRole();
|
||||
userRole.setRoleId(roleId);
|
||||
@@ -227,21 +205,17 @@ public class SysRoleService extends BaseService<SysRole, Long> {
|
||||
* @param menuIdListString 逗号分隔的menuId列表。
|
||||
* @return 验证结果。
|
||||
*/
|
||||
public VerifyResult verifyRelatedData(SysRole sysRole, SysRole originalSysRole, String menuIdListString) {
|
||||
String errorMessage = null;
|
||||
public CallResult verifyRelatedData(SysRole sysRole, SysRole originalSysRole, String menuIdListString) {
|
||||
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;
|
||||
if (!sysMenuService.existAllPrimaryKeys(menuIdSet)) {
|
||||
return CallResult.error("数据验证失败,存在不合法的菜单权限,请刷新后重试!");
|
||||
}
|
||||
jsonObject = new JSONObject();
|
||||
jsonObject.put("menuIdSet", menuIdSet);
|
||||
}
|
||||
} while (false);
|
||||
return VerifyResult.create(errorMessage, jsonObject);
|
||||
return CallResult.ok(jsonObject);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,13 +4,14 @@ 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.object.MyRelationParam;
|
||||
import com.orange.admin.common.core.object.CallResult;
|
||||
import com.orange.admin.common.core.util.MyCommonUtil;
|
||||
import com.orange.admin.common.biz.base.service.BaseBizService;
|
||||
import com.orange.admin.common.biz.util.BasicIdGenerator;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@@ -26,10 +27,10 @@ import java.util.stream.Collectors;
|
||||
* 用户管理数据操作服务类。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
@Service
|
||||
public class SysUserService extends BaseService<SysUser, Long> {
|
||||
public class SysUserService extends BaseBizService<SysUser, Long> {
|
||||
|
||||
@Autowired
|
||||
private SysUserMapper sysUserMapper;
|
||||
@@ -77,7 +78,7 @@ public class SysUserService extends BaseService<SysUser, Long> {
|
||||
* @param passwdSalt 密码的盐。
|
||||
* @return 新增后的用户对象。
|
||||
*/
|
||||
@Transactional
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public SysUser saveNew(SysUser user, Set<Long> roleIdSet, Set<Long> dataPermIdSet, String passwdSalt) {
|
||||
user.setUserId(idGenerator.nextLongId());
|
||||
user.setPassword(MyCommonUtil.encrptedPassword(user.getPassword(), passwdSalt));
|
||||
@@ -122,7 +123,7 @@ public class SysUserService extends BaseService<SysUser, Long> {
|
||||
* @param dataPermIdSet 数据权限Id集合。
|
||||
* @return 更新成功返回true,否则false。
|
||||
*/
|
||||
@Transactional
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean update(SysUser user, SysUser originalUser, Set<Long> roleIdSet, Set<Long> dataPermIdSet) {
|
||||
user.setLoginName(originalUser.getLoginName());
|
||||
user.setPassword(originalUser.getPassword());
|
||||
@@ -134,9 +135,9 @@ public class SysUserService extends BaseService<SysUser, Long> {
|
||||
return false;
|
||||
}
|
||||
// 先删除原有的User-Role关联关系,再重新插入新的关联关系
|
||||
Example e = new Example(SysUserRole.class);
|
||||
e.createCriteria().andEqualTo("userId", user.getUserId());
|
||||
sysUserRoleMapper.deleteByExample(e);
|
||||
SysUserRole deletedUserRole = new SysUserRole();
|
||||
deletedUserRole.setUserId(user.getUserId());
|
||||
sysUserRoleMapper.delete(deletedUserRole);
|
||||
if (CollectionUtils.isNotEmpty(roleIdSet)) {
|
||||
List<SysUserRole> userRoleList = new LinkedList<>();
|
||||
for (Long roleId : roleIdSet) {
|
||||
@@ -148,9 +149,9 @@ public class SysUserService extends BaseService<SysUser, Long> {
|
||||
sysUserRoleMapper.insertList(userRoleList);
|
||||
}
|
||||
// 先删除原有的DataPerm-User关联关系,在重新插入新的关联关系
|
||||
Example e2 = new Example(SysDataPermUser.class);
|
||||
e2.createCriteria().andEqualTo("userId", user.getUserId());
|
||||
sysDataPermUserMapper.deleteByExample(e2);
|
||||
SysDataPermUser deletedDataPermUser = new SysDataPermUser();
|
||||
deletedDataPermUser.setUserId(user.getUserId());
|
||||
sysDataPermUserMapper.delete(deletedDataPermUser);
|
||||
if (CollectionUtils.isNotEmpty(dataPermIdSet)) {
|
||||
List<SysDataPermUser> dataPermUserList = new LinkedList<>();
|
||||
for (Long dataPermId : dataPermIdSet) {
|
||||
@@ -171,11 +172,11 @@ public class SysUserService extends BaseService<SysUser, Long> {
|
||||
* @param passwdSalt 密码的盐。
|
||||
* @return 成功返回true,否则false。
|
||||
*/
|
||||
@Transactional
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
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);
|
||||
e.createCriteria().andEqualTo(super.idFieldName, userId);
|
||||
e.createCriteria().andEqualTo(super.deletedFlagFieldName, GlobalDeletedFlag.NORMAL);
|
||||
SysUser updatedUser = new SysUser();
|
||||
updatedUser.setPassword(MyCommonUtil.encrptedPassword(defaultPasswd, passwdSalt));
|
||||
return sysUserMapper.updateByExampleSelective(updatedUser, e) == 1;
|
||||
@@ -187,12 +188,12 @@ public class SysUserService extends BaseService<SysUser, Long> {
|
||||
* @param userId 主键Id。
|
||||
* @return 成功返回true,否则false。
|
||||
*/
|
||||
@Transactional
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
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);
|
||||
c.andEqualTo(super.idFieldName, userId);
|
||||
c.andEqualTo(super.deletedFlagFieldName, GlobalDeletedFlag.NORMAL);
|
||||
// 这里先删除主数据
|
||||
SysUser deletedObject = new SysUser();
|
||||
deletedObject.setDeletedFlag(GlobalDeletedFlag.DELETED);
|
||||
@@ -200,31 +201,15 @@ public class SysUserService extends BaseService<SysUser, Long> {
|
||||
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);
|
||||
SysUserRole userRole = new SysUserRole();
|
||||
userRole.setUserId(userId);
|
||||
sysUserRoleMapper.delete(userRole);
|
||||
SysDataPermUser dataPermUser = new SysDataPermUser();
|
||||
dataPermUser.setUserId(userId);
|
||||
sysDataPermUserMapper.delete(dataPermUser);
|
||||
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)方法。
|
||||
@@ -248,7 +233,7 @@ public class SysUserService extends BaseService<SysUser, Long> {
|
||||
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);
|
||||
this.buildRelationForDataList(resultList, MyRelationParam.normal(), criteriaMap);
|
||||
return resultList;
|
||||
}
|
||||
|
||||
@@ -309,34 +294,27 @@ public class SysUserService extends BaseService<SysUser, Long> {
|
||||
* @param dataPermIdListString 逗号分隔的数据权限Id列表字符串。
|
||||
* @return 验证结果。
|
||||
*/
|
||||
public VerifyResult verifyRelatedData(
|
||||
public CallResult verifyRelatedData(
|
||||
SysUser sysUser, SysUser originalSysUser, String roleIdListString, String dataPermIdListString) {
|
||||
String errorMessage = null;
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
do {
|
||||
if (StringUtils.isBlank(roleIdListString)) {
|
||||
errorMessage = "数据验证失败,用户的角色数据不能为空!";
|
||||
break;
|
||||
return CallResult.error("数据验证失败,用户的角色数据不能为空!");
|
||||
}
|
||||
Set<Long> roleIdSet = Arrays.stream(
|
||||
roleIdListString.split(",")).map(Long::valueOf).collect(Collectors.toSet());
|
||||
if (!sysRoleService.existUniqueKeyList("roleId", roleIdSet)) {
|
||||
errorMessage = "数据验证失败,存在不合法的用户角色,请刷新后重试!";
|
||||
break;
|
||||
if (!sysRoleService.existAllPrimaryKeys(roleIdSet)) {
|
||||
return CallResult.error("数据验证失败,存在不合法的用户角色,请刷新后重试!");
|
||||
}
|
||||
jsonObject.put("roleIdSet", roleIdSet);
|
||||
if (StringUtils.isBlank(dataPermIdListString)) {
|
||||
errorMessage = "数据验证失败,用户的数据权限不能为空!";
|
||||
break;
|
||||
return CallResult.error("数据验证失败,用户的数据权限不能为空!");
|
||||
}
|
||||
Set<Long> dataPermIdSet = Arrays.stream(
|
||||
dataPermIdListString.split(",")).map(Long::valueOf).collect(Collectors.toSet());
|
||||
if (!sysDataPermService.existUniqueKeyList("dataPermId", dataPermIdSet)) {
|
||||
errorMessage = "数据验证失败,存在不合法的数据权限,请刷新后重试!";
|
||||
break;
|
||||
if (!sysDataPermService.existAllPrimaryKeys(dataPermIdSet)) {
|
||||
return CallResult.error("数据验证失败,存在不合法的数据权限,请刷新后重试!");
|
||||
}
|
||||
jsonObject.put("dataPermIdSet", dataPermIdSet);
|
||||
} while (false);
|
||||
return VerifyResult.create(errorMessage, jsonObject);
|
||||
return CallResult.ok(jsonObject);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ server:
|
||||
# spring相关配置
|
||||
spring:
|
||||
application:
|
||||
name: application
|
||||
name: app
|
||||
profiles:
|
||||
active: dev
|
||||
servlet:
|
||||
@@ -62,7 +62,11 @@ management:
|
||||
web:
|
||||
exposure:
|
||||
include: '*'
|
||||
jmx:
|
||||
exposure:
|
||||
include: '*'
|
||||
endpoint:
|
||||
# 与中间件相关的健康详情也会被展示
|
||||
health:
|
||||
show-details: always
|
||||
configprops:
|
||||
@@ -85,7 +89,7 @@ spring:
|
||||
username: root
|
||||
password: 123456
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
name: application
|
||||
name: app
|
||||
initialSize: 10
|
||||
minIdle: 10
|
||||
maxActive: 50
|
||||
@@ -105,7 +109,7 @@ spring:
|
||||
web-stat-filter:
|
||||
enabled: true
|
||||
url-pattern: /*
|
||||
exclusions: "*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*"
|
||||
exclusions: "*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*,/actuator/*"
|
||||
stat-view-servlet:
|
||||
enabled: true
|
||||
urlPattern: /druid/*
|
||||
@@ -142,7 +146,7 @@ spring:
|
||||
username: root
|
||||
password: 123456
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
name: application
|
||||
name: app
|
||||
initialSize: 10
|
||||
minIdle: 10
|
||||
maxActive: 50
|
||||
@@ -162,7 +166,7 @@ spring:
|
||||
web-stat-filter:
|
||||
enabled: true
|
||||
url-pattern: /*
|
||||
exclusions: "*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*"
|
||||
exclusions: "*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*,/actuator/*"
|
||||
stat-view-servlet:
|
||||
enabled: true
|
||||
urlPattern: /druid/*
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
</plugin>
|
||||
|
||||
<jdbcConnection driverClass="com.mysql.cj.jdbc.Driver"
|
||||
connectionURL="jdbc:mysql://localhost:3306/zz-orangle-admin?useSSL=true&serverTimezone=Asia/Shanghai"
|
||||
connectionURL="jdbc:mysql://localhost:3306/zz-orange-admin?useSSL=true&serverTimezone=Asia/Shanghai"
|
||||
userId="root"
|
||||
password="123456">
|
||||
</jdbcConnection>
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
package com.orange.admin;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
public class MyApplicationTests {
|
||||
|
||||
@Test
|
||||
public void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,7 +3,7 @@ SET FOREIGN_KEY_CHECKS = 0;
|
||||
|
||||
-- ----------------------------
|
||||
-- 行政区划表,在以下数据库中执行该脚本。
|
||||
-- 主数据源 [localhost:3306/zz-orangle-admin]
|
||||
-- 主数据源 [localhost:3306/zz-orange-admin]
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `zz_area_code`;
|
||||
CREATE TABLE `zz_area_code` (
|
||||
|
||||
@@ -12,7 +12,7 @@ import java.util.Date;
|
||||
* Controller的环绕拦截类。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
@ControllerAdvice
|
||||
public class MyControllerAdvice {
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package com.orange.admin.common.biz.advice;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import com.orange.admin.common.core.exception.InvalidClassFieldException;
|
||||
import com.orange.admin.common.core.exception.InvalidDataFieldException;
|
||||
import com.orange.admin.common.core.exception.InvalidDataModelException;
|
||||
import com.orange.admin.common.core.constant.ErrorCodeEnum;
|
||||
import com.orange.admin.common.core.exception.RedisCacheAccessException;
|
||||
import com.orange.admin.common.core.object.ResponseResult;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.ibatis.exceptions.PersistenceException;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.dao.DuplicateKeyException;
|
||||
@@ -19,26 +22,86 @@ import java.util.concurrent.TimeoutException;
|
||||
* 用不同的函数,处理不同类型的异常。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
@Slf4j
|
||||
@RestControllerAdvice
|
||||
public class MyExceptionHandler {
|
||||
|
||||
/**
|
||||
* 通用异常处理方法。
|
||||
*
|
||||
* @param ex 异常对象。
|
||||
* @param request http请求。
|
||||
* @return 应答对象。
|
||||
*/
|
||||
@ExceptionHandler(value = Exception.class)
|
||||
public ResponseResult<?> exceptionHandle(Exception ex, HttpServletRequest request) {
|
||||
public ResponseResult<Void> exceptionHandle(Exception ex, HttpServletRequest request) {
|
||||
log.error("Unhandled exception from URL [" + request.getRequestURI() + "]", ex);
|
||||
return ResponseResult.error(ErrorCodeEnum.UNHANDLED_EXCEPTION);
|
||||
}
|
||||
|
||||
/**
|
||||
* 无效的实体对象异常。
|
||||
*
|
||||
* @param ex 异常对象。
|
||||
* @param request http请求。
|
||||
* @return 应答对象。
|
||||
*/
|
||||
@ExceptionHandler(value = InvalidDataModelException.class)
|
||||
public ResponseResult<Void> invalidDataModelExceptionHandle(Exception ex, HttpServletRequest request) {
|
||||
log.error("InvalidDataModelException exception from URL [" + request.getRequestURI() + "]", ex);
|
||||
return ResponseResult.error(ErrorCodeEnum.INVALID_DATA_MODEL);
|
||||
}
|
||||
|
||||
/**
|
||||
* 无效的实体对象字段异常。
|
||||
*
|
||||
* @param ex 异常对象。
|
||||
* @param request http请求。
|
||||
* @return 应答对象。
|
||||
*/
|
||||
@ExceptionHandler(value = InvalidDataFieldException.class)
|
||||
public ResponseResult<Void> invalidDataFieldExceptionHandle(Exception ex, HttpServletRequest request) {
|
||||
log.error("InvalidDataFieldException exception from URL [" + request.getRequestURI() + "]", ex);
|
||||
return ResponseResult.error(ErrorCodeEnum.INVALID_DATA_FIELD);
|
||||
}
|
||||
|
||||
/**
|
||||
* 无效类字段异常。
|
||||
*
|
||||
* @param ex 异常对象。
|
||||
* @param request http请求。
|
||||
* @return 应答对象。
|
||||
*/
|
||||
@ExceptionHandler(value = InvalidClassFieldException.class)
|
||||
public ResponseResult<Void> invalidClassFieldExceptionHandle(Exception ex, HttpServletRequest request) {
|
||||
log.error("InvalidClassFieldException exception from URL [" + request.getRequestURI() + "]", ex);
|
||||
return ResponseResult.error(ErrorCodeEnum.INVALID_CLASS_FIELD);
|
||||
}
|
||||
|
||||
/**
|
||||
* 重复键异常处理方法。
|
||||
*
|
||||
* @param ex 异常对象。
|
||||
* @param request http请求。
|
||||
* @return 应答对象。
|
||||
*/
|
||||
@ExceptionHandler(value = DuplicateKeyException.class)
|
||||
public ResponseResult<?> duplicateKeyExceptionHandle(Exception ex, HttpServletRequest request) {
|
||||
public ResponseResult<Void> duplicateKeyExceptionHandle(Exception ex, HttpServletRequest request) {
|
||||
log.error("DuplicateKeyException exception from URL [" + request.getRequestURI() + "]", ex);
|
||||
return ResponseResult.error(ErrorCodeEnum.DUPLICATED_UNIQUE_KEY);
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据访问失败异常处理方法。
|
||||
*
|
||||
* @param ex 异常对象。
|
||||
* @param request http请求。
|
||||
* @return 应答对象。
|
||||
*/
|
||||
@ExceptionHandler(value = DataAccessException.class)
|
||||
public ResponseResult<?> dataAccessExceptionHandle(Exception ex, HttpServletRequest request) {
|
||||
public ResponseResult<Void> dataAccessExceptionHandle(Exception ex, HttpServletRequest request) {
|
||||
log.error("DataAccessException exception from URL [" + request.getRequestURI() + "]", ex);
|
||||
if (ex.getCause() instanceof PersistenceException
|
||||
&& ex.getCause().getCause() instanceof PermissionDeniedDataAccessException) {
|
||||
@@ -47,8 +110,15 @@ public class MyExceptionHandler {
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_ACCESS_FAILED);
|
||||
}
|
||||
|
||||
/**
|
||||
* Redis缓存访问异常处理方法。
|
||||
*
|
||||
* @param ex 异常对象。
|
||||
* @param request http请求。
|
||||
* @return 应答对象。
|
||||
*/
|
||||
@ExceptionHandler(value = RedisCacheAccessException.class)
|
||||
public ResponseResult<?> redisCacheAccessExceptionHandle(Exception ex, HttpServletRequest request) {
|
||||
public ResponseResult<Void> redisCacheAccessExceptionHandle(Exception ex, HttpServletRequest request) {
|
||||
log.error("RedisCacheAccessException exception from URL [" + request.getRequestURI() + "]", ex);
|
||||
if (ex.getCause() instanceof TimeoutException) {
|
||||
return ResponseResult.error(ErrorCodeEnum.REDIS_CACHE_ACCESS_TIMEOUT);
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.orange.admin.common.biz.aop;
|
||||
|
||||
import com.orange.admin.common.core.object.GlobalThreadLocal;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 禁用数据权限过滤的AOP处理类。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
@Aspect
|
||||
@Component
|
||||
@Order(1)
|
||||
@Slf4j
|
||||
public class DisableDataPermAspect {
|
||||
|
||||
/**
|
||||
* 所有标记了DisableDataPerm注解的方法。
|
||||
*/
|
||||
@Pointcut("@annotation(com.orange.admin.common.core.annotation.DisableDataPerm)")
|
||||
public void disableDataPermPointCut() {
|
||||
// 空注释,避免sonar警告
|
||||
}
|
||||
|
||||
@Around("disableDataPermPointCut()")
|
||||
public Object around(ProceedingJoinPoint point) throws Throwable {
|
||||
boolean dataPermEnabled = GlobalThreadLocal.setDataPerm(false);
|
||||
try {
|
||||
return point.proceed();
|
||||
} finally {
|
||||
GlobalThreadLocal.setDataPerm(dataPermEnabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.orange.admin.common.biz.base.service;
|
||||
|
||||
import com.orange.admin.common.core.base.service.BaseService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* 所有业务Service的共同基类。由于BaseService位于common-core模块内,该模块很少涉及spring bean的集成,
|
||||
* 因此该类位于业务服务类和BaseService之间,主要提供一些通用方法,特别是与spring bean相关的业务代码。
|
||||
* NOTE: 目前该类实现为空,主要是为了便于用户自行扩展,同时也能方便今后向微服务的升级,
|
||||
*
|
||||
* @param <M> Model对象的类型。
|
||||
* @param <K> Model对象主键的类型。
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
@Slf4j
|
||||
public abstract class BaseBizService<M, K> extends BaseService<M, K> {
|
||||
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
* 应用程序自定义的通用属性配置文件。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
@Data
|
||||
@Configuration
|
||||
|
||||
@@ -6,12 +6,16 @@ import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
|
||||
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.MediaType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* DTA 对象数据格式转换器,这里集成了alibaba的fastjson,作为消息格式转换工具
|
||||
* 对象数据格式转换器,这里集成了alibaba的fastjson,作为消息格式转换工具
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
@Configuration
|
||||
public class FastjsonConfig {
|
||||
@@ -19,9 +23,15 @@ public class FastjsonConfig {
|
||||
@Bean
|
||||
public HttpMessageConverters fastJsonHttpMessageConverters() {
|
||||
FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
|
||||
List<MediaType> supportedMediaTypes = new ArrayList<>();
|
||||
supportedMediaTypes.add(MediaType.APPLICATION_JSON);
|
||||
supportedMediaTypes.add(MediaType.APPLICATION_FORM_URLENCODED);
|
||||
fastConverter.setSupportedMediaTypes(supportedMediaTypes);
|
||||
FastJsonConfig fastJsonConfig = new FastJsonConfig();
|
||||
fastJsonConfig.setSerializerFeatures(
|
||||
SerializerFeature.PrettyFormat, SerializerFeature.DisableCircularReferenceDetect);
|
||||
SerializerFeature.PrettyFormat,
|
||||
SerializerFeature.DisableCircularReferenceDetect,
|
||||
SerializerFeature.IgnoreNonFieldGetter);
|
||||
fastJsonConfig.setDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
fastConverter.setFastJsonConfig(fastJsonConfig);
|
||||
return new HttpMessageConverters(fastConverter);
|
||||
|
||||
@@ -10,7 +10,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
* tomcat配置对象。当前配置禁用了PUT和DELETE方法,防止渗透攻击。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
@Configuration
|
||||
public class TomcatConfig {
|
||||
|
||||
@@ -3,6 +3,12 @@ package com.orange.admin.common.biz.constant;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 科目常量字典对象。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
public final class Subject {
|
||||
|
||||
/**
|
||||
@@ -18,7 +24,7 @@ public final class Subject {
|
||||
*/
|
||||
public static final int ENGLISH = 2;
|
||||
|
||||
public static final Map<Object, String> DICT_MAP = new HashMap<>(3);
|
||||
private static final Map<Object, String> DICT_MAP = new HashMap<>(3);
|
||||
static {
|
||||
DICT_MAP.put(CHINESE, "语文");
|
||||
DICT_MAP.put(MATH, "数学");
|
||||
@@ -31,8 +37,8 @@ public final class Subject {
|
||||
* @param value 待验证的参数值。
|
||||
* @return 合法返回true,否则false。
|
||||
*/
|
||||
public static boolean isValid(int value) {
|
||||
return DICT_MAP.containsKey(value);
|
||||
public static boolean isValid(Integer value) {
|
||||
return value != null && DICT_MAP.containsKey(value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,6 +3,12 @@ package com.orange.admin.common.biz.constant;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 是否常量字典对象。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
public final class YesNo {
|
||||
|
||||
/**
|
||||
@@ -14,7 +20,7 @@ public final class YesNo {
|
||||
*/
|
||||
public static final int NO = 0;
|
||||
|
||||
public static final Map<Object, String> DICT_MAP = new HashMap<>(2);
|
||||
private static final Map<Object, String> DICT_MAP = new HashMap<>(2);
|
||||
static {
|
||||
DICT_MAP.put(YES, "是");
|
||||
DICT_MAP.put(NO, "否");
|
||||
@@ -26,8 +32,8 @@ public final class YesNo {
|
||||
* @param value 待验证的参数值。
|
||||
* @return 合法返回true,否则false。
|
||||
*/
|
||||
public static boolean isValid(int value) {
|
||||
return DICT_MAP.containsKey(value);
|
||||
public static boolean isValid(Integer value) {
|
||||
return value != null && DICT_MAP.containsKey(value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -13,7 +13,7 @@ import javax.servlet.http.HttpServletResponse;
|
||||
* 服务访问日志的拦截器,主要完成记录接口调用时长。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
@Slf4j
|
||||
public class AccessInterceptor implements HandlerInterceptor {
|
||||
@@ -33,6 +33,7 @@ public class AccessInterceptor implements HandlerInterceptor {
|
||||
@Override
|
||||
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
|
||||
ModelAndView modelAndView) throws Exception {
|
||||
// 这里需要加注释,否则sonar不happy。
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -9,9 +9,11 @@ import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.lang.NonNull;
|
||||
import org.springframework.web.bind.support.WebDataBinderFactory;
|
||||
import org.springframework.web.context.request.NativeWebRequest;
|
||||
import org.springframework.web.context.request.RequestAttributes;
|
||||
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
|
||||
import org.springframework.web.method.support.ModelAndViewContainer;
|
||||
|
||||
@@ -27,7 +29,7 @@ import java.util.*;
|
||||
* 2、多个对象需要封装到一个对象里才可以用@RequestBody接收。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
public class MyRequestArgumentResolver implements HandlerMethodArgumentResolver {
|
||||
|
||||
@@ -47,10 +49,10 @@ public class MyRequestArgumentResolver implements HandlerMethodArgumentResolver
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置支持的方法参数类型
|
||||
* 设置支持的方法参数类型。
|
||||
*
|
||||
* @param parameter 方法参数
|
||||
* @return 支持的类型
|
||||
* @param parameter 方法参数。
|
||||
* @return 支持的类型。
|
||||
*/
|
||||
@Override
|
||||
public boolean supportsParameter(@NonNull MethodParameter parameter) {
|
||||
@@ -58,10 +60,9 @@ public class MyRequestArgumentResolver implements HandlerMethodArgumentResolver
|
||||
}
|
||||
|
||||
/**
|
||||
* 参数解析,利用fastjson
|
||||
* 注意:非基本类型返回null会报空指针异常,要通过反射或者JSON工具类创建一个空对象
|
||||
* 参数解析,利用fastjson。
|
||||
* 注意:非基本类型返回null会报空指针异常,要通过反射或者JSON工具类创建一个空对象。
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Object resolveArgument(
|
||||
@NonNull MethodParameter parameter,
|
||||
@@ -73,7 +74,7 @@ public class MyRequestArgumentResolver implements HandlerMethodArgumentResolver
|
||||
if (!HttpMethod.POST.name().equals(servletRequest.getMethod())) {
|
||||
throw new IllegalArgumentException("Only POST method can be applied @MyRequestBody annotation!");
|
||||
}
|
||||
if (!StringUtils.containsIgnoreCase(contentType, "application/json")) {
|
||||
if (!StringUtils.containsIgnoreCase(contentType, MediaType.APPLICATION_JSON_VALUE)) {
|
||||
throw new IllegalArgumentException(
|
||||
"Only application/json Content-Type can be applied @MyRequestBody annotation!");
|
||||
}
|
||||
@@ -106,18 +107,28 @@ public class MyRequestArgumentResolver implements HandlerMethodArgumentResolver
|
||||
// 基本类型包装类
|
||||
if (isBasicDataTypes(parameterType)) {
|
||||
return parseBasicTypeWrapper(parameterType, value);
|
||||
// 字符串类型
|
||||
} else if (parameterType == String.class) {
|
||||
// 字符串类型
|
||||
return value.toString();
|
||||
}
|
||||
// 数组类型
|
||||
if (value instanceof JSONArray) {
|
||||
return parseArray(parameterType, parameterAnnotation.elementType(), key, value);
|
||||
}
|
||||
// 其他复杂对象
|
||||
return JSON.toJavaObject((JSONObject) value, parameterType);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Object parseArray(Class<?> parameterType, Class<?> elementType, String key, Object value)
|
||||
throws IllegalAccessException, InstantiationException {
|
||||
Object o;
|
||||
if (!parameterType.equals(List.class)) {
|
||||
o = parameterType.newInstance();
|
||||
parameterType = (Class<?>) ((ParameterizedType)
|
||||
parameterType.getGenericSuperclass()).getActualTypeArguments()[0];
|
||||
} else {
|
||||
parameterType = parameterAnnotation.elementType();
|
||||
parameterType = elementType;
|
||||
if (parameterType.equals(Class.class)) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("List Type parameter %s MUST have elementType!", key));
|
||||
@@ -130,13 +141,7 @@ public class MyRequestArgumentResolver implements HandlerMethodArgumentResolver
|
||||
((List<Object>) o).addAll(((JSONArray) value).toJavaList(parameterType));
|
||||
return o;
|
||||
}
|
||||
// 其他复杂对象
|
||||
return JSONObject.toJavaObject((JSONObject) value, parameterType);
|
||||
}
|
||||
|
||||
/**
|
||||
* 基本类型解析
|
||||
*/
|
||||
private Object parsePrimitive(String parameterTypeName, Object value) {
|
||||
final String booleanTypeName = "boolean";
|
||||
if (booleanTypeName.equals(parameterTypeName)) {
|
||||
@@ -173,9 +178,6 @@ public class MyRequestArgumentResolver implements HandlerMethodArgumentResolver
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 基本类型包装类解析
|
||||
*/
|
||||
private Object parseBasicTypeWrapper(Class<?> parameterType, Object value) {
|
||||
if (Number.class.isAssignableFrom(parameterType)) {
|
||||
if (value instanceof String) {
|
||||
@@ -203,30 +205,20 @@ public class MyRequestArgumentResolver implements HandlerMethodArgumentResolver
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为基本数据类型包装类
|
||||
*/
|
||||
private boolean isBasicDataTypes(Class<?> clazz) {
|
||||
return classSet.contains(clazz);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取请求体JSON字符串
|
||||
*/
|
||||
private JSONObject getRequestBody(NativeWebRequest webRequest) {
|
||||
private JSONObject getRequestBody(NativeWebRequest webRequest) throws IOException {
|
||||
HttpServletRequest servletRequest = webRequest.getNativeRequest(HttpServletRequest.class);
|
||||
// 有就直接获取
|
||||
JSONObject jsonObject = (JSONObject) webRequest.getAttribute(JSONBODY_ATTRIBUTE, NativeWebRequest.SCOPE_REQUEST);
|
||||
JSONObject jsonObject = (JSONObject) webRequest.getAttribute(JSONBODY_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST);
|
||||
// 没有就从请求中读取
|
||||
if (jsonObject == null) {
|
||||
try {
|
||||
String jsonBody = IOUtils.toString(servletRequest.getReader());
|
||||
jsonObject = JSON.parseObject(jsonBody);
|
||||
if (jsonObject != null) {
|
||||
webRequest.setAttribute(JSONBODY_ATTRIBUTE, jsonObject, NativeWebRequest.SCOPE_REQUEST);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
webRequest.setAttribute(JSONBODY_ATTRIBUTE, jsonObject, RequestAttributes.SCOPE_REQUEST);
|
||||
}
|
||||
}
|
||||
return jsonObject;
|
||||
|
||||
@@ -11,11 +11,12 @@ import java.util.Map;
|
||||
* 应用程序启动后的事件监听对象。主要负责加载Model之间的字典关联和一对一关联所对应的Service结构关系。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
@Component
|
||||
public class LoadCachedDataListener implements ApplicationListener<ApplicationReadyEvent> {
|
||||
|
||||
@SuppressWarnings("all")
|
||||
@Override
|
||||
public void onApplicationEvent(ApplicationReadyEvent applicationReadyEvent) {
|
||||
Map<String, BaseDictService> serviceMap =
|
||||
|
||||
@@ -11,11 +11,12 @@ import java.util.Map;
|
||||
* 应用程序启动后的事件监听对象。主要负责加载Model之间的字典关联和一对一关联所对应的Service结构关系。
|
||||
*
|
||||
* @author Stephen.Liu
|
||||
* @date 2020-04-11
|
||||
* @date 2020-05-24
|
||||
*/
|
||||
@Component
|
||||
public class LoadServiceRelationListener implements ApplicationListener<ApplicationReadyEvent> {
|
||||
|
||||
@SuppressWarnings("all")
|
||||
@Override
|
||||
public void onApplicationEvent(ApplicationReadyEvent applicationReadyEvent) {
|
||||
Map<String, BaseService> serviceMap =
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user