package com.yd.dal.service.meta.impl;

import com.yd.api.practitioner.vo.organization.InsurerBranchDeptInfo;
import com.yd.api.practitioner.vo.organization.InsurerBranchInfo;
import com.yd.api.practitioner.vo.organization.PractitionerSubordinateSystemInfo;
import com.yd.dal.entity.meta.MdDropOptions;
import com.yd.dal.entity.meta.OptionsEGolden;
import com.yd.dal.mapper.meta.MdDropOptionsMapper;
import com.yd.dal.service.meta.MdDropOptionsDALService;
import com.yd.util.intercept.annotation.TargetDataSource;
import com.yd.util.intercept.commons.DataSourceKey;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("mdDropOptionsDALService")
public class MdDropOptionsDALServiceImpl implements MdDropOptionsDALService {

    @Resource
    private MdDropOptionsMapper mdDropOptionsMapper;

    @Override
    public List<MdDropOptions> findByDropMasterId(long dropMasterId) {
        MdDropOptions info = new MdDropOptions();
        info.setDropMasterId(dropMasterId);
        return mdDropOptionsMapper.selectByObj(info);
    }

    @Override
    public MdDropOptions findByDropOptionId(Long dropOptionId) {
        return mdDropOptionsMapper.selectByPrimaryKey(dropOptionId);
    }

    @Override
    public List<MdDropOptions> findByDropMasterCode(String dropMasterCode) {
        return mdDropOptionsMapper.findByDropMasterCode(dropMasterCode);
    }
    @Override
    public MdDropOptions findById(Long trackStatusId) {
        return mdDropOptionsMapper.selectByPrimaryKey(trackStatusId);
    }

    @Override
    public List<MdDropOptions> findByMasterCode(String masterCode) {
        return mdDropOptionsMapper.findByMasterCode(masterCode);
    }

    @Override
    public List<MdDropOptions> findByMasterCodeAndOrderId(String masterCode, int orderId) {
        return mdDropOptionsMapper.findByMasterCodeAndOrderId(masterCode,orderId);
    }

    @Override
    public MdDropOptions selectByMasterCodeAndOptionsCode(String masterCode, String optionsCode) {
        return mdDropOptionsMapper.selectByMasterCodeAndOptionsCode(masterCode, optionsCode);
    }
    @Override
    public List<MdDropOptions> findByMasterCodeAndOptionsCode(String masterCode, String optionsCode) {
        return mdDropOptionsMapper.findByMasterCodeAndOptionsCode(masterCode,optionsCode);
    }

    @Override
    @TargetDataSource(dataSourceKey = DataSourceKey.DB_EGOLDEN)
    public List<OptionsEGolden> findByMasterIdsE(List<Integer> materIds) {
        return mdDropOptionsMapper.findByMasterIdsE(materIds);
    }

    @Override
    @TargetDataSource(dataSourceKey = DataSourceKey.DB_EGOLDEN)
    public List<OptionsEGolden> findAllTitleEG() {
        return mdDropOptionsMapper.findAllTitleEG();
    }

    @Override
    @TargetDataSource(dataSourceKey = DataSourceKey.DB_EGOLDEN)
    public List<PractitionerSubordinateSystemInfo> findSubordinateSystemInfoByIdEG(List<String> subordinateSystemIds) {
        return mdDropOptionsMapper.findSubordinateSystemInfoByIdEG(subordinateSystemIds);
    }

    @Override
    @TargetDataSource(dataSourceKey = DataSourceKey.DB_EGOLDEN)
    public List<PractitionerSubordinateSystemInfo> findSubordinateSystemInfoEG() {
        return mdDropOptionsMapper.findSubordinateSystemInfoEG();
    }

    @Override
    @TargetDataSource(dataSourceKey = DataSourceKey.DB_EGOLDEN)
    public List<InsurerBranchDeptInfo> findBranchDeptInfoByIdEG(List<String> branchDeptIds) {
        return mdDropOptionsMapper.findBranchDeptInfoByIdEG(branchDeptIds);
    }

    @Override
    @TargetDataSource(dataSourceKey = DataSourceKey.DB_EGOLDEN)
    public List<InsurerBranchDeptInfo> findBranchDeptInfoEG() {
        return mdDropOptionsMapper.findBranchDeptInfoEG();
    }

    @Override
    @TargetDataSource(dataSourceKey = DataSourceKey.DB_EGOLDEN)
    public List<InsurerBranchInfo> findInsurerBranchInfoByIdEG(List<String> insurerBranchIds) {
        return mdDropOptionsMapper.findInsurerBranchInfoByIdEG(insurerBranchIds);
    }

    @Override
    @TargetDataSource(dataSourceKey = DataSourceKey.DB_EGOLDEN)
    public List<InsurerBranchInfo> findInsurerBranchInfoEG() {
        return mdDropOptionsMapper.findInsurerBranchInfoEG();
    }

    @Override
    public List<MdDropOptions> findByDropMasterCodes(List<String> masterCodeList) {
        return mdDropOptionsMapper.findByDropMasterCodes(masterCodeList);
    }

    @Override
    public Map<Long, MdDropOptions> queryIdObjMapByByDropMasterCode(String masterCode) {
        Map<Long,MdDropOptions> optMap = new HashMap<>();
        List<MdDropOptions> dropOptionsList = this.findByDropMasterCode(masterCode);
        dropOptionsList.forEach(i->optMap.put(i.getId(), i));
        return optMap;
    }

    @Override
    public List<Long> queryIdByByDropMasterCodes(List<String> masterCodeList) {
        List<Long> idList = new ArrayList<>();
        List<MdDropOptions> options = mdDropOptionsMapper.findByDropMasterCodes(masterCodeList);
        options.forEach(i->idList.add(i.getId()));
        return idList;
    }

    @Override
    public List<Long> queryIdByByDropMasterCode(String masterCode) {
        List<Long> idList = new ArrayList<>();
        List<MdDropOptions> options = mdDropOptionsMapper.findByMasterCode(masterCode);
        options.forEach(i->idList.add(i.getId()));
        return idList;
    }
}
