package cn.iocoder.yudao.module.member.dal.mysql.devicewarn;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.member.controller.admin.screen.vo.DeviceInfo;
import cn.iocoder.yudao.module.member.dal.dataobject.devicewarn.DeviceWarnDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.member.controller.admin.devicewarn.vo.*;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 设备告警次数 Mapper
 *
 * @author 开发账号
 */
@Mapper
public interface DeviceWarnMapper extends BaseMapperX<DeviceWarnDO> {

    default PageResult<DeviceWarnDO> selectPage(DeviceWarnPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<DeviceWarnDO>()
                .eqIfPresent(DeviceWarnDO::getDeviceSn, reqVO.getDeviceSn())
                .eqIfPresent(DeviceWarnDO::getStoreId, reqVO.getStoreId())
                .eqIfPresent(DeviceWarnDO::getWarnNum, reqVO.getWarnNum())
                .betweenIfPresent(DeviceWarnDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(DeviceWarnDO::getId));
    }



    @Select("select di.device_name, ds.dishes_name, ds.dishes_sum_price, dn.total_weight, dn.diff, dn.rem_weight, dn.first_weight\n" +
            "from t_device_info di\n" +
            "         left join (select d.device_sn, d.rem_weight, d.diff, d.total_weight, d.dishes_id, d.first_weight\n" +
            "                    from t_devuce d\n" +
            "                    where d.bind = true\n" +
            "                      and d.deleted = false) dn\n" +
            "                   on dn.device_sn = di.device_ip\n" +
            "         left join t_dishes ds on ds.id = dn.dishes_id\n" +
            "where di.carteen_id = #{carteenId} and di.alive = '1' \n" +
            "  and di.deleted = false")
    List<DeviceInfo> getDeviceInfo(@Param("carteenId") Long carteenId);
}