package cn.autoform.web.service.formbase; import cn.autoform.bean.TemplateManagerOutput; import cn.autoform.db.entity.*; import cn.autoform.util.form.FieldSetJsonUtil; import cn.autoform.util.thread.Keys; import cn.autoform.util.thread.ThreadData; import cn.autoform.util.tool.RequestContext; import cn.autoform.web.mapper.datamanagement.DataManagementMapper; import cn.autoform.web.mapper.formbase.FormBaseMapper; import cn.autoform.web.mapper.formset.FormSetMapper; import cn.autoform.web.mapper.formvalidation.FormValidationMapper; import cn.autoform.web.mapper.formversion.FormVersionMapper; import cn.autoform.web.service.datamanagement.DataManagementService; import cn.autoform.web.service.formsetting.FormsettingService; import net.sf.json.JSONArray; import net.sf.json.JSONObject; import org.apache.ibatis.annotations.Param; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.StringUtils; import javax.annotation.Resource; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Optional; @Service public class FormBaseService { @Resource DataManagementService dataManagementService; @Autowired private FormBaseMapper formbaseMapper = null; @Autowired private FormSetMapper formSetMapper = null; @Autowired private FormVersionMapper formVersionMapper = null; @Autowired private FormValidationMapper formValidationMapper = null; @Autowired DataManagementMapper dataManagementMapper = null; @Autowired FormsettingService formsettingService = null; /** * 查询表单id是否已经存在 * * @param formID 表单ID * @param tenantID 租户ID * @return 件数 */ public Integer queryFromBaseNum(String formID, String tenantID) { return formbaseMapper.queryFromBaseNum(formID, tenantID); } /** * 表单基本表插入数据 * * @param formBase 表单基本表数据 * @return 插入结果 */ public void addFormBase(FormBaseEntity formBase) { formbaseMapper.addFormBase(formBase); } /** * 表单字段管理表插入数据 * * @param formFieldObj * @return 插入结果 */ public void addFormField(FormFieldEntity formFieldObj) { formbaseMapper.addFormField(formFieldObj); } /** * 删除表单字段 * * @param formFieldObj */ public void deleteFormField(String formID, String tenantID) { formbaseMapper.deleteFormField(formID, tenantID); } /** * 删除表单字段属性 * * @param formFieldObj */ public void deleteFormFieldProperty(@Param("formID") String formID, @Param("tenantID") String tenantID) { formbaseMapper.deleteFormFieldProperty(formID, tenantID); } /** * 字段属性管理表插入数据 * * @param fieldPropertyObj * @return 插入结果 */ public void addFormFieldProperty(List fieldPropertyObj) { if(fieldPropertyObj!=null && fieldPropertyObj.size()>0){ formbaseMapper.addFormFieldProperty(fieldPropertyObj); } } /** * 表单基本表更新 * * @param entity * @return 更新结果 */ public Integer updateFormBaseInfo(FormBaseEntity entity) { return formbaseMapper.updateFormBaseInfo2(entity); } /** * 表单数据管理插入 * * @param entity */ public void addFormdataManager(FormdataManagerEntity entity) { formbaseMapper.addFormdataManager(entity); } /** * 表单数据表创建 * * @param excuteSql 执行sql语句 */ public void excuteFormDataTable(String excuteSql) { formbaseMapper.excuteFormDataTable(excuteSql); } /** * 表单数据管理查詢 * * @param entity * @return 件数 */ public FormdataManagerEntity queryFormdataManagerNum(FormdataManagerEntity entity) { return formbaseMapper.queryFormdataManagerNum(entity); } /** * 表单数据管理查詢 * * @param entity * @return 件数 */ public Map queryFormdataManagerNum2(FormdataManagerEntity entity) { return formbaseMapper.queryFormdataManagerNum2(entity); } public void deleteFormdataManager(FormdataManagerEntity entity) { formbaseMapper.deleteFormdataManager(entity); } /** * 查看表单数据表字段 * @param showColumnsSql * @return */ public List showColumns(String showColumnsSql) { return formbaseMapper.showColumns(showColumnsSql); } /** * 查询表单基本数据 * @param tenantID 租户ID * @param formID 表单ID * @return 表单基本数据 */ public FormBaseEntity getFormBaseInfo(String tenantID, String formID,Integer formMode) { FormBaseEntity baseEntity = null; if(formMode != null && (formMode == 5|| formMode == 4) ){ baseEntity = formbaseMapper.getFormModeBaseInfo(tenantID, formID); if(baseEntity == null ){ TemplateManagerOutput asd = formbaseMapper.getFormModeFomBaseInfo(tenantID, formID); baseEntity = new FormBaseEntity(); baseEntity.setFieldset("{}"); baseEntity.setFormID(formID); baseEntity.setTenantID(tenantID); baseEntity.setResultForm("
"); baseEntity.setFormHeight(112); baseEntity.setFormWidth(928); baseEntity.setFormName(asd.getTemplateName()); baseEntity.setDesignMode(formMode + ""); baseEntity.setFormVer(asd.getFormVersion()); baseEntity.setBussinesssystem("cloud"); baseEntity.setTemplateID(asd.getTemplateID()); //2018-02-02 21:17:22 baseEntity.setCreateDatetime(java.sql.Timestamp.valueOf("2018-02-02 21:17:22")); baseEntity.setUpdateDatetime(java.sql.Timestamp.valueOf("2018-02-02 21:17:22")); // baseEntity.set // baseEntity.setCreateUser(createUser); } }else{ baseEntity = formbaseMapper.getFormBaseInfo(tenantID, formID); } if (baseEntity != null && !StringUtils.isEmpty(baseEntity.getValidationRuleGroupID())) { List list = formValidationMapper.getFormValidation(baseEntity.getValidationRuleGroupID()); JSONArray jsonArry = new JSONArray(); list.forEach(formValidationEntity -> jsonArry.add(formValidationEntity.getRuleset())); baseEntity.setLinkage(jsonArry.toString()); } return baseEntity; } /** * 查询表单集合数据 * @param tenantID 租户ID * @param formSetID 表单ID * @return 表单集合数据 */ public FormSetEntity getFormSetInfo(String tenantID, String formSetID) { return formSetMapper.getFormSetInfo(tenantID, formSetID); } /** * 追加表单集合 * @param entity 表单集合数据 */ public void addFormSetInfo(FormSetEntity entity) { formSetMapper.insert(entity); } /** * 追加表单版本 * @param entity 表单版本数据 */ public void addFormVersion(FormVersionEntity entity) { formVersionMapper.insert(entity); } /** * 追加表单集合 * @param entity 表单集合数据 */ public void updateFormSetInfo(FormSetEntity entity) { formSetMapper.updateFormSetInfo1(entity); } /** * 追加表单版本 * @param entity 表单版本数据 */ public void updateFormVersion(FormVersionEntity entity) { formVersionMapper.updateFormVersion(entity); } /** * 追加表单版本 * @param entity 表单版本数据 */ public FormVersionEntity getFormVersion(FormVersionEntity entity) { return formVersionMapper.getFormVersionInfo(entity); } /** * 追加表单验证 * @param entity 表单验证内容 */ public void insertFormValidation(List list) { formValidationMapper.insert(list); } /** * 删除表单验证 * @param validationRuleGroupID 数据验证规则groupID */ public void deleteFormValidation(String validationRuleGroupID) { formValidationMapper.delete(validationRuleGroupID); } /** * 取得表单验证 * @param validationRuleGroupID 数据验证规则groupID * @return 表单验证内容 */ public List receiveFormValidation(String validationRuleGroupID) { return formValidationMapper.getFormValidation(validationRuleGroupID); } /** * 取得表单验证 * @param validationRuleGroupID 数据验证规则groupID * @return 表单验证内容 */ public Integer querySubFormName(String tableName) { return formbaseMapper.querySubFormName(tableName); } /** * 检验表单ID * @param formID * @return Integer */ public Integer checkFormId(String formID, String tenantID){ Integer count = this.dataManagementMapper.checkFormId(formID, tenantID); return count; } /** * 子表单更改表名 * * @param excuteUpdateSql 执行sql语句 */ public void excuteUpdateSubFormName(String excuteUpdateSql) { formbaseMapper.excuteUpdateSubFormName(excuteUpdateSql); } /** * 查看表单数据表字段 * @param showColumnsSql * @return */ public List selectFormField(String selectFormFieldSql) { return formbaseMapper.selectFormField(selectFormFieldSql); } /** * 表单数据更改 * * @param excuteSql 执行sql语句 */ public void excuteAlterSubField(String excuteAlterSql) { formbaseMapper.excuteAlterSubField(excuteAlterSql); } /** * 更改formdatamanager中数据状态 * * @param excuteAlterDataStateSql 执行sql语句 */ public void excuteAlterDataState(String excuteAlterDataStateSql) { formbaseMapper.excuteAlterDataState(excuteAlterDataStateSql); } /** * 子表单数据管理查詢 * * @param entity * @return 件数 */ public FormdataManagerEntity queryFormdataManager(FormdataManagerEntity entity) { return formbaseMapper.queryFormdataManager(entity); } /** * 查询formdatamanager表中所有表名 * * @param selectFormDataTableSql 执行sql语句 */ public List selectFormDataTable(String formId, String tenantId) { return formbaseMapper.selectFormDataTable(formId, tenantId); } public List> getFormHaveSub(String formID, String tenantID){ return formbaseMapper.getFormHaveSub(formID, tenantID); } public String getAssFormId(String formID, String tenantID, String alias){ StringBuilder formId = new StringBuilder(); dataManagementService.queryFormAllField(formID, tenantID).stream() .filter(field -> field.getFieldKey().equals(alias)) .forEach(formMainField ->{ List fields = dataManagementService.queryFormFieldProperty(formID, tenantID, formMainField.getColumnOrderNum()); if(!fields.isEmpty()){ formId.append(getAsFormID(fields)); } }); return formId.toString(); } private String getAsFormID(List Pros){ StringBuilder sourse = new StringBuilder(); Pros.stream().filter(field ->field.getProperty().equals("relevancesourcetype")) .forEach(field ->{ sourse.append(field.getValue()); }); if(!StringUtils.isEmpty(sourse.toString())){ StringBuilder value = new StringBuilder(); Pros.stream().filter(field -> field.getProperty().equals(sourse.toString())) .forEach(field ->{ value.append(field.getValue()); }); return JSONObject.fromObject(JSONObject.fromObject(value.toString()).getString("formID")).getString("formID"); } return null; } public int deleteformTable(String formId){ return formbaseMapper.deleteformTable(formId); } public FormBaseEntity getFormBase(String tenantID, String formID) { return formbaseMapper.getFormBaseInfo(tenantID, formID); } /** * 复制表单设置相关 */ public void copyFormSetUp(String associatedFormID,String formID){ //当前表单ID // String formID = RequestContext.getFormId(); //租户ID String tenantID = RequestContext.getTenantId(); //1.数据源 List dataSorse = formbaseMapper.queryDataSorse(associatedFormID, tenantID,formID); if(!dataSorse.isEmpty()) formbaseMapper.copyDataSorse(dataSorse); //2.接口注册 List interfaces = formbaseMapper.queryInterface(associatedFormID, tenantID,formID); if(!interfaces.isEmpty()) formbaseMapper.copyInterface(interfaces); //3.页面事件 List events = formbaseMapper.queryFormEvent(associatedFormID, tenantID,formID); if(!events.isEmpty()) formbaseMapper.copyFormEvent(events); //4.资源文件 List resource = formbaseMapper.queryFormResource(associatedFormID, tenantID,formID); if(!resource.isEmpty()) formbaseMapper.copyFormResource(resource); //5.工具栏设置 List formsetting = formbaseMapper.queryFormsetting(associatedFormID, tenantID,formID); if(!formsetting.isEmpty()) formbaseMapper.copyFormsetting(formsetting); //6.选项卡配置 List tabConfiguration = formbaseMapper.queryTabConfiguration(associatedFormID, tenantID,formID); if(!tabConfiguration.isEmpty()) formbaseMapper.copyTabConfiguration(tabConfiguration); } public List getFormFieldEntitys(String tenantId, String formID) { List list = FieldSetJsonUtil.getFieldEntitys( Optional.ofNullable(getFormBase(tenantId, formID)) .map(FormBaseEntity::getFieldset) .orElse("") ); //没有提交按钮得,过滤流程状态 FormsettingEntity re = formsettingService.getFormsettingInfo(new CustomButtonEntity(formID,tenantId)); if(re!=null && Objects.equals(re.getSubmitable(),"0")){ //流程状态控件为集合得最后一个,所以直接删除最后一位 list.remove(list.size()-1); } return list; } }