package com.huatek.busi.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.huatek.busi.common.SiteConstants;
import com.huatek.busi.dto.RMasterDataRecordDto;
import com.huatek.busi.entity.RMasterData;
import com.huatek.busi.entity.RMasterDataRecord;
import com.huatek.busi.mapper.RMasterDataRecordMapper;
import com.huatek.busi.service.IRMasterDataRecordService;
import com.huatek.torch.sql.dao.impl.BaseDao;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

@Component
@Service(interfaceClass = IRMasterDataRecordService.class)
@Transactional(rollbackFor = Exception.class)
public class RMasterDataRecordServiceImpl extends BaseDao<RMasterDataRecord, String> implements IRMasterDataRecordService {

    @Resource
    private RMasterDataRecordMapper rMasterDataRecordMapper;

    @Override
    public RMasterDataRecordDto getRMasterDataRecord(RMasterData rMasterData) {
        if(Objects.equals(rMasterData.getEquipmentType(), SiteConstants.ExternalTypeEnum.BYQ.getValue()) || Objects.equals(rMasterData.getEquipmentType(), SiteConstants.ExternalTypeEnum.GIS.getValue())) {
            return rMasterDataRecordMapper.getRMasterDataRecord(rMasterData);
        } else if (Objects.equals(rMasterData.getEquipmentType(), SiteConstants.ExternalTypeEnum.BLQ.getValue())) {
            return rMasterDataRecordMapper.getRBLQDataRecord(rMasterData);
        } else if (Objects.equals(rMasterData.getEquipmentType(), SiteConstants.ExternalTypeEnum.CW.getValue())) {
            return rMasterDataRecordMapper.getRKGGDataRecord(rMasterData);
        } else if (Objects.equals(rMasterData.getEquipmentType(), SiteConstants.ExternalTypeEnum.GEN.getValue())) {
            return rMasterDataRecordMapper.getRGENDataRecord(rMasterData);
        } else if (Objects.equals(rMasterData.getEquipmentType(), SiteConstants.ExternalTypeEnum.DL.getValue())) {
            return rMasterDataRecordMapper.getRCableDataRecord(rMasterData);
        }
        return null;
    }

    @Override
    public int insert(RMasterDataRecord rMasterDataRecord){
        return this.addLocal(rMasterDataRecord);
    }

    @Override
    public int delete(String eqType, String refId){
        if(Objects.equals(eqType, SiteConstants.ExternalTypeEnum.BYQ.getValue()) || Objects.equals(eqType, SiteConstants.ExternalTypeEnum.GIS.getValue())) {
            return rMasterDataRecordMapper.delete(refId);
        } else if (Objects.equals(eqType, SiteConstants.ExternalTypeEnum.BLQ.getValue())) {
            return rMasterDataRecordMapper.deleteBlq(refId);
        } else if (Objects.equals(eqType, SiteConstants.ExternalTypeEnum.CW.getValue())) {
            return rMasterDataRecordMapper.deleteKgg(refId);
        } else if (Objects.equals(eqType, SiteConstants.ExternalTypeEnum.GEN.getValue())) {
            return rMasterDataRecordMapper.deleteGen(refId);
        } else if (Objects.equals(eqType, SiteConstants.ExternalTypeEnum.DL.getValue())) {
            return rMasterDataRecordMapper.deleteDl(refId);
        }
        return 0;
    }

    @Override
    public int deleteBatch(List<String> refIds , String eqType){
        if(Objects.equals(eqType, SiteConstants.ExternalTypeEnum.BYQ.getValue()) || Objects.equals(eqType, SiteConstants.ExternalTypeEnum.GIS.getValue())) {
            return rMasterDataRecordMapper.deleteBatch(refIds);
        } else if (Objects.equals(eqType, SiteConstants.ExternalTypeEnum.BLQ.getValue())) {
            return rMasterDataRecordMapper.deleteBlqBatch(refIds);
        } else if (Objects.equals(eqType, SiteConstants.ExternalTypeEnum.CW.getValue())) {
            return rMasterDataRecordMapper.deleteKggBatch(refIds);
        } else if (Objects.equals(eqType, SiteConstants.ExternalTypeEnum.GEN.getValue())) {
            return rMasterDataRecordMapper.deleteGenBatch(refIds);
        } else if (Objects.equals(eqType, SiteConstants.ExternalTypeEnum.DL.getValue())) {
            return rMasterDataRecordMapper.deleteDlBatch(refIds);
        }
        return 0;
    }
}
