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.
219 lines
9.2 KiB
219 lines
9.2 KiB
package com.example.web.controller;
|
|
|
|
import com.example.web.dto.ManagerAuthInfo;
|
|
import com.example.web.service.FollowUpService;
|
|
import com.example.web.service.InformationTraService;
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
@RestController
|
|
@RequestMapping("/api/followup")
|
|
public class FollowupController {
|
|
|
|
@Autowired
|
|
private FollowUpService followUpService;
|
|
|
|
@Autowired
|
|
private InformationTraService informationTraService;
|
|
|
|
/**
|
|
* 根据电话号码获取跟进信息
|
|
* @param phoneNumber 电话号码
|
|
* @param dataSource 数据源(primary或wechat)
|
|
* @return 跟进信息
|
|
*/
|
|
@GetMapping("/get")
|
|
public ResponseEntity<String> getFollowUp(
|
|
@RequestParam String phoneNumber) {
|
|
try {
|
|
String followup = followUpService.getFollowUpByPhone(phoneNumber);
|
|
return ResponseEntity.ok(followup);
|
|
} catch (Exception e) {
|
|
return ResponseEntity.internalServerError().body("获取跟进信息失败:" + e.getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 从请求中获取管理员认证信息
|
|
* @param request 请求对象
|
|
* @return 管理员认证信息
|
|
*/
|
|
private ManagerAuthInfo getManagerAuthInfoFromRequest(HttpServletRequest request) {
|
|
try {
|
|
// 记录请求中所有参数,便于调试
|
|
System.out.println("🔍 开始获取认证信息,请求参数:");
|
|
java.util.Enumeration<String> parameterNames = request.getParameterNames();
|
|
while (parameterNames.hasMoreElements()) {
|
|
String paramName = parameterNames.nextElement();
|
|
String paramValue = request.getParameter(paramName);
|
|
System.out.println(" " + paramName + " = " + paramValue);
|
|
}
|
|
System.out.println("🔍 请求参数记录完成");
|
|
|
|
// 记录URL查询参数
|
|
System.out.println("🔍 URL查询参数:");
|
|
String queryString = request.getQueryString();
|
|
System.out.println(" queryString = " + queryString);
|
|
|
|
// 从请求参数和URL查询参数中获取认证信息
|
|
// 优先从请求参数中获取,其次从URL查询参数中获取
|
|
String managerId = getParameterFromRequestOrQueryString(request, "managerId");
|
|
String organization = getParameterFromRequestOrQueryString(request, "organization");
|
|
String role = getParameterFromRequestOrQueryString(request, "role");
|
|
String userName = getParameterFromRequestOrQueryString(request, "userName");
|
|
String assistant = getParameterFromRequestOrQueryString(request, "assistant");
|
|
|
|
// 支持两种参数名:managerCompany/managerDepartment 和 company/department
|
|
String managerCompany = getParameterFromRequestOrQueryString(request, "managerCompany");
|
|
String managerDepartment = getParameterFromRequestOrQueryString(request, "managerDepartment");
|
|
|
|
// 如果managerCompany或managerDepartment为空,尝试使用company和department参数
|
|
if (managerCompany == null || managerCompany.trim().isEmpty()) {
|
|
managerCompany = getParameterFromRequestOrQueryString(request, "company");
|
|
}
|
|
if (managerDepartment == null || managerDepartment.trim().isEmpty()) {
|
|
managerDepartment = getParameterFromRequestOrQueryString(request, "department");
|
|
}
|
|
|
|
// 解码URL编码的参数
|
|
if (organization != null) {
|
|
organization = java.net.URLDecoder.decode(organization, "UTF-8");
|
|
}
|
|
if (role != null) {
|
|
role = java.net.URLDecoder.decode(role, "UTF-8");
|
|
}
|
|
if (userName != null) {
|
|
userName = java.net.URLDecoder.decode(userName, "UTF-8");
|
|
}
|
|
if (assistant != null) {
|
|
assistant = java.net.URLDecoder.decode(assistant, "UTF-8");
|
|
}
|
|
if (managerCompany != null) {
|
|
managerCompany = java.net.URLDecoder.decode(managerCompany, "UTF-8");
|
|
}
|
|
if (managerDepartment != null) {
|
|
managerDepartment = java.net.URLDecoder.decode(managerDepartment, "UTF-8");
|
|
}
|
|
|
|
// 记录解码后的参数值
|
|
System.out.println("🔍 解码后的参数值:");
|
|
System.out.println(" managerId = " + managerId);
|
|
System.out.println(" organization = " + organization);
|
|
System.out.println(" role = " + role);
|
|
System.out.println(" userName = " + userName);
|
|
System.out.println(" assistant = " + assistant);
|
|
System.out.println(" managerCompany = " + managerCompany);
|
|
System.out.println(" managerDepartment = " + managerDepartment);
|
|
|
|
// 验证必填参数
|
|
if (userName == null || userName.trim().isEmpty()) {
|
|
System.out.println("❌ 用户名不能为空");
|
|
return null;
|
|
}
|
|
|
|
// 验证公司和部门信息
|
|
if (managerCompany == null || managerCompany.trim().isEmpty()) {
|
|
System.out.println("❌ 公司信息不能为空");
|
|
return null;
|
|
}
|
|
if (managerDepartment == null || managerDepartment.trim().isEmpty()) {
|
|
System.out.println("❌ 部门信息不能为空");
|
|
return null;
|
|
}
|
|
|
|
// 使用正确的构造器创建ManagerAuthInfo对象
|
|
ManagerAuthInfo authInfo = new ManagerAuthInfo(
|
|
managerId,
|
|
managerCompany,
|
|
managerDepartment,
|
|
organization,
|
|
role,
|
|
userName,
|
|
assistant
|
|
);
|
|
|
|
System.out.println("✅ 认证信息获取成功:" + authInfo.toString());
|
|
return authInfo;
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 从请求参数或URL查询参数中获取参数值
|
|
* 优先从请求参数中获取,其次从URL查询参数中获取
|
|
* @param request 请求对象
|
|
* @param paramName 参数名
|
|
* @return 参数值
|
|
*/
|
|
private String getParameterFromRequestOrQueryString(HttpServletRequest request, String paramName) {
|
|
// 先从请求参数中获取
|
|
String paramValue = request.getParameter(paramName);
|
|
if (paramValue != null && !paramValue.trim().isEmpty()) {
|
|
return paramValue;
|
|
}
|
|
|
|
// 如果请求参数中没有,尝试从URL查询参数中获取
|
|
try {
|
|
String queryString = request.getQueryString();
|
|
if (queryString != null) {
|
|
// 解析queryString
|
|
String[] pairs = queryString.split("&");
|
|
for (String pair : pairs) {
|
|
String[] keyValue = pair.split("=");
|
|
if (keyValue.length == 2 && keyValue[0].equals(paramName)) {
|
|
return keyValue[1];
|
|
}
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
System.err.println("解析URL查询参数失败:" + e.getMessage());
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* 保存跟进信息
|
|
* @param phoneNumber 电话号码
|
|
* @param followup 跟进信息
|
|
* @return 保存结果
|
|
*/
|
|
@PostMapping("/save")
|
|
public ResponseEntity<String> saveFollowUp(
|
|
@RequestParam String phoneNumber,
|
|
@RequestParam String followup,
|
|
HttpServletRequest request) {
|
|
try {
|
|
ManagerAuthInfo authInfo = getManagerAuthInfoFromRequest(request);
|
|
boolean result = followUpService.saveFollowUp(phoneNumber, followup);
|
|
if (result) {
|
|
// 只有当authInfo不为null时才记录操作事件,确保负责人信息完整
|
|
if (authInfo != null) {
|
|
// 记录跟进信息更新操作
|
|
informationTraService.recordOperationEvent(
|
|
phoneNumber,
|
|
"", // 跟进记录可能无法获取客户名称,留空
|
|
phoneNumber + "-更新跟进",
|
|
authInfo.getManagercompany(),
|
|
authInfo.getManagerdepartment(),
|
|
authInfo.getOrganization(),
|
|
authInfo.getRole(),
|
|
authInfo.getUserName(),
|
|
authInfo.getAssistant()
|
|
);
|
|
} else {
|
|
System.err.println("❌ 认证信息为空,无法记录操作事件");
|
|
}
|
|
return ResponseEntity.ok("跟进信息保存成功");
|
|
} else {
|
|
return ResponseEntity.badRequest().body("跟进信息保存失败");
|
|
}
|
|
} catch (Exception e) {
|
|
return ResponseEntity.internalServerError().body("保存跟进信息失败:" + e.getMessage());
|
|
}
|
|
}
|
|
}
|
|
|