<?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.AppResumptionDataMapper">
    <sql id="tableName">
        t_app_resumption_data
    </sql>

    <sql id="baseColumn">
        id,plan_id,item_id,resumption_id,res_value,res_time,submit_time,res_status,submit_by,submit_name
    </sql>

    <select id="findTaskDataList" parameterType="java.util.HashMap" resultType="java.util.Map">
           SELECT c.id as itemid,c.item_name as itemname FROM t_app_resumption_data a LEFT JOIN t_app_rule_point b ON a.item_id= b.id LEFT JOIN t_app_rule_item c ON b.item_id = c.id WHERE a.resumption_id=#{taskid} AND b.area_id=#{areaid} GROUP BY c.id having c.id is not null
    </select>

    <select id="findCheckDataList" parameterType="java.util.HashMap" resultType="java.util.Map">
           SELECT a.id AS pointdataid,b.id AS pointid,b.point_name AS pointname,b.point_num AS pointnum,a.res_value AS resvalue,a.res_status AS resstatus,a.res_remark AS resremark,b.time_type as timeType,a.res_time as resTime FROM t_app_resumption_data a LEFT JOIN t_app_rule_point b ON a.item_id  = b.id WHERE a.resumption_id=#{taskid} AND b.area_id=#{areaid} and b.item_id = #{itemid}  order BY b.point_num asc
    </select>

    <select id="findAreaListPlan" parameterType="String" resultType="java.util.Map">
          SELECT a.area_id as areaid,b.name as areaname from t_app_resumption_data a LEFT JOIN t_area b ON a.area_id = b.id WHERE a.resumption_id=#{taskid} GROUP BY a.area_id
    </select>

    <select id="findTaskDataListNew" parameterType="java.util.HashMap" resultType="java.util.Map">
           SELECT c.id as itemid,c.item_name as itemname,ANY_VALUE(a.area_id) AS areaid FROM t_app_resumption_data a LEFT JOIN t_app_rule_point b ON a.item_id= b.id LEFT JOIN t_app_rule_item c ON b.item_id = c.id WHERE a.resumption_id=#{taskid} GROUP BY c.id having c.id is not null
    </select>


    <select id="findCheckDataListNew" parameterType="java.util.HashMap" resultType="java.util.Map">
           SELECT a.id AS pointdataid,b.id AS pointid,b.point_name AS pointname,b.point_num AS pointnum,a.res_value AS resvalue,a.res_status AS resstatus,a.res_remark AS resremark,b.time_type as timeType,a.res_time as resTime, b.area_id as areaid , b.item_id as itemid FROM t_app_resumption_data a LEFT JOIN t_app_rule_point b ON a.item_id  = b.id WHERE a.resumption_id=#{taskid}   order BY b.point_num asc
    </select>

    <select id="findDataByTaskId" parameterType="java.util.HashMap" resultType="com.xunmei.core.resumption.vo.ResumptionInfoVo">
        SELECT
            a.id,
            c.id item_id,
            c.item_name,
            d.id point_id,
            d.point_name,
            d.point_num,
            b.id area_id,
            b.NAME area_name,
            a.res_value data_value,
            a.res_time data_time,
            a.res_remark data_remark,
            a.res_status data_status,
	        d.time_type
        FROM
            t_app_resumption_data a
            LEFT JOIN t_area b ON a.area_id = b.id
            LEFT JOIN t_app_rule_point d ON a.item_id = d.id
            LEFT JOIN t_app_rule_item c ON d.item_id = c.id
        WHERE
            a.resumption_id = #{taskId}


    </select>

    <select id="findDataByPointBusinessType" parameterType="java.util.HashMap" resultType="com.xunmei.core.resumption.domain.AppResumptionData">
        SELECT
            a.*
        FROM
            t_app_resumption_data a
            INNER JOIN t_app_resumption r ON a.resumption_id = r.id
            INNER JOIN core_resumption_plan p ON p.id = a.plan_id
            LEFT JOIN t_app_rule_point d ON a.item_id = d.id
    WHERE
        r.ymd_date = #{date}
      AND r.org_id = #{orgId}
      AND d.business_type = #{businessType}


    </select>
  
     <update id="updateData" parameterType="String">
         update  t_app_resumption_data set res_status = 2 where resumption_id =#{taskId}
     </update>
</mapper>