<?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="cn.cecep.talroad.mapper.STaskYieldTrendMapper">
  <resultMap id="BaseResultMap" type="cn.cecep.talroad.domain.STaskYieldTrend">
      <!--@mbg.generated-->
      <!--@Table s_task_yield_trend-->
      <result column="data_id"  property="dataId" />
      <result column="factory_id"  property="factoryId" />
      <result column="time_type"  property="timeType" />
      <result column="data_time"  property="dataTime" />
      <result column="number"  property="number" />
      <result column="create_time"  property="createTime" />
      <result column="dict_code"  property="dictCode" />
      <result column="device_id"  property="deviceId" />
  </resultMap>
  <sql id="Base_Column_List">
    <!--@mbg.generated-->
    data_id, factory_id, time_type, data_time, "number", create_time, dict_code,device_id
  </sql>

  <select id="selectMonthListGroupByIndustry" resultType="cn.cecep.talroad.vo.STaskYieldTrendVo">
      SELECT
          styt.dict_code,
          styt."month"  dataTime,
          styt."number",
          pyt.large,
          pyt.small,
          pyt.unit
      FROM (
          SELECT
              dict_code,
              to_char(data_time, 'YYYY-MM') AS  "month",
              SUM("number")    AS number
          FROM s_task_yield_trend styt
            LEFT JOIN pc_factory pf ON styt.factory_id = pf.id
          WHERE
              time_type = 'H'
              AND to_char(data_time, 'YYYY-MM') <![CDATA[ >= ]]> #{startMonth}
              AND to_char(data_time, 'YYYY-MM') <![CDATA[ <= ]]> #{endMonth}
              <if test="industry != null and industry != ''">
                  AND pf.industry_category = #{industry}
              </if>
              <if test="regionCodes != null and regionCodes.size() != 0">
                  and pf.country_code IN
                  <foreach collection="regionCodes" separator="," item="item" close=")" open="(">
                      #{item,jdbcType=VARCHAR}
                  </foreach>
              </if>
      GROUP BY dict_code, month ) styt
      LEFT JOIN pc_yield_trend pyt ON styt.dict_code = pyt.code
      ORDER BY styt."month"
  </select>

    <select id="analyseDayTaskYieldTrendData" resultMap="BaseResultMap">
        select  factory_id,device_id,dict_code,sum("number") as number from s_task_yield_trend where time_type='H' and to_char(data_time,'yyyy-MM-dd')=#{dayTime} GROUP BY factory_id,device_id,dict_code
    </select>

</mapper>
