/**
 * Copyright
 * All right reserved.
 * 项目名称:
 * 创建日期:2022/5/22
 */
package org.springblade.etl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springblade.etl.dto.EtlRiverDataDTO;
import org.springblade.etl.entity.EtlRiverDataEntity;
import org.springblade.etl.service.IEtlRiverDataService;
import org.springblade.modules.business.data.entity.RtuDataRiverEntity;
import org.springblade.modules.business.data.service.IRtuDataRiverService;

import java.util.Date;
import java.util.List;

/***
 * Date:2022/5/22
 * Title: 河道水位抽取
 * Description：
 * @author swp
 * @version 1.0
 * Remark：认为有必要的其他信息
 */
public class EtlRiverDataTask {

	public static RtuDataRiverEntity dataSync(EtlRiverDataDTO etlRiverDataDTO, IEtlRiverDataService etlRiverDataService, IRtuDataRiverService rtuDataRiverService) {
		List<EtlRiverDataEntity> riverDataEntityList = etlRiverDataService.selectLastList(etlRiverDataDTO);
		if (null != riverDataEntityList && riverDataEntityList.size() > 0) {
			EtlRiverDataEntity entity = riverDataEntityList.get(0);
			LambdaQueryWrapper<RtuDataRiverEntity> dataWrapper = Wrappers.<RtuDataRiverEntity>query().lambda();
			dataWrapper.eq(RtuDataRiverEntity::getRtuCode, entity.getRtuCode());
			dataWrapper.eq(RtuDataRiverEntity::getIsDeleted, 0);
			RtuDataRiverEntity riverEntity = rtuDataRiverService.getOne(dataWrapper);
			if (null == riverEntity) {
				riverEntity = new RtuDataRiverEntity();
				riverEntity.setRtuCode(entity.getRtuCode());
				riverEntity.setCreateTime(new Date());
				riverEntity.setStatus(1);
				riverEntity.setIsDeleted(0);
			}
			riverEntity.setUpdateTime(new Date());
			riverEntity.setZ(entity.getZ());
			riverEntity.setTm(entity.getTm());
			rtuDataRiverService.saveOrUpdate(riverEntity);
			return riverEntity;
		}
		return null;
	}
}
