package com.mvc.service.temp;

import com.mvc.dao.TempAireadMapper;
import com.mvc.entity.TAiread;
import com.mvc.entity.TempAiread;
import com.mvc.entity.TempAireadExample;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

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

/**
 * 临时读数表Service
 */
@Service
@Transactional
public class TempAireadService {
    @Resource
    private TempAireadMapper tempAireadMapper;

    /**
     * 根据TAiread保存临时表记录
     *
     * @param airead
     * @return
     */
    public TempAiread saveTempAiread(TAiread airead) {
        TempAiread tempAiread = new TempAiread();
        BeanUtils.copyProperties(airead, tempAiread);
        if (tempAireadMapper.insert(tempAiread) > 0) {
            return tempAiread;
        } else {
            return null;
        }
    }

    /**
     * 根据aireadId获取记录
     * @param aireadId
     * @return
     */
    public TempAiread getTempAireadByAireadId(String aireadId) {
        if(StringUtils.isEmpty(aireadId)){
            return null;
        }
        TempAireadExample example = new TempAireadExample();
        TempAireadExample.Criteria criteria = example.createCriteria();
        criteria.andAireadIdEqualTo(aireadId);
        List<TempAiread> list = tempAireadMapper.selectByExample(example);
        return list == null || list.size() == 0 ? null : list.get(0);
    }
}
