ViewGetDataUtils.java 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. package com.kingdee.eas.custom.utils;
  2. import com.kingdee.bos.BOSException;
  3. import com.kingdee.bos.Context;
  4. import com.kingdee.bos.dao.query.IQueryExecutor;
  5. import com.kingdee.bos.dao.query.QueryExecutorFactory;
  6. import com.kingdee.bos.framework.cache.service.CacheService;
  7. import com.kingdee.bos.metadata.MetaDataPK;
  8. import com.kingdee.bos.metadata.entity.EntityViewInfo;
  9. import com.kingdee.bos.metadata.entity.FilterInfo;
  10. import com.kingdee.bos.metadata.entity.SelectorItemCollection;
  11. import com.kingdee.bos.metadata.entity.SorterItemCollection;
  12. import com.kingdee.bos.sql.ParserException;
  13. import com.kingdee.eas.common.EASBizException;
  14. import com.kingdee.eas.framework.CoreBaseCollection;
  15. import com.kingdee.eas.framework.CoreBaseInfo;
  16. import com.kingdee.eas.framework.ICoreBase;
  17. import com.kingdee.shr.base.syssetting.DomainFilterFacadeFactory;
  18. import com.kingdee.shr.base.syssetting.IDomainFilterFacade;
  19. import com.kingdee.shr.base.syssetting.UIViewFactory;
  20. import com.kingdee.shr.base.syssetting.app.util.XMLUtil;
  21. import com.kingdee.shr.base.syssetting.context.SHRContext;
  22. import com.kingdee.shr.base.syssetting.exception.SHRWebException;
  23. import com.kingdee.shr.base.syssetting.exception.ShrWebBizException;
  24. import com.kingdee.shr.base.syssetting.ml.SHRWebResource;
  25. import com.kingdee.shr.base.syssetting.model.VirtualDataFetcher;
  26. import com.kingdee.shr.base.syssetting.util.MetaDataUtil;
  27. import com.kingdee.shr.base.syssetting.util.SysSettingUIViewUtil;
  28. import com.kingdee.shr.base.syssetting.web.dynamic.model.ListUIViewInfo;
  29. import com.kingdee.shr.base.syssetting.web.dynamic.model.UIViewInfo;
  30. import com.kingdee.shr.base.syssetting.web.dynamic.util.UIViewUtil;
  31. import com.kingdee.shr.base.syssetting.web.dynamic.view.converter.IFragmentUIViewConverter;
  32. import com.kingdee.shr.base.syssetting.web.dynamic.view.converter.IUIViewConverter;
  33. import com.kingdee.shr.base.syssetting.web.dynamic.view.converter.UIViewConverterFactory;
  34. import com.kingdee.shr.ml.MLServiceFactory;
  35. import com.kingdee.shr.ml.ResourceType;
  36. import com.kingdee.util.LocaleUtils;
  37. import com.kingdee.util.StringUtils;
  38. import com.kingdee.util.Uuid;
  39. import org.jdom2.Document;
  40. import org.jdom2.Element;
  41. import org.jdom2.filter.Filters;
  42. import org.jdom2.output.XMLOutputter;
  43. import org.jdom2.xpath.XPathExpression;
  44. import org.jdom2.xpath.XPathFactory;
  45. import javax.xml.xpath.XPath;
  46. import java.text.MessageFormat;
  47. import java.util.*;
  48. public class ViewGetDataUtils {
  49. private UIViewInfo viewInfo = null;
  50. private Context context = null;
  51. public UIViewInfo getViewInfo() {
  52. return viewInfo;
  53. }
  54. public void setViewInfo(UIViewInfo viewInfo) {
  55. this.viewInfo = viewInfo;
  56. }
  57. public ViewGetDataUtils(Context context, String uipk){
  58. this.context = context;
  59. try {
  60. this.viewInfo = getUIViewInfoByUIPK( uipk);
  61. } catch (SHRWebException e) {
  62. throw new RuntimeException(e);
  63. }
  64. }
  65. public FilterInfo getDomainFilter(Context context) throws SHRWebException {
  66. ListUIViewInfo uiViewInfo = (ListUIViewInfo)viewInfo;
  67. String domain = uiViewInfo.getDomain();
  68. if (StringUtils.isEmpty(domain)) {
  69. domain = uiViewInfo.getDomain();
  70. }
  71. if (!StringUtils.isEmpty(domain)) {
  72. try {
  73. IDomainFilterFacade localInstance = DomainFilterFacadeFactory.getLocalInstance(context);
  74. FilterInfo domainFilter = localInstance.getDomainFilter(uiViewInfo.getEntityName(), domain,null);
  75. return domainFilter;
  76. } catch (Exception var5) {
  77. throw new SHRWebException(var5.getMessage(), var5);
  78. }
  79. } else {
  80. return null;
  81. }
  82. }
  83. /**
  84. * @Author: LiuYing
  85. * @Description:
  86. * @DateTime: 2025/5/14 17:29
  87. * @Params: 查询数据
  88. * @Return:
  89. */
  90. public List<CoreBaseInfo> getCoreBaseInfo( String uipk, String where) throws SHRWebException {
  91. CoreBaseCollection collection = this.initCollection(this.context, uipk, where);
  92. List<CoreBaseInfo> list = new ArrayList();
  93. int i = 0;
  94. for (int size = collection.size(); i < size; ++i) {
  95. list.add(collection.get(i));
  96. }
  97. return list;
  98. }
  99. public CoreBaseCollection initCollection(Context context, String uipk, String where) throws SHRWebException {
  100. EntityViewInfo entityViewInfo = this.getEntityViewInfo( uipk, where);
  101. try {
  102. CoreBaseCollection collection = this.getBizInterface().getCollection(entityViewInfo);
  103. return collection;
  104. } catch (BOSException var8) {
  105. throw new SHRWebException(var8.getMessage(), var8);
  106. }
  107. }
  108. public ICoreBase getBizInterface() throws SHRWebException {
  109. if (viewInfo == null) {
  110. return null;
  111. } else {
  112. try {
  113. return MetaDataUtil.getBizInterface(SHRContext.getInstance().getContext(), viewInfo.getEntityName());
  114. } catch (BOSException var4) {
  115. throw new SHRWebException(var4);
  116. }
  117. }
  118. }
  119. /**
  120. * @Author: LiuYing
  121. * @Description:
  122. * @DateTime: 2025/5/14 17:30
  123. * @Params: 组装EntityViewInfo
  124. * @Return:
  125. */
  126. public EntityViewInfo getEntityViewInfo(String uipk, String where) throws SHRWebException {
  127. EntityViewInfo entityViewInfo = new EntityViewInfo();
  128. try {
  129. FilterInfo filterInfo1 = new FilterInfo();
  130. if (!where.equals("")) {
  131. FilterInfo filterInfo = new FilterInfo(where);
  132. filterInfo1.mergeFilter(filterInfo,"AND");
  133. }
  134. FilterInfo domainFilter = getDomainFilter(this.context);
  135. filterInfo1.mergeFilter(domainFilter,"AND");
  136. entityViewInfo.setFilter(filterInfo1);
  137. } catch (ParserException e) {
  138. throw new RuntimeException(e);
  139. } catch (BOSException e) {
  140. throw new RuntimeException(e);
  141. }
  142. // filterInfo.getFilterItems().add(new FilterItemInfo(relateField, billId));
  143. // entityViewInfo.setFilter(filterInfo);
  144. entityViewInfo.setSelector(this.getSelectors( uipk));
  145. UIViewInfo uiViewInfo = viewInfo;
  146. if (uiViewInfo.getOrderBy() != null) {
  147. SorterItemCollection sorter = new SorterItemCollection();
  148. try {
  149. sorter.getSorter().decode("order by " + uiViewInfo.getOrderBy());
  150. } catch (ParserException var9) {
  151. throw new SHRWebException(var9.getMessage(), var9);
  152. }
  153. entityViewInfo.setSorter(sorter);
  154. }
  155. return entityViewInfo;
  156. }
  157. /**
  158. * @Author: LiuYing
  159. * @Description:
  160. * @DateTime: 2025/5/14 11:47
  161. * @Params: 获取视图配置字段
  162. * @Return:
  163. */
  164. public SelectorItemCollection getSelectors(String uipk) throws SHRWebException {
  165. UIViewInfo viewInfo = getUIViewInfoByUIPK( uipk);
  166. SelectorItemCollection sic = null;
  167. if (viewInfo != null) {
  168. sic = viewInfo.getSelectors();
  169. if (sic == null) {
  170. sic = UIViewUtil.assembleSelector(viewInfo);
  171. viewInfo.setSelectors(sic);
  172. }
  173. }
  174. return sic;
  175. }
  176. public boolean isRequestFragment(String uipk) {
  177. return uipk.indexOf("$") != -1;
  178. }
  179. /**
  180. * @Author: LiuYing
  181. * @Description:
  182. * @DateTime: 2025/5/14 17:31
  183. * @Params: 通过uikp 获取视图信息
  184. * @Return:
  185. */
  186. public UIViewInfo getUIViewInfoByUIPK(String uipk) throws SHRWebException {
  187. if (viewInfo == null) {
  188. if (isRequestFragment(uipk)) {
  189. String[] str = uipk.split("\\$");
  190. String str1 = str[1];
  191. if (!StringUtils.isEmpty(str1)) {
  192. str1 = str1.replaceAll("'", "").replaceAll("\\|", "").replaceAll("location", "").replaceAll("\\[", "").replaceAll("\\]", "").replaceAll("=", "").replaceAll("\\\\", "").replaceAll("\\+", "").replaceAll("window", "");
  193. }
  194. viewInfo = generateUIViewFragment( str[0], str1);
  195. } else {
  196. viewInfo = generateUIView( uipk);
  197. }
  198. addUIViewInfo( uipk, viewInfo);
  199. }
  200. return viewInfo;
  201. }
  202. /**
  203. * @Author: LiuYing
  204. * @Description:
  205. * @DateTime: 2025/5/14 17:32
  206. * @Params: 添加视图
  207. * @Return:
  208. */
  209. public void addUIViewInfo( String key, UIViewInfo uiViewInfo) {
  210. CacheService.getInstance().put("shr.uiView", getKey(key, this.context.getLocale().toString()), uiViewInfo);
  211. }
  212. /**
  213. * @Author: LiuYing
  214. * @Description:
  215. * @DateTime: 2025/5/14 17:33
  216. * @Params: 生成视图
  217. * @Return:
  218. */
  219. public UIViewInfo generateUIView( String uipk) throws SHRWebException {
  220. com.kingdee.shr.base.syssetting.UIViewInfo dbUIViewInfo = getUIViewFromDB( uipk);
  221. if (dbUIViewInfo == null) {
  222. if (uipk.contains(" ")) {
  223. throw new ShrWebBizException(MessageFormat.format(SHRWebResource.getString("com.kingdee.shr.base.syssetting.SHRSyssettingResource", "view_contain_blank"), uipk));
  224. } else {
  225. throw new ShrWebBizException(SHRWebResource.getString("com.kingdee.shr.base.syssetting.SHRSyssettingResource", "view_not_found"));
  226. }
  227. } else {
  228. dealTreeNavigationElement(dbUIViewInfo);
  229. IUIViewConverter converter = UIViewConverterFactory.getUIViewConverter(dbUIViewInfo, this.context);
  230. return converter.exec();
  231. }
  232. }
  233. public com.kingdee.shr.base.syssetting.UIViewInfo getUIViewFromDB( String uipk) throws SHRWebException {
  234. try {
  235. if (LocaleUtils.locale_zh_CN.toString().equals(LocaleUtils.getLocaleString(LocaleUtils.getFirstOriginLocale(this.context.getLocale())))) {
  236. return UIViewFactory.getLocalInstance(this.context).getValueByUipk(uipk, SysSettingUIViewUtil.getUIViewSelector());
  237. } else {
  238. Map<String, Object> params = new HashMap();
  239. params.put("uipks", uipk);
  240. params.put("isConvert", true);
  241. Object obj = MLServiceFactory.getLocalInstance(this.context).convert(ResourceType.UIView, params);
  242. return null == obj ? null : (com.kingdee.shr.base.syssetting.UIViewInfo) obj;
  243. }
  244. } catch (BOSException var4) {
  245. throw new ShrWebBizException(var4.getMessage(), var4);
  246. } catch (EASBizException var5) {
  247. throw new ShrWebBizException(var5.getMessage(), var5);
  248. }
  249. }
  250. public void dealTreeNavigationElement(com.kingdee.shr.base.syssetting.UIViewInfo dbUIViewInfo) {
  251. String content = dealConfig(dbUIViewInfo.getContent());
  252. String extend = dealConfig(dbUIViewInfo.getExtend());
  253. if (!StringUtils.isEmpty(content)) {
  254. dbUIViewInfo.setContent(content);
  255. }
  256. if (!StringUtils.isEmpty(extend)) {
  257. dbUIViewInfo.setExtend(extend);
  258. }
  259. }
  260. public String dealConfig(String text) {
  261. if (StringUtils.isEmpty(text)) {
  262. return null;
  263. } else {
  264. try {
  265. XMLOutputter output = XMLUtil.getXMLOutputter();
  266. Document doc = XMLUtil.parseXML(text);
  267. XPathFactory xpathFac = XPathFactory.instance();
  268. XPathExpression<Element> xPathTreeNavigation = xpathFac.compile("//treeNavigation", Filters.element());
  269. XPathExpression<Element> xPathFilterItem = xpathFac.compile("//filterItem[@isAdminOrg='true']", Filters.element());
  270. List<Element> treeNavigations = xPathTreeNavigation.evaluate(doc);
  271. List<Element> filterItems = xPathFilterItem.evaluate(doc);
  272. if (null != treeNavigations && !treeNavigations.isEmpty()) {
  273. if (null != filterItems && !filterItems.isEmpty()) {
  274. Iterator var8 = treeNavigations.iterator();
  275. while(var8.hasNext()) {
  276. Element e = (Element)var8.next();
  277. Element parent = e.getParentElement();
  278. parent.removeContent(e);
  279. }
  280. return output.outputString(doc);
  281. } else {
  282. return null;
  283. }
  284. } else {
  285. return null;
  286. }
  287. } catch (Exception var11) {
  288. return null;
  289. }
  290. }
  291. }
  292. /**
  293. * @Author: LiuYing
  294. * @Description:
  295. * @DateTime: 2025/5/14 17:33
  296. * @Params: 生成视图
  297. * @Return:
  298. */
  299. public UIViewInfo generateUIViewFragment( String parentkey, String subType) throws SHRWebException {
  300. UIViewInfo parentUIViewInfo = getUIViewInfoByUIPK(parentkey);
  301. if (parentUIViewInfo == null) {
  302. throw new ShrWebBizException(MessageFormat.format(SHRWebResource.getString("com.kingdee.shr.base.syssetting.SHRSyssettingResource", "view_not_exist"), parentkey));
  303. } else {
  304. IFragmentUIViewConverter converter = UIViewConverterFactory.getFragmentUIViewConverter(parentUIViewInfo, this.context);
  305. converter.setSubType(subType);
  306. return converter.exec();
  307. }
  308. }
  309. public UIViewInfo getUIViewInfoFromCache( String uipk) {
  310. return (UIViewInfo) CacheService.getInstance().get("shr.uiView", getKey(uipk, this.context.getLocale().toString()));
  311. }
  312. public String getKey(String key, String locale) {
  313. return MessageFormat.format("{0}_{1}", key, locale);
  314. }
  315. public List<Map<String, Object>> getGridDataEntity(String uipk, String where) throws SHRWebException, ShrWebBizException, ParserException, BOSException {
  316. ListUIViewInfo uiViewInfo = (ListUIViewInfo) viewInfo;
  317. String query = uiViewInfo.getQuery();
  318. IQueryExecutor queryExecutor = this.getQueryExecutor(uipk, where, query);
  319. Uuid uuid = queryExecutor.openQuery();
  320. VirtualDataFetcher vdf = VirtualDataFetcher.createInstance(queryExecutor, uuid, 0, 1000);
  321. List<Map<String, Object>> data = vdf.getData();
  322. return data;
  323. }
  324. /**
  325. * @Author: LiuYing
  326. * @Description:
  327. * @DateTime: 2025/5/14 17:37
  328. * @Params: 获取查询执行器
  329. * @Return:
  330. */
  331. public IQueryExecutor getQueryExecutor(String uipk, String where, String query) throws SHRWebException, ShrWebBizException, BOSException, ParserException {
  332. IQueryExecutor exec = QueryExecutorFactory.getLocalInstance(this.context, MetaDataPK.create(query));
  333. EntityViewInfo entityViewInfo = this.getEntityViewInfo(uipk, where);
  334. exec.setObjectView(entityViewInfo);
  335. exec.option().isIgnoreOrder = true;
  336. exec.option().isAutoIgnoreZero = true;
  337. exec.option().isAutoTranslateBoolean = true;
  338. exec.option().isAutoTranslateEnum = true;
  339. exec.option().isIgnorePermissionCheck = false;
  340. // Map<String, String> queryOption = (Map)modelMap.get("queryOption");
  341. // if (queryOption != null) {
  342. // String value = (String)queryOption.get("isAutoIgnoreZero");
  343. // if (value != null) {
  344. // exec.option().isAutoIgnoreZero = Boolean.parseBoolean(value);
  345. // }
  346. // }
  347. return exec;
  348. }
  349. }