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/config/FaceConst.java | 5 src/main/java/com/product/face/service/FaceApplyService.java | 86 ++++++ src/main/java/com/product/face/service/FaceDesignService.java | 494 +++++++++++++++++++------------------ src/main/java/com/product/face/controller/FaceApplyController.java | 74 +++++ src/main/java/com/product/face/entity/TableColumn.java | 49 +++ src/main/java/com/product/face/config/ErrorCode.java | 48 ++- 6 files changed, 481 insertions(+), 275 deletions(-) diff --git a/src/main/java/com/product/face/config/ErrorCode.java b/src/main/java/com/product/face/config/ErrorCode.java index f8c5676..49b8f60 100644 --- a/src/main/java/com/product/face/config/ErrorCode.java +++ b/src/main/java/com/product/face/config/ErrorCode.java @@ -14,34 +14,38 @@ */ public enum ErrorCode implements IEnum { - SAVE_FACE_FAIL("淇濆瓨琛ㄥ崟鍐呭澶辫触", 1), - SAVE_EMPTY_FACE_FAIL("淇濆瓨琛ㄥ崟鍐呭澶辫触,琛ㄥ崟鍐呭涓嶈兘涓虹┖", 2), + SAVE_FACE_FAIL("淇濆瓨琛ㄥ崟鍐呭澶辫触", 1), + SAVE_EMPTY_FACE_FAIL("淇濆瓨琛ㄥ崟鍐呭澶辫触,琛ㄥ崟鍐呭涓嶈兘涓虹┖", 2), - DELETE_FACE_FAIL("鍒犻櫎琛ㄥ崟澶辫触", 3), + DELETE_FACE_FAIL("鍒犻櫎琛ㄥ崟澶辫触", 3), + GET_FACE_COLUMN_FAIL("鑾峰彇鍒楄〃閰嶇疆澶辫触", 4), + GET_FACE_CONFIG_FAIL("鑾峰彇琛ㄥ崟閰嶇疆淇℃伅澶辫触", 5), - ; + REQUEST_PARAM_ERROR("璇锋眰鍙傛暟鏈夎", 6), + + ; - private String text; - private int value; + private String text; + private int value; - ErrorCode(String text, int value) { - this.value = value; - this.text = text; - } + ErrorCode(String text, int value) { + this.value = value; + this.text = text; + } - @Override - public String getText() { - return this.text; - } + @Override + public String getText() { + return this.text; + } - @Override - public String getValue() { - Format f1 = new DecimalFormat("000"); - return ModuleEnum.PRINT.getValue() + f1.format(this.value); - } + @Override + public String getValue() { + Format f1 = new DecimalFormat("000"); + return ModuleEnum.PRINT.getValue() + f1.format(this.value); + } - public void throwException() { - throw new BaseException(this); - } + public void throwException() { + throw new BaseException(this); + } } diff --git a/src/main/java/com/product/face/config/FaceConst.java b/src/main/java/com/product/face/config/FaceConst.java index 46ee967..44c045a 100644 --- a/src/main/java/com/product/face/config/FaceConst.java +++ b/src/main/java/com/product/face/config/FaceConst.java @@ -17,7 +17,10 @@ public static final String CHILDREN = "children"; - public static final String FIELD_CONFIG = "__config__"; + //鎺т欢缁戝畾瀛楁鍚嶇殑灞炴�у悕绉� + public static final String FIELD_PROPERTY_CONFIG = "__config__"; + public static final String FIELD_PROPERTY_VMODEL = "__vModel__"; + public static final String FIELD_PROPERTY_LABEL = "label"; public static final String FIELD_MASTER = "master_uuid"; //鎺т欢琛ㄥ睘鎬у悕瀛楁 diff --git a/src/main/java/com/product/face/controller/FaceApplyController.java b/src/main/java/com/product/face/controller/FaceApplyController.java new file mode 100644 index 0000000..003502c --- /dev/null +++ b/src/main/java/com/product/face/controller/FaceApplyController.java @@ -0,0 +1,74 @@ +package com.product.face.controller; + +import com.product.core.entity.FieldSetEntity; +import com.product.core.exception.BaseException; +import com.product.core.spring.context.SpringMVCContextHolder; +import com.product.face.config.ErrorCode; +import com.product.face.config.FaceConst; +import com.product.face.service.FaceApplyService; +import com.product.module.sys.version.ApiVersion; +import com.product.util.BaseUtil; +import com.product.util.support.AbstractBaseController; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; + +/** + * @Author cheng + * @Date 2023/5/17 10:17 + * @Desc 琛ㄥ崟搴旂敤鎺у埗灞� + */ +@RestController +@RequestMapping("/api/face/apply") +public class FaceApplyController extends AbstractBaseController { + + @Resource + private FaceApplyService faceApplyService; + + /** + * 鑾峰彇琛ㄦ牸鍒楅厤缃� + * + * @param request + * @return + */ + @PostMapping("/get-list-column/{version}") + @ApiVersion(1) + public String getListColumn(HttpServletRequest request) { + try { + FieldSetEntity fse = BaseUtil.getFieldSetEntity(request, FaceConst.TABLE_FACE_CONFIG); + return success(faceApplyService.getFaceListConf(fse)); + } catch (BaseException e) { + e.printStackTrace(); + return error(e); + } catch (Exception e) { + e.printStackTrace(); + SpringMVCContextHolder.getSystemLogger().error(e); + return error(ErrorCode.GET_FACE_COLUMN_FAIL, e); + } + } + + /** + * 褰曞叆琛ㄥ崟鑾峰彇閰嶇疆 + * + * @param request + * @return + */ + @PostMapping("/get-form-conf/{version}") + @ApiVersion(1) + public String getFormConf(HttpServletRequest request) { + try { + FieldSetEntity fse = BaseUtil.getFieldSetEntity(request, FaceConst.TABLE_FACE_CONFIG); + return faceApplyService.getFaceFormConfig(fse); + } catch (BaseException e) { + e.printStackTrace(); + return error(e); + } catch (Exception e) { + e.printStackTrace(); + SpringMVCContextHolder.getSystemLogger().error(e); + return error(ErrorCode.GET_FACE_CONFIG_FAIL, e); + } + } +} diff --git a/src/main/java/com/product/face/entity/TableColumn.java b/src/main/java/com/product/face/entity/TableColumn.java new file mode 100644 index 0000000..db127ae --- /dev/null +++ b/src/main/java/com/product/face/entity/TableColumn.java @@ -0,0 +1,49 @@ +package com.product.face.entity; + +import java.io.Serializable; + +/** + * @Author cheng + * @Date 2023/5/17 10:13 + * @Desc 琛ㄦ牸鍒� + */ +public class TableColumn implements Serializable { + + private static final long serialVersionUID = -2568367952209207590L; + /** + * 鍒楃粦瀹氬瓧娈靛悕 + */ + private String field; + /** + * 鍒楁爣棰� + */ + private String title; + /** + * 鍒楀搴� + */ + private String columnWidth; + + public String getField() { + return field; + } + + public void setField(String field) { + this.field = field; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getColumnWidth() { + return columnWidth; + } + + public void setColumnWidth(String columnWidth) { + this.columnWidth = columnWidth; + } +} 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); } } diff --git a/src/main/java/com/product/face/service/FaceDesignService.java b/src/main/java/com/product/face/service/FaceDesignService.java index f6d043a..2fc74e1 100644 --- a/src/main/java/com/product/face/service/FaceDesignService.java +++ b/src/main/java/com/product/face/service/FaceDesignService.java @@ -38,266 +38,270 @@ public class FaceDesignService extends AbstractBaseService implements IFaceDesignService { - @Resource - private PublicService publicService; + @Resource + public PublicService publicService; - /** - * 鑾峰彇琛ㄥ崟閰嶇疆璇︽儏 - * - * @param uuid - * @return - * @throws BaseException - */ - @Override - public String getFaceConfigInfo(String uuid) throws BaseException { - FieldSetEntity fse = getBaseDao().getFieldSetEntity(FaceConst.TABLE_FACE_CONFIG, uuid, true); - DataTableEntity fieldPropertyDt = fse.getSubDataTable(FaceConst.TABLE_FACE_FIELD_CONTROL_PROPERTY); - if (DataTableEntity.isEmpty(fieldPropertyDt)) { - return null; - } - List<JSONObject> result = new ArrayList<>(); - List<FieldSetEntity> data = fieldPropertyDt.getData(); - Map<String, List<FieldSetEntity>> collect = data.stream() - .filter(item -> StringUtils.isEmpty(item.getString(FaceConst.FIELD_PARENT_UUID))) //杩囨护 鍙栫埗绾� + /** + * 鑾峰彇琛ㄥ崟閰嶇疆璇︽儏 + * + * @param uuid + * @return + * @throws BaseException + */ + @Override + public String getFaceConfigInfo(String uuid) throws BaseException { + FieldSetEntity fse = getBaseDao().getFieldSetEntity(FaceConst.TABLE_FACE_CONFIG, uuid, true); + DataTableEntity fieldPropertyDt = fse.getSubDataTable(FaceConst.TABLE_FACE_FIELD_CONTROL_PROPERTY); + if (DataTableEntity.isEmpty(fieldPropertyDt)) { + throw new BaseException(ErrorCode.GET_FACE_CONFIG_FAIL); + } + List<JSONObject> result = getFaceControlList(fieldPropertyDt); + Map<String, Object> other = new HashMap<>(); + other.put("drawingList", result); + fse.getSubData().clear(); + return BaseUtil.success(fse, other); + } + + public List<JSONObject> getFaceControlList(DataTableEntity faceControlDt) { + List<JSONObject> result = new ArrayList<>(); + List<FieldSetEntity> data = faceControlDt.getData(); + Map<String, List<FieldSetEntity>> collect = data.stream() + .filter(item -> StringUtils.isEmpty(item.getString(FaceConst.FIELD_PARENT_UUID))) //杩囨护 鍙栫埗绾� // .sorted(Comparator.comparing(item -> item.getInteger(FaceConst.CONTROL_SEQUENCE))) //鎺掑簭 - .collect(Collectors.groupingBy(item -> item.getString(FaceConst.FIELD_GROUP_UUID))); //鍒嗙粍 - Map<String, List<FieldSetEntity>> groupContainer = data.stream() - .filter(item -> !StringUtils.isEmpty(item.getString(FaceConst.FIELD_PARENT_UUID))) //杩囨护 鍙栧瓙绾� - .collect(Collectors.groupingBy(item -> item.getString(FaceConst.FIELD_PARENT_UUID))); //鍒嗙粍 - for (Map.Entry<String, List<FieldSetEntity>> entry : collect.entrySet()) { - List<FieldSetEntity> propertyList = entry.getValue(); - result.add(getPropertyJson(propertyList, groupContainer)); - } - result.sort(Comparator.comparing(item -> item.getInteger(FaceConst.CONTROL_SEQUENCE))); - System.out.println(result); - Map<String, Object> other = new HashMap<>(); - other.put("drawingList", result); - fse.getSubData().clear(); - return BaseUtil.success(fse, other); - } + .collect(Collectors.groupingBy(item -> item.getString(FaceConst.FIELD_GROUP_UUID))); //鍒嗙粍 + Map<String, List<FieldSetEntity>> groupContainer = data.stream() + .filter(item -> !StringUtils.isEmpty(item.getString(FaceConst.FIELD_PARENT_UUID))) //杩囨护 鍙栧瓙绾� + .collect(Collectors.groupingBy(item -> item.getString(FaceConst.FIELD_PARENT_UUID))); //鍒嗙粍 + for (Map.Entry<String, List<FieldSetEntity>> entry : collect.entrySet()) { + List<FieldSetEntity> propertyList = entry.getValue(); + result.add(getPropertyJson(propertyList, groupContainer)); + } + result.sort(Comparator.comparing(item -> item.getInteger(FaceConst.CONTROL_SEQUENCE))); + return result; + } - private JSONObject getPropertyJson(List<FieldSetEntity> propertyList, Map<String, List<FieldSetEntity>> groupContainer) { - JSONObject property = new JSONObject(); - String propertyValue = null; - if (!CollectionUtil.isEmpty(propertyList)) { - for (FieldSetEntity fs : propertyList) { - //灞炴�х被鍨� 1 - String groupUuid = fs.getUUID(); - String propertyType = fs.getString(FaceConst.FIELD_PROPERTY_TYPE); - String propertyName = fs.getString(FaceConst.FIELD_PROPERTY_NAME); - propertyValue = fs.getString(FaceConst.FIELD_PROPERTY_VALUE); - switch (propertyType) { - case "1"://瀛楃涓� - property.put(propertyName, propertyValue); - break; - case "2"://鏁扮粍 - property.put(propertyName, propertyValue.split(",")); - break; - case "3"://瀛愮骇瀵硅薄 - try { - JSONObject propertyJson = getPropertyJson(groupContainer.get(groupUuid), groupContainer); - property.put(propertyName, propertyJson); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - break; - case "4"://瀛愮骇鏁扮粍瀵硅薄 - List<FieldSetEntity> propertyListChild = groupContainer.get(groupUuid); - if (propertyListChild != null && !propertyListChild.isEmpty()) { - List<Object> array = propertyListChild.stream() - .collect(Collectors.groupingBy(item -> item.getString(FaceConst.FIELD_GROUP_UUID))) - .values().stream().map(item -> getPropertyJson(item, groupContainer)).sorted(Comparator.comparing(item -> item.getInteger(FaceConst.CONTROL_SEQUENCE))).collect(Collectors.toList()); - property.put(propertyName, new JSONArray(array)); - } + private JSONObject getPropertyJson(List<FieldSetEntity> propertyList, Map<String, List<FieldSetEntity>> groupContainer) { + JSONObject property = new JSONObject(); + String propertyValue = null; + if (!CollectionUtil.isEmpty(propertyList)) { + for (FieldSetEntity fs : propertyList) { + //灞炴�х被鍨� 1 + String groupUuid = fs.getUUID(); + String propertyType = fs.getString(FaceConst.FIELD_PROPERTY_TYPE); + String propertyName = fs.getString(FaceConst.FIELD_PROPERTY_NAME); + propertyValue = fs.getString(FaceConst.FIELD_PROPERTY_VALUE); + switch (propertyType) { + case "1"://瀛楃涓� + property.put(propertyName, propertyValue); + break; + case "2"://鏁扮粍 + property.put(propertyName, propertyValue.split(",")); + break; + case "3"://瀛愮骇瀵硅薄 + try { + JSONObject propertyJson = getPropertyJson(groupContainer.get(groupUuid), groupContainer); + property.put(propertyName, propertyJson); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + break; + case "4"://瀛愮骇鏁扮粍瀵硅薄 + List<FieldSetEntity> propertyListChild = groupContainer.get(groupUuid); + if (propertyListChild != null && !propertyListChild.isEmpty()) { + List<Object> array = propertyListChild.stream() + .collect(Collectors.groupingBy(item -> item.getString(FaceConst.FIELD_GROUP_UUID))) + .values().stream().map(item -> getPropertyJson(item, groupContainer)).sorted(Comparator.comparing(item -> item.getInteger(FaceConst.CONTROL_SEQUENCE))).collect(Collectors.toList()); + property.put(propertyName, new JSONArray(array)); + } // groupContainer.put(groupUuid, array); - break; - case "5": //boolean 绫诲瀷 - Boolean value = null; - if ("1".equals(propertyValue)) { - value = true; - } else if ("0".equals(propertyValue)) { - value = false; - } - property.put(propertyName, value); - break; - case "6":// int 绫诲瀷 - if (NumberUtil.isNumber(propertyValue)) { - property.put(propertyName, NumberUtil.parseInt(propertyValue)); - } - break; - case "7"://double 绫诲瀷 - if (NumberUtil.isDouble(propertyValue)) { - property.put(propertyName, NumberUtil.parseDouble(propertyValue)); - } - break; - } - } - } + break; + case "5": //boolean 绫诲瀷 + Boolean value = null; + if ("1".equals(propertyValue)) { + value = true; + } else if ("0".equals(propertyValue)) { + value = false; + } + property.put(propertyName, value); + break; + case "6":// int 绫诲瀷 + if (NumberUtil.isNumber(propertyValue)) { + property.put(propertyName, NumberUtil.parseInt(propertyValue)); + } + break; + case "7"://double 绫诲瀷 + if (NumberUtil.isDouble(propertyValue)) { + property.put(propertyName, NumberUtil.parseDouble(propertyValue)); + } + break; + } + } + } - if (!StringUtils.isEmpty(propertyValue)) { - Object o = groupContainer.get(propertyValue); - if (o != null) { - if (o instanceof JSONArray) { - ((JSONArray) o).add(property); - } else { - ((JSONObject) o).putAll(property); - groupContainer.remove(propertyValue); - } - } - } - return property; - } + if (!StringUtils.isEmpty(propertyValue)) { + Object o = groupContainer.get(propertyValue); + if (o != null) { + if (o instanceof JSONArray) { + ((JSONArray) o).add(property); + } else { + ((JSONObject) o).putAll(property); + groupContainer.remove(propertyValue); + } + } + } + return property; + } - /** - * 淇濆瓨琛ㄥ崟鍐呭鏁版嵁 - * - * @param fse - * @return - * @throws BaseException - */ - @Override - @Transactional - public FieldSetEntity saveFaceData(FieldSetEntity fse) throws BaseException { - DataTableEntity fields = fse.getSubDataTable(FaceConst.FACE_FIELD); - if (DataTableEntity.isEmpty(fields)) { - ErrorCode.SAVE_EMPTY_FACE_FAIL.throwException(); - } - List<FieldSetEntity> fieldSetEntityList = new ArrayList<>(); - for (int i = 0; i < fields.getRows(); i++) { - fieldSetEntityList.addAll(controlTraverse(new JSONObject((Map) fields.getFieldSetEntity(i).getValues()), null, i)); - } - fse.removeSubData(FaceConst.FACE_FIELD); - BaseUtil.createCreatorAndCreationTime(fse); - fields.setData(fieldSetEntityList); - fse.addSubDataTable(fields); + /** + * 淇濆瓨琛ㄥ崟鍐呭鏁版嵁 + * + * @param fse + * @return + * @throws BaseException + */ + @Override + @Transactional + public FieldSetEntity saveFaceData(FieldSetEntity fse) throws BaseException { + DataTableEntity fields = fse.getSubDataTable(FaceConst.FACE_FIELD); + if (DataTableEntity.isEmpty(fields)) { + ErrorCode.SAVE_EMPTY_FACE_FAIL.throwException(); + } + List<FieldSetEntity> fieldSetEntityList = new ArrayList<>(); + for (int i = 0; i < fields.getRows(); i++) { + fieldSetEntityList.addAll(controlTraverse(new JSONObject((Map) fields.getFieldSetEntity(i).getValues()), null, i)); + } + fse.removeSubData(FaceConst.FACE_FIELD); + BaseUtil.createCreatorAndCreationTime(fse); + fields.setData(fieldSetEntityList); + fse.addSubDataTable(fields); // fse.setValue(FaceConst.FIELD_FACE_TYPE, 2); - if (!StringUtils.isEmpty(fse.getUUID())) { - getBaseDao().delete(FaceConst.TABLE_FACE_FIELD_CONTROL_PROPERTY, "master_uuid=?", new Object[]{fse.getUUID()}); - } - getBaseDao().saveFieldSetEntity(fse); - fse.getSubData().clear(); - return fse; - } + if (!StringUtils.isEmpty(fse.getUUID())) { + getBaseDao().delete(FaceConst.TABLE_FACE_FIELD_CONTROL_PROPERTY, "master_uuid=?", new Object[]{fse.getUUID()}); + } + getBaseDao().saveFieldSetEntity(fse); + fse.getSubData().clear(); + return fse; + } - public List<FieldSetEntity> controlTraverse(Object o, String parentUuid, Integer sequence) { - List<FieldSetEntity> fieldSetList = new ArrayList<>(); - try { - if (o instanceof JSONArray) { - //鏁扮粍 - JSONArray jsonArray = (JSONArray) o; - try { - for (int i = 0; i < jsonArray.size(); i++) { - Object obj = jsonArray.get(i); - fieldSetList.addAll(controlTraverse(obj, parentUuid, i)); - } - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } else { - //json瀵硅薄 - JSONObject property = (JSONObject) o; - String groupUuid = IdUtil.randomUUID(); - for (Map.Entry<String, Object> entry : property.entrySet()) { + public List<FieldSetEntity> controlTraverse(Object o, String parentUuid, Integer sequence) { + List<FieldSetEntity> fieldSetList = new ArrayList<>(); + try { + if (o instanceof JSONArray) { + //鏁扮粍 + JSONArray jsonArray = (JSONArray) o; + try { + for (int i = 0; i < jsonArray.size(); i++) { + Object obj = jsonArray.get(i); + fieldSetList.addAll(controlTraverse(obj, parentUuid, i)); + } + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } else { + //json瀵硅薄 + JSONObject property = (JSONObject) o; + String groupUuid = IdUtil.randomUUID(); + for (Map.Entry<String, Object> entry : property.entrySet()) { - FieldSetEntity fs = getTemplateFieldSet(entry.getKey(), entry.getValue(), groupUuid); - if (fs != null) { - 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)); - fs.remove(FaceConst.FIELD_PROPERTY_VALUE); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - fs.setValue(FaceConst.FIELD_PARENT_UUID, parentUuid); - fieldSetList.add(fs); - } - } - if (sequence != null) { - FieldSetEntity fs = getTemplateFieldSet(FaceConst.CONTROL_SEQUENCE, sequence, groupUuid); - fs.setValue(FaceConst.FIELD_PARENT_UUID, parentUuid); - fieldSetList.add(fs); - } - } - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - return fieldSetList; - } + FieldSetEntity fs = getTemplateFieldSet(entry.getKey(), entry.getValue(), groupUuid); + if (fs != null) { + 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)); + fs.remove(FaceConst.FIELD_PROPERTY_VALUE); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + fs.setValue(FaceConst.FIELD_PARENT_UUID, parentUuid); + fieldSetList.add(fs); + } + } + if (sequence != null) { + FieldSetEntity fs = getTemplateFieldSet(FaceConst.CONTROL_SEQUENCE, sequence, groupUuid); + fs.setValue(FaceConst.FIELD_PARENT_UUID, parentUuid); + fieldSetList.add(fs); + } + } + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + return fieldSetList; + } - /** - * 鑾峰彇妯℃澘FieldSet - * - * @return - */ - private FieldSetEntity getTemplateFieldSet(String propertyName, Object propertyValue, String groupUuid) { - FieldSetEntity fse = new FieldSetEntity(FaceConst.TABLE_FACE_FIELD_CONTROL_PROPERTY); - //璁剧疆鎿嶄綔绫诲瀷涓烘柊澧� - fse.setValue(CoreConst.SYSTEM_DATA_OPERATE_TYPE, CoreConst.SYSTEM_DATA_OPERATE_ADD); - //鎵嬪姩鐢熸垚uuid - fse.setValue(CoreConst.UUID, IdUtil.randomUUID()); - fse.setValue("last_update_time", new Date()); - fse.setValue(FaceConst.FIELD_PROPERTY_NAME, propertyName); - fse.setValue(FaceConst.FIELD_GROUP_UUID, groupUuid); - int properType = 1; - if (propertyValue instanceof JSONArray) { - JSONArray array = (JSONArray) propertyValue; - if (array == null || array.isEmpty()) { - return null; - } - Object object = array.get(0); - if (!(object instanceof JSONObject)) { - //鏅�氭暟缁� 杞负瀛楃涓� - fse.setValue(FaceConst.FIELD_PROPERTY_VALUE, ArrayUtil.join(array.toArray(), ","));//鏈夊瓙绾у璞� - properType = 2; - } else { - //鏈夊瓙绾у璞� - properType = 4; - } - } else if (propertyValue instanceof JSONObject) { - //灞炴�у�兼槸瀵硅薄 - JSONObject value = (JSONObject) propertyValue; - if (value == null || value.isEmpty()) { - return null; - } - properType = 3; - } else { - if (propertyValue == null || StringUtils.isEmpty(propertyValue)) { - return null; - } + /** + * 鑾峰彇妯℃澘FieldSet + * + * @return + */ + private FieldSetEntity getTemplateFieldSet(String propertyName, Object propertyValue, String groupUuid) { + FieldSetEntity fse = new FieldSetEntity(FaceConst.TABLE_FACE_FIELD_CONTROL_PROPERTY); + //璁剧疆鎿嶄綔绫诲瀷涓烘柊澧� + fse.setValue(CoreConst.SYSTEM_DATA_OPERATE_TYPE, CoreConst.SYSTEM_DATA_OPERATE_ADD); + //鎵嬪姩鐢熸垚uuid + fse.setValue(CoreConst.UUID, IdUtil.randomUUID()); + fse.setValue("last_update_time", new Date()); + fse.setValue(FaceConst.FIELD_PROPERTY_NAME, propertyName); + fse.setValue(FaceConst.FIELD_GROUP_UUID, groupUuid); + int properType = 1; + if (propertyValue instanceof JSONArray) { + JSONArray array = (JSONArray) propertyValue; + if (array == null || array.isEmpty()) { + return null; + } + Object object = array.get(0); + if (!(object instanceof JSONObject)) { + //鏅�氭暟缁� 杞负瀛楃涓� + fse.setValue(FaceConst.FIELD_PROPERTY_VALUE, ArrayUtil.join(array.toArray(), ","));//鏈夊瓙绾у璞� + properType = 2; + } else { + //鏈夊瓙绾у璞� + properType = 4; + } + } else if (propertyValue instanceof JSONObject) { + //灞炴�у�兼槸瀵硅薄 + JSONObject value = (JSONObject) propertyValue; + if (value == null || value.isEmpty()) { + return null; + } + properType = 3; + } else { + if (propertyValue == null || StringUtils.isEmpty(propertyValue)) { + return null; + } - if (propertyValue instanceof Boolean) { - properType = 5; - } else if (propertyValue instanceof Integer) { - properType = 6; - } else if (propertyValue instanceof Double) { - properType = 7; - } - fse.setValue(FaceConst.FIELD_PROPERTY_VALUE, propertyValue); - } - fse.setValue(FaceConst.FIELD_PROPERTY_TYPE, properType); - return fse; - } + if (propertyValue instanceof Boolean) { + properType = 5; + } else if (propertyValue instanceof Integer) { + properType = 6; + } else if (propertyValue instanceof Double) { + properType = 7; + } + fse.setValue(FaceConst.FIELD_PROPERTY_VALUE, propertyValue); + } + fse.setValue(FaceConst.FIELD_PROPERTY_TYPE, properType); + return fse; + } - /** - * 鍒犻櫎琛ㄥ崟璁捐 - * - * @param fse - * @throws BaseException - */ - @Override - @Transactional - public void deleteFace(FieldSetEntity fse) throws BaseException { - publicService.delete(fse); - } + /** + * 鍒犻櫎琛ㄥ崟璁捐 + * + * @param fse + * @throws BaseException + */ + @Override + @Transactional + public void deleteFace(FieldSetEntity fse) throws BaseException { + publicService.delete(fse); + } } -- Gitblit v1.9.2