package com.chushang.inspection.project.controller;

import com.chushang.common.core.validator.Create;
import com.chushang.common.core.validator.Update;
import com.chushang.common.core.web.AjaxResult;
import com.chushang.common.log.annotation.SysLog;
import com.chushang.common.log.enums.BusinessType;
import com.chushang.inspection.project.dto.TaskGraphDTO;
import com.chushang.inspection.project.service.PollingTaskAutographService;
import com.chushang.security.annotation.RequiresPermissions;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 支行签名
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/graph/task")
public class PollingTaskAutographController {

    private final PollingTaskAutographService taskAutographService;

    /**
     * 查询 客户经理签名
     */
    @GetMapping("/{taskId}")
    @RequiresPermissions("task:graph:query")
    public AjaxResult get(@PathVariable Long taskId) {
        return AjaxResult.success(taskAutographService.getById(taskId));
    }

    @PostMapping("/save")
    @RequiresPermissions("task:graph:save")
    @SysLog(value = "任务签名", businessType = BusinessType.INSERT)
    public AjaxResult save(@RequestBody @Validated(Create.class) TaskGraphDTO task) {
        taskAutographService.save(task);
        return AjaxResult.success();
    }

    @PostMapping("/update")
    @RequiresPermissions("task:graph:update")
    @SysLog(value = "任务签名", businessType = BusinessType.UPDATE)
    public AjaxResult update(@RequestBody @Validated(Update.class) TaskGraphDTO task) {
        taskAutographService.update(task);
        return AjaxResult.success();
    }



}
