许鹏程
2024-11-26 29f1a0a5d9bc184fa497a88ec11c37f10a45df92
src/main/java/com/product/face/service/FaceDesignService.java
@@ -6,6 +6,7 @@
import com.alibaba.fastjson.JSONObject;
import com.product.admin.service.PublicService;
import com.product.common.lang.StringUtils;
import com.product.core.cache.DataPoolCacheImpl;
import com.product.core.config.CoreConst;
import com.product.core.entity.DataTableEntity;
import com.product.core.entity.FieldSetEntity;
@@ -17,6 +18,8 @@
import com.product.face.service.ide.IFaceDesignService;
import com.product.face.util.FaceUtil;
import com.product.util.BaseUtil;
import org.apache.poi.hdgf.pointers.Pointer;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@@ -48,13 +51,34 @@
      if (DataTableEntity.isEmpty(fieldPropertyDt)) {
         throw new BaseException(ErrorCode.GET_FACE_CONFIG_FAIL);
      }
      List<JSONObject> result = FaceUtil.getFaceControlList(fieldPropertyDt);
      List<JSONObject> result = FaceUtil.getFaceControlList(fse, fieldPropertyDt);
      Map<String, Object> other = new HashMap<>();
      other.put("drawingList", result);
      DataTableEntity faceCustomField = fse.getSubDataTable("product_sys_face_custom_field");
      if (!DataTableEntity.isEmpty(faceCustomField)) {
         for (int i = 0; i < faceCustomField.getRows(); i++) {
            faceCustomField.setFieldValue(i, "customField", true);
            faceCustomField.setFieldValue(i, "added", true);
         }
         other.put("product_sys_face_custom_field", BaseUtil.dataTableEntityToJson(faceCustomField));
      } else {
         other.put("product_sys_face_custom_field", new String[]{});
      }
      fse.getSubData().clear();
      return BaseUtil.success(fse, other);
   }
   public class Pointer {
      int data = 0;
      public int getData() {
         return ++data;
      }
      public void setData(int data) {
         this.data = data;
      }
   }
   /**
    * 保存表单内容数据
@@ -71,8 +95,17 @@
         ErrorCode.SAVE_EMPTY_FACE_FAIL.throwException();
      }
      List<FieldSetEntity> fieldSetEntityList = new ArrayList<>();
      //声明一个带指针的int变量
      Pointer pointer = new Pointer();
      for (int i = 0; i < fields.getRows(); i++) {
         fieldSetEntityList.addAll(controlTraverse(new JSONObject((Map) fields.getFieldSetEntity(i).getValues()), null, i));
         if (fields.getBoolean(i, "event_property")) {
            DataTableEntity subDataTable = fields.getFieldSetEntity(i).getSubDataTable("event_array");
            if (DataTableEntity.isEmpty(subDataTable)) {
               continue;
            }
            fields.setFieldValue(i, "event_array", BaseUtil.dataTableEntityToJson(subDataTable));
         }
         fieldSetEntityList.addAll(controlTraverse(new JSONObject((Map) fields.getFieldSetEntity(i).getValues()), null, i, pointer));
      }
      fse.removeSubData(FaceConst.FACE_FIELD);
      BaseUtil.createCreatorAndCreationTime(fse);
@@ -82,12 +115,15 @@
      if (!StringUtils.isEmpty(fse.getUUID())) {
         getBaseDao().delete(FaceConst.TABLE_FACE_FIELD_CONTROL_PROPERTY, "master_uuid=?", new Object[]{fse.getUUID()});
      }
      if (StringUtils.isEmpty(fse.getString("terminal_type"))) {
         fse.setValue("terminal_type", 1);
      }
      getBaseDao().saveFieldSetEntity(fse);
      fse.getSubData().clear();
      return fse;
   }
   public List<FieldSetEntity> controlTraverse(Object o, String parentUuid, Integer sequence) {
   public List<FieldSetEntity> controlTraverse(Object o, String parentUuid, Integer sequence, Pointer pointer) {
      List<FieldSetEntity> fieldSetList = new ArrayList<>();
      try {
         if (o instanceof JSONArray) {
@@ -96,7 +132,7 @@
            try {
               for (int i = 0; i < jsonArray.size(); i++) {
                  Object obj = jsonArray.get(i);
                  fieldSetList.addAll(controlTraverse(obj, parentUuid, i));
                  fieldSetList.addAll(controlTraverse(obj, parentUuid, i, pointer));
               }
            } catch (Exception e) {
               e.printStackTrace();
@@ -113,7 +149,7 @@
                  int propertyType = fs.getInteger(FaceConst.FIELD_PROPERTY_TYPE).intValue();
                  if ((4 == propertyType || 3 == propertyType) && (entry.getValue() instanceof JSONArray || entry.getValue() instanceof JSONObject)) {
                     try {
                        fieldSetList.addAll(controlTraverse(entry.getValue(), fs.getUUID(), null));
                        fieldSetList.addAll(controlTraverse(entry.getValue(), fs.getUUID(), null, pointer));
                        fs.remove(FaceConst.FIELD_PROPERTY_VALUE);
                     } catch (Exception e) {
                        e.printStackTrace();
@@ -125,7 +161,7 @@
               }
            }
            if (sequence != null) {
               FieldSetEntity fs = getTemplateFieldSet(FaceConst.CONTROL_SEQUENCE, sequence, groupUuid);
               FieldSetEntity fs = getTemplateFieldSet(FaceConst.CONTROL_SEQUENCE, pointer.getData(), groupUuid);
               fs.setValue(FaceConst.FIELD_PARENT_UUID, parentUuid);
               fieldSetList.add(fs);
            }