Commit 3b1cda94 authored by frank.xa.zhang's avatar frank.xa.zhang

add report view backend code

parent ea74a6a8
package pwc.taxtech.atms.dto.vatdto;
import lombok.Getter;
import lombok.Setter;
import pwc.taxtech.atms.dto.CellTemplateConfigDto;
import pwc.taxtech.atms.vat.entity.ModifiedReportCell;
import pwc.taxtech.atms.vat.entity.PeriodCellTemplateConfig;
import java.util.List;
@Setter
@Getter
public class CellCalcInfoDto {
private Long cellID;
private Long reportID;
private Integer columnIndex;
private String columnName;
private Integer rowIndex;
private String rowName;
private String formula;
private String parsedFormula;
private Boolean isCalculated;
private String cellValue;
private Long cellTemplateID;
private Long reportTemplateID;
private Integer dataType;
private Boolean isReadOnly;
private String dataSourceExp;
private String formulaExp;
private String description;
private Boolean dataSourceAvailable;
private CellTemplateConfigDto cellTemplateConfig;
private List<DataSourceDto> dataSourceList;
private InvoiceListDto dataInvoiceList;
//是否是用户手工调整过得值
private Boolean isModified;
//用户直接修改单元格的信息
private ModifiedReportCell modifiedReportCell;
private List<CellVoucherDatasourceDto> dataVoucherList;
private Boolean isConfigured;
private Boolean hasModelError;
//private List<ErrorInfoDto> ErrorInfoList;
//private List<ModelBackFillAmountDesc> entriesCheckResultList;
//private List<FormulaValidationError> ValidationErrorList ;
private String comment;
private List<PeriodCellTemplateConfig> configList;
}
...@@ -10,9 +10,9 @@ import java.util.List; ...@@ -10,9 +10,9 @@ import java.util.List;
@Getter @Getter
@Setter @Setter
public class CellDataDto { public class CellDataDto {
private String cellID ; private Long cellID ;
private String reportID ; private Long reportID ;
private int columnIndex ; private int columnIndex ;
...@@ -28,13 +28,13 @@ public class CellDataDto { ...@@ -28,13 +28,13 @@ public class CellDataDto {
private String cellValue ; private String cellValue ;
private String cellTemplateID ; private Long cellTemplateID ;
private String reportTemplateID ; private Long reportTemplateID ;
private Integer dataType ; private Integer dataType ;
private Integer isReadOnly ; private Boolean isReadOnly ;
private String dataSourceExp ; private String dataSourceExp ;
private String formulaExp ; private String formulaExp ;
......
package pwc.taxtech.atms.dto.vatdto;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class CellTemplateConfigGroupDto {
Integer columnIndex;
Integer rowIndex;
String columnName;
String rowName;
Integer dataType;
Boolean isReadOnly;
Long templateID;
Long reportTemplateID;
String comment;
public CellTemplateConfigGroupDto(Integer columnIndex, Integer rowIndex
, String columnName, String rowName, Integer dataType, Boolean isReadOnly
, Long templateID, Long reportTemplateID, String comment) {
this.columnIndex = columnIndex;
this.rowIndex = rowIndex;
this.columnName = columnName;
this.rowName = rowName;
this.dataType = dataType;
this.isReadOnly = isReadOnly;
this.templateID = templateID;
this.reportTemplateID = reportTemplateID;
this.comment = comment;
}
}
...@@ -17,7 +17,7 @@ public class DataSourceDto { ...@@ -17,7 +17,7 @@ public class DataSourceDto {
this.internalCode = _DataSourcePrefix + hashCode() + _DataSourceSuffix; this.internalCode = _DataSourcePrefix + hashCode() + _DataSourceSuffix;
} }
String id; Long id;
String internalCode; String internalCode;
String name; String name;
......
package pwc.taxtech.atms.dto.vatdto;
import lombok.Getter;
import lombok.Setter;
import pwc.taxtech.atms.vat.entity.DataSource;
@Getter
@Setter
public class DataSourceExtendDto extends DataSource {
private Integer operationType;
private Long cellTemplateID;
private Long cellDataID;
}
package pwc.taxtech.atms.dto.vatdto;
import lombok.Getter;
import lombok.Setter;
import pwc.taxtech.atms.common.CommonUtils;
import pwc.taxtech.atms.vat.entity.PeriodCellTemplateConfig;
@Setter
@Getter
public class PeriodCellTemplateConfigExtendDto extends PeriodCellTemplateConfig {
Integer columnIndex;
Integer rowIndex;
String columnName;
String rowName;
Integer dataType;
Boolean isReadOnly;
Long templateID;
Long reportTemplateID;
String comment;
PeriodCellTemplateConfig periodCellTemplateConfig;
public PeriodCellTemplateConfig getPeriodCellTemplateConfig() {
CommonUtils.copyProperties(this, periodCellTemplateConfig);
return periodCellTemplateConfig;
}
}
...@@ -12,5 +12,5 @@ import java.util.Map; ...@@ -12,5 +12,5 @@ import java.util.Map;
public class ReportDataDto { public class ReportDataDto {
private List<CellDataDto> cellData; private List<CellDataDto> cellData;
private List<PeriodFormulaBlock> formulaBlocks; private List<PeriodFormulaBlock> formulaBlocks;
private Map<String,DataSourceDto> manualDataSources; private Map<Long, DataSourceDto> manualDataSources;
} }
...@@ -4,8 +4,10 @@ import org.apache.commons.lang3.StringUtils; ...@@ -4,8 +4,10 @@ import org.apache.commons.lang3.StringUtils;
import pwc.taxtech.atms.constant.Constant; import pwc.taxtech.atms.constant.Constant;
import pwc.taxtech.atms.constant.enums.CellDataSourceType; import pwc.taxtech.atms.constant.enums.CellDataSourceType;
import pwc.taxtech.atms.dto.CellTemplateConfigDto; import pwc.taxtech.atms.dto.CellTemplateConfigDto;
import pwc.taxtech.atms.dto.vatdto.CellCalcInfoDto;
import pwc.taxtech.atms.entitiy.CellTemplate; import pwc.taxtech.atms.entitiy.CellTemplate;
import pwc.taxtech.atms.entitiy.CellTemplateConfig; import pwc.taxtech.atms.entitiy.CellTemplateConfig;
import pwc.taxtech.atms.vat.entity.PeriodCellTemplateConfig;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
...@@ -23,8 +25,16 @@ public final class CellConfigTranslater { ...@@ -23,8 +25,16 @@ public final class CellConfigTranslater {
template.getColumnName(), template.getDataType(), template.getIsReadOnly(), template.getComment(), configList); template.getColumnName(), template.getDataType(), template.getIsReadOnly(), template.getComment(), configList);
} }
public static CellTemplateConfigDto getConfigDto(CellCalcInfoDto x) {
return CellConfigTranslater.getPeriodConfigDto(x.getCellTemplateID(), x.getCellTemplateID(), x.getRowIndex(),
x.getRowName(), x.getColumnIndex(), x.getColumnName(),
x.getDataType(), x.getIsReadOnly(),
x.getDescription(), x.getConfigList());
}
private static CellTemplateConfigDto getConfigDto(Long configID, Long templateID, int rowIndex, String rowName, int columnIndex, private static CellTemplateConfigDto getConfigDto(Long configID, Long templateID, int rowIndex, String rowName, int columnIndex,
String columnName, Integer dataType, Boolean isReadOnly, String description, List<CellTemplateConfig> configList) { String columnName, Integer dataType, Boolean isReadOnly, String description,
List<CellTemplateConfig> configList) {
if (configList == null) { if (configList == null) {
return null; return null;
} }
...@@ -105,6 +115,114 @@ public final class CellConfigTranslater { ...@@ -105,6 +115,114 @@ public final class CellConfigTranslater {
return cellTemplateConfigDto; return cellTemplateConfigDto;
} }
private static CellTemplateConfigDto getPeriodConfigDto(Long configID, Long templateID, int rowIndex, String rowName, int columnIndex,
String columnName, Integer dataType, Boolean isReadOnly,
String description, List<PeriodCellTemplateConfig> configList) {
//already finished by today 20180711
if (configList == null) {
return null;
}
CellTemplateConfigDto cellTemplateConfigDto = new CellTemplateConfigDto();
cellTemplateConfigDto.setCellTemplateID(configID);
cellTemplateConfigDto.setTemplateID(templateID);
cellTemplateConfigDto.setRowIndex(rowIndex);
cellTemplateConfigDto.setRowName(rowName);
cellTemplateConfigDto.setColumnIndex(columnIndex);
cellTemplateConfigDto.setColumnName(columnName);
cellTemplateConfigDto.setDataType(dataType);
cellTemplateConfigDto.setIsReadOnly(isReadOnly);
cellTemplateConfigDto.setFormulaDescription(description);
Optional<PeriodCellTemplateConfig> formulaItem = configList.stream()
.filter(x -> x.getDataSourceType().equals(CellDataSourceType.Formula.getCode()))
.findFirst();
if (formulaItem.isPresent()) {
cellTemplateConfigDto.setHasFormula(true);
cellTemplateConfigDto.setFormula(formulaItem.get().getFormula());
cellTemplateConfigDto.setParsedFormula(formulaItem.get().getParsedFormula());
if (StringUtils.isBlank(cellTemplateConfigDto.getFormulaDescription())
&& StringUtils.isNotBlank(formulaItem.get().getFormulaDescription())) {
cellTemplateConfigDto.setFormulaDescription(formulaItem.get().getFormulaDescription());
}
cellTemplateConfigDto.setFormulaDataSource(formulaItem.get().getFormulaDataSource());
cellTemplateConfigDto.setCellTemplateID(formulaItem.get().getCellTemplateId());
}
Optional<PeriodCellTemplateConfig> voucherItem = configList.stream()
.filter(x -> x.getDataSourceType().equals(CellDataSourceType.Voucher.getCode())).findFirst();
if (voucherItem.isPresent()) {
cellTemplateConfigDto.setHasVoucher(true);
cellTemplateConfigDto.setVoucherKeyword(voucherItem.get().getVoucherKeyword() == null
? StringUtils.EMPTY : voucherItem.get().getVoucherKeyword());
if (StringUtils.isNotBlank(voucherItem.get().getAccountCodes())) {
cellTemplateConfigDto.setAccountCodes(getList(voucherItem.get().getAccountCodes()));
}
}
Optional<PeriodCellTemplateConfig> invoiceItem = configList.stream()
.filter(x -> (x.getDataSourceType().equals(CellDataSourceType.OutputInvoice.getCode()))
|| (x.getDataSourceType().equals(CellDataSourceType.InputInvoice.getCode())
|| (x.getDataSourceType().equals(CellDataSourceType.CustomInvoice.getCode())))).findFirst();
if (invoiceItem.isPresent()) {
cellTemplateConfigDto.setHasInvoice(true);
cellTemplateConfigDto.setInvoiceType(invoiceItem.get().getInvoiceType());
cellTemplateConfigDto.setInvoiceAmountType(invoiceItem.get().getInvoiceAmountType());
if (StringUtils.isNotBlank(invoiceItem.get().getTaxRate())) {
cellTemplateConfigDto.setTaxRate(getList(invoiceItem.get().getTaxRate()));
}
if (StringUtils.isNotBlank(invoiceItem.get().getInvoiceCategory())) {
List<String> invoiceCategoryStrs = getList(invoiceItem.get().getInvoiceCategory());
List<Integer> invoiceCategoryList = new ArrayList<>();
invoiceCategoryStrs.forEach(s -> {
Integer categoryVal;
try {
categoryVal = Integer.parseInt(s);
invoiceCategoryList.add(categoryVal);
} catch (Exception e) {
//转换错误就不做添加,直接吃掉这里的异常,不进行阻塞
}
});
cellTemplateConfigDto.setInvoiceCategory(invoiceCategoryList);
}
}
Optional<PeriodCellTemplateConfig> keyInItem = configList.stream()
.filter(x -> x.getDataSourceType().equals(CellDataSourceType.KeyIn.getCode()))
.findFirst();
if (keyInItem.isPresent()) {
cellTemplateConfigDto.setHasKeyIn(true);
}
Optional<PeriodCellTemplateConfig> modelItem = configList.stream()
.filter(x -> x.getDataSourceType().equals(CellDataSourceType.RelatedModel.getCode()))
.findFirst();
if (modelItem.isPresent()) {
cellTemplateConfigDto.setHasModel(true);
cellTemplateConfigDto.setModelIDs(getList(modelItem.get().getModelIds()));
}
Optional<PeriodCellTemplateConfig> validationItem = configList.stream()
.filter(x -> x.getDataSourceType().equals(CellDataSourceType.Validation.getCode()))
.findFirst();
if (validationItem.isPresent()) {
cellTemplateConfigDto.setHasValidation(true);
cellTemplateConfigDto.setValidation(validationItem.get().getValidation());
cellTemplateConfigDto.setParsedFormula(validationItem.get().getParsedFormula());
cellTemplateConfigDto.setValidationDescription(validationItem.get().getValidationDescription());
cellTemplateConfigDto.setCellTemplateID(validationItem.get().getCellTemplateId());
}
return cellTemplateConfigDto;
}
private static List<String> getList(String joinString) { private static List<String> getList(String joinString) {
if (StringUtils.isEmpty(joinString)) { if (StringUtils.isEmpty(joinString)) {
return null; return null;
......
package pwc.taxtech.atms.vat.dao; package pwc.taxtech.atms.vat.dao;
import java.util.List;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.session.RowBounds; import org.apache.ibatis.session.RowBounds;
import pwc.taxtech.atms.MyVatMapper; import pwc.taxtech.atms.MyVatMapper;
import pwc.taxtech.atms.dto.vatdto.DataSourceExtendDto;
import pwc.taxtech.atms.vat.entity.DataSource; import pwc.taxtech.atms.vat.entity.DataSource;
import pwc.taxtech.atms.vat.entity.DataSourceExample; import pwc.taxtech.atms.vat.entity.DataSourceExample;
import java.util.List;
@Mapper @Mapper
public interface DataSourceMapper extends MyVatMapper { public interface DataSourceMapper extends MyVatMapper {
/** /**
...@@ -106,22 +108,23 @@ public interface DataSourceMapper extends MyVatMapper { ...@@ -106,22 +108,23 @@ public interface DataSourceMapper extends MyVatMapper {
*/ */
int updateByPrimaryKey(DataSource record); int updateByPrimaryKey(DataSource record);
void clearFormulaBlockWithPeriod(@Param("period")Integer period); void clearFormulaBlockWithPeriod(@Param("period") Integer period);
void clearTaxRuleSettingWithPeriod(@Param("period")Integer period); void clearTaxRuleSettingWithPeriod(@Param("period") Integer period);
void clearCellTemplateWithPeriod(@Param("period")Integer period,@Param("exceptReportTemplateIDs") String exceptReportTemplateIDs); void clearCellTemplateWithPeriod(@Param("period") Integer period, @Param("exceptReportTemplateIDs") String exceptReportTemplateIDs);
void clearCellTemplateConfigWithPeriod(@Param("period")Integer period,@Param("exceptReportTemplateIDs") String exceptReportTemplateIDs); void clearCellTemplateConfigWithPeriod(@Param("period") Integer period, @Param("exceptReportTemplateIDs") String exceptReportTemplateIDs);
void clearTemplateWithPeriod(@Param("period")Integer period,@Param("exceptReportTemplateIDs") String exceptReportTemplateIDs); void clearTemplateWithPeriod(@Param("period") Integer period, @Param("exceptReportTemplateIDs") String exceptReportTemplateIDs);
void clearTaxPayerReportWithPeriod(@Param("period")Integer period); void clearTaxPayerReportWithPeriod(@Param("period") Integer period);
void clearDataSourceWithPeriod(@Param("period")Integer period); void clearDataSourceWithPeriod(@Param("period") Integer period);
void clearDataSourceDetailWithPeriod(@Param("period")Integer period); void clearDataSourceDetailWithPeriod(@Param("period") Integer period);
void clearCellDataWithPeriod(@Param("exceptReportTemplateIDs") String exceptReportTemplateIDs); void clearCellDataWithPeriod(@Param("exceptReportTemplateIDs") String exceptReportTemplateIDs);
List<DataSourceExtendDto> getFormulaDataSource(Long reportID);
} }
\ No newline at end of file
...@@ -5,6 +5,7 @@ import org.apache.ibatis.annotations.Mapper; ...@@ -5,6 +5,7 @@ import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.session.RowBounds; import org.apache.ibatis.session.RowBounds;
import pwc.taxtech.atms.MyVatMapper; import pwc.taxtech.atms.MyVatMapper;
import pwc.taxtech.atms.dto.vatdto.PeriodCellTemplateConfigExtendDto;
import pwc.taxtech.atms.vat.entity.PeriodCellTemplateConfig; import pwc.taxtech.atms.vat.entity.PeriodCellTemplateConfig;
import pwc.taxtech.atms.vat.entity.PeriodCellTemplateConfigExample; import pwc.taxtech.atms.vat.entity.PeriodCellTemplateConfigExample;
...@@ -107,4 +108,6 @@ public interface PeriodCellTemplateConfigMapper extends MyVatMapper { ...@@ -107,4 +108,6 @@ public interface PeriodCellTemplateConfigMapper extends MyVatMapper {
int updateByPrimaryKey(PeriodCellTemplateConfig record); int updateByPrimaryKey(PeriodCellTemplateConfig record);
void batchInsert(List<PeriodCellTemplateConfig> list); void batchInsert(List<PeriodCellTemplateConfig> list);
List<PeriodCellTemplateConfigExtendDto> getPeriodCellTemplateConfigExtendDtos(@Param("templateIDList")List<Long> templateIDList,Integer period);
} }
\ No newline at end of file
package pwc.taxtech.atms.vat.service; package pwc.taxtech.atms.vat.service;
import pwc.taxtech.atms.dto.vatdto.CellCalcInfoDto;
import java.util.List; import java.util.List;
public interface ReportGenerator { public interface ReportGenerator {
String generateData(String projectId, List<Long> templateIds, Boolean ifDeleteManualDataSource, List<String> exceptCellTemplates,Integer periodParam, String generator); String generateData(String projectId, List<Long> templateIds, Boolean ifDeleteManualDataSource, List<String> exceptCellTemplates,Integer periodParam, String generator);
List<CellCalcInfoDto> getCellCalcInfo(List<Long> templateIDList, Integer periodParam);
} }
package pwc.taxtech.atms.vat.service.impl; package pwc.taxtech.atms.vat.service.impl;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.formula.functions.FreeRefFunction; import org.apache.poi.ss.formula.functions.FreeRefFunction;
import org.apache.poi.ss.formula.udf.AggregatingUDFFinder; import org.apache.poi.ss.formula.udf.AggregatingUDFFinder;
import org.apache.poi.ss.formula.udf.DefaultUDFFinder; import org.apache.poi.ss.formula.udf.DefaultUDFFinder;
import org.apache.poi.ss.formula.udf.UDFFinder; import org.apache.poi.ss.formula.udf.UDFFinder;
import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.usermodel.FormulaEvaluator;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import pwc.taxtech.atms.common.POIUtil; import pwc.taxtech.atms.common.POIUtil;
import pwc.taxtech.atms.constant.enums.CellDataSourceType; import pwc.taxtech.atms.constant.enums.CellDataSourceType;
import pwc.taxtech.atms.service.impl.DistributedIDService; import pwc.taxtech.atms.dto.vatdto.CellCalcInfoDto;
import pwc.taxtech.atms.vat.dao.CellDataMapper; import pwc.taxtech.atms.dto.vatdto.CellTemplateConfigGroupDto;
import pwc.taxtech.atms.vat.dao.PeriodCellTemplateConfigMapper; import pwc.taxtech.atms.dto.vatdto.PeriodCellTemplateConfigExtendDto;
import pwc.taxtech.atms.vat.dao.PeriodCellTemplateMapper; import pwc.taxtech.atms.vat.entity.*;
import pwc.taxtech.atms.vat.dao.PeriodTemplateMapper;
import pwc.taxtech.atms.vat.dao.ReportMapper;
import pwc.taxtech.atms.vat.entity.CellData;
import pwc.taxtech.atms.vat.entity.PeriodCellTemplate;
import pwc.taxtech.atms.vat.entity.PeriodCellTemplateConfig;
import pwc.taxtech.atms.vat.entity.PeriodCellTemplateConfigExample;
import pwc.taxtech.atms.vat.entity.PeriodCellTemplateExample;
import pwc.taxtech.atms.vat.entity.PeriodTemplate;
import pwc.taxtech.atms.vat.entity.PeriodTemplateExample;
import pwc.taxtech.atms.vat.entity.Report;
import pwc.taxtech.atms.vat.service.ReportGenerator; import pwc.taxtech.atms.vat.service.ReportGenerator;
import pwc.taxtech.atms.vat.service.impl.report.functions.FSJZ; import pwc.taxtech.atms.vat.service.impl.report.functions.FSJZ;
import pwc.taxtech.atms.vat.service.impl.report.functions.FormulaContext; import pwc.taxtech.atms.vat.service.impl.report.functions.FormulaContext;
...@@ -41,37 +26,20 @@ import pwc.taxtech.atms.vat.service.impl.report.functions.SGSR; ...@@ -41,37 +26,20 @@ import pwc.taxtech.atms.vat.service.impl.report.functions.SGSR;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.util.Date; import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static pwc.taxtech.atms.constant.Constant.EMPTY; import static pwc.taxtech.atms.constant.Constant.EMPTY;
@Service @Service
public class ReportGeneratorImpl implements ReportGenerator { public class ReportGeneratorImpl extends VatAbstractService implements ReportGenerator {
@Autowired
PeriodTemplateMapper periodTemplateMapper;
@Autowired
PeriodCellTemplateMapper periodCellTemplateMapper;
@Autowired
PeriodCellTemplateConfigMapper periodCellTemplateConfigMapper;
@Autowired
DistributedIDService distributedIDService;
@Autowired
ReportMapper reportMapper;
@Autowired
CellDataMapper cellDataMapper;
@Autowired
FormulaAgent formulaAgent;
private static final Logger logger = LoggerFactory.getLogger(ReportGeneratorImpl.class); private static final Logger logger = LoggerFactory.getLogger(ReportGeneratorImpl.class);
@Override @Override
public String generateData(String projectId, List<Long> templateIds, Boolean ifDeleteManualDataSource, List<String> exceptCellTemplates, Integer periodParam, String generator) { public String generateData(String projectId, List<Long> templateIds
, Boolean ifDeleteManualDataSource, List<String> exceptCellTemplates
, Integer periodParam, String generator) {
Date createTime = new Date(); Date createTime = new Date();
int period = periodParam != null ? periodParam : 0; int period = periodParam != null ? periodParam : 0;
...@@ -269,4 +237,56 @@ public class ReportGeneratorImpl implements ReportGenerator { ...@@ -269,4 +237,56 @@ public class ReportGeneratorImpl implements ReportGenerator {
UDFFinder udfToolpack = new AggregatingUDFFinder(udfs); UDFFinder udfToolpack = new AggregatingUDFFinder(udfs);
workbook.addToolPack(udfToolpack); workbook.addToolPack(udfToolpack);
} }
public List<CellCalcInfoDto> getCellCalcInfo(List<Long> templateIDList, Integer periodParam) {
//already finished by 20180711
int period = 0;
if (periodParam != null) {
period = periodParam;
}
List<PeriodCellTemplateConfigExtendDto> periodCellTemplateConfigExtendDtos =
periodCellTemplateConfigMapper.getPeriodCellTemplateConfigExtendDtos(templateIDList, period);
List<CellCalcInfoDto> cellCalcInfoDtos = new ArrayList<>();
periodCellTemplateConfigExtendDtos.stream().collect(Collectors.groupingBy(a ->
new CellTemplateConfigGroupDto(a.getColumnIndex(), a.getRowIndex()
, a.getColumnName(), a.getRowName(), a.getDataType(), a.getIsReadOnly()
, a.getId(), a.getReportTemplateID(), a.getComment()))).forEach((x, y) -> {
CellCalcInfoDto cellCalcInfoDto = new CellCalcInfoDto();
cellCalcInfoDto.setColumnIndex(x.getColumnIndex());
cellCalcInfoDto.setColumnName(x.getColumnName());
cellCalcInfoDto.setRowIndex(x.getRowIndex());
cellCalcInfoDto.setRowName(x.getRowName());
cellCalcInfoDto.setFormula(convertListToString(y.stream()
.map(PeriodCellTemplateConfig::getFormula).collect(Collectors.toList())));
cellCalcInfoDto.setParsedFormula(convertListToString(y.stream()
.map(PeriodCellTemplateConfig::getParsedFormula).collect(Collectors.toList())));
//todo: add validation at here later
cellCalcInfoDto.setCellTemplateID(x.getTemplateID());
cellCalcInfoDto.setReportTemplateID(x.getReportTemplateID());
cellCalcInfoDto.setDataType(x.getDataType());
cellCalcInfoDto.setIsReadOnly(x.getIsReadOnly());
cellCalcInfoDto.setComment(x.getComment());
cellCalcInfoDto.setConfigList(y.stream()
.map(PeriodCellTemplateConfigExtendDto::getPeriodCellTemplateConfig)
.collect(Collectors.toList()));
cellCalcInfoDtos.add(cellCalcInfoDto);
});
return cellCalcInfoDtos;
}
private String convertListToString(List<String> list) {
StringBuilder stringBuilder = new StringBuilder();
list.forEach(s -> {
if (StringUtils.isNotBlank(s)) {
stringBuilder.append(s);
stringBuilder.append("+");
}
});
if (stringBuilder.length() > 0) {
stringBuilder.deleteCharAt(stringBuilder.length() - 1);
}
return stringBuilder.toString();
}
} }
...@@ -5,23 +5,14 @@ import org.springframework.stereotype.Service; ...@@ -5,23 +5,14 @@ import org.springframework.stereotype.Service;
import pwc.taxtech.atms.common.datasource.ShardingContextHolder; import pwc.taxtech.atms.common.datasource.ShardingContextHolder;
import pwc.taxtech.atms.constant.enums.EnumServiceType; import pwc.taxtech.atms.constant.enums.EnumServiceType;
import pwc.taxtech.atms.dto.OperationResultDto; import pwc.taxtech.atms.dto.OperationResultDto;
import pwc.taxtech.atms.dto.vatdto.CellTemplateReferenceDto; import pwc.taxtech.atms.dto.vatdto.*;
import pwc.taxtech.atms.dto.vatdto.ReportDataDto;
import pwc.taxtech.atms.dto.vatdto.ReportDto;
import pwc.taxtech.atms.entitiy.*; import pwc.taxtech.atms.entitiy.*;
import pwc.taxtech.atms.exception.NotSupportedException; import pwc.taxtech.atms.exception.NotSupportedException;
import pwc.taxtech.atms.vat.entity.PeriodCellTemplate; import pwc.taxtech.atms.service.impl.CellConfigTranslater;
import pwc.taxtech.atms.vat.entity.PeriodCellTemplateConfig; import pwc.taxtech.atms.vat.entity.*;
import pwc.taxtech.atms.vat.entity.PeriodTemplate;
import pwc.taxtech.atms.vat.entity.PeriodTemplateExample;
import pwc.taxtech.atms.vat.service.ReportService; import pwc.taxtech.atms.vat.service.ReportService;
import java.util.ArrayList; import java.util.*;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Service @Service
...@@ -66,10 +57,9 @@ public class ReportServiceImpl extends VatAbstractService implements ReportServi ...@@ -66,10 +57,9 @@ public class ReportServiceImpl extends VatAbstractService implements ReportServi
ProjectServiceTypeExample projectServiceTypeExample = new ProjectServiceTypeExample(); ProjectServiceTypeExample projectServiceTypeExample = new ProjectServiceTypeExample();
projectServiceTypeExample.createCriteria().andServiceTypeIDEqualTo(serviceTypeStr).andProjectIDEqualTo(projectID); projectServiceTypeExample.createCriteria().andServiceTypeIDEqualTo(serviceTypeStr).andProjectIDEqualTo(projectID);
Optional<Long> tempVlaue = projectServiceTypeMapper.selectByExample(projectServiceTypeExample).stream().map(ProjectServiceType::getTemplateGroupID).findFirst(); Optional<Long> tempVlaue = projectServiceTypeMapper.selectByExample(projectServiceTypeExample).stream().map(ProjectServiceType::getTemplateGroupID).findFirst();
if(tempVlaue.isPresent()){ if (tempVlaue.isPresent()) {
templateGroupID = tempVlaue.get(); templateGroupID = tempVlaue.get();
} } else {
else{
templateGroupID = 0L; templateGroupID = 0L;
} }
} }
...@@ -300,14 +290,142 @@ public class ReportServiceImpl extends VatAbstractService implements ReportServi ...@@ -300,14 +290,142 @@ public class ReportServiceImpl extends VatAbstractService implements ReportServi
OperationResultDto resultDto = new OperationResultDto(); OperationResultDto resultDto = new OperationResultDto();
ReportDataDto dataDto = new ReportDataDto(); ReportDataDto dataDto = new ReportDataDto();
Report report = reportMapper.selectByPrimaryKey(reportId);
if (report == null) {
resultDto.setResult(false);
resultDto.setResultMsg("NoReport");
return resultDto;
}
PeriodTemplateExample example = new PeriodTemplateExample();
example.createCriteria().andTemplateIdEqualTo(report.getTemplateId()).andPeriodEqualTo(report.getPeriod());
Optional<PeriodTemplate> reportTemplate = periodTemplateMapper.selectByExample(example).stream().findFirst();
if (!reportTemplate.isPresent()) {
resultDto.setResult(false);
resultDto.setResultMsg("NoReportTemplate");
return resultDto;
}
Project project = projectMapper.selectByPrimaryKey(report.getProjectId());
if (project == null) {
resultDto.setResult(false);
resultDto.setResultMsg("NoProject");
return resultDto;
}
PeriodTemplateExample periodTemplateExample = new PeriodTemplateExample();
periodTemplateExample.createCriteria()
.andTemplateGroupIdEqualTo(reportTemplate.get().getTemplateGroupId())
.andPeriodEqualTo(report.getPeriod())
.andIsActiveAssociationEqualTo(true);
return null; List<PeriodTemplate> reportTemplates = periodTemplateMapper.selectByExample(example);
List<Long> templateIDs = new ArrayList<>();
templateIDs.add(report.getTemplateId());
List<CellCalcInfoDto> cellCfgList = reportGenerator.getCellCalcInfo(templateIDs, report.getPeriod());
CellDataExample cellDataExample = new CellDataExample();
cellDataExample.createCriteria().andReportIdEqualTo(reportId);
List<CellData> currentCellDataList = cellDataMapper.selectByExample(cellDataExample);
PeriodFormulaBlockExample periodFormulaBlockExample = new PeriodFormulaBlockExample();
periodFormulaBlockExample.createCriteria().andPeriodEqualTo(report.getPeriod());
List<PeriodFormulaBlock> formulaBlocks = periodFormulaBlockMapper.selectByExample(periodFormulaBlockExample);
dataDto.setFormulaBlocks(formulaBlocks);
//todo: 关键字数据源稍后再加
// 获取通过KeyValueDataID关联的数据源,即公式数据源
//var formulaDataSourceList = (from ds in _dbprojectContext.Set<DataSource>()
//join cd in _dbprojectContext.Set<CellData>()
//on ds.KeyValueDataID equals cd.ID
//where cd.ReportID == reportID && ds.Type == (int)CellDataSourceType.Formula
//select new
//{
// DataSource = ds,
// CellTemplateID = cd.CellTemplateID,
// CellDataID = cd.ID
//}).AsNoTracking().ToList();
//todo: 模型数据源稍后再加
// 获取通过ModelBackFillAmount关联的数据源,即模型数据源
// TODO: Check模型回填数据源是否会有多对多的情况出现,如有需distinct
//var modelDataSourceList = (from ds in _dbprojectContext.Set<DataSource>()
//join fa in _dbprojectContext.Set<ModelBackFillAmount>()
//on ds.ID equals fa.DataSourceID
//join cd in _dbprojectContext.Set<CellData>()
//on fa.CellDataID equals cd.ID
//where cd.ReportID == reportID && ds.Type == (int)FormulaDataSourceType.ModelDatasource
//select new
//{
// DataSource = ds,
// OperationType = (int)DataSourceOperationType.Plus,
// CellTemplateID = cd.CellTemplateID,
// CellDataID = cd.ID
//}).AsNoTracking().ToList();
//公式计算数据源 20180711 完成
List<DataSourceExtendDto> manualDataSourceList = dataSourceMapper.getFormulaDataSource(reportId);
Map<Long, DataSourceDto> datasource = new IdentityHashMap<>();
manualDataSourceList.forEach(a -> {
DataSourceDto dataSourceDto = new DataSourceDto();
dataSourceDto.setId(a.getId());
dataSourceDto.setAmount(a.getAmount());
dataSourceDto.setName(a.getName());
dataSourceDto.setOperationType(a.getOperationType());
dataSourceDto.setDataSourceType(a.getType());
dataSourceDto.setDescription(a.getDescription());
dataSourceDto.setCreateTime(a.getCreateTime());
datasource.put(a.getCellTemplateID(), dataSourceDto);
});
dataDto.setManualDataSources(datasource);
List<CellDataDto> cellDataDtoList = new ArrayList<>();
cellCfgList.forEach(a -> {
CellDataDto cellDataDto = new CellDataDto();
cellDataDto.setColumnIndex(a.getColumnIndex());
cellDataDto.setColumnName(a.getColumnName());
cellDataDto.setRowIndex(a.getRowIndex());
cellDataDto.setRowName(a.getRowName());
cellDataDto.setCellTemplateID(a.getCellTemplateID());
cellDataDto.setReportTemplateID(a.getReportTemplateID());
cellDataDto.setDataType(a.getDataType());
cellDataDto.setReportID(reportId);
cellDataDto.setIsReadOnly(a.getIsReadOnly());
Optional<CellData> celldata = currentCellDataList.stream()
.filter(x -> x.getCellTemplateId().equals(a.getCellTemplateID())).findFirst();
celldata.ifPresent(cellData -> cellDataDto.setCellID(cellData.getId()));
cellDataDto.setFormula(a.getFormula());
celldata.ifPresent(cellData -> cellDataDto.setCellValue(cellData.getData()));
celldata.ifPresent(cellData -> cellDataDto.setFormulaExp(cellData.getFormulaExp()));
cellDataDto.setCellTemplateConfig(CellConfigTranslater.getConfigDto(a));
List<Map.Entry<Long, DataSourceDto>> entryList = datasource.entrySet().stream()
.filter(y -> y.getKey().equals(a.getCellTemplateID())).collect(Collectors.toList());
List<DataSourceDto> dataSourceDtoList = new ArrayList<>();
entryList.forEach(z -> dataSourceDtoList.add(z.getValue()));
cellDataDto.setDataSourceList(dataSourceDtoList);
cellDataDtoList.add(cellDataDto);
});
ModifiedReportCellExample modifiedReportCellExample = new ModifiedReportCellExample();
modifiedReportCellExample.createCriteria().andReportIdEqualTo(reportId);
List<ModifiedReportCell> modifiedReportCellList = modifiedReportCellMapper.selectByExample(modifiedReportCellExample);
modifiedReportCellList.forEach(mrc -> {
Optional<CellDataDto> cdd = cellDataDtoList.stream()
.filter(cellDataDto -> cellDataDto.getReportID().equals(mrc.getReportId())
&& cellDataDto.getRowIndex() == mrc.getRow()
&& cellDataDto.getColumnIndex() == mrc.getCol()).findFirst();
if (cdd.isPresent()) {
if (!mrc.getOriginalValue().equals(mrc.getValue())) {
cdd.get().setModifiedReportCell(mrc);
cdd.get().setCellValue(mrc.getValue());
cdd.get().setIsModified(true);
}
}
});
dataDto.setCellData(cellDataDtoList);
resultDto.setData(dataDto);
resultDto.setResult(true);
return resultDto;
} }
} }
...@@ -70,5 +70,13 @@ public class VatAbstractService { ...@@ -70,5 +70,13 @@ public class VatAbstractService {
public ProjectDao projectDao; public ProjectDao projectDao;
@Autowired @Autowired
public PeriodFormulaBlockMapper periodFormulaBlockMapper; public PeriodFormulaBlockMapper periodFormulaBlockMapper;
@Autowired
public ReportMapper reportMapper;
@Autowired
public CellDataMapper cellDataMapper;
@Autowired
public ModifiedReportCellMapper modifiedReportCellMapper;
@Autowired
public FormulaAgent formulaAgent;
} }
package pwc.taxtech.atms.vat.service.impl.report.functions;
import pwc.taxtech.atms.dto.CellTemplateConfigDto;
import pwc.taxtech.atms.vat.entity.PeriodCellTemplateConfig;
import java.util.List;
public final class CellConfigTranslater {
public static CellTemplateConfigDto GetPeriodConfigDto(String configID, String templateID, int rowIndex, String rowName, int columnIndex, String columnName, Integer dataType, Integer isReadOnly, String description, List<PeriodCellTemplateConfig> configList) {
return null;
}
}
...@@ -484,6 +484,41 @@ ...@@ -484,6 +484,41 @@
WHERE report_id not in (${exceptReportTemplateIDs}); WHERE report_id not in (${exceptReportTemplateIDs});
</if> </if>
</delete> </delete>
<resultMap id="DataSourceExtendDtoMap" type="pwc.taxtech.atms.dto.vatdto.DataSourceExtendDto">
<id column="id" jdbcType="BIGINT" property="id" />
<result column="type" jdbcType="INTEGER" property="type" />
<result column="name" jdbcType="VARCHAR" property="name" />
<result column="amount" jdbcType="DECIMAL" property="amount" />
<result column="description" jdbcType="VARCHAR" property="description" />
<result column="key_value_data_id" jdbcType="VARCHAR" property="keyValueDataId" />
<result column="create_by" jdbcType="VARCHAR" property="createBy" />
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
<result column="update_by" jdbcType="VARCHAR" property="updateBy" />
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
<result column="row_name" jdbcType="VARCHAR" property="rowName" />
<result column="column_name" jdbcType="VARCHAR" property="columnName" />
<result column="row_index" jdbcType="INTEGER" property="rowIndex" />
<result column="remap_batch_id" jdbcType="VARCHAR" property="remapBatchId" />
<result column="column_index" jdbcType="INTEGER" property="columnIndex" />
<result column="operation_type" jdbcType="INTEGER" property="operationType" />
<result column="cell_template_id" jdbcType="BIGINT" property="cellTemplateID" />
<result column="cell_data_id" jdbcType="BIGINT" property="cellDataID" />
</resultMap>
<select id="getFormulaDataSource" parameterType="java.lang.Long" resultMap="DataSourceExtendDtoMap">
SELECT
ds.*,
cds.operation_type AS operation_type,
cd.cell_template_id AS cell_template_id,
cd.id AS cell_data_id
FROM data_source ds
JOIN cell_data_source cds
ON ds.id = cds.data_source_id
JOIN cell_data cd
ON cds.cell_data_id = cd.id
WHERE cd.report_id = #{reportID,jdbcType=BIGINT}
AND <![CDATA[ ds.type <> 1 ]]>
</select>
<!--DELETE FROM period_tax_rule_setting WHERE period=#{period,jdbcType=INTEGER};--> <!--DELETE FROM period_tax_rule_setting WHERE period=#{period,jdbcType=INTEGER};-->
<!--DELETE FROM period_cell_template WHERE period=#{period,jdbcType=INTEGER} and report_template_id not in (${exceptReportTemplateIDs});--> <!--DELETE FROM period_cell_template WHERE period=#{period,jdbcType=INTEGER} and report_template_id not in (${exceptReportTemplateIDs});-->
<!--DELETE FROM period_cell_template_config WHERE period=#{period,jdbcType=INTEGER} and report_template_id not in (${exceptReportTemplateIDs});--> <!--DELETE FROM period_cell_template_config WHERE period=#{period,jdbcType=INTEGER} and report_template_id not in (${exceptReportTemplateIDs});-->
......
This diff is collapsed.
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