维修自动登录
This commit is contained in:
parent
bc9c010094
commit
6d5093345b
@ -51,6 +51,14 @@ public interface CustomerMainService extends IService<CustomerMain> {
|
||||
**/
|
||||
CustomerMainRespVO getCustomerById(String id);
|
||||
|
||||
/**
|
||||
* 根据userID客户表信息
|
||||
* @author vinjor-M
|
||||
* @date 15:25 2024/9/27
|
||||
* @param userId 用户id
|
||||
**/
|
||||
CustomerMain getCustomerByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* 获取当前登录用户的客户信息
|
||||
* @author PQZ
|
||||
|
@ -213,6 +213,26 @@ public class CustomerMainServiceImpl extends ServiceImpl<CustomerMainMapper, Cus
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据userID客户表信息
|
||||
*
|
||||
* @param userId 用户id
|
||||
* @return cn.iocoder.yudao.module.custom.vo.CustomerMainRespVO
|
||||
* @author vinjor-M
|
||||
* @date 15:25 2024/9/27
|
||||
**/
|
||||
@Override
|
||||
public CustomerMain getCustomerByUserId(Long userId) {
|
||||
LambdaQueryWrapper<CustomerMain> queryWrapper = new LambdaQueryWrapper<CustomerMain>()
|
||||
.eq(CustomerMain::getUserId,userId);
|
||||
List<CustomerMain> customerList = this.list(queryWrapper);
|
||||
if(customerList.isEmpty()){
|
||||
return null;
|
||||
}else{
|
||||
return customerList.get(0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前登录用户的客户信息
|
||||
*
|
||||
@ -222,7 +242,6 @@ public class CustomerMainServiceImpl extends ServiceImpl<CustomerMainMapper, Cus
|
||||
**/
|
||||
@Override
|
||||
public CustomerMainRespVO getUserCustomer() {
|
||||
|
||||
LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
|
||||
LambdaQueryWrapper<CustomerMain> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper.eq(CustomerMain::getUserId,loginUser.getId()).eq(BaseDO::getDeleted,'0');
|
||||
|
@ -11,6 +11,9 @@ import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
|
||||
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
|
||||
|
||||
import cn.iocoder.yudao.module.app.vo.WxLoginBody;
|
||||
import cn.iocoder.yudao.module.custom.entity.CustomerMain;
|
||||
import cn.iocoder.yudao.module.custom.service.CustomerMainService;
|
||||
import cn.iocoder.yudao.module.custom.vo.CustomerMainRespVO;
|
||||
import cn.iocoder.yudao.module.system.api.dict.DictDataApi;
|
||||
import cn.iocoder.yudao.module.system.api.permission.PermissionApi;
|
||||
import cn.iocoder.yudao.module.system.api.permission.RoleApi;
|
||||
@ -32,6 +35,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@ -65,20 +69,14 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.*;
|
||||
public class LoginController {
|
||||
@Resource
|
||||
private AdminAuthService loginService;
|
||||
|
||||
|
||||
|
||||
|
||||
@Resource
|
||||
private WechatPayConfig wxConfig;
|
||||
|
||||
|
||||
|
||||
@Resource
|
||||
private RestTemplate restTemplate;
|
||||
|
||||
@Resource
|
||||
private SecurityProperties securityProperties;
|
||||
@Autowired
|
||||
private CustomerMainService customerMainService;
|
||||
|
||||
@PostMapping("/wxLogin")
|
||||
@TenantIgnore
|
||||
@ -107,9 +105,12 @@ public class LoginController {
|
||||
|
||||
if (StringUtils.hasText(decryptResult)) {
|
||||
//如果解析成功,获取token
|
||||
AuthLoginRespVO loginVO = loginService.wxLoginJc(decryptResult,openId,wxLoginBody.getInviteId());
|
||||
AuthLoginRespVO loginVO = loginService.wxLoginRepair(decryptResult,openId,wxLoginBody.getInviteId());
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("token", loginVO.getAccessToken());
|
||||
//查会员表里是否有数据
|
||||
CustomerMain customerMain = customerMainService.getCustomerByUserId(loginVO.getUserId());
|
||||
map.put("ifNeedFill", null==customerMain);
|
||||
return success(map);
|
||||
} else {
|
||||
return error(500, "微信登录失败!");
|
||||
|
@ -105,4 +105,9 @@ public class UserSaveReqVO {
|
||||
|
||||
private Long balance;
|
||||
|
||||
/**
|
||||
* 维修小程序openID
|
||||
*/
|
||||
private String repairOpenId;
|
||||
|
||||
}
|
||||
|
@ -85,4 +85,15 @@ public interface AdminAuthService {
|
||||
* @return cn.iocoder.yudao.module.system.controller.admin.auth.vo.AuthLoginRespVO
|
||||
**/
|
||||
AuthLoginRespVO wxLoginByUserId(Long userId,String userName);
|
||||
|
||||
/**
|
||||
* 微信小程序自动注册账号并登录
|
||||
* @author vinjor-M
|
||||
* @date 15:10 2024/9/27
|
||||
* @param decryptResult
|
||||
* @param openId openId
|
||||
* @param inviteId
|
||||
* @return cn.iocoder.yudao.module.system.controller.admin.auth.vo.AuthLoginRespVO
|
||||
**/
|
||||
AuthLoginRespVO wxLoginRepair(String decryptResult, String openId, Long inviteId);
|
||||
}
|
||||
|
@ -375,7 +375,7 @@ public class AdminAuthServiceImpl implements AdminAuthService {
|
||||
List<RoleDO> jcyh = roleService.getRoleListByCodes(Collections.singletonList("jcyh"));
|
||||
Set<Long> ids = new HashSet<>();
|
||||
ids.add(jcyh.get(0).getId());
|
||||
// permissionService.assignUserRole(user.getId(),ids);
|
||||
permissionService.assignUserRole(user.getId(),ids);
|
||||
}else {
|
||||
//更新
|
||||
user.setId(wxUser.getId());
|
||||
@ -410,4 +410,62 @@ public class AdminAuthServiceImpl implements AdminAuthService {
|
||||
// 生成token
|
||||
return createTokenAfterLoginSuccess(userId, userName, LoginLogTypeEnum.LOGIN_USERNAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* 微信小程序自动注册账号并登录
|
||||
*
|
||||
* @param decryptResult
|
||||
* @param openId openId
|
||||
* @param inviteId
|
||||
* @return cn.iocoder.yudao.module.system.controller.admin.auth.vo.AuthLoginRespVO
|
||||
* @author vinjor-M
|
||||
* @date 15:10 2024/9/27
|
||||
**/
|
||||
@Override
|
||||
public AuthLoginRespVO wxLoginRepair(String decryptResult, String openId, Long inviteId) {
|
||||
//字符串转json
|
||||
JSONObject jsonObject = JSONObject.parseObject(decryptResult);
|
||||
String phoneNumber = jsonObject.getString("phoneNumber");
|
||||
//还可以获取其他信息
|
||||
//根据手机号判断数据库中是否有该用户
|
||||
AdminUserDO wxUser = userService.getUserByMobileWithoutTenant(phoneNumber);
|
||||
//如果查不到,则新增,查到了,则更新
|
||||
UserSaveReqVO user = new UserSaveReqVO();
|
||||
if (wxUser == null) {
|
||||
// 新增
|
||||
user.setUsername(phoneNumber);
|
||||
user.setNickname(phoneNumber);
|
||||
user.setMobile(phoneNumber);
|
||||
user.setPassword(passwordEncoder.encode("123456"));
|
||||
user.setRepairOpenId(openId);
|
||||
user.setTenantId(180L);
|
||||
if (null!=inviteId){
|
||||
//绑定上级
|
||||
user.setInviteId(inviteId);
|
||||
//给上级进行积分奖励
|
||||
// userBalanceService.inviteRewards(inviteId);
|
||||
}
|
||||
user.setDeptId(100L);
|
||||
Long uid = userService.createUser(user);
|
||||
wxUser = new AdminUserDO();
|
||||
wxUser.setId(uid);
|
||||
wxUser.setUsername(phoneNumber);
|
||||
}else {
|
||||
//更新
|
||||
user.setId(wxUser.getId());
|
||||
user.setNickname(phoneNumber);
|
||||
user.setRepairOpenId(openId);
|
||||
if (ObjectUtil.isEmpty(user.getInviteId())){
|
||||
if (null!=inviteId){
|
||||
//绑定上级
|
||||
user.setInviteId(inviteId);
|
||||
//给上级进行积分奖励
|
||||
// userBalanceService.inviteRewards(inviteId);
|
||||
}
|
||||
}
|
||||
userService.updateUser(user);
|
||||
}
|
||||
// 生成token
|
||||
return createTokenAfterLoginSuccess(wxUser.getId(), wxUser.getUsername(), LoginLogTypeEnum.LOGIN_SOCIAL);
|
||||
}
|
||||
}
|
||||
|
@ -185,10 +185,10 @@ debug: false
|
||||
--- #################### 微信公众号、小程序相关配置 ####################
|
||||
wx:
|
||||
mp: # 公众号配置(必填),参见 https://github.com/Wechat-Group/WxJava/blob/develop/spring-boot-starters/wx-java-mp-spring-boot-starter/README.md 文档
|
||||
# app-id: wx8653afe16dffec37 # 蓝安
|
||||
# secret: ab94673dd0cca78abd0a453d0aac9f98
|
||||
app-id: wxb1f71e5e0c5f9ee7 # 点亮
|
||||
secret: 2e9864a6b224feb6fba4ab73b70212cd
|
||||
app-id: wx8653afe16dffec37 # 蓝安
|
||||
secret: 0d13b60547b73d844fc95871d9b264dd
|
||||
# app-id: wxb1f71e5e0c5f9ee7 # 点亮
|
||||
# secret: 2e9864a6b224feb6fba4ab73b70212cd
|
||||
# 存储配置,解决 AccessToken 的跨节点的共享
|
||||
config-storage:
|
||||
type: RedisTemplate # 采用 RedisTemplate 操作 Redis,会自动从 Spring 中获取
|
||||
|
@ -3,7 +3,7 @@ spring:
|
||||
name: yudao-server
|
||||
|
||||
profiles:
|
||||
active: prod
|
||||
active: local
|
||||
|
||||
main:
|
||||
allow-circular-references: true # 允许循环依赖,因为项目是三层架构,无法避免这个情况。
|
||||
@ -231,6 +231,8 @@ yudao:
|
||||
- /admin-api/system/tenant/getListByWebsite
|
||||
- /admin-api/rescue/loginQx
|
||||
- /userClient/repair/wxLogin
|
||||
- /userClient/base/company/page #查询可提供服务的子公司,不需要登录
|
||||
- /userClient/base/company/get #查询可提供服务的子公司详情,不需要登录
|
||||
websocket:
|
||||
enable: true # websocket的开关
|
||||
path: /infra/ws # 路径
|
||||
|
Loading…
Reference in New Issue
Block a user