Commit 302b70ff authored by zhkwei's avatar zhkwei

Merge remote-tracking branch 'origin/dev_mysql' into dev_mysql

parents 804e0d9f 5a872d30
...@@ -8,6 +8,7 @@ import com.google.common.collect.Lists; ...@@ -8,6 +8,7 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.map.HashedMap; import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.*; import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFCell; import org.apache.poi.xssf.usermodel.XSSFCell;
...@@ -19,6 +20,8 @@ import org.springframework.beans.BeanUtils; ...@@ -19,6 +20,8 @@ import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional; 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.CommonUtils;
import pwc.taxtech.atms.common.POIUtil; import pwc.taxtech.atms.common.POIUtil;
import pwc.taxtech.atms.common.message.ErrorMessage; import pwc.taxtech.atms.common.message.ErrorMessage;
...@@ -342,15 +345,17 @@ public class ReportServiceImpl extends BaseService { ...@@ -342,15 +345,17 @@ public class ReportServiceImpl extends BaseService {
andStartDateLessThanOrEqualTo(queryDate).andEndDateGreaterThanOrEqualTo(queryDate). andStartDateLessThanOrEqualTo(queryDate).andEndDateGreaterThanOrEqualTo(queryDate).
andStatusEqualTo(0); andStatusEqualTo(0);
List<RevenueTypeMapping> mappingList = revenueTypeMappingMapper.selectByExample(mappingExample); List<RevenueTypeMapping> mappingList = revenueTypeMappingMapper.selectByExample(mappingExample);
//先清除数据
InvoiceRecord delRecord = new InvoiceRecord();
delRecord.setRevenueCofId(null);
if (!isMergeManualData) {
delRecord.setModifyRevenueCofId(null);
}
InvoiceRecordExample delExample = new InvoiceRecordExample(); InvoiceRecordExample delExample = new InvoiceRecordExample();
delExample.createCriteria().andProjectIdEqualTo(projectId). delExample.createCriteria().andProjectIdEqualTo(projectId)
.andProjectIdEqualTo(projectId).
andPeriodEqualTo(Integer.valueOf(queryDate.replace("-", ""))); andPeriodEqualTo(Integer.valueOf(queryDate.replace("-", "")));
if (isMergeManualData) { invoiceRecordMapper.deleteByExample(delExample);
invoiceRecordMapper.clearRevenueCof(true, false, delExample);
} else {
invoiceRecordMapper.clearRevenueCof(true, true, delExample);
}
Map<String, Long> map = new HashMap<>(); Map<String, Long> map = new HashMap<>();
for (RevenueTypeMapping mapping : mappingList) { for (RevenueTypeMapping mapping : mappingList) {
if (!map.containsKey(mapping.getContent())) { if (!map.containsKey(mapping.getContent())) {
...@@ -470,78 +475,140 @@ public class ReportServiceImpl extends BaseService { ...@@ -470,78 +475,140 @@ public class ReportServiceImpl extends BaseService {
for (int r = sheet.getFirstRowNum(); r <= sheet.getLastRowNum(); r++) { for (int r = sheet.getFirstRowNum(); r <= sheet.getLastRowNum(); r++) {
Row row = sheet.getRow(r); Row row = sheet.getRow(r);
for (int c = row.getFirstCellNum(); c <= row.getLastCellNum(); c++) { for (int c = row.getFirstCellNum(); c <= row.getLastCellNum(); c++) {
Cell cell = row.getCell(c); Cell cell = row.getCell(c);
if (cell == null) { if (cell == null) {
continue;//todo cell == null 如何处理 continue;//todo cell == null 如何处理
} }
if (r <= addRowIndex + 1) { if (r <= addRowIndex + 1) {
if(r == addRowIndex + 1 && c>TaxesCalculateReportEnum.Column.Column_14.getIndex()){ String cellId = projectId + template.getId() + period + r + c;
assembleOriginalTemplateData(template,projectId,period,r,c,addRowIndex,cellTemplateList,cellTemplateConfigList); if ((r - 1) >= 0 && (r - 1) < configIds.size()) {
}else{ cellId += configIds.get(configIds.size() - r);
String cellId = projectId + template.getId() + period + r + c; }
if ((r - 1) >= 0 && (r - 1) < configIds.size()) { Long cellTemplateId = Long.valueOf(cellId.hashCode());
cellId += configIds.get(configIds.size() - r); cellTemplateId = cellTemplateId < 0 ? cellTemplateId : (cellTemplateId * -1);
} //更新手工数据源
Long cellTemplateId = Long.valueOf(cellId.hashCode()); PeriodDataSourceExample delExample = new PeriodDataSourceExample();
cellTemplateId = cellTemplateId < 0 ? cellTemplateId : (cellTemplateId * -1); delExample.createCriteria().andProjectIdEqualTo(projectId)
//更新手工数据源 .andPeriodEqualTo(period).andTypeEqualTo(10).andColumnIndexEqualTo(c).andRowIndexEqualTo(r);
PeriodDataSourceExample delExample = new PeriodDataSourceExample(); PeriodDataSource dataSource = new DataSourceExtendDto();
delExample.createCriteria().andProjectIdEqualTo(projectId) dataSource.setColumnIndex(999);
.andPeriodEqualTo(period).andTypeEqualTo(10).andColumnIndexEqualTo(c).andRowIndexEqualTo(r); dataSource.setRowIndex(999);
PeriodDataSource dataSource = new DataSourceExtendDto(); periodDataSourceMapper.updateByExampleSelective(dataSource, delExample);
dataSource.setColumnIndex(999);
dataSource.setRowIndex(999); PeriodDataSourceExample updateExample = new PeriodDataSourceExample();
periodDataSourceMapper.updateByExampleSelective(dataSource, delExample); updateExample.createCriteria().andProjectIdEqualTo(projectId)
.andPeriodEqualTo(period).andTypeEqualTo(10).andCellTemplateIdEqualTo(cellTemplateId);
PeriodDataSourceExample updateExample = new PeriodDataSourceExample(); dataSource = new DataSourceExtendDto();
updateExample.createCriteria().andProjectIdEqualTo(projectId) dataSource.setColumnIndex(c);
.andPeriodEqualTo(period).andTypeEqualTo(10).andCellTemplateIdEqualTo(cellTemplateId); dataSource.setRowIndex(r);
dataSource = new DataSourceExtendDto(); periodDataSourceMapper.updateByExampleSelective(dataSource, updateExample);
dataSource.setColumnIndex(c); PeriodCellTemplate cellTemplate = new PeriodCellTemplate();
dataSource.setRowIndex(r); cellTemplate.setPeriod(period);
periodDataSourceMapper.updateByExampleSelective(dataSource, updateExample); cellTemplate.setRowName(POIUtil.getCellFormulaString(cell));
PeriodCellTemplate cellTemplate = new PeriodCellTemplate(); cellTemplate.setProjectId(projectId);
cellTemplate.setPeriod(period); cellTemplate.setColumnIndex(c);
cellTemplate.setRowName(POIUtil.getCellFormulaString(cell)); cellTemplate.setCreateTime(now);
cellTemplate.setProjectId(projectId); cellTemplate.setCellTemplateId(cellTemplateId);
cellTemplate.setColumnIndex(c); cellTemplate.setUpdateTime(now);
cellTemplate.setCreateTime(now); cellTemplate.setRowIndex(r);
cellTemplate.setCellTemplateId(cellTemplateId); cellTemplate.setReportTemplateId(template.getId());
cellTemplate.setUpdateTime(now); cellTemplate.setId(distributedIdService.nextId());
cellTemplate.setRowIndex(r); if (cell.getCellComment() != null) {
cellTemplate.setReportTemplateId(template.getId()); cellTemplate.setComment(cell.getCellComment().getString().getString());
cellTemplate.setId(distributedIdService.nextId()); }
if (cell.getCellComment() != null) { cellTemplate.setIsReadOnly(hasHandDatas.contains(c) ? 0 : 1);
cellTemplate.setComment(cell.getCellComment().getString().getString()); cellTemplateList.add(cellTemplate);
} if (r > 0 && hasFormulaDatas.contains(c) && StringUtils.isNotBlank(POIUtil.getCellFormulaString(cell))) {
cellTemplate.setIsReadOnly(hasHandDatas.contains(c) ? 0 : 1); PeriodCellTemplateConfig periodCellTemplateConfig = new PeriodCellTemplateConfig();
cellTemplateList.add(cellTemplate); periodCellTemplateConfig.setId(distributedIdService.nextId());
if (r > 0 && hasFormulaDatas.contains(c) && StringUtils.isNotBlank(POIUtil.getCellFormulaString(cell))) { periodCellTemplateConfig.setPeriod(period);
PeriodCellTemplateConfig periodCellTemplateConfig = new PeriodCellTemplateConfig(); periodCellTemplateConfig.setCellTemplateId(cellTemplateId);
periodCellTemplateConfig.setId(distributedIdService.nextId()); periodCellTemplateConfig.setReportTemplateId(template.getId());
periodCellTemplateConfig.setPeriod(period); periodCellTemplateConfig.setDataSourceType(1);
periodCellTemplateConfig.setCellTemplateId(cellTemplateId); periodCellTemplateConfig.setFormula(POIUtil.getCellFormulaString(cell));
periodCellTemplateConfig.setReportTemplateId(template.getId()); periodCellTemplateConfig.setParsedFormula(null);
periodCellTemplateConfig.setDataSourceType(1);
periodCellTemplateConfig.setFormula(POIUtil.getCellFormulaString(cell));
periodCellTemplateConfig.setParsedFormula(null);
// periodCellTemplateConfig.setCreateBy(authUserHelper.getCurrentUserId()); // periodCellTemplateConfig.setCreateBy(authUserHelper.getCurrentUserId());
periodCellTemplateConfig.setCreateTime(now); periodCellTemplateConfig.setCreateTime(now);
// periodCellTemplateConfig.setUpdateBy(authUserHelper.getCurrentUserId()); // periodCellTemplateConfig.setUpdateBy(authUserHelper.getCurrentUserId());
periodCellTemplateConfig.setUpdateTime(now); periodCellTemplateConfig.setUpdateTime(now);
periodCellTemplateConfig.setFormulaDataSource("报表数据"); periodCellTemplateConfig.setFormulaDataSource("报表数据");
periodCellTemplateConfig.setKeyValueParsedFormula(null); periodCellTemplateConfig.setKeyValueParsedFormula(null);
periodCellTemplateConfig.setProjectId(projectId); periodCellTemplateConfig.setProjectId(projectId);
fixedParsedFormula(periodCellTemplateConfig); fixedParsedFormula(periodCellTemplateConfig);
fixedAccountCode(periodCellTemplateConfig); fixedAccountCode(periodCellTemplateConfig);
cellTemplateConfigList.add(periodCellTemplateConfig); cellTemplateConfigList.add(periodCellTemplateConfig);
} }
if (r > 0 && r <= addRowIndex && hasHandDatas.contains(c)) { if (r > 0 && r <= addRowIndex && hasHandDatas.contains(c)) {
addManualConfig(cellTemplate, cell, now, cellTemplateConfigList); addManualConfig(cellTemplate, cell, now, cellTemplateConfigList);
}
} }
} else { } 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 { ...@@ -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) { private void addManualConfig(PeriodCellTemplate cellTemplate, Cell cell, Date now, List<PeriodCellTemplateConfig> list) {
PeriodCellTemplateConfig configManual = new PeriodCellTemplateConfig(); PeriodCellTemplateConfig configManual = new PeriodCellTemplateConfig();
configManual.setId(distributedIdService.nextId()); configManual.setId(distributedIdService.nextId());
...@@ -1234,7 +1230,6 @@ public class ReportServiceImpl extends BaseService { ...@@ -1234,7 +1230,6 @@ public class ReportServiceImpl extends BaseService {
} }
private static final Integer specialConsideration = 0;//特殊因素考虑 private static final Integer specialConsideration = 0;//特殊因素考虑
private static final String ebitRate = "1%";//ebit 比率
public List<CellTemplateReferenceDto> getTemplateReferences(int period) { public List<CellTemplateReferenceDto> getTemplateReferences(int period) {
return new ArrayList<>(); return new ArrayList<>();
...@@ -1249,7 +1244,7 @@ public class ReportServiceImpl extends BaseService { ...@@ -1249,7 +1244,7 @@ public class ReportServiceImpl extends BaseService {
OperationResultDto<ReportDataDto> cellData = getCellData(reportId, getProjId(orgId, period)); OperationResultDto<ReportDataDto> cellData = getCellData(reportId, getProjId(orgId, period));
ReportDataDto reportDataDto = new ReportDataDto(); ReportDataDto reportDataDto = new ReportDataDto();
//特殊因素考虑 默认为0 rate 默认为1% //特殊因素考虑 默认为0 rate 默认为1%
EbitDataDto ebitDataDto1 = loadEbitData(orgId, period, specialConsideration, ebitRate); EbitDataDto ebitDataDto1 = loadEbitData(orgId, period, specialConsideration, Constant.ebitRate);
if (cellData.getData() != null) { if (cellData.getData() != null) {
cellData.getData().setEbitData(ebitDataDto1); cellData.getData().setEbitData(ebitDataDto1);
} else { } else {
...@@ -1259,7 +1254,7 @@ public class ReportServiceImpl extends BaseService { ...@@ -1259,7 +1254,7 @@ public class ReportServiceImpl extends BaseService {
return cellData; return cellData;
} }
} else if (operationResultDto1.getData().getEbitData() == null && operationResultDto1.getData().getCellData() != null) { } 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); operationResultDto1.getData().setEbitData(ebitDataDto1);
} else { } else {
OperationResultDto<ReportDataDto> cellData = getCellData(reportId, getProjId(orgId, period)); OperationResultDto<ReportDataDto> cellData = getCellData(reportId, getProjId(orgId, period));
...@@ -1300,7 +1295,7 @@ public class ReportServiceImpl extends BaseService { ...@@ -1300,7 +1295,7 @@ public class ReportServiceImpl extends BaseService {
case 40: case 40:
if (ebitCellData1.getData() == null) if (ebitCellData1.getData() == null)
break; break;
ebitDataDto.setEbitRate(Double.parseDouble(ebitCellData1.getData())); ebitDataDto.setEbitRate(ebitCellData1.getData());
break; break;
case 41: case 41:
if (ebitCellData1.getData() == null) if (ebitCellData1.getData() == null)
...@@ -1310,7 +1305,7 @@ public class ReportServiceImpl extends BaseService { ...@@ -1310,7 +1305,7 @@ public class ReportServiceImpl extends BaseService {
case 42: case 42:
if (ebitCellData1.getData() == null) if (ebitCellData1.getData() == null)
break; break;
ebitDataDto.setSixAddTax(ebitCellData1.getData()); ebitDataDto.setSixAddTax(new BigDecimal(ebitCellData1.getData()));
break; break;
case 43: case 43:
if (ebitCellData1.getData() == null) if (ebitCellData1.getData() == null)
...@@ -1563,10 +1558,11 @@ public class ReportServiceImpl extends BaseService { ...@@ -1563,10 +1558,11 @@ public class ReportServiceImpl extends BaseService {
@Resource @Resource
private EbitCellDataMapper ebitCellDataMapper; private EbitCellDataMapper ebitCellDataMapper;
//加载Ebit数据 //加载Ebit数据
public EbitDataDto loadEbitData(String orgId, Integer period, Integer specialConsiderations, String ebitRate) { public EbitDataDto loadEbitData(String orgId, Integer period, Integer specialConsiderations, String ebitRate) {
double rate = 0.1;
BigDecimal spec = new BigDecimal(0); BigDecimal spec = new BigDecimal(0);
double rate = 0.01; //ebitRate
if (!ebitRate.isEmpty()) { if (!ebitRate.isEmpty()) {
int _index = ebitRate.indexOf("%"); int _index = ebitRate.indexOf("%");
spec = new BigDecimal(specialConsiderations); spec = new BigDecimal(specialConsiderations);
...@@ -1590,12 +1586,12 @@ public class ReportServiceImpl extends BaseService { ...@@ -1590,12 +1586,12 @@ public class ReportServiceImpl extends BaseService {
BigDecimal yffy = new BigDecimal(0);//研发费用 BigDecimal yffy = new BigDecimal(0);//研发费用
BigDecimal zcjzss = new BigDecimal(0); //资产减值损失 BigDecimal zcjzss = new BigDecimal(0); //资产减值损失
for (ProfitLossStatement profitLossStatement : profitLossStatements) { for (ProfitLossStatement profitLossStatement : profitLossStatements) {
BigDecimal value = profitLossStatement.getPeriodAmt(); BigDecimal value = profitLossStatement.getYtdAmt();
switch (profitLossStatement.getItemName()) { switch (profitLossStatement.getItemName()) {
case "加:营业外收入": case "一、营业收入":
yysr = value; yysr = value;
break; break;
case "减:营业外支出": case "减:营业成本":
yycb = value; yycb = value;
case "营业税金及附加": case "营业税金及附加":
yysjfj = value; yysjfj = value;
...@@ -1611,26 +1607,14 @@ public class ReportServiceImpl extends BaseService { ...@@ -1611,26 +1607,14 @@ public class ReportServiceImpl extends BaseService {
zcjzss = value; zcjzss = value;
} }
EbitDataDto ebitDataDto = new EbitDataDto(); 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.setEbitSubtraction(subtract);
ebitDataDto.setSpecialFactors(subtract.add(spec)); 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.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))); 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 ebitDataDto;
} }
return null; return null;
...@@ -2331,7 +2315,7 @@ public class ReportServiceImpl extends BaseService { ...@@ -2331,7 +2315,7 @@ public class ReportServiceImpl extends BaseService {
ebitCellData1.setData(operationResultDto.getData().getEbitData().getTransactionAmount().toString()); ebitCellData1.setData(operationResultDto.getData().getEbitData().getTransactionAmount().toString());
ebitCellData1.setRow(i); ebitCellData1.setRow(i);
case 42: case 42:
ebitCellData1.setData(operationResultDto.getData().getEbitData().getSixAddTax()); ebitCellData1.setData(operationResultDto.getData().getEbitData().getSixAddTax().toString());
ebitCellData1.setRow(i); ebitCellData1.setRow(i);
case 43: case 43:
ebitCellData1.setData(operationResultDto.getData().getEbitData().getTotalAmountTax().toString()); ebitCellData1.setData(operationResultDto.getData().getEbitData().getTotalAmountTax().toString());
...@@ -2348,8 +2332,9 @@ public class ReportServiceImpl extends BaseService { ...@@ -2348,8 +2332,9 @@ public class ReportServiceImpl extends BaseService {
@Resource @Resource
private EbitSpreadDataMapper ebitSpreadDataMapper; private EbitSpreadDataMapper ebitSpreadDataMapper;
public OperationResultDto spreadToDb(RequestParameterDto.EbitParam ebitParam) { @Transactional
try { public synchronized OperationResultDto spreadToDb(HttpServletRequest request, Integer period, String orgId) {
/* try {
EbitSpreadDataExample example = new EbitSpreadDataExample(); EbitSpreadDataExample example = new EbitSpreadDataExample();
EbitSpreadDataExample.Criteria criteria = example.createCriteria(); EbitSpreadDataExample.Criteria criteria = example.createCriteria();
EbitSpreadDataExample.Criteria criteria1 = criteria.andOrganizationIdEqualTo(ebitParam.getOrgId()).andPeriodEqualTo(ebitParam.getPeriod()); EbitSpreadDataExample.Criteria criteria1 = criteria.andOrganizationIdEqualTo(ebitParam.getOrgId()).andPeriodEqualTo(ebitParam.getPeriod());
...@@ -2374,7 +2359,29 @@ public class ReportServiceImpl extends BaseService { ...@@ -2374,7 +2359,29 @@ public class ReportServiceImpl extends BaseService {
operationResultDto.error(); operationResultDto.error();
operationResultDto.setResultMsg("spread【json序列化字符串】保存失败"); operationResultDto.setResultMsg("spread【json序列化字符串】保存失败");
return operationResultDto; 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(); return operationResultDto.success();
} }
...@@ -2396,8 +2403,11 @@ public class ReportServiceImpl extends BaseService { ...@@ -2396,8 +2403,11 @@ public class ReportServiceImpl extends BaseService {
* *
* @param requestParameterDto * @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) throws Exception {
try { String zipPath = this.getClass().getResource("/").getPath().substring(1) + "zipDir";
String fileName = null;
FileExcelUtil.createFile(zipPath);
/* try {
FileOutputStream out = new FileOutputStream(zipFileName);//要输出的文件名字 FileOutputStream out = new FileOutputStream(zipFileName);//要输出的文件名字
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
e.printStackTrace(); e.printStackTrace();
...@@ -2421,7 +2431,9 @@ public class ReportServiceImpl extends BaseService { ...@@ -2421,7 +2431,9 @@ public class ReportServiceImpl extends BaseService {
List<EbitCellData> ebitCellDataList = ebitCellDataMapper.selectByExample(example);//获取当前期间下所有的数据 List<EbitCellData> ebitCellDataList = ebitCellDataMapper.selectByExample(example);//获取当前期间下所有的数据
List<List<EbitCellData>> dataList = Lists.newArrayList(); List<List<EbitCellData>> dataList = Lists.newArrayList();
List<EbitCellData> orgList = ebitCellDataMapper.selectOrgType(requestParameterDto.getPeriod()); 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++) { for (int i = 0; i < orgList.size(); i++) {
orgTypeList = Lists.newArrayList(); orgTypeList = Lists.newArrayList();
for (EbitCellData ebitCellData : ebitCellDataList) { for (EbitCellData ebitCellData : ebitCellDataList) {
...@@ -2452,41 +2464,73 @@ public class ReportServiceImpl extends BaseService { ...@@ -2452,41 +2464,73 @@ public class ReportServiceImpl extends BaseService {
} }
} }
inputStream = httpFileService.getUserTemplate(templatePath); inputStream = httpFileService.getUserTemplate(templatePath);
Workbook workbook = WorkbookFactory.create(inputStream);
Sheet sheet = workbook.getSheetAt(0);
try { try {
Cell cell = null; Cell cell = null;
List<Workbook> workbooksList = Lists.newArrayList(); List<Workbook> workbooksList = Lists.newArrayList();
for (List<EbitCellData> ebitCellDataList1 : dataList) { for (List<EbitCellData> ebitCellDataList1 : dataList) {
Workbook workbook = WorkbookFactory.create(inputStream); Workbook newworkbook = new XSSFWorkbook();
Sheet sheet = workbook.getSheetAt(0); Sheet sheet1 = newworkbook.getSheetAt(0);
if (isSheetEmpty(sheet)) throw new Exception("模板异常"); if (isSheetEmpty(sheet)) throw new Exception("模板异常");
for (EbitCellData ebitCellData : ebitCellDataList1) { for (EbitCellData ebitCellData : ebitCellDataList1) {
loop1:
for (int j = 1, k = sheet.getLastRowNum(); j < k; j++) { 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++) { for (int m = 1, n = sheet.getRow(j).getLastCellNum(); m < n; m++) {
cell = sheet.getRow(j).getCell(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()); 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); workbooksList.add(workbook);
//将workbook生成file文件 //将workbook生成file文件
String path = "\\\\zipDir\\\\" + requestParameterDto.getPeriod() + Math.random() + "利润表"; 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) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
throw new Exception(ErrorMessage.SystemError); 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) { 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