Explorar o código

有效视频新逻辑

hcst_sunzhen %!s(int64=5) %!d(string=hai) anos
pai
achega
f9321d2670

+ 130 - 1
jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/service/impl/PerformanceServiceImpl2.java

@@ -73,7 +73,9 @@ public class PerformanceServiceImpl2 extends ServiceImpl<PerformanceMapper, Perf
         //传入时间,获取对应的年份
         Date friday = DateUtils.getFriday(calcDate);
         String effiCalcStart = DateUtils.formatDate(DateUtils.addDay(friday, -14)); //计算有效视频开始的时间
-        log.info("有效视频统计的开始时间为" + effiCalcStart);
+        log.info("有效视频统计的开始时间,同时也是有效视频第一周开始时间为" + effiCalcStart);
+        String effiFirstWeekCalcEnd = DateUtils.formatDate(DateUtils.addDay(friday, -8)); //计算有效视频第一周结束时间
+        log.info("有效视频第一周结束时间为" + effiCalcStart);
         String effiCalcEnd = DateUtils.formatDate(DateUtils.addDay(friday, -1)); //计算有效视频结束的时间
         log.info("有效视频统计的结束时间为" + effiCalcEnd);
         String effiStart = DateUtils.formatDate(DateUtils.addDay(friday, -21)); //有效视频发布开始时间
@@ -241,6 +243,133 @@ public class PerformanceServiceImpl2 extends ServiceImpl<PerformanceMapper, Perf
     //有效视频计算结束
     ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
+
+
+
+
+
+    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+    //新有效视频计算开始
+    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+    //快手有效视频统计
+    private void kuaishouNewEffiVideo(Date calcDate, String effiCalcStart, String effiFirstWeekCalcEnd, String effiCalcEnd, String effiStart, String effiEnd, int thisYear, int thisMonth, int thisQuarter) {
+        log.info("快手有效视频统计开始,统计时间为 " + calcDate);
+        List<EffiVideoDTO> effiList = new ArrayList<>();
+
+        //1.计算第一周(周五-下周周四)所有有消耗得md5
+        List<String> md5List = userEfficientVideoMapMapper.getWeekCostMd5(effiCalcStart, effiFirstWeekCalcEnd);
+        //2.排除第一周之前产生消耗的md5以及14天内消耗<5000的md5
+        for (String md5:md5List){
+            Integer count = userEfficientVideoMapMapper.BeforeWeekCostCount(md5, effiCalcStart);
+            //如果第一周之前就有消耗的话排除
+            if(count>0){
+                continue;
+            }
+            String videoEarlistCostDate = userEfficientVideoMapMapper.getVideoEarlistCostDate(md5);
+            String videoEndCostDate = null;
+            try {
+               videoEndCostDate = DateUtils.formatDate(DateUtils.addDay(videoEarlistCostDate, 13)); //有效视频发布开始时间
+            } catch (ParseException e) {
+                e.printStackTrace();
+            }
+            //如果从产生小号开始时间14天内总消耗<5000,则排除掉
+            BigDecimal videoTotalCost = userEfficientVideoMapMapper.videoTotalCostInDates(md5, videoEarlistCostDate, videoEndCostDate);
+            if( (videoTotalCost.subtract(new BigDecimal("5000"))).compareTo(BigDecimal.ZERO) < 0){
+                continue;
+            }
+            EffiVideoDTO effiVideoDTO = new EffiVideoDTO();
+            effiVideoDTO.setSignature(md5);
+            effiVideoDTO.setCharge(videoTotalCost);
+
+
+
+        }
+
+        //3.和ctop_material_info关联并分配角色
+
+
+
+
+
+
+
+        //获取时间段内所有<快手>的有效视频
+        List<EffiVideoDTO> EffiVideoDTOList = userEfficientVideoMapMapper.getUserVideoMap(effiStart, effiEnd, effiCalcStart, effiCalcEnd);
+
+        for (EffiVideoDTO effiVideoDTO : EffiVideoDTOList) {
+            //判断此视频是否已经在关系表中存在,如果已经存在则说明此视频已经存在,跳过即可
+            //有效视频的逻辑是无论是快手还是头条
+            int signatureCount = userEfficientVideoMapMapper.getEffiVideoCountBySignature(effiVideoDTO.getSignature(), new Integer(2));//1快手 2头条
+            if (signatureCount != 0) {
+                continue;
+            }
+
+            UserEfficientVideoMap shot = new UserEfficientVideoMap();
+            UserEfficientVideoMap plane = new UserEfficientVideoMap();
+            UserEfficientVideoMap plan = new UserEfficientVideoMap();
+            UserEfficientVideoMap clip = new UserEfficientVideoMap();
+
+            //拍摄
+            shot.setUserId(effiVideoDTO.getShotId());
+            shot.setEfficientVideoSignature(effiVideoDTO.getSignature());
+            shot.setQuarter(thisQuarter);
+            shot.setAppType(2); //1头条 2快手
+            shot.setYear(thisYear);
+            shot.setMonth(thisMonth);
+            shot.setCalcDate(calcDate);
+            shot.setRoleId("7bff9afed625aeeabca6bffe3c189183");
+            userEfficientVideoMapMapper.insert(shot);
+
+            //平面
+            plane.setUserId(effiVideoDTO.getPlaneId());
+            plane.setEfficientVideoSignature(effiVideoDTO.getSignature());
+            plane.setQuarter(thisQuarter);
+            plane.setAppType(2); //1头条 2快手
+            plane.setYear(thisYear);
+            plane.setMonth(thisMonth);
+            plane.setCalcDate(calcDate);
+            plane.setRoleId("8dc30cb9810bde89bdc3fa8a85b830b0");
+            userEfficientVideoMapMapper.insert(plane);
+
+            //策划
+            plan.setUserId(effiVideoDTO.getPlanId());
+            plan.setEfficientVideoSignature(effiVideoDTO.getSignature());
+            plan.setQuarter(thisQuarter);
+            plan.setAppType(2); //1头条 2快手
+            plan.setYear(thisYear);
+            plan.setMonth(thisMonth);
+            plan.setCalcDate(calcDate);
+            plan.setRoleId("0214283aa16f943efbb149ea4bb18f18");
+            userEfficientVideoMapMapper.insert(plan);
+
+            //剪辑
+            clip.setUserId(effiVideoDTO.getClipId());
+            clip.setEfficientVideoSignature(effiVideoDTO.getSignature());
+            clip.setQuarter(thisQuarter);
+            clip.setAppType(2); //1头条 2快手
+            clip.setYear(thisYear);
+            clip.setMonth(thisMonth);
+            clip.setCalcDate(calcDate);
+            clip.setRoleId("f38d8d70cf7ec50d5357a749e4dbf8ee");
+            userEfficientVideoMapMapper.insert(clip);
+
+            //快手有效视频同步到有效视频素材库
+            userEfficientVideoMapMapper.updateKuaishouEffiType(1, effiVideoDTO.getSignature());
+
+        }
+        log.info("快手有效视频统计结束,统计时间为 " + calcDate);
+    }
+
+    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+    //新有效视频计算结束
+    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+
+
+
+
+
     ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     //绩效计算开始
     ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

