From e4bd5c35f7ced8854b1caa6defa342d35d337b5e Mon Sep 17 00:00:00 2001
From: 杜洪波 <1074825718@qq.com>
Date: 星期二, 04 十一月 2025 17:57:33 +0800
Subject: [PATCH] 图表配置优化

---
 src/main/java/com/product/server/report/service/GenerateEChartService.java |  195 ++++++++++++++++++++++++++----------------------
 1 files changed, 105 insertions(+), 90 deletions(-)

diff --git a/src/main/java/com/product/server/report/service/GenerateEChartService.java b/src/main/java/com/product/server/report/service/GenerateEChartService.java
index 813c664..a462e17 100644
--- a/src/main/java/com/product/server/report/service/GenerateEChartService.java
+++ b/src/main/java/com/product/server/report/service/GenerateEChartService.java
@@ -17,12 +17,16 @@
 import com.product.core.transfer.Transactional;
 import com.product.server.report.config.CmnConst;
 import com.product.server.report.config.ReportCode;
+import com.product.server.report.config.SystemCode;
 import com.product.server.report.service.idel.IGenerateEChartService;
 import com.product.util.BaseUtil;
 import com.product.util.SystemParamReplace;
+
+import org.apache.bcel.generic.NEW;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
+import java.util.Arrays;
 import java.util.List;
 
 /**
@@ -48,6 +52,7 @@
     public DataListReportService dataListReportService;
     @Autowired
     QueryFilterService queryFilterService;
+    
     @Override
     public JSONArray generatePieEChartMaster(FieldSetEntity fse) throws BaseException {
         String uuid = fse.getString(CmnConst.UUID);
@@ -76,101 +81,111 @@
     @Override
     public JSONObject generatePieEChart(FieldSetEntity fse) throws BaseException {
 
-        //鏁版嵁婧恥uid
+        // 鑾峰彇鏁版嵁婧怳UID 鍜� 鎶ヨ〃绫诲瀷UUID
         String report_datasource_uuid = fse.getString(CmnConst.REPORT_DATASOURCE_UUID);
-        //绫诲瀷uuid
         String report_type_config_uuid = fse.getString(CmnConst.REPORT_TYPE_CONFIG_UUID);
         if(BaseUtil.strIsNull(report_datasource_uuid) || BaseUtil.strIsNull(report_type_config_uuid)){
             return BaseUtil.fieldSetEntityToJson(fse);
         }
-        //鏌ヨ绫诲瀷琛�
-        FieldSetEntity typeField = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_REPORT_TYPE_CONFIG, report_type_config_uuid,false);
-
-        //鑾峰彇閰嶇疆鎶ヨ〃鏁版嵁婧恉ata鏁版嵁琛� .PRODUCT_SYS_report_datasource_config瀛愯〃
-        FieldSetEntity datasourceField = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_REPORT_DATASOURCE_CONFIG,report_datasource_uuid,true);
+        // 鑾峰彇鎶ヨ〃绫诲瀷
+        FieldSetEntity fseReportType = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_REPORT_TYPE_CONFIG, report_type_config_uuid, false);
+        // 鑾峰彇鎶ヨ〃鏁版嵁婧愰厤缃〃鍜屽瓧娈佃〃
+        FieldSetEntity datasourceField = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_REPORT_DATASOURCE_CONFIG, report_datasource_uuid, true);
         //鑾峰彇鏌ヨ鐨勬暟鎹畇ql
         String sql_text = datasourceField.getString(CmnConst.SQL_TEXT);
         //瑙f瀽SQL閲岄潰鐨勭郴缁熷弬鏁�
         sql_text = SystemParamReplace.systemParamsReplace(sql_text);
-        String type_group = typeField.getString(CmnConst.TYPE_GROUP);
+        String typeGroup = fseReportType.getString(CmnConst.TYPE_GROUP);
 
         //涓哄叧绯诲浘
-        if("relationCharts".equals(type_group)){
+        if("relationCharts".equals(typeGroup)){
             JSONObject obj = this.chooseRelationship(sql_text);
-            String typeGroup = typeField.getString(CmnConst.TYPE_GROUP);
             JSONObject object = new JSONObject();
-            object.put(CmnConst.TYPE_GROUP,typeGroup);
+            object.put(CmnConst.TYPE_GROUP, typeGroup);
             object.put(CmnConst.OPTION,obj);
 //            object.put("function",this.functionArray(uuid));
             return object;
         }
+        // 鑾峰彇鎶ヨ〃鏁版嵁婧愭暟鎹�
         DataTableEntity valueData = baseDao.listTable(sql_text,new Object[]{});
         //鑾峰彇鎶ヨ〃閰嶇疆灞炴�ц〃  鍔爀charts閰嶇疆灞炴��
-        //鍙兘鏌ヨ鍒板叧鑱斿睘鎬у�肩殑灞炴�ц〃锛屽鏋滅埗绾у睘鎬т笅鏈夊涓浉鍚屽瓙灞炴�с�傞�氳繃grouping鍒嗙粍銆�
-        DataTableEntity attributeData = baseDao.listTable("SELECT a.field_name,a.report_type_attr_value,a.uuid,a.grouping ,b.* FROM product_sys_report_config_attribute a LEFT JOIN product_sys_report_type_attribute b on a.report_type_attr = b.uuid WHERE a.report_config_uuid = ? ORDER BY a.grouping,b.parentAttributeUuid " ,new Object[]{fse.getString(CmnConst.UUID)});
+        //鍙兘鏌ヨ鍒板叧鑱斿睘鎬у�肩殑灞炴�ц〃锛屽鏋滅埗绾у睘鎬т笅鏈夊涓浉鍚屽瓙灞炴�с�傞�氳繃group_sign鍒嗙粍銆�
+        StringBuilder sql = new StringBuilder(); 
+        sql.append("SELECT a.uuid,a.field_name,a.report_type_attr_value,a.group_sign ,b.* \n");
+        sql.append("FROM product_sys_report_config_attribute a \n");
+        sql.append("LEFT JOIN product_sys_report_type_attribute b on a.report_type_attr = b.uuid \n");
+        sql.append("WHERE a.report_config_uuid = ? \n");
+        sql.append("ORDER BY a.group_sign,b.parent_attribute_uuid");
+        DataTableEntity attributeData = baseDao.listTable(sql.toString() ,new Object[]{fse.getString(CmnConst.UUID)});
+        if ("13081b93-bd02-4319-a423-e3000cd9e9b4".equals(fse.getUUID())) {
+			System.out.println("");
+		}
+        // 鍒涘缓鍥捐〃灞炴�у鍣�
         JSONObject allProperties = new JSONObject();
-        if(attributeData.getRows() > 0){
+        if(!BaseUtil.dataTableIsEmpty(attributeData)){
             JSONObject propertyObject = new JSONObject();
-            String parenUuid1 = attributeData.getString(0,"parentAttributeUuid");
-            String grouping1 = attributeData.getString(0,"grouping");
-            for (int i = 0,length = attributeData.getRows(); i < length; i++) {
-                FieldSetEntity fieldSet = attributeData.getFieldSetEntity(i);
-                //涓婄骇uuid
-                String parenUuid2 = fieldSet.getString("parentAttributeUuid");
-                //涓婄骇name
-                String parenName = fieldSet.getString("parentAttributeName");
-                //鍥捐〃灞炴�у��
-                String attr_value = fieldSet.getString("report_type_attr_value");
-                //涓虹┖浼犻粯璁ゅ��
-                if(BaseUtil.strIsNull(attr_value)){
-                    attr_value = fieldSet.getString("default_value");
+            String preParenAttrUuid = attributeData.getString(0, CmnConst.PARENT_ATTRIBUTE_UUID);
+            String preGroupSign = attributeData.getString(0, CmnConst.GROUP_SIGN);
+            for (int i = 0, length = attributeData.getRows(); i < length; i++) {
+                FieldSetEntity fseAttr = attributeData.getFieldSetEntity(i);
+                // 鍥捐〃灞炴�у拰閰嶇疆鍊�
+                String attrName = fseAttr.getString(CmnConst.ATTRIBUTE_NAME);
+                if("show".equals(attrName)) {
+                	System.out.println();
                 }
-                //鍥捐〃灞�
-                String attribute_name = fieldSet.getString("attribute_name");
-                //閫氳繃鏁版嵁搴撴彃鍏ユ暟鎹�
-                String fieldName = fieldSet.getString(CmnConst.FIELD_NAME);
-                //閫氳繃鏁版嵁搴撴彃鍏ユ暟鎹�
-                String grouping2 = fieldSet.getString("grouping");
+                String attrValue = fseAttr.getString(CmnConst.REPORT_TYPE_ATTR_VALUE);
+                if(BaseUtil.strIsNull(attrValue)){
+                	// 閰嶇疆鍊间负绌哄垯鐢ㄩ粯璁ゅ��
+                	attrValue = fseAttr.getString("default_value");
+                }
+                // 褰撳墠灞炴�х殑涓婄骇灞炴�uid鍜宯ame
+                String curParenAttrUuid = fseAttr.getString(CmnConst.PARENT_ATTRIBUTE_UUID);
+                String curParenAttrName = fseAttr.getString(CmnConst.PARENT_ATTRIBUTE_NAME);
+                
+                // 鑾峰彇褰撳墠灞炴�ч厤缃瓧娈� 鍜� 鍒嗙粍鍊�
+                String fieldName = fseAttr.getString(CmnConst.FIELD_NAME);
+                String curGroupSign = fseAttr.getString(CmnConst.GROUP_SIGN);
+                
                 //鏅�氬睘鎬ч兘鏈変笂绾у睘鎬э紝 鐗规畩鐨勯鑹查鏍煎睘鎬ф棤涓婄骇灞炴�э紝鏈韩灏辨槸椤剁骇灞炴�с��
-                if(!BaseUtil.strIsNull(parenUuid2)) {
+                if(!BaseUtil.strIsNull(curParenAttrUuid)) {
                     //涔嬪墠涓婄骇uuid涓虹┖
-                    if(BaseUtil.strIsNull(parenUuid1)) {
-                        parenUuid1 = parenUuid2;
+                    if(BaseUtil.strIsNull(preParenAttrUuid)) {
+                    	preParenAttrUuid = curParenAttrUuid;
                         //鏈変笉鍚岀殑灞炴�э紝鍏堟妸涔嬪墠鍚屾牱鐨勫睘鎬у皝瑁呫��
-                    }else if (!BaseUtil.strIsNull(parenUuid1) && !parenUuid2.equals(parenUuid1)) {
+                    }else if (!BaseUtil.strIsNull(preParenAttrUuid) && !curParenAttrUuid.equals(preParenAttrUuid)) {
                         //灏佽涔嬪墠鐨刯son鏁版嵁
-                        this.getAllProperties(parenUuid1, propertyObject, allProperties);
-                        parenUuid1 = parenUuid2;
-                    } else if ((parenUuid2.equals(parenUuid1) && !BaseUtil.strIsNull(grouping2))) {
-                        if (!grouping2.equals(grouping1)) {
-                            this.getAllProperties(parenUuid1, propertyObject, allProperties);
+                        this.getAllJSONAttrs(preParenAttrUuid, propertyObject, allProperties);
+                        preParenAttrUuid = curParenAttrUuid;
+                    } else if ((curParenAttrUuid.equals(preParenAttrUuid) && !BaseUtil.strIsNull(curGroupSign))) {
+                        if (!curGroupSign.equals(preGroupSign)) {
+                            this.getAllJSONAttrs(preParenAttrUuid, propertyObject, allProperties);
                         }
                     }
                 }else{
                     //涓婄骇灞炴�т负option锛岃鏄庝粬涓烘渶澶у睘鎬ф病鏈変笂绾�  鐩存帴娣诲姞杩沘llProperties
-                    if("option".equals(parenName)){
-                        allProperties.put(attribute_name,changeDataFormat(attr_value)[0]);
+                    if("option".equals(curParenAttrName)){
+                        allProperties.put(attrName, changeDataFormat(attrValue)[0]);
                         continue;
                     }
                 }
-                grouping1 = grouping2;
+                preGroupSign = curGroupSign;
                 //楗肩姸鍥炬彃鍏ユ暟鎹悓灞炰竴涓埗鍏冪礌  澶氫釜鍏冪礌鍜屽搴旂殑鏁版嵁闇�鍏ㄩ儴鎵惧嚭鏉ヤ竴璧峰皝瑁卝son
                 if(!BaseUtil.strIsNull(fieldName)){
-                    String parentAttributeName = fieldSet.getString("parentAttributeName");
+                    String parentAttributeName = fseAttr.getString(CmnConst.PARENT_ATTRIBUTE_NAME);
                     //涓嬬骇涓哄璞¤繕鏄暟缁�
-                    String type = fieldSet.getString("subordinateElementType");
+                    String type = fseAttr.getString(CmnConst.SUBORDINATE_ELEMENT_TYPE);
                     List<String> keys = ListUtils.newArrayList();
                     List<String> keys2 = ListUtils.newArrayList();
                     keys.add(fieldName);
-                    keys2.add(attribute_name);
+                    keys2.add(attrName);
                     //涓烘渶鍚庝竴浣�
                     while (i < length-1) {
                         FieldSetEntity fieldSet2 = attributeData.getFieldSetEntity(i+1);
-                        String parenUuid3 = fieldSet2.getString("parentAttributeUuid");
+                        String parenUuid3 = fieldSet2.getString(CmnConst.PARENT_ATTRIBUTE_UUID);
                         String fieldName3 = fieldSet2.getString(CmnConst.FIELD_NAME);
-                        if(parenUuid2.equals(parenUuid3) && !BaseUtil.strIsNull(fieldName3)){
+                        if(curParenAttrUuid.equals(parenUuid3) && !BaseUtil.strIsNull(fieldName3)){
                             keys.add(fieldName3);
-                            keys2.add(fieldSet2.getString("attribute_name"));
+                            keys2.add(fieldSet2.getString(CmnConst.ATTRIBUTE_NAME));
                         }else {
                             break;
                         }
@@ -182,21 +197,21 @@
                         propertyObject.put(parentAttributeName, this.attributesAndValues(valueData, keys, keys2, type));
                     }
                 }else {
-                    propertyObject.put(attribute_name,changeDataFormat(attr_value)[0]);
+                    propertyObject.put(attrName, changeDataFormat(attrValue)[0]);
                 }
                 if(i == (length - 1)){
                     //灏佽鏈�鍚庝竴缁勬暟鎹�
-                    this.getAllProperties(parenUuid1,propertyObject,allProperties);
+                    this.getAllJSONAttrs(preParenAttrUuid, propertyObject, allProperties);
                 }
             }
         }
-        JSONObject s=new JSONObject();
+
         //鍥捐〃杈硅窛
+//        JSONObject s=new JSONObject();
 //        s.put("bottom",30);
 //        s.put("left",30);
 //        s.put("right",0);
 //        allProperties.put("grid",s);
-        String typeGroup = typeField.getString(CmnConst.TYPE_GROUP);
         JSONObject object = BaseUtil.fieldSetEntityToJson(fse);
         object.put(CmnConst.TYPE,typeGroup);
         object.put(CmnConst.OPTION,allProperties);
@@ -206,38 +221,35 @@
 
     /**
      * 鑾峰彇涓婄骇鏁版嵁骞堕�掑綊鎷艰涓婄骇灞炴��
-     * @param superiorUuid 涓婄骇uuid
-     * @param obj
+     * @param superiorAttrUUID		涓婄骇灞炴�UID
+     * @param noSuperiorJsonAttr	鏈皝瑁呬笂绾х殑JSON灞炴��
+     * @param allProperties			鍥捐〃鎬籎SON灞炴��
      * @return
      * @throws BaseException
      */
     @Override
