FormCacheManager formCacheManager = (FormCacheManager) AppContext.getBean(${doubleQuote}formCacheManager${doubleQuote});
        TemplateManager templateManager = (TemplateManager) AppContext.getBean(${doubleQuote}templateManager${doubleQuote});
        java.util.List<${returnEntityName}> result = new ArrayList<${returnEntityName}>();
        long toFormId = MagicHandleFormUtils.getProviderFormId(${doubleQuote}${businessId}${doubleQuote}, ${doubleQuote}${versionId}${doubleQuote}, ${doubleQuote}${methodName}${doubleQuote});
        FormBean toFormBean = formCacheManager.getForm(toFormId);
        if (toFormBean == null || !formCacheManager.isEnabled(toFormBean)) {
            ${returnEntityName} data = new ${returnEntityName}();
            data.setSuccess(0);
            data.setMsg(${doubleQuote}无法找到表单ID为 ${doubleQuote} +toFormId +${doubleQuote}的表单${doubleQuote} );
            
            result.add(data);
            return result;
        }
        CtpTemplate ctpTemplate = null;
        try {
            template =MagicHandleFormUtils.getRealityTempalte(${doubleQuote}${businessId}${doubleQuote}, ${doubleQuote}${versionId}${doubleQuote}, ${doubleQuote}${methodName}${doubleQuote},template);
            ctpTemplate = templateManager.getCtpTemplate(template);
        

            if (null == ctpTemplate || ctpTemplate.isDelete()) {
                ${returnEntityName} data = new ${returnEntityName}();
                data.setSuccess(0);
                data.setMsg(${doubleQuote}表单名 ${doubleQuote} +toFormBean.getFormName() +${doubleQuote}没有找到 模版ID= ${doubleQuote} + template +${doubleQuote}的模版${doubleQuote} );
                result.add(data);
                return result;
            }
            FormTableBean formTable = toFormBean.getMasterTableBean();
            Map<Long, List<FormDataMasterBean>> masterBeans = new HashMap<Long, List<FormDataMasterBean>>();
    
            Long sourceDataId = 0L;
            Map<String, Map<Long, Set<Long>>> attachmentMap = new HashMap<String, Map<Long,Set<Long>>>();
            Map<String, Map<Long, Set<String>>> mapLocateIdMap = new HashMap<String, Map<Long, Set<String>>>();
            
            WorkflowApiManager wapi = (WorkflowApiManager) AppContext.getBean(${doubleQuote}wapi${doubleQuote});
            FormAuthViewBean authViewBean = null;
            
            String  operationId = FormUtil.parseOperationId(wapi.getNodeFormOperationName(ctpTemplate.getWorkflowId(), null));
            authViewBean = toFormBean.getAuthViewBeanById(Long.valueOf(operationId));
            
            Map<String, Map<String, Object>> toSub = new LinkedHashMap<String, Map<String, Object>>();
            Map<String, Object> toMain = new LinkedHashMap<String, Object>();
            context.addExtAttr(${doubleQuote}toSub${doubleQuote}, toSub);
            context.addExtAttr(${doubleQuote}toMain${doubleQuote}, toMain);
            String tableName = toFormBean.getMasterTableBean().getTableName();
            Map<String,String> formTableMapping =  MagicHandleFormUtils.getFormTableMapping(${doubleQuote}${businessId}${doubleQuote}, ${doubleQuote}${versionId}${doubleQuote}, ${doubleQuote}${methodName}${doubleQuote},true);
            for (${formDataEntityName} temp : formData) {
                Long createUser =Long.parseLong(temp.getCreateUserId());
                sourceDataId = Long.parseLong(temp.getSourceDataId().toString());
                FormDataMasterBean datamasterBean = new FormDataMasterBean(authViewBean,formTable, true);
                Map<String, Object> valueMap = new HashMap<String, Object>();
                valueMap.put(Enums.MasterTableField.start_member_id.getKey(), createUser);
                valueMap.put(Enums.MasterTableField.modify_member_id.getKey(), createUser);
                valueMap.put(Enums.MasterTableField.start_date.getKey(), DateUtil.currentTimestamp());
                valueMap.put(Enums.MasterTableField.state.getKey(), Enums.FormDataStateEnum.FLOW_UNOFFICIAL.getKey());// 先将数据的状态设置为非正式数据-2，校验通过后再设置为正式1
                datamasterBean.addFieldValue(valueMap);
                toMain.put(String.valueOf(sourceDataId), tableName + ${doubleQuote},${doubleQuote} + datamasterBean.getId());
                List<String> fillSubTables = new ArrayList<String>();
                ${assignDataContent}
                
                List<FormTableBean> allSubTableBean = toFormBean.getSubTableBean();
                FormDataSubBean subBean;
                if (Strings.isNotEmpty(allSubTableBean)) {
                    for (FormTableBean subTableBean : allSubTableBean) {
                       if (fillSubTables.contains(subTableBean.getTableName())) {
                           continue;
                         }
                          subBean = new FormDataSubBean(authViewBean,subTableBean, datamasterBean, true);
                          // TODO 需要处理初始值
                         subBean.setFormmainId(datamasterBean.getId());
                         datamasterBean.addSubData(subTableBean.getTableName(), subBean);
                    }
                }
                List<FormDataMasterBean> tempMasters = masterBeans.get(createUser);
                if (tempMasters == null) {
                    tempMasters = new ArrayList<FormDataMasterBean>();
                    masterBeans.put(createUser, tempMasters);
                }
                MagicHandleCAP3FormUtils.fillOtherInfo(toFormBean, datamasterBean, authViewBean, mapLocateIdMap);
                tempMasters.add(datamasterBean);
            }
            List<Map<String, Object>> saveReult = MagicHandleCAP3FormUtils.saveFlowDataBean(context, masterBeans,toFormBean, ctpTemplate, attachmentMap);
            if (saveReult != null && !saveReult.isEmpty()) {
                for (Map<String, Object> temp : saveReult) {
                    ${returnEntityName} d = new ${returnEntityName}();
                    d.setDataId(ParamUtil.getLong(temp, ${doubleQuote}dataId${doubleQuote}, 0L));
                    d.setSuccess(ParamUtil.getInt(temp, ${doubleQuote}success${doubleQuote}, 0));
                    d.setMsg(ParamUtil.getString(temp, ${doubleQuote}msg${doubleQuote}));
                    result.add(d);
                }
    
            }
        } catch (BusinessException e2) {
            e2.printStackTrace();
        }catch (SQLException e) {
            e.printStackTrace();
        }
        return result;