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 getCoreBaseInfo( String uipk, String where) throws SHRWebException { CoreBaseCollection collection = this.initCollection(this.context, uipk, where); List 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 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 xPathTreeNavigation = xpathFac.compile("//treeNavigation", Filters.element()); XPathExpression xPathFilterItem = xpathFac.compile("//filterItem[@isAdminOrg='true']", Filters.element()); List treeNavigations = xPathTreeNavigation.evaluate(doc); List 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> 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> 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 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; } }