update 小改动

master
管理员 1 year ago
parent 081a42390f
commit f2f7c441ba

@ -9,6 +9,7 @@ const useUserStore = defineStore(
{ {
state: () => ({ state: () => ({
token: getToken(), token: getToken(),
user: {},
name: '', name: '',
avatar: '', avatar: '',
roles: [], roles: [],
@ -45,8 +46,9 @@ const useUserStore = defineStore(
} else { } else {
this.roles = ['ROLE_DEFAULT'] this.roles = ['ROLE_DEFAULT']
} }
this.name = user.userName this.name = user.userName;
this.avatar = avatar; this.avatar = avatar;
this.user = user;
resolve(res) resolve(res)
}).catch(error => { }).catch(error => {
reject(error) reject(error)

@ -0,0 +1,26 @@
package com.ruoyi.common.event;
import org.springframework.context.ApplicationEvent;
/**
* QAnything
*/
public class QaEvent extends ApplicationEvent {
public static enum Type {
ALL, ADD, UPDATE, REMOVE;
}
public QaEvent(Type source) {
super(source);
}
public QaEvent() {
super(Type.ALL);
}
@Override
public Type getSource() {
return (Type) super.getSource();
}
}

@ -61,6 +61,7 @@ public class MongoUtil {
} }
return c; return c;
} }
public static Criteria or(Criteria... criterias) { public static Criteria or(Criteria... criterias) {
Criteria c = new Criteria(); Criteria c = new Criteria();
if (ArrayUtil.isNotEmpty(criterias)) { if (ArrayUtil.isNotEmpty(criterias)) {
@ -73,6 +74,7 @@ public class MongoUtil {
/** /**
* (iseq)<br/> * (iseq)<br/>
* *
*
* @param obj * @param obj
* @return * @return
*/ */
@ -101,9 +103,11 @@ public class MongoUtil {
} }
/** age$gt /**
* age$gt
* *
* $ * $
*
* @param obj * @param obj
* @return * @return
*/ */
@ -129,6 +133,14 @@ public class MongoUtil {
return criteria(map); return criteria(map);
} }
public static Criteria criteria() {
return new Criteria();
}
public static Criteria criteria(String key) {
return Criteria.where(key);
}
/** /**
* mapkeyrule,value * mapkeyrule,value
* rule$() * rule$()

@ -0,0 +1,37 @@
package com.ruoyi.cron.task;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.LocalDateTimeUtil;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.cron.TaskLog;
import com.ruoyi.cron.annotation.Cron;
import com.ruoyi.cron.annotation.CronComponent;
import com.ruoyi.cron.annotation.CronParam;
import com.ruoyi.cron.document.CronTaskLog;
import com.ruoyi.cron.runner.CronBeanPostProcessor;
import lombok.RequiredArgsConstructor;
import java.time.LocalDate;
import java.util.Date;
import static com.ruoyi.common.utils.MongoUtil.*;
@CronComponent
@RequiredArgsConstructor
public class CronTaskLogCleanTask {
private final TaskLog log;
private final CronBeanPostProcessor cronBeanPostProcessor;
@Cron("日志清理任务")
public void clear(@CronParam("几天前") Integer day, @CronParam("清理的组(null全部)") Integer groupId, @CronParam("清理的任务(null全部)") String taskId) {
log.log("开始执行日志清理...");
Date date = DateUtils.toDate(LocalDate.now().plusDays(-day));
log.log("清理时间(之前)" + DateUtil.formatDateTime(date));
log.log("清理的组编号:" + ((groupId == null) ? "全部" : groupId));
log.log("清理的任务:" + ((taskId == null) ? "全部" : cronBeanPostProcessor.getList().stream().filter(a -> a.getId().equals(taskId)).findFirst().get().getName()));
long count = doRemove(CronTaskLog.class, conditions().put("startTime$lt", date).query()).getDeletedCount();
log.log("日志清理完成,清理数量:" + count);
}
}

@ -38,6 +38,13 @@ import java.util.function.Supplier;
*/ */
public interface ISysOssService { public interface ISysOssService {
/**
*
*/
public static enum Service {
minio, qiniu, aliyun, qcloud, image, upload;
}
String IMAGE_WEBP = "webp"; String IMAGE_WEBP = "webp";
/** /**
@ -45,9 +52,17 @@ public interface ISysOssService {
*/ */
String PRE_DEFAULT = "default"; String PRE_DEFAULT = "default";
/**
*
*
* @param handle
*/
void setService(Service service, Runnable handle);
public <T> T setService(Service service, Supplier<T> handle);
/** /**
* *
* *
* @param handle * @param handle
*/ */
@ -55,7 +70,7 @@ public interface ISysOssService {
/** /**
* *
* *
* @param handle * @param handle
*/ */
@ -165,7 +180,13 @@ public interface ISysOssService {
void download(Long ossId, HttpServletResponse response) throws IOException; void download(Long ossId, HttpServletResponse response) throws IOException;
void download(String url, String service, HttpServletResponse response) throws IOException; void download(String url, Service service, HttpServletResponse response) throws IOException;
InputStream download(Long ossId) throws IOException;
InputStream download(SysOssVo sysOss) throws IOException;
InputStream download(String url, Service service) throws IOException;
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid); Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
@ -361,4 +382,15 @@ public interface ISysOssService {
// System.out.println(ByteBuffer.wrap(aes.encrypt(buffer.array())).getLong()); // System.out.println(ByteBuffer.wrap(aes.encrypt(buffer.array())).getLong());
// } // }
SysOssVo url(SysOssVo oss, int second);
default SysOssVo url(SysOssVo oss) {
return url(oss, 120);
}
String url(Service service,String url,int second);
default String url(Service service,String url) {
return url(service,url, 120);
}
} }

@ -57,6 +57,27 @@ public class SysOssServiceImpl implements ISysOssService, OssService {
private final FileService fileService; private final FileService fileService;
private final SysOssMapper baseMapper; private final SysOssMapper baseMapper;
private static ThreadLocal<Boolean> IGNORE_THREAD_LOCAL = new ThreadLocal<>(); private static ThreadLocal<Boolean> IGNORE_THREAD_LOCAL = new ThreadLocal<>();
private static ThreadLocal<Service> SERVICE_THREAD_LOCAL = new ThreadLocal<>();
@Override
public void setService(Service service, Runnable handle) {
SERVICE_THREAD_LOCAL.set(service);
try {
handle.run();
} finally {
SERVICE_THREAD_LOCAL.remove();
}
}
@Override
public <T> T setService(Service service, Supplier<T> handle) {
SERVICE_THREAD_LOCAL.set(service);
try {
return handle.get();
} finally {
SERVICE_THREAD_LOCAL.remove();
}
}
@Override @Override
public void ignore(Runnable handle) { public void ignore(Runnable handle) {
@ -82,7 +103,7 @@ public class SysOssServiceImpl implements ISysOssService, OssService {
public TableDataInfo<SysOssVo> queryPageList(SysOssBo bo, PageQuery pageQuery) { public TableDataInfo<SysOssVo> queryPageList(SysOssBo bo, PageQuery pageQuery) {
LambdaQueryWrapper<SysOss> lqw = buildQueryWrapper(bo); LambdaQueryWrapper<SysOss> lqw = buildQueryWrapper(bo);
Page<SysOssVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw); Page<SysOssVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
List<SysOssVo> filterResult = result.getRecords().stream().map(this::matchingUrl).collect(Collectors.toList()); List<SysOssVo> filterResult = result.getRecords().stream().map(this::url).collect(Collectors.toList());
result.setRecords(filterResult); result.setRecords(filterResult);
return TableDataInfo.build(result); return TableDataInfo.build(result);
} }
@ -93,7 +114,7 @@ public class SysOssServiceImpl implements ISysOssService, OssService {
for (Long id : ossIds) { for (Long id : ossIds) {
SysOssVo vo = SpringUtils.getBean(ISysOssService.class).getById(id); SysOssVo vo = SpringUtils.getBean(ISysOssService.class).getById(id);
if (ObjectUtil.isNotNull(vo)) { if (ObjectUtil.isNotNull(vo)) {
list.add(this.matchingUrl(vo)); list.add(this.url(vo));
} }
} }
return list; return list;
@ -105,7 +126,7 @@ public class SysOssServiceImpl implements ISysOssService, OssService {
for (Long id : StringUtils.splitTo(ossIds, Convert::toLong)) { for (Long id : StringUtils.splitTo(ossIds, Convert::toLong)) {
SysOssVo vo = SpringUtils.getBean(ISysOssService.class).getById(id); SysOssVo vo = SpringUtils.getBean(ISysOssService.class).getById(id);
if (ObjectUtil.isNotNull(vo)) { if (ObjectUtil.isNotNull(vo)) {
list.add(this.matchingUrl(vo).getUrl()); list.add(this.url(vo).getUrl());
} }
} }
return String.join(StringUtils.SEPARATOR, list); return String.join(StringUtils.SEPARATOR, list);
@ -159,11 +180,10 @@ public class SysOssServiceImpl implements ISysOssService, OssService {
} }
} }
@Override public void download(String url, Service service, HttpServletResponse response) throws IOException {
public void download(String url, String service, HttpServletResponse response) throws IOException {
FileUtils.setAttachmentResponseHeader(response, FileNameUtil.getName(url)); FileUtils.setAttachmentResponseHeader(response, FileNameUtil.getName(url));
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE + "; charset=UTF-8"); response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE + "; charset=UTF-8");
if (UPLOAD.equalsIgnoreCase(service)) { if (UPLOAD.equalsIgnoreCase(service.name())) {
try (InputStream inputStream = new FileInputStream(fileService.getFile(url))) { try (InputStream inputStream = new FileInputStream(fileService.getFile(url))) {
int available = inputStream.available(); int available = inputStream.available();
IoUtil.copy(inputStream, response.getOutputStream()); IoUtil.copy(inputStream, response.getOutputStream());
@ -172,7 +192,7 @@ public class SysOssServiceImpl implements ISysOssService, OssService {
throw new ServiceException(e.getMessage()); throw new ServiceException(e.getMessage());
} }
} else { } else {
OssClient storage = OssFactory.instance(service); OssClient storage = OssFactory.instance(service.name());
try (InputStream inputStream = storage.getObjectContent(url)) { try (InputStream inputStream = storage.getObjectContent(url)) {
int available = inputStream.available(); int available = inputStream.available();
IoUtil.copy(inputStream, response.getOutputStream()); IoUtil.copy(inputStream, response.getOutputStream());
@ -183,6 +203,35 @@ public class SysOssServiceImpl implements ISysOssService, OssService {
} }
} }
@Override
public InputStream download(Long ossId) throws IOException {
SysOssVo sysOss = SpringUtils.getBean(ISysOssService.class).getById(ossId);
return download(sysOss);
}
@Override
public InputStream download(SysOssVo sysOss) throws IOException {
if (ObjectUtil.isNull(sysOss)) {
throw new ServiceException("文件数据不存在!");
}
if (UPLOAD.equals(sysOss.getService())) {
return new FileInputStream(fileService.getFile(sysOss.getUrl()));
} else {
OssClient storage = OssFactory.instance(sysOss.getService());
return storage.getObjectContent(sysOss.getUrl());
}
}
@Override
public InputStream download(String url, Service service) throws IOException {
if (UPLOAD.equalsIgnoreCase(service.name())) {
return new FileInputStream(fileService.getFile(url));
} else {
OssClient storage = OssFactory.instance(service.name());
return storage.getObjectContent(url);
}
}
@Override @Override
public SysOssVo save(InputStream in, String originalFileName, String contentType, String pre, String rule) { public SysOssVo save(InputStream in, String originalFileName, String contentType, String pre, String rule) {
@ -191,7 +240,7 @@ public class SysOssServiceImpl implements ISysOssService, OssService {
oss.setOriginalName(originalFileName); oss.setOriginalName(originalFileName);
oss.setFileSuffix(suffix); oss.setFileSuffix(suffix);
if (configService.selectOssEnabled()) { if (configService.selectOssEnabled()) {
OssClient storage = OssFactory.instance(); OssClient storage = SERVICE_THREAD_LOCAL.get() == null ? OssFactory.instance() : OssFactory.instance(SERVICE_THREAD_LOCAL.get().name());
UploadResult uploadResult; UploadResult uploadResult;
try { try {
String path = ""; String path = "";
@ -229,7 +278,7 @@ public class SysOssServiceImpl implements ISysOssService, OssService {
SysOssVo sysOssVo = new SysOssVo(); SysOssVo sysOssVo = new SysOssVo();
BeanCopyUtils.copy(oss, sysOssVo); BeanCopyUtils.copy(oss, sysOssVo);
return this.matchingUrl(sysOssVo); return this.url(sysOssVo);
} }
public SysOssVo uploadImgs(MultipartFile file, String pre) { public SysOssVo uploadImgs(MultipartFile file, String pre) {
@ -245,7 +294,7 @@ public class SysOssServiceImpl implements ISysOssService, OssService {
oss.setOriginalName(originalFileName); oss.setOriginalName(originalFileName);
if (configService.selectOssEnabled()) { if (configService.selectOssEnabled()) {
OssClient storage = OssFactory.instance(); OssClient storage = SERVICE_THREAD_LOCAL.get() == null ? OssFactory.instance() : OssFactory.instance(SERVICE_THREAD_LOCAL.get().name());
UploadResult uploadResult; UploadResult uploadResult;
try ( try (
@ -288,7 +337,7 @@ public class SysOssServiceImpl implements ISysOssService, OssService {
} }
SysOssVo sysOssVo = new SysOssVo(); SysOssVo sysOssVo = new SysOssVo();
BeanCopyUtils.copy(oss, sysOssVo); BeanCopyUtils.copy(oss, sysOssVo);
return this.matchingUrl(sysOssVo); return this.url(sysOssVo);
} }
@Override @Override
@ -308,22 +357,32 @@ public class SysOssServiceImpl implements ISysOssService, OssService {
return baseMapper.deleteBatchIds(ids) > 0; return baseMapper.deleteBatchIds(ids) > 0;
} }
/** @Override
* Url public SysOssVo url(SysOssVo oss, int second) {
*
* @param oss OSS
* @return oss UrlOSS
*/
private SysOssVo matchingUrl(SysOssVo oss) {
if (UPLOAD.equals(oss.getService())) { if (UPLOAD.equals(oss.getService())) {
return oss; return oss;
} else { } else {
OssClient storage = OssFactory.instance(oss.getService()); OssClient storage = OssFactory.instance(oss.getService());
// 仅修改桶类型为 private 的URL临时URL时长为120s // 仅修改桶类型为 private 的URL临时URL时长为120s
if (AccessPolicyType.PRIVATE == storage.getAccessPolicy()) { if (AccessPolicyType.PRIVATE == storage.getAccessPolicy()) {
oss.setUrl(storage.getPrivateUrl(oss.getFileName(), 120)); oss.setUrl(storage.getPrivateUrl(oss.getFileName(), second));
} }
return oss; return oss;
} }
} }
@Override
public String url(Service service, String url, int second) {
if (Service.upload.equals(service)) {
return url;
} else {
OssClient storage = OssFactory.instance(service.name());
// 仅修改桶类型为 private 的URL临时URL时长为120s
if (AccessPolicyType.PRIVATE == storage.getAccessPolicy()) {
return storage.getPrivateUrl(url, second);
}
return url;
}
}
} }

Loading…
Cancel
Save