完成工程导入部分的代码
This commit is contained in:
parent
049ebd0d6f
commit
effa0d9f4d
|
|
@ -43,6 +43,15 @@ public class ElePropertyConfig {
|
|||
@Value("${data.repo.download.path}")
|
||||
private String repoDownloadPath;
|
||||
|
||||
@Value("${data.import.prj.path}")
|
||||
private String importPrjPath;
|
||||
|
||||
@Value("${data.import.upload.path}")
|
||||
private String importUploadPath;
|
||||
|
||||
@Value("${data.import.download.path}")
|
||||
private String importDownloadPath;
|
||||
|
||||
@Getter
|
||||
@Value("${backup.mysql.script.path}")
|
||||
private String backupMysqlScriptPath;
|
||||
|
|
@ -164,6 +173,27 @@ public class ElePropertyConfig {
|
|||
return prjRootPath + repoDownloadPath;
|
||||
}
|
||||
|
||||
public String getImportPrjPath() {
|
||||
if (EleCommonUtil.isWinOs()) {
|
||||
return winPrefix + prjRootPath + importPrjPath;
|
||||
}
|
||||
return prjRootPath + importPrjPath;
|
||||
}
|
||||
|
||||
public String getImportUploadPath() {
|
||||
if (EleCommonUtil.isWinOs()) {
|
||||
return winPrefix + prjRootPath + importUploadPath;
|
||||
}
|
||||
return prjRootPath + importUploadPath;
|
||||
}
|
||||
|
||||
public String getImportDownloadPath() {
|
||||
if (EleCommonUtil.isWinOs()) {
|
||||
return winPrefix + prjRootPath + importDownloadPath;
|
||||
}
|
||||
return prjRootPath + importDownloadPath;
|
||||
}
|
||||
|
||||
public String getUploadDataDir(int dataOwnCode) {
|
||||
if (DataOwnEnum.isSysCode(dataOwnCode)) {
|
||||
return getSysUploadPath();
|
||||
|
|
@ -182,4 +212,5 @@ public class ElePropertyConfig {
|
|||
return getRepoDownloadPath();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,28 @@
|
|||
package com.electromagnetic.industry.software.manage.controller;
|
||||
|
||||
import com.electromagnetic.industry.software.common.annotations.UserOperation;
|
||||
import com.electromagnetic.industry.software.common.enums.UserOperationModuleEnum;
|
||||
import com.electromagnetic.industry.software.common.resp.ElectromagneticResult;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@RestController
|
||||
public class ImportPrjController {
|
||||
|
||||
/**
|
||||
* 导入本地工程
|
||||
*
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("/importPrj")
|
||||
@UserOperation(value = "导入本地工程", modelName = UserOperationModuleEnum.SYS_PRJ_DATABASE)
|
||||
public ElectromagneticResult<?> importPrj(@RequestParam("file") MultipartFile file) {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -202,16 +202,5 @@ public class SysEdFileInfoController {
|
|||
return ElectromagneticResultUtil.success(edFileInfoService.findFavorite(userId, fileInfoQueryDTO));
|
||||
}
|
||||
|
||||
/**
|
||||
* 导入本地工程
|
||||
*
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("/importPrj")
|
||||
@UserOperation(value = "导入本地工程", modelName = UserOperationModuleEnum.SYS_PRJ_DATABASE)
|
||||
public ElectromagneticResult<?> importPrj(@RequestParam("file") MultipartFile file, @RequestParam(name = "templateCode", defaultValue = "bhdcfzrjzt", required = false) String templateCode) {
|
||||
return edFileInfoService.importPrj(file, templateCode);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
package com.electromagnetic.industry.software.manage.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.electromagnetic.industry.software.manage.pojo.models.ImportFileInfo;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface ImportPrjInfoMapper extends BaseMapper<ImportFileInfo> {
|
||||
}
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
package com.electromagnetic.industry.software.manage.pojo.models;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
import lombok.experimental.FieldNameConstants;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("import_ed_file_info")
|
||||
@Accessors(chain = true)
|
||||
@Data
|
||||
@FieldNameConstants
|
||||
public class ImportFileInfo extends BaseModel {
|
||||
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
@TableField(value = "id")
|
||||
private String id;
|
||||
/**
|
||||
* 父目录id
|
||||
*/
|
||||
@TableField(value = "parent_id")
|
||||
private String parentId;
|
||||
/**
|
||||
* 文件类型
|
||||
*/
|
||||
@TableField(value = "file_type")
|
||||
private String fileType;
|
||||
/**
|
||||
* 文件名
|
||||
*/
|
||||
@TableField(value = "file_name")
|
||||
private String fileName;
|
||||
/**
|
||||
* 文件内容,保留,暂时里面为空
|
||||
*/
|
||||
@TableField(value = "file_content")
|
||||
private String fileContent;
|
||||
/**
|
||||
* 文件路径,指到文件的父目录,有各个父目录的id加下划线组成
|
||||
*/
|
||||
@TableField(value = "file_path")
|
||||
private String filePath;
|
||||
/**
|
||||
* 数据类型,0-文件夹 1-文件
|
||||
*/
|
||||
@TableField(value = "data_type")
|
||||
private Integer dataType;
|
||||
/**
|
||||
* 文件大小
|
||||
*/
|
||||
@TableField(value = "file_size")
|
||||
private Long fileSize;
|
||||
/**
|
||||
* 文件夹顺序
|
||||
*/
|
||||
@TableField(value = "sort")
|
||||
private Integer sort;
|
||||
|
||||
/**
|
||||
* 当文件被管理员永久物理删除,此时为true
|
||||
*/
|
||||
@TableField(value = "permanent_deleted")
|
||||
private Boolean permanentDeleted;
|
||||
|
||||
}
|
||||
|
|
@ -2,8 +2,6 @@ package com.electromagnetic.industry.software.manage.pojo.req;
|
|||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Data
|
||||
public class AddImportTableDataDTO {
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,6 @@ package com.electromagnetic.industry.software.manage.pojo.req;
|
|||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Data
|
||||
public class UpdateImportTableDataDTO {
|
||||
private String id;
|
||||
|
|
|
|||
|
|
@ -243,9 +243,4 @@ public interface EdFileInfoService {
|
|||
* @return
|
||||
*/
|
||||
ElectromagneticResult<?> uploadFileAndRelation(String parentId, String id, MultipartFile file, String desc, int dataOwnCode);
|
||||
|
||||
/**
|
||||
* 导入工程
|
||||
*/
|
||||
ElectromagneticResult<?> importPrj(MultipartFile file, String templateCode);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
package com.electromagnetic.industry.software.manage.service;
|
||||
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
public interface ImportPrjService {
|
||||
|
||||
boolean importPrj(MultipartFile file);
|
||||
|
||||
}
|
||||
|
|
@ -124,6 +124,8 @@ public class CommonService {
|
|||
PATH_MAP.put(DataOwnEnum.USER_FILE.code, elePropertyConfig.getUserPrjPath());
|
||||
PATH_MAP.put(DataOwnEnum.REPO_FILE.code, elePropertyConfig.getRepoPrjPath());
|
||||
PATH_MAP.put(DataOwnEnum.REPO_PRJ.code, elePropertyConfig.getRepoPrjPath());
|
||||
PATH_MAP.put(DataOwnEnum.IMPORT_FILE.code, elePropertyConfig.getImportPrjPath());
|
||||
PATH_MAP.put(DataOwnEnum.IMPORT_PRJ.code, elePropertyConfig.getImportPrjPath());
|
||||
}
|
||||
|
||||
public String getPrjRootPath1(int dataOwnCode) {
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.electromagnetic.industry.software.common.enums.FilePermission;
|
||||
import com.electromagnetic.industry.software.common.enums.*;
|
||||
import com.electromagnetic.industry.software.common.exception.BizException;
|
||||
import com.electromagnetic.industry.software.common.exception.PermissionDeniedException;
|
||||
|
|
@ -53,7 +52,6 @@ import org.springframework.web.multipart.MultipartFile;
|
|||
|
||||
import java.io.*;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.*;
|
||||
|
|
@ -1526,211 +1524,6 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ElectromagneticResult<?> importPrj(MultipartFile file, String templateCode) {
|
||||
|
||||
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 导入工程
|
||||
*
|
||||
* @param file
|
||||
*/
|
||||
// @Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ElectromagneticResult<?> importPrj1(MultipartFile file, String templateCode) {
|
||||
try {
|
||||
// 创建工程
|
||||
String prjId = updateImportPrj2Db(file);
|
||||
// 层级沿用,先这样写,后续根据需求扩展
|
||||
EdFileInfo prj = this.baseMapper.selectOne(Wrappers.lambdaQuery(EdFileInfo.class)
|
||||
.eq(EdFileInfo::getTemplateCode, templateCode)
|
||||
.eq(EdFileInfo::getEffectFlag, EffectFlagEnum.EFFECT.code));
|
||||
commonService.follow(prj.getId(), prjId, DataOwnEnum.SYS_PRJ.code);
|
||||
// 工程发布
|
||||
commonService.publish(prjId, DataOwnEnum.SYS_PRJ.code);
|
||||
// 将文件存入到数据库和文件系统
|
||||
updateImportPrj2FileSystem(file, prjId);
|
||||
// 添加所有权限
|
||||
addRoleAndPermission(prjId);
|
||||
} catch (Exception e) {
|
||||
String info = "导入失败,原因 " + e.getMessage();
|
||||
log.error(info, e);
|
||||
throw new BizException(info, e);
|
||||
}
|
||||
return ElectromagneticResultUtil.success(true);
|
||||
}
|
||||
|
||||
private void addRoleAndPermission(String prjId) {
|
||||
// 首先添加角色,这里先假设只有北航,角色名称为“936c586c88e44df7a262f0ebb4dbe3ab”
|
||||
Role role = roleMapper.selectOne(Wrappers.lambdaQuery(Role.class)
|
||||
.eq(Role::getEffectFlag, EffectFlagEnum.EFFECT.code)
|
||||
.eq(Role::getRoleName, "936c586c88e44df7a262f0ebb4dbe3ab"));
|
||||
if (Objects.isNull(role)) {
|
||||
role = new Role();
|
||||
role.newInit();
|
||||
role.setRoleName("936c586c88e44df7a262f0ebb4dbe3ab");
|
||||
role.setRoleDesc("针对北航内定的角色");
|
||||
roleMapper.insert(role);
|
||||
}
|
||||
|
||||
List<EdFileInfo> edFileInfos = this.baseMapper.selectList(Wrappers.lambdaQuery(EdFileInfo.class)
|
||||
.eq(EdFileInfo::getDataOwn, DataOwnEnum.SYS_PRJ.code)
|
||||
.likeRight(EdFileInfo::getFilePath, prjId + MYSQL_FILE_PATH_SPLIT));
|
||||
Set<String> ids = edFileInfos.stream().map(EdFileInfo::getId).collect(Collectors.toSet());
|
||||
ids.add(prjId);
|
||||
for (String id : ids) {
|
||||
for (FilePermission permission : FilePermission.values()) {
|
||||
RolePermission rolePermission = new RolePermission();
|
||||
rolePermission.newInit();
|
||||
rolePermission.setRoleId(role.getId());
|
||||
rolePermission.setFileId(id);
|
||||
rolePermission.setPermissionCode(permission.getCode());
|
||||
rolePermissionService.saveOrUpdate(rolePermission);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateImportPrj2FileSystem(MultipartFile file, String prjId) {
|
||||
String tmpZipFile = null;
|
||||
String destDir = null;
|
||||
try {
|
||||
String orgName = file.getOriginalFilename();
|
||||
tmpZipFile = elePropertyConfig.getEleTmpPath() + File.separator + orgName;
|
||||
String mainName = FileUtil.mainName(orgName);
|
||||
FileUtil.del(tmpZipFile);
|
||||
FileUtil.writeFromStream(file.getInputStream(), tmpZipFile);
|
||||
destDir = elePropertyConfig.getEleTmpPath() + File.separator + IdUtil.fastSimpleUUID();
|
||||
try {
|
||||
ZipUtil.unzip(tmpZipFile, destDir, StandardCharsets.UTF_8);
|
||||
} catch (Exception e) {
|
||||
ZipUtil.unzip(tmpZipFile, destDir, Charset.forName("GBK"));
|
||||
}
|
||||
|
||||
File file1 = Objects.requireNonNull(new File(destDir).listFiles())[0];
|
||||
FileUtil.rename(file1, mainName, true);
|
||||
List<EdFileInfo> edFileInfos = this.baseMapper.selectList(Wrappers.lambdaQuery(EdFileInfo.class)
|
||||
.eq(EdFileInfo::getEffectFlag, EffectFlagEnum.EFFECT.code)
|
||||
.likeRight(EdFileInfo::getFilePath, prjId + MYSQL_FILE_PATH_SPLIT)
|
||||
.eq(EdFileInfo::getDataOwn, DataOwnEnum.SYS_PRJ.code));
|
||||
Map<String, String> idNameMap = edFileInfos.stream().collect(Collectors.toMap(EdFileInfo::getId, EdFileInfo::getFileName));
|
||||
idNameMap.put(prjId, mainName);
|
||||
Map<String, EdFileInfo> filePathMap = new HashMap<>();
|
||||
for (EdFileInfo edFileInfo : edFileInfos) {
|
||||
StringBuilder names = new StringBuilder();
|
||||
for (String id : edFileInfo.getFilePath().split(MYSQL_FILE_PATH_SPLIT)) {
|
||||
String name = idNameMap.get(id);
|
||||
names.append(MYSQL_FILE_PATH_SPLIT).append(name);
|
||||
}
|
||||
filePathMap.put(names.substring(1), edFileInfo);
|
||||
}
|
||||
|
||||
List<File> files = FileUtil.loopFiles(destDir);
|
||||
String tmpPath = FileUtil.normalize(destDir);
|
||||
for (File importFile : files) {
|
||||
Assert.isTrue(EleCommonUtil.isFileNameValid(importFile.getName()), "文件名称不符合规范");
|
||||
String parentDir = FileUtil.normalize(importFile.getParent());
|
||||
String relativeFilePath = parentDir.replace(tmpPath, "");
|
||||
String fileType = FileUtil.getSuffix(importFile.getName());
|
||||
relativeFilePath = relativeFilePath.startsWith("/") ? relativeFilePath.substring(1) : relativeFilePath;
|
||||
relativeFilePath = relativeFilePath.replace("/", MYSQL_FILE_PATH_SPLIT);
|
||||
EdFileInfo edFileInfo = filePathMap.get(relativeFilePath);
|
||||
Assert.notNull(edFileInfo, "导入的工程与定义的层级结构不一致");
|
||||
String id = edFileInfo.getId();
|
||||
EdFileInfo newEdFileInfo = new EdFileInfo();
|
||||
newEdFileInfo.newInit();
|
||||
String fileCode = commonService.createFileCode(id, fileType, FILE_START_VERSION, newEdFileInfo.getFileTime());
|
||||
newEdFileInfo.setParentId(id)
|
||||
.setFileCode(fileCode)
|
||||
.setSaveStatus(EleDataSaveStatusEnum.SUCCESS.code)
|
||||
.setDataOwn(DataOwnEnum.SYS_FILE.code)
|
||||
.setFileName(FileUtil.mainName(importFile))
|
||||
.setFileContent(EleCommonUtil.parse(FileUtil.getInputStream(importFile), fileType))
|
||||
.setFileType(fileType)
|
||||
.setFileVersion(FILE_START_VERSION)
|
||||
.setFileSize(importFile.length())
|
||||
.setFilePath(edFileInfo.getFilePath() + MYSQL_FILE_PATH_SPLIT + newEdFileInfo.getId())
|
||||
.setDataType(EleDataTypeEnum.FILE.code)
|
||||
.setDataStatus(PublishEnum.PUBLISHED.getCode())
|
||||
.setEffectFlag(EffectFlagEnum.EFFECT.code);
|
||||
this.baseMapper.insert(newEdFileInfo);
|
||||
String destPath = commonService.getPrjRootPath1(DataOwnEnum.SYS_FILE.code) + File.separator + newEdFileInfo.getId();
|
||||
FileUtil.move(importFile, new File(destPath), false);
|
||||
EleCommonUtil.encryptFile(destPath, SecureUtil.aes(FILE_SEC_PASSWD.getBytes()));
|
||||
UserThreadLocal.setSuccessInfo(newEdFileInfo.getParentId(), newEdFileInfo.getId(), "解析导入的工程文件成功,导入的工程名为 {},文件名为 {}", orgName, importFile.getName());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
String info = "上传失败,原因 " + e.getMessage();
|
||||
throw new BizException(info, e);
|
||||
} finally {
|
||||
FileUtil.del(destDir);
|
||||
FileUtil.del(tmpZipFile);
|
||||
}
|
||||
}
|
||||
|
||||
private String updateImportPrj2Db(MultipartFile file) {
|
||||
String originalFilename = file.getOriginalFilename();
|
||||
String suffix = FileUtil.getSuffix(originalFilename);
|
||||
String mainName = FileUtil.mainName(originalFilename);
|
||||
Assert.isTrue(StrUtil.equals(suffix, "zip"), "不支持 {} 格式的工程文件", suffix);
|
||||
Assert.isTrue(EleCommonUtil.isFileNameValid(originalFilename), "项目名称不符合规范");
|
||||
// 检查工程是否存在
|
||||
List<EdFileInfo> edFileInfos = this.baseMapper.selectList(Wrappers.lambdaQuery(EdFileInfo.class).eq(EdFileInfo::getFileName, mainName)
|
||||
.eq(EdFileInfo::getDataOwn, DataOwnEnum.SYS_PRJ.code)
|
||||
.eq(EdFileInfo::getEffectFlag, EffectFlagEnum.EFFECT.code)
|
||||
.eq(EdFileInfo::getParentId, PRJ_PARENT_ID));
|
||||
|
||||
if (!edFileInfos.isEmpty()) {
|
||||
// 废除工程及其下面的所有文件
|
||||
Set<String> ids = edFileInfos.stream().map(EdFileInfo::getId).collect(Collectors.toSet());
|
||||
for (EdFileInfo edFileInfo : edFileInfos) {
|
||||
String id = edFileInfo.getId();
|
||||
List<EdFileInfo> edFileInfos1 = this.baseMapper.selectList(Wrappers.lambdaQuery(EdFileInfo.class)
|
||||
.select(EdFileInfo::getId)
|
||||
.eq(EdFileInfo::getFileId, id)
|
||||
.likeRight(EdFileInfo::getFilePath, id + MYSQL_FILE_PATH_SPLIT));
|
||||
ids.addAll(edFileInfos1.stream().map(EdFileInfo::getId).collect(Collectors.toSet()));
|
||||
}
|
||||
this.baseMapper.update(new EdFileInfo(), Wrappers.lambdaUpdate(EdFileInfo.class)
|
||||
.set(EdFileInfo::getEffectFlag, EffectFlagEnum.NOT_EFFECTIVE.code)
|
||||
.in(EdFileInfo::getId, ids));
|
||||
UserThreadLocal.setSuccessInfo("", "", "导入工程时,发现了同名工程 {},删除了同名工程,ids是 {}", mainName, ids);
|
||||
}
|
||||
|
||||
// 保存信息到MySQL
|
||||
String maxPrjId = this.baseMapper.maxPrjId();
|
||||
LambdaQueryWrapper<EdFileInfo> qw = Wrappers.lambdaQuery(EdFileInfo.class).eq(EdFileInfo::getParentId, PRJ_PARENT_ID);
|
||||
Long prjCount = this.baseMapper.selectCount(qw.eq(EdFileInfo::getDataOwn, DataOwnEnum.SYS_PRJ.code));
|
||||
int id = Integer.parseInt(StrUtil.isEmpty(maxPrjId) ? "100000" : maxPrjId);
|
||||
String newPrjId = String.valueOf(id + 1);
|
||||
EdFileInfo fileInfo = new EdFileInfo();
|
||||
fileInfo.newInit();
|
||||
String nowTimeStr = EleCommonUtil.getNowTimeStr();
|
||||
fileInfo.setId(newPrjId)
|
||||
.setFileType("文件夹")
|
||||
.setFileId(newPrjId)
|
||||
.setFileName(mainName)
|
||||
.setFileVersion(FILE_START_VERSION)
|
||||
.setParentId(PRJ_PARENT_ID)
|
||||
.setFileTime(nowTimeStr)
|
||||
.setDataType(EleDataTypeEnum.FOLDER.code)
|
||||
.setDataStatus(EleDataStatusEnum.PUBLISHED.code)
|
||||
.setSaveStatus(EleDataSaveStatusEnum.SUCCESS.code)
|
||||
.setFilePath(newPrjId)
|
||||
.setSort(prjCount.intValue() + 1)
|
||||
.setFileCode(commonService.createFileCode(newPrjId, EleDataTypeEnum.FOLDER.desc, FILE_START_VERSION, nowTimeStr))
|
||||
.setDataOwn(DataOwnEnum.SYS_PRJ.code)
|
||||
.setEffectFlag(EffectFlagEnum.EFFECT.code);
|
||||
this.baseMapper.insert(fileInfo);
|
||||
UserThreadLocal.setSuccessInfo("", newPrjId, "创建 {} 项目成功。", mainName);
|
||||
return newPrjId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 统一废除文件相关数据
|
||||
*
|
||||
|
|
|
|||
|
|
@ -0,0 +1,152 @@
|
|||
package com.electromagnetic.industry.software.manage.service.serviceimpl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.electromagnetic.industry.software.common.cons.ElectromagneticConstants;
|
||||
import com.electromagnetic.industry.software.common.enums.EffectFlagEnum;
|
||||
import com.electromagnetic.industry.software.common.enums.EleDataTypeEnum;
|
||||
import com.electromagnetic.industry.software.common.exception.BizException;
|
||||
import com.electromagnetic.industry.software.common.util.EleCommonUtil;
|
||||
import com.electromagnetic.industry.software.common.util.IdWorker;
|
||||
import com.electromagnetic.industry.software.manage.config.ElePropertyConfig;
|
||||
import com.electromagnetic.industry.software.manage.mapper.ImportPrjInfoMapper;
|
||||
import com.electromagnetic.industry.software.manage.pojo.models.ImportFileInfo;
|
||||
import com.electromagnetic.industry.software.manage.service.ImportPrjService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.mockito.internal.util.io.IOUtil;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.util.*;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
import static com.electromagnetic.industry.software.common.cons.ElectromagneticConstants.APPEND_NEW_FILE_NAME;
|
||||
import static com.electromagnetic.industry.software.common.cons.ElectromagneticConstants.FILE_SEC_PASSWD;
|
||||
|
||||
@Service
|
||||
public class ImportPrjServiceImpl extends ServiceImpl<ImportPrjInfoMapper, ImportFileInfo> implements ImportPrjService {
|
||||
|
||||
@Resource
|
||||
private ElePropertyConfig elePropertyConfig;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean importPrj(MultipartFile file) {
|
||||
String zipTmpPath = elePropertyConfig.getEleTmpPath() + File.pathSeparator + UUID.randomUUID() + ".zip";
|
||||
ZipFile zipFile = null;
|
||||
// zipTmpPath = "D:\\tmp\\szsd\\data\\ele.zip";
|
||||
try {
|
||||
FileUtil.writeFromStream(file.getInputStream(), zipTmpPath);
|
||||
Map<String, String> pathIdMap = new HashMap<>();
|
||||
List<ImportFileInfo> items = new ArrayList<>();
|
||||
zipFile = EleCommonUtil.getZipFile(zipTmpPath);
|
||||
Map<String, ImportFileInfo> itemIdMap = new HashMap<>();
|
||||
Map<String, ZipEntry> entryMap = new HashMap<>();
|
||||
Enumeration<? extends ZipEntry> entries = zipFile.entries();
|
||||
// 预处理:建立路径映射
|
||||
while (entries.hasMoreElements()) {
|
||||
ZipEntry entry = entries.nextElement();
|
||||
String entryName = entry.getName();
|
||||
// 跳过根目录(如果存在)
|
||||
if (entryName.isEmpty()) continue;
|
||||
// 解析路径结构
|
||||
String[] pathParts = entryName.split("/");
|
||||
String currentPath = "";
|
||||
String parentId = ElectromagneticConstants.PRJ_PARENT_ID; // 根目录的parentId为0
|
||||
|
||||
for (int i = 0; i < pathParts.length; i++) {
|
||||
String name = pathParts[i];
|
||||
if (name.isEmpty()) continue;
|
||||
currentPath += (i == 0 ? "" : "/") + name;
|
||||
// 如果是目录且不是最后一个元素
|
||||
boolean isDirectory = i < pathParts.length - 1 || entry.isDirectory();
|
||||
if (!pathIdMap.containsKey(currentPath)) {
|
||||
String newId = IdWorker.getSnowFlakeIdString();
|
||||
pathIdMap.put(currentPath, newId);
|
||||
String findIdPath = findIdPath(parentId, itemIdMap);
|
||||
String filePath = StrUtil.isEmpty(findIdPath) ? newId : findIdPath + ElectromagneticConstants.MYSQL_FILE_PATH_SPLIT + newId;
|
||||
ImportFileInfo importFileInfo = new ImportFileInfo()
|
||||
.setId(newId)
|
||||
.setParentId(parentId)
|
||||
.setFileType(FileUtil.getSuffix(entryName))
|
||||
.setFileName(FileUtil.mainName(entryName))
|
||||
.setFilePath(filePath)
|
||||
.setFileContent("")
|
||||
.setDataType(isDirectory ? EleDataTypeEnum.FOLDER.code : EleDataTypeEnum.FILE.code)
|
||||
.setFileSize(entry.getSize())
|
||||
.setPermanentDeleted(false);
|
||||
resetPrjName(importFileInfo);
|
||||
if (isDirectory) {
|
||||
importFileInfo.setSort(createFolderSort(parentId, itemIdMap));
|
||||
} else {
|
||||
entryMap.put(newId, entry);
|
||||
}
|
||||
items.add(importFileInfo);
|
||||
itemIdMap.put(newId, importFileInfo);
|
||||
parentId = newId;
|
||||
} else {
|
||||
parentId = pathIdMap.get(currentPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.saveBatch(items);
|
||||
for (Map.Entry<String, ZipEntry> entry : entryMap.entrySet()) {
|
||||
String newId = entry.getKey();
|
||||
ZipEntry tmp = entry.getValue();
|
||||
InputStream inputStream = zipFile.getInputStream(tmp);
|
||||
String destPath = elePropertyConfig.getEleTmpPath() + File.pathSeparator + newId;
|
||||
FileUtil.writeFromStream(inputStream, destPath);
|
||||
EleCommonUtil.decryptFile(destPath, SecureUtil.aes(FILE_SEC_PASSWD.getBytes()));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new BizException("导入工程失败,原因 " + e.getMessage(), e);
|
||||
} finally {
|
||||
IOUtil.close(zipFile);
|
||||
FileUtil.del(zipTmpPath);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void resetPrjName(ImportFileInfo importFileInfo) {
|
||||
if (!StrUtil.equals(importFileInfo.getParentId(), ElectromagneticConstants.PRJ_PARENT_ID)) {
|
||||
return;
|
||||
}
|
||||
String fileName = importFileInfo.getFileName();
|
||||
for (int i = 0; i < 1000; ++i) {
|
||||
long count = this.baseMapper.selectCount(Wrappers.lambdaQuery(ImportFileInfo.class)
|
||||
.eq(ImportFileInfo::getParentId, ElectromagneticConstants.PRJ_PARENT_ID)
|
||||
.eq(ImportFileInfo::getFileName, fileName)
|
||||
.eq(ImportFileInfo::getEffectFlag, EffectFlagEnum.EFFECT.code));
|
||||
if (count > 0) {
|
||||
fileName = fileName + APPEND_NEW_FILE_NAME;
|
||||
} else {
|
||||
importFileInfo.setFileName(fileName);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String findIdPath(String parentId, Map<String, ImportFileInfo> itemIdMap) {
|
||||
List<String> ids = new ArrayList<>();
|
||||
while (itemIdMap.containsKey(parentId)) {
|
||||
ImportFileInfo zipItem = itemIdMap.get(parentId);
|
||||
ids.add(zipItem.getId());
|
||||
parentId = zipItem.getParentId();
|
||||
}
|
||||
CollUtil.reverse(ids);
|
||||
return CollUtil.join(ids, "_");
|
||||
}
|
||||
|
||||
private Integer createFolderSort(String parentId, Map<String, ImportFileInfo> itemIdMap) {
|
||||
long count = itemIdMap.values().stream().filter(e -> e.getParentId().equals(parentId) && e.getDataType().equals(EleDataTypeEnum.FOLDER.code)).count();
|
||||
return Math.toIntExact(++count);
|
||||
}
|
||||
}
|
||||
|
|
@ -78,7 +78,7 @@ public class ImportTableServiceImpl implements ImportTableService {
|
|||
.set(ImportTableInfo::getEffectFlag, EffectFlagEnum.NOT_EFFECTIVE.code)
|
||||
.eq(ImportTableInfo::getId, id));
|
||||
importTableDataMapper.update(new ImportTableData(), Wrappers.<ImportTableData>lambdaUpdate()
|
||||
.eq(ImportTableData::getTableInfoId, id)
|
||||
.eq(ImportTableData::getTableInfoId, id)
|
||||
.set(ImportTableData::getEffectFlag, EffectFlagEnum.EFFECT.code));
|
||||
return ElectromagneticResultUtil.success(true);
|
||||
}
|
||||
|
|
@ -106,7 +106,7 @@ public class ImportTableServiceImpl implements ImportTableService {
|
|||
@Transactional(rollbackFor = Exception.class)
|
||||
public ElectromagneticResult<?> removeTableDataById(String id) {
|
||||
importTableDataMapper.update(new ImportTableData(), Wrappers.<ImportTableData>lambdaUpdate()
|
||||
.eq(ImportTableData::getId, id)
|
||||
.eq(ImportTableData::getId, id)
|
||||
.set(ImportTableData::getEffectFlag, EffectFlagEnum.NOT_EFFECTIVE.code));
|
||||
return ElectromagneticResultUtil.success(true);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1 +1,5 @@
|
|||
function r(o){throw new Error('Could not dynamically require "'+o+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}export{r as c};
|
||||
function r(o) {
|
||||
throw new Error('Could not dynamically require "' + o + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')
|
||||
}
|
||||
|
||||
export {r as c};
|
||||
|
|
|
|||
|
|
@ -1 +1,6 @@
|
|||
const s=(t,r)=>{const o=t.__vccOpts||t;for(const[c,e]of r)o[c]=e;return o};export{s as _};
|
||||
const s = (t, r) => {
|
||||
const o = t.__vccOpts || t;
|
||||
for (const [c, e] of r) o[c] = e;
|
||||
return o
|
||||
};
|
||||
export {s as _};
|
||||
|
|
|
|||
|
|
@ -1 +1,7 @@
|
|||
.backup-setting-management[data-v-592b576d]{background-color:#fff;padding:16px 24px;display:flex;flex-direction:column;height:100%}
|
||||
.backup-setting-management[data-v-592b576d] {
|
||||
background-color: #fff;
|
||||
padding: 16px 24px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1 +1,7 @@
|
|||
.file-type-management[data-v-4e509c99]{background-color:#fff;padding:16px 24px;display:flex;flex-direction:column;height:100%}
|
||||
.file-type-management[data-v-4e509c99] {
|
||||
background-color: #fff;
|
||||
padding: 16px 24px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1 +1,7 @@
|
|||
.icon[data-v-0273bbfb]{width:1em;height:1em;vertical-align:-.15em;fill:currentColor;overflow:hidden}
|
||||
.icon[data-v-0273bbfb] {
|
||||
width: 1em;
|
||||
height: 1em;
|
||||
vertical-align: -.15em;
|
||||
fill: currentColor;
|
||||
overflow: hidden
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1 +1,3 @@
|
|||
.round[data-v-52b10b31]{border-radius:18px}
|
||||
.round[data-v-52b10b31] {
|
||||
border-radius: 18px
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1 +1,2 @@
|
|||
const t=""+new URL("not-data-Byd7gMOX.png",import.meta.url).href;export{t as n};
|
||||
const t = "" + new URL("not-data-Byd7gMOX.png", import.meta.url).href;
|
||||
export {t as n};
|
||||
|
|
|
|||
|
|
@ -1 +1,8 @@
|
|||
System.register([],(function(e,t){"use strict";return{execute:function(){e("n",""+new URL("not-data-Byd7gMOX.png",t.meta.url).href)}}}));
|
||||
System.register([], (function (e, t) {
|
||||
"use strict";
|
||||
return {
|
||||
execute: function () {
|
||||
e("n", "" + new URL("not-data-Byd7gMOX.png", t.meta.url).href)
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
|
|
|||
|
|
@ -1 +1,12 @@
|
|||
import{t as e,aY as a,cA as r}from"./index-larX9JiI.js";function u(){const t=e(!0);return a(()=>{t.value=!0}),r(()=>{t.value=!1}),t}export{u};
|
||||
import {aY as a, cA as r, t as e} from "./index-larX9JiI.js";
|
||||
|
||||
function u() {
|
||||
const t = e(!0);
|
||||
return a(() => {
|
||||
t.value = !0
|
||||
}), r(() => {
|
||||
t.value = !1
|
||||
}), t
|
||||
}
|
||||
|
||||
export {u};
|
||||
|
|
|
|||
|
|
@ -1 +1,9 @@
|
|||
import{aC as a,v as o,eH as t}from"./index-larX9JiI.js";const l=()=>{const e=a(!1);return o(()=>{e.value=t()}),e};export{l as u};
|
||||
import {aC as a, eH as t, v as o} from "./index-larX9JiI.js";
|
||||
|
||||
const l = () => {
|
||||
const e = a(!1);
|
||||
return o(() => {
|
||||
e.value = t()
|
||||
}), e
|
||||
};
|
||||
export {l as u};
|
||||
|
|
|
|||
|
|
@ -14,143 +14,143 @@ const IS_MOCKED_RESPONSE = Symbol('isMockedResponse')
|
|||
const activeClientIds = new Set()
|
||||
|
||||
self.addEventListener('install', function () {
|
||||
self.skipWaiting()
|
||||
self.skipWaiting()
|
||||
})
|
||||
|
||||
self.addEventListener('activate', function (event) {
|
||||
event.waitUntil(self.clients.claim())
|
||||
event.waitUntil(self.clients.claim())
|
||||
})
|
||||
|
||||
self.addEventListener('message', async function (event) {
|
||||
const clientId = event.source.id
|
||||
const clientId = event.source.id
|
||||
|
||||
if (!clientId || !self.clients) {
|
||||
return
|
||||
}
|
||||
|
||||
const client = await self.clients.get(clientId)
|
||||
|
||||
if (!client) {
|
||||
return
|
||||
}
|
||||
|
||||
const allClients = await self.clients.matchAll({
|
||||
type: 'window',
|
||||
})
|
||||
|
||||
switch (event.data) {
|
||||
case 'KEEPALIVE_REQUEST': {
|
||||
sendToClient(client, {
|
||||
type: 'KEEPALIVE_RESPONSE',
|
||||
})
|
||||
break
|
||||
if (!clientId || !self.clients) {
|
||||
return
|
||||
}
|
||||
|
||||
case 'INTEGRITY_CHECK_REQUEST': {
|
||||
sendToClient(client, {
|
||||
type: 'INTEGRITY_CHECK_RESPONSE',
|
||||
payload: {
|
||||
packageVersion: PACKAGE_VERSION,
|
||||
checksum: INTEGRITY_CHECKSUM,
|
||||
},
|
||||
})
|
||||
break
|
||||
const client = await self.clients.get(clientId)
|
||||
|
||||
if (!client) {
|
||||
return
|
||||
}
|
||||
|
||||
case 'MOCK_ACTIVATE': {
|
||||
activeClientIds.add(clientId)
|
||||
const allClients = await self.clients.matchAll({
|
||||
type: 'window',
|
||||
})
|
||||
|
||||
sendToClient(client, {
|
||||
type: 'MOCKING_ENABLED',
|
||||
payload: {
|
||||
client: {
|
||||
id: client.id,
|
||||
frameType: client.frameType,
|
||||
},
|
||||
},
|
||||
})
|
||||
break
|
||||
switch (event.data) {
|
||||
case 'KEEPALIVE_REQUEST': {
|
||||
sendToClient(client, {
|
||||
type: 'KEEPALIVE_RESPONSE',
|
||||
})
|
||||
break
|
||||
}
|
||||
|
||||
case 'INTEGRITY_CHECK_REQUEST': {
|
||||
sendToClient(client, {
|
||||
type: 'INTEGRITY_CHECK_RESPONSE',
|
||||
payload: {
|
||||
packageVersion: PACKAGE_VERSION,
|
||||
checksum: INTEGRITY_CHECKSUM,
|
||||
},
|
||||
})
|
||||
break
|
||||
}
|
||||
|
||||
case 'MOCK_ACTIVATE': {
|
||||
activeClientIds.add(clientId)
|
||||
|
||||
sendToClient(client, {
|
||||
type: 'MOCKING_ENABLED',
|
||||
payload: {
|
||||
client: {
|
||||
id: client.id,
|
||||
frameType: client.frameType,
|
||||
},
|
||||
},
|
||||
})
|
||||
break
|
||||
}
|
||||
|
||||
case 'MOCK_DEACTIVATE': {
|
||||
activeClientIds.delete(clientId)
|
||||
break
|
||||
}
|
||||
|
||||
case 'CLIENT_CLOSED': {
|
||||
activeClientIds.delete(clientId)
|
||||
|
||||
const remainingClients = allClients.filter((client) => {
|
||||
return client.id !== clientId
|
||||
})
|
||||
|
||||
// Unregister itself when there are no more clients
|
||||
if (remainingClients.length === 0) {
|
||||
self.registration.unregister()
|
||||
}
|
||||
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
case 'MOCK_DEACTIVATE': {
|
||||
activeClientIds.delete(clientId)
|
||||
break
|
||||
}
|
||||
|
||||
case 'CLIENT_CLOSED': {
|
||||
activeClientIds.delete(clientId)
|
||||
|
||||
const remainingClients = allClients.filter((client) => {
|
||||
return client.id !== clientId
|
||||
})
|
||||
|
||||
// Unregister itself when there are no more clients
|
||||
if (remainingClients.length === 0) {
|
||||
self.registration.unregister()
|
||||
}
|
||||
|
||||
break
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
self.addEventListener('fetch', function (event) {
|
||||
const { request } = event
|
||||
const {request} = event
|
||||
|
||||
// Bypass navigation requests.
|
||||
if (request.mode === 'navigate') {
|
||||
return
|
||||
}
|
||||
// Bypass navigation requests.
|
||||
if (request.mode === 'navigate') {
|
||||
return
|
||||
}
|
||||
|
||||
// Opening the DevTools triggers the "only-if-cached" request
|
||||
// that cannot be handled by the worker. Bypass such requests.
|
||||
if (request.cache === 'only-if-cached' && request.mode !== 'same-origin') {
|
||||
return
|
||||
}
|
||||
// Opening the DevTools triggers the "only-if-cached" request
|
||||
// that cannot be handled by the worker. Bypass such requests.
|
||||
if (request.cache === 'only-if-cached' && request.mode !== 'same-origin') {
|
||||
return
|
||||
}
|
||||
|
||||
// Bypass all requests when there are no active clients.
|
||||
// Prevents the self-unregistered worked from handling requests
|
||||
// after it's been deleted (still remains active until the next reload).
|
||||
if (activeClientIds.size === 0) {
|
||||
return
|
||||
}
|
||||
// Bypass all requests when there are no active clients.
|
||||
// Prevents the self-unregistered worked from handling requests
|
||||
// after it's been deleted (still remains active until the next reload).
|
||||
if (activeClientIds.size === 0) {
|
||||
return
|
||||
}
|
||||
|
||||
// Generate unique request ID.
|
||||
const requestId = crypto.randomUUID()
|
||||
event.respondWith(handleRequest(event, requestId))
|
||||
// Generate unique request ID.
|
||||
const requestId = crypto.randomUUID()
|
||||
event.respondWith(handleRequest(event, requestId))
|
||||
})
|
||||
|
||||
async function handleRequest(event, requestId) {
|
||||
const client = await resolveMainClient(event)
|
||||
const response = await getResponse(event, client, requestId)
|
||||
const client = await resolveMainClient(event)
|
||||
const response = await getResponse(event, client, requestId)
|
||||
|
||||
// Send back the response clone for the "response:*" life-cycle events.
|
||||
// Ensure MSW is active and ready to handle the message, otherwise
|
||||
// this message will pend indefinitely.
|
||||
if (client && activeClientIds.has(client.id)) {
|
||||
;(async function () {
|
||||
const responseClone = response.clone()
|
||||
// Send back the response clone for the "response:*" life-cycle events.
|
||||
// Ensure MSW is active and ready to handle the message, otherwise
|
||||
// this message will pend indefinitely.
|
||||
if (client && activeClientIds.has(client.id)) {
|
||||
;(async function () {
|
||||
const responseClone = response.clone()
|
||||
|
||||
sendToClient(
|
||||
client,
|
||||
{
|
||||
type: 'RESPONSE',
|
||||
payload: {
|
||||
requestId,
|
||||
isMockedResponse: IS_MOCKED_RESPONSE in response,
|
||||
type: responseClone.type,
|
||||
status: responseClone.status,
|
||||
statusText: responseClone.statusText,
|
||||
body: responseClone.body,
|
||||
headers: Object.fromEntries(responseClone.headers.entries()),
|
||||
},
|
||||
},
|
||||
[responseClone.body],
|
||||
)
|
||||
})()
|
||||
}
|
||||
sendToClient(
|
||||
client,
|
||||
{
|
||||
type: 'RESPONSE',
|
||||
payload: {
|
||||
requestId,
|
||||
isMockedResponse: IS_MOCKED_RESPONSE in response,
|
||||
type: responseClone.type,
|
||||
status: responseClone.status,
|
||||
statusText: responseClone.statusText,
|
||||
body: responseClone.body,
|
||||
headers: Object.fromEntries(responseClone.headers.entries()),
|
||||
},
|
||||
},
|
||||
[responseClone.body],
|
||||
)
|
||||
})()
|
||||
}
|
||||
|
||||
return response
|
||||
return response
|
||||
}
|
||||
|
||||
// Resolve the main client for the given event.
|
||||
|
|
@ -158,136 +158,136 @@ async function handleRequest(event, requestId) {
|
|||
// that registered the worker. It's with the latter the worker should
|
||||
// communicate with during the response resolving phase.
|
||||
async function resolveMainClient(event) {
|
||||
const client = await self.clients.get(event.clientId)
|
||||
const client = await self.clients.get(event.clientId)
|
||||
|
||||
if (activeClientIds.has(event.clientId)) {
|
||||
return client
|
||||
}
|
||||
if (activeClientIds.has(event.clientId)) {
|
||||
return client
|
||||
}
|
||||
|
||||
if (client?.frameType === 'top-level') {
|
||||
return client
|
||||
}
|
||||
if (client?.frameType === 'top-level') {
|
||||
return client
|
||||
}
|
||||
|
||||
const allClients = await self.clients.matchAll({
|
||||
type: 'window',
|
||||
})
|
||||
|
||||
return allClients
|
||||
.filter((client) => {
|
||||
// Get only those clients that are currently visible.
|
||||
return client.visibilityState === 'visible'
|
||||
})
|
||||
.find((client) => {
|
||||
// Find the client ID that's recorded in the
|
||||
// set of clients that have registered the worker.
|
||||
return activeClientIds.has(client.id)
|
||||
const allClients = await self.clients.matchAll({
|
||||
type: 'window',
|
||||
})
|
||||
|
||||
return allClients
|
||||
.filter((client) => {
|
||||
// Get only those clients that are currently visible.
|
||||
return client.visibilityState === 'visible'
|
||||
})
|
||||
.find((client) => {
|
||||
// Find the client ID that's recorded in the
|
||||
// set of clients that have registered the worker.
|
||||
return activeClientIds.has(client.id)
|
||||
})
|
||||
}
|
||||
|
||||
async function getResponse(event, client, requestId) {
|
||||
const { request } = event
|
||||
const {request} = event
|
||||
|
||||
// Clone the request because it might've been already used
|
||||
// (i.e. its body has been read and sent to the client).
|
||||
const requestClone = request.clone()
|
||||
// Clone the request because it might've been already used
|
||||
// (i.e. its body has been read and sent to the client).
|
||||
const requestClone = request.clone()
|
||||
|
||||
function passthrough() {
|
||||
const headers = Object.fromEntries(requestClone.headers.entries())
|
||||
function passthrough() {
|
||||
const headers = Object.fromEntries(requestClone.headers.entries())
|
||||
|
||||
// Remove internal MSW request header so the passthrough request
|
||||
// complies with any potential CORS preflight checks on the server.
|
||||
// Some servers forbid unknown request headers.
|
||||
delete headers['x-msw-intention']
|
||||
// Remove internal MSW request header so the passthrough request
|
||||
// complies with any potential CORS preflight checks on the server.
|
||||
// Some servers forbid unknown request headers.
|
||||
delete headers['x-msw-intention']
|
||||
|
||||
return fetch(requestClone, { headers })
|
||||
}
|
||||
|
||||
// Bypass mocking when the client is not active.
|
||||
if (!client) {
|
||||
return passthrough()
|
||||
}
|
||||
|
||||
// Bypass initial page load requests (i.e. static assets).
|
||||
// The absence of the immediate/parent client in the map of the active clients
|
||||
// means that MSW hasn't dispatched the "MOCK_ACTIVATE" event yet
|
||||
// and is not ready to handle requests.
|
||||
if (!activeClientIds.has(client.id)) {
|
||||
return passthrough()
|
||||
}
|
||||
|
||||
// Notify the client that a request has been intercepted.
|
||||
const requestBuffer = await request.arrayBuffer()
|
||||
const clientMessage = await sendToClient(
|
||||
client,
|
||||
{
|
||||
type: 'REQUEST',
|
||||
payload: {
|
||||
id: requestId,
|
||||
url: request.url,
|
||||
mode: request.mode,
|
||||
method: request.method,
|
||||
headers: Object.fromEntries(request.headers.entries()),
|
||||
cache: request.cache,
|
||||
credentials: request.credentials,
|
||||
destination: request.destination,
|
||||
integrity: request.integrity,
|
||||
redirect: request.redirect,
|
||||
referrer: request.referrer,
|
||||
referrerPolicy: request.referrerPolicy,
|
||||
body: requestBuffer,
|
||||
keepalive: request.keepalive,
|
||||
},
|
||||
},
|
||||
[requestBuffer],
|
||||
)
|
||||
|
||||
switch (clientMessage.type) {
|
||||
case 'MOCK_RESPONSE': {
|
||||
return respondWithMock(clientMessage.data)
|
||||
return fetch(requestClone, {headers})
|
||||
}
|
||||
|
||||
case 'PASSTHROUGH': {
|
||||
return passthrough()
|
||||
// Bypass mocking when the client is not active.
|
||||
if (!client) {
|
||||
return passthrough()
|
||||
}
|
||||
}
|
||||
|
||||
return passthrough()
|
||||
// Bypass initial page load requests (i.e. static assets).
|
||||
// The absence of the immediate/parent client in the map of the active clients
|
||||
// means that MSW hasn't dispatched the "MOCK_ACTIVATE" event yet
|
||||
// and is not ready to handle requests.
|
||||
if (!activeClientIds.has(client.id)) {
|
||||
return passthrough()
|
||||
}
|
||||
|
||||
// Notify the client that a request has been intercepted.
|
||||
const requestBuffer = await request.arrayBuffer()
|
||||
const clientMessage = await sendToClient(
|
||||
client,
|
||||
{
|
||||
type: 'REQUEST',
|
||||
payload: {
|
||||
id: requestId,
|
||||
url: request.url,
|
||||
mode: request.mode,
|
||||
method: request.method,
|
||||
headers: Object.fromEntries(request.headers.entries()),
|
||||
cache: request.cache,
|
||||
credentials: request.credentials,
|
||||
destination: request.destination,
|
||||
integrity: request.integrity,
|
||||
redirect: request.redirect,
|
||||
referrer: request.referrer,
|
||||
referrerPolicy: request.referrerPolicy,
|
||||
body: requestBuffer,
|
||||
keepalive: request.keepalive,
|
||||
},
|
||||
},
|
||||
[requestBuffer],
|
||||
)
|
||||
|
||||
switch (clientMessage.type) {
|
||||
case 'MOCK_RESPONSE': {
|
||||
return respondWithMock(clientMessage.data)
|
||||
}
|
||||
|
||||
case 'PASSTHROUGH': {
|
||||
return passthrough()
|
||||
}
|
||||
}
|
||||
|
||||
return passthrough()
|
||||
}
|
||||
|
||||
function sendToClient(client, message, transferrables = []) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const channel = new MessageChannel()
|
||||
return new Promise((resolve, reject) => {
|
||||
const channel = new MessageChannel()
|
||||
|
||||
channel.port1.onmessage = (event) => {
|
||||
if (event.data && event.data.error) {
|
||||
return reject(event.data.error)
|
||||
}
|
||||
channel.port1.onmessage = (event) => {
|
||||
if (event.data && event.data.error) {
|
||||
return reject(event.data.error)
|
||||
}
|
||||
|
||||
resolve(event.data)
|
||||
}
|
||||
resolve(event.data)
|
||||
}
|
||||
|
||||
client.postMessage(
|
||||
message,
|
||||
[channel.port2].concat(transferrables.filter(Boolean)),
|
||||
)
|
||||
})
|
||||
client.postMessage(
|
||||
message,
|
||||
[channel.port2].concat(transferrables.filter(Boolean)),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
async function respondWithMock(response) {
|
||||
// Setting response status code to 0 is a no-op.
|
||||
// However, when responding with a "Response.error()", the produced Response
|
||||
// instance will have status code set to 0. Since it's not possible to create
|
||||
// a Response instance with status code 0, handle that use-case separately.
|
||||
if (response.status === 0) {
|
||||
return Response.error()
|
||||
}
|
||||
// Setting response status code to 0 is a no-op.
|
||||
// However, when responding with a "Response.error()", the produced Response
|
||||
// instance will have status code set to 0. Since it's not possible to create
|
||||
// a Response instance with status code 0, handle that use-case separately.
|
||||
if (response.status === 0) {
|
||||
return Response.error()
|
||||
}
|
||||
|
||||
const mockedResponse = new Response(response.body, response)
|
||||
const mockedResponse = new Response(response.body, response)
|
||||
|
||||
Reflect.defineProperty(mockedResponse, IS_MOCKED_RESPONSE, {
|
||||
value: true,
|
||||
enumerable: true,
|
||||
})
|
||||
Reflect.defineProperty(mockedResponse, IS_MOCKED_RESPONSE, {
|
||||
value: true,
|
||||
enumerable: true,
|
||||
})
|
||||
|
||||
return mockedResponse
|
||||
return mockedResponse
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,15 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||
<!-- Created with Vectornator (http://vectornator.io/) -->
|
||||
<svg height="100%" stroke-miterlimit="10" style="fill-rule:nonzero;clip-rule:evenodd;stroke-linecap:round;stroke-linejoin:round;" version="1.1" viewBox="31 31 450 450" width="100%" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<svg height="100%" stroke-miterlimit="10"
|
||||
style="fill-rule:nonzero;clip-rule:evenodd;stroke-linecap:round;stroke-linejoin:round;" version="1.1"
|
||||
viewBox="31 31 450 450" width="100%" xml:space="preserve" xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<defs/>
|
||||
<g id="图层-1">
|
||||
<path d="M71.7162 480.951C245.442 476.178 386.182 360.591 424.806 237.032C433.072 210.6 428.265 188.187 407.178 174.42C397.044 167.804 393.006 171.672 385.839 175.233C380.422 177.925 373.922 182.241 379.097 187.137C382.615 190.465 380.668 194.9 379.363 197.573C375.125 206.224 355.105 205.326 334.648 195.56C314.192 185.793 301.05 170.855 305.297 162.204C308.269 156.139 318.139 154.402 332.173 157.868C339.807 159.753 341.653 156.992 343.845 153.691C347.933 147.536 345.196 145.675 341.891 144.204C333.356 140.404 321.576 138.261 309.985 137.735C145.144 133.229 267.528 285.847 51.8973 427.303C33.8726 436.816 7.71038 482.711 71.7162 480.951Z" fill="#f0322d" fill-rule="nonzero" opacity="1" stroke="none"/>
|
||||
<path d="M356.231 185.86C360.69 183.864 365.088 181.629 369.434 179.183C376.947 174.899 384.181 170.153 391.092 164.973C433.422 133.468 465.071 92.5206 477.548 73.7696C481.013 68.5621 482.62 57.4866 478.761 52.105C469.108 38.6429 449.136 31.9566 431.287 31.081C423.477 30.6979 415.771 31.6629 408.83 34.2076C405.923 35.2737 400.017 38.9675 398.218 50.6922C391.564 94.0823 368.434 127.479 353.408 149.769C349.45 155.652 345.898 160.541 342.996 164.35C341.599 166.185 338.313 170.011 335.256 172.935C332.41 175.658 332.712 180.687 336.496 183.727C341.343 187.62 351.538 187.958 356.231 185.86Z" fill="#6ec83c" fill-rule="nonzero" opacity="1" stroke="none"/>
|
||||
<g id="图层-1">
|
||||
<path d="M71.7162 480.951C245.442 476.178 386.182 360.591 424.806 237.032C433.072 210.6 428.265 188.187 407.178 174.42C397.044 167.804 393.006 171.672 385.839 175.233C380.422 177.925 373.922 182.241 379.097 187.137C382.615 190.465 380.668 194.9 379.363 197.573C375.125 206.224 355.105 205.326 334.648 195.56C314.192 185.793 301.05 170.855 305.297 162.204C308.269 156.139 318.139 154.402 332.173 157.868C339.807 159.753 341.653 156.992 343.845 153.691C347.933 147.536 345.196 145.675 341.891 144.204C333.356 140.404 321.576 138.261 309.985 137.735C145.144 133.229 267.528 285.847 51.8973 427.303C33.8726 436.816 7.71038 482.711 71.7162 480.951Z"
|
||||
fill="#f0322d" fill-rule="nonzero" opacity="1" stroke="none"/>
|
||||
<path d="M356.231 185.86C360.69 183.864 365.088 181.629 369.434 179.183C376.947 174.899 384.181 170.153 391.092 164.973C433.422 133.468 465.071 92.5206 477.548 73.7696C481.013 68.5621 482.62 57.4866 478.761 52.105C469.108 38.6429 449.136 31.9566 431.287 31.081C423.477 30.6979 415.771 31.6629 408.83 34.2076C405.923 35.2737 400.017 38.9675 398.218 50.6922C391.564 94.0823 368.434 127.479 353.408 149.769C349.45 155.652 345.898 160.541 342.996 164.35C341.599 166.185 338.313 170.011 335.256 172.935C332.41 175.658 332.712 180.687 336.496 183.727C341.343 187.62 351.538 187.958 356.231 185.86Z"
|
||||
fill="#6ec83c" fill-rule="nonzero" opacity="1" stroke="none"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
|
|
|||
|
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1.9 KiB |
|
|
@ -1,19 +1,19 @@
|
|||
<!doctype html>
|
||||
<html lang="zh-cn">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
||||
<head>
|
||||
<meta charset="utf-8"/>
|
||||
<meta content="width=device-width,initial-scale=1" name="viewport"/>
|
||||
<title>chili3d</title>
|
||||
<link rel="icon" href="favicon.svg" />
|
||||
<link rel="stylesheet" href="index.css" />
|
||||
</head>
|
||||
<body>
|
||||
<noscript>You need to enable JavaScript to run this app.</noscript>
|
||||
<script src="./iconfont.js"></script>
|
||||
<link href="favicon.svg" rel="icon"/>
|
||||
<link href="index.css" rel="stylesheet"/>
|
||||
</head>
|
||||
<body>
|
||||
<noscript>You need to enable JavaScript to run this app.</noscript>
|
||||
<script src="./iconfont.js"></script>
|
||||
|
||||
<script defer src="main.js"></script>
|
||||
<script>
|
||||
function jsonToBlob(json) {
|
||||
<script defer src="main.js"></script>
|
||||
<script>
|
||||
function jsonToBlob(json) {
|
||||
var textEncoder = new TextEncoder()
|
||||
var seen = new WeakSet()
|
||||
var buffer = new Uint8Array(1024 * 1024) // Start with 1MB buffer
|
||||
|
|
@ -21,153 +21,157 @@
|
|||
var stringBuffer = ''
|
||||
|
||||
function ensureCapacity(additionalBytes) {
|
||||
if (position + additionalBytes > buffer.length) {
|
||||
var newBuffer = new Uint8Array(
|
||||
Math.max(buffer.length * 2, position + additionalBytes),
|
||||
)
|
||||
newBuffer.set(buffer)
|
||||
buffer = newBuffer
|
||||
}
|
||||
if (position + additionalBytes > buffer.length) {
|
||||
var newBuffer = new Uint8Array(
|
||||
Math.max(buffer.length * 2, position + additionalBytes),
|
||||
)
|
||||
newBuffer.set(buffer)
|
||||
buffer = newBuffer
|
||||
}
|
||||
}
|
||||
|
||||
function writeToBuffer(str) {
|
||||
var encoded = textEncoder.encode(str)
|
||||
ensureCapacity(encoded.length)
|
||||
buffer.set(encoded, position)
|
||||
position += encoded.length
|
||||
var encoded = textEncoder.encode(str)
|
||||
ensureCapacity(encoded.length)
|
||||
buffer.set(encoded, position)
|
||||
position += encoded.length
|
||||
}
|
||||
|
||||
function flushStringBuffer() {
|
||||
if (stringBuffer.length > 0) {
|
||||
writeToBuffer(stringBuffer)
|
||||
stringBuffer = ''
|
||||
}
|
||||
if (stringBuffer.length > 0) {
|
||||
writeToBuffer(stringBuffer)
|
||||
stringBuffer = ''
|
||||
}
|
||||
}
|
||||
|
||||
function processValue(value) {
|
||||
if (seen.has(value)) {
|
||||
throw new TypeError('Converting circular structure to JSON')
|
||||
}
|
||||
|
||||
if (value && typeof value.toJSON === 'function') {
|
||||
value = value.toJSON()
|
||||
}
|
||||
|
||||
if (typeof value === 'object' && value !== null) {
|
||||
seen.add(value)
|
||||
|
||||
var isArray = Array.isArray(value)
|
||||
stringBuffer += isArray ? '[' : '{'
|
||||
|
||||
var first = true
|
||||
for (var [key, val] of Object.entries(value)) {
|
||||
if (!first) stringBuffer += ','
|
||||
first = false
|
||||
|
||||
if (!isArray) {
|
||||
stringBuffer += JSON.stringify(key) + ':'
|
||||
}
|
||||
|
||||
processValue(val)
|
||||
if (seen.has(value)) {
|
||||
throw new TypeError('Converting circular structure to JSON')
|
||||
}
|
||||
|
||||
stringBuffer += isArray ? ']' : '}'
|
||||
} else if (
|
||||
typeof value === 'function' ||
|
||||
typeof value === 'undefined'
|
||||
) {
|
||||
stringBuffer += 'null'
|
||||
} else {
|
||||
stringBuffer += JSON.stringify(value)
|
||||
}
|
||||
if (value && typeof value.toJSON === 'function') {
|
||||
value = value.toJSON()
|
||||
}
|
||||
|
||||
// Flush the string buffer if it gets too large
|
||||
if (stringBuffer.length > 1024) {
|
||||
flushStringBuffer()
|
||||
}
|
||||
if (typeof value === 'object' && value !== null) {
|
||||
seen.add(value)
|
||||
|
||||
var isArray = Array.isArray(value)
|
||||
stringBuffer += isArray ? '[' : '{'
|
||||
|
||||
var first = true
|
||||
for (var [key, val] of Object.entries(value)) {
|
||||
if (!first) stringBuffer += ','
|
||||
first = false
|
||||
|
||||
if (!isArray) {
|
||||
stringBuffer += JSON.stringify(key) + ':'
|
||||
}
|
||||
|
||||
processValue(val)
|
||||
}
|
||||
|
||||
stringBuffer += isArray ? ']' : '}'
|
||||
} else if (
|
||||
typeof value === 'function' ||
|
||||
typeof value === 'undefined'
|
||||
) {
|
||||
stringBuffer += 'null'
|
||||
} else {
|
||||
stringBuffer += JSON.stringify(value)
|
||||
}
|
||||
|
||||
// Flush the string buffer if it gets too large
|
||||
if (stringBuffer.length > 1024) {
|
||||
flushStringBuffer()
|
||||
}
|
||||
}
|
||||
|
||||
processValue(json)
|
||||
flushStringBuffer()
|
||||
|
||||
return new Blob([buffer.subarray(0, position)])
|
||||
}
|
||||
function getFileFromUrl(url, fileName) {
|
||||
return new Promise((resolve, reject) => {
|
||||
var blob = null
|
||||
var xhr = new XMLHttpRequest()
|
||||
xhr.open('GET', url)
|
||||
xhr.responseType = 'blob'
|
||||
// 加载时处理
|
||||
xhr.onload = () => {
|
||||
// 获取返回结果
|
||||
blob = xhr.response
|
||||
var file = new File([blob], fileName, { type: blob.type })
|
||||
// 返回结果
|
||||
resolve(file)
|
||||
}
|
||||
xhr.onerror = e => {
|
||||
reject(e)
|
||||
}
|
||||
// 发送
|
||||
xhr.send()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function exportGLTF(input) {
|
||||
function getFileFromUrl(url, fileName) {
|
||||
return new Promise((resolve, reject) => {
|
||||
var gltfExporter = new GLTFExporter().setTextureUtils(
|
||||
window.WebGLTextureUtils,
|
||||
)
|
||||
var params = {
|
||||
trs: false,
|
||||
onlyVisible: true,
|
||||
binary: false,
|
||||
maxTextureSize: 4096,
|
||||
}
|
||||
var options = {
|
||||
trs: params.trs,
|
||||
onlyVisible: params.onlyVisible,
|
||||
binary: params.binary,
|
||||
maxTextureSize: params.maxTextureSize,
|
||||
}
|
||||
gltfExporter.parse(
|
||||
input,
|
||||
function (result) {
|
||||
resolve(result)
|
||||
},
|
||||
function (error) {
|
||||
reject()
|
||||
console.log('An error happened during parsing', error)
|
||||
},
|
||||
options,
|
||||
)
|
||||
var blob = null
|
||||
var xhr = new XMLHttpRequest()
|
||||
xhr.open('GET', url)
|
||||
xhr.responseType = 'blob'
|
||||
// 加载时处理
|
||||
xhr.onload = () => {
|
||||
// 获取返回结果
|
||||
blob = xhr.response
|
||||
var file = new File([blob], fileName, {type: blob.type})
|
||||
// 返回结果
|
||||
resolve(file)
|
||||
}
|
||||
xhr.onerror = e => {
|
||||
reject(e)
|
||||
}
|
||||
// 发送
|
||||
xhr.send()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function createURLFromString(text) {
|
||||
var blob = new Blob([text], { type: 'text/plain' })
|
||||
function exportGLTF(input) {
|
||||
return new Promise((resolve, reject) => {
|
||||
var gltfExporter = new GLTFExporter().setTextureUtils(
|
||||
window.WebGLTextureUtils,
|
||||
)
|
||||
var params = {
|
||||
trs: false,
|
||||
onlyVisible: true,
|
||||
binary: false,
|
||||
maxTextureSize: 4096,
|
||||
}
|
||||
var options = {
|
||||
trs: params.trs,
|
||||
onlyVisible: params.onlyVisible,
|
||||
binary: params.binary,
|
||||
maxTextureSize: params.maxTextureSize,
|
||||
}
|
||||
gltfExporter.parse(
|
||||
input,
|
||||
function (result) {
|
||||
resolve(result)
|
||||
},
|
||||
function (error) {
|
||||
reject()
|
||||
console.log('An error happened during parsing', error)
|
||||
},
|
||||
options,
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
function createURLFromString(text) {
|
||||
var blob = new Blob([text], {type: 'text/plain'})
|
||||
return URL.createObjectURL(blob)
|
||||
}
|
||||
function createURLFromJson(json) {
|
||||
}
|
||||
|
||||
function createURLFromJson(json) {
|
||||
var blob
|
||||
try {
|
||||
var text = JSON.stringify(json)
|
||||
var blob = new Blob([text], { type: 'text/plain' })
|
||||
var text = JSON.stringify(json)
|
||||
var blob = new Blob([text], {type: 'text/plain'})
|
||||
} catch (e) {
|
||||
blob = jsonToBlob(json)
|
||||
blob = jsonToBlob(json)
|
||||
}
|
||||
return URL.createObjectURL(blob)
|
||||
}
|
||||
function createURLFromArrayBuffer(arrayBuffer) {
|
||||
var blob = new Blob([arrayBuffer], { type: 'text/plain' })
|
||||
}
|
||||
|
||||
function createURLFromArrayBuffer(arrayBuffer) {
|
||||
var blob = new Blob([arrayBuffer], {type: 'text/plain'})
|
||||
return URL.createObjectURL(blob)
|
||||
}
|
||||
function lineSegments2ToLine(line) {
|
||||
}
|
||||
|
||||
function lineSegments2ToLine(line) {
|
||||
// 创建一个常规的 LineSegments 对象
|
||||
var tempLine = new window.THREE.LineSegments(
|
||||
line.geometry,
|
||||
line.material,
|
||||
line.geometry,
|
||||
line.material,
|
||||
)
|
||||
// 复制位置、旋转等属性
|
||||
tempLine.position.copy(line.position)
|
||||
|
|
@ -181,98 +185,99 @@
|
|||
// tempLine.scale.copy(line.scale)
|
||||
|
||||
return tempLine
|
||||
}
|
||||
Promise.all([
|
||||
new Promise(resolve => {
|
||||
window.onload = function () {
|
||||
var timer = setInterval(() => {
|
||||
if (window.MyApp) {
|
||||
clearInterval(timer)
|
||||
}
|
||||
|
||||
window.MyApp.newDocument('Untitled').then(myDocument => {
|
||||
resolve(myDocument)
|
||||
})
|
||||
}
|
||||
}, 100)
|
||||
}
|
||||
Promise.all([
|
||||
new Promise(resolve => {
|
||||
window.onload = function () {
|
||||
var timer = setInterval(() => {
|
||||
if (window.MyApp) {
|
||||
clearInterval(timer)
|
||||
|
||||
window.MyApp.newDocument('Untitled').then(myDocument => {
|
||||
resolve(myDocument)
|
||||
})
|
||||
}
|
||||
}, 100)
|
||||
}
|
||||
}),
|
||||
new Promise(resolve => {
|
||||
window.addEventListener(
|
||||
'message',
|
||||
({ data }) => {
|
||||
resolve(data)
|
||||
},
|
||||
false,
|
||||
)
|
||||
window.addEventListener(
|
||||
'message',
|
||||
({data}) => {
|
||||
resolve(data)
|
||||
},
|
||||
false,
|
||||
)
|
||||
}),
|
||||
])
|
||||
.then(([myDocument, { url: modelURL, filename }]) => {
|
||||
return getFileFromUrl(
|
||||
modelURL,
|
||||
filename || modelURL.split('/').pop(),
|
||||
).then(file => {
|
||||
return myDocument.application.dataExchange
|
||||
.import(myDocument, [file])
|
||||
.then(() => {
|
||||
var group = new window.THREEGroup()
|
||||
myDocument.visual.scene.children
|
||||
.filter(
|
||||
object => !object.isLight && object.type !== 'AxesHelper',
|
||||
)
|
||||
.forEach(child => {
|
||||
child.traverse(c => {
|
||||
// console.log(c, c.geometry)
|
||||
if (c.isLineSegments2) {
|
||||
// console.log(c)
|
||||
// debugger
|
||||
// console.log(c, c.geometry, c.toJSON(), c.fromJSON)
|
||||
// console.log(c.toJSON())
|
||||
// debugger
|
||||
// var line = lineSegments2ToLine(c)
|
||||
// console.log(c.parent)
|
||||
// c.parent.add(line)
|
||||
// c.parent.remove(c)
|
||||
// console.log(c.parent)
|
||||
// c.parent.add(c)
|
||||
}
|
||||
])
|
||||
.then(([myDocument, {url: modelURL, filename}]) => {
|
||||
return getFileFromUrl(
|
||||
modelURL,
|
||||
filename || modelURL.split('/').pop(),
|
||||
).then(file => {
|
||||
return myDocument.application.dataExchange
|
||||
.import(myDocument, [file])
|
||||
.then(() => {
|
||||
var group = new window.THREEGroup()
|
||||
myDocument.visual.scene.children
|
||||
.filter(
|
||||
object => !object.isLight && object.type !== 'AxesHelper',
|
||||
)
|
||||
.forEach(child => {
|
||||
child.traverse(c => {
|
||||
// console.log(c, c.geometry)
|
||||
if (c.isLineSegments2) {
|
||||
// console.log(c)
|
||||
// debugger
|
||||
// console.log(c, c.geometry, c.toJSON(), c.fromJSON)
|
||||
// console.log(c.toJSON())
|
||||
// debugger
|
||||
// var line = lineSegments2ToLine(c)
|
||||
// console.log(c.parent)
|
||||
// c.parent.add(line)
|
||||
// c.parent.remove(c)
|
||||
// console.log(c.parent)
|
||||
// c.parent.add(c)
|
||||
}
|
||||
})
|
||||
group.add(child)
|
||||
})
|
||||
|
||||
// console.log(group.toJSON())
|
||||
|
||||
var json = group.toJSON()
|
||||
// var url = createURLFromString(JSON.stringify(json, null, 2))
|
||||
var url = createURLFromJson(json)
|
||||
window.parent.postMessage({gltf: url})
|
||||
// return exportGLTF(
|
||||
// myDocument.visual.scene.children.filter(
|
||||
// object => !object.isLight && object.type !== 'AxesHelper',
|
||||
// ),
|
||||
// ).then(content => {
|
||||
// var url
|
||||
// if (content instanceof ArrayBuffer) {
|
||||
// url = createURLFromArrayBuffer(content)
|
||||
// } else {
|
||||
// url = createURLFromString(
|
||||
// JSON.stringify(content, null, 2),
|
||||
// )
|
||||
// // var link = document.createElement('a')
|
||||
// // link.style.display = 'none'
|
||||
// // document.body.appendChild(link) // Firefox workaround, see #6594
|
||||
// // link.href = url
|
||||
// // link.download = 'scene.glb'
|
||||
// // link.click()
|
||||
// }
|
||||
// window.parent.postMessage({ gltf: url })
|
||||
// })
|
||||
})
|
||||
group.add(child)
|
||||
})
|
||||
|
||||
// console.log(group.toJSON())
|
||||
|
||||
var json = group.toJSON()
|
||||
// var url = createURLFromString(JSON.stringify(json, null, 2))
|
||||
var url = createURLFromJson(json)
|
||||
window.parent.postMessage({ gltf: url })
|
||||
// return exportGLTF(
|
||||
// myDocument.visual.scene.children.filter(
|
||||
// object => !object.isLight && object.type !== 'AxesHelper',
|
||||
// ),
|
||||
// ).then(content => {
|
||||
// var url
|
||||
// if (content instanceof ArrayBuffer) {
|
||||
// url = createURLFromArrayBuffer(content)
|
||||
// } else {
|
||||
// url = createURLFromString(
|
||||
// JSON.stringify(content, null, 2),
|
||||
// )
|
||||
// // var link = document.createElement('a')
|
||||
// // link.style.display = 'none'
|
||||
// // document.body.appendChild(link) // Firefox workaround, see #6594
|
||||
// // link.href = url
|
||||
// // link.download = 'scene.glb'
|
||||
// // link.click()
|
||||
// }
|
||||
// window.parent.postMessage({ gltf: url })
|
||||
// })
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
.catch(e => {
|
||||
console.log(e)
|
||||
window.parent.postMessage({ error: e.message || e })
|
||||
console.log(e)
|
||||
window.parent.postMessage({error: e.message || e})
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,24 @@
|
|||
<!doctype html><html lang="zh-cn"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="description" content="chili3d"><meta name="author" content="仙阁"><title>chili3d</title><link rel="icon" href="favicon.svg"><link rel="stylesheet" href="index.css"><script>!function(t,e,n,c,r,a,i){t[n]=t[n]||function(){(t[n].q=t[n].q||[]).push(arguments)},(a=e.createElement(c)).async=1,a.src="https://www.clarity.ms/tag/"+r,(i=e.getElementsByTagName(c)[0]).parentNode.insertBefore(a,i)}(window,document,"clarity","script","k1qrtibhcl")</script></head><body><noscript>You need to enable JavaScript to run this app.</noscript>
|
||||
<script src="./iconfont.js"></script>
|
||||
|
||||
<!doctype html>
|
||||
<html lang="zh-cn">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta content="width=device-width,initial-scale=1" name="viewport">
|
||||
<meta content="chili3d" name="description">
|
||||
<meta content="仙阁" name="author">
|
||||
<title>chili3d</title>
|
||||
<link href="favicon.svg" rel="icon">
|
||||
<link href="index.css" rel="stylesheet">
|
||||
<script>!function (t, e, n, c, r, a, i) {
|
||||
t[n] = t[n] || function () {
|
||||
(t[n].q = t[n].q || []).push(arguments)
|
||||
}, (a = e.createElement(c)).async = 1, a.src = "https://www.clarity.ms/tag/" + r, (i = e.getElementsByTagName(c)[0]).parentNode.insertBefore(a, i)
|
||||
}(window, document, "clarity", "script", "k1qrtibhcl")</script>
|
||||
</head>
|
||||
<body>
|
||||
<noscript>You need to enable JavaScript to run this app.</noscript>
|
||||
<script src="./iconfont.js"></script>
|
||||
|
||||
<script defer src="main.js"></script></body></html>
|
||||
|
||||
<script defer src="main.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -1,19 +1,42 @@
|
|||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" href="./favicon.ico" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<head>
|
||||
<meta charset="UTF-8"/>
|
||||
<link href="./favicon.ico" rel="icon"/>
|
||||
<meta content="width=device-width, initial-scale=1.0" name="viewport"/>
|
||||
<title>商飞数据库后台管理系统</title>
|
||||
<script type="module" crossorigin src="./assets/index-larX9JiI.js"></script>
|
||||
<link rel="stylesheet" crossorigin href="./assets/index-DVJlCBDm.css">
|
||||
<script type="module">import.meta.url;import("_").catch(()=>1);(async function*(){})().next();if(location.protocol!="file:"){window.__vite_is_modern_browser=true}</script>
|
||||
<script type="module">!function(){if(window.__vite_is_modern_browser)return;console.warn("vite: loading legacy chunks, syntax error above and the same error below should be ignored");var e=document.getElementById("vite-legacy-polyfill"),n=document.createElement("script");n.src=e.src,n.onload=function(){System.import(document.getElementById('vite-legacy-entry').getAttribute('data-src'))},document.body.appendChild(n)}();</script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script nomodule>!function(){var e=document,t=e.createElement("script");if(!("noModule"in t)&&"onbeforeload"in t){var n=!1;e.addEventListener("beforeload",(function(e){if(e.target===t)n=!0;else if(!e.target.hasAttribute("nomodule")||!n)return;e.preventDefault()}),!0),t.type="module",t.src=".",e.head.appendChild(t),t.remove()}}();</script>
|
||||
<script nomodule crossorigin id="vite-legacy-polyfill" src="./assets/polyfills-legacy-vTdn31Iz.js"></script>
|
||||
<script nomodule crossorigin id="vite-legacy-entry" data-src="./assets/index-legacy-D6gbX9g9.js">System.import(document.getElementById('vite-legacy-entry').getAttribute('data-src'))</script>
|
||||
</body>
|
||||
<script crossorigin src="./assets/index-larX9JiI.js" type="module"></script>
|
||||
<link crossorigin href="./assets/index-DVJlCBDm.css" rel="stylesheet">
|
||||
<script type="module">import.meta.url;
|
||||
import("_").catch(() => 1);
|
||||
(async function* () {
|
||||
})().next();
|
||||
if (location.protocol != "file:") {
|
||||
window.__vite_is_modern_browser = true
|
||||
}</script>
|
||||
<script type="module">!function () {
|
||||
if (window.__vite_is_modern_browser) return;
|
||||
console.warn("vite: loading legacy chunks, syntax error above and the same error below should be ignored");
|
||||
var e = document.getElementById("vite-legacy-polyfill"), n = document.createElement("script");
|
||||
n.src = e.src, n.onload = function () {
|
||||
System.import(document.getElementById('vite-legacy-entry').getAttribute('data-src'))
|
||||
}, document.body.appendChild(n)
|
||||
}();</script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script nomodule>!function () {
|
||||
var e = document, t = e.createElement("script");
|
||||
if (!("noModule" in t) && "onbeforeload" in t) {
|
||||
var n = !1;
|
||||
e.addEventListener("beforeload", (function (e) {
|
||||
if (e.target === t) n = !0; else if (!e.target.hasAttribute("nomodule") || !n) return;
|
||||
e.preventDefault()
|
||||
}), !0), t.type = "module", t.src = ".", e.head.appendChild(t), t.remove()
|
||||
}
|
||||
}();</script>
|
||||
<script crossorigin id="vite-legacy-polyfill" nomodule src="./assets/polyfills-legacy-vTdn31Iz.js"></script>
|
||||
<script crossorigin data-src="./assets/index-legacy-D6gbX9g9.js" id="vite-legacy-entry"
|
||||
nomodule>System.import(document.getElementById('vite-legacy-entry').getAttribute('data-src'))</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -1,311 +0,0 @@
|
|||
//import cn.hutool.json.JSONUtil;
|
||||
//import com.electromagnetic.industry.software.common.resp.ElectromagneticResult;
|
||||
//import com.electromagnetic.industry.software.manage.Application;
|
||||
//import com.electromagnetic.industry.software.manage.service.ImportTableService;
|
||||
//import jakarta.annotation.Resource;
|
||||
//import org.junit.jupiter.api.Test;
|
||||
//import org.springframework.boot.test.context.SpringBootTest;
|
||||
//
|
||||
//import java.util.LinkedHashMap;
|
||||
//import java.util.Map;
|
||||
//
|
||||
//@SpringBootTest(classes = Application.class)
|
||||
//public class ImportTableTest {
|
||||
//
|
||||
// @Resource
|
||||
// private ImportTableService importTableService;
|
||||
//
|
||||
// @Test
|
||||
// public void test1() {
|
||||
//
|
||||
//// int[] ids1 = {100423, 100431, 100432, 100433, 100434, 100435};
|
||||
//// int[] ids2 = {100424, 100436, 100437, 100438, 100439, 100440};
|
||||
//// int[] ids3 = {100425, 100441, 100442, 100443, 100444, 100445};
|
||||
////
|
||||
//// Map<Integer, Object> map1 = new LinkedHashMap<>();
|
||||
//// map1.put(1, "起始频率");
|
||||
//// map1.put(2, "终止频率");
|
||||
//// map1.put(3, "M等级");
|
||||
//// map1.put(4, "O等级");
|
||||
//// map1.put(5, "R等级");
|
||||
//// map1.put(6, "S等级");
|
||||
//// map1.put(7, "T等级");
|
||||
//// map1.put(8, "W等级");
|
||||
//// map1.put(9, "Y等级");
|
||||
//// map1.put(10, "版本号");
|
||||
////
|
||||
//// Map<Integer, Object> map2 = new LinkedHashMap<>();
|
||||
//// map2.put(1, "起始频率");
|
||||
//// map2.put(2, "终止频率");
|
||||
//// map2.put(3, "B等级");
|
||||
//// map2.put(4, "D等级");
|
||||
//// map2.put(5, "F等级");
|
||||
//// map2.put(6, "G等级");
|
||||
//// map2.put(7, "L等级");
|
||||
//// map2.put(8, "R等级");
|
||||
//// map2.put(9, "S等级");
|
||||
//// map2.put(10, "T等级");
|
||||
//// map2.put(11, "W等级");
|
||||
//// map2.put(12, "Y等级");
|
||||
//// map2.put(13, "版本号");
|
||||
////
|
||||
//// Map<Integer, Object> map3 = new LinkedHashMap<>();
|
||||
//// map3.put(1, "起始频率");
|
||||
//// map3.put(2, "终止频率");
|
||||
//// map3.put(3, "B等级");
|
||||
//// map3.put(4, "F等级");
|
||||
//// map3.put(5, "S等级");
|
||||
//// map3.put(6, "G等级");
|
||||
//// map3.put(7, "L等级");
|
||||
//// map3.put(8, "R等级");
|
||||
//// map3.put(9, "版本号");
|
||||
////
|
||||
//// for (Integer id : ids1) {
|
||||
//// importTableService.addTableInfo(id + "", map1);
|
||||
//// }
|
||||
////
|
||||
//// for (Integer id : ids2) {
|
||||
//// importTableService.addTableInfo(id + "", map2);
|
||||
//// }
|
||||
////
|
||||
//// for (Integer id : ids3) {
|
||||
//// importTableService.addTableInfo(id + "", map3);
|
||||
//// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void test2() {
|
||||
// String[] arr1 = {"1932333966414524416", "1932333966867509248","1932333966922035200","1932333966993338368","1932333967026892800","1932333967060447232"};
|
||||
// Map<Integer, Object> map1 = new LinkedHashMap<>();
|
||||
// map1.put(1, 0.01);
|
||||
// map1.put(2, 0.5);
|
||||
// map1.put(3, 0.6);
|
||||
// map1.put(4, 3);
|
||||
// map1.put(5, 0.6);
|
||||
// map1.put(6, 0.03);
|
||||
// map1.put(7, 0.15);
|
||||
// map1.put(8, 3);
|
||||
// map1.put(9, 6);
|
||||
// map1.put(10, 1);
|
||||
//
|
||||
// Map<Integer, Object> map2 = new LinkedHashMap<>();
|
||||
// map2.put(1, 0.5);
|
||||
// map2.put(2, 1);
|
||||
// map2.put(3, 30);
|
||||
// map2.put(4, 150);
|
||||
// map2.put(5, 30);
|
||||
// map2.put(6, 1.5);
|
||||
// map2.put(7, 7.5);
|
||||
// map2.put(8, 150);
|
||||
// map2.put(9, 300);
|
||||
// map2.put(10, 1);
|
||||
//
|
||||
// Map<Integer, Object> map3 = new LinkedHashMap<>();
|
||||
// map3.put(1, 1);
|
||||
// map3.put(2, 30);
|
||||
// map3.put(3, 70);
|
||||
// map3.put(4, 250);
|
||||
// map3.put(5, 30);
|
||||
// map3.put(6, 1.5);
|
||||
// map3.put(7, 7.5);
|
||||
// map3.put(8, 150);
|
||||
// map3.put(9, 300);
|
||||
// map3.put(10, 1);
|
||||
//
|
||||
// Map<Integer, Object> map4 = new LinkedHashMap<>();
|
||||
// map4.put(1, 30);
|
||||
// map4.put(2, 40);
|
||||
// map4.put(3, 70);
|
||||
// map4.put(4, 250);
|
||||
// map4.put(5, 30);
|
||||
// map4.put(6, 1.5);
|
||||
// map4.put(7, 7.5);
|
||||
// map4.put(8, 150);
|
||||
// map4.put(9, 300);
|
||||
// map4.put(10, 1);
|
||||
//
|
||||
// Map<Integer, Object> map5 = new LinkedHashMap<>();
|
||||
// map5.put(1, 40);
|
||||
// map5.put(2, 100);
|
||||
// map5.put(3, 32);
|
||||
// map5.put(4, 50);
|
||||
// map5.put(5, 30);
|
||||
// map5.put(6, 1.5);
|
||||
// map5.put(7, 7.55);
|
||||
// map5.put(8, 150);
|
||||
// map5.put(9, 300);
|
||||
// map5.put(10, 1);
|
||||
//
|
||||
// for (String id : arr1) {
|
||||
// importTableService.addTableData(id, map1);
|
||||
// importTableService.addTableData(id, map2);
|
||||
// importTableService.addTableData(id, map3);
|
||||
// importTableService.addTableData(id, map4);
|
||||
// importTableService.addTableData(id, map5);
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void test3() {
|
||||
// String[] arr1 = {"1932333967098195968", "1932333967177887744", "1932333967236608000", "1932333967274356736", "1932333967307911168", "1932333967341465600"};
|
||||
//
|
||||
// Map<Integer, Object> map1 = new LinkedHashMap<>();
|
||||
// map1.put(1, 100);
|
||||
// map1.put(2, 200);
|
||||
// map1.put(3, 20);
|
||||
// map1.put(4, 25);
|
||||
// map1.put(5, 50);
|
||||
// map1.put(6, 100);
|
||||
// map1.put(7, 200);
|
||||
// map1.put(8, 20);
|
||||
// map1.put(9, 1);
|
||||
// map1.put(10, 5);
|
||||
// map1.put(11, 100);
|
||||
// map1.put(12, 200);
|
||||
// map1.put(13, 1);
|
||||
//
|
||||
// Map<Integer, Object> map2 = new LinkedHashMap<>();
|
||||
// map2.put(1, 200);
|
||||
// map2.put(2, 400);
|
||||
// map2.put(3, 20);
|
||||
// map2.put(4, 25);
|
||||
// map2.put(5, 50);
|
||||
// map2.put(6, 100);
|
||||
// map2.put(7, 200);
|
||||
// map2.put(8, 20);
|
||||
// map2.put(9, 1);
|
||||
// map2.put(10, 5);
|
||||
// map2.put(11, 100);
|
||||
// map2.put(12, 200);
|
||||
// map2.put(13, 1);
|
||||
//
|
||||
// Map<Integer, Object> map3 = new LinkedHashMap<>();
|
||||
// map3.put(1, 400);
|
||||
// map3.put(2, 700);
|
||||
// map3.put(3, 20);
|
||||
// map3.put(4, 20);
|
||||
// map3.put(5, 25);
|
||||
// map3.put(6, 50);
|
||||
// map3.put(7, 200);
|
||||
// map3.put(8, 20);
|
||||
// map3.put(9, 1);
|
||||
// map3.put(10, 5);
|
||||
// map3.put(11, 100);
|
||||
// map3.put(12, 200);
|
||||
// map3.put(13, 1);
|
||||
//
|
||||
// Map<Integer, Object> map4 = new LinkedHashMap<>();
|
||||
// map4.put(1, 700);
|
||||
// map4.put(2, 1000);
|
||||
// map4.put(3, 20);
|
||||
// map4.put(4, 25);
|
||||
// map4.put(5, 50);
|
||||
// map4.put(6, 100);
|
||||
// map4.put(7, 240);
|
||||
// map4.put(8, 20);
|
||||
// map4.put(9, 1);
|
||||
// map4.put(10, 5);
|
||||
// map4.put(11, 100);
|
||||
// map4.put(12, 200);
|
||||
// map4.put(13, 1);
|
||||
//
|
||||
// Map<Integer, Object> map5 = new LinkedHashMap<>();
|
||||
// map5.put(1, 100);
|
||||
// map5.put(2, 2000);
|
||||
// map5.put(3, 25);
|
||||
// map5.put(4, 50);
|
||||
// map5.put(5, 100);
|
||||
// map5.put(6, 200);
|
||||
// map5.put(7, 250);
|
||||
// map5.put(8, 20);
|
||||
// map5.put(9, 1);
|
||||
// map5.put(10, 5);
|
||||
// map5.put(11, 100);
|
||||
// map5.put(12, 200);
|
||||
// map5.put(13, 1);
|
||||
//
|
||||
// for (String id : arr1) {
|
||||
// importTableService.addTableData(id, map1);
|
||||
// importTableService.addTableData(id, map2);
|
||||
// importTableService.addTableData(id, map3);
|
||||
// importTableService.addTableData(id, map4);
|
||||
// importTableService.addTableData(id, map5);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void test4() {
|
||||
// String[] arr1 = {"1932333967379214336", "1932333967412768768", "1932333967492460544", "1932333967555375104", "1932333967593123840", "1932333967626678272"};
|
||||
//
|
||||
// Map<Integer, Object> map1 = new LinkedHashMap<>();
|
||||
// map1.put(1, 400);
|
||||
// map1.put(2, 700);
|
||||
// map1.put(3, 150);
|
||||
// map1.put(4, 175);
|
||||
// map1.put(5, 350);
|
||||
// map1.put(6, 700);
|
||||
// map1.put(7, 730);
|
||||
// map1.put(8, 150);
|
||||
// map1.put(9, 1);
|
||||
//
|
||||
// Map<Integer, Object> map2 = new LinkedHashMap<>();
|
||||
// map2.put(1, 700);
|
||||
// map2.put(2, 1000);
|
||||
// map2.put(3, 150);
|
||||
// map2.put(4, 175);
|
||||
// map2.put(5, 350);
|
||||
// map2.put(6, 700);
|
||||
// map2.put(7, 1400);
|
||||
// map2.put(8, 150);
|
||||
// map2.put(9, 1);
|
||||
//
|
||||
// Map<Integer, Object> map3 = new LinkedHashMap<>();
|
||||
// map3.put(1, 1000);
|
||||
// map3.put(2, 2000);
|
||||
// map3.put(3, 250);
|
||||
// map3.put(4, 500);
|
||||
// map3.put(5, 1000);
|
||||
// map3.put(6, 2000);
|
||||
// map3.put(7, 5000);
|
||||
// map3.put(8, 150);
|
||||
// map3.put(9, 1);
|
||||
//
|
||||
// Map<Integer, Object> map4 = new LinkedHashMap<>();
|
||||
// map4.put(1, 2000);
|
||||
// map4.put(2, 4000);
|
||||
// map4.put(3, 375);
|
||||
// map4.put(4, 750);
|
||||
// map4.put(5, 1500);
|
||||
// map4.put(6, 3000);
|
||||
// map4.put(7, 6000);
|
||||
// map4.put(8, 150);
|
||||
// map4.put(9, 1);
|
||||
//
|
||||
// Map<Integer, Object> map5 = new LinkedHashMap<>();
|
||||
// map5.put(1, 4000);
|
||||
// map5.put(2, 6000);
|
||||
// map5.put(3, 375);
|
||||
// map5.put(4, 750);
|
||||
// map5.put(5, 1500);
|
||||
// map5.put(6, 3000);
|
||||
// map5.put(7, 7200);
|
||||
// map5.put(8, 150);
|
||||
// map5.put(9, 1);
|
||||
//
|
||||
// for (String id : arr1) {
|
||||
// importTableService.addTableData(id, map1);
|
||||
// importTableService.addTableData(id, map2);
|
||||
// importTableService.addTableData(id, map3);
|
||||
// importTableService.addTableData(id, map4);
|
||||
// importTableService.addTableData(id, map5);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void test5() {
|
||||
// ElectromagneticResult<?> electromagneticResult = importTableService.selectTableDataByTableInfoId(1, 10, "1932333966867509248");
|
||||
// System.out.println(JSONUtil.toJsonStr(electromagneticResult));
|
||||
// }
|
||||
//}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
import com.electromagnetic.industry.software.common.cons.UserConstants;
|
||||
import com.electromagnetic.industry.software.common.pojo.UserLoginInfo;
|
||||
import com.electromagnetic.industry.software.common.util.UserThreadLocal;
|
||||
import com.electromagnetic.industry.software.manage.Application;
|
||||
import com.electromagnetic.industry.software.manage.config.ElePropertyConfig;
|
||||
import com.electromagnetic.industry.software.manage.service.ImportPrjService;
|
||||
import com.electromagnetic.industry.software.manage.service.ImportTableService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest(classes = Application.class)
|
||||
public class ImportTableTest {
|
||||
|
||||
@Resource
|
||||
private ImportTableService importTableService;
|
||||
@Resource
|
||||
private ImportPrjService importPrjService;
|
||||
@Resource
|
||||
private ElePropertyConfig elePropertyConfig;
|
||||
|
||||
public void testImportPrj() {
|
||||
UserLoginInfo userLoginInfo = new UserLoginInfo();
|
||||
userLoginInfo.setUserId("1916756770835075072");
|
||||
userLoginInfo.setUsername("北航电磁仿真用户1");
|
||||
userLoginInfo.setWorkNumber("");
|
||||
userLoginInfo.setAdminType("");
|
||||
userLoginInfo.setPrjTmpDir(elePropertyConfig.getEleTmpPath());
|
||||
UserThreadLocal.set(userLoginInfo);
|
||||
importPrjService.importPrj(null);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -11,10 +11,12 @@ public enum DataOwnEnum {
|
|||
SYS_PRJ(1, "项目数据层级", "项目数据"),
|
||||
USER_PRJ(2, "个人数据层级", "个人数据"),
|
||||
REPO_PRJ(5, "库数据层级", "库数据"),
|
||||
IMPORT_PRJ(6, "用户导入层级", "导入工程数据"),
|
||||
|
||||
SYS_FILE(0, "项目数据文件(文件夹)", "项目数据"),
|
||||
USER_FILE(4, "个人数据文件(文件夹)", "个人数据"),
|
||||
REPO_FILE(3, "库数据文件(文件夹)", "库数据");
|
||||
REPO_FILE(3, "库数据文件(文件夹)", "库数据"),
|
||||
IMPORT_FILE(7, "用户导入工程", "导入工程数据");
|
||||
|
||||
private static final Map<Integer, Integer> FILE_PRJ_MAP = new HashMap<>();
|
||||
private static final Map<Integer, DataOwnEnum> CODE_ENUM = new HashMap<>();
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.time.LocalDateTime;
|
||||
|
|
@ -17,6 +18,7 @@ import java.time.format.DateTimeFormatter;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
@Slf4j
|
||||
public final class EleCommonUtil {
|
||||
|
|
@ -138,4 +140,17 @@ public final class EleCommonUtil {
|
|||
return match ? t1 : t2;
|
||||
}
|
||||
|
||||
|
||||
public static ZipFile getZipFile(String zipFilePath) {
|
||||
try {
|
||||
return new ZipFile(zipFilePath);
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
return new ZipFile(zipFilePath, Charset.forName("GBK"));
|
||||
} catch (Exception e1) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue