From e63647ef91644dcf0d116a8579213367b9896407 Mon Sep 17 00:00:00 2001 From: guoshengxiong <1923636941@qq.com> Date: Fri, 14 Jun 2024 13:57:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8C=BA=E5=9F=9F=E4=BA=BA=E5=91=98=E6=95=B0?= =?UTF-8?q?=E9=87=8F=E5=88=86=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/SafetyHatDataController.java | 11 +++++ .../entity/vo/WorkerNumAndRegionName.java | 11 +++++ .../entity/vo/WorkerNumByRegionVo.java | 11 +++++ .../safetyhat/mapper/SafetyHatDataMapper.java | 3 ++ .../mapper/xml/SafetyHatDataMapper.xml | 14 ++++++ .../service/ISafetyHatDataService.java | 3 ++ .../impl/SafetyHatDataServiceImpl.java | 47 +++++++++++++++---- 7 files changed, 90 insertions(+), 10 deletions(-) create mode 100644 src/main/java/com/zhgd/xmgl/modules/safetyhat/entity/vo/WorkerNumAndRegionName.java create mode 100644 src/main/java/com/zhgd/xmgl/modules/safetyhat/entity/vo/WorkerNumByRegionVo.java diff --git a/src/main/java/com/zhgd/xmgl/modules/safetyhat/controller/SafetyHatDataController.java b/src/main/java/com/zhgd/xmgl/modules/safetyhat/controller/SafetyHatDataController.java index d9a582fad..2a5748c28 100644 --- a/src/main/java/com/zhgd/xmgl/modules/safetyhat/controller/SafetyHatDataController.java +++ b/src/main/java/com/zhgd/xmgl/modules/safetyhat/controller/SafetyHatDataController.java @@ -7,6 +7,7 @@ import com.gexin.fastjson.JSON; import com.zhgd.jeecg.common.api.vo.Result; import com.zhgd.xmgl.modules.safetyhat.entity.SafetyHatData; import com.zhgd.xmgl.modules.safetyhat.entity.SafetyHatDev; +import com.zhgd.xmgl.modules.safetyhat.entity.vo.WorkerNumByRegionVo; import com.zhgd.xmgl.modules.safetyhat.service.ISafetyHatDataService; import com.zhgd.xmgl.modules.worker.entity.WorkerInfo; import com.zhgd.xmgl.util.DateUtils; @@ -23,6 +24,7 @@ import springfox.documentation.annotations.ApiIgnore; import java.util.HashMap; import java.util.List; +import java.util.Map; /** @@ -159,4 +161,13 @@ public class SafetyHatDataController { return Result.success(safetyHatDataService.newestList(paramMap)); } + @ApiOperation(value = "区域人员数量分析", notes = "区域人员数量分析", httpMethod = "POST") + @ApiImplicitParams({ + @ApiImplicitParam(name = "projectSn", value = "项目sn", paramType = "body", required = true, dataType = "String"), + }) + @PostMapping(value = "/countWorkerNumByRegion") + public Result> countWorkerNumByRegion(@ApiIgnore @RequestBody Map param) { + return Result.success(safetyHatDataService.countWorkerNumByRegion(param)); + } + } diff --git a/src/main/java/com/zhgd/xmgl/modules/safetyhat/entity/vo/WorkerNumAndRegionName.java b/src/main/java/com/zhgd/xmgl/modules/safetyhat/entity/vo/WorkerNumAndRegionName.java new file mode 100644 index 000000000..77f5007eb --- /dev/null +++ b/src/main/java/com/zhgd/xmgl/modules/safetyhat/entity/vo/WorkerNumAndRegionName.java @@ -0,0 +1,11 @@ +package com.zhgd.xmgl.modules.safetyhat.entity.vo; + +import lombok.Data; + +@Data +public class WorkerNumAndRegionName { + private String date; + private Integer workerNum; + private String regionName; + +} diff --git a/src/main/java/com/zhgd/xmgl/modules/safetyhat/entity/vo/WorkerNumByRegionVo.java b/src/main/java/com/zhgd/xmgl/modules/safetyhat/entity/vo/WorkerNumByRegionVo.java new file mode 100644 index 000000000..52b891f0b --- /dev/null +++ b/src/main/java/com/zhgd/xmgl/modules/safetyhat/entity/vo/WorkerNumByRegionVo.java @@ -0,0 +1,11 @@ +package com.zhgd.xmgl.modules.safetyhat.entity.vo; + +import lombok.Data; + +import java.util.List; + +@Data +public class WorkerNumByRegionVo { + private String date; + private List list; +} diff --git a/src/main/java/com/zhgd/xmgl/modules/safetyhat/mapper/SafetyHatDataMapper.java b/src/main/java/com/zhgd/xmgl/modules/safetyhat/mapper/SafetyHatDataMapper.java index 67e049175..f156a89bf 100644 --- a/src/main/java/com/zhgd/xmgl/modules/safetyhat/mapper/SafetyHatDataMapper.java +++ b/src/main/java/com/zhgd/xmgl/modules/safetyhat/mapper/SafetyHatDataMapper.java @@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.Constants; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.zhgd.xmgl.modules.safetyhat.entity.SafetyHatData; +import com.zhgd.xmgl.modules.safetyhat.entity.vo.WorkerNumAndRegionName; import com.zhgd.xmgl.modules.worker.entity.WorkerInfo; import org.apache.ibatis.annotations.Mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; @@ -12,6 +13,7 @@ import org.apache.ibatis.annotations.Param; import java.util.HashMap; import java.util.List; +import java.util.Map; /** * @Description: 智能安全帽-实时数据 @@ -32,4 +34,5 @@ public interface SafetyHatDataMapper extends BaseMapper { int batchInsert(@Param("list") List list); + List countWorkerNumByRegion(@Param("param") Map param); } diff --git a/src/main/java/com/zhgd/xmgl/modules/safetyhat/mapper/xml/SafetyHatDataMapper.xml b/src/main/java/com/zhgd/xmgl/modules/safetyhat/mapper/xml/SafetyHatDataMapper.xml index aaca9ca51..22bd09ce7 100644 --- a/src/main/java/com/zhgd/xmgl/modules/safetyhat/mapper/xml/SafetyHatDataMapper.xml +++ b/src/main/java/com/zhgd/xmgl/modules/safetyhat/mapper/xml/SafetyHatDataMapper.xml @@ -51,4 +51,18 @@ ) + + diff --git a/src/main/java/com/zhgd/xmgl/modules/safetyhat/service/ISafetyHatDataService.java b/src/main/java/com/zhgd/xmgl/modules/safetyhat/service/ISafetyHatDataService.java index 0ae380ec5..fd678f57a 100644 --- a/src/main/java/com/zhgd/xmgl/modules/safetyhat/service/ISafetyHatDataService.java +++ b/src/main/java/com/zhgd/xmgl/modules/safetyhat/service/ISafetyHatDataService.java @@ -4,10 +4,12 @@ import com.zhgd.xmgl.modules.safetyhat.entity.SafetyHatData; import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.core.metadata.IPage; import com.zhgd.xmgl.modules.safetyhat.entity.SafetyHatDev; +import com.zhgd.xmgl.modules.safetyhat.entity.vo.WorkerNumByRegionVo; import com.zhgd.xmgl.modules.worker.entity.WorkerInfo; import java.util.HashMap; import java.util.List; +import java.util.Map; /** * @Description: 智能安全帽-实时数据 @@ -35,4 +37,5 @@ public interface ISafetyHatDataService extends IService { int batchInsert(List list); + List countWorkerNumByRegion(Map param); } diff --git a/src/main/java/com/zhgd/xmgl/modules/safetyhat/service/impl/SafetyHatDataServiceImpl.java b/src/main/java/com/zhgd/xmgl/modules/safetyhat/service/impl/SafetyHatDataServiceImpl.java index bc4d08cd1..387727e8b 100644 --- a/src/main/java/com/zhgd/xmgl/modules/safetyhat/service/impl/SafetyHatDataServiceImpl.java +++ b/src/main/java/com/zhgd/xmgl/modules/safetyhat/service/impl/SafetyHatDataServiceImpl.java @@ -12,22 +12,18 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.google.common.collect.Lists; import com.zhgd.jeecg.common.execption.OpenAlertException; import com.zhgd.jeecg.common.system.query.QueryGenerator; import com.zhgd.xmgl.modules.project.entity.Project; import com.zhgd.xmgl.modules.project.mapper.ProjectMapper; -import com.zhgd.xmgl.modules.safetyhat.entity.SafetyHatAlarm; -import com.zhgd.xmgl.modules.safetyhat.entity.SafetyHatData; -import com.zhgd.xmgl.modules.safetyhat.entity.SafetyHatDev; -import com.zhgd.xmgl.modules.safetyhat.entity.SafetyHatFence; -import com.zhgd.xmgl.modules.safetyhat.mapper.SafetyHatAlarmMapper; -import com.zhgd.xmgl.modules.safetyhat.mapper.SafetyHatDataMapper; -import com.zhgd.xmgl.modules.safetyhat.mapper.SafetyHatDevMapper; -import com.zhgd.xmgl.modules.safetyhat.mapper.SafetyHatFenceMapper; +import com.zhgd.xmgl.modules.safetyhat.entity.*; +import com.zhgd.xmgl.modules.safetyhat.entity.vo.WorkerNumAndRegionName; +import com.zhgd.xmgl.modules.safetyhat.entity.vo.WorkerNumByRegionVo; +import com.zhgd.xmgl.modules.safetyhat.mapper.*; import com.zhgd.xmgl.modules.safetyhat.service.ISafetyHatAlarmService; import com.zhgd.xmgl.modules.safetyhat.service.ISafetyHatDataService; -import com.zhgd.xmgl.modules.safetyhat.entity.SafetyHatDataToFence; -import com.zhgd.xmgl.modules.safetyhat.mapper.SafetyHatDataToFenceMapper; +import com.zhgd.xmgl.util.DateUtils; import com.zhgd.xmgl.util.PageUtil; import com.zhgd.xmgl.util.RefUtil; import com.zhgd.xmgl.util.RegionUtil; @@ -39,6 +35,8 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.*; +import java.util.function.Function; +import java.util.stream.Collectors; /** * @Description: 智能安全帽-实时数据 @@ -274,5 +272,34 @@ public class SafetyHatDataServiceImpl extends ServiceImpl countWorkerNumByRegion(Map param) { + List vos = Lists.newArrayList(); + List dataList = baseMapper.countWorkerNumByRegion(param); + Map> dateMap = dataList.stream().collect(Collectors.groupingBy(WorkerNumAndRegionName::getDate)); + Set regionNameSet = dataList.stream().map(WorkerNumAndRegionName::getRegionName).collect(Collectors.toSet()); + List dateList = DateUtils.getDateTimeStrList(60, "yyyy-MM-dd"); + for (String date : dateList) { + List list = new ArrayList<>(); + for (String regionName : regionNameSet) { + List workerNumAndRegionNames = dateMap.get(date); + Map regionNameMap = Optional.ofNullable(workerNumAndRegionNames).orElse(new ArrayList<>()).stream().collect(Collectors.toMap(WorkerNumAndRegionName::getRegionName, Function.identity(), (oldValue, newValue) -> oldValue)); + WorkerNumAndRegionName workerNumAndRegionName = regionNameMap.get(regionName); + if (workerNumAndRegionName == null) { + workerNumAndRegionName = new WorkerNumAndRegionName(); + workerNumAndRegionName.setWorkerNum(0); + workerNumAndRegionName.setDate(date); + workerNumAndRegionName.setRegionName(regionName); + } + list.add(workerNumAndRegionName); + } + WorkerNumByRegionVo oneVo = new WorkerNumByRegionVo(); + oneVo.setDate(date); + oneVo.setList(list); + vos.add(oneVo); + } + return vos; + } + }