Commit 5bdc2b37 by huangjinxin

feat:重写角色修改

1 parent 0fb8d76f
...@@ -49,8 +49,7 @@ public class RoleController implements IRole { ...@@ -49,8 +49,7 @@ public class RoleController implements IRole {
@Override @Override
public Result<RoleInfo> updateRole(@Validated RoleInfo roleInfo) { public Result<RoleInfo> updateRole(@Validated RoleInfo roleInfo) {
roleInfo = roleService.updateRole(roleInfo); return roleService.updateRole(roleInfo);
return Result.success(roleInfo);
} }
@Override @Override
......
...@@ -33,10 +33,7 @@ import org.springframework.transaction.annotation.Transactional; ...@@ -33,10 +33,7 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.DefaultTransactionDefinition; import org.springframework.transaction.support.DefaultTransactionDefinition;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.*;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
...@@ -104,8 +101,14 @@ public class RoleService { ...@@ -104,8 +101,14 @@ public class RoleService {
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public RoleInfo updateRole(RoleInfo roleInfo) { public Result<RoleInfo> updateRole(RoleInfo roleInfo) {
RoleEntity entity = roleDao.findById(roleInfo.getId()).orElse(null);
if (ObjectUtil.isEmpty(entity)) {
return Result.failed(StatusCodeEnum.ROLE_DOES_NOT_EXIST, null);
}
RoleEntity roleEntity = BeanUtil.copyProperties(roleInfo, RoleEntity.class); RoleEntity roleEntity = BeanUtil.copyProperties(roleInfo, RoleEntity.class);
roleEntity.setCreatedBy(entity.getCreatedBy());
roleEntity.setCreatedTime(entity.getCreatedTime());
roleEntity = roleDao.save(roleEntity); roleEntity = roleDao.save(roleEntity);
List<RoleResourceInfo> resourceInfos = roleInfo.getResourceInfos(); List<RoleResourceInfo> resourceInfos = roleInfo.getResourceInfos();
if (CollectionUtils.isNotEmpty(resourceInfos)) { if (CollectionUtils.isNotEmpty(resourceInfos)) {
...@@ -117,7 +120,7 @@ public class RoleService { ...@@ -117,7 +120,7 @@ public class RoleService {
} }
} }
roleInfo = BeanUtil.copyProperties(roleEntity, RoleInfo.class); roleInfo = BeanUtil.copyProperties(roleEntity, RoleInfo.class);
return roleInfo; return Result.success(roleInfo);
} }
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!