package cn.autoform.web.service.process.impl;
|
|
import cn.autoform.bean.flow.def.ProcessActivityFrom;
|
import cn.autoform.bean.flow.def.ProcessDefineExtend;
|
import cn.autoform.bean.flow.task.ProcessTaskExtend;
|
import cn.autoform.db.entity.ProcessApproval;
|
import cn.autoform.factory.FormFactory;
|
import cn.autoform.factory.product.ProductMethod;
|
import cn.autoform.util.thread.Keys;
|
import cn.autoform.util.thread.ThreadData;
|
import cn.autoform.util.tool.JSONTool;
|
import cn.autoform.util.tool.ObjectUtil;
|
import cn.autoform.web.client.WorkflowClient;
|
import cn.autoform.web.client.util.WorkflowTool;
|
import cn.autoform.web.mapper.process.ProcessApprovalMapper;
|
import cn.autoform.web.service.process.ProcessApprovalService;
|
import com.alibaba.fastjson.TypeReference;
|
import lombok.extern.slf4j.Slf4j;
|
import net.sf.json.JSONObject;
|
import org.apache.commons.lang3.math.NumberUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.ui.ModelMap;
|
|
import javax.annotation.Resource;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.Objects;
|
import java.util.concurrent.TimeoutException;
|
@Service
|
@Slf4j
|
public class ProcessApprovalServiceImpl implements ProcessApprovalService{
|
|
@Resource
|
private ProcessApprovalMapper processMapper;
|
|
@Autowired
|
private WorkflowClient workflowClient;
|
|
@Autowired
|
private WorkflowTool workflowTool;
|
|
@Autowired
|
private FormFactory formFactory;
|
|
/**
|
* 添加流程定义
|
*/
|
|
@Override
|
public int addProcessApproval(Map<String, Object> map,ProcessApproval pro) {
|
Map<String,String> proMap = JSONTool.toObj(JSONTool.toJson(map.get("data")), new TypeReference<Map<String, String>>(){});
|
if(proMap==null){
|
return -1;
|
}
|
pro.setDefJson(JSONTool.toJson(proMap));
|
pro.setProcessDefName(proMap.get("processDefName"));
|
pro.setProcessDefId(proMap.get("processDefId"));
|
pro.setTemplateProcessDefId(proMap.get("templateProcessDefId"));
|
pro.setVersion(proMap.get("version"));
|
pro.setTenantID(ThreadData.get(Keys.TENANT_ID));
|
pro.setCompanyId(ThreadData.get(Keys.COMPANY_ID));
|
return processMapper.addProcessApproval(pro);
|
}
|
|
/**
|
* 删除流程定义
|
*/
|
@Override
|
public int deleteProcessApproval(String id) {
|
|
return processMapper.deleteProcessApproval(id);
|
}
|
|
/**
|
* 获取流程定义
|
*/
|
@Override
|
public ProcessApproval select(String orgId,String formID) {
|
return processMapper.select(orgId,formID, ThreadData.get(Keys.TENANT_ID),ThreadData.get(Keys.COMPANY_ID));
|
}
|
|
@Override
|
public ProcessApproval getApproval(ProcessApproval pro) {
|
pro.setTenantID(ThreadData.get(Keys.TENANT_ID));
|
pro.setCompanyId(ThreadData.get(Keys.COMPANY_ID));
|
return pro.getFormId()!=null && pro.getOrganizationId()!=null?processMapper.getApproval(pro):null;
|
}
|
|
@Override
|
public ProcessApproval selectApp(String formID) {
|
return processMapper.selectApp(formID, ThreadData.get(Keys.TENANT_ID),ThreadData.get(Keys.COMPANY_ID));
|
}
|
|
@Override
|
public int definePeploy(Map<String, Object> result) {
|
ProcessDefineExtend pde = JSONTool.toObj(JSONTool.toJson(result.get("data")), new TypeReference<ProcessDefineExtend>(){});
|
if(pde==null){
|
return -1;
|
}
|
ProcessApproval pa = new ProcessApproval();
|
pa.setDefJson(JSONTool.toJson(pde));
|
pa.setProcessDefId(Objects.toString(pde.getProcessDefId(), ""));
|
pa.setVersion(pde.getVersion());
|
return processMapper.updateDefInfo(pa);
|
}
|
|
@Override
|
public Map<String, String> getProcessParam(String formId, String tenantID,
|
Integer dataRowNum) throws Exception{
|
log.debug("查询执行流程参数,表单id:{},租户id:{},数据id{}", formId, tenantID, dataRowNum);
|
Map<String, String> param = new HashMap<>();
|
// 查询表单数据
|
ProductMethod productMethod = this.formFactory.createFormMethod();
|
Map<String, Object> sf = productMethod.queryFormDataList(formId, tenantID, dataRowNum, null);
|
Map<String, Object> mainInfo = (Map<String, Object>)sf.get("main");
|
if(mainInfo == null || mainInfo.isEmpty()) {
|
return param;
|
}
|
mainInfo.entrySet()
|
.stream()
|
.filter(e->!(e.getValue() instanceof List))
|
.filter(e->!Objects.equals("solidification", e.getKey()))
|
.forEach(e->param.put(e.getKey(), ObjectUtil.empty(e.getValue()) ? "NULL" : e.getValue().toString()));
|
return param;
|
}
|
|
public Map<String, String> getProcessParam(String processActivityDefId, Long processDefId, String formId, String tenantID,
|
Integer dataRowNum) throws Exception{
|
Map<String, String> param = new HashMap<>();
|
// 查询流程定义信息
|
ProcessApproval processApproval = processMapper.selectProcessApproval(Objects.toString(processDefId, ""));
|
if(processApproval == null || processApproval.getDefJson() == null) {
|
return param;
|
}
|
// 查询流程定义
|
ProcessDefineExtend processDefine = JSONTool.toObj(processApproval.getDefJson(), ProcessDefineExtend.class);
|
if(processDefine == null) {
|
return param;
|
}
|
List<ProcessActivityFrom> froms = processDefine.getActivityForm(processActivityDefId);
|
if(froms == null || froms.isEmpty()) {
|
return param;
|
}
|
// 查询表单数据
|
ProductMethod productMethod = this.formFactory.createFormMethod();
|
Map<String, Object> sf = productMethod.queryFormDataList(formId, tenantID, dataRowNum, null);
|
Map<String, Object> mainInfo = (Map<String, Object>)sf.get("main");
|
if(mainInfo == null || mainInfo.isEmpty()) {
|
return param;
|
}
|
froms.stream()
|
.forEach(from->{
|
Object val = mainInfo.get(from.getFromPath());
|
if(ObjectUtil.notEmpty(val)) {
|
param.put(from.getFromPath(), Objects.toString(val));
|
}else{
|
param.put(from.getFromPath(), "NULL");
|
}
|
});
|
return param;
|
}
|
|
protected ProcessTaskExtend getProcessTask(Map<String, Object> param) throws TimeoutException{
|
JSONObject jsonObject = new JSONObject();
|
jsonObject.putAll(param);
|
// jsonObject.put("activityInstId", processActivityInstId);
|
Map<String, Object> res = workflowClient.instSeacheHandle(workflowTool.getProcess(jsonObject));
|
Map<String, Object> list = (Map<String, Object>) res.get("data");
|
if(list == null || list.isEmpty()) {
|
return null;
|
}
|
List<ProcessTaskExtend> taskList = JSONTool.toObj(JSONTool.toJson(list.get("data")), new TypeReference<List<ProcessTaskExtend>>(){});
|
if(taskList == null || taskList.size() == 0) {
|
return null;
|
}
|
return taskList.get(0);
|
}
|
|
@Override
|
public Map<String, String> getProcessOneActivityParam(String processIntsId, String processDefId, String formId, String tenantID, Integer dataRowNum)
|
throws Exception {
|
log.debug("查询执行流程参数:流程实例id:{},流程定义id:{},表单id:{},租户id:{},数据id{}", processIntsId, processDefId, formId, tenantID, dataRowNum);
|
|
ProcessTaskExtend pTask = getProcessTask(new ModelMap("processInstId", processIntsId));
|
if(ObjectUtil.empty(pTask)) {
|
return new HashMap<>();
|
}
|
|
return getProcessParam(pTask.getActivityDefId(), NumberUtils.createLong(processDefId), formId, tenantID, dataRowNum);
|
}
|
public static void main(String... args){
|
System.out.println(
|
JSONTool.toObj("", Map.class).get("budget_itemMoney")
|
);
|
}
|
}
|