package com.sckw.transport.controller.enterpriseApp;

import com.sckw.core.web.constant.HttpStatus;
import com.sckw.core.web.response.HttpResult;
import com.sckw.transport.model.dto.WaybillListAppDTO;
import com.sckw.transport.service.WaybillManagementService;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author jc
 * @description 企业端app运单controller
 * @date 2023-08-21 16:08:41
 */
@Slf4j
@RestController
@RequestMapping("/appKwtWayBill")
public class AppWayBillController {

    @Autowired
    WaybillManagementService waybillManagementService;

    /**
     * APP 运单统计分类 - [运输中|已完成]
     * @param keyword
     * @return
     */
    @Valid
    @RequestMapping(name = "APP运单统计分类", value = "/waybillStatistic", method = RequestMethod.GET)
    public HttpResult waybillStatistic(@RequestParam("keyword") String keyword,
                                       @RequestParam("startDate") String startDate,
                                       @RequestParam("endDate") String endDate) {
        try {
            return waybillManagementService.waybillDataStatisticApp(keyword, startDate, endDate);
        } catch (Exception e) {
            log.error("APP运单统计分类:订单id {},error {} ", keyword, e.getMessage(), e);
            return HttpResult.error(HttpStatus.GLOBAL_EXCEPTION_CODE, e.getMessage());
        }
    }

    /**
     * APP 运单列表 - [运输中|已完成]
     * @param waybillOrderDTO
     * @return
     */
    @Valid
    @RequestMapping(name = "APP运单列表", value = "/waybillData", method = RequestMethod.POST)
    public HttpResult waybillData(@Validated @RequestBody WaybillListAppDTO waybillOrderDTO) {
        try {
            return waybillManagementService.waybillDataApp(waybillOrderDTO);
        } catch (Exception e) {
            log.error("APP运单列表:error-msg: {} ,e: {}", e.getMessage(), e);
            return HttpResult.error(HttpStatus.GLOBAL_EXCEPTION_CODE, e.getMessage());
        }
    }

    /**
     * APP 运单列表吨量统计 - [运输中|已完成]
     * @param waybillOrderDTO
     * @return
     */
    @Valid
    @RequestMapping(name = "APP运单吨量统计", value = "/waybillAmountStatistic", method = RequestMethod.POST)
    public HttpResult waybillAmountStatistic(@Validated @RequestBody WaybillListAppDTO waybillOrderDTO) {
        try {
            return waybillManagementService.waybillAmountStatistic(waybillOrderDTO);
        } catch (Exception e) {
            log.error("APP运单列表:订单id {},error {} ", waybillOrderDTO, e.getMessage(), e);
            return HttpResult.error(HttpStatus.GLOBAL_EXCEPTION_CODE, e.getMessage());
        }
    }

    /**
     * APP 物流订单-运单列表
     * @param waybillOrderDTO
     * @return
     */
    @Valid
    @RequestMapping(name = "物流订单-运单列表", value = "/logisticOrderWaybillData", method = RequestMethod.POST)
    public HttpResult logisticOrderWaybillData(@Validated @RequestBody WaybillListAppDTO waybillOrderDTO) {
        try {
            return waybillManagementService.logisticOrderWaybillData(waybillOrderDTO);
        } catch (Exception e) {
            log.error("物流订单-运单列表:订单id {},error {} ", waybillOrderDTO, e.getMessage(), e);
            return HttpResult.error(HttpStatus.GLOBAL_EXCEPTION_CODE, e.getMessage());
        }
    }
}
