格式一
formDate 为单一的
String formDate="{\"input_1648710489626\":\"lkz\",\"input_1648710513450\":\"测试请假表单\"," +
"\"number_1648710548258\":\"3\",\"datetime_1648710573324\":\"2022-04-01\"}";
String formJson="[{\"key\": \"input_1648710489626\", \"hint\": \"请输入姓名\", \"type\": \"input\", \"label\": \"请假人\", " +
"\"model\": \"input_1648710489626\", \"rules\": [{\"message\": \"必填项\", \"required\": false}], " +
"\"options\": {\"type\": \"text\", \"value\": \"\", \"enable\": true, \"visible\": true, \"required\": true," +
" \"visibleType\": \"1\", \"defaultValueType\": \"1\"}, \"labelShow\": true, \"maxLength\": 200, \"widgetName\": \"\"," +
" \"description\": \"\"}, {\"key\": \"input_1648710513450\", \"hint\": \"请输入原因\", \"type\": \"input\", " +
"\"label\": \"请假原因\", \"model\": \"input_1648710513450\", \"rules\": [{\"message\": \"必填项\", \"required\": false}], " +
"\"options\": {\"type\": \"text\", \"value\": \"\", \"enable\": true, \"visible\": true, \"required\": false, " +
"\"visibleType\": \"1\", \"defaultValueType\": \"1\"}, \"labelShow\": true, \"maxLength\": 200, \"widgetName\": \"\", " +
"\"description\": \"\"}, {\"key\": \"number_1648710548258\", \"hint\": \"请输入天数\", \"type\": \"number\", " +
"\"label\": \"请假天数\", \"model\": \"number_1648710548258\", \"rules\": [{\"message\": \"必填项\", \"required\": false}], " +
"\"options\": {\"type\": \"number\", \"value\": \"\", \"enable\": true, \"visible\": true, \"required\": false," +
" \"maxNumber\": 999999999999999, \"minNumber\": -99999999999999, \"precision\": 0, \"displayMode\": \"1\", " +
"\"visibleType\": \"1\", \"showNumRange\": false, \"defaultValueType\": \"1\", \"thousandsSeparator\": false}, " +
"\"labelShow\": true, \"maxLength\": 15, \"widgetName\": \"\", \"description\": \"\"}, {\"key\": \"datetime_1648710573324\", " +
"\"hint\": \"选择时间\", \"type\": \"datetime\", \"label\": \"请假时间\", \"model\": \"datetime_1648710573324\", " +
"\"rules\": [{\"message\": \"必填项\", \"required\": false}], \"options\": {\"type\": \"datetime\", " +
"\"value\": null, \"enable\": true, \"format\": \"yyyy-MM-dd\", \"visible\": true, \"required\": false, " +
"\"showTime\": false, \"isOnyTime\": false, " +
"\"visibleType\": \"1\", \"defaultValueType\": \"1\"}, \"labelShow\": true, \"maxLength\": 20, \"widgetName\": \"\", " +
"\"description\": \"\"}]";
Map<String, Object> list2 = JSONObject.parseObject(formDate, Map.class);
List<JSONObject> formOldJsonList = JSONObject.parseObject(formJson, List.class);
for (JSONObject json : formOldJsonList) {
String key = (String) json.get("key");
boolean b = list2.containsKey(key);
if(b){
String value =(String)list2.get(key);
if (StrUtil.isNotBlank(value)) {
JSONObject jsonValue = (JSONObject) json.get("options");
jsonValue.put("value", value);
continue;
}
}
}
// 单个数组模式
Map<String, Object> formParam = JSONObject.parseObject(formData, Map.class);
for (JSONObject json : formOldJsonList) {
String key = (String) json.get("key");
boolean b = formParam.containsKey(key);
if (b) {
Object o = formParam.get(key);
if (Objects.nonNull(o)) {
JSONObject jsonValue = (JSONObject) json.get("options");
jsonValue.put("value", o);
continue;
}
}
}
System.out.println(formOldJsonList);
格式二
formDate 里面有多个
String formJson="[{\"key\": \"input_1648710489626\", \"hint\": \"请输入姓名\", \"type\": \"input\", " +
"\"label\": \"请假人\", \"model\": \"input_1648710489626\", \"rules\": [{\"message\": \"必填项\"," +
" \"required\": false}], \"options\": {\"type\": \"text\", \"value\": \"\", \"enable\": true, " +
"\"visible\": true, \"required\": true, \"visibleType\": \"1\", \"defaultValueType\": \"1\"}, " +
"\"labelShow\": true, \"maxLength\": 200, \"widgetName\": \"\", \"description\": \"\"}, " +
"{\"key\": \"input_1648710513450\", \"hint\": \"请输入原因\", \"type\": \"input\", \"label\": \"请假原因\", " +
"\"model\": \"input_1648710513450\", \"rules\": [{\"message\": \"必填项\", \"required\": false}], " +
"\"options\": {\"type\": \"text\", \"value\": \"\", \"enable\": true, \"visible\": true, " +
"\"required\": false, \"visibleType\": \"1\", \"defaultValueType\": \"1\"}, \"labelShow\": true, " +
"\"maxLength\": 200, \"widgetName\": \"\", \"description\": \"\"}, {\"key\": \"number_1648710548258\"," +
" \"hint\": \"请输入天数\", \"type\": \"number\", \"label\": \"请假天数\", \"model\": \"number_1648710548258\"," +
" \"rules\": [{\"message\": \"必填项\", \"required\": false}], \"options\": {\"type\": \"number\", \"value\": \"\"," +
" \"enable\": true, \"visible\": true, \"required\": false, \"maxNumber\": 999999999999999, " +
"\"minNumber\": -99999999999999, \"precision\": 0, \"displayMode\": \"1\", \"visibleType\": \"1\"," +
" \"showNumRange\": false, \"defaultValueType\": \"1\", \"thousandsSeparator\": false}, \"labelShow\": true," +
" \"maxLength\": 15, \"widgetName\": \"\", \"description\": \"\"}, {\"key\": \"datetime_1648710573324\", " +
"\"hint\": \"选择时间\", \"type\": \"datetime\", \"label\": \"请假时间\", \"model\": \"datetime_1648710573324\"," +
" \"rules\": [{\"message\": \"必填项\", \"required\": false}], \"options\": {\"type\": \"datetime\"," +
" \"value\": null, \"enable\": true, \"format\": \"yyyy-MM-dd\", \"visible\": true, \"required\": false, " +
"\"showTime\": false, \"isOnyTime\": false, \"visibleType\": \"1\", \"defaultValueType\": \"1\"}," +
" \"labelShow\": true, \"maxLength\": 20, \"widgetName\": \"\", \"description\": \"\"}]";
String formData="[{\"isEdit\":\"false\",\"id\":\"input_1648710489626\",\"isVisibility\":\"true\"}," +
"{\"isEdit\":\"false\",\"id\":\"input_1648710513450\",\"isVisibility\":\"true\"}," +
"{\"isEdit\":\"true\",\"id\":\"number_1648710548258\",\"isVisibility\":\"true\"}," +
"{\"isEdit\":\"true\",\"id\":\"datetime_1648710573324\",\"isVisibility\":\"true\"}]";
List<JSONObject> formOldJsonList = JSONObject.parseObject(formJson, List.class);
// 获取节点修改的表单样式
List<JSONObject> eleFiledOldList = JSONObject.parseObject(str, List.class);
// 循环比较
for (JSONObject st : formOldJsonList) {
String key = (String) st.get("key");
for (JSONObject field : eleFiledOldList) {
String id = (String) field.get(FlowElementExtConstant.FORM_FIELD_ID);
if (key.equals(id)) {
// 取出 field的值 修改 st中对应的是否可编辑值
String isEdit = (String) field.get(FlowElementExtConstant.FORM_FIELD_EDIT);
String isVisible = (String) field.get(FlowElementExtConstant.FORM_FIELD_VISIBILITY);
JSONObject visibleSt = (JSONObject) st.get("options");
visibleSt.put("visible", isVisible);
visibleSt.put("enable", isEdit);
break;
}
}
}
System.out.println(StrUtil.toString(formOldJsonList));
String newJson = JSON.toJSONString(list);
System.out.println(JSON.toJSONString(newJson));
String ss = "[{\"input_1648087139960\":\"ranyj\"},{\"textarea_1648087140361\":\"ranyj2号\"}]";
List<Map<String, Object>> list3 = JSONObject.parseObject(ss, List.class);
for (JSONObject json : list) {
String key = (String) json.get("key");
for (Map<String, Object> map : list3) {
System.out.println(map);
if (map.containsKey(key)) {
String value = (String) map.get(key);
System.out.println(value);
if (StrUtil.isNotBlank(value)) {
JSONObject jsonValue = (JSONObject) json.get("options");
jsonValue.put("value", value);
break;
}
}
}
}
JSONArray
String type =(String) json.get("type");
if(type.equals("checkbox")){
JSONArray items = (JSONArray)jsonValue.get("items");
for(int i=0;i<items.size();i++){
JSONObject jsonObject = items.getJSONObject(i);
String value = jsonObject.getString("value");
JSONArray objects = JSONArray.parseArray(JSONObject.toJSONString(o));
boolean contains = objects.contains(value);
if(objects.contains(value)){
jsonObject.put("checked",true);
}
}
}
该内容涉及对字符串格式的数据进行解析,将formDate中的键值对更新到formJson的选项中,同时处理了多个formDate的情况。此外,还涉及到对节点修改的表单样式的获取和处理,以及在遍历过程中对checkbox类型的值进行检查和更新。
4252

被折叠的 条评论
为什么被折叠?



