xiejun
2024-09-04 ac3f3629a261770f573f27e5e23f7ec19d096c2a
Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsBtmServiceImpl.java
@@ -38,6 +38,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.constant.QueryOptionConstant;
import com.vci.starter.web.enumpck.BooleanEnum;
import com.vci.starter.web.exception.VciBaseException;
import com.vci.starter.web.pagemodel.BaseResult;
@@ -202,7 +203,7 @@
                //vo.setCreateTime(VciDateUtil.str2Date(String.valueOf(btmItem.createTime),VciDateUtil.DateTimeFormat));
                vo.setCreateTime(Func.parse(btmItem.createTime, ConcurrentDateFormat.of(VciDateUtil.DateTimeFormat)));
                vo.setLastModifyTime( Func.parse(btmItem.modifyTime, ConcurrentDateFormat.of(VciDateUtil.DateTimeFormat)));
                vo.setTs(Func.parse(btmItem.ts, ConcurrentDateFormat.of(VciDateUtil.DateTimeFormat)));
                vo.setTs(Func.parse(btmItem.ts, ConcurrentDateFormat.of(VciDateUtil.DateTimeMillFormat)));
            } catch (Exception e) {
                e.printStackTrace();
            }
@@ -219,11 +220,11 @@
            vo.setInputRevisionFlag(btmItem.revInput);
            vo.setDelimiter(btmItem.delimiter);
            vo.setfName(btmItem.fName);
            if(StringUtils.isNotBlank(vo.getRevisionRuleId()) || vo.isInputRevisionFlag()){
            vo.setVersionRule(String.valueOf(btmItem.verRuleName));
            if(StringUtils.isNotBlank(vo.getRevisionRuleName()) || vo.isInputRevisionFlag()){
                vo.setRevisionFlag(true);
            }
            vo.setVersionRule(String.valueOf(btmItem.verRuleName));
            vo.setSubLifeCycleId(Arrays.stream(btmItem.lifeCycles).collect(Collectors.joining(",")));
            vo.setLifeCycleIds(Arrays.stream(btmItem.lifeCycles).collect(Collectors.joining(",")));
            vo.setApNameArray(btmItem.apNameArray);
            List<OsAttributeVO> attributeVOS = attributeService.listAttrByIds(Arrays.stream(btmItem.apNameArray).collect(Collectors.toList()));
            List<OsBtmTypeAttributeVO> btmTypeAttributeVOS = new ArrayList<>();
@@ -232,7 +233,7 @@
                BeanUtil.convert(attributeVO,btmTypeAttributeVO);
                btmTypeAttributeVO.setPkBtmType(vo.getOid());
                btmTypeAttributeVO.setBtmTypeId(vo.getId());
                btmTypeAttributeVO.setAttrDataType(attributeVO.getAttributeDataType());
                btmTypeAttributeVO.setAttributeDataType(attributeVO.getAttributeDataType());
                btmTypeAttributeVO.setAttributeLength(attributeVO.getAttrLength());
                btmTypeAttributeVO.setDefaultValue(attributeVO.getDefaultValue());
                if("secretgrade".equalsIgnoreCase(attributeVO.getId())){
@@ -358,9 +359,14 @@
     * @return 属性的内容
     */
    @Override
    public List<OsBtmTypeAttributeVO> listAttributeByBtmId(String btmId) {
    public List<OsBtmTypeAttributeVO> listAttributeByBtmId(String btmId) throws PLException {
        VciBaseUtil.alertNotNull(btmId,"业务类型的编号");
        OsBtmTypeVO btmTypeVO = getBtmById(btmId);
        BizType[] bizTypes = platformClientUtil.getBtmService().getBizTypes(btmId);
        if(Func.isEmpty(bizTypes)){
            return new ArrayList<>();
        }
        BizType bizType = bizTypes[0];
        OsBtmTypeVO btmTypeVO = btmDO2VO(bizType);
        List<OsBtmTypeAttributeVO> attributes = btmTypeVO.getAttributes();
        if(attributes == null){
            attributes = new ArrayList<>();
@@ -375,7 +381,7 @@
     * @return 属性的内容
     */
    @Override
    public List<OsBtmTypeAttributeVO> listAttributeByBtmIdHasDefault(String btmId) {
    public List<OsBtmTypeAttributeVO> listAttributeByBtmIdHasDefault(String btmId) throws PLException {
        List<OsBtmTypeAttributeVO> attrVOs = listAttributeByBtmId(btmId);
        if(attrVOs == null){
            attrVOs = new ArrayList<>();
@@ -385,7 +391,7 @@
            attributeService.getDefaultAttributeVOs().stream().forEach(attr->{
                OsBtmTypeAttributeVO attributeVO = new OsBtmTypeAttributeVO();
                BeanUtil.convert(attr, attributeVO);
                attributeVO.setAttrDataType(attr.getAttributeDataType());
                attributeVO.setAttributeDataType(attr.getAttributeDataType());
                attributeVO.setAttributeLength(attr.getAttrLength());
                attributeVO.setReferBtmTypeId(attr.getBtmTypeId());
                attributeVO.setReferBtmTypeName(attr.getBtmTypeName());
@@ -484,6 +490,42 @@
            btmName = "";
        }
        return platformClientUtil.getBtmService().getBizTypes(btmName);
    }
    /**
     * 业务类型列表查询,非树结构:用于UI定义左侧业务类型查询,只返回name和lable
     * @param btmName
     * @return
     * @throws PLException
     */
    @Override
    public Tree getBizTree(String btmName) throws PLException {
        if(null == btmName){
            btmName = "";
        }
        Tree returnTree = new Tree();
        BizType[] bizTypes = platformClientUtil.getBtmService().getBizTypes(btmName);
        if(Func.isEmpty(bizTypes)){
            return returnTree;
        }
        returnTree.setOid("");
        returnTree.setText("业务类型");
        returnTree.setLeaf(false);
        List<Tree> trees = new ArrayList<>();
        Arrays.stream(bizTypes).forEach(bizType -> {
            Tree tree = new Tree();
            tree.setText(bizType.name + " " +bizType.label);
            tree.setOid(bizType.oid);
            tree.setLeaf(true);
            tree.setParentName(bizType.fName);
            Map<String, String> atrrMap = new HashMap<>();
            atrrMap.put("name",bizType.name);
            atrrMap.put("lable",bizType.label);
            tree.setAttributes(atrrMap);
            trees.add(tree);
        });
        returnTree.setChildren(trees);
        return returnTree;
    }
    /**
@@ -648,7 +690,7 @@
            AttributeDef sysAttributeDef = collect.get(attrName.toLowerCase());
            OsBtmTypeAttributeVO vo = new OsBtmTypeAttributeVO();
            vo.setOid(sysAttributeDef.oid);
            vo.setAttrDataType(sysAttributeDef.vtDataType);
            vo.setAttributeDataType(sysAttributeDef.vtDataType);
            vo.setPkBtmType(btmName);
            vo.setCreateTime(new Date(sysAttributeDef.createTime));
            vo.setCreator(sysAttributeDef.creator);
@@ -667,7 +709,7 @@
        for (AttributeDef attribute : attributeDefs) {
            OsBtmTypeAttributeVO vo = new OsBtmTypeAttributeVO();
            vo.setOid(attribute.oid);
            vo.setAttrDataType(attribute.vtDataType);
            vo.setAttributeDataType(attribute.vtDataType);
            vo.setPkBtmType(btmName);
            vo.setCreateTime(new Date(attribute.createTime));
            vo.setCreator(attribute.creator);
@@ -695,6 +737,7 @@
     */
    private BizType dto2BizType(OsBtmTypeDTO dto){
        BizType bizType = new BizType();
        bizType.oid = dto.getOid();
        bizType.name =dto.getId();
        bizType.isAbstract = dto.isAbstractFlag();
        bizType.label = dto.getName();
@@ -710,24 +753,24 @@
        }
        bizType.description = dto.getDescription();
        bizType.revLevel = dto.getRevLevel();
        bizType.revRuleName = dto.getRevisionRuleName();
        bizType.revRuleName = dto.getRevisionRuleId();
        bizType.revInput = dto.isInputRevisionFlag();
        bizType.delimiter = (dto.getDelimiter() == null ? "" : dto.getDelimiter());
        bizType.verRuleName = Short.parseShort(dto.getRevisionRuleName());
        bizType.verRuleName = Func.isBlank(dto.getVersionRule()) ? 0:Short.parseShort(dto.getVersionRule());
        //bizType.imageName = dto.get;
        //List<String> attrIdList = dto.getAttributesDTOList().stream().map(OsBtmTypeLinkAttributesDTO::getId).collect(Collectors.toList());
        bizType.apNameArray = dto.getApNameArray();//attrIdList.toArray(new String[attrIdList.size()]);
        bizType.apNameArray = dto.getApNameArray().split(",");//attrIdList.toArray(new String[attrIdList.size()]);
        String userId = WebThreadLocalUtil.getCurrentUserSessionInfoInThread().getUserId();
        long timeMillis = System.currentTimeMillis();
        bizType.creator = Func.isBlank(dto.getCreator()) ? userId:dto.getCreator();
        bizType.createTime = Func.isEmpty(dto.getCreateTime()) ? timeMillis:dto.getCreateTime().getTime();
        bizType.modifier = userId;
        bizType.modifyTime = timeMillis;
        bizType.ts = Func.isEmpty(dto.getTs())? timeMillis:dto.getTs().getTime();
        return bizType;
    }
@@ -811,9 +854,11 @@
     * @return
     */
    private void checkVersionInfo(OsBtmTypeDTO dto) throws PLException {
        //需要手动输入版本时revisionRuleName不能为空
        if (dto.isInputRevisionFlag() && Func.isBlank(dto.getRevisionRuleName())) {
            throw new PLException("500",new String[]{"版本号规则不能为空"});
        //需要手动输入版本时revisionRuleId不能为空
        if (dto.getRevLevel() == 1 || dto.getRevLevel() == 2) {
            if (Func.isBlank(dto.getRevisionRuleId()) && !dto.isInputRevisionFlag()) {
                throw new PLException("500",new String[]{"版本号规则不能为空"});
            }
        }
    }
@@ -854,14 +899,14 @@
        checkRevLevel(dbBizType,btmTypeDTO);
        checkVersionInfo(btmTypeDTO);
        //处理业务类型下的属性
        List<String> lastAttrList = new ArrayList<>(Arrays.asList(btmTypeDTO.getApNameArray()));
        List<String> lastAttrList = new ArrayList<>(Arrays.asList(btmTypeDTO.getApNameArray().split(",")));
        //不能移除的属性
        String[] unRemovableFields = null;
        List<String> unRemovableFields_ = null;
        //需要移除的属性
        List<String> removableFields = null;
        //修改前业务类型在数据库中已存在的所有属性
        String[] apNameArray = btmTypeDTO.getApNameArray();
        String[] apNameArray = btmTypeDTO.getApNameArray().split(",");
        Set<String> dbApNameArray = Arrays.stream(dbBizType.apNameArray)
                .collect(Collectors.toSet());
        //过滤出需要移除的属性
@@ -1213,13 +1258,15 @@
    public boolean addIndex(List<IndexObject> indexObjectList) throws PLException {
        VciBaseUtil.alertNotNull(indexObjectList,"新增的索引信息");
        String btmName = indexObjectList.get(0).getTypeName();
        String indexNames = indexObjectList.stream().map(IndexObject::getIndexName).collect(Collectors.joining());
        String indexNames = indexObjectList.stream().map(IndexObject::getIndexName).collect(Collectors.joining(","));
        String[] oldindexAttr = {indexNames};
        BusinessObject bo;
        List<BusinessObject> boList = new ArrayList<>();
        //先查询当前添加索引是否已经存在,如果存在就先删除再新增实现替换操作
        Map<String, String> conditionMap = new HashMap<>();
        conditionMap.put("typename",btmName);
        //先这样处理,前端现在只做了单次保存,所以不用in
        conditionMap.put("indexname", indexNames);
        List<IndexObject> indexObjects = getIndexByCondition(conditionMap);
        if(indexObjects!=null && indexObjects.size()>0){
            //索引不存在时删除就会报错索引不存在,所以这里有索引才去删除
@@ -1261,7 +1308,7 @@
    /**
     * 导出业务类型
     * name 业务类型名称
     * oid 业务类型名称
     * @return 创建结果
     */
    @Override
@@ -1308,8 +1355,8 @@
            String attrPath = attributeService.exportAttributes("btmattr",
                    attributes.stream().collect(Collectors.joining(",")),true);
            //移动属性到链接类型文件夹里面去
            cn.hutool.core.io.FileUtil.move(new File(attrPath), new File(defaultTempFolder),true);
            cn.hutool.core.io.FileUtil.del(attrPath.substring(0,attrPath.lastIndexOf("\\")));
            FileUtil.move(new File(attrPath), new File(defaultTempFolder),true);
            FileUtil.del(attrPath.substring(0,attrPath.lastIndexOf("\\")));
        }catch (IOException e) {
            throw new RuntimeException(e);
        }
@@ -1479,7 +1526,7 @@
            if(StringUtils.isBlank(bizType.getfName())){
                continue;
            }
            if(bizType.getfName().equals(parentBIzType.getName())){
            if(bizType.getfName().equals(parentBIzType.getId())){
                Tree tree = new Tree();
                tree.setOid(bizType.getOid());
                tree.setParentName(parentBIzType.getfName());