/**
 * Copyright 2019 DH
 * All right reserved.
 * 项目名称: 大恒泰山系统
 * 创建日期:2022/8/24
 */
package org.springblade.modules.business.warning.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.equipment.inspection.report.entity.EquipmentInspectionReportEntity;
import org.springblade.modules.business.warning.dto.RtuWarningInfoDTO;
import org.springblade.modules.business.warning.entity.RtuWarningInfoEntity;
import org.springblade.modules.business.warning.mapper.RtuWarningMapper;
import org.springblade.modules.business.warning.service.IRtuWarningService;
import org.springblade.modules.business.warning.vo.RtuWarningInfoVO;
import org.springframework.stereotype.Service;

import java.util.List;

/***
 * Date:2022/8/24
 * Title:文件所属模块（必须填写）
 * Description：对本文件的详细描述，原则上不能少于30字
 * @author dylan
 * @version 1.0
 * Remark：认为有必要的其他信息
 */
@Service
public class RtuWarningServiceImpl extends BaseServiceImpl<RtuWarningMapper, RtuWarningInfoEntity> implements IRtuWarningService {
	@Override
	public RtuWarningInfoEntity getWarningInfoByRtuCode(String rtuCode) {
		LambdaQueryWrapper<RtuWarningInfoEntity> wrapper = Wrappers.<RtuWarningInfoEntity>query().lambda();
		wrapper.eq(RtuWarningInfoEntity::getWarningStatus, 0);
		wrapper.eq(RtuWarningInfoEntity::getRtuCode, rtuCode);
		wrapper.orderByDesc(RtuWarningInfoEntity::getUpdateTime);
		wrapper.last("limit 1");
		List<RtuWarningInfoEntity> pages = this.list(wrapper);
		if (null != pages && pages.size() == 1) {
			return pages.get(0);
		}
		return null;
	}

	@Override
	public IPage<RtuWarningInfoVO> selectPage(IPage<RtuWarningInfoVO> page, RtuWarningInfoDTO rtuWarningInfoDTO) {
		return baseMapper.selectPage(page, rtuWarningInfoDTO);
	}

	@Override
	public Long warningRtuCount(RtuWarningInfoDTO rtuWarningInfoDTO) {
		return baseMapper.warningRtuCount(rtuWarningInfoDTO);
	}
}
