package cn.autoform.web.service.formtending; import cn.autoform.bean.FormTable; import cn.autoform.bean.page.PageResult; import cn.autoform.db.entity.FormBaseEntity; import cn.autoform.db.entity.FormSetEntity; import cn.autoform.db.entity.FormSetInfoEntity; import cn.autoform.db.entity.FormVersionEntity; import cn.autoform.db.exten.TableStructure; import cn.autoform.util.tool.JSONTool; import cn.autoform.web.client.FormClient; import cn.autoform.web.mapper.formTable.FormTableMapper; import cn.autoform.web.mapper.formbase.FormBaseMapper; import cn.autoform.web.mapper.formset.FormSetMapper; import cn.autoform.web.mapper.formversion.FormVersionMapper; import cn.autoform.web.request.FormBaseCopyRequestForm; import cn.autoform.web.request.FormBaseUpdateRequestForm; import cn.autoform.web.service.formbase.FormBaseService; import org.apache.commons.lang.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.List; @Service public class FormTendingService { @Autowired private FormBaseMapper formBaseMapper = null; @Autowired private FormSetMapper formSetMapper = null; @Autowired private FormVersionMapper formVersionMapper = null; @Autowired private FormBaseService formBaseService = null; @Resource private FormTableMapper formTable; @Autowired private FormClient formClient; /** * * @param tenantID * @param formID * @return */ public FormBaseEntity receiveFormBaseInfo(String tenantID, String formID) { return formBaseMapper.getFormBaseInfo(tenantID, formID); } /** * * @param formID * @param formSetid * @return */ public FormSetEntity receiveFormSetInfo(String tenantID, String formSetId) { FormSetEntity objFormSet = formSetMapper.getFormSetInfo(tenantID, formSetId); String strUsedversion = objFormSet.getUsedversion(); FormVersionEntity entity = new FormVersionEntity(); entity.setFormSetID(formSetId); entity.setTenantID(tenantID); entity.setFormVersion(strUsedversion); FormVersionEntity objFormVer = formVersionMapper.getFormVersionInfo(entity); String strFormId = ""; if(objFormVer != null) { strFormId = objFormVer.getFormID(); } if(!StringUtils.isEmpty(strFormId)) { String strDescription = formBaseMapper.getFormBaseInfo(tenantID, strFormId).getDescription(); objFormSet.setDescription(strDescription); } return objFormSet; } /** * * @param formID * @param tenantID * @param resourceFilepath * @return */ public PageResult receiveFormSetListInfo(String tenantID,int pageNum,int pageSize,String selectName) { int pageStrat = (pageNum-1)*pageSize; List list1=formSetMapper.getFormSetListInfo(tenantID,pageStrat,pageSize,selectName); // System.out.println("**************************"+list1.size()); int count = formSetMapper.getFormSetListCount(tenantID,selectName); //System.out.println(count); PageResult pageResult=new PageResult(); pageResult.setList(list1); pageResult.setCount(Long.valueOf(count)); return pageResult; } /** * * @param entity * @throws Exception */ public int updateFormBaseInfo(FormBaseUpdateRequestForm entity) throws Exception { // 表单版本表更新 System.out.println("参数:"+JSONTool.toJson(entity)); updateFormVersion(entity); FormSetEntity objFormSet = formSetMapper.getFormSetInfo(entity.getTenantID(), entity.getFormSetID()); String useDversion = objFormSet.getUsedversion(); System.out.println("取出表单数据:"+JSONTool.toJson(objFormSet)); // 表单集合属性管理表更新 FormSetEntity setEntity = new FormSetEntity(); setEntity.setFormSetID(entity.getFormSetID()); setEntity.setTenantID(entity.getTenantID()); setEntity.setUpdateUser(entity.getUpdateUser()); if("1".equals(entity.getEnablesetting())) { setEntity.setUsedversion(entity.getFormVer()); //关闭其他版本 FormTable form = formTable.getFormTable(entity.getFormID()); //创建表位置修改至此 if(form!=null){ if(form.getFlag().equals("services")){ boolean fi = true; for(FormTable fo : formTable.getFormTableList(entity.getFormID())){ TableStructure tab = JSONTool.toObj(fo.getJsonObj(),TableStructure.class); if(fi){ fi = !fi; formClient.createTable(tab); }else{ formClient.updateTable(tab); } } }else{ formBaseService.excuteFormDataTable(form.getJsonObj()); } formTable.removeFormTable(entity.getFormID()); } List list = formVersionMapper.getFormInfo(entity); System.out.println("取出list:"+JSONTool.toJson(list)); if(list!=null){ for(FormVersionEntity fo:list){ int i = formBaseMapper.updateFormInfo(fo); System.out.println("盖面了"+i); } } } else { if(entity.getFormVer().equals(useDversion)){ setEntity.setUsedversion(""); } else { setEntity.setUsedversion(useDversion); } // setEntity.setUsedversion(""); } formSetMapper.updateFormSetUseVerInfo(setEntity); // 表单基本表更新 FormBaseEntity formBaseEntity = new FormBaseEntity(entity); return formBaseMapper.updateFormBaseInfo(formBaseEntity); } /** * * @param entity * @throws Exception */ public int updateFormBaseInfo1(FormBaseUpdateRequestForm entity) throws Exception { // 表单版本表更新 int i = 0; System.out.println("参数:"+JSONTool.toJson(entity)); updateFormVersion(entity); FormSetEntity objFormSet = formSetMapper.getFormSetInfo(entity.getTenantID(), entity.getFormSetID()); String useDversion = objFormSet.getUsedversion(); System.out.println("取出表单数据:"+JSONTool.toJson(objFormSet)); System.out.println(" 参数1:"+JSONTool.toJson(objFormSet)); // 表单集合属性管理表更新 FormSetEntity setEntity = new FormSetEntity(); setEntity.setFormSetID(entity.getFormSetID()); setEntity.setTenantID(entity.getTenantID()); setEntity.setUpdateUser(entity.getUpdateUser()); if("1".equals(entity.getEnablesetting())) { setEntity.setUsedversion(entity.getFormVer()); //关闭其他版本 FormTable form = formTable.getFormTable(entity.getFormID()); //创建表位置修改至此 if(form!=null){ if(form.getFlag().equals("services")){ boolean fi = true; for(FormTable fo : formTable.getFormTableList(entity.getFormID())){ TableStructure tab = JSONTool.toObj(fo.getJsonObj(),TableStructure.class); if(fi){ fi = !fi; formClient.createTable(tab); }else{ formClient.updateTable(tab); } } }else{ formBaseService.excuteFormDataTable(form.getJsonObj()); } formTable.removeFormTable(entity.getFormID()); } System.out.println("参数2:"+JSONTool.toJson(entity)); List list = formVersionMapper.getFormInfo(entity); System.out.println("取出list:"+JSONTool.toJson(list)); if(list!=null){ for(FormVersionEntity fo:list){ //用这个字段代替en 判断状态字段 fo.setFormVersion(""); formBaseMapper.updateFormInfo(fo); } } } else { if(entity.getFormVer().equals(useDversion)){ setEntity.setUsedversion(""); } else { setEntity.setUsedversion(useDversion); } // setEntity.setUsedversion(""); } System.out.println("使用参数3:"+JSONTool.toJson(setEntity)); formSetMapper.updateFormSetUseVerInfo(setEntity); //FormVersionEntity formEn = new FormVersionEntity(); //开启本版本表单 //formEn.setFormVersion(entity.getEnablesetting()); //formEn.setFormID(entity.getFormID()); //formEn.setTenantID(entity.getTenantID()); //return formBaseMapper.updateFormInfo(formEn); // 表单基本表更新 FormBaseEntity formBaseEntity = new FormBaseEntity(entity); return formBaseMapper.updateFormBaseInfo(formBaseEntity); } public int updateFormSetInfo(FormSetEntity entity) { return formSetMapper.updateFormSetInfo(entity); } public int saveFormBaseInfo(FormBaseEntity entity) { return formBaseMapper.addFormBase(entity); } private int updateFormVersion(FormBaseUpdateRequestForm entity) { FormVersionEntity formVersionEntity = new FormVersionEntity(); formVersionEntity.setFormID(entity.getFormID()); formVersionEntity.setFormVersion(entity.getFormVer()); formVersionEntity.setTenantID(entity.getTenantID()); formVersionEntity.setFormSetID(entity.getFormSetID()); return formVersionMapper.updateFormVersion(formVersionEntity); } public int copyFormBaseInfo(FormBaseCopyRequestForm entity) { FormSetEntity formSetInfo = entity.getFormSetInfo(); copyFormSetInfo(formSetInfo); entity.setEnablesetting("0"); FormBaseEntity formBaseEntity = new FormBaseEntity(entity); saveFormBaseInfo(formBaseEntity); FormVersionEntity formVersionEntity = new FormVersionEntity(); formVersionEntity.setFormID(entity.getFormID()); formVersionEntity.setFormSetID(formSetInfo.getFormSetID()); formVersionEntity.setFormVersion(entity.getFormVer()); formVersionEntity.setTenantID(entity.getTenantID()); return formVersionMapper.insert(formVersionEntity); } public void copyFormSetInfo(FormSetEntity formSetInfo) { FormSetEntity entity = formSetMapper.getFormSetInfo( formSetInfo.getTenantID(), formSetInfo.getFormSetID()); if (entity == null) { formSetMapper.insert(formSetInfo); } } public FormVersionEntity getFormVersionInfo(FormVersionEntity entity) { return formVersionMapper.getFormVersionInfo(entity); } public int deleteFormSet(FormSetEntity entity) { return formSetMapper.deleteFormSet(entity); } }