package cn.com.countrygarden.bi.main.service.twerp.hm.impl;

import cn.com.countrygarden.bi.main.core.AbstractService;
import cn.com.countrygarden.bi.main.dao.twerp.hm.TbSysOrganMapper;
import cn.com.countrygarden.bi.main.model.twerp.hm.TbSysOrgan;
import cn.com.countrygarden.bi.main.service.twerp.hm.TbSysOrganService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

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

@Service
@Transactional
public class TbSysOrganServiceImpl extends AbstractService<TbSysOrgan> implements TbSysOrganService {

    @Autowired
    private TbSysOrganMapper tbSysOrganMapper;

    public TbSysOrgan findByOrganCode(String organCode) {

        return tbSysOrganMapper.findByOrganCode(organCode);
    }

    public TbSysOrgan findByUserCode(String userCode) {

        return tbSysOrganMapper.findByUserCode(userCode);
    }

    public TbSysOrgan findByOrganName(String organName) {
        return tbSysOrganMapper.findByOrganName(organName);
    }

    @Override
    public List<Map<String, Object>> findCaseFieldOrgans(String organCode) {
        List<Map<String, Object>> resultList = new ArrayList<>();
        List<TbSysOrgan> caseFieldOrgans = tbSysOrganMapper.findCaseFieldOrgans(organCode);
        if (caseFieldOrgans != null && caseFieldOrgans.size() > 0) {
            for (TbSysOrgan tbSysOrgan : caseFieldOrgans) {
                Map<String, Object> tempMap = new HashMap<>();
                tempMap.put("organCode", tbSysOrgan.getOrganCode());
                tempMap.put("organName", tbSysOrgan.getOrganName());
                resultList.add(tempMap);
            }
        }
        return resultList;
    }

    //有效的绩效区域
    @Override
    public List<TbSysOrgan> selectPerformanceArea() {
        return tbSysOrganMapper.selectPerformanceArea();
    }

    //所有的绩效区域


    @Override
    public List<TbSysOrgan> selectPerformanceAllArea() {
        return tbSysOrganMapper.selectPerformanceAllArea();
    }

    @Override
    public List<TbSysOrgan> selectPerformanceCompany() {
        return tbSysOrganMapper.selectPerformanceCompany();
    }

    @Override
    public List<TbSysOrgan> selectPerformanceAll() {
        return tbSysOrganMapper.selectPerformanceAll();
    }

    @Override
    public List<TbSysOrgan> selectAll() {
        return tbSysOrganMapper.selectAll();
    }

    @Override
    public List<TbSysOrgan> selectAllAreaByType(String typeNo) {

        List<TbSysOrgan> list = null;

        if("1".equals(typeNo)){
            list = tbSysOrganMapper.selectPerformanceArea();
        }else if("2".equals(typeNo)){
            list = tbSysOrganMapper.selectPerformanceCompany();
        }
        return list;
    }
}
