diff --git a/lib/EmergencyService/zdxtLawEnforcementCodeService/src/main/java/com/zdxt/code/controller/StatisticalPanelController.java b/lib/EmergencyService/zdxtLawEnforcementCodeService/src/main/java/com/zdxt/code/controller/StatisticalPanelController.java index 99798586..300b070e 100644 --- a/lib/EmergencyService/zdxtLawEnforcementCodeService/src/main/java/com/zdxt/code/controller/StatisticalPanelController.java +++ b/lib/EmergencyService/zdxtLawEnforcementCodeService/src/main/java/com/zdxt/code/controller/StatisticalPanelController.java @@ -87,5 +87,23 @@ public class StatisticalPanelController extends BaseController { public ZDResponse complaint(StatisticsIndicatorPart statisticsIndicatorPart){ return ZDResponse.success("成功",statisticalPaneService.complaint(statisticsIndicatorPart)); } + + /*------------------------------------------综合分析-新版--------------------------------*/ + + + @GetMapping("/registrationNew") + @ResponseBody + public ZDResponse registrationNew(StatisticsIndicatorPart statisticsIndicatorPart){ + return ZDResponse.success("涉企检查数据统计",statisticalPaneService.registrationNew(statisticsIndicatorPart)); + } + + + + + + + + + } diff --git a/lib/EmergencyService/zdxtLawEnforcementCodeService/src/main/java/com/zdxt/code/domain/StatisticsIndicatorPart.java b/lib/EmergencyService/zdxtLawEnforcementCodeService/src/main/java/com/zdxt/code/domain/StatisticsIndicatorPart.java index 623276ab..72f0b76b 100644 --- a/lib/EmergencyService/zdxtLawEnforcementCodeService/src/main/java/com/zdxt/code/domain/StatisticsIndicatorPart.java +++ b/lib/EmergencyService/zdxtLawEnforcementCodeService/src/main/java/com/zdxt/code/domain/StatisticsIndicatorPart.java @@ -10,6 +10,14 @@ public class StatisticsIndicatorPart extends BaseDomain { private Integer number; private Integer huan; private Integer tong; + /** + * 同比-新字段 + */ + private Double tongValue; + /** + * 环比-新字段 + */ + private Double huanValue; private Integer complaint; List statisticsIndicatorPartList; @@ -157,4 +165,19 @@ public class StatisticsIndicatorPart extends BaseDomain { this.endTime = endTime; } + public Double getTongValue() { + return tongValue; + } + + public void setTongValue(Double tongValue) { + this.tongValue = tongValue; + } + + public Double getHuanValue() { + return huanValue; + } + + public void setHuanValue(Double huanValue) { + this.huanValue = huanValue; + } } diff --git a/lib/EmergencyService/zdxtLawEnforcementCodeService/src/main/java/com/zdxt/code/service/StatisticalPaneService.java b/lib/EmergencyService/zdxtLawEnforcementCodeService/src/main/java/com/zdxt/code/service/StatisticalPaneService.java index c9c79a15..393bce50 100644 --- a/lib/EmergencyService/zdxtLawEnforcementCodeService/src/main/java/com/zdxt/code/service/StatisticalPaneService.java +++ b/lib/EmergencyService/zdxtLawEnforcementCodeService/src/main/java/com/zdxt/code/service/StatisticalPaneService.java @@ -28,4 +28,18 @@ public interface StatisticalPaneService { */ StatisticsIndicatorPart statisticProgram(StatisticsIndicatorPart statisticsIndicatorPart); + + /*------------------------------------------综合分析-新版--------------------------------*/ + + + /** + * 统计涉企检查数量-新版 + * @param statisticsIndicatorPart + * @return + */ + StatisticsIndicatorPart registrationNew(StatisticsIndicatorPart statisticsIndicatorPart); + + + + } diff --git a/lib/EmergencyService/zdxtLawEnforcementCodeService/src/main/java/com/zdxt/code/service/impl/StatisticalPaneServiceImpl.java b/lib/EmergencyService/zdxtLawEnforcementCodeService/src/main/java/com/zdxt/code/service/impl/StatisticalPaneServiceImpl.java index a5e47809..b0c25394 100644 --- a/lib/EmergencyService/zdxtLawEnforcementCodeService/src/main/java/com/zdxt/code/service/impl/StatisticalPaneServiceImpl.java +++ b/lib/EmergencyService/zdxtLawEnforcementCodeService/src/main/java/com/zdxt/code/service/impl/StatisticalPaneServiceImpl.java @@ -12,13 +12,18 @@ import com.zdxt.code.domain.*; import com.zdxt.code.domain.dto.StatisticalPanelDto; import com.zdxt.code.mapper.StatisticalPanelMapper; import com.zdxt.code.service.*; +import com.zdxt.common.annotation.DataScope; import com.zdxt.domain.auth.Dept; import com.zdxt.domain.auth.User; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.text.DecimalFormat; import java.time.LocalDate; import java.time.format.DateTimeFormatter; +import java.time.temporal.ChronoUnit; import java.time.temporal.TemporalAdjusters; import java.util.ArrayList; import java.util.List; @@ -67,6 +72,7 @@ public class StatisticalPaneServiceImpl implements StatisticalPaneService { */ @Override public StatisticsIndicatorPart enterprise(StatisticsIndicatorPart statisticsIndicatorPart){ + StatisticsIndicatorPart sNow=nowDataMake(statisticsIndicatorPart); StatisticsIndicatorPart sLast=lastDataMake(statisticsIndicatorPart,sNow.getBeginTime()); EnterpriseInformation enterpriseNow=new EnterpriseInformation(); @@ -75,6 +81,7 @@ public class StatisticalPaneServiceImpl implements StatisticalPaneService { enterpriseNow.setEndTime(sNow.getEndTime()); enterpriseLast.setBeginTime(sLast.getBeginTime()); enterpriseLast.setEndTime(sLast.getEndTime()); + List enterpriseNowList = iEnterpriseInformationService.selectEnterpriseInformationList1(enterpriseNow); List enterpriseLastList = iEnterpriseInformationService.selectEnterpriseInformationList1(enterpriseLast); List existListNow = enterpriseNowList.stream().filter(item -> item.getIsUnsubscribe() == 0).collect(Collectors.toList()); @@ -370,6 +377,52 @@ public class StatisticalPaneServiceImpl implements StatisticalPaneService { return statisticsIndicatorPartResult; } + @DataScope + @Override + public StatisticsIndicatorPart registrationNew(StatisticsIndicatorPart statisticsIndicatorPart) { + //获取当前用户所在执法部门ID + String deptId = takeDeptId(); + //获取当前部门执法数据 + //获取当前时间 + StatisticsIndicatorPart sNow = nowDataMake(statisticsIndicatorPart); + //获取当前时间的同比时间 + StatisticsIndicatorPart sLast = lastDataMake(statisticsIndicatorPart,sNow.getBeginTime()); + //获取当前时间的环比时间 + StatisticsIndicatorPart sLastQoQ = lastDataMakeQoQ(statisticsIndicatorPart); + + //当前搜索时间 + EnforcementRegistration enforcementRegistrationNow = new EnforcementRegistration(); + enforcementRegistrationNow.setBeginTime(sNow.getBeginTime()); + enforcementRegistrationNow.setEndTime(sNow.getEndTime()); + //当前时间的同比时间 + EnforcementRegistration enforcementRegistrationLast = new EnforcementRegistration(); + enforcementRegistrationLast.setBeginTime(sLast.getBeginTime()); + enforcementRegistrationLast.setEndTime(sLast.getEndTime()); + //当前时间环比时间 + EnforcementRegistration enforcementRegistrationLastQoQ = new EnforcementRegistration(); + enforcementRegistrationLastQoQ.setBeginTime(sLastQoQ.getBeginTime()); + enforcementRegistrationLastQoQ.setEndTime(sLastQoQ.getEndTime()); + + //根据时间规则获取同一时间段内的数据 + List now = enforcementRegistrationService.selectEnforcementRegistrationList1(enforcementRegistrationNow); + List last = enforcementRegistrationService.selectEnforcementRegistrationList1(enforcementRegistrationLast); + List lastQoQ = enforcementRegistrationService.selectEnforcementRegistrationList1(enforcementRegistrationLastQoQ); + + //计算同比 + double tong = calculateYearOnYearGrowth(last.size(), now.size()); + //计算环比 + double huan = calculateYearOnYearGrowth(lastQoQ.size(), now.size()); + + //定义返回DTO + StatisticsIndicatorPart statisticsIndicatorPart1 = new StatisticsIndicatorPart(); + statisticsIndicatorPart1.setTongValue(tong); + statisticsIndicatorPart1.setHuanValue(huan); + statisticsIndicatorPart1.setTotal(now.size()); + + + return statisticsIndicatorPart1; + } + /** * 当前时间处理--转换成beginTime和endTime的形式 @@ -387,8 +440,8 @@ public class StatisticalPaneServiceImpl implements StatisticalPaneService { statisticsIndicatorPart.setBeginTime(str.format(beginTime)); statisticsIndicatorPart.setEndTime(str.format(endTime)); }else if(sip.getQuarter()!=null&&!"".equals(sip.getQuarter())){ - LocalDate beginTime=LocalDate.now(); - LocalDate endTime=LocalDate.now(); + LocalDate beginTime = LocalDate.now(); + LocalDate endTime = LocalDate.now(); switch (sip.getQuarter()) { case 1: beginTime = localDate.withYear(Integer.valueOf(sip.getYear())).withMonth(1).withDayOfMonth(1); @@ -417,8 +470,10 @@ public class StatisticalPaneServiceImpl implements StatisticalPaneService { } return statisticsIndicatorPart; } + + /** - * 上一时间处理--转换成beginTime和endTime的形式 + * 上一时间处理(同比时间)--转换成beginTime和endTime的形式 */ public StatisticsIndicatorPart lastDataMake(StatisticsIndicatorPart sip,String nowBeginData){ DateTimeFormatter str3=DateTimeFormatter.ofPattern("MM"); @@ -445,6 +500,78 @@ public class StatisticalPaneServiceImpl implements StatisticalPaneService { } return statisticsIndicatorPart; } + /** + * 上一时间处理(环比时间)--转换成beginTime和endTime的形式 + */ + public StatisticsIndicatorPart lastDataMakeQoQ(StatisticsIndicatorPart sip){ + /*DateTimeFormatter str3=DateTimeFormatter.ofPattern("MM"); + DateTimeFormatter str = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + LocalDate localDate = LocalDate.parse(nowBeginData, str); + LocalDate previousYearDate = localDate.minus(1, ChronoUnit.YEARS); + StatisticsIndicatorPart statisticsIndicatorPart=new StatisticsIndicatorPart(); + if(sip.getMonth()!=null&&!"".equals(sip.getMonth())) { + LocalDate beginTime=previousYearDate.minusMonths(1).withDayOfMonth(1); + LocalDate endTime = previousYearDate.minusMonths(1).with(TemporalAdjusters.lastDayOfMonth()); + statisticsIndicatorPart.setBeginTime(str.format(beginTime)); + statisticsIndicatorPart.setEndTime(str.format(endTime)); + }else if(sip.getQuarter()!=null&&!"".equals(sip.getQuarter())){ + previousYearDate = previousYearDate.minusMonths(3); + int quarter=(int)Math.ceil(Double.valueOf(str3.format(previousYearDate))/3); + LocalDate beginTime = previousYearDate.withMonth(quarter*3-2).withDayOfMonth(1); + LocalDate endTime=previousYearDate.withMonth(quarter*3).with(TemporalAdjusters.lastDayOfMonth()); + statisticsIndicatorPart.setBeginTime(str.format(beginTime)); + statisticsIndicatorPart.setEndTime(str.format(endTime)); + }else { + LocalDate beginTime=previousYearDate.minusYears(1).withMonth(1).withDayOfMonth(1); + LocalDate endTime=previousYearDate.minusYears(1).withMonth(12).with(TemporalAdjusters.lastDayOfMonth()); + statisticsIndicatorPart.setBeginTime(str.format(beginTime)); + statisticsIndicatorPart.setEndTime(str.format(endTime)); + }*/ + +// LocalDate previousYearDate = localDate.minus(1, ChronoUnit.YEARS); + LocalDate localDate = LocalDate.now(); + localDate = localDate.minus(1, ChronoUnit.YEARS); + DateTimeFormatter str=DateTimeFormatter.ofPattern("yyyy-MM-dd"); + StatisticsIndicatorPart statisticsIndicatorPart=new StatisticsIndicatorPart(); + if(sip.getYear()==null||"".equals(sip.getYear())){ + sip.setYear(localDate.getYear()+""); + } + if(sip.getMonth()!=null&&!"".equals(sip.getMonth())) { + LocalDate beginTime = localDate.withYear(Integer.valueOf(localDate.getYear())).withMonth(Integer.valueOf(localDate.getDayOfMonth())).withDayOfMonth(1); + LocalDate endTime = beginTime.with(TemporalAdjusters.lastDayOfMonth()); + statisticsIndicatorPart.setBeginTime(str.format(beginTime)); + statisticsIndicatorPart.setEndTime(str.format(endTime)); + }else if(sip.getQuarter()!=null&&!"".equals(sip.getQuarter())){ + LocalDate beginTime = localDate; + LocalDate endTime = localDate; + switch (sip.getQuarter()) { + case 1: + beginTime = localDate.withYear(Integer.valueOf(localDate.getYear())).withMonth(1).withDayOfMonth(1); + endTime = beginTime.withMonth(3).with(TemporalAdjusters.lastDayOfMonth()); + break; + case 2: + beginTime = localDate.withYear(Integer.valueOf(localDate.getYear())).withMonth(4).withDayOfMonth(1); + endTime = beginTime.withMonth(6).with(TemporalAdjusters.lastDayOfMonth()); + break; + case 3: + beginTime = localDate.withYear(Integer.valueOf(localDate.getYear())).withMonth(7).withDayOfMonth(1); + endTime = beginTime.withMonth(9).with(TemporalAdjusters.lastDayOfMonth()); + break; + case 4: + beginTime = localDate.withYear(Integer.valueOf(localDate.getYear())).withMonth(10).withDayOfMonth(1); + endTime = beginTime.withMonth(12).with(TemporalAdjusters.lastDayOfMonth()); + break; + } + statisticsIndicatorPart.setBeginTime(str.format(beginTime)); + statisticsIndicatorPart.setEndTime(str.format(endTime)); + }else { + LocalDate beginTime=localDate.withYear(Integer.valueOf(localDate.getYear())).withMonth(1).withDayOfMonth(1); + LocalDate endTime = localDate.withYear(Integer.valueOf(localDate.getYear())).withMonth(12).with(TemporalAdjusters.lastDayOfMonth()); + statisticsIndicatorPart.setBeginTime(str.format(beginTime)); + statisticsIndicatorPart.setEndTime(str.format(endTime)); + } + return statisticsIndicatorPart; + } public String takeDeptId(){ /*//获取该帐号执法证件号 String lawCertificateNum=userApi.getCurrentUser().getLawCertificateNum(); @@ -486,4 +613,22 @@ public class StatisticalPaneServiceImpl implements StatisticalPaneService { } + /** + * 计算同比增长百分比 + * @param baseValue 基准值 + * @param currentValue 当前值 + * @return 同比增长百分比 + */ + public static double calculateYearOnYearGrowth(double baseValue, double currentValue) { + if (baseValue == 0) { + // 如果基准值为0,则无法计算同比增长,可以返回一个特定的值,例如Double.NaN或者一个错误消息 + return 0.00; // 或者抛出异常 + } + + double growth = (currentValue - baseValue) / baseValue * 100; + BigDecimal bd = new BigDecimal(growth); + double v = bd.setScale(2, RoundingMode.HALF_UP).doubleValue(); + return v; + } + }