| | |
| | | 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.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.BusinessObject; |
| | | import com.vci.corba.omd.ltm.LinkType; |
| | | import com.vci.corba.omd.ltm.LinkTypeServicePrx; |
| | | import com.vci.dto.OsAttributeDTO; |
| | | import com.vci.omd.constants.LinkTypeConstants; |
| | | import com.vci.omd.utils.ObjectTool; |
| | | import com.vci.pagemodel.*; |
| | | import com.vci.po.OsAttributePO; |
| | | 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.enumpck.VciFieldTypeEnum; |
| | | import com.vci.starter.web.exception.VciBaseException; |
| | | 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.starter.web.util.*; |
| | | import com.vci.model.OsLinkTypeDO; |
| | | import com.vci.web.service.*; |
| | | import com.vci.web.util.Func; |
| | | import com.vci.web.util.PlatformClientUtil; |
| | | import com.vci.web.util.WebUtil; |
| | | import javafx.scene.shape.HLineTo; |
| | | 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 java.io.IOException; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.*; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | */ |
| | | @Service |
| | | public class OsLinkTypeServiceImpl implements OsLinkTypeServiceI { |
| | | |
| | | private static final String OID = "oid"; |
| | | private static final String NAME = "name"; |
| | | private static final String LABEL = "label"; |
| | | private static final String DESCRIPTION = "description"; |
| | | private static final String TS = "ts"; |
| | | private static final String CREATOR = "creator"; |
| | | private static final String CREATETIME = "createTime"; |
| | | private static final String MODIFIER = "modifier"; |
| | | private static final String MODIFYTIME = "modifyTime"; |
| | | |
| | | /** |
| | | * æ¥å¿ |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 导åºé¾æ¥ç±»å |
| | | * name 龿¥ç±»ååç§° |
| | | * @return åå»ºç»æ |
| | | */ |
| | | @Override |
| | | public void expData(String names, HttpServletResponse response) throws PLException, IOException { |
| | | String defaultTempFolder = LocalFileUtil.getDefaultTempFolder(); |
| | | //åexcel |
| | | String excelPath = defaultTempFolder + File.separator + "lt.xls"; |
| | | //设置åå |
| | | List<String> columns = new ArrayList<>( |
| | | Arrays.asList("åç§°", "æ ç¾", "å®ç°ç±»", "å½¢ç¶", "From端类åå表", "From端主类å", "From端对åºå
³ç³»", |
| | | "To端类åå表", "To端主类å", "To端对åºå
³ç³»", "屿§å表", "æè¿°") |
| | | ); |
| | | 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(",")) { |
| | | LinkType lt = platformClientUtil.getLinkTypeService().getLinkType(name); |
| | | excelDataList.add(new WriteExcelData(i+1,0, lt.name)); |
| | | excelDataList.add(new WriteExcelData(i+1,1, lt.tag)); |
| | | excelDataList.add(new WriteExcelData(i+1,2, lt.implClass)); |
| | | excelDataList.add(new WriteExcelData(i+1,3, lt.shape)); |
| | | excelDataList.add(new WriteExcelData(i+1,4, String.join(",",lt.btmItemsFrom))); |
| | | excelDataList.add(new WriteExcelData(i+1,5, lt.primitivesFrom)); |
| | | excelDataList.add(new WriteExcelData(i+1,6, lt.relationFrom)); |
| | | excelDataList.add(new WriteExcelData(i+1,7, String.join(",",lt.btmItemsTo))); |
| | | excelDataList.add(new WriteExcelData(i+1,8, lt.primitivesTo)); |
| | | excelDataList.add(new WriteExcelData(i+1,9, lt.relationTo)); |
| | | excelDataList.add(new WriteExcelData(i+1,10, String.join(",",lt.attributes))); |
| | | excelDataList.add(new WriteExcelData(i+1,11, lt.description)); |
| | | attributes.addAll(Arrays.asList(lt.attributes)); |
| | | i++; |
| | | } |
| | | WriteExcelOption excelOption = new WriteExcelOption(excelDataList); |
| | | ExcelUtil.writeDataToFile(excelPath, excelOption); |
| | | //导åºå±æ§ |
| | | String attrPath = attributeService.exportAttributes("attr", |
| | | String.valueOf(attributes.stream().collect(Collectors.joining(",")))); |
| | | //ç§»å¨å±æ§å°é¾æ¥ç±»åæä»¶å¤¹éé¢å» |
| | | FileUtil.move(new File(attrPath), new File(defaultTempFolder),true); |
| | | FileUtil.del(attrPath.substring(0,attrPath.lastIndexOf("\\"))); |
| | | //todo 导åºä¸å¡ç±»åè¿æ²¡æå®ç° |
| | | // List<BizType> bts = new ArrayList<BizType>(); |
| | | // for (String btName : btNameSet) { |
| | | // BizType bt = BtmProvider.getBtmItemByName(btName); |
| | | // bts.add(bt); |
| | | // } |
| | | // boolean btFlag = BtmProvider.expData(rootPath, bts.toArray(new BizType[0])); |
| | | }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")) { |
| | | throw new VciBaseException("ä»
è½ä¸ä¼ zipå缩æä»¶ï¼è¯·éæ°ä¸ä¼ ï¼"); |
| | | } |
| | | File unzip = ZipUtil.unzip(fileName); |
| | | File ltExcel = new File(unzip.getAbsolutePath() + File.separator + "lt.xls"); |
| | | File attrExcel = new File(unzip.getAbsolutePath() + File.separator + "attr.xls"); |
| | | if (!attrExcel.exists()) { |
| | | //å¢å è§£åçè·¯å¾ï¼çæä»¶è¿å¨æ²¡æ |
| | | attrExcel = new File(unzip.getAbsolutePath() + File.separator + unzip.getName() + File.separator + "attr.xls"); |
| | | if (!attrExcel.exists()) { |
| | | return BaseResult.fail(FrameWorkLangCodeConstant.IMPORT_FAIL, new String[]{"没æå¯¼å
¥ç屿§æä»¶ã导å
¥ç»æ¢ï¼"}); |
| | | } |
| | | } |
| | | BaseResult baseResult = attributeService.importAttributes(attrExcel); |
| | | if(!baseResult.isSuccess()){ |
| | | //å é¤ä¸ä¼ çæä»¶å¤¹ |
| | | FileUtil.del(defaultTempFolder + File.separator); |
| | | return baseResult; |
| | | } |
| | | //todo è¿é导å
¥ä¸å¡ç±»åï¼çå¾
åè½å®ç° |
| | | if (!ltExcel.exists()) { |
| | | //å¢å è§£åçè·¯å¾ï¼çæä»¶è¿å¨æ²¡æ |
| | | ltExcel = new File(unzip.getAbsolutePath() + File.separator + unzip.getName() + File.separator + "lt.xls"); |
| | | if (!ltExcel.exists()) { |
| | | //å é¤ä¸ä¼ çæä»¶å¤¹ |
| | | FileUtil.del(defaultTempFolder + File.separator); |
| | | return BaseResult.fail(FrameWorkLangCodeConstant.IMPORT_FAIL, new String[]{"没æå¯¼å
¥ç龿¥æä»¶ã导å
¥ç»æ¢ï¼"}); |
| | | } |
| | | } |
| | | try{ |
| | | //1ã读åexcelä¸çæ°æ®ï¼ç»æå¯¹è±¡ |
| | | ReadExcelOption excelOption = new ReadExcelOption(); |
| | | List<OsLinkTypePO> poList = ExcelUtil.readDataObjectFromExcel(ltExcel, OsLinkTypePO.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(osLinkTypePO -> { |
| | | if(Func.isBlank(osLinkTypePO.getName())){//屿§åå¤ç©º |
| | | throw new VciBaseException("第ã"+osLinkTypePO.getRowIndex()+"ãè¡ï¼name"); |
| | | }else if(osLinkTypePO.getName().length() > maxLength){ |
| | | throw new VciBaseException("第ã"+osLinkTypePO.getRowIndex()+"ãè¡ï¼é¾æ¥ç±»ååé¿åº¦ä¸è½è¶
è¿" + maxLength); |
| | | }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()+"ãè¡æ°æ®ï¼å±æ§åéå¤"); |
| | | } |
| | | try { |
| | | LinkType historyLink = platformClientUtil.getLinkTypeService().getLinkType(osLinkTypePO.getName()); |
| | | //å·²ææ¤æ°æ®è¿è¡å é¤è¦ç |
| | | if(historyLink != null && !historyLink.name.equals("")){ |
| | | platformClientUtil.getLinkTypeService().deleteLinkType(historyLink); |
| | | } |
| | | } catch (PLException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | |
| | | //屿§åexcelä¸å¤éå¤ç |
| | | excelReapeat.put(osLinkTypePO.getName(),osLinkTypePO.getRowIndex()); |
| | | LinkType linkType = new LinkType(); |
| | | linkType.name = osLinkTypePO.getName(); |
| | | linkType.attributes = osLinkTypePO.getAttributes().split(","); |
| | | linkType.btmItemsFrom = osLinkTypePO.getBtmItemsFrom().split(","); |
| | | linkType.primitivesFrom = osLinkTypePO.getPrimitivesFrom(); |
| | | linkType.relationFrom = osLinkTypePO.getRelationFrom(); |
| | | linkType.btmItemsTo = osLinkTypePO.getBtmItemsTo().split(","); |
| | | linkType.primitivesTo = osLinkTypePO.getPrimitivesTo(); |
| | | linkType.relationTo = osLinkTypePO.getRelationTo(); |
| | | linkType.relation = osLinkTypePO.getRelationFrom() + ":" + osLinkTypePO.getRelationTo(); |
| | | linkType.description = osLinkTypePO.getDescription(); |
| | | linkType.tag = osLinkTypePO.getTag(); |
| | | linkType.shape = osLinkTypePO.getShape(); |
| | | linkType.implClass = osLinkTypePO.getImplClass(); |
| | | linkType.modifier = WebUtil.getCurrentUserId(); |
| | | linkType.creator = WebUtil.getCurrentUserId(); |
| | | try { |
| | | platformClientUtil.getLinkTypeService().addLinkType(linkType); |
| | | } 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("龿¥ç±»å导å
¥æåï¼"); |
| | | } |
| | | |
| | | /** |
| | | * ä¿®å¤é¾æ¥ç±»åçxmlæä»¶ |