ViewGetDataService.java 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. package com.kingdee.eas.custom.utils;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.kingdee.bos.BOSException;
  5. import com.kingdee.bos.Context;
  6. import com.kingdee.bos.bsf.service.app.IHRMsfService;
  7. import com.kingdee.bos.metadata.entity.*;
  8. import com.kingdee.bos.sql.ParserException;
  9. import com.kingdee.eas.common.EASBizException;
  10. import com.kingdee.eas.framework.CoreBaseInfo;
  11. import com.kingdee.shr.base.syssetting.MSFServiceFacadeFactory;
  12. import com.kingdee.shr.base.syssetting.exception.SHRWebException;
  13. import com.kingdee.shr.base.syssetting.web.dynamic.model.FieldInfo;
  14. import com.kingdee.shr.base.syssetting.web.dynamic.model.UIViewInfo;
  15. import java.util.*;
  16. import java.util.regex.Matcher;
  17. import java.util.regex.Pattern;
  18. public class ViewGetDataService implements IHRMsfService {
  19. @Override
  20. public Object process(Context context, Map map) throws EASBizException, BOSException {
  21. String uipk = map.get("uipk") == null ? "" : map.get("uipk").toString();
  22. String where = map.get("where") == null ? "" : map.get("where").toString();
  23. try {
  24. JSONArray jsonArray = new JSONArray();
  25. ViewGetDataUtils viewGetDataUtils = new ViewGetDataUtils(context,uipk);
  26. //通过uipk获取视图信息
  27. UIViewInfo viewInfo = viewGetDataUtils.getViewInfo();
  28. //获取视图配置字段
  29. List<FieldInfo> fields = viewInfo.getFields();
  30. String query = viewInfo.getQuery();
  31. //判断页面是否配置query
  32. if (query != null && !query.equals("")) {
  33. //通过query获取数据
  34. List<Map<String, Object>> gridDataEntity = viewGetDataUtils.getGridDataEntity( uipk, where);
  35. //合拼组装数据 ,页面配置字段和查询的数据
  36. for (int i = 0; i < gridDataEntity.size(); i++) {
  37. Map<String, Object> stringObjectMap = gridDataEntity.get(i);
  38. JSONArray jsonArray1 = new JSONArray();
  39. for (int j = 0; j < fields.size(); j++) {
  40. JSONObject jsonObject = new JSONObject();
  41. FieldInfo fieldInfo = fields.get(j);
  42. String alias = fieldInfo.getAlias();
  43. String name = fieldInfo.getName();
  44. DataType dataType = fieldInfo.getDataType();
  45. jsonObject.put("alias", alias);
  46. jsonObject.put("name", name);
  47. jsonObject.put("dataType", dataType);
  48. Object o = stringObjectMap.get(name);
  49. jsonObject.put("data", o);
  50. jsonArray1.add(jsonObject);
  51. }
  52. jsonArray.add(jsonArray1);
  53. }
  54. return jsonArray;
  55. }
  56. // 未配置query
  57. List<CoreBaseInfo> coreBaseList = viewGetDataUtils.getCoreBaseInfo(uipk, where);
  58. //合拼组装数据 ,页面配置字段和查询的数据
  59. for (int i = 0; i < coreBaseList.size(); i++) {
  60. CoreBaseInfo coreBaseInfo = coreBaseList.get(i);
  61. JSONArray jsonArray1 = new JSONArray();
  62. int w = 0;
  63. for (int j = 0; j < fields.size(); j++) {
  64. JSONObject jsonObject = new JSONObject();
  65. FieldInfo fieldInfo = fields.get(j);
  66. String alias = fieldInfo.getAlias();
  67. String name = fieldInfo.getName();
  68. DataType dataType = fieldInfo.getDataType();
  69. jsonObject.put("alias", alias);
  70. jsonObject.put("name", name);
  71. jsonObject.put("dataType", dataType);
  72. Object o = coreBaseInfo.get(name);
  73. jsonObject.put("data", o );
  74. if (dataType!=null&&dataType.getName().equals("Enum")){
  75. PropertyInfo property = fieldInfo.getProperty();
  76. if (property instanceof OwnPropertyInfo) {
  77. OwnPropertyInfo ownProp = (OwnPropertyInfo)property;
  78. if (DataType.ENUM.equals(ownProp.getDataType())) {
  79. String enumSource = ownProp.getMetaDataRef();
  80. if ( o!=null){
  81. Object enumByValue = com.kingdee.shr.base.syssetting.app.util.MetaDataUtil.findEnumByValue(enumSource, o);
  82. jsonObject.put("data", enumByValue);
  83. }
  84. }
  85. }
  86. }
  87. jsonArray1.add(jsonObject);
  88. Map<String, String> attributes = fieldInfo.getAttributes();
  89. if (attributes != null) {
  90. String s = attributes.get("data-isGridCol");
  91. if (s != null && s.equals("true")) {
  92. String dataUipk = attributes.get("data-uipk");
  93. if (dataUipk.equals(uipk)) {
  94. jsonObject.put("data", "");
  95. break;
  96. }
  97. String dataValue = attributes.get("data-value");
  98. String dataComparison = attributes.get("data-comparison");
  99. if (dataUipk != null && !dataUipk.equals("")
  100. && dataValue != null && !dataValue.equals("")
  101. && dataComparison != null && !dataComparison.equals("")) {
  102. Map<String, Object> serverMap = new HashMap<>();
  103. serverMap.put("uipk", dataUipk);
  104. serverMap.put("where", dataComparison + " = " + "'" + coreBaseInfo.getString(dataValue) + "'");
  105. Object o1 = MSFServiceFacadeFactory.getLocalInstance(context).processService("viewGetDataService", serverMap);
  106. if (o1 != null) {
  107. // JSONArray objects = JSONArray.parseArray(o1.toString());
  108. jsonObject.put("data", o1);
  109. }
  110. }
  111. }
  112. }
  113. }
  114. jsonArray.add(jsonArray1);
  115. }
  116. return jsonArray;
  117. } catch (SHRWebException e) {
  118. throw new RuntimeException(e);
  119. } catch (ParserException e) {
  120. throw new RuntimeException(e);
  121. }
  122. }
  123. public static void main(String[] args) {
  124. Pattern sqlPattern = Pattern.compile(
  125. "(?:')|(?:--)|(/\\*(?:.|[\\n\\r])*?\\*/)|(\\b(select|update|and|or|delete"
  126. + "|insert|trancate|char|substr|ascii|declare|exec|count|master|into|drop|execute)\\b|(\\*|;|\\+|'|%))");
  127. Matcher ors = sqlPattern.matcher(null);
  128. System.out.println(ors.find());
  129. }
  130. }