-    public void getAllProperties(String superiorUuid,JSONObject obj,JSONObject allProperties) throws BaseException {
-        FieldSetEntity fieldSet = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_REPORT_TYPE_ATTRIBUTE,superiorUuid,false);
-        String attribute_name = fieldSet.getString("attribute_name");
+    public void getAllJSONAttrs(String superiorAttrUUID, JSONObject noSuperiorJsonAttr, JSONObject allProperties) throws BaseException {
+    	// 鑾峰彇鏇撮珮绾х埗绾у睘鎬�
+        FieldSetEntity fseAttrInfo = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_REPORT_TYPE_ATTRIBUTE, superiorAttrUUID, false);
+        String attribute_name = fseAttrInfo.getString(CmnConst.ATTRIBUTE_NAME);
         JSONObject superiorObj = new JSONObject();
-        JSONArray objSubArray = obj.getJSONArray(attribute_name);
-        //纭畾浠栫殑瀛愬睘鎬ф椂(1)array 杩樻槸(0)object
-//        if(objSubArray == null){
-            if ("1".equals(fieldSet.getString("subordinateElementType"))) {
-                JSONArray array = new JSONArray();
-                array.add(obj);
-                superiorObj.put(attribute_name, array);
-            } else {
-                superiorObj.put(attribute_name, obj);
-            }
-//        }else if(objSubArray != null){
-//            superiorObj = obj;
-//        }
-        //涓婄骇灞炴�ame
-        superiorUuid = fieldSet.getString("parentAttributeUuid");
-        //涓婄骇鍚嶇О
-        String parentAttributeName = fieldSet.getString("parentAttributeName");
+        // 鍒ゅ畾灞炴�у�兼槸Object鏁扮粍杩樻槸Object瀵硅薄锛堝嵆瀛愬睘鎬ф槸瀵硅薄杩樻槸鏁扮粍锛�0涓簅bj瀵硅薄锛�1涓篴rray鏁扮粍锛�
+        if ("1".equals(fseAttrInfo.getString(CmnConst.SUBORDINATE_ELEMENT_TYPE))) {
+        	JSONArray array = new JSONArray();
+        	array.add(noSuperiorJsonAttr);
+        	superiorObj.put(attribute_name, array);
+//        	superiorObj.put(attribute_name, Arrays.asList(noSuperiorJsonAttr));
+        } else {
+        	superiorObj.put(attribute_name, noSuperiorJsonAttr);
+        }
+        // 鑾峰彇褰撳墠灞炴�х埗绾у睘鎬UID 鍜� NAME
+        superiorAttrUUID = fseAttrInfo.getString(CmnConst.PARENT_ATTRIBUTE_UUID);
+        String parentAttributeName = fseAttrInfo.getString(CmnConst.PARENT_ATTRIBUTE_NAME);
         //濡傛灉鐖跺厓绱爑uid涓虹┖
