package cn.iocoder.yudao.module.tickets.controller.admin;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.tickets.entity.DlTicketWares;
import cn.iocoder.yudao.module.tickets.service.DlTicketWaresService;
import cn.iocoder.yudao.module.tickets.vo.DlTicketWaresReqVO;
import cn.iocoder.yudao.module.tickets.vo.DlTicketWaresRespVO;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

/**
 * 工单配件申请/退回表(DlTicketWares)表控制层
 *
 * @author 小李
 * @date 11:58 2024/10/15
**/
@RestController
@RequestMapping("/repair/tw")
public class DlTicketWaresController {
    /**
     * 服务对象
     */
    @Resource
    private DlTicketWaresService dlTicketWaresService;

    /**
     * 分页查询
     *
     * @author 小李
     * @date 12:01 2024/10/15
     * @param reqVO 请求对象
     * @param pageNo 页码
     * @param pageSize 条数
    **/
    @GetMapping("/page")
    @Operation(summary = "分页查询")
    public CommonResult<?> getPage(DlTicketWaresReqVO reqVO,
                                   @RequestParam(value = "pageNo", defaultValue = "1")Integer pageNo,
                                   @RequestParam(value = "pageSize", defaultValue = "10")Integer pageSize){
        Page<DlTicketWares> page = new Page<>(pageNo, pageSize);
        return success(dlTicketWaresService.getPage(reqVO, page));
    }

    /**
     * 查询当前工单下的配件申请单
     * @author PQZ
     * @date 13:43 2024/10/19
     * @param reqVO DlTicketWaresReqVO实体
     * @return cn.iocoder.yudao.framework.common.pojo.CommonResult<?>
    **/
    @GetMapping("/list")
    @Operation(summary = "不分页查询待审批的配件申请单")
    public CommonResult<?> list(DlTicketWaresReqVO reqVO){
        return success(dlTicketWaresService.listByTicket(reqVO));
    }

    /**
     * 新增、修改
     *
     * @author 小李
     * @date 12:14 2024/10/15
     * @param respVO 请求对象
    **/
    @PostMapping("/update")
    @Operation(summary = "新增、修改")
    public CommonResult<?> updateTicketWares(@RequestBody DlTicketWaresRespVO respVO){
        dlTicketWaresService.updateTicketWares(respVO);
        return CommonResult.ok();
    }

    /**
     * 新建配件申请单、
     * @author vinjor-M
     * @date 14:35 2024/10/22
     * @param respVO 请求体
     * @return cn.iocoder.yudao.framework.common.pojo.CommonResult<?>
    **/
    @PostMapping("/newApplyOrder")
    @Operation(summary = "新增、修改")
    public CommonResult<?> newApplyOrder(@RequestBody DlTicketWaresRespVO respVO){
        dlTicketWaresService.createApplyOrder(respVO);
        return CommonResult.ok();
    }

    /**
     * 删除
     *
     * @author 小李
     * @date 12:21 2024/10/15
     * @param id id
    **/
    @DeleteMapping("/remove")
    @Operation(summary = "删除")
    public CommonResult<?> removeTicketWares(@RequestParam("id") String id){
        dlTicketWaresService.removeTicketWares(id);
        return CommonResult.ok();
    }

    /**
     * 审核
     *
     * @author 小李
     * @date 21:15 2024/10/15
     * @param respVO 请求对象
    **/
    @PostMapping("/audit")
    @Operation(summary = "审核")
    public CommonResult<?> auditTicketWares(@RequestBody DlTicketWaresRespVO respVO){
        dlTicketWaresService.auditTicketWares(respVO);
        return CommonResult.ok();
    }

    /**
     * 仓库通知领料、退料
     *
     * @author 小李
     * @date 20:45 2024/10/16
     * @param respVO 请求对象
    **/
    @PostMapping("/pass")
    @Operation(summary = "仓库通知领料、退料")
    public CommonResult<?> passTicketWares(@RequestBody DlTicketWaresRespVO respVO){
        dlTicketWaresService.passTicketWares(respVO);
        return CommonResult.ok();
    }

    /**
     * 员工确认领料
     *
     * @author 小李
     * @date 22:07 2024/10/16
     * @param respVO 请求对象
    **/
    @PostMapping("/repairPass")
    @Operation(summary = "员工确认领料")
    public CommonResult<?> repairPassTicketWares(@RequestBody DlTicketWaresRespVO respVO){
        dlTicketWaresService.repairPassTicketWares(respVO);
        return CommonResult.ok();
    }

    /**
     * 仓库确认退料
     *
     * @author 小李
     * @date 22:03 2024/10/17
     * @param respVO 请求对象
    **/
    @PostMapping("/passBack")
    @Operation(summary = "仓库确认退料")
    public CommonResult<?> passBackTicketWares(@RequestBody DlTicketWaresRespVO respVO){
        dlTicketWaresService.passBackTicketWares(respVO);
        return CommonResult.ok();
    }

    /**
     * 维修工的角度查提交的配件申请单\待确认领料单\待确认退料单 待处理数量
     * @author vinjor-M
     * @date 15:32 2024/10/22
     * @return cn.iocoder.yudao.framework.common.pojo.CommonResult<?>
    **/
    @GetMapping("/getWorkerTodo")
    @Operation(summary = "维修工的角度查提交的配件申请单")
    public CommonResult<?> getWorkerTodo(){
        return success(dlTicketWaresService.getWorkerTodo());
    }
}

