From b6ba543fb79d8f3c2e57f5383329e467da30d9cc Mon Sep 17 00:00:00 2001 From: sxu <602087911@qq.com> Date: Wed, 19 Mar 2025 09:28:53 +0800 Subject: [PATCH] role, RedisConfig --- .../common/redis/configure/RedisConfig.java | 28 ++++++------- .../service/impl/SysRoleServiceImpl.java | 42 +++++++++---------- .../resources/mapper/system/SysRoleMapper.xml | 2 +- 3 files changed, 36 insertions(+), 36 deletions(-) diff --git a/bonus-common/bonus-common-redis/src/main/java/com/bonus/common/redis/configure/RedisConfig.java b/bonus-common/bonus-common-redis/src/main/java/com/bonus/common/redis/configure/RedisConfig.java index fc0f014..729b02f 100644 --- a/bonus-common/bonus-common-redis/src/main/java/com/bonus/common/redis/configure/RedisConfig.java +++ b/bonus-common/bonus-common-redis/src/main/java/com/bonus/common/redis/configure/RedisConfig.java @@ -42,8 +42,8 @@ public class RedisConfig extends CachingConfigurerSupport RedisTemplate template = new RedisTemplate<>(); template.setConnectionFactory(connectionFactory); -// FastJson2JsonRedisSerializer serializer = new FastJson2JsonRedisSerializer(Object.class); - RedisSerializer serializer = new GenericJackson2JsonRedisSerializer(OBJECT_MAPPER); + FastJson2JsonRedisSerializer serializer = new FastJson2JsonRedisSerializer(Object.class); +// RedisSerializer serializer = new GenericJackson2JsonRedisSerializer(OBJECT_MAPPER); // 使用StringRedisSerializer来序列化和反序列化redis的key值 template.setKeySerializer(new StringRedisSerializer()); @@ -57,16 +57,16 @@ public class RedisConfig extends CachingConfigurerSupport return template; } - static { - OBJECT_MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - OBJECT_MAPPER.registerModule(new JavaTimeModule()); - OBJECT_MAPPER.registerModule((new SimpleModule()).addSerializer(new StdSerializer(NullValue.class) { - public void serialize(NullValue value, JsonGenerator gen, SerializerProvider provider) throws IOException { - gen.writeStartObject(); - gen.writeStringField("@class", NullValue.class.getName()); - gen.writeEndObject(); - } - })); - OBJECT_MAPPER.activateDefaultTyping(OBJECT_MAPPER.getPolymorphicTypeValidator(), ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY); - } +// static { +// OBJECT_MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); +// OBJECT_MAPPER.registerModule(new JavaTimeModule()); +// OBJECT_MAPPER.registerModule((new SimpleModule()).addSerializer(new StdSerializer(NullValue.class) { +// public void serialize(NullValue value, JsonGenerator gen, SerializerProvider provider) throws IOException { +// gen.writeStartObject(); +// gen.writeStringField("@class", NullValue.class.getName()); +// gen.writeEndObject(); +// } +// })); +// OBJECT_MAPPER.activateDefaultTyping(OBJECT_MAPPER.getPolymorphicTypeValidator(), ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY); +// } } diff --git a/bonus-modules/bonus-system/src/main/java/com/bonus/system/service/impl/SysRoleServiceImpl.java b/bonus-modules/bonus-system/src/main/java/com/bonus/system/service/impl/SysRoleServiceImpl.java index 7b3990b..1396db7 100644 --- a/bonus-modules/bonus-system/src/main/java/com/bonus/system/service/impl/SysRoleServiceImpl.java +++ b/bonus-modules/bonus-system/src/main/java/com/bonus/system/service/impl/SysRoleServiceImpl.java @@ -81,14 +81,7 @@ public class SysRoleServiceImpl implements ISysRoleService role.setRoleKey(str); } role.setCompanyId(SecurityUtils.getLoginUser().getSysUser().getCompanyId()); - List roles = roleMapper.selectRoleList(role); - for (SysRole r : roles) { - List areaIds = roleMapper.getAreaIdsByRoleId(r.getRoleId()); - List dataIds = roleMapper.getDataIdsByRoleId(r.getRoleId()); - r.setAreaIds(areaIds.toArray(new String[areaIds.size()])); - r.setDataIds(dataIds.toArray(new String[dataIds.size()])); - } - return roles; + return roleMapper.selectRoleList(role); } /** @@ -169,7 +162,12 @@ public class SysRoleServiceImpl implements ISysRoleService @Override public SysRole selectRoleById(Long roleId) { - return roleMapper.selectRoleById(roleId); + SysRole role = roleMapper.selectRoleById(roleId); + List areaIds = roleMapper.getAreaIdsByRoleId(role.getRoleId()); + List dataIds = roleMapper.getDataIdsByRoleId(role.getRoleId()); + role.setAreaIds(areaIds.toArray(new String[areaIds.size()])); + role.setDataIds(dataIds.toArray(new String[dataIds.size()])); + return role; } /** @@ -408,12 +406,13 @@ public class SysRoleServiceImpl implements ISysRoleService int rows = 1; // 新增角色与区域(数据权限)管理 List list = new ArrayList(); - for (String areaId : role.getAreaIds()) - { - SysRoleArea rd = new SysRoleArea(); - rd.setRoleId(role.getRoleId()); - rd.setAreaId(areaId); - list.add(rd); + if (role.getAreaIds() != null && role.getAreaIds().length > 0) { + for (String areaId : role.getAreaIds()) { + SysRoleArea rd = new SysRoleArea(); + rd.setRoleId(role.getRoleId()); + rd.setAreaId(areaId); + list.add(rd); + } } if (list.size() > 0) { @@ -432,12 +431,13 @@ public class SysRoleServiceImpl implements ISysRoleService int rows = 1; // 新增角色与食堂档口(数据权限)管理 List list = new ArrayList(); - for (String dataId : role.getDataIds()) - { - SysRoleCanteen rd = new SysRoleCanteen(); - rd.setRoleId(role.getRoleId()); - rd.setDataId(dataId); - list.add(rd); + if (role.getDataIds() != null && role.getDataIds().length > 0) { + for (String dataId : role.getDataIds()) { + SysRoleCanteen rd = new SysRoleCanteen(); + rd.setRoleId(role.getRoleId()); + rd.setDataId(dataId); + list.add(rd); + } } if (list.size() > 0) { diff --git a/bonus-modules/bonus-system/src/main/resources/mapper/system/SysRoleMapper.xml b/bonus-modules/bonus-system/src/main/resources/mapper/system/SysRoleMapper.xml index 427eb6a..5c5bd80 100644 --- a/bonus-modules/bonus-system/src/main/resources/mapper/system/SysRoleMapper.xml +++ b/bonus-modules/bonus-system/src/main/resources/mapper/system/SysRoleMapper.xml @@ -60,7 +60,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - order by r.role_sort + order by r.role_sort, r.role_id