package cn.iocoder.yudao.module.system.dal.mysql.devuce;


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.system.controller.admin.devuce.vo.DevuceListVO;
import cn.iocoder.yudao.module.system.controller.app.devuce.vo.DevucePageReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.devuce.DevuceDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 设备 Mapper
 *
 * @author 开发账号
 */
@Mapper
public interface DevuceMapper extends BaseMapperX<DevuceDO> {

    default PageResult<DevuceDO> selectPage(DevucePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<DevuceDO>()
                .eqIfPresent(DevuceDO::getDeviceSn, reqVO.getDeviceSn())
                .eqIfPresent(DevuceDO::getDishesId, reqVO.getDishesId())
                .betweenIfPresent(DevuceDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(DevuceDO::getBind, reqVO.getBind())
                .orderByDesc(DevuceDO::getId));
    }

    @Select(" select de.*,di.dishes_name from t_devuce  de\n" +
            " left join t_device_info dn on de.device_sn = dn.device_ip\n" +
            " left join t_dishes di on de.dishes_id = di.id\n" +
            " where bind = true and de.deleted = false and dn.carteen_id = #{storeId}")
    List<DevuceListVO> getList(Long storeId);
}