liyong
5 小时以前 1ca5584d7e3200a9af65a099bd26d3593e2ba702
src/main/java/com/ruoyi/basic/service/impl/CustomerFollowUpServiceImpl.java
@@ -3,19 +3,20 @@
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.basic.dto.CustomerFollowUpDto;
import com.ruoyi.basic.dto.CustomerFollowUpFileDto;
import com.ruoyi.basic.mapper.CustomerFollowUpMapper;
import com.ruoyi.basic.pojo.CustomerFollowUp;
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.project.system.domain.SysUser;
import com.ruoyi.project.system.service.ISysUserService;
import lombok.RequiredArgsConstructor;
import org.apache.commons.io.FilenameUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -28,7 +29,7 @@
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.UUID;
@@ -42,13 +43,15 @@
 * @since 2026/03/04 14:48
 */
@Service
@RequiredArgsConstructor
public class CustomerFollowUpServiceImpl extends ServiceImpl<CustomerFollowUpMapper, CustomerFollowUp> implements CustomerFollowUpService {
    @Autowired
    private CustomerFollowUpFileService customerFollowUpFileService;
    private final CustomerFollowUpFileService customerFollowUpFileService;
    @Value("${file.upload-dir}")
    private String uploadDir;
    private final ISysUserService sysUserService;
    @Override
    @Transactional(rollbackFor = Exception.class)
@@ -78,8 +81,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 +139,27 @@
        }
    }
    private void handleFollowUpFiles(List<MultipartFile> multipartFiles, Integer followUpId) {
    @Override
    public List<CustomerFollowUpFile> getFollowUpFilesByIds(Collection<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 +175,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 +201,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) {