package cn.autoform.util.form; import cn.autoform.db.entity.FormFieldEntity; import cn.autoform.db.entity.form.FormCpnAttr; import cn.autoform.db.entity.form.FormCpnInfo; import cn.autoform.fw.utility.ConstMap; import cn.autoform.util.form.mapper.FormCpnInfoMapper; import cn.autoform.util.thread.Keys; import cn.autoform.util.thread.ThreadData; import cn.autoform.util.tool.JSONTool; import com.alibaba.fastjson.TypeReference; import com.iemsoft.framework.cloud.core.tools.MsgTool; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.stream.Collectors; public class FieldSetJsonUtil { public static Map toObj(String formSetJson){ return JSONTool.toObj(formSetJson, new TypeReference>(){}.getType()); } public static List toFormFieldEntityList(Map map){ if(map == null){ return new ArrayList<>(); } return map.values().stream().map(FieldSetJsonUtil::toFormFieldEntity) .sorted((field1, field2)->field1.getColumnOrderNum() - field2.getColumnOrderNum()) .collect(Collectors.toList()); } public static FormFieldEntity toFormFieldEntity(FormCpnInfo formCpnInfo){ return FormCpnInfoMapper.MAP.of(formCpnInfo); } public static List addBaseFieldEntity(List formFieldEntities){ formFieldEntities.addAll(getfieles("", ThreadData.get(Keys.TENANT_ID))); return formFieldEntities; } public static List getFieldEntitys(String formSetJson){ return addBaseFieldEntity(toFormFieldEntityList(toObj(formSetJson))); } /** * 代码里添加默认控件 */ private static List getfieles(String formID,String tenantID){ List list = new ArrayList<>(); //创建人 FormFieldEntity form1 = new FormFieldEntity(); form1.setFormFieldEntity(tenantID, formID, "text", "CREATEUSER", MsgTool.get("CREATEUSER")); form1.setFieldOrderNum(111); form1.setColumnOrderNum(111); FormFieldEntity form3 = new FormFieldEntity(); form3.setFormFieldEntity(tenantID, formID, "calendar", "CREATEDATETIME", MsgTool.get("CREATEDATETIME")); form3.setFieldOrderNum(113); form3.setColumnOrderNum(113); form3.setValue("Y-m-d"); FormFieldEntity form2 = new FormFieldEntity(); form2.setFormFieldEntity(tenantID, formID, "dropdownlist", "processStatE", MsgTool.get("PROCESSSTATE")); form2.setDataSourceType(ConstMap.CUSTOM); form2.setFieldOrderNum(112); form2.setColumnOrderNum(112); form2.setDataSourceData(getMaster()); list.add(form1); list.add(form3); list.add(form2); return list; } private static List getMaster(){ List list = new ArrayList<>(); list.add(new FormCpnAttr.Custom("10", "未提交")); list.add(new FormCpnAttr.Custom("20", "审核中")); list.add(new FormCpnAttr.Custom("30", "审核完成")); return list; } }