Browse Source

📀 重构前端框架进行适配后端框架

master
wangxiang 3 years ago
parent
commit
e29538946a
  1. 10
      kicc-platform/kicc-platform-api/kicc-system-api/src/main/java/com/cloud/kicc/system/api/entity/File.java
  2. 69
      kicc-platform/kicc-platform-biz/kicc-system-biz/src/main/java/com/cloud/kicc/system/controller/FileController.java
  3. 2
      kicc-platform/kicc-platform-biz/kicc-system-biz/src/main/java/com/cloud/kicc/system/service/FileService.java
  4. 40
      kicc-platform/kicc-platform-biz/kicc-system-biz/src/main/java/com/cloud/kicc/system/service/impl/FileServiceImpl.java
  5. 10
      kicc-platform/kicc-platform-biz/kicc-system-biz/src/main/resources/bootstrap.yml
  6. 2
      kicc-ui/.env.development
  7. 2
      kicc-ui/.env.production
  8. 26
      kicc-ui/src/api/platform/system/controller/file.ts
  9. 26
      kicc-ui/src/api/platform/system/entity/file.ts

10
kicc-platform/kicc-platform-api/kicc-system-api/src/main/java/com/cloud/kicc/system/api/entity/File.java

@ -9,7 +9,7 @@ import lombok.experimental.Accessors; @@ -9,7 +9,7 @@ import lombok.experimental.Accessors;
/**
*<p>
* 文件管理
* oss文件管理
*</p>
*
* @Author: entfrm开发团队-王翔
@ -35,14 +35,14 @@ public class File extends CommonEntity { @@ -35,14 +35,14 @@ public class File extends CommonEntity {
private String fileName;
/**
* 原文件名
* 容器名称
*/
private String original;
private String bucketName;
/**
* 容器名称
* 原文件名
*/
private String bucketName;
private String original;
/**
* 文件类型

69
kicc-platform/kicc-platform-biz/kicc-system-biz/src/main/java/com/cloud/kicc/system/controller/FileController.java

@ -1,10 +1,14 @@ @@ -1,10 +1,14 @@
package com.cloud.kicc.system.controller;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cloud.kicc.system.api.entity.File;
import com.cloud.kicc.system.api.entity.Role;
import com.cloud.kicc.system.api.entity.RoleMenu;
import com.cloud.kicc.system.service.FileService;
import com.cloud.kicc.common.core.api.R;
import com.cloud.kicc.common.core.constant.AppConstants;
@ -20,6 +24,7 @@ import org.springframework.web.bind.annotation.*; @@ -20,6 +24,7 @@ import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
/**
*<p>
@ -31,65 +36,36 @@ import javax.servlet.http.HttpServletResponse; @@ -31,65 +36,36 @@ import javax.servlet.http.HttpServletResponse;
*/
@RestController
@AllArgsConstructor
@RequestMapping(AppConstants.APP_SYSTEM + "/sysFile")
@Api(value = "sysFile", tags = "文件管理")
@RequestMapping(AppConstants.APP_SYSTEM + "/file")
@Api(value = "file", tags = "文件管理")
public class FileController {
private final FileService fileService;
/**
* 分页查询
* @param page 分页对象
* @param file 文件管理
* @return
*/
@GetMapping("/list")
@ApiOperation(value = "分页查询", notes = "分页查询")
public R<IPage<File>> getSysFilePage(Page page, File file) {
return R.ok(fileService.page(page, Wrappers.query(file)));
private LambdaQueryWrapper<File> getQueryWrapper(File file) {
return new LambdaQueryWrapper<File>()
.like(StrUtil.isNotBlank(file.getFileName()), File::getFileName, file.getFileName());
}
/**
* 通过id删除文件管理
* @param id id
* @return R
*/
@SysLog("删除文件管理")
@DeleteMapping("/{id:\\w+}")
@PreAuthorize("@pms.hasPermission('sys_file_del')")
@ApiOperation(value = "通过id删除文件管理", notes = "通过id删除文件管理")
public R<Boolean> removeById(@PathVariable String id) {
return R.ok(fileService.deleteFile(id));
@GetMapping("/list")
@ApiOperation(value = "分页查询", notes = "分页查询")
public R list(Page page, File file) {
IPage<Role> fileIPage = fileService.page(page, getQueryWrapper(file));
return R.ok(fileIPage.getRecords(), fileIPage.getTotal());
}
/**
* 上传文件 文件名采用uuid,避免原始文件名中带"-"符号导致下载的时候解析出现异常
* @param file 资源
* @return R(/ admin / bucketName / filename)
*/
@PostMapping("/upload")
public R upload(@RequestPart("file") MultipartFile file) {
return fileService.uploadFile(file);
}
/**
* 获取文件
* @param bucket 桶名称
* @param fileName 文件空间/名称
* @param response
* @return
*/
@Inner(false)
@GetMapping("/{bucket}/{fileName}")
public void file(@PathVariable String bucket, @PathVariable String fileName, HttpServletResponse response) {
public void getById(@PathVariable String bucket, @PathVariable String fileName, HttpServletResponse response) {
fileService.getFile(bucket, fileName, response);
}
/**
* 获取本地resources文件
* @param fileName 文件名称
* @param response 本地文件
*/
/** 获取上传模板 */
@SneakyThrows
@GetMapping("/local/{fileName}")
public void localFile(@PathVariable String fileName, HttpServletResponse response) {
@ -98,4 +74,15 @@ public class FileController { @@ -98,4 +74,15 @@ public class FileController {
IoUtil.copy(resource.getInputStream(), response.getOutputStream());
}
@SysLog("删除文件管理")
@DeleteMapping("/remove/{ids:[\\w,]+}")
@PreAuthorize("@pms.hasPermission('sys_file_del')")
@ApiOperation(value = "通过id删除文件管理", notes = "通过id删除文件管理")
public R remove(@PathVariable String[] ids) {
for (int i = 0; i < ids.length; ++i) {
fileService.deleteFile(ids[i]);
}
return R.ok();
}
}

2
kicc-platform/kicc-platform-biz/kicc-system-biz/src/main/java/com/cloud/kicc/system/service/FileService.java

@ -35,7 +35,7 @@ public interface FileService extends IService<File> { @@ -35,7 +35,7 @@ public interface FileService extends IService<File> {
/**
* 删除文件
* @param id
* @return
* @return Boolean
*/
Boolean deleteFile(String id);

40
kicc-platform/kicc-platform-biz/kicc-system-biz/src/main/java/com/cloud/kicc/system/service/impl/FileServiceImpl.java

@ -36,14 +36,8 @@ import java.util.Map; @@ -36,14 +36,8 @@ import java.util.Map;
public class FileServiceImpl extends ServiceImpl<FileMapper, File> implements FileService {
private final OssProperties ossProperties;
private final OssTemplate ossTemplate;
/**
* 上传文件
* @param file
* @return
*/
@Override
public R uploadFile(MultipartFile file) {
String fileName = IdUtil.simpleUUID() + StrUtil.DOT + FileUtil.extName(file.getOriginalFilename());
@ -51,42 +45,27 @@ public class FileServiceImpl extends ServiceImpl<FileMapper, File> implements Fi @@ -51,42 +45,27 @@ public class FileServiceImpl extends ServiceImpl<FileMapper, File> implements Fi
resultMap.put("bucketName", ossProperties.getBucketName());
resultMap.put("fileName", fileName);
resultMap.put("url", String.format("/admin/sys-file/%s/%s", ossProperties.getBucketName(), fileName));
try {
ossTemplate.putObject(ossProperties.getBucketName(), fileName, file.getContentType(),
file.getInputStream());
ossTemplate.putObject(ossProperties.getBucketName(), fileName, file.getContentType(), file.getInputStream());
// 文件管理数据记录,收集管理追踪文件
fileLog(file, fileName);
}
catch (Exception e) {
} catch (Exception e) {
log.error("上传失败", e);
return R.error(e.getLocalizedMessage());
}
return R.ok(resultMap);
}
/**
* 读取文件
* @param bucket
* @param fileName
* @param response
*/
@Override
public void getFile(String bucket, String fileName, HttpServletResponse response) {
try (S3Object s3Object = ossTemplate.getObject(bucket, fileName)) {
response.setContentType("application/octet-stream; charset=UTF-8");
IoUtil.copy(s3Object.getObjectContent(), response.getOutputStream());
}
catch (Exception e) {
} catch (Exception e) {
log.error("文件读取异常: {}", e.getLocalizedMessage());
}
}
/**
* 删除文件
* @param id
* @return
*/
@Override
@SneakyThrows
@Transactional(rollbackFor = Exception.class)
@ -102,13 +81,12 @@ public class FileServiceImpl extends ServiceImpl<FileMapper, File> implements Fi @@ -102,13 +81,12 @@ public class FileServiceImpl extends ServiceImpl<FileMapper, File> implements Fi
* @param fileName 文件名
*/
private void fileLog(MultipartFile file, String fileName) {
File sysFile = new File();
sysFile.setFileName(fileName);
sysFile.setOriginal(file.getOriginalFilename());
sysFile.setFileSize(file.getSize());
sysFile.setType(FileUtil.extName(file.getOriginalFilename()));
sysFile.setBucketName(ossProperties.getBucketName());
this.save(sysFile);
this.save(new File()
.setFileName(fileName)
.setOriginal(file.getOriginalFilename())
.setFileSize(file.getSize())
.setType(FileUtil.extName(file.getOriginalFilename()))
.setBucketName(ossProperties.getBucketName()));
}
}

10
kicc-platform/kicc-platform-biz/kicc-system-biz/src/main/resources/bootstrap.yml

@ -15,13 +15,3 @@ spring: @@ -15,13 +15,3 @@ spring:
namespace: @profiles.namespace@
shared-configs:
- application.${spring.cloud.nacos.config.file-extension}
# 文件上传相关 支持阿里云、华为云、腾讯、minio
oss:
endpoint: https://oss-cn-hangzhou.aliyuncs.com
access-Key: LTAI4FdQ9kVVXjxTKk3WnYmC
secret-Key: Elc2pUFkSJVjpVU5p1YJSRTNn5dt2s
region: cn-hangzhou
path-style-access: false
bucket-name: kl-kicc-dev

2
kicc-ui/.env.development

@ -4,7 +4,7 @@ VITE_PUBLIC_PATH = / @@ -4,7 +4,7 @@ VITE_PUBLIC_PATH = /
# 本地开发代理,可以解决跨域及多地址代理
# 如果接口地址匹配到,则会转发到http://localhost:3000,防止本地出现跨域问题
# 可以有多个,注意多个不能换行,否则代理将会失效
VITE_PROXY = [["/api","http://localhost:9999"],["/upload","http://localhost:3300/upload"]]
VITE_PROXY = [["/api","http://localhost:9999"],["/upload","http://localhost:9999/system_proxy/system/file/upload"]]
# 是否删除console.log
VITE_DROP_CONSOLE = false

2
kicc-ui/.env.production

@ -4,7 +4,7 @@ VITE_PUBLIC_PATH = / @@ -4,7 +4,7 @@ VITE_PUBLIC_PATH = /
# 本地开发代理,可以解决跨域及多地址代理
# 如果接口地址匹配到,则会转发到http://localhost:3000,防止本地出现跨域问题
# 可以有多个,注意多个不能换行,否则代理将会失效
VITE_PROXY = [["/prod-api","http://localhost:9999"],["/prod-upload","http://localhost:3300/upload"]]
VITE_PROXY = [["/prod-api","http://localhost:9999"],["/prod-upload","http://localhost:9999/system_proxy/system/file/upload"]]
# 是否删除console.log
VITE_DROP_CONSOLE = true

26
kicc-ui/src/api/platform/system/controller/file.ts

@ -0,0 +1,26 @@ @@ -0,0 +1,26 @@
/**
* api模板规范代码参考,
* Copyright © 2020-2022 <a href="http://www.entfrm.com/">entfrm</a> All rights reserved.
* author entfrm开发团队-
*/
import type { FileParams, FileResult } from '/@/api/platform/system/entity/file';
import { defHttp } from '/@/utils/http/axios';
enum Api {
list = '/system_proxy/system/file/list',
get = '/system_proxy/system/file',
getLocal = '/system_proxy/system/file/local',
del = '/system_proxy/system/file/remove'
}
/** 查询文件列表 */
export const listFile = (params?: Partial<FileParams>) => defHttp.get<FileResult>({ url: Api.list, params }, { isReturnResultResponse: true });
/** 获取文件 */
export const getFile = (bucket: string, fileName: string) => defHttp.get({ url: `${Api.get}/${bucket}/${fileName}` });
/** 获取本地模板文件 */
export const getLocalFile = (fileName: string) => defHttp.get({ url: `${Api.getLocal}/${fileName}` });
/** 删除文件 */
export const delFile = (ids: string) => defHttp.delete({ url: `${Api.del}/${ids}` });

26
kicc-ui/src/api/platform/system/entity/file.ts

@ -0,0 +1,26 @@ @@ -0,0 +1,26 @@
/**
* @program: kicc-ui
* @description:
*
* @author: entfrm开发团队-
* @create: 2022/4/8
*/
import { R } from '/#/axios';
import { CommonEntity, Page } from '/@/api/common/data/entity';
/** 文件查询参数 */
export type FileParams = Page & File;
/** 文件对象 */
export interface File extends CommonEntity {
id: string;
fileName: string;
bucketName: string;
original: string;
type: string;
fileSize: number;
[key: string]: any;
}
/** 文件响应对象 */
export type FileResult = R<File[]>;
Loading…
Cancel
Save