You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
263 lines
11 KiB
263 lines
11 KiB
package com.example.web.controller;
|
|
|
|
import com.example.web.entity.Login;
|
|
import com.example.web.service.CustomerService;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
|
|
/**
|
|
* @Description: 客户数据REST控制器
|
|
*/
|
|
@RestController
|
|
@RequestMapping("/api/customer")
|
|
public class CustomerRestController {
|
|
|
|
@Autowired
|
|
private CustomerService customerService;
|
|
|
|
/**
|
|
* 新增客户数据
|
|
* @param customerData 客户数据,包含企业、联系人和负责人信息
|
|
* @return 响应结果
|
|
*/
|
|
@PostMapping
|
|
public Map<String, Object> addCustomer(@RequestParam Map<String, Object> customerData) {
|
|
Map<String, Object> response = new HashMap<>();
|
|
try {
|
|
// 调用服务层方法添加客户
|
|
boolean success = customerService.addCustomer(customerData);
|
|
|
|
if (success) {
|
|
response.put("success", true);
|
|
response.put("message", "客户添加成功");
|
|
} else {
|
|
response.put("success", false);
|
|
response.put("message", "客户添加失败");
|
|
}
|
|
} catch (Exception e) {
|
|
response.put("success", false);
|
|
response.put("message", "客户添加失败: " + e.getMessage());
|
|
e.printStackTrace();
|
|
}
|
|
return response;
|
|
}
|
|
|
|
/**
|
|
* 更新客户数据
|
|
* @param request 客户数据,包含企业、联系人和负责人信息,使用电话号码作为唯一标识,以及操作人信息
|
|
* @return 响应结果
|
|
*/
|
|
@PostMapping("/update")
|
|
public Map<String, Object> updateCustomer(@RequestBody Map<String, Object> request) {
|
|
Map<String, Object> response = new HashMap<>();
|
|
try {
|
|
System.out.println("DEBUG: 收到客户更新请求,数据: " + request);
|
|
|
|
// 获取客户数据
|
|
Map<String, Object> customerData = new HashMap<>(request);
|
|
|
|
// 获取操作人信息
|
|
Map<String, Object> operatorInfo = (Map<String, Object>) request.get("operatorInfo");
|
|
if (operatorInfo == null) {
|
|
operatorInfo = new HashMap<>();
|
|
}
|
|
|
|
// 创建登录者信息对象
|
|
Login login = new Login();
|
|
login.setProjectName((String) operatorInfo.get("role"));
|
|
login.setUserName((String) operatorInfo.get("userName"));
|
|
login.setManagercompany((String) operatorInfo.get("company"));
|
|
login.setManagerdepartment((String) operatorInfo.get("department"));
|
|
login.setOrganization((String) operatorInfo.get("organization"));
|
|
|
|
// 调用服务层方法更新客户
|
|
boolean success = customerService.updateCustomer(customerData, login);
|
|
|
|
System.out.println("DEBUG: 客户更新结果: " + success);
|
|
|
|
if (success) {
|
|
response.put("success", true);
|
|
response.put("message", "客户更新成功");
|
|
} else {
|
|
response.put("success", false);
|
|
response.put("message", "客户更新失败: 未找到客户信息或更新操作失败");
|
|
}
|
|
} catch (Exception e) {
|
|
System.out.println("DEBUG: 客户更新异常,异常信息: " + e.getMessage());
|
|
e.printStackTrace();
|
|
response.put("success", false);
|
|
response.put("message", "客户更新失败: " + e.getMessage());
|
|
}
|
|
System.out.println("DEBUG: 客户更新响应: " + response);
|
|
return response;
|
|
}
|
|
|
|
/**
|
|
* 跟进客户
|
|
* @param request 跟进请求,包含电话号码、跟进内容、数据源和操作人信息
|
|
* @return 响应结果
|
|
*/
|
|
@PostMapping("/followup")
|
|
public Map<String, Object> followupCustomer(@RequestBody Map<String, Object> request) {
|
|
Map<String, Object> response = new HashMap<>();
|
|
try {
|
|
System.out.println("DEBUG: 收到客户跟进请求,数据: " + request);
|
|
|
|
String phoneNumber = (String) request.get("phoneNumber");
|
|
String followupContent = (String) request.get("followup");
|
|
String dataSource = (String) request.get("dataSource");
|
|
|
|
// 获取操作人信息
|
|
Map<String, Object> operatorInfo = (Map<String, Object>) request.get("operatorInfo");
|
|
if (operatorInfo == null) {
|
|
operatorInfo = new HashMap<>();
|
|
}
|
|
|
|
// 创建登录者信息对象
|
|
Login login = new Login();
|
|
login.setProjectName((String) operatorInfo.get("role"));
|
|
login.setUserName((String) operatorInfo.get("userName"));
|
|
login.setManagercompany((String) operatorInfo.get("company"));
|
|
login.setManagerdepartment((String) operatorInfo.get("department"));
|
|
login.setOrganization((String) operatorInfo.get("organization"));
|
|
|
|
if (phoneNumber == null || phoneNumber.isEmpty() || followupContent == null || dataSource == null) {
|
|
response.put("success", false);
|
|
response.put("message", "跟进失败: 参数不完整");
|
|
return response;
|
|
}
|
|
|
|
// 调用服务层方法跟进客户
|
|
boolean success = customerService.followupCustomer(phoneNumber, followupContent, dataSource, login);
|
|
|
|
System.out.println("DEBUG: 客户跟进结果: " + success);
|
|
|
|
if (success) {
|
|
response.put("success", true);
|
|
response.put("message", "跟进成功");
|
|
} else {
|
|
response.put("success", false);
|
|
response.put("message", "跟进失败: 未找到客户信息或更新操作失败");
|
|
}
|
|
} catch (Exception e) {
|
|
System.out.println("DEBUG: 客户跟进异常,异常信息: " + e.getMessage());
|
|
e.printStackTrace();
|
|
response.put("success", false);
|
|
response.put("message", "跟进失败: " + e.getMessage());
|
|
}
|
|
System.out.println("DEBUG: 客户跟进响应: " + response);
|
|
return response;
|
|
}
|
|
|
|
/**
|
|
* 记录客户查看操作
|
|
* @param request 查看请求,包含客户ID和操作人信息
|
|
* @return 响应结果
|
|
*/
|
|
@PostMapping("/view")
|
|
public Map<String, Object> recordCustomerView(@RequestBody Map<String, Object> request) {
|
|
Map<String, Object> response = new HashMap<>();
|
|
try {
|
|
System.out.println("DEBUG: 收到客户查看请求,数据: " + request);
|
|
|
|
String userId = (String) request.get("userId");
|
|
|
|
// 获取操作人信息
|
|
Map<String, Object> operatorInfo = (Map<String, Object>) request.get("operatorInfo");
|
|
if (operatorInfo == null) {
|
|
operatorInfo = new HashMap<>();
|
|
}
|
|
|
|
// 创建登录者信息对象
|
|
Login login = new Login();
|
|
login.setProjectName((String) operatorInfo.get("role"));
|
|
login.setUserName((String) operatorInfo.get("userName"));
|
|
login.setManagercompany((String) operatorInfo.get("company"));
|
|
login.setManagerdepartment((String) operatorInfo.get("department"));
|
|
login.setOrganization((String) operatorInfo.get("organization"));
|
|
|
|
if (userId == null || userId.isEmpty()) {
|
|
response.put("success", false);
|
|
response.put("message", "记录查看操作失败: 参数不完整");
|
|
return response;
|
|
}
|
|
|
|
// 调用服务层方法记录客户查看操作
|
|
boolean success = customerService.recordCustomerView(userId, login);
|
|
|
|
System.out.println("DEBUG: 记录客户查看操作结果: " + success);
|
|
|
|
if (success) {
|
|
response.put("success", true);
|
|
response.put("message", "记录查看操作成功");
|
|
} else {
|
|
response.put("success", false);
|
|
response.put("message", "记录查看操作失败");
|
|
}
|
|
} catch (Exception e) {
|
|
System.out.println("DEBUG: 记录客户查看操作异常,异常信息: " + e.getMessage());
|
|
e.printStackTrace();
|
|
response.put("success", false);
|
|
response.put("message", "记录查看操作失败: " + e.getMessage());
|
|
}
|
|
System.out.println("DEBUG: 记录客户查看操作响应: " + response);
|
|
return response;
|
|
}
|
|
|
|
/**
|
|
* 认领客户
|
|
* @param request 认领请求,包含客户ID和操作人信息
|
|
* @return 响应结果
|
|
*/
|
|
@PostMapping("/claim")
|
|
public Map<String, Object> claimCustomer(@RequestBody Map<String, Object> request) {
|
|
Map<String, Object> response = new HashMap<>();
|
|
try {
|
|
System.out.println("DEBUG: 收到客户认领请求,数据: " + request);
|
|
|
|
String customerId = (String) request.get("customerId");
|
|
|
|
// 获取操作人信息
|
|
Map<String, Object> operatorInfo = (Map<String, Object>) request.get("operatorInfo");
|
|
if (operatorInfo == null) {
|
|
operatorInfo = new HashMap<>();
|
|
}
|
|
|
|
// 创建登录者信息对象
|
|
Login login = new Login();
|
|
login.setProjectName((String) operatorInfo.get("role"));
|
|
login.setUserName((String) operatorInfo.get("userName"));
|
|
login.setManagercompany((String) operatorInfo.get("company"));
|
|
login.setManagerdepartment((String) operatorInfo.get("department"));
|
|
login.setOrganization((String) operatorInfo.get("organization"));
|
|
|
|
if (customerId == null || customerId.isEmpty()) {
|
|
response.put("success", false);
|
|
response.put("message", "客户认领失败: 参数不完整");
|
|
return response;
|
|
}
|
|
|
|
// 调用服务层方法认领客户
|
|
boolean success = customerService.claimCustomer(customerId, login);
|
|
|
|
System.out.println("DEBUG: 客户认领结果: " + success);
|
|
|
|
if (success) {
|
|
response.put("success", true);
|
|
response.put("message", "客户认领成功");
|
|
} else {
|
|
response.put("success", false);
|
|
response.put("message", "客户认领失败");
|
|
}
|
|
} catch (Exception e) {
|
|
System.out.println("DEBUG: 客户认领异常,异常信息: " + e.getMessage());
|
|
e.printStackTrace();
|
|
response.put("success", false);
|
|
response.put("message", "客户认领失败: " + e.getMessage());
|
|
}
|
|
return response;
|
|
}
|
|
}
|