package com.yc.ship.module.trade.job;

import com.yc.ship.framework.quartz.core.handler.JobHandler;
import com.yc.ship.framework.tenant.core.job.TenantJob;
import com.yc.ship.module.trade.service.order.TradeOrderService;
import com.yc.ship.module.trade.service.orderjzdetail.OrderJzDetailService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Component
@Slf4j
public class OrderJzCreateJob implements JobHandler {
    @Resource
    private OrderJzDetailService orderJzDetailService;

    @Resource
    private TradeOrderService tradeOrderService;


    @Override
    @TenantJob
    public String execute(String param) {
        List<Map<String, Object>> tradeJz = tradeOrderService.getTradeJz();
        Map<Object, List<Map<String, Object>>> List = tradeJz.stream().collect(Collectors.groupingBy(map -> map.get("jz_id")));
        for (Map.Entry<Object, List<Map<String, Object>>> entry : List.entrySet()) {
            orderJzDetailService.sendJz(entry.getValue(), Long.parseLong(entry.getKey().toString()));
        }

        return "成功";
    }

}
