Commit 092ecc04 authored by neo's avatar neo

[DEV] add aop exclude for angent mapper

parent 6edf0b16
package pwc.taxtech.atms.dto.vatdto;
import pwc.taxtech.atms.vat.service.impl.report.functions.FormulaAgent;
import pwc.taxtech.atms.vat.service.impl.FormulaAgent;
import java.util.ArrayList;
import java.util.List;
......
package pwc.taxtech.atms.vat.service.impl.report.functions;
package pwc.taxtech.atms.vat.service.impl;
import org.springframework.stereotype.Service;
import pwc.taxtech.atms.common.util.SpringContextUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
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;
......@@ -16,32 +20,33 @@ import java.util.List;
import static pwc.taxtech.atms.constant.Constant.FIRST_OR_DEFAULT;
@Service
public class FormulaAgent {
// @Autowired
// public FormulaAdminMapper formulaAdminMapper;
// @Autowired
// public FormulaProjectMapper projectMp;
// @Autowired
// public ReportMapper reportMapper;
// @Autowired
// public CellDataMapper cellDataMapper;
@Repository
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 = SpringContextUtil.projectServiceTypeMapper.selectByExample(pst);
List<ProjectServiceType> pstReult = projectServiceTypeMapper.selectByExample(pst);
List<CellTemplatePerGroupDto> cellTemplates = SpringContextUtil.formulaAdminMapper.getCellTemplatePerGroupDto(templateGroupId);
List<CellTemplatePerGroupDto> cellTemplates = adminMp.getCellTemplatePerGroupDto(templateGroupId);
if (pstReult == null || pstReult.isEmpty()) {
List<GroupId> groupIds = SpringContextUtil.formulaAdminMapper.getTemplateGroupId(projectId);
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(SpringContextUtil.formulaAdminMapper.getCellTemplatePerGroupDto(groupId.groupId));
cellTemplates.addAll(adminMp.getCellTemplatePerGroupDto(groupId.groupId));
}
}
return cellTemplates;
......@@ -51,7 +56,7 @@ public class FormulaAgent {
ReportExample example = new ReportExample();
example.createCriteria().andTemplateIdEqualTo(Long.valueOf(templateId))
.andPeriodEqualTo(periodId);
List<Report> reports = SpringContextUtil.reportMapper.selectByExample(example);
List<Report> reports = reportMapper.selectByExample(example);
if (reports != null || !reports.isEmpty()) return reports.get(FIRST_OR_DEFAULT);
return null;
......@@ -60,9 +65,10 @@ public class FormulaAgent {
public CellData getCellDataListByTemplate(String templateId, Long reportId) {
CellDataExample dataExample = new CellDataExample();
dataExample.createCriteria().andCellTemplateIdEqualTo(Long.valueOf(templateId));
List<CellData> cellDataList = SpringContextUtil.cellDataMapper.selectByExample(dataExample);
List<CellData> cellDataList = cellDataMapper.selectByExample(dataExample);
if (cellDataList != null || !cellDataList.isEmpty()) return cellDataList.get(FIRST_OR_DEFAULT);
return null;
}
}
......@@ -18,7 +18,6 @@ import pwc.taxtech.atms.dto.vatdto.ReportCellDataSourceDto;
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.math.BigDecimal;
......
......@@ -6,7 +6,12 @@ import org.apache.poi.ss.formula.functions.FreeRefFunction;
import org.apache.poi.ss.formula.udf.AggregatingUDFFinder;
import org.apache.poi.ss.formula.udf.DefaultUDFFinder;
import org.apache.poi.ss.formula.udf.UDFFinder;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.usermodel.Cell;
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.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -15,15 +20,33 @@ import org.springframework.stereotype.Service;
import pwc.taxtech.atms.common.POIUtil;
import pwc.taxtech.atms.constant.enums.CellDataSourceType;
import pwc.taxtech.atms.service.impl.DistributedIDService;
import pwc.taxtech.atms.vat.dao.*;
import pwc.taxtech.atms.vat.entity.*;
import pwc.taxtech.atms.vat.dao.CellDataMapper;
import pwc.taxtech.atms.vat.dao.PeriodCellTemplateConfigMapper;
import pwc.taxtech.atms.vat.dao.PeriodCellTemplateMapper;
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.impl.report.functions.*;
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.ND;
import pwc.taxtech.atms.vat.service.impl.report.functions.SGSR;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.*;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
@Service
......@@ -55,7 +78,7 @@ public class ReportGeneratorImpl implements ReportGenerator {
List<PeriodTemplate> periodTemplateList = periodTemplateMapper.selectByExample(periodTemplateExample);
List<Long> periodTemplateIDList = periodTemplateList.stream().map(PeriodTemplate::getTemplateId).collect(Collectors.toList());
Long templateGroupID = periodTemplateList.size()>0?periodTemplateList.get(0).getTemplateGroupId():0;
Long templateGroupID = periodTemplateList.size() > 0 ? periodTemplateList.get(0).getTemplateGroupId() : 0;
PeriodCellTemplateExample periodCellTemplateExample = new PeriodCellTemplateExample();
periodCellTemplateExample.createCriteria().andReportTemplateIdIn(periodTemplateIDList);
......@@ -74,10 +97,7 @@ public class ReportGeneratorImpl implements ReportGenerator {
Workbook newWorkbook = workbook.get();
addFunctionsToWorkbook(newWorkbook,templateGroupID);
addFunctionsToWorkbook(newWorkbook, templateGroupID);
int sheetCount = newWorkbook.getNumberOfSheets();
for (int i = 0; i < sheetCount; i++) {
Sheet sheet = newWorkbook.getSheetAt(i);
......@@ -119,7 +139,7 @@ public class ReportGeneratorImpl implements ReportGenerator {
cell = row.getCell(k.getColumnIndex());
//todo:后面单独处理kv的公式
if(!v.getFormula().contains("@")) {
if (!v.getFormula().contains("@")) {
cell.setCellFormula(v.getFormula());
}
});
......@@ -157,17 +177,16 @@ public class ReportGeneratorImpl implements ReportGenerator {
List<PeriodCellTemplateConfig> periodCellTemplateConfigs = periodCellTemplateConfigList.stream().filter(a -> a.getReportTemplateId().equals(templateID)).collect(Collectors.toList());
for (PeriodCellTemplateConfig periodCellTemplateConfig : periodCellTemplateConfigs) {
Optional<PeriodCellTemplate> tempPeriodCellTemplate = periodCellTemplateList.stream().filter(a->a.getCellTemplateId().equals(periodCellTemplateConfig.getCellTemplateId())).findFirst();
if (tempPeriodCellTemplate!=null){
Optional<PeriodCellTemplate> tempPeriodCellTemplate = periodCellTemplateList.stream().filter(a -> a.getCellTemplateId().equals(periodCellTemplateConfig.getCellTemplateId())).findFirst();
if (tempPeriodCellTemplate != null) {
CellData cellData = new CellData();
cellData.setId(distributedIDService.nextId());
cellData.setReportId(reportID);
cellData.setCellTemplateId(tempPeriodCellTemplate.get().getCellTemplateId());
String data;
if(sheet.getRow(tempPeriodCellTemplate.get().getRowIndex())!=null&&sheet.getRow(tempPeriodCellTemplate.get().getRowIndex()).getCell(tempPeriodCellTemplate.get().getColumnIndex())!=null){
data =Double.toString(sheet.getRow(tempPeriodCellTemplate.get().getRowIndex()).getCell(tempPeriodCellTemplate.get().getColumnIndex()).getNumericCellValue());
}
else{
if (sheet.getRow(tempPeriodCellTemplate.get().getRowIndex()) != null && sheet.getRow(tempPeriodCellTemplate.get().getRowIndex()).getCell(tempPeriodCellTemplate.get().getColumnIndex()) != null) {
data = Double.toString(sheet.getRow(tempPeriodCellTemplate.get().getRowIndex()).getCell(tempPeriodCellTemplate.get().getColumnIndex()).getNumericCellValue());
} else {
data = StringUtils.EMPTY;
}
cellData.setData(data);
......@@ -236,15 +255,15 @@ public class ReportGeneratorImpl implements ReportGenerator {
*
* @param workbook 工作簿
*/
private void addFunctionsToWorkbook(Workbook workbook,Long templateGroupID) {
String[] functionNames = {"SGSR","FSJZ","ND"};
private void addFunctionsToWorkbook(Workbook workbook, Long templateGroupID) {
String[] functionNames = {"SGSR", "FSJZ", "ND"};
FormulaContext formulaContext = new FormulaContext();
formulaContext.setFormulaAgent(formulaAgent);
formulaContext.setPeriod(6);//todo: assign value later
formulaContext.setReportTemplateGroupID(templateGroupID);
FreeRefFunction[] functionImpls = {new SGSR(formulaContext),new FSJZ(formulaContext),new ND(formulaContext)};
FreeRefFunction[] functionImpls = {new SGSR(formulaContext), new FSJZ(formulaContext), new ND(formulaContext)};
UDFFinder udfs = new DefaultUDFFinder(functionNames, functionImpls);
UDFFinder udfToolpack = new AggregatingUDFFinder(udfs);
workbook.addToolPack(udfToolpack);
}
}
}
......@@ -2,6 +2,7 @@ package pwc.taxtech.atms.vat.service.impl.report.functions;
import lombok.Getter;
import lombok.Setter;
import pwc.taxtech.atms.vat.service.impl.FormulaAgent;
@Setter
@Getter
......
......@@ -74,13 +74,14 @@
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="txPointcut2" expression="execution(public * pwc.taxtech.atms..*.*(..)) &amp;&amp; @target(org.springframework.stereotype.Service)" />
<aop:config proxy-target-class="true">
<aop:pointcut id="txPointcut2" expression="execution(public * pwc.taxtech.atms..*.*(..)) &amp;&amp; @target(org.springframework.stereotype.Service)
and !execution(* pwc.taxtech.atms.vat.service.impl.FormulaAgent.*(..))" />
<aop:advisor pointcut-ref="txPointcut2" advice-ref="txAdvice" />
</aop:config>
<aop:aspectj-autoproxy />
<tx:annotation-driven proxy-target-class="true" />
</beans>
\ No newline at end of file
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