1、XMl实现效果
<?xml version="1.0" encoding="UTF-8"?>
<T_GA_TEAM>
<ST_GA_TEAM_ID>252020000331</ST_GA_TEAM_ID>
<ST_GA_TEAM_NUM>252020000331</ST_GA_TEAM_NUM>
<ST_GA_TEAM_BAR_CODE/>
<ST_GA_TEAM_NAME>上海振华重工(集团)股份有限公司秦玉龙等赴美国</ST_GA_TEAM_NAME>
<ST_APPLY_TYPE>出国任务报批</ST_APPLY_TYPE>
<ST_OPERATOR_ID>上海市浦东新区人民政府</ST_OPERATOR_ID>
<ST_OPERATOR_TYPE>专管员</ST_OPERATOR_TYPE>
<ST_FASS_NAME/>
<ST_FASS_PHONE/>
<ST_FASS_MOBILE/>
<ST_FASS_DEPT>上海振华重工(集团)股份有限公司</ST_FASS_DEPT>
<ST_DOC_NUM/>
<ST_TEAM_LEADER_NAME>秦玉龙</ST_TEAM_LEADER_NAME>
<NM_APPLY_PEOPLE>5</NM_APPLY_PEOPLE>
<ST_VISIT_QUEST_TYPE>商务活动</ST_VISIT_QUEST_TYPE>
<ST_VISIT_QUEST>售后服务</ST_VISIT_QUEST>
<ST_VISIT_PROPERTY_TYPE>经贸</ST_VISIT_PROPERTY_TYPE>
<ST_VISIT_PROPERTY>经济商贸</ST_VISIT_PROPERTY>
<DT_VISIT>2020-10-10 00:00:00</DT_VISIT>
<DT_RETURN>2020-12-08 00:00:00</DT_RETURN>
<NM_VISIT_DAYS>60</NM_VISIT_DAYS>
<ST_COST>一切费用由调剂外汇解决</ST_COST>
<ST_ORGANIZE_DEPT>上海振华重工(集团)股份有限公司</ST_ORGANIZE_DEPT>
<ST_TRANS_REGIONAL_TYPE>非双跨</ST_TRANS_REGIONAL_TYPE>
<ST_FILE_NUM/>
<ST_SSWP_APPLY_COMMENT/>
<ST_APPROVAL_DEPT>上海市浦东新区人民政府</ST_APPROVAL_DEPT>
<DT_APPLY>2020-08-03 15:43:25</DT_APPLY>
<DT_ACCEPT>2020-08-03 15:43:25</DT_ACCEPT>
<DT_FINISH>2020-08-03 15:43:25</DT_FINISH>
<ST_STATE>审批通过</ST_STATE>
<ST_VISIT_TARGET>上海市浦东新区人民政府</ST_VISIT_TARGET>
<ST_GA_OPERATOR_NAME/>
<ST_RETURN_REPORT_REQUIRED>否</ST_RETURN_REPORT_REQUIRED>
<ST_VISIT_CALENDAR>否</ST_VISIT_CALENDAR>
<NM_APPROVAL_PEOPLE>否</NM_APPROVAL_PEOPLE>
<NM_APPROVAL_DAYS>否</NM_APPROVAL_DAYS>
<DT_VISIT_ACTUAL>否</DT_VISIT_ACTUAL>
<DT_RETURN_ACTUAL>否</DT_RETURN_ACTUAL>
<ST_APPROVAL_DOC_CODE>否</ST_APPROVAL_DOC_CODE>
<ST_FA_APPROVAL_DOC_CODE>否</ST_FA_APPROVAL_DOC_CODE>
<ST_TRAINING_PLAN_ID>否</ST_TRAINING_PLAN_ID>
<ST_FA_EXAMINE_CODE>否</ST_FA_EXAMINE_CODE>
<ST_SUMMARY>否</ST_SUMMARY>
<ST_APPROVAL>否</ST_APPROVAL>
<ST_APPROVAL_TYPE>否</ST_APPROVAL_TYPE>
<ST_VISIT_COUNTRY_LIST>否</ST_VISIT_COUNTRY_LIST>
<ST_VISIT_TYPE>否</ST_VISIT_TYPE>
<ST_COMPOSE_TYPE>否</ST_COMPOSE_TYPE>
<T_GT_VISIT_EXPENSE>
<ST_VISIT_EXPENSE_ID>BAC8C351-8361-415B-8EF7-60873015E0AD</ST_VISIT_EXPENSE_ID>
<ST_GA_TEAM_ID>派出单位</ST_GA_TEAM_ID>
<ST_TRAVELLING_EXS>派出单位</ST_TRAVELLING_EXS>
<ST_HOTEL_EXS>派出单位</ST_HOTEL_EXS>
<ST_TABLE_EXS>派出单位</ST_TABLE_EXS>
<ST_SPENT_CASH>派出单位</ST_SPENT_CASH>
<ST_INCIDENTAL_EXS>派出单位</ST_INCIDENTAL_EXS>
<NM_TEAM_SUM>派出单位</NM_TEAM_SUM>
<ST_PASS_FINANCIAL_BUDGET>派出单位</ST_PASS_FINANCIAL_BUDGET>
<ST_IN_BUDGET>派出单位</ST_IN_BUDGET>
<ST_OTHER_EXS>派出单位</ST_OTHER_EXS>
<ST_COMMENT>派出单位</ST_COMMENT>
</T_GT_VISIT_EXPENSE>
<T_GT_VISIT_COUNTRY>
<ST_VISIT_COUNTRY_ID>BAC8C351-8361-415B-8EF7-60873015E0AD</ST_VISIT_COUNTRY_ID>
<ST_GA_TEAM_ID>派出单位</ST_GA_TEAM_ID>
<ST_GA_TEAM_NUM>派出单位</ST_GA_TEAM_NUM>
<ST_COUNTRY>派出单位</ST_COUNTRY>
<NM_STAY_DAYS>派出单位</NM_STAY_DAYS>
<ST_IS_PASSBY>派出单位</ST_IS_PASSBY>
<ST_STAY_TYPE>派出单位</ST_STAY_TYPE>
<DT_ARRIVE>派出单位</DT_ARRIVE>
<DT_LEAVE>派出单位</DT_LEAVE>
<ST_REASON_CN>派出单位</ST_REASON_CN>
<ST_INVITE_DEPT_CN>派出单位</ST_INVITE_DEPT_CN>
<ST_INVITER_NAME_EN>派出单位</ST_INVITER_NAME_EN>
<ST_INVITER_PHONE>派出单位</ST_INVITER_PHONE>
<ST_REASON_EN>派出单位</ST_REASON_EN>
<ST_INVITE_DEPT_EN>派出单位</ST_INVITE_DEPT_EN>
<ST_INVITER_ADDRESS_EN>派出单位</ST_INVITER_ADDRESS_EN>
<NM_ORDER>派出单位</NM_ORDER>
<ST_COMMENT>派出单位</ST_COMMENT>
<ST_INVITER_DESC>派出单位</ST_INVITER_DESC>
<ST_INVITER_RELATE>派出单位</ST_INVITER_RELATE>
<ST_APPROVAL>派出单位</ST_APPROVAL>
<ST_PURPOSE>派出单位</ST_PURPOSE>
</T_GT_VISIT_COUNTRY>
<T_GT_MEMBER>
<ST_GT_MEMBER_ID>BAC8C351-8361-415B-8EF7-60873015E0AD</ST_GT_MEMBER_ID>
<ST_GA_TEAM_ID>派出单位</ST_GA_TEAM_ID>
<ST_GA_TEAM_NUM>派出单位</ST_GA_TEAM_NUM>
<ST_PERSON_ID>派出单位</ST_PERSON_ID>
<ST_NAME>派出单位</ST_NAME>
<ST_SURNAME>派出单位</ST_SURNAME>
<ST_FIRSTNAME>派出单位</ST_FIRSTNAME>
<ST_PINYIN>派出单位</ST_PINYIN>
<ST_TELECODE>派出单位</ST_TELECODE>
<ST_SEX>派出单位</ST_SEX>
<ST_ID_TYPE>派出单位</ST_ID_TYPE>
<ST_ID_NUM>派出单位</ST_ID_NUM>
<ST_BIRTH_PLACE_TYPE>派出单位</ST_BIRTH_PLACE_TYPE>
<ST_BIRTH_PLACE>派出单位</ST_BIRTH_PLACE>
<DT_BIRTHDAY>派出单位</DT_BIRTHDAY>
<ST_RESIDENCY>派出单位</ST_RESIDENCY>
<ST_EMPLOYMENT_PROPERTY>派出单位</ST_EMPLOYMENT_PROPERTY>
<ST_RANK>派出单位</ST_RANK>
<ST_IS_TRANS_REGIONAL>派出单位</ST_IS_TRANS_REGIONAL>
<ST_OCCUPATION>派出单位</ST_OCCUPATION>
<ST_TYPE>派出单位</ST_TYPE>
<ST_COMPANY>派出单位</ST_COMPANY>
<ST_POSITION>派出单位</ST_POSITION>
<ST_SUPER_DEPT>派出单位</ST_SUPER_DEPT>
<ST_WORK_DEPT>派出单位</ST_WORK_DEPT>
<ST_FOREIGN_COMPANY>派出单位</ST_FOREIGN_COMPANY>
<ST_FOREIGN_POSITION>派出单位</ST_FOREIGN_POSITION>
<ST_FOREIGN_IDENTITY>派出单位</ST_FOREIGN_IDENTITY>
<ST_IN_GA_PLAN>派出单位</ST_IN_GA_PLAN>
<ST_GA_PLAN_REASON>派出单位</ST_GA_PLAN_REASON>
<ST_GA_PLAN_ID>派出单位</ST_GA_PLAN_ID>
<NM_ORDER>派出单位</NM_ORDER>
<ST_GA_APPROVAL_REJECT_TYPE>派出单位</ST_GA_APPROVAL_REJECT_TYPE>
<ST_GA_APPROVAL_REJECT_NOTES>派出单位</ST_GA_APPROVAL_REJECT_NOTES>
<ST_GA_APPROVAL_RESULT>派出单位</ST_GA_APPROVAL_RESULT>
<ST_APPROVAL_DOC_NUM>派出单位</ST_APPROVAL_DOC_NUM>
<ST_APPROVAL_DEPT>派出单位</ST_APPROVAL_DEPT>
<ST_PASS_TYPE>派出单位</ST_PASS_TYPE>
<ST_PASS_CODE>派出单位</ST_PASS_CODE>
<ST_ISSUE_DEPT_ID>派出单位</ST_ISSUE_DEPT_ID>
<DT_ISSUE>派出单位</DT_ISSUE>
<DT_EXPIRE>派出单位</DT_EXPIRE>
<ST_OPERATOR_NAME>派出单位</ST_OPERATOR_NAME>
<ST_ISSUE_OPERATOR_NAME>派出单位</ST_ISSUE_OPERATOR_NAME>
<ST_COMMENT>派出单位</ST_COMMENT>
<NM_AGE>派出单位</NM_AGE>
<ST_NATIONALITY>派出单位</ST_NATIONALITY>
</T_GT_MEMBER>
<T_GT_MEMBER_MAP_COUNTRY>
<ST_MAP_ID>BAC8C351-8361-415B-8EF7-60873015E0AD</ST_MAP_ID>
<ST_GT_MEMBER_ID>派出单位</ST_GT_MEMBER_ID>
<ST_VISIT_COUNTRY_ID>派出单位</ST_VISIT_COUNTRY_ID>
<ST_PERSON_ID>派出单位</ST_PERSON_ID>
<ST_COUNTRY>派出单位</ST_COUNTRY>
<DT_ARRIVE>派出单位</DT_ARRIVE>
<DT_LEAVE>派出单位</DT_LEAVE>
<NM_STAY_DAYS>派出单位</NM_STAY_DAYS>
</T_GT_MEMBER_MAP_COUNTRY>
<T_GT_APPROVAL_DOC>
<ST_GT_APPROVAL_DOC_ID>BAC8C351-8361-415B-8EF7-60873015E0AD</ST_GT_APPROVAL_DOC_ID>
<ST_GA_TEAM_ID>派出单位</ST_GA_TEAM_ID>
<ST_TYPE>派出单位</ST_TYPE>
<ST_NUM>派出单位</ST_NUM>
<ST_STATE>派出单位</ST_STATE>
<ST_PREFIX>派出单位</ST_PREFIX>
<ST_SN>派出单位</ST_SN>
<ST_YEAR>派出单位</ST_YEAR>
<ST_REMOVED>派出单位</ST_REMOVED>
<ST_QUEST_APPROVAL_DEPT>派出单位</ST_QUEST_APPROVAL_DEPT>
</T_GT_APPROVAL_DOC>
</T_GA_TEAM>
2、代码实现
2.1工具类
package cn.dreamit.p2047.module_201209092848QCBsGrAiw1FWfb8EBax.utils;
import cn.dreamit.dreamweb.util.DateFormatUtil;
import cn.dreamit.dreamweb.util.FileUtil;
import cn.dreamit.p1000.util.SuperKit;
import cn.dreamit.p2047.module_200730185526Po0wk3EgoVQLuKxFyNJ.utils.FileUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import java.io.File;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
public class MyXmlUtil {
/**
*
* @param nodeAndChildNodes 值为根节点和二级节点的子节点集合、键为对应名称
* @param rootNode 根节点名称
* @param temporaryUrl 临时放置xml的路径
*/
public static void productXml(LinkedHashMap<String,LinkedHashMap<String,String>> nodeAndChildNodes, String rootNode,String temporaryUrl){
try {
//创建XML
File file = new File(temporaryUrl.substring(0,temporaryUrl.lastIndexOf("/")+1));
if (!file.exists()) {
file.mkdirs();
}
// 创建解析器工厂
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder db = factory.newDocumentBuilder();
Document document = db.newDocument();
// 不显示standalone="no"
document.setXmlStandalone(true);
//tGaTeam为创建的根节点
//1、在根节点创建没有三级节点的二级节点
Element rootElement = insertSecondaryNode(rootNode, nodeAndChildNodes.get(rootNode),document);
//2、创建存在三级节点的二级节点
for (String secondNode:nodeAndChildNodes.keySet()) {
//这里将根节点的二级节点排除
if (!secondNode.equals(rootNode)){
Element secondaryNode =insertSecondaryNode(secondNode, nodeAndChildNodes.get(secondNode),document);
rootElement.appendChild(secondaryNode);
}
}
document.appendChild(rootElement);
// 创建TransformerFactory对象
TransformerFactory tff = TransformerFactory.newInstance();
// 创建 Transformer对象
Transformer tf = tff.newTransformer();
// 输出内容是否使用换行
tf.setOutputProperty(OutputKeys.INDENT, "yes");
// 创建xml文件并写入内容
File applyXml = new File(temporaryUrl);
tf.transform(new DOMSource(document), new StreamResult(applyXml));
} catch (Exception e) {
e.printStackTrace();
}
}
/**
*
* @param node 当前节点名称
* @param childNodes 当前节点子节点名称集合
* @param document 文档操作对象
* @return 处理好的当前节点
*/
private static Element insertSecondaryNode(String node, LinkedHashMap<String,String> childNodes, Document document){
Element element =document.createElement(node);
for (Map.Entry<String, String> entry : childNodes.entrySet()) {
Element childElement = document.createElement(entry.getKey());
childElement.setTextContent(entry.getValue());
element.appendChild(childElement);
}
return element;
}
}
2.2、实战代码
package cn.dreamit.p2047.module_201209092848QCBsGrAiw1FWfb8EBax.controller;
import cn.dreamit.dreamweb.util.DateFormatUtil;
import cn.dreamit.dreamweb.util.FileUtil;
import cn.dreamit.p1000.util.SuperKit;
import cn.dreamit.p2047.module_200730185526Po0wk3EgoVQLuKxFyNJ.utils.FileUtils;
import cn.dreamit.p2047.module_201209092848QCBsGrAiw1FWfb8EBax.utils.MyXmlUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
@RestController
@RequestMapping("/applyboard")
public class ExportXmlController {
@RequestMapping("/exportXml")
public void exportXml(HttpServletResponse response) {
//创建二级节点
LinkedHashMap<String, String> hashMap =getsecondaryMap();
// 向二级T_GT_VISIT_EXPENSE子节点中再添加子节点
LinkedHashMap<String, String> tGtVisitExpenseMap = getGtVisitExpenseMap();
// 向二级T_GT_VISIT_EXPENSE子节点中再添加子节点
LinkedHashMap<String, String> tGtVisitCountryMap = getGtVisitCountryMap();
// 向二级T_GT_VISIT_EXPENSE子节点中再添加子节点
LinkedHashMap<String, String> tGtMemberMap = getGtMemberMap();
// 向二级T_GT_VISIT_EXPENSE子节点中再添加子节点
LinkedHashMap<String, String> tGtMemberMapCountryMap = getGtMemberMapCountryMap();
// 向二级T_GT_VISIT_EXPENSE子节点中再添加子节点
LinkedHashMap<String, String> tGtApprovalDocMap = getGtApprovalDocMap();
String rootNode = "T_GA_TEAM";
LinkedHashMap<String,LinkedHashMap<String,String>> nodeAndChildNodes = new LinkedHashMap<>();
nodeAndChildNodes.put(rootNode,hashMap);
nodeAndChildNodes.put("T_GT_VISIT_EXPENSE",tGtVisitExpenseMap);
nodeAndChildNodes.put("T_GT_VISIT_COUNTRY",tGtVisitCountryMap);
nodeAndChildNodes.put("T_GT_MEMBER",tGtMemberMap);
nodeAndChildNodes.put("T_GT_MEMBER_MAP_COUNTRY",tGtMemberMapCountryMap);
nodeAndChildNodes.put("T_GT_APPROVAL_DOC",tGtApprovalDocMap);
String temporaryUrl = SuperKit.getStringFromDBConfig("SYS-ATTACH-0005")
+ "temporaryXML" + DateFormatUtil.format(new Date(), "yyyyMMddHHmmss") + "/apply.xml";
MyXmlUtil.productXml(nodeAndChildNodes,rootNode,temporaryUrl);
try {
FileUtil.downloadByAbsolutePathFromDisk(temporaryUrl, "测试下载xml", response);
} catch (Exception e) {
e.printStackTrace();
} finally {
FileUtils.deleteFolder(temporaryUrl.substring(0,temporaryUrl.lastIndexOf("/")));
}
}
/**
* 得到没有三级节点的二级节点集合
* @return
*/
private LinkedHashMap<String, String> getsecondaryMap(){
LinkedHashMap<String, String> hashMap = new LinkedHashMap<>();
hashMap.put("ST_GA_TEAM_ID", "252020000331");
hashMap.put("ST_GA_TEAM_NUM", "252020000331");
hashMap.put("ST_GA_TEAM_BAR_CODE", "");
hashMap.put("ST_GA_TEAM_NAME", "上海振华重工(集团)股份有限公司秦玉龙等赴美国");
hashMap.put("ST_APPLY_TYPE", "出国任务报批");
hashMap.put("ST_OPERATOR_ID", "上海市浦东新区人民政府");
hashMap.put("ST_OPERATOR_TYPE", "专管员");
hashMap.put("ST_FASS_NAME", "");
hashMap.put("ST_FASS_PHONE", "");
hashMap.put("ST_FASS_MOBILE", "");
hashMap.put("ST_FASS_DEPT", "上海振华重工(集团)股份有限公司");
hashMap.put("ST_DOC_NUM", "");
hashMap.put("ST_TEAM_LEADER_NAME", "秦玉龙");
hashMap.put("NM_APPLY_PEOPLE", "5");
hashMap.put("ST_VISIT_QUEST_TYPE", "商务活动");
hashMap.put("ST_VISIT_QUEST", "售后服务");
hashMap.put("ST_VISIT_PROPERTY_TYPE", "经贸");
hashMap.put("ST_VISIT_PROPERTY", "经济商贸");
hashMap.put("DT_VISIT", "2020-10-10 00:00:00");
hashMap.put("DT_RETURN", "2020-12-08 00:00:00");
hashMap.put("NM_VISIT_DAYS", "60");
hashMap.put("ST_COST", "一切费用由调剂外汇解决");
hashMap.put("ST_ORGANIZE_DEPT", "上海振华重工(集团)股份有限公司");
hashMap.put("ST_TRANS_REGIONAL_TYPE", "非双跨");
hashMap.put("ST_FILE_NUM", "");
hashMap.put("ST_SSWP_APPLY_COMMENT", "");
hashMap.put("ST_APPROVAL_DEPT", "上海市浦东新区人民政府");
hashMap.put("DT_APPLY", "2020-08-03 15:43:25");
hashMap.put("DT_ACCEPT", "2020-08-03 15:43:25");
hashMap.put("DT_FINISH", "2020-08-03 15:43:25");
hashMap.put("ST_STATE", "审批通过");
hashMap.put("ST_VISIT_TARGET", "上海市浦东新区人民政府");
hashMap.put("ST_GA_OPERATOR_NAME", "");
hashMap.put("ST_RETURN_REPORT_REQUIRED", "否");
hashMap.put("ST_VISIT_CALENDAR", "否");
hashMap.put("NM_APPROVAL_PEOPLE", "否");
hashMap.put("NM_APPROVAL_DAYS", "否");
hashMap.put("DT_VISIT_ACTUAL", "否");
hashMap.put("DT_RETURN_ACTUAL", "否");
hashMap.put("ST_APPROVAL_DOC_CODE", "否");
hashMap.put("ST_FA_APPROVAL_DOC_CODE", "否");
hashMap.put("ST_TRAINING_PLAN_ID", "否");
hashMap.put("ST_FA_EXAMINE_CODE", "否");
hashMap.put("ST_SUMMARY", "否");
hashMap.put("ST_APPROVAL", "否");
hashMap.put("ST_APPROVAL_TYPE", "否");
hashMap.put("ST_VISIT_COUNTRY_LIST", "否");
hashMap.put("ST_VISIT_TYPE", "否");
hashMap.put("ST_COMPOSE_TYPE", "否");
return hashMap;
}
/**
* 得到二级节点tGtVisitExpenseMap的三级节点集合
* @return
*/
private LinkedHashMap<String, String> getGtVisitExpenseMap(){
LinkedHashMap<String, String> tGtVisitExpenseMap = new LinkedHashMap<>();
tGtVisitExpenseMap.put("ST_VISIT_EXPENSE_ID","BAC8C351-8361-415B-8EF7-60873015E0AD");
tGtVisitExpenseMap.put("ST_GA_TEAM_ID","派出单位");
tGtVisitExpenseMap.put("ST_TRAVELLING_EXS","派出单位");
tGtVisitExpenseMap.put("ST_HOTEL_EXS","派出单位");
tGtVisitExpenseMap.put("ST_TABLE_EXS","派出单位");
tGtVisitExpenseMap.put("ST_SPENT_CASH","派出单位");
tGtVisitExpenseMap.put("ST_INCIDENTAL_EXS","派出单位");
tGtVisitExpenseMap.put("NM_TEAM_SUM","派出单位");
tGtVisitExpenseMap.put("ST_PASS_FINANCIAL_BUDGET","派出单位");
tGtVisitExpenseMap.put("ST_IN_BUDGET","派出单位");
tGtVisitExpenseMap.put("ST_OTHER_EXS","派出单位");
tGtVisitExpenseMap.put("ST_COMMENT","派出单位");
return tGtVisitExpenseMap;
}
/**
* 得到二级节点tGtVisitCountryMap的三级节点集合
* @return
*/
private LinkedHashMap<String, String> getGtVisitCountryMap(){
LinkedHashMap<String, String> tGtVisitCountryMap = new LinkedHashMap<>();
tGtVisitCountryMap.put("ST_VISIT_COUNTRY_ID","BAC8C351-8361-415B-8EF7-60873015E0AD");
tGtVisitCountryMap.put("ST_GA_TEAM_ID","派出单位");
tGtVisitCountryMap.put("ST_GA_TEAM_NUM","派出单位");
tGtVisitCountryMap.put("ST_COUNTRY","派出单位");
tGtVisitCountryMap.put("NM_STAY_DAYS","派出单位");
tGtVisitCountryMap.put("ST_IS_PASSBY","派出单位");
tGtVisitCountryMap.put("ST_STAY_TYPE","派出单位");
tGtVisitCountryMap.put("DT_ARRIVE","派出单位");
tGtVisitCountryMap.put("DT_LEAVE","派出单位");
tGtVisitCountryMap.put("ST_REASON_CN","派出单位");
tGtVisitCountryMap.put("ST_INVITE_DEPT_CN","派出单位");
tGtVisitCountryMap.put("ST_INVITER_NAME_EN","派出单位");
tGtVisitCountryMap.put("ST_INVITER_PHONE","派出单位");
tGtVisitCountryMap.put("ST_REASON_EN","派出单位");
tGtVisitCountryMap.put("ST_INVITE_DEPT_EN","派出单位");
tGtVisitCountryMap.put("ST_INVITER_ADDRESS_EN","派出单位");
tGtVisitCountryMap.put("NM_ORDER","派出单位");
tGtVisitCountryMap.put("ST_COMMENT","派出单位");
tGtVisitCountryMap.put("ST_INVITER_DESC","派出单位");
tGtVisitCountryMap.put("ST_INVITER_RELATE","派出单位");
tGtVisitCountryMap.put("ST_APPROVAL","派出单位");
tGtVisitCountryMap.put("ST_PURPOSE","派出单位");
return tGtVisitCountryMap;
}
/**
* 得到二级节点tGtMemberMap的三级节点集合
* @return
*/
private LinkedHashMap<String, String> getGtMemberMap(){
LinkedHashMap<String, String> tGtMemberMap = new LinkedHashMap<>();
tGtMemberMap.put("ST_GT_MEMBER_ID","BAC8C351-8361-415B-8EF7-60873015E0AD");
tGtMemberMap.put("ST_GA_TEAM_ID","派出单位");
tGtMemberMap.put("ST_GA_TEAM_NUM","派出单位");
tGtMemberMap.put("ST_PERSON_ID","派出单位");
tGtMemberMap.put("ST_NAME","派出单位");
tGtMemberMap.put("ST_SURNAME","派出单位");
tGtMemberMap.put("ST_FIRSTNAME","派出单位");
tGtMemberMap.put("ST_PINYIN","派出单位");
tGtMemberMap.put("ST_TELECODE","派出单位");
tGtMemberMap.put("ST_SEX","派出单位");
tGtMemberMap.put("ST_ID_TYPE","派出单位");
tGtMemberMap.put("ST_ID_NUM","派出单位");
tGtMemberMap.put("ST_BIRTH_PLACE_TYPE","派出单位");
tGtMemberMap.put("ST_BIRTH_PLACE","派出单位");
tGtMemberMap.put("DT_BIRTHDAY","派出单位");
tGtMemberMap.put("ST_RESIDENCY","派出单位");
tGtMemberMap.put("ST_EMPLOYMENT_PROPERTY","派出单位");
tGtMemberMap.put("ST_RANK","派出单位");
tGtMemberMap.put("ST_IS_TRANS_REGIONAL","派出单位");
tGtMemberMap.put("ST_OCCUPATION","派出单位");
tGtMemberMap.put("ST_TYPE","派出单位");
tGtMemberMap.put("ST_COMPANY","派出单位");
tGtMemberMap.put("ST_POSITION","派出单位");
tGtMemberMap.put("ST_SUPER_DEPT","派出单位");
tGtMemberMap.put("ST_WORK_DEPT","派出单位");
tGtMemberMap.put("ST_FOREIGN_COMPANY","派出单位");
tGtMemberMap.put("ST_FOREIGN_POSITION","派出单位");
tGtMemberMap.put("ST_FOREIGN_IDENTITY","派出单位");
tGtMemberMap.put("ST_IN_GA_PLAN","派出单位");
tGtMemberMap.put("ST_GA_PLAN_REASON","派出单位");
tGtMemberMap.put("ST_GA_PLAN_ID","派出单位");
tGtMemberMap.put("NM_ORDER","派出单位");
tGtMemberMap.put("ST_GA_APPROVAL_REJECT_TYPE","派出单位");
tGtMemberMap.put("ST_GA_APPROVAL_REJECT_NOTES","派出单位");
tGtMemberMap.put("ST_GA_APPROVAL_RESULT","派出单位");
tGtMemberMap.put("ST_APPROVAL_DOC_NUM","派出单位");
tGtMemberMap.put("ST_APPROVAL_DEPT","派出单位");
tGtMemberMap.put("ST_PASS_TYPE","派出单位");
tGtMemberMap.put("ST_PASS_CODE","派出单位");
tGtMemberMap.put("ST_ISSUE_DEPT_ID","派出单位");
tGtMemberMap.put("DT_ISSUE","派出单位");
tGtMemberMap.put("DT_EXPIRE","派出单位");
tGtMemberMap.put("ST_OPERATOR_NAME","派出单位");
tGtMemberMap.put("ST_ISSUE_OPERATOR_NAME","派出单位");
tGtMemberMap.put("ST_COMMENT","派出单位");
tGtMemberMap.put("NM_AGE","派出单位");
tGtMemberMap.put("ST_NATIONALITY","派出单位");
return tGtMemberMap;
}
/**
* 得到二级节点tGtMemberMapCountryMap的三级节点集合
* @return
*/
private LinkedHashMap<String, String> getGtMemberMapCountryMap(){
LinkedHashMap<String, String> tGtMemberMapCountryMap = new LinkedHashMap<>();
tGtMemberMapCountryMap.put("ST_MAP_ID","BAC8C351-8361-415B-8EF7-60873015E0AD");
tGtMemberMapCountryMap.put("ST_GT_MEMBER_ID","派出单位");
tGtMemberMapCountryMap.put("ST_VISIT_COUNTRY_ID","派出单位");
tGtMemberMapCountryMap.put("ST_PERSON_ID","派出单位");
tGtMemberMapCountryMap.put("ST_COUNTRY","派出单位");
tGtMemberMapCountryMap.put("DT_ARRIVE","派出单位");
tGtMemberMapCountryMap.put("DT_LEAVE","派出单位");
tGtMemberMapCountryMap.put("NM_STAY_DAYS","派出单位");
return tGtMemberMapCountryMap;
}
/**
* 得到二级节点tGtApprovalDocMap的三级节点集合
* @return
*/
private LinkedHashMap<String, String> getGtApprovalDocMap(){
LinkedHashMap<String, String> tGtApprovalDocMap = new LinkedHashMap<>();
tGtApprovalDocMap.put("ST_GT_APPROVAL_DOC_ID","BAC8C351-8361-415B-8EF7-60873015E0AD");
tGtApprovalDocMap.put("ST_GA_TEAM_ID","派出单位");
tGtApprovalDocMap.put("ST_TYPE","派出单位");
tGtApprovalDocMap.put("ST_NUM","派出单位");
tGtApprovalDocMap.put("ST_STATE","派出单位");
tGtApprovalDocMap.put("ST_PREFIX","派出单位");
tGtApprovalDocMap.put("ST_SN","派出单位");
tGtApprovalDocMap.put("ST_YEAR","派出单位");
tGtApprovalDocMap.put("ST_REMOVED","派出单位");
tGtApprovalDocMap.put("ST_QUEST_APPROVAL_DEPT","派出单位");
return tGtApprovalDocMap;
}
}
附加: 下载工具类
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
package cn.dreamit.dreamweb.util;
import cn.dreamit.dreamweb.crypto.gm.SM2Util;
import cn.dreamit.dreamweb.crypto.gm.SM4Util;
import cn.dreamit.dreamweb.web.util.ContextHolderUtils;
import cn.dreamit.dreamweb.web.util.ResponseHeaderUtils;
import cn.dreamit.p1000.module.logger.entity.ActlogEntity;
import cn.dreamit.p1000.module.logger.service.LoggerService;
import cn.dreamit.p1000.module.office.OfficeDataSupport;
import cn.dreamit.p1000.module.userinfo.entity.User;
import cn.dreamit.p1000.util.SuperKit;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.RandomAccessFile;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.channels.FileChannel.MapMode;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Calendar;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.htmlparser.Node;
import org.htmlparser.Parser;
import org.htmlparser.tags.MetaTag;
import org.htmlparser.visitors.ObjectFindingVisitor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.FileCopyUtils;
import sun.misc.Cleaner;
import sun.nio.ch.DirectBuffer;
import xsf.ContextDictionary;
import xsf.IContextDictionary;
import xsf.resource.ResourceManager;
import xsf.util.StringHelper;
@Component
public class FileUtil {
private static Logger log = Logger.getLogger(FileUtil.class);
public static final String CONTEXT_TYPE = "application/octet-stream;charset=utf-8";
public static final String FILE_NOT_EXISTS = "文件不存在:";
private static final String FILE_CODE_ERROR = "文件转码失败:";
private static final String FILE_READ_ERROR = "文件读取失败:";
private static LoggerService loggerService;
@Autowired
public FileUtil(LoggerService loggerService) {
loggerService = loggerService;
}
public static String getFileSize(long size) {
String res = null;
if (size <= 0L) {
res = "0Byte";
} else if (size > 0L && size < 1024L) {
res = size + "Byte";
} else if (size > 1024L && size < 1048576L) {
res = size / 1024L + "KB";
} else if (size >= 1048576L && size < 1073741824L) {
res = size / 1048576L + "MB";
} else {
res = size / 1073741824L + "GB";
}
return res;
}
public static String upload(File file, String path) throws Exception {
return upload(new FileInputStream(file), path, file);
}
public static String upload(InputStream is, String path, File uploadFile) throws Exception {
String storage = SuperKit.getStringFromDBConfig("SYS-ATTACH-0003");
String[] fileInfo = unPackPath(path);
File file;
File parentDir;
if (StringUtil.isNotEmpty(fileInfo[0]) && fileInfo[0].equals("TEMPLATE")) {
storage = "TEMPLATE";
file = new File(templatePath(path));
parentDir = file.getParentFile();
if (!parentDir.exists()) {
parentDir.mkdirs();
}
FileCopyUtils.copy(is, new FileOutputStream(file));
} else if (!StringUtil.isEmpty(storage) && !"DISK".equalsIgnoreCase(storage)) {
if (!"DB".equalsIgnoreCase(storage) && "ALIYUN-OSS".equalsIgnoreCase(storage)) {
AliYunOSSUtils.getInstance().upload(fileInfo[1], is);
}
} else {
file = new File(SuperKit.getFileAbsolutePath(path));
parentDir = file.getParentFile();
if (!parentDir.exists()) {
parentDir.mkdirs();
}
if (uploadFile != null) {
FileCopyUtils.copy(encryptFile(readFile(uploadFile.getAbsolutePath())), new FileOutputStream(file));
} else {
FileCopyUtils.copy(is, new FileOutputStream(file));
}
}
if (is != null) {
is.close();
}
return packPath(storage, fileInfo[1]);
}
public static String moveTempFile2Formal(String fileName) throws Exception {
String tempFilePath = SuperKit.getTempFileAbsolutePath(fileName);
return moveDiskFile2Formal(new File(tempFilePath));
}
public static String moveTempFile2ModuleTemplatePath(String unitId, String projectId, String moduleId, String type, String fileName) throws IOException {
String tempFilePath = SuperKit.getTempFileAbsolutePath(fileName);
String destFilePath = templateSubPath(unitId, projectId, moduleId, type) + fileName;
copy2DiskFromDisk(new File(tempFilePath), new File(templatePath(destFilePath)));
return packPath("TEMPLATE", destFilePath);
}
public static String moveTempFile2ImagePath(String fileName) throws IOException {
String tempFilePath = SuperKit.getTempFileAbsolutePath(fileName);
String destFilePath = SuperKit.getImageFileAbsolutePath() + fileName;
copy2DiskFromDisk(new File(tempFilePath), new File(destFilePath));
return "upload/photo/" + fileName;
}
public static String moveDiskFile2Formal(File file) throws Exception {
return moveDiskFile2Formal("upload/", file);
}
public static String moveDiskFile2Formal(String type, File file) throws Exception {
String storage = SuperKit.getStringFromDBConfig("SYS-ATTACH-0003");
if (!StringUtil.isEmpty(storage) && !"DISK".equalsIgnoreCase(storage)) {
return !"DB".equalsIgnoreCase(storage) && "ALIYUN-OSS".equalsIgnoreCase(storage) ? moveDiskFile2AliOSS(file) : null;
} else {
return moveDiskFile2Disk(type, file);
}
}
public static String moveDiskFile2Disk(String type, File tempFile) throws Exception {
String destFilePath = getFileDatePath(type, tempFile.getName());
writeFile(SuperKit.getFileAbsolutePath(destFilePath), encryptFile(readFile(tempFile.getAbsolutePath())));
Files.delete(Paths.get(tempFile.getAbsolutePath()));
return destFilePath;
}
public static String moveDiskFile2AliOSS(File file) {
String objectName = SuperKit.getTenantUnitId() + "/" + getFileDatePath((String)null, file.getName());
AliYunOSSUtils.getInstance().upload(objectName, file);
return packPath("ALIYUN-OSS", objectName);
}
public static String getFileDatePath(String type, String fileName) {
return getFileUnitDatePath(type, fileName, (User)null);
}
public static String getFileUnitDatePath(String type, String fileName, User user) {
Calendar date = Calendar.getInstance();
String destPathStr = date.get(1) + "/" + (date.get(2) + 1);
if (user == null) {
user = SuperKit.getSessionUser();
}
if (user != null) {
destPathStr = user.getUnitId() + "/" + destPathStr;
}
if (StringUtils.isNotEmpty(type)) {
if (type.endsWith("/")) {
destPathStr = type + destPathStr;
} else {
destPathStr = type + "/" + destPathStr;
}
}
File destPath = new File(SuperKit.getFileAbsolutePath(destPathStr));
if (!destPath.exists()) {
destPath.mkdirs();
}
return destPathStr + "/" + fileName;
}
public static String templatePath(String path) {
String rootPath = ResourceManager.getAppKey("TEMPLATE_FILEPATH_HEAD", "");
File parent = new File(rootPath, SuperKit.getProjectName());
String filePath = unPackPath(path)[1];
File file = new File(parent, filePath);
return file.getAbsolutePath();
}
public static String templatePath(String unitId, String projectId, String moduleId, String type) {
return templatePath(templateSubPath(unitId, projectId, moduleId, type));
}
public static String templateSubPath(String unitId, String projectId, String moduleId, String type) {
StringBuilder filePath = new StringBuilder();
filePath.append(unitId).append("/");
filePath.append(projectId).append("/").append(moduleId).append("/").append(type).append("/");
return filePath.toString();
}
public static void downloadTempFile(String path, String fileName, HttpServletResponse response) {
downloadTempFile(path, fileName, response, new ContextDictionary());
}
public static void downloadTempFile(String path, String fileName, HttpServletResponse response, IContextDictionary dict) {
downloadByAbsolutePathFromDisk(SuperKit.getTempFileAbsolutePath(path), fileName, response, dict);
}
public static void downloadByAbsolutePathFromDisk(String path, String fileName, HttpServletResponse response) {
downloadByAbsolutePathFromDisk(path, fileName, response, new ContextDictionary());
}
public static void downloadByAbsolutePathFromDisk(String path, String fileName, HttpServletResponse response, IContextDictionary dict) {
log.info("开始下载临时文件" + path);
File file = new File(path);
response.reset();
HttpServletRequest request = ContextHolderUtils.getRequest();
ResponseHeaderUtils.addHeaders(response, request);
response.setCharacterEncoding("utf-8");
int length = (int)file.length();
response.setContentLength(length);
response.setDateHeader("Last-Modified", file.lastModified());
response.setIntHeader("Content-Length", length);
String fileExtension = FilenameUtils.getExtension(fileName);
String contentType = getFileContentType(fileExtension);
if (StringUtil.isEmpty(contentType)) {
contentType = "application/octet-stream;charset=utf-8";
}
response.setContentType(contentType);
try {
boolean isHasSpace = fileName.contains(" ");
String userAgent = request.getHeader("User-Agent");
if (StringUtil.hasLength(userAgent)) {
userAgent = userAgent.toUpperCase();
}
byte[] bytes = null;
byte[] bytes;
if (!StringUtil.hasLength(userAgent) || userAgent.indexOf("MSIE") <= 0 && (userAgent.indexOf("GECKO") <= 0 || userAgent.indexOf("RV:11") <= 0)) {
bytes = fileName.getBytes("UTF-8");
} else {
bytes = fileName.getBytes("gb2312");
}
fileName = new String(bytes, "ISO-8859-1");
String disposition = dict.getString("disposition");
if ("1".equals(disposition) || StringUtil.isEmpty(disposition)) {
if (isHasSpace) {
response.setHeader("Content-disposition", String.format("attachment; filename=\"%s\"", fileName));
} else {
response.setHeader("Content-disposition", String.format("attachment; filename=%s", fileName));
}
}
FileCopyUtils.copy(new FileInputStream(file), response.getOutputStream());
User currentUser = SuperKit.getLoginedUser(request);
if (currentUser != null && StringUtil.hasLength(dict.getString("fileName"))) {
String content = currentUser.getUserName() + "(" + currentUser.getLogName() + ")下载正文附件-" + dict.getString("fileId");
addActLog(dict.getString("infoId"), currentUser, content, "0004", "00040023", dict);
}
log.info("结束下载临时文件" + path);
} catch (UnsupportedEncodingException var15) {
var15.printStackTrace();
write(response, "文件转码失败:" + fileName);
} catch (FileNotFoundException var16) {
write(response, "文件不存在:" + fileName);
} catch (IOException var17) {
var17.printStackTrace();
write(response, "文件读取失败:" + fileName);
}
}
public static void download(String path, String fileName, HttpServletResponse response) {
download(path, (String)fileName, (HttpServletResponse)response, (IContextDictionary)(new ContextDictionary()));
}
public static void download(String path, String fileName, HttpServletResponse response, IContextDictionary dict) {
log.info("开始下载正式文件:" + path);
response.reset();
HttpServletRequest request = ContextHolderUtils.getRequest();
ResponseHeaderUtils.addHeaders(response, request);
response.setCharacterEncoding("utf-8");
String fileExtension = FilenameUtils.getExtension(fileName);
String contentType = getFileContentType(fileExtension);
if (StringUtil.isEmpty(contentType)) {
contentType = "application/octet-stream;charset=utf-8";
}
response.setContentType(contentType);
try {
String userAgent = request.getHeader("User-Agent");
if (StringUtil.hasLength(userAgent)) {
userAgent = userAgent.toUpperCase();
}
boolean isHasSpace = fileName.contains(" ");
byte[] bytes = null;
byte[] bytes;
if (!StringUtil.hasLength(userAgent) || userAgent.indexOf("MSIE") <= 0 && (userAgent.indexOf("GECKO") <= 0 || userAgent.indexOf("RV:11") <= 0)) {
bytes = fileName.getBytes("UTF-8");
} else {
bytes = fileName.getBytes("gb2312");
}
fileName = StringUtil.hasLength(userAgent) && userAgent.contains("EDGE") ? URLEncoder.encode(fileName, "UTF-8") : new String(bytes, "ISO-8859-1");
String disposition = dict.getString("disposition");
String downloadHeader = "attachment";
if ("pdf".equalsIgnoreCase(fileExtension) && "1".equals(dict.getString("preview"))) {
downloadHeader = "inline";
}
if ("1".equals(disposition) || StringUtil.isEmpty(disposition)) {
if (isHasSpace) {
response.setHeader("Content-disposition", String.format(downloadHeader + "; filename=\"%s\"", fileName));
} else {
response.setHeader("Content-disposition", String.format(downloadHeader + "; filename=%s", fileName));
}
}
download(path, response, dict, fileExtension);
User currentUser = SuperKit.getLoginedUser(request);
if (currentUser != null && StringUtil.hasLength(dict.getString("fileName"))) {
StringBuffer content = new StringBuffer(200);
content.append(currentUser.getUserName()).append("(").append(currentUser.getLogName()).append(")").append("下载正文附件-").append(dict.getString("fileId"));
if (!SuperKit.isSecretSystem()) {
content.append("-").append(dict.getString("fileName"));
}
String mjText = dict.getString("mjText");
if (StringUtil.isNotEmpty(mjText) && !"无".equals(mjText)) {
content.append(",密级为【" + mjText + "】");
}
addActLog(dict.getString("infoId"), currentUser, content.toString(), "0004", "00040023", dict);
}
log.info("结束下载正式文件:" + path);
} catch (UnsupportedEncodingException var15) {
var15.printStackTrace();
write(response, "文件转码失败:" + fileName);
} catch (FileNotFoundException var16) {
write(response, "文件不存在:" + fileName);
} catch (IOException var17) {
var17.printStackTrace();
write(response, "文件读取失败:" + fileName);
} catch (Exception var18) {
var18.printStackTrace();
write(response, "文件转码失败:" + fileName);
}
}
private static void download(String path, HttpServletResponse response, IContextDictionary dict, String fileExtension) throws Exception {
log.info("download file path = " + path);
String storage = getFileStorage(path);
log.info("download file storage = " + storage);
if (!StringUtil.isEmpty(storage) && !"DISK".equalsIgnoreCase(storage)) {
if (!"DB".equalsIgnoreCase(storage)) {
if ("ALIYUN-OSS".equalsIgnoreCase(storage)) {
downloadFromAliOSS(path, response);
} else if ("TEMPLATE".equals(storage)) {
File file = new File(templatePath(path.substring("TEMPLATE".length() + 1)));
downloadFromDisk(file, response);
}
}
} else {
if ("ofd".equalsIgnoreCase(fileExtension) && "suwellOfd".equals(SuperKit.getStringFromDBConfig("SYS-ATTACH-0014"))) {
path = OfficeDataSupport.suwellOfdFileAddTicket(path, fileExtension);
if (StringHelper.isNullOrEmpty(path)) {
throw new RuntimeException("数科ofd添加ticket元数据报错");
}
}
String extension = FilenameUtils.getExtension(path);
boolean isHtml = "html".equalsIgnoreCase(extension) || "htm".equalsIgnoreCase(extension);
String encryptMode = SuperKit.getStringFromDBConfig("SYS-ATTACH-0006");
boolean unencrypted = ValueUtil.getInt(encryptMode) <= 1;
boolean declaredUnencrypted = dict.containsKey("decryptFile") && !ValueUtil.getBoolean(dict.getString("decryptFile"));
File file = new File(SuperKit.getFileAbsolutePath(path));
response.setDateHeader("Last-Modified", file.lastModified());
if (declaredUnencrypted && !isHtml) {
long beginTime = System.currentTimeMillis();
try {
outputFileByMappedBuffer(file, response.getOutputStream());
} catch (Exception var15) {
response.reset();
response.sendError(404, var15.getMessage());
}
long time = System.currentTimeMillis() - beginTime;
log.info("[download] by buffer, time=" + time);
} else {
byte[] content;
if (declaredUnencrypted) {
content = readFile(SuperKit.getFileAbsolutePath(path));
} else {
content = decryptFile(readFile(SuperKit.getFileAbsolutePath(path)));
}
if (isHtml) {
String contentType = getHtmlContentType(new String(content));
if (StringUtil.hasLength(contentType)) {
response.setContentType(contentType);
}
}
response.setIntHeader("Content-Length", content.length);
FileCopyUtils.copy(content, response.getOutputStream());
}
}
}
private static void outputFileByMappedBuffer(File file, OutputStream out) throws Exception {
long len = file.length();
RandomAccessFile raf = null;
FileChannel fileChannel = null;
MappedByteBuffer mappedByteBuffer = null;
try {
raf = new RandomAccessFile(file, "r");
fileChannel = raf.getChannel();
mappedByteBuffer = fileChannel.map(MapMode.READ_ONLY, 0L, len);
int bufferSize = 102400;
byte[] dest = new byte[bufferSize];
int blockNum = (int)len / bufferSize;
int leftSize = (int)len % bufferSize;
for(int blockOffset = 0; blockOffset < blockNum; ++blockOffset) {
mappedByteBuffer.get(dest, 0, bufferSize);
out.write(dest);
}
if (leftSize != 0) {
mappedByteBuffer.get(dest, 0, leftSize);
out.write(dest, 0, leftSize);
}
out.flush();
out.close();
} catch (Exception var19) {
log.error(var19.getMessage(), var19);
throw var19;
} finally {
try {
if (fileChannel != null) {
fileChannel.close();
}
if (raf != null) {
raf.close();
}
unmap(mappedByteBuffer);
} catch (Exception var18) {
log.error(var18);
}
}
}
private static void unmap(MappedByteBuffer buffer) {
if (buffer != null) {
Cleaner cleaner = ((DirectBuffer)buffer).cleaner();
if (cleaner != null) {
cleaner.clean();
}
}
}
private static String getHtmlContentType(String html) {
String contentType = null;
try {
ObjectFindingVisitor visitor = new ObjectFindingVisitor(MetaTag.class);
Parser parser = new Parser();
parser.setInputHTML(new String(html));
parser.visitAllNodesWith(visitor);
Node[] nodes = visitor.getTags();
MetaTag metaTag = null;
for(int i = 0; i < nodes.length; ++i) {
metaTag = (MetaTag)nodes[i];
String equiv = metaTag.getHttpEquiv();
if ("Content-Type".equalsIgnoreCase(equiv)) {
contentType = metaTag.getMetaContent();
break;
}
}
} catch (Exception var8) {
;
}
return contentType;
}
private static void downloadFromDisk(String path, HttpServletResponse response) throws IOException {
File file = new File(SuperKit.getFileAbsolutePath(path));
downloadFromDisk(file, response);
}
private static void downloadFromDisk(File file, HttpServletResponse response) throws IOException {
FileCopyUtils.copy(new FileInputStream(file), response.getOutputStream());
}
private static void downloadFromAliOSS(String path, HttpServletResponse response) throws IOException {
log.info("download file from aliyun oss path = " + path);
int start = "ALIYUN-OSS".length() + 1;
String objectName = path.substring(start);
log.info("download file from aliyun oss object name = " + objectName);
FileCopyUtils.copy(AliYunOSSUtils.getInstance().download(objectName), response.getOutputStream());
}
public static File downLoad(String srcFilePath, String destFilePath) {
log.info("download file : " + srcFilePath);
if (StringUtil.isEmpty(destFilePath)) {
destFilePath = SuperKit.getTempFileAbsolutePath(SuperKit.getUUID() + "." + FilenameUtils.getExtension(srcFilePath));
}
String[] fileInfo = unPackPath(srcFilePath);
if (!StringUtil.isEmpty(fileInfo[0]) && !fileInfo[0].equals("DISK")) {
if (fileInfo[0].equals("ALIYUN-OSS")) {
log.info("downlaod file dest path : " + destFilePath);
AliYunOSSUtils.getInstance().download(fileInfo[1], new File(destFilePath));
} else if (!fileInfo[0].equals("DB") && fileInfo[0].equals("TEMPLATE")) {
;
}
} else {
try {
writeFile(destFilePath, decryptFile(readFile(SuperKit.getFileAbsolutePath(fileInfo[1]))));
} catch (Exception var4) {
var4.printStackTrace();
}
}
return new File(destFilePath);
}
public static InputStream getInputStream(String path) throws FileNotFoundException {
String storage = getFileStorage(path);
if (StringUtil.isEmpty(storage)) {
return null;
} else {
File file;
if (storage.equalsIgnoreCase("DISK")) {
file = new File(SuperKit.getFileAbsolutePath(path));
return new FileInputStream(file);
} else if (storage.equalsIgnoreCase("ALIYUN-OSS")) {
int start = "ALIYUN-OSS".length() + 1;
String objectName = path.substring(start);
return AliYunOSSUtils.getInstance().download(objectName);
} else if (!storage.equalsIgnoreCase("DB") && "TEMPLATE".equals(storage)) {
file = new File(templatePath(path.substring("TEMPLATE".length() + 1)));
return new FileInputStream(file);
} else {
return null;
}
}
}
private static void write(HttpServletResponse response, String msg) {
response.setContentType("text/html;charset=utf-8");
PrintWriter out = null;
try {
out = response.getWriter();
out.println(msg);
} catch (IOException var12) {
log.error(var12.getMessage(), var12);
} finally {
try {
if (out != null) {
out.close();
}
} catch (Exception var11) {
log.error(var11.getMessage(), var11);
}
}
}
public static String copy(String srcFilePath, String destFilePath) throws IOException {
return copy(false, srcFilePath, destFilePath);
}
public static String copyTempFile(String srcFilePath, String destFilePath) throws IOException {
return copy(true, srcFilePath, destFilePath);
}
private static String copy(boolean srcIsTemp, String srcFilePath, String destFilePath) throws IOException {
String[] fileInfo = unPackPath(srcFilePath);
if (fileInfo[0].equals("TEMPLATE")) {
copyModuleTemplate(srcFilePath, destFilePath);
} else {
String storage = SuperKit.getStringFromDBConfig("SYS-ATTACH-0003");
if (StringUtil.isEmpty(storage) || "DISK".equalsIgnoreCase(storage)) {
String destFile = SuperKit.getFileAbsolutePath(destFilePath);
copy2Disk(srcIsTemp, srcFilePath, new File(destFile));
return destFilePath;
}
if (!"DB".equalsIgnoreCase(storage) && "ALIYUN-OSS".equalsIgnoreCase(storage)) {
return copy2AliOSS(srcFilePath, destFilePath);
}
}
return destFilePath;
}
public static void copyModuleTemplate(String srcFilePath, String destFilePath) throws IOException {
copy2DiskFromDisk(new File(templatePath(srcFilePath)), new File(templatePath(destFilePath)));
}
public static String generatorCopyDestFilePath(String destFilePath) {
String storage = SuperKit.getStringFromDBConfig("SYS-ATTACH-0003");
return !StringUtil.isEmpty(storage) && !"DISK".equalsIgnoreCase(storage) ? packPath(storage, destFilePath) : destFilePath;
}
public static void copy2Disk(boolean isTemp, String srcFilePath, File destFile) throws IOException {
String storage = getFileStorage(srcFilePath);
if (!StringUtil.isEmpty(storage)) {
if (storage.equalsIgnoreCase("DISK")) {
if (isTemp) {
srcFilePath = SuperKit.getTempFileAbsolutePath(srcFilePath);
} else {
srcFilePath = SuperKit.getFileAbsolutePath(srcFilePath);
}
copy2DiskFromDisk(new File(srcFilePath), destFile);
} else if (storage.equalsIgnoreCase("ALIYUN-OSS")) {
copy2DiskFromAliOSS(srcFilePath, destFile);
} else if (storage.equalsIgnoreCase("DB")) {
;
}
}
}
public static void copy2DiskFromDisk(File srcFile, File destFile) throws IOException {
try {
if (srcFile.exists()) {
FileUtils.copyFile(srcFile, destFile);
}
} catch (Exception var3) {
var3.printStackTrace();
throw new IOException();
}
}
public static void copy2DiskFromAliOSS(String objectName, File destFile) {
AliYunOSSUtils.getInstance().download(objectName, destFile);
}
public static String copy2AliOSS(String srcFilePath, String destFilePath) {
String storage = getFileStorage(srcFilePath);
if (StringUtil.isEmpty(storage)) {
return null;
} else {
if (storage.equalsIgnoreCase("DISK")) {
copy2AliOSSFromDisk(srcFilePath, destFilePath);
} else if (storage.equalsIgnoreCase("ALIYUN-OSS")) {
int start = "ALIYUN-OSS".length() + 1;
destFilePath = SuperKit.getTenantUnitId() + "/" + destFilePath;
copy2AliOSSFromAliOSS(srcFilePath.substring(start), destFilePath);
} else if (storage.equalsIgnoreCase("DB")) {
;
}
return packPath("ALIYUN-OSS", destFilePath);
}
}
public static void copy2AliOSSFromDisk(String srcFilePath, String objectName) {
srcFilePath = SuperKit.getFileAbsolutePath(srcFilePath);
AliYunOSSUtils.getInstance().upload(objectName, new File(srcFilePath));
}
public static void copy2AliOSSFromAliOSS(String srcObjectName, String destObjectName) {
AliYunOSSUtils.getInstance().copy(srcObjectName, destObjectName);
}
private static String getFileStorage(String srcFilePath) {
if (StringUtil.isNotEmpty(srcFilePath)) {
int index = srcFilePath.indexOf(":");
return index > 0 ? srcFilePath.substring(0, index) : "DISK";
} else {
return null;
}
}
public static String packPath(String storage, String path) {
return !StringUtil.isEmpty(storage) && !storage.equalsIgnoreCase("DISK") ? storage + ":" + path : path;
}
public static String[] unPackPath(String path) {
if (StringUtil.isEmpty(path)) {
return null;
} else {
String[] info = new String[2];
int start = path.indexOf(":");
if (start >= 0) {
info[0] = path.substring(0, start);
info[1] = path.substring(start + 1);
} else {
info[0] = "";
info[1] = path;
}
return info;
}
}
public static String getFileContentType(String type) {
String contentType = "";
if ("3gpp".equalsIgnoreCase(type)) {
contentType = "audio/3gpp, video/3gpp";
} else if ("ac3".equalsIgnoreCase(type)) {
contentType = "audio/ac3";
} else if ("asf".equalsIgnoreCase(type)) {
contentType = "allpication/vnd.ms-asf";
} else if ("au".equalsIgnoreCase(type)) {
contentType = "audio/basic";
} else if ("css".equalsIgnoreCase(type)) {
contentType = "text/css";
} else if ("csv".equalsIgnoreCase(type)) {
contentType = "text/csv";
} else if ("doc".equalsIgnoreCase(type)) {
contentType = "application/msword";
} else if ("dot".equalsIgnoreCase(type)) {
contentType = "application/msword";
} else if ("dtd".equalsIgnoreCase(type)) {
contentType = "application/xml-dtd";
} else if ("dwg".equalsIgnoreCase(type)) {
contentType = "image/vnd.dwg";
} else if ("dxf".equalsIgnoreCase(type)) {
contentType = "image/vnd.dxf";
} else if ("gif".equalsIgnoreCase(type)) {
contentType = "image/gif";
} else if ("htm".equalsIgnoreCase(type)) {
contentType = "text/html";
} else if ("html".equalsIgnoreCase(type)) {
contentType = "text/html";
} else if ("jp2".equalsIgnoreCase(type)) {
contentType = "image/jp2";
} else if ("jpe".equalsIgnoreCase(type)) {
contentType = "image/jpeg";
} else if ("jpeg".equalsIgnoreCase(type)) {
contentType = "image/jpeg";
} else if ("jpg".equalsIgnoreCase(type)) {
contentType = "image/jpeg";
} else if ("js".equalsIgnoreCase(type)) {
contentType = "text/javascript, application/javascript";
} else if ("json".equalsIgnoreCase(type)) {
contentType = "application/json";
} else if ("mp2".equalsIgnoreCase(type)) {
contentType = "audio/mpeg, video/mpeg";
} else if ("mp3".equalsIgnoreCase(type)) {
contentType = "audio/mpeg";
} else if ("mp4".equalsIgnoreCase(type)) {
contentType = "video/mp4";
} else if ("mpeg".equalsIgnoreCase(type)) {
contentType = "video/mpeg";
} else if ("mpg".equalsIgnoreCase(type)) {
contentType = "video/mpeg";
} else if ("mpp".equalsIgnoreCase(type)) {
contentType = "application/vnd.ms-project";
} else if ("ogg".equalsIgnoreCase(type)) {
contentType = "application/ogg, audio/ogg";
} else if ("pdf".equalsIgnoreCase(type)) {
contentType = "application/pdf";
} else if ("png".equalsIgnoreCase(type)) {
contentType = "image/png";
} else if ("bmp".equalsIgnoreCase(type)) {
contentType = "image/bmp";
} else if ("pot".equalsIgnoreCase(type)) {
contentType = "application/vnd.ms-powerpoint";
} else if ("pps".equalsIgnoreCase(type)) {
contentType = "application/vnd.ms-powerpoint";
} else if ("ppt".equalsIgnoreCase(type)) {
contentType = "application/vnd.ms-powerpoint";
} else if ("rtf".equalsIgnoreCase(type)) {
contentType = "application/rtf, text/rtf";
} else if ("svf".equalsIgnoreCase(type)) {
contentType = "image/vnd.svf";
} else if ("tif".equalsIgnoreCase(type)) {
contentType = "image/tiff";
} else if ("tiff".equalsIgnoreCase(type)) {
contentType = "image/tiff";
} else if ("txt".equalsIgnoreCase(type)) {
contentType = "text/plain";
} else if ("wdb".equalsIgnoreCase(type)) {
contentType = "application/vnd.ms-works";
} else if ("wps".equalsIgnoreCase(type)) {
contentType = "application/vnd.ms-works";
} else if ("xhtml".equalsIgnoreCase(type)) {
contentType = "application/xhtml+xml";
} else if ("xlc".equalsIgnoreCase(type)) {
contentType = "application/vnd.ms-excel";
} else if ("xlm".equalsIgnoreCase(type)) {
contentType = "application/vnd.ms-excel";
} else if ("xls".equalsIgnoreCase(type)) {
contentType = "application/vnd.ms-excel";
} else if ("xlt".equalsIgnoreCase(type)) {
contentType = "application/vnd.ms-excel";
} else if ("xlw".equalsIgnoreCase(type)) {
contentType = "application/vnd.ms-excel";
} else if ("xml".equalsIgnoreCase(type)) {
contentType = "text/xml, application/xml";
} else if ("zip".equalsIgnoreCase(type)) {
contentType = "aplication/zip";
} else if ("xlsx".equalsIgnoreCase(type)) {
contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
} else if ("xltx".equalsIgnoreCase(type)) {
contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.template";
} else if ("potx".equalsIgnoreCase(type)) {
contentType = "application/vnd.openxmlformats-officedocument.presentationml.template";
} else if ("ppsx".equalsIgnoreCase(type)) {
contentType = "application/vnd.openxmlformats-officedocument.presentationml.slideshow";
} else if ("pptx".equalsIgnoreCase(type)) {
contentType = "application/vnd.openxmlformats-officedocument.presentationml.presentation";
} else if ("sldx".equalsIgnoreCase(type)) {
contentType = "application/vnd.openxmlformats-officedocument.presentationml.slide";
} else if ("docx".equalsIgnoreCase(type)) {
contentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
} else if ("dotx".equalsIgnoreCase(type)) {
contentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.template";
} else if ("xlsm".equalsIgnoreCase(type)) {
contentType = "application/vnd.ms-excel.addin.macroEnabled.12";
} else if ("xlsb".equalsIgnoreCase(type)) {
contentType = "application/vnd.ms-excel.sheet.binary.macroEnabled.12";
} else if ("ofd".equalsIgnoreCase(type)) {
contentType = "application/ofd";
}
return contentType;
}
public static void writeFile(String filePath, byte[] data) throws IOException {
RandomAccessFile raf = null;
try {
raf = new RandomAccessFile(filePath, "rw");
raf.write(data);
} finally {
if (raf != null) {
raf.close();
}
}
}
public static byte[] readFile(String filePath) throws IOException {
RandomAccessFile raf = null;
byte[] var3;
try {
raf = new RandomAccessFile(filePath, "r");
byte[] data = new byte[(int)raf.length()];
raf.read(data);
var3 = data;
} finally {
if (raf != null) {
raf.close();
}
}
return var3;
}
public static byte[] encryptFile(byte[] data) throws Exception {
String encryptMode = SuperKit.getStringFromDBConfig("SYS-ATTACH-0006");
if ("2".equals(encryptMode)) {
data = SM2Util.encrypt(SM2Util.PUBLIC_KEY, data);
} else if ("3".equals(encryptMode)) {
data = SM4Util.encrypt_Ecb_Padding(SM4Util.KEY, data);
}
return data;
}
public static byte[] decryptFile(byte[] data) throws Exception {
String encryptMode = SuperKit.getStringFromDBConfig("SYS-ATTACH-0006");
if ("2".equals(encryptMode)) {
data = SM2Util.decrypt(SM2Util.PRIVATE_KEY, data);
} else if ("3".equals(encryptMode)) {
data = SM4Util.decrypt_Ecb_Padding(SM4Util.KEY, data);
}
return data;
}
public static void addActLog(String infoId, User currentUser, String content, String logType, String subType, IContextDictionary dict) {
ActlogEntity log = (ActlogEntity)loggerService.initEntity(ActlogEntity.class);
log.setInfoId(infoId);
log.setLogType(logType);
log.setContent(content);
log.setSubType(subType);
loggerService.send(log, currentUser, dict);
}
public static String getFileExtensionIcon(String fileName) {
String icon = "cloud1";
if (StringUtil.isNotBlank(fileName)) {
String extension = FilenameUtils.getExtension(fileName).toLowerCase();
if (!"doc".equals(extension) && !"docx".equals(extension) && !"wps".equals(extension) && !"word".equals(extension) && !"rtf".equals(extension)) {
if (!"xls".equals(extension) && !"xlsx".equals(extension) && !"csv".equals(extension)) {
if (!"mp3".equals(extension) && !"aif".equals(extension) && !"au".equals(extension) && !"wav".equals(extension)) {
if (!"rmvb".equals(extension) && !"mp4".equals(extension) && !"avi".equals(extension) && !"mov".equals(extension) && !"flv".equals(extension) && !"rm".equals(extension) && !"swf".equals(extension) && !"mpg".equals(extension) && !"mpeg".equals(extension)) {
if (!"jpg".equals(extension) && !"jpeg".equals(extension)) {
if ("gif".equals(extension)) {
icon = "img";
} else if ("png".equals(extension)) {
icon = "png";
} else if ("bmp".equals(extension)) {
icon = "img";
} else if ("pdf".equals(extension)) {
icon = "pdf";
} else if (!"xml".equals(extension)) {
if (!"ppt".equals(extension) && !"pptx".equals(extension)) {
if (!"dps".equals(extension) && !"et".equals(extension) && !"ofd".equals(extension) && !"ceb".equals(extension) && !"tif".equals(extension) && !"tiff".equals(extension)) {
if ("rar".equals(extension)) {
icon = "rar";
} else if (!"accdb".equals(extension) && !"mdb".equals(extension) && !"mde".equals(extension)) {
if ("psd".equals(extension)) {
icon = "psd";
} else if (!"folder".equals(extension)) {
if ("swf".equals(extension)) {
icon = "mp4";
} else if ("txt".equals(extension)) {
icon = "txt";
} else if ("zip".equals(extension)) {
icon = "zip";
}
}
}
}
} else {
icon = "ppt";
}
}
} else {
icon = "jpg";
}
} else {
icon = "mp1";
}
} else {
icon = "mp";
}
} else {
icon = "xls";
}
} else {
icon = "DOc";
}
}
return icon;
}
}