<?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.xhkjedu.sapi.mapper.cloud.CloudSyncDetailMapper">
  <!--批量添加-->
  <insert id="batchSave">
    insert into t_cloud_sync_detail (csdid,csid,synctable,plannum,beginid,endid
    ,syncnum,handleid,createid,createtime,begintime,endtime,lsbid)
    values
    <foreach collection ="list" item="d" index= "index" separator =",">
      (#{d.csdid},#{csid},#{d.synctable},#{d.plannum},#{d.beginid},#{d.endid}
      ,#{d.syncnum},#{d.handleid},#{createid},#{d.createtime},#{d.begintime},#{d.endtime},#{d.lsbid})
    </foreach>
  </insert>
  <!--获取未执行完的同步任务详情列表-->
  <select id="listByCsId" resultType="com.xhkjedu.sapi.model.cloud.TCloudSyncDetail">
    select csdid,csid,synctable,beginid,endid,handleid,syncnum,realnum,lsbid
    from t_cloud_sync_detail where csid=#{csid} and endid!=IFNULL(handleid,0)
  </select>
  <!--更新已同步数量-->
  <update id="updateRealNum">
    update t_cloud_sync_detail set handleid=#{detail.handleid}
    <if test="detail.realnum!=null">,realnum=realnum+#{detail.realnum}</if>
    <if test="detail.starttime!=null">,starttime=#{detail.starttime},syncnum=#{detail.syncnum}</if>
    <if test="detail.stoptime!=null">,stoptime=#{detail.stoptime}</if>
    where csid=#{detail.csid} and synctable=#{detail.synctable}
    <if test="detail.lsbid!=null">and lsbid=#{detail.lsbid}</if>
  </update>
  <!--获取未执行完成的任务详情数量-->
  <select id="countNoEndByCsId" resultType="java.lang.Integer">
    select count(*) from t_cloud_sync_detail where csid=#{csid} and endid!=IFNULL(handleid,0)
  </select>
</mapper>
