package com.sckw.transport.controller;

import cn.hutool.core.date.LocalDateTimeUtil;
import com.sckw.transport.api.model.LogisticsBaseOrderVo;
import com.sckw.transport.api.model.dto.McpLogisticsOrderVo;
import com.sckw.transport.api.model.param.OrderPara;
import com.sckw.transport.api.model.vo.TransportTopStatisticsVo;
import com.sckw.transport.model.LogisticsOrderPara;
import com.sckw.transport.service.KwtLogisticsConsignmentService;
import com.sckw.transport.service.TransportStatisticsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author lfdc
 * @desc 物流订单Controller-v4.2
 * @date 2024-03-11 11:06:06
 */
@Slf4j
@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping(value = "/logisticsOrder")
@Tag(name = "物流订单相关接口")
public class McpController {

    private final KwtLogisticsConsignmentService logisticsConsignmentService;
    private final TransportStatisticsService transportStatisticsService;


    @PostMapping(value = "/list")
    @Operation(summary = "分页查询物流订单", description = "分页查询物流订单")
    public List<McpLogisticsOrderVo> list(@RequestBody OrderPara orderPara) {
        LogisticsOrderPara tradeOrderPara = new LogisticsOrderPara();
        tradeOrderPara.setStartTime(LocalDateTimeUtil.parse(orderPara.getStartTime(), "yyyy-MM-dd HH:mm:ss"));
        tradeOrderPara.setEndTime(LocalDateTimeUtil.parse(orderPara.getEndTime(), "yyyy-MM-dd HH:mm:ss"));
        tradeOrderPara.setUserId(orderPara.getUserId());
        tradeOrderPara.setOrderNo(orderPara.getOrderNo());
        tradeOrderPara.setLogisticsOrderNo(orderPara.getLogisticsOrderNo());
        return logisticsConsignmentService.queryMcpList(tradeOrderPara);
    }

    @PostMapping(value = "/base")
    @Operation(summary = "分页查询物流订单概要信息", description = "分页查询物流订单概要信息")
    public List<LogisticsBaseOrderVo> base(@RequestBody OrderPara orderPara) {
        LogisticsOrderPara tradeOrderPara = new LogisticsOrderPara();
        tradeOrderPara.setStartTime(LocalDateTimeUtil.parse(orderPara.getStartTime(), "yyyy-MM-dd HH:mm:ss"));
        tradeOrderPara.setEndTime(LocalDateTimeUtil.parse(orderPara.getEndTime(), "yyyy-MM-dd HH:mm:ss"));
        tradeOrderPara.setUserId(orderPara.getUserId());
        return logisticsConsignmentService.queryBaseList(tradeOrderPara);
    }

    /**
     * 首页顶部运输统计。
     * <p>
     * 提供给报表模块通过 Feign 调用，统一返回：
     * 累计运量、累计车次、今日车次、今日运量。
     * </p>
     *
     * @return 顶部统计结果
     */
    @GetMapping("/topStatistics")
    @Operation(summary = "首页顶部运输统计", description = "累计运量/累计车次/今日车次/今日运量")
    public TransportTopStatisticsVo topStatistics() {
        return transportStatisticsService.queryTopStatistics();
    }

}
