|
|
|
|
@ -1,20 +1,36 @@ |
|
|
|
|
package org.jeecg.modules.inspur.controller; |
|
|
|
|
|
|
|
|
|
import cn.hutool.json.JSONObject; |
|
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import org.jeecg.common.api.vo.Result; |
|
|
|
|
import org.jeecg.common.constant.CommonConstant; |
|
|
|
|
import org.jeecg.common.constant.SymbolConstant; |
|
|
|
|
import org.jeecg.common.system.util.JwtUtil; |
|
|
|
|
import org.jeecg.common.system.vo.LoginUser; |
|
|
|
|
import org.jeecg.common.util.RedisUtil; |
|
|
|
|
import org.jeecg.common.util.oConvertUtils; |
|
|
|
|
import org.jeecg.modules.inspur.domain.InspurRegisterParams; |
|
|
|
|
import org.jeecg.modules.inspur.domain.InspurResp; |
|
|
|
|
import org.jeecg.modules.inspur.entity.InspurUser; |
|
|
|
|
import org.jeecg.modules.inspur.service.InspurService; |
|
|
|
|
import org.jeecg.modules.inspur.util.ConstantInspur; |
|
|
|
|
import org.jeecg.modules.inspur.util.UniqueIdGenerator; |
|
|
|
|
import org.jeecg.modules.system.entity.SysDepart; |
|
|
|
|
import org.jeecg.modules.system.entity.SysTenant; |
|
|
|
|
import org.jeecg.modules.system.entity.SysUser; |
|
|
|
|
import org.jeecg.modules.system.service.ISysDepartService; |
|
|
|
|
import org.jeecg.modules.system.service.ISysDictService; |
|
|
|
|
import org.jeecg.modules.system.service.ISysTenantService; |
|
|
|
|
import org.jeecg.modules.system.service.ISysUserService; |
|
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
import org.springframework.http.HttpStatus; |
|
|
|
|
import org.springframework.http.ResponseEntity; |
|
|
|
|
import org.springframework.web.bind.annotation.RequestBody; |
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping; |
|
|
|
|
import org.springframework.web.bind.annotation.RestController; |
|
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
|
|
|
|
|
|
import java.util.Map; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.LinkedHashMap; |
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @author 84018 |
|
|
|
|
@ -26,29 +42,141 @@ import java.util.Map; |
|
|
|
|
public class InspurUserController { |
|
|
|
|
|
|
|
|
|
private final InspurService inspurService; |
|
|
|
|
@Autowired |
|
|
|
|
private ISysUserService sysUserService; |
|
|
|
|
@Autowired |
|
|
|
|
private RedisUtil redisUtil; |
|
|
|
|
@Autowired |
|
|
|
|
private ISysDepartService sysDepartService; |
|
|
|
|
@Autowired |
|
|
|
|
private ISysTenantService sysTenantService; |
|
|
|
|
@Autowired |
|
|
|
|
private ISysDictService sysDictService; |
|
|
|
|
|
|
|
|
|
@RequestMapping("/register") |
|
|
|
|
@PostMapping("/register") |
|
|
|
|
public ResponseEntity register(@RequestBody InspurRegisterParams registerParams) { |
|
|
|
|
String code = registerParams.getCode(); |
|
|
|
|
String token = null; |
|
|
|
|
String traceId = null; |
|
|
|
|
if (code != null && !code.isEmpty()) { |
|
|
|
|
Map<String, Object> map = inspurService.appAuthCheck(code); |
|
|
|
|
token = (String) map.get("token"); |
|
|
|
|
traceId = (String) map.get("traceId"); |
|
|
|
|
if (!ConstantInspur.APP_ID.equals(registerParams.getAppKey())) { |
|
|
|
|
InspurResp resp = InspurResp.builder() |
|
|
|
|
.code(ConstantInspur.SUCCESS_CODE_ERR) |
|
|
|
|
.msg("开通失败:AppId错误") |
|
|
|
|
.data(null) |
|
|
|
|
.build(); |
|
|
|
|
new ResponseEntity(resp, HttpStatus.OK); |
|
|
|
|
} |
|
|
|
|
InspurUser inspurUser = inspurService.getUserInfoByToken(token); |
|
|
|
|
SysUser user = new SysUser(); |
|
|
|
|
user.setUsername("admin"); |
|
|
|
|
user.setPassword("123456"); |
|
|
|
|
|
|
|
|
|
if (!ConstantInspur.APP_SECRET.equals(registerParams.getAppSecret())) { |
|
|
|
|
InspurResp resp = InspurResp.builder() |
|
|
|
|
.code(ConstantInspur.SUCCESS_CODE_ERR) |
|
|
|
|
.msg("开通失败:AppSecret错误") |
|
|
|
|
.data(null) |
|
|
|
|
.build(); |
|
|
|
|
new ResponseEntity(resp, HttpStatus.OK); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
String traceId = UniqueIdGenerator.generate16DigitId(); |
|
|
|
|
|
|
|
|
|
JSONObject resultJson = inspurService.addAccount(registerParams); |
|
|
|
|
InspurResp resp = InspurResp.builder() |
|
|
|
|
.code(ConstantInspur.SUCCESS_CODE_INT) |
|
|
|
|
.msg("成功") |
|
|
|
|
.data(user) |
|
|
|
|
.data(resultJson) |
|
|
|
|
.traceId(traceId) |
|
|
|
|
.build(); |
|
|
|
|
return new ResponseEntity(resp, HttpStatus.OK); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@GetMapping("/login") |
|
|
|
|
public Result<com.alibaba.fastjson.JSONObject> login(@RequestParam String code) { |
|
|
|
|
Result<com.alibaba.fastjson.JSONObject> result = new Result<com.alibaba.fastjson.JSONObject>(); |
|
|
|
|
// String token = null;
|
|
|
|
|
// if (code != null && !code.isEmpty()) {
|
|
|
|
|
// Map<String, Object> map = inspurService.appAuthCheck(code);
|
|
|
|
|
// token = (String) map.get("token");
|
|
|
|
|
// }
|
|
|
|
|
// if (StringUtils.isEmpty(token)) {
|
|
|
|
|
// result.error500("登录失败,code无效");
|
|
|
|
|
// return result;
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// InspurUser inspurUser = inspurService.getUserInfoByToken(token);
|
|
|
|
|
// if (ObjectUtils.isEmpty(inspurUser)) {
|
|
|
|
|
// result.error500("登录失败,用户信息为空");
|
|
|
|
|
// return result;
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// LambdaQueryWrapper<SysUser> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
// queryWrapper.eq(SysUser::getUsername, inspurUser.getLoginLoginname());
|
|
|
|
|
// SysUser sysUser = sysUserService.getOne(queryWrapper);
|
|
|
|
|
// result = sysUserService.checkUserIsEffective(sysUser);
|
|
|
|
|
// if (!result.isSuccess()) {
|
|
|
|
|
// return result;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
SysUser sysUser = sysUserService.getUserByName("admin"); |
|
|
|
|
//用户登录信息
|
|
|
|
|
userInfo(sysUser, result); |
|
|
|
|
LoginUser loginUser = new LoginUser(); |
|
|
|
|
BeanUtils.copyProperties(sysUser, loginUser); |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 用户信息 |
|
|
|
|
* |
|
|
|
|
* @param sysUser |
|
|
|
|
* @param result |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private Result<com.alibaba.fastjson.JSONObject> userInfo(SysUser sysUser, Result<com.alibaba.fastjson.JSONObject> result) { |
|
|
|
|
String username = sysUser.getUsername(); |
|
|
|
|
String syspassword = sysUser.getPassword(); |
|
|
|
|
// 获取用户部门信息
|
|
|
|
|
com.alibaba.fastjson.JSONObject obj = new com.alibaba.fastjson.JSONObject(new LinkedHashMap<>()); |
|
|
|
|
|
|
|
|
|
// 生成token
|
|
|
|
|
String token = JwtUtil.sign(username, syspassword); |
|
|
|
|
// 设置token缓存有效时间
|
|
|
|
|
redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token); |
|
|
|
|
redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME * 2 / 1000); |
|
|
|
|
obj.put("token", token); |
|
|
|
|
|
|
|
|
|
String tenantIds = sysUser.getRelTenantIds(); |
|
|
|
|
if (oConvertUtils.isNotEmpty(tenantIds)) { |
|
|
|
|
List<Integer> tenantIdList = new ArrayList<>(); |
|
|
|
|
for (String id : tenantIds.split(SymbolConstant.COMMA)) { |
|
|
|
|
tenantIdList.add(Integer.valueOf(id)); |
|
|
|
|
} |
|
|
|
|
List<SysTenant> tenantList = sysTenantService.queryEffectiveTenant(tenantIdList); |
|
|
|
|
if (tenantList.size() == 0) { |
|
|
|
|
result.error500("与该用户关联的租户均已被冻结,无法登录!"); |
|
|
|
|
return result; |
|
|
|
|
} else { |
|
|
|
|
obj.put("tenantList", tenantList); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// 20210802 for:获取用户租户信息
|
|
|
|
|
|
|
|
|
|
obj.put("userInfo", sysUser); |
|
|
|
|
|
|
|
|
|
List<SysDepart> departs = sysDepartService.queryUserDeparts(sysUser.getId()); |
|
|
|
|
obj.put("departs", departs); |
|
|
|
|
if (departs == null || departs.size() == 0) { |
|
|
|
|
obj.put("multi_depart", 0); |
|
|
|
|
} else if (departs.size() == 1) { |
|
|
|
|
sysUserService.updateUserDepart(username, departs.get(0).getOrgCode()); |
|
|
|
|
obj.put("multi_depart", 1); |
|
|
|
|
} else { |
|
|
|
|
SysUser sysUserById = sysUserService.getById(sysUser.getId()); |
|
|
|
|
if (oConvertUtils.isEmpty(sysUserById.getOrgCode())) { |
|
|
|
|
sysUserService.updateUserDepart(username, departs.get(0).getOrgCode()); |
|
|
|
|
} |
|
|
|
|
// 如果用戶为选择部门,数据库为存在上一次登录部门,则取一条存进去
|
|
|
|
|
obj.put("multi_depart", 2); |
|
|
|
|
} |
|
|
|
|
obj.put("sysAllDictItems", sysDictService.queryAllDictItems()); |
|
|
|
|
result.setResult(obj); |
|
|
|
|
result.success("登录成功"); |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|