Commit 092ecc04 authored by neo's avatar neo

[DEV] add aop exclude for angent mapper

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