package cn.iocoder.yudao.module.bpm.controller.admin.definition;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.copy.TaskCopyRespVO;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.copy.TaskCopySaveReqVO;
import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.TaskCopyDO;
import cn.iocoder.yudao.module.bpm.service.definition.TaskCopyService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

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

/**
 * @Author: jinyd
 * @CreateTime: 2024/9/25  15:58
 * @Description:
 * @Version: 4.0
 */

@Tag(name = "管理后台 - 抄送节点信息")
@RestController
@RequestMapping("/bpm/task-copy")
@Validated
public class TaskCopyController {

    @Resource
    private TaskCopyService taskCopyService;

    @PostMapping("/create")
    @Operation(summary = "创建抄送节点信息")
    @PreAuthorize("@ss.hasPermission('bpm:task-copy:create')")
    public CommonResult<Long> createTaskCopy(@Valid @RequestBody TaskCopySaveReqVO createReqVO) {
        return success(taskCopyService.createTaskCopy(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新抄送节点信息")
    @PreAuthorize("@ss.hasPermission('bpm:task-copy:update')")
    public CommonResult<Boolean> updateTaskCopy(@Valid @RequestBody TaskCopySaveReqVO updateReqVO) {
        taskCopyService.updateTaskCopy(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除抄送节点信息")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('bpm:task-copy:delete')")
    public CommonResult<Boolean> deleteTaskCopy(@RequestParam("id") Long id) {
        taskCopyService.deleteTaskCopy(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得抄送节点信息")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('bpm:task-copy:query')")
    public CommonResult<TaskCopyRespVO> getTaskCopy(@RequestParam("id") Long id) {
        TaskCopyDO taskCopy = taskCopyService.getTaskCopy(id);
        return success(BeanUtils.toBean(taskCopy, TaskCopyRespVO.class));
    }

}
