Commit 75adc8ae authored by chase's avatar chase

merge 档案管理

parent 60e6de64
......@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;
import net.sf.json.JSONNull;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
......@@ -30,10 +31,7 @@ import pwc.taxtech.atms.thirdparty.ExcelUtil;
import pwc.taxtech.atms.vat.entity.FileUpload;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLDecoder;
......@@ -112,6 +110,47 @@ public class TaxDocumentController {
//地址示例: D://multipaiInitData
return taxDocumentService.multipalInitData(address);
}
/**
* 读取PDF 使用base64 解析
*
*/
@PostMapping("/previewPDF")
@ResponseBody
public String previewPDF(@RequestBody TaxDocumentDto taxDocumentDto) {
InputStream is = null;
ByteArrayOutputStream os = null;
try {
//根据url地址 获取文件输入流
is = getInputStreamByUrl(taxDocumentDto.getPath());
os = new ByteArrayOutputStream();
byte[] buff = new byte[1024];
int len = 0;
String dUrlData="";
while ((len = is.read(buff)) != -1) {
os.write(buff, 0, len);
}
//刷新此输出流并强制写出所有缓冲的输出字节,必须这行代码,否则有可能有问题
os.flush();
os.toByteArray();
dUrlData= Base64.encode(os.toByteArray());
return dUrlData;
} catch (Exception e) {
e.printStackTrace();
return null;
}finally {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
try {
os.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
@RequestMapping("exportExcel")
@ResponseBody
public void exportExcelFile(HttpServletResponse response, @RequestBody TaxDocumentDto taxDocumentDto) {
......@@ -219,6 +258,7 @@ public class TaxDocumentController {
}
}
/**
* 下载全部附件
*/
......
......@@ -405,6 +405,22 @@ taxDocumentManageModule.controller('taxDocumentListController',
}
}
};
//查询条件-根据文件属性来匹配出 文件类型
$scope.queryFileAttr = function (curAttr) {
if(curAttr){
$scope.fileTypeOptions.length=0;
Object.keys($scope.typeAndAttrMap).forEach(function (key) {
if (curAttr === $scope.typeAndAttrMap[key]) {
$scope.fileTypeOptions.push(key);
}
});
}else{
Object.keys($scope.typeAndAttrMap).forEach(function (key) {
$scope.fileTypeOptions.push(key);
});
}
$scope.queryFieldModel.fileType="";
};
//弹出框
$scope.isCreatePop = false;
var openSimpleUploadPop = function (rowId) {
......@@ -1541,7 +1557,7 @@ taxDocumentManageModule.directive('filePreview', function () {
taxDocumentManageModule.directive('pdfPreview', function () {
return {
restrict: 'EA',
controller: ['$scope', function ($scope) {
controller: ['$scope','taxDocumentListService', function ($scope,taxDocumentListService) {
window.PDFJS.workerSrc = './bundles/pdf.worker.js';
var canvas = document.getElementById('the-canvas');
var context = canvas.getContext('2d');
......@@ -1550,7 +1566,7 @@ taxDocumentManageModule.directive('pdfPreview', function () {
var container = document.getElementById("pdfLayoutDialog");
var pdfPromise = null;
var cacheUrl = null;
$scope.openPdfPreviewPop = function (url) {
$scope.openPdfPreviewPop_bak = function (url) {
container.style.display = "block";
if (cacheUrl !== url) {
cacheUrl = url;
......@@ -1560,7 +1576,48 @@ taxDocumentManageModule.directive('pdfPreview', function () {
renderPdf(pdf)
})
};
$scope.openPdfPreviewPop = function (url) {
container.style.display = "block";
function start() {
return new Promise(function (resolve, reject){
resolve('start');
});
}
start().then(function(data) {
console.log('result of start: ', data);
return taxDocumentListService.readPDF({path:url});
}).then(function(dataURL) {
var pdfData=null;
if(typeof dataURL =="string"){
pdfData = convertDataURIToBinary(dataURL);
}
console.log(pdfData);
return window.PDFJS.getDocument({data:pdfData});
}).then(function(data) {
pdfSumPages = data.numPages;
return data.getPage(pdfCurPageIndex);
}).then(function(page){
var scale = 1.5;
var viewport = page.getViewport(scale);
canvas.height = viewport.height;
canvas.width = viewport.width;
var renderContext = {
canvasContext: context,
viewport: viewport
};
page.render(renderContext);
});
};
function convertDataURIToBinary(dataURI) { //将encodeBase64解码
var raw = window.atob(dataURI);
var rawLength = raw.length;
//转换成pdf.js能直接解析的Uint8Array类型,见pdf.js-4068
var array = new Uint8Array(new ArrayBuffer(rawLength));
for(var i = 0; i < rawLength; i++) {
array[i] = raw.charCodeAt(i);
}
return array;
}
$scope.closePdfPop = function () {
container.style.display = "none";
};
......@@ -1578,7 +1635,6 @@ taxDocumentManageModule.directive('pdfPreview', function () {
renderPdf(pdf)
})
};
function getPdf(url) {
// var url = 'http://47.94.233.173:11007/static/erp_tax_system/61063D1D-8C9E-47C1-B106-AFF696CF5D98?expire=1552466477&signiture=5IaoVIHX_pzmQgyaxdzYC2NsNOz_R0eyRUhQU1BJjiE=';
return window.PDFJS.getDocument(url);
......
......@@ -378,19 +378,14 @@
<span translate="DocumentAttr"></span>
</div>
<div class="TDL-query-val">
<select ng-model="queryFieldModel.fileAttr"
class="form-control radius3" style="width:85%"
<select ng-model="queryFieldModel.fileAttr" ng-change="queryFileAttr(queryFieldModel.fileAttr)"
class="form-control radius3"
placeholder="{{'PleaseSelected' | translate}}">
<option value=""></option>
<option ng-repeat="fileAttr in fileAttrOptions track by $index"
value="{{fileAttr}}">{{fileAttr}}
</option>
</select>
<div class="DTL-special-external-btn" title="查看类型列表">
<a href="javascript:void(0)" ng-click="openHelpPop(queryFieldModel)">
<i class="fa fake-question-circle" aria-hidden="true"></i>
</a>
</div>
<!--<input type="text" class="form-control radius3"-->
<!--ng-model="queryFieldModel.fileAttr"/>-->
</div>
......
......@@ -133,6 +133,9 @@ taxDocumentManageModule.factory('taxDocumentListService',
readXLSX:function(params){
return jqFetch.post(apiInterceptor.webApiHostUrl + '/taxDoc/previewExcelToJson', params);
},
readPDF:function(params){
return jqFetch.post(apiInterceptor.webApiHostUrl + '/taxDoc/previewPDF', params);
},
getBinaryData:function(url){
var defer = $q.defer();
var oReq = new XMLHttpRequest();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment