ViewGetDataUtils.java 15 KB

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