<?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.roadm.mapper.DownLoadCenterMapper">
    
    <select id="countTaskDetail" parameterType="TaskDetailInfo" resultType="java.lang.Integer">
        select count(*)
        from
        sms_submit st
        where 1=1
        <if test="mdn!=null and mdn!=''">
			and st.mdn=#{mdn}
		</if>

		<if test="sp_id!=null and sp_id>0">
			and st.sp_id=#{sp_id}
		</if>
		<if test="taskid!=null and taskid>0">
			and st.taskid=#{taskid}
		</if>
		<if test="createtime!=null and createtime!=''">
			and st.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d')
		</if>

		<if test="endtime!=null and endtime!=''">
			and st.create_time&lt;=DATE_ADD(str_to_date(#{endtime},'%Y-%m-%d'),INTERVAL 1 DAY)
		</if>
    </select>
    
    <insert id="insertToExcelStatus" parameterType="ExcelPathStatus" useGeneratedKeys="true" keyProperty="id">
    
    	<selectKey keyProperty="id" order="AFTER" resultType="java.lang.Integer">
            SELECT LAST_INSERT_ID()
        </selectKey>
    	insert into sms_excel_file
        	(sp_id,operate_type,path,status,create_time,export_condition,count,sp_saler)
        	values
        	(#{sp_id}, #{operate_type},#{path}, #{status}, NOW(), #{export_condition}, #{count}, #{sp_saler})
    </insert>
    
    <update id="updateExcelCreateStatus" parameterType="ExcelPathStatus">
    	update sms_excel_file set status = #{status},result_time = NOW(),file_size = #{file_size},count=#{count}
    	where id = #{id}
    </update>

    <update id="updateExcelPathStatus" parameterType="ExcelPathStatus">
    	update sms_excel_file set status = #{status},result_time = #{result_time},path = #{path}
    	where id = #{id}
    </update>
    
    <update id="cancelExcelCreate" parameterType="ExcelPathStatus">
    	update sms_excel_file set status = #{status},result_time = NOW() where id = #{id}
    </update>
	
	<select id="listPageExcel" parameterType="ExcelPathStatus" resultType="ExcelPathStatus">
		select id,sp_id,operate_type,path,status,create_time,result_time,export_condition,file_size,count,sp_saler from sms_excel_file where sp_id = #{sp_id}
		<if test="path!=null and path!=''">
			and path like CONCAT('%',#{path},'%')
		</if>
		<if test="create_time!=null and create_time!=''">
			and STR_TO_DATE(create_time,"%Y-%m-%d") &gt;= STR_TO_DATE(#{create_time},"%Y-%m-%d")
		</if>
		<if test="result_time!=null and result_time!=''">
			and STR_TO_DATE(create_time,"%Y-%m-%d") &lt;= STR_TO_DATE(#{result_time},"%Y-%m-%d")
		</if>
		<if test="sp_saler!=null and sp_saler!=''">
            and sp_saler =#{sp_saler}
        </if>
		order by id desc
	</select>
	
	
	<insert id="insertExtendExcelStatus" parameterType="ExcelPathStatus" useGeneratedKeys="true" keyProperty="id">
    
    	<selectKey keyProperty="id" order="AFTER" resultType="java.lang.Integer">
            SELECT LAST_INSERT_ID()
        </selectKey>
    	insert into extend_excel_file
        	(sp_id,operate_type,path,status,create_time,export_condition,count,sp_saler,channelid,start_time,end_time)
        	values
        	(#{sp_id}, #{operate_type},#{path}, #{status}, NOW(), #{export_condition}, #{count}, #{sp_saler},#{channelid},#{start_time},#{end_time})
    </insert>
    
    <update id="updateExtendExcelCreateStatus" parameterType="ExcelPathStatus">
    	update extend_excel_file set status = #{status},result_time = NOW(),file_size = #{file_size},count=#{count}
    	where id = #{id}
    </update>
    
    <update id="cancelExtendExcelCreate" parameterType="ExcelPathStatus">
    	update extend_excel_file set status = #{status},result_time = NOW() where id = #{id}
    </update>
    
    <update id="downloadExtendStatus">
    	update extend_excel_file set down_number=ifnull(down_number,0)+1 where id = #{id}
    </update>
	
	<select id="listPageExtendExcel" parameterType="ExcelPathStatus" resultType="ExcelPathStatus">
		select id,sp_id,operate_type,path,status,create_time,result_time,export_condition,file_size,count,down_number,channelid,start_time,end_time from extend_excel_file where sp_id = #{sp_id}
		<if test="path!=null and path!=''">
			and path like CONCAT('%',#{path},'%')
		</if>
		<if test="create_time!=null and create_time!=''">
			and STR_TO_DATE(create_time,"%Y-%m-%d") &gt;= STR_TO_DATE(#{create_time},"%Y-%m-%d")
		</if>
		<if test="result_time!=null and result_time!=''">
			and STR_TO_DATE(create_time,"%Y-%m-%d") &lt;= STR_TO_DATE(#{result_time},"%Y-%m-%d")
		</if>
		<if test="start_time!=null and start_time!=''">
			and STR_TO_DATE(start_time,"%Y-%m-%d") &gt;= STR_TO_DATE(#{start_time},"%Y-%m-%d")
		</if>
		<if test="end_time!=null and end_time!=''">
			and STR_TO_DATE(end_time,"%Y-%m-%d") &lt;= STR_TO_DATE(#{end_time},"%Y-%m-%d")
		</if>
		<if test="sp_saler!=null and sp_saler!=''">
            and sp_saler =#{sp_saler}
        </if>
        <if test="channelid!=null and channelid!=''">
        	and channelid=#{channelid}
        </if>
		order by id desc
	</select>
	
	
	
</mapper>