<?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.energy.manage.service.mappers.wavedatatransfer.WaveDataTransferMapper">
  <resultMap id="BaseResultMap" type="com.energy.manage.common.po.wavedatatransfer.WaveDataTransferPo">
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="field_code" jdbcType="VARCHAR" property="fieldCode" />
    <result column="transfer_addr" jdbcType="VARCHAR" property="transferAddr" />
    <result column="transfer_status" jdbcType="TINYINT" property="transferStatus" />
    <result column="err_code" jdbcType="VARCHAR" property="errCode" />
    <result column="err_info" jdbcType="VARCHAR" property="errInfo" />
    <result column="transfer_start_time" jdbcType="TIMESTAMP" property="transferStartTime" />
    <result column="transfer_finish_time" jdbcType="TIMESTAMP" property="transferFinishTime" />
    <result column="transfer_progress" jdbcType="INTEGER" property="transferProgress" />
    <result column="create_by" jdbcType="INTEGER" property="createBy" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="update_by" jdbcType="INTEGER" property="updateBy" />
    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
    <result column="transfer_type" jdbcType="TINYINT" property="transferType" />
  </resultMap>
  <sql id="Base_Column_List">
    field_code, transfer_addr, transfer_status, err_code, err_info, transfer_start_time,
    transfer_finish_time, transfer_progress, create_by, create_time, update_by, update_time
  </sql>

  <select id="selectByCondition" parameterType="com.energy.manage.service.domain.dto.wavedatatransfer.WaveDataTransferDto" resultType="com.energy.manage.service.domain.vo.wavedatatransfer.WaveDataTransferVo">
    select
        field.field_name,
        transfer.id,
        transfer.field_code,
        transfer.transfer_addr,
        transfer.transfer_status,
        transfer.err_code,
        transfer.err_info,
        transfer.transfer_start_time,
        transfer.transfer_finish_time,
        transfer.transfer_progress
    from wave_data_transfer transfer
    left join wind_field field
    on transfer.field_code = field.field_code
    <where>
      <if test="fieldName != null and fieldName != ''">
        field.field_name like concat ('%', #{fieldName}, '%')
      </if>
      <if test="transferStatus != null">
        and transfer.transfer_status = #{transferStatus}
      </if>
      <if test="transferType != null">
        and transfer.transfer_type = #{transferType}
      </if>
    </where>
    order by transfer.update_time desc
  </select>

  <select id="selectCountByCondition" parameterType="com.energy.manage.service.domain.dto.wavedatatransfer.WaveDataTransferDto" resultType="java.lang.Integer">
    select
    count(*)
    from wave_data_transfer transfer
    where transfer_status = -1
    <if test="fileCode != null and fileCode != ''">
      and field_code = #{fileCode}
    </if>
    <if test="transferAddr != null and transferAddr != ''">
      and transfer_addr = #{transferAddr}
    </if>
  </select>


  <update id="update" parameterType="com.energy.manage.common.po.wavedatatransfer.WaveDataTransferPo">
    update wave_data_transfer
    <set>
      <if test="fieldCode != null">
        field_code = #{fieldCode,jdbcType=VARCHAR},
      </if>
      <if test="transferAddr != null">
        transfer_addr = #{transferAddr,jdbcType=VARCHAR},
      </if>
      <if test="transferStatus != null">
        transfer_status = #{transferStatus,jdbcType=TINYINT},
      </if>
      <if test="updateBy != null">
        update_by = #{updateBy,jdbcType=INTEGER},
      </if>
      <if test="updateTime != null">
        update_time = #{updateTime,jdbcType=INTEGER}
      </if>
    </set>
    where id = #{id,jdbcType=BIGINT}
  </update>

</mapper>
