package com.base.util; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import com.amarsoft.app.alarm.AlarmMessage; import com.amarsoft.app.alarm.CheckItem; import com.amarsoft.app.alarm.DefaultCheckItemRunner; import com.amarsoft.app.alarm.DefaultScenarioContextLoader; import com.amarsoft.app.alarm.ItemGroup; import com.amarsoft.app.alarm.ScenarioContext; import com.amarsoft.app.alarm.ScenarioContextLoader; import com.amarsoft.app.alarm.StringTool; import com.amarsoft.are.ARE; import com.amarsoft.are.jbo.JBOTransaction; import com.amarsoft.are.lang.StringX; import com.amarsoft.awe.util.ObjectConverts; import com.amarsoft.awe.util.Transaction; import com.tenwa.flow.warning.Warning; public class ScenarioUtil { List> list; String sMsg; public String getsMsg() { return sMsg; } public List> getList() { return list; } public boolean autoRiskScan(String sScenarioID, String sBizArgs, String sSubTypeNo, JBOTransaction tx, Transaction sqlca) throws Exception { boolean sReturn = true; if (StringX.isSpace(sScenarioID)) { sMsg = "sScenarioID不能为空!"; return false; } if (StringX.isSpace(sBizArgs)) { sMsg = "sBizArgs不能为空!"; return false; } Warning warning = new Warning(); warning.setScenarioid(sScenarioID); warning.setSubTypeNo(sSubTypeNo); String sRes = warning.selectByScenarioid(tx); String autoCommit = "false"; if ("failed".equals(sRes.toLowerCase())) { sMsg = "无需风险预警!"; return true; } else { if (sBizArgs.indexOf("isAutoCommit=true") >= 0) { autoCommit = "true"; } // 获得组件参数 System.out.println(sBizArgs); sBizArgs = sBizArgs.replace("&", ","); ARE.getLog().debug("传入业务参数:" + sBizArgs); // 加载器 ScenarioContextLoader loader = new DefaultScenarioContextLoader(); ((DefaultScenarioContextLoader) loader).init(sqlca, sScenarioID, sBizArgs, sSubTypeNo); ScenarioContext context = loader.getContext(); // 获取下文容器 context.setCheckItemRunner(new DefaultCheckItemRunner()); // 模型运行器 String scenarioSerializable = ObjectConverts.getString(context); // 序列化 List gList0 = context.getScenario().getGroupList(); List gList = new ArrayList(); // 根据运行条件进行预处理,分组下检查项检查条件均没通过,则不显示该分组 for (int i = 0; i < gList0.size(); i++) { ItemGroup group = gList0.get(i); List ckList0 = group.getCheckItemList(); List ckList1 = new ArrayList(); // 存放检查通过的 for (int j = 0; j < ckList0.size(); j++) { CheckItem ckItem = ckList0.get(j); String sCondition = ckItem.getRunCondition(); // 运行条件 if (sCondition != null && sCondition.length() > 0) { boolean bCondition = StringTool.runAmarScript(sqlca, sCondition, context.getParameter()) .booleanValue(); if (!bCondition) continue; else ckList1.add(ckItem); } else { ckList1.add(ckItem); } } if (ckList1.size() > 0) { // 重组分组 group.getCheckItemList().clear(); group.getCheckItemList().addAll(ckList1); gList.add(group); } } for (int i = 0; i < gList.size(); i++) { ItemGroup group = gList.get(i); List ckList = group.getCheckItemList(); String sGroupId = group.getGroupID(); String sGroupName = group.getGroupName(); list = new ArrayList>(); for (int j = 0; j < ckList.size(); j++) { CheckItem ckItem = ckList.get(j); // String sItemId = ckItem.getItemID(); String viewerScript = ckItem.getBizViewer(); if (viewerScript == null) viewerScript = ""; else viewerScript = StringTool.pretreat( context.getParameter(), viewerScript); if (ckItem.getItemID().equals("0028")) { autoCommit="fales"; continue; } else { String sItemName = ckItem.getItemName(); String sItemId = ckItem.getItemID(); try { Map map = alarmModelInvoker( sGroupId, sItemId, sqlca, tx, scenarioSerializable); map.put("sItemName", sItemName); map.put("sGroupName", sGroupName); list.add(map); if (map.get("sStatus") == null ? false : (boolean) map.get("sStatus") == false) { sReturn = false; } } catch (Exception e) { ARE.getLog().error(e); return false; } } } } } return sReturn; } @SuppressWarnings("deprecation") public Map alarmModelInvoker(String sGroupId, String sItemId, Transaction Sqlca, JBOTransaction tx, String serializableScenario) throws Exception { Map map = new HashMap(); try { if (serializableScenario == null) serializableScenario = ""; if (serializableScenario.length() == 0) throw new Exception("场景对象获取错误!"); try { ScenarioContext context = (ScenarioContext) ObjectConverts .getObject(serializableScenario); CheckItem chItem = context.getScenario().getCheckItem(sGroupId, sItemId); String sPassMessage = chItem.getPassMessage(); String sNoPassMessage = chItem.getNoPassMessage(); if (sPassMessage == null) sPassMessage = ""; if (sNoPassMessage == null) sNoPassMessage = ""; // AlarmMessage am = (AlarmMessage) context.getCheckItemRunner() // .run(Sqlca, chItem); AlarmMessage am = (AlarmMessage) context.getCheckItemRunner() .run(Sqlca, chItem); StringBuffer sbMessage = new StringBuffer(); String sMessage = ""; for (int j = 0; j < am.size(); j++) { sbMessage.append(am.getMessage(j) + "[~`~]"); } if (sbMessage.length() > 5) { sMessage = sbMessage.substring(0, sbMessage.length() - 5); } else { sMessage = ""; } // 如果执行后,返回的消息为空 // 1.如果通过,则消息取配置的通过的提示消息 // 2.如果未通过,则取配置的未通过的提示消息 if (sMessage.equals("")) { if (am.isPass()) { sMessage = sPassMessage; } else { sMessage = sNoPassMessage; } } // Thread.sleep(200); // 生成JSON boolean sStatus = am.isPass(); String sNoPassDeal = am.getNoPassDeal(); String sMsg = sMessage; map.put("sStatus", sStatus); map.put("sNoPassDeal", sNoPassDeal); map.put("sMsg", sMsg); ARE.getLog().debug( "status:" + am.isPass() + "|message:" + sMessage); } catch (Exception e) { ARE.getLog().error(e); throw e; } } catch (Exception e) { if (Sqlca != null) Sqlca.getConnection().rollback(); e.printStackTrace(); ARE.getLog().error(e.getMessage(), e); throw e; } finally { if (Sqlca != null) { Sqlca.getConnection().commit(); Sqlca.disConnect(); Sqlca = null; } } return map; } }