package com.zt.plat.module.base.controller.admin.plandate;

import com.zt.plat.framework.common.pojo.CommonResult;
import com.zt.plat.framework.common.pojo.PageResult;
import com.zt.plat.module.base.controller.admin.plandate.vo.PlanDateRespVO;
import com.zt.plat.module.base.controller.admin.plandate.vo.PlanOrderSaveReqVO;
import com.zt.plat.module.base.service.plandate.PlanOrderService;
import com.zt.plat.module.contractorder.api.dto.order.OrderAndPlanDataReqDTO;
import com.zt.plat.module.contractorder.api.dto.order.OrderDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.apache.ibatis.annotations.Delete;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import static com.zt.plat.framework.common.pojo.CommonResult.success;


@Tag(name = "管理后台 - 计划数据与订单绑定")
@RestController
@RequestMapping("/base/plan-order")
@Validated
public class PlanOrderController {
    @Resource
    private PlanOrderService planOrderService;
    //绑定订单
    @PostMapping("/bind-order")
    @Operation(summary = "计划与订单绑定")
    @PreAuthorize("@ss.hasAnyPermissions({'base:plan-date:tree:list-all:query'})")
    public CommonResult<?> bindOrder(@RequestBody PlanOrderSaveReqVO reqVO) {
        return success( planOrderService.bindOrder(reqVO));
    }
    //解绑订单
    @DeleteMapping("/release-order")
    @Operation(summary = "计划与订单解绑")
    @PreAuthorize("@ss.hasAnyPermissions({'base:plan-date:tree:list-all:releaseOrder'})")
    public CommonResult<?> unbindOrder(@RequestParam("planId") String planId,@RequestParam("orderNumber") String orderNumber) {
        planOrderService.unbindOrder(planId, orderNumber);
        return success(true);
    }
    //根据订单号获取已绑定的订单
    @GetMapping("/get-bound-order")
    @Operation(summary = "根据计划ID获取已绑定的订单")
    @PreAuthorize("@ss.hasAnyPermissions({'base:plan-date:tree:list-all:query'})")
    public CommonResult<?> getBoundOrder(@RequestParam("planId") String planId) {
        return success(planOrderService.getBoundOrder(planId));
    }

    //根据计划和订单的参数查询相关的订单
    @PostMapping("/query-order-plan-data")
    @Operation(summary = "根据计划和订单的参数查询相关的订单")
    @PreAuthorize("@ss.hasAnyPermissions({'base:plan-date:tree:list-all:query'})")
    public CommonResult<PageResult<OrderDTO>> queryOrder(@RequestBody OrderAndPlanDataReqDTO reqVO) {
        return success(planOrderService.queryOrderAndPlanData(reqVO));
    }

}
