package com.sckw.order.dubbo;

import com.sckw.core.model.constant.Global;
import com.sckw.core.utils.CollectionUtils;
import com.sckw.order.api.dubbo.TradeOrderStatisticsService;
import com.sckw.order.api.model.TradeOrderCountStatisticsDTO;
import com.sckw.order.enums.OrderTypeEnum;
import com.sckw.order.serivce.KwoTradeOrderService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;

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

/**
 * @desc: 贸易订单统计dubbo接口实现
 * @author: yzc
 * @date: 2023-09-11 10:43
 */
@DubboService(group = "design", version = "1.0.0")
@Slf4j
@RequiredArgsConstructor
public class TradeOrderStatisticsServiceImpl implements TradeOrderStatisticsService {

    private final KwoTradeOrderService kwoTradeOrderService;

    @Override
    public Map<Integer, Integer> getOrderNumByTopEntId(Long topEntId) {
        Map<Integer, Integer> map = new HashMap<>(Global.NUMERICAL_FOUR);
        map.put(Global.NUMERICAL_ONE, Global.NUMERICAL_ZERO);
        map.put(Global.NUMERICAL_TWO, Global.NUMERICAL_ZERO);
        List<TradeOrderCountStatisticsDTO> list = kwoTradeOrderService.getOrderNumByTopEntId(topEntId);
        if (CollectionUtils.isEmpty(list)) {
            return map;
        }

        list.forEach(item -> {
            map.put(item.getOrderType(), item.getNum());
        });
        return map;
    }
}
