<?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">
    
    <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>
    
    <insert id="insertToExcelAlyStatus" 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_copy
        	(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>
    
    <insert id="insertToExcelTencentStatus" parameterType="ExcelPathStatus" useGeneratedKeys="true" keyProperty="id">
    
    	<selectKey keyProperty="id" order="AFTER" resultType="java.lang.Integer">
            SELECT LAST_INSERT_ID()
        </selectKey>
    	insert into excel_file
        	(sp_id,operate_type,path,status,create_time,export_condition,count,sp_saler,type)
        	values
        	(#{sp_id}, #{operate_type},#{path}, #{status}, NOW(), #{export_condition}, #{count}, #{sp_saler},#{type})
    </insert>
    
    <update id="updateExcelCreateStatus" parameterType="ExcelPathStatus">
    	update sms_excel_file set status = #{status},result_time = NOW(),file_size = #{file_size},count = #{count} where path = #{path}
    </update>
    
    <update id="updateExcelCreateStatusAly" parameterType="ExcelPathStatus">
    	update sms_excel_file_copy set status = #{status},result_time = NOW(),file_size = #{file_size},count = #{count} where path = #{path}
    </update>
    
    <update id="updateExcelCreateStatuTencent" parameterType="ExcelPathStatus">
    	update excel_file set status = #{status},result_time = NOW(),file_size = #{file_size},count = #{count} where path = #{path}
    </update>
    
    <update id="cancelExcelCreate" parameterType="ExcelPathStatus">
    	update sms_excel_file set status = #{status},result_time = NOW() where id = #{id}
    </update>
    
     <update id="cancelExcelCreateAly" parameterType="ExcelPathStatus">
    	update sms_excel_file_copy set status = #{status},result_time = NOW() where id = #{id}
    </update>
    
    <update id="cancelExcelCreateTencent" parameterType="ExcelPathStatus">
    	update 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 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>
	
	<select id="listPageExcelAly" parameterType="ExcelPathStatus" resultType="ExcelPathStatus">
		select id,sp_id,operate_type,path,status,create_time,result_time,export_condition,file_size,count from sms_excel_file_copy 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>
	
	
	<select id="listPageExcelTencent" parameterType="ExcelPathStatus" resultType="ExcelPathStatus">
		select id,sp_id,operate_type,path,status,create_time,result_time,export_condition,file_size,count,type from 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>
        <if test="type!=null and type>0">
            and type =#{type}
        </if>
		order by id desc
	</select>
	<select id="getAllExcelType" resultType="cn.roadm.bo.ExcelType">
		select * from excel_type
	</select>
	
</mapper>