+ 38 - 24
performance-appraisal/src/main/java/cn/com/ctop/userefficientvideomap/mapper/UserEfficientVideoMapMapper.java

@@ -18,39 +18,39 @@ import java.util.List;
 @Component
 public interface UserEfficientVideoMapMapper extends BaseMapper<UserEfficientVideoMap> {
 
-    List<EffiVideoDTO> getUserVideoMap(@Param("startDate")String startDate, @Param("endDate")String endDate, @Param("startCalcDate")String startCalcDate, @Param("endCalcDate")String endCalcDate);
+    List<EffiVideoDTO> getUserVideoMap(@Param("startDate") String startDate, @Param("endDate") String endDate, @Param("startCalcDate") String startCalcDate, @Param("endCalcDate") String endCalcDate);
 
-    int getEffiVideoCountBySignature(@Param("signature")String signature, @Param("appType")Integer appType);
+    int getEffiVideoCountBySignature(@Param("signature") String signature, @Param("appType") Integer appType);
 
     int getEffiVideoCountByUserId(@Param("appType") int appType, @Param("year") int year, @Param("quarter") int quarter, @Param("userId") String userId, @Param("roleId") String roleId);
 
-    int getQuarterMaterialCountByUserId(@Param("roleCode")String roleCode, @Param("startTime")String startTime, @Param("endTime")String endTime, @Param("userId")String userId);
+    int getQuarterMaterialCountByUserId(@Param("roleCode") String roleCode, @Param("startTime") String startTime, @Param("endTime") String endTime, @Param("userId") String userId);
 
-    BigDecimal getTotalCostByClipId(@Param("userId")String userId, @Param("startDate")String startDate, @Param("endDate")String endDate);
+    BigDecimal getTotalCostByClipId(@Param("userId") String userId, @Param("startDate") String startDate, @Param("endDate") String endDate);
 
-    BigDecimal getTotalCostByShotId(@Param("userId")String userId, @Param("startDate")String startDate, @Param("endDate")String endDate);
+    BigDecimal getTotalCostByShotId(@Param("userId") String userId, @Param("startDate") String startDate, @Param("endDate") String endDate);
 
-    BigDecimal getTotalCostByPlanId(@Param("userId")String userId, @Param("startDate")String startDate, @Param("endDate")String endDate);
+    BigDecimal getTotalCostByPlanId(@Param("userId") String userId, @Param("startDate") String startDate, @Param("endDate") String endDate);
 
-    BigDecimal getTotalCostByPlaneId(@Param("userId")String userId, @Param("startDate")String startDate, @Param("endDate")String endDate);
+    BigDecimal getTotalCostByPlaneId(@Param("userId") String userId, @Param("startDate") String startDate, @Param("endDate") String endDate);
 
-    BigDecimal getProjectTotalCostByUserId(@Param("userId")String userId, @Param("startDate")String startDate, @Param("endDate")String endDate);
+    BigDecimal getProjectTotalCostByUserId(@Param("userId") String userId, @Param("startDate") String startDate, @Param("endDate") String endDate);
 
-    List<ProjectDTO> getProjectsByUserId(@Param("userId")String userId);
+    List<ProjectDTO> getProjectsByUserId(@Param("userId") String userId);
 
-    int getPlaneCountByProjectId(@Param("projectId")Long projectId);
+    int getPlaneCountByProjectId(@Param("projectId") Long projectId);
 
-    int getPlaneCountByUserId(@Param("userId")String userId);
+    int getPlaneCountByUserId(@Param("userId") String userId);
 
-    List<DesignMaterialInfo> designMaterialInfoList(@Param("roleCode")String roleCode, @Param("userId")String userId, @Param("startDate")String startDate, @Param("endDate")String endDate);
+    List<DesignMaterialInfo> designMaterialInfoList(@Param("roleCode") String roleCode, @Param("userId") String userId, @Param("startDate") String startDate, @Param("endDate") String endDate);
 
-    List<DesignMaterialInfo> getMaterialAccountInfoByMaterialId(@Param("materialId")String materialId, @Param("startDate")String startDate, @Param("endDate")String endDate);
+    List<DesignMaterialInfo> getMaterialAccountInfoByMaterialId(@Param("materialId") String materialId, @Param("startDate") String startDate, @Param("endDate") String endDate);
 
-    List<ProjectDTO> getProjects(@Param("mediaId")String mediaId);
+    List<ProjectDTO> getProjects(@Param("mediaId") String mediaId);
 
-    BigDecimal getProjectQuarterCostById(@Param("startDate")String startDate, @Param("endDate")String endDate, @Param("projectId")Long projectId);
+    BigDecimal getProjectQuarterCostById(@Param("startDate") String startDate, @Param("endDate") String endDate, @Param("projectId") Long projectId);
 
-    List<UserDto2> getPlaneByProjectId(@Param("projectId")Long projectId);
+    List<UserDto2> getPlaneByProjectId(@Param("projectId") Long projectId);
 
     List<UserDto2> getKuaishouDesignLeaderList();
 
@@ -68,7 +68,7 @@ public interface UserEfficientVideoMapMapper extends BaseMapper<UserEfficientVid
 
     List<UserDto2> getToutiaoDesignLeaderList();
 
-    List<String> getClip(@Param("depId")String depId);
+    List<String> getClip(@Param("depId") String depId);
 
     BigDecimal getClipQuarterCost(@Param("appType") int appType, @Param("quarter") int quarter, @Param("year") int year, @Param("userId") String userId);
 
@@ -108,28 +108,42 @@ public interface UserEfficientVideoMapMapper extends BaseMapper<UserEfficientVid
     void updateToutiaoEffiType(@Param("toutiaoEffiType") Integer toutiaoEffiType, @Param("signature") String signature);
 
     List<UserDto2> getKuaishouDepartUserInfo();
+
     List<UserDto2> getKuaishouDepartAllUserInfo();
+
     List<UserDto2> getToutiaoDepartUserInfo();
+
     List<UserDto2> getToutiaoDepartAllUserInfo();
 
     //根据天数的区间获取userId获取有效视频数量
     Integer getEffiVideoCountByCalcDate(@Param("startDate") String startDate, @Param("endDate") String endDate, @Param("roleId") String roleId, @Param("userId") String userId, @Param("appType") Integer appType);
 
-    List<MaterialInfo> getEffiVideoList(@Param("appType")Integer appType, @Param("year")Integer year, @Param("quarter")Integer quarter, @Param("userId")String userId);
+    List<MaterialInfo> getEffiVideoList(@Param("appType") Integer appType, @Param("year") Integer year, @Param("quarter") Integer quarter, @Param("userId") String userId);
 
     List<UserDto2> getKuaishouYunyingDepartUserInfo();
 
     List<UserDto2> getToutiaoYunyingDepartUserInfo();
+
     //获取快手单个优化师当前账户下的总消耗
-    BigDecimal getKuaishouYunyingTotalCost(@Param("userId")String userId, @Param("appType")Integer appType, @Param("startDate")String startDate, @Param("endDate")String endDate);
+    BigDecimal getKuaishouYunyingTotalCost(@Param("userId") String userId, @Param("appType") Integer appType, @Param("startDate") String startDate, @Param("endDate") String endDate);
+
     //获取快手单个优化师当前账户下的总消耗
-    BigDecimal getToutiaoYunyingTotalCost(@Param("userId")String userId, @Param("appType")Integer appType, @Param("startDate")String startDate, @Param("endDate")String endDate);
+    BigDecimal getToutiaoYunyingTotalCost(@Param("userId") String userId, @Param("appType") Integer appType, @Param("startDate") String startDate, @Param("endDate") String endDate);
+
     //获取快手单个优化师其下所有的账户下当前的消耗
-    List<AccountDTO> getKuaishouAccountTotalCost(@Param("userId")String userId, @Param("appType")Integer appType, @Param("startDate")String startDate, @Param("endDate")String endDate);
+    List<AccountDTO> getKuaishouAccountTotalCost(@Param("userId") String userId, @Param("appType") Integer appType, @Param("startDate") String startDate, @Param("endDate") String endDate);
+
     //获取头条单个优化师其下所有的账户下当前的消耗
-    List<AccountDTO> getToutiaoAccountTotalCost(@Param("userId")String userId, @Param("appType")Integer appType, @Param("startDate")String startDate, @Param("endDate")String endDate);
+    List<AccountDTO> getToutiaoAccountTotalCost(@Param("userId") String userId, @Param("appType") Integer appType, @Param("startDate") String startDate, @Param("endDate") String endDate);
 
-    List<MaterialInfo> getEffiWeekVideoList(@Param("appType")Integer appType, @Param("startDate")String startDate, @Param("endDate")String endDate, @Param("userId")String userId);
+    List<MaterialInfo> getEffiWeekVideoList(@Param("appType") Integer appType, @Param("startDate") String startDate, @Param("endDate") String endDate, @Param("userId") String userId);
 
-}
+    List<String> getWeekCostMd5(@Param("startDate") String startDate, @Param("endDate") String endDate);
+
+    Integer BeforeWeekCostCount(@Param("md5") String md5, @Param("date") String date);
 
