Browse Source

账户维度-账户自定义字段

zhaoxian 4 years ago
parent
commit
a560daab62

+ 8 - 10
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/xml/KuaishouVideoEtlInfoMapper.xml

@@ -14,15 +14,14 @@
         WHERE t1.account_id = #{accountId}
           AND t1.stat_date >= #{startTime}
           AND t1.stat_date <= #{endTime}
-        GROUP BY t1.signature
     </select>
 
     <select id="queryPageList" resultType="com.alibaba.fastjson.JSONObject">
         SELECT t1.signature,
-               SUM(t1.charge) as 'charge',
-               SUM(t1.activation) as 'activation',
-               SUM(t1.photo_show) as 'phototShow',
-               ROUND(SUM(t1.charge) / SUM(t1.activation), 2) as 'activationCost',
+               t1.charge as 'charge',
+               t1.activation as 'activation',
+               t1.photo_show as 'phototShow',
+               ROUND(t1.charge / t1.activation, 2) as 'activationCost',
                t2.url,
                t2.cover_url as 'coverUrl',
                t2.state_date as 'stateDate'
@@ -31,18 +30,17 @@
         WHERE t1.account_id = #{accountId}
           AND t1.stat_date &gt;= #{startTime}
           AND t1.stat_date &lt;= #{endTime}
-        GROUP BY t1.signature
         <if test="sortCode == 'charge' ">
-            ORDER BY  SUM(t1.charge)
+            ORDER BY t1.charge
         </if>
         <if test="sortCode == 'activationCost' ">
-            ORDER BY SUM(t1.charge) / SUM(t1.activation)
+            ORDER BY t1.charge / t1.activation
         </if>
         <if test="sortCode == 'phototShow' ">
-            ORDER BY SUM(t1.photo_show)
+            ORDER BY t1.photo_show
         </if>
         <if test="sortCode == 'activation' ">
-            ORDER BY SUM(t1.activation)
+            ORDER BY t1.activation
         </if>
         ${sortType}
     </select>

+ 2 - 2
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/service/impl/KuaishouVideoEtlInfoServiceImpl.java

@@ -318,8 +318,8 @@ public class KuaishouVideoEtlInfoServiceImpl extends ServiceImpl<KuaishouVideoEt
         String startTime = request.getString("startTime");
         String endTime = request.getString("endTime");
         if (Check.isNull(startTime) || Check.isNull(endTime)) {
-            startTime = DateUtils.getNowDate("yyyy-MM-dd");
-            endTime = startTime;
+            endTime = DateUtils.getNowDate("yyyy-MM-dd");
+            startTime = DateUtils.getLastDay(endTime, 1);
         }
         String sortCode = request.getString("sortCode");
         String sortType = request.getString("sortType");

+ 1 - 3
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/DTO/ColumnDTO.java

@@ -1,17 +1,15 @@
 package cn.com.ctop.toutiao.modules.report.DTO;
 
-import com.alibaba.fastjson.JSONArray;
-import com.alibaba.fastjson.JSONObject;
 import lombok.Data;
 
 import java.io.Serializable;
