package com.ytpm.controller;

import com.ytpm.agent.param.WorkorderParam;
import com.ytpm.agent.view.AgentUserInfo;
import com.ytpm.general.Result;
import com.ytpm.service.WorkorderService;
import io.swagger.annotations.Api;
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 Administrator
 * @date 2025/7/31 17:20
 */
@Api(tags = "工单管理")
@RestController
@RequestMapping("/workorder")
public class WorkorderController {

    @Resource
    private WorkorderService workorderService;

    /**
     * 创建工单
     */
    @ApiOperation("创建工单")
    @PostMapping("/create")
    public Result<String> createWorkorder(@RequestBody WorkorderParam param,@ApiIgnore @AuthenticationPrincipal AgentUserInfo user) {
        param.setDefaultParam(user.getUserId());
        return workorderService.createWorkorder(param);
    }

    /**
     * 关闭工单
     */
    @ApiOperation("关闭工单")
    @GetMapping("/close")
    public Result<String> closeWorkorder(@RequestParam(name = "workorderId")String workorderId, @ApiIgnore @AuthenticationPrincipal AgentUserInfo user) {
        return workorderService.closeWorkorder(workorderId,user.getUserId());
    }
}
