xiejun
2024-09-04 ac3f3629a261770f573f27e5e23f7ec19d096c2a
Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsLinkTypeServiceImpl.java
@@ -4,6 +4,7 @@
import cn.hutool.core.util.ZipUtil;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.vci.common.qt.object.QTConstants;
import com.vci.constant.FrameWorkLangCodeConstant;
import com.vci.corba.common.PLException;
import com.vci.corba.omd.atm.AttributeDef;
@@ -12,6 +13,7 @@
import com.vci.corba.omd.ltm.LinkType;
import com.vci.corba.omd.ltm.LinkTypeServicePrx;
import com.vci.dto.OsAttributeDTO;
import com.vci.omd.constants.AttributeConstants;
import com.vci.omd.constants.LinkTypeConstants;
import com.vci.omd.utils.ObjectTool;
import com.vci.pagemodel.*;
@@ -23,6 +25,7 @@
import com.vci.starter.poi.constant.ExcelLangCodeConstant;
import com.vci.starter.poi.util.ExcelUtil;
import com.vci.starter.web.annotation.log.VciUnLog;
import com.vci.starter.web.enumpck.ResultCodeEnum;
import com.vci.starter.web.enumpck.VciFieldTypeEnum;
import com.vci.starter.web.exception.VciBaseException;
import com.vci.starter.web.pagemodel.BaseQueryObject;
@@ -46,7 +49,10 @@
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
@@ -314,7 +320,7 @@
                    }
                    OsBtmTypeAttributeVO attributeVO = attributeVOMap.getOrDefault(attrId.toLowerCase(Locale.ROOT), null);
                    if(attributeVO!=null){
                        String vtType = attributeVO.getAttrDataType();
                        String vtType = attributeVO.getAttributeDataType();
                        String attrType = "";
                        VciFieldTypeEnum fieldTypeEnum = VciFieldTypeEnum.forValue(vtType);
                        if(fieldTypeEnum == null) {
@@ -443,7 +449,9 @@
            returnData.put("btmCheckMap",btmCheckMap);
            List<Map> list = new ArrayList<>();
            list.add(returnData);
            return BaseResult.dataList(500,list,"需要进行列的修复!!");
            BaseResult<List<Map>> listBaseResult = BaseResult.dataList(200, list, "需要进行列的修复!!");
            listBaseResult.setSuccess(false);
            return listBaseResult;
        }
    }
@@ -559,7 +567,7 @@
            ExcelUtil.writeDataToFile(excelPath, excelOption);
            //导出属性
            String attrPath = attributeService.exportAttributes("attr",
                    String.valueOf(attributes.stream().collect(Collectors.joining(","))));
                    String.valueOf(attributes.stream().collect(Collectors.joining(","))),true);
            //移动属性到链接类型文件夹里面去
            FileUtil.move(new File(attrPath), new File(defaultTempFolder),true);
            FileUtil.del(attrPath.substring(0,attrPath.lastIndexOf("\\")));
