package com.ruixuan.isc.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.ruixuan.common.utils.Check;
import com.ruixuan.isc.mapper.SupplyChainMapper;
import com.ruixuan.isc.service.ISupplyChainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class SupplyChainServiceImpl implements ISupplyChainService {
    @Autowired
    private SupplyChainMapper supplyChainMapper;

    // 获取订单数据　
    @Override
    public List<JSONObject> getOrderList(Map<String, Object> requestMap) {
        List<JSONObject> list = supplyChainMapper.getOrderList(requestMap);
        if (!Check.isNull(list)) {
            Map<Long, Long> map = new HashMap<>();
            for (int i = 0; i < list.size(); i++) {
                JSONObject jsonObject = list.get(i);
                Long promoterId = jsonObject.getLong("promoterId");
                requestMap.put("promoterId", promoterId);
                List<JSONObject> topOrders = supplyChainMapper.getTopOrders(requestMap);
                jsonObject.put("topOrders", topOrders);
                map.put(promoterId, promoterId);
            }
            Map<Long, String> userMap = new HashMap<>();
            if (!Check.isNullMap(map)) {
                List<JSONObject> userList = supplyChainMapper.getUserList(map);
                for (int i = 0; i < userList.size(); i++) {
                    JSONObject jsonObject = userList.get(i);
                    userMap.put(jsonObject.getLong("promoterId"), jsonObject.getString("userName"));
                }
            }

            if (!Check.isNullMap(userMap)) {
                for (int i = 0; i < list.size(); i++) {
                    JSONObject jsonObject = list.get(i);
                    Long promoterId = jsonObject.getLong("promoterId");
                    String userName = userMap.get(promoterId);
                    if (!Check.isNull(userName)) {
                        jsonObject.put("userName", userName);
                    }
                }
            }
        }


        return list;
    }

    //达人带货详情
    @Override
    public List<JSONObject> anchorOrderDetail(Map<String, Object> requestMap) {
        return supplyChainMapper.anchorOrderDetail(requestMap);
    }

    //订单统计
    @Override
    public List<JSONObject> orderStatistics(Map<String, Object> requestMap) {
        return supplyChainMapper.orderStatistics(requestMap);
    }

    //商品列表
    @Override
    public List<JSONObject> itemList(Map<String, Object> requestMap) {
        List<JSONObject> list = supplyChainMapper.itemList(requestMap);

        return list;
    }

    @Override
    public List<JSONObject> itemBindList(Map<String, Object> requestMap) {
        return supplyChainMapper.itemBindList(requestMap);
    }

    @Override
    public List<JSONObject> itemDetail(Map<String, Object> requestMap) {
        return supplyChainMapper.itemDetail(requestMap);
    }

    @Override
    public List<JSONObject> itemServiceCharge(Map<String, Object> requestMap) {
        return supplyChainMapper.itemServiceCharge(requestMap);
    }

    @Override
    public JSONObject getOrderTotal(Map<String, Object> requestMap) {
        return supplyChainMapper.getOrderTotal(requestMap);
    }

    @Override
    public Double getOrderTotalRatio(Map<String, Object> ratioMap) {
        return supplyChainMapper.getOrderTotalRatio(ratioMap);
    }

    @Override
    public JSONObject getAmountTotal(Map<String, Object> requestMap) {
        return supplyChainMapper.getAmountTotal(requestMap);
    }

    @Override
    public Double getAmountTotalRatio(Map<String, Object> ratioMap) {
        return supplyChainMapper.getAmountTotalRatio(ratioMap);
    }

    @Override
    public JSONObject getServiceAmountTotal(Map<String, Object> requestMap) {
        return supplyChainMapper.getServiceAmountTotal(requestMap);
    }

    @Override
    public List<JSONObject> getOrderRankRatioList(Map<String, Object> requestMap) {
        return supplyChainMapper.getOrderRankRatioList(requestMap);
    }

    @Override
    public List<JSONObject> getOrderRankList(Map<String, Object> requestMap) {
        return supplyChainMapper.getOrderRankList(requestMap);
    }

    @Override
    public List<JSONObject> getPromoterRankRatioList(Map<String, Object> requestMap) {
        return supplyChainMapper.getPromoterRankRatioList(requestMap);
    }

    @Override
    public List<JSONObject> getPromoterRatioList(Map<String, Object> requestMap) {
        return supplyChainMapper.getPromoterRatioList(requestMap);
    }

    @Override
    public List<JSONObject> exportPromoterTotal(Map<String, Object> requestMap) {
        return supplyChainMapper.exportPromoterTotal(requestMap);
    }

    @Override
    public List<JSONObject> exportPromoter(Map<String, Object> requestMap) {
        return supplyChainMapper.exportPromoter(requestMap);
    }

    @Override
    public List<JSONObject> exportOrder(Map<String, Object> requestMap) {
        return supplyChainMapper.exportOrder(requestMap);
    }

    @Override
    public List<JSONObject> getTopPromoterByItemId(Map<String, Object> requestMap) {
        return supplyChainMapper.getTopPromoterByItemId(requestMap);
    }

    @Override
    public List<JSONObject> bindUserItemList(Map<String, Object> requestMap) {
        return supplyChainMapper.bindUserItemList(requestMap);
    }

    @Override
    public List<JSONObject> getSupplyChainUserList() {
        return supplyChainMapper.getSupplyChainUserList();
    }

    @Override
    public boolean unbindUser(Long itemId) {
        return supplyChainMapper.unbindUser(itemId);
    }

    @Override
    public boolean bindUser(Long itemId, Long userId, String nikeName) {
        return supplyChainMapper.bindUser(itemId, userId, nikeName);
    }

    @Override
    public List<JSONObject> adminReportList(Map<String, Object> requestMap) {
        return supplyChainMapper.adminReportList(requestMap);
    }

    @Override
    public List<JSONObject> userItemDetail(Map<String, Object> requestMap) {
        return supplyChainMapper.userItemDetail(requestMap);
    }

    @Override
    public JSONObject getTimeIntervalRatio(Map<String, Object> requestMap) {
        return supplyChainMapper.getTimeIntervalRatio(requestMap);
    }

    @Override
    public List<JSONObject> indexStatistics(Map<String, Object> requestMap) {
        return supplyChainMapper.indexStatistics(requestMap);
    }

    @Override
    public JSONObject itemBindSummary() {
        return supplyChainMapper.itemBindSummary();
    }

    @Override
    public JSONObject userItemTotal(Map<String, Object> requestMap) {
        return supplyChainMapper.userItemTotal(requestMap);
    }

    @Override
    public List<JSONObject> exportUserItemDetail(Map<String, Object> requestMap) {
        return supplyChainMapper.exportUserItemDetail(requestMap);
    }

    @Override
    public JSONObject selectOrderInfo(List<String> promoterIds, String startDate, String endDate) {
        return supplyChainMapper.selectOrderInfo(promoterIds, startDate, endDate);
    }

    @Override
    public JSONObject selectOrderRate(List<String> promoterIds, List<Long> itemIds, Long statDate, Long endDate) {
        return supplyChainMapper.selectOrderRate(promoterIds, itemIds, statDate, endDate);
    }

    @Override
    public JSONObject selectOrderRateBytedance(List<String> promoterIds, List<Long> itemIds, Long statDate, Long endDate) {
        return supplyChainMapper.selectOrderRateBytedance(promoterIds, itemIds, statDate, endDate);
    }

    @Override
    public List<JSONObject> getMonthOrderAmount(Map<String, Object> map) {
        return supplyChainMapper.getMonthOrderAmount(map);
    }

    @Override
    public List<JSONObject> getMonthOrderAmountBytedance(Map<String, Object> map) {
        return supplyChainMapper.getMonthOrderAmountBytedance(map);
    }

    @Override
    public JSONObject getMonthOrderAmountTotalBytedance(Map<String, Object> map) {
        return supplyChainMapper.getMonthOrderAmountTotalBytedance(map);
    }

    @Override
    public List<JSONObject> getMonthOrderAmountByItemsBytedance(Map<String, Object> map) {
        return supplyChainMapper.getMonthOrderAmountByItemsBytedance(map);
    }

    @Override
    public JSONObject getMonthOrderAmountTotalByItemsBytedance(Map<String, Object> map) {
        return supplyChainMapper.getMonthOrderAmountTotalByItemsBytedance(map);
    }

    @Override
    public List<JSONObject> getOrderRankRatioListBytedance(Map<String, Object> requestMap) {
        return supplyChainMapper.getOrderRankRatioListBytedance(requestMap);
    }

    @Override
    public List<JSONObject> getOrderRankListBytedance(Map<String, Object> requestMap) {
        return supplyChainMapper.getOrderRankListBytedance(requestMap);
    }

    @Override
    public List<JSONObject> getPromoterRankRatioListBytedance(Map<String, Object> requestMap) {
        return supplyChainMapper.getPromoterRankRatioListBytedance(requestMap);
    }

    @Override
    public List<JSONObject> getPromoterRatioListBytedance(Map<String, Object> requestMap) {
        return supplyChainMapper.getPromoterRatioListBytedance(requestMap);
    }

    @Override
    public JSONObject selectOrderInfoBytedance(List<String> promoterIds, Long startDate, Long endDate) {
        return supplyChainMapper.selectOrderInfoBytedance(promoterIds, startDate, endDate);
    }

    @Override
    public List<JSONObject> bdReportListV2ByBind(Map<String, Object> requestMap) {
        return supplyChainMapper.bdReportListV2ByBind(requestMap);
    }

    @Override
    public List<JSONObject> exportBindOrder(Map<String, Object> requestMap) {
        return supplyChainMapper.exportBindOrder(requestMap);
    }

    @Override
    public JSONObject getMonthOrderAmountTotal(Map<String, Object> map) {
        return supplyChainMapper.getMonthOrderAmountTotal(map);
    }

    @Override
    public JSONObject selectOrderInfoByItemIds(List<Long> itemIds, String startDate, String endDate) {
        return supplyChainMapper.selectOrderInfoByItemIds(itemIds, startDate, endDate);
    }

    @Override
    public List<JSONObject> getMonthOrderAmountByItems(Map<String, Object> map) {
        return supplyChainMapper.getMonthOrderAmountByItems(map);
    }

    @Override
    public JSONObject getMonthOrderAmountTotalByItems(Map<String, Object> map) {
        return supplyChainMapper.getMonthOrderAmountTotalByItems(map);
    }

    @Override
    public List<JSONObject> bdReportList(Map<String, Object> requestMap) {
        return supplyChainMapper.bdReportList(requestMap);
    }

    @Override
    public List<JSONObject> bdDetailList(Map<String, Object> requestMap) {
        return supplyChainMapper.bdDetailList(requestMap);
    }

    @Override
    public List<JSONObject> bdTotal(Map<String, Object> requestMap) {
        return supplyChainMapper.bdTotal(requestMap);
    }

    @Override
    public List<JSONObject> exportBdDetail(Map<String, Object> requestMap) {
        return supplyChainMapper.exportBdDetail(requestMap);
    }

    @Override
    public String getUserName(Long promoterId) {
        return supplyChainMapper.getUserName(promoterId);
    }

    @Override
    public List<JSONObject> exportBdReportList(Map<String, Object> requestMap) {
        return supplyChainMapper.exportBdReportList(requestMap);
    }

    @Override
    public List<JSONObject> exportAdminReportList(Map<String, Object> requestMap) {
        return supplyChainMapper.exportAdminReportList(requestMap);
    }

    @Override
    public List<JSONObject> getSupplyChainCourtshipUserList() {
        return supplyChainMapper.getSupplyChainCourtshipUserList();
    }

    @Override
    public List<JSONObject> adminReportListByBind(Map<String, Object> requestMap) {
        return supplyChainMapper.adminReportListByBind(requestMap);
    }

    @Override
    public List<JSONObject> exportAdminReportListByBind(Map<String, Object> requestMap) {
        return supplyChainMapper.exportAdminReportListByBind(requestMap);
    }

    @Override
    public List<JSONObject> bdReportListV2(Map<String, Object> requestMap) {
        return supplyChainMapper.bdReportListV2(requestMap);
    }

    @Override
    public List<JSONObject> bdTotalV2(Map<String, Object> requestMap) {
        return supplyChainMapper.bdTotalV2(requestMap);
    }

    @Override
    public List<JSONObject> bdDetailListV2(Map<String, Object> requestMap) {
        return supplyChainMapper.bdDetailListV2(requestMap);
    }

    @Override
    public JSONObject selectOrderInfoByItemIdsBytedance(List<Long> itemIds, Long startDate, Long endDate) {
        return supplyChainMapper.selectOrderInfoByItemIdsBytedance(itemIds, startDate, endDate);
    }

}
