Revert "feat: 微信登录获取用户信息,客户列表按最后登录排序"
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This reverts commit e35189b203.
This commit is contained in:
@@ -1,11 +1,8 @@
|
||||
package com.example.building.service.impl;
|
||||
|
||||
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.entity.Customer;
|
||||
import com.example.building.entity.User;
|
||||
import com.example.building.mapper.CustomerMapper;
|
||||
import com.example.building.mapper.UserMapper;
|
||||
import com.example.building.service.AuthService;
|
||||
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.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
@@ -29,9 +25,6 @@ public class AuthServiceImpl implements AuthService {
|
||||
@Autowired
|
||||
private UserMapper userMapper;
|
||||
|
||||
@Autowired
|
||||
private CustomerMapper customerMapper;
|
||||
|
||||
@Autowired
|
||||
private JwtUtil jwtUtil;
|
||||
|
||||
@@ -88,49 +81,25 @@ public class AuthServiceImpl implements AuthService {
|
||||
* 实际生产中需要调用微信API获取openid
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> wechatLogin(String code, String nickname, String avatar) {
|
||||
public Map<String, Object> wechatLogin(String code) {
|
||||
// TODO: 调用微信API获取openid
|
||||
// String openid = wechatService.getOpenId(code);
|
||||
String openid = "wechat_" + code;
|
||||
|
||||
// 查询或创建顾客
|
||||
Customer customer = customerMapper.selectOne(new LambdaQueryWrapper<Customer>()
|
||||
.eq(Customer::getWechatOpenid, openid));
|
||||
|
||||
if (customer == null) {
|
||||
// 新顾客
|
||||
customer = new Customer();
|
||||
customer.setCustomerId(UUID.randomUUID().toString());
|
||||
customer.setWechatOpenid(openid);
|
||||
customer.setName(nickname != null ? nickname : "微信用户");
|
||||
customer.setWechatNickname(nickname);
|
||||
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());
|
||||
// 查询用户,不存在则创建
|
||||
User user = userMapper.selectOne(new LambdaQueryWrapper<User>()
|
||||
.eq(User::getWechatOpenid, openid));
|
||||
if (user == null) {
|
||||
user = new User();
|
||||
user.setUserId(UUID.randomUUID().toString());
|
||||
user.setWechatOpenid(openid);
|
||||
user.setUsername("微信用户");
|
||||
user.setRole("sales");
|
||||
user.setStatus(1);
|
||||
userMapper.insert(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;
|
||||
return generateTokens(user);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user