<?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.com.ctop.common.module.mapper.MaterialInfoMapper">


    <select id="getProjectIdByAccountId" resultType="java.lang.Long">

       select
       project_id
       from ctop_user_allocation
       where  account_id = #{accountId}

    </select>

    <select id="selectUserNameById" resultType="java.lang.String">
   select realname from  sys_user where  id = #{auditorId}
    </select>


    <select id="selectCountByMap" parameterType="java.util.Map" resultType="java.lang.Integer">

        select count(1)
        from ctop_material_info
        where 1 = 1
        <if test="userId != null">
            and user_id = #{userId}
        </if>

        <if test="status != null">
            and status = #{status}
        </if>


    </select>

    <select id="getRoleCodeByUserId" resultType="java.lang.String">
   SELECT
    role_code
    FROM
    sys_role
    WHERE
    id = (
    SELECT
    t2.role_id
    FROM
    sys_user t1
    LEFT JOIN sys_user_role t2 ON t1.id = t2.user_id
    WHERE
    t1.id = #{userId,jdbcType=VARCHAR}
    )
    </select>

    <select id="getKuaishouUpVideoCount" resultType="java.lang.Integer">
        select
        count(1)
        from
        ctop_kuaishou_video_get v
        where
        v.signature = #{code}
    </select>

    <select id="getToutiaoUpVideoCount" resultType="java.lang.Integer">
        select
        count(1)
        from
        ctop_bytedance_video_info v
        where
        v.signature = #{code}
    </select>


    <select id="getGeneralizationInfo" resultType="com.alibaba.fastjson.JSONObject">
     SELECT
	 SUM(t.cost) cost,
	 SUM(t.photoShow) photoShow,
	 SUM(t.photoClick) photoClick
      FROM
	 (
		SELECT
		cost cost,
        show_num photoShow,
        click photoClick
		FROM
		ctop_bytedance_clean_material_report
		WHERE
		id = #{code}
		UNION ALL
		SELECT
		charge cost,
        photo_show photoShow,
        photo_click photoClick
		FROM
		ctop_kuaishou_clean_material_report
		WHERE
		id = #{code}
	  )t
    </select>

    <select id="getEffiSignature" resultType="string">
        select
        efficient_video_signature
        from ctop_user_efficient_video_map
        where company_id is not null
        group by efficient_video_signature

    </select>

    <select id="getMaterialInfoByCode" resultType="cn.com.ctop.common.module.entity.MaterialInfo">
            select
            id,
            code,
            url,
            watermark_code as watermarkCode,
            material_name as materialName,
            watermark_url as watermarkUrl,
            watermark_material_name as watermarkMaterialName,
            user_id as userId,
            auditor_id as auditorId,
            status as status,
            material_describe as materialDescribe,
            project_id as projectId,
            refuse_reason as refuseReason,
            creative_copywriter as creativeCopywriter,
            refuse_file as refuseFile,
            excellent,
            type
        from
        ctop_material_info
        where code = #{code}
        limit 1
    </select>

    <select id="getListByDate" resultType="cn.com.ctop.common.module.entity.MaterialInfo">
        select  *  from
        ctop_material_info
        where  1 = 1
        and DATE_FORMAT(create_time,'%Y-%m-%d') &gt;= #{startDate}
        and DATE_FORMAT(create_time,'%Y-%m-%d') &lt;= #{endDate}
    </select>


</mapper>
