CreateRequestTest.java
package test;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.junit.Test;
import ecustom.ecology.commons.CustomMap;
import ecustom.ecology.services.BillService;
import weaver.soa.workflow.request.DetailTableInfo;
import weaver.soa.workflow.request.MainTableInfo;
import weaver.soa.workflow.request.RequestInfo;
import weaver.soa.workflow.request.RequestService;
public class CreateRequestTest extends BaseTest {
@Test
public void createRequest() throws Exception {
RequestService rs = new RequestService();
RequestInfo ri = new RequestInfo();
ri.setCreatorid("1"); // 创建人
ri.setWorkflowid("129"); // 路径ID,指定需要创建的流程
ri.setDescription("JX01-季度/月度绩效考核流程-张三-2020-09-17"); // 请求标题
ri.setRequestlevel("0"); // 紧急程度,0正常
ri.setRemindtype("0");
ri.setIsNextFlow("1"); // 0 停留在申请人待办,1 提交到下一节点
ri.setMainTableInfo(getMainTableInfo()); // 设置主表
ri.setDetailTableInfo(getDetailTableInfo()); // 设置明细表
int requestId = Integer.parseInt(rs.createRequest(ri)); // 发起流程
if (requestId < 0) throw new RuntimeException(getRequestIdText(requestId));
System.out.println("发起流程成功,requestId = " + requestId);
}
/**
* 获取主表信息
* @return
* Create date: 2020年9月17日
*/
private MainTableInfo getMainTableInfo() {
CustomMap mf = new CustomMap(); // Main fields
mf.put("bkhr", "1"); // 被考核人
mf.put("bkhrgh", "M000001"); // 被考核人工号
mf.put("zxbm", "1"); // 最小部门
mf.put("khfzr", "2"); // 考核负责人
mf.put("gw", "1"); // 岗位
mf.put("zj", "M5-A"); // 职级
mf.put("rzrq", "2020-09-17"); // 入职日期
// TODO ...
return new BillService().genMainTableInfo(mf);
}
/**
* 获取明细表信息
* @return
* Create date: 2020年9月17日
*/
private DetailTableInfo getDetailTableInfo() {
List<List<CustomMap>> tables = new ArrayList<List<CustomMap>>();
tables.add(new ArrayList<CustomMap>());
List<Map<String, Object>> zbRows = getZbRows();
for (Map<String, Object> zbRow : zbRows) {
CustomMap row = new CustomMap();
row.put("ZBLX", zbRow.get("ZBFL")); // 指标分类
row.put("ZBMC", zbRow.get("ID")); // 指标名称
row.put("QZ", zbRow.get("QZ")); // 权重
tables.get(0).add(row);
}
return new BillService().genDetailTableInfo(tables);
}
/**
* 获取指标信息。
* @return
* Create date: 2020年9月17日
*/
private List<Map<String, Object>> getZbRows() {
// TODO ...
return null;
}
private String getRequestIdText(int requestId) {
if (requestId > 0) return "创建流程成功";
if (requestId == -2) return "没有创建权限";
if (requestId == -4) return "保存表单主表数据失败,请检查表单字段类型";
if (requestId == -5) return "更新流程级别失败";
if (requestId == -6) return "无法创建流程待办任务";
if (requestId == -7) return "流程下一节点出错,请检查配置(操作者、出口及条件、附加操作接口等)";
if (requestId == -8) return "流程节点自动赋值操作错误";
return "未知错误 " + requestId;
}
}
CustomMap.java
package ecustom.ecology.commons;
import java.util.HashMap;
public class CustomMap extends HashMap<String, Object> {
private static final long serialVersionUID = 1L;
public Integer getInteger(String key) {
return CustomUtil.getInteger(get(key));
}
public int getInt(String key) {
return CustomUtil.getInt(get(key));
}
public String getString(String key) {
return CustomUtil.getString(get(key));
}
}
BillService.java
package ecustom.ecology.services;
import java.util.List;
import ecustom.ecology.commons.CustomMap;
import weaver.soa.workflow.request.Cell;
import weaver.soa.workflow.request.DetailTable;
import weaver.soa.workflow.request.DetailTableInfo;
import weaver.soa.workflow.request.MainTableInfo;
import weaver.soa.workflow.request.Property;
import weaver.soa.workflow.request.Row;
public class BillService {
public MainTableInfo genMainTableInfo(CustomMap fields) {
MainTableInfo mti = new MainTableInfo();
for (String name : fields.keySet()) {
mti.addProperty(genMainField(name, fields.getString(name)));
}
return mti;
}
public DetailTableInfo genDetailTableInfo(List<List<CustomMap>> tables) {
DetailTableInfo dti = new DetailTableInfo();
for (int i = 0; i < tables.size(); i++) {
dti.addDetailTable(genDetailTable(i + 1, tables.get(i)));
}
return dti;
}
public DetailTable genDetailTable(int id, List<CustomMap> rows) {
DetailTable dt = new DetailTable();
dt.setId(id + "");
for (CustomMap rowMap : rows) {
dt.addRow(genRow(rowMap));
}
return dt;
}
public Property genMainField(String name, String value) {
if (name == null || name.isEmpty()) throw new RuntimeException("字段名不能为空!");
if (value == null) value = "";
Property field = new Property();
field.setName(name);
field.setValue(value);
return field;
}
public Row genRow(CustomMap rowMap) {
Row row = new Row();
for (String name : rowMap.keySet()) {
row.addCell(genCell(name, rowMap.getString(name)));
}
return row;
}
public Cell genCell(String name, String value) {
if (name == null || name.isEmpty()) throw new RuntimeException("字段名不能为空!");
if (value == null) value = "";
Cell field = new Cell();
field.setName(name);
field.setValue(value);
return field;
}
}