findOriginService(String sql, int start, int pageSize);
+
+ public OriginServiceBean getOriginService(String beanName, String method);
+
+ public OriginServiceBean loadOriginServiceBean(String id);
+
+ public void saveRegister();
+
+}
diff --git a/platform-legacy-core/src/main/java/com/dsasp/server/common/function/GetDefaultValueFunction.java b/platform-legacy-core/src/main/java/com/dsasp/server/common/function/GetDefaultValueFunction.java
deleted file mode 100644
index b829927..0000000
--- a/platform-legacy-core/src/main/java/com/dsasp/server/common/function/GetDefaultValueFunction.java
+++ /dev/null
@@ -1,8 +0,0 @@
-package com.dsasp.server.common.function;
-
-/**
- * eip4-poc 移植桩:原版为 Groovy 脚本函数库(currentYear/currentMonth 等默认值函数),
- * 仅被 FunctionUtil 以 class 引用注册。WS3 脚本验证时回迁完整实现。
- */
-public class GetDefaultValueFunction {
-}
diff --git a/platform-legacy-core/src/main/java/com/dsasp/server/common/function/GetServicesFunction.java b/platform-legacy-core/src/main/java/com/dsasp/server/common/function/GetServicesFunction.java
index 5850e36..22b0bf1 100644
--- a/platform-legacy-core/src/main/java/com/dsasp/server/common/function/GetServicesFunction.java
+++ b/platform-legacy-core/src/main/java/com/dsasp/server/common/function/GetServicesFunction.java
@@ -1,12 +1,28 @@
package com.dsasp.server.common.function;
+import java.util.Map;
+import java.util.Properties;
+
import com.dsasp.server.common.core.service.SpringBeanOsgiServices;
+import com.dsasp.server.common.dataDic.bean.GeneralPOJO;
import com.dsasp.server.common.dataDic.service.DataDicService;
+import com.dsasp.server.common.dataDic.service.POJOCRUDService;
+import com.dsasp.server.common.util.UserSession;
/**
- * eip4-poc 移植桩:原版为 780 行 Groovy 脚本函数库(@Function 注解暴露给模板脚本)。
- * PoC 阶段只实现被 Java 代码直接调用的 findCount(POInfo.java:860);
- * 完整 Groovy 函数库在 WS3 脚本验证时以 groovy-jsr223 联合编译方式回迁。
+ * 服务调用函数库(保包名/类名/签名替换类)。
+ *
+ * framework 原版 {@code GetServicesFunction.groovy}(136 行 @Function 库)依赖
+ * OrganizationService / UserFindService / WorkCalendarService / ProcessCoreService /
+ * ChangeStatus / Enumerate 等横切服务——这些服务属 P2/P3 迁移面,P1 阶段尚未移植。
+ * 按双层制「确需替换的类按 PoC 保包名/类名/签名纪律」(迁移手册 §3.1),本类保持
+ * framework 同名同签名,仅实现 P1 服务流引擎执行路径实际调用的方法子集
+ * ({@code findCount} / {@code loadPOJO} / {@code listSelect}),委托目标 bean 与
+ * framework Groovy 逐字一致,旧引擎代码(com.dsasp.*)对本类的引用零修改。
+ *
+ *
引擎调用点:POInfo.java:860(findCount)、FlowExcuteServiceImpl.checkControl
+ * 与 ControlBean(loadPOJO / listSelect)。未实现的取数/枚举/组织/工作流方法随 P2/P3
+ * 对应横切服务移植时按 framework 原版补全(见 P1 服务流实测报告「替换类登记」)。
*/
public class GetServicesFunction {
@@ -15,4 +31,15 @@ public class GetServicesFunction {
(DataDicService) SpringBeanOsgiServices.getInstance().getBeanByName("dataDicService");
return dataDicService.findCount(countSql);
}
+
+ public static GeneralPOJO loadPOJO(String entityId, String tableName, Boolean isHierarchical) {
+ return ((POJOCRUDService) SpringBeanOsgiServices.getInstance().getBeanByName("pojoCRUDService"))
+ .loadPOJO(entityId, tableName, UserSession.get(), isHierarchical);
+ }
+
+ @SuppressWarnings({"rawtypes", "unchecked"})
+ public static Map listSelect(Map map, final String tableName, Properties ctx) {
+ return ((POJOCRUDService) SpringBeanOsgiServices.getInstance().getBeanByName("pojoCRUDService"))
+ .listSelect(map, tableName, ctx);
+ }
}
diff --git a/platform-legacy-core/src/main/java/com/dsasp/server/common/function/GetValueFunction.java b/platform-legacy-core/src/main/java/com/dsasp/server/common/function/GetValueFunction.java
deleted file mode 100644
index 8c1ceab..0000000
--- a/platform-legacy-core/src/main/java/com/dsasp/server/common/function/GetValueFunction.java
+++ /dev/null
@@ -1,8 +0,0 @@
-package com.dsasp.server.common.function;
-
-/**
- * eip4-poc 移植桩:原版为 Groovy 脚本函数库,仅被 FunctionUtil 以 class 引用注册。
- * WS3 脚本验证时回迁完整实现。
- */
-public class GetValueFunction {
-}
diff --git a/platform-legacy-core/src/main/java/com/dsasp/server/common/privilege/service/FlowPrivilegeService.java b/platform-legacy-core/src/main/java/com/dsasp/server/common/privilege/service/FlowPrivilegeService.java
new file mode 100644
index 0000000..a445417
--- /dev/null
+++ b/platform-legacy-core/src/main/java/com/dsasp/server/common/privilege/service/FlowPrivilegeService.java
@@ -0,0 +1,21 @@
+package com.dsasp.server.common.privilege.service;
+
+import java.util.List;
+
+public interface FlowPrivilegeService {
+
+ /**
+ * get the action special permission of some fields,
+ * @param userID
+ * @param action
+ * @return
+ */
+ public List getServicePrivileges(String roleId);
+
+
+ public boolean authority(List roles, String serviceId);
+
+
+ public Object getMenus(String userID);
+
+}
diff --git a/platform-legacy-core/src/main/java/com/dsasp/server/common/util/AopTargetUtils.java b/platform-legacy-core/src/main/java/com/dsasp/server/common/util/AopTargetUtils.java
new file mode 100644
index 0000000..3e0a696
--- /dev/null
+++ b/platform-legacy-core/src/main/java/com/dsasp/server/common/util/AopTargetUtils.java
@@ -0,0 +1,62 @@
+package com.dsasp.server.common.util;
+
+import java.lang.reflect.Field;
+
+import org.springframework.aop.framework.AdvisedSupport;
+import org.springframework.aop.framework.AopProxy;
+import org.springframework.aop.support.AopUtils;
+
+public class AopTargetUtils {
+
+
+ /**
+ * 获取 目标对象
+ * @param proxy 代理对象
+ * @return
+ * @throws Exception
+ */
+ public static Object getTarget(Object proxy) throws Exception {
+
+ if(!AopUtils.isAopProxy(proxy)) {
+ return proxy;//不是代理对象
+ }
+
+ if(AopUtils.isJdkDynamicProxy(proxy)) {
+ return getJdkDynamicProxyTargetObject(proxy);
+ } else { //cglib
+ return getCglibProxyTargetObject(proxy);
+ }
+
+
+
+ }
+
+
+ private static Object getCglibProxyTargetObject(Object proxy) throws Exception {
+ Field h = proxy.getClass().getDeclaredField("CGLIB$CALLBACK_0");
+ h.setAccessible(true);
+ Object dynamicAdvisedInterceptor = h.get(proxy);
+
+ Field advised = dynamicAdvisedInterceptor.getClass().getDeclaredField("advised");
+ advised.setAccessible(true);
+
+ Object target = ((AdvisedSupport)advised.get(dynamicAdvisedInterceptor)).getTargetSource().getTarget();
+
+ return target;
+ }
+
+
+ private static Object getJdkDynamicProxyTargetObject(Object proxy) throws Exception {
+ Field h = proxy.getClass().getSuperclass().getDeclaredField("h");
+ h.setAccessible(true);
+ AopProxy aopProxy = (AopProxy) h.get(proxy);
+
+ Field advised = aopProxy.getClass().getDeclaredField("advised");
+ advised.setAccessible(true);
+
+ Object target = ((AdvisedSupport)advised.get(aopProxy)).getTargetSource().getTarget();
+
+ return target;
+ }
+
+}
diff --git a/platform-legacy-core/src/main/java/com/dsasp/server/common/util/ExceptionUtil.java b/platform-legacy-core/src/main/java/com/dsasp/server/common/util/ExceptionUtil.java
new file mode 100644
index 0000000..3a40d68
--- /dev/null
+++ b/platform-legacy-core/src/main/java/com/dsasp/server/common/util/ExceptionUtil.java
@@ -0,0 +1,19 @@
+package com.dsasp.server.common.util;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+public class ExceptionUtil {
+ public static String convertExceptionToString(Exception e){
+ StringWriter sw = new StringWriter();
+ PrintWriter pw;
+ try {
+ pw = new PrintWriter(sw);
+ e.printStackTrace(pw);
+ return sw.toString();
+ } catch (Exception e1) {
+ e1.printStackTrace();
+ }
+ return "";
+ }
+}
diff --git a/platform-legacy-core/src/main/java/com/dsasp/server/core/origin/service/OriginServiceManagerImpl.java b/platform-legacy-core/src/main/java/com/dsasp/server/core/origin/service/OriginServiceManagerImpl.java
new file mode 100644
index 0000000..bda8f26
--- /dev/null
+++ b/platform-legacy-core/src/main/java/com/dsasp/server/core/origin/service/OriginServiceManagerImpl.java
@@ -0,0 +1,320 @@
+package com.dsasp.server.core.origin.service;
+
+import java.io.Writer;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Vector;
+
+import org.codehaus.groovy.runtime.StringBufferWriter;
+import org.dom4j.Document;
+import org.dom4j.DocumentHelper;
+import org.dom4j.Element;
+import org.dom4j.io.OutputFormat;
+import org.dom4j.io.XMLWriter;
+import org.springframework.stereotype.Service;
+
+import com.dsasp.server.common.core.OriginServiceBean;
+import com.dsasp.server.common.core.service.FlowService;
+import com.dsasp.server.common.core.service.OriginServiceManager;
+import com.dsasp.server.common.core.service.OriginServiceMethod;
+import com.dsasp.server.common.core.service.SpringBeanOsgiServices;
+import com.dsasp.server.common.dataDic.bean.AbstractPOJOInfo;
+import com.dsasp.server.common.dataDic.bean.CustomSearchConditional;
+import com.dsasp.server.common.dataDic.bean.GeneralPOJO;
+import com.dsasp.server.common.dataDic.bean.POJOInfo;
+import com.dsasp.server.common.dataDic.service.POJOCRUDService;
+import com.dsasp.server.common.dataDic.service.POJOService;
+import com.dsasp.server.common.privilege.bean.MethodSecurityInterceptor;
+import com.dsasp.server.common.user.service.LoggedInUser;
+import com.dsasp.server.common.util.UserSession;
+import com.dsasp.server.core.service.flow.model.Flow;
+
+@Service(value="originServiceManager")
+public class OriginServiceManagerImpl implements OriginServiceManager {
+
+private static Vector vector = new Vector();
+
+ private static Vector flowVector = new Vector();
+
+ public OriginServiceManagerImpl(){
+ //saveRegister();
+ }
+
+ @Override
+ public boolean register(Class beanClass) {
+
+ Service d = (Service) beanClass.getAnnotation(Service.class);
+ if (d != null) {
+ String serviceName = d.value();
+ Method[] methods = beanClass.getMethods();
+ String beanClassName = beanClass.getName();
+ String beanName = d.value();
+ for (Method method : methods) {
+ OriginServiceMethod m = (OriginServiceMethod) method.getAnnotation(OriginServiceMethod.class);
+ if (m != null) {
+ OriginServiceBean bean = new OriginServiceBean();
+ bean.setBeanName(serviceName);
+ bean.setMethod(method.getName());
+ bean.setReturnResult(method.getReturnType().getName());
+ Class[] paras = method.getParameterTypes();
+ if(paras != null && paras.length > 0){
+ List list = new ArrayList(paras.length);
+ for(Class c : paras){
+ list.add(c.getName());
+ }
+ bean.setArg(list);
+ }
+ bean.setDescription(m.description());
+ bean.setDisplayName(m.name());
+ bean.setType(m.type());
+ vector.add(bean);
+ }
+ MethodSecurityInterceptor mSecurityInterceptor = (MethodSecurityInterceptor) method
+ .getAnnotation(MethodSecurityInterceptor.class);
+ if (mSecurityInterceptor != null) {
+ Class[] paras = method.getParameterTypes();
+ // 创建流程xml
+ Document doc = DocumentHelper.createDocument();
+ Element root = doc.addElement("flow");
+ root.addAttribute("id", method.getName());
+ Element input = root.addElement("input");
+ if (paras != null && paras.length > 0) {
+ List listParas = new ArrayList(
+ paras.length);
+ for (Class c : paras) {
+ listParas.add(c.getName());
+ }
+ for (String arg : listParas) {
+ Element fieldElement = input.addElement("field");
+ fieldElement.addAttribute("name", arg);
+ fieldElement.addAttribute("type", arg);
+ }
+ }
+ Element startElement = root.addElement("start");
+ startElement.addAttribute("id", "start");
+ startElement.addAttribute("name", "开始");
+
+ Element service = startElement.addElement("service");
+ service.addAttribute("beanName", beanName);
+ service.addAttribute("method", method.getName());
+ Element list = service.addElement("list");
+
+ if (paras != null && paras.length > 0) {
+ List listParas = new ArrayList(
+ paras.length);
+ for (Class c : paras) {
+ listParas.add(c.getName());
+ }
+ for (String arg : listParas) {
+ Element argEle = list.addElement("arg");
+ argEle.addAttribute("name", arg);
+ }
+ }
+
+ if (method.getReturnType() != null) {
+ Element resultEle = service.addElement("result");
+ resultEle.addAttribute("name", method.getReturnType()
+ .getName());
+ }
+
+ Element ele = root.addElement("transition");
+ ele.addAttribute("from", "start");
+ ele.addAttribute("to", "End");
+
+ Element endElement = root.addElement("end");
+ endElement.addAttribute("id", "End");
+ endElement.addAttribute("name", "结束");
+ Element output = root.addElement("output");
+
+ if (method.getReturnType() != null) {
+ Element fieldElement = output.addElement("field");
+ fieldElement.addAttribute("name", method
+ .getReturnType().getName());
+ fieldElement.addAttribute("type", method
+ .getReturnType().getName());
+ }
+
+ OutputFormat format = OutputFormat.createPrettyPrint();
+ StringBuffer buffer = new StringBuffer();
+ Writer out = new StringBufferWriter(buffer);
+ XMLWriter writer = new XMLWriter(out, format);
+ String contentxml = "";
+ try {
+ writer.write(doc);
+ contentxml = buffer.toString();
+ } catch (Exception ex) {
+ // throw new RuntimeException("格式有误");
+ }
+
+ Flow flow = new Flow(beanClassName + "." + method.getName(),contentxml);
+ flow.setDisplayName(mSecurityInterceptor.name());
+ flow.setEntityId(mSecurityInterceptor.tableName());
+ flow.setControl(mSecurityInterceptor.isControl());
+ flow.setUpdateable(false);
+ flowVector.add(flow);
+ }
+ }
+ }
+ return true;
+ }
+
+// private void saveRegister(){
+// Timer timer = new Timer("registerService", true);
+// timer.schedule(new TimerTask() {
+//
+// @Override
+// public void run() {
+// while(vector.size() > 0){
+// OriginServiceBean bean = vector.remove(0);
+// saveOrUpdate(bean);
+// }
+// while(flowVector.size() > 0){
+// Flow bean = flowVector.remove(0);
+// saveOrUpdateFlow(bean);
+// }
+// }
+// }, 60000, 10 * 60 * 1000);
+// }
+
+ public void saveRegister(){
+ while(vector.size() > 0){
+ OriginServiceBean bean = vector.remove(0);
+ saveOrUpdate(bean);
+ }
+ while(flowVector.size() > 0){
+ Flow bean = flowVector.remove(0);
+ saveOrUpdateFlow(bean);
+ }
+ }
+
+ public void saveOrUpdateFlow(Flow flow){
+ POJOInfo po = AbstractPOJOInfo.getPOInfo(flow.getEntityId());
+ if (po != null) {
+ flow.setEntityId(po.getAD_Table_ID());
+ }
+ FlowService flowService = (FlowService) SpringBeanOsgiServices
+ .getInstance().getBeanByName("flowService");
+ flowService.saveOrUpdate(flow, UserSession.getAdmin());
+ }
+
+ public void saveOrUpdate(OriginServiceBean bean) {
+
+ POJOService pojoService = (POJOService) SpringBeanOsgiServices
+ .getInstance().getBeanByName("pojoService");
+
+ POJOCRUDService poCurdService = (POJOCRUDService) SpringBeanOsgiServices
+ .getInstance().getBeanByName("pojoCRUDService");
+ Map map = new HashMap();
+ map.put("CLASSNAME", bean.getBeanName());
+ map.put("METHODNAME", bean.getMethod());
+ List poList = (List)poCurdService.listSelect(map, "SYS_ORIGINSERVICE", UserSession.getAdmin()).get(POJOCRUDService.LIST_RESULT);
+ if(poList != null && poList.size() == 1){
+ GeneralPOJO po = poList.get(0);
+ po = pojoService.loadPOJO(po.get_ID(), "SYS_ORIGINSERVICE", UserSession.getAdmin(), true);
+ bean.updateToPO(po);
+ pojoService.update(po, LoggedInUser.ADMIN);
+ }else if(poList == null || poList.size() == 0 ){
+
+ poCurdService.save(bean.convertToMap(), "SYS_ORIGINSERVICE", UserSession.getAdmin());
+ }else{
+ //log error message
+ for (GeneralPOJO pojo : poList) {
+ pojoService.delete(pojo, "", true);
+ }
+ saveOrUpdate(bean);
+ }
+ }
+
+ @Override
+ public boolean unregister(Class beanClass) {
+
+ Service d = (Service) beanClass.getAnnotation(Service.class);
+ if (d != null) {
+ Method[] methods = beanClass.getMethods();
+ String beanClassName = beanClass.getName();
+ for (Method method : methods) {
+ OriginServiceMethod m = (OriginServiceMethod) method.getAnnotation(OriginServiceMethod.class);
+ if (method.getAnnotation(OriginServiceMethod.class) != null) {
+ OriginServiceBean bean = new OriginServiceBean();
+ bean.setBeanName(beanClassName);
+ bean.setMethod(method.getName());
+ bean.setReturnResult(method.getReturnType().getName());
+ Class[] paras = method.getParameterTypes();
+ if(paras != null && paras.length > 0){
+ List list = new ArrayList(paras.length);
+ for(Class c : paras){
+ list.add(c.getName());
+ }
+ bean.setArg(list);
+ }
+ bean.setDescription(m.description());
+ bean.setDisplayName(m.name());
+ bean.setType(m.type());
+ delete(bean);
+ }
+ }
+ }
+ return true;
+
+ }
+
+ public void delete(OriginServiceBean bean) {
+
+ POJOService pojoService = (POJOService) SpringBeanOsgiServices
+ .getInstance().getBeanByName("pojoService");
+ String select = "SELECT SYS_ORIGINSERVICE_ID FROM SYS_ORIGINSERVICE WHERE CLASSNAME='"
+ + bean.getBeanName()
+ + "' AND METHODNAME='"
+ + bean.getMethod()
+ + "'";
+ List cols = new ArrayList();
+ cols.add("SYS_ORIGINSERVICE_ID");
+ List poList = pojoService.listSelectSpecialCols(select,
+ "SYS_ORIGINSERVICE", 0, Integer.MAX_VALUE, cols);
+ if (poList != null && poList.size() > 0) {
+ for (GeneralPOJO pojo : poList) {
+ pojoService.delete(pojo, "", true);
+ }
+ }
+ }
+
+ @Override
+ public List findOriginService(String sql, int start,
+ int pageSize) {
+
+ return null;
+ }
+
+ @Override
+ public OriginServiceBean getOriginService(String beanName, String method) {
+
+ POJOCRUDService poCurdService = (POJOCRUDService) SpringBeanOsgiServices
+ .getInstance().getBeanByName("pojoCRUDService");
+ Map map = new HashMap();
+ CustomSearchConditional beanNameCon = new CustomSearchConditional("CLASSNAME = '" + beanName + "'");
+ CustomSearchConditional methodCon = new CustomSearchConditional("METHODNAME = '" + method + "'");
+ map.put("CLASSNAME", beanNameCon);
+ map.put("METHODNAME", methodCon);
+
+
+ List poList = (List)poCurdService.listSelect(map, "SYS_ORIGINSERVICE", UserSession.getAdmin()).get(POJOCRUDService.LIST_RESULT);
+ if(poList != null && poList.size() == 1){
+ GeneralPOJO po = poList.get(0);
+ po = poCurdService.loadPOJO(po.get_ID(), po.get_TableName(), null, true);
+ return new OriginServiceBean(po);
+ }
+ return null;
+ }
+
+ @Override
+ public OriginServiceBean loadOriginServiceBean(String id) {
+ POJOService pojoService = (POJOService) SpringBeanOsgiServices
+ .getInstance().getBeanByName("pojoService");
+ GeneralPOJO po = pojoService.loadPOJO(id, "SYS_ORIGINSERVICE", UserSession.getAdmin(), true);
+ return new OriginServiceBean(po);
+ }
+
+}
diff --git a/platform-legacy-core/src/main/java/com/dsasp/server/core/service/FlowExcuteServiceImpl.java b/platform-legacy-core/src/main/java/com/dsasp/server/core/service/FlowExcuteServiceImpl.java
new file mode 100644
index 0000000..1b874d3
--- /dev/null
+++ b/platform-legacy-core/src/main/java/com/dsasp/server/core/service/FlowExcuteServiceImpl.java
@@ -0,0 +1,534 @@
+package com.dsasp.server.core.service;
+
+import java.lang.reflect.Method;
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import org.joda.time.DateTime;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import com.dsasp.server.common.core.ControlBean;
+import com.dsasp.server.common.core.FlowDefinition;
+import com.dsasp.server.common.core.service.FlowExcuteService;
+import com.dsasp.server.common.core.service.FlowService;
+import com.dsasp.server.common.core.service.OriginServiceMethod;
+import com.dsasp.server.common.core.service.SpringBeanOsgiServices;
+import com.dsasp.server.common.dataDic.bean.CustomSearchConditional;
+import com.dsasp.server.common.dataDic.bean.GeneralPOJO;
+import com.dsasp.server.common.dataDic.service.POJOCRUDService;
+import com.dsasp.server.common.exception.PrivilegeException;
+import com.dsasp.server.common.exception.SameCodeException;
+import com.dsasp.server.common.exception.ValidationException;
+import com.dsasp.server.common.function.GetDefaultValueFunction;
+import com.dsasp.server.common.function.GetServicesFunction;
+import com.dsasp.server.common.log.service.SystemLogManager;
+import com.dsasp.server.common.log.service.SystemLogManager.LogType;
+import com.dsasp.server.common.privilege.service.FlowPrivilegeService;
+import com.dsasp.server.common.user.service.LoggedInUser;
+import com.dsasp.server.common.util.AopTargetUtils;
+import com.dsasp.server.common.util.ExceptionUtil;
+import com.dsasp.server.common.util.StringUtil;
+import com.dsasp.server.common.util.UserSession;
+import com.dsasp.server.core.service.flow.model.Field;
+import com.dsasp.server.core.service.flow.model.Flow;
+import com.dsasp.server.core.service.flow.model.Node;
+import com.dsasp.server.core.service.flow.model.Procedure;
+import com.dsasp.server.core.service.flow.model.Script;
+import com.dsasp.server.core.service.flow.model.ServiceBean;
+import com.dsasp.server.core.service.flow.model.Start;
+import com.dsasp.server.core.service.flow.model.Transition;
+import com.dsasp.server.core.service.script.ScriptingEnginesManager;
+
+@Service(value = "flowExcuteService")
+@Transactional
+public class FlowExcuteServiceImpl implements FlowExcuteService {
+
+ private static String defaultImport =
+// " import com.dsasp.server.common.dataDic.bean.GeneralPOJO; \n"
+// + " import com.dsasp.server.common.util.StringUtil; \n"
+// + " import com.dsasp.server.dataDic.util.FunctionUtil; \n"
+// + " import com.dsasp.server.common.function.GetServicesFunction; \n"
+// + " import com.dsasp.server.common.function.GetDefaultValueFunction; \n"
+// + " import com.dsasp.server.common.function.GetValueFunction; \n"
+ " import com.dsasp.server.common.message.bean.*; \n";
+
+
+ @Autowired
+ private FlowService flowService;
+
+ //protected static CCache is_cache = new CCache("ServiceControls", 200);
+
+ //private SystemLogManager systemLogManager = (SystemLogManager)SpringBeanOsgiServices.getInstance().getBeanByName("systemLogManager");
+
+ protected SystemLogManager getSystemLogManager(){
+ return (SystemLogManager)SpringBeanOsgiServices.getInstance().getBeanByName("systemLogManager");
+ }
+
+ /**
+ * the implement return the object is hashmap, but other implement is not fixed
+ */
+ @OriginServiceMethod(name="服务流执行", type="core", description="执行服务流入口,参数1 map 数据载体,参数 2 ctx 环境载体,参数 3 flowId 服务流key")
+ @Override
+ public Object excute(Map map, Properties ctx, String flowId) {
+ if(flowId != null){
+ FlowDefinition definition = flowService.getFlowDefinition(flowId);
+ if(definition == null){
+ throw new ValidationException("服务:"+flowId+"不存在!");
+ }
+ Flow flow = ((Flow)definition).initial();
+ flow.createFlowScriptBindings(map, ctx);
+ //控制
+ List conFlows = checkControl(flowId, flow, map);
+
+ if(conFlows != null && conFlows.size() > 0){
+ for (String contFlowId : conFlows) {
+ excute(map, ctx, contFlowId);
+ }
+ }
+
+ if(validateInput(flow.getInputs(), flow)){
+ Start start = flow.getStart();
+ excuteNode(start, map, flow, ctx);
+ return returnOutputs(map, flow.getOutputs());
+ }
+ }
+ return null;
+ }
+
+ //检查是否有服务控制
+ protected List checkControl(String flowId,Flow flow,Map map){
+
+ Map tMap;
+ Map listSelect = new HashMap();
+ List results = new ArrayList();
+ List resultList = ControlBean.getControl(flowId, 2);
+
+ if(resultList != null && resultList.size() > 0){
+
+ List flows = new ArrayList();
+
+ for (GeneralPOJO result : resultList) {
+ if(result != null){
+ //有控制
+ String controlId = (String) result.get_Value("CONTROLID");
+ String contFlowId = (String) result.get_Value("CONTROLSERVICEID");
+
+ result = GetServicesFunction.loadPOJO(controlId, "SYS_TEMPLATECONTROL", false);
+ Integer type = (Integer) result.get_Value("TEMPLATETYPE");
+ Integer isEnable = (Integer) result.get_Value("ISENABLE");
+
+ //
+ tMap = new HashMap();
+ tMap.put("CONTROLID", new CustomSearchConditional(" CONTROLID = '" + controlId + "'"));
+ listSelect = GetServicesFunction.listSelect(tMap, "SYS_TEMPLATECONTROL_USER", UserSession.getAdmin());
+ List users = new ArrayList();
+ if(listSelect != null){
+ users = (List) listSelect.get("listresult");
+ }
+ Boolean flag = true;
+ String userId = GetDefaultValueFunction.getCurrentUserId();
+ if(users != null && users.size() >0){
+ for (GeneralPOJO user : users) {
+ if(userId.equals(user.get_Value("USERID"))){
+ DateTime date3 = (DateTime) user.get_Value("EXPIRY");
+ if(date3 == null || date3.isAfter(GetDefaultValueFunction.currentDate())){
+ flag = false;
+ }
+ }
+ }
+ }
+ //没有不设控用户,或者当前用户不属于不设控用户
+ if(flag){
+ //无解控日期或者已经超过解控日期
+ if(isEnable == 1){
+
+ Boolean flag2 = true;
+ //如果是功能类型为工程
+ if(type == 1){
+ String columnName = "";
+ String tableName = "";
+ String keyId = "";
+ Field[] inputs = flow.getInputs();
+ if(inputs != null && inputs.length > 0){
+ for (Field input : inputs) {
+ if("tableName".equals(input.getName())){
+ tableName = input.getInitValue();
+ keyId = tableName + "_ID";
+ if(!StringUtil.isEmpty(tableName)){
+ tMap = new HashMap();
+ tMap.put("TABLENAME", new CustomSearchConditional(" TABLENAME = '" + tableName + "'"));
+ listSelect = GetServicesFunction.listSelect(tMap, "SYS_ENTITY", UserSession.getAdmin());
+ List entitys = new ArrayList();
+ if(listSelect != null){
+ entitys = (List) listSelect.get("listresult");
+ }
+ if(entitys != null && entitys.size() > 0){
+ String entityId = entitys.get(0).get_ID();
+ tMap = new HashMap();
+ tMap.put("SYS_ENTITYATTRIBUTE_ID", new CustomSearchConditional(" ENTITYID = '" + entityId + "' and REFERENCEID = 'ab81c24e-3fd0-4beb-afe3-ed86d378cdc5'"));
+ listSelect = GetServicesFunction.listSelect(tMap, "SYS_ENTITYATTRIBUTE", UserSession.getAdmin());
+ List attrs = new ArrayList();
+ if(listSelect != null){
+ attrs = (List) listSelect.get("listresult");
+ }
+ if(attrs != null && attrs.size() >0){
+ columnName = (String) attrs.get(0).get_Value("COLUMNNAME");
+ }
+ }
+ }
+ break;
+ }
+ }
+ }
+
+ if(!StringUtil.isEmpty(tableName) && !StringUtil.isEmpty(keyId) && !StringUtil.isEmpty(columnName) && map != null){
+ String projectId = "";
+ if(StringUtil.empty(map.get(columnName))){
+ keyId = (String) map.get(keyId);
+ if(!StringUtil.isEmpty(keyId)){
+ GeneralPOJO pojo = GetServicesFunction.loadPOJO(keyId, tableName, false);
+ projectId = (String) pojo.get_Value(columnName);
+ }
+ } else {
+ projectId = (String) map.get(columnName);
+ }
+ tMap = new HashMap();
+ tMap.put("SYS_TEMPLATEDECONTROL_ID", new CustomSearchConditional(" CONTROLID = '" + controlId + "' and PROJECTID = '" + projectId + "'"));
+ listSelect = GetServicesFunction.listSelect(tMap, "SYS_TEMPLATEDECONTROL", UserSession.getAdmin());
+ List deControls = new ArrayList();
+ if(listSelect != null){
+ deControls = (List) listSelect.get("listresult");
+ }
+ if(deControls != null && deControls.size() > 0){
+ DateTime date2 = (DateTime) deControls.get(0).get_Value("EXPIRY");
+ if(date2 == null || date2.isAfter(GetDefaultValueFunction.currentDate())){
+ flag2 = false;
+ }
+ }
+ }
+ }
+
+ if(flag2){
+ flows.add(contFlowId);
+ }
+ }
+ }
+ }
+ }
+
+ return flows;
+ }
+
+
+ return null;
+ }
+
+ private void authority(Properties ctx, FlowDefinition definition){
+ if(definition != null && !definition.isControl()){
+ return;
+ }
+ FlowPrivilegeService flowPrivilegeService = (FlowPrivilegeService)SpringBeanOsgiServices.getInstance().getBeanByName("flowPrivilegeService");
+ flowPrivilegeService.authority((List)ctx.get(LoggedInUser.ROLES), definition.getKey());
+ }
+
+
+
+ public FlowService getFlowService() {
+ return flowService;
+ }
+
+ public void setFlowService(FlowService flowService) {
+ this.flowService = flowService;
+ }
+
+ //FIXME: validate the inputs
+ private boolean validateInput(Object[] input, Flow flow) {
+ Field[] fields = flow.getInputs();
+ for (Field field : fields) {
+ Object obj = null;
+ if (!StringUtil.isEmpty(field.getInitValue())) {
+ obj = convertToObject(field.getType(), field.getInitValue());
+ } else if (!StringUtil.isEmpty(field.getInitExpression())) {
+ obj = parseExpressionFromContext(flow,
+ field.getInitExpression());
+ }
+ if (obj != null && !flow.getBindings().containsKey(field.getName())) {
+ flow.getBindings().put(field.getName(), obj);
+ }
+ }
+ return true;
+ }
+
+ /**
+ * excute node
+ * @param node
+ * @param map
+ * @param flow
+ * @param ctx
+ */
+ private void excuteNode(Node node, Map map, Flow flow, Properties ctx) {
+ if (Node.SCRIPT_TYPE.equals(node.getType())) {
+ Script script = node.getScript();
+ try {
+ if (!StringUtil.isEmpty(script.getScrip())) {
+ ScriptingEnginesManager.getScriptingEnginesManager()
+ .evaluateGroovy(script.getKey() + flow.getKey(), defaultImport + script.getScrip(),
+ flow.getBindings());
+ if(!StringUtil.isEmpty(script.getExecuteExpression())){
+ String executScript = (String)flow.getBindings().get(script.getExecuteExpression());
+ ScriptingEnginesManager.getScriptingEnginesManager()
+ .evaluateGroovy("", defaultImport + executScript,
+ flow.getBindings());
+ }
+ }
+ } catch (RuntimeException e) {
+ String logContent = "服务流中的脚本执行出错,出错的服务流名称:"+flow.getDisplayName()+",节点名称:"+node.getName()+",节点ID:"+node.getId()+"\n";
+ logContent+="出错的脚本ID:"+script.getKey()+"\n";
+ logContent+="环境变量:"+map != null ?map.toString():"无"+"\n";
+ logContent+=ExceptionUtil.convertExceptionToString(e);
+ getSystemLogManager().log(LogType.ERRORS, logContent);
+ throw e;
+ }
+ } else if (Node.SERVICE_TYPE.equals(node.getType())) {
+ ServiceBean bean = node.getBean();
+ if (bean != null) {
+ Object proxy = SpringBeanOsgiServices.getInstance()
+ .getBeanByName(bean.getBeanName());
+ if (proxy == null) {
+ throw new RuntimeException("no service");
+ }
+ try {
+ Object obj = AopTargetUtils.getTarget(proxy);
+ List args = bean.getArgs();
+
+ List