Commit c5517275 authored by frank.xa.zhang's avatar frank.xa.zhang

fixed report display issue

parent d62b1024
......@@ -14,6 +14,7 @@ import pwc.taxtech.atms.service.TemplateService;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.net.URISyntaxException;
import java.util.Collections;
import java.util.List;
......@@ -34,37 +35,37 @@ public class TemplateController {
@RequestMapping(value = "get", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public @ResponseBody
List<TemplateDto> get(@RequestParam String templateGroupID, @RequestParam Integer reportType) {
List<TemplateDto> get(@RequestParam String templateGroupID, @RequestParam String reportType) {
if (StringUtils.isEmpty(templateGroupID)) {
return Collections.emptyList();
}
try {
return templateService.get(templateGroupID, reportType);
return templateService.get(templateGroupID, (reportType != null && !reportType.equals("null")) ? Integer.parseInt(reportType) : null);
} catch (Exception e) {
logger.error("GetCellConfigList", e);
}
return Collections.emptyList();
}
@RequestMapping(value = "getTemplateJson", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@RequestMapping(value = "getTemplateJson", method = RequestMethod.POST, produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
public @ResponseBody
void getTemplateBlob(@RequestParam String templateID, HttpServletResponse response) {
void getTemplateBlob(@RequestParam String templateID, HttpServletResponse response) throws URISyntaxException {
String filePath;
File templateFile;
InputStream inputStream = null;
String templatePath = templateService.getTemplatePath(templateID);
if(StringUtils.isEmpty(templateID))
{
if (StringUtils.isEmpty(templateID)) {
return;
}
if (templatePath==null||StringUtils.isEmpty(templatePath)){
if (templatePath == null || StringUtils.isEmpty(templatePath)) {
return;
}
filePath = this.getClass().getResource("/").getPath();
templateFile = new File(filePath + templateService.getTemplatePath(templateID));
filePath = this.getClass().getResource("").toURI().getPath();
String tempPath = filePath.substring(0,filePath.indexOf("classes")+"\\classes".length());
templateFile = new File(tempPath + templateService.getTemplatePath(templateID));
try {
inputStream = new BufferedInputStream(new FileInputStream(templateFile));
......@@ -72,7 +73,14 @@ public class TemplateController {
String customFileName = "template_" + DateTime.now().toString("yyyyMMddHHmmss") + ".xlsx";
response.setHeader("Content-Disposition", String.format("inline; filename=\"" + customFileName + "\""));
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
FileCopyUtils.copy(inputStream, response.getOutputStream());
int len=0;
byte[] buffer = new byte[1024];
OutputStream out = response.getOutputStream();
while ((len=inputStream.read(buffer))>0){
out.write(buffer,0,len);
}
//FileCopyUtils.copy(inputStream, response.getOutputStream());
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (Exception e) {
......
......@@ -120,20 +120,20 @@ public final class TemplateDto {
this.code = code;
}
public boolean isSystemType() {
return isSystemType;
public boolean getIsSystemType() {
return this.isSystemType;
}
public void setSystemType(boolean systemType) {
isSystemType = systemType;
public void setIsSystemType(boolean isSystemType) {
this.isSystemType = isSystemType;
}
public boolean isActiveAssociation() {
return isActiveAssociation;
public boolean getIsActiveAssociation() {
return this.isActiveAssociation;
}
public void setActiveAssociation(boolean activeAssociation) {
isActiveAssociation = activeAssociation;
public void setIsActiveAssociation(boolean isActiveAssociation) {
this.isActiveAssociation = isActiveAssociation;
}
public List<CellTemplateDto> getCellTemplateDtos() {
......
......@@ -43,7 +43,7 @@ public class TemplateServiceImpl extends AbstractService implements TemplateServ
if (template != null) {
if (template.getPath().startsWith("~")) {
result = template.getPath().substring(1, template.getPath().length() - 1);
result = template.getPath().substring(1, template.getPath().length());
} else {
result = template.getPath();
}
......
......@@ -7,6 +7,6 @@ mail_jdbc_user=sa
mail_jdbc_password=atmsunittestSQL
web.url=http://localhost:8080
#web.url=*
jwt.base64Secret=TXppQjFlZFBSbnJzMHc0Tg==
jwt.powerToken=xxxx
\ No newline at end of file
......@@ -274,6 +274,10 @@ grunt.initConfig({
src: ["Scripts/spreadjs/gc.spread.sheets.all.11.0.0.min.js"],
dest: '<%= pkg.bundleDest %>/spread.js'
},
spreadiojs: {
src: ["Scripts/spreadjs/interop/gc.spread.excelio.11.0.0.min.js"],
dest: '<%= pkg.bundleDest %>/spreadio.js'
},
ivhTreeview: {
src: ["Scripts/angular-ivh-treeview/ivh-treeview.js",
"Scripts/angular-notify/angular-notify.js",
......
......@@ -95,6 +95,7 @@
<script type="text/javascript" src="bundles/spread.js"></script>
<script type="text/javascript" src="bundles/ivh-treeview.js"></script>
<script type="text/javascript" src="bundles/ui-select.js"></script>
<script type="text/javascript" src="bundles/spreadio.js"></script>
<script type="text/javascript">
//window.location.href = '/Home/Admin/#/userDetail/808b7a8c-0265-4497-9adb-6b7a757bd2f2';
......
// web service proxy for standard account
webservices.factory('templateService', ['$log', '$http', '$q', 'apiConfig', 'httpCacheService', '$timeout', '$rootScope', '$interval',
function ($log, $http, $q, apiConfig, httpCacheService, $timeout, $rootScope, $interval) {
webservices.factory('templateService', ['$log', '$http', '$q', 'apiConfig', 'httpCacheService', '$timeout', '$rootScope', '$interval', 'loginContext',
function ($log, $http, $q, apiConfig, httpCacheService, $timeout, $rootScope, $interval, loginContext) {
'use strict';
var getCookie = function (cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i].trim();
// if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
if (c.indexOf(name) == 0) return ATMS_EXTRA.decodeCookieValue(c.substring(name.length, c.length));
}
return "";
};
var getTemplateJson = function (templateID) {
//return $http.get('/template/getTemplateJson?templateID=' + templateID, apiConfig.create());
// var result = httpCacheService.get('/template/getTemplateJson?templateID=' + templateID);
// if (result.finishedCache) {
// return result;
// } else {
var thisConfig = apiConfig.create();
thisConfig.responseType = "arraybuffer";
$http.post('/template/getTemplateJson?templateID=' + templateID, {}, apiConfig.create()).then(function (response) {
var data = new Blob([response.data], {type: response.headers('Content-Type')});
return data;
});
// var thisConfig = apiConfig.create();
// thisConfig.responseType = "blob";
// return $http.post('/template/getTemplateJson?templateID=' + templateID, {}, apiConfig.create());
// }
var deferred = $q.defer();
var promise = deferred.promise;
// var ajaxUrl = loginContext.apiHost + constant.webapi.prefix + '/template/getTemplateJson?templateID=' + templateID;
// var apiTokenObj = JSON.parse(getCookie('AtmsApiToken'));
// var apiToken = apiTokenObj.access_token;
// var tokenType = apiTokenObj.token_type;
// var ajaxSource = $.ajax({
// url: ajaxUrl,
// type: "POST",
// dataType:"blob",
// beforeSend: function (xhr) {
// xhr.setRequestHeader('Authorization', tokenType + ' ' + apiToken);
// //xhr.setRequestHeader('from', 'aabb@cn.pwc.com');
// //xhr.responseType = "blob";
// },
// success: function(data){
// deferred.resolve(data);
// },
// complete: function(data){
// deferred.resolve(data.responseText);
// }
// });
// ajaxSource.done(function (data) {
// deferred.resolve(data);
// });
return promise;
};
var initSpreadExcel = function (id, ssjsondata) {
......@@ -22,7 +58,7 @@ webservices.factory('templateService', ['$log', '$http', '$q', 'apiConfig', 'htt
var deferred = $q.defer();
var promise = deferred.promise;
var spread = new GC.Spread.Sheets.Spread(document.getElementById(id));
var spread = new GC.Spread.Sheets.Workbook(document.getElementById(id));
spread.showVerticalScrollbar(true);
spread.showHorizontalScrollbar(true);
spread.scrollbarMaxAlign(true);
......@@ -32,23 +68,23 @@ webservices.factory('templateService', ['$log', '$http', '$q', 'apiConfig', 'htt
spread.tabEditable(false);
spread.tabStripVisible(false);
spread.newTabVisible(false);
spread.allowUndo(false);
spread.allowUserResize(false);
spread.canUserDragDrop(false);
spread.canUserDragFill(false);
spread.canUserEditFormula(false);
spread.isPaintSuspended(true);
spread.fromJSON(JSON.parse(ssjsondata));
spread.isPaintSuspended(false);
// spread.allowUndo(false);
// spread.allowUserResize(false);
// spread.canUserDragDrop(false);
// spread.canUserDragFill(false);
// spread.canUserEditFormula(false);
//
// spread.isPaintSuspended(true);
// spread.fromJSON(JSON.parse(ssjsondata));
// spread.isPaintSuspended(false);
var sheet = spread.getActiveSheet();
if (sheet != null) {
sheet.setRowHeaderVisible(true);
sheet.setColumnHeaderVisible(true);
sheet.setGridlineOptions({
showVerticalGridline: false, showHorizontalGridline: false
});
// sheet.setRowHeaderVisible(true);
// sheet.setColumnHeaderVisible(true);
// sheet.setGridlineOptions({
// showVerticalGridline: false, showHorizontalGridline: false
// });
}
deferred.resolve(spread);
......@@ -60,21 +96,63 @@ webservices.factory('templateService', ['$log', '$http', '$q', 'apiConfig', 'htt
var promise = deferred.promise;
var spreadSheet;
getTemplateJson(templateID).success(function (result) {
var url = loginContext.apiHost + constant.webapi.prefix+'/template/getTemplateJson?templateID=' + templateID;
var xhr = new XMLHttpRequest();
xhr.open('POST', url, true); // 也可以使用POST方式,根据接口
xhr.responseType = "blob"; // 返回类型blob
var apiTokenObj = JSON.parse(getCookie('AtmsApiToken'));
var apiToken = apiTokenObj.access_token;
var tokenType = apiTokenObj.token_type;
xhr.setRequestHeader('Authorization', tokenType + ' ' + apiToken);
// xhr.setRequestHeader("Authorization","bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZG1pbiIsImV4cCI6MTUyNzMxNDA4NCwiaWF0IjoxNTI3MTQxMjg0LCJuYmYiOjE1MjcxNDA2ODQsImp0aSI6IjVGM0FGMTBDLTdFMEEtNDVDQy04RDVGLUREMTBFMDRCOUY4NCIsInVzZXJuYW1lIjoiYWRtaW4iLCJkYXRhYmFzZVVzZXJuYW1lIjoiQWRtaW4iLCJ1c2VyaWQiOiI2NjkzM0U3Qi1EQTc1LTRCMkUtQjdENi1BQjY1RENBMjBENTAifQ.M-dyU6W51LAPVQ66HIJZ-KAg6WjPSIt1GqpOc6etQ6XJfXp8KkUPA6A8qPZ8bhydWsKKMqpPlx-KRVhK2o5q0Q")
// 定义请求完成的处理函数,请求前也可以增加加载框/禁用下载按钮逻辑
xhr.onload = function () {
// 请求完成
if (this.status === 200) {
// 返回200
var blob = this.response;
var excelIo = new GC.Spread.Excel.IO();
excelIo.open(result, function (json) {
var workbookObj = json;
excelIo.open(blob, function (json) {
//var workbookObj = json;
//spread.fromJSON(workbookObj);
spreadSheet = initSpreadExcel(id, workbookObj);
spreadSheet = initSpreadExcel(id, json);
deferred.resolve(spreadSheet);
}, function (e) {
// process error
alert(e.errorMessage);
}, {});
// var reader = new FileReader();
// reader.readAsDataURL(blob); // 转换为base64,可以直接放入a表情href
// reader.onload = function (e) {
// // 转换完成,创建一个a标签用于下载
// var a = document.createElement('a');
// a.download = 'data.xlsx';
// a.href = e.target.result;
// $("body").append(a); // 修复firefox中无法触发click
// a.click();
// $(a).remove();
// }
}
};
// 发送ajax请求
xhr.send();
// getTemplateJson(templateID).then(function (result) {
// //var data = new Blob(result, {type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8"});
// var excelIo = new GC.Spread.Excel.IO();
// excelIo.open(result, function (json) {
// //var workbookObj = json;
// //spread.fromJSON(workbookObj);
// spreadSheet = initSpreadExcel(id, json);
// deferred.resolve(spreadSheet);
// }, function (e) {
// // process error
// alert(e.errorMessage);
// }, {});
// spreadSheet = initSpreadExcel(id, result.data === undefined ? result : result.data);
//
// deferred.resolve(spreadSheet);
});
// });
return promise;
};
......
This diff is collapsed.
This diff is collapsed.
......@@ -576,14 +576,14 @@ systemConfigurationModule
setCellFormula(template.id);
//给单元格增加双击事件
activeSheet.bind(GcSpread.Sheets.Events.CellDoubleClick, function (sender, args) {
activeSheet.bind(GC.Spread.Sheets.Events.CellDoubleClick, function (sender, args) {
var sheet = args.sheet;
var cell = sheet.getCell(args.row, args.col);
showEditReportFormulaPop(template, args.row, args.col, true);
});
//给单元格增加单击事件
activeSheet.bind(GcSpread.Sheets.Events.CellClick, function (sender, args) {
activeSheet.bind(GC.Spread.Sheets.Events.CellClick, function (sender, args) {
var sheet = args.sheet;
var cell = sheet.getCell(args.row, args.col);
showEditReportFormulaPop(template, args.row, args.col, false);
......@@ -604,7 +604,7 @@ systemConfigurationModule
if ($scope.currentTemplate.isSystemType) {
isHideContextMenu = true;
}
else if (hitTestType === GcSpread.Sheets.SheetArea.colHeader) {
else if (hitTestType === GC.Spread.Sheets.SheetArea.colHeader) {
if (getCellInSelections(selections, row, col) === null) {
sheet.setSelection(-1, col, sheet.getRowCount(), 1);
}
......@@ -612,7 +612,7 @@ systemConfigurationModule
$(".context-header").show();
$(".context-cell").hide();
}
} else if (hitTestType === GcSpread.Sheets.SheetArea.rowHeader) {
} else if (hitTestType === GC.Spread.Sheets.SheetArea.rowHeader) {
if (getCellInSelections(selections, row, col) === null) {
sheet.setSelection(row, -1, 1, sheet.getColumnCount());
}
......@@ -620,7 +620,7 @@ systemConfigurationModule
$(".context-header").show();
$(".context-cell").hide();
}
} else if (hitTestType === GcSpread.Sheets.SheetArea.viewport) {
} else if (hitTestType === GC.Spread.Sheets.SheetArea.viewport) {
if (getCellInSelections(selections, row, col) === null) {
sheet.clearSelection();
sheet.setActiveCell(row, col);
......@@ -631,7 +631,7 @@ systemConfigurationModule
} else {
isHideContextMenu = true;
}
} else if (hitTestType === GcSpread.Sheets.SheetArea.corner) {
} else if (hitTestType === GC.Spread.Sheets.SheetArea.corner) {
sheet.setSelection(-1, -1, sheet.getRowCount(), sheet.getColumnCount());
if (row !== undefined && col !== undefined) {
$(".context-header").hide();
......
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