<?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.weight.mapper.MacWeighBindMapper">

    <select id="selectMacWeightBindList" resultType="com.bonus.canteen.core.order.weight.model.MacWeighBind">
        select * from mac_weigh_bind md
        <where>
            <if test="macWeighBind.serialNum！=null">
                and md.serial_num = #{macWeighBind.serialNum}
            </if>

            <if test="macWeighBind.custId！=null and macWeighBind.custId != -1 and macWeighBind.custId != 0">
                and md.bind_state = #{macWeighBind.bindState}
            </if>
            <if test="macWeighBind.serialNum！=null">
                and md.serial_num = #{macWeighBind.serialNum}
            </if>

            <if test="macWeighBind.plateNum！=null">
                and md.plate_num = #{macWeighBind.plateNum}
            </if>

            <if test="macWeighBind.macOrdId！=null">
                and md.serial_num = #{macWeighBind.macOrdId}
            </if>

            <if test="macWeighBind.openid！=null">
                and md.openid = #{macWeighBind.openid}
            </if>


        </where>


    </select>
    <select id="queryMacWeightBindDetails" resultType="com.bonus.canteen.core.order.weight.dto.BuffetWeighBind">
        select md.cust_id         as custId,
               md.openid          as openId,
               md.serial_num      as serialNum,
               md.plate_num       as plateNum,
               md.serial_num_card as serialNumCard,
               md.bind_type       as bindType,
               md.nu_clear_mode   as nuClearMode,
               md.pay_type        as payType,
               md.machine_sn      as machineSn,
               md.mac_ord_id      as macOrdId,
               md.uptime          as uptime
        from mac_weigh_bind md
        where md.cust_id = #{macWeighBinds.custId}
          and md.bind_state = #{macWeighBinds.bindState}
    </select>


    <!--	<select id="selectNeedPayList"  resultType="net.xnzn.leniu.yunshitangtcp.mac.entity.MacWeighBind">-->
    <!--		select * from mac_weight_bind  where-->


    <!--	</select>-->


    <select id="getAlifTokenAndAliSignByMacOrdId" resultType="com.bonus.canteen.core.order.weight.vo.AliMacWeightBindVO">
        select mwb.alif_token,
               mwb.ali_sign
        from mac_weigh_bind mwb
        where mwb.mac_ord_id = #{macOrdId}
    </select>

    <select id="getWeightBindByPage" resultType="com.bonus.canteen.core.order.weight.model.MacWeighBind">
        SELECT A.id,
               A.cust_id,
               A.cust_name,
               A.cust_limit_id,
               A.serial_num,
               A.serial_num_card,
               A.plate_num,
               A.bind_type,
               A.nu_clear_mode,
               A.quantity,
               A.sales_mode,
               A.bind_state,
               A.mac_ord_id,
               A.machine_sn,
               A.openid,
               A.pay_type,
               A.pay_time,
               A.if_redress,
               A.redress_remarks,
               A.resress_picurl,
               A.pro_special,
               A.resress_picurl,
               A.alipay_contract_num,
               A.crby,
               A.crtime,
               A.upby,
               A.uptime,
               A.discount
        FROM mac_weigh_bind A
        WHERE A.bind_state = 1
         and   A.cust_id = #{param.custid}
        ORDER BY A.crtime DESC
    </select>


    <select id="queryWeighBindDetail" resultType="com.bonus.canteen.core.order.deprecated.vo.AppPageOrdListVO">
        SELECT A.*,A.resress_picurl as resressPicurl,
        A.if_redress as checkState , A.redress_remarks as remark ,A.crtime as bindTime,
        E.cust_name,E.mobile
        FROM mac_weigh_bind A LEFT JOIN mac_machine B ON A.machine_sn = B.machine_sn
        LEFT JOIN cust_info E ON A.cust_id = E.cust_id
        WHERE A.bind_state = 1
        <if test="openId != null and openId != ''">
            AND A.openid = #{openId}
        </if>
        <if test="openId == null or openId == ''">
            AND A.if_redress = 1
        </if>
        <if test="param.nowDate != null">
            AND A.uptime BETWEEN #{minTime} AND #{maxTime}
        </if>

    </select>

</mapper>
