package com.cyl.h5.controller.staff;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cyl.manager.staff.domain.DispatchOrder;
import com.cyl.manager.staff.domain.Staff;
import com.cyl.manager.staff.domain.StaffAnswerRecord;
import com.cyl.manager.staff.service.IDispatchOrderService;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.framework.config.LocalDataUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


//@Api("派单")
@RestController
@Slf4j
@RequestMapping("/h5/dispatchOrder")
public class H5DispatchOrderController {

    @Autowired
    private IDispatchOrderService dispatchOrderService;



    /**
     * 查询派单信息列表
     */
    @GetMapping("/list")
    public AjaxResult list(@ApiParam(value = "查询条件", required = false) DispatchOrder record)
    {
        //伴宠师Id
        Staff staff = (Staff) LocalDataUtil.getVar(Constants.STAFF_INFO);
        record.setStaffId(staff.getId());

        List<DispatchOrder> result =
                dispatchOrderService
                        .list(Wrappers.query(record).lambda().orderByDesc(DispatchOrder::getCreateTime));
        return AjaxResult.successData(result);
    }


    /**
     * 查询派单信息列表
     */
    @GetMapping("/getById")
    public AjaxResult list(@ApiParam(value = "", required = false) @RequestParam("dispatchOrderId") String dispatchOrderId)
    {
        return AjaxResult.successData(dispatchOrderService.getById(dispatchOrderId));
    }



    /**
     * 接单
     * @return
     */
    @GetMapping("/acceptDispatch")
//    @ApiOperation(value = "接单", notes = "接单")
    public AjaxResult acceptDispatch(@RequestParam("dispatchOrderId") String dispatchOrderId){
        log.info("接单,请求参数:{}", dispatchOrderId);
        return AjaxResult.success(dispatchOrderService.acceptDispatch(dispatchOrderId));
    }


    /**
     * 拒单
     * @return
     */
    @GetMapping("/rejectDispatch")
//    @ApiOperation(value = "接单", notes = "接单")
    public AjaxResult rejectDispatch(@RequestParam("dispatchOrderId") String dispatchOrderId){
        log.info("拒单,请求参数:{}", dispatchOrderId);
        return AjaxResult.success(dispatchOrderService.rejectDispatch(dispatchOrderId));
    }
}
