mirror of
https://github.com/jeecgboot/JeecgBoot.git
synced 2025-12-26 16:26:41 +08:00
JeecgBoot 2.4 微服务正式版本发布,基于SpringBoot的低代码平台
This commit is contained in:
@ -5,6 +5,7 @@ import org.apache.catalina.Context;
|
||||
import org.apache.tomcat.util.scan.StandardJarScanner;
|
||||
import org.jeecg.common.util.oConvertUtils;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
|
||||
@ -26,8 +27,6 @@ public class JeecgSystemApplication extends SpringBootServletInitializer {
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws UnknownHostException {
|
||||
//System.setProperty("spring.devtools.restart.enabled", "true");
|
||||
|
||||
ConfigurableApplicationContext application = SpringApplication.run(JeecgSystemApplication.class, args);
|
||||
Environment env = application.getEnvironment();
|
||||
String ip = InetAddress.getLocalHost().getHostAddress();
|
||||
@ -37,8 +36,7 @@ public class JeecgSystemApplication extends SpringBootServletInitializer {
|
||||
"Application Jeecg-Boot is running! Access URLs:\n\t" +
|
||||
"Local: \t\thttp://localhost:" + port + path + "/\n\t" +
|
||||
"External: \thttp://" + ip + ":" + port + path + "/\n\t" +
|
||||
"Swagger-ui: \thttp://" + ip + ":" + port + path + "/swagger-ui.html\n\t" +
|
||||
"Doc文档: \thttp://" + ip + ":" + port + path + "/doc.html\n" +
|
||||
"Swagger文档: \thttp://" + ip + ":" + port + path + "/doc.html\n" +
|
||||
"----------------------------------------------------------");
|
||||
|
||||
}
|
||||
|
||||
@ -42,7 +42,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/cas/client")
|
||||
@RequestMapping("/sys/cas/client")
|
||||
public class CasClientController {
|
||||
|
||||
@Autowired
|
||||
|
||||
@ -0,0 +1,38 @@
|
||||
package org.jeecg.modules.init;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jeecg.common.constant.CacheConstant;
|
||||
import org.jeecg.modules.system.service.ISysGatewayRouteService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @desc: 启动程序,初始化路由配置
|
||||
* @author: flyme
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class SystemInitListener implements ApplicationListener<ApplicationReadyEvent>, Ordered {
|
||||
|
||||
|
||||
@Autowired
|
||||
private ISysGatewayRouteService sysGatewayRouteService;
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(ApplicationReadyEvent applicationReadyEvent) {
|
||||
|
||||
log.info(" 服务已启动,准备初始化路由配置 ###################");
|
||||
if (applicationReadyEvent.getApplicationContext().getDisplayName().indexOf("AnnotationConfigServletWebServerApplicationContext") > -1) {
|
||||
sysGatewayRouteService.addRoute2Redis(CacheConstant.GATEWAY_ROUTES);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@ -35,7 +35,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/message/sysMessage")
|
||||
@RequestMapping("/sys/message/sysMessage")
|
||||
public class SysMessageController extends JeecgController<SysMessage, ISysMessageService> {
|
||||
@Autowired
|
||||
private ISysMessageService sysMessageService;
|
||||
|
||||
@ -39,7 +39,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/message/sysMessageTemplate")
|
||||
@RequestMapping("/sys/message/sysMessageTemplate")
|
||||
public class SysMessageTemplateController extends JeecgController<SysMessageTemplate, ISysMessageTemplateService> {
|
||||
@Autowired
|
||||
private ISysMessageTemplateService sysMessageTemplateService;
|
||||
|
||||
@ -11,12 +11,12 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("webSocketApi")
|
||||
public class TestController {
|
||||
|
||||
@RequestMapping("/sys/socketTest")
|
||||
public class TestSocketController {
|
||||
|
||||
@Autowired
|
||||
private WebSocket webSocket;
|
||||
|
||||
|
||||
@PostMapping("/sendAll")
|
||||
public Result<String> sendAll(@RequestBody JSONObject jsonObject) {
|
||||
Result<String> result = new Result<String>();
|
||||
@ -44,5 +44,5 @@ public class TestController {
|
||||
result.setResult("单发");
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -22,7 +22,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/actuator/redis")
|
||||
@RequestMapping("/sys/actuator/redis")
|
||||
public class ActuatorRedisController {
|
||||
|
||||
@Autowired
|
||||
|
||||
@ -1,12 +0,0 @@
|
||||
package org.jeecg.modules.ngalain.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface NgAlainMapper extends BaseMapper {
|
||||
public List<Map<String,String>> getDictByTable(@Param("table") String table, @Param("key") String key, @Param("value") String value);
|
||||
|
||||
}
|
||||
@ -1,7 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="org.jeecg.modules.ngalain.mapper.NgAlainMapper">
|
||||
<select id="getDictByTable" parameterType="String" resultType="java.util.HashMap">
|
||||
select ${key} as "label",${value} as "value" from ${table}
|
||||
</select>
|
||||
</mapper>
|
||||
@ -2,11 +2,10 @@ package org.jeecg.modules.ngalain.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.jeecg.common.util.MD5Util;
|
||||
import org.jeecg.common.util.oConvertUtils;
|
||||
import org.jeecg.modules.ngalain.mapper.NgAlainMapper;
|
||||
import org.jeecg.modules.ngalain.service.NgAlainService;
|
||||
import org.jeecg.modules.system.entity.SysPermission;
|
||||
import org.jeecg.modules.system.mapper.SysDictMapper;
|
||||
import org.jeecg.modules.system.service.ISysPermissionService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -22,7 +21,7 @@ public class NgAlainServiceImpl implements NgAlainService {
|
||||
@Autowired
|
||||
private ISysPermissionService sysPermissionService;
|
||||
@Autowired
|
||||
private NgAlainMapper mapper;
|
||||
private SysDictMapper mapper;
|
||||
@Override
|
||||
public JSONArray getMenu(String id) throws Exception {
|
||||
return getJeecgMenu(id);
|
||||
@ -44,7 +43,7 @@ public class NgAlainServiceImpl implements NgAlainService {
|
||||
|
||||
@Override
|
||||
public List<Map<String, String>> getDictByTable(String table, String key, String value) {
|
||||
return this.mapper.getDictByTable(table,key,value);
|
||||
return this.mapper.getDictByTableNgAlain(table,key,value);
|
||||
}
|
||||
|
||||
private JSONArray parseNgAlain(JSONArray jsonArray) {
|
||||
|
||||
@ -23,7 +23,7 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@Slf4j
|
||||
@Controller
|
||||
@RequestMapping("/oss/file")
|
||||
@RequestMapping("/sys/oss/file")
|
||||
public class OSSFileController {
|
||||
|
||||
@Autowired
|
||||
|
||||
@ -87,6 +87,10 @@ public class CommonController {
|
||||
}
|
||||
}
|
||||
if(CommonConstant.UPLOAD_TYPE_LOCAL.equals(uploadType)){
|
||||
//update-begin-author:lvdandan date:20200928 for:修改JEditor编辑器本地上传
|
||||
savePath = this.uploadLocal(file,bizPath);
|
||||
//update-begin-author:lvdandan date:20200928 for:修改JEditor编辑器本地上传
|
||||
/** 富文本编辑器及markdown本地上传时,采用返回链接方式
|
||||
//针对jeditor编辑器如何使 lcaol模式,采用 base64格式存储
|
||||
String jeditor = request.getParameter("jeditor");
|
||||
if(oConvertUtils.isNotEmpty(jeditor)){
|
||||
@ -96,6 +100,7 @@ public class CommonController {
|
||||
}else{
|
||||
savePath = this.uploadLocal(file,bizPath);
|
||||
}
|
||||
*/
|
||||
}else{
|
||||
//update-begin-author:taoyan date:20200814 for:文件上传改造
|
||||
savePath = CommonUtils.upload(file, bizPath, uploadType);
|
||||
|
||||
@ -1,5 +1,10 @@
|
||||
package org.jeecg.modules.system.controller;
|
||||
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.util.HexUtil;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import cn.hutool.crypto.symmetric.SymmetricAlgorithm;
|
||||
import cn.hutool.crypto.symmetric.SymmetricCrypto;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
@ -8,6 +13,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
import org.jeecg.common.aspect.annotation.AutoLog;
|
||||
import org.jeecg.common.system.base.controller.JeecgController;
|
||||
@ -15,6 +21,7 @@ import org.jeecg.common.system.query.QueryGenerator;
|
||||
import org.jeecg.common.util.dynamic.db.DataSourceCachePool;
|
||||
import org.jeecg.modules.system.entity.SysDataSource;
|
||||
import org.jeecg.modules.system.service.ISysDataSourceService;
|
||||
import org.jeecg.modules.system.util.SecurityUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
@ -60,6 +67,18 @@ public class SysDataSourceController extends JeecgController<SysDataSource, ISys
|
||||
QueryWrapper<SysDataSource> queryWrapper = QueryGenerator.initQueryWrapper(sysDataSource, req.getParameterMap());
|
||||
Page<SysDataSource> page = new Page<>(pageNo, pageSize);
|
||||
IPage<SysDataSource> pageList = sysDataSourceService.page(page, queryWrapper);
|
||||
try {
|
||||
List<SysDataSource> records = pageList.getRecords();
|
||||
records.forEach(item->{
|
||||
String dbPassword = item.getDbPassword();
|
||||
if(StringUtils.isNotBlank(dbPassword)){
|
||||
String decodedStr = SecurityUtil.jiemi(dbPassword);
|
||||
item.setDbPassword(decodedStr);
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return Result.ok(pageList);
|
||||
}
|
||||
|
||||
@ -88,7 +107,16 @@ public class SysDataSourceController extends JeecgController<SysDataSource, ISys
|
||||
@ApiOperation(value = "多数据源管理-添加", notes = "多数据源管理-添加")
|
||||
@PostMapping(value = "/add")
|
||||
public Result<?> add(@RequestBody SysDataSource sysDataSource) {
|
||||
sysDataSourceService.save(sysDataSource);
|
||||
try {
|
||||
String dbPassword = sysDataSource.getDbPassword();
|
||||
if(StringUtils.isNotBlank(dbPassword)){
|
||||
String encrypt = SecurityUtil.jiami(dbPassword);
|
||||
sysDataSource.setDbPassword(encrypt);
|
||||
}
|
||||
sysDataSourceService.save(sysDataSource);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return Result.ok("添加成功!");
|
||||
}
|
||||
|
||||
@ -102,9 +130,18 @@ public class SysDataSourceController extends JeecgController<SysDataSource, ISys
|
||||
@ApiOperation(value = "多数据源管理-编辑", notes = "多数据源管理-编辑")
|
||||
@PutMapping(value = "/edit")
|
||||
public Result<?> edit(@RequestBody SysDataSource sysDataSource) {
|
||||
SysDataSource d = sysDataSourceService.getById(sysDataSource.getId());
|
||||
DataSourceCachePool.removeCache(d.getCode());
|
||||
sysDataSourceService.updateById(sysDataSource);
|
||||
try {
|
||||
SysDataSource d = sysDataSourceService.getById(sysDataSource.getId());
|
||||
DataSourceCachePool.removeCache(d.getCode());
|
||||
String dbPassword = sysDataSource.getDbPassword();
|
||||
if(StringUtils.isNotBlank(dbPassword)){
|
||||
String encrypt = SecurityUtil.jiami(dbPassword);
|
||||
sysDataSource.setDbPassword(encrypt);
|
||||
}
|
||||
sysDataSourceService.updateById(sysDataSource);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return Result.ok("编辑成功!");
|
||||
}
|
||||
|
||||
|
||||
@ -16,11 +16,13 @@ import org.jeecg.common.system.query.QueryGenerator;
|
||||
import org.jeecg.common.system.vo.DictModel;
|
||||
import org.jeecg.common.system.vo.DictQuery;
|
||||
import org.jeecg.common.system.vo.LoginUser;
|
||||
import org.jeecg.common.util.FieldPresenceUtil;
|
||||
import org.jeecg.common.util.ImportExcelUtil;
|
||||
import org.jeecg.common.util.SqlInjectionUtil;
|
||||
import org.jeecg.common.util.oConvertUtils;
|
||||
import org.jeecg.modules.system.entity.SysDict;
|
||||
import org.jeecg.modules.system.entity.SysDictItem;
|
||||
import org.jeecg.modules.system.entity.SysUser;
|
||||
import org.jeecg.modules.system.model.SysDictTree;
|
||||
import org.jeecg.modules.system.model.TreeSelectModel;
|
||||
import org.jeecg.modules.system.service.ISysDictItemService;
|
||||
@ -124,7 +126,7 @@ public class SysDictController {
|
||||
if(dictCode.indexOf(",")!=-1) {
|
||||
//关联表字典(举例:sys_user,realname,id)
|
||||
String[] params = dictCode.split(",");
|
||||
|
||||
|
||||
if(params.length<3) {
|
||||
result.error500("字典Code格式不正确!");
|
||||
return result;
|
||||
@ -132,7 +134,7 @@ public class SysDictController {
|
||||
//SQL注入校验(只限制非法串改数据库)
|
||||
final String[] sqlInjCheck = {params[0],params[1],params[2]};
|
||||
SqlInjectionUtil.filterContent(sqlInjCheck);
|
||||
|
||||
|
||||
if(params.length==4) {
|
||||
//SQL注入校验(查询条件SQL 特殊check,此方法仅供此处使用)
|
||||
SqlInjectionUtil.specialFilterContent(params[3]);
|
||||
@ -276,6 +278,7 @@ public class SysDictController {
|
||||
}
|
||||
// SQL注入漏洞 sign签名校验(表名,label字段,val字段,条件)
|
||||
String dictCode = tbname+","+text+","+code+","+condition;
|
||||
SqlInjectionUtil.filterContent(dictCode);
|
||||
List<TreeSelectModel> ls = sysDictService.queryTreeList(query,tbname, text, code, pidField, pid,hasChildField);
|
||||
result.setSuccess(true);
|
||||
result.setResult(ls);
|
||||
@ -297,6 +300,7 @@ public class SysDictController {
|
||||
Result<List<DictModel>> res = new Result<List<DictModel>>();
|
||||
// SQL注入漏洞 sign签名校验
|
||||
String dictCode = query.getTable()+","+query.getText()+","+query.getCode();
|
||||
SqlInjectionUtil.filterContent(dictCode);
|
||||
List<DictModel> ls = this.sysDictService.queryDictTablePageList(query,pageSize,pageNo);
|
||||
res.setResult(ls);
|
||||
res.setSuccess(true);
|
||||
@ -445,6 +449,7 @@ public class SysDictController {
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
//@RequiresRoles({"admin"})
|
||||
@RequestMapping(value = "/importExcel", method = RequestMethod.POST)
|
||||
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
|
||||
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
||||
@ -456,6 +461,12 @@ public class SysDictController {
|
||||
params.setHeadRows(2);
|
||||
params.setNeedSave(true);
|
||||
try {
|
||||
//update-begin-author:wangshuai date:20201030 for:导入测试用例
|
||||
boolean aBoolean = FieldPresenceUtil.fieldPresence(file.getInputStream(), SysDictPage.class, params);
|
||||
if(!aBoolean){
|
||||
throw new RuntimeException("导入Excel标题格式不匹配!");
|
||||
}
|
||||
//update-end-author:wangshuai date:20201030 for:导入测试用例
|
||||
List<SysDictPage> list = ExcelImportUtil.importExcel(file.getInputStream(), SysDictPage.class, params);
|
||||
// 错误信息
|
||||
List<String> errorMessage = new ArrayList<>();
|
||||
@ -493,7 +504,7 @@ public class SysDictController {
|
||||
}
|
||||
return Result.error("文件导入失败!");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 查询被删除的列表
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
package org.jeecg.modules.system.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import io.swagger.annotations.Api;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.shiro.authz.annotation.RequiresRoles;
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
import org.jeecg.common.system.base.controller.JeecgController;
|
||||
import org.jeecg.common.util.oConvertUtils;
|
||||
@ -19,10 +19,10 @@ import java.util.List;
|
||||
/**
|
||||
* @Description: gateway路由管理
|
||||
* @Author: jeecg-boot
|
||||
* @Date: 2020-05-26
|
||||
* @Date: 2020-05-26
|
||||
* @Version: V1.0
|
||||
*/
|
||||
@Api(tags="gateway路由管理")
|
||||
@Api(tags = "gateway路由管理")
|
||||
@RestController
|
||||
@RequestMapping("/sys/gatewayRoute")
|
||||
@Slf4j
|
||||
@ -31,18 +31,15 @@ public class SysGatewayRouteController extends JeecgController<SysGatewayRoute,
|
||||
@Autowired
|
||||
private ISysGatewayRouteService sysGatewayRouteService;
|
||||
|
||||
@PostMapping(value = "/updateAll")
|
||||
public Result<?> updateAll(@RequestBody JSONObject json) {
|
||||
String text = json.getString("routes");
|
||||
JSONArray array = JSON.parseArray(text);
|
||||
sysGatewayRouteService.updateAll(array);
|
||||
return Result.ok("操作成功!");
|
||||
}
|
||||
@PostMapping(value = "/updateAll")
|
||||
public Result<?> updateAll(@RequestBody JSONObject json) {
|
||||
sysGatewayRouteService.updateAll(json);
|
||||
return Result.ok("操作成功!");
|
||||
}
|
||||
|
||||
@GetMapping(value = "/list")
|
||||
public Result<?> queryPageList(SysGatewayRoute sysGatewayRoute) {
|
||||
LambdaQueryWrapper<SysGatewayRoute> query = new LambdaQueryWrapper<>();
|
||||
query.eq(SysGatewayRoute::getStatus,1);
|
||||
List<SysGatewayRoute> ls = sysGatewayRouteService.list(query);
|
||||
JSONArray array = new JSONArray();
|
||||
for(SysGatewayRoute rt: ls){
|
||||
@ -64,4 +61,17 @@ public class SysGatewayRouteController extends JeecgController<SysGatewayRoute,
|
||||
return Result.ok("清除成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id删除
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
//@RequiresRoles({"admin"})
|
||||
@RequestMapping(value = "/delete", method = RequestMethod.DELETE)
|
||||
public Result<?> delete(@RequestParam(name = "id", required = true) String id) {
|
||||
sysGatewayRouteService.deleteById(id);
|
||||
return Result.ok("删除路由成功");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -5,10 +5,12 @@ import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.authz.annotation.RequiresRoles;
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
import org.jeecg.common.constant.CommonConstant;
|
||||
import org.jeecg.common.system.util.JwtUtil;
|
||||
import org.jeecg.common.system.vo.LoginUser;
|
||||
import org.jeecg.common.util.MD5Util;
|
||||
import org.jeecg.common.util.oConvertUtils;
|
||||
import org.jeecg.modules.system.entity.SysDepartPermission;
|
||||
@ -192,20 +194,20 @@ public class SysPermissionController {
|
||||
// }
|
||||
|
||||
/**
|
||||
* 查询用户拥有的菜单权限和按钮权限(根据TOKEN)
|
||||
* 查询用户拥有的菜单权限和按钮权限
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/getUserPermissionByToken", method = RequestMethod.GET)
|
||||
public Result<?> getUserPermissionByToken(@RequestParam(name = "token", required = true) String token) {
|
||||
public Result<?> getUserPermissionByToken() {
|
||||
Result<JSONObject> result = new Result<JSONObject>();
|
||||
try {
|
||||
if (oConvertUtils.isEmpty(token)) {
|
||||
return Result.error("TOKEN不允许为空!");
|
||||
//直接获取当前用户不适用前端token
|
||||
LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
||||
if (oConvertUtils.isEmpty(loginUser)) {
|
||||
return Result.error("请登录系统!");
|
||||
}
|
||||
log.info(" ------ 通过令牌获取用户拥有的访问菜单 ---- TOKEN ------ " + token);
|
||||
String username = JwtUtil.getUsername(token);
|
||||
List<SysPermission> metaList = sysPermissionService.queryByUser(username);
|
||||
List<SysPermission> metaList = sysPermissionService.queryByUser(loginUser.getUsername());
|
||||
//添加首页路由
|
||||
//update-begin-author:taoyan date:20200211 for: TASK #3368 【路由缓存】首页的缓存设置有问题,需要根据后台的路由配置来实现是否缓存
|
||||
if(!PermissionDataUtil.hasIndexPage(metaList)){
|
||||
@ -608,6 +610,14 @@ public class SysPermissionController {
|
||||
/* update_end author:wuxianquan date:20190908 for: 往菜单信息里添加外链菜单打开方式*/
|
||||
|
||||
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());
|
||||
|
||||
@ -374,7 +374,7 @@ public class SysUserController {
|
||||
Map<String,String> useDepNames = sysUserService.getDepNamesByUserIds(userIds);
|
||||
userList.forEach(item->{
|
||||
//TODO 临时借用这个字段用于页面展示
|
||||
item.setOrgCode(useDepNames.get(item.getId()));
|
||||
item.setOrgCodeTxt(useDepNames.get(item.getId()));
|
||||
});
|
||||
}
|
||||
|
||||
@ -1170,7 +1170,7 @@ public class SysUserController {
|
||||
String sex=jsonObject.getString("sex");
|
||||
String phone=jsonObject.getString("phone");
|
||||
String email=jsonObject.getString("email");
|
||||
// Date birthday=jsonObject.getDate("birthday");
|
||||
Date birthday=jsonObject.getDate("birthday");
|
||||
SysUser userPhone = sysUserService.getUserByPhone(phone);
|
||||
if(sysUser==null) {
|
||||
result.error500("未找到对应用户!");
|
||||
@ -1197,6 +1197,9 @@ public class SysUserController {
|
||||
if(StringUtils.isNotBlank(email)){
|
||||
sysUser.setEmail(email);
|
||||
}
|
||||
if(null != birthday){
|
||||
sysUser.setBirthday(birthday);
|
||||
}
|
||||
sysUser.setUpdateTime(new Date());
|
||||
sysUserService.updateById(sysUser);
|
||||
}
|
||||
|
||||
@ -4,6 +4,7 @@ import cn.hutool.crypto.SecureUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.xkcoding.justauth.AuthRequestFactory;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.zhyd.oauth.model.AuthCallback;
|
||||
import me.zhyd.oauth.model.AuthResponse;
|
||||
@ -12,25 +13,24 @@ import me.zhyd.oauth.utils.AuthStateUtils;
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
import org.jeecg.common.constant.CacheConstant;
|
||||
import org.jeecg.common.constant.CommonConstant;
|
||||
import org.jeecg.common.util.*;
|
||||
import org.jeecg.modules.base.service.BaseCommonService;
|
||||
import org.jeecg.common.system.util.JwtUtil;
|
||||
import org.jeecg.common.system.vo.LoginUser;
|
||||
import org.jeecg.common.util.PasswordUtil;
|
||||
import org.jeecg.common.util.RedisUtil;
|
||||
import org.jeecg.common.util.oConvertUtils;
|
||||
import org.jeecg.modules.system.entity.SysThirdAccount;
|
||||
import org.jeecg.modules.system.entity.SysUser;
|
||||
import org.jeecg.modules.system.model.ThirdLoginModel;
|
||||
import org.jeecg.modules.system.service.ISysThirdAccountService;
|
||||
import org.jeecg.modules.system.service.ISysUserService;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -38,11 +38,13 @@ import java.util.List;
|
||||
* @since 2018-12-17
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping("/thirdLogin")
|
||||
@RequestMapping("/sys/thirdLogin")
|
||||
@Slf4j
|
||||
public class ThirdLoginController {
|
||||
@Autowired
|
||||
private ISysUserService sysUserService;
|
||||
@Autowired
|
||||
private ISysThirdAccountService sysThirdAccountService;
|
||||
|
||||
@Autowired
|
||||
private BaseCommonService baseCommonService;
|
||||
@ -61,7 +63,7 @@ public class ThirdLoginController {
|
||||
}
|
||||
|
||||
@RequestMapping("/{source}/callback")
|
||||
public String login(@PathVariable("source") String source, AuthCallback callback,ModelMap modelMap) {
|
||||
public String loginThird(@PathVariable("source") String source, AuthCallback callback,ModelMap modelMap) {
|
||||
log.info("第三方登录进入callback:" + source + " params:" + JSONObject.toJSONString(callback));
|
||||
AuthRequest authRequest = factory.get(source);
|
||||
AuthResponse response = authRequest.login(callback);
|
||||
@ -73,43 +75,33 @@ public class ThirdLoginController {
|
||||
String username = data.getString("username");
|
||||
String avatar = data.getString("avatar");
|
||||
String uuid = data.getString("uuid");
|
||||
|
||||
//构造第三方登录信息存储对象
|
||||
ThirdLoginModel tlm = new ThirdLoginModel(source, uuid, username, avatar);
|
||||
//判断有没有这个人
|
||||
LambdaQueryWrapper<SysUser> query = new LambdaQueryWrapper<SysUser>();
|
||||
query.eq(SysUser::getThirdId, uuid);
|
||||
query.eq(SysUser::getThirdType, source);
|
||||
List<SysUser> thridList = sysUserService.list(query);
|
||||
SysUser user = null;
|
||||
//update-begin-author:wangshuai date:20201118 for:修改成查询第三方账户表
|
||||
LambdaQueryWrapper<SysThirdAccount> query = new LambdaQueryWrapper<SysThirdAccount>();
|
||||
query.eq(SysThirdAccount::getThirdUserUuid, uuid);
|
||||
query.eq(SysThirdAccount::getThirdType, source);
|
||||
List<SysThirdAccount> thridList = sysThirdAccountService.list(query);
|
||||
SysThirdAccount user = null;
|
||||
if(thridList==null || thridList.size()==0) {
|
||||
user = new SysUser();
|
||||
user.setActivitiSync(CommonConstant.ACT_SYNC_0);
|
||||
user.setDelFlag(CommonConstant.DEL_FLAG_0);
|
||||
user.setStatus(1);
|
||||
user.setThirdId(uuid);
|
||||
user.setThirdType(source);
|
||||
user.setAvatar(avatar);
|
||||
user.setUsername(uuid);
|
||||
user.setRealname(username);
|
||||
|
||||
//设置初始密码
|
||||
String salt = oConvertUtils.randomGen(8);
|
||||
user.setSalt(salt);
|
||||
String passwordEncode = PasswordUtil.encrypt(user.getUsername(), "123456", salt);
|
||||
user.setPassword(passwordEncode);
|
||||
sysUserService.saveThirdUser(user);
|
||||
//否则直接创建新账号
|
||||
user = saveThirdUser(tlm);
|
||||
}else {
|
||||
//已存在 只设置用户名 不设置头像
|
||||
user = thridList.get(0);
|
||||
//user.setUsername(username);
|
||||
//sysUserService.updateById(user);
|
||||
}
|
||||
// 生成token
|
||||
String token = JwtUtil.sign(user.getUsername(), user.getPassword());
|
||||
redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token);
|
||||
// 设置超时时间
|
||||
redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME / 1000);
|
||||
|
||||
modelMap.addAttribute("token", token);
|
||||
//update-begin-author:wangshuai date:20201118 for:从第三方登录查询是否存在用户id,不存在绑定手机号
|
||||
if(oConvertUtils.isNotEmpty(user.getSysUserId())) {
|
||||
String sysUserId = user.getSysUserId();
|
||||
SysUser sysUser = sysUserService.getById(sysUserId);
|
||||
String token = saveToken(sysUser);
|
||||
modelMap.addAttribute("token", token);
|
||||
}else{
|
||||
modelMap.addAttribute("token", "绑定手机号,"+""+uuid);
|
||||
}
|
||||
//update-end-author:wangshuai date:20201118 for:从第三方登录查询是否存在用户id,不存在绑定手机号
|
||||
//update-begin--Author:wangshuai Date:20200729 for:接口在签名校验失败时返回失败的标识码 issues#1441--------------------
|
||||
}else{
|
||||
modelMap.addAttribute("token", "登录失败");
|
||||
@ -119,11 +111,106 @@ public class ThirdLoginController {
|
||||
result.setMessage("第三方登录异常,请联系管理员");
|
||||
return "thirdLogin";
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建新账号
|
||||
* @param model
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/user/create")
|
||||
@ResponseBody
|
||||
public Result<String> thirdUserCreate(@RequestBody ThirdLoginModel model) {
|
||||
log.info("第三方登录创建新账号:" );
|
||||
Result<String> res = new Result<>();
|
||||
Object operateCode = redisUtil.get(CommonConstant.THIRD_LOGIN_CODE);
|
||||
if(operateCode==null || !operateCode.toString().equals(model.getOperateCode())){
|
||||
res.setSuccess(false);
|
||||
res.setMessage("校验失败");
|
||||
return res;
|
||||
}
|
||||
//创建新账号
|
||||
//update-begin-author:wangshuai date:20201118 for:修改成从第三方登录查出来的user_id,在查询用户表尽行token
|
||||
SysThirdAccount user = saveThirdUser(model);
|
||||
if(oConvertUtils.isNotEmpty(user.getSysUserId())){
|
||||
String sysUserId = user.getSysUserId();
|
||||
SysUser sysUser = sysUserService.getById(sysUserId);
|
||||
// 生成token
|
||||
String token = saveToken(sysUser);
|
||||
//update-end-author:wangshuai date:20201118 for:修改成从第三方登录查出来的user_id,在查询用户表尽行token
|
||||
res.setResult(token);
|
||||
res.setSuccess(true);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定账号 需要设置密码 需要走一遍校验
|
||||
* @param json
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/user/checkPassword")
|
||||
@ResponseBody
|
||||
public Result<String> checkPassword(@RequestBody JSONObject json) {
|
||||
Result<String> result = new Result<>();
|
||||
Object operateCode = redisUtil.get(CommonConstant.THIRD_LOGIN_CODE);
|
||||
if(operateCode==null || !operateCode.toString().equals(json.getString("operateCode"))){
|
||||
result.setSuccess(false);
|
||||
result.setMessage("校验失败");
|
||||
return result;
|
||||
}
|
||||
String username = json.getString("uuid");
|
||||
SysUser user = this.sysUserService.getUserByName(username);
|
||||
if(user==null){
|
||||
result.setMessage("用户未找到");
|
||||
result.setSuccess(false);
|
||||
return result;
|
||||
}
|
||||
String password = json.getString("password");
|
||||
String salt = user.getSalt();
|
||||
String passwordEncode = PasswordUtil.encrypt(user.getUsername(), password, salt);
|
||||
if(!passwordEncode.equals(user.getPassword())){
|
||||
result.setMessage("密码不正确");
|
||||
result.setSuccess(false);
|
||||
return result;
|
||||
}
|
||||
|
||||
sysUserService.updateById(user);
|
||||
result.setSuccess(true);
|
||||
// 生成token
|
||||
String token = saveToken(user);
|
||||
result.setResult(token);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建新用户
|
||||
* @param tlm 第三方登录信息
|
||||
*/
|
||||
private SysThirdAccount saveThirdUser(ThirdLoginModel tlm){
|
||||
SysThirdAccount user = new SysThirdAccount();
|
||||
user.setDelFlag(CommonConstant.DEL_FLAG_0);
|
||||
user.setStatus(1);
|
||||
user.setThirdType(tlm.getSource());
|
||||
user.setAvatar(tlm.getAvatar());
|
||||
user.setRealname(tlm.getUsername());
|
||||
user.setThirdUserUuid(tlm.getUuid());
|
||||
sysThirdAccountService.save(user);
|
||||
return user;
|
||||
}
|
||||
|
||||
private String saveToken(SysUser user) {
|
||||
// 生成token
|
||||
String token = JwtUtil.sign(user.getUsername(), user.getPassword());
|
||||
redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token);
|
||||
// 设置超时时间
|
||||
redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME / 1000);
|
||||
return token;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@RequestMapping(value = "/getLoginUser/{token}", method = RequestMethod.GET)
|
||||
@RequestMapping(value = "/getLoginUser/{token}/{thirdType}", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public Result<JSONObject> getLoginUser(@PathVariable("token") String token) throws Exception {
|
||||
public Result<JSONObject> getThirdLoginUser(@PathVariable("token") String token,@PathVariable("thirdType") String thirdType) throws Exception {
|
||||
Result<JSONObject> result = new Result<JSONObject>();
|
||||
String username = JwtUtil.getUsername(token);
|
||||
|
||||
@ -133,6 +220,18 @@ public class ThirdLoginController {
|
||||
if(!result.isSuccess()) {
|
||||
return result;
|
||||
}
|
||||
//update-begin-author:wangshuai date:20201118 for:如果真实姓名和头像不存在就取第三方登录的
|
||||
LambdaQueryWrapper<SysThirdAccount> query = new LambdaQueryWrapper<>();
|
||||
query.eq(SysThirdAccount::getSysUserId,sysUser.getId());
|
||||
query.eq(SysThirdAccount::getThirdType,thirdType);
|
||||
SysThirdAccount account = sysThirdAccountService.getOne(query);
|
||||
if(oConvertUtils.isEmpty(sysUser.getRealname())){
|
||||
sysUser.setRealname(account.getRealname());
|
||||
}
|
||||
if(oConvertUtils.isEmpty(sysUser.getAvatar())){
|
||||
sysUser.setAvatar(account.getAvatar());
|
||||
}
|
||||
//update-end-author:wangshuai date:20201118 for:如果真实姓名和头像不存在就取第三方登录的
|
||||
JSONObject obj = new JSONObject();
|
||||
//用户登录信息
|
||||
obj.put("userInfo", sysUser);
|
||||
@ -144,5 +243,38 @@ public class ThirdLoginController {
|
||||
baseCommonService.addLog("用户名: " + username + ",登录成功[第三方用户]!", CommonConstant.LOG_TYPE_1, null);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 第三方绑定手机号返回token
|
||||
*
|
||||
* @param jsonObject
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation("手机号登录接口")
|
||||
@PostMapping("/bindingThirdPhone")
|
||||
@ResponseBody
|
||||
public Result<String> bindingThirdPhone(@RequestBody JSONObject jsonObject) {
|
||||
Result<String> result = new Result<String>();
|
||||
String phone = jsonObject.getString("mobile");
|
||||
String thirdUserUuid = jsonObject.getString("thirdUserUuid");
|
||||
//校验用户有效性
|
||||
SysUser sysUser = sysUserService.getUserByPhone(phone);
|
||||
if(sysUser != null){
|
||||
sysThirdAccountService.updateThirdUserId(sysUser,thirdUserUuid);
|
||||
}else{
|
||||
// 不存在手机号,创建用户
|
||||
String smscode = jsonObject.getString("captcha");
|
||||
Object code = redisUtil.get(phone);
|
||||
if (!smscode.equals(code)) {
|
||||
result.setMessage("手机验证码错误");
|
||||
result.setSuccess(false);
|
||||
return result;
|
||||
}
|
||||
//创建用户
|
||||
sysUser = sysThirdAccountService.createUser(phone,thirdUserUuid);
|
||||
}
|
||||
String token = saveToken(sysUser);
|
||||
result.setSuccess(true);
|
||||
result.setResult(token);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@ -31,10 +31,14 @@ public class SysGatewayRoute implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**主键*/
|
||||
@TableId(type = IdType.ID_WORKER_STR)
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
@ApiModelProperty(value = "主键")
|
||||
private String id;
|
||||
|
||||
/**routerKEy*/
|
||||
@ApiModelProperty(value = "路由ID")
|
||||
private String routerId;
|
||||
|
||||
/**服务名*/
|
||||
@Excel(name = "服务名", width = 15)
|
||||
@ApiModelProperty(value = "服务名")
|
||||
|
||||
@ -0,0 +1,63 @@
|
||||
package org.jeecg.modules.system.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import org.jeecgframework.poi.excel.annotation.Excel;
|
||||
|
||||
/**
|
||||
* @Description: 第三方登录账号表
|
||||
* @Author: jeecg-boot
|
||||
* @Date: 2020-11-17
|
||||
* @Version: V1.0
|
||||
*/
|
||||
@Data
|
||||
@TableName("sys_third_account")
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Accessors(chain = true)
|
||||
@ApiModel(value="sys_third_account对象", description="第三方登录账号表")
|
||||
public class SysThirdAccount {
|
||||
|
||||
/**编号*/
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
@ApiModelProperty(value = "编号")
|
||||
private java.lang.String id;
|
||||
/**第三方登录id*/
|
||||
@Excel(name = "第三方登录id", width = 15)
|
||||
@ApiModelProperty(value = "第三方登录id")
|
||||
private java.lang.String sysUserId;
|
||||
/**登录来源*/
|
||||
@Excel(name = "登录来源", width = 15)
|
||||
@ApiModelProperty(value = "登录来源")
|
||||
private java.lang.String thirdType;
|
||||
/**头像*/
|
||||
@Excel(name = "头像", width = 15)
|
||||
@ApiModelProperty(value = "头像")
|
||||
private java.lang.String avatar;
|
||||
/**状态(1-正常,2-冻结)*/
|
||||
@Excel(name = "状态(1-正常,2-冻结)", width = 15)
|
||||
@ApiModelProperty(value = "状态(1-正常,2-冻结)")
|
||||
private java.lang.Integer status;
|
||||
/**删除状态(0-正常,1-已删除)*/
|
||||
@Excel(name = "删除状态(0-正常,1-已删除)", width = 15)
|
||||
@ApiModelProperty(value = "删除状态(0-正常,1-已删除)")
|
||||
private java.lang.Integer delFlag;
|
||||
/**真实姓名*/
|
||||
@Excel(name = "真实姓名", width = 15)
|
||||
@ApiModelProperty(value = "真实姓名")
|
||||
private java.lang.String realname;
|
||||
/**真实姓名*/
|
||||
@Excel(name = "真实姓名", width = 15)
|
||||
@ApiModelProperty(value = "真实姓名")
|
||||
private java.lang.String thirdUserUuid;
|
||||
}
|
||||
@ -175,19 +175,6 @@ public class SysUser implements Serializable {
|
||||
@Dict(dictTable ="sys_depart",dicText = "depart_name",dicCode = "id")
|
||||
private String departIds;
|
||||
|
||||
|
||||
/**
|
||||
* 第三方登录的唯一标识
|
||||
*/
|
||||
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
|
||||
private String thirdId;
|
||||
|
||||
/**
|
||||
* 第三方类型 <br>
|
||||
* (github/github,wechat_enterprise/企业微信,dingtalk/钉钉)
|
||||
*/
|
||||
private String thirdType;
|
||||
|
||||
/**
|
||||
* 多租户id配置,编辑用户的时候设置
|
||||
*/
|
||||
|
||||
@ -41,6 +41,10 @@ public interface SysDictMapper extends BaseMapper<SysDict> {
|
||||
@Deprecated
|
||||
public List<DictModel> queryTableDictItemsByCodeAndFilter(@Param("table") String table,@Param("text") String text,@Param("code") String code,@Param("filterSql") String filterSql);
|
||||
|
||||
@Deprecated
|
||||
@Select("select ${key} as \"label\",${value} as \"value\" from ${table}")
|
||||
public List<Map<String,String>> getDictByTableNgAlain(@Param("table") String table, @Param("key") String key, @Param("value") String value);
|
||||
|
||||
public String queryDictTextByKey(@Param("code") String code,@Param("key") String key);
|
||||
|
||||
@Deprecated
|
||||
|
||||
@ -0,0 +1,17 @@
|
||||
package org.jeecg.modules.system.mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.jeecg.modules.system.entity.SysThirdAccount;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* @Description: 第三方登录账号表
|
||||
* @Author: jeecg-boot
|
||||
* @Date: 2020-11-17
|
||||
* @Version: V1.0
|
||||
*/
|
||||
public interface SysThirdAccountMapper extends BaseMapper<SysThirdAccount> {
|
||||
|
||||
}
|
||||
@ -1,13 +1,10 @@
|
||||
package org.jeecg.modules.system.mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.jeecg.modules.system.entity.SysUserDepart;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
|
||||
public interface SysUserDepartMapper extends BaseMapper<SysUserDepart>{
|
||||
|
||||
List<SysUserDepart> getUserDepartByUid(@Param("userId") String userId);
|
||||
|
||||
@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="org.jeecg.modules.system.mapper.SysThirdAccountMapper">
|
||||
|
||||
</mapper>
|
||||
@ -0,0 +1,72 @@
|
||||
package org.jeecg.modules.system.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 第三方登录 信息存储
|
||||
*/
|
||||
@Data
|
||||
public class ThirdLoginModel implements Serializable {
|
||||
private static final long serialVersionUID = 4098628709290780891L;
|
||||
|
||||
/**
|
||||
* 第三方登录 来源
|
||||
*/
|
||||
private String source;
|
||||
|
||||
/**
|
||||
* 第三方登录 uuid
|
||||
*/
|
||||
private String uuid;
|
||||
|
||||
/**
|
||||
* 第三方登录 username
|
||||
*/
|
||||
private String username;
|
||||
|
||||
/**
|
||||
* 第三方登录 头像
|
||||
*/
|
||||
private String avatar;
|
||||
|
||||
/**
|
||||
* 账号 后缀第三方登录 防止账号重复
|
||||
*/
|
||||
private String suffix;
|
||||
|
||||
/**
|
||||
* 操作码 防止被攻击
|
||||
*/
|
||||
private String operateCode;
|
||||
|
||||
public ThirdLoginModel(){
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造器
|
||||
* @param source
|
||||
* @param uuid
|
||||
* @param username
|
||||
* @param avatar
|
||||
*/
|
||||
public ThirdLoginModel(String source,String uuid,String username,String avatar){
|
||||
this.source = source;
|
||||
this.uuid = uuid;
|
||||
this.username = username;
|
||||
this.avatar = avatar;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取登录账号名
|
||||
* @return
|
||||
*/
|
||||
public String getUserLoginAccount(){
|
||||
if(suffix==null){
|
||||
return this.uuid;
|
||||
}
|
||||
return this.uuid + this.suffix;
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,6 @@
|
||||
package org.jeecg.modules.system.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.jeecg.modules.system.entity.SysGatewayRoute;
|
||||
|
||||
@ -16,13 +16,19 @@ public interface ISysGatewayRouteService extends IService<SysGatewayRoute> {
|
||||
* 添加所有的路由信息到redis
|
||||
* @param key
|
||||
*/
|
||||
public void addRoute2Redis(String key);
|
||||
void addRoute2Redis(String key);
|
||||
|
||||
/**
|
||||
* 删除路由
|
||||
* @param id
|
||||
*/
|
||||
void deleteById(String id);
|
||||
|
||||
/**
|
||||
* 保存路由配置
|
||||
* @param array
|
||||
*/
|
||||
void updateAll(JSONArray array);
|
||||
void updateAll(JSONObject array);
|
||||
|
||||
/**
|
||||
* 清空redis中的route信息
|
||||
|
||||
@ -0,0 +1,19 @@
|
||||
package org.jeecg.modules.system.service;
|
||||
|
||||
import org.jeecg.modules.system.entity.SysThirdAccount;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.jeecg.modules.system.entity.SysUser;
|
||||
|
||||
/**
|
||||
* @Description: 第三方登录账号表
|
||||
* @Author: jeecg-boot
|
||||
* @Date: 2020-11-17
|
||||
* @Version: V1.0
|
||||
*/
|
||||
public interface ISysThirdAccountService extends IService<SysThirdAccount> {
|
||||
/**更新第三方账户信息*/
|
||||
void updateThirdUserId(SysUser sysUser,String thirdUserUuid);
|
||||
/**创建第三方用户*/
|
||||
SysUser createUser(String phone, String thirdUserUuid);
|
||||
|
||||
}
|
||||
@ -10,9 +10,10 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.google.common.base.Joiner;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.jeecg.common.api.dto.message.*;
|
||||
import org.jeecg.common.api.dto.OnlineAuthDTO;
|
||||
import org.jeecg.common.api.dto.message.*;
|
||||
import org.jeecg.common.aspect.UrlMatchEnum;
|
||||
import org.jeecg.common.constant.CacheConstant;
|
||||
import org.jeecg.common.constant.CommonConstant;
|
||||
@ -31,12 +32,14 @@ import org.jeecg.modules.message.websocket.WebSocket;
|
||||
import org.jeecg.modules.system.entity.*;
|
||||
import org.jeecg.modules.system.mapper.*;
|
||||
import org.jeecg.modules.system.service.*;
|
||||
import org.jeecg.modules.system.util.SecurityUtil;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.AntPathMatcher;
|
||||
import org.springframework.util.PathMatcher;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Connection;
|
||||
@ -630,12 +633,22 @@ public class SysBaseApiImpl implements ISysBaseAPI {
|
||||
@Override
|
||||
public DynamicDataSourceModel getDynamicDbSourceById(String dbSourceId) {
|
||||
SysDataSource dbSource = dataSourceService.getById(dbSourceId);
|
||||
if(dbSource!=null && StringUtils.isNotBlank(dbSource.getDbPassword())){
|
||||
String dbPassword = dbSource.getDbPassword();
|
||||
String decodedStr = SecurityUtil.jiemi(dbPassword);
|
||||
dbSource.setDbPassword(decodedStr);
|
||||
}
|
||||
return new DynamicDataSourceModel(dbSource);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DynamicDataSourceModel getDynamicDbSourceByCode(String dbSourceCode) {
|
||||
SysDataSource dbSource = dataSourceService.getOne(new LambdaQueryWrapper<SysDataSource>().eq(SysDataSource::getCode, dbSourceCode));
|
||||
if(dbSource!=null && StringUtils.isNotBlank(dbSource.getDbPassword())){
|
||||
String dbPassword = dbSource.getDbPassword();
|
||||
String decodedStr = SecurityUtil.jiemi(dbPassword);
|
||||
dbSource.setDbPassword(decodedStr);
|
||||
}
|
||||
return new DynamicDataSourceModel(dbSource);
|
||||
}
|
||||
|
||||
|
||||
@ -51,7 +51,7 @@ public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, SysDict> impl
|
||||
@Override
|
||||
@Cacheable(value = CacheConstant.SYS_DICT_CACHE,key = "#code")
|
||||
public List<DictModel> queryDictItemsByCode(String code) {
|
||||
log.info("无缓存dictCache的时候调用这里!");
|
||||
log.debug("无缓存dictCache的时候调用这里!");
|
||||
return sysDictMapper.queryDictItemsByCode(code);
|
||||
}
|
||||
|
||||
@ -73,7 +73,7 @@ public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, SysDict> impl
|
||||
}).collect(Collectors.toList());
|
||||
res.put(d.getDictCode(), dictModelList);
|
||||
}
|
||||
log.info("-------登录加载系统字典-----" + res.toString());
|
||||
log.debug("-------登录加载系统字典-----" + res.toString());
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -87,7 +87,7 @@ public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, SysDict> impl
|
||||
@Override
|
||||
@Cacheable(value = CacheConstant.SYS_DICT_CACHE,key = "#code+':'+#key")
|
||||
public String queryDictTextByKey(String code, String key) {
|
||||
log.info("无缓存dictText的时候调用这里!");
|
||||
log.debug("无缓存dictText的时候调用这里!");
|
||||
return sysDictMapper.queryDictTextByKey(code, key);
|
||||
}
|
||||
|
||||
@ -102,13 +102,13 @@ public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, SysDict> impl
|
||||
@Override
|
||||
//@Cacheable(value = CacheConstant.SYS_DICT_TABLE_CACHE)
|
||||
public List<DictModel> queryTableDictItemsByCode(String table, String text, String code) {
|
||||
log.info("无缓存dictTableList的时候调用这里!");
|
||||
log.debug("无缓存dictTableList的时候调用这里!");
|
||||
return sysDictMapper.queryTableDictItemsByCode(table,text,code);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DictModel> queryTableDictItemsByCodeAndFilter(String table, String text, String code, String filterSql) {
|
||||
log.info("无缓存dictTableList的时候调用这里!");
|
||||
log.debug("无缓存dictTableList的时候调用这里!");
|
||||
return sysDictMapper.queryTableDictItemsByCodeAndFilter(table,text,code,filterSql);
|
||||
}
|
||||
|
||||
@ -124,7 +124,7 @@ public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, SysDict> impl
|
||||
@Override
|
||||
@Cacheable(value = CacheConstant.SYS_DICT_TABLE_CACHE)
|
||||
public String queryTableDictTextByKey(String table,String text,String code, String key) {
|
||||
log.info("无缓存dictTable的时候调用这里!");
|
||||
log.debug("无缓存dictTable的时候调用这里!");
|
||||
return sysDictMapper.queryTableDictTextByKey(table,text,code,key);
|
||||
}
|
||||
|
||||
|
||||
@ -1,88 +1,102 @@
|
||||
package org.jeecg.modules.system.service.impl;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jeecg.common.base.BaseMap;
|
||||
import org.jeecg.common.constant.CacheConstant;
|
||||
import org.jeecg.common.constant.GlobalConstants;
|
||||
import org.jeecg.modules.system.entity.SysGatewayRoute;
|
||||
import org.jeecg.modules.system.mapper.SysGatewayRouteMapper;
|
||||
import org.jeecg.modules.system.service.ISysGatewayRouteService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.context.ApplicationEventPublisherAware;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Description: gateway路由管理
|
||||
* @Author: jeecg-boot
|
||||
* @Date: 2020-05-26
|
||||
* @Date: 2020-05-26
|
||||
* @Version: V1.0
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class SysGatewayRouteServiceImpl extends ServiceImpl<SysGatewayRouteMapper, SysGatewayRoute> implements ApplicationEventPublisherAware,ISysGatewayRouteService {
|
||||
public class SysGatewayRouteServiceImpl extends ServiceImpl<SysGatewayRouteMapper, SysGatewayRoute> implements ISysGatewayRouteService {
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate<String, Object> redisTemplate;
|
||||
|
||||
private ApplicationEventPublisher applicationEventPublisher;
|
||||
|
||||
@Override
|
||||
public void addRoute2Redis(String key) {
|
||||
List<SysGatewayRoute> ls = this.list(new LambdaQueryWrapper<SysGatewayRoute>().eq(SysGatewayRoute::getStatus,1));
|
||||
List<SysGatewayRoute> ls = this.list(new LambdaQueryWrapper<SysGatewayRoute>().eq(SysGatewayRoute::getStatus, 1));
|
||||
redisTemplate.opsForValue().set(key, JSON.toJSONString(ls));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteById(String id) {
|
||||
this.removeById(id);
|
||||
this.resreshRouter();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateAll(JSONArray array) {
|
||||
public void updateAll(JSONObject json) {
|
||||
log.info("--gateway 路由配置修改--");
|
||||
try {
|
||||
this.remove(new LambdaQueryWrapper<SysGatewayRoute>().eq(SysGatewayRoute::getStatus,1));
|
||||
List<SysGatewayRoute> ls = new ArrayList<>();
|
||||
for(int i =0;i<array.size();i++){
|
||||
JSONObject json = array.getJSONObject(i);
|
||||
SysGatewayRoute route = new SysGatewayRoute();
|
||||
route.setId(json.getString("id"));
|
||||
route.setName(json.getString("name"));
|
||||
route.setPredicates(json.getString("predicates"));
|
||||
route.setFilters(json.getString("filters"));
|
||||
route.setUri(json.getString("uri"));
|
||||
if(json.get("status")==null){
|
||||
route.setStatus(1);
|
||||
}else{
|
||||
route.setStatus(json.getInteger("status"));
|
||||
}
|
||||
ls.add(route);
|
||||
json = json.getJSONObject("router");
|
||||
String id = json.getString("id");
|
||||
SysGatewayRoute route = getById(id);
|
||||
if (ObjectUtil.isEmpty(route)) {
|
||||
route = new SysGatewayRoute();
|
||||
}
|
||||
this.saveBatch(ls);
|
||||
redisTemplate.opsForValue().set(CacheConstant.GATEWAY_ROUTES, JSON.toJSONString(ls));
|
||||
//执行完毕需要重新加载路由 但是触发事件在另一个项目,此路不通,只能通过redis监听整了
|
||||
// this.applicationEventPublisher.publishEvent(new RefreshRoutesEvent(this));
|
||||
redisTemplate.convertAndSend(CacheConstant.ROUTE_JVM_RELOAD_TOPIC, "system路由信息,网关缓存更新>>");
|
||||
route.setRouterId(json.getString("routerId"));
|
||||
route.setName(json.getString("name"));
|
||||
route.setPredicates(json.getString("predicates"));
|
||||
String filters = json.getString("filters");
|
||||
if (ObjectUtil.isEmpty(filters)) {
|
||||
filters = "[]";
|
||||
}
|
||||
route.setFilters(filters);
|
||||
route.setUri(json.getString("uri"));
|
||||
if (json.get("status") == null) {
|
||||
route.setStatus(1);
|
||||
} else {
|
||||
route.setStatus(json.getInteger("status"));
|
||||
}
|
||||
this.saveOrUpdate(route);
|
||||
resreshRouter();
|
||||
} catch (Exception e) {
|
||||
log.error("路由配置解析失败", e);
|
||||
//报错需要重新初始化路由
|
||||
//this.applicationEventPublisher.publishEvent(new GatewayRouteInitEvent(this));
|
||||
resreshRouter();
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearRedis() {
|
||||
redisTemplate.opsForValue().set(CacheConstant.GATEWAY_ROUTES, null);
|
||||
/**
|
||||
* 更新redis路由缓存
|
||||
*/
|
||||
private void resreshRouter() {
|
||||
//更新redis路由缓存
|
||||
addRoute2Redis(CacheConstant.GATEWAY_ROUTES);
|
||||
BaseMap params = new BaseMap();
|
||||
params.put(GlobalConstants.HANDLER_NAME, "loderRouderHandler");
|
||||
//刷新网关
|
||||
redisTemplate.convertAndSend(GlobalConstants.REDIS_TOPIC_NAME, params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
|
||||
this.applicationEventPublisher = applicationEventPublisher;
|
||||
public void clearRedis() {
|
||||
redisTemplate.opsForValue().set(CacheConstant.GATEWAY_ROUTES, null);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,104 @@
|
||||
package org.jeecg.modules.system.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import org.jeecg.common.constant.CommonConstant;
|
||||
import org.jeecg.common.util.PasswordUtil;
|
||||
import org.jeecg.common.util.UUIDGenerator;
|
||||
import org.jeecg.common.util.oConvertUtils;
|
||||
import org.jeecg.modules.system.entity.SysRole;
|
||||
import org.jeecg.modules.system.entity.SysThirdAccount;
|
||||
import org.jeecg.modules.system.entity.SysUser;
|
||||
import org.jeecg.modules.system.entity.SysUserRole;
|
||||
import org.jeecg.modules.system.mapper.SysRoleMapper;
|
||||
import org.jeecg.modules.system.mapper.SysThirdAccountMapper;
|
||||
import org.jeecg.modules.system.mapper.SysUserMapper;
|
||||
import org.jeecg.modules.system.mapper.SysUserRoleMapper;
|
||||
import org.jeecg.modules.system.service.ISysThirdAccountService;
|
||||
import org.jeecg.modules.system.service.ISysUserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description: 第三方登录账号表
|
||||
* @Author: jeecg-boot
|
||||
* @Date: 2020-11-17
|
||||
* @Version: V1.0
|
||||
*/
|
||||
@Service
|
||||
public class SysThirdAccountServiceImpl extends ServiceImpl<SysThirdAccountMapper, SysThirdAccount> implements ISysThirdAccountService {
|
||||
|
||||
@Autowired
|
||||
private SysThirdAccountMapper sysThirdAccountMapper;
|
||||
|
||||
@Autowired
|
||||
private SysUserMapper sysUserMapper;
|
||||
@Autowired
|
||||
private SysRoleMapper sysRoleMapper;
|
||||
@Autowired
|
||||
private SysUserRoleMapper sysUserRoleMapper;
|
||||
|
||||
@Override
|
||||
public void updateThirdUserId(SysUser sysUser,String thirdUserUuid) {
|
||||
//修改第三方登录账户表使其进行添加用户id
|
||||
LambdaQueryWrapper<SysThirdAccount> query = new LambdaQueryWrapper<>();
|
||||
query.eq(SysThirdAccount::getThirdUserUuid,thirdUserUuid);
|
||||
SysThirdAccount account = sysThirdAccountMapper.selectOne(query);
|
||||
SysThirdAccount sysThirdAccount = new SysThirdAccount();
|
||||
sysThirdAccount.setSysUserId(sysUser.getId());
|
||||
//根据当前用户id和登录方式查询第三方登录表
|
||||
LambdaQueryWrapper<SysThirdAccount> thirdQuery = new LambdaQueryWrapper<>();
|
||||
thirdQuery.eq(SysThirdAccount::getSysUserId,sysUser.getId());
|
||||
thirdQuery.eq(SysThirdAccount::getThirdType,account.getThirdType());
|
||||
SysThirdAccount sysThirdAccounts = sysThirdAccountMapper.selectOne(thirdQuery);
|
||||
if(sysThirdAccounts!=null){
|
||||
sysThirdAccountMapper.deleteById(sysThirdAccounts.getId());
|
||||
}
|
||||
//更新用户账户表sys_user_id
|
||||
sysThirdAccountMapper.update(sysThirdAccount,query);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysUser createUser(String phone, String thirdUserUuid) {
|
||||
//先查询第三方,获取登录方式
|
||||
LambdaQueryWrapper<SysThirdAccount> query = new LambdaQueryWrapper<>();
|
||||
query.eq(SysThirdAccount::getThirdUserUuid,thirdUserUuid);
|
||||
SysThirdAccount account = sysThirdAccountMapper.selectOne(query);
|
||||
//添加用户
|
||||
SysUser user = new SysUser();
|
||||
user.setActivitiSync(CommonConstant.ACT_SYNC_0);
|
||||
user.setDelFlag(CommonConstant.DEL_FLAG_0);
|
||||
user.setStatus(1);
|
||||
user.setUsername(thirdUserUuid);
|
||||
user.setPhone(phone);
|
||||
//设置初始密码
|
||||
String salt = oConvertUtils.randomGen(8);
|
||||
user.setSalt(salt);
|
||||
String passwordEncode = PasswordUtil.encrypt(user.getUsername(), "123456", salt);
|
||||
user.setPassword(passwordEncode);
|
||||
String s = this.saveThirdUser(user);
|
||||
//更新用户第三方账户表的userId
|
||||
SysThirdAccount sysThirdAccount = new SysThirdAccount();
|
||||
sysThirdAccount.setSysUserId(s);
|
||||
sysThirdAccountMapper.update(sysThirdAccount,query);
|
||||
return user;
|
||||
}
|
||||
|
||||
public String saveThirdUser(SysUser sysUser) {
|
||||
//保存用户
|
||||
String userid = UUIDGenerator.generate();
|
||||
sysUser.setId(userid);
|
||||
sysUserMapper.insert(sysUser);
|
||||
//获取第三方角色
|
||||
SysRole sysRole = sysRoleMapper.selectOne(new LambdaQueryWrapper<SysRole>().eq(SysRole::getRoleCode, "third_role"));
|
||||
//保存用户角色
|
||||
SysUserRole userRole = new SysUserRole();
|
||||
userRole.setRoleId(sysRole.getId());
|
||||
userRole.setUserId(userid);
|
||||
sysUserRoleMapper.insert(userRole);
|
||||
return userid;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,51 @@
|
||||
package org.jeecg.modules.system.util;
|
||||
|
||||
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.crypto.symmetric.SymmetricAlgorithm;
|
||||
import cn.hutool.crypto.symmetric.SymmetricCrypto;
|
||||
|
||||
/**
|
||||
* @Description: 密码加密解密
|
||||
* @author: lsq
|
||||
* @date: 2020年09月07日 14:26
|
||||
*/
|
||||
public class SecurityUtil {
|
||||
/**加密key*/
|
||||
private static String key = "JEECGBOOT1423670";
|
||||
|
||||
//---AES加密---------begin---------
|
||||
/**加密
|
||||
* @param content
|
||||
* @return
|
||||
*/
|
||||
public static String jiami(String content) {
|
||||
SymmetricCrypto aes = new SymmetricCrypto(SymmetricAlgorithm.AES, key.getBytes());
|
||||
String encryptResultStr = aes.encryptHex(content);
|
||||
return encryptResultStr;
|
||||
}
|
||||
|
||||
/**解密
|
||||
* @param encryptResultStr
|
||||
* @return
|
||||
*/
|
||||
public static String jiemi(String encryptResultStr){
|
||||
SymmetricCrypto aes = new SymmetricCrypto(SymmetricAlgorithm.AES, key.getBytes());
|
||||
//解密为字符串
|
||||
String decryptResult = aes.decryptStr(encryptResultStr, CharsetUtil.CHARSET_UTF_8);
|
||||
return decryptResult;
|
||||
}
|
||||
//---AES加密---------end---------
|
||||
/**
|
||||
* 主函数
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
String content="test1111";
|
||||
String encrypt = jiami(content);
|
||||
System.out.println(encrypt);
|
||||
//构建
|
||||
String decrypt = jiemi(encrypt);
|
||||
//解密为字符串
|
||||
System.out.println(decrypt);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user