/**
 * Copyright 2019 DH
 * All right reserved.
 * 项目名称:
 * 创建日期:2023/8/22
 */
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.RtuDataWaterLevelDTO;
import org.springblade.modules.business.data.entity.RtuDataWaterLevelEntity;
import org.springblade.modules.business.data.mapper.RtuDataWaterLevelMapper;
import org.springblade.modules.business.data.service.IRtuDataWaterLevelService;
import org.springblade.modules.business.data.vo.RtuDataWaterLevelVO;
import org.springblade.modules.etl.entity.EtlRiverDataEntity;
import org.springblade.modules.etl.entity.EtlRsvrDataEntity;
import org.springframework.stereotype.Service;


/***
 * Date:2023/8/22
 * Title:文件所属模块（必须填写）
 * Description：对本文件的详细描述，原则上不能少于30字
 * @author dylan
 * @version 1.0
 * Remark：认为有必要的其他信息
 */
@Service
public class RtuDataWaterLevelServiceImpl extends BaseServiceImpl<RtuDataWaterLevelMapper, RtuDataWaterLevelEntity> implements IRtuDataWaterLevelService {
	@Override
	public IPage<RtuDataWaterLevelVO> selectPage(IPage<RtuDataWaterLevelVO> page, RtuDataWaterLevelDTO dto) {
		return page.setRecords(baseMapper.selectPage(page, dto));
	}

	@Override
	public boolean updateRiverInfo(EtlRiverDataEntity etlRiverDataEntity) {
		LambdaQueryWrapper<RtuDataWaterLevelEntity> dataWrapper = Wrappers.<RtuDataWaterLevelEntity>query().lambda();
		dataWrapper.eq(RtuDataWaterLevelEntity::getRtuCode, etlRiverDataEntity.getRtuCode());
		RtuDataWaterLevelEntity entity = this.getOne(dataWrapper);
		if (null == entity) {
			entity = new RtuDataWaterLevelEntity();
			entity.setRtuCode(etlRiverDataEntity.getRtuCode());
			entity.setStatus(1);
			entity.setIsDeleted(0);
			entity.setIsRiver(1);
			entity.setIsRes(0);
		}
		entity.setWaterLevel(etlRiverDataEntity.getZ());
		entity.setTm(etlRiverDataEntity.getTm());
		entity.setFromTime(etlRiverDataEntity.getFromDate());
		return this.saveOrUpdate(entity);
	}

	@Override
	public boolean updateRsvrInfo(EtlRsvrDataEntity etlRsvrDataEntity) {
		LambdaQueryWrapper<RtuDataWaterLevelEntity> dataWrapper = Wrappers.<RtuDataWaterLevelEntity>query().lambda();
		dataWrapper.eq(RtuDataWaterLevelEntity::getRtuCode, etlRsvrDataEntity.getRtuCode());
		RtuDataWaterLevelEntity entity = this.getOne(dataWrapper);
		if (null == entity) {
			entity = new RtuDataWaterLevelEntity();
			entity.setRtuCode(etlRsvrDataEntity.getRtuCode());
			entity.setStatus(1);
			entity.setIsDeleted(0);
			entity.setIsRiver(0);
			entity.setIsRes(1);
		}
		entity.setWaterLevel(etlRsvrDataEntity.getRz());
		entity.setTm(etlRsvrDataEntity.getTm());
		entity.setFromTime(etlRsvrDataEntity.getFromDate());
		return this.saveOrUpdate(entity);
	}
}
