Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.iqiny.silly.spring.controller.SillyController Maven / Gradle / Ivy
/*
* Copyright iqiny.com
*
* https://gitee.com/iqiny/silly
*
* project name:silly-spring
* project description:top silly project pom.xml file
*/
package com.iqiny.silly.spring.controller;
import com.iqiny.silly.common.exception.SillyCheckException;
import com.iqiny.silly.common.util.SillyAssert;
import com.iqiny.silly.common.util.SillyReflectUtil;
import com.iqiny.silly.common.util.StringUtils;
import com.iqiny.silly.core.base.core.SillyMaster;
import com.iqiny.silly.core.cache.SillyCache;
import com.iqiny.silly.core.common.SillyExecutorUtil;
import com.iqiny.silly.core.common.SillyLockUtil;
import com.iqiny.silly.core.config.SillyCategoryConfig;
import com.iqiny.silly.core.config.SillyConfigContent;
import com.iqiny.silly.core.config.property.SillyProcessNodeProperty;
import com.iqiny.silly.core.config.property.SillyProcessProperty;
import com.iqiny.silly.core.engine.SillyMasterTask;
import com.iqiny.silly.core.engine.SillyTask;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.*;
import static com.iqiny.silly.core.common.SillyConfigUtil.processKeys;
/**
* 默认silly提供的接口
*/
@ResponseBody
@RequestMapping("${silly.webController.urlPrefix:'/v1/silly'}/{category}")
public class SillyController {
@Autowired
private SillyResultWrapper sillyResultWrapper;
/**
* 待办列表
*/
@PostMapping("/todo")
public Object todo(@PathVariable("category") String category, @RequestBody Map params) {
Object o = SillyExecutorUtil.execute(category, config -> config.getSillyReadService().queryDoingPage(params));
return sillyResultWrapper.wrapperOk(o);
}
/**
* 历史列表
*/
@PostMapping("/history")
public Object history(@PathVariable("category") String category, @RequestBody Map params) {
Object o = SillyExecutorUtil.execute(category, config -> config.getSillyReadService().queryHistoryPage(params));
return sillyResultWrapper.wrapperOk(o);
}
/**
* 查询列表
*/
@PostMapping("/query")
public Object query(@PathVariable("category") String category, @RequestBody Map params) {
Object o = SillyExecutorUtil.execute(category, config -> config.getSillyReadService().queryPage(params));
return sillyResultWrapper.wrapperOk(o);
}
/**
* 获取分页数据(经过流程引擎, 获取对应任务信息)
*/
@PostMapping("/source")
public Object sourcePage(@PathVariable("category") String category, @RequestBody Map params) {
Object o = SillyExecutorUtil.execute(category, config -> config.getSillyReadService().sourcePage(params));
return sillyResultWrapper.wrapperOk(o);
}
/**
* 新增数据
*/
@PostMapping("/addMap")
public Object add(@PathVariable("category") String category, @RequestBody Map params) {
Object o = SillyExecutorUtil.execute(category, config -> {
SillyMaster master = config.getSillyWriteService().saveOrNewMap(params);
Map searchMap = new HashMap<>();
searchMap.put("id", master.getId());
return config.getSillyReadService().queryDoingPage(searchMap);
});
return sillyResultWrapper.wrapperOk(o);
}
/**
* 新增或保存数据
*/
@PostMapping("/addOrSaveMap")
public Object addOrSaveMap(@PathVariable("category") String category, @RequestBody Map params) {
Object o = SillyExecutorUtil.execute(category, config -> {
SillyMaster master = config.getSillyWriteService().saveOrNewMap(params);
Map searchMap = new HashMap<>();
searchMap.put("id", master.getId());
return config.getSillyReadService().queryDoingPage(searchMap);
});
return sillyResultWrapper.wrapperOk(o);
}
/**
* 保存数据
*/
@PostMapping("/saveMap")
public Object save(@PathVariable("category") String category, @RequestBody Map params) {
Object o = SillyExecutorUtil.execute(category, config -> config.getSillyWriteService().saveTaskMap(params));
return sillyResultWrapper.wrapperOk(o);
}
/**
* 结束流程
*/
@PostMapping("/forceEndProcess/{masterId}")
public Object forceEndProcess(@PathVariable("category") String category, @PathVariable("masterId") String masterId) {
SillyExecutorUtil.lockMasterExecute(category, masterId, config -> {
SillyMaster master = config.getSillyReadService().getMaster(masterId);
SillyAssert.notNull(master, "主数据信息不存在,无法结束流程");
SillyAssert.notNull(master.getProcessId(), "流程实例信息不存在,无法结束流程");
config.getSillyWriteService().forceEndProcess(masterId, master.getProcessId());
return null;
});
return sillyResultWrapper.wrapperOk("结束流程成功");
}
/**
* 删除并结束流程
*/
@PostMapping("/delete/{masterId}")
public Object delete(@PathVariable("category") String category, @PathVariable("masterId") String masterId) {
SillyExecutorUtil.lockMasterExecute(category, masterId, config -> {
SillyMaster master = config.getSillyReadService().getMaster(masterId);
SillyAssert.notNull(master, "主数据信息不存在,无法删除");
config.getSillyWriteService().delete(masterId, master.getProcessId());
return null;
});
return sillyResultWrapper.wrapperOk("数据删除成功");
}
/**
* 主数据详情
*/
@GetMapping("/{masterId}")
public Object get(@PathVariable("category") String category, @PathVariable("masterId") String masterId) {
Object o = SillyExecutorUtil.execute(category, config -> config.getSillyReadService().getMasterMap(masterId));
return sillyResultWrapper.wrapperOk(o);
}
/**
* root 对象详情
*/
@GetMapping(value = "/root")
public Object root(@PathVariable("category") String category, @RequestParam("id") String id) {
Map map = SillyExecutorUtil.execute(category, config -> config.getSillyReadService().queryRoot(id));
return sillyResultWrapper.wrapperOk(new TreeMap<>(map));
}
/**
* root 对象详情
*/
@GetMapping(value = "/nodeKeyRoot")
public Object nodeKeyRoot(@PathVariable("category") String category, @RequestParam("id") String id) {
Map map = SillyExecutorUtil.execute(category, config -> config.getSillyReadService().queryNodeKeyRoot(id));
return sillyResultWrapper.wrapperOk(new TreeMap<>(map));
}
/**
* 主对象 + root 内容
*/
@GetMapping(value = "/masterAndRoot")
public Object masterAndRoot(@PathVariable("category") String category, @RequestParam("id") String id) {
Map map = SillyExecutorUtil.execute(category, config -> {
Map masterMap = config.getSillyReadService().getMasterMap(id);
Map rootMap = config.getSillyReadService().queryRoot(id);
Map returnMap = new HashMap<>();
returnMap.put("root", new TreeMap<>(rootMap));
returnMap.put("master", new TreeMap<>(masterMap));
return returnMap;
});
return sillyResultWrapper.wrapperOk(map);
}
/**
* 获取当前任务操作信息
*/
@GetMapping(value = "/option")
public Object option(@PathVariable("category") String category, @RequestParam("id") String id
, @RequestParam(value = "taskId", required = false) String taskId
, @RequestParam(value = "nodeKey", required = false) String nodeKey
) {
Object option = SillyExecutorUtil.execute(category,
config -> {
if (StringUtils.isNotBlank(nodeKey)) {
return config.getSillyReadService().option(id, nodeKey);
} else if (StringUtils.isNotBlank(taskId)) {
return config.getSillyReadService().optionByTask(id, taskId);
} else {
throw SillyCheckException.newInstance("获取当前任务操作信息 参数 taskId、nodeKey 必须传递一个");
}
}
);
return sillyResultWrapper.wrapperOk(option);
}
/**
* 人员流转
*/
@PostMapping("/flow")
public Object flow(@PathVariable("category") String category,
@RequestParam("taskId") String taskId,
@RequestParam("userId") String userId,
@RequestParam("reason") String reason) {
SillyExecutorUtil.lockMasterExecute(category, null, config -> {
config.getSillyWriteService().changeUser(taskId, userId, reason);
return null;
});
return sillyResultWrapper.wrapperOk("人员流转成功");
}
/**
* 任务驳回
*/
@PostMapping("/reject")
public Object reject(@PathVariable("category") String category,
@RequestParam("taskId") String taskId,
@RequestParam("nodeKey") String nodeKey,
@RequestParam("reason") String reason,
@RequestParam(value = "userId", required = false) String userId,
@RequestParam(value = "deleteOtherTask", required = false) Boolean deleteOtherTask) {
SillyExecutorUtil.lockTaskExecute(category, taskId, config -> {
boolean deleteOtherTaskFlag = deleteOtherTask == null ? Boolean.TRUE : deleteOtherTask;
config.getSillyWriteService().reject(taskId, nodeKey, reason, userId, deleteOtherTaskFlag);
return null;
});
return sillyResultWrapper.wrapperOk("任务驳回成功");
}
/**
* 任务驳回
*/
@PostMapping("/rejectByProcessId")
public Object rejectByProcessId(@PathVariable("category") String category,
@RequestParam("processId") String processId,
@RequestParam("nodeKey") String nodeKey,
@RequestParam("reason") String reason,
@RequestParam(value = "userId", required = false) String userId) {
SillyExecutorUtil.lockObjExecute(category, processId, config -> {
List tasks = config.getSillyEngineService().findTaskByProcessInstanceId(processId);
SillyAssert.notEmpty(tasks, "当前流程实例下无可执行任务");
config.getSillyWriteService().reject(tasks.get(0).getId(), nodeKey, reason, userId, true);
return null;
});
return sillyResultWrapper.wrapperOk("任务驳回成功");
}
/**
* 跳转节点(若流程未启动,则进行启动后跳转;若流程进行中,则直接跳转;若流程已结束,则重启流程后跳转)
*/
@PostMapping("/dumpNode")
public Object dumpNode(@PathVariable("category") String category,
@RequestParam("masterId") String masterId,
@RequestParam("nodeKey") String nodeKey,
@RequestParam(value = "reason", required = false) String reason,
@RequestParam(required = false) Map params) {
SillyExecutorUtil.lockMasterExecute(category, masterId, config -> {
config.getSillyWriteService().jumpNode(masterId, nodeKey, reason, params);
return null;
});
return sillyResultWrapper.wrapperOk("跳转节点成功");
}
/**
* 根据category刷新缓存
*/
@PostMapping("/refreshCache")
public Object refreshCache(@PathVariable("category") String category) {
SillyExecutorUtil.lockExecute(category, null, null, category, config -> {
SillyCache sillyCache = config.getSillyCache();
sillyCache.clearAll(category);
return null;
});
return sillyResultWrapper.wrapperOk("缓存清除成功");
}
@Autowired
private SillyConfigContent sillyConfigContent;
private static final Object refreshLock = new Object();
/**
* 更新傻瓜工作流配置缓存
*/
@RequestMapping("/refreshResource")
public Object refreshResource() {
SillyLockUtil.getLock(refreshLock, 0);
try {
sillyConfigContent.refresh();
} finally {
SillyLockUtil.unlock(refreshLock);
}
return sillyResultWrapper.wrapperOk("更新傻瓜工作流配置完成");
}
/**
* 流程履历
*/
@GetMapping("/resumeList/{masterId}")
public Object resumeList(@PathVariable("category") String category, @PathVariable("masterId") String masterId) {
Object obj = SillyExecutorUtil.execute(category, config -> config.getSillyResumeService().selectList(masterId, category));
return sillyResultWrapper.wrapperOk(obj);
}
/**
* 获取当前业务下自己的任务信息
*/
@GetMapping(value = "/myTask")
public Object myTask(@RequestParam("category") String category, @RequestParam(value = "userId", required = false) String userId, @RequestParam("masterId") String masterId) {
Object obj = SillyExecutorUtil.execute(category, config -> {
Set allGroupId = config.getSillyTaskGroupHandle().getAllGroupId(category, userId);
return config.getSillyEngineService().findMyTaskByMasterId(processKeys(category), userId, masterId, allGroupId);
});
return sillyResultWrapper.wrapperOk(obj);
}
/**
* 流程参数属性
*/
@GetMapping("/property")
public Object propertyAll(@PathVariable("category") String category) {
SillyProcessProperty property = SillyExecutorUtil.execute(category, SillyCategoryConfig::getSillyProcessProperty);
final SillyProcessProperty processProperty = SillyReflectUtil.serializeCloneObj(property);
return sillyResultWrapper.wrapperOk(processProperty);
}
/**
* 流程参数属性
*/
@GetMapping("/property/{processKey}/{nodeKey}")
public Object property(@PathVariable("category") String category,
@PathVariable("processKey") String processKey,
@PathVariable("nodeKey") String nodeKey) {
SillyProcessNodeProperty nodeProperty = SillyExecutorUtil.execute(category, config ->
config.getSillyProcessProperty().getMaster().get(processKey).getNode().get(nodeKey)
);
final SillyProcessNodeProperty processNodeProperty = SillyReflectUtil.serializeCloneObj(nodeProperty);
return sillyResultWrapper.wrapperOk(processNodeProperty);
}
/**
* 待办数量
*/
@GetMapping("/count")
public SillyR count(@PathVariable("category") String category) {
List taskList = SillyExecutorUtil.execute(category, config -> {
String currentUserId = null;
Set allGroupId = null;
if (!config.getSillyUserUtil().isAdmin()) {
currentUserId = config.getSillyUserUtil().currentUserId();
allGroupId = config.getSillyTaskGroupHandle().getAllGroupId(category, currentUserId);
}
return config.getSillyEngineService().findMyTaskByMasterId(processKeys(category), currentUserId, null, allGroupId);
});
return SillyR.ok(taskList.size());
}
}