-import java.math.BigDecimal;
 
 
 @Data
 public class ColumnDTO extends PageDTO implements Serializable {
     private Integer columnType;
     private String userId;
+    private Long accountId;
     private String json;
     //private JSONArray json2;
     //private String jsonStr;

+ 43 - 1
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/controller/ByteDanceVideoReportDailyController.java

@@ -16,7 +16,12 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.util.DateUtils;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
@@ -232,6 +237,43 @@ public class ByteDanceVideoReportDailyController {
 
     @AutoLog(value = "保存或更新视频报表保存的字段")
     @ApiOperation(value = "保存或更新视频报表保存的字段", notes = "保存或更新视频报表保存的字段")
+    @PostMapping(value = "/saveOrUpdateColumnJsonByAccountId")
+    public Result<Object> saveOrUpdateColumnJsonByAccountId(@RequestBody ColumnDTO columnDTO) {
+        try {
+            Integer columnType = columnDTO.getColumnType();
+            String json = columnDTO.getJson();
+            Long accountId = columnDTO.getAccountId();
+            if (Check.isNull(json) || Check.isNull(columnType) || Check.isNull(accountId)) {
+                return Result.error("必填项为空");
+            }
+            videoReportDailyService.saveOrUpdateColumnJsonByAccountId(accountId, columnType, json);
+            return Result.ok("操作成功");
+        } catch (Exception e) {
+            e.printStackTrace();
+            return Result.error("执行异常," + e.getMessage());
+        }
+    }
+
+    @AutoLog(value = "查询视频报表保存的字段")
+    @ApiOperation(value = "查询视频报表保存的字段", notes = "查询视频报表保存的字段")
+    @PostMapping(value = "/getColumnJsonByAccountId")
+    public Result<Object> getColumnJsonByAccountId(@RequestBody ColumnDTO columnDTO) {
+        try {
+            Integer columnType = columnDTO.getColumnType();
+            Long accountId = columnDTO.getAccountId();
+            if (Check.isNull(accountId) || Check.isNull(columnType)) {
+                return Result.error("请选择账户和类型");
+            }
+            String json = videoReportDailyService.getColumnJsonByAccountId(accountId, columnType);
+            return Result.ok(json);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return Result.error("查询异常," + e.getMessage());
+        }
+    }
+
+    @AutoLog(value = "保存或更新视频报表保存的字段")
+    @ApiOperation(value = "保存或更新视频报表保存的字段", notes = "保存或更新视频报表保存的字段")
     @PostMapping(value = "/saveOrUpdateColumnJson")
     public Result saveOrUpdateColumnJson(@RequestBody ColumnDTO columnDTO, HttpServletRequest req) {
         Result result = new Result();

+ 4 - 2
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/mapper/ByteDanceVideoReportDailyMapper.java

@@ -31,9 +31,11 @@ public interface ByteDanceVideoReportDailyMapper extends BaseMapper<ByteDanceVid
 
     String getJsonByUserIdAndColumnType(@Param("columnType") Integer columnType, @Param("userId") String userId);
 
-    void insertColumnLoad(@Param("json") String json, @Param("userId") String userId, @Param("columnType") Integer columnType);
+    String getJsonByAccountIdAndColumnType(@Param("accountId") Long accountId,@Param("columnType") Integer columnType);
 
-    void updateJsonByUserIdAndType(@Param("json") String json, @Param("userId") String userId, @Param("columnType") Integer columnType);
+    void insertColumnLoad(@Param("json") String json, @Param("userId") String userId, @Param("columnType") Integer columnType,@Param("accountId") Long accountId);
+
+    void updateJsonByUserIdAndType(@Param("json") String json, @Param("userId") String userId, @Param("columnType") Integer columnType,@Param("accountId") Long accountId);
 
     List<ByteDanceVideoReportDaily> videoInfoListDetail(@Param("companyId") String companyId, @Param("startDate") String startDate, @Param("endDate") String endDate, @Param("signature") String signature, @Param("accountIds") List<Long> accountIds);
 

+ 268 - 177
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/mapper/xml/ByteDanceVideoReportDailyMapper.xml

@@ -11,25 +11,28 @@
         stat_datetime &gt;= #{startDate} and
         stat_datetime &lt;= #{endDate} and
         <if test="accountIds != null">
-        account_id in
+            account_id in
             <foreach item="item" index="index" collection="accountIds" open="(" separator="," close=")">
                 #{item}
-            </foreach> and
+            </foreach>
+            and
         </if>
         signature = #{signature}
     </select>
 
     <update id="updateHuanbiByDateAndSignature">
         update
-        ctop_bytedance_video_report_daily
+            ctop_bytedance_video_report_daily
         set huanbi = #{huanbi}
-        where
-        stat_datetime = #{date}
-        and signature = #{signature}
+        where stat_datetime = #{date}
+          and signature = #{signature}
     </update>
 
     <sql id="selectSql">
-        a.project_id                             as projectId,
+        a
+        .
+        project_id
+        as projectId,
         a.project_name                           as projectName,
         a.advertiser_id                          as advertiserId,
         a.advertiser_name                        as advertiserName,
@@ -51,17 +54,20 @@
         case
         when sum(a.total_play) != 0
         then sum(a.play25_feed_break) / sum(a.total_play)
-        else 0 end                           as play25FeedBreakRate,
+        else 0
+        end                           as play25FeedBreakRate,
 
         case
         when sum(a.total_play) != 0
         then sum(a.play_over) / sum(a.total_play)
-        else 0 end                           as playOverRate,
+        else 0
+        end                           as playOverRate,
 
         case
         when sum(a.click) != 0
         then sum(a.convert_material) / sum(a.click)
-        else 0 end                           as convertRate,
+        else 0
+        end                           as convertRate,
         sum(a.active)                            as active,
         sum(a.download_finish)                   as downloadFinish,
         sum(a.download_start)                    as downloadStart,
@@ -82,38 +88,45 @@
         case
         when sum(a.active) != 0
         then sum(a.next_day_open) / sum(a.active)
-        else 0 end                           as nextDayOpenRate,
+        else 0
+        end                           as nextDayOpenRate,
 
         case
         when sum(a.next_day_open) != 0
         then sum(a.cost) / sum(a.next_day_open)
-        else 0 end                           as nextDayOpenCost,
+        else 0
+        end                           as nextDayOpenCost,
 
         sum(a.active_pay_amount)                 as activePayAmount,
 
         case
         when sum(a.valid_play) != 0
         then sum(a.cost) / sum(a.valid_play)
-        else 0 end                              validPlayCost,
+        else 0
+        end                              validPlayCost,
         sum(a.convert_material)                  as convertMaterial,
 
         case
         when sum(a.active_pay_amount) != 0
         then sum(a.cost) / sum(a.active_pay_amount)
-        else 0 end                           as activePayCost,
+        else 0
+        end                           as activePayCost,
         case
         when sum(a.click) != 0
         then sum(a.cost) / sum(a.click)
-        else 0 end                           as cpc,
+        else 0
+        end                           as cpc,
         case
         when sum(a.show_material) != 0
         then sum(a.click) / sum(a.show_material)
-        else 0 end                           as ctr,
+        else 0
+        end                           as ctr,
 
         case
         when sum(a.show_material) != 0
         then sum(a.cost) / sum(a.show_material) * 1000
-        else 0 end                              cpm,
+        else 0
+        end                              cpm,
         sum(a.wifi_play_rate)                    as wifiPlayRate,
         sum(a.like_material)                     as likeMaterial,
 
@@ -121,144 +134,180 @@
         case
         when sum(a.active) != 0
         then sum(a.cost) / sum(a.active)
-        else 0 end                              activeCost,
+        else 0
+        end                              activeCost,
 
         case
         when sum(a.game_addiction) != 0
         then sum(a.cost) / sum(a.game_addiction)
-        else 0 end                           as gameAddictionCost,
+        else 0
+        end                           as gameAddictionCost,
         sum(a.game_addiction)                    as gameAddiction,
 
         case
         when sum(a.click) != 0
         then sum(a.active) / sum(a.click)
-        else 0 end                           as activeRate,
+        else 0
+        end                           as activeRate,
 
 
         case
         when sum(a.active) != 0
         then sum(a.game_addiction) / sum(a.active)
-        else 0 end                              gameAddictionRate,
+        else 0
+        end                              gameAddictionRate,
 
         case
         when sum(a.active) != 0
         then sum(a.register) / sum(a.active)
-        else 0 end                           as activeRegisterRate,
+        else 0
+        end                           as activeRegisterRate,
         case
         when sum(a.download_finish) != 0
         then sum(a.cost) / sum(a.download_finish)
-        else 0 end                           as downloadFinishCost,
+        else 0
+        end                           as downloadFinishCost,
         case
         when sum(a.register) != 0
         then sum(a.cost) / sum(a.register)
-        else 0 end                           as activeRegisterCost,
+        else 0
+        end                           as activeRegisterCost,
         sum(a.show_material)                     as showMaterial,
         case
         when sum(a.download_start) != 0
         then sum(a.download_finish) / sum(a.download_start)
-        else 0 end                           as downloadFinishRate,
+        else 0
+        end                           as downloadFinishRate,
         case
         when sum(a.download_finish) != 0
         then sum(a.install_finish) / sum(a.download_finish)
-        else 0 end                           as installFinishRate,
+        else 0
+        end                           as installFinishRate,
         sum(a.play_over)                         as playOver,
         case
         when sum(a.download_start) != 0
         then sum(a.cost) / sum(a.download_start)
-        else 0 end                           as downloadStartCost,
+        else 0
+        end                           as downloadStartCost,
         case
         when sum(a.show_material) != 0
         then sum(a.valid_play) / sum(a.show_material)
-        else 0 end                           as validPlayRate,
+        else 0
+        end                           as validPlayRate,
         case
         when sum(a.valid_play) != 0
         then sum(a.average_play_time_per_play*a.valid_play)/sum(a.valid_play)
-        else 0 end as averagePlayTimePerPlay,
+        else 0
+        end as averagePlayTimePerPlay,
         case
         when sum(a.convert_material) != 0
         then sum(a.cost) / sum(a.convert_material)
-        else 0 end                           as convertCost,
+        else 0
+        end                           as convertCost,
         case
         when sum(a.install_finish) != 0
         then sum(a.cost) / sum(a.install_finish)
-        else 0 end                           as installFinishCost,
+        else 0
+        end                           as installFinishCost,
         case
         when sum(a.click) != 0
         then sum(a.download_start) / sum(a.click)
-        else 0 end                           as downloadStartRate
+        else 0
+        end                           as downloadStartRate
     </sql>
 
     <select id="getRoleCodeByUserId" resultType="string">
-        select
-        role_code
-        from
-        sys_user_role a
-        left join sys_role b on a.role_id = b.id
+        select role_code
+        from sys_user_role a
+                 left join sys_role b on a.role_id = b.id
         where a.user_id = #{userId}
     </select>
 
     <select id="getCompanyIdByUserId" resultType="string">
-            select
-            company_id
-        from
-        user_company
+        select company_id
+        from user_company
         where user_id = #{userId}
     </select>
 
     <select id="getJsonByUserIdAndColumnType" resultType="string">
-        select
-        json as json
-        from
-        ctop_column_load
-        where
-        column_type = #{columnType}
-        and user_id = #{userId}
+        select json as json
+        from ctop_column_load
+        where column_type = #{columnType}
+          and user_id = #{userId}
+    </select>
+
+    <select id="getJsonByAccountIdAndColumnType" resultType="string">
+        select json as json
+        from ctop_column_load
+        where column_type = #{columnType}
+          and account_id = #{accountId}
     </select>
 
     <insert id="insertColumnLoad">
-        insert into
-        ctop_column_load
-        (
-        user_id,
-        json,
-        column_type,
-        status
-        )
-        values
-        (
-        #{userId},
-        #{json},
-        #{columnType},
-        1
-        )
+        insert into ctop_column_load
+        <trim prefix="(" suffix=")" suffixOverrides=",">
+            <if test="userId != null">
+                user_id,
+            </if>
+            <if test="json != null">
+                json,
+            </if>
+            <if test="columnType != null">
+                column_type,
+            </if>
+            <if test="accountId != null">
+                account_id,
+            </if>
+            status
+        </trim>
+        <trim prefix="values (" suffix=")" suffixOverrides=",">
+            <if test="userId != null">
+                #{userId},
+            </if>
+            <if test="json != null">
+                #{json},
+            </if>
+            <if test="columnType != null">
+                #{columnType},
+            </if>
+            <if test="accountId != null">
+                #{accountId},
+            </if>
+            1
+        </trim>
     </insert>
 
+
     <update id="updateJsonByUserIdAndType">
         update
         ctop_column_load
         set
         json = #{json}
-        where
-        user_id = #{userId}
-        and
-        column_type = #{columnType}
+        where column_type = #{columnType}
+        <if test="userId != null">
+            and user_id = #{userId}
+        </if>
+        <if test="accountId != null">
+            and account_id = #{accountId}
+        </if>
     </update>
 
     <select id="videoInfoListDetail" resultType="cn.com.ctop.toutiao.modules.report.entity.ByteDanceVideoReportDaily">
-                select
-                a.project_id as projectId,
-                a.project_name as projectName,
-                a.account_id as accountId,
-                a.advertiser_id as advertiserId,
-                a.advertiser_name as advertiserName,
-                a.stat_datetime as statDatetime,
-                sum(a.cost) as cost,
-                a.video_url as videoUrl,
-                (select info.url from ctop_material_info info where info.code = a.signature limit 1) as url,
-                signature as signature
+        select
+        a.project_id as projectId,
+        a.project_name as projectName,
+        a.account_id as accountId,
+        a.advertiser_id as advertiserId,
+        a.advertiser_name as advertiserName,
+        a.stat_datetime as statDatetime,
+        sum(a.cost) as cost,
+        a.video_url as videoUrl,
+        (select info.url from ctop_material_info info where info.code = a.signature limit 1) as url,
+        signature as signature
 
         from ctop_bytedance_video_report_daily a
-        left join (select material_id,clip_id,shot_id,plan_id,plane_id from ctop_material_ascription group by material_id) f on a.signature = f.material_id
+        left join (select material_id,clip_id,shot_id,plan_id,plane_id from ctop_material_ascription group by
+        material_id) f on a.signature = f.material_id
         where
         stat_datetime &gt;= #{startDate}
         and stat_datetime &lt;= #{endDate}
@@ -273,7 +322,8 @@
         order by stat_datetime desc
     </select>
 
-    <select id="videoInfoListDetailOperator" resultType="cn.com.ctop.toutiao.modules.report.entity.ByteDanceVideoReportDaily">
+    <select id="videoInfoListDetailOperator"
+            resultType="cn.com.ctop.toutiao.modules.report.entity.ByteDanceVideoReportDaily">
         select
         a.project_id as projectId,
         a.project_name as projectName,
@@ -287,12 +337,13 @@
         signature as signature
 
         from ctop_bytedance_video_report_daily a
-        left join (select material_id,clip_id,shot_id,plan_id,plane_id from ctop_material_ascription group by material_id) f on a.signature = f.material_id
+        left join (select material_id,clip_id,shot_id,plan_id,plane_id from ctop_material_ascription group by
+        material_id) f on a.signature = f.material_id
         where
         stat_datetime &gt;= #{startDate}
         and stat_datetime &lt;= #{endDate}
         <if test="accountIds != null">
-        and a.account_id in
+            and a.account_id in
             <foreach item="item" index="index" collection="accountIds" open="(" separator="," close=")">
                 #{item}
             </foreach>
@@ -302,7 +353,8 @@
         order by stat_datetime desc
     </select>
 
-    <select id="videoInfoListDetailOtherRoles" resultType="cn.com.ctop.toutiao.modules.report.entity.ByteDanceVideoReportDaily">
+    <select id="videoInfoListDetailOtherRoles"
+            resultType="cn.com.ctop.toutiao.modules.report.entity.ByteDanceVideoReportDaily">
         select
         a.project_id as projectId,
         a.project_name as projectName,
@@ -316,7 +368,8 @@
         signature as signature
 
         from ctop_bytedance_video_report_daily a
-        left join (select material_id,clip_id,shot_id,plan_id,plane_id from ctop_material_ascription group by material_id) f on a.signature = f.material_id
+        left join (select material_id,clip_id,shot_id,plan_id,plane_id from ctop_material_ascription group by
+        material_id) f on a.signature = f.material_id
         where
         stat_datetime &gt;= #{startDate}
         and stat_datetime &lt;= #{endDate}
@@ -331,7 +384,8 @@
         order by stat_datetime desc
     </select>
 
-    <select id="videoInfoListDetailDesign" resultType="cn.com.ctop.toutiao.modules.report.entity.ByteDanceVideoReportDaily">
+    <select id="videoInfoListDetailDesign"
+            resultType="cn.com.ctop.toutiao.modules.report.entity.ByteDanceVideoReportDaily">
         select
         a.project_id as projectId,
         a.project_name as projectName,
@@ -345,7 +399,8 @@
         signature as signature
 
         from ctop_bytedance_video_report_daily a
-        left join (select material_id,clip_id,shot_id,plan_id,plane_id from ctop_material_ascription group by material_id) f on a.signature = f.material_id
+        left join (select material_id,clip_id,shot_id,plan_id,plane_id from ctop_material_ascription group by
+        material_id) f on a.signature = f.material_id
         where
         stat_datetime &gt;= #{startDate}
         and stat_datetime &lt;= #{endDate}
@@ -364,29 +419,28 @@
     </select>
 
     <select id="accountVideoMap" resultType="cn.com.ctop.toutiao.modules.report.DTO.AccountVideoDTO">
-            select
-            a.account_id,b.signature
-        FROM
-        ctop_bytedance_report_material_daily a
-        left join ctop_bytedance_video_info b on a.material_id = b.material_id
-        where a.image_mode in ('CREATIVE_IMAGE_MODE_VIDEO','CREATIVE_IMAGE_MODE_VIDEO_VERTICAL')
-        and b.signature is not null
-        group by a.account_id,b.signature
+        select a.account_id,
+               b.signature
+        FROM ctop_bytedance_report_material_daily a
+                 left join ctop_bytedance_video_info b on a.material_id = b.material_id
+        where a.image_mode in ('CREATIVE_IMAGE_MODE_VIDEO', 'CREATIVE_IMAGE_MODE_VIDEO_VERTICAL')
+          and b.signature is not null
+        group by a.account_id, b.signature
     </select>
 
     <insert id="replaceIntoAccountVideoMapBatch">
         replace into
         ctop_bytedance_account_video_map
         (
-            account_id,
-            signature
+        account_id,
+        signature
         )
         values
         <foreach collection="accountVideoDTOList" item="accountVideo" separator=",">
-        (
+            (
             #{accountVideo.accountId},
             #{accountVideo.signature}
-        )
+            )
         </foreach>
     </insert>
     <insert id="insertBatch">
@@ -605,17 +659,17 @@
     </select>
 
     <select id="getAccountIdsByOperatorIdAndMediaId" resultType="long">
-        select
-        account_id
-        from
-        ctop_user_allocation
-        where
-        user_id = #{userId}
-        and media_id in (1,3)
+        select account_id
+        from ctop_user_allocation
+        where user_id = #{userId}
+          and media_id in (1, 3)
     </select>
 
     <sql id="videoInfoSql">
-        a.account_id as accountId,
+        a
+        .
+        account_id
+        as accountId,
         b.project_id as projectId,
         b.project_name as projectName,
         b.advertiser_id as advertiserId,
@@ -631,16 +685,19 @@
         case
         when sum(a.total_play) != 0
         then sum(a.play25_feed_break)/sum(a.total_play)
-        else 0 end as play25FeedBreakRate,
+        else 0
+        end as play25FeedBreakRate,
 
         case
         when sum(a.total_play) != 0
         then sum(a.play_over)/sum(a.total_play)
-        else 0 end as playOverRate,
+        else 0
+        end as playOverRate,
         case
         when sum(a.click) != 0
         then sum(a.convert_material)/sum(a.click)
-        else 0 end as convertRate,
+        else 0
+        end as convertRate,
         sum(a.active) as active,
         sum(a.download_finish) as downloadFinish,
         sum(a.download_start) as downloadStart,
@@ -687,16 +744,19 @@
         case
         when sum(a.active) != 0
         then sum(a.next_day_open)/sum(a.active)
-        else 0 end as nextDayOpenRate,
+        else 0
+        end as nextDayOpenRate,
 
         case
         when sum(a.next_day_open) != 0
         then sum(a.cost)/sum(a.next_day_open)
-        else 0 end as nextDayOpenCost,
+        else 0
+        end as nextDayOpenCost,
 
         case when sum(a.pay_count) != 0
         then sum(a.cost)/sum(a.pay_count)
-        else 0 end
+        else 0
+        end
         as activePayCost,
 
         sum(a.active_pay_amount) as activePayAmount,
@@ -704,79 +764,93 @@
         case
         when sum(a.valid_play) != 0
         then sum(a.cost)/sum(a.valid_play)
-        else 0 end validPlayCost,
+        else 0
+        end validPlayCost,
         sum(a.advanced_creative_coupon_addition) as advancedCreativeCouponAddition,
         sum(a.convert_material) as convertMaterial,
 
         case
         when sum(a.active_pay_amount) != 0
         then sum(a.cost)/sum(a.active_pay_amount)
-        else 0 end as activePayCost,
+        else 0
+        end as activePayCost,
         sum(a.download) as download,
         case
         when sum(a.click) != 0
         then sum(a.cost) / sum(a.click)
-        else 0 end                           as cpc,
+        else 0
+        end                           as cpc,
         sum(a.location_click) as locationClick,
 
         case
         when sum(a.show_material) != 0
         then sum(a.click)/sum(a.show_material)
-        else 0 end as ctr,
+        else 0
+        end as ctr,
 
         case
         when sum(a.show_material) != 0
         then sum(a.cost)/sum(a.show_material)*1000
-        else 0 end cpm,
+        else 0
+        end cpm,
         sum(a.wifi_play_rate) as wifiPlayRate,
         sum(a.like_material) as likeMaterial,
 
         case
         when sum(a.active) != 0
         then sum(a.cost)/sum(a.active)
-        else 0 end activeCost,
+        else 0
+        end activeCost,
 
         case
         when sum(a.game_addiction) != 0
         then sum(a.cost)/sum(a.game_addiction)
-        else 0 end as gameAddictionCost,
+        else 0
+        end as gameAddictionCost,
         sum(a.game_addiction) as gameAddiction,
 
         case
         when sum(a.click) != 0
         then sum(a.active)/sum(a.click)
-        else 0 end as activeRate,
+        else 0
+        end as activeRate,
 
         case
         when sum(a.active) != 0
         then sum(a.game_addiction)/sum(a.active)
-        else 0 end gameAddictionRate,
+        else 0
+        end gameAddictionRate,
         case
         when sum(a.active) != 0
         then sum(a.register)/sum(a.active)
-        else 0 end as activeRegisterRate,
+        else 0
+        end as activeRegisterRate,
 
         case
         when sum(a.download_finish) != 0
         then sum(a.cost)/sum(a.download_finish)
-        else 0 end as downloadFinishCost,
+        else 0
+        end as downloadFinishCost,
 
 
         case
         when sum(a.register) != 0
         then sum(a.cost)/sum(a.register)
-        else 0 end as activeRegisterCost,
+        else 0
+        end as activeRegisterCost,
         sum(a.show_material) as showMaterial,
 
         case
         when sum(a.download_start) != 0
         then sum(a.download_finish)/sum(a.download_start)
-        else 0 end as downloadFinishRate,
+        else 0
+        end as downloadFinishRate,
 
         case
         when sum(a.download_finish) != 0
         then sum(a.install_finish)/sum(a.download_finish)
-        else 0 end as installFinishRate,
+        else 0
+        end as installFinishRate,
         sum(a.coupon) as coupon,
         sum(a.coupon_single_page) as couponSinglePage,
         sum(a.play_over) as playOver,
@@ -784,31 +858,37 @@
         case
         when sum(a.download_start) != 0
         then sum(a.cost)/sum(a.download_start)
-        else 0 end as downloadStartCost,
+        else 0
+        end as downloadStartCost,
         sum(a.message) as message,
         case
         when sum(a.show_material) != 0
         then sum(a.valid_play)/sum(a.show_material)
-        else 0 end as validPlayRate,
+        else 0
+        end as validPlayRate,
 
         case
         when sum(a.valid_play) != 0
         then sum(a.average_play_time_per_play*a.valid_play)/sum(a.valid_play)
-        else 0 end as averagePlayTimePerPlay,
+        else 0
+        end as averagePlayTimePerPlay,
         case
         when sum(a.convert_material) != 0
         then sum(a.cost)/sum(a.convert_material)
-        else 0 end as convertCost,
+        else 0
+        end as convertCost,
 
         case
         when sum(a.install_finish) != 0
         then sum(a.cost)/sum(a.install_finish)
-        else 0 end as installFinishCost,
+        else 0
+        end as installFinishCost,
 
         case
         when sum(a.click) != 0
         then sum(a.download_start)/sum(a.click)
-        else 0 end as downloadStartRate,
+        else 0
+        end as downloadStartRate,
     </sql>
 
     <select id="videoInfoList" resultType="cn.com.ctop.toutiao.modules.report.entity.ByteDanceVideoReportDaily">
@@ -916,7 +996,7 @@
         case
         when sum(a.click) != 0
         then sum(a.cost) / sum(a.click)
-        else 0 end                           as cpc,
+        else 0 end as cpc,
         sum(a.location_click) as locationClick,
 
         case
@@ -1015,7 +1095,8 @@
         from ctop_bytedance_report_material_daily a
         left join ctop_user_allocation b on a.account_id = b.account_id
         left join user_company c on b.user_id = c.user_id
-        left join (select signature,video_url,material_id from ctop_bytedance_video_info group by material_id) d on a.material_id = d.material_id
+        left join (select signature,video_url,material_id from ctop_bytedance_video_info group by material_id) d on
+        a.material_id = d.material_id
         where c.company_id = #{companyId}
         and stat_datetime &gt;= #{startDate}
         and stat_datetime &lt;= #{endDate}
@@ -1026,27 +1107,26 @@
     </select>
 
     <select id="getCompanyIdByAccountId" resultType="string">
-        select
-        c.company_id
-        from
-        ctop_user_allocation b
-        left join user_company c on b.user_id = c.user_id
-        where b.account_id = #{accountId}
-        limit 1
+        select c.company_id
+        from ctop_user_allocation b
+                 left join user_company c on b.user_id = c.user_id
+        where b.account_id = #{accountId} limit 1
     </select>
 
-    <select id="videoInfoListGroupOperator" resultType="cn.com.ctop.toutiao.modules.report.entity.ByteDanceVideoReportDaily">
+    <select id="videoInfoListGroupOperator"
+            resultType="cn.com.ctop.toutiao.modules.report.entity.ByteDanceVideoReportDaily">
         select
         <include refid="selectSql"></include>
         from ctop_bytedance_video_report_daily a
-        left join (select material_id from ctop_material_ascription group by material_id) f on a.signature = f.material_id
+        left join (select material_id from ctop_material_ascription group by material_id) f on a.signature =
+        f.material_id
         where stat_datetime &gt;= #{startDate}
         and stat_datetime &lt;= #{endDate}
         and f.material_id is not null
         and a.account_id in
-            <foreach item="item" index="index" collection="accountIds" open="(" separator="," close=")">
-                #{item}
-            </foreach>
+        <foreach item="item" index="index" collection="accountIds" open="(" separator="," close=")">
+            #{item}
+        </foreach>
         <if test="signature != null and signature != '' ">
             and a.signature = #{signature}
         </if>
@@ -1057,11 +1137,13 @@
 
     </select>
 
-    <select id="videoInfoListGroupOtherRoles" resultType="cn.com.ctop.toutiao.modules.report.entity.ByteDanceVideoReportDaily">
+    <select id="videoInfoListGroupOtherRoles"
+            resultType="cn.com.ctop.toutiao.modules.report.entity.ByteDanceVideoReportDaily">
         select
         <include refid="selectSql"></include>
         from ctop_bytedance_video_report_daily a
-        left join (select material_id from ctop_material_ascription group by material_id) f on a.signature = f.material_id
+        left join (select material_id from ctop_material_ascription group by material_id) f on a.signature =
+        f.material_id
         where stat_datetime &gt;= #{startDate}
         and stat_datetime &lt;= #{endDate}
         and f.material_id is not null
@@ -1079,11 +1161,13 @@
 
     </select>
 
-    <select id="videoInfoListGroupShot" resultType="cn.com.ctop.toutiao.modules.report.entity.ByteDanceVideoReportDaily">
+    <select id="videoInfoListGroupShot"
+            resultType="cn.com.ctop.toutiao.modules.report.entity.ByteDanceVideoReportDaily">
         select
         <include refid="selectSql"></include>
         from ctop_bytedance_video_report_daily a
-        left join (select material_id,clip_id,shot_id,plan_id,plane_id from ctop_material_ascription group by material_id) f on a.signature = f.material_id
+        left join (select material_id,clip_id,shot_id,plan_id,plane_id from ctop_material_ascription group by
+        material_id) f on a.signature = f.material_id
         where stat_datetime &gt;= #{startDate}
         and stat_datetime &lt;= #{endDate}
         and f.material_id is not null
@@ -1104,11 +1188,13 @@
 
     </select>
 
-    <select id="videoInfoListGroupAdmin" resultType="cn.com.ctop.toutiao.modules.report.entity.ByteDanceVideoReportDaily">
+    <select id="videoInfoListGroupAdmin"
+            resultType="cn.com.ctop.toutiao.modules.report.entity.ByteDanceVideoReportDaily">
         select
         <include refid="selectSql"></include>
         from ctop_bytedance_video_report_daily a
-        left join (select material_id,clip_id,shot_id,plan_id,plane_id from ctop_material_ascription group by material_id) f on a.signature = f.material_id
+        left join (select material_id,clip_id,shot_id,plan_id,plane_id from ctop_material_ascription group by
+        material_id) f on a.signature = f.material_id
         where stat_datetime &gt;= #{startDate}
         and stat_datetime &lt;= #{endDate}
         and f.material_id is not null
@@ -1128,11 +1214,13 @@
         </if>
     </select>
 
-    <select id="videoInfoListGroupdesignTeamLeader" resultType="cn.com.ctop.toutiao.modules.report.entity.ByteDanceVideoReportDaily">
+    <select id="videoInfoListGroupdesignTeamLeader"
+            resultType="cn.com.ctop.toutiao.modules.report.entity.ByteDanceVideoReportDaily">
         select
         <include refid="selectSql"></include>
         from ctop_bytedance_video_report_daily a
-        left join (select material_id,clip_id,shot_id,plan_id,plane_id from ctop_material_ascription group by material_id) f on a.signature = f.material_id
+        left join (select material_id,clip_id,shot_id,plan_id,plane_id from ctop_material_ascription group by
+        material_id) f on a.signature = f.material_id
         where stat_datetime &gt;= #{startDate}
         and stat_datetime &lt;= #{endDate}
         and a.company_id = #{companyId}
@@ -1154,11 +1242,13 @@
 
     </select>
 
-    <select id="videoInfoListGroupPlaneAndPlaneLeader" resultType="cn.com.ctop.toutiao.modules.report.entity.ByteDanceVideoReportDaily">
+    <select id="videoInfoListGroupPlaneAndPlaneLeader"
+            resultType="cn.com.ctop.toutiao.modules.report.entity.ByteDanceVideoReportDaily">
         select
         <include refid="selectSql"></include>
         from ctop_bytedance_video_report_daily a
-        left join (select material_id,clip_id,shot_id,plan_id,plane_id from ctop_material_ascription group by material_id) f on a.signature = f.material_id
+        left join (select material_id,clip_id,shot_id,plan_id,plane_id from ctop_material_ascription group by
+        material_id) f on a.signature = f.material_id
         where stat_datetime &gt;= #{startDate}
         and stat_datetime &lt;= #{endDate}
 
@@ -1180,11 +1270,13 @@
 
     </select>
 
-    <select id="videoInfoListGroupPlan" resultType="cn.com.ctop.toutiao.modules.report.entity.ByteDanceVideoReportDaily">
+    <select id="videoInfoListGroupPlan"
+            resultType="cn.com.ctop.toutiao.modules.report.entity.ByteDanceVideoReportDaily">
         select
         <include refid="selectSql"></include>
         from ctop_bytedance_video_report_daily a
-        left join (select material_id,clip_id,shot_id,plan_id,plane_id from ctop_material_ascription group by material_id) f on a.signature = f.material_id
+        left join (select material_id,clip_id,shot_id,plan_id,plane_id from ctop_material_ascription group by
+        material_id) f on a.signature = f.material_id
         where stat_datetime &gt;= #{startDate}
         and stat_datetime &lt;= #{endDate}
         and f.material_id is not null
@@ -1205,11 +1297,13 @@
 
     </select>
 
-    <select id="videoInfoListGroupClip" resultType="cn.com.ctop.toutiao.modules.report.entity.ByteDanceVideoReportDaily">
+    <select id="videoInfoListGroupClip"
+            resultType="cn.com.ctop.toutiao.modules.report.entity.ByteDanceVideoReportDaily">
         select
         <include refid="selectSql"></include>
         from ctop_bytedance_video_report_daily a
-        left join (select material_id,clip_id,shot_id,plan_id,plane_id from ctop_material_ascription group by material_id) f on a.signature = f.material_id
+        left join (select material_id,clip_id,shot_id,plan_id,plane_id from ctop_material_ascription group by
+        material_id) f on a.signature = f.material_id
         where stat_datetime &gt;= #{startDate}
         and stat_datetime &lt;= #{endDate}
         and f.material_id is not null
@@ -1231,13 +1325,10 @@
     </select>
 
     <select id="getAccountIds" resultType="long">
-        select
-        account_id
-        from
-        ctop_bytedance_video_report_daily
-        where
-        signature = #{signature}
-         and company_id = #{companyId}
+        select account_id
+        from ctop_bytedance_video_report_daily
+        where signature = #{signature}
+          and company_id = #{companyId}
     </select>
 
     <select id="getAccountIdsByUserIdAndMediaIds" resultType="long">
@@ -1247,16 +1338,16 @@
         ctop_user_allocation
         where
         project_id in (
-            select
-            project_id
-            from ctop_project_member member
-            left join ctop_project pro on member.project_id = pro.id
-            where member.user_id =#{userId}
-            and pro.media_id in
-            <foreach collection="mediaIds" item="item" separator=","
-                     open="(" close=")">
-                #{item}
-            </foreach>
+        select
+        project_id
+        from ctop_project_member member
+        left join ctop_project pro on member.project_id = pro.id
+        where member.user_id =#{userId}
+        and pro.media_id in
+        <foreach collection="mediaIds" item="item" separator=","
+                 open="(" close=")">
+            #{item}
+        </foreach>
         )
     </select>
 </mapper>

+ 4 - 0
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/service/IByteDanceVideoReportDailyService.java

@@ -31,8 +31,11 @@ public interface IByteDanceVideoReportDailyService extends IService<ByteDanceVid
 
     String getColumnJson(Integer columnType);
 
+    String getColumnJsonByAccountId(Long accountId, Integer columnType);
+
     void saveOrUpdateColumnJson(Integer columnType, String json);
 
+    void saveOrUpdateColumnJsonByAccountId(Long accountId, Integer columnType, String json);
     //excel导出权限
     int videoInfoListTotalExportExcelPermission();
 
@@ -40,4 +43,5 @@ public interface IByteDanceVideoReportDailyService extends IService<ByteDanceVid
 
     void accountVideoMap();
 
+
 }

+ 18 - 2
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/service/impl/ByteDanceVideoReportDailyServiceImpl.java

@@ -572,15 +572,31 @@ public class ByteDanceVideoReportDailyServiceImpl extends ServiceImpl<ByteDanceV
     }
 
     @Override
+    public String getColumnJsonByAccountId(Long accountId, Integer columnType){
+        return byteDanceVideoReportDailyMapper.getJsonByAccountIdAndColumnType(accountId,columnType);
+    }
+
+    @Override
     public void saveOrUpdateColumnJson(Integer columnType, String json){
         LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
         String userId = sysUser.getId();
 
         String jsonObject = byteDanceVideoReportDailyMapper.getJsonByUserIdAndColumnType(columnType, userId);
         if(jsonObject == null){
-            byteDanceVideoReportDailyMapper.insertColumnLoad(json,userId, columnType);
+            byteDanceVideoReportDailyMapper.insertColumnLoad(json,userId, columnType,null);
+        }else{
+            byteDanceVideoReportDailyMapper.updateJsonByUserIdAndType(json,userId,columnType,null);
+        }
+    }
+
+    @Override
+    public void saveOrUpdateColumnJsonByAccountId(Long accountId, Integer columnType, String json){
+
+        String jsonObject = byteDanceVideoReportDailyMapper.getJsonByAccountIdAndColumnType(accountId,columnType);
+        if(jsonObject == null){
+            byteDanceVideoReportDailyMapper.insertColumnLoad(json,null, columnType,accountId);
         }else{
-            byteDanceVideoReportDailyMapper.updateJsonByUserIdAndType(json,userId,columnType);
+            byteDanceVideoReportDailyMapper.updateJsonByUserIdAndType(json,null,columnType,accountId);
         }
     }