package com.fjhx.controller.process;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fjhx.entity.process.ProcessTenant;
import com.fjhx.params.NodeDetailsVo;
import com.fjhx.service.process.ProcessNodeService;
import com.fjhx.service.process.ProcessTenantService;
import org.springblade.core.tool.api.R;
import org.springframework.beans.factory.annotation.Autowired;
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.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 租户流程表 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2022-08-16
 */
@RestController
@RequestMapping("/processTenant")
public class ProcessTenantController {

    @Autowired
    private ProcessTenantService processTenantService;

    @Autowired
    private ProcessNodeService processNodeService;

    /**
     * 分页
     */
    @PostMapping("/page")
    public R page(@RequestBody Map<String, String> condition) {
        Page<Map<String, Object>> result = processTenantService.getPage(condition);
        return R.data(result);
    }

    /**
     * 添加租户流程
     */
    @PostMapping("/add")
    public R add(@RequestBody ProcessTenant processTenant) {
        processTenantService.add(processTenant);
        return R.success();
    }

    /**
     * 添加流程版本
     */
    @PostMapping("/addVersion")
    public R addVersion(@RequestBody NodeDetailsVo nodeDetailsVo) {
        processTenantService.addVersion(nodeDetailsVo);
        return R.success();
    }

    /**
     * 获取流程详情
     */
    @PostMapping("/getDetails")
    public R getDetails(@RequestBody HashMap<String, String> condition) {
        Map<String, Object> result = processNodeService.getDetails(condition);
        return R.data(result);
    }

    /**
     * 获取流程版本号
     */
    @PostMapping("/getVersionByProcessInfoId")
    public R getVersionByProcessInfoId(@RequestBody ProcessTenant processTenant) {
        List<ProcessTenant> result = processTenantService.getVersionByProcessInfoId(processTenant);
        return R.data(result);
    }

    /**
     * 修改流程版本号
     */
    @PostMapping("/editVersion")
    public R editVersion(@RequestBody ProcessTenant processTenant) {
        processTenantService.editVersion(processTenant);
        return R.success();
    }

}

