package com.vci.web.service.impl; import com.vci.client.common.providers.ClientServiceProvider; import com.vci.corba.common.PLException; import com.vci.corba.framework.data.UserInfo; import com.vci.corba.omd.data.*; import com.vci.corba.omd.lcm.LifeCycle; import com.vci.file.pagemodel.VciFileObjectVO; import com.vci.frameworkcore.lcstatuspck.FrameworkDataLCStatus; import com.vci.frameworkcore.lcstatuspck.ReleaseDataLCStatus; import com.vci.omd.utils.ObjectTool; import com.vci.starter.revision.bo.TreeWrapperOptions; import com.vci.starter.web.annotation.bus.VciChangeDataAfter; import com.vci.starter.web.annotation.bus.VciChangeDataBefore; import com.vci.starter.web.annotation.bus.VciChangeDataPlugin; import com.vci.starter.web.constant.FrameWorkLcStatusConstant; import com.vci.starter.web.constant.QueryOptionConstant; import com.vci.starter.web.enumpck.VciChangeDocumentTypeEnum; import com.vci.starter.web.exception.VciBaseException; import com.vci.starter.web.model.BaseModel; import com.vci.starter.web.pagemodel.*; import com.vci.starter.web.util.*; import com.vci.starter.web.wrapper.VciQueryWrapperForDO; import com.vci.web.dto.*; import com.vci.web.enumpck.UIFieldTypeEnum; import com.vci.web.enumpck.UITreeLoadTypeEnum; import com.vci.web.pageModel.*; import com.vci.web.query.UIDataGridQuery; import com.vci.web.query.UIFormQuery; import com.vci.web.query.UILinkTypeDataQuery; import com.vci.web.query.UITreeQuery; import com.vci.web.service.*; import com.vci.web.util.PlatformClientUtil; import com.vci.web.util.WebUtil; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import java.lang.reflect.Method; import java.util.*; import java.util.stream.Collectors; import static com.vci.frameworkcore.constant.FrameWorkBusLangCodeConstant.DATA_OID_NOT_EXIST; /** * UI上的数据查询 * @author weidy * @date 2021/3/3 */ @Service public class UIDataServiceImpl implements UIDataServiceI { /** * 平台的调用客户端 */ @Autowired private PlatformClientUtil platformClientUtil; /** * UI的服务 */ @Autowired private UIEngineServiceI uiEngineService; /** * 业务类型 */ @Autowired private OsBtmServiceI btmService; /** * 链接类型 */ @Autowired private OsLinkTypeServiceI linkTypeService; /** * 业务类型操作 */ @Autowired private WebBoServiceI boService; /** * 链接类型操作 */ @Autowired private WebLoServiceI loService; /** * 生命周期的服务 */ @Autowired private OsLifeCycleServiceI lifeCycleService; /** * 版本规则的服务 */ @Autowired private OsRevisionRuleServiceI revisionRuleServiceI; /** * 文件的服务 */ @Autowired private VciFileObjectServiceI fileObjectService; /** * 属性的服务 */ @Autowired private OsAttributeServiceI attributeService; /** * from端的前缀 */ public static final String LO_FROM_PREFIX="f_oid."; /** * to端的前缀 */ public static final String LO_TO_PREFIX = "t_oid."; /** * 获取表格的数据 * * @param dataGridQuery 表格查询,必须有业务类型名称和 表格的编号 * @return DataGrid中data为Map格式 * @throws VciBaseException 查询出错的时候会抛出异常 */ @Override public DataGrid getDataForGrid(UIDataGridQuery dataGridQuery) throws VciBaseException { VciBaseUtil.alertNotNull(dataGridQuery,"查询对象",dataGridQuery.getBtmname(),"业务类型",dataGridQuery.getTableDefineId()); //先判断查询模板 UITableDefineVO tableDefineVO = uiEngineService.getComponentByOid(dataGridQuery.getComponentOid()).getTableDefineVO(); String queryTemplate = !CollectionUtils.isEmpty(dataGridQuery.getSourceData())?dataGridQuery.getSourceData().getOrDefault("querytemplate",tableDefineVO.getQueryTemplateName()):tableDefineVO.getQueryTemplateName(); if(StringUtils.isBlank(queryTemplate)){ //说明没有设置查询模板,需要看看在这个表格所在的组件有没有设置 tableDefineVO = uiEngineService.getTableById(dataGridQuery.getBtmname(), dataGridQuery.getTableDefineId()); queryTemplate = tableDefineVO.getQueryTemplateName(); } //看看有没有自定义的SQL Set queryFieldList = new HashSet<>(); tableDefineVO.getCols().forEach(cols->{ //获取参照 List referFieldList = cols.stream().filter(s -> UIFieldTypeEnum.REFER.getValue().equalsIgnoreCase(s.getFieldType())).collect(Collectors.toList()); if(!CollectionUtils.isEmpty(referFieldList)){ referFieldList.stream().forEach(field->{ queryFieldList.add(field.getField()); if(StringUtils.isNotBlank(field.getShowField())) { queryFieldList.add(field.getShowField()); } }); } Map comboxMap = cols.stream().filter(s -> UIFieldTypeEnum.COMBOX.getValue().equalsIgnoreCase(s.getFieldType()) && StringUtils.isNotBlank(s.getComboxKey())).collect(Collectors.toList()).stream().collect(Collectors.toMap(s -> s.getField(), t -> t.getComboxKey())); if(!CollectionUtils.isEmpty(comboxMap)) { comboxMap.forEach((field,comboxKey)->{ queryFieldList.add(comboxKey+"_" + field.substring(0,field.length()-4) + "#" + field); }); } queryFieldList.addAll(cols.stream().filter(s -> !UIFieldTypeEnum.REFER.getValue().equalsIgnoreCase(s.getFieldType()) && !UIFieldTypeEnum.COMBOX.getValue().equalsIgnoreCase(s.getFieldType())).map(s -> s.getField()).collect(Collectors.toList())); }); //针对参照的,我们需要添加对应的 //这个业务类型包含的属性 OsBtmTypeVO btmTypeVO = null; OsLinkTypeVO linkTypeVO = null; if(dataGridQuery.isLinkTypeFlag()){ linkTypeVO = linkTypeService.getLinkTypeById(dataGridQuery.getBtmname()); queryFieldList.addAll(linkTypeVO.getAttributes().stream().map(OsLinkTypeAttributeVO::getId).collect(Collectors.toList())); queryFieldList.addAll(WebLoServiceImpl.LO_BASE_FIELD_MAP.values()); }else{ btmTypeVO = btmService.getBtmById(dataGridQuery.getBtmname()); queryFieldList.addAll(btmTypeVO.getAttributes().stream().map(OsBtmTypeAttributeVO::getId).collect(Collectors.toList())); queryFieldList.addAll(WebBoServiceImpl.BO_BASE_FIELD_MAP.values()); } queryFieldList.add("creator_name"); queryFieldList.add("lastmodifier_name"); //我们在后台查询业务数据 Map replaceMap = wrapperReplaceMap( dataGridQuery.getSourceData()); if(dataGridQuery.isLinkTypeFlag()){ UILinkTypeDataQuery linkTypeDataQuery = new UILinkTypeDataQuery(); linkTypeDataQuery.setQueryTemplateName(queryTemplate); linkTypeDataQuery.setReplaceMap(replaceMap); linkTypeDataQuery.setConditionMap(dataGridQuery.getConditionMap()); linkTypeDataQuery.setClauseList(queryFieldList); linkTypeDataQuery.setLinkType(dataGridQuery.getBtmname()); if(dataGridQuery.isTreeTableFlag()){ linkTypeDataQuery.setLevel(-1); } return loService.queryGridByScheme(linkTypeDataQuery); }else { return boService.queryGridByScheme(queryTemplate, dataGridQuery.getConditionMap(), replaceMap, dataGridQuery.getPageHelper(), queryFieldList.stream().collect(Collectors.toList())); } //生命周期在其中查询后就会处理 //枚举也会被处理了 } /** * 获取表单的数据 * * @param formQuery 表单的查询条件 * @return 表单的数据 * @throws VciBaseException 查询出错的时候会抛出异常 */ @Override public UIFormDataVO getDataForForm(UIFormQuery formQuery) throws VciBaseException { VciBaseUtil.alertNotNull(formQuery,"表单的查询对象",formQuery.getBtmname(),"业务类型的信息",formQuery.getOid(),"业务数据的主键",formQuery.getFormDefineId(),"表单的定义编号"); UIFormDefineVO formDefineVO = uiEngineService.getFormById(formQuery.getBtmname(),formQuery.getFormDefineId()); String queryTemplate = !CollectionUtils.isEmpty(formQuery.getSourceData())?formQuery.getSourceData().getOrDefault("querytemplate",formDefineVO.getQueryTemplateName()):formDefineVO.getQueryTemplateName(); Set queryFieldList = formDefineVO.getItems().stream().filter(s->!UIFieldTypeEnum.CUSTOM.getValue().equalsIgnoreCase(s.getType())).map(UIFormItemVO::getField).collect(Collectors.toSet()); //获取参照 List referFieldList = formDefineVO.getItems().stream().filter(s -> UIFieldTypeEnum.REFER.getValue().equalsIgnoreCase(s.getType())).collect(Collectors.toList()); if(!CollectionUtils.isEmpty(referFieldList)){ referFieldList.stream().forEach(field->{ queryFieldList.add(field.getField()); if(StringUtils.isNotBlank(field.getShowField())) { queryFieldList.add(field.getShowField()); } }); } Map comboxMap = formDefineVO.getItems().stream().filter(s -> UIFieldTypeEnum.COMBOX.getValue().equalsIgnoreCase(s.getType()) && StringUtils.isNotBlank(s.getComboxKey())).collect(Collectors.toList()).stream().collect(Collectors.toMap(s -> s.getField(), t -> t.getComboxKey())); if(!CollectionUtils.isEmpty(comboxMap)) { comboxMap.forEach((field,comboxKey)->{ //要把枚举的属性查询出来,和表格额地方不一样,因为那边会把field直接加了text queryFieldList.add(comboxKey+"_" + field + "#" + field +"text"); }); } //这个业务类型包含的属性 OsBtmTypeVO btmTypeVO = null; OsLinkTypeVO linkTypeVO = null; if(formDefineVO.isLinkTypeFlag()){ linkTypeVO = linkTypeService.getLinkTypeById(formQuery.getBtmname()); queryFieldList.addAll(linkTypeVO.getAttributes().stream().map(OsLinkTypeAttributeVO::getId).collect(Collectors.toList())); queryFieldList.addAll(WebLoServiceImpl.LO_BASE_FIELD_MAP.values()); }else{ btmTypeVO = btmService.getBtmById(formQuery.getBtmname()); queryFieldList.addAll(btmTypeVO.getAttributes().stream().map(OsBtmTypeAttributeVO::getId).collect(Collectors.toList())); } queryFieldList.add("creator_name"); queryFieldList.add("lastmodifier_name"); Map conditionMap = WebUtil.getOidQuery(formQuery.getOid()); Map replaceMap = wrapperReplaceMap(formQuery.getSourceData()); UIFormDataVO formDataVO = new UIFormDataVO(); replaceMap.put("oid", formQuery.getOid().trim()); if(!formDefineVO.isLinkTypeFlag()) { List cbos = null; if (StringUtils.isNotBlank(queryTemplate)) { replaceMap.put("oid", formQuery.getOid().trim()); cbos = boService.queryCBOByScheme(queryTemplate, conditionMap, replaceMap, null, queryFieldList.stream().collect(Collectors.toList())); } else { //没有查询模板,那我们就直接主键和业务类型去查询 cbos = boService.queryCBO(formQuery.getBtmname(), conditionMap, null, queryFieldList.stream().collect(Collectors.toList())); } if (!CollectionUtils.isEmpty(cbos)) { BusinessObject cbo = cbos.get(0); formDataVO.setData(boService.cbo2Map(cbo)); } else { throw new VciBaseException(DATA_OID_NOT_EXIST); } }else{ UILinkTypeDataQuery linkTypeDataQuery = new UILinkTypeDataQuery(); linkTypeDataQuery.setQueryTemplateName(queryTemplate); linkTypeDataQuery.setReplaceMap(replaceMap); linkTypeDataQuery.setConditionMap(conditionMap); linkTypeDataQuery.setClauseList(queryFieldList); linkTypeDataQuery.setLinkType(formQuery.getBtmname()); //linkTypeDataQuery.setDirection(formQuery.isOrientation()); //linkTypeDataQuery.setToBtmType(treeDefineVO.getBtmType()); DataGrid dataGrid = loService.queryGridByScheme(linkTypeDataQuery); if (dataGrid != null && !CollectionUtils.isEmpty(dataGrid.getData())) { formDataVO.setData((Map) dataGrid.getData().get(0)); } } //查询附件 formDataVO.setAttachmentFileVOs(fileObjectService.listFilesByOwnbiz(formQuery.getOid(), formQuery.getBtmname(), "attachment")); List fileItems = formDefineVO.getItems().stream().filter(s -> UIFieldTypeEnum.FILE.getValue().equalsIgnoreCase(s.getType())).collect(Collectors.toList()); if(!CollectionUtils.isEmpty(fileItems)){ //字段的属性肯定不会超过1000个 //查询这些的值 List filePathList = new ArrayList<>(); fileItems.stream().forEach(field->{ Object value = formDataVO.getData().getOrDefault(field.getField(),null); if(value!=null && StringUtils.isNotBlank(value.toString())){ filePathList.add(value.toString()); } }); List fileObjectVOS = fileObjectService.listFileObjectByPath(filePathList, "filePathField"); if(!CollectionUtils.isEmpty(fileObjectVOS)){ Map fileObjectVOMap = fileObjectVOS.stream().collect(Collectors.toMap(s->s.getFilePath(),t->t,(o1,o2)->o2)); Map fieldFileVOMap = new HashMap<>(); fileItems.stream().forEach(field->{ Object value = formDataVO.getData().getOrDefault(field.getField(),null); if(value!=null){ VciFileObjectVO fileObjectVO = fileObjectVOMap.getOrDefault(value.toString(),null); if(fileObjectVO!=null){ fieldFileVOMap.put(field.getField(),fileObjectVO); } } }); formDataVO.setFilePathFieldMap(fieldFileVOMap); } } return formDataVO; } /** * 封装replaceMap * @param sourceDataMap 来源数据 * @return 替换后的值 */ private Map wrapperReplaceMap(Map sourceDataMap){ Map replaceMap =!CollectionUtils.isEmpty(sourceDataMap)? sourceDataMap:new HashMap<>(); if(!replaceMap.containsKey("f_oid")){ replaceMap.put("f_oid",replaceMap.getOrDefault("oid","")); } if(replaceMap.get("f_oid").contains(TREE_NODE_ID_SEP)){ replaceMap.put("f_oid",replaceMap.get("f_oid").split(TREE_NODE_ID_SEP)[1]); } return replaceMap; } /** * 树节点的分隔符不一样 */ private static final String TREE_NODE_ID_SEP = "@vcitreesep@"; /** * 获取树形数据 * * @param treeQuery 树形查询条件 * @return 树形数据 * @throws VciBaseException 查询出错的时候会抛出异常 */ @Override public List getDataForTree(UITreeQuery treeQuery) throws VciBaseException { VciBaseUtil.alertNotNull(treeQuery,"表单的查询对象",treeQuery.getBtmname(),"业务类型的信息",treeQuery.getComponentOid(),"树所在的组件的主键"); UIComponentVO componentVO = uiEngineService.getComponentByOid(treeQuery.getComponentOid()); if(componentVO == null || StringUtils.isBlank(componentVO.getOid())){ throw new VciBaseException("树的配置信息没有获取到"); } //树形有两种,一种是业务类型里自参照,一种是链接类型 UITreeDefineVO treeDefineVO = componentVO.getTreeDefineVO(); if(treeDefineVO == null){ throw new VciBaseException("这个组件不是树"); } if(!treeQuery.isLinkTypeFlag() && StringUtils.isBlank(treeQuery.getParentBtmName())){ treeQuery.setParentBtmName(treeQuery.getBtmname()); } if(treeQuery.getConditionMap() == null){ treeQuery.setConditionMap(new HashMap<>()); } if(treeQuery.getExtandParamsMap() != null){ treeQuery.getConditionMap().putAll(treeQuery.getExtandParamsMap()); } String parentFieldName = treeQuery.getParentFieldName(); if(parentFieldName.contains(",")){ parentFieldName = parentFieldName.split(",")[0]; } if(StringUtils.isNotBlank(parentFieldName)){ if(StringUtils.isNotBlank(treeQuery.getParentOid())){ treeQuery.getConditionMap().put(parentFieldName,treeQuery.getParentOid()); } } if(StringUtils.isNotBlank(treeQuery.getParentOid()) && treeQuery.getParentOid().contains(TREE_NODE_ID_SEP)){ treeQuery.setParentOid(treeQuery.getParentOid().split(TREE_NODE_ID_SEP)[1]); } String queryTemplate = StringUtils.isNotBlank(treeQuery.getQueryTemplate())?treeQuery.getQueryTemplate():(!CollectionUtils.isEmpty(treeQuery.getSourceData())?treeQuery.getSourceData().getOrDefault("querytemplate",treeDefineVO.getQueryTemplateName()):treeDefineVO.getQueryTemplateName()); String valueField = treeQuery.isLinkTypeFlag()?(!treeDefineVO.isOrientation()?"${oid}" + TREE_NODE_ID_SEP + "${t_oid}":"${oid}" + TREE_NODE_ID_SEP + "${f_oid}"):(StringUtils.isNotBlank(treeQuery.getValueField())?treeQuery.getValueField():"oid"); String textField = StringUtils.isNotBlank(treeDefineVO.getTreeNodeExpression())?treeDefineVO.getTreeNodeExpression():(StringUtils.isNotBlank(treeQuery.getTextField())?treeQuery.getTextField():"name"); List rootTreeList = new ArrayList<>(); List queryFieldList = new ArrayList<>(); queryFieldList.add("creator_name"); queryFieldList.add("lastmodifier_name"); String rootExpress = StringUtils.isNotBlank(treeQuery.getRootExpress())?treeQuery.getRootExpress():treeDefineVO.getRootContent(); Map replaceMap = wrapperReplaceMap(treeQuery.getSourceData()); if(StringUtils.isBlank(treeDefineVO.getLinkType())){ //这个是业务类型的自参照 //以前的平台没有对自参照这种有全部查询的 OsBtmTypeVO btmTypeVO = btmService.getBtmById(treeDefineVO.getBtmType()); queryFieldList.addAll(btmTypeVO.getAttributes().stream().map(OsBtmTypeAttributeVO::getId).collect(Collectors.toList())); queryFieldList.addAll(WebBoServiceImpl.BO_BASE_FIELD_MAP.values()); addQueryField(queryFieldList,valueField); addQueryField(queryFieldList,textField); if(treeQuery.isQueryRoot()){ //是查询根节点 List rootCbos = null; if(StringUtils.isNotBlank(queryTemplate)){ //说明是菜单里定义了查询模板的 rootCbos = boService.queryCBOByScheme(queryTemplate, null, replaceMap); }else{ //说明没有传递,这需要兼容以前的方式,就是在showLinkAps里设置 String parentFieldNameAndValue = treeDefineVO.getShowLinkAbs(); if(StringUtils.isBlank(parentFieldNameAndValue) || !parentFieldNameAndValue.contains(",")){ throw new VciBaseException("配置的信息有误。在没有在菜单或者来源数据设置根节点的查询模板时,请在树的【参照树】上设置上级字段的名称和根节点的查询的值。比如xxxx,yyy。其中xxxx是上级字段英文名称"); } parentFieldName= parentFieldNameAndValue.split(",")[0]; String rootQueryValue = parentFieldNameAndValue.split(",")[1]; treeQuery.getConditionMap().put(parentFieldName,rootQueryValue); replaceMap.put(parentFieldName,rootQueryValue); replaceMap.put("f_oid",rootQueryValue); if(StringUtils.isNotBlank(queryTemplate)){ rootCbos = boService.queryCBOByScheme(queryTemplate,treeQuery.getConditionMap(),replaceMap,null,queryFieldList); }else{ rootCbos = boService.queryCBO(treeDefineVO.getBtmType(),treeQuery.getConditionMap(),null,queryFieldList); } } if(!CollectionUtils.isEmpty(rootCbos)){ rootTreeList = cbo2Trees(rootCbos,valueField,StringUtils.isBlank(rootExpress)?textField:rootExpress,parentFieldName,treeQuery.isShowCheckBox(),null); TreeQueryObject treeQueryObject = new TreeQueryObject(); treeQueryObject.setValueField(valueField); treeQueryObject.setTextField(textField); treeQueryObject.setParentFieldName(parentFieldName); treeQueryObject.setShowCheckBox(treeQuery.isShowCheckBox()); if(UITreeLoadTypeEnum.ALL.getValue().equalsIgnoreCase(treeDefineVO.getLoadType())){ treeQueryObject.setQueryAllLevel(true); } queryTreeForBO(rootTreeList,treeDefineVO.getQueryTemplateName(),queryFieldList,treeQueryObject); } return rootTreeList; }else{ //这个不是跟节点,但是一般只是增加一个逐级查询,因为全部查询的时候,在根节点已经全部查询完了 List thisChildren = null; if (StringUtils.isNotBlank(queryTemplate)) { thisChildren = boService.queryCBOByScheme(queryTemplate, treeQuery.getConditionMap(), replaceMap, null, queryFieldList); } else { thisChildren = boService.queryCBO(treeQuery.getParentBtmName(), treeQuery.getConditionMap(), null, queryFieldList); } return cbo2Trees(thisChildren, valueField, textField, parentFieldName, treeQuery.isShowCheckBox(), null); } }else{ OsLinkTypeVO linkTypeVO = linkTypeService.getLinkTypeById(treeDefineVO.getLinkType()); queryFieldList.addAll(linkTypeVO.getAttributes().stream().map(OsLinkTypeAttributeVO::getId).collect(Collectors.toList())); queryFieldList.addAll(WebLoServiceImpl.LO_BASE_FIELD_MAP.values()); addQueryField(queryFieldList,valueField); addQueryField(queryFieldList,textField); UILinkTypeDataQuery linkTypeDataQuery = new UILinkTypeDataQuery(); linkTypeDataQuery.setQueryTemplateName(queryTemplate); linkTypeDataQuery.setReplaceMap(replaceMap); linkTypeDataQuery.setConditionMap(treeQuery.getConditionMap()); linkTypeDataQuery.setParentOid(treeQuery.getParentOid()); linkTypeDataQuery.setClauseList(queryFieldList); linkTypeDataQuery.setDirection(treeDefineVO.isOrientation()); linkTypeDataQuery.setToBtmType(treeDefineVO.getBtmType()); linkTypeDataQuery.setLinkType(treeDefineVO.getLinkType()); if(UITreeLoadTypeEnum.ALL.getValue().equalsIgnoreCase(treeDefineVO.getLoadType())){ linkTypeDataQuery.setQueryAllLevel(true); } if(treeQuery.isQueryRoot()){ //查询根节点.我们需要判断是否设置了根节点的查询条件 List rootCbos = null; String parentFieldNameAndValue = treeDefineVO.getShowLinkAbs(); if(StringUtils.isNotBlank(parentFieldNameAndValue)){ if(StringUtils.isNotBlank(queryTemplate)){ linkTypeDataQuery.setQueryAllLevel(false); //根节点只查询一次 //使用查询模板本身设置的内容 linkTypeDataQuery.setToBtmType(null); linkTypeDataQuery.setQueryTemplateName(queryTemplate); rootCbos = loService.queryCLOAndBOBySchema(linkTypeDataQuery); }else{ String rootQueryValue = ""; parentFieldName = parentFieldNameAndValue.split(",")[0]; rootQueryValue = parentFieldNameAndValue.split(",")[1]; treeQuery.getConditionMap().put(parentFieldName,rootQueryValue); linkTypeDataQuery.setQueryAllLevel(false); linkTypeDataQuery.setLinkType(treeDefineVO.getLinkType()); linkTypeDataQuery.setParentOid(rootQueryValue); rootCbos = loService.queryCLOAndBoByLinkType(linkTypeDataQuery); } if(!CollectionUtils.isEmpty(rootCbos)){ if(StringUtils.isBlank(parentFieldName)){ if(treeDefineVO.isOrientation()){ parentFieldName = "t_oid"; }else{ parentFieldName = "f_oid"; } } rootTreeList = cloAndCbo2Trees(rootCbos,valueField,rootExpress,parentFieldName,treeQuery.isShowCheckBox(),null); linkTypeDataQuery.setLinkType(treeDefineVO.getLinkType()); linkTypeDataQuery.setQueryTemplateName(queryTemplate); if(UITreeLoadTypeEnum.ALL.getValue().equalsIgnoreCase(treeDefineVO.getLoadType())){ linkTypeDataQuery.setQueryAllLevel(true); } queryTreeForLO(rootTreeList,linkTypeDataQuery,parentFieldName,valueField,textField,treeQuery.isShowCheckBox()); } return rootTreeList; }else{ //没有设置查询条件。那就是把来源数据作为根节点 if(CollectionUtils.isEmpty(replaceMap)){ throw new VciBaseException("根节点没有配置查询条件,也没有来源数据"); } Tree root = new Tree(); root.setOid(replaceMap.getOrDefault("oid",replaceMap.getOrDefault("t_oid",""))); root.setText(getValueByExpressForBOAndLO(new HashMap<>(),replaceMap,rootExpress)); root.setAttributes(replaceMap); root.setIndex("0"); rootTreeList.add(root); if(StringUtils.isBlank(parentFieldName)){ if(treeDefineVO.isOrientation()){ parentFieldName = "t_oid"; }else{ parentFieldName = "f_oid"; } } linkTypeDataQuery.setLinkType(treeDefineVO.getLinkType()); linkTypeDataQuery.setQueryTemplateName(queryTemplate); if(UITreeLoadTypeEnum.ALL.getValue().equalsIgnoreCase(treeDefineVO.getLoadType())){ linkTypeDataQuery.setQueryAllLevel(true); } queryTreeForLO(rootTreeList,linkTypeDataQuery,parentFieldName,valueField,textField,treeQuery.isShowCheckBox()); return rootTreeList; } }else{ if(StringUtils.isNotBlank(treeQuery.getParentOid())){ //有上级了。那replace的f_oid就应该设置为上级 if(linkTypeDataQuery.getReplaceMap() == null){ linkTypeDataQuery.setReplaceMap(new HashMap<>()); } linkTypeDataQuery.getReplaceMap().put(treeDefineVO.isOrientation()?"t_oid":"f_oid",treeQuery.getParentOid()); } return cloAndCbo2Trees(loService.queryCLOAndBoByLinkType(linkTypeDataQuery),valueField,textField,parentFieldName,treeQuery.isShowCheckBox(),treeQuery.getParentOid()); } } } /** * 业务类型的属性查询 * @param rootTreeList 根节点的内容 * @param queryTemplate 查询模板 * @param queryFieldList 查询的字段 * @param treeQueryObject 树形查询对象,需要valueField和textField,还有parentFieldName,和checkBox */ private void queryTreeForBO(List rootTreeList, String queryTemplate,List queryFieldList,TreeQueryObject treeQueryObject) { for (Tree rootTree : rootTreeList) { List thisChildren = null; Map sourceDataMap = rootTree.getAttributes(); sourceDataMap.put("f_oid",rootTree.getOid()); Map conditionMap = new HashMap<>(); conditionMap.put(treeQueryObject.getParentFieldName(),rootTree.getOid()); if (StringUtils.isNotBlank(queryTemplate)) { thisChildren = boService.queryCBOByScheme(queryTemplate, conditionMap, sourceDataMap, null, queryFieldList); } else { thisChildren = boService.queryCBO(sourceDataMap.getOrDefault("btmname",sourceDataMap.getOrDefault("btmName",treeQueryObject.getParentBtmName())), conditionMap, null, queryFieldList); } List childrenTree = cbo2Trees(thisChildren, treeQueryObject.getValueField(), treeQueryObject.getTextField(), treeQueryObject.getParentFieldName(), treeQueryObject.isShowCheckBox(), null); rootTree.setChildren(childrenTree); if(treeQueryObject.isQueryAllLevel() && !CollectionUtils.isEmpty(childrenTree) ) { queryTreeForBO(childrenTree,queryTemplate,queryFieldList,treeQueryObject); } } } /** * 查询链接类型的树形信息 * @param rootTreeList 根节点 * @param linkTypeDataQuery 链接类型查询对象 * @param parentFieldName 上级的主键的属性 * @param valueField 值表达式 * @param textField 显示表达式 * @param showCheckBox 是否显示复选框 */ private void queryTreeForLO(List rootTreeList, UILinkTypeDataQuery linkTypeDataQuery,String parentFieldName,String valueField,String textField,boolean showCheckBox) { for (Tree rootTree : rootTreeList) { Map conditionMap = new HashMap<>(); conditionMap.put(linkTypeDataQuery.isDirection()?"t_oid":"f_oid",rootTree.getOid()); linkTypeDataQuery.setConditionMap(conditionMap); linkTypeDataQuery.setParentOid(rootTree.getOid()); rootTree.setChildren(cloAndCbo2Trees(loService.queryCLOAndBoByLinkType(linkTypeDataQuery),valueField,textField,parentFieldName,showCheckBox,rootTree.getOid())); } } /** * 业务类型数据转换为树 * @param cbos 业务数据 * @param valueField 值的表达式 * @param textField 显示表达式 * @param parentFieldName 上级字段属性 * @param showCheckBox 显示复选框 * @param parentOid 上级的主键 * @return 树 */ private List cbo2Trees(Collection cbos,String valueField,String textField,String parentFieldName,boolean showCheckBox,String parentOid){ final int[] i = {0}; List rootList = new ArrayList<>(); List children = new ArrayList<>(); cbos.stream().forEach(cbo->{ Tree tree = new Tree(); tree.setOid(getValueByExpress(cbo,valueField)); tree.setText(getValueByExpress(cbo,textField)); if(StringUtils.isNotBlank(parentFieldName)){ tree.setParentId(ObjectTool.getBOAttributeValue(cbo,parentFieldName)); } tree.setAttributes(boService.cbo2Map(cbo)); tree.setIndex(i[0] + ""); i[0]++; tree.setChecked(showCheckBox); //暂时不处理图标 if(StringUtils.isBlank(tree.getParentId() ) || tree.getParentId().equalsIgnoreCase(parentOid)){ rootList.add(tree); }else{ children.add(tree); } }); if(rootList.size() == 0 && children.size() == 0){ return rootList; } return Tree.getChildList(rootList,children); } /** * 链接类型转换为树 * @param boAndLOS 业务类型和链接类型 * @param valueField 值表达式 * @param textField 显示文本表达式 * @param parentFieldName 上级字段,默认是f_oid,反向的时候请自行设置 * @param showCheckBox 是否显示复选框 * @param parentOid 上级的值 * @return 树形数据 */ public List cloAndCbo2Trees(Collection boAndLOS,String valueField,String textField,String parentFieldName,boolean showCheckBox,String parentOid){ final int[] i = {0}; List rootList = new ArrayList<>(); List children = new ArrayList<>(); boAndLOS.stream().forEach(boAndLO->{ Tree tree = new Tree(); BusinessObject cbo = new BusinessObject(); cbo = boAndLO.bo; LinkObject clo = new LinkObject(); clo = boAndLO.lo; Map cloMap = loService.clo2Map(clo); Map cbo2Map = boService.cbo2Map(cbo); if(!CollectionUtils.isEmpty(cbo2Map)){ cbo2Map.forEach((key,value)->{ cloMap.put(parentFieldName + "." + key,value); }); } tree.setOid(getValueByExpressForBOAndLO(cloMap,cbo2Map,valueField)); tree.setText(getValueByExpressForBOAndLO(cloMap,cbo2Map,textField)); if(StringUtils.isBlank(parentFieldName)){ tree.setParentId(boAndLO.lo.oid + TREE_NODE_ID_SEP + boAndLO.lo.fromOid); }else { if (parentFieldName.contains(".")) { tree.setParentId(ObjectTool.getBOAttributeValue(cbo,parentFieldName)); } else { tree.setParentId(ObjectTool.getLOAttributeValue(clo,parentFieldName)); } } tree.setAttributes(cbo2Map); tree.setIndex(i[0] + ""); i[0]++; tree.setChecked(showCheckBox); //暂时不处理图标 if(StringUtils.isBlank(tree.getParentId() ) || tree.getParentId().equalsIgnoreCase(parentOid)){ rootList.add(tree); }else{ children.add(tree); } }); return Tree.getChildList(rootList,children); } /** * 获取值, 含有${xxx}的时候,表示为替换的方式,没有则用空格分隔 * @param cbo 业务数据 * @param fieldExpress 表达式的值 * @return 转换后的值 */ private String getValueByExpress(BusinessObject cbo,String fieldExpress){ if(StringUtils.isBlank(fieldExpress)){ return ""; } if(fieldExpress.contains("${")){ //使用freemarker处理 return VciBaseUtil.replaceByFreeMarker(fieldExpress,boService.cbo2Map(cbo)); }else { List fieldList = VciBaseUtil.str2List(fieldExpress); StringBuilder sb = new StringBuilder(); fieldList.stream().forEach(field->{ sb.append(ObjectTool.getBOAttributeValue(cbo,field)).append(" "); }); return sb.toString().trim(); } } /** * 获取连接类型 * @param valueMap 链接类型和业务类型的数据 * @param fieldExpress 表达式 * @return 替换后的值 */ private String getValueByExpressForBOAndLO(Map valueMap,Map boValueMap,String fieldExpress){ if(fieldExpress.contains("${")){ //使用freemarker处理 return VciBaseUtil.replaceByFreeMarker(fieldExpress,valueMap); }else { List fieldList = VciBaseUtil.str2List(fieldExpress); Map valueLowMap = new HashMap<>(); valueMap.forEach((key,value)->{ valueLowMap.put(key.toLowerCase(),value); }); Map boLowValueMap = new HashMap<>(); if(!CollectionUtils.isEmpty(boValueMap)){ boValueMap.forEach((key,value)->{ boLowValueMap.put(key.toLowerCase(),value); }); } StringBuilder sb = new StringBuilder(); fieldList.stream().forEach(field->{ sb.append(valueLowMap.getOrDefault(field,boLowValueMap.getOrDefault(field,""))).append(" "); }); return sb.toString().trim(); } } /** * 处理要查询的字段 * @param queryFieldList 查询的字段列表 * @param fieldExpress 字段表达式 */ private void addQueryField(List queryFieldList,String fieldExpress){ if(fieldExpress.contains("${")){ String temp = fieldExpress; //比如 ${id} ${name} / ${rev} while(temp.contains("${")){ int dollar = temp.indexOf("${"); int brackets = temp.indexOf("}"); String tempField = temp.substring(dollar+2,brackets); if (!queryFieldList.contains(tempField.trim().toLowerCase())){ queryFieldList.add(tempField.trim().toLowerCase()); } temp = temp.substring(brackets+1); } }else { List fieldList = VciBaseUtil.str2List(fieldExpress); fieldList.stream().forEach(field->{ if (!queryFieldList.contains(field.toLowerCase())) { queryFieldList.add(field.toLowerCase()); } }); } } /** * 调用前置事件 * @param baseModelDTOList 业务数据的信息 * @param baseLinkModelDTOList 链接类型的数据信息 * @param preEvent 前置事件的名称 * @param businessType 调用的类型 * @return 执行结果,请判断success属性是否为true * @throws VciBaseException 配置或者是调用不成功的时候,会抛出异常 */ @Override public BaseResult callPreEvent(BaseModelDTOList baseModelDTOList,BaseLinkModelDTOList baseLinkModelDTOList, String preEvent, VciChangeDocumentTypeEnum businessType) throws VciBaseException{ if((baseModelDTOList == null || CollectionUtils.isEmpty(baseModelDTOList.getDataList())) && (baseLinkModelDTOList == null || CollectionUtils.isEmpty(baseLinkModelDTOList.getDataList()))){ return BaseResult.success(); } String btmType = (baseModelDTOList !=null && !CollectionUtils.isEmpty(baseModelDTOList.getDataList()))? baseModelDTOList.getDataList().get(0).getBtmname():null; String linkType = (baseLinkModelDTOList !=null && !CollectionUtils.isEmpty(baseLinkModelDTOList.getDataList()))?baseLinkModelDTOList.getDataList().get(0).getLinkType():null; if(StringUtils.isNotBlank(preEvent)){ //前置事件 //bean的名字#方法; 或者全路径。最后一个是方法的名字 Method method = null; Object bean = null; String beanName = null; String methodName = null; if(preEvent.contains("#")){ //说明是bean的名字#的方法 beanName = preEvent.split("#")[0]; methodName = preEvent.split("#")[1]; String configMsg = "配置的前置事件有误,需要 bean的名字#方法名字 这种形式,其中这个bean需要加@Component或者@Service的注解.如果注解里没有指定名称,默认为这个class的名称(且第一个字母变小写)"; if(StringUtils.isBlank(beanName) || StringUtils.isBlank(methodName)){ throw new VciBaseException(configMsg); } bean = ApplicationContextProvider.getBean(beanName); if(bean == null){ throw new VciBaseException(configMsg); } method = VciBaseUtil.getMethodByName(bean.getClass(),methodName); if(method == null){ throw new VciBaseException("{0}这个组件中没有找到{1}的方法,请开发者确认",new String[]{beanName,methodName}); } }else{ if(!preEvent.contains(".")){ throw new VciBaseException("前置事件的全路径配置错误,需要class的全路径+方法名字,目前的配置是{0},请开发者确认",new String[]{preEvent}); } //全路径 beanName = preEvent.substring(0,preEvent.lastIndexOf(".")); methodName = preEvent.substring(preEvent.lastIndexOf(".") + 1); Class classInstance = null; try { classInstance = Class.forName(beanName); } catch (ClassNotFoundException e) { throw new VciBaseException(LangBaseUtil.getErrorMsg(e),new String[]{beanName,methodName},e); } try { bean = classInstance.newInstance(); } catch (Throwable e) { throw new VciBaseException(LangBaseUtil.getErrorMsg(e),new String[]{beanName,methodName},e); } method = VciBaseUtil.getMethodByName(classInstance,methodName); if(method == null){ throw new VciBaseException("{0}这个组件中没有找到{1}的方法,请开发者确认",new String[]{beanName,methodName}); } } try { return (BaseResult)method.invoke(bean,baseModelDTOList); } catch (Throwable e) { throw new VciBaseException(LangBaseUtil.getErrorMsg(e),new String[]{beanName,methodName},e); } }else{ //直接获取注解 Map beanMap = ApplicationContextProvider.getApplicationContext().getBeansWithAnnotation(VciChangeDataPlugin.class); if(!CollectionUtils.isEmpty(beanMap)){ beanMap.forEach((beanName,bean)->{ Method[] methods = bean.getClass().getMethods(); List hasBeforeMethods = Arrays.stream(methods).filter(m -> m.isAnnotationPresent(VciChangeDataBefore.class)).collect(Collectors.toList()); if(!CollectionUtils.isEmpty(hasBeforeMethods)){ hasBeforeMethods.stream().forEach(method -> { VciChangeDataBefore before = method.getAnnotation(VciChangeDataBefore.class); if(before == null){ before = method.getDeclaredAnnotation(VciChangeDataBefore.class); } if(StringUtils.isNotBlank(btmType) && before.btmType().equals(btmType) && before.changeType().equals(businessType)){ try { BaseResult result = (BaseResult) method.invoke(bean, baseModelDTOList); if(!result.isSuccess()){ throw new VciBaseException(result.getMsg(),result.getMsgObjs()); } }catch (Throwable e){ throw new VciBaseException(LangBaseUtil.getErrorMsg(e),new String[]{beanName,method.getName()},e); } } if(StringUtils.isNotBlank(linkType) && before.btmType().equals(linkType) && before.changeType().equals(businessType)){ try { BaseResult result = (BaseResult) method.invoke(bean, baseLinkModelDTOList); if(!result.isSuccess()){ throw new VciBaseException(result.getMsg(),result.getMsgObjs()); } }catch (Throwable e){ throw new VciBaseException(LangBaseUtil.getErrorMsg(e),new String[]{beanName,method.getName()},e); } } }); } }); } } return BaseResult.success(); } /** * 后置事件 * @param cbos 添加完成后内容 * @param postEvent 后置事件的名称,如果为空会自动扫描是否有注解 * @param businessType 业务操作的类型 * @return 执行的结果 * @throws VciBaseException 执行出错的会抛出异常,或者事件直接返回了异常 */ @Override public BaseResult callPostEvent(Collection cbos, Collection clos, String postEvent, VciChangeDocumentTypeEnum businessType) throws VciBaseException{ if(CollectionUtils.isEmpty(cbos)){ return BaseResult.success(); } String btmType = !CollectionUtils.isEmpty(cbos)?cbos.stream().findFirst().get().btName:null; String linkType = !CollectionUtils.isEmpty(clos)?clos.stream().findFirst().get().ltName:null; if(StringUtils.isNotBlank(postEvent)){ //前置事件 //bean的名字#方法; 或者全路径。最后一个是方法的名字 Method method = null; Object bean = null; String beanName = null; String methodName = null; if(postEvent.contains("#")){ //说明是bean的名字#的方法 beanName = postEvent.split("#")[0]; methodName = postEvent.split("#")[1]; String configMsg = "配置的后置事件有误,需要 bean的名字#方法名字 这种形式,其中这个bean需要加@Component或者@Service的注解.如果注解里没有指定名称,默认为这个class的名称(且第一个字母变小写)"; if(StringUtils.isBlank(beanName) || StringUtils.isBlank(methodName)){ throw new VciBaseException(configMsg); } bean = ApplicationContextProvider.getBean(beanName); if(bean == null){ throw new VciBaseException(configMsg); } method = VciBaseUtil.getMethodByName(bean.getClass(),methodName); if(method == null){ throw new VciBaseException("{0}这个组件中没有找到{1}的方法,请开发者确认",new String[]{beanName,methodName}); } }else{ if(!postEvent.contains(".")){ throw new VciBaseException("后置事件的全路径配置错误,需要class的全路径+方法名字,目前的配置是{0},请开发者确认",new String[]{postEvent}); } //全路径 beanName = postEvent.substring(0,postEvent.lastIndexOf(".")); methodName = postEvent.substring(postEvent.lastIndexOf(".") + 1); Class classInstance = null; try { classInstance = Class.forName(beanName); } catch (ClassNotFoundException e) { throw new VciBaseException(LangBaseUtil.getErrorMsg(e),new String[]{beanName,methodName},e); } try { bean = classInstance.newInstance(); } catch (Throwable e) { throw new VciBaseException(LangBaseUtil.getErrorMsg(e),new String[]{beanName,methodName},e); } method = VciBaseUtil.getMethodByName(classInstance,methodName); if(method == null){ throw new VciBaseException("{0}这个组件中没有找到{1}的方法,请开发者确认",new String[]{beanName,methodName}); } } try { return (BaseResult)method.invoke(bean,cbos); } catch (Throwable e) { throw new VciBaseException(LangBaseUtil.getErrorMsg(e),new String[]{beanName,methodName},e); } }else{ //直接获取注解 Map beanMap = ApplicationContextProvider.getApplicationContext().getBeansWithAnnotation(VciChangeDataPlugin.class); if(!CollectionUtils.isEmpty(beanMap)){ beanMap.forEach((beanName,bean)->{ Method[] methods = bean.getClass().getMethods(); List hasBeforeMethods = Arrays.stream(methods).filter(m -> m.isAnnotationPresent(VciChangeDataAfter.class)).collect(Collectors.toList()); if(!CollectionUtils.isEmpty(hasBeforeMethods)){ hasBeforeMethods.stream().forEach(method -> { VciChangeDataAfter after = method.getAnnotation(VciChangeDataAfter.class); if(after == null){ after = method.getDeclaredAnnotation(VciChangeDataAfter.class); } if(StringUtils.isNotBlank(btmType) && after.btmType().equals(btmType) && after.changeType().equals(businessType)){ try { BaseResult result = (BaseResult) method.invoke(bean, cbos); if(!result.isSuccess()){ throw new VciBaseException(result.getMsg(),result.getMsgObjs()); } }catch (Throwable e){ throw new VciBaseException(LangBaseUtil.getErrorMsg(e),new String[]{beanName,method.getName()},e); } } if(StringUtils.isNotBlank(linkType) && after.btmType().equals(linkType) && after.changeType().equals(businessType)){ try { BaseResult result = (BaseResult) method.invoke(bean, clos); if(!result.isSuccess()){ throw new VciBaseException(result.getMsg(),result.getMsgObjs()); } }catch (Throwable e){ throw new VciBaseException(LangBaseUtil.getErrorMsg(e),new String[]{beanName,method.getName()},e); } } }); } }); } } return BaseResult.success(); } /** * 表单数据转换为基础对象 * @param formDataDTO 表单数据 * @return 基础对象列表 */ @Override public BaseModelDTOList formData2DTOList(FormDataDTO formDataDTO){ BaseModelDTOList modelDTOList = new BaseModelDTOList(); BaseModelDTO modelDTO = new BaseModelDTO(); BeanUtil.convert((BaseModelDTO)formDataDTO,modelDTO); modelDTO.setData(formDataDTO.getData()); List modelDTOS = new ArrayList<>(); modelDTOS.add(modelDTO); modelDTOList.setDataList(modelDTOS); return modelDTOList; } /** * 链接数据 转换为基础对象 * @param formLinkDataDTO 表单数据 * @return 基础数据列表 */ @Override public BaseLinkModelDTOList formLinkData2DTOList(FormLinkDataDTO formLinkDataDTO){ BaseLinkModelDTOList modelDTOList = new BaseLinkModelDTOList(); BaseLinkModelDTO modelDTO = new BaseLinkModelDTO(); modelDTO.setData(formLinkDataDTO.getData()); BeanUtil.convert((BaseLinkModelDTO)formLinkDataDTO,modelDTO); List linkModelDTOS = new ArrayList<>(); linkModelDTOS.add(modelDTO); modelDTOList.setDataList(linkModelDTOS); return modelDTOList; } /** * 表单的数据转换为 * @param formDataDTOList 表单数据 * @return 基础对象列表 */ @Override public BaseModelDTOList formDataList2DTOList(FormDataDTOList formDataDTOList){ BaseModelDTOList modelDTOList = new BaseModelDTOList(); List modelDTOS = new ArrayList<>(); modelDTOS.stream().findAny().orElseGet(()->null); formDataDTOList.getFormDataDTOS().forEach(formDataDTO -> { BaseModelDTO modelDTO = new BaseModelDTO(); BeanUtil.convert((BaseModelDTO)formDataDTO,modelDTO); modelDTO.setData(formDataDTO.getData()); modelDTOS.add(modelDTO); }); modelDTOList.setDataList(modelDTOS); return modelDTOList; } /** * 链接类型批量转换 * @param formLinkDataDTOList 表单的数据 * @return 基础对象列表 */ @Override public BaseLinkModelDTOList formLinkDataList2DTOList(FormLinkDataDTOList formLinkDataDTOList){ BaseLinkModelDTOList modelDTOList = new BaseLinkModelDTOList(); List modelDTOS = new ArrayList<>(); formLinkDataDTOList.getDataDTOList().forEach(formDataDTO -> { BaseLinkModelDTO modelDTO = new BaseLinkModelDTO(); BeanUtil.convert((BaseLinkModelDTO)formDataDTO,modelDTO); modelDTO.setData(formDataDTO.getData()); modelDTOS.add(modelDTO); }); modelDTOList.setDataList(modelDTOS); return modelDTOList; } /** * 添加数据 * * @param formDataDTO 数据的传输对象 * @return 执行结果和显示后的值 * @throws VciBaseException 保存出错的时候会抛出异常 */ @Override public BaseResult> addSave(FormDataDTO formDataDTO) throws VciBaseException { //首先判断对象是否为空 VciBaseUtil.alertNotNull(formDataDTO,"添加的数据对象",formDataDTO.getBtmname(),"业务类型的名称",formDataDTO.getFormDefineId(),"表单定义的编号"); UIFormDefineVO formDefineVO = uiEngineService.getFormById(formDataDTO.getBtmname(), formDataDTO.getFormDefineId()); String preEvent = formDataDTO.getPreEvent(); BaseModelDTOList modelDTOList = formData2DTOList(formDataDTO); BaseResult beforeResult = callPreEvent(modelDTOList, null,preEvent, VciChangeDocumentTypeEnum.ADD); if(!beforeResult.isSuccess()){ //说明前置事件没有执行成功 return beforeResult; } //封装数据 BaseResult resultCbo = wrapperCbo(formDataDTO,formDefineVO,false,false,false); if(!resultCbo.isSuccess()){ return BaseResult.fail(resultCbo.getMsg(),resultCbo.getMsgObjs()); } //执行保存 BaseResult> result = BaseResult.success(); BusinessObject afterCBO = null; try { BusinessObject resultBO = platformClientUtil.getBOFService().createBusinessObject(resultCbo.getObj(),false,false); afterCBO = new BusinessObject(); afterCBO = resultBO; result.setObj(boService.cbo2Map(afterCBO)); } catch (PLException vciError) { throw WebUtil.getVciBaseException(vciError); } if(!CollectionUtils.isEmpty(formDataDTO.getReleaseFileOids())){ fileObjectService.releasedFile(afterCBO.btName,afterCBO.oid,formDataDTO.getReleaseFileOids()); } //后置事件 String afterEvent = formDataDTO.getPostEvent(); try { callPostEvent(Arrays.stream(new BusinessObject[]{afterCBO}).collect(Collectors.toList()),null, afterEvent, VciChangeDocumentTypeEnum.ADD); }catch (Throwable e){ //说明后置事件出现了错误,那么就需要删除以前的这条数据 try { platformClientUtil.getBOFService().deleteBusinessObject(afterCBO,1); } catch (PLException vciError) { throw WebUtil.getVciBaseException(vciError); } throw new VciBaseException(LangBaseUtil.getErrorMsg(e),new String[]{},e); } return result; } /** * 封装cbo对象 * @param formDataDTO 表单数据 * @param formDefineVO 表单的定义 * @param editFlag 是否为编辑 * @param newRevision 新版本 * @param newVersion 新版次 * @return 执行的结果 */ private BaseResult wrapperCbo(FormDataDTO formDataDTO,UIFormDefineVO formDefineVO,boolean editFlag,boolean newRevision,boolean newVersion){ //扩展属性的值 Map data = formDataDTO.getData(); Map dataLow = new HashMap<>(); data.forEach((key,value)->{ dataLow.put(key.toLowerCase(),value); }); String oid = formDataDTO.getOid(); Date ts = formDataDTO.getTs(); if(editFlag && StringUtils.isBlank(oid)){ //修改的时候主键不能为空 throw new VciBaseException("修改的时候,数据的主键不能为空"); } if((newRevision || newRevision) && StringUtils.isBlank(formDataDTO.getCopyFromVersion())){ throw new VciBaseException("升版的时候,老版本数据的主键不能为空"); } if(editFlag &&ts !=null){ Map conditionMap = WebUtil.getOidQuery(oid); conditionMap.put("ts", VciDateUtil.date2Str(ts,VciDateUtil.DateTimeMillFormat)); conditionMap.put("oid",oid); if(boService.queryCount(formDefineVO.getBtmType(),conditionMap) ==0){ throw new VciBaseException("数据不是最新的,建议您刷新后重新操作"); } } //默认属性的值 Map baseDataMap = formDataDTO2MapLow(formDataDTO); Map allDataMapLow = new HashMap<>(); allDataMapLow.putAll(dataLow); allDataMapLow.putAll(baseDataMap); //判断必输项 BaseResult result = checkRequired(formDefineVO,null,allDataMapLow); if(!result.isSuccess()){ return result; } //判断唯一项 result = checkUnique(formDefineVO,null,allDataMapLow,editFlag); if(!result.isSuccess()){ return result; } BusinessObject cbo = createOrGetCbo(dataLow,baseDataMap,editFlag,newRevision,newVersion); return BaseResult.success(cbo); } /** * 业务类型 * @param cbo 业务数据对象 * @return 基础对象 */ @Override public BaseModel cbo2BaseModel(BusinessObject cbo){ BaseModel baseModel = new BaseModel(); baseModel.setOid(cbo.oid); baseModel.setNameOid(cbo.nameoid); baseModel.setRevisionOid(cbo.revisionid); baseModel.setBtmname(cbo.btName); baseModel.setLastR(String.valueOf(cbo.isLastR)); baseModel.setLastV(String.valueOf(cbo.isLastV)); baseModel.setFirstR(String.valueOf(cbo.isFirstR)); baseModel.setFirstV(String.valueOf(cbo.isFirstV)); baseModel.setCreator(cbo.creator); try { baseModel.setCreateTime(new Date(cbo.createTime)); baseModel.setLastModifyTime(new Date(cbo.modifyTime)); baseModel.setTs(new Date(cbo.ts)); // baseModel.setCheckInTime(VciDateUtil.str2Date(cbo.getCheckinTime(), VciDateUtil.DateTimeFormat)); // baseModel.setCheckOutTime(VciDateUtil.str2Date(cbo.getCheckoutTime(), VciDateUtil.DateTimeFormat)); }catch (Throwable e){ } baseModel.setLastModifier(cbo.modifier); baseModel.setRevisionRule(cbo.revisionRule); baseModel.setVersionRule(cbo.versionRule); baseModel.setRevisionSeq(cbo.revisionSeq); baseModel.setRevisionValue(cbo.revisionValue); baseModel.setVersionSeq(cbo.versionSeq); baseModel.setVersionValue(cbo.versionValue); baseModel.setLcStatus(cbo.lcStatus); baseModel.setId(cbo.id); baseModel.setName(cbo.name); baseModel.setDescription(cbo.description); baseModel.setOwner(cbo.owner); // baseModel.setCheckInBy(cbo.getCheckinBy()); // baseModel.setCheckOutBy(cbo.getCheckoutBy()); baseModel.setCopyFromVersion(cbo.fromVersion); return baseModel; } /** * 业务数据表单对象转换为基础的属性 * @param formDataDTO 表的数据传输对象 * @return 数据的映射内容 */ @Override public Map formDataDTO2MapLow(FormDataDTO formDataDTO){ Map data = new HashMap<>(); BaseModel baseModel = (BaseModel)formDataDTO; Map map = WebUtil.objectToMapString(baseModel); if(!CollectionUtils.isEmpty(map)){ map.forEach((key,value)->{ data.put(key.toLowerCase(),value); }); } return data; } /** * 链接数据表单对象转换为基础的属性 * @param formLinkDataDTO 表的数据传输对象 * @return 数据的映射内容 */ @Override public Map formLinkDataDTO2MapLow(FormLinkDataDTO formLinkDataDTO){ Map data = new HashMap<>(); BaseLinkModelDTO baseModel = (BaseLinkModelDTO)formLinkDataDTO; Map map = WebUtil.objectToMapString(baseModel); if(!CollectionUtils.isEmpty(map)){ map.forEach((key,value)->{ data.put(WebLoServiceImpl.LO_BASE_FIELD_MAP.getOrDefault(key.toLowerCase(),key.toLowerCase()),value); }); } return data; } /** * 获取下一个版本号 * @param btmTypeVO 业务类型的显示对象 * @param baseModel 基础对象 * @return 版本的对象 */ @Override public RevisionDataInfo getNextRevision(OsBtmTypeVO btmTypeVO, BaseModel baseModel){ try { if(baseModel.getRevisionValue() == null){ baseModel.setRevisionValue(""); } return changeRevisionValueInfoToObject(platformClientUtil.getBOFactoryService().getNextRevisionValueObject(btmTypeVO.getId(),baseModel.getNameOid(),btmTypeVO.getRevisionRuleId(),btmTypeVO.isInputRevisionFlag(),baseModel.getRevisionValue())); } catch (PLException vciError) { throw WebUtil.getVciBaseException(vciError); } } /** * 版本值的corba对象转换为java * @param info corba对象 * @return java对象 */ private RevisionDataInfo changeRevisionValueInfoToObject(RevisionDataInfo info) { RevisionDataInfo object = new RevisionDataInfo(); object.revisionVal = info.revisionVal; object.revisionSeq = info.revisionSeq; return object; } /** * 获取下一个版次的号 * @param btmTypeVO 业务类型的显示对象 * @param baseModel 基础对象 * @return 版本的值对象 */ @Override public VersionDataInfo getNextVersion(OsBtmTypeVO btmTypeVO, BaseModel baseModel){ try{ return changeRevisionValueInfoToObject(platformClientUtil.getBOFactoryService().getNextVersionValue(WebUtil.getTableName(btmTypeVO.getId()),baseModel.getRevisionOid(),baseModel.getNameOid(),WebUtil.getInt(btmTypeVO.getVersionRule()))); }catch (PLException vciError){ throw WebUtil.getVciBaseException(vciError); } } /** * 转换版次的值的对象 * @param info 版次的值 * @return java对象 */ private VersionDataInfo changeRevisionValueInfoToObject(VersionDataInfo info) { VersionDataInfo object = new VersionDataInfo(); object.versionVal = info.versionVal; object.versionSeq = info.versionSeq; return object; } /** * 获取第一个版次 * @param versionRule 版次的规则 * @return 第一个版次 */ @Override public String getFirstVersion(String versionRule){ if("0".equalsIgnoreCase(versionRule)){ return "1"; }else if("1".equalsIgnoreCase(versionRule)){ return "a"; }else if("2".equalsIgnoreCase(versionRule)){ return "0"; }else{ //没有版次 return ""; } } /** * 批量添加数据 * * @param formDataDTOList 数据的传输对象 * @return 执行结果和主键 * @throws VciBaseException 保存出错的时候会抛出异常 */ @Override public BaseResult batchAddSave(FormDataDTOList formDataDTOList) throws VciBaseException { VciBaseUtil.alertNotNull(formDataDTOList,"要添加的数据",formDataDTOList.getFormDataDTOS(),"要添加的数据"); //首先判断对象是否为空 FormDataDTO firstFormDataDTO = formDataDTOList.getFormDataDTOS().stream().findFirst().get(); UIFormDefineVO formDefineVO = uiEngineService.getFormById(firstFormDataDTO.getBtmname(), firstFormDataDTO.getId()); String preEvent = firstFormDataDTO.getPreEvent(); BaseModelDTOList modelDTOList = formDataList2DTOList(formDataDTOList); BaseResult beforeResult = callPreEvent(modelDTOList, null, preEvent, VciChangeDocumentTypeEnum.ADD); if(!beforeResult.isSuccess()){ //说明前置事件没有执行成功 return beforeResult; } //封装数据 List addBos = new ArrayList<>(); List afterBOs = new ArrayList<>(); List afterCBOs = new ArrayList<>(); Map> releasedFileOids = new HashMap<>(); for(FormDataDTO formDataDTO:formDataDTOList.getFormDataDTOS()) { BaseResult resultCbo = wrapperCbo(formDataDTO, formDefineVO, false, false, false); if (!resultCbo.isSuccess()) { return BaseResult.fail(resultCbo.getMsg(), resultCbo.getMsgObjs()); } addBos.add(resultCbo.getObj()); //执行保存 if (!CollectionUtils.isEmpty(formDataDTO.getReleaseFileOids())) { releasedFileOids.put(resultCbo.getObj().oid,formDataDTO.getReleaseFileOids()); } } try { BusinessObject[] resultBOs = platformClientUtil.getBOFService().batchCreateBusinessObject(addBos.toArray(new BusinessObject[0]), false, false); afterBOs = Arrays.stream(resultBOs).collect(Collectors.toList()); Arrays.stream(resultBOs).forEach(bo->{ BusinessObject cbo = new BusinessObject(); cbo = bo; afterCBOs.add(cbo); }); } catch (PLException vciError) { throw WebUtil.getVciBaseException(vciError); } if(!CollectionUtils.isEmpty(releasedFileOids)){ releasedFileOids.forEach((oid,fileOids)->{ fileObjectService.releasedFile(firstFormDataDTO.getBtmname(),oid,fileOids); }); } //后置事件 String afterEvent = firstFormDataDTO.getPostEvent(); try { callPostEvent(afterCBOs, null,afterEvent, VciChangeDocumentTypeEnum.ADD); }catch (Throwable e){ //说明后置事件出现了错误,那么就需要删除以前的这条数据 try { platformClientUtil.getBOFactoryService().batchDeleteBusinessObject(afterBOs.toArray(new BusinessObject[0]),1); } catch (PLException vciError) { throw WebUtil.getVciBaseException(vciError); } throw new VciBaseException(LangBaseUtil.getErrorMsg(e),new String[]{},e); } BaseResult result = BaseResult.success(); result.setData(afterBOs.stream().map(s->s.oid).collect(Collectors.toList())); return result; } /** * 修改数据。注意表单定义的字段才会被修改,ts这种默认字段除外 * * @param formDataDTO 数据的传输对象 * @return 执行结果和显示后的值 * @throws VciBaseException 保存出错的时候会抛出异常 */ @Override public BaseResult> editSave(FormDataDTO formDataDTO) throws VciBaseException { //首先判断对象是否为空 VciBaseUtil.alertNotNull(formDataDTO,"修改的数据对象",formDataDTO.getBtmname(),"业务类型的名称",formDataDTO.getFormDefineId(),"表单定义的编号"); UIFormDefineVO formDefineVO = uiEngineService.getFormById(formDataDTO.getBtmname(), formDataDTO.getFormDefineId()); String preEvent = formDataDTO.getPreEvent(); BaseModelDTOList modelDTOList = formData2DTOList(formDataDTO); BaseResult beforeResult = callPreEvent(modelDTOList,null, preEvent, VciChangeDocumentTypeEnum.EDIT); if(!beforeResult.isSuccess()){ //说明前置事件没有执行成功 return beforeResult; } //封装数据 BaseResult resultCbo = wrapperCbo(formDataDTO,formDefineVO,true,false,false); if(!resultCbo.isSuccess()){ return BaseResult.fail(resultCbo.getMsg(),resultCbo.getMsgObjs()); } //执行保存 BaseResult> result = BaseResult.success(); try { platformClientUtil.getBOFService().updateBusinessObject(resultCbo.getObj()); result.setObj(boService.cbo2Map(resultCbo.getObj())); } catch (PLException vciError) { throw WebUtil.getVciBaseException(vciError); } if(!CollectionUtils.isEmpty(formDataDTO.getReleaseFileOids())){ fileObjectService.releasedFile(resultCbo.getObj().btName,resultCbo.getObj().oid,formDataDTO.getReleaseFileOids()); } //后置事件 String afterEvent = formDataDTO.getPostEvent(); try { callPostEvent(Arrays.stream(new BusinessObject[]{resultCbo.getObj()}).collect(Collectors.toList()), null,afterEvent, VciChangeDocumentTypeEnum.EDIT); }catch (Throwable e){ throw new VciBaseException(LangBaseUtil.getErrorMsg(e),new String[]{},e); } return result; } /** * 数据升版 * * @param formDataDTO 数据的传输对象 * @return 执行结果和显示后的值 * @throws VciBaseException 保存出错的时候会抛出异常 */ @Override public BaseResult> upRevision(FormDataDTO formDataDTO) throws VciBaseException, PLException { //首先判断对象是否为空 VciBaseUtil.alertNotNull(formDataDTO,"修改的数据对象",formDataDTO.getBtmname(),"业务类型的名称",formDataDTO.getFormDefineId(),"表单定义的编号",formDataDTO.getCopyFromVersion(),"老版本的主键"); UIFormDefineVO formDefineVO = uiEngineService.getFormById(formDataDTO.getBtmname(), formDataDTO.getFormDefineId()); String preEvent = formDataDTO.getPreEvent(); BaseModelDTOList modelDTOList = formData2DTOList(formDataDTO); BaseResult beforeResult = callPreEvent(modelDTOList, null,preEvent, VciChangeDocumentTypeEnum.UPREVISION); if(!beforeResult.isSuccess()){ //说明前置事件没有执行成功 return beforeResult; } List businessObjects = null; Date ts = formDataDTO.getTs(); Map conditionMap = WebUtil.getOidQuery(formDataDTO.getCopyFromVersion()); conditionMap.put("ts", VciDateUtil.date2Str(ts,VciDateUtil.DateTimeMillFormat)); conditionMap.put("oid",formDataDTO.getCopyFromVersion()); businessObjects = boService.queryCBO(formDataDTO.getBtmname(), conditionMap); if(businessObjects.size() ==0){ throw new VciBaseException("数据不是最新的,建议您刷新后重新操作"); } //扩展属性的值 Map data = formDataDTO.getData(); Map dataLow = new HashMap<>(); data.forEach((key,value)->{ dataLow.put(key.toLowerCase(),value); }); Map baseDataMap = formDataDTO2MapLow(formDataDTO); Map allDataMapLow = new HashMap<>(); allDataMapLow.putAll(dataLow); allDataMapLow.putAll(baseDataMap); //判断唯一项 BaseResult baseResult = checkUnique(formDefineVO, null, allDataMapLow, true); if(!baseResult.isSuccess()){ return baseResult; } BusinessObject businessObject = platformClientUtil.getBOFService() .revisionBusinessObject(businessObjects.get(0), null, !formDataDTO.isUpVersion(),true, false, false); //执行保存 BaseResult> result = BaseResult.success(); result.setObj(boService.cbo2Map(businessObject)); //后置事件 String afterEvent = formDataDTO.getPostEvent(); try { callPostEvent(Arrays.stream(new BusinessObject[]{businessObject}).collect(Collectors.toList()), null,afterEvent, VciChangeDocumentTypeEnum.EDIT); }catch (Throwable e){ throw new VciBaseException(LangBaseUtil.getErrorMsg(e),new String[]{},e); } return result; } /** * 批量修改,注意表单定义的字段才会被修改,ts这种默认字段除外 * * @param formDataDTOList 数据的传输对象 * @return 执行结果和显示后的值 * @throws VciBaseException 保存出错的时候会抛出异常 */ @Override public BaseResult batchEditSave(FormDataDTOList formDataDTOList) throws VciBaseException { VciBaseUtil.alertNotNull(formDataDTOList,"要修改的数据",formDataDTOList.getFormDataDTOS(),"要修改的数据"); //首先判断对象是否为空 FormDataDTO firstFormDataDTO = formDataDTOList.getFormDataDTOS().stream().findFirst().get(); UIFormDefineVO formDefineVO = uiEngineService.getFormById(firstFormDataDTO.getBtmname(), firstFormDataDTO.getId()); String preEvent = firstFormDataDTO.getPreEvent(); BaseModelDTOList modelDTOList = formDataList2DTOList(formDataDTOList); BaseResult beforeResult = callPreEvent(modelDTOList,null, preEvent, VciChangeDocumentTypeEnum.EDIT); if(!beforeResult.isSuccess()){ //说明前置事件没有执行成功 return beforeResult; } //封装数据 List updateCBOS = new ArrayList<>(); Map> releasedFileOids = new HashMap<>(); List afterCBOs = new ArrayList<>(); for(FormDataDTO formDataDTO:formDataDTOList.getFormDataDTOS()) { BaseResult resultCbo = wrapperCbo(formDataDTO, formDefineVO, true, false, false); if (!resultCbo.isSuccess()) { return BaseResult.fail(resultCbo.getMsg(), resultCbo.getMsgObjs()); } updateCBOS.add(resultCbo.getObj()); //执行保存 if (!CollectionUtils.isEmpty(formDataDTO.getReleaseFileOids())) { releasedFileOids.put(resultCbo.getObj().oid,formDataDTO.getReleaseFileOids()); } } try { platformClientUtil.getBOFactoryService().batchUpdateBusinessObject(updateCBOS.toArray(new BusinessObject[updateCBOS.size()])); } catch (PLException vciError) { throw WebUtil.getVciBaseException(vciError); } if(!CollectionUtils.isEmpty(releasedFileOids)){ releasedFileOids.forEach((oid,fileOids)->{ fileObjectService.releasedFile(firstFormDataDTO.getBtmname(),oid,fileOids); }); } //后置事件 String afterEvent = firstFormDataDTO.getPostEvent(); try { callPostEvent(afterCBOs,null, afterEvent, VciChangeDocumentTypeEnum.ADD); }catch (Throwable e){ throw new VciBaseException(LangBaseUtil.getErrorMsg(e),new String[]{},e); } BaseResult result = BaseResult.success(); result.setData(updateCBOS.stream().map(s->s.oid).collect(Collectors.toList())); return result; } /** * 批量删除 * * @param deleteDataDTO 数据的传输对象 * @return 执行结果 * @throws VciBaseException 数据被引用的时候会抛出异常 */ @Override public BaseResult batchDelete(DeleteDataDTO deleteDataDTO) throws VciBaseException { VciBaseUtil.alertNotNull(deleteDataDTO,"数据传输对象",deleteDataDTO.getDataList(),"数据传输对象"); String btmName = deleteDataDTO.getDataList().get(0).getBtmname(); List oidList = deleteDataDTO.getDataList().stream().map(BaseModelDTO::getOid).collect(Collectors.toList()); //看看级联删除。只有自己引用自己的时候可以级联删除 List cbo = null; if(deleteDataDTO.isCascade()){ //级联删除 OsBtmTypeVO btmTypeVO = btmService.getBtmById(btmName); OsBtmTypeAttributeVO parentAttributeVO = btmTypeVO.getAttributes().stream().filter(s -> s.getReferBtmTypeId().equalsIgnoreCase(btmName)).findFirst().orElseGet(null); if(parentAttributeVO != null){ //页面分页不能显示超过1000 String sql = "select oid from " + VciBaseUtil.getTableName(btmName) + " where start with oid in ( " + VciBaseUtil.toInSql(oidList.toArray(new String[0])) +") connect by prior " + parentAttributeVO.getId() + " = oid"; cbo = boService.queryBySql(sql, new HashMap<>()); }else{ cbo = boService.selectCBOByOidCollection(oidList, btmName); } }else { cbo = boService.selectCBOByOidCollection(oidList, btmName); } //判断需要校验关联 if(CollectionUtils.isEmpty(cbo)){ return BaseResult.fail("没有在系统中找到这些数据,未执行删除操作"); } List finalCbo = cbo; Collection> oidCollections = WebUtil.switchCollectionForOracleIn(finalCbo.stream().map(bo -> bo.oid).collect(Collectors.toList())); List usedAttributeVOS = null; boolean adminCascade = false; if("admin".equalsIgnoreCase(VciBaseUtil.getCurrentUserId()) && deleteDataDTO.isAdminCascade()){ adminCascade = true; } if(deleteDataDTO.isCheckLinkedFlag() && !adminCascade){ //说明要校验关联的信息 usedAttributeVOS = btmService.listBtmUsedInfo(btmName); if(!CollectionUtils.isEmpty(usedAttributeVOS)){ usedAttributeVOS.stream().forEach(usedAttributeVO->{ oidCollections.stream().forEach(oids->{ Map conditionMap = new HashMap<>(); conditionMap.put(usedAttributeVO.getId(),QueryOptionConstant.IN + "(" + VciBaseUtil.toInSql(oids.toArray(new String[0])) + ")"); if(StringUtils.isNotBlank(usedAttributeVO.getPkBtmType())) { if (boService.queryCount(usedAttributeVO.getPkBtmType(), conditionMap) > 0) { OsBtmTypeVO btmTypeVO = btmService.getBtmById(usedAttributeVO.getPkBtmType()); throw new VciBaseException("数据在【" + btmTypeVO.getName() + "】中的字段[" + usedAttributeVO.getName() + "]里被引用.不能删除"); } }else{ //链接类型 } }); }); } } if(adminCascade){ //查询关联的数据 usedAttributeVOS = btmService.listBtmUsedInfo(btmName); if(!CollectionUtils.isEmpty(usedAttributeVOS)){ usedAttributeVOS.stream().forEach(usedAttributeVO->{ oidCollections.stream().forEach(oids->{ Map conditionMap = new HashMap<>(); conditionMap.put(usedAttributeVO.getId(),QueryOptionConstant.IN + "(" + VciBaseUtil.toInSql(oids.toArray(new String[0])) + ")"); if(StringUtils.isNotBlank(usedAttributeVO.getPkBtmType())) { List tempCbos = boService.queryCBO(usedAttributeVO.getPkBtmType(), conditionMap); if(!CollectionUtils.isEmpty(tempCbos)){ finalCbo.addAll(tempCbos); } }else{ //链接类型 } }); }); } } VciBaseUtil.switchCollectionForOracleIn(finalCbo).stream().forEach(cbos->{ try { platformClientUtil.getBOFService().batchDeleteBusinessObject(cbos.toArray(new BusinessObject[0]),1); } catch (PLException vciError) { throw WebUtil.getVciBaseException(vciError); } }); return BaseResult.success(); } /** * 链接类型添加 * * @param formLinkDataDTO 链接类型的表单数据 * @return 链接类型的主键 * @throws VciBaseException 参数为空,必输项缺失 */ @Override public BaseResult linkAddSave(FormLinkDataDTO formLinkDataDTO) throws VciBaseException { //首先判断对象是否为空 VciBaseUtil.alertNotNull(formLinkDataDTO,"添加的数据对象",formLinkDataDTO.getLinkType(),"链接类型的名称",formLinkDataDTO.getFormDefineId(),"表单定义的编号"); if(formLinkDataDTO.getData() ==null){ formLinkDataDTO.setData(new HashMap<>()); } //支持的场景 /** * 支持的场景 * 1. to端数据已经存在,则保存链接数据,不处理to端的数据 * 2. to端数据不存在,则保存链接数据,并且添加to端的数据 * 3. to端数据已经存在,但是需要升版 * 4. to端数据已经存在,但是需要升版次 */ UIFormDefineVO formDefineVO = uiEngineService.getFormById(formLinkDataDTO.getLinkType(), formLinkDataDTO.getFormDefineId()); //前置事件 String preEvent = formLinkDataDTO.getPreEvent(); BaseLinkModelDTOList modelDTOList = formLinkData2DTOList(formLinkDataDTO); BaseResult beforeResult = callPreEvent(null,modelDTOList, preEvent, VciChangeDocumentTypeEnum.ADD); if(!beforeResult.isSuccess()){ //说明前置事件没有执行成功 return beforeResult; } LinkObject clo = null; String prefix = ""; if(formLinkDataDTO.isDirection()){ prefix = LO_FROM_PREFIX; VciBaseUtil.alertNotNull(formLinkDataDTO.getToid(),"to端的数据主键"); }else{ VciBaseUtil.alertNotNull(formLinkDataDTO.getFoid(),"from端的数据主键"); prefix = LO_TO_PREFIX; } //判断数据 String toOid = formLinkDataDTO.isDirection()?formLinkDataDTO.getFoid():formLinkDataDTO.getToid(); String toBtmName = formLinkDataDTO.isDirection()?formLinkDataDTO.getFbtmname():formLinkDataDTO.getTbtmname(); String fromOid = formLinkDataDTO.isDirection()?formLinkDataDTO.getToid():formLinkDataDTO.getFoid(); String fromBtmName = formLinkDataDTO.isDirection()?formLinkDataDTO.getTbtmname():formLinkDataDTO.getFbtmname(); VciBaseUtil.alertNotNull(toBtmName,formLinkDataDTO.isDirection()?"from端":"to端" + "的业务类型", fromBtmName,formLinkDataDTO.isDirection()?"to端":"from端" + "的业务类型", fromOid,formLinkDataDTO.isDirection()?"to端":"from端" + "的主键"); Map boData = new HashMap<>(); Map loData = new HashMap<>(); if(CollectionUtils.isEmpty(formLinkDataDTO.getData()) && StringUtils.isBlank(toOid)){ throw new VciBaseException(formLinkDataDTO.isDirection()?"from端":"to端" + "没有任何的属性被保存"); } if(CollectionUtils.isEmpty(formLinkDataDTO.getData()) && StringUtils.isBlank(toBtmName)){ throw new VciBaseException(formLinkDataDTO.isDirection()?"from端":"to端" + "的业务类型为空"); } //查询from端的 BusinessObject fromCbo = new BusinessObject(); try { fromCbo = platformClientUtil.getBOFService().readBusinessObject(fromOid,fromBtmName); } catch (PLException vciError) { throw WebUtil.getVciBaseException(vciError); } String finalPrefix = prefix; formLinkDataDTO.getData().forEach((key, value)->{ if(key.toLowerCase().startsWith(finalPrefix)){ boData.put(key.substring(finalPrefix.length()).toLowerCase(),value); }else{ loData.put(key.toLowerCase(),value); } }); //封装to端的 BaseResult result = wrapperToCbo(formLinkDataDTO,formDefineVO,toOid,toBtmName,boData); if(!result.isSuccess()){ return BaseResult.fail(result.getMsg(),result.getMsgObjs()); } BusinessObject toCbo = result.getObj(); //初始化链接类型的值 BaseResult resultClo = wrapperOnlyCLO(formLinkDataDTO, loData, formDefineVO, false); if(!resultClo.isSuccess()){ return BaseResult.fail(resultClo.getMsg(),resultClo.getMsgObjs()); } clo = resultClo.getObj(); //执行保存 BusinessObject[] bos = new BusinessObject[1]; ObjectTool.dealBusinessObjectNullValue(toCbo); ObjectTool.dealLinkObjectNullValue(clo); bos[0] = toCbo; try { platformClientUtil.getBOFService().createBusinessObjectWithLink(bos,clo); } catch (PLException vciError) { throw WebUtil.getVciBaseException(vciError); } if(!CollectionUtils.isEmpty(formLinkDataDTO.getReleaseFileOids())){ fileObjectService.releasedFile(formLinkDataDTO.getLinkType(),clo.oid,formLinkDataDTO.getReleaseFileOids()); } //后置事件 String afterEvent = formLinkDataDTO.getPostEvent(); try { callPostEvent(null,Arrays.stream(new LinkObject[]{clo}).collect(Collectors.toList()), afterEvent, VciChangeDocumentTypeEnum.ADD); }catch (Throwable e){ //说明后置事件出现了错误,那么就需要删除以前的这条数据 try { platformClientUtil.getBOFService().deleteBusinessObject(toCbo,1); platformClientUtil.getBOFService().deleteLinkObject(clo); } catch (PLException vciError) { throw WebUtil.getVciBaseException(vciError); } throw new VciBaseException(LangBaseUtil.getErrorMsg(e),new String[]{},e); } return BaseResult.success(clo.oid); } /** * 封装仅仅包含链接类型的 * @param formLinkDataDTO 链接类型的数据传输对象 * @param loData 链接类型的数据 * @param formDefineVO 表单的定义 * @param editFlag 是否为编辑 * @return 链接类型的内容 */ private BaseResult wrapperOnlyCLO(FormLinkDataDTO formLinkDataDTO,Map loData,UIFormDefineVO formDefineVO,boolean editFlag){ Map baseDataMap = formLinkDataDTO2MapLow(formLinkDataDTO); Map allDataMap = new HashMap<>(); allDataMap.putAll(loData); allDataMap.putAll(baseDataMap); //校验必输项 BaseResult result = checkRequired(formDefineVO,null,allDataMap); if(!result.isSuccess()){ return result; } //校验唯一项 result = checkUnique(formDefineVO,null,allDataMap,editFlag); if(!result.isSuccess()){ return result; } //处理业务类型得到数据 LinkObject clo ; if(editFlag){ try { LinkObject linkObject = platformClientUtil.getBOFService().readLinkObjectById(formLinkDataDTO.getOid(), formLinkDataDTO.getLinkType()); clo = new LinkObject(); clo = linkObject; } catch (PLException vciError) { throw WebUtil.getVciBaseException(vciError); } }else{ clo = new LinkObject(); //处理初始化的数据 clo.oid = VciBaseUtil.getPk(); clo.creator = VciBaseUtil.getCurrentUserId(); clo.createTime = System.currentTimeMillis(); clo.ts = System.currentTimeMillis(); clo.ltName = formLinkDataDTO.getLinkType(); } // LinkObject finalClo = clo; allDataMap.forEach((key, value)->{ if(editFlag&&("lastmodifier".equalsIgnoreCase(key) || "lastmodifytime".equalsIgnoreCase(key) || "ts".equalsIgnoreCase(key) || "creator".equalsIgnoreCase(key) || "createtime".equalsIgnoreCase(key))){ //平台不能传递这个 }else{ loService.setAttribute(finalClo,key,value); } }); return BaseResult.success(clo); } /** * 封装to端的数据 * @param formLinkDataDTO 链接类型的表单数据 * @param formDefineVO 表单的定义 * @param toOid to端的主键 * @param toBtmName to的业务类型 * @param boData to的数据 * @return 包含的对象 */ private BaseResult wrapperToCbo(FormLinkDataDTO formLinkDataDTO,UIFormDefineVO formDefineVO,String toOid,String toBtmName,Map boData){ Map dataLow = new HashMap<>(); boData.forEach((key,value)->{ dataLow.put(key.toLowerCase(),value); }); boolean editFlag = StringUtils.isNotBlank(toOid) && !formLinkDataDTO.isToUpRevision() && !formLinkDataDTO.isToUpVersion() && !CollectionUtils.isEmpty(dataLow); if((formLinkDataDTO.isToUpRevision() || formLinkDataDTO.isToUpVersion()) && StringUtils.isBlank(toOid)){ throw new VciBaseException("升版的时候,老版本数据的主键不能为空"); } String prefix = formLinkDataDTO.isDirection()?LO_FROM_PREFIX:LO_TO_PREFIX; //判断必输项 BaseResult result = checkRequired(formDefineVO,prefix,dataLow); if(!result.isSuccess()){ return result; } Map baseDataMap = new HashMap<>(); WebUtil.copyValueForMap(dataLow,baseDataMap,dataLow.keySet().toArray(new String[0])); baseDataMap.put("btmname",toBtmName); baseDataMap.put("oid",toOid); if(formLinkDataDTO.isToUpRevision() || formLinkDataDTO.isToUpVersion()){ baseDataMap.put("copyfromversion",toOid); } //判断唯一项 result = checkUnique(formDefineVO,prefix,baseDataMap,editFlag); if(!result.isSuccess()){ return result; } BusinessObject cbo = createOrGetCbo(dataLow,baseDataMap,editFlag,formLinkDataDTO.isToUpRevision(),formLinkDataDTO.isToUpVersion()); return BaseResult.success(cbo); } /** * 校验必输项 * @param formDefineVO 表单的定义 * @param prefix 前缀(链接类型的表单使用) * @param dataLow 数据的小写 * @return 执行结果 */ private BaseResult checkRequired(UIFormDefineVO formDefineVO,String prefix,Map dataLow){ final BaseResult[] result = {BaseResult.success()}; if(prefix == null){ prefix = ""; } List items = formDefineVO.getItems(); List requiredItems = items.stream().filter(item -> item.isRequired()).collect(Collectors.toList()); if(!CollectionUtils.isEmpty(requiredItems)){ String finalPrefix = prefix; if(requiredItems.stream().anyMatch(item->{ Object value = dataLow.getOrDefault(item.getField().toLowerCase(),dataLow.getOrDefault(item.getField().toLowerCase().substring(finalPrefix.length()),null)); if(value == null || ( (value instanceof String) && StringUtils.isBlank((String)value))){ result[0] = BaseResult.fail(item.getText() + "的值不能为空"); return true; } return false; })){ return result[0]; } } return result[0]; } /** * 校验是否重复 * @param formDefineVO 表单的配置 * @param prefix 前缀 * @param dataLow 数据的小写 * @param editFlag 是否编辑 * @return 校验结果 */ public BaseResult checkUnique(UIFormDefineVO formDefineVO, String prefix,Map dataLow,boolean editFlag){ final BaseResult[] result = {BaseResult.success()}; List uniqueItems = formDefineVO.getItems().stream().filter(item -> item.isUnique()).collect(Collectors.toList()); if(!CollectionUtils.isEmpty(uniqueItems)){ if(uniqueItems.stream().anyMatch(item->{ String field = item.getField().toLowerCase(); if(StringUtils.isNotBlank(prefix) && field.startsWith(prefix)){ field = field.substring(prefix.length()); } Object value = dataLow.getOrDefault(field,null); if(value == null || ( (value instanceof String) && StringUtils.isBlank((String)value))){ result[0] = BaseResult.fail(item.getText() + "的值不能为空"); return true; } //我们查询内容 Map conditionMap = new HashMap<>(); conditionMap.put(item.getField().toLowerCase(),WebUtil.getStringValueFromObject(value)); if(editFlag){ String oid = dataLow.get("oid"); VciBaseUtil.alertNotNull(oid,"主键"); conditionMap.put("oid",QueryOptionConstant.NOTEQUAL + oid); } if(formDefineVO.isLinkTypeFlag()){ if (loService.queryCount(formDefineVO.getBtmType(), conditionMap) > 0) { result[0] = BaseResult.fail("[" + item.getText() + "]的值发生了重复"); return true; } }else { if (boService.queryCount(formDefineVO.getBtmType(), conditionMap) > 0) { result[0] = BaseResult.fail("[" + item.getText() + "]的值发生了重复"); return true; } } return false; })){ return result[0]; } } return result[0]; } /** * 创建或者读取cbo对象 * @param dataLowMap 数据(小写) * @param baseDataMap 基础数据 * @param editFlag 是否编辑 * @param newRevision 是否升版 * @param newVersion 是否升版次 * @return cbo对象 */ public BusinessObject createOrGetCbo(Map dataLowMap,Map baseDataMap,boolean editFlag,boolean newRevision,boolean newVersion){ String btmName = baseDataMap.get("btmname"); String oid = baseDataMap.get("oid"); // BusinessObject cbo = new BusinessObject(); BusinessObject cbo = new BusinessObject(); String copyfromversion = baseDataMap.get("copyfromversion"); OsBtmTypeVO btmTypeVO = btmService.getBtmById(btmName); List attributeList = btmTypeVO.getAttributes().stream().map(attribute -> attribute.getId()).collect(Collectors.toList()); if(editFlag || newRevision || newVersion){ try { cbo = platformClientUtil.getBOFService().readBusinessObject(editFlag?oid:copyfromversion,btmName); } catch (PLException vciError) { throw new VciBaseException("使用主键在系统中没有查询到数据",new String[]{oid},vciError); } if(btmTypeVO.isRevisionFlag() && newRevision){ cbo.oid = VciBaseUtil.getPk(); cbo.fromVersion = copyfromversion; if(btmTypeVO.isInputRevisionFlag() && StringUtils.isNotBlank(baseDataMap.getOrDefault("revisionvalue",""))){ //手动的,所以不处理版本规则了 cbo.revisionValue = baseDataMap.get("revisionvalue"); }else{ //说明是升版 BaseModel baseModel = cbo2BaseModel(cbo); RevisionDataInfo revisionValueObject = getNextRevision(btmTypeVO,baseModel); cbo.revisionid = VciBaseUtil.getPk(); cbo.revisionSeq = revisionValueObject.revisionSeq; cbo.revisionValue = revisionValueObject.revisionVal; cbo.isLastR = true; cbo.isFirstR = false; //处理版次 cbo.versionValue = getFirstVersion(btmTypeVO.getVersionRule()); cbo.versionRule = btmTypeVO.getVersionRule(); cbo.versionSeq = (short) 0; cbo.isLastV = true; cbo.isFirstV = true; } //升版的时候,生命周期的状态需要改动到默认状态 if(StringUtils.isNotBlank(btmTypeVO.getLifeCycleId())){ //查询生命周期 LifeCycle lifeCycleVO = null; try { lifeCycleVO = platformClientUtil.getLifeCycleService().getLifeCycle(btmTypeVO.getLifeCycleId()); } catch (PLException e) { throw new RuntimeException(e); } if(lifeCycleVO == null || StringUtils.isBlank(lifeCycleVO.oid)){ throw new VciBaseException("{0}里的生命周期设置得不正确,在系统中没有找到{1}这个生命周期",new String[]{btmTypeVO.getName(),btmTypeVO.getLifeCycleId()}); } cbo.lcStatus = lifeCycleVO.startState; } } if(btmTypeVO.isRevisionFlag() && newVersion){ cbo.fromVersion = copyfromversion; cbo.oid = VciBaseUtil.getPk(); //这是升版次,不存在即升版本,又升版次的情况 BaseModel baseModel = cbo2BaseModel(cbo); VersionDataInfo versionValueObject = getNextVersion(btmTypeVO,baseModel); cbo.versionValue = versionValueObject.versionVal; cbo.versionSeq = versionValueObject.versionSeq; cbo.isLastV = true; cbo.isFirstV = false; //升版的时候,生命周期的状态需要改动到默认状态 if(StringUtils.isNotBlank(btmTypeVO.getLifeCycleId())){ //查询生命周期 LifeCycle lifeCycleVO = null; try { lifeCycleVO = platformClientUtil.getLifeCycleService().getLifeCycle(btmTypeVO.getLifeCycleId()); } catch (PLException e) { throw new RuntimeException(e); } if(lifeCycleVO == null || StringUtils.isBlank(lifeCycleVO.oid)){ throw new VciBaseException("{0}里的生命周期设置得不正确,在系统中没有找到{1}这个生命周期",new String[]{btmTypeVO.getName(),btmTypeVO.getLifeCycleId()}); } cbo.lcStatus = lifeCycleVO.startState; } } }else{ //我们需要将属性初始化 if(StringUtils.isBlank(cbo.oid) || (newRevision || newVersion)){ cbo.oid = VciBaseUtil.getPk(); } if(StringUtils.isBlank(cbo.creator)){ cbo.creator = VciBaseUtil.getCurrentUserId(); } if(cbo.createTime != 0){ cbo.createTime = System.currentTimeMillis(); } if(StringUtils.isBlank(cbo.owner)){ cbo.owner = cbo.creator; } cbo.ts = System.currentTimeMillis(); if(StringUtils.isNotBlank(btmTypeVO.getLifeCycleId()) && (StringUtils.isBlank(cbo.lcStatus) || newRevision || newVersion)){ //查询生命周期 OsLifeCycleVO lifeCycleVO = lifeCycleService.getLifeCycleById(btmTypeVO.getLifeCycleId()); if(lifeCycleVO == null || StringUtils.isBlank(lifeCycleVO.getOid())){ throw new VciBaseException("{0}里的生命周期设置得不正确,在系统中没有找到{1}这个生命周期",new String[]{btmTypeVO.getName(),btmTypeVO.getLifeCycleId()}); } cbo.lcStatus = lifeCycleVO.getStartStatus(); cbo.lctId = btmTypeVO.getLifeCycleId(); } if(StringUtils.isBlank(cbo.btName)){ cbo.btName = btmTypeVO.getId(); } if(btmTypeVO.isRevisionFlag()){ //要管理版本 if(btmTypeVO.isInputRevisionFlag() && StringUtils.isNotBlank(baseDataMap.getOrDefault("revisionvalue",""))){ //手动的,所以不处理版本规则了 cbo.revisionValue = baseDataMap.get("revisionvalue"); }else { OsRevisionRuleVO ruleVO = revisionRuleServiceI.getRevisionRuleById(btmTypeVO.getRevisionRuleId()); if (ruleVO == null || StringUtils.isBlank(ruleVO.getOid())) { throw new VciBaseException("{0}里的版本规则设置得不正确,在系统中没有找到{1}这个版本规则", new String[]{btmTypeVO.getName(), btmTypeVO.getRevisionRuleId()}); } cbo.revisionValue = ruleVO.getStartCode(); } if (StringUtils.isBlank(cbo.nameoid)) { cbo.nameoid = VciBaseUtil.getPk(); } if (StringUtils.isBlank(cbo.revisionid)) { cbo.revisionid = VciBaseUtil.getPk(); } cbo.isFirstR = true; cbo.isLastR = true; cbo.revisionRule = btmTypeVO.getRevisionRuleId(); cbo.revisionSeq = (short) 0; //看看是否需要处理版次 cbo.versionValue = getFirstVersion(btmTypeVO.getVersionRule()); cbo.versionRule = btmTypeVO.getVersionRule(); cbo.versionSeq = (short) 0; cbo.isLastV = true; cbo.isFirstV = true; } } // Iterator> iterator = baseDataMap.entrySet().iterator(); // while(iterator.hasNext()){ // Map.Entry next = iterator.next(); // if(!attributeList.contains(next.getKey())){ // iterator.remove(); // } // } setValueToCbo(dataLowMap,baseDataMap,cbo,editFlag); // cbo.setName(dataLowMap.get("name")); return cbo; } /** * 基础的属性 */ public static final List basicFields = new ArrayList(){{ add("id"); add("name"); add("description"); add("secretgrade"); }}; /** * 编辑时不处理的书序 * @param key 属性 * @return true */ private boolean notSendOnEdit(String key){ return "lastmodifier".equalsIgnoreCase(key) || "lastmodifytime".equalsIgnoreCase(key) || "ts".equalsIgnoreCase(key) || "creator".equalsIgnoreCase(key) || "createTime".equalsIgnoreCase(key); } /** * 设置值到业务类型的对象上 * @param dataLow 数据(key小写) * @param baseDataLow 基础属性的数据(key小写) * @param cbo 业务类型的对象 * @param editFlag 是否为编辑 */ @Override public void setValueToCbo(Map dataLow, Map baseDataLow, BusinessObject cbo, boolean editFlag){ dataLow.forEach((key,value)->{ if(editFlag&¬SendOnEdit(key)){ //平台不能传递这个 }else{ ObjectTool.setBOAttributeValue(cbo,key,value); } }); baseDataLow.forEach((key,value)->{ if(editFlag&¬SendOnEdit(key)){ //平台不能传递这个 }else{ if(editFlag) { //编辑的时候可以都设置 ObjectTool.setBOAttributeValue(cbo,key,value); }else{ //只需要处理id,name,description,密级即可,其余的都已经被设置了 if(basicFields.contains(key) &&StringUtils.isNotBlank(value)){ ObjectTool.setBOAttributeValue(cbo,key,value); } } } }); } /** * 链接类型的编辑数据 * * @param formLinkDataDTO 数据的传输对象 * @return 执行结果 * @throws VciBaseException 参数为空,必输项缺失 */ @Override public BaseResult linkEditSave(FormLinkDataDTO formLinkDataDTO) throws VciBaseException { VciBaseUtil.alertNotNull(formLinkDataDTO,"修改的数据对象",formLinkDataDTO.getLinkType(),"链接类型的名称", formLinkDataDTO.getFormDefineId(),"表单定义的编号",formLinkDataDTO.getOid(),"主键", formLinkDataDTO.getFoid(),"from端主键",formLinkDataDTO.getToid(),"to端主键"); if(formLinkDataDTO.getData() ==null){ formLinkDataDTO.setData(new HashMap<>()); } /** * 支持的场景 * 1. 如果有to端的其他属性的值就更新 * 2. 没有其他属性的值,只更新链接类型 */ UIFormDefineVO formDefineVO = uiEngineService.getFormById(formLinkDataDTO.getLinkType(), formLinkDataDTO.getFormDefineId()); //前置事件 String preEvent = formLinkDataDTO.getPreEvent(); BaseLinkModelDTOList modelDTOList = formLinkData2DTOList(formLinkDataDTO); BaseResult beforeResult = callPreEvent(null,modelDTOList, preEvent, VciChangeDocumentTypeEnum.ADD); if(!beforeResult.isSuccess()){ //说明前置事件没有执行成功 return beforeResult; } LinkObject clo = null; String prefix = formLinkDataDTO.isDirection()?LO_FROM_PREFIX:LO_TO_PREFIX; String toOid = formLinkDataDTO.isDirection()?formLinkDataDTO.getFoid():formLinkDataDTO.getToid(); String toBtmName = formLinkDataDTO.isDirection()?formLinkDataDTO.getFbtmname():formLinkDataDTO.getTbtmname(); String fromOid = formLinkDataDTO.isDirection()?formLinkDataDTO.getToid():formLinkDataDTO.getFoid(); String fromBtmName = formLinkDataDTO.isDirection()?formLinkDataDTO.getTbtmname():formLinkDataDTO.getFbtmname(); Map boData = new HashMap<>(); Map loData = new HashMap<>(); if(!CollectionUtils.isEmpty(formLinkDataDTO.getData())){ formLinkDataDTO.getData().forEach((key, value)->{ if(key.toLowerCase().startsWith(prefix)){ boData.put(key.substring(prefix.length()).toLowerCase(),value); }else{ loData.put(key.toLowerCase(),value); } }); } BusinessObject toCbo =null; if(!CollectionUtils.isEmpty(boData)) { //封装to端的 BaseResult result = wrapperToCbo(formLinkDataDTO, formDefineVO, toOid, toBtmName, boData); if (!result.isSuccess()) { return BaseResult.fail(result.getMsg(), result.getMsgObjs()); } toCbo= result.getObj(); } //初始化链接类型的值 BaseResult resultClo = wrapperOnlyCLO(formLinkDataDTO, loData, formDefineVO, true); if(!resultClo.isSuccess()){ return BaseResult.fail(resultClo.getMsg(),resultClo.getMsgObjs()); } clo = resultClo.getObj(); try { platformClientUtil.getBOFService().updateLinkObject(clo); } catch (PLException vciError) { throw WebUtil.getVciBaseException(vciError); } //保存to端或者from端 try{ platformClientUtil.getBOFactoryService().updateBusinessObject(toCbo); } catch (PLException vciError) { throw WebUtil.getVciBaseException(vciError); } if(!CollectionUtils.isEmpty(formLinkDataDTO.getReleaseFileOids())){ fileObjectService.releasedFile(formLinkDataDTO.getLinkType(),clo.oid,formLinkDataDTO.getReleaseFileOids()); } //后置事件 String afterEvent = formLinkDataDTO.getPostEvent(); try { callPostEvent(null,Arrays.stream(new LinkObject[]{clo}).collect(Collectors.toList()), afterEvent, VciChangeDocumentTypeEnum.ADD); }catch (Throwable e){ //后置事件有问题了就只能是这样了,没办法恢复 throw new VciBaseException(LangBaseUtil.getErrorMsg(e),new String[]{},e); } return BaseResult.success(clo.oid); } /** * 删除链接类型 * * @param deleteLinkDataDTO 数据的传输对象 * @return 执行结果 * @throws VciBaseException 参数为空,必输项缺失 */ @Override public BaseResult batchLinkDelete(DeleteLinkDataDTO deleteLinkDataDTO) throws VciBaseException { VciBaseUtil.alertNotNull(deleteLinkDataDTO,"删除数据",deleteLinkDataDTO.getDataList(),"要删除的信息"); if(deleteLinkDataDTO.getDataList().stream().anyMatch(s->StringUtils.isBlank(s.getOid()) || StringUtils.isBlank(s.getLinkType()))){ throw new VciBaseException("有数据的主键(或链接类型)没有值,无法删除"); } List clos = new ArrayList<>(); VciBaseUtil.switchListForOracleIn(deleteLinkDataDTO.getDataList()).stream().forEach(linkModelDTOs->{ Map conditionMap = new HashMap<>(); conditionMap.put("oid",QueryOptionConstant.IN +"(" + VciBaseUtil.toInSql(linkModelDTOs.stream().map(BaseLinkModelDTO::getOid).toArray(String[]::new)) +")"); List LinkObjects = loService.queryCLO(linkModelDTOs.get(0).getLinkType(), conditionMap); if(!CollectionUtils.isEmpty(LinkObjects)){ clos.addAll(LinkObjects); } }); if(CollectionUtils.isEmpty(clos)){ throw new VciBaseException("使用主键没有在系统中找到链接类型的数据"); } Map> fromBtmGroups = clos.stream().collect(Collectors.groupingBy(s->s.fromBTName)); Map> toBtmGroups = clos.stream().collect(Collectors.groupingBy(s->s.toBTName)); Map> fromBtmDataGroups = new HashMap<>(); Map> toBtmDataGroups = new HashMap<>(); if(!CollectionUtils.isEmpty(fromBtmGroups)){ fromBtmGroups.forEach((btmType,cloList)->{ List cbos = boService.selectCBOByOidCollection(cloList.stream().map(clo -> clo.fromOid).collect(Collectors.toList()), btmType); fromBtmDataGroups.put(btmType,cbos); }); } if(!CollectionUtils.isEmpty(toBtmGroups)){ toBtmGroups.forEach((btmType,cloList)->{ List cbos = boService.selectCBOByOidCollection(cloList.stream().map(clo -> clo.toOid).collect(Collectors.toList()), btmType); toBtmDataGroups.put(btmType,cbos); }); } if(StringUtils.isNotBlank(deleteLinkDataDTO.getCheckNotDelete())){ //需要校验内容 Map checkNotDeleteMap = VciBaseUtil.getParamsByUrl(deleteLinkDataDTO.getCheckNotDelete()); checkNotDeleteMap.forEach((attr,attrValue)->{ if(StringUtils.isBlank(attr) || StringUtils.isBlank(attrValue)){ throw new VciBaseException("校验是否能删除的配置错误,没有属性的值。格式需要xxx=yyy&zzz=aaa"); } if(attr.toLowerCase().startsWith(LO_FROM_PREFIX)){ fromBtmDataGroups.forEach((btm,cbos)->{ String attrNotPrefix = attr.substring(LO_FROM_PREFIX.length()); if(!CollectionUtils.isEmpty(cbos) && cbos.stream().anyMatch(s->!attrValue.equalsIgnoreCase(ObjectTool.getBOAttributeValue(s, attrNotPrefix)))){ throw new VciBaseException("数据的内容不允许删除,{0}", new String[]{deleteLinkDataDTO.getCheckNotDeleteMsg()}); } }); }else if(attr.toLowerCase().startsWith(LO_TO_PREFIX)){ toBtmDataGroups.forEach((btm,cbos)->{ String attrNotPrefix = attr.substring(LO_TO_PREFIX.length()); if(!CollectionUtils.isEmpty(cbos) && cbos.stream().anyMatch(s->!attrValue.equalsIgnoreCase(ObjectTool.getBOAttributeValue(s, attrNotPrefix)))){ throw new VciBaseException("数据的内容不允许删除,{0}", new String[]{deleteLinkDataDTO.getCheckNotDeleteMsg()}); } }); }else { if (clos.stream().anyMatch(s -> attrValue.equalsIgnoreCase(ObjectTool.getLOAttributeValue(s,attr)))) { throw new VciBaseException("数据的内容不允许删除,{0}", new String[]{deleteLinkDataDTO.getCheckNotDeleteMsg()}); } } }); } //链接类型本身一般不会有关联 List los = new ArrayList<>(); clos.stream().forEach(clo->{ los.add(clo); }); try { platformClientUtil.getBOFactoryService().batchDeleteLinkObject(los.toArray(new LinkObject[0])); } catch (PLException vciError) { throw WebUtil.getVciBaseException(vciError); } if(deleteLinkDataDTO.isDeleteFromData()){ fromBtmDataGroups.forEach((btm,cbos)->{ try{ platformClientUtil.getBOFactoryService().batchDeleteBusinessObject(cbos.toArray(new BusinessObject[0]),1); }catch (PLException vciError) { throw WebUtil.getVciBaseException(vciError); } }); } if(deleteLinkDataDTO.isDeleteToData()){ toBtmDataGroups.forEach((btm,cbos)->{ try{ platformClientUtil.getBOFactoryService().batchDeleteBusinessObject(cbos.toArray(new BusinessObject[0]),1); }catch (PLException vciError) { throw WebUtil.getVciBaseException(vciError); } }); } return BaseResult.success(); } /** * 获取参照的信息 * * @param referConfigVO 参照的配置 * @param pageHelper 分页的工具 * @return 列表数据 */ @Override public DataGrid referDataGrid(ReferConfigVO referConfigVO, PageHelper pageHelper) { checkReferConfig(referConfigVO); //使用业务类型查询 OsBtmTypeVO btmById = btmService.getBtmById(referConfigVO.getReferBo()); if(referConfigVO.getConditionMap() == null){ referConfigVO.setConditionMap(new HashMap<>()); } if(VciBaseUtil.containsKeyUnCaseForMap(referConfigVO.getConditionMap(), VciQueryWrapperForDO.LC_STATUS_FIELD) && FrameWorkLcStatusConstant.FRAME_WORK_LIFE_CYCLE_NAME.equalsIgnoreCase(btmById.getLifeCycleId())){ referConfigVO.getConditionMap().put(VciQueryWrapperForDO.LC_STATUS_FIELD,FrameworkDataLCStatus.ENABLED.getValue()); } if(VciBaseUtil.containsKeyUnCaseForMap(referConfigVO.getConditionMap(), VciQueryWrapperForDO.LC_STATUS_FIELD) && FrameWorkLcStatusConstant.RELEASE_LIFE_CYCLE.equalsIgnoreCase(btmById.getLifeCycleId())){ referConfigVO.getConditionMap().put(VciQueryWrapperForDO.LC_STATUS_FIELD, ReleaseDataLCStatus.RELEASED.getValue()); } if(StringUtils.isNotBlank(referConfigVO.getQueryScheme())){ return boService.queryGridByScheme(referConfigVO.getQueryScheme(),referConfigVO.getConditionMap(),referConfigVO.getReplaceMap(),pageHelper); }else{ return boService.queryGridByBo(referConfigVO.getReferBo(),referConfigVO.getConditionMap(),pageHelper); } } /** * 检查参照的信息 * @param referConfigVO 参照的信息 */ private void checkReferConfig(ReferConfigVO referConfigVO){ VciBaseUtil.alertNotNull(referConfigVO,"参照的信息"); if(StringUtils.isBlank(referConfigVO.getReferField()) && StringUtils.isBlank(referConfigVO.getReferBo())){ throw new VciBaseException("没有参照的配置信息"); } if(StringUtils.isBlank(referConfigVO.getReferBo()) && StringUtils.isNotBlank(referConfigVO.getReferField())){ //根据字段获取参照的类型 OsAttributeVO attributeVO = attributeService.getAttr(referConfigVO.getReferField()); if(attributeVO == null || StringUtils.isBlank(attributeVO.getOid())){ throw new VciBaseException("这个属性{0}在系统中不存在",new String[]{referConfigVO.getReferField()}); } referConfigVO.setReferBo(attributeVO.getBtmTypeId()); if(StringUtils.isBlank(attributeVO.getBtmTypeId())){ throw new VciBaseException("这个属性{0}在不是参照属性",new String[]{referConfigVO.getReferField()}); } } } /** * 获取树形的参照 * * @param referConfigVO 参照的配置 * @return 树形的数据 */ @Override public List referTree(ReferConfigVO referConfigVO) { checkReferConfig(referConfigVO); if(referConfigVO.getConditionMap() == null){ referConfigVO.setConditionMap(new HashMap<>()); } List cbos = null; String oidFieldName = StringUtils.isNotBlank(referConfigVO.getParentUsedField())?referConfigVO.getParentUsedField():referConfigVO.getValueField(); if(referConfigVO.isSelectAllLevel()) { String parentOidSql = ""; if(StringUtils.isNotBlank(referConfigVO.getParentOid())){ String temp = referConfigVO.getParentOid(); if(temp.startsWith(QueryOptionConstant.IN)){ temp = temp.substring((QueryOptionConstant.IN).length()).trim(); parentOidSql = " in " + ((temp.startsWith("(") && temp.endsWith(")"))?temp:"(" + temp + ")"); }else if(temp.startsWith(QueryOptionConstant.NOTIN)){ parentOidSql = " not in " + ((temp.startsWith("(") && temp.endsWith(")"))?temp:"(" + temp + ")"); }else if(temp.startsWith(QueryOptionConstant.NOTEQUAL)){ temp = temp.substring((QueryOptionConstant.NOTEQUAL).length()).trim(); parentOidSql = QueryOptionConstant.NOTEQUAL + " " + ((temp.startsWith("'") && temp.endsWith("'"))?temp:"'" + temp + "'"); }else if(temp.startsWith(QueryOptionConstant.MORETHAN)){ temp = temp.substring((QueryOptionConstant.MORETHAN).length()).trim(); parentOidSql = QueryOptionConstant.MORETHAN + " " + ((temp.startsWith("'") && temp.endsWith("'"))?temp:"'" + temp + "'"); }else if(temp.startsWith(QueryOptionConstant.MORE)){ temp = temp.substring((QueryOptionConstant.MORE).length()).trim(); parentOidSql = QueryOptionConstant.MORE + " " + ((temp.startsWith("'") && temp.endsWith("'"))?temp:"'" + temp + "'"); }else if(temp.startsWith(QueryOptionConstant.LESSTHAN)){ temp = temp.substring((QueryOptionConstant.LESSTHAN).length()).trim(); parentOidSql = QueryOptionConstant.LESSTHAN + " " + ((temp.startsWith("'") && temp.endsWith("'"))?temp:"'" + temp + "'"); }else if(temp.startsWith(QueryOptionConstant.LESS)){ temp = temp.substring((QueryOptionConstant.LESS).length()).trim(); parentOidSql = QueryOptionConstant.LESS + " " + ((temp.startsWith("'") && temp.endsWith("'"))?temp:"'" + temp + "'"); }else if (temp.startsWith(QueryOptionConstant.ISNOTNULL)) { parentOidSql = " is not null"; } else if (temp.startsWith(QueryOptionConstant.ISNULL)) { parentOidSql = " is null"; } else if(temp.contains("*")){ parentOidSql = " like " + ((temp.startsWith("'") && temp.endsWith("'"))?temp:"'" + temp + "'").replace("*","%"); }else { parentOidSql = " = " + ((temp.startsWith("'") && temp.endsWith("'"))?temp:"'" + temp + "'"); } } //查询全部的信息 referConfigVO.getConditionMap().put("oid",QueryOptionConstant.IN + "(select oid from " + VciBaseUtil.getTableName(referConfigVO.getReferBo()) + " START WITH " + referConfigVO.getParentFieldName() + " "+ parentOidSql + " CONNECT BY PRIOR " + oidFieldName + " = " + referConfigVO.getParentFieldName() + ")"); }else{ if(StringUtils.isNotBlank(referConfigVO.getParentFieldName()) && StringUtils.isNotBlank(referConfigVO.getParentOid())){ referConfigVO.getConditionMap().put(referConfigVO.getParentFieldName(),referConfigVO.getParentOid()); } } PageHelper pageHelper = new PageHelper(-1); if(StringUtils.isNotBlank(referConfigVO.getSort())){ pageHelper.setSort(referConfigVO.getSort()); pageHelper.setOrder(referConfigVO.getOrder()); } if (StringUtils.isNotBlank(referConfigVO.getQueryScheme())) { cbos = boService.queryCBOByScheme(referConfigVO.getQueryScheme(), referConfigVO.getConditionMap(), referConfigVO.getReplaceMap(),pageHelper); } else { cbos = boService.queryCBO(referConfigVO.getReferBo(), referConfigVO.getConditionMap(),pageHelper); } TreeWrapperOptions treeWrapperOptions = new TreeWrapperOptions(referConfigVO.getParentFieldName()); treeWrapperOptions.setOidFieldName(oidFieldName); treeWrapperOptions.setTextFieldName(referConfigVO.getTextField()); treeWrapperOptions.setMultipleSelect(referConfigVO.isMuti()); treeWrapperOptions.setParentOid(referConfigVO.getParentOid()); return WebUtil.cboList2Trees(cbos,treeWrapperOptions,null); } /** * 表单的数据查询 * @param btmname 业务类型的信息 * @param oid 业务数据的主键 * @return 业务数据的属性信息 */ @Override public List> getDataAttr(String btmname, String oid) { VciBaseUtil.alertNotNull(btmname,"业务类型的信息",oid,"业务数据的主键"); List cbos = boService.queryCBO(btmname,WebUtil.getOidQuery(oid)); List> dataMap = new ArrayList<>(); if(!CollectionUtils.isEmpty(cbos)){ cbos.stream().forEach(cbo->{ Map data = new HashMap<>(); WebUtil.copyValueToMapFromCbos(cbo,data); dataMap.add(data); }); } return dataMap; } /** * 数据升版本/次,前端使用JSON提交 * @param btmname 业务类型的信息 * @param oid 业务数据的主键 * @param type 1:版次对象;2:版本对象;3:主对象 * @return 执行的结果 */ @Override public BaseResult deleteBusinessObject(String btmname, String oid, int type) throws PLException { List cbos = boService.queryCBO(btmname,WebUtil.getOidQuery(oid)); BaseResult objectBaseResult = new BaseResult<>(); if(cbos.size() == 0){ objectBaseResult.setSuccess(false); throw new PLException("500", new String[]{"没有获取到数据的主键"}); } for (BusinessObject cbo : cbos) { if(StringUtils.isBlank(cbo.revisionid)){ String revisionoid = Arrays.stream(cbo.hisAttrValList).filter(e -> e.attrName.equals("REVISIONOID")).findFirst().map(e -> e.attrVal).orElse(""); cbo.revisionid = revisionoid; } boolean b = platformClientUtil.getBOFService().deleteBusinessObject(cbo,type); if(!b){ throw new PLException("500", new String[]{"数据删除失败!!"}); } } return BaseResult.success(); } /** * 变更所有者 * @param btmname 业务类型 * @param oid 主键 * @return 执行的结果 */ @Override public BaseResult changeBusinessObjectOwner(String btmname, String oid) throws PLException { List cbos = boService.queryCBO(btmname,WebUtil.getOidQuery(oid)); BaseResult objectBaseResult = new BaseResult<>(); if(cbos.size() == 0){ objectBaseResult.setSuccess(false); throw new PLException("500", new String[]{"没有获取到数据的主键"}); } UserInfo userInfo = platformClientUtil.getFrameworkService().getUserObjectByUserName(WebUtil.getCurrentUserId()); for (BusinessObject cbo : cbos) { platformClientUtil.getBOFService().changeBusinessObjectOwner(cbo,userInfo); } return BaseResult.success(); } /** * 变更所有者 * @param btmname 业务类型 * @param oid 主键 * @param releaseStatus 发布状态 * @return 执行的结果 */ @Override @Transactional public BaseResult transferBusinessObject(String btmname, String oid, String toStatus,String releaseStatus) throws PLException { List cbos = boService.queryCBO(btmname,WebUtil.getOidQuery(oid)); BaseResult objectBaseResult = new BaseResult<>(); if(cbos.size() == 0){ objectBaseResult.setSuccess(false); throw new PLException("500", new String[]{"没有获取到数据的主键"}); } for (BusinessObject cbo : cbos) { platformClientUtil.getBOFService().transferBusinessObjectAndRelease(cbo, toStatus, releaseStatus); } return BaseResult.success(); } }