package cn.com.countrygarden.bi.main.service.common.impl;

import cn.com.countrygarden.bi.main.core.AbstractService;
import cn.com.countrygarden.bi.main.dao.common.ProjectTypeMapper;
import cn.com.countrygarden.bi.main.model.common.CommConstant;
import cn.com.countrygarden.bi.main.model.common.ProjectNature;
import cn.com.countrygarden.bi.main.model.common.ProjectType;
import cn.com.countrygarden.bi.main.service.common.ProjectTypeService;
import cn.com.countrygarden.bi.main.util.RedisCacheUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service
@Transactional
public class ProjectTypeServiceImpl extends AbstractService<ProjectType> implements ProjectTypeService {
    @Resource
    private ProjectTypeMapper mapper;

    @Override
    public Map<String,Object> projectTypeCache(){
        return RedisCacheUtils.rememberMap(CommConstant.ProjectTypeCache.key,
                CommConstant.ProjectTypeCache.time,new HashMap<String,String>(),
                p->{
                    HashMap<String,Object> result = new HashMap<String,Object>();
                    ProjectType query = new ProjectType();
                    query.setIsDelete((byte)0);
                    List<ProjectType> dataList = mapper.select(query);
                    for(ProjectType data :dataList){
                        result.put(data.getName(),data.getCode());
                    }
                    return  result;
                }
        );
    }
}
