From b2f8320707dc72b2429bfb4fe0b317c11b1e5b7f Mon Sep 17 00:00:00 2001
From: zhangwencui <1064582902@qq.com>
Date: 星期四, 29 十月 2026 16:34:45 +0800
Subject: [PATCH] change
---
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