/**
 * 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.etl.entity.EtlGroundDataEntity;
import org.springblade.modules.business.data.dto.RtuDataGroundDTO;
import org.springblade.modules.business.data.entity.RtuDataGroundEntity;
import org.springblade.modules.business.data.mapper.RtuDataGroundMapper;
import org.springblade.modules.business.data.service.IRtuDataGroundService;
import org.springblade.modules.business.data.vo.RtuDataGroundVO;
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 RtuDataGroundServiceImpl extends BaseServiceImpl<RtuDataGroundMapper, RtuDataGroundEntity> implements IRtuDataGroundService {
	@Override
	public IPage<RtuDataGroundVO> selectPage(IPage<RtuDataGroundVO> page, RtuDataGroundDTO rtuDataGroundDTO) {
		return page.setRecords(baseMapper.selectPage(page, rtuDataGroundDTO));
	}

	@Override
	public boolean updateGroundInfo(EtlGroundDataEntity etlGroundDataEntity) {
		LambdaQueryWrapper<RtuDataGroundEntity> dataWrapper = Wrappers.<RtuDataGroundEntity>query().lambda();
		dataWrapper.eq(RtuDataGroundEntity::getRtuCode, etlGroundDataEntity.getRtuCode());
		dataWrapper.eq(RtuDataGroundEntity::getIsDeleted, 0);
		RtuDataGroundEntity groundDataEntity = this.getOne(dataWrapper);
		if (null == groundDataEntity) {
			groundDataEntity = new RtuDataGroundEntity();
			groundDataEntity.setRtuCode(etlGroundDataEntity.getRtuCode());
			groundDataEntity.setCreateTime(new Date());
			groundDataEntity.setStatus(1);
			groundDataEntity.setIsDeleted(0);
		}
		groundDataEntity.setSlm10(etlGroundDataEntity.getMoco10cm());
		groundDataEntity.setSlm20(etlGroundDataEntity.getMoco20cm());
		groundDataEntity.setSlm30(etlGroundDataEntity.getMoco30cm());
		groundDataEntity.setSlm40(etlGroundDataEntity.getMoco40cm());
		groundDataEntity.setSlm50(etlGroundDataEntity.getMoco50cm());
		groundDataEntity.setSlm60(etlGroundDataEntity.getMoco60cm());
		groundDataEntity.setSlm80(etlGroundDataEntity.getMoco80cm());
		groundDataEntity.setSlm100(etlGroundDataEntity.getMoco100cm());
		groundDataEntity.setSrlslm(etlGroundDataEntity.getSurfMoco());
		groundDataEntity.setVtavslm(etlGroundDataEntity.getVertAverMoco());
		groundDataEntity.setTm(etlGroundDataEntity.getTm());
		groundDataEntity.setFromTime(etlGroundDataEntity.getFromDate());
		return this.saveOrUpdate(groundDataEntity);
	}
}
