Commit 887a9b34 authored by neo's avatar neo

[Dev] fixed get celltemplatedto bugs and fixed other year projectid

parent 1498a94f
......@@ -38,6 +38,10 @@ public class MyAsserts {
if (obj == null || obj.isEmpty()) throw exception;
}
public static void assertNotEmpty(Collection obj, FormulaException exception) {
if (obj == null || obj.isEmpty()) throw exception;
}
public static void assertNotEmpty(Collection obj, ApiException exception) {
if (obj == null || obj.isEmpty()) throw exception;
}
......
......@@ -19,4 +19,5 @@ public class Exceptions {
public static final ApiException NOT_FOUND_TEMPLATE_GROUP_EXCEPTION = new NotFoundException("not found template group");
public static final ApiException NOT_FOUND_EXCEPTION = new NotFoundException("not found resources");
public static final ApiException REPORT_IN_PROCESS_OR_AGREED_EXCEPTION = new PreconditionFailedException("report in approval or agreed result");
public static final FormulaException PROJECT_NOT_FOUND = new FormulaException("project not found");;
}
......@@ -8,6 +8,7 @@ import pwc.taxtech.atms.dao.FormulaAdminMapper;
import pwc.taxtech.atms.dao.ProjectServiceTypeMapper;
import pwc.taxtech.atms.dpo.CellTemplatePerGroupDto;
import pwc.taxtech.atms.dpo.GroupId;
import pwc.taxtech.atms.entity.Project;
import pwc.taxtech.atms.entity.ProjectServiceType;
import pwc.taxtech.atms.entity.ProjectServiceTypeExample;
import pwc.taxtech.atms.exception.Exceptions;
......@@ -36,24 +37,12 @@ public class FormulaAgent {
@Autowired
private PeriodDataSourceMapper periodDataSourceMapper;
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 List<CellTemplatePerGroupDto> getCellTemplateGroupDto(Long templateGroupId, String projectId,String code,Integer rowIndex,Integer columnIndex,Integer period) {
return adminMp.getCellTemplatePerGroupDto(templateGroupId,code,rowIndex,columnIndex,projectId,period);
}
public Project getFixedProject(String projectId, Integer year) {
return adminMp.getFixedProject(projectId,year);
}
public List<PeriodDataSource> queryManualDataSource(Long templateId, String projectId,Integer period){
......
......@@ -12,6 +12,7 @@ import pwc.taxtech.atms.dpo.CellTemplatePerGroupDto;
import pwc.taxtech.atms.dto.vatdto.BBParasBo;
import pwc.taxtech.atms.dto.vatdto.CurrentPeriodBo;
import pwc.taxtech.atms.dto.vatdto.ReportCellDataSourceDto;
import pwc.taxtech.atms.entity.Project;
import pwc.taxtech.atms.exception.Exceptions;
import pwc.taxtech.atms.exception.FormulaException;
import pwc.taxtech.atms.vat.entity.PeriodCellData;
......@@ -60,14 +61,18 @@ public class BB extends FunctionBase implements FreeRefFunction {
BigDecimal cellValue = BigDecimal.ZERO;
try {
CellTemplatePerGroupDto cellTemplateData = agent.getCellTemplateGroupDto(formulaContext.getReportTemplateGroupId(),
formulaContext.getProjectId()).stream().filter(dto -> dto.getRowIndex() == bo.getRowIndex() - 1
&& dto.getColumnIndex() == bo.getColumnIndex() - 1 && dto.getReportCode().equals(bo.getReportCode()))
.findFirst().orElseThrow(() -> {
return Exceptions.BB_CELL_TEMP_NULL;
});
MyAsserts.assertNotNull(cellTemplateData, Exceptions.BB_CELL_TEMP_NULL);
List<CellTemplatePerGroupDto> cellTemplateDataList;
if (curPeriod.getCurYear() != formulaContext.getYear()) {
Project project = agent.getFixedProject(formulaContext.getProjectId(), curPeriod.getCurYear());
MyAsserts.assertNotNull(project, Exceptions.PROJECT_NOT_FOUND);
cellTemplateDataList = agent.getCellTemplateGroupDto(formulaContext.getReportTemplateGroupId(),
project.getId(), bo.getReportCode(), bo.getRowIndex() - 1, bo.getColumnIndex() - 1, curPeriod.getCurPeriod());
} else {
cellTemplateDataList = agent.getCellTemplateGroupDto(formulaContext.getReportTemplateGroupId(),
formulaContext.getProjectId(), bo.getReportCode(), bo.getRowIndex() - 1, bo.getColumnIndex() - 1, curPeriod.getCurPeriod());
}
MyAsserts.assertNotEmpty(cellTemplateDataList, Exceptions.BB_CELL_TEMP_NULL);
CellTemplatePerGroupDto cellTemplateData = cellTemplateDataList.get(0);
nullCellDto.fixedWithGroup(cellTemplateData);
// todo: fix datasource name by templateList(neo)
......
......@@ -6,37 +6,43 @@ import org.apache.ibatis.annotations.Select;
import pwc.taxtech.atms.MyMapper;
import pwc.taxtech.atms.dpo.CellTemplatePerGroupDto;
import pwc.taxtech.atms.dpo.GroupId;
import pwc.taxtech.atms.entity.Project;
import java.util.List;
@Mapper
public interface FormulaAdminMapper extends MyMapper {
@Select("SELECT " +
" cell_template.id AS cellTemplateID, " +
" template.id AS reportTemplateID, " +
" template.template_group_id AS reportTemplateGroupID, " +
" cell_template.row_index AS rowIndex, " +
" cell_template.column_index AS columnIndex, " +
" template.Code AS reportCode, " +
" cell_template.column_name AS columnName, " +
" cell_template.row_name AS rowName, " +
" cell_template.data_type AS resultType " +
"FROM " +
" template " +
" JOIN " +
" cell_template ON template.id = cell_template.report_template_id " +
"WHERE " +
" template.id IN ( " +
" SELECT " +
" ID " +
" FROM " +
" TEMPLATE " +
" WHERE " +
" TEMPLATE_GROUP_ID = #{groupId} " +
" AND IS_ACTIVE_ASSOCIATION = 1 " +
" )")
List<CellTemplatePerGroupDto> getCellTemplatePerGroupDto(@Param("groupId") Long groupId);
@Select("" +
"SELECT " +
" cell_template.CELL_TEMPLATE_ID AS cellTemplateID, " +
" template.TEMPLATE_ID AS reportTemplateID, " +
" template.template_group_id AS reportTemplateGroupID, " +
" cell_template.row_index AS rowIndex, " +
" cell_template.column_index AS columnIndex, " +
" template.Code AS reportCode, " +
" cell_template.column_name AS columnName, " +
" cell_template.row_name AS rowName, " +
" cell_template.data_type AS resultType " +
"FROM " +
" period_template template " +
" JOIN period_cell_template cell_template ON template.TEMPLATE_ID = cell_template.report_template_id " +
"WHERE " +
" template.TEMPLATE_ID IN ( SELECT TEMPLATE_ID FROM period_template WHERE TEMPLATE_GROUP_ID = #{templateGroupId} " +
" AND IS_ACTIVE_ASSOCIATION = 1 AND CODE = #{code} ) " +
" AND ROW_INDEX = #{rowIndex} " +
" AND COLUMN_INDEX = #{columnIndex} " +
" AND template.PROJECT_ID = #{projectId} " +
" AND template.PERIOD = #{period} " +
" AND cell_template.PROJECT_ID = #{projectId} " +
" AND cell_template.PERIOD = #{period}" +
"")
List<CellTemplatePerGroupDto> getCellTemplatePerGroupDto(@Param("templateGroupId") Long templateGroupId,
@Param("code") String code,
@Param("rowIndex") Integer rowIndex,
@Param("columnIndex") Integer columnIndex,
@Param("projectId") String projectId,
@Param("period") Integer period);
@Select("SELECT " +
......@@ -64,4 +70,17 @@ public interface FormulaAdminMapper extends MyMapper {
" AND ROWNUM=1"+
"ORDER BY ps.Service_Type_ID ")
String getPastProjectId(@Param("year") int year, @Param("orgId") String organizationId);
@Select("" +
"SELECT " +
" p.ID AS id, " +
" p.CODE AS code, " +
" p.NAME AS name, " +
" p.ORGANIZATION_ID AS organizationId " +
"FROM " +
" PROJECT p " +
" JOIN ( SELECT CODE, ORGANIZATION_ID FROM PROJECT WHERE ID = #{projectId} ) t ON p.CODE = t.CODE " +
" AND p.ORGANIZATION_ID = t.ORGANIZATION_ID AND p.YEAR = #{year}" +
"")
Project getFixedProject(@Param("projectId") String projectId, @Param("year") Integer year);
}
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