TaskCheckController.java 2.66 KB
package com.hotent.runtime.controller;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.hotent.base.controller.BaseController;
import com.hotent.base.model.CheckResult;
import com.hotent.base.query.QueryFilter;
import com.hotent.base.util.BeanUtils;
import com.hotent.bpm.api.model.process.task.BpmTask;
import com.hotent.bpm.persistence.manager.BpmCheckOpinionManager;
import com.hotent.bpm.persistence.manager.BpmTaskManager;
import com.hotent.bpm.persistence.model.DefaultBpmCheckOpinion;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

/**
 * 对接统一待办反查任务相关接口
 * 
 * @company 广州宏天软件股份有限公司
 * @author zhangxianwen
 * @email zhangxw@jee-soft.cn
 * @date 2022年11月21日
 */

@RestController
@RequestMapping("/task")
@Api(tags="TaskCheckController")
public class TaskCheckController {
	
	@Resource
	BpmTaskManager bpmTaskManager;
	@Resource
	BpmCheckOpinionManager bpmCheckOpinionManager;
	
	private Logger logger = LoggerFactory.getLogger(TaskCheckController.class);
	
	@RequestMapping(value="/check",method=RequestMethod.GET, produces = { "application/json; charset=utf-8" })
	@ApiOperation(value = "根据任务id判断任务是否已转已办", httpMethod = "GET", notes = "根据任务id判断任务是否已转已办(返回值:true(已待办转已办),false(待办还存在))")
	public CheckResult checkTaskDown(@ApiParam(name="instanceId",value="实例id", required = true) @RequestParam String instanceId,@ApiParam(name="taskId",value="任务id", required = true) @RequestParam String taskId) throws Exception{
		CheckResult checkResult = new CheckResult();
		try {
			boolean hasDown = false;
			BpmTask task = bpmTaskManager.get(taskId);
			if(BeanUtils.isEmpty(task)){
				DefaultBpmCheckOpinion opinoin = bpmCheckOpinionManager.getTaskKeyByTaskId(taskId);
				if(BeanUtils.isNotEmpty(opinoin) && BeanUtils.isNotEmpty(opinoin.getCompleteTime())) {
					hasDown = true;
					checkResult.setDoneTime(opinoin.getCompleteTime());
				}
			}
			checkResult.setState(hasDown);
			checkResult.setMessage("获取成功");
			checkResult.setValue(hasDown);
			return checkResult;
		} catch (Exception e) {
			logger.error(String.format("查询失败:%s", e.getMessage()));
			return new CheckResult(false,String.format("查询失败:%s", e.getMessage()), false, null);
		}
	}
	
}