添加销售人员时默认添加一个登录用户
This commit is contained in:
@@ -195,5 +195,6 @@ public class PasswordUtil {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -179,5 +179,6 @@ public class ServiceManager {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -6,9 +6,12 @@ import com.rj.common.DataEnrichmentUtil;
|
||||
import com.rj.entity.Dealership;
|
||||
import com.rj.entity.ProjectManagement;
|
||||
import com.rj.entity.SalesManagement;
|
||||
import com.rj.entity.sys.User;
|
||||
import com.rj.service.IDealershipService;
|
||||
import com.rj.service.IProjectManagementService;
|
||||
import com.rj.service.ISalesManagementService;
|
||||
import com.rj.service.sys.IUserService;
|
||||
import com.rj.controller.sys.UserController;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
@@ -17,7 +20,9 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -40,6 +45,12 @@ public class SalesManagementController {
|
||||
@Autowired
|
||||
private ISalesManagementService salesManagementService;
|
||||
|
||||
@Autowired
|
||||
private IUserService userService;
|
||||
|
||||
@Autowired
|
||||
private UserController userController;
|
||||
|
||||
/**
|
||||
* 新增销售
|
||||
*/
|
||||
@@ -54,6 +65,14 @@ public class SalesManagementController {
|
||||
salesManagement.setUpdateTime(LocalDateTime.now());
|
||||
boolean success = salesManagementService.save(salesManagement);
|
||||
if (success) {
|
||||
// 原有逻辑处理完成后,创建用户管理模块的用户
|
||||
try {
|
||||
createUserForSales(salesManagement);
|
||||
} catch (Exception userException) {
|
||||
// 用户创建失败不影响销售人员创建成功,只记录日志
|
||||
System.err.println("创建用户失败:" + userException.getMessage());
|
||||
}
|
||||
|
||||
result.put("success", true);
|
||||
result.put("message", "销售添加成功");
|
||||
result.put("data", salesManagement);
|
||||
@@ -70,6 +89,61 @@ public class SalesManagementController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 为销售人员创建用户管理模块的用户
|
||||
*/
|
||||
private void createUserForSales(SalesManagement salesManagement) {
|
||||
// 检查销售人员是否有联系方式(登录账号)
|
||||
if (salesManagement.getLoginAccount() == null || salesManagement.getLoginAccount().trim().isEmpty()) {
|
||||
throw new RuntimeException("销售人员联系方式不能为空");
|
||||
}
|
||||
|
||||
String phone = salesManagement.getLoginAccount();
|
||||
|
||||
// 生成密码:当前日期 + 联系方式后4位
|
||||
String password = generatePasswordForSales(phone);
|
||||
|
||||
// 创建用户对象
|
||||
User user = new User();
|
||||
user.setUserId(salesManagement.getId().hashCode());
|
||||
user.setUserName(phone); // 用户名 = 销售人员电话
|
||||
user.setPhone(phone); // 电话号码 = 销售人员电话
|
||||
user.setPassword(password); // 设置密码(UserController会自动加密)
|
||||
user.setEmail(phone+"@YiDuoWang.com");
|
||||
// 调用UserController的addUser方法保存用户
|
||||
ResponseEntity<Map<String, Object>> response = userController.addUser(user);
|
||||
|
||||
// 检查响应结果
|
||||
if (response.getBody() != null) {
|
||||
Map<String, Object> result = response.getBody();
|
||||
Boolean success = (Boolean) result.get("success");
|
||||
if (success == null || !success) {
|
||||
String message = (String) result.get("message");
|
||||
throw new RuntimeException("用户创建失败:" + (message != null ? message : "未知错误"));
|
||||
}
|
||||
} else {
|
||||
throw new RuntimeException("用户创建失败:响应为空");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成销售人员密码:当前日期 + 联系方式后4位
|
||||
*/
|
||||
private String generatePasswordForSales(String phone) {
|
||||
// 获取当前日期,格式:yyyyMMdd
|
||||
String currentDate = LocalDate.now().format(DateTimeFormatter.ofPattern("MMdd"));
|
||||
|
||||
// 获取联系方式后4位
|
||||
String lastFourDigits = "";
|
||||
if (phone != null && phone.length() >= 4) {
|
||||
lastFourDigits = phone.substring(phone.length() - 4);
|
||||
} else {
|
||||
lastFourDigits = phone; // 如果长度不足4位,使用全部
|
||||
}
|
||||
|
||||
return currentDate + lastFourDigits;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID查询销售
|
||||
*/
|
||||
|
||||
@@ -417,5 +417,6 @@ public class MenuController {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -387,5 +387,6 @@ public class RoleController {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -393,5 +393,6 @@ public class UserRoleController {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -159,5 +159,6 @@ public class DifyWorkflowResponseDto {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -102,5 +102,6 @@ public interface CustomerProfileAnalysisMapper extends BaseMapper<CustomerProfil
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -123,5 +123,6 @@ public interface ICustomerProfileAnalysisService extends IService<CustomerProfil
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -158,5 +158,6 @@ public class CustomerProfileAnalysisServiceImpl extends ServiceImpl<CustomerProf
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -130,5 +130,6 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements IM
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -130,5 +130,6 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements IR
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -130,5 +130,6 @@ public class UserRoleServiceImpl extends ServiceImpl<UserRoleMapper, UserRole> i
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user