Revert "feat: 微信登录获取用户信息,客户列表按最后登录排序"
Some checks failed
continuous-integration/drone/push Build is failing

This reverts commit e35189b203.
This commit is contained in:
Agent
2026-03-24 02:42:37 +00:00
parent e35189b203
commit a0c2fd31ee
5 changed files with 16 additions and 73 deletions

View File

@@ -38,16 +38,10 @@ public class AuthController {
/** /**
* 微信登录 * 微信登录
* @param code 微信授权码
* @param nickname 微信昵称(可选)
* @param avatar 微信头像URL可选
*/ */
@PostMapping("/wechat") @PostMapping("/wechat")
public Result<Map<String, Object>> wechatLogin( public Result<Map<String, Object>> wechatLogin(@RequestParam String code) {
@RequestParam String code, Map<String, Object> result = authService.wechatLogin(code);
@RequestParam(required = false) String nickname,
@RequestParam(required = false) String avatar) {
Map<String, Object> result = authService.wechatLogin(code, nickname, avatar);
return Result.success(result); return Result.success(result);
} }

View File

@@ -31,16 +31,6 @@ public class Customer {
*/ */
private String wechatOpenid; private String wechatOpenid;
/**
* 微信昵称
*/
private String wechatNickname;
/**
* 微信头像
*/
private String wechatAvatar;
/** /**
* 地址 * 地址
*/ */
@@ -61,11 +51,6 @@ public class Customer {
*/ */
private String createdBy; private String createdBy;
/**
* 最后登录时间(用于订单客户排序)
*/
private LocalDateTime lastLoginAt;
@TableField(fill = FieldFill.INSERT) @TableField(fill = FieldFill.INSERT)
private LocalDateTime createdAt; private LocalDateTime createdAt;

View File

@@ -19,11 +19,8 @@ public interface AuthService {
/** /**
* 微信扫码登录 * 微信扫码登录
* @param code 微信授权码
* @param nickname 微信昵称
* @param avatar 微信头像
*/ */
Map<String, Object> wechatLogin(String code, String nickname, String avatar); Map<String, Object> wechatLogin(String code);
/** /**
* 支付宝扫码登录 * 支付宝扫码登录

View File

@@ -1,11 +1,8 @@
package com.example.building.service.impl; package com.example.building.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.example.building.common.JwtUtil; import com.example.building.common.JwtUtil;
import com.example.building.entity.Customer;
import com.example.building.entity.User; import com.example.building.entity.User;
import com.example.building.mapper.CustomerMapper;
import com.example.building.mapper.UserMapper; import com.example.building.mapper.UserMapper;
import com.example.building.service.AuthService; import com.example.building.service.AuthService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@@ -13,7 +10,6 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
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.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
@@ -29,9 +25,6 @@ public class AuthServiceImpl implements AuthService {
@Autowired @Autowired
private UserMapper userMapper; private UserMapper userMapper;
@Autowired
private CustomerMapper customerMapper;
@Autowired @Autowired
private JwtUtil jwtUtil; private JwtUtil jwtUtil;
@@ -88,49 +81,25 @@ public class AuthServiceImpl implements AuthService {
* 实际生产中需要调用微信API获取openid * 实际生产中需要调用微信API获取openid
*/ */
@Override @Override
public Map<String, Object> wechatLogin(String code, String nickname, String avatar) { public Map<String, Object> wechatLogin(String code) {
// TODO: 调用微信API获取openid // TODO: 调用微信API获取openid
// String openid = wechatService.getOpenId(code); // String openid = wechatService.getOpenId(code);
String openid = "wechat_" + code; String openid = "wechat_" + code;
// 查询或创建顾客 // 查询用户,不存在则创建
Customer customer = customerMapper.selectOne(new LambdaQueryWrapper<Customer>() User user = userMapper.selectOne(new LambdaQueryWrapper<User>()
.eq(Customer::getWechatOpenid, openid)); .eq(User::getWechatOpenid, openid));
if (user == null) {
if (customer == null) { user = new User();
// 新顾客 user.setUserId(UUID.randomUUID().toString());
customer = new Customer(); user.setWechatOpenid(openid);
customer.setCustomerId(UUID.randomUUID().toString()); user.setUsername("微信用户");
customer.setWechatOpenid(openid); user.setRole("sales");
customer.setName(nickname != null ? nickname : "微信用户"); user.setStatus(1);
customer.setWechatNickname(nickname); userMapper.insert(user);
customer.setWechatAvatar(avatar);
customer.setTotalAmount(new java.math.BigDecimal("0"));
customer.setLastLoginAt(LocalDateTime.now());
customerMapper.insert(customer);
} else {
// 更新已有顾客信息
LambdaUpdateWrapper<Customer> updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper.eq(Customer::getCustomerId, customer.getCustomerId());
if (nickname != null) {
updateWrapper.set(Customer::getWechatNickname, nickname);
}
if (avatar != null) {
updateWrapper.set(Customer::getWechatAvatar, avatar);
}
updateWrapper.set(Customer::getLastLoginAt, LocalDateTime.now());
customerMapper.update(null, updateWrapper);
customer.setLastLoginAt(LocalDateTime.now());
} }
// 返回顾客信息 return generateTokens(user);
Map<String, Object> result = new HashMap<>();
result.put("token", "customer_token_" + customer.getCustomerId());
result.put("customerId", customer.getCustomerId());
result.put("name", customer.getName());
result.put("role", "customer");
return result;
} }
/** /**

View File

@@ -33,8 +33,6 @@ public class CustomerServiceImpl implements CustomerService {
.or() .or()
.like(Customer::getPhone, keyword); .like(Customer::getPhone, keyword);
} }
// 按最后登录时间排序(最新的在前),没有登录时间的排最后
wrapper.orderByDesc(Customer::getLastLoginAt);
wrapper.orderByDesc(Customer::getCreatedAt); wrapper.orderByDesc(Customer::getCreatedAt);
return customerMapper.selectPage(pageParam, wrapper); return customerMapper.selectPage(pageParam, wrapper);
} }