コード例 #1
0
  @Override
  public Map<String, Object> getDefaultFormData(String businessFormTemplateId) {
    Map<String, Object> formData = new HashMap<String, Object>();
    List<BusinessBaseTemplate> list =
        businessBaseTemplateDao.queryBybusinessBaseTemplate(businessFormTemplateId);
    for (BusinessBaseTemplate baseTemplate : list) {
      List<TemplateField> fieldList = templateFieldDao.queryByTemplateFormId(baseTemplate.getId());
      String businessBaseId = baseTemplate.getBusinessBaseId();
      BusinessBase businessBase = businessBaseDao.getById(businessBaseId);
      String baseFormId = businessBase.getBaseFormId();
      BaseForm baseForm = baseFormDao.getById(baseFormId);
      // 主表单
      if (businessBase.getIsDetail() != null && businessBase.getIsDetail().intValue() == 0) {
        Map<String, Object> map = new HashMap<String, Object>();
        for (TemplateField templateField : fieldList) {
          FormField formField = formFieldDao.getById(templateField.getFieldId());
          String defaultValue = templateField.getDefaultValue();
          if (!StringUtil.isNullOrEmpty(defaultValue)) {
            if (formField.getViewType().intValue() == FormMetaValue.FORMFIELD_DATAFIELD) {
              try {
                Date v = DateUtils.parseDate(defaultValue, new String[] {"yyyy-MM-dd"});
                map.put(formField.getFieldCode().toLowerCase(), v);
              } catch (ParseException e) {
                log.error(
                    this.getClass().getSimpleName()
                        + " e==> getDefaultFormData  ,ParseException + businessFormTemplateId:["
                        + businessFormTemplateId
                        + "]",
                    e);
              }
            } else {
              map.put(formField.getFieldCode().toLowerCase(), defaultValue);
            }
            // 列表组件 需要设置rawText值
            if (formField.getViewType().intValue() == FormMetaValue.FORMFIELD_GRID
                || formField.getViewType().intValue() == FormMetaValue.FORMFIELD_TREE) {
              map.put(
                  formField.getFieldCode().toLowerCase() + "_rawtext",
                  formFieldService.getRawTextValue(defaultValue, formField));
            }
          }
        }
        formData.put(baseForm.getBaseFormCode().toLowerCase(), map);
      } else {

      }
    }
    return formData;
  }
コード例 #2
0
  @Override
  public Map<String, Object> getFormData(String businessFormtemplateId, String flowRequestId) {
    Map<String, Object> resultMap = new HashMap<String, Object>();
    List<BusinessBaseTemplate> list =
        businessBaseTemplateDao.queryBybusinessBaseTemplate(businessFormtemplateId);
    for (BusinessBaseTemplate baseTemplate : list) {
      StringBuffer selectSql = new StringBuffer();
      Map<String, Object> selectParam = new HashMap<String, Object>();
      String businessBaseId = baseTemplate.getBusinessBaseId();
      String baseFormId = businessBaseDao.getById(businessBaseId).getBaseFormId();
      BaseForm baseForm = baseFormDao.getById(baseFormId);
      String baseFormCode = baseForm.getBaseFormCode().toLowerCase();
      selectSql.append("select id ").append("\"id\",");
      // 需要设置rawText值的字段
      List<FormField> needRawTextList = new ArrayList<FormField>();
      // 自定义组件list
      List<TemplateFieldDto> cusFomFieldList = new ArrayList<TemplateFieldDto>();

      List<TemplateField> fieldList = templateFieldDao.queryByTemplateFormId(baseTemplate.getId());
      for (TemplateField templateField : fieldList) {
        if (templateField != null
            && templateField.getIsShow() != null
            && templateField.getIsShow() == 1) {
          FormField formField = formFieldDao.getById(templateField.getFieldId());
          selectSql
              .append(formField.getFieldCode() + "  \"")
              .append(formField.getFieldCode().toLowerCase() + "\",");
          // 列表组件
          if (formField.getViewType().intValue() == FormMetaValue.FORMFIELD_GRID
              || formField.getViewType().intValue() == FormMetaValue.FORMFIELD_TREE) {
            needRawTextList.add(formField);
          }
          if (formField.getViewType().intValue() == FormMetaValue.FORMFIELD_CUS_FIELD) {
            TemplateFieldDto d = new TemplateFieldDto();
            d.setTemplateField(templateField);
            d.setFormField(formField);
            cusFomFieldList.add(d);
          }
        }
      }
      String sql =
          selectSql.substring(0, selectSql.length() - 1)
              + " from "
              + baseForm.getBaseFormCode().toLowerCase()
              + " where FLOW_REQUEST_ID = #{flowRequestId}";
      selectParam.put("flowRequestId", flowRequestId);

      BusinessBase businessBase = businessBaseDao.getById(baseTemplate.getBusinessBaseId());
      // 主表单
      if (businessBase.getIsDetail() != null && businessBase.getIsDetail() == 0) {
        // 从数据库查询表单值
        Map<String, Object> map = businessBaseTemplateDao.getMainDataBySql(sql, selectParam);
        // 设置需要rawText的值
        for (FormField formField : needRawTextList) {
          Object value = map.get(formField.getFieldCode().toLowerCase());
          if (!StringUtil.isNullOrEmpty(value)) {
            map.put(
                formField.getFieldCode().toLowerCase() + "_rawtext",
                formFieldService.getRawTextValue(value.toString(), formField));
          }
        }
        // 自定义组件设置值
        for (TemplateFieldDto dto : cusFomFieldList) {
          Object value = map.get(dto.getFormField().getFieldCode().toLowerCase());
          if (!StringUtil.isNullOrEmpty(value)) {
            sqlDatasourceService.setCusFieldValueToMap(dto, map, value);
          }
        }
        resultMap.put(baseFormCode, map);
      } else if (businessBase.getIsDetail() != null && businessBase.getIsDetail() == 1) {
        List<Map<String, Object>> resultList =
            businessBaseTemplateDao.getSubDataBySql(sql, selectParam);
        // 设置需要rawText的值
        for (Map<String, Object> subList : resultList) {
          for (FormField formField : needRawTextList) {
            Object value = subList.get(formField.getFieldCode().toLowerCase());
            if (!StringUtil.isNullOrEmpty(value)) {
              subList.put(
                  formField.getFieldCode().toLowerCase() + "_rawtext",
                  formFieldService.getRawTextValue(value.toString(), formField));
            }
          }
        }
        if (resultList != null) {
          resultMap.put(baseFormCode, resultList);
        } else {
          resultMap.put(baseFormCode, new ArrayList<Map<String, String>>());
        }
      } else {
        resultMap.put(baseFormCode, new HashMap<String, String>());
      }
    }
    return resultMap;
  }