<?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.kxs.product.biz.mapper.KxsGdReportMapper">

    <resultMap type="com.kxs.product.api.model.KxsGdReport" id="KxsGdReportMap">
        <result column="id" property="id"/>
        <result column="create_time" property="createTime"/>
        <result column="update_time" property="updateTime"/>
        <result column="del_flag" property="delFlag"/>
        <result column="version" property="version"/>
        <result column="user_id" property="userId"/>
        <result column="username" property="username"/>
        <result column="user_code" property="userCode"/>
        <result column="province" property="province"/>
        <result column="city" property="city"/>
        <result column="put_name" property="putName"/>
        <result column="put_mobile" property="putMobile"/>
        <result column="remark" property="remark"/>
        <result column="status" property="status"/>
        <result column="gd_sn" property="gdSn"/>
        <result column="gd_mobile" property="gdMobile"/>
        <result column="is_check" property="isCheck"/>
        <result column="put_type" property="putType"/>

    </resultMap>
    <select id="getByPage" resultType="com.kxs.product.api.vo.kxsapp.gd.GdReportListVO">
        select id, create_time, put_name, put_mobile, gd_sn, gd_mobile, status
        from kxs_gd_report
        <where>
            and del_flag = 0
            and user_id = #{userId}
            and status = #{status}
            and put_type = #{putType}
            <if test="keyword != null and keyword != ''">
                and (put_name = #{keyword} or put_mobile = #{keyword} or gd_mobile = #{keyword})
            </if>
        </where>
        order by id desc
    </select>
    <select id="getByUnBindPage" resultType="com.kxs.product.api.vo.kxsapp.machine.MachineUnBindListVO">
        select a.id, a.pos_sn
        from kxs_machine a
        left join kxs_gd_report b on a.pos_sn = b.gd_sn
        <where>
            and a.del_flag = 0
            and a.bind_status = 0
            and a.brand_id = 14
            and a.user_id = #{userId}
            and b.gd_sn is null
            <choose>
                <when test="posSn != null and posSn != ''">
                    and a.pos_sn like concat('CS', '%', #{posSn})
                </when>
                <otherwise>
                    and a.pos_sn like concat('CS', '%')
                </otherwise>
            </choose>
        </where>
    </select>
    <select id="getDqByPage" resultType="com.kxs.product.api.vo.kxsapp.gd.GdReportListVO">
        select id, create_time, put_name, put_mobile, gd_sn, gd_mobile, status, is_check
        from kxs_gd_report
        <where>
            and del_flag = 0
            and put_type = 1
            and user_id = #{userId}
            <if test="status != null and status == 1">
                and status = 1
            </if>
            <if test="status != null and status == 2">
                and status = 1
                and is_check = 1
            </if>
            <if test="keyword != null and keyword != ''">
                and (put_name = #{keyword} or put_mobile = #{keyword} or gd_mobile = #{keyword})
            </if>
        </where>
        order by id desc
    </select>

</mapper>
