|
@@ -2,6 +2,7 @@ package com.jeeplus.pubmodules.oss.service;
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.extra.spring.SpringUtil;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.aliyun.oss.OSSClient;
|
|
|
import com.aliyun.oss.model.OSSObject;
|
|
@@ -20,6 +21,7 @@ import com.jeeplus.pubmodules.oss.service.dto.FileUrlDto;
|
|
|
import com.jeeplus.pubmodules.oss.service.dto.WorkAttachmentDto;
|
|
|
import com.jeeplus.sys.domain.WorkAttachmentInfo;
|
|
|
import com.jeeplus.sys.feign.IUserApi;
|
|
|
+import com.jeeplus.sys.feign.IWorkAttachmentApi;
|
|
|
import com.jeeplus.sys.service.dto.UserDTO;
|
|
|
import com.jeeplus.sys.service.dto.WorkAttachmentInfoDTO;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -31,12 +33,19 @@ import org.springframework.security.core.Authentication;
|
|
|
import org.springframework.security.core.context.SecurityContextHolder;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
+import org.w3c.dom.Document;
|
|
|
+import org.w3c.dom.Node;
|
|
|
+import org.w3c.dom.NodeList;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
+import javax.xml.parsers.DocumentBuilder;
|
|
|
+import javax.xml.parsers.DocumentBuilderFactory;
|
|
|
import java.io.BufferedInputStream;
|
|
|
import java.io.BufferedOutputStream;
|
|
|
+import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
import java.net.URL;
|
|
|
import java.net.URLEncoder;
|
|
@@ -548,4 +557,164 @@ public class OssService extends ServiceImpl<OssServiceMapper, WorkAttachment> {
|
|
|
public void deleteByAttachmentIdNotInIds(String attachmentId, List<String> delIds) {
|
|
|
ossServiceMapper.deleteByAttachmentIdNotInIds(attachmentId,delIds);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ public Map<String,Object> downLoadFileDisposeXmlFile(String file) {
|
|
|
+ file = "http://oss.gangwaninfo.com" + file;
|
|
|
+ file = file.replace("amp;", "");
|
|
|
+ String fileName = file.substring(file.lastIndexOf("/") + 1, file.length());
|
|
|
+ String cons = "";
|
|
|
+ if (file.contains(aliyunUrl)) {
|
|
|
+ cons = aliyunUrl;
|
|
|
+ } else if (file.contains("http://gangwan-app.oss-cn-hangzhou.aliyuncs.com")) {
|
|
|
+ cons = "http://gangwan-app.oss-cn-hangzhou.aliyuncs.com";
|
|
|
+ } else {
|
|
|
+ cons = aliyunDownloadUrl;
|
|
|
+ }
|
|
|
+ String key = file.split(cons + "/")[1];
|
|
|
+ log.info("-----------------------------------------");
|
|
|
+ log.info("fileName=" + fileName);
|
|
|
+ log.info("key=" + key);
|
|
|
+ log.info("-----------------------------------------");
|
|
|
+
|
|
|
+ String path = null;
|
|
|
+ if(System.getProperty("os.name").toLowerCase().contains("win")){
|
|
|
+ path = "D:/attachment-file/";
|
|
|
+ }else{
|
|
|
+ path = "/attachment-file/";
|
|
|
+ }
|
|
|
+ ossClientService.downByStreamSaveLocal(key, fileName, path+fileName);
|
|
|
+
|
|
|
+ Map<String,Object> map = new HashMap();
|
|
|
+ //创建DOM4J解析器对象
|
|
|
+ File newFile = new File(path + fileName);
|
|
|
+ try {
|
|
|
+ //MultipartFile转File
|
|
|
+ //newFile = FileUtil.transformMultipartFile(file);
|
|
|
+ // 创建一个 DocumentBuilderFactory
|
|
|
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
|
|
+ // 使用工厂创建一个 DocumentBuilder
|
|
|
+ DocumentBuilder builder = factory.newDocumentBuilder();
|
|
|
+ // 使用 DocumentBuilder 解析 XML 文件
|
|
|
+ Document document = builder.parse(newFile);
|
|
|
+ // 获取所有header节点的集合
|
|
|
+ NodeList headerList = document.getElementsByTagName("Header");
|
|
|
+ // 获取所有eInvoiceDataList节点的集合
|
|
|
+ NodeList eInvoiceDataList = document.getElementsByTagName("EInvoiceData");
|
|
|
+ // 获取所有taxSupervisionInfo节点的集合
|
|
|
+ NodeList taxSupervisionInfoList = document.getElementsByTagName("TaxSupervisionInfo");
|
|
|
+
|
|
|
+ Map<String,String> map1 = xmlNodeListDataDispose(headerList, document);
|
|
|
+ Map<String,String> map2 = xmlNodeListDataDispose(eInvoiceDataList, document);
|
|
|
+ Map<String,String> map3 = xmlNodeListDataDispose(taxSupervisionInfoList, document);
|
|
|
+ map.putAll(map1);
|
|
|
+ map.putAll(map2);
|
|
|
+ map.putAll(map3);
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }finally {
|
|
|
+ newFile.delete();
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 对节点集合进行遍历,并获取每个节点下的参数信息
|
|
|
+ * @param nodeList
|
|
|
+ * @param document
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Map<String,String> xmlNodeListDataDispose(NodeList nodeList,Document document){
|
|
|
+ Map<String,String> map = new HashMap<>();
|
|
|
+ if(null != nodeList && nodeList.getLength()>0){
|
|
|
+ //遍历每一个header节点
|
|
|
+ for (int i = 0; i < nodeList.getLength(); i++) {
|
|
|
+ //通过 item(i)方法 获取一个header节点,nodelist的索引值从0开始
|
|
|
+ Node header = nodeList.item(i);
|
|
|
+ //解析定义节点的子节点
|
|
|
+ NodeList childNodes = header.getChildNodes();
|
|
|
+ //节点数据处理
|
|
|
+ Map<String,String> map1 = xmlDataDispose(childNodes, document);
|
|
|
+ map.putAll(map1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 子节点遍历获取参数,若其下还有子节点,则循环调用 xmlNodeListDataDispose 方法
|
|
|
+ * @param childNodes
|
|
|
+ * @param document
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Map<String,String> xmlDataDispose(NodeList childNodes,Document document){
|
|
|
+ Map<String,String> map = new HashMap<>();
|
|
|
+ for (int k = 0; k < childNodes.getLength(); k++) {
|
|
|
+ // 区分出text类型的node以及element类型的node
|
|
|
+ if (childNodes.item(k).getNodeType() == Node.ELEMENT_NODE) {
|
|
|
+ Node firstChild = childNodes.item(k).getFirstChild();
|
|
|
+ if(null != firstChild){
|
|
|
+ if(StringUtils.isBlank(childNodes.item(k).getFirstChild().getNodeValue())){
|
|
|
+ // 获取所有header节点的集合
|
|
|
+ NodeList childList = document.getElementsByTagName(childNodes.item(k).getNodeName());
|
|
|
+
|
|
|
+ String parentName = childNodes.item(k).getNodeName();
|
|
|
+ //循环调用,获取最低级节点数据信息
|
|
|
+ Map<String,String> map1 = xmlNodeListDataDispose(childList, document);
|
|
|
+ Map<String,String> map2 = new HashMap<>();
|
|
|
+ if(map1.size()>0){
|
|
|
+ //将获取到的数据进行遍历,添加父节点的参数信息,防止子节点key键相同,导致数据被覆盖
|
|
|
+ for (String key : map1.keySet()) {
|
|
|
+ if(key.contains("-")){
|
|
|
+ String newKey = key.replaceAll("-","");
|
|
|
+ map2.put(parentName + newKey,map1.get(key));
|
|
|
+ }else{
|
|
|
+ map2.put(parentName + key,map1.get(key));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ map.putAll(map2);
|
|
|
+ }
|
|
|
+ //判定key 和value 值均存在,则进行储存,否则不进行储存
|
|
|
+ if(StringUtils.isNotBlank(childNodes.item(k).getNodeName()) && StringUtils.isNotBlank(childNodes.item(k).getFirstChild().getNodeValue())){
|
|
|
+ map.put(childNodes.item(k).getNodeName(),childNodes.item(k).getFirstChild().getNodeValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @param attachmentIdList
|
|
|
+ * @param type 代表处理类型,不同类型代表不同的分公司的报销数据:1、评估;2、会计;3、ccpm;4、中审;5、咨询
|
|
|
+ */
|
|
|
+ public Map<String,String> disposeElectronicEngineeringInvoice(List<String> attachmentIdList, String type){
|
|
|
+ Map<String,String> map = new HashMap<>();
|
|
|
+ //首先获取所有数电发票报销信息
|
|
|
+ List<WorkAttachmentInfo> attachmentList = ossServiceMapper.getElectronicEngineeringInvoiceAttachmentList(attachmentIdList,"");
|
|
|
+ //遍历所有附件发票信息,并将其下载到本地固定文件夹,并对下载的文件进行数据解析
|
|
|
+ try{
|
|
|
+ for (WorkAttachmentInfo attachmentInfo : attachmentList) {
|
|
|
+ if(attachmentInfo.getUrl().contains(".xml")){
|
|
|
+ Map<String, Object> stringObjectMap = this.downLoadFileDisposeXmlFile(attachmentInfo.getUrl());
|
|
|
+ String invoiceNumber = (String) stringObjectMap.get("InvoiceNumber");
|
|
|
+ String buyerInformationBuyerName = (String) stringObjectMap.get("BuyerInformationBuyerName");
|
|
|
+ if(StringUtils.isNotBlank(invoiceNumber) && StringUtils.isNotBlank(buyerInformationBuyerName)){
|
|
|
+ map.put(invoiceNumber,buyerInformationBuyerName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.getMessage();
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
}
|