<?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.xunmei.core.resumption.mapper.AppResumptionDataNfcMapper">
    <sql id="tableName">
        t_app_resumption_data_nfc
    </sql>

    <sql id="baseColumn">
        id,resumption_id,nfc_id,submit_time,status
    </sql>
    <select id="findnfcDataList" parameterType="java.util.HashMap" resultType="java.util.Map">
           SELECT ANY_VALUE(a.id) AS nfcdataid,ANY_VALUE(b.id) AS nfcid,ANY_VALUE(b.code) AS nfccdoe,ANY_VALUE(a.status) as status ,ANY_VALUE(c.check_name) as checkName FROM t_app_resumption_data_nfc a LEFT JOIN t_nfc_bind b ON a.nfc_id = b.check_id  left join t_area_check c on b.check_id = c.id WHERE b.area_id=#{areaid} AND a.resumption_id=#{taskid} AND b.org_id =#{orgId} group by b.code
    </select>

    <select id="findnfcDataListByPointid" parameterType="java.util.HashMap" resultType="java.util.Map">
     SELECT a.id AS nfcdataid,b.id AS nfcid,b.code AS nfccdoe,a.status,c.check_name as checkName FROM t_app_resumption_data_nfc a LEFT join t_nfc_bind b ON a.nfc_id =b.check_id  left join t_area_check c on b.check_id = c.id WHERE  a.point_id =#{pointid} and a.resumption_id=#{taskid} AND b.org_id =#{orgId}
    </select>

    <select id="findnfcDataListNew" parameterType="java.util.HashMap" resultType="java.util.Map">
           SELECT ANY_VALUE(a.id) AS nfcdataid,ANY_VALUE(b.id) AS nfcid,ANY_VALUE(b.code) AS nfccdoe,ANY_VALUE(a.status) as status ,ANY_VALUE(c.check_name) as checkName,ANY_VALUE(b.area_id) AS areaid FROM t_app_resumption_data_nfc a LEFT JOIN t_nfc_bind b ON a.nfc_id = b.check_id  left join t_area_check c on b.check_id = c.id WHERE  a.resumption_id=#{taskid} AND b.org_id =#{orgId} group by b.code
    </select>

    <select id="findnfcDataListByPointidNew" parameterType="java.util.HashMap" resultType="java.util.Map">
     SELECT a.id AS nfcdataid,b.id AS nfcid,b.code AS nfccdoe,a.status,c.check_name as checkName,a.point_id as pointid FROM t_app_resumption_data_nfc a LEFT join t_nfc_bind b ON a.nfc_id =b.check_id  left join t_area_check c on b.check_id = c.id WHERE  a.resumption_id=#{taskid} AND b.org_id =#{orgId}
    </select>

    <select id="findPointNfcData" parameterType="java.util.HashMap" resultType="com.xunmei.core.resumption.vo.ResumptionNfcInfoVo">
        SELECT
            a.id  AS nfcdataid,
            b.id  AS nfcid,
            a.point_id,
            b.CODE AS nfccdoe,
            a.STATUS  AS status,
            c.check_name  AS checkName,
            b.area_id  AS area_id
        FROM
            t_app_resumption_data_nfc a
            LEFT JOIN t_nfc_bind b ON a.nfc_id = b.check_id and b.enable = 1
            LEFT JOIN t_area_check c ON b.check_id = c.id
        WHERE
            a.resumption_id = #{taskid}
            AND b.org_id = #{orgId}
    </select>


<!--    SELECT ANY_VALUE(a.id) AS nfcdataid,ANY_VALUE(b.id) AS nfcid,ANY_VALUE(b.code) AS nfccdoe,ANY_VALUE(a.status) as status ,ANY_VALUE(c.check_name) as checkName
       FROM t_app_resumption_data_nfc a LEFT JOIN t_nfc_bind b ON a.nfc_id = b.check_id  left join t_area_check c on b.check_id = c.id WHERE b.area_id=#{areaid} AND a.resumption_id=#{taskid} AND b.org_id =#{orgId} group by b.code-->
    <select id="findNfcByAreaIdAndOrgId"  parameterType="java.util.HashMap" resultType="com.xunmei.core.resumption.vo.ResumptionNfcVo" >
        select c.id as checkId,  a.collection_area_name as checkName,a.code as  nfccdoe,d.id as pointId,a.area_id as areaId ,a.id as nfcid from t_nfc_bind a
        LEFT JOIN t_area_check c ON a.check_id = c.id
        LEFT JOIN t_app_rule_point d on a.area_id = d.area_id
        LEFT JOIN core_resumption_plan_to_item e ON e.item_id = d.id
        where a.org_id =  #{orgId}
        and e.plan_id = #{planId}
        and a.check_id is not null
        and a.enable = 1
        and e.point_scan = 1
        <if test="nfcBindIdList!=null and nfcBindIdList.size>0">
            and a.area_id in
            <foreach collection="nfcBindIdList" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
    </select>

</mapper>