Commit dfba77f2 authored by fangxinjiang's avatar fangxinjiang

代码优化

parent ff8c24dc
......@@ -106,21 +106,21 @@ public interface CommonConstants {
/**
* number 0
*/
String ZERO_String = "0";
String ZERO_STRING = "0";
/**
* number 1
*/
String ONE_String = "1";
String ONE_STRING = "1";
/**
* number 2
*/
String TWO_String = "2";
String TWO_STRING = "2";
/**
* number 3
*/
String THREE_String = "3";
String THREE_STRING = "3";
}
......@@ -34,6 +34,11 @@ public enum MenuTypeEnum {
*/
SYSTEM("0", "系统内置"),
/**
* 字典类型-数据权限配置表示
*/
DATA_FLAG("0", "是"),
/**
* 左侧菜单
*/
......
......@@ -68,6 +68,11 @@ public interface ErrorCodes {
*/
String SYS_MENU_DELETE_SYSTEM = "sys.menu.delete.system";
/**
* 菜单上级菜单不可为数据权限配置类菜单
*/
String SYS_MENU_ADD_PARENT_ERROR = "sys.menu.add.parent.error";
/**
* 菜单存在下级节点 删除失败
*/
......
......@@ -34,4 +34,11 @@ public class Common {
public static boolean isNotNull(Object obj) {
return null != obj;
}
public static boolean isNotNull(String obj) {
if (null == obj || "".equals(obj) || "undefined".equals(obj)){
return true;
}
return false;
}
}
......@@ -17,6 +17,8 @@ sys.param.config.error={0} \u7CFB\u7EDF\u53C2\u6570\u914D\u7F6E\u9519\u8BEF
sys.menu.delete.existing=\u83DC\u5355\u542B\u6709\u4E0B\u7EA7\u4E0D\u80FD\u5220\u9664
sys.menu.delete.system=\u7CFB\u7EDF\u5185\u7F6E\u83DC\u5355\u4E0D\u80FD\u5220\u9664
sys.menu.add.parent.error=\u83DC\u5355\u4E0A\u7EA7\u83DC\u5355\u4E0D\u53EF\u4E3A\u6570\u636E\u6743\u9650\u914D\u7F6E\u7C7B\u83DC\u5355
sys.app.sms.often=\u9A8C\u8BC1\u7801\u53D1\u9001\u8FC7\u9891\u7E41
sys.app.phone.unregistered={0} \u624B\u673A\u53F7\u672A\u6CE8\u518C
......
package com.yifu.cloud.plus.v1.yifu.common.dapr.util;
import cn.hutool.json.JSONUtil;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.CommonConstants;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.SecurityConstants;
import com.yifu.cloud.plus.v1.yifu.common.core.util.R;
......@@ -13,7 +12,6 @@ import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.client.RestTemplate;
import java.net.URI;
import java.net.URL;
/**
* @author fxj
......
......@@ -13,6 +13,7 @@ import org.springframework.validation.BindException;
import org.springframework.validation.FieldError;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;
......@@ -52,7 +53,8 @@ public class GlobalExceptionHandler {
* @ExceptionHandler:当这个Controller中任何一个方法发生异常,一定会被这个方法拦截到
*/
@ExceptionHandler(Exception.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
//@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
@ResponseBody
public R exception(Exception e) {
errorLog( e );
if( null != e.getMessage()){
......
......@@ -16,9 +16,7 @@
package com.yifu.cloud.plus.v1.yifu.admin.api.dto;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.yifu.cloud.plus.v1.yifu.admin.api.entity.SysUser;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
......
......@@ -72,7 +72,7 @@ public class DictController {
*/
@GetMapping("/page")
public R<IPage<SysDict>> getDictPage(Page page, SysDict sysDict) {
return R.ok(sysDictService.page(page, Wrappers.query(sysDict)));
return R.ok(sysDictService.pageAsso(page, sysDict));
}
/**
......
......@@ -124,8 +124,8 @@ public class MenuController {
@PostMapping
@PreAuthorize("@pms.hasPermission('sys_menu_add')")
public R<SysMenu> save(@Valid @RequestBody SysMenu sysMenu) {
sysMenuService.save(sysMenu);
return R.ok(sysMenu);
SysMenu menu = sysMenuService.saveAsso(sysMenu);
return R.ok(menu);
}
/**
......
......@@ -96,10 +96,6 @@ public class UserController {
public UserInfo infoAPI(@RequestParam(required = true,name = "username") String username) {
SysUser user = userService.getOne(Wrappers.<SysUser>query().lambda().eq(SysUser::getUsername, username));
return userService.getUserInfo(user);
/*if (user == null) {
return R.failed(MsgUtils.getMessage(ErrorCodes.SYS_USER_USERINFO_EMPTY, username));
}
return R.ok(userService.getUserInfo(user));*/
}
/**
......
......@@ -15,6 +15,8 @@
*/
package com.yifu.cloud.plus.v1.yifu.admin.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.yifu.cloud.plus.v1.yifu.admin.api.entity.SysDict;
......@@ -45,4 +47,5 @@ public interface SysDictService extends IService<SysDict> {
*/
void clearDictCache();
IPage<SysDict> pageAsso(Page page, SysDict sysDict);
}
......@@ -80,4 +80,6 @@ public interface SysMenuService extends IService<SysMenu> {
IPage<List<SysMenu>> getMenuPage(Page page, SysMenu sysMenu);
List<SysMenu> listOfPageMenu(SysMenu sysMenu);
SysMenu saveAsso(SysMenu sysMenu);
}
......@@ -15,7 +15,11 @@
*/
package com.yifu.cloud.plus.v1.yifu.admin.service.impl;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yifu.cloud.plus.v1.yifu.admin.api.entity.SysDict;
import com.yifu.cloud.plus.v1.yifu.admin.api.entity.SysDictItem;
......@@ -82,4 +86,35 @@ public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, SysDict> impl
}
/**
* @Author fxj
* @Description
* @Date 10:49 2022/6/14
* @Param sysDict
* @return
**/
@Override
public IPage<SysDict> pageAsso(Page page, SysDict sysDict) {
return this.page(page,buildQueryWrapper(sysDict));
}
/**
* 构建查询的 wrapper
* @param sysDict 查询条件
* @return LambdaQueryWrapper
*/
private LambdaQueryWrapper buildQueryWrapper(SysDict sysDict) {
LambdaQueryWrapper<SysDict> wrapper = Wrappers.lambdaQuery();
if (StrUtil.isNotBlank(sysDict.getSystemFlag())){
wrapper.eq(SysDict::getSystemFlag,sysDict.getSystemFlag());
}
if (StrUtil.isNotBlank(sysDict.getType())){
wrapper.likeRight(SysDict::getType,sysDict.getType());
}
if (StrUtil.isNotBlank(sysDict.getDescription())){
wrapper.likeRight(SysDict::getDescription,sysDict.getDescription());
}
return wrapper;
}
}
......@@ -35,6 +35,7 @@ import com.yifu.cloud.plus.v1.yifu.common.core.constant.CacheConstants;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.CommonConstants;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.enums.MenuTypeEnum;
import com.yifu.cloud.plus.v1.yifu.common.core.exception.ErrorCodes;
import com.yifu.cloud.plus.v1.yifu.common.core.util.Common;
import com.yifu.cloud.plus.v1.yifu.common.core.util.MsgUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.CacheEvict;
......@@ -52,19 +53,23 @@ import java.util.function.Function;
import java.util.stream.Collectors;
/**
* <p>
* 菜单权限表 服务实现类
* </p>
*
* @author lengleng
* @since 2017-10-29
*/
* @Author fxj
* @Description
* @Date 10:28 2022/6/14
**/
@Service
@RequiredArgsConstructor
public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> implements SysMenuService {
private final SysRoleMenuMapper sysRoleMenuMapper;
/**
* @Author fxj
* @Description
* @Date 10:28 2022/6/14
* @Param
* @return
**/
@Override
@Cacheable(value = CacheConstants.MENU_DETAILS, key = "#roleId + '_menu'", unless = "#result == null")
public Set<SysMenu> findMenuByRoleId(Long roleId) {
......@@ -172,6 +177,25 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
return baseMapper.selectList(buildQueryWrapper(sysMenu));
}
/**
* @author fxj
* @Date 2022-06-14
* @param sysMenu
* @return
*/
@Override
public SysMenu saveAsso(SysMenu sysMenu) {
if (Common.isNotNull(sysMenu) && Common.isNotNull(sysMenu.getParentId())){
SysMenu menu = baseMapper.selectById(sysMenu.getParentId());
if (Common.isNotNull(menu) && CommonConstants.ONE_STRING.equals(menu.getFlag())){
Assert.state(!MenuTypeEnum.DATA_FLAG.getType().equals(sysMenu.getSystemFlag()),
MsgUtils.getMessage(ErrorCodes.SYS_MENU_ADD_PARENT_ERROR));
}
}
this.save(sysMenu);
return sysMenu;
}
/**
* 构建查询的 wrapper
* @param sysMenu 查询条件
......
......@@ -84,7 +84,7 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
//已存在用户
Assert.state(Common.isEmpty(userRole),MsgUtils.getMessage(ErrorCodes.SYS_ROLE_DELETE_EXIST_USER));
//系统内置
Assert.state(!CommonConstants.ZERO_String.equals(sysRole.getSystemFlag()),MsgUtils.getMessage(ErrorCodes.SYS_ROLE_DELETE_SYSTEM));
Assert.state(!CommonConstants.ZERO_STRING.equals(sysRole.getSystemFlag()),MsgUtils.getMessage(ErrorCodes.SYS_ROLE_DELETE_SYSTEM));
sysRoleMenuMapper.delete(Wrappers.<SysRoleMenu>update().lambda().eq(SysRoleMenu::getRoleId, id));
return this.removeById(id);
}
......
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