/**
 * 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.EtlRsvrDataDTO;
import org.springblade.etl.entity.EtlRsvrDataEntity;
import org.springblade.etl.service.IEtlRsvrDataService;
import org.springblade.modules.business.data.entity.RtuDataRsvrEntity;
import org.springblade.modules.business.data.service.IRtuDataRsvrService;


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

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

	public static RtuDataRsvrEntity dataSync(EtlRsvrDataDTO etlRsvrDataDTO, IEtlRsvrDataService etlRsvrDataService, IRtuDataRsvrService rtuDataRsvrService) {
		List<EtlRsvrDataEntity> rsvrDataEntityList = etlRsvrDataService.selectLastList(etlRsvrDataDTO);
		if (null != rsvrDataEntityList && rsvrDataEntityList.size() > 0) {
			EtlRsvrDataEntity entity = rsvrDataEntityList.get(0);
			LambdaQueryWrapper<RtuDataRsvrEntity> dataWrapper = Wrappers.<RtuDataRsvrEntity>query().lambda();
			dataWrapper.eq(RtuDataRsvrEntity::getRtuCode, entity.getRtuCode());
			dataWrapper.eq(RtuDataRsvrEntity::getIsDeleted, 0);
			RtuDataRsvrEntity rsvrDataEntity = rtuDataRsvrService.getOne(dataWrapper);
			if (null == rsvrDataEntity) {
				rsvrDataEntity = new RtuDataRsvrEntity();
				rsvrDataEntity.setRtuCode(entity.getRtuCode());
				rsvrDataEntity.setCreateTime(new Date());
				rsvrDataEntity.setUpdateTime(new Date());
				rsvrDataEntity.setStatus(1);
				rsvrDataEntity.setIsDeleted(0);
			}
			rsvrDataEntity.setRz(entity.getRz());
			rsvrDataEntity.setTm(entity.getTm());
			rtuDataRsvrService.saveOrUpdate(rsvrDataEntity);
			return rsvrDataEntity;
		}
		return null;
	}
}
