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.CooperationTypeMapper;
import cn.com.countrygarden.bi.main.model.common.CommConstant;
import cn.com.countrygarden.bi.main.model.common.CooperationType;
import cn.com.countrygarden.bi.main.model.common.ProjectNature;
import cn.com.countrygarden.bi.main.service.common.CooperationTypeService;
import cn.com.countrygarden.bi.main.util.RedisCacheUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

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

@Service
@Transactional
public class CooperationTypeServiceImpl extends AbstractService<CooperationType> implements CooperationTypeService {
    @Autowired
    private CooperationTypeMapper mapper;

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