Commit 37241b97 authored by 王向伟's avatar 王向伟

添加修改密码的功能,删除角色时同时删除用户角色关系表中的相关数据

parent 57883159
......@@ -16,8 +16,10 @@ public class UserRoleMapping {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "user_id")
private Long userId;
@Column(name = "role_id")
private Long roleId;
}
......@@ -2,11 +2,9 @@ package cn.quantgroup.cashloanflowboss.api.mapping;
import cn.quantgroup.cashloanflowboss.core.persistence.CashLoanFlowBossPubConfDataSource;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.stereotype.Repository;
import javax.transaction.Transactional;
import java.util.List;
/**
* Created by WeiWei on 2019/7/22.
......
package cn.quantgroup.cashloanflowboss.api.role.service;
import cn.quantgroup.cashloanflowboss.api.mapping.UserRoleMapping;
import cn.quantgroup.cashloanflowboss.api.mapping.UserRoleMappingRepository;
import cn.quantgroup.cashloanflowboss.api.permissionmodule.entity.Permission;
import cn.quantgroup.cashloanflowboss.api.permissionmodule.repository.PermissionRepository;
import cn.quantgroup.cashloanflowboss.api.role.entity.Role;
......@@ -9,7 +9,6 @@ import cn.quantgroup.cashloanflowboss.api.role.model.RoleModelVo;
import cn.quantgroup.cashloanflowboss.api.role.model.RoleQueryModel;
import cn.quantgroup.cashloanflowboss.api.role.repository.RoleRepository;
import cn.quantgroup.cashloanflowboss.core.base.Result;
import cn.quantgroup.cashloanflowboss.api.mapping.UserRoleMappingRepository;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
......@@ -122,8 +121,8 @@ public class RoleServiceImpl implements RoleService {
Long parentId = roleModelVo.getParentId();
if (parentId != null) {
if(!roleRepository.exists(parentId)){
log.error("{} 不存在父角色 id={}",LOG_PRE,parentId);
if (!roleRepository.exists(parentId)) {
log.error("{} 不存在父角色 id={}", LOG_PRE, parentId);
return Result.buildFail("父角色不存在");
}
Role parent = roleRepository.getOne(parentId);
......@@ -150,7 +149,7 @@ public class RoleServiceImpl implements RoleService {
public Result<Boolean> deleteRole(Long roleId) {
final String LOG_PRE = "RoleServiceImpl.deleteRole";
log.info("{} 删除角色 roleId={}", LOG_PRE, roleId);
if(roleId == null){
if (roleId == null) {
log.error("{} 删除角色失败 id为空");
return Result.buildFail("角色id不能为空");
}
......@@ -166,8 +165,8 @@ public class RoleServiceImpl implements RoleService {
public Result<List<RoleModel>> getAll() {
List<Role> all = roleRepository.findAll();
List<RoleModel> list = new ArrayList<>();
if(CollectionUtils.isNotEmpty(all)){
all.forEach(e->{
if (CollectionUtils.isNotEmpty(all)) {
all.forEach(e -> {
RoleModel model = new RoleModel();
model.setId(e.getId());
model.setName(e.getName());
......
......@@ -4,29 +4,17 @@ import cn.quantgroup.cashloanflowboss.api.user.dictionary.UserRank;
import cn.quantgroup.cashloanflowboss.api.user.dictionary.UserStatus;
import cn.quantgroup.cashloanflowboss.api.user.entity.User;
import cn.quantgroup.cashloanflowboss.api.user.model.*;
import cn.quantgroup.cashloanflowboss.core.base.Pagination;
import cn.quantgroup.cashloanflowboss.api.user.service.UserService;
import cn.quantgroup.cashloanflowboss.component.security.annotiation.Security;
import cn.quantgroup.cashloanflowboss.component.validator.constraints.NotEmpty;
import cn.quantgroup.cashloanflowboss.core.base.Result;
import cn.quantgroup.cashloanflowboss.core.base.Tuple;
import cn.quantgroup.cashloanflowboss.spi.user.service.XyqbUserService;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;
......@@ -153,38 +141,40 @@ public class UserController {
/**
* 添加用户
*
* @param userModelVo
* @return
*/
// @Security(authorityId = "User.add")
@PostMapping(value = "/add")
public Result<Boolean> addUser(@RequestBody @Valid UserModelVo userModelVo){
public Result<Boolean> addUser(@RequestBody @Valid UserModelVo userModelVo) {
return userService.addUser(userModelVo);
}
@PutMapping("/modify")
// @Security(authorityId = "User.update")
public Result<Boolean> modifyUser(@RequestBody @Valid UserModelVo userModelVo){
public Result<Boolean> modifyUser(@RequestBody @Valid UserModelVo userModelVo) {
return userService.modifyUser(userModelVo);
}
/**
* 根据用户名、角色分页查询
*
* @param queryUserListModel
* @return
*/
@GetMapping("/list/get")
//@Security(authorityId = "User.list")
public Result<Page<User>> UserList(@Valid QueryUserListModel queryUserListModel){
public Result<Page<User>> UserList(@Valid QueryUserListModel queryUserListModel) {
return userService.getUserList(queryUserListModel);
}
@GetMapping("/rank")
public Result<List<String>> userRank(){
public Result<List<String>> userRank() {
List<String> list = new ArrayList<>();
for (UserRank value : UserRank.values()) {
if(value == UserRank.ADMINISTRATOR || value == UserRank.SUPER_ADMINISTRATOR){
if (value == UserRank.ADMINISTRATOR || value == UserRank.SUPER_ADMINISTRATOR) {
continue;
}
list.add(value.name());
......@@ -194,7 +184,7 @@ public class UserController {
@GetMapping("/status")
public Result<List<String>> userStatus(){
public Result<List<String>> userStatus() {
List<String> list = new ArrayList<>();
for (UserStatus value : UserStatus.values()) {
list.add(value.name());
......@@ -204,7 +194,7 @@ public class UserController {
@PutMapping("/update/password")
// @Security(authorityId = "User.update")
public Result<Boolean> modifyUser(@RequestBody @Valid UpdatePasswordParam param){
public Result<Boolean> modifyUser(@RequestBody @Valid UpdatePasswordParam param) {
return userService.updatePassword(param);
}
......
......@@ -12,8 +12,7 @@ public class UpdatePasswordParam {
@NotEmpty(message = "请输入账号")
private String username;
@NotEmpty(message = "请输入旧密码")
private String oldPassword;
@NotEmpty(message = "请输入新密码")
private String newPassword;
......
......@@ -5,11 +5,7 @@ import cn.quantgroup.cashloanflowboss.api.role.entity.Role;
import cn.quantgroup.cashloanflowboss.api.role.repository.RoleRepository;
import cn.quantgroup.cashloanflowboss.api.user.dictionary.UserStatus;
import cn.quantgroup.cashloanflowboss.api.user.entity.User;
import cn.quantgroup.cashloanflowboss.api.user.model.QueryUserListModel;
import cn.quantgroup.cashloanflowboss.api.user.model.UserDetailInfo;
import cn.quantgroup.cashloanflowboss.api.user.model.UserInfoModel;
import cn.quantgroup.cashloanflowboss.api.user.model.UserModelVo;
import cn.quantgroup.cashloanflowboss.api.user.model.UpdatePasswordParam;
import cn.quantgroup.cashloanflowboss.api.user.model.*;
import cn.quantgroup.cashloanflowboss.api.user.repository.UserRepository;
import cn.quantgroup.cashloanflowboss.core.Application;
import cn.quantgroup.cashloanflowboss.core.asserts.Assert;
......@@ -247,9 +243,9 @@ public class UserServiceImpl implements UserService {
Long channelId = user.getChannelId();
if (channelId != null) {
ClfChannelConfiguration configuration = clfChannelConfigurationRepository.findByRegisteredFrom(channelId);
if(configuration == null){
log.error("{},渠道不存在 channelId={}",LOG_PRE,channelId);
return Result.buildFail("channelId="+channelId+"的渠道不存在");
if (configuration == null) {
log.error("{},渠道不存在 channelId={}", LOG_PRE, channelId);
return Result.buildFail("channelId=" + channelId + "的渠道不存在");
}
user.setChannelName(configuration.getChannelName());
}
......@@ -298,9 +294,9 @@ public class UserServiceImpl implements UserService {
//渠道检查
if (channelId != null) {
ClfChannelConfiguration configuration = clfChannelConfigurationRepository.findByRegisteredFrom(channelId);
if(configuration == null){
log.error("{},渠道不存在 channelId={}",LOG_PRE,channelId);
return Result.buildFail("channelId="+channelId+"的渠道不存在");
if (configuration == null) {
log.error("{},渠道不存在 channelId={}", LOG_PRE, channelId);
return Result.buildFail("channelId=" + channelId + "的渠道不存在");
}
exist.setChannelName(configuration.getChannelName());
}
......@@ -332,16 +328,11 @@ public class UserServiceImpl implements UserService {
String logPre = "UserServiceImpl.updatePassword";
log.info("{},修改密码,updatePasswordParam={}", logPre, updatePasswordParam);
User user = userRepository.getUserByUsername(updatePasswordParam.getUsername());
if(Objects.isNull(user)){
log.info("{} 不存在 {} 用户",logPre, updatePasswordParam.getUsername());
if (Objects.isNull(user)) {
log.info("{} 不存在 {} 用户", logPre, updatePasswordParam.getUsername());
return Result.buildFail("用户不存在,不能修改密码");
}
String md5 = MD5Tools.md5(updatePasswordParam.getOldPassword());
if(!md5.equals(user.getPassword())){
log.info("{} 旧密码不正确不能修改密码 username={}",logPre,updatePasswordParam.getUsername());
return Result.buildFail("旧密码错误,不能修改密码");
}
String newPassword = MD5Tools.md5(updatePasswordParam.getNewPassword());
user.setPassword(newPassword);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment