package com.gyee.frame.controller.ticket;


import com.alibaba.fastjson.JSONObject;
import com.gyee.frame.common.dataSources.DataSource;
import com.gyee.frame.common.dataSources.DataSourceType;
import com.gyee.frame.common.domain.AjaxResult;
import com.gyee.frame.model.ticket.Wfaction;
import com.gyee.frame.service.ticket.WfactionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

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

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author chenmh
 * @since 2020-07-21
 */
@RestController
@RequestMapping("/wfaction")
public class WfactionController {

    @Autowired
    WfactionService wfactionService;

    @DataSource(value = DataSourceType.TICKET)
    @PostMapping(value = "index")
    public AjaxResult index(@RequestParam("info") String info) {
        Map<String, Object> actionMap = null;
        JSONObject jsonObject = JSONObject.parseObject(info);
        int status = jsonObject.getInteger("status");
        if (status == 0){
            actionMap = wfactionService.listAction(
                    jsonObject.getInteger("status"), -1, -1, jsonObject.getString("wfname"));
        }

        if (status == 2){
            actionMap = wfactionService.listAction(
                    jsonObject.getInteger("status"),
                    jsonObject.getDouble("nodeid"),
                    jsonObject.getDouble("version"),
                    jsonObject.getString("wfname"));
        }

        if(actionMap == null || actionMap.size() == 0)
            return AjaxResult.error(4004, "工作流下一步操作查询失败");

        return AjaxResult.successData(actionMap);
    }

}

