Browse Source

Merge branch 'V2.0.1' into test

zhaoxian 3 years ago
parent
commit
157a951728

+ 3 - 2
jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/settlement/service/serviceImpl/SettlementFileInfoServiceImpl.java

@@ -186,8 +186,9 @@ public class SettlementFileInfoServiceImpl extends ServiceImpl<SettlementFileInf
 
                 BeanUtils.copyProperties(settlementFileInfo,settlement,SettlementUtil.getNullPropertyNames(settlementFileInfo));
                 settlementFileInfoMapper.insert(settlement);
-                return Result.successMsg("账户截图上传成功",null);
+                //log.info("上传截图======{}====",settlement);
             }
+            return Result.successMsg("账户截图上传成功",null);
         }catch (Exception e){
             e.printStackTrace();
         }
@@ -196,7 +197,7 @@ public class SettlementFileInfoServiceImpl extends ServiceImpl<SettlementFileInf
 
     @Autowired
     private IReportSettlementService reportSettlementService;
-    @Autowired
+    @Resource
     private ReportSettlementMapper reportSettlementMapper;
 
     /**

+ 17 - 19
jeecg-boot-material-view/src/main/java/org/jeecg/ctop/material/mapper/ManagerSaleValueMapper.java

@@ -30,51 +30,49 @@ public interface ManagerSaleValueMapper extends BaseMapper<ManagerSaleValue> {
 
     List<String> querySaleDirctorItsTeamMember(@Param("userId") String userId);
 
-    List<Long> getCompanyAccountIds(@Param("companyId") String companyId, @Param("mediaId") String mediaId);
+    List<Long> querySalesDirectorAccountIds(@Param("companyId") String companyId, @Param("mediaId") String mediaId, @Param("userIds") List<String> saleTeaMber);
 
     /**
      * -----------------------------------------------------
      */
 
-    JSONObject queryTtTodayCharge(@Param("statDay") String statDay, @Param("hour") Integer hour, @Param("accountIds") List<Long> accountIds);
+    JSONObject queryTtTodayCharge(@Param("statDay") String statDay, @Param("hour") Integer hour, @Param("accountIds") List<Long> accountIds, @Param("companyId") String companyId);
 
-    String queryTtManydaysTotalCharge(@Param("startDay") String startDay, @Param("endDay") String endDay, @Param("accountIds") List<Long> accountIds);
+    String queryTtManydaysTotalCharge(@Param("startDay") String startDay, @Param("endDay") String endDay, @Param("accountIds") List<Long> accountIds, @Param("companyId") String companyId);
 
-    JSONObject queryTtRealCharged(@Param("lastMonthFirstday") String lastMonthFirstday, @Param("monthFirstday") String monthFirstday, @Param("statDay") String statDay, @Param("accountIds") List<Long> accountIds);
+    JSONObject queryTtRealCharged(@Param("lastMonthFirstday") String lastMonthFirstday, @Param("monthFirstday") String monthFirstday, @Param("statDay") String statDay, @Param("accountIds") List<Long> accountIds, @Param("companyId") String companyId);
 
 
-    JSONObject queryKsTodayCharge(@Param("statDay") String statDay, @Param("hour") Integer hour, @Param("accountIds") List<Long> accountIds);
+    JSONObject queryKsTodayCharge(@Param("statDay") String statDay, @Param("hour") Integer hour, @Param("accountIds") List<Long> accountIds, @Param("companyId") String companyId);
 
-    String queryKsManydaysTotalCharge(@Param("startDay") String startDay, @Param("endDay") String endDay, @Param("accountIds") List<Long> accountIds);
+    String queryKsManydaysTotalCharge(@Param("startDay") String startDay, @Param("endDay") String endDay, @Param("accountIds") List<Long> accountIds, @Param("companyId") String companyId);
 
-    JSONObject queryKsRealCharged(@Param("lastMonthFirstday") String lastMonthFirstday, @Param("monthFirstday") String monthFirstday, @Param("statDay") String statDay, @Param("accountIds") List<Long> accountIds);
+    JSONObject queryKsRealCharged(@Param("lastMonthFirstday") String lastMonthFirstday, @Param("monthFirstday") String monthFirstday, @Param("statDay") String statDay, @Param("accountIds") List<Long> accountIds, @Param("companyId") String companyId);
 
     Long getWeekly(@Param("userId") String userId, @Param("companyId") String companyId, @Param("mediaId") String mediaId);
 
     Long getMonthly(@Param("userId") String userId, @Param("companyId") String companyId, @Param("mediaId") String mediaId);
 
-    List<Long> querySalesDirectorAccountIds(@Param("companyId") String companyId, @Param("mediaId") String mediaId, @Param("userIds") List<String> saleTeaMber);
-
-    List<JSONObject> queryKsHourList(@Param("statDay") String statDay, @Param("accountIds") List<Long> accountIds);
+    List<JSONObject> queryKsHourList(@Param("statDay") String statDay, @Param("accountIds") List<Long> accountIds, @Param("companyId") String companyId);
 
-    List<JSONObject> queryTtHourList(@Param("statDay") String statDay, @Param("accountIds") List<Long> accountIds);
+    List<JSONObject> queryTtHourList(@Param("statDay") String statDay, @Param("accountIds") List<Long> accountIds, @Param("companyId") String companyId);
 
-    JSONObject queryTtManydaysChargeAndRoi(@Param("startTime") String startTime, @Param("endTime") String endTime, @Param("lastTimeStart") String lastTimeStart, @Param("lastTimeEnd") String lastTimeEnd, @Param("accountIds") List<Long> accountIds);
+    JSONObject queryTtManydaysChargeAndRoi(@Param("startTime") String startTime, @Param("endTime") String endTime, @Param("lastTimeStart") String lastTimeStart, @Param("lastTimeEnd") String lastTimeEnd, @Param("accountIds") List<Long> accountIds, @Param("companyId") String companyId);
 
-    List<JSONObject> queryTtManydaysCharge(@Param("startTime") String startTime, @Param("endTime") String endTime, @Param("accountIds") List<Long> accountIds);
+    List<JSONObject> queryTtManydaysCharge(@Param("startTime") String startTime, @Param("endTime") String endTime, @Param("accountIds") List<Long> accountIds, @Param("companyId") String companyId);
 
-    JSONObject queryKsManydaysChargeAndRoi(@Param("startTime") String startTime, @Param("endTime") String endTime, @Param("lastTimeStart") String lastTimeStart, @Param("lastTimeEnd") String lastTimeEnd, @Param("accountIds") List<Long> accountIds);
+    JSONObject queryKsManydaysChargeAndRoi(@Param("startTime") String startTime, @Param("endTime") String endTime, @Param("lastTimeStart") String lastTimeStart, @Param("lastTimeEnd") String lastTimeEnd, @Param("accountIds") List<Long> accountIds, @Param("companyId") String companyId);
 
-    List<JSONObject> queryKsManydaysCharge(@Param("startTime") String startTime, @Param("endTime") String endTime, @Param("accountIds") List<Long> accountIds);
+    List<JSONObject> queryKsManydaysCharge(@Param("startTime") String startTime, @Param("endTime") String endTime, @Param("accountIds") List<Long> accountIds, @Param("companyId") String companyId);
 
     List<Long> querySalesDirectorProjectIds(@Param("companyId") String companyId, @Param("mediaId") String mediaId, @Param("userIds") List<String> saleTeaMber);
 
-    Long queryKsHourProjectTopTotal(@Param("projectIds") List<Long> projectIds, @Param("startTime") String startTime, @Param("endTime") String endTime);
+    Long queryKsHourProjectTopTotal(@Param("accountIds") List<Long> accountIds, @Param("startTime") String startTime, @Param("endTime") String endTime, @Param("companyId") String companyId);
 
-    List<JSONObject> queryKsHourProjectTop(@Param("projectIds") List<Long> projectIds, @Param("startTime") String startTime, @Param("endTime") String endTime, @Param("days") Long days, @Param("hour") Integer hour );
+    List<JSONObject> queryKsHourProjectTop(@Param("accountIds") List<Long> accountIds, @Param("startTime") String startTime, @Param("endTime") String endTime, @Param("days") Long days, @Param("hour") Integer hour, @Param("companyId") String companyId);
 
-    Long queryTtHourProjectTopTotal(@Param("projectIds") List<Long> projectIds, @Param("startTime") String startTime, @Param("endTime") String endTime);
+    Long queryTtHourProjectTopTotal(@Param("accountIds") List<Long> accountIds, @Param("startTime") String startTime, @Param("endTime") String endTime, @Param("companyId") String companyId);
 
-    List<JSONObject> queryTtHourProjectTop(@Param("projectIds") List<Long> projectIds, @Param("startTime") String startTime, @Param("endTime") String endTime, @Param("days") Long days, @Param("hour") Integer hour );
+    List<JSONObject> queryTtHourProjectTop(@Param("accountIds") List<Long> accountIds, @Param("startTime") String startTime, @Param("endTime") String endTime, @Param("days") Long days, @Param("hour") Integer hour, @Param("companyId") String companyId);
 
 }

+ 281 - 231
jeecg-boot-material-view/src/main/java/org/jeecg/ctop/material/mapper/xml/ManagerSaleValueMapper.xml

@@ -34,48 +34,69 @@
         where manage_id = #{userId}
     </select>
 
-    <select id="getCompanyAccountIds" resultType="Long">
-        SELECT t1.account_id
-        FROM `jeecg-boot`.ctop_user_allocation t1
-        LEFT JOIN `jeecg-boot`.user_company t2 ON t1.user_id = t2.user_id
-        WHERE t2.company_id = #{companyId}
+    <select id="querySalesDirectorAccountIds" resultType="Long">
+        SELECT
+        account_id
+        FROM
+        `jeecg-boot`.ctop_user_allocation
+        WHERE
+        project_id IN (
+        SELECT DISTINCT
+        id
+        FROM `jeecg-boot`.ctop_project
+        WHERE company_id = #{companyId}
         <if test='mediaId ==2'>
             AND (media_id = 2 or media_id = 4)
         </if>
         <if test='mediaId ==1'>
             AND (media_id = 1 or media_id = 3)
         </if>
-        and t1.account_status = 0
-        GROUP BY t1.account_id
+        <if test="userIds !=null and userIds.size()>0">
+            AND sale_id IN
+            <foreach collection="userIds" item="id" separator=","
+                     open="(" close=")">
+                #{id}
+            </foreach>
+        </if>
+        )
+        GROUP BY
+        account_id
     </select>
 
