gongchunyi
8 天以前 d79daa5f520947f63a92791012de0f8e18f76850
feat: 附件上传无ID接口及根据ID集合查询信息
已添加1个文件
已修改3个文件
123 ■■■■■ 文件已修改
src/main/java/com/ruoyi/basic/controller/CustomerFollowUpController.java 25 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/basic/dto/CustomerFollowUpFileDto.java 26 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/basic/service/CustomerFollowUpService.java 10 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/basic/service/impl/CustomerFollowUpServiceImpl.java 62 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/basic/controller/CustomerFollowUpController.java
@@ -15,6 +15,8 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import com.ruoyi.basic.dto.CustomerFollowUpFileDto;
import com.ruoyi.common.utils.SecurityUtils;
import java.util.List;
@@ -86,8 +88,27 @@
    @PostMapping("/upload/{followUpId}")
    @Log(title = "客户跟进-上传附件", businessType = BusinessType.INSERT)
    public AjaxResult uploadFiles(@RequestParam("files") List<MultipartFile> files, @PathVariable Integer followUpId) {
        customerFollowUpService.addFollowUpFiles(files, followUpId);
        return AjaxResult.success();
        return AjaxResult.success(customerFollowUpService.addFollowUpFiles(files, followUpId));
    }
    /**
     * ä¸Šä¼ è·Ÿè¿›é™„件(复用,无ID)
     */
    @ApiOperation("上传附件(复用)")
    @PostMapping("/upload")
    @Log(title = "上传附件(复用)", businessType = BusinessType.INSERT)
    public AjaxResult uploadFiles(@RequestParam("files") List<MultipartFile> files, @RequestParam(required = false) String name) {
        List<CustomerFollowUpFileDto> uploadedFiles = customerFollowUpService.addFollowUpFiles(files, null);
        return AjaxResult.success(uploadedFiles);
    }
    /**
     * æ‰¹é‡æŸ¥è¯¢é™„件列表
     */
    @ApiOperation("批量查询附件列表")
    @PostMapping("/file/list")
    public AjaxResult getFileList(@RequestBody List<Long> ids) {
        return AjaxResult.success(customerFollowUpService.getFollowUpFilesByIds(ids));
    }
    /**
src/main/java/com/ruoyi/basic/dto/CustomerFollowUpFileDto.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,26 @@
package com.ruoyi.basic.dto;
import com.ruoyi.basic.pojo.CustomerFollowUpFile;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
 * å®¢æˆ·è·Ÿè¿›é™„ä»¶DTO
 *
 * @author deslrey
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class CustomerFollowUpFileDto extends CustomerFollowUpFile {
    private static final long serialVersionUID = 1L;
    /**
     * ä¸Šä¼ è€…姓名
     */
    private String createUserName;
    /**
     * ä¿®æ”¹è€…姓名
     */
    private String updateUserName;
}
src/main/java/com/ruoyi/basic/service/CustomerFollowUpService.java
@@ -3,7 +3,8 @@
import com.baomidou.mybatisplus.extension.service.IService;
import com.ruoyi.basic.dto.CustomerFollowUpDto;
import com.ruoyi.basic.pojo.CustomerFollowUp;
import org.springframework.transaction.annotation.Transactional;
import com.ruoyi.basic.dto.CustomerFollowUpFileDto;
import com.ruoyi.basic.pojo.CustomerFollowUpFile;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
@@ -41,7 +42,7 @@
    /**
     * æ·»åŠ è·Ÿè¿›é™„ä»¶
     */
    void addFollowUpFiles(List<MultipartFile> files, Integer followUpId);
    List<CustomerFollowUpFileDto> addFollowUpFiles(List<MultipartFile> files, Integer followUpId);
    /**
     * åˆ é™¤è·Ÿè¿›é™„ä»¶
@@ -49,6 +50,11 @@
    void deleteFollowUpFile(Integer fileId);
    /**
     * æ ¹æ®é™„ä»¶ID集合获取附件列表
     */
    List<CustomerFollowUpFile> getFollowUpFilesByIds(List<Long> fileIds);
    /**
     * èŽ·å–è·Ÿè¿›è¯¦æƒ…
     */
    CustomerFollowUpDto getFollowUpWithFiles(Integer id);
