package com.mvc.service.aihcxd;

import com.mvc.dao.TDataPredictMapper;
import com.mvc.entity.TDataPredict;
import com.mvc.entity.TDataPredictExample;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

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

/**
 * 数据预测记录表
 */
@Service
@Transactional
public class TDataPredictService {
    @Resource
    private TDataPredictMapper tDataPredictMapper;

    /**
     * 保存记录
     *
     * @param dataPredict
     * @return
     */
    public TDataPredict saveTDataPredict(TDataPredict dataPredict) {
        //防止AireadId调用两次(即有小图又有大图的情况,会触发两次) 2024-06-14 guozhao
        if (dataPredict.getAireadId() != null) {
            if (tDataPredictMapper.selectByPrimaryKey(dataPredict.getAireadId()) != null) {
                return null;
            }
        }

        dataPredict.setCreateTime(new Date());
        return tDataPredictMapper.insert(dataPredict) > 0 ? dataPredict : null;
    }

    /**
     * 根据aireadId获取记录
     *
     * @param aireadId
     * @return
     */
    public TDataPredict getTDataPredictByAireadId(Integer aireadId) {
        if (aireadId == null) {
            return null;
        }
        TDataPredictExample example = new TDataPredictExample();
        TDataPredictExample.Criteria criteria = example.createCriteria();
        criteria.andAireadIdEqualTo(aireadId);
        List<TDataPredict> list = tDataPredictMapper.selectByExample(example);
        return list == null || list.size() == 0 ? null : list.get(0);
    }
}
