first commit
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
*.js linguist-language=Java
|
||||
*.css linguist-language=Java
|
||||
*.html linguist-language=Java
|
||||
*.vue linguist-language=Java
|
||||
@@ -0,0 +1,15 @@
|
||||
FROM anapsix/alpine-java:8_server-jre_unlimited
|
||||
|
||||
MAINTAINER test@163.com
|
||||
|
||||
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
|
||||
|
||||
RUN mkdir -p /jero-boot
|
||||
|
||||
WORKDIR /jero-boot
|
||||
|
||||
EXPOSE 8080
|
||||
|
||||
ADD ./target/jero-boot-module-system-2.5.0.jar ./
|
||||
|
||||
CMD sleep 60;java -Djava.security.egd=file:/dev/./urandom -jar jero-boot-module-system-2.5.0.jar
|
||||
@@ -0,0 +1,52 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<groupId>com.jero.boot</groupId>
|
||||
<artifactId>jero-boot</artifactId>
|
||||
<version>2.5.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>jero-boot-module-system</artifactId>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>aliyun</id>
|
||||
<name>aliyun Repository</name>
|
||||
<url>https://maven.aliyun.com/repository/public</url>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>jeecg</id>
|
||||
<name>jeecg Repository</name>
|
||||
<url>https://maven.jeecg.org/nexus/content/repositories/jeecg</url>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.jero.boot</groupId>
|
||||
<artifactId>jero-system-local-api</artifactId>
|
||||
</dependency>
|
||||
<!-- 积木报表 -->
|
||||
<dependency>
|
||||
<groupId>com.jimureport</groupId>
|
||||
<artifactId>spring-boot-starter-jimureport</artifactId>
|
||||
<version>1.2.0</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>autopoi-web</artifactId>
|
||||
<groupId>org.jeecgframework</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.jero.config.init;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import com.jero.common.constant.CacheConstant;
|
||||
import com.jero.config.JeroCloudCondition;
|
||||
import com.jero.modules.system.service.ISysGatewayRouteService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.annotation.Conditional;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @desc: 启动程序,初始化路由配置
|
||||
* @author: flyme
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@Conditional(JeroCloudCondition.class)
|
||||
public class SystemInitListener implements ApplicationListener<ApplicationReadyEvent>, Ordered {
|
||||
|
||||
|
||||
@Autowired
|
||||
private ISysGatewayRouteService sysGatewayRouteService;
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(ApplicationReadyEvent applicationReadyEvent) {
|
||||
|
||||
log.info(" 服务已启动,初始化路由配置 ###################");
|
||||
if (applicationReadyEvent.getApplicationContext().getDisplayName().indexOf("AnnotationConfigServletWebServerApplicationContext") > -1) {
|
||||
sysGatewayRouteService.addRoute2Redis(CacheConstant.GATEWAY_ROUTES);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.jero.config.init;
|
||||
|
||||
import org.apache.catalina.Context;
|
||||
import org.apache.tomcat.util.scan.StandardJarScanner;
|
||||
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @Description: TomcatFactoryConfig
|
||||
* @author: scott
|
||||
* @date: 2021年01月25日 11:40
|
||||
*/
|
||||
@Configuration
|
||||
public class TomcatFactoryConfig {
|
||||
/**
|
||||
* tomcat-embed-jasper引用后提示jar找不到的问题
|
||||
*/
|
||||
@Bean
|
||||
public TomcatServletWebServerFactory tomcatFactory() {
|
||||
TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory() {
|
||||
@Override
|
||||
protected void postProcessContext(Context context) {
|
||||
((StandardJarScanner) context.getJarScanner()).setScanManifest(false);
|
||||
}
|
||||
};
|
||||
factory.addConnectorCustomizers(connector -> {
|
||||
connector.setProperty("relaxedPathChars", "[]{}");
|
||||
connector.setProperty("relaxedQueryChars", "[]{}");
|
||||
});
|
||||
return factory;
|
||||
}
|
||||
}
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
package com.jero.config.jimureport;
|
||||
|
||||
import com.jero.common.system.api.ISysBaseAPI;
|
||||
import com.jero.common.system.util.JwtUtil;
|
||||
import com.jero.common.system.vo.SysUserCacheInfo;
|
||||
import com.jero.common.util.RedisUtil;
|
||||
import com.jero.common.util.TokenUtils;
|
||||
import org.jeecg.modules.jmreport.api.JmReportTokenServiceI;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 自定义积木报表鉴权(如果不进行自定义,则所有请求不做权限控制)
|
||||
* * 1.自定义获取登录token
|
||||
* * 2.自定义获取登录用户
|
||||
*/
|
||||
class JimuReportTokenService implements JmReportTokenServiceI {
|
||||
@Autowired
|
||||
private ISysBaseAPI sysBaseAPI;
|
||||
@Autowired
|
||||
@Lazy
|
||||
private RedisUtil redisUtil;
|
||||
|
||||
@Override
|
||||
public String getToken(HttpServletRequest request) {
|
||||
return TokenUtils.getTokenByRequest(request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsername(String token) {
|
||||
return JwtUtil.getUsername(token);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean verifyToken(String token) {
|
||||
return TokenUtils.verifyToken(token, sysBaseAPI, redisUtil);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getUserInfo(String token) {
|
||||
String username = JwtUtil.getUsername(token);
|
||||
//此处通过token只能拿到一个信息 用户账号 后面的就是根据账号获取其他信息 查询数据或是走redis 用户根据自身业务可自定义
|
||||
SysUserCacheInfo userInfo = sysBaseAPI.getCacheUser(username);
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
//设置账号名
|
||||
map.put(SYS_USER_CODE, userInfo.getSysUserCode());
|
||||
//设置部门编码
|
||||
map.put(SYS_ORG_CODE, userInfo.getSysOrgCode());
|
||||
// 将所有信息存放至map 解析sql/api会根据map的键值解析
|
||||
return map;
|
||||
}
|
||||
}
|
||||
+657
@@ -0,0 +1,657 @@
|
||||
package com.jero.modules.api.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.jero.common.api.dto.OnlineAuthDTO;
|
||||
import com.jero.common.api.dto.message.*;
|
||||
import com.jero.common.system.api.ISysBaseAPI;
|
||||
import com.jero.common.system.vo.*;
|
||||
import com.jero.modules.system.service.ISysDepartService;
|
||||
import com.jero.modules.system.service.ISysUserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
/**
|
||||
* 服务化 system模块 对外接口请求类
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/sys/api")
|
||||
public class SystemAPIController {
|
||||
|
||||
@Autowired
|
||||
private ISysBaseAPI sysBaseAPI;
|
||||
|
||||
@Autowired
|
||||
private ISysUserService sysUserService;
|
||||
|
||||
@Autowired
|
||||
private ISysDepartService sysDepartService;
|
||||
/**
|
||||
* 发送系统消息
|
||||
* @param message 使用构造器赋值参数 如果不设置category(消息类型)则默认为2 发送系统消息
|
||||
*/
|
||||
@PostMapping("/sendSysAnnouncement")
|
||||
public void sendSysAnnouncement(@RequestBody MessageDTO message){
|
||||
sysBaseAPI.sendSysAnnouncement(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送消息 附带业务参数
|
||||
* @param message 使用构造器赋值参数
|
||||
*/
|
||||
@PostMapping("/sendBusAnnouncement")
|
||||
public void sendBusAnnouncement(@RequestBody BusMessageDTO message){
|
||||
sysBaseAPI.sendBusAnnouncement(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过模板发送消息
|
||||
* @param message 使用构造器赋值参数
|
||||
*/
|
||||
@PostMapping("/sendTemplateAnnouncement")
|
||||
public void sendTemplateAnnouncement(@RequestBody TemplateMessageDTO message){
|
||||
sysBaseAPI.sendTemplateAnnouncement(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过模板发送消息 附带业务参数
|
||||
* @param message 使用构造器赋值参数
|
||||
*/
|
||||
@PostMapping("/sendBusTemplateAnnouncement")
|
||||
public void sendBusTemplateAnnouncement(@RequestBody BusTemplateMessageDTO message){
|
||||
sysBaseAPI.sendBusTemplateAnnouncement(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过消息中心模板,生成推送内容
|
||||
* @param templateDTO 使用构造器赋值参数
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/parseTemplateByCode")
|
||||
public String parseTemplateByCode(@RequestBody TemplateDTO templateDTO){
|
||||
return sysBaseAPI.parseTemplateByCode(templateDTO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据业务类型busType及业务busId修改消息已读
|
||||
*/
|
||||
@GetMapping("/updateSysAnnounReadFlag")
|
||||
public void updateSysAnnounReadFlag(@RequestParam("busType") String busType, @RequestParam("busId")String busId){
|
||||
sysBaseAPI.updateSysAnnounReadFlag(busType, busId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户账号查询用户信息
|
||||
* @param username
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getUserByName")
|
||||
public LoginUser getUserByName(@RequestParam("username") String username){
|
||||
return sysBaseAPI.getUserByName(username);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户id查询用户信息
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getUserById")
|
||||
LoginUser getUserById(@RequestParam("id") String id){
|
||||
return sysBaseAPI.getUserById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过用户账号查询角色集合
|
||||
* @param username
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getRolesByUsername")
|
||||
List<String> getRolesByUsername(@RequestParam("username") String username){
|
||||
return sysBaseAPI.getRolesByUsername(username);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过用户账号查询部门集合
|
||||
* @param username
|
||||
* @return 部门 id
|
||||
*/
|
||||
@GetMapping("/getDepartIdsByUsername")
|
||||
List<String> getDepartIdsByUsername(@RequestParam("username") String username){
|
||||
return sysBaseAPI.getDepartIdsByUsername(username);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过用户账号查询部门 name
|
||||
* @param username
|
||||
* @return 部门 name
|
||||
*/
|
||||
@GetMapping("/getDepartNamesByUsername")
|
||||
List<String> getDepartNamesByUsername(@RequestParam("username") String username){
|
||||
return sysBaseAPI.getDepartNamesByUsername(username);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取数据字典
|
||||
* @param code
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/queryDictItemsByCode")
|
||||
List<DictModel> queryDictItemsByCode(@RequestParam("code") String code){
|
||||
return sysBaseAPI.queryDictItemsByCode(code);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取有效的数据字典
|
||||
* @param code
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/queryEnableDictItemsByCode")
|
||||
List<DictModel> queryEnableDictItemsByCode(@RequestParam("code") String code){
|
||||
return sysBaseAPI.queryEnableDictItemsByCode(code);
|
||||
}
|
||||
|
||||
/** 查询所有的父级字典,按照create_time排序 */
|
||||
@GetMapping("/queryAllDict")
|
||||
List<DictModel> queryAllDict(){
|
||||
return sysBaseAPI.queryAllDict();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有分类字典
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/queryAllDSysCategory")
|
||||
List<SysCategoryModel> queryAllDSysCategory(){
|
||||
return sysBaseAPI.queryAllDSysCategory();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有部门 作为字典信息 id -->value,departName -->text
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/queryAllDepartBackDictModel")
|
||||
List<DictModel> queryAllDepartBackDictModel(){
|
||||
return sysBaseAPI.queryAllDepartBackDictModel();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有角色 带参
|
||||
* roleIds 默认选中角色
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/queryAllRole")
|
||||
public List<ComboModel> queryAllRole(@RequestParam(name = "roleIds",required = false)String[] roleIds){
|
||||
if(roleIds==null || roleIds.length==0){
|
||||
return sysBaseAPI.queryAllRole();
|
||||
}else{
|
||||
return sysBaseAPI.queryAllRole(roleIds);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过用户账号查询角色Id集合
|
||||
* @param username
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getRoleIdsByUsername")
|
||||
public List<String> getRoleIdsByUsername(@RequestParam("username")String username){
|
||||
return sysBaseAPI.getRoleIdsByUsername(username);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过部门编号查询部门id
|
||||
* @param orgCode
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getDepartIdsByOrgCode")
|
||||
public String getDepartIdsByOrgCode(@RequestParam("orgCode")String orgCode){
|
||||
return sysBaseAPI.getDepartIdsByOrgCode(orgCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有部门
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getAllSysDepart")
|
||||
public List<SysDepartModel> getAllSysDepart(){
|
||||
return sysBaseAPI.getAllSysDepart();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 id 查询数据库中存储的 DynamicDataSourceModel
|
||||
*
|
||||
* @param dbSourceId
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getDynamicDbSourceById")
|
||||
DynamicDataSourceModel getDynamicDbSourceById(@RequestParam("dbSourceId")String dbSourceId){
|
||||
return sysBaseAPI.getDynamicDbSourceById(dbSourceId);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 根据部门Id获取部门负责人
|
||||
* @param deptId
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getDeptHeadByDepId")
|
||||
public List<String> getDeptHeadByDepId(@RequestParam("deptId") String deptId){
|
||||
return sysBaseAPI.getDeptHeadByDepId(deptId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查找父级部门
|
||||
* @param departId
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getParentDepartId")
|
||||
public DictModel getParentDepartId(@RequestParam("departId")String departId){
|
||||
return sysBaseAPI.getParentDepartId(departId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 code 查询数据库中存储的 DynamicDataSourceModel
|
||||
*
|
||||
* @param dbSourceCode
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getDynamicDbSourceByCode")
|
||||
public DynamicDataSourceModel getDynamicDbSourceByCode(@RequestParam("dbSourceCode") String dbSourceCode){
|
||||
return sysBaseAPI.getDynamicDbSourceByCode(dbSourceCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* 给指定用户发消息
|
||||
* @param userIds
|
||||
* @param cmd
|
||||
*/
|
||||
@GetMapping("/sendWebSocketMsg")
|
||||
public void sendWebSocketMsg(String[] userIds, String cmd){
|
||||
sysBaseAPI.sendWebSocketMsg(userIds, cmd);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据id获取所有参与用户
|
||||
* userIds
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/queryAllUserByIds")
|
||||
public List<LoginUser> queryAllUserByIds(@RequestParam("userIds") String[] userIds){
|
||||
return sysBaseAPI.queryAllUserByIds(userIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有用户 返回ComboModel
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/queryAllUserBackCombo")
|
||||
public List<ComboModel> queryAllUserBackCombo(){
|
||||
return sysBaseAPI.queryAllUserBackCombo();
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询用户 返回JSONObject
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/queryAllUser")
|
||||
public JSONObject queryAllUser(@RequestParam(name="userIds",required=false)String userIds, @RequestParam(name="pageNo",required=false) Integer pageNo,@RequestParam(name="pageSize",required=false) int pageSize){
|
||||
return sysBaseAPI.queryAllUser(userIds, pageNo, pageSize);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 将会议签到信息推动到预览
|
||||
* userIds
|
||||
* @return
|
||||
* @param userId
|
||||
*/
|
||||
@GetMapping("/meetingSignWebsocket")
|
||||
public void meetingSignWebsocket(@RequestParam("userId")String userId){
|
||||
sysBaseAPI.meetingSignWebsocket(userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据name获取所有参与用户
|
||||
* userNames
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/queryUserByNames")
|
||||
public List<LoginUser> queryUserByNames(@RequestParam("userNames")String[] userNames){
|
||||
return sysBaseAPI.queryUserByNames(userNames);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户的角色集合
|
||||
* @param username
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getUserRoleSet")
|
||||
public Set<String> getUserRoleSet(@RequestParam("username")String username){
|
||||
return sysBaseAPI.getUserRoleSet(username);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户的权限集合
|
||||
* @param username
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getUserPermissionSet")
|
||||
public Set<String> getUserPermissionSet(@RequestParam("username") String username){
|
||||
return sysBaseAPI.getUserPermissionSet(username);
|
||||
}
|
||||
|
||||
//-----
|
||||
|
||||
/**
|
||||
* 判断是否有online访问的权限
|
||||
* @param onlineAuthDTO
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/hasOnlineAuth")
|
||||
public boolean hasOnlineAuth(@RequestBody OnlineAuthDTO onlineAuthDTO){
|
||||
return sysBaseAPI.hasOnlineAuth(onlineAuthDTO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询用户角色信息
|
||||
* @param username
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/queryUserRoles")
|
||||
public Set<String> queryUserRoles(@RequestParam("username") String username){
|
||||
return sysUserService.getUserRolesSet(username);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询用户权限信息
|
||||
* @param username
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/queryUserAuths")
|
||||
public Set<String> queryUserAuths(@RequestParam("username") String username){
|
||||
return sysUserService.getUserPermissionsSet(username);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过部门id获取部门全部信息
|
||||
*/
|
||||
@GetMapping("/selectAllById")
|
||||
public SysDepartModel selectAllById(@RequestParam("id") String id){
|
||||
return sysBaseAPI.selectAllById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户id查询用户所属公司下所有用户ids
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/queryDeptUsersByUserId")
|
||||
public List<String> queryDeptUsersByUserId(@RequestParam("userId") String userId){
|
||||
return sysBaseAPI.queryDeptUsersByUserId(userId);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询数据权限
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/queryPermissionDataRule")
|
||||
public List<SysPermissionDataRuleModel> queryPermissionDataRule(@RequestParam("component") String component, @RequestParam("requestPath")String requestPath, @RequestParam("username") String username){
|
||||
return sysBaseAPI.queryPermissionDataRule(component, requestPath, username);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询用户信息
|
||||
* @param username
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getCacheUser")
|
||||
public SysUserCacheInfo getCacheUser(@RequestParam("username") String username){
|
||||
return sysBaseAPI.getCacheUser(username);
|
||||
}
|
||||
|
||||
/**
|
||||
* 普通字典的翻译
|
||||
* @param code
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/translateDict")
|
||||
public String translateDict(@RequestParam("code") String code, @RequestParam("key") String key){
|
||||
return sysBaseAPI.translateDict(code, key);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 36根据多个用户账号(逗号分隔),查询返回多个用户信息
|
||||
* @param usernames
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("/queryUsersByUsernames")
|
||||
List<JSONObject> queryUsersByUsernames(@RequestParam("usernames") String usernames){
|
||||
return this.sysBaseAPI.queryUsersByUsernames(usernames);
|
||||
}
|
||||
|
||||
/**
|
||||
* 37根据多个用户id(逗号分隔),查询返回多个用户信息
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("/queryUsersByIds")
|
||||
List<JSONObject> queryUsersByIds(@RequestParam("ids") String ids){
|
||||
return this.sysBaseAPI.queryUsersByIds(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 38根据多个部门编码(逗号分隔),查询返回多个部门信息
|
||||
* @param orgCodes
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/queryDepartsByOrgcodes")
|
||||
List<JSONObject> queryDepartsByOrgcodes(@RequestParam("orgCodes") String orgCodes){
|
||||
return this.sysBaseAPI.queryDepartsByOrgcodes(orgCodes);
|
||||
}
|
||||
|
||||
/**
|
||||
* 39根据多个部门ID(逗号分隔),查询返回多个部门信息
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/queryDepartsByIds")
|
||||
List<JSONObject> queryDepartsByIds(@RequestParam("ids") String ids){
|
||||
return this.sysBaseAPI.queryDepartsByIds(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 40发送邮件消息
|
||||
* @param email
|
||||
* @param title
|
||||
* @param content
|
||||
*/
|
||||
@GetMapping("/sendEmailMsg")
|
||||
public void sendEmailMsg(@RequestParam("email")String email,@RequestParam("title")String title,@RequestParam("content")String content){
|
||||
this.sysBaseAPI.sendEmailMsg(email,title,content);
|
||||
}
|
||||
/**
|
||||
* 根据部门id查询部门所有的父级(不包含自己)
|
||||
* @author 马志朝
|
||||
* @date 2021/3/24 8:50
|
||||
* @param departId 部门id
|
||||
*/
|
||||
@GetMapping("/listParentDepartsByDepId")
|
||||
List<SysDepartTreeModel> listParentDepartsByDepId(@RequestParam("departId") String departId){
|
||||
return sysDepartService.listParentDepartsByDepId(departId);
|
||||
}
|
||||
|
||||
@GetMapping("/listSonDepartsByDepId")
|
||||
/**
|
||||
* 根据部门id查询部门所有的子级(不包含自己)
|
||||
* @author 马志朝
|
||||
* @date 2021/3/24 8:54
|
||||
* @param departId 部门id
|
||||
*/
|
||||
List<SysDepartTreeModel> listSonDepartsByDepId(@RequestParam("departId") String departId){
|
||||
return sysDepartService.listSonDepartsByDepId(departId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 41 获取公司下级部门和公司下所有用户信息
|
||||
* @param orgCode
|
||||
*/
|
||||
@GetMapping("/getDeptUserByOrgCode")
|
||||
List<Map<String,Object>> getDeptUserByOrgCode(@RequestParam("orgCode")String orgCode){
|
||||
return this.sysBaseAPI.getDeptUserByOrgCode(orgCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询分类字典翻译
|
||||
*
|
||||
* @param ids 分类字典表id
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/loadCategoryDictItem")
|
||||
public List<String> loadCategoryDictItem(@RequestParam("ids") String ids) {
|
||||
return sysBaseAPI.loadCategoryDictItem(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据字典code加载字典text
|
||||
*
|
||||
* @param dictCode 顺序:tableName,text,code
|
||||
* @param keys 要查询的key
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/loadDictItem")
|
||||
public List<String> loadDictItem(@RequestParam("dictCode") String dictCode, @RequestParam("keys") String keys) {
|
||||
return sysBaseAPI.loadDictItem(dictCode, keys);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据字典code查询字典项
|
||||
*
|
||||
* @param dictCode 顺序:tableName,text,code
|
||||
* @param dictCode 要查询的key
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getDictItems")
|
||||
public List<DictModel> getDictItems(@RequestParam("dictCode") String dictCode) {
|
||||
return sysBaseAPI.getDictItems(dictCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据多个字典code查询多个字典项
|
||||
*
|
||||
* @param dictCodeList
|
||||
* @return key = dictCode ; value=对应的字典项
|
||||
*/
|
||||
@RequestMapping("/getManyDictItems")
|
||||
public Map<String, List<DictModel>> getManyDictItems(@RequestParam("dictCodeList") List<String> dictCodeList) {
|
||||
return sysBaseAPI.getManyDictItems(dictCodeList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 【下拉搜索】
|
||||
* 大数据量的字典表 走异步加载,即前端输入内容过滤数据
|
||||
*
|
||||
* @param dictCode 字典code格式:table,text,code
|
||||
* @param keyword 过滤关键字
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/loadDictItemByKeyword")
|
||||
public List<DictModel> loadDictItemByKeyword(@RequestParam("dictCode") String dictCode, @RequestParam("keyword") String keyword, @RequestParam(value = "pageSize", required = false) Integer pageSize) {
|
||||
return sysBaseAPI.loadDictItemByKeyword(dictCode, keyword, pageSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* 48 普通字典的翻译,根据多个dictCode和多条数据,多个以逗号分割
|
||||
* @param dictCodes
|
||||
* @param keys
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/translateManyDict")
|
||||
public Map<String, List<DictModel>> translateManyDict(@RequestParam("dictCodes") String dictCodes, @RequestParam("keys") String keys){
|
||||
return this.sysBaseAPI.translateManyDict(dictCodes, keys);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取表数据字典 【接口签名验证】
|
||||
* @param table
|
||||
* @param text
|
||||
* @param code
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/queryTableDictItemsByCode")
|
||||
List<DictModel> queryTableDictItemsByCode(@RequestParam("table") String table, @RequestParam("text") String text, @RequestParam("code") String code){
|
||||
return sysBaseAPI.queryTableDictItemsByCode(table, text, code);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询表字典 支持过滤数据 【接口签名验证】
|
||||
* @param table
|
||||
* @param text
|
||||
* @param code
|
||||
* @param filterSql
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/queryFilterTableDictInfo")
|
||||
List<DictModel> queryFilterTableDictInfo(@RequestParam("table") String table, @RequestParam("text") String text, @RequestParam("code") String code, @RequestParam("filterSql") String filterSql){
|
||||
return sysBaseAPI.queryFilterTableDictInfo(table, text, code, filterSql);
|
||||
}
|
||||
|
||||
/**
|
||||
* 【接口签名验证】
|
||||
* 查询指定table的 text code 获取字典,包含text和value
|
||||
* @param table
|
||||
* @param text
|
||||
* @param code
|
||||
* @param keyArray
|
||||
* @deprecated 不推荐
|
||||
* @return
|
||||
*/
|
||||
@Deprecated
|
||||
@GetMapping("/queryTableDictByKeys")
|
||||
public List<String> queryTableDictByKeys(@RequestParam("table") String table, @RequestParam("text") String text, @RequestParam("code") String code, @RequestParam("keyArray") String[] keyArray){
|
||||
return sysBaseAPI.queryTableDictByKeys(table, text, code, keyArray);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 字典表的 翻译【接口签名验证】
|
||||
* @param table
|
||||
* @param text
|
||||
* @param code
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/translateDictFromTable")
|
||||
public String translateDictFromTable(@RequestParam("table") String table, @RequestParam("text") String text, @RequestParam("code") String code, @RequestParam("key") String key){
|
||||
return sysBaseAPI.translateDictFromTable(table, text, code, key);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 【接口签名验证】
|
||||
* 49 字典表的 翻译,可批量
|
||||
*
|
||||
* @param table
|
||||
* @param text
|
||||
* @param code
|
||||
* @param keys 多个用逗号分割
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/translateDictFromTableByKeys")
|
||||
public List<DictModel> translateDictFromTableByKeys(@RequestParam("table") String table, @RequestParam("text") String text, @RequestParam("code") String code, @RequestParam("keys") String keys) {
|
||||
return this.sysBaseAPI.translateDictFromTableByKeys(table, text, code, keys);
|
||||
}
|
||||
|
||||
}
|
||||
+110
@@ -0,0 +1,110 @@
|
||||
package com.jero.modules.cas.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.jero.common.api.vo.Results;
|
||||
import com.jero.common.constant.CommonConstant;
|
||||
import com.jero.common.exception.JeroBootException;
|
||||
import com.jero.common.system.util.JwtUtil;
|
||||
import com.jero.common.util.RedisUtil;
|
||||
import com.jero.modules.cas.util.CASServiceUtil;
|
||||
import com.jero.modules.cas.util.XmlUtils;
|
||||
import com.jero.modules.system.entity.SysDepart;
|
||||
import com.jero.modules.system.entity.SysUser;
|
||||
import com.jero.modules.system.service.ISysDepartService;
|
||||
import com.jero.modules.system.service.ISysUserService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* CAS单点登录客户端登录认证
|
||||
* </p>
|
||||
*
|
||||
* @Author zhoujf
|
||||
* @since 2018-12-20
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/sys/cas/client")
|
||||
public class CasClientController {
|
||||
|
||||
@Autowired
|
||||
private ISysUserService sysUserService;
|
||||
@Autowired
|
||||
private ISysDepartService sysDepartService;
|
||||
@Autowired
|
||||
private RedisUtil redisUtil;
|
||||
|
||||
@Value("${cas.prefixUrl}")
|
||||
private String prefixUrl;
|
||||
|
||||
|
||||
@GetMapping("/validateLogin")
|
||||
public Object validateLogin(@RequestParam(name="ticket") String ticket,
|
||||
@RequestParam(name="service") String service,
|
||||
HttpServletRequest request,
|
||||
HttpServletResponse response) {
|
||||
String multiDepart = "multi_depart";
|
||||
Results<JSONObject> result = new Results<>();
|
||||
log.info("Rest api login.");
|
||||
try {
|
||||
String validateUrl = prefixUrl+"/p3/serviceValidate";
|
||||
String res = CASServiceUtil.getSTValidate(validateUrl, ticket, service);
|
||||
log.info("res."+res);
|
||||
final String error = XmlUtils.getTextForElement(res, "authenticationFailure");
|
||||
if(StringUtils.isNotEmpty(error)) {
|
||||
throw new JeroBootException(error);
|
||||
}
|
||||
final String principal = XmlUtils.getTextForElement(res, "user");
|
||||
if (StringUtils.isEmpty(principal)) {
|
||||
throw new JeroBootException("No principal was found in the response from the CAS server.");
|
||||
}
|
||||
log.info("-------token----username---"+principal);
|
||||
//1. 校验用户是否有效
|
||||
SysUser sysUser = sysUserService.getUserByName(principal);
|
||||
result = sysUserService.checkUserIsEffective(sysUser);
|
||||
if(!result.isSuccess()) {
|
||||
return result;
|
||||
}
|
||||
String token = JwtUtil.sign(sysUser.getUsername(), sysUser.getPassword());
|
||||
// 设置超时时间
|
||||
redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token);
|
||||
redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME / 1000);
|
||||
|
||||
//获取用户部门信息
|
||||
JSONObject obj = new JSONObject();
|
||||
List<SysDepart> departs = sysDepartService.queryUserDeparts(sysUser.getId());
|
||||
obj.put("departs", departs);
|
||||
if (departs == null || departs.isEmpty()) {
|
||||
obj.put(multiDepart, 0);
|
||||
} else if (departs.size() == 1) {
|
||||
sysUserService.updateUserDepart(principal, departs.get(0).getOrgCode());
|
||||
obj.put(multiDepart, 1);
|
||||
} else {
|
||||
obj.put(multiDepart, 2);
|
||||
}
|
||||
obj.put("token", token);
|
||||
obj.put("userInfo", sysUser);
|
||||
result.setResult(obj);
|
||||
result.setMessage("登录成功");
|
||||
|
||||
} catch (Exception e) {
|
||||
result.setSuccess(false);
|
||||
result.setMessage(e.getMessage());
|
||||
}
|
||||
return new HttpEntity<>(result);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
package com.jero.modules.cas.util;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.conn.socket.LayeredConnectionSocketFactory;
|
||||
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.TrustManager;
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.security.KeyManagementException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.cert.X509Certificate;
|
||||
|
||||
@Slf4j
|
||||
public class CASServiceUtil {
|
||||
|
||||
private CASServiceUtil(){
|
||||
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String serviceUrl = "https://cas.8f8.com.cn:8443/cas/p3/serviceValidate";
|
||||
String service = "http://localhost:3003/user/login";
|
||||
String ticket = "ST-5-1g-9cNES6KXNRwq-GuRET103sm0-DESKTOP-VKLS8B3";
|
||||
String res = getSTValidate(serviceUrl,ticket, service);
|
||||
|
||||
log.info("---------res-----"+res);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 验证ST
|
||||
*/
|
||||
public static String getSTValidate(String url,String st, String service){
|
||||
try {
|
||||
url = url+"?service="+service+"&ticket="+st;
|
||||
CloseableHttpClient httpclient = createHttpClientWithNoSsl();
|
||||
HttpGet httpget = new HttpGet(url);
|
||||
HttpResponse response = httpclient.execute(httpget);
|
||||
String res = readResponse(response);
|
||||
return "".equals(res) ? null : res;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 读取 response body 内容为字符串
|
||||
*
|
||||
* @param response
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
private static String readResponse(HttpResponse response) throws IOException {
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
||||
StringBuilder result = new StringBuilder();
|
||||
String line;
|
||||
while ((line = in.readLine()) != null) {
|
||||
result.append(line);
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 创建模拟客户端(针对 https 客户端禁用 SSL 验证)
|
||||
*
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
private static CloseableHttpClient createHttpClientWithNoSsl() throws NoSuchAlgorithmException, KeyManagementException {
|
||||
// Create a trust manager that does not validate certificate chains
|
||||
TrustManager[] trustAllCerts = new TrustManager[]{
|
||||
new X509TrustManager() {
|
||||
@Override
|
||||
public X509Certificate[] getAcceptedIssuers() {
|
||||
return new X509Certificate[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkClientTrusted(X509Certificate[] certs, String authType) {
|
||||
// don't check
|
||||
log.info("client");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkServerTrusted(X509Certificate[] certs, String authType) {
|
||||
// don't check
|
||||
log.info("server");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
SSLContext ctx = SSLContext.getInstance("TLS");
|
||||
ctx.init(null, trustAllCerts, null);
|
||||
LayeredConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(ctx);
|
||||
return HttpClients.custom()
|
||||
.setSSLSocketFactory(sslSocketFactory)
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,293 @@
|
||||
package com.jero.modules.cas.util;
|
||||
|
||||
|
||||
import com.jero.common.exception.JeroBootException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.w3c.dom.Document;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.XMLReader;
|
||||
import org.xml.sax.helpers.DefaultHandler;
|
||||
|
||||
import javax.xml.XMLConstants;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.parsers.SAXParser;
|
||||
import javax.xml.parsers.SAXParserFactory;
|
||||
import java.io.StringReader;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 解析cas,ST验证后的xml
|
||||
*
|
||||
*/
|
||||
@Slf4j
|
||||
public final class XmlUtils {
|
||||
|
||||
/**
|
||||
* Creates a new namespace-aware DOM document object by parsing the given XML.
|
||||
*
|
||||
* @param xml XML content.
|
||||
*
|
||||
* @return DOM document.
|
||||
*/
|
||||
public static Document newDocument(final String xml) {
|
||||
final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
final Map<String, Boolean> features = new HashMap<>();
|
||||
features.put(XMLConstants.FEATURE_SECURE_PROCESSING, true);
|
||||
features.put("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
|
||||
for (final Map.Entry<String, Boolean> entry : features.entrySet()) {
|
||||
try {
|
||||
factory.setFeature(entry.getKey(), entry.getValue());
|
||||
} catch (ParserConfigurationException e) {
|
||||
log.warn("Failed setting XML feature {}: {}", entry.getKey(), e);
|
||||
}
|
||||
}
|
||||
factory.setNamespaceAware(true);
|
||||
try {
|
||||
return factory.newDocumentBuilder().parse(new InputSource(new StringReader(xml)));
|
||||
} catch (Exception e) {
|
||||
throw new JeroBootException("XML parsing error: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an instance of an XML reader from the XMLReaderFactory.
|
||||
*
|
||||
* @return the XMLReader.
|
||||
*/
|
||||
public static XMLReader getXmlReader() {
|
||||
try {
|
||||
final XMLReader reader = SAXParserFactory.newInstance().newSAXParser().getXMLReader();
|
||||
reader.setFeature("http://xml.org/sax/features/namespaces", true);
|
||||
reader.setFeature("http://xml.org/sax/features/namespace-prefixes", false);
|
||||
reader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
|
||||
return reader;
|
||||
} catch (final Exception e) {
|
||||
throw new JeroBootException("Unable to create XMLReader", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve the text for a group of elements. Each text element is an entry
|
||||
* in a list.
|
||||
* <p>This method is currently optimized for the use case of two elements in a list.
|
||||
*
|
||||
* @param xmlAsString the xml response
|
||||
* @param element the element to look for
|
||||
* @return the list of text from the elements.
|
||||
*/
|
||||
public static List<String> getTextForElements(final String xmlAsString, final String element) {
|
||||
final List<String> elements = new ArrayList<>(2);
|
||||
final XMLReader reader = getXmlReader();
|
||||
|
||||
final DefaultHandler handler = new DefaultHandler() {
|
||||
|
||||
private boolean foundElement = false;
|
||||
|
||||
private StringBuilder buffer = new StringBuilder();
|
||||
|
||||
@Override
|
||||
public void startElement(final String uri, final String localName, final String qName,
|
||||
final Attributes attributes) throws SAXException {
|
||||
if (localName.equals(element)) {
|
||||
this.foundElement = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endElement(final String uri, final String localName, final String qName) throws SAXException {
|
||||
if (localName.equals(element)) {
|
||||
this.foundElement = false;
|
||||
elements.add(this.buffer.toString());
|
||||
this.buffer = new StringBuilder();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void characters(char[] ch, int start, int length) throws SAXException {
|
||||
if (this.foundElement) {
|
||||
this.buffer.append(ch, start, length);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
reader.setContentHandler(handler);
|
||||
reader.setErrorHandler(handler);
|
||||
|
||||
try {
|
||||
reader.parse(new InputSource(new StringReader(xmlAsString)));
|
||||
} catch (final Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return elements;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the text for a specific element (when we know there is only
|
||||
* one).
|
||||
*
|
||||
* @param xmlAsString the xml response
|
||||
* @param element the element to look for
|
||||
* @return the text value of the element.
|
||||
*/
|
||||
public static String getTextForElement(final String xmlAsString, final String element) {
|
||||
final XMLReader reader = getXmlReader();
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
|
||||
final DefaultHandler handler = new DefaultHandler() {
|
||||
|
||||
private boolean foundElement = false;
|
||||
|
||||
@Override
|
||||
public void startElement(final String uri, final String localName, final String qName,
|
||||
final Attributes attributes) throws SAXException {
|
||||
if (localName.equals(element)) {
|
||||
this.foundElement = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endElement(final String uri, final String localName, final String qName) throws SAXException {
|
||||
if (localName.equals(element)) {
|
||||
this.foundElement = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void characters(char[] ch, int start, int length) throws SAXException {
|
||||
if (this.foundElement) {
|
||||
builder.append(ch, start, length);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
reader.setContentHandler(handler);
|
||||
reader.setErrorHandler(handler);
|
||||
|
||||
try {
|
||||
reader.parse(new InputSource(new StringReader(xmlAsString)));
|
||||
} catch (final Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
return null;
|
||||
}
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
|
||||
public static Map<String, Object> extractCustomAttributes(final String xml) {
|
||||
final SAXParserFactory spf = SAXParserFactory.newInstance();
|
||||
spf.setNamespaceAware(true);
|
||||
spf.setValidating(false);
|
||||
try {
|
||||
final SAXParser saxParser = spf.newSAXParser();
|
||||
final XMLReader xmlReader = saxParser.getXMLReader();
|
||||
final CustomAttributeHandler handler = new CustomAttributeHandler();
|
||||
xmlReader.setContentHandler(handler);
|
||||
xmlReader.parse(new InputSource(new StringReader(xml)));
|
||||
return handler.getAttributes();
|
||||
} catch (final Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
}
|
||||
|
||||
private static class CustomAttributeHandler extends DefaultHandler {
|
||||
|
||||
private Map<String, Object> attributes;
|
||||
|
||||
private boolean foundAttributes;
|
||||
|
||||
private String currentAttribute;
|
||||
|
||||
private StringBuilder value;
|
||||
|
||||
@Override
|
||||
public void startDocument() throws SAXException {
|
||||
this.attributes = new HashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startElement(final String namespaceURI, final String localName, final String qName,
|
||||
final Attributes attributes) throws SAXException {
|
||||
if ("attributes".equals(localName)) {
|
||||
this.foundAttributes = true;
|
||||
} else if (this.foundAttributes) {
|
||||
this.value = new StringBuilder();
|
||||
this.currentAttribute = localName;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void characters(final char[] chars, final int start, final int length) throws SAXException {
|
||||
if (this.currentAttribute != null) {
|
||||
value.append(chars, start, length);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endElement(final String namespaceURI, final String localName, final String qName)
|
||||
throws SAXException {
|
||||
if ("attributes".equals(localName)) {
|
||||
this.foundAttributes = false;
|
||||
this.currentAttribute = null;
|
||||
} else if (this.foundAttributes) {
|
||||
final Object o = this.attributes.get(this.currentAttribute);
|
||||
|
||||
if (o == null) {
|
||||
this.attributes.put(this.currentAttribute, this.value.toString());
|
||||
} else {
|
||||
final List<Object> items;
|
||||
if (o instanceof List) {
|
||||
items = (List<Object>) o;
|
||||
} else {
|
||||
items = new LinkedList<>();
|
||||
items.add(o);
|
||||
this.attributes.put(this.currentAttribute, items);
|
||||
}
|
||||
items.add(this.value.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Map<String, Object> getAttributes() {
|
||||
return this.attributes;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
String result = "<cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'>\r\n" +
|
||||
" <cas:authenticationSuccess>\r\n" +
|
||||
" <cas:user>admin</cas:user>\r\n" +
|
||||
" <cas:attributes>\r\n" +
|
||||
" <cas:credentialType>UsernamePasswordCredential</cas:credentialType>\r\n" +
|
||||
" <cas:isFromNewLogin>true</cas:isFromNewLogin>\r\n" +
|
||||
" <cas:authenticationDate>2019-08-01T19:33:21.527+08:00[Asia/Shanghai]</cas:authenticationDate>\r\n" +
|
||||
" <cas:authenticationMethod>RestAuthenticationHandler</cas:authenticationMethod>\r\n" +
|
||||
" <cas:successfulAuthenticationHandlers>RestAuthenticationHandler</cas:successfulAuthenticationHandlers>\r\n" +
|
||||
" <cas:longTermAuthenticationRequestTokenUsed>false</cas:longTermAuthenticationRequestTokenUsed>\r\n" +
|
||||
" </cas:attributes>\r\n" +
|
||||
" </cas:authenticationSuccess>\r\n" +
|
||||
"</cas:serviceResponse>";
|
||||
|
||||
String errorRes = "<cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'>\r\n" +
|
||||
" <cas:authenticationFailure code=\"INVALID_TICKET\">未能够识别出目标 'ST-5-1g-9cNES6KXNRwq-GuRET103sm0-DESKTOP-VKLS8B3'票根</cas:authenticationFailure>\r\n" +
|
||||
"</cas:serviceResponse>";
|
||||
|
||||
String error = XmlUtils.getTextForElement(errorRes, "authenticationFailure");
|
||||
log.info("------"+error);
|
||||
|
||||
String error2 = XmlUtils.getTextForElement(result, "authenticationFailure");
|
||||
log.info("------"+error2);
|
||||
String principal = XmlUtils.getTextForElement(result, "user");
|
||||
log.info("---principal---"+principal);
|
||||
Map<String, Object> attributes = XmlUtils.extractCustomAttributes(result);
|
||||
log.info("---attributes---"+attributes);
|
||||
}
|
||||
}
|
||||
+148
@@ -0,0 +1,148 @@
|
||||
package com.jero.modules.message.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.jero.common.api.vo.Results;
|
||||
import com.jero.common.system.base.controller.JeroController;
|
||||
import com.jero.common.system.query.QueryGenerator;
|
||||
import com.jero.modules.message.entity.SysMessage;
|
||||
import com.jero.modules.message.service.ISysMessageService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.poi.ss.formula.functions.T;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Description: 消息
|
||||
* @author: jero-boot
|
||||
* @date: 2019-04-09
|
||||
* @version: V1.0
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/sys/message/sysMessage")
|
||||
public class SysMessageController extends JeroController<SysMessage, ISysMessageService> {
|
||||
@Autowired
|
||||
private ISysMessageService sysMessageService;
|
||||
|
||||
/**
|
||||
* 分页列表查询
|
||||
*
|
||||
* @param sysMessage
|
||||
* @param pageNo
|
||||
* @param pageSize
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/page")
|
||||
@RequiresPermissions("message:list")
|
||||
public Results<IPage<SysMessage>> queryPageList(SysMessage sysMessage, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
|
||||
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest req) {
|
||||
QueryWrapper<SysMessage> queryWrapper = QueryGenerator.initQueryWrapper(sysMessage, req.getParameterMap());
|
||||
Page<SysMessage> page = new Page<>(pageNo, pageSize);
|
||||
IPage<SysMessage> pageList = sysMessageService.page(page, queryWrapper);
|
||||
return Results.OK(pageList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*
|
||||
* @param sysMessage
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/add")
|
||||
public Results<T> add(@RequestBody SysMessage sysMessage) {
|
||||
sysMessageService.save(sysMessage);
|
||||
return Results.OK("操作成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*
|
||||
* @param sysMessage
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/edit")
|
||||
public Results<T> edit(@RequestBody SysMessage sysMessage) {
|
||||
sysMessageService.updateById(sysMessage);
|
||||
return Results.OK("操作成功!");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id删除
|
||||
*
|
||||
* @param map
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/delete")
|
||||
@RequiresPermissions("message:del")
|
||||
public Results<T> delete(@RequestBody Map<String, String> map) {
|
||||
String id = map.get("id");
|
||||
if(StringUtils.isBlank(id)){
|
||||
return Results.error("参数不识别!");
|
||||
}
|
||||
sysMessageService.removeById(id);
|
||||
return Results.OK("删除成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
*
|
||||
* @param map
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/deleteBatch")
|
||||
public Results<T> deleteBatch(@RequestBody Map<String, String> map) {
|
||||
String ids = map.get("ids");
|
||||
if(StringUtils.isBlank(ids)){
|
||||
return Results.error("参数不识别!");
|
||||
}
|
||||
this.sysMessageService.removeByIds(Arrays.asList(ids.split(",")));
|
||||
return Results.OK("批量删除成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id查询
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/queryById")
|
||||
public Results<SysMessage> queryById(@RequestParam(name = "id", required = true) String id) {
|
||||
SysMessage sysMessage = sysMessageService.getById(id);
|
||||
return Results.OK(sysMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出excel
|
||||
*
|
||||
* @param request
|
||||
*/
|
||||
@GetMapping(value = "/exportXls")
|
||||
public ModelAndView exportXls(HttpServletRequest request, SysMessage sysMessage) {
|
||||
return super.exportXls(request, sysMessage, SysMessage.class, "推送消息模板");
|
||||
}
|
||||
|
||||
/**
|
||||
* excel导入
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/importExcel")
|
||||
public Results<SysMessage> importExcel(HttpServletRequest request, HttpServletResponse response) {
|
||||
return super.importExcel(request, response, SysMessage.class);
|
||||
}
|
||||
|
||||
}
|
||||
+175
@@ -0,0 +1,175 @@
|
||||
package com.jero.modules.message.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.jero.common.api.vo.Results;
|
||||
import com.jero.common.system.base.controller.JeroController;
|
||||
import com.jero.common.system.query.QueryGenerator;
|
||||
import com.jero.modules.message.entity.MsgParams;
|
||||
import com.jero.modules.message.entity.SysMessageTemplate;
|
||||
import com.jero.modules.message.service.ISysMessageTemplateService;
|
||||
import com.jero.modules.message.util.PushMsgUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.poi.ss.formula.functions.T;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Description: 消息模板
|
||||
* @Author: jero-boot
|
||||
* @Sate: 2019-04-09
|
||||
* @Version: V1.0
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/sys/message/sysMessageTemplate")
|
||||
public class SysMessageTemplateController extends JeroController<SysMessageTemplate, ISysMessageTemplateService> {
|
||||
@Autowired
|
||||
private ISysMessageTemplateService sysMessageTemplateService;
|
||||
@Autowired
|
||||
private PushMsgUtil pushMsgUtil;
|
||||
|
||||
/**
|
||||
* 分页列表查询
|
||||
*
|
||||
* @param sysMessageTemplate
|
||||
* @param pageNo
|
||||
* @param pageSize
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/page")
|
||||
@RequiresPermissions("message:template:list")
|
||||
public Results<IPage<SysMessageTemplate>> queryPageList(SysMessageTemplate sysMessageTemplate, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
|
||||
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest req) {
|
||||
QueryWrapper<SysMessageTemplate> queryWrapper = QueryGenerator.initQueryWrapper(sysMessageTemplate, req.getParameterMap());
|
||||
Page<SysMessageTemplate> page = new Page<>(pageNo, pageSize);
|
||||
IPage<SysMessageTemplate> pageList = sysMessageTemplateService.page(page, queryWrapper);
|
||||
return Results.OK(pageList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*
|
||||
* @param sysMessageTemplate
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/add")
|
||||
@RequiresPermissions("message:template:add")
|
||||
public Results<T> add(@RequestBody SysMessageTemplate sysMessageTemplate) {
|
||||
sysMessageTemplateService.save(sysMessageTemplate);
|
||||
return Results.OK("操作成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*
|
||||
* @param sysMessageTemplate
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/edit")
|
||||
@RequiresPermissions("message:template:edit")
|
||||
public Results<T> edit(@RequestBody SysMessageTemplate sysMessageTemplate) {
|
||||
sysMessageTemplateService.updateById(sysMessageTemplate);
|
||||
return Results.OK("更新成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id删除
|
||||
*
|
||||
* @param map
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/delete")
|
||||
@RequiresPermissions("message:template:del")
|
||||
public Results<T> delete(@RequestBody Map<String, String> map) {
|
||||
String id = map.get("id");
|
||||
if(StringUtils.isBlank(id)){
|
||||
return Results.error("参数不识别!");
|
||||
}
|
||||
sysMessageTemplateService.removeById(id);
|
||||
return Results.OK("删除成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
*
|
||||
* @param map
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/deleteBatch")
|
||||
public Results<T> deleteBatch(@RequestBody Map<String, String> map) {
|
||||
String ids = map.get("ids");
|
||||
if(StringUtils.isBlank(ids)){
|
||||
return Results.error("参数不识别!");
|
||||
}
|
||||
this.sysMessageTemplateService.removeByIds(Arrays.asList(ids.split(",")));
|
||||
return Results.OK("批量删除成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id查询
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/queryById")
|
||||
public Results<SysMessageTemplate> queryById(@RequestParam(name = "id", required = true) String id) {
|
||||
SysMessageTemplate sysMessageTemplate = sysMessageTemplateService.getById(id);
|
||||
return Results.OK(sysMessageTemplate);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出excel
|
||||
*
|
||||
* @param request
|
||||
*/
|
||||
@GetMapping(value = "/exportXls")
|
||||
@RequiresPermissions("message:template:export")
|
||||
public ModelAndView exportXls(HttpServletRequest request,SysMessageTemplate sysMessageTemplate) {
|
||||
return super.exportXls(request, sysMessageTemplate, SysMessageTemplate.class,"推送消息模板");
|
||||
}
|
||||
|
||||
/**
|
||||
* excel导入
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/importExcel")
|
||||
@RequiresPermissions("message:template:import")
|
||||
public Results<SysMessageTemplate> importExcel(HttpServletRequest request, HttpServletResponse response) {
|
||||
return super.importExcel(request, response, SysMessageTemplate.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送消息
|
||||
*/
|
||||
@PostMapping(value = "/sendMsg")
|
||||
@RequiresPermissions("message:template:send")
|
||||
public Results<Object> sendMessage(@RequestBody MsgParams msgParams) {
|
||||
Map<String, String> map = null;
|
||||
try {
|
||||
map = (Map<String, String>) JSON.parse(msgParams.getTestData());
|
||||
} catch (Exception e) {
|
||||
return Results.error("解析Json出错!");
|
||||
}
|
||||
boolean isSendSuccess = pushMsgUtil.sendMessage(msgParams.getMsgType(), msgParams.getTemplateCode(), map, msgParams.getReceiver());
|
||||
if (isSendSuccess) {
|
||||
return Results.OK("发送消息任务操作成功!");
|
||||
} else {
|
||||
return Results.error("发送消息任务添加失败!");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.jero.modules.message.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 发送消息实体
|
||||
*/
|
||||
@Data
|
||||
public class MsgParams implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
/*消息类型*/
|
||||
private String msgType;
|
||||
/*消息接收方*/
|
||||
private String receiver;
|
||||
/*消息模板码*/
|
||||
private String templateCode;
|
||||
/*测试数据*/
|
||||
private String testData;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.jero.modules.message.entity;
|
||||
|
||||
import com.jero.common.aspect.annotation.Dict;
|
||||
import com.jero.common.system.base.entity.JeroEntity;
|
||||
import cn.afterturn.easypoi.excel.annotation.Excel;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* @Description: 消息
|
||||
* @Author: jero-boot
|
||||
* @Date: 2019-04-09
|
||||
* @Version: V1.0
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Accessors(chain = true)
|
||||
@TableName("sys_sms")
|
||||
public class SysMessage extends JeroEntity {
|
||||
/**推送内容*/
|
||||
@Excel(name = "推送内容", width = 15)
|
||||
private java.lang.String esContent;
|
||||
/**推送所需参数Json格式*/
|
||||
@Excel(name = "推送所需参数Json格式", width = 15)
|
||||
private java.lang.String esParam;
|
||||
/**接收人*/
|
||||
@Excel(name = "接收人", width = 15)
|
||||
private java.lang.String esReceiver;
|
||||
/**推送失败原因*/
|
||||
@Excel(name = "推送失败原因", width = 15)
|
||||
private java.lang.String esResult;
|
||||
/**发送次数*/
|
||||
@Excel(name = "发送次数", width = 15)
|
||||
private java.lang.Integer esSendNum;
|
||||
/**推送状态 0未推送 1推送成功 2推送失败*/
|
||||
@Excel(name = "推送状态 0未推送 1推送成功 2推送失败", width = 15)
|
||||
@Dict(dicCode = "msgSendStatus")
|
||||
private java.lang.String esSendStatus;
|
||||
/**推送时间*/
|
||||
@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")
|
||||
private java.util.Date esSendTime;
|
||||
/**消息标题*/
|
||||
@Excel(name = "消息标题", width = 15)
|
||||
private java.lang.String esTitle;
|
||||
/**推送方式:1短信 2邮件 3微信*/
|
||||
@Excel(name = "推送方式:1短信 2邮件 3微信", width = 15)
|
||||
@Dict(dicCode = "msgType")
|
||||
private java.lang.String esType;
|
||||
/**备注*/
|
||||
@Excel(name = "备注", width = 15)
|
||||
private java.lang.String remark;
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
package com.jero.modules.message.entity;
|
||||
|
||||
import com.jero.common.system.base.entity.JeroEntity;
|
||||
import cn.afterturn.easypoi.excel.annotation.Excel;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* @Description: 消息模板
|
||||
* @Author: jero-boot
|
||||
* @Date: 2019-04-09
|
||||
* @Version: V1.0
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Accessors(chain = true)
|
||||
@TableName("sys_sms_template")
|
||||
public class SysMessageTemplate extends JeroEntity {
|
||||
/**模板CODE*/
|
||||
@Excel(name = "模板CODE", width = 15)
|
||||
private java.lang.String templateCode;
|
||||
/**模板标题*/
|
||||
@Excel(name = "模板标题", width = 30)
|
||||
private java.lang.String templateName;
|
||||
/**模板内容*/
|
||||
@Excel(name = "模板内容", width = 50)
|
||||
private java.lang.String templateContent;
|
||||
/**模板测试json*/
|
||||
/*@Excel(name = "模板测试json", width = 15)
|
||||
private java.lang.String templateTestJson;*/
|
||||
/**模板类型*/
|
||||
@Excel(name = "模板类型", width = 15)
|
||||
private java.lang.String templateType;
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
package com.jero.modules.message.handle;
|
||||
|
||||
public interface ISendMsgHandle {
|
||||
|
||||
void SendMsg(String esReceiver, String esTitle, String esContent);
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
package com.jero.modules.message.handle.enums;
|
||||
|
||||
/**
|
||||
* 推送状态枚举
|
||||
*/
|
||||
public enum SendMsgStatusEnum {
|
||||
|
||||
//推送状态 0未推送 1推送成功 2推送失败
|
||||
WAIT("0"), SUCCESS("1"), FAIL("2");
|
||||
|
||||
private String code;
|
||||
|
||||
private SendMsgStatusEnum(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setStatusCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
package com.jero.modules.message.handle.enums;
|
||||
|
||||
import com.jero.common.util.oConvertUtils;
|
||||
|
||||
/**
|
||||
* 发送消息类型枚举
|
||||
*/
|
||||
public enum SendMsgTypeEnum {
|
||||
|
||||
//推送方式:1短信 2邮件 3微信
|
||||
SMS("1", "com.jero.modules.message.handle.impl.SmsSendMsgHandle"),
|
||||
EMAIL("2", "com.jero.modules.message.handle.impl.EmailSendMsgHandle"),
|
||||
WX("3","com.jero.modules.message.handle.impl.WxSendMsgHandle");
|
||||
|
||||
private String type;
|
||||
|
||||
private String implClass;
|
||||
|
||||
private SendMsgTypeEnum(String type, String implClass) {
|
||||
this.type = type;
|
||||
this.implClass = implClass;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getImplClass() {
|
||||
return implClass;
|
||||
}
|
||||
|
||||
public void setImplClass(String implClass) {
|
||||
this.implClass = implClass;
|
||||
}
|
||||
|
||||
public static SendMsgTypeEnum getByType(String type) {
|
||||
if (oConvertUtils.isEmpty(type)) {
|
||||
return null;
|
||||
}
|
||||
for (SendMsgTypeEnum val : values()) {
|
||||
if (val.getType().equals(type)) {
|
||||
return val;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
package com.jero.modules.message.handle.impl;
|
||||
|
||||
import com.jero.common.util.SpringContextUtils;
|
||||
import com.jero.common.util.oConvertUtils;
|
||||
import com.jero.config.StaticConfig;
|
||||
import com.jero.modules.message.handle.ISendMsgHandle;
|
||||
import org.springframework.mail.javamail.JavaMailSender;
|
||||
import org.springframework.mail.javamail.MimeMessageHelper;
|
||||
|
||||
import javax.mail.MessagingException;
|
||||
import javax.mail.internet.MimeMessage;
|
||||
|
||||
public class EmailSendMsgHandle implements ISendMsgHandle {
|
||||
static String emailFrom;
|
||||
|
||||
public static void setEmailFrom(String emailFrom) {
|
||||
EmailSendMsgHandle.emailFrom = emailFrom;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void SendMsg(String esReceiver, String esTitle, String esContent) {
|
||||
JavaMailSender mailSender = (JavaMailSender) SpringContextUtils.getBean("mailSender");
|
||||
MimeMessage message = mailSender.createMimeMessage();
|
||||
MimeMessageHelper helper = null;
|
||||
//update-begin-author:taoyan date:20200811 for:配置类数据获取
|
||||
if(oConvertUtils.isEmpty(emailFrom)){
|
||||
StaticConfig staticConfig = SpringContextUtils.getBean(StaticConfig.class);
|
||||
setEmailFrom(staticConfig.getEmailFrom());
|
||||
}
|
||||
//update-end-author:taoyan date:20200811 for:配置类数据获取
|
||||
try {
|
||||
helper = new MimeMessageHelper(message, true);
|
||||
// 设置发送方邮箱地址
|
||||
helper.setFrom(emailFrom);
|
||||
helper.setTo(esReceiver);
|
||||
helper.setSubject(esTitle);
|
||||
helper.setText(esContent, true);
|
||||
mailSender.send(message);
|
||||
} catch (MessagingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package com.jero.modules.message.handle.impl;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import com.jero.modules.message.handle.ISendMsgHandle;
|
||||
|
||||
@Slf4j
|
||||
public class SmsSendMsgHandle implements ISendMsgHandle {
|
||||
|
||||
@Override
|
||||
public void SendMsg(String esReceiver, String esTitle, String esContent) {
|
||||
log.info("发短信");
|
||||
}
|
||||
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package com.jero.modules.message.handle.impl;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import com.jero.modules.message.handle.ISendMsgHandle;
|
||||
@Slf4j
|
||||
public class WxSendMsgHandle implements ISendMsgHandle {
|
||||
|
||||
@Override
|
||||
public void SendMsg(String esReceiver, String esTitle, String esContent) {
|
||||
log.info("发微信消息模板");
|
||||
}
|
||||
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package com.jero.modules.message.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.jero.modules.message.entity.SysMessage;
|
||||
|
||||
/**
|
||||
* @Description: 消息
|
||||
* @Author: jero-boot
|
||||
* @Date: 2019-04-09
|
||||
* @Version: V1.0
|
||||
*/
|
||||
public interface SysMessageMapper extends BaseMapper<SysMessage> {
|
||||
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
package com.jero.modules.message.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import com.jero.modules.message.entity.SysMessageTemplate;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description: 消息模板
|
||||
* @Author: jero-boot
|
||||
* @Date: 2019-04-09
|
||||
* @Version: V1.0
|
||||
*/
|
||||
public interface SysMessageTemplateMapper extends BaseMapper<SysMessageTemplate> {
|
||||
@Select("SELECT * FROM SYS_SMS_TEMPLATE WHERE TEMPLATE_CODE = #{code}")
|
||||
List<SysMessageTemplate> selectByCode(String code);
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.jero.modules.message.mapper.SysMessageMapper">
|
||||
|
||||
</mapper>
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.jero.modules.message.mapper.SysMessageTemplateMapper">
|
||||
|
||||
</mapper>
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package com.jero.modules.message.service;
|
||||
|
||||
import com.jero.common.system.base.service.JeroService;
|
||||
import com.jero.modules.message.entity.SysMessage;
|
||||
|
||||
/**
|
||||
* @Description: 消息
|
||||
* @Author: jero-boot
|
||||
* @Date: 2019-04-09
|
||||
* @Version: V1.0
|
||||
*/
|
||||
public interface ISysMessageService extends JeroService<SysMessage> {
|
||||
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package com.jero.modules.message.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.jero.common.system.base.service.JeroService;
|
||||
import com.jero.modules.message.entity.SysMessageTemplate;
|
||||
|
||||
/**
|
||||
* @Description: 消息模板
|
||||
* @Author: jero-boot
|
||||
* @Date: 2019-04-09
|
||||
* @Version: V1.0
|
||||
*/
|
||||
public interface ISysMessageTemplateService extends JeroService<SysMessageTemplate> {
|
||||
List<SysMessageTemplate> selectByCode(String code);
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
package com.jero.modules.message.service.impl;
|
||||
|
||||
import com.jero.common.system.base.service.impl.JeroServiceImpl;
|
||||
import com.jero.modules.message.entity.SysMessage;
|
||||
import com.jero.modules.message.mapper.SysMessageMapper;
|
||||
import com.jero.modules.message.service.ISysMessageService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @Description: 消息
|
||||
* @Author: jero-boot
|
||||
* @Date: 2019-04-09
|
||||
* @Version: V1.0
|
||||
*/
|
||||
@Service
|
||||
public class SysMessageServiceImpl extends JeroServiceImpl<SysMessageMapper, SysMessage> implements ISysMessageService {
|
||||
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package com.jero.modules.message.service.impl;
|
||||
|
||||
import com.jero.common.system.base.service.impl.JeroServiceImpl;
|
||||
import com.jero.modules.message.entity.SysMessageTemplate;
|
||||
import com.jero.modules.message.mapper.SysMessageTemplateMapper;
|
||||
import com.jero.modules.message.service.ISysMessageTemplateService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description: 消息模板
|
||||
* @Author: jero-boot
|
||||
* @Date: 2019-04-09
|
||||
* @Version: V1.0
|
||||
*/
|
||||
@Service
|
||||
public class SysMessageTemplateServiceImpl extends JeroServiceImpl<SysMessageTemplateMapper, SysMessageTemplate> implements ISysMessageTemplateService {
|
||||
|
||||
@Autowired
|
||||
private SysMessageTemplateMapper sysMessageTemplateMapper;
|
||||
|
||||
|
||||
@Override
|
||||
public List<SysMessageTemplate> selectByCode(String code) {
|
||||
return sysMessageTemplateMapper.selectByCode(code);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package com.jero.modules.message.util;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.jero.modules.message.entity.SysMessage;
|
||||
import com.jero.modules.message.entity.SysMessageTemplate;
|
||||
import com.jero.modules.message.handle.enums.SendMsgStatusEnum;
|
||||
import com.jero.modules.message.service.ISysMessageService;
|
||||
import com.jero.modules.message.service.ISysMessageTemplateService;
|
||||
import freemarker.template.Configuration;
|
||||
import freemarker.template.Template;
|
||||
import freemarker.template.TemplateException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 消息生成工具
|
||||
*/
|
||||
|
||||
@Component
|
||||
public class PushMsgUtil {
|
||||
|
||||
@Autowired
|
||||
private ISysMessageService sysMessageService;
|
||||
|
||||
@Autowired
|
||||
private ISysMessageTemplateService sysMessageTemplateService;
|
||||
|
||||
@Autowired
|
||||
private Configuration freemarkerConfig;
|
||||
/**
|
||||
* @param msgType 消息类型 1短信 2邮件 3微信
|
||||
* @param templateCode 消息模板码
|
||||
* @param map 消息参数
|
||||
* @param sentTo 接收消息方
|
||||
*/
|
||||
public boolean sendMessage(String msgType, String templateCode, Map<String, String> map, String sentTo) {
|
||||
List<SysMessageTemplate> sysSmsTemplates = sysMessageTemplateService.selectByCode(templateCode);
|
||||
SysMessage sysMessage = new SysMessage();
|
||||
if (!sysSmsTemplates.isEmpty()) {
|
||||
SysMessageTemplate sysSmsTemplate = sysSmsTemplates.get(0);
|
||||
sysMessage.setEsType(msgType);
|
||||
sysMessage.setEsReceiver(sentTo);
|
||||
//模板标题
|
||||
String title = sysSmsTemplate.getTemplateName();
|
||||
//模板内容
|
||||
String content = sysSmsTemplate.getTemplateContent();
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
Template template = null;
|
||||
try {
|
||||
template = new Template("SysMessageTemplate", content, freemarkerConfig);
|
||||
template.process(map, stringWriter);
|
||||
} catch (IOException |TemplateException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
content = stringWriter.toString();
|
||||
sysMessage.setEsTitle(title);
|
||||
sysMessage.setEsContent(content);
|
||||
sysMessage.setEsParam(JSON.toJSONString(map));
|
||||
sysMessage.setEsSendTime(new Date());
|
||||
sysMessage.setEsSendStatus(SendMsgStatusEnum.WAIT.getCode());
|
||||
sysMessage.setEsSendNum(0);
|
||||
if(sysMessageService.save(sysMessage)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package com.jero.modules.message.websocket;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.jero.common.constant.CommonSendStatus;
|
||||
import com.jero.common.modules.redis.listener.JeroRedisListerer;
|
||||
import com.jero.common.base.BaseMap;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 监听消息(采用redis发布订阅方式发送消息)
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class SocketHandler implements JeroRedisListerer {
|
||||
|
||||
@Autowired
|
||||
private WebSocket webSocket;
|
||||
|
||||
@Override
|
||||
public void onMessage(BaseMap map) {
|
||||
log.info("【SocketHandler消息】Redis Listerer:" + map.toString());
|
||||
|
||||
String userId = map.get("userId");
|
||||
String message = map.get("message");
|
||||
if (ObjectUtil.isNotEmpty(userId)) {
|
||||
webSocket.pushMessage(userId, message);
|
||||
//app端消息推送
|
||||
webSocket.pushMessage(userId + CommonSendStatus.APP_SESSION_SUFFIX, message);
|
||||
} else {
|
||||
webSocket.pushMessage(message);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
package com.jero.modules.message.websocket;
|
||||
|
||||
import com.jero.common.api.vo.Results;
|
||||
import com.jero.common.constant.WebsocketConst;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/sys/socketTest")
|
||||
public class TestSocketController {
|
||||
|
||||
@Autowired
|
||||
private WebSocket webSocket;
|
||||
|
||||
@PostMapping("/sendAll")
|
||||
public Results<String> sendAll(@RequestBody JSONObject jsonObject) {
|
||||
Results<String> result = new Results<>();
|
||||
String message = jsonObject.getString("message");
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put(WebsocketConst.MSG_CMD, WebsocketConst.CMD_TOPIC);
|
||||
obj.put(WebsocketConst.MSG_ID, "M0001");
|
||||
obj.put(WebsocketConst.MSG_TXT, message);
|
||||
webSocket.sendMessage(obj.toJSONString());
|
||||
result.setResult("群发!");
|
||||
return result;
|
||||
}
|
||||
|
||||
@PostMapping("/sendUser")
|
||||
public Results<String> sendUser(@RequestBody JSONObject jsonObject) {
|
||||
Results<String> result = new Results<>();
|
||||
String userId = jsonObject.getString("userId");
|
||||
String message = jsonObject.getString("message");
|
||||
JSONObject obj = new JSONObject();
|
||||
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.sendMessage(userId, obj.toJSONString());
|
||||
result.setResult("单发");
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
+157
@@ -0,0 +1,157 @@
|
||||
package com.jero.modules.message.websocket;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CopyOnWriteArraySet;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.websocket.OnClose;
|
||||
import javax.websocket.OnMessage;
|
||||
import javax.websocket.OnOpen;
|
||||
import javax.websocket.Session;
|
||||
import javax.websocket.server.PathParam;
|
||||
import javax.websocket.server.ServerEndpoint;
|
||||
|
||||
import com.jero.common.modules.redis.client.JeroRedisClient;
|
||||
import com.jero.common.base.BaseMap;
|
||||
import com.jero.common.constant.WebsocketConst;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* @Author scott
|
||||
* @Date 2019/11/29 9:41
|
||||
* @Description: 此注解相当于设置访问URL
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
@ServerEndpoint("/websocket/{userId}") //此注解相当于设置访问URL
|
||||
public class WebSocket {
|
||||
|
||||
private Session session;
|
||||
|
||||
private String userId;
|
||||
|
||||
private static final String REDIS_TOPIC_NAME = "socketHandler";
|
||||
|
||||
@Resource
|
||||
private JeroRedisClient jeroRedisClient;
|
||||
|
||||
/**
|
||||
* 缓存 webSocket连接到单机服务class中(整体方案支持集群)
|
||||
*/
|
||||
private static CopyOnWriteArraySet<WebSocket> webSockets = new CopyOnWriteArraySet<>();
|
||||
private static Map<String, Session> sessionPool = new HashMap<>();
|
||||
|
||||
|
||||
@OnOpen
|
||||
public void onOpen(Session session, @PathParam(value = "userId") String userId) {
|
||||
try {
|
||||
this.session = session;
|
||||
this.userId = userId;
|
||||
webSockets.add(this);
|
||||
sessionPool.put(userId, session);
|
||||
log.info("【websocket消息】有新的连接,总数为:" + webSockets.size());
|
||||
} catch (Exception e) {
|
||||
log.error("异常",e);
|
||||
}
|
||||
}
|
||||
|
||||
@OnClose
|
||||
public void onClose() {
|
||||
try {
|
||||
webSockets.remove(this);
|
||||
sessionPool.remove(this.userId);
|
||||
log.info("【websocket消息】连接断开,总数为:" + webSockets.size());
|
||||
} catch (Exception e) {
|
||||
log.error("异常",e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 服务端推送消息
|
||||
*
|
||||
* @param userId
|
||||
* @param message
|
||||
*/
|
||||
public void pushMessage(String userId, String message) {
|
||||
Session s = sessionPool.get(userId);
|
||||
if (s != null && s.isOpen()) {
|
||||
try {
|
||||
log.info("【websocket消息】 单点消息:" + message);
|
||||
s.getAsyncRemote().sendText(message);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 服务器端推送消息
|
||||
*/
|
||||
public void pushMessage(String message) {
|
||||
try {
|
||||
webSockets.forEach(ws -> ws.session.getAsyncRemote().sendText(message));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@OnMessage
|
||||
public void onMessage(String message) {
|
||||
//todo 现在有个定时任务刷,应该去掉
|
||||
log.debug("【websocket消息】收到客户端消息:" + message);
|
||||
JSONObject obj = new JSONObject();
|
||||
//业务类型
|
||||
obj.put(WebsocketConst.MSG_CMD, WebsocketConst.CMD_CHECK);
|
||||
//消息内容
|
||||
obj.put(WebsocketConst.MSG_TXT, "心跳响应");
|
||||
for (WebSocket webSocket : webSockets) {
|
||||
webSocket.pushMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 后台发送消息到redis
|
||||
*
|
||||
* @param message
|
||||
*/
|
||||
public void sendMessage(String message) {
|
||||
log.info("【websocket消息】广播消息:" + message);
|
||||
BaseMap baseMap = new BaseMap();
|
||||
baseMap.put("userId", "");
|
||||
baseMap.put("message", message);
|
||||
jeroRedisClient.sendMessage(REDIS_TOPIC_NAME, baseMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* 此为单点消息
|
||||
*
|
||||
* @param userId
|
||||
* @param message
|
||||
*/
|
||||
public void sendMessage(String userId, String message) {
|
||||
BaseMap baseMap = new BaseMap();
|
||||
baseMap.put("userId", userId);
|
||||
baseMap.put("message", message);
|
||||
jeroRedisClient.sendMessage(REDIS_TOPIC_NAME, baseMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* 此为单点消息(多人)
|
||||
*
|
||||
* @param userIds
|
||||
* @param message
|
||||
*/
|
||||
public void sendMessage(String[] userIds, String message) {
|
||||
for (String uId : userIds) {
|
||||
sendMessage(uId, message);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+120
@@ -0,0 +1,120 @@
|
||||
package com.jero.modules.monitor.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.jero.common.api.vo.Results;
|
||||
import com.jero.modules.monitor.domain.RedisInfo;
|
||||
import com.jero.modules.monitor.exception.RedisConnectException;
|
||||
import com.jero.modules.monitor.service.RedisService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.swing.filechooser.FileSystemView;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/sys/actuator/redis")
|
||||
public class ActuatorRedisController {
|
||||
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
/**
|
||||
* Redis详细信息
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
@GetMapping("/info")
|
||||
public Results<List<RedisInfo>> getRedisInfo() throws RedisConnectException {
|
||||
List<RedisInfo> infoList = this.redisService.getRedisInfo();
|
||||
log.info(infoList.toString());
|
||||
return Results.OK(infoList);
|
||||
}
|
||||
|
||||
@GetMapping("/keysSize")
|
||||
public Map<String, Object> getKeysSize() throws RedisConnectException {
|
||||
return redisService.getKeysSize();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取redis key数量 for 报表
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
@GetMapping("/keysSizeForReport")
|
||||
public Map<String, JSONArray> getKeysSizeReport() throws RedisConnectException {
|
||||
return redisService.getMapForReport("1");
|
||||
}
|
||||
/**
|
||||
* 获取redis 内存 for 报表
|
||||
*
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
@GetMapping("/memoryForReport")
|
||||
public Map<String, JSONArray> memoryForReport() throws RedisConnectException {
|
||||
return redisService.getMapForReport("2");
|
||||
}
|
||||
/**
|
||||
* 获取redis 全部信息 for 报表
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
@GetMapping("/infoForReport")
|
||||
public Map<String, JSONArray> infoForReport() throws RedisConnectException {
|
||||
return redisService.getMapForReport("3");
|
||||
}
|
||||
|
||||
@GetMapping("/memoryInfo")
|
||||
public Map<String, Object> getMemoryInfo() throws RedisConnectException {
|
||||
return redisService.getMemoryInfo();
|
||||
}
|
||||
|
||||
//update-begin--Author:zhangweijian Date:20190425 for:获取磁盘信息
|
||||
/**
|
||||
* @功能:获取磁盘信息
|
||||
* @param request
|
||||
* @param response
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/queryDiskInfo")
|
||||
public Results<List<Map<String,Object>>> queryDiskInfo(HttpServletRequest request, HttpServletResponse response){
|
||||
Results<List<Map<String,Object>>> res = new Results<>();
|
||||
try {
|
||||
// 当前文件系统类
|
||||
FileSystemView fsv = FileSystemView.getFileSystemView();
|
||||
// 列出所有windows 磁盘
|
||||
File[] fs = File.listRoots();
|
||||
log.info("查询磁盘信息:"+fs.length+"个");
|
||||
List<Map<String,Object>> list = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < fs.length; i++) {
|
||||
if(fs[i].getTotalSpace()==0) {
|
||||
continue;
|
||||
}
|
||||
Map<String,Object> map = new HashMap<>();
|
||||
map.put("name", fsv.getSystemDisplayName(fs[i]));
|
||||
map.put("max", fs[i].getTotalSpace());
|
||||
map.put("rest", fs[i].getFreeSpace());
|
||||
map.put("restPPT", (fs[i].getTotalSpace()-fs[i].getFreeSpace())*100/fs[i].getTotalSpace());
|
||||
list.add(map);
|
||||
log.info(map.toString());
|
||||
}
|
||||
res.setResult(list);
|
||||
res.setMessage("查询成功");
|
||||
} catch (Exception e) {
|
||||
return Results.error("查询失败"+e.getMessage());
|
||||
}
|
||||
return res;
|
||||
}
|
||||
//update-end--Author:zhangweijian Date:20190425 for:获取磁盘信息
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
package com.jero.modules.monitor.domain;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class RedisInfo {
|
||||
|
||||
private static Map<String, String> map = new HashMap<>();
|
||||
|
||||
static {
|
||||
map.put("redis_version", "Redis 服务器版本");
|
||||
map.put("redis_git_sha1", "Git SHA1");
|
||||
map.put("redis_git_dirty", "Git dirty flag");
|
||||
map.put("os", "Redis 服务器的宿主操作系统");
|
||||
map.put("arch_bits", " 架构(32 或 64 位)");
|
||||
map.put("multiplexing_api", "Redis 所使用的事件处理机制");
|
||||
map.put("gcc_version", "编译 Redis 时所使用的 GCC 版本");
|
||||
map.put("process_id", "服务器进程的 PID");
|
||||
map.put("run_id", "Redis 服务器的随机标识符(用于 Sentinel 和集群)");
|
||||
map.put("tcp_port", "TCP/IP 监听端口");
|
||||
map.put("uptime_in_seconds", "自 Redis 服务器启动以来,经过的秒数");
|
||||
map.put("uptime_in_days", "自 Redis 服务器启动以来,经过的天数");
|
||||
map.put("lru_clock", " 以分钟为单位进行自增的时钟,用于 LRU 管理");
|
||||
map.put("connected_clients", "已连接客户端的数量(不包括通过从属服务器连接的客户端)");
|
||||
map.put("client_longest_output_list", "当前连接的客户端当中,最长的输出列表");
|
||||
map.put("client_longest_input_buf", "当前连接的客户端当中,最大输入缓存");
|
||||
map.put("blocked_clients", "正在等待阻塞命令(BLPOP、BRPOP、BRPOPLPUSH)的客户端的数量");
|
||||
map.put("used_memory", "由 Redis 分配器分配的内存总量,以字节(byte)为单位");
|
||||
map.put("used_memory_human", "以人类可读的格式返回 Redis 分配的内存总量");
|
||||
map.put("used_memory_rss", "从操作系统的角度,返回 Redis 已分配的内存总量(俗称常驻集大小)。这个值和 top 、 ps 等命令的输出一致");
|
||||
map.put("used_memory_peak", " Redis 的内存消耗峰值(以字节为单位)");
|
||||
map.put("used_memory_peak_human", "以人类可读的格式返回 Redis 的内存消耗峰值");
|
||||
map.put("used_memory_lua", "Lua 引擎所使用的内存大小(以字节为单位)");
|
||||
map.put("mem_fragmentation_ratio", "sed_memory_rss 和 used_memory 之间的比率");
|
||||
map.put("mem_allocator", "在编译时指定的, Redis 所使用的内存分配器。可以是 libc 、 jemalloc 或者 tcmalloc");
|
||||
|
||||
map.put("redis_build_id", "redis_build_id");
|
||||
map.put("redis_mode", "运行模式,单机(standalone)或者集群(cluster)");
|
||||
map.put("atomicvar_api", "atomicvar_api");
|
||||
map.put("hz", "redis内部调度(进行关闭timeout的客户端,删除过期key等等)频率,程序规定serverCron每秒运行10次。");
|
||||
map.put("executable", "server脚本目录");
|
||||
map.put("config_file", "配置文件目录");
|
||||
map.put("client_biggest_input_buf", "当前连接的客户端当中,最大输入缓存,用client list命令观察qbuf和qbuf-free两个字段最大值");
|
||||
map.put("used_memory_rss_human", "以人类可读的方式返回 Redis 已分配的内存总量");
|
||||
map.put("used_memory_peak_perc", "内存使用率峰值");
|
||||
map.put("total_system_memory", "系统总内存");
|
||||
map.put("total_system_memory_human", "以人类可读的方式返回系统总内存");
|
||||
map.put("used_memory_lua_human", "以人类可读的方式返回Lua 引擎所使用的内存大小");
|
||||
map.put("maxmemory", "最大内存限制,0表示无限制");
|
||||
map.put("maxmemory_human", "以人类可读的方式返回最大限制内存");
|
||||
map.put("maxmemory_policy", "超过内存限制后的处理策略");
|
||||
map.put("loading", "服务器是否正在载入持久化文件");
|
||||
map.put("rdb_changes_since_last_save", "离最近一次成功生成rdb文件,写入命令的个数,即有多少个写入命令没有持久化");
|
||||
map.put("rdb_bgsave_in_progress", "服务器是否正在创建rdb文件");
|
||||
map.put("rdb_last_save_time", "离最近一次成功创建rdb文件的时间戳。当前时间戳 - rdb_last_save_time=多少秒未成功生成rdb文件");
|
||||
map.put("rdb_last_bgsave_status", "最近一次rdb持久化是否成功");
|
||||
map.put("rdb_last_bgsave_time_sec", "最近一次成功生成rdb文件耗时秒数");
|
||||
map.put("rdb_current_bgsave_time_sec", "如果服务器正在创建rdb文件,那么这个域记录的就是当前的创建操作已经耗费的秒数");
|
||||
map.put("aof_enabled", "是否开启了aof");
|
||||
map.put("aof_rewrite_in_progress", "标识aof的rewrite操作是否在进行中");
|
||||
map.put("aof_rewrite_scheduled", "rewrite任务计划,当客户端发送bgrewriteaof指令,如果当前rewrite子进程正在执行,那么将客户端请求的bgrewriteaof变为计划任务,待aof子进程结束后执行rewrite ");
|
||||
|
||||
map.put("aof_last_rewrite_time_sec", "最近一次aof rewrite耗费的时长");
|
||||
map.put("aof_current_rewrite_time_sec", "如果rewrite操作正在进行,则记录所使用的时间,单位秒");
|
||||
map.put("aof_last_bgrewrite_status", "上次bgrewrite aof操作的状态");
|
||||
map.put("aof_last_write_status", "上次aof写入状态");
|
||||
|
||||
map.put("total_commands_processed", "redis处理的命令数");
|
||||
map.put("total_connections_received", "新创建连接个数,如果新创建连接过多,过度地创建和销毁连接对性能有影响,说明短连接严重或连接池使用有问题,需调研代码的连接设置");
|
||||
map.put("instantaneous_ops_per_sec", "redis当前的qps,redis内部较实时的每秒执行的命令数");
|
||||
map.put("total_net_input_bytes", "redis网络入口流量字节数");
|
||||
map.put("total_net_output_bytes", "redis网络出口流量字节数");
|
||||
|
||||
map.put("instantaneous_input_kbps", "redis网络入口kps");
|
||||
map.put("instantaneous_output_kbps", "redis网络出口kps");
|
||||
map.put("rejected_connections", "拒绝的连接个数,redis连接个数达到maxclients限制,拒绝新连接的个数");
|
||||
map.put("sync_full", "主从完全同步成功次数");
|
||||
|
||||
map.put("sync_partial_ok", "主从部分同步成功次数");
|
||||
map.put("sync_partial_err", "主从部分同步失败次数");
|
||||
map.put("expired_keys", "运行以来过期的key的数量");
|
||||
map.put("evicted_keys", "运行以来剔除(超过了maxmemory后)的key的数量");
|
||||
map.put("keyspace_hits", "命中次数");
|
||||
map.put("keyspace_misses", "没命中次数");
|
||||
map.put("pubsub_channels", "当前使用中的频道数量");
|
||||
map.put("pubsub_patterns", "当前使用的模式的数量");
|
||||
map.put("latest_fork_usec", "最近一次fork操作阻塞redis进程的耗时数,单位微秒");
|
||||
map.put("role", "实例的角色,是master or slave");
|
||||
map.put("connected_slaves", "连接的slave实例个数");
|
||||
map.put("master_repl_offset", "主从同步偏移量,此值如果和上面的offset相同说明主从一致没延迟");
|
||||
map.put("repl_backlog_active", "复制积压缓冲区是否开启");
|
||||
map.put("repl_backlog_size", "复制积压缓冲大小");
|
||||
map.put("repl_backlog_first_byte_offset", "复制缓冲区里偏移量的大小");
|
||||
map.put("repl_backlog_histlen", "此值等于 master_repl_offset - repl_backlog_first_byte_offset,该值不会超过repl_backlog_size的大小");
|
||||
map.put("used_cpu_sys", "将所有redis主进程在核心态所占用的CPU时求和累计起来");
|
||||
map.put("used_cpu_user", "将所有redis主进程在用户态所占用的CPU时求和累计起来");
|
||||
map.put("used_cpu_sys_children", "将后台进程在核心态所占用的CPU时求和累计起来");
|
||||
map.put("used_cpu_user_children", "将后台进程在用户态所占用的CPU时求和累计起来");
|
||||
map.put("cluster_enabled", "实例是否启用集群模式");
|
||||
map.put("db0", "db0的key的数量,以及带有生存期的key的数,平均存活时间");
|
||||
|
||||
}
|
||||
|
||||
private String key;
|
||||
private String value;
|
||||
private String description;
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
this.description = map.get(this.key);
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "RedisInfo{" + "key='" + key + '\'' + ", value='" + value + '\'' + ", desctiption='" + description + '\'' + '}';
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package com.jero.modules.monitor.exception;
|
||||
|
||||
/**
|
||||
* Redis 连接异常
|
||||
*/
|
||||
public class RedisConnectException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = 1639374111871115063L;
|
||||
|
||||
public RedisConnectException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
package com.jero.modules.monitor.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.jero.modules.monitor.domain.RedisInfo;
|
||||
import com.jero.modules.monitor.exception.RedisConnectException;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface RedisService {
|
||||
|
||||
/**
|
||||
* 获取 redis 的详细信息
|
||||
*
|
||||
* @return List
|
||||
*/
|
||||
List<RedisInfo> getRedisInfo() throws RedisConnectException;
|
||||
|
||||
/**
|
||||
* 获取 redis key 数量
|
||||
*
|
||||
* @return Map
|
||||
*/
|
||||
Map<String, Object> getKeysSize() throws RedisConnectException;
|
||||
|
||||
/**
|
||||
* 获取 redis 内存信息
|
||||
*
|
||||
* @return Map
|
||||
*/
|
||||
Map<String, Object> getMemoryInfo() throws RedisConnectException;
|
||||
/**
|
||||
* 获取 报表需要个redis信息
|
||||
*
|
||||
* @return Map
|
||||
*/
|
||||
Map<String, JSONArray> getMapForReport(String type) throws RedisConnectException ;
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package com.jero.modules.monitor.service.impl;
|
||||
|
||||
import org.springframework.boot.actuate.health.Health;
|
||||
import org.springframework.boot.actuate.health.HealthIndicator;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 功能说明:自定义邮件检测
|
||||
*
|
||||
* @author: 李波
|
||||
* @email: 503378406@qq.com
|
||||
* @date: 2019-06-29
|
||||
*/
|
||||
@Component
|
||||
public class MailHealthIndicator implements HealthIndicator {
|
||||
|
||||
private static final int BEST_NUMBER = 0;
|
||||
|
||||
|
||||
@Override public Health health() {
|
||||
int errorCode = check();
|
||||
if (errorCode != 0) {
|
||||
return Health.down().withDetail("Error Code", errorCode) .build();
|
||||
}
|
||||
return Health.up().build();
|
||||
}
|
||||
int check(){
|
||||
//可以实现自定义的数据库检测逻辑
|
||||
return BEST_NUMBER;
|
||||
}
|
||||
}
|
||||
+119
@@ -0,0 +1,119 @@
|
||||
package com.jero.modules.monitor.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.jero.common.util.oConvertUtils;
|
||||
import com.jero.modules.monitor.domain.RedisInfo;
|
||||
import com.jero.modules.monitor.exception.RedisConnectException;
|
||||
import com.jero.modules.monitor.service.RedisService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.cglib.beans.BeanMap;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Redis 监控信息获取
|
||||
*
|
||||
* @Author MrBird
|
||||
*/
|
||||
@Service("redisService")
|
||||
@Slf4j
|
||||
public class RedisServiceImpl implements RedisService {
|
||||
|
||||
private static final String CREATE_TIME ="create_time";
|
||||
private static final String USER_MEMORY ="used_memory";
|
||||
@Resource
|
||||
private RedisConnectionFactory redisConnectionFactory;
|
||||
|
||||
/**
|
||||
* Redis详细信息
|
||||
*/
|
||||
@Override
|
||||
public List<RedisInfo> getRedisInfo() throws RedisConnectException {
|
||||
Properties info = redisConnectionFactory.getConnection().info();
|
||||
if(info==null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
List<RedisInfo> infoList = new ArrayList<>();
|
||||
RedisInfo redisInfo = null;
|
||||
for (Map.Entry<Object, Object> entry : info.entrySet()) {
|
||||
redisInfo = new RedisInfo();
|
||||
redisInfo.setKey(oConvertUtils.getString(entry.getKey()));
|
||||
redisInfo.setValue(oConvertUtils.getString(entry.getValue()));
|
||||
infoList.add(redisInfo);
|
||||
}
|
||||
return infoList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getKeysSize() throws RedisConnectException {
|
||||
Long dbSize = redisConnectionFactory.getConnection().dbSize();
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put(CREATE_TIME, System.currentTimeMillis());
|
||||
map.put("dbSize", dbSize);
|
||||
|
||||
log.info("--getKeysSize--: " + map.toString());
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getMemoryInfo() throws RedisConnectException {
|
||||
Map<String, Object> map = null;
|
||||
Properties info = redisConnectionFactory.getConnection().info();
|
||||
if(info==null) {
|
||||
return new HashMap<>();
|
||||
}
|
||||
for (Map.Entry<Object, Object> entry : info.entrySet()) {
|
||||
String key = oConvertUtils.getString(entry.getKey());
|
||||
if (USER_MEMORY.equals(key)) {
|
||||
map = new HashMap<>();
|
||||
map.put(USER_MEMORY, entry.getValue());
|
||||
map.put(CREATE_TIME, System.currentTimeMillis());
|
||||
}
|
||||
}
|
||||
log.info("--getMemoryInfo--: " + (map==null?":":map.toString()));
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询redis信息for报表
|
||||
* @param type 1redis key数量 2 占用内存 3redis信息
|
||||
* @return
|
||||
* @throws RedisConnectException
|
||||
*/
|
||||
@Override
|
||||
public Map<String, JSONArray> getMapForReport(String type) throws RedisConnectException {
|
||||
Map<String,JSONArray> mapJson=new HashMap<> ();
|
||||
JSONArray json = new JSONArray();
|
||||
if("3".equals(type)){
|
||||
List<RedisInfo> redisInfo = getRedisInfo();
|
||||
for(RedisInfo info:redisInfo){
|
||||
BeanMap beanMap = BeanMap.create(info);
|
||||
json.add(beanMap);
|
||||
}
|
||||
mapJson.put("data",json);
|
||||
return mapJson;
|
||||
}
|
||||
for(int i = 0; i < 5; i++){
|
||||
JSONObject jo = new JSONObject();
|
||||
Map<String, Object> map;
|
||||
if("1".equals(type)){
|
||||
map= getKeysSize();
|
||||
jo.put("value",map.get("dbSize"));
|
||||
}else{
|
||||
map = getMemoryInfo();
|
||||
Integer usedMemory = Integer.valueOf(map.get(USER_MEMORY).toString());
|
||||
jo.put("value",usedMemory/1000);
|
||||
}
|
||||
String createTime = DateUtil.formatTime(DateUtil.date((Long) map.get(CREATE_TIME)-(4-i)*1000));
|
||||
jo.put("name",createTime);
|
||||
json.add(jo);
|
||||
}
|
||||
mapJson.put("data",json);
|
||||
return mapJson;
|
||||
}
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
package com.jero.modules.ngalain.aop;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.springframework.web.context.request.RequestAttributes;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
// 暂时注释掉,提高系统性能
|
||||
//@Aspect //定义一个切面
|
||||
//@Configuration
|
||||
@Slf4j
|
||||
public class LogRecordAspect {
|
||||
|
||||
// 定义切点Pointcut
|
||||
@Pointcut("execution(public * com.jero.modules.*.*.*Controller.*(..))")
|
||||
public void excudeService() {
|
||||
// do point
|
||||
}
|
||||
|
||||
@Around("excudeService()")
|
||||
public Object doAround(ProceedingJoinPoint pjp) throws Throwable {
|
||||
RequestAttributes ra = RequestContextHolder.getRequestAttributes();
|
||||
ServletRequestAttributes sra = (ServletRequestAttributes) ra;
|
||||
String url = null;
|
||||
String method = null;
|
||||
String uri = null;
|
||||
String queryString = null;
|
||||
if (sra!=null) {
|
||||
HttpServletRequest request = sra.getRequest();
|
||||
url = request.getRequestURL().toString();
|
||||
method = request.getMethod();
|
||||
uri = request.getRequestURI();
|
||||
queryString = request.getQueryString();
|
||||
}
|
||||
log.info("请求开始, 各个参数, url: {}, method: {}, uri: {}, params: {}", url, method, uri, queryString);
|
||||
|
||||
// result的值就是被拦截方法的返回值
|
||||
Object result = pjp.proceed();
|
||||
|
||||
log.info("请求结束,controller的返回值是 " + result);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
package com.jero.modules.ngalain.controller;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import com.jero.common.api.vo.Results;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import com.jero.common.system.vo.DictModel;
|
||||
import com.jero.common.system.vo.LoginUser;
|
||||
import com.jero.modules.ngalain.service.NgAlainService;
|
||||
import com.jero.modules.system.service.ISysDictService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/sys/ng-alain")
|
||||
public class NgAlainController {
|
||||
@Autowired
|
||||
private NgAlainService ngAlainService;
|
||||
@Autowired
|
||||
private ISysDictService sysDictService;
|
||||
|
||||
@RequestMapping(value = "/getAppData")
|
||||
@ResponseBody
|
||||
public JSONObject getAppData(HttpServletRequest request){
|
||||
String token=request.getHeader("X-Access-Token");
|
||||
JSONObject j = new JSONObject();
|
||||
LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
||||
JSONObject userObjcet = new JSONObject();
|
||||
userObjcet.put("name", user.getUsername());
|
||||
userObjcet.put("avatar", user.getAvatar());
|
||||
userObjcet.put("email", user.getEmail());
|
||||
userObjcet.put("token", token);
|
||||
j.put("user", userObjcet);
|
||||
j.put("menu",ngAlainService.getMenu(user.getUsername()));
|
||||
JSONObject app = new JSONObject();
|
||||
app.put("name", "jero-boot-angular");
|
||||
app.put("description", "jero+ng-alain整合版本");
|
||||
j.put("app", app);
|
||||
return j;
|
||||
}
|
||||
|
||||
// @RequestMapping(value = "/getDictItems/{dictCode}", method = RequestMethod.GET)
|
||||
@GetMapping("/getDictItems/{dictCode}")
|
||||
public Object getDictItems(@PathVariable String dictCode) {
|
||||
log.info(" dictCode : "+ dictCode);
|
||||
Results<List<DictModel>> result = new Results<>();
|
||||
List<DictModel> ls = null;
|
||||
try {
|
||||
ls = sysDictService.queryDictItemsByCode(dictCode);
|
||||
result.setSuccess(true);
|
||||
result.setResult(ls);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(),e);
|
||||
return Results.error("操作失败");
|
||||
}
|
||||
List<JSONObject> dictlist=new ArrayList<>();
|
||||
for (DictModel l : ls) {
|
||||
JSONObject dict=new JSONObject();
|
||||
try {
|
||||
dict.put("value",Integer.parseInt(l.getValue()));
|
||||
} catch (NumberFormatException e) {
|
||||
dict.put("value",l.getValue());
|
||||
}
|
||||
dict.put("label",l.getText());
|
||||
dictlist.add(dict);
|
||||
}
|
||||
return dictlist;
|
||||
}
|
||||
// @RequestMapping(value = "/getDictItemsByTable/{table}/{key}/{value}", method = RequestMethod.GET)
|
||||
@GetMapping("/getDictItemsByTable/{table}/{key}/{value}")
|
||||
public Object getDictItemsByTable(@PathVariable String table,@PathVariable String key,@PathVariable String value) {
|
||||
return this.ngAlainService.getDictByTable(table,key,value);
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package com.jero.modules.ngalain.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface NgAlainService {
|
||||
JSONArray getMenu(String id);
|
||||
JSONArray getJeroMenu(String id);
|
||||
List<Map<String, String>> getDictByTable(String table, String key, String value);
|
||||
}
|
||||
+189
@@ -0,0 +1,189 @@
|
||||
package com.jero.modules.ngalain.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.jero.common.util.oConvertUtils;
|
||||
import com.jero.modules.ngalain.service.NgAlainService;
|
||||
import com.jero.modules.system.entity.SysPermission;
|
||||
import com.jero.modules.system.mapper.SysDictMapper;
|
||||
import com.jero.modules.system.service.ISysPermissionService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Base64;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service("ngAlainService")
|
||||
public class NgAlainServiceImpl implements NgAlainService {
|
||||
@Autowired
|
||||
private ISysPermissionService sysPermissionService;
|
||||
@Autowired
|
||||
private SysDictMapper mapper;
|
||||
private static final String CHILDREN ="children";
|
||||
@Override
|
||||
public JSONArray getMenu(String id) {
|
||||
return getJeroMenu(id);
|
||||
}
|
||||
@Override
|
||||
public JSONArray getJeroMenu(String id) {
|
||||
List<SysPermission> metaList = sysPermissionService.queryByUser(id);
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
getPermissionJsonArray(jsonArray, metaList, null);
|
||||
JSONArray menulist= parseNgAlain(jsonArray);
|
||||
JSONObject menu = new JSONObject();
|
||||
menu.put("text", "jero菜单");
|
||||
menu.put("group",true);
|
||||
menu.put(CHILDREN, menulist);
|
||||
JSONArray jeroMenuList=new JSONArray();
|
||||
jeroMenuList.add(menu);
|
||||
return jeroMenuList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Map<String, String>> getDictByTable(String table, String key, String value) {
|
||||
return this.mapper.getDictByTableNgAlain(table,key,value);
|
||||
}
|
||||
|
||||
private JSONArray parseNgAlain(JSONArray jsonArray) {
|
||||
JSONArray menulist=new JSONArray();
|
||||
for (Object object : jsonArray) {
|
||||
JSONObject jsonObject= (JSONObject) object;
|
||||
String path= (String) jsonObject.get("path");
|
||||
JSONObject meta= (JSONObject) jsonObject.get("meta");
|
||||
JSONObject menu=new JSONObject();
|
||||
menu.put("text",meta.get("title"));
|
||||
menu.put("reuse",true);
|
||||
if (jsonObject.get(CHILDREN)!=null){
|
||||
JSONArray child= parseNgAlain((JSONArray) jsonObject.get(CHILDREN));
|
||||
menu.put(CHILDREN,child);
|
||||
JSONObject icon=new JSONObject();
|
||||
icon.put("type", "icon");
|
||||
icon.put("value", meta.get("icon"));
|
||||
menu.put("icon",icon);
|
||||
}else {
|
||||
menu.put("link",path);
|
||||
}
|
||||
menulist.add(menu);
|
||||
}
|
||||
return menulist;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取菜单JSON数组
|
||||
* @param jsonArray
|
||||
* @param metaList
|
||||
* @param parentJson
|
||||
*/
|
||||
private void getPermissionJsonArray(JSONArray jsonArray,List<SysPermission> metaList,JSONObject parentJson) {
|
||||
for (SysPermission permission : metaList) {
|
||||
if(permission.getMenuType()==null) {
|
||||
continue;
|
||||
}
|
||||
String tempPid = permission.getParentId();
|
||||
JSONObject json = getPermissionJsonObject(permission);
|
||||
if(parentJson==null && oConvertUtils.isEmpty(tempPid)) {
|
||||
jsonArray.add(json);
|
||||
if(!permission.isLeaf()) {
|
||||
getPermissionJsonArray(jsonArray, metaList, json);
|
||||
}
|
||||
}else if(parentJson!=null && oConvertUtils.isNotEmpty(tempPid) && tempPid.equals(parentJson.getString("id"))){
|
||||
putParentJson(jsonArray, metaList, parentJson, permission, json);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void putParentJson(JSONArray jsonArray, List<SysPermission> metaList, JSONObject parentJson, SysPermission permission, JSONObject json) {
|
||||
final String PERMISSIONLIST = "permissionList";
|
||||
if(permission.getMenuType()==0) {
|
||||
JSONObject metaJson = parentJson.getJSONObject("meta");
|
||||
if(metaJson.containsKey(PERMISSIONLIST)) {
|
||||
metaJson.getJSONArray(PERMISSIONLIST).add(json);
|
||||
}else {
|
||||
JSONArray permissionList = new JSONArray();
|
||||
permissionList.add(json);
|
||||
metaJson.put(PERMISSIONLIST, permissionList);
|
||||
}
|
||||
|
||||
}else if(permission.getMenuType()==1) {
|
||||
if(parentJson.containsKey(CHILDREN)) {
|
||||
parentJson.getJSONArray(CHILDREN).add(json);
|
||||
}else {
|
||||
JSONArray children = new JSONArray();
|
||||
children.add(json);
|
||||
parentJson.put(CHILDREN, children);
|
||||
}
|
||||
|
||||
if(!permission.isLeaf()) {
|
||||
getPermissionJsonArray(jsonArray, metaList, json);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private JSONObject getPermissionJsonObject(SysPermission permission) {
|
||||
JSONObject json = new JSONObject();
|
||||
//类型(0:一级菜单 1:子菜单 2:按钮)
|
||||
if(permission.getMenuType()==2) {
|
||||
json.put("action", permission.getPerms());
|
||||
json.put("describe", permission.getName());
|
||||
}else if(permission.getMenuType()==0||permission.getMenuType()==1) {
|
||||
json.put("id", permission.getId());
|
||||
putJson(permission, json);
|
||||
|
||||
//重要规则:路由name (通过URL生成路由name,路由name供前端开发,页面跳转使用)
|
||||
json.put("name", urlToRouteName(permission.getUrl()));
|
||||
|
||||
//是否隐藏路由,默认都是显示的
|
||||
if(permission.isHidden()) {
|
||||
json.put("hidden",true);
|
||||
}
|
||||
//聚合路由
|
||||
if(permission.isAlwaysShow()) {
|
||||
json.put("alwaysShow",true);
|
||||
}
|
||||
json.put("component", permission.getComponent());
|
||||
JSONObject meta = new JSONObject();
|
||||
meta.put("title", permission.getName());
|
||||
if(oConvertUtils.isEmpty(permission.getParentId())) {
|
||||
//一级菜单跳转地址
|
||||
json.put("redirect",permission.getRedirect());
|
||||
meta.put("icon", oConvertUtils.getString(permission.getIcon(), ""));
|
||||
}else {
|
||||
meta.put("icon", oConvertUtils.getString(permission.getIcon(), ""));
|
||||
}
|
||||
if(permission.getUrl()!=null&&(permission.getUrl().startsWith("http://")||permission.getUrl().startsWith("https://"))) {
|
||||
meta.put("url", permission.getUrl());
|
||||
}
|
||||
json.put("meta", meta);
|
||||
}
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
private void putJson(SysPermission permission, JSONObject json) {
|
||||
if(permission.getUrl()!=null&&(permission.getUrl().startsWith("http://")||permission.getUrl().startsWith("https://"))) {
|
||||
String url= new String(Base64.getUrlEncoder().encode(permission.getUrl().getBytes()));
|
||||
json.put("path", "/sys/link/" +url.replace("=",""));
|
||||
}else {
|
||||
json.put("path", permission.getUrl());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过URL生成路由name(去掉URL前缀斜杠,替换内容中的斜杠‘/’为-)
|
||||
* 举例: URL = /isystem/role
|
||||
* RouteName = isystem-role
|
||||
* @return
|
||||
*/
|
||||
private String urlToRouteName(String url) {
|
||||
if(oConvertUtils.isNotEmpty(url)) {
|
||||
if(url.startsWith("/")) {
|
||||
url = url.substring(1);
|
||||
}
|
||||
url = url.replace("/", "-");
|
||||
return url;
|
||||
}else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
+94
@@ -0,0 +1,94 @@
|
||||
package com.jero.modules.oss.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.jero.common.api.vo.Results;
|
||||
import com.jero.common.system.query.QueryGenerator;
|
||||
import com.jero.modules.oss.entity.OSSFile;
|
||||
import com.jero.modules.oss.service.IOSSFileService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.poi.ss.formula.functions.T;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@Controller
|
||||
@RequestMapping("/sys/oss/file")
|
||||
public class OSSFileController {
|
||||
|
||||
@Autowired
|
||||
private IOSSFileService ossFileService;
|
||||
|
||||
@ResponseBody
|
||||
@GetMapping("/page")
|
||||
public Results<IPage<OSSFile>> queryPageList(OSSFile file,
|
||||
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
|
||||
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest req) {
|
||||
Results<IPage<OSSFile>> result = new Results<>();
|
||||
QueryWrapper<OSSFile> queryWrapper = QueryGenerator.initQueryWrapper(file, req.getParameterMap());
|
||||
Page<OSSFile> page = new Page<>(pageNo, pageSize);
|
||||
IPage<OSSFile> pageList = ossFileService.page(page, queryWrapper);
|
||||
result.setSuccess(true);
|
||||
result.setResult(pageList);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@PostMapping("/upload")
|
||||
//@RequiresRoles("admin")
|
||||
public Results<T> upload(@RequestParam("file") MultipartFile multipartFile) {
|
||||
try {
|
||||
ossFileService.upload(multipartFile);
|
||||
return Results.OK("上传成功!");
|
||||
}
|
||||
catch (Exception ex) {
|
||||
log.info(ex.getMessage(), ex);
|
||||
return Results.error("上传失败");
|
||||
}
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@PostMapping("/delete")
|
||||
public Results<T> delete(@RequestBody Map<String,String> map) {
|
||||
String id = map.get("id");
|
||||
if(StringUtils.isBlank(id)){
|
||||
return Results.error("参数不识别!");
|
||||
}
|
||||
OSSFile file = ossFileService.getById(id);
|
||||
if (file == null) {
|
||||
return Results.error("未找到对应实体");
|
||||
} else {
|
||||
boolean ok = ossFileService.delete(file);
|
||||
if (ok) {
|
||||
return Results.OK("删除成功!");
|
||||
}
|
||||
}
|
||||
return Results.OK();
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id查询.
|
||||
*/
|
||||
@ResponseBody
|
||||
@GetMapping("/queryById")
|
||||
public Results<OSSFile> queryById(@RequestParam(name = "id") String id) {
|
||||
Results<OSSFile> result = new Results<>();
|
||||
OSSFile file = ossFileService.getById(id);
|
||||
if (file == null) {
|
||||
return Results.error("未找到对应实体");
|
||||
}
|
||||
else {
|
||||
result.setResult(file);
|
||||
result.setSuccess(true);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.jero.modules.oss.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
import com.jero.common.system.base.entity.JeroEntity;
|
||||
import cn.afterturn.easypoi.excel.annotation.Excel;
|
||||
|
||||
@Data
|
||||
@TableName("oss_file")
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Accessors(chain = true)
|
||||
public class OSSFile extends JeroEntity {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Excel(name = "文件名称")
|
||||
private String fileName;
|
||||
|
||||
@Excel(name = "文件地址")
|
||||
private String url;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.jero.modules.oss.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.jero.modules.oss.entity.OSSFile;
|
||||
|
||||
public interface OSSFileMapper extends BaseMapper<OSSFile> {
|
||||
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package com.jero.modules.oss.service;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.jero.modules.oss.entity.OSSFile;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
public interface IOSSFileService extends IService<OSSFile> {
|
||||
|
||||
void upload(MultipartFile multipartFile) throws IOException;
|
||||
|
||||
boolean delete(OSSFile ossFile);
|
||||
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
package com.jero.modules.oss.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.jero.common.util.CommonUtils;
|
||||
import com.jero.common.util.oss.OssBootUtil;
|
||||
import com.jero.modules.oss.entity.OSSFile;
|
||||
import com.jero.modules.oss.mapper.OSSFileMapper;
|
||||
import com.jero.modules.oss.service.IOSSFileService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@Service("ossFileService")
|
||||
public class OSSFileServiceImpl extends ServiceImpl<OSSFileMapper, OSSFile> implements IOSSFileService {
|
||||
|
||||
@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");
|
||||
//update-begin--Author:scott Date:20201227 for:JT-361【文件预览】阿里云原生域名可以文件预览,自己映射域名kkfileview提示文件下载失败-------------------
|
||||
// 返回阿里云原生域名前缀URL
|
||||
ossFile.setUrl(OssBootUtil.getOriginalUrl(url));
|
||||
//update-end--Author:scott Date:20201227 for:JT-361【文件预览】阿里云原生域名可以文件预览,自己映射域名kkfileview提示文件下载失败-------------------
|
||||
this.save(ossFile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean delete(OSSFile ossFile) {
|
||||
try {
|
||||
this.removeById(ossFile.getId());
|
||||
OssBootUtil.deleteUrl(ossFile.getUrl());
|
||||
}
|
||||
catch (Exception ex) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
+282
@@ -0,0 +1,282 @@
|
||||
package com.jero.modules.quartz.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.jero.common.api.vo.Results;
|
||||
import com.jero.common.constant.CommonConstant;
|
||||
import com.jero.common.system.base.controller.JeroController;
|
||||
import com.jero.common.system.query.QueryGenerator;
|
||||
import com.jero.common.util.ImportExcelUtil;
|
||||
import com.jero.common.util.SpringContextUtils;
|
||||
import com.jero.config.easypoi.EasyPoiDictHandlerImpl;
|
||||
import com.jero.modules.quartz.entity.QuartzJob;
|
||||
import com.jero.modules.quartz.service.IQuartzJobService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.poi.ss.formula.functions.T;
|
||||
import cn.afterturn.easypoi.excel.ExcelImportUtil;
|
||||
import cn.afterturn.easypoi.entity.vo.NormalExcelConstants;
|
||||
import cn.afterturn.easypoi.excel.entity.ExportParams;
|
||||
import cn.afterturn.easypoi.excel.entity.ImportParams;
|
||||
import cn.afterturn.easypoi.view.EasypoiSingleExcelView;
|
||||
import org.quartz.Scheduler;
|
||||
import org.quartz.SchedulerException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Description: 定时任务在线管理
|
||||
* @Author: jero-boot
|
||||
* @Date: 2019-01-02
|
||||
* @Version:V1.0
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/sys/quartzJob")
|
||||
@Slf4j
|
||||
@Api(tags = "定时任务接口")
|
||||
public class QuartzJobController {
|
||||
@Autowired
|
||||
private IQuartzJobService quartzJobService;
|
||||
@Autowired
|
||||
private Scheduler scheduler;
|
||||
|
||||
/**
|
||||
* 分页列表查询
|
||||
*
|
||||
* @param quartzJob
|
||||
* @param pageNo
|
||||
* @param pageSize
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/page")
|
||||
public Results<IPage<QuartzJob>> queryPageList(QuartzJob quartzJob, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
|
||||
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest req) {
|
||||
QueryWrapper<QuartzJob> queryWrapper = QueryGenerator.initQueryWrapper(quartzJob, req.getParameterMap());
|
||||
Page<QuartzJob> page = new Page<>(pageNo, pageSize);
|
||||
IPage<QuartzJob> pageList = quartzJobService.page(page, queryWrapper);
|
||||
return Results.OK(pageList);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加定时任务
|
||||
*
|
||||
* @param quartzJob
|
||||
* @return
|
||||
*/
|
||||
//@RequiresRoles("admin")
|
||||
@PostMapping("/add")
|
||||
public Results<T> add(@RequestBody QuartzJob quartzJob) {
|
||||
quartzJobService.saveAndScheduleJob(quartzJob);
|
||||
return Results.OK("创建定时任务成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新定时任务
|
||||
*
|
||||
* @param quartzJob
|
||||
* @return
|
||||
*/
|
||||
//@RequiresRoles("admin")
|
||||
@PostMapping("/edit")
|
||||
public Results<T> eidt(@RequestBody QuartzJob quartzJob) {
|
||||
try {
|
||||
quartzJobService.editAndScheduleJob(quartzJob);
|
||||
} catch (SchedulerException e) {
|
||||
log.error(e.getMessage(),e);
|
||||
return Results.error("更新定时任务失败!");
|
||||
}
|
||||
return Results.OK("更新定时任务成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id删除
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
//@RequiresRoles("admin")
|
||||
@PostMapping("/delete")
|
||||
public Results<T> delete(@RequestBody Map<String,String> map) {
|
||||
String id = map.get("id");
|
||||
if(StringUtils.isBlank(id)){
|
||||
return Results.error("参数不识别!");
|
||||
}
|
||||
QuartzJob quartzJob = quartzJobService.getById(id);
|
||||
if (quartzJob == null) {
|
||||
return Results.error("未找到对应实体");
|
||||
}
|
||||
quartzJobService.deleteAndStopJob(quartzJob);
|
||||
return Results.OK("删除成功!");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
*
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
//@RequiresRoles("admin")
|
||||
@PostMapping("/deleteBatch")
|
||||
public Results<T> deleteBatch(@RequestBody Map<String,String> map) {
|
||||
String ids = map.get("ids");
|
||||
if (ids == null || "".equals(ids.trim())) {
|
||||
return Results.error("参数不识别!");
|
||||
}
|
||||
for (String id : Arrays.asList(ids.split(","))) {
|
||||
QuartzJob job = quartzJobService.getById(id);
|
||||
quartzJobService.deleteAndStopJob(job);
|
||||
}
|
||||
return Results.OK("删除定时任务成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 暂停定时任务
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
//@RequiresRoles("admin")
|
||||
@GetMapping(value = "/pause")
|
||||
@ApiOperation(value = "暂停定时任务")
|
||||
public Results<Object> pauseJob(@RequestParam(name = "id") String id) {
|
||||
QuartzJob job = quartzJobService.getById(id);
|
||||
if (job == null) {
|
||||
return Results.error("定时任务不存在!");
|
||||
}
|
||||
quartzJobService.pause(job);
|
||||
return Results.OK("暂停定时任务成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 启动定时任务
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
//@RequiresRoles("admin")
|
||||
@GetMapping(value = "/resume")
|
||||
@ApiOperation(value = "恢复定时任务")
|
||||
public Results<Object> resumeJob(@RequestParam(name = "id") String id) {
|
||||
QuartzJob job = quartzJobService.getById(id);
|
||||
if (job == null) {
|
||||
return Results.error("定时任务不存在!");
|
||||
}
|
||||
quartzJobService.resumeJob(job);
|
||||
return Results.OK("恢复定时任务成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id查询
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/queryById")
|
||||
public Results<QuartzJob> queryById(@RequestParam(name = "id", required = true) String id) {
|
||||
QuartzJob quartzJob = quartzJobService.getById(id);
|
||||
return Results.OK(quartzJob);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出excel
|
||||
*
|
||||
* @param request
|
||||
* @param quartzJob
|
||||
*/
|
||||
@RequestMapping(value = "/exportXls")
|
||||
public ModelAndView exportXls(HttpServletRequest request, QuartzJob quartzJob) {
|
||||
// Step.1 组装查询条件
|
||||
QueryWrapper<QuartzJob> queryWrapper = QueryGenerator.initQueryWrapper(quartzJob, request.getParameterMap());
|
||||
// Step.2 AutoPoi 导出Excel
|
||||
ModelAndView mv = new ModelAndView(new EasypoiSingleExcelView());
|
||||
List<QuartzJob> pageList = quartzJobService.list(queryWrapper);
|
||||
// 导出文件名称
|
||||
mv.addObject(JeroController.FILE_NAME, "定时任务列表");
|
||||
mv.addObject(JeroController.CLASS, QuartzJob.class);
|
||||
ExportParams exportParams = new ExportParams("定时任务列表数据", "导出人:Jero", "导出信息");
|
||||
exportParams.setDictHandler(SpringContextUtils.getApplicationContext().getBean(EasyPoiDictHandlerImpl.class));
|
||||
mv.addObject(JeroController.PARAMS, exportParams);
|
||||
mv.addObject(NormalExcelConstants.DATA_LIST, pageList);
|
||||
return mv;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过excel导入数据
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/importExcel")
|
||||
public Results<JSONObject> 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;
|
||||
int errorLines = 0;
|
||||
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
|
||||
MultipartFile file = entity.getValue();// 获取上传文件对象
|
||||
ImportParams params = new ImportParams();
|
||||
params.setDictHandler(SpringContextUtils.getApplicationContext().getBean(EasyPoiDictHandlerImpl.class));
|
||||
params.setTitleRows(2);
|
||||
params.setHeadRows(1);
|
||||
params.setNeedSave(true);
|
||||
try {
|
||||
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 Results.error("文件导入失败!");
|
||||
} finally {
|
||||
try {
|
||||
file.getInputStream().close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return ImportExcelUtil.imporReturnRes(errorLines,successLines,errorMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 立即执行
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
//@RequiresRoles("admin")
|
||||
@GetMapping("/execute")
|
||||
public Results<T> execute(@RequestParam(name = "id", required = true) String id) {
|
||||
QuartzJob quartzJob = quartzJobService.getById(id);
|
||||
if (quartzJob == null) {
|
||||
return Results.error("未找到对应实体");
|
||||
}
|
||||
try {
|
||||
quartzJobService.execute(quartzJob);
|
||||
} catch (Exception e) {
|
||||
log.info("定时任务 立即执行失败>>"+e.getMessage());
|
||||
return Results.error("执行失败!");
|
||||
}
|
||||
return Results.OK("执行成功!");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.jero.modules.quartz.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.jero.common.aspect.annotation.Dict;
|
||||
import lombok.Data;
|
||||
import cn.afterturn.easypoi.excel.annotation.Excel;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @Description: 定时任务在线管理
|
||||
* @Author: jero-boot
|
||||
* @Date: 2019-01-02
|
||||
* @Version: V1.0
|
||||
*/
|
||||
@Data
|
||||
@TableName("sys_quartz_job")
|
||||
public class QuartzJob implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**id*/
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
private java.lang.String id;
|
||||
/**创建人*/
|
||||
private java.lang.String createBy;
|
||||
/**创建时间*/
|
||||
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
|
||||
private java.util.Date createTime;
|
||||
/**删除状态*/
|
||||
private java.lang.Integer delFlag;
|
||||
/**修改人*/
|
||||
private java.lang.String updateBy;
|
||||
/**修改时间*/
|
||||
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
|
||||
private java.util.Date updateTime;
|
||||
/**任务类名*/
|
||||
@Excel(name="任务类名",width=40)
|
||||
private java.lang.String jobClassName;
|
||||
/**cron表达式*/
|
||||
@Excel(name="cron表达式",width=30)
|
||||
private java.lang.String cronExpression;
|
||||
/**参数*/
|
||||
@Excel(name="参数",width=15)
|
||||
private java.lang.String parameter;
|
||||
/**描述*/
|
||||
@Excel(name="描述",width=40)
|
||||
private java.lang.String description;
|
||||
/**状态 0正常 -1停止*/
|
||||
@Excel(name="状态",width=15, dict="quartz_status")
|
||||
@Dict(dicCode = "quartz_status")
|
||||
private java.lang.Integer status;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.jero.modules.quartz.job;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import com.jero.common.util.DateUtils;
|
||||
import org.quartz.*;
|
||||
|
||||
/**
|
||||
* @Description: 同步定时任务测试
|
||||
*
|
||||
* 此处的同步是指 当定时任务的执行时间大于任务的时间间隔时
|
||||
* 会等待第一个任务执行完成才会走第二个任务
|
||||
*
|
||||
*
|
||||
* @author: taoyan
|
||||
* @date: 2020年06月19日
|
||||
*/
|
||||
@PersistJobDataAfterExecution
|
||||
@DisallowConcurrentExecution
|
||||
@Slf4j
|
||||
public class AsyncJob implements Job {
|
||||
|
||||
@Override
|
||||
public void execute(JobExecutionContext jobExecutionContext) {
|
||||
log.info(" --- 同步任务调度开始 --- ");
|
||||
try {
|
||||
//此处模拟任务执行时间 5秒 任务表达式配置为每秒执行一次:0/1 * * * * ? *
|
||||
Thread.sleep(5000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
//测试发现 每5秒执行一次
|
||||
log.info(" --- 执行完毕,时间:"+DateUtils.now()+"---");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.jero.modules.quartz.job;
|
||||
|
||||
import com.jero.common.util.DateUtils;
|
||||
import org.quartz.Job;
|
||||
import org.quartz.JobExecutionContext;
|
||||
import org.quartz.JobExecutionException;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* 示例不带参定时任务
|
||||
*
|
||||
* @Author Scott
|
||||
*/
|
||||
@Slf4j
|
||||
public class SampleJob implements Job {
|
||||
|
||||
@Override
|
||||
public void execute(JobExecutionContext jobExecutionContext){
|
||||
log.info(" jero-boot 普通定时任务 SampleJob ! 时间:" + DateUtils.getTimestamp());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.jero.modules.quartz.job;
|
||||
|
||||
import com.jero.common.aspect.annotation.RedisLock;
|
||||
import com.jero.common.util.DateUtils;
|
||||
import org.quartz.DisallowConcurrentExecution;
|
||||
import org.quartz.Job;
|
||||
import org.quartz.JobExecutionContext;
|
||||
import org.quartz.JobExecutionException;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 示例带参定时任务
|
||||
*
|
||||
* @Author Scott
|
||||
*/
|
||||
@Slf4j
|
||||
public class SampleParamJob implements Job {
|
||||
|
||||
/**
|
||||
* 若参数变量名修改 QuartzJobController中也需对应修改
|
||||
*/
|
||||
private String parameter;
|
||||
|
||||
public void setParameter(String parameter) {
|
||||
this.parameter = parameter;
|
||||
}
|
||||
|
||||
@Override
|
||||
@RedisLock(key = "lock----TestJob",expire=60,timeUnit= TimeUnit.SECONDS)
|
||||
public void execute(JobExecutionContext jobExecutionContext) {
|
||||
log.info(" Job Execution key:"+jobExecutionContext.getJobDetail().getKey());
|
||||
log.info("welcome " + this.parameter + " Jero-Boot 带参数定时任务 SampleParamJob ! 时间:" + DateUtils.now());
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
package com.jero.modules.quartz.mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import com.jero.modules.quartz.entity.QuartzJob;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* @Description: 定时任务在线管理
|
||||
* @Author: jero-boot
|
||||
* @Date: 2019-01-02
|
||||
* @Version: V1.0
|
||||
*/
|
||||
public interface QuartzJobMapper extends BaseMapper<QuartzJob> {
|
||||
|
||||
public List<QuartzJob> findByJobClassName(@Param("jobClassName") String jobClassName);
|
||||
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.jero.modules.quartz.mapper.QuartzJobMapper">
|
||||
|
||||
<!-- 根据jobClassName查询 -->
|
||||
<select id="findByJobClassName" resultType="com.jero.modules.quartz.entity.QuartzJob">
|
||||
select * from sys_quartz_job where job_class_name = #{jobClassName}
|
||||
</select>
|
||||
</mapper>
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
package com.jero.modules.quartz.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.jero.modules.quartz.entity.QuartzJob;
|
||||
import org.quartz.SchedulerException;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* @Description: 定时任务在线管理
|
||||
* @Author: jero-boot
|
||||
* @Date: 2019-04-28
|
||||
* @Version: V1.1
|
||||
*/
|
||||
public interface IQuartzJobService extends IService<QuartzJob> {
|
||||
|
||||
List<QuartzJob> findByJobClassName(String jobClassName);
|
||||
|
||||
boolean saveAndScheduleJob(QuartzJob quartzJob);
|
||||
|
||||
boolean editAndScheduleJob(QuartzJob quartzJob) throws SchedulerException;
|
||||
|
||||
boolean deleteAndStopJob(QuartzJob quartzJob);
|
||||
|
||||
boolean resumeJob(QuartzJob quartzJob);
|
||||
|
||||
/**
|
||||
* 执行定时任务
|
||||
* @param quartzJob
|
||||
*/
|
||||
void execute(QuartzJob quartzJob) throws IllegalAccessException, InstantiationException, ClassNotFoundException, SchedulerException;
|
||||
|
||||
/**
|
||||
* 暂停任务
|
||||
* @param quartzJob
|
||||
* @throws SchedulerException
|
||||
*/
|
||||
void pause(QuartzJob quartzJob);
|
||||
}
|
||||
+180
@@ -0,0 +1,180 @@
|
||||
package com.jero.modules.quartz.service.impl;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import com.jero.common.constant.CommonConstant;
|
||||
import com.jero.common.exception.JeroBootException;
|
||||
import com.jero.common.util.DateUtils;
|
||||
import com.jero.modules.quartz.entity.QuartzJob;
|
||||
import com.jero.modules.quartz.mapper.QuartzJobMapper;
|
||||
import com.jero.modules.quartz.service.IQuartzJobService;
|
||||
import org.quartz.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* @Description: 定时任务在线管理
|
||||
* @Author: jero-boot
|
||||
* @Date: 2019-04-28
|
||||
* @Version: V1.1
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class QuartzJobServiceImpl extends ServiceImpl<QuartzJobMapper, QuartzJob> implements IQuartzJobService {
|
||||
@Autowired
|
||||
private QuartzJobMapper quartzJobMapper;
|
||||
@Autowired
|
||||
private Scheduler scheduler;
|
||||
|
||||
/**
|
||||
* 立即执行的任务分组
|
||||
*/
|
||||
private static final String JOB_TEST_GROUP = "test_group";
|
||||
|
||||
@Override
|
||||
public List<QuartzJob> findByJobClassName(String jobClassName) {
|
||||
return quartzJobMapper.findByJobClassName(jobClassName);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = JeroBootException.class)
|
||||
public boolean saveAndScheduleJob(QuartzJob quartzJob) {
|
||||
// DB设置修改
|
||||
quartzJob.setDelFlag(CommonConstant.DEL_FLAG_0);
|
||||
boolean success = this.save(quartzJob);
|
||||
if (success && CommonConstant.STATUS_NORMAL.equals(quartzJob.getStatus())) {
|
||||
// 定时器添加
|
||||
this.schedulerAdd(quartzJob.getId(), quartzJob.getJobClassName().trim(), quartzJob.getCronExpression().trim(), quartzJob.getParameter());
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
/**
|
||||
* 恢复定时任务
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = JeroBootException.class)
|
||||
public boolean resumeJob(QuartzJob quartzJob) {
|
||||
schedulerDelete(quartzJob.getId());
|
||||
schedulerAdd(quartzJob.getId(), quartzJob.getJobClassName().trim(), quartzJob.getCronExpression().trim(), quartzJob.getParameter());
|
||||
quartzJob.setStatus(CommonConstant.STATUS_NORMAL);
|
||||
return this.updateById(quartzJob);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑&启停定时任务
|
||||
*
|
||||
* @throws SchedulerException
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = JeroBootException.class)
|
||||
public boolean editAndScheduleJob(QuartzJob quartzJob) throws SchedulerException {
|
||||
if (CommonConstant.STATUS_NORMAL.equals(quartzJob.getStatus())) {
|
||||
schedulerDelete(quartzJob.getId());
|
||||
schedulerAdd(quartzJob.getId(), quartzJob.getJobClassName().trim(), quartzJob.getCronExpression().trim(), quartzJob.getParameter());
|
||||
} else {
|
||||
scheduler.pauseJob(JobKey.jobKey(quartzJob.getId()));
|
||||
}
|
||||
return this.updateById(quartzJob);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除&停止删除定时任务
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = JeroBootException.class)
|
||||
public boolean deleteAndStopJob(QuartzJob job) {
|
||||
schedulerDelete(job.getId());
|
||||
return this.removeById(job.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(QuartzJob quartzJob) throws IllegalAccessException, InstantiationException, ClassNotFoundException, SchedulerException {
|
||||
String jobName = quartzJob.getJobClassName().trim();
|
||||
Date startDate = new Date();
|
||||
String ymd = DateUtils.date2Str(startDate, DateUtils.yyyymmddhhmmss.get());
|
||||
String identity = jobName + ymd;
|
||||
//3秒后执行 只执行一次
|
||||
// update-begin--author:sunjianlei ---- date:20210511--- for:定时任务立即执行,延迟3秒改成0.1秒-------
|
||||
startDate.setTime(startDate.getTime() + 100L);
|
||||
// update-end--author:sunjianlei ---- date:20210511--- for:定时任务立即执行,延迟3秒改成0.1秒-------
|
||||
// 定义一个Trigger
|
||||
SimpleTrigger trigger = (SimpleTrigger) TriggerBuilder.newTrigger()
|
||||
.withIdentity(identity, JOB_TEST_GROUP)
|
||||
.startAt(startDate)
|
||||
.build();
|
||||
// 构建job信息
|
||||
JobDetail jobDetail = JobBuilder.newJob(getClass(jobName).getClass()).withIdentity(identity).usingJobData("parameter", quartzJob.getParameter()).build();
|
||||
// 将trigger和 jobDetail 加入这个调度
|
||||
scheduler.scheduleJob(jobDetail, trigger);
|
||||
// 启动scheduler
|
||||
scheduler.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = JeroBootException.class)
|
||||
public void pause(QuartzJob quartzJob) {
|
||||
schedulerDelete(quartzJob.getId());
|
||||
quartzJob.setStatus(CommonConstant.STATUS_DISABLE);
|
||||
this.updateById(quartzJob);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加定时任务
|
||||
*
|
||||
* @param jobClassName
|
||||
* @param cronExpression
|
||||
* @param parameter
|
||||
*/
|
||||
private void schedulerAdd(String id, String jobClassName, String cronExpression, String parameter) {
|
||||
try {
|
||||
// 启动调度器
|
||||
scheduler.start();
|
||||
|
||||
// 构建job信息
|
||||
JobDetail jobDetail = JobBuilder.newJob(getClass(jobClassName).getClass()).withIdentity(id).usingJobData("parameter", parameter).build();
|
||||
|
||||
// 表达式调度构建器(即任务执行的时间)
|
||||
CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(cronExpression);
|
||||
|
||||
// 按新的cronExpression表达式构建一个新的trigger
|
||||
CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity(id).withSchedule(scheduleBuilder).build();
|
||||
|
||||
scheduler.scheduleJob(jobDetail, trigger);
|
||||
} catch (SchedulerException e) {
|
||||
throw new JeroBootException("创建定时任务失败", e);
|
||||
} catch (RuntimeException e) {
|
||||
throw new JeroBootException(e.getMessage(), e);
|
||||
} catch (Exception e) {
|
||||
throw new JeroBootException("后台找不到该类名:" + jobClassName, e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除定时任务
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
private void schedulerDelete(String id) {
|
||||
try {
|
||||
scheduler.pauseTrigger(TriggerKey.triggerKey(id));
|
||||
scheduler.unscheduleJob(TriggerKey.triggerKey(id));
|
||||
scheduler.deleteJob(JobKey.jobKey(id));
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
throw new JeroBootException("删除定时任务失败");
|
||||
}
|
||||
}
|
||||
|
||||
private static Job getClass(String classname) throws ClassNotFoundException, IllegalAccessException, InstantiationException {
|
||||
Class<?> class1 = Class.forName(classname);
|
||||
return (Job) class1.newInstance();
|
||||
}
|
||||
|
||||
}
|
||||
+340
@@ -0,0 +1,340 @@
|
||||
package com.jero.modules.system.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.jero.common.api.vo.Results;
|
||||
import com.jero.common.constant.CommonConstant;
|
||||
import com.jero.common.exception.JeroBootException;
|
||||
import com.jero.common.system.api.ISysBaseAPI;
|
||||
import com.jero.common.util.*;
|
||||
import com.jero.modules.oss.entity.OSSFile;
|
||||
import com.jero.modules.oss.service.IOSSFileService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.http.server.ServletServerHttpRequest;
|
||||
import org.springframework.util.AntPathMatcher;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
||||
import org.springframework.web.servlet.HandlerMapping;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.*;
|
||||
import java.net.URLDecoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 用户表 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @Author scott
|
||||
* @since 2018-12-20
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/sys/common")
|
||||
public class CommonController {
|
||||
|
||||
@Autowired
|
||||
private ISysBaseAPI sysBaseAPI;
|
||||
|
||||
@Resource
|
||||
private IOSSFileService ossFileService;
|
||||
|
||||
@Value(value = "${jero.path.upload}")
|
||||
private String uploadpath;
|
||||
|
||||
/**
|
||||
* 本地:local minio:minio 阿里:alioss
|
||||
*/
|
||||
@Value(value="${jero.uploadType}")
|
||||
private String uploadType;
|
||||
/**
|
||||
* 文件后缀黑名单
|
||||
*/
|
||||
@Value(value="${jero.fileSuffixLimits}")
|
||||
private String[] fileSuffixLimits;
|
||||
|
||||
private static final String UTF8 ="UTF-8";
|
||||
|
||||
private static final String FILE_VIEW_ERROR = "预览文件失败";
|
||||
|
||||
/**
|
||||
* @Author 政辉
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/403")
|
||||
public Results<String> noauth() {
|
||||
return Results.error("没有权限,请联系管理员授权");
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件上传统一方法
|
||||
* @param request
|
||||
* @param response
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/upload")
|
||||
public Results<OSSFile> upload(HttpServletRequest request, HttpServletResponse response) {
|
||||
Results<OSSFile> result = new Results<>();
|
||||
String savePath = "";
|
||||
String bizPath = request.getParameter("biz");
|
||||
|
||||
//sys/common/upload接口存在任意文件上传漏洞
|
||||
if (oConvertUtils.isNotEmpty(bizPath) && (bizPath.contains("../") || bizPath.contains("..\\"))) {
|
||||
throw new JeroBootException("上传目录bizPath,格式非法!");
|
||||
}
|
||||
|
||||
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
||||
// 获取上传文件对象
|
||||
MultipartFile file = multipartRequest.getFile("file");
|
||||
if(file==null) {
|
||||
return result;
|
||||
}
|
||||
// 文件类型是否处于黑名单
|
||||
if(CommonUtils.limitFileSuffix(file.getOriginalFilename(),fileSuffixLimits)){
|
||||
result.setMessage("该文件类型不允许上传");
|
||||
result.setSuccess(false);
|
||||
result.setCode(0);
|
||||
return result;
|
||||
}
|
||||
if(oConvertUtils.isEmpty(bizPath)){
|
||||
bizPath = "";
|
||||
}
|
||||
if(CommonConstant.UPLOAD_TYPE_LOCAL.equals(uploadType)){
|
||||
// 本地上传
|
||||
savePath = CommonUtils.uploadLocal(file,bizPath,uploadpath);
|
||||
}else{
|
||||
// minio上传
|
||||
savePath = CommonUtils.upload(file, bizPath, uploadType);
|
||||
}
|
||||
if(oConvertUtils.isNotEmpty(savePath)){
|
||||
//上传成功 进行数据库存储
|
||||
OSSFile ossFile = new OSSFile();
|
||||
// 文件名
|
||||
String fileName = file.getOriginalFilename();
|
||||
fileName = CommonUtils.getFileName(fileName);
|
||||
ossFile.setFileName(fileName);
|
||||
ossFile.setUrl(savePath);
|
||||
ossFileService.save(ossFile);
|
||||
result.setMessage(savePath);
|
||||
result.setResult(ossFile);
|
||||
result.setSuccess(true);
|
||||
}else {
|
||||
result.setMessage("上传失败!");
|
||||
result.setSuccess(false);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 预览图片&下载文件
|
||||
*
|
||||
* @param id 传入文件id
|
||||
* @param request
|
||||
* @param response
|
||||
*/
|
||||
@GetMapping(value = "/download/{id}")
|
||||
public void view(@PathVariable String id,HttpServletRequest request, HttpServletResponse response) {
|
||||
// 查询数据表数据是否存在
|
||||
LambdaQueryWrapper<OSSFile> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(OSSFile::getId,id);
|
||||
OSSFile ossFile = ossFileService.getOne(queryWrapper);
|
||||
if( null == ossFile){
|
||||
throw new JeroBootException("文件不存在..");
|
||||
}
|
||||
String fileUrl = ossFile.getUrl();
|
||||
if(CommonConstant.UPLOAD_TYPE_LOCAL.equals(uploadType)){
|
||||
//本地下载
|
||||
String filePath = uploadpath + File.separator + fileUrl;
|
||||
File file = new File(filePath);
|
||||
if(!file.exists()){
|
||||
response.setStatus(404);
|
||||
throw new JeroBootException("文件不存在..");
|
||||
}
|
||||
// 文件名称
|
||||
String fileName = file.getName();
|
||||
setResponse(response, fileName);
|
||||
try (InputStream inputStream = new BufferedInputStream(new FileInputStream(filePath));
|
||||
OutputStream outputStream = response.getOutputStream()
|
||||
) {
|
||||
byte[] buf = new byte[1024];
|
||||
int len;
|
||||
while ((len = inputStream.read(buf)) > 0) {
|
||||
outputStream.write(buf, 0, len);
|
||||
}
|
||||
response.flushBuffer();
|
||||
}catch (Exception e){
|
||||
log.error(FILE_VIEW_ERROR + e.getMessage());
|
||||
response.setStatus(404);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}else if(CommonConstant.UPLOAD_TYPE_MINIO.equals(uploadType)){
|
||||
// minio 下载
|
||||
// 通过MinioUtil查询时 只需要桶后面的路径
|
||||
String minioUrl = MinioUtil.getMinioUrl();
|
||||
// Linux/unix 系统下文件路径分隔符为"/" 获取minio与存储桶的路径
|
||||
minioUrl = minioUrl + MinioUtil.getBucketName() + "/";
|
||||
String url = fileUrl.replace(minioUrl, "");
|
||||
// 文件名称
|
||||
String fileName = ossFile.getFileName();
|
||||
setResponse(response, fileName);
|
||||
try (InputStream inputStream = MinioUtil.getMinioFile(MinioUtil.getBucketName(), url);
|
||||
OutputStream outputStream = response.getOutputStream()
|
||||
) {
|
||||
byte[] buf = new byte[1024];
|
||||
int len;
|
||||
if(inputStream==null) {
|
||||
return;
|
||||
}
|
||||
while ((len = inputStream.read(buf)) > 0) {
|
||||
outputStream.write(buf, 0, len);
|
||||
}
|
||||
response.flushBuffer();
|
||||
}catch (Exception e){
|
||||
log.error(FILE_VIEW_ERROR + e.getMessage());
|
||||
response.setStatus(404);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setResponse(HttpServletResponse response, String fileName) {
|
||||
response.addHeader("Content-Disposition", "attachment;fileName=" + new String(fileName.getBytes(StandardCharsets.UTF_8), StandardCharsets.ISO_8859_1));
|
||||
// 设置强制下载不打开
|
||||
response.setContentType("application/force-download");
|
||||
}
|
||||
|
||||
/**
|
||||
* @功能:pdf预览Iframe
|
||||
* @param modelAndView
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("/pdf/pdfPreviewIframe")
|
||||
public ModelAndView pdfPreviewIframe(ModelAndView modelAndView) {
|
||||
modelAndView.setViewName("pdfPreviewIframe");
|
||||
return modelAndView;
|
||||
}
|
||||
|
||||
/**
|
||||
* 把指定URL后的字符串全部截断当成参数
|
||||
* 这么做是为了防止URL中包含中文或者特殊字符(/等)时,匹配不了的问题
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
private static String extractPathFromPattern(final HttpServletRequest request) {
|
||||
String path = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
|
||||
String bestMatchPattern = (String) request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
|
||||
return new AntPathMatcher().extractPathWithinPattern(bestMatchPattern, path);
|
||||
}
|
||||
|
||||
/**
|
||||
* 中转HTTP请求,解决跨域问题
|
||||
*
|
||||
* @param url 必填:请求地址
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("/transitRESTful")
|
||||
public Results<Object> transitRESTful(@RequestParam("url") String url, HttpServletRequest request) {
|
||||
try {
|
||||
ServletServerHttpRequest httpRequest = new ServletServerHttpRequest(request);
|
||||
// 中转请求method、body
|
||||
HttpMethod method = httpRequest.getMethod();
|
||||
JSONObject params;
|
||||
params = getJsonObject(httpRequest);
|
||||
// 中转请求问号参数
|
||||
JSONObject variables = JSON.parseObject(JSON.toJSONString(request.getParameterMap()));
|
||||
variables.remove("url");
|
||||
// 在 headers 里传递Token
|
||||
String token = TokenUtils.getTokenByRequest(request);
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("X-Access-Token", token);
|
||||
// 发送请求
|
||||
String httpURL = URLDecoder.decode(url, UTF8);
|
||||
ResponseEntity<String> response = RestUtil.request(httpURL, method, headers , variables, params, String.class);
|
||||
// 封装返回结果
|
||||
Results<Object> result = new Results<>();
|
||||
int statusCode = response.getStatusCodeValue();
|
||||
result.setCode(statusCode);
|
||||
result.setSuccess(statusCode == 200);
|
||||
String responseBody = response.getBody();
|
||||
getResult(result, responseBody);
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
log.debug("中转HTTP请求失败", e);
|
||||
return Results.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void getResult(Results<Object> result, String responseBody) {
|
||||
try {
|
||||
// 尝试将返回结果转为JSON
|
||||
Object json = JSON.parse(responseBody);
|
||||
result.setResult(json);
|
||||
} catch (Exception e) {
|
||||
// 转成JSON失败,直接返回原始数据
|
||||
result.setResult(responseBody);
|
||||
}
|
||||
}
|
||||
|
||||
private JSONObject getJsonObject(ServletServerHttpRequest httpRequest) {
|
||||
JSONObject params;
|
||||
try {
|
||||
params = JSON.parseObject(JSON.toJSONString(httpRequest.getBody()));
|
||||
} catch (Exception e) {
|
||||
params = new JSONObject();
|
||||
}
|
||||
return params;
|
||||
}
|
||||
|
||||
/**
|
||||
* 预览图片&下载文件
|
||||
* 请求地址:http://localhost:8080/common/static/{user/20190119/e1fe9925bc315c60addea1b98eb1cb1349547719_1547866868179.jpg}
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
*/
|
||||
@GetMapping(value = "/static/**")
|
||||
public void view(HttpServletRequest request, HttpServletResponse response) {
|
||||
// ISO-8859-1 ==> UTF-8 进行编码转换
|
||||
String imgPath = extractPathFromPattern(request);
|
||||
if(oConvertUtils.isEmpty(imgPath) || "null".equals(imgPath)){
|
||||
return;
|
||||
}
|
||||
imgPath = imgPath.replace("..", "").replace("../","");
|
||||
if (imgPath.endsWith(",")) {
|
||||
imgPath = imgPath.substring(0, imgPath.length() - 1);
|
||||
}
|
||||
String filePath = uploadpath + File.separator + imgPath;
|
||||
File file = new File(filePath);
|
||||
if(!file.exists()){
|
||||
response.setStatus(404);
|
||||
throw new JeroBootException("文件["+imgPath+"]不存在..");
|
||||
}
|
||||
response.setContentType("application/force-download");// 设置强制下载不打开
|
||||
response.addHeader("Content-Disposition", "attachment;fileName=" + new String(file.getName().getBytes(StandardCharsets.UTF_8), StandardCharsets.ISO_8859_1));
|
||||
// 其余处理略
|
||||
try (InputStream inputStream = new BufferedInputStream(new FileInputStream(filePath));
|
||||
OutputStream outputStream = response.getOutputStream()) {
|
||||
byte[] buf = new byte[1024];
|
||||
int len;
|
||||
while ((len = inputStream.read(buf)) > 0) {
|
||||
outputStream.write(buf, 0, len);
|
||||
}
|
||||
response.flushBuffer();
|
||||
} catch (IOException e) {
|
||||
log.error(FILE_VIEW_ERROR + e.getMessage());
|
||||
response.setStatus(404);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
package com.jero.modules.system.controller;
|
||||
|
||||
import com.jero.common.api.vo.Results;
|
||||
import com.jero.common.util.PasswordUtil;
|
||||
import com.jero.common.util.SqlInjectionUtil;
|
||||
import com.jero.modules.system.mapper.SysDictMapper;
|
||||
import com.jero.modules.system.model.DuplicateCheckVo;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* @Title: DuplicateCheckAction
|
||||
* @Description: 重复校验工具
|
||||
* @Author 张代浩
|
||||
* @Date 2019-03-25
|
||||
* @Version V1.0
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/sys/duplicate")
|
||||
@Api(tags="重复校验")
|
||||
public class DuplicateCheckController {
|
||||
|
||||
@Autowired
|
||||
SysDictMapper sysDictMapper;
|
||||
|
||||
/**
|
||||
* 校验数据是否在系统中是否存在
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/check")
|
||||
@ApiOperation("重复校验接口")
|
||||
public Results<Object> doDuplicateCheck(DuplicateCheckVo duplicateCheckVo, HttpServletRequest request) {
|
||||
Long num = null;
|
||||
|
||||
log.info("----duplicate check------:"+ duplicateCheckVo.toString());
|
||||
//关联表字典(举例:sys_user,realname,id)
|
||||
//SQL注入校验(只限制非法串改数据库)
|
||||
final String[] sqlInjCheck = {duplicateCheckVo.getTableName(),duplicateCheckVo.getFieldName()};
|
||||
SqlInjectionUtil.filterContent(sqlInjCheck);
|
||||
if ("phone".equals(duplicateCheckVo.getFieldName()) || "email".equals(duplicateCheckVo.getFieldName())) {
|
||||
if (StringUtils.isNotBlank(duplicateCheckVo.getFieldVal())) {
|
||||
duplicateCheckVo.setFieldVal(PasswordUtil.encrypt(duplicateCheckVo.getFieldVal()));
|
||||
}
|
||||
}
|
||||
if (StringUtils.isNotBlank(duplicateCheckVo.getDataId())) {
|
||||
// [2].编辑页面校验
|
||||
num = sysDictMapper.duplicateCheckCountSql(duplicateCheckVo);
|
||||
} else {
|
||||
// [1].添加页面校验
|
||||
num = sysDictMapper.duplicateCheckCountSqlNoDataId(duplicateCheckVo);
|
||||
}
|
||||
|
||||
if (num == null || num == 0) {
|
||||
// 该值可用
|
||||
return Results.OK("该值可用!");
|
||||
} else {
|
||||
// 该值不可用
|
||||
log.info("该值不可用,系统中已存在!");
|
||||
return Results.error("该值不可用,系统中已存在!");
|
||||
}
|
||||
}
|
||||
}
|
||||
+154
@@ -0,0 +1,154 @@
|
||||
package com.jero.modules.system.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.jero.common.api.vo.Results;
|
||||
import com.jero.modules.system.entity.SysUser;
|
||||
import com.jero.modules.system.model.SysLoginModel;
|
||||
import com.jero.modules.system.service.ILoginService;
|
||||
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.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author scott
|
||||
* @since 2018-12-17
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/sys")
|
||||
@Api(tags="用户登录")
|
||||
@Slf4j
|
||||
public class LoginController {
|
||||
@Autowired
|
||||
private ILoginService loginService;
|
||||
|
||||
@ApiOperation("登录接口")
|
||||
@PostMapping("/login")
|
||||
public Results<JSONObject> login(@RequestBody SysLoginModel sysLoginModel){
|
||||
return loginService.login(sysLoginModel);
|
||||
}
|
||||
|
||||
/**
|
||||
* 退出登录
|
||||
* @param request
|
||||
* @param response
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/logout")
|
||||
public Results<Object> logout(HttpServletRequest request, HttpServletResponse response) {
|
||||
return loginService.logout(request,response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取访问量
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("loginfo")
|
||||
public Results<JSONObject> loginfo() {
|
||||
return loginService.loginfo();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取访问量
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("visitInfo")
|
||||
public Results<List<Map<String,Object>>> visitInfo() {
|
||||
return loginService.visitInfo();
|
||||
}
|
||||
|
||||
/**
|
||||
* 登陆成功选择用户当前部门
|
||||
* @param user
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/selectDepart")
|
||||
public Results<JSONObject> selectDepart(@RequestBody SysUser user) {
|
||||
return loginService.selectDepart(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* 短信登录接口
|
||||
*
|
||||
* @param jsonObject
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/sms")
|
||||
public Results<JSONObject> sms(@RequestBody JSONObject jsonObject) {
|
||||
return loginService.sms(jsonObject);
|
||||
}
|
||||
|
||||
/**
|
||||
* 手机号登录接口
|
||||
*
|
||||
* @param jsonObject
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation("手机号登录接口")
|
||||
@PostMapping("/phoneLogin")
|
||||
public Results<JSONObject> phoneLogin(@RequestBody JSONObject jsonObject) {
|
||||
return loginService.phoneLogin(jsonObject);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取加密字符串
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/getEncryptedString")
|
||||
public Results<Map<String,String>> getEncryptedString(){
|
||||
return loginService.getEncryptedString();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 后台生成图形验证码 :有效
|
||||
* @param response
|
||||
* @param key
|
||||
*/
|
||||
@ApiOperation("获取验证码")
|
||||
@GetMapping(value = "/randomImage/{key}")
|
||||
public Results<String> randomImage(HttpServletResponse response, @PathVariable String key){
|
||||
return loginService.randomImage(response,key);
|
||||
}
|
||||
|
||||
/**
|
||||
* app登录
|
||||
* @param sysLoginModel
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
@PostMapping("/mLogin")
|
||||
public Results<JSONObject> mLogin(@RequestBody SysLoginModel sysLoginModel) {
|
||||
return loginService.mLogin(sysLoginModel);
|
||||
}
|
||||
|
||||
/**
|
||||
* 图形验证码
|
||||
* @param sysLoginModel
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/checkCaptcha")
|
||||
public Results<T> checkCaptcha(@RequestBody SysLoginModel sysLoginModel){
|
||||
return loginService.checkCaptcha(sysLoginModel);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回一个RSA公钥
|
||||
* @author 马志朝
|
||||
* @date 2021/4/15 15:01
|
||||
* @param
|
||||
* @return com.jero.common.api.vo.Result<java.lang.String>
|
||||
*/
|
||||
@ApiOperation("获取RSA公钥")
|
||||
@GetMapping("/getRSAPublicKey")
|
||||
public Results<String> getRSAPublicKey(){
|
||||
return loginService.getRSAPublicKey();
|
||||
}
|
||||
}
|
||||
+402
@@ -0,0 +1,402 @@
|
||||
package com.jero.modules.system.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.jero.common.api.vo.Results;
|
||||
import com.jero.common.aspect.annotation.AutoLog;
|
||||
import com.jero.common.constant.CommonConstant;
|
||||
import com.jero.common.constant.CommonSendStatus;
|
||||
import com.jero.common.constant.WebsocketConst;
|
||||
import com.jero.common.system.api.ISysBaseAPI;
|
||||
import com.jero.common.system.util.JwtUtil;
|
||||
import com.jero.common.system.vo.LoginUser;
|
||||
import com.jero.common.util.RedisUtil;
|
||||
import com.jero.common.util.TokenUtils;
|
||||
import com.jero.common.util.oConvertUtils;
|
||||
import com.jero.modules.message.websocket.WebSocket;
|
||||
import com.jero.modules.system.entity.SysAnnouncement;
|
||||
import com.jero.modules.system.entity.SysAnnouncementSend;
|
||||
import com.jero.modules.system.service.ISysAnnouncementSendService;
|
||||
import com.jero.modules.system.service.ISysAnnouncementService;
|
||||
import com.jero.modules.system.util.XSSUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.poi.ss.formula.functions.T;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.jero.common.constant.CommonConstant.ANNOUNCEMENT_SEND_STATUS_1;
|
||||
|
||||
/**
|
||||
* @Title: Controller
|
||||
* @Description: 系统通告表
|
||||
* @Author: jero-boot
|
||||
* @Date: 2019-01-02
|
||||
* @Version: V1.0
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/sys/annountCement")
|
||||
@Slf4j
|
||||
public class SysAnnouncementController {
|
||||
@Autowired
|
||||
private ISysAnnouncementService sysAnnouncementService;
|
||||
@Autowired
|
||||
private ISysAnnouncementSendService sysAnnouncementSendService;
|
||||
@Resource
|
||||
private WebSocket webSocket;
|
||||
@Autowired
|
||||
private ISysBaseAPI sysBaseAPI;
|
||||
@Autowired
|
||||
@Lazy
|
||||
private RedisUtil redisUtil;
|
||||
|
||||
private static final String ERROR_TEXT = "未找到对应实体";
|
||||
|
||||
/**
|
||||
* 分页列表查询
|
||||
* @param sysAnnouncement
|
||||
* @param pageNo
|
||||
* @param pageSize
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/page")
|
||||
@AutoLog(operateType = 1,value = "查询系统通告")
|
||||
@RequiresPermissions("system:list")
|
||||
public Results<IPage<SysAnnouncement>> queryPageList(SysAnnouncement sysAnnouncement,
|
||||
@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
|
||||
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
|
||||
HttpServletRequest req) {
|
||||
Results<IPage<SysAnnouncement>> result = new Results<>();
|
||||
sysAnnouncement.setDelFlag(CommonConstant.DEL_FLAG_0.toString());
|
||||
QueryWrapper<SysAnnouncement> queryWrapper = new QueryWrapper<>(sysAnnouncement);
|
||||
Page<SysAnnouncement> page = new Page<>(pageNo,pageSize);
|
||||
//排序逻辑 处理
|
||||
String column = req.getParameter("column");
|
||||
String order = req.getParameter("order");
|
||||
if(oConvertUtils.isNotEmpty(column) && oConvertUtils.isNotEmpty(order)) {
|
||||
if("asc".equals(order)) {
|
||||
queryWrapper.orderByAsc(oConvertUtils.camelToUnderline(column));
|
||||
}else {
|
||||
queryWrapper.orderByDesc(oConvertUtils.camelToUnderline(column));
|
||||
}
|
||||
}
|
||||
IPage<SysAnnouncement> pageList = sysAnnouncementService.page(page, queryWrapper);
|
||||
result.setSuccess(true);
|
||||
result.setResult(pageList);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
* @param sysAnnouncement
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/add")
|
||||
@AutoLog(operateType = 2,value = "新增系统通告")
|
||||
@RequiresPermissions("annount:cement:add")
|
||||
public Results<Object> add(@RequestBody SysAnnouncement sysAnnouncement) {
|
||||
try {
|
||||
// update-begin-author:liusq date:20210804 for:标题处理xss攻击的问题
|
||||
String title = XSSUtils.striptXSS(sysAnnouncement.getTitile());
|
||||
sysAnnouncement.setTitile(title);
|
||||
// update-end-author:liusq date:20210804 for:标题处理xss攻击的问题
|
||||
sysAnnouncement.setDelFlag(CommonConstant.DEL_FLAG_0.toString());
|
||||
sysAnnouncement.setSendStatus(CommonSendStatus.UNPUBLISHED_STATUS_0);//未发布
|
||||
sysAnnouncementService.saveAnnouncement(sysAnnouncement);
|
||||
return Results.OK("操作成功!");
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(),e);
|
||||
return Results.error("操作失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
* @param sysAnnouncement
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/edit")
|
||||
@AutoLog(operateType = 3,value = "修改系统通告")
|
||||
@RequiresPermissions("annount:cement:edit")
|
||||
public Results<Object> eidt(@RequestBody SysAnnouncement sysAnnouncement) {
|
||||
SysAnnouncement sysAnnouncementEntity = sysAnnouncementService.getById(sysAnnouncement.getId());
|
||||
if(sysAnnouncementEntity==null) {
|
||||
return Results.error(ERROR_TEXT);
|
||||
}else {
|
||||
// update-begin-author:liusq date:20210804 for:标题处理xss攻击的问题
|
||||
String title = XSSUtils.striptXSS(sysAnnouncement.getTitile());
|
||||
sysAnnouncement.setTitile(title);
|
||||
// update-end-author:liusq date:20210804 for:标题处理xss攻击的问题
|
||||
boolean ok = sysAnnouncementService.upDateAnnouncement(sysAnnouncement);
|
||||
if(ok) {
|
||||
return Results.OK("操作成功!");
|
||||
}
|
||||
}
|
||||
|
||||
return Results.OK();
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id删除
|
||||
* @param map
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/delete")
|
||||
@AutoLog(operateType = 4,value = "删除系统通告")
|
||||
@RequiresPermissions("annount:cement:del")
|
||||
public Results<Object> delete(@RequestBody Map<String, String> map) {
|
||||
String id = map.get("id");
|
||||
if(StringUtils.isBlank(id)){
|
||||
return Results.error("参数不识别!");
|
||||
}
|
||||
SysAnnouncement sysAnnouncement = sysAnnouncementService.getById(id);
|
||||
if(sysAnnouncement==null) {
|
||||
return Results.error(ERROR_TEXT);
|
||||
}else {
|
||||
sysAnnouncement.setDelFlag(CommonConstant.DEL_FLAG_1.toString());
|
||||
boolean ok = sysAnnouncementService.updateById(sysAnnouncement);
|
||||
if(ok) {
|
||||
return Results.OK("删除成功!");
|
||||
}
|
||||
}
|
||||
|
||||
return Results.OK();
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
* @param map
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/deleteBatch")
|
||||
@AutoLog(operateType = 4,value = "批量删除系统通告")
|
||||
public Results<T> deleteBatch(@RequestBody Map<String, String> map) {
|
||||
String ids = map.get("ids");
|
||||
if(ids==null || "".equals(ids.trim())) {
|
||||
return Results.error("参数不识别!");
|
||||
}else {
|
||||
String[] id = ids.split(",");
|
||||
for(int i=0;i<id.length;i++) {
|
||||
SysAnnouncement announcement = sysAnnouncementService.getById(id[i]);
|
||||
announcement.setDelFlag(CommonConstant.DEL_FLAG_1.toString());
|
||||
sysAnnouncementService.updateById(announcement);
|
||||
}
|
||||
return Results.OK("删除成功!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id查询
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/queryById")
|
||||
public Results<SysAnnouncement> queryById(@RequestParam(name="id",required=true) String id) {
|
||||
SysAnnouncement sysAnnouncement = sysAnnouncementService.getById(id);
|
||||
if(sysAnnouncement==null) {
|
||||
return Results.error(ERROR_TEXT);
|
||||
}else {
|
||||
return Results.OK(sysAnnouncement);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新发布操作
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/doReleaseData")
|
||||
@RequiresPermissions("annount:cement:send")
|
||||
public Results<SysAnnouncement> doReleaseData(@RequestParam(name="id",required=true) String id, HttpServletRequest request) {
|
||||
SysAnnouncement sysAnnouncement = sysAnnouncementService.getById(id);
|
||||
if(sysAnnouncement==null) {
|
||||
return Results.error(ERROR_TEXT);
|
||||
}else {
|
||||
sysAnnouncement.setSendStatus(CommonSendStatus.PUBLISHED_STATUS_1);//发布中
|
||||
sysAnnouncement.setSendTime(new Date());
|
||||
String currentUserName = JwtUtil.getUserNameByToken(request);
|
||||
sysAnnouncement.setSender(currentUserName);
|
||||
boolean ok = sysAnnouncementService.updateById(sysAnnouncement);
|
||||
if(ok) {
|
||||
if(sysAnnouncement.getMsgType().equals(CommonConstant.MSG_TYPE_ALL)) {
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put(WebsocketConst.MSG_CMD, WebsocketConst.CMD_TOPIC);
|
||||
obj.put(WebsocketConst.MSG_ID, sysAnnouncement.getId());
|
||||
obj.put(WebsocketConst.MSG_TXT, sysAnnouncement.getTitile());
|
||||
webSocket.sendMessage(obj.toJSONString());
|
||||
}else {
|
||||
// 2.插入用户通告阅读标记表记录
|
||||
String userId = sysAnnouncement.getUserIds();
|
||||
String[] userIds = userId.substring(0, (userId.length()-1)).split(",");
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put(WebsocketConst.MSG_CMD, WebsocketConst.CMD_USER);
|
||||
obj.put(WebsocketConst.MSG_ID, sysAnnouncement.getId());
|
||||
obj.put(WebsocketConst.MSG_TXT, sysAnnouncement.getTitile());
|
||||
webSocket.sendMessage(userIds, obj.toJSONString());
|
||||
}
|
||||
return Results.OK("该系统通知发布成功");
|
||||
}
|
||||
}
|
||||
|
||||
return Results.OK();
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新撤销操作
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/doReovkeData")
|
||||
public Results<Object> doReovkeData(@RequestParam(name="id",required=true) String id, HttpServletRequest request) {
|
||||
SysAnnouncement sysAnnouncement = sysAnnouncementService.getById(id);
|
||||
if(sysAnnouncement==null) {
|
||||
return Results.error(ERROR_TEXT);
|
||||
}else {
|
||||
sysAnnouncement.setSendStatus(CommonSendStatus.REVOKE_STATUS_2);//撤销发布
|
||||
sysAnnouncement.setCancelTime(new Date());
|
||||
boolean ok = sysAnnouncementService.updateById(sysAnnouncement);
|
||||
if(ok) {
|
||||
return Results.OK("该系统通知撤销成功");
|
||||
}
|
||||
}
|
||||
|
||||
return Results.OK();
|
||||
}
|
||||
|
||||
/**
|
||||
* @功能:补充用户数据,并返回系统消息
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/listByUser")
|
||||
public Results<Map<String,Object>> listByUser() {
|
||||
Results<Map<String,Object>> result = new Results<>();
|
||||
LoginUser sysUser = (LoginUser)SecurityUtils.getSubject().getPrincipal();
|
||||
String userId = sysUser.getId();
|
||||
// 1.将系统消息补充到用户通告阅读标记表中
|
||||
LambdaQueryWrapper<SysAnnouncement> querySaWrapper = new LambdaQueryWrapper<>();
|
||||
querySaWrapper.eq(SysAnnouncement::getMsgType,CommonConstant.MSG_TYPE_ALL); // 全部人员
|
||||
querySaWrapper.eq(SysAnnouncement::getDelFlag,CommonConstant.DEL_FLAG_0.toString()); // 未删除
|
||||
querySaWrapper.eq(SysAnnouncement::getSendStatus, CommonConstant.HAS_SEND); //已发布
|
||||
querySaWrapper.ge(SysAnnouncement::getEndTime, sysUser.getCreateTime()); //新注册用户不看结束通知
|
||||
//update-begin--Author:liusq Date:20210108 for:[JT-424] 【开源issue】bug处理--------------------
|
||||
querySaWrapper.notInSql(SysAnnouncement::getId,"select annt_id from sys_announcement_send where user_id='"+userId+"'");
|
||||
//update-begin--Author:liusq Date:20210108 for: [JT-424] 【开源issue】bug处理--------------------
|
||||
List<SysAnnouncement> announcements = sysAnnouncementService.list(querySaWrapper);
|
||||
if(!announcements.isEmpty()) {
|
||||
for(int i=0;i<announcements.size();i++) {
|
||||
//update-begin--Author:wangshuai Date:20200803 for: 通知公告消息重复LOWCOD-759--------------------
|
||||
//因为websocket没有判断是否存在这个用户,要是判断会出现问题,故在此判断逻辑
|
||||
LambdaQueryWrapper<SysAnnouncementSend> query = new LambdaQueryWrapper<>();
|
||||
query.eq(SysAnnouncementSend::getAnntId,announcements.get(i).getId());
|
||||
query.eq(SysAnnouncementSend::getUserId,userId);
|
||||
SysAnnouncementSend one = sysAnnouncementSendService.getOne(query);
|
||||
if(null==one){
|
||||
SysAnnouncementSend announcementSend = new SysAnnouncementSend();
|
||||
announcementSend.setAnntId(announcements.get(i).getId());
|
||||
announcementSend.setUserId(userId);
|
||||
announcementSend.setReadFlag(CommonConstant.NO_READ_FLAG);
|
||||
sysAnnouncementSendService.save(announcementSend);
|
||||
}
|
||||
//update-end--Author:wangshuai Date:20200803 for: 通知公告消息重复LOWCOD-759------------
|
||||
}
|
||||
}
|
||||
// 2.查询用户未读的系统消息
|
||||
Page<SysAnnouncement> anntMsgList = new Page<>(0,5);
|
||||
anntMsgList = sysAnnouncementService.querySysCementPageByUserId(anntMsgList,userId,"1");//通知公告消息
|
||||
Page<SysAnnouncement> sysMsgList = new Page<>(0,5);
|
||||
sysMsgList = sysAnnouncementService.querySysCementPageByUserId(sysMsgList,userId,"2");//系统消息
|
||||
Map<String,Object> sysMsgMap = new HashMap<>();
|
||||
sysMsgMap.put("sysMsgList", sysMsgList.getRecords());
|
||||
sysMsgMap.put("sysMsgTotal", sysMsgList.getTotal());
|
||||
sysMsgMap.put("anntMsgList", anntMsgList.getRecords());
|
||||
sysMsgMap.put("anntMsgTotal", anntMsgList.getTotal());
|
||||
result.setSuccess(true);
|
||||
result.setResult(sysMsgMap);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*同步消息
|
||||
* @param anntId
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/syncNotic")
|
||||
public Results<SysAnnouncement> syncNotic(@RequestParam(name="anntId",required=false) String anntId, HttpServletRequest request) {
|
||||
Results<SysAnnouncement> result = new Results<>();
|
||||
JSONObject obj = new JSONObject();
|
||||
if(StringUtils.isNotBlank(anntId)){
|
||||
SysAnnouncement sysAnnouncement = sysAnnouncementService.getById(anntId);
|
||||
if(sysAnnouncement==null) {
|
||||
return Results.error(ERROR_TEXT);
|
||||
}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.sendMessage(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.sendMessage(userIds, obj.toJSONString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}else{
|
||||
obj.put(WebsocketConst.MSG_CMD, WebsocketConst.CMD_TOPIC);
|
||||
obj.put(WebsocketConst.MSG_TXT, "批量设置已读");
|
||||
webSocket.sendMessage(obj.toJSONString());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通告查看详情页面
|
||||
* @param modelAndView
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/show/{id}")
|
||||
public ModelAndView showContent(ModelAndView modelAndView, @PathVariable("id") String id, HttpServletRequest request) {
|
||||
SysAnnouncement announcement = sysAnnouncementService.getById(id);
|
||||
if (announcement != null) {
|
||||
boolean tokenOK = false;
|
||||
try {
|
||||
// 验证Token有效性
|
||||
tokenOK = TokenUtils.verifyToken(request, sysBaseAPI, redisUtil);
|
||||
} catch (Exception ignored) {
|
||||
ignored.printStackTrace();
|
||||
}
|
||||
// 判断是否传递了Token,并且Token有效,如果传了就不做查看限制,直接返回
|
||||
// 如果Token无效,就做查看限制:只能查看已发布的
|
||||
if (tokenOK || ANNOUNCEMENT_SEND_STATUS_1.equals(announcement.getSendStatus())) {
|
||||
modelAndView.addObject("data", announcement);
|
||||
modelAndView.setViewName("announcement/showContent");
|
||||
return modelAndView;
|
||||
}
|
||||
}
|
||||
modelAndView.setStatus(HttpStatus.NOT_FOUND);
|
||||
return modelAndView;
|
||||
}
|
||||
|
||||
}
|
||||
+224
@@ -0,0 +1,224 @@
|
||||
package com.jero.modules.system.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.jero.common.api.vo.Results;
|
||||
import com.jero.common.constant.CommonConstant;
|
||||
import com.jero.common.system.vo.LoginUser;
|
||||
import com.jero.common.util.oConvertUtils;
|
||||
import com.jero.modules.system.entity.SysAnnouncementSend;
|
||||
import com.jero.modules.system.model.AnnouncementSendModel;
|
||||
import com.jero.modules.system.service.ISysAnnouncementSendService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Title: Controller
|
||||
* @Description: 用户通告阅读标记表
|
||||
* @Author: jero-boot
|
||||
* @Date: 2019-02-21
|
||||
* @Version: V1.0
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/sys/sysAnnouncementSend")
|
||||
@Slf4j
|
||||
public class SysAnnouncementSendController {
|
||||
@Autowired
|
||||
private ISysAnnouncementSendService sysAnnouncementSendService;
|
||||
private static final String ERROE_MSG = "未找到对应实体";
|
||||
|
||||
/**
|
||||
* 分页列表查询
|
||||
* @param sysAnnouncementSend
|
||||
* @param pageNo
|
||||
* @param pageSize
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/page")
|
||||
public Results<IPage<SysAnnouncementSend>> queryPageList(SysAnnouncementSend sysAnnouncementSend,
|
||||
@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
|
||||
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
|
||||
HttpServletRequest req) {
|
||||
Results<IPage<SysAnnouncementSend>> result = new Results<>();
|
||||
QueryWrapper<SysAnnouncementSend> queryWrapper = new QueryWrapper<>(sysAnnouncementSend);
|
||||
Page<SysAnnouncementSend> page = new Page<>(pageNo,pageSize);
|
||||
//排序逻辑 处理
|
||||
String column = req.getParameter("column");
|
||||
String order = req.getParameter("order");
|
||||
if(oConvertUtils.isNotEmpty(column) && oConvertUtils.isNotEmpty(order)) {
|
||||
if("asc".equals(order)) {
|
||||
queryWrapper.orderByAsc(oConvertUtils.camelToUnderline(column));
|
||||
}else {
|
||||
queryWrapper.orderByDesc(oConvertUtils.camelToUnderline(column));
|
||||
}
|
||||
}
|
||||
IPage<SysAnnouncementSend> pageList = sysAnnouncementSendService.page(page, queryWrapper);
|
||||
result.setSuccess(true);
|
||||
result.setResult(pageList);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
* @param sysAnnouncementSend
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/add")
|
||||
public Results<Object> add(@RequestBody SysAnnouncementSend sysAnnouncementSend) {
|
||||
try {
|
||||
sysAnnouncementSendService.save(sysAnnouncementSend);
|
||||
return Results.OK("操作成功!");
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(),e);
|
||||
return Results.error("操作失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
* @param sysAnnouncementSend
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/edit")
|
||||
public Results<Object> edit(@RequestBody SysAnnouncementSend sysAnnouncementSend) {
|
||||
SysAnnouncementSend sysAnnouncementSendEntity = sysAnnouncementSendService.getById(sysAnnouncementSend.getId());
|
||||
if(sysAnnouncementSendEntity==null) {
|
||||
return Results.error(ERROE_MSG);
|
||||
}else {
|
||||
boolean ok = sysAnnouncementSendService.updateById(sysAnnouncementSend);
|
||||
if(ok) {
|
||||
return Results.OK("操作成功!");
|
||||
}
|
||||
}
|
||||
|
||||
return Results.OK();
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id删除
|
||||
* @param map
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/delete")
|
||||
public Results<Object> delete(@RequestBody Map<String, String> map) {
|
||||
String id = map.get("id");
|
||||
if(StringUtils.isBlank(id)){
|
||||
return Results.error("参数不识别!");
|
||||
}
|
||||
SysAnnouncementSend sysAnnouncementSend = sysAnnouncementSendService.getById(id);
|
||||
if(sysAnnouncementSend==null) {
|
||||
return Results.error(ERROE_MSG);
|
||||
}else {
|
||||
boolean ok = sysAnnouncementSendService.removeById(id);
|
||||
if(ok) {
|
||||
return Results.OK("删除成功!");
|
||||
}
|
||||
}
|
||||
|
||||
return Results.OK();
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
* @param map
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/deleteBatch")
|
||||
public Results<Object> deleteBatch(@RequestBody Map<String, String> map) {
|
||||
String ids = map.get("ids");
|
||||
if(ids == null || "".equals(ids.trim())) {
|
||||
return Results.error("参数不识别!");
|
||||
}else {
|
||||
this.sysAnnouncementSendService.removeByIds(Arrays.asList(ids.split(",")));
|
||||
return Results.OK("删除成功!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id查询
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/queryById")
|
||||
public Results<SysAnnouncementSend> queryById(@RequestParam(name="id",required=true) String id) {
|
||||
SysAnnouncementSend sysAnnouncementSend = sysAnnouncementSendService.getById(id);
|
||||
if(sysAnnouncementSend==null) {
|
||||
return Results.error(ERROE_MSG);
|
||||
}else {
|
||||
return Results.OK(sysAnnouncementSend);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @功能:更新用户系统消息阅读状态
|
||||
* @param json
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/editByAnntIdAndUserId")
|
||||
public Results<SysAnnouncementSend> editById(@RequestBody JSONObject json) {
|
||||
Results<SysAnnouncementSend> result = new Results<>();
|
||||
String anntId = json.getString("anntId");
|
||||
LoginUser sysUser = (LoginUser)SecurityUtils.getSubject().getPrincipal();
|
||||
String userId = sysUser.getId();
|
||||
LambdaUpdateWrapper<SysAnnouncementSend> updateWrapper = new LambdaUpdateWrapper<>();
|
||||
updateWrapper.set(SysAnnouncementSend::getReadFlag, CommonConstant.HAS_READ_FLAG);
|
||||
updateWrapper.set(SysAnnouncementSend::getReadTime, new Date());
|
||||
updateWrapper.last("where annt_id ='"+anntId+"' and user_id ='"+userId+"'");
|
||||
SysAnnouncementSend announcementSend = new SysAnnouncementSend();
|
||||
sysAnnouncementSendService.update(announcementSend, updateWrapper);
|
||||
result.setSuccess(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @功能:获取我的消息
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/getMyAnnouncementSend")
|
||||
@RequiresPermissions("my:mesg:list")
|
||||
public Results<IPage<AnnouncementSendModel>> getMyAnnouncementSend(AnnouncementSendModel announcementSendModel,
|
||||
@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
|
||||
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize) {
|
||||
Results<IPage<AnnouncementSendModel>> result = new Results<>();
|
||||
LoginUser sysUser = (LoginUser)SecurityUtils.getSubject().getPrincipal();
|
||||
String userId = sysUser.getId();
|
||||
announcementSendModel.setUserId(userId);
|
||||
announcementSendModel.setPageNo((pageNo-1)*pageSize);
|
||||
announcementSendModel.setPageSize(pageSize);
|
||||
Page<AnnouncementSendModel> pageList = new Page<>(pageNo,pageSize);
|
||||
pageList = sysAnnouncementSendService.getMyAnnouncementSendPage(pageList, announcementSendModel);
|
||||
result.setResult(pageList);
|
||||
result.setSuccess(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @功能:一键已读
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/readAll")
|
||||
public Results<SysAnnouncementSend> readAll() {
|
||||
LoginUser sysUser = (LoginUser)SecurityUtils.getSubject().getPrincipal();
|
||||
String userId = sysUser.getId();
|
||||
LambdaUpdateWrapper<SysAnnouncementSend> updateWrapper = new LambdaUpdateWrapper<>();
|
||||
updateWrapper.set(SysAnnouncementSend::getReadFlag, CommonConstant.HAS_READ_FLAG);
|
||||
updateWrapper.set(SysAnnouncementSend::getReadTime, new Date());
|
||||
updateWrapper.last("where user_id ='"+userId+"'");
|
||||
SysAnnouncementSend announcementSend = new SysAnnouncementSend();
|
||||
sysAnnouncementSendService.update(announcementSend, updateWrapper);
|
||||
return Results.OK("全部已读");
|
||||
}
|
||||
}
|
||||
+483
@@ -0,0 +1,483 @@
|
||||
package com.jero.modules.system.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.jero.common.api.vo.Results;
|
||||
import com.jero.common.system.base.controller.JeroController;
|
||||
import com.jero.common.system.query.QueryGenerator;
|
||||
import com.jero.common.system.vo.DictModel;
|
||||
import com.jero.common.system.vo.LoginUser;
|
||||
import com.jero.common.util.SpringContextUtils;
|
||||
import com.jero.common.util.oConvertUtils;
|
||||
import com.jero.config.easypoi.EasyPoiDictHandlerImpl;
|
||||
import com.jero.modules.system.entity.SysCategory;
|
||||
import com.jero.modules.system.model.TreeSelectModel;
|
||||
import com.jero.modules.system.service.ISysCategoryService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.poi.ss.formula.functions.T;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import cn.afterturn.easypoi.excel.ExcelImportUtil;
|
||||
import cn.afterturn.easypoi.entity.vo.NormalExcelConstants;
|
||||
import cn.afterturn.easypoi.excel.entity.ExportParams;
|
||||
import cn.afterturn.easypoi.excel.entity.ImportParams;
|
||||
import cn.afterturn.easypoi.view.EasypoiSingleExcelView;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @Description: 分类字典
|
||||
* @Author: jero-boot
|
||||
* @Date: 2019-05-29
|
||||
* @Version: V1.0
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/sys/category")
|
||||
@Slf4j
|
||||
public class SysCategoryController {
|
||||
@Autowired
|
||||
private ISysCategoryService sysCategoryService;
|
||||
private static final String ERROE_MSG = "未找到对应实体";
|
||||
|
||||
/**
|
||||
* 分页列表查询
|
||||
* @param sysCategory
|
||||
* @param pageNo
|
||||
* @param pageSize
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/rootList")
|
||||
public Results<IPage<SysCategory>> queryPageList(SysCategory sysCategory,
|
||||
@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
|
||||
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
|
||||
HttpServletRequest req) {
|
||||
if(oConvertUtils.isEmpty(sysCategory.getPid())){
|
||||
sysCategory.setPid("0");
|
||||
}
|
||||
Results<IPage<SysCategory>> result = new Results<>();
|
||||
|
||||
QueryWrapper<SysCategory> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("pid", sysCategory.getPid());
|
||||
|
||||
Page<SysCategory> page = new Page<>(pageNo, pageSize);
|
||||
IPage<SysCategory> pageList = sysCategoryService.page(page, queryWrapper);
|
||||
result.setSuccess(true);
|
||||
result.setResult(pageList);
|
||||
return result;
|
||||
}
|
||||
|
||||
@GetMapping(value = "/childList")
|
||||
public Results<List<SysCategory>> queryPageList(SysCategory sysCategory, HttpServletRequest req) {
|
||||
Results<List<SysCategory>> result = new Results<>();
|
||||
QueryWrapper<SysCategory> queryWrapper = QueryGenerator.initQueryWrapper(sysCategory, req.getParameterMap());
|
||||
List<SysCategory> list = sysCategoryService.list(queryWrapper);
|
||||
result.setSuccess(true);
|
||||
result.setResult(list);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 添加
|
||||
* @param sysCategory
|
||||
* @return
|
||||
*/
|
||||
@RequiresPermissions("sys:category:add")
|
||||
@PostMapping(value = "/add")
|
||||
public Results<Object> add(@RequestBody SysCategory sysCategory) {
|
||||
try {
|
||||
sysCategoryService.addSysCategory(sysCategory);
|
||||
return Results.OK("操作成功!");
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(),e);
|
||||
return Results.error("操作失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
* @param sysCategory
|
||||
* @return
|
||||
*/
|
||||
@RequiresPermissions("sys:category:edit")
|
||||
@PostMapping(value = "/edit")
|
||||
public Results<Object> edit(@RequestBody SysCategory sysCategory) {
|
||||
SysCategory sysCategoryEntity = sysCategoryService.getById(sysCategory.getId());
|
||||
if(sysCategoryEntity==null) {
|
||||
return Results.error(ERROE_MSG);
|
||||
}else {
|
||||
sysCategoryService.updateSysCategory(sysCategory);
|
||||
return Results.OK("操作成功!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id删除
|
||||
* @param map
|
||||
* @return
|
||||
*/
|
||||
@RequiresPermissions("sys:category:del")
|
||||
@PostMapping(value = "/delete")
|
||||
public Results<Object> delete(@RequestBody Map<String, String> map) {
|
||||
String id = map.get("id");
|
||||
if(StringUtils.isBlank(id)){
|
||||
return Results.error("参数不识别!");
|
||||
}
|
||||
SysCategory sysCategory = sysCategoryService.getById(id);
|
||||
if(sysCategory==null) {
|
||||
return Results.error(ERROE_MSG);
|
||||
}else {
|
||||
this.sysCategoryService.deleteSysCategory(id);
|
||||
return Results.OK("删除成功!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
* @param map
|
||||
* @return
|
||||
*/
|
||||
@RequiresPermissions("sys:category:del")
|
||||
@PostMapping(value = "/deleteBatch")
|
||||
public Results<T> deleteBatch(@RequestBody Map<String, String> map) {
|
||||
String ids = map.get("ids");
|
||||
if(ids==null || "".equals(ids.trim())) {
|
||||
return Results.error("参数不识别!");
|
||||
}else {
|
||||
this.sysCategoryService.deleteSysCategory(ids);
|
||||
return Results.OK("删除成功!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id查询
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
|
||||
@GetMapping(value = "/queryById")
|
||||
public Results<SysCategory> queryById(@RequestParam(name="id",required=true) String id) {
|
||||
SysCategory sysCategory = sysCategoryService.getById(id);
|
||||
if(sysCategory==null) {
|
||||
return Results.error(ERROE_MSG);
|
||||
}else {
|
||||
return Results.OK(sysCategory);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出excel
|
||||
*
|
||||
* @param request
|
||||
*/
|
||||
@RequiresPermissions("sys:category:export")
|
||||
@RequestMapping(value = "/exportXls")
|
||||
public ModelAndView exportXls(HttpServletRequest request, SysCategory sysCategory) {
|
||||
// Step.1 组装查询条件查询数据
|
||||
QueryWrapper<SysCategory> queryWrapper = QueryGenerator.initQueryWrapper(sysCategory, request.getParameterMap());
|
||||
List<SysCategory> pageList = sysCategoryService.list(queryWrapper);
|
||||
// Step.2 AutoPoi 导出Excel
|
||||
ModelAndView mv = new ModelAndView(new EasypoiSingleExcelView());
|
||||
// 过滤选中数据
|
||||
String selections = request.getParameter("selections");
|
||||
if(oConvertUtils.isEmpty(selections)) {
|
||||
mv.addObject(NormalExcelConstants.DATA_LIST, pageList);
|
||||
}else {
|
||||
List<String> selectionList = Arrays.asList(selections.split(","));
|
||||
List<SysCategory> exportList = pageList.stream().filter(item -> selectionList.contains(item.getId())).collect(Collectors.toList());
|
||||
mv.addObject(NormalExcelConstants.DATA_LIST, exportList);
|
||||
}
|
||||
//导出文件名称
|
||||
mv.addObject(JeroController.FILE_NAME, "分类字典列表");
|
||||
mv.addObject(JeroController.CLASS, SysCategory.class);
|
||||
LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
||||
ExportParams exportParams = new ExportParams("分类字典列表数据", "导出人:"+user.getRealname(), "导出信息");
|
||||
exportParams.setDictHandler(SpringContextUtils.getApplicationContext().getBean(EasyPoiDictHandlerImpl.class));
|
||||
mv.addObject(JeroController.PARAMS, exportParams);
|
||||
return mv;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过excel导入数据
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
* @return
|
||||
*/
|
||||
@RequiresPermissions("sys:category:import")
|
||||
|
||||
@PostMapping("/importExcel")
|
||||
public Results<T> importExcel(HttpServletRequest request, HttpServletResponse response) {
|
||||
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
||||
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
|
||||
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
|
||||
MultipartFile file = entity.getValue();// 获取上传文件对象
|
||||
ImportParams params = new ImportParams();
|
||||
params.setTitleRows(2);
|
||||
params.setHeadRows(1);
|
||||
params.setNeedSave(true);
|
||||
try {
|
||||
List<SysCategory> listSysCategorys = ExcelImportUtil.importExcel(file.getInputStream(), SysCategory.class, params);
|
||||
//按照编码长度排序
|
||||
Collections.sort(listSysCategorys);
|
||||
log.info("排序后的list====>",listSysCategorys);
|
||||
for (SysCategory sysCategoryExcel : listSysCategorys) {
|
||||
String code = sysCategoryExcel.getCode();
|
||||
if(code.length()>3){
|
||||
String pCode = sysCategoryExcel.getCode().substring(0,code.length()-3);
|
||||
log.info("pCode====>",pCode);
|
||||
String pId=sysCategoryService.queryIdByCode(pCode);
|
||||
log.info("pId====>",pId);
|
||||
if(StringUtils.isNotBlank(pId)){
|
||||
sysCategoryExcel.setPid(pId);
|
||||
}
|
||||
}else{
|
||||
sysCategoryExcel.setPid("0");
|
||||
}
|
||||
sysCategoryService.save(sysCategoryExcel);
|
||||
}
|
||||
return Results.OK("文件导入成功!数据行数:" + listSysCategorys.size());
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
return Results.error("文件导入失败:"+e.getMessage());
|
||||
} finally {
|
||||
try {
|
||||
file.getInputStream().close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return Results.error("文件导入失败!");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 加载单个数据 用于回显
|
||||
*/
|
||||
// @RequestMapping(value = "/loadOne", method = RequestMethod.GET)
|
||||
@GetMapping("/loadOne")
|
||||
public Results<SysCategory> loadOne(@RequestParam(name="field") String field, @RequestParam(name="val") String val) {
|
||||
try {
|
||||
|
||||
QueryWrapper<SysCategory> query = new QueryWrapper<>();
|
||||
query.eq(field, val);
|
||||
List<SysCategory> ls = this.sysCategoryService.list(query);
|
||||
if(ls==null || ls.isEmpty()) {
|
||||
return Results.error("查询无果");
|
||||
}else if(ls.size()>1) {
|
||||
return Results.error("查询数据异常,["+field+"]存在多个值:"+val);
|
||||
}else {
|
||||
return Results.OK(ls.get(0));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return Results.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载节点的子数据
|
||||
*/
|
||||
@GetMapping("/loadTreeChildren")
|
||||
public Results<List<TreeSelectModel>> loadTreeChildren(@RequestParam(name="pid") String pid) {
|
||||
Results<List<TreeSelectModel>> result = new Results<>();
|
||||
try {
|
||||
List<TreeSelectModel> ls = this.sysCategoryService.queryListByPid(pid);
|
||||
result.setResult(ls);
|
||||
result.setSuccess(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
result.setMessage(e.getMessage());
|
||||
result.setSuccess(false);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载一级节点/如果是同步 则所有数据
|
||||
*/
|
||||
// @RequestMapping(value = "/loadTreeRoot", method = RequestMethod.GET)
|
||||
@GetMapping("/loadTreeRoot")
|
||||
public Results<List<TreeSelectModel>> loadTreeRoot(@RequestParam(name="async") Boolean async, @RequestParam(name="pcode") String pcode) {
|
||||
Results<List<TreeSelectModel>> result = new Results<>();
|
||||
try {
|
||||
List<TreeSelectModel> ls = this.sysCategoryService.queryListByCode(pcode);
|
||||
if(Boolean.FALSE.equals(async)) {
|
||||
loadAllCategoryChildren(ls);
|
||||
}
|
||||
result.setResult(ls);
|
||||
result.setSuccess(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
result.setMessage(e.getMessage());
|
||||
result.setSuccess(false);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
private void loadAllCategoryChildren(List<TreeSelectModel> ls) {
|
||||
for (TreeSelectModel tsm : ls) {
|
||||
List<TreeSelectModel> temp = this.sysCategoryService.queryListByPid(tsm.getKey());
|
||||
if(temp!=null && !temp.isEmpty()) {
|
||||
tsm.setChildren(temp);
|
||||
loadAllCategoryChildren(temp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验编码
|
||||
* @param pid
|
||||
* @param code
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/checkCode")
|
||||
public Results<T> checkCode(@RequestParam(name="pid",required = false) String pid, @RequestParam(name="code",required = false) String code) {
|
||||
if(oConvertUtils.isEmpty(code)){
|
||||
return Results.error("错误,类型编码为空!");
|
||||
}
|
||||
if(oConvertUtils.isEmpty(pid)){
|
||||
return Results.OK();
|
||||
}
|
||||
SysCategory parent = this.sysCategoryService.getById(pid);
|
||||
if(code.startsWith(parent.getCode())){
|
||||
return Results.OK();
|
||||
}else{
|
||||
return Results.error("编码不符合规范,须以\""+parent.getCode()+"\"开头!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 分类字典树控件 加载节点
|
||||
* @param pid
|
||||
* @param pcode
|
||||
* @param condition
|
||||
* @return
|
||||
*/
|
||||
// @RequestMapping(value = "/loadTreeData", method = RequestMethod.GET)
|
||||
@GetMapping("/loadTreeData")
|
||||
public Results<List<TreeSelectModel>> loadDict(@RequestParam(name="pid",required = false) String pid, @RequestParam(name="pcode",required = false) String pcode, @RequestParam(name="condition",required = false) String condition) {
|
||||
Results<List<TreeSelectModel>> result = new Results<>();
|
||||
//pid如果传值了 就忽略pcode的作用
|
||||
if(oConvertUtils.isEmpty(pid)){
|
||||
if(oConvertUtils.isEmpty(pcode)){
|
||||
result.setSuccess(false);
|
||||
result.setMessage("加载分类字典树参数有误.[null]!");
|
||||
return result;
|
||||
}else{
|
||||
if(ISysCategoryService.ROOT_PID_VALUE.equals(pcode)){
|
||||
pid = ISysCategoryService.ROOT_PID_VALUE;
|
||||
}else{
|
||||
pid = this.sysCategoryService.queryIdByCode(pcode);
|
||||
}
|
||||
if(oConvertUtils.isEmpty(pid)){
|
||||
result.setSuccess(false);
|
||||
result.setMessage("加载分类字典树参数有误.[code]!");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
Map<String, String> query = null;
|
||||
if(oConvertUtils.isNotEmpty(condition)) {
|
||||
query = JSON.parseObject(condition, Map.class);
|
||||
}
|
||||
List<TreeSelectModel> ls = sysCategoryService.queryListByPid(pid,query);
|
||||
result.setSuccess(true);
|
||||
result.setResult(ls);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 分类字典控件数据回显[表单页面]
|
||||
*
|
||||
* @param ids
|
||||
* @param delNotExist 是否移除不存在的项,默认为true,设为false如果某个key不存在数据库中,则直接返回key本身
|
||||
* @return
|
||||
*/
|
||||
// @RequestMapping(value = "/loadDictItem", method = RequestMethod.GET)
|
||||
@GetMapping("/loadDictItem")
|
||||
public Results<List<String>> loadDictItem(@RequestParam(name = "ids") String ids, @RequestParam(name = "delNotExist", required = false, defaultValue = "true") boolean delNotExist) {
|
||||
Results<List<String>> result = new Results<>();
|
||||
// 非空判断
|
||||
if (StringUtils.isBlank(ids)) {
|
||||
result.setSuccess(false);
|
||||
result.setMessage("ids 不能为空");
|
||||
return result;
|
||||
}
|
||||
// 查询数据
|
||||
List<String> textList = sysCategoryService.loadDictItem(ids, delNotExist);
|
||||
result.setSuccess(true);
|
||||
result.setResult(textList);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* [列表页面]加载分类字典数据 用于值的替换
|
||||
* @param code
|
||||
* @return
|
||||
*/
|
||||
// @RequestMapping(value = "/loadAllData", method = RequestMethod.GET)
|
||||
@GetMapping("/loadAllData")
|
||||
public Results<List<DictModel>> loadAllData(@RequestParam(name="code",required = true) String code) {
|
||||
Results<List<DictModel>> result = new Results<>();
|
||||
LambdaQueryWrapper<SysCategory> query = new LambdaQueryWrapper<>();
|
||||
if(oConvertUtils.isNotEmpty(code) && !"0".equals(code)){
|
||||
query.likeRight(SysCategory::getCode,code);
|
||||
}
|
||||
List<SysCategory> list = this.sysCategoryService.list(query);
|
||||
if(list==null || list.isEmpty()) {
|
||||
result.setMessage("无数据,参数有误.[code]");
|
||||
result.setSuccess(false);
|
||||
return result;
|
||||
}
|
||||
List<DictModel> rdList = new ArrayList<>();
|
||||
for (SysCategory c : list) {
|
||||
rdList.add(new DictModel(c.getId(),c.getName()));
|
||||
}
|
||||
result.setSuccess(true);
|
||||
result.setResult(rdList);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据父级id批量查询子节点
|
||||
* @param parentIds
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getChildListBatch")
|
||||
public Results<IPage<SysCategory>> getChildListBatch(@RequestParam("parentIds") String parentIds) {
|
||||
try {
|
||||
QueryWrapper<SysCategory> queryWrapper = new QueryWrapper<>();
|
||||
List<String> parentIdList = Arrays.asList(parentIds.split(","));
|
||||
queryWrapper.in("pid", parentIdList);
|
||||
List<SysCategory> list = sysCategoryService.list(queryWrapper);
|
||||
IPage<SysCategory> pageList = new Page<>(1, 10, list.size());
|
||||
pageList.setRecords(list);
|
||||
return Results.OK(pageList);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
return Results.error("批量查询子节点失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+198
@@ -0,0 +1,198 @@
|
||||
package com.jero.modules.system.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.jero.common.api.vo.Results;
|
||||
import com.jero.common.aspect.annotation.AutoLog;
|
||||
import com.jero.common.system.base.controller.JeroController;
|
||||
import com.jero.common.system.query.QueryGenerator;
|
||||
import com.jero.modules.system.entity.SysCheckRule;
|
||||
import com.jero.modules.system.service.ISysCheckRuleService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.poi.ss.formula.functions.T;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Description: 编码校验规则
|
||||
* @Author: jero-boot
|
||||
* @Date: 2020-02-04
|
||||
* @Version: V1.0
|
||||
*/
|
||||
@Slf4j
|
||||
@Api(tags = "编码校验规则")
|
||||
@RestController
|
||||
@RequestMapping("/sys/checkRule")
|
||||
public class SysCheckRuleController extends JeroController<SysCheckRule, ISysCheckRuleService> {
|
||||
|
||||
@Autowired
|
||||
private ISysCheckRuleService sysCheckRuleService;
|
||||
|
||||
/**
|
||||
* 分页列表查询
|
||||
*
|
||||
* @param sysCheckRule
|
||||
* @param pageNo
|
||||
* @param pageSize
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "编码校验规则-分页列表查询")
|
||||
@ApiOperation(value = "编码校验规则-分页列表查询", notes = "编码校验规则-分页列表查询")
|
||||
@GetMapping(value = "/page")
|
||||
public Results<IPage<SysCheckRule>> queryPageList(
|
||||
SysCheckRule sysCheckRule,
|
||||
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
|
||||
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
|
||||
HttpServletRequest request
|
||||
) {
|
||||
QueryWrapper<SysCheckRule> queryWrapper = QueryGenerator.initQueryWrapper(sysCheckRule, request.getParameterMap());
|
||||
Page<SysCheckRule> page = new Page<>(pageNo, pageSize);
|
||||
IPage<SysCheckRule> pageList = sysCheckRuleService.page(page, queryWrapper);
|
||||
return Results.OK(pageList);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 通过id查询
|
||||
*
|
||||
* @param ruleCode
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "编码校验规则-通过Code校验传入的值")
|
||||
@ApiOperation(value = "编码校验规则-通过Code校验传入的值", notes = "编码校验规则-通过Code校验传入的值")
|
||||
@GetMapping(value = "/checkByCode")
|
||||
public Results<Object> checkByCode(
|
||||
@RequestParam(name = "ruleCode") String ruleCode,
|
||||
@RequestParam(name = "value") String value
|
||||
) throws UnsupportedEncodingException {
|
||||
SysCheckRule sysCheckRule = sysCheckRuleService.getByCode(ruleCode);
|
||||
if (sysCheckRule == null) {
|
||||
return Results.error("该编码不存在");
|
||||
}
|
||||
JSONObject errorResult = sysCheckRuleService.checkValue(sysCheckRule, URLDecoder.decode(value, "UTF-8"));
|
||||
if (errorResult.isEmpty()) {
|
||||
return Results.OK();
|
||||
} else {
|
||||
Results<Object> r = Results.error(errorResult.getString("message"));
|
||||
r.setResult(errorResult);
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*
|
||||
* @param sysCheckRule
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "编码校验规则-添加")
|
||||
@ApiOperation(value = "编码校验规则-添加", notes = "编码校验规则-添加")
|
||||
@PostMapping(value = "/add")
|
||||
public Results<T> add(@RequestBody SysCheckRule sysCheckRule) {
|
||||
sysCheckRuleService.save(sysCheckRule);
|
||||
return Results.OK("操作成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*
|
||||
* @param sysCheckRule
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "编码校验规则-编辑")
|
||||
@ApiOperation(value = "编码校验规则-编辑", notes = "编码校验规则-编辑")
|
||||
@PostMapping(value = "/edit")
|
||||
public Results<T> edit(@RequestBody SysCheckRule sysCheckRule) {
|
||||
sysCheckRuleService.updateById(sysCheckRule);
|
||||
return Results.OK("操作成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id删除
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "编码校验规则-通过id删除")
|
||||
@ApiOperation(value = "编码校验规则-通过id删除", notes = "编码校验规则-通过id删除")
|
||||
@PostMapping(value = "/delete")
|
||||
public Results<T> delete(@RequestBody Map<String, String> map) {
|
||||
String id = map.get("id");
|
||||
if(StringUtils.isBlank(id)){
|
||||
return Results.error("参数不识别!");
|
||||
}
|
||||
sysCheckRuleService.removeById(id);
|
||||
return Results.OK("删除成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
*
|
||||
* @param map
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "编码校验规则-批量删除")
|
||||
@ApiOperation(value = "编码校验规则-批量删除", notes = "编码校验规则-批量删除")
|
||||
@PostMapping(value = "/deleteBatch")
|
||||
public Results<T> deleteBatch(@RequestBody Map<String, String> map) {
|
||||
String ids = map.get("ids");
|
||||
if(StringUtils.isBlank(ids)){
|
||||
return Results.error("参数不识别!");
|
||||
}
|
||||
this.sysCheckRuleService.removeByIds(Arrays.asList(ids.split(",")));
|
||||
return Results.OK("批量删除成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id查询
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "编码校验规则-通过id查询")
|
||||
@ApiOperation(value = "编码校验规则-通过id查询", notes = "编码校验规则-通过id查询")
|
||||
@GetMapping(value = "/queryById")
|
||||
public Results<SysCheckRule> queryById(@RequestParam(name = "id", required = true) String id) {
|
||||
SysCheckRule sysCheckRule = sysCheckRuleService.getById(id);
|
||||
return Results.OK(sysCheckRule);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出excel
|
||||
*
|
||||
* @param request
|
||||
* @param sysCheckRule
|
||||
*/
|
||||
@RequestMapping(value = "/exportXls")
|
||||
public ModelAndView exportXls(HttpServletRequest request, SysCheckRule sysCheckRule) {
|
||||
return super.exportXls(request, sysCheckRule, SysCheckRule.class, "编码校验规则");
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过excel导入数据
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
* @return
|
||||
*/
|
||||
// @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
|
||||
@PostMapping("/importExcel")
|
||||
public Results<SysCheckRule> importExcel(HttpServletRequest request, HttpServletResponse response) {
|
||||
return super.importExcel(request, response, SysCheckRule.class);
|
||||
}
|
||||
|
||||
}
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
package com.jero.modules.system.controller;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import com.jero.common.api.vo.Results;
|
||||
import com.jero.common.system.query.QueryGenerator;
|
||||
import com.jero.modules.system.entity.SysDataLog;
|
||||
import com.jero.modules.system.service.ISysDataLogService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/sys/dataLog")
|
||||
@Slf4j
|
||||
public class SysDataLogController {
|
||||
@Autowired
|
||||
private ISysDataLogService service;
|
||||
|
||||
|
||||
@GetMapping("/page")
|
||||
public Results<IPage<SysDataLog>> queryPageList(SysDataLog dataLog, @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
|
||||
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize, HttpServletRequest req) {
|
||||
Results<IPage<SysDataLog>> result = new Results<>();
|
||||
QueryWrapper<SysDataLog> queryWrapper = QueryGenerator.initQueryWrapper(dataLog, req.getParameterMap());
|
||||
Page<SysDataLog> page = new Page<>(pageNo, pageSize);
|
||||
IPage<SysDataLog> pageList = service.page(page, queryWrapper);
|
||||
log.info("查询当前页:"+pageList.getCurrent());
|
||||
log.info("查询当前页数量:"+pageList.getSize());
|
||||
log.info("查询结果数量:"+pageList.getRecords().size());
|
||||
log.info("数据总数:"+pageList.getTotal());
|
||||
result.setSuccess(true);
|
||||
result.setResult(pageList);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询对比数据
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
|
||||
@GetMapping("/queryCompareList")
|
||||
public Results<List<SysDataLog>> queryCompareList(HttpServletRequest req) {
|
||||
Results<List<SysDataLog>> result = new Results<>();
|
||||
String dataId1 = req.getParameter("dataId1");
|
||||
String dataId2 = req.getParameter("dataId2");
|
||||
List<String> idList = new ArrayList<>();
|
||||
idList.add(dataId1);
|
||||
idList.add(dataId2);
|
||||
try {
|
||||
List<SysDataLog> list = service.listByIds(idList);
|
||||
result.setResult(list);
|
||||
result.setSuccess(true);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(),e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询版本信息
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
|
||||
@GetMapping("/queryDataVerList")
|
||||
public Results<List<SysDataLog>> queryDataVerList(HttpServletRequest req) {
|
||||
Results<List<SysDataLog>> result = new Results<>();
|
||||
String dataTable = req.getParameter("dataTable");
|
||||
String dataId = req.getParameter("dataId");
|
||||
QueryWrapper<SysDataLog> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("data_table", dataTable);
|
||||
queryWrapper.eq("data_id", dataId);
|
||||
List<SysDataLog> list = service.list(queryWrapper);
|
||||
if(list==null||list.isEmpty()) {
|
||||
return Results.error("未找到版本信息");
|
||||
}else {
|
||||
result.setResult(list);
|
||||
result.setSuccess(true);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
+227
@@ -0,0 +1,227 @@
|
||||
package com.jero.modules.system.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.jero.common.api.vo.Results;
|
||||
import com.jero.common.aspect.annotation.AutoLog;
|
||||
import com.jero.common.system.base.controller.JeroController;
|
||||
import com.jero.common.system.query.QueryGenerator;
|
||||
import com.jero.common.util.dynamic.db.DataSourceCachePool;
|
||||
import com.jero.modules.system.entity.SysDataSource;
|
||||
import com.jero.modules.system.service.ISysDataSourceService;
|
||||
import com.jero.modules.system.util.SecurityUtil;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.poi.ss.formula.functions.T;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Description: 多数据源管理
|
||||
* @Author: jero-boot
|
||||
* @Date: 2019-12-25
|
||||
* @Version: V1.0
|
||||
*/
|
||||
@Slf4j
|
||||
@Api(tags = "多数据源管理")
|
||||
@RestController
|
||||
@RequestMapping("/sys/dataSource")
|
||||
public class SysDataSourceController extends JeroController<SysDataSource, ISysDataSourceService> {
|
||||
|
||||
@Autowired
|
||||
private ISysDataSourceService sysDataSourceService;
|
||||
|
||||
/**
|
||||
* 分页列表查询
|
||||
*
|
||||
* @param sysDataSource
|
||||
* @param pageNo
|
||||
* @param pageSize
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "多数据源管理-分页列表查询")
|
||||
@ApiOperation(value = "多数据源管理-分页列表查询", notes = "多数据源管理-分页列表查询")
|
||||
@GetMapping(value = "/page")
|
||||
public Results<IPage<SysDataSource>> queryPageList(
|
||||
SysDataSource sysDataSource,
|
||||
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
|
||||
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
|
||||
HttpServletRequest req
|
||||
) {
|
||||
QueryWrapper<SysDataSource> queryWrapper = QueryGenerator.initQueryWrapper(sysDataSource, req.getParameterMap());
|
||||
Page<SysDataSource> page = new Page<>(pageNo, pageSize);
|
||||
IPage<SysDataSource> pageList = sysDataSourceService.page(page, queryWrapper);
|
||||
try {
|
||||
List<SysDataSource> records = pageList.getRecords();
|
||||
records.forEach(item->{
|
||||
String dbPassword = item.getDbPassword();
|
||||
if(StringUtils.isNotBlank(dbPassword)){
|
||||
String decodedStr = SecurityUtil.jiemi(dbPassword);
|
||||
item.setDbPassword(decodedStr);
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return Results.error(e.getMessage());
|
||||
}
|
||||
return Results.OK(pageList);
|
||||
}
|
||||
|
||||
@GetMapping(value = "/options")
|
||||
public Results<JSONArray> queryOptions(SysDataSource sysDataSource, HttpServletRequest req) {
|
||||
QueryWrapper<SysDataSource> queryWrapper = QueryGenerator.initQueryWrapper(sysDataSource, req.getParameterMap());
|
||||
List<SysDataSource> pageList = sysDataSourceService.list(queryWrapper);
|
||||
JSONArray array = new JSONArray(pageList.size());
|
||||
for (SysDataSource item : pageList) {
|
||||
JSONObject option = new JSONObject(3);
|
||||
option.put("value", item.getCode());
|
||||
option.put("label", item.getName());
|
||||
option.put("text", item.getName());
|
||||
array.add(option);
|
||||
}
|
||||
return Results.OK(array);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*
|
||||
* @param sysDataSource
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "多数据源管理-添加")
|
||||
@ApiOperation(value = "多数据源管理-添加", notes = "多数据源管理-添加")
|
||||
@PostMapping(value = "/add")
|
||||
public Results<T> add(@RequestBody SysDataSource sysDataSource) {
|
||||
try {
|
||||
String dbPassword = sysDataSource.getDbPassword();
|
||||
if(StringUtils.isNotBlank(dbPassword)){
|
||||
String encrypt = SecurityUtil.jiami(dbPassword);
|
||||
sysDataSource.setDbPassword(encrypt);
|
||||
}
|
||||
sysDataSourceService.save(sysDataSource);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return Results.OK("操作成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*
|
||||
* @param sysDataSource
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "多数据源管理-编辑")
|
||||
@ApiOperation(value = "多数据源管理-编辑", notes = "多数据源管理-编辑")
|
||||
@PostMapping(value = "/edit")
|
||||
public Results<T> edit(@RequestBody SysDataSource sysDataSource) {
|
||||
try {
|
||||
SysDataSource d = sysDataSourceService.getById(sysDataSource.getId());
|
||||
DataSourceCachePool.removeCache(d.getCode());
|
||||
String dbPassword = sysDataSource.getDbPassword();
|
||||
if(StringUtils.isNotBlank(dbPassword)){
|
||||
String encrypt = SecurityUtil.jiami(dbPassword);
|
||||
sysDataSource.setDbPassword(encrypt);
|
||||
}
|
||||
sysDataSourceService.updateById(sysDataSource);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return Results.OK("操作成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id删除
|
||||
*
|
||||
* @param map
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "多数据源管理-通过id删除")
|
||||
@ApiOperation(value = "多数据源管理-通过id删除", notes = "多数据源管理-通过id删除")
|
||||
@PostMapping(value = "/delete")
|
||||
public Results<T> delete(@RequestBody Map<String, String> map) {
|
||||
String id = map.get("id");
|
||||
if(StringUtils.isBlank(id)){
|
||||
return Results.error("参数不识别!");
|
||||
}
|
||||
SysDataSource sysDataSource = sysDataSourceService.getById(id);
|
||||
DataSourceCachePool.removeCache(sysDataSource.getCode());
|
||||
sysDataSourceService.removeById(id);
|
||||
return Results.OK("删除成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
*
|
||||
* @param map
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "多数据源管理-批量删除")
|
||||
@ApiOperation(value = "多数据源管理-批量删除", notes = "多数据源管理-批量删除")
|
||||
@PostMapping(value = "/deleteBatch")
|
||||
public Results<T> deleteBatch(@RequestBody Map<String, String> map) {
|
||||
String ids = map.get("ids");
|
||||
if(StringUtils.isBlank(ids)){
|
||||
return Results.error("参数不识别!");
|
||||
}
|
||||
List<String> idList = Arrays.asList(ids.split(","));
|
||||
idList.forEach(item->{
|
||||
SysDataSource sysDataSource = sysDataSourceService.getById(item);
|
||||
DataSourceCachePool.removeCache(sysDataSource.getCode());
|
||||
});
|
||||
this.sysDataSourceService.removeByIds(idList);
|
||||
return Results.OK("批量删除成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id查询
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "多数据源管理-通过id查询")
|
||||
@ApiOperation(value = "多数据源管理-通过id查询", notes = "多数据源管理-通过id查询")
|
||||
@GetMapping(value = "/queryById")
|
||||
public Results<SysDataSource> queryById(@RequestParam(name = "id") String id) {
|
||||
SysDataSource sysDataSource = sysDataSourceService.getById(id);
|
||||
return Results.OK(sysDataSource);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出excel
|
||||
*
|
||||
* @param request
|
||||
* @param sysDataSource
|
||||
*/
|
||||
@RequestMapping(value = "/exportXls")
|
||||
public ModelAndView exportXls(HttpServletRequest request, SysDataSource sysDataSource) {
|
||||
return super.exportXls(request, sysDataSource, SysDataSource.class, "多数据源管理");
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过excel导入数据
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
* @return
|
||||
*/
|
||||
// @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
|
||||
@PostMapping("/importExcel")
|
||||
public Results<SysDataSource> importExcel(HttpServletRequest request, HttpServletResponse response) {
|
||||
return super.importExcel(request, response, SysDataSource.class);
|
||||
}
|
||||
|
||||
}
|
||||
+517
@@ -0,0 +1,517 @@
|
||||
package com.jero.modules.system.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.jero.common.api.vo.Results;
|
||||
import com.jero.common.constant.CacheConstant;
|
||||
import com.jero.common.constant.CommonConstant;
|
||||
import com.jero.common.system.base.controller.JeroController;
|
||||
import com.jero.common.system.query.QueryGenerator;
|
||||
import com.jero.common.system.util.JwtUtil;
|
||||
import com.jero.common.system.vo.LoginUser;
|
||||
import com.jero.common.system.vo.SysDepartTreeModel;
|
||||
import com.jero.common.util.ImportExcelUtil;
|
||||
import com.jero.common.util.SpringContextUtils;
|
||||
import com.jero.common.util.YouBianCodeUtil;
|
||||
import com.jero.common.util.oConvertUtils;
|
||||
import com.jero.config.easypoi.EasyPoiDictHandlerImpl;
|
||||
import com.jero.modules.system.entity.SysDepart;
|
||||
import com.jero.modules.system.entity.SysUser;
|
||||
import com.jero.modules.system.mapper.SysDepartMapper;
|
||||
import com.jero.modules.system.model.DepartIdModel;
|
||||
import com.jero.modules.system.service.ISysDepartService;
|
||||
import com.jero.modules.system.service.ISysUserDepartService;
|
||||
import com.jero.modules.system.service.ISysUserService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import cn.afterturn.easypoi.excel.ExcelImportUtil;
|
||||
import cn.afterturn.easypoi.entity.vo.NormalExcelConstants;
|
||||
import cn.afterturn.easypoi.excel.entity.ExportParams;
|
||||
import cn.afterturn.easypoi.excel.entity.ImportParams;
|
||||
import cn.afterturn.easypoi.view.EasypoiSingleExcelView;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 部门表 前端控制器
|
||||
* <p>
|
||||
*
|
||||
* @Author: Steve @Since: 2019-01-22
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/sys/sysDepart")
|
||||
@Slf4j
|
||||
public class SysDepartController {
|
||||
|
||||
@Autowired
|
||||
private ISysDepartService sysDepartService;
|
||||
@Autowired
|
||||
public RedisTemplate<String, Object> redisTemplate;
|
||||
@Autowired
|
||||
private ISysUserService sysUserService;
|
||||
@Autowired
|
||||
private ISysUserDepartService sysUserDepartService;
|
||||
|
||||
@Autowired
|
||||
private SysDepartMapper sysDepartMapper;
|
||||
/**
|
||||
* 查询数据 查出我的部门,并以树结构数据格式响应给前端
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
|
||||
@GetMapping("/queryMyDeptTreeList")
|
||||
public Results<List<SysDepartTreeModel>> queryMyDeptTreeList() {
|
||||
Results<List<SysDepartTreeModel>> result = new Results<>();
|
||||
LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
||||
try {
|
||||
if(oConvertUtils.isNotEmpty(user.getUserIdentity()) && user.getUserIdentity().equals( CommonConstant.USER_IDENTITY_2 )){
|
||||
//update-begin--Author:liusq Date:20210624 for:部门查询ids为空后的前端显示问题 issues/I3UD06
|
||||
String departIds = user.getDepartIds();
|
||||
if(StringUtils.isNotBlank(departIds)){
|
||||
List<SysDepartTreeModel> list = sysDepartService.queryMyDeptTreeList(departIds);
|
||||
result.setResult(list);
|
||||
}
|
||||
//update-end--Author:liusq Date:20210624 for:部门查询ids为空后的前端显示问题 issues/I3UD06
|
||||
result.setMessage(CommonConstant.USER_IDENTITY_2.toString());
|
||||
result.setSuccess(true);
|
||||
}else{
|
||||
result.setMessage(CommonConstant.USER_IDENTITY_1.toString());
|
||||
result.setSuccess(true);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(),e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询数据 查出所有部门,并以树结构数据格式响应给前端
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
|
||||
@GetMapping("/queryTreeList")
|
||||
public Results<List<SysDepartTreeModel>> queryTreeList() {
|
||||
Results<List<SysDepartTreeModel>> result = new Results<>();
|
||||
try {
|
||||
List<SysDepartTreeModel> list = sysDepartService.queryTreeList();
|
||||
result.setResult(list);
|
||||
result.setSuccess(true);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(),e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 异步查询部门list
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
|
||||
@GetMapping("/queryDepartTreeSync")
|
||||
public Results<List<SysDepartTreeModel>> queryDepartTreeSync(@RequestParam(name = "pid", required = false) String parentId) {
|
||||
Results<List<SysDepartTreeModel>> result = new Results<>();
|
||||
try {
|
||||
List<SysDepartTreeModel> list = sysDepartService.queryTreeListByPid(parentId);
|
||||
result.setResult(list);
|
||||
result.setSuccess(true);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(),e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取某个部门的所有父级部门的ID
|
||||
*
|
||||
* @param departId 根据departId查
|
||||
* @param orgCode 根据orgCode查,departId和orgCode必须有一个不为空
|
||||
*/
|
||||
@GetMapping("/queryAllParentId")
|
||||
public Results<JSONObject> queryParentIds(
|
||||
@RequestParam(name = "departId", required = false) String departId,
|
||||
@RequestParam(name = "orgCode", required = false) String orgCode
|
||||
) {
|
||||
try {
|
||||
JSONObject data;
|
||||
if (oConvertUtils.isNotEmpty(departId)) {
|
||||
data = sysDepartService.queryAllParentIdByDepartId(departId);
|
||||
} else if (oConvertUtils.isNotEmpty(orgCode)) {
|
||||
data = sysDepartService.queryAllParentIdByOrgCode(orgCode);
|
||||
} else {
|
||||
return Results.error("departId 和 orgCode 不能都为空!");
|
||||
}
|
||||
return Results.OK(data);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
return Results.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加新数据 添加用户新建的部门对象数据,并保存到数据库
|
||||
*
|
||||
* @param sysDepart
|
||||
* @return
|
||||
*/
|
||||
//@RequiresRoles({"admin"})
|
||||
@RequiresPermissions("sys:depart:add")
|
||||
@PostMapping("/add")
|
||||
@CacheEvict(value= {CacheConstant.SYS_DEPARTS_CACHE,CacheConstant.SYS_DEPART_IDS_CACHE}, allEntries=true)
|
||||
public Results<Object> add(@RequestBody SysDepart sysDepart, HttpServletRequest request) {
|
||||
String username = JwtUtil.getUserNameByToken(request);
|
||||
try {
|
||||
long count = sysDepartMapper.selectCountByPId(sysDepart);
|
||||
if(count > 0){
|
||||
return Results.error("同级目录下,名称不能重复");
|
||||
}
|
||||
sysDepart.setCreateBy(username);
|
||||
sysDepartService.saveDepartData(sysDepart, username);
|
||||
return Results.OK("操作成功!");
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(),e);
|
||||
return Results.error("操作失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑数据 编辑部门的部分数据,并保存到数据库
|
||||
*
|
||||
* @param sysDepart
|
||||
* @return
|
||||
*/
|
||||
//@RequiresRoles({"admin"})
|
||||
@RequiresPermissions("sys:depart:edit")
|
||||
@PostMapping("/edit")
|
||||
@CacheEvict(value= {CacheConstant.SYS_DEPARTS_CACHE,CacheConstant.SYS_DEPART_IDS_CACHE}, allEntries=true)
|
||||
public Results<Object> edit(@RequestBody SysDepart sysDepart, HttpServletRequest request) {
|
||||
long count = sysDepartMapper.selectCountByPId(sysDepart);
|
||||
if(count > 0){
|
||||
return Results.error("同级目录下,名称不能重复");
|
||||
}
|
||||
String username = JwtUtil.getUserNameByToken(request);
|
||||
sysDepart.setUpdateBy(username);
|
||||
SysDepart sysDepartEntity = sysDepartService.getById(sysDepart.getId());
|
||||
if (sysDepartEntity == null) {
|
||||
return Results.error("未找到对应实体");
|
||||
} else {
|
||||
boolean ok = sysDepartService.updateDepartDataById(sysDepart, username);
|
||||
if (ok) {
|
||||
return Results.OK("操作成功!");
|
||||
}
|
||||
}
|
||||
return Results.OK();
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id删除
|
||||
* @param map
|
||||
* @return
|
||||
*/
|
||||
//@RequiresRoles({"admin"})
|
||||
@RequiresPermissions("sys:depart:del")
|
||||
@PostMapping("/delete")
|
||||
@CacheEvict(value= {CacheConstant.SYS_DEPARTS_CACHE,CacheConstant.SYS_DEPART_IDS_CACHE}, allEntries=true)
|
||||
public Results<Object> delete(@RequestBody Map<String,String> map) {
|
||||
String id = map.get("id");
|
||||
if(org.apache.commons.lang.StringUtils.isBlank(id)){
|
||||
return Results.error("参数不识别!");
|
||||
}
|
||||
SysDepart sysDepart = sysDepartService.getById(id);
|
||||
if(sysDepart==null) {
|
||||
return Results.error("未找到对应实体");
|
||||
}else {
|
||||
boolean ok = sysDepartService.delete(id);
|
||||
if(ok) {
|
||||
return Results.OK("删除成功!");
|
||||
}
|
||||
}
|
||||
return Results.OK();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 批量删除 根据前端请求的多个ID,对数据库执行删除相关部门数据的操作
|
||||
*
|
||||
* @param map
|
||||
* @return
|
||||
*/
|
||||
//@RequiresRoles({"admin"})
|
||||
@RequiresPermissions("sys:depart:del")
|
||||
@PostMapping("/deleteBatch")
|
||||
@CacheEvict(value= {CacheConstant.SYS_DEPARTS_CACHE,CacheConstant.SYS_DEPART_IDS_CACHE}, allEntries=true)
|
||||
public Results<Object> deleteBatch(@RequestBody Map<String,String> map) {
|
||||
String ids = map.get("ids");
|
||||
if (ids == null || "".equals(ids.trim())) {
|
||||
return Results.error("参数不识别!");
|
||||
} else {
|
||||
this.sysDepartService.deleteBatchWithChildren(Arrays.asList(ids.split(",")));
|
||||
return Results.OK("删除成功!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询数据 添加或编辑页面对该方法发起请求,以树结构形式加载所有部门的名称,方便用户的操作
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/queryIdTree")
|
||||
public Results<List<DepartIdModel>> queryIdTree() {
|
||||
try {
|
||||
List<DepartIdModel> list = sysDepartService.queryDepartIdTreeList();
|
||||
return Results.OK(list);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(),e);
|
||||
return Results.error("查询失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 部门搜索功能方法,根据关键字模糊搜索相关部门
|
||||
* </p>
|
||||
*
|
||||
* @param keyWord
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/searchBy")
|
||||
public Results<List<SysDepartTreeModel>> searchBy(@RequestParam(name = "keyWord", required = true) String keyWord, @RequestParam(name = "myDeptSearch", required = false) String myDeptSearch) {
|
||||
//部门查询,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.isEmpty()) {
|
||||
return Results.error("未查询匹配数据!");
|
||||
}
|
||||
return Results.OK(treeList);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 导出excel
|
||||
*
|
||||
* @param request
|
||||
*/
|
||||
@RequiresPermissions("sys:depart:export")
|
||||
@RequestMapping(value = "/exportXls")
|
||||
public ModelAndView exportXls(SysDepart sysDepart,HttpServletRequest request) {
|
||||
// Step.1 组装查询条件
|
||||
QueryWrapper<SysDepart> queryWrapper = QueryGenerator.initQueryWrapper(sysDepart, request.getParameterMap());
|
||||
//Step.2 AutoPoi 导出Excel
|
||||
ModelAndView mv = new ModelAndView(new EasypoiSingleExcelView());
|
||||
List<SysDepart> pageList = sysDepartService.list(queryWrapper);
|
||||
//按字典排序
|
||||
Collections.sort(pageList,(SysDepart arg0, SysDepart arg1)-> arg0.getOrgCode().compareTo(arg1.getOrgCode()));
|
||||
//导出文件名称
|
||||
mv.addObject(JeroController.FILE_NAME, "部门列表");
|
||||
mv.addObject(JeroController.CLASS, SysDepart.class);
|
||||
LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
||||
ExportParams exportParams = new ExportParams("部门列表数据", "导出人:"+user.getRealname(), "导出信息");
|
||||
exportParams.setDictHandler(SpringContextUtils.getApplicationContext().getBean(EasyPoiDictHandlerImpl.class));
|
||||
mv.addObject(JeroController.PARAMS, exportParams);
|
||||
mv.addObject(NormalExcelConstants.DATA_LIST, pageList);
|
||||
return mv;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过excel导入数据
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
* @return
|
||||
*/
|
||||
//@RequiresRoles({"admin"})
|
||||
@RequiresPermissions("sys:depart:import")
|
||||
// @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
|
||||
@PostMapping("/importExcel")
|
||||
@CacheEvict(value= {CacheConstant.SYS_DEPARTS_CACHE,CacheConstant.SYS_DEPART_IDS_CACHE}, allEntries=true)
|
||||
public Results<JSONObject> 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();// 获取上传文件对象
|
||||
ImportParams params = new ImportParams();
|
||||
params.setDictHandler(SpringContextUtils.getApplicationContext().getBean(EasyPoiDictHandlerImpl.class));
|
||||
params.setTitleRows(2);
|
||||
params.setHeadRows(1);
|
||||
params.setNeedSave(true);
|
||||
try {
|
||||
// orgCode编码长度
|
||||
int codeLength = YouBianCodeUtil.ZHANWEI_LENGTH;
|
||||
listSysDeparts = ExcelImportUtil.importExcel(file.getInputStream(), SysDepart.class, params);
|
||||
// TODO 按长度排序 当比较到最后一个元素时会出现空指针 导入需要做orgCode必填效验
|
||||
Collections.sort(listSysDeparts, (SysDepart arg0, SysDepart arg1) -> arg0.getOrgCode().length() - arg1.getOrgCode().length());
|
||||
|
||||
int num = 0;
|
||||
for (SysDepart sysDepart : listSysDeparts) {
|
||||
String orgCode = sysDepart.getOrgCode();
|
||||
if(orgCode.length() > codeLength) {
|
||||
String parentCode = orgCode.substring(0, orgCode.length()-codeLength);
|
||||
QueryWrapper<SysDepart> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("org_code", parentCode);
|
||||
setParentId(sysDepart, queryWrapper);
|
||||
}else{
|
||||
sysDepart.setParentId("");
|
||||
}
|
||||
//update-begin---author:liusq Date:20210223 for:批量导入部门以后,不能追加下一级部门 #2245------------
|
||||
sysDepart.setOrgType(sysDepart.getOrgCode().length()/codeLength+"");
|
||||
//update-end---author:liusq Date:20210223 for:批量导入部门以后,不能追加下一级部门 #2245------------
|
||||
sysDepart.setDelFlag(CommonConstant.DEL_FLAG_0.toString());
|
||||
ImportExcelUtil.importDateSaveOne(sysDepart, ISysDepartService.class, errorMessageList, num, CommonConstant.SQL_INDEX_UNIQ_DEPART_ORG_CODE);
|
||||
num++;
|
||||
}
|
||||
//清空部门缓存
|
||||
Set<String> keys3 = redisTemplate.keys(CacheConstant.SYS_DEPARTS_CACHE + "*");
|
||||
Set<String> keys4 = redisTemplate.keys(CacheConstant.SYS_DEPART_IDS_CACHE + "*");
|
||||
if(!Objects.isNull(keys3)){
|
||||
redisTemplate.delete(keys3);
|
||||
}
|
||||
if(!Objects.isNull(keys4)){
|
||||
redisTemplate.delete(keys4);
|
||||
}
|
||||
return ImportExcelUtil.imporReturnRes(errorMessageList.size(), listSysDeparts.size() - errorMessageList.size(), errorMessageList);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(),e);
|
||||
return Results.error("导入失败,请联系管理员");
|
||||
} finally {
|
||||
try {
|
||||
file.getInputStream().close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return Results.error("文件导入失败!");
|
||||
}
|
||||
|
||||
private void setParentId(SysDepart sysDepart, QueryWrapper<SysDepart> queryWrapper) {
|
||||
try {
|
||||
SysDepart parentDept = sysDepartService.getOne(queryWrapper);
|
||||
if(parentDept != null) {
|
||||
sysDepart.setParentId(parentDept.getId());
|
||||
} else {
|
||||
sysDepart.setParentId("");
|
||||
}
|
||||
}catch (Exception e) {
|
||||
//没有查找到parentDept
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询所有部门信息
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("listAll")
|
||||
public Results<List<SysDepart>> listAll(@RequestParam(name = "id", required = false) String id) {
|
||||
LambdaQueryWrapper<SysDepart> query = new LambdaQueryWrapper<>();
|
||||
query.orderByAsc(SysDepart::getOrgCode);
|
||||
if(oConvertUtils.isNotEmpty(id)){
|
||||
String[] arr = id.split(",");
|
||||
query.in(SysDepart::getId,Arrays.asList(arr));
|
||||
}
|
||||
List<SysDepart> ls = this.sysDepartService.list(query);
|
||||
return Results.OK(ls);
|
||||
}
|
||||
/**
|
||||
* 查询数据 查出所有部门,并以树结构数据格式响应给前端
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/queryTreeByKeyWord")
|
||||
public Results<Map<String,Object>> queryTreeByKeyWord(@RequestParam(name = "keyWord", required = false) String keyWord) {
|
||||
Results<Map<String,Object>> result = new Results<>();
|
||||
try {
|
||||
Map<String,Object> map=new HashMap<>();
|
||||
List<SysDepartTreeModel> list = sysDepartService.queryTreeByKeyWord(keyWord);
|
||||
//根据keyWord获取用户信息
|
||||
LambdaQueryWrapper<SysUser> queryUser = new LambdaQueryWrapper<>();
|
||||
queryUser.eq(SysUser::getDelFlag,CommonConstant.DEL_FLAG_0);
|
||||
queryUser.and(i -> i.like(SysUser::getUsername, keyWord).or().like(SysUser::getRealname, keyWord));
|
||||
List<SysUser> sysUsers = this.sysUserService.list(queryUser);
|
||||
map.put("userList",sysUsers);
|
||||
map.put("departList",list);
|
||||
result.setResult(map);
|
||||
result.setSuccess(true);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(),e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据部门编码获取部门信息
|
||||
*
|
||||
* @param orgCode
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getDepartName")
|
||||
public Results<SysDepart> getDepartName(@RequestParam(name = "orgCode") String orgCode) {
|
||||
Results<SysDepart> result = new Results<>();
|
||||
LambdaQueryWrapper<SysDepart> query = new LambdaQueryWrapper<>();
|
||||
query.eq(SysDepart::getOrgCode, orgCode);
|
||||
SysDepart sysDepart = sysDepartService.getOne(query);
|
||||
result.setSuccess(true);
|
||||
result.setResult(sysDepart);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据部门id获取用户信息
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getUsersByDepartId")
|
||||
public Results<List<SysUser>> getUsersByDepartId(@RequestParam(name = "id") String id) {
|
||||
Results<List<SysUser>> result = new Results<>();
|
||||
List<SysUser> sysUsers = sysUserDepartService.queryUserByDepId(id);
|
||||
result.setSuccess(true);
|
||||
result.setResult(sysUsers);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据部门id查询部门所有的父级(不包含自己)
|
||||
* @author 马志朝
|
||||
* @date 2021/3/24 8:50
|
||||
* @param departId 部门id
|
||||
*/
|
||||
@GetMapping("/listParentDepartsByDepId")
|
||||
List<SysDepartTreeModel> listParentDepartsByDepId(@RequestParam("departId") String departId){
|
||||
return sysDepartService.listParentDepartsByDepId(departId);
|
||||
}
|
||||
/**
|
||||
* 根据部门id查询部门所有的子级(不包含自己)
|
||||
* @author 马志朝
|
||||
* @date 2021/3/24 8:54
|
||||
* @param departId 部门id
|
||||
*/
|
||||
@GetMapping("/listSonDepartsByDepId")
|
||||
List<SysDepartTreeModel> listSonDepartsByDepId(@RequestParam("departId") String departId){
|
||||
return sysDepartService.listSonDepartsByDepId(departId);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+247
@@ -0,0 +1,247 @@
|
||||
package com.jero.modules.system.controller;
|
||||
|
||||
import java.util.*;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.jero.common.api.vo.Results;
|
||||
import com.jero.common.constant.CommonConstant;
|
||||
import com.jero.common.system.base.controller.JeroController;
|
||||
import com.jero.common.system.query.QueryGenerator;
|
||||
import com.jero.common.util.oConvertUtils;
|
||||
import com.jero.modules.system.entity.SysDepartPermission;
|
||||
import com.jero.modules.system.entity.SysPermission;
|
||||
import com.jero.modules.system.entity.SysPermissionDataRule;
|
||||
import com.jero.modules.system.model.TreeModel;
|
||||
import com.jero.modules.system.service.ISysDepartPermissionService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import com.jero.modules.system.service.ISysPermissionDataRuleService;
|
||||
import com.jero.modules.system.service.ISysPermissionService;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.poi.ss.formula.functions.T;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
|
||||
/**
|
||||
* @Description: 部门权限表
|
||||
* @Author: jero-boot
|
||||
* @Date: 2020-02-11
|
||||
* @Version: V1.0
|
||||
*/
|
||||
@Slf4j
|
||||
@Api(tags="部门权限表")
|
||||
@RestController
|
||||
@RequestMapping("/sys/sysDepartPermission")
|
||||
public class SysDepartPermissionController extends JeroController<SysDepartPermission, ISysDepartPermissionService> {
|
||||
@Autowired
|
||||
private ISysDepartPermissionService sysDepartPermissionService;
|
||||
|
||||
@Autowired
|
||||
private ISysPermissionDataRuleService sysPermissionDataRuleService;
|
||||
|
||||
@Autowired
|
||||
private ISysPermissionService sysPermissionService;
|
||||
|
||||
/**
|
||||
* 分页列表查询
|
||||
*
|
||||
* @param sysDepartPermission
|
||||
* @param pageNo
|
||||
* @param pageSize
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value="部门权限表-分页列表查询", notes="部门权限表-分页列表查询")
|
||||
@GetMapping(value = "/page")
|
||||
public Results<IPage<SysDepartPermission>> queryPageList(SysDepartPermission sysDepartPermission,
|
||||
@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
|
||||
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
|
||||
HttpServletRequest req) {
|
||||
QueryWrapper<SysDepartPermission> queryWrapper = QueryGenerator.initQueryWrapper(sysDepartPermission, req.getParameterMap());
|
||||
Page<SysDepartPermission> page = new Page<>(pageNo, pageSize);
|
||||
IPage<SysDepartPermission> pageList = sysDepartPermissionService.page(page, queryWrapper);
|
||||
return Results.OK(pageList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*
|
||||
* @param sysDepartPermission
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value="部门权限表-添加", notes="部门权限表-添加")
|
||||
@PostMapping(value = "/add")
|
||||
public Results<T> add(@RequestBody SysDepartPermission sysDepartPermission) {
|
||||
sysDepartPermissionService.save(sysDepartPermission);
|
||||
return Results.OK("操作成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*
|
||||
* @param sysDepartPermission
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value="部门权限表-编辑", notes="部门权限表-编辑")
|
||||
@PostMapping(value = "/edit")
|
||||
public Results<T> edit(@RequestBody SysDepartPermission sysDepartPermission) {
|
||||
sysDepartPermissionService.updateById(sysDepartPermission);
|
||||
return Results.OK("操作成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id删除
|
||||
*
|
||||
* @param map
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value="部门权限表-通过id删除", notes="部门权限表-通过id删除")
|
||||
@PostMapping(value = "/delete")
|
||||
public Results<T> delete(@RequestBody Map<String, String> map) {
|
||||
String id = map.get("id");
|
||||
if(StringUtils.isBlank(id)){
|
||||
return Results.error("参数不识别!");
|
||||
}
|
||||
sysDepartPermissionService.removeById(id);
|
||||
return Results.OK("删除成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
*
|
||||
* @param map
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value="部门权限表-批量删除", notes="部门权限表-批量删除")
|
||||
@PostMapping(value = "/deleteBatch")
|
||||
public Results<T> deleteBatch(@RequestBody Map<String, String> map) {
|
||||
String ids = map.get("ids");
|
||||
if(StringUtils.isBlank(ids)){
|
||||
return Results.error("参数不识别!");
|
||||
}
|
||||
this.sysDepartPermissionService.removeByIds(Arrays.asList(ids.split(",")));
|
||||
return Results.OK("批量删除成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id查询
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value="部门权限表-通过id查询", notes="部门权限表-通过id查询")
|
||||
@GetMapping(value = "/queryById")
|
||||
public Results<SysDepartPermission> queryById(@RequestParam(name="id",required=true) String id) {
|
||||
SysDepartPermission sysDepartPermission = sysDepartPermissionService.getById(id);
|
||||
return Results.OK(sysDepartPermission);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出excel
|
||||
*
|
||||
* @param request
|
||||
* @param sysDepartPermission
|
||||
*/
|
||||
@RequestMapping(value = "/exportXls")
|
||||
public ModelAndView exportXls(HttpServletRequest request, SysDepartPermission sysDepartPermission) {
|
||||
return super.exportXls(request, sysDepartPermission, SysDepartPermission.class, "部门权限表");
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过excel导入数据
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/importExcel")
|
||||
public Results<SysDepartPermission> importExcel(HttpServletRequest request, HttpServletResponse response) {
|
||||
return super.importExcel(request, response, SysDepartPermission.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 部门管理授权查询数据规则数据
|
||||
*/
|
||||
@GetMapping(value = "/datarule/{permissionId}/{departId}")
|
||||
public Results<Map<String, Object>> loadDatarule(@PathVariable("permissionId") String permissionId, @PathVariable("departId") String departId) {
|
||||
List<SysPermissionDataRule> list = sysPermissionDataRuleService.getPermRuleListByPermId(permissionId);
|
||||
if(list==null || list.isEmpty()) {
|
||||
return Results.error("未找到权限配置信息");
|
||||
}else {
|
||||
Map<String,Object> map = new HashMap<>();
|
||||
map.put("datarule", list);
|
||||
LambdaQueryWrapper<SysDepartPermission> query = new LambdaQueryWrapper<SysDepartPermission>()
|
||||
.eq(SysDepartPermission::getPermissionId, permissionId)
|
||||
.eq(SysDepartPermission::getDepartId,departId);
|
||||
SysDepartPermission sysDepartPermission = sysDepartPermissionService.getOne(query);
|
||||
if(sysDepartPermission!=null) {
|
||||
String drChecked = sysDepartPermission.getDataRuleIds();
|
||||
if(oConvertUtils.isNotEmpty(drChecked)) {
|
||||
map.put("drChecked", drChecked.endsWith(",")?drChecked.substring(0, drChecked.length()-1):drChecked);
|
||||
}
|
||||
}
|
||||
return Results.OK(map);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户角色授权功能,查询菜单权限树
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
// @RequestMapping(value = "/queryTreeListForDeptRole", method = RequestMethod.GET)
|
||||
@GetMapping("/queryTreeListForDeptRole")
|
||||
public Results<Map<String,Object>> queryTreeListForDeptRole(@RequestParam(name="departId",required=true) String departId, HttpServletRequest request) {
|
||||
Results<Map<String,Object>> result = new Results<>();
|
||||
//全部权限ids
|
||||
List<String> ids = new ArrayList<>();
|
||||
try {
|
||||
LambdaQueryWrapper<SysPermission> query = new LambdaQueryWrapper<>();
|
||||
query.eq(SysPermission::getDelFlag, CommonConstant.DEL_FLAG_0);
|
||||
query.orderByAsc(SysPermission::getSortNo);
|
||||
query.inSql(SysPermission::getId,"select permission_id from sys_depart_permission where depart_id='"+departId+"'");
|
||||
List<SysPermission> list = sysPermissionService.list(query);
|
||||
for(SysPermission sysPer : list) {
|
||||
ids.add(sysPer.getId());
|
||||
}
|
||||
List<TreeModel> treeList = new ArrayList<>();
|
||||
getTreeModelList(treeList, list, null);
|
||||
Map<String,Object> resMap = new HashMap<>();
|
||||
resMap.put("treeList", treeList); //全部树节点数据
|
||||
resMap.put("ids", ids);//全部树ids
|
||||
result.setResult(resMap);
|
||||
result.setSuccess(true);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void getTreeModelList(List<TreeModel> treeList, List<SysPermission> metaList, TreeModel temp) {
|
||||
for (SysPermission permission : metaList) {
|
||||
String tempPid = permission.getParentId();
|
||||
TreeModel tree = new TreeModel(permission.getId(), tempPid, permission.getName(),permission.getRuleFlag(), permission.isLeaf());
|
||||
if(temp==null && oConvertUtils.isEmpty(tempPid)) {
|
||||
treeList.add(tree);
|
||||
if(!tree.getIsLeaf()) {
|
||||
getTreeModelList(treeList, metaList, tree);
|
||||
}
|
||||
}else if(temp!=null && tempPid!=null && tempPid.equals(temp.getKey())){
|
||||
temp.getChildren().add(tree);
|
||||
if(!tree.getIsLeaf()) {
|
||||
getTreeModelList(treeList, metaList, tree);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+583
@@ -0,0 +1,583 @@
|
||||
package com.jero.modules.system.controller;
|
||||
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.jero.common.api.vo.Results;
|
||||
import com.jero.common.constant.CacheConstant;
|
||||
import com.jero.common.constant.CommonConstant;
|
||||
import com.jero.common.exception.JeroBootException;
|
||||
import com.jero.common.system.base.controller.JeroController;
|
||||
import com.jero.common.system.query.QueryGenerator;
|
||||
import com.jero.common.system.vo.DictModel;
|
||||
import com.jero.common.system.vo.LoginUser;
|
||||
import com.jero.common.util.ImportExcelUtil;
|
||||
import com.jero.common.util.SpringContextUtils;
|
||||
import com.jero.common.util.SqlInjectionUtil;
|
||||
import com.jero.common.util.oConvertUtils;
|
||||
import com.jero.config.easypoi.EasyPoiDictHandlerImpl;
|
||||
import com.jero.modules.system.entity.SuccessAndErrorLines;
|
||||
import com.jero.modules.system.entity.SysDict;
|
||||
import com.jero.modules.system.entity.SysDictItem;
|
||||
import com.jero.modules.system.model.SysDictTree;
|
||||
import com.jero.modules.system.model.TreeSelectModel;
|
||||
import com.jero.modules.system.service.ISysDictItemService;
|
||||
import com.jero.modules.system.service.ISysDictService;
|
||||
import com.jero.modules.system.vo.SysDictPage;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.poi.ss.formula.functions.T;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import cn.afterturn.easypoi.excel.ExcelImportUtil;
|
||||
import cn.afterturn.easypoi.entity.vo.NormalExcelConstants;
|
||||
import cn.afterturn.easypoi.excel.entity.ExportParams;
|
||||
import cn.afterturn.easypoi.excel.entity.ImportParams;
|
||||
import cn.afterturn.easypoi.view.EasypoiSingleExcelView;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 字典表 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @Author zhangweijian
|
||||
* @since 2018-12-28
|
||||
*/
|
||||
@RestController
|
||||
@Api(tags = "字典控制器")
|
||||
@RequestMapping("/sys/dict")
|
||||
@Slf4j
|
||||
public class SysDictController {
|
||||
|
||||
@Autowired
|
||||
private ISysDictService sysDictService;
|
||||
@Autowired
|
||||
private ISysDictItemService sysDictItemService;
|
||||
@Autowired
|
||||
public RedisTemplate<String, Object> redisTemplate;
|
||||
|
||||
private static final String DICT_CODE_ERROE = "字典Code格式不正确!";
|
||||
private static final String OPTION_SUCCESS = "操作成功!";
|
||||
private static final String DEL_SUCCESS = "删除成功!";
|
||||
|
||||
@GetMapping("/page")
|
||||
@ApiOperation(value = "字典控制器-分页列表查询", notes = "字典控制器-分页列表查询")
|
||||
public Results<IPage<SysDict>> queryPageList(SysDict sysDict, @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
|
||||
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize, HttpServletRequest req) {
|
||||
Results<IPage<SysDict>> result = new Results<>();
|
||||
QueryWrapper<SysDict> queryWrapper = QueryGenerator.initQueryWrapper(sysDict, req.getParameterMap());
|
||||
Page<SysDict> page = new Page<>(pageNo, pageSize);
|
||||
IPage<SysDict> pageList = sysDictService.page(page, queryWrapper);
|
||||
log.debug("查询当前页:"+pageList.getCurrent());
|
||||
log.debug("查询当前页数量:"+pageList.getSize());
|
||||
log.debug("查询结果数量:"+pageList.getRecords().size());
|
||||
log.debug("数据总数:"+pageList.getTotal());
|
||||
result.setSuccess(true);
|
||||
result.setResult(pageList);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @功能:获取树形字典数据
|
||||
* @param sysDict
|
||||
* @param pageNo
|
||||
* @param pageSize
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "字典控制器-树形字典数据", notes = "字典控制器-树形字典数据")
|
||||
@GetMapping("/treeList")
|
||||
public Results<List<SysDictTree>> treeList(SysDict sysDict, @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
|
||||
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize, HttpServletRequest req) {
|
||||
Results<List<SysDictTree>> result = new Results<>();
|
||||
LambdaQueryWrapper<SysDict> query = new LambdaQueryWrapper<>();
|
||||
// 构造查询条件
|
||||
String dictName = sysDict.getDictName();
|
||||
if(oConvertUtils.isNotEmpty(dictName)) {
|
||||
query.like(true, SysDict::getDictName, dictName);
|
||||
}
|
||||
query.orderByDesc(true, SysDict::getCreateTime);
|
||||
List<SysDict> list = sysDictService.list(query);
|
||||
List<SysDictTree> treeList = new ArrayList<>();
|
||||
for (SysDict node : list) {
|
||||
treeList.add(new SysDictTree(node));
|
||||
}
|
||||
result.setSuccess(true);
|
||||
result.setResult(treeList);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取全部字典数据
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "字典控制器-获取全部字典数据", notes = "字典控制器-获取全部字典数据")
|
||||
@GetMapping("/queryAllDictItems")
|
||||
public Results<Map<String, List<DictModel>>> queryAllDictItems(HttpServletRequest request) {
|
||||
Map<String, List<DictModel>> res ;
|
||||
res = sysDictService.queryAllDictItems();
|
||||
return Results.OK(res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取字典数据
|
||||
* @param dictCode
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "字典控制器-通过字典code和字典值key获取字典数据", notes = "字典控制器-通过字典code和字典值key获取字典数据")
|
||||
@GetMapping("/getDictText/{dictCode}/{key}")
|
||||
public Results<String> getDictText(@PathVariable("dictCode") String dictCode, @PathVariable("key") String key) {
|
||||
log.info(" dictCode : "+ dictCode);
|
||||
Results<String> result = new Results<>();
|
||||
String text = null;
|
||||
try {
|
||||
text = sysDictService.queryDictTextByKey(dictCode, key);
|
||||
result.setSuccess(true);
|
||||
result.setResult(text);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(),e);
|
||||
return Results.error("操作失败");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取字典数据 【接口签名验证】
|
||||
* @param dictCode 字典code
|
||||
* @param dictCode 表名,文本字段,code字段 | 举例:sys_user,realname,id
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getDictItems/{dictCode}")
|
||||
public Results<List<DictModel>> getDictItems(@PathVariable String dictCode, @RequestParam(value = "sign",required = false) String sign, HttpServletRequest request) {
|
||||
log.info(" dictCode : "+ dictCode);
|
||||
Results<List<DictModel>> result = new Results<>();
|
||||
try {
|
||||
List<DictModel> ls = sysDictService.getDictItems(dictCode);
|
||||
if (ls == null) {
|
||||
return Results.error(DICT_CODE_ERROE);
|
||||
}
|
||||
result.setSuccess(true);
|
||||
result.setResult(ls);
|
||||
log.debug(result.toString());
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
return Results.error("操作失败");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 【接口签名验证】
|
||||
* 【JSearchSelectTag下拉搜索组件专用接口】
|
||||
* 大数据量的字典表 走异步加载 即前端输入内容过滤数据
|
||||
* @param dictCode 字典code格式:table,text,code
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/loadDict/{dictCode}")
|
||||
public Results<List<DictModel>> loadDict(@PathVariable String dictCode,
|
||||
@RequestParam(name="keyword",required = false) String keyword,
|
||||
@RequestParam(value = "sign",required = false) String sign,
|
||||
@RequestParam(value = "pageSize", required = false) Integer pageSize) {
|
||||
log.info(" 加载字典表数据,加载关键字: "+ keyword);
|
||||
Results<List<DictModel>> result = new Results<>();
|
||||
try {
|
||||
List<DictModel> ls = sysDictService.loadDict(dictCode, keyword, pageSize);
|
||||
if (ls == null) {
|
||||
return Results.error(DICT_CODE_ERROE);
|
||||
}
|
||||
result.setSuccess(true);
|
||||
result.setResult(ls);
|
||||
log.info(result.toString());
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(),e);
|
||||
return Results.error("操作失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 【给表单设计器的表字典使用】下拉搜索模式,有值时动态拼接数据
|
||||
* @param dictCode
|
||||
* @param keyword 当前控件的值,可以逗号分割
|
||||
* @param sign
|
||||
* @param pageSize
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/loadDictOrderByValue/{dictCode}")
|
||||
public Results<List<DictModel>> loadDictOrderByValue(
|
||||
@PathVariable String dictCode,
|
||||
@RequestParam(name = "keyword",required = false) String keyword,
|
||||
@RequestParam(value = "sign", required = false) String sign,
|
||||
@RequestParam(value = "pageSize", required = false) Integer pageSize) {
|
||||
// 首次查询查出来用户选中的值,并且不分页
|
||||
Results<List<DictModel>> firstRes = this.loadDict(dictCode, keyword, sign, null);
|
||||
if (!firstRes.isSuccess()) {
|
||||
return firstRes;
|
||||
}
|
||||
// 然后再查询出第一页的数据
|
||||
Results<List<DictModel>> result = this.loadDict(dictCode, "", sign, pageSize);
|
||||
if (!result.isSuccess()) {
|
||||
return result;
|
||||
}
|
||||
// 合并两次查询的数据
|
||||
List<DictModel> firstList = firstRes.getResult();
|
||||
List<DictModel> list = result.getResult();
|
||||
for (DictModel firstItem : firstList) {
|
||||
// anyMatch 表示:判断的条件里,任意一个元素匹配成功,返回true
|
||||
// allMatch 表示:判断条件里的元素,所有的都匹配成功,返回true
|
||||
// noneMatch 跟 allMatch 相反,表示:判断条件里的元素,所有的都匹配失败,返回true
|
||||
boolean none = list.stream().noneMatch(item -> item.getValue().equals(firstItem.getValue()));
|
||||
// 当元素不存在时,再添加到集合里
|
||||
if (none) {
|
||||
list.add(0, firstItem);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*【接口签名验证】
|
||||
* 根据字典code加载字典text 返回
|
||||
* @param dictCode 顺序:tableName,text,code
|
||||
* @param keys 要查询的key
|
||||
* @param sign
|
||||
* @param delNotExist 是否移除不存在的项,默认为true,设为false如果某个key不存在数据库中,则直接返回key本身
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/loadDictItem/{dictCode}")
|
||||
public Results<List<String>> loadDictItem(@PathVariable String dictCode, @RequestParam(name="key") String keys, @RequestParam(value = "sign",required = false) String sign, @RequestParam(value = "delNotExist",required = false,defaultValue = "true") boolean delNotExist, HttpServletRequest request) {
|
||||
Results<List<String>> result = new Results<>();
|
||||
try {
|
||||
if(dictCode.indexOf(",")!=-1) {
|
||||
String[] params = dictCode.split(",");
|
||||
if(params.length!=3) {
|
||||
return Results.error(DICT_CODE_ERROE);
|
||||
}
|
||||
List<String> texts = sysDictService.queryTableDictByKeys(params[0], params[1], params[2], keys, delNotExist);
|
||||
|
||||
result.setSuccess(true);
|
||||
result.setResult(texts);
|
||||
log.info(result.toString());
|
||||
}else {
|
||||
return Results.error(DICT_CODE_ERROE);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(),e);
|
||||
return Results.error("操作失败");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 【接口签名验证】
|
||||
* 根据表名——显示字段-存储字段 pid 加载树形数据
|
||||
*/
|
||||
@ApiOperation(value = "字典控制器-根据表名—显示字段-存储字段 pid 加载树形数据", notes = "字典控制器-根据表名—显示字段-存储字段 pid 加载树形数据")
|
||||
@GetMapping("/loadTreeData")
|
||||
public Results<List<TreeSelectModel>> loadTreeData(@RequestParam(name="pid") String pid, @RequestParam(name="pidField") String pidField,
|
||||
@RequestParam(name="tableName") String tbname,
|
||||
@RequestParam(name="text") String text,
|
||||
@RequestParam(name="code") String code,
|
||||
@RequestParam(name="hasChildField", required = false) String hasChildField,
|
||||
@RequestParam(value = "sign", required = false) String sign, HttpServletRequest request) {
|
||||
Results<List<TreeSelectModel>> result = new Results<>();
|
||||
|
||||
// SQL注入漏洞 sign签名校验(表名,label字段,val字段,条件)
|
||||
String dictCode = tbname +","+ text +","+ code;
|
||||
SqlInjectionUtil.filterContent(dictCode);
|
||||
List<TreeSelectModel> ls = sysDictService.queryTreeList(null, tbname, text, code, pidField, pid, hasChildField);
|
||||
result.setSuccess(true);
|
||||
result.setResult(ls);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询后返回树型数据
|
||||
*/
|
||||
@ApiOperation(value = "字典控制器-根据表名—显示字段-存储字段 加载树形数据", notes = "字典控制器-根据表名—显示字段-存储字段 加载树形数据")
|
||||
@GetMapping("/queryAllTreeData")
|
||||
public Results<List<TreeSelectModel>> queryAllTreeData(@RequestParam(name="pidField") String pidField,
|
||||
@RequestParam(name="tableName") String tbname,
|
||||
@RequestParam(name="text") String text,
|
||||
@RequestParam(name="code") String code,
|
||||
HttpServletRequest request) {
|
||||
Results<List<TreeSelectModel>> result = new Results<>();
|
||||
|
||||
// SQL注入漏洞 sign签名校验(表名,label字段,val字段,条件)
|
||||
String dictCode = tbname +","+ text +","+ code;
|
||||
SqlInjectionUtil.filterContent(dictCode);
|
||||
List<TreeSelectModel> ls = sysDictService.queryAllTreeData(tbname, text, code, pidField);
|
||||
result.setSuccess(true);
|
||||
result.setResult(ls);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @功能:新增
|
||||
* @param sysDict
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "字典控制器-新增字典", notes = "字典控制器-新增字典")
|
||||
@PostMapping("/add")
|
||||
@RequiresPermissions("sys:dict:operation")
|
||||
public Results<Object> add(@RequestBody SysDict sysDict) {
|
||||
try {
|
||||
sysDict.setCreateTime(new Date());
|
||||
sysDict.setDelFlag(CommonConstant.DEL_FLAG_0);
|
||||
sysDictService.save(sysDict);
|
||||
//添加成功后需要刷新缓存
|
||||
sysDictService.refreshCache();
|
||||
return Results.OK(OPTION_SUCCESS);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(),e);
|
||||
return Results.error("操作失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @功能:编辑
|
||||
* @param sysDict
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "字典控制器-编辑字典", notes = "字典控制器-编辑字典")
|
||||
@PostMapping("/edit")
|
||||
@RequiresPermissions("sys:dict:operation")
|
||||
public Results<Object> edit(@RequestBody SysDict sysDict) {
|
||||
SysDict sysdict = sysDictService.getById(sysDict.getId());
|
||||
if(sysdict==null) {
|
||||
return Results.error("未找到对应实体");
|
||||
}else {
|
||||
sysDict.setUpdateTime(new Date());
|
||||
boolean ok = sysDictService.updateById(sysDict);
|
||||
if(ok) {
|
||||
//编辑成功后需要刷新缓存
|
||||
sysDictService.refreshCache();
|
||||
return Results.OK(OPTION_SUCCESS);
|
||||
}
|
||||
}
|
||||
return Results.OK();
|
||||
}
|
||||
|
||||
/**
|
||||
* @功能:删除
|
||||
* @param map
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "字典控制器-删除字典", notes = "字典控制器-删除字典")
|
||||
@PostMapping(value = "/delete")
|
||||
@RequiresPermissions("sys:dict:operation")
|
||||
@CacheEvict(value={CacheConstant.SYS_DICT_CACHE, CacheConstant.SYS_ENABLE_DICT_CACHE}, allEntries=true)
|
||||
public Results<Object> delete(@RequestBody Map<String,String> map) {
|
||||
String id = map.get("id");
|
||||
if(StringUtils.isBlank(id)){
|
||||
return Results.error("参数不识别!");
|
||||
}
|
||||
boolean ok = sysDictService.removeById(id);
|
||||
if(ok) {
|
||||
return Results.OK(DEL_SUCCESS);
|
||||
}else{
|
||||
return Results.error("删除失败!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @功能:批量删除
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "字典控制器-批量字典", notes = "字典控制器-批量字典")
|
||||
@PostMapping(value = "/deleteBatch")
|
||||
@RequiresPermissions("sys:dict:operation")
|
||||
@CacheEvict(value= {CacheConstant.SYS_DICT_CACHE, CacheConstant.SYS_ENABLE_DICT_CACHE}, allEntries=true)
|
||||
public Results<Object> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
|
||||
if(oConvertUtils.isEmpty(ids)) {
|
||||
return Results.error("参数不识别!");
|
||||
}else {
|
||||
sysDictService.removeByIds(Arrays.asList(ids.split(",")));
|
||||
return Results.OK(DEL_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @功能:刷新缓存
|
||||
* @date 修改时间 2021.4.8
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/refleshCache")
|
||||
public Results<SysDict> refleshCache() {
|
||||
Results<SysDict> result = new Results<>();
|
||||
sysDictService.refreshCache();
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出excel
|
||||
*
|
||||
* @param request
|
||||
*/
|
||||
@RequestMapping(value = "/exportXls")
|
||||
@RequiresPermissions("sys:dict:operation")
|
||||
public ModelAndView exportXls(SysDict sysDict, HttpServletRequest request) {
|
||||
// Step.1 组装查询条件
|
||||
QueryWrapper<SysDict> queryWrapper = QueryGenerator.initQueryWrapper(sysDict, request.getParameterMap());
|
||||
//Step.2 AutoPoi 导出Excel
|
||||
ModelAndView mv = new ModelAndView(new EasypoiSingleExcelView());
|
||||
List<SysDictPage> pageList = new ArrayList<>();
|
||||
|
||||
List<SysDict> sysDictList = sysDictService.list(queryWrapper);
|
||||
for (SysDict dictMain : sysDictList) {
|
||||
SysDictPage vo = new SysDictPage();
|
||||
BeanUtils.copyProperties(dictMain, vo);
|
||||
// 查询子列表
|
||||
List<SysDictItem> sysDictItemList = sysDictItemService.selectItemsByMainId(dictMain.getId());
|
||||
vo.setSysDictItemList(sysDictItemList);
|
||||
pageList.add(vo);
|
||||
}
|
||||
|
||||
// 导出文件名称
|
||||
mv.addObject(JeroController.FILE_NAME, "数据字典");
|
||||
// 注解对象Class
|
||||
mv.addObject(JeroController.CLASS, SysDictPage.class);
|
||||
// 自定义表格参数
|
||||
LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
||||
ExportParams exportParams = new ExportParams("数据字典列表", "导出人:"+user.getRealname(), "数据字典");
|
||||
exportParams.setDictHandler(SpringContextUtils.getApplicationContext().getBean(EasyPoiDictHandlerImpl.class));
|
||||
mv.addObject(JeroController.PARAMS, exportParams);
|
||||
// 导出数据列表
|
||||
mv.addObject(NormalExcelConstants.DATA_LIST, pageList);
|
||||
return mv;
|
||||
}
|
||||
|
||||
|
||||
@PostMapping(value = "/importExcel")
|
||||
@RequiresPermissions("sys:dict:operation")
|
||||
public Results<JSONObject> importExcel(HttpServletRequest request, HttpServletResponse response) {
|
||||
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
||||
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
|
||||
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
|
||||
MultipartFile file = entity.getValue();// 获取上传文件对象
|
||||
ImportParams params = new ImportParams();
|
||||
params.setDictHandler(SpringContextUtils.getApplicationContext().getBean(EasyPoiDictHandlerImpl.class));
|
||||
params.setTitleRows(2);
|
||||
params.setHeadRows(2);
|
||||
params.setNeedSave(true);
|
||||
try {
|
||||
List<SysDictPage> list = ExcelImportUtil.importExcel(file.getInputStream(), SysDictPage.class, params);
|
||||
// 错误信息
|
||||
List<String> errorMessage = new ArrayList<>();
|
||||
int successLines = 0;
|
||||
int errorLines = 0;
|
||||
for (int i=0;i< list.size();i++) {
|
||||
SysDict po = new SysDict();
|
||||
BeanUtils.copyProperties(list.get(i), po);
|
||||
po.setDelFlag(CommonConstant.DEL_FLAG_0);
|
||||
SuccessAndErrorLines successAndErrorLines = getSuccessAndErrorLines(list, errorMessage, successLines, errorLines, i, po);
|
||||
successLines = successAndErrorLines.getSuccessLines();
|
||||
errorLines = successAndErrorLines.getErrorLines();
|
||||
}
|
||||
return ImportExcelUtil.imporReturnRes(errorLines,successLines,errorMessage);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(),e);
|
||||
return Results.error("文件导入失败:"+e.getMessage());
|
||||
} finally {
|
||||
fileClose(file);
|
||||
}
|
||||
}
|
||||
return Results.error("文件导入失败!");
|
||||
}
|
||||
|
||||
private SuccessAndErrorLines getSuccessAndErrorLines(List<SysDictPage> list, List<String> errorMessage, int successLines, int errorLines, int i, SysDict po) {
|
||||
SuccessAndErrorLines successAndErrorLines = new SuccessAndErrorLines();
|
||||
successAndErrorLines.setSuccessLines(successLines);
|
||||
successAndErrorLines.setErrorLines(errorLines);
|
||||
try {
|
||||
Integer integer = sysDictService.saveMain(po, list.get(i).getSysDictItemList());
|
||||
if(integer>0){
|
||||
successAndErrorLines.setSuccessLines(successLines + 1);
|
||||
}else{
|
||||
successAndErrorLines.setErrorLines(errorLines + 1);
|
||||
int lineNumber = i + 1;
|
||||
errorMessage.add("第 " + lineNumber + " 行:字典编码已经存在,忽略导入。");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
successAndErrorLines.setErrorLines(errorLines + 1);
|
||||
int lineNumber = i + 1;
|
||||
errorMessage.add("第 " + lineNumber + " 行:字典编码已经存在,忽略导入。");
|
||||
}
|
||||
return successAndErrorLines;
|
||||
}
|
||||
|
||||
private void fileClose(MultipartFile file) {
|
||||
try {
|
||||
file.getInputStream().close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询被删除的列表
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/deleteList")
|
||||
public Results<List<SysDict>> deleteList() {
|
||||
List<SysDict> list = this.sysDictService.queryDeleteList();
|
||||
return Results.OK(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 物理删除
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/deletePhysic/{id}")
|
||||
@RequiresPermissions("sys:dict:operation")
|
||||
public Results<T> deletePhysic(@PathVariable String id) {
|
||||
try {
|
||||
sysDictService.deleteOneDictPhysically(id);
|
||||
return Results.OK(DEL_SUCCESS);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return Results.error("删除失败!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 逻辑删除的字段,进行取回
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/back/{id}")
|
||||
@RequiresPermissions("sys:dict:operation")
|
||||
public Results<T> back(@PathVariable String id) {
|
||||
try {
|
||||
sysDictService.updateDictDelFlag(0,id);
|
||||
return Results.OK(OPTION_SUCCESS);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return Results.error("操作失败!");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+177
@@ -0,0 +1,177 @@
|
||||
package com.jero.modules.system.controller;
|
||||
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.jero.common.api.vo.Results;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.poi.ss.formula.functions.T;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import com.jero.common.constant.CacheConstant;
|
||||
import com.jero.common.system.query.QueryGenerator;
|
||||
import com.jero.modules.system.entity.SysDictItem;
|
||||
import com.jero.modules.system.service.ISysDictItemService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @Author zhangweijian
|
||||
* @since 2018-12-28
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/sys/dictItem")
|
||||
@Slf4j
|
||||
public class SysDictItemController {
|
||||
|
||||
@Autowired
|
||||
private ISysDictItemService sysDictItemService;
|
||||
|
||||
/**
|
||||
* @功能:查询字典数据
|
||||
* @param sysDictItem
|
||||
* @param pageNo
|
||||
* @param pageSize
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/page")
|
||||
public Results<IPage<SysDictItem>> queryPageList(SysDictItem sysDictItem, @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
|
||||
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize, HttpServletRequest req) {
|
||||
Results<IPage<SysDictItem>> result = new Results<>();
|
||||
QueryWrapper<SysDictItem> queryWrapper = QueryGenerator.initQueryWrapper(sysDictItem, req.getParameterMap());
|
||||
queryWrapper.orderByAsc("sort_order");
|
||||
Page<SysDictItem> page = new Page<>(pageNo, pageSize);
|
||||
IPage<SysDictItem> pageList = sysDictItemService.page(page, queryWrapper);
|
||||
result.setSuccess(true);
|
||||
result.setResult(pageList);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @功能:新增
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/add")
|
||||
@RequiresPermissions("sys:dict:operation")
|
||||
@CacheEvict(value= {CacheConstant.SYS_DICT_CACHE, CacheConstant.SYS_ENABLE_DICT_CACHE}, allEntries=true)
|
||||
public Results<Object> add(@RequestBody SysDictItem sysDictItem) {
|
||||
try {
|
||||
sysDictItem.setCreateTime(new Date());
|
||||
sysDictItemService.save(sysDictItem);
|
||||
return Results.OK("操作成功!");
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(),e);
|
||||
return Results.error("操作失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @功能:编辑
|
||||
* @param sysDictItem
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/edit")
|
||||
@RequiresPermissions("sys:dict:operation")
|
||||
@CacheEvict(value={CacheConstant.SYS_DICT_CACHE, CacheConstant.SYS_ENABLE_DICT_CACHE}, allEntries=true)
|
||||
public Results<Object> edit(@RequestBody SysDictItem sysDictItem) {
|
||||
SysDictItem sysdict = sysDictItemService.getById(sysDictItem.getId());
|
||||
if(sysdict==null) {
|
||||
return Results.error("未找到对应实体");
|
||||
}else {
|
||||
sysDictItem.setUpdateTime(new Date());
|
||||
boolean ok = sysDictItemService.updateById(sysDictItem);
|
||||
if(ok) {
|
||||
return Results.OK("操作成功!");
|
||||
}
|
||||
}
|
||||
return Results.OK();
|
||||
}
|
||||
|
||||
/**
|
||||
* @功能:删除字典数据
|
||||
* @param map
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/delete")
|
||||
@RequiresPermissions("sys:dict:operation")
|
||||
@CacheEvict(value={CacheConstant.SYS_DICT_CACHE, CacheConstant.SYS_ENABLE_DICT_CACHE}, allEntries=true)
|
||||
public Results<T> delete(@RequestBody Map<String, String> map) {
|
||||
String id = map.get("id");
|
||||
if(StringUtils.isBlank(id)){
|
||||
return Results.error("参数不识别!");
|
||||
}
|
||||
SysDictItem joinSystem = sysDictItemService.getById(id);
|
||||
if(joinSystem==null) {
|
||||
return Results.error("未找到对应实体");
|
||||
}else {
|
||||
boolean ok = sysDictItemService.removeById(id);
|
||||
if(ok) {
|
||||
return Results.OK("删除成功!");
|
||||
}
|
||||
}
|
||||
return Results.OK();
|
||||
}
|
||||
|
||||
/**
|
||||
* @功能:批量删除字典数据
|
||||
* @param map
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/deleteBatch")
|
||||
@RequiresPermissions("sys:dict:operation")
|
||||
@CacheEvict(value={CacheConstant.SYS_DICT_CACHE, CacheConstant.SYS_ENABLE_DICT_CACHE}, allEntries=true)
|
||||
public Results<Object> deleteBatch(@RequestBody Map<String, String> map) {
|
||||
String ids = map.get("ids");
|
||||
if(ids==null || "".equals(ids.trim())) {
|
||||
return Results.error("参数不识别!");
|
||||
}else {
|
||||
this.sysDictItemService.removeByIds(Arrays.asList(ids.split(",")));
|
||||
return Results.OK("删除成功!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 字典值重复校验
|
||||
* @param sysDictItem
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/dictItemCheck")
|
||||
public Results<Object> doDictItemCheck(SysDictItem sysDictItem, HttpServletRequest request) {
|
||||
int num = 0;
|
||||
LambdaQueryWrapper<SysDictItem> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(SysDictItem::getItemValue,sysDictItem.getItemValue());
|
||||
queryWrapper.eq(SysDictItem::getDictId,sysDictItem.getDictId());
|
||||
if (StringUtils.isNotBlank(sysDictItem.getId())) {
|
||||
// 编辑页面校验
|
||||
queryWrapper.ne(SysDictItem::getId,sysDictItem.getId());
|
||||
}
|
||||
num = sysDictItemService.count(queryWrapper);
|
||||
if (num == 0) {
|
||||
// 该值可用
|
||||
return Results.OK("该值可用!");
|
||||
} else {
|
||||
// 该值不可用
|
||||
log.info("该值不可用,系统中已存在!");
|
||||
return Results.error("该值不可用,系统中已存在!");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+225
@@ -0,0 +1,225 @@
|
||||
package com.jero.modules.system.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.jero.common.api.vo.Results;
|
||||
import com.jero.common.aspect.annotation.AutoLog;
|
||||
import com.jero.common.system.base.controller.JeroController;
|
||||
import com.jero.common.system.query.QueryGenerator;
|
||||
import com.jero.common.util.FillRuleUtil;
|
||||
import com.jero.modules.system.entity.SysFillRule;
|
||||
import com.jero.modules.system.service.ISysFillRuleService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.poi.ss.formula.functions.T;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Description: 填值规则
|
||||
* @Author: jero-boot
|
||||
* @Date: 2019-11-07
|
||||
* @Version: V1.0
|
||||
*/
|
||||
@Slf4j
|
||||
@Api(tags = "填值规则")
|
||||
@RestController
|
||||
@RequestMapping("/sys/fillRule")
|
||||
public class SysFillRuleController extends JeroController<SysFillRule, ISysFillRuleService> {
|
||||
@Autowired
|
||||
private ISysFillRuleService sysFillRuleService;
|
||||
|
||||
/**
|
||||
* 分页列表查询
|
||||
*
|
||||
* @param sysFillRule
|
||||
* @param pageNo
|
||||
* @param pageSize
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "填值规则-分页列表查询")
|
||||
@ApiOperation(value = "填值规则-分页列表查询", notes = "填值规则-分页列表查询")
|
||||
@GetMapping(value = "/page")
|
||||
public Results<IPage<SysFillRule>> queryPageList(SysFillRule sysFillRule,
|
||||
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
|
||||
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
|
||||
HttpServletRequest req) {
|
||||
QueryWrapper<SysFillRule> queryWrapper = QueryGenerator.initQueryWrapper(sysFillRule, req.getParameterMap());
|
||||
Page<SysFillRule> page = new Page<>(pageNo, pageSize);
|
||||
IPage<SysFillRule> pageList = sysFillRuleService.page(page, queryWrapper);
|
||||
return Results.OK(pageList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试 ruleCode
|
||||
*
|
||||
* @param ruleCode
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/testFillRule")
|
||||
public Results<Object> testFillRule(@RequestParam("ruleCode") String ruleCode) {
|
||||
Object result = FillRuleUtil.executeRule(ruleCode, new JSONObject());
|
||||
return Results.OK(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*
|
||||
* @param sysFillRule
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "填值规则-添加")
|
||||
@ApiOperation(value = "填值规则-添加", notes = "填值规则-添加")
|
||||
@PostMapping(value = "/add")
|
||||
public Results<T> add(@RequestBody SysFillRule sysFillRule) {
|
||||
sysFillRuleService.save(sysFillRule);
|
||||
return Results.OK("操作成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*
|
||||
* @param sysFillRule
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "填值规则-编辑")
|
||||
@ApiOperation(value = "填值规则-编辑", notes = "填值规则-编辑")
|
||||
@PostMapping(value = "/edit")
|
||||
public Results<T> edit(@RequestBody SysFillRule sysFillRule) {
|
||||
sysFillRuleService.updateById(sysFillRule);
|
||||
return Results.OK("操作成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id删除
|
||||
*
|
||||
* @param map
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "填值规则-通过id删除")
|
||||
@ApiOperation(value = "填值规则-通过id删除", notes = "填值规则-通过id删除")
|
||||
@PostMapping(value = "/delete")
|
||||
public Results<T> delete(@RequestBody Map<String, String> map) {
|
||||
String id = map.get("id");
|
||||
if(StringUtils.isBlank(id)){
|
||||
return Results.error("参数不识别!");
|
||||
}
|
||||
sysFillRuleService.removeById(id);
|
||||
return Results.OK("删除成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
*
|
||||
* @param map
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "填值规则-批量删除")
|
||||
@ApiOperation(value = "填值规则-批量删除", notes = "填值规则-批量删除")
|
||||
@PostMapping(value = "/deleteBatch")
|
||||
public Results<T> deleteBatch(@RequestBody Map<String, String> map) {
|
||||
String ids = map.get("ids");
|
||||
if(StringUtils.isBlank(ids)){
|
||||
return Results.error("参数不识别!");
|
||||
}
|
||||
this.sysFillRuleService.removeByIds(Arrays.asList(ids.split(",")));
|
||||
return Results.OK("批量删除成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id查询
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "填值规则-通过id查询")
|
||||
@ApiOperation(value = "填值规则-通过id查询", notes = "填值规则-通过id查询")
|
||||
@GetMapping(value = "/queryById")
|
||||
public Results<SysFillRule> queryById(@RequestParam(name = "id", required = true) String id) {
|
||||
SysFillRule sysFillRule = sysFillRuleService.getById(id);
|
||||
return Results.OK(sysFillRule);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出excel
|
||||
*
|
||||
* @param request
|
||||
* @param sysFillRule
|
||||
*/
|
||||
@RequestMapping(value = "/exportXls")
|
||||
public ModelAndView exportXls(HttpServletRequest request, SysFillRule sysFillRule) {
|
||||
return super.exportXls(request, sysFillRule, SysFillRule.class, "填值规则");
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过excel导入数据
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
* @return
|
||||
*/
|
||||
// @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
|
||||
@PostMapping("/importExcel")
|
||||
public Results<SysFillRule> importExcel(HttpServletRequest request, HttpServletResponse response) {
|
||||
return super.importExcel(request, response, SysFillRule.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过 ruleCode 执行自定义填值规则
|
||||
*
|
||||
* @param ruleCode 要执行的填值规则编码
|
||||
* @param formData 表单数据,可根据表单数据的不同生成不同的填值结果
|
||||
* @return 运行后的结果
|
||||
*/
|
||||
@PostMapping("/executeRuleByCode/{ruleCode}")
|
||||
public Results<Object> executeByRuleCode(@PathVariable("ruleCode") String ruleCode, @RequestBody JSONObject formData) {
|
||||
Object result = FillRuleUtil.executeRule(ruleCode, formData);
|
||||
return Results.OK(result);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 批量通过 ruleCode 执行自定义填值规则
|
||||
*
|
||||
* @param ruleData 要执行的填值规则JSON数组:
|
||||
* 示例: { "commonFormData": {}, rules: [ { "ruleCode": "xxx", "formData": null } ] }
|
||||
* @return 运行后的结果,返回示例: [{"ruleCode": "order_num_rule", "result": "CN2019111117212984"}]
|
||||
*
|
||||
*/
|
||||
@PostMapping("/executeRuleByCodeBatch")
|
||||
public Results<JSONArray> executeByRuleCodeBatch(@RequestBody JSONObject ruleData) {
|
||||
JSONObject commonFormData = ruleData.getJSONObject("commonFormData");
|
||||
JSONArray rules = ruleData.getJSONArray("rules");
|
||||
// 遍历 rules ,批量执行规则
|
||||
JSONArray results = new JSONArray(rules.size());
|
||||
for (int i = 0; i < rules.size(); i++) {
|
||||
JSONObject rule = rules.getJSONObject(i);
|
||||
String ruleCode = rule.getString("ruleCode");
|
||||
JSONObject formData = rule.getJSONObject("formData");
|
||||
// 如果没有传递 formData,就用common的
|
||||
if (formData == null) {
|
||||
formData = commonFormData;
|
||||
}
|
||||
// 执行填值规则
|
||||
Object result = FillRuleUtil.executeRule(ruleCode, formData);
|
||||
JSONObject obj = new JSONObject(rules.size());
|
||||
obj.put("ruleCode", ruleCode);
|
||||
obj.put("result", result);
|
||||
results.add(obj);
|
||||
}
|
||||
return Results.OK(results);
|
||||
}
|
||||
|
||||
}
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
package com.jero.modules.system.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.jero.common.api.vo.Results;
|
||||
import com.jero.common.system.base.controller.JeroController;
|
||||
import com.jero.common.util.oConvertUtils;
|
||||
import com.jero.modules.system.entity.SysGatewayRoute;
|
||||
import com.jero.modules.system.service.ISysGatewayRouteService;
|
||||
import io.swagger.annotations.Api;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.poi.ss.formula.functions.T;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Description: gateway路由管理
|
||||
* @Author: jero-boot
|
||||
* @Date: 2020-05-26
|
||||
* @Version: V1.0
|
||||
*/
|
||||
@Api(tags = "gateway路由管理")
|
||||
@RestController
|
||||
@RequestMapping("/sys/gatewayRoute")
|
||||
@Slf4j
|
||||
public class SysGatewayRouteController extends JeroController<SysGatewayRoute, ISysGatewayRouteService> {
|
||||
|
||||
@Autowired
|
||||
private ISysGatewayRouteService sysGatewayRouteService;
|
||||
|
||||
@PostMapping(value = "/updateAll")
|
||||
public Results<T> updateAll(@RequestBody JSONObject json) {
|
||||
sysGatewayRouteService.updateAll(json);
|
||||
return Results.OK("操作成功!");
|
||||
}
|
||||
|
||||
@GetMapping(value = "/page")
|
||||
public Results<JSONArray> queryPageList(SysGatewayRoute sysGatewayRoute) {
|
||||
LambdaQueryWrapper<SysGatewayRoute> query = new LambdaQueryWrapper<>();
|
||||
List<SysGatewayRoute> ls = sysGatewayRouteService.list(query);
|
||||
JSONArray array = new JSONArray();
|
||||
for(SysGatewayRoute rt: ls){
|
||||
JSONObject obj = (JSONObject) JSON.toJSON(rt);
|
||||
if(oConvertUtils.isNotEmpty(rt.getPredicates())){
|
||||
obj.put("predicates", JSON.parseArray(rt.getPredicates()));
|
||||
}
|
||||
if(oConvertUtils.isNotEmpty(rt.getFilters())){
|
||||
obj.put("filters", JSON.parseArray(rt.getFilters()));
|
||||
}
|
||||
array.add(obj);
|
||||
}
|
||||
return Results.OK(array);
|
||||
}
|
||||
|
||||
@GetMapping(value = "/clearRedis")
|
||||
public Results<T> clearRedis() {
|
||||
sysGatewayRouteService.clearRedis();
|
||||
return Results.OK("清除成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id删除
|
||||
*
|
||||
* @param map
|
||||
* @return
|
||||
*/
|
||||
//@RequiresRoles({"admin"})
|
||||
// @RequestMapping(value = "/delete", method = RequestMethod.DELETE)
|
||||
@PostMapping("/delete")
|
||||
public Results<T> delete(@RequestBody Map<String, String> map) {
|
||||
String id = map.get("id");
|
||||
if(StringUtils.isBlank(id)){
|
||||
return Results.error("参数不识别!");
|
||||
}
|
||||
sysGatewayRouteService.deleteById(id);
|
||||
return Results.OK("删除路由成功");
|
||||
}
|
||||
|
||||
}
|
||||
+112
@@ -0,0 +1,112 @@
|
||||
package com.jero.modules.system.controller;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.jero.common.api.vo.Results;
|
||||
import com.jero.common.system.query.QueryGenerator;
|
||||
import com.jero.common.util.oConvertUtils;
|
||||
import com.jero.modules.system.entity.SysLog;
|
||||
import com.jero.modules.system.service.ISysLogService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.poi.ss.formula.functions.T;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 系统日志表 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @Author zhangweijian
|
||||
* @since 2018-12-26
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/sys/log")
|
||||
@Slf4j
|
||||
public class SysLogController {
|
||||
|
||||
@Autowired
|
||||
private ISysLogService sysLogService;
|
||||
|
||||
/**
|
||||
* @功能:查询日志记录
|
||||
* @param syslog
|
||||
* @param pageNo
|
||||
* @param pageSize
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/page")
|
||||
public Results<IPage<SysLog>> queryPageList(SysLog syslog, @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
|
||||
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize, HttpServletRequest req) {
|
||||
Results<IPage<SysLog>> result = new Results<>();
|
||||
QueryWrapper<SysLog> queryWrapper = QueryGenerator.initQueryWrapper(syslog, req.getParameterMap());
|
||||
Page<SysLog> page = new Page<>(pageNo, pageSize);
|
||||
//日志关键词
|
||||
String keyWord = req.getParameter("keyWord");
|
||||
if(oConvertUtils.isNotEmpty(keyWord)) {
|
||||
queryWrapper.like("log_content",keyWord);
|
||||
}
|
||||
//创建时间/创建人的赋值
|
||||
IPage<SysLog> pageList = sysLogService.page(page, queryWrapper);
|
||||
log.info("查询当前页:"+pageList.getCurrent());
|
||||
log.info("查询当前页数量:"+pageList.getSize());
|
||||
log.info("查询结果数量:"+pageList.getRecords().size());
|
||||
log.info("数据总数:"+pageList.getTotal());
|
||||
result.setSuccess(true);
|
||||
result.setResult(pageList);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @功能:删除单个日志记录
|
||||
* @param map
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/delete")
|
||||
public Results<T> delete(@RequestBody Map<String, String> map) {
|
||||
String id = map.get("id");
|
||||
if(StringUtils.isBlank(id)){
|
||||
return Results.error("参数不识别!");
|
||||
}
|
||||
SysLog sysLog = sysLogService.getById(id);
|
||||
if(sysLog==null) {
|
||||
return Results.error("未找到对应实体");
|
||||
}else {
|
||||
boolean ok = sysLogService.removeById(id);
|
||||
if(ok) {
|
||||
return Results.OK("删除成功!");
|
||||
}
|
||||
}
|
||||
return Results.OK();
|
||||
}
|
||||
|
||||
/**
|
||||
* @功能:批量,全部清空日志记录
|
||||
* @param map
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/deleteBatch")
|
||||
public Results<T> deleteBatch(@RequestBody Map<String, String> map) {
|
||||
String ids = map.get("ids");
|
||||
if(ids==null || "".equals(ids.trim())) {
|
||||
return Results.error("参数不识别!");
|
||||
}else {
|
||||
if("allclear".equals(ids)) {
|
||||
this.sysLogService.removeAll();
|
||||
return Results.OK("清除成功!");
|
||||
}
|
||||
this.sysLogService.removeByIds(Arrays.asList(ids.split(",")));
|
||||
return Results.OK("删除成功!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+766
@@ -0,0 +1,766 @@
|
||||
package com.jero.modules.system.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.jero.common.api.vo.Results;
|
||||
import com.jero.common.constant.CommonConstant;
|
||||
import com.jero.common.system.vo.LoginUser;
|
||||
import com.jero.common.util.MD5Util;
|
||||
import com.jero.common.util.oConvertUtils;
|
||||
import com.jero.modules.system.entity.SysDepartPermission;
|
||||
import com.jero.modules.system.entity.SysPermission;
|
||||
import com.jero.modules.system.entity.SysPermissionDataRule;
|
||||
import com.jero.modules.system.entity.SysRolePermission;
|
||||
import com.jero.modules.system.model.SysPermissionTree;
|
||||
import com.jero.modules.system.model.TreeModel;
|
||||
import com.jero.modules.system.service.ISysDepartPermissionService;
|
||||
import com.jero.modules.system.service.ISysPermissionDataRuleService;
|
||||
import com.jero.modules.system.service.ISysPermissionService;
|
||||
import com.jero.modules.system.service.ISysRolePermissionService;
|
||||
import com.jero.modules.system.util.PermissionDataUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.poi.ss.formula.functions.T;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 菜单权限表 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @Author scott
|
||||
* @since 2018-12-21
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/sys/permission")
|
||||
public class SysPermissionController {
|
||||
|
||||
@Autowired
|
||||
private ISysPermissionService sysPermissionService;
|
||||
|
||||
@Autowired
|
||||
private ISysRolePermissionService sysRolePermissionService;
|
||||
|
||||
@Autowired
|
||||
private ISysPermissionDataRuleService sysPermissionDataRuleService;
|
||||
|
||||
@Autowired
|
||||
private ISysDepartPermissionService sysDepartPermissionService;
|
||||
|
||||
private static final String OPTION_SUCCESS = "操作成功!";
|
||||
private static final String DEL_SUCCESS = "删除成功!";
|
||||
private static final String PERMISSION_LIST = "permissionList";
|
||||
private static final String CHILDREN = "children";
|
||||
private static final String PARAM_NULL = "参数不识别!";
|
||||
|
||||
/**
|
||||
* 加载数据节点
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/page")
|
||||
public Results<List<SysPermissionTree>> list() {
|
||||
long start = System.currentTimeMillis();
|
||||
Results<List<SysPermissionTree>> result = new Results<>();
|
||||
try {
|
||||
LambdaQueryWrapper<SysPermission> query = new LambdaQueryWrapper<>();
|
||||
query.eq(SysPermission::getDelFlag, CommonConstant.DEL_FLAG_0);
|
||||
query.orderByAsc(SysPermission::getSortNo);
|
||||
List<SysPermission> list = sysPermissionService.list(query);
|
||||
List<SysPermissionTree> treeList = new ArrayList<>();
|
||||
getTreeList(treeList, list, null);
|
||||
result.setResult(treeList);
|
||||
result.setSuccess(true);
|
||||
log.info("======获取全部菜单数据=====耗时:" + (System.currentTimeMillis() - start) + "毫秒");
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/*update_begin author:wuxianquan date:20190908 for:先查询一级菜单,当用户点击展开菜单时加载子菜单 */
|
||||
/**
|
||||
* 系统菜单列表(一级菜单)
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getSystemMenuList")
|
||||
public Results<List<SysPermissionTree>> getSystemMenuList() {
|
||||
long start = System.currentTimeMillis();
|
||||
Results<List<SysPermissionTree>> result = new Results<>();
|
||||
try {
|
||||
LambdaQueryWrapper<SysPermission> query = new LambdaQueryWrapper<>();
|
||||
query.eq(SysPermission::getMenuType,CommonConstant.MENU_TYPE_0);
|
||||
query.eq(SysPermission::getDelFlag, CommonConstant.DEL_FLAG_0);
|
||||
query.orderByAsc(SysPermission::getSortNo);
|
||||
List<SysPermission> list = sysPermissionService.list(query);
|
||||
List<SysPermissionTree> sysPermissionTreeList = new ArrayList<>();
|
||||
for(SysPermission sysPermission : list){
|
||||
SysPermissionTree sysPermissionTree = new SysPermissionTree(sysPermission);
|
||||
sysPermissionTreeList.add(sysPermissionTree);
|
||||
}
|
||||
result.setResult(sysPermissionTreeList);
|
||||
result.setSuccess(true);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
log.info("======获取一级菜单数据=====耗时:" + (System.currentTimeMillis() - start) + "毫秒");
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询子菜单
|
||||
* @param parentId
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getSystemSubmenu")
|
||||
public Results<List<SysPermissionTree>> getSystemSubmenu(@RequestParam("parentId") String parentId){
|
||||
Results<List<SysPermissionTree>> result = new Results<>();
|
||||
try{
|
||||
LambdaQueryWrapper<SysPermission> query = new LambdaQueryWrapper<>();
|
||||
query.eq(SysPermission::getParentId,parentId);
|
||||
query.eq(SysPermission::getDelFlag, CommonConstant.DEL_FLAG_0);
|
||||
query.orderByAsc(SysPermission::getSortNo);
|
||||
List<SysPermission> list = sysPermissionService.list(query);
|
||||
List<SysPermissionTree> sysPermissionTreeList = new ArrayList<>();
|
||||
for(SysPermission sysPermission : list){
|
||||
SysPermissionTree sysPermissionTree = new SysPermissionTree(sysPermission);
|
||||
sysPermissionTreeList.add(sysPermissionTree);
|
||||
}
|
||||
result.setResult(sysPermissionTreeList);
|
||||
result.setSuccess(true);
|
||||
}catch (Exception e){
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/*update_end author:wuxianquan date:20190908 for:先查询一级菜单,当用户点击展开菜单时加载子菜单 */
|
||||
|
||||
// update_begin author:sunjianlei date:20200108 for: 新增批量根据父ID查询子级菜单的接口 -------------
|
||||
/**
|
||||
* 查询子菜单
|
||||
*
|
||||
* @param parentIds 父ID(多个采用半角逗号分割)
|
||||
* @return 返回 key-value 的 Map
|
||||
*/
|
||||
@GetMapping("/getSystemSubmenuBatch")
|
||||
public Results<Map<String, List<SysPermissionTree>>> getSystemSubmenuBatch(@RequestParam("parentIds") String parentIds) {
|
||||
try {
|
||||
LambdaQueryWrapper<SysPermission> query = new LambdaQueryWrapper<>();
|
||||
List<String> parentIdList = Arrays.asList(parentIds.split(","));
|
||||
query.in(SysPermission::getParentId, parentIdList);
|
||||
query.eq(SysPermission::getDelFlag, CommonConstant.DEL_FLAG_0);
|
||||
query.orderByAsc(SysPermission::getSortNo);
|
||||
List<SysPermission> list = sysPermissionService.list(query);
|
||||
Map<String, List<SysPermissionTree>> listMap = new HashMap<>();
|
||||
for (SysPermission item : list) {
|
||||
String pid = item.getParentId();
|
||||
if (parentIdList.contains(pid)) {
|
||||
List<SysPermissionTree> mapList = listMap.get(pid);
|
||||
if (mapList == null) {
|
||||
mapList = new ArrayList<>();
|
||||
}
|
||||
mapList.add(new SysPermissionTree(item));
|
||||
listMap.put(pid, mapList);
|
||||
}
|
||||
}
|
||||
return Results.OK(listMap);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
return Results.error("批量查询子菜单失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询用户拥有的菜单权限和按钮权限
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getUserPermissionByToken")
|
||||
public Results<JSONObject> getUserPermissionByToken() {
|
||||
Results<JSONObject> result = new Results<>();
|
||||
try {
|
||||
//直接获取当前用户不适用前端token
|
||||
LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
||||
if (oConvertUtils.isEmpty(loginUser)) {
|
||||
return Results.error("请登录系统!");
|
||||
}
|
||||
List<SysPermission> metaList = sysPermissionService.queryByUser(loginUser.getUsername());
|
||||
|
||||
JSONObject json = new JSONObject();
|
||||
JSONArray menujsonArray = new JSONArray();
|
||||
this.getPermissionJsonArray(menujsonArray, metaList, null);
|
||||
JSONArray authjsonArray = new JSONArray();
|
||||
this.getAuthJsonArray(authjsonArray, metaList);
|
||||
//查询所有的权限
|
||||
LambdaQueryWrapper<SysPermission> query = new LambdaQueryWrapper<>();
|
||||
query.eq(SysPermission::getDelFlag, CommonConstant.DEL_FLAG_0);
|
||||
query.eq(SysPermission::getMenuType, CommonConstant.MENU_TYPE_2);
|
||||
List<SysPermission> allAuthList = sysPermissionService.list(query);
|
||||
JSONArray allauthjsonArray = new JSONArray();
|
||||
this.getAllAuthJsonArray(allauthjsonArray, allAuthList);
|
||||
//路由菜单
|
||||
json.put("menu", menujsonArray);
|
||||
//按钮权限(用户拥有的权限集合)
|
||||
json.put("auth", authjsonArray);
|
||||
//全部权限配置集合(按钮权限,访问权限)
|
||||
json.put("allAuth", allauthjsonArray);
|
||||
result.setResult(json);
|
||||
result.setMessage("查询成功");
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
return Results.error("查询失败:" + e.getMessage());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加菜单
|
||||
* @param permission
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/add")
|
||||
public Results<Object> add(@RequestBody SysPermission permission) {
|
||||
try {
|
||||
permission = PermissionDataUtil.intelligentProcessData(permission);
|
||||
sysPermissionService.addPermission(permission);
|
||||
return Results.OK(OPTION_SUCCESS);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
return Results.error("操作失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑菜单
|
||||
* @param permission
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/edit")
|
||||
public Results<Object> edit(@RequestBody SysPermission permission) {
|
||||
try {
|
||||
permission = PermissionDataUtil.intelligentProcessData(permission);
|
||||
sysPermissionService.editPermission(permission);
|
||||
return Results.OK(OPTION_SUCCESS);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
return Results.error("操作失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除菜单
|
||||
* @param map
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/delete")
|
||||
public Results<T> delete(@RequestBody Map<String, String> map) {
|
||||
String id = map.get("id");
|
||||
if(StringUtils.isBlank(id)){
|
||||
return Results.error(PARAM_NULL);
|
||||
}
|
||||
try {
|
||||
sysPermissionService.deletePermission(id);
|
||||
return Results.OK(DEL_SUCCESS);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
return Results.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除菜单
|
||||
* @param map
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/deleteBatch")
|
||||
public Results<T> deleteBatch(@RequestBody Map<String, String> map) {
|
||||
String ids = map.get("ids");
|
||||
if(StringUtils.isBlank(ids)){
|
||||
return Results.error(PARAM_NULL);
|
||||
}
|
||||
try {
|
||||
String[] arr = ids.split(",");
|
||||
for (String id : arr) {
|
||||
if (oConvertUtils.isNotEmpty(id)) {
|
||||
sysPermissionService.deletePermission(id);
|
||||
}
|
||||
}
|
||||
return Results.OK(DEL_SUCCESS);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
return Results.error(DEL_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取全部的权限树
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/queryTreeList")
|
||||
public Results<Map<String, Object>> queryTreeList() {
|
||||
Results<Map<String, Object>> result = new Results<>();
|
||||
// 全部权限ids
|
||||
List<String> ids = new ArrayList<>();
|
||||
try {
|
||||
LambdaQueryWrapper<SysPermission> query = new LambdaQueryWrapper<>();
|
||||
query.eq(SysPermission::getDelFlag, CommonConstant.DEL_FLAG_0);
|
||||
query.orderByAsc(SysPermission::getSortNo);
|
||||
List<SysPermission> list = sysPermissionService.list(query);
|
||||
for (SysPermission sysPer : list) {
|
||||
ids.add(sysPer.getId());
|
||||
}
|
||||
List<TreeModel> treeList = new ArrayList<>();
|
||||
getTreeModelList(treeList, list, null);
|
||||
|
||||
Map<String, Object> resMap = new HashMap<>();
|
||||
resMap.put("treeList", treeList); // 全部树节点数据
|
||||
resMap.put("ids", ids);// 全部树ids
|
||||
result.setResult(resMap);
|
||||
result.setSuccess(true);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 异步加载数据节点
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/queryListAsync")
|
||||
public Results<List<TreeModel>> queryAsync(@RequestParam(name = "pid", required = false) String parentId) {
|
||||
Results<List<TreeModel>> result = new Results<>();
|
||||
try {
|
||||
List<TreeModel> list = sysPermissionService.queryListByParentId(parentId);
|
||||
if (list == null || list.isEmpty()) {
|
||||
return Results.error("未找到角色信息");
|
||||
} else {
|
||||
result.setResult(list);
|
||||
result.setSuccess(true);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询角色授权
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/queryRolePermission")
|
||||
public Results<List<String>> queryRolePermission(@RequestParam(name = "roleId", required = true) String roleId) {
|
||||
Results<List<String>> result = new Results<>();
|
||||
try {
|
||||
List<SysRolePermission> list = sysRolePermissionService.list(new QueryWrapper<SysRolePermission>().lambda().eq(SysRolePermission::getRoleId, roleId));
|
||||
result.setResult(list.stream().map(sysRolePermission -> String.valueOf(sysRolePermission.getPermissionId())).collect(Collectors.toList()));
|
||||
result.setSuccess(true);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存角色授权
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/saveRolePermission")
|
||||
public Results<String> saveRolePermission(@RequestBody JSONObject json) {
|
||||
long start = System.currentTimeMillis();
|
||||
try {
|
||||
String roleId = json.getString("roleId");
|
||||
String permissionIds = json.getString("permissionIds");
|
||||
String lastPermissionIds = json.getString("lastpermissionIds");
|
||||
this.sysRolePermissionService.saveRolePermission(roleId, permissionIds, lastPermissionIds);
|
||||
log.info("======角色授权成功=====耗时:" + (System.currentTimeMillis() - start) + "毫秒");
|
||||
return Results.OK(OPTION_SUCCESS);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
return Results.error("授权失败!");
|
||||
}
|
||||
}
|
||||
|
||||
private void getTreeList(List<SysPermissionTree> treeList, List<SysPermission> metaList, SysPermissionTree temp) {
|
||||
for (SysPermission permission : metaList) {
|
||||
String tempPid = permission.getParentId();
|
||||
SysPermissionTree tree = new SysPermissionTree(permission);
|
||||
if (temp == null && oConvertUtils.isEmpty(tempPid)) {
|
||||
treeList.add(tree);
|
||||
if (!tree.getIsLeaf()) {
|
||||
getTreeList(treeList, metaList, tree);
|
||||
}
|
||||
} else if (temp != null && tempPid != null && tempPid.equals(temp.getId())) {
|
||||
temp.getChildren().add(tree);
|
||||
if (!tree.getIsLeaf()) {
|
||||
getTreeList(treeList, metaList, tree);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void getTreeModelList(List<TreeModel> treeList, List<SysPermission> metaList, TreeModel temp) {
|
||||
for (SysPermission permission : metaList) {
|
||||
String tempPid = permission.getParentId();
|
||||
TreeModel tree = new TreeModel(permission);
|
||||
if (temp == null && oConvertUtils.isEmpty(tempPid)) {
|
||||
treeList.add(tree);
|
||||
if (!tree.getIsLeaf()) {
|
||||
getTreeModelList(treeList, metaList, tree);
|
||||
}
|
||||
} else if (temp != null && tempPid != null && tempPid.equals(temp.getKey())) {
|
||||
temp.getChildren().add(tree);
|
||||
if (!tree.getIsLeaf()) {
|
||||
getTreeModelList(treeList, metaList, tree);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取权限JSON数组
|
||||
* @param jsonArray
|
||||
* @param allList
|
||||
*/
|
||||
private void getAllAuthJsonArray(JSONArray jsonArray,List<SysPermission> allList) {
|
||||
JSONObject json = null;
|
||||
for (SysPermission permission : allList) {
|
||||
json = new JSONObject();
|
||||
json.put("action", permission.getPerms());
|
||||
json.put("status", permission.getStatus());
|
||||
//1显示2禁用
|
||||
json.put("type", permission.getPermsType());
|
||||
json.put("describe", permission.getName());
|
||||
jsonArray.add(json);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取权限JSON数组
|
||||
* @param jsonArray
|
||||
* @param metaList
|
||||
*/
|
||||
private void getAuthJsonArray(JSONArray jsonArray,List<SysPermission> metaList) {
|
||||
for (SysPermission permission : metaList) {
|
||||
if(permission.getMenuType()==null) {
|
||||
continue;
|
||||
}
|
||||
JSONObject json = null;
|
||||
if(permission.getMenuType().equals(CommonConstant.MENU_TYPE_2) &&CommonConstant.STATUS_1.equals(permission.getStatus())) {
|
||||
json = new JSONObject();
|
||||
json.put("action", permission.getPerms());
|
||||
json.put("type", permission.getPermsType());
|
||||
json.put("describe", permission.getName());
|
||||
jsonArray.add(json);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 获取菜单JSON数组
|
||||
* @param jsonArray
|
||||
* @param metaList
|
||||
* @param parentJson
|
||||
*/
|
||||
private void getPermissionJsonArray(JSONArray jsonArray, List<SysPermission> metaList, JSONObject parentJson) {
|
||||
for (SysPermission permission : metaList) {
|
||||
if (permission.getMenuType() == null) {
|
||||
continue;
|
||||
}
|
||||
String tempPid = permission.getParentId();
|
||||
JSONObject json = getPermissionJsonObject(permission);
|
||||
if (parentJson == null && oConvertUtils.isEmpty(tempPid)) {
|
||||
jsonArray.add(json);
|
||||
if (!permission.isLeaf()) {
|
||||
getPermissionJsonArray(jsonArray, metaList, json);
|
||||
}
|
||||
} else if (parentJson != null && oConvertUtils.isNotEmpty(tempPid) && tempPid.equals(parentJson.getString("id"))) {
|
||||
putParentJson(jsonArray, metaList, parentJson, permission, json);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void putParentJson(JSONArray jsonArray, List<SysPermission> metaList, JSONObject parentJson, SysPermission permission, JSONObject json) {
|
||||
// 类型( 0:一级菜单 1:子菜单 2:按钮 )
|
||||
if (permission.getMenuType().equals(CommonConstant.MENU_TYPE_2)) {
|
||||
JSONObject metaJson = parentJson.getJSONObject("meta");
|
||||
if (metaJson.containsKey(PERMISSION_LIST)) {
|
||||
metaJson.getJSONArray(PERMISSION_LIST).add(json);
|
||||
} else {
|
||||
JSONArray permissionList = new JSONArray();
|
||||
permissionList.add(json);
|
||||
metaJson.put(PERMISSION_LIST, permissionList);
|
||||
}
|
||||
// 类型( 0:一级菜单 1:子菜单 2:按钮 )
|
||||
} else if (permission.getMenuType().equals(CommonConstant.MENU_TYPE_1) || permission.getMenuType().equals(CommonConstant.MENU_TYPE_0)) {
|
||||
if (parentJson.containsKey(CHILDREN)) {
|
||||
parentJson.getJSONArray(CHILDREN).add(json);
|
||||
} else {
|
||||
JSONArray children = new JSONArray();
|
||||
children.add(json);
|
||||
parentJson.put(CHILDREN, children);
|
||||
}
|
||||
|
||||
if (!permission.isLeaf()) {
|
||||
getPermissionJsonArray(jsonArray, metaList, json);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据菜单配置生成路由json
|
||||
* @param permission
|
||||
* @return
|
||||
*/
|
||||
private JSONObject getPermissionJsonObject(SysPermission permission) {
|
||||
JSONObject json = new JSONObject();
|
||||
// 类型(0:一级菜单 1:子菜单 2:按钮)
|
||||
if (permission.getMenuType().equals(CommonConstant.MENU_TYPE_2)) {
|
||||
return new JSONObject();
|
||||
} else if (permission.getMenuType().equals(CommonConstant.MENU_TYPE_0) || permission.getMenuType().equals(CommonConstant.MENU_TYPE_1)) {
|
||||
json.put("id", permission.getId());
|
||||
putJson(permission, json);
|
||||
json.put("component", permission.getComponent());
|
||||
JSONObject meta = putMeta(permission, json);
|
||||
json.put("meta", meta);
|
||||
}
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private JSONObject putMeta(SysPermission permission, JSONObject json) {
|
||||
JSONObject meta = new JSONObject();
|
||||
// 由用户设置是否缓存页面 用布尔值
|
||||
meta.put("keepAlive", permission.isKeepAlive());
|
||||
|
||||
/*update_begin author:wuxianquan date:20190908 for:往菜单信息里添加外链菜单打开方式 */
|
||||
//外链菜单打开方式
|
||||
meta.put("internalOrExternal", permission.isInternalOrExternal());
|
||||
/* update_end author:wuxianquan date:20190908 for: 往菜单信息里添加外链菜单打开方式*/
|
||||
|
||||
meta.put("title", permission.getName());
|
||||
|
||||
//update-begin--Author:scott Date:20201015 for:路由缓存问题,关闭了tab页时再打开就不刷新 #842
|
||||
String component = permission.getComponent();
|
||||
if(oConvertUtils.isNotEmpty(permission.getComponentName()) || oConvertUtils.isNotEmpty(component)){
|
||||
meta.put("componentName", oConvertUtils.getString(permission.getComponentName(),component.substring(component.lastIndexOf("/")+1)));
|
||||
}
|
||||
//update-end--Author:scott Date:20201015 for:路由缓存问题,关闭了tab页时再打开就不刷新 #842
|
||||
|
||||
if (oConvertUtils.isEmpty(permission.getParentId())) {
|
||||
// 一级菜单跳转地址
|
||||
json.put("redirect", permission.getRedirect());
|
||||
if (oConvertUtils.isNotEmpty(permission.getIcon())) {
|
||||
meta.put("icon", permission.getIcon());
|
||||
}
|
||||
} else {
|
||||
if (oConvertUtils.isNotEmpty(permission.getIcon())) {
|
||||
meta.put("icon", permission.getIcon());
|
||||
}
|
||||
}
|
||||
if (isWWWHttpUrl(permission.getUrl())) {
|
||||
meta.put("url", permission.getUrl());
|
||||
}
|
||||
return meta;
|
||||
}
|
||||
|
||||
private void putJson(SysPermission permission, JSONObject json) {
|
||||
if (permission.isRoute()) {
|
||||
json.put("route", "1");// 表示生成路由
|
||||
} else {
|
||||
json.put("route", "0");// 表示不生成路由
|
||||
}
|
||||
|
||||
if (isWWWHttpUrl(permission.getUrl())) {
|
||||
json.put("path", MD5Util.MD5Encode(permission.getUrl(), "utf-8"));
|
||||
} else {
|
||||
json.put("path", permission.getUrl());
|
||||
}
|
||||
|
||||
// 重要规则:路由name (通过URL生成路由name,路由name供前端开发,页面跳转使用)
|
||||
if (oConvertUtils.isNotEmpty(permission.getComponentName())) {
|
||||
json.put("name", permission.getComponentName());
|
||||
} else {
|
||||
json.put("name", urlToRouteName(permission.getUrl()));
|
||||
}
|
||||
|
||||
// 是否隐藏路由,默认都是显示的
|
||||
if (permission.isHidden()) {
|
||||
json.put("hidden", true);
|
||||
}
|
||||
// 聚合路由
|
||||
if (permission.isAlwaysShow()) {
|
||||
json.put("alwaysShow", true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否外网URL 例如: http://localhost:8080/jero-boot/swagger-ui.html#/ 支持特殊格式: {{
|
||||
* window._CONFIG['domianURL'] }}/druid/ {{ JS代码片段 }},前台解析会自动执行JS代码片段
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private boolean isWWWHttpUrl(String url) {
|
||||
return url != null && (url.startsWith("http://") || url.startsWith("https://") || url.startsWith("{{"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过URL生成路由name(去掉URL前缀斜杠,替换内容中的斜杠‘/’为-) 举例: URL = /isystem/role RouteName =
|
||||
* isystem-role
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private String urlToRouteName(String url) {
|
||||
if (oConvertUtils.isNotEmpty(url)) {
|
||||
if (url.startsWith("/")) {
|
||||
url = url.substring(1);
|
||||
}
|
||||
url = url.replace("/", "-");
|
||||
|
||||
// 特殊标记
|
||||
url = url.replace(":", "@");
|
||||
return url;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据菜单id来获取其对应的权限数据
|
||||
*
|
||||
* @param sysPermissionDataRule
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getPermRuleListByPermId")
|
||||
public Results<List<SysPermissionDataRule>> getPermRuleListByPermId(SysPermissionDataRule sysPermissionDataRule) {
|
||||
List<SysPermissionDataRule> permRuleList = sysPermissionDataRuleService.getPermRuleListByPermId(sysPermissionDataRule.getPermissionId());
|
||||
Results<List<SysPermissionDataRule>> result = new Results<>();
|
||||
result.setSuccess(true);
|
||||
result.setResult(permRuleList);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加菜单权限数据
|
||||
*
|
||||
* @param sysPermissionDataRule
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/addPermissionRule")
|
||||
public Results<Object> addPermissionRule(@RequestBody SysPermissionDataRule sysPermissionDataRule) {
|
||||
try {
|
||||
sysPermissionDataRule.setCreateTime(new Date());
|
||||
sysPermissionDataRuleService.savePermissionDataRule(sysPermissionDataRule);
|
||||
return Results.OK(OPTION_SUCCESS);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
return Results.error("操作失败");
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/editPermissionRule")
|
||||
public Results<Object> editPermissionRule(@RequestBody SysPermissionDataRule sysPermissionDataRule) {
|
||||
try {
|
||||
sysPermissionDataRuleService.saveOrUpdate(sysPermissionDataRule);
|
||||
return Results.OK("更新成功!");
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
return Results.error("操作失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除菜单权限数据
|
||||
*
|
||||
* @param map
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/deletePermissionRule")
|
||||
public Results<Object> deletePermissionRule(@RequestBody Map<String,String> map) {
|
||||
try {
|
||||
String id = map.get("id");
|
||||
if(StringUtils.isBlank(id)){
|
||||
return Results.error(PARAM_NULL);
|
||||
}
|
||||
sysPermissionDataRuleService.deletePermissionDataRule(id);
|
||||
return Results.OK("删除成功!");
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
return Results.error("操作失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询菜单权限数据
|
||||
*
|
||||
* @param sysPermissionDataRule
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/queryPermissionRule")
|
||||
public Results<List<SysPermissionDataRule>> queryPermissionRule(SysPermissionDataRule sysPermissionDataRule) {
|
||||
try {
|
||||
List<SysPermissionDataRule> permRuleList = sysPermissionDataRuleService.queryPermissionRule(sysPermissionDataRule);
|
||||
return Results.OK("查询成功", permRuleList);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
return Results.error("操作失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 部门权限表
|
||||
* @param departId
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/queryDepartPermission")
|
||||
public Results<List<String>> queryDepartPermission(@RequestParam(name = "departId", required = true) String departId) {
|
||||
Results<List<String>> result = new Results<>();
|
||||
try {
|
||||
List<SysDepartPermission> list = sysDepartPermissionService.list(new QueryWrapper<SysDepartPermission>().lambda().eq(SysDepartPermission::getDepartId, departId));
|
||||
result.setResult(list.stream().map(sysDepartPermission -> String.valueOf(sysDepartPermission.getPermissionId())).collect(Collectors.toList()));
|
||||
result.setSuccess(true);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存部门授权
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/saveDepartPermission")
|
||||
public Results<String> saveDepartPermission(@RequestBody JSONObject json) {
|
||||
long start = System.currentTimeMillis();
|
||||
try {
|
||||
String departId = json.getString("departId");
|
||||
String permissionIds = json.getString("permissionIds");
|
||||
String lastPermissionIds = json.getString("lastpermissionIds");
|
||||
this.sysDepartPermissionService.saveDepartPermission(departId, permissionIds, lastPermissionIds);
|
||||
log.info("======部门授权成功=====耗时:" + (System.currentTimeMillis() - start) + "毫秒");
|
||||
return Results.OK(OPTION_SUCCESS);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
return Results.error("授权失败!");
|
||||
}
|
||||
}
|
||||
}
|
||||
+394
@@ -0,0 +1,394 @@
|
||||
package com.jero.modules.system.controller;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.jero.common.api.vo.Results;
|
||||
import com.jero.common.system.base.controller.JeroController;
|
||||
import com.jero.common.util.SpringContextUtils;
|
||||
import com.jero.config.easypoi.EasyPoiDictHandlerImpl;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.poi.ss.formula.functions.T;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import com.jero.common.constant.CommonConstant;
|
||||
import com.jero.common.system.query.QueryGenerator;
|
||||
import com.jero.common.util.oConvertUtils;
|
||||
import com.jero.modules.system.entity.SysPermission;
|
||||
import com.jero.modules.system.entity.SysPermissionDataRule;
|
||||
import com.jero.modules.system.entity.SysRole;
|
||||
import com.jero.modules.system.entity.SysRolePermission;
|
||||
import com.jero.modules.system.model.TreeModel;
|
||||
import com.jero.modules.system.service.ISysPermissionDataRuleService;
|
||||
import com.jero.modules.system.service.ISysPermissionService;
|
||||
import com.jero.modules.system.service.ISysRolePermissionService;
|
||||
import com.jero.modules.system.service.ISysRoleService;
|
||||
import cn.afterturn.easypoi.entity.vo.NormalExcelConstants;
|
||||
import cn.afterturn.easypoi.excel.entity.ExportParams;
|
||||
import cn.afterturn.easypoi.excel.entity.ImportParams;
|
||||
import cn.afterturn.easypoi.view.EasypoiSingleExcelView;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
import com.jero.common.system.vo.LoginUser;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 角色表 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @Author scott
|
||||
* @since 2018-12-19
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/sys/role")
|
||||
@Slf4j
|
||||
public class SysRoleController {
|
||||
@Autowired
|
||||
private ISysRoleService sysRoleService;
|
||||
|
||||
@Autowired
|
||||
private ISysPermissionDataRuleService sysPermissionDataRuleService;
|
||||
|
||||
@Autowired
|
||||
private ISysRolePermissionService sysRolePermissionService;
|
||||
|
||||
@Autowired
|
||||
private ISysPermissionService sysPermissionService;
|
||||
|
||||
private static final String OPTION_SUCCESS = "操作成功!";
|
||||
|
||||
/**
|
||||
* 分页列表查询
|
||||
* @param role
|
||||
* @param pageNo
|
||||
* @param pageSize
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/page")
|
||||
public Results<IPage<SysRole>> queryPageList(SysRole role,
|
||||
@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
|
||||
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
|
||||
HttpServletRequest req) {
|
||||
Results<IPage<SysRole>> result = new Results<>();
|
||||
QueryWrapper<SysRole> queryWrapper = QueryGenerator.initQueryWrapper(role, req.getParameterMap());
|
||||
Page<SysRole> page = new Page<>(pageNo, pageSize);
|
||||
IPage<SysRole> pageList = sysRoleService.page(page, queryWrapper);
|
||||
result.setSuccess(true);
|
||||
result.setResult(pageList);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
* @param role
|
||||
* @return
|
||||
*/
|
||||
@RequiresPermissions("sys:role:add")
|
||||
@PostMapping("/add")
|
||||
public Results<Object> add(@RequestBody SysRole role) {
|
||||
try {
|
||||
role.setCreateTime(new Date());
|
||||
sysRoleService.save(role);
|
||||
return Results.OK(OPTION_SUCCESS);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
return Results.error("操作失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
* @param role
|
||||
* @return
|
||||
*/
|
||||
@RequiresPermissions("sys:role:edit")
|
||||
@PostMapping("/edit")
|
||||
public Results<Object> edit(@RequestBody SysRole role) {
|
||||
SysRole sysrole = sysRoleService.getById(role.getId());
|
||||
if(sysrole==null) {
|
||||
return Results.error("未找到对应实体");
|
||||
}else {
|
||||
role.setUpdateTime(new Date());
|
||||
boolean ok = sysRoleService.updateById(role);
|
||||
if(ok) {
|
||||
return Results.OK(OPTION_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
return Results.OK();
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id删除
|
||||
* @param map
|
||||
* @return
|
||||
*/
|
||||
@RequiresPermissions("sys:role:del")
|
||||
@PostMapping("/delete")
|
||||
public Results<T> delete(@RequestBody Map<String, String> map) {
|
||||
String id = map.get("id");
|
||||
if(StringUtils.isBlank(id)){
|
||||
return Results.error("参数不识别!");
|
||||
}
|
||||
sysRoleService.deleteRole(id);
|
||||
return Results.OK("删除角色成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
* @param map
|
||||
* @return
|
||||
*/
|
||||
@RequiresPermissions("sys:role:del")
|
||||
@PostMapping("/deleteBatch")
|
||||
public Results<T> deleteBatch(@RequestBody Map<String, String> map) {
|
||||
String ids = map.get("ids");
|
||||
if(StringUtils.isBlank(ids)){
|
||||
return Results.error("参数不识别!");
|
||||
}
|
||||
if(oConvertUtils.isEmpty(ids)) {
|
||||
return Results.error("未选中角色!");
|
||||
}else {
|
||||
sysRoleService.deleteBatchRole(ids.split(","));
|
||||
return Results.OK("删除角色成功!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id查询
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/queryById")
|
||||
public Results<SysRole> queryById(@RequestParam(name="id",required=true) String id) {
|
||||
SysRole sysRole = sysRoleService.getById(id);
|
||||
if(sysRole==null) {
|
||||
return Results.error("未找到对应实体");
|
||||
}else {
|
||||
return Results.OK(sysRole);
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/queryall")
|
||||
public Results<List<SysRole>> queryall() {
|
||||
List<SysRole> list = sysRoleService.list();
|
||||
if(list==null||list.isEmpty()) {
|
||||
return Results.error("未找到角色信息");
|
||||
}else {
|
||||
return Results.OK(list);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验角色编码唯一
|
||||
*/
|
||||
@GetMapping("/checkRoleCode")
|
||||
public Results<Boolean> checkUsername(String id, String roleCode) {
|
||||
Results<Boolean> result = new Results<>();
|
||||
result.setResult(true);//如果此参数为false则程序发生异常
|
||||
log.info("--验证角色编码是否唯一---id:"+id+"--roleCode:"+roleCode);
|
||||
try {
|
||||
SysRole role = null;
|
||||
if(oConvertUtils.isNotEmpty(id)) {
|
||||
role = sysRoleService.getById(id);
|
||||
}
|
||||
SysRole newRole = sysRoleService.getOne(new QueryWrapper<SysRole>().lambda().eq(SysRole::getRoleCode, roleCode));
|
||||
//如果根据传入的roleCode查询到信息了,那么就需要做校验了。
|
||||
if(newRole!=null && (role==null || !id.equals(newRole.getId()))) {
|
||||
//role为空=>新增模式=>只要roleCode存在则返回false
|
||||
//否则=>编辑模式=>判断两者ID是否一致-
|
||||
result.setSuccess(false);
|
||||
result.setMessage("角色编码已存在");
|
||||
return result;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
result.setSuccess(false);
|
||||
result.setResult(false);
|
||||
result.setMessage(e.getMessage());
|
||||
return result;
|
||||
}
|
||||
result.setSuccess(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出excel
|
||||
* @param request
|
||||
*/
|
||||
@RequiresPermissions("sys:role:export")
|
||||
@RequestMapping(value = "/exportXls")
|
||||
public ModelAndView exportXls(SysRole sysRole,HttpServletRequest request) {
|
||||
// Step.1 组装查询条件
|
||||
QueryWrapper<SysRole> queryWrapper = QueryGenerator.initQueryWrapper(sysRole, request.getParameterMap());
|
||||
//Step.2 AutoPoi 导出Excel
|
||||
ModelAndView mv = new ModelAndView(new EasypoiSingleExcelView());
|
||||
List<SysRole> pageList = sysRoleService.list(queryWrapper);
|
||||
//导出文件名称
|
||||
mv.addObject(JeroController.FILE_NAME,"角色列表");
|
||||
mv.addObject(JeroController.CLASS,SysRole.class);
|
||||
LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
||||
ExportParams exportParams = new ExportParams("角色列表数据","导出人:"+user.getRealname(),"导出信息");
|
||||
exportParams.setDictHandler(SpringContextUtils.getApplicationContext().getBean(EasyPoiDictHandlerImpl.class));
|
||||
mv.addObject(JeroController.PARAMS, exportParams);
|
||||
mv.addObject(NormalExcelConstants.DATA_LIST,pageList);
|
||||
return mv;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过excel导入数据
|
||||
* @param request
|
||||
* @param response
|
||||
* @return
|
||||
*/
|
||||
@RequiresPermissions("sys:role:import")
|
||||
@PostMapping("/importExcel")
|
||||
public Results<T> importExcel(HttpServletRequest request, HttpServletResponse response) {
|
||||
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
||||
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
|
||||
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
|
||||
MultipartFile file = entity.getValue();// 获取上传文件对象
|
||||
ImportParams params = new ImportParams();
|
||||
params.setDictHandler(SpringContextUtils.getApplicationContext().getBean(EasyPoiDictHandlerImpl.class));
|
||||
params.setTitleRows(2);
|
||||
params.setHeadRows(1);
|
||||
params.setNeedSave(true);
|
||||
try {
|
||||
return sysRoleService.importExcelCheckRoleCode(file, params);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
return Results.error("文件导入失败:" + e.getMessage());
|
||||
} finally {
|
||||
try {
|
||||
file.getInputStream().close();
|
||||
} catch (IOException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
return Results.error("文件导入失败!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询数据规则数据
|
||||
*/
|
||||
@GetMapping(value = "/datarule/{permissionId}/{roleId}")
|
||||
public Results<Map<String, Object>> loadDatarule(@PathVariable("permissionId") String permissionId, @PathVariable("roleId") String roleId) {
|
||||
List<SysPermissionDataRule> list = sysPermissionDataRuleService.getPermRuleListByPermId(permissionId);
|
||||
if(list==null || list.isEmpty()) {
|
||||
return Results.error("未找到权限配置信息");
|
||||
}else {
|
||||
Map<String,Object> map = new HashMap<>();
|
||||
map.put("datarule", list);
|
||||
LambdaQueryWrapper<SysRolePermission> query = new LambdaQueryWrapper<SysRolePermission>()
|
||||
.eq(SysRolePermission::getPermissionId, permissionId)
|
||||
.isNotNull(SysRolePermission::getDataRuleIds)
|
||||
.eq(SysRolePermission::getRoleId,roleId);
|
||||
SysRolePermission sysRolePermission = sysRolePermissionService.getOne(query);
|
||||
if(sysRolePermission!=null) {
|
||||
String drChecked = sysRolePermission.getDataRuleIds();
|
||||
if(oConvertUtils.isNotEmpty(drChecked)) {
|
||||
map.put("drChecked", drChecked.endsWith(",")?drChecked.substring(0, drChecked.length()-1):drChecked);
|
||||
}
|
||||
}
|
||||
return Results.OK(map);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存数据规则至角色菜单关联表
|
||||
*/
|
||||
@PostMapping(value = "/datarule")
|
||||
public Results<T> saveDatarule(@RequestBody JSONObject jsonObject) {
|
||||
try {
|
||||
String permissionId = jsonObject.getString("permissionId");
|
||||
String roleId = jsonObject.getString("roleId");
|
||||
String dataRuleIds = jsonObject.getString("dataRuleIds");
|
||||
log.info("保存数据规则>>"+"菜单ID:"+permissionId+"角色ID:"+ roleId+"数据权限ID:"+dataRuleIds);
|
||||
LambdaQueryWrapper<SysRolePermission> query = new LambdaQueryWrapper<SysRolePermission>()
|
||||
.eq(SysRolePermission::getPermissionId, permissionId)
|
||||
.eq(SysRolePermission::getRoleId,roleId);
|
||||
SysRolePermission sysRolePermission = sysRolePermissionService.getOne(query);
|
||||
if(sysRolePermission==null) {
|
||||
return Results.error("请先保存角色菜单权限!");
|
||||
}else {
|
||||
sysRolePermission.setDataRuleIds(dataRuleIds);
|
||||
this.sysRolePermissionService.updateById(sysRolePermission);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("SysRoleController.saveDatarule()发生异常:" + e.getMessage(),e);
|
||||
return Results.error("保存失败");
|
||||
}
|
||||
return Results.OK(OPTION_SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 用户角色授权功能,查询菜单权限树
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/queryTreeList")
|
||||
public Results<Map<String,Object>> queryTreeList(HttpServletRequest request) {
|
||||
Results<Map<String,Object>> result = new Results<>();
|
||||
//全部权限ids
|
||||
List<String> ids = new ArrayList<>();
|
||||
try {
|
||||
LambdaQueryWrapper<SysPermission> query = new LambdaQueryWrapper<>();
|
||||
query.eq(SysPermission::getDelFlag, CommonConstant.DEL_FLAG_0);
|
||||
query.orderByAsc(SysPermission::getSortNo);
|
||||
List<SysPermission> list = sysPermissionService.list(query);
|
||||
for(SysPermission sysPer : list) {
|
||||
ids.add(sysPer.getId());
|
||||
}
|
||||
List<TreeModel> treeList = new ArrayList<>();
|
||||
getTreeModelList(treeList, list, null);
|
||||
Map<String,Object> resMap = new HashMap<>();
|
||||
resMap.put("treeList", treeList); //全部树节点数据
|
||||
resMap.put("ids", ids);//全部树ids
|
||||
result.setResult(resMap);
|
||||
result.setSuccess(true);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void getTreeModelList(List<TreeModel> treeList,List<SysPermission> metaList,TreeModel temp) {
|
||||
for (SysPermission permission : metaList) {
|
||||
String tempPid = permission.getParentId();
|
||||
TreeModel tree = new TreeModel(permission.getId(), tempPid, permission.getName(),permission.getRuleFlag(), permission.isLeaf());
|
||||
if(temp==null && oConvertUtils.isEmpty(tempPid)) {
|
||||
treeList.add(tree);
|
||||
if(!tree.getIsLeaf()) {
|
||||
getTreeModelList(treeList, metaList, tree);
|
||||
}
|
||||
}else if(temp!=null && tempPid!=null && tempPid.equals(temp.getKey())){
|
||||
temp.getChildren().add(tree);
|
||||
if(!tree.getIsLeaf()) {
|
||||
getTreeModelList(treeList, metaList, tree);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+182
@@ -0,0 +1,182 @@
|
||||
package com.jero.modules.system.controller;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.jero.common.api.vo.Results;
|
||||
import com.jero.common.aspect.annotation.PermissionData;
|
||||
import com.jero.common.system.query.QueryGenerator;
|
||||
import com.jero.common.util.oConvertUtils;
|
||||
import com.jero.modules.system.entity.SysTenant;
|
||||
import com.jero.modules.system.service.ISysTenantService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.poi.ss.formula.functions.T;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 租户配置信息
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/sys/tenant")
|
||||
public class SysTenantController {
|
||||
|
||||
@Autowired
|
||||
private ISysTenantService sysTenantService;
|
||||
|
||||
/**
|
||||
* 获取列表数据
|
||||
* @param sysTenant
|
||||
* @param pageNo
|
||||
* @param pageSize
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
@PermissionData(pageComponent = "system/TenantList")
|
||||
@GetMapping("/page")
|
||||
public Results<IPage<SysTenant>> queryPageList(SysTenant sysTenant, @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
|
||||
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize, HttpServletRequest req) {
|
||||
Results<IPage<SysTenant>> result = new Results<>();
|
||||
QueryWrapper<SysTenant> queryWrapper = QueryGenerator.initQueryWrapper(sysTenant, req.getParameterMap());
|
||||
Page<SysTenant> page = new Page<>(pageNo, pageSize);
|
||||
IPage<SysTenant> pageList = sysTenantService.page(page, queryWrapper);
|
||||
result.setSuccess(true);
|
||||
result.setResult(pageList);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
// @RequestMapping(value = "/add", method = RequestMethod.POST)
|
||||
@PostMapping("/add")
|
||||
public Results<Object> add(@RequestBody SysTenant sysTenant) {
|
||||
if(sysTenantService.getById(sysTenant.getId())!=null){
|
||||
return Results.error("该编号已存在!");
|
||||
}
|
||||
|
||||
try {
|
||||
sysTenantService.save(sysTenant);
|
||||
return Results.OK("操作成功!");
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
return Results.error("操作失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
// @RequestMapping(value = "/edit", method = RequestMethod.PUT)
|
||||
@PostMapping("/edit")
|
||||
public Results<Object> edit(@RequestBody SysTenant tenant) {
|
||||
SysTenant sysTenant = sysTenantService.getById(tenant.getId());
|
||||
if(sysTenant==null) {
|
||||
return Results.error("未找到对应实体");
|
||||
}else {
|
||||
boolean ok = sysTenantService.updateById(tenant);
|
||||
if(ok) {
|
||||
return Results.OK("操作成功!");
|
||||
}
|
||||
}
|
||||
return Results.OK();
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id删除
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
// @RequestMapping(value = "/delete", method = RequestMethod.DELETE)
|
||||
@PostMapping("/delete")
|
||||
public Results<T> delete(@RequestBody Map<String,String> map) {
|
||||
String id = map.get("id");
|
||||
if(StringUtils.isBlank(id)){
|
||||
return Results.error("参数不识别!");
|
||||
}
|
||||
sysTenantService.removeTenantById(id);
|
||||
return Results.OK("删除成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
* @param map
|
||||
* @return
|
||||
*/
|
||||
// @RequestMapping(value = "/deleteBatch", method = RequestMethod.DELETE)
|
||||
@PostMapping("/deleteBatch")
|
||||
public Results<T> deleteBatch(@RequestBody Map<String, String> map) {
|
||||
String ids = map.get("ids");
|
||||
if(oConvertUtils.isEmpty(ids)) {
|
||||
return Results.error("未选中租户!");
|
||||
}else {
|
||||
String[] ls = ids.split(",");
|
||||
// 过滤掉已被引用的租户
|
||||
List<String> idList = new ArrayList<>();
|
||||
for (String id : ls) {
|
||||
int userCount = sysTenantService.countUserLinkTenant(id);
|
||||
if (userCount == 0) {
|
||||
idList.add(id);
|
||||
}
|
||||
}
|
||||
|
||||
if (!idList.isEmpty()) {
|
||||
sysTenantService.removeByIds(idList);
|
||||
if (ls.length == idList.size()) {
|
||||
return Results.OK("删除成功!");
|
||||
} else {
|
||||
return Results.OK("部分删除成功!(被引用的租户无法删除)");
|
||||
}
|
||||
}else {
|
||||
return Results.error("选择的租户都已被引用,无法删除!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id查询
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
// @RequestMapping(value = "/queryById", method = RequestMethod.GET)
|
||||
@GetMapping("/queryById")
|
||||
public Results<SysTenant> queryById(@RequestParam(name="id",required=true) String id) {
|
||||
SysTenant sysTenant = sysTenantService.getById(id);
|
||||
if(sysTenant==null) {
|
||||
return Results.error("未找到对应实体");
|
||||
}else {
|
||||
return Results.OK(sysTenant);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询有效的 租户数据
|
||||
* @return
|
||||
*/
|
||||
// @RequestMapping(value = "/queryList", method = RequestMethod.GET)
|
||||
@GetMapping("/queryList")
|
||||
public Results<List<SysTenant>> queryList(@RequestParam(name="ids",required=false) String ids) {
|
||||
LambdaQueryWrapper<SysTenant> query = new LambdaQueryWrapper<>();
|
||||
query.eq(SysTenant::getStatus, 1);
|
||||
if(oConvertUtils.isNotEmpty(ids)){
|
||||
query.in(SysTenant::getId, ids.split(","));
|
||||
}
|
||||
//此处查询忽略时间条件
|
||||
List<SysTenant> ls = sysTenantService.list(query);
|
||||
return Results.OK(ls);
|
||||
}
|
||||
}
|
||||
+243
@@ -0,0 +1,243 @@
|
||||
package com.jero.modules.system.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.jero.common.api.vo.Results;
|
||||
import com.jero.common.system.base.controller.JeroController;
|
||||
import com.jero.common.system.query.QueryGenerator;
|
||||
import com.jero.common.system.vo.LoginUser;
|
||||
import com.jero.common.util.SpringContextUtils;
|
||||
import com.jero.config.easypoi.EasyPoiDictHandlerImpl;
|
||||
import com.jero.modules.system.entity.SysUserAgent;
|
||||
import com.jero.modules.system.service.ISysUserAgentService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.poi.ss.formula.functions.T;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import cn.afterturn.easypoi.excel.ExcelImportUtil;
|
||||
import cn.afterturn.easypoi.entity.vo.NormalExcelConstants;
|
||||
import cn.afterturn.easypoi.excel.entity.ExportParams;
|
||||
import cn.afterturn.easypoi.excel.entity.ImportParams;
|
||||
import cn.afterturn.easypoi.view.EasypoiSingleExcelView;
|
||||
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;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Title: Controller
|
||||
* @Description: 用户代理人设置
|
||||
* @Author: jero-boot
|
||||
* @Date: 2019-04-17
|
||||
* @Version: V1.0
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/sys/sysUserAgent")
|
||||
@Slf4j
|
||||
public class SysUserAgentController {
|
||||
@Autowired
|
||||
private ISysUserAgentService sysUserAgentService;
|
||||
|
||||
@Value("${jero.path.upload}")
|
||||
private String upLoadPath;
|
||||
|
||||
private static final String ERROE_MSG = "未找到对应实体";
|
||||
/**
|
||||
* 分页列表查询
|
||||
* @param sysUserAgent
|
||||
* @param pageNo
|
||||
* @param pageSize
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/page")
|
||||
public Results<IPage<SysUserAgent>> queryPageList(SysUserAgent sysUserAgent,
|
||||
@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
|
||||
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
|
||||
HttpServletRequest req) {
|
||||
Results<IPage<SysUserAgent>> result = new Results<>();
|
||||
QueryWrapper<SysUserAgent> queryWrapper = QueryGenerator.initQueryWrapper(sysUserAgent, req.getParameterMap());
|
||||
Page<SysUserAgent> page = new Page<>(pageNo, pageSize);
|
||||
IPage<SysUserAgent> pageList = sysUserAgentService.page(page, queryWrapper);
|
||||
result.setSuccess(true);
|
||||
result.setResult(pageList);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
* @param sysUserAgent
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/add")
|
||||
public Results<Object> add(@RequestBody SysUserAgent sysUserAgent) {
|
||||
try {
|
||||
sysUserAgentService.save(sysUserAgent);
|
||||
return Results.OK("代理人设置成功!");
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(),e);
|
||||
return Results.error("操作失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
* @param sysUserAgent
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/edit")
|
||||
public Results<Object> edit(@RequestBody SysUserAgent sysUserAgent) {
|
||||
SysUserAgent sysUserAgentEntity = sysUserAgentService.getById(sysUserAgent.getId());
|
||||
if(sysUserAgentEntity==null) {
|
||||
return Results.error(ERROE_MSG);
|
||||
}else {
|
||||
boolean ok = sysUserAgentService.updateById(sysUserAgent);
|
||||
if(ok) {
|
||||
return Results.OK("代理人设置成功!");
|
||||
}
|
||||
}
|
||||
|
||||
return Results.OK();
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id删除
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/delete")
|
||||
public Results<Object> delete(@RequestParam(name="id",required=true) String id) {
|
||||
SysUserAgent sysUserAgent = sysUserAgentService.getById(id);
|
||||
if(sysUserAgent==null) {
|
||||
return Results.error(ERROE_MSG);
|
||||
}else {
|
||||
boolean ok = sysUserAgentService.removeById(id);
|
||||
if(ok) {
|
||||
return Results.OK("删除成功!");
|
||||
}
|
||||
}
|
||||
return Results.OK();
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
* @param map
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/deleteBatch")
|
||||
public Results<T> deleteBatch(@RequestBody Map<String, String> map) {
|
||||
String ids = map.get("ids");
|
||||
if(ids==null || "".equals(ids.trim())) {
|
||||
return Results.error("参数不识别!");
|
||||
}else {
|
||||
this.sysUserAgentService.removeByIds(Arrays.asList(ids.split(",")));
|
||||
return Results.OK("删除成功!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id查询
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/queryById")
|
||||
public Results<SysUserAgent> queryById(@RequestParam(name="id",required=true) String id) {
|
||||
SysUserAgent sysUserAgent = sysUserAgentService.getById(id);
|
||||
if(sysUserAgent==null) {
|
||||
return Results.error(ERROE_MSG);
|
||||
}else {
|
||||
return Results.OK(sysUserAgent);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过userName查询
|
||||
* @param userName
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/queryByUserName")
|
||||
public Results<SysUserAgent> queryByUserName(@RequestParam(name="userName",required=true) String userName) {
|
||||
LambdaQueryWrapper<SysUserAgent> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(SysUserAgent::getUserName, userName);
|
||||
SysUserAgent sysUserAgent = sysUserAgentService.getOne(queryWrapper);
|
||||
if(sysUserAgent==null) {
|
||||
return Results.error(ERROE_MSG);
|
||||
}else {
|
||||
return Results.OK(sysUserAgent);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出excel
|
||||
*
|
||||
* @param sysUserAgent
|
||||
* @param request
|
||||
*/
|
||||
@RequestMapping(value = "/exportXls")
|
||||
public ModelAndView exportXls(SysUserAgent sysUserAgent,HttpServletRequest request) {
|
||||
// Step.1 组装查询条件
|
||||
QueryWrapper<SysUserAgent> queryWrapper = QueryGenerator.initQueryWrapper(sysUserAgent, request.getParameterMap());
|
||||
//Step.2 AutoPoi 导出Excel
|
||||
ModelAndView mv = new ModelAndView(new EasypoiSingleExcelView());
|
||||
List<SysUserAgent> pageList = sysUserAgentService.list(queryWrapper);
|
||||
//导出文件名称
|
||||
mv.addObject(JeroController.FILE_NAME, "用户代理人设置列表");
|
||||
mv.addObject(JeroController.CLASS, SysUserAgent.class);
|
||||
LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
||||
ExportParams exportParams = new ExportParams("用户代理人设置列表数据", "导出人:"+user.getRealname(), "导出信息");
|
||||
exportParams.setDictHandler(SpringContextUtils.getApplicationContext().getBean(EasyPoiDictHandlerImpl.class));
|
||||
mv.addObject(JeroController.PARAMS, exportParams);
|
||||
mv.addObject(NormalExcelConstants.DATA_LIST, pageList);
|
||||
return mv;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过excel导入数据
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
* @return
|
||||
*/
|
||||
|
||||
@PostMapping("/importExcel")
|
||||
public Results<T> importExcel(HttpServletRequest request, HttpServletResponse response) {
|
||||
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
||||
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
|
||||
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
|
||||
MultipartFile file = entity.getValue();// 获取上传文件对象
|
||||
ImportParams params = new ImportParams();
|
||||
params.setDictHandler(SpringContextUtils.getApplicationContext().getBean(EasyPoiDictHandlerImpl.class));
|
||||
params.setTitleRows(2);
|
||||
params.setHeadRows(1);
|
||||
params.setNeedSave(true);
|
||||
try {
|
||||
List<SysUserAgent> listSysUserAgents = ExcelImportUtil.importExcel(file.getInputStream(), SysUserAgent.class, params);
|
||||
for (SysUserAgent sysUserAgentExcel : listSysUserAgents) {
|
||||
sysUserAgentService.save(sysUserAgentExcel);
|
||||
}
|
||||
return Results.OK("文件导入成功!数据行数:" + listSysUserAgents.size());
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(),e);
|
||||
return Results.error("文件导入失败!");
|
||||
} finally {
|
||||
try {
|
||||
file.getInputStream().close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return Results.error("文件导入失败!");
|
||||
}
|
||||
|
||||
}
|
||||
+1490
File diff suppressed because it is too large
Load Diff
+130
@@ -0,0 +1,130 @@
|
||||
package com.jero.modules.system.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.jero.common.api.vo.Results;
|
||||
import com.jero.common.constant.CacheConstant;
|
||||
import com.jero.common.constant.CommonConstant;
|
||||
import com.jero.common.system.api.ISysBaseAPI;
|
||||
import com.jero.common.system.util.JwtUtil;
|
||||
import com.jero.common.system.vo.LoginUser;
|
||||
import com.jero.common.util.RedisUtil;
|
||||
import com.jero.common.util.oConvertUtils;
|
||||
import com.jero.modules.base.service.BaseCommonService;
|
||||
import com.jero.modules.system.service.ISysUserService;
|
||||
import com.jero.modules.system.vo.SysUserOnlineVO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description: 在线用户
|
||||
* @Author: chenli
|
||||
* @Date: 2020-06-07
|
||||
* @Version: V1.0
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/sys/online")
|
||||
@Slf4j
|
||||
public class SysUserOnlineController {
|
||||
|
||||
@Autowired
|
||||
private RedisUtil redisUtil;
|
||||
|
||||
@Autowired
|
||||
public RedisTemplate<String, Object> redisTemplate;
|
||||
|
||||
@Autowired
|
||||
public ISysUserService userService;
|
||||
|
||||
@Autowired
|
||||
private ISysBaseAPI sysBaseAPI;
|
||||
|
||||
@Resource
|
||||
private BaseCommonService baseCommonService;
|
||||
|
||||
// @RequestMapping(value = "/list", method = RequestMethod.GET)
|
||||
@GetMapping("/list")
|
||||
public Results<Page<SysUserOnlineVO>> list(@RequestParam(name="username", required=false) String username, @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
|
||||
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize) {
|
||||
Collection<String> keys = redisTemplate.keys(CommonConstant.PREFIX_USER_TOKEN + "*");
|
||||
SysUserOnlineVO online;
|
||||
List<SysUserOnlineVO> onlineList = new ArrayList<>();
|
||||
for (String key : keys) {
|
||||
online = new SysUserOnlineVO();
|
||||
String token = (String) redisUtil.get(key);
|
||||
if (!StringUtils.isEmpty(token)){
|
||||
online.setToken(token);
|
||||
LoginUser loginUser = sysBaseAPI.getUserByName(JwtUtil.getUsername(token));
|
||||
BeanUtils.copyProperties(loginUser, online);
|
||||
if (StringUtils.isNotEmpty(username)) {
|
||||
if (StringUtils.equals(username, online.getUsername())) {
|
||||
onlineList.add(online);
|
||||
}
|
||||
} else {
|
||||
onlineList.add(online);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Page<SysUserOnlineVO> page = new Page<>(pageNo, pageSize);
|
||||
int count = onlineList.size();
|
||||
List<SysUserOnlineVO> pages = new ArrayList<>();
|
||||
//计算当前页第一条数据的下标
|
||||
int currId = pageNo>1 ? (pageNo-1)*pageSize:0;
|
||||
for (int i=0; i<pageSize && i<count - currId;i++){
|
||||
pages.add(onlineList.get(currId+i));
|
||||
}
|
||||
page.setSize(pageSize);
|
||||
page.setCurrent(pageNo);
|
||||
page.setTotal(count);
|
||||
//计算分页总页数
|
||||
page.setPages(count %10 == 0 ? count/10 :count/10+1);
|
||||
page.setRecords(pages);
|
||||
|
||||
Collections.reverse(onlineList);
|
||||
onlineList.removeAll(Collections.singleton(null));
|
||||
Results<Page<SysUserOnlineVO>> result = new Results<>();
|
||||
result.setSuccess(true);
|
||||
result.setResult(page);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 强退用户
|
||||
*/
|
||||
// @RequestMapping(value = "/forceLogout",method = RequestMethod.POST)
|
||||
@PostMapping("/forceLogout")
|
||||
public Results<Object> forceLogout(@RequestBody SysUserOnlineVO online) {
|
||||
//用户退出逻辑
|
||||
if(oConvertUtils.isEmpty(online.getToken())) {
|
||||
return Results.error("退出登录失败!");
|
||||
}
|
||||
String username = JwtUtil.getUsername(online.getToken());
|
||||
LoginUser sysUser = sysBaseAPI.getUserByName(username);
|
||||
if(sysUser!=null) {
|
||||
baseCommonService.addLog("强制: "+sysUser.getRealname()+"退出成功!", CommonConstant.LOG_TYPE_1, null,sysUser);
|
||||
log.info(" 强制 "+sysUser.getRealname()+"退出成功! ");
|
||||
//清空用户登录Token缓存
|
||||
redisUtil.del(CommonConstant.PREFIX_USER_TOKEN + online.getToken());
|
||||
//清空用户登录Shiro权限缓存
|
||||
redisUtil.del(CommonConstant.PREFIX_USER_SHIRO_CACHE + sysUser.getId());
|
||||
//清空用户的缓存信息(包括部门信息),例如sys:cache:user::<username>
|
||||
redisUtil.del(String.format("%s::%s", CacheConstant.SYS_USERS_CACHE, sysUser.getUsername()));
|
||||
//调用shiro的logout
|
||||
SecurityUtils.getSubject().logout();
|
||||
return Results.OK("退出登录成功!");
|
||||
}else {
|
||||
return Results.error("Token无效!");
|
||||
}
|
||||
}
|
||||
}
|
||||
+280
@@ -0,0 +1,280 @@
|
||||
package com.jero.modules.system.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.jero.common.api.vo.Results;
|
||||
import com.jero.common.constant.CommonConstant;
|
||||
import com.jero.common.system.util.JwtUtil;
|
||||
import com.jero.common.util.PasswordUtil;
|
||||
import com.jero.common.util.RedisUtil;
|
||||
import com.jero.common.util.oConvertUtils;
|
||||
import com.jero.modules.base.service.BaseCommonService;
|
||||
import com.jero.modules.system.entity.SysThirdAccount;
|
||||
import com.jero.modules.system.entity.SysUser;
|
||||
import com.jero.modules.system.model.ThirdLoginModel;
|
||||
import com.jero.modules.system.service.ISysThirdAccountService;
|
||||
import com.jero.modules.system.service.ISysUserService;
|
||||
import com.xkcoding.justauth.AuthRequestFactory;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.zhyd.oauth.model.AuthCallback;
|
||||
import me.zhyd.oauth.model.AuthResponse;
|
||||
import me.zhyd.oauth.request.AuthRequest;
|
||||
import me.zhyd.oauth.utils.AuthStateUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author scott
|
||||
* @since 2018-12-17
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping("/sys/thirdLogin")
|
||||
@Slf4j
|
||||
public class ThirdLoginController {
|
||||
@Autowired
|
||||
private ISysUserService sysUserService;
|
||||
@Autowired
|
||||
private ISysThirdAccountService sysThirdAccountService;
|
||||
|
||||
@Autowired
|
||||
private BaseCommonService baseCommonService;
|
||||
@Autowired
|
||||
private RedisUtil redisUtil;
|
||||
@Autowired
|
||||
private AuthRequestFactory factory;
|
||||
|
||||
private static final String TOKEN = "token";
|
||||
|
||||
@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 loginThird(@PathVariable("source") String source, AuthCallback callback,ModelMap modelMap) {
|
||||
log.info("第三方登录进入callback:" + source + " params:" + JSON.toJSONString(callback));
|
||||
AuthRequest authRequest = factory.get(source);
|
||||
AuthResponse<?> response = authRequest.login(callback);
|
||||
log.info(JSON.toJSONString(response));
|
||||
Results<JSONObject> result = new Results<>();
|
||||
if(response.getCode()==2000) {
|
||||
|
||||
JSONObject data = JSON.parseObject(JSON.toJSONString(response.getData()));
|
||||
String username = data.getString("username");
|
||||
String avatar = data.getString("avatar");
|
||||
String uuid = data.getString("uuid");
|
||||
//构造第三方登录信息存储对象
|
||||
ThirdLoginModel tlm = new ThirdLoginModel(source, uuid, username, avatar);
|
||||
//判断有没有这个人
|
||||
//update-begin-author:wangshuai date:20201118 for:修改成查询第三方账户表
|
||||
LambdaQueryWrapper<SysThirdAccount> query = new LambdaQueryWrapper<>();
|
||||
query.eq(SysThirdAccount::getThirdUserUuid, uuid);
|
||||
query.eq(SysThirdAccount::getThirdType, source);
|
||||
List<SysThirdAccount> thridList = sysThirdAccountService.list(query);
|
||||
SysThirdAccount user = null;
|
||||
if(thridList==null || thridList.isEmpty()) {
|
||||
//否则直接创建新账号
|
||||
user = saveThirdUser(tlm);
|
||||
}else {
|
||||
//已存在 只设置用户名 不设置头像
|
||||
user = thridList.get(0);
|
||||
}
|
||||
// 生成token
|
||||
//update-begin-author:wangshuai date:20201118 for:从第三方登录查询是否存在用户id,不存在绑定手机号
|
||||
if(oConvertUtils.isNotEmpty(user.getSysUserId())) {
|
||||
String sysUserId = user.getSysUserId();
|
||||
SysUser sysUser = sysUserService.getById(sysUserId);
|
||||
String token = saveToken(sysUser);
|
||||
modelMap.addAttribute(TOKEN, token);
|
||||
}else{
|
||||
modelMap.addAttribute(TOKEN, "绑定手机号,"+""+uuid);
|
||||
}
|
||||
//update-end-author:wangshuai date:20201118 for:从第三方登录查询是否存在用户id,不存在绑定手机号
|
||||
//update-begin--Author:wangshuai Date:20200729 for:接口在签名校验失败时返回失败的标识码 issues#1441--------------------
|
||||
}else{
|
||||
modelMap.addAttribute(TOKEN, "登录失败");
|
||||
}
|
||||
//update-end--Author:wangshuai Date:20200729 for:接口在签名校验失败时返回失败的标识码 issues#1441--------------------
|
||||
result.setSuccess(false);
|
||||
result.setMessage("第三方登录异常,请联系管理员");
|
||||
return "thirdLogin";
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建新账号
|
||||
* @param model
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/user/create")
|
||||
@ResponseBody
|
||||
public Results<String> thirdUserCreate(@RequestBody ThirdLoginModel model) {
|
||||
log.info("第三方登录创建新账号:" );
|
||||
Results<String> res = new Results<>();
|
||||
Object operateCode = redisUtil.get(CommonConstant.THIRD_LOGIN_CODE);
|
||||
if(operateCode==null || !operateCode.toString().equals(model.getOperateCode())){
|
||||
res.setSuccess(false);
|
||||
res.setMessage("校验失败");
|
||||
return res;
|
||||
}
|
||||
//创建新账号
|
||||
//update-begin-author:wangshuai date:20201118 for:修改成从第三方登录查出来的user_id,在查询用户表尽行token
|
||||
SysThirdAccount user = saveThirdUser(model);
|
||||
if(oConvertUtils.isNotEmpty(user.getSysUserId())){
|
||||
String sysUserId = user.getSysUserId();
|
||||
SysUser sysUser = sysUserService.getById(sysUserId);
|
||||
// 生成token
|
||||
String token = saveToken(sysUser);
|
||||
//update-end-author:wangshuai date:20201118 for:修改成从第三方登录查出来的user_id,在查询用户表尽行token
|
||||
res.setResult(token);
|
||||
res.setSuccess(true);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定账号 需要设置密码 需要走一遍校验
|
||||
* @param json
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/user/checkPassword")
|
||||
@ResponseBody
|
||||
public Results<String> checkPassword(@RequestBody JSONObject json) {
|
||||
Results<String> result = new Results<>();
|
||||
Object operateCode = redisUtil.get(CommonConstant.THIRD_LOGIN_CODE);
|
||||
if(operateCode==null || !operateCode.toString().equals(json.getString("operateCode"))){
|
||||
result.setSuccess(false);
|
||||
result.setMessage("校验失败");
|
||||
return result;
|
||||
}
|
||||
String username = json.getString("uuid");
|
||||
SysUser user = this.sysUserService.getUserByName(username);
|
||||
if(user==null){
|
||||
result.setMessage("用户未找到");
|
||||
result.setSuccess(false);
|
||||
return result;
|
||||
}
|
||||
String password = json.getString("password");
|
||||
String salt = user.getSalt();
|
||||
String passwordEncode = PasswordUtil.encrypt(user.getUsername(), password, salt);
|
||||
if(!passwordEncode.equals(user.getPassword())){
|
||||
result.setMessage("密码不正确");
|
||||
result.setSuccess(false);
|
||||
return result;
|
||||
}
|
||||
|
||||
sysUserService.updateById(user);
|
||||
result.setSuccess(true);
|
||||
// 生成token
|
||||
String token = saveToken(user);
|
||||
result.setResult(token);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建新用户
|
||||
* @param tlm 第三方登录信息
|
||||
*/
|
||||
private SysThirdAccount saveThirdUser(ThirdLoginModel tlm){
|
||||
SysThirdAccount user = new SysThirdAccount();
|
||||
user.setDelFlag(CommonConstant.DEL_FLAG_0);
|
||||
user.setStatus(1);
|
||||
user.setThirdType(tlm.getSource());
|
||||
user.setAvatar(tlm.getAvatar());
|
||||
user.setRealname(tlm.getUsername());
|
||||
user.setThirdUserUuid(tlm.getUuid());
|
||||
sysThirdAccountService.save(user);
|
||||
return user;
|
||||
}
|
||||
|
||||
private String saveToken(SysUser user) {
|
||||
// 生成token
|
||||
String token = JwtUtil.sign(user.getUsername(), user.getPassword());
|
||||
redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token);
|
||||
// 设置超时时间
|
||||
redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME / 1000);
|
||||
return token;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@GetMapping("/getLoginUser/{token}/{thirdType}")
|
||||
@ResponseBody
|
||||
public Results<JSONObject> getThirdLoginUser(@PathVariable("token") String token, @PathVariable("thirdType") String thirdType) {
|
||||
Results<JSONObject> result ;
|
||||
String username = JwtUtil.getUsername(token);
|
||||
|
||||
//1. 校验用户是否有效
|
||||
SysUser sysUser = sysUserService.getUserByName(username);
|
||||
result = sysUserService.checkUserIsEffective(sysUser);
|
||||
if(!result.isSuccess()) {
|
||||
return result;
|
||||
}
|
||||
//update-begin-author:wangshuai date:20201118 for:如果真实姓名和头像不存在就取第三方登录的
|
||||
LambdaQueryWrapper<SysThirdAccount> query = new LambdaQueryWrapper<>();
|
||||
query.eq(SysThirdAccount::getSysUserId,sysUser.getId());
|
||||
query.eq(SysThirdAccount::getThirdType,thirdType);
|
||||
SysThirdAccount account = sysThirdAccountService.getOne(query);
|
||||
if(oConvertUtils.isEmpty(sysUser.getRealname())){
|
||||
sysUser.setRealname(account.getRealname());
|
||||
}
|
||||
if(oConvertUtils.isEmpty(sysUser.getAvatar())){
|
||||
sysUser.setAvatar(account.getAvatar());
|
||||
}
|
||||
//update-end-author:wangshuai date:20201118 for:如果真实姓名和头像不存在就取第三方登录的
|
||||
JSONObject obj = new JSONObject();
|
||||
//用户登录信息
|
||||
obj.put("userInfo", sysUser);
|
||||
//token 信息
|
||||
obj.put(TOKEN, token);
|
||||
result.setResult(obj);
|
||||
result.setSuccess(true);
|
||||
result.setCode(200);
|
||||
baseCommonService.addLog("用户名: " + username + ",登录成功[第三方用户]!", CommonConstant.LOG_TYPE_1, null);
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* 第三方绑定手机号返回token
|
||||
*
|
||||
* @param jsonObject
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation("手机号登录接口")
|
||||
@PostMapping("/bindingThirdPhone")
|
||||
@ResponseBody
|
||||
public Results<String> bindingThirdPhone(@RequestBody JSONObject jsonObject) {
|
||||
Results<String> result = new Results<>();
|
||||
String phone = jsonObject.getString("mobile");
|
||||
String thirdUserUuid = jsonObject.getString("thirdUserUuid");
|
||||
//校验用户有效性
|
||||
SysUser sysUser = sysUserService.getUserByPhone(phone);
|
||||
if(sysUser != null){
|
||||
sysThirdAccountService.updateThirdUserId(sysUser,thirdUserUuid);
|
||||
}else{
|
||||
// 不存在手机号,创建用户
|
||||
String smscode = jsonObject.getString("captcha");
|
||||
Object code = redisUtil.get(phone);
|
||||
if (!smscode.equals(code)) {
|
||||
result.setMessage("手机验证码错误");
|
||||
result.setSuccess(false);
|
||||
return result;
|
||||
}
|
||||
//创建用户
|
||||
sysUser = sysThirdAccountService.createUser(phone,thirdUserUuid);
|
||||
}
|
||||
String token = saveToken(sysUser);
|
||||
result.setSuccess(true);
|
||||
result.setResult(token);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
package com.jero.modules.system.controller.job;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.jero.common.util.DateUtils;
|
||||
import com.jero.modules.message.entity.SysMessage;
|
||||
import com.jero.modules.message.handle.ISendMsgHandle;
|
||||
import com.jero.modules.message.handle.enums.SendMsgStatusEnum;
|
||||
import com.jero.modules.message.handle.enums.SendMsgTypeEnum;
|
||||
import com.jero.modules.message.service.ISysMessageService;
|
||||
import org.quartz.Job;
|
||||
import org.quartz.JobExecutionContext;
|
||||
import org.quartz.JobExecutionException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* 发送消息任务
|
||||
*/
|
||||
|
||||
@Slf4j
|
||||
public class SendMsgJob implements Job {
|
||||
|
||||
@Autowired
|
||||
private ISysMessageService sysMessageService;
|
||||
|
||||
@Override
|
||||
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
|
||||
|
||||
log.info(" jero-boot 发送消息任务 SendMsgJob ! 时间:" + DateUtils.getTimestamp());
|
||||
|
||||
// 1.读取消息中心数据,只查询未发送的和发送失败不超过次数的
|
||||
QueryWrapper<SysMessage> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("es_send_status", SendMsgStatusEnum.WAIT.getCode())
|
||||
.or(i -> i.eq("es_send_status", SendMsgStatusEnum.FAIL.getCode()).lt("es_send_num", 6));
|
||||
List<SysMessage> sysMessages = sysMessageService.list(queryWrapper);
|
||||
log.info(sysMessages.toString());
|
||||
// 2.根据不同的类型走不通的发送实现类
|
||||
for (SysMessage sysMessage : sysMessages) {
|
||||
ISendMsgHandle sendMsgHandle = null;
|
||||
try {
|
||||
if (sysMessage.getEsType().equals(SendMsgTypeEnum.EMAIL.getType())) {
|
||||
sendMsgHandle = (ISendMsgHandle) Class.forName(SendMsgTypeEnum.EMAIL.getImplClass()).newInstance();
|
||||
} else if (sysMessage.getEsType().equals(SendMsgTypeEnum.SMS.getType())) {
|
||||
sendMsgHandle = (ISendMsgHandle) Class.forName(SendMsgTypeEnum.SMS.getImplClass()).newInstance();
|
||||
} else if (sysMessage.getEsType().equals(SendMsgTypeEnum.WX.getType())) {
|
||||
sendMsgHandle = (ISendMsgHandle) Class.forName(SendMsgTypeEnum.WX.getImplClass()).newInstance();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(),e);
|
||||
}
|
||||
Integer sendNum = sysMessage.getEsSendNum();
|
||||
try {
|
||||
if(sendMsgHandle==null){
|
||||
throw new NullPointerException();
|
||||
}
|
||||
sendMsgHandle.SendMsg(sysMessage.getEsReceiver(), sysMessage.getEsTitle(),
|
||||
sysMessage.getEsContent());
|
||||
// 发送消息成功
|
||||
sysMessage.setEsSendStatus(SendMsgStatusEnum.SUCCESS.getCode());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
// 发送消息出现异常
|
||||
sysMessage.setEsSendStatus(SendMsgStatusEnum.FAIL.getCode());
|
||||
}
|
||||
sysMessage.setEsSendNum(++sendNum);
|
||||
// 发送结果回写到数据库
|
||||
sysMessageService.updateById(sysMessage);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
package com.jero.modules.system.dto;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.jero.common.aspect.annotation.Dict;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 用户表
|
||||
* </p>
|
||||
*
|
||||
* @Author scott
|
||||
* @since 2018-12-20
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Accessors(chain = true)
|
||||
public class SysUserDTO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 登录账号
|
||||
*/
|
||||
private String username;
|
||||
|
||||
/**
|
||||
* 真实姓名
|
||||
*/
|
||||
private String realname;
|
||||
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* md5密码盐
|
||||
*/
|
||||
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
|
||||
private String salt;
|
||||
|
||||
/**
|
||||
* 头像
|
||||
*/
|
||||
private String avatar;
|
||||
|
||||
/**
|
||||
* 生日
|
||||
*/
|
||||
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
||||
private Date birthday;
|
||||
|
||||
/**
|
||||
* 性别(1:男 2:女)
|
||||
*/
|
||||
@Dict(dicCode = "sex")
|
||||
private Integer sex;
|
||||
|
||||
/**
|
||||
* 电子邮件
|
||||
*/
|
||||
private String email;
|
||||
|
||||
/**
|
||||
* 电话
|
||||
*/
|
||||
private String phone;
|
||||
|
||||
/**
|
||||
* 部门code(当前选择登录部门)
|
||||
*/
|
||||
private String orgCode;
|
||||
|
||||
/**部门名称*/
|
||||
private transient String orgCodeTxt;
|
||||
|
||||
/**角色名称*/
|
||||
private transient String roleTxt;
|
||||
|
||||
/**
|
||||
* 状态(1:正常 2:冻结 )
|
||||
*/
|
||||
@Dict(dicCode = "user_status")
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 删除状态(0,正常,1已删除)
|
||||
*/
|
||||
@TableLogic
|
||||
private Integer delFlag;
|
||||
|
||||
/**
|
||||
* 工号,唯一键
|
||||
*/
|
||||
private String workNo;
|
||||
|
||||
/**
|
||||
* 座机号
|
||||
*/
|
||||
private String telephone;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
private String createBy;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 更新人
|
||||
*/
|
||||
private String updateBy;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private Date updateTime;
|
||||
/**
|
||||
* 同步工作流引擎1同步0不同步
|
||||
*/
|
||||
private Integer activitiSync;
|
||||
|
||||
/**
|
||||
* 身份(0 普通成员 1 上级)
|
||||
*/
|
||||
private Integer userIdentity;
|
||||
|
||||
/**
|
||||
* 负责部门
|
||||
*/
|
||||
@Dict(dictTable ="sys_depart",dicText = "depart_name",dicCode = "id")
|
||||
private String departIds;
|
||||
|
||||
/**
|
||||
* 多租户id配置,编辑用户的时候设置
|
||||
*/
|
||||
private String relTenantIds;
|
||||
|
||||
/**设备id uniapp推送用*/
|
||||
private String clientId;
|
||||
|
||||
private String userIds;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.jero.modules.system.dto;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 用户角色表
|
||||
* </p>
|
||||
*
|
||||
* @Author scott
|
||||
* @since 2018-12-21
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Accessors(chain = true)
|
||||
public class SysUserRoleDTO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
private String userId;
|
||||
|
||||
/**
|
||||
* 角色id
|
||||
*/
|
||||
private String roleId;
|
||||
|
||||
@TableField(exist = false)
|
||||
private String userIds;
|
||||
|
||||
public SysUserRoleDTO() {
|
||||
}
|
||||
|
||||
public SysUserRoleDTO(String userId, String roleId) {
|
||||
this.userId = userId;
|
||||
this.roleId = roleId;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package com.jero.modules.system.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
*
|
||||
* @Author lqt
|
||||
* @Date 2023/4/4 9:29
|
||||
* @Version 1.0
|
||||
*/
|
||||
@Data
|
||||
public class SuccessAndErrorLines implements Serializable {
|
||||
/**
|
||||
* 成功条数
|
||||
*/
|
||||
private Integer successLines;
|
||||
/**
|
||||
* 失败条数
|
||||
*/
|
||||
private Integer errorLines;
|
||||
}
|
||||
+145
@@ -0,0 +1,145 @@
|
||||
package com.jero.modules.system.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.jero.common.aspect.annotation.Dict;
|
||||
import lombok.Data;
|
||||
import cn.afterturn.easypoi.excel.annotation.Excel;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @Description: 系统通告表
|
||||
* @Author: jero-boot
|
||||
* @Date: 2019-01-02
|
||||
* @Version: V1.0
|
||||
*/
|
||||
@Data
|
||||
@TableName("sys_announcement")
|
||||
public class SysAnnouncement implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
private java.lang.String id;
|
||||
/**
|
||||
* 标题
|
||||
*/
|
||||
@Excel(name = "标题", width = 15)
|
||||
@TableField(condition = SqlCondition.LIKE)
|
||||
private java.lang.String titile;
|
||||
/**
|
||||
* 内容
|
||||
*/
|
||||
@Excel(name = "内容", width = 30)
|
||||
private java.lang.String msgContent;
|
||||
/**
|
||||
* 开始时间
|
||||
*/
|
||||
@Excel(name = "开始时间", width = 15, 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")
|
||||
private java.util.Date startTime;
|
||||
/**
|
||||
* 结束时间
|
||||
*/
|
||||
@Excel(name = "结束时间", width = 15, 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")
|
||||
private java.util.Date endTime;
|
||||
/**
|
||||
* 发布人
|
||||
*/
|
||||
@Excel(name = "发布人", width = 15)
|
||||
private java.lang.String sender;
|
||||
/**
|
||||
* 优先级(L低,M中,H高)
|
||||
*/
|
||||
@Excel(name = "优先级", width = 15, dict = "priority")
|
||||
@Dict(dicCode = "priority")
|
||||
private java.lang.String priority;
|
||||
|
||||
/**
|
||||
* 消息类型1:通知公告2:系统消息
|
||||
*/
|
||||
@Excel(name = "消息类型", width = 15, dict = "msg_category")
|
||||
@Dict(dicCode = "msg_category")
|
||||
private java.lang.String msgCategory;
|
||||
/**
|
||||
* 通告对象类型(USER:指定用户,ALL:全体用户)
|
||||
*/
|
||||
@Excel(name = "通告对象类型", width = 15, dict = "msg_type")
|
||||
@Dict(dicCode = "msg_type")
|
||||
private java.lang.String msgType;
|
||||
/**
|
||||
* 发布状态(0未发布,1已发布,2已撤销)
|
||||
*/
|
||||
@Excel(name = "发布状态", width = 15, dict = "send_status")
|
||||
@Dict(dicCode = "send_status")
|
||||
private java.lang.String sendStatus;
|
||||
/**
|
||||
* 发布时间
|
||||
*/
|
||||
@Excel(name = "发布时间", width = 15, 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")
|
||||
private java.util.Date sendTime;
|
||||
/**
|
||||
* 撤销时间
|
||||
*/
|
||||
@Excel(name = "撤销时间", width = 15, 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")
|
||||
private java.util.Date cancelTime;
|
||||
/**
|
||||
* 删除状态(0,正常,1已删除)
|
||||
*/
|
||||
private java.lang.String delFlag;
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
private java.lang.String createBy;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private java.util.Date createTime;
|
||||
/**
|
||||
* 更新人
|
||||
*/
|
||||
private java.lang.String updateBy;
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private java.util.Date updateTime;
|
||||
/**
|
||||
* 指定用户
|
||||
**/
|
||||
private java.lang.String userIds;
|
||||
/**
|
||||
* 业务类型(email:邮件 bpm:流程)
|
||||
*/
|
||||
private java.lang.String busType;
|
||||
/**
|
||||
* 业务id
|
||||
*/
|
||||
private java.lang.String busId;
|
||||
/**
|
||||
* 打开方式 组件:component 路由:url
|
||||
*/
|
||||
private java.lang.String openType;
|
||||
/**
|
||||
* 组件/路由 地址
|
||||
*/
|
||||
private java.lang.String openPage;
|
||||
/**
|
||||
* 摘要
|
||||
*/
|
||||
private java.lang.String msgAbstract;
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
package com.jero.modules.system.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @Description: 用户通告阅读标记表
|
||||
* @Author: jero-boot
|
||||
* @Date: 2019-02-21
|
||||
* @Version: V1.0
|
||||
*/
|
||||
@Data
|
||||
@TableName("sys_announcement_send")
|
||||
public class SysAnnouncementSend implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**id*/
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
private java.lang.String id;
|
||||
/**通告id*/
|
||||
private java.lang.String anntId;
|
||||
/**用户id*/
|
||||
private java.lang.String userId;
|
||||
/**阅读状态(0未读,1已读)*/
|
||||
private java.lang.String readFlag;
|
||||
/**阅读时间*/
|
||||
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
|
||||
private java.util.Date readTime;
|
||||
/**创建人*/
|
||||
private java.lang.String createBy;
|
||||
/**创建时间*/
|
||||
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
|
||||
private java.util.Date createTime;
|
||||
/**更新人*/
|
||||
private java.lang.String updateBy;
|
||||
/**更新时间*/
|
||||
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
|
||||
private java.util.Date updateTime;
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package com.jero.modules.system.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
import cn.afterturn.easypoi.excel.annotation.Excel;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @Description: 分类字典
|
||||
* @Author: jero-boot
|
||||
* @Date: 2019-05-29
|
||||
* @Version: V1.0
|
||||
*/
|
||||
@Data
|
||||
@TableName("sys_category")
|
||||
public class SysCategory implements Serializable,Comparable<SysCategory>{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**主键*/
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
private java.lang.String id;
|
||||
/**父级节点*/
|
||||
private java.lang.String pid;
|
||||
/**类型名称*/
|
||||
@Excel(name = "类型名称", width = 15)
|
||||
private java.lang.String name;
|
||||
/**类型编码*/
|
||||
@Excel(name = "类型编码", width = 15)
|
||||
private java.lang.String code;
|
||||
/**创建人*/
|
||||
private java.lang.String createBy;
|
||||
/**创建日期*/
|
||||
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
|
||||
private java.util.Date createTime;
|
||||
/**更新人*/
|
||||
private java.lang.String updateBy;
|
||||
/**更新日期*/
|
||||
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
|
||||
private java.util.Date updateTime;
|
||||
/**所属部门*/
|
||||
private java.lang.String sysOrgCode;
|
||||
/**是否有子节点*/
|
||||
@Excel(name = "是否有子节点(1:有)", width = 15)
|
||||
private java.lang.String hasChild;
|
||||
|
||||
@Override
|
||||
public int compareTo(SysCategory o) {
|
||||
//比较条件我们定的是按照code的长度升序
|
||||
// <0:当前对象比传入对象小。
|
||||
// =0:当前对象等于传入对象。
|
||||
// >0:当前对象比传入对象大。
|
||||
return this.code.length() - o.code.length();
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SysCategory [code=" + code + ", name=" + name + "]";
|
||||
}
|
||||
}
|
||||
+88
@@ -0,0 +1,88 @@
|
||||
package com.jero.modules.system.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
import cn.afterturn.easypoi.excel.annotation.Excel;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @Description: 编码校验规则
|
||||
* @Author: jero-boot
|
||||
* @Date: 2020-02-04
|
||||
* @Version: V1.0
|
||||
*/
|
||||
@Data
|
||||
@TableName("sys_check_rule")
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Accessors(chain = true)
|
||||
@ApiModel(value = "sys_check_rule对象", description = "编码校验规则")
|
||||
public class SysCheckRule {
|
||||
|
||||
/**
|
||||
* 主键id
|
||||
*/
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
@ApiModelProperty(value = "主键id")
|
||||
private String id;
|
||||
/**
|
||||
* 规则名称
|
||||
*/
|
||||
@Excel(name = "规则名称", width = 15)
|
||||
@ApiModelProperty(value = "规则名称")
|
||||
private String ruleName;
|
||||
/**
|
||||
* 规则Code
|
||||
*/
|
||||
@Excel(name = "规则Code", width = 15)
|
||||
@ApiModelProperty(value = "规则Code")
|
||||
private String ruleCode;
|
||||
/**
|
||||
* 规则JSON
|
||||
*/
|
||||
@Excel(name = "规则JSON", width = 15)
|
||||
@ApiModelProperty(value = "规则JSON")
|
||||
private String ruleJson;
|
||||
/**
|
||||
* 规则描述
|
||||
*/
|
||||
@Excel(name = "规则描述", width = 15)
|
||||
@ApiModelProperty(value = "规则描述")
|
||||
private String ruleDescription;
|
||||
/**
|
||||
* 更新人
|
||||
*/
|
||||
@Excel(name = "更新人", width = 15)
|
||||
@ApiModelProperty(value = "更新人")
|
||||
private 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 = "更新时间")
|
||||
private Date updateTime;
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
@Excel(name = "创建人", width = 15)
|
||||
@ApiModelProperty(value = "创建人")
|
||||
private 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 = "创建时间")
|
||||
private Date createTime;
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.jero.modules.system.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Accessors(chain = true)
|
||||
public class SysDataLog implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
private String id; //id'
|
||||
private String createBy; //创建人登录名称
|
||||
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
|
||||
private Date createTime; //创建日期
|
||||
private String updateBy; //更新人登录名称
|
||||
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
|
||||
private Date updateTime; //更新日期
|
||||
private String dataTable; //表名
|
||||
private String dataId; //数据ID
|
||||
private String dataContent; //数据内容
|
||||
private String dataVersion; //版本号
|
||||
}
|
||||
+120
@@ -0,0 +1,120 @@
|
||||
package com.jero.modules.system.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
import com.jero.common.aspect.annotation.Dict;
|
||||
import cn.afterturn.easypoi.excel.annotation.Excel;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
/**
|
||||
* @Description: 多数据源管理
|
||||
* @Author: jero-boot
|
||||
* @Date: 2019-12-25
|
||||
* @Version: V1.0
|
||||
*/
|
||||
@Data
|
||||
@TableName("sys_data_source")
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Accessors(chain = true)
|
||||
@ApiModel(value = "sys_data_source对象", description = "多数据源管理")
|
||||
public class SysDataSource {
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
@ApiModelProperty(value = "id")
|
||||
private java.lang.String id;
|
||||
/**
|
||||
* 数据源编码
|
||||
*/
|
||||
@Excel(name = "数据源编码", width = 15)
|
||||
@ApiModelProperty(value = "数据源编码")
|
||||
private java.lang.String code;
|
||||
/**
|
||||
* 数据源名称
|
||||
*/
|
||||
@Excel(name = "数据源名称", width = 15)
|
||||
@ApiModelProperty(value = "数据源名称")
|
||||
private java.lang.String name;
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
@Excel(name = "备注", width = 15)
|
||||
@ApiModelProperty(value = "备注")
|
||||
private java.lang.String remark;
|
||||
/**
|
||||
* 数据库类型
|
||||
*/
|
||||
@Dict(dicCode = "database_type")
|
||||
@Excel(name = "数据库类型", width = 15, dict = "database_type")
|
||||
@ApiModelProperty(value = "数据库类型")
|
||||
private java.lang.String dbType;
|
||||
/**
|
||||
* 驱动类
|
||||
*/
|
||||
@Excel(name = "驱动类", width = 15)
|
||||
@ApiModelProperty(value = "驱动类")
|
||||
private java.lang.String dbDriver;
|
||||
/**
|
||||
* 数据源地址
|
||||
*/
|
||||
@Excel(name = "数据源地址", width = 15)
|
||||
@ApiModelProperty(value = "数据源地址")
|
||||
private java.lang.String dbUrl;
|
||||
/**
|
||||
* 数据库名称
|
||||
*/
|
||||
@Excel(name = "数据库名称", width = 15)
|
||||
@ApiModelProperty(value = "数据库名称")
|
||||
private java.lang.String dbName;
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
@Excel(name = "用户名", width = 15)
|
||||
@ApiModelProperty(value = "用户名")
|
||||
private java.lang.String dbUsername;
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
@Excel(name = "密码", width = 15)
|
||||
@ApiModelProperty(value = "密码")
|
||||
private java.lang.String dbPassword;
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
@ApiModelProperty(value = "创建人")
|
||||
private java.lang.String createBy;
|
||||
/**
|
||||
* 创建日期
|
||||
*/
|
||||
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@ApiModelProperty(value = "创建日期")
|
||||
private java.util.Date createTime;
|
||||
/**
|
||||
* 更新人
|
||||
*/
|
||||
@ApiModelProperty(value = "更新人")
|
||||
private java.lang.String updateBy;
|
||||
/**
|
||||
* 更新日期
|
||||
*/
|
||||
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@ApiModelProperty(value = "更新日期")
|
||||
private java.util.Date updateTime;
|
||||
/**
|
||||
* 所属部门
|
||||
*/
|
||||
@Excel(name = "所属部门", width = 15)
|
||||
@ApiModelProperty(value = "所属部门")
|
||||
private java.lang.String sysOrgCode;
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
package com.jero.modules.system.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
import com.jero.common.aspect.annotation.Dict;
|
||||
import cn.afterturn.easypoi.excel.annotation.Excel;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 部门表
|
||||
* <p>
|
||||
*
|
||||
* @Author Steve
|
||||
* @Since 2019-01-22
|
||||
*/
|
||||
@Data
|
||||
@TableName("sys_depart")
|
||||
public class SysDepart implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**ID*/
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
private String id;
|
||||
/**父机构ID*/
|
||||
private String parentId;
|
||||
/**机构/部门名称*/
|
||||
@Excel(name="机构/部门名称",width=15)
|
||||
private String departName;
|
||||
/**英文名*/
|
||||
@Excel(name="英文名",width=15)
|
||||
private String departNameEn;
|
||||
/**缩写*/
|
||||
private String departNameAbbr;
|
||||
/**排序*/
|
||||
@Excel(name="排序",width=15)
|
||||
private Integer departOrder;
|
||||
/**描述*/
|
||||
@Excel(name="描述",width=15)
|
||||
private String description;
|
||||
/**机构类别 1公司,2组织机构,2岗位*/
|
||||
@Excel(name="机构类别",width=15, dict="org_category")
|
||||
private String orgCategory;
|
||||
/**机构类型*/
|
||||
private String orgType;
|
||||
/**机构编码*/
|
||||
@Excel(name="机构编码",width=15)
|
||||
private String orgCode;
|
||||
/**手机号*/
|
||||
@Excel(name="手机号",width=15)
|
||||
private String mobile;
|
||||
/**传真*/
|
||||
@Excel(name="传真",width=15)
|
||||
private String fax;
|
||||
/**地址*/
|
||||
@Excel(name="地址",width=15)
|
||||
private String address;
|
||||
/**备注*/
|
||||
@Excel(name="备注",width=15)
|
||||
private String memo;
|
||||
/**状态(1启用,0不启用)*/
|
||||
@Dict(dicCode = "depart_status")
|
||||
private String status;
|
||||
/**删除状态(0,正常,1已删除)*/
|
||||
@Dict(dicCode = "del_flag")
|
||||
private String delFlag;
|
||||
/**创建人*/
|
||||
private String createBy;
|
||||
/**创建日期*/
|
||||
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
|
||||
private Date createTime;
|
||||
/**更新人*/
|
||||
private String updateBy;
|
||||
/**更新日期*/
|
||||
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* 重写equals方法
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
if (!super.equals(o)) {
|
||||
return false;
|
||||
}
|
||||
SysDepart depart = (SysDepart) o;
|
||||
return Objects.equals(id, depart.id) &&
|
||||
Objects.equals(parentId, depart.parentId) &&
|
||||
Objects.equals(departName, depart.departName) &&
|
||||
Objects.equals(departNameEn, depart.departNameEn) &&
|
||||
Objects.equals(departNameAbbr, depart.departNameAbbr) &&
|
||||
Objects.equals(departOrder, depart.departOrder) &&
|
||||
Objects.equals(description, depart.description) &&
|
||||
Objects.equals(orgCategory, depart.orgCategory) &&
|
||||
Objects.equals(orgType, depart.orgType) &&
|
||||
Objects.equals(orgCode, depart.orgCode) &&
|
||||
Objects.equals(mobile, depart.mobile) &&
|
||||
Objects.equals(fax, depart.fax) &&
|
||||
Objects.equals(address, depart.address) &&
|
||||
Objects.equals(memo, depart.memo) &&
|
||||
Objects.equals(status, depart.status) &&
|
||||
Objects.equals(delFlag, depart.delFlag) &&
|
||||
Objects.equals(createBy, depart.createBy) &&
|
||||
Objects.equals(createTime, depart.createTime) &&
|
||||
Objects.equals(updateBy, depart.updateBy) &&
|
||||
Objects.equals(updateTime, depart.updateTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* 重写hashCode方法
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
return Objects.hash(super.hashCode(), id, parentId, departName,
|
||||
departNameEn, departNameAbbr, departOrder, description,orgCategory,
|
||||
orgType, orgCode, mobile, fax, address, memo, status,
|
||||
delFlag, createBy, createTime, updateBy, updateTime);
|
||||
}
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
package com.jero.modules.system.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
import cn.afterturn.easypoi.excel.annotation.Excel;
|
||||
|
||||
/**
|
||||
* @Description: 部门权限表
|
||||
* @Author: jero-boot
|
||||
* @Date: 2020-02-11
|
||||
* @Version: V1.0
|
||||
*/
|
||||
@Data
|
||||
@TableName("sys_depart_permission")
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Accessors(chain = true)
|
||||
@ApiModel(value="sys_depart_permission对象", description="部门权限表")
|
||||
public class SysDepartPermission {
|
||||
|
||||
/**id*/
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
@ApiModelProperty(value = "id")
|
||||
private java.lang.String id;
|
||||
/**部门id*/
|
||||
@Excel(name = "部门id", width = 15)
|
||||
@ApiModelProperty(value = "部门id")
|
||||
private java.lang.String departId;
|
||||
/**权限id*/
|
||||
@Excel(name = "权限id", width = 15)
|
||||
@ApiModelProperty(value = "权限id")
|
||||
private java.lang.String permissionId;
|
||||
/**数据规则id*/
|
||||
@ApiModelProperty(value = "数据规则id")
|
||||
private java.lang.String dataRuleIds;
|
||||
|
||||
public SysDepartPermission() {
|
||||
|
||||
}
|
||||
|
||||
public SysDepartPermission(String departId, String permissionId) {
|
||||
this.departId = departId;
|
||||
this.permissionId = permissionId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package com.jero.modules.system.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 字典表
|
||||
* </p>
|
||||
*
|
||||
* @Author zhangweijian
|
||||
* @since 2018-12-28
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Accessors(chain = true)
|
||||
public class SysDict implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* [预留字段,暂时无用]
|
||||
* 字典类型,0 string,1 number类型,2 boolean
|
||||
* 前端js对stirng类型和number类型 boolean 类型敏感,需要区分。在select 标签匹配的时候会用到
|
||||
* 默认为string类型
|
||||
*/
|
||||
private Integer type;
|
||||
|
||||
/**
|
||||
* 字典名称
|
||||
*/
|
||||
private String dictName;
|
||||
|
||||
/**
|
||||
* 字典编码
|
||||
*/
|
||||
private String dictCode;
|
||||
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 删除状态
|
||||
*/
|
||||
@TableLogic
|
||||
private Integer delFlag;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
private String createBy;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 更新人
|
||||
*/
|
||||
private String updateBy;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private Date updateTime;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package com.jero.modules.system.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.jero.common.aspect.annotation.Dict;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
import cn.afterturn.easypoi.excel.annotation.Excel;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* @Author zhangweijian
|
||||
* @since 2018-12-28
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Accessors(chain = true)
|
||||
public class SysDictItem implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 字典id
|
||||
*/
|
||||
private String dictId;
|
||||
|
||||
/**
|
||||
* 字典项文本
|
||||
*/
|
||||
@Excel(name = "字典项文本", width = 20)
|
||||
private String itemText;
|
||||
|
||||
/**
|
||||
* 字典项值
|
||||
*/
|
||||
@Excel(name = "字典项值", width = 30)
|
||||
private String itemValue;
|
||||
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
@Excel(name = "描述", width = 40)
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
@Excel(name = "排序", width = 15,type = 10)
|
||||
private Integer sortOrder;
|
||||
|
||||
|
||||
/**
|
||||
* 状态(1启用 0不启用)
|
||||
*/
|
||||
@Dict(dicCode = "dict_item_status")
|
||||
private Integer status;
|
||||
|
||||
private String createBy;
|
||||
|
||||
private Date createTime;
|
||||
|
||||
private String updateBy;
|
||||
|
||||
private Date updateTime;
|
||||
|
||||
|
||||
}
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
package com.jero.modules.system.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.jero.common.aspect.annotation.Dict;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
import cn.afterturn.easypoi.excel.annotation.Excel;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* @Author zhangweijian
|
||||
* @since 2018-12-28
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Accessors(chain = true)
|
||||
public class SysDictItemCore implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 字典id
|
||||
*/
|
||||
private String dictId;
|
||||
|
||||
/**
|
||||
* 字典编码
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
private String dictCode;
|
||||
|
||||
/**
|
||||
* 字典项文本
|
||||
*/
|
||||
@Excel(name = "字典项文本", width = 20)
|
||||
private String itemText;
|
||||
|
||||
/**
|
||||
* 字典项值
|
||||
*/
|
||||
@Excel(name = "字典项值", width = 30)
|
||||
private String itemValue;
|
||||
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
@Excel(name = "描述", width = 40)
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
@Excel(name = "排序", width = 15, type = 10)
|
||||
private Integer sortOrder;
|
||||
|
||||
|
||||
/**
|
||||
* 状态(1启用 0不启用)
|
||||
*/
|
||||
@Dict(dicCode = "dict_item_status")
|
||||
private Integer status;
|
||||
|
||||
private String createBy;
|
||||
|
||||
private Date createTime;
|
||||
|
||||
private String updateBy;
|
||||
|
||||
private Date updateTime;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
package com.jero.modules.system.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
import cn.afterturn.easypoi.excel.annotation.Excel;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
/**
|
||||
* @Description: 填值规则
|
||||
* @Author: jero-boot
|
||||
* @Date: 2019-11-07
|
||||
* @Version: V1.0
|
||||
*/
|
||||
@Data
|
||||
@TableName("sys_fill_rule")
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Accessors(chain = true)
|
||||
@ApiModel(value = "sys_fill_rule对象", description = "填值规则")
|
||||
public class SysFillRule {
|
||||
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
@ApiModelProperty(value = "主键ID")
|
||||
private java.lang.String id;
|
||||
/**
|
||||
* 规则名称
|
||||
*/
|
||||
@Excel(name = "规则名称", width = 15)
|
||||
@ApiModelProperty(value = "规则名称")
|
||||
private java.lang.String ruleName;
|
||||
/**
|
||||
* 规则Code
|
||||
*/
|
||||
@Excel(name = "规则Code", width = 15)
|
||||
@ApiModelProperty(value = "规则Code")
|
||||
private java.lang.String ruleCode;
|
||||
/**
|
||||
* 规则实现类
|
||||
*/
|
||||
@Excel(name = "规则实现类", width = 15)
|
||||
@ApiModelProperty(value = "规则实现类")
|
||||
private java.lang.String ruleClass;
|
||||
/**
|
||||
* 规则参数
|
||||
*/
|
||||
@Excel(name = "规则参数", width = 15)
|
||||
@ApiModelProperty(value = "规则参数")
|
||||
private java.lang.String ruleParams;
|
||||
/**
|
||||
* 修改人
|
||||
*/
|
||||
@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 = "修改时间")
|
||||
private java.util.Date updateTime;
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
@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 = "创建时间")
|
||||
private java.util.Date createTime;
|
||||
}
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
package com.jero.modules.system.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
import com.jero.common.aspect.annotation.Dict;
|
||||
import cn.afterturn.easypoi.excel.annotation.Excel;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @Description: gateway路由管理
|
||||
* @Author: jero-boot
|
||||
* @Date: 2020-05-26
|
||||
* @Version: V1.0
|
||||
*/
|
||||
@Data
|
||||
@TableName("sys_gateway_route")
|
||||
@Accessors(chain = true)
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@ApiModel(value="sys_gateway_route对象", description="gateway路由管理")
|
||||
public class SysGatewayRoute implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**主键*/
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
@ApiModelProperty(value = "主键")
|
||||
private String id;
|
||||
|
||||
/**routerKEy*/
|
||||
@ApiModelProperty(value = "路由ID")
|
||||
private String routerId;
|
||||
|
||||
/**服务名*/
|
||||
@Excel(name = "服务名", width = 15)
|
||||
@ApiModelProperty(value = "服务名")
|
||||
private String name;
|
||||
|
||||
/**服务地址*/
|
||||
@Excel(name = "服务地址", width = 15)
|
||||
@ApiModelProperty(value = "服务地址")
|
||||
private String uri;
|
||||
|
||||
/**
|
||||
* 断言配置
|
||||
*/
|
||||
private String predicates;
|
||||
|
||||
/**
|
||||
* 过滤配置
|
||||
*/
|
||||
private String filters;
|
||||
|
||||
/**是否忽略前缀0-否 1-是*/
|
||||
@Excel(name = "忽略前缀", width = 15)
|
||||
@ApiModelProperty(value = "忽略前缀")
|
||||
@Dict(dicCode = "yn")
|
||||
private Integer stripPrefix;
|
||||
|
||||
/**是否重试0-否 1-是*/
|
||||
@Excel(name = "是否重试", width = 15)
|
||||
@ApiModelProperty(value = "是否重试")
|
||||
@Dict(dicCode = "yn")
|
||||
private Integer retryable;
|
||||
|
||||
/**是否为保留数据:0-否 1-是*/
|
||||
@Excel(name = "保留数据", width = 15)
|
||||
@ApiModelProperty(value = "保留数据")
|
||||
@Dict(dicCode = "yn")
|
||||
private Integer persistable;
|
||||
|
||||
/**是否在接口文档中展示:0-否 1-是*/
|
||||
@Excel(name = "在接口文档中展示", width = 15)
|
||||
@ApiModelProperty(value = "在接口文档中展示")
|
||||
@Dict(dicCode = "yn")
|
||||
private Integer showApi;
|
||||
|
||||
/**状态 1有效 0无效*/
|
||||
@Excel(name = "状态", width = 15)
|
||||
@ApiModelProperty(value = "状态")
|
||||
@Dict(dicCode = "yn")
|
||||
private Integer status;
|
||||
|
||||
/**创建人*/
|
||||
@ApiModelProperty(value = "创建人")
|
||||
private String createBy;
|
||||
/**创建日期*/
|
||||
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
|
||||
@ApiModelProperty(value = "创建日期")
|
||||
private Date createTime;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
package com.jero.modules.system.entity;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import com.jero.common.aspect.annotation.Dict;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import java.io.Serializable;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 系统日志表
|
||||
* </p>
|
||||
*
|
||||
* @Author zhangweijian
|
||||
* @since 2018-12-26
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Accessors(chain = true)
|
||||
public class SysLog implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
private String createBy;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 更新人
|
||||
*/
|
||||
private String updateBy;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* 耗时
|
||||
*/
|
||||
private Long costTime;
|
||||
|
||||
/**
|
||||
* IP
|
||||
*/
|
||||
private String ip;
|
||||
|
||||
/**
|
||||
* 请求参数
|
||||
*/
|
||||
private String requestParam;
|
||||
|
||||
/**
|
||||
* 请求类型
|
||||
*/
|
||||
private String requestType;
|
||||
|
||||
/**
|
||||
* 请求路径
|
||||
*/
|
||||
private String requestUrl;
|
||||
/**
|
||||
* 请求方法
|
||||
*/
|
||||
private String method;
|
||||
|
||||
/**
|
||||
* 操作人用户名称
|
||||
*/
|
||||
private String username;
|
||||
/**
|
||||
* 操作人用户账户
|
||||
*/
|
||||
private String userid;
|
||||
/**
|
||||
* 操作详细日志
|
||||
*/
|
||||
private String logContent;
|
||||
|
||||
/**
|
||||
* 日志类型(1登录日志,2操作日志)
|
||||
*/
|
||||
@Dict(dicCode = "log_type")
|
||||
private Integer logType;
|
||||
|
||||
/**
|
||||
* 操作类型(1查询,2添加,3修改,4删除,5导入,6导出)
|
||||
*/
|
||||
@Dict(dicCode = "operate_type")
|
||||
private Integer operateType;
|
||||
|
||||
}
|
||||
+182
@@ -0,0 +1,182 @@
|
||||
package com.jero.modules.system.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.jero.common.aspect.annotation.Dict;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 菜单权限表
|
||||
* </p>
|
||||
*
|
||||
* @Author scott
|
||||
* @since 2018-12-21
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Accessors(chain = true)
|
||||
public class SysPermission implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 父id
|
||||
*/
|
||||
private String parentId;
|
||||
|
||||
/**
|
||||
* 菜单名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 菜单权限编码,例如:“sys:schedule:list,sys:schedule:info”,多个逗号隔开
|
||||
*/
|
||||
private String perms;
|
||||
/**
|
||||
* 权限策略1显示2禁用
|
||||
*/
|
||||
private String permsType;
|
||||
|
||||
/**
|
||||
* 菜单图标
|
||||
*/
|
||||
private String icon;
|
||||
|
||||
/**
|
||||
* 组件
|
||||
*/
|
||||
private String component;
|
||||
|
||||
/**
|
||||
* 组件名字
|
||||
*/
|
||||
private String componentName;
|
||||
|
||||
/**
|
||||
* 路径
|
||||
*/
|
||||
private String url;
|
||||
/**
|
||||
* 一级菜单跳转地址
|
||||
*/
|
||||
private String redirect;
|
||||
|
||||
/**
|
||||
* 菜单排序
|
||||
*/
|
||||
private Double sortNo;
|
||||
|
||||
/**
|
||||
* 类型(0:一级菜单;1:子菜单 ;2:按钮权限)
|
||||
*/
|
||||
@Dict(dicCode = "menu_type")
|
||||
private Integer menuType;
|
||||
|
||||
/**
|
||||
* 是否叶子节点: 1:是 0:不是
|
||||
*/
|
||||
@TableField(value="is_leaf")
|
||||
private boolean leaf;
|
||||
|
||||
/**
|
||||
* 是否路由菜单: 0:不是 1:是(默认值1)
|
||||
*/
|
||||
@TableField(value="is_route")
|
||||
private boolean route;
|
||||
|
||||
|
||||
/**
|
||||
* 是否缓存页面: 0:不是 1:是(默认值1)
|
||||
*/
|
||||
@TableField(value="keep_alive")
|
||||
private boolean keepAlive;
|
||||
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
private String createBy;
|
||||
|
||||
/**
|
||||
* 删除状态 0正常 1已删除
|
||||
*/
|
||||
private Integer delFlag;
|
||||
|
||||
/**
|
||||
* 是否配置菜单的数据权限 1是0否 默认0
|
||||
*/
|
||||
private Integer ruleFlag;
|
||||
|
||||
/**
|
||||
* 是否隐藏路由菜单: 0否,1是(默认值0)
|
||||
*/
|
||||
private boolean hidden;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 更新人
|
||||
*/
|
||||
private String updateBy;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private Date updateTime;
|
||||
|
||||
/**按钮权限状态(0无效1有效)*/
|
||||
private java.lang.String status;
|
||||
|
||||
/**alwaysShow*/
|
||||
private boolean alwaysShow;
|
||||
|
||||
/*update_begin author:wuxianquan date:20190908 for:实体增加字段 */
|
||||
/** 外链菜单打开方式 0/内部打开 1/外部打开 */
|
||||
private boolean internalOrExternal;
|
||||
/*update_end author:wuxianquan date:20190908 for:实体增加字段 */
|
||||
|
||||
public SysPermission() {
|
||||
|
||||
}
|
||||
public SysPermission(boolean index) {
|
||||
if(index) {
|
||||
this.id = "9502685863ab87f0ad1134142788a385";
|
||||
this.name="首页";
|
||||
this.component="dashboard/Analysis";
|
||||
this.componentName="dashboard-analysis";
|
||||
this.url="/dashboard/analysis";
|
||||
this.icon="home";
|
||||
this.menuType=0;
|
||||
this.sortNo=0.0;
|
||||
this.ruleFlag=0;
|
||||
this.delFlag=0;
|
||||
this.alwaysShow=false;
|
||||
this.route=true;
|
||||
this.keepAlive=true;
|
||||
this.leaf=true;
|
||||
this.hidden=false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
package com.jero.modules.system.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 菜单权限规则表
|
||||
* </p>
|
||||
*
|
||||
* @Author huangzhilin
|
||||
* @since 2019-03-29
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Accessors(chain = true)
|
||||
public class SysPermissionDataRule implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 对应的菜单id
|
||||
*/
|
||||
private String permissionId;
|
||||
|
||||
/**
|
||||
* 规则名称
|
||||
*/
|
||||
private String ruleName;
|
||||
|
||||
/**
|
||||
* 字段
|
||||
*/
|
||||
private String ruleColumn;
|
||||
|
||||
/**
|
||||
* 条件
|
||||
*/
|
||||
private String ruleConditions;
|
||||
|
||||
/**
|
||||
* 规则值
|
||||
*/
|
||||
private String ruleValue;
|
||||
|
||||
/**
|
||||
* 状态值 1有效 0无效
|
||||
*/
|
||||
private String status;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
private String createBy;
|
||||
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* 修改人
|
||||
*/
|
||||
private String updateBy;
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user