浏览代码

Merge remote-tracking branch 'origin/master'

zhaoxian 1 年之前
父节点
当前提交
12ae27241c

+ 159 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/report/controller/SalesBudgetController.java

@@ -0,0 +1,159 @@
+package cn.com.ctop.kuaishou.modules.report.controller;
+
+import cn.com.ctop.common.module.service.ISysUserService;
+import cn.com.ctop.common.module.utils.Check;
+import cn.com.ctop.kuaishou.modules.report.service.ISalesBudgetService;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import org.jeecg.common.api.vo.Result;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.List;
+
+@RestController
+@RequestMapping("/budget")
+public class SalesBudgetController {
+    @Autowired
+    private ISalesBudgetService salesBudgetService;
+    @Autowired
+    private ISysUserService sysUserService;
+
+    @GetMapping("/report")
+    public Result<Object> getOperateGroupInfo(String userId, String mediaId, String date, Integer pageNo, Integer pageSize) {
+        try {
+
+            if (Check.isNull(date)) {
+                throw new Exception("请传入日期");
+            }
+            String roleCode = sysUserService.getRoleCodeByUserId(userId);
+            String saleId = null;
+            if (!"admin".equals(roleCode) && !"saleDirector".equals(roleCode)) {
+                saleId = userId;
+            }
+            Long statDate = Long.valueOf(date.replace("-", ""));
+            if ("1".equals(mediaId)) {
+                return salesBudgetService.bytedanceSalesReport(saleId, statDate, pageNo, pageSize);
+            } else {
+                return salesBudgetService.kuaiShouSalesReport(saleId, statDate, pageNo, pageSize);
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return Result.error("查询失败");
+    }
+
+    @GetMapping("/ocpxList")
+    public Result<List> ocpxList(String mediaId) {
+        try {
+
+            if (Check.isNull(mediaId)) {
+                throw new Exception("媒体");
+            }
+            List<JSONObject> jsonObjects = salesBudgetService.ocpxList(mediaId);
+            return Result.OK(jsonObjects);
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return Result.error("失败", null);
+    }
+
+
+    @GetMapping("/add")
+    public JSONObject add(String mediaId, String userId, String addInfo) {
+
+        JSONObject returnJson = new JSONObject();
+        try {
+            if (Check.isNull(mediaId)) {
+                throw new Exception("请传入媒体");
+            }
+
+            if (Check.isNull(userId)) {
+                throw new Exception("请传入用户ID");
+            }
+            JSONObject addInfoJson = JSONObject.parseObject(addInfo);
+
+            if (Check.isNull(addInfoJson)) {
+                throw new Exception("请传入出价信息");
+            }
+
+            Long projectId = addInfoJson.getLong("projectId");
+            if (Check.isNull(projectId)) {
+                throw new Exception("请传入项目ID");
+            }
+            BigDecimal budget = addInfoJson.getBigDecimal("budget");
+         /*   BigDecimal budget = addInfoJson.getBigDecimal("budget");
+            if (Check.isNull(budget)) {
+                throw new Exception("请传入预算信息");
+            }*/
+
+            JSONArray ruleDetails = addInfoJson.getJSONArray("ruleDetails");
+            if (Check.isNull(ruleDetails)) {
+                throw new Exception("请传入出价信息");
+            }
+            salesBudgetService.deleteInfo(projectId);
+            List<JSONObject> addList = new ArrayList<>();
+            if (!Check.isNull(budget)) {
+                JSONObject budgetInfo = new JSONObject();
+                budgetInfo.put("projectId", projectId);
+                budgetInfo.put("mediaId", mediaId);
+                budgetInfo.put("userId", userId);
+                budgetInfo.put("budgetKey", "budget");
+                budgetInfo.put("budgetVale", "预算");
+                budgetInfo.put("maxValue", budget);
+                addList.add(budgetInfo);
+            }
+
+            for (int i = 0; i < ruleDetails.size(); i++) {
+                JSONObject addJson = new JSONObject();
+                addJson.put("projectId", projectId);
+                addJson.put("mediaId", mediaId);
+                addJson.put("userId", userId);
+                JSONObject jsonObject = ruleDetails.getJSONObject(i);
+                String budget_key = jsonObject.getString("ocpxCode");
+                String budget_vale = jsonObject.getString("ocpxName");
+                BigDecimal maxValue = jsonObject.getBigDecimal("maxValue");
+                addJson.put("budgetKey", budget_key);
+                addJson.put("budgetVale", budget_vale);
+                addJson.put("maxValue", maxValue);
+                addList.add(addJson);
+            }
+            salesBudgetService.adds(addList);
+            returnJson.put("success", true);
+            returnJson.put("message", "设置成功");
+        } catch (Exception e) {
+            e.printStackTrace();
+            returnJson.put("success", false);
+            returnJson.put("message", e.getMessage());
+        }
+        return returnJson;
+    }
+
+
+    @GetMapping("/getById")
+    public JSONObject getById(Long projectId) {
+
+        JSONObject returnJson = new JSONObject();
+        try {
+            if (Check.isNull(projectId)) {
+                throw new Exception("请传入项目ID");
+            }
+            JSONObject data = salesBudgetService.getById(projectId);
+            returnJson.put("success", true);
+            returnJson.put("message", "设置成功");
+            returnJson.put("data", data);
+        } catch (Exception e) {
+            e.printStackTrace();
+            returnJson.put("success", false);
+            returnJson.put("message", e.getMessage());
+        }
+        return returnJson;
+    }
+
+
+}

+ 26 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/SalesBudgetMapper.java

@@ -0,0 +1,26 @@
+package cn.com.ctop.kuaishou.modules.report.mapper;
+
+import com.alibaba.fastjson.JSONObject;
+import org.apache.ibatis.annotations.Param;
+import org.jeecg.common.api.vo.Result;
+
+import java.math.BigDecimal;
+import java.util.List;
+
+public interface SalesBudgetMapper {
+    List<JSONObject> bytedanceSalesReport(@Param("saleId") String saleId, @Param("statDate") Long statDate);
+
+    List<JSONObject> kuaiShouSalesReport(@Param("saleId") String saleId, @Param("statDate") Long statDate);
+
+    List<JSONObject> ocpxList(@Param("mediaId") String mediaId);
+
+    void deleteInfo(@Param("projectId") Long projectId);
+
+    void adds(@Param("list") List<JSONObject> list);
+
+    BigDecimal getBudget(@Param("projectId") Long projectId);
+
+    List<JSONObject> getBudgetList(@Param("projectId") Long projectId);
+
+    List<JSONObject> getConfigs(Long projectId);
+}

+ 130 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/xml/SalesBudgetMapper.xml

@@ -0,0 +1,130 @@
+<?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.report.mapper.SalesBudgetMapper">
+    <insert id="adds" >
+        insert into ctop_sale_project_budget_set (
+        project_id,
+        media_id,
+        budget_key,
+        budget_vale,
+        max_value,
+        user_id
+        ) values
+        <foreach collection="list" item="item" index="index" separator=",">
+            (
+            #{item.projectId},
+            #{item.mediaId},
+            #{item.budgetKey},
+            #{item.budgetVale},
+            #{item.maxValue},
+            #{item.userId}
+            )
+        </foreach>
+    </insert>
+    <delete id="deleteInfo" parameterType="java.lang.Long">
+        delete
+        from ctop_sale_project_budget_set
+        where project_id = #{projectId}
+    </delete>
+
+    <select id="bytedanceSalesReport" resultType="com.alibaba.fastjson.JSONObject"
+            parameterType="java.lang.Long">
+        select t1.*,
+        substring(t2.realname,1,3) as 'saleName',
+        (select substring(realname,1,3) from `jeecg-boot`.sys_user where id = t3.responsible_id) as 'responsibleName'
+        from (SELECT sale_id as 'saleId',
+        project_id as 'projectId',
+        project_name as 'projectName',
+        sum(cost) as 'budget',
+        sum(active) as 'active',
+        ROUND(sum(cost) / sum(active), 3) as 'activeCost',
+        sum(attribution_next_day_open_cnt) as 'attributionNextDayOpenCnt',
+        ROUND(sum(attribution_next_day_open_cnt) / sum(active) * 100, 3) as 'attributionNextDayOpenRate',
+        ROUND(sum(cost) / sum(attribution_next_day_open_cnt), 3) as 'attributionNextDayOpenCost',
+        sum(pay_count) as 'payCount',
+        ROUND(sum(cost) / sum(pay_count), 3) as 'payCost',
+        sum(form) as 'form',
+        ROUND(sum(cost) / sum(form), 3) as 'formCost',
+        sum(register) as 'register',
+        ROUND(sum(cost) / sum(register), 3) as 'registerCost',
+        sum(game_addiction) as 'gameAddiction',
+        ROUND(sum(cost) / sum(game_addiction), 3) as 'gameAddictionCost',
+        sum(loan_completion) as 'loanCompletion',
+        ROUND(sum(cost) / sum(loan_completion), 3) as 'loanCompletionCost',
+        sum(pre_loan_credit) as 'preLoanCredit',
+        ROUND(sum(cost) / sum(pre_loan_credit), 3) as 'preLoanCreditCost',
+        sum(in_app_uv) as 'inAppUv',
+        ROUND(sum(cost) / sum(in_app_uv), 3) as 'inAppUvCost',
+        sum(in_app_pay) as 'inAppPay',
+        ROUND(sum(cost) / sum(in_app_pay), 3) as 'inAppPayCost',
+        ROUND(sum(cost) / sum(stat_pay_amount), 3) as 'statPayAmount'
+        FROM application.bytedance_advertiser_report_daily_dw
+        WHERE stat_datetime = #{statDate}
+        <if test="saleId != null and saleId != ''">
+            and sale_id = #{saleId}
+        </if>
+        GROUP BY project_id) t1
+        left join `jeecg-boot`.sys_user t2 on t1.saleId = t2.id
+        left join `jeecg-boot`.ctop_project t3 on t1.projectId = t3.id
+        order by t1.budget desc
+
+    </select>
+    <select id="kuaiShouSalesReport" resultType="com.alibaba.fastjson.JSONObject"
+            parameterType="java.lang.Long">
+        select t1.*,
+        replace(t2.realname,'(汇创)','') as 'saleName',
+        (select replace(realname,'(汇创)','') from `jeecg-boot`.sys_user where id = t3.responsible_id) as
+        'responsibleName'
+        from (SELECT sale_id as 'saleId',
+        project_id as 'projectId',
+        project_name as 'projectName',
+        SUM(charge) AS 'budget',
+        sum(activation) as 'activation',
+        ROUND(sum(charge) / sum(activation), 3) AS 'activationCost',
+        sum(event_next_day_stay) as 'eventNextDayStay',
+        ROUND(sum(event_next_day_stay) / sum(activation) * 100, 3) as 'eventNextDayStayRate',
+        ROUND(sum(charge) / sum(event_next_day_stay), 3) AS 'eventNextDayStayCost',
+        sum(form_count) as 'formCount',
+        ROUND(sum(charge) / sum(form_count), 3) AS 'formCountCost',
+        sum(event_pay) as 'eventPay',
+        ROUND(sum(charge) / sum(event_pay), 3) AS 'eventCost',
+        sum(key_action) as 'keyAction',
+        ROUND(sum(charge) / sum(key_action), 3) AS 'keyActionCost',
+        sum(event_app_invoked) as 'eventAppInvoked',
+        ROUND(sum(charge) / sum(event_app_invoked), 3) AS 'eventAppInvokedCost',
+        ROUND(sum(charge) / sum(event_pay_purchase_amount_first_day), 3) AS 'eventPayPurchaseAmountFirstDayCost',
+        ROUND(sum(charge) / sum(event_three_day_stay_by_conversion), 3) AS 'eventThreeDayStayByConversionCost',
+        ROUND(sum(charge) / sum(event_week_stay_by_conversion), 3) AS 'eventWeekStayByConversionCost'
+        FROM application.kuaishou_account_report_daily_dw
+        WHERE stat_date = #{statDate}
+        <if test="saleId != null and saleId != ''">
+            and sale_id = #{saleId}
+        </if>
+        GROUP BY project_id) t1
+        left join `jeecg-boot`.sys_user t2 on t1.saleId = t2.id
+        left join `jeecg-boot`.ctop_project t3 on t1.projectId = t3.id
+        order by t1.budget desc
+
+    </select>
+    <select id="ocpxList" resultType="com.alibaba.fastjson.JSONObject" parameterType="java.lang.String">
+        select budget_key as 'ocpxActionType',budget_vale as 'ocpxActionName'
+        from ctop_sale_budget_config
+        where media_id = #{mediaId}
+    </select>
+    <select id="getBudget" resultType="java.math.BigDecimal" parameterType="java.lang.Long">
+        select max_value as 'maxValue'  from ctop_sale_project_budget_set where project_id = #{projectId} and budget_key = 'budget'
+    </select>
+    <select id="getBudgetList" resultType="com.alibaba.fastjson.JSONObject" parameterType="java.lang.Long">
+        select  budget_key as  'ocpxCode',
+                budget_vale as 'ocpxName',
+                max_value as   'maxValue'
+        from ctop_sale_project_budget_set
+        where project_id = #{projectId}
+          and budget_key != 'budget'
+    </select>
+    <select id="getConfigs" resultType="com.alibaba.fastjson.JSONObject" parameterType="java.lang.Long">
+        select budget_key as  'ocpxCode', budget_vale as 'ocpxName', max_value as   'maxValue'
+        from ctop_sale_project_budget_set
+        where project_id = #{projectId}
+    </select>
+</mapper>

+ 21 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/report/service/ISalesBudgetService.java

@@ -0,0 +1,21 @@
+package cn.com.ctop.kuaishou.modules.report.service;
+
+
+import com.alibaba.fastjson.JSONObject;
+import org.jeecg.common.api.vo.Result;
+
+import java.util.List;
+
+public interface ISalesBudgetService {
+    Result<Object> bytedanceSalesReport(String saleId,Long statDate,Integer pageNo, Integer pageSize);
+
+    Result<Object> kuaiShouSalesReport(String saleId,Long statDate, Integer pageNo, Integer pageSize);
+
+    List<JSONObject> ocpxList(String mediaId);
+
+    void deleteInfo(Long projectId);
+
+    void adds(List<JSONObject> addList);
+
+    JSONObject getById(Long projectId);
+}

+ 195 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/report/service/impl/SalesBudgetServiceImpl.java

@@ -0,0 +1,195 @@
+package cn.com.ctop.kuaishou.modules.report.service.impl;
+
+import cn.com.ctop.common.module.utils.Check;
+import cn.com.ctop.kuaishou.modules.report.mapper.SalesBudgetMapper;
+import cn.com.ctop.kuaishou.modules.report.service.ISalesBudgetService;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.github.pagehelper.PageHelper;
+import com.github.pagehelper.PageInfo;
+import org.jeecg.common.api.vo.Result;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.math.BigDecimal;
+import java.util.List;
+
+@Service
+public class SalesBudgetServiceImpl implements ISalesBudgetService {
+    @Autowired
+    private SalesBudgetMapper salesBudgetMapper;
+
+    @Override
+    public Result<Object> bytedanceSalesReport(String saleId, Long statDate, Integer pageNo, Integer pageSize) {
+        PageHelper.startPage(pageNo, pageSize);
+        List<JSONObject> data = salesBudgetMapper.bytedanceSalesReport(saleId, statDate);
+        if (!Check.isNull(data)) {
+            for (int i = 0; i < data.size(); i++) {
+                JSONObject jsonObject = data.get(i);
+                Long projectId = jsonObject.getLong("projectId");
+                List<JSONObject> configs = salesBudgetMapper.getConfigs(projectId);
+                if (!Check.isNull(configs)) {
+                    JSONArray costArray = new JSONArray();
+                    boolean trueOrFalse = false;
+                    for (int j = 0; j < configs.size(); j++) {
+                        JSONObject configJson = configs.get(j);
+                        String ocpxCode = configJson.getString("ocpxCode");
+                        String ocpxName = configJson.getString("ocpxName");
+                        BigDecimal maxValue = configJson.getBigDecimal("maxValue");
+                        if ("budget".equals(ocpxCode)) {
+                            trueOrFalse = true;
+                            BigDecimal budget = jsonObject.getBigDecimal("budget");
+                            JSONObject budgetJson = new JSONObject();
+                            budgetJson.put("setBudget", maxValue);
+                            budgetJson.put("actualBudget", budget);
+                            BigDecimal subtract = budget.subtract(maxValue);
+                            int compare = subtract.compareTo(new BigDecimal(0));
+                            budgetJson.put("compare", compare);
+                            if (compare < 0) {
+                                budgetJson.put("subtract", subtract.multiply(new BigDecimal(-1)));
+                            } else if (compare == 0) {
+                                budgetJson.put("subtract", 0);
+                            } else {
+                                budgetJson.put("subtract", subtract);
+                            }
+
+
+                            jsonObject.put("budgetJson", budgetJson);
+                        } else {
+                            JSONObject costJson = new JSONObject();
+                            BigDecimal cost = jsonObject.getBigDecimal(ocpxCode);
+                            if (Check.isNull(cost)) {
+                                cost = new BigDecimal(0);
+                            }
+                            costJson.put("cost", cost);
+                            costJson.put("setCost", maxValue);
+                            costJson.put("name", ocpxName.replace("成本", ""));
+                            BigDecimal subtract = cost.subtract(maxValue);
+                            int compare = subtract.compareTo(new BigDecimal(0));
+                            costJson.put("compare", compare);
+                            costArray.add(costJson);
+                        }
+                        if (!trueOrFalse) {
+                            JSONObject budgetJson = new JSONObject();
+                            BigDecimal budget = jsonObject.getBigDecimal("budget");
+                            budgetJson.put("actualBudget", budget);
+                            budgetJson.put("setBudget", "不限");
+                            jsonObject.put("budgetJson", budgetJson);
+                        }
+                    }
+
+                    jsonObject.put("costArray", costArray);
+                } else {
+                    jsonObject.put("costArray", new JSONArray());
+
+                    JSONObject budgetJson = new JSONObject();
+                    BigDecimal budget = jsonObject.getBigDecimal("budget");
+                    budgetJson.put("actualBudget", budget);
+                    jsonObject.put("budgetJson", budgetJson);
+
+                }
+            }
+        }
+        return Result.ok(new PageInfo<>(data));
+    }
+
+    @Override
+    public Result<Object> kuaiShouSalesReport(String saleId, Long statDate, Integer pageNo, Integer pageSize) {
+        PageHelper.startPage(pageNo, pageSize);
+        List<JSONObject> data = salesBudgetMapper.kuaiShouSalesReport(saleId, statDate);
+        if (!Check.isNull(data)) {
+            for (int i = 0; i < data.size(); i++) {
+                JSONObject jsonObject = data.get(i);
+                Long projectId = jsonObject.getLong("projectId");
+                List<JSONObject> configs = salesBudgetMapper.getConfigs(projectId);
+                if (!Check.isNull(configs)) {
+                    JSONArray costArray = new JSONArray();
+                    boolean trueOrFalse = false;
+                    for (int j = 0; j < configs.size(); j++) {
+                        JSONObject configJson = configs.get(j);
+                        String ocpxCode = configJson.getString("ocpxCode");
+                        String ocpxName = configJson.getString("ocpxName");
+                        BigDecimal maxValue = configJson.getBigDecimal("maxValue");
+                        if ("budget".equals(ocpxCode)) {
+                            trueOrFalse = true;
+                            BigDecimal budget = jsonObject.getBigDecimal("budget");
+                            JSONObject budgetJson = new JSONObject();
+                            budgetJson.put("setBudget", maxValue);
+                            budgetJson.put("actualBudget", budget);
+                            BigDecimal subtract = budget.subtract(maxValue);
+                            int compare = subtract.compareTo(new BigDecimal(0));
+                            budgetJson.put("compare", compare);
+                            if (compare < 0) {
+                                budgetJson.put("subtract", subtract.multiply(new BigDecimal(-1)));
+                            } else if (compare == 0) {
+                                budgetJson.put("subtract", 0);
+                            } else {
+                                budgetJson.put("subtract", subtract);
+                            }
+                            jsonObject.put("budgetJson", budgetJson);
+                        } else {
+                            JSONObject costJson = new JSONObject();
+                            BigDecimal cost = jsonObject.getBigDecimal(ocpxCode);
+                            if (Check.isNull(cost)) {
+                                cost = new BigDecimal(0);
+                            }
+                            costJson.put("cost", cost);
+                            costJson.put("setCost", maxValue);
+                            costJson.put("name", ocpxName.replace("成本", ""));
+                            BigDecimal subtract = cost.subtract(maxValue);
+                            int compare = subtract.compareTo(new BigDecimal(0));
+                            costJson.put("compare", compare);
+                            costArray.add(costJson);
+                        }
+                        if (!trueOrFalse) {
+                            JSONObject budgetJson = new JSONObject();
+                            BigDecimal budget = jsonObject.getBigDecimal("budget");
+                            budgetJson.put("actualBudget", budget);
+                            budgetJson.put("setBudget", "不限");
+                            jsonObject.put("budgetJson", budgetJson);
+                        }
+                    }
+                    jsonObject.put("costArray", costArray);
+                } else {
+                    jsonObject.put("costArray", new JSONArray());
+
+                    JSONObject budgetJson = new JSONObject();
+                    BigDecimal budget = jsonObject.getBigDecimal("budget");
+                    budgetJson.put("actualBudget", budget);
+                    jsonObject.put("budgetJson", budgetJson);
+
+                }
+            }
+
+        }
+
+        return Result.ok(new PageInfo<>(data));
+    }
+
+    @Override
+    public List<JSONObject> ocpxList(String mediaId) {
+        return salesBudgetMapper.ocpxList(mediaId);
+    }
+
+    @Override
+    public void deleteInfo(Long projectId) {
+        salesBudgetMapper.deleteInfo(projectId);
+    }
+
+    @Override
+    public void adds(List<JSONObject> addList) {
+        salesBudgetMapper.adds(addList);
+    }
+
+    @Override
+    public JSONObject getById(Long projectId) {
+        JSONObject json = new JSONObject();
+
+        BigDecimal budget = salesBudgetMapper.getBudget(projectId);
+        json.put("budget", budget);
+        List<JSONObject> ruleDetails = salesBudgetMapper.getBudgetList(projectId);
+        json.put("ruleDetails", ruleDetails);
+
+        return json;
+    }
+}