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

import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.system.dal.dataobject.home.HomeServiceOrderItemDO;
import cn.iocoder.yudao.module.system.dal.mysql.home.vo.HomeServiceOrderItemDetailVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface HomeServiceOrderItemMapper extends BaseMapperX<HomeServiceOrderItemDO> {

    @Select({
            "<script>",
            "select",
            "oi.id,",
            "oi.home_service_order_id as homeServiceOrderId,",
            "oi.service_item_id as serviceItemId,",
            "oi.tenant_id as tenantId,",
            "i.item_name as itemName",
            "from home_service_order_item oi",
            "left join home_service_item i on i.id = oi.service_item_id",
            "<where>",
            "<choose>",
            "<when test='orderIds != null and orderIds.length &gt; 0'>",
            "oi.home_service_order_id in",
            "<foreach collection='orderIds' item='orderId' open='(' separator=',' close=')'>",
            "#{orderId}",
            "</foreach>",
            "</when>",
            "<otherwise>",
            "1 = 0",
            "</otherwise>",
            "</choose>",
            "</where>",
            "order by oi.home_service_order_id asc, oi.id asc",
            "</script>"
    })
    List<HomeServiceOrderItemDetailVO> selectListByOrderIds(@Param("orderIds") Long[] orderIds);
}
