Browse Source

通过视图获取数据 --分了两个版本 8.*和9.0

liuling 2 weeks ago
parent
commit
3ae9e7259d

+ 174 - 0
OSFViewConfig/code/v1/8.0/com/kingdee/eas/custom/utils/ViewGetDataService.java

@@ -0,0 +1,174 @@
+package com.kingdee.eas.custom.utils;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.kingdee.bos.BOSException;
+import com.kingdee.bos.Context;
+import com.kingdee.bos.bsf.service.app.IHRMsfService;
+import com.kingdee.bos.dao.query.IQueryExecutor;
+import com.kingdee.bos.dao.query.QueryExecutorFactory;
+import com.kingdee.bos.framework.cache.service.CacheService;
+import com.kingdee.bos.metadata.MetaDataPK;
+import com.kingdee.bos.metadata.entity.*;
+import com.kingdee.bos.sql.ParserException;
+import com.kingdee.eas.common.EASBizException;
+import com.kingdee.eas.framework.CoreBaseCollection;
+import com.kingdee.eas.framework.CoreBaseInfo;
+import com.kingdee.eas.framework.ICoreBase;
+import com.kingdee.shr.base.syssetting.DomainFilterFacadeFactory;
+import com.kingdee.shr.base.syssetting.IDomainFilterFacade;
+import com.kingdee.shr.base.syssetting.MSFServiceFacadeFactory;
+import com.kingdee.shr.base.syssetting.UIViewFactory;
+import com.kingdee.shr.base.syssetting.app.util.XMLUtil;
+import com.kingdee.shr.base.syssetting.context.SHRContext;
+import com.kingdee.shr.base.syssetting.exception.SHRWebException;
+import com.kingdee.shr.base.syssetting.exception.ShrWebBizException;
+import com.kingdee.shr.base.syssetting.ml.SHRWebResource;
+import com.kingdee.shr.base.syssetting.model.VirtualDataFetcher;
+import com.kingdee.shr.base.syssetting.util.MetaDataUtil;
+import com.kingdee.shr.base.syssetting.util.SysSettingUIViewUtil;
+import com.kingdee.shr.base.syssetting.web.dynamic.model.FieldInfo;
+import com.kingdee.shr.base.syssetting.web.dynamic.model.ListUIViewInfo;
+import com.kingdee.shr.base.syssetting.web.dynamic.model.UIViewInfo;
+import com.kingdee.shr.base.syssetting.web.dynamic.util.UIViewUtil;
+import com.kingdee.shr.base.syssetting.web.dynamic.view.converter.IFragmentUIViewConverter;
+import com.kingdee.shr.base.syssetting.web.dynamic.view.converter.IUIViewConverter;
+import com.kingdee.shr.base.syssetting.web.dynamic.view.converter.UIViewConverterFactory;
+import com.kingdee.shr.ml.MLServiceFactory;
+import com.kingdee.shr.ml.ResourceType;
+import com.kingdee.util.LocaleUtils;
+import com.kingdee.util.StringUtils;
+import com.kingdee.util.Uuid;
+import org.jdom.Document;
+import org.jdom.Element;
+import org.jdom.output.XMLOutputter;
+import org.jdom.xpath.XPath;
+
+import java.text.MessageFormat;
+import java.util.*;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class ViewGetDataService implements IHRMsfService {
+    @Override
+    public Object process(Context context, Map map) throws EASBizException, BOSException {
+        String uipk = map.get("uipk") == null ? "" : map.get("uipk").toString();
+        String where = map.get("where") == null ? "" : map.get("where").toString();
+        try {
+            JSONArray jsonArray = new JSONArray();
+            ViewGetDataUtils viewGetDataUtils = new ViewGetDataUtils(context,uipk);
+            //通过uipk获取视图信息
+            UIViewInfo viewInfo = viewGetDataUtils.getViewInfo();
+            //获取视图配置字段
+            List<FieldInfo> fields = viewInfo.getFields();
+            String query = viewInfo.getQuery();
+            //判断页面是否配置query
+            if (query != null && !query.equals("")) {
+                //通过query获取数据
+                List<Map<String, Object>> gridDataEntity = viewGetDataUtils.getGridDataEntity( uipk, where);
+                //合拼组装数据 ,页面配置字段和查询的数据
+                for (int i = 0; i < gridDataEntity.size(); i++) {
+                    Map<String, Object> stringObjectMap = gridDataEntity.get(i);
+                    JSONArray jsonArray1 = new JSONArray();
+                    for (int j = 0; j < fields.size(); j++) {
+                        JSONObject jsonObject = new JSONObject();
+                        FieldInfo fieldInfo = fields.get(j);
+                        String alias = fieldInfo.getAlias();
+                        String name = fieldInfo.getName();
+                        DataType dataType = fieldInfo.getDataType();
+                        jsonObject.put("alias", alias);
+                        jsonObject.put("name", name);
+                        jsonObject.put("dataType", dataType);
+                        Object o = stringObjectMap.get(name);
+                        jsonObject.put("data", o);
+                        jsonArray1.add(jsonObject);
+                    }
+                    jsonArray.add(jsonArray1);
+                }
+                return jsonArray;
+            }
+            // 未配置query
+            List<CoreBaseInfo> coreBaseList = viewGetDataUtils.getCoreBaseInfo(uipk, where);
+            //合拼组装数据 ,页面配置字段和查询的数据
+            for (int i = 0; i < coreBaseList.size(); i++) {
+                CoreBaseInfo coreBaseInfo = coreBaseList.get(i);
+                JSONArray jsonArray1 = new JSONArray();
+                int w = 0;
+                for (int j = 0; j < fields.size(); j++) {
+                    JSONObject jsonObject = new JSONObject();
+                    FieldInfo fieldInfo = fields.get(j);
+                    String alias = fieldInfo.getAlias();
+                    String name = fieldInfo.getName();
+                    DataType dataType = fieldInfo.getDataType();
+                    jsonObject.put("alias", alias);
+                    jsonObject.put("name", name);
+                    jsonObject.put("dataType", dataType);
+                    Object o = coreBaseInfo.get(name);
+                    jsonObject.put("data", o );
+                    if (dataType!=null&&dataType.getName().equals("Enum")){
+                        PropertyInfo property = fieldInfo.getProperty();
+                        if (property instanceof OwnPropertyInfo) {
+                            OwnPropertyInfo ownProp = (OwnPropertyInfo)property;
+                            if (DataType.ENUM.equals(ownProp.getDataType())) {
+                                String enumSource = ownProp.getMetaDataRef();
+                                if ( o!=null){
+                                    Object enumByValue = com.kingdee.shr.base.syssetting.app.util.MetaDataUtil.findEnumByValue(enumSource, o);
+                                    jsonObject.put("data", enumByValue);
+                                }
+                            }
+                        }
+
+                    }
+
+
+                    jsonArray1.add(jsonObject);
+                    Map<String, String> attributes = fieldInfo.getAttributes();
+                    if (attributes != null) {
+                        String s = attributes.get("data-isGridCol");
+                        if (s != null && s.equals("true")) {
+                            String dataUipk = attributes.get("data-uipk");
+                            if (dataUipk.equals(uipk)) {
+                                jsonObject.put("data", "");
+                                break;
+                            }
+                            String dataValue = attributes.get("data-value");
+                            String dataComparison = attributes.get("data-comparison");
+                            if (dataUipk != null && !dataUipk.equals("")
+                                    && dataValue != null && !dataValue.equals("")
+                                    && dataComparison != null && !dataComparison.equals("")) {
+                                Map<String, Object> serverMap = new HashMap<>();
+                                serverMap.put("uipk", dataUipk);
+                                serverMap.put("where", dataComparison + " = " + "'" + coreBaseInfo.getString(dataValue) + "'");
+                                Object o1 = MSFServiceFacadeFactory.getLocalInstance(context).processService("serviceTest", serverMap);
+                                if (o1 != null) {
+//                                    JSONArray objects = JSONArray.parseArray(o1.toString());
+                                    jsonObject.put("data", o1);
+
+                                }
+                            }
+                        }
+                    }
+
+
+                }
+                jsonArray.add(jsonArray1);
+            }
+            return jsonArray;
+        } catch (SHRWebException e) {
+            throw new RuntimeException(e);
+        } catch (ParserException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+
+
+    public static void main(String[] args) {
+        Pattern sqlPattern = Pattern.compile(
+                "(?:')|(?:--)|(/\\*(?:.|[\\n\\r])*?\\*/)|(\\b(select|update|and|or|delete"
+                        + "|insert|trancate|char|substr|ascii|declare|exec|count|master|into|drop|execute)\\b|(\\*|;|\\+|'|%))");
+
+        Matcher ors = sqlPattern.matcher(null);
+        System.out.println(ors.find());
+    }
+}

+ 392 - 0
OSFViewConfig/code/v1/8.0/com/kingdee/eas/custom/utils/ViewGetDataUtils.java

@@ -0,0 +1,392 @@
+package com.kingdee.eas.custom.utils;
+
+import com.kingdee.bos.BOSException;
+import com.kingdee.bos.Context;
+import com.kingdee.bos.dao.query.IQueryExecutor;
+import com.kingdee.bos.dao.query.QueryExecutorFactory;
+import com.kingdee.bos.framework.cache.service.CacheService;
+import com.kingdee.bos.metadata.MetaDataPK;
+import com.kingdee.bos.metadata.entity.EntityViewInfo;
+import com.kingdee.bos.metadata.entity.FilterInfo;
+import com.kingdee.bos.metadata.entity.SelectorItemCollection;
+import com.kingdee.bos.metadata.entity.SorterItemCollection;
+import com.kingdee.bos.sql.ParserException;
+import com.kingdee.eas.common.EASBizException;
+import com.kingdee.eas.framework.CoreBaseCollection;
+import com.kingdee.eas.framework.CoreBaseInfo;
+import com.kingdee.eas.framework.ICoreBase;
+import com.kingdee.shr.base.syssetting.DomainFilterFacadeFactory;
+import com.kingdee.shr.base.syssetting.IDomainFilterFacade;
+import com.kingdee.shr.base.syssetting.UIViewFactory;
+import com.kingdee.shr.base.syssetting.app.util.XMLUtil;
+import com.kingdee.shr.base.syssetting.context.SHRContext;
+import com.kingdee.shr.base.syssetting.exception.SHRWebException;
+import com.kingdee.shr.base.syssetting.exception.ShrWebBizException;
+import com.kingdee.shr.base.syssetting.ml.SHRWebResource;
+import com.kingdee.shr.base.syssetting.model.VirtualDataFetcher;
+import com.kingdee.shr.base.syssetting.util.MetaDataUtil;
+import com.kingdee.shr.base.syssetting.util.SysSettingUIViewUtil;
+import com.kingdee.shr.base.syssetting.web.dynamic.model.ListUIViewInfo;
+import com.kingdee.shr.base.syssetting.web.dynamic.model.UIViewInfo;
+import com.kingdee.shr.base.syssetting.web.dynamic.util.UIViewUtil;
+import com.kingdee.shr.base.syssetting.web.dynamic.view.converter.IFragmentUIViewConverter;
+import com.kingdee.shr.base.syssetting.web.dynamic.view.converter.IUIViewConverter;
+import com.kingdee.shr.base.syssetting.web.dynamic.view.converter.UIViewConverterFactory;
+import com.kingdee.shr.ml.MLServiceFactory;
+import com.kingdee.shr.ml.ResourceType;
+import com.kingdee.util.LocaleUtils;
+import com.kingdee.util.StringUtils;
+import com.kingdee.util.Uuid;
+import org.jdom.Document;
+import org.jdom.Element;
+import org.jdom.output.XMLOutputter;
+import org.jdom.xpath.XPath;
+
+import java.text.MessageFormat;
+import java.util.*;
+
+public class ViewGetDataUtils {
+    private UIViewInfo viewInfo = null;
+
+    private Context context = null;
+
+    public UIViewInfo getViewInfo() {
+        return viewInfo;
+    }
+
+    public void setViewInfo(UIViewInfo viewInfo) {
+        this.viewInfo = viewInfo;
+    }
+
+    public ViewGetDataUtils(Context context, String uipk){
+        this.context = context;
+        try {
+            this.viewInfo = getUIViewInfoByUIPK( uipk);
+        } catch (SHRWebException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    public FilterInfo getDomainFilter(Context context) throws SHRWebException {
+        ListUIViewInfo uiViewInfo = (ListUIViewInfo)viewInfo;
+        String domain = uiViewInfo.getDomain();
+        if (StringUtils.isEmpty(domain)) {
+            domain = uiViewInfo.getDomain();
+        }
+
+        if (!StringUtils.isEmpty(domain)) {
+            try {
+                IDomainFilterFacade localInstance = DomainFilterFacadeFactory.getLocalInstance(context);
+                FilterInfo domainFilter = localInstance.getDomainFilter(uiViewInfo.getEntityName(), domain,null);
+                return domainFilter;
+            } catch (Exception var5) {
+                throw new SHRWebException(var5.getMessage(), var5);
+            }
+        } else {
+            return null;
+        }
+    }
+
+
+    /**
+     * @Author: LiuYing
+     * @Description:
+     * @DateTime: 2025/5/14 17:29
+     * @Params: 查询数据
+     * @Return:
+     */
+    public List<CoreBaseInfo> getCoreBaseInfo( String uipk, String where) throws SHRWebException {
+        CoreBaseCollection collection = this.initCollection(this.context, uipk, where);
+        List<CoreBaseInfo> list = new ArrayList();
+        int i = 0;
+
+        for (int size = collection.size(); i < size; ++i) {
+            list.add(collection.get(i));
+        }
+
+        return list;
+    }
+
+    public CoreBaseCollection initCollection(Context context, String uipk, String where) throws SHRWebException {
+        EntityViewInfo entityViewInfo = this.getEntityViewInfo( uipk, where);
+
+        try {
+            CoreBaseCollection collection = this.getBizInterface().getCollection(entityViewInfo);
+            return collection;
+        } catch (BOSException var8) {
+            throw new SHRWebException(var8.getMessage(), var8);
+        }
+    }
+
+    public ICoreBase getBizInterface() throws SHRWebException {
+        if (viewInfo == null) {
+            return null;
+        } else {
+            try {
+                return MetaDataUtil.getBizInterface(SHRContext.getInstance().getContext(), viewInfo.getEntityName());
+            } catch (BOSException var4) {
+                throw new SHRWebException(var4);
+            }
+        }
+    }
+
+    /**
+     * @Author: LiuYing
+     * @Description:
+     * @DateTime: 2025/5/14 17:30
+     * @Params: 组装EntityViewInfo
+     * @Return:
+     */
+    public EntityViewInfo getEntityViewInfo(String uipk, String where) throws SHRWebException {
+        EntityViewInfo entityViewInfo = new EntityViewInfo();
+        try {
+            FilterInfo filterInfo1 = new FilterInfo();
+
+            if (!where.equals("")) {
+                FilterInfo filterInfo = new FilterInfo(where);
+                filterInfo1.mergeFilter(filterInfo,"AND");
+            }
+            FilterInfo domainFilter = getDomainFilter(this.context);
+            filterInfo1.mergeFilter(domainFilter,"AND");
+            entityViewInfo.setFilter(filterInfo1);
+        } catch (ParserException e) {
+            throw new RuntimeException(e);
+        } catch (BOSException e) {
+            throw new RuntimeException(e);
+        }
+//        filterInfo.getFilterItems().add(new FilterItemInfo(relateField, billId));
+//        entityViewInfo.setFilter(filterInfo);
+        entityViewInfo.setSelector(this.getSelectors( uipk));
+        UIViewInfo uiViewInfo = viewInfo;
+        if (uiViewInfo.getOrderBy() != null) {
+            SorterItemCollection sorter = new SorterItemCollection();
+            try {
+                sorter.getSorter().decode("order by " + uiViewInfo.getOrderBy());
+            } catch (ParserException var9) {
+                throw new SHRWebException(var9.getMessage(), var9);
+            }
+            entityViewInfo.setSorter(sorter);
+        }
+        return entityViewInfo;
+    }
+
+    /**
+     * @Author: LiuYing
+     * @Description:
+     * @DateTime: 2025/5/14 11:47
+     * @Params: 获取视图配置字段
+     * @Return:
+     */
+
+    public SelectorItemCollection getSelectors(String uipk) throws SHRWebException {
+        UIViewInfo viewInfo = getUIViewInfoByUIPK( uipk);
+        SelectorItemCollection sic = null;
+        if (viewInfo != null) {
+            sic = viewInfo.getSelectors();
+            if (sic == null) {
+                sic = UIViewUtil.assembleSelector(viewInfo);
+                viewInfo.setSelectors(sic);
+            }
+        }
+        return sic;
+    }
+
+    public boolean isRequestFragment(String uipk) {
+        return uipk.indexOf("$") != -1;
+    }
+
+    /**
+     * @Author: LiuYing
+     * @Description:
+     * @DateTime: 2025/5/14 17:31
+     * @Params: 通过uikp 获取视图信息
+     * @Return:
+     */
+
+    public  UIViewInfo getUIViewInfoByUIPK(String uipk) throws SHRWebException {
+        if (viewInfo == null) {
+            if (isRequestFragment(uipk)) {
+                String[] str = uipk.split("\\$");
+                String str1 = str[1];
+                if (!StringUtils.isEmpty(str1)) {
+                    str1 = str1.replaceAll("'", "").replaceAll("\\|", "").replaceAll("location", "").replaceAll("\\[", "").replaceAll("\\]", "").replaceAll("=", "").replaceAll("\\\\", "").replaceAll("\\+", "").replaceAll("window", "");
+                }
+
+                viewInfo = generateUIViewFragment( str[0], str1);
+            } else {
+                viewInfo = generateUIView( uipk);
+            }
+
+            addUIViewInfo( uipk, viewInfo);
+        }
+
+        return viewInfo;
+    }
+
+    /**
+     * @Author: LiuYing
+     * @Description:
+     * @DateTime: 2025/5/14 17:32
+     * @Params: 添加视图
+     * @Return:
+     */
+
+    public  void addUIViewInfo( String key, UIViewInfo uiViewInfo) {
+        CacheService.getInstance().put("shr.uiView", getKey(key, this.context.getLocale().toString()), uiViewInfo);
+    }
+
+    /**
+     * @Author: LiuYing
+     * @Description:
+     * @DateTime: 2025/5/14 17:33
+     * @Params: 生成视图
+     * @Return:
+     */
+
+    public  UIViewInfo generateUIView( String uipk) throws SHRWebException {
+        com.kingdee.shr.base.syssetting.UIViewInfo dbUIViewInfo = getUIViewFromDB( uipk);
+        if (dbUIViewInfo == null) {
+            if (uipk.contains(" ")) {
+                throw new ShrWebBizException(MessageFormat.format(SHRWebResource.getString("com.kingdee.shr.base.syssetting.SHRSyssettingResource", "view_contain_blank"), uipk));
+            } else {
+                throw new ShrWebBizException(SHRWebResource.getString("com.kingdee.shr.base.syssetting.SHRSyssettingResource", "view_not_found"));
+            }
+        } else {
+            dealTreeNavigationElement(dbUIViewInfo);
+            IUIViewConverter converter = UIViewConverterFactory.getUIViewConverter(dbUIViewInfo, this.context);
+            return converter.exec();
+        }
+    }
+
+    public  com.kingdee.shr.base.syssetting.UIViewInfo getUIViewFromDB( String uipk) throws SHRWebException {
+        try {
+            if (LocaleUtils.locale_zh_CN.toString().equals(LocaleUtils.getLocaleString(LocaleUtils.getFirstOriginLocale(this.context.getLocale())))) {
+                return UIViewFactory.getLocalInstance(this.context).getValueByUipk(uipk, SysSettingUIViewUtil.getUIViewSelector());
+            } else {
+                Map<String, Object> params = new HashMap();
+                params.put("uipks", uipk);
+                params.put("isConvert", true);
+                Object obj = MLServiceFactory.getLocalInstance(this.context).convert(ResourceType.UIView, params);
+                return null == obj ? null : (com.kingdee.shr.base.syssetting.UIViewInfo) obj;
+            }
+        } catch (BOSException var4) {
+            throw new ShrWebBizException(var4.getMessage(), var4);
+        } catch (EASBizException var5) {
+            throw new ShrWebBizException(var5.getMessage(), var5);
+        }
+    }
+
+    public  void dealTreeNavigationElement(com.kingdee.shr.base.syssetting.UIViewInfo dbUIViewInfo) {
+        String content = dealConfig(dbUIViewInfo.getContent());
+        String extend = dealConfig(dbUIViewInfo.getExtend());
+        if (!StringUtils.isEmpty(content)) {
+            dbUIViewInfo.setContent(content);
+        }
+
+        if (!StringUtils.isEmpty(extend)) {
+            dbUIViewInfo.setExtend(extend);
+        }
+
+    }
+
+    public  String dealConfig(String text) {
+        if (StringUtils.isEmpty(text)) {
+            return null;
+        } else {
+            try {
+                XMLOutputter output = XMLUtil.getXMLOutputter();
+                Document doc = XMLUtil.parseXML(text);
+                Element rootElement = doc.getRootElement();
+                XPath xPathTreeNavigation = XPath.newInstance("//treeNavigation");
+                XPath xPathFilterItem = XPath.newInstance("//filterItem[@isAdminOrg='true']");
+                List<Element> treeNavigations = xPathTreeNavigation.selectNodes(rootElement);
+                List<Element> filterItems = xPathFilterItem.selectNodes(rootElement);
+                if (null != treeNavigations && treeNavigations.size() > 0) {
+                    if (null != filterItems && filterItems.size() > 0) {
+                        Iterator i$ = treeNavigations.iterator();
+
+                        while (i$.hasNext()) {
+                            Element e = (Element) i$.next();
+                            Element parent = e.getParent();
+                            parent.removeContent(e);
+                        }
+
+                        String r = output.outputString(doc);
+                        return r;
+                    } else {
+                        return null;
+                    }
+                } else {
+                    return null;
+                }
+            } catch (Exception var11) {
+                return null;
+            }
+        }
+    }
+
+    /**
+     * @Author: LiuYing
+     * @Description:
+     * @DateTime: 2025/5/14 17:33
+     * @Params: 生成视图
+     * @Return:
+     */
+
+    public  UIViewInfo generateUIViewFragment( String parentkey, String subType) throws SHRWebException {
+        UIViewInfo parentUIViewInfo = getUIViewInfoByUIPK(parentkey);
+        if (parentUIViewInfo == null) {
+            throw new ShrWebBizException(MessageFormat.format(SHRWebResource.getString("com.kingdee.shr.base.syssetting.SHRSyssettingResource", "view_not_exist"), parentkey));
+        } else {
+            IFragmentUIViewConverter converter = UIViewConverterFactory.getFragmentUIViewConverter(parentUIViewInfo, this.context);
+            converter.setSubType(subType);
+            return converter.exec();
+        }
+    }
+
+    public  UIViewInfo getUIViewInfoFromCache( String uipk) {
+        return (UIViewInfo) CacheService.getInstance().get("shr.uiView", getKey(uipk, this.context.getLocale().toString()));
+    }
+
+    public  String getKey(String key, String locale) {
+        return MessageFormat.format("{0}_{1}", key, locale);
+    }
+
+    public List<Map<String, Object>> getGridDataEntity(String uipk, String where) throws SHRWebException, ShrWebBizException, ParserException, BOSException {
+        ListUIViewInfo uiViewInfo = (ListUIViewInfo) viewInfo;
+        String query = uiViewInfo.getQuery();
+        IQueryExecutor queryExecutor = this.getQueryExecutor(uipk, where, query);
+        Uuid uuid = queryExecutor.openQuery();
+        VirtualDataFetcher vdf = VirtualDataFetcher.createInstance(queryExecutor, uuid, 0, 1000);
+        List<Map<String, Object>> data = vdf.getData();
+        return data;
+    }
+
+    /**
+     * @Author: LiuYing
+     * @Description:
+     * @DateTime: 2025/5/14 17:37
+     * @Params: 获取查询执行器
+     * @Return:
+     */
+    public IQueryExecutor getQueryExecutor(String uipk, String where, String query) throws SHRWebException, ShrWebBizException, BOSException, ParserException {
+        IQueryExecutor exec = QueryExecutorFactory.getLocalInstance(this.context, MetaDataPK.create(query));
+        EntityViewInfo entityViewInfo = this.getEntityViewInfo(uipk, where);
+        exec.setObjectView(entityViewInfo);
+        exec.option().isIgnoreOrder = true;
+        exec.option().isAutoIgnoreZero = true;
+        exec.option().isAutoTranslateBoolean = true;
+        exec.option().isAutoTranslateEnum = true;
+        exec.option().isIgnorePermissionCheck = false;
+//        Map<String, String> queryOption = (Map)modelMap.get("queryOption");
+//        if (queryOption != null) {
+//            String value = (String)queryOption.get("isAutoIgnoreZero");
+//            if (value != null) {
+//                exec.option().isAutoIgnoreZero = Boolean.parseBoolean(value);
+//            }
+//        }
+
+        return exec;
+    }
+
+}

+ 147 - 0
OSFViewConfig/code/v1/9.0/com/kingdee/eas/custom/utils/ViewGetDataService.java

@@ -0,0 +1,147 @@
+package com.kingdee.eas.custom.utils;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.kingdee.bos.BOSException;
+import com.kingdee.bos.Context;
+import com.kingdee.bos.bsf.service.app.IHRMsfService;
+import com.kingdee.bos.metadata.entity.*;
+import com.kingdee.bos.sql.ParserException;
+import com.kingdee.eas.common.EASBizException;
+import com.kingdee.eas.framework.CoreBaseInfo;
+
+import com.kingdee.shr.base.syssetting.MSFServiceFacadeFactory;
+
+import com.kingdee.shr.base.syssetting.exception.SHRWebException;
+
+import com.kingdee.shr.base.syssetting.web.dynamic.model.FieldInfo;
+import com.kingdee.shr.base.syssetting.web.dynamic.model.UIViewInfo;
+
+
+import java.util.*;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class ViewGetDataService implements IHRMsfService {
+    @Override
+    public Object process(Context context, Map map) throws EASBizException, BOSException {
+        String uipk = map.get("uipk") == null ? "" : map.get("uipk").toString();
+        String where = map.get("where") == null ? "" : map.get("where").toString();
+        try {
+            JSONArray jsonArray = new JSONArray();
+            ViewGetDataUtils viewGetDataUtils = new ViewGetDataUtils(context,uipk);
+            //通过uipk获取视图信息
+            UIViewInfo viewInfo = viewGetDataUtils.getViewInfo();
+            //获取视图配置字段
+            List<FieldInfo> fields = viewInfo.getFields();
+            String query = viewInfo.getQuery();
+            //判断页面是否配置query
+            if (query != null && !query.equals("")) {
+                //通过query获取数据
+                List<Map<String, Object>> gridDataEntity = viewGetDataUtils.getGridDataEntity( uipk, where);
+                //合拼组装数据 ,页面配置字段和查询的数据
+                for (int i = 0; i < gridDataEntity.size(); i++) {
+                    Map<String, Object> stringObjectMap = gridDataEntity.get(i);
+                    JSONArray jsonArray1 = new JSONArray();
+                    for (int j = 0; j < fields.size(); j++) {
+                        JSONObject jsonObject = new JSONObject();
+                        FieldInfo fieldInfo = fields.get(j);
+                        String alias = fieldInfo.getAlias();
+                        String name = fieldInfo.getName();
+                        DataType dataType = fieldInfo.getDataType();
+                        jsonObject.put("alias", alias);
+                        jsonObject.put("name", name);
+                        jsonObject.put("dataType", dataType);
+                        Object o = stringObjectMap.get(name);
+                        jsonObject.put("data", o);
+                        jsonArray1.add(jsonObject);
+                    }
+                    jsonArray.add(jsonArray1);
+                }
+                return jsonArray;
+            }
+            // 未配置query
+            List<CoreBaseInfo> coreBaseList = viewGetDataUtils.getCoreBaseInfo(uipk, where);
+            //合拼组装数据 ,页面配置字段和查询的数据
+            for (int i = 0; i < coreBaseList.size(); i++) {
+                CoreBaseInfo coreBaseInfo = coreBaseList.get(i);
+                JSONArray jsonArray1 = new JSONArray();
+                int w = 0;
+                for (int j = 0; j < fields.size(); j++) {
+                    JSONObject jsonObject = new JSONObject();
+                    FieldInfo fieldInfo = fields.get(j);
+                    String alias = fieldInfo.getAlias();
+                    String name = fieldInfo.getName();
+                    DataType dataType = fieldInfo.getDataType();
+                    jsonObject.put("alias", alias);
+                    jsonObject.put("name", name);
+                    jsonObject.put("dataType", dataType);
+                    Object o = coreBaseInfo.get(name);
+                    jsonObject.put("data", o );
+                    if (dataType!=null&&dataType.getName().equals("Enum")){
+                        PropertyInfo property = fieldInfo.getProperty();
+                        if (property instanceof OwnPropertyInfo) {
+                            OwnPropertyInfo ownProp = (OwnPropertyInfo)property;
+                            if (DataType.ENUM.equals(ownProp.getDataType())) {
+                                String enumSource = ownProp.getMetaDataRef();
+                                if ( o!=null){
+                                    Object enumByValue = com.kingdee.shr.base.syssetting.app.util.MetaDataUtil.findEnumByValue(enumSource, o);
+                                    jsonObject.put("data", enumByValue);
+                                }
+                            }
+                        }
+
+                    }
+
+
+                    jsonArray1.add(jsonObject);
+                    Map<String, String> attributes = fieldInfo.getAttributes();
+                    if (attributes != null) {
+                        String s = attributes.get("data-isGridCol");
+                        if (s != null && s.equals("true")) {
+                            String dataUipk = attributes.get("data-uipk");
+                            if (dataUipk.equals(uipk)) {
+                                jsonObject.put("data", "");
+                                break;
+                            }
+                            String dataValue = attributes.get("data-value");
+                            String dataComparison = attributes.get("data-comparison");
+                            if (dataUipk != null && !dataUipk.equals("")
+                                    && dataValue != null && !dataValue.equals("")
+                                    && dataComparison != null && !dataComparison.equals("")) {
+                                Map<String, Object> serverMap = new HashMap<>();
+                                serverMap.put("uipk", dataUipk);
+                                serverMap.put("where", dataComparison + " = " + "'" + coreBaseInfo.getString(dataValue) + "'");
+                                Object o1 = MSFServiceFacadeFactory.getLocalInstance(context).processService("viewGetDataService", serverMap);
+                                if (o1 != null) {
+//                                    JSONArray objects = JSONArray.parseArray(o1.toString());
+                                    jsonObject.put("data", o1);
+
+                                }
+                            }
+                        }
+                    }
+
+
+                }
+                jsonArray.add(jsonArray1);
+            }
+            return jsonArray;
+        } catch (SHRWebException e) {
+            throw new RuntimeException(e);
+        } catch (ParserException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+
+
+    public static void main(String[] args) {
+        Pattern sqlPattern = Pattern.compile(
+                "(?:')|(?:--)|(/\\*(?:.|[\\n\\r])*?\\*/)|(\\b(select|update|and|or|delete"
+                        + "|insert|trancate|char|substr|ascii|declare|exec|count|master|into|drop|execute)\\b|(\\*|;|\\+|'|%))");
+
+        Matcher ors = sqlPattern.matcher(null);
+        System.out.println(ors.find());
+    }
+}

+ 394 - 0
OSFViewConfig/code/v1/9.0/com/kingdee/eas/custom/utils/ViewGetDataUtils.java

@@ -0,0 +1,394 @@
+package com.kingdee.eas.custom.utils;
+
+import com.kingdee.bos.BOSException;
+import com.kingdee.bos.Context;
+import com.kingdee.bos.dao.query.IQueryExecutor;
+import com.kingdee.bos.dao.query.QueryExecutorFactory;
+import com.kingdee.bos.framework.cache.service.CacheService;
+import com.kingdee.bos.metadata.MetaDataPK;
+import com.kingdee.bos.metadata.entity.EntityViewInfo;
+import com.kingdee.bos.metadata.entity.FilterInfo;
+import com.kingdee.bos.metadata.entity.SelectorItemCollection;
+import com.kingdee.bos.metadata.entity.SorterItemCollection;
+import com.kingdee.bos.sql.ParserException;
+import com.kingdee.eas.common.EASBizException;
+import com.kingdee.eas.framework.CoreBaseCollection;
+import com.kingdee.eas.framework.CoreBaseInfo;
+import com.kingdee.eas.framework.ICoreBase;
+import com.kingdee.shr.base.syssetting.DomainFilterFacadeFactory;
+import com.kingdee.shr.base.syssetting.IDomainFilterFacade;
+import com.kingdee.shr.base.syssetting.UIViewFactory;
+import com.kingdee.shr.base.syssetting.app.util.XMLUtil;
+import com.kingdee.shr.base.syssetting.context.SHRContext;
+import com.kingdee.shr.base.syssetting.exception.SHRWebException;
+import com.kingdee.shr.base.syssetting.exception.ShrWebBizException;
+import com.kingdee.shr.base.syssetting.ml.SHRWebResource;
+import com.kingdee.shr.base.syssetting.model.VirtualDataFetcher;
+import com.kingdee.shr.base.syssetting.util.MetaDataUtil;
+import com.kingdee.shr.base.syssetting.util.SysSettingUIViewUtil;
+import com.kingdee.shr.base.syssetting.web.dynamic.model.ListUIViewInfo;
+import com.kingdee.shr.base.syssetting.web.dynamic.model.UIViewInfo;
+import com.kingdee.shr.base.syssetting.web.dynamic.util.UIViewUtil;
+import com.kingdee.shr.base.syssetting.web.dynamic.view.converter.IFragmentUIViewConverter;
+import com.kingdee.shr.base.syssetting.web.dynamic.view.converter.IUIViewConverter;
+import com.kingdee.shr.base.syssetting.web.dynamic.view.converter.UIViewConverterFactory;
+import com.kingdee.shr.ml.MLServiceFactory;
+import com.kingdee.shr.ml.ResourceType;
+import com.kingdee.util.LocaleUtils;
+import com.kingdee.util.StringUtils;
+import com.kingdee.util.Uuid;
+import org.jdom2.Document;
+import org.jdom2.Element;
+import org.jdom2.filter.Filters;
+import org.jdom2.output.XMLOutputter;
+import org.jdom2.xpath.XPathExpression;
+import org.jdom2.xpath.XPathFactory;
+
+import javax.xml.xpath.XPath;
+import java.text.MessageFormat;
+import java.util.*;
+
+public class ViewGetDataUtils {
+    private UIViewInfo viewInfo = null;
+
+    private Context context = null;
+
+    public UIViewInfo getViewInfo() {
+        return viewInfo;
+    }
+
+    public void setViewInfo(UIViewInfo viewInfo) {
+        this.viewInfo = viewInfo;
+    }
+
+    public ViewGetDataUtils(Context context, String uipk){
+        this.context = context;
+        try {
+            this.viewInfo = getUIViewInfoByUIPK( uipk);
+        } catch (SHRWebException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    public FilterInfo getDomainFilter(Context context) throws SHRWebException {
+        ListUIViewInfo uiViewInfo = (ListUIViewInfo)viewInfo;
+        String domain = uiViewInfo.getDomain();
+        if (StringUtils.isEmpty(domain)) {
+            domain = uiViewInfo.getDomain();
+        }
+
+        if (!StringUtils.isEmpty(domain)) {
+            try {
+                IDomainFilterFacade localInstance = DomainFilterFacadeFactory.getLocalInstance(context);
+                FilterInfo domainFilter = localInstance.getDomainFilter(uiViewInfo.getEntityName(), domain,null);
+                return domainFilter;
+            } catch (Exception var5) {
+                throw new SHRWebException(var5.getMessage(), var5);
+            }
+        } else {
+            return null;
+        }
+    }
+
+
+    /**
+     * @Author: LiuYing
+     * @Description:
+     * @DateTime: 2025/5/14 17:29
+     * @Params: 查询数据
+     * @Return:
+     */
+    public List<CoreBaseInfo> getCoreBaseInfo( String uipk, String where) throws SHRWebException {
+        CoreBaseCollection collection = this.initCollection(this.context, uipk, where);
+        List<CoreBaseInfo> list = new ArrayList();
+        int i = 0;
+
+        for (int size = collection.size(); i < size; ++i) {
+            list.add(collection.get(i));
+        }
+
+        return list;
+    }
+
+    public CoreBaseCollection initCollection(Context context, String uipk, String where) throws SHRWebException {
+        EntityViewInfo entityViewInfo = this.getEntityViewInfo( uipk, where);
+
+        try {
+            CoreBaseCollection collection = this.getBizInterface().getCollection(entityViewInfo);
+            return collection;
+        } catch (BOSException var8) {
+            throw new SHRWebException(var8.getMessage(), var8);
+        }
+    }
+
+    public ICoreBase getBizInterface() throws SHRWebException {
+        if (viewInfo == null) {
+            return null;
+        } else {
+            try {
+                return MetaDataUtil.getBizInterface(SHRContext.getInstance().getContext(), viewInfo.getEntityName());
+            } catch (BOSException var4) {
+                throw new SHRWebException(var4);
+            }
+        }
+    }
+
+    /**
+     * @Author: LiuYing
+     * @Description:
+     * @DateTime: 2025/5/14 17:30
+     * @Params: 组装EntityViewInfo
+     * @Return:
+     */
+    public EntityViewInfo getEntityViewInfo(String uipk, String where) throws SHRWebException {
+        EntityViewInfo entityViewInfo = new EntityViewInfo();
+        try {
+            FilterInfo filterInfo1 = new FilterInfo();
+
+            if (!where.equals("")) {
+                FilterInfo filterInfo = new FilterInfo(where);
+                filterInfo1.mergeFilter(filterInfo,"AND");
+            }
+            FilterInfo domainFilter = getDomainFilter(this.context);
+            filterInfo1.mergeFilter(domainFilter,"AND");
+            entityViewInfo.setFilter(filterInfo1);
+        } catch (ParserException e) {
+            throw new RuntimeException(e);
+        } catch (BOSException e) {
+            throw new RuntimeException(e);
+        }
+//        filterInfo.getFilterItems().add(new FilterItemInfo(relateField, billId));
+//        entityViewInfo.setFilter(filterInfo);
+        entityViewInfo.setSelector(this.getSelectors( uipk));
+        UIViewInfo uiViewInfo = viewInfo;
+        if (uiViewInfo.getOrderBy() != null) {
+            SorterItemCollection sorter = new SorterItemCollection();
+            try {
+                sorter.getSorter().decode("order by " + uiViewInfo.getOrderBy());
+            } catch (ParserException var9) {
+                throw new SHRWebException(var9.getMessage(), var9);
+            }
+            entityViewInfo.setSorter(sorter);
+        }
+        return entityViewInfo;
+    }
+
+    /**
+     * @Author: LiuYing
+     * @Description:
+     * @DateTime: 2025/5/14 11:47
+     * @Params: 获取视图配置字段
+     * @Return:
+     */
+
+    public SelectorItemCollection getSelectors(String uipk) throws SHRWebException {
+        UIViewInfo viewInfo = getUIViewInfoByUIPK( uipk);
+        SelectorItemCollection sic = null;
+        if (viewInfo != null) {
+            sic = viewInfo.getSelectors();
+            if (sic == null) {
+                sic = UIViewUtil.assembleSelector(viewInfo);
+                viewInfo.setSelectors(sic);
+            }
+        }
+        return sic;
+    }
+
+    public boolean isRequestFragment(String uipk) {
+        return uipk.indexOf("$") != -1;
+    }
+
+    /**
+     * @Author: LiuYing
+     * @Description:
+     * @DateTime: 2025/5/14 17:31
+     * @Params: 通过uikp 获取视图信息
+     * @Return:
+     */
+
+    public  UIViewInfo getUIViewInfoByUIPK(String uipk) throws SHRWebException {
+        if (viewInfo == null) {
+            if (isRequestFragment(uipk)) {
+                String[] str = uipk.split("\\$");
+                String str1 = str[1];
+                if (!StringUtils.isEmpty(str1)) {
+                    str1 = str1.replaceAll("'", "").replaceAll("\\|", "").replaceAll("location", "").replaceAll("\\[", "").replaceAll("\\]", "").replaceAll("=", "").replaceAll("\\\\", "").replaceAll("\\+", "").replaceAll("window", "");
+                }
+
+                viewInfo = generateUIViewFragment( str[0], str1);
+            } else {
+                viewInfo = generateUIView( uipk);
+            }
+
+            addUIViewInfo( uipk, viewInfo);
+        }
+
+        return viewInfo;
+    }
+
+    /**
+     * @Author: LiuYing
+     * @Description:
+     * @DateTime: 2025/5/14 17:32
+     * @Params: 添加视图
+     * @Return:
+     */
+
+    public  void addUIViewInfo( String key, UIViewInfo uiViewInfo) {
+        CacheService.getInstance().put("shr.uiView", getKey(key, this.context.getLocale().toString()), uiViewInfo);
+    }
+
+    /**
+     * @Author: LiuYing
+     * @Description:
+     * @DateTime: 2025/5/14 17:33
+     * @Params: 生成视图
+     * @Return:
+     */
+
+    public  UIViewInfo generateUIView( String uipk) throws SHRWebException {
+        com.kingdee.shr.base.syssetting.UIViewInfo dbUIViewInfo = getUIViewFromDB( uipk);
+        if (dbUIViewInfo == null) {
+            if (uipk.contains(" ")) {
+                throw new ShrWebBizException(MessageFormat.format(SHRWebResource.getString("com.kingdee.shr.base.syssetting.SHRSyssettingResource", "view_contain_blank"), uipk));
+            } else {
+                throw new ShrWebBizException(SHRWebResource.getString("com.kingdee.shr.base.syssetting.SHRSyssettingResource", "view_not_found"));
+            }
+        } else {
+            dealTreeNavigationElement(dbUIViewInfo);
+            IUIViewConverter converter = UIViewConverterFactory.getUIViewConverter(dbUIViewInfo, this.context);
+            return converter.exec();
+        }
+    }
+
+    public  com.kingdee.shr.base.syssetting.UIViewInfo getUIViewFromDB( String uipk) throws SHRWebException {
+        try {
+            if (LocaleUtils.locale_zh_CN.toString().equals(LocaleUtils.getLocaleString(LocaleUtils.getFirstOriginLocale(this.context.getLocale())))) {
+                return UIViewFactory.getLocalInstance(this.context).getValueByUipk(uipk, SysSettingUIViewUtil.getUIViewSelector());
+            } else {
+                Map<String, Object> params = new HashMap();
+                params.put("uipks", uipk);
+                params.put("isConvert", true);
+                Object obj = MLServiceFactory.getLocalInstance(this.context).convert(ResourceType.UIView, params);
+                return null == obj ? null : (com.kingdee.shr.base.syssetting.UIViewInfo) obj;
+            }
+        } catch (BOSException var4) {
+            throw new ShrWebBizException(var4.getMessage(), var4);
+        } catch (EASBizException var5) {
+            throw new ShrWebBizException(var5.getMessage(), var5);
+        }
+    }
+
+    public  void dealTreeNavigationElement(com.kingdee.shr.base.syssetting.UIViewInfo dbUIViewInfo) {
+        String content = dealConfig(dbUIViewInfo.getContent());
+        String extend = dealConfig(dbUIViewInfo.getExtend());
+        if (!StringUtils.isEmpty(content)) {
+            dbUIViewInfo.setContent(content);
+        }
+
+        if (!StringUtils.isEmpty(extend)) {
+            dbUIViewInfo.setExtend(extend);
+        }
+
+    }
+
+    public  String dealConfig(String text) {
+        if (StringUtils.isEmpty(text)) {
+            return null;
+        } else {
+            try {
+                XMLOutputter output = XMLUtil.getXMLOutputter();
+                Document doc = XMLUtil.parseXML(text);
+                XPathFactory xpathFac = XPathFactory.instance();
+                XPathExpression<Element> xPathTreeNavigation = xpathFac.compile("//treeNavigation", Filters.element());
+                XPathExpression<Element> xPathFilterItem = xpathFac.compile("//filterItem[@isAdminOrg='true']", Filters.element());
+                List<Element> treeNavigations = xPathTreeNavigation.evaluate(doc);
+                List<Element> filterItems = xPathFilterItem.evaluate(doc);
+                if (null != treeNavigations && !treeNavigations.isEmpty()) {
+                    if (null != filterItems && !filterItems.isEmpty()) {
+                        Iterator var8 = treeNavigations.iterator();
+
+                        while(var8.hasNext()) {
+                            Element e = (Element)var8.next();
+                            Element parent = e.getParentElement();
+                            parent.removeContent(e);
+                        }
+
+                        return output.outputString(doc);
+                    } else {
+                        return null;
+                    }
+                } else {
+                    return null;
+                }
+            } catch (Exception var11) {
+                return null;
+            }
+        }
+    }
+
+    /**
+     * @Author: LiuYing
+     * @Description:
+     * @DateTime: 2025/5/14 17:33
+     * @Params: 生成视图
+     * @Return:
+     */
+
+    public  UIViewInfo generateUIViewFragment( String parentkey, String subType) throws SHRWebException {
+        UIViewInfo parentUIViewInfo = getUIViewInfoByUIPK(parentkey);
+        if (parentUIViewInfo == null) {
+            throw new ShrWebBizException(MessageFormat.format(SHRWebResource.getString("com.kingdee.shr.base.syssetting.SHRSyssettingResource", "view_not_exist"), parentkey));
+        } else {
+            IFragmentUIViewConverter converter = UIViewConverterFactory.getFragmentUIViewConverter(parentUIViewInfo, this.context);
+            converter.setSubType(subType);
+            return converter.exec();
+        }
+    }
+
+    public  UIViewInfo getUIViewInfoFromCache( String uipk) {
+        return (UIViewInfo) CacheService.getInstance().get("shr.uiView", getKey(uipk, this.context.getLocale().toString()));
+    }
+
+    public  String getKey(String key, String locale) {
+        return MessageFormat.format("{0}_{1}", key, locale);
+    }
+
+    public List<Map<String, Object>> getGridDataEntity(String uipk, String where) throws SHRWebException, ShrWebBizException, ParserException, BOSException {
+        ListUIViewInfo uiViewInfo = (ListUIViewInfo) viewInfo;
+        String query = uiViewInfo.getQuery();
+        IQueryExecutor queryExecutor = this.getQueryExecutor(uipk, where, query);
+        Uuid uuid = queryExecutor.openQuery();
+        VirtualDataFetcher vdf = VirtualDataFetcher.createInstance(queryExecutor, uuid, 0, 1000);
+        List<Map<String, Object>> data = vdf.getData();
+        return data;
+    }
+
+    /**
+     * @Author: LiuYing
+     * @Description:
+     * @DateTime: 2025/5/14 17:37
+     * @Params: 获取查询执行器
+     * @Return:
+     */
+    public IQueryExecutor getQueryExecutor(String uipk, String where, String query) throws SHRWebException, ShrWebBizException, BOSException, ParserException {
+        IQueryExecutor exec = QueryExecutorFactory.getLocalInstance(this.context, MetaDataPK.create(query));
+        EntityViewInfo entityViewInfo = this.getEntityViewInfo(uipk, where);
+        exec.setObjectView(entityViewInfo);
+        exec.option().isIgnoreOrder = true;
+        exec.option().isAutoIgnoreZero = true;
+        exec.option().isAutoTranslateBoolean = true;
+        exec.option().isAutoTranslateEnum = true;
+        exec.option().isIgnorePermissionCheck = false;
+//        Map<String, String> queryOption = (Map)modelMap.get("queryOption");
+//        if (queryOption != null) {
+//            String value = (String)queryOption.get("isAutoIgnoreZero");
+//            if (value != null) {
+//                exec.option().isAutoIgnoreZero = Boolean.parseBoolean(value);
+//            }
+//        }
+
+        return exec;
+    }
+
+}

BIN
OSFViewConfig/config/V1/8.0/OSF_Export.zip


BIN
OSFViewConfig/config/V1/8.0/sp_osfUitls_qy.jar


BIN
OSFViewConfig/config/V1/9.0/OSF_Export.zip


BIN
OSFViewConfig/config/V1/9.0/sp_osfUitls_qy.jar


+ 0 - 0
OSFViewConfig/document/通过视图配置获取系统数据.docx → OSFViewConfig/document/V1/通过视图配置获取系统数据.docx