-        if(BaseUtil.strIsNull(superiorUuid)){
+        if(BaseUtil.strIsNull(superiorAttrUUID)){
             JSONArray allSubProperties = allProperties.getJSONArray(attribute_name);
             if(allSubProperties != null){
-                JSONObject subObj = JSONObject.parseObject(obj.toJSONString());
+                JSONObject subObj = JSONObject.parseObject(noSuperiorJsonAttr.toJSONString());
                 if(allSubProperties.size() > 0){
                     //鏄墿鍏呭綋鍓嶅瓙鍏冪礌  杩樻槸鍚岀骇鏂板涓�涓瓙鍏冪礌
                     Boolean is_extend = true;
@@ -257,23 +269,21 @@
                         for (String key :subObj.keySet()) {
                             subPropertiesJSONObject.put(key, subObj.get(key));
                         }
-                        obj.clear();
+                        noSuperiorJsonAttr.clear();
                         return;
                     }
                     }
                 allSubProperties.add(subObj);
-                obj.clear();
+                noSuperiorJsonAttr.clear();
                 return;
             }
-            //鍏嬮殕json
-            JSONObject copy;
             Object o = superiorObj.get(attribute_name);
             if(o instanceof JSONArray){
                 JSONArray oar = (JSONArray) o;
                 JSONArray arr = JSONObject.parseArray(oar.toJSONString());
                 allProperties.put(attribute_name,arr);
             }else {
-                copy = JSONObject.parseObject(superiorObj.toJSONString());
+            	JSONObject copy = JSONObject.parseObject(superiorObj.toJSONString());
                 allProperties.put(attribute_name,copy.getJSONObject(attribute_name));
             }
         }else {
@@ -294,7 +304,7 @@
                         }
                     }
                 }
