Browse Source

直接覆盖KH分支代码

KH
Trae AI 1 month ago
parent
commit
26bb317baa
  1. 2
      web/src/main/java/com/example/web/config/SecurityConfig.java
  2. 5
      web/src/main/java/com/example/web/controller/UserController.java
  3. 4
      web/src/main/java/com/example/web/entity/CustomerApply.java
  4. 2
      web/src/main/java/com/example/web/mapper/CustomerApplyMapper.java
  5. 3
      web/src/main/java/com/example/web/mapper/PersonnelMapper.java
  6. 3
      web/src/main/java/com/example/web/mapper/UserTraceMapper.java
  7. 3
      web/src/main/java/com/example/web/mapper/UsersMapper.java
  8. 3
      web/src/main/java/com/example/web/service/UserService.java
  9. 124
      web/src/main/java/com/example/web/service/impl/CustomerApplyServiceImpl.java
  10. 86
      web/src/main/java/com/example/web/service/impl/UserServiceImpl.java
  11. 4
      web/src/main/resources/mapper/CustomerApplyMapper.xml
  12. 4
      web/src/main/resources/mapper/PersonnelMapper.xml
  13. 8
      web/src/main/resources/mapper/UserTraceMapper.xml
  14. 4
      web/src/main/resources/mapper/UsersMapper.xml
  15. 797
      web/src/main/resources/static/index.html
  16. 2
      web/src/main/resources/static/login.html

2
web/src/main/java/com/example/web/config/SecurityConfig.java

@ -14,7 +14,7 @@ public class SecurityConfig {
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http http
.authorizeRequests() .authorizeRequests()
.requestMatchers("/login.html", "/index.html", "/api/login", "/api/users/**", "/api/products/**").permitAll() .requestMatchers("/login.html", "/index.html", "/api/login", "/api/users/**", "/api/products/**", "/api/personnel/**").permitAll()
.requestMatchers("/static/**").permitAll() .requestMatchers("/static/**").permitAll()
.anyRequest().authenticated() .anyRequest().authenticated()
.and() .and()

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

@ -139,4 +139,9 @@ public class UserController {
@RequestParam String productId) { @RequestParam String productId) {
return userService.getProductDetail(productId); return userService.getProductDetail(productId);
} }
@GetMapping("/personnel")
public Map<String, Object> getPersonnelList() {
return userService.getPersonnelList();
}
} }

4
web/src/main/java/com/example/web/entity/CustomerApply.java

