package com.ytpm.middle.controller;

import com.ytpm.general.Result;
import com.ytpm.general.ResultTable;
import com.ytpm.middle.param.WorkorderListParam;
import com.ytpm.middle.service.WorkorderService;
import com.ytpm.middle.view.MiddleUserInfo;
import com.ytpm.middle.view.WorkorderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;

/**
 * @author Marx
 * @date 2025/8/1 8:57
 */
@Api(tags = "工单管理")
@RestController
@RequestMapping("/workorder")
public class WorkorderController {

    @Resource
    private WorkorderService workorderService;


    @ApiOperation("查询工单列表")
    @PostMapping("/queryList")
    public ResultTable<WorkorderVO> queryList(@RequestBody WorkorderListParam param) {
        return workorderService.queryList(param);
    }

    @ApiImplicitParams({
            @ApiImplicitParam(name = "workorderId",value = "工单ID",required = true),
            @ApiImplicitParam(name = "remark",value = "工单处理备注",required = true),
    })
    @ApiOperation("处理工单")
    @GetMapping("/process")
    public Result<String> processWorkorder(@RequestParam("workorderId")String workorderId,
                                           @RequestParam("remark")String remark,
                                           @ApiIgnore @AuthenticationPrincipal MiddleUserInfo user) {
        return workorderService.processWorkorder(workorderId,remark,user.getUserId());
    }

    @ApiImplicitParam(name = "workorderId",value = "工单ID",required = true)
    @ApiOperation("查询工单详情")
    @GetMapping("/view")
    public Result<WorkorderVO> view(@RequestParam("workorderId")String workorderId) {
        return workorderService.selectOne(workorderId);
    }
}
