无关风月
2025-03-07 3603b4ea7d56f0893f5067ca05fc81b784c27b94
权限
2个文件已修改
1个文件已添加
151 ■■■■■ 已修改文件
ruoyi-applet/src/main/java/com/ruoyi/web/controller/api/IndexController.java 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-applet/src/main/java/com/ruoyi/web/controller/tool/MyFileUtil.java 128 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/FlowListenerService.java 14 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-applet/src/main/java/com/ruoyi/web/controller/api/IndexController.java
@@ -21,6 +21,7 @@
import com.ruoyi.system.query.*;
import com.ruoyi.system.service.*;
import com.ruoyi.system.vo.*;
import com.ruoyi.web.controller.tool.MyFileUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jdk.nashorn.internal.parser.Token;
@@ -31,7 +32,10 @@
import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
@@ -76,6 +80,11 @@
    private TContractRentTypeService contractRentTypeService;
    @Autowired
    private StateProcessTemplateService processTemplateService;
    public static void main(String[] args) throws IOException {
        File file = new File("D:\\wechatFiles\\WeChat Files\\wxid_25nztsudcon722\\FileStorage\\File\\2025-03\\2.mp3");
        MultipartFile multipartFile = MyFileUtil.fileToMultipartFile(file, "3333");
    }
    /**
     * 获取轮播图管理列表
     */
ruoyi-applet/src/main/java/com/ruoyi/web/controller/tool/MyFileUtil.java
New file
@@ -0,0 +1,128 @@
package com.ruoyi.web.controller.tool;
import org.springframework.web.multipart.MultipartFile;
import java.io.*;
import java.nio.file.Files;
/**
 * @author RainbowCloud
 */
