package com.zy.asrs.wcs.rcs.thread;
|
|
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONObject;
|
import com.zy.asrs.framework.common.Cools;
|
import com.zy.asrs.wcs.asrs.entity.param.FlowLogicCodeParam;
|
import org.apache.commons.codec.digest.DigestUtils;
|
import org.apache.commons.codec.digest.Md5Crypt;
|
import org.springframework.stereotype.Component;
|
|
import java.util.List;
|
import java.util.Map;
|
|
@Component
|
public class FlowExecute {
|
|
//执行流程图
|
public boolean execute(List<JSONObject> list) {
|
String currentId = list.get(0).getString("id");
|
|
String listId = DigestUtils.md5Hex(JSON.toJSONString(list));
|
|
while (currentId != null) {
|
//获取流程图
|
JSONObject flow = findFLow(list, currentId);
|
if (flow == null) {
|
break;
|
}
|
|
//执行
|
boolean result = executeFlow(flow, listId);
|
|
//执行后续流程
|
if (Cools.isEmpty(flow.get("nextTrue")) && Cools.isEmpty(flow.get("nextFalse"))) {
|
break;//无后续流程
|
}
|
|
//更新id
|
currentId = result ? flow.getString("nextTrue") : flow.getString("nextFalse");
|
}
|
|
System.out.println("执行完成");
|
return true;
|
}
|
|
private boolean executeFlow(JSONObject flow, String listId) {
|
System.out.println(flow.getString("id") + "被执行");
|
String type = flow.getString("type");
|
if (type.equals("devp")) {
|
|
} else if (type.equals("shuttle")) {
|
|
}
|
return true;
|
}
|
|
private JSONObject findFLow(List<JSONObject> list, String id) {
|
for (JSONObject flow : list) {
|
if (flow.getString("id").equals(id)) {
|
return flow;
|
}
|
}
|
return null;
|
}
|
|
// private boolean executeFlow(List<Map<String, Object>> list) {
|
// for (Map<String, Object> map : list) {
|
// JSONObject data = (JSONObject) map.get("data");
|
// if (data.getString("type").equals("devp")) {
|
// JSONObject devp = data.getJSONObject("devpType");
|
// String devpNo = devp.getString("devpNo");//输送线PLC
|
// String staNo = devp.getString("staNo");//站号
|
// Boolean enableStaStatus = devp.getBoolean("enableStaStatus");//判断站点状态
|
// JSONArray staStatus = devp.getJSONArray("staStatus");//站点状态列表
|
// String staJudgementFailExecute = devp.getString("staJudgementFailExecute");//判断失败后是否继续执行流程
|
// Boolean writeWorkNoStatus = devp.getBoolean("writeWorkNoStatus");//是否写入工作号
|
// Boolean writeStaNoStatus = devp.getBoolean("writeStaNoStatus");//是否写入目标站
|
// String writeWorkNo = devp.getString("writeWorkNo");//写入工作号数据
|
// String writeStaNo = devp.getString("writeStaNo");//写入目标站数据
|
// if (enableStaStatus) {
|
// //判断站点状态
|
// boolean statusFlag = true;//默认判断通过
|
// for (Object status : staStatus) {
|
// System.out.println(status);
|
// }
|
//
|
// if (!statusFlag) {
|
// //判断不通过
|
// if (staJudgementFailExecute.equals("stop")) {
|
// //判断失败后不继续执行
|
// return false;
|
// }
|
// }
|
//
|
// }
|
//
|
// if (writeWorkNoStatus) {
|
// //写入工作号
|
// }
|
//
|
// if (writeStaNoStatus) {
|
// //写入目标站
|
// }
|
// System.out.println(devp);
|
// }
|
// System.out.println(data);
|
// }
|
//
|
// System.out.println(list);
|
// return false;
|
// }
|
|
}
|