Commit 5728602c authored by chase's avatar chase

fix bug

parent d4f36128
...@@ -108,6 +108,7 @@ public class TaxDocumentController { ...@@ -108,6 +108,7 @@ public class TaxDocumentController {
response.setHeader("Content-Disposition", "attachment;fileName=" + new String("taxDocument.xlsx".getBytes("GB2312"), "ISO-8859-1")); response.setHeader("Content-Disposition", "attachment;fileName=" + new String("taxDocument.xlsx".getBytes("GB2312"), "ISO-8859-1"));
OutputStream ouputStream = response.getOutputStream(); OutputStream ouputStream = response.getOutputStream();
ExcelUtil.exportExcel(headers, TaxDocument, ouputStream); ExcelUtil.exportExcel(headers, TaxDocument, ouputStream);
ouputStream.close();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
......
...@@ -23,6 +23,17 @@ public class DidiFileIUploadParam implements Serializable { ...@@ -23,6 +23,17 @@ public class DidiFileIUploadParam implements Serializable {
private List<Integer> uploadYears; private List<Integer> uploadYears;
//是否转换url为本地url
private boolean isParseUrl = true;
public boolean isParseUrl() {
return isParseUrl;
}
public void setParseUrl(boolean parseUrl) {
isParseUrl = parseUrl;
}
public List<String> getBizSources() { public List<String> getBizSources() {
return bizSources; return bizSources;
} }
......
...@@ -35,6 +35,7 @@ import pwc.taxtech.atms.vat.entity.FileUploadLog; ...@@ -35,6 +35,7 @@ import pwc.taxtech.atms.vat.entity.FileUploadLog;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.IOException; import java.io.IOException;
import java.net.URLEncoder;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Calendar; import java.util.Calendar;
...@@ -74,6 +75,10 @@ public class DidiFileUploadService extends BaseService { ...@@ -74,6 +75,10 @@ public class DidiFileUploadService extends BaseService {
private static final String PROXY_PORT = "11007"; private static final String PROXY_PORT = "11007";
public FileUpload getFileUpload(String uid){
return fileUploadMapper.selectByPrimaryKey(uid);
}
public FileUpload uploadFile(MultipartFile file, String fileName, String bizSource) throws ServiceException { public FileUpload uploadFile(MultipartFile file, String fileName, String bizSource) throws ServiceException {
CloseableHttpClient httpClient = null; CloseableHttpClient httpClient = null;
String requestKey = CommonUtils.getUUID(); String requestKey = CommonUtils.getUUID();
...@@ -86,7 +91,7 @@ public class DidiFileUploadService extends BaseService { ...@@ -86,7 +91,7 @@ public class DidiFileUploadService extends BaseService {
httpClient = HttpClients.createDefault(); httpClient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(requestUrl); HttpPost httpPost = new HttpPost(requestUrl);
String md5Str = getFileMD5String(file); String md5Str = getFileMD5String(file);
ByteArrayBody byteBody = new ByteArrayBody(file.getBytes(), ContentType.MULTIPART_FORM_DATA, StringUtils.isBlank(fileName) ? file.getOriginalFilename() : fileName); ByteArrayBody byteBody = new ByteArrayBody(file.getBytes(), ContentType.MULTIPART_FORM_DATA, StringUtils.isBlank(fileName) ? URLEncoder.encode(file.getOriginalFilename(), "UTF-8") : URLEncoder.encode(fileName, "UTF-8"));
StringBody md5 = new StringBody(md5Str, ContentType.create("text/plain")); StringBody md5 = new StringBody(md5Str, ContentType.create("text/plain"));
HttpEntity httpEntity = MultipartEntityBuilder.create().addPart("filecontent", byteBody).addPart("md5", md5).build(); HttpEntity httpEntity = MultipartEntityBuilder.create().addPart("filecontent", byteBody).addPart("md5", md5).build();
httpPost.setEntity(httpEntity); httpPost.setEntity(httpEntity);
...@@ -134,7 +139,7 @@ public class DidiFileUploadService extends BaseService { ...@@ -134,7 +139,7 @@ public class DidiFileUploadService extends BaseService {
try { try {
httpClient = HttpClients.createDefault(); httpClient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(requestUrl); HttpPost httpPost = new HttpPost(requestUrl);
ByteArrayBody byteBody = new ByteArrayBody(bytes, ContentType.MULTIPART_FORM_DATA, fileName); ByteArrayBody byteBody = new ByteArrayBody(bytes, ContentType.MULTIPART_FORM_DATA, URLEncoder.encode(fileName, "UTF-8"));
HttpEntity httpEntity = MultipartEntityBuilder.create().addPart("filecontent", byteBody).build(); HttpEntity httpEntity = MultipartEntityBuilder.create().addPart("filecontent", byteBody).build();
httpPost.setEntity(httpEntity); httpPost.setEntity(httpEntity);
HttpResponse httpResponse = httpClient.execute(httpPost); HttpResponse httpResponse = httpClient.execute(httpPost);
...@@ -192,6 +197,7 @@ public class DidiFileUploadService extends BaseService { ...@@ -192,6 +197,7 @@ public class DidiFileUploadService extends BaseService {
} }
public PageInfo<DidiFileUploadDetailResult> queryPage(DidiFileIUploadParam param) { public PageInfo<DidiFileUploadDetailResult> queryPage(DidiFileIUploadParam param) {
Page page = null; Page page = null;
if (param.getPageInfo() != null && param.getPageInfo().getPageSize() != null && param.getPageInfo().getPageIndex() != null) { if (param.getPageInfo() != null && param.getPageInfo().getPageSize() != null && param.getPageInfo().getPageIndex() != null) {
...@@ -219,7 +225,11 @@ public class DidiFileUploadService extends BaseService { ...@@ -219,7 +225,11 @@ public class DidiFileUploadService extends BaseService {
} }
refreshViewUrl(param); refreshViewUrl(param);
PageInfo<DidiFileUploadDetailResult> pageInfo = new PageInfo<>(fileUploadMapper.selectByExample(example).stream() PageInfo<DidiFileUploadDetailResult> pageInfo = new PageInfo<>(fileUploadMapper.selectByExample(example).stream()
.map(o -> beanUtil.copyProperties(o, new DidiFileUploadDetailResult())).collect(Collectors.toList())); .map(o -> {
DidiFileUploadDetailResult item = new DidiFileUploadDetailResult();
beanUtil.copyProperties(o, item);
return item;
}).collect(Collectors.toList()));
if (page != null) { if (page != null) {
pageInfo.setTotal(page.getTotal()); pageInfo.setTotal(page.getTotal());
} }
......
...@@ -352,15 +352,18 @@ public class TaxDocumentServiceImpl { ...@@ -352,15 +352,18 @@ public class TaxDocumentServiceImpl {
TaxDocumentExample.Criteria criteria = example.createCriteria(); TaxDocumentExample.Criteria criteria = example.createCriteria();
criteria.andIdIn(ids); criteria.andIdIn(ids);
TaxDocument taxDocument = taxDocumentMapper.selectByExample(example).get(0); TaxDocument taxDocument = taxDocumentMapper.selectByExample(example).get(0);
String urlPath = taxDocument.getFilePositionUrl(); DidiFileIUploadParam fileParam = new DidiFileIUploadParam();
fileParam.setUuids(Arrays.asList(taxDocument.getFileUploadId()));
PageInfo<DidiFileUploadDetailResult> uploadDetail = didiFileUploadService.queryPage(fileParam);
String urlPath = uploadDetail.getList().get(0).getViewHttpUrl();
//如果url为null或空字符串而抛出异常 //如果url为null或空字符串而抛出异常
if (StringUtils.isBlank(urlPath)) { if (StringUtils.isBlank(urlPath)) {
throw new RuntimeException("文件url为空,id为:" + taxDocument.getId()); throw new RuntimeException("文件url为空,id为:" + taxDocument.getId());
} }
//文件名称(带后缀) 文件名前+7位uuid截取码以防文件名相同 //文件名称(带后缀) 文件名前+7位uuid截取码以防文件名相同
String fileName = StringUtils.isBlank(taxDocument.getFileName()) String fileName = StringUtils.isBlank(uploadDetail.getList().get(0).getFileName())
? "未知文件(请修改后缀名).xlsx" ? "未知文件(请修改后缀名).xlsx"
: taxDocument.getFileOriginalName();//设置输出流信息 : uploadDetail.getList().get(0).getFileName();//设置输出流信息
try { try {
response.setContentType("multipart/form-data"); response.setContentType("multipart/form-data");
response.setHeader("Content-Disposition", "attachment;fileName=" + URLEncoder.encode(fileName, "UTF-8")); response.setHeader("Content-Disposition", "attachment;fileName=" + URLEncoder.encode(fileName, "UTF-8"));
...@@ -476,15 +479,20 @@ public class TaxDocumentServiceImpl { ...@@ -476,15 +479,20 @@ public class TaxDocumentServiceImpl {
criteria.andIdIn(ids); criteria.andIdIn(ids);
//查询出根据条件过滤后需要下载的附件数据信息 //查询出根据条件过滤后需要下载的附件数据信息
List<TaxDocument> taxDocuments = taxDocumentMapper.selectByExample(example); List<TaxDocument> taxDocuments = taxDocumentMapper.selectByExample(example);
DidiFileIUploadParam fileParam = new DidiFileIUploadParam();
fileParam.setUuids(taxDocuments.stream()
.map(o -> o.getFileUploadId()).collect(Collectors.toList()));
PageInfo<DidiFileUploadDetailResult> uploadDetail = didiFileUploadService.queryPage(fileParam);
//新建一个空集合,记录下载的名字,并用于判断是否重名,重名则修改名字为(n) //新建一个空集合,记录下载的名字,并用于判断是否重名,重名则修改名字为(n)
List<String> fileNameList = new ArrayList<>(); List<String> fileNameList = new ArrayList<>();
for (TaxDocument item : taxDocuments) { for (DidiFileUploadDetailResult item : uploadDetail.getList()) {
//文件url //文件url
String urlPath = item.getFilePositionUrl(); String urlPath = item.getViewHttpUrl();
//如果url为null或空字符串而抛出异常 // //如果url为null或空字符串而抛出异常
if (StringUtils.isBlank(urlPath)) { // if (StringUtils.isBlank(urlPath)) {
throw new RuntimeException("文件url为空,id为:" + item.getId()); // throw new RuntimeException("文件url为空,id为:" + item.getId());
} // }
//检查文件名是否有重复 //检查文件名是否有重复
int fileNameRepeatTimes = 0; int fileNameRepeatTimes = 0;
if (fileNameList.size()>0){ if (fileNameList.size()>0){
......
package pwc.taxtech.atms.vat.service.impl.report.functions; package pwc.taxtech.atms.vat.service.impl.report.functions;
import org.apache.commons.collections.CollectionUtils;
import org.apache.poi.ss.formula.OperationEvaluationContext; import org.apache.poi.ss.formula.OperationEvaluationContext;
import org.apache.poi.ss.formula.eval.NumberEval; import org.apache.poi.ss.formula.eval.NumberEval;
import org.apache.poi.ss.formula.eval.StringEval; import org.apache.poi.ss.formula.eval.StringEval;
...@@ -61,21 +62,6 @@ public class BB extends FunctionBase implements FreeRefFunction { ...@@ -61,21 +62,6 @@ public class BB extends FunctionBase implements FreeRefFunction {
BigDecimal cellValue = BigDecimal.ZERO; BigDecimal cellValue = BigDecimal.ZERO;
try { try {
List<CellTemplatePerGroupDto> cellTemplateDataList;
if (curPeriod.getCurYear() != formulaContext.getYear()) {
Project project = agent.getFixedProject(formulaContext.getProjectId(), curPeriod.getCurYear());
MyAsserts.assertNotNull(project, Exceptions.PROJECT_NOT_FOUND);
cellTemplateDataList = agent.getCellTemplateGroupDto(formulaContext.getReportTemplateGroupId(),
project.getId(), bo.getReportCode(), bo.getRowIndex() - 1, bo.getColumnIndex() - 1, curPeriod.getCurPeriod());
} else {
cellTemplateDataList = agent.getCellTemplateGroupDto(formulaContext.getReportTemplateGroupId(),
formulaContext.getProjectId(), bo.getReportCode(), bo.getRowIndex() - 1, bo.getColumnIndex() - 1, curPeriod.getCurPeriod());
}
MyAsserts.assertNotEmpty(cellTemplateDataList, Exceptions.BB_CELL_TEMP_NULL);
CellTemplatePerGroupDto cellTemplateData = cellTemplateDataList.get(0);
nullCellDto.fixedWithGroup(cellTemplateData);
// todo: fix datasource name by templateList(neo)
if (bo.getPeriod().intValue() == 99) { if (bo.getPeriod().intValue() == 99) {
dataSource.clear(); dataSource.clear();
BigDecimal returnEval = defaultBigDecimal; BigDecimal returnEval = defaultBigDecimal;
...@@ -83,7 +69,7 @@ public class BB extends FunctionBase implements FreeRefFunction { ...@@ -83,7 +69,7 @@ public class BB extends FunctionBase implements FreeRefFunction {
return defaultBigDecimal; return defaultBigDecimal;
} }
//如果是当年取到当期截至,往年取12期 //如果是当年取到当期截至,往年取12期
for (int p = 1; p < (curPeriod.getCurYear()==formulaContext.getYear()?formulaContext.getPeriod():12); p++) { for (int p = 1; p <= (curPeriod.getCurYear()==formulaContext.getYear()?formulaContext.getPeriod():12); p++) {
try { try {
returnEval = returnEval.add(bb(new BBParasBo(bo, p, curPeriod.getCurYear()), ec, dataSource, bo)); returnEval = returnEval.add(bb(new BBParasBo(bo, p, curPeriod.getCurYear()), ec, dataSource, bo));
} catch (Exception e) { } catch (Exception e) {
...@@ -92,33 +78,45 @@ public class BB extends FunctionBase implements FreeRefFunction { ...@@ -92,33 +78,45 @@ public class BB extends FunctionBase implements FreeRefFunction {
} }
} }
} }
return returnEval; return returnEval;
} }
List<CellTemplatePerGroupDto> cellTemplateDataList;
if (curPeriod.getCurYear() != formulaContext.getYear()) {
Project project = agent.getFixedProject(formulaContext.getProjectId(), curPeriod.getCurYear());
// MyAsserts.assertNotNull(project, Exceptions.PROJECT_NOT_FOUND);
if(project == null){
return cellValue;
}
cellTemplateDataList = agent.getCellTemplateGroupDto(formulaContext.getReportTemplateGroupId(),
project.getId(), bo.getReportCode(), bo.getRowIndex() - 1, bo.getColumnIndex() - 1, curPeriod.getCurPeriod());
} else {
cellTemplateDataList = agent.getCellTemplateGroupDto(formulaContext.getReportTemplateGroupId(),
formulaContext.getProjectId(), bo.getReportCode(), bo.getRowIndex() - 1, bo.getColumnIndex() - 1, curPeriod.getCurPeriod());
}
// MyAsserts.assertNotEmpty(cellTemplateDataList, Exceptions.BB_CELL_TEMP_NULL);
if(CollectionUtils.isEmpty(cellTemplateDataList)){
return cellValue;
}
CellTemplatePerGroupDto cellTemplateData = cellTemplateDataList.get(0);
nullCellDto.fixedWithGroup(cellTemplateData);
//当年当期
if (bo.getPeriod().intValue() == 0 && bo.getYear().intValue() == 0) { if (bo.getPeriod().intValue() == 0 && bo.getYear().intValue() == 0) {
int index = ec.getWorkbook().getSheetIndex(bo.getReportCode()); int index = ec.getWorkbook().getSheetIndex(bo.getReportCode());
cellValue = getCellValue(index, ec, formulaContext, agent, bo.getRowIndex() - 1, bo.getColumnIndex() - 1, cellValue = getCellValue(index, ec, formulaContext, agent, bo.getRowIndex() - 1, bo.getColumnIndex() - 1,
Long.parseLong(cellTemplateData.getCellTemplateId())); Long.parseLong(cellTemplateData.getCellTemplateId()));
nullCellDto.extractFromGroup(bo, formulaContext.getPeriod(), formulaContext.getYear(), cellTemplateData); nullCellDto.extractFromGroup(bo, formulaContext.getPeriod(), formulaContext.getYear(), cellTemplateData);
nullCellDto.setAmount(cellValue); nullCellDto.setAmount(cellValue);
return cellValue; return cellValue;
} }
PeriodCellData cellData = null; PeriodCellData cellData = null;
String projectId = agent.getPastProjectId(curPeriod.getCurYear(), String projectId = agent.getPastProjectId(curPeriod.getCurYear(),
formulaContext.getOrganizationId()); formulaContext.getOrganizationId());
MyAsserts.assertNotEmpty(projectId, Exceptions.PROJECT_EMPTY); MyAsserts.assertNotEmpty(projectId, Exceptions.PROJECT_EMPTY);
cellData = agent.getCellData(cellTemplateData.getReportTemplateId(), cellData = agent.getCellData(cellTemplateData.getReportTemplateId(),
cellTemplateData.getCellTemplateId(), curPeriod.getCurPeriod(), formulaContext.getProjectId()); cellTemplateData.getCellTemplateId(), curPeriod.getCurPeriod(), formulaContext.getProjectId());
List<PeriodDataSource> dss = agent.queryManualDataSource(Long.parseLong(cellTemplateData.getCellTemplateId()), List<PeriodDataSource> dss = agent.queryManualDataSource(Long.parseLong(cellTemplateData.getCellTemplateId()),
formulaContext.getProjectId(), bo.getPeriod()); formulaContext.getProjectId(), bo.getPeriod());
nullCellDto.extractFromGroup(bo, curPeriod, cellData, cellTemplateData); nullCellDto.extractFromGroup(bo, curPeriod, cellData, cellTemplateData);
if (cellData.getData() == null && !dss.isEmpty()) { if (cellData.getData() == null && !dss.isEmpty()) {
cellValue = dss.get(0).getAmount(); cellValue = dss.get(0).getAmount();
} else if (cellData.getData() != null && dss.isEmpty()) { } else if (cellData.getData() != null && dss.isEmpty()) {
...@@ -128,14 +126,12 @@ public class BB extends FunctionBase implements FreeRefFunction { ...@@ -128,14 +126,12 @@ public class BB extends FunctionBase implements FreeRefFunction {
cellValue = dss.get(0).getAmount().add(new BigDecimal(cellData.getData()).setScale(4, cellValue = dss.get(0).getAmount().add(new BigDecimal(cellData.getData()).setScale(4,
BigDecimal.ROUND_HALF_DOWN)); BigDecimal.ROUND_HALF_DOWN));
} else throw Exceptions.BB_CELL_DATA_NULL; } else throw Exceptions.BB_CELL_DATA_NULL;
nullCellDto.setAmount(cellValue); nullCellDto.setAmount(cellValue);
if (rootBo != null) { if (rootBo != null) {
rootBo.putPeriodCellTempate(curPeriod.getCurPeriod(), Long.parseLong(cellTemplateData.getCellTemplateId())); rootBo.putPeriodCellTempate(curPeriod.getCurPeriod(), Long.parseLong(cellTemplateData.getCellTemplateId()));
} else { } else {
bo.putPeriodCellTempate(curPeriod.getCurPeriod(), Long.parseLong(cellTemplateData.getCellTemplateId())); bo.putPeriodCellTempate(curPeriod.getCurPeriod(), Long.parseLong(cellTemplateData.getCellTemplateId()));
} }
LOGGER.debug("cell static value "); LOGGER.debug("cell static value ");
return cellValue; return cellValue;
} catch (Exception e) { } catch (Exception e) {
......
...@@ -251,9 +251,11 @@ public class FunctionBase { ...@@ -251,9 +251,11 @@ public class FunctionBase {
return bigDecimal; return bigDecimal;
} }
} catch (Exception e) { } catch (Exception e) {
if (!dss.isEmpty())
return dss.get(0).getAmount();
e.printStackTrace(); e.printStackTrace();
if (!dss.isEmpty()){
return dss.get(0).getAmount();}
else {return new BigDecimal(0);}
} }
}else{ }else{
try { try {
...@@ -264,9 +266,10 @@ public class FunctionBase { ...@@ -264,9 +266,10 @@ public class FunctionBase {
return bigDecimal; return bigDecimal;
} }
} catch (Exception e) { } catch (Exception e) {
if (!dss.isEmpty())
return dss.get(0).getAmount();
e.printStackTrace(); e.printStackTrace();
if (!dss.isEmpty()){
return dss.get(0).getAmount();}
else {return new BigDecimal(0);}
} }
} }
......
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