From 07f6af85516f68ba6943c1e4823fc0be4f851be6 Mon Sep 17 00:00:00 2001
From: 许鹏程 <1821349743@qq.com>
Date: 星期三, 17 五月 2023 16:35:16 +0800
Subject: [PATCH] 表单设计器、表单加载

---
 src/main/java/com/product/face/service/FaceApplyService.java |   86 +++++++++++++++++++++++++++++++++++++++---
 1 files changed, 79 insertions(+), 7 deletions(-)

diff --git a/src/main/java/com/product/face/service/FaceApplyService.java b/src/main/java/com/product/face/service/FaceApplyService.java
index c3bcc00..689c4a8 100644
--- a/src/main/java/com/product/face/service/FaceApplyService.java
+++ b/src/main/java/com/product/face/service/FaceApplyService.java
@@ -1,13 +1,25 @@
 package com.product.face.service;
 
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.google.common.collect.Lists;
 import com.product.admin.service.SystemFaceService;
 import com.product.common.lang.StringUtils;
+import com.product.core.entity.DataTableEntity;
 import com.product.core.entity.FieldSetEntity;
+import com.product.core.exception.BaseException;
 import com.product.core.service.support.AbstractBaseService;
+import com.product.face.config.ErrorCode;
 import com.product.face.config.FaceConst;
+import com.product.face.entity.TableColumn;
+import com.product.util.BaseUtil;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
 
 /**
  * @Author cheng
@@ -20,20 +32,80 @@
 	@Resource
 	private SystemFaceService systemFaceService;
 
+	@Resource
+	private FaceDesignService designService;
+
 
 	public Object getFaceListConf(FieldSetEntity fse) {
-		//TODO 浣跨敤鍙樺姩瀹�
 		String faceUuid = fse.getString(FaceConst.FIELD_FACE_UUID);
 		String faceNumber = fse.getString(FaceConst.FIELD_FACE_NUMBER);
-		if (faceNumber == null && faceUuid == null) {
-			return null;
-		}
+		if (StringUtils.isEmpty(faceNumber) && StringUtils.isEmpty(faceUuid)) {
+			throw new BaseException(ErrorCode.REQUEST_PARAM_ERROR);
 
-		if(StringUtils.isEmpty(faceUuid)){
+		}
+		if (!StringUtils.isEmpty(faceUuid) && StringUtils.isEmpty(faceNumber)) {
 			return systemFaceService.getFaceFieldList(faceUuid);
 		}
-		//TODO 浣跨敤琛ㄥ崟璁捐鍣ㄨ璁$殑鍒楄〃杩斿洖
-		return null;
+		//鏍规嵁琛ㄥ崟鍙锋煡璇�
+		FieldSetEntity faceConf = getBaseDao().getFieldSetByFilter(FaceConst.TABLE_FACE_CONFIG, "face_number=?", new Object[]{faceNumber}, true);
+		DataTableEntity fieldPropertyDt = faceConf.getSubDataTable(FaceConst.TABLE_FACE_FIELD_CONTROL_PROPERTY);
+		if (DataTableEntity.isEmpty(fieldPropertyDt)) {
+			throw new BaseException(ErrorCode.GET_FACE_CONFIG_FAIL);
+		}
+		List<JSONObject> faceControlList = designService.getFaceControlList(fieldPropertyDt);
+		JSONObject jsonObject = faceControlList.get(0);
+		if (jsonObject == null || jsonObject.isEmpty()) {
+			throw new BaseException(ErrorCode.GET_FACE_CONFIG_FAIL);
+		}
+		//琛ㄦ牸鍒�
+		JSONArray tableColumns = jsonObject.getJSONObject(FaceConst.FIELD_PROPERTY_CONFIG).getJSONArray(FaceConst.CHILDREN);
+		if (tableColumns == null || tableColumns.isEmpty()) {
+			throw new BaseException(ErrorCode.GET_FACE_CONFIG_FAIL);
+		}
+		List<TableColumn> result = Lists.newArrayList();
+		for (int i = 0; i < tableColumns.size(); i++) {
+			TableColumn tableColumn = new TableColumn();
+			JSONObject columnJson = tableColumns.getJSONObject(i);
+			String fieldName = columnJson.getString(FaceConst.FIELD_PROPERTY_VMODEL);
+			if (StringUtils.isEmpty(fieldName)) {
+				continue;
+			}
+			JSONObject config = columnJson.getJSONObject(FaceConst.FIELD_PROPERTY_CONFIG);
+			Object setWidth = config.get("setWidth");
+			if (!StringUtils.isEmpty(setWidth)) {
+				tableColumn.setColumnWidth(setWidth + "%");
+			}
+			tableColumn.setField(fieldName);
+			tableColumn.setTitle(config.getString(FaceConst.FIELD_PROPERTY_LABEL));
+			result.add(tableColumn);
+		}
+
+		return result;
+	}
+
+	/**
+	 * 褰曞叆琛ㄥ崟鑾峰彇琛ㄥ崟閰嶇疆
+	 *
+	 * @param fse
+	 * @return
+	 * @throws BaseException
+	 */
+	public String getFaceFormConfig(FieldSetEntity fse) throws BaseException {
+		String faceNumber = fse.getString(FaceConst.FIELD_FACE_NUMBER);
+		if (StringUtils.isEmpty(faceNumber)) {
+			throw new BaseException(ErrorCode.REQUEST_PARAM_ERROR);
+		}
+		//鏍规嵁琛ㄥ崟鍙锋煡璇�
+		FieldSetEntity faceConf = getBaseDao().getFieldSetByFilter(FaceConst.TABLE_FACE_CONFIG, "face_number=?", new Object[]{faceNumber}, true);
+		DataTableEntity fieldPropertyDt = faceConf.getSubDataTable(FaceConst.TABLE_FACE_FIELD_CONTROL_PROPERTY);
+		if (DataTableEntity.isEmpty(fieldPropertyDt)) {
+			throw new BaseException(ErrorCode.GET_FACE_CONFIG_FAIL);
+		}
+		List<JSONObject> faceControlList = designService.getFaceControlList(fieldPropertyDt);
+		Map<String, Object> other = new HashMap<>();
+		other.put("drawingList", faceControlList);
+		faceConf.getSubData().clear();
+		return BaseUtil.success(faceConf, other);
 	}
 
 }

--
Gitblit v1.9.2