/**
 * Copyright 2019 DH
 * All right reserved.
 * 项目名称: 运维系统
 * 创建日期:2022/8/28
 */
package org.springblade.modules.business.data.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.modules.business.data.dto.RtuDataRainDTO;
import org.springblade.modules.business.data.entity.RtuDataRainEntity;
import org.springblade.modules.business.data.mapper.RtuDataRainMapper;
import org.springblade.modules.business.data.service.IRtuDataRainService;
import org.springblade.modules.business.data.vo.RtuDataRainVO;
import org.springblade.modules.etl.entity.EtlRainDataEntity;
import org.springframework.stereotype.Service;

import java.util.Date;

/***
 * Date:2022/8/28
 * Title:文件所属模块（必须填写）
 * Description：对本文件的详细描述，原则上不能少于30字
 * @author dylan
 * @version 1.0
 * Remark：认为有必要的其他信息
 */
@Service
public class RtuDataRainServiceImpl extends BaseServiceImpl<RtuDataRainMapper, RtuDataRainEntity> implements IRtuDataRainService {

	@Override
	public IPage<RtuDataRainVO> selectPage(IPage<RtuDataRainVO> page, RtuDataRainDTO rtuDataRainDTO) {
		return page.setRecords(baseMapper.selectPage(page, rtuDataRainDTO));
	}

	@Override
	public boolean updateRainInfo(EtlRainDataEntity etlRainDataEntity) {
		LambdaQueryWrapper<RtuDataRainEntity> dataWrapper = Wrappers.<RtuDataRainEntity>query().lambda();
		dataWrapper.eq(RtuDataRainEntity::getRtuCode, etlRainDataEntity.getRtuCode());
		dataWrapper.eq(RtuDataRainEntity::getIsDeleted, 0);
		RtuDataRainEntity rainEntity = this.getOne(dataWrapper);
		if (null == rainEntity) {
			rainEntity = new RtuDataRainEntity();
			rainEntity.setRtuCode(etlRainDataEntity.getRtuCode());
			rainEntity.setCreateTime(new Date());
			rainEntity.setStatus(1);
			rainEntity.setIsDeleted(0);
		}
		rainEntity.setUpdateTime(new Date());
		rainEntity.setDrp(etlRainDataEntity.getDrp());
		rainEntity.setIntv(etlRainDataEntity.getIntv());
		rainEntity.setTm(etlRainDataEntity.getTm());
		rainEntity.setFromTime(etlRainDataEntity.getFromDate());
		return this.saveOrUpdate(rainEntity);
	}

}
