Browse Source

添加用户跟进历史功能

KH
Trae AI 4 weeks ago
parent
commit
b4feede4ca
  1. 5
      web/src/main/java/com/example/web/controller/UserController.java
  2. 69
      web/src/main/java/com/example/web/entity/UserFollowupHistory.java
  3. 27
      web/src/main/java/com/example/web/mapper/UserFollowupHistoryMapper.java
  4. 3
      web/src/main/java/com/example/web/service/UserService.java
  5. 40
      web/src/main/java/com/example/web/service/impl/UserServiceImpl.java
  6. 24
      web/src/main/resources/mapper/UserFollowupHistoryMapper.xml
  7. 62
      web/src/main/resources/static/index.html

5
web/src/main/java/com/example/web/controller/UserController.java

@ -100,6 +100,11 @@ public class UserController {
return userService.getManagersList();
}
@GetMapping("/users/followupHistory")
public List<com.example.web.entity.UserFollowupHistory> getFollowupHistory(@RequestParam String userId) {
return userService.getFollowupHistory(userId);
}
@PostMapping("/users/assign")
public Map<String, Object> assignCustomers(@RequestBody Map<String, Object> params) {
return userService.assignCustomers(params);

69
web/src/main/java/com/example/web/entity/UserFollowupHistory.java

@ -0,0 +1,69 @@
package com.example.web.entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.time.LocalDateTime;
/**
* 客户历史跟进记录表实体类
*/
@Data
@NoArgsConstructor
public class UserFollowupHistory {
private Integer id; // 主键ID
private String user_id; // 关联的用户ID,对应users表的userId
private String followup_content; // 跟进内容
private String followup_person; // 跟进人
private String phone_number; // 客户电话号码
private LocalDateTime created_at; // 创建时间
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getUser_id() {
return user_id;
}
public void setUser_id(String user_id) {
this.user_id = user_id;
}
public String getFollowup_content() {
return followup_content;
}
public void setFollowup_content(String followup_content) {
this.followup_content = followup_content;
}
public String getFollowup_person() {
return followup_person;
}
public void setFollowup_person(String followup_person) {
this.followup_person = followup_person;
}
public String getPhone_number() {
return phone_number;
}
public void setPhone_number(String phone_number) {
this.phone_number = phone_number;
}
public LocalDateTime getCreated_at() {
return created_at;
}
public void setCreated_at(LocalDateTime created_at) {
this.created_at = created_at;
}
}

27
web/src/main/java/com/example/web/mapper/UserFollowupHistoryMapper.java

@ -0,0 +1,27 @@
package com.example.web.mapper;
import com.example.web.entity.UserFollowupHistory;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 客户历史跟进记录表Mapper
*/
@Mapper
public interface UserFollowupHistoryMapper {
/**
* 插入跟进记录
* @param userFollowupHistory 跟进记录实体
* @return 影响行数
*/
int insert(UserFollowupHistory userFollowupHistory);
/**
* 根据用户ID查询跟进记录
* @param user_id 用户ID
* @return 跟进记录列表
*/
List<UserFollowupHistory> selectByUserId(@Param("user_id") String user_id);
}

3
web/src/main/java/com/example/web/service/UserService.java

@ -35,4 +35,7 @@ public interface UserService {
// 获取人员列表
Map<String, Object> getPersonnelList();
// 获取跟进历史记录
List<com.example.web.entity.UserFollowupHistory> getFollowupHistory(String userId);
}

40
web/src/main/java/com/example/web/service/impl/UserServiceImpl.java

@ -4,12 +4,14 @@ import com.example.web.entity.InformationTra;
import com.example.web.entity.Managers;
import com.example.web.entity.Personnel;
import com.example.web.entity.Product;
import com.example.web.entity.UserFollowupHistory;
import com.example.web.entity.UserTrace;
import com.example.web.entity.Users;
import com.example.web.entity.UsersManagements;
import com.example.web.entity.CustomerApply;
import com.example.web.mapper.PersonnelMapper;
import com.example.web.mapper.ProductMapper;
import com.example.web.mapper.UserFollowupHistoryMapper;
import com.example.web.mapper.UserTraceMapper;
import com.example.web.mapper.UsersMapper;
import com.example.web.mapper.ManagersMapper;
@ -54,6 +56,9 @@ public class UserServiceImpl implements UserService {
@Autowired
private UserTraceMapper userTraceMapper;
@Autowired
private UserFollowupHistoryMapper userFollowupHistoryMapper;
@Override
public Map<String, Object> getUserList(Map<String, Object> requestParams) {
Map<String, Object> result = new HashMap<>();
@ -213,6 +218,27 @@ public class UserServiceImpl implements UserService {
// 更新跟进信息
usersMapper.updateFollowup(params);
// 写入跟进历史记录
if (user != null) {
// 保存当前数据源
String currentDataSource = DataSourceContextHolder.getDataSource();
try {
// 切换到wechat数据源
DataSourceContextHolder.setDataSource("wechat");
UserFollowupHistory history = new UserFollowupHistory();
history.setUser_id(userId);
history.setFollowup_content(followup);
history.setFollowup_person(userName);
history.setPhone_number(user.getPhoneNumber());
history.setCreated_at(LocalDateTime.now());
userFollowupHistoryMapper.insert(history);
} finally {
// 恢复原数据源
DataSourceContextHolder.setDataSource(currentDataSource);
}
}
// 记录跟进操作
InformationTra tra = createInformationTra(
managercompany,
@ -881,4 +907,18 @@ public class UserServiceImpl implements UserService {
}
return result;
}
@Override
public List<UserFollowupHistory> getFollowupHistory(String userId) {
// 保存当前数据源
String currentDataSource = DataSourceContextHolder.getDataSource();
try {
// 切换到wechat数据源
DataSourceContextHolder.setDataSource("wechat");
return userFollowupHistoryMapper.selectByUserId(userId);
} finally {
// 恢复原数据源
DataSourceContextHolder.setDataSource(currentDataSource);
}
}
}

24
web/src/main/resources/mapper/UserFollowupHistoryMapper.xml

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.example.web.mapper.UserFollowupHistoryMapper">
<resultMap id="BaseResultMap" type="com.example.web.entity.UserFollowupHistory">
<id column="id" property="id" />
<result column="user_id" property="user_id" />
<result column="followup_content" property="followup_content" />
<result column="followup_person" property="followup_person" />
<result column="phone_number" property="phone_number" />
<result column="created_at" property="created_at" />
</resultMap>
<insert id="insert" parameterType="com.example.web.entity.UserFollowupHistory">
INSERT INTO user_followup_history (user_id, followup_content, followup_person, phone_number, created_at)
VALUES (#{user_id}, #{followup_content}, #{followup_person}, #{phone_number}, #{created_at})
</insert>
<select id="selectByUserId" resultMap="BaseResultMap">
SELECT id, user_id, followup_content, followup_person, phone_number, created_at
FROM user_followup_history
WHERE user_id = #{user_id}
ORDER BY created_at DESC
</select>
</mapper>

62
web/src/main/resources/static/index.html

@ -4944,6 +4944,14 @@
<span id="detailComparenum" style="font-size: 14px; color: #333;"></span>
</div>
</div>
<!-- 跟进历史记录 -->
<div style="margin-bottom: 16px;">
<h4 style="font-size: 16px; font-weight: 600; color: #333; margin-bottom: 12px; padding-bottom: 8px; border-bottom: 1px solid #e8e8e8;">跟进历史记录</h4>
<div id="followupHistoryList" style="max-height: 300px; overflow-y: auto; border: 1px solid #e8e8e8; border-radius: 4px; padding: 12px; background-color: #fafafa;">
<div style="text-align: center; color: #999; padding: 20px;">加载中...</div>
</div>
</div>
</div>
<div style="text-align: center; margin-top: 24px;">
<button onclick="closeDetailModal()" style="padding: 10px 24px; border: none; border-radius: 4px; font-size: 14px; color: white; background-color: #1890ff; cursor: pointer; transition: all 0.3s ease;">关闭</button>
@ -6113,6 +6121,9 @@
document.getElementById('detailModal').style.display = 'block';
// 防止背景滚动
document.body.style.overflow = 'hidden';
// 获取并显示跟进历史记录
loadFollowupHistory(userId);
}
function closeDetailModal() {
@ -6121,6 +6132,57 @@
document.body.style.overflow = 'auto';
}
// 加载跟进历史记录
function loadFollowupHistory(userId) {
var url = '/KH/api/users/followupHistory?userId=' + encodeURIComponent(userId);
var followupHistoryList = document.getElementById('followupHistoryList');
followupHistoryList.innerHTML = '<div style="text-align: center; color: #999; padding: 20px;">加载中...</div>';
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
if (xhr.status == 200) {
try {
var historyList = JSON.parse(xhr.responseText);
if (historyList && historyList.length > 0) {
var html = '';
historyList.forEach(function(history) {
html += '<div style="background-color: white; border: 1px solid #e8e8e8; border-radius: 4px; padding: 12px; margin-bottom: 10px; box-shadow: 0 1px 2px rgba(0,0,0,0.05);">';
html += '<div style="display: flex; justify-content: space-between; margin-bottom: 8px;">';
html += '<span style="font-size: 14px; font-weight: 500; color: #666;">跟进人:</span>';
html += '<span style="font-size: 14px; color: #333;">' + (history.followup_person || '-') + '</span>';
html += '</div>';
html += '<div style="display: flex; justify-content: space-between; margin-bottom: 8px;">';
html += '<span style="font-size: 14px; font-weight: 500; color: #666;">跟进时间:</span>';
html += '<span style="font-size: 14px; color: #333;">' + (history.created_at ? formatDateTime(history.created_at) : '-') + '</span>';
html += '</div>';
html += '<div style="margin-bottom: 8px;">';
html += '<span style="font-size: 14px; font-weight: 500; color: #666;">跟进内容:</span>';
html += '</div>';
html += '<div style="font-size: 14px; color: #333; line-height: 1.4; background-color: #f8f9fa; padding: 10px; border-radius: 4px; word-break: break-all;">';
html += history.followup_content || '-';
html += '</div>';
html += '</div>';
});
followupHistoryList.innerHTML = html;
} else {
followupHistoryList.innerHTML = '<div style="text-align: center; color: #999; padding: 20px;">暂无跟进历史记录</div>';
}
} catch (e) {
followupHistoryList.innerHTML = '<div style="text-align: center; color: #ff4d4f; padding: 20px;">加载失败,请重试</div>';
console.error('解析跟进历史记录失败:', e);
}
} else {
followupHistoryList.innerHTML = '<div style="text-align: center; color: #ff4d4f; padding: 20px;">加载失败,请重试</div>';
console.error('获取跟进历史记录失败:', xhr.status, xhr.statusText);
}
}
};
xhr.send();
}
function saveJianDaoYun() {
var userId = document.getElementById('jianDaoYunUserId').value;
var usersManagements = userInfo.usersManagements;

Loading…
Cancel
Save