Commit b22c475a authored by neo's avatar neo

[DEV] bb formula impl

parent 8d258f2d
package pwc.taxtech.atms.constant.enums;
public enum EnumOperationType {
Single(0),
Add(1),
Sub(2),
Mul(3),
Div(4);
private int code;
EnumOperationType(int code) {
this.code = code;
}
public int getCode() {
return code;
}
}
......@@ -46,4 +46,18 @@ public interface FormulaAdminMapper extends MyMapper {
" AND p.ID = #{projectId}")
List<GroupId> getTemplateGroupId(@Param("projectId") String projectId);
@Select("SELECT " +
" p.DbName " +
"FROM " +
" Project p " +
" JOIN " +
" ProjectServiceType ps ON p.id = ps.ProjectID " +
"WHERE " +
" ps.ServiceTypeID IN ('2' , '3') " +
" AND p.Year = #{year} " +
" AND p.OrganizationID = #{orgId} " +
" AND p.IsActive = 1 " +
"ORDER BY ps.ServiceTypeID " +
"LIMIT 0 , 1")
String getPastProjectDbName(@Param("year") int year, @Param("orgId") String organizationID);
}
package pwc.taxtech.atms.dto.vatdto;
import java.math.BigDecimal;
public class DataSourceAmount {
public BigDecimal amount;
public Integer operationType;
}
......@@ -3,6 +3,8 @@ package pwc.taxtech.atms.dto.vatdto;
import pwc.taxtech.atms.constant.Constant;
import pwc.taxtech.atms.constant.DataSourceName;
import pwc.taxtech.atms.constant.enums.FormulaDataSourceType;
import pwc.taxtech.atms.dto.CellTemplateDto;
import pwc.taxtech.atms.vat.entity.CellData;
public class ReportCellDataSourceDto extends FormulaDataSourceDto {
Integer year;
......@@ -22,7 +24,7 @@ public class ReportCellDataSourceDto extends FormulaDataSourceDto {
this.type = FormulaDataSourceType.Report.getCode();
}
public static ReportCellDataSourceDto nullDataSource(BBParasBo bbParasBo,CurrentPeriodBo currentPeriodBo) {
public static ReportCellDataSourceDto nullDataSource(BBParasBo bbParasBo, CurrentPeriodBo currentPeriodBo) {
ReportCellDataSourceDto nulDataSource = new ReportCellDataSourceDto();
nulDataSource.name = DataSourceName.ReportDataSource;
nulDataSource.reportTemplateID = bbParasBo.getReportCode();
......@@ -34,7 +36,24 @@ public class ReportCellDataSourceDto extends FormulaDataSourceDto {
return nulDataSource;
}
public void fixedWithGroup(CellTemplatePerGroupDto dto){
public static ReportCellDataSourceDto extractFromGroup(BBParasBo bbParasBo, CurrentPeriodBo currentPeriodBo,
CellData cellData, CellTemplatePerGroupDto cellTemplateData) {
ReportCellDataSourceDto dataSource = new ReportCellDataSourceDto();
dataSource.year = currentPeriodBo.curYear;
dataSource.period = currentPeriodBo.curPeriod;
dataSource.columnIndex = bbParasBo.getColumnIndex();
dataSource.columnName = cellTemplateData.getColumnName();
dataSource.rowIndex = bbParasBo.getRowIndex();
dataSource.rowName = cellTemplateData.getRowName();
dataSource.reportTemplateID = cellTemplateData.getReportTemplateID();
dataSource.cellDataID = cellData.getId() + "";
dataSource.cellTemplateID = cellData.getCellTemplateId() + "";
dataSource.resultType = cellTemplateData.getResultType();
dataSource.isOnlyManualInput = false;
return dataSource;
}
public void fixedWithGroup(CellTemplatePerGroupDto dto) {
cellTemplateID = dto.getCellTemplateID();
rowName = dto.getRowName();
columnName = dto.getColumnName();
......
package pwc.taxtech.atms.vat.dao;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import pwc.taxtech.atms.MyVatMapper;
import pwc.taxtech.atms.dto.vatdto.DataSourceAmount;
import java.util.List;
@Mapper
public interface FormulaProjectMapper extends MyVatMapper {
@Select("SELECT " +
" ds.amount, cds.operation_type AS operationType " +
"FROM " +
" data_source ds " +
" JOIN " +
" cell_data_source cds ON ds.id = cds.data_source_id " +
"WHERE " +
" cds.cell_data_id = #{cellId} " +
" AND ds.type != #{code} " +
" AND ds.amount IS NOT NULL ")
List<DataSourceAmount> queryDsAmount(@Param("cellId") Long dataId, @Param("code") Integer code);
}
package pwc.taxtech.atms.vat.service.impl;
import com.github.pagehelper.util.StringUtil;
import org.apache.poi.ss.formula.OperationEvaluationContext;
import org.apache.poi.ss.formula.eval.EvaluationException;
import org.apache.poi.ss.formula.eval.NumberEval;
import org.apache.poi.ss.formula.eval.OperandResolver;
import org.apache.poi.ss.formula.eval.StringEval;
import org.apache.poi.ss.formula.eval.StringValueEval;
......@@ -9,20 +11,33 @@ import org.apache.poi.ss.formula.eval.ValueEval;
import org.apache.poi.ss.formula.functions.FreeRefFunction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pwc.taxtech.atms.common.datasource.ShardingContextHolder;
import pwc.taxtech.atms.constant.Constant;
import pwc.taxtech.atms.constant.enums.CellDataSourceType;
import pwc.taxtech.atms.constant.enums.EnumOperationType;
import pwc.taxtech.atms.constant.enums.EnumServiceType;
import pwc.taxtech.atms.dto.GroupId;
import pwc.taxtech.atms.dto.vatdto.BBParasBo;
import pwc.taxtech.atms.dto.vatdto.CellTemplatePerGroupDto;
import pwc.taxtech.atms.dto.vatdto.CloseableFormulaDataSource;
import pwc.taxtech.atms.dto.vatdto.CurrentPeriodBo;
import pwc.taxtech.atms.dto.vatdto.DataSourceAmount;
import pwc.taxtech.atms.dto.vatdto.ReportCellDataSourceDto;
import pwc.taxtech.atms.entitiy.ProjectExample;
import pwc.taxtech.atms.entitiy.ProjectServiceType;
import pwc.taxtech.atms.entitiy.ProjectServiceTypeExample;
import pwc.taxtech.atms.vat.entity.CellData;
import pwc.taxtech.atms.vat.entity.CellDataExample;
import pwc.taxtech.atms.vat.entity.Report;
import pwc.taxtech.atms.vat.entity.ReportExample;
import pwc.taxtech.atms.vat.service.impl.report.functions.FormulaAgent;
import pwc.taxtech.atms.vat.service.impl.report.functions.FormulaContext;
import java.math.BigDecimal;
import java.util.List;
import static pwc.taxtech.atms.constant.Constant.FIRST_OR_DEFAULT;
public class ReportFormulaFactory {
static final Logger LOGGER = LoggerFactory.getLogger(ReportFormulaFactory.class);
final static ValueEval defaultEval = new StringEval("0");
......@@ -81,7 +96,7 @@ public class ReportFormulaFactory {
}
CellTemplatePerGroupDto cellTemplateData = cellTemplates.stream().filter(dto ->
dto.getRowIndex() == bo.getColumnIndex() - 1 &&dto.getColumnIndex()==bo.getColumnIndex()-1)
dto.getRowIndex() == bo.getColumnIndex() - 1 && dto.getColumnIndex() == bo.getColumnIndex() - 1)
.findFirst().get();
if (cellTemplateData == null) {
......@@ -90,15 +105,15 @@ public class ReportFormulaFactory {
}
nullCellDto.fixedWithGroup(cellTemplateData);
// todo: fix datasource name by templateList(neo)
if(curPeriod.getCurPeriod()==-99){
// todo: fix datasource name by templateList(neo)
if (curPeriod.getCurPeriod() == -99) {
closeDataSource.clean();
ValueEval returnEval=null;
if(context.getPeriod()<=1){
return defaultEval;
ValueEval returnEval = null;
if (context.getPeriod() <= 1) {
return defaultEval;
}
for(int p =1;p< context.getPeriod();p++){
for (int p = 1; p < context.getPeriod(); p++) {
// returnEval=And(returnEval,BB)//TODO: to impl add vormular
}
......@@ -106,8 +121,56 @@ public class ReportFormulaFactory {
}
bo.disCount();
String dbName = agent.adminMp.getPastProjectDbName(curPeriod.getCurYear(), context.getOrganizationID());
String currentProjectDb = ShardingContextHolder.getDataSourceKey();
ShardingContextHolder.setDataSourceKey(dbName);
ReportExample example = new ReportExample();
example.createCriteria().andTemplateIdEqualTo(Long.valueOf(cellTemplateData.getCellTemplateID()))
.andPeriodEqualTo(curPeriod.getCurPeriod());
List<Report> reports = agent.reportMapper.selectByExample(example);
if (reports == null || reports.isEmpty()) {
LOGGER.warn("report data is empty");
return defaultEval;
}
CellDataExample dataExample = new CellDataExample();
dataExample.createCriteria().andCellTemplateIdEqualTo(Long.valueOf(cellTemplateData.getCellTemplateID()))
.andReportIdEqualTo(reports.get(FIRST_OR_DEFAULT).getId());
List<CellData> cellDatas = agent.cellDataMapper.selectByExample(dataExample);
if (cellDatas == null || cellDatas.isEmpty()) {
LOGGER.warn("cell data is empty");
return defaultEval;
}
CellData cellData = cellDatas.get(FIRST_OR_DEFAULT);
nullCellDto = ReportCellDataSourceDto.extractFromGroup(bo, curPeriod, cellData, cellTemplateData);
// todo: fix datasource name by templateList(neo)
if (!StringUtil.isEmpty(cellData.getData())) {
// cellValue= RoundValue(cellValue, cellDataType)TODO:maybe fixd round by cellDataTyep(KV neo)
BigDecimal decimal = new BigDecimal(cellData.getData());
BigDecimal cellValue = decimal.setScale(4, BigDecimal.ROUND_HALF_DOWN);
nullCellDto.setAmount(cellValue);
LOGGER.debug("cell static value ");
return new NumberEval(cellValue.doubleValue());
}
ShardingContextHolder.setDataSourceKey(currentProjectDb);
// Boolean hasValuedDataSource = false;//TODO: Calculate other referenced formula
// BigDecimal dataSourceAmount = new BigDecimal(0);
// List<DataSourceAmount> amounts = agent.projectMp.queryDsAmount(cellData.getId(),
// CellDataSourceType.Formula.getCode());
// if (amounts != null || !amounts.isEmpty())
// for (DataSourceAmount m : amounts)
// if (m.operationType.intValue() == EnumOperationType.Sub.getCode())
// dataSourceAmount = dataSourceAmount.subtract(m.amount);
// else dataSourceAmount = dataSourceAmount.add(m.amount);
//
// if (!StringUtil.isEmpty(cellTemplateData.getFormula())) {
//
// }
} catch (EvaluationException e) {
LOGGER.warn("resole args some exception", e);
......
......@@ -3,7 +3,9 @@ package pwc.taxtech.atms.vat.service.impl.report.functions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import pwc.taxtech.atms.dao.FormulaAdminMapper;
import pwc.taxtech.atms.vat.dao.CellDataMapper;
import pwc.taxtech.atms.vat.dao.FormulaProjectMapper;
import pwc.taxtech.atms.vat.dao.ReportMapper;
import pwc.taxtech.atms.vat.service.impl.VatAbstractService;
@Service
......@@ -12,4 +14,8 @@ public class FormulaAgent extends VatAbstractService {
public FormulaAdminMapper adminMp;
@Autowired
public FormulaProjectMapper projectMp;
@Autowired
public ReportMapper reportMapper;
@Autowired
public CellDataMapper cellDataMapper;
}
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