package com.ho.flow.controller.process;

import com.ho.common.tools.annotation.LogAnnotation;
import com.ho.common.tools.constant.ContextConstant;
import com.ho.common.tools.exception.DataResult;
import com.ho.common.tools.util.PageResult;
import com.ho.flow.entity.ProcessTemplate;
import com.ho.flow.service.process.service.ProcessManagementService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @Author yule
 * @Date 2023/8/18 9:20
 * @desc ${}
 */
@RequestMapping(ContextConstant.FLOW_CONTEXT + "processManagement")
@RestController
@Api(tags = "流程管理")
public class ProcessManagementController {

    @Autowired
    ProcessManagementService processManagementService;

    @PostMapping
    @ApiOperation(value = "分页查询")
    public DataResult<PageResult<ProcessTemplate>> page(@RequestBody @Valid ProcessTemplate processTemplate) {
        PageResult<ProcessTemplate> page = processManagementService.selectPage(processTemplate);
        return DataResult.success(page);

    }


    @PostMapping("add")
    @ApiOperation(value = "新增流程模板")
    @LogAnnotation(title = "流程模板", action = "新增流程模板")
    public DataResult add(@RequestBody @Valid ProcessTemplate processTemplate) {
        processManagementService.add(processTemplate);
        return DataResult.success();
    }

    @PostMapping("delete")
    @ApiOperation(value = "删除流程模板")
    @LogAnnotation(title = "流程模板", action = "删除流程模板")
    public DataResult delete(@RequestBody @Valid ProcessTemplate processTemplate) {
        processManagementService.delete(processTemplate);
        return DataResult.success();
    }

    @PostMapping("edit")
    @ApiOperation(value = "修改流程模板")
    @LogAnnotation(title = "流程模板", action = "修改流程模板")
    public DataResult edit(@RequestBody @Valid ProcessTemplate processTemplate) {
        processManagementService.edit(processTemplate);
        return DataResult.success();
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "查询详情")
    public DataResult<ProcessTemplate> getInfo(@PathVariable Integer id) {
        return  DataResult.success(processManagementService.getInfo(id));
    }

    @PostMapping("/{id}")
    @ApiOperation(value = "查询流程图")
    public DataResult<String> getBpmn(@PathVariable Integer id) {
        return  DataResult.success(processManagementService.getBpmn(id));
    }
}