@ -16,16 +16,18 @@ public class CustomerApply {
private String user_id; // 客户ID private String user_id; // 客户ID
private String sales_id; // 业务员ID private String sales_id; // 业务员ID
private String sales_name; // 业务员姓名 private String sales_name; // 业务员姓名
private String original_manager_name; // 原始负责人姓名
private Integer status; // 申请状态:0-申请中,1-通过,2-失败 private Integer status; // 申请状态:0-申请中,1-通过,2-失败
private LocalDateTime apply_time; // 申请时间 private LocalDateTime apply_time; // 申请时间
private LocalDateTime approve_time; // 审批时间 private LocalDateTime approve_time; // 审批时间
private String approve_by; // 审批人 private String approve_by; // 审批人
private String reason; // 申请理由/失败原因 private String reason; // 申请理由/失败原因
public CustomerApply(String user_id, String sales_id, String sales_name, String reason) { public CustomerApply(String user_id, String sales_id, String sales_name, String original_manager_name, String reason) {
this.user_id = user_id; this.user_id = user_id;
this.sales_id = sales_id; this.sales_id = sales_id;
this.sales_name = sales_name; this.sales_name = sales_name;
this.original_manager_name = original_manager_name;
this.status = 0; // 默认状态为申请中 this.status = 0; // 默认状态为申请中
this.apply_time = LocalDateTime.now(); this.apply_time = LocalDateTime.now();
this.reason = reason; this.reason = reason;

2
web/src/main/java/com/example/web/mapper/CustomerApplyMapper.java

@ -1,5 +1,6 @@
package com.example.web.mapper; package com.example.web.mapper;
import com.example.web.annotation.DataSource;
import com.example.web.entity.CustomerApply; import com.example.web.entity.CustomerApply;
import java.util.List; import java.util.List;
@ -8,6 +9,7 @@ import java.util.Map;
/** /**
* 客户申请Mapper接口 * 客户申请Mapper接口
*/ */
@DataSource("wechat")
public interface CustomerApplyMapper { public interface CustomerApplyMapper {
/** /**

3
web/src/main/java/com/example/web/mapper/PersonnelMapper.java

@ -12,6 +12,9 @@ public interface PersonnelMapper {
@DataSource("primary") @DataSource("primary")
Personnel findByNameAndProjectName(String name, String projectName); Personnel findByNameAndProjectName(String name, String projectName);
@DataSource("primary")
Personnel findByPhoneNumber(String phoneNumber);
@DataSource("primary") @DataSource("primary")
List<Personnel> findAll(); List<Personnel> findAll();
} }

3
web/src/main/java/com/example/web/mapper/UserTraceMapper.java

@ -9,4 +9,7 @@ public interface UserTraceMapper {
@DataSource("wechat") @DataSource("wechat")
List<UserTrace> getProductTraces(String productId); List<UserTrace> getProductTraces(String productId);
@DataSource("wechat")
UserTrace findById(Integer id);
} }

3
web/src/main/java/com/example/web/mapper/UsersMapper.java

@ -75,4 +75,7 @@ public interface UsersMapper {
@DataSource("wechat") @DataSource("wechat")
List<Users> findAllUsers(); List<Users> findAllUsers();
@DataSource("wechat")
Users findByPhoneNumber(String phoneNumber);
} }

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

@ -32,4 +32,7 @@ public interface UserService {
Map<String, Object> applyCustomer(Map<String, Object> params); Map<String, Object> applyCustomer(Map<String, Object> params);
Map<String, Object> approveApply(Map<String, Object> params); Map<String, Object> approveApply(Map<String, Object> params);
List<CustomerApply> getApplyList(Integer status); List<CustomerApply> getApplyList(Integer status);
// 获取人员列表
Map<String, Object> getPersonnelList();
} }

124
web/src/main/java/com/example/web/service/impl/CustomerApplyServiceImpl.java

@ -1,13 +1,17 @@
package com.example.web.service.impl; package com.example.web.service.impl;
import com.example.web.entity.CustomerApply; import com.example.web.entity.CustomerApply;
import com.example.web.entity.InformationTra;
import com.example.web.entity.Personnel; import com.example.web.entity.Personnel;
import com.example.web.entity.UserTrace;
import com.example.web.entity.Users; import com.example.web.entity.Users;
import com.example.web.mapper.CustomerApplyMapper; import com.example.web.mapper.CustomerApplyMapper;
import com.example.web.mapper.PersonnelMapper; import com.example.web.mapper.PersonnelMapper;
import com.example.web.mapper.UserTraceMapper;
import com.example.web.mapper.UsersMapper; import com.example.web.mapper.UsersMapper;
import com.example.web.mapper.UsersManagementsMapper; import com.example.web.mapper.UsersManagementsMapper;
import com.example.web.service.CustomerApplyService; import com.example.web.service.CustomerApplyService;
import com.example.web.service.InformationTraService;
import com.example.web.config.DataSourceContextHolder; import com.example.web.config.DataSourceContextHolder;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -35,26 +39,61 @@ public class CustomerApplyServiceImpl implements CustomerApplyService {
@Autowired @Autowired
private UsersMapper usersMapper; private UsersMapper usersMapper;
@Autowired
private UserTraceMapper userTraceMapper;
@Autowired
private InformationTraService informationTraService;
@Override @Override
public Map<String, Object> submitApply(Map<String, Object> params) { public Map<String, Object> submitApply(Map<String, Object> params) {
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
try { try {
// 切换到wechat数据源 // 获取当前登录信息
DataSourceContextHolder.setDataSource("wechat");
String userId = (String) params.get("userId");
String salesId = (String) params.get("salesId");
String salesName = (String) params.get("salesName"); String salesName = (String) params.get("salesName");
String reason = (String) params.get("reason"); String reason = (String) params.get("reason");
String traceId = (String) params.get("traceId"); // 从前端传递的浏览记录ID
if (userId == null || salesId == null || salesName == null) { if (salesName == null || traceId == null) {
result.put("success", false); result.put("success", false);
result.put("message", "缺少必要参数"); result.put("message", "缺少必要参数");
return result; return result;
} }
// 检查是否已经有申请记录 // 1. 到primary数据源的personnel表里获取业务员的信息
DataSourceContextHolder.setDataSource("primary");
Personnel personnel = personnelMapper.findByName(salesName);
if (personnel == null || personnel.getPhoneNumber() == null) {
result.put("success", false);
result.put("message", "未找到业务员信息");
return result;
}
String phoneNumber = personnel.getPhoneNumber();
// 2. 到wechat数据源的users表里查询业务员的userId
DataSourceContextHolder.setDataSource("wechat");
Users salesUser = usersMapper.findByPhoneNumber(phoneNumber);
if (salesUser == null || salesUser.getUserId() == null) {
result.put("success", false);
result.put("message", "未找到业务员的用户ID");
return result;
}
String salesId = salesUser.getUserId(); // 业务员的ID
// 3. 到wechat数据源的usertraces表里获取相应的客户userId
UserTrace trace = userTraceMapper.findById(Integer.parseInt(traceId));
if (trace == null || trace.getUserId() == null) {
result.put("success", false);
result.put("message", "未找到浏览记录信息");
return result;
}
String userId = trace.getUserId(); // 客户的ID
// 允许自己申请自己,这是合理的测试场景
// 如果需要防止这种情况,可以在此处添加验证
// 4. 检查是否已经有申请记录
CustomerApply existingApply = customerApplyMapper.findByUserIdAndSalesId(userId, salesId); CustomerApply existingApply = customerApplyMapper.findByUserIdAndSalesId(userId, salesId);
if (existingApply != null && existingApply.getStatus() == 0) { if (existingApply != null && existingApply.getStatus() == 0) {
result.put("success", false); result.put("success", false);
@ -62,8 +101,15 @@ public class CustomerApplyServiceImpl implements CustomerApplyService {
return result; return result;
} }
// 创建新的申请记录 // 5. 获取客户的原始负责人信息
CustomerApply apply = new CustomerApply(userId, salesId, salesName, reason); String original_manager_name = null;
com.example.web.entity.UsersManagements existingManagements = usersManagementsMapper.findByUserId(userId);
if (existingManagements != null) {
original_manager_name = existingManagements.getUserName();
}
// 6. 创建新的申请记录
CustomerApply apply = new CustomerApply(userId, salesId, salesName, original_manager_name, reason);
int count = customerApplyMapper.insert(apply); int count = customerApplyMapper.insert(apply);
if (count > 0) { if (count > 0) {
@ -121,20 +167,28 @@ public class CustomerApplyServiceImpl implements CustomerApplyService {
// 根据id查询完整的申请记录 // 根据id查询完整的申请记录
CustomerApply apply = customerApplyMapper.findById(id); CustomerApply apply = customerApplyMapper.findById(id);
if (apply != null) { if (apply != null) {
// 实现更新客户负责人的逻辑 // 1. 使用wechat数据源的customer_apply表里的user_id到usermanagements表里查询
com.example.web.entity.UsersManagements usersManagements = usersManagementsMapper.findByUserId(apply.getUser_id()); com.example.web.entity.UsersManagements usersManagements = usersManagementsMapper.findByUserId(apply.getUser_id());
// 切换到primary数据源查询personnel表 // 2. 将customer_apply表里的original_manager_name的值放到primary数据源的personnel数据源里获取信息
DataSourceContextHolder.setDataSource("primary"); DataSourceContextHolder.setDataSource("primary");
Personnel originalPersonnel = null;
if (apply.getOriginal_manager_name() != null) {
try {
originalPersonnel = personnelMapper.findByName(apply.getOriginal_manager_name());
} catch (Exception e) {
e.printStackTrace();
System.out.println("查询原始负责人信息时发生错误: " + e.getMessage());
}
}
// 从personnel表中查询业务员的详细信息 // 3. 从personnel表中查询业务员的详细信息
Personnel personnel = null; Personnel salesPersonnel = null;
try { try {
// 只通过name查询业务员信息 salesPersonnel = personnelMapper.findByName(apply.getSales_name());
personnel = personnelMapper.findByName(apply.getSales_name());
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
System.out.println("查询Personnel时发生错误: " + e.getMessage()); System.out.println("查询业务员信息时发生错误: " + e.getMessage());
} }
// 切换回wechat数据源 // 切换回wechat数据源
@ -144,11 +198,11 @@ public class CustomerApplyServiceImpl implements CustomerApplyService {
// 更新现有记录 // 更新现有记录
usersManagements.setManagerId(apply.getSales_id()); usersManagements.setManagerId(apply.getSales_id());
usersManagements.setUserName(apply.getSales_name()); usersManagements.setUserName(apply.getSales_name());
if (personnel != null) { if (salesPersonnel != null) {
usersManagements.setManagercompany(personnel.getManagercompany()); usersManagements.setManagercompany(salesPersonnel.getManagercompany());
usersManagements.setManagerdepartment(personnel.getManagerdepartment()); usersManagements.setManagerdepartment(salesPersonnel.getManagerdepartment());
usersManagements.setOrganization(personnel.getOrganization()); usersManagements.setOrganization(salesPersonnel.getOrganization());
usersManagements.setRole(personnel.getProjectName()); // projectName与role同值 usersManagements.setRole(salesPersonnel.getProjectName()); // role与projectName同值
} }
usersManagements.setUpdated_at(LocalDateTime.now()); usersManagements.setUpdated_at(LocalDateTime.now());
usersManagementsMapper.update(usersManagements); usersManagementsMapper.update(usersManagements);
@ -167,11 +221,11 @@ public class CustomerApplyServiceImpl implements CustomerApplyService {
newUsersManagements.setUserId(apply.getUser_id()); newUsersManagements.setUserId(apply.getUser_id());
newUsersManagements.setManagerId(apply.getSales_id()); newUsersManagements.setManagerId(apply.getSales_id());
newUsersManagements.setUserName(apply.getSales_name()); newUsersManagements.setUserName(apply.getSales_name());
if (personnel != null) { if (salesPersonnel != null) {
newUsersManagements.setManagercompany(personnel.getManagercompany()); newUsersManagements.setManagercompany(salesPersonnel.getManagercompany());
newUsersManagements.setManagerdepartment(personnel.getManagerdepartment()); newUsersManagements.setManagerdepartment(salesPersonnel.getManagerdepartment());
newUsersManagements.setOrganization(personnel.getOrganization()); newUsersManagements.setOrganization(salesPersonnel.getOrganization());
newUsersManagements.setRole(personnel.getProjectName()); // projectName与role同值 newUsersManagements.setRole(salesPersonnel.getProjectName()); // role与projectName同值
} }
newUsersManagements.setCreated_at(LocalDateTime.now()); newUsersManagements.setCreated_at(LocalDateTime.now());
newUsersManagements.setUpdated_at(LocalDateTime.now()); newUsersManagements.setUpdated_at(LocalDateTime.now());
@ -185,6 +239,24 @@ public class CustomerApplyServiceImpl implements CustomerApplyService {
System.out.println("客户ID " + apply.getUser_id() + " 在users表中不存在,无法创建usermanagements记录"); System.out.println("客户ID " + apply.getUser_id() + " 在users表中不存在,无法创建usermanagements记录");
} }
} }
// 记录分配操作
try {
com.example.web.entity.InformationTra tra = new com.example.web.entity.InformationTra();
if (salesPersonnel != null) {
tra.setTracompany(salesPersonnel.getManagercompany());
tra.setTradepartment(salesPersonnel.getManagerdepartment());
tra.setTraorganization(salesPersonnel.getOrganization());
tra.setTrarole(salesPersonnel.getProjectName());
}
tra.setTrauserName(apply.getSales_name());
tra.setUserId(apply.getUser_id());
tra.setOperationEvent("申请通过分配客户: " + apply.getSales_name());
informationTraService.recordUserOperation(tra);
} catch (Exception e) {
e.printStackTrace();
System.out.println("记录分配操作时发生错误: " + e.getMessage());
}
} }
} }

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

@ -718,8 +718,76 @@ public class UserServiceImpl implements UserService {
} }
} }
// 处理产品列表,添加销售负责人和创建人信息
List<Map<String, Object>> processedProducts = new ArrayList<>();
for (Product product : products) {
Map<String, Object> productMap = new HashMap<>();
// 复制原有字段
productMap.put("id", product.getId());
productMap.put("productId", product.getProductId());
productMap.put("sellerId", product.getSellerId());
productMap.put("productName", product.getProductName());
productMap.put("price", product.getPrice());
productMap.put("costprice", product.getCostprice());
productMap.put("quantity", product.getQuantity());
productMap.put("grossWeight", product.getGrossWeight());
productMap.put("yolk", product.getYolk());
productMap.put("specification", product.getSpecification());
productMap.put("created_at", product.getCreated_at());
productMap.put("updated_at", product.getUpdated_at());
productMap.put("status", product.getStatus());
productMap.put("region", product.getRegion());
productMap.put("sourceType", product.getSourceType());
productMap.put("supplyStatus", product.getSupplyStatus());
productMap.put("category", product.getCategory());
productMap.put("producting", product.getProducting());
productMap.put("description", product.getDescription());
productMap.put("frequency", product.getFrequency());
productMap.put("contact_phone", product.getContact_phone());
productMap.put("product_contact", product.getProduct_contact());
productMap.put("negotiateStatus", product.getNegotiateStatus());
productMap.put("fullRegion", product.getFullRegion());
productMap.put("createdAt", product.getCreatedAt());
productMap.put("reservedCount", product.getReservedCount());
productMap.put("reservedCountDisplay", product.getReservedCountDisplay());
productMap.put("sales", product.getSales());
productMap.put("totalStock", product.getTotalStock());
productMap.put("originalTotalStock", product.getOriginalTotalStock());
productMap.put("displaySpecification", product.getDisplaySpecification());
productMap.put("displayYolk", product.getDisplayYolk());
// 计算销售负责人
if (product.getContact_phone() != null && !product.getContact_phone().isEmpty()) {
try {
Personnel salesPersonnel = personnelMapper.findByPhoneNumber(product.getContact_phone());
if (salesPersonnel != null) {
productMap.put("salesManager", salesPersonnel.getName());
}
} catch (Exception e) {
e.printStackTrace();
}
}
// 计算创建人
if (product.getSellerId() != null && !product.getSellerId().isEmpty()) {
try {
Users seller = usersMapper.findByUserId(product.getSellerId());
if (seller != null && seller.getPhoneNumber() != null) {
Personnel creatorPersonnel = personnelMapper.findByPhoneNumber(seller.getPhoneNumber());
if (creatorPersonnel != null) {
productMap.put("creator", creatorPersonnel.getName());
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
processedProducts.add(productMap);
}
result.put("success", true); result.put("success", true);
result.put("products", products); result.put("products", processedProducts);
result.put("total", total); result.put("total", total);
result.put("page", page); result.put("page", page);
result.put("size", size); result.put("size", size);
@ -778,4 +846,20 @@ public class UserServiceImpl implements UserService {
public List<CustomerApply> getApplyList(Integer status) { public List<CustomerApply> getApplyList(Integer status) {
return customerApplyService.getApplyList(status); return customerApplyService.getApplyList(status);
} }
@Override
public Map<String, Object> getPersonnelList() {
Map<String, Object> result = new HashMap<>();
try {
// 从primary数据源的personnel表获取所有人员
List<Personnel> personnelList = personnelMapper.findAll();
result.put("success", true);
result.put("personnel", personnelList);
} catch (Exception e) {
e.printStackTrace();
result.put("success", false);
result.put("message", "获取人员列表失败: " + e.getMessage());
}
return result;
}
} }

4
web/src/main/resources/mapper/CustomerApplyMapper.xml

@ -6,8 +6,8 @@
<mapper namespace="com.example.web.mapper.CustomerApplyMapper"> <mapper namespace="com.example.web.mapper.CustomerApplyMapper">
<insert id="insert" parameterType="com.example.web.entity.CustomerApply"> <insert id="insert" parameterType="com.example.web.entity.CustomerApply">
INSERT INTO customer_apply (user_id, sales_id, sales_name, status, apply_time, reason) INSERT INTO customer_apply (user_id, sales_id, sales_name, original_manager_name, status, apply_time, reason)
VALUES (#{user_id}, #{sales_id}, #{sales_name}, #{status}, #{apply_time}, #{reason}) VALUES (#{user_id}, #{sales_id}, #{sales_name}, #{original_manager_name}, #{status}, #{apply_time}, #{reason})
</insert> </insert>
<update id="updateStatus" parameterType="java.util.Map"> <update id="updateStatus" parameterType="java.util.Map">

4
web/src/main/resources/mapper/PersonnelMapper.xml

@ -12,4 +12,8 @@
<select id="findAll" resultType="com.example.web.entity.Personnel"> <select id="findAll" resultType="com.example.web.entity.Personnel">
SELECT * FROM personnel SELECT * FROM personnel
</select> </select>
<select id="findByPhoneNumber" parameterType="String" resultType="com.example.web.entity.Personnel">
SELECT * FROM personnel WHERE phoneNumber = #{phoneNumber} LIMIT 1
</select>
</mapper> </mapper>

8
web/src/main/resources/mapper/UserTraceMapper.xml

@ -10,4 +10,12 @@
WHERE ut.originalData LIKE CONCAT('%', #{productId}, '%') WHERE ut.originalData LIKE CONCAT('%', #{productId}, '%')
ORDER BY ut.operationTime DESC ORDER BY ut.operationTime DESC
</select> </select>
<select id="findById" resultType="com.example.web.entity.UserTrace">
SELECT ut.*, u.nickName, u.followup, um.userName as managerName
FROM usertraces ut
LEFT JOIN users u ON ut.userId = u.userId
LEFT JOIN usermanagements um ON ut.userId = um.userId
WHERE ut.id = #{id}
</select>
</mapper> </mapper>

4
web/src/main/resources/mapper/UsersMapper.xml

@ -281,4 +281,8 @@
<select id="findAllUsers" resultType="com.example.web.entity.Users"> <select id="findAllUsers" resultType="com.example.web.entity.Users">
SELECT * FROM users WHERE type != 'Colleague' SELECT * FROM users WHERE type != 'Colleague'
</select> </select>
<select id="findByPhoneNumber" parameterType="String" resultType="com.example.web.entity.Users">
SELECT * FROM users WHERE phoneNumber = #{phoneNumber} LIMIT 1
</select>
</mapper> </mapper>

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

File diff suppressed because it is too large

2
web/src/main/resources/static/login.html

@ -273,7 +273,7 @@
console.log('收到来自其他页面的消息:', event); console.log('收到来自其他页面的消息:', event);
// 验证消息来源(可选,增强安全性) // 验证消息来源(可选,增强安全性)
if (event.origin === 'http://localhost:3005' || event.origin === 'http://localhost:8083') { if (event.origin === 'http://8.137.125.67:3005' || event.origin === 'http://8.137.125.67:8083') {
try { try {
const messageData = event.data; const messageData = event.data;
if (messageData.type === 'LOGIN_INFO') { if (messageData.type === 'LOGIN_INFO') {

Loading…
Cancel
Save