<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bonus.canteen.core.order.common.mapper.OrderPreBookMapper">

    <select id="listByParam" resultType="com.bonus.canteen.core.order.common.vo.OrderPreBookVO">
        SELECT
        opb.pre_book_id,
        opb.pre_book_type,
        opb.order_type,
        opb.order_date,
        opb.submit_time,
        opb.cust_id,
        opb.ext_param,
        opb.crby,
        opb.crtime,
        opb.upby,
        opb.uptime,
        ci.cust_name,
        ci.cust_num,
        ci.mobile,
        ci.cust_type,
        ci.org_full_name,
        ci.cust_photo_url,
        ci.psn_type,
        ci.psn_type_name
        FROM order_pre_book opb
        LEFT JOIN cust_info ci ON opb.cust_id = ci.cust_id
        WHERE 1 = 1
        <if test="param.orderDate != null">
            AND opb.order_date = #{param.orderDate}
        </if>
        <if test="param.custSearchInfo != null and param.custSearchInfo != ''">
            AND (
                ci.cust_num = #{param.custSearchInfo}
                OR ci.cust_name = #{param.custSearchInfo,typeHandler=net.xnzn.core.common.encrypt.SM4EncDecHandler}
                OR ci.mobile = #{param.custSearchInfo,typeHandler=net.xnzn.core.common.encrypt.SM4EncDecHandler}
                OR ci.mobile_suffix = #{param.custSearchInfo,typeHandler=net.xnzn.core.common.encrypt.SM4EncDecHandler}
            )
        </if>
        <if test="param.orgIdList != null and param.orgIdList.size() > 0">
            AND ci.org_id in
            <foreach collection="param.orgIdList" item="orgId" open="(" close=")" separator=",">
                #{orgId}
            </foreach>
        </if>
    </select>
</mapper>
