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

import com.google.common.base.Strings;
import com.yd.api.practitioner.vo.payscale.PayScaleInfo;
import com.yd.dal.entity.practitioner.opportunity.PlayerSalesActivityInfo;
import com.yd.dal.entity.practitioner.opportunity.OwnOpportunityInfo;
import com.yd.dal.entity.customer.AclPractitioner;
import com.yd.dal.entity.customer.practitioner.PractitionerBasicInfo;
import com.yd.dal.entity.customer.practitioner.PractitionerInfo;
import com.yd.dal.entity.customer.practitioner.PractitionerRankInfo;
import com.yd.dal.entity.practitioner.payscale.PayScaleBasicInfo;
import com.yd.dal.mapper.customer.AclPractitionerMapper;
import com.yd.dal.service.customer.AclPractitionerDALService;
import com.yd.util.deshandler.DESTypeHandler;
import com.yd.util.intercept.annotation.TargetDataSource;
import com.yd.util.intercept.commons.DataSourceKey;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
@Service("aclPractitionerDALService")
public class AclPractitionerDALServiceImpl implements AclPractitionerDALService {
    private static final Logger LOG = Logger.getLogger(AclPractitionerDALServiceImpl.class);
    @Resource
    private AclPractitionerMapper aclPractitionerMapper;
    @Override
    public AclPractitioner findByCustomerIdIsActive(Long customerId, int isActive) {
        return aclPractitionerMapper.findByCustomerIdIsActive(customerId,isActive);
    }

    @Override
    @TargetDataSource(dataSourceKey = DataSourceKey.DB_EGOLDEN)
    public PractitionerBasicInfo getPractitionerBasicInfoForOffline(String mobileNo) {
        if(!Strings.isNullOrEmpty(mobileNo)){
            return aclPractitionerMapper.getPractitionerInfoByMobileNoForOffline(mobileNo);
        }else{
            LOG.error("mobileNo is null！");
        }
        return null;
    }

    @Override
    public PractitionerBasicInfo getPractitionerBasicInfoForOnline(String mobileNo) {
        if(!Strings.isNullOrEmpty(mobileNo)){
            return aclPractitionerMapper.getPractitionerInfoByMobileNoForOnline(mobileNo);
        }else{
            LOG.error("mobileNo is null！");
        }
        return null;
    }

    @Override
    @TargetDataSource(dataSourceKey = DataSourceKey.DB_EGOLDEN)
    public List<PractitionerRankInfo> getPractitionerRankInfoForOffline(Integer time) {
        return aclPractitionerMapper.getPractitionerRankInfoForOffline(time);
    }

    @Override
    public List<PractitionerRankInfo> getPractitionerRankInfoForOnline(Integer time,Long practitionerTypeId) {
        return aclPractitionerMapper.getPractitionerRankInfoForOnline(time,practitionerTypeId);
    }

    @Override
    public List<PractitionerRankInfo> getPractitionerRankInfoForSpecials(List<String> mobileSpecials,Integer time) {
        return aclPractitionerMapper.getPractitionerRankInfoForSpecials(mobileSpecials,time);
    }

    @Override
    public PractitionerInfo findPractitionerInfoByLogin(String mobileNo) {
        return aclPractitionerMapper.findPractitionerInfoByLogin(mobileNo);
    }

    @Override
    @TargetDataSource(dataSourceKey = DataSourceKey.DB_MASTER)
    public AclPractitioner findPractitionerById(Long practitionerId) {
        return aclPractitionerMapper.selectByPrimaryKey(practitionerId);
    }

    @Override
    @TargetDataSource(dataSourceKey = DataSourceKey.DB_MASTER)
    public void updatePractitioner(AclPractitioner practitioner) {
        aclPractitionerMapper.updateByPrimaryKeySelective(practitioner);
    }

    @Override
    public List<OwnOpportunityInfo> ownOpportunityQuery(Long practitionerId) {
        return aclPractitionerMapper.ownOpportunityQuery(practitionerId);
    }
    @Override
    public List<AclPractitioner> findByIds(List<Long> practitionerIdList) {
        return aclPractitionerMapper.findByIds(practitionerIdList);
    }

