/**
 * Copyright 2019 DH
 * All right reserved.
 * 项目名称: 大恒泰山系统
 * 创建日期:2022/8/19
 */
package org.springblade.modules.business.rtumanage.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.enums.EquipmentStatusEnum;
import org.springblade.modules.business.project.base.entity.ProjectInfoEntity;
import org.springblade.modules.business.rtu.base.dto.RtuInfoDTO;
import org.springblade.modules.business.rtu.base.entity.RtuInfoEntity;
import org.springblade.modules.business.rtumanage.entity.RtuStatusEntity;
import org.springblade.modules.business.rtumanage.mapper.RtuManageMapper;
import org.springblade.modules.business.rtumanage.service.IRtuManageService;
import org.springblade.modules.business.rtumanage.vo.RtuStatusVO;
import org.springframework.stereotype.Service;

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

	@Override
	public boolean updateLastTime(RtuStatusEntity rtuStatusEntity) {

		LambdaQueryWrapper<RtuStatusEntity> querywrapper = Wrappers.<RtuStatusEntity>query().lambda();
		querywrapper.eq(RtuStatusEntity::getRtuCode,rtuStatusEntity.getRtuCode());
		RtuStatusEntity entity=this.getOne(querywrapper);
		if (null == entity){
//			LambdaUpdateWrapper<RtuStatusEntity> wrapper = Wrappers.<RtuStatusEntity>update().lambda();
//			wrapper.set(RtuStatusEntity::getLastUpTime,rtuStatusEntity.getLastUpTime());
//			wrapper.eq(RtuStatusEntity::getRtuCode,rtuStatusEntity.getRtuCode());
			//rtuStatusEntity.setRunStatusId(EquipmentStatusEnum.STATUS__RUN.getCode());
			return  this.save(rtuStatusEntity);
		}else{
			LambdaUpdateWrapper<RtuStatusEntity> wrapper = Wrappers.<RtuStatusEntity>update().lambda();
			wrapper.set(RtuStatusEntity::getLastUpTime,rtuStatusEntity.getLastUpTime());
			wrapper.eq(RtuStatusEntity::getRtuCode,rtuStatusEntity.getRtuCode());
			return  this.update(wrapper);
		}
	}

	@Override
	public boolean updateRtuStatus(RtuStatusEntity rtuStatusEntity) {
		LambdaQueryWrapper<RtuStatusEntity> querywrapper = Wrappers.<RtuStatusEntity>query().lambda();
		querywrapper.eq(RtuStatusEntity::getRtuCode,rtuStatusEntity.getRtuCode());
		RtuStatusEntity entity=this.getOne(querywrapper);
		if (null == entity){
//			LambdaUpdateWrapper<RtuStatusEntity> wrapper = Wrappers.<RtuStatusEntity>update().lambda();
//			wrapper.set(RtuStatusEntity::getLastUpTime,rtuStatusEntity.getLastUpTime());
//			wrapper.eq(RtuStatusEntity::getRtuCode,rtuStatusEntity.getRtuCode());
			//rtuStatusEntity.setRunStatusId(EquipmentStatusEnum.STATUS__RUN.getCode());
			return  this.save(rtuStatusEntity);
		}else{
			LambdaUpdateWrapper<RtuStatusEntity> wrapper = Wrappers.<RtuStatusEntity>update().lambda();
			wrapper.set(RtuStatusEntity::getRunStatusId,rtuStatusEntity.getRunStatusId());
			wrapper.eq(RtuStatusEntity::getRtuCode,rtuStatusEntity.getRtuCode());
			return  this.update(wrapper);
		}


	}
}
