微调
This commit is contained in:
@@ -29,4 +29,8 @@ public interface UserValidMessage {
|
|||||||
String PHONE_FORMAT_ERROR = "电话号码格式错误,请检查phone参数";
|
String PHONE_FORMAT_ERROR = "电话号码格式错误,请检查phone参数";
|
||||||
|
|
||||||
String EMAIL_FORMAT_ERROR = "邮箱格式错误,请检查email参数";
|
String EMAIL_FORMAT_ERROR = "邮箱格式错误,请检查email参数";
|
||||||
|
|
||||||
|
String OLD_PASSWORD_NOT_BLANK = "旧密码不能为空,请检查oldPassword参数";
|
||||||
|
|
||||||
|
String NEW_PASSWORD_NOT_BLANK = "新密码格式错误,请检查newPassword参数";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import cn.hutool.core.util.StrUtil;
|
|||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||||
import com.njcn.common.pojo.constant.OperateType;
|
import com.njcn.common.pojo.constant.OperateType;
|
||||||
|
import com.njcn.common.pojo.constant.SecurityConstants;
|
||||||
import com.njcn.common.pojo.enums.common.LogEnum;
|
import com.njcn.common.pojo.enums.common.LogEnum;
|
||||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||||
import com.njcn.common.pojo.response.HttpResult;
|
import com.njcn.common.pojo.response.HttpResult;
|
||||||
@@ -15,12 +16,15 @@ import com.njcn.web.controller.BaseController;
|
|||||||
import com.njcn.web.utils.HttpResultUtil;
|
import com.njcn.web.utils.HttpResultUtil;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiImplicitParam;
|
import io.swagger.annotations.ApiImplicitParam;
|
||||||
|
import io.swagger.annotations.ApiImplicitParams;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import springfox.documentation.annotations.ApiIgnore;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
@@ -29,7 +33,7 @@ import java.util.List;
|
|||||||
* @since 2024-11-08
|
* @since 2024-11-08
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Api(tags = "")
|
@Api(tags = "用户管理")
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("sysUser")
|
@RequestMapping("sysUser")
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@@ -121,12 +125,32 @@ public class SysUserController extends BaseController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.DOWNLOAD)
|
@OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.UPDATE)
|
||||||
// @PostMapping("/export")
|
@PutMapping("/updatePassword")
|
||||||
// @ApiOperation("导出用户数据")
|
@ApiOperation("修改密码")
|
||||||
// @ApiImplicitParam(name = "queryParam", value = "查询参数", required = true)
|
@ApiImplicitParams({
|
||||||
// public void export(@RequestBody @Validated SysUserParam.UserQueryParam queryParam) {
|
@ApiImplicitParam(name = "id", value = "用户id", required = true),
|
||||||
// sysUserService.exportUserData(queryParam);
|
@ApiImplicitParam(name = "oldPassword", value = "旧密码", required = true),
|
||||||
// }
|
@ApiImplicitParam(name = "newPassword", value = "新密码", required = true)
|
||||||
|
})
|
||||||
|
public HttpResult<Object> updatePassword(@RequestBody @Validated SysUserParam.SysUserUpdatePasswordParam param) {
|
||||||
|
String methodDescribe = getMethodDescribe("updatePassword");
|
||||||
|
LogUtil.njcnDebug(log, "{},用户id:{},用户旧密码:{},新密码:{}", methodDescribe, param.getId(), param.getOldPassword(), param.getNewPassword());
|
||||||
|
if (param.getOldPassword().equals(param.getNewPassword())) {
|
||||||
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, "新密码不能与旧密码相同", methodDescribe);
|
||||||
|
}
|
||||||
|
boolean result = sysUserService.oldPwdConfirm(param.getId(), param.getOldPassword());
|
||||||
|
if (!result) {
|
||||||
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, "原密码错误", methodDescribe);
|
||||||
|
} else {
|
||||||
|
result = sysUserService.updatePassword(param.getId(), param.getNewPassword());
|
||||||
|
if (!result) {
|
||||||
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, "修改密码失败", methodDescribe);
|
||||||
|
} else {
|
||||||
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -76,6 +76,24 @@ public class SysUserParam {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class SysUserUpdatePasswordParam {
|
||||||
|
@ApiModelProperty("用户Id")
|
||||||
|
@NotBlank(message = UserValidMessage.ID_NOT_BLANK)
|
||||||
|
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = UserValidMessage.ID_FORMAT_ERROR)
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
@ApiModelProperty("旧密码")
|
||||||
|
@NotBlank(message = UserValidMessage.OLD_PASSWORD_NOT_BLANK)
|
||||||
|
@Pattern(regexp = PatternRegex.PASSWORD_REGEX, message = UserValidMessage.PASSWORD_FORMAT_ERROR)
|
||||||
|
private String oldPassword;
|
||||||
|
|
||||||
|
@ApiModelProperty("新密码")
|
||||||
|
@NotBlank(message = UserValidMessage.NEW_PASSWORD_NOT_BLANK)
|
||||||
|
@Pattern(regexp = PatternRegex.PASSWORD_REGEX, message = UserValidMessage.PASSWORD_FORMAT_ERROR)
|
||||||
|
private String newPassword;
|
||||||
|
}
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
public static class SysUserQueryParam extends BaseParam {
|
public static class SysUserQueryParam extends BaseParam {
|
||||||
@@ -83,4 +101,5 @@ public class SysUserParam {
|
|||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -90,6 +90,9 @@ public class SysUser extends BaseEntity implements Serializable {
|
|||||||
private Integer state;
|
private Integer state;
|
||||||
|
|
||||||
@TableField(exist = false)
|
@TableField(exist = false)
|
||||||
private List<String> role;
|
private List<String> roleIds;
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
private List<String> roleNames;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -82,6 +82,23 @@ public interface ISysUserService extends IService<SysUser> {
|
|||||||
*/
|
*/
|
||||||
boolean updateUser(SysUserParam.SysUserUpdateParam updateUserParam);
|
boolean updateUser(SysUserParam.SysUserUpdateParam updateUserParam);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 原密码确认
|
||||||
|
*
|
||||||
|
* @param userId 用户ID
|
||||||
|
* @param oldPassword 原密码
|
||||||
|
* @return 结果,true表示确认成功,false表示确认失败
|
||||||
|
*/
|
||||||
|
boolean oldPwdConfirm(String userId, String oldPassword);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改密码
|
||||||
|
* @param userId
|
||||||
|
* @param newPassword
|
||||||
|
* @return 结果,true表示修改成功,false表示修改失败
|
||||||
|
*/
|
||||||
|
boolean updatePassword(String userId, String newPassword);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 批量删除用户
|
* 批量删除用户
|
||||||
*
|
*
|
||||||
@@ -90,4 +107,5 @@ public interface ISysUserService extends IService<SysUser> {
|
|||||||
*/
|
*/
|
||||||
boolean deleteUser(List<String> ids);
|
boolean deleteUser(List<String> ids);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import org.apache.commons.lang3.StringUtils;
|
|||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@@ -60,8 +61,9 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|||||||
queryWrapper.ne("sys_user.state", UserState.DELETED);
|
queryWrapper.ne("sys_user.state", UserState.DELETED);
|
||||||
Page<SysUser> page = this.baseMapper.selectPage(new Page<>(PageFactory.getPageNum(queryParam), PageFactory.getPageSize(queryParam)), queryWrapper);
|
Page<SysUser> page = this.baseMapper.selectPage(new Page<>(PageFactory.getPageNum(queryParam), PageFactory.getPageSize(queryParam)), queryWrapper);
|
||||||
page.getRecords().forEach(sysUser -> {
|
page.getRecords().forEach(sysUser -> {
|
||||||
List<String> roleIds = sysUserRoleService.listRoleByUserId(sysUser.getId()).stream().map(SysRole::getId).collect(Collectors.toList());
|
List<SysRole> sysRoles = sysUserRoleService.listRoleByUserId(sysUser.getId());
|
||||||
sysUser.setRole(roleIds);
|
sysUser.setRoleIds(sysRoles.stream().map(SysRole::getId).collect(Collectors.toList()));
|
||||||
|
sysUser.setRoleNames(sysRoles.stream().map(SysRole::getName).collect(Collectors.toList()));
|
||||||
});
|
});
|
||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
@@ -139,6 +141,31 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|||||||
return result1 && result2;
|
return result1 && result2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean oldPwdConfirm(String userId, String oldPassword) {
|
||||||
|
SysUser user = lambdaQuery().ne(SysUser::getState, UserState.DELETED).eq(SysUser::getId, userId).one();
|
||||||
|
if (ObjectUtil.isNotNull(user)) {
|
||||||
|
String secretkey = Sm4Utils.globalSecretKey;
|
||||||
|
Sm4Utils sm4 = new Sm4Utils(secretkey);
|
||||||
|
if (sm4.encryptData_ECB(oldPassword).equals(user.getPassword())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean updatePassword(String userId, String newPassword) {
|
||||||
|
SysUser user = lambdaQuery().ne(SysUser::getState, UserState.DELETED).eq(SysUser::getId, userId).one();
|
||||||
|
if (ObjectUtil.isNotNull(user)) {
|
||||||
|
String secretkey = Sm4Utils.globalSecretKey;
|
||||||
|
Sm4Utils sm4 = new Sm4Utils(secretkey);
|
||||||
|
user.setPassword(sm4.encryptData_ECB(newPassword));
|
||||||
|
return this.updateById(user);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean deleteUser(List<String> ids) {
|
public boolean deleteUser(List<String> ids) {
|
||||||
return this.lambdaUpdate()
|
return this.lambdaUpdate()
|
||||||
|
|||||||
Reference in New Issue
Block a user