Pārlūkot izejas kodu

0618 文件打包下载

caizm 2 mēneši atpakaļ
vecāks
revīzija
d0cb1bf366

+ 1 - 0
dbscript/init/generate/03-functionInit.sql

@@ -19,6 +19,7 @@ INSERT INTO SYS_FUNCTION(FUNCTIONID, CLASSNAME, FUNCTIONNAME ,ENABLE)VALUES ('ES
 INSERT INTO SYS_FUNCTION(FUNCTIONID, CLASSNAME, FUNCTIONNAME ,ENABLE)VALUES ('ES0015', '无锡发动机','结果属性值查询',true);
 INSERT INTO SYS_FUNCTION(FUNCTIONID, CLASSNAME, FUNCTIONNAME ,ENABLE)VALUES ('ES0016', '无锡发动机','项目模拟数据组件属性删除',true);
 INSERT INTO SYS_FUNCTION(FUNCTIONID, CLASSNAME, FUNCTIONNAME ,ENABLE)VALUES ('ES0017', '无锡发动机','求解日志获取',true);
+INSERT INTO SYS_FUNCTION(FUNCTIONID, CLASSNAME, FUNCTIONNAME ,ENABLE)VALUES ('ES0018', '无锡发动机','文件打包下载',true);
 INSERT INTO SYS_FUNCTION(FUNCTIONID, CLASSNAME, FUNCTIONNAME ,ENABLE)VALUES ('ES1001', '无锡发动机','组件查询',true);
 INSERT INTO SYS_FUNCTION(FUNCTIONID, CLASSNAME, FUNCTIONNAME ,ENABLE)VALUES ('BES001', '无锡发动机','基础字典查询',true);
 -- 基础系统

+ 112 - 0
generated/com/miniframe/generate/business/es/model/ES0018BaseModel.java

@@ -0,0 +1,112 @@
+package com.miniframe.generate.business.es.model;
+
+import java.util.Map;
+import java.io.IOException;
+import java.util.LinkedHashMap;
+import com.miniframe.core.BaseMapModel;
+import com.miniframe.core.ext.UtilTools;
+import com.miniframe.core.ext.HttpMapFormater;
+import java.time.ZonedDateTime;
+import java.time.format.DateTimeFormatter;
+import com.miniframe.generate.global.AppGlobalVariableSysconfig;
+
+import com.miniframe.generate.comm.es.A_ESHEAD;
+import com.miniframe.generate.comm.es.D_ESHEAD;
+import com.miniframe.generate.comm.es.A_ES0018;
+import com.miniframe.generate.comm.es.D_ES0018;
+
+/**
+ * 无锡发动机,“文件打包下载”模型类(不要维护,重新生成将覆盖)。
+ */
+@SuppressWarnings({ "rawtypes", "unchecked" })
+public class ES0018BaseModel extends BaseMapModel {
+
+	private static final long serialVersionUID = -1326184831746814093L;
+
+	A_ESHEAD a_eshead;//上行头
+	D_ESHEAD d_eshead;//下行头
+	A_ES0018 a_es0018;//上行体
+	D_ES0018 d_es0018;//下行体
+
+	public ES0018BaseModel(){
+		a_eshead=new A_ESHEAD();
+		d_eshead=new D_ESHEAD();
+		a_es0018=new A_ES0018();
+		d_es0018=new D_ES0018();
+	}
+
+	public void validater() throws Exception {
+		this.a_eshead.validater();
+		this.a_es0018.validater();
+	}
+
+	public void setTransMap(Map map) throws Exception {
+		Map headMap = HttpMapFormater.format(map, A_ESHEAD.class);
+		this.a_eshead = UtilTools.map2Obj(headMap, A_ESHEAD.class);
+		Map bodyMap = HttpMapFormater.format(map, A_ES0018.class);
+		this.a_es0018 = UtilTools.map2Obj(bodyMap, A_ES0018.class);
+	}
+
+	public Map getTransMap() throws Exception {
+		Map reMap = new LinkedHashMap();
+
+		if(UtilTools.isNullOrBlank((this.d_eshead).getTransCode())){
+			(this.d_eshead).setTransCode((this.a_eshead).getTransCode());
+		}
+		if(UtilTools.isNullOrBlank((this.d_eshead).getChannelNo())){
+			(this.d_eshead).setChannelNo((this.a_eshead).getChannelNo());
+		}
+		if(UtilTools.isNullOrBlank((this.d_eshead).getUserId())){
+			(this.d_eshead).setUserId((this.a_eshead).getUserId());
+		}
+        if(UtilTools.isNullOrBlank((this.d_eshead).getTransTime())){
+            (this.d_eshead).setTransTime(DateTimeFormatter.ofPattern(AppGlobalVariableSysconfig.DATETIMEFORMAT).format(ZonedDateTime.now()));
+        }
+
+		reMap.putAll(UtilTools.obj2Map(this.d_eshead));
+		reMap.putAll(UtilTools.obj2Map(this.d_es0018));
+
+		return reMap;
+	}
+
+	public A_ESHEAD getA_eshead() {
+		return this.a_eshead;
+	}
+
+	public void setA_eshead(A_ESHEAD a_eshead) {
+		this.a_eshead=a_eshead;
+	}
+
+	public D_ESHEAD getD_eshead() {
+		return d_eshead;
+	}
+
+	public void setD_eshead(D_ESHEAD d_eshead) {
+		this.d_eshead=d_eshead;
+	}
+
+	public A_ES0018 getA_es0018() {
+		return a_es0018;
+	}
+
+	public void setA_es0018(A_ES0018 a_es0018) {
+		this.a_es0018=a_es0018;
+	}
+
+	public D_ES0018 getD_es0018() {
+		return this.d_es0018;
+	}
+
+	public void setD_es0018(D_ES0018 d_es0018) {
+		this.d_es0018=d_es0018;
+	}
+
+	@Override
+	public String toString() {
+		try {
+			return UtilTools.obj2Json(this,true);
+		} catch (IOException e) {
+			return "";
+		}
+	}
+}

+ 25 - 0
generated/com/miniframe/generate/comm/es/A_ES0018.java

@@ -0,0 +1,25 @@
+/**
+ * 无锡发动机
+ */
+package com.miniframe.generate.comm.es;
+import com.miniframe.core.BaseMapModel;
+import java.io.Serializable;
+/**
+ * 文件打包下载
+ */
+public class A_ES0018 extends BaseMapModel implements Serializable {
+	private static final long serialVersionUID = -1463838678425832212L;
+	String pid;//项目Id
+	/**
+	 *项目Id
+	 */
+	public void setPid(String pid) {
+		this.pid=pid;
+	}
+	/**
+	 *项目Id
+	 */
+	public String getPid() {
+		return this.pid;
+	}
+}

+ 12 - 0
generated/com/miniframe/generate/comm/es/D_ES0018.java

@@ -0,0 +1,12 @@
+/**
+ * 无锡发动机
+ */
+package com.miniframe.generate.comm.es;
+import com.miniframe.core.BaseMapModel;
+import java.io.Serializable;
+/**
+ * 文件打包下载
+ */
+public class D_ES0018 extends BaseMapModel implements Serializable {
+	private static final long serialVersionUID = -1463838678425832212L;
+}

+ 99 - 0
generated/com/miniframe/generate/comm/httpesapater/ES0018Client.java

@@ -0,0 +1,99 @@
+package com.miniframe.generate.comm.httpesapater;
+
+import com.miniframe.spring.httpclient.MFHttpRespInfo;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import com.miniframe.core.Transmitter;
+import com.miniframe.core.ext.UtilTools;
+import com.miniframe.generate.comm.es.D_ES0018;
+import com.miniframe.generate.comm.es.D_ESHEAD;
+
+import com.miniframe.generate.business.es.model.ES0018BaseModel;
+
+public class ES0018Client {
+
+	private static final Logger logger = LoggerFactory.getLogger(ES0018Client.class);
+	private MFHttpRespInfo respInfo;
+
+	public MFHttpRespInfo getRespInfo(){
+		return respInfo;
+	}
+
+	/**
+	 * 调用 [无锡发动机->文件打包下载((ES0018)]的通讯接口
+	 * @param model 接口模型
+	 * @param extMap 扩展输入
+	 * @param url 请求地址
+	 * @return model 接口模型
+	 * @throws Exception
+	 */
+	@SuppressWarnings({ "rawtypes", "unchecked" })
+	public ES0018BaseModel execute(ES0018BaseModel model,final Map extMap,final String url) throws Exception {
+		this.executeToRespInfo(model,extMap,url);
+		return model;
+	}
+
+	@SuppressWarnings({ "rawtypes", "unchecked" })
+	public ES0018BaseModel execute(ES0018BaseModel model,final Map extMap) throws Exception {
+		this.executeToRespInfo(model,extMap,null);
+		return model;
+	}
+
+
+	@SuppressWarnings({ "rawtypes", "unchecked" })
+	public MFHttpRespInfo executeToRespInfo(ES0018BaseModel model,final Map extMap,final String url) throws Exception {
+		if (logger.isDebugEnabled()) {
+			logger.debug("execute(ES0018BaseModel) - start");
+		}
+
+		if(UtilTools.isNullOrBlank(model.getA_eshead().getTransCode())){
+			model.getA_eshead().setTransCode("ES0018");
+		}
+
+		Map inMap = new LinkedHashMap();
+		inMap.putAll(UtilTools.obj2Map(model.getA_eshead()));
+		inMap.putAll(UtilTools.obj2Map(model.getA_es0018()));
+		if(extMap!=null && extMap.size()>0){
+			inMap.putAll(extMap);
+		}
+
+		Transmitter httpesApater = (Transmitter) UtilTools.getBean("httpesApater");
+		MFHttpRespInfo respInfo;
+		if(UtilTools.isNotNullAndBlank(url)){
+			respInfo = httpesApater.doPostDataToRespInfo(inMap,url);
+		}else{
+			respInfo = httpesApater.doPostDataToRespInfo(inMap);
+		}
+
+		if(respInfo!=null) {
+			Map outMap=respInfo.getParamMap();
+			D_ESHEAD d_eshead =  UtilTools.map2Obj(outMap, D_ESHEAD.class);
+			D_ES0018 d_es0018 =  UtilTools.map2Obj(outMap, D_ES0018.class);
+			model.setD_eshead(d_eshead);
+			model.setD_es0018(d_es0018);
+
+
+		}
+
+		if (logger.isDebugEnabled()) {
+			logger.debug("execute(ES0018BaseModel) - end");
+		}
+
+        this.respInfo=respInfo;
+
+		return respInfo;
+	}
+
+
+
+	@SuppressWarnings({ "rawtypes", "unchecked" })
+	public ES0018BaseModel execute(ES0018BaseModel model) throws Exception {
+		return this.execute(model,null,null);
+	}
+
+
+}

+ 12 - 0
generated/validateform/a_es0018Form.xml

@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE form-validation PUBLIC "-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.1//EN" "http://jakarta.apache.org/commons/dtds/validator_1_1.dtd">
+<!-- 文件打包下载Form配置文件系统生成请勿修改,否则重新生成将覆盖 -->
+<form-validation>
+<formset>
+<form name="a_es0018Form">
+<field property="pid" depends="required">
+    <arg0 key="a_es0018.pid"/>
+</field>
+</form>
+</formset>
+</form-validation>

+ 2 - 0
generated/validator/resources_a_es0018Form_validator.properties

@@ -0,0 +1,2 @@
+a_es0018.pid = \u9879\u76EEId
+a_es0018Form = true

+ 2 - 0
generated/validator/resources_a_es0018Form_validator_zh_CN.properties

@@ -0,0 +1,2 @@
+a_es0018.pid = \u9879\u76EEId
+a_es0018Form = true

+ 1 - 0
generated/validator/resources_d_es0018Form_validator.properties

@@ -0,0 +1 @@
+d_es0018Form = false

+ 1 - 0
generated/validator/resources_d_es0018Form_validator_zh_CN.properties

@@ -0,0 +1 @@
+d_es0018Form = false

+ 126 - 0
src/main/java/com/miniframe/bisiness/es/ES0018Service.java

@@ -0,0 +1,126 @@
+package com.miniframe.bisiness.es;
+
+import java.io.*;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Map;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
+
+import com.miniframe.core.ExecProcessFlow;
+import com.miniframe.core.ext.UtilTools;
+import com.miniframe.generate.business.es.model.ES0018BaseModel;
+import com.miniframe.httpserver.HttpServerTransFile;
+import com.miniframe.tools.XIFileUtils;
+
+/**
+ * 无锡发动机,“文件打包下载”逻辑处理(重新生成不覆盖)。
+ */
+public class ES0018Service extends ES0018BaseModel implements ExecProcessFlow {
+	
+	private static final long serialVersionUID = -7051358269847459502L;
+		
+	/**
+	 * 无锡发动机,“文件打包下载”业务核心处理
+ 	 */
+	public void transExecute() throws Exception {
+		// 验证路径是否有效
+		String pid = this.getA_es0018().getPid();
+		String basePath = XIFileUtils.getRootPathStr()+"/es/"+pid;
+		Path directoryPath = Paths.get(basePath);
+		if (!Files.exists(directoryPath)) {
+			throw new IllegalArgumentException("指定的目录不存在: " + basePath);
+		}
+
+		if (!Files.isDirectory(directoryPath)) {
+			throw new IllegalArgumentException("指定的路径不是目录: " + basePath);
+		}
+
+		// 创建临时ZIP文件
+		Path tempZip = createTempZipFile();
+
+		try {
+			// 压缩目录内容
+			zipDirectory(directoryPath, tempZip);
+
+			// 准备文件传输对象
+			String zipFileName = directoryPath.getFileName() + ".zip";
+			String mimeType = "application/zip";
+
+			HttpServerTransFile transFile = new HttpServerTransFile(
+					zipFileName,
+					mimeType,
+					tempZip,
+					true // 设置自动删除标志
+			);
+
+			// 设置当前请求的文件传输对象
+			UtilTools.setHttpServerTransFile(transFile);
+		} catch (Exception e) {
+			// 发生异常时删除临时文件
+			Files.deleteIfExists(tempZip);
+			throw e;
+		}
+	}
+
+	private Path createTempZipFile() throws IOException {
+		return Files.createTempFile("download-", ".zip");
+	}
+
+	private void zipDirectory(Path sourceDir, Path zipPath) throws IOException {
+		try (OutputStream fos = Files.newOutputStream(zipPath);
+			 BufferedOutputStream bos = new BufferedOutputStream(fos);
+			 ZipOutputStream zos = new ZipOutputStream(bos)) {
+
+			Files.walk(sourceDir)
+					.filter(path -> !Files.isDirectory(path))
+					.forEach(path -> {
+						try {
+							// 获取相对路径并修正分隔符
+							String relativePath = sourceDir.relativize(path).toString()
+									.replace(File.separatorChar, '/');
+
+							// 创建ZIP条目
+							ZipEntry zipEntry = new ZipEntry(relativePath);
+							zos.putNextEntry(zipEntry);
+
+							// 复制文件内容
+							Files.copy(path, zos);
+							zos.closeEntry();
+						} catch (IOException e) {
+							throw new UncheckedIOException(e);
+						}
+					});
+
+			zos.finish();
+		}
+	}
+	/**
+	 * 无锡发动机,“文件打包下载”业务前处理
+ 	 */
+	public void preTransFlow() throws Exception {
+		this.validater();
+	}
+	
+	/**
+	 * 无锡发动机,“文件打包下载”业务后处理
+ 	 */
+	public void afterTransFlow() throws Exception {
+	
+	}
+	
+	/**
+	 * 无锡发动机,“文件打包下载”逻辑入口处理方法
+ 	 */
+ 	@SuppressWarnings("rawtypes")
+	@Override
+	public Map execute(Map vars) throws Exception {
+		this.setTransMap(vars);
+		preTransFlow();// 执行业务开始的规则检查和校验
+		transExecute();// 执行核心业务段
+		afterTransFlow();// 执行核心逻辑完成后的收尾逻辑
+		return this.getTransMap();
+	}
+
+}

+ 44 - 0
src/test/java/com/miniframe/comm/httpesapater/ES0018Test.java

@@ -0,0 +1,44 @@
+package com.miniframe.comm.httpesapater;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import com.miniframe.comm.httpesapater.HttpesapaterUtil;
+import com.miniframe.generate.comm.es.A_ES0018;
+import com.miniframe.generate.comm.httpesapater.ES0018Client;
+import com.miniframe.generate.business.es.model.ES0018BaseModel;
+
+public class ES0018Test {
+
+	private static final Logger logger = LoggerFactory.getLogger(ES0018Test.class);
+
+	/**
+	 * 文件打包下载,获取报文体
+	 * @return
+	 */
+	public static A_ES0018 getA_es0018() {
+		A_ES0018 a_es0018 = new A_ES0018();
+
+		// ----------以下增加【文件打包下载】上行体赋值-------------
+
+
+
+		// ---------------------------------------------------
+		return a_es0018;
+	}
+	
+	/**
+	 * 运行客户端测试,文件打包下载
+	 * 
+	 * @param args
+	 * @throws Exception
+	 */
+	public static void main(String[] args) throws Exception {
+		ES0018BaseModel model = new ES0018BaseModel();
+		model.setA_eshead(HttpesapaterUtil.getA_eshead("ES0018"));
+		model.setA_es0018(ES0018Test.getA_es0018());
+		ES0018Client client = new ES0018Client();
+		logger.error("客户端发送前总线:\r\n"+model);
+		model = client.execute(model);
+		logger.error("客户端发送后总线:\r\n"+model);
+	}
+}

+ 1 - 0
系统设计/系统模块/ES(无锡发动机).csv

@@ -16,6 +16,7 @@
 100015,ES0015,结果属性值查询,service,
 100016,ES0016,项目模拟数据组件属性删除,service,
 100017,ES0017,求解日志获取,service,
+100018,ES0018,文件打包下载,service,
 
 110001,ES1001,组件查询,service,
 110002,BES001,基础字典查询,service,

+ 2 - 0
系统设计/通信设计/通讯报文/es(无锡发动机)/报文体/ES0018_A(文件打包下载).csv

@@ -0,0 +1,2 @@
+"序号","英文名称","中文名称","数据类型","默认值","格式化","非空/引用","最小(长度/值)","最大(长度/值)","验证规则","标准数据ID","XML样式","TAG标签","映射/子标签","CDATA"
+1,pid,项目Id,string,,,是,,,,,,,,

+ 1 - 0
系统设计/通信设计/通讯报文/es(无锡发动机)/报文体/ES0018_D(文件打包下载).csv

@@ -0,0 +1 @@
+"序号","英文名称","中文名称","数据类型","默认值","格式化","非空/引用","最小(长度/值)","最大(长度/值)","验证规则","标准数据ID","XML样式","TAG标签","映射/子标签","CDATA"