AppOrgCache.java 2.22 KB
package com.zteits.pay.cache;

import com.clouds.common.cache.base.AbstractCache;
import com.clouds.common.cache.base.HashCacheVO;
import com.clouds.common.constants.RedisKeyEnum;
import com.github.pagehelper.PageHelper;
import com.google.common.collect.Lists;
import com.zteits.clouds.api.apibase.constants.DataStatusEnum;
import com.zteits.clouds.api.dto.park.dto.ParkingLotDTO;
import com.zteits.clouds.api.dto.pay.AppOrgDTO;
import com.zteits.pay.domain.AppOrg;
import com.zteits.pay.domain.AppOrgExample;
import com.zteits.pay.mapper.AppOrgMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * appOrg信息缓存 <br>
 * 是要hash类型,hkey为orgId,value为appOrg对象
 *
 * Copyright: Copyright (c) 2017  zteits
 *
 * @ClassName: ParkingLotAndGeoInfoCache.java
 * @Description:
 * @version: v1.0.0
 * @author: zhaowg
 * @date: 2017年6月6日   上午9:58:38
 * Modification History:
 * Date             Author          Version            Description
 *---------------------------------------------------------*
 * 2017年6月6日      zhaowg              v1.0.0               创建
 */
@Component
public class AppOrgCache extends AbstractCache<HashCacheVO>{
	@Autowired
	private AppOrgMapper appOrgMapper;

	@Override
	protected List<HashCacheVO> getData(int pageNum, int pageSize) {
		PageHelper.startPage(pageNum, pageSize);
		AppOrgExample example = new AppOrgExample();
		example.createCriteria().andDataStateEqualTo(DataStatusEnum.DATA_STATUS_VALID.value());
		List<AppOrg> appOrgs = appOrgMapper.selectByExample(example );
		List<HashCacheVO> cacheVOs = Lists.newArrayList();

		for (AppOrg item : appOrgs) {
			AppOrgDTO dto = new AppOrgDTO();
			BeanUtils.copyProperties(item, dto);
			HashCacheVO vo = new HashCacheVO(item.getOrgId(), dto);
			cacheVOs.add(vo);
		}
		return cacheVOs;
	}

	@Override
	protected long getTotalSize() {
		AppOrgExample example = new AppOrgExample();
		example.createCriteria().andDataStateEqualTo(DataStatusEnum.DATA_STATUS_VALID.value());
		return appOrgMapper.countByExample(example );
	}

	@Override
	protected String getKey() {
		return RedisKeyEnum.APP_ORG.key();
	}

}