|
@@ -0,0 +1,248 @@
|
|
|
|
+package com.usky.fire.service.impl;
|
|
|
|
+
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
|
+import com.usky.common.core.exception.BusinessException;
|
|
|
|
+import com.usky.common.core.util.Arith;
|
|
|
|
+import com.usky.common.core.util.DateUtils;
|
|
|
|
+import com.usky.common.mybatis.core.AbstractCrudService;
|
|
|
|
+import com.usky.fire.domain.BscLawTrend;
|
|
|
|
+import com.usky.fire.domain.DemEnforceReportAttach;
|
|
|
|
+import com.usky.fire.domain.DemEnforceReportComplaint;
|
|
|
|
+import com.usky.fire.mapper.BscLawTrendMapper;
|
|
|
|
+import com.usky.fire.service.BscLawTrendService;
|
|
|
|
+import com.usky.fire.service.DemEnforceReportAttachService;
|
|
|
|
+import com.usky.fire.service.DemEnforceReportComplaintService;
|
|
|
|
+import com.usky.fire.service.DemLawStatisticsService;
|
|
|
|
+import com.usky.fire.service.vo.ReportComplaintVO;
|
|
|
|
+import com.usky.fire.service.vo.SiAeAllVO;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+
|
|
|
|
+import java.text.ParseException;
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
|
+import java.util.*;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * <p>
|
|
|
|
+ * 消防执法动态大屏统计 服务实现类
|
|
|
|
+ * </p>
|
|
|
|
+ *
|
|
|
|
+ * @author JCB
|
|
|
|
+ * @since 2022-10-13
|
|
|
|
+ */
|
|
|
|
+@Service
|
|
|
|
+public class BscLawTrendServiceImpl extends AbstractCrudService<BscLawTrendMapper, BscLawTrend> implements BscLawTrendService {
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private DemLawStatisticsService demLawStatisticsService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private DemEnforceReportComplaintService demEnforceReportComplaintService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private DemEnforceReportAttachService demEnforceReportAttachService;
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Object lawTrendList(String moduleType) {
|
|
|
|
+ LambdaQueryWrapper<BscLawTrend> queryWrapper = Wrappers.lambdaQuery();
|
|
|
|
+ switch (moduleType) {
|
|
|
|
+ case "monthLaw":
|
|
|
|
+ queryWrapper.select(BscLawTrend::getMonthLaw);
|
|
|
|
+ break;
|
|
|
|
+ case "adstraLicense":
|
|
|
|
+ queryWrapper.select(BscLawTrend::getAdstraLicense);
|
|
|
|
+ break;
|
|
|
|
+ case "reportComplaint":
|
|
|
|
+ queryWrapper.select(BscLawTrend::getReportComplaint);
|
|
|
|
+ break;
|
|
|
|
+ case "complaintHandle":
|
|
|
|
+ queryWrapper.select(BscLawTrend::getComplaintHandle);
|
|
|
|
+ break;
|
|
|
|
+ default:
|
|
|
|
+ throw new BusinessException("参数错误");
|
|
|
|
+ }
|
|
|
|
+ queryWrapper.orderByDesc(BscLawTrend::getId)
|
|
|
|
+ .last(" limit 1");
|
|
|
|
+ List<BscLawTrend> list = this.list(queryWrapper);
|
|
|
|
+ String data = null;
|
|
|
|
+ JSONArray jsonArray = new JSONArray();
|
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
|
+ switch (moduleType) {
|
|
|
|
+ case "monthLaw":
|
|
|
|
+ data = list.get(0).getMonthLaw();
|
|
|
|
+ jsonArray = JSONObject.parseArray(data);
|
|
|
|
+ break;
|
|
|
|
+ case "adstraLicense":
|
|
|
|
+ data = list.get(0).getAdstraLicense();
|
|
|
|
+ jsonObject = JSONObject.parseObject(data);
|
|
|
|
+ break;
|
|
|
|
+ case "reportComplaint":
|
|
|
|
+ data = list.get(0).getReportComplaint();
|
|
|
|
+ jsonArray = JSONObject.parseArray(data);
|
|
|
|
+ break;
|
|
|
|
+ case "complaintHandle":
|
|
|
|
+ data = list.get(0).getComplaintHandle();
|
|
|
|
+ jsonArray = JSONObject.parseArray(data);
|
|
|
|
+ break;
|
|
|
|
+ default:
|
|
|
|
+ throw new BusinessException("参数错误");
|
|
|
|
+ }
|
|
|
|
+ if (CollectionUtils.isNotEmpty(jsonArray)) {
|
|
|
|
+ return jsonArray;
|
|
|
|
+ } else if (CollectionUtils.isNotEmpty(jsonObject)) {
|
|
|
|
+ return jsonObject;
|
|
|
|
+ } else {
|
|
|
|
+ return jsonArray;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public List<SiAeAllVO> monthLaw() {
|
|
|
|
+ Date startTime = null;
|
|
|
|
+ Date endTime = null;
|
|
|
|
+ List<SiAeAllVO> allVoS = new ArrayList<>();
|
|
|
|
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
+ Date date = new Date();
|
|
|
|
+ Calendar calendar = new GregorianCalendar();
|
|
|
|
+ calendar.setTime(date);
|
|
|
|
+ //获得本月第一天
|
|
|
|
+ calendar.add(Calendar.MONTH, 0);
|
|
|
|
+ calendar.set(Calendar.DAY_OF_MONTH, 1);
|
|
|
|
+ String firstDay = sdf.format(calendar.getTime());
|
|
|
|
+ //获得本月最后一天
|
|
|
|
+ calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
|
|
|
|
+ String lastDay = sdf.format(calendar.getTime());
|
|
|
|
+ try {
|
|
|
|
+ startTime = simpleDateFormat.parse(firstDay + " 00:00:00");
|
|
|
|
+ endTime = simpleDateFormat.parse(lastDay + " 23:59:59");
|
|
|
|
+ } catch (ParseException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ Optional.ofNullable(startTime).orElseThrow(() -> new BusinessException("开始时间不能为空"));
|
|
|
|
+ Optional.ofNullable(endTime).orElseThrow(() -> new BusinessException("结束时间不能为空"));
|
|
|
|
+ Map<String, Object> aeAllCollect = demLawStatisticsService.lawStatistics(startTime, endTime);
|
|
|
|
+ //获取同比
|
|
|
|
+ Date upStartTime = DateUtils.addYears(startTime, -1);
|
|
|
|
+ Date upEndTime = DateUtils.addYears(endTime, -1);
|
|
|
|
+ Map<String, Object> upAllCollect = demLawStatisticsService.lawStatistics(upStartTime, upEndTime);
|
|
|
|
+ //获取环比
|
|
|
|
+ //获取两个时间天数之差
|
|
|
|
+ int distanceOfTwoDate = DateUtils.getDistanceOfTwoDateNew(startTime, endTime);
|
|
|
|
+ Date linkEndTime = DateUtils.addDays(startTime, -1);
|
|
|
|
+ Date linkStartTime = DateUtils.addDays(linkEndTime, -distanceOfTwoDate);
|
|
|
|
+ Map<String, Object> linkAllCollect = demLawStatisticsService.lawStatistics(linkStartTime, linkEndTime);
|
|
|
|
+
|
|
|
|
+ Optional.ofNullable(aeAllCollect).ifPresent(aeAll -> {
|
|
|
|
+ for (String type : aeAll.keySet()) {
|
|
|
|
+ SiAeAllVO siAeAllVO = new SiAeAllVO();
|
|
|
|
+ siAeAllVO.setCheckType(type);
|
|
|
|
+ Double radio = Double.parseDouble(aeAll.get(type).toString());
|
|
|
|
+ siAeAllVO.setNumber(radio);
|
|
|
|
+ Double upRadio = 0.00;
|
|
|
|
+ Double linkRadio = 0.00;
|
|
|
|
+ if (0 != radio) {
|
|
|
|
+ upRadio = Optional.ofNullable(upAllCollect).map(up -> Double.parseDouble(up.get(type).toString())).orElse(0.0);
|
|
|
|
+ siAeAllVO.setSameRatio(Arith.div(upRadio, radio));
|
|
|
|
+ linkRadio = Optional.ofNullable(linkAllCollect).map(link -> Double.parseDouble(link.get(type).toString())).orElse(0.0);
|
|
|
|
+ siAeAllVO.setLinkRelativeRatio(Arith.div(linkRadio, radio));
|
|
|
|
+ } else {
|
|
|
|
+ siAeAllVO.setSameRatio(0.00);
|
|
|
|
+ siAeAllVO.setLinkRelativeRatio(0.00);
|
|
|
|
+ }
|
|
|
|
+ if (radio.equals(upRadio)) {
|
|
|
|
+ siAeAllVO.setSameStatus(0);
|
|
|
|
+ } else if (radio > upRadio) {
|
|
|
|
+ siAeAllVO.setSameStatus(1);
|
|
|
|
+ } else {
|
|
|
|
+ siAeAllVO.setSameStatus(2);
|
|
|
|
+ }
|
|
|
|
+ if (radio.equals(linkRadio)) {
|
|
|
|
+ siAeAllVO.setLinkRelativeStatus(0);
|
|
|
|
+ } else if (radio > linkRadio) {
|
|
|
|
+ siAeAllVO.setLinkRelativeStatus(1);
|
|
|
|
+ } else {
|
|
|
|
+ siAeAllVO.setLinkRelativeStatus(2);
|
|
|
|
+ }
|
|
|
|
+ allVoS.add(siAeAllVO);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ return allVoS;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void adstraLicense() {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public List<ReportComplaintVO> reportComplaint() {
|
|
|
|
+ List<ReportComplaintVO> list = new ArrayList<>();
|
|
|
|
+ List<String> strings = this.enforceReportList();
|
|
|
|
+ strings.stream().filter(StringUtils::isNotBlank)
|
|
|
|
+ .forEach(type -> {
|
|
|
|
+ ReportComplaintVO reportComplaintVo = new ReportComplaintVO();
|
|
|
|
+ reportComplaintVo.setType(type);
|
|
|
|
+ reportComplaintVo.setNumber(this.enforceReportCount(type));
|
|
|
|
+ list.add(reportComplaintVo);
|
|
|
|
+ });
|
|
|
|
+ return list;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public int enforceReportCount(String hazardSiteName) {
|
|
|
|
+ int count = 0;
|
|
|
|
+ List<DemEnforceReportComplaint> list1 = this.enforceReportComplaint();
|
|
|
|
+ if (CollectionUtils.isNotEmpty(list1)) {
|
|
|
|
+ List<String> reportIdList = new ArrayList<>();
|
|
|
|
+ for (int i = 0; i < list1.size(); i++) {
|
|
|
|
+ reportIdList.add(list1.get(i).getReportId());
|
|
|
|
+ }
|
|
|
|
+ QueryWrapper<DemEnforceReportAttach> query = Wrappers.query();
|
|
|
|
+ query.in("report_id", reportIdList)
|
|
|
|
+ .ne("work_order_status_name", "已撤销")
|
|
|
|
+ .eq(StringUtils.isNotBlank(hazardSiteName), "hazard_site_name", hazardSiteName);
|
|
|
|
+ count = demEnforceReportAttachService.count(query);
|
|
|
|
+ }
|
|
|
|
+ return count;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public List<String> enforceReportList() {
|
|
|
|
+ List<String> HazardSiteNameList = new ArrayList<>();
|
|
|
|
+ List<DemEnforceReportComplaint> list1 = this.enforceReportComplaint();
|
|
|
|
+ if (CollectionUtils.isNotEmpty(list1)) {
|
|
|
|
+ List<String> reportIdList = new ArrayList<>();
|
|
|
|
+ for (int i = 0; i < list1.size(); i++) {
|
|
|
|
+ reportIdList.add(list1.get(i).getReportId());
|
|
|
|
+ }
|
|
|
|
+ LambdaQueryWrapper<DemEnforceReportAttach> queryWrapper = Wrappers.lambdaQuery();
|
|
|
|
+ queryWrapper.select(DemEnforceReportAttach::getHazardSiteName)
|
|
|
|
+ .in(DemEnforceReportAttach::getReportId, reportIdList)
|
|
|
|
+ .ne(DemEnforceReportAttach::getHazardSiteName, "")
|
|
|
|
+ .groupBy(DemEnforceReportAttach::getHazardSiteName);
|
|
|
|
+ List<DemEnforceReportAttach> list = demEnforceReportAttachService.list(queryWrapper);
|
|
|
|
+ if (CollectionUtils.isNotEmpty(list)) {
|
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
|
+ HazardSiteNameList.add(list.get(i).getHazardSiteName());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return HazardSiteNameList;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public List<DemEnforceReportComplaint> enforceReportComplaint() {
|
|
|
|
+ LambdaQueryWrapper<DemEnforceReportComplaint> queryWrapper1 = Wrappers.lambdaQuery();
|
|
|
|
+ queryWrapper1.select(DemEnforceReportComplaint::getReportId).eq(DemEnforceReportComplaint::getEnable, 0);
|
|
|
|
+ List<DemEnforceReportComplaint> list1 = demEnforceReportComplaintService.list(queryWrapper1);
|
|
|
|
+ return list1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|