role, RedisConfig

This commit is contained in:
sxu 2025-03-19 09:28:53 +08:00
parent 0c1fe9ce7a
commit b6ba543fb7
3 changed files with 36 additions and 36 deletions

View File

@ -42,8 +42,8 @@ public class RedisConfig extends CachingConfigurerSupport
RedisTemplate<Object, Object> template = new RedisTemplate<>(); RedisTemplate<Object, Object> template = new RedisTemplate<>();
template.setConnectionFactory(connectionFactory); template.setConnectionFactory(connectionFactory);
// FastJson2JsonRedisSerializer serializer = new FastJson2JsonRedisSerializer(Object.class); FastJson2JsonRedisSerializer serializer = new FastJson2JsonRedisSerializer(Object.class);
RedisSerializer<Object> serializer = new GenericJackson2JsonRedisSerializer(OBJECT_MAPPER); // RedisSerializer<Object> serializer = new GenericJackson2JsonRedisSerializer(OBJECT_MAPPER);
// 使用StringRedisSerializer来序列化和反序列化redis的key值 // 使用StringRedisSerializer来序列化和反序列化redis的key值
template.setKeySerializer(new StringRedisSerializer()); template.setKeySerializer(new StringRedisSerializer());
@ -57,16 +57,16 @@ public class RedisConfig extends CachingConfigurerSupport
return template; return template;
} }
static { // static {
OBJECT_MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); // OBJECT_MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
OBJECT_MAPPER.registerModule(new JavaTimeModule()); // OBJECT_MAPPER.registerModule(new JavaTimeModule());
OBJECT_MAPPER.registerModule((new SimpleModule()).addSerializer(new StdSerializer<NullValue>(NullValue.class) { // OBJECT_MAPPER.registerModule((new SimpleModule()).addSerializer(new StdSerializer<NullValue>(NullValue.class) {
public void serialize(NullValue value, JsonGenerator gen, SerializerProvider provider) throws IOException { // public void serialize(NullValue value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeStartObject(); // gen.writeStartObject();
gen.writeStringField("@class", NullValue.class.getName()); // gen.writeStringField("@class", NullValue.class.getName());
gen.writeEndObject(); // gen.writeEndObject();
} // }
})); // }));
OBJECT_MAPPER.activateDefaultTyping(OBJECT_MAPPER.getPolymorphicTypeValidator(), ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY); // OBJECT_MAPPER.activateDefaultTyping(OBJECT_MAPPER.getPolymorphicTypeValidator(), ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY);
} // }
} }

View File

@ -81,14 +81,7 @@ public class SysRoleServiceImpl implements ISysRoleService
role.setRoleKey(str); role.setRoleKey(str);
} }
role.setCompanyId(SecurityUtils.getLoginUser().getSysUser().getCompanyId()); role.setCompanyId(SecurityUtils.getLoginUser().getSysUser().getCompanyId());
List<SysRole> roles = roleMapper.selectRoleList(role); return roleMapper.selectRoleList(role);
for (SysRole r : roles) {
List<String> areaIds = roleMapper.getAreaIdsByRoleId(r.getRoleId());
List<String> dataIds = roleMapper.getDataIdsByRoleId(r.getRoleId());
r.setAreaIds(areaIds.toArray(new String[areaIds.size()]));
r.setDataIds(dataIds.toArray(new String[dataIds.size()]));
}
return roles;
} }
/** /**
@ -169,7 +162,12 @@ public class SysRoleServiceImpl implements ISysRoleService
@Override @Override
public SysRole selectRoleById(Long roleId) public SysRole selectRoleById(Long roleId)
{ {
return roleMapper.selectRoleById(roleId); SysRole role = roleMapper.selectRoleById(roleId);
List<String> areaIds = roleMapper.getAreaIdsByRoleId(role.getRoleId());
List<String> dataIds = roleMapper.getDataIdsByRoleId(role.getRoleId());
role.setAreaIds(areaIds.toArray(new String[areaIds.size()]));
role.setDataIds(dataIds.toArray(new String[dataIds.size()]));
return role;
} }
/** /**
@ -408,13 +406,14 @@ public class SysRoleServiceImpl implements ISysRoleService
int rows = 1; int rows = 1;
// 新增角色与区域数据权限管理 // 新增角色与区域数据权限管理
List<SysRoleArea> list = new ArrayList<SysRoleArea>(); List<SysRoleArea> list = new ArrayList<SysRoleArea>();
for (String areaId : role.getAreaIds()) if (role.getAreaIds() != null && role.getAreaIds().length > 0) {
{ for (String areaId : role.getAreaIds()) {
SysRoleArea rd = new SysRoleArea(); SysRoleArea rd = new SysRoleArea();
rd.setRoleId(role.getRoleId()); rd.setRoleId(role.getRoleId());
rd.setAreaId(areaId); rd.setAreaId(areaId);
list.add(rd); list.add(rd);
} }
}
if (list.size() > 0) if (list.size() > 0)
{ {
rows = roleAreaMapper.batchRoleArea(list); rows = roleAreaMapper.batchRoleArea(list);
@ -432,13 +431,14 @@ public class SysRoleServiceImpl implements ISysRoleService
int rows = 1; int rows = 1;
// 新增角色与食堂档口数据权限管理 // 新增角色与食堂档口数据权限管理
List<SysRoleCanteen> list = new ArrayList<SysRoleCanteen>(); List<SysRoleCanteen> list = new ArrayList<SysRoleCanteen>();
for (String dataId : role.getDataIds()) if (role.getDataIds() != null && role.getDataIds().length > 0) {
{ for (String dataId : role.getDataIds()) {
SysRoleCanteen rd = new SysRoleCanteen(); SysRoleCanteen rd = new SysRoleCanteen();
rd.setRoleId(role.getRoleId()); rd.setRoleId(role.getRoleId());
rd.setDataId(dataId); rd.setDataId(dataId);
list.add(rd); list.add(rd);
} }
}
if (list.size() > 0) if (list.size() > 0)
{ {
rows = roleAreaMapper.batchRoleCanteen(list); rows = roleAreaMapper.batchRoleCanteen(list);

View File

@ -60,7 +60,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</if> </if>
<!-- 数据范围过滤 --> <!-- 数据范围过滤 -->
<include refid="com.bonus.system.mapper.DataScopeMapper.dataScopeFilter"/> <include refid="com.bonus.system.mapper.DataScopeMapper.dataScopeFilter"/>
order by r.role_sort order by r.role_sort, r.role_id
</select> </select>
<select id="selectRolePermissionByUserId" parameterType="Long" resultMap="SysRoleResult"> <select id="selectRolePermissionByUserId" parameterType="Long" resultMap="SysRoleResult">