/* package pwc.taxtech.atms.data; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.CachePut; import org.springframework.cache.annotation.Cacheable; import org.springframework.cache.annotation.Caching; import org.springframework.stereotype.Service; import pwc.taxtech.atms.dao.RoleMapper; import pwc.taxtech.atms.dto.role.RoleDto; import pwc.taxtech.atms.entity.Role; import java.util.ArrayList; import java.util.List; import pwc.taxtech.atms.entity.RoleExample; import javax.annotation.Resource; */ /** * @Auther: Gary J Li * @Date: 11/01/2019 14:53 * @Description:将Role存入ehcache,提高查询效率 *//* @Service public class RoleData { private static final Logger logger = LoggerFactory.getLogger(RoleData.class); @Resource private RoleMapper roleMapper; */ /** * 11/01/2019 16:15 * 根据serviceTypeId查询,存入ehcache * [serviceTypeId] * @author Gary J Li * @return List<Role> roleList *//* @Cacheable(value = "roleByServiceTypeIdCache", key = "#serviceTypeId") public List<Role> selectByServiceTypeId(String serviceTypeId){ List<Role> roleList = new ArrayList<>(); try{ RoleExample roleExample = new RoleExample(); if(!StringUtils.equals("All",serviceTypeId)){ roleExample.createCriteria().andServiceTypeIdEqualTo(serviceTypeId); } roleList = roleMapper.selectByExample(roleExample); }catch (Exception e){ logger.error(String.format("Error selectByServiceTypeId: %s",e.getMessage())); } return roleList; } */ /** * 11/01/2019 16:16 * 根据id查询,存入ehcache * [id] * @author Gary J Li * @return Role role *//* @Cacheable(value = "roleByIdCache", key = "#id") public Role selectByPrimaryKey(String id){ Role role = new Role(); try{ role = roleMapper.selectByPrimaryKey(id); }catch (Exception e){ logger.error(String.format("Error role selectByPrimaryKey: %s",e.getMessage())); } return role; } */ /** * 11/01/2019 16:17 * 根据主键id删除,并把ehcache里的role都删掉 * [roleDto] * @author Gary J Li * @return int res *//* @Caching(evict= {@CacheEvict(value = "roleByServiceTypeIdCache", key = "#role.getServiceTypeId()"),@CacheEvict(value = "roleByIdCache", key = "#role.getId()")} ) public int deleteByPrimaryKey(RoleDto roleDto){ int res = 0; try{ res = roleMapper.deleteByPrimaryKey(roleDto.getId()); }catch (Exception e){ logger.error(String.format("Error role delete: %s",e.getMessage())); } return res; } */ /** * 11/01/2019 16:20 * role写入,并在缓存里写入两个Hash(ServiceTypeId,Id)里 * [role] * @author Gary J Li * @return Role role *//* @Caching(put= {@CachePut(value = "roleByServiceTypeIdCache", key = "#role.getServiceTypeId()"),@CachePut(value = "roleByIdCache", key = "#role.getId()")} ) public Role insert(Role role){ try{ roleMapper.insert(role); }catch (Exception e){ logger.error(String.format("Error role insert: %s",e.getMessage())); } return role; } */ /** * 11/01/2019 16:22 * role更新,并在缓存里更新两个Hash(ServiceTypeId,Id)里 * [role] * @author Gary J Li * @return Role role *//* @Caching(put= {@CachePut(value = "roleByServiceTypeIdCache", key = "#role.getServiceTypeId()"),@CachePut(value = "roleByIdCache", key = "#role.getId()")} ) public Role updateByPrimaryKey(Role role){ try{ roleMapper.updateByPrimaryKey(role); }catch (Exception e){ logger.error(String.format("Error role updateByPrimaryKey : %s",e.getMessage())); } return role; } } */