package org.jeecg.modules.sensor.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.modules.bigScreen.controller.bigScreenController;
import org.jeecg.modules.bigScreen.model.SensorTemperature;
import org.jeecg.modules.bigScreen.model.TableStructure;
import org.jeecg.modules.sensor.entity.BuSensor;
import org.jeecg.modules.sensor.mapper.BuSensorDataMapper;
import org.jeecg.modules.sensor.mapper.BuSensorMapper;
import org.jeecg.modules.sensor.model.DeviceDataRequest;
import org.jeecg.modules.sensor.model.TableNameStatistics;
import org.jeecg.modules.sensor.service.IBuSensorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * @Description: 传感器信息表
 * @Author: jeecg-boot
 * @Date:   2020-12-23
 * @Version: V1.0
 */
@Service
public class BuSensorServiceImpl extends ServiceImpl<BuSensorMapper, BuSensor> implements IBuSensorService {

	@Autowired
	private BuSensorMapper buSensorMapper;
	@Autowired
	private BuSensorDataMapper buSensorDataMapper;

	@Override
	@Transactional
	public void delMain(String id) {
//		buSensorMeasurementsMapper.deleteByMainId(id);
//		buSensorDataMapper.deleteByMainId(id);
		buSensorMapper.deleteById(id);
	}

	@Override
	@Transactional
	public void delBatchMain(Collection<? extends Serializable> idList) {
		for(Serializable id:idList) {
			buSensorDataMapper.deleteByMainId(id.toString());
			buSensorMapper.deleteById(id);
		}
	}

	@Override
	public List<BuSensor> getDataByName(String name){
		return buSensorMapper.getDataByName(name);
	}

	@Override
	public List<String> getBatteryVoltage(String deviceName){
		return buSensorMapper.getBatteryVoltage(deviceName);
	}

	@Override
	public BuSensor getValueById(String deviceId,String item)
	{
		return buSensorMapper.getValueById(deviceId,item);
	}
	@Override
	public List<String> getIpByName(String deviceName){
		return buSensorMapper.getIpByName(deviceName);
	}
	@Override
	public List<String> getHeightIpByName(String deviceName){
		return buSensorMapper.getHeightIpByName(deviceName);
	}
	@Override
	public List<String> getElectricIpByName(String deviceName){
		return buSensorMapper.getElectricIpByName(deviceName);
	}
	// 通过传感器类型获取所有传感器信息
	@Override
	public BuSensor getDataByTypeId(String typeId){
		return buSensorMapper.getDataByTypeId(typeId);
	}

	@Override
	public List<TableNameStatistics> getDataByDeviceId(String deviceId){
		return buSensorMapper.getDataByDeviceId(deviceId);
	}
	@Override
	public List<TableNameStatistics> getItemByDeviceId(String deviceId){
		return buSensorMapper.getItemByDeviceId(deviceId);
	}

	@Override
	public BuSensor getDataByIp(String ip){
		return buSensorMapper.getDataByIp(ip);
	}

	@Override
	public List<String> getNormalStatus(){
		return buSensorMapper.getNormalStatus();
	}

	@Override
	public List<BuSensor> getEarlyStatus(){
		return buSensorMapper.getEarlyStatus();
	}

	@Override
	public List<BuSensor> getAlarmStatus(){
		return buSensorMapper.getAlarmStatus();
	}

	@Override
	public List<BuSensor> getRepairStatus(){
		return buSensorMapper.getRepairStatus();
	}

	@Override
	public List<BuSensor> getPowerData(){
		return buSensorMapper.getPowerData();
	}

	@Override
	public List<BuSensor> getBoardData(){
		return buSensorMapper.getBoardData();
	}

	@Override
	public BuSensor getByCheckItem(String deviceId,String checkItem){
		return buSensorMapper.getByCheckItem(deviceId,checkItem);
	}
	@Override
	public List<BuSensor> getByCheckName(String deviceId,String name){
		return buSensorMapper.getByCheckName(deviceId,name);
	}
	@Override
	public BuSensor getBySensorId(String deviceId,String sensorId){
		return buSensorMapper.getBySensorId(deviceId,sensorId);
	}
	@Override
	public BuSensor getByCode(String deviceId,String code){
		return buSensorMapper.getByCode(deviceId,code);
	}

	@Override
	public List<String> getVibrationSensorIp(){
		return buSensorMapper.getVibrationSensorIp();
	}

	@Override
	public double getTemperature(String tableName){
		return buSensorMapper.getTemperature(tableName);
	}

	@Override
	public List<DeviceDataRequest> getDeviceData(String tableName, String ip, String beginTime, String endTime) {
		return buSensorMapper.getDeviceData(tableName,ip,beginTime,endTime);
	}
	@Override
	public SensorTemperature getTestClassData(String tableName, String dataId){
		return buSensorMapper.getTestClassData(tableName,dataId);
	}

	@Override
	public List<TableStructure> getTableStrutureData(String tableName){
		return buSensorMapper.getTableStrutureData(tableName);
	}

	@Override
	public Map<String, Object> getValueByField(String tableName, String dataId, String field){
		return buSensorMapper.getValueByField(tableName,"'" + dataId + "'",field);
	}

	@Override
	public BuSensor getCodeData(String sensorId){
		return buSensorMapper.getCodeData(sensorId);
	}

}
