Commit 017a3bf0 authored by chase's avatar chase

fix bug

parent 61b410ff
...@@ -59,6 +59,7 @@ public class SpringContextUtil implements ApplicationContextAware { ...@@ -59,6 +59,7 @@ public class SpringContextUtil implements ApplicationContextAware {
public static AdjustmentTableMapper adjustmentTableMapper; public static AdjustmentTableMapper adjustmentTableMapper;
public static TrialBalanceFinalMapper trialBalanceFinalMapper; public static TrialBalanceFinalMapper trialBalanceFinalMapper;
public static ProfitLossStatementMapper profitLossStatementMapper; public static ProfitLossStatementMapper profitLossStatementMapper;
public static RevenueConfigMapper revenueConfigMapper;
public static RevenueTypeMappingMapper revenueTypeMappingMapper; public static RevenueTypeMappingMapper revenueTypeMappingMapper;
public static InvoiceRecordMapper invoiceRecordMapper; public static InvoiceRecordMapper invoiceRecordMapper;
public static CertifiedInvoicesListMapper certifiedInvoicesListMapper; public static CertifiedInvoicesListMapper certifiedInvoicesListMapper;
...@@ -148,6 +149,7 @@ public class SpringContextUtil implements ApplicationContextAware { ...@@ -148,6 +149,7 @@ public class SpringContextUtil implements ApplicationContextAware {
invoiceRecordMapper = webApplicationContext.getBean(InvoiceRecordMapper.class); invoiceRecordMapper = webApplicationContext.getBean(InvoiceRecordMapper.class);
certifiedInvoicesListMapper = webApplicationContext.getBean(CertifiedInvoicesListMapper.class); certifiedInvoicesListMapper = webApplicationContext.getBean(CertifiedInvoicesListMapper.class);
trialBalanceMappingMapper = webApplicationContext.getBean(TrialBalanceMappingMapper.class); trialBalanceMappingMapper = webApplicationContext.getBean(TrialBalanceMappingMapper.class);
revenueConfigMapper = webApplicationContext.getBean(RevenueConfigMapper.class);
/* map.put("balance_sheet", balanceMapper); /* map.put("balance_sheet", balanceMapper);
map.put("profit_loss_statement",profitLossStatementMapper); map.put("profit_loss_statement",profitLossStatementMapper);
map.put("cash_flow", cashFlowMapper); map.put("cash_flow", cashFlowMapper);
......
...@@ -342,6 +342,17 @@ public class ReportServiceImpl extends BaseService { ...@@ -342,6 +342,17 @@ public class ReportServiceImpl extends BaseService {
andStartDateLessThanOrEqualTo(queryDate).andEndDateGreaterThanOrEqualTo(queryDate). andStartDateLessThanOrEqualTo(queryDate).andEndDateGreaterThanOrEqualTo(queryDate).
andStatusEqualTo(0); andStatusEqualTo(0);
List<RevenueTypeMapping> mappingList = revenueTypeMappingMapper.selectByExample(mappingExample); List<RevenueTypeMapping> mappingList = revenueTypeMappingMapper.selectByExample(mappingExample);
//先清除数据
InvoiceRecord delRecord = new InvoiceRecord();
delRecord.setRevenueCofId(null);
if(!isMergeManualData){
delRecord.setModifyRevenueCofId(null);
}
InvoiceRecordExample delExample = new InvoiceRecordExample();
delExample.createCriteria().andProjectIdEqualTo(projectId)
.andProjectIdEqualTo(projectId).
andPeriodEqualTo(Integer.valueOf(queryDate.replace("-", "")));
invoiceRecordMapper.deleteByExample(delExample);
Map<String, Long> map = new HashMap<>(); Map<String, Long> map = new HashMap<>();
for (RevenueTypeMapping mapping : mappingList) { for (RevenueTypeMapping mapping : mappingList) {
if (!map.containsKey(mapping.getContent())) { if (!map.containsKey(mapping.getContent())) {
...@@ -356,10 +367,6 @@ public class ReportServiceImpl extends BaseService { ...@@ -356,10 +367,6 @@ public class ReportServiceImpl extends BaseService {
} }
if (map.containsKey(mapping.getContent())) { if (map.containsKey(mapping.getContent())) {
InvoiceRecord destRecord = new InvoiceRecord(); InvoiceRecord destRecord = new InvoiceRecord();
//是否保存手工数据源
if(!isMergeManualData){
destRecord.setModifyRevenueCofId(null);
}
destRecord.setRevenueCofId(map.get(mapping.getContent())); destRecord.setRevenueCofId(map.get(mapping.getContent()));
InvoiceRecordExample recordExample = new InvoiceRecordExample(); InvoiceRecordExample recordExample = new InvoiceRecordExample();
recordExample.createCriteria().andProjectIdEqualTo(projectId) recordExample.createCriteria().andProjectIdEqualTo(projectId)
...@@ -2331,7 +2338,7 @@ public class ReportServiceImpl extends BaseService { ...@@ -2331,7 +2338,7 @@ public class ReportServiceImpl extends BaseService {
} }
@Autowired @Resource
private EbitSpreadDataMapper ebitSpreadDataMapper; private EbitSpreadDataMapper ebitSpreadDataMapper;
public OperationResultDto spreadToDb(RequestParameterDto.EbitParam ebitParam) { public OperationResultDto spreadToDb(RequestParameterDto.EbitParam ebitParam) {
......
...@@ -12,19 +12,17 @@ import pwc.taxtech.atms.constant.enums.EnumOperationType; ...@@ -12,19 +12,17 @@ import pwc.taxtech.atms.constant.enums.EnumOperationType;
import pwc.taxtech.atms.constant.enums.FormulaDataSourceDetailType; import pwc.taxtech.atms.constant.enums.FormulaDataSourceDetailType;
import pwc.taxtech.atms.constant.enums.KeyValueConfigResultType; import pwc.taxtech.atms.constant.enums.KeyValueConfigResultType;
import pwc.taxtech.atms.dto.vatdto.OutputInvoiceDataSourceDto; import pwc.taxtech.atms.dto.vatdto.OutputInvoiceDataSourceDto;
import pwc.taxtech.atms.vat.entity.InvoiceRecord; import pwc.taxtech.atms.vat.entity.*;
import pwc.taxtech.atms.vat.entity.InvoiceRecordExample;
import pwc.taxtech.atms.vat.entity.RevenueTypeMapping;
import pwc.taxtech.atms.vat.entity.RevenueTypeMappingExample;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
* 根据收入类型配置查询开票收入开票金额总计 * 根据收入类型配置查询开票收入开票金额总计
*/ */
public class KPSR extends FunctionBase implements FreeRefFunction { public class KPSR extends FunctionBase implements FreeRefFunction {
public KPSR(FormulaContext formulaContext) { public KPSR(FormulaContext formulaContext) {
...@@ -40,10 +38,10 @@ public class KPSR extends FunctionBase implements FreeRefFunction { ...@@ -40,10 +38,10 @@ public class KPSR extends FunctionBase implements FreeRefFunction {
String revenueTypeName = getStringParam(args[0], ec);//收入类型名称 String revenueTypeName = getStringParam(args[0], ec);//收入类型名称
Integer billType = getIntParam(args[1], ec);//发票类型 Integer billType = getIntParam(args[1], ec);//发票类型
Integer amountType = getIntParam(args[2], ec);//金额类型 Integer amountType = getIntParam(args[2], ec);//金额类型
String formulaExpression = "KPSR(\"" + revenueTypeName + "\","+billType+ ","+amountType+")"; String formulaExpression = "KPSR(\"" + revenueTypeName + "\"," + billType + "," + amountType + ")";
logger.debug(formulaExpression); logger.debug(formulaExpression);
List<OutputInvoiceDataSourceDto> dataSource = new ArrayList<>(); List<OutputInvoiceDataSourceDto> dataSource = new ArrayList<>();
double result = assembleData(revenueTypeName,dataSource,billType,amountType,ec); double result = assembleData(revenueTypeName, dataSource, billType, amountType, ec);
Long dataSoureId = saveDataSource(ec, Collections.singletonList(dataSource), FormulaDataSourceDetailType.OutputInvoiceDataSourceDto, new BigDecimal(result), formulaContext.getPeriod(), Long dataSoureId = saveDataSource(ec, Collections.singletonList(dataSource), FormulaDataSourceDetailType.OutputInvoiceDataSourceDto, new BigDecimal(result), formulaContext.getPeriod(),
formulaContext.getReportTemplateGroupId(), formulaContext.getProjectId()); formulaContext.getReportTemplateGroupId(), formulaContext.getProjectId());
saveFormulaBlock(formulaContext.getPeriod(), ec, formulaExpression, new BigDecimal(result), dataSoureId, formulaContext.getProjectId()); saveFormulaBlock(formulaContext.getPeriod(), ec, formulaExpression, new BigDecimal(result), dataSoureId, formulaContext.getProjectId());
...@@ -51,9 +49,9 @@ public class KPSR extends FunctionBase implements FreeRefFunction { ...@@ -51,9 +49,9 @@ public class KPSR extends FunctionBase implements FreeRefFunction {
} }
private double assembleData(String revenueTypeName, List<OutputInvoiceDataSourceDto> contain, Integer billType,Integer amountType,OperationEvaluationContext ec) { private double assembleData(String revenueTypeName, List<OutputInvoiceDataSourceDto> contain, Integer billType, Integer amountType, OperationEvaluationContext ec) {
String queryDate = formulaContext.getYear()+(formulaContext.getPeriod()<10?("0"+formulaContext.getPeriod()):(formulaContext.getPeriod()+"")); String queryDate = formulaContext.getYear() + (formulaContext.getPeriod() < 10 ? ("0" + formulaContext.getPeriod()) : (formulaContext.getPeriod() + ""));
RevenueTypeMappingExample typeMappingExample = new RevenueTypeMappingExample(); RevenueTypeMappingExample typeMappingExample = new RevenueTypeMappingExample();
typeMappingExample.createCriteria().andOrgIdEqualTo(formulaContext.getOrganizationId()) typeMappingExample.createCriteria().andOrgIdEqualTo(formulaContext.getOrganizationId())
.andRevenueTypeNameEqualTo(revenueTypeName).andStartDateLessThanOrEqualTo(queryDate) .andRevenueTypeNameEqualTo(revenueTypeName).andStartDateLessThanOrEqualTo(queryDate)
...@@ -62,17 +60,43 @@ public class KPSR extends FunctionBase implements FreeRefFunction { ...@@ -62,17 +60,43 @@ public class KPSR extends FunctionBase implements FreeRefFunction {
if (CollectionUtils.isEmpty(typeMappingList)) { if (CollectionUtils.isEmpty(typeMappingList)) {
return 0.0; return 0.0;
} }
List<String> contens = typeMappingList.stream() List<String> revenueTypes = typeMappingList.stream()
.map(o -> o.getContent()).collect(Collectors.toList()); .map(o -> o.getRevenueTypeName()).collect(Collectors.toList());
if (CollectionUtils.isEmpty(contens)) { RevenueConfigExample configExample = new RevenueConfigExample();
configExample.createCriteria().andOrgIdEqualTo(formulaContext.getOrganizationId()).andStartDateLessThanOrEqualTo(queryDate)
.andEndDateGreaterThanOrEqualTo(queryDate).andNameIn(revenueTypes);
List<RevenueConfig> configDatas = SpringContextUtil.revenueConfigMapper.selectByExample(configExample);
if (CollectionUtils.isEmpty(configDatas)) {
return 0.0; return 0.0;
} }
List<Long> revenueTypeIds = configDatas.stream()
.map(o -> o.getId()).collect(Collectors.toList());
List<InvoiceRecord> billDetails = new ArrayList<>();
InvoiceRecordExample invoiceRecordExample = new InvoiceRecordExample(); InvoiceRecordExample invoiceRecordExample = new InvoiceRecordExample();
InvoiceRecordExample.Criteria c = invoiceRecordExample.createCriteria().andBillingContentIn(contens) invoiceRecordExample.createCriteria().andRevenueCofIdIn(revenueTypeIds)
.andProjectIdEqualTo(formulaContext.getProjectId())
.andPeriodEqualTo(Integer.valueOf(queryDate))
.andInvoiceTypeEqualTo(InvoiceRecordEnum.InvoiceType.MAPPING.get(billType));
List<InvoiceRecord> billDetails1 = SpringContextUtil.invoiceRecordMapper.selectByExample(invoiceRecordExample);
if(CollectionUtils.isNotEmpty(billDetails1)){
Iterator<InvoiceRecord> iterator = billDetails1.iterator();
while (iterator.hasNext()){
if(iterator.next().getModifyRevenueCofId()!=null){
iterator.remove();
}
}
billDetails.addAll(billDetails1);
}
invoiceRecordExample = new InvoiceRecordExample();
invoiceRecordExample.createCriteria().andModifyRevenueCofIdIn(revenueTypeIds)
.andProjectIdEqualTo(formulaContext.getProjectId()) .andProjectIdEqualTo(formulaContext.getProjectId())
.andPeriodEqualTo(Integer.valueOf(queryDate)) .andPeriodEqualTo(Integer.valueOf(queryDate))
.andInvoiceTypeEqualTo(InvoiceRecordEnum.InvoiceType.MAPPING.get(billType)); .andInvoiceTypeEqualTo(InvoiceRecordEnum.InvoiceType.MAPPING.get(billType));
List<InvoiceRecord> billDetails = SpringContextUtil.invoiceRecordMapper.selectByExample(invoiceRecordExample); List<InvoiceRecord> billDetails2 = SpringContextUtil.invoiceRecordMapper.selectByExample(invoiceRecordExample);
if(CollectionUtils.isNotEmpty(billDetails2)){
billDetails.addAll(billDetails2);
}
for (InvoiceRecord invoiceRecord : billDetails) { for (InvoiceRecord invoiceRecord : billDetails) {
OutputInvoiceDataSourceDto outputInvoiceDataSourceDto = new OutputInvoiceDataSourceDto(); OutputInvoiceDataSourceDto outputInvoiceDataSourceDto = new OutputInvoiceDataSourceDto();
outputInvoiceDataSourceDto.setAmount(FormulaHelper.roundValue(invoiceRecord.getInvoiceAmount(), outputInvoiceDataSourceDto.setAmount(FormulaHelper.roundValue(invoiceRecord.getInvoiceAmount(),
...@@ -91,9 +115,9 @@ public class KPSR extends FunctionBase implements FreeRefFunction { ...@@ -91,9 +115,9 @@ public class KPSR extends FunctionBase implements FreeRefFunction {
outputInvoiceDataSourceDto.setOperationType(EnumOperationType.Single.getCode()); outputInvoiceDataSourceDto.setOperationType(EnumOperationType.Single.getCode());
contain.add(outputInvoiceDataSourceDto); contain.add(outputInvoiceDataSourceDto);
} }
if(InvoiceRecordEnum.AmountType.INVOICE_AMOUNT.getCode().equals(amountType)){ if (InvoiceRecordEnum.AmountType.INVOICE_AMOUNT.getCode().equals(amountType)) {
return billDetails.stream().mapToDouble(a -> a.getInvoiceAmount().doubleValue()).sum(); return billDetails.stream().mapToDouble(a -> a.getInvoiceAmount().doubleValue()).sum();
}else if (InvoiceRecordEnum.AmountType.TAX_AMOUNT.getCode().equals(amountType)){ } else if (InvoiceRecordEnum.AmountType.TAX_AMOUNT.getCode().equals(amountType)) {
return billDetails.stream().mapToDouble(a -> a.getTaxAmount().doubleValue()).sum(); return billDetails.stream().mapToDouble(a -> a.getTaxAmount().doubleValue()).sum();
} }
return 0; return 0;
......
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