package com.sckw.usual.controller;

import com.sckw.core.utils.TenantUtil;
import com.sckw.core.web.response.HttpResult;
import com.sckw.usual.entity.req.*;
import com.sckw.usual.service.OrderActionService;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;

/**
 * @desc: 普货运输
 * @author: lt
 * @date: 2024/3/27 16:51
 */
@Validated
@RestController
@RequestMapping("/normal")
public class UsualController {

    @Autowired
    OrderActionService orderActionService;


    @PostMapping(value = "/orderPageList", produces = MediaType.APPLICATION_JSON_VALUE)
    public HttpResult orderPageList(@RequestBody @Valid OrderListParam orderListParam)
    {
        return HttpResult.ok(orderActionService.orderPageList(orderListParam));
    }


    /**
     * @desc: 陆运订单新增
     * @author: lt
     * @date: 2024/3/27 16:59
     */
    @PostMapping(value = "/landTransport", produces = MediaType.APPLICATION_JSON_VALUE)
    public HttpResult landTransportation(@RequestBody OrderGeneralTransportReq orderGeneralTransportReq)
    {
        if (orderActionService.orderGeneralTransportAdd(orderGeneralTransportReq)) {
            return HttpResult.ok("添加成功");
        }
        return HttpResult.error("添加失败");

    }

    /**
     * @desc: 分包托运
     * @author: lt
     * @date: 2024/4/9 9:37
     */
    //@PostMapping(value = "/subcontractConsignment", produces = MediaType.APPLICATION_JSON_VALUE)
    //public HttpResult subcontractConsignment(@RequestBody @Validated KwOrderSubConsignReq kwOrderSubConsignReq)
    //{
    //    if (orderActionService.orderSubConsignAdd(kwOrderSubConsignReq)) {
    //        return HttpResult.ok("添加成功");
    //    }
    //    return HttpResult.error("添加失败");
    //
    //}



    /**
     * @desc: 获取运输类型
     * @author: lt
     * @date: 2024/4/3 11:54
     */
    @GetMapping("/getTransportType")
    public HttpResult getTransportType()
    {
        return HttpResult.ok(orderActionService.getTransportType());
    }

    @GetMapping("/getTransportMode")
    public HttpResult getTransportMode()
    {
        return HttpResult.ok(orderActionService.getTransportMode());
    }

    /**
     * @desc: 分包托运
     * @author: lt
     * @date: 2024/4/7 10:28
     */
    @PostMapping(value = "/subConsign")
    public HttpResult subConsign(@RequestBody @Validated KwOrderSubConsignReq kwOrderSubConsignReq)
    {
        if (orderActionService.orderSubConsignAdd(kwOrderSubConsignReq)) {
            return HttpResult.ok("添加成功");
        }
        return HttpResult.error("添加失败");
    }

    /**
     * @desc: 根据订单id获取订单状态记录信息
     * @author: lt
     * @date: 2024/4/7 16:50
     */
    @PostMapping(value = "/getOrderStatusList")
    public HttpResult getOrderStatusList(@RequestBody @Valid KwOrderStatusListParam kwOrderStatusListParam)
    {
        return HttpResult.ok(orderActionService.getOrderStatusList(kwOrderStatusListParam));
    }

    /**
     * @desc: 获取订单详情
     * @author: lt
     * @date: 2024/4/7 17:34
     */
    @GetMapping(value = "/orderDetailById")
    public HttpResult orderDetailById(@RequestParam("orderId") String orderId)
    {
        return orderActionService.orderDetailById(orderId);
    }

    /**
     * 承运订单-完结订单
     *
     * @param orderFinishDTO    物流订单请求参数
     * @return  响应结果
     */
    @RequestMapping(value = "/commitAcceptCarriageOrderFinish", method = RequestMethod.POST)
    public HttpResult commitAcceptCarriageOrderFinish(@Valid @RequestBody OrderFinishReq orderFinishDTO) {
        return orderActionService.commitAcceptCarriageOrderFinish(orderFinishDTO);
    }

    /**
    * @Description: 完结订单详情
    * @Author: Lt
    * @Date: 2024/5/11 15:45
    */
    @GetMapping("/completeDetail")
    public HttpResult completeDetail(@RequestParam("orderId") String orderId)
    {
        return HttpResult.ok(orderActionService.completeDetail(orderId));
    }

    /**
    * @Description: 订单列表状态统计
    * @Author: Lt
    * @Date: 2024/5/11 15:45
    */
    @GetMapping("/getStatusCountListInSingleQuery")
    public HttpResult getStatusCountListInSingleQuery()
    {
        return HttpResult.ok(orderActionService.getStatusCountListInSingleQuery());
    }



}
