TaskController.java 3.09 KB
package com.trash.activiti.controller;


import com.github.pagehelper.Page;
import com.trash.common.annotation.RepeatSubmit;
import com.trash.common.core.controller.BaseController;
import com.trash.common.core.domain.AjaxResult;
import com.trash.common.core.page.PageDomain;
import com.trash.common.core.page.TableDataInfo;
import com.trash.common.core.page.TableSupport;
import com.trash.common.utils.ServletUtils;
import com.trash.activiti.domain.dto.ActTaskDTO;
import com.trash.activiti.domain.dto.ActWorkflowFormDataDTO;
import com.trash.activiti.mapper.ActReDeploymentMapper;
import com.trash.activiti.service.IActTaskService;

import org.activiti.api.task.runtime.TaskRuntime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;


@RestController
@RequestMapping("/task")
public class TaskController extends BaseController {
    @Autowired
    private TaskRuntime taskRuntime;

    @Autowired
    private IActTaskService actTaskService;

    @Autowired
    private ActReDeploymentMapper actReDeploymentMapper;
    
    //获取我的代办任务
    @GetMapping(value = "/list")
    public TableDataInfo getTasks() {
        PageDomain pageDomain = TableSupport.buildPageRequest();
        Page<ActTaskDTO> hashMaps = actTaskService.selectProcessDefinitionList(pageDomain);
        
        List<String> allNames =  actReDeploymentMapper.selectTitles();
        List<String> names =  new ArrayList<String>();
        
        for(String str:allNames){
        	for(ActTaskDTO dto:hashMaps.getResult()){
        		if(str.equals(dto.getInstanceName())){
        			names.add(str);
        		}
        	}
        }
        
        TableDataInfo tableDataInfo = getDataTable(hashMaps);
        
        int pageNum = pageDomain.getPageNum();
        int pageSize = pageDomain.getPageSize();

        tableDataInfo.setNames(names);
        
        if(tableDataInfo.getRows().size() <= pageSize){
        	return tableDataInfo;
        }
        
        if(tableDataInfo.getRows().size() > (pageNum)*pageSize){
        	tableDataInfo.setRows(tableDataInfo.getRows().subList((pageNum -1)*pageSize, (pageNum)*pageSize));
        }else{
        	tableDataInfo.setRows(tableDataInfo.getRows().subList((pageNum -1)*pageSize, tableDataInfo.getRows().size()));
        }
        
        
        return tableDataInfo;
    }

    @RequestMapping("/taskHistory")
    public String taskHistory() {
         return "taskHistory";
    }

    

    //渲染表单
    @GetMapping(value = "/formDataShow/{taskID}")
    public AjaxResult formDataShow(@PathVariable("taskID") String taskID) {

        return AjaxResult.success(actTaskService.formDataShow(taskID));
    }

    //保存表单
    @PostMapping(value = "/formDataSave/{taskID}")
    @RepeatSubmit
    public AjaxResult formDataSave(@PathVariable("taskID") String taskID,
                                   @RequestBody   List<ActWorkflowFormDataDTO> formData ) throws ParseException {
        return toAjax(actTaskService.formDataSave(taskID, formData));

    }

}