|
@@ -1,24 +1,22 @@
|
|
|
package cn.com.qmth.print.manage.controller;
|
|
|
|
|
|
+import cn.com.qmth.print.manage.config.PmConstants;
|
|
|
import cn.com.qmth.print.manage.entity.UserEntity;
|
|
|
import cn.com.qmth.print.manage.enums.RoleMeta;
|
|
|
import cn.com.qmth.print.manage.service.PmSession;
|
|
|
import cn.com.qmth.print.manage.service.UserService;
|
|
|
import cn.com.qmth.print.manage.service.query.UserQuery;
|
|
|
-
|
|
|
-import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonNullFormatVisitor;
|
|
|
import com.qmth.boot.api.annotation.Aac;
|
|
|
import com.qmth.boot.api.annotation.BOOL;
|
|
|
import com.qmth.boot.api.constant.ApiConstant;
|
|
|
import com.qmth.boot.core.exception.StatusException;
|
|
|
-
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
-import javax.management.relation.Role;
|
|
|
import java.io.IOException;
|
|
|
import java.util.Date;
|
|
|
import java.util.Objects;
|
|
@@ -65,11 +63,45 @@ public class UserController extends BaseController {
|
|
|
public Object save(@RequestAttribute PmSession accessEntity, @RequestBody UserEntity user, @RequestParam(required = false) MultipartFile file) throws IOException {
|
|
|
Long userId = getAccessUserId(accessEntity);
|
|
|
UserEntity requestUser = userService.getById(userId);
|
|
|
- if (Objects.isNull(requestUser)){
|
|
|
+ if (Objects.isNull(requestUser)) {
|
|
|
throw new StatusException("当前用户不存在");
|
|
|
}
|
|
|
return userService.save(requestUser, user, file);
|
|
|
}
|
|
|
|
|
|
- // TODO: 2023/10/17 修改密码 初始化密码
|
|
|
+ @ApiOperation(value = "修改用户密码", notes = "修改密码")
|
|
|
+ @RequestMapping(value = "/update_password", method = RequestMethod.POST)
|
|
|
+ @Transactional
|
|
|
+ public void updatePassword(@RequestAttribute PmSession accessEntity, @RequestParam String password) {
|
|
|
+ Long userId = getAccessUserId(accessEntity);
|
|
|
+ UserEntity requestUser = userService.getById(userId);
|
|
|
+ requestUser.setPassword(password);
|
|
|
+ requestUser.setPasswordCount(requestUser.getPasswordCount() + 1);
|
|
|
+ requestUser.setUpdaterId(userId);
|
|
|
+ requestUser.setUpdateTime(new Date());
|
|
|
+ userService.updateById(requestUser);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @ApiOperation(value = "重置用户密码", notes = "重置密码")
|
|
|
+ @RequestMapping(value = "/reset_password", method = RequestMethod.POST)
|
|
|
+ @Transactional
|
|
|
+ public void resetPassword(@RequestAttribute PmSession accessEntity, @RequestParam Long userId) {
|
|
|
+ Long requestUserId = getAccessUserId(accessEntity);
|
|
|
+ UserEntity requestUser = userService.getById(requestUserId);
|
|
|
+
|
|
|
+ if (!RoleMeta.ADMIN.equals(requestUser.getRole())) {
|
|
|
+ throw new StatusException("只有管理员能重置密码");
|
|
|
+ }
|
|
|
+
|
|
|
+ UserEntity db = userService.getById(userId);
|
|
|
+ if (Objects.isNull(db)) {
|
|
|
+ throw new StatusException("用户不存在");
|
|
|
+ }
|
|
|
+ db.setPassword(PmConstants.DEFAULT_PASSWORD);
|
|
|
+ db.setPasswordCount(db.getPasswordCount() + 1);
|
|
|
+ db.setUpdaterId(userId);
|
|
|
+ db.setUpdateTime(new Date());
|
|
|
+ userService.updateById(db);
|
|
|
+ }
|
|
|
}
|