mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-11-10 02:57:17 +08:00
refactor: 优化项目模块命名(简化、分类、统一)
This commit is contained in:
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.continew.admin.system.config.file;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.ClassUtil;
|
||||
import cn.hutool.core.util.EscapeUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.x.file.storage.core.FileInfo;
|
||||
import org.dromara.x.file.storage.core.recorder.FileRecorder;
|
||||
import org.dromara.x.file.storage.core.upload.FilePartInfo;
|
||||
import org.springframework.stereotype.Component;
|
||||
import top.continew.admin.common.context.UserContextHolder;
|
||||
import top.continew.admin.system.enums.FileTypeEnum;
|
||||
import top.continew.admin.system.mapper.FileMapper;
|
||||
import top.continew.admin.system.mapper.StorageMapper;
|
||||
import top.continew.admin.system.model.entity.FileDO;
|
||||
import top.continew.admin.system.model.entity.StorageDO;
|
||||
import top.continew.starter.core.constant.StringConstants;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* 文件记录实现类
|
||||
*
|
||||
* @author Charles7c
|
||||
* @since 2023/12/24 22:31
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class FileRecorderImpl implements FileRecorder {
|
||||
|
||||
private final FileMapper fileMapper;
|
||||
private final StorageMapper storageMapper;
|
||||
|
||||
@Override
|
||||
public boolean save(FileInfo fileInfo) {
|
||||
FileDO file = new FileDO();
|
||||
String originalFilename = EscapeUtil.unescape(fileInfo.getOriginalFilename());
|
||||
file.setName(StrUtil.contains(originalFilename, StringConstants.DOT)
|
||||
? StrUtil.subBefore(originalFilename, StringConstants.DOT, true)
|
||||
: originalFilename);
|
||||
file.setUrl(fileInfo.getUrl());
|
||||
file.setSize(fileInfo.getSize());
|
||||
file.setExtension(fileInfo.getExt());
|
||||
file.setType(FileTypeEnum.getByExtension(file.getExtension()));
|
||||
file.setThumbnailUrl(fileInfo.getThUrl());
|
||||
file.setThumbnailSize(fileInfo.getThSize());
|
||||
StorageDO storage = (StorageDO)fileInfo.getAttr().get(ClassUtil.getClassName(StorageDO.class, false));
|
||||
file.setStorageId(storage.getId());
|
||||
file.setCreateTime(DateUtil.toLocalDateTime(fileInfo.getCreateTime()));
|
||||
file.setUpdateUser(UserContextHolder.getUserId());
|
||||
file.setUpdateTime(file.getCreateTime());
|
||||
fileMapper.insert(file);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileInfo getByUrl(String url) {
|
||||
FileDO file = this.getFileByUrl(url);
|
||||
if (null == file) {
|
||||
return null;
|
||||
}
|
||||
return file.toFileInfo(storageMapper.lambdaQuery().eq(StorageDO::getId, file.getStorageId()).one().getCode());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean delete(String url) {
|
||||
FileDO file = this.getFileByUrl(url);
|
||||
return fileMapper.lambdaUpdate().eq(FileDO::getUrl, file.getUrl()).remove();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(FileInfo fileInfo) {
|
||||
/* 不使用分片功能则无需重写 */
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveFilePart(FilePartInfo filePartInfo) {
|
||||
/* 不使用分片功能则无需重写 */
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteFilePartByUploadId(String s) {
|
||||
/* 不使用分片功能则无需重写 */
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 URL 查询文件
|
||||
*
|
||||
* @param url URL
|
||||
* @return 文件信息
|
||||
*/
|
||||
private FileDO getFileByUrl(String url) {
|
||||
Optional<FileDO> fileOptional = fileMapper.lambdaQuery().eq(FileDO::getUrl, url).oneOpt();
|
||||
return fileOptional.orElseGet(() -> fileMapper.lambdaQuery()
|
||||
.likeLeft(FileDO::getUrl, StrUtil.subAfter(url, StringConstants.SLASH, true))
|
||||
.oneOpt()
|
||||
.orElse(null));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.continew.admin.system.config.file;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.stereotype.Component;
|
||||
import top.continew.admin.common.enums.DisEnableStatusEnum;
|
||||
import top.continew.admin.system.model.query.StorageQuery;
|
||||
import top.continew.admin.system.model.req.StorageReq;
|
||||
import top.continew.admin.system.model.resp.StorageResp;
|
||||
import top.continew.admin.system.service.StorageService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 文件存储配置加载器
|
||||
*
|
||||
* @author Charles7c
|
||||
* @since 2023/12/24 22:31
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class FileStorageConfigLoader implements ApplicationRunner {
|
||||
|
||||
private final StorageService storageService;
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) {
|
||||
StorageQuery query = new StorageQuery();
|
||||
query.setStatus(DisEnableStatusEnum.ENABLE);
|
||||
List<StorageResp> storageList = storageService.list(query, null);
|
||||
if (CollUtil.isEmpty(storageList)) {
|
||||
return;
|
||||
}
|
||||
storageList.forEach(s -> storageService.load(BeanUtil.copyProperties(s, StorageReq.class)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.continew.admin.system.config.mail;
|
||||
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
import top.continew.admin.common.constant.SysConstants;
|
||||
import top.continew.admin.system.service.OptionService;
|
||||
import top.continew.starter.messaging.mail.core.MailConfig;
|
||||
import top.continew.starter.messaging.mail.core.MailConfigurer;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 邮件配置实现
|
||||
*
|
||||
* @author Charles7c
|
||||
* @since 2024/5/30 22:32
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class MailConfigurerImpl implements MailConfigurer {
|
||||
|
||||
private final OptionService optionService;
|
||||
|
||||
@Override
|
||||
public MailConfig getMailConfig() {
|
||||
// 查询邮件配置
|
||||
Map<String, String> map = optionService.getByCategory("MAIL");
|
||||
// 封装邮件配置
|
||||
MailConfig mailConfig = new MailConfig();
|
||||
mailConfig.setProtocol(MapUtil.getStr(map, "MAIL_PROTOCOL"));
|
||||
mailConfig.setHost(MapUtil.getStr(map, "MAIL_HOST"));
|
||||
mailConfig.setPort(MapUtil.getInt(map, "MAIL_PORT"));
|
||||
mailConfig.setUsername(MapUtil.getStr(map, "MAIL_USERNAME"));
|
||||
mailConfig.setPassword(MapUtil.getStr(map, "MAIL_PASSWORD"));
|
||||
mailConfig.setSslEnabled(SysConstants.YES.equals(MapUtil.getInt(map, "MAIL_SSL_ENABLED")));
|
||||
if (mailConfig.isSslEnabled()) {
|
||||
mailConfig.setSslPort(MapUtil.getInt(map, "MAIL_SSL_PORT"));
|
||||
}
|
||||
return mailConfig;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user