+    String getVideoEarlistCostDate(@Param("md5")String md5);
+
+    BigDecimal videoTotalCostInDates(@Param("md5")String md5, @Param("startDate")String startDate, @Param("endDate")String endDate);
+
+}

+ 43 - 0
performance-appraisal/src/main/java/cn/com/ctop/userefficientvideomap/mapper/xml/UserEfficientVideoMapMapper.xml

@@ -939,4 +939,47 @@
         m.calc_date &gt;= #{startDate}
     </select>
 
+    <!-- 获取有效视频第一周所有产生消耗的视频的md5 -->
+    <select id="getWeekCostMd5" resultType="string">
+        select
+        signature
+        from ctop_kuaishou_report_daily_creative
+        where
+        DATE_FORMAT(stat_date,'%Y-%m-%d') &gt;= #{startDate}
+        and DATE_FORMAT(stat_date,'%Y-%m-%d') &lt;= #{endDate}
+        and signature is not null
+        group by signature
+    </select>
+
+    <!-- 获取有效视频第一周开始时间之前消耗次数 -->
+    <select id="BeforeWeekCostCount" resultType="integer">
+        select
+        count(1)
+        from ctop_kuaishou_report_daily_creative
+        where
+        signature = #{md5} and
+        DATE_FORMAT(stat_date,'%Y-%m-%d') &lt; #{date}
+    </select>
+
+    <!-- 获取视频最早产生消耗的日期 -->
+    <select id="getVideoEarlistCostDate" resultType="string">
+        select
+        DATE_FORMAT(stat_date,'%Y-%m-%d')
+        from ctop_kuaishou_report_daily_creative
+        where
+        signature = #{md5}
+        order by stat_date asc limit 1
+    </select>
+
+    <!-- 获取视频在时间范围内的总消耗 -->
+    <select id="videoTotalCostInDates" resultType="java.math.BigDecimal">
+        select
+        sum(charge)
+        from ctop_kuaishou_report_daily_creative
+        where
+        signature = #{md5}
+        and DATE_FORMAT(stat_date,'%Y-%m-%d') &lt;= #{endDate}
+        and DATE_FORMAT(stat_date, '%Y-%m-%d') &gt;= #{startDate}
+    </select>
+
 </mapper>