|
@@ -1,24 +1,26 @@
|
|
|
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 com.flyer.exception.BusinessException;
|
|
|
import com.flyer.foster.consts.LoginDevice;
|
|
|
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.Garden;
|
|
|
import com.flyer.foster.mapper.IAppUserMapper;
|
|
|
import com.flyer.foster.pojo.Code2SessionResp;
|
|
|
import com.flyer.foster.pojo.StpAppUtil;
|
|
|
import com.flyer.foster.service.IAppUserService;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.flyer.foster.service.IGardenService;
|
|
|
import com.flyer.foster.util.WeChatApiUtil;
|
|
|
-import org.etsi.uri.x01903.v13.ResponderIDType;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.expression.spel.ast.OpInc;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
-import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -45,11 +47,19 @@ public class AppUserServiceImpl extends ServiceImpl<IAppUserMapper, AppUser> imp
|
|
|
@Autowired
|
|
|
private IAppUserService iAppUserService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IGardenService iGardenService;
|
|
|
+
|
|
|
@Override
|
|
|
public AppUserRespDTO login(AppUserQueryDTO dto) {
|
|
|
// 查找用户信息
|
|
|
Code2SessionResp code2Session = weChatApiUtil.getCode2Session(dto.getCode(), WechatConst.APP_ID, WechatConst.APP_SECRET);
|
|
|
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();
|
|
|
if (appUser == null) {
|
|
@@ -59,6 +69,7 @@ public class AppUserServiceImpl extends ServiceImpl<IAppUserMapper, AppUser> imp
|
|
|
appUser.setOpenId(code2Session.getOpenid());
|
|
|
appUser.setName(DEFAUT_NAME);
|
|
|
appUser.setIcon(DEFAULT_ICON);
|
|
|
+ appUser.setTenantId(garden.getTenantId());
|
|
|
appUser.setCreatedBy("kelei");
|
|
|
appUser.setCreatedTime(LocalDateTime.now());
|
|
|
appUser.setUpdatedBy("kelei");
|
|
@@ -67,6 +78,10 @@ public class AppUserServiceImpl extends ServiceImpl<IAppUserMapper, AppUser> imp
|
|
|
this.save(appUser);
|
|
|
}
|
|
|
StpAppUtil.login(appUser.getId(), LoginDevice.APP);
|
|
|
+ SaSession tokenSession = StpAppUtil.getTokenSession();
|
|
|
+ // 设置tenantId
|
|
|
+ tokenSession.set("tenantId", appUser.getTenantId());
|
|
|
+
|
|
|
AppUserRespDTO respDTO = new AppUserRespDTO();
|
|
|
BeanUtil.copyProperties(appUser, respDTO);
|
|
|
respDTO.setToken(StpAppUtil.getTokenValue());
|