yuxc
2024-07-24 66a397414a20aa592ce24ecd622024bc7744b7a0
Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsLinkTypeServiceImpl.java
@@ -1,16 +1,19 @@
package com.vci.web.service.impl;
import com.vci.corba.common.PLException;
import com.vci.corba.omd.data.BusinessObject;
import com.vci.corba.omd.ltm.LinkType;
import com.vci.omd.utils.ObjectTool;
import com.vci.pagemodel.*;
import com.vci.starter.web.annotation.log.VciUnLog;
import com.vci.starter.web.enumpck.VciFieldTypeEnum;
import com.vci.starter.web.pagemodel.BaseQueryObject;
import com.vci.starter.web.pagemodel.BaseResult;
import com.vci.starter.web.pagemodel.DataGrid;
import com.vci.starter.web.util.BeanUtil;
import com.vci.starter.web.util.VciBaseUtil;
import com.vci.starter.web.util.VciDateUtil;
import com.vci.web.model.OsLinkTypeDO;
import com.vci.web.pageModel.*;
import com.vci.model.OsLinkTypeDO;
import com.vci.web.service.*;
import com.vci.web.util.PlatformClientUtil;
import com.vci.web.util.WebUtil;
@@ -270,11 +273,11 @@
                    "inner JOIN user_col_comments c on t.TABLE_NAME  = c.table_name and t.COLUMN_NAME = c.column_name where " +
                    "t.table_name = '" + VciBaseUtil.getTableName(btmTypeVO.getId()).toUpperCase(Locale.ROOT) + "' order by t.column_name asc";
            Map<String, OsBtmTypeAttributeVO> attributeVOMap = btmTypeVO.getAttributes().stream().collect(Collectors.toMap(s -> s.getId().toLowerCase(Locale.ROOT), t -> t));
            List<com.vci.client.bof.ClientBusinessObject> cbosList = boService.queryBySql(sql, new HashMap<>());
            List<BusinessObject> cbosList = boService.queryBySql(sql, new HashMap<>());
            if(!CollectionUtils.isEmpty(cbosList)){
                cbosList.stream().forEach(cbo->{
                    String attrId = cbo.getAttributeValue("column_name");
                    String dataType = cbo.getAttributeValue("data_type");
                    String attrId = ObjectTool.getBOAttributeValue(cbo,"column_name");
                    String dataType = ObjectTool.getBOAttributeValue(cbo,"data_type");
                    if(StringUtils.isNotBlank(dataType) && dataType.contains("(")){
                        dataType = dataType.substring(0,dataType.indexOf("("));
                    }
@@ -319,6 +322,85 @@
    }
    /**
     * 链接类型的列表
     *
     * @return 链接类型的显示对象
     */
    @Override
    public BaseResult<List<LinkType>> gridLink() throws PLException {
        LinkType[] linkTypes = platformClientUtil.getLinkTypeService().getLinkTypes();
        return BaseResult.dataList(Arrays.asList(linkTypes));
    }
    /**
     * 链接类型保存
     * linkType 链接类型的保存对象
     * addFlag 是否为新增 true新增,false修改
     * @return 保存结果
     */
    @Override
    public BaseResult addAndEditLink(LinkType linkType, Boolean addFlag) throws PLException {
        VciBaseUtil.alertNotNull(linkType.name,"请输入链接类型名称",linkType.btmItemsFrom,"From端业务类型不能为空!",
                linkType.btmItemsTo,"To端类型均不能为空!");
        int maxLength = platformClientUtil.getLinkTypeService().getLTNameMaxLength();
        if(linkType.name.length() > maxLength){
            throw new PLException("500",new String[] {"链接类型名长度不能超过" + maxLength});
        }
        if(!linkType.name.matches("^[A-Za-z]+$")){
            throw new PLException("500",new String[] {"链接类型名称只能为英文字母"});
        }
        LinkType historyLink = platformClientUtil.getLinkTypeService().getLinkType(linkType.name);
        if(historyLink != null && !historyLink.name.equals("") && addFlag){
            throw new PLException("500",new String[] {"该链接类型名称已经存在"});
        }
        linkType.modifier = WebUtil.getCurrentUserId();
        if(addFlag){
            linkType.creator = WebUtil.getCurrentUserId();
            platformClientUtil.getLinkTypeService().addLinkType(linkType);
            return BaseResult.success(null,"保存成功!");
        }
        ArrayList<String> removeAbList = getRemovedApList(historyLink, linkType);
        if(removeAbList.size() > 0 && platformClientUtil.getLinkTypeService().hasData(linkType.name)){
            linkType.attributes = historyLink.attributes;
            platformClientUtil.getLinkTypeService().modifyLinkType(linkType);
            throw new PLException("500",new String[] {"类型已有实例, 不进行移除操作"});
        }
        platformClientUtil.getLinkTypeService().modifyLinkType(linkType);
        return BaseResult.success(null,"保存成功!");
    }
    /**
     * 获取修改链接类型时 减少的属性
     * @param oldLt
     * @param newLt
     * @return
     */
    private ArrayList<String> getRemovedApList(LinkType oldLt,
                                               LinkType newLt) {
        String[] oldAbInfo = oldLt.attributes;
        ArrayList<String> oldNameList = new ArrayList<String>();
        for(int i = 0; i < oldAbInfo.length; i++){
            oldNameList.add(oldAbInfo[i]);
        }
        String[] newAbInfo = newLt.attributes;
        ArrayList<String> newNameList = new ArrayList<String>();
        for(int i = 0; i < newAbInfo.length; i++){
            newNameList.add(newAbInfo[i]);
        }
        ArrayList<String> removedApList = new ArrayList<String>();
        for(Iterator<String> iterator = oldNameList.iterator(); iterator.hasNext();){
            String oldName = iterator.next();
            if(!newNameList.contains(oldName)){
                removedApList.add(oldName);
            }
        }
        return removedApList;
    }
    /**
     * 清除缓存
     */
    @Override