|
@@ -1,16 +1,19 @@
|
|
|
package com.qmth.themis.backend.api;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.google.gson.Gson;
|
|
|
import com.qmth.themis.backend.config.DictionaryConfig;
|
|
|
import com.qmth.themis.backend.util.ServletUtil;
|
|
|
import com.qmth.themis.business.constant.SystemConstant;
|
|
|
import com.qmth.themis.business.dto.AuthDto;
|
|
|
import com.qmth.themis.business.entity.TBSession;
|
|
|
import com.qmth.themis.business.entity.TBUser;
|
|
|
+import com.qmth.themis.business.entity.TBUserRole;
|
|
|
import com.qmth.themis.business.enums.MqEnum;
|
|
|
import com.qmth.themis.business.enums.RoleEnum;
|
|
|
import com.qmth.themis.business.enums.SystemOperationEnum;
|
|
|
import com.qmth.themis.business.service.EhcacheService;
|
|
|
+import com.qmth.themis.business.service.TBUserRoleService;
|
|
|
import com.qmth.themis.business.service.TBUserService;
|
|
|
import com.qmth.themis.business.util.EhcacheUtil;
|
|
|
import com.qmth.themis.business.util.JacksonUtil;
|
|
@@ -31,20 +34,13 @@ import io.swagger.annotations.*;
|
|
|
import org.apache.commons.lang3.RandomStringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
-import org.springframework.web.bind.annotation.RequestBody;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
-import java.io.UnsupportedEncodingException;
|
|
|
import java.security.NoSuchAlgorithmException;
|
|
|
-import java.security.spec.InvalidKeySpecException;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Objects;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* @Description: 用户 前端控制器
|
|
@@ -74,10 +70,13 @@ public class TBUserController {
|
|
|
@Resource
|
|
|
MqDtoService mqDtoService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ TBUserRoleService tbUserRoleService;
|
|
|
+
|
|
|
@ApiOperation(value = "用户登录接口")
|
|
|
@RequestMapping(value = "/login/account", method = RequestMethod.POST)
|
|
|
@ApiResponses({@ApiResponse(code = 200, message = "用户信息", response = TBUser.class)})
|
|
|
- public Result login(@ApiParam(value = "用户信息", required = true) @RequestBody TBUser tbUser, HttpServletRequest request) throws NoSuchAlgorithmException, UnsupportedEncodingException, InvalidKeySpecException {
|
|
|
+ public Result login(@ApiParam(value = "用户信息", required = true) @RequestBody TBUser tbUser, HttpServletRequest request) throws NoSuchAlgorithmException {
|
|
|
if (Objects.isNull(tbUser.getLoginName()) || Objects.equals(tbUser.getLoginName(), "")) {
|
|
|
throw new BusinessException(ExceptionResultEnum.LOGIN_NAME_IS_NULL);
|
|
|
}
|
|
@@ -113,7 +112,7 @@ public class TBUserController {
|
|
|
//添加用户缓存
|
|
|
redisUtil.setUser(user.getId(), user);
|
|
|
//添加用户会话缓存
|
|
|
- String sessionId = SessionUtil.digest(user.getId(), authDto.getRoleCodes().toString(), platform.getSource());
|
|
|
+ String sessionId = SessionUtil.digest(user.getId(), authDto.getRoleCodes().toString().replaceAll(",", "&&").replaceAll(" ", ""), platform.getSource());
|
|
|
|
|
|
Date expire = SystemConstant.getExpireTime(platform);
|
|
|
TBSession tbSession = new TBSession(sessionId, String.valueOf(user.getId()), authDto.getRoleCodes().toString(), platform.getSource(), platform.name(), deviceId, request.getLocalAddr(), token, expire);
|
|
@@ -129,11 +128,13 @@ public class TBUserController {
|
|
|
map.put(SystemConstant.ACCESS_TOKEN, test);
|
|
|
map.put(SystemConstant.ACCOUNT, user);
|
|
|
map.put(SystemConstant.SESSION_ID, sessionId);
|
|
|
- Map orgMap = new HashMap();
|
|
|
- orgMap.put("name", authDto.getTbOrg().getName());
|
|
|
- orgMap.put("logo", authDto.getTbOrg().getLogo());
|
|
|
- orgMap.put("enableVideoRecord", authDto.getTbOrg().getEnableVideoRecord());
|
|
|
- map.put(SystemConstant.ORG_INFO, orgMap);
|
|
|
+ if (Objects.nonNull(authDto.getTbOrg())) {
|
|
|
+ Map orgMap = new HashMap();
|
|
|
+ orgMap.put("name", authDto.getTbOrg().getName());
|
|
|
+ orgMap.put("logo", authDto.getTbOrg().getLogo());
|
|
|
+ orgMap.put("enableVideoRecord", authDto.getTbOrg().getEnableVideoRecord());
|
|
|
+ map.put(SystemConstant.ORG_INFO, orgMap);
|
|
|
+ }
|
|
|
return ResultUtil.ok(map);
|
|
|
}
|
|
|
|
|
@@ -452,7 +453,7 @@ public class TBUserController {
|
|
|
//循环检查该用户下其他平台是否存在session,不存在则删除用户缓存和鉴权缓存
|
|
|
boolean delete = true;
|
|
|
for (Source s : Source.values()) {
|
|
|
- String sessionId = SessionUtil.digest(tbUser.getId(), authDto.getRoleCodes().toString(), s.name());
|
|
|
+ String sessionId = SessionUtil.digest(tbUser.getId(), authDto.getRoleCodes().toString().replaceAll(",", "&&").replaceAll(" ", ""), s.name());
|
|
|
if (Objects.nonNull(redisUtil.getUserSession(sessionId))) {
|
|
|
delete = false;
|
|
|
break;
|
|
@@ -467,4 +468,55 @@ public class TBUserController {
|
|
|
//mq发送消息end
|
|
|
return ResultUtil.ok(JacksonUtil.parseJson(SystemConstant.SUCCESS));
|
|
|
}
|
|
|
+
|
|
|
+ // @CachePut(value = "user_cache", key = "'userCacheQuery'")
|
|
|
+ @ApiOperation(value = "用户查询接口")
|
|
|
+ @RequestMapping(value = "/query", method = RequestMethod.GET)
|
|
|
+ @ApiResponses({@ApiResponse(code = 200, message = "用户信息", response = TBUser.class)})
|
|
|
+ public Result query(@ApiParam(value = "用户id", required = false) @RequestParam(required = false) Long id, @ApiParam(value = "登录名", required = false) @RequestParam(required = false) String loginName, @ApiParam(value = "姓名", required = false) @RequestParam(required = false) String name, @ApiParam(value = "角色", required = false) @RequestParam(required = false) String role, @ApiParam(value = "是否启用", required = false) @RequestParam(required = false) Integer enable, HttpServletRequest request) {
|
|
|
+ List<TBUser> tbUserList = tbUserService.userQuery(id, loginName, name, role, enable);
|
|
|
+ Map map = new HashMap<>();
|
|
|
+ map.put(SystemConstant.RECORDS, tbUserList);
|
|
|
+ return ResultUtil.ok(map);
|
|
|
+ }
|
|
|
+
|
|
|
+ // @CacheEvict(value = "user_cache", key = "'userCacheQuery'")
|
|
|
+ @ApiOperation(value = "用户新增/编辑接口")
|
|
|
+ @RequestMapping(value = "/save", method = RequestMethod.POST)
|
|
|
+ @ApiResponses({@ApiResponse(code = 200, message = "{\"success\":true}", response = Result.class)})
|
|
|
+ @Transactional
|
|
|
+ public Result save(@ApiParam(value = "机构信息", required = true) @RequestBody Map<String, Object> mapParameter, HttpServletRequest request) {
|
|
|
+ Gson gson = new Gson();
|
|
|
+ TBUser tbUser = gson.fromJson(gson.toJson(mapParameter), TBUser.class);
|
|
|
+ List<String> roleList = (List<String>) mapParameter.get("role");
|
|
|
+ Set<String> roleSet = null;
|
|
|
+ if (Objects.nonNull(roleList) && roleList.size() > 0) {
|
|
|
+ roleSet = new HashSet<>(roleList);
|
|
|
+ }
|
|
|
+ //todo orgId待从redis取
|
|
|
+ if (Objects.isNull(tbUser.getId())) {
|
|
|
+ tbUser.setId(Constants.idGen.next());
|
|
|
+ tbUser.setCreateId(tbUser.getId());
|
|
|
+ if (Objects.nonNull(roleSet) && roleSet.size() > 0) {
|
|
|
+ roleSet.forEach(s -> {
|
|
|
+ TBUserRole tbUserRole = new TBUserRole(tbUser.getId(), s);
|
|
|
+ tbUserRoleService.save(tbUserRole);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (Objects.nonNull(roleSet) && roleSet.size() > 0) {
|
|
|
+ QueryWrapper<TBUserRole> tbUserRoleQueryWrapper = new QueryWrapper<>();
|
|
|
+ tbUserRoleQueryWrapper.lambda().eq(TBUserRole::getUserId, tbUser.getId());
|
|
|
+ tbUserRoleService.remove(tbUserRoleQueryWrapper);
|
|
|
+ roleSet.forEach(s -> {
|
|
|
+ TBUserRole tbUserRole = new TBUserRole(tbUser.getId(), s);
|
|
|
+ tbUserRoleService.save(tbUserRole);
|
|
|
+ });
|
|
|
+ ehcacheService.removeAccountCache(tbUser.getId());
|
|
|
+ }
|
|
|
+ tbUser.setUpdateId(tbUser.getId());
|
|
|
+ }
|
|
|
+ tbUserService.saveOrUpdate(tbUser);
|
|
|
+ return ResultUtil.ok(JacksonUtil.parseJson(SystemConstant.SUCCESS));
|
|
|
+ }
|
|
|
}
|