Jeecg-Boot 2.2.0 版本发布 | 重磅升级

This commit is contained in:
zhangdaiscott
2020-05-03 12:43:53 +08:00
parent c4ac8d716b
commit b87ac50420
335 changed files with 12894 additions and 27387 deletions

View File

@ -1,29 +1,25 @@
package org.jeecg;
import java.net.InetAddress;
import java.net.UnknownHostException;
import lombok.extern.slf4j.Slf4j;
import org.apache.catalina.Context;
import org.apache.tomcat.util.scan.StandardJarScanner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;
import lombok.extern.slf4j.Slf4j;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import java.net.InetAddress;
import java.net.UnknownHostException;
@Slf4j
@EnableSwagger2
@SpringBootApplication
@EnableAutoConfiguration
public class JeecgApplication {
public static void main(String[] args) throws UnknownHostException {
//System.setProperty("spring.devtools.restart.enabled", "true");
ConfigurableApplicationContext application = SpringApplication.run(JeecgApplication.class, args);
Environment env = application.getEnvironment();
@ -34,9 +30,21 @@ public class JeecgApplication {
"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: \t\thttp://" + ip + ":" + port + path + "/doc.html\n" +
"Swagger-UI: \t\thttp://" + ip + ":" + port + path + "/doc.html\n" +
"----------------------------------------------------------");
}
/**
* tomcat-embed-jasper引用后提示jar找不到的问题
*/
@Bean
public TomcatServletWebServerFactory tomcatFactory() {
return new TomcatServletWebServerFactory() {
@Override
protected void postProcessContext(Context context) {
((StandardJarScanner) context.getJarScanner()).setScanManifest(false);
}
};
}
}

View File

@ -4,8 +4,9 @@ import org.jeecgframework.codegenerate.window.CodeWindow;
/**
* @Title: 单表代码生成器入口
* 【 GUI模式已弃用请转移Online模式进行代码生成 】
* @Author 张代浩
* @site www.jeecg.org
* @site www.jeecg.com
* @Version:V1.0.1
*/
public class JeecgOneGUI {

View File

@ -9,6 +9,7 @@ import org.jeecgframework.codegenerate.generate.pojo.onetomany.SubTableVo;
/**
* 代码生成器入口【一对多】
* 【 GUI模式已弃用请转移Online模式进行代码生成 】
* @Author 张代浩
* @site www.jeecg.org
*
@ -23,17 +24,17 @@ public class JeecgOneToMainUtil {
//第一步:设置主表配置
MainTableVo mainTable = new MainTableVo();
mainTable.setTableName("jeecg_order_main");//表名
mainTable.setEntityName("TestOrderMain"); //实体名
mainTable.setEntityPackage("test2"); //包名
mainTable.setFtlDescription("订单"); //描述
mainTable.setEntityName("GuiTestOrderMain"); //实体名
mainTable.setEntityPackage("gui"); //包名
mainTable.setFtlDescription("GUI订单管理"); //描述
//第二步:设置子表集合配置
List<SubTableVo> subTables = new ArrayList<SubTableVo>();
//[1].子表一
SubTableVo po = new SubTableVo();
po.setTableName("jeecg_order_customer");//表名
po.setEntityName("TestOrderCustom"); //实体名
po.setEntityPackage("test2"); //包名
po.setEntityName("GuiTestOrderCustom"); //实体名
po.setEntityPackage("gui"); //包名
po.setFtlDescription("客户明细"); //描述
//子表外键参数配置
/*说明:
@ -46,8 +47,8 @@ public class JeecgOneToMainUtil {
//[2].子表二
SubTableVo po2 = new SubTableVo();
po2.setTableName("jeecg_order_ticket"); //表名
po2.setEntityName("TestOrderTicket"); //实体名
po2.setEntityPackage("test2"); //包名
po2.setEntityName("GuiTestOrderTicket"); //实体名
po2.setEntityPackage("gui"); //包名
po2.setFtlDescription("产品明细"); //描述
//子表外键参数配置
/*说明:

View File

@ -1,7 +1,7 @@
package org.jeecg.config;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.system.util.MinioUtil;
import org.jeecg.common.util.MinioUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

View File

@ -70,11 +70,12 @@ public class ShiroConfig {
//cas验证登录
filterChainDefinitionMap.put("/cas/client/validateLogin", "anon");
// 配置不会被拦截的链接 顺序判断
filterChainDefinitionMap.put("/sys/getCheckCode", "anon"); //登录验证码接口排除
filterChainDefinitionMap.put("/sys/randomImage/**", "anon"); //登录验证码接口排除
filterChainDefinitionMap.put("/sys/checkCaptcha", "anon"); //登录验证码接口排除
filterChainDefinitionMap.put("/sys/login", "anon"); //登录接口排除
filterChainDefinitionMap.put("/sys/mLogin", "anon"); //登录接口排除
filterChainDefinitionMap.put("/sys/logout", "anon"); //登出接口排除
filterChainDefinitionMap.put("/thirdLogin/**", "anon"); //第三方登录
filterChainDefinitionMap.put("/sys/getEncryptedString", "anon"); //获取加密串
filterChainDefinitionMap.put("/sys/sms", "anon");//短信验证码
filterChainDefinitionMap.put("/sys/phoneLogin", "anon");//手机登录
@ -85,8 +86,6 @@ public class ShiroConfig {
filterChainDefinitionMap.put("/sys/user/passwordChange", "anon");//用户更改密码
filterChainDefinitionMap.put("/auth/2step-code", "anon");//登录验证码
filterChainDefinitionMap.put("/sys/common/static/**", "anon");//图片预览 &下载文件不限制token
//filterChainDefinitionMap.put("/sys/common/view/**", "anon");//图片预览不限制token
//filterChainDefinitionMap.put("/sys/common/download/**", "anon");//文件下载不限制token
filterChainDefinitionMap.put("/sys/common/pdf/**", "anon");//pdf预览
filterChainDefinitionMap.put("/generic/**", "anon");//pdf预览需要文件
filterChainDefinitionMap.put("/", "anon");
@ -117,19 +116,16 @@ public class ShiroConfig {
filterChainDefinitionMap.put("/actuator/httptrace/**", "anon");
filterChainDefinitionMap.put("/actuator/redis/**", "anon");
//大屏设计器排除
filterChainDefinitionMap.put("/big/screen/**", "anon");
//测试示例
filterChainDefinitionMap.put("/test/jeecgDemo/html", "anon"); //模板页面
filterChainDefinitionMap.put("/test/jeecgDemo/redis/**", "anon"); //redis测试
//排除Online请求
filterChainDefinitionMap.put("/auto/cgform/**", "anon");
//websocket排除
filterChainDefinitionMap.put("/websocket/**", "anon");
//大屏设计器排除
filterChainDefinitionMap.put("/big/screen/**", "anon");
// 添加自己的过滤器并且取名为jwt
Map<String, Filter> filterMap = new HashMap<String, Filter>(1);
filterMap.put("jwt", new JwtFilter());
@ -173,6 +169,12 @@ public class ShiroConfig {
public DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator() {
DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator = new DefaultAdvisorAutoProxyCreator();
defaultAdvisorAutoProxyCreator.setProxyTargetClass(true);
/**
* 解决重复代理问题 github#994
* 添加前缀判断 不匹配 任何Advisor
*/
defaultAdvisorAutoProxyCreator.setUsePrefix(true);
defaultAdvisorAutoProxyCreator.setAdvisorBeanNamePrefix("_no_advisor");
return defaultAdvisorAutoProxyCreator;
}

View File

