/*
 * Copyright (c) 2023 codvision.com All Rights Reserved.
 */

package com.codvision.workflow.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.codvision.commoncore.common.ResponseEntity;
import com.codvision.webcore.bean.QueryPage;
import com.codvision.workflow.entity.WorkFlowExpression;
import com.codvision.workflow.service.WorkFlowExpressionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author hxl
 */
@Slf4j
@Api(tags = "工作流表达式管理")
@RestController
@RequiredArgsConstructor
@RequestMapping("/flowExpression")
public class WorkFlowExpressionController {

    private final WorkFlowExpressionService service;

    @PostMapping("/getPageResult")
    @ApiOperation("分页列表")
    public ResponseEntity<IPage<WorkFlowExpression>> getPageResult(@RequestBody QueryPage<Map<String, Object>> queryPage) {
        return new ResponseEntity<IPage<WorkFlowExpression>>().data(service.getPageResult(queryPage));
    }

    @PostMapping("/add")
    @ApiOperation("添加")
    public ResponseEntity<String> add(@Validated @RequestBody WorkFlowExpression expression) {
        service.addExpression(expression);
        return new ResponseEntity<String>().ok();
    }

    @PostMapping("/update")
    @ApiOperation("更新")
    public ResponseEntity<String> update(@RequestBody WorkFlowExpression expression) {
        service.updateExpression(expression);
        return new ResponseEntity<String>().ok();
    }

    @PostMapping("/del")
    @ApiOperation("删除")
    public ResponseEntity<String> del(@RequestParam(value = "id") Integer id) {
        service.removeExpression(id);
        return new ResponseEntity<String>().ok();
    }
}
