Kaynağa Gözat

代码样式调整

user5 2 yıl önce
ebeveyn
işleme
e0d9f449d2

+ 96 - 83
jeeplus-plugins/jeeplus-flowable/src/main/java/com/jeeplus/centerservice/utils/GenerateFormUtil.java

@@ -309,95 +309,103 @@ public class GenerateFormUtil {
             // 为防止数据又重新排序,所以在这里转换时使用Feature.OrderedField来解决此问题
             LinkedHashMap<String,Object> key = JSONObject.parseObject(k, LinkedHashMap.class, Feature.OrderedField);
             String type = key.get("type").toString(); // 表单类型
-            if ("input".equals(type)) { // 单行文本
-                boolean createNew = true; // 是否创建新的栅栏,放入col_12的input
-                if (formList.size() > 0) { // 表单列表已经有表单,则进入如下操作
-                    // 获取表单列表中最后一个表单
-                    Map<String, Object> lastForm = formList.get(formList.size() - 1);
-                    // 判断最后一个表单是否为栅栏
-                    if ("grid".equals(lastForm.get("type").toString())) {
-                        int size = Integer.parseInt(lastForm.get("size").toString()); // 获取栅栏中元素的占位
-                        List<Object> gridColumns = JSONArray.parseArray(JSON.toJSONString(lastForm.get("columns")));
-                        if (size == 12) { // 元素的占位是12,则不创建新的栅栏,直接放入col_12的input
-                            Map<String, Object> newGrid = setCol_12_Input(lastForm,gridColumns,key,v);
-                            formList.set(formList.size() - 1, newGrid);
-                            createNew = false;
+            switch (type) {
+                case "input": // 单行文本
+                    boolean createNew = true; // 是否创建新的栅栏,放入col_12的input
+                    if (formList.size() > 0) { // 表单列表已经有表单,则进入如下操作
+                        // 获取表单列表中最后一个表单
+                        Map<String, Object> lastForm = formList.get(formList.size() - 1);
+                        // 判断最后一个表单是否为栅栏
+                        if ("grid".equals(lastForm.get("type").toString())) {
+                            int size = Integer.parseInt(lastForm.get("size").toString()); // 获取栅栏中元素的占位
+                            List<Object> gridColumns = JSONArray.parseArray(JSON.toJSONString(lastForm.get("columns")));
+                            if (size == 12) { // 元素的占位是12,则不创建新的栅栏,直接放入col_12的input
+                                Map<String, Object> newGrid = setCol_12_Input(lastForm,gridColumns,key,v);
+                                formList.set(formList.size() - 1, newGrid);
+                                createNew = false;
+                            }
                         }
                     }
-                }
-                if (createNew) { // createNew为true,表示需要创建新的栅栏,放入col_12的input
-                    Map<String, Object> newGrid = setCol_12_Input(createGrid(),new ArrayList<>(),key,v);
+                    if (createNew) { // createNew为true,表示需要创建新的栅栏,放入col_12的input
+                        Map<String, Object> newGrid = setCol_12_Input(createGrid(),new ArrayList<>(),key,v);
+                        formList.add(newGrid);
+                    }
+                    break;
+                case "textarea": // 多行文本
+                    Map<String, Object> newGrid = setCol_24_Textarea(createGrid(), new ArrayList<>(), key, v);
                     formList.add(newGrid);
-                }
-            } else if ("textarea".equals(type)) { // 多行文本
-                Map<String, Object> newGrid = setCol_24_Textarea(createGrid(), new ArrayList<>(), key, v);
-                formList.add(newGrid);
-            } else if ("table".equals(type)) { // 子表单,也就是表格
-                Map<String, Object> divider = createDivider(); // 开始创建分割线
-                if (ObjectUtil.isNotEmpty(key.get("label"))) {
-                    divider.put("name", key.get("label").toString());
-                } else {
-                    divider.put("name", "详情列表");
-                }
-                formList.add(divider); // 添加分割线
-                Map<String, Object> table = createTable(); // 开始创建表格
-                List<Map<String, Object>> tableColumnList = new ArrayList<>();
-                // 表头获取
-                LinkedHashMap<String, Object> tableColumnsMap = JSONObject.parseObject(JSON.toJSONString(key.get("tableColumns")), LinkedHashMap.class, Feature.OrderedField);
-                tableColumnsMap.forEach((columnKey,columnValue) -> {
-                    Map<String, Object> text = createText();
-                    text.put("name",columnValue.toString()); // 列头的名称
-                    text.put("model",columnKey); // 列表数据绑定的字段
-                    String textWidth = getTextWidthByValue(columnKey,v); // 根据该列下的值来判断此列的宽度应该设置为多少
-                    if (StringUtils.isNotBlank(textWidth)) {
-                        Map<String,Object> textOptionsMap = JSONObject.parseObject(JSON.toJSONString(text.get("options")), Map.class);
-                        textOptionsMap.put("width",textWidth); // 设置当前列的宽度
-                        text.put("options",textOptionsMap);
+                    break;
+                case "table": // 子表单,也就是表格
+                    Map<String, Object> divider = createDivider(); // 开始创建分割线
+                    if (ObjectUtil.isNotEmpty(key.get("label"))) {
+                        divider.put("name", key.get("label").toString());
+                    } else {
+                        divider.put("name", "详情列表");
                     }
-                    tableColumnList.add(text);
-                });
-                table.put("tableColumns",tableColumnList);
-                // 列表数据
-                List<Map<String, Object>> defaultValues = JSONArray.parseArray(JSON.toJSONString(v)); // 通过集合中map的key对应表头的model来进行数据的绑定
-                Map<String, Object> optionsMap = JSONObject.parseObject(JSON.toJSONString(table.get("options")));
-                optionsMap.put("defaultValue",defaultValues); // 绑定列表的数据
-                table.put("options",optionsMap);
-                // 表格
-                formList.add(table);
-            } else if ("files".equals(type)) { // 附件
-                if (ObjectUtil.isNotEmpty(key.get("label"))) {
-                    respMap.put("filesLabel",key.get("label").toString()); // 附件label
-                } else {
-                    respMap.put("filesLabel","附件"); // 附件label
-                }
-                List<WorkAttachmentDto> files = new ArrayList<>();
-                if (ObjectUtil.isNotEmpty(v)) {
-                    List<Map<String, Object>> fileList = JSONArray.parseArray(JSON.toJSONString(v));
-                    for (Map<String, Object> fileMap : fileList) {
-                        WorkAttachmentDto attachmentDto = new WorkAttachmentDto();
-                        UserDTO userDTO = new UserDTO();
-                        if (ObjectUtil.isNotEmpty(fileMap.get("attachmentName"))) { // 附件名称
-                            attachmentDto.setName(fileMap.get("attachmentName").toString());
-                        }
-                        if (ObjectUtil.isNotEmpty(fileMap.get("createName"))) { // 创建人
-                            userDTO.setName(fileMap.get("createName").toString());
-                        }
-                        if (ObjectUtil.isNotEmpty(fileMap.get("createDate"))) { // 创建时间
-                            attachmentDto.setCreateDate(DateUtil.parse(fileMap.get("createDate").toString()));
+                    formList.add(divider); // 添加分割线
+                    Map<String, Object> table = createTable(); // 开始创建表格
+                    List<Map<String, Object>> tableColumnList = new ArrayList<>();
+                    // 表头获取
+                    LinkedHashMap<String, Object> tableColumnsMap = JSONObject.parseObject(JSON.toJSONString(key.get("tableColumns")), LinkedHashMap.class, Feature.OrderedField);
+                    tableColumnsMap.forEach((columnKey,columnValue) -> {
+                        Map<String, Object> text = createText();
+                        text.put("name",columnValue.toString()); // 列头的名称
+                        text.put("model",columnKey); // 列表数据绑定的字段
+                        String textWidth = getTextWidthByValue(columnKey,v); // 根据该列下的值来判断此列的宽度应该设置为多少
+                        if (StringUtils.isNotBlank(textWidth)) {
+                            Map<String,Object> textOptionsMap = JSONObject.parseObject(JSON.toJSONString(text.get("options")), Map.class);
+                            textOptionsMap.put("width",textWidth); // 设置当前列的宽度
+                            text.put("options",textOptionsMap);
                         }
-                        if (ObjectUtil.isNotEmpty(fileMap.get("url"))) { // 文件地址
-                            attachmentDto.setUrl(fileMap.get("url").toString());
-                        }
-                        if (ObjectUtil.isNotEmpty(fileMap.get("temporaryUrl"))) { // 文件临时地址
-                            attachmentDto.setLsUrl(fileMap.get("temporaryUrl").toString());
+                        tableColumnList.add(text);
+                    });
+                    table.put("tableColumns",tableColumnList);
+                    // 列表数据
+                    List<Map<String, Object>> defaultValues = JSONArray.parseArray(JSON.toJSONString(v)); // 通过集合中map的key对应表头的model来进行数据的绑定
+                    Map<String, Object> optionsMap = JSONObject.parseObject(JSON.toJSONString(table.get("options")));
+                    optionsMap.put("defaultValue",defaultValues); // 绑定列表的数据
+                    table.put("options",optionsMap);
+                    // 表格
+                    formList.add(table);
+                    break;
+                case "files": // 附件
+                    if (ObjectUtil.isNotEmpty(key.get("label"))) {
+                        respMap.put("filesLabel",key.get("label").toString()); // 附件label
+                    } else {
+                        respMap.put("filesLabel","附件"); // 附件label
+                    }
+                    List<WorkAttachmentDto> files = new ArrayList<>();
+                    if (ObjectUtil.isNotEmpty(v)) {
+                        List<Map<String, Object>> fileList = JSONArray.parseArray(JSON.toJSONString(v));
+                        for (Map<String, Object> fileMap : fileList) {
+                            WorkAttachmentDto attachmentDto = new WorkAttachmentDto();
+                            UserDTO userDTO = new UserDTO();
+                            if (ObjectUtil.isNotEmpty(fileMap.get("attachmentName"))) { // 附件名称
+                                attachmentDto.setName(fileMap.get("attachmentName").toString());
+                            }
+                            if (ObjectUtil.isNotEmpty(fileMap.get("createName"))) { // 创建人
+                                userDTO.setName(fileMap.get("createName").toString());
+                            }
+                            if (ObjectUtil.isNotEmpty(fileMap.get("createDate"))) { // 创建时间
+                                attachmentDto.setCreateDate(DateUtil.parse(fileMap.get("createDate").toString()));
+                            }
+                            if (ObjectUtil.isNotEmpty(fileMap.get("url"))) { // 文件地址
+                                attachmentDto.setUrl(fileMap.get("url").toString());
+                            }
+                            if (ObjectUtil.isNotEmpty(fileMap.get("temporaryUrl"))) { // 文件临时地址
+                                attachmentDto.setLsUrl(fileMap.get("temporaryUrl").toString());
+                            }
+                            attachmentDto.setCreateBy(userDTO);
+                            files.add(attachmentDto);
                         }
-                        attachmentDto.setCreateBy(userDTO);
-                        files.add(attachmentDto);
                     }
-                }
-                respMap.put("files",files); // 附件
-            } else if ("processInstanceId".equals(type)) {
-                respMap.put("processInstanceId", v.toString()); // processInstanceId
+                    respMap.put("files",files); // 附件
+                    break;
+                case "processInstanceId":
+                    respMap.put("processInstanceId", v.toString()); // processInstanceId
+                    break;
+                default:
+                    break;
             }
         });
         respMap.put("list",formList); // 表单数据
@@ -405,7 +413,12 @@ public class GenerateFormUtil {
         return respMap;
     }
 
-    // 根据该列下的值来判断此列的宽度应该设置为多少
+    /**
+     * 根据该列下的值来判断此列的宽度应该设置为多少
+     * @param columnKey
+     * @param value
+     * @return
+     */
     public static String getTextWidthByValue(Object columnKey,Object value) {
         String column = columnKey.toString();
         AtomicReference<String> width = new AtomicReference<>("");