use of org.springframework.cache.annotation.CacheEvict in project cu-kfs by CU-CommunityApps.
the class PermissionServiceImpl method updatePermission.
@CacheEvict(value = { Permission.CACHE_NAME, PermissionTemplate.CACHE_NAME }, allEntries = true)
@Override
public Permission updatePermission(Permission permission) throws IllegalArgumentException, IllegalStateException {
incomingParamCheck(permission, "permission");
Permission oldPermission = getPermissionImpl(permission.getId());
if (StringUtils.isBlank(permission.getId()) || oldPermission == null) {
throw new IllegalStateException("the permission does not exist: " + permission);
}
List<PermissionAttribute> oldAttrBos = oldPermission.getAttributeDetails();
// put old attributes in map for easier updating
Map<String, PermissionAttribute> oldAttrMap = new HashMap<>();
for (PermissionAttribute oldAttr : oldAttrBos) {
oldAttrMap.put(oldAttr.getKimAttribute().getAttributeName(), oldAttr);
}
List<PermissionAttribute> newAttrBos = new ArrayList<>();
for (String key : permission.getAttributes().keySet()) {
if (oldAttrMap.containsKey(key)) {
PermissionAttribute updatedAttr = oldAttrMap.get(key);
updatedAttr.setAttributeValue(permission.getAttributes().get(key));
newAttrBos.add(updatedAttr);
} else {
newAttrBos.addAll(KimAttributeData.createFrom(PermissionAttribute.class, Collections.singletonMap(key, permission.getAttributes().get(key)), permission.getTemplate().getKimTypeId()));
}
}
if (CollectionUtils.isNotEmpty(newAttrBos)) {
if (null != permission.getAttributeDetails()) {
permission.getAttributeDetails().clear();
}
permission.setAttributeDetails(newAttrBos);
}
if (permission.getTemplate() == null && permission.getTemplateId() != null) {
permission.setTemplate(getPermissionTemplate(permission.getTemplateId()));
}
return businessObjectService.save(permission);
}
use of org.springframework.cache.annotation.CacheEvict in project fw-cloud-framework by liuweijw.
the class MenuServiceImpl method deleteMenu.
@Override
@Transactional
@CacheEvict(allEntries = true)
public Boolean deleteMenu(Integer menuId, String roleCode) {
// 删除当前节点 -- 假删除
QMenu qMenu = QMenu.menu;
this.queryFactory.update(qMenu).set(qMenu.statu, CommonConstant.STATUS_DEL).where(qMenu.menuId.eq(menuId)).execute();
// 删除父节点为当前节点的节点 -- 假删除
this.queryFactory.update(qMenu).set(qMenu.statu, CommonConstant.STATUS_DEL).where(qMenu.pid.eq(menuId)).execute();
return true;
}
use of org.springframework.cache.annotation.CacheEvict in project fw-cloud-framework by liuweijw.
the class PermissionServiceImpl method updateRoleMenuPermissions.
@Override
@CacheEvict(value = { AdminCacheKey.PERMISSION_INFO, AdminCacheKey.MENU_INFO, AdminCacheKey.MODULE_INFO, AdminCacheKey.ROLE_INFO }, allEntries = true)
@Transactional
public boolean updateRoleMenuPermissions(String roleCode, String... permissions) {
Role role = roleService.findRoleByCode(roleCode.trim());
if (null == role)
return false;
// 菜单集合
Map<Integer, List<String>> roleMenuIdList = new HashMap<Integer, List<String>>();
for (String permission : permissions) {
if (!permission.contains("|"))
continue;
String[] menuPermissions = permission.split("\\|");
Integer menuId = WebUtils.parseStrToInteger(menuPermissions[0], null);
if (null == menuId || StringHelper.isBlank(menuPermissions[1]))
continue;
if (!roleMenuIdList.containsKey(menuId)) {
roleMenuIdList.put(menuId, new ArrayList<String>());
}
roleMenuIdList.get(menuId).add(menuPermissions[1].trim());
}
// 删除RoleMenu和RoleMenuPermission
this.delRoleMenuPermission(role.getRoleId());
if (roleMenuIdList.size() > 0) {
roleMenuIdList.forEach((menuId, menuPermissions) -> {
RoleMenu menuRole = new RoleMenu();
menuRole.setMenuId(menuId);
menuRole.setRoleId(role.getRoleId());
menuRole = roleMenuRepository.saveAndFlush(menuRole);
Integer menuRoleId = menuRole.getId();
menuPermissions.forEach(p -> {
String permission = p.trim();
if (permission.contains("_")) {
RoleMenuPermission roleMenuPermission = new RoleMenuPermission();
roleMenuPermission.setRoleMenuId(menuRoleId);
roleMenuPermission.setPermission(permission);
roleMenuPermissionRepository.saveAndFlush(roleMenuPermission);
}
});
});
}
return true;
}
use of org.springframework.cache.annotation.CacheEvict in project topjava10 by JavaWebinar.
the class UserServiceImpl method update.
@CacheEvict(value = "users", allEntries = true)
@Transactional
@Override
public void update(UserTo userTo) {
User user = updateFromTo(get(userTo.getId()), userTo);
repository.save(prepareToSave(user));
}
use of org.springframework.cache.annotation.CacheEvict in project tesla by linking12.
the class RoleServiceImpl method update.
@CacheEvict(value = CACHE_NAME, key = ROLE_ALL_KEY)
@Override
public int update(RoleDO role) {
int r = roleMapper.update(role);
List<Long> menuIds = role.getMenuIds();
Long roleId = role.getRoleId();
roleMenuMapper.removeByRoleId(roleId);
List<RoleMenuDO> rms = new ArrayList<>();
for (Long menuId : menuIds) {
RoleMenuDO rmDo = new RoleMenuDO();
rmDo.setRoleId(roleId);
rmDo.setMenuId(menuId);
rms.add(rmDo);
}
if (rms.size() > 0) {
roleMenuMapper.batchSave(rms);
}
return r;
}
Aggregations