@ -1,32 +1,31 @@
package org.jeecg.config;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.shiro.vo.DefContants;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.service.ApiKey;
import springfox.documentation.service.Parameter;
import lombok.extern.slf4j.Slf4j;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.ApiKey;
import springfox.documentation.service.Parameter;
import springfox.documentation.service.SecurityScheme;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* @Author scott
*/
@ -34,6 +33,7 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configuration
@EnableSwagger2
@EnableSwaggerBootstrapUI
@ConditionalOnProperty(name = "swagger.enable", havingValue = "true")
public class Swagger2Config implements WebMvcConfigurer {
/**

View File

@ -1,18 +1,20 @@
package org.jeecg.config;
import org.jeecg.modules.shiro.authc.interceptor.OnlineInterceptor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
* Spring Boot 2.0 解决跨域问题
*
*
* @Author qinfeng
*
*/
@ -26,6 +28,11 @@ public class WebMvcConfiguration implements WebMvcConfigurer {
@Value("${spring.resource.static-locations}")
private String staticLocations;
@Bean
public OnlineInterceptor onlineInterceptor(){
return new OnlineInterceptor();
}
@Bean
public CorsFilter corsFilter() {
final UrlBasedCorsConfigurationSource urlBasedCorsConfigurationSource = new UrlBasedCorsConfigurationSource();
@ -60,4 +67,10 @@ public class WebMvcConfiguration implements WebMvcConfigurer {
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/").setViewName("doc.html");
}
@Override
public void addInterceptors(InterceptorRegistry registry) {
String [] exculudes = new String[]{"/*.html","/html/**","/js/**","/css/**","/images/**"};
registry.addInterceptor(onlineInterceptor()).excludePathPatterns(exculudes).addPathPatterns("/online/cgform/api/**");
}
}

View File

@ -194,7 +194,7 @@ public class MockController {
//json = FileUtils.re.readFileToString(jsonFile);
//换个写法解决springboot读取jar包中文件的问题
InputStream stream = getClass().getClassLoader().getResourceAsStream(jsonSrc.replace("classpath:", ""));
json = IOUtils.toString(stream);
json = IOUtils.toString(stream,"UTF-8");
} catch (IOException e) {
log.error(e.getMessage(),e);
}

View File

@ -0,0 +1,36 @@
[
{"value": "110000", "label": "北京市"},
{"value": "120000", "label": "天津市"},
{"value": "130000", "label": "河北省"},
{"value": "140000", "label": "山西省"},
{"value": "150000", "label": "内蒙古自治区"},
{"value": "210000", "label": "辽宁省"},
{"value": "220000", "label": "吉林省"},
{"value": "230000", "label": "黑龙江省"},
{"value": "310000", "label": "上海市"},
{"value": "320000", "label": "江苏省"},
{"value": "330000", "label": "浙江省"},
{"value": "340000", "label": "安徽省"},
{"value": "350000", "label": "福建省"},
{"value": "360000", "label": "江西省"},
{"value": "370000", "label": "山东省"},
{"value": "410000", "label": "河南省"},
{"value": "420000", "label": "湖北省"},
{"value": "430000", "label": "湖南省"},
{"value": "440000", "label": "广东省"},
{"value": "450000", "label": "广西壮族自治区"},
{"value": "460000", "label": "海南省"},
{"value": "500000", "label": "重庆市"},
{"value": "510000", "label": "四川省"},
{"value": "520000", "label": "贵州省"},
{"value": "530000", "label": "云南省"},
{"value": "540000", "label": "西藏自治区"},
{"value": "610000", "label": "陕西省"},
{"value": "620000", "label": "甘肃省"},
{"value": "630000", "label": "青海省"},
{"value": "640000", "label": "宁夏回族自治区"},
{"value": "650000", "label": "新疆维吾尔自治区"},
{"value": "710000", "label": "台湾省"},
{"value": "810000", "label": "香港特别行政区"},
{"value": "820000", "label": "澳门特别行政区"}
]

View File

@ -0,0 +1,84 @@
package org.jeecg.modules.demo.test.controller;
import io.minio.MinioClient;
import org.apache.tomcat.util.http.fileupload.IOUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;
/**
* @Author scott
* @Date 2020/1/12 17:19
* @Description: Minio文件服务测试
*/
@RestController
@RequestMapping("/test/minio")
public class MinioController {
//minio服务的IP端口
private static String url = "http://111.225.222.176:9000";
private static String accessKey = "admin";
private static String secretKey = "jeecg1357";
private static String bucketName = "jeecgtest";
/**
* 上传文件到minio服务
*
* @param file
* @return
*/
@PostMapping("upload")
public String upload(@RequestParam("file") MultipartFile file) {
try {
MinioClient minioClient = new MinioClient(url, accessKey, secretKey);
InputStream is = file.getInputStream(); //得到文件流
String fileName = "/upload/img/" + file.getOriginalFilename(); //文件名
String contentType = file.getContentType(); //类型
minioClient.putObject(bucketName, fileName, is, contentType); //把文件放置Minio桶(文件夹)
return "上传成功";
} catch (Exception e) {
return "上传失败";
}
}
/**
* 下载minio服务的文件
*
* @param response
* @return
*/
@GetMapping("download")
public String download(HttpServletResponse response) {
try {
MinioClient minioClient = new MinioClient(url, accessKey, secretKey);
InputStream fileInputStream = minioClient.getObject(bucketName, "11.jpg");
response.setHeader("Content-Disposition", "attachment;filename=" + "11.jpg");
response.setContentType("application/force-download");
response.setCharacterEncoding("UTF-8");
IOUtils.copy(fileInputStream, response.getOutputStream());
return "下载完成";
} catch (Exception e) {
e.printStackTrace();
return "下载失败";
}
}
/**
* 获取minio文件的下载地址
*
* @return
*/
@GetMapping("url")
public String getUrl() {
try {
MinioClient minioClient = new MinioClient(url, accessKey, secretKey);
String url = minioClient.presignedGetObject(bucketName, "11.jpg");
return url;
} catch (Exception e) {
e.printStackTrace();
return "获取失败";
}
}
}

View File

@ -1,13 +1,15 @@
package org.jeecg.modules.message.handle.impl;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.message.handle.ISendMsgHandle;
@Slf4j
public class SmsSendMsgHandle implements ISendMsgHandle {
@Override
public void SendMsg(String es_receiver, String es_title, String es_content) {
// TODO Auto-generated method stub
System.out.println("发短信");
log.info("发短信");
}
}

View File

@ -1,13 +1,14 @@
package org.jeecg.modules.message.handle.impl;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.message.handle.ISendMsgHandle;
@Slf4j
public class WxSendMsgHandle implements ISendMsgHandle {
@Override
public void SendMsg(String es_receiver, String es_title, String es_content) {
// TODO Auto-generated method stub
System.out.println("发微信消息模板");
log.info("发微信消息模板");
}
}

View File

@ -1,6 +1,7 @@
package org.jeecg.modules.message.websocket;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.WebsocketConst;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
@ -21,24 +22,24 @@ public class TestController {
Result<String> result = new Result<String>();
String message = jsonObject.getString("message");
JSONObject obj = new JSONObject();
obj.put("cmd", "topic");
obj.put("msgId", "M0001");
obj.put("msgTxt", message);
obj.put(WebsocketConst.MSG_CMD, WebsocketConst.CMD_TOPIC);
obj.put(WebsocketConst.MSG_ID, "M0001");
obj.put(WebsocketConst.MSG_TXT, message);
webSocket.sendAllMessage(obj.toJSONString());
result.setResult("群发!");
return result;
}
@PostMapping("/sendUser")
public Result<String> sendUser(@RequestBody JSONObject jsonObject) {
Result<String> result = new Result<String>();
String userId = jsonObject.getString("userId");
String message = jsonObject.getString("message");
JSONObject obj = new JSONObject();
obj.put("cmd", "user");
obj.put("userId", userId);
obj.put("msgId", "M0001");
obj.put("msgTxt", message);
obj.put(WebsocketConst.MSG_CMD, WebsocketConst.CMD_USER);
obj.put(WebsocketConst.MSG_USER_ID, userId);
obj.put(WebsocketConst.MSG_ID, "M0001");
obj.put(WebsocketConst.MSG_TXT, message);
webSocket.sendOneMessage(userId, obj.toJSONString());
result.setResult("单发");
return result;

View File

@ -11,6 +11,7 @@ import javax.websocket.Session;
import javax.websocket.server.PathParam;
import javax.websocket.server.ServerEndpoint;
import org.jeecg.common.constant.WebsocketConst;
import org.springframework.stereotype.Component;
import com.alibaba.fastjson.JSONObject;
@ -57,8 +58,8 @@ public class WebSocket {
//todo 现在有个定时任务刷,应该去掉
log.debug("【websocket消息】收到客户端消息:"+message);
JSONObject obj = new JSONObject();
obj.put("cmd", "heartcheck");//业务类型
obj.put("msgTxt", "心跳响应");//消息内容
obj.put(WebsocketConst.MSG_CMD, WebsocketConst.CMD_CHECK);//业务类型
obj.put(WebsocketConst.MSG_TXT, "心跳响应");//消息内容
session.getAsyncRemote().sendText(obj.toJSONString());
}

View File

@ -1,6 +1,7 @@
package org.jeecg.modules.oss.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.common.util.CommonUtils;
import org.jeecg.common.util.oss.OssBootUtil;
import org.jeecg.modules.oss.entity.OSSFile;
import org.jeecg.modules.oss.mapper.OSSFileMapper;
@ -16,6 +17,7 @@ public class OSSFileServiceImpl extends ServiceImpl<OSSFileMapper, OSSFile> impl
@Override
public void upload(MultipartFile multipartFile) throws IOException {
String fileName = multipartFile.getOriginalFilename();
fileName = CommonUtils.getFileName(fileName);
OSSFile ossFile = new OSSFile();
ossFile.setFileName(fileName);
String url = OssBootUtil.upload(multipartFile,"upload/test");

View File

@ -1,6 +1,7 @@
package org.jeecg.modules.quartz.controller;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
@ -13,6 +14,7 @@ import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.util.ImportExcelUtil;
import org.jeecg.modules.quartz.entity.QuartzJob;
import org.jeecg.modules.quartz.service.IQuartzJobService;
import org.jeecgframework.poi.excel.ExcelImportUtil;
@ -235,9 +237,12 @@ public class QuartzJobController {
* @return
*/
@RequestMapping(value = "/importExcel", method = RequestMethod.POST)
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) throws IOException {
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
// 错误信息
List<String> errorMessage = new ArrayList<>();
int successLines = 0, errorLines = 0;
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
MultipartFile file = entity.getValue();// 获取上传文件对象
ImportParams params = new ImportParams();
@ -245,11 +250,10 @@ public class QuartzJobController {
params.setHeadRows(1);
params.setNeedSave(true);
try {
List<QuartzJob> listQuartzJobs = ExcelImportUtil.importExcel(file.getInputStream(), QuartzJob.class, params);
for (QuartzJob quartzJobExcel : listQuartzJobs) {
quartzJobService.save(quartzJobExcel);
}
return Result.ok("文件导入成功!数据行数:" + listQuartzJobs.size());
List<Object> listQuartzJobs = ExcelImportUtil.importExcel(file.getInputStream(), QuartzJob.class, params);
List<String> list = ImportExcelUtil.importDateSave(listQuartzJobs, IQuartzJobService.class, errorMessage,CommonConstant.SQL_INDEX_UNIQ_JOB_CLASS_NAME);
errorLines+=list.size();
successLines+=(listQuartzJobs.size()-errorLines);
} catch (Exception e) {
log.error(e.getMessage(), e);
return Result.error("文件导入失败!");
@ -261,6 +265,6 @@ public class QuartzJobController {
}
}
}
return Result.error("文件导入失败!");
return ImportExcelUtil.imporReturnRes(errorLines,successLines,errorMessage);
}
}

View File

@ -2,6 +2,7 @@ package org.jeecg.modules.quartz.entity;
import java.io.Serializable;
import org.jeecg.common.aspect.annotation.Dict;
import org.jeecgframework.poi.excel.annotation.Excel;
import org.springframework.format.annotation.DateTimeFormat;
@ -54,7 +55,8 @@ public class QuartzJob implements Serializable {
@Excel(name="描述",width=40)
private java.lang.String description;
/**状态 0正常 -1停止*/
@Excel(name="状态",width=15)
@Excel(name="状态",width=15,dicCode="quartz_status")
@Dict(dicCode = "quartz_status")
private java.lang.Integer status;
}

View File

@ -115,7 +115,7 @@ public class ShiroRealm extends AuthorizingRealm {
}
// 查询用户信息
log.info("———校验token是否有效————checkUserTokenIsEffect——————— "+ token);
log.debug("———校验token是否有效————checkUserTokenIsEffect——————— "+ token);
LoginUser loginUser = sysBaseAPI.getUserByName(username);
if (loginUser == null) {
throw new AuthenticationException("用户不存在!");

View File

@ -0,0 +1,141 @@
package org.jeecg.modules.shiro.authc.interceptor;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.OnlineAuth;
import org.jeecg.common.system.util.JwtUtil;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.system.entity.SysPermission;
import org.jeecg.modules.system.service.ISysPermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
/**
* Online 自定义请求拦截器
*
* @author: taoyan
* @date: 2020年03月20日
*/
@Slf4j
public class OnlineInterceptor implements HandlerInterceptor {
@Autowired
private ISysPermissionService sysPermissionService;
/**
* online表单菜单地址
*/
private static final String ONLINE_FORM = "/online/cgform";
/**
* online功能测试地址 前缀
*/
private static final String[] ONLINE_TEST_PRE = {"/online/cgformErpList", "/online/cgformList", "/online/cgformTreeList"};
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
// 请求的方法是否有注解
boolean anno = handler.getClass().isAssignableFrom(HandlerMethod.class);
if (anno) {
OnlineAuth onlineAuth = ((HandlerMethod) handler).getMethodAnnotation(OnlineAuth.class);
if (onlineAuth != null) {
String requestPath = request.getRequestURI().substring(request.getContextPath().length());
requestPath = filterUrl(requestPath);
//1.通过前端请求地址得到code
String authKey = onlineAuth.value();
String code = requestPath.substring(requestPath.lastIndexOf(authKey) + authKey.length());
log.info("拦截请求(" + request.getMethod() + ")" + requestPath + ",");
if ("form".equals(authKey) && "DELETE".equals(request.getMethod())) {
code = code.substring(0, code.lastIndexOf("/"));
}
List<String> possibleUrl = new ArrayList<>();
//获取可能的表单地址
for (String pre : ONLINE_TEST_PRE) {
possibleUrl.add(pre + code);
}
//查询菜单
LambdaQueryWrapper<SysPermission> query = new LambdaQueryWrapper<SysPermission>();
query.eq(SysPermission::getDelFlag, 0);
query.in(SysPermission::getUrl, possibleUrl);
List<SysPermission> permissionList = sysPermissionService.list(query);
String username = JwtUtil.getUserNameByToken(request);
if (permissionList == null || permissionList.size() == 0) {
//没有配置菜单 找online表单菜单地址
boolean hasPermission = sysPermissionService.hasPermission(username, ONLINE_FORM);
if (!hasPermission) {
backError(response, authKey);
return false;
}
} else {
//找到菜单了
boolean has = false;
for (SysPermission p : permissionList) {
has = has || sysPermissionService.hasPermission(username, p);
}
if (!has) {
backError(response, authKey);
return false;
}
}
}
}
return true;
}
/**
* 地址过滤
*
* @param requestPath
* @return
*/
private String filterUrl(String requestPath) {
String url = "";
if (oConvertUtils.isNotEmpty(requestPath)) {
url = requestPath.replace("\\", "/");
url = requestPath.replace("//", "/");
if (url.indexOf("//") >= 0) {
url = filterUrl(url);
}
}
return url;
}
/**
* 返回一个错误信息
*
* @param response
* @param authKey
*/
private void backError(HttpServletResponse response, String authKey) {
PrintWriter writer = null;
response.setCharacterEncoding("UTF-8");
response.setContentType("application/json; charset=utf-8");
response.setHeader("auth", "fail");
try {
writer = response.getWriter();
if ("exportXls".equals(authKey)) {
writer.print("");
} else {
Result<?> result = Result.error("无权限访问(操作)");
writer.print(JSON.toJSON(result));
}
} catch (IOException e) {
log.error(e.getMessage());
} finally {
if (writer != null) {
writer.close();
}
}
}
}

View File

@ -2,6 +2,6 @@ package org.jeecg.modules.shiro.vo;
public class DefContants {
public static String X_ACCESS_TOKEN = "X-Access-Token";
public final static String X_ACCESS_TOKEN = "X-Access-Token";
}

View File

@ -6,6 +6,7 @@ import java.util.Date;
import javax.servlet.http.HttpServletRequest;
import org.apache.shiro.SecurityUtils;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
@ -19,6 +20,7 @@ import org.jeecg.common.util.SpringContextUtils;
import org.jeecg.modules.system.entity.SysLog;
import org.jeecg.modules.system.service.ISysLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
import org.springframework.stereotype.Component;
import com.alibaba.fastjson.JSONObject;
@ -80,17 +82,11 @@ public class AutoLogAspect {
sysLog.setOperateType(getOperateType(methodName, syslog.operateType()));
}
//请求的参数
Object[] args = joinPoint.getArgs();
try{
String params = JSONObject.toJSONString(args);
sysLog.setRequestParam(params);
}catch (Exception e){
}
//获取request
HttpServletRequest request = SpringContextUtils.getHttpServletRequest();
//请求的参数
sysLog.setRequestParam(getReqestParams(request,joinPoint));
//设置IP地址
sysLog.setIp(IPUtils.getIpAddr(request));
@ -134,4 +130,35 @@ public class AutoLogAspect {
}
return CommonConstant.OPERATE_TYPE_1;
}
/**
* @Description: 获取请求参数
* @author: scott
* @date: 2020/4/16 0:10
* @param request: request
* @param joinPoint: joinPoint
* @Return: java.lang.String
*/
private String getReqestParams(HttpServletRequest request, JoinPoint joinPoint) {
String httpMethod = request.getMethod();
String params = "";
if ("POST".equals(httpMethod) || "PUT".equals(httpMethod) || "PATCH".equals(httpMethod)) {
Object[] paramsArray = joinPoint.getArgs();
params = JSONObject.toJSONString(paramsArray);
} else {
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
Method method = signature.getMethod();
// 请求的方法参数值
Object[] args = joinPoint.getArgs();
// 请求的方法参数名称
LocalVariableTableParameterNameDiscoverer u = new LocalVariableTableParameterNameDiscoverer();
String[] paramNames = u.getParameterNames(method);
if (args != null && paramNames != null) {
for (int i = 0; i < args.length; i++) {
params += " " + paramNames[i] + ": " + args[i];
}
}
}
return params;
}
}

View File

@ -125,7 +125,7 @@ public class DictAspect {
}
/**
* 翻译字典文本
* 翻译字典文本
* @param code
* @param text
* @param table
@ -145,6 +145,7 @@ public class DictAspect {
continue; //跳过循环
}
if (!StringUtils.isEmpty(table)){
log.debug("--DictAspect------dicTable="+ table+" ,dicText= "+text+" ,dicCode="+code);
tmpValue= dictService.queryTableDictTextByKey(table,text,code,k.trim());
}else {
tmpValue = dictService.queryDictTextByKey(code, k.trim());

View File

@ -90,7 +90,9 @@ public class PermissionDataAspect {
queryQserMatch.eq(SysPermission::getMenuType, 1);
queryQserMatch.eq(SysPermission::getDelFlag, 0);
queryQserMatch.eq(SysPermission::getUrl, userMatchUrl);
currentSyspermission = sysPermissionService.list(queryQserMatch);
if(oConvertUtils.isNotEmpty(userMatchUrl)){
currentSyspermission = sysPermissionService.list(queryQserMatch);
}
}
//3.未找到 再通过正则匹配获取菜单
if(currentSyspermission==null || currentSyspermission.size()==0) {

View File

@ -7,7 +7,11 @@ package org.jeecg.modules.system.aspect;
*/
public enum UrlMatchEnum {
CGFORM_DATA("/online/cgform/api/getData/", "/online/cgformList/"),
CGFORM_TREE_DATA("/online/cgform/api/getTreeData/", "/online/cgformList/");
CGFORM_EXCEL_DATA("/online/cgform/api/exportXls/", "/online/cgformList/"),
CGFORM_TREE_DATA("/online/cgform/api/getTreeData/", "/online/cgformList/"),
CGREPORT_DATA("/online/cgreport/api/getColumnsAndData/", "/online/cgreport/"),
CGREPORT_EXCEL_DATA("/online/cgreport/api/exportXls/", "/online/cgreport/");
UrlMatchEnum(String url, String match_url) {
this.url = url;

View File

@ -21,6 +21,7 @@ import org.jeecg.modules.system.entity.SysDepart;
import org.jeecg.modules.system.entity.SysUser;
import org.jeecg.modules.system.model.SysLoginModel;
import org.jeecg.modules.system.service.ISysDepartService;
import org.jeecg.modules.system.service.ISysDictService;
import org.jeecg.modules.system.service.ISysLogService;
import org.jeecg.modules.system.service.ISysUserService;
import org.jeecg.modules.system.util.RandImageUtil;
@ -50,7 +51,9 @@ public class LoginController {
private RedisUtil redisUtil;
@Autowired
private ISysDepartService sysDepartService;
@Autowired
private ISysDictService sysDictService;
private static final String BASE_CHECK_CODES = "qwertyuiplkjhgfdsazxcvbnmQWERTYUPLKJHGFDSAZXCVBNM1234567890";
@ApiOperation("登录接口")
@ -353,6 +356,7 @@ public class LoginController {
}
obj.put("token", token);
obj.put("userInfo", sysUser);
obj.put("sysAllDictItems", sysDictService.queryAllDictItems());
result.setResult(obj);
result.success("登录成功");
return result;
@ -371,39 +375,13 @@ public class LoginController {
result.setResult(map);
return result;
}
/**
* 获取校验码
*/
@ApiOperation("获取验证码")
@GetMapping(value = "/getCheckCode")
public Result<Map<String,String>> getCheckCode(){
Result<Map<String,String>> result = new Result<Map<String,String>>();
Map<String,String> map = new HashMap<String,String>();
try {
String code = RandomUtil.randomString(BASE_CHECK_CODES,4);
String key = MD5Util.MD5Encode(code+System.currentTimeMillis(), "utf-8");
redisUtil.set(key, code, 60);
map.put("key", key);
//update-begin-authortaoyan date:20200210 for:TASK #3391 【bug】安全问题返回验证码不安全
String encode = java.util.Base64.getEncoder().encodeToString(code.getBytes("UTF-8"));
map.put("code",encode);
//update-end-authortaoyan date:20200210 for:TASK #3391 【bug】安全问题返回验证码不安全
result.setResult(map);
result.setSuccess(true);
} catch (Exception e) {
e.printStackTrace();
result.setSuccess(false);
}
return result;
}
/**
* 后台生成图形验证码
* 后台生成图形验证码 :有效
* @param response
* @param key
*/
@ApiOperation("获取验证码2")
@ApiOperation("获取验证码")
@GetMapping(value = "/randomImage/{key}")
public Result<String> randomImage(HttpServletResponse response,@PathVariable String key){
Result<String> res = new Result<String>();
@ -479,4 +457,25 @@ public class LoginController {
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();
}
}

View File

@ -11,10 +11,12 @@ import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.constant.CommonSendStatus;
import org.jeecg.common.constant.WebsocketConst;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.system.util.JwtUtil;
import org.jeecg.common.system.vo.LoginUser;
@ -24,6 +26,7 @@ import org.jeecg.modules.system.entity.SysAnnouncement;
import org.jeecg.modules.system.entity.SysAnnouncementSend;
import org.jeecg.modules.system.service.ISysAnnouncementSendService;
import org.jeecg.modules.system.service.ISysAnnouncementService;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
@ -227,9 +230,9 @@ public class SysAnnouncementController {
result.success("该系统通知发布成功");
if(sysAnnouncement.getMsgType().equals(CommonConstant.MSG_TYPE_ALL)) {
JSONObject obj = new JSONObject();
obj.put("cmd", "topic");
obj.put("msgId", sysAnnouncement.getId());
obj.put("msgTxt", sysAnnouncement.getTitile());
obj.put(WebsocketConst.MSG_CMD, WebsocketConst.CMD_TOPIC);
obj.put(WebsocketConst.MSG_ID, sysAnnouncement.getId());
obj.put(WebsocketConst.MSG_TXT, sysAnnouncement.getTitile());
webSocket.sendAllMessage(obj.toJSONString());
}else {
// 2.插入用户通告阅读标记表记录
@ -238,9 +241,9 @@ public class SysAnnouncementController {
String anntId = sysAnnouncement.getId();
Date refDate = new Date();
JSONObject obj = new JSONObject();
obj.put("cmd", "user");
obj.put("msgId", sysAnnouncement.getId());
obj.put("msgTxt", sysAnnouncement.getTitile());
obj.put(WebsocketConst.MSG_CMD, WebsocketConst.CMD_USER);
obj.put(WebsocketConst.MSG_ID, sysAnnouncement.getId());
obj.put(WebsocketConst.MSG_TXT, sysAnnouncement.getTitile());
webSocket.sendMoreMessage(userIds, obj.toJSONString());
}
}
@ -274,7 +277,6 @@ public class SysAnnouncementController {
/**
* @功能:补充用户数据,并返回系统消息
* @param id
* @return
*/
@RequestMapping(value = "/listByUser", method = RequestMethod.GET)
@ -378,4 +380,42 @@ public class SysAnnouncementController {
}
return Result.error("文件导入失败!");
}
/**
*同步消息
* @param anntId
* @return
*/
@RequestMapping(value = "/syncNotic", method = RequestMethod.GET)
public Result<SysAnnouncement> syncNotic(@RequestParam(name="anntId",required=false) String anntId, HttpServletRequest request) {
Result<SysAnnouncement> result = new Result<SysAnnouncement>();
JSONObject obj = new JSONObject();
if(StringUtils.isNotBlank(anntId)){
SysAnnouncement sysAnnouncement = sysAnnouncementService.getById(anntId);
if(sysAnnouncement==null) {
result.error500("未找到对应实体");
}else {
if(sysAnnouncement.getMsgType().equals(CommonConstant.MSG_TYPE_ALL)) {
obj.put(WebsocketConst.MSG_CMD, WebsocketConst.CMD_TOPIC);
obj.put(WebsocketConst.MSG_ID, sysAnnouncement.getId());
obj.put(WebsocketConst.MSG_TXT, sysAnnouncement.getTitile());
webSocket.sendAllMessage(obj.toJSONString());
}else {
// 2.插入用户通告阅读标记表记录
String userId = sysAnnouncement.getUserIds();
if(oConvertUtils.isNotEmpty(userId)){
String[] userIds = userId.substring(0, (userId.length()-1)).split(",");
obj.put(WebsocketConst.MSG_CMD, WebsocketConst.CMD_USER);
obj.put(WebsocketConst.MSG_ID, sysAnnouncement.getId());
obj.put(WebsocketConst.MSG_TXT, sysAnnouncement.getTitile());
webSocket.sendMoreMessage(userIds, obj.toJSONString());
}
}
}
}else{
obj.put(WebsocketConst.MSG_CMD, WebsocketConst.CMD_TOPIC);
obj.put(WebsocketConst.MSG_TXT, "批量设置已读");
webSocket.sendAllMessage(obj.toJSONString());
}
return result;
}
}

View File

@ -189,7 +189,6 @@ public class SysCategoryController {
* 导出excel
*
* @param request
* @param response
*/
@RequestMapping(value = "/exportXls")
public ModelAndView exportXls(HttpServletRequest request, SysCategory sysCategory) {
@ -376,8 +375,8 @@ public class SysCategoryController {
result.setMessage("加载分类字典树参数有误.[null]!");
return result;
}else{
if(sysCategoryService.ROOT_PID_VALUE.equals(pcode)){
pid = sysCategoryService.ROOT_PID_VALUE;
if(ISysCategoryService.ROOT_PID_VALUE.equals(pcode)){
pid = ISysCategoryService.ROOT_PID_VALUE;
}else{
pid = this.sysCategoryService.queryIdByCode(pcode);
}
@ -452,5 +451,4 @@ public class SysCategoryController {
}

View File

@ -102,8 +102,9 @@ 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);
DataSourceCachePool.removeCacheById(sysDataSource.getId());
return Result.ok("编辑成功!");
}
@ -117,8 +118,9 @@ public class SysDataSourceController extends JeecgController<SysDataSource, ISys
@ApiOperation(value = "多数据源管理-通过id删除", notes = "多数据源管理-通过id删除")
@DeleteMapping(value = "/delete")
public Result<?> delete(@RequestParam(name = "id") String id) {
SysDataSource sysDataSource = sysDataSourceService.getById(id);
DataSourceCachePool.removeCache(sysDataSource.getCode());
sysDataSourceService.removeById(id);
DataSourceCachePool.removeCacheById(id);
return Result.ok("删除成功!");
}
@ -133,8 +135,11 @@ public class SysDataSourceController extends JeecgController<SysDataSource, ISys
@DeleteMapping(value = "/deleteBatch")
public Result<?> deleteBatch(@RequestParam(name = "ids") String ids) {
List<String> idList = Arrays.asList(ids.split(","));
idList.forEach(item->{
SysDataSource sysDataSource = sysDataSourceService.getById(item);
DataSourceCachePool.removeCache(sysDataSource.getCode());
});
this.sysDataSourceService.removeByIds(idList);
idList.forEach(DataSourceCachePool::removeCacheById);
return Result.ok("批量删除成功!");
}

View File

@ -1,15 +1,12 @@
package org.jeecg.modules.system.controller;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.jeecg.common.api.vo.Result;
@ -18,25 +15,25 @@ import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.system.util.JwtUtil;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.ImportExcelUtil;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.system.entity.SysDepart;
import org.jeecg.modules.system.model.DepartIdModel;
import org.jeecg.modules.system.model.SysDepartTreeModel;
import org.jeecg.modules.system.service.ISysDepartService;
import org.jeecg.modules.system.service.ISysPositionService;
import org.jeecg.modules.system.util.FindsDepartsChildrenUtil;
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.util.CollectionUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;
@ -59,7 +56,8 @@ public class SysDepartController {
@Autowired
private ISysDepartService sysDepartService;
@Autowired
public RedisTemplate<String, Object> redisTemplate;
/**
* 查询数据 查出我的部门,并以树结构数据格式响应给前端
*
@ -70,7 +68,7 @@ public class SysDepartController {
Result<List<SysDepartTreeModel>> result = new Result<>();
LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
try {
if(oConvertUtils.isNotEmpty(user.getIdentity()) && user.getIdentity() == CommonConstant.USER_IDENTITY_2 ){
if(oConvertUtils.isNotEmpty(user.getUserIdentity()) && user.getUserIdentity().equals( CommonConstant.USER_IDENTITY_2 )){
List<SysDepartTreeModel> list = sysDepartService.queryMyDeptTreeList(user.getDepartIds());
result.setResult(list);
result.setMessage(CommonConstant.USER_IDENTITY_2.toString());
@ -114,6 +112,7 @@ public class SysDepartController {
* @param sysDepart
* @return
*/
//@RequiresRoles({"admin"})
@RequestMapping(value = "/add", method = RequestMethod.POST)
@CacheEvict(value= {CacheConstant.SYS_DEPARTS_CACHE,CacheConstant.SYS_DEPART_IDS_CACHE}, allEntries=true)
public Result<SysDepart> add(@RequestBody SysDepart sysDepart, HttpServletRequest request) {
@ -139,6 +138,7 @@ public class SysDepartController {
* @param sysDepart
* @return
*/
//@RequiresRoles({"admin"})
@RequestMapping(value = "/edit", method = RequestMethod.PUT)
@CacheEvict(value= {CacheConstant.SYS_DEPARTS_CACHE,CacheConstant.SYS_DEPART_IDS_CACHE}, allEntries=true)
public Result<SysDepart> edit(@RequestBody SysDepart sysDepart, HttpServletRequest request) {
@ -166,6 +166,7 @@ public class SysDepartController {
* @param id
* @return
*/
//@RequiresRoles({"admin"})
@RequestMapping(value = "/delete", method = RequestMethod.DELETE)
@CacheEvict(value= {CacheConstant.SYS_DEPARTS_CACHE,CacheConstant.SYS_DEPART_IDS_CACHE}, allEntries=true)
public Result<SysDepart> delete(@RequestParam(name="id",required=true) String id) {
@ -193,6 +194,7 @@ public class SysDepartController {
* @param ids
* @return
*/
//@RequiresRoles({"admin"})
@RequestMapping(value = "/deleteBatch", method = RequestMethod.DELETE)
@CacheEvict(value= {CacheConstant.SYS_DEPARTS_CACHE,CacheConstant.SYS_DEPART_IDS_CACHE}, allEntries=true)
public Result<SysDepart> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
@ -253,9 +255,15 @@ public class SysDepartController {
* @return
*/
@RequestMapping(value = "/searchBy", method = RequestMethod.GET)
public Result<List<SysDepartTreeModel>> searchBy(@RequestParam(name = "keyWord", required = true) String keyWord) {
public Result<List<SysDepartTreeModel>> searchBy(@RequestParam(name = "keyWord", required = true) String keyWord,@RequestParam(name = "myDeptSearch", required = false) String myDeptSearch) {
Result<List<SysDepartTreeModel>> result = new Result<List<SysDepartTreeModel>>();
List<SysDepartTreeModel> treeList = this.sysDepartService.searhBy(keyWord);
//部门查询myDeptSearch为1时为我的部门查询登录用户为上级时查只查负责部门下数据
LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
String departIds = null;
if(oConvertUtils.isNotEmpty(user.getUserIdentity()) && user.getUserIdentity().equals( CommonConstant.USER_IDENTITY_2 )){
departIds = user.getDepartIds();
}
List<SysDepartTreeModel> treeList = this.sysDepartService.searhBy(keyWord,myDeptSearch,departIds);
if (treeList == null || treeList.size() == 0) {
result.setSuccess(false);
result.setMessage("未查询匹配数据!");
@ -301,10 +309,13 @@ public class SysDepartController {
* @param response
* @return
*/
//@RequiresRoles({"admin"})
@RequestMapping(value = "/importExcel", method = RequestMethod.POST)
@CacheEvict(value= {CacheConstant.SYS_DEPARTS_CACHE,CacheConstant.SYS_DEPART_IDS_CACHE}, allEntries=true)
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
List<String> errorMessageList = new ArrayList<>();
List<SysDepart> listSysDeparts = null;
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
MultipartFile file = entity.getValue();// 获取上传文件对象
@ -315,7 +326,7 @@ public class SysDepartController {
try {
// orgCode编码长度
int codeLength = 3;
List<SysDepart> listSysDeparts = ExcelImportUtil.importExcel(file.getInputStream(), SysDepart.class, params);
listSysDeparts = ExcelImportUtil.importExcel(file.getInputStream(), SysDepart.class, params);
//按长度排序
Collections.sort(listSysDeparts, new Comparator<SysDepart>() {
@Override
@ -323,6 +334,8 @@ public class SysDepartController {
return arg0.getOrgCode().length() - arg1.getOrgCode().length();
}
});
int num = 0;
for (SysDepart sysDepart : listSysDeparts) {
String orgCode = sysDepart.getOrgCode();
if(orgCode.length() > codeLength) {
@ -342,9 +355,16 @@ public class SysDepartController {
}else{
sysDepart.setParentId("");
}
sysDepartService.save(sysDepart);
sysDepart.setDelFlag(CommonConstant.DEL_FLAG_0.toString());
ImportExcelUtil.importDateSaveOne(sysDepart, ISysDepartService.class, errorMessageList, num, CommonConstant.SQL_INDEX_UNIQ_DEPART_ORG_CODE);
num++;
}
return Result.ok("文件导入成功!数据行数:" + listSysDeparts.size());
//清空部门缓存
Set keys3 = redisTemplate.keys(CacheConstant.SYS_DEPARTS_CACHE + "*");
Set keys4 = redisTemplate.keys(CacheConstant.SYS_DEPART_IDS_CACHE + "*");
redisTemplate.delete(keys3);
redisTemplate.delete(keys4);
return ImportExcelUtil.imporReturnRes(errorMessageList.size(), listSysDeparts.size() - errorMessageList.size(), errorMessageList);
} catch (Exception e) {
log.error(e.getMessage(),e);
return Result.error("文件导入失败:"+e.getMessage());
@ -358,4 +378,24 @@ public class SysDepartController {
}
return Result.error("文件导入失败!");
}
/**
* 查询所有部门信息
* @return
*/
@GetMapping("listAll")
public Result<List<SysDepart>> listAll(@RequestParam(name = "id", required = false) String id) {
Result<List<SysDepart>> result = new Result<>();
LambdaQueryWrapper<SysDepart> query = new LambdaQueryWrapper<SysDepart>();
query.orderByAsc(SysDepart::getOrgCode);
if(oConvertUtils.isNotEmpty(id)){
String arr[] = id.split(",");
query.in(SysDepart::getId,arr);
}
List<SysDepart> ls = this.sysDepartService.list(query);
result.setSuccess(true);
result.setResult(ls);
return result;
}
}

View File

@ -65,7 +65,6 @@ public class SysDepartPermissionController extends JeecgController<SysDepartPerm
* @param req
* @return
*/
@AutoLog(value = "部门权限表-分页列表查询")
@ApiOperation(value="部门权限表-分页列表查询", notes="部门权限表-分页列表查询")
@GetMapping(value = "/list")
public Result<?> queryPageList(SysDepartPermission sysDepartPermission,
@ -84,7 +83,6 @@ public class SysDepartPermissionController extends JeecgController<SysDepartPerm
* @param sysDepartPermission
* @return
*/
@AutoLog(value = "部门权限表-添加")
@ApiOperation(value="部门权限表-添加", notes="部门权限表-添加")
@PostMapping(value = "/add")
public Result<?> add(@RequestBody SysDepartPermission sysDepartPermission) {
@ -98,7 +96,6 @@ public class SysDepartPermissionController extends JeecgController<SysDepartPerm
* @param sysDepartPermission
* @return
*/
@AutoLog(value = "部门权限表-编辑")
@ApiOperation(value="部门权限表-编辑", notes="部门权限表-编辑")
@PutMapping(value = "/edit")
public Result<?> edit(@RequestBody SysDepartPermission sysDepartPermission) {
@ -112,7 +109,6 @@ public class SysDepartPermissionController extends JeecgController<SysDepartPerm
* @param id
* @return
*/
@AutoLog(value = "部门权限表-通过id删除")
@ApiOperation(value="部门权限表-通过id删除", notes="部门权限表-通过id删除")
@DeleteMapping(value = "/delete")
public Result<?> delete(@RequestParam(name="id",required=true) String id) {
@ -126,7 +122,6 @@ public class SysDepartPermissionController extends JeecgController<SysDepartPerm
* @param ids
* @return
*/
@AutoLog(value = "部门权限表-批量删除")
@ApiOperation(value="部门权限表-批量删除", notes="部门权限表-批量删除")
@DeleteMapping(value = "/deleteBatch")
public Result<?> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
@ -140,7 +135,6 @@ public class SysDepartPermissionController extends JeecgController<SysDepartPerm
* @param id
* @return
*/
@AutoLog(value = "部门权限表-通过id查询")
@ApiOperation(value="部门权限表-通过id查询", notes="部门权限表-通过id查询")
@GetMapping(value = "/queryById")
public Result<?> queryById(@RequestParam(name="id",required=true) String id) {

View File

@ -7,16 +7,14 @@ import javax.servlet.http.HttpServletResponse;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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.query.QueryGenerator;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.system.entity.SysDepartRole;
import org.jeecg.modules.system.entity.SysDepartRolePermission;
import org.jeecg.modules.system.entity.SysDepartRoleUser;
import org.jeecg.modules.system.entity.SysPermissionDataRule;
import org.jeecg.modules.system.entity.*;
import org.jeecg.modules.system.service.*;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
@ -65,7 +63,6 @@ public class SysDepartRoleController extends JeecgController<SysDepartRole, ISys
* @param req
* @return
*/
@AutoLog(value = "部门角色-分页列表查询")
@ApiOperation(value="部门角色-分页列表查询", notes="部门角色-分页列表查询")
@GetMapping(value = "/list")
public Result<?> queryPageList(SysDepartRole sysDepartRole,
@ -77,16 +74,19 @@ public class SysDepartRoleController extends JeecgController<SysDepartRole, ISys
Page<SysDepartRole> page = new Page<SysDepartRole>(pageNo, pageSize);
LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
List<String> deptIds = null;
if(oConvertUtils.isEmpty(deptId)){
if(oConvertUtils.isNotEmpty(user.getIdentity()) && user.getIdentity() == CommonConstant.USER_IDENTITY_2 ){
deptIds = sysDepartService.getMySubDepIdsByDepId(user.getDepartIds());
}else{
return Result.ok(null);
}
}else{
deptIds = sysDepartService.getSubDepIdsByDepId(deptId);
}
queryWrapper.in("depart_id",deptIds);
// if(oConvertUtils.isEmpty(deptId)){
// if(oConvertUtils.isNotEmpty(user.getUserIdentity()) && user.getUserIdentity().equals(CommonConstant.USER_IDENTITY_2) ){
// deptIds = sysDepartService.getMySubDepIdsByDepId(user.getDepartIds());
// }else{
// return Result.ok(null);
// }
// }else{
// deptIds = sysDepartService.getSubDepIdsByDepId(deptId);
// }
// queryWrapper.in("depart_id",deptIds);
//我的部门,选中部门只能看当前部门下的角色
queryWrapper.eq("depart_id",deptId);
IPage<SysDepartRole> pageList = sysDepartRoleService.page(page, queryWrapper);
return Result.ok(pageList);
}
@ -97,7 +97,7 @@ public class SysDepartRoleController extends JeecgController<SysDepartRole, ISys
* @param sysDepartRole
* @return
*/
@AutoLog(value = "部门角色-添加")
//@RequiresRoles({"admin"})
@ApiOperation(value="部门角色-添加", notes="部门角色-添加")
@PostMapping(value = "/add")
public Result<?> add(@RequestBody SysDepartRole sysDepartRole) {
@ -111,7 +111,7 @@ public class SysDepartRoleController extends JeecgController<SysDepartRole, ISys
* @param sysDepartRole
* @return
*/
@AutoLog(value = "部门角色-编辑")
//@RequiresRoles({"admin"})
@ApiOperation(value="部门角色-编辑", notes="部门角色-编辑")
@PutMapping(value = "/edit")
public Result<?> edit(@RequestBody SysDepartRole sysDepartRole) {
@ -125,6 +125,7 @@ public class SysDepartRoleController extends JeecgController<SysDepartRole, ISys
* @param id
* @return
*/
//@RequiresRoles({"admin"})
@AutoLog(value = "部门角色-通过id删除")
@ApiOperation(value="部门角色-通过id删除", notes="部门角色-通过id删除")
@DeleteMapping(value = "/delete")
@ -139,6 +140,7 @@ public class SysDepartRoleController extends JeecgController<SysDepartRole, ISys
* @param ids
* @return
*/
//@RequiresRoles({"admin"})
@AutoLog(value = "部门角色-批量删除")
@ApiOperation(value="部门角色-批量删除", notes="部门角色-批量删除")
@DeleteMapping(value = "/deleteBatch")
@ -153,7 +155,6 @@ public class SysDepartRoleController extends JeecgController<SysDepartRole, ISys
* @param id
* @return
*/
@AutoLog(value = "部门角色-通过id查询")
@ApiOperation(value="部门角色-通过id查询", notes="部门角色-通过id查询")
@GetMapping(value = "/queryById")
public Result<?> queryById(@RequestParam(name="id",required=true) String id) {
@ -167,9 +168,11 @@ public class SysDepartRoleController extends JeecgController<SysDepartRole, ISys
* @return
*/
@RequestMapping(value = "/getDeptRoleList", method = RequestMethod.GET)
public Result<List<SysDepartRole>> getDeptRoleList(@RequestParam(value = "departId") String departId){
public Result<List<SysDepartRole>> getDeptRoleList(@RequestParam(value = "departId") String departId,@RequestParam(value = "userId") String userId){
Result<List<SysDepartRole>> result = new Result<>();
List<SysDepartRole> deptRoleList = sysDepartRoleService.list(new QueryWrapper<SysDepartRole>().eq("depart_id",departId));
//查询管理部门下,用户所在部门的所有角色
SysDepart depart = sysDepartService.getById(departId);
List<SysDepartRole> deptRoleList = sysDepartRoleService.queryDeptRoleByDeptAndUser(depart.getOrgCode(),userId);
result.setSuccess(true);
result.setResult(deptRoleList);
return result;

View File

@ -1,22 +1,29 @@
package org.jeecg.modules.system.controller;
import java.io.InputStream;
import java.util.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import cn.hutool.crypto.SecureUtil;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.CacheConstant;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.exception.JeecgBootException;
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.ImportExcelUtil;
import org.jeecg.common.util.RedisUtil;
import org.jeecg.common.util.SqlInjectionUtil;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.shiro.vo.DefContants;
import org.jeecg.modules.system.entity.SysDict;
import org.jeecg.modules.system.entity.SysDictItem;
import org.jeecg.modules.system.model.SysDictTree;
@ -33,12 +40,7 @@ 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.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;
@ -125,7 +127,7 @@ public class SysDictController {
* @return
*/
@RequestMapping(value = "/getDictItems/{dictCode}", method = RequestMethod.GET)
public Result<List<DictModel>> getDictItems(@PathVariable String dictCode) {
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;
@ -169,13 +171,25 @@ public class SysDictController {
return result;
}
/**
* 获取全部字典数据
*
* @return
*/
@RequestMapping(value = "/queryAllDictItems", method = RequestMethod.GET)
public Result<?> queryAllDictItems(HttpServletRequest request) {
Map<String, List<DictModel>> res = new HashMap<String, List<DictModel>>();
res = sysDictService.queryAllDictItems();
return Result.ok(res);
}
/**
* 获取字典数据
* @param dictCode
* @return
*/
@RequestMapping(value = "/getDictText/{dictCode}/{key}", method = RequestMethod.GET)
public Result<String> getDictItems(@PathVariable("dictCode") String dictCode, @PathVariable("key") String key) {
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;
@ -191,11 +205,121 @@ public class SysDictController {
return result;
}
/**
* 大数据量的字典表 走异步加载 即前端输入内容过滤数据
* @param dictCode
* @return
*/
@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,HttpServletRequest request) {
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;
}
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 返回
*/
@RequestMapping(value = "/loadDictItem/{dictCode}", method = RequestMethod.GET)
public Result<List<String>> loadDictItem(@PathVariable String dictCode,@RequestParam(name="key") String key, @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], key.split(","));
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 加载树形数据
*/
@SuppressWarnings("unchecked")
@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") String hasChildField,
@RequestParam(name="condition") String condition,
@RequestParam(value = "sign",required = false) String sign,HttpServletRequest request) {
Result<List<TreeSelectModel>> result = new Result<List<TreeSelectModel>>();
Map<String, String> query = null;
if(oConvertUtils.isNotEmpty(condition)) {
query = JSON.parseObject(condition, Map.class);
}
// SQL注入漏洞 sign签名校验(表名,label字段,val字段,条件)
String dictCode = tbname+","+text+","+code+","+condition;
List<TreeSelectModel> ls = sysDictService.queryTreeList(query,tbname, text, code, pidField, pid,hasChildField);
result.setSuccess(true);
result.setResult(ls);
return result;
}
/**
* 【APP接口】根据字典配置查询表字典数据
* @param query
* @param pageNo
* @param pageSize
* @return
*/
@GetMapping("/queryTableData")
public Result<List<DictModel>> queryTableData(DictQuery query,
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
@RequestParam(value = "sign",required = false) String sign,HttpServletRequest request){
Result<List<DictModel>> res = new Result<List<DictModel>>();
// SQL注入漏洞 sign签名校验
String dictCode = query.getTable()+","+query.getText()+","+query.getCode();
List<DictModel> ls = this.sysDictService.queryDictTablePageList(query,pageSize,pageNo);
res.setResult(ls);
res.setSuccess(true);
return res;
}
/**
* @功能:新增
* @param sysDict
* @return
*/
//@RequiresRoles({"admin"})
@RequestMapping(value = "/add", method = RequestMethod.POST)
public Result<SysDict> add(@RequestBody SysDict sysDict) {
Result<SysDict> result = new Result<SysDict>();
@ -216,6 +340,7 @@ public class SysDictController {
* @param sysDict
* @return
*/
//@RequiresRoles({"admin"})
@RequestMapping(value = "/edit", method = RequestMethod.PUT)
public Result<SysDict> edit(@RequestBody SysDict sysDict) {
Result<SysDict> result = new Result<SysDict>();
@ -237,6 +362,7 @@ public class SysDictController {
* @param id
* @return
*/
//@RequiresRoles({"admin"})
@RequestMapping(value = "/delete", method = RequestMethod.DELETE)
@CacheEvict(value=CacheConstant.SYS_DICT_CACHE, allEntries=true)
public Result<SysDict> delete(@RequestParam(name="id",required=true) String id) {
@ -255,6 +381,7 @@ public class SysDictController {
* @param ids
* @return
*/
//@RequiresRoles({"admin"})
@RequestMapping(value = "/deleteBatch", method = RequestMethod.DELETE)
@CacheEvict(value= CacheConstant.SYS_DICT_CACHE, allEntries=true)
public Result<SysDict> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
@ -331,7 +458,7 @@ public class SysDictController {
*/
@RequestMapping(value = "/importExcel", method = RequestMethod.POST)
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
MultipartFile file = entity.getValue();// 获取上传文件对象
@ -341,15 +468,29 @@ public class SysDictController {
params.setNeedSave(true);
try {
List<SysDictPage> list = ExcelImportUtil.importExcel(file.getInputStream(), SysDictPage.class, params);
for (SysDictPage page : list) {
// 错误信息
List<String> errorMessage = new ArrayList<>();
int successLines = 0, errorLines = 0;
for (int i=0;i< list.size();i++) {
SysDict po = new SysDict();
BeanUtils.copyProperties(page, po);
if(page.getDelFlag()==null){
po.setDelFlag(1);
}
sysDictService.saveMain(po, page.getSysDictItemList());
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 Result.ok("文件导入成功!");
return ImportExcelUtil.imporReturnRes(errorLines,successLines,errorMessage);
} catch (Exception e) {
log.error(e.getMessage(),e);
return Result.error("文件导入失败:"+e.getMessage());
@ -364,91 +505,6 @@ public class SysDictController {
return Result.error("文件导入失败!");
}
/**
* 大数据量的字典表 走异步加载 即前端输入内容过滤数据
* @param dictCode
* @return
*/
@RequestMapping(value = "/loadDict/{dictCode}", method = RequestMethod.GET)
public Result<List<DictModel>> loadDict(@PathVariable String dictCode,@RequestParam(name="keyword") String keyword) {
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;
}
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 返回
*/
@RequestMapping(value = "/loadDictItem/{dictCode}", method = RequestMethod.GET)
public Result<List<String>> loadDictItem(@PathVariable String dictCode,@RequestParam(name="key") String key) {
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], key.split(","));
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 加载树形数据
*/
@SuppressWarnings("unchecked")
@RequestMapping(value = "/loadTreeData", method = RequestMethod.GET)
public Result<List<TreeSelectModel>> loadDict(@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") String hasChildField,
@RequestParam(name="condition") String condition) {
Result<List<TreeSelectModel>> result = new Result<List<TreeSelectModel>>();
Map<String, String> query = null;
if(oConvertUtils.isNotEmpty(condition)) {
query = JSON.parseObject(condition, Map.class);
}
List<TreeSelectModel> ls = sysDictService.queryTreeList(query,tbname, text, code, pidField, pid,hasChildField);
result.setSuccess(true);
result.setResult(ls);
return result;
}
/**
* 查询被删除的列表

View File

@ -6,6 +6,7 @@ import java.util.Date;
import javax.servlet.http.HttpServletRequest;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.CacheConstant;
import org.jeecg.common.system.query.QueryGenerator;
@ -65,7 +66,6 @@ public class SysDictItemController {
/**
* @功能:新增
* @param sysDict
* @return
*/
@RequestMapping(value = "/add", method = RequestMethod.POST)

View File

@ -5,12 +5,10 @@ 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;
@ -18,7 +16,6 @@ import org.jeecg.modules.system.entity.SysPermission;
import org.jeecg.modules.system.entity.SysPermissionDataRule;
import org.jeecg.modules.system.entity.SysRolePermission;
import org.jeecg.modules.system.model.SysPermissionTree;
import org.jeecg.modules.system.model.SysRoleDeisgnModel;
import org.jeecg.modules.system.model.TreeModel;
import org.jeecg.modules.system.service.*;
import org.jeecg.modules.system.util.PermissionDataUtil;
@ -231,9 +228,9 @@ public class SysPermissionController {
this.getAllAuthJsonArray(allauthjsonArray, allAuthList);
//路由菜单
json.put("menu", menujsonArray);
//按钮权限
//按钮权限(用户拥有的权限集合)
json.put("auth", authjsonArray);
//全部权限配置(按钮权限,访问权限)
//全部权限配置集合(按钮权限,访问权限)
json.put("allAuth", allauthjsonArray);
result.setResult(json);
result.success("查询成功");
@ -295,7 +292,6 @@ public class SysPermissionController {
Result<SysPermission> result = new Result<>();
try {
sysPermissionService.deletePermission(id);
sysPermissionService.deletePermRuleByPermId(id);
result.success("删除成功!");
} catch (Exception e) {
log.error(e.getMessage(), e);

View File

@ -7,10 +7,14 @@ 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.poi.ss.formula.functions.T;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.util.ImportExcelUtil;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.quartz.service.IQuartzJobService;
import org.jeecg.modules.system.entity.SysPosition;
import org.jeecg.modules.system.service.ISysPositionService;
import org.jeecgframework.poi.excel.ExcelImportUtil;
@ -29,6 +33,7 @@ import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
@ -219,9 +224,12 @@ public class SysPositionController {
* @return
*/
@RequestMapping(value = "/importExcel", method = RequestMethod.POST)
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response)throws IOException {
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
// 错误信息
List<String> errorMessage = new ArrayList<>();
int successLines = 0, errorLines = 0;
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
MultipartFile file = entity.getValue();// 获取上传文件对象
ImportParams params = new ImportParams();
@ -229,9 +237,10 @@ public class SysPositionController {
params.setHeadRows(1);
params.setNeedSave(true);
try {
List<SysPosition> listSysPositions = ExcelImportUtil.importExcel(file.getInputStream(), SysPosition.class, params);
sysPositionService.saveBatch(listSysPositions);
return Result.ok("文件导入成功!数据行数:" + listSysPositions.size());
List<Object> listSysPositions = ExcelImportUtil.importExcel(file.getInputStream(), SysPosition.class, params);
List<String> list = ImportExcelUtil.importDateSave(listSysPositions, ISysPositionService.class, errorMessage,CommonConstant.SQL_INDEX_UNIQ_CODE);
errorLines+=list.size();
successLines+=(listSysPositions.size()-errorLines);
} catch (Exception e) {
log.error(e.getMessage(), e);
return Result.error("文件导入失败:" + e.getMessage());
@ -243,7 +252,7 @@ public class SysPositionController {
}
}
}
return Result.ok("文件导入失败!");
return ImportExcelUtil.imporReturnRes(errorLines,successLines,errorMessage);
}
}

View File

@ -109,6 +109,7 @@ public class SysRoleController {
* @return
*/
@RequestMapping(value = "/add", method = RequestMethod.POST)
//@RequiresRoles({"admin"})
public Result<SysRole> add(@RequestBody SysRole role) {
Result<SysRole> result = new Result<SysRole>();
try {
@ -127,6 +128,7 @@ public class SysRoleController {
* @param role
* @return
*/
//@RequiresRoles({"admin"})
@RequestMapping(value = "/edit", method = RequestMethod.PUT)
public Result<SysRole> edit(@RequestBody SysRole role) {
Result<SysRole> result = new Result<SysRole>();
@ -150,6 +152,7 @@ public class SysRoleController {
* @param id
* @return
*/
//@RequiresRoles({"admin"})
@RequestMapping(value = "/delete", method = RequestMethod.DELETE)
public Result<?> delete(@RequestParam(name="id",required=true) String id) {
sysRoleService.deleteRole(id);
@ -161,6 +164,7 @@ public class SysRoleController {
* @param ids
* @return
*/
//@RequiresRoles({"admin"})
@RequestMapping(value = "/deleteBatch", method = RequestMethod.DELETE)
public Result<SysRole> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
Result<SysRole> result = new Result<SysRole>();

View File

@ -2,10 +2,11 @@ package org.jeecg.modules.system.controller;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.util.CommonUtils;
import org.jeecg.common.util.MinioUtil;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.oss.entity.OSSFile;
import org.jeecg.modules.oss.service.IOSSFileService;
import org.jeecg.modules.system.util.MinioUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@ -39,6 +40,7 @@ public class SysUploadController {
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
MultipartFile file = multipartRequest.getFile("file");// 获取上传文件对象
String orgName = file.getOriginalFilename();// 获取文件名
orgName = CommonUtils.getFileName(orgName);
String file_url = MinioUtil.upload(file,bizPath);
//保存文件信息
OSSFile minioFile = new OSSFile();

View File

@ -23,6 +23,7 @@ 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.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
@ -57,6 +58,9 @@ import lombok.extern.slf4j.Slf4j;
public class SysUserAgentController {
@Autowired
private ISysUserAgentService sysUserAgentService;
@Value("${jeecg.path.upload}")
private String upLoadPath;
/**
* 分页列表查询
@ -199,8 +203,8 @@ public class SysUserAgentController {
/**
* 导出excel
*
* @param sysUserAgent
* @param request
* @param response
*/
@RequestMapping(value = "/exportXls")
public ModelAndView exportXls(SysUserAgent sysUserAgent,HttpServletRequest request) {
@ -213,7 +217,9 @@ public class SysUserAgentController {
mv.addObject(NormalExcelConstants.FILE_NAME, "用户代理人设置列表");
mv.addObject(NormalExcelConstants.CLASS, SysUserAgent.class);
LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("用户代理人设置列表数据", "导出人:"+user.getRealname(), "导出信息"));
ExportParams exportParams = new ExportParams("用户代理人设置列表数据", "导出人:"+user.getRealname(), "导出信息");
exportParams.setImageBasePath(upLoadPath);
mv.addObject(NormalExcelConstants.PARAMS, exportParams);
mv.addObject(NormalExcelConstants.DATA_LIST, pageList);
return mv;
}

View File

@ -16,24 +16,20 @@ import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.PermissionData;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.system.api.ISysBaseAPI;
import org.jeecg.common.system.query.QueryGenerator;
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.PmsUtil;
import org.jeecg.common.util.RedisUtil;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.system.entity.SysDepart;
import org.jeecg.modules.system.entity.SysUser;
import org.jeecg.modules.system.entity.SysUserDepart;
import org.jeecg.modules.system.entity.SysUserRole;
import org.jeecg.modules.system.entity.*;
import org.jeecg.modules.system.model.DepartIdModel;
import org.jeecg.modules.system.model.SysUserSysDepartModel;
import org.jeecg.modules.system.service.ISysDepartService;
import org.jeecg.modules.system.service.ISysUserDepartService;
import org.jeecg.modules.system.service.ISysUserRoleService;
import org.jeecg.modules.system.service.ISysUserService;
import org.jeecg.modules.system.service.*;
import org.jeecg.modules.system.vo.SysDepartUsersVO;
import org.jeecg.modules.system.vo.SysUserRoleVO;
import org.jeecgframework.poi.excel.ExcelImportUtil;
@ -42,6 +38,7 @@ 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.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
@ -49,6 +46,7 @@ import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;
@ -83,14 +81,34 @@ public class SysUserController {
@Autowired
private ISysUserRoleService userRoleService;
@Autowired
private ISysDepartRoleUserService departRoleUserService;
@Autowired
private ISysDepartRoleService departRoleService;
@Autowired
private RedisUtil redisUtil;
@Value("${jeecg.path.upload}")
private String upLoadPath;
/**
* 获取用户列表数据
* @param user
* @param pageNo
* @param pageSize
* @param req
* @return
*/
@PermissionData(pageComponent = "system/UserList")
@RequestMapping(value = "/list", method = RequestMethod.GET)
public Result<IPage<SysUser>> queryPageList(SysUser user,@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize,HttpServletRequest req) {
Result<IPage<SysUser>> result = new Result<IPage<SysUser>>();
QueryWrapper<SysUser> queryWrapper = QueryGenerator.initQueryWrapper(user, req.getParameterMap());
//TODO 外部模拟登陆临时账号,列表不显示
queryWrapper.ne("username","_reserve_user_external");
Page<SysUser> page = new Page<SysUser>(pageNo, pageSize);
IPage<SysUser> pageList = sysUserService.page(page, queryWrapper);
@ -125,7 +143,7 @@ public class SysUserController {
String passwordEncode = PasswordUtil.encrypt(user.getUsername(), user.getPassword(), salt);
user.setPassword(passwordEncode);
user.setStatus(1);
user.setDelFlag("0");
user.setDelFlag(CommonConstant.DEL_FLAG_0);
sysUserService.addUserWithRole(user, selectedRoles);
sysUserService.addUserWithDepart(user, selectedDeparts);
result.success("添加成功!");
@ -137,6 +155,7 @@ public class SysUserController {
}
@RequestMapping(value = "/edit", method = RequestMethod.PUT)
//@RequiresRoles({"admin"})
//@RequiresPermissions("user:edit")
public Result<SysUser> edit(@RequestBody JSONObject jsonObject) {
Result<SysUser> result = new Result<SysUser>();
@ -154,6 +173,7 @@ public class SysUserController {
String departs = jsonObject.getString("selecteddeparts");
sysUserService.editUserWithRole(user, roles);
sysUserService.editUserWithDepart(user, departs);
sysUserService.updateNullPhoneEmail();
result.success("修改成功!");
}
} catch (Exception e) {
@ -166,6 +186,7 @@ public class SysUserController {
/**
* 删除用户
*/
//@RequiresRoles({"admin"})
@RequestMapping(value = "/delete", method = RequestMethod.DELETE)
public Result<?> delete(@RequestParam(name="id",required=true) String id) {
sysBaseAPI.addLog("删除用户id " +id ,CommonConstant.LOG_TYPE_2, 3);
@ -176,6 +197,7 @@ public class SysUserController {
/**
* 批量删除用户
*/
//@RequiresRoles({"admin"})
@RequestMapping(value = "/deleteBatch", method = RequestMethod.DELETE)
public Result<?> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
sysBaseAPI.addLog("批量删除用户, ids " +ids ,CommonConstant.LOG_TYPE_2, 3);
@ -188,6 +210,7 @@ public class SysUserController {
* @param jsonObject
* @return
*/
//@RequiresRoles({"admin"})
@RequestMapping(value = "/frozenBatch", method = RequestMethod.PUT)
public Result<SysUser> frozenBatch(@RequestBody JSONObject jsonObject) {
Result<SysUser> result = new Result<SysUser>();
@ -274,7 +297,7 @@ public class SysUserController {
/**
* 修改密码
*/
@RequiresRoles({"admin"})
//@RequiresRoles({"admin"})
@RequestMapping(value = "/changePassword", method = RequestMethod.PUT)
public Result<?> changePassword(@RequestBody SysUser sysUser) {
SysUser u = this.sysUserService.getOne(new LambdaQueryWrapper<SysUser>().eq(SysUser::getUsername, sysUser.getUsername()));
@ -336,11 +359,11 @@ public class SysUserController {
* @return
*/
@RequestMapping(value = "/queryUserByDepId", method = RequestMethod.GET)
public Result<List<SysUser>> queryUserByDepId(@RequestParam(name = "id", required = true) String id) {
public Result<List<SysUser>> queryUserByDepId(@RequestParam(name = "id", required = true) String id,@RequestParam(name="realname",required=false) String realname) {
Result<List<SysUser>> result = new Result<>();
//List<SysUser> userList = sysUserDepartService.queryUserByDepId(id);
SysDepart sysDepart = sysDepartService.getById(id);
List<SysUser> userList = sysUserDepartService.queryUserByDepCode(sysDepart.getOrgCode());
List<SysUser> userList = sysUserDepartService.queryUserByDepCode(sysDepart.getOrgCode(),realname);
//批量查询用户的所属部门
//step.1 先拿到全部的 useids
@ -365,20 +388,6 @@ public class SysUserController {
}
}
/**
* 查询所有用户所对应的角色信息
*
* @return
*/
@RequestMapping(value = "/queryUserRoleMap", method = RequestMethod.GET)
public Result<Map<String, String>> queryUserRole() {
Result<Map<String, String>> result = new Result<>();
Map<String, String> map = userRoleService.queryUserRole();
result.setResult(map);
result.setSuccess(true);
return result;
}
/**
* 导出excel
*
@ -403,7 +412,9 @@ public class SysUserController {
mv.addObject(NormalExcelConstants.FILE_NAME, "用户列表");
mv.addObject(NormalExcelConstants.CLASS, SysUser.class);
LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("用户列表数据", "导出人:"+user.getRealname(), "导出信息"));
ExportParams exportParams = new ExportParams("用户列表数据", "导出人:"+user.getRealname(), "导出信息");
exportParams.setImageBasePath(upLoadPath);
mv.addObject(NormalExcelConstants.PARAMS, exportParams);
mv.addObject(NormalExcelConstants.DATA_LIST, pageList);
return mv;
}
@ -420,6 +431,9 @@ public class SysUserController {
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
// 错误信息
List<String> errorMessage = new ArrayList<>();
int successLines = 0, errorLines = 0;
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
MultipartFile file = entity.getValue();// 获取上传文件对象
ImportParams params = new ImportParams();
@ -428,17 +442,54 @@ public class SysUserController {
params.setNeedSave(true);
try {
List<SysUser> listSysUsers = ExcelImportUtil.importExcel(file.getInputStream(), SysUser.class, params);
for (SysUser sysUserExcel : listSysUsers) {
if (sysUserExcel.getPassword() == null) {
// 密码默认为“123456”
for (int i = 0; i < listSysUsers.size(); i++) {
SysUser sysUserExcel = listSysUsers.get(i);
if (StringUtils.isBlank(sysUserExcel.getPassword())) {
// 密码默认为 “123456”
sysUserExcel.setPassword("123456");
}
sysUserService.save(sysUserExcel);
// 密码加密加盐
String salt = oConvertUtils.randomGen(8);
sysUserExcel.setSalt(salt);
String passwordEncode = PasswordUtil.encrypt(sysUserExcel.getUsername(), sysUserExcel.getPassword(), salt);
sysUserExcel.setPassword(passwordEncode);
try {
sysUserService.save(sysUserExcel);
successLines++;
} catch (Exception e) {
errorLines++;
String message = e.getMessage();
int lineNumber = i + 1;
// 通过索引名判断出错信息
if (message.contains(CommonConstant.SQL_INDEX_UNIQ_SYS_USER_USERNAME)) {
errorMessage.add("" + lineNumber + " 行:用户名已经存在,忽略导入。");
} else if (message.contains(CommonConstant.SQL_INDEX_UNIQ_SYS_USER_WORK_NO)) {
errorMessage.add("" + lineNumber + " 行:工号已经存在,忽略导入。");
} else if (message.contains(CommonConstant.SQL_INDEX_UNIQ_SYS_USER_PHONE)) {
errorMessage.add("" + lineNumber + " 行:手机号已经存在,忽略导入。");
} else if (message.contains(CommonConstant.SQL_INDEX_UNIQ_SYS_USER_EMAIL)) {
errorMessage.add("" + lineNumber + " 行:电子邮件已经存在,忽略导入。");
} else {
errorMessage.add("" + lineNumber + " 行:未知错误,忽略导入");
log.error(e.getMessage(), e);
}
}
// 批量将部门和用户信息建立关联关系
String departIds = sysUserExcel.getDepartIds();
if (StringUtils.isNotBlank(departIds)) {
String userId = sysUserExcel.getId();
String[] departIdArray = departIds.split(",");
List<SysUserDepart> userDepartList = new ArrayList<>(departIdArray.length);
for (String departId : departIdArray) {
userDepartList.add(new SysUserDepart(userId, departId));
}
sysUserDepartService.saveBatch(userDepartList);
}
}
return Result.ok("文件导入成功!数据行数:" + listSysUsers.size());
} catch (Exception e) {
log.error(e.getMessage(),e);
return Result.error("抱歉! 您导入的数据中用户名已经存在.");
errorMessage.add("发生异常:" + e.getMessage());
log.error(e.getMessage(), e);
} finally {
try {
file.getInputStream().close();
@ -447,7 +498,27 @@ public class SysUserController {
}
}
}
return Result.error("文件导入失败!");
if (errorLines == 0) {
return Result.ok("" + successLines + "行数据全部导入成功!");
} else {
JSONObject result = new JSONObject(5);
int totalCount = successLines + errorLines;
result.put("totalCount", totalCount);
result.put("errorCount", errorLines);
result.put("successCount", successLines);
result.put("msg", "总上传行数:" + totalCount + ",已导入行数:" + successLines + ",错误行数:" + errorLines);
String fileUrl = PmsUtil.saveErrorTxtByList(errorMessage, "userImportExcelErrorLog");
int lastIndex = fileUrl.lastIndexOf(File.separator);
String fileName = fileUrl.substring(lastIndex + 1);
result.put("fileUrl", "/sys/common/static/" + fileUrl);
result.put("fileName", fileName);
Result res = Result.ok(result);
res.setCode(201);
res.setMessage("文件导入成功,但有错误。");
return res;
}
}
/**
@ -469,6 +540,7 @@ public class SysUserController {
/**
* 首页用户重置密码
*/
//@RequiresRoles({"admin"})
@RequestMapping(value = "/updatePassword", method = RequestMethod.PUT)
public Result<?> changPassword(@RequestBody JSONObject json) {
String username = json.getString("username");
@ -501,6 +573,7 @@ public class SysUserController {
* @param
* @return
*/
//@RequiresRoles({"admin"})
@RequestMapping(value = "/addSysUserRole", method = RequestMethod.POST)
public Result<String> addSysUserRole(@RequestBody SysUserRoleVO sysUserRoleVO) {
Result<String> result = new Result<String>();
@ -531,6 +604,7 @@ public class SysUserController {
* @param
* @return
*/
//@RequiresRoles({"admin"})
@RequestMapping(value = "/deleteUserRole", method = RequestMethod.DELETE)
public Result<SysUserRole> deleteUserRole(@RequestParam(name="roleId") String roleId,
@RequestParam(name="userId",required=true) String userId
@ -554,6 +628,7 @@ public class SysUserController {
* @param
* @return
*/
//@RequiresRoles({"admin"})
@RequestMapping(value = "/deleteUserRoleBatch", method = RequestMethod.DELETE)
public Result<SysUserRole> deleteUserRoleBatch(
@RequestParam(name="roleId") String roleId,
@ -586,7 +661,7 @@ public class SysUserController {
//部门id为空时查询我的部门下所有用户
if(oConvertUtils.isEmpty(depId)){
LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
int userIdentity = user.getIdentity() != null?user.getIdentity():CommonConstant.USER_IDENTITY_1;
int userIdentity = user.getUserIdentity() != null?user.getUserIdentity():CommonConstant.USER_IDENTITY_1;
if(oConvertUtils.isNotEmpty(userIdentity) && userIdentity == CommonConstant.USER_IDENTITY_2 ){
subDepids = sysDepartService.getMySubDepIdsByDepId(user.getDepartIds());
}
@ -652,21 +727,21 @@ public class SysUserController {
JSONArray resultJson = new JSONArray(list.size());
for (SysUserSysDepartModel item : list) {
String userId = item.getSysUser().getId();
String userId = item.getId();
// userId
JSONObject getModel = hasUser.get(userId);
// 之前已存在过该用户,直接合并数据
if (getModel != null) {
String departName = getModel.get("departName").toString();
getModel.put("departName", (departName + " | " + item.getSysDepart().getDepartName()));
getModel.put("departName", (departName + " | " + item.getDepartName()));
} else {
// 将用户对象转换为json格式并将部门信息合并到 json 中
JSONObject json = JSON.parseObject(JSON.toJSONString(item.getSysUser()));
JSONObject json = JSON.parseObject(JSON.toJSONString(item));
json.remove("id");
json.put("userId", userId);
json.put("departId", item.getSysDepart().getId());
json.put("departName", item.getSysDepart().getDepartName());
json.put("departId", item.getDepartId());
json.put("departName", item.getDepartName());
// json.put("avatar", item.getSysUser().getAvatar());
resultJson.add(json);
hasUser.put(userId, json);
}
@ -680,6 +755,7 @@ public class SysUserController {
/**
* 给指定部门添加对应的用户
*/
//@RequiresRoles({"admin"})
@RequestMapping(value = "/editSysDepartWithUser", method = RequestMethod.POST)
public Result<String> editSysDepartWithUser(@RequestBody SysDepartUsersVO sysDepartUsersVO) {
Result<String> result = new Result<String>();
@ -708,6 +784,7 @@ public class SysUserController {
/**
* 删除指定机构的用户关系
*/
//@RequiresRoles({"admin"})
@RequestMapping(value = "/deleteUserInDepart", method = RequestMethod.DELETE)
public Result<SysUserDepart> deleteUserInDepart(@RequestParam(name="depId") String depId,
@RequestParam(name="userId",required=true) String userId
@ -718,6 +795,13 @@ public class SysUserController {
queryWrapper.eq("dep_id", depId).eq("user_id",userId);
boolean b = sysUserDepartService.remove(queryWrapper);
if(b){
List<SysDepartRole> sysDepartRoleList = departRoleService.list(new QueryWrapper<SysDepartRole>().eq("depart_id",depId));
List<String> roleIds = sysDepartRoleList.stream().map(SysDepartRole::getId).collect(Collectors.toList());
if(roleIds != null && roleIds.size()>0){
QueryWrapper<SysDepartRoleUser> query = new QueryWrapper<>();
query.eq("user_id",userId).in("drole_id",roleIds);
departRoleUserService.remove(query);
}
result.success("删除成功!");
}else{
result.error500("当前选中部门与用户无关联关系!");
@ -732,6 +816,7 @@ public class SysUserController {
/**
* 批量删除指定机构的用户关系
*/
//@RequiresRoles({"admin"})
@RequestMapping(value = "/deleteUserInDepartBatch", method = RequestMethod.DELETE)
public Result<SysUserDepart> deleteUserInDepartBatch(
@RequestParam(name="depId") String depId,
@ -740,7 +825,10 @@ public class SysUserController {
try {
QueryWrapper<SysUserDepart> queryWrapper = new QueryWrapper<SysUserDepart>();
queryWrapper.eq("dep_id", depId).in("user_id",Arrays.asList(userIds.split(",")));
sysUserDepartService.remove(queryWrapper);
boolean b = sysUserDepartService.remove(queryWrapper);
if(b){
departRoleUserService.removeDeptRoleUser(Arrays.asList(userIds.split(",")),depId);
}
result.success("删除成功!");
}catch(Exception e) {
log.error(e.getMessage(), e);
@ -836,9 +924,9 @@ public class SysUserController {
user.setPassword(passwordEncode);
user.setEmail(email);
user.setPhone(phone);
user.setStatus(1);
user.setDelFlag(CommonConstant.DEL_FLAG_0.toString());
user.setActivitiSync(CommonConstant.ACT_SYNC_1);
user.setStatus(CommonConstant.USER_UNFREEZE);
user.setDelFlag(CommonConstant.DEL_FLAG_0);
user.setActivitiSync(CommonConstant.ACT_SYNC_0);
sysUserService.addUserWithRole(user,"ee8626f80f7c2619917b6236f3a7f02b");//默认临时角色 test
result.success("注册成功");
} catch (Exception e) {
@ -848,8 +936,8 @@ public class SysUserController {
}
/**
*
* @param 根据用户名或手机号查询用户信息
* 根据用户名或手机号查询用户信息
* @param
* @return
*/
@GetMapping("/querySysUser")
@ -984,7 +1072,7 @@ public class SysUserController {
}
/**
* 获取用户列表 根据用户名和真实名 模糊匹配
* 【APP端接口】获取用户列表 根据用户名和真实名 模糊匹配
* @param keyword
* @param pageNo
* @param pageSize
@ -992,6 +1080,7 @@ public class SysUserController {
*/
@GetMapping("/appUserList")
public Result<?> appUserList(@RequestParam(name = "keyword", required = false) String keyword,
@RequestParam(name = "username", required = false) String username,
@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize) {
try {
@ -999,8 +1088,11 @@ public class SysUserController {
LambdaQueryWrapper<SysUser> query = new LambdaQueryWrapper<SysUser>();
query.eq(SysUser::getActivitiSync, "1");
query.eq(SysUser::getDelFlag,"0");
query.and(i -> i.like(SysUser::getUsername, keyword).or().like(SysUser::getRealname, keyword));
if(oConvertUtils.isNotEmpty(username)){
query.eq(SysUser::getUsername,username);
}else{
query.and(i -> i.like(SysUser::getUsername, keyword).or().like(SysUser::getRealname, keyword));
}
Page<SysUser> page = new Page<>(pageNo, pageSize);
IPage<SysUser> res = this.sysUserService.page(page, query);
return Result.ok(res);
@ -1033,16 +1125,17 @@ public class SysUserController {
/**
* 还原被逻辑删除的用户
*
* @param userIds 被还原的用户ID是个 list 集合
* @param jsonObject
* @return
*/
@PutMapping("/recycleBin")
public Result putRecycleBin(@RequestBody List<String> userIds, HttpServletRequest request) {
if (userIds != null && userIds.size() > 0) {
@RequestMapping(value = "/putRecycleBin", method = RequestMethod.PUT)
public Result putRecycleBin(@RequestBody JSONObject jsonObject, HttpServletRequest request) {
String userIds = jsonObject.getString("userIds");
if (StringUtils.isNotBlank(userIds)) {
SysUser updateUser = new SysUser();
updateUser.setUpdateBy(JwtUtil.getUserNameByToken(request));
updateUser.setUpdateTime(new Date());
sysUserService.revertLogicDeleted(userIds, updateUser);
sysUserService.revertLogicDeleted(Arrays.asList(userIds.split(",")), updateUser);
}
return Result.ok("还原成功");
}
@ -1053,7 +1146,7 @@ public class SysUserController {
* @param userIds 被删除的用户ID多个id用半角逗号分割
* @return
*/
@DeleteMapping("/recycleBin")
@RequestMapping(value = "/deleteRecycleBin", method = RequestMethod.DELETE)
public Result deleteRecycleBin(@RequestParam("userIds") String userIds) {
if (StringUtils.isNotBlank(userIds)) {
sysUserService.removeLogicDeleted(Arrays.asList(userIds.split(",")));
@ -1061,4 +1154,31 @@ public class SysUserController {
return Result.ok("删除成功");
}
/**
* 移动端修改用户信息
* @param jsonObject
* @return
*/
@RequestMapping(value = "/appEdit", method = RequestMethod.PUT)
public Result<SysUser> appEdit(@RequestBody JSONObject jsonObject) {
Result<SysUser> result = new Result<SysUser>();
try {
SysUser sysUser = sysUserService.getById(jsonObject.getString("id"));
sysBaseAPI.addLog("移动端编辑用户id " +jsonObject.getString("id") ,CommonConstant.LOG_TYPE_2, 2);
if(sysUser==null) {
result.error500("未找到对应用户!");
}else {
SysUser user = JSON.parseObject(jsonObject.toJSONString(), SysUser.class);
user.setUpdateTime(new Date());
user.setPassword(sysUser.getPassword());
sysUserService.updateById(user);
}
} catch (Exception e) {
log.error(e.getMessage(), e);
result.error500("操作失败!");
}
return result;
}
}

View File

@ -0,0 +1,140 @@
package org.jeecg.modules.system.controller;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xkcoding.justauth.AuthRequestFactory;
import lombok.extern.slf4j.Slf4j;
import me.zhyd.oauth.model.AuthCallback;
import me.zhyd.oauth.model.AuthResponse;
import me.zhyd.oauth.request.AuthRequest;
import me.zhyd.oauth.utils.AuthStateUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.system.api.ISysBaseAPI;
import org.jeecg.common.system.util.JwtUtil;
import org.jeecg.common.util.PasswordUtil;
import org.jeecg.common.util.RedisUtil;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.system.entity.SysUser;
import org.jeecg.modules.system.service.ISysUserService;
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 javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
/**
* @Author scott
* @since 2018-12-17
*/
@Controller
@RequestMapping("/thirdLogin")
@Slf4j
public class ThirdLoginController {
@Autowired
private ISysUserService sysUserService;
@Autowired
private ISysBaseAPI sysBaseAPI;
@Autowired
private RedisUtil redisUtil;
@Autowired
private AuthRequestFactory factory;
@RequestMapping("/render/{source}")
public void render(@PathVariable("source") String source, HttpServletResponse response) throws IOException {
log.info("第三方登录进入render" + source);
AuthRequest authRequest = factory.get(source);
String authorizeUrl = authRequest.authorize(AuthStateUtils.createState());
log.info("第三方登录认证地址:" + authorizeUrl);
response.sendRedirect(authorizeUrl);
}
@RequestMapping("/{source}/callback")
public String login(@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);
log.info(JSONObject.toJSONString(response));
Result<JSONObject> result = new Result<JSONObject>();
if(response.getCode()==2000) {
JSONObject data = JSONObject.parseObject(JSONObject.toJSONString(response.getData()));
String username = data.getString("username");
String avatar = data.getString("avatar");
String uuid = data.getString("uuid");
//判断有没有这个人
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;
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);
}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);
}
result.setSuccess(false);
result.setMessage("第三方登录异常,请联系管理员");
return "thirdLogin";
}
@SuppressWarnings("unchecked")
@RequestMapping(value = "/getLoginUser/{token}", method = RequestMethod.GET)
@ResponseBody
public Result<JSONObject> getLoginUser(@PathVariable("token") String token) throws Exception {
Result<JSONObject> result = new Result<JSONObject>();
String username = JwtUtil.getUsername(token);
//1. 校验用户是否有效
SysUser sysUser = sysUserService.getUserByName(username);
result = sysUserService.checkUserIsEffective(sysUser);
if(!result.isSuccess()) {
return result;
}
JSONObject obj = new JSONObject();
//用户登录信息
obj.put("userInfo", sysUser);
//token 信息
obj.put("token", token);
result.setResult(obj);
result.setSuccess(true);
result.setCode(200);
sysBaseAPI.addLog("用户名: " + username + ",登录成功[第三方用户]", CommonConstant.LOG_TYPE_1, null);
return result;
}
}

View File

@ -140,4 +140,8 @@ public class SysAnnouncement implements Serializable {
* 组件/路由 地址
*/
private java.lang.String openPage;
/**
* 摘要
*/
private java.lang.String msgAbstract;
}

View File

@ -90,13 +90,11 @@ public class SysDataSource {
/**
* 创建人
*/
@Excel(name = "创建人", width = 15)
@ApiModelProperty(value = "创建人")
private java.lang.String createBy;
/**
* 创建日期
*/
@Excel(name = "创建日期", width = 20, format = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "创建日期")
@ -104,13 +102,11 @@ public class SysDataSource {
/**
* 更新人
*/
@Excel(name = "更新人", width = 15)
@ApiModelProperty(value = "更新人")
private java.lang.String updateBy;
/**
* 更新日期
*/
@Excel(name = "更新日期", width = 20, format = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "更新日期")

View File

@ -46,12 +46,11 @@ public class SysDepart implements Serializable {
private Integer departOrder;
/**描述*/
@Excel(name="描述",width=15)
private Object description;
private String description;
/**机构类别 1组织机构2岗位*/
@Excel(name="机构类别",width=15)
@Excel(name="机构类别",width=15,dicCode="org_category")
private String orgCategory;
/**机构类型*/
@Excel(name="机构类型",width=15)
private String orgType;
/**机构编码*/
@Excel(name="机构编码",width=15)
@ -69,11 +68,9 @@ public class SysDepart implements Serializable {
@Excel(name="备注",width=15)
private String memo;
/**状态1启用0不启用*/
@Excel(name="状态",width=15)
@Dict(dicCode = "depart_status")
private String status;
/**删除状态0正常1已删除*/
@Excel(name="删除状态",width=15)
@Dict(dicCode = "del_flag")
private String delFlag;
/**创建人*/

View File

@ -164,6 +164,7 @@ public class SysPermission implements Serializable {
this.id = "9502685863ab87f0ad1134142788a385";
this.name="首页";
this.component="dashboard/Analysis";
this.componentName="dashboard-analysis";
this.url="/dashboard/analysis";
this.icon="home";
this.menuType=0;

View File

@ -60,13 +60,11 @@ public class SysPosition {
/**
* 创建人
*/
@Excel(name = "创建人", width = 15)
@ApiModelProperty(value = "创建人")
private java.lang.String createBy;
/**
* 创建时间
*/
@Excel(name = "创建时间", width = 20, format = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "创建时间")
@ -74,13 +72,11 @@ public class SysPosition {
/**
* 修改人
*/
@Excel(name = "修改人", width = 15)
@ApiModelProperty(value = "修改人")
private java.lang.String updateBy;
/**
* 修改时间
*/
@Excel(name = "修改时间", width = 20, format = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "修改时间")

View File

@ -67,7 +67,7 @@ public class SysUser implements Serializable {
/**
* 头像
*/
@Excel(name = "头像", width = 15)
@Excel(name = "头像", width = 15,type = 2)
private String avatar;
/**
@ -114,7 +114,7 @@ public class SysUser implements Serializable {
*/
@Excel(name = "删除状态", width = 15,dicCode="del_flag")
@TableLogic
private String delFlag;
private Integer delFlag;
/**
* 工号,唯一键
@ -156,13 +156,13 @@ public class SysUser implements Serializable {
/**
* 同步工作流引擎1同步0不同步
*/
private String activitiSync;
private Integer activitiSync;
/**
* 身份0 普通成员 1 上级)
*/
@Excel(name="1普通成员 2上级",width = 15)
private Integer identity;
private Integer userIdentity;
/**
* 负责部门
@ -170,4 +170,16 @@ public class SysUser implements Serializable {
@Excel(name="负责部门",width = 15,dictTable ="sys_depart",dicText = "depart_name",dicCode = "id")
@Dict(dictTable ="sys_depart",dicText = "depart_name",dicCode = "id")
private String departIds;
/**
* 第三方登录的唯一标识
*/
private String thirdId;
/**
* 第三方类型 <br>
* github/githubwechat_enterprise/企业微信dingtalk/钉钉)
*/
private String thirdType;
}

View File

@ -13,5 +13,11 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
* @Version: V1.0
*/
public interface SysDepartRoleMapper extends BaseMapper<SysDepartRole> {
/**
* 根据用户id部门id查询可授权所有部门角色
* @param orgCode
* @param userId
* @return
*/
public List<SysDepartRole> queryDeptRoleByDeptAndUser(@Param("orgCode") String orgCode, @Param("userId") String userId);
}

View File

@ -3,11 +3,13 @@ package org.jeecg.modules.system.mapper;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.jeecg.common.system.vo.DictModel;
import org.jeecg.common.system.vo.DictQuery;
import org.jeecg.modules.system.entity.SysDict;
import org.jeecg.modules.system.model.DuplicateCheckVo;
import org.jeecg.modules.system.model.TreeSelectModel;
@ -32,14 +34,19 @@ public interface SysDictMapper extends BaseMapper<SysDict> {
public Long duplicateCheckCountSqlNoDataId(DuplicateCheckVo duplicateCheckVo);
public List<DictModel> queryDictItemsByCode(@Param("code") String code);
public List<DictModel> queryTableDictItemsByCode(@Param("table") String table,@Param("text") String text,@Param("code") String code);
public List<DictModel> queryTableDictItemsByCodeAndFilter(@Param("table") String table,@Param("text") String text,@Param("code") String code,@Param("filterSql") String filterSql);
@Deprecated
public List<DictModel> queryTableDictItemsByCode(@Param("table") String table,@Param("text") String text,@Param("code") String code);
@Deprecated
public List<DictModel> queryTableDictItemsByCodeAndFilter(@Param("table") String table,@Param("text") String text,@Param("code") String code,@Param("filterSql") String filterSql);
public String queryDictTextByKey(@Param("code") String code,@Param("key") String key);
@Deprecated
public String queryTableDictTextByKey(@Param("table") String table,@Param("text") String text,@Param("code") String code,@Param("key") String key);
@Deprecated
public List<DictModel> queryTableDictByKeys(@Param("table") String table, @Param("text") String text, @Param("code") String code, @Param("keyArray") String[] keyArray);
/**
@ -62,6 +69,7 @@ public interface SysDictMapper extends BaseMapper<SysDict> {
* @param keyword
* @return
*/
@Deprecated
public List<DictModel> queryTableDictItems(@Param("table") String table,@Param("text") String text,@Param("code") String code,@Param("keyword") String keyword);
/**
@ -73,6 +81,7 @@ public interface SysDictMapper extends BaseMapper<SysDict> {
* @param hasChildField
* @return
*/
@Deprecated
List<TreeSelectModel> queryTreeList(@Param("query") Map<String, String> query,@Param("table") String table,@Param("text") String text,@Param("code") String code,@Param("pidField") String pidField,@Param("pid") String pid,@Param("hasChildField") String hasChildField);
/**
@ -97,4 +106,13 @@ public interface SysDictMapper extends BaseMapper<SysDict> {
@Update("update sys_dict set del_flag = #{flag,jdbcType=INTEGER} where id = #{id,jdbcType=VARCHAR}")
public void updateDictDelFlag(@Param("flag") int delFlag, @Param("id") String id);
/**
* 分页查询字典表数据
* @param page
* @param query
* @return
*/
@Deprecated
public Page<DictModel> queryDictTablePageList(Page page, @Param("query") DictQuery query);
}

View File

@ -43,4 +43,15 @@ public interface SysPermissionMapper extends BaseMapper<SysPermission> {
@Select("SELECT url FROM sys_permission WHERE del_flag = 0 and menu_type = 2 and url like '%*%'")
public List<String> queryPermissionUrlWithStar();
/**
* 根据用户账号查询菜单权限
* @param sysPermission
* @param username
* @return
*/
public int queryCountByUsername(@Param("username") String username, @Param("permission") SysPermission sysPermission);
}

View File

@ -130,4 +130,13 @@ public interface SysUserMapper extends BaseMapper<SysUser> {
*/
int deleteLogicDeleted(@Param("userIds") String userIds);
/** 更新空字符串为null【此写法有sql注入风险禁止随便用】 */
int updateNullByEmptyString(@Param("fieldName") String fieldName);
/**
* 根据部门Ids,查询部门下用户信息
* @param departIds
* @return
*/
List<SysUser> queryByDepIds(@Param("departIds")List<String> departIds,@Param("username") String username);
}

View File

@ -33,7 +33,8 @@
where send_status = '1'
and del_flag = '0'
and msg_category = #{msgCategory}
and id IN ( select annt_id from sys_announcement_send where user_id = #{userId} and read_flag = '0')
and id IN ( select annt_id from sys_announcement_send where user_id = #{userId} and read_flag = '0')
order by create_time DESC
</select>
</mapper>

View File

@ -36,19 +36,32 @@
sa.send_time as send_time,
sa.bus_id as bus_id,
sa.open_type as open_type,
sa.open_page as open_page
sa.open_page as open_page,
sa.msg_abstract
from sys_announcement_send sas
left join sys_announcement sa ON sas.annt_id = sa.id
where sa.send_status = '1'
and sa.del_flag = '0'
and sas.user_id = #{announcementSendModel.userId}
<if test="announcementSendModel.titile !=null and announcementSendModel.titile != ''">
and sa.titile = #{announcementSendModel.titile}
and sa.titile LIKE concat(concat('%',#{announcementSendModel.titile}),'%')
</if>
<if test="announcementSendModel.sender !=null and announcementSendModel.sender != ''">
and sa.sender = #{announcementSendModel.sender}
and sa.sender LIKE concat(concat('%',#{announcementSendModel.sender}),'%')
</if>
order by sa.send_time desc
<if test="announcementSendModel.readFlag !=null and announcementSendModel.readFlag != ''">
and sas.read_flag = #{announcementSendModel.readFlag}
</if>
<if test="announcementSendModel.busType !=null and announcementSendModel.busType != ''">
and sa.bus_type = #{announcementSendModel.busType}
</if>
<if test="announcementSendModel.bizSource !=null and announcementSendModel.bizSource =='isNoBpm'">
and (sa.bus_type != 'bpm' or sa.bus_type is null)
</if>
<if test="announcementSendModel.msgCategory !=null and announcementSendModel.msgCategory != ''">
and sa.msg_category = #{announcementSendModel.msgCategory}
</if>
order by sas.read_flag,sa.send_time desc
</select>
</mapper>

View File

@ -2,4 +2,11 @@
<!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.SysDepartRoleMapper">
<!--根据用户id部门id查询可授权所有部门角色 -->
<select id="queryDeptRoleByDeptAndUser" resultType="org.jeecg.modules.system.entity.SysDepartRole">
SELECT * FROM sys_depart_role WHERE depart_id IN (
SELECT id FROM sys_depart WHERE id IN (SELECT dep_id FROM sys_user_depart WHERE user_id=#{userId})
AND org_code LIKE CONCAT(#{orgCode},'%')
)
</select>
</mapper>

View File

@ -92,6 +92,18 @@
</foreach>
</if>
</select>
<!-- 分页查询字典表数据 -->
<select id="queryDictTablePageList" parameterType="Object" resultType="org.jeecg.common.system.vo.DictModel">
select ${query.text} as "text",${query.code} as "value" from ${query.table}
where 1 = 1
<if test="query.keyword != null and query.keyword != ''">
and (${query.text} like '%${query.keyword}%' or ${query.code} like '%${query.keyword}%')
</if>
<if test="query.codeValue != null and query.codeValue != ''">
and ${query.code} = #{query.codeValue}
</if>
</select>
</mapper>

View File

@ -51,12 +51,10 @@
join sys_user d on d.id = c.user_id
where p.id = a.permission_id AND d.username = #{username,jdbcType=VARCHAR}
)
<!--update begin Author:taoyan Date:20200225 for默认授权online的auto动态隐藏路由 -->
or (p.url like '%:code' and p.url like '/online%' and p.hidden = 1)
or (p.url = '/online') )
<!--update end Author:taoyan Date:20200213 for默认授权online的auto动态隐藏路由 -->
or p.url = '/online')
and p.del_flag = 0
<!--update begin Author:lvdandan Date:20200225 for加入部门权限 -->
<!--update begin Author:lvdandan Date:20200213 for加入部门权限 -->
UNION
SELECT p.*
FROM sys_permission p
@ -71,7 +69,40 @@
<!--update end Author:lvdandan Date:20200213 for加入部门权限 -->
) h order by h.sort_no ASC
</select>
<!-- 根据用户账号查询菜单权限 -->
<select id="queryCountByUsername" parameterType="Object" resultType="int">
select sum(cnt) from (
select count(*) as cnt
from sys_role_permission a
join sys_permission b on a.permission_id = b.id
join sys_role c on a.role_id = c.id
join sys_user_role d on d.role_id = c.id
join sys_user e on d.user_id = e.id
where e.username = #{username}
<if test="permission.id !=null and permission.id != ''">
and b.id = #{permission.id}
</if>
<if test="permission.url !=null and permission.url != ''">
and b.url = #{permission.url}
</if>
union all
select count(*) as cnt
from sys_permission z
join sys_depart_role_permission y on z.id = y.permission_id
join sys_depart_role x on y.role_id = x.id
join sys_depart_role_user w on w.drole_id = x.id
join sys_user v on w.user_id = v.id
where v.username = #{username}
<if test="permission.id !=null and permission.id != ''">
and z.id = #{permission.id}
</if>
<if test="permission.url !=null and permission.url != ''">
and z.url = #{permission.url}
</if>
) temp
</select>
</mapper>

View File

@ -4,12 +4,12 @@
<!-- 根据用户名查询 -->
<select id="getUserByName" resultType="org.jeecg.modules.system.entity.SysUser">
select * from sys_user where username = #{username} and del_flag = '0'
select * from sys_user where username = #{username} and del_flag = 0
</select>
<!-- 根据部门Id查询 -->
<select id="getUserByDepId" resultType="org.jeecg.modules.system.entity.SysUser">
select * from sys_user where del_flag = '0' and id in (select user_id from sys_user_depart where dep_id=#{departId})
select * from sys_user where del_flag = 0 and id in (select user_id from sys_user_depart where dep_id=#{departId})
<if test="username!=null and username!=''">
and username = #{username}
</if>
@ -25,7 +25,7 @@
<!-- 通过多个部门IDS查询部门下的用户信息 -->
<select id="getUserByDepIds" resultType="org.jeecg.modules.system.entity.SysUser">
select * from sys_user where del_flag = '0'
select * from sys_user where del_flag = 0
<if test="departIds!=null and departIds.size()>0">
and id in (select user_id from sys_user_depart where dep_id in
<foreach collection="departIds" index="index" item="id" open="(" separator="," close=")">
@ -40,7 +40,7 @@
<!-- 根据角色Id查询 -->
<select id="getUserByRoleId" resultType="org.jeecg.modules.system.entity.SysUser">
select * from sys_user where del_flag = '0' and id in (select user_id from sys_user_role where role_id=#{roleId})
select * from sys_user where del_flag = 0 and id in (select user_id from sys_user_role where role_id=#{roleId})
<if test="username!=null and username!=''">
and username = #{username}
</if>
@ -53,31 +53,29 @@
<!-- 根据手机号查询 -->
<select id="getUserByPhone" resultType="org.jeecg.modules.system.entity.SysUser">
select * from sys_user where phone = #{phone} and del_flag = '0'
select * from sys_user where phone = #{phone} and del_flag = 0
</select>
<!-- 根据邮箱查询用户信息 -->
<select id="getUserByEmail" resultType="org.jeecg.modules.system.entity.SysUser">
select * from sys_user where email = #{email} and del_flag = '0'
select * from sys_user where email = #{email} and del_flag = 0
</select>
<!-- SQL片段getUserByOrgCode 的 FROM 和 WHERE 部分 -->
<sql id="getUserByOrgCodeFromSql">
FROM
sys_depart
-- 关联查询出该部门有哪些用户
INNER JOIN sys_user_depart ON sys_user_depart.dep_id = sys_depart.id
-- 关联查询出该用户的详细信息
INNER JOIN sys_user ON sys_user.id = sys_user_depart.user_id
WHERE
sys_user.del_flag = "0" AND sys_depart.org_code LIKE '${orgCode}%'
sys_user.del_flag = 0 AND sys_depart.org_code LIKE '${orgCode}%'
<if test="userParams != null">
<if test="userParams.realname != null and userParams.realname != ''">
AND sys_user.realname LIKE '%${userParams.realname}%'
AND sys_user.realname LIKE concat(concat('%',#{userParams.realname}),'%')
</if>
<if test="userParams.workNo != null and userParams.workNo != ''">
AND sys_user.work_no LIKE '%${userParams.workNo}%'
AND sys_user.work_no LIKE concat(concat('%',#{userParams.workNo}),'%')
</if>
</if>
</sql>
@ -85,15 +83,15 @@
<!-- 根据 orgCode 查询用户,包括子部门下的用户 -->
<select id="getUserByOrgCode" resultType="org.jeecg.modules.system.model.SysUserSysDepartModel">
SELECT
sys_user.id AS "sys_user.id",
sys_user.realname AS "sys_user.realname",
sys_user.work_no AS "sys_user.work_no",
sys_user.post AS "sys_user.post",
sys_user.telephone AS "sys_user.telephone",
sys_user.email AS "sys_user.email",
sys_user.phone AS "sys_user.phone",
sys_depart.id AS "sys_depart.id",
sys_depart.depart_name AS "sys_depart.depart_name"
sys_user.id AS id,
sys_user.realname AS realname,
sys_user.work_no AS workNo,
sys_user.post AS post,
sys_user.telephone AS telephone,
sys_user.email AS email,
sys_user.phone AS phone,
sys_depart.id AS departId,
sys_depart.depart_name AS departName
<include refid="getUserByOrgCodeFromSql"/>
ORDER BY
sys_depart.org_code ASC
@ -131,17 +129,36 @@
UPDATE
sys_user
SET
del_flag = "0",
del_flag = 0,
update_by = #{entity.updateBy},
update_time = #{entity.updateTime}
WHERE
del_flag = "1"
del_flag = 1
AND id IN (${userIds})
</update>
<!-- 彻底删除被逻辑删除的用户 -->
<delete id="deleteLogicDeleted">
DELETE FROM sys_user WHERE del_flag = "1" AND id IN (${userIds})
DELETE FROM sys_user WHERE del_flag = 1 AND id IN (${userIds})
</delete>
<!-- 更新空字符串为null -->
<update id="updateNullByEmptyString">
UPDATE sys_user SET ${fieldName} = NULL WHERE ${fieldName} = ''
</update>
<!-- 通过多个部门IDS查询部门下的用户信息 -->
<select id="queryByDepIds" resultType="org.jeecg.modules.system.entity.SysUser">
select * from sys_user where del_flag = 0
<if test="departIds!=null and departIds.size()>0">
and id in (select user_id from sys_user_depart where dep_id in
<foreach collection="departIds" index="index" item="id" open="(" separator="," close=")">
#{id}
</foreach>
)
</if>
<if test="username!=null and username!=''">
and username != #{username}
</if>
</select>
</mapper>

View File

@ -18,7 +18,6 @@ import lombok.Data;
* @Version: V1.0
*/
@Data
@TableName("sys_announcement_send")
public class AnnouncementSendModel implements Serializable {
private static final long serialVersionUID = 1L;
@ -55,6 +54,10 @@ public class AnnouncementSendModel implements Serializable {
* 业务id
*/
private java.lang.String busId;
/**
* 业务类型
*/
private java.lang.String busType;
/**
* 打开方式 组件component 路由url
*/
@ -63,4 +66,14 @@ public class AnnouncementSendModel implements Serializable {
* 组件/路由 地址
*/
private java.lang.String openPage;
/**
* 业务类型查询0.非bpm业务
*/
private java.lang.String bizSource;
/**
* 摘要
*/
private java.lang.String msgAbstract;
}

View File

@ -45,7 +45,7 @@ public class SysDepartTreeModel implements Serializable{
private Integer departOrder;
private Object description;
private String description;
private String orgCategory;
@ -263,11 +263,11 @@ public class SysDepartTreeModel implements Serializable{
this.departOrder = departOrder;
}
public Object getDescription() {
public String getDescription() {
return description;
}
public void setDescription(Object description) {
public void setDescription(String description) {
this.description = description;
}

View File

@ -1,24 +0,0 @@
package org.jeecg.modules.system.model;
import lombok.Data;
/**
* Created by Administrator on 2019/12/12.
*/
@Data
public class SysRoleDeisgnModel {
/**主键*/
private java.lang.String id;
/**变单设计器code*/
private java.lang.String desformCode;
/**变单设计器名称*/
private java.lang.String desformName;
/**变单设计器图标*/
private java.lang.String desformIcon;
/**流程类型*/
private java.lang.String procType;
/**流程名称*/
private java.lang.String procName;
/**标题表达式*/
private java.lang.String titleExp;
}

View File

@ -12,7 +12,14 @@ import org.jeecg.modules.system.entity.SysUser;
@Data
public class SysUserSysDepartModel {
private SysUser sysUser;
private SysDepart sysDepart;
private String id;
private String realname;
private String workNo;
private String post;
private String telephone;
private String email;
private String phone;
private String departId;
private String departName;
}

View File

@ -43,7 +43,7 @@ public class CategoryCodeRule implements IFillRuleHandler {
* 3.添加子节点有兄弟元素 YouBianCodeUtil.getNextYouBianCode(lastCode);
* */
//找同类 确定上一个最大的code值
LambdaQueryWrapper<SysCategory> query = new LambdaQueryWrapper<SysCategory>().eq(SysCategory::getPid, categoryPid).orderByDesc(SysCategory::getCode);
LambdaQueryWrapper<SysCategory> query = new LambdaQueryWrapper<SysCategory>().eq(SysCategory::getPid, categoryPid).isNotNull(SysCategory::getCode).orderByDesc(SysCategory::getCode);
SysCategoryMapper baseMapper = (SysCategoryMapper) SpringContextUtils.getBean("sysCategoryMapper");
List<SysCategory> list = baseMapper.selectList(query);
if (list == null || list.size() == 0) {

View File

@ -3,6 +3,8 @@ package org.jeecg.modules.system.service;
import org.jeecg.modules.system.entity.SysDepartRole;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
/**
* @Description: 部门角色
* @Author: jeecg-boot
@ -11,4 +13,12 @@ import com.baomidou.mybatisplus.extension.service.IService;
*/
public interface ISysDepartRoleService extends IService<SysDepartRole> {
/**
* 根据用户id部门id查询可授权所有部门角色
* @param orgCode
* @param userId
* @return
*/
List<SysDepartRole> queryDeptRoleByDeptAndUser(String orgCode, String userId);
}

View File

@ -14,4 +14,11 @@ import java.util.List;
public interface ISysDepartRoleUserService extends IService<SysDepartRoleUser> {
void deptRoleUserAdd(String userId,String newRoleId,String oldRoleId);
/**
* 取消用户与部门关联,删除关联关系
* @param userIds
* @param depId
*/
void removeDeptRoleUser(List<String> userIds,String depId);
}

View File

@ -59,7 +59,7 @@ public interface ISysDepartService extends IService<SysDepart>{
* @param keyWord
* @return
*/
List<SysDepartTreeModel> searhBy(String keyWord);
List<SysDepartTreeModel> searhBy(String keyWord,String myDeptSearch,String departIds);
/**
* 根据部门id删除并删除其可能存在的子级部门

View File

@ -4,6 +4,7 @@ import java.util.List;
import java.util.Map;
import org.jeecg.common.system.vo.DictModel;
import org.jeecg.common.system.vo.DictQuery;
import org.jeecg.modules.system.entity.SysDict;
import com.baomidou.mybatisplus.extension.service.IService;
import org.jeecg.modules.system.entity.SysDictItem;
@ -21,14 +22,20 @@ public interface ISysDictService extends IService<SysDict> {
public List<DictModel> queryDictItemsByCode(String code);
public Map<String,List<DictModel>> queryAllDictItems();
@Deprecated
List<DictModel> queryTableDictItemsByCode(String table, String text, String code);
@Deprecated
public List<DictModel> queryTableDictItemsByCodeAndFilter(String table, String text, String code, String filterSql);
public String queryDictTextByKey(String code, String key);
@Deprecated
String queryTableDictTextByKey(String table, String text, String code, String key);
@Deprecated
List<String> queryTableDictByKeys(String table, String text, String code, String[] keyArray);
/**
@ -42,7 +49,7 @@ public interface ISysDictService extends IService<SysDict> {
/**
* 添加一对多
*/
public void saveMain(SysDict sysDict, List<SysDictItem> sysDictItemList);
public Integer saveMain(SysDict sysDict, List<SysDictItem> sysDictItemList);
/**
* 查询所有部门 作为字典信息 id -->value,departName -->text
@ -64,6 +71,7 @@ public interface ISysDictService extends IService<SysDict> {
* @param keyword
* @return
*/
@Deprecated
public List<DictModel> queryTableDictItems(String table, String text, String code,String keyword);
/**
@ -76,6 +84,7 @@ public interface ISysDictService extends IService<SysDict> {
* @param hasChildField
* @return
*/
@Deprecated
List<TreeSelectModel> queryTreeList(Map<String, String> query,String table, String text, String code, String pidField,String pid,String hasChildField);
/**
@ -97,5 +106,14 @@ public interface ISysDictService extends IService<SysDict> {
*/
public List<SysDict> queryDeleteList();
/**
* 分页查询
* @param query
* @param pageSize
* @param pageNo
* @return
*/
@Deprecated
public List<DictModel> queryDictTablePageList(DictQuery query,int pageSize, int pageNo);
}

View File

@ -45,4 +45,20 @@ public interface ISysPermissionService extends IService<SysPermission> {
* @return
*/
public List<String> queryPermissionUrlWithStar();
/**
* 判断用户否拥有权限
* @param username
* @param sysPermission
* @return
*/
public boolean hasPermission(String username, SysPermission sysPermission);
/**
* 根据用户和请求地址判断是否有此权限
* @param username
* @param url
* @return
*/
public boolean hasPermission(String username, String url);
}

View File

@ -37,5 +37,5 @@ public interface ISysUserDepartService extends IService<SysUserDepart> {
/**
* 根据部门code查询当前部门和下级部门的用户信息
*/
public List<SysUser> queryUserByDepCode(String depCode);
public List<SysUser> queryUserByDepCode(String depCode,String realname);
}

View File

@ -15,10 +15,4 @@ import com.baomidou.mybatisplus.extension.service.IService;
* @since 2018-12-21
*/
public interface ISysUserRoleService extends IService<SysUserRole> {
/**
* 查询所有的用户角色信息
* @return
*/
Map<String,String> queryUserRole();
}

View File

@ -15,6 +15,7 @@ import org.jeecg.modules.system.entity.SysUser;
import com.baomidou.mybatisplus.extension.service.IService;
import org.jeecg.modules.system.model.SysUserSysDepartModel;
import org.springframework.transaction.annotation.Transactional;
/**
* <p>
@ -214,4 +215,22 @@ public interface ISysUserService extends IService<SysUser> {
*/
boolean removeLogicDeleted(List<String> userIds);
/**
* 更新手机号、邮箱空字符串为 null
*/
@Transactional(rollbackFor = Exception.class)
boolean updateNullPhoneEmail();
/**
* 保存第三方用户信息
* @param sysUser
*/
void saveThirdUser(SysUser sysUser);
/**
* 根据部门Ids查询
* @param
* @return
*/
List<SysUser> queryByDepIds(List<String> departIds, String username);
}

View File

@ -52,7 +52,9 @@ public class AutoPoiDictService implements AutoPoiDictServiceI {
}
}
for (DictModel t : dictList) {
dictReplaces.add(t.getText() + "_" + t.getValue());
if(t!=null){
dictReplaces.add(t.getText() + "_" + t.getValue());
}
}
if (dictReplaces != null && dictReplaces.size() != 0) {
log.info("---AutoPoi--Get_DB_Dict------"+ dictReplaces.toString());

View File

@ -0,0 +1,26 @@
package org.jeecg.modules.system.service.impl;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.util.CommonUtils;
import org.jeecgframework.poi.excel.imports.base.ImportFileServiceI;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
/**
* excel导入 实现类
*/
@Slf4j
@Service
public class ImportFileServiceImpl implements ImportFileServiceI {
@Value("${jeecg.path.upload}")
private String upLoadPath;
@Value(value="${jeecg.uploadType}")
private String uploadType;
@Override
public String doUpload(byte[] data) {
return CommonUtils.uploadOnlineImage(data, upLoadPath, "import", uploadType);
}
}

View File

@ -1,5 +1,6 @@
package org.jeecg.modules.system.service.impl;
import java.io.*;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;
@ -10,8 +11,11 @@ import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
@ -21,13 +25,11 @@ import org.apache.shiro.SecurityUtils;
import org.jeecg.common.constant.CacheConstant;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.constant.DataBaseConstant;
import org.jeecg.common.constant.WebsocketConst;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.system.api.ISysBaseAPI;
import org.jeecg.common.system.vo.*;
import org.jeecg.common.util.IPUtils;
import org.jeecg.common.util.SpringContextUtils;
import org.jeecg.common.util.SysAnnmentTypeEnum;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.common.util.*;
import org.jeecg.common.util.oss.OssBootUtil;
import org.jeecg.modules.message.entity.SysMessageTemplate;
import org.jeecg.modules.message.service.ISysMessageTemplateService;
@ -37,7 +39,6 @@ import org.jeecg.modules.system.mapper.*;
import org.jeecg.modules.system.service.ISysDataSourceService;
import org.jeecg.modules.system.service.ISysDepartService;
import org.jeecg.modules.system.service.ISysDictService;
import org.jeecg.modules.system.util.MinioUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
@ -59,7 +60,7 @@ import org.springframework.web.multipart.MultipartFile;
@Service
public class SysBaseApiImpl implements ISysBaseAPI {
/** 当前系统数据库类型 */
public static String DB_TYPE = "";
private static String DB_TYPE = "";
@Autowired
private ISysMessageTemplateService sysMessageTemplateService;
@Resource
@ -176,11 +177,15 @@ public class SysBaseApiImpl implements ISysBaseAPI {
@Override
public String getDatabaseType() throws SQLException {
if(oConvertUtils.isNotEmpty(DB_TYPE)){
return DB_TYPE;
}
DataSource dataSource = SpringContextUtils.getApplicationContext().getBean(DataSource.class);
return getDatabaseTypeByDataSource(dataSource);
}
@Override
@Cacheable(value = CacheConstant.SYS_DICT_CACHE,key = "#code")
public List<DictModel> queryDictItemsByCode(String code) {
return sysDictService.queryDictItemsByCode(code);
}
@ -195,7 +200,13 @@ public class SysBaseApiImpl implements ISysBaseAPI {
return sysDictService.queryAllDepartBackDictModel();
}
@Override
@Override
public List<JSONObject> queryAllDepart(Wrapper wrapper) {
//noinspection unchecked
return JSON.parseArray(JSON.toJSONString(sysDepartService.list(wrapper))).toJavaList(JSONObject.class);
}
@Override
public void sendSysAnnouncement(String fromUser, String toUser, String title, String msgContent) {
this.sendSysAnnouncement(fromUser, toUser, title, msgContent, CommonConstant.MSG_CATEGORY_2);
}
@ -229,10 +240,10 @@ public class SysBaseApiImpl implements ISysBaseAPI {
announcementSend.setReadFlag(CommonConstant.NO_READ_FLAG);
sysAnnouncementSendMapper.insert(announcementSend);
JSONObject obj = new JSONObject();
obj.put("cmd", "user");
obj.put("userId", sysUser.getId());
obj.put("msgId", announcement.getId());
obj.put("msgTxt", announcement.getTitile());
obj.put(WebsocketConst.MSG_CMD, WebsocketConst.CMD_USER);
obj.put(WebsocketConst.MSG_USER_ID, sysUser.getId());
obj.put(WebsocketConst.MSG_ID, announcement.getId());
obj.put(WebsocketConst.MSG_TXT, announcement.getTitile());
webSocket.sendOneMessage(sysUser.getId(), obj.toJSONString());
}
}
@ -272,10 +283,10 @@ public class SysBaseApiImpl implements ISysBaseAPI {
announcementSend.setReadFlag(CommonConstant.NO_READ_FLAG);
sysAnnouncementSendMapper.insert(announcementSend);
JSONObject obj = new JSONObject();
obj.put("cmd", "user");
obj.put("userId", sysUser.getId());
obj.put("msgId", announcement.getId());
obj.put("msgTxt", announcement.getTitile());
obj.put(WebsocketConst.MSG_CMD, WebsocketConst.CMD_USER);
obj.put(WebsocketConst.MSG_USER_ID, sysUser.getId());
obj.put(WebsocketConst.MSG_ID, announcement.getId());
obj.put(WebsocketConst.MSG_TXT, announcement.getTitile());
webSocket.sendOneMessage(sysUser.getId(), obj.toJSONString());
}
}
@ -360,10 +371,10 @@ public class SysBaseApiImpl implements ISysBaseAPI {
announcementSend.setReadFlag(CommonConstant.NO_READ_FLAG);
sysAnnouncementSendMapper.insert(announcementSend);
JSONObject obj = new JSONObject();
obj.put("cmd", "user");
obj.put("userId", sysUser.getId());
obj.put("msgId", announcement.getId());
obj.put("msgTxt", announcement.getTitile());
obj.put(WebsocketConst.MSG_CMD, WebsocketConst.CMD_USER);
obj.put(WebsocketConst.MSG_USER_ID, sysUser.getId());
obj.put(WebsocketConst.MSG_ID, announcement.getId());
obj.put(WebsocketConst.MSG_TXT, announcement.getTitile());
webSocket.sendOneMessage(sysUser.getId(), obj.toJSONString());
}
}
@ -418,10 +429,10 @@ public class SysBaseApiImpl implements ISysBaseAPI {
announcementSend.setReadFlag(CommonConstant.NO_READ_FLAG);
sysAnnouncementSendMapper.insert(announcementSend);
JSONObject obj = new JSONObject();
obj.put("cmd", "user");
obj.put("userId", sysUser.getId());
obj.put("msgId", announcement.getId());
obj.put("msgTxt", announcement.getTitile());
obj.put(WebsocketConst.MSG_CMD, WebsocketConst.CMD_USER);
obj.put(WebsocketConst.MSG_USER_ID, sysUser.getId());
obj.put(WebsocketConst.MSG_ID, announcement.getId());
obj.put(WebsocketConst.MSG_TXT, announcement.getTitile());
webSocket.sendOneMessage(sysUser.getId(), obj.toJSONString());
}
}
@ -495,7 +506,7 @@ public class SysBaseApiImpl implements ISysBaseAPI {
@Override
public List<ComboModel> queryAllUser() {
List<ComboModel> list = new ArrayList<ComboModel>();
List<SysUser> userList = userMapper.selectList(new QueryWrapper<SysUser>().eq("status","1").eq("del_flag","0"));
List<SysUser> userList = userMapper.selectList(new QueryWrapper<SysUser>().eq("status",1).eq("del_flag",0));
for(SysUser user : userList){
ComboModel model = new ComboModel();
model.setTitle(user.getRealname());
@ -509,7 +520,7 @@ public class SysBaseApiImpl implements ISysBaseAPI {
@Override
public JSONObject queryAllUser(String[] userIds,int pageNo,int pageSize) {
JSONObject json = new JSONObject();
QueryWrapper<SysUser> queryWrapper = new QueryWrapper<SysUser>().eq("status","1").eq("del_flag","0");
QueryWrapper<SysUser> queryWrapper = new QueryWrapper<SysUser>().eq("status",1).eq("del_flag",0);
List<ComboModel> list = new ArrayList<ComboModel>();
Page<SysUser> page = new Page<SysUser>(pageNo, pageSize);
IPage<SysUser> pageList = userMapper.selectPage(page, queryWrapper);
@ -533,7 +544,13 @@ public class SysBaseApiImpl implements ISysBaseAPI {
return json;
}
@Override
@Override
public List<JSONObject> queryAllUser(Wrapper wrapper) {
//noinspection unchecked
return JSON.parseArray(JSON.toJSONString(userMapper.selectList(wrapper))).toJavaList(JSONObject.class);
}
@Override
public List<ComboModel> queryAllRole() {
List<ComboModel> list = new ArrayList<ComboModel>();
List<SysRole> roleList = roleMapper.selectList(new QueryWrapper<SysRole>());
@ -610,7 +627,7 @@ public class SysBaseApiImpl implements ISysBaseAPI {
@Override
public List<String> getDeptHeadByDepId(String deptId) {
List<SysUser> userList = userMapper.selectList(new QueryWrapper<SysUser>().like("depart_ids",deptId).eq("status","1").eq("del_flag","0"));
List<SysUser> userList = userMapper.selectList(new QueryWrapper<SysUser>().like("depart_ids",deptId).eq("status",1).eq("del_flag",0));
List<String> list = new ArrayList<>();
for(SysUser user : userList){
list.add(user.getUsername());
@ -629,4 +646,132 @@ public class SysBaseApiImpl implements ISysBaseAPI {
return url;
}
@Override
public String upload(MultipartFile file, String bizPath, String uploadType, String customBucket) {
String url = "";
if(CommonConstant.UPLOAD_TYPE_MINIO.equals(uploadType)){
url = MinioUtil.upload(file,bizPath,customBucket);
}else{
url = OssBootUtil.upload(file,bizPath,customBucket);
}
return url;
}
@Override
public void viewAndDownload(String filePath, String uploadpath, String uploadType, HttpServletResponse response) {
InputStream inputStream = null;
OutputStream outputStream = null;
try {
if(filePath.startsWith("http")){
String fileName = filePath.substring(filePath.lastIndexOf("/")+1);
if(CommonConstant.UPLOAD_TYPE_MINIO.equals(uploadType)){
String bucketName = filePath.replace(MinioUtil.getMinioUrl(),"").split("/")[0];
String objectName = filePath.replace(MinioUtil.getMinioUrl()+bucketName,"");
inputStream = MinioUtil.getMinioFile(bucketName,objectName);
if(inputStream == null){
bucketName = CommonConstant.UPLOAD_CUSTOM_BUCKET;
objectName = filePath.replace(OssBootUtil.getStaticDomain()+"/","");
inputStream = OssBootUtil.getOssFile(objectName,bucketName);
}
}else{
String bucketName = CommonConstant.UPLOAD_CUSTOM_BUCKET;
String objectName = filePath.replace(OssBootUtil.getStaticDomain()+"/","");
inputStream = OssBootUtil.getOssFile(objectName,bucketName);
if(inputStream == null){
bucketName = filePath.replace(MinioUtil.getMinioUrl(),"").split("/")[0];
objectName = filePath.replace(MinioUtil.getMinioUrl()+bucketName,"");
inputStream = MinioUtil.getMinioFile(bucketName,objectName);
}
}
response.addHeader("Content-Disposition", "attachment;fileName=" + new String(fileName.getBytes("UTF-8"),"iso-8859-1"));
}else{
// 本地文件处理
filePath = filePath.replace("..", "");
if (filePath.endsWith(",")) {
filePath = filePath.substring(0, filePath.length() - 1);
}
String fullPath = uploadpath + File.separator + filePath;
String downloadFilePath = uploadpath + File.separator + fullPath;
File file = new File(downloadFilePath);
inputStream = new BufferedInputStream(new FileInputStream(fullPath));
response.addHeader("Content-Disposition", "attachment;fileName=" + new String(file.getName().getBytes("UTF-8"),"iso-8859-1"));
}
response.setContentType("application/force-download");// 设置强制下载不打开
outputStream = response.getOutputStream();
if(inputStream != null){
byte[] buf = new byte[1024];
int len;
while ((len = inputStream.read(buf)) > 0) {
outputStream.write(buf, 0, len);
}
response.flushBuffer();
}
} catch (IOException e) {
response.setStatus(404);
log.error("预览文件失败" + e.getMessage());
} finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
log.error(e.getMessage(), e);
}
}
if (outputStream != null) {
try {
outputStream.close();
} catch (IOException e) {
log.error(e.getMessage(), e);
}
}
}
}
@Override
public void sendWebSocketMsg(String[] userIds, String cmd) {
JSONObject obj = new JSONObject();
obj.put(WebsocketConst.MSG_CMD, cmd);
webSocket.sendMoreMessage(userIds, obj.toJSONString());
}
@Override
public List<LoginUser> queryAllUserByIds(String[] userIds) {
QueryWrapper<SysUser> queryWrapper = new QueryWrapper<SysUser>().eq("status",1).eq("del_flag",0);
queryWrapper.in("id",userIds);
List<LoginUser> loginUsers = new ArrayList<>();
List<SysUser> sysUsers = userMapper.selectList(queryWrapper);
for (SysUser user:sysUsers) {
LoginUser loginUser=new LoginUser();
BeanUtils.copyProperties(user, loginUser);
loginUsers.add(loginUser);
}
return loginUsers;
}
/**
* 推送签到人员信息
* @param userId
*/
@Override
public void meetingSignWebsocket(String userId) {
JSONObject obj = new JSONObject();
obj.put(WebsocketConst.MSG_CMD, WebsocketConst.CMD_SIGN);
obj.put(WebsocketConst.MSG_USER_ID,userId);
//TODO 目前全部推送,后面修改
webSocket.sendAllMessage(obj.toJSONString());
}
@Override
public List<LoginUser> queryUserByNames(String[] userNames) {
QueryWrapper<SysUser> queryWrapper = new QueryWrapper<SysUser>().eq("status",1).eq("del_flag",0);
queryWrapper.in("username",userNames);
List<LoginUser> loginUsers = new ArrayList<>();
List<SysUser> sysUsers = userMapper.selectList(queryWrapper);
for (SysUser user:sysUsers) {
LoginUser loginUser=new LoginUser();
BeanUtils.copyProperties(user, loginUser);
loginUsers.add(loginUser);
}
return loginUsers;
}
}

View File

@ -4,6 +4,7 @@ import java.util.List;
import java.util.Map;
import com.alibaba.fastjson.JSONObject;
import org.jeecg.common.constant.FillRuleConstant;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.util.FillRuleUtil;
import org.jeecg.common.util.YouBianCodeUtil;
@ -47,7 +48,7 @@ public class SysCategoryServiceImpl extends ServiceImpl<SysCategoryMapper, SysCa
//update-begin--Author:baihailong Date:20191209 for分类字典编码规则生成器做成公用配置
JSONObject formData = new JSONObject();
formData.put("pid",categoryPid);
categoryCode = (String) FillRuleUtil.executeRule("category_code_rule",formData);
categoryCode = (String) FillRuleUtil.executeRule(FillRuleConstant.CATEGORY,formData);
//update-end--Author:baihailong Date:20191209 for分类字典编码规则生成器做成公用配置
sysCategory.setCode(categoryCode);
sysCategory.setPid(categoryPid);

View File

@ -4,16 +4,22 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.system.entity.SysDepartPermission;
import org.jeecg.modules.system.entity.SysDepartRole;
import org.jeecg.modules.system.entity.SysDepartRolePermission;
import org.jeecg.modules.system.entity.SysPermissionDataRule;
import org.jeecg.modules.system.mapper.SysDepartPermissionMapper;
import org.jeecg.modules.system.mapper.SysDepartRoleMapper;
import org.jeecg.modules.system.mapper.SysDepartRolePermissionMapper;
import org.jeecg.modules.system.mapper.SysPermissionDataRuleMapper;
import org.jeecg.modules.system.service.ISysDepartPermissionService;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;
/**
* @Description: 部门权限表
@ -26,7 +32,14 @@ public class SysDepartPermissionServiceImpl extends ServiceImpl<SysDepartPermiss
@Resource
private SysPermissionDataRuleMapper ruleMapper;
@Resource
private SysDepartRoleMapper sysDepartRoleMapper;
@Resource
private SysDepartRolePermissionMapper departRolePermissionMapper;
@Override
@Transactional(rollbackFor = Exception.class)
public void saveDepartPermission(String departId, String permissionIds, String lastPermissionIds) {
List<String> add = getDiff(lastPermissionIds,permissionIds);
if(add!=null && add.size()>0) {
@ -43,6 +56,12 @@ public class SysDepartPermissionServiceImpl extends ServiceImpl<SysDepartPermiss
if(delete!=null && delete.size()>0) {
for (String permissionId : delete) {
this.remove(new QueryWrapper<SysDepartPermission>().lambda().eq(SysDepartPermission::getDepartId, departId).eq(SysDepartPermission::getPermissionId, permissionId));
//删除部门权限时,删除部门角色中已授权的权限
List<SysDepartRole> sysDepartRoleList = sysDepartRoleMapper.selectList(new LambdaQueryWrapper<SysDepartRole>().eq(SysDepartRole::getDepartId,departId));
List<String> roleIds = sysDepartRoleList.stream().map(SysDepartRole::getId).collect(Collectors.toList());
if(roleIds != null && roleIds.size()>0){
departRolePermissionMapper.delete(new LambdaQueryWrapper<SysDepartRolePermission>().eq(SysDepartRolePermission::getPermissionId,permissionId));
}
}
}
}

View File

@ -7,6 +7,8 @@ import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.util.List;
/**
* @Description: 部门角色
* @Author: jeecg-boot
@ -16,4 +18,8 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@Service
public class SysDepartRoleServiceImpl extends ServiceImpl<SysDepartRoleMapper, SysDepartRole> implements ISysDepartRoleService {
@Override
public List<SysDepartRole> queryDeptRoleByDeptAndUser(String orgCode, String userId) {
return this.baseMapper.queryDeptRoleByDeptAndUser(orgCode,userId);
}
}

View File

@ -2,14 +2,19 @@ package org.jeecg.modules.system.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.system.entity.SysDepartRole;
import org.jeecg.modules.system.entity.SysDepartRoleUser;
import org.jeecg.modules.system.mapper.SysDepartRoleMapper;
import org.jeecg.modules.system.mapper.SysDepartRoleUserMapper;
import org.jeecg.modules.system.service.ISysDepartRoleUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import java.util.stream.Collectors;
/**
* @Description: 部门角色人员信息
@ -19,6 +24,8 @@ import java.util.*;
*/
@Service
public class SysDepartRoleUserServiceImpl extends ServiceImpl<SysDepartRoleUserMapper, SysDepartRoleUser> implements ISysDepartRoleUserService {
@Autowired
private SysDepartRoleMapper sysDepartRoleMapper;
@Override
public void deptRoleUserAdd(String userId, String newRoleId, String oldRoleId) {
@ -41,6 +48,20 @@ public class SysDepartRoleUserServiceImpl extends ServiceImpl<SysDepartRoleUserM
}
}
@Override
@Transactional(rollbackFor = Exception.class)
public void removeDeptRoleUser(List<String> userIds, String depId) {
for(String userId : userIds){
List<SysDepartRole> sysDepartRoleList = sysDepartRoleMapper.selectList(new QueryWrapper<SysDepartRole>().eq("depart_id",depId));
List<String> roleIds = sysDepartRoleList.stream().map(SysDepartRole::getId).collect(Collectors.toList());
if(roleIds != null && roleIds.size()>0){
QueryWrapper<SysDepartRoleUser> query = new QueryWrapper<>();
query.eq("user_id",userId).in("drole_id",roleIds);
this.remove(query);
}
}
}
/**
* 从diff中找出main中没有的元素
* @param main

View File

@ -3,17 +3,18 @@ package org.jeecg.modules.system.service.impl;
import java.util.*;
import com.alibaba.fastjson.JSONObject;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.constant.CacheConstant;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.constant.FillRuleConstant;
import org.jeecg.common.util.FillRuleUtil;
import org.jeecg.common.util.YouBianCodeUtil;
import org.jeecg.modules.system.entity.SysDepart;
import org.jeecg.modules.system.mapper.SysDepartMapper;
import org.jeecg.modules.system.entity.*;
import org.jeecg.modules.system.mapper.*;
import org.jeecg.modules.system.model.DepartIdModel;
import org.jeecg.modules.system.model.SysDepartTreeModel;
import org.jeecg.modules.system.service.ISysDepartService;
import org.jeecg.modules.system.util.FindsDepartsChildrenUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -34,6 +35,17 @@ import io.netty.util.internal.StringUtil;
@Service
public class SysDepartServiceImpl extends ServiceImpl<SysDepartMapper, SysDepart> implements ISysDepartService {
@Autowired
private SysUserDepartMapper userDepartMapper;
@Autowired
private SysDepartRoleMapper sysDepartRoleMapper;
@Autowired
private SysDepartPermissionMapper departPermissionMapper;
@Autowired
private SysDepartRolePermissionMapper departRolePermissionMapper;
@Autowired
private SysDepartRoleUserMapper departRoleUserMapper;
@Override
public List<SysDepartTreeModel> queryMyDeptTreeList(String departIds) {
//根据部门id获取所负责部门
@ -103,7 +115,7 @@ public class SysDepartServiceImpl extends ServiceImpl<SysDepartMapper, SysDepart
//update-begin--Author:baihailong Date:20191209 for部门编码规则生成器做成公用配置
JSONObject formData = new JSONObject();
formData.put("parentId",parentId);
String[] codeArray = (String[]) FillRuleUtil.executeRule("org_num_role",formData);
String[] codeArray = (String[]) FillRuleUtil.executeRule(FillRuleConstant.DEPART,formData);
//update-end--Author:baihailong Date:20191209 for部门编码规则生成器做成公用配置
sysDepart.setOrgCode(codeArray[0]);
String orgType = codeArray[1];
@ -212,7 +224,7 @@ public class SysDepartServiceImpl extends ServiceImpl<SysDepartMapper, SysDepart
}
@Override
@Transactional
@Transactional(rollbackFor = Exception.class)
public void deleteBatchWithChildren(List<String> ids) {
List<String> idList = new ArrayList<String>();
for(String id: ids) {
@ -220,7 +232,26 @@ public class SysDepartServiceImpl extends ServiceImpl<SysDepartMapper, SysDepart
this.checkChildrenExists(id, idList);
}
this.removeByIds(idList);
//根据部门id获取部门角色id
List<String> roleIdList = new ArrayList<>();
LambdaQueryWrapper<SysDepartRole> query = new LambdaQueryWrapper<>();
query.select(SysDepartRole::getId).in(SysDepartRole::getDepartId, idList);
List<SysDepartRole> depRoleList = sysDepartRoleMapper.selectList(query);
for(SysDepartRole deptRole : depRoleList){
roleIdList.add(deptRole.getId());
}
//根据部门id删除用户与部门关系
userDepartMapper.delete(new LambdaQueryWrapper<SysUserDepart>().in(SysUserDepart::getDepId,idList));
//根据部门id删除部门授权
departPermissionMapper.delete(new LambdaQueryWrapper<SysDepartPermission>().in(SysDepartPermission::getDepartId,idList));
//根据部门id删除部门角色
sysDepartRoleMapper.delete(new LambdaQueryWrapper<SysDepartRole>().in(SysDepartRole::getDepartId,idList));
if(roleIdList != null && roleIdList.size()>0){
//根据角色id删除部门角色授权
departRolePermissionMapper.delete(new LambdaQueryWrapper<SysDepartRolePermission>().in(SysDepartRolePermission::getRoleId,roleIdList));
//根据角色id删除部门角色用户信息
departRoleUserMapper.delete(new LambdaQueryWrapper<SysDepartRoleUser>().in(SysDepartRoleUser::getDroleId,roleIdList));
}
}
@Override
@ -241,13 +272,26 @@ public class SysDepartServiceImpl extends ServiceImpl<SysDepartMapper, SysDepart
* </p>
*/
@Override
public List<SysDepartTreeModel> searhBy(String keyWord) {
public List<SysDepartTreeModel> searhBy(String keyWord,String myDeptSearch,String departIds) {
LambdaQueryWrapper<SysDepart> query = new LambdaQueryWrapper<SysDepart>();
List<SysDepartTreeModel> newList = new ArrayList<>();
//myDeptSearch不为空时为我的部门搜索只搜索所负责部门
if(!StringUtil.isNullOrEmpty(myDeptSearch)){
//departIds 为空普通用户或没有管理部门
if(StringUtil.isNullOrEmpty(departIds)){
return newList;
}
//根据部门id获取所负责部门
String[] codeArr = this.getMyDeptParentOrgCode(departIds);
for(int i=0;i<codeArr.length;i++){
query.or().likeRight(SysDepart::getOrgCode,codeArr[i]);
}
query.eq(SysDepart::getDelFlag, CommonConstant.DEL_FLAG_0.toString());
}
query.like(SysDepart::getDepartName, keyWord);
//update-begin--Author:huangzhilin Date:20140417 for[bugfree号]组织机构搜索回显优化--------------------
SysDepartTreeModel model = new SysDepartTreeModel();
List<SysDepart> departList = this.list(query);
List<SysDepartTreeModel> newList = new ArrayList<>();
if(departList.size() > 0) {
for(SysDepart depart : departList) {
model = new SysDepartTreeModel(depart);
@ -264,6 +308,7 @@ public class SysDepartServiceImpl extends ServiceImpl<SysDepartMapper, SysDepart
* 根据部门id删除并且删除其可能存在的子级任何部门
*/
@Override
@Transactional(rollbackFor = Exception.class)
public boolean delete(String id) {
List<String> idList = new ArrayList<>();
idList.add(id);
@ -271,6 +316,26 @@ public class SysDepartServiceImpl extends ServiceImpl<SysDepartMapper, SysDepart
//清空部门树内存
//FindsDepartsChildrenUtil.clearDepartIdModel();
boolean ok = this.removeByIds(idList);
//根据部门id获取部门角色id
List<String> roleIdList = new ArrayList<>();
LambdaQueryWrapper<SysDepartRole> query = new LambdaQueryWrapper<>();
query.select(SysDepartRole::getId).in(SysDepartRole::getDepartId, idList);
List<SysDepartRole> depRoleList = sysDepartRoleMapper.selectList(query);
for(SysDepartRole deptRole : depRoleList){
roleIdList.add(deptRole.getId());
}
//根据部门id删除用户与部门关系
userDepartMapper.delete(new LambdaQueryWrapper<SysUserDepart>().in(SysUserDepart::getDepId,idList));
//根据部门id删除部门授权
departPermissionMapper.delete(new LambdaQueryWrapper<SysDepartPermission>().in(SysDepartPermission::getDepartId,idList));
//根据部门id删除部门角色
sysDepartRoleMapper.delete(new LambdaQueryWrapper<SysDepartRole>().in(SysDepartRole::getDepartId,idList));
if(roleIdList != null && roleIdList.size()>0){
//根据角色id删除部门角色授权
departRolePermissionMapper.delete(new LambdaQueryWrapper<SysDepartRolePermission>().in(SysDepartRolePermission::getRoleId,roleIdList));
//根据角色id删除部门角色用户信息
departRoleUserMapper.delete(new LambdaQueryWrapper<SysDepartRoleUser>().in(SysDepartRoleUser::getDroleId,roleIdList));
}
return ok;
}

View File

@ -1,13 +1,13 @@
package org.jeecg.modules.system.service.impl;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.constant.CacheConstant;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.system.vo.DictModel;
import org.jeecg.common.system.vo.DictQuery;
import org.jeecg.modules.system.entity.SysDict;
import org.jeecg.modules.system.entity.SysDictItem;
import org.jeecg.modules.system.mapper.SysDictItemMapper;
@ -19,9 +19,11 @@ import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* <p>
@ -52,6 +54,28 @@ public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, SysDict> impl
return sysDictMapper.queryDictItemsByCode(code);
}
@Override
public Map<String, List<DictModel>> queryAllDictItems() {
Map<String, List<DictModel>> res = new HashMap<String, List<DictModel>>();
List<SysDict> ls = sysDictMapper.selectList(null);
LambdaQueryWrapper<SysDictItem> queryWrapper = new LambdaQueryWrapper<SysDictItem>();
queryWrapper.eq(SysDictItem::getStatus, 1);
queryWrapper.orderByAsc(SysDictItem::getSortOrder);
List<SysDictItem> sysDictItemList = sysDictItemMapper.selectList(queryWrapper);
for (SysDict d : ls) {
List<DictModel> dictModelList = sysDictItemList.stream().filter(s -> d.getId().equals(s.getDictId())).map(item -> {
DictModel dictModel = new DictModel();
dictModel.setText(item.getItemText());
dictModel.setValue(item.getItemValue());
return dictModel;
}).collect(Collectors.toList());
res.put(d.getDictCode(), dictModelList);
}
log.debug("-------登录加载系统字典-----" + res.toString());
return res;
}
/**
* 通过查询指定code 获取字典值text
* @param code
@ -140,15 +164,21 @@ public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, SysDict> impl
@Override
@Transactional
public void saveMain(SysDict sysDict, List<SysDictItem> sysDictItemList) {
sysDictMapper.insert(sysDict);
if (sysDictItemList != null) {
for (SysDictItem entity : sysDictItemList) {
entity.setDictId(sysDict.getId());
sysDictItemMapper.insert(entity);
}
}
public Integer saveMain(SysDict sysDict, List<SysDictItem> sysDictItemList) {
int insert=0;
try{
insert = sysDictMapper.insert(sysDict);
if (sysDictItemList != null) {
for (SysDictItem entity : sysDictItemList) {
entity.setDictId(sysDict.getId());
entity.setStatus(1);
sysDictItemMapper.insert(entity);
}
}
}catch(Exception e){
return insert;
}
return insert;
}
@Override
@ -186,4 +216,11 @@ public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, SysDict> impl
public List<SysDict> queryDeleteList() {
return baseMapper.queryDeleteList();
}
@Override
public List<DictModel> queryDictTablePageList(DictQuery query, int pageSize, int pageNo) {
Page page = new Page(pageNo,pageSize,false);
Page<DictModel> pageList = baseMapper.queryDictTablePageList(page, query);
return pageList.getRecords();
}
}

View File

@ -1,7 +1,9 @@
package org.jeecg.modules.system.service.impl;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
@ -11,7 +13,10 @@ import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.system.entity.SysPermission;
import org.jeecg.modules.system.entity.SysPermissionDataRule;
import org.jeecg.modules.system.mapper.SysDepartPermissionMapper;
import org.jeecg.modules.system.mapper.SysDepartRolePermissionMapper;
import org.jeecg.modules.system.mapper.SysPermissionMapper;
import org.jeecg.modules.system.mapper.SysRolePermissionMapper;
import org.jeecg.modules.system.model.TreeModel;
import org.jeecg.modules.system.service.ISysPermissionDataRuleService;
import org.jeecg.modules.system.service.ISysPermissionService;
@ -40,7 +45,16 @@ public class SysPermissionServiceImpl extends ServiceImpl<SysPermissionMapper, S
@Resource
private ISysPermissionDataRuleService permissionDataRuleService;
@Resource
private SysRolePermissionMapper sysRolePermissionMapper;
@Resource
private SysDepartPermissionMapper sysDepartPermissionMapper;
@Resource
private SysDepartRolePermissionMapper sysDepartRolePermissionMapper;
@Override
public List<TreeModel> queryListByParentId(String parentId) {
return sysPermissionMapper.queryListByParentId(parentId);
@ -68,6 +82,17 @@ public class SysPermissionServiceImpl extends ServiceImpl<SysPermissionMapper, S
sysPermissionMapper.deleteById(id);
// 该节点可能是子节点但也可能是其它节点的父节点,所以需要级联删除
this.removeChildrenBy(sysPermission.getId());
//关联删除
Map map = new HashMap<>();
map.put("permission_id",id);
//删除数据规则
this.deletePermRuleByPermId(id);
//删除角色授权表
sysRolePermissionMapper.deleteByMap(map);
//删除部门权限表
sysDepartPermissionMapper.deleteByMap(map);
//删除部门角色授权
sysDepartRolePermissionMapper.deleteByMap(map);
}
/**
@ -89,6 +114,16 @@ public class SysPermissionServiceImpl extends ServiceImpl<SysPermissionMapper, S
// 再遍历刚才查出的集合, 根据每个对象,查找其是否仍有子级
for (int i = 0, len = permissionList.size(); i < len; i++) {
id = permissionList.get(i).getId();
Map map = new HashMap<>();
map.put("permission_id",id);
//删除数据规则
this.deletePermRuleByPermId(id);
//删除角色授权表
sysRolePermissionMapper.deleteByMap(map);
//删除部门权限表
sysDepartPermissionMapper.deleteByMap(map);
//删除部门角色授权
sysDepartRolePermissionMapper.deleteByMap(map);
num = this.count(new LambdaQueryWrapper<SysPermission>().eq(SysPermission::getParentId, id));
// 如果有, 则递归
if (num > 0) {
@ -206,4 +241,26 @@ public class SysPermissionServiceImpl extends ServiceImpl<SysPermissionMapper, S
return this.baseMapper.queryPermissionUrlWithStar();
}
@Override
public boolean hasPermission(String username, SysPermission sysPermission) {
int count = baseMapper.queryCountByUsername(username,sysPermission);
if(count>0){
return true;
}else{
return false;
}
}
@Override
public boolean hasPermission(String username, String url) {
SysPermission sysPermission = new SysPermission();
sysPermission.setUrl(url);
int count = baseMapper.queryCountByUsername(username,sysPermission);
if(count>0){
return true;
}else{
return false;
}
}
}

View File

@ -2,8 +2,12 @@ package org.jeecg.modules.system.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.poi.ss.formula.functions.T;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.util.ImportExcelUtil;
import org.jeecg.common.util.PmsUtil;
import org.jeecg.modules.quartz.service.IQuartzJobService;
import org.jeecg.modules.system.entity.SysRole;
import org.jeecg.modules.system.mapper.SysRoleMapper;
import org.jeecg.modules.system.mapper.SysUserMapper;
@ -37,18 +41,15 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
@Override
public Result importExcelCheckRoleCode(MultipartFile file, ImportParams params) throws Exception {
List<SysRole> listSysRoles = ExcelImportUtil.importExcel(file.getInputStream(), SysRole.class, params);
List<Object> listSysRoles = ExcelImportUtil.importExcel(file.getInputStream(), SysRole.class, params);
int totalCount = listSysRoles.size();
List<String> errorStrs = new ArrayList<>();
// 去除 listSysRoles 中重复的数据
for (int i = 0; i < listSysRoles.size(); i++) {
String roleCodeI = listSysRoles.get(i).getRoleCode();
String roleCodeI =((SysRole)listSysRoles.get(i)).getRoleCode();
for (int j = i + 1; j < listSysRoles.size(); j++) {
String roleCodeJ = listSysRoles.get(j).getRoleCode();
String roleCodeJ =((SysRole)listSysRoles.get(j)).getRoleCode();
// 发现重复数据
if (roleCodeI.equals(roleCodeJ)) {
errorStrs.add("" + (j + 1) + " 行的 roleCode 值:" + roleCodeI + " 已存在,忽略导入");
@ -57,36 +58,13 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
}
}
}
// 去掉 sql 中的重复数据
for (int i = 0; i < listSysRoles.size(); i++) {
SysRole sysRoleExcel = listSysRoles.get(i);
try {
super.save(sysRoleExcel);
} catch (org.springframework.dao.DuplicateKeyException e) {
errorStrs.add("" + (i + 1) + " 行的 roleCode 值:" + sysRoleExcel.getRoleCode() + " 已存在,忽略导入");
} catch (Exception e) {
e.printStackTrace();
}
}
if (errorStrs.size() == 0) {
return Result.ok("文件导入成功!总导入行数:" + totalCount);
}
JSONObject result = new JSONObject(5);
result.put("totalCount", totalCount);
result.put("errorCount", errorStrs.size());
result.put("successCount", (errorStrs.size() - totalCount));
result.put("msg", "总上传行数:" + totalCount + ",已导入行数:" + (errorStrs.size() - totalCount) + ",错误行数:" + errorStrs.size());
String fileUrl = PmsUtil.saveErrorTxtByList(errorStrs, "roleImportExcelErrorLog");
int lastIndex = fileUrl.lastIndexOf(File.separator);
String fileName = fileUrl.substring(lastIndex + 1);
result.put("fileUrl", "/sys/common/download/" + fileUrl);
result.put("fileName", fileName);
Result res = Result.ok(result);
res.setCode(201);
res.setMessage("文件导入成功,但有错误。");
return res;
Integer errorLines=0;
Integer successLines=0;
List<String> list = ImportExcelUtil.importDateSave(listSysRoles, ISysRoleService.class, errorStrs, CommonConstant.SQL_INDEX_UNIQ_SYS_ROLE_CODE);
errorLines+=list.size();
successLines+=(listSysRoles.size()-errorLines);
return ImportExcelUtil.imporReturnRes(errorLines,successLines,list);
}
@Override

View File

@ -6,6 +6,7 @@ import java.util.stream.Collectors;
import java.util.stream.Collectors;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.system.entity.SysDepart;
import org.jeecg.modules.system.entity.SysUser;
import org.jeecg.modules.system.entity.SysUserDepart;
@ -98,7 +99,7 @@ public class SysUserDepartServiceImpl extends ServiceImpl<SysUserDepartMapper, S
* 根据部门code查询当前部门和下级部门的 用户信息
*/
@Override
public List<SysUser> queryUserByDepCode(String depCode) {
public List<SysUser> queryUserByDepCode(String depCode,String realname) {
LambdaQueryWrapper<SysDepart> queryByDepCode = new LambdaQueryWrapper<SysDepart>();
queryByDepCode.likeRight(SysDepart::getOrgCode,depCode);
List<SysDepart> sysDepartList = sysDepartService.list(queryByDepCode);
@ -112,7 +113,12 @@ public class SysUserDepartServiceImpl extends ServiceImpl<SysUserDepartMapper, S
for(SysUserDepart uDep : uDepList) {
userIdList.add(uDep.getUserId());
}
List<SysUser> userList = (List<SysUser>) sysUserService.listByIds(userIdList);
LambdaQueryWrapper<SysUser> queryUser = new LambdaQueryWrapper<SysUser>();
queryUser.in(SysUser::getId,userIdList);
if(oConvertUtils.isNotEmpty(realname)){
queryUser.like(SysUser::getRealname,realname.trim());
}
List<SysUser> userList = (List<SysUser>) sysUserService.list(queryUser);
//update-begin-author:taoyan date:201905047 for:接口调用查询返回结果不能返回密码相关信息
for (SysUser sysUser : userList) {
sysUser.setSalt("");

View File

@ -27,53 +27,4 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@Service
public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleMapper, SysUserRole> implements ISysUserRoleService {
@Autowired
private ISysUserService userService;
@Autowired
private ISysRoleService roleService;
/**
* 查询所有用户对应的角色信息
*/
@Override
public Map<String,String> queryUserRole() {
List<SysUserRole> uRoleList = this.list();
List<SysUser> userList = userService.list();
List<SysRole> roleList = roleService.list();
Map<String,String> map = new IdentityHashMap<>();
String userId = "";
String roleId = "";
String roleName = "";
if(uRoleList != null && uRoleList.size() > 0) {
for(SysUserRole uRole : uRoleList) {
roleId = uRole.getRoleId();
for(SysUser user : userList) {
userId = user.getId();
if(uRole.getUserId().equals(userId)) {
roleName = this.searchByRoleId(roleList,roleId);
map.put(userId, roleName);
}
}
}
return map;
}
return map;
}
/**
* queryUserRole调用的方法
* @param roleList
* @param roleId
* @return
*/
private String searchByRoleId(List<SysRole> roleList, String roleId) {
while(true) {
for(SysRole role : roleList) {
if(roleId.equals(role.getId())) {
return role.getRoleName();
}
}
}
}
}

View File

@ -15,6 +15,7 @@ import org.jeecg.common.system.api.ISysBaseAPI;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.system.vo.SysUserCacheInfo;
import org.jeecg.common.util.PasswordUtil;
import org.jeecg.common.util.UUIDGenerator;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.system.entity.*;
import org.jeecg.modules.system.mapper.*;
@ -53,6 +54,12 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
private ISysBaseAPI sysBaseAPI;
@Autowired
private SysDepartMapper sysDepartMapper;
@Autowired
private SysRoleMapper sysRoleMapper;
@Autowired
private SysDepartRoleUserMapper departRoleUserMapper;
@Autowired
private SysDepartRoleMapper sysDepartRoleMapper;
@Override
@CacheEvict(value = {CacheConstant.SYS_USERS_CACHE}, allEntries = true)
@ -303,14 +310,33 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
@Override
@Transactional
@Transactional(rollbackFor = Exception.class)
@CacheEvict(value={CacheConstant.SYS_USERS_CACHE}, allEntries=true)
public void editUserWithDepart(SysUser user, String departs) {
this.updateById(user); //更新角色的时候已经更新了一次了,可以再跟新一次
String[] arr = {};
if(oConvertUtils.isNotEmpty(departs)){
arr = departs.split(",");
}
//查询已关联部门
List<SysUserDepart> userDepartList = sysUserDepartMapper.selectList(new QueryWrapper<SysUserDepart>().lambda().eq(SysUserDepart::getUserId, user.getId()));
if(userDepartList != null && userDepartList.size()>0){
for(SysUserDepart depart : userDepartList ){
//修改已关联部门删除部门用户角色关系
if(!Arrays.asList(arr).contains(depart.getDepId())){
List<SysDepartRole> sysDepartRoleList = sysDepartRoleMapper.selectList(
new QueryWrapper<SysDepartRole>().lambda().eq(SysDepartRole::getDepartId,depart.getDepId()));
List<String> roleIds = sysDepartRoleList.stream().map(SysDepartRole::getId).collect(Collectors.toList());
if(roleIds != null && roleIds.size()>0){
departRoleUserMapper.delete(new QueryWrapper<SysDepartRoleUser>().lambda().eq(SysDepartRoleUser::getUserId, user.getId())
.in(SysDepartRoleUser::getDroleId,roleIds));
}
}
}
}
//先删后加
sysUserDepartMapper.delete(new QueryWrapper<SysUserDepart>().lambda().eq(SysUserDepart::getUserId, user.getId()));
if(oConvertUtils.isNotEmpty(departs)) {
String[] arr = departs.split(",");
for (String departId : arr) {
SysUserDepart userDepart = new SysUserDepart(user.getId(), departId);
sysUserDepartMapper.insert(userDepart);
@ -381,4 +407,32 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
return line != 0;
}
@Override
@Transactional(rollbackFor = Exception.class)
public boolean updateNullPhoneEmail() {
userMapper.updateNullByEmptyString("email");
userMapper.updateNullByEmptyString("phone");
return true;
}
@Override
public void saveThirdUser(SysUser sysUser) {
//保存用户
String userid = UUIDGenerator.generate();
sysUser.setId(userid);
baseMapper.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);
}
@Override
public List<SysUser> queryByDepIds(List<String> departIds, String username) {
return userMapper.queryByDepIds(departIds,username);
}
}

View File

@ -1,114 +0,0 @@
package org.jeecg.modules.system.util;
import io.minio.MinioClient;
import io.minio.errors.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.multipart.MultipartFile;
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
import java.io.InputStream;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* minio文件上传工具类
*/
@Slf4j
public class MinioUtil {
private static String minioUrl;
private static String minioName;
private static String minioPass;
private static String bucketName;
public static void setMinioUrl(String minioUrl) {
MinioUtil.minioUrl = minioUrl;
}
public static void setMinioName(String minioName) {
MinioUtil.minioName = minioName;
}
public static void setMinioPass(String minioPass) {
MinioUtil.minioPass = minioPass;
}
public static void setBucketName(String bucketName) {
MinioUtil.bucketName = bucketName;
}
private static MinioClient minioClient = null;
/**
* 上传文件
* @param file
* @return
*/
public static String upload(MultipartFile file,String bizPath) {
String file_url = "";
try {
initMinio(minioUrl, minioName,minioPass);
// 检查存储桶是否已经存在
if(minioClient.bucketExists(bucketName)) {
log.info("Bucket already exists.");
} else {
// 创建一个名为ota的存储桶
minioClient.makeBucket(bucketName);
log.info("create a new bucket.");
}
InputStream stream = file.getInputStream();
String orgName = file.getOriginalFilename();// 获取文件名
String objectName = bizPath+"/"+orgName.substring(0, orgName.lastIndexOf(".")) + "_" + System.currentTimeMillis() + orgName.substring(orgName.indexOf("."));
// 使用putObject上传一个本地文件到存储桶中。
minioClient.putObject(bucketName,objectName, stream,stream.available(),"application/octet-stream");
stream.close();
file_url = minioUrl+bucketName+"/"+objectName;
}catch (IOException e){
log.error(e.getMessage(), e);
} catch (InvalidKeyException e) {
log.error(e.getMessage(), e);
} catch (NoSuchAlgorithmException e) {
log.error(e.getMessage(), e);
} catch (NoResponseException e) {
log.error(e.getMessage(), e);
} catch (XmlPullParserException e) {
log.error(e.getMessage(), e);
} catch (InvalidArgumentException e) {
log.error(e.getMessage(), e);
} catch (RegionConflictException e) {
log.error(e.getMessage(), e);
} catch (InvalidBucketNameException e) {
log.error(e.getMessage(), e);
} catch (ErrorResponseException e) {
log.error(e.getMessage(), e);
} catch (InternalException e) {
log.error(e.getMessage(), e);
} catch (InsufficientDataException e) {
log.error(e.getMessage(), e);
}
return file_url;
}
/**
* 初始化客户端
* @param minioUrl
* @param minioName
* @param minioPass
* @return
*/
private static MinioClient initMinio(String minioUrl, String minioName,String minioPass) {
if (minioClient == null) {
try {
minioClient = new MinioClient(minioUrl, minioName,minioPass);
} catch (InvalidEndpointException e) {
e.printStackTrace();
} catch (InvalidPortException e) {
e.printStackTrace();
}
}
return minioClient;
}
}