public class MyFileUtil {
    /**
     * 将 File 转换为 MultipartFile。
     *
     * @param file      要转换的文件
     * @param fieldName 字段名,通常用于表单中的文件字段名
     * @return 转换后的 MultipartFile
     * @throws IOException 如果发生I/O错误
     */
    public static MultipartFile fileToMultipartFile(File file, String fieldName) throws IOException {
        try {
            if (file == null || !file.exists()) {
                throw new FileNotFoundException("文件未找到:" + file);
            }
            byte[] content = Files.readAllBytes(file.toPath());
            return new ByteArrayMultipartFile(content, file.getName(), fieldName, Files.probeContentType(file.toPath()));
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            // 删除临时文件
            file.delete();
        }
    }
    /**
     * 将 MultipartFile 转换为 File。
     *
     * @param multipartFile 要转换的 MultipartFile
     * @return 转换后的 File
     * @throws IOException 如果发生I/O错误
     */
    public static File multipartFileToFile(MultipartFile multipartFile) throws IOException {
        if (multipartFile.isEmpty()) {
            throw new IOException("传入的MultipartFile为空");
        }
        String originalFilename = multipartFile.getOriginalFilename();
        String tempFileSuffix = originalFilename != null ? originalFilename.substring(originalFilename.lastIndexOf('.')) : ".tmp";
        File tempFile = File.createTempFile("temp", tempFileSuffix);
        try (InputStream ins = multipartFile.getInputStream();
             OutputStream os = new FileOutputStream(tempFile)) {
            byte[] buffer = new byte[8192];
            int bytesRead;
            while ((bytesRead = ins.read(buffer)) != -1) {
                os.write(buffer, 0, bytesRead);
            }
        }
        return tempFile;
    }
    /**
     * 内置一个简单的 MultipartFile 实现类,用于File转换
     */
    private static class ByteArrayMultipartFile implements MultipartFile {
        private final byte[] content;
        private final String name;
        private final String originalFilename;
        private final String contentType;
        /**
         * 构造函数
         *
         * @param content         文件内容
         * @param originalFilename 文件原始名字
         * @param name            字段名
         * @param contentType     文件类型
         */
        public ByteArrayMultipartFile(byte[] content, String originalFilename, String name, String contentType) {
            this.content = content;
            this.originalFilename = originalFilename;
            this.name = name;
            this.contentType = contentType;
        }
        @Override
        public String getName() {
            return this.name;
        }
        @Override
        public String getOriginalFilename() {
            return this.originalFilename;
        }
        @Override
        public String getContentType() {
            return this.contentType;
        }
        @Override
        public boolean isEmpty() {
            return (this.content == null || this.content.length == 0);
        }
        @Override
        public long getSize() {
            return this.content.length;
        }
        @Override
        public byte[] getBytes() {
            return this.content;
        }
        @Override
        public InputStream getInputStream() {
            return new ByteArrayInputStream(this.content);
        }
        @Override
        public void transferTo(File dest) throws IOException, IllegalStateException {
            try (OutputStream os = new FileOutputStream(dest)) {
                os.write(this.content);
            }
        }
    }
}
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/FlowListenerService.java
@@ -294,7 +294,7 @@
                }
                if (tContractRentType != null && rentBill.getEndTime().isAfter(tContractRentType.getChangeTime())) {
                    long moneyDays = 0;
                    moneyDays = ChronoUnit.DAYS.between(tContractRentType.getChangeTime(), rentBill.getEndTime());
                    moneyDays = ChronoUnit.DAYS.between(tContractRentType.getChangeTime(), rentBill.getEndTime())+1;
                    // 计算租金变动的天数
                    contract.setChangeTime(tContractRentType.getChangeTime());
                    // 递增递减的租金
@@ -330,14 +330,14 @@
                            break;
                    }
                    // 不需要涨租金的时间段
                    long originalDays = Math.abs(ChronoUnit.DAYS.between(contract.getFirstPayTime(), tContractRentType.getChangeTime()));
                    long originalDays = Math.abs(ChronoUnit.DAYS.between(contract.getFirstPayTime(), tContractRentType.getChangeTime()))+1;
                    originalMoney = originalMoney.add(contract.getMonthRent().divide(new BigDecimal(30), 2, BigDecimal.ROUND_DOWN))
                            .multiply(new BigDecimal(originalDays));
                    rentBill.setPayableFeesMoney(contractRentTypeMoney.add(originalMoney));
                    rentBill.setOutstandingMoney(rentBill.getPayableFeesMoney());
                } else {
                    // 不走递增递减
                    long allDays = ChronoUnit.DAYS.between(contract.getStartPayTime(), rentBill.getEndTime());
                    long allDays = ChronoUnit.DAYS.between(contract.getStartPayTime(), rentBill.getEndTime())+1;
                    int dayOfMonth = rentBill.getStartTime().getDayOfMonth();
                    if (dayOfMonth == 1) {
                        rentBill.setPayableFeesMoney(contract.getMonthRent().multiply(new BigDecimal(contract.getPayType().equals("1") ? 1 : contract.getPayType().equals("2") ? 3 : 12)));
@@ -394,7 +394,7 @@
                                        if (changeTime.isBefore(tBill.getEndTime()) && changeTime.isAfter(tBill.getStartTime())) {
                                            contract.setChangeTime(changeTime);
                                            // 租金递增递减的时长 天
                                            long moneyDays = Math.abs(ChronoUnit.DAYS.between(tContractRentType.getChangeTime(), tBill.getEndTime()));
                                            long moneyDays = Math.abs(ChronoUnit.DAYS.between(tContractRentType.getChangeTime(), tBill.getEndTime()))+1;
                                            // 递增递减的租金
                                            BigDecimal contractRentTypeMoney = new BigDecimal("0");
                                            // 不递增递减的租金
@@ -446,7 +446,7 @@
                                            System.err.println("首次递增递减");
                                            contract.setChangeTime(tContractRentType.getChangeTime());
                                            // 租金递增递减的时长 天
                                            long moneyDays = Math.abs(ChronoUnit.DAYS.between(tContractRentType.getChangeTime(), tBill.getEndTime()));
                                            long moneyDays = Math.abs(ChronoUnit.DAYS.between(tContractRentType.getChangeTime(), tBill.getEndTime()))+1;
                                            // 递增递减的租金
                                            BigDecimal contractRentTypeMoney = new BigDecimal("0");
                                            // 不递增递减的租金
@@ -536,7 +536,7 @@
                                if (changeTime.isBefore(tBill.getEndTime()) && changeTime.isAfter(tBill.getStartTime())) {
                                    contract.setChangeTime(changeTime);
                                    // 租金递增递减的时长 天
                                    long moneyDays = Math.abs(ChronoUnit.DAYS.between(changeTime, tBill.getEndTime()));
                                    long moneyDays = Math.abs(ChronoUnit.DAYS.between(changeTime, tBill.getEndTime()))+1;
                                    // 递增递减的租金
                                    BigDecimal contractRentTypeMoney = new BigDecimal("0");
                                    // 不递增递减的租金
@@ -587,7 +587,7 @@
                                if (tContractRentType.getChangeTime().isBefore(tBill.getEndTime()) && tContractRentType.getChangeTime().isAfter(tBill.getStartTime())) {
                                    contract.setChangeTime(tContractRentType.getChangeTime());
                                    // 租金递增递减的时长 天
                                    long moneyDays = Math.abs(ChronoUnit.DAYS.between(tContractRentType.getChangeTime(), tBill.getEndTime()));
                                    long moneyDays = Math.abs(ChronoUnit.DAYS.between(tContractRentType.getChangeTime(), tBill.getEndTime()))+1;
                                    // 递增递减的租金
                                    BigDecimal contractRentTypeMoney = new BigDecimal("0");
                                    // 不递增递减的租金