Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/UIDataServiceImpl.java
@@ -1,13 +1,14 @@
package com.vci.web.service.impl;
import com.vci.client.common.providers.ClientServiceProvider;
import com.vci.corba.common.PLException;
import com.vci.corba.framework.data.UserInfo;
import com.vci.corba.omd.data.*;
import com.vci.corba.omd.lcm.LifeCycle;
import com.vci.file.pagemodel.VciFileObjectVO;
import com.vci.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;
@@ -20,10 +21,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;
@@ -34,13 +34,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上的数据查询
@@ -67,6 +69,11 @@
     */
    @Autowired
    private OsBtmServiceI btmService;
    /**
     * 属性服务
     */
    @Autowired
    private OsAttributeServiceI attrService;
    /**
     * 链接类型
@@ -128,10 +135,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)){
            //说明没有设置查询模板,需要看看在这个表格所在的组件有没有设置
@@ -337,7 +344,8 @@
    @Override
    public List<Tree> getDataForTree(UITreeQuery treeQuery) throws VciBaseException {
        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("树的配置信息没有获取到");
        }
@@ -380,7 +388,7 @@
        if(StringUtils.isBlank(treeDefineVO.getLinkType())){
            //这个是业务类型的自参照
            //以前的平台没有对自参照这种有全部查询的
            OsBtmTypeVO btmTypeVO = btmService.getBtmById(treeDefineVO.getBtmType());
            OsBtmTypeVO btmTypeVO = btmService.getBtmById(treeDefineVO.getBtmType(),attributeVOMap);
            queryFieldList.addAll(btmTypeVO.getAttributes().stream().map(OsBtmTypeAttributeVO::getId).collect(Collectors.toList()));
            queryFieldList.addAll(WebBoServiceImpl.BO_BASE_FIELD_MAP.values());
@@ -760,7 +768,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();
        }
@@ -1362,7 +1370,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);
            }
@@ -1682,13 +1690,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)){
@@ -1709,10 +1710,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);
@@ -1767,7 +1770,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);
@@ -1780,6 +1782,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;
@@ -2038,7 +2048,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();
@@ -2156,8 +2166,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<>();
@@ -2294,7 +2302,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);
                }
@@ -2303,7 +2311,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);
                }
@@ -2484,7 +2492,6 @@
                String revisionoid = Arrays.stream(cbo.hisAttrValList).filter(e -> e.attrName.equals("REVISIONOID")).findFirst().map(e -> e.attrVal).orElse("");
                cbo.revisionid = revisionoid;
            }
//            cbo.revisionid = hisAttrValList.
            boolean b = platformClientUtil.getBOFService().deleteBusinessObject(cbo,type);
            if(!b){
                throw new PLException("500", new String[]{"数据删除失败!!"});
@@ -2492,4 +2499,45 @@
        }
        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();
    }
}