Commit 2704734c authored by neo's avatar neo

[DEV] fixed bb when cacls add manual

parent d9177a0e
...@@ -13,11 +13,9 @@ import pwc.taxtech.atms.entity.ProjectServiceTypeExample; ...@@ -13,11 +13,9 @@ import pwc.taxtech.atms.entity.ProjectServiceTypeExample;
import pwc.taxtech.atms.exception.Exceptions; import pwc.taxtech.atms.exception.Exceptions;
import pwc.taxtech.atms.vat.dao.CellDataMapper; import pwc.taxtech.atms.vat.dao.CellDataMapper;
import pwc.taxtech.atms.vat.dao.PeriodCellDataMapper; import pwc.taxtech.atms.vat.dao.PeriodCellDataMapper;
import pwc.taxtech.atms.vat.dao.PeriodDataSourceMapper;
import pwc.taxtech.atms.vat.dao.PeriodReportMapper; import pwc.taxtech.atms.vat.dao.PeriodReportMapper;
import pwc.taxtech.atms.vat.entity.PeriodCellData; import pwc.taxtech.atms.vat.entity.*;
import pwc.taxtech.atms.vat.entity.PeriodCellDataExample;
import pwc.taxtech.atms.vat.entity.PeriodReport;
import pwc.taxtech.atms.vat.entity.PeriodReportExample;
import java.util.List; import java.util.List;
...@@ -35,6 +33,8 @@ public class FormulaAgent { ...@@ -35,6 +33,8 @@ public class FormulaAgent {
private PeriodCellDataMapper periodCellDataMapper; private PeriodCellDataMapper periodCellDataMapper;
@Autowired @Autowired
private ProjectServiceTypeMapper projectServiceTypeMapper; private ProjectServiceTypeMapper projectServiceTypeMapper;
@Autowired
private PeriodDataSourceMapper periodDataSourceMapper;
public List<CellTemplatePerGroupDto> getCellTemplateGroupDto(Long templateGroupId, String projectId) { public List<CellTemplatePerGroupDto> getCellTemplateGroupDto(Long templateGroupId, String projectId) {
ProjectServiceTypeExample pst = new ProjectServiceTypeExample(); ProjectServiceTypeExample pst = new ProjectServiceTypeExample();
...@@ -56,6 +56,14 @@ public class FormulaAgent { ...@@ -56,6 +56,14 @@ public class FormulaAgent {
return cellTemplates; return cellTemplates;
} }
public List<PeriodDataSource> queryManualDataSource(Long templateId, String projectId,Integer period){
PeriodDataSourceExample example = new PeriodDataSourceExample();
example.createCriteria().andProjectIdEqualTo(projectId).andPeriodEqualTo(period)
.andCellTemplateIdEqualTo(templateId).andTypeEqualTo(10);
return periodDataSourceMapper.selectByExample(example);
}
private PeriodReport getReportByTemplate(String templateId, Integer periodId, String projectId) { private PeriodReport getReportByTemplate(String templateId, Integer periodId, String projectId) {
PeriodReportExample example = new PeriodReportExample(); PeriodReportExample example = new PeriodReportExample();
example.createCriteria().andProjectIdEqualTo(projectId).andTemplateIdEqualTo(Long.valueOf(templateId)) example.createCriteria().andProjectIdEqualTo(projectId).andTemplateIdEqualTo(Long.valueOf(templateId))
......
...@@ -15,6 +15,7 @@ import pwc.taxtech.atms.dto.vatdto.ReportCellDataSourceDto; ...@@ -15,6 +15,7 @@ import pwc.taxtech.atms.dto.vatdto.ReportCellDataSourceDto;
import pwc.taxtech.atms.exception.Exceptions; import pwc.taxtech.atms.exception.Exceptions;
import pwc.taxtech.atms.exception.FormulaException; import pwc.taxtech.atms.exception.FormulaException;
import pwc.taxtech.atms.vat.entity.PeriodCellData; import pwc.taxtech.atms.vat.entity.PeriodCellData;
import pwc.taxtech.atms.vat.entity.PeriodDataSource;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.math.BigDecimal; import java.math.BigDecimal;
...@@ -94,24 +95,30 @@ public class BB extends FunctionBase implements FreeRefFunction { ...@@ -94,24 +95,30 @@ public class BB extends FunctionBase implements FreeRefFunction {
WorkbookEvaluator evaluator = (WorkbookEvaluator) evaluatorField.get(ec); WorkbookEvaluator evaluator = (WorkbookEvaluator) evaluatorField.get(ec);
int index = ec.getWorkbook().getSheetIndex(bo.getReportCode()); int index = ec.getWorkbook().getSheetIndex(bo.getReportCode());
if (index < 0) logger.warn("not found sheet code {}", bo.getReportCode()); if (index < 0)
logger.warn("[BB_Exception] not found sheet code {} with {}", bo.getReportCode(), bo.toString());
ValueEval eval = evaluator.evaluate(ec.getWorkbook().getSheet(index) ValueEval eval = evaluator.evaluate(ec.getWorkbook().getSheet(index)
.getCell(bo.getRowIndex() - 1, bo.getColumnIndex() - 1)); .getCell(bo.getRowIndex() - 1, bo.getColumnIndex() - 1));
bo.putPeriodCellTempate(formulaContext.getPeriod(), Long.parseLong(cellTemplateData.getCellTemplateId())); bo.putPeriodCellTempate(formulaContext.getPeriod(), Long.parseLong(cellTemplateData.getCellTemplateId()));
if (eval instanceof ErrorEval) { if (eval instanceof ErrorEval) {
LOGGER.warn("error eval for bb {} and error code {} and error String {}", bo.toString(), LOGGER.warn("[BB_Exception] error eval for bb {} and error code {} and error String {}", bo.toString(),
((ErrorEval) eval).getErrorCode(), ((ErrorEval) eval).getErrorString()); ((ErrorEval) eval).getErrorCode(), ((ErrorEval) eval).getErrorString());
} }
cellValue = new BigDecimal(OperandResolver.coerceValueToDouble(eval)); cellValue = new BigDecimal(OperandResolver.coerceValueToDouble(eval));
nullCellDto.extractFromGroup(bo, formulaContext.getPeriod(), formulaContext.getYear(), cellTemplateData); nullCellDto.extractFromGroup(bo, formulaContext.getPeriod(), formulaContext.getYear(), cellTemplateData);
List<PeriodDataSource> dss = agent.queryManualDataSource(Long.parseLong(cellTemplateData.getCellTemplateId()),
formulaContext.getProjectId(), bo.getPeriod());
if (dss.isEmpty()) {
cellValue = cellValue.add(dss.get(0).getAmount());
}
nullCellDto.setAmount(cellValue); nullCellDto.setAmount(cellValue);
return cellValue; return cellValue;
} }
// bo.disCount();
PeriodCellData cellData = null; PeriodCellData cellData = null;
String projectId = agent.getPastProjectId(curPeriod.getCurYear(), String projectId = agent.getPastProjectId(curPeriod.getCurYear(),
...@@ -120,15 +127,19 @@ public class BB extends FunctionBase implements FreeRefFunction { ...@@ -120,15 +127,19 @@ public class BB extends FunctionBase implements FreeRefFunction {
MyAsserts.assertNotEmpty(projectId, Exceptions.PROJECT_EMPTY); MyAsserts.assertNotEmpty(projectId, Exceptions.PROJECT_EMPTY);
cellData = agent.getCellData(cellTemplateData.getReportTemplateId(), cellData = agent.getCellData(cellTemplateData.getReportTemplateId(),
cellTemplateData.getCellTemplateId(), curPeriod.getCurPeriod(), formulaContext.getProjectId()); cellTemplateData.getCellTemplateId(), curPeriod.getCurPeriod(), formulaContext.getProjectId());
List<PeriodDataSource> dss = agent.queryManualDataSource(Long.parseLong(cellTemplateData.getCellTemplateId()),
formulaContext.getProjectId(), formulaContext.getPeriod());
nullCellDto.extractFromGroup(bo, curPeriod, cellData, cellTemplateData); nullCellDto.extractFromGroup(bo, curPeriod, cellData, cellTemplateData);
// todo: fix datasource name by templateList(neo)
MyAsserts.assertNotNull(cellData.getData(), Exceptions.BB_CELL_DATA_NULL); if (dss.isEmpty())
MyAsserts.assertNotNull(cellData.getData(), Exceptions.BB_CELL_DATA_NULL);
else cellValue = dss.get(0).getAmount();
// cellValue= RoundValue(cellValue, cellDataType)TODO:maybe fixd round by cellDataTyep(KV neo) if (cellData.getData()!=null) {
cellValue = new BigDecimal(cellData.getData()).setScale(4, cellValue = cellValue.add( new BigDecimal(cellData.getData()).setScale(4,
BigDecimal.ROUND_HALF_DOWN); BigDecimal.ROUND_HALF_DOWN));
}
nullCellDto.setAmount(cellValue); nullCellDto.setAmount(cellValue);
if (rootBo != null) { if (rootBo != null) {
rootBo.putPeriodCellTempate(curPeriod.getCurPeriod(), Long.parseLong(cellTemplateData.getCellTemplateId())); rootBo.putPeriodCellTempate(curPeriod.getCurPeriod(), Long.parseLong(cellTemplateData.getCellTemplateId()));
...@@ -138,9 +149,12 @@ public class BB extends FunctionBase implements FreeRefFunction { ...@@ -138,9 +149,12 @@ public class BB extends FunctionBase implements FreeRefFunction {
LOGGER.debug("cell static value "); LOGGER.debug("cell static value ");
return cellValue; return cellValue;
} catch (Exception e) {
logger.warn("[BB_Exception] some error {}", bo.toString());
throw e;
} finally { } finally {
if (rootBo == null) { if (rootBo == null) {
LOGGER.warn("error for bb cacls for {} and current for {}", bo.toString(), curPeriod.toString()); LOGGER.warn("[BB_Exception] error for bb cacls for {} and current for {}", bo.toString(), curPeriod.toString());
Long dataSourceId = saveDataSource(ec, dataSource, FormulaDataSourceDetailType.ReportCellDataSourceDto, Long dataSourceId = saveDataSource(ec, dataSource, FormulaDataSourceDetailType.ReportCellDataSourceDto,
cellValue, formulaContext.getPeriod(), cellValue, formulaContext.getPeriod(),
formulaContext.getReportTemplateGroupId(), bo.getColumnIndex() - 1, bo.getRowIndex() - 1, formulaContext.getReportTemplateGroupId(), bo.getColumnIndex() - 1, bo.getRowIndex() - 1,
......
...@@ -2,15 +2,12 @@ package pwc.taxtech.atms.vat.dao; ...@@ -2,15 +2,12 @@ package pwc.taxtech.atms.vat.dao;
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.annotations.Select;
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.vat.entity.CellData; import pwc.taxtech.atms.vat.entity.CellData;
import pwc.taxtech.atms.vat.entity.CellDataExample; import pwc.taxtech.atms.vat.entity.CellDataExample;
import pwc.taxtech.atms.vat.entity.PCTEntity;
import java.util.List; import java.util.List;
import java.util.Set;
@Mapper @Mapper
public interface CellDataMapper extends MyVatMapper { public interface CellDataMapper extends MyVatMapper {
...@@ -110,19 +107,4 @@ public interface CellDataMapper extends MyVatMapper { ...@@ -110,19 +107,4 @@ public interface CellDataMapper extends MyVatMapper {
*/ */
int updateByPrimaryKey(CellData record); int updateByPrimaryKey(CellData record);
@Select("<script>" +
"SELECT " +
" R.PERIOD, C.CELL_TEMPLATE_ID AS CELLTEMPLATEID, DATA " +
"FROM " +
" CELL_DATA C, " +
" REPORT R " +
"WHERE " +
" C.REPORT_ID = R.ID AND " +
" " +
" <foreach item=\"item\" index=\"index\" collection=\"list\"" +
" open=\"(\" separator=\"OR\" close=\")\">" +
" ( R.PERIOD=#{item.period} AND C.CELL_TEMPLATE_ID=#{item.cellTemplateId} )" +
" </foreach>" +
"</script>")
List<PCTEntity> queryByPCTs(@Param("list") Set<PCTEntity> parameter);
} }
\ No newline at end of file
...@@ -2,16 +2,12 @@ package pwc.taxtech.atms.vat.dao; ...@@ -2,16 +2,12 @@ package pwc.taxtech.atms.vat.dao;
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.annotations.Select;
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.vat.dpo.MergerManaualCellData;
import pwc.taxtech.atms.vat.entity.PCTEntity;
import pwc.taxtech.atms.vat.entity.PeriodCellData; import pwc.taxtech.atms.vat.entity.PeriodCellData;
import pwc.taxtech.atms.vat.entity.PeriodCellDataExample; import pwc.taxtech.atms.vat.entity.PeriodCellDataExample;
import java.util.List; import java.util.List;
import java.util.Set;
@Mapper @Mapper
public interface PeriodCellDataMapper extends MyVatMapper { public interface PeriodCellDataMapper extends MyVatMapper {
...@@ -111,51 +107,5 @@ public interface PeriodCellDataMapper extends MyVatMapper { ...@@ -111,51 +107,5 @@ public interface PeriodCellDataMapper extends MyVatMapper {
*/ */
int updateByPrimaryKey(PeriodCellData record); int updateByPrimaryKey(PeriodCellData record);
int batchInsert2(List<PeriodCellData> list);
int batchInsert(List<PeriodCellData> list); int batchInsert(List<PeriodCellData> list);
@Select("<script>" +
"SELECT " +
" count( pcds.DATA_SOURCE_ID ) AS dsCount, " +
" pcd.ID as cellId, " +
" pcd.DATA as data, " +
" pcd.FORMULA_EXP as formulaExp, " +
" pcd.CELL_TEMPLATE_ID as cellTemplateId, " +
" pcd.PERIOD as period, " +
" temp.AMOUNT as amount " +
"FROM " +
" PERIOD_CELL_DATA pcd " +
" JOIN PERIOD_CELL_DATA_SOURCE pcds ON pcd.ID = pcds.CELL_DATA_ID " +
" LEFT JOIN ( " +
" SELECT " +
" pcd.ID, " +
" pds.TYPE, " +
" pds.AMOUNT, " +
" pds.PERIOD, " +
" pds.PROJECT_ID " +
" FROM " +
" PERIOD_CELL_DATA pcd " +
" JOIN PERIOD_CELL_DATA_SOURCE pcds ON pcd.ID = pcds.CELL_DATA_ID " +
" JOIN PERIOD_DATA_SOURCE pds ON pcds.DATA_SOURCE_ID = pds.ID " +
" WHERE " +
" pcd.PROJECT_ID = #{projectId} " +
" AND pds.TYPE = 10 " +
" ) temp ON pcd.ID = temp.ID AND pcd.PROJECT_ID = temp.PROJECT_ID and pcd.PERIOD = temp.period " +
"WHERE " +
" pcd.PERIOD = 10 " +
" AND pcd.PROJECT_ID = #{projectId} AND " +
" <foreach item=\"item\" index=\"index\" collection=\"list\"" +
" open=\"(\" separator=\"OR\" close=\")\">" +
" ( pcd.PERIOD=#{item.period} AND pcd.CELL_TEMPLATE_ID=#{item.cellTemplateId} )" +
" </foreach>" +
"GROUP BY " +
" pcd.ID, " +
" pcd.DATA, " +
" pcd.FORMULA_EXP, " +
" pcd.CELL_TEMPLATE_ID, " +
" pcd.PERIOD, " +
" temp.AMOUNT" +
"</script>")
List<PCTEntity> queryByPCTs(@Param("list") Set<PCTEntity> parameter, @Param("projectId") String projectId);
} }
\ No newline at end of file
package pwc.taxtech.atms.vat.entity;
public class PCTEntity {
Integer period;
Long cellTemplateId;
String data;
String formulaExp;
Long cellId;
String amount;
Integer dsCount;
public PCTEntity() {
}
public PCTEntity(String pctStr) {
String[] pct = pctStr.split(":");
this.period = Integer.parseInt(pct[0]);
this.cellTemplateId = Long.parseLong(pct[1]);
}
@Override
public int hashCode() {
return (period + "" + cellTemplateId).hashCode();
}
@Override
public boolean equals(Object obj) {
PCTEntity target = (PCTEntity) obj;
return period.intValue() == target.period.intValue()
&& cellTemplateId.longValue() == target.cellTemplateId.longValue();
}
public Integer getPeriod() {
return period;
}
public void setPeriod(Integer period) {
this.period = period;
}
public Long getCellTemplateId() {
return cellTemplateId;
}
public void setCellTemplateId(Long cellTemplateId) {
this.cellTemplateId = cellTemplateId;
}
public String getData() {
return data;
}
public void setData(String data) {
this.data = data;
}
public String getFormulaExp() {
return formulaExp;
}
public void setFormulaExp(String formulaExp) {
this.formulaExp = formulaExp;
}
public Long getCellId() {
return cellId;
}
public void setCellId(Long cellId) {
this.cellId = cellId;
}
public String getAmount() {
return amount;
}
public void setAmount(String amount) {
this.amount = amount;
}
public Integer getDsCount() {
return dsCount;
}
public void setDsCount(Integer dsCount) {
this.dsCount = dsCount;
}
}
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