修改手机端PC端接口分离
This commit is contained in:
+573
@@ -0,0 +1,573 @@
|
||||
package com.jero.modules.system.controller;
|
||||
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.crypto.asymmetric.RSA;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.aliyuncs.exceptions.ClientException;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.jero.common.api.vo.Result;
|
||||
import com.jero.common.constant.CacheConstant;
|
||||
import com.jero.common.constant.CommonConstant;
|
||||
import com.jero.common.system.api.ISysBaseAPI;
|
||||
import com.jero.common.system.util.JwtUtil;
|
||||
import com.jero.common.system.vo.LoginUser;
|
||||
import com.jero.common.util.*;
|
||||
import com.jero.common.util.encryption.EncryptedString;
|
||||
import com.jero.modules.base.service.BaseCommonService;
|
||||
import com.jero.modules.config.entity.SysConfig;
|
||||
import com.jero.modules.config.service.ISysConfigService;
|
||||
import com.jero.modules.system.entity.SysDepart;
|
||||
import com.jero.modules.system.entity.SysRole;
|
||||
import com.jero.modules.system.entity.SysUser;
|
||||
import com.jero.modules.system.model.SysLoginModel;
|
||||
import com.jero.modules.system.service.ISysDepartService;
|
||||
import com.jero.modules.system.service.ISysDictService;
|
||||
import com.jero.modules.system.service.ISysLogService;
|
||||
import com.jero.modules.system.service.ISysUserService;
|
||||
import com.jero.modules.system.util.RandImageUtil;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @Author scott
|
||||
* @since 2018-12-17
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/phone/sys")
|
||||
@Api(tags="用户登录")
|
||||
@Slf4j
|
||||
public class PhoneLoginController {
|
||||
@Autowired
|
||||
private ISysUserService sysUserService;
|
||||
@Autowired
|
||||
private ISysBaseAPI sysBaseAPI;
|
||||
@Autowired
|
||||
private ISysLogService logService;
|
||||
@Autowired
|
||||
private RedisUtil redisUtil;
|
||||
@Autowired
|
||||
private ISysDepartService sysDepartService;
|
||||
@Autowired
|
||||
private ISysDictService sysDictService;
|
||||
@Autowired
|
||||
private ISysConfigService iSysConfigService;
|
||||
@Resource
|
||||
private BaseCommonService baseCommonService;
|
||||
|
||||
private static final String BASE_CHECK_CODES = "qwertyuiplkjhgfdsazxcvbnmQWERTYUPLKJHGFDSAZXCVBNM1234567890";
|
||||
//密码登录错误的次数前缀
|
||||
public static final String RETRY_LOGIN_PREFIX = "login:retryLoginCount_";
|
||||
//密码登录错误的最大限制次数
|
||||
public static final int RETRY_LOGIN_MAX_COUNT = 5;
|
||||
@ApiOperation("登录接口")
|
||||
@RequestMapping(value = "/login", method = RequestMethod.POST)
|
||||
public Result<JSONObject> login(@RequestBody SysLoginModel sysLoginModel){
|
||||
Result<JSONObject> result = new Result<JSONObject>();
|
||||
String username = sysLoginModel.getUsername();
|
||||
String password = sysLoginModel.getPassword();
|
||||
String rsaPublicKey = sysLoginModel.getRsaPublicKey();
|
||||
String rsaPrivateKey = String.valueOf(redisUtil.get(rsaPublicKey));
|
||||
//update-begin--Author:scott Date:20190805 for:暂时注释掉密码加密逻辑,有点问题
|
||||
//前端密码加密,后端进行密码解密
|
||||
//password = AesEncryptUtil.desEncrypt(sysLoginModel.getPassword().replaceAll("%2B", "\\+")).trim();//密码解密
|
||||
//update-begin--Author:scott Date:20190805 for:暂时注释掉密码加密逻辑,有点问题
|
||||
//update-begin-author:taoyan date:20190828 for:校验验证码
|
||||
String captcha = sysLoginModel.getCaptcha();
|
||||
if(captcha==null){
|
||||
result.error500("验证码无效");
|
||||
return result;
|
||||
}
|
||||
String lowerCaseCaptcha = captcha.toLowerCase();
|
||||
String realKey = MD5Util.MD5Encode(lowerCaseCaptcha+sysLoginModel.getCheckKey(), "utf-8");
|
||||
Object checkCode = redisUtil.get(realKey);
|
||||
//当进入登录页时,有一定几率出现验证码错误 #1714
|
||||
if(checkCode==null || !checkCode.toString().equals(lowerCaseCaptcha)) {
|
||||
result.error500("验证码错误");
|
||||
return result;
|
||||
}
|
||||
try {
|
||||
//解密获取密码和用户名
|
||||
password = CommonUtils.decryptBtRsaPriKey(password, rsaPrivateKey);
|
||||
username = CommonUtils.decryptBtRsaPriKey(username, rsaPrivateKey);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
//1. 校验用户是否有效
|
||||
//update-begin-author:wangshuai date:20200601 for: 登录代码验证用户是否注销bug,if条件永远为false
|
||||
LambdaQueryWrapper<SysUser> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(SysUser::getUsername,username);
|
||||
SysUser sysUser = sysUserService.getOne(queryWrapper);
|
||||
//update-end-author:wangshuai date:20200601 for: 登录代码验证用户是否注销bug,if条件永远为false
|
||||
result = sysUserService.checkUserIsEffective(sysUser);
|
||||
if(!result.isSuccess()) {
|
||||
return result;
|
||||
}
|
||||
|
||||
// 若用户名有效,则查询该账号的登陆失败次数是否符合等保要求
|
||||
int retryCount = 0 ;
|
||||
if ( redisUtil.get(RETRY_LOGIN_PREFIX + username) != null){
|
||||
retryCount = (int) redisUtil.get(RETRY_LOGIN_PREFIX + username);
|
||||
}
|
||||
if (retryCount >= RETRY_LOGIN_MAX_COUNT){
|
||||
result.error500("密码错误次数过多,请稍后重试");
|
||||
return result;
|
||||
}
|
||||
//2. 校验用户名或密码是否正确
|
||||
String userpassword = PasswordUtil.encrypt(username, password, sysUser.getSalt());
|
||||
String syspassword = sysUser.getPassword();
|
||||
if (!syspassword.equals(userpassword)) {
|
||||
// 重试登录次数加一
|
||||
retryCount++;
|
||||
if( retryCount == 1){
|
||||
redisUtil.set(RETRY_LOGIN_PREFIX + username,retryCount,60 * 30);
|
||||
}else {
|
||||
redisUtil.set(RETRY_LOGIN_PREFIX + username,retryCount,redisUtil.getExpire(RETRY_LOGIN_PREFIX + username));
|
||||
}
|
||||
String msg = retryCount == RETRY_LOGIN_MAX_COUNT ? "密码错误次数过多,请稍后重试":"用户名或密码错误,剩余可登录次数:"+(RETRY_LOGIN_MAX_COUNT - retryCount);
|
||||
result.error500(msg);
|
||||
return result;
|
||||
}
|
||||
//登录成功,清除错误登录次数
|
||||
redisUtil.del(RETRY_LOGIN_PREFIX + username);
|
||||
|
||||
//用户登录信息
|
||||
userInfo(sysUser, result);
|
||||
//update-begin--Author:wangshuai Date:20200714 for:登录日志没有记录人员
|
||||
LoginUser loginUser = new LoginUser();
|
||||
BeanUtils.copyProperties(sysUser, loginUser);
|
||||
baseCommonService.addLog("用户名: " + username + ",登录成功!", CommonConstant.LOG_TYPE_1, null,loginUser);
|
||||
//update-end--Author:wangshuai Date:20200714 for:登录日志没有记录人员
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 退出登录
|
||||
* @param request
|
||||
* @param response
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/logout")
|
||||
public Result<Object> logout(HttpServletRequest request,HttpServletResponse response) {
|
||||
//用户退出逻辑
|
||||
String token = request.getHeader(CommonConstant.X_ACCESS_TOKEN);
|
||||
if(oConvertUtils.isEmpty(token)) {
|
||||
return Result.error("退出登录失败!");
|
||||
}
|
||||
String username = JwtUtil.getUsername(token);
|
||||
LoginUser sysUser = sysBaseAPI.getUserByName(username);
|
||||
if(sysUser!=null) {
|
||||
//update-begin--Author:wangshuai Date:20200714 for:登出日志没有记录人员
|
||||
baseCommonService.addLog("用户名: "+sysUser.getRealname()+",退出成功!", CommonConstant.LOG_TYPE_1, null,sysUser);
|
||||
//update-end--Author:wangshuai Date:20200714 for:登出日志没有记录人员
|
||||
log.info(" 用户名: "+sysUser.getRealname()+",退出成功! ");
|
||||
//清空用户登录Token缓存
|
||||
redisUtil.del(CommonConstant.PREFIX_USER_TOKEN + token);
|
||||
//清空用户登录Shiro权限缓存
|
||||
redisUtil.del(CommonConstant.PREFIX_USER_SHIRO_CACHE + sysUser.getId());
|
||||
//清空用户的缓存信息(包括部门信息),例如sys:cache:user::<username>
|
||||
redisUtil.del(String.format("%s::%s", CacheConstant.SYS_USERS_CACHE, sysUser.getUsername()));
|
||||
//调用shiro的logout
|
||||
SecurityUtils.getSubject().logout();
|
||||
return Result.OK("退出登录成功!");
|
||||
}else {
|
||||
return Result.error("Token无效!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取访问量
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("loginfo")
|
||||
public Result<JSONObject> loginfo() {
|
||||
Result<JSONObject> result = new Result<JSONObject>();
|
||||
JSONObject obj = new JSONObject();
|
||||
//update-begin--Author:zhangweijian Date:20190428 for:传入开始时间,结束时间参数
|
||||
// 获取一天的开始和结束时间
|
||||
Calendar calendar = new GregorianCalendar();
|
||||
calendar.set(Calendar.HOUR_OF_DAY, 0);
|
||||
calendar.set(Calendar.MINUTE, 0);
|
||||
calendar.set(Calendar.SECOND, 0);
|
||||
calendar.set(Calendar.MILLISECOND, 0);
|
||||
Date dayStart = calendar.getTime();
|
||||
calendar.add(Calendar.DATE, 1);
|
||||
Date dayEnd = calendar.getTime();
|
||||
// 获取系统访问记录
|
||||
Long totalVisitCount = logService.findTotalVisitCount();
|
||||
obj.put("totalVisitCount", totalVisitCount);
|
||||
Long todayVisitCount = logService.findTodayVisitCount(dayStart,dayEnd);
|
||||
obj.put("todayVisitCount", todayVisitCount);
|
||||
Long todayIp = logService.findTodayIp(dayStart,dayEnd);
|
||||
//update-end--Author:zhangweijian Date:20190428 for:传入开始时间,结束时间参数
|
||||
obj.put("todayIp", todayIp);
|
||||
result.setResult(obj);
|
||||
result.success("登录成功");
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取访问量
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("visitInfo")
|
||||
public Result<List<Map<String,Object>>> visitInfo() {
|
||||
Result<List<Map<String,Object>>> result = new Result<List<Map<String,Object>>>();
|
||||
Calendar calendar = new GregorianCalendar();
|
||||
calendar.set(Calendar.HOUR_OF_DAY,0);
|
||||
calendar.set(Calendar.MINUTE,0);
|
||||
calendar.set(Calendar.SECOND,0);
|
||||
calendar.set(Calendar.MILLISECOND,0);
|
||||
calendar.add(Calendar.DAY_OF_MONTH, 1);
|
||||
Date dayEnd = calendar.getTime();
|
||||
calendar.add(Calendar.DAY_OF_MONTH, -7);
|
||||
Date dayStart = calendar.getTime();
|
||||
List<Map<String,Object>> list = logService.findVisitCount(dayStart, dayEnd);
|
||||
result.setResult(oConvertUtils.toLowerCasePageList(list));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 登陆成功选择用户当前部门
|
||||
* @param user
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/selectDepart", method = RequestMethod.PUT)
|
||||
public Result<JSONObject> selectDepart(@RequestBody SysUser user) {
|
||||
Result<JSONObject> result = new Result<JSONObject>();
|
||||
String username = user.getUsername();
|
||||
if(oConvertUtils.isEmpty(username)) {
|
||||
LoginUser sysUser = (LoginUser)SecurityUtils.getSubject().getPrincipal();
|
||||
username = sysUser.getUsername();
|
||||
}
|
||||
String orgCode= user.getOrgCode();
|
||||
this.sysUserService.updateUserDepart(username, orgCode);
|
||||
SysUser sysUser = sysUserService.getUserByName(username);
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("userInfo", sysUser);
|
||||
result.setResult(obj);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 短信登录接口
|
||||
*
|
||||
* @param jsonObject
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/sms")
|
||||
public Result<String> sms(@RequestBody JSONObject jsonObject) {
|
||||
Result<String> result = new Result<String>();
|
||||
String mobile = jsonObject.get("mobile").toString();
|
||||
//手机号模式 登录模式: "2" 注册模式: "1"
|
||||
String smsmode=jsonObject.get("smsmode").toString();
|
||||
log.info(mobile);
|
||||
if(oConvertUtils.isEmpty(mobile)){
|
||||
result.setMessage("手机号不允许为空!");
|
||||
result.setSuccess(false);
|
||||
return result;
|
||||
}
|
||||
Object object = redisUtil.get(mobile);
|
||||
if (object != null) {
|
||||
result.setMessage("验证码10分钟内,仍然有效!");
|
||||
result.setSuccess(false);
|
||||
return result;
|
||||
}
|
||||
|
||||
//随机数
|
||||
String captcha = RandomUtil.randomNumbers(6);
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("code", captcha);
|
||||
try {
|
||||
boolean b = false;
|
||||
//注册模板
|
||||
if (CommonConstant.SMS_TPL_TYPE_1.equals(smsmode)) {
|
||||
SysUser sysUser = sysUserService.getUserByPhone(mobile);
|
||||
if(sysUser!=null) {
|
||||
result.error500(" 手机号已经注册,请直接登录!");
|
||||
baseCommonService.addLog("手机号已经注册,请直接登录!", CommonConstant.LOG_TYPE_1, null);
|
||||
return result;
|
||||
}
|
||||
b = DySmsHelper.sendSms(mobile, obj, DySmsEnum.REGISTER_TEMPLATE_CODE);
|
||||
}else {
|
||||
//登录模式,校验用户有效性
|
||||
SysUser sysUser = sysUserService.getUserByPhone(mobile);
|
||||
result = sysUserService.checkUserIsEffective(sysUser);
|
||||
if(!result.isSuccess()) {
|
||||
String message = result.getMessage();
|
||||
if("该用户不存在,请注册".equals(message)){
|
||||
result.error500("该用户不存在或未绑定手机号");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* smsmode 短信模板方式 0 .登录模板、1.注册模板、2.忘记密码模板
|
||||
*/
|
||||
if (CommonConstant.SMS_TPL_TYPE_0.equals(smsmode)) {
|
||||
//登录模板
|
||||
b = DySmsHelper.sendSms(mobile, obj, DySmsEnum.LOGIN_TEMPLATE_CODE);
|
||||
} else if(CommonConstant.SMS_TPL_TYPE_2.equals(smsmode)) {
|
||||
//忘记密码模板
|
||||
b = DySmsHelper.sendSms(mobile, obj, DySmsEnum.FORGET_PASSWORD_TEMPLATE_CODE);
|
||||
}
|
||||
}
|
||||
|
||||
if (b == false) {
|
||||
result.setMessage("短信验证码发送失败,请稍后重试");
|
||||
result.setSuccess(false);
|
||||
return result;
|
||||
}
|
||||
//验证码10分钟内有效
|
||||
redisUtil.set(mobile, captcha, 600);
|
||||
//update-begin--Author:scott Date:20190812 for:issues#391
|
||||
//result.setResult(captcha);
|
||||
//update-end--Author:scott Date:20190812 for:issues#391
|
||||
result.setSuccess(true);
|
||||
|
||||
} catch (ClientException e) {
|
||||
e.printStackTrace();
|
||||
result.error500(" 短信接口未配置,请联系管理员!");
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 手机号登录接口
|
||||
*
|
||||
* @param jsonObject
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation("手机号登录接口")
|
||||
@PostMapping("/phoneLogin")
|
||||
public Result<JSONObject> phoneLogin(@RequestBody JSONObject jsonObject) {
|
||||
Result<JSONObject> result = new Result<JSONObject>();
|
||||
String phone = jsonObject.getString("mobile");
|
||||
|
||||
//校验用户有效性
|
||||
SysUser sysUser = sysUserService.getUserByPhone(phone);
|
||||
result = sysUserService.checkUserIsEffective(sysUser);
|
||||
if(!result.isSuccess()) {
|
||||
return result;
|
||||
}
|
||||
|
||||
String smscode = jsonObject.getString("captcha");
|
||||
Object code = redisUtil.get(phone);
|
||||
if (!smscode.equals(code)) {
|
||||
result.setMessage("手机验证码错误");
|
||||
return result;
|
||||
}
|
||||
//用户信息
|
||||
userInfo(sysUser, result);
|
||||
//添加日志
|
||||
baseCommonService.addLog("用户名: " + sysUser.getUsername() + ",登录成功!", CommonConstant.LOG_TYPE_1, null);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 用户信息
|
||||
*
|
||||
* @param sysUser
|
||||
* @param result
|
||||
* @return
|
||||
*/
|
||||
private Result<JSONObject> userInfo(SysUser sysUser, Result<JSONObject> result) {
|
||||
String syspassword = sysUser.getPassword();
|
||||
String username = sysUser.getUsername();
|
||||
// 生成token
|
||||
String token = JwtUtil.sign(username, syspassword);
|
||||
// 设置token缓存有效时间
|
||||
redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token);
|
||||
redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME*2 / 1000);
|
||||
|
||||
// 获取用户部门信息
|
||||
JSONObject obj = new JSONObject();
|
||||
List<SysDepart> departs = sysDepartService.queryUserDeparts(sysUser.getId());
|
||||
obj.put("departs", departs);
|
||||
if (departs == null || departs.size() == 0) {
|
||||
obj.put("multi_depart", 0);
|
||||
} else if (departs.size() == 1) {
|
||||
sysUserService.updateUserDepart(username, departs.get(0).getOrgCode());
|
||||
obj.put("multi_depart", 1);
|
||||
} else {
|
||||
//查询当前是否有登录部门
|
||||
// update-begin--Author:wangshuai Date:20200805 for:如果用戶为选择部门,数据库为存在上一次登录部门,则取一条存进去
|
||||
SysUser sysUserById = sysUserService.getById(sysUser.getId());
|
||||
if(oConvertUtils.isEmpty(sysUserById.getOrgCode())){
|
||||
sysUserService.updateUserDepart(username, departs.get(0).getOrgCode());
|
||||
}
|
||||
// update-end--Author:wangshuai Date:20200805 for:如果用戶为选择部门,数据库为存在上一次登录部门,则取一条存进去
|
||||
obj.put("multi_depart", 2);
|
||||
}
|
||||
|
||||
// 获取用户角色信息
|
||||
List<SysRole> userRoleListInfo = sysUserService.queryUserRoleListInfoByUserId(sysUser.getId());
|
||||
sysUser.setUserRoleList(userRoleListInfo);
|
||||
|
||||
//获取配置信息
|
||||
List<SysConfig> sysConfigs = iSysConfigService.queryList();
|
||||
if(CollectionUtils.isNotEmpty(sysConfigs)){
|
||||
for (SysConfig sysConfig : sysConfigs) {
|
||||
obj.put(sysConfig.getConfigName(),sysConfig.getConfig());
|
||||
}
|
||||
}
|
||||
|
||||
obj.put("token", token);
|
||||
obj.put("userInfo", sysUser);
|
||||
obj.put("sysAllDictItems", sysDictService.queryAllDictItems());
|
||||
result.setResult(obj);
|
||||
result.success("登录成功");
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取加密字符串
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/getEncryptedString")
|
||||
public Result<Map<String,String>> getEncryptedString(){
|
||||
Result<Map<String,String>> result = new Result<Map<String,String>>();
|
||||
Map<String,String> map = new HashMap<String,String>();
|
||||
map.put("key", EncryptedString.key);
|
||||
map.put("iv",EncryptedString.iv);
|
||||
result.setResult(map);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 后台生成图形验证码 :有效
|
||||
* @param response
|
||||
* @param key
|
||||
*/
|
||||
@ApiOperation("获取验证码")
|
||||
@GetMapping(value = "/randomImage/{key}")
|
||||
public Result<String> randomImage(HttpServletResponse response,@PathVariable String key){
|
||||
Result<String> res = new Result<String>();
|
||||
try {
|
||||
String code = RandomUtil.randomString(BASE_CHECK_CODES,4);
|
||||
String lowerCaseCode = code.toLowerCase();
|
||||
String realKey = MD5Util.MD5Encode(lowerCaseCode+key, "utf-8");
|
||||
redisUtil.set(realKey, lowerCaseCode, 60);
|
||||
String base64 = RandImageUtil.generate(code);
|
||||
res.setSuccess(true);
|
||||
res.setResult(base64);
|
||||
} catch (Exception e) {
|
||||
res.error500("获取验证码出错"+e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* app登录
|
||||
* @param sysLoginModel
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
@RequestMapping(value = "/mLogin", method = RequestMethod.POST)
|
||||
public Result<JSONObject> mLogin(@RequestBody SysLoginModel sysLoginModel) throws Exception {
|
||||
Result<JSONObject> result = new Result<JSONObject>();
|
||||
String username = sysLoginModel.getUsername();
|
||||
String password = sysLoginModel.getPassword();
|
||||
|
||||
//1. 校验用户是否有效
|
||||
SysUser sysUser = sysUserService.getUserByName(username);
|
||||
result = sysUserService.checkUserIsEffective(sysUser);
|
||||
if(!result.isSuccess()) {
|
||||
return result;
|
||||
}
|
||||
|
||||
//2. 校验用户名或密码是否正确
|
||||
String userpassword = PasswordUtil.encrypt(username, password, sysUser.getSalt());
|
||||
String syspassword = sysUser.getPassword();
|
||||
if (!syspassword.equals(userpassword)) {
|
||||
result.error500("用户名或密码错误");
|
||||
return result;
|
||||
}
|
||||
|
||||
String orgCode = sysUser.getOrgCode();
|
||||
if(oConvertUtils.isEmpty(orgCode)) {
|
||||
//如果当前用户无选择部门 查看部门关联信息
|
||||
List<SysDepart> departs = sysDepartService.queryUserDeparts(sysUser.getId());
|
||||
if (departs == null || departs.size() == 0) {
|
||||
result.error500("用户暂未归属部门,不可登录!");
|
||||
return result;
|
||||
}
|
||||
orgCode = departs.get(0).getOrgCode();
|
||||
sysUser.setOrgCode(orgCode);
|
||||
this.sysUserService.updateUserDepart(username, orgCode);
|
||||
}
|
||||
JSONObject obj = new JSONObject();
|
||||
//用户登录信息
|
||||
obj.put("userInfo", sysUser);
|
||||
|
||||
// 生成token
|
||||
String token = JwtUtil.sign(username, syspassword);
|
||||
// 设置超时时间
|
||||
redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token);
|
||||
redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME*2 / 1000);
|
||||
|
||||
//token 信息
|
||||
obj.put("token", token);
|
||||
result.setResult(obj);
|
||||
result.setSuccess(true);
|
||||
result.setCode(200);
|
||||
baseCommonService.addLog("用户名: " + username + ",登录成功[移动端]!", CommonConstant.LOG_TYPE_1, null);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 图形验证码
|
||||
* @param sysLoginModel
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/checkCaptcha", method = RequestMethod.POST)
|
||||
public Result<?> checkCaptcha(@RequestBody SysLoginModel sysLoginModel){
|
||||
String captcha = sysLoginModel.getCaptcha();
|
||||
String checkKey = sysLoginModel.getCheckKey();
|
||||
if(captcha==null){
|
||||
return Result.error("验证码无效");
|
||||
}
|
||||
String lowerCaseCaptcha = captcha.toLowerCase();
|
||||
String realKey = MD5Util.MD5Encode(lowerCaseCaptcha+checkKey, "utf-8");
|
||||
Object checkCode = redisUtil.get(realKey);
|
||||
if(checkCode==null || !checkCode.equals(lowerCaseCaptcha)) {
|
||||
return Result.error("验证码错误");
|
||||
}
|
||||
return Result.OK();
|
||||
}
|
||||
/**
|
||||
* 返回一个RSA公钥
|
||||
* @author 马志朝
|
||||
* @date 2021/4/15 15:01
|
||||
* @param
|
||||
* @return com.jero.common.api.vo.Result<java.lang.String>
|
||||
*/
|
||||
@ApiOperation("获取RSA公钥")
|
||||
@GetMapping("/getRSAPublicKey")
|
||||
public Result<String> getRSAPublicKey(){
|
||||
RSA rsa = new RSA();
|
||||
String privateKeyBase64 = rsa.getPrivateKeyBase64();
|
||||
String publicKeyBase64 = rsa.getPublicKeyBase64();
|
||||
//存到redis key为公钥 value为私钥
|
||||
redisUtil.set(publicKeyBase64, privateKeyBase64, 60L);
|
||||
Result<String> result = new Result<>();
|
||||
result.setResult(publicKeyBase64);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+856
@@ -0,0 +1,856 @@
|
||||
package com.jero.modules.system.controller;
|
||||
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.jero.common.api.vo.Result;
|
||||
import com.jero.common.aspect.annotation.AutoLog;
|
||||
import com.jero.common.constant.CacheConstant;
|
||||
import com.jero.common.constant.CommonConstant;
|
||||
import com.jero.common.system.query.QueryGenerator;
|
||||
import com.jero.common.system.vo.DictModel;
|
||||
import com.jero.common.system.vo.LoginUser;
|
||||
import com.jero.common.util.ImportExcelUtil;
|
||||
import com.jero.common.util.SqlInjectionUtil;
|
||||
import com.jero.common.util.oConvertUtils;
|
||||
import com.jero.modules.enums.DictCodeEnum;
|
||||
import com.jero.modules.enums.FixedFieldEnum;
|
||||
import com.jero.modules.enums.IsTagDict;
|
||||
import com.jero.modules.system.entity.SysDict;
|
||||
import com.jero.modules.system.entity.SysDictItem;
|
||||
import com.jero.modules.system.entity.SysUser;
|
||||
import com.jero.modules.system.model.SysDictTree;
|
||||
import com.jero.modules.system.model.TreeSelectModel;
|
||||
import com.jero.modules.system.service.IProjectUserBrandService;
|
||||
import com.jero.modules.system.service.ISysDictItemService;
|
||||
import com.jero.modules.system.service.ISysDictService;
|
||||
import com.jero.modules.system.service.ISysUserService;
|
||||
import com.jero.modules.system.vo.SysDictPage;
|
||||
import com.jero.modules.utils.HanYuPinYinUtil;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.apache.shiro.authz.annotation.RequiresRoles;
|
||||
import org.jeecgframework.poi.excel.ExcelImportCheckUtil;
|
||||
import org.jeecgframework.poi.excel.ExcelImportUtil;
|
||||
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
|
||||
import org.jeecgframework.poi.excel.entity.ExportParams;
|
||||
import org.jeecgframework.poi.excel.entity.ImportParams;
|
||||
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 字典表 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @Author zhangweijian
|
||||
* @since 2018-12-28
|
||||
*/
|
||||
@RestController
|
||||
@Api(tags = "字典控制器")
|
||||
@RequestMapping("/phone/sys/dict")
|
||||
@Slf4j
|
||||
public class PhoneSysDictController {
|
||||
|
||||
@Autowired
|
||||
private ISysDictService sysDictService;
|
||||
@Autowired
|
||||
private ISysDictItemService sysDictItemService;
|
||||
@Autowired
|
||||
public RedisTemplate<String, Object> redisTemplate;
|
||||
@Autowired
|
||||
private ISysUserService sysUserService;
|
||||
@Autowired
|
||||
private IProjectUserBrandService projectUserBrandService;
|
||||
|
||||
@RequestMapping(value = "/page", method = RequestMethod.GET)
|
||||
@ApiOperation(value = "字典控制器-分页列表查询", notes = "字典控制器-分页列表查询")
|
||||
public Result<IPage<SysDict>> queryPageList(SysDict sysDict, @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
|
||||
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize, HttpServletRequest req) {
|
||||
Result<IPage<SysDict>> result = new Result<IPage<SysDict>>();
|
||||
QueryWrapper<SysDict> queryWrapper = QueryGenerator.initQueryWrapper(sysDict, req.getParameterMap());
|
||||
queryWrapper.eq("del_flag",CommonConstant.DEL_FLAG_0);
|
||||
queryWrapper.eq("is_tag_dict", IsTagDict.SYS_DICT_SYSTEM.getValue());
|
||||
Page<SysDict> page = new Page<SysDict>(pageNo, pageSize);
|
||||
IPage<SysDict> pageList = sysDictService.page(page, queryWrapper);
|
||||
log.debug("查询当前页:"+pageList.getCurrent());
|
||||
log.debug("查询当前页数量:"+pageList.getSize());
|
||||
log.debug("查询结果数量:"+pageList.getRecords().size());
|
||||
log.debug("数据总数:"+pageList.getTotal());
|
||||
result.setSuccess(true);
|
||||
result.setResult(pageList);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 标签内容-分页查询
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "标签内容-分页列表查询")
|
||||
@ApiOperation(value="标签内容-分页列表查询", notes="区域管理表-分页列表查询")
|
||||
@RequiresPermissions("dict:tagDictPage")
|
||||
@PostMapping(value = "/tagDictPage")
|
||||
public Result<?> queryPageList(@RequestBody Map<String,Object> params) {
|
||||
IPage<SysDict> pageList=sysDictService.queryPageList(params);
|
||||
return Result.OK(pageList);
|
||||
}
|
||||
|
||||
/**
|
||||
* @功能:获取树形字典数据
|
||||
* @param sysDict
|
||||
* @param pageNo
|
||||
* @param pageSize
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "字典控制器-树形字典数据", notes = "字典控制器-树形字典数据")
|
||||
@RequestMapping(value = "/treeList", method = RequestMethod.GET)
|
||||
public Result<List<SysDictTree>> treeList(SysDict sysDict, @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
|
||||
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize, HttpServletRequest req) {
|
||||
Result<List<SysDictTree>> result = new Result<>();
|
||||
LambdaQueryWrapper<SysDict> query = new LambdaQueryWrapper<>();
|
||||
// 构造查询条件
|
||||
String dictName = sysDict.getDictName();
|
||||
if(oConvertUtils.isNotEmpty(dictName)) {
|
||||
query.like(true, SysDict::getDictName, dictName);
|
||||
}
|
||||
query.orderByDesc(true, SysDict::getCreateTime);
|
||||
List<SysDict> list = sysDictService.list(query);
|
||||
List<SysDictTree> treeList = new ArrayList<>();
|
||||
for (SysDict node : list) {
|
||||
treeList.add(new SysDictTree(node));
|
||||
}
|
||||
result.setSuccess(true);
|
||||
result.setResult(treeList);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取字典数据
|
||||
* @param dictCode 字典code
|
||||
* @param dictCode 表名,文本字段,code字段 | 举例:sys_user,realname,id
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "字典控制器-根据字典编码获取字典数据", notes = "字典控制器-根据字典编码获取字典数据")
|
||||
@RequestMapping(value = "/getDictItems/{dictCode}", method = RequestMethod.GET)
|
||||
public Result<List<DictModel>> getDictItems(@PathVariable String dictCode, @RequestParam(value = "sign",required = false) String sign, HttpServletRequest request) {
|
||||
log.info(" dictCode : "+ dictCode);
|
||||
Result<List<DictModel>> result = new Result<List<DictModel>>();
|
||||
List<DictModel> ls = null;
|
||||
try {
|
||||
if(dictCode.indexOf(",")!=-1) {
|
||||
//关联表字典(举例:sys_user,realname,id)
|
||||
String[] params = dictCode.split(",");
|
||||
|
||||
if(params.length<3) {
|
||||
result.error500("字典Code格式不正确!");
|
||||
return result;
|
||||
}
|
||||
//SQL注入校验(只限制非法串改数据库)
|
||||
final String[] sqlInjCheck = {params[0],params[1],params[2]};
|
||||
SqlInjectionUtil.filterContent(sqlInjCheck);
|
||||
|
||||
if(params.length==4) {
|
||||
//SQL注入校验(查询条件SQL 特殊check,此方法仅供此处使用)
|
||||
SqlInjectionUtil.specialFilterContent(params[3]);
|
||||
ls = sysDictService.queryTableDictItemsByCodeAndFilter(params[0],params[1],params[2],params[3]);
|
||||
}else if (params.length==3) {
|
||||
ls = sysDictService.queryTableDictItemsByCode(params[0],params[1],params[2]);
|
||||
}else{
|
||||
result.error500("字典Code格式不正确!");
|
||||
return result;
|
||||
}
|
||||
}else {
|
||||
//字典表
|
||||
ls = sysDictService.queryDictItemsByCode(dictCode);
|
||||
}
|
||||
|
||||
// 将结果集进行排序
|
||||
/*if (CollectionUtils.isNotEmpty(ls)) {
|
||||
// 匿名比较器排序
|
||||
Collections.sort(ls, new Comparator<DictModel>() {
|
||||
@Override
|
||||
public int compare(DictModel p1, DictModel p2) {
|
||||
return p1.getText().compareTo(p2.getText());
|
||||
}
|
||||
});
|
||||
}*/
|
||||
|
||||
result.setSuccess(true);
|
||||
result.setResult(ls);
|
||||
log.debug(result.toString());
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(),e);
|
||||
result.error500("操作失败");
|
||||
return result;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取全部字典数据
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "字典控制器-获取全部字典数据", notes = "字典控制器-获取全部字典数据")
|
||||
@RequestMapping(value = "/queryAllDictItems", method = RequestMethod.GET)
|
||||
public Result<?> queryAllDictItems(HttpServletRequest request) {
|
||||
Map<String, List<DictModel>> res = new HashMap<String, List<DictModel>>();
|
||||
res = sysDictService.queryAllDictItems();
|
||||
//添加成功后需要刷新缓存
|
||||
sysDictService.refreshCache();
|
||||
return Result.OK(res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取全部字典数据(中英文切换)
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "字典控制器-获取全部字典数据", notes = "字典控制器-获取全部字典数据")
|
||||
@RequestMapping(value = "/queryAllDictItemsByCut", method = RequestMethod.GET)
|
||||
public Result<?> queryAllDictItemsByCut(HttpServletRequest request,String cut) {
|
||||
Map<String, List<DictModel>> res = new HashMap<String, List<DictModel>>();
|
||||
res = sysDictService.queryAllDictItemsByCut(cut);
|
||||
return Result.OK(res);
|
||||
}
|
||||
@ApiOperation(value = "更新浏览器内保存的数据字典数据", notes = "更新浏览器内保存的数据字典数据")
|
||||
@RequestMapping(value = "/login", method = RequestMethod.POST)
|
||||
private Result<JSONObject> userInfo(SysUser sysUser, Result<JSONObject> result) {
|
||||
// 获取数据字典
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("sysAllDictItems", sysDictService.queryAllDictItems());
|
||||
result.setResult(obj);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取字典数据
|
||||
* @param dictCode
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "字典控制器-通过字典code和字典值key获取字典数据", notes = "字典控制器-通过字典code和字典值key获取字典数据")
|
||||
@RequestMapping(value = "/getDictText/{dictCode}/{key}", method = RequestMethod.GET)
|
||||
public Result<String> getDictText(@PathVariable("dictCode") String dictCode, @PathVariable("key") String key) {
|
||||
log.info(" dictCode : "+ dictCode);
|
||||
Result<String> result = new Result<String>();
|
||||
String text = null;
|
||||
try {
|
||||
text = sysDictService.queryDictTextByKey(dictCode, key);
|
||||
result.setSuccess(true);
|
||||
result.setResult(text);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(),e);
|
||||
result.error500("操作失败");
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 大数据量的字典表 走异步加载 即前端输入内容过滤数据
|
||||
* @param dictCode
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "字典控制器-通过字典code获取字典数据", notes = "字典控制器-通过字典code获取字典数据")
|
||||
@RequestMapping(value = "/loadDict/{dictCode}", method = RequestMethod.GET)
|
||||
public Result<List<DictModel>> loadDict(@PathVariable String dictCode,
|
||||
@RequestParam(name="keyword") String keyword,
|
||||
@RequestParam(value = "sign",required = false) String sign,
|
||||
@RequestParam(value = "pageSize", required = false) Integer pageSize) {
|
||||
log.info(" 加载字典表数据,加载关键字: "+ keyword);
|
||||
Result<List<DictModel>> result = new Result<List<DictModel>>();
|
||||
List<DictModel> ls = null;
|
||||
try {
|
||||
if(dictCode.indexOf(",")!=-1) {
|
||||
String[] params = dictCode.split(",");
|
||||
if(params.length!=3) {
|
||||
result.error500("字典Code格式不正确!");
|
||||
return result;
|
||||
}
|
||||
if(pageSize!=null){
|
||||
ls = sysDictService.queryLittleTableDictItems(params[0],params[1],params[2],keyword, pageSize);
|
||||
}else{
|
||||
ls = sysDictService.queryTableDictItems(params[0],params[1],params[2],keyword);
|
||||
}
|
||||
result.setSuccess(true);
|
||||
result.setResult(ls);
|
||||
log.info(result.toString());
|
||||
}else {
|
||||
result.error500("字典Code格式不正确!");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(),e);
|
||||
result.error500("操作失败");
|
||||
return result;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据字典code加载字典text 返回
|
||||
*/
|
||||
@ApiOperation(value = "字典控制器-根据字典code加载字典text", notes = "字典控制器-根据字典code加载字典text")
|
||||
@RequestMapping(value = "/loadDictItem/{dictCode}", method = RequestMethod.GET)
|
||||
public Result<List<String>> loadDictItem(@PathVariable String dictCode, @RequestParam(name="key") String keys, @RequestParam(value = "sign",required = false) String sign, HttpServletRequest request) {
|
||||
Result<List<String>> result = new Result<>();
|
||||
try {
|
||||
if(dictCode.indexOf(",")!=-1) {
|
||||
String[] params = dictCode.split(",");
|
||||
if(params.length!=3) {
|
||||
result.error500("字典Code格式不正确!");
|
||||
return result;
|
||||
}
|
||||
List<String> texts = sysDictService.queryTableDictByKeys(params[0], params[1], params[2], keys);
|
||||
|
||||
result.setSuccess(true);
|
||||
result.setResult(texts);
|
||||
log.info(result.toString());
|
||||
}else {
|
||||
result.error500("字典Code格式不正确!");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(),e);
|
||||
result.error500("操作失败");
|
||||
return result;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据表名——显示字段-存储字段 pid 加载树形数据
|
||||
*/
|
||||
@ApiOperation(value = "字典控制器-根据表名—显示字段-存储字段 pid 加载树形数据", notes = "字典控制器-根据表名—显示字段-存储字段 pid 加载树形数据")
|
||||
@RequestMapping(value = "/loadTreeData", method = RequestMethod.GET)
|
||||
public Result<List<TreeSelectModel>> loadTreeData(@RequestParam(name="pid") String pid, @RequestParam(name="pidField") String pidField,
|
||||
@RequestParam(name="tableName") String tbname,
|
||||
@RequestParam(name="text") String text,
|
||||
@RequestParam(name="code") String code,
|
||||
@RequestParam(name="hasChildField", required = false) String hasChildField,
|
||||
@RequestParam(value = "sign", required = false) String sign, HttpServletRequest request) {
|
||||
Result<List<TreeSelectModel>> result = new Result<List<TreeSelectModel>>();
|
||||
|
||||
// SQL注入漏洞 sign签名校验(表名,label字段,val字段,条件)
|
||||
String dictCode = tbname +","+ text +","+ code;
|
||||
SqlInjectionUtil.filterContent(dictCode);
|
||||
List<TreeSelectModel> ls = sysDictService.queryTreeList(null, tbname, text, code, pidField, pid, hasChildField);
|
||||
result.setSuccess(true);
|
||||
result.setResult(ls);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询后返回树型数据
|
||||
*/
|
||||
@ApiOperation(value = "字典控制器-根据表名—显示字段-存储字段 加载树形数据", notes = "字典控制器-根据表名—显示字段-存储字段 加载树形数据")
|
||||
@RequestMapping(value = "/queryAllTreeData", method = RequestMethod.GET)
|
||||
public Result<List<TreeSelectModel>> queryAllTreeData(@RequestParam(name="pidField") String pidField,
|
||||
@RequestParam(name="tableName") String tbname,
|
||||
@RequestParam(name="text") String text,
|
||||
@RequestParam(name="code") String code,
|
||||
HttpServletRequest request) {
|
||||
Result<List<TreeSelectModel>> result = new Result<List<TreeSelectModel>>();
|
||||
|
||||
// SQL注入漏洞 sign签名校验(表名,label字段,val字段,条件)
|
||||
String dictCode = tbname +","+ text +","+ code;
|
||||
SqlInjectionUtil.filterContent(dictCode);
|
||||
List<TreeSelectModel> ls = sysDictService.queryAllTreeData(tbname, text, code, pidField);
|
||||
result.setSuccess(true);
|
||||
result.setResult(ls);
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* 查询被删除的列表
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/deleteList")
|
||||
public Result<List<SysDict>> deleteList() {
|
||||
Result<List<SysDict>> result = new Result<List<SysDict>>();
|
||||
List<SysDict> list = this.sysDictService.queryDeleteList();
|
||||
result.setSuccess(true);
|
||||
result.setResult(list);
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* @功能:新增
|
||||
* @param sysDict
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "字典控制器-新增字典", notes = "字典控制器-新增字典")
|
||||
@RequiresRoles({"admin"})
|
||||
@RequestMapping(value = "/add", method = RequestMethod.POST)
|
||||
@RequiresPermissions("dict:add")
|
||||
public Result<SysDict> add(@RequestBody SysDict sysDict) {
|
||||
Result<SysDict> result = new Result<SysDict>();
|
||||
|
||||
sysDictService.setAddOrdderNum(sysDict);
|
||||
//校验--不能重复数据
|
||||
QueryWrapper<SysDict> queryWrapper = new QueryWrapper<>();
|
||||
//查询同一模块下,同名数据
|
||||
queryWrapper.eq("dict_name",sysDict.getDictName())
|
||||
.eq("is_tag_dict",sysDict.getIsTagDict());
|
||||
List<SysDict> existDictList = this.sysDictService.list(queryWrapper);
|
||||
try {
|
||||
if(!existDictList.isEmpty()) {
|
||||
SysDict sysDictDB = existDictList.get(0);
|
||||
//存在重复同名标签内容,且已删,恢复
|
||||
if (sysDictDB.getDelFlag() == CommonConstant.DEL_FLAG_1) {
|
||||
sysDictService.updateDictDelFlag(CommonConstant.DEL_FLAG_0, sysDictDB.getId());
|
||||
}else{//存在重复同名标签内容,未删
|
||||
result.error500("标签名称不能重复");
|
||||
}
|
||||
} else {//不是同名
|
||||
if (ObjectUtils.isNotEmpty(sysDict.getIsTagDict())
|
||||
&& sysDict.getIsTagDict() == IsTagDict.TAG_DICT.getValue()) {
|
||||
String pinYin = HanYuPinYinUtil.changeToNumberPinYin(sysDict.getDictName());
|
||||
sysDict.setDictCode(pinYin.replace(" ","_"));
|
||||
|
||||
sysDict.setCreateTime(new Date());
|
||||
sysDict.setDelFlag(CommonConstant.DEL_FLAG_0);
|
||||
|
||||
// sysDict.setDictName(sysDict.getDictName().replace(" ",""));
|
||||
sysDictService.save(sysDict);
|
||||
}else if(sysDict.getIsTagDict() == IsTagDict.SYS_DICT_SYSTEM.getValue()){
|
||||
sysDict.setCreateTime(new Date());
|
||||
sysDict.setDelFlag(CommonConstant.DEL_FLAG_0);
|
||||
sysDictService.save(sysDict);
|
||||
}
|
||||
result.success("保存成功!");
|
||||
//添加成功后需要刷新缓存
|
||||
sysDictService.refreshCache();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(),e);
|
||||
result.error500("操作失败");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @功能:编辑
|
||||
* @param sysDict
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "字典控制器-编辑字典", notes = "字典控制器-编辑字典")
|
||||
@RequiresRoles({"admin"})
|
||||
@RequestMapping(value = "/edit", method = RequestMethod.PUT)
|
||||
@RequiresPermissions("dict:edit")
|
||||
public Result<SysDict> edit(@RequestBody SysDict sysDict) {
|
||||
Result<SysDict> result = new Result<SysDict>();
|
||||
sysDictService.setEditOrderNum(sysDict);
|
||||
SysDict sysdict = sysDictService.getById(sysDict.getId());
|
||||
if (sysdict == null) {
|
||||
result.error500("未找到对应实体");
|
||||
}else {
|
||||
if (StringUtils.isNotBlank(String.valueOf(sysDict.getIsReadOnly()))) {
|
||||
if (FixedFieldEnum.FIXED_FIELD_ENUM.getValue().equals(String.valueOf(sysDict.getIsReadOnly()))) {
|
||||
result.error500("固定字段,不可修改");
|
||||
} else {
|
||||
//校验--不能重复数据
|
||||
QueryWrapper<SysDict> queryWrapper = new QueryWrapper<>();
|
||||
//查询同一模块下,同名数据
|
||||
queryWrapper.eq("dict_name", sysDict.getDictName())
|
||||
.eq("is_tag_dict",sysDict.getIsTagDict());
|
||||
List<SysDict> existDictList = this.sysDictService.list(queryWrapper);
|
||||
if (!existDictList.isEmpty()) {
|
||||
if (existDictList.get(0).getId().equals(sysDict.getId())) {//已存在同名的数据,就是正在编辑的这个
|
||||
sysDict.setUpdateTime(new Date());
|
||||
boolean ok = sysDictService.updateById(sysDict);
|
||||
if (ok) {
|
||||
result.success("编辑成功!");
|
||||
//编辑成功后需要刷新缓存
|
||||
sysDictService.refreshCache();
|
||||
}
|
||||
} else {//已存在同名的数据,不是正在编辑的这个
|
||||
SysDict sysDictDB = existDictList.get(0);
|
||||
//存在重复同名标签内容,且已删,恢复
|
||||
if (sysDictDB.getDelFlag() == CommonConstant.DEL_FLAG_1) {
|
||||
sysDictService.updateDictDelFlag(CommonConstant.DEL_FLAG_0, sysDictDB.getId());
|
||||
} else {//存在重复同名标签内容,未删
|
||||
result.error500("标签名称不能重复");
|
||||
}
|
||||
}
|
||||
} else {//不是同名
|
||||
sysDict.setUpdateTime(new Date());
|
||||
boolean ok = sysDictService.updateById(sysDict);
|
||||
if (ok) {
|
||||
result.success("编辑成功!");
|
||||
//编辑成功后需要刷新缓存
|
||||
sysDictService.refreshCache();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @功能:删除
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "字典控制器-删除字典", notes = "字典控制器-删除字典")
|
||||
@RequiresRoles({"admin"})
|
||||
@DeleteMapping(value = "/delete")
|
||||
@CacheEvict(value=CacheConstant.SYS_DICT_CACHE, allEntries=true)
|
||||
public Result<SysDict> delete(@RequestParam(name="id",required=true) String id) {
|
||||
|
||||
Result<SysDict> result = new Result<SysDict>();
|
||||
SysDict sysDict = sysDictService.queryById(id);
|
||||
if (StringUtils.isNotBlank(String.valueOf(sysDict.getIsReadOnly()))) {
|
||||
if (FixedFieldEnum.FIXED_FIELD_ENUM.getValue().equals(String.valueOf(sysDict.getIsReadOnly()))) {
|
||||
result.error500("固定字段,不可删除");
|
||||
} else {
|
||||
boolean ok = sysDictService.removeById(id);
|
||||
if (ok) {
|
||||
result.success("删除成功!");
|
||||
} else {
|
||||
result.error500("删除失败!");
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @功能:逻辑删除
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "字典控制器-逻辑删除字典", notes = "字典控制器-逻辑删除字典")
|
||||
@RequiresRoles({"admin"})
|
||||
@GetMapping(value = "/logicDelete")
|
||||
@CacheEvict(value=CacheConstant.SYS_DICT_CACHE, allEntries=true)
|
||||
@RequiresPermissions("dict:logicDelete")
|
||||
public Result<SysDict> logicDelete(@RequestParam(name="id",required=true) String id) {
|
||||
|
||||
Result<SysDict> result = new Result<SysDict>();
|
||||
try{
|
||||
SysDict sysDict = sysDictService.queryById(id);
|
||||
if (FixedFieldEnum.FIXED_FIELD_ENUM.getValue().equals(String.valueOf(sysDict.getIsReadOnly()))) {
|
||||
result.error500("固定字段,不可删除");
|
||||
} else {
|
||||
sysDictService.updateDictDelFlag(CommonConstant.DEL_FLAG_1,id);
|
||||
result.success("删除成功!");
|
||||
}
|
||||
}catch (Exception e) {
|
||||
log.error(e.getMessage(),e);
|
||||
result.error500("删除失败");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @功能:批量删除
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "字典控制器-批量字典", notes = "字典控制器-批量字典")
|
||||
@DeleteMapping(value = "/deleteBatch")
|
||||
@CacheEvict(value= CacheConstant.SYS_DICT_CACHE, allEntries=true)
|
||||
public Result<SysDict> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
|
||||
Result<SysDict> result = new Result<SysDict>();
|
||||
SysDict sysDict = sysDictService.queryById(ids);
|
||||
if(oConvertUtils.isEmpty(ids)) {
|
||||
result.error500("参数不识别!");
|
||||
}else {
|
||||
List<String> idList = Arrays.asList(ids.split(","));
|
||||
for (String list : idList) {
|
||||
SysDict midDict = sysDictService.getById(list);
|
||||
if (FixedFieldEnum.FIXED_FIELD_ENUM.getValue().equals(String.valueOf(sysDict.getIsReadOnly())) || FixedFieldEnum.CONFIGURABLE_FIELD.getValue().equals(String.valueOf(midDict.getIsReadOnly()))) {
|
||||
return result.error500("包含固定字段,不可删除");
|
||||
} else {
|
||||
sysDictService.removeByIds(idList);
|
||||
result.success("删除成功!");
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @功能:批量逻辑删除
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "字典控制器-批量字典", notes = "字典控制器-批量字典")
|
||||
@GetMapping(value = "/logicDeleteBatch")
|
||||
@CacheEvict(value= CacheConstant.SYS_DICT_CACHE, allEntries=true)
|
||||
public Result<SysDict> logicdeleteBatch(@RequestParam(name="ids",required=true) String ids) {
|
||||
Result<SysDict> result = new Result<SysDict>();
|
||||
List<String> idList = Arrays.asList(ids.split(","));
|
||||
for(String list:idList){
|
||||
SysDict joinSystem=sysDictService.getById(list);
|
||||
if(oConvertUtils.isEmpty(ids)) {
|
||||
result.error500("参数不识别!");
|
||||
}else {
|
||||
if (StringUtils.isNotBlank(String.valueOf(joinSystem.getIsReadOnly()))) {
|
||||
if (FixedFieldEnum.FIXED_FIELD_ENUM.getValue().equals(String.valueOf(joinSystem.getIsReadOnly()))) {
|
||||
result.error500("包含固定字段,不可删除");
|
||||
} else {
|
||||
sysDictService.updateDictDelFlag(CommonConstant.DEL_FLAG_1,joinSystem.getId());
|
||||
result.success("批量删除成功!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @功能:刷新缓存
|
||||
* @date 修改时间 2021.4.8
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/refleshCache")
|
||||
public Result<?> refleshCache() {
|
||||
Result<?> result = new Result<SysDict>();
|
||||
sysDictService.refreshCache();
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出excel
|
||||
*
|
||||
* @param request
|
||||
*/
|
||||
@RequestMapping(value = "/exportXls")
|
||||
public ModelAndView exportXls(SysDict sysDict, HttpServletRequest request) {
|
||||
// Step.1 组装查询条件
|
||||
QueryWrapper<SysDict> queryWrapper = QueryGenerator.initQueryWrapper(sysDict, request.getParameterMap());
|
||||
//Step.2 AutoPoi 导出Excel
|
||||
ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
|
||||
List<SysDictPage> pageList = new ArrayList<SysDictPage>();
|
||||
|
||||
List<SysDict> sysDictList = sysDictService.list(queryWrapper);
|
||||
for (SysDict dictMain : sysDictList) {
|
||||
SysDictPage vo = new SysDictPage();
|
||||
BeanUtils.copyProperties(dictMain, vo);
|
||||
// 查询机票
|
||||
List<SysDictItem> sysDictItemList = sysDictItemService.selectItemsByMainId(dictMain.getId());
|
||||
vo.setSysDictItemList(sysDictItemList);
|
||||
pageList.add(vo);
|
||||
}
|
||||
|
||||
// 导出文件名称
|
||||
mv.addObject(NormalExcelConstants.FILE_NAME, "数据字典");
|
||||
// 注解对象Class
|
||||
mv.addObject(NormalExcelConstants.CLASS, SysDictPage.class);
|
||||
// 自定义表格参数
|
||||
LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
||||
mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("数据字典列表", "导出人:"+user.getRealname(), "数据字典"));
|
||||
// 导出数据列表
|
||||
mv.addObject(NormalExcelConstants.DATA_LIST, pageList);
|
||||
return mv;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过excel导入数据
|
||||
*
|
||||
* @param request
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
@RequiresRoles({"admin"})
|
||||
@PostMapping(value = "/importExcel")
|
||||
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
|
||||
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
||||
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
|
||||
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
|
||||
MultipartFile file = entity.getValue();// 获取上传文件对象
|
||||
ImportParams params = new ImportParams();
|
||||
params.setTitleRows(2);
|
||||
params.setHeadRows(2);
|
||||
params.setNeedSave(true);
|
||||
try {
|
||||
//导入Excel格式校验,看匹配的字段文本概率
|
||||
Boolean t = ExcelImportCheckUtil.check(file.getInputStream(), SysDictPage.class, params);
|
||||
if(!t){
|
||||
throw new RuntimeException("导入Excel校验失败 !");
|
||||
}
|
||||
List<SysDictPage> list = ExcelImportUtil.importExcel(file.getInputStream(), SysDictPage.class, params);
|
||||
// 错误信息
|
||||
List<String> errorMessage = new ArrayList<>();
|
||||
int successLines = 0, errorLines = 0;
|
||||
for (int i=0;i< list.size();i++) {
|
||||
SysDict po = new SysDict();
|
||||
BeanUtils.copyProperties(list.get(i), po);
|
||||
po.setDelFlag(CommonConstant.DEL_FLAG_0);
|
||||
try {
|
||||
Integer integer = sysDictService.saveMain(po, list.get(i).getSysDictItemList());
|
||||
if(integer>0){
|
||||
successLines++;
|
||||
}else{
|
||||
errorLines++;
|
||||
int lineNumber = i + 1;
|
||||
errorMessage.add("第 " + lineNumber + " 行:字典编码已经存在,忽略导入。");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
errorLines++;
|
||||
int lineNumber = i + 1;
|
||||
errorMessage.add("第 " + lineNumber + " 行:字典编码已经存在,忽略导入。");
|
||||
}
|
||||
}
|
||||
return ImportExcelUtil.imporReturnRes(errorLines,successLines,errorMessage);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(),e);
|
||||
return Result.error("文件导入失败:"+e.getMessage());
|
||||
} finally {
|
||||
try {
|
||||
file.getInputStream().close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return Result.error("文件导入失败!");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 查询选项内容
|
||||
*
|
||||
*/
|
||||
@GetMapping(value = "/queryDictName")
|
||||
public Result<List<SysDict>> queryDictName(@RequestParam(name = "cut") String cut,SysDict sysDict) {
|
||||
List<SysDict> list =sysDictService.queryDictName(cut,sysDict);
|
||||
return Result.OK(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 物理删除
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@DeleteMapping(value = "/deletePhysic/{id}")
|
||||
public Result<?> deletePhysic(@PathVariable String id) {
|
||||
try {
|
||||
sysDictService.deleteOneDictPhysically(id);
|
||||
return Result.OK("删除成功!");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return Result.error("删除失败!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 取回
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@PutMapping(value = "/back/{id}")
|
||||
public Result<?> back(@PathVariable String id) {
|
||||
try {
|
||||
sysDictService.updateDictDelFlag(0,id);
|
||||
return Result.OK("操作成功!");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return Result.error("操作失败!");
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation(value = "查询出当前用户可配置品牌")
|
||||
@GetMapping(value = "/getBrandDict")
|
||||
public Result<List<DictModel>> getBrandDict() {
|
||||
List<DictModel> dictModels = sysDictService.queryDictItemsByCode(DictCodeEnum.BRAND.getValue());
|
||||
if (!sysUserService.isAdministrator()) {
|
||||
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
||||
List<String> brands = projectUserBrandService.queryBrandByUserId(sysUser.getId());
|
||||
dictModels = dictModels.stream().filter(dictModel -> brands.contains(dictModel.getValue())).collect(Collectors.toList());
|
||||
}
|
||||
return Result.OK(dictModels);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取责任领域字典数据
|
||||
* @param dictCode 字典code
|
||||
* @param dictCode 表名,文本字段,code字段 | 举例:sys_user,realname,id
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "字典控制器-获取责任领域字典数据", notes = "字典控制器-获取责任领域字典数据")
|
||||
@RequestMapping(value = "/getDutyTerritoryDictItems/{dictCode}", method = RequestMethod.GET)
|
||||
public Result<List<DictModel>> getDutyTerritoryDictItems(@PathVariable String dictCode, @RequestParam(value = "sign",required = false) String sign, HttpServletRequest request) {
|
||||
log.info(" dictCode : "+ dictCode);
|
||||
Result<List<DictModel>> result = new Result<List<DictModel>>();
|
||||
List<DictModel> ls = null;
|
||||
try {
|
||||
if(dictCode.indexOf(",")!=-1) {
|
||||
//关联表字典(举例:sys_user,realname,id)
|
||||
String[] params = dictCode.split(",");
|
||||
|
||||
if(params.length<3) {
|
||||
result.error500("字典Code格式不正确!");
|
||||
return result;
|
||||
}
|
||||
//SQL注入校验(只限制非法串改数据库)
|
||||
final String[] sqlInjCheck = {params[0],params[1],params[2]};
|
||||
SqlInjectionUtil.filterContent(sqlInjCheck);
|
||||
|
||||
if(params.length==4) {
|
||||
//SQL注入校验(查询条件SQL 特殊check,此方法仅供此处使用)
|
||||
SqlInjectionUtil.specialFilterContent(params[3]);
|
||||
ls = sysDictService.queryTableDictItemsByCodeAndFilter(params[0],params[1],params[2],params[3]);
|
||||
}else if (params.length==3) {
|
||||
ls = sysDictService.queryTableDictItemsByCode(params[0],params[1],params[2]);
|
||||
}else{
|
||||
result.error500("字典Code格式不正确!");
|
||||
return result;
|
||||
}
|
||||
}else {
|
||||
//字典表
|
||||
ls = sysDictService.queryDictItemsByCode(dictCode);
|
||||
}
|
||||
|
||||
// 将结果集进行排序
|
||||
if (CollectionUtils.isNotEmpty(ls)) {
|
||||
// 匿名比较器排序
|
||||
Collections.sort(ls, new Comparator<DictModel>() {
|
||||
@Override
|
||||
public int compare(DictModel p1, DictModel p2) {
|
||||
return p1.getText().compareTo(p2.getText());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
result.setSuccess(true);
|
||||
result.setResult(ls);
|
||||
log.debug(result.toString());
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(),e);
|
||||
result.error500("操作失败");
|
||||
return result;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
+865
@@ -0,0 +1,865 @@
|
||||
package com.jero.modules.system.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.jero.common.api.vo.Result;
|
||||
import com.jero.common.constant.CommonConstant;
|
||||
import com.jero.common.constant.enums.CutEnum;
|
||||
import com.jero.common.system.vo.LoginUser;
|
||||
import com.jero.common.util.MD5Util;
|
||||
import com.jero.common.util.oConvertUtils;
|
||||
import com.jero.modules.system.entity.SysDepartPermission;
|
||||
import com.jero.modules.system.entity.SysPermission;
|
||||
import com.jero.modules.system.entity.SysPermissionDataRule;
|
||||
import com.jero.modules.system.entity.SysRolePermission;
|
||||
import com.jero.modules.system.enums.SysPermissionEnum;
|
||||
import com.jero.modules.system.mapper.TodoCenterMapper;
|
||||
import com.jero.modules.system.model.SysPermissionTree;
|
||||
import com.jero.modules.system.model.TreeModel;
|
||||
import com.jero.modules.system.service.ISysDepartPermissionService;
|
||||
import com.jero.modules.system.service.ISysPermissionDataRuleService;
|
||||
import com.jero.modules.system.service.ISysPermissionService;
|
||||
import com.jero.modules.system.service.ISysRolePermissionService;
|
||||
import com.jero.modules.system.util.PermissionDataUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 菜单权限表 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @Author scott
|
||||
* @since 2018-12-21
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/phone/sys/permission")
|
||||
public class PhoneSysPermissionController {
|
||||
|
||||
@Autowired
|
||||
private ISysPermissionService sysPermissionService;
|
||||
|
||||
@Autowired
|
||||
private ISysRolePermissionService sysRolePermissionService;
|
||||
|
||||
@Autowired
|
||||
private ISysPermissionDataRuleService sysPermissionDataRuleService;
|
||||
|
||||
@Autowired
|
||||
private ISysDepartPermissionService sysDepartPermissionService;
|
||||
|
||||
@Autowired
|
||||
private TodoCenterMapper todoCenterMapper;
|
||||
|
||||
/**
|
||||
* 加载数据节点
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/page", method = RequestMethod.GET)
|
||||
public Result<List<SysPermissionTree>> list() {
|
||||
long start = System.currentTimeMillis();
|
||||
Result<List<SysPermissionTree>> result = new Result<>();
|
||||
try {
|
||||
LambdaQueryWrapper<SysPermission> query = new LambdaQueryWrapper<SysPermission>();
|
||||
query.eq(SysPermission::getDelFlag, CommonConstant.DEL_FLAG_0);
|
||||
query.orderByAsc(SysPermission::getSortNo);
|
||||
List<SysPermission> list = sysPermissionService.list(query);
|
||||
List<SysPermissionTree> treeList = new ArrayList<>();
|
||||
getTreeList(treeList, list, null);
|
||||
result.setResult(treeList);
|
||||
result.setSuccess(true);
|
||||
log.info("======获取全部菜单数据=====耗时:" + (System.currentTimeMillis() - start) + "毫秒");
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/*update_begin author:wuxianquan date:20190908 for:先查询一级菜单,当用户点击展开菜单时加载子菜单 */
|
||||
/**
|
||||
* 系统菜单列表(一级菜单)
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/getSystemMenuList", method = RequestMethod.GET)
|
||||
public Result<List<SysPermissionTree>> getSystemMenuList() {
|
||||
long start = System.currentTimeMillis();
|
||||
Result<List<SysPermissionTree>> result = new Result<>();
|
||||
try {
|
||||
LambdaQueryWrapper<SysPermission> query = new LambdaQueryWrapper<SysPermission>();
|
||||
query.eq(SysPermission::getMenuType,CommonConstant.MENU_TYPE_0);
|
||||
query.eq(SysPermission::getDelFlag, CommonConstant.DEL_FLAG_0);
|
||||
query.orderByAsc(SysPermission::getSortNo);
|
||||
List<SysPermission> list = sysPermissionService.list(query);
|
||||
List<SysPermissionTree> sysPermissionTreeList = new ArrayList<SysPermissionTree>();
|
||||
for(SysPermission sysPermission : list){
|
||||
SysPermissionTree sysPermissionTree = new SysPermissionTree(sysPermission);
|
||||
sysPermissionTreeList.add(sysPermissionTree);
|
||||
}
|
||||
result.setResult(sysPermissionTreeList);
|
||||
result.setSuccess(true);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
log.info("======获取一级菜单数据=====耗时:" + (System.currentTimeMillis() - start) + "毫秒");
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询子菜单
|
||||
* @param parentId
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/getSystemSubmenu", method = RequestMethod.GET)
|
||||
public Result<List<SysPermissionTree>> getSystemSubmenu(@RequestParam("parentId") String parentId){
|
||||
Result<List<SysPermissionTree>> result = new Result<>();
|
||||
try{
|
||||
LambdaQueryWrapper<SysPermission> query = new LambdaQueryWrapper<SysPermission>();
|
||||
query.eq(SysPermission::getParentId,parentId);
|
||||
query.eq(SysPermission::getDelFlag, CommonConstant.DEL_FLAG_0);
|
||||
query.orderByAsc(SysPermission::getSortNo);
|
||||
List<SysPermission> list = sysPermissionService.list(query);
|
||||
List<SysPermissionTree> sysPermissionTreeList = new ArrayList<SysPermissionTree>();
|
||||
for(SysPermission sysPermission : list){
|
||||
SysPermissionTree sysPermissionTree = new SysPermissionTree(sysPermission);
|
||||
sysPermissionTreeList.add(sysPermissionTree);
|
||||
}
|
||||
result.setResult(sysPermissionTreeList);
|
||||
result.setSuccess(true);
|
||||
}catch (Exception e){
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/*update_end author:wuxianquan date:20190908 for:先查询一级菜单,当用户点击展开菜单时加载子菜单 */
|
||||
|
||||
// update_begin author:sunjianlei date:20200108 for: 新增批量根据父ID查询子级菜单的接口 -------------
|
||||
/**
|
||||
* 查询子菜单
|
||||
*
|
||||
* @param parentIds 父ID(多个采用半角逗号分割)
|
||||
* @return 返回 key-value 的 Map
|
||||
*/
|
||||
@GetMapping("/getSystemSubmenuBatch")
|
||||
public Result getSystemSubmenuBatch(@RequestParam("parentIds") String parentIds) {
|
||||
try {
|
||||
LambdaQueryWrapper<SysPermission> query = new LambdaQueryWrapper<>();
|
||||
List<String> parentIdList = Arrays.asList(parentIds.split(","));
|
||||
query.in(SysPermission::getParentId, parentIdList);
|
||||
query.eq(SysPermission::getDelFlag, CommonConstant.DEL_FLAG_0);
|
||||
query.orderByAsc(SysPermission::getSortNo);
|
||||
List<SysPermission> list = sysPermissionService.list(query);
|
||||
Map<String, List<SysPermissionTree>> listMap = new HashMap<>();
|
||||
for (SysPermission item : list) {
|
||||
String pid = item.getParentId();
|
||||
if (parentIdList.contains(pid)) {
|
||||
List<SysPermissionTree> mapList = listMap.get(pid);
|
||||
if (mapList == null) {
|
||||
mapList = new ArrayList<>();
|
||||
}
|
||||
mapList.add(new SysPermissionTree(item));
|
||||
listMap.put(pid, mapList);
|
||||
}
|
||||
}
|
||||
return Result.OK(listMap);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
return Result.error("批量查询子菜单失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
// update_end author:sunjianlei date:20200108 for: 新增批量根据父ID查询子级菜单的接口 -------------
|
||||
|
||||
// /**
|
||||
// * 查询用户拥有的菜单权限和按钮权限(根据用户账号)
|
||||
// *
|
||||
// * @return
|
||||
// */
|
||||
// @RequestMapping(value = "/queryByUser", method = RequestMethod.GET)
|
||||
// public Result<JSONArray> queryByUser(HttpServletRequest req) {
|
||||
// Result<JSONArray> result = new Result<>();
|
||||
// try {
|
||||
// String username = req.getParameter("username");
|
||||
// List<SysPermission> metaList = sysPermissionService.queryByUser(username);
|
||||
// JSONArray jsonArray = new JSONArray();
|
||||
// this.getPermissionJsonArray(jsonArray, metaList, null);
|
||||
// result.setResult(jsonArray);
|
||||
// result.success("查询成功");
|
||||
// } catch (Exception e) {
|
||||
// result.error500("查询失败:" + e.getMessage());
|
||||
// log.error(e.getMessage(), e);
|
||||
// }
|
||||
// return result;
|
||||
// }
|
||||
|
||||
/**
|
||||
* 查询用户拥有的菜单权限和按钮权限
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/getUserPermissionByToken", method = RequestMethod.GET)
|
||||
public Result<?> getUserPermissionByToken(String cut) {
|
||||
Result<JSONObject> result = new Result<JSONObject>();
|
||||
try {
|
||||
//直接获取当前用户不适用前端token
|
||||
LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
||||
if (oConvertUtils.isEmpty(loginUser)) {
|
||||
return Result.error("请登录系统!");
|
||||
}
|
||||
List<SysPermission> metaList = sysPermissionService.queryByUser(loginUser.getUsername());
|
||||
//添加首页路由
|
||||
//update-begin-author:taoyan date:20200211 for: TASK #3368 【路由缓存】首页的缓存设置有问题,需要根据后台的路由配置来实现是否缓存
|
||||
if(!PermissionDataUtil.hasIndexPage(metaList)){
|
||||
SysPermission indexMenu = sysPermissionService.list(new LambdaQueryWrapper<SysPermission>().eq(SysPermission::getName,"首页")).get(0);
|
||||
metaList.add(0,indexMenu);
|
||||
}
|
||||
//update-end-author:taoyan date:20200211 for: TASK #3368 【路由缓存】首页的缓存设置有问题,需要根据后台的路由配置来实现是否缓存
|
||||
JSONObject json = new JSONObject();
|
||||
JSONArray menujsonArray = new JSONArray();
|
||||
this.getPermissionJsonArray(menujsonArray, metaList, null,cut);
|
||||
JSONArray authjsonArray = new JSONArray();
|
||||
this.getAuthJsonArray(authjsonArray, metaList);
|
||||
//查询所有的权限
|
||||
LambdaQueryWrapper<SysPermission> query = new LambdaQueryWrapper<SysPermission>();
|
||||
query.eq(SysPermission::getDelFlag, CommonConstant.DEL_FLAG_0);
|
||||
query.eq(SysPermission::getMenuType, CommonConstant.MENU_TYPE_2);
|
||||
//query.eq(SysPermission::getStatus, "1");
|
||||
List<SysPermission> allAuthList = sysPermissionService.list(query);
|
||||
JSONArray allauthjsonArray = new JSONArray();
|
||||
this.getAllAuthJsonArray(allauthjsonArray, allAuthList);
|
||||
//路由菜单
|
||||
json.put("menu", menujsonArray);
|
||||
//按钮权限(用户拥有的权限集合)
|
||||
json.put("auth", authjsonArray);
|
||||
//全部权限配置集合(按钮权限,访问权限)
|
||||
json.put("allAuth", allauthjsonArray);
|
||||
result.setResult(json);
|
||||
result.success("查询成功");
|
||||
} catch (Exception e) {
|
||||
result.error500("查询失败:" + e.getMessage());
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加菜单
|
||||
* @param permission
|
||||
* @return
|
||||
*/
|
||||
//@RequiresRoles({ "admin" })
|
||||
@RequestMapping(value = "/add", method = RequestMethod.POST)
|
||||
public Result<SysPermission> add(@RequestBody SysPermission permission) {
|
||||
Result<SysPermission> result = new Result<SysPermission>();
|
||||
try {
|
||||
permission = PermissionDataUtil.intelligentProcessData(permission);
|
||||
sysPermissionService.addPermission(permission);
|
||||
result.success("添加成功!");
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
result.error500("操作失败");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑菜单
|
||||
* @param permission
|
||||
* @return
|
||||
*/
|
||||
//@RequiresRoles({ "admin" })
|
||||
@RequestMapping(value = "/edit", method = { RequestMethod.PUT, RequestMethod.POST })
|
||||
public Result<SysPermission> edit(@RequestBody SysPermission permission) {
|
||||
Result<SysPermission> result = new Result<>();
|
||||
try {
|
||||
permission = PermissionDataUtil.intelligentProcessData(permission);
|
||||
sysPermissionService.editPermission(permission);
|
||||
result.success("修改成功!");
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
result.error500("操作失败");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除菜单
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
//@RequiresRoles({ "admin" })
|
||||
@RequestMapping(value = "/delete", method = RequestMethod.DELETE)
|
||||
public Result<SysPermission> delete(@RequestParam(name = "id", required = true) String id) {
|
||||
Result<SysPermission> result = new Result<>();
|
||||
try {
|
||||
sysPermissionService.deletePermission(id);
|
||||
result.success("删除成功!");
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
result.error500(e.getMessage());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除菜单
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
//@RequiresRoles({ "admin" })
|
||||
@RequestMapping(value = "/deleteBatch", method = RequestMethod.DELETE)
|
||||
public Result<SysPermission> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
|
||||
Result<SysPermission> result = new Result<>();
|
||||
try {
|
||||
String[] arr = ids.split(",");
|
||||
for (String id : arr) {
|
||||
if (oConvertUtils.isNotEmpty(id)) {
|
||||
sysPermissionService.deletePermission(id);
|
||||
}
|
||||
}
|
||||
result.success("删除成功!");
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
result.error500("删除成功!");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取全部的权限树
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/queryTreeList", method = RequestMethod.GET)
|
||||
public Result<Map<String, Object>> queryTreeList() {
|
||||
Result<Map<String, Object>> result = new Result<>();
|
||||
// 全部权限ids
|
||||
List<String> ids = new ArrayList<>();
|
||||
try {
|
||||
LambdaQueryWrapper<SysPermission> query = new LambdaQueryWrapper<SysPermission>();
|
||||
query.eq(SysPermission::getDelFlag, CommonConstant.DEL_FLAG_0);
|
||||
query.orderByAsc(SysPermission::getSortNo);
|
||||
List<SysPermission> list = sysPermissionService.list(query);
|
||||
for (SysPermission sysPer : list) {
|
||||
ids.add(sysPer.getId());
|
||||
}
|
||||
List<TreeModel> treeList = new ArrayList<>();
|
||||
getTreeModelList(treeList, list, null);
|
||||
|
||||
Map<String, Object> resMap = new HashMap<String, Object>();
|
||||
resMap.put("treeList", treeList); // 全部树节点数据
|
||||
resMap.put("ids", ids);// 全部树ids
|
||||
result.setResult(resMap);
|
||||
result.setSuccess(true);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 异步加载数据节点
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/queryListAsync", method = RequestMethod.GET)
|
||||
public Result<List<TreeModel>> queryAsync(@RequestParam(name = "pid", required = false) String parentId) {
|
||||
Result<List<TreeModel>> result = new Result<>();
|
||||
try {
|
||||
List<TreeModel> list = sysPermissionService.queryListByParentId(parentId);
|
||||
if (list == null || list.size() <= 0) {
|
||||
result.error500("未找到角色信息");
|
||||
} else {
|
||||
result.setResult(list);
|
||||
result.setSuccess(true);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询角色授权
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@RequiresPermissions("sys:role:auth")
|
||||
@RequestMapping(value = "/queryRolePermission", method = RequestMethod.GET)
|
||||
public Result<List<String>> queryRolePermission(@RequestParam(name = "roleId", required = true) String roleId) {
|
||||
Result<List<String>> result = new Result<>();
|
||||
try {
|
||||
List<SysRolePermission> list = sysRolePermissionService.list(new QueryWrapper<SysRolePermission>().lambda().eq(SysRolePermission::getRoleId, roleId));
|
||||
result.setResult(list.stream().map(SysRolePermission -> String.valueOf(SysRolePermission.getPermissionId())).collect(Collectors.toList()));
|
||||
result.setSuccess(true);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存角色授权
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@RequiresPermissions("sys:role:auth")
|
||||
@RequestMapping(value = "/saveRolePermission", method = RequestMethod.POST)
|
||||
//@RequiresRoles({ "admin" })
|
||||
public Result<String> saveRolePermission(@RequestBody JSONObject json) {
|
||||
long start = System.currentTimeMillis();
|
||||
Result<String> result = new Result<>();
|
||||
try {
|
||||
String roleId = json.getString("roleId");
|
||||
String permissionIds = json.getString("permissionIds");
|
||||
String lastPermissionIds = json.getString("lastpermissionIds");
|
||||
this.sysRolePermissionService.saveRolePermission(roleId, permissionIds, lastPermissionIds);
|
||||
result.success("保存成功!");
|
||||
log.info("======角色授权成功=====耗时:" + (System.currentTimeMillis() - start) + "毫秒");
|
||||
} catch (Exception e) {
|
||||
result.error500("授权失败!");
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void getTreeList(List<SysPermissionTree> treeList, List<SysPermission> metaList, SysPermissionTree temp) {
|
||||
for (SysPermission permission : metaList) {
|
||||
String tempPid = permission.getParentId();
|
||||
SysPermissionTree tree = new SysPermissionTree(permission);
|
||||
if (temp == null && oConvertUtils.isEmpty(tempPid)) {
|
||||
treeList.add(tree);
|
||||
if (!tree.getIsLeaf()) {
|
||||
getTreeList(treeList, metaList, tree);
|
||||
}
|
||||
} else if (temp != null && tempPid != null && tempPid.equals(temp.getId())) {
|
||||
temp.getChildren().add(tree);
|
||||
if (!tree.getIsLeaf()) {
|
||||
getTreeList(treeList, metaList, tree);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void getTreeModelList(List<TreeModel> treeList, List<SysPermission> metaList, TreeModel temp) {
|
||||
for (SysPermission permission : metaList) {
|
||||
String tempPid = permission.getParentId();
|
||||
TreeModel tree = new TreeModel(permission);
|
||||
if (temp == null && oConvertUtils.isEmpty(tempPid)) {
|
||||
treeList.add(tree);
|
||||
if (!tree.getIsLeaf()) {
|
||||
getTreeModelList(treeList, metaList, tree);
|
||||
}
|
||||
} else if (temp != null && tempPid != null && tempPid.equals(temp.getKey())) {
|
||||
temp.getChildren().add(tree);
|
||||
if (!tree.getIsLeaf()) {
|
||||
getTreeModelList(treeList, metaList, tree);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取权限JSON数组
|
||||
* @param jsonArray
|
||||
* @param allList
|
||||
*/
|
||||
private void getAllAuthJsonArray(JSONArray jsonArray,List<SysPermission> allList) {
|
||||
JSONObject json = null;
|
||||
for (SysPermission permission : allList) {
|
||||
json = new JSONObject();
|
||||
json.put("action", permission.getPerms());
|
||||
json.put("status", permission.getStatus());
|
||||
//1显示2禁用
|
||||
json.put("type", permission.getPermsType());
|
||||
json.put("describe", permission.getName());
|
||||
jsonArray.add(json);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取权限JSON数组
|
||||
* @param jsonArray
|
||||
* @param metaList
|
||||
*/
|
||||
private void getAuthJsonArray(JSONArray jsonArray,List<SysPermission> metaList) {
|
||||
for (SysPermission permission : metaList) {
|
||||
if(permission.getMenuType()==null) {
|
||||
continue;
|
||||
}
|
||||
JSONObject json = null;
|
||||
if(permission.getMenuType().equals(CommonConstant.MENU_TYPE_2) &&CommonConstant.STATUS_1.equals(permission.getStatus())) {
|
||||
json = new JSONObject();
|
||||
json.put("action", permission.getPerms());
|
||||
json.put("type", permission.getPermsType());
|
||||
json.put("describe", permission.getName());
|
||||
jsonArray.add(json);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 获取菜单JSON数组
|
||||
* @param jsonArray
|
||||
* @param metaList
|
||||
* @param parentJson
|
||||
*/
|
||||
private void getPermissionJsonArray(JSONArray jsonArray, List<SysPermission> metaList, JSONObject parentJson,String cut) {
|
||||
for (SysPermission permission : metaList) {
|
||||
if (permission.getMenuType() == null) {
|
||||
continue;
|
||||
}
|
||||
String tempPid = permission.getParentId();
|
||||
JSONObject json = getPermissionJsonObject(permission,cut);
|
||||
if(json==null) {
|
||||
continue;
|
||||
}
|
||||
if (parentJson == null && oConvertUtils.isEmpty(tempPid)) {
|
||||
jsonArray.add(json);
|
||||
if (!permission.isLeaf()) {
|
||||
getPermissionJsonArray(jsonArray, metaList, json,cut);
|
||||
}
|
||||
} else if (parentJson != null && oConvertUtils.isNotEmpty(tempPid) && tempPid.equals(parentJson.getString("id"))) {
|
||||
// 类型( 0:一级菜单 1:子菜单 2:按钮 )
|
||||
if (permission.getMenuType().equals(CommonConstant.MENU_TYPE_2)) {
|
||||
JSONObject metaJson = parentJson.getJSONObject("meta");
|
||||
if (metaJson.containsKey("permissionList")) {
|
||||
metaJson.getJSONArray("permissionList").add(json);
|
||||
} else {
|
||||
JSONArray permissionList = new JSONArray();
|
||||
permissionList.add(json);
|
||||
metaJson.put("permissionList", permissionList);
|
||||
}
|
||||
// 类型( 0:一级菜单 1:子菜单 2:按钮 )
|
||||
} else if (permission.getMenuType().equals(CommonConstant.MENU_TYPE_1) || permission.getMenuType().equals(CommonConstant.MENU_TYPE_0)) {
|
||||
if (parentJson.containsKey("children")) {
|
||||
parentJson.getJSONArray("children").add(json);
|
||||
} else {
|
||||
JSONArray children = new JSONArray();
|
||||
children.add(json);
|
||||
parentJson.put("children", children);
|
||||
}
|
||||
|
||||
if (!permission.isLeaf()) {
|
||||
getPermissionJsonArray(jsonArray, metaList, json,cut);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据菜单配置生成路由json
|
||||
* @param permission
|
||||
* @return
|
||||
*/
|
||||
private JSONObject getPermissionJsonObject(SysPermission permission,String cut) {
|
||||
JSONObject json = new JSONObject();
|
||||
// 类型(0:一级菜单 1:子菜单 2:按钮)
|
||||
if (permission.getMenuType().equals(CommonConstant.MENU_TYPE_2)) {
|
||||
//json.put("action", permission.getPerms());
|
||||
//json.put("type", permission.getPermsType());
|
||||
//json.put("describe", permission.getName());
|
||||
return null;
|
||||
} else if (permission.getMenuType().equals(CommonConstant.MENU_TYPE_0) || permission.getMenuType().equals(CommonConstant.MENU_TYPE_1)) {
|
||||
json.put("id", permission.getId());
|
||||
if (permission.isRoute()) {
|
||||
json.put("route", "1");// 表示生成路由
|
||||
} else {
|
||||
json.put("route", "0");// 表示不生成路由
|
||||
}
|
||||
|
||||
if (isWWWHttpUrl(permission.getUrl())) {
|
||||
json.put("path", MD5Util.MD5Encode(permission.getUrl(), "utf-8"));
|
||||
} else {
|
||||
json.put("path", permission.getUrl());
|
||||
}
|
||||
|
||||
// 重要规则:路由name (通过URL生成路由name,路由name供前端开发,页面跳转使用)
|
||||
if (oConvertUtils.isNotEmpty(permission.getComponentName())) {
|
||||
json.put("name", permission.getComponentName());
|
||||
} else {
|
||||
json.put("name", urlToRouteName(permission.getUrl()));
|
||||
}
|
||||
|
||||
// 是否隐藏路由,默认都是显示的
|
||||
if (permission.isHidden()) {
|
||||
json.put("hidden", true);
|
||||
}
|
||||
// 聚合路由
|
||||
if (permission.isAlwaysShow()) {
|
||||
json.put("alwaysShow", true);
|
||||
}
|
||||
json.put("component", permission.getComponent());
|
||||
JSONObject meta = new JSONObject();
|
||||
// 由用户设置是否缓存页面 用布尔值
|
||||
if (permission.isKeepAlive()) {
|
||||
meta.put("keepAlive", true);
|
||||
} else {
|
||||
meta.put("keepAlive", false);
|
||||
}
|
||||
|
||||
/*update_begin author:wuxianquan date:20190908 for:往菜单信息里添加外链菜单打开方式 */
|
||||
//外链菜单打开方式
|
||||
if (permission.isInternalOrExternal()) {
|
||||
meta.put("internalOrExternal", true);
|
||||
} else {
|
||||
meta.put("internalOrExternal", false);
|
||||
}
|
||||
/* update_end author:wuxianquan date:20190908 for: 往菜单信息里添加外链菜单打开方式*/
|
||||
|
||||
if(CutEnum.EN.getValue().equals(cut)){
|
||||
meta.put("title", permission.getMenuEn());
|
||||
}else{
|
||||
meta.put("title", permission.getName());
|
||||
}
|
||||
|
||||
//update-begin--Author:scott Date:20201015 for:路由缓存问题,关闭了tab页时再打开就不刷新 #842
|
||||
String component = permission.getComponent();
|
||||
if(oConvertUtils.isNotEmpty(permission.getComponentName()) || oConvertUtils.isNotEmpty(component)){
|
||||
meta.put("componentName", oConvertUtils.getString(permission.getComponentName(),component.substring(component.lastIndexOf("/")+1)));
|
||||
}
|
||||
//update-end--Author:scott Date:20201015 for:路由缓存问题,关闭了tab页时再打开就不刷新 #842
|
||||
|
||||
if (oConvertUtils.isEmpty(permission.getParentId())) {
|
||||
// 一级菜单跳转地址
|
||||
json.put("redirect", permission.getRedirect());
|
||||
if (oConvertUtils.isNotEmpty(permission.getIcon())) {
|
||||
meta.put("icon", permission.getIcon());
|
||||
}
|
||||
} else {
|
||||
if (oConvertUtils.isNotEmpty(permission.getIcon())) {
|
||||
meta.put("icon", permission.getIcon());
|
||||
}
|
||||
}
|
||||
if (isWWWHttpUrl(permission.getUrl())) {
|
||||
meta.put("url", permission.getUrl());
|
||||
}
|
||||
|
||||
LoginUser currentUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
||||
|
||||
Map<String,Object> params = new HashMap<>();
|
||||
params.put("currentUserId",currentUser.getId());
|
||||
|
||||
List<String> flowTypeList = new ArrayList<>();
|
||||
//项目法规任务
|
||||
if(StringUtils.equals(permission.getId(), SysPermissionEnum.PROJECT_REGULATION_TASKS.getId())){
|
||||
flowTypeList.add("1");
|
||||
flowTypeList.add("2");
|
||||
flowTypeList.add("3");
|
||||
flowTypeList.add("4");
|
||||
flowTypeList.add("10");
|
||||
flowTypeList.add("21");
|
||||
params.put("flowTypeList",flowTypeList);
|
||||
//存在待办任务标识,true为有
|
||||
boolean existTaskFlag = false;
|
||||
int result = todoCenterMapper.todoCenterTaskCount(params);
|
||||
if(result > 0){
|
||||
existTaskFlag = true;
|
||||
}
|
||||
//查询当前登录用户是否有项目法规任务
|
||||
meta.put("existTask",existTaskFlag);
|
||||
}
|
||||
//法规评估任务
|
||||
if(StringUtils.equals(permission.getId(), SysPermissionEnum.REGULATORY_ASSESSMENT_TASKS.getId())){
|
||||
flowTypeList.add("5");
|
||||
flowTypeList.add("6");
|
||||
params.put("flowTypeList",flowTypeList);
|
||||
int result = todoCenterMapper.todoCenterTaskCount(params);
|
||||
boolean existTaskFlag = false;
|
||||
if(result > 0){
|
||||
existTaskFlag = true;
|
||||
}
|
||||
meta.put("existTask",existTaskFlag);
|
||||
}
|
||||
//项目参数任务
|
||||
if(StringUtils.equals(permission.getId(), SysPermissionEnum.PROJECT_PARAMETER_TASKS.getId())){
|
||||
boolean existTaskFlag = false;
|
||||
existTaskFlag = sysPermissionService.judgeToDo();
|
||||
meta.put("existTask",existTaskFlag);
|
||||
}
|
||||
json.put("meta", meta);
|
||||
}
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否外网URL 例如: http://localhost:8080/jero-boot/swagger-ui.html#/ 支持特殊格式: {{
|
||||
* window._CONFIG['domianURL'] }}/druid/ {{ JS代码片段 }},前台解析会自动执行JS代码片段
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private boolean isWWWHttpUrl(String url) {
|
||||
if (url != null && (url.startsWith("http://") || url.startsWith("https://") || url.startsWith("{{"))) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过URL生成路由name(去掉URL前缀斜杠,替换内容中的斜杠‘/’为-) 举例: URL = /isystem/role RouteName =
|
||||
* isystem-role
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private String urlToRouteName(String url) {
|
||||
if (oConvertUtils.isNotEmpty(url)) {
|
||||
if (url.startsWith("/")) {
|
||||
url = url.substring(1);
|
||||
}
|
||||
url = url.replace("/", "-");
|
||||
|
||||
// 特殊标记
|
||||
url = url.replace(":", "@");
|
||||
return url;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据菜单id来获取其对应的权限数据
|
||||
*
|
||||
* @param sysPermissionDataRule
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/getPermRuleListByPermId", method = RequestMethod.GET)
|
||||
public Result<List<SysPermissionDataRule>> getPermRuleListByPermId(SysPermissionDataRule sysPermissionDataRule) {
|
||||
List<SysPermissionDataRule> permRuleList = sysPermissionDataRuleService.getPermRuleListByPermId(sysPermissionDataRule.getPermissionId());
|
||||
Result<List<SysPermissionDataRule>> result = new Result<>();
|
||||
result.setSuccess(true);
|
||||
result.setResult(permRuleList);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加菜单权限数据
|
||||
*
|
||||
* @param sysPermissionDataRule
|
||||
* @return
|
||||
*/
|
||||
//@RequiresRoles({ "admin" })
|
||||
@RequestMapping(value = "/addPermissionRule", method = RequestMethod.POST)
|
||||
public Result<SysPermissionDataRule> addPermissionRule(@RequestBody SysPermissionDataRule sysPermissionDataRule) {
|
||||
Result<SysPermissionDataRule> result = new Result<SysPermissionDataRule>();
|
||||
try {
|
||||
sysPermissionDataRule.setCreateTime(new Date());
|
||||
sysPermissionDataRuleService.savePermissionDataRule(sysPermissionDataRule);
|
||||
result.success("添加成功!");
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
result.error500("操作失败");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//@RequiresRoles({ "admin" })
|
||||
@RequestMapping(value = "/editPermissionRule", method = { RequestMethod.PUT, RequestMethod.POST })
|
||||
public Result<SysPermissionDataRule> editPermissionRule(@RequestBody SysPermissionDataRule sysPermissionDataRule) {
|
||||
Result<SysPermissionDataRule> result = new Result<SysPermissionDataRule>();
|
||||
try {
|
||||
sysPermissionDataRuleService.saveOrUpdate(sysPermissionDataRule);
|
||||
result.success("更新成功!");
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
result.error500("操作失败");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除菜单权限数据
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
//@RequiresRoles({ "admin" })
|
||||
@RequestMapping(value = "/deletePermissionRule", method = RequestMethod.DELETE)
|
||||
public Result<SysPermissionDataRule> deletePermissionRule(@RequestParam(name = "id", required = true) String id) {
|
||||
Result<SysPermissionDataRule> result = new Result<SysPermissionDataRule>();
|
||||
try {
|
||||
sysPermissionDataRuleService.deletePermissionDataRule(id);
|
||||
result.success("删除成功!");
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
result.error500("操作失败");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询菜单权限数据
|
||||
*
|
||||
* @param sysPermissionDataRule
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/queryPermissionRule", method = RequestMethod.GET)
|
||||
public Result<List<SysPermissionDataRule>> queryPermissionRule(SysPermissionDataRule sysPermissionDataRule) {
|
||||
Result<List<SysPermissionDataRule>> result = new Result<>();
|
||||
try {
|
||||
List<SysPermissionDataRule> permRuleList = sysPermissionDataRuleService.queryPermissionRule(sysPermissionDataRule);
|
||||
result.setResult(permRuleList);
|
||||
result.success("查询成功!");
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
result.error500("操作失败");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 部门权限表
|
||||
* @param departId
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/queryDepartPermission", method = RequestMethod.GET)
|
||||
public Result<List<String>> queryDepartPermission(@RequestParam(name = "departId", required = true) String departId) {
|
||||
Result<List<String>> result = new Result<>();
|
||||
try {
|
||||
List<SysDepartPermission> list = sysDepartPermissionService.list(new QueryWrapper<SysDepartPermission>().lambda().eq(SysDepartPermission::getDepartId, departId));
|
||||
result.setResult(list.stream().map(SysDepartPermission -> String.valueOf(SysDepartPermission.getPermissionId())).collect(Collectors.toList()));
|
||||
result.setSuccess(true);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存部门授权
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/saveDepartPermission", method = RequestMethod.POST)
|
||||
//@RequiresRoles({ "admin" })
|
||||
public Result<String> saveDepartPermission(@RequestBody JSONObject json) {
|
||||
long start = System.currentTimeMillis();
|
||||
Result<String> result = new Result<>();
|
||||
try {
|
||||
String departId = json.getString("departId");
|
||||
String permissionIds = json.getString("permissionIds");
|
||||
String lastPermissionIds = json.getString("lastpermissionIds");
|
||||
this.sysDepartPermissionService.saveDepartPermission(departId, permissionIds, lastPermissionIds);
|
||||
result.success("保存成功!");
|
||||
log.info("======部门授权成功=====耗时:" + (System.currentTimeMillis() - start) + "毫秒");
|
||||
} catch (Exception e) {
|
||||
result.error500("授权失败!");
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user