-                 this.getAllProperties(superiorUuid,newObj,allProperties);
+                 this.getAllJSONAttrs(superiorAttrUUID, newObj, allProperties);
             }else {
                 JSONObject currentProperty = null;
                 if(o instanceof JSONArray) {
@@ -338,7 +348,7 @@
                 }
             }
         }
-        obj.clear();
+        noSuperiorJsonAttr.clear();
     }
 
     /**
@@ -527,8 +537,14 @@
      */
     @Transactional
     @Override
-    public List<String> releaseConfig(FieldSetEntity fse, String module_uuid, String parentCode) {
+    public List<String> releaseConfig(FieldSetEntity fse, String parentModuleUUID) {
 
+    	//鑾峰彇鎸囧畾鍙戝竷鐩綍淇℃伅
+    	FieldSetEntity fseParentModuleData = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_FUNCTIONS, parentModuleUUID, false);
+    	if (fseParentModuleData == null) {
+			throw new BaseException(SystemCode.PUBLISH_REPORT_FAIL_MODULE_NO_EXIST.getValue(), SystemCode.PUBLISH_REPORT_FAIL_MODULE_NO_EXIST.getText());
+		}
+    	
         FieldSetEntity fseReport=baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_REPORT_CONFIG, fse.getUUID(), false);
 
         //鍒涘缓MVCC淇濆瓨瀵硅薄
