Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
smallwei 2020-05-14 10:46:30 +08:00
commit 60a76b6cd5
10 changed files with 39 additions and 49 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

@ -29,6 +29,7 @@ import com.pig4cloud.pig.common.core.util.R;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
/**
* 字典项
@ -54,9 +55,7 @@ public class SysDictItemServiceImpl extends ServiceImpl<SysDictItemMapper, SysDi
SysDictItem dictItem = this.getById(id);
SysDict dict = dictService.getById(dictItem.getDictId());
// 系统内置
if (DictTypeEnum.SYSTEM.getType().equals(dict.getSystem())) {
return R.failed("系统内置字典项目不能删除");
}
Assert.state(!DictTypeEnum.SYSTEM.getType().equals(dict.getSystem()),"系统内置字典项目不能删除");
return R.ok(this.removeById(id));
}
@ -72,9 +71,7 @@ public class SysDictItemServiceImpl extends ServiceImpl<SysDictItemMapper, SysDi
//查询字典
SysDict dict = dictService.getById(item.getDictId());
// 系统内置
if (DictTypeEnum.SYSTEM.getType().equals(dict.getSystem())) {
return R.failed("系统内置字典项目不能删除");
}
Assert.state(!DictTypeEnum.SYSTEM.getType().equals(dict.getSystem()),"系统内置字典项目不能修改");
return R.ok(this.updateById(item));
}
}

View File

@ -26,11 +26,11 @@ 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;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
/**
* 字典表
@ -52,17 +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);
// 系统内置
if (DictTypeEnum.SYSTEM.getType().equals(dict.getSystem())) {
return R.failed("系统内置字典不能删除");
}
Assert.state(!DictTypeEnum.SYSTEM.getType().equals(dict.getSystem()),"系统内置字典项目不能删除");
baseMapper.deleteById(id);
dictItemMapper.delete(Wrappers.<SysDictItem>lambdaQuery()
.eq(SysDictItem::getDictId, id));
return R.ok();
}
/**
@ -72,12 +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());
// 系统内置
if (DictTypeEnum.SYSTEM.getType().equals(sysDict.getSystem())) {
return R.failed("系统内置字典不能修改");
}
return R.ok(this.updateById(dict));
Assert.state(!DictTypeEnum.SYSTEM.getType().equals(sysDict.getSystem()),"系统内置字典项目不能修改");
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,12 +31,12 @@ 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;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import java.util.Comparator;
import java.util.List;
@ -63,21 +62,25 @@ 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));
if (CollUtil.isNotEmpty(menuList)) {
return R.failed("菜单含有下级不能删除");
}
Assert.isNull(menuList,"菜单含有下级不能删除");
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;
@ -46,6 +45,7 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import java.time.LocalDateTime;
import java.util.HashSet;
@ -161,22 +161,19 @@ 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();
if (StrUtil.isNotBlank(userDto.getPassword())
&& StrUtil.isNotBlank(userDto.getNewpassword1())) {
if (ENCODER.matches(userDto.getPassword(), userVO.getPassword())) {
sysUser.setPassword(ENCODER.encode(userDto.getNewpassword1()));
} else {
log.warn("原密码错误,修改密码失败:{}", userDto.getUsername());
return R.failed("原密码错误,修改失败");
}
}
Assert.notNull(userDto.getPassword(),"原密码不存在");
Assert.notNull(userDto.getNewpassword1(),"新密码不存在");
Assert.state(ENCODER.matches(userDto.getPassword(), userVO.getPassword()),"原密码错误,修改失败");
sysUser.setPassword(ENCODER.encode(userDto.getNewpassword1()));
sysUser.setPhone(userDto.getPhone());
sysUser.setUserId(userVO.getUserId());
sysUser.setAvatar(userDto.getAvatar());
return R.ok(this.updateById(sysUser));
return this.updateById(sysUser);
}
@Override