Commit 3d324f46 authored by neo.wang's avatar neo.wang

Merge branch 'dev_neo' into 'dev'

Dev neo

See merge request root/atms!49
parents 54239090 729b3949
package pwc.taxtech.atms.common.util;
import pwc.taxtech.atms.exception.FormulaException;
public class MyAsserts {
public static void assertNotNull(Object obj, FormulaException exception) {
if (obj == null) throw exception;
}
}
......@@ -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);
}
......@@ -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.exception;
public class Exceptions {
public static final FormulaException BB_CELL_TEMP_NULL = new FormulaException("cell template data is null");
public static final FormulaException BB_REPORT_NULL = new FormulaException("cell report is null");
public static final FormulaException BB_CELL_DATA_NULL = new FormulaException("cell data is null");
}
package pwc.taxtech.atms.exception;
/**
* 仅用于公式计算过程中抛出的异常
*/
public class FormulaException extends RuntimeException {
private static final long serialVersionUID = 1L;
public FormulaException() {
super();
}
public FormulaException(String message) {
super(message);
}
public FormulaException(String message, Throwable cause) {
super(message, cause);
}
public FormulaException(Throwable cause) {
super(cause);
}
}
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.OperandResolver;
import org.apache.poi.ss.formula.eval.NumberEval;
import org.apache.poi.ss.formula.eval.StringEval;
import org.apache.poi.ss.formula.eval.StringValueEval;
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.constant.enums.EnumServiceType;
import pwc.taxtech.atms.dto.GroupId;
import pwc.taxtech.atms.common.datasource.ShardingContextHolder;
import pwc.taxtech.atms.common.util.MyAsserts;
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.ReportCellDataSourceDto;
import pwc.taxtech.atms.entitiy.ProjectServiceType;
import pwc.taxtech.atms.entitiy.ProjectServiceTypeExample;
import pwc.taxtech.atms.exception.Exceptions;
import pwc.taxtech.atms.vat.entity.CellData;
import pwc.taxtech.atms.vat.entity.Report;
import pwc.taxtech.atms.vat.service.impl.report.functions.FormulaAgent;
import pwc.taxtech.atms.vat.service.impl.report.functions.FormulaContext;
import java.util.List;
import java.math.BigDecimal;
public class ReportFormulaFactory {
static final Logger LOGGER = LoggerFactory.getLogger(ReportFormulaFactory.class);
......@@ -46,6 +46,19 @@ public class ReportFormulaFactory {
}
}
@Override
public ValueEval evaluate(ValueEval[] args, OperationEvaluationContext ec) {
try {
return wrapExceptionEval(args, ec);
} catch (Exception e) {
LOGGER.warn("un expect exception", e);
e.printStackTrace();
return defaultEval;
}
}
public abstract ValueEval wrapExceptionEval(ValueEval[] args, OperationEvaluationContext ec) throws Exception;
}
public static class BB extends ReportBaseFormula {
......@@ -54,7 +67,7 @@ public class ReportFormulaFactory {
}
@Override
public ValueEval evaluate(ValueEval[] args, OperationEvaluationContext ec) {
public ValueEval wrapExceptionEval(ValueEval[] args, OperationEvaluationContext ec) throws Exception {
try (CloseableFormulaDataSource closeDataSource = new CloseableFormulaDataSource(context.getFormulaAgent())) {
BBParasBo bo = new BBParasBo(args, ec);
CurrentPeriodBo curPeriod = CurrentPeriodBo.getPeriod(bo.getPeriod().intValue(), context.getPeriod());
......@@ -63,42 +76,24 @@ public class ReportFormulaFactory {
ReportCellDataSourceDto nullCellDto = ReportCellDataSourceDto.nullDataSource(bo, curPeriod);
closeDataSource.addDS(nullCellDto);
ProjectServiceTypeExample pst = new ProjectServiceTypeExample();
pst.createCriteria().andTemplateGroupIDEqualTo(Long.valueOf(context.getReportTemplateGroupID()))
.andServiceTypeIDEqualTo(EnumServiceType.VAT.getCode() + "");
List<ProjectServiceType> pstReult = agent.projectServiceTypeMapper.selectByExample(pst);
CellTemplatePerGroupDto cellTemplateData = agent.getCellTemplateGroupDto(context.getReportTemplateGroupID(),
context.getProjectID()).stream().filter(dto -> dto.getRowIndex() == bo.getColumnIndex() - 1
&& dto.getColumnIndex() == bo.getColumnIndex() - 1).findFirst().get();
List<CellTemplatePerGroupDto> cellTemplates = agent.adminMp.getCellTemplatePerGroupDto(context.getReportTemplateGroupID());
if (pstReult == null || pstReult.isEmpty()) {
List<GroupId> groupIds = agent.adminMp.getTemplateGroupId(context.getProjectID());
GroupId groupId;
if (groupIds.size() > 0) {
groupId = groupIds.stream().filter(m -> m.isDefault != 1).findFirst().get();
if (groupId == null) groupId = groupIds.get(0);
cellTemplates.addAll(agent.adminMp.getCellTemplatePerGroupDto(groupId.groupId));
}
}
CellTemplatePerGroupDto cellTemplateData = cellTemplates.stream().filter(dto ->
dto.getRowIndex() == bo.getColumnIndex() - 1 &&dto.getColumnIndex()==bo.getColumnIndex()-1)
.findFirst().get();
if (cellTemplateData == null) {
LOGGER.warn("tcell template data is empty");
return defaultEval;
}
MyAsserts.assertNotNull(cellTemplateData, Exceptions.BB_CELL_TEMP_NULL);
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,20 +101,38 @@ public class ReportFormulaFactory {
}
bo.disCount();
String dbName = agent.adminMp.getPastProjectDbName(curPeriod.getCurYear(), context.getOrganizationID());
String currentProjectDb = ShardingContextHolder.getDataSourceKey();
ShardingContextHolder.setDataSourceKey(dbName);
try {
Report report = agent.getReportByTemplate(cellTemplateData.getCellTemplateID(), curPeriod.getCurPeriod());
MyAsserts.assertNotNull(report, Exceptions.BB_REPORT_NULL);
CellData cellData = agent.getCellDataListByTemplate(cellTemplateData.getCellTemplateID(), report.getId());
MyAsserts.assertNotNull(cellData, Exceptions.BB_CELL_DATA_NULL);
} catch (EvaluationException e) {
LOGGER.warn("resole args some exception", e);
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
nullCellDto = ReportCellDataSourceDto.extractFromGroup(bo, curPeriod, cellData, cellTemplateData);
// todo: fix datasource name by templateList(neo)
if (!StringUtil.isEmpty(cellData.getData())) {
return null;
}
// cellValue= RoundValue(cellValue, cellDataType)TODO:maybe fixd round by cellDataTyep(KV neo)
BigDecimal cellValue = new BigDecimal(cellData.getData()).setScale(4,
BigDecimal.ROUND_HALF_DOWN);
nullCellDto.setAmount(cellValue);
LOGGER.debug("cell static value ");
ShardingContextHolder.setDataSourceKey(currentProjectDb);
return new NumberEval(cellValue.doubleValue());
}
} catch (Exception e) {
LOGGER.warn("un support exception", e);
ShardingContextHolder.setDataSourceKey(currentProjectDb);
throw e;
}
}
return defaultEval;
}
}
}
......@@ -2,14 +2,75 @@ 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.constant.enums.EnumServiceType;
import pwc.taxtech.atms.dao.FormulaAdminMapper;
import pwc.taxtech.atms.dto.GroupId;
import pwc.taxtech.atms.dto.vatdto.CellTemplatePerGroupDto;
import pwc.taxtech.atms.entitiy.ProjectServiceType;
import pwc.taxtech.atms.entitiy.ProjectServiceTypeExample;
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.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.VatAbstractService;
import java.util.List;
import static pwc.taxtech.atms.constant.Constant.FIRST_OR_DEFAULT;
@Service
public class FormulaAgent extends VatAbstractService {
@Autowired
public FormulaAdminMapper adminMp;
@Autowired
public FormulaProjectMapper projectMp;
@Autowired
public ReportMapper reportMapper;
@Autowired
public CellDataMapper cellDataMapper;
public List<CellTemplatePerGroupDto> getCellTemplateGroupDto(Long templateGroupId, String projectId) {
ProjectServiceTypeExample pst = new ProjectServiceTypeExample();
pst.createCriteria().andTemplateGroupIDEqualTo(Long.valueOf(templateGroupId))
.andServiceTypeIDEqualTo(EnumServiceType.VAT.getCode() + "");
List<ProjectServiceType> pstReult = projectServiceTypeMapper.selectByExample(pst);
List<CellTemplatePerGroupDto> cellTemplates = adminMp.getCellTemplatePerGroupDto(templateGroupId);
if (pstReult == null || pstReult.isEmpty()) {
List<GroupId> groupIds = adminMp.getTemplateGroupId(projectId);
GroupId groupId;
if (groupIds.size() > 0) {
groupId = groupIds.stream().filter(m -> m.isDefault != 1).findFirst().get();
if (groupId == null) groupId = groupIds.get(0);
cellTemplates.addAll(adminMp.getCellTemplatePerGroupDto(groupId.groupId));
}
}
return cellTemplates;
}
public Report getReportByTemplate(String templateId, Integer periodId) {
ReportExample example = new ReportExample();
example.createCriteria().andTemplateIdEqualTo(Long.valueOf(templateId))
.andPeriodEqualTo(periodId);
List<Report> reports = reportMapper.selectByExample(example);
if (reports != null || !reports.isEmpty()) return reports.get(FIRST_OR_DEFAULT);
return null;
}
public CellData getCellDataListByTemplate(String templateId, Long reportId) {
CellDataExample dataExample = new CellDataExample();
dataExample.createCriteria().andCellTemplateIdEqualTo(Long.valueOf(templateId));
List<CellData> cellDataList = cellDataMapper.selectByExample(dataExample);
if (cellDataList != null || !cellDataList.isEmpty()) return cellDataList.get(FIRST_OR_DEFAULT);
return null;
}
}
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