roleMenuUpd(Integer roleId, @RequestParam("menuIds[]") Integer[] menuIds) {
+ return new R<>(sysRoleMenuService.insertRoleMenus(getRole().get(0),roleId,menuIds));
}
}
diff --git a/pig-admin-service/src/main/java/com/github/pig/admin/controller/UserController.java b/pig-admin-service/src/main/java/com/github/pig/admin/controller/UserController.java
index 8effaadb..1bae0a04 100644
--- a/pig-admin-service/src/main/java/com/github/pig/admin/controller/UserController.java
+++ b/pig-admin-service/src/main/java/com/github/pig/admin/controller/UserController.java
@@ -2,8 +2,8 @@ package com.github.pig.admin.controller;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
-import com.github.pig.common.bean.QiniuPropertiesConfig;
import com.github.pig.admin.dto.UserDto;
+import com.github.pig.common.bean.QiniuPropertiesConfig;
import com.github.pig.admin.dto.UserInfo;
import com.github.pig.admin.entity.SysUser;
import com.github.pig.admin.entity.SysUserRole;
diff --git a/pig-admin-service/src/main/java/com/github/pig/admin/service/SysLogService.java b/pig-admin-service/src/main/java/com/github/pig/admin/service/SysLogService.java
index c333065c..a9dcc863 100644
--- a/pig-admin-service/src/main/java/com/github/pig/admin/service/SysLogService.java
+++ b/pig-admin-service/src/main/java/com/github/pig/admin/service/SysLogService.java
@@ -2,6 +2,7 @@ package com.github.pig.admin.service;
import com.baomidou.mybatisplus.service.IService;
import com.github.pig.common.entity.SysLog;
+import com.github.pig.common.util.R;
/**
*
@@ -13,4 +14,11 @@ import com.github.pig.common.entity.SysLog;
*/
public interface SysLogService extends IService {
+ /**
+ * 通过ID删除日志(逻辑删除)
+ *
+ * @param id 日志ID
+ * @return true/false
+ */
+ Boolean updateByLogId(Integer id);
}
diff --git a/pig-admin-service/src/main/java/com/github/pig/admin/service/SysMenuService.java b/pig-admin-service/src/main/java/com/github/pig/admin/service/SysMenuService.java
index 541b2ede..69869183 100644
--- a/pig-admin-service/src/main/java/com/github/pig/admin/service/SysMenuService.java
+++ b/pig-admin-service/src/main/java/com/github/pig/admin/service/SysMenuService.java
@@ -31,4 +31,22 @@ public interface SysMenuService extends IService {
* @return 权限列表
*/
String[] findPermission(String[] roles);
+
+ /**
+ * 级联删除菜单
+ *
+ * @param id 菜单ID
+ * @param role 角色
+ * @return 成功、失败
+ */
+ Boolean deleteMenu(Integer id, String role);
+
+ /**
+ * 更新菜单信息
+ *
+ * @param sysMenu 菜单信息
+ * @param role 角色
+ * @return 成功、失败
+ */
+ Boolean updateMenuById(SysMenu sysMenu, String role);
}
diff --git a/pig-admin-service/src/main/java/com/github/pig/admin/service/SysRoleMenuService.java b/pig-admin-service/src/main/java/com/github/pig/admin/service/SysRoleMenuService.java
index b814763a..12fce7b1 100644
--- a/pig-admin-service/src/main/java/com/github/pig/admin/service/SysRoleMenuService.java
+++ b/pig-admin-service/src/main/java/com/github/pig/admin/service/SysRoleMenuService.java
@@ -13,5 +13,15 @@ import com.github.pig.admin.entity.SysRoleMenu;
* @since 2017-10-29
*/
public interface SysRoleMenuService extends IService {
-
+
+ /**
+ * 更新角色菜单
+ *
+ *
+ * @param role
+ * @param roleId 角色
+ * @param menuIds 菜单列表
+ * @return
+ */
+ Boolean insertRoleMenus(String role, Integer roleId, Integer[] menuIds);
}
diff --git a/pig-admin-service/src/main/java/com/github/pig/admin/service/impl/SysLogServiceImpl.java b/pig-admin-service/src/main/java/com/github/pig/admin/service/impl/SysLogServiceImpl.java
index 12cc897a..5770317f 100644
--- a/pig-admin-service/src/main/java/com/github/pig/admin/service/impl/SysLogServiceImpl.java
+++ b/pig-admin-service/src/main/java/com/github/pig/admin/service/impl/SysLogServiceImpl.java
@@ -3,9 +3,14 @@ package com.github.pig.admin.service.impl;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.github.pig.admin.mapper.SysLogMapper;
import com.github.pig.admin.service.SysLogService;
+import com.github.pig.common.constant.CommonConstant;
import com.github.pig.common.entity.SysLog;
+import com.github.pig.common.util.Assert;
+import com.github.pig.common.util.R;
import org.springframework.stereotype.Service;
+import java.util.Date;
+
/**
*
* 日志表 服务实现类
@@ -17,4 +22,14 @@ import org.springframework.stereotype.Service;
@Service
public class SysLogServiceImpl extends ServiceImpl implements SysLogService {
+ @Override
+ public Boolean updateByLogId(Integer id) {
+ Assert.isNull(id, "日志ID为空");
+
+ SysLog sysLog = new SysLog();
+ sysLog.setId(id);
+ sysLog.setDelFlag(CommonConstant.STATUS_DEL);
+ sysLog.setUpdateTime(new Date());
+ return updateById(sysLog);
+ }
}
diff --git a/pig-admin-service/src/main/java/com/github/pig/admin/service/impl/SysMenuServiceImpl.java b/pig-admin-service/src/main/java/com/github/pig/admin/service/impl/SysMenuServiceImpl.java
index bf188cbc..43d27f12 100644
--- a/pig-admin-service/src/main/java/com/github/pig/admin/service/impl/SysMenuServiceImpl.java
+++ b/pig-admin-service/src/main/java/com/github/pig/admin/service/impl/SysMenuServiceImpl.java
@@ -1,12 +1,16 @@
package com.github.pig.admin.service.impl;
+import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.github.pig.admin.entity.SysMenu;
import com.github.pig.admin.mapper.SysMenuMapper;
import com.github.pig.admin.service.SysMenuService;
+import com.github.pig.common.constant.CommonConstant;
+import com.github.pig.common.util.Assert;
import com.github.pig.common.vo.MenuVo;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
@@ -50,4 +54,28 @@ public class SysMenuServiceImpl extends ServiceImpl impl
return permissions.toArray(new String[permissions.size()]);
}
+
+ @Override
+ @CacheEvict(value = "menu_details", key = "#role + '_menu'")
+ public Boolean deleteMenu(Integer id, String role) {
+ Assert.isNull(id, "菜单ID不能为空");
+ // 删除当前节点
+ SysMenu condition1 = new SysMenu();
+ condition1.setMenuId(id);
+ condition1.setDelFlag(CommonConstant.STATUS_DEL);
+ this.updateById(condition1);
+
+ // 删除父节点为当前节点的节点
+ SysMenu conditon2 = new SysMenu();
+ conditon2.setParentId(id);
+ SysMenu sysMenu = new SysMenu();
+ sysMenu.setDelFlag(CommonConstant.STATUS_DEL);
+ return this.update(sysMenu, new EntityWrapper<>(conditon2));
+ }
+
+ @Override
+ @CacheEvict(value = "menu_details", key = "#role + '_menu'")
+ public Boolean updateMenuById(SysMenu sysMenu, String role) {
+ return this.updateById(sysMenu);
+ }
}
diff --git a/pig-admin-service/src/main/java/com/github/pig/admin/service/impl/SysRoleMenuServiceImpl.java b/pig-admin-service/src/main/java/com/github/pig/admin/service/impl/SysRoleMenuServiceImpl.java
index 04b77597..5a1809a0 100644
--- a/pig-admin-service/src/main/java/com/github/pig/admin/service/impl/SysRoleMenuServiceImpl.java
+++ b/pig-admin-service/src/main/java/com/github/pig/admin/service/impl/SysRoleMenuServiceImpl.java
@@ -1,11 +1,16 @@
package com.github.pig.admin.service.impl;
+import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.github.pig.admin.entity.SysRoleMenu;
import com.github.pig.admin.mapper.SysRoleMenuMapper;
import com.github.pig.admin.service.SysRoleMenuService;
+import org.springframework.cache.annotation.CacheEvict;
import org.springframework.stereotype.Service;
+import java.util.ArrayList;
+import java.util.List;
+
/**
*
* 角色菜单表 服务实现类
@@ -16,5 +21,20 @@ import org.springframework.stereotype.Service;
*/
@Service
public class SysRoleMenuServiceImpl extends ServiceImpl implements SysRoleMenuService {
-
+ @Override
+ @CacheEvict(value = "menu_details", key = "#role + '_menu'")
+ public Boolean insertRoleMenus(String role, Integer roleId, Integer[] menuIds) {
+ SysRoleMenu condition = new SysRoleMenu();
+ condition.setRoleId(roleId);
+ this.delete(new EntityWrapper<>(condition));
+
+ List roleMenuList = new ArrayList<>();
+ for (Integer menuId : menuIds) {
+ SysRoleMenu roleMenu = new SysRoleMenu();
+ roleMenu.setRoleId(roleId);
+ roleMenu.setMenuId(menuId);
+ roleMenuList.add(roleMenu);
+ }
+ return this.insertBatch(roleMenuList);
+ }
}
diff --git a/pig-common/pom.xml b/pig-common/pom.xml
index f5071651..a2cdd452 100644
--- a/pig-common/pom.xml
+++ b/pig-common/pom.xml
@@ -67,6 +67,12 @@
org.springframework.boot
spring-boot-starter-aop
+
+
+ org.hibernate
+ hibernate-validator
+ 5.4.1.Final
+
diff --git a/pig-common/src/main/java/com/github/pig/common/bean/ControllerAop.java b/pig-common/src/main/java/com/github/pig/common/bean/ControllerAop.java
index c0806bb0..b17a234b 100644
--- a/pig-common/src/main/java/com/github/pig/common/bean/ControllerAop.java
+++ b/pig-common/src/main/java/com/github/pig/common/bean/ControllerAop.java
@@ -30,17 +30,37 @@ public class ControllerAop {
private static final Logger logger = LoggerFactory.getLogger(ControllerAop.class);
@Pointcut("execution(public com.github.pig.common.util.R *(..))")
- public void pointCut() {
+ public void pointCutR() {
}
/**
* 拦截器具体实现
*
- * @param pjp 切点
+ * @param pjp 切点 所有返回对象R
* @return R 结果包装
*/
- @Around("pointCut()")
- public Object methodHandler(ProceedingJoinPoint pjp) {
+ @Around("pointCutR()")
+ public Object methodRHandler(ProceedingJoinPoint pjp) {
+ return methodHandler(pjp);
+ }
+
+
+ @Pointcut("execution(public com.baomidou.mybatisplus.plugins.Page *(..))")
+ public void pointCutPage() {
+ }
+
+ /**
+ * 拦截器具体实现
+ *
+ * @param pjp 切点 所有返回对象Page
+ * @return R 结果包装
+ */
+ @Around("pointCutPage()")
+ public Object methodPageHandler(ProceedingJoinPoint pjp) {
+ return methodHandler(pjp);
+ }
+
+ private Object methodHandler(ProceedingJoinPoint pjp) {
long startTime = System.currentTimeMillis();
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
@@ -56,10 +76,10 @@ public class ControllerAop {
logger.info("CLASS_METHOD : " + pjp.getSignature().getDeclaringTypeName() + "." + pjp.getSignature().getName());
logger.info("ARGS : " + Arrays.toString(pjp.getArgs()));
- R> result;
+ Object result;
try {
- result = (R>) pjp.proceed();
+ result = pjp.proceed();
logger.info(pjp.getSignature() + "use time:" + (System.currentTimeMillis() - startTime));
} catch (Throwable e) {
result = handlerException(pjp, e);
diff --git a/pig-common/src/main/java/com/github/pig/common/util/Assert.java b/pig-common/src/main/java/com/github/pig/common/util/Assert.java
new file mode 100644
index 00000000..78251789
--- /dev/null
+++ b/pig-common/src/main/java/com/github/pig/common/util/Assert.java
@@ -0,0 +1,53 @@
+package com.github.pig.common.util;
+
+import com.github.pig.common.util.exception.CheckException;
+import org.apache.commons.lang.StringUtils;
+
+import javax.validation.ConstraintViolation;
+import javax.validation.Validation;
+import javax.validation.Validator;
+import java.util.Set;
+
+/**
+ * 数据校验
+ * @author chenshun
+ * @email sunlightcs@gmail.com
+ * @date 2017-03-23 15:50
+ */
+public abstract class Assert {
+ private static Validator validator;
+
+ static {
+ validator = Validation.buildDefaultValidatorFactory().getValidator();
+ }
+
+ /**
+ * 校验对象
+ * @param object 待校验对象
+ * @param groups 待校验的组
+ * @throws CheckException 校验不通过,则报RRException异常
+ */
+ public static void validateEntity(Object object, Class>... groups)
+ throws CheckException {
+ Set> constraintViolations = validator.validate(object, groups);
+ if (!constraintViolations.isEmpty()) {
+ StringBuilder msg = new StringBuilder();
+ for(ConstraintViolation