|
@@ -1,6 +1,9 @@
|
|
|
package com.qmth.themis.backend.api;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.google.gson.Gson;
|
|
|
import com.qmth.themis.backend.util.ServletUtil;
|
|
|
import com.qmth.themis.business.annotation.ApiJsonObject;
|
|
@@ -18,6 +21,7 @@ import com.qmth.themis.business.service.CacheService;
|
|
|
import com.qmth.themis.business.service.TBOrgService;
|
|
|
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;
|
|
|
import com.qmth.themis.business.util.RedisUtil;
|
|
|
import com.qmth.themis.business.util.SessionUtil;
|
|
@@ -79,32 +83,45 @@ public class TBUserController {
|
|
|
@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 Map<String,Object> map) throws NoSuchAlgorithmException {
|
|
|
- if (Objects.isNull(map)) {
|
|
|
+ public Result login(@ApiJsonObject(name = "loginAccount", value = {
|
|
|
+ @ApiJsonProperty(key = "loginName", description = "登录名"),
|
|
|
+ @ApiJsonProperty(key = "password", description = "密码"),
|
|
|
+ @ApiJsonProperty(key = "code", description = "机构代码")
|
|
|
+ }) @ApiParam(value = "用户信息", required = true) @RequestBody Map<String, Object> mapParameter) throws NoSuchAlgorithmException {
|
|
|
+ if (Objects.isNull(mapParameter)) {
|
|
|
throw new BusinessException(ExceptionResultEnum.USER_INFO_IS_NULL);
|
|
|
}
|
|
|
- if (Objects.isNull(map.get("loginName")) || Objects.equals(map.get("loginName"), "")) {
|
|
|
+ if (Objects.isNull(mapParameter.get("loginName")) || Objects.equals(mapParameter.get("loginName"), "")) {
|
|
|
throw new BusinessException(ExceptionResultEnum.LOGIN_NAME_IS_NULL);
|
|
|
}
|
|
|
- if (Objects.isNull(map.get("password")) || Objects.equals(map.get("password"), "")) {
|
|
|
+ if (Objects.isNull(mapParameter.get("password")) || Objects.equals(mapParameter.get("password"), "")) {
|
|
|
throw new BusinessException(ExceptionResultEnum.PASSWORD_IS_NULL);
|
|
|
}
|
|
|
- if (Objects.isNull(map.get("code")) || Objects.equals(map.get("code"), "")) {
|
|
|
+ if (Objects.isNull(mapParameter.get("code")) || Objects.equals(mapParameter.get("code"), "")) {
|
|
|
throw new BusinessException(ExceptionResultEnum.ORG_CODE_IS_NULL);
|
|
|
}
|
|
|
- String loginName = String.valueOf(map.get("loginName"));
|
|
|
- String password = String.valueOf(map.get("password"));
|
|
|
- String orgCode = String.valueOf(map.get("code"));
|
|
|
- QueryWrapper<TBOrg> tbOrgQueryWrapper = new QueryWrapper<>();
|
|
|
- tbOrgQueryWrapper.lambda().eq(TBOrg::getCode, orgCode);
|
|
|
- TBOrg tbOrg = tbOrgService.getOne(tbOrgQueryWrapper);
|
|
|
+ String loginName = String.valueOf(mapParameter.get("loginName"));
|
|
|
+ String password = String.valueOf(mapParameter.get("password"));
|
|
|
+ String orgCode = String.valueOf(mapParameter.get("code"));
|
|
|
+ TBOrg tbOrg = (TBOrg) EhcacheUtil.get(SystemConstant.orgCodeCache, orgCode);
|
|
|
+ if (Objects.isNull(tbOrg)) {
|
|
|
+ QueryWrapper<TBOrg> tbOrgQueryWrapper = new QueryWrapper<>();
|
|
|
+ tbOrgQueryWrapper.lambda().eq(TBOrg::getCode, orgCode);
|
|
|
+ tbOrg = tbOrgService.getOne(tbOrgQueryWrapper);
|
|
|
+ if (Objects.nonNull(tbOrg)) {
|
|
|
+ EhcacheUtil.put(SystemConstant.orgCodeCache, orgCode, tbOrg);
|
|
|
+ }
|
|
|
+ }
|
|
|
if (Objects.isNull(tbOrg)) {
|
|
|
throw new BusinessException(ExceptionResultEnum.ORG_NO);
|
|
|
}
|
|
|
|
|
|
QueryWrapper<TBUser> wrapper = new QueryWrapper<>();
|
|
|
- wrapper.lambda().eq(TBUser::getLoginName, loginName).eq(TBUser::getOrgId, tbOrg.getId());
|
|
|
+ wrapper.lambda().eq(TBUser::getLoginName, loginName);
|
|
|
TBUser user = tbUserService.getOne(wrapper);
|
|
|
+ if (Objects.nonNull(user.getOrgId()) && user.getOrgId().longValue() != tbOrg.getId().longValue()) {
|
|
|
+ throw new BusinessException("用户机构不匹配");
|
|
|
+ }
|
|
|
//用户不存在
|
|
|
if (Objects.isNull(user)) {
|
|
|
throw new BusinessException(ExceptionResultEnum.USER_NO);
|
|
@@ -533,10 +550,10 @@ public class TBUserController {
|
|
|
@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) {
|
|
|
- List<TBUser> tbUserList = tbUserService.userQuery(id, loginName, name, role, enable);
|
|
|
+ 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, @ApiParam(value = "分页页码", required = true) @RequestParam int pageNumber, @ApiParam(value = "分页数", required = true) @RequestParam int pageSize) {
|
|
|
+ IPage<Map> tbUserIPage = tbUserService.userQuery(new Page<>(pageNumber, pageSize), id, loginName, name, role, enable);
|
|
|
Map map = new HashMap<>();
|
|
|
- map.put(SystemConstant.RECORDS, tbUserList);
|
|
|
+ map.put(SystemConstant.RECORDS, tbUserIPage);
|
|
|
return ResultUtil.ok(map);
|
|
|
}
|
|
|
|
|
@@ -621,4 +638,57 @@ public class TBUserController {
|
|
|
public Result validateGetVerifyCode() {
|
|
|
return ResultUtil.ok(JacksonUtil.parseJson(SystemConstant.SUCCESS));
|
|
|
}
|
|
|
+
|
|
|
+ @ApiOperation(value = "用户停用/启用接口")
|
|
|
+ @RequestMapping(value = "/enable", method = RequestMethod.POST)
|
|
|
+ @Transactional
|
|
|
+ @ApiResponses({@ApiResponse(code = 200, message = "{\"success\":true}", response = Result.class)})
|
|
|
+ public Result enable(@ApiJsonObject(name = "enableUser", value = {
|
|
|
+ @ApiJsonProperty(key = "id", type = "long", example = "1", description = "用户id"),
|
|
|
+ @ApiJsonProperty(key = "enable", type = "int", example = "1", description = "停用/启用")
|
|
|
+ }) @ApiParam(value = "用户信息", required = true) @RequestBody Map<String, Object> user) {
|
|
|
+ if (Objects.isNull(user.get("id")) || Objects.equals(user.get("id"), "")) {
|
|
|
+ throw new BusinessException(ExceptionResultEnum.USER_ID_IS_NULL);
|
|
|
+ }
|
|
|
+ Long userId = Long.parseLong(String.valueOf(user.get("id")));
|
|
|
+ if (Objects.isNull(user.get("enable")) || Objects.equals(user.get("enable"), "")) {
|
|
|
+ throw new BusinessException(ExceptionResultEnum.ENABLE_IS_NULL);
|
|
|
+ }
|
|
|
+ Integer enable = Integer.parseInt(String.valueOf(user.get("enable")));
|
|
|
+ TBUser tbUser = tbUserService.getById(userId);
|
|
|
+ if (Objects.isNull(tbUser)) {
|
|
|
+ throw new BusinessException(ExceptionResultEnum.USER_NO);
|
|
|
+ }
|
|
|
+ //保存用户
|
|
|
+ tbUser.setEnable(enable);
|
|
|
+ tbUserService.updateById(tbUser);
|
|
|
+ return ResultUtil.ok(JSONObject.parseObject(SystemConstant.SUCCESS));
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "用户修改密码接口")
|
|
|
+ @RequestMapping(value = "/updatePwd", method = RequestMethod.POST)
|
|
|
+ @ApiResponses({@ApiResponse(code = 200, message = "{\"success\":true}", response = Result.class)})
|
|
|
+ @Transactional
|
|
|
+ public Result updatePwd(@ApiJsonObject(name = "userUpdatePwd", value = {
|
|
|
+ @ApiJsonProperty(key = "id", type = "long", example = "1", description = "用户ID"),
|
|
|
+ @ApiJsonProperty(key = "password", description = "新密码")
|
|
|
+ }) @ApiParam(value = "用户信息", required = true) @RequestBody Map<String, Object> mapParameter) {
|
|
|
+ if (Objects.isNull(mapParameter.get("id")) || Objects.equals(mapParameter.get("id"), "")) {
|
|
|
+ throw new BusinessException(ExceptionResultEnum.USER_ID_IS_NULL);
|
|
|
+ }
|
|
|
+ Long id = Long.parseLong(String.valueOf(mapParameter.get("id")));
|
|
|
+ if (Objects.isNull(mapParameter.get("password")) || Objects.equals(mapParameter.get("password"), "")) {
|
|
|
+ throw new BusinessException(ExceptionResultEnum.PASSWORD_IS_NULL);
|
|
|
+ }
|
|
|
+ String password = String.valueOf(mapParameter.get("password"));
|
|
|
+ TBUser tbUser = tbUserService.getById(id);
|
|
|
+ if (Objects.isNull(tbUser)) {
|
|
|
+ throw new BusinessException(ExceptionResultEnum.USER_NO);
|
|
|
+ }
|
|
|
+ TBUser currentUser = (TBUser) ServletUtil.getRequestAccount();
|
|
|
+ tbUser.setPassword(password);
|
|
|
+ tbUser.setUpdateId(currentUser.getId());
|
|
|
+ tbUserService.updateById(tbUser);
|
|
|
+ return ResultUtil.ok(JacksonUtil.parseJson(SystemConstant.SUCCESS));
|
|
|
+ }
|
|
|
}
|