package com.vci.web.service.uidataservice.impl;
|
|
import com.vci.client.common.oq.OQTool;
|
import com.vci.common.qt.object.QueryTemplate;
|
import com.vci.corba.common.PLException;
|
import com.vci.corba.framework.data.UserInfo;
|
import com.vci.corba.omd.data.BusinessObject;
|
import com.vci.corba.omd.data.LinkObject;
|
import com.vci.corba.omd.data.RevisionDataInfo;
|
import com.vci.corba.omd.data.VersionDataInfo;
|
import com.vci.corba.omd.lcm.LifeCycle;
|
import com.vci.corba.omd.ltm.LinkType;
|
import com.vci.corba.omd.qtm.QTInfo;
|
import com.vci.corba.query.data.BOAndLO;
|
import com.vci.dto.*;
|
import com.vci.lcstatuspck.FrameworkDataLCStatus;
|
import com.vci.lcstatuspck.ReleaseDataLCStatus;
|
import com.vci.omd.utils.ObjectTool;
|
import com.vci.pagemodel.*;
|
import com.vci.query.UIDataGridQuery;
|
import com.vci.query.UIFormQuery;
|
import com.vci.query.UILinkTypeDataQuery;
|
import com.vci.query.UITreeQuery;
|
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.dto.BaseLinkModelDTO;
|
import com.vci.starter.web.dto.BaseLinkModelDTOList;
|
import com.vci.starter.web.dto.BaseModelDTO;
|
import com.vci.starter.web.dto.BaseModelDTOList;
|
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.util.Lcm.Func;
|
import com.vci.starter.web.wrapper.VciQueryWrapperForDO;
|
import com.vci.web.enumpck.DeleteTypeEnum;
|
import com.vci.web.enumpck.UIFieldTypeEnum;
|
import com.vci.web.enumpck.UITreeLoadTypeEnum;
|
import com.vci.web.service.*;
|
import com.vci.web.service.impl.WebBoServiceImpl;
|
import com.vci.web.service.impl.WebLoServiceImpl;
|
import com.vci.web.service.uidataservice.UIDataCommonServiceI;
|
import com.vci.web.util.PlatformClientUtil;
|
import com.vci.web.util.WebUtil;
|
import org.apache.commons.lang3.StringUtils;
|
import org.dom4j.DocumentHelper;
|
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.constant.FrameWorkBusLangCodeConstant.DATA_OID_NOT_EXIST;
|
|
/**
|
* UI上的数据查询(通用查询服务)
|
* @author Ludc
|
* @date 2024/12/04
|
*/
|
@Service
|
public class UIDataCommonServiceImpl implements UIDataCommonServiceI {
|
|
/**
|
* 平台的调用客户端
|
*/
|
@Autowired
|
private PlatformClientUtil platformClientUtil;
|
|
/**
|
* UI的服务
|
*/
|
@Autowired
|
private UIEngineServiceI uiEngineService;
|
|
/**
|
* 业务类型
|
*/
|
@Autowired
|
private OsBtmServiceI btmService;
|
/**
|
* 属性服务
|
*/
|
@Autowired
|
private OsAttributeServiceI attrService;
|
|
/**
|
* 链接类型
|
*/
|
@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<String, String>格式
|
* @throws VciBaseException 查询出错的时候会抛出异常
|
*/
|
@Override
|
public DataGrid getDataForGrid(UIDataGridQuery dataGridQuery) throws VciBaseException, PLException {
|
VciBaseUtil.alertNotNull(dataGridQuery,"查询对象",dataGridQuery.getBtmName(),"业务类型",dataGridQuery.getTableDefineId());
|
// TODO: 2024/12/4 Ludc 前端传过来的sourceData参数的vlaue可能是json这儿做一下处理
|
if(Func.isNotEmpty(dataGridQuery.getSourceData())){
|
dataGridQuery.setSourceData(this.convertMapValueJson2Map(dataGridQuery.getSourceData()));
|
}
|
UIComponentVO componentVO = uiEngineService.getComponentByOid(dataGridQuery.getComponentOid(), null);
|
UITableDefineVO tableDefineVO = componentVO.getTableDefineVO();
|
//先判断查询模板是否配置了自定义查询类
|
String bsCustQueryCLsOrUrl = componentVO.getBsDataModel() ;
|
// TODO: 2024/12/5 Ludc 根据UI配置的进行判断是否使用自定义类进行查询(自定义类查询方式优先级高于查询模板)
|
if(Func.isNotBlank(bsCustQueryCLsOrUrl) && isCustomClass(bsCustQueryCLsOrUrl)){
|
//通过反射调用bsCustQueryCLsOrUrl中定义的服务类中的查询方法
|
try {
|
// 获取类的 Class 对象
|
Class<?> clazz = Class.forName(bsCustQueryCLsOrUrl.replace("@",""));
|
// 创建类的实例
|
Object instance = clazz.getDeclaredConstructor().newInstance();
|
// 获取方法getDataForGrid(该方法是接口中统一定义的方法)
|
Method method = clazz.getMethod("getDataForGrid", UIDataGridQuery.class);
|
// 调用方法
|
DataGrid dataGrid = (DataGrid) method.invoke(instance, dataGridQuery);
|
return dataGrid;
|
}catch (Exception e){
|
e.printStackTrace();
|
throw new VciBaseException("获取表格数据时出现错误,原因:"+e.getMessage());
|
}
|
}else{
|
String queryTemplate = Func.isNotEmpty(dataGridQuery.getSourceData())? (String) dataGridQuery.getSourceData().getOrDefault("querytemplate",tableDefineVO.getQueryTemplateName()) :tableDefineVO.getQueryTemplateName();
|
if(StringUtils.isBlank(queryTemplate)){
|
//说明没有设置查询模板,需要看看在这个表格所在的组件有没有设置
|
tableDefineVO = uiEngineService.getTableById(dataGridQuery.getBtmName(), dataGridQuery.getTableDefineId());
|
queryTemplate = tableDefineVO.getQueryTemplateName();
|
}
|
//看看有没有自定义的SQL
|
Set<String> queryFieldList = new HashSet<>();
|
tableDefineVO.getCols().forEach(cols->{
|
//获取参照
|
List<UITableFieldVO> 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<String, String> 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());
|
btmTypeVO = btmService.getBtmByName(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<String, Object> 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 {
|
DataGrid dataGrid = boService.queryGridByScheme(queryTemplate,
|
dataGridQuery.getConditionMap(), replaceMap, dataGridQuery.getPageHelper(), queryFieldList.stream().collect(Collectors.toList()));
|
return dataGrid;
|
}
|
}
|
}
|
|
/**
|
* 获取表单的数据
|
*
|
* @param formQuery 表单的查询条件
|
* @return 表单的数据
|
* @throws VciBaseException 查询出错的时候会抛出异常
|
*/
|
@Override
|
public UIFormDataVO getDataForForm(UIFormQuery formQuery) throws VciBaseException, PLException {
|
VciBaseUtil.alertNotNull(formQuery,"表单的查询对象",formQuery.getBtmName(),"业务类型的信息",formQuery.getSourceOid(),"业务数据的主键",formQuery.getFormDefineId(),"表单的定义编号");
|
// TODO: 2024/12/4 Ludc 前端传过来的sourceData参数的vlaue可能是json这儿做一下处理
|
if(Func.isNotEmpty(formQuery.getSourceData())){
|
formQuery.setSourceData(this.convertMapValueJson2Map(formQuery.getSourceData()));
|
}
|
//先判断查询模板是否配置了自定义查询类
|
UIComponentVO componentVO = uiEngineService.getComponentByOid(formQuery.getComponentOid(), null);
|
//UIFormDefineVO formDefineVO = uiEngineService.getFormById(formQuery.getBtmName(),formQuery.getFormDefineId());
|
String bsCustQueryCLsOrUrl = componentVO.getBsDataModel();
|
if(Func.isNotBlank(bsCustQueryCLsOrUrl) && isCustomClass(bsCustQueryCLsOrUrl)){
|
//通过反射调用bsCustQueryCLsOrUrl中定义的服务类中的查询方法
|
try {
|
// 获取类的 Class 对象
|
Class<?> clazz = Class.forName(bsCustQueryCLsOrUrl.replace("@",""));
|
// 创建类的实例
|
Object instance = clazz.getDeclaredConstructor().newInstance();
|
// 获取方法getDataForGrid(该方法是接口中统一定义的方法)
|
Method method = clazz.getMethod("getDataForForm", UIFormQuery.class);
|
// 调用方法
|
UIFormDataVO uiFormDataVO = (UIFormDataVO) method.invoke(instance, formQuery);
|
return uiFormDataVO;
|
}catch (Exception e){
|
e.printStackTrace();
|
throw new VciBaseException("获取表格数据时出现错误,原因:"+e.getMessage());
|
}
|
}else{
|
UIFormDefineVO formDefineVO = componentVO.getFormDefineVO();
|
String queryTemplate = !CollectionUtils.isEmpty(formQuery.getSourceData())? (String) formQuery.getSourceData().getOrDefault("querytemplate",formDefineVO.getQueryTemplateName()) :formDefineVO.getQueryTemplateName();
|
Set<String> queryFieldList = formDefineVO.getItems().stream().filter(s->!UIFieldTypeEnum.CUSTOM.getValue().equalsIgnoreCase(s.getType())).map(UIFormItemVO::getField).collect(Collectors.toSet());
|
//获取参照
|
List<UIFormItemVO> 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<String, String> 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.getBtmByName(formQuery.getBtmName());
|
queryFieldList.addAll(btmTypeVO.getAttributes().stream().map(OsBtmTypeAttributeVO::getId).collect(Collectors.toList()));
|
}
|
queryFieldList.add("creator_name");
|
queryFieldList.add("lastmodifier_name");
|
Map<String,String> conditionMap = WebUtil.getOidQuery(formQuery.getSourceOid());
|
Map<String, Object> replaceMap = wrapperReplaceMap(formQuery.getSourceData());
|
UIFormDataVO formDataVO = new UIFormDataVO();
|
replaceMap.put("oid", formQuery.getSourceOid().trim());
|
if(!formDefineVO.isLinkTypeFlag()) {
|
List<BusinessObject> 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<String, Object>) dataGrid.getData().get(0));
|
}
|
}
|
//查询附件
|
formDataVO.setAttachmentFileVOs(fileObjectService.listFilesByOwnbiz(formQuery.getSourceOid(), formQuery.getBtmName(), "attachment"));
|
List<UIFormItemVO> fileItems = formDefineVO.getItems().stream().filter(s -> UIFieldTypeEnum.FILE.getValue().equalsIgnoreCase(s.getType())).collect(Collectors.toList());
|
if(!CollectionUtils.isEmpty(fileItems)){
|
//字段的属性肯定不会超过1000个
|
//查询这些的值
|
List<String> 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<VciFileObjectVO> fileObjectVOS = fileObjectService.listFileObjectByPath(filePathList, "filePathField");
|
if(!CollectionUtils.isEmpty(fileObjectVOS)){
|
Map<String,VciFileObjectVO> fileObjectVOMap = fileObjectVOS.stream().collect(Collectors.toMap(s->s.getFilePath(),t->t,(o1,o2)->o2));
|
Map<String,VciFileObjectVO> 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<String,Object> wrapperReplaceMap(Map<String,Object> sourceDataMap){
|
Map<String,Object> replaceMap =!CollectionUtils.isEmpty(sourceDataMap)? sourceDataMap:new HashMap<>();
|
if(!replaceMap.containsKey("f_oid")){
|
replaceMap.put("f_oid",replaceMap.getOrDefault("oid",""));
|
}
|
String fOid = replaceMap.get("f_oid").toString();
|
if(fOid.contains(TREE_NODE_ID_SEP)){
|
replaceMap.put("f_oid",fOid.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<UIDataTree> getDataForTree(UITreeQuery treeQuery) throws Exception {
|
VciBaseUtil.alertNotNull(treeQuery,"表单的查询对象",treeQuery.getBtmName(),"业务类型的信息",treeQuery.getComponentOid(),"树所在的组件的主键");
|
// TODO: 2024/12/4 Ludc 前端传过来的sourceData参数的vlaue可能是json这儿做一下处理
|
if(Func.isNotEmpty(treeQuery.getSourceData())){
|
treeQuery.setSourceData(this.convertMapValueJson2Map(treeQuery.getSourceData()));
|
}
|
Map<String, OsAttributeVO> attributeVOMap = attrService.selectAllAttributeMap();
|
UIComponentVO componentVO = uiEngineService.getComponentByOid(treeQuery.getComponentOid(),attributeVOMap);
|
if(componentVO == null || StringUtils.isBlank(componentVO.getOid())){
|
throw new VciBaseException("树的配置信息没有获取到");
|
}
|
String bsCustQueryCLsOrUrl = componentVO.getBsDataModel();
|
if(Func.isNotBlank(bsCustQueryCLsOrUrl) && isCustomClass(bsCustQueryCLsOrUrl)){
|
//通过反射调用bsCustQueryCLsOrUrl中定义的服务类中的查询方法
|
try {
|
// 获取类的 Class 对象
|
Class<?> clazz = Class.forName(bsCustQueryCLsOrUrl.replace("@",""));
|
// 创建类的实例
|
Object instance = clazz.getDeclaredConstructor().newInstance();
|
// 获取方法getDataForGrid(该方法是接口中统一定义的方法)
|
Method method = clazz.getMethod("getDataForForm", UITreeQuery.class);
|
// 调用方法
|
List<UIDataTree> uiDataTreeList = (List<UIDataTree>) method.invoke(instance, treeQuery);
|
return uiDataTreeList;
|
}catch (Exception e){
|
e.printStackTrace();
|
throw new VciBaseException("获取表格数据时出现错误,原因:"+e.getMessage());
|
}
|
}else{
|
//树形有两种,一种是业务类型里自参照,一种是链接类型
|
UITreeDefineVO treeDefineVO = componentVO.getTreeDefineVO();
|
if(treeDefineVO == null){
|
throw new VciBaseException("这个组件不是树");
|
}
|
if(!treeQuery.isLinkTypeFlag() && StringUtils.isBlank(treeQuery.getParentBtmName())){
|
treeQuery.setParentBtmName(treeQuery.getBtmName());
|
}
|
//TODO: 替换树定义上的正反向查询属性,因为正反向查询是由链接类型查询模板上控制的
|
boolean isOrientation = false; //是否反向,使用模板上配置的
|
String qtName = treeDefineVO.getQueryTemplateName();
|
if(Func.isNotBlank(treeDefineVO.getOrientation())){
|
isOrientation = treeDefineVO.getOrientation().equalsIgnoreCase("opposite");
|
}else{
|
if(Func.isNotBlank(treeDefineVO.getLinkType()) && Func.isNotBlank(qtName)){
|
QTInfo wrapper = platformClientUtil.getQTDService().getQT(qtName);
|
QueryTemplate qt = OQTool.getQTByDoc(DocumentHelper.parseText(wrapper.qtText), qtName);
|
isOrientation = qt.getDirection().equals("opposite");
|
}
|
}
|
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())? (String) treeQuery.getSourceData().getOrDefault("querytemplate",treeDefineVO.getQueryTemplateName()) :treeDefineVO.getQueryTemplateName());
|
String valueField = treeQuery.isLinkTypeFlag()?(!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<UIDataTree> rootTreeList = new ArrayList<>();
|
List<String> queryFieldList = new ArrayList<>();
|
queryFieldList.add("creator_name");
|
queryFieldList.add("lastmodifier_name");
|
String rootExpress = StringUtils.isNotBlank(treeQuery.getRootExpress())?treeQuery.getRootExpress():treeDefineVO.getRootContent();
|
Map<String, Object> replaceMap = wrapperReplaceMap(treeQuery.getSourceData());
|
if(StringUtils.isBlank(treeDefineVO.getLinkType())){
|
//这个是业务类型的自参照
|
//以前的平台没有对自参照这种有全部查询的
|
OsBtmTypeVO btmTypeVO = btmService.getBtmByName(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<BusinessObject> 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<BusinessObject> 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());
|
LinkType linkType = platformClientUtil.getLinkTypeService().getLinkType(treeDefineVO.getLinkType());
|
//queryFieldList.addAll(linkTypeVO.getAttributes().stream().map(OsLinkTypeAttributeVO::getId).collect(Collectors.toList()));
|
queryFieldList.addAll(Arrays.asList(linkType.attributes));
|
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(isOrientation);
|
linkTypeDataQuery.setToBtmType(treeDefineVO.getBtmType());
|
linkTypeDataQuery.setLinkType(treeDefineVO.getLinkType());
|
if(UITreeLoadTypeEnum.ALL.getValue().equalsIgnoreCase(treeDefineVO.getLoadType())){
|
linkTypeDataQuery.setQueryAllLevel(true);
|
}
|
if(treeQuery.isQueryRoot()){
|
//查询根节点.我们需要判断是否设置了根节点的查询条件
|
List<BOAndLO> 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(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("根节点没有配置查询条件,也没有来源数据");
|
}
|
UIDataTree root = new UIDataTree();
|
root.setOid((String) 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(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(isOrientation?"t_oid":"f_oid",treeQuery.getParentOid());
|
}
|
return cloAndCbo2Trees(loService.queryCLOAndBoByLinkType(linkTypeDataQuery),valueField,textField,parentFieldName,treeQuery.isShowCheckBox(),treeQuery.getParentOid());
|
}
|
}
|
}
|
}
|
|
/**
|
* 获取数据(根据查询模板查询对象,返回的结构按照ui定义,定义的模板类型返回)
|
* @param treeQuery 树形查询条件
|
* @return 树形数据
|
* @throws VciBaseException 查询出错的时候会抛出异常
|
*/
|
@Override
|
public BaseResult getDataByTemp(UITreeQuery treeQuery) throws Exception {
|
VciBaseUtil.alertNotNull(treeQuery,"表单的查询对象",treeQuery.getComponentOid(),"当前组件的主键");
|
// TODO: 2024/12/4 Ludc 前端传过来的sourceData参数的vlaue可能是json这儿做一下处理
|
if(Func.isNotEmpty(treeQuery.getSourceData())){
|
treeQuery.setSourceData(this.convertMapValueJson2Map(treeQuery.getSourceData()));
|
}
|
//1、先查询页面定义组件
|
Map<String, OsAttributeVO> attributeVOMap = attrService.selectAllAttributeMap();
|
UIComponentVO componentVO = uiEngineService.getComponentByOid(treeQuery.getComponentOid(),attributeVOMap);
|
if(componentVO == null || StringUtils.isBlank(componentVO.getOid())){
|
throw new VciBaseException("未获取到界面配置信息!");
|
}
|
// 2、根据配置的查询模板查询数据(需要考虑全面一点),
|
// 这儿根据当前类型来获取是什么类型的查询模板,然后做对应的查询处理
|
//TODO: 替换树定义上的正反向查询属性,因为正反向查询是由链接类型查询模板上控制的
|
UITreeDefineVO treeDefineVO = componentVO.getTreeDefineVO();
|
boolean isOrientation = false; //是否反向,使用模板上配置的
|
String qtName = treeDefineVO.getQueryTemplateName();
|
if(Func.isNotBlank(treeDefineVO.getOrientation())){
|
isOrientation = treeDefineVO.getOrientation().equalsIgnoreCase("opposite");
|
}else{
|
if(Func.isNotBlank(treeDefineVO.getLinkType()) && Func.isNotBlank(qtName)){
|
QTInfo wrapper = platformClientUtil.getQTDService().getQT(qtName);
|
QueryTemplate qt = OQTool.getQTByDoc(DocumentHelper.parseText(wrapper.qtText), qtName);
|
isOrientation = qt.getDirection().equals("opposite");
|
}
|
}
|
|
String queryTemplate = StringUtils.isNotBlank(treeQuery.getQueryTemplate())?treeQuery.getQueryTemplate():(!CollectionUtils.isEmpty(treeQuery.getSourceData())? (String) treeQuery.getSourceData().getOrDefault("querytemplate",treeDefineVO.getQueryTemplateName()) :treeDefineVO.getQueryTemplateName());
|
Map<String, Object> replaceMap = wrapperReplaceMap(treeQuery.getSourceData());
|
List<String> queryFieldList = new ArrayList<>();
|
String valueField = treeQuery.isLinkTypeFlag()?(!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");
|
String rootExpress = StringUtils.isNotBlank(treeQuery.getRootExpress())?treeQuery.getRootExpress():treeDefineVO.getRootContent();
|
String parentFieldName = treeQuery.getParentFieldName();
|
if(parentFieldName.contains(",")){
|
parentFieldName = parentFieldName.split(",")[0];
|
}
|
queryFieldList.add("creator_name");
|
queryFieldList.add("lastmodifier_name");
|
OsBtmTypeVO btmTypeVO = btmService.getBtmByName(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);
|
List<BusinessObject> rootCbos = boService.queryCBOByScheme(queryTemplate, null, replaceMap);
|
|
//3、根据不同的组件返回不同的数据类型(树、列表、树表、自定义模板、表单等)
|
List<UIDataTree> rootTreeList = null;
|
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(false);
|
}
|
//queryTreeForBO(rootTreeList,treeDefineVO.getQueryTemplateName(),queryFieldList,treeQueryObject);
|
}
|
return BaseResult.tree(rootTreeList);
|
}
|
|
/**
|
* 业务类型的属性查询
|
* @param rootTreeList 根节点的内容
|
* @param queryTemplate 查询模板
|
* @param queryFieldList 查询的字段
|
* @param treeQueryObject 树形查询对象,需要valueField和textField,还有parentFieldName,和checkBox
|
*/
|
private void queryTreeForBO(List<UIDataTree> rootTreeList, String queryTemplate,List<String> queryFieldList,TreeQueryObject treeQueryObject) {
|
for (UIDataTree rootTree : rootTreeList) {
|
List<BusinessObject> thisChildren = null;
|
Map<String,Object> sourceDataMap = rootTree.getAttributes();
|
sourceDataMap.put("f_oid",rootTree.getOid());
|
Map<String,String> 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((String) sourceDataMap.getOrDefault("btmname",sourceDataMap.getOrDefault("btmName",treeQueryObject.getParentBtmName())), conditionMap, null, queryFieldList);
|
}
|
List<UIDataTree> 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<UIDataTree> rootTreeList, UILinkTypeDataQuery linkTypeDataQuery,String parentFieldName,String valueField,String textField,boolean showCheckBox) {
|
for (UIDataTree rootTree : rootTreeList) {
|
Map<String,String> 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<UIDataTree> cbo2Trees(Collection<BusinessObject> cbos,String valueField,String textField,String parentFieldName,boolean showCheckBox,String parentOid){
|
final int[] i = {0};
|
List<UIDataTree> rootList = new ArrayList<>();
|
List<UIDataTree> children = new ArrayList<>();
|
cbos.stream().forEach(cbo->{
|
UIDataTree tree = new UIDataTree();
|
tree.setOid(getValueByExpress(cbo,valueField));
|
tree.setText(getValueByExpress(cbo,textField));
|
if(StringUtils.isNotBlank(parentFieldName)){
|
tree.setParentId(ObjectTool.getBOAttributeValue(cbo,parentFieldName));
|
}
|
Map<String,Object> cbo2Map = boService.cbo2Map(cbo);
|
Map<String, Object> returnMap = new HashMap<>();
|
returnMap.put((String) cbo2Map.get("btmname"),cbo2Map);
|
tree.setAttributes(returnMap);
|
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 UIDataTree.getChildList(rootList,children);
|
}
|
|
/**
|
* 链接类型转换为树
|
* @param boAndLOS 业务类型和链接类型
|
* @param valueField 值表达式
|
* @param textField 显示文本表达式
|
* @param parentFieldName 上级字段,默认是f_oid,反向的时候请自行设置
|
* @param showCheckBox 是否显示复选框
|
* @param parentOid 上级的值
|
* @return 树形数据
|
*/
|
public List<UIDataTree> cloAndCbo2Trees(Collection<BOAndLO> boAndLOS, String valueField, String textField, String parentFieldName, boolean showCheckBox, String parentOid){
|
final int[] i = {0};
|
List<UIDataTree> rootList = new ArrayList<>();
|
List<UIDataTree> children = new ArrayList<>();
|
boAndLOS.stream().forEach(boAndLO->{
|
UIDataTree tree = new UIDataTree();
|
BusinessObject cbo = new BusinessObject();
|
cbo = boAndLO.bo;
|
LinkObject clo = new LinkObject();
|
clo = boAndLO.lo;
|
Map<String,Object> cloMap = loService.clo2Map(clo);
|
Map<String,Object> cbo2Map = boService.cbo2Map(cbo);
|
|
/*if(!CollectionUtils.isEmpty(cbo2Map)){
|
cbo2Map.forEach((key,value)->{
|
//TODO: 这儿为啥要拼接上parentFieldName,导致后面freemarker表达式无法正确替换
|
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));
|
}
|
}
|
//TODO:返回的数据改成按链接类型和业务类型为key:值为对应的属性集合形式返回
|
Map<String, Object> returnMap = new HashMap<>();
|
returnMap.put((String) cloMap.get("linktypename"),cloMap);
|
returnMap.put((String) cbo2Map.get("btmname"),cbo2Map);
|
// TODO: 2024/12/4 Ludc 将一些重要的后续可能需要用到的属性放入第一层Map
|
String fOid = (String)cbo2Map.get("f_oid");
|
if(Func.isNotBlank(fOid)){
|
returnMap.put("f_oid",fOid);
|
}else{
|
if(Func.isNotEmpty(cbo2Map.get("oid"))){
|
returnMap.put("oid",cbo2Map.get("oid").toString());
|
}
|
}
|
|
tree.setAttributes(returnMap);
|
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 UIDataTree.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<String> 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<String,Object> valueMap,Map<String,Object> boValueMap,String fieldExpress){
|
if(fieldExpress.contains("${")){
|
//使用freemarker处理
|
/*
|
TODO:表达式存在T_OID.name这种形式时freemarker替换规则是从T_OID这个对象中招name属性,
|
但是valueMap是一个String,String的Map所以需要将T_OID.或F_OID.去掉,因为不管是查询的
|
form端还是to端都是平台查好放在业务属性boValueMap集合中的,所以直接替就可以
|
*/
|
if(fieldExpress.contains(".")){
|
//去除t_oid、T_OID以及f_oid、F_OID
|
fieldExpress = fieldExpress
|
.replace("t_oid.","")
|
.replace("T_OID.","")
|
.replace("f_oid.","")
|
.replace("F_OID.","");
|
}
|
return VciBaseUtil.replaceByFreeMarker(fieldExpress,boValueMap);
|
}else {
|
List<String> fieldList = VciBaseUtil.str2List(fieldExpress);
|
Map<String,Object> valueLowMap = new HashMap<>();
|
valueMap.forEach((key,value)->{
|
valueLowMap.put(key.toLowerCase(),value);
|
});
|
Map<String,Object> 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(boLowValueMap.getOrDefault(field,valueLowMap.getOrDefault(field,""))).append(" ");
|
});
|
return sb.toString().trim();
|
}
|
}
|
|
/**
|
* 处理要查询的字段
|
* @param queryFieldList 查询的字段列表
|
* @param fieldExpress 字段表达式
|
*/
|
private void addQueryField(List<String> 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<String> 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<String, Object> beanMap = ApplicationContextProvider.getApplicationContext().getBeansWithAnnotation(VciChangeDataPlugin.class);
|
if(!CollectionUtils.isEmpty(beanMap)){
|
beanMap.forEach((beanName,bean)->{
|
Method[] methods = bean.getClass().getMethods();
|
List<Method> 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<BusinessObject> cbos, Collection<LinkObject> 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<String, Object> beanMap = ApplicationContextProvider.getApplicationContext().getBeansWithAnnotation(VciChangeDataPlugin.class);
|
if(!CollectionUtils.isEmpty(beanMap)){
|
beanMap.forEach((beanName,bean)->{
|
Method[] methods = bean.getClass().getMethods();
|
List<Method> 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();
|
BeanUtilForVCI.convert(formDataDTO,modelDTO);
|
modelDTO.setData(formDataDTO.getData());
|
List<BaseModelDTO> 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());
|
BeanUtilForVCI.convert(formLinkDataDTO,modelDTO);
|
List<BaseLinkModelDTO> 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<BaseModelDTO> modelDTOS = new ArrayList<>();
|
modelDTOS.stream().findAny().orElseGet(()->null);
|
formDataDTOList.getFormDataDTOS().forEach(formDataDTO -> {
|
BaseModelDTO modelDTO = new BaseModelDTO();
|
BeanUtilForVCI.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<BaseLinkModelDTO> modelDTOS = new ArrayList<>();
|
formLinkDataDTOList.getDataDTOList().forEach(formDataDTO -> {
|
BaseLinkModelDTO modelDTO = new BaseLinkModelDTO();
|
BeanUtilForVCI.convert((BaseLinkModelDTO)formDataDTO,modelDTO);
|
modelDTO.setData(formDataDTO.getData());
|
modelDTOS.add(modelDTO);
|
});
|
modelDTOList.setDataList(modelDTOS);
|
return modelDTOList;
|
}
|
|
/**
|
* 添加数据
|
*
|
* @param formDataDTO 数据的传输对象
|
* @return 执行结果和显示后的值
|
* @throws VciBaseException 保存出错的时候会抛出异常
|
*/
|
@Override
|
public BaseResult<Map<String, Object>> addSave(FormDataDTO formDataDTO) throws VciBaseException, PLException {
|
//首先判断对象是否为空
|
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<BusinessObject> resultCbo = wrapperCbo(formDataDTO,formDefineVO,false,false,false);
|
if(!resultCbo.isSuccess()){
|
return BaseResult.fail(resultCbo.getMsg(),resultCbo.getMsgObjs());
|
}
|
//执行保存
|
BaseResult<Map<String,Object>> 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<BusinessObject> wrapperCbo(FormDataDTO formDataDTO,UIFormDefineVO formDefineVO,boolean editFlag,boolean newRevision,boolean newVersion) throws PLException {
|
//扩展属性的值
|
Map<String, String> data = formDataDTO.getData();
|
Map<String,String> 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<String,String> 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<String,String> baseDataMap = formDataDTO2MapLow(formDataDTO);
|
Map<String,String> 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.revoid);
|
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<String,String> formDataDTO2MapLow(FormDataDTO formDataDTO){
|
Map<String,String> data = new HashMap<>();
|
BaseModel baseModel = (BaseModel)formDataDTO;
|
Map<String, String> 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<String,String> formLinkDataDTO2MapLow(FormLinkDataDTO formLinkDataDTO){
|
Map<String,String> data = new HashMap<>();
|
BaseLinkModelDTO baseModel = (BaseLinkModelDTO)formLinkDataDTO;
|
Map<String, String> 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<String> batchAddSave(FormDataDTOList formDataDTOList) throws VciBaseException, PLException {
|
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<BusinessObject> addBos = new ArrayList<>();
|
List<BusinessObject> afterBOs = new ArrayList<>();
|
List<BusinessObject> afterCBOs = new ArrayList<>();
|
Map<String,List<String>> releasedFileOids = new HashMap<>();
|
for(FormDataDTO formDataDTO:formDataDTOList.getFormDataDTOS()) {
|
BaseResult<BusinessObject> 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]),DeleteTypeEnum.OID_AND_TS.getValue());
|
} 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<Map<String, Object>> editSave(FormDataDTO formDataDTO) throws VciBaseException, PLException {
|
//首先判断对象是否为空
|
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<BusinessObject> resultCbo = wrapperCbo(formDataDTO,formDefineVO,true,false,false);
|
if(!resultCbo.isSuccess()){
|
return BaseResult.fail(resultCbo.getMsg(),resultCbo.getMsgObjs());
|
}
|
//执行保存
|
BaseResult<Map<String,Object>> 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<Map<String, Object>> 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<BusinessObject> businessObjects = null;
|
Date ts = formDataDTO.getTs();
|
Map<String,String> 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<String, String> data = formDataDTO.getData();
|
Map<String,String> dataLow = new HashMap<>();
|
data.forEach((key,value)->{
|
dataLow.put(key.toLowerCase(),value);
|
});
|
|
Map<String,String> baseDataMap = formDataDTO2MapLow(formDataDTO);
|
Map<String,String> 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<Map<String, Object>> 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<String> batchEditSave(FormDataDTOList formDataDTOList) throws VciBaseException, PLException {
|
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<BusinessObject> updateCBOS = new ArrayList<>();
|
Map<String,List<String>> releasedFileOids = new HashMap<>();
|
List<BusinessObject> afterCBOs = new ArrayList<>();
|
for(FormDataDTO formDataDTO:formDataDTOList.getFormDataDTOS()) {
|
BaseResult<BusinessObject> 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, PLException {
|
VciBaseUtil.alertNotNull(deleteDataDTO,"数据传输对象",deleteDataDTO.getDataList(),"数据传输对象");
|
String btmName = deleteDataDTO.getDataList().get(0).getBtmName();
|
List<String> oidList = deleteDataDTO.getDataList().stream().map(BaseModelDTO::getOid).collect(Collectors.toList());
|
//看看级联删除。只有自己引用自己的时候可以级联删除
|
List<BusinessObject> cbo = null;
|
if(deleteDataDTO.isCascade()){
|
//级联删除
|
OsBtmTypeVO btmTypeVO = btmService.getBtmByName(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<BusinessObject> finalCbo = cbo;
|
Collection<Collection<String>> oidCollections = WebUtil.switchCollectionForOracleIn(finalCbo.stream().map(bo -> bo.oid).collect(Collectors.toList()));
|
List<OsUsedAttributeVO> 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<String,String> 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 = null;
|
try {
|
btmTypeVO = btmService.getBtmById(usedAttributeVO.getPkBtmType());
|
} catch (PLException e) {
|
e.printStackTrace();
|
}
|
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<String,String> conditionMap = new HashMap<>();
|
conditionMap.put(usedAttributeVO.getId(),QueryOptionConstant.IN + "(" + VciBaseUtil.toInSql(oids.toArray(new String[0])) + ")");
|
if(StringUtils.isNotBlank(usedAttributeVO.getPkBtmType())) {
|
List<BusinessObject> 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<String> linkAddSave(FormLinkDataDTO formLinkDataDTO) throws VciBaseException, PLException {
|
//首先判断对象是否为空
|
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<String,String> boData = new HashMap<>();
|
Map<String,String> 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端" + "的业务类型为空");
|
}
|
|
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<BusinessObject> result = wrapperToCbo(formLinkDataDTO,formDefineVO,toOid,toBtmName,boData);
|
if(!result.isSuccess()){
|
return BaseResult.fail(result.getMsg(),result.getMsgObjs());
|
}
|
BusinessObject toCbo = result.getObj();
|
//初始化链接类型的值
|
BaseResult<LinkObject> resultClo = wrapperOnlyCLO(formLinkDataDTO, loData, formDefineVO, false);
|
if(!resultClo.isSuccess()){
|
return BaseResult.fail(resultClo.getMsg(),resultClo.getMsgObjs());
|
}
|
clo = resultClo.getObj();
|
if(StringUtils.isBlank(clo.toOid)){
|
clo.toOid = toCbo.oid;
|
}
|
//执行保存
|
BusinessObject[] bos = new BusinessObject[1];
|
ObjectTool.dealBusinessObjectNullValue(toCbo);
|
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<LinkObject> wrapperOnlyCLO(FormLinkDataDTO formLinkDataDTO,Map<String,String> loData,UIFormDefineVO formDefineVO,boolean editFlag){
|
Map<String,String> baseDataMap = formLinkDataDTO2MapLow(formLinkDataDTO);
|
Map<String,String> 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 = 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();
|
clo.toOid = formLinkDataDTO.getToid();
|
clo.toNameOid = formLinkDataDTO.getTnameoid();
|
clo.toRevOid = formLinkDataDTO.getTrevisionoid();
|
clo.toBTName = formLinkDataDTO.getTbtmname();
|
clo.fromOid = formLinkDataDTO.getFoid();
|
clo.fromBTName = formLinkDataDTO.getFbtmname();
|
clo.fromNameOid = formLinkDataDTO.getFnameoid();
|
clo.fromRevOid = formLinkDataDTO.getFrevisionoid();
|
}
|
//
|
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<BusinessObject> wrapperToCbo(FormLinkDataDTO formLinkDataDTO,UIFormDefineVO formDefineVO,String toOid,String toBtmName,Map<String,String> boData) throws PLException {
|
Map<String,String> 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<String,String> 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<String,String> dataLow){
|
final BaseResult[] result = {BaseResult.success()};
|
if(prefix == null){
|
prefix = "";
|
}
|
List<UIFormItemVO> items = formDefineVO.getItems();
|
List<UIFormItemVO> 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<String,String> dataLow,boolean editFlag){
|
final BaseResult[] result = {BaseResult.success()};
|
List<UIFormItemVO> 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<String,String> 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<String,String> dataLowMap,Map<String,String> baseDataMap,boolean editFlag,boolean newRevision,boolean newVersion) throws PLException {
|
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);
|
OsBtmTypeVO btmTypeVO = btmService.getBtmByName(btmName);
|
//List<String> 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.revoid = 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.getInitialValue();
|
}
|
if (StringUtils.isBlank(cbo.nameoid)) {
|
cbo.nameoid = VciBaseUtil.getPk();
|
}
|
if (StringUtils.isBlank(cbo.revoid)) {
|
cbo.revoid = 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<Map.Entry<String, String>> iterator = baseDataMap.entrySet().iterator();
|
// while(iterator.hasNext()){
|
// Map.Entry<String, String> next = iterator.next();
|
// if(!attributeList.contains(next.getKey())){
|
// iterator.remove();
|
// }
|
// }
|
setValueToCbo(dataLowMap,baseDataMap,cbo,editFlag);
|
//TODO:默认属性需要放在cbo外层
|
if(StringUtils.isNotBlank(baseDataMap.getOrDefault("id",""))){
|
cbo.id = baseDataMap.getOrDefault("id","");
|
}
|
if(StringUtils.isNotBlank(baseDataMap.getOrDefault("name",""))){
|
cbo.name = baseDataMap.getOrDefault("name","");
|
}
|
if(StringUtils.isNotBlank(baseDataMap.getOrDefault("description",""))){
|
cbo.description = baseDataMap.getOrDefault("description","");
|
}
|
return cbo;
|
}
|
|
/**
|
* 基础的属性
|
*/
|
public static final List<String> basicFields = new ArrayList<String>(){{
|
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<String, String> dataLow, Map<String, String> 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, PLException {
|
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();
|
|
Map<String,String> boData = new HashMap<>();
|
Map<String,String> 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<BusinessObject> result = wrapperToCbo(formLinkDataDTO, formDefineVO, toOid, toBtmName, boData);
|
if (!result.isSuccess()) {
|
return BaseResult.fail(result.getMsg(), result.getMsgObjs());
|
}
|
toCbo= result.getObj();
|
}
|
|
//初始化链接类型的值
|
BaseResult<LinkObject> 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<LinkObject> clos = new ArrayList<>();
|
VciBaseUtil.switchListForOracleIn(deleteLinkDataDTO.getDataList()).stream().forEach(linkModelDTOs->{
|
Map<String,String> conditionMap = new HashMap<>();
|
conditionMap.put("oid",QueryOptionConstant.IN +"(" + VciBaseUtil.toInSql(linkModelDTOs.stream().map(BaseLinkModelDTO::getOid).toArray(String[]::new)) +")");
|
List<LinkObject> LinkObjects = loService.queryCLO(linkModelDTOs.get(0).getLinkType(), conditionMap);
|
if(!CollectionUtils.isEmpty(LinkObjects)){
|
clos.addAll(LinkObjects);
|
}
|
});
|
if(CollectionUtils.isEmpty(clos)){
|
throw new VciBaseException("使用主键没有在系统中找到链接类型的数据");
|
}
|
Map<String,List<LinkObject>> fromBtmGroups = clos.stream().collect(Collectors.groupingBy(s->s.fromBTName));
|
Map<String,List<LinkObject>> toBtmGroups = clos.stream().collect(Collectors.groupingBy(s->s.toBTName));
|
Map<String,List<BusinessObject>> fromBtmDataGroups = new HashMap<>();
|
Map<String,List<BusinessObject>> toBtmDataGroups = new HashMap<>();
|
if(!CollectionUtils.isEmpty(fromBtmGroups)){
|
fromBtmGroups.forEach((btmType,cloList)->{
|
List<BusinessObject> 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<BusinessObject> cbos = boService.selectCBOByOidCollection(cloList.stream().map(clo -> clo.toOid).collect(Collectors.toList()), btmType);
|
toBtmDataGroups.put(btmType,cbos);
|
});
|
}
|
|
if(StringUtils.isNotBlank(deleteLinkDataDTO.getCheckNotDelete())){
|
//需要校验内容
|
Map<String, String> 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<LinkObject> 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]), DeleteTypeEnum.OID_AND_TS.getValue());
|
}catch (PLException vciError) {
|
throw WebUtil.getVciBaseException(vciError);
|
}
|
});
|
}
|
if(deleteLinkDataDTO.isDeleteToData()){
|
toBtmDataGroups.forEach((btm,cbos)->{
|
try{
|
platformClientUtil.getBOFactoryService().batchDeleteBusinessObject(cbos.toArray(new BusinessObject[0]),DeleteTypeEnum.OID_AND_TS.getValue());
|
}catch (PLException vciError) {
|
throw WebUtil.getVciBaseException(vciError);
|
}
|
});
|
}
|
return BaseResult.success();
|
}
|
|
/**
|
* 获取参照的信息
|
*
|
* @param referConfigVO 参照的配置
|
* @param pageHelper 分页的工具
|
* @return 列表数据
|
*/
|
@Override
|
public DataGrid referDataGrid(ReferConfigVO referConfigVO, PageHelper pageHelper) throws PLException {
|
checkReferConfig(referConfigVO);
|
//使用业务类型查询
|
OsBtmTypeVO btmById = btmService.getBtmByName(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<Tree> referTree(ReferConfigVO referConfigVO) {
|
checkReferConfig(referConfigVO);
|
if(referConfigVO.getConditionMap() == null){
|
referConfigVO.setConditionMap(new HashMap<>());
|
}
|
|
List<BusinessObject> 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<Map<String,String>> getDataAttr(String btmname, String oid) {
|
VciBaseUtil.alertNotNull(btmname,"业务类型的信息",oid,"业务数据的主键");
|
List<BusinessObject> cbos = boService.queryCBO(btmname,WebUtil.getOidQuery(oid));
|
List<Map<String,String>> dataMap = new ArrayList<>();
|
if(!CollectionUtils.isEmpty(cbos)){
|
cbos.stream().forEach(cbo->{
|
Map<String,String> 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<BusinessObject> cbos = boService.queryCBO(btmname,WebUtil.getOidQuery(oid));
|
BaseResult<Object> objectBaseResult = new BaseResult<>();
|
if(cbos.size() == 0){
|
objectBaseResult.setSuccess(false);
|
throw new PLException("500", new String[]{"没有获取到数据的主键"});
|
}
|
for (BusinessObject cbo : cbos) {
|
if(StringUtils.isBlank(cbo.revoid)){
|
String revisionoid = Arrays.stream(cbo.hisAttrValList).filter(e -> e.name.equals("REVISIONOID")).findFirst().map(e -> e.value).orElse("");
|
cbo.revoid = 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<BusinessObject> cbos = boService.queryCBO(btmname,WebUtil.getOidQuery(oid));
|
BaseResult<Object> 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<BusinessObject> cbos = boService.queryCBO(btmname,WebUtil.getOidQuery(oid));
|
BaseResult<Object> 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();
|
}
|
}
|