    @Override
    public List<AclPractitioner> findForSubordinateIdByPractitionerId(Long practitionerId) {
        return aclPractitionerMapper.findForSubordinateIdByPractitionerId(practitionerId) ;
    }

    @Override
    public List<PlayerSalesActivityInfo> playerSalesActivityQuery(Long practitionerId, Long optionsId) {
        return aclPractitionerMapper.playerSalesActivityQuery(practitionerId, optionsId);
    }
    @Override
    public List<AclPractitioner> findBySubordinateSystemId(Long subordinateSystemId) {
        return aclPractitionerMapper.findBySubordinateSystemId(subordinateSystemId);
    }

    @Override
    public String findMobileNoByPractitionerId(Long practitionerId) {
        String mobileNo =  aclPractitionerMapper.findMobileNoByPractitionerId(practitionerId);
        if(!Strings.isNullOrEmpty(mobileNo)){
            DESTypeHandler jpaCryptoConverter = new DESTypeHandler();
            mobileNo = jpaCryptoConverter.decode(mobileNo);
        }
        return mobileNo;
    }

    @Override
    @TargetDataSource(dataSourceKey = DataSourceKey.DB_EGOLDEN)
    public PractitionerBasicInfo findByMobileNoE(String mobileNo) {
        return aclPractitionerMapper.findByMobileNoE(mobileNo);
    }

    @Override
    public AclPractitioner findById(Long practitionerId) {
        return aclPractitionerMapper.selectByPrimaryKey(practitionerId);
    }

    @Override
    @TargetDataSource(dataSourceKey = DataSourceKey.DB_EGOLDEN)
    public PractitionerRankInfo getPractitionerRankInfoByPractitionerIdEG(String practitionerIdEG, Integer time) {
        return aclPractitionerMapper.getPractitionerRankInfoByPractitionerIdEG(practitionerIdEG,time);
    }

    @Override
    public PractitionerRankInfo getPractitionerRankInfoByPractitionerIdYD(Long practitionerId, Integer time) {
        return aclPractitionerMapper.getPractitionerRankInfoByPractitionerIdYD(practitionerId,time);
    }

    @Override
    @TargetDataSource(dataSourceKey = DataSourceKey.DB_EGOLDEN)
    public List<PayScaleInfo> findPayScaleByPractitionerEG(String practitionerIdEG) {
        return aclPractitionerMapper.findPayScaleByPractitionerEG(practitionerIdEG);
    }

    @Override
    @TargetDataSource(dataSourceKey = DataSourceKey.DB_EGOLDEN)
    public PayScaleBasicInfo findFilePathByMonShId(Integer monShId) {
        return aclPractitionerMapper.findFilePathByMonShId(monShId);
    }

    @Override
    @TargetDataSource(dataSourceKey = DataSourceKey.DB_EGOLDEN)
    public PractitionerBasicInfo findByIdEG(String practitionerIdEG) {
        return aclPractitionerMapper.findByIdEG(practitionerIdEG);
    }

    @Override
    public AclPractitioner findPractitionerByLeadsAssignedId(Long leadsAssignedId) {
        return aclPractitionerMapper.findPractitionerByLeadsAssignedId(leadsAssignedId);
    }

    @Override
    public List<AclPractitioner> findAll() {
        return aclPractitionerMapper.findAll();
    }

    @Override
    public int isTeamLeader(Long practitionerId) {
        return aclPractitionerMapper.isTeamLeader(practitionerId);
    }

    @Override
    public List<Long> queryTeamAllPractitionerId(Long practitionerId) {
        return aclPractitionerMapper.queryTeamAllPractitionerId(practitionerId);
    }

    @Override
    public List<Long> queryMentoredByPractitionerId(Long practitionerId) {
        return aclPractitionerMapper.queryMentoredByPractitionerId(practitionerId);
    }
}
