package com.huatek.busi.service.impl;

import java.math.BigDecimal;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import com.huatek.busi.common.UploadCycle.ConfigField;
import com.huatek.busi.common.util.DecimalUtil;
import com.huatek.busi.mapper.SiteUploadCycleMapper;
import com.huatek.busi.service.SiteUploadCycleService;
import com.huatek.busi.vo.SiteUploadCycleVo;

import lombok.extern.slf4j.Slf4j;

/**
 * 测温柜-CAC传过来的测温点数据
 * 
 * @author buck_guo
 * @date 2019/07/15
 */
@Slf4j
@Service
@Transactional
public class SiteUploadCycleServiceImpl implements SiteUploadCycleService {

    @Autowired
    private SiteUploadCycleMapper siteUploadCycleMapper;

    @Override
    public SiteUploadCycleVo findBySiteId(String siteId) {
        return siteUploadCycleMapper.selectSiteUploadCycleInfo(siteId);
    }

    @Override
    public BigDecimal getCycle(String siteId, ConfigField configField) {
        String cycle = siteUploadCycleMapper.getCycle(siteId, configField.name());
        if (StringUtils.isEmpty(cycle)) {
            log.warn("siteId:{}, fieldName: {} 未配置", siteId, configField.name());
        }
        return DecimalUtil.getVal(cycle);
    }
}
