package com.yuchen.saas.park.service.controller.pldoor;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.yuchen.saas.park.api.dto.pldoor.PlPsOrderDTO;
import com.yuchen.saas.park.api.entity.pldoor.PlPsTask;
import com.yuchen.saas.park.api.vo.request.PlPsOrderReq;
import com.yuchen.saas.park.api.vo.request.PlPsTaskReq;
import com.yuchen.saas.park.service.service.pldoor.PlPsTaskService;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nest.springwrap.core.mp.support.NestPage;
import org.nest.springwrap.core.mp.support.Query;
import org.nest.springwrap.core.tool.api.R;
import org.nest.springwrap.core.tool.utils.Func;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 智慧配送任务 前端控制器
 * </p>
 *
 * @author miaoqs
 * @since 2024-07-31
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/plPsTask")
public class PlPsTaskController {

    private final PlPsTaskService plPsTaskService;

    /**
     * 智慧配送任务 新增或修改
     */
    @PostMapping("/saveOrUpdate")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "智慧配送任务 新增或修改", notes = "智慧配送任务 新增或修改")
    public R saveOrUpdate(@Valid @RequestBody PlPsTask plPsTask) {
        if(Func.isEmpty(plPsTask)) {
            return R.error("智慧配送任务不能为空");
        }
        return R.data(plPsTaskService.saveOrUpdate(plPsTask));
    }

    /**
     * 获取详情
     * @param id
     * @return
     */
    @GetMapping("/detail")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "智慧配送任务 详情", notes = "智慧配送任务详情")
    public R detail(Long id) {
        return R.data(plPsTaskService.getById(id));
    }

    /**
     * 根据主表id删除智慧配送任务
     * @param plPsTask
     * @return
     */
    @PostMapping("/removeId")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "根据主表id 智慧配送任务 删除", notes = "根据主表id 智慧配送任务 删除")
    public R removeId(@RequestBody PlPsTask plPsTask) {
        plPsTaskService.removeById(plPsTask.getId());
        return R.success();
    }

    /**
     * 分页 智慧配送运单
     */
    @GetMapping("/pageByparam")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "分页 智慧配送运单", notes = "分页 智慧配送运单")
    public R<NestPage<PlPsTask>> pageByparam(PlPsTaskReq plPsTaskReq, Query query) {
        IPage<PlPsTask> pages = plPsTaskService.pageByparam(plPsTaskReq, query);
        return  R.data(NestPage.of(pages));
    }

    @PostMapping("/updateOrderState")
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "修改启用状态", notes = "修改启用状态")
    public R updateOrderState(@Valid @RequestBody PlPsTask plPsTask) {
        if(Func.isEmpty(plPsTask) || Func.isEmpty(plPsTask.getTaskState())) {
            return R.error("启用状态不能为空");
        }
        plPsTask.setId(plPsTask.getId());
        plPsTask.setTaskState(plPsTask.getTaskState());
        return R.data(plPsTaskService.updateById(plPsTask));
    }

    @GetMapping("/getTodayPs")
    @ApiOperationSupport(order = 6)
    @ApiOperation(value = "今日配送", notes = "今日配送")
    public R getTodayPs(Long partId) {
        if(Func.isEmpty(partId) || Func.isEmpty(partId)) {
            return R.error("项目ID不能为空");
        }
        return R.data(plPsTaskService.getTodayPs(partId));
    }


}
