|
|
@ -2,8 +2,10 @@ package com.example.web.service.impl; |
|
|
|
|
|
|
|
|
import com.example.web.entity.InformationTra; |
|
|
import com.example.web.entity.InformationTra; |
|
|
import com.example.web.entity.Managers; |
|
|
import com.example.web.entity.Managers; |
|
|
|
|
|
import com.example.web.entity.Personnel; |
|
|
import com.example.web.entity.Users; |
|
|
import com.example.web.entity.Users; |
|
|
import com.example.web.entity.UsersManagements; |
|
|
import com.example.web.entity.UsersManagements; |
|
|
|
|
|
import com.example.web.mapper.PersonnelMapper; |
|
|
import com.example.web.mapper.UsersMapper; |
|
|
import com.example.web.mapper.UsersMapper; |
|
|
import com.example.web.mapper.ManagersMapper; |
|
|
import com.example.web.mapper.ManagersMapper; |
|
|
import com.example.web.mapper.UsersManagementsMapper; |
|
|
import com.example.web.mapper.UsersManagementsMapper; |
|
|
@ -12,6 +14,7 @@ import com.example.web.service.UserService; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
|
|
|
import java.time.LocalDateTime; |
|
|
import java.util.HashMap; |
|
|
import java.util.HashMap; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
import java.util.Map; |
|
|
import java.util.Map; |
|
|
@ -25,6 +28,9 @@ public class UserServiceImpl implements UserService { |
|
|
@Autowired |
|
|
@Autowired |
|
|
private ManagersMapper managersMapper; |
|
|
private ManagersMapper managersMapper; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
private PersonnelMapper personnelMapper; |
|
|
|
|
|
|
|
|
@Autowired |
|
|
@Autowired |
|
|
private UsersManagementsMapper usersManagementsMapper; |
|
|
private UsersManagementsMapper usersManagementsMapper; |
|
|
|
|
|
|
|
|
@ -177,6 +183,13 @@ public class UserServiceImpl implements UserService { |
|
|
return result; |
|
|
return result; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 检查客户是否是第一次跟进
|
|
|
|
|
|
Users user = usersMapper.findByUserId(userId); |
|
|
|
|
|
if (user != null && user.getFollowup_at() != null) { |
|
|
|
|
|
// 不是第一次跟进,设置followup_at参数为非空,避免更新跟进时间
|
|
|
|
|
|
params.put("followup_at", user.getFollowup_at()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// 更新跟进信息
|
|
|
// 更新跟进信息
|
|
|
usersMapper.updateFollowup(params); |
|
|
usersMapper.updateFollowup(params); |
|
|
|
|
|
|
|
|
@ -271,24 +284,97 @@ public class UserServiceImpl implements UserService { |
|
|
return result; |
|
|
return result; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 1. 更新 users 表,修改 type 字段并清空 followup 字段
|
|
|
// 获取客户信息
|
|
|
usersMapper.updateUserTypeAndClearFollowup(params); |
|
|
Users user = usersMapper.findByUserId(userId); |
|
|
|
|
|
if (user == null) { |
|
|
|
|
|
result.put("success", false); |
|
|
|
|
|
result.put("message", "客户不存在"); |
|
|
|
|
|
return result; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// 2. 清除 usermanagements 表中的记录
|
|
|
// 根据用户选择的类型进行不同的归还处理
|
|
|
usersMapper.clearUsersManagements(params); |
|
|
// type参数是用户选择的类型,可能值包括:buyer(大贸易客户)、seller(供应商)、both(两者都是)、smalls(小品种客户)
|
|
|
|
|
|
if ("seller".equals(type) || "both".equals(type)) { |
|
|
|
|
|
// 随机分配给指定的人员
|
|
|
|
|
|
String[] assignUsers = {"刘琴", "何佳芹", "汤敏", "李真音"}; |
|
|
|
|
|
int randomIndex = (int) (Math.random() * assignUsers.length); |
|
|
|
|
|
String assignedUser = assignUsers[randomIndex]; |
|
|
|
|
|
|
|
|
|
|
|
// 1. 更新 users 表,修改 type 字段
|
|
|
|
|
|
usersMapper.updateUserTypeAndClearFollowup(params); |
|
|
|
|
|
|
|
|
|
|
|
// 从primary数据源的personnel表查询业务员信息
|
|
|
|
|
|
Personnel personnel = personnelMapper.findByName(assignedUser); |
|
|
|
|
|
|
|
|
|
|
|
// 创建UsersManagements对象,将personnel表中的信息写入usermanagements表
|
|
|
|
|
|
UsersManagements usersManagements = new UsersManagements(); |
|
|
|
|
|
usersManagements.setUserId(userId); |
|
|
|
|
|
usersManagements.setAssistant(assistant); |
|
|
|
|
|
|
|
|
|
|
|
if (personnel != null) { |
|
|
|
|
|
// 如果找到业务员信息,使用查询到的信息
|
|
|
|
|
|
usersManagements.setManagerId(personnel.getManagerId()); |
|
|
|
|
|
usersManagements.setManagercompany(personnel.getManagercompany()); |
|
|
|
|
|
usersManagements.setManagerdepartment(personnel.getManagerdepartment()); |
|
|
|
|
|
usersManagements.setOrganization(personnel.getOrganization()); |
|
|
|
|
|
usersManagements.setRole(personnel.getProjectName()); // projectName对应role
|
|
|
|
|
|
usersManagements.setUserName(personnel.getName()); // name对应userName
|
|
|
|
|
|
} else { |
|
|
|
|
|
// 如果未找到业务员信息,使用默认值
|
|
|
|
|
|
usersManagements.setManagerId(userId); |
|
|
|
|
|
usersManagements.setManagercompany(managercompany); |
|
|
|
|
|
usersManagements.setManagerdepartment(managerdepartment); |
|
|
|
|
|
usersManagements.setOrganization(organization); |
|
|
|
|
|
usersManagements.setRole(role); |
|
|
|
|
|
usersManagements.setUserName(assignedUser); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// 记录归还操作
|
|
|
// 更新或插入usermanagements表
|
|
|
InformationTra tra = createInformationTra( |
|
|
UsersManagements existing = usersManagementsMapper.findByUserId(userId); |
|
|
managercompany, |
|
|
if (existing != null) { |
|
|
managerdepartment, |
|
|
usersManagements.setId(existing.getId()); |
|
|
organization, |
|
|
usersManagements.setCreated_at(existing.getCreated_at()); |
|
|
role, |
|
|
usersManagements.setUpdated_at(LocalDateTime.now()); |
|
|
userName, |
|
|
usersManagementsMapper.update(usersManagements); |
|
|
assistant, |
|
|
} else { |
|
|
userId, |
|
|
usersManagements.setCreated_at(LocalDateTime.now()); |
|
|
"归还客户到" + type |
|
|
usersManagements.setUpdated_at(LocalDateTime.now()); |
|
|
); |
|
|
usersManagementsMapper.insert(usersManagements); |
|
|
informationTraService.recordUserOperation(tra); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 记录归还操作
|
|
|
|
|
|
InformationTra tra = createInformationTra( |
|
|
|
|
|
managercompany, |
|
|
|
|
|
managerdepartment, |
|
|
|
|
|
organization, |
|
|
|
|
|
role, |
|
|
|
|
|
userName, |
|
|
|
|
|
assistant, |
|
|
|
|
|
userId, |
|
|
|
|
|
"归还客户并分配给" + assignedUser |
|
|
|
|
|
); |
|
|
|
|
|
informationTraService.recordUserOperation(tra); |
|
|
|
|
|
} else { |
|
|
|
|
|
// 正常放入公海池
|
|
|
|
|
|
// 1. 更新 users 表,修改 type 字段
|
|
|
|
|
|
usersMapper.updateUserTypeAndClearFollowup(params); |
|
|
|
|
|
|
|
|
|
|
|
// 2. 清除 usermanagements 表中的记录
|
|
|
|
|
|
usersMapper.clearUsersManagements(params); |
|
|
|
|
|
|
|
|
|
|
|
// 记录归还操作
|
|
|
|
|
|
InformationTra tra = createInformationTra( |
|
|
|
|
|
managercompany, |
|
|
|
|
|
managerdepartment, |
|
|
|
|
|
organization, |
|
|
|
|
|
role, |
|
|
|
|
|
userName, |
|
|
|
|
|
assistant, |
|
|
|
|
|
userId, |
|
|
|
|
|
"归还客户到" + type |
|
|
|
|
|
); |
|
|
|
|
|
informationTraService.recordUserOperation(tra); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
result.put("success", true); |
|
|
result.put("success", true); |
|
|
result.put("message", "归还成功"); |
|
|
result.put("message", "归还成功"); |
|
|
@ -306,6 +392,7 @@ public class UserServiceImpl implements UserService { |
|
|
|
|
|
|
|
|
try { |
|
|
try { |
|
|
String userId = (String) params.get("userId"); |
|
|
String userId = (String) params.get("userId"); |
|
|
|
|
|
String systemType = (String) params.get("systemType"); // 大贸易系统或小品种系统
|
|
|
String userName = (String) params.get("userName"); |
|
|
String userName = (String) params.get("userName"); |
|
|
String managercompany = (String) params.get("managercompany"); |
|
|
String managercompany = (String) params.get("managercompany"); |
|
|
String managerdepartment = (String) params.get("managerdepartment"); |
|
|
String managerdepartment = (String) params.get("managerdepartment"); |
|
|
@ -313,14 +400,41 @@ public class UserServiceImpl implements UserService { |
|
|
String role = (String) params.get("role"); |
|
|
String role = (String) params.get("role"); |
|
|
String assistant = (String) params.get("assistant"); |
|
|
String assistant = (String) params.get("assistant"); |
|
|
|
|
|
|
|
|
if (userId == null) { |
|
|
if (userId == null || systemType == null) { |
|
|
result.put("success", false); |
|
|
result.put("success", false); |
|
|
result.put("message", "缺少必要参数"); |
|
|
result.put("message", "缺少必要参数"); |
|
|
return result; |
|
|
return result; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 更新 users 表,设置 sync_statuss 字段值为 0
|
|
|
// 获取客户信息,判断客户类型
|
|
|
usersMapper.updateSyncStatusToZero(params); |
|
|
Users user = usersMapper.findByUserId(userId); |
|
|
|
|
|
if (user == null) { |
|
|
|
|
|
result.put("success", false); |
|
|
|
|
|
result.put("message", "客户不存在"); |
|
|
|
|
|
return result; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
String userType = user.getType(); |
|
|
|
|
|
Integer syncStatus = 0; |
|
|
|
|
|
|
|
|
|
|
|
// 根据系统类型和客户类型设置sync_statuss值
|
|
|
|
|
|
if ("大贸易系统".equals(systemType)) { |
|
|
|
|
|
if ("seller".equals(userType) || "both".equals(userType)) { |
|
|
|
|
|
syncStatus = 1; |
|
|
|
|
|
} else { |
|
|
|
|
|
syncStatus = 0; |
|
|
|
|
|
} |
|
|
|
|
|
} else if ("小品种系统".equals(systemType)) { |
|
|
|
|
|
if ("seller".equals(userType) || "both".equals(userType)) { |
|
|
|
|
|
syncStatus = 3; |
|
|
|
|
|
} else { |
|
|
|
|
|
syncStatus = 2; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 更新sync_statuss值
|
|
|
|
|
|
params.put("syncStatus", syncStatus); |
|
|
|
|
|
usersMapper.updateSyncStatusWithValue(params); |
|
|
|
|
|
|
|
|
// 记录操作
|
|
|
// 记录操作
|
|
|
InformationTra tra = createInformationTra( |
|
|
InformationTra tra = createInformationTra( |
|
|
@ -331,7 +445,7 @@ public class UserServiceImpl implements UserService { |
|
|
userName, |
|
|
userName, |
|
|
assistant, |
|
|
assistant, |
|
|
userId, |
|
|
userId, |
|
|
"简道云操作" |
|
|
"简道云操作 - " + systemType |
|
|
); |
|
|
); |
|
|
informationTraService.recordUserOperation(tra); |
|
|
informationTraService.recordUserOperation(tra); |
|
|
|
|
|
|
|
|
|