update 更改模块名称

This commit is contained in:
lijiarao
2023-09-05 09:10:12 +08:00
parent 248a2dbe8a
commit 8522fc6f34
1501 changed files with 4 additions and 47397 deletions
@@ -0,0 +1,94 @@
package com.jero.modules.oss.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jero.common.api.vo.Result;
import com.jero.common.system.query.QueryGenerator;
import com.jero.modules.oss.entity.OSSFile;
import com.jero.modules.oss.service.IOSSFileService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;
@Slf4j
@Controller
@RequestMapping("/sys/oss/file")
public class OSSFileController {
@Autowired
private IOSSFileService ossFileService;
@ResponseBody
@GetMapping("/page")
public Result<IPage<OSSFile>> queryPageList(OSSFile file,
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest req) {
Result<IPage<OSSFile>> result = new Result<>();
QueryWrapper<OSSFile> queryWrapper = QueryGenerator.initQueryWrapper(file, req.getParameterMap());
Page<OSSFile> page = new Page<>(pageNo, pageSize);
IPage<OSSFile> pageList = ossFileService.page(page, queryWrapper);
result.setSuccess(true);
result.setResult(pageList);
return result;
}
@ResponseBody
@PostMapping("/upload")
//@RequiresRoles("admin")
public Result<T> upload(@RequestParam("file") MultipartFile multipartFile) {
try {
ossFileService.upload(multipartFile);
return Result.OK("上传成功!");
}
catch (Exception ex) {
log.info(ex.getMessage(), ex);
return Result.error("上传失败");
}
}
@ResponseBody
@PostMapping("/delete")
public Result<T> delete(@RequestBody Map<String,String> map) {
String id = map.get("id");
if(StringUtils.isBlank(id)){
return Result.error("参数不识别!");
}
OSSFile file = ossFileService.getById(id);
if (file == null) {
return Result.error("未找到对应实体");
} else {
boolean ok = ossFileService.delete(file);
if (ok) {
return Result.OK("删除成功!");
}
}
return Result.OK();
}
/**
* 通过id查询.
*/
@ResponseBody
@GetMapping("/queryById")
public Result<OSSFile> queryById(@RequestParam(name = "id") String id) {
Result<OSSFile> result = new Result<>();
OSSFile file = ossFileService.getById(id);
if (file == null) {
return Result.error("未找到对应实体");
}
else {
result.setResult(file);
result.setSuccess(true);
}
return result;
}
}
@@ -0,0 +1,48 @@
package com.jero.modules.oss.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import com.jero.common.system.base.entity.JeroEntity;
import org.jeecgframework.poi.excel.annotation.Excel;
import java.util.Date;
@Data
@TableName("oss_file")
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
public class OSSFile extends JeroEntity {
private static final long serialVersionUID = 1L;
@Excel(name = "文件名称")
private String fileName;
@Excel(name = "文件地址")
private String url;
@ApiModelProperty(value = "关联ID")
private String connectId;
@ApiModelProperty(value = "创建人登录名称")
private String createBy;
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
@ApiModelProperty(value = "创建日期")
private Date createTime;
@ApiModelProperty(value = "更新人登录名称")
private String updateBy;
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
@ApiModelProperty(value = "更新日期")
private Date updateTime;
@ApiModelProperty(value = "所属部门")
private String sysOrgCode;
}
@@ -0,0 +1,8 @@
package com.jero.modules.oss.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jero.modules.oss.entity.OSSFile;
public interface OSSFileMapper extends BaseMapper<OSSFile> {
}
@@ -0,0 +1,29 @@
package com.jero.modules.oss.service;
import java.io.IOException;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.IService;
import com.jero.modules.oss.entity.OSSFile;
import org.springframework.web.multipart.MultipartFile;
public interface IOSSFileService extends IService<OSSFile> {
void upload(MultipartFile multipartFile) throws IOException;
boolean delete(OSSFile ossFile);
List<OSSFile> getFileInfoAll(String id);
List<OSSFile> getFileInfosByConnectId(String connectId);
void deleteByConnectIdList(List<String> connectIdList);
OSSFile uploadLocalForSplit(MultipartFile mf, String bizPath, String state, String cut);
List<OSSFile> getFileInfos(String id);
void updateFileInfo(List<OSSFile> ossFileList);
OSSFile uploadLocalOfCos(MultipartFile mf, String bizPath, String state, String cut);
}
@@ -0,0 +1,333 @@
package com.jero.modules.oss.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jero.common.constant.enums.LanguageEnum;
import com.jero.common.exception.JeroBootException;
import com.jero.common.system.vo.LoginUser;
import com.jero.common.util.CommonUtils;
import com.jero.common.util.MinioUtil;
import com.jero.common.util.oss.OssBootUtil;
import com.jero.modules.oss.entity.OSSFile;
import com.jero.modules.oss.mapper.OSSFileMapper;
import com.jero.modules.oss.service.IOSSFileService;
import com.jero.modules.system.util.MyStringUtils;
import me.zhyd.oauth.utils.UuidUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
@Service("ossFileService")
public class OSSFileServiceImpl extends ServiceImpl<OSSFileMapper, OSSFile> implements IOSSFileService {
@Value(value = "${jero.path.upload}")
private String uploadpath;
@Value(value = "${jero.path.uploadCos}")
private String uploadCospath;
/**
* 文件后缀黑名单
*/
@Value(value = "${jero.fileSuffixLimits}")
private String[] fileSuffixLimits;
// 文档拆分条款图片访问路径
@Value(value = "${jero.splitUrl}")
private String splitUrl;
@Override
public void upload(MultipartFile multipartFile) throws IOException {
String fileName = multipartFile.getOriginalFilename();
fileName = CommonUtils.getFileName(fileName);
OSSFile ossFile = new OSSFile();
ossFile.setFileName(fileName);
String url = OssBootUtil.upload(multipartFile,"upload/test");
//update-begin--Author:scott Date:20201227 forJT-361【文件预览】阿里云原生域名可以文件预览,自己映射域名kkfileview提示文件下载失败-------------------
// 返回阿里云原生域名前缀URL
ossFile.setUrl(OssBootUtil.getOriginalUrl(url));
//update-end--Author:scott Date:20201227 forJT-361【文件预览】阿里云原生域名可以文件预览,自己映射域名kkfileview提示文件下载失败-------------------
this.save(ossFile);
}
@Override
public boolean delete(OSSFile ossFile) {
try {
this.removeById(ossFile.getId());
OssBootUtil.deleteUrl(ossFile.getUrl());
}
catch (Exception ex) {
return false;
}
return true;
}
@Override
public List<OSSFile> getFileInfosByConnectId(String connectId) {
if(StringUtils.isBlank(connectId)){
return new ArrayList<>();
}
LambdaQueryWrapper<OSSFile> wrapper = new LambdaQueryWrapper<>();
if (connectId.contains(",")) {
wrapper.in(OSSFile::getConnectId, Arrays.asList(connectId.split(",")));
} else {
wrapper.eq(OSSFile::getConnectId, connectId);
}
List<OSSFile> list = this.list(wrapper);
return list;
}
@Override
public void deleteByConnectIdList(List<String> connectIdList) {
if (connectIdList.size() != 0) {
LambdaQueryWrapper<OSSFile> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.in(OSSFile::getConnectId, connectIdList);
this.remove(lambdaQueryWrapper);
}
}
/**
* 本地文件上传-文档拆分专用
*
* @param mf 文件
* @param bizPath 自定义路径
* @return
*/
@Override
public OSSFile uploadLocalForSplit(MultipartFile mf, String bizPath, String state, String cut) {
//处理文件大小,大于100M抛出异常
// long fileSize = mf.getSize() / 1024 / 1024;
// String originalFilename = mf.getOriginalFilename();
// if (fileSize >= 100) {
// if (cut.equals(LanguageEnum.CN.getValue())) {
// throw new JeroBootException(originalFilename + "文件大小超出100MB, 请压缩或降低文件质量!");
// } else {
// throw new JeroBootException(originalFilename + "File size out 100MB, Please compress or reduce file quality!");
// }
// }
OSSFile oSSFile = new OSSFile();
String ctxPath = uploadCospath;
String fileName = null;
String fileType = null;
String orgName = mf.getOriginalFilename();// 获取文件名
orgName = CommonUtils.getFileName(orgName);
if (orgName.indexOf(".") != -1) {
fileName = orgName.substring(0, orgName.lastIndexOf(".")) + "_" + System.currentTimeMillis() + orgName.substring(orgName.lastIndexOf("."));
} else {
fileName = orgName + "_" + System.currentTimeMillis();
}
String filePath = ctxPath + "/" + fileName;
fileType = orgName.substring(orgName.lastIndexOf("."));
String fileTypeStr = ".doc,.DOC,.docx,.DOCX,.xls, .XLS,.xlsx,.XLSX,.pdf,.PDF";
//判断文件类型
if ("1".equals(state)) {
//固定文件
if (!fileTypeStr.contains(fileType)) {
if (cut.equals(LanguageEnum.CN.getValue())) {
throw new JeroBootException("只能够上传pdf,word,excel类型的文件。请重新选择文件!");
} else {
throw new JeroBootException("Only upload pdf,word,excel type of file Please select the file again");
}
}
} else {
if (CommonUtils.limitFileSuffix(orgName, fileSuffixLimits)) {
if (cut.equals(LanguageEnum.CN.getValue())) {
throw new JeroBootException("不能上传" + StringUtils.join(fileSuffixLimits, ",") + "类型的文件。请重新选择文件!");
} else {
throw new JeroBootException("Can't upload" + StringUtils.join(fileSuffixLimits, ",") + "type of file Please select the file again");
}
}
}
if (StringUtils.isNotEmpty(fileType)) {
String[] fileTypeArr = {".doc", ".DOC", ".txt", ".TXT", ".docx", ".DOCX",
".xls", ".XLS", ".xlsx", ".XLSX", ".pdf", ".PDF", ".png", ".PNG",
".jfif", ".JFIF", ".pjpeg", ".PJPEG", ".jpeg", ".JPEG", ".pjp", ".PJP",
".jpg", ".JPG", ".swf", ".SWF", ".bmp", ".BMP", ".rar", ".RAR", ".zip", ".ZIP", ".ppt", ".PPT", ".pptx", ".PPTX", ".csv", ".CSV"};
boolean flag = true;
for (String fileTypeTemp : fileTypeArr) {
if (fileTypeTemp.equalsIgnoreCase(fileType)) {
flag = false;
}
}
if (flag) {
if (cut.equals(LanguageEnum.CN.getValue())) {
throw new JeroBootException("只能够上传pdf/word/excel/csv/ppt/txt/zip/rar/静态图片类型的文件。请重新选择文件!");
} else {
throw new JeroBootException("Only upload pdf/word/excel/csv/ppt/txt/zip/rar/Static image type file. Please re select the file!");
}
}
}
// 将文件上传至腾讯云 cos
MinioUtil.upload(mf, filePath);
LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
//存入文件表
oSSFile.setFileName(orgName);
oSSFile.setId(UuidUtils.getUUID());
oSSFile.setUrl(filePath);
oSSFile.setCreateBy(loginUser.getUsername());
oSSFile.setCreateTime(new Date());
this.save(oSSFile);
// 文件路径做特殊处理
// BASE64Encoder base64Encoder = new BASE64Encoder();
// String encode = base64Encoder.encode(filePath.getBytes(StandardCharsets.UTF_8));
String imgUrl = splitUrl + "/jero-boot/sys/split/file/getImage?fileUrl=" + filePath;
oSSFile.setUrl(imgUrl);
return oSSFile;
}
@Override
public List<OSSFile> getFileInfos(String id) {
if (MyStringUtils.isEmpty(id)) {
return new ArrayList<>();
}
LambdaQueryWrapper<OSSFile> wrapper = new LambdaQueryWrapper<>();
wrapper.in(OSSFile::getId, id.split(","));
wrapper.orderByAsc(OSSFile::getCreateTime);
List<OSSFile> list = this.list(wrapper);
if (list.size() == 0) {
LambdaQueryWrapper<OSSFile> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.in(OSSFile::getConnectId, id.split(","));
lambdaQueryWrapper.orderByAsc(OSSFile::getCreateTime);
list = this.list(lambdaQueryWrapper);
}
return list;
}
@Override
public List<OSSFile> getFileInfoAll(String id) {
if (MyStringUtils.isEmpty(id)) {
return new ArrayList<>();
}
LambdaQueryWrapper<OSSFile> wrapper = new LambdaQueryWrapper<>();
wrapper.in(OSSFile::getId, id.split(","));
List<OSSFile> list = this.list(wrapper);
LambdaQueryWrapper<OSSFile> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.in(OSSFile::getConnectId, id.split(","));
list.addAll(this.list(lambdaQueryWrapper));
return list;
}
@Override
public void updateFileInfo(List<OSSFile> ossFileList) {
this.updateBatchById(ossFileList);
}
/**
* 本地文件上传 cos
*
* @param mf 文件
* @param bizPath 自定义路径
* @return
*/
@Override
public OSSFile uploadLocalOfCos(MultipartFile mf, String bizPath, String state, String cut) {
//处理文件大小,大于100M抛出异常
// long fileSize = mf.getSize() / 1024 / 1024;
// String originalFilename = mf.getOriginalFilename();
// if (fileSize >= 100) {
// if (cut.equals(LanguageEnum.CN.getValue())) {
// throw new JeroBootException(originalFilename + "文件大小超出100MB, 请压缩或降低文件质量!");
// } else {
// throw new JeroBootException(originalFilename + "File size out 100MB, Please compress or reduce file quality!");
// }
// }
OSSFile oSSFile = new OSSFile();
String ctxPath = uploadCospath;
if (StringUtils.isNotBlank(bizPath)) {
ctxPath += bizPath;
}
String fileName = null;
String fileType = null;
String orgName = mf.getOriginalFilename();// 获取文件名
orgName = CommonUtils.getFileName(orgName);
if (orgName.indexOf(".") != -1) {
fileName = orgName.substring(0, orgName.lastIndexOf(".")) + "_" + System.currentTimeMillis() + orgName.substring(orgName.lastIndexOf("."));
} else {
fileName = orgName + "_" + System.currentTimeMillis();
}
String filePath = ctxPath + "/" + fileName;
fileType = orgName.substring(orgName.lastIndexOf("."));
String fileTypeStr = ".doc,.DOC,.docx,.DOCX,.xls, .XLS,.xlsx,.XLSX,.pdf,.PDF";
//判断文件类型
if ("1".equals(state)) {
//固定文件
if (!fileTypeStr.contains(fileType)) {
if (cut.equals(LanguageEnum.CN.getValue())) {
throw new JeroBootException("只能够上传pdf,word,excel类型的文件。请重新选择文件!");
} else {
throw new JeroBootException("Only upload pdf,word,excel type of file Please select the file again");
}
}
} else if ("2".equals(state)) { // 认证-参数导出模板上传 专用
String fileTypeStrTwo = ".docx,.DOCX,.xlsx,.XLSX";
List<String> fileTypeStrTwoList = Arrays.asList(fileTypeStrTwo.split(","));
//固定文件
if (!fileTypeStrTwoList.contains(fileType)) {
if (cut.equals(LanguageEnum.CN.getValue())) {
throw new JeroBootException("只能够上传.docx,.DOCX,.xlsx,.XLSX后缀类型的文件。请重新选择文件!");
} else {
throw new JeroBootException("Only upload .docx,.DOCX,.xlsx,.XLSX suffix type of file Please select the file again");
}
}
} else {
if (CommonUtils.limitFileSuffix(orgName, fileSuffixLimits)) {
if (cut.equals(LanguageEnum.CN.getValue())) {
throw new JeroBootException("不能上传" + StringUtils.join(fileSuffixLimits, ",") + "类型的文件。请重新选择文件!");
} else {
throw new JeroBootException("Can't upload" + StringUtils.join(fileSuffixLimits, ",") + "type of file Please select the file again");
}
}
}
if (StringUtils.isNotEmpty(fileType)) {
String[] fileTypeArr = {".doc", ".DOC", ".txt", ".TXT", ".docx", ".DOCX",
".xls", ".XLS", ".xlsx", ".XLSX", ".pdf", ".PDF", ".png", ".PNG",
".jfif", ".JFIF", ".pjpeg", ".PJPEG", ".jpeg", ".JPEG", ".pjp", ".PJP",
".jpg", ".JPG", ".swf", ".SWF", ".bmp", ".BMP", ".rar", ".RAR", ".zip",
".ZIP", ".ppt", ".PPT", ".pptx", ".PPTX", ".csv", ".CSV", ".gif", ".GIF",
".msg", ".MSG"};
boolean flag = true;
for (String fileTypeTemp : fileTypeArr) {
if (fileTypeTemp.equalsIgnoreCase(fileType)) {
flag = false;
}
}
if (flag) {
if (cut.equals(LanguageEnum.CN.getValue())) {
throw new JeroBootException("只能够上传pdf/word/excel/csv/ppt/txt/zip/rar/msg/gif/静态图片类型的文件。请重新选择文件!");
} else {
throw new JeroBootException("Only upload pdf/word/excel/csv/ppt/txt/zip/rar/msg/gif/Static image type file. Please re select the file!");
}
}
}
// 将文件上传至腾讯云 cos
MinioUtil.upload(mf, filePath);
LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
//存入文件表
oSSFile.setFileName(orgName);
oSSFile.setId(UuidUtils.getUUID());
oSSFile.setUrl(filePath);
oSSFile.setCreateBy(loginUser.getUsername());
oSSFile.setCreateTime(new Date());
this.save(oSSFile);
oSSFile.setUrl(null);
return oSSFile;
}
}