| | |
| | | package com.vci.web.service.impl; |
| | | |
| | | import cn.hutool.core.io.FileUtil; |
| | | import cn.hutool.core.util.ZipUtil; |
| | | import com.fasterxml.jackson.core.type.TypeReference; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import com.vci.client.common.oq.OQTool; |
| | | import com.vci.client.common.providers.ClientServiceProvider; |
| | | import com.vci.client.mw.ClientSessionUtility; |
| | | import com.vci.common.qt.object.Condition; |
| | | import com.vci.common.qt.object.QueryTemplate; |
| | | import com.vci.common.utility.ObjectUtility; |
| | | import com.vci.constant.FrameWorkLangCodeConstant; |
| | | import com.vci.corba.common.PLException; |
| | | import com.vci.corba.omd.atm.AttributeDef; |
| | | import com.vci.corba.omd.btm.BizType; |
| | | import com.vci.corba.omd.data.AttributeValue; |
| | | import com.vci.corba.omd.data.BusinessObject; |
| | | import com.vci.corba.omd.etm.EnumType; |
| | | import com.vci.corba.omd.lcm.Bound; |
| | | import com.vci.corba.omd.lcm.LifeCycle; |
| | |
| | | import com.vci.corba.omd.vrm.VersionRule; |
| | | import com.vci.dto.OsBtmTypeDTO; |
| | | import com.vci.dto.OsBtmTypeLinkAttributesDTO; |
| | | import com.vci.model.IndexObject; |
| | | import com.vci.omd.constants.AttributeConstants; |
| | | import com.vci.omd.constants.FileObjectType; |
| | | import com.vci.omd.objects.OtherInfo; |
| | | import com.vci.omd.utils.ObjectTool; |
| | | import com.vci.pagemodel.*; |
| | | import com.vci.po.OsBtmTypePO; |
| | | import com.vci.po.OsLinkTypePO; |
| | | import com.vci.starter.poi.bo.ReadExcelOption; |
| | | import com.vci.starter.poi.bo.WriteExcelData; |
| | | import com.vci.starter.poi.bo.WriteExcelOption; |
| | | 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; |
| | | import com.vci.starter.web.pagemodel.DataGrid; |
| | | import com.vci.starter.web.pagemodel.PageHelper; |
| | | import com.vci.starter.web.pagemodel.Tree; |
| | | import com.vci.starter.web.util.*; |
| | | import com.vci.starter.web.util.BeanUtil; |
| | | import com.vci.starter.web.util.VciBaseUtil; |
| | | import com.vci.starter.web.util.VciDateUtil; |
| | | import com.vci.starter.web.util.WebThreadLocalUtil; |
| | | import com.vci.web.service.*; |
| | | import com.vci.web.util.ConcurrentDateFormat; |
| | | import com.vci.web.util.Func; |
| | | import com.vci.web.util.PlatformClientUtil; |
| | | import com.vci.web.util.WebUtil; |
| | | import com.vci.web.util.*; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import javax.swing.*; |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | |
| | | //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(); |
| | | } |
| | | vo.setDescription(btmItem.description); |
| | | vo.setId(btmItem.name); |
| | | vo.setName(btmItem.label); |
| | | vo.setName(btmItem.label); |
| | | vo.setLifeCycleId(btmItem.lifeCycle); |
| | | vo.setAbstractFlag(btmItem.isAbstract); |
| | | vo.setImplClass(btmItem.implClass); |
| | |
| | | vo.setTableName(VciBaseUtil.getTableName(vo.getId())); |
| | | vo.setInputRevisionFlag(btmItem.revInput); |
| | | vo.setDelimiter(btmItem.delimiter); |
| | | if(StringUtils.isNotBlank(vo.getRevisionRuleId()) || vo.isInputRevisionFlag()){ |
| | | vo.setfName(btmItem.fName); |
| | | 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<>(); |
| | | Optional.ofNullable(attributeVOS).orElseGet(()->new ArrayList<>()).stream().forEach(attributeVO->{ |
| | |
| | | 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())){ |
| | |
| | | * @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<>(); |
| | |
| | | * @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<>(); |
| | |
| | | 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()); |
| | |
| | | public List<Tree> getTreeBizTypes() throws PLException { |
| | | List<Tree> rootTreeList = new ArrayList<>(); |
| | | BizType[] bizTypes = getBizTypes(""); |
| | | BizType btItem = null; |
| | | for(int i = 0; i < bizTypes.length; i++){ |
| | | btItem = bizTypes[i]; |
| | | if(btItem.fName.equals("")){ |
| | | OsBtmTypeVO osBtmTypeVO = null; |
| | | List<OsBtmTypeVO> osBtmTypeVOS = btmDO2VOs(Arrays.asList(bizTypes)); |
| | | for(int i = 0; i < osBtmTypeVOS.size(); i++){ |
| | | osBtmTypeVO = osBtmTypeVOS.get(i); |
| | | |
| | | if(osBtmTypeVO.getfName().equals("")){ |
| | | Tree tree = new Tree(); |
| | | tree.setOid(btItem.oid); |
| | | tree.setOid(osBtmTypeVO.getOid()); |
| | | tree.setParentName(null); |
| | | tree.setParentId(null); |
| | | tree.setLeaf(true); |
| | | tree.setText(btItem.description); |
| | | tree.setAttributes(WebUtil.objectToMapString(btItem)); |
| | | tree.setChildren(getChildren(bizTypes,btItem)); |
| | | tree.setText(osBtmTypeVO.getDescription()); |
| | | tree.setAttributes(WebUtil.objectToMapString(osBtmTypeVO)); |
| | | tree.setChildren(getChildren(osBtmTypeVOS,osBtmTypeVO)); |
| | | rootTreeList.add(tree); |
| | | } |
| | | } |
| | |
| | | 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); |
| | |
| | | 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); |
| | |
| | | */ |
| | | 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(); |
| | |
| | | } |
| | | 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; |
| | | } |
| | | |
| | |
| | | * @param bizTypes |
| | | * @return |
| | | */ |
| | | @Override |
| | | /* @Override |
| | | public boolean addBtmTypes(List<BizType> bizTypes) { |
| | | VciBaseUtil.alertNotNull(bizTypes,"创建的业务类型对象列表"); |
| | | bizTypes.stream().forEach(bizType->{ |
| | |
| | | throw new VciBaseException(exceptionMessage); |
| | | } |
| | | }); |
| | | |
| | | return true; |
| | | } |
| | | }*/ |
| | | |
| | | /** |
| | | * 检查业务类型名称是否合规 |
| | |
| | | * @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[]{"版本号规则不能为空"}); |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | if (dbBizType.revLevel == 1 && dto.getRevLevel()==0) { |
| | | throw new PLException("500",new String[]{"版本变更错误:不能从一级变为不可修订"}); |
| | | } |
| | | |
| | | if (dbBizType.revLevel == 2 && (dto.getRevLevel() == 1 || dto.getRevLevel() == 0)) { |
| | | throw new PLException("500",new String[]{"版本变更错误:不能从二级变为一级或不可修订"}); |
| | | } |
| | |
| | | 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()); |
| | | //过滤出需要移除的属性 |
| | |
| | | } |
| | | |
| | | /** |
| | | * 根据业务类型名称和其下的属性名称获取也有的索引 |
| | | * @param btmName |
| | | * @param attrName |
| | | * 根据业务类型名称和其下的属性名称获取已有的索引 |
| | | * @param conditionMap 根据查询条件传参: typename:业务类型名; |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<String> getIndexByBtmAndAttrName(String btmName, String attrName) { |
| | | return null; |
| | | public List<IndexObject> getIndexByCondition(Map<String,String> conditionMap) throws PLException { |
| | | if(Func.isEmpty(conditionMap)){ |
| | | return new ArrayList<>(); |
| | | } |
| | | List<String> indexNameList = new ArrayList<String>(); |
| | | QueryTemplate qtl = new QueryTemplate(); |
| | | List<String> list = new ArrayList<String>(); |
| | | list.add("*"); |
| | | qtl.setBtmType("indexobject"); |
| | | qtl.setClauseList(list); |
| | | qtl.setId("p"); |
| | | qtl.setType("btm"); |
| | | qtl.setRightFlag(false); |
| | | Condition condition = OQTool.getCondition(conditionMap); |
| | | qtl.setCondition(condition); |
| | | //HashMap<String, String> indexmap = new HashMap<String, String>(); |
| | | BusinessObject findBTMObjects[] = platformClientUtil.getQueryService().findBTMObjects(qtl.getId(), OQTool.qtTOXMl(qtl).asXML()); |
| | | List<IndexObject> indexObjects = new ArrayList<>(); |
| | | for(int i = 0; i < findBTMObjects.length; i++) { |
| | | BusinessObject findBTMObject = findBTMObjects[i]; |
| | | IndexObject indexObject = new IndexObject(); |
| | | indexObject.setOid(findBTMObject.oid); |
| | | indexObject.setDescription(findBTMObject.description); |
| | | indexObject.setCreateTime(Func.format(new Date(findBTMObject.createTime),DateUtil.PATTERN_DATE)); |
| | | indexObject.setIndexName(ObjectTool.getBOAttributeValue(findBTMObject,"indexname")); |
| | | indexObject.setTypeName(ObjectTool.getBOAttributeValue(findBTMObject,"typename")); |
| | | indexObject.setAttrNames(ObjectTool.getBOAttributeValue(findBTMObject,"attrname")); |
| | | indexObjects.add(indexObject); |
| | | } |
| | | return indexObjects; |
| | | } |
| | | |
| | | /** |
| | | * 根据业务类型名称和其下的属性名称删除索引 |
| | | * @param btmName |
| | | * @param attrName |
| | | * @param indexName |
| | | * @return |
| | | */ |
| | | @Override |
| | | public boolean delIndexByBtmAndAttrName(String btmName, String attrName) { |
| | | return false; |
| | | public boolean delIndex(String btmName, String indexName) throws PLException { |
| | | VciBaseUtil.alertNotNull(btmName,"业务类型名",indexName,"索引名"); |
| | | Map<String, String> conditionMap = new HashMap<>(); |
| | | conditionMap.put("typename",btmName); |
| | | conditionMap.put("indexname",indexName); |
| | | List<IndexObject> bo2 = getIndexByCondition(conditionMap); |
| | | if(bo2!=null && bo2.size()>0) { |
| | | String[] indexAttr = {indexName}; |
| | | |
| | | boolean alterFlag = platformClientUtil.getBtmService().dropIndex(btmName, indexAttr); |
| | | |
| | | if (!alterFlag) { |
| | | return false; |
| | | } |
| | | for (int i = 0; i < bo2.size(); i++) { |
| | | String oid = bo2.get(i).getOid(); |
| | | BusinessObject bo = platformClientUtil.getBOFactoryService().readBusinessObject(oid, "indexobject"); |
| | | platformClientUtil.getBOFactoryService().deleteBusinessObject(bo,1); |
| | | } |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * 给业务类型下的指定属性新增索引 |
| | | * @param addMap 如:(btmName:part attrName:name indexName: PARTNAMEINDEX) |
| | | * @param indexObjectList |
| | | * @return |
| | | */ |
| | | @Override |
| | | public boolean addIndex(Map<String, String> addMap) { |
| | | return false; |
| | | 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[] 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){ |
| | | //索引不存在时删除就会报错索引不存在,所以这里有索引才去删除 |
| | | boolean b = platformClientUtil.getBtmService().dropIndex(btmName, oldindexAttr); |
| | | if(b){ |
| | | for(int i = 0; i < indexObjects.size(); i ++){ |
| | | String oid = (String) indexObjects.get(i).getOid(); |
| | | bo = platformClientUtil.getBOFactoryService().readBusinessObject(oid,"indexobject"); |
| | | platformClientUtil.getBOFactoryService().deleteBusinessObject(bo,1); |
| | | } |
| | | } |
| | | } |
| | | |
| | | for(int i = 0; i < indexObjectList.size(); i ++){ |
| | | IndexObject indexObject = indexObjectList.get(i); |
| | | //bo = platformClientUtil.getBOFService().initBusinessObject("indexobject"); |
| | | bo = boService.createCBOByBtmName("indexobject"); |
| | | List<AttributeValue> attributeValues = new ArrayList<>(); |
| | | attributeValues.add(new AttributeValue("typename", btmName)); |
| | | attributeValues.add(new AttributeValue("indexname", indexObject.getIndexName())); |
| | | attributeValues.add(new AttributeValue("attrname", indexObject.getAttrNames())); |
| | | bo.newAttrValList = attributeValues.toArray(new AttributeValue[attributeValues.size()]); |
| | | bo.description = indexObject.getDescription(); |
| | | String[] indexAttr = {indexObject.getIndexName(),indexObject.getAttrNames()}; |
| | | //给指定业务类型的指定属性创建索引 |
| | | boolean alterFlag = platformClientUtil.getBtmService().addIndex(btmName, indexAttr); |
| | | //索引创建成功之后,需要存储成功索引到索引表中 |
| | | if(!alterFlag){ |
| | | return false; |
| | | } |
| | | boList.add(bo); |
| | | //添加索引信息到索引的业务表中 |
| | | //platformClientUtil.getBOFactoryService().createBusinessObject(bo,false,false); |
| | | } |
| | | //添加索引信息到索引的业务表中 |
| | | platformClientUtil.getBOFactoryService().batchCreateBusinessObject(boList.toArray(new BusinessObject[boList.size()]),false,false); |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * 导出业务类型 |
| | | * oid 业务类型名称 |
| | | * @return 创建结果 |
| | | */ |
| | | @Override |
| | | public void expData(String names, HttpServletResponse response) throws PLException, IOException { |
| | | String defaultTempFolder = LocalFileUtil.getDefaultTempFolder(); |
| | | //写excel |
| | | String excelPath = defaultTempFolder + File.separator + "btm.xls"; |
| | | //设置列名 |
| | | List<String> columns = new ArrayList<>( |
| | | Arrays.asList("类型名称", "标签", "继承自", "实现类", "描述", "版本规则", "版本号规则", |
| | | "是否手工输入","分隔符", "版次号规则","生命周期", "备选生命周期列表","属性列表") |
| | | ); |
| | | try { |
| | | new File(excelPath).createNewFile(); |
| | | //设置列 |
| | | List<WriteExcelData> excelDataList = new ArrayList<>(); |
| | | //设置列头 |
| | | for (int index = 0; index < columns.size(); index++) { |
| | | excelDataList.add(new WriteExcelData(0,index, columns.get(index))); |
| | | } |
| | | HashSet<String> attributes = new HashSet<>(); |
| | | int i = 0; |
| | | for (String name : names.split(",")) { |
| | | BizType bizType = platformClientUtil.getBtmService().getBizTypeByName(name); |
| | | excelDataList.add(new WriteExcelData(i+1,0, bizType.name)); |
| | | excelDataList.add(new WriteExcelData(i+1,1, bizType.label)); |
| | | excelDataList.add(new WriteExcelData(i+1,2, bizType.fName)); |
| | | excelDataList.add(new WriteExcelData(i+1,3, bizType.implClass)); |
| | | excelDataList.add(new WriteExcelData(i+1,4, bizType.description)); |
| | | excelDataList.add(new WriteExcelData(i+1,5, bizType.revLevel)); |
| | | excelDataList.add(new WriteExcelData(i+1,6, bizType.revRuleName)); |
| | | excelDataList.add(new WriteExcelData(i+1,7, bizType.revInput)); |
| | | excelDataList.add(new WriteExcelData(i+1,8, bizType.delimiter)); |
| | | excelDataList.add(new WriteExcelData(i+1,9, bizType.verRuleName)); |
| | | excelDataList.add(new WriteExcelData(i+1,10, bizType.lifeCycle)); |
| | | excelDataList.add(new WriteExcelData(i+1,11, String.join(",",bizType.lifeCycles))); |
| | | excelDataList.add(new WriteExcelData(i+1,12, String.join(",",bizType.apNameArray))); |
| | | attributes.addAll(Arrays.asList(bizType.apNameArray)); |
| | | i++; |
| | | } |
| | | WriteExcelOption excelOption = new WriteExcelOption(excelDataList); |
| | | ExcelUtil.writeDataToFile(excelPath, excelOption); |
| | | //导出属性 |
| | | String attrPath = attributeService.exportAttributes("btmattr", |
| | | attributes.stream().collect(Collectors.joining(",")),true); |
| | | //移动属性到链接类型文件夹里面去 |
| | | FileUtil.move(new File(attrPath), new File(defaultTempFolder),true); |
| | | FileUtil.del(attrPath.substring(0,attrPath.lastIndexOf("\\"))); |
| | | }catch (IOException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | File zip = ZipUtil.zip(defaultTempFolder); |
| | | FileUtil.del(defaultTempFolder + File.separator); |
| | | ControllerUtil.writeFileToResponse(response,zip.getAbsoluteFile()); |
| | | } |
| | | |
| | | /** |
| | | * 导入业务类型 |
| | | * @param file 上传的文件 |
| | | * @return |
| | | */ |
| | | @Override |
| | | public BaseResult impData(MultipartFile file) throws Exception { |
| | | String defaultTempFolder = LocalFileUtil.getDefaultTempFolder(); |
| | | String fileName = defaultTempFolder + File.separator + LocalFileUtil.getFileNameForIE(file.getOriginalFilename()); |
| | | file.transferTo(new File(fileName)); |
| | | if (file == null) { |
| | | return BaseResult.fail(FrameWorkLangCodeConstant.IMPORT_FAIL, new String[]{"无导入的文件"}); |
| | | } |
| | | if (!fileName.endsWith(".zip") || !fileName.endsWith(".rar")) { |
| | | throw new VciBaseException("仅能上传zip压缩文件,请重新上传!"); |
| | | } |
| | | File unzip = ZipUtil.unzip(fileName); |
| | | File btmExcel = new File(unzip.getAbsolutePath() + File.separator + "btm.xls"); |
| | | File attrExcel = new File(unzip.getAbsolutePath() + File.separator + "btmattr.xls"); |
| | | if (!attrExcel.exists()) { |
| | | //增加解压的路径,看文件还在没有 |
| | | attrExcel = new File(unzip.getAbsolutePath() + File.separator + unzip.getName() + File.separator + "btmattr.xls"); |
| | | if (!attrExcel.exists()) { |
| | | return BaseResult.fail(FrameWorkLangCodeConstant.IMPORT_FAIL, new String[]{"没有导入的属性文件。导入终止!"}); |
| | | } |
| | | } |
| | | //TODO:导入属性,但是这个逻辑实际上存在一些问题,导入的属性只是业务类型的属性不应该去给属性池导入,可能是想的属性不存在的就新增一次 |
| | | BaseResult baseResult = attributeService.importAttributes(attrExcel,true); |
| | | if(!baseResult.isSuccess()){ |
| | | //删除上传的文件夹 |
| | | FileUtil.del(defaultTempFolder + File.separator); |
| | | return baseResult; |
| | | } |
| | | //入业务类型 |
| | | if (!btmExcel.exists()) { |
| | | //增加解压的路径,看文件还在没有 |
| | | btmExcel = new File(unzip.getAbsolutePath() + File.separator + unzip.getName() + File.separator + "btm.xls"); |
| | | if (!btmExcel.exists()) { |
| | | //删除上传的文件夹 |
| | | FileUtil.del(defaultTempFolder + File.separator); |
| | | return BaseResult.fail(FrameWorkLangCodeConstant.IMPORT_FAIL, new String[]{"没有导入的链接文件。导入终止!"}); |
| | | } |
| | | } |
| | | try{ |
| | | //1、读取excel中的数据,组成对象 |
| | | ReadExcelOption excelOption = new ReadExcelOption(); |
| | | List<OsBtmTypePO> poList = ExcelUtil.readDataObjectFromExcel(btmExcel, OsBtmTypePO.class,excelOption,(value, po, fieldName)->{}); |
| | | //去除都是空的情况 |
| | | if(CollectionUtils.isEmpty(poList)){ |
| | | return BaseResult.fail(ExcelLangCodeConstant.IMPORT_CONTENT_NULL,new String[]{}); |
| | | } |
| | | //当前excel中是否重复用的判重Map:(key:判重属性,value:行号) |
| | | Map<String, String> excelReapeat = new HashMap<>(); |
| | | int maxLength = platformClientUtil.getLinkTypeService().getLTNameMaxLength(); |
| | | |
| | | //判断必填属性是否为空,用户是否已存在,以及部门是否填错等校验逻辑 |
| | | poList.stream().forEach(osBtmTypePO -> { |
| | | if(Func.isBlank(osBtmTypePO.getName())){//属性名判空 |
| | | throw new VciBaseException("第【"+osBtmTypePO.getRowIndex()+"】行,name"); |
| | | }else if(osBtmTypePO.getName().length() > maxLength){ |
| | | throw new VciBaseException("第【"+osBtmTypePO.getRowIndex()+"】行,业务类型名长度不能超过" + maxLength); |
| | | }else if(!osBtmTypePO.getName().matches("^[A-Za-z]+$")){ |
| | | throw new VciBaseException("第【"+osBtmTypePO.getRowIndex()+"】行,业务类型名称只能为英文字母"); |
| | | }else if (osBtmTypePO.getName().length() > maxLength) { |
| | | throw new VciBaseException("第【"+osBtmTypePO.getRowIndex()+"】行,业务类型名长度不能超过" + maxLength); |
| | | }else if(excelReapeat.containsKey(osBtmTypePO.getName())){//业务类型名在表格中判重 |
| | | throw new VciBaseException("第【"+excelReapeat.get(osBtmTypePO.getName())+"】行和第【"+osBtmTypePO.getRowIndex()+"】行数据,业务类型名重复"); |
| | | }else if (Func.isBlank(osBtmTypePO.getLifeCycle())) { |
| | | throw new VciBaseException("第【"+osBtmTypePO.getRowIndex()+"】行,生命周期不能为空"); |
| | | }else if ("true".equalsIgnoreCase(osBtmTypePO.getRevInput()) && Func.isBlank(osBtmTypePO.getRevRuleName())) { |
| | | throw new VciBaseException("第【"+osBtmTypePO.getRowIndex()+"】行,版本号规则不能为空"); |
| | | } |
| | | try { |
| | | BizType historyBtm = platformClientUtil.getBtmService().getBizTypeByName(osBtmTypePO.getName()); |
| | | //已有此数据进行删除覆盖 |
| | | if(historyBtm != null && !historyBtm.name.equals("")){ |
| | | platformClientUtil.getBtmService().deleteBizType(historyBtm); |
| | | } |
| | | } catch (PLException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | |
| | | //属性名excel中判重处理 |
| | | excelReapeat.put(osBtmTypePO.getName(),osBtmTypePO.getRowIndex()); |
| | | BizType bizType = new BizType(); |
| | | bizType.name = osBtmTypePO.getName(); |
| | | bizType.label = osBtmTypePO.getLable(); |
| | | bizType.description = osBtmTypePO.getDescription(); |
| | | bizType.fName = osBtmTypePO.getFName(); |
| | | bizType.implClass = osBtmTypePO.getImplClass(); |
| | | bizType.revLevel = osBtmTypePO.getRevLevel(); |
| | | bizType.revRuleName = osBtmTypePO.getRevRuleName(); |
| | | bizType.revInput = Boolean.parseBoolean(osBtmTypePO.getRevInput().toLowerCase(Locale.ROOT)); |
| | | bizType.delimiter = osBtmTypePO.getDelimiter(); |
| | | bizType.verRuleName = osBtmTypePO.getVerRuleName(); |
| | | bizType.lifeCycle = osBtmTypePO.getLifeCycle(); |
| | | bizType.lifeCycles = osBtmTypePO.getLifeCycles().split(","); |
| | | bizType.apNameArray = osBtmTypePO.getApNameArray().split(","); |
| | | String userId = WebUtil.getCurrentUserId(); |
| | | bizType.modifier = userId; |
| | | bizType.creator = userId; |
| | | try { |
| | | platformClientUtil.getBtmService().addBizType(bizType); |
| | | } catch (PLException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | }); |
| | | }catch (Exception e){ |
| | | if(logger.isErrorEnabled()){ |
| | | logger.error("读取excel内容时或保存业务类型信息时出现了错误,具体原因:",VciBaseUtil.getExceptionMessage(e)); |
| | | } |
| | | e.printStackTrace(); |
| | | return BaseResult.fail(VciBaseUtil.getExceptionMessage(e),new String[]{},e); |
| | | } |
| | | //删除上传的文件夹 |
| | | FileUtil.del(defaultTempFolder + File.separator); |
| | | return BaseResult.success("业务类型导入成功!"); |
| | | } |
| | | |
| | | /** |
| | |
| | | return flag; |
| | | } |
| | | |
| | | private List<Tree> getChildren(BizType[] bizTypes,BizType parentBIzType){ |
| | | private List<Tree> getChildren(List<OsBtmTypeVO> osBtmTypeVOS,OsBtmTypeVO parentBIzType){ |
| | | List<Tree> trees= new ArrayList<>(); |
| | | for (BizType bizType : bizTypes) { |
| | | if(StringUtils.isBlank(bizType.fName)){ |
| | | for (OsBtmTypeVO bizType : osBtmTypeVOS) { |
| | | if(StringUtils.isBlank(bizType.getfName())){ |
| | | continue; |
| | | } |
| | | if(bizType.fName.equals(parentBIzType.name)){ |
| | | if(bizType.getfName().equals(parentBIzType.getId())){ |
| | | Tree tree = new Tree(); |
| | | tree.setOid(bizType.oid); |
| | | tree.setParentName(parentBIzType.fName); |
| | | tree.setParentId(parentBIzType.oid); |
| | | tree.setOid(bizType.getOid()); |
| | | tree.setParentName(parentBIzType.getfName()); |
| | | tree.setParentId(parentBIzType.getOid()); |
| | | tree.setLeaf(true); |
| | | tree.setText(bizType.description); |
| | | tree.setText(bizType.getDescription()); |
| | | tree.setAttributes(WebUtil.objectToMapString(bizType)); |
| | | tree.setChildren(getChildren(bizTypes,bizType)); |
| | | tree.setChildren(getChildren(osBtmTypeVOS,bizType)); |
| | | trees.add(tree); |
| | | } |
| | | } |