Commit 19fc7c4a authored by sherlock's avatar sherlock

JFFS

parent c6b49c2b
package pwc.taxtech.atms.vat.service.impl;
import com.google.common.collect.Lists;
import jdk.nashorn.internal.runtime.options.Option;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.formula.functions.FreeRefFunction;
......@@ -20,16 +18,13 @@ import org.springframework.transaction.annotation.Transactional;
import pwc.taxtech.atms.common.POIUtil;
import pwc.taxtech.atms.common.util.SpringContextUtil;
import pwc.taxtech.atms.constant.enums.CellDataSourceType;
import pwc.taxtech.atms.constant.enums.FormulaDataSourceType;
import pwc.taxtech.atms.dao.ProjectMapper;
import pwc.taxtech.atms.dto.vatdto.CellCalcInfoDto;
import pwc.taxtech.atms.dto.vatdto.PeriodResources;
import pwc.taxtech.atms.dto.vatdto.WrapPeriodJobDto;
import pwc.taxtech.atms.exception.Exceptions;
import pwc.taxtech.atms.service.impl.DistributedIdService;
import pwc.taxtech.atms.service.impl.HttpFileService;
import pwc.taxtech.atms.vat.dao.*;
import pwc.taxtech.atms.vat.dpo.MergerManaualCellData;
import pwc.taxtech.atms.vat.dpo.PeriodCellTemplateConfigExtendDto;
import pwc.taxtech.atms.vat.entity.*;
import pwc.taxtech.atms.vat.service.impl.report.functions.*;
......@@ -44,7 +39,6 @@ import java.util.regex.Pattern;
import java.util.stream.Collectors;
import static pwc.taxtech.atms.common.util.SpringContextUtil.reportMapper;
import static pwc.taxtech.atms.constant.Constant.EMPTY;
import static pwc.taxtech.atms.dto.vatdto.WrapPeriodJobDto.*;
@Component
......@@ -521,7 +515,8 @@ public class ReportGeneratorImpl {
public void addFunctionsAndContext(Workbook workbook, String[] functions, FormulaContext formulaContext) {
FreeRefFunction[] functionImpls = {new SGSR(formulaContext), new FSJZ(formulaContext), new ND(formulaContext),
new BB(formulaContext), new XXFP(formulaContext), new GZSD(formulaContext), new ProjectContext(formulaContext)
, new JXFPMX(formulaContext), new JXFP(formulaContext), new PSUM(formulaContext) ,new DFFS(formulaContext)};
, new JXFPMX(formulaContext), new JXFP(formulaContext), new PSUM(formulaContext) ,new DFFS(formulaContext),
new JFFS(formulaContext)};
UDFFinder udfs = new DefaultUDFFinder(functions, functionImpls);
UDFFinder udfToolpack = new AggregatingUDFFinder(udfs);
workbook.addToolPack(udfToolpack);
......
......@@ -50,7 +50,7 @@ import static pwc.taxtech.atms.dto.vatdto.WrapPeriodJobDto.*;
public class ReportServiceImpl {
private final static Logger logger = LoggerFactory.getLogger(ReportServiceImpl.class);
private BlockingQueue<PeriodJob> queue = new LinkedBlockingQueue<>();
private final static String[] functions = {"SGSR", "FSJZ", "ND", "BB", "XXFP", "GZSD", "ProjectContext", "JXFPMX", "JXFP","PSUM","DFFS"};
private final static String[] functions = {"SGSR", "FSJZ", "ND", "BB", "XXFP", "GZSD", "ProjectContext", "JXFPMX", "JXFP","PSUM","DFFS", "JFFS"};
@Autowired
private ReportGeneratorImpl reportGenerator;
......
package pwc.taxtech.atms.vat.service.impl.report.functions;
import com.google.common.collect.Lists;
import org.apache.commons.collections.CollectionUtils;
import org.apache.poi.ss.formula.OperationEvaluationContext;
import org.apache.poi.ss.formula.eval.NumberEval;
import org.apache.poi.ss.formula.eval.ValueEval;
import org.apache.poi.ss.formula.functions.FreeRefFunction;
import pwc.taxtech.atms.common.util.DateUtils;
import pwc.taxtech.atms.common.util.SpringContextUtil;
import pwc.taxtech.atms.constant.Constant;
import pwc.taxtech.atms.constant.enums.FormulaDataSourceDetailType;
import pwc.taxtech.atms.dto.vatdto.ReportCellDataSourceDto;
import pwc.taxtech.atms.entity.AccountMapping;
import pwc.taxtech.atms.entity.AccountMappingExample;
import pwc.taxtech.atms.entity.EnterpriseAccountSetOrg;
import pwc.taxtech.atms.entity.EnterpriseAccountSetOrgExample;
import pwc.taxtech.atms.vat.entity.GlBalance;
import pwc.taxtech.atms.vat.entity.GlBalanceExample;
import java.math.BigDecimal;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
public class JFFS extends FunctionBase implements FreeRefFunction {
public JFFS(FormulaContext formulaContext) {
super(formulaContext);
}
@Override
public ValueEval evaluate(ValueEval[] args, OperationEvaluationContext ec) {
if (args.length < 4) {
return null;
}
int type = getIntParam(args[0], ec);
String code = getStringParam(args[1], ec);
int year = getIntParam(args[2], ec);
int period = getIntParam(args[3], ec);
String formulaExpression = "JFFS(" + type + ",\"" + code + "\","
+ year + "," + period + ")";
logger.debug(formulaExpression);
year = getYear(year);
Integer yearOffset = 0;
period = FormulaHelper.getPeriod(period, yearOffset, formulaContext);
String orgId = formulaContext.getOrganizationId();
year = year + yearOffset;
List<ReportCellDataSourceDto> dataSource = Lists.newArrayList();
if(type == 0){
EnterpriseAccountSetOrgExample example = new EnterpriseAccountSetOrgExample();
example.createCriteria().andEffectiveDateLessThanOrEqualTo(DateUtils.getNow()).andExpiredDateGreaterThanOrEqualTo(DateUtils.getNow()).andOrganizationIdEqualTo(orgId);
List<EnterpriseAccountSetOrg> enterpriseAccountSetOrgs = SpringContextUtil.enterpriseAccountSetOrgMapper.selectByExample(example);
if(CollectionUtils.isEmpty(enterpriseAccountSetOrgs)){
return NumberEval.ZERO;
}
AccountMappingExample accountMappingExample = new AccountMappingExample();
accountMappingExample.createCriteria().andOrganizationIdEqualTo(orgId).andEnterpriseAccountSetIdEqualTo(enterpriseAccountSetOrgs.get(0).getEnterpriseAccountSetId());
List<AccountMapping> accountMappings = SpringContextUtil.accountMappingMapper.selectByExample(accountMappingExample);
double result = 0;
for(AccountMapping a : accountMappings){
result += count(a.getEnterpriseAccountCode(), dataSource, period, year);
}
Long dataSoureId = saveDataSource(ec, Collections.singletonList(dataSource),
FormulaDataSourceDetailType.FormulaDataSourceDto,
new BigDecimal(result), period, formulaContext.getReportTemplateGroupId(), formulaContext.getProjectId());
saveFormulaBlock(period, ec, formulaExpression, new BigDecimal(result), dataSoureId, formulaContext.getProjectId());
return new NumberEval(result);
} else if(type == 1){
double result = count(code, dataSource, period, year);
Long dataSoureId = saveDataSource(ec, Collections.singletonList(dataSource),
FormulaDataSourceDetailType.FormulaDataSourceDto,
new BigDecimal(result), period, formulaContext.getReportTemplateGroupId(), formulaContext.getProjectId());
saveFormulaBlock(period, ec, formulaExpression, new BigDecimal(result), dataSoureId, formulaContext.getProjectId());
return new NumberEval(result);
}
return NumberEval.ZERO;
}
private String periodName(int period, int year){
return year + "-" + (period > 9 ? period : ("0" + period));
}
private double count(String code, List<ReportCellDataSourceDto> contain, int period, int year){
GlBalanceExample glBalanceExample = new GlBalanceExample();
GlBalanceExample.Criteria c1 = glBalanceExample.createCriteria().andSegment3EqualTo(code).andPeriodNameEqualTo(periodName(period, year));
GlBalanceExample.Criteria c2 = glBalanceExample.createCriteria().andSegment4EqualTo(code).andPeriodNameEqualTo(periodName(period, year));
glBalanceExample.or(c2);
List<GlBalance> list = SpringContextUtil.glBalanceMapper.selectByExample(glBalanceExample);
if(CollectionUtils.isEmpty(list)){
return 0.0;
}
List<GlBalance> temp = list.stream().filter(x -> code.equalsIgnoreCase(x.getSegment3())).collect(Collectors.toList());
if(CollectionUtils.isEmpty(temp)){
temp = list;
}
for(GlBalance glBalance : temp){
ReportCellDataSourceDto dto = new ReportCellDataSourceDto();
dto.setAmount(glBalance.getPtdDr());
dto.setPeriod(period);
dto.setIsOnlyManualInput(Boolean.FALSE);
dto.setName(Constant.DataSourceName.ReportDataSource);
contain.add(dto);
}
return temp.stream().mapToDouble(a -> a.getPtdDr().doubleValue()).sum();
}
}
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