-
     <select id="queryKsTodayCharge" resultType="com.alibaba.fastjson.JSONObject">
         SELECT IFNULL(t.charge, 0.00) as 'totalCharge', CONCAT(
         CAST(IFNULL(ROUND((t.charge - y.charge) / y.charge * 100, 2), 0) as CHAR), '%') as 'chargeRoi'
         FROM (
         SELECT sum(charge) as 'charge'
         FROM application.kuaishou_account_report_hourly_dw
-        WHERE account_id in
-        <foreach collection="accountIds" item="id" separator=","
-                 open="(" close=")">
-            #{id}
-        </foreach>
-        and stat_date = DATE_FORMAT(#{statDay}, '%Y%m%d')
-        <if test="hour !=null">
-            AND hour &lt;= #{hour}
-        </if>
+        <where>
+            <if test="accountIds !=null and accountIds.size()>0">
+                AND account_id in
+                <foreach collection="accountIds" item="id" separator=","
+                         open="(" close=")">
+                    #{id}
+                </foreach>
+            </if>
+            and company_id = #{companyId}
+            and stat_date = DATE_FORMAT(#{statDay}, '%Y%m%d')
+            <if test="hour !=null">
+                AND hour &lt;= #{hour}
+            </if>
+        </where>
         ) t
         LEFT JOIN
         (
         SELECT sum(charge) as 'charge'
         FROM application.kuaishou_account_report_hourly_dw
-        WHERE account_id in
-        <foreach collection="accountIds" item="id" separator=","
-                 open="(" close=")">
-            #{id}
-        </foreach>
-        and stat_date = DATE_FORMAT(DATE_ADD(#{statDay},INTERVAL -1 day), '%Y%m%d')
+        where stat_date = DATE_FORMAT(DATE_ADD(#{statDay},INTERVAL -1 day), '%Y%m%d')
+        and company_id = #{companyId}
+        <if test="accountIds !=null and accountIds.size()>0">
+            AND account_id in
+            <foreach collection="accountIds" item="id" separator=","
+                     open="(" close=")">
+                #{id}
+            </foreach>
+        </if>
         <if test="hour !=null">
             AND hour &lt;= #{hour}
         </if>
@@ -88,12 +109,16 @@
         FROM (
         SELECT sum(cost) as 'charge'
         FROM application.bytedance_advertiser_report_hourly_dw
-        WHERE account_id in
-        <foreach collection="accountIds" item="id" separator=","
-                 open="(" close=")">
-            #{id}
-        </foreach>
-        and stat_datetime = DATE_FORMAT(#{statDay}, '%Y%m%d')
+        where stat_datetime = DATE_FORMAT(#{statDay}, '%Y%m%d')
+        and company_id = #{companyId}
+        <if test="accountIds !=null and accountIds.size()>0">
+            and account_id in
+            <foreach collection="accountIds" item="id" separator=","
+                     open="(" close=")">
+                #{id}
+            </foreach>
+        </if>
+
         <if test="hour !=null">
             AND hour &lt;= #{hour}
         </if>
@@ -102,12 +127,14 @@
         (
         SELECT sum(cost) as 'charge'
         FROM application.bytedance_advertiser_report_hourly_dw
-        WHERE account_id in
-        <foreach collection="accountIds" item="id" separator=","
-                 open="(" close=")">
-            #{id}
-        </foreach>
-        and stat_datetime = DATE_FORMAT(DATE_ADD(#{statDay},INTERVAL -1 day), '%Y%m%d')
+        WHERE stat_datetime = DATE_FORMAT(DATE_ADD(#{statDay},INTERVAL -1 day), '%Y%m%d')
+        <if test="accountIds !=null and accountIds.size()>0">
+            and account_id in
+            <foreach collection="accountIds" item="id" separator=","
+                     open="(" close=")">
+                #{id}
+            </foreach>
+        </if>
         <if test="hour !=null">
             AND hour &lt;= #{hour}
         </if>
@@ -116,54 +143,68 @@
 
     <select id="queryTtManydaysTotalCharge" resultType="String">
         SELECT IFNULL(sum(cost), 0.00)
-        FROM application.bytedance_advertiser_report_daily_dw
-        WHERE account_id in
-        <foreach collection="accountIds" item="id" separator=","
-                 open="(" close=")">
-            #{id}
-        </foreach>
-        and stat_datetime >= DATE_FORMAT(#{startDay}, '%Y%m%d')
-        and stat_datetime &lt; DATE_FORMAT(#{endDay}, '%Y%m%d')
+        FROM application.bytedance_advertiser_report_hourly_dw
+        WHERE stat_datetime >= DATE_FORMAT(#{startDay}, '%Y%m%d')
+        and stat_datetime &lt;= DATE_FORMAT(#{endDay}, '%Y%m%d')
+        and company_id = #{companyId}
+        <if test="accountIds !=null and accountIds.size()>0">
+            and account_id in
+            <foreach collection="accountIds" item="id" separator=","
+                     open="(" close=")">
+                #{id}
+            </foreach>
+        </if>
     </select>
 
     <select id="queryTtManydaysCharge" resultType="com.alibaba.fastjson.JSONObject">
         SELECT DATE_FORMAT(stat_datetime,'%Y-%m-%d') as 'statDate', IFNULL(sum(cost), 0.00) as 'charge'
-        FROM application.bytedance_advertiser_report_daily_dw
-        WHERE account_id in
-        <foreach collection="accountIds" item="id" separator=","
-                 open="(" close=")">
-            #{id}
-        </foreach>
-        and stat_datetime >= DATE_FORMAT(#{startTime}, '%Y%m%d')
+        FROM application.bytedance_advertiser_report_hourly_dw
+        WHERE stat_datetime >= DATE_FORMAT(#{startTime}, '%Y%m%d')
         and stat_datetime &lt;= DATE_FORMAT(#{endTime}, '%Y%m%d')
+        and company_id = #{companyId}
+        <if test="accountIds !=null and accountIds.size()>0">
+            and account_id in
+            <foreach collection="accountIds" item="id" separator=","
+                     open="(" close=")">
+                #{id}
+            </foreach>
+        </if>
         GROUP BY stat_datetime
         order by stat_datetime
     </select>
 
     <select id="queryKsManydaysCharge" resultType="com.alibaba.fastjson.JSONObject">
         SELECT DATE_FORMAT(stat_date,'%Y-%m-%d') as 'statDate', IFNULL(sum(charge), 0.00) as 'charge'
-        FROM application.kuaishou_account_report_daily_dw
-        WHERE account_id in
-        <foreach collection="accountIds" item="id" separator=","
-                 open="(" close=")">
-            #{id}
-        </foreach>
-        and stat_date >= DATE_FORMAT(#{startTime}, '%Y%m%d')
+        FROM application.kuaishou_account_report_hourly_dw
+        WHERE
+        stat_date >= DATE_FORMAT(#{startTime}, '%Y%m%d')
         and stat_date &lt;= DATE_FORMAT(#{endTime}, '%Y%m%d')
+        and company_id = #{companyId}
+        <if test="accountIds !=null and accountIds.size()>0">
+            and account_id in
+            <foreach collection="accountIds" item="id" separator=","
+                     open="(" close=")">
+                #{id}
+            </foreach>
+        </if>
         GROUP BY stat_date
         order by stat_date
     </select>
 
     <select id="queryKsManydaysTotalCharge" resultType="String">
         SELECT IFNULL(sum(charge), 0.00)
-        FROM application.kuaishou_account_report_daily_dw
-        WHERE account_id in
-        <foreach collection="accountIds" item="id" separator=","
-                 open="(" close=")">
-            #{id}
-        </foreach>
-        and stat_date >= DATE_FORMAT(#{startDay}, '%Y%m%d')
-        and stat_date &lt; DATE_FORMAT(#{endDay}, '%Y%m%d')
+        FROM application.kuaishou_account_report_hourly_dw
+        WHERE
+        stat_date >= DATE_FORMAT(#{startDay}, '%Y%m%d')
+        and stat_date &lt;= DATE_FORMAT(#{endDay}, '%Y%m%d')
+        and company_id = #{companyId}
+        <if test="accountIds !=null and accountIds.size()>0">
+            and account_id in
+            <foreach collection="accountIds" item="id" separator=","
+                     open="(" close=")">
+                #{id}
+            </foreach>
+        </if>
     </select>
 
     <select id="queryKsRealCharged" resultType="com.alibaba.fastjson.JSONObject">
@@ -177,28 +218,33 @@
         IFNULL( sum( real_charged_in_yuan ), 0.00 ) AS 'realCharged'
         FROM
         application.app_kuaishou_agent_report_d
-        WHERE
-        account_id IN
-        <foreach collection="accountIds" item="id" separator=","
-                 open="(" close=")">
-            #{id}
-        </foreach>
-        AND stat_date >= DATE_FORMAT( #{monthFirstday}, '%Y%m%d' )
+        WHERE stat_date >= DATE_FORMAT( #{monthFirstday}, '%Y%m%d' )
         AND stat_date &lt;= DATE_FORMAT( #{statDay}, '%Y%m%d' )
+        and company_id = #{companyId}
+        <if test="accountIds !=null and accountIds.size()>0">
+            AND account_id IN
+            <foreach collection="accountIds" item="id" separator=","
+                     open="(" close=")">
+                #{id}
+            </foreach>
+        </if>
         ) thisMonth
         LEFT JOIN (
         SELECT
         IFNULL( sum( real_charged_in_yuan ), 0.00 ) AS 'realCharged'
         FROM
         application.app_kuaishou_agent_report_d
-        WHERE
-        account_id IN
-        <foreach collection="accountIds" item="id" separator=","
-                 open="(" close=")">
-            #{id}
-        </foreach>
-        AND stat_date >= DATE_FORMAT(#{lastMonthFirstday}, '%Y%m%d' )
+        WHERE stat_date >= DATE_FORMAT(#{lastMonthFirstday}, '%Y%m%d' )
         AND stat_date &lt; DATE_FORMAT(#{monthFirstday}, '%Y%m%d' )
+        and company_id = #{companyId}
+        <if test="accountIds !=null and accountIds.size()>0">
+            AND
+            account_id IN
+            <foreach collection="accountIds" item="id" separator=","
+                     open="(" close=")">
+                #{id}
+            </foreach>
+        </if>
         ) lastMonth ON 1=1
     </select>
 
@@ -213,28 +259,32 @@
         IFNULL( sum( cash_cost ), 0.00 ) AS 'realCharged'
         FROM
         application.app_bytedance_agent_report_d
-        WHERE
-        account_id IN
-        <foreach collection="accountIds" item="id" separator=","
-                 open="(" close=")">
-            #{id}
-        </foreach>
-        AND stat_datetime >= DATE_FORMAT( #{monthFirstday}, '%Y%m%d' )
+        WHERE stat_datetime >= DATE_FORMAT( #{monthFirstday}, '%Y%m%d' )
         AND stat_datetime &lt;= DATE_FORMAT( #{statDay}, '%Y%m%d' )
+        and company_id = #{companyId}
+        <if test="accountIds !=null and accountIds.size()>0">
+            AND
+            account_id IN
+            <foreach collection="accountIds" item="id" separator=","
+                     open="(" close=")">
+                #{id}
+            </foreach>
+        </if>
         ) thisMonth
         LEFT JOIN (
         SELECT
         IFNULL( sum( cash_cost ), 0.00 ) AS 'realCharged'
         FROM
         application.app_bytedance_agent_report_d
-        WHERE
-        account_id IN
-        <foreach collection="accountIds" item="id" separator=","
-                 open="(" close=")">
-            #{id}
-        </foreach>
-        AND stat_datetime >= DATE_FORMAT(#{lastMonthFirstday}, '%Y%m%d' )
+        WHERE stat_datetime >= DATE_FORMAT(#{lastMonthFirstday}, '%Y%m%d' )
         AND stat_datetime &lt; DATE_FORMAT(#{monthFirstday}, '%Y%m%d' )
+        <if test="accountIds !=null and accountIds.size()>0">
+            AND account_id IN
+            <foreach collection="accountIds" item="id" separator=","
+                     open="(" close=")">
+                #{id}
+            </foreach>
+        </if>
         ) lastMonth ON 1=1
     </select>
 
@@ -254,38 +304,6 @@
           AND company_id = #{companyId}
     </select>
 
-    <select id="querySalesDirectorAccountIds" resultType="Long">
-        SELECT
-        t1.account_id
-        FROM
-        `jeecg-boot`.ctop_user_allocation t1
-        LEFT JOIN `jeecg-boot`.user_company t2 ON t1.user_id = t2.user_id
-        WHERE
-        t1.account_status = 0
-        AND t2.company_id = #{companyId}
-        AND project_id IN (
-        SELECT DISTINCT
-        t1.project_id AS projectId
-        FROM
-        `jeecg-boot`.ctop_project_member t1
-        LEFT JOIN `jeecg-boot`.ctop_project t2 ON t1.project_id = t2.id
-        WHERE t1.user_id IN
-        <foreach collection="userIds" item="id" separator=","
-                 open="(" close=")">
-            #{id}
-        </foreach>
-        <if test='mediaId ==2'>
-            AND (t2.media_id = 2 or t2.media_id = 4)
-        </if>
-        <if test='mediaId ==1'>
-            AND (t2.media_id = 1 or t2.media_id = 3)
-        </if>
-        AND t1.project_name IS NOT NULL
-        AND t1.project_name != ''
-        )
-        GROUP BY
-        t1.account_id
-    </select>
 
     <select id="querySalesDirectorProjectIds" resultType="Long">
         SELECT DISTINCT
@@ -315,12 +333,15 @@
     <select id="queryKsHourList" resultType="com.alibaba.fastjson.JSONObject">
         SELECT hour,sum(charge) as 'charge'
         FROM application.kuaishou_account_report_hourly_dw
-        WHERE account_id in
-        <foreach collection="accountIds" item="id" separator=","
-                 open="(" close=")">
-            #{id}
-        </foreach>
-        and stat_date = DATE_FORMAT(#{statDay}, '%Y%m%d' )
+        WHERE stat_date = DATE_FORMAT(#{statDay}, '%Y%m%d' )
+        and company_id = #{companyId}
+        <if test="accountIds !=null and accountIds.size()>0">
+            AND account_id in
+            <foreach collection="accountIds" item="id" separator=","
+                     open="(" close=")">
+                #{id}
+            </foreach>
+        </if>
         GROUP BY hour
         ORDER BY hour
     </select>
@@ -328,12 +349,15 @@
     <select id="queryTtHourList" resultType="com.alibaba.fastjson.JSONObject">
         SELECT hour,sum(cost) as 'charge'
         FROM application.bytedance_advertiser_report_hourly_dw
-        WHERE account_id in
-        <foreach collection="accountIds" item="id" separator=","
-                 open="(" close=")">
-            #{id}
-        </foreach>
-        and stat_datetime = DATE_FORMAT(#{statDay}, '%Y%m%d' )
+        WHERE stat_datetime = DATE_FORMAT(#{statDay}, '%Y%m%d' )
+        and company_id = #{companyId}
+        <if test="accountIds !=null and accountIds.size()>0">
+            AND account_id in
+            <foreach collection="accountIds" item="id" separator=","
+                     open="(" close=")">
+                #{id}
+            </foreach>
+        </if>
         GROUP BY hour
         ORDER BY hour
     </select>
@@ -349,29 +373,33 @@
         SELECT
         IFNULL( sum(cost), 0.00 ) AS 'charge'
         FROM
-        application.bytedance_advertiser_report_daily_dw
-        WHERE
-        account_id IN
-        <foreach collection="accountIds" item="id" separator=","
-                 open="(" close=")">
-            #{id}
-        </foreach>
-        AND stat_datetime >= DATE_FORMAT(#{startTime}, '%Y%m%d' )
+        application.bytedance_advertiser_report_hourly_dw
+        WHERE stat_datetime >= DATE_FORMAT(#{startTime}, '%Y%m%d' )
         AND stat_datetime &lt;= DATE_FORMAT(#{endTime}, '%Y%m%d' )
+        and company_id = #{companyId}
+        <if test="accountIds !=null and accountIds.size()>0">
+            AND account_id IN
+            <foreach collection="accountIds" item="id" separator=","
+                     open="(" close=")">
+                #{id}
+            </foreach>
+        </if>
         ) this
         LEFT JOIN (
         SELECT
         IFNULL( sum(cost), 0.00 ) AS 'charge'
         FROM
-        application.bytedance_advertiser_report_daily_dw
-        WHERE
-        account_id IN
-        <foreach collection="accountIds" item="id" separator=","
-                 open="(" close=")">
-            #{id}
-        </foreach>
-        AND stat_datetime >= DATE_FORMAT( #{lastTimeStart}, '%Y%m%d' )
+        application.bytedance_advertiser_report_hourly_dw
+        WHERE stat_datetime >= DATE_FORMAT( #{lastTimeStart}, '%Y%m%d' )
         AND stat_datetime &lt;= DATE_FORMAT( #{lastTimeEnd}, '%Y%m%d' )
+        and company_id = #{companyId}
+        <if test="accountIds !=null and accountIds.size()>0">
+            AND account_id IN
+            <foreach collection="accountIds" item="id" separator=","
+                     open="(" close=")">
+                #{id}
+            </foreach>
+        </if>
         ) last ON 1=1
     </select>
 
@@ -386,29 +414,33 @@
         SELECT
         IFNULL( sum(charge), 0.00 ) AS 'charge'
         FROM
-        application.kuaishou_account_report_daily_dw
-        WHERE
-        account_id IN
-        <foreach collection="accountIds" item="id" separator=","
-                 open="(" close=")">
-            #{id}
-        </foreach>
-        AND stat_date >= DATE_FORMAT(#{startTime}, '%Y%m%d' )
+        application.kuaishou_account_report_hourly_dw
+        WHERE stat_date >= DATE_FORMAT(#{startTime}, '%Y%m%d' )
         AND stat_date &lt;= DATE_FORMAT(#{endTime}, '%Y%m%d' )
+        and company_id = #{companyId}
+        <if test="accountIds !=null and accountIds.size()>0">
+            AND account_id IN
+            <foreach collection="accountIds" item="id" separator=","
+                     open="(" close=")">
+                #{id}
+            </foreach>
+        </if>
         ) this
         LEFT JOIN (
         SELECT
         IFNULL( sum(charge), 0.00 ) AS 'charge'
         FROM
-        application.kuaishou_account_report_daily_dw
-        WHERE
-        account_id IN
-        <foreach collection="accountIds" item="id" separator=","
-                 open="(" close=")">
-            #{id}
-        </foreach>
-        AND stat_date >= DATE_FORMAT( #{lastTimeStart}, '%Y%m%d' )
+        application.kuaishou_account_report_hourly_dw
+        WHERE stat_date >= DATE_FORMAT( #{lastTimeStart}, '%Y%m%d' )
         AND stat_date &lt;= DATE_FORMAT( #{lastTimeEnd}, '%Y%m%d' )
+        and company_id = #{companyId}
+        <if test="accountIds !=null and accountIds.size()>0">
+            AND account_id IN
+            <foreach collection="accountIds" item="id" separator=","
+                     open="(" close=")">
+                #{id}
+            </foreach>
+        </if>
         ) last ON 1=1
     </select>
 
@@ -417,13 +449,16 @@
         SELECT count(1)
         FROM
         (select 1 from application.kuaishou_account_report_hourly_dw t1
-        where t1.project_id in
-        <foreach collection="projectIds" item="id" separator=","
-                 open="(" close=")">
-            #{id}
-        </foreach>
-        and t1.stat_date >= DATE_FORMAT(#{startTime}, '%Y%m%d')
+        where t1.stat_date >= DATE_FORMAT(#{startTime}, '%Y%m%d')
         and t1.stat_date &lt;= DATE_FORMAT(#{endTime}, '%Y%m%d')
+        and company_id = #{companyId}
+        <if test="accountIds !=null and accountIds.size()>0">
+            and account_id IN
+            <foreach collection="accountIds" item="id" separator=","
+                     open="(" close=")">
+                #{id}
+            </foreach>
+        </if>
         GROUP BY project_id
         ) t
     </select>
@@ -432,13 +467,16 @@
         SELECT count(1)
         FROM
         (select 1 from application.bytedance_advertiser_report_hourly_dw t1
-        where t1.project_id in
-        <foreach collection="projectIds" item="id" separator=","
-                 open="(" close=")">
-            #{id}
-        </foreach>
-        and t1.stat_datetime >= DATE_FORMAT(#{startTime}, '%Y%m%d')
+        where t1.stat_datetime >= DATE_FORMAT(#{startTime}, '%Y%m%d')
         and t1.stat_datetime &lt;= DATE_FORMAT(#{endTime}, '%Y%m%d')
+        and company_id = #{companyId}
+        <if test="accountIds !=null and accountIds.size()>0">
+            and account_id IN
+            <foreach collection="accountIds" item="id" separator=","
+                     open="(" close=")">
+                #{id}
+            </foreach>
+        </if>
         GROUP BY project_id
         ) t
     </select>
@@ -447,7 +485,7 @@
         SELECT
         t1.project_id as 'projectId',
         t1.project_name as 'projectName',
-        ( SELECT realname FROM `jeecg-boot`.sys_user us WHERE us.id = t1.sale_id ) AS 'saleName',
+        t4.realname AS 'saleName',
         SUM( t1.charge ) AS 'charge',
         CONCAT( CAST( IFNULL( ROUND(( SUM( t1.charge ) - t3.charge ) / t3.charge * 100, 2 ), 0.00 ) AS CHAR ), '%' ) AS
         'chargeRoi',
@@ -461,37 +499,44 @@
         SUM(real_charged_in_yuan) as 'realCharge',
         SUM(direct_rebate_real_charged_in_yuan) as 'jlCharge'
         FROM application.app_kuaishou_agent_report_d
-        WHERE
-        project_id IN
-        <foreach collection="projectIds" item="id" separator=","
-                 open="(" close=")">
-            #{id}
-        </foreach>
-        AND stat_date >= DATE_FORMAT(#{startTime}, '%Y%m%d' )
+        WHERE stat_date >= DATE_FORMAT(#{startTime}, '%Y%m%d' )
         AND stat_date &lt;= DATE_FORMAT(#{endTime}, '%Y%m%d' )
+        and company_id = #{companyId}
+        <if test="accountIds !=null and accountIds.size()>0">
+            and account_id IN
+            <foreach collection="accountIds" item="id" separator=","
+                     open="(" close=")">
+                #{id}
+            </foreach>
+        </if>
         GROUP BY project_id
         )t2 ON t1.project_id = t2.project_id
         LEFT JOIN (
-        SELECT project_id, SUM( charge ) AS 'charge' FROM application.kuaishou_account_report_hourly_dw WHERE project_id
-        IN
-        <foreach collection="projectIds" item="id" separator=","
-                 open="(" close=")">
-            #{id}
-        </foreach>
+        SELECT project_id, SUM( charge ) AS 'charge' FROM application.kuaishou_account_report_hourly_dw
+        WHERE hour &lt;= #{hour}
+        and company_id = #{companyId}
+        <if test="accountIds !=null and accountIds.size()>0">
+            and account_id IN
+            <foreach collection="accountIds" item="id" separator=","
+                     open="(" close=")">
+                #{id}
+            </foreach>
+        </if>
         AND stat_date >= DATE_FORMAT(DATE_ADD(#{startTime}, INTERVAL - ${days} DAY ), '%Y%m%d' )
         AND stat_date &lt;= DATE_FORMAT(DATE_ADD(#{endTime}, INTERVAL - ${days} DAY ), '%Y%m%d' )
-        AND hour &lt;= #{hour}
-        GROUP BY project_id ) t3 ON
-        t1.project_id = t3.project_id
-        WHERE
-        t1.project_id IN
-        <foreach collection="projectIds" item="id" separator=","
-                 open="(" close=")">
-            #{id}
-        </foreach>
+        GROUP BY project_id ) t3 ON t1.project_id = t3.project_id
+        left join(select id,realname from `jeecg-boot`.sys_user )t4 on t1.sale_id=t4.id
+        WHERE hour &lt;= #{hour}
+        and company_id = #{companyId}
+        <if test="accountIds !=null and accountIds.size()>0">
+            and t1.account_id IN
+            <foreach collection="accountIds" item="id" separator=","
+                     open="(" close=")">
+                #{id}
+            </foreach>
+        </if>
         AND stat_date >= DATE_FORMAT(#{startTime}, '%Y%m%d' )
         AND stat_date &lt;= DATE_FORMAT(#{endTime}, '%Y%m%d' )
-        AND hour &lt;= #{hour}
         GROUP BY t1.project_id
     </select>
 
@@ -500,7 +545,7 @@
         SELECT
         t1.project_id as 'projectId',
         t1.project_name as 'projectName',
-        ( SELECT realname FROM `jeecg-boot`.sys_user us WHERE us.id = t1.sale_id ) AS 'saleName',
+        t4.realname AS 'saleName',
         SUM( t1.cost ) AS 'charge',
         CONCAT( CAST( IFNULL( ROUND(( SUM( t1.cost ) - t3.charge ) / t3.charge * 100, 2 ), 0 ) AS CHAR ), '%' ) AS
         'chargeRoi',
@@ -514,40 +559,45 @@
         SUM(cash_cost) as 'realCharge',
         SUM(grants_cost) AS 'jlCharge'
         FROM application.app_bytedance_agent_report_d
-        WHERE
-        project_id IN
-        <foreach collection="projectIds" item="id" separator=","
-                 open="(" close=")">
-            #{id}
-        </foreach>
-        AND stat_datetime >= DATE_FORMAT(#{startTime}, '%Y%m%d' )
+        WHERE stat_datetime >= DATE_FORMAT(#{startTime}, '%Y%m%d' )
         AND stat_datetime &lt;= DATE_FORMAT(#{endTime}, '%Y%m%d' )
+        and company_id = #{companyId}
+        <if test="accountIds !=null and accountIds.size()>0">
+            and account_id IN
+            <foreach collection="accountIds" item="id" separator=","
+                     open="(" close=")">
+                #{id}
+            </foreach>
+        </if>
         GROUP BY project_id
         )t2 ON t1.project_id = t2.project_id
         LEFT JOIN (
-        SELECT project_id, SUM( cost ) AS 'charge' FROM application.bytedance_advertiser_report_hourly_dw WHERE
-        project_id
-        IN
-        <foreach collection="projectIds" item="id" separator=","
-                 open="(" close=")">
-            #{id}
-        </foreach>
-        AND stat_datetime >= DATE_FORMAT(DATE_ADD(#{startTime}, INTERVAL - ${days} DAY ), '%Y%m%d' )
+        SELECT project_id, SUM( cost ) AS 'charge' FROM application.bytedance_advertiser_report_hourly_dw
+        WHERE stat_datetime >= DATE_FORMAT(DATE_ADD(#{startTime}, INTERVAL - ${days} DAY ), '%Y%m%d' )
         AND stat_datetime &lt;= DATE_FORMAT(DATE_ADD(#{endTime}, INTERVAL - ${days} DAY ), '%Y%m%d' )
+        and company_id = #{companyId}
+        <if test="accountIds !=null and accountIds.size()>0">
+            and account_id IN
+            <foreach collection="accountIds" item="id" separator=","
+                     open="(" close=")">
+                #{id}
+            </foreach>
+        </if>
         AND hour &lt;= #{hour}
-        GROUP BY project_id ) t3 ON
-        t1.project_id = t3.project_id
-        WHERE
-        t1.project_id IN
-        <foreach collection="projectIds" item="id" separator=","
-                 open="(" close=")">
-            #{id}
-        </foreach>
-        AND t1.stat_datetime >= DATE_FORMAT(#{startTime}, '%Y%m%d' )
+        GROUP BY project_id ) t3 ON t1.project_id = t3.project_id
+        left join(select id,realname from `jeecg-boot`.sys_user )t4 on t1.sale_id=t4.id
+        WHERE t1.stat_datetime >= DATE_FORMAT(#{startTime}, '%Y%m%d' )
         AND t1.stat_datetime &lt;= DATE_FORMAT(#{endTime}, '%Y%m%d' )
+        and company_id = #{companyId}
+        <if test="accountIds !=null and accountIds.size()>0">
+            and account_id IN
+            <foreach collection="accountIds" item="id" separator=","
+                     open="(" close=")">
+                #{id}
+            </foreach>
+        </if>
         AND hour &lt;= #{hour}
         GROUP BY t1.project_id
     </select>
 
-
 </mapper>

+ 64 - 54
jeecg-boot-material-view/src/main/java/org/jeecg/ctop/material/service/impl/ManagerSaleValueServiceImpl.java

@@ -16,7 +16,6 @@ import org.springframework.stereotype.Service;
 import java.math.BigDecimal;
 import java.text.ParseException;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
 import java.util.UUID;
@@ -69,7 +68,10 @@ public class ManagerSaleValueServiceImpl extends ServiceImpl<ManagerSaleValueMap
             //丁兆明特殊处理
             if ("b161b7d9793942f980dbfe8c931cd1b0".equals(userId) || "228c45f913924639bf20c79ce5dadb16".equals(userId)) {
                 //账户集合
-                List<Long> accountIds = baseMapper.getCompanyAccountIds(companyId, mediaId);
+                List<Long> accountIds = baseMapper.querySalesDirectorAccountIds(companyId, mediaId, null);
+                if (Check.isNull(accountIds)) {
+                    return Result.error("未查询到账户!");
+                }
                 JSONObject data = getManagerData(accountIds, userId, mediaId, companyId);
                 data.put("weeklyGoalValue", weekly);
                 data.put("monthlyGoalValue", monthly);
@@ -77,9 +79,7 @@ public class ManagerSaleValueServiceImpl extends ServiceImpl<ManagerSaleValueMap
             }
             //查询销售总监及旗下的人员 集
             List<String> saleTeaMber = baseMapper.querySaleDirctorItsTeamMember(userId);
-            if (Check.isNull(saleTeaMber)) {
-                saleTeaMber = Arrays.asList(userId);
-            }
+            saleTeaMber.add(userId);
             //账户集合
             List<Long> accountIds = baseMapper.querySalesDirectorAccountIds(companyId, mediaId, saleTeaMber);
             if (Check.isNull(accountIds)) {
@@ -92,7 +92,10 @@ public class ManagerSaleValueServiceImpl extends ServiceImpl<ManagerSaleValueMap
             //分公司总经理
         } else if ("CompanyManager".equals(roleCode) || "admin".equals(roleCode)) {
             //账户集合
-            List<Long> accountIds = baseMapper.getCompanyAccountIds(companyId, mediaId);
+            List<Long> accountIds = baseMapper.querySalesDirectorAccountIds(companyId, mediaId, null);
+            if (Check.isNull(accountIds)) {
+                return Result.error("未查询到账户!");
+            }
             JSONObject data = getManagerData(accountIds, userId, mediaId, companyId);
             data.put("weeklyGoalValue", weekly);
             data.put("monthlyGoalValue", monthly);
@@ -121,27 +124,27 @@ public class ManagerSaleValueServiceImpl extends ServiceImpl<ManagerSaleValueMap
         //1 头条
         if ("1".equals(mediaId)) {
             //查询当日消耗 + 环比
-            result = baseMapper.queryTtTodayCharge(statDay, hour, accountIds);
+            result = baseMapper.queryTtTodayCharge(statDay, hour, accountIds, companyId);
             //周消耗
-            weekCharge = baseMapper.queryTtManydaysTotalCharge(weekFirstDay, statDay, accountIds);
+            weekCharge = baseMapper.queryTtManydaysTotalCharge(weekFirstDay, statDay, accountIds, companyId);
             //月消耗
-            String monthCharge = baseMapper.queryTtManydaysTotalCharge(monthFirstday, statDay, accountIds);
-            result.put("weekCharge", getBigDecimalVal(weekCharge, result.getBigDecimal("totalCharge")));
-            result.put("monthCharge", getBigDecimalVal(monthCharge, result.getBigDecimal("totalCharge")));
+            String monthCharge = baseMapper.queryTtManydaysTotalCharge(monthFirstday, statDay, accountIds, companyId);
+            result.put("weekCharge", new BigDecimal(weekCharge));
+            result.put("monthCharge", new BigDecimal(monthCharge));
             //现金消耗 + 环比ROI
-            JSONObject realCharged = baseMapper.queryTtRealCharged(lastMonthFirstday, monthFirstday, statDay, accountIds);
+            JSONObject realCharged = baseMapper.queryTtRealCharged(lastMonthFirstday, monthFirstday, statDay, accountIds, companyId);
             result.put("realCharged", realCharged.getBigDecimal("realCharged"));
             result.put("realChargedRoi", realCharged.getString("realChargedRoi"));
         } else if ("2".equals(mediaId)) {
-            result = baseMapper.queryKsTodayCharge(statDay, hour, accountIds);
+            result = baseMapper.queryKsTodayCharge(statDay, hour, accountIds, companyId);
             //周消耗
-            weekCharge = baseMapper.queryKsManydaysTotalCharge(weekFirstDay, statDay, accountIds);
+            weekCharge = baseMapper.queryKsManydaysTotalCharge(weekFirstDay, statDay, accountIds, companyId);
             //月消耗
-            String monthCharge = baseMapper.queryKsManydaysTotalCharge(monthFirstday, statDay, accountIds);
-            result.put("weekCharge", getBigDecimalVal(weekCharge, result.getBigDecimal("totalCharge")));
-            result.put("monthCharge", getBigDecimalVal(monthCharge, result.getBigDecimal("totalCharge")));
+            String monthCharge = baseMapper.queryKsManydaysTotalCharge(monthFirstday, statDay, accountIds, companyId);
+            result.put("weekCharge", new BigDecimal(weekCharge));
+            result.put("monthCharge", new BigDecimal(monthCharge));
             //现金消耗 + 环比ROI
-            JSONObject realCharged = baseMapper.queryKsRealCharged(lastMonthFirstday, monthFirstday, statDay, accountIds);
+            JSONObject realCharged = baseMapper.queryKsRealCharged(lastMonthFirstday, monthFirstday, statDay, accountIds, companyId);
             result.put("realCharged", realCharged.getBigDecimal("realCharged"));
             result.put("realChargedRoi", realCharged.getString("realChargedRoi"));
         }
@@ -182,7 +185,11 @@ public class ManagerSaleValueServiceImpl extends ServiceImpl<ManagerSaleValueMap
     public Result<Object> getHomeCharges(String userId, String mediaId, String companyId, String startTime, String endTime) throws ParseException {
         String roleCode = baseMapper.getRoleCodeByUserId(userId);
 
-        List<Long> compayAllAccountIds = baseMapper.getCompanyAccountIds(companyId, mediaId);
+        List<Long> compayAllAccountIds = baseMapper.querySalesDirectorAccountIds(companyId, mediaId, null);
+        if (Check.isNull(compayAllAccountIds)) {
+            return Result.error("未查询到账户!");
+        }
+
         JSONObject data = null;
         //销售总监
         if ("saleDirector".equals(roleCode)) {
@@ -197,9 +204,7 @@ public class ManagerSaleValueServiceImpl extends ServiceImpl<ManagerSaleValueMap
             }
             //查询销售总监及旗下的人员 集
             List<String> saleTeaMber = baseMapper.querySaleDirctorItsTeamMember(userId);
-            if (Check.isNull(saleTeaMber)) {
-                saleTeaMber = Arrays.asList(userId);
-            }
+            saleTeaMber.add(userId);
             //账户集合
             List<Long> accountIds = baseMapper.querySalesDirectorAccountIds(companyId, mediaId, saleTeaMber);
             if (Check.isNull(accountIds)) {
@@ -238,28 +243,28 @@ public class ManagerSaleValueServiceImpl extends ServiceImpl<ManagerSaleValueMap
         //1 头条
         if ("1".equals(mediaId)) {
             //查询 消耗 + 环比
-            result = baseMapper.queryTtManydaysChargeAndRoi(startTime, endTime, lastTimeStart, lastTimeEnd, accountIds);
-            List<JSONObject> list = baseMapper.queryTtManydaysCharge(startTime, endTime, accountIds);
+            result = baseMapper.queryTtManydaysChargeAndRoi(startTime, endTime, lastTimeStart, lastTimeEnd, accountIds, companyId);
+            List<JSONObject> list = baseMapper.queryTtManydaysCharge(startTime, endTime, accountIds, companyId);
             result.put("list", list);
             //平台消耗
             if (compayAllAccountIds == null) {
                 result.put("platformCharge", result.getString("totalCharge"));
                 result.put("platformChargeRoi", result.getString("chargeRoi"));
             } else {
-                JSONObject ptdata = baseMapper.queryTtManydaysChargeAndRoi(startTime, endTime, lastTimeStart, lastTimeEnd, compayAllAccountIds);
+                JSONObject ptdata = baseMapper.queryTtManydaysChargeAndRoi(startTime, endTime, lastTimeStart, lastTimeEnd, compayAllAccountIds, companyId);
                 result.put("platformCharge", ptdata.getString("totalCharge"));
                 result.put("platformChargeRoi", ptdata.getString("chargeRoi"));
             }
         } else if ("2".equals(mediaId)) {
-            result = baseMapper.queryKsManydaysChargeAndRoi(startTime, endTime, lastTimeStart, lastTimeEnd, accountIds);
-            List<JSONObject> list = baseMapper.queryKsManydaysCharge(startTime, endTime, accountIds);
+            result = baseMapper.queryKsManydaysChargeAndRoi(startTime, endTime, lastTimeStart, lastTimeEnd, accountIds, companyId);
+            List<JSONObject> list = baseMapper.queryKsManydaysCharge(startTime, endTime, accountIds, companyId);
             result.put("list", list);
             //平台消耗
             if (compayAllAccountIds == null) {
                 result.put("platformCharge", result.getString("totalCharge"));
                 result.put("platformChargeRoi", result.getString("chargeRoi"));
             } else {
-                JSONObject ptdata = baseMapper.queryKsManydaysChargeAndRoi(startTime, endTime, lastTimeStart, lastTimeEnd, compayAllAccountIds);
+                JSONObject ptdata = baseMapper.queryKsManydaysChargeAndRoi(startTime, endTime, lastTimeStart, lastTimeEnd, compayAllAccountIds, companyId);
                 result.put("platformCharge", ptdata.getString("totalCharge"));
                 result.put("platformChargeRoi", ptdata.getString("chargeRoi"));
             }
@@ -278,28 +283,28 @@ public class ManagerSaleValueServiceImpl extends ServiceImpl<ManagerSaleValueMap
         //1 头条
         if ("1".equals(mediaId)) {
             //查询当日消耗 + 环比
-            result = baseMapper.queryTtTodayCharge(date, hour, accountIds);
-            List<JSONObject> list = baseMapper.queryTtHourList(date, accountIds);
+            result = baseMapper.queryTtTodayCharge(date, hour, accountIds, companyId);
+            List<JSONObject> list = baseMapper.queryTtHourList(date, accountIds, companyId);
             result.put("list", list);
             //平台消耗
             if (compayAllAccountIds == null) {
                 result.put("platformCharge", result.getString("totalCharge"));
                 result.put("platformChargeRoi", result.getString("chargeRoi"));
             } else {
-                JSONObject ptdata = baseMapper.queryTtTodayCharge(date, hour, compayAllAccountIds);
+                JSONObject ptdata = baseMapper.queryTtTodayCharge(date, hour, compayAllAccountIds, companyId);
                 result.put("platformCharge", ptdata.getString("totalCharge"));
                 result.put("platformChargeRoi", ptdata.getString("chargeRoi"));
             }
         } else if ("2".equals(mediaId)) {
-            result = baseMapper.queryKsTodayCharge(date, hour, accountIds);
-            List<JSONObject> list = baseMapper.queryKsHourList(date, accountIds);
+            result = baseMapper.queryKsTodayCharge(date, hour, accountIds, companyId);
+            List<JSONObject> list = baseMapper.queryKsHourList(date, accountIds, companyId);
             result.put("list", list);
             //平台消耗
             if (compayAllAccountIds == null) {
                 result.put("platformCharge", result.getString("totalCharge"));
                 result.put("platformChargeRoi", result.getString("chargeRoi"));
             } else {
-                JSONObject ptdata = baseMapper.queryKsTodayCharge(date, hour, compayAllAccountIds);
+                JSONObject ptdata = baseMapper.queryKsTodayCharge(date, hour, compayAllAccountIds, companyId);
                 result.put("platformCharge", ptdata.getString("totalCharge"));
                 result.put("platformChargeRoi", ptdata.getString("chargeRoi"));
             }
@@ -310,48 +315,54 @@ public class ManagerSaleValueServiceImpl extends ServiceImpl<ManagerSaleValueMap
     @Override
     public PageInfo getProjectChargeTop(String userId, String mediaId, String companyId, String startTime, String endTime, Integer pageNo, Integer pageSize) throws Exception {
         String roleCode = baseMapper.getRoleCodeByUserId(userId);
-        List<Long> compayAllAccountIds = baseMapper.getCompanyAccountIds(companyId, mediaId);
         JSONObject data = null;
         //销售总监
         if ("saleDirector".equals(roleCode)) {
             //丁兆明特殊处理
             if ("b161b7d9793942f980dbfe8c931cd1b0".equals(userId) || "228c45f913924639bf20c79ce5dadb16".equals(userId)) {
-                List<Long> projectIds = baseMapper.querySalesDirectorProjectIds(companyId, mediaId, null);
+                //账户集合
+                List<Long> accountIds = baseMapper.querySalesDirectorAccountIds(companyId, mediaId, null);
+                if (Check.isNull(accountIds)) {
+                    throw new Exception("未查询到账户!");
+                }
                 if (startTime.equals(endTime)) {
-                    return getProjectDailyCharges(projectIds, mediaId, startTime, null, pageNo, pageSize);
+                    return getProjectDailyCharges(accountIds, companyId, mediaId, startTime, null, pageNo, pageSize);
                 } else {
-                    return getProjectDailyCharges(projectIds, mediaId, startTime, endTime, pageNo, pageSize);
+                    return getProjectDailyCharges(accountIds, companyId, mediaId, startTime, endTime, pageNo, pageSize);
                 }
             }
+
             //查询销售总监及旗下的人员 集
             List<String> saleTeaMber = baseMapper.querySaleDirctorItsTeamMember(userId);
-            if (Check.isNull(saleTeaMber)) {
-                saleTeaMber = Arrays.asList(userId);
-            }
+            saleTeaMber.add(userId);
             //账户集合
-            List<Long> projectIds = baseMapper.querySalesDirectorProjectIds(companyId, mediaId, saleTeaMber);
-            if (Check.isNull(projectIds)) {
+            List<Long> accountIds = baseMapper.querySalesDirectorAccountIds(companyId, mediaId, saleTeaMber);
+            if (Check.isNull(accountIds)) {
                 throw new Exception("未查询到账户!");
             }
             if (startTime.equals(endTime)) {
-                return getProjectDailyCharges(projectIds, mediaId, startTime, null, pageNo, pageSize);
+                return getProjectDailyCharges(accountIds, companyId, mediaId, startTime, null, pageNo, pageSize);
             } else {
-                return getProjectDailyCharges(projectIds, mediaId, startTime, endTime, pageNo, pageSize);
+                return getProjectDailyCharges(accountIds, companyId, mediaId, startTime, endTime, pageNo, pageSize);
             }
             //分公司总经理
         } else if ("CompanyManager".equals(roleCode) || "admin".equals(roleCode)) {
-            List<Long> projectIds = baseMapper.querySalesDirectorProjectIds(companyId, mediaId, null);
+            //账户集合
+            List<Long> accountIds = baseMapper.querySalesDirectorAccountIds(companyId, mediaId, null);
+            if (Check.isNull(accountIds)) {
+                throw new Exception("未查询到账户!");
+            }
             if (startTime.equals(endTime)) {
-                return getProjectDailyCharges(projectIds, mediaId, startTime, null, pageNo, pageSize);
+                return getProjectDailyCharges(accountIds, companyId, mediaId, startTime, null, pageNo, pageSize);
             } else {
-                return getProjectDailyCharges(projectIds, mediaId, startTime, endTime, pageNo, pageSize);
+                return getProjectDailyCharges(accountIds, companyId, mediaId, startTime, endTime, pageNo, pageSize);
             }
         } else {
             throw new Exception("该用户角色权限不足!");
         }
     }
 
-    private PageInfo getProjectDailyCharges(List<Long> projectIds, String mediaId, String startTime, String endTime, Integer pageNo, Integer pageSize) throws ParseException {
+    private PageInfo getProjectDailyCharges(List<Long> accountIds, String companyId, String mediaId, String startTime, String endTime, Integer pageNo, Integer pageSize) throws ParseException {
         Long days = 1L;
         Integer hour = DateUtils.getHour(DateUtils.formatDateTime());
         if (endTime == null) {
@@ -360,19 +371,18 @@ public class ManagerSaleValueServiceImpl extends ServiceImpl<ManagerSaleValueMap
             days = DateUtils.getDiscrepantDays(startTime, endTime) + 1;
             hour = 23;
         }
-
         //1 头条
         if ("1".equals(mediaId)) {
-            Long total = baseMapper.queryTtHourProjectTopTotal(projectIds, startTime, endTime);
+            Long total = baseMapper.queryTtHourProjectTopTotal(accountIds, startTime, endTime, companyId);
             PageHelper.startPage(pageNo, pageSize, false);
-            List<JSONObject> list = baseMapper.queryTtHourProjectTop(projectIds, startTime, endTime, days, hour);
+            List<JSONObject> list = baseMapper.queryTtHourProjectTop(accountIds, startTime, endTime, days, hour, companyId);
             PageInfo pageInfo = new PageInfo(list);
             pageInfo.setTotal(total);
             return pageInfo;
         } else if ("2".equals(mediaId)) {
-            Long total = baseMapper.queryKsHourProjectTopTotal(projectIds, startTime, endTime);
+            Long total = baseMapper.queryKsHourProjectTopTotal(accountIds, startTime, endTime, companyId);
             PageHelper.startPage(pageNo, pageSize, false);
-            List<JSONObject> list = baseMapper.queryKsHourProjectTop(projectIds, startTime, endTime, days, hour);
+            List<JSONObject> list = baseMapper.queryKsHourProjectTop(accountIds, startTime, endTime, days, hour, companyId);
             PageInfo pageInfo = new PageInfo(list);
             pageInfo.setTotal(total);
             return pageInfo;

+ 249 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/material/controller/ProductMaterialController.java

@@ -0,0 +1,249 @@
+package cn.com.ctop.kuaishou.modules.material.controller;
+
+import cn.com.ctop.common.module.utils.Check;
+import cn.com.ctop.common.module.utils.ExportExcelUtils;
+import cn.com.ctop.kuaishou.modules.material.entity.ProductMaterial;
+import cn.com.ctop.kuaishou.modules.material.service.IProductMaterialService;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.api.R;
+import com.github.pagehelper.PageInfo;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.system.query.QueryGenerator;
+import org.jeecg.common.util.oConvertUtils;
+import org.jeecgframework.poi.excel.ExcelImportUtil;
+import org.jeecgframework.poi.excel.def.NormalExcelConstants;
+import org.jeecgframework.poi.excel.entity.ExportParams;
+import org.jeecgframework.poi.excel.entity.ImportParams;
+import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.DeleteMapping;
+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.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.multipart.MultipartFile;
+import org.springframework.web.multipart.MultipartHttpServletRequest;
+import org.springframework.web.servlet.ModelAndView;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 选品库——产品与商品信息
+ *
+ * @author jeecg-boot
+ * @version V1.0
+ * @date 2022-04-19
+ */
+@Slf4j
+@Api(tags = "选品库——产品与商品信息")
+@RestController
+@RequestMapping("/product/material")
+public class ProductMaterialController {
+    @Autowired
+    private IProductMaterialService productMaterialService;
+
+    /**
+     * 分页列表查询
+     */
+    @GetMapping(value = "/materialList")
+    public Result<Object> materialList(Long productId, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
+        return productMaterialService.materialList(productId, pageNo, pageSize);
+    }
+
+    /**
+     * 分页列表查询
+     */
+    @GetMapping(value = "/list")
+    public Result<Object> queryPageList(ProductMaterial productMaterial,
+                                        @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
+                                        @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
+        return productMaterialService.queryPageList(productMaterial, pageNo, pageSize);
+    }
+
+    /**
+     * 分页列表查询
+     */
+    @GetMapping(value = "/videoList")
+    public Result<Object> videoList(ProductMaterial productMaterial,
+                                    @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
+                                    @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
+        if (Check.isNull(productMaterial.getProductId()) || Check.isNull(productMaterial.getProductId()) || Check.isNull(productMaterial.getTradeName()) || Check.isNull(productMaterial.getStartMonth())) {
+            return Result.error("缺少参数");
+        }
+
+        return productMaterialService.videoList(productMaterial, pageNo, pageSize);
+    }
+
+    /**
+     * 添加
+     */
+    @PostMapping(value = "/add")
+    public Result<Object> add(@RequestBody JSONObject data) {
+        try {
+            return productMaterialService.add(data);
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+            return Result.error("操作失败");
+        }
+    }
+
+    /**
+     * 编辑
+     */
+    @PostMapping(value = "/edit")
+    public Result<ProductMaterial> edit(@RequestBody ProductMaterial productMaterial) {
+        Result<ProductMaterial> result = new Result<ProductMaterial>();
+        Long productId = productMaterial.getProductId();
+        String tradeName = productMaterial.getTradeName();
+        if (Check.isNull(productId) || Check.isNull(tradeName)) {
+            return result.error500("缺少参数");
+        }
+        QueryWrapper<ProductMaterial> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("product_id", productId);
+        queryWrapper.eq("trade_name", tradeName);
+        boolean ok = productMaterialService.update(productMaterial, queryWrapper);
+        if (ok) {
+            result.success("修改成功!");
+        }
+        return result;
+    }
+
+    /**
+     * 通过id删除
+     */
+    @GetMapping(value = "/delete")
+    public Result<?> delete(@RequestParam(name = "id") String id) {
+        try {
+            if (Check.isNull(id)) {
+                return Result.error("缺少参数!");
+            }
+            productMaterialService.removeById(id);
+        } catch (Exception e) {
+            log.error("删除失败", e.getMessage());
+            return Result.error("删除失败!");
+        }
+        return Result.ok("删除成功!");
+    }
+
+
+    /**
+     * 通过id查询
+     *
+     * @param id
+     * @return
+     */
+    @ApiOperation(value = "选品库——产品与商品信息-通过id查询", notes = "选品库——产品与商品信息-通过id查询")
+    @GetMapping(value = "/queryById")
+    public Result<ProductMaterial> queryById(@RequestParam(name = "id", required = true) String id) {
+        Result<ProductMaterial> result = new Result<>();
+        ProductMaterial productMaterial = productMaterialService.getById(id);
+        if (productMaterial == null) {
+            result.error500("未找到对应实体");
+        } else {
+            result.setResult(productMaterial);
+            result.setSuccess(true);
+        }
+        return result;
+    }
+
+    /**
+     * 下载视频详情报表
+     */
+    @GetMapping(value = "/getVideoDetailsReportExcel")
+    public void getVideoDetailsReportExcel(HttpServletResponse response, ProductMaterial productMaterial) {
+        try {
+
+            List<JSONObject> list = productMaterialService.getVideoDetailsReportList(productMaterial);
+            List<List<Object>> excelList = new ArrayList<>();
+            if (!list.isEmpty()) {
+                list.forEach(data -> {
+                    List<Object> temp = new ArrayList<>();
+                    temp.add(data.getString("productName"));
+                    temp.add(data.getString("tradeName"));
+                    temp.add(data.getString("startMonth"));
+                    temp.add(data.getString("endMonth"));
+                    temp.add(data.getString("videoUrl"));
+                    temp.add(data.getString("charge"));
+                    temp.add(data.getString("itemRun"));
+                    temp.add(data.getString("user"));
+                    excelList.add(temp);
+                });
+            }
+            List<String> titles = new ArrayList<>();
+            titles.add(0, "产品名称");
+            titles.add(1, "商品名称");
+            titles.add(2, "开始时间");
+            titles.add(3, "暂停时间");
+            titles.add(4, "视频链接");
+            titles.add(5, "消耗");
+            titles.add(6, "是否跑量");
+            titles.add(7, "上传人");
+
+            OutputStream os = response.getOutputStream();
+            ExportExcelUtils eeu = new ExportExcelUtils();
+            XSSFWorkbook workbook = new XSSFWorkbook();
+            String[] headers = titles.toArray(new String[titles.size()]);
+            eeu.exportExcelForAttendance(workbook, 0, "选品视频", headers, excelList);
+            workbook.write(os);
+            os.flush();
+            os.close();
+        } catch (Exception e) {
+            e.printStackTrace();
+            log.error("查询失败", e.getMessage());
+        }
+    }
+
+    /**
+     * 通过excel导入数据
+     *
+     * @param request
+     * @param response
+     * @return
+     */
+    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
+    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
+        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
+        Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
+        for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
+            MultipartFile file = entity.getValue();
+            ImportParams params = new ImportParams();
+            params.setTitleRows(2);
+            params.setHeadRows(1);
+            params.setNeedSave(true);
+            try {
+                List<ProductMaterial> listProductMaterials = ExcelImportUtil.importExcel(file.getInputStream(), ProductMaterial.class, params);
+                productMaterialService.saveBatch(listProductMaterials);
+                return Result.ok("文件导入成功!数据行数:" + listProductMaterials.size());
+            } catch (Exception e) {
+                log.error(e.getMessage(), e);
+                return Result.error("文件导入失败:" + e.getMessage());
+            } finally {
+                try {
+                    file.getInputStream().close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+        return Result.ok("文件导入失败!");
+    }
+
+}

+ 123 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/material/entity/ProductMaterial.java

@@ -0,0 +1,123 @@
+package cn.com.ctop.kuaishou.modules.material.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+import org.jeecgframework.poi.excel.annotation.Excel;
+import org.springframework.format.annotation.DateTimeFormat;
+
+/**
+ * 选品库——产品与商品信息
+ *
+ * @author jeecg-boot
+ * @version V1.0
+ * @date 2022-04-19
+ */
+@Data
+@TableName("ctop_product_material")
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+@ApiModel(value = "ctop_product_material对象", description = "选品库——产品与商品信息")
+public class ProductMaterial {
+
+    /**
+     * id
+     */
+    @TableId(type = IdType.AUTO)
+    @ApiModelProperty(value = "id")
+    private Long id;
+    /**
+     * 产品id
+     */
+    @Excel(name = "产品id", width = 15)
+    @ApiModelProperty(value = "产品id")
+    private Long productId;
+    /**
+     * 产品名
+     */
+    @Excel(name = "产品名", width = 15)
+    @ApiModelProperty(value = "产品名")
+    private java.lang.String productName;
+    /**
+     * 商品名
+     */
+    @Excel(name = "商品名", width = 15)
+    @ApiModelProperty(value = "商品名")
+    private java.lang.String tradeName;
+    /**
+     * 商品品类
+     */
+    @Excel(name = "商品品类", width = 15)
+    @ApiModelProperty(value = "商品品类")
+    private java.lang.String tradeType;
+    /**
+     * 跑量单品
+     */
+    @Excel(name = "跑量单品", width = 15)
+    @ApiModelProperty(value = "跑量单品")
+    private java.lang.String itemRun;
+    /**
+     * 视频链接
+     */
+    @Excel(name = "视频链接", width = 15)
+    @ApiModelProperty(value = "视频链接")
+    private java.lang.String videoUrl;
+    /**
+     * 唯一MD5码
+     */
+    @Excel(name = "唯一MD5码", width = 15)
+    @ApiModelProperty(value = "唯一MD5码")
+    private java.lang.String signature;
+    /**
+     * 开始月份
+     */
+    @Excel(name = "开始月份", width = 15)
+    @ApiModelProperty(value = "开始月份")
+    private java.lang.String startMonth;
+    /**
+     * 结束月份
+     */
+    @Excel(name = "结束月份", width = 15)
+    @ApiModelProperty(value = "结束月份")
+    private java.lang.String endMonth;
+    /**
+     * 创建人id
+     */
+    @Excel(name = "创建人id", width = 15)
+    @ApiModelProperty(value = "创建人id")
+    private java.lang.String userId;
+    /**
+     * 视频上传人id
+     */
+    @Excel(name = "视频上传人", width = 15)
+    @ApiModelProperty(value = "视频上传人")
+    private java.lang.String uploaderId;
+    /**
+     * 创建时间
+     */
+    @Excel(name = "创建时间", width = 20, format = "yyyy-MM-dd HH:mm:ss")
+    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @ApiModelProperty(value = "创建时间")
+    private java.util.Date createTime;
+    /**
+     * 修改时间
+     */
+    @Excel(name = "修改时间", width = 20, format = "yyyy-MM-dd HH:mm:ss")
+    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @ApiModelProperty(value = "修改时间")
+    private java.util.Date updateTime;
+
+    @TableField(exist = false)
+    private String startDate;
+    @TableField(exist = false)
+    private String endDate;
+}

+ 29 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/material/mapper/ProductMaterialMapper.java

@@ -0,0 +1,29 @@
+package cn.com.ctop.kuaishou.modules.material.mapper;
+
+import java.util.List;
+
+import cn.com.ctop.kuaishou.modules.material.entity.ProductMaterial;
+import com.alibaba.fastjson.JSONObject;
+import org.apache.ibatis.annotations.Param;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+ * 选品库——产品与商品信息
+ * @author jeecg-boot
+ * 2022-04-19
+ * @version V1.0
+ */
+public interface ProductMaterialMapper extends BaseMapper<ProductMaterial> {
+
+    void replaceBatch(@Param("list")  List<ProductMaterial> lists);
+
+    Long queryPageListTotal(ProductMaterial productMaterial);
+
+    List<JSONObject> queryPageList(ProductMaterial productMaterial);
+
+    Long videoListTotal(ProductMaterial productMaterial);
+
+    List<JSONObject> videoList(ProductMaterial productMaterial);
+
+    List<JSONObject> getVideoDetailsReportList(ProductMaterial productMaterial);
+}

+ 202 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/material/mapper/xml/ProductMaterialMapper.xml

@@ -0,0 +1,202 @@
+<?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.kuaishou.modules.material.mapper.ProductMaterialMapper">
+
+    <insert id="replaceBatch">
+        replace into ctop_product_material(
+        product_id,
+        product_name,
+        trade_name,
+        trade_type,
+        video_url,
+        signature,
+        start_month,
+        end_month,
+        user_id,
+        uploader_id
+        )
+        values
+        <foreach collection="list" item="pro" separator=",">
+            (
+            #{pro.productId},
+            #{pro.productName},
+            #{pro.tradeName},
+            #{pro.tradeType},
+            #{pro.videoUrl},
+            #{pro.signature},
+            #{pro.startMonth},
+            #{pro.endMonth},
+            #{pro.userId},
+            #{pro.uploaderId}
+            )
+        </foreach>
+    </insert>
+
+    <select id="queryPageListTotal" resultType="java.lang.Long">
+        SELECT
+        IFNULL(sum(1),0)
+        from (
+        select
+        trade_name
+        FROM ctop_product_material
+        <where>
+            <if test="productId!=null">
+                and product_id = #{productId}
+            </if>
+            <if test="tradeName!=null">
+                and trade_name like CONCAT(CONCAT('%', #{tradeName}), '%')
+            </if>
+            <if test="startMonth!=null">
+                and start_month >= #{startMonth}
+            </if>
+            <if test="endMonth!=null">
+                and end_month &lt;= #{endMonth}
+            </if>
+            <if test="itemRun!=null">
+                and item_run = #{itemRun}
+            </if>
+        </where>
+        group by product_id,trade_name
+        ) t
+    </select>
+
+
+    <select id="queryPageList" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        t1.product_id as 'productId',
+        t1.product_name as 'productName',
+        t1.trade_name as 'tradeName',
+        t1.trade_type as 'tradeType',
+        t1.item_run as 'itemRun',
+        IFNULL(sum(t2.charge),0.00) as 'charge',
+        CONCAT(t1.start_month,' ~ ',t1.end_month) as 'time',
+        IFNULL(t3.realname,'-') as 'user',
+        (SELECT COUNT(1) FROM ctop_product_material tt WHERE tt.product_id = t1.product_id AND tt.trade_name =
+        t1.trade_name) as 'videoCount'
+        FROM ctop_product_material t1
+        LEFT JOIN
+        (
+        SELECT signature , sum(charge) as 'charge' FROM application.kuaishou_material_video_report_daily_dw
+        <where>
+            <if test="productId!=null">
+                and product_id = #{productId}
+            </if>
+            <if test="startDate!=null">
+                AND stat_date >=DATE_FORMAT(#{startDate}, '%Y%m%d' )
+            </if>
+            <if test="endDate!=null">
+                AND stat_date &lt;=DATE_FORMAT(#{endDate}, '%Y%m%d' )
+            </if>
+        </where>
+        GROUP BY signature
+        ) t2 ON t1.signature = t2.signature
+            left join (select id, realname from sys_user)t3 on t1.user_id =t3.id
+        <where>
+            <if test="productId!=null">
+                and t1.product_id = #{productId}
+            </if>
+            <if test="tradeName!=null">
+                and t1.trade_name like CONCAT(CONCAT('%', #{tradeName}), '%')
+            </if>
+            <if test="startMonth!=null">
+                and t1.start_month >= #{startMonth}
+            </if>
+            <if test="endMonth!=null">
+                and t1.end_month &lt;= #{endMonth}
+            </if>
+            <if test="itemRun!=null">
+                and t1.item_run = #{itemRun}
+            </if>
+        </where>
+        group by t1.product_id,t1.trade_name
+    </select>
+
+
+    <select id="videoListTotal" resultType="java.lang.Long">
+        SELECT IFNULL(sum(1), 0)
+        from (
+                 select trade_name
+                 FROM ctop_product_material
+                 WHERE product_id = #{productId}
+                   and trade_name = #{tradeName}
+                   and start_month >= #{startMonth}
+                   and end_month &lt;= #{endMonth}
+                 group by signature
+             ) t
+    </select>
+
+    <select id="videoList" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT id,
+               t1.product_name as 'productName',
+               t1.trade_name as 'tradeName',
+               t1.video_url as 'videoUrl',
+               IFNULL(sum(t2.charge), 0.00) as 'charge',
+               (select realname from sys_user where t1.user_id = id) as 'user'
+        FROM ctop_product_material t1
+                 LEFT JOIN
+             (
+                 SELECT signature, sum(charge) as 'charge'
+                 FROM application.kuaishou_material_video_report_daily_dw
+                 where product_id = #{productId}
+                   AND stat_date >= DATE_FORMAT(#{startDate}, '%Y%m%d')
+                   AND stat_date &lt;= DATE_FORMAT(#{endDate}, '%Y%m%d')
+                 GROUP BY signature
+             ) t2 ON t1.signature = t2.signature
+        WHERE product_id = #{productId}
+          and trade_name = #{tradeName}
+          and start_month >= #{startMonth}
+          and end_month &lt;= #{endMonth}
+        group by t1.signature
+    </select>
+
+    <select id="getVideoDetailsReportList" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        t1.product_name as 'productName',
+        t1.trade_name as 'tradeName',
+        t1.start_month as 'startMonth',
+        t1.end_month as 'endMonth',
+        t1.video_url as 'videoUrl',
+        IFNULL(sum(t2.charge), 0.00) as 'charge',
+        case t1.item_run
+        WHEN 1 THEN '是'
+        WHEN 0 THEN '否'
+        ELSE '-' END as 'itemRun',
+        (select realname from sys_user where t1.user_id = id) as 'user'
+        FROM ctop_product_material t1
+        LEFT JOIN
+        (
+        SELECT signature , sum(charge) as 'charge' FROM application.kuaishou_material_video_report_daily_dw
+        <where>
+            <if test="productId!=null">
+                and product_id = #{productId}
+            </if>
+            <if test="startDate!=null">
+                AND stat_date >=DATE_FORMAT(#{startDate}, '%Y%m%d' )
+            </if>
+            <if test="endDate!=null">
+                AND stat_date &lt;=DATE_FORMAT(#{endDate}, '%Y%m%d' )
+            </if>
+        </where>
+        GROUP BY signature
+        ) t2 ON t1.signature = t2.signature
+        <where>
+            <if test="productId!=null">
+                and t1.product_id = #{productId}
+            </if>
+            <if test="tradeName!=null">
+                and t1.trade_name like CONCAT(CONCAT('%', #{tradeName}), '%')
+            </if>
+            <if test="startMonth!=null">
+                and t1.start_month >= #{startMonth}
+            </if>
+            <if test="endMonth!=null">
+                and t1.end_month &lt;= #{endMonth}
+            </if>
+            <if test="itemRun!=null">
+                and t1.item_run = #{itemRun}
+            </if>
+        </where>
+        group by t1.signature
+    </select>
+
+</mapper>

+ 26 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/material/service/IProductMaterialService.java

@@ -0,0 +1,26 @@
+package cn.com.ctop.kuaishou.modules.material.service;
+
+import cn.com.ctop.kuaishou.modules.material.entity.ProductMaterial;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.extension.service.IService;
+import org.jeecg.common.api.vo.Result;
+
+import java.io.IOException;
+import java.util.List;
+
+/**
+ * 选品库——产品与商品信息
+ * 2022-04-19
+ */
+public interface IProductMaterialService extends IService<ProductMaterial> {
+
+    Result<Object> queryPageList(ProductMaterial productMaterial, Integer pageNo, Integer pageSize);
+
+    Result<Object> videoList(ProductMaterial productMaterial, Integer pageNo, Integer pageSize);
+
+    Result<Object> add(JSONObject data) throws IOException;
+
+    List<JSONObject> getVideoDetailsReportList(ProductMaterial productMaterial);
+
+    Result<Object> materialList(Long productId, Integer pageNo, Integer pageSize);
+}

+ 225 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/material/service/impl/ProductMaterialServiceImpl.java

@@ -0,0 +1,225 @@
+package cn.com.ctop.kuaishou.modules.material.service.impl;
+
+import cn.com.ctop.common.module.entity.MaterialInfo;
+import cn.com.ctop.common.module.service.IMaterialInfoService;
+import cn.com.ctop.common.module.utils.Check;
+import cn.com.ctop.common.module.utils.CosUtils;
+import cn.com.ctop.common.module.utils.KuaishouInterfaceConstant;
+import cn.com.ctop.common.module.utils.LoadFileUtil;
+import cn.com.ctop.common.module.vo.ResFileDTO;
+import cn.com.ctop.kuaishou.modules.material.entity.ProductMaterial;
+import cn.com.ctop.kuaishou.modules.material.mapper.ProductMaterialMapper;
+import cn.com.ctop.kuaishou.modules.material.service.IProductMaterialService;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.github.pagehelper.PageHelper;
+import com.github.pagehelper.PageInfo;
+import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.util.DateUtils;
+import org.jeecg.common.util.MD5Util;
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.List;
+import java.util.UUID;
+
+/**
+ * 选品库——产品与商品信息
+ *
+ * @author jeecg-boot
+ * 2022-04-19
+ * @version V1.0
+ */
+@Service
+public class ProductMaterialServiceImpl extends ServiceImpl<ProductMaterialMapper, ProductMaterial> implements IProductMaterialService {
+
+    @Autowired
+    private IMaterialInfoService materialInfoService;
+
+
+    @Value("${zip.local.download-path}")
+    private String downloadPath;
+
+
+    @Override
+    public Result<Object> queryPageList(ProductMaterial productMaterial, Integer pageNo, Integer pageSize) {
+        String startMonth = productMaterial.getStartMonth();
+        String endMonth = productMaterial.getEndMonth();
+        if (!Check.isNull(startMonth)) {
+            productMaterial.setStartDate(startMonth.concat("-01"));
+            if (!Check.isNull(endMonth)) {
+                String[] sp = endMonth.split("-");
+                String lastDayStr = "-" + DateUtils.getDaysOfMonth(Integer.valueOf(sp[0]), Integer.valueOf(sp[1]));
+                productMaterial.setEndDate(endMonth.concat(lastDayStr));
+            }
+        }
+        Long total = baseMapper.queryPageListTotal(productMaterial);
+        PageHelper.startPage(pageNo, pageSize, false);
+        List<JSONObject> list = baseMapper.queryPageList(productMaterial);
+        PageInfo pageInfo = new PageInfo(list);
+        pageInfo.setTotal(total);
+        return Result.ok(pageInfo);
+    }
+
+    @Override
+    public Result<Object> videoList(ProductMaterial productMaterial, Integer pageNo, Integer pageSize) {
+        String startMonth = productMaterial.getStartMonth();
+        String endMonth = productMaterial.getEndMonth();
+        if (!Check.isNull(startMonth)) {
+            productMaterial.setStartDate(startMonth.concat("-01"));
+            if (!Check.isNull(endMonth)) {
+                String[] sp = endMonth.split("-");
+                String lastDayStr = "-" + DateUtils.getDaysOfMonth(Integer.valueOf(sp[0]), Integer.valueOf(sp[1]));
+                productMaterial.setEndDate(endMonth.concat(lastDayStr));
+            }
+        }
+        Long total = baseMapper.videoListTotal(productMaterial);
+        PageHelper.startPage(pageNo, pageSize, false);
+        List<JSONObject> list = baseMapper.videoList(productMaterial);
+        PageInfo pageInfo = new PageInfo(list);
+        pageInfo.setTotal(total);
+        return Result.ok(pageInfo);
+    }
+
+    @Override
+    public Result<Object> add(JSONObject data) throws IOException {
+        JSONArray list = data.getJSONArray("list");
+        if (Check.isNull(list) || list.size() == 0) {
+            return Result.error("缺少参数");
+        }
+        ProductMaterial entity = JSONObject.parseObject(data.toJSONString(), ProductMaterial.class);
+
+        List<ProductMaterial> lists = new ArrayList<>();
+        boolean flag = false;
+        String msg = "";
+        for (int i = 0; i < list.size(); i++) {
+            JSONObject trade = list.getJSONObject(i);
+            String tradeName = trade.getString("tradeName");
+            String videoUrl = trade.getString("videoUrl");
+            String signature = trade.getString("signature");
+            String uploaderId = trade.getString("uploaderId");
+            int count = 0;
+            if (Check.isNull(signature) && Check.isNull(uploaderId)) {
+                List<String> urls = Arrays.asList(videoUrl.split(","));
+                for (String url : urls) {
+                    ProductMaterial material = new ProductMaterial();
+                    count++;
+                    //获取MD5
+                    String localPath = LoadFileUtil.downLoadFromUrl(url, downloadPath);
+                    String md5 = MD5Util.getMd5(localPath);
+                    if (checkVideo(entity.getProductId(), tradeName, md5)) {
+                        BeanUtils.copyProperties(entity, material);
+                        material.setTradeName(tradeName);
+                        MaterialInfo info = materialInfoService.getMaterialInfoByCode(md5);
+                        if (!Check.isNull(info)) {
+                            material.setUploaderId(uploaderId);
+                        } else {
+                            material.setUploaderId(material.getUserId());
+                        }
+                        material.setSignature(md5);
+                        String cosUrl = getCosUrl(url);
+                        material.setVideoUrl(cosUrl);
+                        lists.add(material);
+                    } else {
+                        flag = true;
+                        if (msg.contains(tradeName)) {
+                            msg += "第" + count + "条视频已存在,";
+                        } else {
+                            msg += "商品(" + tradeName + ")下的第" + count + "条视频已存在,";
+                        }
+                    }
+                    LoadFileUtil.delFile(localPath);
+                }
+            } else {
+                ProductMaterial material = new ProductMaterial();
+                BeanUtils.copyProperties(entity, material);
+                material.setTradeName(tradeName);
+                material.setVideoUrl(videoUrl);
+                material.setSignature(signature);
+                material.setUploaderId(uploaderId);
+                if (checkVideo(entity.getProductId(), tradeName, signature)) {
+                    lists.add(material);
+                }
+            }
+        }
+        if (!Check.isNull(lists)) {
+            baseMapper.replaceBatch(lists);
+        }
+        if (flag) {
+            return Result.ok("添加完成,其中" + msg.substring(0, msg.length() - 1));
+        }
+        return Result.ok("添加完成");
+    }
+
+    @Override
+    public List<JSONObject> getVideoDetailsReportList(ProductMaterial productMaterial) {
+        String startMonth = productMaterial.getStartMonth();
+        String endMonth = productMaterial.getEndMonth();
+        if (!Check.isNull(startMonth)) {
+            productMaterial.setStartDate(startMonth.concat("-01"));
+            if (!Check.isNull(endMonth)) {
+                String[] sp = endMonth.split("-");
+                String lastDayStr = "-" + DateUtils.getDaysOfMonth(Integer.valueOf(sp[0]), Integer.valueOf(sp[1]));
+                productMaterial.setEndDate(endMonth.concat(lastDayStr));
+            }
+        }
+        List<JSONObject> list = baseMapper.getVideoDetailsReportList(productMaterial);
+        return list;
+    }
+
+    @Override
+    public Result<Object> materialList(Long productId, Integer pageNo, Integer pageSize) {
+        PageHelper.startPage(pageNo, pageSize, false);
+        List<MaterialInfo> list = materialInfoService.getListByProduct(productId);
+        PageInfo pageInfo = new PageInfo(list);
+        return Result.ok(pageInfo);
+    }
+
+
+    private boolean checkVideo(Long productId, String tradeName, String signature) {
+        QueryWrapper<ProductMaterial> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("product_id", productId);
+        queryWrapper.eq("trade_name", tradeName);
+        queryWrapper.eq("signature", signature).last("limit 1");
+        ProductMaterial one = this.getOne(queryWrapper);
+        if (Check.isNull(one)) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+
+    /**
+     * 根据原始视频链接,下载到cos上
+     */
+    private String getCosUrl(String url) {
+        try {
+            if (!url.contains("http")) {
+                url = KuaishouInterfaceConstant.HTTPS_PREFIX + url;
+            }
+            InputStream imageStream = LoadFileUtil.getFileStream(url);
+            if (!Check.isNull(imageStream)) {
+                String path = "XuanPinKu/" + DateUtils.formatDate(new Date(), DateUtils.SHORT_FORMAT) + "/";
+                String videoName = UUID.randomUUID().toString().replace("-", "") + ".mp4";
+                ResFileDTO file = CosUtils.uploadDetailInputStreamV2(imageStream, videoName, "mp4", 0L, path);
+                return file.getFileUrl();
+            }
+        } catch (Exception e) {
+            log.error("上传COS异常", e);
+            return "上传COS失败";
+        }
+        return null;
+    }
+
+
+}

File diff suppressed because it is too large
+ 423 - 409
jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/controller/SysUserController.java