@@ -604,7 +612,7 @@
                return BaseResult.fail(FrameWorkLangCodeConstant.IMPORT_FAIL, new String[]{"没有导入的属性文件。导入终止!"});
            }
        }
        BaseResult baseResult = attributeService.importAttributes(attrExcel);
        BaseResult baseResult = attributeService.importAttributes(attrExcel,true);
        if(!baseResult.isSuccess()){
            //删除上传的文件夹
            FileUtil.del(defaultTempFolder + File.separator);
@@ -641,7 +649,7 @@
                }else if(!osLinkTypePO.getName().matches("^[A-Za-z]+$")){
                    throw new VciBaseException("第【"+osLinkTypePO.getRowIndex()+"】行,链接类型名称只能为英文字母");
                }else if(excelReapeat.containsKey(osLinkTypePO.getName())){//属性名表格中判重
                    throw new VciBaseException("第【"+excelReapeat.get(osLinkTypePO.getName())+"】行和第【"+osLinkTypePO.getRowIndex()+"】行数据,属性名重复");
                    throw new VciBaseException("第【"+excelReapeat.get(osLinkTypePO.getName())+"】行和第【"+osLinkTypePO.getRowIndex()+"】行数据,链接类型名重复");
                }
                try {
                    LinkType historyLink = platformClientUtil.getLinkTypeService().getLinkType(osLinkTypePO.getName());
@@ -680,7 +688,7 @@
            });
        }catch (Exception e){
            if(logger.isErrorEnabled()){
                logger.error("读取excel内容时或保存用户信息时出现了错误,具体原因:",VciBaseUtil.getExceptionMessage(e));
                logger.error("读取excel内容时或保存链接类型信息时出现了错误,具体原因:",VciBaseUtil.getExceptionMessage(e));
            }
            e.printStackTrace();
            return BaseResult.fail(VciBaseUtil.getExceptionMessage(e),new String[]{},e);
@@ -688,6 +696,87 @@
        //删除上传的文件夹
        FileUtil.del(defaultTempFolder + File.separator);
        return BaseResult.success("链接类型导入成功!");
    }
    /**
     * 获取链接类型包含的属性
     * @param name 链接类型的编号
     * @return 属性的信息
     */
    @Override
    public List<OsLinkTypeAttributeVO> getAllAttributeByLink(String name) throws PLException, ParseException {
        AttributeDef[] attributes = platformClientUtil.getLinkTypeService().getAttributes(name);
        Map<String, AttributeDef> collect = Arrays.stream(platformClientUtil.getLinkTypeService().getSysAttributeDefs())
                .collect(Collectors.toMap(str -> str.name, str -> str));
        List<OsLinkTypeAttributeVO> links = new ArrayList<>();
        String[] sysAttibutes = { "OID", "Creator", "CreateTime", "LastModifier", "LASTMODIFYTIME", "F_OID",
                "F_REVISIONOID", "F_NAMEOID", "F_BtwName", "T_OID", "T_REVISIONOID", "T_NAMEOID", "T_BtwName", "TS" };
        for (String sysname : sysAttibutes) {
            AttributeDef sysAttributeDef = collect.get(sysname.toLowerCase());
            OsLinkTypeAttributeVO vo = new OsLinkTypeAttributeVO();
            vo.setOid(sysAttributeDef.oid);
            vo.setAttrDataType(sysAttributeDef.vtDataType);
            vo.setPkLinkType(name);
            vo.setCreateTime(new Date(sysAttributeDef.createTime));
            vo.setCreator(sysAttributeDef.creator);
            vo.setDefaultValue(sysAttributeDef.defValue);
            vo.setDescription(sysAttributeDef.description);
            vo.setRange(sysAttributeDef.rage);
            vo.setId(sysname);
            vo.setName(sysAttributeDef.label);
            vo.setLastModifier(sysAttributeDef.modifier);
            vo.setLastModifyTime(new Date(sysAttributeDef.modifyTime));
            links.add(vo);
        }
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        for (AttributeDef attribute : attributes) {
            OsLinkTypeAttributeVO vo = new OsLinkTypeAttributeVO();
            vo.setOid(attribute.oid);
            vo.setAttrDataType(attribute.vtDataType);
            vo.setPkLinkType(name);
            vo.setCreateTime(new Date(attribute.createTime));
            vo.setCreator(attribute.creator);
            vo.setDefaultValue(attribute.defValue);
            vo.setDescription(attribute.description);
            vo.setRange(attribute.rage);
            vo.setId(attribute.name);
            vo.setName(attribute.label);
            vo.setTs(formatter.parse(attribute.ts));
            vo.setLastModifier(attribute.modifier);
            vo.setOwner(attribute.creator);
            vo.setLastModifyTime(new Date(attribute.modifyTime));
            String maxLength = AttributeConstants.getOtherValueByType(attribute.other, AttributeConstants.LENGTH);
            if(StringUtils.isNotBlank(maxLength)){
                vo.setAttributeLength(Integer.valueOf(maxLength));
            }
            links.add(vo);
        }
        return links;
    }
    /**
     * 获取设置排序字段的排序字段
     * @param linkType 链接类型的编号
     * @param btmType 业务类型的编号
     * @param direction 正/反向
     * @return 属性的信息
     */
    @Override
    public List<String> getAllOrderbyAttributeByLink(String linkType, String btmType, String direction) throws PLException, ParseException {
        List<String> abNames = new ArrayList<>(Arrays.asList("OID", "Creator", "CreateTime", "LastModifier", "LASTMODIFYTIME", "F_OID",
                "F_REVISIONOID", "F_NAMEOID", "F_BtwName", "T_OID", "T_REVISIONOID", "T_NAMEOID", "T_BtwName", "TS" ));
        AttributeDef[] attributes = platformClientUtil.getLinkTypeService().getAttributes(linkType);
        for (AttributeDef attribute : attributes) {
            abNames.add(String.valueOf(attribute.name));
        }
        String wrapper = "T_OID.";
        if(direction.equals(QTConstants.DIRECTION_OPPOSITE)){
            wrapper = "F_OID.";
        }
        List<OsBtmTypeAttributeVO> bizTypeQTDs = btmService.getBizTypeQTDs(btmType);
        for (OsBtmTypeAttributeVO bizTypeQTD : bizTypeQTDs) {
            abNames.add(wrapper + bizTypeQTD.getId());
        }
        return abNames;
    }
    /**
@@ -925,4 +1014,49 @@
        return null;
    }
    /**
     * 获取使用该业务类型的链接类型名
     * @param btmName 业务类型名称
     * @return
     */
    @Override
    public List<String> getUsedBtmLinkList(String btmName) {
        try {
            List<String> list = new ArrayList<String>();
            LinkType[] linkTypes = platformClientUtil.getLinkTypeService().getLinkTypes();
            for(int i = 0; i < linkTypes.length; i++){
                LinkType linkType = linkTypes[i];
                if(this.containsBtm(linkType, btmName)){
                    list.add(linkType.name);
                }
            }
            return list;
        } catch (PLException e) {
            e.printStackTrace();
        }
        return null;
    }
    /**
     * 指定的链接类型是否使用了指定的业务类型
     * @param link
     * @param btmName
     * @return
     */
    private boolean containsBtm(LinkType link, String btmName){
        String[] btms = link.btmItemsFrom;
        for(int i = 0; i < btms.length; i++){
            if(btmName.equalsIgnoreCase(btms[i])){
                return true;
            }
        }
        btms = link.btmItemsTo;
        for(int i = 0; i < btms.length; i++){
            if(btmName.equalsIgnoreCase(btms[i])){
                return true;
            }
        }
        return false;
    }
}