SysOrgAndAppIdCache.java 2.36 KB
package com.zteits.sys.cache;

import org.apache.commons.collections4.CollectionUtils;
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.google.common.collect.Maps;
import com.zteits.clouds.api.apibase.constants.DataStatusEnum;
import com.zteits.clouds.api.dto.park.dto.ParkingLotExtendDTO;
import com.zteits.clouds.api.dto.sys.SysCodeValueDTO;
import com.zteits.clouds.api.dto.sys.SysOrgAppIdCacheDTO;
import com.zteits.sys.domain.SysCodeDef;
import com.zteits.sys.domain.SysCodeValue;
import com.zteits.sys.domain.SysOrgAppId;
import com.zteits.sys.domain.SysOrgAppIdExample;
import com.zteits.sys.mapper.SysOrgAppIdMapper;
import com.zteits.sys.mapper.smapper.SysCodeDefSMapper;
import com.zteits.sys.mapper.smapper.SysCodeValueSMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * 组织和appId对应关系
 */
@Component
public class SysOrgAndAppIdCache extends AbstractCache<HashCacheVO>{
	@Autowired
	private SysOrgAppIdMapper sysOrgAppIdMapper;

	@Override
	protected List<HashCacheVO> getData(int pageNum, int pageSize) {
		PageHelper.startPage(pageNum, pageSize);
		SysOrgAppIdExample example = new SysOrgAppIdExample();
		example.createCriteria().andDataStateEqualTo(DataStatusEnum.DATA_STATUS_VALID.value());
		List<SysOrgAppId> sysOrgAppIds = sysOrgAppIdMapper.selectByExample(example );
		List<HashCacheVO> cacheVOs = Lists.newArrayList();

		for (SysOrgAppId item : sysOrgAppIds) {
			SysOrgAppIdCacheDTO sysOrgAppIdCacheDTO = new SysOrgAppIdCacheDTO();
			BeanUtils.copyProperties(item, sysOrgAppIdCacheDTO);
			String hkey = sysOrgAppIdCacheDTO.getOrgId()+"_"+sysOrgAppIdCacheDTO.getPayType();
			HashCacheVO vo = new HashCacheVO(hkey, sysOrgAppIdCacheDTO);
			cacheVOs.add(vo);
		}
		return cacheVOs;
	}

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

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

}