RoleData.java 4.01 KB
Newer Older
1
/*
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
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;


23
*/
24 25 26 27
/**
 * @Auther: Gary J Li
 * @Date: 11/01/2019 14:53
 * @Description:将Role存入ehcache,提高查询效率
28 29
 *//*

30 31 32 33 34 35 36 37
@Service
public class RoleData {

    private static final Logger logger = LoggerFactory.getLogger(RoleData.class);

    @Resource
    private RoleMapper roleMapper;

38 39
    */
/**
40 41 42 43 44
     * 11/01/2019 16:15
     * 根据serviceTypeId查询,存入ehcache
     * [serviceTypeId]
     * @author Gary J Li
     * @return List<Role> roleList
45 46
     *//*

47 48 49 50 51
    @Cacheable(value = "roleByServiceTypeIdCache", key = "#serviceTypeId")
    public List<Role> selectByServiceTypeId(String serviceTypeId){
        List<Role> roleList = new ArrayList<>();
        try{
            RoleExample roleExample = new RoleExample();
gary's avatar
gary committed
52
            if(!StringUtils.equals("All",serviceTypeId)){
53 54 55 56 57 58 59 60 61
                roleExample.createCriteria().andServiceTypeIdEqualTo(serviceTypeId);
            }
            roleList = roleMapper.selectByExample(roleExample);
        }catch (Exception e){
            logger.error(String.format("Error selectByServiceTypeId: %s",e.getMessage()));
        }
        return roleList;
    }

62 63
    */
/**
64 65 66 67 68
     * 11/01/2019 16:16
     * 根据id查询,存入ehcache
     * [id]
     * @author Gary J Li
     * @return Role role
69 70
     *//*

71 72 73 74 75 76 77 78 79 80 81
    @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;
    }

82 83
    */
/**
84 85 86 87 88
     * 11/01/2019 16:17
     * 根据主键id删除,并把ehcache里的role都删掉
     * [roleDto]
     * @author Gary J Li
     * @return int res
89 90
     *//*

91 92 93 94 95 96 97 98 99 100 101
    @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;
    }

102 103
    */
/**
104 105 106 107 108
     * 11/01/2019 16:20
     * role写入,并在缓存里写入两个Hash(ServiceTypeId,Id)里
     * [role]
     * @author Gary J Li
     * @return Role role
109 110
     *//*

111 112 113 114 115 116 117 118 119 120
    @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;
    }

121 122
    */
/**
123 124 125 126 127
     * 11/01/2019 16:22
     * role更新,并在缓存里更新两个Hash(ServiceTypeId,Id)里
     * [role]
     * @author Gary J Li
     * @return Role role
128 129
     *//*

130 131 132 133 134 135 136 137 138 139
    @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;
    }
}
140
*/