package org.jeecg.modules.energy.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.jeecg.modules.energy.entity.BuElectric;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;



/**
 * @Description: bu_electric
 * @Author: jeecg-boot
 * @Date:   2024-05-09
 * @Version: V1.0
 */
public interface BuElectricMapper extends BaseMapper<BuElectric> {

//    public BuElectric getBySensorId(@Param("tableName") String tableName,@Param("sensorId") String sensorId);
    public List<BuElectric> getBySensorId(@Param("tableName") String tableName,@Param("sensorId") String sensorId);
    public List<BuElectric> getElectricData();
    public List<BuElectric> getElectricByStatus();

    @Insert("INSERT INTO bu_electric_history_202405(id,sensor_id,create_time,udy,vdy,wdy,udl, vdl, wdl,eng) VALUES(#{id},#{sensorId},#{createTime},#{udy},#{vdy},#{wdy},#{udl},#{vdl},#{wdl},#{eng})")
    void insertElectric(@Param("id") String id,@Param("sensorId") String sensorId,@Param("createTime") String createTime,
                        @Param("udy") Double udy,@Param("vdy") Double vdy,@Param("wdy") Double wdy,
                        @Param("udl") Double udl,@Param("vdl") Double vdl,@Param("wdl") Double wdl,
                        @Param("eng") Double eng);

    public BuElectric getYesterdayFirstData(@Param("tableName")String tableName,@Param("sensorId")String sensorId,@Param("time")String time);
    public BuElectric getYesterdayLastData(@Param("tableName")String tableName,@Param("sensorId")String sensorId,@Param("time")String time);
    public String getAverage(@Param("tableName")String tableName,@Param("sensorId")String sensorId,@Param("time")String time);

    /**
     * 动态表名分页查询
     */
    public IPage<BuElectric> selectByDynamicTable(
            Page<BuElectric> page,
            @Param("tableName") String tableName,
            @Param("deviceId") String deviceId,
            @Param("sensorId") String sensorId,
            @Param("beginTime") String beginTime,
            @Param("endTime") String endTime
    );
    /**
     * 动态表名分页查询
     */
    public List<BuElectric> selectByDynamicTable(
            @Param("tableName") String tableName,
            @Param("deviceId") String deviceId,
            @Param("sensorId") String sensorId,
            @Param("beginTime") String beginTime,
            @Param("endTime") String endTime
    );
}
