Browse Source

销售盯盘V1-2功能版本更新 运营数据 添加日期

zhaoxian 2 years ago
parent
commit
1754eaf285

+ 2 - 2
jeecg-boot-material-view/src/main/java/org/jeecg/ctop/material/controller/ManagerSaleValueController.java

@@ -59,12 +59,12 @@ public class ManagerSaleValueController {
      * 查询当日消耗 + 月度消耗
      * 查询当日消耗 + 月度消耗
      */
      */
     @GetMapping(value = "/getDayAndMonthlyCharges")
     @GetMapping(value = "/getDayAndMonthlyCharges")
-    public Result<Object> getDayAndMonthlyCharges(String userId, String mediaId, String companyId, String operate) {
+    public Result<Object> getDayAndMonthlyCharges(String userId, String mediaId, String companyId, String startTime, String endTime, String operate) {
         if (Check.isNull(userId) || Check.isNull(mediaId) || Check.isNull(companyId)) {
         if (Check.isNull(userId) || Check.isNull(mediaId) || Check.isNull(companyId)) {
             return Result.error("缺少参数");
             return Result.error("缺少参数");
         }
         }
         try {
         try {
-            return managerSaleValueService.getDayAndMonthlyCharges(userId, mediaId, companyId, operate);
+            return managerSaleValueService.getDayAndMonthlyCharges(userId, mediaId, companyId, startTime, endTime, operate);
         } catch (Exception e) {
         } catch (Exception e) {
             e.printStackTrace();
             e.printStackTrace();
             return Result.error("查询失败");
             return Result.error("查询失败");

+ 4 - 0
jeecg-boot-material-view/src/main/java/org/jeecg/ctop/material/mapper/ManagerSaleValueMapper.java

@@ -38,6 +38,8 @@ public interface ManagerSaleValueMapper extends BaseMapper<ManagerSaleValue> {
 
 
     JSONObject queryTtTodayCharge(@Param("statDay") String statDay, @Param("hour") Integer hour, @Param("accountIds") List<Long> accountIds, @Param("companyId") String companyId);
     JSONObject queryTtTodayCharge(@Param("statDay") String statDay, @Param("hour") Integer hour, @Param("accountIds") List<Long> accountIds, @Param("companyId") String companyId);
 
 
+    JSONObject queryTtTodayCharge2(@Param("statDay") String statDay, @Param("endTime") String endTime, @Param("hour") Integer hour, @Param("accountIds") List<Long> accountIds, @Param("companyId") String companyId, @Param("days") long days);
+
     String queryTtManydaysTotalCharge(@Param("startDay") String startDay, @Param("endDay") String endDay, @Param("accountIds") List<Long> accountIds, @Param("companyId") String companyId);
     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, @Param("companyId") String companyId);
     JSONObject queryTtRealCharged(@Param("lastMonthFirstday") String lastMonthFirstday, @Param("monthFirstday") String monthFirstday, @Param("statDay") String statDay, @Param("accountIds") List<Long> accountIds, @Param("companyId") String companyId);
@@ -45,6 +47,8 @@ public interface ManagerSaleValueMapper extends BaseMapper<ManagerSaleValue> {
 
 
     JSONObject queryKsTodayCharge(@Param("statDay") String statDay, @Param("hour") Integer hour, @Param("accountIds") List<Long> accountIds, @Param("companyId") String companyId);
     JSONObject queryKsTodayCharge(@Param("statDay") String statDay, @Param("hour") Integer hour, @Param("accountIds") List<Long> accountIds, @Param("companyId") String companyId);
 
 
+    JSONObject queryKsTodayCharge2(@Param("statDay") String statDay, @Param("endTime") String endTime, @Param("hour") Integer hour, @Param("accountIds") List<Long> accountIds, @Param("companyId") String companyId, @Param("days") long days);
+
     String queryKsManydaysTotalCharge(@Param("startDay") String startDay, @Param("endDay") String endDay, @Param("accountIds") List<Long> accountIds, @Param("companyId") String companyId);
     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, @Param("companyId") String companyId);
     JSONObject queryKsRealCharged(@Param("lastMonthFirstday") String lastMonthFirstday, @Param("monthFirstday") String monthFirstday, @Param("statDay") String statDay, @Param("accountIds") List<Long> accountIds, @Param("companyId") String companyId);

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

@@ -110,6 +110,49 @@
         ) y on 1 = 1
         ) y on 1 = 1
     </select>
     </select>
 
 
+
+    <select id="queryKsTodayCharge2" 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>
+            <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')
+            and stat_date &lt;= DATE_FORMAT(#{endTime}, '%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 stat_date >= DATE_FORMAT(DATE_ADD(#{statDay},INTERVAL -#{days} day), '%Y%m%d')
+        where stat_date &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>
+        <if test="hour !=null">
+            AND hour &lt;= #{hour}
+        </if>
+        ) y on 1 = 1
+    </select>
+
     <select id="queryTtTodayCharge" resultType="com.alibaba.fastjson.JSONObject">
     <select id="queryTtTodayCharge" resultType="com.alibaba.fastjson.JSONObject">
         SELECT IFNULL(t.charge, 0.00) as 'totalCharge', CONCAT(
         SELECT IFNULL(t.charge, 0.00) as 'totalCharge', CONCAT(
         CAST(IFNULL(ROUND((t.charge - tt.charge) / tt.charge * 100, 2), 0) as CHAR), '%') as 'chargeRoi'
         CAST(IFNULL(ROUND((t.charge - tt.charge) / tt.charge * 100, 2), 0) as CHAR), '%') as 'chargeRoi'
@@ -148,6 +191,46 @@
         ) tt on 1 = 1
         ) tt on 1 = 1
     </select>
     </select>
 
 
+    <select id="queryTtTodayCharge2" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT IFNULL(t.charge, 0.00) as 'totalCharge', CONCAT(
+        CAST(IFNULL(ROUND((t.charge - tt.charge) / tt.charge * 100, 2), 0) as CHAR), '%') as 'chargeRoi'
+        FROM (
+        SELECT sum(cost) as 'charge'
+        FROM application.bytedance_advertiser_report_hourly_dw
+        where stat_datetime >= DATE_FORMAT(#{statDay}, '%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>
+
+        <if test="hour !=null">
+            AND hour &lt;= #{hour}
+        </if>
+        ) t
+        LEFT JOIN
+        (
+        SELECT sum(cost) as 'charge'
+        FROM application.bytedance_advertiser_report_hourly_dw
+        WHERE stat_datetime >= DATE_FORMAT(DATE_ADD(#{statDay},INTERVAL -#{days} day), '%Y%m%d')
+        AND stat_datetime &lt;=DATE_FORMAT(DATE_ADD(#{endTime},INTERVAL -#{days} 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>
+        ) tt on 1 = 1
+    </select>
+
     <select id="queryTtManydaysTotalCharge" resultType="String">
     <select id="queryTtManydaysTotalCharge" resultType="String">
         SELECT IFNULL(sum(cost), 0.00)
         SELECT IFNULL(sum(cost), 0.00)
         FROM application.bytedance_advertiser_report_hourly_dw
         FROM application.bytedance_advertiser_report_hourly_dw
@@ -534,7 +617,8 @@
         AND stat_date &lt;= DATE_FORMAT(DATE_ADD(#{endTime}, INTERVAL - ${days} DAY ), '%Y%m%d' )
         AND stat_date &lt;= DATE_FORMAT(DATE_ADD(#{endTime}, INTERVAL - ${days} DAY ), '%Y%m%d' )
         GROUP BY project_id ) t3 ON t1.project_id = t3.project_id
         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
         left join(select id,realname from `jeecg-boot`.sys_user )t4 on t1.sale_id=t4.id
-        LEFT JOIN ( SELECT t1.id, realname FROM `jeecg-boot`.ctop_project t1 LEFT JOIN `jeecg-boot`.sys_user t2 ON t1.responsible_id = t2.id ) t5 ON t1.project_id = t5.id
+        LEFT JOIN ( SELECT t1.id, realname FROM `jeecg-boot`.ctop_project t1 LEFT JOIN `jeecg-boot`.sys_user t2 ON
+        t1.responsible_id = t2.id ) t5 ON t1.project_id = t5.id
         WHERE hour &lt;= #{hour}
         WHERE hour &lt;= #{hour}
         and company_id = #{companyId}
         and company_id = #{companyId}
         <if test="accountIds !=null and accountIds.size()>0">
         <if test="accountIds !=null and accountIds.size()>0">
@@ -596,7 +680,8 @@
         AND hour &lt;= #{hour}
         AND hour &lt;= #{hour}
         GROUP BY project_id ) t3 ON t1.project_id = t3.project_id
         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
         left join(select id,realname from `jeecg-boot`.sys_user )t4 on t1.sale_id=t4.id
-        LEFT JOIN ( SELECT t1.id, realname FROM `jeecg-boot`.ctop_project t1 LEFT JOIN `jeecg-boot`.sys_user t2 ON t1.responsible_id = t2.id ) t5 ON t1.project_id = t5.id
+        LEFT JOIN ( SELECT t1.id, realname FROM `jeecg-boot`.ctop_project t1 LEFT JOIN `jeecg-boot`.sys_user t2 ON
+        t1.responsible_id = t2.id ) t5 ON t1.project_id = t5.id
         WHERE 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 t1.stat_datetime &lt;= DATE_FORMAT(#{endTime}, '%Y%m%d' )
         and company_id = #{companyId}
         and company_id = #{companyId}

+ 1 - 1
jeecg-boot-material-view/src/main/java/org/jeecg/ctop/material/service/IManagerSaleValueService.java

@@ -18,7 +18,7 @@ public interface IManagerSaleValueService extends IService<ManagerSaleValue> {
 
 
     Result<Object> getCompany(String userId);
     Result<Object> getCompany(String userId);
 
 
-    Result<Object> getDayAndMonthlyCharges(String userId, String mediaId, String companyId, String operate) throws ParseException;
+    Result<Object> getDayAndMonthlyCharges(String userId, String mediaId, String companyId, String startTime, String endTime, String operate) throws ParseException;
 
 
     void setUpManagerSaleValue(ManagerSaleValue sale) throws Exception;
     void setUpManagerSaleValue(ManagerSaleValue sale) throws Exception;
 
 

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

@@ -66,7 +66,7 @@ public class ManagerSaleValueServiceImpl extends ServiceImpl<ManagerSaleValueMap
     }
     }
 
 
     @Override
     @Override
-    public Result<Object> getDayAndMonthlyCharges(String userId, String mediaId, String companyId, String operate) throws ParseException {
+    public Result<Object> getDayAndMonthlyCharges(String userId, String mediaId, String companyId, String startTime, String endTime, String operate) throws ParseException {
         Result<Object> result = new Result<>();
         Result<Object> result = new Result<>();
         String roleCode = baseMapper.getRoleCodeByUserId(userId);
         String roleCode = baseMapper.getRoleCodeByUserId(userId);
         Boolean bjCompany = false;
         Boolean bjCompany = false;
@@ -84,7 +84,7 @@ public class ManagerSaleValueServiceImpl extends ServiceImpl<ManagerSaleValueMap
                 if (Check.isNull(accountIds)) {
                 if (Check.isNull(accountIds)) {
                     return Result.error("未查询到账户!");
                     return Result.error("未查询到账户!");
                 }
                 }
-                JSONObject data = getManagerData(accountIds, userId, mediaId, companyId, bjCompany, null);
+                JSONObject data = getManagerData(accountIds, userId, mediaId, companyId, bjCompany, null, startTime, endTime);
                 return Result.ok(data);
                 return Result.ok(data);
             }
             }
             //查询销售总监及旗下的人员 集
             //查询销售总监及旗下的人员 集
@@ -95,7 +95,7 @@ public class ManagerSaleValueServiceImpl extends ServiceImpl<ManagerSaleValueMap
             if (Check.isNull(accountIds)) {
             if (Check.isNull(accountIds)) {
                 return Result.error("未查询到账户!");
                 return Result.error("未查询到账户!");
             }
             }
-            JSONObject data = getManagerData(accountIds, userId, mediaId, companyId, bjCompany, saleTeaMber);
+            JSONObject data = getManagerData(accountIds, userId, mediaId, companyId, bjCompany, saleTeaMber, startTime, endTime);
             result = Result.ok(data);
             result = Result.ok(data);
             //分公司总经理
             //分公司总经理
         } else if ("CompanyManager".equals(roleCode) || "admin".equals(roleCode)) {
         } else if ("CompanyManager".equals(roleCode) || "admin".equals(roleCode)) {
@@ -104,7 +104,7 @@ public class ManagerSaleValueServiceImpl extends ServiceImpl<ManagerSaleValueMap
             if (Check.isNull(accountIds)) {
             if (Check.isNull(accountIds)) {
                 return Result.error("未查询到账户!");
                 return Result.error("未查询到账户!");
             }
             }
-            JSONObject data = getManagerData(accountIds, userId, mediaId, companyId, bjCompany, null);
+            JSONObject data = getManagerData(accountIds, userId, mediaId, companyId, bjCompany, null, startTime, endTime);
             result = Result.ok(data);
             result = Result.ok(data);
         } else {
         } else {
             result = Result.error("该用户角色权限不足!");
             result = Result.error("该用户角色权限不足!");
@@ -113,7 +113,7 @@ public class ManagerSaleValueServiceImpl extends ServiceImpl<ManagerSaleValueMap
     }
     }
 
 
 
 
-    private JSONObject getManagerData(List<Long> accountIds, String userId, String mediaId, String companyId, boolean bjCompany, List<String> saleTeaMber) throws ParseException {
+    private JSONObject getManagerData(List<Long> accountIds, String userId, String mediaId, String companyId, boolean bjCompany, List<String> saleTeaMber, String startTime, String endTime) throws ParseException {
         //当天日期
         //当天日期
         String statDay = DateUtils.date2Str();
         String statDay = DateUtils.date2Str();
         //当前小时数
         //当前小时数
@@ -148,15 +148,19 @@ public class ManagerSaleValueServiceImpl extends ServiceImpl<ManagerSaleValueMap
             result.put("realCharged", realCharged.getBigDecimal("realCharged"));
             result.put("realCharged", realCharged.getBigDecimal("realCharged"));
             result.put("realChargedRoi", realCharged.getString("realChargedRoi"));
             result.put("realChargedRoi", realCharged.getString("realChargedRoi"));
             if (bjCompany) {
             if (bjCompany) {
+                long days = DateUtils.getDiscrepantDays(startTime, endTime) + 1;
+                if (!startTime.equals(endTime)) {
+                    hour = 23;
+                }
                 //运营一部:李超及其下级 李超 id:f6a6843879c949618e4a859140c8a127
                 //运营一部:李超及其下级 李超 id:f6a6843879c949618e4a859140c8a127
                 oneAccountIds = baseMapper.querySalesDirectorAccountIds(companyId, mediaId, saleTeaMber, lichaoId);
                 oneAccountIds = baseMapper.querySalesDirectorAccountIds(companyId, mediaId, saleTeaMber, lichaoId);
-                JSONObject oneResult = baseMapper.queryTtTodayCharge(statDay, hour, oneAccountIds, companyId);
+                JSONObject oneResult = baseMapper.queryTtTodayCharge2(startTime, endTime, hour, oneAccountIds, companyId, days);
                 result.put("oneCharge", oneResult.getBigDecimal("totalCharge"));
                 result.put("oneCharge", oneResult.getBigDecimal("totalCharge"));
                 result.put("oneChargeRoi", oneResult.getString("chargeRoi"));
                 result.put("oneChargeRoi", oneResult.getString("chargeRoi"));
 
 
                 //运营二部:兰兰及其下级 兰兰id:461857c245f54ba5813bcb5900a23092
                 //运营二部:兰兰及其下级 兰兰id:461857c245f54ba5813bcb5900a23092
                 twoAccountIds = baseMapper.querySalesDirectorAccountIds(companyId, mediaId, saleTeaMber, lanlanId);
                 twoAccountIds = baseMapper.querySalesDirectorAccountIds(companyId, mediaId, saleTeaMber, lanlanId);
-                JSONObject twoResult = baseMapper.queryTtTodayCharge(statDay, hour, twoAccountIds, companyId);
+                JSONObject twoResult = baseMapper.queryTtTodayCharge2(startTime, endTime, hour, twoAccountIds, companyId, days);
                 result.put("twoCharge", twoResult.getBigDecimal("totalCharge"));
                 result.put("twoCharge", twoResult.getBigDecimal("totalCharge"));
                 result.put("twoChargeRoi", twoResult.getString("chargeRoi"));
                 result.put("twoChargeRoi", twoResult.getString("chargeRoi"));
             }
             }
@@ -173,15 +177,19 @@ public class ManagerSaleValueServiceImpl extends ServiceImpl<ManagerSaleValueMap
             result.put("realCharged", realCharged.getBigDecimal("realCharged"));
             result.put("realCharged", realCharged.getBigDecimal("realCharged"));
             result.put("realChargedRoi", realCharged.getString("realChargedRoi"));
             result.put("realChargedRoi", realCharged.getString("realChargedRoi"));
             if (bjCompany) {
             if (bjCompany) {
+                long days = DateUtils.getDiscrepantDays(startTime, endTime) + 1;
+                if (!startTime.equals(endTime)) {
+                    hour = 23;
+                }
                 //运营一部:李超及其下级 李超 id:f6a6843879c949618e4a859140c8a127
                 //运营一部:李超及其下级 李超 id:f6a6843879c949618e4a859140c8a127
                 oneAccountIds = baseMapper.querySalesDirectorAccountIds(companyId, mediaId, saleTeaMber, lichaoId);
                 oneAccountIds = baseMapper.querySalesDirectorAccountIds(companyId, mediaId, saleTeaMber, lichaoId);
-                JSONObject oneResult = baseMapper.queryKsTodayCharge(statDay, hour, oneAccountIds, companyId);
+                JSONObject oneResult = baseMapper.queryKsTodayCharge2(startTime, endTime, hour, oneAccountIds, companyId, days);
                 result.put("oneCharge", oneResult.getBigDecimal("totalCharge"));
                 result.put("oneCharge", oneResult.getBigDecimal("totalCharge"));
                 result.put("oneChargeRoi", oneResult.getString("chargeRoi"));
                 result.put("oneChargeRoi", oneResult.getString("chargeRoi"));
 
 
                 //运营二部:兰兰及其下级 兰兰id:461857c245f54ba5813bcb5900a23092
                 //运营二部:兰兰及其下级 兰兰id:461857c245f54ba5813bcb5900a23092
                 twoAccountIds = baseMapper.querySalesDirectorAccountIds(companyId, mediaId, saleTeaMber, lanlanId);
                 twoAccountIds = baseMapper.querySalesDirectorAccountIds(companyId, mediaId, saleTeaMber, lanlanId);
-                JSONObject twoResult = baseMapper.queryKsTodayCharge(statDay, hour, twoAccountIds, companyId);
+                JSONObject twoResult = baseMapper.queryKsTodayCharge2(startTime, endTime, hour, twoAccountIds, companyId, days);
                 result.put("twoCharge", twoResult.getBigDecimal("totalCharge"));
                 result.put("twoCharge", twoResult.getBigDecimal("totalCharge"));
                 result.put("twoChargeRoi", twoResult.getString("chargeRoi"));
                 result.put("twoChargeRoi", twoResult.getString("chargeRoi"));
             }
             }