Commit e6df59e4 authored by kevin's avatar kevin

#

parent 9ddc9cd0
......@@ -194,7 +194,7 @@ public class FileExcelUtil {
* @Param path 文件路径,包括zip文件夹路径
* @throws Exception
*/
public static List<File> generateExcelToPath(Workbook wb, String path) throws Exception {
public static File generateExcelToPath(Workbook wb, String path) throws Exception {
String[] pathArr = path.split("\\\\");
String zipDir = pathArr[0];
FileExcelUtil.createFile(zipDir);
......@@ -203,8 +203,11 @@ public class FileExcelUtil {
try {
fos = new FileOutputStream(path);
wb.write(fos);
listFile.add(new File(path));
} finally {
return new File(path);
}catch (Exception e ){
e.printStackTrace();
return null;
}finally {
if (fos != null) {
fos.flush();
fos.close();
......@@ -213,7 +216,6 @@ public class FileExcelUtil {
wb.close();
}
}
return listFile;
}
/**
......
......@@ -7,6 +7,7 @@ import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import pwc.taxtech.atms.common.message.ErrorMessage;
import pwc.taxtech.atms.common.util.FileExcelUtil;
import pwc.taxtech.atms.constant.enums.EnumServiceType;
......@@ -34,6 +35,7 @@ import java.io.File;
import java.io.OutputStream;
import java.net.URISyntaxException;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@RestController
......@@ -360,8 +362,9 @@ public class ReportController {
reportService.manyExport(requestParameterDto, zipName,request, response, zipPath);
} catch (URISyntaxException e) {
e.printStackTrace();
operationResultDto.error(e.getMessage());
return operationResultDto;
}
operationResultDto.setResult(null);
return operationResultDto;
}
......@@ -370,8 +373,13 @@ public class ReportController {
* 将spread序列化字符串保存到数据库
*/
@RequestMapping("spreadToDb")
public OperationResultDto spreadToDb(@RequestBody RequestParameterDto.EbitParam ebitParam) {
return reportService.spreadToDb(ebitParam);
public OperationResultDto spreadToDb(@RequestBody HttpServletRequest request) {
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
Map<String,MultipartFile> fileMap = multipartRequest.getFileMap();
MultipartFile file = fileMap.get("llb.xlsx");
//didiFileUploadService.uploadFile(file, );
return null;
//return reportService.spreadToDb(ebitParam);
}
}
\ No newline at end of file
......@@ -981,7 +981,7 @@ public class ReportServiceImpl extends BaseService {
Workbook workbook = reportGenerator.createWorkBookByPeriodTemplate(resources.getPeriodTemplates(), genJob);
reportGenerator.addFunctionsAndContext(workbook, functions, reportGenerator.initContext(resources, periodParam),false);
reportGenerator.addFunctionsAndContext(workbook, functions, reportGenerator.initContext(resources, periodParam), false);
reportGenerator.setConfigAndDataToWorkBook(workbook, resources);
FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator();
......@@ -1023,7 +1023,7 @@ public class ReportServiceImpl extends BaseService {
periodCellTemplateConfigDtos.forEach(a -> {
workbook4Validate.getSheetAt(a.getSheetNumber() - 1).getRow(a.getRowNumber()).getCell(a.getColNumber()).setCellFormula(a.getParsedValidation());
});
reportGenerator.addFunctionsAndContext(workbook4Validate, functions, reportGenerator.initContext(resources, periodParam),true);
reportGenerator.addFunctionsAndContext(workbook4Validate, functions, reportGenerator.initContext(resources, periodParam), true);
FormulaEvaluator validateEvaluator = workbook4Validate.getCreationHelper().createFormulaEvaluator();
validateEvaluator.evaluateAll();
//todo: 4.then save the validation result to cellData table
......@@ -2233,7 +2233,7 @@ public class ReportServiceImpl extends BaseService {
pwcReportAttach.setRemarks(remarks);
pwcReportAttachMapper.insert(pwcReportAttach);
System.out.println("==>>>附件绑定成功");
return pwcReportAttach;
return pwcReportAttach;
}
public List<PwcReportAttach> loadAttachList(ReportAttachDto param) {
......@@ -2381,7 +2381,7 @@ public class ReportServiceImpl extends BaseService {
*
* @param requestParameterDto
*/
public void manyExport(RequestParameterDto requestParameterDto, String zipFileName, HttpServletRequest request, HttpServletResponse response, String zipPath) throws Exception {
public void manyExport(RequestParameterDto requestParameterDto, String zipFileName, HttpServletRequest request, HttpServletResponse response, String zipPath) throws Exception {
try {
FileOutputStream out = new FileOutputStream(zipFileName);//要输出的文件名字
} catch (FileNotFoundException e) {
......@@ -2406,7 +2406,9 @@ public class ReportServiceImpl extends BaseService {
List<EbitCellData> ebitCellDataList = ebitCellDataMapper.selectByExample(example);//获取当前期间下所有的数据
List<List<EbitCellData>> dataList = Lists.newArrayList();
List<EbitCellData> orgList = ebitCellDataMapper.selectOrgType(requestParameterDto.getPeriod());
List<EbitCellData> orgTypeList = null;
List<EbitCellData> orgTypeList = Lists.newArrayList();
File file = null;//要生成的Excel文件
List<File> filesList = Lists.newArrayList();
for (int i = 0; i < orgList.size(); i++) {
orgTypeList = Lists.newArrayList();
for (EbitCellData ebitCellData : ebitCellDataList) {
......@@ -2417,8 +2419,8 @@ public class ReportServiceImpl extends BaseService {
}
dataList.add(orgTypeList);
}
if(dataList.size() == 0){
throw new Exception("没有可导出的数据");
if (dataList.size() == 0) {
throw new Exception("没有可导出的数据");
}
if (template.getIsSystemType()) {
try {
......@@ -2445,11 +2447,15 @@ public class ReportServiceImpl extends BaseService {
Sheet sheet = workbook.getSheetAt(0);
if (isSheetEmpty(sheet)) throw new Exception("模板异常");
for (EbitCellData ebitCellData : ebitCellDataList1) {
loop1:
for (int j = 1, k = sheet.getLastRowNum(); j < k; j++) {
if (sheet.getRow(j) == null) continue;
for (int m = 1, n = sheet.getRow(j).getLastCellNum(); m < n; m++) {
cell = sheet.getRow(j).getCell(m);
if ("".equals(getCellStringValue(cell)) && ebitCellData.getRow() == j && ebitCellData.getCol() == m) {
if (cell == null) continue;
if (!"".equals(getCellStringValue(cell)) && ebitCellData.getRow() == j && ebitCellData.getCol() == m) {
cell.setCellValue(ebitCellData.getData());
break loop1;
}
}
}
......@@ -2457,9 +2463,12 @@ public class ReportServiceImpl extends BaseService {
workbooksList.add(workbook);
//将workbook生成file文件
String path = "\\\\zipDir\\\\" + requestParameterDto.getPeriod() + Math.random() + "利润表";
FileExcelUtil.downloadZip(request, response, zipFileName, FileExcelUtil.generateExcelToPath(workbook, path), zipPath);
}
file = FileExcelUtil.generateExcelToPath(workbook, path);
if (file != null)
filesList.add(file);
}
FileExcelUtil.downloadZip(request, response, zipFileName, filesList, zipPath);
//将workbook转成流
/* ByteArrayOutputStream bos = new ByteArrayOutputStream();
workbook.write(bos);
......
......@@ -2930,7 +2930,7 @@
});
}
var spreadTODb = function(){
//spread序列化参数
/*//spread序列化参数
var serializationOption = {
ignoreFormula: false, // indicate to ignore the style when convert workbook to json, default value is false
ignoreStyle: false, // indicate to ignore the formula when convert workbook to json, default value is false
......@@ -2946,7 +2946,31 @@
$http.post('/Report/spreadToDb', obj ,function(res){
if(!res.result)
SweetAlert.error("保存表单到数据库失败");
});
});*/
var json = $scope.spread.toJSON({includeBindingSource: true});
var excelIo = new GC.Spread.Excel.IO();
var url = apiInterceptor.webApiHostUrl + '/Report/spreadToDb';
// here is excel IO API
excelIo.save(json, function (blob) {
var fd = new FormData(document.forms.namedItem("myform"));
fd.append( "llb.xlsx",blob);
$.ajax({
url: url,
type:"POST",
contentType:false,
processData: false,
data:fd,
success: function (data) {
if(data.result){
//alert("上传成功!");
}else{
SweetAlert.error(data.resultMsg);
}
},
error : function(ex) {
alert("上传失败:"+ex);
}
});
}
$scope.$watch('file', function (file) {
......@@ -3045,7 +3069,7 @@
$scope.singleExport = function(){
if($scope.spread != undefined && $scope.spread){
var excelIo = new GC.Spread.Excel.IO();
var fileName = "利润表.xlsx";
var fileName = "-利润表.xlsx";
if (fileName.substr(-5, 5) !== '.xlsx') {
fileName += '.xlsx';
}
......@@ -3100,9 +3124,10 @@
$log.debug(mainSpread);
}, 500);*/
vatReportService.manyExport(JSON.stringify(param)).success(function(res){
if(!res.result)
SweetAlert.error(res.resultMsg);
}).error(function(error){
SweetAlert.error(error + "批量导出失败")
SweetAlert.error("批量导出失败")
});
};
$scope.relation._orgId = null;
......
......@@ -3,7 +3,7 @@
<div class="row" style=" height: 71px; background: #ccc;">
<div class="col-sm-7" style=" margin-top: 20px;">
<div class="col-sm-8">
<span class="text-bold" translate="SelectedOrganization" style=" top: -11px; display: inline!important; position: relative; ">:</span>
<span class="text-bold" translate="SelectedOrganization" style=" top: -7px; display: inline!important; position: relative; ">:</span>
<!-- <div id="dx-select-industry" class="tab-content-select industry " style=" display: inline-block;"
dx-select-box="dataSourceIndustryList" dx-item-alias="itemObj">
<div data-options="dxTemplate: { name: 'orgList' }" class="dx-item-content dx-list-item-content"
......@@ -11,7 +11,7 @@
{{itemObj.code}}-{{itemObj.name}}
</div>
</div>-->
<div dx-tag-box="selectOrgOptions" style="width: 340px;display: inline-block"></div>
<div dx-tag-box="selectOrgOptions" style="width: 287px;display: inline-block"></div>
</div>
<div class="col-sm-4" class="dateClass">
<span class="text-bold" translate="InvoiceQJ">:</span>
......@@ -38,5 +38,9 @@
<table-report-sheet report-source="reportData" spread='spread' template-id='templateId'
relation="relation">
</table-report-sheet>
<form name="myform" style="disply:none;" id="myform" enctype="multipart/form-data" method="post">
    
   </form>
</div>
</div>
\ No newline at end of file
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