|
|
@@ -1,10 +1,14 @@
|
|
|
package com.github.zuihou.oauth.controller;
|
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
+import com.github.zuihou.authority.dao.auth.StationUserLoginInfoMapper;
|
|
|
+import com.github.zuihou.authority.dao.core.StationMapper;
|
|
|
import com.github.zuihou.authority.dto.auth.LoginParamDTO;
|
|
|
+import com.github.zuihou.authority.entity.auth.StationUserLoginInfo;
|
|
|
import com.github.zuihou.base.R;
|
|
|
import com.github.zuihou.common.constant.BizConstant;
|
|
|
import com.github.zuihou.context.BaseContextHandler;
|
|
|
+import com.github.zuihou.database.mybatis.conditions.Wraps;
|
|
|
import com.github.zuihou.exception.BizException;
|
|
|
import com.github.zuihou.jwt.TokenUtil;
|
|
|
import com.github.zuihou.jwt.model.AuthInfo;
|
|
|
@@ -13,6 +17,7 @@ import com.github.zuihou.oauth.granter.TokenGranter;
|
|
|
import com.github.zuihou.oauth.granter.TokenGranterBuilder;
|
|
|
import com.github.zuihou.oauth.service.AdminUiService;
|
|
|
import com.github.zuihou.oauth.service.ValidateCodeService;
|
|
|
+import com.github.zuihou.tenant.entity.Productionresource;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
@@ -24,6 +29,7 @@ import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.IOException;
|
|
|
+import java.time.LocalDateTime;
|
|
|
|
|
|
import static com.github.zuihou.utils.BizAssert.isFalse;
|
|
|
|
|
|
@@ -48,6 +54,8 @@ public class OauthController {
|
|
|
private AdminUiService authManager;
|
|
|
@Autowired
|
|
|
private TokenUtil tokenUtil;
|
|
|
+ @Autowired
|
|
|
+ private StationUserLoginInfoMapper stationUserLoginInfoMapper;
|
|
|
|
|
|
/**
|
|
|
* 租户登录 zuihou-ui 系统
|
|
|
@@ -67,6 +75,8 @@ public class OauthController {
|
|
|
TokenGranter granter = tokenGranterBuilder.getGranter(login.getGrantType());
|
|
|
R<AuthInfo> userInfo = granter.grant(login);
|
|
|
|
|
|
+ // 账号密码登录绑定当前登录用户和上下料站的绑定关系
|
|
|
+ stationLoginInfo(login, userInfo);
|
|
|
return userInfo;
|
|
|
}
|
|
|
|
|
|
@@ -146,6 +156,38 @@ public class OauthController {
|
|
|
TokenGranter granter = tokenGranterBuilder.getGranter(login.getGrantType());
|
|
|
R<AuthInfo> userInfo = granter.grant(login);
|
|
|
|
|
|
+ // 二维码登录绑定当前登录用户和上下料站的绑定关系
|
|
|
+ // 先判断上下料站是否之前有人登录过,如果已经有人登录,更新登录信息
|
|
|
+ stationLoginInfo(login, userInfo);
|
|
|
return userInfo;
|
|
|
}
|
|
|
+
|
|
|
+ private void stationLoginInfo(@RequestBody @Validated LoginParamDTO login, R<AuthInfo> userInfo) {
|
|
|
+ Long userId = userInfo.getData().getUserId();
|
|
|
+ StationUserLoginInfo hisUserLoginInfo = stationUserLoginInfoMapper.selectOne(Wraps.<StationUserLoginInfo>lbQ().eq(StationUserLoginInfo::getUserId, userId));
|
|
|
+ if(null != hisUserLoginInfo){
|
|
|
+ hisUserLoginInfo.setUserId(null);
|
|
|
+ hisUserLoginInfo.setCurrentLoginTime(null);
|
|
|
+ stationUserLoginInfoMapper.updateAllById(hisUserLoginInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ StationUserLoginInfo hisStationUserLoginInfo = stationUserLoginInfoMapper.selectOne(Wraps.<StationUserLoginInfo>lbQ().eq(StationUserLoginInfo::getStationId, login.getStationResourceId()));
|
|
|
+ if(null != hisStationUserLoginInfo){
|
|
|
+ hisStationUserLoginInfo.setUserId(userInfo.getData().getUserId());
|
|
|
+ hisStationUserLoginInfo.setCurrentLoginTime(LocalDateTime.now());
|
|
|
+ hisStationUserLoginInfo.setUpdateUser(userId);
|
|
|
+ stationUserLoginInfoMapper.updateAllById(hisStationUserLoginInfo);
|
|
|
+ }else{
|
|
|
+ StationUserLoginInfo stationUserLoginInfo = new StationUserLoginInfo();
|
|
|
+ stationUserLoginInfo.setUserId(userId);
|
|
|
+ stationUserLoginInfo.setStationId(login.getStationResourceId());
|
|
|
+ stationUserLoginInfo.setCurrentLoginTime(LocalDateTime.now());
|
|
|
+ stationUserLoginInfo.setCreateUser(userId);
|
|
|
+ stationUserLoginInfo.setUpdateUser(userId);
|
|
|
+ stationUserLoginInfoMapper.insert(stationUserLoginInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
}
|