mirror of https://github.com/elunez/eladmin
修复定时任务执行失败后还继续执行的bug,优化Redis发生异常时,程序正常执行,优化Excel大数据导出,优化QueryHelp,其他细节优化
parent
a481b16bcf
commit
f9bb8cf241
|
@ -3,14 +3,14 @@ package me.zhengjie.redis;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.parser.ParserConfig;
|
import com.alibaba.fastjson.parser.ParserConfig;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import me.zhengjie.utils.StringUtils;
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
|
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
|
import org.springframework.cache.Cache;
|
||||||
import org.springframework.cache.annotation.CachingConfigurerSupport;
|
import org.springframework.cache.annotation.CachingConfigurerSupport;
|
||||||
import org.springframework.cache.annotation.EnableCaching;
|
import org.springframework.cache.annotation.EnableCaching;
|
||||||
|
import org.springframework.cache.interceptor.CacheErrorHandler;
|
||||||
import org.springframework.cache.interceptor.KeyGenerator;
|
import org.springframework.cache.interceptor.KeyGenerator;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
@ -74,8 +74,8 @@ public class RedisConfig extends CachingConfigurerSupport {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 自定义缓存key生成策略
|
* 自定义缓存key生成策略,默认将使用该策略
|
||||||
* 使用方法 @Cacheable(keyGenerator="keyGenerator")
|
* 使用方法 @Cacheable
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
|
@ -91,4 +91,34 @@ public class RedisConfig extends CachingConfigurerSupport {
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@Override
|
||||||
|
public CacheErrorHandler errorHandler() {
|
||||||
|
// 异常处理,当Redis发生异常时,打印日志,但是程序正常走
|
||||||
|
log.info("初始化 -> [{}]", "Redis CacheErrorHandler");
|
||||||
|
CacheErrorHandler cacheErrorHandler = new CacheErrorHandler() {
|
||||||
|
@Override
|
||||||
|
public void handleCacheGetError(RuntimeException e, Cache cache, Object key) {
|
||||||
|
log.error("Redis occur handleCacheGetError:key -> [{}]", key, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleCachePutError(RuntimeException e, Cache cache, Object key, Object value) {
|
||||||
|
log.error("Redis occur handleCachePutError:key -> [{}];value -> [{}]", key, value, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleCacheEvictError(RuntimeException e, Cache cache, Object key) {
|
||||||
|
log.error("Redis occur handleCacheEvictError:key -> [{}]", key, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleCacheClearError(RuntimeException e, Cache cache) {
|
||||||
|
log.error("Redis occur handleCacheClearError:", e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return cacheErrorHandler;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package me.zhengjie.utils;
|
||||||
import cn.hutool.core.codec.Base64;
|
import cn.hutool.core.codec.Base64;
|
||||||
import cn.hutool.core.io.IoUtil;
|
import cn.hutool.core.io.IoUtil;
|
||||||
import cn.hutool.core.util.IdUtil;
|
import cn.hutool.core.util.IdUtil;
|
||||||
|
import cn.hutool.poi.excel.BigExcelWriter;
|
||||||
import cn.hutool.poi.excel.ExcelUtil;
|
import cn.hutool.poi.excel.ExcelUtil;
|
||||||
import cn.hutool.poi.excel.ExcelWriter;
|
import cn.hutool.poi.excel.ExcelWriter;
|
||||||
import me.zhengjie.exception.BadRequestException;
|
import me.zhengjie.exception.BadRequestException;
|
||||||
|
@ -197,24 +198,20 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
|
||||||
* @return
|
* @return
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public static void downloadExcel(List<Map<String, Object>> list, HttpServletResponse response){
|
public static void downloadExcel(List<Map<String, Object>> list, HttpServletResponse response) throws IOException {
|
||||||
// 通过工具类创建writer
|
String tempPath =System.getProperty("java.io.tmpdir") + IdUtil.fastSimpleUUID() + ".xlsx";
|
||||||
ExcelWriter writer = ExcelUtil.getWriter();
|
File file = new File(tempPath);
|
||||||
|
BigExcelWriter writer= ExcelUtil.getBigWriter(file);
|
||||||
// 一次性写出内容,使用默认样式,强制输出标题
|
// 一次性写出内容,使用默认样式,强制输出标题
|
||||||
writer.write(list, true);
|
writer.write(list, true);
|
||||||
//response为HttpServletResponse对象
|
//response为HttpServletResponse对象
|
||||||
response.setContentType("application/vnd.ms-excel;charset=utf-8");
|
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
|
||||||
//test.xls是弹出下载对话框的文件名,不能为中文,中文请自行编码
|
//test.xls是弹出下载对话框的文件名,不能为中文,中文请自行编码
|
||||||
response.setHeader("Content-Disposition","attachment;filename=file.xls");
|
response.setHeader("Content-Disposition","attachment;filename=file.xlsx");
|
||||||
ServletOutputStream out= null;
|
ServletOutputStream out=response.getOutputStream();
|
||||||
try {
|
// 终止后删除临时文件
|
||||||
out = response.getOutputStream();
|
file.deleteOnExit();
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
writer.flush(out, true);
|
writer.flush(out, true);
|
||||||
// 关闭writer,释放内存
|
|
||||||
writer.close();
|
|
||||||
//此处记得关闭输出Servlet流
|
//此处记得关闭输出Servlet流
|
||||||
IoUtil.close(out);
|
IoUtil.close(out);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
package me.zhengjie.utils;
|
package me.zhengjie.utils;
|
||||||
|
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分页工具
|
* 分页工具
|
||||||
|
@ -39,11 +36,9 @@ public class PageUtil extends cn.hutool.core.util.PageUtil {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static Map toPage(Page page) {
|
public static Map toPage(Page page) {
|
||||||
Map map = new HashMap();
|
Map<String,Object> map = new LinkedHashMap<>(2);
|
||||||
|
|
||||||
map.put("content",page.getContent());
|
map.put("content",page.getContent());
|
||||||
map.put("totalElements",page.getTotalElements());
|
map.put("totalElements",page.getTotalElements());
|
||||||
|
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,8 +48,7 @@ public class PageUtil extends cn.hutool.core.util.PageUtil {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static Map toPage(Object object, Object totalElements) {
|
public static Map toPage(Object object, Object totalElements) {
|
||||||
Map map = new HashMap();
|
Map<String,Object> map = new LinkedHashMap<>(2);
|
||||||
|
|
||||||
map.put("content",object);
|
map.put("content",object);
|
||||||
map.put("totalElements",totalElements);
|
map.put("totalElements",totalElements);
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@ public class QueryHelp {
|
||||||
String attributeName = isBlank(propName) ? field.getName() : propName;
|
String attributeName = isBlank(propName) ? field.getName() : propName;
|
||||||
Class<?> fieldType = field.getType();
|
Class<?> fieldType = field.getType();
|
||||||
Object val = field.get(query);
|
Object val = field.get(query);
|
||||||
if (ObjectUtil.isNull(val)) {
|
if (ObjectUtil.isNull(val) || "".equals(val)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Join join = null;
|
Join join = null;
|
||||||
|
@ -58,15 +58,26 @@ public class QueryHelp {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (ObjectUtil.isNotEmpty(joinName)) {
|
if (ObjectUtil.isNotEmpty(joinName)) {
|
||||||
|
String[] joinNames = joinName.split(">");
|
||||||
|
for (String name : joinNames) {
|
||||||
switch (q.join()) {
|
switch (q.join()) {
|
||||||
case LEFT:
|
case LEFT:
|
||||||
join = root.join(joinName, JoinType.LEFT);
|
if(ObjectUtil.isNotEmpty(join)){
|
||||||
|
join = join.join(name, JoinType.LEFT);
|
||||||
|
} else {
|
||||||
|
join = root.join(name, JoinType.LEFT);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case RIGHT:
|
case RIGHT:
|
||||||
join = root.join(joinName, JoinType.RIGHT);
|
if(ObjectUtil.isNotEmpty(join)){
|
||||||
|
join = join.join(name, JoinType.RIGHT);
|
||||||
|
} else {
|
||||||
|
join = root.join(name, JoinType.RIGHT);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
switch (q.type()) {
|
switch (q.type()) {
|
||||||
case EQUAL:
|
case EQUAL:
|
||||||
list.add(cb.equal(getExpression(attributeName,join,root)
|
list.add(cb.equal(getExpression(attributeName,join,root)
|
||||||
|
|
|
@ -21,7 +21,7 @@ public interface QuartzJobService {
|
||||||
* @param pageable
|
* @param pageable
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Cacheable(keyGenerator = "keyGenerator")
|
@Cacheable
|
||||||
Object queryAll(JobQueryCriteria criteria, Pageable pageable);
|
Object queryAll(JobQueryCriteria criteria, Pageable pageable);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package me.zhengjie.modules.quartz.task;
|
package me.zhengjie.modules.quartz.task;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import me.zhengjie.exception.BadRequestException;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -25,6 +25,7 @@ public class ExecutionJob extends QuartzJobBean {
|
||||||
|
|
||||||
private Logger logger = LoggerFactory.getLogger(this.getClass());
|
private Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||||
|
|
||||||
|
// 建议自定义线程池实现方式,该处仅供参考
|
||||||
private ExecutorService executorService = Executors.newSingleThreadExecutor();
|
private ExecutorService executorService = Executors.newSingleThreadExecutor();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -61,8 +62,7 @@ public class ExecutionJob extends QuartzJobBean {
|
||||||
// 任务状态 0:成功 1:失败
|
// 任务状态 0:成功 1:失败
|
||||||
log.setIsSuccess(false);
|
log.setIsSuccess(false);
|
||||||
log.setExceptionDetail(ThrowableUtil.getStackTrace(e));
|
log.setExceptionDetail(ThrowableUtil.getStackTrace(e));
|
||||||
//出错就暂停任务
|
quartzJob.setIsPause(false);
|
||||||
quartzManage.pauseJob(quartzJob);
|
|
||||||
//更新状态
|
//更新状态
|
||||||
quartzJobService.updateIsPause(quartzJob);
|
quartzJobService.updateIsPause(quartzJob);
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -1,17 +1,19 @@
|
||||||
package me.zhengjie.modules.quartz.utils;
|
package me.zhengjie.modules.quartz.utils;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import me.zhengjie.exception.BadRequestException;
|
||||||
import me.zhengjie.utils.SpringContextHolder;
|
import me.zhengjie.utils.SpringContextHolder;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.util.ReflectionUtils;
|
import org.springframework.util.ReflectionUtils;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 执行定时任务
|
* 执行定时任务
|
||||||
* @author
|
* @author
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class QuartzRunnable implements Runnable {
|
public class QuartzRunnable implements Callable {
|
||||||
|
|
||||||
private Object target;
|
private Object target;
|
||||||
private Method method;
|
private Method method;
|
||||||
|
@ -30,17 +32,13 @@ public class QuartzRunnable implements Runnable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public Object call() throws Exception {
|
||||||
try {
|
|
||||||
ReflectionUtils.makeAccessible(method);
|
ReflectionUtils.makeAccessible(method);
|
||||||
if (StringUtils.isNotBlank(params)) {
|
if (StringUtils.isNotBlank(params)) {
|
||||||
method.invoke(target, params);
|
method.invoke(target, params);
|
||||||
} else {
|
} else {
|
||||||
method.invoke(target);
|
method.invoke(target);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
return null;
|
||||||
log.error("定时任务执行失败",e);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@ -59,7 +60,7 @@ public class UserController {
|
||||||
@Log("导出用户数据")
|
@Log("导出用户数据")
|
||||||
@GetMapping(value = "/users/download")
|
@GetMapping(value = "/users/download")
|
||||||
@PreAuthorize("hasAnyRole('ADMIN','USER_ALL','USER_SELECT')")
|
@PreAuthorize("hasAnyRole('ADMIN','USER_ALL','USER_SELECT')")
|
||||||
public void update(HttpServletResponse response, UserQueryCriteria criteria){
|
public void update(HttpServletResponse response, UserQueryCriteria criteria) throws IOException {
|
||||||
userService.download(userService.queryAll(criteria), response);
|
userService.download(userService.queryAll(criteria), response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ public interface DeptService {
|
||||||
* @param criteria
|
* @param criteria
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Cacheable(keyGenerator = "keyGenerator")
|
@Cacheable
|
||||||
List<DeptDTO> queryAll(DeptQueryCriteria criteria);
|
List<DeptDTO> queryAll(DeptQueryCriteria criteria);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -60,7 +60,7 @@ public interface DeptService {
|
||||||
* @param deptDTOS
|
* @param deptDTOS
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Cacheable(keyGenerator = "keyGenerator")
|
@Cacheable
|
||||||
Object buildTree(List<DeptDTO> deptDTOS);
|
Object buildTree(List<DeptDTO> deptDTOS);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -68,7 +68,7 @@ public interface DeptService {
|
||||||
* @param pid
|
* @param pid
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Cacheable(keyGenerator = "keyGenerator")
|
@Cacheable
|
||||||
List<Dept> findByPid(long pid);
|
List<Dept> findByPid(long pid);
|
||||||
|
|
||||||
Set<Dept> findByRoleIds(Long id);
|
Set<Dept> findByRoleIds(Long id);
|
||||||
|
|
|
@ -47,6 +47,6 @@ public interface DictDetailService {
|
||||||
@CacheEvict(allEntries = true)
|
@CacheEvict(allEntries = true)
|
||||||
void delete(Long id);
|
void delete(Long id);
|
||||||
|
|
||||||
@Cacheable(keyGenerator = "keyGenerator")
|
@Cacheable
|
||||||
Map queryAll(DictDetailQueryCriteria criteria, Pageable pageable);
|
Map queryAll(DictDetailQueryCriteria criteria, Pageable pageable);
|
||||||
}
|
}
|
|
@ -21,7 +21,7 @@ public interface DictService {
|
||||||
* @param pageable
|
* @param pageable
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Cacheable(keyGenerator = "keyGenerator")
|
@Cacheable
|
||||||
Object queryAll(DictQueryCriteria dict, Pageable pageable);
|
Object queryAll(DictQueryCriteria dict, Pageable pageable);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -23,7 +23,7 @@ public interface MenuService {
|
||||||
* @param criteria
|
* @param criteria
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Cacheable(keyGenerator = "keyGenerator")
|
@Cacheable
|
||||||
List<MenuDTO> queryAll(MenuQueryCriteria criteria);
|
List<MenuDTO> queryAll(MenuQueryCriteria criteria);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -67,7 +67,7 @@ public interface PermissionService {
|
||||||
* @param permissionDTOS
|
* @param permissionDTOS
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Cacheable(keyGenerator = "keyGenerator")
|
@Cacheable
|
||||||
Object buildTree(List<PermissionDTO> permissionDTOS);
|
Object buildTree(List<PermissionDTO> permissionDTOS);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -75,7 +75,7 @@ public interface PermissionService {
|
||||||
* @param criteria
|
* @param criteria
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Cacheable(keyGenerator = "keyGenerator")
|
@Cacheable
|
||||||
List<PermissionDTO> queryAll(PermissionQueryCriteria criteria);
|
List<PermissionDTO> queryAll(PermissionQueryCriteria criteria);
|
||||||
|
|
||||||
Set<Permission> getDeletePermission(List<Permission> permissions, Set<Permission> permissionSet);
|
Set<Permission> getDeletePermission(List<Permission> permissions, Set<Permission> permissionSet);
|
||||||
|
|
|
@ -58,7 +58,7 @@ public interface RoleService {
|
||||||
@Cacheable(key = "'findByUsers_Id:' + #p0")
|
@Cacheable(key = "'findByUsers_Id:' + #p0")
|
||||||
List<RoleSmallDTO> findByUsers_Id(Long id);
|
List<RoleSmallDTO> findByUsers_Id(Long id);
|
||||||
|
|
||||||
@Cacheable(keyGenerator = "keyGenerator")
|
@Cacheable
|
||||||
Integer findByRoles(Set<Role> roles);
|
Integer findByRoles(Set<Role> roles);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -85,7 +85,7 @@ public interface RoleService {
|
||||||
* @param pageable
|
* @param pageable
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Cacheable(keyGenerator = "keyGenerator")
|
@Cacheable
|
||||||
Object queryAll(Pageable pageable);
|
Object queryAll(Pageable pageable);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -94,7 +94,7 @@ public interface RoleService {
|
||||||
* @param criteria
|
* @param criteria
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Cacheable(keyGenerator = "keyGenerator")
|
@Cacheable
|
||||||
Object queryAll(RoleQueryCriteria criteria, Pageable pageable);
|
Object queryAll(RoleQueryCriteria criteria, Pageable pageable);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -102,7 +102,7 @@ public interface RoleService {
|
||||||
* @param criteria
|
* @param criteria
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Cacheable(keyGenerator = "keyGenerator")
|
@Cacheable
|
||||||
List<RoleDTO> queryAll(RoleQueryCriteria criteria);
|
List<RoleDTO> queryAll(RoleQueryCriteria criteria);
|
||||||
|
|
||||||
@CacheEvict(allEntries = true)
|
@CacheEvict(allEntries = true)
|
||||||
|
|
|
@ -11,6 +11,7 @@ import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -81,11 +82,11 @@ public interface UserService {
|
||||||
@CacheEvict(allEntries = true)
|
@CacheEvict(allEntries = true)
|
||||||
void updateEmail(String username, String email);
|
void updateEmail(String username, String email);
|
||||||
|
|
||||||
@Cacheable(keyGenerator = "keyGenerator")
|
@Cacheable
|
||||||
Object queryAll(UserQueryCriteria criteria, Pageable pageable);
|
Object queryAll(UserQueryCriteria criteria, Pageable pageable);
|
||||||
|
|
||||||
@Cacheable(keyGenerator = "keyGenerator")
|
@Cacheable
|
||||||
List<UserDTO> queryAll(UserQueryCriteria criteria);
|
List<UserDTO> queryAll(UserQueryCriteria criteria);
|
||||||
|
|
||||||
void download(List<UserDTO> queryAll, HttpServletResponse response);
|
void download(List<UserDTO> queryAll, HttpServletResponse response) throws IOException;
|
||||||
}
|
}
|
||||||
|
|
|
@ -180,7 +180,7 @@ public class UserServiceImpl implements UserService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void download(List<UserDTO> queryAll, HttpServletResponse response) {
|
public void download(List<UserDTO> queryAll, HttpServletResponse response) throws IOException {
|
||||||
List<Map<String, Object>> list = new ArrayList<>();
|
List<Map<String, Object>> list = new ArrayList<>();
|
||||||
for (UserDTO userDTO : queryAll) {
|
for (UserDTO userDTO : queryAll) {
|
||||||
List roles = userDTO.getRoles().stream().map(RoleSmallDTO::getName).collect(Collectors.toList());
|
List roles = userDTO.getRoles().stream().map(RoleSmallDTO::getName).collect(Collectors.toList());
|
||||||
|
|
|
@ -1,2 +1,4 @@
|
||||||
# If you use SLF4J. First, you need to tell log4jdbc-log4j2 that you want to use the SLF4J logger
|
# If you use SLF4J. First, you need to tell log4jdbc-log4j2 that you want to use the SLF4J logger
|
||||||
log4jdbc.spylogdelegator.name=net.sf.log4jdbc.log.slf4j.Slf4jSpyLogDelegator
|
log4jdbc.spylogdelegator.name=net.sf.log4jdbc.log.slf4j.Slf4jSpyLogDelegator
|
||||||
|
log4jdbc.auto.load.popular.drivers=false
|
||||||
|
log4jdbc.drivers=com.mysql.cj.jdbc.Driver
|
|
@ -3,10 +3,12 @@ package ${package}.service;
|
||||||
import ${package}.domain.${className};
|
import ${package}.domain.${className};
|
||||||
import ${package}.service.dto.${className}DTO;
|
import ${package}.service.dto.${className}DTO;
|
||||||
import ${package}.service.dto.${className}QueryCriteria;
|
import ${package}.service.dto.${className}QueryCriteria;
|
||||||
//import org.springframework.cache.annotation.CacheConfig;
|
import org.springframework.cache.annotation.CacheConfig;
|
||||||
//import org.springframework.cache.annotation.CacheEvict;
|
import org.springframework.cache.annotation.CacheEvict;
|
||||||
//import org.springframework.cache.annotation.Cacheable;
|
import org.springframework.cache.annotation.Cacheable;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author ${author}
|
* @author ${author}
|
||||||
|
@ -16,24 +18,24 @@ import org.springframework.data.domain.Pageable;
|
||||||
public interface ${className}Service {
|
public interface ${className}Service {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* queryAll 分页
|
* 查询数据分页
|
||||||
* @param criteria
|
* @param criteria
|
||||||
* @param pageable
|
* @param pageable
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
//@Cacheable(keyGenerator = "keyGenerator")
|
//@Cacheable
|
||||||
Object queryAll(${className}QueryCriteria criteria, Pageable pageable);
|
Map<String,Object> queryAll(${className}QueryCriteria criteria, Pageable pageable);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* queryAll 不分页
|
* 查询所有数据不分页
|
||||||
* @param criteria
|
* @param criteria
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
//@Cacheable(keyGenerator = "keyGenerator")
|
//@Cacheable
|
||||||
public Object queryAll(${className}QueryCriteria criteria);
|
List<${className}DTO> queryAll(${className}QueryCriteria criteria);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* findById
|
* 根据ID查询
|
||||||
* @param ${pkChangeColName}
|
* @param ${pkChangeColName}
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
@ -41,7 +43,7 @@ public interface ${className}Service {
|
||||||
${className}DTO findById(${pkColumnType} ${pkChangeColName});
|
${className}DTO findById(${pkColumnType} ${pkChangeColName});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* create
|
* 创建
|
||||||
* @param resources
|
* @param resources
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
@ -49,14 +51,14 @@ public interface ${className}Service {
|
||||||
${className}DTO create(${className} resources);
|
${className}DTO create(${className} resources);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* update
|
* 编辑
|
||||||
* @param resources
|
* @param resources
|
||||||
*/
|
*/
|
||||||
//@CacheEvict(allEntries = true)
|
//@CacheEvict(allEntries = true)
|
||||||
void update(${className} resources);
|
void update(${className} resources);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* delete
|
* 删除
|
||||||
* @param ${pkChangeColName}
|
* @param ${pkChangeColName}
|
||||||
*/
|
*/
|
||||||
//@CacheEvict(allEntries = true)
|
//@CacheEvict(allEntries = true)
|
||||||
|
|
|
@ -32,6 +32,8 @@ import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import me.zhengjie.utils.PageUtil;
|
import me.zhengjie.utils.PageUtil;
|
||||||
import me.zhengjie.utils.QueryHelp;
|
import me.zhengjie.utils.QueryHelp;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author ${author}
|
* @author ${author}
|
||||||
|
@ -48,13 +50,13 @@ public class ${className}ServiceImpl implements ${className}Service {
|
||||||
private ${className}Mapper ${changeClassName}Mapper;
|
private ${className}Mapper ${changeClassName}Mapper;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object queryAll(${className}QueryCriteria criteria, Pageable pageable){
|
public Map<String,Object> queryAll(${className}QueryCriteria criteria, Pageable pageable){
|
||||||
Page<${className}> page = ${changeClassName}Repository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
|
Page<${className}> page = ${changeClassName}Repository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
|
||||||
return PageUtil.toPage(page.map(${changeClassName}Mapper::toDto));
|
return PageUtil.toPage(page.map(${changeClassName}Mapper::toDto));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object queryAll(${className}QueryCriteria criteria){
|
public List<${className}DTO> queryAll(${className}QueryCriteria criteria){
|
||||||
return ${changeClassName}Mapper.toDto(${changeClassName}Repository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
|
return ${changeClassName}Mapper.toDto(${changeClassName}Repository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ public class PictureController {
|
||||||
public ResponseEntity upload(@RequestParam MultipartFile file){
|
public ResponseEntity upload(@RequestParam MultipartFile file){
|
||||||
String userName = SecurityUtils.getUsername();
|
String userName = SecurityUtils.getUsername();
|
||||||
Picture picture = pictureService.upload(file,userName);
|
Picture picture = pictureService.upload(file,userName);
|
||||||
Map map = new HashMap(3);
|
Map<String,Object> map = new HashMap<>(3);
|
||||||
map.put("errno",0);
|
map.put("errno",0);
|
||||||
map.put("id",picture.getId());
|
map.put("id",picture.getId());
|
||||||
map.put("data",new String[]{picture.getUrl()});
|
map.put("data",new String[]{picture.getUrl()});
|
||||||
|
|
|
@ -22,7 +22,7 @@ public interface LocalStorageService {
|
||||||
* @param pageable
|
* @param pageable
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Cacheable(keyGenerator = "keyGenerator")
|
@Cacheable
|
||||||
Object queryAll(LocalStorageQueryCriteria criteria, Pageable pageable);
|
Object queryAll(LocalStorageQueryCriteria criteria, Pageable pageable);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -30,7 +30,7 @@ public interface LocalStorageService {
|
||||||
* @param criteria
|
* @param criteria
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Cacheable(keyGenerator = "keyGenerator")
|
@Cacheable
|
||||||
public Object queryAll(LocalStorageQueryCriteria criteria);
|
public Object queryAll(LocalStorageQueryCriteria criteria);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -20,7 +20,7 @@ public interface PictureService {
|
||||||
* @param pageable
|
* @param pageable
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Cacheable(keyGenerator = "keyGenerator")
|
@Cacheable
|
||||||
Object queryAll(PictureQueryCriteria criteria, Pageable pageable);
|
Object queryAll(PictureQueryCriteria criteria, Pageable pageable);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -24,7 +24,7 @@ public interface QiNiuService {
|
||||||
* @param pageable
|
* @param pageable
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Cacheable(keyGenerator = "keyGenerator")
|
@Cacheable
|
||||||
Object queryAll(QiniuQueryCriteria criteria, Pageable pageable);
|
Object queryAll(QiniuQueryCriteria criteria, Pageable pageable);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
11
pom.xml
11
pom.xml
|
@ -160,6 +160,17 @@
|
||||||
<artifactId>poi</artifactId>
|
<artifactId>poi</artifactId>
|
||||||
<version>3.17</version>
|
<version>3.17</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.poi</groupId>
|
||||||
|
<artifactId>poi-ooxml</artifactId>
|
||||||
|
<version>3.17</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- https://mvnrepository.com/artifact/xerces/xercesImpl -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>xerces</groupId>
|
||||||
|
<artifactId>xercesImpl</artifactId>
|
||||||
|
<version>2.11.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- fastjson -->
|
<!-- fastjson -->
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
Loading…
Reference in New Issue