package com.njzscloud.dispose.cst.order.controller;

import com.njzscloud.common.core.utils.R;
import com.njzscloud.common.mp.support.PageParam;
import com.njzscloud.common.mp.support.PageResult;
import com.njzscloud.dispose.cst.order.pojo.entity.OrderEntity;
import com.njzscloud.dispose.cst.order.pojo.param.*;
import com.njzscloud.dispose.cst.order.pojo.result.OrderResult;
import com.njzscloud.dispose.cst.order.pojo.result.SearchOrderResult;
import com.njzscloud.dispose.cst.order.service.OrderService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 收/销订单
 *
 * @author ljw
 */
@Slf4j
@RestController
@RequestMapping("/order")
@RequiredArgsConstructor
public class OrderController {

    private final OrderService orderService;

    /**
     * 新增
     */
    @PostMapping("/add")
    public synchronized R<?> add(@RequestBody CreateOrderParam param) {
        orderService.add(param);
        return R.success();
    }

    /**
     * 修改
     */
    @PostMapping("/modify")
    public R<?> modify(@RequestBody OrderEntity orderEntity) {
        orderService.modify(orderEntity);
        return R.success();
    }

    /**
     * 删除
     */
    @PostMapping("/del")
    public R<?> del(@RequestBody List<Long> ids) {
        orderService.del(ids);
        return R.success();
    }

    /**
     * 详情（小程序）
     */
    @GetMapping("/miniDetail")
    public R<OrderResult> miniDetail(@RequestParam("id") Long id) {
        return R.success(orderService.miniDetail(id));
    }

    /**
     * 详情
     */
    @GetMapping("/detail")
    public R<SearchOrderResult> detail(@RequestParam("id") Long id, @RequestParam(value = "orderType", required = false) String orderType) {
        return R.success(orderService.detail(id, orderType));
    }

    /**
     * 分页查询
     */
    @GetMapping("/paging")
    public R<PageResult<SearchOrderResult>> paging(PageParam pageParam, SearchOrderParam searchOrderParam) {
        return R.success(orderService.paging(pageParam, searchOrderParam));
    }

    /**
     * 指派清运公司
     */
    @PostMapping("/assignmentOrg")
    public R<?> assignmentOrg(@RequestBody AssignmentOrgParam orgParam) {
        orderService.assignmentOrg(orgParam);
        return R.success();
    }

    /**
     * 指派司机
     */
    @PostMapping("/assignmentDriver")
    public R<?> assignmentDriver(@RequestBody AssignmentDriverParam driverParam) {
        orderService.assignmentDriver(driverParam);
        return R.success();
    }

    /**
     * 司机接单
     */
    @PostMapping("/driverAcceptOrder")
    public R<?> driverAcceptOrder(@RequestBody DriverAcceptOrderParam acceptOrderParam) {
        orderService.driverAcceptOrder(acceptOrderParam);
        return R.success();
    }

    /**
     * 开始清运
     */
    @PostMapping("/start_trans")
    public R<?> startTrans(@RequestBody StartTransParam transParam) {
        orderService.startTrans(transParam);

        return R.success();
    }

    /**
     * 车辆进场
     */
    @PostMapping("/truck_coming")
    public synchronized R<?> truckComing(@RequestBody TruckComingParam param) {
        orderService.truckComing(param);
        return R.success();
    }

    /**
     * 看料
     */
    @PostMapping("/check")
    public synchronized R<?> check(@RequestBody CheckGoodsParam checkGoodsParam) {
        orderService.check(checkGoodsParam);
        return R.success();
    }

    /**
     * 车辆出场
     */
    @PostMapping("/truck_leaving")
    public synchronized R<?> truckLeaving(@RequestBody TruckLeavingParam leavingParam) {
        orderService.truckLeaving(leavingParam);
        return R.success();
    }

}


