From 570507f7cff00c9b0f37c5c8f6c2887e0230ec11 Mon Sep 17 00:00:00 2001 From: luoyijiucheng <1784525940@qq.com> Date: Fri, 29 Nov 2019 23:43:14 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E8=A7=92=E8=89=B2=E7=9A=84?= =?UTF-8?q?=E5=90=8C=E6=97=B6=EF=BC=8C=E5=88=A0=E9=99=A4sys=5Frole=5Fpermi?= =?UTF-8?q?ssion=E5=92=8Csys=5Fuser=5Frole=E8=A1=A8=E4=B8=AD=E7=9A=84?= =?UTF-8?q?=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 7 +++- .../yeqifu/sys/controller/RoleController.java | 9 ++--- src/main/java/com/yeqifu/sys/entity/Role.java | 1 - .../com/yeqifu/sys/mapper/RoleMapper.java | 16 +++++++++ .../sys/service/impl/RoleServiceImpl.java | 10 ++++++ src/main/resources/application.yml | 4 +-- src/main/resources/log4j.properties | 5 +++ src/main/resources/mapper/sys/RoleMapper.xml | 7 +++- .../templates/system/role/roleManager.html | 33 ++++++++++++++++--- 9 files changed, 77 insertions(+), 15 deletions(-) create mode 100644 src/main/resources/log4j.properties diff --git a/pom.xml b/pom.xml index d6f372c..b002faa 100644 --- a/pom.xml +++ b/pom.xml @@ -81,6 +81,7 @@ mybatis-plus-boot-starter ${mybatisplus.version} + com.baomidou @@ -139,7 +140,11 @@ hutool-all ${hutool.version} - + + + org.apache.commons + commons-lang3 + diff --git a/src/main/java/com/yeqifu/sys/controller/RoleController.java b/src/main/java/com/yeqifu/sys/controller/RoleController.java index e9f1811..7de5414 100644 --- a/src/main/java/com/yeqifu/sys/controller/RoleController.java +++ b/src/main/java/com/yeqifu/sys/controller/RoleController.java @@ -44,8 +44,10 @@ public class RoleController { QueryWrapper queryWrapper = new QueryWrapper(); queryWrapper.like(StringUtils.isNotBlank(roleVo.getName()),"name",roleVo.getName()); queryWrapper.like(StringUtils.isNotBlank(roleVo.getRemark()),"remark",roleVo.getRemark()); + queryWrapper.eq(roleVo.getAvailable()!=null,"available",roleVo.getAvailable()); queryWrapper.ge(roleVo.getStartTime()!=null,"createtime",roleVo.getStartTime()); queryWrapper.le(roleVo.getEndTime()!=null,"createtime",roleVo.getEndTime()); + queryWrapper.orderByDesc("createtime"); roleService.page(page,queryWrapper); return new DataGridView(page.getTotal(),page.getRecords()); } @@ -85,19 +87,18 @@ public class RoleController { /** * 删除角色 - * @param roleVo + * @param id * @return */ @RequestMapping("deleteRole") - public ResultObj deleteRole(RoleVo roleVo){ + public ResultObj deleteRole(Integer id){ try { - roleService.removeById(roleVo); + this.roleService.removeById(id); return ResultObj.DELETE_SUCCESS; } catch (Exception e) { e.printStackTrace(); return ResultObj.DELETE_ERROR; } - } } diff --git a/src/main/java/com/yeqifu/sys/entity/Role.java b/src/main/java/com/yeqifu/sys/entity/Role.java index 68445cf..abbd07a 100644 --- a/src/main/java/com/yeqifu/sys/entity/Role.java +++ b/src/main/java/com/yeqifu/sys/entity/Role.java @@ -3,7 +3,6 @@ package com.yeqifu.sys.entity; import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableId; -import java.time.LocalDateTime; import java.io.Serializable; import java.util.Date; diff --git a/src/main/java/com/yeqifu/sys/mapper/RoleMapper.java b/src/main/java/com/yeqifu/sys/mapper/RoleMapper.java index 4c19a60..6cde0c4 100644 --- a/src/main/java/com/yeqifu/sys/mapper/RoleMapper.java +++ b/src/main/java/com/yeqifu/sys/mapper/RoleMapper.java @@ -2,6 +2,10 @@ package com.yeqifu.sys.mapper; import com.yeqifu.sys.entity.Role; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.io.Serializable; /** *

@@ -11,6 +15,18 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; * @author luoyi- * @since 2019-11-28 */ +@Mapper public interface RoleMapper extends BaseMapper { + /** + * 根据角色ID删除sys_role_permission表中的数据 + * @param id 角色的id + */ + void deleteRolePermissionByRid(@Param("pid") Serializable id); + + /** + * 根据角色ID删除sys_user_role表中的数据 + * @param id 角色的id + */ + void deleteUserRoleByRid(@Param("pid") Serializable id); } diff --git a/src/main/java/com/yeqifu/sys/service/impl/RoleServiceImpl.java b/src/main/java/com/yeqifu/sys/service/impl/RoleServiceImpl.java index a3e8e2f..0e24892 100644 --- a/src/main/java/com/yeqifu/sys/service/impl/RoleServiceImpl.java +++ b/src/main/java/com/yeqifu/sys/service/impl/RoleServiceImpl.java @@ -6,6 +6,8 @@ import com.yeqifu.sys.service.IRoleService; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.springframework.stereotype.Service; +import java.io.Serializable; + /** *

* InnoDB free: 9216 kB 服务实现类 @@ -17,4 +19,12 @@ import org.springframework.stereotype.Service; @Service public class RoleServiceImpl extends ServiceImpl implements IRoleService { + @Override + public boolean removeById(Serializable id) { + //根据角色ID删除sys_role_permission表中的数据 + this.getBaseMapper().deleteRolePermissionByRid(id); + //根据角色ID删除sys_user_role表中的数据 + this.getBaseMapper().deleteUserRoleByRid(id); + return super.removeById(id); + } } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 5645580..e2404ea 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,4 +1,3 @@ - #配置数据源 spring: datasource: @@ -31,8 +30,7 @@ spring: #配置mybatisplus mybatis-plus: - mapper-locations: - -classpath: mapper/*/*Mapper.xml + mapper-locations: classpath*:mapper/**/*Mapper.xml global-config: db-config: id-type: auto diff --git a/src/main/resources/log4j.properties b/src/main/resources/log4j.properties new file mode 100644 index 0000000..f15f1e7 --- /dev/null +++ b/src/main/resources/log4j.properties @@ -0,0 +1,5 @@ +log4j.rootLogger=DEBUG, stdout +# Console output... +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n \ No newline at end of file diff --git a/src/main/resources/mapper/sys/RoleMapper.xml b/src/main/resources/mapper/sys/RoleMapper.xml index 4baf616..3f69227 100644 --- a/src/main/resources/mapper/sys/RoleMapper.xml +++ b/src/main/resources/mapper/sys/RoleMapper.xml @@ -1,5 +1,10 @@ - + + delete from sys_role_permission where rid = #{pid} + + + delete from sys_user_role where rid = #{pid} + diff --git a/src/main/resources/templates/system/role/roleManager.html b/src/main/resources/templates/system/role/roleManager.html index 08374a1..72acb92 100644 --- a/src/main/resources/templates/system/role/roleManager.html +++ b/src/main/resources/templates/system/role/roleManager.html @@ -53,11 +53,18 @@

-
+
+ +
+ + +
+
+
-
@@ -79,6 +86,9 @@ +
@@ -154,8 +164,11 @@ {field: 'id', title: 'ID', align: 'center'}, {field: 'name', title: '角色名称', align: 'center'}, {field: 'remark', title: '角色备注', align: 'center'}, + {field: 'available', title: '是否可用', align: 'center',templet:function (d) { + return d.available==1?'可用':'不可用'; + }}, {field: 'createtime', title: '创建时间', align: 'center'}, - {fixed: 'right', title: '操作', toolbar: '#roleRowBar', align: 'center'} + {fixed: 'right', title: '操作', toolbar: '#roleRowBar', align: 'center',width:280} ] ], done:function (data, curr, count) { //不是第一页时,如果当前返回的数据为0那么就返回上一页 @@ -178,10 +191,17 @@ } }); + //点击重置按钮时,重置表单的值 + $("#resetRole").click(function () { + $("#searchFrm")[0].reset(); + }); + //监控模糊查询按钮事件 form.on("submit(doSearch)", function (data) { + var params = $("#searchFrm").serialize(); tableIns.reload({ - where: data.field, +// where: data.field, + url:"/role/loadAllRole?"+params, page: { curr: 1 } @@ -209,6 +229,9 @@ case 'delete': deleteRole(data); break; + case 'selectPermission': + selectPermission(data); + break; }; }); @@ -256,7 +279,7 @@ layer.close(mainIndex); }); return false; - }) + }); //删除 function deleteRole(data) {