From e099d0cd93c26b44bc1c10e51944edfad0465b0c Mon Sep 17 00:00:00 2001
From: maven <2163098428@qq.com>
Date: 星期四, 05 三月 2026 17:44:44 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/dev_New' into dev_New
---
src/main/java/com/ruoyi/basic/service/impl/CustomerFollowUpServiceImpl.java | 227 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 227 insertions(+), 0 deletions(-)
diff --git a/src/main/java/com/ruoyi/basic/service/impl/CustomerFollowUpServiceImpl.java b/src/main/java/com/ruoyi/basic/service/impl/CustomerFollowUpServiceImpl.java
new file mode 100644
index 0000000..9f452ac
--- /dev/null
+++ b/src/main/java/com/ruoyi/basic/service/impl/CustomerFollowUpServiceImpl.java
@@ -0,0 +1,227 @@
+package com.ruoyi.basic.service.impl;
+
+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.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 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;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.time.LocalDate;
+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;
+
+/**
+ * <br>
+ * 瀹㈡埛鏍规嵁鎺ュ彛瀹炵幇绫�
+ * </br>
+ *
+ * @author deslrey
+ * @version 1.0
+ * @since 2026/03/04 14:48
+ */
+@Service
+public class CustomerFollowUpServiceImpl extends ServiceImpl<CustomerFollowUpMapper, CustomerFollowUp> implements CustomerFollowUpService {
+
+ @Autowired
+ private CustomerFollowUpFileService customerFollowUpFileService;
+
+ @Value("${file.upload-dir}")
+ private String uploadDir;
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public boolean insertCustomerFollowUp(CustomerFollowUp customerFollowUp) {
+ validateFollowUp(customerFollowUp);
+ Long currentUserId = SecurityUtils.getUserId();
+ Long currentTenantId = SecurityUtils.getLoginUser().getTenantId();
+
+ customerFollowUp.setFollowerUserId(currentUserId);
+ customerFollowUp.setCreateTime(LocalDateTime.now());
+ customerFollowUp.setTenantId(currentTenantId);
+
+ int result = baseMapper.insert(customerFollowUp);
+ if (result < 1) {
+ throw new ServiceException("瀹㈡埛璺熻繘鏁版嵁娣诲姞澶辫触");
+ }
+
+ return true;
+ }
+
+ @Override
+ public int updateCustomerFollowUp(CustomerFollowUp customerFollowUp) {
+ validateFollowUp(customerFollowUp);
+ customerFollowUp.setUpdateTime(LocalDateTime.now());
+ return baseMapper.updateById(customerFollowUp);
+ }
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public void addFollowUpFiles(List<MultipartFile> files, Integer followUpId) {
+ handleFollowUpFiles(files, followUpId);
+ }
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public void deleteFollowUpFile(Integer fileId) {
+ CustomerFollowUpFile file = customerFollowUpFileService.getById(fileId);
+ if (file != null) {
+ try {
+ Files.deleteIfExists(Paths.get(file.getFileUrl()));
+ } catch (Exception e) {
+ throw new ServiceException("鍒犻櫎鏂囦欢澶辫触锛�" + e.getMessage());
+ }
+ customerFollowUpFileService.removeById(fileId);
+ }
+ }
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public int deleteCustomerFollowUpById(Integer id) {
+ if (id == null) {
+ throw new ServiceException("璺熻繘ID涓嶈兘涓虹┖");
+ }
+
+ List<CustomerFollowUpFile> files = customerFollowUpFileService.list(new LambdaQueryWrapper<CustomerFollowUpFile>()
+ .eq(CustomerFollowUpFile::getFollowUpId, id));
+
+ if (files != null && !files.isEmpty()) {
+ for (CustomerFollowUpFile file : files) {
+ deleteFollowUpFile(file.getId().intValue());
+ }
+ }
+
+ int result = baseMapper.deleteById(id);
+ if (result < 1) {
+ throw new ServiceException("瀹㈡埛璺熻繘璁板綍鍒犻櫎澶辫触");
+ }
+ return result;
+ }
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public void deleteByCustomerId(Long customerId) {
+ if (customerId == null) {
+ throw new ServiceException("瀹㈡埛ID涓嶈兘涓虹┖");
+ }
+
+ List<CustomerFollowUp> followUps = list(new LambdaQueryWrapper<CustomerFollowUp>()
+ .eq(CustomerFollowUp::getCustomerId, customerId));
+
+ if (followUps != null && !followUps.isEmpty()) {
+ for (CustomerFollowUp followUp : followUps) {
+ deleteCustomerFollowUpById(followUp.getId());
+ }
+ }
+ }
+
+ private void handleFollowUpFiles(List<MultipartFile> multipartFiles, Integer followUpId) {
+ if (multipartFiles == null || multipartFiles.isEmpty()) {
+ return;
+ }
+
+ Long currentUserId = SecurityUtils.getUserId();
+ Long currentTenantId = SecurityUtils.getLoginUser().getTenantId();
+ List<CustomerFollowUpFile> fileList = new ArrayList<>();
+
+ for (MultipartFile file : multipartFiles) {
+ if (file == null || file.isEmpty()) {
+ continue;
+ }
+ try {
+ String formalDir = uploadDir + "/" + LocalDate.now().format(DateTimeFormatter.ISO_LOCAL_DATE);
+ Path formalDirPath = Paths.get(formalDir);
+
+ if (!Files.exists(formalDirPath)) {
+ Files.createDirectories(formalDirPath);
+ }
+
+ String originalFilename = file.getOriginalFilename();
+ String fileExtension = FilenameUtils.getExtension(originalFilename);
+ String formalFilename = followUpId + "_" +
+ System.currentTimeMillis() + "_" +
+ UUID.randomUUID().toString().substring(0, 8) +
+ (StringUtils.hasText(fileExtension) ? "." + fileExtension : "");
+
+ Path formalFilePath = formalDirPath.resolve(formalFilename);
+ file.transferTo(formalFilePath.toFile());
+
+ CustomerFollowUpFile followUpFile = new CustomerFollowUpFile();
+ followUpFile.setFollowUpId(followUpId);
+ followUpFile.setFileName(originalFilename);
+ followUpFile.setFileUrl(formalFilePath.toString());
+ followUpFile.setFileSize(file.getSize());
+ followUpFile.setFileSuffix(fileExtension);
+ followUpFile.setCreateUser(currentUserId);
+ followUpFile.setCreateTime(LocalDateTime.now());
+ followUpFile.setTenantId(currentTenantId);
+
+ fileList.add(followUpFile);
+ } catch (Exception e) {
+ throw new ServiceException("鏂囦欢 [" + file.getOriginalFilename() + "] 涓婁紶澶辫触锛�" + e.getMessage());
+ }
+ }
+ if (!fileList.isEmpty()) {
+ customerFollowUpFileService.saveBatch(fileList);
+ }
+ }
+
+ private void validateFollowUp(CustomerFollowUp followUp) {
+ if (followUp == null) {
+ throw new ServiceException("璺熻繘鏁版嵁涓嶈兘涓虹┖");
+ }
+ if (StringUtils.isEmpty(followUp.getFollowUpMethod())) {
+ throw new ServiceException("璺熻繘鏂瑰紡涓嶈兘涓虹┖");
+ }
+ if (StringUtils.isEmpty(followUp.getFollowUpLevel())) {
+ throw new ServiceException("璺熻繘绋嬪害涓嶈兘涓虹┖");
+ }
+ if (followUp.getFollowUpTime() == null) {
+ throw new ServiceException("璺熻繘鏃堕棿涓嶈兘涓虹┖");
+ }
+ if (StringUtils.isEmpty(followUp.getFollowerUserName())) {
+ throw new ServiceException("璺熻繘浜轰笉鑳戒负绌�");
+ }
+ if (StringUtils.isEmpty(followUp.getContent())) {
+ throw new ServiceException("璺熻繘鍐呭涓嶈兘涓虹┖");
+ }
+ }
+
+ @Override
+ public CustomerFollowUpDto getFollowUpWithFiles(Integer id) {
+ CustomerFollowUp followUp = baseMapper.selectById(id);
+ if (followUp == null) {
+ return null;
+ }
+
+ CustomerFollowUpDto dto = new CustomerFollowUpDto();
+ BeanUtils.copyProperties(followUp, dto);
+
+ List<CustomerFollowUpFile> fileList = customerFollowUpFileService.list(new LambdaQueryWrapper<CustomerFollowUpFile>()
+ .eq(CustomerFollowUpFile::getFollowUpId, id));
+ dto.setFileList(fileList);
+
+ return dto;
+ }
+}
--
Gitblit v1.9.3