Commit b0296f5f authored by kevin's avatar kevin

#

parent 07dd1550
......@@ -8,6 +8,7 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFCell;
......@@ -19,6 +20,8 @@ import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import pwc.taxtech.atms.common.CommonUtils;
import pwc.taxtech.atms.common.POIUtil;
import pwc.taxtech.atms.common.message.ErrorMessage;
......@@ -342,15 +345,17 @@ public class ReportServiceImpl extends BaseService {
andStartDateLessThanOrEqualTo(queryDate).andEndDateGreaterThanOrEqualTo(queryDate).
andStatusEqualTo(0);
List<RevenueTypeMapping> mappingList = revenueTypeMappingMapper.selectByExample(mappingExample);
//先清除数据
InvoiceRecord delRecord = new InvoiceRecord();
delRecord.setRevenueCofId(null);
if (!isMergeManualData) {
delRecord.setModifyRevenueCofId(null);
}
InvoiceRecordExample delExample = new InvoiceRecordExample();
delExample.createCriteria().andProjectIdEqualTo(projectId).
delExample.createCriteria().andProjectIdEqualTo(projectId)
.andProjectIdEqualTo(projectId).
andPeriodEqualTo(Integer.valueOf(queryDate.replace("-", "")));
if (isMergeManualData) {
invoiceRecordMapper.clearRevenueCof(true, false, delExample);
} else {
invoiceRecordMapper.clearRevenueCof(true, true, delExample);
}
invoiceRecordMapper.deleteByExample(delExample);
Map<String, Long> map = new HashMap<>();
for (RevenueTypeMapping mapping : mappingList) {
if (!map.containsKey(mapping.getContent())) {
......@@ -470,78 +475,140 @@ public class ReportServiceImpl extends BaseService {
for (int r = sheet.getFirstRowNum(); r <= sheet.getLastRowNum(); r++) {
Row row = sheet.getRow(r);
for (int c = row.getFirstCellNum(); c <= row.getLastCellNum(); c++) {
Cell cell = row.getCell(c);
if (cell == null) {
continue;//todo cell == null 如何处理
}
if (r <= addRowIndex + 1) {
if(r == addRowIndex + 1 && c>TaxesCalculateReportEnum.Column.Column_14.getIndex()){
assembleOriginalTemplateData(template,projectId,period,r,c,addRowIndex,cellTemplateList,cellTemplateConfigList);
}else{
String cellId = projectId + template.getId() + period + r + c;
if ((r - 1) >= 0 && (r - 1) < configIds.size()) {
cellId += configIds.get(configIds.size() - r);
}
Long cellTemplateId = Long.valueOf(cellId.hashCode());
cellTemplateId = cellTemplateId < 0 ? cellTemplateId : (cellTemplateId * -1);
//更新手工数据源
PeriodDataSourceExample delExample = new PeriodDataSourceExample();
delExample.createCriteria().andProjectIdEqualTo(projectId)
.andPeriodEqualTo(period).andTypeEqualTo(10).andColumnIndexEqualTo(c).andRowIndexEqualTo(r);
PeriodDataSource dataSource = new DataSourceExtendDto();
dataSource.setColumnIndex(999);
dataSource.setRowIndex(999);
periodDataSourceMapper.updateByExampleSelective(dataSource, delExample);
PeriodDataSourceExample updateExample = new PeriodDataSourceExample();
updateExample.createCriteria().andProjectIdEqualTo(projectId)
.andPeriodEqualTo(period).andTypeEqualTo(10).andCellTemplateIdEqualTo(cellTemplateId);
dataSource = new DataSourceExtendDto();
dataSource.setColumnIndex(c);
dataSource.setRowIndex(r);
periodDataSourceMapper.updateByExampleSelective(dataSource, updateExample);
PeriodCellTemplate cellTemplate = new PeriodCellTemplate();
cellTemplate.setPeriod(period);
cellTemplate.setRowName(POIUtil.getCellFormulaString(cell));
cellTemplate.setProjectId(projectId);
cellTemplate.setColumnIndex(c);
cellTemplate.setCreateTime(now);
cellTemplate.setCellTemplateId(cellTemplateId);
cellTemplate.setUpdateTime(now);
cellTemplate.setRowIndex(r);
cellTemplate.setReportTemplateId(template.getId());
cellTemplate.setId(distributedIdService.nextId());
if (cell.getCellComment() != null) {
cellTemplate.setComment(cell.getCellComment().getString().getString());
}
cellTemplate.setIsReadOnly(hasHandDatas.contains(c) ? 0 : 1);
cellTemplateList.add(cellTemplate);
if (r > 0 && hasFormulaDatas.contains(c) && StringUtils.isNotBlank(POIUtil.getCellFormulaString(cell))) {
PeriodCellTemplateConfig periodCellTemplateConfig = new PeriodCellTemplateConfig();
periodCellTemplateConfig.setId(distributedIdService.nextId());
periodCellTemplateConfig.setPeriod(period);
periodCellTemplateConfig.setCellTemplateId(cellTemplateId);
periodCellTemplateConfig.setReportTemplateId(template.getId());
periodCellTemplateConfig.setDataSourceType(1);
periodCellTemplateConfig.setFormula(POIUtil.getCellFormulaString(cell));
periodCellTemplateConfig.setParsedFormula(null);
String cellId = projectId + template.getId() + period + r + c;
if ((r - 1) >= 0 && (r - 1) < configIds.size()) {
cellId += configIds.get(configIds.size() - r);
}
Long cellTemplateId = Long.valueOf(cellId.hashCode());
cellTemplateId = cellTemplateId < 0 ? cellTemplateId : (cellTemplateId * -1);
//更新手工数据源
PeriodDataSourceExample delExample = new PeriodDataSourceExample();
delExample.createCriteria().andProjectIdEqualTo(projectId)
.andPeriodEqualTo(period).andTypeEqualTo(10).andColumnIndexEqualTo(c).andRowIndexEqualTo(r);
PeriodDataSource dataSource = new DataSourceExtendDto();
dataSource.setColumnIndex(999);
dataSource.setRowIndex(999);
periodDataSourceMapper.updateByExampleSelective(dataSource, delExample);
PeriodDataSourceExample updateExample = new PeriodDataSourceExample();
updateExample.createCriteria().andProjectIdEqualTo(projectId)
.andPeriodEqualTo(period).andTypeEqualTo(10).andCellTemplateIdEqualTo(cellTemplateId);
dataSource = new DataSourceExtendDto();
dataSource.setColumnIndex(c);
dataSource.setRowIndex(r);
periodDataSourceMapper.updateByExampleSelective(dataSource, updateExample);
PeriodCellTemplate cellTemplate = new PeriodCellTemplate();
cellTemplate.setPeriod(period);
cellTemplate.setRowName(POIUtil.getCellFormulaString(cell));
cellTemplate.setProjectId(projectId);
cellTemplate.setColumnIndex(c);
cellTemplate.setCreateTime(now);
cellTemplate.setCellTemplateId(cellTemplateId);
cellTemplate.setUpdateTime(now);
cellTemplate.setRowIndex(r);
cellTemplate.setReportTemplateId(template.getId());
cellTemplate.setId(distributedIdService.nextId());
if (cell.getCellComment() != null) {
cellTemplate.setComment(cell.getCellComment().getString().getString());
}
cellTemplate.setIsReadOnly(hasHandDatas.contains(c) ? 0 : 1);
cellTemplateList.add(cellTemplate);
if (r > 0 && hasFormulaDatas.contains(c) && StringUtils.isNotBlank(POIUtil.getCellFormulaString(cell))) {
PeriodCellTemplateConfig periodCellTemplateConfig = new PeriodCellTemplateConfig();
periodCellTemplateConfig.setId(distributedIdService.nextId());
periodCellTemplateConfig.setPeriod(period);
periodCellTemplateConfig.setCellTemplateId(cellTemplateId);
periodCellTemplateConfig.setReportTemplateId(template.getId());
periodCellTemplateConfig.setDataSourceType(1);
periodCellTemplateConfig.setFormula(POIUtil.getCellFormulaString(cell));
periodCellTemplateConfig.setParsedFormula(null);
// periodCellTemplateConfig.setCreateBy(authUserHelper.getCurrentUserId());
periodCellTemplateConfig.setCreateTime(now);
periodCellTemplateConfig.setCreateTime(now);
// periodCellTemplateConfig.setUpdateBy(authUserHelper.getCurrentUserId());
periodCellTemplateConfig.setUpdateTime(now);
periodCellTemplateConfig.setFormulaDataSource("报表数据");
periodCellTemplateConfig.setKeyValueParsedFormula(null);
periodCellTemplateConfig.setProjectId(projectId);
fixedParsedFormula(periodCellTemplateConfig);
fixedAccountCode(periodCellTemplateConfig);
cellTemplateConfigList.add(periodCellTemplateConfig);
}
if (r > 0 && r <= addRowIndex && hasHandDatas.contains(c)) {
addManualConfig(cellTemplate, cell, now, cellTemplateConfigList);
}
periodCellTemplateConfig.setUpdateTime(now);
periodCellTemplateConfig.setFormulaDataSource("报表数据");
periodCellTemplateConfig.setKeyValueParsedFormula(null);
periodCellTemplateConfig.setProjectId(projectId);
fixedParsedFormula(periodCellTemplateConfig);
fixedAccountCode(periodCellTemplateConfig);
cellTemplateConfigList.add(periodCellTemplateConfig);
}
if (r > 0 && r <= addRowIndex && hasHandDatas.contains(c)) {
addManualConfig(cellTemplate, cell, now, cellTemplateConfigList);
}
} else {
assembleOriginalTemplateData(template,projectId,period,r,c,addRowIndex,cellTemplateList,cellTemplateConfigList);
//查询原来行cell是否有CellTemplate
CellTemplateExample cellTemplateExample = new CellTemplateExample();
cellTemplateExample.createCriteria().andReportTemplateIdEqualTo(template.getId()).andRowIndexEqualTo(r - addRowIndex).andColumnIndexEqualTo(c);
List<CellTemplate> cellTemplates = cellTemplateMapper.selectByExample(cellTemplateExample);
if (CollectionUtils.isNotEmpty(cellTemplates)) {
CellTemplate cellTemplate = cellTemplates.get(0);
PeriodCellTemplate periodCellTemplate = new PeriodCellTemplate();
CommonUtils.copyProperties(cellTemplate, periodCellTemplate);
periodCellTemplate.setId(distributedIdService.nextId());
periodCellTemplate.setPeriod(period);
periodCellTemplate.setReportTemplateId(template.getId());
periodCellTemplate.setRowIndex(r);
periodCellTemplate.setRowName(cellTemplate.getRowName());
periodCellTemplate.setColumnIndex(c);
periodCellTemplate.setColumnName(cellTemplate.getColumnName());
periodCellTemplate.setComment(cellTemplate.getComment());
periodCellTemplate.setCreateTime(cellTemplate.getCreateTime());
periodCellTemplate.setUpdateTime(cellTemplate.getUpdateTime());
periodCellTemplate.setCellTemplateId(cellTemplate.getId());
periodCellTemplate.setDataType(cellTemplate.getDataType());
periodCellTemplate.setIsReadOnly(cellTemplate.getIsReadOnly() ? 1 : 0);
periodCellTemplate.setCopyFromId(cellTemplate.getCopyFromId());
periodCellTemplate.setCreateBy(StringUtils.isBlank(cellTemplate.getCreateBy()) ? "admin" : cellTemplate.getCreateBy());
periodCellTemplate.setUpdateBy(StringUtils.isBlank(cellTemplate.getUpdateBy()) ? "admin" : cellTemplate.getUpdateBy());
periodCellTemplate.setProjectId(projectId);
cellTemplateList.add(periodCellTemplate);
CellTemplateConfigExample configExample = new CellTemplateConfigExample();
configExample.createCriteria().andCellTemplateIdEqualTo(cellTemplate.getId());
List<CellTemplateConfig> configs = cellTemplateConfigMapper.selectByExample(configExample);
if (CollectionUtils.isNotEmpty(configs)) {
for (CellTemplateConfig cellTemplateConfig : configs) {
PeriodCellTemplateConfig periodCellTemplateConfig = new PeriodCellTemplateConfig();
CommonUtils.copyProperties(cellTemplateConfig, periodCellTemplateConfig);
periodCellTemplateConfig.setId(distributedIdService.nextId());
periodCellTemplateConfig.setPeriod(period);
periodCellTemplateConfig.setCellTemplateId(cellTemplateConfig.getCellTemplateId());
periodCellTemplateConfig.setReportTemplateId(template.getId());
periodCellTemplateConfig.setDataSourceType(cellTemplateConfig.getDataSourceType());
periodCellTemplateConfig.setFormula(StringUtils.isBlank(cellTemplateConfig.getFormula()) ? null : cellTemplateConfig.getFormula());
periodCellTemplateConfig.setParsedFormula(null);
periodCellTemplateConfig.setFormulaDescription(cellTemplateConfig.getFormulaDescription());
periodCellTemplateConfig.setAccountCodes(cellTemplateConfig.getAccountCodes());
periodCellTemplateConfig.setInvoiceType(cellTemplateConfig.getInvoiceType());
periodCellTemplateConfig.setTaxRate(cellTemplateConfig.getTaxRate());
periodCellTemplateConfig.setInvoiceAmountType(cellTemplateConfig.getInvoiceAmountType());
periodCellTemplateConfig.setModelIds(cellTemplateConfig.getModelIds());
periodCellTemplateConfig.setCreateBy(StringUtils.isBlank(cellTemplateConfig.getCreateBy()) ? "admin" : cellTemplateConfig.getCreateBy());
periodCellTemplateConfig.setCreateTime(cellTemplateConfig.getCreateTime());
periodCellTemplateConfig.setUpdateBy(StringUtils.isBlank(cellTemplateConfig.getUpdateBy()) ? "admin" : cellTemplateConfig.getUpdateBy());
periodCellTemplateConfig.setUpdateTime(cellTemplateConfig.getUpdateTime());
periodCellTemplateConfig.setInvoiceCategory(cellTemplateConfig.getInvoiceCategory());
periodCellTemplateConfig.setFormulaDataSource(cellTemplateConfig.getFormulaDataSource());
periodCellTemplateConfig.setValidation(cellTemplateConfig.getValidation());
periodCellTemplateConfig.setParsedValidation(null);
periodCellTemplateConfig.setValidationDescription(cellTemplateConfig.getValidationDescription());
periodCellTemplateConfig.setVoucherKeyword(cellTemplateConfig.getVoucherKeyword());
periodCellTemplateConfig.setCellTemplateConfigId(cellTemplateConfig.getId());
periodCellTemplateConfig.setKeyValueParsedFormula(null);
periodCellTemplateConfig.setProjectId(projectId);
fixedParsedFormula(periodCellTemplateConfig);
fixedAccountCode(periodCellTemplateConfig);
cellTemplateConfigList.add(periodCellTemplateConfig);
}
}
}
}
}
}
......@@ -556,77 +623,6 @@ public class ReportServiceImpl extends BaseService {
}
}
public void assembleOriginalTemplateData(Template template, String projectId, Integer period,
Integer r, Integer c, Integer addRowIndex,
List<PeriodCellTemplate> cellTemplateList, List<PeriodCellTemplateConfig> cellTemplateConfigList) {
//查询原来行cell是否有CellTemplate
CellTemplateExample cellTemplateExample = new CellTemplateExample();
cellTemplateExample.createCriteria().andReportTemplateIdEqualTo(template.getId()).andRowIndexEqualTo(r - addRowIndex).andColumnIndexEqualTo(c);
List<CellTemplate> cellTemplates = cellTemplateMapper.selectByExample(cellTemplateExample);
if (CollectionUtils.isNotEmpty(cellTemplates)) {
CellTemplate cellTemplate = cellTemplates.get(0);
PeriodCellTemplate periodCellTemplate = new PeriodCellTemplate();
CommonUtils.copyProperties(cellTemplate, periodCellTemplate);
periodCellTemplate.setId(distributedIdService.nextId());
periodCellTemplate.setPeriod(period);
periodCellTemplate.setReportTemplateId(template.getId());
periodCellTemplate.setRowIndex(r);
periodCellTemplate.setRowName(cellTemplate.getRowName());
periodCellTemplate.setColumnIndex(c);
periodCellTemplate.setColumnName(cellTemplate.getColumnName());
periodCellTemplate.setComment(cellTemplate.getComment());
periodCellTemplate.setCreateTime(cellTemplate.getCreateTime());
periodCellTemplate.setUpdateTime(cellTemplate.getUpdateTime());
periodCellTemplate.setCellTemplateId(cellTemplate.getId());
periodCellTemplate.setDataType(cellTemplate.getDataType());
periodCellTemplate.setIsReadOnly(cellTemplate.getIsReadOnly() ? 1 : 0);
periodCellTemplate.setCopyFromId(cellTemplate.getCopyFromId());
periodCellTemplate.setCreateBy(StringUtils.isBlank(cellTemplate.getCreateBy()) ? "admin" : cellTemplate.getCreateBy());
periodCellTemplate.setUpdateBy(StringUtils.isBlank(cellTemplate.getUpdateBy()) ? "admin" : cellTemplate.getUpdateBy());
periodCellTemplate.setProjectId(projectId);
cellTemplateList.add(periodCellTemplate);
CellTemplateConfigExample configExample = new CellTemplateConfigExample();
configExample.createCriteria().andCellTemplateIdEqualTo(cellTemplate.getId());
List<CellTemplateConfig> configs = cellTemplateConfigMapper.selectByExample(configExample);
if (CollectionUtils.isNotEmpty(configs)) {
for (CellTemplateConfig cellTemplateConfig : configs) {
PeriodCellTemplateConfig periodCellTemplateConfig = new PeriodCellTemplateConfig();
CommonUtils.copyProperties(cellTemplateConfig, periodCellTemplateConfig);
periodCellTemplateConfig.setId(distributedIdService.nextId());
periodCellTemplateConfig.setPeriod(period);
periodCellTemplateConfig.setCellTemplateId(cellTemplateConfig.getCellTemplateId());
periodCellTemplateConfig.setReportTemplateId(template.getId());
periodCellTemplateConfig.setDataSourceType(cellTemplateConfig.getDataSourceType());
periodCellTemplateConfig.setFormula(StringUtils.isBlank(cellTemplateConfig.getFormula()) ? null : cellTemplateConfig.getFormula());
periodCellTemplateConfig.setParsedFormula(null);
periodCellTemplateConfig.setFormulaDescription(cellTemplateConfig.getFormulaDescription());
periodCellTemplateConfig.setAccountCodes(cellTemplateConfig.getAccountCodes());
periodCellTemplateConfig.setInvoiceType(cellTemplateConfig.getInvoiceType());
periodCellTemplateConfig.setTaxRate(cellTemplateConfig.getTaxRate());
periodCellTemplateConfig.setInvoiceAmountType(cellTemplateConfig.getInvoiceAmountType());
periodCellTemplateConfig.setModelIds(cellTemplateConfig.getModelIds());
periodCellTemplateConfig.setCreateBy(StringUtils.isBlank(cellTemplateConfig.getCreateBy()) ? "admin" : cellTemplateConfig.getCreateBy());
periodCellTemplateConfig.setCreateTime(cellTemplateConfig.getCreateTime());
periodCellTemplateConfig.setUpdateBy(StringUtils.isBlank(cellTemplateConfig.getUpdateBy()) ? "admin" : cellTemplateConfig.getUpdateBy());
periodCellTemplateConfig.setUpdateTime(cellTemplateConfig.getUpdateTime());
periodCellTemplateConfig.setInvoiceCategory(cellTemplateConfig.getInvoiceCategory());
periodCellTemplateConfig.setFormulaDataSource(cellTemplateConfig.getFormulaDataSource());
periodCellTemplateConfig.setValidation(cellTemplateConfig.getValidation());
periodCellTemplateConfig.setParsedValidation(null);
periodCellTemplateConfig.setValidationDescription(cellTemplateConfig.getValidationDescription());
periodCellTemplateConfig.setVoucherKeyword(cellTemplateConfig.getVoucherKeyword());
periodCellTemplateConfig.setCellTemplateConfigId(cellTemplateConfig.getId());
periodCellTemplateConfig.setKeyValueParsedFormula(null);
periodCellTemplateConfig.setProjectId(projectId);
fixedParsedFormula(periodCellTemplateConfig);
fixedAccountCode(periodCellTemplateConfig);
cellTemplateConfigList.add(periodCellTemplateConfig);
}
}
}
}
private void addManualConfig(PeriodCellTemplate cellTemplate, Cell cell, Date now, List<PeriodCellTemplateConfig> list) {
PeriodCellTemplateConfig configManual = new PeriodCellTemplateConfig();
configManual.setId(distributedIdService.nextId());
......@@ -1234,7 +1230,6 @@ public class ReportServiceImpl extends BaseService {
}
private static final Integer specialConsideration = 0;//特殊因素考虑
private static final String ebitRate = "1%";//ebit 比率
public List<CellTemplateReferenceDto> getTemplateReferences(int period) {
return new ArrayList<>();
......@@ -1249,7 +1244,7 @@ public class ReportServiceImpl extends BaseService {
OperationResultDto<ReportDataDto> cellData = getCellData(reportId, getProjId(orgId, period));
ReportDataDto reportDataDto = new ReportDataDto();
//特殊因素考虑 默认为0 rate 默认为1%
EbitDataDto ebitDataDto1 = loadEbitData(orgId, period, specialConsideration, ebitRate);
EbitDataDto ebitDataDto1 = loadEbitData(orgId, period, specialConsideration, Constant.ebitRate);
if (cellData.getData() != null) {
cellData.getData().setEbitData(ebitDataDto1);
} else {
......@@ -1259,7 +1254,7 @@ public class ReportServiceImpl extends BaseService {
return cellData;
}
} else if (operationResultDto1.getData().getEbitData() == null && operationResultDto1.getData().getCellData() != null) {
EbitDataDto ebitDataDto1 = loadEbitData(orgId, period, specialConsideration, ebitRate);
EbitDataDto ebitDataDto1 = loadEbitData(orgId, period, specialConsideration, Constant.ebitRate);
operationResultDto1.getData().setEbitData(ebitDataDto1);
} else {
OperationResultDto<ReportDataDto> cellData = getCellData(reportId, getProjId(orgId, period));
......@@ -1300,7 +1295,7 @@ public class ReportServiceImpl extends BaseService {
case 40:
if (ebitCellData1.getData() == null)
break;
ebitDataDto.setEbitRate(Double.parseDouble(ebitCellData1.getData()));
ebitDataDto.setEbitRate(ebitCellData1.getData());
break;
case 41:
if (ebitCellData1.getData() == null)
......@@ -1310,7 +1305,7 @@ public class ReportServiceImpl extends BaseService {
case 42:
if (ebitCellData1.getData() == null)
break;
ebitDataDto.setSixAddTax(ebitCellData1.getData());
ebitDataDto.setSixAddTax(new BigDecimal(ebitCellData1.getData()));
break;
case 43:
if (ebitCellData1.getData() == null)
......@@ -1563,10 +1558,11 @@ public class ReportServiceImpl extends BaseService {
@Resource
private EbitCellDataMapper ebitCellDataMapper;
//加载Ebit数据
public EbitDataDto loadEbitData(String orgId, Integer period, Integer specialConsiderations, String ebitRate) {
double rate = 0.1;
BigDecimal spec = new BigDecimal(0);
double rate = 0.01; //ebitRate
if (!ebitRate.isEmpty()) {
int _index = ebitRate.indexOf("%");
spec = new BigDecimal(specialConsiderations);
......@@ -1590,12 +1586,12 @@ public class ReportServiceImpl extends BaseService {
BigDecimal yffy = new BigDecimal(0);//研发费用
BigDecimal zcjzss = new BigDecimal(0); //资产减值损失
for (ProfitLossStatement profitLossStatement : profitLossStatements) {
BigDecimal value = profitLossStatement.getPeriodAmt();
BigDecimal value = profitLossStatement.getYtdAmt();
switch (profitLossStatement.getItemName()) {
case "加:营业外收入":
case "一、营业收入":
yysr = value;
break;
case "减:营业外支出":
case "减:营业成本":
yycb = value;
case "营业税金及附加":
yysjfj = value;
......@@ -1611,26 +1607,14 @@ public class ReportServiceImpl extends BaseService {
zcjzss = value;
}
EbitDataDto ebitDataDto = new EbitDataDto();
BigDecimal subtract = yysr.subtract(yycb).subtract(yysjfj).subtract(xsfy).subtract(glfy).subtract(yffy).subtract(zcjzss);
BigDecimal subtract = yysr.subtract(yycb).add(yysjfj).add(xsfy).add(glfy).add(yffy).add(zcjzss);
ebitDataDto.setEbitSubtraction(subtract);
ebitDataDto.setSpecialFactors(subtract.add(spec));
ebitDataDto.setEbitRate(rate);
ebitDataDto.setEbitRate(String.valueOf(rate*100 + "%"));
ebitDataDto.setTransactionAmount(ebitDataDto.getSpecialFactors().multiply(new BigDecimal(ebitDataDto.getEbitRate())));
ebitDataDto.setTransactionAmount(ebitDataDto.getTransactionAmount().multiply(new BigDecimal(0.06)));
ebitDataDto.setEbitRate(ebitRate);
ebitDataDto.setSixAddTax(ebitDataDto.getTransactionAmount().multiply(new BigDecimal(0.06)));
ebitDataDto.setTotalAmountTax(ebitDataDto.getTransactionAmount().multiply(new BigDecimal(0.16)));
/*//保存
for (int i = 37; i <= 43; i++) {
EbitCellData ebitCellData = new EbitCellData();
ebitCellData.setData(arr[i - 37]);
ebitCellData.setRow(i);
ebitCellData.setCol(3);
ebitCellData.setCreateTime(now);
ebitCellData.setOrganizationId(orgId);
ebitCellData.setPeriod(period);
ebitCellDataMapper.insert(ebitCellData);
}*/
return ebitDataDto;
}
return null;
......@@ -2331,7 +2315,7 @@ public class ReportServiceImpl extends BaseService {
ebitCellData1.setData(operationResultDto.getData().getEbitData().getTransactionAmount().toString());
ebitCellData1.setRow(i);
case 42:
ebitCellData1.setData(operationResultDto.getData().getEbitData().getSixAddTax());
ebitCellData1.setData(operationResultDto.getData().getEbitData().getSixAddTax().toString());
ebitCellData1.setRow(i);
case 43:
ebitCellData1.setData(operationResultDto.getData().getEbitData().getTotalAmountTax().toString());
......@@ -2348,8 +2332,9 @@ public class ReportServiceImpl extends BaseService {
@Resource
private EbitSpreadDataMapper ebitSpreadDataMapper;
public OperationResultDto spreadToDb(RequestParameterDto.EbitParam ebitParam) {
try {
@Transactional
public synchronized OperationResultDto spreadToDb(HttpServletRequest request, Integer period, String orgId) {
/* try {
EbitSpreadDataExample example = new EbitSpreadDataExample();
EbitSpreadDataExample.Criteria criteria = example.createCriteria();
EbitSpreadDataExample.Criteria criteria1 = criteria.andOrganizationIdEqualTo(ebitParam.getOrgId()).andPeriodEqualTo(ebitParam.getPeriod());
......@@ -2374,7 +2359,29 @@ public class ReportServiceImpl extends BaseService {
operationResultDto.error();
operationResultDto.setResultMsg("spread【json序列化字符串】保存失败");
return operationResultDto;
}*/
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
Map<String,MultipartFile> fileMap = multipartRequest.getFileMap();
MultipartFile file = fileMap.get("llb.xlsx");
String fileName = orgId + period + "利润表";
EbitSpreadDataExample example = new EbitSpreadDataExample();
example.createCriteria().andPeriodEqualTo(period).andOrganizationIdEqualTo(orgId);
List<EbitSpreadData> ebitSpreadData1 = ebitSpreadDataMapper.selectByExample(example);
if(ebitSpreadData1.size() != 0){
didiFileUploadService.delData(ebitSpreadData1.get(0).getFileKey());
ebitSpreadDataMapper.deleteByExample(example);
}
FileUpload fileUpload = didiFileUploadService.uploadFile(file, fileName, "ebit利润表");
EbitSpreadData ebitSpreadData = new EbitSpreadData();
ebitSpreadData.setPeriod(period);
ebitSpreadData.setOrganizationId(orgId);
ebitSpreadData.setFileKey(fileUpload.getUid());
ebitSpreadData.setFileName(fileName);
ebitSpreadData.setId(idService.nextId());
ebitSpreadDataMapper.insert(ebitSpreadData);
return operationResultDto.success();
}
......@@ -2396,8 +2403,11 @@ public class ReportServiceImpl extends BaseService {
*
* @param requestParameterDto
*/
public void manyExport(RequestParameterDto requestParameterDto, String zipFileName, HttpServletRequest request, HttpServletResponse response, String zipPath) throws Exception {
try {
public void manyExport(RequestParameterDto requestParameterDto, String zipFileName, HttpServletRequest request, HttpServletResponse response) throws Exception {
String zipPath = this.getClass().getResource("/").getPath().substring(1) + "zipDir";
String fileName = null;
FileExcelUtil.createFile(zipPath);
/* try {
FileOutputStream out = new FileOutputStream(zipFileName);//要输出的文件名字
} catch (FileNotFoundException e) {
e.printStackTrace();
......@@ -2421,7 +2431,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) {
......@@ -2452,41 +2464,73 @@ public class ReportServiceImpl extends BaseService {
}
}
inputStream = httpFileService.getUserTemplate(templatePath);
Workbook workbook = WorkbookFactory.create(inputStream);
Sheet sheet = workbook.getSheetAt(0);
try {
Cell cell = null;
List<Workbook> workbooksList = Lists.newArrayList();
for (List<EbitCellData> ebitCellDataList1 : dataList) {
Workbook workbook = WorkbookFactory.create(inputStream);
Sheet sheet = workbook.getSheetAt(0);
Workbook newworkbook = new XSSFWorkbook();
Sheet sheet1 = newworkbook.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;
}
}
}
sheet1.getRow(ebitCellData.getRow()).getCell(ebitCellData.getCol()).setCellValue(ebitCellData.getData());
}
POIUtil.cloneSheetAndStyle(workbook.getSheetAt(0), workbook.createSheet("利润表"),newworkbook);
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);
byte[] barray = bos.toByteArray();
InputStream is = new ByteArrayInputStream(barray);*/
// FileOutputStream fileOut = new FileOutputStream(path);
} catch (IOException e) {
e.printStackTrace();
throw new Exception(ErrorMessage.SystemError);
}
}*/
EbitSpreadDataExample example = new EbitSpreadDataExample();
example.createCriteria().andPeriodEqualTo(requestParameterDto.getPeriod());
List<EbitSpreadData> ebitSpreadData = ebitSpreadDataMapper.selectByExample(example);
List<File> fileList = Lists.newArrayList();
if (ebitSpreadData.size() == 0)
throw new Exception("没有可导出的数据");
for (int i = 0; i < ebitSpreadData.size(); i++) {
DidiFileIUploadParam fileParam = new DidiFileIUploadParam();
fileParam.setUuids(Arrays.asList(ebitSpreadData.get(i).getFileKey()));
PageInfo<DidiFileUploadDetailResult> uploadDetail = didiFileUploadService.queryPage(fileParam);
String path = null;
if (CollectionUtils.isNotEmpty(uploadDetail.getList())) {
path = uploadDetail.getList().get(0).getViewHttpUrl();
}
InputStream inputStream = httpFileService.getUserTemplate(path);
Workbook workbook1 = WorkbookFactory.create(inputStream);
fileName = zipPath + "/" + requestParameterDto.getPeriod() + ".xlsx";
fileList.add(FileExcelUtil.generateExcelToPath(workbook1, fileName));
}
String zipPath1 = zipPath + "/sizegang.zip";
FileExcelUtil.downloadZip(request, response, zipFileName, fileList, zipPath1);
//将workbook转成流
/* ByteArrayOutputStream bos = new ByteArrayOutputStream();
workbook.write(bos);
byte[] barray = bos.toByteArray();6
InputStream is = new ByteArrayInputStream(barray);*/
// FileOutputStream fileOut = new FileOutputStream(path);
}
private String getCellStringValue(Cell cell) {
......
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