mirror of
https://github.com/jeecgboot/JeecgBoot.git
synced 2025-12-26 16:26:41 +08:00
jeecg-boot 1.1 稳定版本发布
This commit is contained in:
@ -5,12 +5,12 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||
|
||||
@EnableSwagger2
|
||||
@SpringBootApplication
|
||||
@EnableSwagger2
|
||||
public class JeecgApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.setProperty("spring.devtools.restart.enabled", "true");
|
||||
System.setProperty("spring.devtools.restart.enabled", "false");
|
||||
SpringApplication.run(JeecgApplication.class, args);
|
||||
}
|
||||
}
|
||||
@ -1,46 +0,0 @@
|
||||
package org.jeecg;
|
||||
|
||||
import org.jeecgframework.codegenerate.generate.impl.CodeGenerateOne;
|
||||
import org.jeecgframework.codegenerate.generate.pojo.TableVo;
|
||||
|
||||
/**
|
||||
* jeecg-boot代码生成器
|
||||
* 功能说明: 一键生成增删改查所有代码(包括:controller、service、dao、mapper、entity、vue)
|
||||
* 自定义模板: 模板位置在/src/main/resources/jeecg/code-template
|
||||
* @author scott
|
||||
*
|
||||
*/
|
||||
public class JeecgCodeGenerator {
|
||||
|
||||
/**
|
||||
* 代码生成器使用说明(单表模型)
|
||||
*
|
||||
* [1]、全局配置文件
|
||||
* src/main/resources/jeecg/jeecg_config.properties : 代码生成器基础配置文件(项目路径、根业务包路径)
|
||||
* src/main/resources/jeecg/jeecg_database.properties :代码生成器数据库配置文件(独立的数据源配置)
|
||||
*
|
||||
* [3]、页面使用说明:
|
||||
* 1. 页面生成路径: src/main/java/{业务包根路径}/{子业务包}/vue/
|
||||
* 2. 使用方法,手工复制到webstorm项目下面
|
||||
* 3. 配置访问菜单
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
System.out.println("----jeecg--------- Code------------- Generation -----[单表模型]------- 生成中。。。");
|
||||
|
||||
/**[2]、表配置参数 */
|
||||
TableVo table = new TableVo();
|
||||
//表名
|
||||
table.setTableName("jeecg_order_main");
|
||||
//表主键策略(目前只支持UUID)
|
||||
table.setPrimaryKeyPolicy("uuid");
|
||||
//子业务包名
|
||||
table.setEntityPackage("test2");
|
||||
//实体类名
|
||||
table.setEntityName("JeecgOrderMain");
|
||||
//功能描述
|
||||
table.setFtlDescription("订单");
|
||||
new CodeGenerateOne(table).generateCodeFile();
|
||||
System.out.println("----jeecg--------- Code------------- Generation -----[单表模型]------- 生成完成。。。");
|
||||
}
|
||||
|
||||
}
|
||||
18
jeecg-boot/src/main/java/org/jeecg/JeecgOneGUI.java
Normal file
18
jeecg-boot/src/main/java/org/jeecg/JeecgOneGUI.java
Normal file
@ -0,0 +1,18 @@
|
||||
package org.jeecg;
|
||||
|
||||
import org.jeecgframework.codegenerate.window.CodeWindow;
|
||||
|
||||
/**
|
||||
* @Title: 单表代码生成器入口
|
||||
* @author 张代浩
|
||||
* @site www.jeecg.org
|
||||
* @version:V1.0.1
|
||||
*/
|
||||
public class JeecgOneGUI {
|
||||
|
||||
/** 详细使用手册: http://jeecg-boot.mydoc.io/?t=338140 */
|
||||
public static void main(String[] args) {
|
||||
new CodeWindow().pack();
|
||||
}
|
||||
|
||||
}
|
||||
65
jeecg-boot/src/main/java/org/jeecg/JeecgOneToMainUtil.java
Normal file
65
jeecg-boot/src/main/java/org/jeecg/JeecgOneToMainUtil.java
Normal file
@ -0,0 +1,65 @@
|
||||
package org.jeecg;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.jeecgframework.codegenerate.generate.impl.CodeGenerateOneToMany;
|
||||
import org.jeecgframework.codegenerate.generate.pojo.onetomany.MainTableVo;
|
||||
import org.jeecgframework.codegenerate.generate.pojo.onetomany.SubTableVo;
|
||||
|
||||
/**
|
||||
* 代码生成器入口【一对多】
|
||||
* @author 张代浩
|
||||
* @site www.jeecg.org
|
||||
*
|
||||
*/
|
||||
public class JeecgOneToMainUtil {
|
||||
|
||||
/**
|
||||
* 一对多(父子表)数据模型,生成方法
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
//第一步:设置主表配置
|
||||
MainTableVo mainTable = new MainTableVo();
|
||||
mainTable.setTableName("jeecg_order_main");//表名
|
||||
mainTable.setEntityName("TestOrderMain"); //实体名
|
||||
mainTable.setEntityPackage("test2"); //包名
|
||||
mainTable.setFtlDescription("订单"); //描述
|
||||
|
||||
//第二步:设置子表集合配置
|
||||
List<SubTableVo> subTables = new ArrayList<SubTableVo>();
|
||||
//[1].子表一
|
||||
SubTableVo po = new SubTableVo();
|
||||
po.setTableName("jeecg_order_customer");//表名
|
||||
po.setEntityName("TestOrderCustom"); //实体名
|
||||
po.setEntityPackage("test2"); //包名
|
||||
po.setFtlDescription("客户明细"); //描述
|
||||
//子表外键参数配置
|
||||
/*说明:
|
||||
* a) 子表引用主表主键ID作为外键,外键字段必须以_ID结尾;
|
||||
* b) 主表和子表的外键字段名字,必须相同(除主键ID外);
|
||||
* c) 多个外键字段,采用逗号分隔;
|
||||
*/
|
||||
po.setForeignKeys(new String[]{"order_id"});
|
||||
subTables.add(po);
|
||||
//[2].子表二
|
||||
SubTableVo po2 = new SubTableVo();
|
||||
po2.setTableName("jeecg_order_ticket"); //表名
|
||||
po2.setEntityName("TestOrderTicket"); //实体名
|
||||
po2.setEntityPackage("test2"); //包名
|
||||
po2.setFtlDescription("产品明细"); //描述
|
||||
//子表外键参数配置
|
||||
/*说明:
|
||||
* a) 子表引用主表主键ID作为外键,外键字段必须以_ID结尾;
|
||||
* b) 主表和子表的外键字段名字,必须相同(除主键ID外);
|
||||
* c) 多个外键字段,采用逗号分隔;
|
||||
*/
|
||||
po2.setForeignKeys(new String[]{"order_id"});
|
||||
subTables.add(po2);
|
||||
mainTable.setSubTables(subTables);
|
||||
|
||||
//第三步:一对多(父子表)数据模型,代码生成
|
||||
new CodeGenerateOneToMany(mainTable,subTables).generateCodeFile();
|
||||
}
|
||||
}
|
||||
@ -20,23 +20,27 @@ public class Result<T> implements Serializable {
|
||||
/**
|
||||
* 成功标志
|
||||
*/
|
||||
private boolean success;
|
||||
private boolean success = true;
|
||||
|
||||
/**
|
||||
* 返回处理消息
|
||||
*/
|
||||
private String message;
|
||||
private String message = "操作成功!";
|
||||
|
||||
/**
|
||||
* 返回代码
|
||||
*/
|
||||
private Integer code;
|
||||
private Integer code = 0;
|
||||
|
||||
/**
|
||||
* 返回数据对象 data
|
||||
*/
|
||||
private T result;
|
||||
|
||||
public Result() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 时间戳
|
||||
*/
|
||||
@ -74,11 +78,11 @@ public class Result<T> implements Serializable {
|
||||
return r;
|
||||
}
|
||||
|
||||
public static Result<Object> ok(Object obj) {
|
||||
public static Result<Object> ok(Object data) {
|
||||
Result<Object> r = new Result<Object>();
|
||||
r.setSuccess(true);
|
||||
r.setCode(CommonConstant.SC_OK_200);
|
||||
r.setResult(obj);
|
||||
r.setResult(data);
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
126
jeecg-boot/src/main/java/org/jeecg/common/aspect/DictAspect.java
Normal file
126
jeecg-boot/src/main/java/org/jeecg/common/aspect/DictAspect.java
Normal file
@ -0,0 +1,126 @@
|
||||
package org.jeecg.common.aspect;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
import org.jeecg.common.aspect.annotation.Dict;
|
||||
import org.jeecg.modules.system.service.ISysDictService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* @Description: 字典aop类
|
||||
* @Author: dangzhenghui
|
||||
* @Date: 2019-3-17 21:50
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Aspect
|
||||
@Component
|
||||
@Slf4j
|
||||
public class DictAspect {
|
||||
private static final Logger logger = LoggerFactory.getLogger(DictAspect.class);
|
||||
@Autowired
|
||||
private ISysDictService dictService;
|
||||
// 定义切点Pointcut
|
||||
@Pointcut("execution(public * org.jeecg.modules.*.*.*Controller.*(..))")
|
||||
public void excudeService() {
|
||||
}
|
||||
|
||||
@Around("excudeService()")
|
||||
public Object doAround(ProceedingJoinPoint pjp) throws Throwable {
|
||||
long time1=System.currentTimeMillis();
|
||||
Object result = pjp.proceed();
|
||||
long time2=System.currentTimeMillis();
|
||||
log.debug("获取JSON数据 耗时:"+(time2-time1)+"ms");
|
||||
long start=System.currentTimeMillis();
|
||||
parseDictText(result);
|
||||
long end=System.currentTimeMillis();
|
||||
log.debug("解析注入JSON数据 耗时"+(end-start)+"ms");
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 本方法针对返回对象为Result 的IPage的分页列表数据进行动态字典注入
|
||||
* 字典注入实现 通过对实体类添加注解@dict 来标识需要的字典内容,字典分为单字典code即可 ,table字典 code table text配合使用与原来jeecg的用法相同
|
||||
* 示例为SysUser 字段为sex 添加了注解@Dict(dicCode = "sex") 会在字典服务立马查出来对应的text 然后在请求list的时候将这个字典text,已字段名称加_dictText形式返回到前端
|
||||
* 例输入当前返回值的就会多出一个sex_dictText字段
|
||||
* {
|
||||
* sex:1,
|
||||
* sex_dictText:"男"
|
||||
* }
|
||||
* 前端直接取值sext_dictText在table里面无需再进行前端的字典转换了
|
||||
* customRender:function (text) {
|
||||
* if(text==1){
|
||||
* return "男";
|
||||
* }else if(text==2){
|
||||
* return "女";
|
||||
* }else{
|
||||
* return text;
|
||||
* }
|
||||
* }
|
||||
* 目前vue是这么进行字典渲染到table上的多了就很麻烦了 这个直接在服务端渲染完成前端可以直接用
|
||||
* @param result
|
||||
*/
|
||||
private void parseDictText(Object result) {
|
||||
if (result instanceof Result) {
|
||||
if (((Result) result).getResult() instanceof IPage) {
|
||||
List<JSONObject> items = new ArrayList<>();
|
||||
for (Object record : ((IPage) ((Result) result).getResult()).getRecords()) {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
String json="{}";
|
||||
try {
|
||||
//解决@JsonFormat注解解析不了的问题详见SysAnnouncement类的@JsonFormat
|
||||
json = mapper.writeValueAsString(record);
|
||||
} catch (JsonProcessingException e) {
|
||||
logger.error("json解析失败"+e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
JSONObject item = JSONObject.parseObject(json);
|
||||
for (Field field : record.getClass().getDeclaredFields()) {
|
||||
if (field.getAnnotation(Dict.class) != null) {
|
||||
String code = field.getAnnotation(Dict.class).dicCode();
|
||||
String text = field.getAnnotation(Dict.class).dicText();
|
||||
String table = field.getAnnotation(Dict.class).dictTable();
|
||||
String key = String.valueOf(item.get(field.getName()));
|
||||
String textValue=null;
|
||||
if (!StringUtils.isEmpty(table)){
|
||||
textValue= dictService.queryTableDictTextByKey(table,text,code,key);
|
||||
}else {
|
||||
textValue = dictService.queryDictTextByKey(code, key);
|
||||
}
|
||||
item.put(field.getName() + "_dictText", textValue);
|
||||
}
|
||||
//date类型默认转换string格式化日期
|
||||
if (field.getType().getName().equals("java.util.Date")&&field.getAnnotation(JsonFormat.class)==null&&item.get(field.getName())!=null){
|
||||
SimpleDateFormat aDate=new SimpleDateFormat("yyyy-mm-dd HH:mm:ss");
|
||||
item.put(field.getName(), aDate.format(new Date((Long) item.get(field.getName()))));
|
||||
}
|
||||
}
|
||||
items.add(item);
|
||||
}
|
||||
((IPage) ((Result) result).getResult()).setRecords(items);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,175 @@
|
||||
package org.jeecg.common.aspect;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
import org.jeecg.common.aspect.annotation.PermissionData;
|
||||
import org.jeecg.common.util.SpringContextUtils;
|
||||
import org.jeecg.common.util.oConvertUtils;
|
||||
import org.jeecg.modules.shiro.authc.util.JwtUtil;
|
||||
import org.jeecg.modules.system.entity.SysPermission;
|
||||
import org.jeecg.modules.system.entity.SysPermissionDataRule;
|
||||
import org.jeecg.modules.system.model.SysUserCacheInfo;
|
||||
import org.jeecg.modules.system.service.ISysPermissionDataRuleService;
|
||||
import org.jeecg.modules.system.service.ISysPermissionService;
|
||||
import org.jeecg.modules.system.service.ISysUserService;
|
||||
import org.jeecg.modules.system.util.JeecgDataAutorUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.AntPathMatcher;
|
||||
import org.springframework.util.PathMatcher;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* 数据权限切面处理类
|
||||
* 当被请求的方法有注解PermissionData时,会在往当前request中写入数据权限信息
|
||||
* @date 2019年4月10日
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Aspect
|
||||
@Component
|
||||
@Slf4j
|
||||
public class PermissionDataAspect {
|
||||
|
||||
@Autowired
|
||||
private ISysPermissionService sysPermissionService;
|
||||
|
||||
@Autowired
|
||||
private ISysPermissionDataRuleService sysPermissionDataRuleService;
|
||||
|
||||
@Autowired
|
||||
private ISysUserService sysUserService;
|
||||
|
||||
@Pointcut("@annotation(org.jeecg.common.aspect.annotation.PermissionData)")
|
||||
public void pointCut() {
|
||||
|
||||
}
|
||||
|
||||
@Around("pointCut()")
|
||||
public Object arround(ProceedingJoinPoint point) throws Throwable{
|
||||
HttpServletRequest request = SpringContextUtils.getHttpServletRequest();
|
||||
MethodSignature signature = (MethodSignature) point.getSignature();
|
||||
Method method = signature.getMethod();
|
||||
PermissionData pd = method.getAnnotation(PermissionData.class);
|
||||
String component = pd.pageComponent();
|
||||
SysPermission currentSyspermission=null;
|
||||
if(oConvertUtils.isNotEmpty(component)) {
|
||||
//1.通过注解属性pageComponent 获取菜单
|
||||
LambdaQueryWrapper<SysPermission> query = new LambdaQueryWrapper<SysPermission>();
|
||||
query.eq(SysPermission::getDelFlag,0);
|
||||
query.eq(SysPermission::getComponent, component);
|
||||
currentSyspermission = sysPermissionService.getOne(query);
|
||||
}else {
|
||||
String requestMethod = request.getMethod();
|
||||
String requestPath = request.getRequestURI().substring(request.getContextPath().length());
|
||||
requestPath = filterUrl(requestPath);
|
||||
log.info("拦截请求>>"+requestPath+";请求类型>>"+requestMethod);
|
||||
//1.直接通过前端请求地址查询菜单
|
||||
LambdaQueryWrapper<SysPermission> query = new LambdaQueryWrapper<SysPermission>();
|
||||
query.eq(SysPermission::getMenuType,2);
|
||||
query.eq(SysPermission::getDelFlag,0);
|
||||
query.eq(SysPermission::getUrl, requestPath);
|
||||
currentSyspermission = sysPermissionService.getOne(query);
|
||||
//2.未找到 再通过正则匹配获取菜单
|
||||
if(currentSyspermission==null) {
|
||||
String regUrl = getRegexpUrl(requestPath);
|
||||
if(regUrl!=null) {
|
||||
currentSyspermission = sysPermissionService.getOne(new LambdaQueryWrapper<SysPermission>().eq(SysPermission::getMenuType,2).eq(SysPermission::getUrl, regUrl).eq(SysPermission::getDelFlag,0));
|
||||
}
|
||||
}
|
||||
}
|
||||
//3.通过用户名+菜单ID 找到权限配置信息 放到request中去
|
||||
if(currentSyspermission!=null) {
|
||||
String username = JwtUtil.getUserNameByToken(request);
|
||||
List<SysPermissionDataRule> dataRules = sysPermissionDataRuleService.queryPermissionDataRules(username, currentSyspermission.getId());
|
||||
if(dataRules!=null && dataRules.size()>0) {
|
||||
JeecgDataAutorUtils.installDataSearchConditon(request, dataRules);
|
||||
|
||||
//TODO 此处将用户信息查找出来放到request中实属无奈 可以优化
|
||||
SysUserCacheInfo userinfo = sysUserService.getCacheUser(username);
|
||||
JeecgDataAutorUtils.installUserInfo(request, userinfo);
|
||||
}
|
||||
}
|
||||
|
||||
return point.proceed();
|
||||
}
|
||||
|
||||
private String filterUrl(String requestPath){
|
||||
String url = "";
|
||||
if(oConvertUtils.isNotEmpty(requestPath)){
|
||||
url = requestPath.replace("\\", "/");
|
||||
url = requestPath.replace("//", "/");
|
||||
if(url.indexOf("//")>=0){
|
||||
url = filterUrl(url);
|
||||
}
|
||||
if(url.startsWith("/")){
|
||||
url=url.substring(1);
|
||||
}
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取请求地址
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
private String getJgAuthRequsetPath(HttpServletRequest request) {
|
||||
String queryString = request.getQueryString();
|
||||
String requestPath = request.getRequestURI();
|
||||
if(oConvertUtils.isNotEmpty(queryString)){
|
||||
requestPath += "?" + queryString;
|
||||
}
|
||||
if (requestPath.indexOf("&") > -1) {// 去掉其他参数(保留一个参数) 例如:loginController.do?login
|
||||
requestPath = requestPath.substring(0, requestPath.indexOf("&"));
|
||||
}
|
||||
if(requestPath.indexOf("=")!=-1){
|
||||
if(requestPath.indexOf(".do")!=-1){
|
||||
requestPath = requestPath.substring(0,requestPath.indexOf(".do")+3);
|
||||
}else{
|
||||
requestPath = requestPath.substring(0,requestPath.indexOf("?"));
|
||||
}
|
||||
}
|
||||
requestPath = requestPath.substring(request.getContextPath().length() + 1);// 去掉项目路径
|
||||
return filterUrl(requestPath);
|
||||
}
|
||||
|
||||
private boolean moHuContain(List<String> list,String key){
|
||||
for(String str : list){
|
||||
if(key.contains(str)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 匹配前端传过来的地址 匹配成功返回正则地址
|
||||
* AntPathMatcher匹配地址
|
||||
*()* 匹配0个或多个字符
|
||||
*()**匹配0个或多个目录
|
||||
*/
|
||||
private String getRegexpUrl(String url) {
|
||||
List<String> list = sysPermissionService.queryPermissionUrlWithStar();
|
||||
if(list!=null && list.size()>0) {
|
||||
for (String p : list) {
|
||||
PathMatcher matcher = new AntPathMatcher();
|
||||
if(matcher.match(p, url)) {
|
||||
return p;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,42 @@
|
||||
package org.jeecg.common.aspect.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* 类描述: 字典注解
|
||||
* 作 者: dangzhenghui
|
||||
* 日 期: 2019年03月17日-下午9:37:16
|
||||
*/
|
||||
@Target(ElementType.FIELD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Dict {
|
||||
/**
|
||||
* 方法描述: 数据code
|
||||
* 作 者: dangzhenghui
|
||||
* 日 期: 2019年03月17日-下午9:37:16
|
||||
*
|
||||
* @return 返回类型: String
|
||||
*/
|
||||
String dicCode();
|
||||
|
||||
/**
|
||||
* 方法描述: 数据Text
|
||||
* 作 者: dangzhenghui
|
||||
* 日 期: 2019年03月17日-下午9:37:16
|
||||
*
|
||||
* @return 返回类型: String
|
||||
*/
|
||||
String dicText() default "";
|
||||
|
||||
/**
|
||||
* 方法描述: 数据字典表
|
||||
* 作 者: dangzhenghui
|
||||
* 日 期: 2019年03月17日-下午9:37:16
|
||||
*
|
||||
* @return 返回类型: String
|
||||
*/
|
||||
String dictTable() default "";
|
||||
}
|
||||
@ -0,0 +1,25 @@
|
||||
package org.jeecg.common.aspect.annotation;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* 数据权限注解
|
||||
* @author taoyan
|
||||
* @date 2019年4月11日
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.TYPE,ElementType.METHOD})
|
||||
@Documented
|
||||
public @interface PermissionData {
|
||||
String value() default "";
|
||||
|
||||
|
||||
/**
|
||||
* 配置菜单的组件路径,用于数据权限
|
||||
*/
|
||||
String pageComponent() default "";
|
||||
}
|
||||
@ -41,7 +41,7 @@ public interface CommonConstant {
|
||||
|
||||
public static String PREFIX_USER_ROLE = "PREFIX_USER_ROLE";
|
||||
public static String PREFIX_USER_PERMISSION = "PREFIX_USER_PERMISSION ";
|
||||
public static int TOKEN_EXPIRE_TIME = 3600;
|
||||
public static int TOKEN_EXPIRE_TIME = 3600; //3600秒即是一小时
|
||||
|
||||
public static String PREFIX_USER_TOKEN = "PREFIX_USER_TOKEN ";
|
||||
|
||||
|
||||
@ -0,0 +1,103 @@
|
||||
package org.jeecg.common.constant;
|
||||
/**
|
||||
* 数据库上下文常量
|
||||
*/
|
||||
public interface DataBaseConstant {
|
||||
|
||||
//*********系统上下文变量****************************************
|
||||
/**
|
||||
* 数据-所属公司编码
|
||||
*/
|
||||
public static final String SYS_COMPANY_CODE = "sysCompanyCode";
|
||||
/**
|
||||
* 数据-所属公司编码
|
||||
*/
|
||||
public static final String SYS_COMPANY_CODE_TABLE = "sys_company_code";
|
||||
/**
|
||||
* 数据-所属机构编码
|
||||
*/
|
||||
public static final String SYS_ORG_CODE = "sysOrgCode";
|
||||
/**
|
||||
* 数据-所属机构编码
|
||||
*/
|
||||
public static final String SYS_ORG_CODE_TABLE = "sys_org_code";
|
||||
/**
|
||||
* 数据-系统用户编码(对应登录用户账号)
|
||||
*/
|
||||
public static final String SYS_USER_CODE = "sysUserCode";
|
||||
/**
|
||||
* 数据-系统用户编码(对应登录用户账号)
|
||||
*/
|
||||
public static final String SYS_USER_CODE_TABLE = "sys_user_code";
|
||||
|
||||
/**
|
||||
* 登录用户真实姓名
|
||||
*/
|
||||
public static final String SYS_USER_NAME = "sysUserName";
|
||||
/**
|
||||
* 登录用户真实姓名
|
||||
*/
|
||||
public static final String SYS_USER_NAME_TABLE = "sys_user_name";
|
||||
/**
|
||||
* 系统日期"yyyy-MM-dd"
|
||||
*/
|
||||
public static final String SYS_DATE = "sysDate";
|
||||
/**
|
||||
* 系统日期"yyyy-MM-dd"
|
||||
*/
|
||||
public static final String SYS_DATE_TABLE = "sys_date";
|
||||
/**
|
||||
* 系统时间"yyyy-MM-dd HH:mm"
|
||||
*/
|
||||
public static final String SYS_TIME = "sysTime";
|
||||
/**
|
||||
* 系统时间"yyyy-MM-dd HH:mm"
|
||||
*/
|
||||
public static final String SYS_TIME_TABLE = "sys_time";
|
||||
//*********系统上下文变量****************************************
|
||||
|
||||
|
||||
//*********系统建表标准字段****************************************
|
||||
/**
|
||||
* 创建者登录名称
|
||||
*/
|
||||
public static final String CREATE_BY_TABLE = "create_by";
|
||||
/**
|
||||
* 创建者登录名称
|
||||
*/
|
||||
public static final String CREATE_BY = "createBy";
|
||||
/**
|
||||
* 创建日期时间
|
||||
*/
|
||||
public static final String CREATE_TIME_TABLE = "create_time";
|
||||
/**
|
||||
* 创建日期时间
|
||||
*/
|
||||
public static final String CREATE_TIME = "createTime";
|
||||
/**
|
||||
* 更新用户登录名称
|
||||
*/
|
||||
public static final String UPDATE_BY_TABLE = "update_by";
|
||||
/**
|
||||
* 更新用户登录名称
|
||||
*/
|
||||
public static final String UPDATE_BY = "updateBy";
|
||||
/**
|
||||
* 更新日期时间
|
||||
*/
|
||||
public static final String UPDATE_TIME = "updateTime";
|
||||
/**
|
||||
* 更新日期时间
|
||||
*/
|
||||
public static final String UPDATE_TIME_TABLE = "update_time";
|
||||
|
||||
/**
|
||||
* 业务流程状态
|
||||
*/
|
||||
public static final String BPM_STATUS = "bpmStatus";
|
||||
/**
|
||||
* 业务流程状态
|
||||
*/
|
||||
public static final String BPM_STATUS_TABLE = "bpm_status";
|
||||
//*********系统建表标准字段****************************************
|
||||
}
|
||||
@ -0,0 +1,140 @@
|
||||
package org.jeecg.common.jsonschema;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
/**
|
||||
* 验证通用属性
|
||||
*/
|
||||
public abstract class CommonProperty implements Serializable{
|
||||
|
||||
private static final long serialVersionUID = -426159949502493187L;
|
||||
|
||||
|
||||
protected String key;
|
||||
|
||||
|
||||
/**
|
||||
* <p>此关键字的值必须是字符串或数组。如果它是一个数组,那么数组的元素必须是字符串,并且必须是唯一的。
|
||||
* <p>字符串值必须是六种基本类型之一(“null”,“boolean”,“object”,“array”,“number”或“string”),或“integer”,它匹配任何数字,零分数部分。
|
||||
* <p>当且仅当实例位于为此关键字列出的任何集合中时,实例才会验证。
|
||||
*
|
||||
*/
|
||||
protected String type;
|
||||
|
||||
/**
|
||||
* 对应JsonSchema的enum
|
||||
* <p>该关键字的值必须是一个数组。这个数组应该至少有一个元素。数组中的元素应该是唯一的。如果实例的值等于此关键字的数组值中的某个元素,则实例将对此关键字成功验证。
|
||||
* 数组中的元素可以是任何值,包括null
|
||||
*
|
||||
* {
|
||||
* "type": "string",
|
||||
* "enum": ["1", "2", "3"] 需要的话可以通过这个include转一下
|
||||
* }
|
||||
*/
|
||||
protected List<Map<String,Object>> include;
|
||||
|
||||
/**
|
||||
* 对应JsonSchema的const
|
||||
* <p>此关键字的值可以是任何类型,包括null。
|
||||
* 如果实例的值等于关键字的值,则实例将针对此关键字成功验证。
|
||||
*/
|
||||
protected Object constant;
|
||||
|
||||
//三个自定义 属性
|
||||
protected String view;// 展示类型
|
||||
protected String title;//数据库字段备注
|
||||
protected Integer order;//字段显示排序
|
||||
|
||||
public String getView() {
|
||||
return view;
|
||||
}
|
||||
|
||||
public void setView(String view) {
|
||||
this.view = view;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public List<Map<String, Object>> getInclude() {
|
||||
return include;
|
||||
}
|
||||
|
||||
public void setInclude(List<Map<String, Object>> include) {
|
||||
this.include = include;
|
||||
}
|
||||
|
||||
public Object getConstant() {
|
||||
return constant;
|
||||
}
|
||||
|
||||
public void setConstant(Object constant) {
|
||||
this.constant = constant;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public Integer getOrder() {
|
||||
return order;
|
||||
}
|
||||
|
||||
public void setOrder(Integer order) {
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回一个map有两个key
|
||||
* <P>key ---> Property JSON的key
|
||||
* <P>prop --> JSON object
|
||||
* @return
|
||||
*/
|
||||
public abstract Map<String,Object> getPropertyJson();
|
||||
|
||||
public JSONObject getCommonJson() {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("type", type);
|
||||
if(include!=null && include.size()>0) {
|
||||
json.put("enum", include);
|
||||
}
|
||||
if(constant!=null) {
|
||||
json.put("const", constant);
|
||||
}
|
||||
if(title!=null) {
|
||||
json.put("title", title);
|
||||
}
|
||||
if(order!=null) {
|
||||
json.put("order", order);
|
||||
}
|
||||
if(view==null) {
|
||||
json.put("view", "input");
|
||||
}else {
|
||||
json.put("view", view);
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,87 @@
|
||||
package org.jeecg.common.jsonschema;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* JsonSchema 模式类
|
||||
* < http://json-schema.org/draft-07/schema# >
|
||||
*/
|
||||
public class JsonSchemaDescrip implements Serializable{
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 7682073117441544718L;
|
||||
|
||||
|
||||
private String $schema = "http://json-schema.org/draft-07/schema#";
|
||||
|
||||
/**
|
||||
* 用它给我们的模式提供了标题。
|
||||
*/
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 关于模式的描述。
|
||||
*/
|
||||
private String description;
|
||||
|
||||
/**
|
||||
*type 关键字在我们的 JSON 数据上定义了第一个约束:必须是一个 JSON 对象。 可以直接设置成object
|
||||
*/
|
||||
private String type;
|
||||
|
||||
private List<String> required;
|
||||
|
||||
|
||||
public List<String> getRequired() {
|
||||
return required;
|
||||
}
|
||||
|
||||
public void setRequired(List<String> required) {
|
||||
this.required = required;
|
||||
}
|
||||
|
||||
public String get$schema() {
|
||||
return $schema;
|
||||
}
|
||||
|
||||
public void set$schema(String $schema) {
|
||||
this.$schema = $schema;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public JsonSchemaDescrip() {}
|
||||
|
||||
public JsonSchemaDescrip(List<String> required) {
|
||||
this.description="我是一个jsonschema description";
|
||||
this.title="我是一个jsonschema title";
|
||||
this.type="object";
|
||||
this.required = required;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,69 @@
|
||||
package org.jeecg.common.jsonschema;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
public class JsonschemaUtil {
|
||||
|
||||
/**
|
||||
* 生成JsonSchema
|
||||
*
|
||||
* @param descrip
|
||||
* @param propertyList
|
||||
* @return
|
||||
*/
|
||||
public static JSONObject getJsonSchema(JsonSchemaDescrip descrip, List<CommonProperty> propertyList) {
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("$schema", descrip.get$schema());
|
||||
obj.put("type", descrip.getType());
|
||||
obj.put("title", descrip.getTitle());
|
||||
|
||||
List<String> requiredArr = descrip.getRequired();
|
||||
obj.put("required", requiredArr);
|
||||
|
||||
JSONObject properties = new JSONObject();
|
||||
for (CommonProperty commonProperty : propertyList) {
|
||||
Map<String, Object> map = commonProperty.getPropertyJson();
|
||||
properties.put(map.get("key").toString(), map.get("prop"));
|
||||
}
|
||||
obj.put("properties", properties);
|
||||
log.info("---JSONSchema--->"+obj.toString());
|
||||
return obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成JsonSchema 用于子对象
|
||||
* @param title 子对象描述
|
||||
* @param requiredArr 子对象必填属性名集合
|
||||
* @param propertyList 子对象属性集合
|
||||
* @return
|
||||
*/
|
||||
public static JSONObject getSubJsonSchema(String title,List<String> requiredArr,List<CommonProperty> propertyList) {
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("type", "object");
|
||||
obj.put("view", "tab");
|
||||
obj.put("title", title);
|
||||
|
||||
if(requiredArr==null) {
|
||||
requiredArr = new ArrayList<String>();
|
||||
}
|
||||
obj.put("required", requiredArr);
|
||||
|
||||
JSONObject properties = new JSONObject();
|
||||
for (CommonProperty commonProperty : propertyList) {
|
||||
Map<String, Object> map = commonProperty.getPropertyJson();
|
||||
properties.put(map.get("key").toString(), map.get("prop"));
|
||||
}
|
||||
obj.put("properties", properties);
|
||||
//log.info("---JSONSchema--->"+obj.toString());
|
||||
return obj;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,139 @@
|
||||
package org.jeecg.common.jsonschema.validate;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jeecg.common.jsonschema.CommonProperty;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
public class NumberProperty extends CommonProperty {
|
||||
|
||||
private static final long serialVersionUID = -558615331436437200L;
|
||||
|
||||
/**
|
||||
* 倍数
|
||||
* 验证实例是否为此数值的倍数
|
||||
* “multipleOf”的值必须是一个数字,严格大于0。
|
||||
*/
|
||||
private Integer multipleOf;
|
||||
|
||||
/**
|
||||
* 小于等于
|
||||
* “maximum”的值必须是一个数字,表示数字实例的包含上限。
|
||||
* 如果实例是数字,则仅当实例小于或等于“最大”时,此关键字才会生效。
|
||||
*/
|
||||
private Integer maxinum;
|
||||
|
||||
/**
|
||||
* 小于
|
||||
* “exclusiveMaximum”的值必须是数字,表示数字实例的独占上限。
|
||||
* 如果实例是数字,则实例仅在其值严格小于(不等于)“exclusiveMaximum”时才有效。
|
||||
*/
|
||||
private Integer exclusiveMaximum;
|
||||
|
||||
/**
|
||||
* 大于等于
|
||||
*/
|
||||
private Integer minimum;
|
||||
|
||||
/**
|
||||
* 大于等于
|
||||
*/
|
||||
private Integer exclusiveMinimum;
|
||||
|
||||
public Integer getMultipleOf() {
|
||||
return multipleOf;
|
||||
}
|
||||
|
||||
public void setMultipleOf(Integer multipleOf) {
|
||||
this.multipleOf = multipleOf;
|
||||
}
|
||||
|
||||
public Integer getMaxinum() {
|
||||
return maxinum;
|
||||
}
|
||||
|
||||
public void setMaxinum(Integer maxinum) {
|
||||
this.maxinum = maxinum;
|
||||
}
|
||||
|
||||
public Integer getExclusiveMaximum() {
|
||||
return exclusiveMaximum;
|
||||
}
|
||||
|
||||
public void setExclusiveMaximum(Integer exclusiveMaximum) {
|
||||
this.exclusiveMaximum = exclusiveMaximum;
|
||||
}
|
||||
|
||||
public Integer getMinimum() {
|
||||
return minimum;
|
||||
}
|
||||
|
||||
public void setMinimum(Integer minimum) {
|
||||
this.minimum = minimum;
|
||||
}
|
||||
|
||||
public Integer getExclusiveMinimum() {
|
||||
return exclusiveMinimum;
|
||||
}
|
||||
|
||||
public void setExclusiveMinimum(Integer exclusiveMinimum) {
|
||||
this.exclusiveMinimum = exclusiveMinimum;
|
||||
}
|
||||
|
||||
public NumberProperty() {}
|
||||
|
||||
/**
|
||||
* 构造器
|
||||
* @param key 字段名
|
||||
* @param title 字段备注
|
||||
* @param type number和integer
|
||||
*/
|
||||
public NumberProperty(String key,String title,String type) {
|
||||
this.key = key;
|
||||
this.type = type;
|
||||
this.title = title;
|
||||
this.view = "number";
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表类型的走这个构造器 字典里存储的都是字符串 没法走这个构造器
|
||||
* @param key
|
||||
* @param type
|
||||
* @param view list-checkbox-radio
|
||||
* @param include
|
||||
*/
|
||||
public NumberProperty(String key,String title,String view,List<Map<String,Object>> include) {
|
||||
this.type = "integer";
|
||||
this.key = key;
|
||||
this.view = view;
|
||||
this.title = title;
|
||||
this.include = include;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String,Object> getPropertyJson() {
|
||||
Map<String,Object> map = new HashMap<>();
|
||||
map.put("key",getKey());
|
||||
JSONObject prop = getCommonJson();
|
||||
if(multipleOf!=null) {
|
||||
prop.put("multipleOf",multipleOf);
|
||||
}
|
||||
if(maxinum!=null) {
|
||||
prop.put("maxinum",maxinum);
|
||||
}
|
||||
if(exclusiveMaximum!=null) {
|
||||
prop.put("exclusiveMaximum",exclusiveMaximum);
|
||||
}
|
||||
if(minimum!=null) {
|
||||
prop.put("minimum",minimum);
|
||||
}
|
||||
if(exclusiveMinimum!=null) {
|
||||
prop.put("exclusiveMinimum",exclusiveMinimum);
|
||||
}
|
||||
map.put("prop",prop);
|
||||
return map;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,100 @@
|
||||
package org.jeecg.common.jsonschema.validate;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jeecg.common.jsonschema.CommonProperty;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
public class StringProperty extends CommonProperty {
|
||||
|
||||
private static final long serialVersionUID = -3200493311633999539L;
|
||||
|
||||
private Integer maxLength;
|
||||
|
||||
private Integer minLength;
|
||||
|
||||
/**
|
||||
* 根据ECMA 262正则表达式方言,该字符串应该是有效的正则表达式。
|
||||
*/
|
||||
private String pattern;
|
||||
|
||||
public Integer getMaxLength() {
|
||||
return maxLength;
|
||||
}
|
||||
|
||||
|
||||
public void setMaxLength(Integer maxLength) {
|
||||
this.maxLength = maxLength;
|
||||
}
|
||||
|
||||
public Integer getMinLength() {
|
||||
return minLength;
|
||||
}
|
||||
|
||||
public void setMinLength(Integer minLength) {
|
||||
this.minLength = minLength;
|
||||
}
|
||||
|
||||
public String getPattern() {
|
||||
return pattern;
|
||||
}
|
||||
|
||||
public void setPattern(String pattern) {
|
||||
this.pattern = pattern;
|
||||
}
|
||||
|
||||
public StringProperty() {}
|
||||
|
||||
/**
|
||||
* 一般字符串类型走这个构造器
|
||||
* @param key 字段名
|
||||
* @param title 字段备注
|
||||
* @param view 展示控件
|
||||
* @param maxLength 数据库字段最大长度
|
||||
*/
|
||||
public StringProperty(String key,String title,String view,Integer maxLength) {
|
||||
this.maxLength = maxLength;
|
||||
this.key = key;
|
||||
this.view = view;
|
||||
this.title = title;
|
||||
this.type = "string";
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表类型的走这个构造器
|
||||
* @param key 字段名
|
||||
* @param title 字段备注
|
||||
* @param view 展示控件 list-checkbox-radio
|
||||
* @param maxLength 数据库字段最大长度
|
||||
* @param include 数据字典
|
||||
*/
|
||||
public StringProperty(String key,String title,String view,Integer maxLength,List<Map<String,Object>> include) {
|
||||
this.maxLength = maxLength;
|
||||
this.key = key;
|
||||
this.view = view;
|
||||
this.title = title;
|
||||
this.type = "string";
|
||||
this.include = include;
|
||||
}
|
||||
@Override
|
||||
public Map<String, Object> getPropertyJson() {
|
||||
Map<String,Object> map = new HashMap<>();
|
||||
map.put("key",getKey());
|
||||
JSONObject prop = getCommonJson();
|
||||
if(maxLength!=null) {
|
||||
prop.put("maxLength",maxLength);
|
||||
}
|
||||
if(minLength!=null) {
|
||||
prop.put("minLength",minLength);
|
||||
}
|
||||
if(pattern!=null) {
|
||||
prop.put("pattern",pattern);
|
||||
}
|
||||
map.put("prop",prop);
|
||||
return map;
|
||||
}
|
||||
|
||||
}
|
||||
@ -40,7 +40,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
@RequestMapping("/sys/common")
|
||||
public class CommonController {
|
||||
|
||||
@Value(value = "${uploadpath}")
|
||||
@Value(value = "${jeecg.path.upload}")
|
||||
private String uploadpath;
|
||||
|
||||
@PostMapping(value = "/upload")
|
||||
|
||||
@ -0,0 +1,55 @@
|
||||
package org.jeecg.common.system.query;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class QueryCondition implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 4740166316629191651L;
|
||||
|
||||
private String field;
|
||||
private String type;
|
||||
private String rule;
|
||||
private String val;
|
||||
|
||||
public String getField() {
|
||||
return field;
|
||||
}
|
||||
|
||||
public void setField(String field) {
|
||||
this.field = field;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getRule() {
|
||||
return rule;
|
||||
}
|
||||
|
||||
public void setRule(String rule) {
|
||||
this.rule = rule;
|
||||
}
|
||||
|
||||
public String getVal() {
|
||||
return val;
|
||||
}
|
||||
|
||||
public void setVal(String val) {
|
||||
this.val = val;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
StringBuffer sb =new StringBuffer();
|
||||
if(field == null || "".equals(field)){
|
||||
return "";
|
||||
}
|
||||
sb.append(this.field).append(" ").append(this.rule).append(" ").append(this.type).append(" ").append(this.val);
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,484 @@
|
||||
package org.jeecg.common.system.query;
|
||||
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.math.BigDecimal;
|
||||
import java.net.URLDecoder;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.commons.beanutils.PropertyUtils;
|
||||
import org.jeecg.common.util.oConvertUtils;
|
||||
import org.jeecg.modules.shiro.authc.util.JwtUtil;
|
||||
import org.jeecg.modules.system.entity.SysPermissionDataRule;
|
||||
import org.jeecg.modules.system.util.JeecgDataAutorUtils;
|
||||
import org.springframework.util.NumberUtils;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
public class QueryGenerator {
|
||||
|
||||
public static final String SQL_RULES_COLUMN = "SQL_RULES_COLUMN";
|
||||
|
||||
private static final String BEGIN = "_begin";
|
||||
private static final String END = "_end";
|
||||
private static final String STAR = "*";
|
||||
private static final String COMMA = ",";
|
||||
private static final String NOT_EQUAL = "!";
|
||||
/**高级查询前端传来的参数名*/
|
||||
private static final String SUPER_QUERY_PARAMS = "superQueryParams";
|
||||
|
||||
/**排序列*/
|
||||
private static final String ORDER_COLUMN = "column";
|
||||
/**排序方式*/
|
||||
private static final String ORDER_TYPE = "order";
|
||||
private static final String ORDER_TYPE_ASC = "ASC";
|
||||
|
||||
/**时间格式化 */
|
||||
private static final ThreadLocal<SimpleDateFormat> local = new ThreadLocal<SimpleDateFormat>();
|
||||
private static SimpleDateFormat getTime(){
|
||||
SimpleDateFormat time = local.get();
|
||||
if(time == null){
|
||||
time = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
|
||||
local.set(time);
|
||||
}
|
||||
return time;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取查询条件构造器QueryWrapper实例 通用查询条件已被封装完成
|
||||
* @param searchObj 查询实体
|
||||
* @param parameterMap request.getParameterMap()
|
||||
* @return QueryWrapper实例
|
||||
*/
|
||||
public static <T> QueryWrapper<T> initQueryWrapper(T searchObj,Map<String, String[]> parameterMap){
|
||||
long start = System.currentTimeMillis();
|
||||
QueryWrapper<T> queryWrapper = new QueryWrapper<T>();
|
||||
installMplus(queryWrapper, searchObj, parameterMap);
|
||||
log.info("---查询条件构造器初始化完成,耗时:"+(System.currentTimeMillis()-start)+"毫秒----");
|
||||
return queryWrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 组装Mybatis Plus 查询条件
|
||||
* <p>使用此方法 需要有如下几点注意:
|
||||
* <br>1.使用QueryWrapper 而非LambdaQueryWrapper;
|
||||
* <br>2.实例化QueryWrapper时不可将实体传入参数
|
||||
* <br>错误示例:如QueryWrapper<JeecgDemo> queryWrapper = new QueryWrapper<JeecgDemo>(jeecgDemo);
|
||||
* <br>正确示例:QueryWrapper<JeecgDemo> queryWrapper = new QueryWrapper<JeecgDemo>();
|
||||
* <br>3.也可以不使用这个方法直接调用 {@link #initQueryWrapper}直接获取实例
|
||||
*/
|
||||
public static void installMplus(QueryWrapper<?> queryWrapper,Object searchObj,Map<String, String[]> parameterMap) {
|
||||
|
||||
/*
|
||||
* 注意:权限查询由前端配置数据规则 当一个人有多个所属部门时候 可以在规则配置包含条件 orgCode 包含 #{sys_org_code}
|
||||
但是不支持在自定义SQL中写orgCode in #{sys_org_code}
|
||||
当一个人只有一个部门 就直接配置等于条件: orgCode 等于 #{sys_org_code} 或者配置自定义SQL: orgCode = '#{sys_org_code}'
|
||||
*/
|
||||
|
||||
//区间条件组装 模糊查询 高级查询组装 简单排序 权限查询
|
||||
PropertyDescriptor origDescriptors[] = PropertyUtils.getPropertyDescriptors(searchObj);
|
||||
Map<String,SysPermissionDataRule> ruleMap = getRuleMap();
|
||||
|
||||
//权限规则自定义SQL表达式
|
||||
for (String c : ruleMap.keySet()) {
|
||||
if(oConvertUtils.isNotEmpty(c) && c.startsWith(SQL_RULES_COLUMN)){
|
||||
queryWrapper.and(i ->i.apply(getSqlRuleValue(ruleMap.get(c).getRuleValue())));
|
||||
}
|
||||
}
|
||||
|
||||
String name, type;
|
||||
for (int i = 0; i < origDescriptors.length; i++) {
|
||||
//aliasName = origDescriptors[i].getName(); mybatis 不存在实体属性 不用处理别名的情况
|
||||
name = origDescriptors[i].getName();
|
||||
type = origDescriptors[i].getPropertyType().toString();
|
||||
try {
|
||||
if (judgedIsUselessField(name)|| !PropertyUtils.isReadable(searchObj, name)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
//权限查询
|
||||
if(ruleMap.containsKey(name)) {
|
||||
addRuleToQueryWrapper(ruleMap.get(name), name, origDescriptors[i].getPropertyType(), queryWrapper);
|
||||
}
|
||||
|
||||
// 添加 判断是否有区间值
|
||||
String endValue = null,beginValue = null;
|
||||
if (parameterMap != null && parameterMap.containsKey(name + BEGIN)) {
|
||||
beginValue = parameterMap.get(name + BEGIN)[0].trim();
|
||||
addQueryByRule(queryWrapper, name, type, beginValue, QueryRuleEnum.GE);
|
||||
|
||||
}
|
||||
if (parameterMap != null && parameterMap.containsKey(name + END)) {
|
||||
endValue = parameterMap.get(name + END)[0].trim();
|
||||
addQueryByRule(queryWrapper, name, type, endValue, QueryRuleEnum.LE);
|
||||
}
|
||||
|
||||
//判断单值 参数带不同标识字符串 走不同的查询
|
||||
//TODO 这种前后带逗号的支持分割后模糊查询需要否 使多选字段的查询生效
|
||||
Object value = PropertyUtils.getSimpleProperty(searchObj, name);
|
||||
if (null != value && value.toString().startsWith(COMMA) && value.toString().endsWith(COMMA)) {
|
||||
String multiLikeval = value.toString().replace(",,", COMMA);
|
||||
String[] vals = multiLikeval.substring(1, multiLikeval.length()).split(COMMA);
|
||||
final String field = oConvertUtils.camelToUnderline(name);
|
||||
if(vals.length>1) {
|
||||
queryWrapper.and(j -> {
|
||||
j = j.like(field,vals[0]);
|
||||
for (int k=1;k<vals.length;k++) {
|
||||
j = j.or().like(field,vals[k]);
|
||||
}
|
||||
return j;
|
||||
});
|
||||
}else {
|
||||
queryWrapper.and(j -> j.like(field,vals[0]));
|
||||
}
|
||||
}else {
|
||||
//根据参数值带什么关键字符串判断走什么类型的查询
|
||||
QueryRuleEnum rule = convert2Rule(value);
|
||||
value = replaceValue(rule,value);
|
||||
addEasyQuery(queryWrapper, name, rule, value);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
// 排序逻辑 处理
|
||||
doMultiFieldsOrder(queryWrapper, parameterMap);
|
||||
|
||||
//高级查询
|
||||
doSuperQuery(queryWrapper, parameterMap);
|
||||
|
||||
}
|
||||
|
||||
//多字段排序 TODO 需要修改前端
|
||||
public static void doMultiFieldsOrder(QueryWrapper<?> queryWrapper,Map<String, String[]> parameterMap) {
|
||||
String column=null,order=null;
|
||||
if(parameterMap!=null&& parameterMap.containsKey(ORDER_COLUMN)) {
|
||||
column = parameterMap.get(ORDER_COLUMN)[0];
|
||||
}
|
||||
if(parameterMap!=null&& parameterMap.containsKey(ORDER_TYPE)) {
|
||||
order = parameterMap.get(ORDER_TYPE)[0];
|
||||
}
|
||||
log.info("排序规则>>列:"+column+",排序方式:"+order);
|
||||
if (oConvertUtils.isNotEmpty(column) && oConvertUtils.isNotEmpty(order)) {
|
||||
if (order.toUpperCase().indexOf(ORDER_TYPE_ASC)>=0) {
|
||||
queryWrapper.orderByAsc(oConvertUtils.camelToUnderline(column));
|
||||
} else {
|
||||
queryWrapper.orderByDesc(oConvertUtils.camelToUnderline(column));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 高级查询
|
||||
* @param queryWrapper
|
||||
* @param parameterMap
|
||||
*/
|
||||
public static void doSuperQuery(QueryWrapper<?> queryWrapper,Map<String, String[]> parameterMap) {
|
||||
if(parameterMap!=null&& parameterMap.containsKey(SUPER_QUERY_PARAMS)){
|
||||
String superQueryParams = parameterMap.get(SUPER_QUERY_PARAMS)[0];
|
||||
// 解码
|
||||
try {
|
||||
superQueryParams = URLDecoder.decode(superQueryParams, "UTF-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
log.error("--高级查询参数转码失败!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
List<QueryCondition> conditions = JSON.parseArray(superQueryParams, QueryCondition.class);
|
||||
log.info("---高级查询参数-->"+conditions.toString());
|
||||
|
||||
for (QueryCondition rule : conditions) {
|
||||
if(oConvertUtils.isNotEmpty(rule.getField()) && oConvertUtils.isNotEmpty(rule.getRule()) && oConvertUtils.isNotEmpty(rule.getVal())){
|
||||
addEasyQuery(queryWrapper, rule.getField(), QueryRuleEnum.getByValue(rule.getRule()), rule.getVal());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 根据所传的值 转化成对应的比较方式
|
||||
* 支持><= like in !
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
private static QueryRuleEnum convert2Rule(Object value) {
|
||||
// 避免空数据
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
String val = (value + "").toString().trim();
|
||||
if (val.length() == 0) {
|
||||
return null;
|
||||
}
|
||||
// step 1 .> <
|
||||
QueryRuleEnum rule = QueryRuleEnum.getByValue(val.substring(0, 1));
|
||||
// step 2 .>= =<
|
||||
if (rule == null && val.length() >= 2) {
|
||||
rule = QueryRuleEnum.getByValue(val.substring(0, 2));
|
||||
}
|
||||
// step 3 like
|
||||
if (rule == null && val.contains(STAR)) {
|
||||
if (val.startsWith(STAR) && val.endsWith(STAR)) {
|
||||
rule = QueryRuleEnum.LIKE;
|
||||
} else if (val.startsWith(STAR)) {
|
||||
rule = QueryRuleEnum.LEFT_LIKE;
|
||||
} else if(val.endsWith(STAR)){
|
||||
rule = QueryRuleEnum.RIGHT_LIKE;
|
||||
}
|
||||
}
|
||||
// step 4 in
|
||||
if (rule == null && val.contains(COMMA)) {
|
||||
//TODO in 查询这里应该有个bug 如果一字段本身就是多选 此时用in查询 未必能查询出来
|
||||
rule = QueryRuleEnum.IN;
|
||||
}
|
||||
// step 5 !=
|
||||
if(rule == null && val.startsWith(NOT_EQUAL)){
|
||||
rule = QueryRuleEnum.NE;
|
||||
}
|
||||
return rule != null ? rule : QueryRuleEnum.EQ;
|
||||
}
|
||||
|
||||
/**
|
||||
* 替换掉关键字字符
|
||||
*
|
||||
* @param rule
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
private static Object replaceValue(QueryRuleEnum rule, Object value) {
|
||||
if (rule == null) {
|
||||
return null;
|
||||
}
|
||||
if (! (value instanceof String)){
|
||||
return value;
|
||||
}
|
||||
String val = (value + "").toString().trim();
|
||||
if (rule == QueryRuleEnum.LIKE) {
|
||||
value = val.substring(1, val.length() - 1);
|
||||
} else if (rule == QueryRuleEnum.LEFT_LIKE || rule == QueryRuleEnum.NE) {
|
||||
value = val.substring(1);
|
||||
} else if (rule == QueryRuleEnum.RIGHT_LIKE) {
|
||||
value = val.substring(0, val.length() - 1);
|
||||
} else if (rule == QueryRuleEnum.IN) {
|
||||
value = val.split(",");
|
||||
} else {
|
||||
value = val.replace(rule.getValue(),"");
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
private static void addQueryByRule(QueryWrapper<?> queryWrapper,String name,String type,String value,QueryRuleEnum rule) throws ParseException {
|
||||
if(!"".equals(value)) {
|
||||
Object temp;
|
||||
switch (type) {
|
||||
case "class java.lang.Integer":
|
||||
temp = Integer.parseInt(value);
|
||||
break;
|
||||
case "class java.math.BigDecimal":
|
||||
temp = new BigDecimal(value);
|
||||
break;
|
||||
case "class java.lang.Short":
|
||||
temp = Short.parseShort(value);
|
||||
break;
|
||||
case "class java.lang.Long":
|
||||
temp = Long.parseLong(value);
|
||||
break;
|
||||
case "class java.lang.Float":
|
||||
temp = Float.parseFloat(value);
|
||||
break;
|
||||
case "class java.lang.Double":
|
||||
temp = Double.parseDouble(value);
|
||||
break;
|
||||
case "class java.util.Date":
|
||||
temp = getDateQueryByRule(value, rule);
|
||||
break;
|
||||
default:
|
||||
temp = value;
|
||||
break;
|
||||
}
|
||||
addEasyQuery(queryWrapper, name, rule, temp);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取日期类型的值
|
||||
* @param value
|
||||
* @param rule
|
||||
* @return
|
||||
* @throws ParseException
|
||||
*/
|
||||
private static Date getDateQueryByRule(String value,QueryRuleEnum rule) throws ParseException {
|
||||
Date date = null;
|
||||
if(value.length()==10) {
|
||||
if(rule==QueryRuleEnum.GE) {
|
||||
//比较大于
|
||||
date = getTime().parse(value + " 00:00:00");
|
||||
}else if(rule==QueryRuleEnum.LE) {
|
||||
//比较小于
|
||||
date = getTime().parse(value + " 23:59:59");
|
||||
}
|
||||
//TODO 日期类型比较特殊 可能oracle下不一定好使
|
||||
}
|
||||
if(date==null) {
|
||||
date = getTime().parse(value);
|
||||
}
|
||||
return date;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据规则走不同的查询
|
||||
* @param queryWrapper QueryWrapper
|
||||
* @param name 字段名字
|
||||
* @param rule 查询规则
|
||||
* @param value 查询条件值
|
||||
*/
|
||||
private static void addEasyQuery(QueryWrapper<?> queryWrapper, String name, QueryRuleEnum rule, Object value) {
|
||||
if (value == null || rule == null) {
|
||||
return;
|
||||
}
|
||||
name = oConvertUtils.camelToUnderline(name);
|
||||
log.info("--查询规则-->"+name+" "+rule.getValue()+" "+value);
|
||||
switch (rule) {
|
||||
case GT:
|
||||
queryWrapper.gt(name, value);
|
||||
break;
|
||||
case GE:
|
||||
queryWrapper.ge(name, value);
|
||||
break;
|
||||
case LT:
|
||||
queryWrapper.lt(name, value);
|
||||
break;
|
||||
case LE:
|
||||
queryWrapper.le(name, value);
|
||||
break;
|
||||
case EQ:
|
||||
queryWrapper.eq(name, value);
|
||||
break;
|
||||
case NE:
|
||||
queryWrapper.ne(name, value);
|
||||
break;
|
||||
case IN:
|
||||
if(value instanceof String) {
|
||||
queryWrapper.in(name, (Object[])value.toString().split(","));
|
||||
}else if(value instanceof String[]) {
|
||||
queryWrapper.in(name, (Object[]) value);
|
||||
}else {
|
||||
queryWrapper.in(name, value);
|
||||
}
|
||||
break;
|
||||
case LIKE:
|
||||
queryWrapper.like(name, value);
|
||||
break;
|
||||
case LEFT_LIKE:
|
||||
queryWrapper.likeLeft(name, value);
|
||||
break;
|
||||
case RIGHT_LIKE:
|
||||
queryWrapper.likeRight(name, value);
|
||||
break;
|
||||
default:
|
||||
log.info("--查询规则未匹配到---");
|
||||
break;
|
||||
}
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
private static boolean judgedIsUselessField(String name) {
|
||||
return "class".equals(name) || "ids".equals(name)
|
||||
|| "page".equals(name) || "rows".equals(name)
|
||||
|| "sort".equals(name) || "order".equals(name);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static Map<String, SysPermissionDataRule> getRuleMap() {
|
||||
Map<String, SysPermissionDataRule> ruleMap = new HashMap<String, SysPermissionDataRule>();
|
||||
List<SysPermissionDataRule> list =JeecgDataAutorUtils.loadDataSearchConditon();
|
||||
if(list != null&&list.size()>0){
|
||||
if(list.get(0)==null){
|
||||
return ruleMap;
|
||||
}
|
||||
for (SysPermissionDataRule rule : list) {
|
||||
String column = rule.getRuleColumn();
|
||||
if(QueryRuleEnum.SQL_RULES.getValue().equals(rule.getRuleConditions())) {
|
||||
column = SQL_RULES_COLUMN+rule.getId();
|
||||
}
|
||||
ruleMap.put(column, rule);
|
||||
}
|
||||
}
|
||||
return ruleMap;
|
||||
}
|
||||
|
||||
private static void addRuleToQueryWrapper(SysPermissionDataRule dataRule,String name, Class propertyType, QueryWrapper<?> queryWrapper) {
|
||||
QueryRuleEnum rule = QueryRuleEnum.getByValue(dataRule.getRuleConditions());
|
||||
if(rule.equals(QueryRuleEnum.IN) && ! propertyType.equals(String.class)) {
|
||||
String[] values = dataRule.getRuleValue().split(",");
|
||||
Object[] objs = new Object[values.length];
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
objs[i] = NumberUtils.parseNumber(values[i], propertyType);
|
||||
}
|
||||
addEasyQuery(queryWrapper, name, rule, objs);
|
||||
}else {
|
||||
if (propertyType.equals(String.class)) {
|
||||
addEasyQuery(queryWrapper, name, rule, converRuleValue(dataRule.getRuleValue()));
|
||||
} else {
|
||||
addEasyQuery(queryWrapper, name, rule, NumberUtils.parseNumber(dataRule.getRuleValue(), propertyType));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String converRuleValue(String ruleValue) {
|
||||
String value = JwtUtil.getSessionData(ruleValue);
|
||||
if(oConvertUtils.isEmpty(value)) {
|
||||
value = JwtUtil.getUserSystemData(ruleValue,null);
|
||||
}
|
||||
return value!= null ? value : ruleValue;
|
||||
}
|
||||
|
||||
public static String getSqlRuleValue(String sqlRule){
|
||||
try {
|
||||
Set<String> varParams = getSqlRuleParams(sqlRule);
|
||||
for(String var:varParams){
|
||||
String tempValue = converRuleValue(var);
|
||||
sqlRule = sqlRule.replace("#{"+var+"}",tempValue);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return sqlRule;
|
||||
}
|
||||
|
||||
private static Set<String> getSqlRuleParams(String sql) {
|
||||
if(oConvertUtils.isEmpty(sql)){
|
||||
return null;
|
||||
}
|
||||
Set<String> varParams = new HashSet<String>();
|
||||
String regex = "\\#\\{\\w+\\}";
|
||||
|
||||
Pattern p = Pattern.compile(regex);
|
||||
Matcher m = p.matcher(sql);
|
||||
while(m.find()){
|
||||
String var = m.group();
|
||||
varParams.add(var.substring(var.indexOf("{")+1,var.indexOf("}")));
|
||||
}
|
||||
return varParams;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,71 @@
|
||||
package org.jeecg.common.system.query;
|
||||
|
||||
import org.jeecg.common.util.oConvertUtils;
|
||||
|
||||
/**
|
||||
* Query 规则 常量
|
||||
* @author Scott
|
||||
* @date 2019年02月14日
|
||||
*/
|
||||
public enum QueryRuleEnum {
|
||||
|
||||
GT(">","gt","大于"),
|
||||
GE(">=","ge","大于等于"),
|
||||
LT("<","lt","小于"),
|
||||
LE("<=","le","小于等于"),
|
||||
EQ("=","eq","等于"),
|
||||
NE("!=","ne","不等于"),
|
||||
IN("IN","in","包含"),
|
||||
LIKE("LIKE","like","全模糊"),
|
||||
LEFT_LIKE("LEFT_LIKE","left_like","左模糊"),
|
||||
RIGHT_LIKE("RIGHT_LIKE","right_like","右模糊"),
|
||||
SQL_RULES("USE_SQL_RULES","ext","自定义SQL片段");
|
||||
|
||||
private String value;
|
||||
|
||||
private String condition;
|
||||
|
||||
private String msg;
|
||||
|
||||
QueryRuleEnum(String value, String condition, String msg){
|
||||
this.value = value;
|
||||
this.condition = condition;
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
|
||||
public void setMsg(String msg) {
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public String getCondition() {
|
||||
return condition;
|
||||
}
|
||||
|
||||
public void setCondition(String condition) {
|
||||
this.condition = condition;
|
||||
}
|
||||
|
||||
public static QueryRuleEnum getByValue(String value){
|
||||
if(oConvertUtils.isEmpty(value)) {
|
||||
return null;
|
||||
}
|
||||
for(QueryRuleEnum val :values()){
|
||||
if (val.getValue().equals(value) || val.getCondition().equals(value)){
|
||||
return val;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -222,7 +222,7 @@ public class DateUtils extends PropertyEditorSupport {
|
||||
* @return 系统当前的时间戳
|
||||
*/
|
||||
public static Timestamp getTimestamp() {
|
||||
return new Timestamp(new Date().getTime());
|
||||
return new Timestamp(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -274,7 +274,7 @@ public class DateUtils extends PropertyEditorSupport {
|
||||
* @return 系统时间的毫秒数
|
||||
*/
|
||||
public static long getMillis() {
|
||||
return new Date().getTime();
|
||||
return System.currentTimeMillis();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -591,6 +591,7 @@ public class DateUtils extends PropertyEditorSupport {
|
||||
* String类型 转换为Date, 如果参数长度为10 转换格式”yyyy-MM-dd“ 如果参数长度为19 转换格式”yyyy-MM-dd
|
||||
* HH:mm:ss“ * @param text String类型的时间值
|
||||
*/
|
||||
@Override
|
||||
public void setAsText(String text) throws IllegalArgumentException {
|
||||
if (StringUtils.hasText(text)) {
|
||||
try {
|
||||
|
||||
@ -6,16 +6,17 @@ public class MD5Util {
|
||||
|
||||
public static String byteArrayToHexString(byte b[]) {
|
||||
StringBuffer resultSb = new StringBuffer();
|
||||
for (int i = 0; i < b.length; i++)
|
||||
for (int i = 0; i < b.length; i++){
|
||||
resultSb.append(byteToHexString(b[i]));
|
||||
|
||||
}
|
||||
return resultSb.toString();
|
||||
}
|
||||
|
||||
private static String byteToHexString(byte b) {
|
||||
int n = b;
|
||||
if (n < 0)
|
||||
if (n < 0) {
|
||||
n += 256;
|
||||
}
|
||||
int d1 = n / 16;
|
||||
int d2 = n % 16;
|
||||
return hexDigits[d1] + hexDigits[d2];
|
||||
@ -26,10 +27,11 @@ public class MD5Util {
|
||||
try {
|
||||
resultString = new String(origin);
|
||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||
if (charsetname == null || "".equals(charsetname))
|
||||
if (charsetname == null || "".equals(charsetname)) {
|
||||
resultString = byteArrayToHexString(md.digest(resultString.getBytes()));
|
||||
else
|
||||
} else {
|
||||
resultString = byteArrayToHexString(md.digest(resultString.getBytes(charsetname)));
|
||||
}
|
||||
} catch (Exception exception) {
|
||||
}
|
||||
return resultString;
|
||||
|
||||
@ -18,8 +18,9 @@ public class MyClassLoader extends ClassLoader {
|
||||
// 获得类的全名,包括包名
|
||||
public static String getPackPath(Object object) {
|
||||
// 检查用户传入的参数是否为空
|
||||
if (object == null)
|
||||
if (object == null) {
|
||||
throw new java.lang.IllegalArgumentException("参数不能为空!");
|
||||
}
|
||||
// 获得类的全名,包括包名
|
||||
String clsName = object.getClass().getName();
|
||||
return clsName;
|
||||
@ -27,8 +28,9 @@ public class MyClassLoader extends ClassLoader {
|
||||
|
||||
public static String getAppPath(Class cls) {
|
||||
// 检查用户传入的参数是否为空
|
||||
if (cls == null)
|
||||
if (cls == null) {
|
||||
throw new java.lang.IllegalArgumentException("参数不能为空!");
|
||||
}
|
||||
ClassLoader loader = cls.getClassLoader();
|
||||
// 获得类的全名,包括包名
|
||||
String clsName = cls.getName() + ".class";
|
||||
@ -39,14 +41,15 @@ public class MyClassLoader extends ClassLoader {
|
||||
if (pack != null) {
|
||||
String packName = pack.getName();
|
||||
// 此处简单判定是否是Java基础类库,防止用户传入JDK内置的类库
|
||||
if (packName.startsWith("java.") || packName.startsWith("javax."))
|
||||
if (packName.startsWith("java.") || packName.startsWith("javax.")) {
|
||||
throw new java.lang.IllegalArgumentException("不要传送系统类!");
|
||||
}
|
||||
// 在类的名称中,去掉包名的部分,获得类的文件名
|
||||
clsName = clsName.substring(packName.length() + 1);
|
||||
// 判定包名是否是简单包名,如果是,则直接将包名转换为路径,
|
||||
if (packName.indexOf(".") < 0)
|
||||
if (packName.indexOf(".") < 0) {
|
||||
path = packName + "/";
|
||||
else {// 否则按照包名的组成部分,将包名转换为路径
|
||||
} else {// 否则按照包名的组成部分,将包名转换为路径
|
||||
int start = 0, end = 0;
|
||||
end = packName.indexOf(".");
|
||||
while (end != -1) {
|
||||
@ -63,14 +66,16 @@ public class MyClassLoader extends ClassLoader {
|
||||
String realPath = url.getPath();
|
||||
// 去掉路径信息中的协议名"file:"
|
||||
int pos = realPath.indexOf("file:");
|
||||
if (pos > -1)
|
||||
if (pos > -1) {
|
||||
realPath = realPath.substring(pos + 5);
|
||||
}
|
||||
// 去掉路径信息最后包含类文件信息的部分,得到类所在的路径
|
||||
pos = realPath.indexOf(path + clsName);
|
||||
realPath = realPath.substring(0, pos - 1);
|
||||
// 如果类文件被打包到JAR等文件中时,去掉对应的JAR等打包文件名
|
||||
if (realPath.endsWith("!"))
|
||||
if (realPath.endsWith("!")) {
|
||||
realPath = realPath.substring(0, realPath.lastIndexOf("/"));
|
||||
}
|
||||
/*------------------------------------------------------------
|
||||
ClassLoader的getResource方法使用了utf-8对路径信息进行了编码,当路径
|
||||
中存在中文和空格时,他会对这些字符进行转换,这样,得到的往往不是我们想要
|
||||
|
||||
@ -367,8 +367,9 @@ public class RedisUtil {
|
||||
public long sSetAndTime(String key, long time, Object... values) {
|
||||
try {
|
||||
Long count = redisTemplate.opsForSet().add(key, values);
|
||||
if (time > 0)
|
||||
if (time > 0) {
|
||||
expire(key, time);
|
||||
}
|
||||
return count;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@ -486,8 +487,9 @@ public class RedisUtil {
|
||||
public boolean lSet(String key, Object value, long time) {
|
||||
try {
|
||||
redisTemplate.opsForList().rightPush(key, value);
|
||||
if (time > 0)
|
||||
if (time > 0) {
|
||||
expire(key, time);
|
||||
}
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@ -524,8 +526,9 @@ public class RedisUtil {
|
||||
public boolean lSet(String key, List<Object> value, long time) {
|
||||
try {
|
||||
redisTemplate.opsForList().rightPushAll(key, value);
|
||||
if (time > 0)
|
||||
if (time > 0) {
|
||||
expire(key, time);
|
||||
}
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@ -0,0 +1,95 @@
|
||||
package org.jeecg.common.util;
|
||||
|
||||
|
||||
import java.net.InetAddress;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 张代浩
|
||||
*
|
||||
*/
|
||||
public class UUIDGenerator {
|
||||
|
||||
|
||||
/**
|
||||
* 产生一个32位的UUID
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
|
||||
public static String generate() {
|
||||
return new StringBuilder(32).append(format(getIP())).append(
|
||||
format(getJVM())).append(format(getHiTime())).append(
|
||||
format(getLoTime())).append(format(getCount())).toString();
|
||||
|
||||
}
|
||||
|
||||
private static final int IP;
|
||||
static {
|
||||
int ipadd;
|
||||
try {
|
||||
ipadd = toInt(InetAddress.getLocalHost().getAddress());
|
||||
} catch (Exception e) {
|
||||
ipadd = 0;
|
||||
}
|
||||
IP = ipadd;
|
||||
}
|
||||
|
||||
private static short counter = (short) 0;
|
||||
|
||||
private static final int JVM = (int) (System.currentTimeMillis() >>> 8);
|
||||
|
||||
private final static String format(int intval) {
|
||||
String formatted = Integer.toHexString(intval);
|
||||
StringBuilder buf = new StringBuilder("00000000");
|
||||
buf.replace(8 - formatted.length(), 8, formatted);
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
private final static String format(short shortval) {
|
||||
String formatted = Integer.toHexString(shortval);
|
||||
StringBuilder buf = new StringBuilder("0000");
|
||||
buf.replace(4 - formatted.length(), 4, formatted);
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
private final static int getJVM() {
|
||||
return JVM;
|
||||
}
|
||||
|
||||
private final static short getCount() {
|
||||
synchronized (UUIDGenerator.class) {
|
||||
if (counter < 0) {
|
||||
counter = 0;
|
||||
}
|
||||
return counter++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unique in a local network
|
||||
*/
|
||||
private final static int getIP() {
|
||||
return IP;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unique down to millisecond
|
||||
*/
|
||||
private final static short getHiTime() {
|
||||
return (short) (System.currentTimeMillis() >>> 32);
|
||||
}
|
||||
|
||||
private final static int getLoTime() {
|
||||
return (int) System.currentTimeMillis();
|
||||
}
|
||||
|
||||
private final static int toInt(byte[] bytes) {
|
||||
int result = 0;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
result = (result << 8) - Byte.MIN_VALUE + (int) bytes[i];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@ -29,10 +29,10 @@ public class oConvertUtils {
|
||||
if (object == null) {
|
||||
return (true);
|
||||
}
|
||||
if (object.equals("")) {
|
||||
if ("".equals(object)) {
|
||||
return (true);
|
||||
}
|
||||
if (object.equals("null")) {
|
||||
if ("null".equals(object)) {
|
||||
return (true);
|
||||
}
|
||||
return (false);
|
||||
@ -64,8 +64,9 @@ public class oConvertUtils {
|
||||
|
||||
private static String code2code(String strIn, String sourceCode, String targetCode) {
|
||||
String strOut = null;
|
||||
if (strIn == null || (strIn.trim()).equals(""))
|
||||
if (strIn == null || (strIn.trim()).equals("")) {
|
||||
return strIn;
|
||||
}
|
||||
try {
|
||||
byte[] b = strIn.getBytes(sourceCode);
|
||||
for (int i = 0; i < b.length; i++) {
|
||||
@ -160,6 +161,17 @@ public class oConvertUtils {
|
||||
return (defval);
|
||||
}
|
||||
}
|
||||
|
||||
public static Integer getInt(Object object) {
|
||||
if (isEmpty(object)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return (Integer.parseInt(object.toString()));
|
||||
} catch (NumberFormatException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static int getInt(BigDecimal s, int defval) {
|
||||
if (s == null) {
|
||||
|
||||
28
jeecg-boot/src/main/java/org/jeecg/config/AutoPoiConfig.java
Normal file
28
jeecg-boot/src/main/java/org/jeecg/config/AutoPoiConfig.java
Normal file
@ -0,0 +1,28 @@
|
||||
package org.jeecg.config;
|
||||
|
||||
import org.jeecgframework.core.util.ApplicationContextUtil;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @author: Scott
|
||||
* @date: 2018/2/7
|
||||
* @description: autopoi 配置类
|
||||
*/
|
||||
|
||||
@Configuration
|
||||
public class AutoPoiConfig {
|
||||
|
||||
/**
|
||||
* excel注解字典参数支持(导入导出字典值,自动翻译)
|
||||
* 举例: @Excel(name = "性别", width = 15, dicCode = "sex")
|
||||
* 1、导出的时候会根据字典配置,把值1,2翻译成:男、女;
|
||||
* 2、导入的时候,会把男、女翻译成1,2存进数据库;
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public ApplicationContextUtil applicationContextUtil() {
|
||||
return new org.jeecgframework.core.util.ApplicationContextUtil();
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,18 +1,34 @@
|
||||
package org.jeecg.config;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.cache.annotation.CachingConfigurerSupport;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.cache.concurrent.ConcurrentMapCache;
|
||||
import org.springframework.cache.interceptor.KeyGenerator;
|
||||
import org.springframework.cache.support.SimpleCacheManager;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.cache.RedisCacheConfiguration;
|
||||
import org.springframework.data.redis.cache.RedisCacheManager;
|
||||
import org.springframework.data.redis.cache.RedisCacheWriter;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
|
||||
import org.springframework.data.redis.serializer.RedisSerializationContext;
|
||||
import org.springframework.data.redis.serializer.RedisSerializer;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
||||
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
|
||||
import com.fasterxml.jackson.annotation.PropertyAccessor;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
@ -30,6 +46,7 @@ public class RedisConfig extends CachingConfigurerSupport {
|
||||
* 只需要讲注解上keyGenerator的值设置为keyGenerator即可</br>
|
||||
* @return 自定义策略生成的key
|
||||
*/
|
||||
@Override
|
||||
@Bean
|
||||
public KeyGenerator keyGenerator() {
|
||||
return new KeyGenerator() {
|
||||
@ -46,14 +63,6 @@ public class RedisConfig extends CachingConfigurerSupport {
|
||||
};
|
||||
}
|
||||
|
||||
// 这个注释不能放开,发现自定义缓存管理器,会导致实体解析失败
|
||||
//TODO
|
||||
// @Bean
|
||||
// public CacheManager cacheManager() {
|
||||
// RedisCacheManager.RedisCacheManagerBuilder builder = RedisCacheManager.RedisCacheManagerBuilder.fromConnectionFactory(lettuceConnectionFactory);
|
||||
// return builder.build();
|
||||
// }
|
||||
|
||||
/**
|
||||
* RedisTemplate配置
|
||||
*/
|
||||
@ -76,5 +85,61 @@ public class RedisConfig extends CachingConfigurerSupport {
|
||||
redisTemplate.afterPropertiesSet();
|
||||
return redisTemplate;
|
||||
}
|
||||
|
||||
/**
|
||||
* 此处的缓存到JAVA虚拟机内存,非存Redis
|
||||
*/
|
||||
@Override
|
||||
@Bean
|
||||
public CacheManager cacheManager() {
|
||||
SimpleCacheManager cacheManager = new SimpleCacheManager();
|
||||
List<ConcurrentMapCache> list=new ArrayList<ConcurrentMapCache>();
|
||||
list.add(new ConcurrentMapCache("dictCache"));
|
||||
list.add(new ConcurrentMapCache("jeecgDemo"));
|
||||
list.add(new ConcurrentMapCache("permission"));
|
||||
cacheManager.setCaches(list);
|
||||
cacheManager.afterPropertiesSet();
|
||||
return cacheManager;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Redis缓存支持设置缓存过期时间
|
||||
* @param redisConnectionFactory
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public RedisCacheManager redisCacheManager(RedisConnectionFactory redisConnectionFactory) {
|
||||
return new RedisCacheManager(
|
||||
RedisCacheWriter.nonLockingRedisCacheWriter(redisConnectionFactory),
|
||||
this.getRedisCacheConfigurationWithTtl(3600), //3600秒,默认策略,未配置的 key 会使用这个
|
||||
this.getRedisCacheConfigurationMap() // 指定 key 策略
|
||||
);
|
||||
}
|
||||
/**
|
||||
* 指定redis缓存超时时间
|
||||
* @return
|
||||
*/
|
||||
private Map<String, RedisCacheConfiguration> getRedisCacheConfigurationMap() {
|
||||
Map<String, RedisCacheConfiguration> redisCacheConfigurationMap = new HashMap<>();
|
||||
redisCacheConfigurationMap.put("dictTableCache", this.getRedisCacheConfigurationWithTtl(600));// 600秒(表数据字典只缓存10分钟)
|
||||
|
||||
return redisCacheConfigurationMap;
|
||||
}
|
||||
private RedisCacheConfiguration getRedisCacheConfigurationWithTtl(Integer seconds) {
|
||||
Jackson2JsonRedisSerializer<Object> jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer<>(Object.class);
|
||||
ObjectMapper om = new ObjectMapper();
|
||||
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
|
||||
om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
|
||||
jackson2JsonRedisSerializer.setObjectMapper(om);
|
||||
|
||||
RedisCacheConfiguration redisCacheConfiguration = RedisCacheConfiguration.defaultCacheConfig();
|
||||
redisCacheConfiguration = redisCacheConfiguration.serializeValuesWith(
|
||||
RedisSerializationContext
|
||||
.SerializationPair
|
||||
.fromSerializer(jackson2JsonRedisSerializer)
|
||||
).entryTtl(Duration.ofSeconds(seconds));
|
||||
|
||||
return redisCacheConfiguration;
|
||||
}
|
||||
}
|
||||
|
||||
@ -43,44 +43,41 @@ public class ShiroConfig {
|
||||
Map<String, String> filterChainDefinitionMap = new LinkedHashMap<String, String>();
|
||||
// 配置不会被拦截的链接 顺序判断
|
||||
filterChainDefinitionMap.put("/sys/login", "anon"); //登录接口排除
|
||||
filterChainDefinitionMap.put("/auth/2step-code", "anon");//登录验证码
|
||||
filterChainDefinitionMap.put("/test/jeecgDemo/**", "anon"); //测试接口
|
||||
filterChainDefinitionMap.put("/test/jeecgOrderMain/**", "anon"); //测试接口
|
||||
filterChainDefinitionMap.put("/**/exportXls", "anon"); //导出接口
|
||||
filterChainDefinitionMap.put("/**/importExcel", "anon"); //导入接口
|
||||
filterChainDefinitionMap.put("/sys/common/view/**", "anon");//图片预览不限制token
|
||||
filterChainDefinitionMap.put("/api/auth/logout", "anon");//退出登录
|
||||
filterChainDefinitionMap.put("/auth/2step-code", "anon");//退出登录
|
||||
|
||||
filterChainDefinitionMap.put("/**.js", "anon");
|
||||
filterChainDefinitionMap.put("/**.css", "anon");
|
||||
filterChainDefinitionMap.put("/", "anon");
|
||||
filterChainDefinitionMap.put("/**/*.js", "anon");
|
||||
filterChainDefinitionMap.put("/**/*.css", "anon");
|
||||
filterChainDefinitionMap.put("/**/*.html", "anon");
|
||||
filterChainDefinitionMap.put("/**/*.svg", "anon");
|
||||
filterChainDefinitionMap.put("/**/*.jpg", "anon");
|
||||
filterChainDefinitionMap.put("/**/*.png", "anon");
|
||||
filterChainDefinitionMap.put("/**/*.ico", "anon");
|
||||
filterChainDefinitionMap.put("/druid/**", "anon");
|
||||
filterChainDefinitionMap.put("/swagger-ui.html", "anon");
|
||||
filterChainDefinitionMap.put("/swagger**/**", "anon");
|
||||
filterChainDefinitionMap.put("/webjars/**", "anon");
|
||||
filterChainDefinitionMap.put("/v2/**", "anon");
|
||||
|
||||
|
||||
filterChainDefinitionMap.put("/processInstance/**", "anon");
|
||||
filterChainDefinitionMap.put("/task/**", "anon");
|
||||
|
||||
//性能监控
|
||||
filterChainDefinitionMap.put("/actuator/metrics/**", "anon");
|
||||
filterChainDefinitionMap.put("/actuator/httptrace/**", "anon");
|
||||
filterChainDefinitionMap.put("/redis/**", "anon");
|
||||
|
||||
//TODO 排除Online请求
|
||||
filterChainDefinitionMap.put("/auto/cgform/**", "anon");
|
||||
//filterChainDefinitionMap.put("/cgAutoListController?list&id=**", "anon");
|
||||
//filterChainDefinitionMap.put("/cgFormBuildController/**", "anon");
|
||||
//TODO 排除FineReport请求
|
||||
//filterChainDefinitionMap.put("/ReportServer?reportlet=**", "anon");
|
||||
|
||||
|
||||
//用户,需要角色权限 “user”
|
||||
//filterChainDefinitionMap.put("/test/**", "roles[test]");
|
||||
//管理员,需要角色权限 “admin”
|
||||
//filterChainDefinitionMap.put("/sys/**", "roles[admin]");
|
||||
filterChainDefinitionMap.put("/online/cgreport/api/exportXls/**", "anon");
|
||||
|
||||
// 添加自己的过滤器并且取名为jwt
|
||||
Map<String, Filter> filterMap = new HashMap<String, Filter>(1);
|
||||
filterMap.put("jwt", new JwtFilter());
|
||||
filterMap.put("resourceCheckFilter", new ResourceCheckFilter());
|
||||
shiroFilterFactoryBean.setFilters(filterMap);
|
||||
// <!-- 过滤链定义,从上向下顺序执行,一般将/**放在最为下边
|
||||
filterChainDefinitionMap.put("/**", "jwt");
|
||||
//filterChainDefinitionMap.put("/**", "resourceCheckFilter");
|
||||
|
||||
// 未授权界面;
|
||||
shiroFilterFactoryBean.setUnauthorizedUrl("/403");
|
||||
|
||||
@ -1,33 +1,62 @@
|
||||
package org.jeecg.config;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.cors.CorsConfiguration;
|
||||
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
||||
import org.springframework.web.filter.CorsFilter;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
/**
|
||||
* Spring Boot 2.0 解决跨域问题
|
||||
* Spring Boot 2.0 解决跨域问题
|
||||
*
|
||||
* @author qinfeng
|
||||
*
|
||||
*/
|
||||
@Configuration
|
||||
public class WebMvcConfiguration implements WebMvcConfigurer {
|
||||
|
||||
@Bean
|
||||
public CorsFilter corsFilter() {
|
||||
final UrlBasedCorsConfigurationSource urlBasedCorsConfigurationSource = new UrlBasedCorsConfigurationSource();
|
||||
final CorsConfiguration corsConfiguration = new CorsConfiguration();
|
||||
/*是否允许请求带有验证信息*/
|
||||
corsConfiguration.setAllowCredentials(true);
|
||||
/*允许访问的客户端域名*/
|
||||
corsConfiguration.addAllowedOrigin("*");
|
||||
/*允许服务端访问的客户端请求头*/
|
||||
corsConfiguration.addAllowedHeader("*");
|
||||
/*允许访问的方法名,GET POST等*/
|
||||
corsConfiguration.addAllowedMethod("*");
|
||||
urlBasedCorsConfigurationSource.registerCorsConfiguration("/**", corsConfiguration);
|
||||
return new CorsFilter(urlBasedCorsConfigurationSource);
|
||||
}
|
||||
@Value("${jeecg.path.upload}")
|
||||
private String upLoadPath;
|
||||
@Value("${jeecg.path.webapp}")
|
||||
private String webAppPath;
|
||||
@Value("${spring.resource.static-locations}")
|
||||
private String staticLocations;
|
||||
|
||||
@Bean
|
||||
public CorsFilter corsFilter() {
|
||||
final UrlBasedCorsConfigurationSource urlBasedCorsConfigurationSource = new UrlBasedCorsConfigurationSource();
|
||||
final CorsConfiguration corsConfiguration = new CorsConfiguration();
|
||||
/* 是否允许请求带有验证信息 */
|
||||
corsConfiguration.setAllowCredentials(true);
|
||||
/* 允许访问的客户端域名 */
|
||||
corsConfiguration.addAllowedOrigin("*");
|
||||
/* 允许服务端访问的客户端请求头 */
|
||||
corsConfiguration.addAllowedHeader("*");
|
||||
/* 允许访问的方法名,GET POST等 */
|
||||
corsConfiguration.addAllowedMethod("*");
|
||||
urlBasedCorsConfigurationSource.registerCorsConfiguration("/**", corsConfiguration);
|
||||
return new CorsFilter(urlBasedCorsConfigurationSource);
|
||||
}
|
||||
|
||||
/**
|
||||
* 静态资源的配置 - 使得可以从磁盘中读取 Html、图片、视频、音频等
|
||||
*/
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
registry.addResourceHandler("/**")
|
||||
.addResourceLocations("file:" + upLoadPath + "//", "file:" + webAppPath + "//")
|
||||
.addResourceLocations(staticLocations.split(","));
|
||||
}
|
||||
|
||||
/**
|
||||
* 访问根路径默认跳转 index.html页面 (简化部署方案: 可以把前端打包直接放到项目的 webapp,上面的配置)
|
||||
*/
|
||||
@Override
|
||||
public void addViewControllers(ViewControllerRegistry registry) {
|
||||
registry.addViewController("/").setViewName("index.html");
|
||||
}
|
||||
}
|
||||
|
||||
@ -38,7 +38,7 @@ public class MybatisInterceptor implements Interceptor {
|
||||
log.debug("------sqlId------" + sqlId);
|
||||
SqlCommandType sqlCommandType = mappedStatement.getSqlCommandType();
|
||||
Object parameter = invocation.getArgs()[1];
|
||||
log.info("------sqlCommandType------" + sqlCommandType);
|
||||
log.debug("------sqlCommandType------" + sqlCommandType);
|
||||
|
||||
if (parameter == null) {
|
||||
return invocation.proceed();
|
||||
|
||||
@ -1,21 +1,57 @@
|
||||
package org.jeecg.modules.demo.mock;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.swing.filechooser.FileSystemView;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api")
|
||||
@Slf4j
|
||||
public class MockController {
|
||||
|
||||
/**
|
||||
* 通用json访问接口
|
||||
* 格式: http://localhost:8080/jeecg-boot/api/json/{filename}
|
||||
* @param filename
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/json/{filename}", method = RequestMethod.GET)
|
||||
public String getJsonData(@PathVariable String filename) {
|
||||
String jsonpath = "classpath:org/jeecg/modules/demo/mock/json/"+filename+".json";
|
||||
return readJson(jsonpath);
|
||||
}
|
||||
|
||||
@GetMapping(value = "/user")
|
||||
public String user() {
|
||||
return readJson("classpath:org/jeecg/modules/demo/mock/json/user.json");
|
||||
}
|
||||
|
||||
/**
|
||||
* 老的登录获取用户信息接口
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/user/info")
|
||||
public String userInfo() {
|
||||
return readJson("classpath:org/jeecg/modules/demo/mock/json/user_info.json");
|
||||
}
|
||||
|
||||
@GetMapping(value = "/role")
|
||||
public String role() {
|
||||
@ -37,6 +73,70 @@ public class MockController {
|
||||
return readJson("classpath:org/jeecg/modules/demo/mock/json/permission_no_page.json");
|
||||
}
|
||||
|
||||
/**
|
||||
* 省市县
|
||||
*/
|
||||
@GetMapping(value = "/area")
|
||||
public String area() {
|
||||
return readJson("classpath:org/jeecg/modules/demo/mock/json/area.json");
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试报表数据
|
||||
*/
|
||||
@GetMapping(value = "/report/getYearCountInfo")
|
||||
public String getYearCountInfo() {
|
||||
return readJson("classpath:org/jeecg/modules/demo/mock/json/getCntrNoCountInfo.json");
|
||||
}
|
||||
@GetMapping(value = "/report/getMonthCountInfo")
|
||||
public String getMonthCountInfo() {
|
||||
return readJson("classpath:org/jeecg/modules/demo/mock/json/getCntrNoCountInfo.json");
|
||||
}
|
||||
@GetMapping(value = "/report/getCntrNoCountInfo")
|
||||
public String getCntrNoCountInfo() {
|
||||
return readJson("classpath:org/jeecg/modules/demo/mock/json/getCntrNoCountInfo.json");
|
||||
}
|
||||
@GetMapping(value = "/report/getCabinetCountInfo")
|
||||
public String getCabinetCountInfo() {
|
||||
return readJson("classpath:org/jeecg/modules/demo/mock/json/getCntrNoCountInfo.json");
|
||||
}
|
||||
|
||||
/**
|
||||
* 实时磁盘监控
|
||||
* @param request
|
||||
* @param response
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/queryDiskInfo")
|
||||
public Result<List<Map<String,Object>>> queryDiskInfo(HttpServletRequest request, HttpServletResponse response){
|
||||
Result<List<Map<String,Object>>> res = new Result<>();
|
||||
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].getFreeSpace()*100/fs[i].getTotalSpace());
|
||||
list.add(map);
|
||||
log.info(map.toString());
|
||||
}
|
||||
res.setResult(list);
|
||||
res.success("查询成功");
|
||||
} catch (Exception e) {
|
||||
res.error500("查询失败"+e.getMessage());
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------
|
||||
/**
|
||||
@ -62,8 +162,19 @@ public class MockController {
|
||||
public String radar() {
|
||||
return readJson("classpath:org/jeecg/modules/demo/mock/json/workplace_radar.json");
|
||||
}
|
||||
|
||||
@GetMapping(value = "/task/process")
|
||||
public String taskProcess() {
|
||||
return readJson("classpath:org/jeecg/modules/demo/mock/json/task_process.json");
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------
|
||||
|
||||
//author:lvdandan-----date:20190315---for:添加数据日志json----
|
||||
public String sysDataLogJson() {
|
||||
return readJson("classpath:org/jeecg/modules/demo/mock/json/sysdatalog.json");
|
||||
}
|
||||
//author:lvdandan-----date:20190315---for:添加数据日志json----
|
||||
|
||||
/**
|
||||
* 读取json格式文件
|
||||
* @param jsonSrc
|
||||
|
||||
13551
jeecg-boot/src/main/java/org/jeecg/modules/demo/mock/json/area.json
Normal file
13551
jeecg-boot/src/main/java/org/jeecg/modules/demo/mock/json/area.json
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,27 @@
|
||||
{
|
||||
"success": true,
|
||||
"message": "查询成功",
|
||||
"code": null,
|
||||
"result": [{
|
||||
"resultIndex": 0,
|
||||
"yearcount": null,
|
||||
"year": 0,
|
||||
"month": null,
|
||||
"monthcount": null,
|
||||
"classifyname": "证明类",
|
||||
"cntrnocount": 4,
|
||||
"cabinetname": null,
|
||||
"cabinetcocunt": 0
|
||||
}, {
|
||||
"resultIndex": 0,
|
||||
"yearcount": null,
|
||||
"year": 0,
|
||||
"month": null,
|
||||
"monthcount": null,
|
||||
"classifyname": "产权类",
|
||||
"cntrnocount": 9,
|
||||
"cabinetname": null,
|
||||
"cabinetcocunt": 0
|
||||
}],
|
||||
"timestamp": 1554285003594
|
||||
}
|
||||
@ -0,0 +1,50 @@
|
||||
{
|
||||
"status": 200,
|
||||
"success": true,
|
||||
"message": "ok",
|
||||
"result": {
|
||||
"data": [
|
||||
{
|
||||
"id": 0,
|
||||
"x": "1",
|
||||
"y": 889
|
||||
},
|
||||
{
|
||||
"id": 1,
|
||||
"x": "2",
|
||||
"y": 341
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"x": "3",
|
||||
"y": 1028
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"x": "4",
|
||||
"y": 1168
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"x": "5",
|
||||
"y": 653
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"x": "6",
|
||||
"y": 863
|
||||
},
|
||||
{
|
||||
"id": 6,
|
||||
"x": "7",
|
||||
"y": 421
|
||||
},
|
||||
{
|
||||
"id": 7,
|
||||
"x": "8",
|
||||
"y": 1320
|
||||
}
|
||||
]
|
||||
},
|
||||
"timestamp": 1554950583837
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
{
|
||||
"mobilePhone":"1872222222",
|
||||
"officePhone":"1222222",
|
||||
"email":"",
|
||||
"createDate":"Jun 23, 2016 12:00:00 PM",
|
||||
"sex":"1",
|
||||
"depId":"402880e447e99cf10147e9a03b320003",
|
||||
"userName":"9001",
|
||||
"status":"1",
|
||||
"content":"111",
|
||||
"id":"4028ef81550c1a7901550c1cd6e70001"
|
||||
}
|
||||
@ -0,0 +1,55 @@
|
||||
{
|
||||
"success": true,
|
||||
"message": "操作成功!",
|
||||
"code": 0,
|
||||
"result": {
|
||||
"records": [
|
||||
{
|
||||
"taskId": "48701",
|
||||
"name": "start",
|
||||
"taskBeginTime": "2019-03-07 09:33:04",
|
||||
"taskEndTime": "2019-03-08 04:03:01",
|
||||
"principal": "测试体验账号",
|
||||
"result": "已完成"
|
||||
},
|
||||
{
|
||||
"taskId": "48702",
|
||||
"name": "部门领导审批",
|
||||
"taskBeginTime": "2019-03-07 09:33:04",
|
||||
"taskEndTime": "2019-03-08 04:03:01",
|
||||
"principal": "测试体验账号",
|
||||
"result": "已完成"
|
||||
},
|
||||
{
|
||||
"taskId": "48703",
|
||||
"name": "调整申请",
|
||||
"taskBeginTime": "2019-03-07 09:33:04",
|
||||
"taskEndTime": "2019-03-08 04:03:01",
|
||||
"principal": "测试体验账号",
|
||||
"result": "已完成"
|
||||
},
|
||||
{
|
||||
"taskId": "48704",
|
||||
"name": "人事审批",
|
||||
"taskBeginTime": "2019-03-07 09:33:04",
|
||||
"taskEndTime": "2019-03-08 04:03:01",
|
||||
"principal": "测试体验账号",
|
||||
"result": "已完成"
|
||||
},
|
||||
{
|
||||
"taskId": "48705",
|
||||
"name": "end",
|
||||
"taskBeginTime": "2019-03-07 09:33:04",
|
||||
"taskEndTime": "2019-03-08 04:03:01",
|
||||
"principal": "测试体验账号",
|
||||
"result": "已完成"
|
||||
}
|
||||
],
|
||||
"total": 0,
|
||||
"size": 10,
|
||||
"current": 1,
|
||||
"searchCount": true,
|
||||
"pages": 0
|
||||
},
|
||||
"timestamp": 1551922394641
|
||||
}
|
||||
@ -0,0 +1,407 @@
|
||||
{
|
||||
"message": "",
|
||||
"result": {
|
||||
"id": "4291d7da9005377ec9aec4a71ea837f",
|
||||
"name": "天野远子",
|
||||
"username": "admin",
|
||||
"password": "",
|
||||
"avatar": "/avatar2.jpg",
|
||||
"status": 1,
|
||||
"telephone": "",
|
||||
"lastLoginIp": "27.154.74.117",
|
||||
"lastLoginTime": 1534837621348,
|
||||
"creatorId": "admin",
|
||||
"createTime": 1497160610259,
|
||||
"merchantCode": "TLif2btpzg079h15bk",
|
||||
"deleted": 0,
|
||||
"roleId": "admin",
|
||||
"role": {
|
||||
"id": "admin",
|
||||
"name": "管理员",
|
||||
"describe": "拥有所有权限",
|
||||
"status": 1,
|
||||
"creatorId": "system",
|
||||
"createTime": 1497160610259,
|
||||
"deleted": 0,
|
||||
"permissions": [
|
||||
{
|
||||
"roleId": "admin",
|
||||
"permissionId": "dashboard",
|
||||
"permissionName": "仪表盘",
|
||||
"actions": "[{\"action\":\"add\",\"defaultCheck\":false,\"describe\":\"新增\"},{\"action\":\"query\",\"defaultCheck\":false,\"describe\":\"查询\"},{\"action\":\"get\",\"defaultCheck\":false,\"describe\":\"详情\"},{\"action\":\"update\",\"defaultCheck\":false,\"describe\":\"修改\"},{\"action\":\"delete\",\"defaultCheck\":false,\"describe\":\"删除\"}]",
|
||||
"actionEntitySet": [
|
||||
{
|
||||
"action": "add",
|
||||
"describe": "新增",
|
||||
"defaultCheck": false
|
||||
},
|
||||
{
|
||||
"action": "query",
|
||||
"describe": "查询",
|
||||
"defaultCheck": false
|
||||
},
|
||||
{
|
||||
"action": "get",
|
||||
"describe": "详情",
|
||||
"defaultCheck": false
|
||||
},
|
||||
{
|
||||
"action": "update",
|
||||
"describe": "修改",
|
||||
"defaultCheck": false
|
||||
},
|
||||
{
|
||||
"action": "delete",
|
||||
"describe": "删除",
|
||||
"defaultCheck": false
|
||||
}
|
||||
],
|
||||
"actionList": null,
|
||||
"dataAccess": null
|
||||
},
|
||||
{
|
||||
"roleId": "admin",
|
||||
"permissionId": "exception",
|
||||
"permissionName": "异常页面权限",
|
||||
"actions": "[{\"action\":\"add\",\"defaultCheck\":false,\"describe\":\"新增\"},{\"action\":\"query\",\"defaultCheck\":false,\"describe\":\"查询\"},{\"action\":\"get\",\"defaultCheck\":false,\"describe\":\"详情\"},{\"action\":\"update\",\"defaultCheck\":false,\"describe\":\"修改\"},{\"action\":\"delete\",\"defaultCheck\":false,\"describe\":\"删除\"}]",
|
||||
"actionEntitySet": [
|
||||
{
|
||||
"action": "add",
|
||||
"describe": "新增",
|
||||
"defaultCheck": false
|
||||
},
|
||||
{
|
||||
"action": "query",
|
||||
"describe": "查询",
|
||||
"defaultCheck": false
|
||||
},
|
||||
{
|
||||
"action": "get",
|
||||
"describe": "详情",
|
||||
"defaultCheck": false
|
||||
},
|
||||
{
|
||||
"action": "update",
|
||||
"describe": "修改",
|
||||
"defaultCheck": false
|
||||
},
|
||||
{
|
||||
"action": "delete",
|
||||
"describe": "删除",
|
||||
"defaultCheck": false
|
||||
}
|
||||
],
|
||||
"actionList": null,
|
||||
"dataAccess": null
|
||||
},
|
||||
{
|
||||
"roleId": "admin",
|
||||
"permissionId": "result",
|
||||
"permissionName": "结果权限",
|
||||
"actions": "[{\"action\":\"add\",\"defaultCheck\":false,\"describe\":\"新增\"},{\"action\":\"query\",\"defaultCheck\":false,\"describe\":\"查询\"},{\"action\":\"get\",\"defaultCheck\":false,\"describe\":\"详情\"},{\"action\":\"update\",\"defaultCheck\":false,\"describe\":\"修改\"},{\"action\":\"delete\",\"defaultCheck\":false,\"describe\":\"删除\"}]",
|
||||
"actionEntitySet": [
|
||||
{
|
||||
"action": "add",
|
||||
"describe": "新增",
|
||||
"defaultCheck": false
|
||||
},
|
||||
{
|
||||
"action": "query",
|
||||
"describe": "查询",
|
||||
"defaultCheck": false
|
||||
},
|
||||
{
|
||||
"action": "get",
|
||||
"describe": "详情",
|
||||
"defaultCheck": false
|
||||
},
|
||||
{
|
||||
"action": "update",
|
||||
"describe": "修改",
|
||||
"defaultCheck": false
|
||||
},
|
||||
{
|
||||
"action": "delete",
|
||||
"describe": "删除",
|
||||
"defaultCheck": false
|
||||
}
|
||||
],
|
||||
"actionList": null,
|
||||
"dataAccess": null
|
||||
},
|
||||
{
|
||||
"roleId": "admin",
|
||||
"permissionId": "profile",
|
||||
"permissionName": "详细页权限",
|
||||
"actions": "[{\"action\":\"add\",\"defaultCheck\":false,\"describe\":\"新增\"},{\"action\":\"query\",\"defaultCheck\":false,\"describe\":\"查询\"},{\"action\":\"get\",\"defaultCheck\":false,\"describe\":\"详情\"},{\"action\":\"update\",\"defaultCheck\":false,\"describe\":\"修改\"},{\"action\":\"delete\",\"defaultCheck\":false,\"describe\":\"删除\"}]",
|
||||
"actionEntitySet": [
|
||||
{
|
||||
"action": "add",
|
||||
"describe": "新增",
|
||||
"defaultCheck": false
|
||||
},
|
||||
{
|
||||
"action": "query",
|
||||
"describe": "查询",
|
||||
"defaultCheck": false
|
||||
},
|
||||
{
|
||||
"action": "get",
|
||||
"describe": "详情",
|
||||
"defaultCheck": false
|
||||
},
|
||||
{
|
||||
"action": "update",
|
||||
"describe": "修改",
|
||||
"defaultCheck": false
|
||||
},
|
||||
{
|
||||
"action": "delete",
|
||||
"describe": "删除",
|
||||
"defaultCheck": false
|
||||
}
|
||||
],
|
||||
"actionList": null,
|
||||
"dataAccess": null
|
||||
},
|
||||
{
|
||||
"roleId": "admin",
|
||||
"permissionId": "table",
|
||||
"permissionName": "表格权限",
|
||||
"actions": "[{\"action\":\"add\",\"defaultCheck\":false,\"describe\":\"新增\"},{\"action\":\"import\",\"defaultCheck\":false,\"describe\":\"导入\"},{\"action\":\"get\",\"defaultCheck\":false,\"describe\":\"详情\"},{\"action\":\"update\",\"defaultCheck\":false,\"describe\":\"修改\"}]",
|
||||
"actionEntitySet": [
|
||||
{
|
||||
"action": "add",
|
||||
"describe": "新增",
|
||||
"defaultCheck": false
|
||||
},
|
||||
{
|
||||
"action": "import",
|
||||
"describe": "导入",
|
||||
"defaultCheck": false
|
||||
},
|
||||
{
|
||||
"action": "get",
|
||||
"describe": "详情",
|
||||
"defaultCheck": false
|
||||
},
|
||||
{
|
||||
"action": "update",
|
||||
"describe": "修改",
|
||||
"defaultCheck": false
|
||||
}
|
||||
],
|
||||
"actionList": null,
|
||||
"dataAccess": null
|
||||
},
|
||||
{
|
||||
"roleId": "admin",
|
||||
"permissionId": "form",
|
||||
"permissionName": "表单权限",
|
||||
"actions": "[{\"action\":\"add\",\"defaultCheck\":false,\"describe\":\"新增\"},{\"action\":\"get\",\"defaultCheck\":false,\"describe\":\"详情\"},{\"action\":\"query\",\"defaultCheck\":false,\"describe\":\"查询\"},{\"action\":\"update\",\"defaultCheck\":false,\"describe\":\"修改\"},{\"action\":\"delete\",\"defaultCheck\":false,\"describe\":\"删除\"}]",
|
||||
"actionEntitySet": [
|
||||
{
|
||||
"action": "add",
|
||||
"describe": "新增",
|
||||
"defaultCheck": false
|
||||
},
|
||||
{
|
||||
"action": "get",
|
||||
"describe": "详情",
|
||||
"defaultCheck": false
|
||||
},
|
||||
{
|
||||
"action": "query",
|
||||
"describe": "查询",
|
||||
"defaultCheck": false
|
||||
},
|
||||
{
|
||||
"action": "update",
|
||||
"describe": "修改",
|
||||
"defaultCheck": false
|
||||
},
|
||||
{
|
||||
"action": "delete",
|
||||
"describe": "删除",
|
||||
"defaultCheck": false
|
||||
}
|
||||
],
|
||||
"actionList": null,
|
||||
"dataAccess": null
|
||||
},
|
||||
{
|
||||
"roleId": "admin",
|
||||
"permissionId": "order",
|
||||
"permissionName": "订单管理",
|
||||
"actions": "[{\"action\":\"add\",\"defaultCheck\":false,\"describe\":\"新增\"},{\"action\":\"query\",\"defaultCheck\":false,\"describe\":\"查询\"},{\"action\":\"get\",\"defaultCheck\":false,\"describe\":\"详情\"},{\"action\":\"update\",\"defaultCheck\":false,\"describe\":\"修改\"},{\"action\":\"delete\",\"defaultCheck\":false,\"describe\":\"删除\"}]",
|
||||
"actionEntitySet": [
|
||||
{
|
||||
"action": "add",
|
||||
"describe": "新增",
|
||||
"defaultCheck": false
|
||||
},
|
||||
{
|
||||
"action": "query",
|
||||
"describe": "查询",
|
||||
"defaultCheck": false
|
||||
},
|
||||
{
|
||||
"action": "get",
|
||||
"describe": "详情",
|
||||
"defaultCheck": false
|
||||
},
|
||||
{
|
||||
"action": "update",
|
||||
"describe": "修改",
|
||||
"defaultCheck": false
|
||||
},
|
||||
{
|
||||
"action": "delete",
|
||||
"describe": "删除",
|
||||
"defaultCheck": false
|
||||
}
|
||||
],
|
||||
"actionList": null,
|
||||
"dataAccess": null
|
||||
},
|
||||
{
|
||||
"roleId": "admin",
|
||||
"permissionId": "permission",
|
||||
"permissionName": "权限管理",
|
||||
"actions": "[{\"action\":\"add\",\"defaultCheck\":false,\"describe\":\"新增\"},{\"action\":\"get\",\"defaultCheck\":false,\"describe\":\"详情\"},{\"action\":\"update\",\"defaultCheck\":false,\"describe\":\"修改\"},{\"action\":\"delete\",\"defaultCheck\":false,\"describe\":\"删除\"}]",
|
||||
"actionEntitySet": [
|
||||
{
|
||||
"action": "add",
|
||||
"describe": "新增",
|
||||
"defaultCheck": false
|
||||
},
|
||||
{
|
||||
"action": "get",
|
||||
"describe": "详情",
|
||||
"defaultCheck": false
|
||||
},
|
||||
{
|
||||
"action": "update",
|
||||
"describe": "修改",
|
||||
"defaultCheck": false
|
||||
},
|
||||
{
|
||||
"action": "delete",
|
||||
"describe": "删除",
|
||||
"defaultCheck": false
|
||||
}
|
||||
],
|
||||
"actionList": null,
|
||||
"dataAccess": null
|
||||
},
|
||||
{
|
||||
"roleId": "admin",
|
||||
"permissionId": "role",
|
||||
"permissionName": "角色管理",
|
||||
"actions": "[{\"action\":\"add\",\"defaultCheck\":false,\"describe\":\"新增\"},{\"action\":\"get\",\"defaultCheck\":false,\"describe\":\"详情\"},{\"action\":\"update\",\"defaultCheck\":false,\"describe\":\"修改\"},{\"action\":\"delete\",\"defaultCheck\":false,\"describe\":\"删除\"}]",
|
||||
"actionEntitySet": [
|
||||
{
|
||||
"action": "add",
|
||||
"describe": "新增",
|
||||
"defaultCheck": false
|
||||
},
|
||||
{
|
||||
"action": "get",
|
||||
"describe": "详情",
|
||||
"defaultCheck": false
|
||||
},
|
||||
{
|
||||
"action": "update",
|
||||
"describe": "修改",
|
||||
"defaultCheck": false
|
||||
},
|
||||
{
|
||||
"action": "delete",
|
||||
"describe": "删除",
|
||||
"defaultCheck": false
|
||||
}
|
||||
],
|
||||
"actionList": null,
|
||||
"dataAccess": null
|
||||
},
|
||||
{
|
||||
"roleId": "admin",
|
||||
"permissionId": "table",
|
||||
"permissionName": "桌子管理",
|
||||
"actions": "[{\"action\":\"add\",\"defaultCheck\":false,\"describe\":\"新增\"},{\"action\":\"get\",\"defaultCheck\":false,\"describe\":\"详情\"},{\"action\":\"query\",\"defaultCheck\":false,\"describe\":\"查询\"},{\"action\":\"update\",\"defaultCheck\":false,\"describe\":\"修改\"},{\"action\":\"delete\",\"defaultCheck\":false,\"describe\":\"删除\"}]",
|
||||
"actionEntitySet": [
|
||||
{
|
||||
"action": "add",
|
||||
"describe": "新增",
|
||||
"defaultCheck": false
|
||||
},
|
||||
{
|
||||
"action": "get",
|
||||
"describe": "详情",
|
||||
"defaultCheck": false
|
||||
},
|
||||
{
|
||||
"action": "query",
|
||||
"describe": "查询",
|
||||
"defaultCheck": false
|
||||
},
|
||||
{
|
||||
"action": "update",
|
||||
"describe": "修改",
|
||||
"defaultCheck": false
|
||||
},
|
||||
{
|
||||
"action": "delete",
|
||||
"describe": "删除",
|
||||
"defaultCheck": false
|
||||
}
|
||||
],
|
||||
"actionList": null,
|
||||
"dataAccess": null
|
||||
},
|
||||
{
|
||||
"roleId": "admin",
|
||||
"permissionId": "user",
|
||||
"permissionName": "用户管理",
|
||||
"actions": "[{\"action\":\"add\",\"defaultCheck\":false,\"describe\":\"新增\"},{\"action\":\"import\",\"defaultCheck\":false,\"describe\":\"导入\"},{\"action\":\"get\",\"defaultCheck\":false,\"describe\":\"详情\"},{\"action\":\"update\",\"defaultCheck\":false,\"describe\":\"修改\"},{\"action\":\"delete\",\"defaultCheck\":false,\"describe\":\"删除\"},{\"action\":\"export\",\"defaultCheck\":false,\"describe\":\"导出\"}]",
|
||||
"actionEntitySet": [
|
||||
{
|
||||
"action": "add",
|
||||
"describe": "新增",
|
||||
"defaultCheck": false
|
||||
},
|
||||
{
|
||||
"action": "import",
|
||||
"describe": "导入",
|
||||
"defaultCheck": false
|
||||
},
|
||||
{
|
||||
"action": "get",
|
||||
"describe": "详情",
|
||||
"defaultCheck": false
|
||||
},
|
||||
{
|
||||
"action": "update",
|
||||
"describe": "修改",
|
||||
"defaultCheck": false
|
||||
},
|
||||
{
|
||||
"action": "delete",
|
||||
"describe": "删除",
|
||||
"defaultCheck": false
|
||||
},
|
||||
{
|
||||
"action": "export",
|
||||
"describe": "导出",
|
||||
"defaultCheck": false
|
||||
}
|
||||
],
|
||||
"actionList": null,
|
||||
"dataAccess": null
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"status": 200,
|
||||
"timestamp": 1534844188679
|
||||
}
|
||||
@ -1,42 +0,0 @@
|
||||
package org.jeecg.modules.demo.test.controller;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* @Description: auto/cgform
|
||||
* @author: scott
|
||||
* @date: 2019-01-30
|
||||
* @version:V1.0
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/auto/cgform")
|
||||
@Slf4j
|
||||
public class AutoController {
|
||||
|
||||
@GetMapping(value = "/list")
|
||||
public ModelAndView list(HttpServletRequest request, HttpServletResponse response,ModelAndView modelAndView) {
|
||||
HttpSession session = request.getSession();
|
||||
log.info(" session id = " + session.getId());
|
||||
|
||||
modelAndView.setViewName("demo3");
|
||||
List<String> userList = new ArrayList<String>();
|
||||
userList.add("admin");
|
||||
userList.add("user1");
|
||||
userList.add("user2");
|
||||
log.info("--------------test--------------");
|
||||
modelAndView.addObject("userList", userList);
|
||||
modelAndView.addObject("sessionid", session.getId());
|
||||
return modelAndView;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,24 +1,30 @@
|
||||
package org.jeecg.modules.demo.test.controller;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
import org.jeecg.common.aspect.annotation.AutoLog;
|
||||
import org.jeecg.common.system.query.QueryGenerator;
|
||||
import org.jeecg.common.util.DateUtils;
|
||||
import org.jeecg.common.util.RedisUtil;
|
||||
import org.jeecg.common.util.oConvertUtils;
|
||||
import org.jeecg.common.util.superSearch.ObjectParseUtil;
|
||||
import org.jeecg.common.util.superSearch.QueryRuleEnum;
|
||||
import org.jeecg.common.util.superSearch.QueryRuleVo;
|
||||
import org.jeecg.modules.demo.test.entity.JeecgDemo;
|
||||
import org.jeecg.modules.demo.test.service.IJeecgDemoService;
|
||||
import org.jeecgframework.poi.excel.ExcelImportUtil;
|
||||
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
|
||||
import org.jeecgframework.poi.excel.entity.ExportParams;
|
||||
import org.jeecgframework.poi.excel.entity.ImportParams;
|
||||
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@ -27,14 +33,19 @@ import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
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 io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -71,7 +82,7 @@ public class JeecgDemoController {
|
||||
public Result<IPage<JeecgDemo>> list(JeecgDemo jeecgDemo, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
|
||||
HttpServletRequest req) {
|
||||
Result<IPage<JeecgDemo>> result = new Result<IPage<JeecgDemo>>();
|
||||
QueryWrapper<JeecgDemo> queryWrapper = null;
|
||||
/*QueryWrapper<JeecgDemo> queryWrapper = null;
|
||||
//================================================================================
|
||||
//高级组合查询
|
||||
try {
|
||||
@ -106,7 +117,10 @@ public class JeecgDemoController {
|
||||
} else {
|
||||
queryWrapper.orderByDesc(oConvertUtils.camelToUnderline(column));
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
QueryWrapper<JeecgDemo> queryWrapper = QueryGenerator.initQueryWrapper(jeecgDemo, req.getParameterMap());
|
||||
Page<JeecgDemo> page = new Page<JeecgDemo>(pageNo, pageSize);
|
||||
|
||||
IPage<JeecgDemo> pageList = jeecgDemoService.page(page, queryWrapper);
|
||||
// log.info("查询当前页:" + pageList.getCurrent());
|
||||
@ -224,6 +238,78 @@ public class JeecgDemoController {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 导出excel
|
||||
* @param request
|
||||
* @param response
|
||||
*/
|
||||
@RequestMapping(value = "/exportXls")
|
||||
public ModelAndView exportXls(HttpServletRequest request, HttpServletResponse response) {
|
||||
// Step.1 组装查询条件
|
||||
QueryWrapper<JeecgDemo> queryWrapper = null;
|
||||
try {
|
||||
String paramsStr = request.getParameter("paramsStr");
|
||||
if (oConvertUtils.isNotEmpty(paramsStr)) {
|
||||
String deString = URLDecoder.decode(paramsStr, "UTF-8");
|
||||
JeecgDemo jeecgDemo = JSON.parseObject(deString, JeecgDemo.class);
|
||||
queryWrapper = QueryGenerator.initQueryWrapper(jeecgDemo, request.getParameterMap());
|
||||
log.info(paramsStr);
|
||||
log.info(jeecgDemo.toString());
|
||||
}
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
//Step.2 AutoPoi 导出Excel
|
||||
ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
|
||||
List<JeecgDemo> pageList = jeecgDemoService.list(queryWrapper);
|
||||
//导出文件名称
|
||||
mv.addObject(NormalExcelConstants.FILE_NAME,"Excel导出文件名字");
|
||||
//注解对象Class
|
||||
mv.addObject(NormalExcelConstants.CLASS,JeecgDemo.class);
|
||||
//自定义表格参数
|
||||
mv.addObject(NormalExcelConstants.PARAMS,new ExportParams("自定义导出Excel模板内容标题","导出人:Jeecg","导出信息"));
|
||||
//导出数据列表
|
||||
mv.addObject(NormalExcelConstants.DATA_LIST,pageList);
|
||||
return mv;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过excel导入数据
|
||||
* @param request
|
||||
* @param response
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/importExcel", method = RequestMethod.POST)
|
||||
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
|
||||
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
||||
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
|
||||
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
|
||||
MultipartFile file = entity.getValue();// 获取上传文件对象
|
||||
ImportParams params = new ImportParams();
|
||||
params.setTitleRows(2);
|
||||
params.setHeadRows(1);
|
||||
params.setNeedSave(true);
|
||||
try {
|
||||
List<JeecgDemo> listJeecgDemos = ExcelImportUtil.importExcel(file.getInputStream(), JeecgDemo.class, params);
|
||||
for (JeecgDemo jeecgDemoExcel : listJeecgDemos) {
|
||||
jeecgDemoService.save(jeecgDemoExcel);
|
||||
}
|
||||
return Result.ok("文件导入成功!数据行数:" + listJeecgDemos.size());
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
return Result.error("文件导入失败!");
|
||||
} finally {
|
||||
try {
|
||||
file.getInputStream().close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return Result.ok("文件导入失败!");
|
||||
}
|
||||
|
||||
// ================================================================================================================
|
||||
/**
|
||||
* redis操作 -- set
|
||||
@ -292,5 +378,15 @@ public class JeecgDemoController {
|
||||
}
|
||||
|
||||
// ================================================================================================================
|
||||
|
||||
|
||||
// ==========================================动态表单 JSON接收测试===========================================//
|
||||
@PostMapping(value = "/testOnlineAdd")
|
||||
public Result<JeecgDemo> testOnlineAdd(@RequestBody JSONObject json) {
|
||||
Result<JeecgDemo> result = new Result<JeecgDemo>();
|
||||
log.info(json.toJSONString());
|
||||
result.success("添加成功!");
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@ import java.util.List;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
import org.jeecg.common.util.oConvertUtils;
|
||||
import org.jeecg.common.system.query.QueryGenerator;
|
||||
import org.jeecg.modules.demo.test.entity.JeecgOrderCustomer;
|
||||
import org.jeecg.modules.demo.test.entity.JeecgOrderMain;
|
||||
import org.jeecg.modules.demo.test.entity.JeecgOrderTicket;
|
||||
@ -14,6 +14,7 @@ import org.jeecg.modules.demo.test.service.IJeecgOrderCustomerService;
|
||||
import org.jeecg.modules.demo.test.service.IJeecgOrderMainService;
|
||||
import org.jeecg.modules.demo.test.service.IJeecgOrderTicketService;
|
||||
import org.jeecg.modules.demo.test.vo.JeecgOrderMainPage;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@ -41,364 +42,385 @@ import lombok.extern.slf4j.Slf4j;
|
||||
@RestController
|
||||
@RequestMapping("/test/order")
|
||||
public class JeecgOrderDMainController {
|
||||
@Autowired
|
||||
private IJeecgOrderMainService jeecgOrderMainService;
|
||||
@Autowired
|
||||
private IJeecgOrderCustomerService jeecgOrderCustomerService;
|
||||
@Autowired
|
||||
private IJeecgOrderTicketService jeecgOrderTicketService;
|
||||
@Autowired
|
||||
private IJeecgOrderCustomerService customerService;
|
||||
@Autowired
|
||||
private IJeecgOrderTicketService ticketService;
|
||||
|
||||
/**
|
||||
* 分页列表查询
|
||||
* @param jeecgOrderMain
|
||||
* @param pageNo
|
||||
* @param pageSize
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/orderList")
|
||||
public Result<IPage<JeecgOrderMain>> respondePagedData(JeecgOrderMain jeecgOrderMain,
|
||||
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
|
||||
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
|
||||
HttpServletRequest req){
|
||||
Result<IPage<JeecgOrderMain>> result = new Result<IPage<JeecgOrderMain>>();
|
||||
QueryWrapper<JeecgOrderMain> queryWrapper = new QueryWrapper<JeecgOrderMain>(jeecgOrderMain);
|
||||
Page<JeecgOrderMain> page = new Page<JeecgOrderMain>(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<JeecgOrderMain> pageList = jeecgOrderMainService.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 jeecgOrderMainPage
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/add")
|
||||
public Result<JeecgOrderMain> add(@RequestBody JeecgOrderMainPage jeecgOrderMainPage){
|
||||
Result<JeecgOrderMain> result = new Result<JeecgOrderMain>();
|
||||
try {
|
||||
jeecgOrderMainService.saveMain(jeecgOrderMainPage.getJeecgOrderMain(), jeecgOrderMainPage.getJeecgOrderCustomerList(), jeecgOrderMainPage.getJeecgOrderTicketList());;
|
||||
result.success("添加成功!");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.info(e.getMessage());
|
||||
result.error500("操作失败");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
* @param jeecgOrderMainPage
|
||||
* @return
|
||||
*/
|
||||
@PutMapping("/edit")
|
||||
public Result<JeecgOrderMain> edit(@RequestBody JeecgOrderMainPage jeecgOrderMainPage){
|
||||
Result<JeecgOrderMain> result = new Result<JeecgOrderMain>();
|
||||
JeecgOrderMain jeecgOrderMain = jeecgOrderMainPage.getJeecgOrderMain();
|
||||
JeecgOrderMain jeecgOrderMainEntity = jeecgOrderMainService.getById(jeecgOrderMain.getId());
|
||||
if(jeecgOrderMainEntity==null) {
|
||||
result.error500("未找到对应实体");
|
||||
}else {
|
||||
jeecgOrderMainService.updateMain(jeecgOrderMain, jeecgOrderMainPage.getJeecgOrderCustomerList(), jeecgOrderMainPage.getJeecgOrderTicketList());
|
||||
result.success("修改成功!");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id删除
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@DeleteMapping(value = "/delete")
|
||||
public Result<JeecgOrderMain> delete(@RequestParam(name = "id",required = true) String id){
|
||||
Result<JeecgOrderMain> result = new Result<JeecgOrderMain>();
|
||||
JeecgOrderMain jeecgOrderMain = jeecgOrderMainService.getById(id);
|
||||
if(jeecgOrderMain==null) {
|
||||
result.error500("未找到对应实体");
|
||||
}else {
|
||||
jeecgOrderMainService.delMain(id);
|
||||
result.success("删除成功!");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
@DeleteMapping(value = "/deleteBatch")
|
||||
public Result<JeecgOrderMain> deleteBatch(@RequestParam(name = "ids", required = true) String ids){
|
||||
Result<JeecgOrderMain> result = new Result<JeecgOrderMain>();
|
||||
if(ids==null || "".equals(ids.trim())) {
|
||||
result.error500("参数不识别!");
|
||||
}else {
|
||||
this.jeecgOrderMainService.removeByIds(Arrays.asList(ids.split(",")));
|
||||
result.success("删除成功!");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id查询
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/queryById")
|
||||
public Result<JeecgOrderMain> queryById(@RequestParam(name = "id", required = true) String id){
|
||||
Result<JeecgOrderMain> result = new Result<JeecgOrderMain>();
|
||||
JeecgOrderMain jeecgOrderMain = jeecgOrderMainService.getById(id);
|
||||
if(jeecgOrderMain==null) {
|
||||
result.error500("未找到对应实体");
|
||||
}else {
|
||||
result.setResult(jeecgOrderMain);
|
||||
result.setSuccess(true);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id查询
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/queryOrderCustomerListByMainId")
|
||||
public Result<List<JeecgOrderCustomer>> queryOrderCustomerListByMainId(@RequestParam(name="id",required=true) String id){
|
||||
Result<List<JeecgOrderCustomer>> result = new Result<List<JeecgOrderCustomer>>();
|
||||
List<JeecgOrderCustomer> jeecgOrderCustomerList = jeecgOrderCustomerService.selectCustomersByMainId(id);
|
||||
result.setResult(jeecgOrderCustomerList);
|
||||
result.setSuccess(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id查询
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/queryOrderTicketListByMainId")
|
||||
public Result<List<JeecgOrderTicket>> queryOrderTicketListByMainId(@RequestParam(name="id",required=true) String id) {
|
||||
Result<List<JeecgOrderTicket>> result = new Result<List<JeecgOrderTicket>>();
|
||||
List<JeecgOrderTicket> jeecgOrderTicketList = jeecgOrderTicketService.selectTicketsByMainId(id);
|
||||
result.setResult(jeecgOrderTicketList);
|
||||
result.setSuccess(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
// ================================以下是客户信息相关的API=================================
|
||||
/**
|
||||
* 添加
|
||||
* @param jeecgOrderCustomer
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/addCustomer")
|
||||
public Result<JeecgOrderCustomer> addCustomer(@RequestBody JeecgOrderCustomer jeecgOrderCustomer){
|
||||
Result<JeecgOrderCustomer> result = new Result<>();
|
||||
try {
|
||||
boolean ok = customerService.save(jeecgOrderCustomer);
|
||||
if(ok) {
|
||||
result.setSuccess(true);
|
||||
result.setMessage("添加数据成功");
|
||||
}else {
|
||||
result.setSuccess(false);
|
||||
result.setMessage("添加数据失败");
|
||||
}
|
||||
return result;
|
||||
}catch(Exception e) {
|
||||
e.fillInStackTrace();
|
||||
result.setSuccess(false);
|
||||
result.setMessage("遇到问题了!");
|
||||
return result;
|
||||
}
|
||||
@Autowired
|
||||
private IJeecgOrderMainService jeecgOrderMainService;
|
||||
@Autowired
|
||||
private IJeecgOrderCustomerService jeecgOrderCustomerService;
|
||||
@Autowired
|
||||
private IJeecgOrderTicketService jeecgOrderTicketService;
|
||||
@Autowired
|
||||
private IJeecgOrderCustomerService customerService;
|
||||
@Autowired
|
||||
private IJeecgOrderTicketService ticketService;
|
||||
|
||||
/**
|
||||
* 分页列表查询
|
||||
*
|
||||
* @param jeecgOrderMain
|
||||
* @param pageNo
|
||||
* @param pageSize
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/orderList")
|
||||
public Result<IPage<JeecgOrderMain>> respondePagedData(JeecgOrderMain jeecgOrderMain,
|
||||
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
|
||||
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
|
||||
HttpServletRequest req) {
|
||||
Result<IPage<JeecgOrderMain>> result = new Result<IPage<JeecgOrderMain>>();
|
||||
QueryWrapper<JeecgOrderMain> queryWrapper = QueryGenerator.initQueryWrapper(jeecgOrderMain, req.getParameterMap());
|
||||
Page<JeecgOrderMain> page = new Page<JeecgOrderMain>(pageNo, pageSize);
|
||||
IPage<JeecgOrderMain> pageList = jeecgOrderMainService.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 jeecgOrderMainPage
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/add")
|
||||
public Result<JeecgOrderMain> add(@RequestBody JeecgOrderMainPage jeecgOrderMainPage) {
|
||||
Result<JeecgOrderMain> result = new Result<JeecgOrderMain>();
|
||||
try {
|
||||
JeecgOrderMain jeecgOrderMain = new JeecgOrderMain();
|
||||
BeanUtils.copyProperties(jeecgOrderMainPage, jeecgOrderMain);
|
||||
jeecgOrderMainService.save(jeecgOrderMain);
|
||||
result.success("添加成功!");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.info(e.getMessage());
|
||||
result.error500("操作失败");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*
|
||||
* @param jeecgOrderMainPage
|
||||
* @return
|
||||
*/
|
||||
@PutMapping("/edit")
|
||||
public Result<JeecgOrderMain> edit(@RequestBody JeecgOrderMainPage jeecgOrderMainPage) {
|
||||
Result<JeecgOrderMain> result = new Result<JeecgOrderMain>();
|
||||
JeecgOrderMain jeecgOrderMain = new JeecgOrderMain();
|
||||
BeanUtils.copyProperties(jeecgOrderMainPage, jeecgOrderMain);
|
||||
JeecgOrderMain jeecgOrderMainEntity = jeecgOrderMainService.getById(jeecgOrderMain.getId());
|
||||
if (jeecgOrderMainEntity == null) {
|
||||
result.error500("未找到对应实体");
|
||||
} else {
|
||||
jeecgOrderMainService.updateById(jeecgOrderMain);
|
||||
result.success("修改成功!");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id删除
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@DeleteMapping(value = "/delete")
|
||||
public Result<JeecgOrderMain> delete(@RequestParam(name = "id", required = true) String id) {
|
||||
Result<JeecgOrderMain> result = new Result<JeecgOrderMain>();
|
||||
JeecgOrderMain jeecgOrderMain = jeecgOrderMainService.getById(id);
|
||||
if (jeecgOrderMain == null) {
|
||||
result.error500("未找到对应实体");
|
||||
} else {
|
||||
jeecgOrderMainService.delMain(id);
|
||||
result.success("删除成功!");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
*
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
@DeleteMapping(value = "/deleteBatch")
|
||||
public Result<JeecgOrderMain> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
|
||||
Result<JeecgOrderMain> result = new Result<JeecgOrderMain>();
|
||||
if (ids == null || "".equals(ids.trim())) {
|
||||
result.error500("参数不识别!");
|
||||
} else {
|
||||
this.jeecgOrderMainService.removeByIds(Arrays.asList(ids.split(",")));
|
||||
result.success("删除成功!");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id查询
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/queryById")
|
||||
public Result<JeecgOrderMain> queryById(@RequestParam(name = "id", required = true) String id) {
|
||||
Result<JeecgOrderMain> result = new Result<JeecgOrderMain>();
|
||||
JeecgOrderMain jeecgOrderMain = jeecgOrderMainService.getById(id);
|
||||
if (jeecgOrderMain == null) {
|
||||
result.error500("未找到对应实体");
|
||||
} else {
|
||||
result.setResult(jeecgOrderMain);
|
||||
result.setSuccess(true);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id查询
|
||||
*
|
||||
* @param mainId
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/listOrderCustomerByMainId")
|
||||
public Result<List<JeecgOrderCustomer>> queryOrderCustomerListByMainId(@RequestParam(name = "mainId", required = false) String mainId) {
|
||||
Result<List<JeecgOrderCustomer>> result = new Result<List<JeecgOrderCustomer>>();
|
||||
List<JeecgOrderCustomer> jeecgOrderCustomerList = null;
|
||||
if (mainId != null) {
|
||||
jeecgOrderCustomerList = jeecgOrderCustomerService.selectCustomersByMainId(mainId);
|
||||
result.setResult(jeecgOrderCustomerList);
|
||||
result.setSuccess(true);
|
||||
return result;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
* @param jeecgOrderCustomer
|
||||
* @return
|
||||
*/
|
||||
@PutMapping("/editCustomer")
|
||||
public Result<JeecgOrderCustomer> editCustomer(@RequestBody JeecgOrderCustomer jeecgOrderCustomer){
|
||||
Result<JeecgOrderCustomer> result = new Result<>();
|
||||
try {
|
||||
boolean ok = customerService.updateById(jeecgOrderCustomer);
|
||||
if(ok) {
|
||||
result.setSuccess(true);
|
||||
result.setMessage("更新成功");
|
||||
}else{
|
||||
result.setSuccess(false);
|
||||
result.setMessage("更新失败");
|
||||
}
|
||||
return result;
|
||||
}catch(Exception e) {
|
||||
e.fillInStackTrace();
|
||||
result.setSuccess(true);
|
||||
result.setMessage("更新中碰到异常了");
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id查询
|
||||
*
|
||||
* @param mainId
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/listOrderTicketByMainId")
|
||||
public Result<List<JeecgOrderTicket>> queryOrderTicketListByMainId(@RequestParam(name = "mainId", required = false) String mainId) {
|
||||
Result<List<JeecgOrderTicket>> result = new Result<List<JeecgOrderTicket>>();
|
||||
List<JeecgOrderTicket> jeecgOrderTicketList = null;
|
||||
if (mainId != null) {
|
||||
jeecgOrderTicketList = jeecgOrderTicketService.selectTicketsByMainId(mainId);
|
||||
result.setResult(jeecgOrderTicketList);
|
||||
result.setSuccess(true);
|
||||
return result;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id删除
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@DeleteMapping(value = "/deleteCustomer")
|
||||
public Result<JeecgOrderCustomer> deleteCustomer(@RequestParam(name = "id",required = true) String id){
|
||||
Result<JeecgOrderCustomer> result = new Result<>();
|
||||
try {
|
||||
boolean ok = customerService.removeById(id);
|
||||
if(ok) {
|
||||
result.setSuccess(true);
|
||||
result.setMessage("删除成功");
|
||||
}else {
|
||||
result.setSuccess(false);
|
||||
result.setMessage("删除失败");
|
||||
}
|
||||
return result;
|
||||
}catch(Exception e) {
|
||||
e.fillInStackTrace();
|
||||
result.setSuccess(false);
|
||||
result.setMessage("删除过程中碰到异常了");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
@DeleteMapping(value = "/deleteBatchCustomer")
|
||||
public Result<JeecgOrderCustomer> deleteBatchCustomer(@RequestParam(name = "ids", required = true) String ids){
|
||||
Result<JeecgOrderCustomer> result = new Result<JeecgOrderCustomer>();
|
||||
if(ids==null || "".equals(ids.trim())) {
|
||||
result.error500("参数不识别!");
|
||||
}else {
|
||||
this.customerService.removeByIds(Arrays.asList(ids.split(",")));
|
||||
result.success("删除成功!");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
// ================================以下是客户信息相关的API=================================
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*
|
||||
* @param jeecgOrderCustomer
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/addCustomer")
|
||||
public Result<JeecgOrderCustomer> addCustomer(@RequestBody JeecgOrderCustomer jeecgOrderCustomer) {
|
||||
Result<JeecgOrderCustomer> result = new Result<>();
|
||||
try {
|
||||
boolean ok = customerService.save(jeecgOrderCustomer);
|
||||
if (ok) {
|
||||
result.setSuccess(true);
|
||||
result.setMessage("添加数据成功");
|
||||
} else {
|
||||
result.setSuccess(false);
|
||||
result.setMessage("添加数据失败");
|
||||
}
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
e.fillInStackTrace();
|
||||
result.setSuccess(false);
|
||||
result.setMessage("遇到问题了!");
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*
|
||||
* @param jeecgOrderCustomer
|
||||
* @return
|
||||
*/
|
||||
@PutMapping("/editCustomer")
|
||||
public Result<JeecgOrderCustomer> editCustomer(@RequestBody JeecgOrderCustomer jeecgOrderCustomer) {
|
||||
Result<JeecgOrderCustomer> result = new Result<>();
|
||||
try {
|
||||
boolean ok = customerService.updateById(jeecgOrderCustomer);
|
||||
if (ok) {
|
||||
result.setSuccess(true);
|
||||
result.setMessage("更新成功");
|
||||
} else {
|
||||
result.setSuccess(false);
|
||||
result.setMessage("更新失败");
|
||||
}
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
e.fillInStackTrace();
|
||||
result.setSuccess(true);
|
||||
result.setMessage("更新中碰到异常了");
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id删除
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@DeleteMapping(value = "/deleteCustomer")
|
||||
public Result<JeecgOrderCustomer> deleteCustomer(@RequestParam(name = "id", required = true) String id) {
|
||||
Result<JeecgOrderCustomer> result = new Result<>();
|
||||
try {
|
||||
boolean ok = customerService.removeById(id);
|
||||
if (ok) {
|
||||
result.setSuccess(true);
|
||||
result.setMessage("删除成功");
|
||||
} else {
|
||||
result.setSuccess(false);
|
||||
result.setMessage("删除失败");
|
||||
}
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
e.fillInStackTrace();
|
||||
result.setSuccess(false);
|
||||
result.setMessage("删除过程中碰到异常了");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
*
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
@DeleteMapping(value = "/deleteBatchCustomer")
|
||||
public Result<JeecgOrderCustomer> deleteBatchCustomer(@RequestParam(name = "ids", required = true) String ids) {
|
||||
Result<JeecgOrderCustomer> result = new Result<JeecgOrderCustomer>();
|
||||
if (ids == null || "".equals(ids.trim())) {
|
||||
result.error500("参数不识别!");
|
||||
} else {
|
||||
this.customerService.removeByIds(Arrays.asList(ids.split(",")));
|
||||
result.success("删除成功!");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
//===========================以下是机票的相关API====================================
|
||||
/**
|
||||
* 添加
|
||||
* @param jeecgOrderTicket
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/addTicket")
|
||||
public Result<JeecgOrderTicket> addTicket(@RequestBody JeecgOrderTicket jeecgOrderTicket){
|
||||
Result<JeecgOrderTicket> result = new Result<>();
|
||||
try {
|
||||
boolean ok = ticketService.save(jeecgOrderTicket);
|
||||
if(ok) {
|
||||
result.setSuccess(true);
|
||||
result.setMessage("添加机票信息成功.");
|
||||
}else {
|
||||
result.setSuccess(false);
|
||||
result.setMessage("添加机票信息失败!");
|
||||
}
|
||||
return result;
|
||||
}catch(Exception e) {
|
||||
e.fillInStackTrace();
|
||||
result.setSuccess(false);
|
||||
result.setMessage("添加机票信息过程中出现了异常: "+e.getMessage());
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
* @param jeecgOrderTicket
|
||||
* @return
|
||||
*/
|
||||
@PutMapping("/editTicket")
|
||||
public Result<JeecgOrderTicket> editTicket(@RequestBody JeecgOrderTicket jeecgOrderTicket){
|
||||
Result<JeecgOrderTicket> result = new Result<>();
|
||||
try {
|
||||
boolean ok = ticketService.updateById(jeecgOrderTicket);
|
||||
if(ok) {
|
||||
result.setSuccess(true);
|
||||
result.setMessage("更新数据成功.");
|
||||
}else {
|
||||
result.setSuccess(false);
|
||||
result.setMessage("更新机票 信息失败!");
|
||||
}
|
||||
return result;
|
||||
}catch(Exception e) {
|
||||
result.setSuccess(false);
|
||||
result.setMessage("更新数据过程中出现异常啦: " + e.getMessage());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id删除
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@DeleteMapping(value = "/deleteTicket")
|
||||
public Result<JeecgOrderTicket> deleteTicket(@RequestParam(name = "id",required = true) String id){
|
||||
Result<JeecgOrderTicket> result = new Result<>();
|
||||
try {
|
||||
boolean ok = ticketService.removeById(id);
|
||||
if(ok) {
|
||||
result.setSuccess(true);
|
||||
result.setMessage("删除机票信息成功.");
|
||||
}else {
|
||||
result.setSuccess(false);
|
||||
result.setMessage("删除机票信息失败!");
|
||||
}
|
||||
return result;
|
||||
}catch(Exception e) {
|
||||
result.setSuccess(false);
|
||||
result.setMessage("删除机票信息过程中出现异常啦: " + e.getMessage());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
@DeleteMapping(value = "/deleteBatchTicket")
|
||||
public Result<JeecgOrderTicket> deleteBatchTicket(@RequestParam(name = "ids", required = true) String ids){
|
||||
Result<JeecgOrderTicket> result = new Result<JeecgOrderTicket>();
|
||||
if(ids==null || "".equals(ids.trim())) {
|
||||
result.error500("参数不识别!");
|
||||
}else {
|
||||
this.ticketService.removeByIds(Arrays.asList(ids.split(",")));
|
||||
result.success("删除成功!");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*
|
||||
* @param jeecgOrderTicket
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/addTicket")
|
||||
public Result<JeecgOrderTicket> addTicket(@RequestBody JeecgOrderTicket jeecgOrderTicket) {
|
||||
Result<JeecgOrderTicket> result = new Result<>();
|
||||
try {
|
||||
boolean ok = ticketService.save(jeecgOrderTicket);
|
||||
if (ok) {
|
||||
result.setSuccess(true);
|
||||
result.setMessage("添加机票信息成功.");
|
||||
} else {
|
||||
result.setSuccess(false);
|
||||
result.setMessage("添加机票信息失败!");
|
||||
}
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
e.fillInStackTrace();
|
||||
result.setSuccess(false);
|
||||
result.setMessage("添加机票信息过程中出现了异常: " + e.getMessage());
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*
|
||||
* @param jeecgOrderTicket
|
||||
* @return
|
||||
*/
|
||||
@PutMapping("/editTicket")
|
||||
public Result<JeecgOrderTicket> editTicket(@RequestBody JeecgOrderTicket jeecgOrderTicket) {
|
||||
Result<JeecgOrderTicket> result = new Result<>();
|
||||
try {
|
||||
boolean ok = ticketService.updateById(jeecgOrderTicket);
|
||||
if (ok) {
|
||||
result.setSuccess(true);
|
||||
result.setMessage("更新数据成功.");
|
||||
} else {
|
||||
result.setSuccess(false);
|
||||
result.setMessage("更新机票 信息失败!");
|
||||
}
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
result.setSuccess(false);
|
||||
result.setMessage("更新数据过程中出现异常啦: " + e.getMessage());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id删除
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@DeleteMapping(value = "/deleteTicket")
|
||||
public Result<JeecgOrderTicket> deleteTicket(@RequestParam(name = "id", required = true) String id) {
|
||||
Result<JeecgOrderTicket> result = new Result<>();
|
||||
try {
|
||||
boolean ok = ticketService.removeById(id);
|
||||
if (ok) {
|
||||
result.setSuccess(true);
|
||||
result.setMessage("删除机票信息成功.");
|
||||
} else {
|
||||
result.setSuccess(false);
|
||||
result.setMessage("删除机票信息失败!");
|
||||
}
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
result.setSuccess(false);
|
||||
result.setMessage("删除机票信息过程中出现异常啦: " + e.getMessage());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
*
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
@DeleteMapping(value = "/deleteBatchTicket")
|
||||
public Result<JeecgOrderTicket> deleteBatchTicket(@RequestParam(name = "ids", required = true) String ids) {
|
||||
Result<JeecgOrderTicket> result = new Result<JeecgOrderTicket>();
|
||||
if (ids == null || "".equals(ids.trim())) {
|
||||
result.error500("参数不识别!");
|
||||
} else {
|
||||
this.ticketService.removeByIds(Arrays.asList(ids.split(",")));
|
||||
result.success("删除成功!");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,10 +1,17 @@
|
||||
package org.jeecg.modules.demo.test.controller;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
import org.jeecg.common.system.query.QueryGenerator;
|
||||
import org.jeecg.common.util.oConvertUtils;
|
||||
import org.jeecg.modules.demo.test.entity.JeecgOrderCustomer;
|
||||
import org.jeecg.modules.demo.test.entity.JeecgOrderMain;
|
||||
@ -13,6 +20,12 @@ import org.jeecg.modules.demo.test.service.IJeecgOrderCustomerService;
|
||||
import org.jeecg.modules.demo.test.service.IJeecgOrderMainService;
|
||||
import org.jeecg.modules.demo.test.service.IJeecgOrderTicketService;
|
||||
import org.jeecg.modules.demo.test.vo.JeecgOrderMainPage;
|
||||
import org.jeecgframework.poi.excel.ExcelImportUtil;
|
||||
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
|
||||
import org.jeecgframework.poi.excel.entity.ExportParams;
|
||||
import org.jeecgframework.poi.excel.entity.ImportParams;
|
||||
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@ -20,18 +33,25 @@ import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
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 lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
/**
|
||||
* @Title: Controller
|
||||
* @Description: 订单
|
||||
* @author: jeecg-boot
|
||||
* @date: 2019-02-15
|
||||
* @Description: 订单
|
||||
* @author: jeecg-boot
|
||||
* @date: 2019-02-15
|
||||
* @version: V1.0
|
||||
*/
|
||||
@RestController
|
||||
@ -44,9 +64,10 @@ public class JeecgOrderMainController {
|
||||
private IJeecgOrderCustomerService jeecgOrderCustomerService;
|
||||
@Autowired
|
||||
private IJeecgOrderTicketService jeecgOrderTicketService;
|
||||
|
||||
|
||||
/**
|
||||
* 分页列表查询
|
||||
* 分页列表查询
|
||||
*
|
||||
* @param jeecgOrderMain
|
||||
* @param pageNo
|
||||
* @param pageSize
|
||||
@ -54,35 +75,23 @@ public class JeecgOrderMainController {
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/list")
|
||||
public Result<IPage<JeecgOrderMain>> queryPageList(JeecgOrderMain jeecgOrderMain,
|
||||
@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
|
||||
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
|
||||
HttpServletRequest req) {
|
||||
public Result<IPage<JeecgOrderMain>> queryPageList(JeecgOrderMain jeecgOrderMain, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest req) {
|
||||
Result<IPage<JeecgOrderMain>> result = new Result<IPage<JeecgOrderMain>>();
|
||||
QueryWrapper<JeecgOrderMain> queryWrapper = new QueryWrapper<JeecgOrderMain>(jeecgOrderMain);
|
||||
Page<JeecgOrderMain> page = new Page<JeecgOrderMain>(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));
|
||||
}
|
||||
}
|
||||
QueryWrapper<JeecgOrderMain> queryWrapper = QueryGenerator.initQueryWrapper(jeecgOrderMain, req.getParameterMap());
|
||||
Page<JeecgOrderMain> page = new Page<JeecgOrderMain>(pageNo, pageSize);
|
||||
IPage<JeecgOrderMain> pageList = jeecgOrderMainService.page(page, queryWrapper);
|
||||
//log.debug("查询当前页:"+pageList.getCurrent());
|
||||
//log.debug("查询当前页数量:"+pageList.getSize());
|
||||
//log.debug("查询结果数量:"+pageList.getRecords().size());
|
||||
//log.debug("数据总数:"+pageList.getTotal());
|
||||
// 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 jeecgOrderMain
|
||||
* @return
|
||||
*/
|
||||
@ -90,7 +99,9 @@ public class JeecgOrderMainController {
|
||||
public Result<JeecgOrderMain> add(@RequestBody JeecgOrderMainPage jeecgOrderMainPage) {
|
||||
Result<JeecgOrderMain> result = new Result<JeecgOrderMain>();
|
||||
try {
|
||||
jeecgOrderMainService.saveMain(jeecgOrderMainPage.getJeecgOrderMain(), jeecgOrderMainPage.getJeecgOrderCustomerList(), jeecgOrderMainPage.getJeecgOrderTicketList());;
|
||||
JeecgOrderMain jeecgOrderMain = new JeecgOrderMain();
|
||||
BeanUtils.copyProperties(jeecgOrderMainPage, jeecgOrderMain);
|
||||
jeecgOrderMainService.saveMain(jeecgOrderMain, jeecgOrderMainPage.getJeecgOrderCustomerList(), jeecgOrderMainPage.getJeecgOrderTicketList());
|
||||
result.success("添加成功!");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@ -99,102 +110,109 @@ public class JeecgOrderMainController {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
* 编辑
|
||||
*
|
||||
* @param jeecgOrderMain
|
||||
* @return
|
||||
*/
|
||||
@PutMapping(value = "/edit")
|
||||
public Result<JeecgOrderMain> eidt(@RequestBody JeecgOrderMainPage jeecgOrderMainPage) {
|
||||
Result<JeecgOrderMain> result = new Result<JeecgOrderMain>();
|
||||
JeecgOrderMain jeecgOrderMain = jeecgOrderMainPage.getJeecgOrderMain();
|
||||
JeecgOrderMain jeecgOrderMain = new JeecgOrderMain();
|
||||
BeanUtils.copyProperties(jeecgOrderMainPage, jeecgOrderMain);
|
||||
JeecgOrderMain jeecgOrderMainEntity = jeecgOrderMainService.getById(jeecgOrderMain.getId());
|
||||
if(jeecgOrderMainEntity==null) {
|
||||
if (jeecgOrderMainEntity == null) {
|
||||
result.error500("未找到对应实体");
|
||||
}else {
|
||||
} else {
|
||||
jeecgOrderMainService.updateMain(jeecgOrderMain, jeecgOrderMainPage.getJeecgOrderCustomerList(), jeecgOrderMainPage.getJeecgOrderTicketList());
|
||||
result.success("修改成功!");
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 通过id删除
|
||||
* 通过id删除
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@DeleteMapping(value = "/delete")
|
||||
public Result<JeecgOrderMain> delete(@RequestParam(name="id",required=true) String id) {
|
||||
public Result<JeecgOrderMain> delete(@RequestParam(name = "id", required = true) String id) {
|
||||
Result<JeecgOrderMain> result = new Result<JeecgOrderMain>();
|
||||
JeecgOrderMain jeecgOrderMain = jeecgOrderMainService.getById(id);
|
||||
if(jeecgOrderMain==null) {
|
||||
if (jeecgOrderMain == null) {
|
||||
result.error500("未找到对应实体");
|
||||
}else {
|
||||
} else {
|
||||
jeecgOrderMainService.delMain(id);
|
||||
result.success("删除成功!");
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
* 批量删除
|
||||
*
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
@DeleteMapping(value = "/deleteBatch")
|
||||
public Result<JeecgOrderMain> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
|
||||
public Result<JeecgOrderMain> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
|
||||
Result<JeecgOrderMain> result = new Result<JeecgOrderMain>();
|
||||
if(ids==null || "".equals(ids.trim())) {
|
||||
if (ids == null || "".equals(ids.trim())) {
|
||||
result.error500("参数不识别!");
|
||||
}else {
|
||||
this.jeecgOrderMainService.removeByIds(Arrays.asList(ids.split(",")));
|
||||
} else {
|
||||
this.jeecgOrderMainService.delBatchMain(Arrays.asList(ids.split(",")));
|
||||
result.success("删除成功!");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 通过id查询
|
||||
* 通过id查询
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/queryById")
|
||||
public Result<JeecgOrderMain> queryById(@RequestParam(name="id",required=true) String id) {
|
||||
public Result<JeecgOrderMain> queryById(@RequestParam(name = "id", required = true) String id) {
|
||||
Result<JeecgOrderMain> result = new Result<JeecgOrderMain>();
|
||||
JeecgOrderMain jeecgOrderMain = jeecgOrderMainService.getById(id);
|
||||
if(jeecgOrderMain==null) {
|
||||
if (jeecgOrderMain == null) {
|
||||
result.error500("未找到对应实体");
|
||||
}else {
|
||||
} else {
|
||||
result.setResult(jeecgOrderMain);
|
||||
result.setSuccess(true);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 通过id查询
|
||||
* 通过id查询
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/queryOrderCustomerListByMainId")
|
||||
public Result<List<JeecgOrderCustomer>> queryOrderCustomerListByMainId(@RequestParam(name="id",required=true) String id) {
|
||||
public Result<List<JeecgOrderCustomer>> queryOrderCustomerListByMainId(@RequestParam(name = "id", required = true) String id) {
|
||||
Result<List<JeecgOrderCustomer>> result = new Result<List<JeecgOrderCustomer>>();
|
||||
List<JeecgOrderCustomer> jeecgOrderCustomerList = jeecgOrderCustomerService.selectCustomersByMainId(id);
|
||||
result.setResult(jeecgOrderCustomerList);
|
||||
result.setSuccess(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 通过id查询
|
||||
* 通过id查询
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/queryOrderTicketListByMainId")
|
||||
public Result<List<JeecgOrderTicket>> queryOrderTicketListByMainId(@RequestParam(name="id",required=true) String id) {
|
||||
public Result<List<JeecgOrderTicket>> queryOrderTicketListByMainId(@RequestParam(name = "id", required = true) String id) {
|
||||
Result<List<JeecgOrderTicket>> result = new Result<List<JeecgOrderTicket>>();
|
||||
List<JeecgOrderTicket> jeecgOrderTicketList = jeecgOrderTicketService.selectTicketsByMainId(id);
|
||||
result.setResult(jeecgOrderTicketList);
|
||||
@ -202,4 +220,94 @@ public class JeecgOrderMainController {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出excel
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
*/
|
||||
@RequestMapping(value = "/exportXls")
|
||||
public ModelAndView exportXls(HttpServletRequest request, HttpServletResponse response) {
|
||||
// Step.1 组装查询条件
|
||||
QueryWrapper<JeecgOrderMain> queryWrapper = null;
|
||||
try {
|
||||
String paramsStr = request.getParameter("paramsStr");
|
||||
if (oConvertUtils.isNotEmpty(paramsStr)) {
|
||||
String deString = URLDecoder.decode(paramsStr, "UTF-8");
|
||||
JeecgOrderMain jeecgOrderMain = JSON.parseObject(deString, JeecgOrderMain.class);
|
||||
queryWrapper = QueryGenerator.initQueryWrapper(jeecgOrderMain, request.getParameterMap());
|
||||
log.info(paramsStr);
|
||||
log.info(jeecgOrderMain.toString());
|
||||
}
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
//Step.2 AutoPoi 导出Excel
|
||||
ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
|
||||
List<JeecgOrderMainPage> pageList = new ArrayList<JeecgOrderMainPage>();
|
||||
|
||||
List<JeecgOrderMain> jeecgOrderMainList = jeecgOrderMainService.list(queryWrapper);
|
||||
for (JeecgOrderMain orderMain : jeecgOrderMainList) {
|
||||
JeecgOrderMainPage vo = new JeecgOrderMainPage();
|
||||
BeanUtils.copyProperties(orderMain, vo);
|
||||
// 查询机票
|
||||
List<JeecgOrderTicket> jeecgOrderTicketList = jeecgOrderTicketService.selectTicketsByMainId(orderMain.getId());
|
||||
vo.setJeecgOrderTicketList(jeecgOrderTicketList);
|
||||
// 查询客户
|
||||
List<JeecgOrderCustomer> jeecgOrderCustomerList = jeecgOrderCustomerService.selectCustomersByMainId(orderMain.getId());
|
||||
vo.setJeecgOrderCustomerList(jeecgOrderCustomerList);
|
||||
pageList.add(vo);
|
||||
}
|
||||
|
||||
// 导出文件名称
|
||||
mv.addObject(NormalExcelConstants.FILE_NAME, "一对多导出文件名字");
|
||||
// 注解对象Class
|
||||
mv.addObject(NormalExcelConstants.CLASS, JeecgOrderMainPage.class);
|
||||
// 自定义表格参数
|
||||
mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("自定义导出Excel内容标题", "导出人:Jeecg", "自定义Sheet名字"));
|
||||
// 导出数据列表
|
||||
mv.addObject(NormalExcelConstants.DATA_LIST, pageList);
|
||||
return mv;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过excel导入数据
|
||||
*
|
||||
* @param request
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/importExcel", method = RequestMethod.POST)
|
||||
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
|
||||
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
||||
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
|
||||
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
|
||||
MultipartFile file = entity.getValue();// 获取上传文件对象
|
||||
ImportParams params = new ImportParams();
|
||||
params.setTitleRows(2);
|
||||
params.setHeadRows(2);
|
||||
params.setNeedSave(true);
|
||||
try {
|
||||
List<JeecgOrderMainPage> list = ExcelImportUtil.importExcel(file.getInputStream(), JeecgOrderMainPage.class, params);
|
||||
for (JeecgOrderMainPage page : list) {
|
||||
JeecgOrderMain po = new JeecgOrderMain();
|
||||
BeanUtils.copyProperties(page, po);
|
||||
jeecgOrderMainService.saveMain(po, page.getJeecgOrderCustomerList(), page.getJeecgOrderTicketList());
|
||||
}
|
||||
return Result.ok("文件导入成功!");
|
||||
} catch (Exception e) {
|
||||
log.error(e.toString());
|
||||
return Result.ok("文件导入失败!");
|
||||
} finally {
|
||||
try {
|
||||
file.getInputStream().close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return Result.ok("文件导入失败!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -7,6 +7,8 @@ import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
|
||||
import org.jeecgframework.poi.excel.annotation.Excel;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
/**
|
||||
@ -24,26 +26,35 @@ public class JeecgDemo implements Serializable {
|
||||
@TableId(type = IdType.UUID)
|
||||
private java.lang.String id;
|
||||
/** 姓名 */
|
||||
@Excel(name="姓名",width=25)
|
||||
private java.lang.String name;
|
||||
/** 关键词 */
|
||||
@Excel(name="关键词",width=15)
|
||||
private java.lang.String keyWord;
|
||||
/** 打卡时间 */
|
||||
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@Excel(name="打卡时间",width=20,format="yyyy-MM-dd HH:mm:ss")
|
||||
private java.util.Date punchTime;
|
||||
/** 工资 */
|
||||
@Excel(name="工资",width=15)
|
||||
private java.math.BigDecimal salaryMoney;
|
||||
/** 奖金 */
|
||||
@Excel(name="奖金",width=15)
|
||||
private java.lang.Double bonusMoney;
|
||||
/** 性别 {男:1,女:2} */
|
||||
@Excel(name = "性别", width = 15, dicCode = "sex")
|
||||
private java.lang.String sex;
|
||||
/** 年龄 */
|
||||
@Excel(name="年龄",width=15)
|
||||
private java.lang.Integer age;
|
||||
/** 生日 */
|
||||
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
||||
@Excel(name="生日",format="yyyy-MM-dd")
|
||||
private java.util.Date birthday;
|
||||
/** 邮箱 */
|
||||
@Excel(name="邮箱",width=30)
|
||||
private java.lang.String email;
|
||||
/** 个人简介 */
|
||||
private java.lang.String content;
|
||||
|
||||
@ -1,12 +1,13 @@
|
||||
package org.jeecg.modules.demo.test.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
|
||||
import org.jeecgframework.poi.excel.annotation.Excel;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
/**
|
||||
@ -24,14 +25,17 @@ public class JeecgOrderCustomer implements Serializable {
|
||||
@TableId(type = IdType.UUID)
|
||||
private java.lang.String id;
|
||||
/**客户名*/
|
||||
@Excel(name="客户名字",width=15)
|
||||
private java.lang.String name;
|
||||
/**性别*/
|
||||
private java.lang.String sex;
|
||||
/**身份证号码*/
|
||||
@Excel(name="身份证号码",width=15)
|
||||
private java.lang.String idcard;
|
||||
/**身份证扫描件*/
|
||||
private java.lang.String idcardPic;
|
||||
/**电话1*/
|
||||
@Excel(name="电话",width=15)
|
||||
private java.lang.String telphone;
|
||||
/**外键*/
|
||||
private java.lang.String orderId;
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
package org.jeecg.modules.demo.test.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import org.jeecgframework.poi.excel.annotation.Excel;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
/**
|
||||
@ -24,10 +24,12 @@ public class JeecgOrderTicket implements Serializable {
|
||||
@TableId(type = IdType.UUID)
|
||||
private java.lang.String id;
|
||||
/**航班号*/
|
||||
@Excel(name="航班号",width=15)
|
||||
private java.lang.String ticketCode;
|
||||
/**航班时间*/
|
||||
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
|
||||
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
|
||||
@Excel(name="航班时间",width=15,format = "yyyy-MM-dd")
|
||||
private java.util.Date tickectDate;
|
||||
/**外键*/
|
||||
private java.lang.String orderId;
|
||||
|
||||
@ -26,6 +26,7 @@ public class JeecgDemoServiceImpl extends ServiceImpl<JeecgDemoMapper, JeecgDemo
|
||||
* 事务控制在service层面
|
||||
* 加上注解:@Transactional,声明的方法就是一个独立的事务(有异常DB操作全部回滚)
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public void testTran() {
|
||||
JeecgDemo pp = new JeecgDemo();
|
||||
@ -51,9 +52,11 @@ public class JeecgDemoServiceImpl extends ServiceImpl<JeecgDemoMapper, JeecgDemo
|
||||
/**
|
||||
* 缓存注解测试: redis
|
||||
*/
|
||||
@Override
|
||||
@Cacheable(cacheNames="jeecgDemo", key="#id")
|
||||
public JeecgDemo getByIdCacheable(String id) {
|
||||
JeecgDemo t = jeecgDemoMapper.selectById(id);
|
||||
System.err.println("---未读缓存,读取数据库---");
|
||||
System.err.println(t);
|
||||
return t;
|
||||
}
|
||||
|
||||
@ -26,46 +26,54 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
@Service
|
||||
public class JeecgOrderMainServiceImpl extends ServiceImpl<JeecgOrderMainMapper, JeecgOrderMain> implements IJeecgOrderMainService {
|
||||
|
||||
@Autowired
|
||||
private JeecgOrderMainMapper jeecgOrderMainMapper;
|
||||
@Autowired
|
||||
private JeecgOrderCustomerMapper jeecgOrderCustomerMapper;
|
||||
@Autowired
|
||||
private JeecgOrderTicketMapper jeecgOrderTicketMapper;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void saveMain(JeecgOrderMain jeecgOrderMain, List<JeecgOrderCustomer> jeecgOrderCustomerList, List<JeecgOrderTicket> jeecgOrderTicketList) {
|
||||
jeecgOrderMainMapper.insert(jeecgOrderMain);
|
||||
for(JeecgOrderCustomer entity:jeecgOrderCustomerList) {
|
||||
entity.setOrderId(jeecgOrderMain.getId());
|
||||
jeecgOrderCustomerMapper.insert(entity);
|
||||
}
|
||||
for(JeecgOrderTicket entity:jeecgOrderTicketList) {
|
||||
entity.setOrderId(jeecgOrderMain.getId());
|
||||
jeecgOrderTicketMapper.insert(entity);
|
||||
}
|
||||
}
|
||||
@Autowired
|
||||
private JeecgOrderMainMapper jeecgOrderMainMapper;
|
||||
@Autowired
|
||||
private JeecgOrderCustomerMapper jeecgOrderCustomerMapper;
|
||||
@Autowired
|
||||
private JeecgOrderTicketMapper jeecgOrderTicketMapper;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void updateMain(JeecgOrderMain jeecgOrderMain, List<JeecgOrderCustomer> jeecgOrderCustomerList, List<JeecgOrderTicket> jeecgOrderTicketList) {
|
||||
jeecgOrderMainMapper.updateById(jeecgOrderMain);
|
||||
|
||||
//1.先删除子表数据
|
||||
jeecgOrderTicketMapper.deleteTicketsByMainId(jeecgOrderMain.getId());
|
||||
jeecgOrderCustomerMapper.deleteCustomersByMainId(jeecgOrderMain.getId());
|
||||
|
||||
//2.子表数据重新插入
|
||||
for(JeecgOrderCustomer entity:jeecgOrderCustomerList) {
|
||||
entity.setOrderId(jeecgOrderMain.getId());
|
||||
jeecgOrderCustomerMapper.insert(entity);
|
||||
}
|
||||
for(JeecgOrderTicket entity:jeecgOrderTicketList) {
|
||||
entity.setOrderId(jeecgOrderMain.getId());
|
||||
jeecgOrderTicketMapper.insert(entity);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
@Transactional
|
||||
public void saveMain(JeecgOrderMain jeecgOrderMain, List<JeecgOrderCustomer> jeecgOrderCustomerList, List<JeecgOrderTicket> jeecgOrderTicketList) {
|
||||
jeecgOrderMainMapper.insert(jeecgOrderMain);
|
||||
if (jeecgOrderCustomerList != null) {
|
||||
for (JeecgOrderCustomer entity : jeecgOrderCustomerList) {
|
||||
entity.setOrderId(jeecgOrderMain.getId());
|
||||
jeecgOrderCustomerMapper.insert(entity);
|
||||
}
|
||||
}
|
||||
if (jeecgOrderTicketList != null) {
|
||||
for (JeecgOrderTicket entity : jeecgOrderTicketList) {
|
||||
entity.setOrderId(jeecgOrderMain.getId());
|
||||
jeecgOrderTicketMapper.insert(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void updateMain(JeecgOrderMain jeecgOrderMain, List<JeecgOrderCustomer> jeecgOrderCustomerList, List<JeecgOrderTicket> jeecgOrderTicketList) {
|
||||
jeecgOrderMainMapper.updateById(jeecgOrderMain);
|
||||
|
||||
//1.先删除子表数据
|
||||
jeecgOrderTicketMapper.deleteTicketsByMainId(jeecgOrderMain.getId());
|
||||
jeecgOrderCustomerMapper.deleteCustomersByMainId(jeecgOrderMain.getId());
|
||||
|
||||
//2.子表数据重新插入
|
||||
if (jeecgOrderCustomerList != null) {
|
||||
for (JeecgOrderCustomer entity : jeecgOrderCustomerList) {
|
||||
entity.setOrderId(jeecgOrderMain.getId());
|
||||
jeecgOrderCustomerMapper.insert(entity);
|
||||
}
|
||||
}
|
||||
if (jeecgOrderTicketList != null) {
|
||||
for (JeecgOrderTicket entity : jeecgOrderTicketList) {
|
||||
entity.setOrderId(jeecgOrderMain.getId());
|
||||
jeecgOrderTicketMapper.insert(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
|
||||
@ -1,16 +1,44 @@
|
||||
package org.jeecg.modules.demo.test.vo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.jeecg.modules.demo.test.entity.JeecgOrderCustomer;
|
||||
import org.jeecg.modules.demo.test.entity.JeecgOrderMain;
|
||||
import org.jeecg.modules.demo.test.entity.JeecgOrderTicket;
|
||||
import org.jeecgframework.poi.excel.annotation.Excel;
|
||||
import org.jeecgframework.poi.excel.annotation.ExcelCollection;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class JeecgOrderMainPage {
|
||||
|
||||
private JeecgOrderMain jeecgOrderMain;
|
||||
/**主键*/
|
||||
private java.lang.String id;
|
||||
/**订单号*/
|
||||
@Excel(name="订单号",width=15)
|
||||
private java.lang.String orderCode;
|
||||
/**订单类型*/
|
||||
private java.lang.String ctype;
|
||||
/**订单日期*/
|
||||
@Excel(name="订单日期",width=15,format = "yyyy-MM-dd")
|
||||
private java.util.Date orderDate;
|
||||
/**订单金额*/
|
||||
@Excel(name="订单金额",width=15)
|
||||
private java.lang.Double orderMoney;
|
||||
/**订单备注*/
|
||||
private java.lang.String content;
|
||||
/**创建人*/
|
||||
private java.lang.String createBy;
|
||||
/**创建时间*/
|
||||
private java.util.Date createTime;
|
||||
/**修改人*/
|
||||
private java.lang.String updateBy;
|
||||
/**修改时间*/
|
||||
private java.util.Date updateTime;
|
||||
|
||||
@ExcelCollection(name="客户")
|
||||
private List<JeecgOrderCustomer> jeecgOrderCustomerList;
|
||||
@ExcelCollection(name="机票")
|
||||
private List<JeecgOrderTicket> jeecgOrderTicketList;
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,237 @@
|
||||
package org.jeecg.modules.message.controller;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLDecoder;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
import org.jeecg.common.system.query.QueryGenerator;
|
||||
import org.jeecg.common.util.oConvertUtils;
|
||||
import org.jeecg.modules.message.entity.SysMessage;
|
||||
import org.jeecg.modules.message.service.ISysMessageService;
|
||||
|
||||
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 org.jeecgframework.poi.excel.ExcelImportUtil;
|
||||
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
|
||||
import org.jeecgframework.poi.excel.entity.ExportParams;
|
||||
import org.jeecgframework.poi.excel.entity.ImportParams;
|
||||
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
|
||||
|
||||
import org.springframework.beans.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.alibaba.fastjson.JSON;
|
||||
|
||||
/**
|
||||
* @Title: Controller
|
||||
* @Description: 消息
|
||||
* @author: jeecg-boot
|
||||
* @date: 2019-04-09
|
||||
* @version: V1.0
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/message/sysMessage")
|
||||
@Slf4j
|
||||
public class SysMessageController {
|
||||
@Autowired
|
||||
private ISysMessageService sysMessageService;
|
||||
|
||||
/**
|
||||
* 分页列表查询
|
||||
* @param sysMessage
|
||||
* @param pageNo
|
||||
* @param pageSize
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/list")
|
||||
public Result<IPage<SysMessage>> queryPageList(SysMessage sysMessage,
|
||||
@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
|
||||
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
|
||||
HttpServletRequest req) {
|
||||
Result<IPage<SysMessage>> result = new Result<IPage<SysMessage>>();
|
||||
QueryWrapper<SysMessage> queryWrapper = QueryGenerator.initQueryWrapper(sysMessage, req.getParameterMap());
|
||||
Page<SysMessage> page = new Page<SysMessage>(pageNo, pageSize);
|
||||
IPage<SysMessage> pageList = sysMessageService.page(page, queryWrapper);
|
||||
result.setSuccess(true);
|
||||
result.setResult(pageList);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
* @param sysMessage
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/add")
|
||||
public Result<SysMessage> add(@RequestBody SysMessage sysMessage) {
|
||||
Result<SysMessage> result = new Result<SysMessage>();
|
||||
try {
|
||||
sysMessageService.save(sysMessage);
|
||||
result.success("添加成功!");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.info(e.getMessage());
|
||||
result.error500("操作失败");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
* @param sysMessage
|
||||
* @return
|
||||
*/
|
||||
@PutMapping(value = "/edit")
|
||||
public Result<SysMessage> edit(@RequestBody SysMessage sysMessage) {
|
||||
Result<SysMessage> result = new Result<SysMessage>();
|
||||
SysMessage sysMessageEntity = sysMessageService.getById(sysMessage.getId());
|
||||
if(sysMessageEntity==null) {
|
||||
result.error500("未找到对应实体");
|
||||
}else {
|
||||
boolean ok = sysMessageService.updateById(sysMessage);
|
||||
//TODO 返回false说明什么?
|
||||
if(ok) {
|
||||
result.success("修改成功!");
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id删除
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@DeleteMapping(value = "/delete")
|
||||
public Result<SysMessage> delete(@RequestParam(name="id",required=true) String id) {
|
||||
Result<SysMessage> result = new Result<SysMessage>();
|
||||
SysMessage sysMessage = sysMessageService.getById(id);
|
||||
if(sysMessage==null) {
|
||||
result.error500("未找到对应实体");
|
||||
}else {
|
||||
boolean ok = sysMessageService.removeById(id);
|
||||
if(ok) {
|
||||
result.success("删除成功!");
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
@DeleteMapping(value = "/deleteBatch")
|
||||
public Result<SysMessage> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
|
||||
Result<SysMessage> result = new Result<SysMessage>();
|
||||
if(ids==null || "".equals(ids.trim())) {
|
||||
result.error500("参数不识别!");
|
||||
}else {
|
||||
this.sysMessageService.removeByIds(Arrays.asList(ids.split(",")));
|
||||
result.success("删除成功!");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id查询
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/queryById")
|
||||
public Result<SysMessage> queryById(@RequestParam(name="id",required=true) String id) {
|
||||
Result<SysMessage> result = new Result<SysMessage>();
|
||||
SysMessage sysMessage = sysMessageService.getById(id);
|
||||
if(sysMessage==null) {
|
||||
result.error500("未找到对应实体");
|
||||
}else {
|
||||
result.setResult(sysMessage);
|
||||
result.setSuccess(true);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出excel
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
*/
|
||||
@RequestMapping(value = "/exportXls")
|
||||
public ModelAndView exportXls(HttpServletRequest request, HttpServletResponse response) {
|
||||
// Step.1 组装查询条件
|
||||
QueryWrapper<SysMessage> queryWrapper = null;
|
||||
try {
|
||||
String paramsStr = request.getParameter("paramsStr");
|
||||
if (oConvertUtils.isNotEmpty(paramsStr)) {
|
||||
String deString = URLDecoder.decode(paramsStr, "UTF-8");
|
||||
SysMessage sysMessage = JSON.parseObject(deString, SysMessage.class);
|
||||
queryWrapper = QueryGenerator.initQueryWrapper(sysMessage, request.getParameterMap());
|
||||
}
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
//Step.2 AutoPoi 导出Excel
|
||||
ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
|
||||
List<SysMessage> pageList = sysMessageService.list(queryWrapper);
|
||||
//导出文件名称
|
||||
mv.addObject(NormalExcelConstants.FILE_NAME, "消息列表");
|
||||
mv.addObject(NormalExcelConstants.CLASS, SysMessage.class);
|
||||
mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("消息列表数据", "导出人:Jeecg", "导出信息"));
|
||||
mv.addObject(NormalExcelConstants.DATA_LIST, pageList);
|
||||
return mv;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过excel导入数据
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/importExcel", method = RequestMethod.POST)
|
||||
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
|
||||
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
||||
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
|
||||
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
|
||||
MultipartFile file = entity.getValue();// 获取上传文件对象
|
||||
ImportParams params = new ImportParams();
|
||||
params.setTitleRows(2);
|
||||
params.setHeadRows(1);
|
||||
params.setNeedSave(true);
|
||||
try {
|
||||
List<SysMessage> listSysMessages = ExcelImportUtil.importExcel(file.getInputStream(), SysMessage.class, params);
|
||||
for (SysMessage sysMessageExcel : listSysMessages) {
|
||||
sysMessageService.save(sysMessageExcel);
|
||||
}
|
||||
return Result.ok("文件导入成功!数据行数:" + listSysMessages.size());
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
return Result.error("文件导入失败!");
|
||||
} finally {
|
||||
try {
|
||||
file.getInputStream().close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return Result.ok("文件导入失败!");
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,267 @@
|
||||
package org.jeecg.modules.message.controller;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLDecoder;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
import org.jeecg.common.system.query.QueryGenerator;
|
||||
import org.jeecg.common.util.oConvertUtils;
|
||||
import org.jeecg.modules.message.entity.MsgParams;
|
||||
import org.jeecg.modules.message.entity.SysMessage;
|
||||
import org.jeecg.modules.message.entity.SysMessageTemplate;
|
||||
import org.jeecg.modules.message.service.ISysMessageService;
|
||||
import org.jeecg.modules.message.service.ISysMessageTemplateService;
|
||||
import org.jeecg.modules.message.util.PushMsgUtil;
|
||||
|
||||
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 org.jeecgframework.poi.excel.ExcelImportUtil;
|
||||
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
|
||||
import org.jeecgframework.poi.excel.entity.ExportParams;
|
||||
import org.jeecgframework.poi.excel.entity.ImportParams;
|
||||
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
|
||||
|
||||
import org.springframework.beans.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.alibaba.fastjson.JSON;
|
||||
|
||||
/**
|
||||
* @Title: Controller
|
||||
* @Description: 消息模板
|
||||
* @author: jeecg-boot
|
||||
* @date: 2019-04-09
|
||||
* @version: V1.0
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/message/sysMessageTemplate")
|
||||
@Slf4j
|
||||
public class SysMessageTemplateController {
|
||||
@Autowired
|
||||
private ISysMessageTemplateService sysMessageTemplateService;
|
||||
@Autowired
|
||||
private ISysMessageService sysMessageService;
|
||||
@Autowired
|
||||
private PushMsgUtil pushMsgUtil;
|
||||
|
||||
/**
|
||||
* 分页列表查询
|
||||
* @param sysMessageTemplate
|
||||
* @param pageNo
|
||||
* @param pageSize
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/list")
|
||||
public Result<IPage<SysMessageTemplate>> queryPageList(SysMessageTemplate sysMessageTemplate,
|
||||
@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
|
||||
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
|
||||
HttpServletRequest req) {
|
||||
Result<IPage<SysMessageTemplate>> result = new Result<IPage<SysMessageTemplate>>();
|
||||
QueryWrapper<SysMessageTemplate> queryWrapper = QueryGenerator.initQueryWrapper(sysMessageTemplate, req.getParameterMap());
|
||||
Page<SysMessageTemplate> page = new Page<SysMessageTemplate>(pageNo, pageSize);
|
||||
IPage<SysMessageTemplate> pageList = sysMessageTemplateService.page(page, queryWrapper);
|
||||
result.setSuccess(true);
|
||||
result.setResult(pageList);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
* @param sysMessageTemplate
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/add")
|
||||
public Result<SysMessageTemplate> add(@RequestBody SysMessageTemplate sysMessageTemplate) {
|
||||
Result<SysMessageTemplate> result = new Result<SysMessageTemplate>();
|
||||
try {
|
||||
sysMessageTemplateService.save(sysMessageTemplate);
|
||||
result.success("添加成功!");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.info(e.getMessage());
|
||||
result.error500("操作失败");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
* @param sysMessageTemplate
|
||||
* @return
|
||||
*/
|
||||
@PutMapping(value = "/edit")
|
||||
public Result<SysMessageTemplate> edit(@RequestBody SysMessageTemplate sysMessageTemplate) {
|
||||
Result<SysMessageTemplate> result = new Result<SysMessageTemplate>();
|
||||
SysMessageTemplate sysMessageTemplateEntity = sysMessageTemplateService.getById(sysMessageTemplate.getId());
|
||||
if(sysMessageTemplateEntity==null) {
|
||||
result.error500("未找到对应实体");
|
||||
}else {
|
||||
boolean ok = sysMessageTemplateService.updateById(sysMessageTemplate);
|
||||
//TODO 返回false说明什么?
|
||||
if(ok) {
|
||||
result.success("修改成功!");
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id删除
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@DeleteMapping(value = "/delete")
|
||||
public Result<SysMessageTemplate> delete(@RequestParam(name="id",required=true) String id) {
|
||||
Result<SysMessageTemplate> result = new Result<SysMessageTemplate>();
|
||||
SysMessageTemplate sysMessageTemplate = sysMessageTemplateService.getById(id);
|
||||
if(sysMessageTemplate==null) {
|
||||
result.error500("未找到对应实体");
|
||||
}else {
|
||||
boolean ok = sysMessageTemplateService.removeById(id);
|
||||
if(ok) {
|
||||
result.success("删除成功!");
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
@DeleteMapping(value = "/deleteBatch")
|
||||
public Result<SysMessageTemplate> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
|
||||
Result<SysMessageTemplate> result = new Result<SysMessageTemplate>();
|
||||
if(ids==null || "".equals(ids.trim())) {
|
||||
result.error500("参数不识别!");
|
||||
}else {
|
||||
this.sysMessageTemplateService.removeByIds(Arrays.asList(ids.split(",")));
|
||||
result.success("删除成功!");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id查询
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/queryById")
|
||||
public Result<SysMessageTemplate> queryById(@RequestParam(name="id",required=true) String id) {
|
||||
Result<SysMessageTemplate> result = new Result<SysMessageTemplate>();
|
||||
SysMessageTemplate sysMessageTemplate = sysMessageTemplateService.getById(id);
|
||||
if(sysMessageTemplate==null) {
|
||||
result.error500("未找到对应实体");
|
||||
}else {
|
||||
result.setResult(sysMessageTemplate);
|
||||
result.setSuccess(true);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出excel
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
*/
|
||||
@RequestMapping(value = "/exportXls")
|
||||
public ModelAndView exportXls(HttpServletRequest request, HttpServletResponse response) {
|
||||
// Step.1 组装查询条件
|
||||
QueryWrapper<SysMessageTemplate> queryWrapper = null;
|
||||
try {
|
||||
String paramsStr = request.getParameter("paramsStr");
|
||||
if (oConvertUtils.isNotEmpty(paramsStr)) {
|
||||
String deString = URLDecoder.decode(paramsStr, "UTF-8");
|
||||
SysMessageTemplate sysMessageTemplate = JSON.parseObject(deString, SysMessageTemplate.class);
|
||||
queryWrapper = QueryGenerator.initQueryWrapper(sysMessageTemplate, request.getParameterMap());
|
||||
}
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
//Step.2 AutoPoi 导出Excel
|
||||
ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
|
||||
List<SysMessageTemplate> pageList = sysMessageTemplateService.list(queryWrapper);
|
||||
//导出文件名称
|
||||
mv.addObject(NormalExcelConstants.FILE_NAME, "消息模板列表");
|
||||
mv.addObject(NormalExcelConstants.CLASS, SysMessageTemplate.class);
|
||||
mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("消息模板列表数据", "导出人:Jeecg", "导出信息"));
|
||||
mv.addObject(NormalExcelConstants.DATA_LIST, pageList);
|
||||
return mv;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过excel导入数据
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/importExcel", method = RequestMethod.POST)
|
||||
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
|
||||
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
||||
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
|
||||
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
|
||||
MultipartFile file = entity.getValue();// 获取上传文件对象
|
||||
ImportParams params = new ImportParams();
|
||||
params.setTitleRows(2);
|
||||
params.setHeadRows(1);
|
||||
params.setNeedSave(true);
|
||||
try {
|
||||
List<SysMessageTemplate> listSysMessageTemplates = ExcelImportUtil.importExcel(file.getInputStream(), SysMessageTemplate.class, params);
|
||||
for (SysMessageTemplate sysMessageTemplateExcel : listSysMessageTemplates) {
|
||||
sysMessageTemplateService.save(sysMessageTemplateExcel);
|
||||
}
|
||||
return Result.ok("文件导入成功!数据行数:" + listSysMessageTemplates.size());
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
return Result.error("文件导入失败!");
|
||||
} finally {
|
||||
try {
|
||||
file.getInputStream().close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return Result.ok("文件导入失败!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送消息
|
||||
*/
|
||||
@PostMapping(value = "/sendMsg")
|
||||
public Result<SysMessageTemplate> sendMessage(@RequestBody MsgParams msgParams) {
|
||||
Result<SysMessageTemplate> result = new Result<SysMessageTemplate>();
|
||||
Map<String, String> map = null;
|
||||
try {
|
||||
map = (Map<String, String>) JSON.parse(msgParams.getTestData());
|
||||
} catch (Exception e) {
|
||||
result.error500("解析Json出错!");
|
||||
return result;
|
||||
}
|
||||
boolean is_sendSuccess = pushMsgUtil.sendMessage(msgParams.getMsgType(), msgParams.getTemplateCode(), map,
|
||||
msgParams.getReceiver());
|
||||
if (is_sendSuccess)
|
||||
result.success("发送消息任务添加成功!");
|
||||
else
|
||||
result.error500("发送消息任务添加失败!");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,23 @@
|
||||
package org.jeecg.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,75 @@
|
||||
package org.jeecg.modules.message.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import org.jeecgframework.poi.excel.annotation.Excel;
|
||||
|
||||
/**
|
||||
* @Description: 消息
|
||||
* @author: jeecg-boot
|
||||
* @date: 2019-04-09
|
||||
* @version: V1.0
|
||||
*/
|
||||
@Data
|
||||
@TableName("sys_sms")
|
||||
public class SysMessage implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**创建人登录名称*/
|
||||
@Excel(name = "创建人登录名称", width = 15)
|
||||
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")
|
||||
private java.util.Date createTime;
|
||||
/**推送内容*/
|
||||
@Excel(name = "推送内容", width = 15)
|
||||
private java.lang.Object 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)
|
||||
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)
|
||||
private java.lang.String esType;
|
||||
/**ID*/
|
||||
@TableId(type = IdType.UUID)
|
||||
private java.lang.String id;
|
||||
/**备注*/
|
||||
@Excel(name = "备注", width = 15)
|
||||
private java.lang.String remark;
|
||||
/**更新人登录名称*/
|
||||
@Excel(name = "更新人登录名称", width = 15)
|
||||
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")
|
||||
private java.util.Date updateTime;
|
||||
}
|
||||
@ -0,0 +1,58 @@
|
||||
package org.jeecg.modules.message.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import org.jeecgframework.poi.excel.annotation.Excel;
|
||||
|
||||
/**
|
||||
* @Description: 消息模板
|
||||
* @author: jeecg-boot
|
||||
* @date: 2019-04-09
|
||||
* @version: V1.0
|
||||
*/
|
||||
@Data
|
||||
@TableName("sys_sms_template")
|
||||
public class SysMessageTemplate implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**主键*/
|
||||
@TableId(type = IdType.UUID)
|
||||
private java.lang.String id;
|
||||
/**模板CODE*/
|
||||
@Excel(name = "模板CODE", width = 15)
|
||||
private java.lang.String templateCode;
|
||||
/**模板内容*/
|
||||
@Excel(name = "模板内容", width = 15)
|
||||
private java.lang.String templateContent;
|
||||
/**模板标题*/
|
||||
@Excel(name = "模板标题", width = 15)
|
||||
private java.lang.String templateName;
|
||||
/**模板测试json*/
|
||||
@Excel(name = "模板测试json", width = 15)
|
||||
private java.lang.String templateTestJson;
|
||||
/**模板类型*/
|
||||
@Excel(name = "模板类型", width = 15)
|
||||
private java.lang.String templateType;
|
||||
/**创建人登录名称*/
|
||||
@Excel(name = "创建人登录名称", width = 15)
|
||||
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")
|
||||
private java.util.Date createTime;
|
||||
/**更新人登录名称*/
|
||||
@Excel(name = "更新人登录名称", width = 15)
|
||||
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")
|
||||
private java.util.Date updateTime;
|
||||
}
|
||||
@ -0,0 +1,6 @@
|
||||
package org.jeecg.modules.message.handle;
|
||||
|
||||
public interface ISendMsgHandle {
|
||||
|
||||
void SendMsg(String es_receiver, String es_title, String es_content);
|
||||
}
|
||||
@ -0,0 +1,25 @@
|
||||
package org.jeecg.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;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,51 @@
|
||||
package org.jeecg.modules.message.handle.enums;
|
||||
|
||||
import org.jeecg.common.util.oConvertUtils;
|
||||
|
||||
/**
|
||||
* 发送消息类型枚举
|
||||
*/
|
||||
public enum SendMsgTypeEnum {
|
||||
|
||||
//推送方式:1短信 2邮件 3微信
|
||||
SMS("1", "org.jeecg.modules.message.handle.impl.SmsSendMsgHandle"),
|
||||
EMAIL("2", "org.jeecg.modules.message.handle.impl.EmailSendMsgHandle"),
|
||||
WX("3","org.jeecg.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;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,22 @@
|
||||
package org.jeecg.modules.message.handle.impl;
|
||||
|
||||
import org.jeecg.common.util.SpringContextUtils;
|
||||
import org.jeecg.modules.message.handle.ISendMsgHandle;
|
||||
import org.springframework.mail.SimpleMailMessage;
|
||||
import org.springframework.mail.javamail.JavaMailSender;
|
||||
|
||||
public class EmailSendMsgHandle implements ISendMsgHandle {
|
||||
|
||||
@Override
|
||||
public void SendMsg(String es_receiver, String es_title, String es_content) {
|
||||
JavaMailSender mailSender = (JavaMailSender) SpringContextUtils.getBean("mailSender");
|
||||
SimpleMailMessage message = new SimpleMailMessage();
|
||||
// 设置发送方邮箱地址
|
||||
message.setFrom("2897976540@qq.com");
|
||||
message.setTo(es_receiver);
|
||||
message.setSubject(es_title);
|
||||
message.setText(es_content);
|
||||
mailSender.send(message);
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
package org.jeecg.modules.message.handle.impl;
|
||||
|
||||
import org.jeecg.modules.message.handle.ISendMsgHandle;
|
||||
|
||||
public class SmsSendMsgHandle implements ISendMsgHandle {
|
||||
|
||||
@Override
|
||||
public void SendMsg(String es_receiver, String es_title, String es_content) {
|
||||
// TODO Auto-generated method stub
|
||||
System.out.println("发短信");
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
package org.jeecg.modules.message.handle.impl;
|
||||
|
||||
import org.jeecg.modules.message.handle.ISendMsgHandle;
|
||||
|
||||
public class WxSendMsgHandle implements ISendMsgHandle {
|
||||
|
||||
@Override
|
||||
public void SendMsg(String es_receiver, String es_title, String es_content) {
|
||||
// TODO Auto-generated method stub
|
||||
System.out.println("发微信消息模板");
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,72 @@
|
||||
package org.jeecg.modules.message.job;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.jeecg.common.util.DateUtils;
|
||||
import org.jeecg.modules.message.entity.SysMessage;
|
||||
import org.jeecg.modules.message.handle.ISendMsgHandle;
|
||||
import org.jeecg.modules.message.handle.enums.SendMsgStatusEnum;
|
||||
import org.jeecg.modules.message.handle.enums.SendMsgTypeEnum;
|
||||
import org.jeecg.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(String.format(" Jeecg-Boot 发送消息任务 SendMsgJob ! 时间:" + DateUtils.getTimestamp()));
|
||||
|
||||
// 1.读取消息中心数据,只查询未发送的和发送失败不超过次数的
|
||||
QueryWrapper<SysMessage> queryWrapper = new QueryWrapper<SysMessage>();
|
||||
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);
|
||||
System.out.println(sysMessages);
|
||||
// 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) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Integer sendNum = sysMessage.getEsSendNum();
|
||||
try {
|
||||
sendMsgHandle.SendMsg(sysMessage.getEsReceiver(), sysMessage.getEsTitle(),
|
||||
sysMessage.getEsContent().toString());
|
||||
// 发送消息成功
|
||||
sysMessage.setEsSendStatus(SendMsgStatusEnum.SUCCESS.getCode());
|
||||
} catch (Exception e) {
|
||||
// 发送消息出现异常
|
||||
sysMessage.setEsSendStatus(SendMsgStatusEnum.FAIL.getCode());
|
||||
}
|
||||
sysMessage.setEsSendNum(++sendNum);
|
||||
// 发送结果回写到数据库
|
||||
sysMessageService.updateById(sysMessage);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,17 @@
|
||||
package org.jeecg.modules.message.mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.jeecg.modules.message.entity.SysMessage;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* @Description: 消息
|
||||
* @author: jeecg-boot
|
||||
* @date: 2019-04-09
|
||||
* @version: V1.0
|
||||
*/
|
||||
public interface SysMessageMapper extends BaseMapper<SysMessage> {
|
||||
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
package org.jeecg.modules.message.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.jeecg.modules.message.entity.SysMessageTemplate;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description: 消息模板
|
||||
* @author: jeecg-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);
|
||||
}
|
||||
@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="org.jeecg.modules.message.mapper.SysMessageMapper">
|
||||
|
||||
</mapper>
|
||||
@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="org.jeecg.modules.message.mapper.SysMessageTemplateMapper">
|
||||
|
||||
</mapper>
|
||||
@ -0,0 +1,14 @@
|
||||
package org.jeecg.modules.message.service;
|
||||
|
||||
import org.jeecg.modules.message.entity.SysMessage;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* @Description: 消息
|
||||
* @author: jeecg-boot
|
||||
* @date: 2019-04-09
|
||||
* @version: V1.0
|
||||
*/
|
||||
public interface ISysMessageService extends IService<SysMessage> {
|
||||
|
||||
}
|
||||
@ -0,0 +1,16 @@
|
||||
package org.jeecg.modules.message.service;
|
||||
|
||||
import org.jeecg.modules.message.entity.SysMessageTemplate;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description: 消息模板
|
||||
* @author: jeecg-boot
|
||||
* @date: 2019-04-09
|
||||
* @version: V1.0
|
||||
*/
|
||||
public interface ISysMessageTemplateService extends IService<SysMessageTemplate> {
|
||||
List<SysMessageTemplate> selectByCode(String code);
|
||||
}
|
||||
@ -0,0 +1,19 @@
|
||||
package org.jeecg.modules.message.service.impl;
|
||||
|
||||
import org.jeecg.modules.message.entity.SysMessage;
|
||||
import org.jeecg.modules.message.mapper.SysMessageMapper;
|
||||
import org.jeecg.modules.message.service.ISysMessageService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
|
||||
/**
|
||||
* @Description: 消息
|
||||
* @author: jeecg-boot
|
||||
* @date: 2019-04-09
|
||||
* @version: V1.0
|
||||
*/
|
||||
@Service
|
||||
public class SysMessageServiceImpl extends ServiceImpl<SysMessageMapper, SysMessage> implements ISysMessageService {
|
||||
|
||||
}
|
||||
@ -0,0 +1,29 @@
|
||||
package org.jeecg.modules.message.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.jeecg.modules.message.entity.SysMessageTemplate;
|
||||
import org.jeecg.modules.message.mapper.SysMessageTemplateMapper;
|
||||
import org.jeecg.modules.message.service.ISysMessageTemplateService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description: 消息模板
|
||||
* @author: jeecg-boot
|
||||
* @date: 2019-04-09
|
||||
* @version: V1.0
|
||||
*/
|
||||
@Service
|
||||
public class SysMessageTemplateServiceImpl extends ServiceImpl<SysMessageTemplateMapper, SysMessageTemplate> implements ISysMessageTemplateService {
|
||||
|
||||
@Autowired
|
||||
private SysMessageTemplateMapper sysMessageTemplateMapper;
|
||||
|
||||
|
||||
@Override
|
||||
public List<SysMessageTemplate> selectByCode(String code) {
|
||||
return sysMessageTemplateMapper.selectByCode(code);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,63 @@
|
||||
package org.jeecg.modules.message.util;
|
||||
|
||||
import org.jeecg.modules.message.entity.SysMessage;
|
||||
import org.jeecg.modules.message.entity.SysMessageTemplate;
|
||||
import org.jeecg.modules.message.handle.enums.SendMsgStatusEnum;
|
||||
import org.jeecg.modules.message.service.ISysMessageService;
|
||||
import org.jeecg.modules.message.service.ISysMessageTemplateService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 消息生成工具
|
||||
*/
|
||||
|
||||
@Component
|
||||
public class PushMsgUtil {
|
||||
|
||||
@Autowired
|
||||
private ISysMessageService sysMessageService;
|
||||
|
||||
@Autowired
|
||||
private ISysMessageTemplateService sysMessageTemplateService;
|
||||
|
||||
/**
|
||||
* @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.size() > 0) {
|
||||
SysMessageTemplate sysSmsTemplate = sysSmsTemplates.get(0);
|
||||
sysMessage.setEsType(msgType);
|
||||
sysMessage.setEsReceiver(sentTo);
|
||||
//模板标题
|
||||
String title = sysSmsTemplate.getTemplateName();
|
||||
//模板内容
|
||||
String content = sysSmsTemplate.getTemplateContent();
|
||||
for (Map.Entry<String, String> entry : map.entrySet()) {
|
||||
String str = "${" + entry.getKey() + "}";
|
||||
title = title.replace(str, entry.getValue());
|
||||
content = content.replace(str, entry.getValue());
|
||||
}
|
||||
sysMessage.setEsTitle(title);
|
||||
sysMessage.setEsContent(content);
|
||||
sysMessage.setEsParam(JSONObject.toJSONString(map));
|
||||
sysMessage.setEsSendTime(new Date());
|
||||
sysMessage.setEsSendStatus(SendMsgStatusEnum.WAIT.getCode());
|
||||
sysMessage.setEsSendNum(0);
|
||||
if(sysMessageService.save(sysMessage))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,46 @@
|
||||
package org.jeecg.modules.monitor.controller;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
import org.jeecg.modules.monitor.domain.RedisInfo;
|
||||
import org.jeecg.modules.monitor.service.RedisService;
|
||||
import org.jeecg.modules.system.controller.LoginController;
|
||||
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 lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("redis")
|
||||
@Slf4j
|
||||
public class RedisController {
|
||||
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
/**
|
||||
* Redis详细信息
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
@GetMapping("info")
|
||||
public Result<?> getRedisInfo() throws Exception {
|
||||
List<RedisInfo> infoList = this.redisService.getRedisInfo();
|
||||
log.info(infoList.toString());
|
||||
return Result.ok(infoList);
|
||||
}
|
||||
|
||||
@GetMapping("keysSize")
|
||||
public Map<String, Object> getKeysSize() throws Exception {
|
||||
return redisService.getKeysSize();
|
||||
}
|
||||
|
||||
@GetMapping("memoryInfo")
|
||||
public Map<String, Object> getMemoryInfo() throws Exception {
|
||||
return redisService.getMemoryInfo();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,137 @@
|
||||
package org.jeecg.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 + '\'' + '}';
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
package org.jeecg.modules.monitor.exception;
|
||||
|
||||
/**
|
||||
* Redis 连接异常
|
||||
*/
|
||||
public class RedisConnectException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = 1639374111871115063L;
|
||||
|
||||
public RedisConnectException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
package org.jeecg.modules.monitor.service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jeecg.modules.monitor.domain.RedisInfo;
|
||||
import org.jeecg.modules.monitor.exception.RedisConnectException;
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
@ -0,0 +1,75 @@
|
||||
package org.jeecg.modules.monitor.service.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.jeecg.common.util.oConvertUtils;
|
||||
import org.jeecg.modules.monitor.domain.RedisInfo;
|
||||
import org.jeecg.modules.monitor.exception.RedisConnectException;
|
||||
import org.jeecg.modules.monitor.service.RedisService;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* Redis 监控信息获取
|
||||
*
|
||||
* @author MrBird
|
||||
*/
|
||||
@Service("redisService")
|
||||
@Slf4j
|
||||
public class RedisServiceImpl implements RedisService {
|
||||
|
||||
@Resource
|
||||
private RedisConnectionFactory redisConnectionFactory;
|
||||
|
||||
/**
|
||||
* Redis详细信息
|
||||
*/
|
||||
@Override
|
||||
public List<RedisInfo> getRedisInfo() throws RedisConnectException {
|
||||
Properties info = redisConnectionFactory.getConnection().info();
|
||||
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();
|
||||
for (Map.Entry<Object, Object> entry : info.entrySet()) {
|
||||
String key = oConvertUtils.getString(entry.getKey());
|
||||
if ("used_memory".equals(key)) {
|
||||
map = new HashMap<>();
|
||||
map.put("used_memory", entry.getValue());
|
||||
map.put("create_time", System.currentTimeMillis());
|
||||
}
|
||||
}
|
||||
log.info("--getMemoryInfo--: " + map.toString());
|
||||
return map;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,46 @@
|
||||
package org.jeecg.modules.ngalain.aop;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.context.request.RequestAttributes;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;;
|
||||
|
||||
|
||||
// 暂时注释掉,提高系统性能
|
||||
//@Aspect //定义一个切面
|
||||
//@Configuration
|
||||
public class LogRecordAspect {
|
||||
private static final Logger logger = LoggerFactory.getLogger(LogRecordAspect.class);
|
||||
|
||||
// 定义切点Pointcut
|
||||
@Pointcut("execution(public * org.jeecg.modules.*.*.*Controller.*(..))")
|
||||
public void excudeService() {
|
||||
}
|
||||
|
||||
@Around("excudeService()")
|
||||
public Object doAround(ProceedingJoinPoint pjp) throws Throwable {
|
||||
RequestAttributes ra = RequestContextHolder.getRequestAttributes();
|
||||
ServletRequestAttributes sra = (ServletRequestAttributes) ra;
|
||||
HttpServletRequest request = sra.getRequest();
|
||||
|
||||
String url = request.getRequestURL().toString();
|
||||
String method = request.getMethod();
|
||||
String uri = request.getRequestURI();
|
||||
String queryString = request.getQueryString();
|
||||
logger.info("请求开始, 各个参数, url: {}, method: {}, uri: {}, params: {}", url, method, uri, queryString);
|
||||
|
||||
// result的值就是被拦截方法的返回值
|
||||
Object result = pjp.proceed();
|
||||
|
||||
logger.info("请求结束,controller的返回值是 " + result);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,85 @@
|
||||
package org.jeecg.modules.ngalain.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
import org.jeecg.common.util.oConvertUtils;
|
||||
import org.jeecg.modules.ngalain.service.NgAlainService;
|
||||
import org.jeecg.modules.system.entity.SysDict;
|
||||
import org.jeecg.modules.system.entity.SysUser;
|
||||
import org.jeecg.modules.system.model.SysDictTree;
|
||||
import org.jeecg.modules.system.service.ISysDictService;
|
||||
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/ng-alain")
|
||||
public class NgAlainController {
|
||||
@Autowired
|
||||
private NgAlainService ngAlainService;
|
||||
@Autowired
|
||||
private ISysDictService sysDictService;
|
||||
|
||||
@RequestMapping(value = "/getAppData")
|
||||
@ResponseBody
|
||||
public JSONObject getAppData(HttpServletRequest request) throws Exception {
|
||||
String token=request.getHeader("X-Access-Token");
|
||||
JSONObject j = new JSONObject();
|
||||
SysUser user = (SysUser) 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", "jeecg-boot-angular");
|
||||
app.put("description", "jeecg+ng-alain整合版本");
|
||||
j.put("app", app);
|
||||
return j;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/getDictItems/{dictCode}", method = RequestMethod.GET)
|
||||
public Object getDictItems(@PathVariable String dictCode) {
|
||||
log.info(" dictCode : "+ dictCode);
|
||||
Result<List<Map<String,Object>>> result = new Result<List<Map<String,Object>>>();
|
||||
List<Map<String,Object>> ls = null;
|
||||
try {
|
||||
ls = sysDictService.queryDictItemsByCode(dictCode);
|
||||
result.setSuccess(true);
|
||||
result.setResult(ls);
|
||||
} catch (Exception e) {
|
||||
log.info(e.getMessage());
|
||||
result.error500("操作失败");
|
||||
return result;
|
||||
}
|
||||
List<JSONObject> dictlist=new ArrayList<>();
|
||||
for (Map<String, Object> l : ls) {
|
||||
JSONObject dict=new JSONObject();
|
||||
try {
|
||||
dict.put("value",Integer.parseInt((String)l.get("value")));
|
||||
} catch (NumberFormatException e) {
|
||||
dict.put("value",l.get("value"));
|
||||
}
|
||||
dict.put("label",l.get("text"));
|
||||
dictlist.add(dict);
|
||||
}
|
||||
return dictlist;
|
||||
}
|
||||
@RequestMapping(value = "/getDictItemsByTable/{table}/{key}/{value}", method = RequestMethod.GET)
|
||||
public Object getDictItemsByTable(@PathVariable String table,@PathVariable String key,@PathVariable String value) {
|
||||
return this.ngAlainService.getDictByTable(table,key,value);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
package org.jeecg.modules.ngalain.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface NgAlainMapper extends BaseMapper {
|
||||
public List<Map<String,String>> getDictByTable(@Param("table") String table, @Param("key") String key, @Param("value") String value);
|
||||
|
||||
}
|
||||
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="org.jeecg.modules.ngalain.mapper.NgAlainMapper">
|
||||
<select id="getDictByTable" parameterType="String" resultType="java.util.HashMap">
|
||||
select ${key} as 'label',${value} as 'value' from ${table}
|
||||
</select>
|
||||
</mapper>
|
||||
@ -0,0 +1,12 @@
|
||||
package org.jeecg.modules.ngalain.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface NgAlainService {
|
||||
public JSONArray getMenu(String id) throws Exception;
|
||||
public JSONArray getJeecgMenu(String id) throws Exception;
|
||||
public List<Map<String, String>> getDictByTable(String table, String key, String value);
|
||||
}
|
||||
@ -0,0 +1,182 @@
|
||||
package org.jeecg.modules.ngalain.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.jeecg.common.util.MD5Util;
|
||||
import org.jeecg.common.util.oConvertUtils;
|
||||
import org.jeecg.modules.ngalain.mapper.NgAlainMapper;
|
||||
import org.jeecg.modules.ngalain.service.NgAlainService;
|
||||
import org.jeecg.modules.system.entity.SysPermission;
|
||||
import org.jeecg.modules.system.service.ISysPermissionService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Base64;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service("ngAlainService")
|
||||
@Transactional
|
||||
public class NgAlainServiceImpl implements NgAlainService {
|
||||
@Autowired
|
||||
private ISysPermissionService sysPermissionService;
|
||||
@Autowired
|
||||
private NgAlainMapper mapper;
|
||||
@Override
|
||||
public JSONArray getMenu(String id) throws Exception {
|
||||
return getJeecgMenu(id);
|
||||
}
|
||||
@Override
|
||||
public JSONArray getJeecgMenu(String id) throws Exception {
|
||||
List<SysPermission> metaList = sysPermissionService.queryByUser(id);
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
getPermissionJsonArray(jsonArray, metaList, null);
|
||||
JSONArray menulist= parseNgAlain(jsonArray);
|
||||
JSONObject jeecgMenu = new JSONObject();
|
||||
jeecgMenu.put("text", "jeecg菜单");
|
||||
jeecgMenu.put("group",true);
|
||||
jeecgMenu.put("children", menulist);
|
||||
JSONArray jeecgMenuList=new JSONArray();
|
||||
jeecgMenuList.add(jeecgMenu);
|
||||
return jeecgMenuList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Map<String, String>> getDictByTable(String table, String key, String value) {
|
||||
return this.mapper.getDictByTable(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", "appstore");
|
||||
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"))){
|
||||
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());
|
||||
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.replaceAll("=",""));
|
||||
}else {
|
||||
json.put("path", permission.getUrl());
|
||||
}
|
||||
|
||||
//重要规则:路由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;
|
||||
}
|
||||
/**
|
||||
* 通过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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,253 @@
|
||||
package org.jeecg.modules.online.cgreport.controller;
|
||||
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
import org.jeecg.common.exception.JeecgBootException;
|
||||
import org.jeecg.common.util.oConvertUtils;
|
||||
import org.jeecg.modules.online.cgreport.def.CgReportConstant;
|
||||
import org.jeecg.modules.online.cgreport.entity.OnlCgreportHead;
|
||||
import org.jeecg.modules.online.cgreport.entity.OnlCgreportItem;
|
||||
import org.jeecg.modules.online.cgreport.service.IOnlCgreportHeadService;
|
||||
import org.jeecg.modules.online.cgreport.service.IOnlCgreportItemService;
|
||||
import org.jeecg.modules.online.cgreport.util.BrowserUtils;
|
||||
import org.jeecg.modules.online.cgreport.util.CgReportQueryParamUtil;
|
||||
import org.jeecg.modules.online.cgreport.util.SqlUtil;
|
||||
import org.jeecg.modules.system.service.ISysDictService;
|
||||
import org.jeecgframework.poi.excel.ExcelExportUtil;
|
||||
import org.jeecgframework.poi.excel.entity.ExportParams;
|
||||
import org.jeecgframework.poi.excel.entity.params.ExcelExportEntity;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* @Title: Controller
|
||||
* @Description: 在线报表配置
|
||||
* @author: jeecg-boot
|
||||
* @date: 2019-03-08
|
||||
* @version: V1.0
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/online/cgreport/api")
|
||||
public class OnlCgreportAPI {
|
||||
|
||||
@Autowired
|
||||
private IOnlCgreportHeadService onlCgreportHeadService;
|
||||
@Autowired
|
||||
private IOnlCgreportItemService onlCgreportItemService;
|
||||
@Autowired
|
||||
private ISysDictService sysDictService;
|
||||
|
||||
/**
|
||||
* 通过 head code 获取 所有的 item,并生成 columns 所需的 json
|
||||
*
|
||||
* @param code
|
||||
* head code
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
@GetMapping(value = "/getColumns/{code}")
|
||||
public Result<?> getColumns(@PathVariable("code") String code) {
|
||||
|
||||
QueryWrapper<OnlCgreportItem> queryWrapper = new QueryWrapper<OnlCgreportItem>();
|
||||
queryWrapper.eq("cgrhead_id", code);
|
||||
queryWrapper.eq("is_show", 1);
|
||||
queryWrapper.orderByAsc("order_num");
|
||||
|
||||
List<OnlCgreportItem> list = onlCgreportItemService.list(queryWrapper);
|
||||
|
||||
List<Map<String, String>> array = new ArrayList<Map<String, String>>();
|
||||
for (OnlCgreportItem item : list) {
|
||||
Map<String, String> column = new HashMap<String, String>(3);
|
||||
column.put("title", item.getFieldTxt());
|
||||
column.put("dataIndex", item.getFieldName());
|
||||
column.put("align", "center");
|
||||
column.put("sorter", "true");
|
||||
|
||||
array.add(column);
|
||||
}
|
||||
|
||||
Map<String, Object> result = new HashMap<String, Object>(1);
|
||||
result.put("columns", array);
|
||||
|
||||
return Result.ok(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过 head code 获取 sql语句,并执行该语句返回查询数据
|
||||
*
|
||||
* @param code
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/getData/{code}")
|
||||
public Result<?> getData(@PathVariable("code") String code,HttpServletRequest request) {
|
||||
OnlCgreportHead head = onlCgreportHeadService.getById(code);
|
||||
if (head == null) {
|
||||
return Result.error("实体不存在");
|
||||
}
|
||||
String sql = head.getCgrSql();
|
||||
try {
|
||||
Map<String,Object> params = SqlUtil.getParameterMap(request);
|
||||
Map<String, Object> reslutMap = onlCgreportHeadService.executeSelectSql(sql,params);
|
||||
return Result.ok(reslutMap);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return Result.error("SQL执行失败:" + e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取查询条件
|
||||
*/
|
||||
@GetMapping(value = "/getQueryInfo/{code}")
|
||||
public Result<?> getQueryInfo(@PathVariable("code") String cgrheadId) {
|
||||
try {
|
||||
List<Map<String,String>> list = onlCgreportItemService.getAutoListQueryInfo(cgrheadId);
|
||||
return Result.ok(list);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.info("OnlCgformApiController.getQueryInfo()发生异常:" + e.getMessage());
|
||||
return Result.error("查询失败");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 将报表导出为excel
|
||||
* @param request
|
||||
* @param response
|
||||
*/
|
||||
@RequestMapping(value = "/exportXls/{reportId}")
|
||||
public void exportXls(@PathVariable("reportId") String reportId,HttpServletRequest request,HttpServletResponse response) {
|
||||
//step.1 设置,获取配置信息
|
||||
String codedFileName = "报表";
|
||||
String sheetName="导出信息";
|
||||
if (oConvertUtils.isNotEmpty(reportId)) {
|
||||
Map<String, Object> cgReportMap = null;
|
||||
try{
|
||||
cgReportMap = onlCgreportHeadService.queryCgReportConfig(reportId);
|
||||
}catch (Exception e) {
|
||||
throw new JeecgBootException("动态报表配置不存在!");
|
||||
}
|
||||
List<Map<String,Object>> fieldList = (List<Map<String, Object>>) cgReportMap.get(CgReportConstant.ITEMS);
|
||||
Map<String, Object> configM = (Map<String, Object>) cgReportMap.get(CgReportConstant.MAIN);
|
||||
codedFileName = configM.get("name")+codedFileName;
|
||||
String querySql = (String) configM.get(CgReportConstant.CONFIG_SQL);
|
||||
List<Map<String,Object>> items = (List<Map<String, Object>>) cgReportMap.get(CgReportConstant.ITEMS);
|
||||
List<String> paramList = (List<String>) cgReportMap.get(CgReportConstant.PARAMS);
|
||||
//页面参数查询字段(占位符的条件语句)
|
||||
Map<String, Object> pageSearchFields = new LinkedHashMap<String,Object>();
|
||||
//step.2 装载查询条件
|
||||
Map<String,Object> paramData = new HashMap<String, Object>();
|
||||
if(paramList!=null&¶mList.size()>0){
|
||||
for(String param :paramList){
|
||||
String value = request.getParameter(param);
|
||||
value = value==null?"":value;
|
||||
querySql = querySql.replace("'${"+param+"}'", ":"+param);
|
||||
querySql = querySql.replace("${"+param+"}", ":"+param);
|
||||
paramData.put(param, value);
|
||||
}
|
||||
}
|
||||
for(Map<String,Object> item:items){
|
||||
String isQuery = item.get(CgReportConstant.ITEM_ISQUERY).toString();
|
||||
if(CgReportConstant.BOOL_TRUE.equalsIgnoreCase(isQuery)){
|
||||
CgReportQueryParamUtil.loadQueryParams(request, item, pageSearchFields,paramData);
|
||||
}
|
||||
}
|
||||
//step.3 进行查询返回结果
|
||||
String dbKey=(String)configM.get("db_source");
|
||||
List<Map<?, ?>> result=null;
|
||||
if(oConvertUtils.isNotEmpty(dbKey)){
|
||||
if(paramData!=null&¶mData.size()>0){
|
||||
//TODO 动态数据源功能未实现
|
||||
//result= DynamicDBUtil.findListByHash(dbKey,SqlUtil.getFullSql(querySql,pageSearchFields),(HashMap<String, Object>)paramData);
|
||||
}else{
|
||||
//result= DynamicDBUtil.findList(dbKey, SqlUtil.getFullSql(querySql,pageSearchFields));
|
||||
}
|
||||
}else{
|
||||
result= onlCgreportHeadService.queryByCgReportSql(querySql, pageSearchFields,paramData, -1, -1);
|
||||
}
|
||||
|
||||
// Step.4 组装AutoPoi所需参数
|
||||
List<ExcelExportEntity> entityList = new ArrayList<ExcelExportEntity>();
|
||||
for (int i = 0; i < fieldList.size(); i++) {
|
||||
// 过滤不展示的字段
|
||||
if ("1".equals(oConvertUtils.getString(fieldList.get(i).get("is_show")))) {
|
||||
ExcelExportEntity expEntity = new ExcelExportEntity(fieldList.get(i).get("field_txt").toString(), fieldList.get(i).get("field_name"), 15);
|
||||
|
||||
//1. 字典值设置
|
||||
Object dictCode = fieldList.get(i).get("dict_code");
|
||||
if (oConvertUtils.isNotEmpty(dictCode)) {
|
||||
List<String> dictReplaces = new ArrayList<String>();
|
||||
List<Map<String, Object>> dictList = sysDictService.queryDictItemsByCode(dictCode.toString());
|
||||
for (Map<String, Object> d : dictList) {
|
||||
dictReplaces.add(d.get("text") + "_" + d.get("value"));
|
||||
}
|
||||
//男_1, 女_2
|
||||
expEntity.setReplace(dictReplaces.toArray(new String[dictReplaces.size()]));
|
||||
}
|
||||
//2. 取值表达式(男_1, 女_2)
|
||||
//TODO oracle下大小写兼容问题
|
||||
Object replace_val = fieldList.get(i).get("replace_val");
|
||||
if(oConvertUtils.isNotEmpty(replace_val)) {
|
||||
expEntity.setReplace(replace_val.toString().split(","));
|
||||
}
|
||||
entityList.add(expEntity);
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
response.setContentType("application/vnd.ms-excel");
|
||||
OutputStream fOut = null;
|
||||
try {
|
||||
|
||||
// step.4 根据浏览器进行转码,使其支持中文文件名
|
||||
String browse = BrowserUtils.checkBrowse(request);
|
||||
if ("MSIE".equalsIgnoreCase(browse.substring(0, 4))) {
|
||||
response.setHeader("content-disposition", "attachment;filename=" + java.net.URLEncoder.encode(codedFileName, "UTF-8") + ".xls");
|
||||
} else {
|
||||
String newtitle = new String(codedFileName.getBytes("UTF-8"), "ISO8859-1");
|
||||
response.setHeader("content-disposition", "attachment;filename=" + newtitle + ".xls");
|
||||
}
|
||||
// step.5 产生工作簿对象
|
||||
//HSSFWorkbook workbook = cgReportExcelService.exportExcel(codedFileName, fieldList, result);
|
||||
Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(null,sheetName), entityList, result);
|
||||
fOut = response.getOutputStream();
|
||||
workbook.write(fOut);
|
||||
} catch (Exception e) {
|
||||
|
||||
} finally {
|
||||
try {
|
||||
fOut.flush();
|
||||
fOut.close();
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
}
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
} else {
|
||||
throw new JeecgBootException("参数错误");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,269 @@
|
||||
package org.jeecg.modules.online.cgreport.controller;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
import org.jeecg.common.system.query.QueryGenerator;
|
||||
import org.jeecg.common.util.oConvertUtils;
|
||||
import org.jeecg.modules.online.cgreport.entity.OnlCgreportHead;
|
||||
import org.jeecg.modules.online.cgreport.entity.OnlCgreportItem;
|
||||
import org.jeecg.modules.online.cgreport.entity.OnlCgreportParam;
|
||||
import org.jeecg.modules.online.cgreport.model.OnlCgreportModel;
|
||||
import org.jeecg.modules.online.cgreport.service.IOnlCgreportHeadService;
|
||||
import org.jeecg.modules.online.cgreport.service.IOnlCgreportItemService;
|
||||
import org.jeecg.modules.online.cgreport.service.IOnlCgreportParamService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* @Title: Controller
|
||||
* @Description: 在线报表配置
|
||||
* @author: jeecg-boot
|
||||
* @date: 2019-03-08
|
||||
* @version: V1.0
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/online/cgreport/head")
|
||||
@Slf4j
|
||||
public class OnlCgreportHeadController {
|
||||
|
||||
@Autowired
|
||||
private IOnlCgreportHeadService onlCgreportHeadService;
|
||||
@Autowired
|
||||
private IOnlCgreportParamService onlCgreportParamService;
|
||||
@Autowired
|
||||
private IOnlCgreportItemService onlCgreportItemService;
|
||||
|
||||
/**
|
||||
* sql解析获取字段和参数
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/parseSql")
|
||||
public Result<?> parseSql(@RequestParam(name = "sql", required = true) String sql) {
|
||||
Map<String, Object> resultJson = new HashMap<String, Object>();
|
||||
//返回SQL解析字段
|
||||
List<OnlCgreportItem> onlCgreportItemList = new ArrayList<OnlCgreportItem>();
|
||||
//返回SQL解析参数
|
||||
List<OnlCgreportParam> onlCgreportParamList = new ArrayList<OnlCgreportParam>();
|
||||
List<String> fields = null;
|
||||
List<String> params = null;
|
||||
String dbKey = null;
|
||||
try {
|
||||
fields = onlCgreportHeadService.getSqlFields(sql, dbKey);
|
||||
params = onlCgreportHeadService.getSqlParams(sql);
|
||||
|
||||
int i = 1;
|
||||
for(String f:fields) {
|
||||
OnlCgreportItem t = new OnlCgreportItem();
|
||||
t.setFieldName(f);
|
||||
t.setFieldTxt(f);
|
||||
t.setIsShow(1);
|
||||
t.setOrderNum(i);
|
||||
t.setId(i+"_"+System.currentTimeMillis());
|
||||
t.setFieldType("String");
|
||||
onlCgreportItemList.add(t);
|
||||
i++;
|
||||
}
|
||||
|
||||
for(String p:params) {
|
||||
OnlCgreportParam param = new OnlCgreportParam();
|
||||
param.setParamName(p);
|
||||
param.setParamTxt(p);
|
||||
onlCgreportParamList.add(param);
|
||||
}
|
||||
resultJson.put("fields", onlCgreportItemList);
|
||||
resultJson.put("params", onlCgreportParamList);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
String msg = "解析失败!<br><br>失败原因:";
|
||||
int i = e.getMessage().indexOf("Connection refused: connect");
|
||||
if (i != -1) {// 非链接异常
|
||||
msg += "数据源连接失败.";
|
||||
} else {
|
||||
msg += "SQL语法错误.";
|
||||
}
|
||||
Result.error(msg);
|
||||
}
|
||||
return Result.ok(resultJson);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页列表查询
|
||||
*
|
||||
* @param onlCgreportHead
|
||||
* @param pageNo
|
||||
* @param pageSize
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/list")
|
||||
public Result<IPage<OnlCgreportHead>> queryPageList(OnlCgreportHead onlCgreportHead, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest req) {
|
||||
Result<IPage<OnlCgreportHead>> result = new Result<IPage<OnlCgreportHead>>();
|
||||
QueryWrapper<OnlCgreportHead> queryWrapper = QueryGenerator.initQueryWrapper(onlCgreportHead, req.getParameterMap());
|
||||
Page<OnlCgreportHead> page = new Page<OnlCgreportHead>(pageNo, pageSize);
|
||||
IPage<OnlCgreportHead> pageList = onlCgreportHeadService.page(page, queryWrapper);
|
||||
result.setSuccess(true);
|
||||
result.setResult(pageList);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*
|
||||
* @param onlCgreportHead
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/add")
|
||||
public Result<?> add(@RequestBody OnlCgreportModel values) {
|
||||
Result<OnlCgreportHead> result = new Result<OnlCgreportHead>();
|
||||
try {
|
||||
String uuid = UUID.randomUUID().toString().replace("-", "");
|
||||
|
||||
OnlCgreportHead head = values.getHead();
|
||||
List<OnlCgreportParam> params = values.getParams();
|
||||
List<OnlCgreportItem> items = values.getItems();
|
||||
|
||||
head.setId(uuid);
|
||||
for (OnlCgreportParam param : params) {
|
||||
param.setId(null);
|
||||
param.setCgrheadId(uuid);
|
||||
}
|
||||
for (OnlCgreportItem item : items) {
|
||||
item.setId(null);
|
||||
item.setCgrheadId(uuid);
|
||||
}
|
||||
|
||||
onlCgreportHeadService.save(head);
|
||||
onlCgreportParamService.saveBatch(params);
|
||||
onlCgreportItemService.saveBatch(items);
|
||||
|
||||
result.success("添加成功!");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.info(e.getMessage());
|
||||
result.error500("操作失败");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑保存全部操作
|
||||
*/
|
||||
@PutMapping(value = "/editAll")
|
||||
public Result<?> editAll(@RequestBody OnlCgreportModel values) {
|
||||
|
||||
try {
|
||||
return onlCgreportHeadService.editAll(values);
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.info(e.getMessage());
|
||||
return Result.error("操作失败");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*
|
||||
* @param onlCgreportHead
|
||||
* @return
|
||||
*/
|
||||
@PutMapping(value = "/edit")
|
||||
public Result<OnlCgreportHead> edit(@RequestBody OnlCgreportHead onlCgreportHead) {
|
||||
Result<OnlCgreportHead> result = new Result<OnlCgreportHead>();
|
||||
OnlCgreportHead onlCgreportHeadEntity = onlCgreportHeadService.getById(onlCgreportHead.getId());
|
||||
if (onlCgreportHeadEntity == null) {
|
||||
result.error500("未找到对应实体");
|
||||
} else {
|
||||
boolean ok = onlCgreportHeadService.updateById(onlCgreportHead);
|
||||
// TODO 返回false说明什么?
|
||||
if (ok) {
|
||||
result.success("修改成功!");
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id删除
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@DeleteMapping(value = "/delete")
|
||||
public Result<OnlCgreportHead> delete(@RequestParam(name = "id", required = true) String id) {
|
||||
Result<OnlCgreportHead> result = new Result<OnlCgreportHead>();
|
||||
OnlCgreportHead onlCgreportHead = onlCgreportHeadService.getById(id);
|
||||
if (onlCgreportHead == null) {
|
||||
result.error500("未找到对应实体");
|
||||
} else {
|
||||
boolean ok = onlCgreportHeadService.removeById(id);
|
||||
if (ok) {
|
||||
result.success("删除成功!");
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
*
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
@DeleteMapping(value = "/deleteBatch")
|
||||
public Result<OnlCgreportHead> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
|
||||
Result<OnlCgreportHead> result = new Result<OnlCgreportHead>();
|
||||
if (ids == null || "".equals(ids.trim())) {
|
||||
result.error500("参数不识别!");
|
||||
} else {
|
||||
this.onlCgreportHeadService.removeByIds(Arrays.asList(ids.split(",")));
|
||||
result.success("删除成功!");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id查询
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/queryById")
|
||||
public Result<OnlCgreportHead> queryById(@RequestParam(name = "id", required = true) String id) {
|
||||
Result<OnlCgreportHead> result = new Result<OnlCgreportHead>();
|
||||
OnlCgreportHead onlCgreportHead = onlCgreportHeadService.getById(id);
|
||||
if (onlCgreportHead == null) {
|
||||
result.error500("未找到对应实体");
|
||||
} else {
|
||||
result.setResult(onlCgreportHead);
|
||||
result.setSuccess(true);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,183 @@
|
||||
package org.jeecg.modules.online.cgreport.controller;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
import org.jeecg.common.system.query.QueryGenerator;
|
||||
import org.jeecg.common.util.oConvertUtils;
|
||||
import org.jeecg.modules.online.cgreport.entity.OnlCgreportItem;
|
||||
import org.jeecg.modules.online.cgreport.service.IOnlCgreportItemService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* @Title: Controller
|
||||
* @Description: 在线报表配置
|
||||
* @author: jeecg-boot
|
||||
* @date: 2019-03-08
|
||||
* @version: V1.0
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/online/cgreport/item")
|
||||
@Slf4j
|
||||
public class OnlCgreportItemController {
|
||||
|
||||
@Autowired
|
||||
private IOnlCgreportItemService onlCgreportItemService;
|
||||
|
||||
/**
|
||||
* 根据 headId 查询出 所有的 item
|
||||
*/
|
||||
@GetMapping(value = "/listByHeadId")
|
||||
public Result<?> queryPageListByHeadId(String headId) {
|
||||
|
||||
QueryWrapper<OnlCgreportItem> queryWrapper = new QueryWrapper<OnlCgreportItem>();
|
||||
queryWrapper.eq("cgrhead_id", headId);
|
||||
queryWrapper.orderByAsc("order_num");
|
||||
List<OnlCgreportItem> list = onlCgreportItemService.list(queryWrapper);
|
||||
|
||||
Result<List<OnlCgreportItem>> result = new Result<List<OnlCgreportItem>>();
|
||||
result.setSuccess(true);
|
||||
result.setResult(list);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页列表查询
|
||||
*
|
||||
* @param onlCgreportItem
|
||||
* @param pageNo
|
||||
* @param pageSize
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/list")
|
||||
public Result<IPage<OnlCgreportItem>> queryPageList(OnlCgreportItem onlCgreportItem, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest req) {
|
||||
Result<IPage<OnlCgreportItem>> result = new Result<IPage<OnlCgreportItem>>();
|
||||
QueryWrapper<OnlCgreportItem> queryWrapper = QueryGenerator.initQueryWrapper(onlCgreportItem, req.getParameterMap());
|
||||
Page<OnlCgreportItem> page = new Page<OnlCgreportItem>(pageNo, pageSize);
|
||||
IPage<OnlCgreportItem> pageList = onlCgreportItemService.page(page, queryWrapper);
|
||||
result.setSuccess(true);
|
||||
result.setResult(pageList);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*
|
||||
* @param onlCgreportItem
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/add")
|
||||
public Result<OnlCgreportItem> add(@RequestBody OnlCgreportItem onlCgreportItem) {
|
||||
Result<OnlCgreportItem> result = new Result<OnlCgreportItem>();
|
||||
try {
|
||||
onlCgreportItemService.save(onlCgreportItem);
|
||||
result.success("添加成功!");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.info(e.getMessage());
|
||||
result.error500("操作失败");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*
|
||||
* @param onlCgreportItem
|
||||
* @return
|
||||
*/
|
||||
@PutMapping(value = "/edit")
|
||||
public Result<OnlCgreportItem> edit(@RequestBody OnlCgreportItem onlCgreportItem) {
|
||||
Result<OnlCgreportItem> result = new Result<OnlCgreportItem>();
|
||||
OnlCgreportItem onlCgreportItemEntity = onlCgreportItemService.getById(onlCgreportItem.getId());
|
||||
if (onlCgreportItemEntity == null) {
|
||||
result.error500("未找到对应实体");
|
||||
} else {
|
||||
boolean ok = onlCgreportItemService.updateById(onlCgreportItem);
|
||||
// TODO 返回false说明什么?
|
||||
if (ok) {
|
||||
result.success("修改成功!");
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id删除
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@DeleteMapping(value = "/delete")
|
||||
public Result<OnlCgreportItem> delete(@RequestParam(name = "id", required = true) String id) {
|
||||
Result<OnlCgreportItem> result = new Result<OnlCgreportItem>();
|
||||
OnlCgreportItem onlCgreportItem = onlCgreportItemService.getById(id);
|
||||
if (onlCgreportItem == null) {
|
||||
result.error500("未找到对应实体");
|
||||
} else {
|
||||
boolean ok = onlCgreportItemService.removeById(id);
|
||||
if (ok) {
|
||||
result.success("删除成功!");
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
*
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
@DeleteMapping(value = "/deleteBatch")
|
||||
public Result<OnlCgreportItem> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
|
||||
Result<OnlCgreportItem> result = new Result<OnlCgreportItem>();
|
||||
if (ids == null || "".equals(ids.trim())) {
|
||||
result.error500("参数不识别!");
|
||||
} else {
|
||||
this.onlCgreportItemService.removeByIds(Arrays.asList(ids.split(",")));
|
||||
result.success("删除成功!");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id查询
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/queryById")
|
||||
public Result<OnlCgreportItem> queryById(@RequestParam(name = "id", required = true) String id) {
|
||||
Result<OnlCgreportItem> result = new Result<OnlCgreportItem>();
|
||||
OnlCgreportItem onlCgreportItem = onlCgreportItemService.getById(id);
|
||||
if (onlCgreportItem == null) {
|
||||
result.error500("未找到对应实体");
|
||||
} else {
|
||||
result.setResult(onlCgreportItem);
|
||||
result.setSuccess(true);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,183 @@
|
||||
package org.jeecg.modules.online.cgreport.controller;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
import org.jeecg.common.system.query.QueryGenerator;
|
||||
import org.jeecg.common.util.oConvertUtils;
|
||||
import org.jeecg.modules.online.cgreport.entity.OnlCgreportParam;
|
||||
import org.jeecg.modules.online.cgreport.service.IOnlCgreportParamService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* @Title: Controller
|
||||
* @Description: 在线报表配置
|
||||
* @author: jeecg-boot
|
||||
* @date: 2019-03-08
|
||||
* @version: V1.0
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/online/cgreport/param")
|
||||
@Slf4j
|
||||
public class OnlCgreportParamController {
|
||||
|
||||
@Autowired
|
||||
private IOnlCgreportParamService onlCgreportParamService;
|
||||
|
||||
/**
|
||||
* 根据 headId 查询出 所有的 param
|
||||
*/
|
||||
@GetMapping(value = "/listByHeadId")
|
||||
public Result<?> queryPageListByHeadId(String headId) {
|
||||
|
||||
QueryWrapper<OnlCgreportParam> queryWrapper = new QueryWrapper<OnlCgreportParam>();
|
||||
queryWrapper.eq("cgrhead_id", headId);
|
||||
queryWrapper.orderByAsc("order_num");
|
||||
List<OnlCgreportParam> list = onlCgreportParamService.list(queryWrapper);
|
||||
|
||||
Result<List<OnlCgreportParam>> result = new Result<List<OnlCgreportParam>>();
|
||||
result.setSuccess(true);
|
||||
result.setResult(list);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页列表查询
|
||||
*
|
||||
* @param onlCgreportParam
|
||||
* @param pageNo
|
||||
* @param pageSize
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/list")
|
||||
public Result<IPage<OnlCgreportParam>> queryPageList(OnlCgreportParam onlCgreportParam, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest req) {
|
||||
Result<IPage<OnlCgreportParam>> result = new Result<IPage<OnlCgreportParam>>();
|
||||
QueryWrapper<OnlCgreportParam> queryWrapper = QueryGenerator.initQueryWrapper(onlCgreportParam, req.getParameterMap());
|
||||
Page<OnlCgreportParam> page = new Page<OnlCgreportParam>(pageNo, pageSize);
|
||||
IPage<OnlCgreportParam> pageList = onlCgreportParamService.page(page, queryWrapper);
|
||||
result.setSuccess(true);
|
||||
result.setResult(pageList);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*
|
||||
* @param onlCgreportParam
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/add")
|
||||
public Result<OnlCgreportParam> add(@RequestBody OnlCgreportParam onlCgreportParam) {
|
||||
Result<OnlCgreportParam> result = new Result<OnlCgreportParam>();
|
||||
try {
|
||||
onlCgreportParamService.save(onlCgreportParam);
|
||||
result.success("添加成功!");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.info(e.getMessage());
|
||||
result.error500("操作失败");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*
|
||||
* @param onlCgreportParam
|
||||
* @return
|
||||
*/
|
||||
@PutMapping(value = "/edit")
|
||||
public Result<OnlCgreportParam> edit(@RequestBody OnlCgreportParam onlCgreportParam) {
|
||||
Result<OnlCgreportParam> result = new Result<OnlCgreportParam>();
|
||||
OnlCgreportParam onlCgreportParamEntity = onlCgreportParamService.getById(onlCgreportParam.getId());
|
||||
if (onlCgreportParamEntity == null) {
|
||||
result.error500("未找到对应实体");
|
||||
} else {
|
||||
boolean ok = onlCgreportParamService.updateById(onlCgreportParam);
|
||||
// TODO 返回false说明什么?
|
||||
if (ok) {
|
||||
result.success("修改成功!");
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id删除
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@DeleteMapping(value = "/delete")
|
||||
public Result<OnlCgreportParam> delete(@RequestParam(name = "id", required = true) String id) {
|
||||
Result<OnlCgreportParam> result = new Result<OnlCgreportParam>();
|
||||
OnlCgreportParam onlCgreportParam = onlCgreportParamService.getById(id);
|
||||
if (onlCgreportParam == null) {
|
||||
result.error500("未找到对应实体");
|
||||
} else {
|
||||
boolean ok = onlCgreportParamService.removeById(id);
|
||||
if (ok) {
|
||||
result.success("删除成功!");
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
*
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
@DeleteMapping(value = "/deleteBatch")
|
||||
public Result<OnlCgreportParam> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
|
||||
Result<OnlCgreportParam> result = new Result<OnlCgreportParam>();
|
||||
if (ids == null || "".equals(ids.trim())) {
|
||||
result.error500("参数不识别!");
|
||||
} else {
|
||||
this.onlCgreportParamService.removeByIds(Arrays.asList(ids.split(",")));
|
||||
result.success("删除成功!");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id查询
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/queryById")
|
||||
public Result<OnlCgreportParam> queryById(@RequestParam(name = "id", required = true) String id) {
|
||||
Result<OnlCgreportParam> result = new Result<OnlCgreportParam>();
|
||||
OnlCgreportParam onlCgreportParam = onlCgreportParamService.getById(id);
|
||||
if (onlCgreportParam == null) {
|
||||
result.error500("未找到对应实体");
|
||||
} else {
|
||||
result.setResult(onlCgreportParam);
|
||||
result.setSuccess(true);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,70 @@
|
||||
package org.jeecg.modules.online.cgreport.def;
|
||||
/**
|
||||
*
|
||||
* @Title:CgReportConstant
|
||||
* @description:动态报表常量类
|
||||
* @author 赵俊夫
|
||||
* @date Jul 30, 2013 9:16:18 AM
|
||||
* @version V1.0
|
||||
*/
|
||||
public class CgReportConstant {
|
||||
/** 抬头配置 */
|
||||
public static final String MAIN= "main";
|
||||
/** 明细配置*/
|
||||
public static final String ITEMS= "items";
|
||||
/** 动态报表参数*/
|
||||
public static final String PARAMS= "params";
|
||||
/** 配置的id*/
|
||||
public static final String CONFIG_ID="config_id";
|
||||
/** 配置的名称*/
|
||||
public static final String CONFIG_NAME="config_name";
|
||||
/** 字段列表*/
|
||||
public static final String CONFIG_FIELDLIST = "config_fieldList";
|
||||
/** 查询字段*/
|
||||
public static final String CONFIG_QUERYLIST ="config_queryList";
|
||||
/** 动态报表参数*/
|
||||
public static final String CONFIG_PARAMS ="config_params";
|
||||
/**字典数据*/
|
||||
public static final String FIELD_DICTLIST = "field_dictlist";
|
||||
/**系统字典表*/
|
||||
public static final String SYS_DIC="t_s_type";
|
||||
/**系统字典分组表*/
|
||||
public static final String SYS_DICGROUP="t_s_typegroup";
|
||||
/** 抬头配置-查询SQL*/
|
||||
public static final String CONFIG_SQL= "cgreport_sql";
|
||||
/** 字典编码*/
|
||||
public static final String ITEM_DICCODE= "dict_code";
|
||||
/** 取值表达式*/
|
||||
public static final String ITEM_REPLACE = "replace_value";
|
||||
/** 明细配置-字段名*/
|
||||
public static final String ITEM_FIELDNAME = "field_name";
|
||||
/** 明细配置-是否查询*/
|
||||
public static final String ITEM_ISQUERY = "search_flag";
|
||||
/** 明细配置-字段类型*/
|
||||
public static final String ITEM_FIELDTYPE = "field_type";
|
||||
/** 明细配置-查询模式*/
|
||||
public static final String ITEM_QUERYMODE = "search_mode";
|
||||
/**逻辑true*/
|
||||
public static final String BOOL_TRUE= "Y";
|
||||
/**逻辑false*/
|
||||
public static final String BOOL_FALSE= "N";
|
||||
/**查询操作=*/
|
||||
public static final String OP_EQ = " = ";
|
||||
/**查询操作>=*/
|
||||
public static final String OP_RQ = " >= ";
|
||||
/**查询操作<=*/
|
||||
public static final String OP_LQ = " <= ";
|
||||
/**查询操作like*/
|
||||
public static final String OP_LIKE = " LIKE ";
|
||||
/**显示模式Date*/
|
||||
public static final String TYPE_DATE = "Date";
|
||||
/**显示模式String*/
|
||||
public static final String TYPE_STRING = "String";
|
||||
/**显示模式Integer*/
|
||||
public static final String TYPE_INTEGER = "Integer";
|
||||
/**显示模式Double*/
|
||||
public static final String TYPE_DOUBLE = "Double";
|
||||
|
||||
/** iframe */
|
||||
public static final String CONFIG_IFRAME = "config_iframe";
|
||||
}
|
||||
@ -0,0 +1,57 @@
|
||||
package org.jeecg.modules.online.cgreport.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* @Description: 在线报表配置
|
||||
* @author: jeecg-boot
|
||||
* @date: 2019-03-08
|
||||
* @version: V1.0
|
||||
*/
|
||||
@Data
|
||||
@TableName("onl_cgreport_head")
|
||||
public class OnlCgreportHead implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** id */
|
||||
@TableId(type = IdType.UUID)
|
||||
private java.lang.String id;
|
||||
/** 报表编码 */
|
||||
private java.lang.String code;
|
||||
/** 报表名字 */
|
||||
private java.lang.String name;
|
||||
/** 报表SQL */
|
||||
private java.lang.String cgrSql;
|
||||
/** 返回值字段 */
|
||||
private java.lang.String returnValField;
|
||||
/** 返回文本字段 */
|
||||
private java.lang.String returnTxtField;
|
||||
/** 返回类型,单选或多选 */
|
||||
private java.lang.String returnType;
|
||||
/** 动态数据源 */
|
||||
private java.lang.String dbSource;
|
||||
/** 描述 */
|
||||
private java.lang.String content;
|
||||
/** 修改时间 */
|
||||
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private java.util.Date updateTime;
|
||||
/** 修改人id */
|
||||
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 createTime;
|
||||
/** 创建人id */
|
||||
private java.lang.String createBy;
|
||||
|
||||
}
|
||||
@ -0,0 +1,66 @@
|
||||
package org.jeecg.modules.online.cgreport.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* @Description: 在线报表配置
|
||||
* @author: jeecg-boot
|
||||
* @date: 2019-03-08
|
||||
* @version: V1.0
|
||||
*/
|
||||
@Data
|
||||
@TableName("onl_cgreport_item")
|
||||
public class OnlCgreportItem implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** id */
|
||||
@TableId(type = IdType.UUID)
|
||||
private java.lang.String id;
|
||||
/** 报表ID */
|
||||
private java.lang.String cgrheadId;
|
||||
/** 字段名字 */
|
||||
private java.lang.String fieldName;
|
||||
/** 字段文本 */
|
||||
private java.lang.String fieldTxt;
|
||||
/** fieldWidth */
|
||||
private java.lang.Integer fieldWidth;
|
||||
/** 字段类型 */
|
||||
private java.lang.String fieldType;
|
||||
/** 查询模式 */
|
||||
private java.lang.String searchMode;
|
||||
/** 是否排序 0否,1是 */
|
||||
private java.lang.Integer isOrder;
|
||||
/** 是否查询 0否,1是 */
|
||||
private java.lang.Integer isSearch;
|
||||
/** 字典CODE */
|
||||
private java.lang.String dictCode;
|
||||
/** 字段跳转URL */
|
||||
private java.lang.String fieldHref;
|
||||
/** 是否显示 0否,1显示 */
|
||||
private java.lang.Integer isShow;
|
||||
/** 排序 */
|
||||
private java.lang.Integer orderNum;
|
||||
/** 取值表达式 */
|
||||
private java.lang.String replaceVal;
|
||||
/** 创建人 */
|
||||
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,50 @@
|
||||
package org.jeecg.modules.online.cgreport.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* @Description: 在线报表配置
|
||||
* @author: jeecg-boot
|
||||
* @date: 2019-03-08
|
||||
* @version: V1.0
|
||||
*/
|
||||
@Data
|
||||
@TableName("onl_cgreport_param")
|
||||
public class OnlCgreportParam implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** id */
|
||||
@TableId(type = IdType.UUID)
|
||||
private java.lang.String id;
|
||||
/** 动态报表ID */
|
||||
private java.lang.String cgrheadId;
|
||||
/** 参数字段 */
|
||||
private java.lang.String paramName;
|
||||
/** 参数文本 */
|
||||
private java.lang.String paramTxt;
|
||||
/** 参数默认值 */
|
||||
private java.lang.String paramValue;
|
||||
/** 排序 */
|
||||
private java.lang.Integer orderNum;
|
||||
/** 创建人登录名称 */
|
||||
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,52 @@
|
||||
package org.jeecg.modules.online.cgreport.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jeecg.modules.online.cgreport.entity.OnlCgreportHead;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* @Description: 在线报表配置
|
||||
* @author: jeecg-boot
|
||||
* @date: 2019-03-08
|
||||
* @version: V1.0
|
||||
*/
|
||||
public interface OnlCgreportHeadMapper extends BaseMapper<OnlCgreportHead> {
|
||||
|
||||
/**
|
||||
* 执行查询SQL语句
|
||||
*
|
||||
* @param sql
|
||||
* @return
|
||||
*/
|
||||
List<Map<?, ?>> executeSelete(String sql);
|
||||
|
||||
/**
|
||||
* 动态sql查询数据量
|
||||
* @param sql
|
||||
* @return
|
||||
*/
|
||||
Long queryCountBySql(String sql);
|
||||
|
||||
/**
|
||||
* 通过reportId获取报表主配置信息
|
||||
* @param reportId
|
||||
* @return
|
||||
*/
|
||||
Map<String, Object> queryCgReportMainConfig(String reportId);
|
||||
/**
|
||||
* 通过reportId获取报表字段信息
|
||||
* @param reportCode
|
||||
* @return
|
||||
*/
|
||||
List<Map<String, Object>> queryCgReportItems(String reportId);
|
||||
/**
|
||||
* 通过reportId获取报参数信息
|
||||
* @param reportId
|
||||
* @return
|
||||
*/
|
||||
List<String> queryCgReportParams(String reportId);
|
||||
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
package org.jeecg.modules.online.cgreport.mapper;
|
||||
|
||||
import org.jeecg.modules.online.cgreport.entity.OnlCgreportItem;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* @Description: 在线报表配置
|
||||
* @author: jeecg-boot
|
||||
* @date: 2019-03-08
|
||||
* @version: V1.0
|
||||
*/
|
||||
public interface OnlCgreportItemMapper extends BaseMapper<OnlCgreportItem> {
|
||||
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
package org.jeecg.modules.online.cgreport.mapper;
|
||||
|
||||
import org.jeecg.modules.online.cgreport.entity.OnlCgreportParam;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* @Description: 在线报表配置
|
||||
* @author: jeecg-boot
|
||||
* @date: 2019-03-08
|
||||
* @version: V1.0
|
||||
*/
|
||||
public interface OnlCgreportParamMapper extends BaseMapper<OnlCgreportParam> {
|
||||
|
||||
}
|
||||
@ -0,0 +1,58 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="org.jeecg.modules.online.cgreport.mapper.OnlCgreportHeadMapper">
|
||||
|
||||
<!-- 执行select sql语句 -->
|
||||
<select id="executeSelete" resultType="map" parameterType="java.lang.String">
|
||||
${_parameter}
|
||||
</select>
|
||||
|
||||
<!-- 执行select count语句 -->
|
||||
<select id="queryCountBySql" parameterType="java.lang.String" resultType="java.lang.Long">
|
||||
${_parameter}
|
||||
</select>
|
||||
|
||||
<!-- 执行select sql语句 -->
|
||||
<select id="findForListMap" resultType="map" parameterType="map">
|
||||
${_parameter}
|
||||
</select>
|
||||
|
||||
<!-- 查询报表配置主信息 -->
|
||||
<select id="queryCgReportMainConfig" resultType="map" parameterType="java.lang.String">
|
||||
select
|
||||
ch.id as id,
|
||||
ch.code as code,
|
||||
ch.name as name,
|
||||
ch.cgr_sql as cgreport_sql,
|
||||
ch.content as content,
|
||||
ch.db_source,
|
||||
ch.return_type
|
||||
from onl_cgreport_head ch
|
||||
where ch.id =#{reportId,jdbcType=VARCHAR}
|
||||
</select>
|
||||
|
||||
<!-- 查询报表配置字段信息 -->
|
||||
<select id="queryCgReportItems" resultType="map" parameterType="java.lang.String">
|
||||
select
|
||||
ci.id as id,
|
||||
ci.field_name as field_name,
|
||||
ci.field_txt as field_txt,
|
||||
ci.field_href as field_href,
|
||||
ci.is_show as is_show,
|
||||
ci.field_type as field_type,
|
||||
ci.replace_val as replace_value,
|
||||
ci.dict_code as dict_code,
|
||||
ci.is_search as search_flag,
|
||||
ci.search_mode as search_mode,
|
||||
ci.cgrhead_id as cgreport_head_id
|
||||
from onl_cgreport_item ci
|
||||
where ci.cgrhead_id = #{cgrheadId,jdbcType=VARCHAR}
|
||||
order by ci.order_num asc
|
||||
</select>
|
||||
|
||||
<!-- 查询报表配置参数信息 -->
|
||||
<select id="queryCgReportParams" resultType="map" parameterType="java.lang.String">
|
||||
select * from onl_cgreport_param where cgrhead_id = #{cgrheadId,jdbcType=VARCHAR}
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="org.jeecg.modules.online.cgreport.mapper.OnlCgreportItemMapper">
|
||||
|
||||
</mapper>
|
||||
@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="org.jeecg.modules.online.cgreport.mapper.OnlCgreportParamMapper">
|
||||
|
||||
</mapper>
|
||||
@ -0,0 +1,79 @@
|
||||
package org.jeecg.modules.online.cgreport.model;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.jeecg.modules.online.cgreport.entity.OnlCgreportHead;
|
||||
import org.jeecg.modules.online.cgreport.entity.OnlCgreportItem;
|
||||
import org.jeecg.modules.online.cgreport.entity.OnlCgreportParam;
|
||||
|
||||
/**
|
||||
* @Description: 用于接收修改或新增报表信息的model
|
||||
* @author: sunjianlei
|
||||
* @date: 2019-03-11
|
||||
* @version: V1.0
|
||||
*/
|
||||
public class OnlCgreportModel {
|
||||
|
||||
private OnlCgreportHead head;
|
||||
|
||||
private List<OnlCgreportParam> params;
|
||||
private String deleteParamIds;
|
||||
|
||||
private List<OnlCgreportItem> items;
|
||||
private String deleteItemIds;
|
||||
|
||||
public OnlCgreportHead getHead() {
|
||||
return head;
|
||||
}
|
||||
|
||||
public void setHead(OnlCgreportHead head) {
|
||||
this.head = head;
|
||||
}
|
||||
|
||||
public List<OnlCgreportParam> getParams() {
|
||||
return params;
|
||||
}
|
||||
|
||||
public void setParams(List<OnlCgreportParam> params) {
|
||||
this.params = params;
|
||||
}
|
||||
|
||||
public List<OnlCgreportItem> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
public void setItems(List<OnlCgreportItem> items) {
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
public String getDeleteParamIds() {
|
||||
return deleteParamIds;
|
||||
}
|
||||
|
||||
public List<String> getDeleteParamIdList() {
|
||||
return Arrays.asList(deleteParamIds.split(","));
|
||||
}
|
||||
|
||||
public void setDeleteParamIds(String deleteParamIds) {
|
||||
this.deleteParamIds = deleteParamIds;
|
||||
}
|
||||
|
||||
public String getDeleteItemIds() {
|
||||
return deleteItemIds;
|
||||
}
|
||||
|
||||
public List<String> getDeleteItemIdList() {
|
||||
return Arrays.asList(deleteItemIds.split(","));
|
||||
}
|
||||
|
||||
public void setDeleteItemIds(String deleteItemIds) {
|
||||
this.deleteItemIds = deleteItemIds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "OnlCgreportModel [head=" + head + ", params=" + params + ", deleteParamIds=" + deleteParamIds + ", items=" + items + ", deleteItemIds=" + deleteItemIds + "]";
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
package org.jeecg.modules.online.cgreport.service;
|
||||
|
||||
|
||||
import java.util.Collection;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
|
||||
/**
|
||||
*
|
||||
* @Title:CgReportExcelServiceI
|
||||
* @description:动态报表excel导出
|
||||
* @author scott
|
||||
* @date 2019-03-21
|
||||
* @version V1.0
|
||||
*/
|
||||
public interface CgReportExcelServiceI{
|
||||
/**
|
||||
*
|
||||
* @param title 标题
|
||||
* @param titleSet 报表头
|
||||
* @param dataSet 报表内容
|
||||
* @return
|
||||
*/
|
||||
public HSSFWorkbook exportExcel(String title, Collection<?> titleSet,Collection<?> dataSet);
|
||||
}
|
||||
@ -0,0 +1,51 @@
|
||||
package org.jeecg.modules.online.cgreport.service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
import org.jeecg.modules.online.cgreport.entity.OnlCgreportHead;
|
||||
import org.jeecg.modules.online.cgreport.model.OnlCgreportModel;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* @Description: 在线报表配置
|
||||
* @author: jeecg-boot
|
||||
* @date: 2019-03-08
|
||||
* @version: V1.0
|
||||
*/
|
||||
public interface IOnlCgreportHeadService extends IService<OnlCgreportHead> {
|
||||
|
||||
/**
|
||||
* 修改全部项,包括新增、修改、删除
|
||||
*
|
||||
* @param values
|
||||
* @return
|
||||
*/
|
||||
Result<?> editAll(OnlCgreportModel values);
|
||||
|
||||
/**
|
||||
* 执行SQL语句
|
||||
*
|
||||
* @param sql
|
||||
* @return
|
||||
*/
|
||||
Map<String, Object> executeSelectSql(String sql,Map<String,Object> params);
|
||||
|
||||
/**
|
||||
* 动态数据源: 获取SQL解析的字段
|
||||
*/
|
||||
public List<String> getSqlFields(String sql,String dbKey);
|
||||
|
||||
|
||||
/**
|
||||
* 解析SQL参数
|
||||
*/
|
||||
public List<String> getSqlParams(String sql);
|
||||
|
||||
Map<String, Object> queryCgReportConfig(String reportCode);
|
||||
|
||||
public List<Map<?, ?>> queryByCgReportSql(String sql, Map params,Map paramData,int page, int rows);
|
||||
|
||||
}
|
||||
@ -0,0 +1,20 @@
|
||||
package org.jeecg.modules.online.cgreport.service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jeecg.modules.online.cgreport.entity.OnlCgreportItem;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* @Description: 在线报表配置
|
||||
* @author: jeecg-boot
|
||||
* @date: 2019-03-08
|
||||
* @version: V1.0
|
||||
*/
|
||||
public interface IOnlCgreportItemService extends IService<OnlCgreportItem> {
|
||||
|
||||
List<Map<String, String>> getAutoListQueryInfo(String cgrheadId);
|
||||
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
package org.jeecg.modules.online.cgreport.service;
|
||||
|
||||
import org.jeecg.modules.online.cgreport.entity.OnlCgreportParam;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* @Description: 在线报表配置
|
||||
* @author: jeecg-boot
|
||||
* @date: 2019-03-08
|
||||
* @version: V1.0
|
||||
*/
|
||||
public interface IOnlCgreportParamService extends IService<OnlCgreportParam> {
|
||||
|
||||
}
|
||||
@ -0,0 +1,144 @@
|
||||
package org.jeecg.modules.online.cgreport.service.impl;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
|
||||
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.hssf.util.HSSFColor;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.CellStyle;
|
||||
import org.apache.poi.ss.usermodel.RichTextString;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.jeecg.modules.online.cgreport.service.CgReportExcelServiceI;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @Description: Excel导出工具类
|
||||
* @author: scott
|
||||
* @date: 2019-03-21
|
||||
* @version: V1.0
|
||||
*/
|
||||
@Service(value = "cgReportExcelService")
|
||||
public class CgReportExcelServiceImpl implements CgReportExcelServiceI {
|
||||
|
||||
@Override
|
||||
public HSSFWorkbook exportExcel(String title, Collection<?> titleSet, Collection<?> dataSet) {
|
||||
// 声明一个工作薄
|
||||
HSSFWorkbook workbook = null;
|
||||
try {
|
||||
// 首先检查数据看是否是正确的
|
||||
if (titleSet == null || titleSet.size() == 0) {
|
||||
throw new Exception("读取表头失败!");
|
||||
}
|
||||
if (title == null) {
|
||||
title = "";
|
||||
}
|
||||
// 声明一个工作薄
|
||||
workbook = new HSSFWorkbook();
|
||||
// 生成一个表格
|
||||
Sheet sheet = workbook.createSheet(title);
|
||||
int rindex = 0;
|
||||
int cindex = 0;
|
||||
// 产生表格标题行
|
||||
Row row = sheet.createRow(rindex);
|
||||
row.setHeight((short) 450);
|
||||
CellStyle titleStyle = getTitleStyle(workbook);
|
||||
// Iterator itTitle = titleSet.iterator();
|
||||
List<Map> titleList = (List<Map>) titleSet;
|
||||
Iterator itData = dataSet.iterator();
|
||||
// 遍历标题行
|
||||
for (Map titleM : titleList) {
|
||||
String titleContent = (String) titleM.get("field_txt");
|
||||
Cell cell = row.createCell(cindex);
|
||||
RichTextString text = new HSSFRichTextString(titleContent);
|
||||
cell.setCellValue(text);
|
||||
cell.setCellStyle(titleStyle);
|
||||
cindex++;
|
||||
}
|
||||
HSSFCellStyle bodyStyle = getOneStyle(workbook);
|
||||
// 遍历内容
|
||||
while (itData.hasNext()) {
|
||||
cindex = 0;
|
||||
rindex++;
|
||||
row = sheet.createRow(rindex);
|
||||
Map dataM = (Map) itData.next();// 获取每一行的内容
|
||||
for (Map titleM : titleList) {
|
||||
String field = (String) titleM.get("field_name");
|
||||
String content = dataM.get(field) == null ? "" : dataM.get(field).toString();
|
||||
Cell cell = row.createCell(cindex);
|
||||
RichTextString text = new HSSFRichTextString(content);
|
||||
cell.setCellStyle(bodyStyle);
|
||||
cell.setCellValue(text);
|
||||
cindex++;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < titleList.size(); i++) {
|
||||
sheet.autoSizeColumn(i);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return workbook;
|
||||
}
|
||||
|
||||
/**
|
||||
* exce表头单元格样式处理
|
||||
*
|
||||
* @param workbook
|
||||
* @return
|
||||
*/
|
||||
private HSSFCellStyle getTitleStyle(HSSFWorkbook workbook) {
|
||||
// 产生Excel表头
|
||||
HSSFCellStyle titleStyle = workbook.createCellStyle();
|
||||
titleStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN); // 左边框
|
||||
titleStyle.setBorderRight(HSSFCellStyle.BORDER_THIN); // 右边框
|
||||
titleStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); // 底边框
|
||||
titleStyle.setBorderTop(HSSFCellStyle.BORDER_THIN); // 顶边框
|
||||
titleStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
|
||||
titleStyle.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index); // 填充的背景颜色
|
||||
titleStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); // 填充图案
|
||||
|
||||
return titleStyle;
|
||||
}
|
||||
|
||||
// 生成多少行的带有比边框的空行
|
||||
private void setBlankRows(int rows, int columns, HSSFWorkbook workbook) {
|
||||
// 得到第一页
|
||||
Sheet sheet = workbook.getSheetAt(0);
|
||||
// 样式
|
||||
CellStyle cellStyle = getOneStyle(workbook);
|
||||
for (int i = 1; i <= rows; i++) {
|
||||
Row row = sheet.createRow(i);
|
||||
for (int j = 0; j < columns; j++) {
|
||||
row.createCell(j).setCellStyle(cellStyle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private HSSFCellStyle getTwoStyle(HSSFWorkbook workbook) {
|
||||
// 产生Excel表头
|
||||
HSSFCellStyle style = workbook.createCellStyle();
|
||||
style.setBorderLeft((short) 1); // 左边框
|
||||
style.setBorderRight((short) 1); // 右边框
|
||||
style.setBorderBottom((short) 1);
|
||||
style.setBorderTop((short) 1);
|
||||
style.setFillForegroundColor(HSSFColor.LIGHT_TURQUOISE.index); // 填充的背景颜色
|
||||
style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); // 填充图案
|
||||
return style;
|
||||
}
|
||||
|
||||
private HSSFCellStyle getOneStyle(HSSFWorkbook workbook) {
|
||||
// 产生Excel表头
|
||||
HSSFCellStyle style = workbook.createCellStyle();
|
||||
style.setBorderLeft((short) 1); // 左边框
|
||||
style.setBorderRight((short) 1); // 右边框
|
||||
style.setBorderBottom((short) 1);
|
||||
style.setBorderTop((short) 1);
|
||||
return style;
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user