package com.sckw.usual.controller;

import com.sckw.usual.entity.req.waybill.SendCarDto;
import com.sckw.usual.entity.req.waybill.WaybillFinishReq;
import com.sckw.usual.entity.req.waybill.WaybillPageListReq;
import com.sckw.usual.service.WaybillOrderService;
import com.sckw.core.utils.*;
import com.sckw.core.web.response.HttpResult;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @desc: 运单
 * @author: lt
 * @date: 2024/4/9 14:38
 */
@RestController
@RequestMapping("/wayBill")
public class WayBillOrderController {

    @Autowired
    WaybillOrderService waybillOrderService;


    @PostMapping("/waybillPageList")
    public HttpResult waybillPageList(@RequestBody @Valid WaybillPageListReq waybillPageListReq)
    {
        return HttpResult.ok(waybillOrderService.waybillPageList(waybillPageListReq));
    }


    /**
     * @param params {}
     * @desc 派车-趟次/循环
     * @date 2023/5/30
     **/
    @PostMapping("/sendCar")
    public HttpResult sendCar(@RequestBody @Valid List<SendCarDto> params){
        if (CollectionUtils.isEmpty(params)) {
            return HttpResult.error("请选择委派车辆信息！");
        }
        return waybillOrderService.sendCarV2(params);
    }

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

    /**
    * @Description: 运单接单
    * @Author: Lt
    * @Date: 2024/5/13 17:12
    */
    @GetMapping("/waybillTaking")
    public  HttpResult waybillTaking(@RequestParam("waybillId") String waybillId)
    {
        return waybillOrderService.waybillTaking(waybillId);
    }

    /**
     * @Description: 运单完结
     * @Author: Lt
     * @Date: 2024/5/13 17:12
     */
    @PostMapping("/waybillFinish")
    public  HttpResult waybillFinish(@RequestBody @Valid WaybillFinishReq waybillFinishReq)
    {
        return waybillOrderService.waybillFinish(waybillFinishReq);
    }

}
