package com.fjhx.controller.example;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fjhx.entity.example.ExampleInfo;
import com.fjhx.service.example.ExampleInfoService;
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.List;
import java.util.Map;

/**
 * <p>
 * 流程实例 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2022-08-18
 */
@RestController
@RequestMapping("/exampleInfo")
public class ExampleInfoController {

    @Autowired
    private ExampleInfoService exampleInfoService;

    /**
     * 代办
     */
    @PostMapping("/getWaitingProcessingPage")
    public R getWaitingProcessingPage(@RequestBody Map<String, String> condition) {
        Page<Map<String, Object>> result = exampleInfoService.getWaitingProcessingPage(condition);
        return R.data(result);
    }

    /**
     * 审批记录
     */
    @PostMapping("/record")
    public R record(@RequestBody ExampleInfo exampleInfo) {
        List<Map<String, Object>> result = exampleInfoService.record(exampleInfo.getFlowLinkNo());
        return R.data(result);
    }

    /**
     * 展示流程
     */
    @PostMapping("/showFlow")
    public R showFlow(@RequestBody Map<String, String> condition) {
        List<Map<String, Object>> result = exampleInfoService.showFlow(condition.get("code"));
        return R.data(result);
    }

    /**
     * 已办
     */
    @PostMapping("/getDone")
    public R getDone(Map<String, String> condition) {
        Page<Map<String, Object>> result = exampleInfoService.getDone(condition);
        return R.data(result);
    }

    /**
     * 撤回
     */
    @PostMapping("/withdraw")
    public R withdraw(Map<String, Long> condition) {
        Long withdrawExampleInfoId = condition.get("withdrawExampleInfoId");
        Long withdrawExampleDetailsId = condition.get("withdrawExampleDetailsId");
        exampleInfoService.withdraw(withdrawExampleInfoId, withdrawExampleDetailsId);
        return R.success();
    }

    /**
     * 撤销
     */
    @PostMapping("/revoke")
    public R revoke(Map<String, Long> condition) {
        Long withdrawExampleInfoId = condition.get("withdrawExampleInfoId");
        exampleInfoService.revoke(withdrawExampleInfoId);
        return R.success();
    }

}