@@ -536,11 +552,10 @@
         fseFunction.setTableName(CmnConst.PRODUCT_SYS_FUNCTIONS);
         //1.鍒涘缓MVC(绯荤粺MVC鐩綍涓�)
         //鐢熸垚鍔熻兘缂栫爜
-        codeService.createCode(fseFunction,CmnConst.PRODUCT_SYS_FUNCTIONS, CmnConst.TRICODE, parentCode);
+        codeService.createCode(fseFunction,CmnConst.PRODUCT_SYS_FUNCTIONS, CmnConst.TRICODE, fseParentModuleData.getString(CmnConst.TRICODE));
         String function_tricode=fseFunction.getString(CmnConst.TRICODE);
         fseFunction.setTableName(CmnConst.PRODUCT_SYS_FUNCTIONS);
         fseFunction.setValue(CmnConst.TRICODE, function_tricode);		//鍔熻兘缂栫爜
-        fseFunction.setValue(CmnConst.MODULE_UUID, module_uuid);	//鎵�灞炴ā鍧桿UID
         fseFunction.setValue(CmnConst.TABLE_UUID, CmnConst.PRODUCT_SYS_REPORT_CONFIG);			//鍔熻兘鍏宠仈琛�
         fseFunction.setValue(CmnConst.FUNCTION_NAME, fseReport.getString(CmnConst.REPORT_NAME));	//鍔熻兘鍚嶇О
         fseFunction.setValue(CmnConst.FUNCTION_DESCRIPTION, fseReport.getString(CmnConst.REPORT_NAME));	//鍔熻兘鎻忚堪
@@ -548,7 +563,7 @@
         fseFunction.setValue(CmnConst.FUNCTION_TYPE_UUID, 1);	//鍔熻兘绫诲瀷-涓氬姟鍔熻兘
         fseFunction.setValue(CmnConst.CLIENT_TYPE_UUID, "web");		//瀹㈡埛绔被鍨�
         fseFunction.setValue(CmnConst.VERSION_UUID, "001"); //鐗堟湰uuid
-        fseFunction.setValue(CmnConst.TRICODE_PARENT, parentCode);
+        fseFunction.setValue(CmnConst.TRICODE_PARENT, fseParentModuleData.getString(CmnConst.TRICODE));
         fseFunction.setValue("data_type", 1); //绫诲瀷  1涓哄姛鑳�
         BaseUtil.createCreatorAndCreationTime(SpringMVCContextHolder.getCurrentUser(), fseFunction);
 

--
Gitblit v1.9.2