|
@@ -1,373 +1,385 @@
|
|
-package com.enteprise.benefit_monitor_assess.service.impl;
|
|
|
|
-
|
|
|
|
-import com.enteprise.benefit_monitor_assess.domain.AvgBenefit;
|
|
|
|
-import com.enteprise.benefit_monitor_assess.domain.BenefitMonitorAssess;
|
|
|
|
-import com.enteprise.benefit_monitor_assess.domain.IndustrySummary;
|
|
|
|
-import com.enteprise.benefit_monitor_assess.service.IBusinessMonitorAssessService;
|
|
|
|
-import com.enteprise.industry_run.domain.EnterpriseBaseDataTotal;
|
|
|
|
-import com.enteprise.industry_run.service.IEnterpriseBaseDataTotalService;
|
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
|
-
|
|
|
|
-import java.util.*;
|
|
|
|
-import java.util.logging.Level;
|
|
|
|
-import java.util.logging.Logger;
|
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
-
|
|
|
|
-@Service
|
|
|
|
-public class BusinessMonitorAssessService implements IBusinessMonitorAssessService {
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- IEnterpriseBaseDataTotalService service;
|
|
|
|
-
|
|
|
|
- private static final Logger LOGGER = Logger.getLogger(BusinessMonitorAssessService.class.getName());
|
|
|
|
- @Override
|
|
|
|
- public List<BenefitMonitorAssess> getListByBusinessMonitorAssess(BenefitMonitorAssess businessMonitorAssess) {
|
|
|
|
- List<BenefitMonitorAssess> list = new ArrayList<>();
|
|
|
|
- EnterpriseBaseDataTotal dataTotal = new EnterpriseBaseDataTotal();
|
|
|
|
- List<EnterpriseBaseDataTotal> currentDataTotal = new ArrayList<>();
|
|
|
|
- List<EnterpriseBaseDataTotal> previousDataTotal = new ArrayList<>();
|
|
|
|
- String year = businessMonitorAssess.getYear();
|
|
|
|
- String season = businessMonitorAssess.getSeason();
|
|
|
|
- String code = businessMonitorAssess.getCode();
|
|
|
|
- String enterpriseName = businessMonitorAssess.getEnterpriseName();
|
|
|
|
- //若有企业、行业过滤直接赋值进行筛选
|
|
|
|
- if (code != null && !code.isEmpty()) {
|
|
|
|
- dataTotal.setCode(code);
|
|
|
|
- }
|
|
|
|
- if (enterpriseName != null && !enterpriseName.isEmpty()) {
|
|
|
|
- dataTotal.setEnterpriseName(enterpriseName);
|
|
|
|
- }
|
|
|
|
- //if趋势分析,获取上一个季度的工业产值、电力消耗、实缴税金、本季度实缴税金
|
|
|
|
- if (year !=null && !year.isEmpty()) {
|
|
|
|
- //精确到年份
|
|
|
|
- if (season != null && !season.isEmpty()) {
|
|
|
|
- //精确到季度
|
|
|
|
- setDataWithYearAndSeason(year, season, dataTotal);
|
|
|
|
- currentDataTotal = service.selectEnterpriseBaseDataTotalList(dataTotal);
|
|
|
|
- getPreviousQuarter(businessMonitorAssess, dataTotal);
|
|
|
|
- previousDataTotal = service.selectEnterpriseBaseDataTotalList(dataTotal);
|
|
|
|
- //判断分析方式
|
|
|
|
- if (businessMonitorAssess.getMode().equals("trendAnalysis")) {
|
|
|
|
- compareTrendAnalysis(currentDataTotal, previousDataTotal, list);
|
|
|
|
- } else if (businessMonitorAssess.getMode().equals("avgAnalysis")) {
|
|
|
|
- compareAvgAnalysis(previousDataTotal, list, year, season);
|
|
|
|
- }
|
|
|
|
- return list;
|
|
|
|
- }
|
|
|
|
- // 无季度值,根据当前日期获取当前季度
|
|
|
|
- Calendar now = Calendar.getInstance();
|
|
|
|
- int currentMonth = now.get(Calendar.MONTH) + 1; // 月份从0开始,所以加1
|
|
|
|
- int currentQuarter = (currentMonth - 1) / 3 + 1; // 计算当前季度
|
|
|
|
- for (int i = currentQuarter; i > 0; i--) {
|
|
|
|
- dataTotal.setYear(year);
|
|
|
|
- dataTotal.setSeason(String.valueOf(i));
|
|
|
|
- currentDataTotal = service.selectEnterpriseBaseDataTotalList(dataTotal);
|
|
|
|
- if (i==1){
|
|
|
|
- //第一季度特殊处理
|
|
|
|
- int _year = Integer.parseInt(year) - 1;
|
|
|
|
- dataTotal.setYear(String.valueOf(_year));
|
|
|
|
- dataTotal.setSeason("4");
|
|
|
|
- }else {
|
|
|
|
- dataTotal.setSeason(String.valueOf(i - 1));
|
|
|
|
- }
|
|
|
|
- previousDataTotal = service.selectEnterpriseBaseDataTotalList(dataTotal);
|
|
|
|
- //判断分析方式
|
|
|
|
- if (businessMonitorAssess.getMode().equals("trendAnalysis")) {
|
|
|
|
- compareTrendAnalysis(currentDataTotal, previousDataTotal, list);
|
|
|
|
- } else if (businessMonitorAssess.getMode().equals("avgAnalysis")) {
|
|
|
|
- compareAvgAnalysis(previousDataTotal, list, year, String.valueOf(i));
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return list;
|
|
|
|
- }
|
|
|
|
- return list;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- public static void setDataWithYearAndSeason(String year, String season, EnterpriseBaseDataTotal dataTotal){
|
|
|
|
- dataTotal.setSeason(season);
|
|
|
|
- dataTotal.setYear(year);
|
|
|
|
- }
|
|
|
|
- /**
|
|
|
|
- * 计算某年某月的上一季度
|
|
|
|
- * @param assess
|
|
|
|
- * @param dataTotal
|
|
|
|
- */
|
|
|
|
- public static void getPreviousQuarter(BenefitMonitorAssess assess, EnterpriseBaseDataTotal dataTotal) {
|
|
|
|
- int year = Integer.parseInt(assess.getYear()); // 将字符串转换为整数
|
|
|
|
- int season = Integer.parseInt(assess.getSeason()); // 将字符串转换为整数
|
|
|
|
- if (season == 1) {
|
|
|
|
- dataTotal.setYear(String.valueOf(year - 1)); // 如果是第一季度,返回上一年第四季度
|
|
|
|
- } else {
|
|
|
|
- dataTotal.setSeason(String.valueOf(season - 1)); // 否则返回当前年份,季度减一
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 对比数据--趋势分析
|
|
|
|
- * @param currentQuarterList 当前季度数据
|
|
|
|
- * @param previousQuarterList 上季度数据
|
|
|
|
- */
|
|
|
|
- public static void compareTrendAnalysis(List<EnterpriseBaseDataTotal> currentQuarterList, List<EnterpriseBaseDataTotal> previousQuarterList, List<BenefitMonitorAssess> list) {
|
|
|
|
- // 使用 HashMap 缓存上个季度的数据,根据企业 ID 快速查找
|
|
|
|
- Map<String, List<EnterpriseBaseDataTotal>> previousDataMap = new HashMap<>();
|
|
|
|
-
|
|
|
|
- for (EnterpriseBaseDataTotal data : previousQuarterList) {
|
|
|
|
- previousDataMap.computeIfAbsent(data.getEnterpriseName(), k -> new ArrayList<>()).add(data); // 按企业 ID 存储
|
|
|
|
- }
|
|
|
|
- //当前企业
|
|
|
|
- String enterpriseName = "";
|
|
|
|
- // 遍历当前季度数据,进行比较
|
|
|
|
- for (EnterpriseBaseDataTotal currentData : currentQuarterList) {
|
|
|
|
- //判断是否已经对比过该企业
|
|
|
|
- if (enterpriseName.isEmpty() || !enterpriseName.equals(currentData.getEnterpriseName())) {
|
|
|
|
- enterpriseName = currentData.getEnterpriseName();
|
|
|
|
- List<EnterpriseBaseDataTotal> previousDataList = previousDataMap.get(enterpriseName); // 获取对应的上个季度数据
|
|
|
|
- if (previousDataList != null) { // 检查上一季度是否存在数据
|
|
|
|
- //设置对比旗子
|
|
|
|
- //List<Boolean> taxChangeTrend = new ArrayList<>();
|
|
|
|
- List<Boolean> powerChangeTrend = new ArrayList<>();
|
|
|
|
- List<Boolean> outputChangeTrend = new ArrayList<>();
|
|
|
|
- //初始化第一个月数据
|
|
|
|
- EnterpriseBaseDataTotal previousFirstData = previousDataList.get(0);
|
|
|
|
- double previousTotalOutput = previousFirstData.getTotalIndustrialValue();
|
|
|
|
- double previousPower = previousFirstData.getPowerConsume();
|
|
|
|
- //long previousTax = previousDataList.get(0).getPaidTax();
|
|
|
|
- //初始化两个季度的实缴税金总额
|
|
|
|
- double currentQuarterTaxSum = 0L;
|
|
|
|
- double currentQuarterIncomeSum = 0L;
|
|
|
|
- double previousQuarterTaxSum = previousFirstData.getPaidTax();
|
|
|
|
- double previousQuarterIncomeSum = previousFirstData.getTaxableIncome();
|
|
|
|
-
|
|
|
|
- for (int i = 1; i < previousDataList.size(); i++) {
|
|
|
|
- double currentOutput = previousDataList.get(i).getTotalIndustrialValue();
|
|
|
|
- double currentPower = previousDataList.get(i).getPowerConsume();
|
|
|
|
- //累加上季度实缴税金
|
|
|
|
- double currentTax = previousDataList.get(i).getPaidTax();
|
|
|
|
- double currentIncome = previousDataList.get(i).getTaxableIncome();
|
|
|
|
- previousQuarterTaxSum += currentTax;
|
|
|
|
- previousQuarterIncomeSum += currentIncome;
|
|
|
|
- // 记录变化趋势
|
|
|
|
- //taxChangeTrend.add(currentTax > previousTax);
|
|
|
|
- powerChangeTrend.add(currentPower > previousPower);
|
|
|
|
- outputChangeTrend.add(currentOutput > previousTotalOutput);
|
|
|
|
- //更新为下个月数据
|
|
|
|
- previousTotalOutput = currentOutput;
|
|
|
|
- previousPower = currentPower;
|
|
|
|
- //previousTax = currentTax;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // 计算当前季度交税值总和
|
|
|
|
- for (EnterpriseBaseDataTotal current : currentQuarterList) {
|
|
|
|
- if (current.getEnterpriseName().equals(currentData.getEnterpriseName())) {
|
|
|
|
- currentQuarterTaxSum += current.getPaidTax(); // 累加交税值
|
|
|
|
- currentQuarterIncomeSum += current.getTaxableIncome(); //累加应付值
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- //创建实体类
|
|
|
|
- BenefitMonitorAssess assess = new BenefitMonitorAssess();
|
|
|
|
- assess.setYear(currentData.getYear());
|
|
|
|
- assess.setSeason(currentData.getSeason());
|
|
|
|
- assess.setEnterpriseName(enterpriseName);
|
|
|
|
- assess.setCode(currentData.getCode());
|
|
|
|
- // 当前季度和上个季度交税值比较并填充返回的list(指标解耦)
|
|
|
|
- if (currentQuarterTaxSum > previousQuarterTaxSum) {
|
|
|
|
- //交税大于上季度
|
|
|
|
- if (determineTrend(outputChangeTrend).equals("0") && determineTrend(powerChangeTrend).equals("0")) {
|
|
|
|
- assess.setTrendAnalysis("连续近三个月,工业产值持续升高、电力消耗持续升高、本季度实缴税金相较上一季度升高");
|
|
|
|
- assess.setOperationalEvaluate("企业订单增加,市场份额提升,对地区经济发展的贡献度提高");
|
|
|
|
- list.add(assess);
|
|
|
|
- }else if (determineTrend(outputChangeTrend).equals("0") && determineTrend(powerChangeTrend).equals("1")) {
|
|
|
|
- assess.setTrendAnalysis("连续近三个月,工业产值持续升高、电力消耗持续下降、本季度实缴税金相较上一季度升高");
|
|
|
|
- assess.setOperationalEvaluate("企业订单增加,市场份额提升,对地区行业和经济发展的贡献度提高,可能存在技术或设备更新");
|
|
|
|
- list.add(assess);
|
|
|
|
- } else if (determineTrend(outputChangeTrend).equals("1") && determineTrend(powerChangeTrend).equals("0")) {
|
|
|
|
- assess.setTrendAnalysis("连续近三个月,工业产值持续下降、电力消耗持续升高、本季度实缴税金相较上一季度升高");
|
|
|
|
- assess.setOperationalEvaluate("企业上报数据可能存在错误,企业生产经营情况可能存在异常");
|
|
|
|
- list.add(assess);
|
|
|
|
- } else if (determineTrend(outputChangeTrend).equals("1") && determineTrend(powerChangeTrend).equals("1")) {
|
|
|
|
- assess.setTrendAnalysis("连续近三个月,工业产值持续下降、电力消耗持续下降、本季度实缴税金相较上一季度升高");
|
|
|
|
- assess.setOperationalEvaluate("企业上报数据可能存在错误,企业生产经营情况可能存在异常");
|
|
|
|
- list.add(assess);
|
|
|
|
- } else if (determineTrend(outputChangeTrend).equals("2") || determineTrend(powerChangeTrend).equals("2")) {
|
|
|
|
- //(月度数据波动情况下)
|
|
|
|
- if (currentQuarterIncomeSum > previousQuarterIncomeSum){
|
|
|
|
- //应付大于上季度
|
|
|
|
- assess.setTrendAnalysis("连续三个月,工业产值和电力消耗存在小幅波动、本季度应税收入和实缴税金相较上一季度均升高");
|
|
|
|
- assess.setOperationalEvaluate("企业生产经营情况良好");
|
|
|
|
- list.add(assess);
|
|
|
|
- }else {
|
|
|
|
- //应付小于上季度
|
|
|
|
- assess.setTrendAnalysis("连续三个月,工业产值和电力消耗存在小幅波动、本季度应税收入相较上一季度下降,实缴税金相较上一季度升高");
|
|
|
|
- assess.setOperationalEvaluate("企业生产经营情况可能存在异常");
|
|
|
|
- list.add(assess);
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- LOGGER.log(Level.WARNING, "企业名称: {0} - 对比数据出错", currentData.getEnterpriseName());
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- //交税小于上季度
|
|
|
|
- if (determineTrend(outputChangeTrend).equals("0") && determineTrend(powerChangeTrend).equals("0")) {
|
|
|
|
- assess.setTrendAnalysis("连续近三个月,工业产值持续升高、电力消耗持续升高、本季度实缴税金相较上一季度下降");
|
|
|
|
- assess.setOperationalEvaluate("企业订单增加,市场份额提升,可能存在退税、政策扶持或缴税异常");
|
|
|
|
- list.add(assess);
|
|
|
|
- }else if (determineTrend(outputChangeTrend).equals("0") && determineTrend(powerChangeTrend).equals("1")) {
|
|
|
|
- assess.setTrendAnalysis("连续近三个月,工业产值持续升高、电力消耗持续下降、本季度实缴税金相较上一季度下降");
|
|
|
|
- assess.setOperationalEvaluate("企业订单增加,市场份额提升,可能存在退税、政策扶持或缴税异常,可能存在技术或设备更新");
|
|
|
|
- list.add(assess);
|
|
|
|
- } else if (determineTrend(outputChangeTrend).equals("1") && determineTrend(powerChangeTrend).equals("0")) {
|
|
|
|
- assess.setTrendAnalysis("连续近三个月,工业产值持续下降、电力消耗持续升高、本季度实缴税金相较上一季度下降");
|
|
|
|
- assess.setOperationalEvaluate("企业生产经营情况可能存在异常");
|
|
|
|
- list.add(assess);
|
|
|
|
- } else if (determineTrend(outputChangeTrend).equals("1") && determineTrend(powerChangeTrend).equals("1")) {
|
|
|
|
- assess.setTrendAnalysis("连续近三个月,工业产值持续下降、电力消耗持续下降、本季度实缴税金相较上一季度下降");
|
|
|
|
- assess.setOperationalEvaluate("企业订单减少,市场份额萎缩,企业生产经营情况可能存在异常");
|
|
|
|
- list.add(assess);
|
|
|
|
- }else if (determineTrend(outputChangeTrend).equals("2") || determineTrend(powerChangeTrend).equals("2")) {
|
|
|
|
- //(月度数据波动情况下)
|
|
|
|
- if (currentQuarterIncomeSum > previousQuarterIncomeSum){
|
|
|
|
- //应付大于上季度
|
|
|
|
- assess.setTrendAnalysis("连续三个月,工业产值和电力消耗存在小幅波动、本季度应税收入相较上一季度升高,实缴税金相较上一季度下降");
|
|
|
|
- assess.setOperationalEvaluate("企业生产经营情况良好,可能存在退税、政策扶持或缴税异常");
|
|
|
|
- list.add(assess);
|
|
|
|
- }else {
|
|
|
|
- //应付小于上季度
|
|
|
|
- assess.setTrendAnalysis("连续三个月,工业产值和电力消耗存在小幅波动、本季度应税收入和实缴税金相较上一季度均下降");
|
|
|
|
- assess.setOperationalEvaluate("企业生产经营情况一般");
|
|
|
|
- list.add(assess);
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- LOGGER.log(Level.WARNING, "企业名称: {0} - 对比数据出错", currentData.getEnterpriseName());
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- } else {
|
|
|
|
- LOGGER.log(Level.WARNING, "企业名称: {0} - 上个季度无数据", currentData.getEnterpriseName());
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 季度对比
|
|
|
|
- * @param trends
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- private static String determineTrend(List<Boolean> trends) {
|
|
|
|
- boolean allIncreasing = true;
|
|
|
|
- boolean allDecreasing = true;
|
|
|
|
-
|
|
|
|
- for (Boolean trend : trends) {
|
|
|
|
- if (!trend) {
|
|
|
|
- allIncreasing = false;
|
|
|
|
- }
|
|
|
|
- if (trend) {
|
|
|
|
- allDecreasing = false;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (allIncreasing) {
|
|
|
|
- //递增
|
|
|
|
- return "0";
|
|
|
|
- } else if (allDecreasing) {
|
|
|
|
- //递减
|
|
|
|
- return "1";
|
|
|
|
- } else {
|
|
|
|
- //波动
|
|
|
|
- return "2"; // 有增有减
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 平均水平对比
|
|
|
|
- * @param previousQuarterList 上季度数据
|
|
|
|
- * @param list 返回的结果list
|
|
|
|
- */
|
|
|
|
- public static void compareAvgAnalysis(List<EnterpriseBaseDataTotal> previousQuarterList, List<BenefitMonitorAssess> list, String year, String season){
|
|
|
|
- String enterpriseName = "";
|
|
|
|
- Double industrialValueSum = 0.0;
|
|
|
|
- Double paidTaxSum = 0.0;
|
|
|
|
- int i = 1;
|
|
|
|
- List<AvgBenefit> benefits = new ArrayList<>();
|
|
|
|
- //统计多个或一个企业的近三个月总产值和交税总值
|
|
|
|
- for (EnterpriseBaseDataTotal item : previousQuarterList){
|
|
|
|
- if (!enterpriseName.equals(item.getEnterpriseName())){
|
|
|
|
- //当企业不相同或者第一次为空,初始化统计数
|
|
|
|
- if (!enterpriseName.isEmpty()){
|
|
|
|
- //非空即已统计完毕一个企业
|
|
|
|
- AvgBenefit benefit = new AvgBenefit();
|
|
|
|
- benefit.setEnterpriseName(enterpriseName);
|
|
|
|
- benefit.setCode(item.getCode());
|
|
|
|
- benefit.setIndustrialValueAvg(industrialValueSum / i);
|
|
|
|
- benefit.setPaidTaxAvg(paidTaxSum / i);
|
|
|
|
- benefits.add(benefit);
|
|
|
|
- }
|
|
|
|
- enterpriseName = item.getEnterpriseName();
|
|
|
|
- industrialValueSum = item.getTotalIndustrialValue();
|
|
|
|
- paidTaxSum = item.getPaidTax();
|
|
|
|
- i = 1;
|
|
|
|
- }else {
|
|
|
|
- //企业相同直接相加
|
|
|
|
- industrialValueSum += item.getTotalIndustrialValue();
|
|
|
|
- paidTaxSum += item.getPaidTax();
|
|
|
|
- i += 1;
|
|
|
|
- if (i == previousQuarterList.size() ){
|
|
|
|
- //单企业统计到尽头,即已统计完毕一个企业
|
|
|
|
- AvgBenefit benefit = new AvgBenefit();
|
|
|
|
- benefit.setEnterpriseName(enterpriseName);
|
|
|
|
- benefit.setCode(item.getCode());
|
|
|
|
- benefit.setIndustrialValueAvg(industrialValueSum / i);
|
|
|
|
- benefit.setPaidTaxAvg(paidTaxSum / i);
|
|
|
|
- benefits.add(benefit);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- Map<String, IndustrySummary> industrySummaryMap = previousQuarterList.stream()
|
|
|
|
- .collect(Collectors.groupingBy(
|
|
|
|
- EnterpriseBaseDataTotal::getCode,
|
|
|
|
- Collectors.collectingAndThen(
|
|
|
|
- Collectors.toList(),
|
|
|
|
- enterpriseBaseData -> {
|
|
|
|
- double totalIndustrialValue = enterpriseBaseData.stream()
|
|
|
|
- .mapToDouble(EnterpriseBaseDataTotal::getTotalIndustrialValue)
|
|
|
|
- .sum();
|
|
|
|
- double totalPaidTax = enterpriseBaseData.stream()
|
|
|
|
- .mapToDouble(EnterpriseBaseDataTotal::getPaidTax)
|
|
|
|
- .sum();
|
|
|
|
- int uniqueEnterpriseCount = (int) enterpriseBaseData.stream()
|
|
|
|
- .map(EnterpriseBaseDataTotal::getEnterpriseName)
|
|
|
|
- .distinct()
|
|
|
|
- .count();
|
|
|
|
-
|
|
|
|
- return new IndustrySummary(totalIndustrialValue, totalPaidTax, uniqueEnterpriseCount);
|
|
|
|
- }
|
|
|
|
- )
|
|
|
|
- ));
|
|
|
|
- for (AvgBenefit item : benefits){
|
|
|
|
- BenefitMonitorAssess assess = new BenefitMonitorAssess();
|
|
|
|
- assess.setEnterpriseName(item.getEnterpriseName());
|
|
|
|
- assess.setCode(item.getCode());
|
|
|
|
- assess.setYear(year);
|
|
|
|
- assess.setSeason(season);
|
|
|
|
- //开始平均水平分析
|
|
|
|
- IndustrySummary industrySummary = industrySummaryMap.get(item.getCode());
|
|
|
|
- if (item.getIndustrialValueAvg() < industrySummary.getIndustrialValueSum() / industrySummary.getEnterpriseNumber() && item.getPaidTaxAvg() < industrySummary.getPaidTaxSum() / industrySummary.getEnterpriseNumber()){
|
|
|
|
- assess.setAvgAnalysis("近三个月工业总产值低于行业平均水平,且本季度实缴税金低于行业平均水平");
|
|
|
|
- assess.setOperationalEvaluate("企业生产经营状况一般,行业竞争力较弱");
|
|
|
|
- }else if (item.getIndustrialValueAvg() > industrySummary.getIndustrialValueSum() / industrySummary.getEnterpriseNumber() && item.getPaidTaxAvg() > industrySummary.getPaidTaxSum() / industrySummary.getEnterpriseNumber()){
|
|
|
|
- assess.setAvgAnalysis("近三个月工业总产值高于行业平均水平,且本季度实缴税金高于行业平均水平");
|
|
|
|
- assess.setOperationalEvaluate("企业生产经营状况良好,具备行业竞争力");
|
|
|
|
- }else if (item.getIndustrialValueAvg() < industrySummary.getIndustrialValueSum() / industrySummary.getEnterpriseNumber() && item.getPaidTaxAvg() > industrySummary.getPaidTaxSum() / industrySummary.getEnterpriseNumber()){
|
|
|
|
- assess.setAvgAnalysis("近三个月工业总产值低于行业平均水平,且本季度实缴税金高于行业平均水平");
|
|
|
|
- assess.setOperationalEvaluate("企业上报数据可能存在错误,企业生产经营情况可能存在异常");
|
|
|
|
- }else if (item.getIndustrialValueAvg() > industrySummary.getIndustrialValueSum() / industrySummary.getEnterpriseNumber() && item.getPaidTaxAvg() < industrySummary.getPaidTaxSum() / industrySummary.getEnterpriseNumber()){
|
|
|
|
- assess.setAvgAnalysis("近三个月工业总产值高于行业平均水平,且本季度实缴税金低于行业平均水平");
|
|
|
|
- assess.setOperationalEvaluate("企业生产经营状况一般,行业竞争力良好,可能存在退税、政策扶持或缴税异常等情况");
|
|
|
|
- }else {
|
|
|
|
- LOGGER.log(Level.WARNING, "企业名称: {0} - 上个季度无数据或任一数据没有变化", item.getEnterpriseName());
|
|
|
|
- }
|
|
|
|
- list.add(assess);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
|
|
+package com.enteprise.benefit_monitor_assess.service.impl;
|
|
|
|
+
|
|
|
|
+import com.enteprise.benefit_monitor_assess.domain.AvgBenefit;
|
|
|
|
+import com.enteprise.benefit_monitor_assess.domain.BenefitMonitorAssess;
|
|
|
|
+import com.enteprise.benefit_monitor_assess.domain.IndustrySummary;
|
|
|
|
+import com.enteprise.benefit_monitor_assess.service.IBusinessMonitorAssessService;
|
|
|
|
+import com.enteprise.industry_run.domain.EnterpriseBaseDataTotal;
|
|
|
|
+import com.enteprise.industry_run.service.IEnterpriseBaseDataTotalService;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+
|
|
|
|
+import java.util.*;
|
|
|
|
+import java.util.logging.Level;
|
|
|
|
+import java.util.logging.Logger;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
+
|
|
|
|
+@Service
|
|
|
|
+public class BusinessMonitorAssessService implements IBusinessMonitorAssessService {
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ IEnterpriseBaseDataTotalService service;
|
|
|
|
+
|
|
|
|
+ private static final Logger LOGGER = Logger.getLogger(BusinessMonitorAssessService.class.getName());
|
|
|
|
+ @Override
|
|
|
|
+ public List<BenefitMonitorAssess> getListByBusinessMonitorAssess(BenefitMonitorAssess businessMonitorAssess) {
|
|
|
|
+ List<BenefitMonitorAssess> list = new ArrayList<>();
|
|
|
|
+ EnterpriseBaseDataTotal dataTotal = new EnterpriseBaseDataTotal();
|
|
|
|
+ //用于获取行业总体的值来求平均
|
|
|
|
+ EnterpriseBaseDataTotal _dataTotal = new EnterpriseBaseDataTotal();
|
|
|
|
+ List<EnterpriseBaseDataTotal> currentDataTotal = new ArrayList<>();
|
|
|
|
+ List<EnterpriseBaseDataTotal> previousDataTotal = new ArrayList<>();
|
|
|
|
+ List<EnterpriseBaseDataTotal> _previousDataTotal = new ArrayList<>();
|
|
|
|
+ String year = businessMonitorAssess.getYear();
|
|
|
|
+ String season = businessMonitorAssess.getSeason();
|
|
|
|
+ String code = businessMonitorAssess.getCode();
|
|
|
|
+ String enterpriseName = businessMonitorAssess.getEnterpriseName();
|
|
|
|
+ //若有企业、行业过滤直接赋值进行筛选
|
|
|
|
+ if (code != null && !code.isEmpty()) {
|
|
|
|
+ dataTotal.setCode(code);
|
|
|
|
+ _dataTotal.setCode(code);
|
|
|
|
+ }
|
|
|
|
+ if (enterpriseName != null && !enterpriseName.isEmpty()) {
|
|
|
|
+ dataTotal.setEnterpriseName(enterpriseName);
|
|
|
|
+ }
|
|
|
|
+ //if趋势分析,获取上一个季度的工业产值、电力消耗、实缴税金、本季度实缴税金
|
|
|
|
+ if (year !=null && !year.isEmpty()) {
|
|
|
|
+ //精确到年份
|
|
|
|
+ if (season != null && !season.isEmpty()) {
|
|
|
|
+ //精确到季度
|
|
|
|
+ setDataWithYearAndSeason(year, season, dataTotal);
|
|
|
|
+ currentDataTotal = service.selectEnterpriseBaseDataTotalList(dataTotal);
|
|
|
|
+ getPreviousQuarter(businessMonitorAssess, dataTotal);
|
|
|
|
+ previousDataTotal = service.selectEnterpriseBaseDataTotalList(dataTotal);
|
|
|
|
+ _previousDataTotal = service.selectEnterpriseBaseDataTotalList(_dataTotal);
|
|
|
|
+ //判断分析方式
|
|
|
|
+ if (businessMonitorAssess.getMode().equals("trendAnalysis")) {
|
|
|
|
+ compareTrendAnalysis(currentDataTotal, previousDataTotal, list);
|
|
|
|
+ } else if (businessMonitorAssess.getMode().equals("avgAnalysis")) {
|
|
|
|
+ compareAvgAnalysis(previousDataTotal, _previousDataTotal, list, year, season);
|
|
|
|
+ }
|
|
|
|
+ return list;
|
|
|
|
+ }
|
|
|
|
+ // 无季度值,根据当前日期获取当前季度
|
|
|
|
+ Calendar now = Calendar.getInstance();
|
|
|
|
+ int currentMonth = now.get(Calendar.MONTH) + 1; // 月份从0开始,所以加1
|
|
|
|
+ int currentQuarter = (currentMonth - 1) / 3 + 1; // 计算当前季度
|
|
|
|
+ for (int i = currentQuarter; i > 0; i--) {
|
|
|
|
+ dataTotal.setYear(year);
|
|
|
|
+ dataTotal.setSeason(String.valueOf(i));
|
|
|
|
+ _dataTotal.setYear(year);
|
|
|
|
+ _dataTotal.setSeason(String.valueOf(i));
|
|
|
|
+ currentDataTotal = service.selectEnterpriseBaseDataTotalList(dataTotal);
|
|
|
|
+ if (i==1){
|
|
|
|
+ //第一季度特殊处理
|
|
|
|
+ int _year = Integer.parseInt(year) - 1;
|
|
|
|
+ dataTotal.setYear(String.valueOf(_year));
|
|
|
|
+ dataTotal.setSeason("4");
|
|
|
|
+ _dataTotal.setYear(String.valueOf(_year));
|
|
|
|
+ _dataTotal.setSeason("4");
|
|
|
|
+ }else {
|
|
|
|
+ dataTotal.setSeason(String.valueOf(i - 1));
|
|
|
|
+ _dataTotal.setSeason(String.valueOf(i - 1));
|
|
|
|
+ }
|
|
|
|
+ previousDataTotal = service.selectEnterpriseBaseDataTotalList(dataTotal);
|
|
|
|
+ _previousDataTotal = service.selectEnterpriseBaseDataTotalList(_dataTotal);
|
|
|
|
+ //判断分析方式
|
|
|
|
+ if (businessMonitorAssess.getMode().equals("trendAnalysis")) {
|
|
|
|
+ compareTrendAnalysis(currentDataTotal, previousDataTotal, list);
|
|
|
|
+ } else if (businessMonitorAssess.getMode().equals("avgAnalysis")) {
|
|
|
|
+ compareAvgAnalysis(previousDataTotal, _previousDataTotal, list, year, String.valueOf(i));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return list;
|
|
|
|
+ }
|
|
|
|
+ return list;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ public static void setDataWithYearAndSeason(String year, String season, EnterpriseBaseDataTotal dataTotal){
|
|
|
|
+ dataTotal.setSeason(season);
|
|
|
|
+ dataTotal.setYear(year);
|
|
|
|
+ }
|
|
|
|
+ /**
|
|
|
|
+ * 计算某年某月的上一季度
|
|
|
|
+ * @param assess
|
|
|
|
+ * @param dataTotal
|
|
|
|
+ */
|
|
|
|
+ public static void getPreviousQuarter(BenefitMonitorAssess assess, EnterpriseBaseDataTotal dataTotal) {
|
|
|
|
+ int year = Integer.parseInt(assess.getYear()); // 将字符串转换为整数
|
|
|
|
+ int season = Integer.parseInt(assess.getSeason()); // 将字符串转换为整数
|
|
|
|
+ if (season == 1) {
|
|
|
|
+ dataTotal.setYear(String.valueOf(year - 1)); // 如果是第一季度,返回上一年第四季度
|
|
|
|
+ } else {
|
|
|
|
+ dataTotal.setSeason(String.valueOf(season - 1)); // 否则返回当前年份,季度减一
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 对比数据--趋势分析
|
|
|
|
+ * @param currentQuarterList 当前季度数据
|
|
|
|
+ * @param previousQuarterList 上季度数据
|
|
|
|
+ */
|
|
|
|
+ public static void compareTrendAnalysis(List<EnterpriseBaseDataTotal> currentQuarterList, List<EnterpriseBaseDataTotal> previousQuarterList, List<BenefitMonitorAssess> list) {
|
|
|
|
+ // 使用 HashMap 缓存上个季度的数据,根据企业 ID 快速查找
|
|
|
|
+ Map<String, List<EnterpriseBaseDataTotal>> previousDataMap = new HashMap<>();
|
|
|
|
+
|
|
|
|
+ for (EnterpriseBaseDataTotal data : previousQuarterList) {
|
|
|
|
+ previousDataMap.computeIfAbsent(data.getEnterpriseName(), k -> new ArrayList<>()).add(data); // 按企业 ID 存储
|
|
|
|
+ }
|
|
|
|
+ //当前企业
|
|
|
|
+ String enterpriseName = "";
|
|
|
|
+ // 遍历当前季度数据,进行比较
|
|
|
|
+ for (EnterpriseBaseDataTotal currentData : currentQuarterList) {
|
|
|
|
+ //判断是否已经对比过该企业
|
|
|
|
+ if (enterpriseName.isEmpty() || !enterpriseName.equals(currentData.getEnterpriseName())) {
|
|
|
|
+ enterpriseName = currentData.getEnterpriseName();
|
|
|
|
+ List<EnterpriseBaseDataTotal> previousDataList = previousDataMap.get(enterpriseName); // 获取对应的上个季度数据
|
|
|
|
+ if (previousDataList != null) { // 检查上一季度是否存在数据
|
|
|
|
+ //设置对比旗子
|
|
|
|
+ //List<Boolean> taxChangeTrend = new ArrayList<>();
|
|
|
|
+ List<Boolean> powerChangeTrend = new ArrayList<>();
|
|
|
|
+ List<Boolean> outputChangeTrend = new ArrayList<>();
|
|
|
|
+ //初始化第一个月数据
|
|
|
|
+ EnterpriseBaseDataTotal previousFirstData = previousDataList.get(0);
|
|
|
|
+ double previousTotalOutput = previousFirstData.getTotalIndustrialValue();
|
|
|
|
+ double previousPower = previousFirstData.getPowerConsume();
|
|
|
|
+ //long previousTax = previousDataList.get(0).getPaidTax();
|
|
|
|
+ //初始化两个季度的实缴税金总额
|
|
|
|
+ double currentQuarterTaxSum = 0L;
|
|
|
|
+ double currentQuarterIncomeSum = 0L;
|
|
|
|
+ double previousQuarterTaxSum = previousFirstData.getPaidTax();
|
|
|
|
+ double previousQuarterIncomeSum = previousFirstData.getTaxableIncome();
|
|
|
|
+
|
|
|
|
+ for (int i = 1; i < previousDataList.size(); i++) {
|
|
|
|
+ double currentOutput = previousDataList.get(i).getTotalIndustrialValue();
|
|
|
|
+ double currentPower = previousDataList.get(i).getPowerConsume();
|
|
|
|
+ //累加上季度实缴税金
|
|
|
|
+ double currentTax = previousDataList.get(i).getPaidTax();
|
|
|
|
+ double currentIncome = previousDataList.get(i).getTaxableIncome();
|
|
|
|
+ previousQuarterTaxSum += currentTax;
|
|
|
|
+ previousQuarterIncomeSum += currentIncome;
|
|
|
|
+ // 记录变化趋势
|
|
|
|
+ //taxChangeTrend.add(currentTax > previousTax);
|
|
|
|
+ powerChangeTrend.add(currentPower > previousPower);
|
|
|
|
+ outputChangeTrend.add(currentOutput > previousTotalOutput);
|
|
|
|
+ //更新为下个月数据
|
|
|
|
+ previousTotalOutput = currentOutput;
|
|
|
|
+ previousPower = currentPower;
|
|
|
|
+ //previousTax = currentTax;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 计算当前季度交税值总和
|
|
|
|
+ for (EnterpriseBaseDataTotal current : currentQuarterList) {
|
|
|
|
+ if (current.getEnterpriseName().equals(currentData.getEnterpriseName())) {
|
|
|
|
+ currentQuarterTaxSum += current.getPaidTax(); // 累加交税值
|
|
|
|
+ currentQuarterIncomeSum += current.getTaxableIncome(); //累加应付值
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //创建实体类
|
|
|
|
+ BenefitMonitorAssess assess = new BenefitMonitorAssess();
|
|
|
|
+ assess.setYear(currentData.getYear());
|
|
|
|
+ assess.setSeason(currentData.getSeason());
|
|
|
|
+ assess.setEnterpriseName(enterpriseName);
|
|
|
|
+ assess.setCode(currentData.getCode());
|
|
|
|
+ // 当前季度和上个季度交税值比较并填充返回的list(指标解耦)
|
|
|
|
+ if (currentQuarterTaxSum > previousQuarterTaxSum) {
|
|
|
|
+ //交税大于上季度
|
|
|
|
+ if (determineTrend(outputChangeTrend).equals("0") && determineTrend(powerChangeTrend).equals("0")) {
|
|
|
|
+ assess.setTrendAnalysis("连续近三个月,工业产值持续升高、电力消耗持续升高、本季度实缴税金相较上一季度升高");
|
|
|
|
+ assess.setOperationalEvaluate("企业订单增加,市场份额提升,对地区经济发展的贡献度提高");
|
|
|
|
+ list.add(assess);
|
|
|
|
+ }else if (determineTrend(outputChangeTrend).equals("0") && determineTrend(powerChangeTrend).equals("1")) {
|
|
|
|
+ assess.setTrendAnalysis("连续近三个月,工业产值持续升高、电力消耗持续下降、本季度实缴税金相较上一季度升高");
|
|
|
|
+ assess.setOperationalEvaluate("企业订单增加,市场份额提升,对地区行业和经济发展的贡献度提高,可能存在技术或设备更新");
|
|
|
|
+ list.add(assess);
|
|
|
|
+ } else if (determineTrend(outputChangeTrend).equals("1") && determineTrend(powerChangeTrend).equals("0")) {
|
|
|
|
+ assess.setTrendAnalysis("连续近三个月,工业产值持续下降、电力消耗持续升高、本季度实缴税金相较上一季度升高");
|
|
|
|
+ assess.setOperationalEvaluate("企业上报数据可能存在错误,企业生产经营情况可能存在异常");
|
|
|
|
+ list.add(assess);
|
|
|
|
+ } else if (determineTrend(outputChangeTrend).equals("1") && determineTrend(powerChangeTrend).equals("1")) {
|
|
|
|
+ assess.setTrendAnalysis("连续近三个月,工业产值持续下降、电力消耗持续下降、本季度实缴税金相较上一季度升高");
|
|
|
|
+ assess.setOperationalEvaluate("企业上报数据可能存在错误,企业生产经营情况可能存在异常");
|
|
|
|
+ list.add(assess);
|
|
|
|
+ } else if (determineTrend(outputChangeTrend).equals("2") || determineTrend(powerChangeTrend).equals("2")) {
|
|
|
|
+ //(月度数据波动情况下)
|
|
|
|
+ if (currentQuarterIncomeSum > previousQuarterIncomeSum){
|
|
|
|
+ //应付大于上季度
|
|
|
|
+ assess.setTrendAnalysis("连续三个月,工业产值和电力消耗存在小幅波动、本季度应税收入和实缴税金相较上一季度均升高");
|
|
|
|
+ assess.setOperationalEvaluate("企业生产经营情况良好");
|
|
|
|
+ list.add(assess);
|
|
|
|
+ }else {
|
|
|
|
+ //应付小于上季度
|
|
|
|
+ assess.setTrendAnalysis("连续三个月,工业产值和电力消耗存在小幅波动、本季度应税收入相较上一季度下降,实缴税金相较上一季度升高");
|
|
|
|
+ assess.setOperationalEvaluate("企业生产经营情况可能存在异常");
|
|
|
|
+ list.add(assess);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ LOGGER.log(Level.WARNING, "企业名称: {0} - 对比数据出错", currentData.getEnterpriseName());
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ //交税小于上季度
|
|
|
|
+ if (determineTrend(outputChangeTrend).equals("0") && determineTrend(powerChangeTrend).equals("0")) {
|
|
|
|
+ assess.setTrendAnalysis("连续近三个月,工业产值持续升高、电力消耗持续升高、本季度实缴税金相较上一季度下降");
|
|
|
|
+ assess.setOperationalEvaluate("企业订单增加,市场份额提升,可能存在退税、政策扶持或缴税异常");
|
|
|
|
+ list.add(assess);
|
|
|
|
+ }else if (determineTrend(outputChangeTrend).equals("0") && determineTrend(powerChangeTrend).equals("1")) {
|
|
|
|
+ assess.setTrendAnalysis("连续近三个月,工业产值持续升高、电力消耗持续下降、本季度实缴税金相较上一季度下降");
|
|
|
|
+ assess.setOperationalEvaluate("企业订单增加,市场份额提升,可能存在退税、政策扶持或缴税异常,可能存在技术或设备更新");
|
|
|
|
+ list.add(assess);
|
|
|
|
+ } else if (determineTrend(outputChangeTrend).equals("1") && determineTrend(powerChangeTrend).equals("0")) {
|
|
|
|
+ assess.setTrendAnalysis("连续近三个月,工业产值持续下降、电力消耗持续升高、本季度实缴税金相较上一季度下降");
|
|
|
|
+ assess.setOperationalEvaluate("企业生产经营情况可能存在异常");
|
|
|
|
+ list.add(assess);
|
|
|
|
+ } else if (determineTrend(outputChangeTrend).equals("1") && determineTrend(powerChangeTrend).equals("1")) {
|
|
|
|
+ assess.setTrendAnalysis("连续近三个月,工业产值持续下降、电力消耗持续下降、本季度实缴税金相较上一季度下降");
|
|
|
|
+ assess.setOperationalEvaluate("企业订单减少,市场份额萎缩,企业生产经营情况可能存在异常");
|
|
|
|
+ list.add(assess);
|
|
|
|
+ }else if (determineTrend(outputChangeTrend).equals("2") || determineTrend(powerChangeTrend).equals("2")) {
|
|
|
|
+ //(月度数据波动情况下)
|
|
|
|
+ if (currentQuarterIncomeSum > previousQuarterIncomeSum){
|
|
|
|
+ //应付大于上季度
|
|
|
|
+ assess.setTrendAnalysis("连续三个月,工业产值和电力消耗存在小幅波动、本季度应税收入相较上一季度升高,实缴税金相较上一季度下降");
|
|
|
|
+ assess.setOperationalEvaluate("企业生产经营情况良好,可能存在退税、政策扶持或缴税异常");
|
|
|
|
+ list.add(assess);
|
|
|
|
+ }else {
|
|
|
|
+ //应付小于上季度
|
|
|
|
+ assess.setTrendAnalysis("连续三个月,工业产值和电力消耗存在小幅波动、本季度应税收入和实缴税金相较上一季度均下降");
|
|
|
|
+ assess.setOperationalEvaluate("企业生产经营情况一般");
|
|
|
|
+ list.add(assess);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ LOGGER.log(Level.WARNING, "企业名称: {0} - 对比数据出错", currentData.getEnterpriseName());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ } else {
|
|
|
|
+ LOGGER.log(Level.WARNING, "企业名称: {0} - 上个季度无数据", currentData.getEnterpriseName());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 季度对比
|
|
|
|
+ * @param trends
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ private static String determineTrend(List<Boolean> trends) {
|
|
|
|
+ boolean allIncreasing = true;
|
|
|
|
+ boolean allDecreasing = true;
|
|
|
|
+
|
|
|
|
+ for (Boolean trend : trends) {
|
|
|
|
+ if (!trend) {
|
|
|
|
+ allIncreasing = false;
|
|
|
|
+ }
|
|
|
|
+ if (trend) {
|
|
|
|
+ allDecreasing = false;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (allIncreasing) {
|
|
|
|
+ //递增
|
|
|
|
+ return "0";
|
|
|
|
+ } else if (allDecreasing) {
|
|
|
|
+ //递减
|
|
|
|
+ return "1";
|
|
|
|
+ } else {
|
|
|
|
+ //波动
|
|
|
|
+ return "2"; // 有增有减
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 平均水平对比
|
|
|
|
+ * @param previousQuarterList 上季度数据
|
|
|
|
+ * @param list 返回的结果list
|
|
|
|
+ */
|
|
|
|
+ public static void compareAvgAnalysis(List<EnterpriseBaseDataTotal> previousQuarterList, List<EnterpriseBaseDataTotal> _previousQuarterList, List<BenefitMonitorAssess> list, String year, String season){
|
|
|
|
+ String enterpriseName = "";
|
|
|
|
+ Double industrialValueSum = 0.0;
|
|
|
|
+ Double paidTaxSum = 0.0;
|
|
|
|
+ int i = 1;
|
|
|
|
+ List<AvgBenefit> benefits = new ArrayList<>();
|
|
|
|
+ //统计多个或一个企业的近三个月总产值和交税总值
|
|
|
|
+ for (EnterpriseBaseDataTotal item : previousQuarterList){
|
|
|
|
+ if (!enterpriseName.equals(item.getEnterpriseName())){
|
|
|
|
+ //当企业不相同或者第一次为空,初始化统计数
|
|
|
|
+ if (!enterpriseName.isEmpty()){
|
|
|
|
+ //非空即已统计完毕一个企业
|
|
|
|
+ AvgBenefit benefit = new AvgBenefit();
|
|
|
|
+ benefit.setEnterpriseName(enterpriseName);
|
|
|
|
+ benefit.setCode(item.getCode());
|
|
|
|
+ benefit.setIndustrialValueAvg(industrialValueSum / i);
|
|
|
|
+ benefit.setPaidTaxAvg(paidTaxSum / i);
|
|
|
|
+ benefits.add(benefit);
|
|
|
|
+ }
|
|
|
|
+ enterpriseName = item.getEnterpriseName();
|
|
|
|
+ industrialValueSum = item.getTotalIndustrialValue();
|
|
|
|
+ paidTaxSum = item.getPaidTax();
|
|
|
|
+ i = 1;
|
|
|
|
+ }else {
|
|
|
|
+ //企业相同直接相加
|
|
|
|
+ industrialValueSum += item.getTotalIndustrialValue();
|
|
|
|
+ paidTaxSum += item.getPaidTax();
|
|
|
|
+ i += 1;
|
|
|
|
+ if (i == previousQuarterList.size() ){
|
|
|
|
+ //单企业统计到尽头,即已统计完毕一个企业
|
|
|
|
+ AvgBenefit benefit = new AvgBenefit();
|
|
|
|
+ benefit.setEnterpriseName(enterpriseName);
|
|
|
|
+ benefit.setCode(item.getCode());
|
|
|
|
+ benefit.setIndustrialValueAvg(industrialValueSum / i);
|
|
|
|
+ benefit.setPaidTaxAvg(paidTaxSum / i);
|
|
|
|
+ benefits.add(benefit);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ Map<String, IndustrySummary> industrySummaryMap = _previousQuarterList.stream()
|
|
|
|
+ .collect(Collectors.groupingBy(
|
|
|
|
+ EnterpriseBaseDataTotal::getCode,
|
|
|
|
+ Collectors.collectingAndThen(
|
|
|
|
+ Collectors.toList(),
|
|
|
|
+ enterpriseBaseData -> {
|
|
|
|
+ double totalIndustrialValue = enterpriseBaseData.stream()
|
|
|
|
+ .mapToDouble(EnterpriseBaseDataTotal::getTotalIndustrialValue)
|
|
|
|
+ .sum();
|
|
|
|
+ double totalPaidTax = enterpriseBaseData.stream()
|
|
|
|
+ .mapToDouble(EnterpriseBaseDataTotal::getPaidTax)
|
|
|
|
+ .sum();
|
|
|
|
+ int uniqueEnterpriseCount = (int) enterpriseBaseData.stream()
|
|
|
|
+ .map(EnterpriseBaseDataTotal::getEnterpriseName)
|
|
|
|
+ .count();
|
|
|
|
+
|
|
|
|
+ return new IndustrySummary(totalIndustrialValue, totalPaidTax, uniqueEnterpriseCount);
|
|
|
|
+ }
|
|
|
|
+ )
|
|
|
|
+ ));
|
|
|
|
+ for (AvgBenefit item : benefits){
|
|
|
|
+ BenefitMonitorAssess assess = new BenefitMonitorAssess();
|
|
|
|
+ assess.setEnterpriseName(item.getEnterpriseName());
|
|
|
|
+ assess.setCode(item.getCode());
|
|
|
|
+ assess.setYear(year);
|
|
|
|
+ assess.setSeason(season);
|
|
|
|
+ //开始平均水平分析
|
|
|
|
+ IndustrySummary industrySummary = industrySummaryMap.get(item.getCode());
|
|
|
|
+ double avgIndustrial = industrySummary.getIndustrialValueSum() / industrySummary.getEnterpriseNumber();
|
|
|
|
+ double avgPaidTax = industrySummary.getPaidTaxSum() / industrySummary.getEnterpriseNumber();
|
|
|
|
+ if (item.getIndustrialValueAvg() < avgIndustrial && item.getPaidTaxAvg() < avgPaidTax){
|
|
|
|
+ assess.setAvgAnalysis("近三个月工业总产值低于行业平均水平,且本季度实缴税金低于行业平均水平");
|
|
|
|
+ assess.setOperationalEvaluate("企业生产经营状况一般,行业竞争力较弱");
|
|
|
|
+ }else if (item.getIndustrialValueAvg() > avgIndustrial && item.getPaidTaxAvg() > avgPaidTax){
|
|
|
|
+ assess.setAvgAnalysis("近三个月工业总产值高于行业平均水平,且本季度实缴税金高于行业平均水平");
|
|
|
|
+ assess.setOperationalEvaluate("企业生产经营状况良好,具备行业竞争力");
|
|
|
|
+ }else if (item.getIndustrialValueAvg() < avgIndustrial && item.getPaidTaxAvg() > avgPaidTax){
|
|
|
|
+ assess.setAvgAnalysis("近三个月工业总产值低于行业平均水平,且本季度实缴税金高于行业平均水平");
|
|
|
|
+ assess.setOperationalEvaluate("企业上报数据可能存在错误,企业生产经营情况可能存在异常");
|
|
|
|
+ }else if (item.getIndustrialValueAvg() > avgIndustrial && item.getPaidTaxAvg() < avgPaidTax){
|
|
|
|
+ assess.setAvgAnalysis("近三个月工业总产值高于行业平均水平,且本季度实缴税金低于行业平均水平");
|
|
|
|
+ assess.setOperationalEvaluate("企业生产经营状况一般,行业竞争力良好,可能存在退税、政策扶持或缴税异常等情况");
|
|
|
|
+ }else {
|
|
|
|
+ LOGGER.log(Level.WARNING, "企业名称: {0} - 上个季度无数据或任一数据没有变化", item.getEnterpriseName());
|
|
|
|
+ }
|
|
|
|
+ list.add(assess);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|