Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/UIDataServiceImpl.java
@@ -1,16 +1,15 @@
package com.vci.web.service.impl;
import com.vci.client.common.providers.ClientServiceProvider;
import com.vci.corba.common.PLException;
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.framework.data.UserInfo;
import com.vci.corba.omd.btm.BizType;
import com.vci.corba.omd.data.*;
import com.vci.corba.omd.lcm.LifeCycle;
import com.vci.file.pagemodel.VciFileObjectVO;
import com.vci.dto.*;
import com.vci.frameworkcore.lcstatuspck.FrameworkDataLCStatus;
import com.vci.frameworkcore.lcstatuspck.ReleaseDataLCStatus;
import com.vci.omd.utils.ObjectTool;
import com.vci.pagemodel.*;
import com.vci.starter.revision.bo.TreeWrapperOptions;
import com.vci.starter.web.annotation.bus.VciChangeDataAfter;
import com.vci.starter.web.annotation.bus.VciChangeDataBefore;
@@ -23,10 +22,9 @@
import com.vci.starter.web.pagemodel.*;
import com.vci.starter.web.util.*;
import com.vci.starter.web.wrapper.VciQueryWrapperForDO;
import com.vci.web.dto.*;
import com.vci.web.enumpck.DeleteTypeEnum;
import com.vci.web.enumpck.UIFieldTypeEnum;
import com.vci.web.enumpck.UITreeLoadTypeEnum;
import com.vci.web.pageModel.*;
import com.vci.web.query.UIDataGridQuery;
import com.vci.web.query.UIFormQuery;
import com.vci.web.query.UILinkTypeDataQuery;
@@ -37,13 +35,15 @@
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.lang.reflect.Method;
import java.util.*;
import java.util.stream.Collectors;
import static com.vci.frameworkcore.constant.FrameWorkBusLangCodeConstant.DATA_OID_NOT_EXIST;
import static com.vci.constant.FrameWorkBusLangCodeConstant.DATA_OID_NOT_EXIST;
/**
 * UI上的数据查询
@@ -70,6 +70,11 @@
     */
    @Autowired
    private OsBtmServiceI btmService;
    /**
     * 属性服务
     */
    @Autowired
    private OsAttributeServiceI attrService;
    /**
     * 链接类型
@@ -131,10 +136,10 @@
     * @throws VciBaseException 查询出错的时候会抛出异常
     */
    @Override
    public DataGrid getDataForGrid(UIDataGridQuery dataGridQuery) throws VciBaseException {
    public DataGrid getDataForGrid(UIDataGridQuery dataGridQuery) throws VciBaseException, PLException {
        VciBaseUtil.alertNotNull(dataGridQuery,"查询对象",dataGridQuery.getBtmname(),"业务类型",dataGridQuery.getTableDefineId());
        //先判断查询模板
        UITableDefineVO tableDefineVO = uiEngineService.getComponentByOid(dataGridQuery.getComponentOid()).getTableDefineVO();
        UITableDefineVO tableDefineVO = uiEngineService.getComponentByOid(dataGridQuery.getComponentOid(),null).getTableDefineVO();
        String queryTemplate = !CollectionUtils.isEmpty(dataGridQuery.getSourceData())?dataGridQuery.getSourceData().getOrDefault("querytemplate",tableDefineVO.getQueryTemplateName()):tableDefineVO.getQueryTemplateName();
        if(StringUtils.isBlank(queryTemplate)){
            //说明没有设置查询模板,需要看看在这个表格所在的组件有没有设置
@@ -172,7 +177,8 @@
            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.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());
        }
@@ -193,8 +199,9 @@
            }
            return loService.queryGridByScheme(linkTypeDataQuery);
        }else {
            return boService.queryGridByScheme(queryTemplate,
            DataGrid dataGrid = boService.queryGridByScheme(queryTemplate,
                    dataGridQuery.getConditionMap(), replaceMap, dataGridQuery.getPageHelper(), queryFieldList.stream().collect(Collectors.toList()));
            return dataGrid;
        }
        //生命周期在其中查询后就会处理
        //枚举也会被处理了
@@ -208,7 +215,7 @@
     * @throws VciBaseException 查询出错的时候会抛出异常
     */
    @Override
    public UIFormDataVO getDataForForm(UIFormQuery formQuery) throws VciBaseException {
    public UIFormDataVO getDataForForm(UIFormQuery formQuery) throws VciBaseException, PLException {
        VciBaseUtil.alertNotNull(formQuery,"表单的查询对象",formQuery.getBtmname(),"业务类型的信息",formQuery.getOid(),"业务数据的主键",formQuery.getFormDefineId(),"表单的定义编号");
        UIFormDefineVO formDefineVO = uiEngineService.getFormById(formQuery.getBtmname(),formQuery.getFormDefineId());
        String queryTemplate = !CollectionUtils.isEmpty(formQuery.getSourceData())?formQuery.getSourceData().getOrDefault("querytemplate",formDefineVO.getQueryTemplateName()):formDefineVO.getQueryTemplateName();
@@ -238,7 +245,7 @@
            queryFieldList.addAll(linkTypeVO.getAttributes().stream().map(OsLinkTypeAttributeVO::getId).collect(Collectors.toList()));
            queryFieldList.addAll(WebLoServiceImpl.LO_BASE_FIELD_MAP.values());
        }else{
            btmTypeVO = btmService.getBtmById(formQuery.getBtmname());
            btmTypeVO = btmService.getBtmByName(formQuery.getBtmname());
            queryFieldList.addAll(btmTypeVO.getAttributes().stream().map(OsBtmTypeAttributeVO::getId).collect(Collectors.toList()));
        }
        queryFieldList.add("creator_name");
@@ -338,9 +345,10 @@
     * @throws VciBaseException 查询出错的时候会抛出异常
     */
    @Override
    public List<Tree> getDataForTree(UITreeQuery treeQuery) throws VciBaseException {
    public List<Tree> getDataForTree(UITreeQuery treeQuery) throws VciBaseException, PLException {
        VciBaseUtil.alertNotNull(treeQuery,"表单的查询对象",treeQuery.getBtmname(),"业务类型的信息",treeQuery.getComponentOid(),"树所在的组件的主键");
        UIComponentVO componentVO = uiEngineService.getComponentByOid(treeQuery.getComponentOid());
        Map<String, OsAttributeVO> attributeVOMap = attrService.selectAllAttributeMap();
        UIComponentVO componentVO = uiEngineService.getComponentByOid(treeQuery.getComponentOid(),attributeVOMap);
        if(componentVO == null || StringUtils.isBlank(componentVO.getOid())){
            throw new VciBaseException("树的配置信息没有获取到");
        }
@@ -383,7 +391,7 @@
        if(StringUtils.isBlank(treeDefineVO.getLinkType())){
            //这个是业务类型的自参照
            //以前的平台没有对自参照这种有全部查询的
            OsBtmTypeVO btmTypeVO = btmService.getBtmById(treeDefineVO.getBtmType());
            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());
@@ -532,6 +540,62 @@
                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 VciBaseException, PLException {
        VciBaseUtil.alertNotNull(treeQuery,"表单的查询对象",treeQuery.getComponentOid(),"当前组件的主键");
        //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、根据配置的查询模板查询数据(需要考虑全面一点),
        // 这儿根据当前类型来获取是什么类型的查询模板,然后做对应的查询处理
        UITreeDefineVO treeDefineVO = componentVO.getTreeDefineVO();
        String queryTemplate = StringUtils.isNotBlank(treeQuery.getQueryTemplate())?treeQuery.getQueryTemplate():(!CollectionUtils.isEmpty(treeQuery.getSourceData())?treeQuery.getSourceData().getOrDefault("querytemplate",treeDefineVO.getQueryTemplateName()):treeDefineVO.getQueryTemplateName());
        Map<String, String> replaceMap = wrapperReplaceMap(treeQuery.getSourceData());
        List<String> queryFieldList = new ArrayList<>();
        String valueField = treeQuery.isLinkTypeFlag()?(!treeDefineVO.isOrientation()?"${oid}" + TREE_NODE_ID_SEP + "${t_oid}":"${oid}" + TREE_NODE_ID_SEP + "${f_oid}"):(StringUtils.isNotBlank(treeQuery.getValueField())?treeQuery.getValueField():"oid");
        String textField = StringUtils.isNotBlank(treeDefineVO.getTreeNodeExpression())?treeDefineVO.getTreeNodeExpression():(StringUtils.isNotBlank(treeQuery.getTextField())?treeQuery.getTextField():"name");
        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<Tree> 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);
    }
    /**
@@ -763,7 +827,7 @@
     * @throws VciBaseException 配置或者是调用不成功的时候,会抛出异常
     */
    @Override
    public BaseResult callPreEvent(BaseModelDTOList baseModelDTOList,BaseLinkModelDTOList baseLinkModelDTOList, String preEvent, VciChangeDocumentTypeEnum businessType) throws VciBaseException{
    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();
        }
@@ -1049,7 +1113,7 @@
     * @throws VciBaseException 保存出错的时候会抛出异常
     */
    @Override
    public BaseResult<Map<String, Object>> addSave(FormDataDTO formDataDTO) throws VciBaseException {
    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());
@@ -1105,7 +1169,7 @@
     * @param newVersion 新版次
     * @return  执行的结果
     */
    private BaseResult<BusinessObject> wrapperCbo(FormDataDTO formDataDTO,UIFormDefineVO formDefineVO,boolean editFlag,boolean newRevision,boolean newVersion){
    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<>();
@@ -1133,7 +1197,7 @@
        Map<String,String> baseDataMap = formDataDTO2MapLow(formDataDTO);
        Map<String,String> allDataMapLow = new HashMap<>();
        allDataMapLow.putAll(dataLow);
//        allDataMapLow.putAll(baseDataMap);
        allDataMapLow.putAll(baseDataMap);
        //判断必输项
        BaseResult result = checkRequired(formDefineVO,null,allDataMapLow);
        if(!result.isSuccess()){
@@ -1243,7 +1307,7 @@
            if(baseModel.getRevisionValue() == null){
                baseModel.setRevisionValue("");
            }
            return  changeRevisionValueInfoToObject(platformClientUtil.getBOFactoryService().getNextRevisionValueObject(WebUtil.getTableName(btmTypeVO.getId()),baseModel.getNameOid(),btmTypeVO.getRevisionRuleId(),btmTypeVO.isInputRevisionFlag(),baseModel.getRevisionValue()));
            return  changeRevisionValueInfoToObject(platformClientUtil.getBOFactoryService().getNextRevisionValueObject(btmTypeVO.getId(),baseModel.getNameOid(),btmTypeVO.getRevisionRuleId(),btmTypeVO.isInputRevisionFlag(),baseModel.getRevisionValue()));
        } catch (PLException vciError) {
            throw WebUtil.getVciBaseException(vciError);
        }
@@ -1314,7 +1378,7 @@
     * @throws VciBaseException 保存出错的时候会抛出异常
     */
    @Override
    public BaseResult<String> batchAddSave(FormDataDTOList formDataDTOList) throws VciBaseException {
    public BaseResult<String> batchAddSave(FormDataDTOList formDataDTOList) throws VciBaseException, PLException {
        VciBaseUtil.alertNotNull(formDataDTOList,"要添加的数据",formDataDTOList.getFormDataDTOS(),"要添加的数据");
        //首先判断对象是否为空
        FormDataDTO firstFormDataDTO = formDataDTOList.getFormDataDTOS().stream().findFirst().get();
@@ -1365,7 +1429,7 @@
        }catch (Throwable e){
            //说明后置事件出现了错误,那么就需要删除以前的这条数据
            try {
                platformClientUtil.getBOFactoryService().batchDeleteBusinessObject(afterBOs.toArray(new BusinessObject[0]),1);
                platformClientUtil.getBOFactoryService().batchDeleteBusinessObject(afterBOs.toArray(new BusinessObject[0]),DeleteTypeEnum.OID_AND_TS.getValue());
            } catch (PLException vciError) {
                throw WebUtil.getVciBaseException(vciError);
            }
@@ -1384,7 +1448,7 @@
     * @throws VciBaseException 保存出错的时候会抛出异常
     */
    @Override
    public BaseResult<Map<String, Object>> editSave(FormDataDTO formDataDTO) throws VciBaseException {
    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());
@@ -1429,7 +1493,7 @@
     * @throws VciBaseException 保存出错的时候会抛出异常
     */
    @Override
    public BaseResult<Map<String, Object>> upRevision(FormDataDTO formDataDTO) throws VciBaseException {
    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());
@@ -1440,28 +1504,40 @@
            //说明前置事件没有执行成功
            return beforeResult;
        }
        //封装数据
        BaseResult<BusinessObject> resultCbo = wrapperCbo(formDataDTO,formDefineVO,false,formDataDTO.isUpVersion()?false:true,formDataDTO.isUpVersion());
        if(!resultCbo.isSuccess()){
            return BaseResult.fail(resultCbo.getMsg(),resultCbo.getMsgObjs());
        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();
        try {
            BusinessObject bo = platformClientUtil.getBOFService().createBusinessObject(resultCbo.getObj(),formDataDTO.isUpVersion()?false:true,formDataDTO.isUpVersion());
            BusinessObject afterCbo = new BusinessObject();
            afterCbo = bo;
            result.setObj(boService.cbo2Map(afterCbo));
        } catch (PLException vciError) {
            throw WebUtil.getVciBaseException(vciError);
        }
        if(!CollectionUtils.isEmpty(formDataDTO.getReleaseFileOids())){
            fileObjectService.releasedFile(resultCbo.getObj().btName,resultCbo.getObj().oid,formDataDTO.getReleaseFileOids());
        }
        BaseResult<Map<String, Object>> result = BaseResult.success();
        result.setObj(boService.cbo2Map(businessObject));
        //后置事件
        String afterEvent = formDataDTO.getPostEvent();
        try {
            callPostEvent(Arrays.stream(new BusinessObject[]{resultCbo.getObj()}).collect(Collectors.toList()), null,afterEvent, VciChangeDocumentTypeEnum.EDIT);
            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);
        }
@@ -1476,7 +1552,7 @@
     * @throws VciBaseException 保存出错的时候会抛出异常
     */
    @Override
    public BaseResult<String> batchEditSave(FormDataDTOList formDataDTOList) throws VciBaseException {
    public BaseResult<String> batchEditSave(FormDataDTOList formDataDTOList) throws VciBaseException, PLException {
        VciBaseUtil.alertNotNull(formDataDTOList,"要修改的数据",formDataDTOList.getFormDataDTOS(),"要修改的数据");
        //首先判断对象是否为空
        FormDataDTO firstFormDataDTO = formDataDTOList.getFormDataDTOS().stream().findFirst().get();
@@ -1533,7 +1609,7 @@
     * @throws VciBaseException 数据被引用的时候会抛出异常
     */
    @Override
    public BaseResult batchDelete(DeleteDataDTO deleteDataDTO) throws VciBaseException {
    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());
@@ -1541,7 +1617,7 @@
        List<BusinessObject> cbo = null;
        if(deleteDataDTO.isCascade()){
            //级联删除
            OsBtmTypeVO btmTypeVO = btmService.getBtmById(btmName);
            OsBtmTypeVO btmTypeVO = btmService.getBtmByName(btmName);
            OsBtmTypeAttributeVO parentAttributeVO = btmTypeVO.getAttributes().stream().filter(s -> s.getReferBtmTypeId().equalsIgnoreCase(btmName)).findFirst().orElseGet(null);
            if(parentAttributeVO != null){
                //页面分页不能显示超过1000
@@ -1574,7 +1650,12 @@
                        conditionMap.put(usedAttributeVO.getId(),QueryOptionConstant.IN + "(" + VciBaseUtil.toInSql(oids.toArray(new String[0])) + ")");
                        if(StringUtils.isNotBlank(usedAttributeVO.getPkBtmType())) {
                            if (boService.queryCount(usedAttributeVO.getPkBtmType(), conditionMap) > 0) {
                                OsBtmTypeVO btmTypeVO = btmService.getBtmById(usedAttributeVO.getPkBtmType());
                                OsBtmTypeVO btmTypeVO = null;
                                try {
                                    btmTypeVO = btmService.getBtmById(usedAttributeVO.getPkBtmType());
                                } catch (PLException e) {
                                    e.printStackTrace();
                                }
                                throw new VciBaseException("数据在【" + btmTypeVO.getName() + "】中的字段[" + usedAttributeVO.getName() + "]里被引用.不能删除");
                            }
                        }else{
@@ -1622,7 +1703,7 @@
     * @throws VciBaseException 参数为空,必输项缺失
     */
    @Override
    public BaseResult<String> linkAddSave(FormLinkDataDTO formLinkDataDTO) throws VciBaseException {
    public BaseResult<String> linkAddSave(FormLinkDataDTO formLinkDataDTO) throws VciBaseException, PLException {
        //首先判断对象是否为空
        VciBaseUtil.alertNotNull(formLinkDataDTO,"添加的数据对象",formLinkDataDTO.getLinkType(),"链接类型的名称",formLinkDataDTO.getFormDefineId(),"表单定义的编号");
        if(formLinkDataDTO.getData() ==null){
@@ -1673,13 +1754,6 @@
            throw new VciBaseException(formLinkDataDTO.isDirection()?"from端":"to端" + "的业务类型为空");
        }
        //查询from端的
        BusinessObject fromCbo = new BusinessObject();
        try {
            fromCbo = platformClientUtil.getBOFService().readBusinessObject(fromOid,fromBtmName);
        } catch (PLException vciError) {
            throw WebUtil.getVciBaseException(vciError);
        }
        String finalPrefix = prefix;
        formLinkDataDTO.getData().forEach((key, value)->{
            if(key.toLowerCase().startsWith(finalPrefix)){
@@ -1700,10 +1774,12 @@
            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);
        ObjectTool.dealLinkObjectNullValue(clo);
        bos[0] = toCbo;
        try {
            platformClientUtil.getBOFService().createBusinessObjectWithLink(bos,clo);
@@ -1758,7 +1834,6 @@
        if(editFlag){
            try {
                LinkObject linkObject = platformClientUtil.getBOFService().readLinkObjectById(formLinkDataDTO.getOid(), formLinkDataDTO.getLinkType());
                clo = new LinkObject();
                clo = linkObject;
            } catch (PLException vciError) {
                throw WebUtil.getVciBaseException(vciError);
@@ -1771,6 +1846,14 @@
            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;
@@ -1796,7 +1879,7 @@
     * @param boData to的数据
     * @return 包含的对象
     */
    private BaseResult<BusinessObject> wrapperToCbo(FormLinkDataDTO formLinkDataDTO,UIFormDefineVO formDefineVO,String toOid,String toBtmName,Map<String,String> boData){
    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);
@@ -1916,14 +1999,15 @@
     * @param newVersion 是否升版次
     * @return cbo对象
     */
    public BusinessObject createOrGetCbo(Map<String,String> dataLowMap,Map<String,String> baseDataMap,boolean editFlag,boolean newRevision,boolean newVersion){
    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);
        List<String> attributeList = btmTypeVO.getAttributes().stream().map(attribute -> attribute.getId()).collect(Collectors.toList());
        //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);
@@ -2019,6 +2103,7 @@
            if(StringUtils.isBlank(cbo.btName)){
                cbo.btName = btmTypeVO.getId();
            }
            if(btmTypeVO.isRevisionFlag()){
                //要管理版本
                if(btmTypeVO.isInputRevisionFlag() && StringUtils.isNotBlank(baseDataMap.getOrDefault("revisionvalue",""))){
@@ -2029,7 +2114,7 @@
                    if (ruleVO == null || StringUtils.isBlank(ruleVO.getOid())) {
                        throw new VciBaseException("{0}里的版本规则设置得不正确,在系统中没有找到{1}这个版本规则", new String[]{btmTypeVO.getName(), btmTypeVO.getRevisionRuleId()});
                    }
                    cbo.revisionValue = ruleVO.getStartCode();
                    cbo.revisionValue = ruleVO.getInitialValue();
                }
                if (StringUtils.isBlank(cbo.nameoid)) {
                    cbo.nameoid = VciBaseUtil.getPk();
@@ -2058,7 +2143,16 @@
//            }
//        }
        setValueToCbo(dataLowMap,baseDataMap,cbo,editFlag);
//        cbo.setName(dataLowMap.get("name"));
        //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;
    }
@@ -2122,7 +2216,7 @@
     * @throws VciBaseException 参数为空,必输项缺失
     */
    @Override
    public BaseResult linkEditSave(FormLinkDataDTO formLinkDataDTO) throws VciBaseException {
    public BaseResult linkEditSave(FormLinkDataDTO formLinkDataDTO) throws VciBaseException, PLException {
        VciBaseUtil.alertNotNull(formLinkDataDTO,"修改的数据对象",formLinkDataDTO.getLinkType(),"链接类型的名称",
                formLinkDataDTO.getFormDefineId(),"表单定义的编号",formLinkDataDTO.getOid(),"主键",
                formLinkDataDTO.getFoid(),"from端主键",formLinkDataDTO.getToid(),"to端主键");
@@ -2147,8 +2241,6 @@
        String prefix = formLinkDataDTO.isDirection()?LO_FROM_PREFIX:LO_TO_PREFIX;
        String toOid = formLinkDataDTO.isDirection()?formLinkDataDTO.getFoid():formLinkDataDTO.getToid();
        String toBtmName =  formLinkDataDTO.isDirection()?formLinkDataDTO.getFbtmname():formLinkDataDTO.getTbtmname();
        String fromOid = formLinkDataDTO.isDirection()?formLinkDataDTO.getToid():formLinkDataDTO.getFoid();
        String fromBtmName = formLinkDataDTO.isDirection()?formLinkDataDTO.getTbtmname():formLinkDataDTO.getFbtmname();
        Map<String,String> boData = new HashMap<>();
        Map<String,String> loData = new HashMap<>();
@@ -2285,7 +2377,7 @@
        if(deleteLinkDataDTO.isDeleteFromData()){
            fromBtmDataGroups.forEach((btm,cbos)->{
                try{
                    platformClientUtil.getBOFactoryService().batchDeleteBusinessObject(cbos.toArray(new BusinessObject[0]),1);
                    platformClientUtil.getBOFactoryService().batchDeleteBusinessObject(cbos.toArray(new BusinessObject[0]), DeleteTypeEnum.OID_AND_TS.getValue());
                }catch (PLException vciError) {
                    throw WebUtil.getVciBaseException(vciError);
                }
@@ -2294,7 +2386,7 @@
        if(deleteLinkDataDTO.isDeleteToData()){
            toBtmDataGroups.forEach((btm,cbos)->{
                try{
                    platformClientUtil.getBOFactoryService().batchDeleteBusinessObject(cbos.toArray(new BusinessObject[0]),1);
                    platformClientUtil.getBOFactoryService().batchDeleteBusinessObject(cbos.toArray(new BusinessObject[0]),DeleteTypeEnum.OID_AND_TS.getValue());
                }catch (PLException vciError) {
                    throw WebUtil.getVciBaseException(vciError);
                }
@@ -2311,10 +2403,10 @@
     * @return 列表数据
     */
    @Override
    public DataGrid referDataGrid(ReferConfigVO referConfigVO, PageHelper pageHelper) {
    public DataGrid referDataGrid(ReferConfigVO referConfigVO, PageHelper pageHelper) throws PLException {
        checkReferConfig(referConfigVO);
        //使用业务类型查询
        OsBtmTypeVO btmById = btmService.getBtmById(referConfigVO.getReferBo());
        OsBtmTypeVO btmById = btmService.getBtmByName(referConfigVO.getReferBo());
        if(referConfigVO.getConditionMap() == null){
            referConfigVO.setConditionMap(new HashMap<>());
        }
@@ -2454,4 +2546,73 @@
        }
        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.revisionid)){
                String revisionoid = Arrays.stream(cbo.hisAttrValList).filter(e -> e.attrName.equals("REVISIONOID")).findFirst().map(e -> e.attrVal).orElse("");
                cbo.revisionid = revisionoid;
            }
            boolean b = platformClientUtil.getBOFService().deleteBusinessObject(cbo,type);
            if(!b){
                throw new PLException("500", new String[]{"数据删除失败!!"});
            }
        }
        return BaseResult.success();
    }
    /**
     * 变更所有者
     * @param btmname 业务类型
     * @param oid 主键
     * @return 执行的结果
     */
    @Override
    public BaseResult changeBusinessObjectOwner(String btmname, String oid) throws PLException {
        List<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();
    }
}