♻️ Refactoring code.优化代码,R对象仅在控制器层返回

This commit is contained in:
lishangbu 2020-05-14 05:04:16 +08:00
parent c7fafda6e5
commit c0e7a623e6
9 changed files with 24 additions and 24 deletions

View File

@ -113,7 +113,8 @@ public class DictController {
@DeleteMapping("/{id}")
@PreAuthorize("@pms.hasPermission('sys_dict_del')")
public R removeById(@PathVariable Integer id) {
return sysDictService.removeDict(id);
sysDictService.removeDict(id);
return R.ok();
}
/**
@ -126,7 +127,8 @@ public class DictController {
@SysLog("修改字典")
@PreAuthorize("@pms.hasPermission('sys_dict_edit')")
public R updateById(@Valid @RequestBody SysDict sysDict) {
return sysDictService.updateDict(sysDict);
sysDictService.updateDict(sysDict);
return R.ok();
}
/**

View File

@ -122,7 +122,7 @@ public class MenuController {
@DeleteMapping("/{id}")
@PreAuthorize("@pms.hasPermission('sys_menu_del')")
public R removeById(@PathVariable Integer id) {
return sysMenuService.removeMenuById(id);
return R.ok(sysMenuService.removeMenuById(id));
}
/**

View File

@ -163,7 +163,7 @@ public class UserController {
@SysLog("修改个人信息")
@PutMapping("/edit")
public R updateUserInfo(@Valid @RequestBody UserDTO userDto) {
return userService.updateUserInfo(userDto);
return R.ok(userService.updateUserInfo(userDto));
}
/**

View File

@ -19,7 +19,6 @@ package com.pig4cloud.pig.admin.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.pig4cloud.pig.admin.api.entity.SysDict;
import com.pig4cloud.pig.common.core.util.R;
/**
* 字典表
@ -35,7 +34,7 @@ public interface SysDictService extends IService<SysDict> {
* @param id
* @return
*/
R removeDict(Integer id);
void removeDict(Integer id);
/**
* 更新字典
@ -43,5 +42,5 @@ public interface SysDictService extends IService<SysDict> {
* @param sysDict 字典
* @return
*/
R updateDict(SysDict sysDict);
void updateDict(SysDict sysDict);
}

View File

@ -23,7 +23,6 @@ import com.baomidou.mybatisplus.extension.service.IService;
import com.pig4cloud.pig.admin.api.dto.MenuTree;
import com.pig4cloud.pig.admin.api.entity.SysMenu;
import com.pig4cloud.pig.admin.api.vo.MenuVO;
import com.pig4cloud.pig.common.core.util.R;
import java.util.List;
import java.util.Set;
@ -49,9 +48,9 @@ public interface SysMenuService extends IService<SysMenu> {
* 级联删除菜单
*
* @param id 菜单ID
* @return 成功失败
* @return true成功,false失败
*/
R removeMenuById(Integer id);
Boolean removeMenuById(Integer id);
/**
* 更新菜单信息

View File

@ -25,7 +25,6 @@ import com.pig4cloud.pig.admin.api.dto.UserDTO;
import com.pig4cloud.pig.admin.api.dto.UserInfo;
import com.pig4cloud.pig.admin.api.entity.SysUser;
import com.pig4cloud.pig.admin.api.vo.UserVO;
import com.pig4cloud.pig.common.core.util.R;
import java.util.List;
@ -65,7 +64,7 @@ public interface SysUserService extends IService<SysUser> {
* @param userDto 用户信息
* @return Boolean
*/
R<Boolean> updateUserInfo(UserDTO userDto);
Boolean updateUserInfo(UserDTO userDto);
/**
* 更新指定用户信息

View File

@ -26,7 +26,6 @@ import com.pig4cloud.pig.admin.mapper.SysDictMapper;
import com.pig4cloud.pig.admin.service.SysDictService;
import com.pig4cloud.pig.common.core.constant.CacheConstants;
import com.pig4cloud.pig.common.core.constant.enums.DictTypeEnum;
import com.pig4cloud.pig.common.core.util.R;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.stereotype.Service;
@ -53,14 +52,13 @@ public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, SysDict> impl
@Override
@CacheEvict(value = CacheConstants.DICT_DETAILS, allEntries = true)
@Transactional(rollbackFor = Exception.class)
public R removeDict(Integer id) {
public void removeDict(Integer id) {
SysDict dict = this.getById(id);
// 系统内置
Assert.state(!DictTypeEnum.SYSTEM.getType().equals(dict.getSystem()),"系统内置字典项目不能删除");
baseMapper.deleteById(id);
dictItemMapper.delete(Wrappers.<SysDictItem>lambdaQuery()
.eq(SysDictItem::getDictId, id));
return R.ok();
}
/**
@ -70,10 +68,10 @@ public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, SysDict> impl
* @return
*/
@Override
public R updateDict(SysDict dict) {
public void updateDict(SysDict dict) {
SysDict sysDict = this.getById(dict.getId());
// 系统内置
Assert.state(!DictTypeEnum.SYSTEM.getType().equals(sysDict.getSystem()),"系统内置字典项目不能修改");
return R.ok(this.updateById(dict));
this.updateById(dict);
}
}

View File

@ -18,7 +18,6 @@
package com.pig4cloud.pig.admin.service.impl;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pig4cloud.pig.admin.api.dto.MenuTree;
@ -32,7 +31,6 @@ import com.pig4cloud.pig.admin.service.SysMenuService;
import com.pig4cloud.pig.common.core.constant.CacheConstants;
import com.pig4cloud.pig.common.core.constant.CommonConstants;
import com.pig4cloud.pig.common.core.constant.enums.MenuTypeEnum;
import com.pig4cloud.pig.common.core.util.R;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
@ -64,10 +62,16 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
return baseMapper.listMenusByRoleId(roleId);
}
/**
* 级联删除菜单
*
* @param id 菜单ID
* @return true成功,false失败
*/
@Override
@Transactional(rollbackFor = Exception.class)
@CacheEvict(value = CacheConstants.MENU_DETAILS, allEntries = true)
public R removeMenuById(Integer id) {
public Boolean removeMenuById(Integer id) {
// 查询父节点为当前节点的节点
List<SysMenu> menuList = this.list(Wrappers.<SysMenu>query()
.lambda().eq(SysMenu::getParentId, id));
@ -76,7 +80,7 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
sysRoleMenuMapper.delete(Wrappers.<SysRoleMenu>query()
.lambda().eq(SysRoleMenu::getMenuId, id));
//删除当前菜单及其子菜单
return R.ok(this.removeById(id));
return this.removeById(id);
}
@Override

View File

@ -36,7 +36,6 @@ import com.pig4cloud.pig.admin.mapper.SysUserMapper;
import com.pig4cloud.pig.admin.service.*;
import com.pig4cloud.pig.common.core.constant.CacheConstants;
import com.pig4cloud.pig.common.core.constant.CommonConstants;
import com.pig4cloud.pig.common.core.util.R;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
@ -162,7 +161,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
@Override
@CacheEvict(value = CacheConstants.USER_DETAILS, key = "#userDto.username")
public R<Boolean> updateUserInfo(UserDTO userDto) {
public Boolean updateUserInfo(UserDTO userDto) {
UserVO userVO = baseMapper.getUserVoByUsername(userDto.getUsername());
SysUser sysUser = new SysUser();
@ -174,7 +173,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
sysUser.setPhone(userDto.getPhone());
sysUser.setUserId(userVO.getUserId());
sysUser.setAvatar(userDto.getAvatar());
return R.ok(this.updateById(sysUser));
return this.updateById(sysUser);
}
@Override