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

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

import java.util.List;

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

    default PageResult<DeviceWarnNumDO> selectPage(DeviceWarnPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<DeviceWarnNumDO>()
                .eqIfPresent(DeviceWarnNumDO::getDeviceSn, reqVO.getDeviceSn())
                .eqIfPresent(DeviceWarnNumDO::getStoreId, reqVO.getStoreId())
                .eqIfPresent(DeviceWarnNumDO::getWarnNum, reqVO.getWarnNum())
                .betweenIfPresent(DeviceWarnNumDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(DeviceWarnNumDO::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);
}