From 2dd645b5346f510d1207346347f1fa70a204d9d3 Mon Sep 17 00:00:00 2001
From: zhangwencui <1064582902@qq.com>
Date: 星期四, 05 十一月 2026 16:11:34 +0800
Subject: [PATCH] 1. 完成项目管理全流程优化,补充阶段推进、汇报统计及生命周期记录。 2. 完成业务与项目数据关联,支持查看项目进度、详情及相关附件。 3. 完成采购审批流程接入,支持配置审批人员及采购业务审批。 4. 精简用户、角色、部门、菜单和字典,完善操作日志及附件下载。

---
 src/main/java/com/ruoyi/basic/service/impl/CustomerServiceImpl.java |   61 +++++++++++++++++++++---------
 1 files changed, 42 insertions(+), 19 deletions(-)

diff --git a/src/main/java/com/ruoyi/basic/service/impl/CustomerServiceImpl.java b/src/main/java/com/ruoyi/basic/service/impl/CustomerServiceImpl.java
index b2f407d..ce90a16 100644
--- a/src/main/java/com/ruoyi/basic/service/impl/CustomerServiceImpl.java
+++ b/src/main/java/com/ruoyi/basic/service/impl/CustomerServiceImpl.java
@@ -33,6 +33,7 @@
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
@@ -70,6 +71,8 @@
     private CustomerReturnVisitService customerReturnVisitService;
     @Autowired
     private CustomerUserService customerUserService;
+    @Autowired
+    private JdbcTemplate jdbcTemplate;
 
     /**
      * 鏌ヨ瀹㈡埛妗f
@@ -92,6 +95,13 @@
     public CustomerVo selectCustomerDetailById(Long id) {
         CustomerVo customerVo = new CustomerVo();
         BeanUtils.copyProperties(this.getById(id), customerVo);
+
+        // 鍥炴樉缁戝畾鐨勭櫥褰曡处鍙�
+        CustomerUser binding = customerUserService.getOne(new LambdaQueryWrapper<CustomerUser>()
+                .eq(CustomerUser::getCustomerId, id).last("limit 1"), false);
+        if (binding != null) {
+            customerVo.setBindUserId(binding.getUserId());
+        }
 
         // 鏌ヨ璺熻繘璁板綍
         List<CustomerFollowUp> followUpList = customerFollowUpService.list(
@@ -196,11 +206,14 @@
      * @return 缁撴灉
      */
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public int insertCustomer(Customer customer) {
         LoginUser loginUser = SecurityUtils.getLoginUser();
         Long tenantId = loginUser.getTenantId();
         customer.setTenantId(tenantId);
-        return customerMapper.insert(customer);
+        int rows = customerMapper.insert(customer);
+        saveCustomerBinding(customer.getId(), customer.getBindUserId());
+        return rows;
     }
 
     /**
@@ -210,12 +223,38 @@
      * @return 缁撴灉
      */
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public int updateCustomer(Customer customer) {
         LoginUser loginUser = SecurityUtils.getLoginUser();
         Long tenantId = loginUser.getTenantId();
-        validateCustomerEditPermission(customer.getId());
         customer.setTenantId(tenantId);
-        return customerMapper.updateById(customer);
+        int rows = customerMapper.updateById(customer);
+        saveCustomerBinding(customer.getId(), customer.getBindUserId());
+        return rows;
+    }
+
+    /**
+     * 淇濆瓨瀹㈡埛涓庣櫥褰曡处鍙风殑涓�瀵逛竴缁戝畾鍏崇郴
+     */
+    private void saveCustomerBinding(Long customerId, Long bindUserId) {
+        if (customerId == null) {
+            return;
+        }
+        customerUserService.remove(new LambdaQueryWrapper<CustomerUser>()
+                .eq(CustomerUser::getCustomerId, customerId));
+        if (bindUserId == null) {
+            return;
+        }
+        // 涓�涓櫥褰曡处鍙峰彧鑳界粦瀹氫竴涓鎴�
+        customerUserService.remove(new LambdaQueryWrapper<CustomerUser>()
+                .eq(CustomerUser::getUserId, bindUserId));
+        CustomerUser binding = new CustomerUser();
+        binding.setCustomerId(customerId);
+        binding.setUserId(bindUserId);
+        customerUserService.save(binding);
+        // 缁戝畾璐﹀彿鑷姩鎺堜簣鈥滃鎴封�濊鑹诧紝浣垮叾鐧诲綍鍚庡彧鑳借闂鎴烽棬鎴�
+        jdbcTemplate.update("INSERT IGNORE INTO sys_user_role (user_id, role_id) "
+                + "SELECT ?, role_id FROM sys_role WHERE role_key = 'customer' AND del_flag = '0'", bindUserId);
     }
 
     /**
@@ -418,22 +457,6 @@
         customer.setType(1);
         customer.setIsAssigned(0);
         return this.updateById(customer);
-    }
-
-    private void validateCustomerEditPermission(Long customerId) {
-        Customer customer = customerMapper.selectById(customerId);
-        if (customer == null) {
-            throw new RuntimeException("瀹㈡埛妗f涓嶅瓨鍦�");
-        }
-        if (!hasSalesModuleReference(customerId)) {
-            return;
-        }
-        if (Objects.equals(customer.getType(), 0)) {
-            throw new RuntimeException("宸茶閿�鍞ā鍧楀紩鐢ㄧ殑绉佹捣瀹㈡埛涓嶈兘缂栬緫");
-        }
-        if (Objects.equals(customer.getType(), 1) && Objects.equals(customer.getIsAssigned(), 1)) {
-            throw new RuntimeException("宸查鐢ㄥ苟涓旇閿�鍞ā鍧楀紩鐢ㄧ殑鍏捣瀹㈡埛涓嶈兘缂栬緫");
-        }
     }
 
     private void validatePublicSeaRecyclePermission(Long customerId) {

--
Gitblit v1.9.3