yumeng 6 ヶ月 前
コミット
b9cf5662b3

+ 1 - 1
ruixuan-live/src/main/java/com/ruixuan/isc/controller/KwaiJSTController.java

@@ -96,7 +96,7 @@ public class KwaiJSTController {
                 @Override
                 public void run() {
                     try {
-                        kwaiJSTService.cleanCost(skuId);
+                        kwaiJSTService.cleanCost(skuId, 0);
                     } catch (Exception e) {
                         e.printStackTrace();
                     }

+ 127 - 2
ruixuan-live/src/main/java/com/ruixuan/isc/controller/KwaiXiaoDianReportController.java

@@ -37,6 +37,8 @@ public class KwaiXiaoDianReportController {
     private IKwaixiaodianItemGetService kwaixiaodianItemGetService;
 
     // 供应链盯盘数据
+
+
     @GetMapping("/getSumInfo")
     public JSONObject getSumInfo(Long userId, String startDate, String endDate, Long companyId) {
         JSONObject returnJson = new JSONObject();
@@ -251,9 +253,9 @@ public class KwaiXiaoDianReportController {
             List<JSONObject> today = kwaiXiaoDianReportService.getGmvHours(requestMap);
             String lastDate = null;
             if (hourType == 1) {
-                 lastDate = DateUtils.getAnotherDay("yyyy-MM-dd", nowDate, -1);  //  日期 -1
+                lastDate = DateUtils.getAnotherDay("yyyy-MM-dd", nowDate, -1);  //  日期 -1
             } else if (hourType == 2) {
-                 lastDate = DateUtils.getAnotherDay("yyyy-MM-dd", nowDate, -7);  //  日期 -7
+                lastDate = DateUtils.getAnotherDay("yyyy-MM-dd", nowDate, -7);  //  日期 -7
             }
             requestMap.put("date", DateUtils.strDateToInt(lastDate));
             List<JSONObject> yesterday = kwaiXiaoDianReportService.getGmvHours(requestMap);
@@ -613,4 +615,127 @@ public class KwaiXiaoDianReportController {
     }
 
 
+    @GetMapping("/getCostTotal")
+    public JSONObject getCostTotal(Long userId, String startDate, String endDate, Long companyId) {
+        JSONObject returnJson = new JSONObject();
+        try {
+            if (Check.isNull(userId)) {
+                throw new Exception("请传入用户ID");
+            }
+            Map<String, Object> requestMap = new HashMap<>();
+            String roleId = sysRoleService.getRoleBYUserId(userId);
+            if ("admin".equals(roleId)) { // 管理员查看所有
+                if (!Check.isNull(companyId)) {
+                    requestMap.put("companyId", companyId);
+                }
+            } else if ("industry_admin".equals(roleId)) { // 供应链管理员查看所属公司
+                companyId = kwaixiaodianItemGetService.getCompanyId(userId);
+                if (Check.isNull(companyId)) {
+                    throw new Exception("此用户未查询到归属公司");
+                }
+                requestMap.put("companyId", companyId);
+            }
+
+            Long start = DateUtils.strDateToInt(startDate);
+            Long end = DateUtils.strDateToInt(endDate);
+            requestMap.put("start", start);
+            requestMap.put("end", end);
+            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
+            int differDay = DateUtils.differentDaysByMillisecond(simpleDateFormat.parse(startDate), simpleDateFormat.parse(endDate));
+            String lastEndStr = DateUtils.getAnotherDay("yyyy-MM-dd", startDate, -1); // 上一时段结束日期
+            String lastStartStr = DateUtils.getAnotherDay("yyyy-MM-dd", lastEndStr, -differDay); // 上一时段开始日期
+            requestMap.put("lastEnd", DateUtils.strDateToInt(lastEndStr));
+            requestMap.put("lastStart", DateUtils.strDateToInt(lastStartStr));
+
+            JSONObject data = kwaiXiaoDianReportService.getCostTotal(requestMap);
+            returnJson.put("code", 200);
+            returnJson.put("data", data);
+            returnJson.put("success", true);
+        } catch (Exception e) {
+            e.printStackTrace();
+            returnJson.put("code", 500);
+            returnJson.put("message", e.getMessage());
+        }
+        return returnJson;
+    }
+
+
+    @GetMapping("/getCostDate")
+    public JSONObject getCostDate(Long userId, String startDate, String endDate, Long companyId) {
+        JSONObject returnJson = new JSONObject();
+        try {
+            if (Check.isNull(userId)) {
+                throw new Exception("请传入用户ID");
+            }
+            Map<String, Object> requestMap = new HashMap<>();
+            String roleId = sysRoleService.getRoleBYUserId(userId);
+            if ("admin".equals(roleId)) { // 管理员查看所有
+                if (!Check.isNull(companyId)) {
+                    requestMap.put("companyId", companyId);
+                }
+            } else if ("industry_admin".equals(roleId)) { // 供应链管理员查看所属公司
+                companyId = kwaixiaodianItemGetService.getCompanyId(userId);
+                if (Check.isNull(companyId)) {
+                    throw new Exception("此用户未查询到归属公司");
+                }
+                requestMap.put("companyId", companyId);
+            }
+
+            Long start = DateUtils.strDateToInt(startDate);
+            Long end = DateUtils.strDateToInt(endDate);
+            requestMap.put("start", start);
+            requestMap.put("end", end);
+
+            List<JSONObject> data = kwaiXiaoDianReportService.getCostDate(requestMap);
+            returnJson.put("code", 200);
+            returnJson.put("data", data);
+            returnJson.put("success", true);
+        } catch (Exception e) {
+            e.printStackTrace();
+            returnJson.put("code", 500);
+            returnJson.put("message", e.getMessage());
+        }
+        return returnJson;
+    }
+
+    @GetMapping("/getItemCostList")
+    public TableDataInfo getItemCostList(String startDate, String endDate, Long userId, Long companyId, Integer pageNum, Integer pageSize, Integer itemType) {
+        TableDataInfo rspData = new TableDataInfo();
+        try {
+            if (Check.isNull(userId)) {
+                throw new Exception("请传入用户ID");
+            }
+            Map<String, Object> requestMap = new HashMap<>();
+            String roleId = sysRoleService.getRoleBYUserId(userId);
+            if ("admin".equals(roleId)) { // 管理员查看所有
+                if (!Check.isNull(companyId)) {
+                    requestMap.put("companyId", companyId);
+                }
+            } else if ("industry_admin".equals(roleId)) { // 供应链管理员查看所属公司
+                companyId = kwaixiaodianItemGetService.getCompanyId(userId);
+                if (Check.isNull(companyId)) {
+                    throw new Exception("此用户未查询到归属公司");
+                }
+                requestMap.put("companyId", companyId);
+            }
+
+            Long start = DateUtils.strDateToInt(startDate);
+            Long end = DateUtils.strDateToInt(endDate);
+            requestMap.put("start", start);
+            requestMap.put("end", end);
+
+
+            startPage(pageNum, pageSize);
+            List<JSONObject> list = kwaiXiaoDianReportService.getItemCostList(requestMap);
+            rspData.setCode(HttpStatus.SUCCESS);
+            rspData.setMsg("查询成功");
+            rspData.setRows(list);
+            rspData.setTotal(new PageInfo(list).getTotal());
+        } catch (Exception e) {
+            e.printStackTrace();
+            rspData.setCode(HttpStatus.ERROR);
+            rspData.setMsg(e.getMessage());
+        }
+        return rspData;
+    }
 }

+ 6 - 0
ruixuan-live/src/main/java/com/ruixuan/isc/mapper/KwaiXiaoDianReportMapper.java

@@ -25,4 +25,10 @@ public interface KwaiXiaoDianReportMapper {
     List<JSONObject> getTeamDetail(Map<String, Object> requestMap);
 
     List<JSONObject> getItemList(Map<String, Object> requestMap);
+
+    JSONObject getCostTotal(Map<String, Object> requestMap);
+
+    List<JSONObject> getCostDate(Map<String, Object> requestMap);
+
+    List<JSONObject> getItemCostList(Map<String, Object> requestMap);
 }

+ 1 - 1
ruixuan-live/src/main/java/com/ruixuan/isc/service/IKwaiJSTService.java

@@ -15,7 +15,7 @@ public interface IKwaiJSTService {
 
     List<JSONObject> getSkuDataList(Long date);
 
-    JSONObject cleanCost(String skuNick);
+    JSONObject cleanCost(String skuNick,Integer cunt);
 
     List<JSONObject> getCleanDataList(Long date);
 }

+ 6 - 0
ruixuan-live/src/main/java/com/ruixuan/isc/service/IKwaiXiaoDianReportService.java

@@ -21,4 +21,10 @@ public interface IKwaiXiaoDianReportService {
     List<JSONObject> getTeamDetail(Map<String, Object> requestMap);
 
     List<JSONObject> getItemList(Map<String, Object> requestMap);
+
+    JSONObject getCostTotal(Map<String, Object> requestMap);
+
+    List<JSONObject> getCostDate(Map<String, Object> requestMap);
+
+    List<JSONObject> getItemCostList(Map<String, Object> requestMap);
 }

+ 7 - 15
ruixuan-live/src/main/java/com/ruixuan/isc/service/impl/KwaiJSTServiceImpl.java

@@ -236,19 +236,6 @@ public class KwaiJSTServiceImpl implements IKwaiJSTService {
     }
 
 
-    public static void main(String[] args) {
-        List<Integer> list = new ArrayList<>();
-        list.add(1);
-        list.add(2);
-        list.add(3);
-        list.add(4);
-        List<Integer> list2 = new ArrayList<>();
-        list2.add(5);
-        list2.add(6);
-        list.addAll(list2);
-        System.err.println(list);
-    }
-
     @Override
     public JSONObject costDetail(String skuNick, Integer dataType, Long date) {
         JSONObject returnJSon = new JSONObject();
@@ -369,7 +356,7 @@ public class KwaiJSTServiceImpl implements IKwaiJSTService {
     }
 
     @Override
-    public JSONObject cleanCost(String skuNick) {
+    public JSONObject cleanCost(String skuNick, Integer count) {
         JSONObject returnJson = new JSONObject();
 
         try {
@@ -450,8 +437,13 @@ public class KwaiJSTServiceImpl implements IKwaiJSTService {
             }
             log.info("{},suk数据处理最终清洗完成", skuNick);
         } catch (Exception e) {
+
             e.printStackTrace();
-            this.send("快手小店成本数据清洗失败,请处理,序号:2,sukId:" + skuNick + "  ," + e.getMessage());
+            this.send("快手小店成本数据清洗失败,请处理,序号:2,失败次数:" + count + "sukId:" + skuNick + "  ," + e.getMessage());
+            if (count <= 3) {
+                cleanCost(skuNick, count + 1);
+            }
+
         }
 
         return null;

+ 15 - 0
ruixuan-live/src/main/java/com/ruixuan/isc/service/impl/KwaiXiaoDianReportServiceImpl.java

@@ -89,4 +89,19 @@ public class KwaiXiaoDianReportServiceImpl implements IKwaiXiaoDianReportService
     public List<JSONObject> getItemList(Map<String, Object> requestMap) {
         return kwaiXiaoDianReportMapper.getItemList(requestMap);
     }
+
+    @Override
+    public JSONObject getCostTotal(Map<String, Object> requestMap) {
+        return kwaiXiaoDianReportMapper.getCostTotal(requestMap);
+    }
+
+    @Override
+    public List<JSONObject> getCostDate(Map<String, Object> requestMap) {
+        return kwaiXiaoDianReportMapper.getCostDate(requestMap);
+    }
+
+    @Override
+    public List<JSONObject> getItemCostList(Map<String, Object> requestMap) {
+        return kwaiXiaoDianReportMapper.getItemCostList(requestMap);
+    }
 }

+ 139 - 2
ruixuan-live/src/main/resources/mapper/isc/KwaiXiaoDianReportMapper.xml

@@ -8,7 +8,8 @@
     <select id="getSumInfo" resultType="com.alibaba.fastjson.JSONObject">
         SELECT round((t.orderNum - tt.orderNum) / tt.orderNum * 100, 2) AS 'orderNumRate',
         round((t.totalFee - tt.totalFee) / tt.totalFee * 100, 2) AS 'totalFeeRate',
-        t.*,ttt.*
+        t.*,ttt.*,ifnull(tttt.costPrice,0) as 'costPrice',
+        ifnull(round(ttt.estimatedIncome - tttt.costPrice,3 ) , 0) as 'estimatedGrossProfit'
         FROM (
         SELECT COUNT(t1.oid) AS 'orderNum',
         IFNULL(SUM(CASE WHEN t1.status != 80 AND t1.status != 10 THEN 1 ELSE 0 END), 0) AS 'validOrderNum',
@@ -115,7 +116,16 @@
             </foreach>
         </if>
 
-        ) ttt
+        ) ttt join
+        (
+        select sum(cost_price) as 'costPrice'
+        from kwaixiaodian_cost_detail_end
+        where send_time &gt;= #{start}
+        AND send_time &lt;= #{end}
+        <if test='companyId != null and companyId != ""'>
+            and company_id = #{companyId}
+        </if>
+        )tttt
     </select>
     <select id="getMonthInfo" resultType="com.alibaba.fastjson.JSONObject">
         SELECT round((t.orderNum - tt.orderNum) / tt.orderNum * 100, 2) AS 'orderNumRate',
@@ -810,4 +820,131 @@
         order by t1.orderNum desc
 
     </select>
+    <select id="getCostTotal" resultType="com.alibaba.fastjson.JSONObject">
+        select
+        ifnull(t1.income, 0) as 'income',
+        ifnull(round((t1.income - t2.income) / t2.income * 100, 2) , 0) as 'incomeRate',
+        ifnull(t3.costPrice, 0) as 'costPrice',
+        ifnull(round((t3.costPrice - t4.costPrice) / t4.costPrice * 100, 2), 0) as 'costPriceRate',
+        ifnull(t5.purchaseCost , 0) as 'purchaseCost',
+        ifnull(round((t5.purchaseCost - t6.purchaseCost) / t6.purchaseCost * 100, 2), 0) as 'purchaseCostRate'
+        from (select round(
+        sum(total_fee) / 100, 2
+        ) as 'income'
+        from kwaixiaodian_order_cursor_list
+        where send_time &gt;= #{start}
+        and send_time &lt;= #{end}
+        <if test='companyId != null and companyId != ""'>
+            and company_id = #{companyId}
+        </if>
+        and status in (40, 50, 70) ) t1
+        join (
+        select round(
+        sum(total_fee) / 100, 2
+        ) as 'income'
+        from kwaixiaodian_order_cursor_list
+        where send_time &gt;= #{lastStart}
+        and send_time &lt;= #{lastEnd}
+        <if test='companyId != null and companyId != ""'>
+            and company_id = #{companyId}
+        </if>
+        and status in (40, 50, 70) ) t2
+        join (
+        select round(sum(cost_price), 2) as 'costPrice'
+        from kwaixiaodian_cost_detail_end
+        where send_time &gt;= #{start}
+        and send_time &lt;= #{end}
+        <if test='companyId != null and companyId != ""'>
+            and company_id = #{companyId}
+        </if>
+        ) t3
+        join (select round(sum(cost_price), 2) as 'costPrice'
+        from kwaixiaodian_cost_detail_end
+        where send_time &gt;= #{lastStart}
+        and send_time &lt;= #{lastEnd}
+        <if test='companyId != null and companyId != ""'>
+            and company_id = #{companyId}
+        </if>) t4
+        join (
+        select round(sum(t2.price * t2.qty), 2) as 'purchaseCost'
+        from kwaixiaodian_jst_purchase t1
+        left join kwaixiaodian_jst_purchase_items t2
+        on t1.po_id = t2.po_id
+        where t1.po_date &gt;= concat(date_format(#{start}, '%Y-%m-%d'), '00:00:01')
+        and t1.po_date &lt;= concat(date_format(#{end}, '%Y-%m-%d'), '23:59:59')
+        and t1.status in ('Confirmed', 'Finished')) t5
+
+
+        join (select round(sum(t2.price * t2.qty), 2) as 'purchaseCost'
+        from kwaixiaodian_jst_purchase t1
+        left join kwaixiaodian_jst_purchase_items t2
+        on t1.po_id = t2.po_id
+        where t1.po_date &gt;=str_to_date(concat(date_format( #{lastStart}, '%Y-%m-%d'), '00:00:01'), '%Y-%m-%d
+        %H:%i:%s')
+        and t1.po_date &lt;=str_to_date(concat(date_format( #{lastEnd}, '%Y-%m-%d'), '23:59:59'), '%Y-%m-%d
+        %H:%i:%s')
+        and t1.status in ('Confirmed', 'Finished')) t6
+
+    </select>
+    <select id="getCostDate" resultType="com.alibaba.fastjson.JSONObject">
+        select send_time as 'sendTime',
+        round(sum(total_fee) / 100, 2) as 'totalFee'
+        from kwaixiaodian_order_cursor_list
+        where send_time &gt;= #{start}
+        and send_time &lt;= #{end}
+        <if test='companyId != null and companyId != ""'>
+            and company_id = #{companyId}
+        </if>
+        and status in(40,50,70)
+        group by send_time
+        order by send_time
+    </select>
+    <select id="getItemCostList" resultType="com.alibaba.fastjson.JSONObject">
+        select count(t.oid) as 'orderNum',
+        t.itemId,
+        t.itemTitle,
+        t.itemPicUrl,
+        round(sum(t.totalFee) / 100, 2) as 'totalFee',
+        round(sum(t.costPrice), 2) as 'costPrice',
+        tt.user_name as 'userName',
+        tt.courtship_purchase_name as 'courtshipPurchaseName',
+        (
+        CASE when tt.item_type = 1
+        then '自选品'
+        when tt.item_type = 2
+        then '推品'
+        else '-'
+        end
+        ) as 'itemType'
+        from (select t1.oid as 'oid',
+        t1.item_id as 'itemId',
+        t1.item_pic_url as 'itemPicUrl',
+        t1.item_title as 'itemTitle',
+        t2.costPrice as 'costPrice',
+        t1.total_fee as 'totalFee'
+
+        from kwaixiaodian_order_cursor_list t1
+        left join (select oid as 'oid',
+        sum(cost_price) as 'costPrice',
+        group_concat(distinct sku_id) as 'skuId',
+        group_concat(distinct po_id) as 'poId'
+        from kwaixiaodian_cost_detail_end
+        where send_time &gt;= #{start}
+        and send_time &lt;= #{end}
+        <if test='companyId != null and companyId != ""'>
+            and company_id = #{companyId}
+        </if>
+        group by oid) t2
+        on t1.oid = t2.oid
+        where t1.send_time &gt;= #{start}
+        and t1.send_time &lt;= #{end}
+        <if test='companyId != null and companyId != ""'>
+            and t1.company_id = #{companyId}
+        </if>
+        and t1.status in (40, 50, 70)) t
+        left join kwaixiaodian_item_get tt
+        on t.itemId = tt.item_id
+        group by t.itemId
+        order by count(t.oid) desc
+    </select>
 </mapper>