package com.trade.admin.workflow.controller;

import com.trade.admin.system.controller.BaseController;
import com.trade.admin.workflow.dto.*;
import com.trade.admin.workflow.service.BusinessProcessingLogService;
import com.trade.admin.workflow.service.BusinessProcessingTaskService;
import com.trade.common.core.domain.ResponseResult;
import com.trade.common.core.page.GridPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description:流程相关业务任务列表Controller（如立项流程、尽调流程、评审会流程等待我处理、我已处理和全部列表）
 * @Author:wanxiangZhou
 * @E-mail:zhouyu@sunxung.cn
 * @Date:2018年7月30日 下午7:18:28
 */
@RestController
@RequestMapping("/businessProcessingTask")
public class BusinessProcessingTaskController extends BaseController {
    @Autowired
    private BusinessProcessingTaskService businessProcessingTaskService;
    @Autowired
    private BusinessProcessingLogService processingLogService;

    /**
     * 查询待我处理的流程业务信息
     */
    @PostMapping(value = "/doMyPendingList")
    public ResponseResult<GridPage<BusinessProcessingTaskVo>> doMyPendingList(@RequestBody SearchBusinessProcessingTask search) {
        GridPage<BusinessProcessingTaskVo> gridPage = businessProcessingTaskService.findMyPendingList(search);
        return success(gridPage);
    }

    /**
     * 我已处理的流程业务信息
     */
    @PostMapping(value = "/doMyCompletedList")
    public ResponseResult<GridPage<BusinessProcessingTaskVo>> doMyCompletedList(SearchBusinessProcessingTask search) {
        GridPage<BusinessProcessingTaskVo> gridPage = businessProcessingTaskService.findMyCompletedList(search);
        return success(gridPage);
    }

    /**
     * 全部流程业务信息
     */
    @GetMapping(value = "/doList")
    public ResponseResult<GridPage<BusinessProcessingTaskVo>> doList(SearchBusinessProcessingTask search) {
        GridPage<BusinessProcessingTaskVo> gridPage = businessProcessingTaskService.findAll(search);
        return success(gridPage);
    }

    /**
     * 时间轴
     */
    @GetMapping(value = "/doTimelineList")
    public ResponseResult<List<BusinessProcessingLogDetailVo>> doTimelineList(@RequestParam Long businessKey, @RequestParam String businessType) {
        List<BusinessProcessingLogDetailVo> list = processingLogService.findByBusiness(businessKey, businessType);
        return success(list);
    }

    /**
     * 加载流程业务内各个节点处理的历史信息
     */
    @GetMapping(value = "/doBusinessHistoryView")
    public ResponseResult<List<BusinessHistoricDetailVo>> doBusinessHistoryView(@RequestParam Long businessKey, @RequestParam String businessType) {
        List<BusinessHistoricDetailVo> list = businessProcessingTaskService.getHistoricBusinessById(businessKey, businessType);
        return success(list);
    }

    /**
     * 验证任务是否已经完成或者被分配了
     *
     * @param taskId 任务ID
     * @return
     */
    @GetMapping(value = "/doDuplicateProcessing")
    public ResponseResult<Boolean> doDuplicateProcessing(String taskId) {
        Boolean isDuplicate = businessProcessingTaskService.duplicateProcessingTask(taskId);
        return success(isDuplicate);
    }

}
