You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
3.4 KiB
Java

import com.matrixone.apps.domain.DomainObject;
import com.matrixone.apps.domain.util.MqlUtil;
import matrix.db.Context;
import matrix.db.File;
import matrix.db.FileItr;
import matrix.db.FileList;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Logger;
public class AegApiTool_mxJPO {
private static final String basePath = "/kkFileView2/kkFileView-4.4.0";
private static final String targetDir = basePath + "/file/demo/";
private static final Logger LOGGER = Logger.getLogger(AegCADemote_mxJPO.class.getName());
private static final String tempFilePath = "/kkFileView2/kkFileView-4.4.0/file/demo/";
public Map<String, String> downloadFile(Context context1, String[] args) throws Exception {
String physicalId = args[0];
String documentName = args[1];
LOGGER.info("physicalId ==> " + physicalId);
LOGGER.info("documentName ==> " + documentName);
LOGGER.info("context.name ==> " + context1.getUser());
Context context=new Context("");
context.setUser("admin_platform");
context.setPassword("Aeg12345678");
context.connect();
String getItemIdInfo = "temp query bus * * * where 'physicalId == " + physicalId + "' select id dump |";
String itemIdInfo = MqlUtil.mqlCommand(context, getItemIdInfo);
String itemId = itemIdInfo.split("\\|")[3];
DomainObject domainObject = DomainObject.newInstance(context, itemId);
String getFileFormat = "print bus " + itemId + " select format[].file.format dump |" ;
String fileFormat = MqlUtil.mqlCommand(context, getFileFormat);
String[] formatArray=fileFormat.split("\\|");
boolean isFlag = false;
String displayName = "";
for(String format : formatArray)
{
FileList fileList = domainObject.getFiles(context, format);
FileItr fileItr = new FileItr(fileList);
while (fileItr.next())
{
File file = fileItr.obj();
String fileName = file.getName();
LOGGER.info("fileName ==> " + fileName);
LOGGER.info("documentName ==> " + documentName);
// if(documentName.equals(fileName.substring(0, fileName.lastIndexOf('.')))) {
// domainObject.checkoutFile(context, false, format, fileName, tempFilePath);
// displayName = fileName;
// isFlag = true;
// }
Path path = Paths.get(targetDir);
if(!Files.exists(path)){
Files.createDirectories(path);
System.out.println("目录创建成功:" + targetDir);
} else {
System.out.println("目录已存在,跳过创建:" + targetDir);
}
domainObject.checkoutFile(context, false, format, fileName, tempFilePath);
displayName = fileName;
isFlag = true;
}
}
Map<String, String> map = new HashMap<>();
map.put("displayName", displayName);
if(isFlag) {
map.put("isFlag","true");
return map;
} else {
map.put("isFlag","false");
return map;
}
}
}