src/main/java/com/ruoyi/basic/service/impl/CustomerFollowUpServiceImpl.java
@@ -8,10 +8,12 @@
import com.ruoyi.basic.pojo.CustomerFollowUpFile;
import com.ruoyi.basic.service.CustomerFollowUpFileService;
import com.ruoyi.basic.service.CustomerFollowUpService;
import com.ruoyi.basic.service.ICustomerService;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.basic.dto.CustomerFollowUpFileDto;
import com.ruoyi.project.system.domain.SysUser;
import com.ruoyi.project.system.service.ISysUserService;
import org.apache.commons.io.FilenameUtils;
import org.springframework.beans.BeanUtils;
@@ -28,7 +30,6 @@
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
@@ -49,6 +50,9 @@
    @Value("${file.upload-dir}")
    private String uploadDir;
    @Autowired
    private ISysUserService sysUserService;
    @Override
    @Transactional(rollbackFor = Exception.class)
@@ -78,8 +82,8 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void addFollowUpFiles(List<MultipartFile> files, Integer followUpId) {
        handleFollowUpFiles(files, followUpId);
    public List<CustomerFollowUpFileDto> addFollowUpFiles(List<MultipartFile> files, Integer followUpId) {
        return handleFollowUpFiles(files, followUpId);
    }
    @Override
@@ -136,14 +140,27 @@
        }
    }
    private void handleFollowUpFiles(List<MultipartFile> multipartFiles, Integer followUpId) {
    @Override
    public List<CustomerFollowUpFile> getFollowUpFilesByIds(List<Long> fileIds) {
        if (fileIds == null || fileIds.isEmpty()) {
            return new ArrayList<>(0);
        }
        LambdaQueryWrapper<CustomerFollowUpFile> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(CustomerFollowUpFile::getId, fileIds)
                .select(CustomerFollowUpFile::getId, CustomerFollowUpFile::getFileUrl, CustomerFollowUpFile::getFileName);
        return customerFollowUpFileService.list(queryWrapper);
    }
    private List<CustomerFollowUpFileDto> handleFollowUpFiles(List<MultipartFile> multipartFiles, Integer followUpId) {
        List<CustomerFollowUpFile> fileList = new ArrayList<>();
        List<CustomerFollowUpFileDto> dtoList = new ArrayList<>();
        if (multipartFiles == null || multipartFiles.isEmpty()) {
            return;
            return dtoList;
        }
        Long currentUserId = SecurityUtils.getUserId();
        Long currentTenantId = SecurityUtils.getLoginUser().getTenantId();
        List<CustomerFollowUpFile> fileList = new ArrayList<>();
        for (MultipartFile file : multipartFiles) {
            if (file == null || file.isEmpty()) {
@@ -159,7 +176,8 @@
                String originalFilename = file.getOriginalFilename();
                String fileExtension = FilenameUtils.getExtension(originalFilename);
                String formalFilename = followUpId + "_" +
                String prefix = (followUpId != null) ? followUpId.toString() : "temp";
                String formalFilename = prefix + "_" +
                        System.currentTimeMillis() + "_" +
                        UUID.randomUUID().toString().substring(0, 8) +
                        (StringUtils.hasText(fileExtension) ? "." + fileExtension : "");
@@ -184,7 +202,35 @@
        }
        if (!fileList.isEmpty()) {
            customerFollowUpFileService.saveBatch(fileList);
            return convertToDtoList(fileList);
        }
        return dtoList;
    }
    private List<CustomerFollowUpFileDto> convertToDtoList(List<CustomerFollowUpFile> fileList) {
        List<CustomerFollowUpFileDto> dtoList = new ArrayList<>();
        if (fileList == null || fileList.isEmpty()) {
            return dtoList;
        }
        for (CustomerFollowUpFile entity : fileList) {
            CustomerFollowUpFileDto dto = new CustomerFollowUpFileDto();
            BeanUtils.copyProperties(entity, dto);
            if (entity.getCreateUser() != null) {
                SysUser createUser = sysUserService.selectUserById(entity.getCreateUser());
                if (createUser != null) {
                    dto.setCreateUserName(createUser.getNickName());
                }
            }
            if (entity.getUpdateUser() != null) {
                SysUser updateUser = sysUserService.selectUserById(entity.getUpdateUser());
                if (updateUser != null) {
                    dto.setUpdateUserName(updateUser.getNickName());
                }
            }
            dtoList.add(dto);
        }
        return dtoList;
    }
    private void validateFollowUp(CustomerFollowUp followUp) {