From e4d0113d214e05dbb6a36a111bc125202ddfd1ed Mon Sep 17 00:00:00 2001 From: xuhy <3313886187@qq.com> Date: 星期四, 06 三月 2025 10:54:46 +0800 Subject: [PATCH] Merge branch 'xizang-changyun' of https://gitee.com/xiaochen991015/xizang --- ruoyi-admin/src/main/java/com/ruoyi/web/controller/tool/TencentCosUtil.java | 215 +++++++++++------ ruoyi-admin/src/main/resources/application-test.yml | 6 ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/COSController.java | 155 ++++++++++++ ruoyi-admin/pom.xml | 10 ruoyi-admin/src/main/java/com/ruoyi/web/core/config/FileUploaderConfig.java | 67 +++++ ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/BankOutController.java | 5 ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TBillServiceImpl.java | 4 ruoyi-system/src/main/resources/mapper/system/TBillMapper.xml | 10 ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysFileServiceImpl.java | 42 +++ ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/SysFileController.java | 22 + ruoyi-admin/src/main/java/com/ruoyi/web/controller/tool/PdfUtils.java | 2 ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysFileMapper.java | 16 + ruoyi-system/src/main/resources/mapper/system/TFlowManagementMapper.xml | 8 ruoyi-admin/src/main/resources/application-prod.yml | 2 ruoyi-system/src/main/java/com/ruoyi/system/model/TFile.java | 81 ++++++ ruoyi-common/src/main/java/com/ruoyi/common/config/FileUploadConfig.java | 2 ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java | 2 ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/TokenService.java | 8 ruoyi-admin/src/main/java/com/ruoyi/web/controller/tool/WordUtil.java | 2 ruoyi-system/src/main/java/com/ruoyi/system/service/SysFileService.java | 17 + ruoyi-system/src/main/resources/mapper/system/TBankFlowMapper.xml | 6 21 files changed, 570 insertions(+), 112 deletions(-) diff --git a/ruoyi-admin/pom.xml b/ruoyi-admin/pom.xml index 5741488..96e7388 100644 --- a/ruoyi-admin/pom.xml +++ b/ruoyi-admin/pom.xml @@ -32,11 +32,11 @@ <version>31.1-jre</version> <!-- 请根据需要选择合适的版本 --> </dependency> <!-- spring-boot-devtools --> -<!-- <dependency>--> -<!-- <groupId>org.springframework.boot</groupId>--> -<!-- <artifactId>spring-boot-devtools</artifactId>--> -<!-- <optional>true</optional> <!– 表示依赖不会传递 –>--> -<!-- </dependency>--> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-devtools</artifactId> + <optional>true</optional> <!-- 表示依赖不会传递 --> + </dependency> <!-- swagger3--> <dependency> diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/BankOutController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/BankOutController.java index c474d4d..bcb7af3 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/BankOutController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/BankOutController.java @@ -29,7 +29,10 @@ return result.getBack(); } - + @PostMapping(value = "bills") + public @ResponseBody String bills(HttpServletRequest request){ + return ""; + } } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/COSController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/COSController.java index 0702deb..6aa9856 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/COSController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/COSController.java @@ -1,19 +1,33 @@ package com.ruoyi.web.controller.api; +import com.alibaba.fastjson2.JSON; +import com.ruoyi.common.config.FileUploadConfig; +import com.ruoyi.common.constant.CacheConstants; import com.ruoyi.common.core.domain.R; +import com.ruoyi.common.core.redis.RedisCache; +import com.ruoyi.common.utils.StringUtils; +import com.ruoyi.framework.web.service.TokenService; +import com.ruoyi.system.model.TFile; +import com.ruoyi.system.service.SysFileService; +import com.ruoyi.system.service.impl.SysFileServiceImpl; import com.ruoyi.web.controller.tool.TencentCosUtil; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; -import java.io.OutputStream; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.PrintWriter; +import java.net.URLEncoder; /** * @author HJL @@ -23,18 +37,145 @@ @RestController @RequestMapping("/cos") @Api(tags = "公共-文件上传") +@Slf4j public class COSController { @Resource private TencentCosUtil tencentCosUtil; + @Autowired + SysFileService sysFileService; + + @Autowired + FileUploadConfig fileUploadConfig; + + @Autowired + TokenService tokenService; + + public String getLocalUrlPrefix(){ + ServletRequestAttributes servletRequestAttributes = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()); + if (servletRequestAttributes==null || servletRequestAttributes.getRequest()==null){ + return fileUploadConfig.getFileUrlPrefix(); + } + HttpServletRequest request = servletRequestAttributes.getRequest(); + StringBuffer url = new StringBuffer(); + url.append(request.getScheme()).append("://") + .append(request.getServerName()) + .append((request.getServerPort() == 80 ? "" : ":" + request.getServerPort())) + .append(request.getContextPath()); + return url.toString(); + } + + public String getLocalFileUrlPrefix(String fileId){ + String token = tokenService.getLoginUser().getToken(); + StringBuffer url = new StringBuffer(); + url.append(getLocalUrlPrefix()) + .append("/cos/get/").append(fileId).append("?s=").append(URLEncoder.encode(token)) + ; + return url.toString(); + } + + + + + + + public static void failResponse(String message){ + ServletRequestAttributes servletRequestAttributes = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()); + HttpServletResponse response = servletRequestAttributes.getResponse(); + String failResult = JSON.toJSONString(R.fail(message)); + //设置编码格式 + response.setCharacterEncoding("UTF-8"); + response.setContentType("application/json;charset=UTF-8"); + PrintWriter pw = null; + try { + pw = response.getWriter(); + pw.write(failResult); + pw.flush(); + } catch (IOException e) { + log.error("io异常"); + }finally { + if (pw!=null) { + pw.close(); + } + } + + } + @Autowired + private RedisCache redisCache; + + @GetMapping("get/{fileId}") + public void get(@PathVariable("fileId") String fileid,@RequestParam("s") String s){ + if (StringUtils.isEmpty(fileid)){ + failResponse("文件ID不能为空"); + return; + } + if (StringUtils.isEmpty(s)){ + failResponse("token不能为空"); + return; + } + Object object = redisCache.getCacheObject(CacheConstants.LOGIN_TOKEN_KEY + s); + if (object==null){ + failResponse("用户登录已失效"); + return; + } + TFile file = sysFileService.getById(fileid); + if (file==null){ + failResponse("图片不存在"); + return; + } + tencentCosUtil.download(file); + } + + + @GetMapping("get/file") + public void getFile(@RequestParam("fileUrl") String fileUrl,@RequestParam("s") String s){ + if (StringUtils.isEmpty(fileUrl)){ + failResponse("文件路径不能为空"); + return; + } + if (StringUtils.isEmpty(s)){ + failResponse("token不能为空"); + return; + } + Object object = redisCache.getCacheObject(CacheConstants.LOGIN_TOKEN_KEY + s); + if (object==null){ + failResponse("用户登录已失效"); + return; + } + tencentCosUtil.download(fileUrl); + } + + /** + * 新上传接口,下一版更新 + * @param file + * @param folder 上传到cos的文件目录:如/contract/ + * @return + */ + @PostMapping("/uploadnew") + @ApiOperation(value = "文件上传,带上传目录,返回文件ID", tags = "公共-文件上传") + @ApiImplicitParams({ + @ApiImplicitParam(value = "文件", name = "file", dataType = "MultipartFile", required = true) + }) + public R<TFile> uploadnew(@RequestParam("file") MultipartFile file, @RequestParam("folder") String folder) { + TFile tFile = tencentCosUtil.upload(file,folder); + tFile.setFileUrl(getLocalFileUrlPrefix(tFile.getId())); + return R.ok(tFile); + } + + /** + * + * @param file + * @param + * @return + */ @PostMapping("/upload") @ApiOperation(value = "文件上传", tags = "公共-文件上传") @ApiImplicitParams({ @ApiImplicitParam(value = "文件", name = "file", dataType = "MultipartFile", required = true) }) - public R<String> upload(@RequestParam("file") MultipartFile file) { - String url = tencentCosUtil.upLoadFile(file); + public R<String> upload(@RequestParam("file") MultipartFile file,@RequestParam("folder") String folder) { + String url = tencentCosUtil.upLoadFile(file,folder); return R.ok(url, url); } @PostMapping("/downloadImg") diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/SysFileController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/SysFileController.java new file mode 100644 index 0000000..b213e84 --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/SysFileController.java @@ -0,0 +1,22 @@ +package com.ruoyi.web.controller.api; + + +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * <p> + * 文件列表 前端控制器 + * </p> + * + * @author yupeng + * @since 2025-03-05 + */ +@RestController +@RequestMapping("/sys-file") +public class SysFileController { + + + +} + diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/tool/PdfUtils.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/tool/PdfUtils.java index 71c5a6c..c786d9b 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/tool/PdfUtils.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/tool/PdfUtils.java @@ -50,7 +50,7 @@ //上传图片 byte2File(stream.toByteArray(),filePath + "/pdf",fileName.substring(0,fileName.lastIndexOf(".")) + ".pdf"); MultipartFile multipartFile = convertToMultipartFile(stream,fileName.substring(0,fileName.lastIndexOf(".")) ); - String s = tencentCosUtil.upLoadFile(multipartFile); + String s = tencentCosUtil.upLoadFile(multipartFile,"/wordToPdf"); stream.close(); inputStream.close(); diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/tool/TencentCosUtil.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/tool/TencentCosUtil.java index 1d02134..3834733 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/tool/TencentCosUtil.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/tool/TencentCosUtil.java @@ -1,20 +1,23 @@ package com.ruoyi.web.controller.tool; +import cn.hutool.core.date.DateUtil; import com.qcloud.cos.COSClient; import com.qcloud.cos.ClientConfig; import com.qcloud.cos.auth.BasicCOSCredentials; import com.qcloud.cos.auth.COSCredentials; -import com.qcloud.cos.exception.CosClientException; -import com.qcloud.cos.exception.CosServiceException; import com.qcloud.cos.http.HttpProtocol; import com.qcloud.cos.model.COSObject; -import com.qcloud.cos.model.GetObjectRequest; import com.qcloud.cos.model.ObjectMetadata; import com.qcloud.cos.model.PutObjectResult; import com.qcloud.cos.region.Region; -import com.qcloud.cos.utils.IOUtils; import com.ruoyi.common.utils.WebUtils; -import org.springframework.beans.factory.annotation.Value; +import com.ruoyi.system.model.TFile; +import com.ruoyi.system.service.SysFileService; +import com.ruoyi.system.service.impl.SysFileServiceImpl; +import com.ruoyi.web.core.config.FileUploaderConfig; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.web.multipart.MultipartFile; @@ -25,44 +28,17 @@ import java.io.InputStream; import java.io.OutputStream; import java.util.Base64; +import java.util.Date; import java.util.UUID; + +import static cn.hutool.core.date.DatePattern.NORM_DATE_FORMAT; /** * @author HJL */ @Component +@Slf4j public class TencentCosUtil { - - /** - * COS的SecretId - */ - @Value("${cos.client.accessKey}") - private String secretId; - /** - * COS的SecretKey - */ - @Value("${cos.client.secretKey}") - private String secretKey; - /** - * 文件上传后访问路径的根路径,后面要最佳文件名字与类型 - */ - @Value("${cos.client.rootSrc}") - private String rootSrc; - /** - * 上传的存储桶的地域 - */ - @Value("${cos.client.bucketAddr}") - private String bucketAddr; - /** - * 存储桶的名字,是自己在存储空间自己创建的,我创建的名字是:qq-test-1303****** - */ - @Value("${cos.client.bucket}") - private String bucketName; - /** - * 文件存放位置 - */ - @Value("${cos.client.location}") - private String location; /** * 1.调用静态方法getCosClient()就会获得COSClient实例 @@ -70,16 +46,64 @@ * * @return COSClient实例 */ - private COSClient getCosClient() { - // 1 初始化用户身份信息(secretId, secretKey)。 - COSCredentials cred = new BasicCOSCredentials(secretId, secretKey); - // 2.1 设置存储桶的地域(上文获得) - Region region = new Region(bucketAddr); - ClientConfig clientConfig = new ClientConfig(region); - // 2.2 使用https协议传输 - clientConfig.setHttpProtocol(HttpProtocol.https); - // 生成 cos 客户端 - return new COSClient(cred, clientConfig); + + @Autowired + COSClient cosClient; + + @Autowired + FileUploaderConfig cosConfig; + + @Autowired + SysFileService sysFileService; + + + /** + * 上传文件,并存入sys_file,返回文件的主键ID + * @param file + * @param folder 格式:/xxxxx,/xxxx/xxxx ,最后不用加斜杠 + * @return + */ + public TFile upload(MultipartFile file, String folder){ + try { + // 获取上传的文件的输入流 + InputStream inputStream = file.getInputStream(); + // 避免文件覆盖,获取文件的原始名称,如123.jpg,然后通过截取获得文件的后缀,也就是文件的类型 + + String originalFilename = file.getOriginalFilename(); + + //获取文件的类型 + String fileType = originalFilename.substring(originalFilename.lastIndexOf(".")); + //使用UUID工具 创建唯一名称,放置文件重名被覆盖,在拼接上上命令获取的文件类型 + String fileName = UUID.randomUUID() + fileType; + String filePath = (StringUtils.isNotEmpty(folder)? + folder+"/" + :"/default/") + DateUtil.format(new Date(),NORM_DATE_FORMAT)+"/"+fileName; + // 指定文件上传到 COS 上的路径,即对象键。最终文件会传到存储桶名字中的images文件夹下的fileName名字 + filePath = cosConfig.getLocation() + filePath; + // 创建上传Object的Metadata + ObjectMetadata objectMetadata = new ObjectMetadata(); + // - 使用输入流存储,需要设置请求长度 + objectMetadata.setContentLength(inputStream.available()); + // - 设置缓存 + objectMetadata.setCacheControl("no-cache"); + // - 设置Content-Type + objectMetadata.setContentType(fileType); + //上传文件 + cosClient.putObject(cosConfig.getBucketName(), filePath, inputStream, objectMetadata); + TFile tFile = new TFile(); + tFile.setFileName(filePath); + tFile.setRealName(originalFilename); + tFile.setFileType(fileType); + tFile.setUrl(cosConfig.getRootSrc()+filePath); + tFile.setContentType(file.getContentType()); + tFile.setFileSize(file.getSize()); + sysFileService.save(tFile); + return tFile; + } catch (Exception e) { + log.error("上传文件发生异常",e); + // 发生IO异常、COS连接异常等,返回空 + return null; + } } /** @@ -88,7 +112,7 @@ * @param file * @return 返回文件的浏览全路径 */ - public String upLoadFile(MultipartFile file) { + public String upLoadFile(MultipartFile file,String folder) { try { // 获取上传的文件的输入流 InputStream inputStream = file.getInputStream(); @@ -99,7 +123,11 @@ //使用UUID工具 创建唯一名称,放置文件重名被覆盖,在拼接上上命令获取的文件类型 String fileName = UUID.randomUUID() + fileType; // 指定文件上传到 COS 上的路径,即对象键。最终文件会传到存储桶名字中的images文件夹下的fileName名字 - String key = location+"/" + fileName; + String filePath = (StringUtils.isNotEmpty(folder)? + folder+"/" + :"/default/") + DateUtil.format(new Date(),NORM_DATE_FORMAT)+"/"+fileName; + + filePath = cosConfig.getLocation()+"/" + filePath; // 创建上传Object的Metadata ObjectMetadata objectMetadata = new ObjectMetadata(); // - 使用输入流存储,需要设置请求长度 @@ -109,14 +137,13 @@ // - 设置Content-Type objectMetadata.setContentType(fileType); //上传文件 - PutObjectResult putResult = getCosClient().putObject(bucketName, key, inputStream, objectMetadata); + PutObjectResult putResult = cosClient.putObject(cosConfig.getBucketName(), filePath, inputStream, objectMetadata); // 创建文件的网络访问路径 - String url = rootSrc + key; - //关闭 cosClient,并释放 HTTP 连接的后台管理线程 - getCosClient().shutdown(); + String url = cosConfig.getRootSrc() + filePath; return url; } catch (Exception e) { e.printStackTrace(); + log.error("上传文件发生异常",e); // 发生IO异常、COS连接异常等,返回空 return null; } @@ -129,20 +156,11 @@ */ public void downLoadFile(String file) { HttpServletResponse response = WebUtils.response(); - String replace = file.replace(rootSrc, ""); + String replace = file.replace(cosConfig.getRootSrc(), ""); response.setHeader("Access-Control-Expose-Headers","File-Type"); - COSCredentials cred = new BasicCOSCredentials( - secretId, - secretKey); - // 2.1 设置存储桶的地域(上文获得) - Region region = new Region(bucketAddr); - ClientConfig clientConfig = new ClientConfig(region); - // 2.2 使用https协议传输 - clientConfig.setHttpProtocol(HttpProtocol.https); - COSClient cosClient = new COSClient(cred, clientConfig); try { // 5. 下载文件并获取输入流 - InputStream inputStream = cosClient.getObject(bucketName, replace).getObjectContent(); + InputStream inputStream = cosClient.getObject(cosConfig.getBucketName(), replace).getObjectContent(); ServletOutputStream outputStream = response.getOutputStream(); // 6. 处理输入流,例如读取内容或保存到本地文件 // 这里仅作示例,实际应用中需要根据需求处理输入流 @@ -154,26 +172,15 @@ } } catch (Exception e) { e.printStackTrace(); - } finally { - // 7. 关闭输入流 - cosClient.shutdown(); + log.error("下载文件发生异常",e); } } public String downLoadFileImg(String file) { byte[] data = null; - String replace = file.replace(rootSrc, ""); - COSCredentials cred = new BasicCOSCredentials( - secretId, - secretKey); - // 2.1 设置存储桶的地域(上文获得) - Region region = new Region(bucketAddr); - ClientConfig clientConfig = new ClientConfig(region); - // 2.2 使用https协议传输 - clientConfig.setHttpProtocol(HttpProtocol.https); - COSClient cosClient = new COSClient(cred, clientConfig); + String replace = file.replace(cosConfig.getRootSrc(), ""); try { // 5. 下载文件并获取输入流 - InputStream inputStream = cosClient.getObject(bucketName, replace).getObjectContent(); + InputStream inputStream = cosClient.getObject(cosConfig.getBucketName(), replace).getObjectContent(); ByteArrayOutputStream swapStream = new ByteArrayOutputStream(); // 6. 处理输入流,例如读取内容或保存到本地文件 byte[] buffer = new byte[1024]; @@ -185,10 +192,60 @@ data = swapStream.toByteArray(); } catch (Exception e) { e.printStackTrace(); + log.error("下载图片发生异常",e); } finally { - // 7. 关闭输入流 - cosClient.shutdown(); } return Base64.getEncoder().encodeToString(data); } + + public void download(String fileUrl) { + HttpServletResponse response = WebUtils.response(); + fileUrl = fileUrl.replace(cosConfig.getRootSrc(), ""); + + // 5. 下载文件并获取输入流 + COSObject object = cosClient.getObject(cosConfig.getBucketName(),fileUrl); + try ( + InputStream is = object.getObjectContent(); + OutputStream os = response.getOutputStream() + ) { + String fileName = fileUrl.substring(fileUrl.lastIndexOf("/")); + response.setContentType(object.getObjectMetadata().getContentType() + ";charset=utf-8"); + String filename = new String(fileName.getBytes("UTF-8"), "ISO-8859-1"); + response.addHeader("Content-Disposition", "attachment;filename=" + filename); + response.addHeader("Content-Length", "" + object.getObjectMetadata().getContentLength()); + int len = 0; + byte[] buffer = new byte[2048]; + while ((len = is.read(buffer)) > 0) { + os.write(buffer, 0, len); + } + os.flush(); + } catch (IOException e) { + log.error("读取cos图片发生异常", e); + } + } + + public void download(TFile file) { + HttpServletResponse response = WebUtils.response(); + // 5. 下载文件并获取输入流 + COSObject object = cosClient.getObject(cosConfig.getBucketName(), file.getFileName()); + try ( + InputStream is = object.getObjectContent(); + OutputStream os = response.getOutputStream() + ) { + response.setContentType(file.getContentType() + ";charset=utf-8"); + String filename = new String(file.getRealName().getBytes("UTF-8"), "ISO-8859-1"); + response.addHeader("Content-Disposition", "attachment;filename=" + filename); + response.addHeader("Content-Length", "" + file.getFileSize()); + int len = 0; + byte[] buffer = new byte[2048]; + while ((len = is.read(buffer)) > 0) { + os.write(buffer, 0, len); + } + os.flush(); + } catch (IOException e) { + log.error("读取cos图片发生异常", e); + } + } + + } \ No newline at end of file diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/tool/WordUtil.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/tool/WordUtil.java index 85a55ce..ce14b96 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/tool/WordUtil.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/tool/WordUtil.java @@ -101,7 +101,7 @@ fis.read(fileContent); } MultipartFile mockMultipartFile = new MockMultipartFile(encodedFileName+".doc", fileContent); - String s = tencentCosUtil.upLoadFile(mockMultipartFile); + String s = tencentCosUtil.upLoadFile(mockMultipartFile,"/wordGenerate"); return s; } catch (IOException | TemplateException e) { log.error("生成Word文档异常,异常原因:{}", e.getMessage(), e); diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/core/config/FileUploaderConfig.java b/ruoyi-admin/src/main/java/com/ruoyi/web/core/config/FileUploaderConfig.java new file mode 100644 index 0000000..d87ab0d --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/core/config/FileUploaderConfig.java @@ -0,0 +1,67 @@ +package com.ruoyi.web.core.config; + +import com.qcloud.cos.COSClient; +import com.qcloud.cos.ClientConfig; +import com.qcloud.cos.auth.BasicCOSCredentials; +import com.qcloud.cos.auth.COSCredentials; +import com.qcloud.cos.http.HttpProtocol; +import com.qcloud.cos.region.Region; +import lombok.Data; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +@Data +public class FileUploaderConfig { + + /** + * COS的SecretId + */ + @Value("${cos.client.accessKey}") + private String secretId; + /** + * COS的SecretKey + */ + @Value("${cos.client.secretKey}") + private String secretKey; + /** + * 文件上传后访问路径的根路径,后面要最佳文件名字与类型 + */ + @Value("${cos.client.rootSrc}") + private String rootSrc; + /** + * 上传的存储桶的地域 + */ + @Value("${cos.client.bucketAddr}") + private String bucketAddr; + /** + * 存储桶的名字,是自己在存储空间自己创建的,我创建的名字是:qq-test-1303****** + */ + @Value("${cos.client.bucket}") + private String bucketName; + /** + * 文件存放位置 + */ + @Value("${cos.client.location}") + private String location; + + @Value("${file.url.prefix}") + private String fileUrlPrefix; + + + @Bean + public COSClient cosClient() { + // 1 初始化用户身份信息(secretId, secretKey)。 + COSCredentials cred = new BasicCOSCredentials(secretId, secretKey); + // 2.1 设置存储桶的地域(上文获得) + Region region = new Region(bucketAddr); + ClientConfig clientConfig = new ClientConfig(region); + // 2.2 使用https协议传输 + clientConfig.setHttpProtocol(HttpProtocol.https); + // 生成 cos 客户端 + return new COSClient(cred, clientConfig); + } + + +} diff --git a/ruoyi-admin/src/main/resources/application-prod.yml b/ruoyi-admin/src/main/resources/application-prod.yml index caf8b52..99a087e 100644 --- a/ruoyi-admin/src/main/resources/application-prod.yml +++ b/ruoyi-admin/src/main/resources/application-prod.yml @@ -213,4 +213,4 @@ bucket: xzgttest-1305134071 bucketAddr: ap-chengdu rootSrc: https://xzgttest-1305134071.cos.ap-chengdu.myqcloud.com/ - location: xizang \ No newline at end of file + location: /xizang \ No newline at end of file diff --git a/ruoyi-admin/src/main/resources/application-test.yml b/ruoyi-admin/src/main/resources/application-test.yml index ec0ed40..f4b61c4 100644 --- a/ruoyi-admin/src/main/resources/application-test.yml +++ b/ruoyi-admin/src/main/resources/application-test.yml @@ -18,7 +18,7 @@ # 开发环境配置 server: # 服务器的HTTP端口,默认为8080 - port: 8081 + port: 8080 servlet: # 应用的访问路径 context-path: / @@ -199,6 +199,8 @@ qrLocation: /file/qrCode/ accessPath: /file/ allowExt: .jpg|.png|.gif|.jpeg|.doc|.docx|.apk|.MP4|.mp4|.pdf|.PDF + url: + prefix: http://localhost:${server.port}${server.servlet.context-path} wx: conf: appId: wxe91f1af7638aa5dd @@ -219,7 +221,7 @@ bucket: xzgttest-1305134071 bucketAddr: ap-chengdu rootSrc: https://xzgttest-1305134071.cos.ap-chengdu.myqcloud.com/ - location: xizang + location: /xizang sms: enable: true appId: 1400957506 diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/config/FileUploadConfig.java b/ruoyi-common/src/main/java/com/ruoyi/common/config/FileUploadConfig.java index 3a8b0ed..32c0b2a 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/config/FileUploadConfig.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/config/FileUploadConfig.java @@ -18,4 +18,6 @@ private String allowExt; private String location; private String qrLocation; + private String fileUrlPrefix; + } diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java index 5f90047..b4118dc 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java @@ -119,7 +119,7 @@ "/operations/getBySingleNum/**", "/user/getUserInfoByNumber/**", "/wxLogin/**", - "/open/**" + "/open/**","/cos/get/**" ).permitAll() // 静态资源,可匿名访问 .antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll() diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/TokenService.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/TokenService.java index a7a640b..206c1a4 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/TokenService.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/TokenService.java @@ -204,6 +204,14 @@ refreshToken(loginUser); } } + + + public boolean verifyToken(String token) + { + Claims claims = parseToken(token); + + return true; + } /** * 小程序验证令牌有效期,相差不足20分钟,自动刷新缓存 * diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysFileMapper.java b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysFileMapper.java new file mode 100644 index 0000000..f5e0298 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysFileMapper.java @@ -0,0 +1,16 @@ +package com.ruoyi.system.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.ruoyi.system.model.TFile; + +/** + * <p> + * 文件列表 Mapper 接口 + * </p> + * + * @author yupeng + * @since 2025-03-05 + */ +public interface SysFileMapper extends BaseMapper<TFile> { + +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/model/TFile.java b/ruoyi-system/src/main/java/com/ruoyi/system/model/TFile.java new file mode 100644 index 0000000..93be19a --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/model/TFile.java @@ -0,0 +1,81 @@ +package com.ruoyi.system.model; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; +import java.time.LocalDateTime; + +/** + * <p> + * 文件列表 + * </p> + * + * @author yupeng + * @since 2025-03-05 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@TableName("t_file") +@ApiModel(value="t_file对象", description="文件列表") +public class TFile implements Serializable { + + private static final long serialVersionUID = 1L; + + @TableId("id") + private String id; + + @ApiModelProperty(value = "文件分类,0.用户文件 1.钉钉文件") + @TableField("type") + private Integer type; + + @TableField("content_type") + private String contentType; + + @ApiModelProperty(value = "文件类型(后缀)") + @TableField("file_type") + private String fileType; + + @ApiModelProperty(value = "文件真实名称") + @TableField("real_name") + private String realName; + + @ApiModelProperty(value = "文件名称") + @TableField("file_name") + private String fileName; + + @ApiModelProperty(value = "文件大小") + @TableField("file_size") + private Long fileSize; + + @TableField("create_time") + private LocalDateTime createTime; + + @ApiModelProperty(value = "地址路径或者url") + @TableField("url") + private String url; + + @ApiModelProperty(value = "上传人ID") + @TableField("creator_id") + private String creatorId; + + @ApiModelProperty(value = "是否需要校验权限") + @TableField("need_auth") + private Boolean needAuth; + + @ApiModelProperty(value = "是否有效") + @TableField("valid") + private Boolean valid; + /** + * 返回文件对象时自动组装文件访问路径 + */ + @TableField(exist = false) + @ApiModelProperty("文件访问路径") + private String fileUrl; + +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/SysFileService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/SysFileService.java new file mode 100644 index 0000000..63b9bce --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/SysFileService.java @@ -0,0 +1,17 @@ +package com.ruoyi.system.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.ruoyi.system.model.TFile; + +/** + * <p> + * 文件列表 服务类 + * </p> + * + * @author yupeng + * @since 2025-03-05 + */ +public interface SysFileService extends IService<TFile> { + + +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysFileServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysFileServiceImpl.java new file mode 100644 index 0000000..5cd94fd --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysFileServiceImpl.java @@ -0,0 +1,42 @@ +package com.ruoyi.system.service.impl; + +import com.alibaba.fastjson2.JSON; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.ruoyi.common.config.FileUploadConfig; +import com.ruoyi.common.core.domain.R; +import com.ruoyi.system.mapper.SysFileMapper; +import com.ruoyi.system.model.TFile; +import com.ruoyi.system.service.SysFileService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.core.token.TokenService; +import org.springframework.stereotype.Service; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.PrintWriter; +import java.net.URLEncoder; + +/** + * <p> + * 文件列表 服务实现类 + * </p> + * + * @author yupeng + * @since 2025-03-05 + */ +@Service +@Slf4j +public class SysFileServiceImpl extends ServiceImpl<SysFileMapper, TFile> implements SysFileService { + + @Autowired + FileUploadConfig fileUploadConfig; + + + + + +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TBillServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TBillServiceImpl.java index e70e065..ecc4884 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TBillServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TBillServiceImpl.java @@ -252,7 +252,7 @@ throw new ServiceException("实付金额不能高于于流水可抵扣剩余金额"); } //如果实付金额大于欠费金额 - if (dto.getAmount().compareTo(bill.getOutstandingMoney())>=0){ + if (dto.getAmount().compareTo(bill.getOutstandingMoney())>0){ throw new ServiceException("实付金额不能高于该账单欠费金额"); } @@ -464,7 +464,7 @@ throw new ServiceException("实付金额不能高于于流水可抵扣剩余金额"); } //如果实付金额大于欠费金额 - if (dto.getAmount().compareTo(bill.getOutstandingMoney())>=0){ + if (dto.getAmount().compareTo(bill.getOutstandingMoney())>0){ throw new ServiceException("实付金额不能高于该账单欠费金额"); } } diff --git a/ruoyi-system/src/main/resources/mapper/system/TBankFlowMapper.xml b/ruoyi-system/src/main/resources/mapper/system/TBankFlowMapper.xml index c72c8f5..8995310 100644 --- a/ruoyi-system/src/main/resources/mapper/system/TBankFlowMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/system/TBankFlowMapper.xml @@ -37,9 +37,9 @@ <!-- 统计总额和微信支付金额 --> <select id="getPaymentStats" resultMap="PaymentStatsResultMap"> SELECT - SUM(flow_money) AS totalFlowMoney, - SUM(deduction_money) AS totalDeductionMoney, - SUM(remaining_money) AS totalRemainingMoney + ifnull(SUM(flow_money),0) AS totalFlowMoney, + ifnull(SUM(deduction_money),0) AS totalDeductionMoney, + ifnull(SUM(remaining_money),0) AS totalRemainingMoney FROM t_bank_flow <where> diff --git a/ruoyi-system/src/main/resources/mapper/system/TBillMapper.xml b/ruoyi-system/src/main/resources/mapper/system/TBillMapper.xml index 1e5bc53..5415d26 100644 --- a/ruoyi-system/src/main/resources/mapper/system/TBillMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/system/TBillMapper.xml @@ -63,7 +63,7 @@ and t.id = #{query.userId} </if> </where> - order by b.payable_fees_time + order by b.payable_fees_time desc,b.create_time desc </select> <select id="getBillList" resultType="com.ruoyi.system.dto.TBillDto"> SELECT @@ -148,18 +148,18 @@ </select> <select id="statisticsAllRent" resultType="java.math.BigDecimal"> - SELECT sum(payable_fees_money) as amount FROM t_bill + SELECT ifnull(sum(payable_fees_money),0) as amount FROM t_bill </select> <select id="statisticsNoPay" resultType="java.math.BigDecimal"> - SELECT sum(outstanding_money) as amount FROM t_bill where pay_fees_status!=3 + SELECT ifnull(sum(outstanding_money),0) as amount FROM t_bill where pay_fees_status!=3 </select> <select id="statisticsPayed" resultType="java.math.BigDecimal"> - SELECT sum(pay_fees_money) as amount FROM t_bill + SELECT ifnull(sum(pay_fees_money),0) as amount FROM t_bill </select> <select id="statisticsOverdue" resultType="java.math.BigDecimal"> - SELECT sum(outstanding_money) as amount FROM t_bill where pay_fees_status=4 + SELECT ifnull(sum(outstanding_money),0) as amount FROM t_bill where pay_fees_status=4 </select> </mapper> diff --git a/ruoyi-system/src/main/resources/mapper/system/TFlowManagementMapper.xml b/ruoyi-system/src/main/resources/mapper/system/TFlowManagementMapper.xml index f11b0fd..136ec5f 100644 --- a/ruoyi-system/src/main/resources/mapper/system/TFlowManagementMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/system/TFlowManagementMapper.xml @@ -39,10 +39,10 @@ <!-- 统计总额和微信支付金额 --> <select id="getPaymentStats" resultMap="PaymentStatsResultMap"> - SELECT SUM(flow_money) AS total_amount, - SUM(CASE WHEN pay_type = 1 THEN flow_money ELSE 0 END ) AS wechat_amount, - SUM(CASE WHEN pay_type = 2 THEN flow_money ELSE 0 END ) AS alipay_amount, - SUM(CASE WHEN pay_type = 3 THEN flow_money ELSE 0 END ) AS offline_amount + SELECT ifnull(SUM(flow_money),0) AS total_amount, + ifnull(SUM(CASE WHEN pay_type = 1 THEN flow_money ELSE 0 END ) ,0)AS wechat_amount, + ifnull(SUM(CASE WHEN pay_type = 2 THEN flow_money ELSE 0 END ),0) AS alipay_amount, + ifnull(SUM(CASE WHEN pay_type = 3 THEN flow_money ELSE 0 END ),0) AS offline_amount FROM t_flow_management <where> -- Gitblit v1.7.1