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.ProjectNatureMapper;
import cn.com.countrygarden.bi.main.model.common.CommConstant;
import cn.com.countrygarden.bi.main.model.common.ProjectNature;
import cn.com.countrygarden.bi.main.service.common.ProjectNatureService;
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 ProjectNatureServiceImpl extends AbstractService<ProjectNature> implements ProjectNatureService {
    @Resource
    private ProjectNatureMapper mapper;

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