<?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="org.jeecg.modules.ctop.mapper.MaterialUploadTaskMapper">

    <select id="getCountByUserIdAndMd5" resultType="java.lang.Integer">
        select  count(1)  from  ctop_material_upload_task
        where kuaishou_user_id = #{userId}
        and signature = #{signature}
        and task_status != 4
    </select>
    <select id="getMaterialNameBySignature" resultType="com.alibaba.fastjson.JSONObject">
        select material_name as 'materialName', url as 'materialUrl',`code` as 'signature'  from ctop_material_info
        where  `id` = #{id}
        limit 1
    </select>
    <select id="getCountByAccountIdAndMd5" resultType="java.lang.Integer">
         select  count(1)  from  ctop_material_upload_task
        where account_id = #{accountId}
        and signature = #{signature}
        and task_status != 4
    </select>
    <select id="uploadDetail" resultType="com.alibaba.fastjson.JSONObject">
    SELECT
	t1.media_id AS 'mediaId',
	t1.account_id AS 'accountId',
	t1.kuaishou_user_id AS 'userId',
	t1.task_status AS 'taskStatus',
	t1.user_name AS 'userName',
	t1.remarks AS 'remarks',
	t3.project_name AS 'projectName',
	CAST(t1.create_time AS CHAR)  as 'createTime'
    FROM
	ctop_material_upload_task t1
    LEFT JOIN ctop_user_allocation t2 ON t1.account_id = t2.account_id
    LEFT JOIN ctop_project t3 ON t2.project_id = t3.id
    WHERE
	t1.signature = #{signature}
    ORDER BY
	t3.id

    </select>
    <select id="getCount" resultType="java.lang.Integer">
        select  count(1)  from  ctop_material_upload_task where signature = #{signature}

    </select>
    <select id="getCountByaccountIdAndMd5" resultType="java.lang.Integer">
        select  count(1)  from  ctop_material_upload_task
        where kuaishou_user_id = #{userId}
        and signature = #{signature}
        and account_id = #{accountId}
        and task_status != 4

    </select>
    <insert id="replaceBatch">
        insert into ctop_material_upload_task(
        media_id,
        signature,
        account_id,
        kuaishou_user_id,
        shield_backward_switch,
        user_id,
        user_name,
        material_name,
        material_url,
        task_status,
        remarks
        )
        values
        <foreach collection="addList" item="add" separator=",">
            (
            #{add.mediaId},
            #{add.signature},
            #{add.accountId},
            #{add.kuaishouUserId},
            #{add.shieldBackwardSwitch},
            #{add.userId},
            #{add.userName},
            #{add.materialName},
            #{add.materialUrl},
            #{add.taskStatus},
            #{add.remarks}
            )
        </foreach>
    </insert>
</mapper>