|
@@ -1,24 +1,26 @@
|
|
package com.flyer.foster.service.impl;
|
|
package com.flyer.foster.service.impl;
|
|
|
|
|
|
|
|
+import cn.dev33.satoken.session.SaSession;
|
|
|
|
+import cn.dev33.satoken.stp.StpUtil;
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
|
+import com.flyer.exception.BusinessException;
|
|
import com.flyer.foster.consts.LoginDevice;
|
|
import com.flyer.foster.consts.LoginDevice;
|
|
import com.flyer.foster.consts.WechatConst;
|
|
import com.flyer.foster.consts.WechatConst;
|
|
-import com.flyer.foster.dto.AppUserQueryDTO;
|
|
|
|
-import com.flyer.foster.dto.AppUserRespDTO;
|
|
|
|
|
|
+import com.flyer.foster.dto.app.AppUserQueryDTO;
|
|
|
|
+import com.flyer.foster.dto.app.AppUserRespDTO;
|
|
import com.flyer.foster.entity.AppUser;
|
|
import com.flyer.foster.entity.AppUser;
|
|
|
|
+import com.flyer.foster.entity.Garden;
|
|
import com.flyer.foster.mapper.IAppUserMapper;
|
|
import com.flyer.foster.mapper.IAppUserMapper;
|
|
import com.flyer.foster.pojo.Code2SessionResp;
|
|
import com.flyer.foster.pojo.Code2SessionResp;
|
|
import com.flyer.foster.pojo.StpAppUtil;
|
|
import com.flyer.foster.pojo.StpAppUtil;
|
|
import com.flyer.foster.service.IAppUserService;
|
|
import com.flyer.foster.service.IAppUserService;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
+import com.flyer.foster.service.IGardenService;
|
|
import com.flyer.foster.util.WeChatApiUtil;
|
|
import com.flyer.foster.util.WeChatApiUtil;
|
|
-import org.etsi.uri.x01903.v13.ResponderIDType;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
-import org.springframework.expression.spel.ast.OpInc;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
-import java.util.Map;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
* <p>
|
|
* <p>
|
|
@@ -45,11 +47,19 @@ public class AppUserServiceImpl extends ServiceImpl<IAppUserMapper, AppUser> imp
|
|
@Autowired
|
|
@Autowired
|
|
private IAppUserService iAppUserService;
|
|
private IAppUserService iAppUserService;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private IGardenService iGardenService;
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public AppUserRespDTO login(AppUserQueryDTO dto) {
|
|
public AppUserRespDTO login(AppUserQueryDTO dto) {
|
|
// 查找用户信息
|
|
// 查找用户信息
|
|
Code2SessionResp code2Session = weChatApiUtil.getCode2Session(dto.getCode(), WechatConst.APP_ID, WechatConst.APP_SECRET);
|
|
Code2SessionResp code2Session = weChatApiUtil.getCode2Session(dto.getCode(), WechatConst.APP_ID, WechatConst.APP_SECRET);
|
|
String openid = code2Session.getOpenid();
|
|
String openid = code2Session.getOpenid();
|
|
|
|
+ // 根据gardenId获取租户id
|
|
|
|
+ Garden garden = iGardenService.getById(dto.getGardenId());
|
|
|
|
+ if (garden == null) {
|
|
|
|
+ throw new BusinessException("无效的gardenId");
|
|
|
|
+ }
|
|
// 查找用户信息,存在更新,不存在新增
|
|
// 查找用户信息,存在更新,不存在新增
|
|
AppUser appUser = iAppUserService.lambdaQuery().eq(AppUser::getOpenId, openid).one();
|
|
AppUser appUser = iAppUserService.lambdaQuery().eq(AppUser::getOpenId, openid).one();
|
|
if (appUser == null) {
|
|
if (appUser == null) {
|
|
@@ -59,6 +69,7 @@ public class AppUserServiceImpl extends ServiceImpl<IAppUserMapper, AppUser> imp
|
|
appUser.setOpenId(code2Session.getOpenid());
|
|
appUser.setOpenId(code2Session.getOpenid());
|
|
appUser.setName(DEFAUT_NAME);
|
|
appUser.setName(DEFAUT_NAME);
|
|
appUser.setIcon(DEFAULT_ICON);
|
|
appUser.setIcon(DEFAULT_ICON);
|
|
|
|
+ appUser.setTenantId(garden.getTenantId());
|
|
appUser.setCreatedBy("kelei");
|
|
appUser.setCreatedBy("kelei");
|
|
appUser.setCreatedTime(LocalDateTime.now());
|
|
appUser.setCreatedTime(LocalDateTime.now());
|
|
appUser.setUpdatedBy("kelei");
|
|
appUser.setUpdatedBy("kelei");
|
|
@@ -67,6 +78,10 @@ public class AppUserServiceImpl extends ServiceImpl<IAppUserMapper, AppUser> imp
|
|
this.save(appUser);
|
|
this.save(appUser);
|
|
}
|
|
}
|
|
StpAppUtil.login(appUser.getId(), LoginDevice.APP);
|
|
StpAppUtil.login(appUser.getId(), LoginDevice.APP);
|
|
|
|
+ SaSession tokenSession = StpAppUtil.getTokenSession();
|
|
|
|
+ // 设置tenantId
|
|
|
|
+ tokenSession.set("tenantId", appUser.getTenantId());
|
|
|
|
+
|
|
AppUserRespDTO respDTO = new AppUserRespDTO();
|
|
AppUserRespDTO respDTO = new AppUserRespDTO();
|
|
BeanUtil.copyProperties(appUser, respDTO);
|
|
BeanUtil.copyProperties(appUser, respDTO);
|
|
respDTO.setToken(StpAppUtil.getTokenValue());
|
|
respDTO.setToken(StpAppUtil.getTokenValue());
|