| | |
| | | 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; |
| | |
| | | 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; |
| | | |
| | |
| | | |
| | | @Value("${file.upload-dir}") |
| | | private String uploadDir; |
| | | |
| | | @Autowired |
| | | private ISysUserService sysUserService; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | |
| | | |
| | | @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 |
| | |
| | | } |
| | | } |
| | | |
| | | 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()) { |
| | |
| | | |
| | | 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 : ""); |
| | |
| | | } |
| | | 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) { |