mirror of https://github.com/elunez/eladmin
Merge branch '2.2DEV'
commit
0f0392d782
|
@ -10,5 +10,6 @@
|
|||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>eladmin-common</artifactId>
|
||||
<name>公共模块</name>
|
||||
|
||||
</project>
|
|
@ -3,14 +3,14 @@ package me.zhengjie.redis;
|
|||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.parser.ParserConfig;
|
||||
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.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.cache.Cache;
|
||||
import org.springframework.cache.annotation.CachingConfigurerSupport;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.cache.interceptor.CacheErrorHandler;
|
||||
import org.springframework.cache.interceptor.KeyGenerator;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
@ -61,6 +61,7 @@ public class RedisConfig extends CachingConfigurerSupport {
|
|||
// 建议使用这种方式,小范围指定白名单
|
||||
ParserConfig.getGlobalInstance().addAccept("me.zhengjie.domain");
|
||||
ParserConfig.getGlobalInstance().addAccept("me.zhengjie.modules.system.service.dto");
|
||||
ParserConfig.getGlobalInstance().addAccept("me.zhengjie.service.dto");
|
||||
ParserConfig.getGlobalInstance().addAccept("me.zhengjie.modules.system.domain");
|
||||
ParserConfig.getGlobalInstance().addAccept("me.zhengjie.modules.quartz.domain");
|
||||
ParserConfig.getGlobalInstance().addAccept("me.zhengjie.modules.monitor.domain");
|
||||
|
@ -73,8 +74,8 @@ public class RedisConfig extends CachingConfigurerSupport {
|
|||
}
|
||||
|
||||
/**
|
||||
* 自定义缓存key生成策略
|
||||
* 使用方法 @Cacheable(keyGenerator="keyGenerator")
|
||||
* 自定义缓存key生成策略,默认将使用该策略
|
||||
* 使用方法 @Cacheable
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
|
@ -90,4 +91,34 @@ public class RedisConfig extends CachingConfigurerSupport {
|
|||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,10 +1,21 @@
|
|||
package me.zhengjie.utils;
|
||||
|
||||
import cn.hutool.core.codec.Base64;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.poi.excel.BigExcelWriter;
|
||||
import cn.hutool.poi.excel.ExcelUtil;
|
||||
import cn.hutool.poi.excel.ExcelWriter;
|
||||
import me.zhengjie.exception.BadRequestException;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.*;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* File工具类,扩展 hutool 工具包
|
||||
|
@ -100,7 +111,7 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
|
|||
* @param size
|
||||
* @return
|
||||
*/
|
||||
public static String getSize(int size){
|
||||
public static String getSize(long size){
|
||||
String resultSize = "";
|
||||
if (size / GB >= 1) {
|
||||
//如果当前Byte的值大于等于1GB
|
||||
|
@ -139,4 +150,91 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
|
|||
ins.close();
|
||||
return file;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将文件名解析成文件的上传路径
|
||||
*
|
||||
* @param file
|
||||
* @param filePath
|
||||
* @return 上传到服务器的文件名
|
||||
*/
|
||||
public static File upload(MultipartFile file, String filePath) {
|
||||
Date date = new Date();
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddhhmmssS");
|
||||
String name = getFileNameNoEx(file.getOriginalFilename());
|
||||
String suffix = getExtensionName(file.getOriginalFilename());
|
||||
String nowStr = "-" + format.format(date);
|
||||
try {
|
||||
String fileName = name + nowStr + "." + suffix;
|
||||
String path = filePath + fileName;
|
||||
File dest = new File(path);
|
||||
// 检测是否存在目录
|
||||
if (!dest.getParentFile().exists()) {
|
||||
dest.getParentFile().mkdirs();// 新建文件夹
|
||||
}
|
||||
String d = dest.getPath();
|
||||
file.transferTo(dest);// 文件写入
|
||||
return dest;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String fileToBase64(File file) throws Exception {
|
||||
FileInputStream inputFile = new FileInputStream(file);
|
||||
String base64 =null;
|
||||
byte[] buffer = new byte[(int)file.length()];
|
||||
inputFile.read(buffer);
|
||||
inputFile.close();
|
||||
base64=new Base64().encode(buffer);
|
||||
String encoded = base64.replaceAll("[\\s*\t\n\r]", "");
|
||||
return encoded;
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出excel
|
||||
* @param list
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static void downloadExcel(List<Map<String, Object>> list, HttpServletResponse response) throws IOException {
|
||||
String tempPath =System.getProperty("java.io.tmpdir") + IdUtil.fastSimpleUUID() + ".xlsx";
|
||||
File file = new File(tempPath);
|
||||
BigExcelWriter writer= ExcelUtil.getBigWriter(file);
|
||||
// 一次性写出内容,使用默认样式,强制输出标题
|
||||
writer.write(list, true);
|
||||
//response为HttpServletResponse对象
|
||||
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
|
||||
//test.xls是弹出下载对话框的文件名,不能为中文,中文请自行编码
|
||||
response.setHeader("Content-Disposition","attachment;filename=file.xlsx");
|
||||
ServletOutputStream out=response.getOutputStream();
|
||||
// 终止后删除临时文件
|
||||
file.deleteOnExit();
|
||||
writer.flush(out, true);
|
||||
//此处记得关闭输出Servlet流
|
||||
IoUtil.close(out);
|
||||
}
|
||||
|
||||
public static String getFileType(String type) {
|
||||
String documents = "txt doc pdf ppt pps xlsx xls";
|
||||
String music = "mp3 wav wma mpa ram ra aac aif m4a";
|
||||
String video = "avi mpg mpe mpeg asf wmv mov qt rm mp4 flv m4v webm ogv ogg";
|
||||
String image = "bmp dib pcp dif wmf gif jpg tif eps psd cdr iff tga pcd mpt png jpeg";
|
||||
if(image.indexOf(type) != -1){
|
||||
return "图片";
|
||||
} else if(documents.indexOf(type) != -1){
|
||||
return "文档";
|
||||
} else if(music.indexOf(type) != -1){
|
||||
return "音乐";
|
||||
} else if(video.indexOf(type) != -1){
|
||||
return "视频";
|
||||
} else return "其他";
|
||||
}
|
||||
|
||||
public static void checkSize(long maxSize, long size) {
|
||||
if(size > (maxSize * 1024 * 1024)){
|
||||
throw new BadRequestException("文件超出规定大小");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
package me.zhengjie.utils;
|
||||
|
||||
import org.springframework.data.domain.Page;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 分页工具
|
||||
|
@ -39,11 +36,9 @@ public class PageUtil extends cn.hutool.core.util.PageUtil {
|
|||
* @return
|
||||
*/
|
||||
public static Map toPage(Page page) {
|
||||
Map map = new HashMap();
|
||||
|
||||
Map<String,Object> map = new LinkedHashMap<>(2);
|
||||
map.put("content",page.getContent());
|
||||
map.put("totalElements",page.getTotalElements());
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
|
@ -53,8 +48,7 @@ public class PageUtil extends cn.hutool.core.util.PageUtil {
|
|||
* @return
|
||||
*/
|
||||
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("totalElements",totalElements);
|
||||
|
||||
|
|
|
@ -58,13 +58,24 @@ public class QueryHelp {
|
|||
continue;
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(joinName)) {
|
||||
switch (q.join()) {
|
||||
case LEFT:
|
||||
join = root.join(joinName, JoinType.LEFT);
|
||||
break;
|
||||
case RIGHT:
|
||||
join = root.join(joinName, JoinType.RIGHT);
|
||||
break;
|
||||
String[] joinNames = joinName.split(">");
|
||||
for (String name : joinNames) {
|
||||
switch (q.join()) {
|
||||
case LEFT:
|
||||
if(ObjectUtil.isNotEmpty(join)){
|
||||
join = join.join(name, JoinType.LEFT);
|
||||
} else {
|
||||
join = root.join(name, JoinType.LEFT);
|
||||
}
|
||||
break;
|
||||
case RIGHT:
|
||||
if(ObjectUtil.isNotEmpty(join)){
|
||||
join = join.join(name, JoinType.RIGHT);
|
||||
} else {
|
||||
join = root.join(name, JoinType.RIGHT);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
switch (q.type()) {
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package me.zhengjie.utils;
|
||||
|
||||
import me.zhengjie.exception.BadRequestException;
|
||||
import org.hibernate.exception.ConstraintViolationException;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
|
||||
|
@ -25,4 +28,15 @@ public class ThrowableUtil {
|
|||
pw.close();
|
||||
}
|
||||
}
|
||||
|
||||
public static void throwForeignKeyException(Throwable e, String msg){
|
||||
Throwable t = e.getCause();
|
||||
while ((t != null) && !(t instanceof ConstraintViolationException)) {
|
||||
t = t.getCause();
|
||||
}
|
||||
if (t instanceof ConstraintViolationException) {
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
throw new BadRequestException("删除失败:" + t.getMessage());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
package me.zhengjie.utils;
|
||||
|
||||
import cn.hutool.json.JSONArray;
|
||||
import lombok.var;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
|
||||
public class TranslatorUtil {
|
||||
|
||||
public static String translate(String word){
|
||||
try {
|
||||
String url = "https://translate.googleapis.com/translate_a/single?" +
|
||||
"client=gtx&" +
|
||||
"sl=en" +
|
||||
"&tl=zh-CN" +
|
||||
"&dt=t&q=" + URLEncoder.encode(word, "UTF-8");
|
||||
|
||||
URL obj = new URL(url);
|
||||
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
|
||||
con.setRequestProperty("User-Agent", "Mozilla/5.0");
|
||||
|
||||
BufferedReader in = new BufferedReader(
|
||||
new InputStreamReader(con.getInputStream()));
|
||||
String inputLine;
|
||||
StringBuffer response = new StringBuffer();
|
||||
|
||||
while ((inputLine = in.readLine()) != null) {
|
||||
response.append(inputLine);
|
||||
}
|
||||
in.close();
|
||||
return parseResult(response.toString());
|
||||
}catch (Exception e){
|
||||
return word;
|
||||
}
|
||||
}
|
||||
|
||||
private static String parseResult(String inputJson) throws Exception {
|
||||
JSONArray jsonArray = new JSONArray(inputJson);
|
||||
JSONArray jsonArray2 = (JSONArray) jsonArray.get(0);
|
||||
String result ="";
|
||||
|
||||
for(var i = 0; i < jsonArray2.size(); i ++){
|
||||
result += ((JSONArray) jsonArray2.get(i)).get(0).toString();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
|
@ -10,6 +10,7 @@
|
|||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>eladmin-generator</artifactId>
|
||||
<name>代码生成模块</name>
|
||||
|
||||
<properties>
|
||||
<configuration.version>1.9</configuration.version>
|
||||
|
|
|
@ -5,6 +5,8 @@ import me.zhengjie.repository.GenConfigRepository;
|
|||
import me.zhengjie.service.GenConfigService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
|
@ -30,6 +32,22 @@ public class GenConfigServiceImpl implements GenConfigService {
|
|||
@Override
|
||||
public GenConfig update(GenConfig genConfig) {
|
||||
genConfig.setId(1L);
|
||||
// 自动设置Api路径,注释掉前需要同步取消前端的注释
|
||||
String separator = File.separator;
|
||||
String[] paths = null;
|
||||
if (separator.equals("\\")) {
|
||||
paths = genConfig.getPath().split("\\\\");
|
||||
} else paths = genConfig.getPath().split(File.separator);
|
||||
StringBuffer api = new StringBuffer();
|
||||
for (int i = 0; i < paths.length; i++) {
|
||||
api.append(paths[i]);
|
||||
api.append(separator);
|
||||
if(paths[i].equals("src")){
|
||||
api.append("api");
|
||||
break;
|
||||
}
|
||||
}
|
||||
genConfig.setApiPath(api.toString());
|
||||
return genConfigRepository.save(genConfig);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>eladmin-logging</artifactId>
|
||||
<name>日志模块</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>eladmin-system</artifactId>
|
||||
<name>核心模块</name>
|
||||
|
||||
<properties>
|
||||
<jjwt.version>0.9.1</jjwt.version>
|
||||
|
|
|
@ -3,6 +3,7 @@ package me.zhengjie.config;
|
|||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.http.converter.StringHttpMessageConverter;
|
||||
|
@ -25,6 +26,12 @@ import java.util.List;
|
|||
@EnableWebMvc
|
||||
public class ConfigurerAdapter implements WebMvcConfigurer {
|
||||
|
||||
@Value("${file.path}")
|
||||
private String path;
|
||||
|
||||
@Value("${file.avatar}")
|
||||
private String avatar;
|
||||
|
||||
@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
registry.addMapping("/**")
|
||||
|
@ -35,27 +42,12 @@ public class ConfigurerAdapter implements WebMvcConfigurer {
|
|||
|
||||
}
|
||||
|
||||
// 可解决Long 类型在 前端精度丢失的问题, 如不想全局 直接添加注解 @JsonSerialize(using= ToStringSerializer.class) 到相应的字段
|
||||
|
||||
// @Override
|
||||
// public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
|
||||
//
|
||||
// MappingJackson2HttpMessageConverter jackson2HttpMessageConverter =
|
||||
// new MappingJackson2HttpMessageConverter();
|
||||
//
|
||||
// ObjectMapper objectMapper = new ObjectMapper();
|
||||
// SimpleModule simpleModule = new SimpleModule();
|
||||
// simpleModule.addSerializer(BigInteger.class, ToStringSerializer.instance);
|
||||
// simpleModule.addSerializer(Long.class, ToStringSerializer.instance);
|
||||
// simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance);
|
||||
// objectMapper.registerModule(simpleModule);
|
||||
// jackson2HttpMessageConverter.setObjectMapper(objectMapper);
|
||||
// converters.add(jackson2HttpMessageConverter);
|
||||
// converters.add(new StringHttpMessageConverter(Charset.forName("UTF-8")));
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
String avatarUtl = "file:" + avatar.replace("\\","/");
|
||||
String pathUtl = "file:" + path.replace("\\","/");
|
||||
registry.addResourceHandler("/avatar/**").addResourceLocations(avatarUtl).setCachePeriod(0);
|
||||
registry.addResourceHandler("/file/**").addResourceLocations(pathUtl).setCachePeriod(0);
|
||||
registry.addResourceHandler("/**").addResourceLocations("classpath:/META-INF/resources/").setCachePeriod(0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ public interface QuartzJobService {
|
|||
* @param pageable
|
||||
* @return
|
||||
*/
|
||||
@Cacheable(keyGenerator = "keyGenerator")
|
||||
@Cacheable
|
||||
Object queryAll(JobQueryCriteria criteria, Pageable pageable);
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package me.zhengjie.modules.quartz.task;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.zhengjie.exception.BadRequestException;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
|
|
|
@ -25,6 +25,7 @@ public class ExecutionJob extends QuartzJobBean {
|
|||
|
||||
private Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
// 建议自定义线程池实现方式,该处仅供参考
|
||||
private ExecutorService executorService = Executors.newSingleThreadExecutor();
|
||||
|
||||
@Override
|
||||
|
@ -61,8 +62,7 @@ public class ExecutionJob extends QuartzJobBean {
|
|||
// 任务状态 0:成功 1:失败
|
||||
log.setIsSuccess(false);
|
||||
log.setExceptionDetail(ThrowableUtil.getStackTrace(e));
|
||||
//出错就暂停任务
|
||||
quartzManage.pauseJob(quartzJob);
|
||||
quartzJob.setIsPause(false);
|
||||
//更新状态
|
||||
quartzJobService.updateIsPause(quartzJob);
|
||||
} finally {
|
||||
|
|
|
@ -1,17 +1,19 @@
|
|||
package me.zhengjie.modules.quartz.utils;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.zhengjie.exception.BadRequestException;
|
||||
import me.zhengjie.utils.SpringContextHolder;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
* 执行定时任务
|
||||
* @author
|
||||
*/
|
||||
@Slf4j
|
||||
public class QuartzRunnable implements Runnable {
|
||||
public class QuartzRunnable implements Callable {
|
||||
|
||||
private Object target;
|
||||
private Method method;
|
||||
|
@ -30,17 +32,13 @@ public class QuartzRunnable implements Runnable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
ReflectionUtils.makeAccessible(method);
|
||||
if (StringUtils.isNotBlank(params)) {
|
||||
method.invoke(target, params);
|
||||
} else {
|
||||
method.invoke(target);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("定时任务执行失败",e);
|
||||
public Object call() throws Exception {
|
||||
ReflectionUtils.makeAccessible(method);
|
||||
if (StringUtils.isNotBlank(params)) {
|
||||
method.invoke(target, params);
|
||||
} else {
|
||||
method.invoke(target);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -106,6 +106,11 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
|||
|
||||
// 接口限流测试
|
||||
.antMatchers("/test/**").anonymous()
|
||||
// 文件
|
||||
.antMatchers("/avatar/**").anonymous()
|
||||
.antMatchers("/file/**").anonymous()
|
||||
|
||||
// 放行OPTIONS请求
|
||||
.antMatchers(HttpMethod.OPTIONS, "/**").anonymous()
|
||||
|
||||
.antMatchers("/druid/**").anonymous()
|
||||
|
|
|
@ -34,13 +34,23 @@ public class Menu implements Serializable {
|
|||
@NotNull
|
||||
private Long sort;
|
||||
|
||||
@NotBlank
|
||||
@Column(name = "path")
|
||||
private String path;
|
||||
|
||||
private String component;
|
||||
|
||||
@Column(unique = true)
|
||||
private String componentName;
|
||||
|
||||
private String icon;
|
||||
|
||||
@Column(columnDefinition = "bit(1) default 0")
|
||||
private Boolean cache;
|
||||
|
||||
@Column(columnDefinition = "bit(1) default 0")
|
||||
private Boolean hidden;
|
||||
|
||||
/**
|
||||
* 上级菜单ID
|
||||
*/
|
||||
|
|
|
@ -31,7 +31,9 @@ public class User implements Serializable {
|
|||
@Column(unique = true)
|
||||
private String username;
|
||||
|
||||
private String avatar;
|
||||
@OneToOne
|
||||
@JoinColumn(name = "avatar_id")
|
||||
private UserAvatar userAvatar;
|
||||
|
||||
@NotBlank
|
||||
@Pattern(regexp = "([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}",message = "格式错误")
|
||||
|
@ -69,7 +71,6 @@ public class User implements Serializable {
|
|||
return "User{" +
|
||||
"id=" + id +
|
||||
", username='" + username + '\'' +
|
||||
", avatar='" + avatar + '\'' +
|
||||
", email='" + email + '\'' +
|
||||
", enabled=" + enabled +
|
||||
", password='" + password + '\'' +
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
package me.zhengjie.modules.system.domain;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.sql.Timestamp;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2019年9月7日 16:16:59
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "user_avatar")
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class UserAvatar {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
private String realName;
|
||||
|
||||
private String path;
|
||||
|
||||
private String size;
|
||||
|
||||
public UserAvatar(UserAvatar userAvatar,String realName, String path, String size) {
|
||||
this.id = ObjectUtil.isNotEmpty(userAvatar) ? userAvatar.getId() : null;
|
||||
this.realName = realName;
|
||||
this.path = path;
|
||||
this.size = size;
|
||||
}
|
||||
}
|
|
@ -15,4 +15,6 @@ public class MenuMetaVo implements Serializable {
|
|||
private String title;
|
||||
|
||||
private String icon;
|
||||
|
||||
private Boolean noCache;
|
||||
}
|
||||
|
|
|
@ -19,6 +19,8 @@ public class MenuVo implements Serializable {
|
|||
|
||||
private String path;
|
||||
|
||||
private Boolean hidden;
|
||||
|
||||
private String redirect;
|
||||
|
||||
private String component;
|
||||
|
|
|
@ -23,6 +23,13 @@ public interface MenuRepository extends JpaRepository<Menu, Long>, JpaSpecificat
|
|||
*/
|
||||
Menu findByName(String name);
|
||||
|
||||
/**
|
||||
* findByName
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
Menu findByComponentName(String name);
|
||||
|
||||
/**
|
||||
* findByPid
|
||||
* @param pid
|
||||
|
|
|
@ -1,13 +1,9 @@
|
|||
package me.zhengjie.modules.system.repository;
|
||||
|
||||
import me.zhengjie.modules.system.domain.Permission;
|
||||
import me.zhengjie.modules.system.domain.Role;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
|
|
|
@ -3,6 +3,8 @@ package me.zhengjie.modules.system.repository;
|
|||
import me.zhengjie.modules.system.domain.Role;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -21,5 +23,11 @@ public interface RoleRepository extends JpaRepository<Role, Long>, JpaSpecificat
|
|||
|
||||
Set<Role> findByUsers_Id(Long id);
|
||||
|
||||
Set<Role> findByMenus_Id(Long id);
|
||||
@Modifying
|
||||
@Query(value = "delete from roles_permissions where permission_id = ?1",nativeQuery = true)
|
||||
void untiedPermission(Long id);
|
||||
|
||||
@Modifying
|
||||
@Query(value = "delete from roles_menus where menu_id = ?1",nativeQuery = true)
|
||||
void untiedMenu(Long id);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
package me.zhengjie.modules.system.repository;
|
||||
|
||||
import me.zhengjie.modules.system.domain.UserAvatar;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2018-11-22
|
||||
*/
|
||||
public interface UserAvatarRepository extends JpaRepository<UserAvatar, Long>, JpaSpecificationExecutor {
|
||||
|
||||
}
|
|
@ -7,6 +7,7 @@ import me.zhengjie.modules.system.domain.Dept;
|
|||
import me.zhengjie.modules.system.service.DeptService;
|
||||
import me.zhengjie.modules.system.service.dto.DeptDTO;
|
||||
import me.zhengjie.modules.system.service.dto.DeptQueryCriteria;
|
||||
import me.zhengjie.utils.ThrowableUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
@ -63,7 +64,11 @@ public class DeptController {
|
|||
@DeleteMapping(value = "/dept/{id}")
|
||||
@PreAuthorize("hasAnyRole('ADMIN','DEPT_ALL','DEPT_DELETE')")
|
||||
public ResponseEntity delete(@PathVariable Long id){
|
||||
deptService.delete(id);
|
||||
try {
|
||||
deptService.delete(id);
|
||||
}catch (Throwable e){
|
||||
ThrowableUtil.throwForeignKeyException(e, "该部门存在岗位或者角色关联,请取消关联后再试");
|
||||
}
|
||||
return new ResponseEntity(HttpStatus.OK);
|
||||
}
|
||||
}
|
|
@ -4,7 +4,6 @@ import me.zhengjie.aop.log.Log;
|
|||
import me.zhengjie.exception.BadRequestException;
|
||||
import me.zhengjie.modules.system.domain.Dict;
|
||||
import me.zhengjie.modules.system.service.DictService;
|
||||
import me.zhengjie.modules.system.service.dto.DictDTO;
|
||||
import me.zhengjie.modules.system.service.dto.DictQueryCriteria;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
|
|
@ -6,6 +6,7 @@ import me.zhengjie.exception.BadRequestException;
|
|||
import me.zhengjie.modules.system.domain.Job;
|
||||
import me.zhengjie.modules.system.service.JobService;
|
||||
import me.zhengjie.modules.system.service.dto.JobQueryCriteria;
|
||||
import me.zhengjie.utils.ThrowableUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
@ -64,7 +65,11 @@ public class JobController {
|
|||
@DeleteMapping(value = "/job/{id}")
|
||||
@PreAuthorize("hasAnyRole('ADMIN','USERJOB_ALL','USERJOB_DELETE')")
|
||||
public ResponseEntity delete(@PathVariable Long id){
|
||||
jobService.delete(id);
|
||||
try {
|
||||
jobService.delete(id);
|
||||
}catch (Throwable e){
|
||||
ThrowableUtil.throwForeignKeyException(e, "该岗位存在用户关联,请取消关联后再试");
|
||||
}
|
||||
return new ResponseEntity(HttpStatus.OK);
|
||||
}
|
||||
}
|
|
@ -16,7 +16,9 @@ import org.springframework.http.ResponseEntity;
|
|||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
|
@ -90,14 +92,10 @@ public class MenuController {
|
|||
@PreAuthorize("hasAnyRole('ADMIN','MENU_ALL','MENU_DELETE')")
|
||||
public ResponseEntity delete(@PathVariable Long id){
|
||||
List<Menu> menuList = menuService.findByPid(id);
|
||||
|
||||
// 特殊情况,对级联删除进行处理
|
||||
for (Menu menu : menuList) {
|
||||
roleService.untiedMenu(menu);
|
||||
menuService.delete(menu.getId());
|
||||
}
|
||||
roleService.untiedMenu(menuService.findOne(id));
|
||||
menuService.delete(id);
|
||||
Set<Menu> menuSet = new HashSet<>();
|
||||
menuSet.add(menuService.findOne(id));
|
||||
menuSet = menuService.getDeleteMenus(menuList, menuSet);
|
||||
menuService.delete(menuSet);
|
||||
return new ResponseEntity(HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import me.zhengjie.exception.BadRequestException;
|
|||
import me.zhengjie.modules.system.service.PermissionService;
|
||||
import me.zhengjie.modules.system.service.dto.PermissionDTO;
|
||||
import me.zhengjie.modules.system.service.dto.PermissionQueryCriteria;
|
||||
import me.zhengjie.modules.system.service.mapper.PermissionMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
@ -13,7 +14,9 @@ import org.springframework.security.access.prepost.PreAuthorize;
|
|||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
|
@ -26,6 +29,9 @@ public class PermissionController {
|
|||
@Autowired
|
||||
private PermissionService permissionService;
|
||||
|
||||
@Autowired
|
||||
private PermissionMapper permissionMapper;
|
||||
|
||||
private static final String ENTITY_NAME = "permission";
|
||||
|
||||
/**
|
||||
|
@ -68,7 +74,11 @@ public class PermissionController {
|
|||
@DeleteMapping(value = "/permissions/{id}")
|
||||
@PreAuthorize("hasAnyRole('ADMIN','PERMISSION_ALL','PERMISSION_DELETE')")
|
||||
public ResponseEntity delete(@PathVariable Long id){
|
||||
permissionService.delete(id);
|
||||
List<Permission> permissions = permissionService.findByPid(id);
|
||||
Set<Permission> permissionSet = new HashSet<>();
|
||||
permissionSet.add(permissionMapper.toEntity(permissionService.findById(id)));
|
||||
permissionSet = permissionService.getDeletePermission(permissions, permissionSet);
|
||||
permissionService.delete(permissionSet);
|
||||
return new ResponseEntity(HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,10 +5,11 @@ import me.zhengjie.aop.log.Log;
|
|||
import me.zhengjie.modules.system.domain.Role;
|
||||
import me.zhengjie.exception.BadRequestException;
|
||||
import me.zhengjie.modules.system.service.RoleService;
|
||||
import me.zhengjie.modules.system.service.dto.MenuQueryCriteria;
|
||||
import me.zhengjie.modules.system.service.dto.RoleQueryCriteria;
|
||||
import me.zhengjie.modules.system.service.dto.RoleSmallDTO;
|
||||
import me.zhengjie.utils.SecurityUtils;
|
||||
import me.zhengjie.utils.ThrowableUtil;
|
||||
import org.hibernate.exception.ConstraintViolationException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
|
@ -16,6 +17,7 @@ import org.springframework.data.web.PageableDefault;
|
|||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.transaction.TransactionSystemException;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import java.util.Collections;
|
||||
|
@ -107,7 +109,11 @@ public class RoleController {
|
|||
@DeleteMapping(value = "/roles/{id}")
|
||||
@PreAuthorize("hasAnyRole('ADMIN','ROLES_ALL','ROLES_DELETE')")
|
||||
public ResponseEntity delete(@PathVariable Long id){
|
||||
roleService.delete(id);
|
||||
try {
|
||||
roleService.delete(id);
|
||||
}catch (Throwable e){
|
||||
ThrowableUtil.throwForeignKeyException(e, "该角色存在用户关联,请取消关联后再试");
|
||||
}
|
||||
return new ResponseEntity(HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,6 +26,8 @@ import org.springframework.util.ObjectUtils;
|
|||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
@ -55,6 +57,13 @@ public class UserController {
|
|||
@Autowired
|
||||
private VerificationCodeService verificationCodeService;
|
||||
|
||||
@Log("导出用户数据")
|
||||
@GetMapping(value = "/users/download")
|
||||
@PreAuthorize("hasAnyRole('ADMIN','USER_ALL','USER_SELECT')")
|
||||
public void update(HttpServletResponse response, UserQueryCriteria criteria) throws IOException {
|
||||
userService.download(userService.queryAll(criteria), response);
|
||||
}
|
||||
|
||||
@Log("查询用户")
|
||||
@GetMapping(value = "/users")
|
||||
@PreAuthorize("hasAnyRole('ADMIN','USER_ALL','USER_SELECT')")
|
||||
|
@ -147,8 +156,7 @@ public class UserController {
|
|||
*/
|
||||
@PostMapping(value = "/users/updateAvatar")
|
||||
public ResponseEntity updateAvatar(@RequestParam MultipartFile file){
|
||||
Picture picture = pictureService.upload(file, SecurityUtils.getUsername());
|
||||
userService.updateAvatar(SecurityUtils.getUsername(),picture.getUrl());
|
||||
userService.updateAvatar(file);
|
||||
return new ResponseEntity(HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ public interface DeptService {
|
|||
* @param criteria
|
||||
* @return
|
||||
*/
|
||||
@Cacheable(keyGenerator = "keyGenerator")
|
||||
@Cacheable
|
||||
List<DeptDTO> queryAll(DeptQueryCriteria criteria);
|
||||
|
||||
/**
|
||||
|
@ -60,7 +60,7 @@ public interface DeptService {
|
|||
* @param deptDTOS
|
||||
* @return
|
||||
*/
|
||||
@Cacheable(keyGenerator = "keyGenerator")
|
||||
@Cacheable
|
||||
Object buildTree(List<DeptDTO> deptDTOS);
|
||||
|
||||
/**
|
||||
|
@ -68,7 +68,7 @@ public interface DeptService {
|
|||
* @param pid
|
||||
* @return
|
||||
*/
|
||||
@Cacheable(keyGenerator = "keyGenerator")
|
||||
@Cacheable
|
||||
List<Dept> findByPid(long pid);
|
||||
|
||||
Set<Dept> findByRoleIds(Long id);
|
||||
|
|
|
@ -47,6 +47,6 @@ public interface DictDetailService {
|
|||
@CacheEvict(allEntries = true)
|
||||
void delete(Long id);
|
||||
|
||||
@Cacheable(keyGenerator = "keyGenerator")
|
||||
@Cacheable
|
||||
Map queryAll(DictDetailQueryCriteria criteria, Pageable pageable);
|
||||
}
|
|
@ -21,7 +21,7 @@ public interface DictService {
|
|||
* @param pageable
|
||||
* @return
|
||||
*/
|
||||
@Cacheable(keyGenerator = "keyGenerator")
|
||||
@Cacheable
|
||||
Object queryAll(DictQueryCriteria dict, Pageable pageable);
|
||||
|
||||
/**
|
||||
|
|
|
@ -9,6 +9,7 @@ import org.springframework.cache.annotation.CacheEvict;
|
|||
import org.springframework.cache.annotation.Cacheable;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
|
@ -22,7 +23,7 @@ public interface MenuService {
|
|||
* @param criteria
|
||||
* @return
|
||||
*/
|
||||
@Cacheable(keyGenerator = "keyGenerator")
|
||||
@Cacheable
|
||||
List<MenuDTO> queryAll(MenuQueryCriteria criteria);
|
||||
|
||||
/**
|
||||
|
@ -49,11 +50,12 @@ public interface MenuService {
|
|||
void update(Menu resources);
|
||||
|
||||
/**
|
||||
* delete
|
||||
* @param id
|
||||
* getDeleteMenus
|
||||
* @param menuList
|
||||
* @param menuSet
|
||||
* @return
|
||||
*/
|
||||
@CacheEvict(allEntries = true)
|
||||
void delete(Long id);
|
||||
Set<Menu> getDeleteMenus(List<Menu> menuList, Set<Menu> menuSet);
|
||||
|
||||
/**
|
||||
* permission tree
|
||||
|
@ -92,4 +94,11 @@ public interface MenuService {
|
|||
Object buildMenus(List<MenuDTO> byRoles);
|
||||
|
||||
Menu findOne(Long id);
|
||||
|
||||
/**
|
||||
* delete
|
||||
* @param menuSet
|
||||
*/
|
||||
@CacheEvict(allEntries = true)
|
||||
void delete(Set<Menu> menuSet);
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import org.springframework.cache.annotation.CacheEvict;
|
|||
import org.springframework.cache.annotation.Cacheable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
|
@ -41,10 +42,10 @@ public interface PermissionService {
|
|||
|
||||
/**
|
||||
* delete
|
||||
* @param id
|
||||
* @param permissions
|
||||
*/
|
||||
@CacheEvict(allEntries = true)
|
||||
void delete(Long id);
|
||||
void delete(Set<Permission> permissions);
|
||||
|
||||
/**
|
||||
* permission tree
|
||||
|
@ -66,7 +67,7 @@ public interface PermissionService {
|
|||
* @param permissionDTOS
|
||||
* @return
|
||||
*/
|
||||
@Cacheable(keyGenerator = "keyGenerator")
|
||||
@Cacheable
|
||||
Object buildTree(List<PermissionDTO> permissionDTOS);
|
||||
|
||||
/**
|
||||
|
@ -74,6 +75,8 @@ public interface PermissionService {
|
|||
* @param criteria
|
||||
* @return
|
||||
*/
|
||||
@Cacheable(keyGenerator = "keyGenerator")
|
||||
@Cacheable
|
||||
List<PermissionDTO> queryAll(PermissionQueryCriteria criteria);
|
||||
|
||||
Set<Permission> getDeletePermission(List<Permission> permissions, Set<Permission> permissionSet);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package me.zhengjie.modules.system.service;
|
||||
|
||||
import me.zhengjie.modules.system.domain.Menu;
|
||||
import me.zhengjie.modules.system.domain.Role;
|
||||
import me.zhengjie.modules.system.service.dto.RoleDTO;
|
||||
import me.zhengjie.modules.system.service.dto.RoleQueryCriteria;
|
||||
|
@ -59,7 +58,7 @@ public interface RoleService {
|
|||
@Cacheable(key = "'findByUsers_Id:' + #p0")
|
||||
List<RoleSmallDTO> findByUsers_Id(Long id);
|
||||
|
||||
@Cacheable(keyGenerator = "keyGenerator")
|
||||
@Cacheable
|
||||
Integer findByRoles(Set<Role> roles);
|
||||
|
||||
/**
|
||||
|
@ -79,13 +78,14 @@ public interface RoleService {
|
|||
void updateMenu(Role resources, RoleDTO roleDTO);
|
||||
|
||||
@CacheEvict(allEntries = true)
|
||||
void untiedMenu(Menu menu);
|
||||
void untiedMenu(Long id);
|
||||
|
||||
/**
|
||||
* queryAll
|
||||
* @param pageable
|
||||
* @return
|
||||
*/
|
||||
@Cacheable
|
||||
Object queryAll(Pageable pageable);
|
||||
|
||||
/**
|
||||
|
@ -94,5 +94,17 @@ public interface RoleService {
|
|||
* @param criteria
|
||||
* @return
|
||||
*/
|
||||
@Cacheable
|
||||
Object queryAll(RoleQueryCriteria criteria, Pageable pageable);
|
||||
|
||||
/**
|
||||
* queryAll
|
||||
* @param criteria
|
||||
* @return
|
||||
*/
|
||||
@Cacheable
|
||||
List<RoleDTO> queryAll(RoleQueryCriteria criteria);
|
||||
|
||||
@CacheEvict(allEntries = true)
|
||||
void untiedPermission(Long id);
|
||||
}
|
||||
|
|
|
@ -8,6 +8,11 @@ import org.springframework.cache.annotation.CacheConfig;
|
|||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
|
@ -64,11 +69,10 @@ public interface UserService {
|
|||
|
||||
/**
|
||||
* 修改头像
|
||||
* @param username
|
||||
* @param url
|
||||
* @param file
|
||||
*/
|
||||
@CacheEvict(allEntries = true)
|
||||
void updateAvatar(String username, String url);
|
||||
void updateAvatar(MultipartFile file);
|
||||
|
||||
/**
|
||||
* 修改邮箱
|
||||
|
@ -78,6 +82,11 @@ public interface UserService {
|
|||
@CacheEvict(allEntries = true)
|
||||
void updateEmail(String username, String email);
|
||||
|
||||
@Cacheable(keyGenerator = "keyGenerator")
|
||||
@Cacheable
|
||||
Object queryAll(UserQueryCriteria criteria, Pageable pageable);
|
||||
|
||||
@Cacheable
|
||||
List<UserDTO> queryAll(UserQueryCriteria criteria);
|
||||
|
||||
void download(List<UserDTO> queryAll, HttpServletResponse response) throws IOException;
|
||||
}
|
||||
|
|
|
@ -27,6 +27,12 @@ public class MenuDTO {
|
|||
|
||||
private Boolean iFrame;
|
||||
|
||||
private Boolean cache;
|
||||
|
||||
private Boolean hidden;
|
||||
|
||||
private String componentName;
|
||||
|
||||
private String icon;
|
||||
|
||||
private List<MenuDTO> children;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package me.zhengjie.modules.system.service.impl;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import me.zhengjie.modules.system.domain.Menu;
|
||||
import me.zhengjie.modules.system.domain.vo.MenuMetaVo;
|
||||
|
@ -8,11 +10,13 @@ import me.zhengjie.exception.BadRequestException;
|
|||
import me.zhengjie.exception.EntityExistException;
|
||||
import me.zhengjie.modules.system.repository.MenuRepository;
|
||||
import me.zhengjie.modules.system.service.MenuService;
|
||||
import me.zhengjie.modules.system.service.RoleService;
|
||||
import me.zhengjie.modules.system.service.dto.MenuDTO;
|
||||
import me.zhengjie.modules.system.service.dto.MenuQueryCriteria;
|
||||
import me.zhengjie.modules.system.service.dto.RoleSmallDTO;
|
||||
import me.zhengjie.modules.system.service.mapper.MenuMapper;
|
||||
import me.zhengjie.utils.QueryHelp;
|
||||
import me.zhengjie.utils.StringUtils;
|
||||
import me.zhengjie.utils.ValidationUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -31,6 +35,9 @@ public class MenuServiceImpl implements MenuService {
|
|||
@Autowired
|
||||
private MenuMapper menuMapper;
|
||||
|
||||
@Autowired
|
||||
private RoleService roleService;
|
||||
|
||||
@Override
|
||||
public List queryAll(MenuQueryCriteria criteria){
|
||||
return menuMapper.toDto(menuRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
|
||||
|
@ -58,6 +65,11 @@ public class MenuServiceImpl implements MenuService {
|
|||
if(menuRepository.findByName(resources.getName()) != null){
|
||||
throw new EntityExistException(Menu.class,"name",resources.getName());
|
||||
}
|
||||
if(StringUtils.isNotBlank(resources.getComponentName())){
|
||||
if(menuRepository.findByComponentName(resources.getComponentName()) != null){
|
||||
throw new EntityExistException(Menu.class,"componentName",resources.getComponentName());
|
||||
}
|
||||
}
|
||||
if(resources.getIFrame()){
|
||||
if (!(resources.getPath().toLowerCase().startsWith("http://")||resources.getPath().toLowerCase().startsWith("https://"))) {
|
||||
throw new BadRequestException("外链必须以http://或者https://开头");
|
||||
|
@ -85,6 +97,13 @@ public class MenuServiceImpl implements MenuService {
|
|||
if(menu1 != null && !menu1.getId().equals(menu.getId())){
|
||||
throw new EntityExistException(Menu.class,"name",resources.getName());
|
||||
}
|
||||
|
||||
if(StringUtils.isNotBlank(resources.getComponentName())){
|
||||
menu1 = menuRepository.findByComponentName(resources.getComponentName());
|
||||
if(menu1 != null && !menu1.getId().equals(menu.getId())){
|
||||
throw new EntityExistException(Menu.class,"componentName",resources.getComponentName());
|
||||
}
|
||||
}
|
||||
menu.setName(resources.getName());
|
||||
menu.setComponent(resources.getComponent());
|
||||
menu.setPath(resources.getPath());
|
||||
|
@ -92,12 +111,32 @@ public class MenuServiceImpl implements MenuService {
|
|||
menu.setIFrame(resources.getIFrame());
|
||||
menu.setPid(resources.getPid());
|
||||
menu.setSort(resources.getSort());
|
||||
menu.setCache(resources.getCache());
|
||||
menu.setHidden(resources.getHidden());
|
||||
menu.setComponentName(resources.getComponentName());
|
||||
menuRepository.save(menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Long id) {
|
||||
menuRepository.deleteById(id);
|
||||
public Set<Menu> getDeleteMenus(List<Menu> menuList, Set<Menu> menuSet) {
|
||||
// 递归找出待删除的菜单
|
||||
for (Menu menu1 : menuList) {
|
||||
menuSet.add(menu1);
|
||||
List<Menu> menus = menuRepository.findByPid(menu1.getId());
|
||||
if(menus!=null && menus.size()!=0){
|
||||
getDeleteMenus(menus, menuSet);
|
||||
}
|
||||
}
|
||||
return menuSet;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void delete(Set<Menu> menuSet) {
|
||||
for (Menu menu : menuSet) {
|
||||
roleService.untiedMenu(menu.getId());
|
||||
menuRepository.deleteById(menu.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -127,24 +166,26 @@ public class MenuServiceImpl implements MenuService {
|
|||
@Override
|
||||
public Map buildTree(List<MenuDTO> menuDTOS) {
|
||||
List<MenuDTO> trees = new ArrayList<MenuDTO>();
|
||||
|
||||
Set<Long> ids = new HashSet<>();
|
||||
for (MenuDTO menuDTO : menuDTOS) {
|
||||
|
||||
if ("0".equals(menuDTO.getPid().toString())) {
|
||||
if (menuDTO.getPid() == 0) {
|
||||
trees.add(menuDTO);
|
||||
}
|
||||
|
||||
for (MenuDTO it : menuDTOS) {
|
||||
if (it.getPid().equals(menuDTO.getId())) {
|
||||
if (menuDTO.getChildren() == null) {
|
||||
menuDTO.setChildren(new ArrayList<MenuDTO>());
|
||||
}
|
||||
menuDTO.getChildren().add(it);
|
||||
ids.add(it.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
Map map = new HashMap();
|
||||
map.put("content",trees.size() == 0?menuDTOS:trees);
|
||||
if(trees.size() == 0){
|
||||
trees = menuDTOS.stream().filter(s -> !ids.contains(s.getId())).collect(Collectors.toList());
|
||||
}
|
||||
map.put("content",trees);
|
||||
map.put("totalElements",menuDTOS!=null?menuDTOS.size():0);
|
||||
return map;
|
||||
}
|
||||
|
@ -156,26 +197,25 @@ public class MenuServiceImpl implements MenuService {
|
|||
if (menuDTO!=null){
|
||||
List<MenuDTO> menuDTOList = menuDTO.getChildren();
|
||||
MenuVo menuVo = new MenuVo();
|
||||
menuVo.setName(menuDTO.getName());
|
||||
menuVo.setPath(menuDTO.getPath());
|
||||
|
||||
menuVo.setName(ObjectUtil.isNotEmpty(menuDTO.getComponentName()) ? menuDTO.getComponentName() : menuDTO.getName());
|
||||
// 一级目录需要加斜杠,不然会报警告
|
||||
menuVo.setPath(menuDTO.getPid() == 0 ? "/" + menuDTO.getPath() :menuDTO.getPath());
|
||||
menuVo.setHidden(menuDTO.getHidden());
|
||||
// 如果不是外链
|
||||
if(!menuDTO.getIFrame()){
|
||||
if(menuDTO.getPid().equals(0L)){
|
||||
//一级目录需要加斜杠,不然访问 会跳转404页面
|
||||
menuVo.setPath("/" + menuDTO.getPath());
|
||||
if(menuDTO.getPid() == 0){
|
||||
menuVo.setComponent(StrUtil.isEmpty(menuDTO.getComponent())?"Layout":menuDTO.getComponent());
|
||||
}else if(!StrUtil.isEmpty(menuDTO.getComponent())){
|
||||
menuVo.setComponent(menuDTO.getComponent());
|
||||
}
|
||||
}
|
||||
menuVo.setMeta(new MenuMetaVo(menuDTO.getName(),menuDTO.getIcon()));
|
||||
menuVo.setMeta(new MenuMetaVo(menuDTO.getName(),menuDTO.getIcon(),!menuDTO.getCache()));
|
||||
if(menuDTOList!=null && menuDTOList.size()!=0){
|
||||
menuVo.setAlwaysShow(true);
|
||||
menuVo.setRedirect("noredirect");
|
||||
menuVo.setChildren(buildMenus(menuDTOList));
|
||||
// 处理是一级菜单并且没有子菜单的情况
|
||||
} else if(menuDTO.getPid().equals(0L)){
|
||||
} else if(menuDTO.getPid() == 0){
|
||||
MenuVo menuVo1 = new MenuVo();
|
||||
menuVo1.setMeta(menuVo.getMeta());
|
||||
// 非外链
|
||||
|
|
|
@ -5,6 +5,7 @@ import me.zhengjie.exception.BadRequestException;
|
|||
import me.zhengjie.exception.EntityExistException;
|
||||
import me.zhengjie.modules.system.repository.PermissionRepository;
|
||||
import me.zhengjie.modules.system.service.PermissionService;
|
||||
import me.zhengjie.modules.system.service.RoleService;
|
||||
import me.zhengjie.modules.system.service.dto.PermissionDTO;
|
||||
import me.zhengjie.modules.system.service.dto.PermissionQueryCriteria;
|
||||
import me.zhengjie.modules.system.service.mapper.PermissionMapper;
|
||||
|
@ -30,6 +31,9 @@ public class PermissionServiceImpl implements PermissionService {
|
|||
@Autowired
|
||||
private PermissionMapper permissionMapper;
|
||||
|
||||
@Autowired
|
||||
private RoleService roleService;
|
||||
|
||||
@Override
|
||||
public List<PermissionDTO> queryAll(PermissionQueryCriteria criteria) {
|
||||
return permissionMapper.toDto(permissionRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
|
||||
|
@ -74,14 +78,26 @@ public class PermissionServiceImpl implements PermissionService {
|
|||
permissionRepository.save(permission);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Permission> getDeletePermission(List<Permission> permissions, Set<Permission> permissionSet) {
|
||||
// 递归找出待删除的菜单
|
||||
for (Permission permission : permissions) {
|
||||
permissionSet.add(permission);
|
||||
List<Permission> permissionList = permissionRepository.findByPid(permission.getId());
|
||||
if(permissionList!=null && permissionList.size()!=0){
|
||||
getDeletePermission(permissionList, permissionSet);
|
||||
}
|
||||
}
|
||||
return permissionSet;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void delete(Long id) {
|
||||
List<Permission> permissionList = permissionRepository.findByPid(id);
|
||||
for (Permission permission : permissionList) {
|
||||
public void delete(Set<Permission> permissions) {
|
||||
for (Permission permission : permissions) {
|
||||
roleService.untiedPermission(permission.getId());
|
||||
permissionRepository.delete(permission);
|
||||
}
|
||||
permissionRepository.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package me.zhengjie.modules.system.service.impl;
|
||||
|
||||
import me.zhengjie.modules.system.domain.Menu;
|
||||
import me.zhengjie.modules.system.domain.Role;
|
||||
import me.zhengjie.exception.EntityExistException;
|
||||
import me.zhengjie.modules.system.repository.RoleRepository;
|
||||
|
@ -44,6 +43,11 @@ public class RoleServiceImpl implements RoleService {
|
|||
return roleMapper.toDto(roleRepository.findAll(pageable).getContent());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<RoleDTO> queryAll(RoleQueryCriteria criteria) {
|
||||
return roleMapper.toDto(roleRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object queryAll(RoleQueryCriteria criteria, Pageable pageable) {
|
||||
Page<Role> page = roleRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
|
||||
|
@ -104,13 +108,15 @@ public class RoleServiceImpl implements RoleService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void untiedMenu(Menu menu) {
|
||||
Set<Role> roles = roleRepository.findByMenus_Id(menu.getId());
|
||||
for (Role role : roles) {
|
||||
menu.getRoles().remove(role);
|
||||
role.getMenus().remove(menu);
|
||||
roleRepository.save(role);
|
||||
}
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void untiedMenu(Long id) {
|
||||
roleRepository.untiedMenu(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void untiedPermission(Long id) {
|
||||
roleRepository.untiedPermission(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,25 +1,36 @@
|
|||
package me.zhengjie.modules.system.service.impl;
|
||||
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.poi.excel.ExcelUtil;
|
||||
import cn.hutool.poi.excel.ExcelWriter;
|
||||
import me.zhengjie.modules.monitor.service.RedisService;
|
||||
import me.zhengjie.modules.system.domain.User;
|
||||
import me.zhengjie.exception.EntityExistException;
|
||||
import me.zhengjie.exception.EntityNotFoundException;
|
||||
import me.zhengjie.modules.system.domain.UserAvatar;
|
||||
import me.zhengjie.modules.system.repository.UserAvatarRepository;
|
||||
import me.zhengjie.modules.system.repository.UserRepository;
|
||||
import me.zhengjie.modules.system.service.UserService;
|
||||
import me.zhengjie.modules.system.service.dto.RoleSmallDTO;
|
||||
import me.zhengjie.modules.system.service.dto.UserDTO;
|
||||
import me.zhengjie.modules.system.service.dto.UserQueryCriteria;
|
||||
import me.zhengjie.modules.system.service.mapper.UserMapper;
|
||||
import me.zhengjie.utils.PageUtil;
|
||||
import me.zhengjie.utils.QueryHelp;
|
||||
import me.zhengjie.utils.ValidationUtil;
|
||||
import me.zhengjie.utils.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import java.util.Date;
|
||||
import java.util.Optional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
|
@ -38,12 +49,24 @@ public class UserServiceImpl implements UserService {
|
|||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
@Autowired
|
||||
private UserAvatarRepository userAvatarRepository;
|
||||
|
||||
@Value("${file.avatar}")
|
||||
private String avatar;
|
||||
|
||||
@Override
|
||||
public Object queryAll(UserQueryCriteria criteria, Pageable pageable) {
|
||||
Page<User> page = userRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
|
||||
return PageUtil.toPage(page.map(userMapper::toDto));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserDTO> queryAll(UserQueryCriteria criteria) {
|
||||
List<User> users = userRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder));
|
||||
return userMapper.toDto(users);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserDTO findById(long id) {
|
||||
Optional<User> user = userRepository.findById(id);
|
||||
|
@ -65,7 +88,6 @@ public class UserServiceImpl implements UserService {
|
|||
|
||||
// 默认密码 123456,此密码是加密后的字符
|
||||
resources.setPassword("e10adc3949ba59abbe56e057f20f883e");
|
||||
resources.setAvatar("https://i.loli.net/2019/04/04/5ca5b971e1548.jpeg");
|
||||
return userMapper.toDto(userRepository.save(resources));
|
||||
}
|
||||
|
||||
|
@ -135,8 +157,20 @@ public class UserServiceImpl implements UserService {
|
|||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateAvatar(String username, String url) {
|
||||
userRepository.updateAvatar(username,url);
|
||||
public void updateAvatar(MultipartFile multipartFile) {
|
||||
User user = userRepository.findByUsername(SecurityUtils.getUsername());
|
||||
UserAvatar userAvatar = user.getUserAvatar();
|
||||
String oldPath = "";
|
||||
if(userAvatar != null){
|
||||
oldPath = userAvatar.getPath();
|
||||
}
|
||||
File file = FileUtil.upload(multipartFile, avatar);
|
||||
userAvatar = userAvatarRepository.save(new UserAvatar(userAvatar,file.getName(), file.getPath(), FileUtil.getSize(multipartFile.getSize())));
|
||||
user.setUserAvatar(userAvatar);
|
||||
userRepository.save(user);
|
||||
if(StringUtils.isNotBlank(oldPath)){
|
||||
FileUtil.del(oldPath);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -144,4 +178,25 @@ public class UserServiceImpl implements UserService {
|
|||
public void updateEmail(String username, String email) {
|
||||
userRepository.updateEmail(username,email);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void download(List<UserDTO> queryAll, HttpServletResponse response) throws IOException {
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
for (UserDTO userDTO : queryAll) {
|
||||
List roles = userDTO.getRoles().stream().map(RoleSmallDTO::getName).collect(Collectors.toList());
|
||||
Map map = new LinkedHashMap();
|
||||
map.put("用户名", userDTO.getUsername());
|
||||
map.put("头像", userDTO.getAvatar());
|
||||
map.put("邮箱", userDTO.getEmail());
|
||||
map.put("状态", userDTO.getEnabled() ? "启用" : "禁用");
|
||||
map.put("手机号码", userDTO.getPhone());
|
||||
map.put("角色", roles);
|
||||
map.put("部门", userDTO.getDept().getName());
|
||||
map.put("岗位", userDTO.getJob().getName());
|
||||
map.put("最后修改密码的时间", userDTO.getLastPasswordResetTime());
|
||||
map.put("创建日期", userDTO.getCreateTime());
|
||||
list.add(map);
|
||||
}
|
||||
FileUtil.downloadExcel(list, response);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,8 +4,11 @@ import me.zhengjie.modules.system.domain.User;
|
|||
import me.zhengjie.mapper.EntityMapper;
|
||||
import me.zhengjie.modules.system.service.dto.UserDTO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2018-11-23
|
||||
|
@ -13,4 +16,6 @@ import org.mapstruct.ReportingPolicy;
|
|||
@Mapper(componentModel = "spring",uses = {RoleMapper.class, DeptMapper.class, JobMapper.class},unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||
public interface UserMapper extends EntityMapper<UserDTO, User> {
|
||||
|
||||
@Mapping(source = "user.userAvatar.realName",target = "avatar")
|
||||
UserDTO toDto(User user);
|
||||
}
|
||||
|
|
|
@ -45,8 +45,8 @@ spring:
|
|||
jwt:
|
||||
header: Authorization
|
||||
secret: mySecret
|
||||
# token 过期时间 2个小时
|
||||
expiration: 7200000
|
||||
# token 过期时间 6个小时
|
||||
expiration: 21000000
|
||||
auth:
|
||||
# 授权路径
|
||||
path: /login
|
||||
|
@ -59,4 +59,12 @@ generator:
|
|||
|
||||
#是否开启 swagger-ui
|
||||
swagger:
|
||||
enabled: true
|
||||
enabled: true
|
||||
|
||||
# 文件存储路径
|
||||
file:
|
||||
path: C:\eladmin\file\
|
||||
avatar: C:\eladmin\avatar\
|
||||
# 文件大小 /M
|
||||
maxSize: 100
|
||||
avatarMaxSize: 5
|
|
@ -68,4 +68,12 @@ generator:
|
|||
|
||||
#是否开启 swagger-ui
|
||||
swagger:
|
||||
enabled: false
|
||||
enabled: false
|
||||
|
||||
# 文件存储路径
|
||||
file:
|
||||
path: /home/eladmin/file/
|
||||
avatar: /home/eladmin/avatar/
|
||||
# 文件大小 /M
|
||||
maxSize: 100
|
||||
avatarMaxSize: 5
|
|
@ -1,4 +1,4 @@
|
|||
#数据库类型转换成java类型
|
||||
#数据库类型转Java类型
|
||||
tinyint=Integer
|
||||
smallint=Integer
|
||||
mediumint=Integer
|
||||
|
|
|
@ -24,7 +24,8 @@
|
|||
<appender-ref ref="console" />
|
||||
</logger>
|
||||
|
||||
<logger name="jdbc.resultsettable" level="INFO" additivity="false">
|
||||
<!-- 如想看到表格数据,将OFF改为INFO -->
|
||||
<logger name="jdbc.resultsettable" level="OFF" additivity="false">
|
||||
<appender-ref ref="console" />
|
||||
</logger>
|
||||
|
||||
|
|
|
@ -3,10 +3,12 @@ package ${package}.service;
|
|||
import ${package}.domain.${className};
|
||||
import ${package}.service.dto.${className}DTO;
|
||||
import ${package}.service.dto.${className}QueryCriteria;
|
||||
//import org.springframework.cache.annotation.CacheConfig;
|
||||
//import org.springframework.cache.annotation.CacheEvict;
|
||||
//import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author ${author}
|
||||
|
@ -16,24 +18,24 @@ import org.springframework.data.domain.Pageable;
|
|||
public interface ${className}Service {
|
||||
|
||||
/**
|
||||
* queryAll 分页
|
||||
* 查询数据分页
|
||||
* @param criteria
|
||||
* @param pageable
|
||||
* @return
|
||||
*/
|
||||
//@Cacheable(keyGenerator = "keyGenerator")
|
||||
Object queryAll(${className}QueryCriteria criteria, Pageable pageable);
|
||||
//@Cacheable
|
||||
Map<String,Object> queryAll(${className}QueryCriteria criteria, Pageable pageable);
|
||||
|
||||
/**
|
||||
* queryAll 不分页
|
||||
* 查询所有数据不分页
|
||||
* @param criteria
|
||||
* @return
|
||||
*/
|
||||
//@Cacheable(keyGenerator = "keyGenerator")
|
||||
public Object queryAll(${className}QueryCriteria criteria);
|
||||
//@Cacheable
|
||||
List<${className}DTO> queryAll(${className}QueryCriteria criteria);
|
||||
|
||||
/**
|
||||
* findById
|
||||
* 根据ID查询
|
||||
* @param ${pkChangeColName}
|
||||
* @return
|
||||
*/
|
||||
|
@ -41,7 +43,7 @@ public interface ${className}Service {
|
|||
${className}DTO findById(${pkColumnType} ${pkChangeColName});
|
||||
|
||||
/**
|
||||
* create
|
||||
* 创建
|
||||
* @param resources
|
||||
* @return
|
||||
*/
|
||||
|
@ -49,14 +51,14 @@ public interface ${className}Service {
|
|||
${className}DTO create(${className} resources);
|
||||
|
||||
/**
|
||||
* update
|
||||
* 编辑
|
||||
* @param resources
|
||||
*/
|
||||
//@CacheEvict(allEntries = true)
|
||||
void update(${className} resources);
|
||||
|
||||
/**
|
||||
* delete
|
||||
* 删除
|
||||
* @param ${pkChangeColName}
|
||||
*/
|
||||
//@CacheEvict(allEntries = true)
|
||||
|
|
|
@ -32,6 +32,8 @@ import org.springframework.data.domain.Page;
|
|||
import org.springframework.data.domain.Pageable;
|
||||
import me.zhengjie.utils.PageUtil;
|
||||
import me.zhengjie.utils.QueryHelp;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author ${author}
|
||||
|
@ -48,13 +50,13 @@ public class ${className}ServiceImpl implements ${className}Service {
|
|||
private ${className}Mapper ${changeClassName}Mapper;
|
||||
|
||||
@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);
|
||||
return PageUtil.toPage(page.map(${changeClassName}Mapper::toDto));
|
||||
}
|
||||
|
||||
@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)));
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<template>
|
||||
<el-dialog :append-to-body="true" :visible.sync="dialog" :title="isAdd ? '新增' : '编辑'" width="500px">
|
||||
<el-dialog :append-to-body="true" :close-on-click-modal="false" :before-close="cancel" :visible.sync="dialog" :title="isAdd ? '新增' : '编辑'" width="500px">
|
||||
<el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
|
||||
<#if columns??>
|
||||
<#list columns as column>
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>eladmin-tools</artifactId>
|
||||
<name>工具模块</name>
|
||||
|
||||
<properties>
|
||||
<mail.version>1.4.7</mail.version>
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
package me.zhengjie.domain;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.bean.copier.CopyOptions;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.hibernate.annotations.CreationTimestamp;
|
||||
import org.hibernate.annotations.UpdateTimestamp;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.sql.Timestamp;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2019-09-05
|
||||
*/
|
||||
@Entity
|
||||
@Data
|
||||
@Table(name="local_storage")
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class LocalStorage implements Serializable {
|
||||
|
||||
// ID
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id")
|
||||
private Long id;
|
||||
|
||||
// 真实文件名
|
||||
@Column(name = "real_name")
|
||||
private String realName;
|
||||
|
||||
// 文件名
|
||||
@Column(name = "name")
|
||||
private String name;
|
||||
|
||||
// 后缀
|
||||
@Column(name = "suffix")
|
||||
private String suffix;
|
||||
|
||||
// 路径
|
||||
@Column(name = "path")
|
||||
private String path;
|
||||
|
||||
// 类型
|
||||
@Column(name = "type")
|
||||
private String type;
|
||||
|
||||
// 大小
|
||||
@Column(name = "size")
|
||||
private String size;
|
||||
|
||||
// 操作人
|
||||
@Column(name = "operate")
|
||||
private String operate;
|
||||
|
||||
// 创建日期
|
||||
@Column(name = "create_time")
|
||||
@CreationTimestamp
|
||||
private Timestamp createTime;
|
||||
|
||||
// 修改日期
|
||||
@Column(name = "update_time")
|
||||
@UpdateTimestamp
|
||||
private Timestamp updateTime;
|
||||
|
||||
public LocalStorage(String realName,String name, String suffix, String path, String type, String size, String operate) {
|
||||
this.realName = realName;
|
||||
this.name = name;
|
||||
this.suffix = suffix;
|
||||
this.path = path;
|
||||
this.type = type;
|
||||
this.size = size;
|
||||
this.operate = operate;
|
||||
}
|
||||
|
||||
public void copy(LocalStorage source){
|
||||
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
|
||||
}
|
||||
}
|
|
@ -42,6 +42,8 @@ public class QiniuContent implements Serializable {
|
|||
*/
|
||||
private String url;
|
||||
|
||||
private String suffix;
|
||||
|
||||
/**
|
||||
* 空间类型:公开/私有
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
package me.zhengjie.repository;
|
||||
|
||||
import me.zhengjie.domain.LocalStorage;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2019-09-05
|
||||
*/
|
||||
public interface LocalStorageRepository extends JpaRepository<LocalStorage, Long>, JpaSpecificationExecutor {
|
||||
}
|
|
@ -2,10 +2,16 @@ package me.zhengjie.repository;
|
|||
|
||||
import me.zhengjie.domain.QiniuConfig;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2018-12-31
|
||||
*/
|
||||
public interface QiNiuConfigRepository extends JpaRepository<QiniuConfig,Long> {
|
||||
|
||||
@Modifying
|
||||
@Query(value = "update qiniu_content set type = ?1", nativeQuery = true)
|
||||
void update(String type);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
package me.zhengjie.rest;
|
||||
|
||||
import me.zhengjie.aop.log.Log;
|
||||
import me.zhengjie.domain.LocalStorage;
|
||||
import me.zhengjie.service.LocalStorageService;
|
||||
import me.zhengjie.service.dto.LocalStorageQueryCriteria;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import io.swagger.annotations.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2019-09-05
|
||||
*/
|
||||
@Api(tags = "本地存储管理")
|
||||
@RestController
|
||||
@RequestMapping("api")
|
||||
public class LocalStorageController {
|
||||
|
||||
@Autowired
|
||||
private LocalStorageService localStorageService;
|
||||
|
||||
@ApiOperation(value = "查询文件")
|
||||
@GetMapping(value = "/localStorage")
|
||||
@PreAuthorize("hasAnyRole('ADMIN','LOCALSTORAGE_ALL','LOCALSTORAGE_SELECT')")
|
||||
public ResponseEntity getLocalStorages(LocalStorageQueryCriteria criteria, Pageable pageable){
|
||||
return new ResponseEntity(localStorageService.queryAll(criteria,pageable),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "上传文件")
|
||||
@PostMapping(value = "/localStorage")
|
||||
@PreAuthorize("hasAnyRole('ADMIN','LOCALSTORAGE_ALL','LOCALSTORAGE_CREATE')")
|
||||
public ResponseEntity create(@RequestParam String name, @RequestParam("file") MultipartFile file){
|
||||
return new ResponseEntity(localStorageService.create(name, file),HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "修改文件")
|
||||
@PutMapping(value = "/localStorage")
|
||||
@PreAuthorize("hasAnyRole('ADMIN','LOCALSTORAGE_ALL','LOCALSTORAGE_EDIT')")
|
||||
public ResponseEntity update(@Validated @RequestBody LocalStorage resources){
|
||||
localStorageService.update(resources);
|
||||
return new ResponseEntity(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "删除文件")
|
||||
@DeleteMapping(value = "/localStorage/{id}")
|
||||
@PreAuthorize("hasAnyRole('ADMIN','LOCALSTORAGE_ALL','LOCALSTORAGE_DELETE')")
|
||||
public ResponseEntity delete(@PathVariable Long id){
|
||||
localStorageService.delete(id);
|
||||
return new ResponseEntity(HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除多张图片
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
@Log("删除图片")
|
||||
@DeleteMapping(value = "/localStorage")
|
||||
public ResponseEntity deleteAll(@RequestBody Long[] ids) {
|
||||
localStorageService.deleteAll(ids);
|
||||
return new ResponseEntity(HttpStatus.OK);
|
||||
}
|
||||
}
|
|
@ -45,7 +45,7 @@ public class PictureController {
|
|||
public ResponseEntity upload(@RequestParam MultipartFile file){
|
||||
String userName = SecurityUtils.getUsername();
|
||||
Picture picture = pictureService.upload(file,userName);
|
||||
Map map = new HashMap(3);
|
||||
Map<String,Object> map = new HashMap<>(3);
|
||||
map.put("errno",0);
|
||||
map.put("id",picture.getId());
|
||||
map.put("data",new String[]{picture.getUrl()});
|
||||
|
|
|
@ -38,6 +38,7 @@ public class QiniuController {
|
|||
@PutMapping(value = "/qiNiuConfig")
|
||||
public ResponseEntity emailConfig(@Validated @RequestBody QiniuConfig qiniuConfig){
|
||||
qiNiuService.update(qiniuConfig);
|
||||
qiNiuService.update(qiniuConfig.getType());
|
||||
return new ResponseEntity(HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
package me.zhengjie.service;
|
||||
|
||||
import me.zhengjie.domain.LocalStorage;
|
||||
import me.zhengjie.service.dto.LocalStorageDTO;
|
||||
import me.zhengjie.service.dto.LocalStorageQueryCriteria;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2019-09-05
|
||||
*/
|
||||
@CacheConfig(cacheNames = "localStorage")
|
||||
public interface LocalStorageService {
|
||||
|
||||
/**
|
||||
* queryAll 分页
|
||||
* @param criteria
|
||||
* @param pageable
|
||||
* @return
|
||||
*/
|
||||
@Cacheable
|
||||
Object queryAll(LocalStorageQueryCriteria criteria, Pageable pageable);
|
||||
|
||||
/**
|
||||
* queryAll 不分页
|
||||
* @param criteria
|
||||
* @return
|
||||
*/
|
||||
@Cacheable
|
||||
public Object queryAll(LocalStorageQueryCriteria criteria);
|
||||
|
||||
/**
|
||||
* findById
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@Cacheable(key = "#p0")
|
||||
LocalStorageDTO findById(Long id);
|
||||
|
||||
/**
|
||||
* create
|
||||
* @param name
|
||||
* @param file
|
||||
* @return
|
||||
*/
|
||||
@CacheEvict(allEntries = true)
|
||||
LocalStorageDTO create(String name, MultipartFile file);
|
||||
|
||||
/**
|
||||
* update
|
||||
* @param resources
|
||||
*/
|
||||
@CacheEvict(allEntries = true)
|
||||
void update(LocalStorage resources);
|
||||
|
||||
/**
|
||||
* delete
|
||||
* @param id
|
||||
*/
|
||||
@CacheEvict(allEntries = true)
|
||||
void delete(Long id);
|
||||
|
||||
@CacheEvict(allEntries = true)
|
||||
void deleteAll(Long[] ids);
|
||||
}
|
|
@ -20,7 +20,7 @@ public interface PictureService {
|
|||
* @param pageable
|
||||
* @return
|
||||
*/
|
||||
@Cacheable(keyGenerator = "keyGenerator")
|
||||
@Cacheable
|
||||
Object queryAll(PictureQueryCriteria criteria, Pageable pageable);
|
||||
|
||||
/**
|
||||
|
|
|
@ -8,6 +8,7 @@ import org.springframework.cache.annotation.CacheEvict;
|
|||
import org.springframework.cache.annotation.CachePut;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
/**
|
||||
|
@ -23,7 +24,7 @@ public interface QiNiuService {
|
|||
* @param pageable
|
||||
* @return
|
||||
*/
|
||||
@Cacheable(keyGenerator = "keyGenerator")
|
||||
@Cacheable
|
||||
Object queryAll(QiniuQueryCriteria criteria, Pageable pageable);
|
||||
|
||||
/**
|
||||
|
@ -89,4 +90,7 @@ public interface QiNiuService {
|
|||
*/
|
||||
@CacheEvict(allEntries = true)
|
||||
void deleteAll(Long[] ids, QiniuConfig config);
|
||||
|
||||
@CacheEvict(allEntries = true)
|
||||
void update(String type);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
package me.zhengjie.service.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import lombok.Data;
|
||||
import java.sql.Timestamp;
|
||||
import java.io.Serializable;
|
||||
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2019-09-05
|
||||
*/
|
||||
@Data
|
||||
public class LocalStorageDTO implements Serializable {
|
||||
|
||||
// ID
|
||||
private Long id;
|
||||
|
||||
private String realName;
|
||||
|
||||
// 文件名
|
||||
private String name;
|
||||
|
||||
// 后缀
|
||||
private String suffix;
|
||||
|
||||
// 类型
|
||||
private String type;
|
||||
|
||||
// 大小
|
||||
private String size;
|
||||
|
||||
// 操作人
|
||||
private String operate;
|
||||
|
||||
// 创建日期
|
||||
private Timestamp createTime;
|
||||
|
||||
// 修改日期
|
||||
private Timestamp updateTime;
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package me.zhengjie.service.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import java.sql.Timestamp;
|
||||
import me.zhengjie.annotation.Query;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2019-09-05
|
||||
*/
|
||||
@Data
|
||||
public class LocalStorageQueryCriteria{
|
||||
|
||||
// 模糊
|
||||
@Query(blurry = "name,suffix,type,operate,size")
|
||||
private String blurry;
|
||||
}
|
|
@ -0,0 +1,118 @@
|
|||
package me.zhengjie.service.impl;
|
||||
|
||||
import me.zhengjie.domain.LocalStorage;
|
||||
import me.zhengjie.exception.BadRequestException;
|
||||
import me.zhengjie.utils.*;
|
||||
import me.zhengjie.repository.LocalStorageRepository;
|
||||
import me.zhengjie.service.LocalStorageService;
|
||||
import me.zhengjie.service.dto.LocalStorageDTO;
|
||||
import me.zhengjie.service.dto.LocalStorageQueryCriteria;
|
||||
import me.zhengjie.service.mapper.LocalStorageMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Optional;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2019-09-05
|
||||
*/
|
||||
@Service
|
||||
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
|
||||
public class LocalStorageServiceImpl implements LocalStorageService {
|
||||
|
||||
@Autowired
|
||||
private LocalStorageRepository localStorageRepository;
|
||||
|
||||
@Autowired
|
||||
private LocalStorageMapper localStorageMapper;
|
||||
|
||||
@Value("${file.path}")
|
||||
private String path;
|
||||
|
||||
@Value("${file.maxSize}")
|
||||
private long maxSize;
|
||||
|
||||
@Override
|
||||
public Object queryAll(LocalStorageQueryCriteria criteria, Pageable pageable){
|
||||
Page<LocalStorage> page = localStorageRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
|
||||
return PageUtil.toPage(page.map(localStorageMapper::toDto));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object queryAll(LocalStorageQueryCriteria criteria){
|
||||
return localStorageMapper.toDto(localStorageRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalStorageDTO findById(Long id) {
|
||||
Optional<LocalStorage> localStorage = localStorageRepository.findById(id);
|
||||
ValidationUtil.isNull(localStorage,"LocalStorage","id",id);
|
||||
return localStorageMapper.toDto(localStorage.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public LocalStorageDTO create(String name, MultipartFile multipartFile) {
|
||||
FileUtil.checkSize(maxSize, multipartFile.getSize());
|
||||
String suffix = FileUtil.getExtensionName(multipartFile.getOriginalFilename());
|
||||
String type = FileUtil.getFileType(suffix);
|
||||
File file = FileUtil.upload(multipartFile, path + type + File.separator);
|
||||
try {
|
||||
name = StringUtils.isBlank(name) ? FileUtil.getFileNameNoEx(multipartFile.getOriginalFilename()) : name;
|
||||
LocalStorage localStorage = new LocalStorage(
|
||||
file.getName(),
|
||||
name,
|
||||
suffix,
|
||||
file.getPath(),
|
||||
type,
|
||||
FileUtil.getSize(multipartFile.getSize()),
|
||||
SecurityUtils.getUsername()
|
||||
);
|
||||
return localStorageMapper.toDto(localStorageRepository.save(localStorage));
|
||||
}catch (Exception e){
|
||||
FileUtil.del(file);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
File file = new File("C:\\Users\\Jie\\Pictures\\Saved Pictures\\demo1.jpg");
|
||||
System.out.println(FileUtil.getType(file));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void update(LocalStorage resources) {
|
||||
Optional<LocalStorage> optionalLocalStorage = localStorageRepository.findById(resources.getId());
|
||||
ValidationUtil.isNull( optionalLocalStorage,"LocalStorage","id",resources.getId());
|
||||
LocalStorage localStorage = optionalLocalStorage.get();
|
||||
localStorage.copy(resources);
|
||||
localStorageRepository.save(localStorage);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void delete(Long id) {
|
||||
LocalStorage storage = localStorageRepository.findById(id).get();
|
||||
FileUtil.del(storage.getPath());
|
||||
localStorageRepository.delete(storage);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteAll(Long[] ids) {
|
||||
for (Long id : ids) {
|
||||
LocalStorage storage = localStorageRepository.findById(id).get();
|
||||
FileUtil.del(storage.getPath());
|
||||
localStorageRepository.delete(storage);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -37,7 +37,7 @@ public class PictureServiceImpl implements PictureService {
|
|||
|
||||
public static final String CODE = "code";
|
||||
|
||||
public static final String MSG = "msg";
|
||||
public static final String MSG = "message";
|
||||
|
||||
@Override
|
||||
public Object queryAll(PictureQueryCriteria criteria, Pageable pageable){
|
||||
|
@ -56,7 +56,7 @@ public class PictureServiceImpl implements PictureService {
|
|||
JSONObject jsonObject = JSONUtil.parseObj(result);
|
||||
Picture picture = null;
|
||||
if(!jsonObject.get(CODE).toString().equals(SUCCESS)){
|
||||
throw new BadRequestException(jsonObject.get(MSG).toString());
|
||||
throw new BadRequestException(TranslatorUtil.translate(jsonObject.get(MSG).toString()));
|
||||
}
|
||||
//转成实体类
|
||||
picture = JSON.parseObject(jsonObject.get("data").toString(), Picture.class);
|
||||
|
|
|
@ -73,11 +73,7 @@ public class QiNiuServiceImpl implements QiNiuService {
|
|||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public QiniuContent upload(MultipartFile file, QiniuConfig qiniuConfig) {
|
||||
|
||||
Long size = maxSize * 1024 * 1024;
|
||||
if(file.getSize() > size){
|
||||
throw new BadRequestException("文件超出规定大小");
|
||||
}
|
||||
FileUtil.checkSize(maxSize, file.getSize());
|
||||
if(qiniuConfig.getId() == null){
|
||||
throw new BadRequestException("请先添加相应配置,再操作");
|
||||
}
|
||||
|
@ -98,9 +94,10 @@ public class QiNiuServiceImpl implements QiNiuService {
|
|||
DefaultPutRet putRet = new Gson().fromJson(response.bodyString(), DefaultPutRet.class);
|
||||
//存入数据库
|
||||
QiniuContent qiniuContent = new QiniuContent();
|
||||
qiniuContent.setSuffix(FileUtil.getExtensionName(putRet.key));
|
||||
qiniuContent.setBucket(qiniuConfig.getBucket());
|
||||
qiniuContent.setType(qiniuConfig.getType());
|
||||
qiniuContent.setKey(putRet.key);
|
||||
qiniuContent.setKey(FileUtil.getFileNameNoEx(putRet.key));
|
||||
qiniuContent.setUrl(qiniuConfig.getHost()+"/"+putRet.key);
|
||||
qiniuContent.setSize(FileUtil.getSize(Integer.parseInt(file.getSize()+"")));
|
||||
return qiniuContentRepository.save(qiniuContent);
|
||||
|
@ -140,7 +137,7 @@ public class QiNiuServiceImpl implements QiNiuService {
|
|||
Auth auth = Auth.create(config.getAccessKey(), config.getSecretKey());
|
||||
BucketManager bucketManager = new BucketManager(auth, cfg);
|
||||
try {
|
||||
bucketManager.delete(content.getBucket(), content.getKey());
|
||||
bucketManager.delete(content.getBucket(), content.getKey() + "." + content.getSuffix());
|
||||
qiniuContentRepository.delete(content);
|
||||
} catch (QiniuException ex) {
|
||||
qiniuContentRepository.delete(content);
|
||||
|
@ -170,10 +167,11 @@ public class QiNiuServiceImpl implements QiNiuService {
|
|||
QiniuContent qiniuContent = null;
|
||||
FileInfo[] items = fileListIterator.next();
|
||||
for (FileInfo item : items) {
|
||||
if(qiniuContentRepository.findByKey(item.key) == null){
|
||||
if(qiniuContentRepository.findByKey(FileUtil.getFileNameNoEx(item.key)) == null){
|
||||
qiniuContent = new QiniuContent();
|
||||
qiniuContent.setSize(FileUtil.getSize(Integer.parseInt(item.fsize+"")));
|
||||
qiniuContent.setKey(item.key);
|
||||
qiniuContent.setSuffix(FileUtil.getExtensionName(item.key));
|
||||
qiniuContent.setKey(FileUtil.getFileNameNoEx(item.key));
|
||||
qiniuContent.setType(config.getType());
|
||||
qiniuContent.setBucket(config.getBucket());
|
||||
qiniuContent.setUrl(config.getHost()+"/"+item.key);
|
||||
|
@ -189,4 +187,10 @@ public class QiNiuServiceImpl implements QiNiuService {
|
|||
delete(findByContentId(id), config);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void update(String type) {
|
||||
qiNiuConfigRepository.update(type);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package me.zhengjie.service.mapper;
|
||||
|
||||
import me.zhengjie.mapper.EntityMapper;
|
||||
import me.zhengjie.domain.LocalStorage;
|
||||
import me.zhengjie.service.dto.LocalStorageDTO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2019-09-05
|
||||
*/
|
||||
@Mapper(componentModel = "spring",uses = {},unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||
public interface LocalStorageMapper extends EntityMapper<LocalStorageDTO, LocalStorage> {
|
||||
|
||||
}
|
18
pom.xml
18
pom.xml
|
@ -17,7 +17,7 @@
|
|||
<module>eladmin-generator</module>
|
||||
</modules>
|
||||
|
||||
<name>el-admin</name>
|
||||
<name>EL-ADMIN后台管理系统</name>
|
||||
<url>http://auauz.net</url>
|
||||
|
||||
<parent>
|
||||
|
@ -155,6 +155,22 @@
|
|||
<artifactId>ip2region</artifactId>
|
||||
<version>1.7.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>poi</artifactId>
|
||||
<version>3.17</version>
|
||||
</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 -->
|
||||
<dependency>
|
||||
|
|
876
sql/eladmin.sql
876
sql/eladmin.sql
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue