From 8873248220c566ae54034b233a9f2886970ef08e Mon Sep 17 00:00:00 2001 From: yang_shj <1069818635@QQ.com> Date: Tue, 12 Dec 2023 11:14:21 +0800 Subject: [PATCH 01/11] =?UTF-8?q?#=E6=B0=B4=E4=BD=8D=E6=9F=B1=E7=8A=B6?= =?UTF-8?q?=E9=A2=9C=E8=89=B2=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../scheduled/service/operation/monitor/impl/MonitorServiceImpl.java | 2 +- .../hzims/operational/station/service/impl/RealMonitorServiceImpl.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/monitor/impl/MonitorServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/monitor/impl/MonitorServiceImpl.java index 21cff8b..700feef 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/monitor/impl/MonitorServiceImpl.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/monitor/impl/MonitorServiceImpl.java @@ -6,7 +6,6 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.google.common.collect.Lists; import com.google.common.util.concurrent.ThreadFactoryBuilder; -import com.hnac.hzims.alarm.entity.AlarmEntity; import com.hnac.hzims.equipment.entity.WorkshopInfoEntity; import com.hnac.hzims.equipment.vo.EminfoAndEmParamVo; import com.hnac.hzims.fdp.vo.FdpFaultStatusVo; @@ -455,6 +454,7 @@ public class MonitorServiceImpl implements MonitorService { item.setWaterLevelMax(station.getLimitWaterLevel()); item.setServerType(station.getServeType()); item.setStationDeptId(station.getRefDept()); + item.setSort(9999); // 排序 List list = deptAll.stream().filter(o-> station.getRefDept().equals(o.getId())).collect(Collectors.toList()); if(CollectionUtil.isEmpty(list)){ diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/RealMonitorServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/RealMonitorServiceImpl.java index a5a4e97..cd7b49f 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/RealMonitorServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/RealMonitorServiceImpl.java @@ -965,7 +965,7 @@ public class RealMonitorServiceImpl implements IRealMonitorService { return; } station.setWaterLevel(levelList.get(0)); - if(station.getWaterLevelMax() <= 0 || station.getWaterLevel() <= 0){ + if(ObjectUtil.isEmpty(station.getWaterLevelMax()) || ObjectUtil.isEmpty(station.getWaterLevel()) || station.getWaterLevelMax() <= 0 || station.getWaterLevel() <= 0){ return; } if(station.getWaterLevelMax() < station.getWaterLevel()){ From 4a9e4985e9e70f9ffee4e1658b58d7258fdc5ef0 Mon Sep 17 00:00:00 2001 From: yang_shj <1069818635@QQ.com> Date: Tue, 12 Dec 2023 14:23:23 +0800 Subject: [PATCH 02/11] =?UTF-8?q?#AI=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/constant/VideoEnumConstants.java | 40 +++++++++++ .../hzims/operational/main/vo/VideoAlarmVO.java | 24 +++++++ .../scheduled/scheduled/MonitorScheduledTask.java | 7 +- .../operation/monitor/impl/MonitorServiceImpl.java | 2 +- .../main/controller/AiAlarmController.java | 38 ++++++++++ .../operational/main/service/AiAlarmService.java | 14 ++++ .../main/service/impl/AiAlarmServiceImpl.java | 82 ++++++++++++++++++++++ 7 files changed, 202 insertions(+), 5 deletions(-) create mode 100644 hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/constant/VideoEnumConstants.java create mode 100644 hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/VideoAlarmVO.java create mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/controller/AiAlarmController.java create mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/AiAlarmService.java create mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/AiAlarmServiceImpl.java diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/constant/VideoEnumConstants.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/constant/VideoEnumConstants.java new file mode 100644 index 0000000..9839c58 --- /dev/null +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/constant/VideoEnumConstants.java @@ -0,0 +1,40 @@ +package com.hnac.hzims.operational.main.constant; + +import lombok.Getter; + +/** + * @author ysj + * @version 4.0.0 + * @create 2023-11-07-14:31 + */ +public interface VideoEnumConstants { + + @Getter + enum SoeKindEnum{ + /** + * 视频告警类型 + */ + MOTION_DETECTION("131331","移动侦测"), + REGIONAL_INTRUSION("131588","区域入侵"), + CROSS_BORDER_DETECTION("131585","越界侦测"), + SMOKE_FIRE_DETECTION("192514","烟火检测"), + OTHER_FLOATING_OBJECTS("42200047146001","其他漂浮物"), + PLANT_FLOATING_OBJECTS("42200047146000","植物类漂浮物"), + PLASTIC_FLOATING_OBJECTS("42200047146002","塑料类漂浮物"); + private final String instance; + private final String name; + SoeKindEnum(String instance,String name){ + this.instance = instance; + this.name = name; + } + public static String getValueByKey(String key) { + for (SoeKindEnum kind : SoeKindEnum.values()) { + if (kind.instance.equals(key)) { + return kind.getName(); + } + } + throw new IllegalArgumentException("Invalid key: " + key); + } + + } +} \ No newline at end of file diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/VideoAlarmVO.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/VideoAlarmVO.java new file mode 100644 index 0000000..a46f330 --- /dev/null +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/VideoAlarmVO.java @@ -0,0 +1,24 @@ +package com.hnac.hzims.operational.main.vo; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + + +/** + * @author ysj + */ +@Data +public class VideoAlarmVO { + + @ApiModelProperty("设备编码") + private String deviceCode; + + @ApiModelProperty("设备名称") + private String deviceName; + + @ApiModelProperty("开始时间") + private String startTime; + + @ApiModelProperty("结束时间") + private String endTime; +} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/MonitorScheduledTask.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/MonitorScheduledTask.java index daed33c..51131e3 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/MonitorScheduledTask.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/MonitorScheduledTask.java @@ -55,10 +55,9 @@ public class MonitorScheduledTask { * 集中监控数据处理 * @return ReturnT */ - //@XxlJob(CENTRALIZED_MONITORING) - @Scheduled(cron = "0/40 * * * * ? ") - public ReturnT loadMonitoring() { - String param = ""; + @XxlJob(CENTRALIZED_MONITORING) + //@Scheduled(cron = "0/40 * * * * ? ") + public ReturnT loadMonitoring(String param) { if (Func.isBlank(param)) { param = DateUtil.format(new Date(), "yyyy-MM"); } diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/monitor/impl/MonitorServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/monitor/impl/MonitorServiceImpl.java index 700feef..e7e3558 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/monitor/impl/MonitorServiceImpl.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/monitor/impl/MonitorServiceImpl.java @@ -451,7 +451,7 @@ public class MonitorServiceImpl implements MonitorService { return; } item.setStationName(station.getName()); - item.setWaterLevelMax(station.getLimitWaterLevel()); + item.setWaterLevelMax(Optional.ofNullable(station.getLimitWaterLevel()).orElse(0.0)); item.setServerType(station.getServeType()); item.setStationDeptId(station.getRefDept()); item.setSort(9999); diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/controller/AiAlarmController.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/controller/AiAlarmController.java new file mode 100644 index 0000000..acabaeb --- /dev/null +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/controller/AiAlarmController.java @@ -0,0 +1,38 @@ +package com.hnac.hzims.operational.main.controller; + +import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; +import com.hnac.hzims.operational.main.service.AiAlarmService; +import com.hnac.hzims.operational.main.vo.VideoAlarmVO; +import com.hnac.hzinfo.datasearch.soe.vo.DeviceSoeVO; +import com.hnac.hzinfo.sdk.core.response.HzPage; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.AllArgsConstructor; +import org.springblade.core.boot.ctrl.BladeController; +import org.springblade.core.log.annotation.ApiLog; +import org.springblade.core.mp.support.Condition; +import org.springblade.core.mp.support.Query; +import org.springblade.core.tool.api.R; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * @author ysj + */ +@RestController +@RequestMapping("/ai") +@Api(value = "ai视频告警", tags = "ai视频告警") +@AllArgsConstructor +public class AiAlarmController extends BladeController { + + private final AiAlarmService aiAlarmService; + + @ApiLog + @GetMapping("/video/alarm_page") + @ApiOperationSupport(order = 15) + @ApiOperation(value = "视频告警数据查询接口", notes = "station") + public R> alarmPage(VideoAlarmVO videoAlarm, Query query) { + return R.data(aiAlarmService.alarmPage(videoAlarm, Condition.getPage(query))); + } +} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/AiAlarmService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/AiAlarmService.java new file mode 100644 index 0000000..900338e --- /dev/null +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/AiAlarmService.java @@ -0,0 +1,14 @@ +package com.hnac.hzims.operational.main.service; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.hnac.hzims.operational.main.vo.VideoAlarmVO; +import com.hnac.hzinfo.datasearch.soe.vo.DeviceSoeVO; +import com.hnac.hzinfo.sdk.core.response.HzPage; + +/** + * @author ysj + */ +public interface AiAlarmService { + + HzPage alarmPage(VideoAlarmVO videoAlarm, IPage page); +} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/AiAlarmServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/AiAlarmServiceImpl.java new file mode 100644 index 0000000..6e48f38 --- /dev/null +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/AiAlarmServiceImpl.java @@ -0,0 +1,82 @@ +package com.hnac.hzims.operational.main.service.impl; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.hnac.hzims.operational.main.constant.VideoEnumConstants; +import com.hnac.hzims.operational.main.service.AiAlarmService; +import com.hnac.hzims.operational.main.vo.VideoAlarmVO; +import com.hnac.hzinfo.datasearch.soe.ISoeClient; +import com.hnac.hzinfo.datasearch.soe.vo.DeviceSoeVO; +import com.hnac.hzinfo.sdk.core.response.HzPage; +import com.hnac.hzinfo.sdk.core.response.Result; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springblade.core.tool.utils.CollectionUtil; +import org.springblade.core.tool.utils.DateUtil; +import org.springblade.core.tool.utils.StringUtil; +import org.springframework.stereotype.Service; + +import java.util.Calendar; +import java.util.Date; +import java.util.List; +import java.util.stream.Collectors; + +/** + * @author ysj + */ +@Slf4j +@RequiredArgsConstructor +@Service +public class AiAlarmServiceImpl implements AiAlarmService { + + private final ISoeClient alarmClient; + + /** + * 设备告警列表查询 + * @param videoAlarm + * @param page + * @return + */ + @Override + public HzPage alarmPage(VideoAlarmVO videoAlarm, IPage page) { + String startTime,endTime; + if(StringUtils.isEmpty(videoAlarm.getStartTime())){ + Calendar calendar = Calendar.getInstance(); + calendar.add(Calendar.DAY_OF_MONTH,-calendar.get(Calendar.DAY_OF_MONTH)); + startTime = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE) + " 00:00:00"; + }else{ + startTime = videoAlarm.getStartTime(); + } + if(StringUtils.isEmpty(videoAlarm.getEndTime())){ + endTime = DateUtil.format(new Date(),DateUtil.PATTERN_DATETIME); + }else{ + endTime = videoAlarm.getEndTime(); + } + // 查询视频告警数据 + Result> soe = alarmClient.getDeviceCodeByTaosSoe(startTime,endTime,videoAlarm.getDeviceCode(),(int) page.getCurrent(), String.valueOf(page.getSize())); + if(!soe.isSuccess() || CollectionUtil.isEmpty(soe.getData().getRecords())){ + return new HzPage<>(); + } + List records = soe.getData().getRecords(); + soe.getData().setRecords(records.stream().peek(record -> { + record.setSoeType(videoAlarm.getDeviceName() + "_" + VideoEnumConstants.SoeKindEnum.getValueByKey(record.getInstanceFieldName()) + "_触发告警"); + if(!StringUtil.isEmpty(record.getSoeExplain())) { + String soeExplain = StringUtils.strip(record.getSoeExplain(), "[]"); + StringBuilder sb = new StringBuilder(); + if(record.getSoeExplain().contains("http")){ + String[] imgs = soeExplain.split(","); + for (String img : imgs){ + sb.append(img).append(","); + } + }else{ + String[] imgs = soeExplain.split(","); + for (String img : imgs){ + sb.append("https://172.30.100.204").append(img).append(","); + } + } + record.setSoeAlarmType(sb.substring(0, sb.length() - 1).replace("\"", "")); + } + }).collect(Collectors.toList())); + return soe.getData(); + } +} \ No newline at end of file From abbf21522955531ebe08fd0f559ba71060c49ee0 Mon Sep 17 00:00:00 2001 From: yang_shj <1069818635@QQ.com> Date: Tue, 12 Dec 2023 16:10:41 +0800 Subject: [PATCH 03/11] =?UTF-8?q?#AI=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/hnac/hzims/equipment/controller/EmInfoController.java | 7 +++++++ .../java/com/hnac/hzims/equipment/service/IEmInfoService.java | 2 ++ .../hnac/hzims/equipment/service/impl/EmInfoServiceImpl.java | 11 +++++++++++ 3 files changed, 20 insertions(+) diff --git a/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/controller/EmInfoController.java b/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/controller/EmInfoController.java index f0c1a71..92ab91d 100644 --- a/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/controller/EmInfoController.java +++ b/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/controller/EmInfoController.java @@ -413,4 +413,11 @@ public class EmInfoController extends BladeController { public R> getEmTreeByDeptAndParentCode(@ApiParam("机构ID") Long deptId, @ApiParam("父级设备编号") String parentCode) { return R.data(em_infoService.getEmTreeByDeptAndParentCode(deptId,parentCode)); } + + @GetMapping("/hkVideoDevices") + @ApiOperationSupport(order = 12) + @ApiOperation(value = "海康视频设备获取") + public R> hkVideoDevices() { + return R.data(em_infoService.hkVideoDevices()); + } } diff --git a/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/service/IEmInfoService.java b/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/service/IEmInfoService.java index 5decdcc..8562541 100644 --- a/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/service/IEmInfoService.java +++ b/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/service/IEmInfoService.java @@ -89,4 +89,6 @@ public interface IEmInfoService extends BaseService { List getEmTreeByDeptAndParentCode(Long deptId, String parentCode); List getVideoDeviceByEmCode(EmInfoEntity emInfo); + + List hkVideoDevices(); } diff --git a/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/service/impl/EmInfoServiceImpl.java b/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/service/impl/EmInfoServiceImpl.java index 5b9ecef..cadc489 100644 --- a/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/service/impl/EmInfoServiceImpl.java +++ b/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/service/impl/EmInfoServiceImpl.java @@ -900,4 +900,15 @@ public class EmInfoServiceImpl extends BaseServiceImpl hkVideoDevices() { + return this.list(Wrappers.lambdaQuery() + .eq(EmInfoEntity::getEmType,4)); + } + } From 6539903e232d1826f8a8588d942e3f8d5007714c Mon Sep 17 00:00:00 2001 From: yang_shj <1069818635@QQ.com> Date: Wed, 13 Dec 2023 15:02:33 +0800 Subject: [PATCH 04/11] =?UTF-8?q?#=E9=9B=86=E4=B8=AD=E7=9B=91=E6=8E=A7?= =?UTF-8?q?=E5=85=B3=E8=81=94=E5=8E=86=E5=8F=B2=E6=95=B0=E6=8D=AE=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/controller/CentralMonitorController.java | 7 +++++-- .../config/service/CentralMonitorService.java | 3 ++- .../config/service/impl/CentralMonitorServiceImpl.java | 17 ++++++++++++----- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/controller/CentralMonitorController.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/controller/CentralMonitorController.java index a86b507..4f64964 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/controller/CentralMonitorController.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/controller/CentralMonitorController.java @@ -15,6 +15,7 @@ import org.springblade.core.boot.ctrl.BladeController; import org.springblade.core.tool.api.R; import org.springframework.web.bind.annotation.*; +import java.util.Date; import java.util.List; @@ -58,8 +59,10 @@ public class CentralMonitorController extends BladeController { @GetMapping("/selectCommunication/{page}/{size}") public R selectCommunication(@PathVariable Integer page, @PathVariable Integer size, - String roleId){ - IPage result = monitorService.selectOriginalDataByRealIds(page, size, roleId); + String roleId, + Date start, + Date end){ + IPage result = monitorService.selectOriginalDataByRealIds(page, size, roleId,start,end); return R.data(result); } } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/service/CentralMonitorService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/service/CentralMonitorService.java index 887026e..1a8c211 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/service/CentralMonitorService.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/service/CentralMonitorService.java @@ -7,6 +7,7 @@ import com.hnac.hzims.operational.main.vo.RealStationVo; import com.hnac.hzinfo.datasearch.PointData; import com.hnac.hzinfo.sdk.core.response.HzPage; +import java.util.Date; import java.util.List; /** @@ -28,6 +29,6 @@ public interface CentralMonitorService{ * @param roleId * @return */ - IPage selectOriginalDataByRealIds(Integer page, Integer size, String roleId); + IPage selectOriginalDataByRealIds(Integer page, Integer size, String roleId, Date start, Date end); } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/service/impl/CentralMonitorServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/service/impl/CentralMonitorServiceImpl.java index 6f92abc..6a6bbc9 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/service/impl/CentralMonitorServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/service/impl/CentralMonitorServiceImpl.java @@ -91,14 +91,21 @@ public class CentralMonitorServiceImpl implements CentralMonitorService { * @return */ @Override - public IPage selectOriginalDataByRealIds(Integer page, Integer size, String roleId) { + public IPage selectOriginalDataByRealIds(Integer page, Integer size, String roleId,Date start,Date end) { OriginalDataQuery originalDataQuery = new OriginalDataQuery(); originalDataQuery.setRealId(roleId); originalDataQuery.setLimit(size); - Calendar calendar = Calendar.getInstance(); - originalDataQuery.setEndTime(calendar.getTime()); - calendar.add(Calendar.HOUR_OF_DAY,-1); - originalDataQuery.setBeginTime(calendar.getTime()); + // 当日 + if(ObjectUtil.isEmpty(start) && ObjectUtil.isEmpty(end)){ + Calendar calendar = Calendar.getInstance(); + originalDataQuery.setEndTime(calendar.getTime()); + calendar.add(Calendar.HOUR_OF_DAY,-calendar.get(Calendar.HOUR_OF_DAY)); + calendar.add(Calendar.MINUTE,-calendar.get(Calendar.MINUTE)); + calendar.add(Calendar.SECOND,-calendar.get(Calendar.SECOND)); + originalDataQuery.setBeginTime(calendar.getTime()); + } + originalDataQuery.setBeginTime(start); + originalDataQuery.setEndTime(end); Result> originalDataByRealIds = historyDataSearchClient.getOriginalDataByRealIds(originalDataQuery); if (!originalDataByRealIds.isSuccess()) { throw new ServiceException("数据不存在"); From 1b0c0ebcc29f5fb52f1fbc48573c6b1e35c144b0 Mon Sep 17 00:00:00 2001 From: ty <1577900710@qq.com> Date: Wed, 13 Dec 2023 18:30:44 +0800 Subject: [PATCH 05/11] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=A7=86=E9=A2=91?= =?UTF-8?q?=E6=B5=81=E9=85=8D=E7=BD=AE=E8=A1=A8=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../station/entity/VideoConfigEntity.java | 41 ++++++++++++++++++++++ .../controller/StationVideoTypeController.java | 41 ++++++++++++++++++++++ .../station/mapper/VideoConfigMapper.java | 12 +++++++ .../station/mapper/VideoConfigMapper.xml | 20 +++++++++++ .../station/service/VideoConfigService.java | 13 +++++++ .../service/impl/VideoConfigServiceImpl.java | 17 +++++++++ 6 files changed, 144 insertions(+) create mode 100644 hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/entity/VideoConfigEntity.java create mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/mapper/VideoConfigMapper.java create mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/mapper/VideoConfigMapper.xml create mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/VideoConfigService.java create mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/VideoConfigServiceImpl.java diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/entity/VideoConfigEntity.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/entity/VideoConfigEntity.java new file mode 100644 index 0000000..ba036c6 --- /dev/null +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/entity/VideoConfigEntity.java @@ -0,0 +1,41 @@ +package com.hnac.hzims.operational.station.entity; + +import com.baomidou.mybatisplus.annotation.SqlCondition; +import com.baomidou.mybatisplus.annotation.TableName; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.NullSerializer; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.springblade.core.mp.support.QueryField; +import org.springblade.core.tenant.mp.TenantEntity; + +@Data +@TableName("hzims_flv_video_config") +@EqualsAndHashCode(callSuper = true) +@ApiModel(value = "视频配置对象", description = "视频配置表") +public class VideoConfigEntity extends TenantEntity { + + private static final long serialVersionUID = 8694213320261034807L; + + @QueryField(condition = SqlCondition.LIKE) + @ApiModelProperty("视频源配置名称") + private String name; + + @QueryField(condition = SqlCondition.EQUAL) + @ApiModelProperty("时间间隔") + private String time; + + @QueryField(condition = SqlCondition.LIKE) + @ApiModelProperty("配置json") + private String configEntity; + + @QueryField(condition = SqlCondition.EQUAL) + @ApiModelProperty("视频类型") + private String type; + + @QueryField(condition = SqlCondition.EQUAL) + @ApiModelProperty("保存人姓名") + private String savePeople; +} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/controller/StationVideoTypeController.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/controller/StationVideoTypeController.java index 8647c33..45f0e90 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/controller/StationVideoTypeController.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/controller/StationVideoTypeController.java @@ -3,6 +3,7 @@ package com.hnac.hzims.operational.station.controller; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; import com.hnac.hzims.common.logs.annotation.OperationAnnotation; @@ -11,10 +12,12 @@ import com.hnac.hzims.common.logs.enums.OperatorType; import com.hnac.hzims.operational.station.dto.StationVideoTypeDTO; import com.hnac.hzims.operational.station.entity.StationEntity; import com.hnac.hzims.operational.station.entity.StationVideoTypeEntity; +import com.hnac.hzims.operational.station.entity.VideoConfigEntity; import com.hnac.hzims.operational.station.response.HikDeviceResp; import com.hnac.hzims.operational.station.response.HikMonitorResp; import com.hnac.hzims.operational.station.service.IStationService; import com.hnac.hzims.operational.station.service.IStationVideoTypeService; +import com.hnac.hzims.operational.station.service.VideoConfigService; import com.hnac.hzims.operational.station.utils.ArtemisPostUtils; import com.hnac.hzims.operational.station.vo.StationVO; import com.hnac.hzims.operational.station.vo.StationVideoTypeVO; @@ -56,6 +59,7 @@ public class StationVideoTypeController extends BladeController { private final ISysClient sysClient; private final IStationService stationService; + private final VideoConfigService videoConfigService; /** 秘钥appKey **/ @Value("${hzims.videoProperties.appKey}") @@ -233,6 +237,43 @@ public class StationVideoTypeController extends BladeController { page.getRecords().forEach(getFlvVideo); return R.data(page); } + + @ApiLog + @GetMapping("/getFlvVideoConfig") + @ApiOperationSupport(order = 120) + @ApiOperation(value = "获取Flv配置列表", notes = "获取Flv配置列表") + public R getFlvVideoConfig(VideoConfigEntity req,Query query) { + LambdaQueryWrapper queryWrapper = com.hnac.hzims.common.utils.Condition.getQueryWrapper(VideoConfigEntity.class, req); + IPage page = videoConfigService.page(com.hnac.hzims.common.utils.Condition.getPage(query), queryWrapper); + return R.data(page); + } + @ApiLog + @PostMapping ("/updateFlvVideoConfig") + @ApiOperationSupport(order = 120) + @ApiOperation(value = "更新Flv配置列表", notes = "更新Flv配置列表") + public R updateFlvVideoConfig(@RequestBody VideoConfigEntity req) { + if (ObjectUtil.isNotEmpty(req)) { + boolean b = videoConfigService.saveOrUpdate(req); + if (b) { + return R.success("更新视频配置成功"); + } + } + return R.fail("更新视频配置失败"); + } + @ApiLog + @PostMapping("/deleteFlvVideoConfig") + @ApiOperationSupport(order = 120) + @ApiOperation(value = "删除Flv配置列表", notes = "删除Flv配置列表") + public R deleteFlvVideoConfig(@RequestBody List ids) { + if (CollectionUtils.isNotEmpty(ids)) { + boolean flag = videoConfigService.removeByIds(ids); + if (flag) { + return R.success("删除成功"); + } + } + return R.fail("删除失败"); + } + @ApiLog @GetMapping("/getMonitorsByStation") @ApiOperationSupport(order = 130) diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/mapper/VideoConfigMapper.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/mapper/VideoConfigMapper.java new file mode 100644 index 0000000..a9b2c78 --- /dev/null +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/mapper/VideoConfigMapper.java @@ -0,0 +1,12 @@ +package com.hnac.hzims.operational.station.mapper; + +import com.hnac.hzims.operational.station.entity.VideoConfigEntity; +import org.springblade.core.datascope.mapper.UserDataScopeBaseMapper; + + +/** + * @author ty + */ +public interface VideoConfigMapper extends UserDataScopeBaseMapper { + +} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/mapper/VideoConfigMapper.xml b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/mapper/VideoConfigMapper.xml new file mode 100644 index 0000000..cd7d542 --- /dev/null +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/mapper/VideoConfigMapper.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/VideoConfigService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/VideoConfigService.java new file mode 100644 index 0000000..64f74a8 --- /dev/null +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/VideoConfigService.java @@ -0,0 +1,13 @@ +package com.hnac.hzims.operational.station.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.hnac.hzims.operational.station.entity.VideoConfigEntity; + +/** + * @Author WL + * @Version v1.0 + * @Serial 1.0 + * @Date 2023/8/8 16:14 + */ +public interface VideoConfigService extends IService { +} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/VideoConfigServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/VideoConfigServiceImpl.java new file mode 100644 index 0000000..5e85fc2 --- /dev/null +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/VideoConfigServiceImpl.java @@ -0,0 +1,17 @@ +package com.hnac.hzims.operational.station.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.hnac.hzims.operational.station.entity.VideoConfigEntity; +import com.hnac.hzims.operational.station.mapper.VideoConfigMapper; +import com.hnac.hzims.operational.station.service.VideoConfigService; +import org.springframework.stereotype.Service; + +/** + * @Author WL + * @Version v1.0 + * @Serial 1.0 + * @Date 2023/8/8 16:17 + */ +@Service +public class VideoConfigServiceImpl extends ServiceImpl implements VideoConfigService { +} From 3261a28de5ca2a808f8de3d247451372da835047 Mon Sep 17 00:00:00 2001 From: yang_shj <1069818635@QQ.com> Date: Thu, 14 Dec 2023 09:16:11 +0800 Subject: [PATCH 06/11] =?UTF-8?q?#=E9=9B=86=E4=B8=AD=E7=9B=91=E6=8E=A7real?= =?UTF-8?q?Id=E5=AE=9E=E6=97=B6=E5=9B=BE=E5=88=97=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../operational/config/service/impl/CentralMonitorServiceImpl.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/service/impl/CentralMonitorServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/service/impl/CentralMonitorServiceImpl.java index 6a6bbc9..790e2c1 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/service/impl/CentralMonitorServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/service/impl/CentralMonitorServiceImpl.java @@ -102,10 +102,12 @@ public class CentralMonitorServiceImpl implements CentralMonitorService { calendar.add(Calendar.HOUR_OF_DAY,-calendar.get(Calendar.HOUR_OF_DAY)); calendar.add(Calendar.MINUTE,-calendar.get(Calendar.MINUTE)); calendar.add(Calendar.SECOND,-calendar.get(Calendar.SECOND)); + calendar.add(Calendar.MILLISECOND,-calendar.get(Calendar.MILLISECOND)); originalDataQuery.setBeginTime(calendar.getTime()); + }else{ + originalDataQuery.setBeginTime(start); + originalDataQuery.setEndTime(end); } - originalDataQuery.setBeginTime(start); - originalDataQuery.setEndTime(end); Result> originalDataByRealIds = historyDataSearchClient.getOriginalDataByRealIds(originalDataQuery); if (!originalDataByRealIds.isSuccess()) { throw new ServiceException("数据不存在"); From c5fa431f4682118b998b1e961ce098de648e5050 Mon Sep 17 00:00:00 2001 From: ty <1577900710@qq.com> Date: Thu, 14 Dec 2023 10:31:21 +0800 Subject: [PATCH 07/11] =?UTF-8?q?=E8=A7=86=E9=A2=91=E6=B5=81=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=B0=E5=A2=9E=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../station/controller/StationVideoTypeController.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/controller/StationVideoTypeController.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/controller/StationVideoTypeController.java index 45f0e90..4c47925 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/controller/StationVideoTypeController.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/controller/StationVideoTypeController.java @@ -31,9 +31,13 @@ import org.springblade.core.boot.ctrl.BladeController; import org.springblade.core.log.annotation.ApiLog; import org.springblade.core.mp.support.Condition; import org.springblade.core.mp.support.Query; +import org.springblade.core.secure.BladeUser; +import org.springblade.core.secure.utils.AuthUtil; import org.springblade.core.tool.api.R; import org.springblade.core.tool.utils.Func; import org.springblade.core.tool.utils.ObjectUtil; +import org.springblade.core.tool.utils.StringUtil; +import org.springblade.system.entity.AuthClient; import org.springblade.system.entity.Dept; import org.springblade.system.feign.ISysClient; import org.springframework.beans.factory.annotation.Value; @@ -253,6 +257,12 @@ public class StationVideoTypeController extends BladeController { @ApiOperation(value = "更新Flv配置列表", notes = "更新Flv配置列表") public R updateFlvVideoConfig(@RequestBody VideoConfigEntity req) { if (ObjectUtil.isNotEmpty(req)) { + if(StringUtil.isBlank(req.getSavePeople())){ + String userName = AuthUtil.getNickName(); + if (StringUtil.isNotBlank(userName)){ + req.setSavePeople(userName); + } + } boolean b = videoConfigService.saveOrUpdate(req); if (b) { return R.success("更新视频配置成功"); From 911bdf17e0b123e033da694ad29e3b8aee79ea94 Mon Sep 17 00:00:00 2001 From: liwen Date: Thu, 14 Dec 2023 16:23:48 +0800 Subject: [PATCH 08/11] =?UTF-8?q?add:=20=E6=96=B0=E5=A2=9E=E6=BC=94?= =?UTF-8?q?=E7=BB=83=E8=AE=B0=E5=BD=95=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hzims/safeproduct/dto/RehearsalYearDTO.java | 23 +++ .../safeproduct/entity/RehearsalRecordEntity.java | 93 +++++++++++ .../safeproduct/enums/RehearsalStatusEnum.java | 32 ++++ .../hzims/safeproduct/vo/RehearsalMonthVO.java | 31 ++++ .../hnac/hzims/safeproduct/vo/RehearsalYearVO.java | 53 ++++++ .../controller/RehearsalRecordController.java | 93 +++++++++++ .../safeproduct/mapper/RehearsalRecordMapper.java | 54 +++++++ .../safeproduct/mapper/RehearsalRecordMapper.xml | 65 ++++++++ .../service/IRehearsalRecordService.java | 40 +++++ .../service/impl/RehearsalRecordServiceImpl.java | 178 +++++++++++++++++++++ .../safeproduct/src/main/resources/db/1.0.1.sql | 30 +++- 11 files changed, 691 insertions(+), 1 deletion(-) create mode 100644 hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/dto/RehearsalYearDTO.java create mode 100644 hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/RehearsalRecordEntity.java create mode 100644 hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/enums/RehearsalStatusEnum.java create mode 100644 hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/RehearsalMonthVO.java create mode 100644 hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/RehearsalYearVO.java create mode 100644 hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/RehearsalRecordController.java create mode 100644 hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/RehearsalRecordMapper.java create mode 100644 hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/RehearsalRecordMapper.xml create mode 100644 hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/IRehearsalRecordService.java create mode 100644 hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/RehearsalRecordServiceImpl.java diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/dto/RehearsalYearDTO.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/dto/RehearsalYearDTO.java new file mode 100644 index 0000000..6ce369d --- /dev/null +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/dto/RehearsalYearDTO.java @@ -0,0 +1,23 @@ +package com.hnac.hzims.safeproduct.dto; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * @author liwen + * @date 2023-12-14 + */ +@Data +@ApiModel(value = "演练年度统计DTO类") +public class RehearsalYearDTO { + + @ApiModelProperty("单位") + private String unit; + + @ApiModelProperty("日期") + private String dateTime; + + @ApiModelProperty("完成数") + private Long finishedNum; +} diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/RehearsalRecordEntity.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/RehearsalRecordEntity.java new file mode 100644 index 0000000..1ae07b8 --- /dev/null +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/RehearsalRecordEntity.java @@ -0,0 +1,93 @@ +package com.hnac.hzims.safeproduct.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.springblade.core.mp.base.BaseEntity; + +import javax.validation.constraints.Max; +import javax.validation.constraints.Min; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import java.util.Date; + +/** + * @author liwen + * @date 2023-12-13 + */ +@Data +@EqualsAndHashCode(callSuper = true) +@TableName("hzims_rehearsal_record") +@ApiModel(value = "演练记录实体类") +public class RehearsalRecordEntity extends BaseEntity { + + @Size(max = 50, message = "编码字段长度不能超过50") + @ApiModelProperty("编码") + private String code; + + @NotNull + @Size(max = 50, message = "单位字段长度不能超过50") + @ApiModelProperty("单位") + private String unit; + + @NotNull + @Size(max = 50, message = "演练科目字段长度不能超过50") + @ApiModelProperty("演练科目") + private String subject; + + @NotNull + @ApiModelProperty("演练计划开始时间") + private Date scheduledStartTime; + + @NotNull + @ApiModelProperty("演练计划结束时间") + private Date scheduledEndTime; + + @NotNull + @Size(max = 255, message = "演练地点字段长度不能超过255") + @ApiModelProperty("演练地点") + private String location; + + @Min(value = 0, message = "参演人数不能小于0") + @Max(value = 1000000000, message = "参演人数超出限制范围") + @ApiModelProperty("参演人数") + private Integer peopleNum; + + @NotNull + @Size(max = 10, message = "总指挥字段长度不能超过10") + @ApiModelProperty("总指挥") + private String commander; + + @ApiModelProperty("演练实际开始时间") + private Date actualStartTime; + + @ApiModelProperty("演练实际结束时间") + private Date actualEndTime; + + @Size(max = 250, message = "演练记录字段长度不能超过250") + @ApiModelProperty("演练记录") + private String record; + + @Size(max = 250, message = "演练评价字段长度不能超过250") + @ApiModelProperty("演练评价") + private String comment; + + @Size(max = 20, message = "演练方式字段长度不能超过20") + @ApiModelProperty("演练方式") + private String rehearsalMethod; + + @NotNull + @Size(max = 20, message = "演练状态字段长度不能超过20") + @ApiModelProperty("演练状态") + private String rehearsalStatus; + + @Size(max = 1000, message = "演练图片字段长度不能超过1000") + @ApiModelProperty("演练图片") + private String imgPath; + + @Size(max = 1000, message = "演练附件字段长度不能超过1000") + @ApiModelProperty("演练附件") + private String filePath; +} diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/enums/RehearsalStatusEnum.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/enums/RehearsalStatusEnum.java new file mode 100644 index 0000000..864af73 --- /dev/null +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/enums/RehearsalStatusEnum.java @@ -0,0 +1,32 @@ +package com.hnac.hzims.safeproduct.enums; + +/** + * 演练状态枚举类 + * + * @author liwen + * @date 2023-12-14 + */ +public enum RehearsalStatusEnum { + + WAITING("WAITING", "未开始"), + UNFINISHED("UNFINISHED", "未完成"), + FINISHED("FINISHED", "已完成"); + + private final String value; + + private final String desc; + + RehearsalStatusEnum(String value, String desc) { + this.value = value; + this.desc = desc; + } + + public String getValue() { + return value; + } + + public String getDesc() { + return desc; + } + +} diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/RehearsalMonthVO.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/RehearsalMonthVO.java new file mode 100644 index 0000000..0bc8aaf --- /dev/null +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/RehearsalMonthVO.java @@ -0,0 +1,31 @@ +package com.hnac.hzims.safeproduct.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @author liwen + * @date 2023-12-14 + */ +@Data +@ApiModel(value = "演练月度统计VO类") +public class RehearsalMonthVO { + + @ApiModelProperty("单位") + private String unit; + + @ApiModelProperty("计划任务总数") + private Long scheduledTaskNum; + + @ApiModelProperty("已完成任务/次") + private Long finishedTaskNum; + + @ApiModelProperty("未完成任务/次") + private Long unfinishedTaskNum; + + @ApiModelProperty("任务完成率") + private BigDecimal taskCompletionRate; +} diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/RehearsalYearVO.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/RehearsalYearVO.java new file mode 100644 index 0000000..97556b8 --- /dev/null +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/RehearsalYearVO.java @@ -0,0 +1,53 @@ +package com.hnac.hzims.safeproduct.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * @author liwen + * @date 2023-12-14 + */ +@Data +@ApiModel(value = "演练年度统计VO类") +public class RehearsalYearVO { + + @ApiModelProperty("单位") + private String unit; + + @ApiModelProperty("1月完成数") + private Long januaryNum; + + @ApiModelProperty("2月完成数") + private Long februaryNum; + + @ApiModelProperty("3月完成数") + private Long marchNum; + + @ApiModelProperty("4月完成数") + private Long aprilNum; + + @ApiModelProperty("5月完成数") + private Long mayNum; + + @ApiModelProperty("6月完成数") + private Long juneNum; + + @ApiModelProperty("7月完成数") + private Long julyNum; + + @ApiModelProperty("8月完成数") + private Long augustNum; + + @ApiModelProperty("9月完成数") + private Long septemberNum; + + @ApiModelProperty("10月完成数") + private Long octoberNum; + + @ApiModelProperty("11月完成数") + private Long novemberNum; + + @ApiModelProperty("12月完成数") + private Long decemberNum; +} diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/RehearsalRecordController.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/RehearsalRecordController.java new file mode 100644 index 0000000..3d81120 --- /dev/null +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/RehearsalRecordController.java @@ -0,0 +1,93 @@ +package com.hnac.hzims.safeproduct.controller; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; +import com.hnac.hzims.common.utils.Condition; +import com.hnac.hzims.safeproduct.entity.RehearsalRecordEntity; +import com.hnac.hzims.safeproduct.service.IRehearsalRecordService; +import com.hnac.hzims.safeproduct.vo.RehearsalMonthVO; +import com.hnac.hzims.safeproduct.vo.RehearsalYearVO; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; +import lombok.AllArgsConstructor; +import org.springblade.core.boot.ctrl.BladeController; +import org.springblade.core.mp.support.Query; +import org.springblade.core.tool.api.R; +import org.springframework.web.bind.annotation.*; +import springfox.documentation.annotations.ApiIgnore; + +import javax.validation.Valid; +import java.util.Map; + +/** + * 演练记录接口类 + * + * @author liwen + * @date 2023-12-13 + */ +@RestController +@AllArgsConstructor +@RequestMapping("/rehearsal") +@Api(value = "演练记录", tags = "演练记录接口") +public class RehearsalRecordController extends BladeController { + + private final IRehearsalRecordService rehearsalRecordService; + + @PostMapping("/save") + @ApiOperation(value = "新增") + @ApiOperationSupport(order = 1) + public R save(@Valid @RequestBody RehearsalRecordEntity rehearsalRecord) { + return R.status(rehearsalRecordService.saveRehearsal(rehearsalRecord)); + } + + @PostMapping("/update") + @ApiOperation(value = "修改") + @ApiOperationSupport(order = 2) + public R update(@Valid @RequestBody RehearsalRecordEntity rehearsalRecord) { + return R.status(rehearsalRecordService.updateById(rehearsalRecord)); + } + + @PostMapping("/remove") + @ApiOperation(value = "删除") + @ApiOperationSupport(order = 3) + public R remove(@RequestParam Long id) { + return R.status(rehearsalRecordService.removeById(id)); + } + + @GetMapping("/detail") + @ApiOperation(value = "详情") + @ApiOperationSupport(order = 4) + public R detail(@RequestParam Long id) { + return R.data(rehearsalRecordService.getById(id)); + } + + @GetMapping("/page") + @ApiImplicitParams({ + @ApiImplicitParam() + }) + @ApiOperation(value = "分页") + @ApiOperationSupport(order = 5) + public R> page(@ApiIgnore @RequestParam Map param, Query query) { + IPage page = rehearsalRecordService.page(Condition.getPage(query), + Condition.getQueryWrapper(param, RehearsalRecordEntity.class)); + return R.data(page); + } + + @GetMapping("/dataByMonth") + @ApiOperation(value = "月度统计表") + @ApiOperationSupport(order = 6) + public R> dataByMonth(@RequestParam String month, Query query) { + IPage page = rehearsalRecordService.dataByMonth(month, query); + return R.data(page); + } + + @GetMapping("/dataByYear") + @ApiOperation(value = "年度统计表") + @ApiOperationSupport(order = 7) + public R> dataByYear(@RequestParam String year, Query query) { + IPage page = rehearsalRecordService.dataByYear(year, query); + return R.data(page); + } +} diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/RehearsalRecordMapper.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/RehearsalRecordMapper.java new file mode 100644 index 0000000..9d60ecf --- /dev/null +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/RehearsalRecordMapper.java @@ -0,0 +1,54 @@ +package com.hnac.hzims.safeproduct.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.hnac.hzims.safeproduct.dto.RehearsalYearDTO; +import com.hnac.hzims.safeproduct.entity.RehearsalRecordEntity; +import com.hnac.hzims.safeproduct.vo.RehearsalMonthVO; +import com.hnac.hzims.safeproduct.vo.RehearsalYearVO; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * 演练记录Mapper类 + * + * @author liwen + * @date 2023-12-13 + */ +@Mapper +public interface RehearsalRecordMapper extends BaseMapper { + + /** + * 查询当月各单位的演练总数 + * @param page 分页类 + * @param month 月份 + * @return 当月的演练总数据 + */ + IPage selectByMonth(IPage page, @Param("month") String month); + + /** + * 查询当月各单位已完成的演练数据 + * @param page 分页类 + * @param month 月份 + * @return 当月的已完成数据 + */ + IPage selectFinishedDataByMonth(IPage page, @Param("month") String month); + + /** + * 查询当年的所有单位 + * @param page 分页类 + * @param year 年份 + * @return 年度单位数据 + */ + IPage selectUnitByYear(IPage page, @Param("year") String year); + + /** + * 查询各单位全年已完成的演练数据 + * @param unitList 单元列表 + * @param year 年份 + * @return 单位各月的数据列表 + */ + List selectFinishedDataByUnit(@Param("unitList") List unitList, @Param("year") String year); +} diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/RehearsalRecordMapper.xml b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/RehearsalRecordMapper.xml new file mode 100644 index 0000000..fbe9efc --- /dev/null +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/RehearsalRecordMapper.xml @@ -0,0 +1,65 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/IRehearsalRecordService.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/IRehearsalRecordService.java new file mode 100644 index 0000000..ae85eda --- /dev/null +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/IRehearsalRecordService.java @@ -0,0 +1,40 @@ +package com.hnac.hzims.safeproduct.service; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.service.IService; +import com.hnac.hzims.safeproduct.entity.RehearsalRecordEntity; +import com.hnac.hzims.safeproduct.vo.RehearsalMonthVO; +import com.hnac.hzims.safeproduct.vo.RehearsalYearVO; +import org.springblade.core.mp.support.Query; + +/** + * 演练记录服务类 + * + * @author liwen + * @date 2023-12-13 + */ +public interface IRehearsalRecordService extends IService { + + /** + * 演练月度数据 + * @param month 月份 + * @param query 分页类 + * @return 月度统计分页 + */ + IPage dataByMonth(String month, Query query); + + /** + * 演练年度数据 + * @param year 年份 + * @param query 分页类 + * @return 年度统计分页 + */ + IPage dataByYear(String year, Query query); + + /** + * 新增演练 + * @param rehearsalRecord 演练记录实体类 + * @return 新增是否成功 + */ + boolean saveRehearsal(RehearsalRecordEntity rehearsalRecord); +} diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/RehearsalRecordServiceImpl.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/RehearsalRecordServiceImpl.java new file mode 100644 index 0000000..98ed350 --- /dev/null +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/RehearsalRecordServiceImpl.java @@ -0,0 +1,178 @@ +package com.hnac.hzims.safeproduct.service.impl; + +import cn.hutool.core.date.DatePattern; +import com.alibaba.excel.util.CollectionUtils; +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.hnac.hzims.common.logs.utils.StringUtils; +import com.hnac.hzims.safeproduct.dto.RehearsalYearDTO; +import com.hnac.hzims.safeproduct.entity.RehearsalRecordEntity; +import com.hnac.hzims.safeproduct.mapper.RehearsalRecordMapper; +import com.hnac.hzims.safeproduct.service.IRehearsalRecordService; +import com.hnac.hzims.safeproduct.vo.RehearsalMonthVO; +import com.hnac.hzims.safeproduct.vo.RehearsalYearVO; +import org.springblade.core.mp.support.Query; +import org.springframework.stereotype.Service; + +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.util.Date; +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; + +/** + * 演练记录服务实现类 + * + * @author liwen + * @date 2023-12-13 + */ +@Service +public class RehearsalRecordServiceImpl extends ServiceImpl implements IRehearsalRecordService { + + /** + * 演练月度数据 + */ + @Override + public IPage dataByMonth(String month, Query query) { + IPage page = new Page<>(query.getCurrent(), query.getSize()); + // 查询当月各单位的演练总数 + IPage unitPage = baseMapper.selectByMonth(page, month); + List unitList = unitPage.getRecords(); + // 查询当月各单位已完成的演练数据 + IPage finishedPage = baseMapper.selectFinishedDataByMonth(page, month); + List finishedList = finishedPage.getRecords(); + // 处理统计数据 + for (RehearsalMonthVO unit : unitList) { + Long taskNum = unit.getScheduledTaskNum(); + Optional finishedRehearsal = finishedList.stream().filter(x -> x.getUnit().equals(unit.getUnit())).findFirst(); + Long finishedTaskNum = finishedRehearsal.isPresent() ? finishedRehearsal.get().getFinishedTaskNum() : 0L; + unit.setFinishedTaskNum(finishedTaskNum); + unit.setUnfinishedTaskNum(taskNum - finishedTaskNum); + BigDecimal taskDecimal = new BigDecimal(taskNum); + BigDecimal finishedDecimal = new BigDecimal(finishedTaskNum); + unit.setTaskCompletionRate(finishedDecimal.divide(taskDecimal, RoundingMode.HALF_UP).multiply(new BigDecimal("100")) + .setScale(2, RoundingMode.HALF_UP)); + } + unitPage.setRecords(unitList); + return unitPage; + } + + /** + * 演练年度数据 + */ + @Override + public IPage dataByYear(String year, Query query) { + IPage page = new Page<>(query.getCurrent(), query.getSize()); + // 查询当年的所有单位 + IPage unitPage = baseMapper.selectUnitByYear(page, year); + List records = unitPage.getRecords(); + List unitList = records.stream().map(RehearsalYearVO::getUnit).collect(Collectors.toList()); + // 查询各单位全年已完成的演练数据 + List unitMonthDataList = baseMapper.selectFinishedDataByUnit(unitList, year); + // 将各单位每个月的演练数据写入统计列表 + unitMonthDataList.forEach(data -> { + RehearsalYearVO rehearsalYearVO = records.stream().filter(x -> x.getUnit().equals(data.getUnit())) + .collect(Collectors.toList()).get(0); + // 根据月份匹配写入对应字段 + switch (data.getDateTime()) { + case "01": + rehearsalYearVO.setJanuaryNum(data.getFinishedNum()); + break; + case "02": + rehearsalYearVO.setFebruaryNum(data.getFinishedNum()); + break; + case "03": + rehearsalYearVO.setMarchNum(data.getFinishedNum()); + break; + case "04": + rehearsalYearVO.setAprilNum(data.getFinishedNum()); + break; + case "05": + rehearsalYearVO.setMayNum(data.getFinishedNum()); + break; + case "06": + rehearsalYearVO.setJuneNum(data.getFinishedNum()); + break; + case "07": + rehearsalYearVO.setJulyNum(data.getFinishedNum()); + break; + case "08": + rehearsalYearVO.setAugustNum(data.getFinishedNum()); + break; + case "09": + rehearsalYearVO.setSeptemberNum(data.getFinishedNum()); + break; + case "10": + rehearsalYearVO.setOctoberNum(data.getFinishedNum()); + break; + case "11": + rehearsalYearVO.setNovemberNum(data.getFinishedNum()); + break; + case "12": + rehearsalYearVO.setDecemberNum(data.getFinishedNum()); + } + }); + unitPage.setRecords(records); + return unitPage; + } + + /** + * 新增演练 + */ + @Override + public boolean saveRehearsal(RehearsalRecordEntity rehearsalRecord) { + // 获取当月时间(yyyymm) + String currentMonth = DatePattern.SIMPLE_MONTH_FORMAT.format(new Date()); + // 查询是否存在同月编号 + String lastCode = getLastCode(currentMonth); + // 若不存在,新增编号 + if (StringUtils.isNull(lastCode)) { + String code = "YLJL" + currentMonth + "001"; + rehearsalRecord.setCode(code); + return this.save(rehearsalRecord); + } + // 若存在,编号递增 + String oldNum = lastCode.substring(lastCode.length() - 3); + int value = Integer.parseInt(oldNum) + 1; + String code; + // 根据数位拼接编号 + if (value < 10) { + code = "YLJL" + currentMonth + "00" + value; + } else if (value < 100) { + code = "YLJL" + currentMonth + "0" + value; + } else { + code = "YLJL" + currentMonth + value; + } + rehearsalRecord.setCode(code); + return this.save(rehearsalRecord); + } + + /** + * 查询是否存在同月编号 + * @param currentMonth 当月 + * @return 存在则返回上一编号,否则返回null + */ + private String getLastCode(String currentMonth) { + String month = currentMonth.substring(currentMonth.length() - 2); + List list = getRehearsalByMonth(month); + if (CollectionUtils.isEmpty(list)) { + return null; + } + return list.get(0).getCode(); + } + + /** + * 查询当月演练记录 + * @param month 当月 + * @return 当月演练数据表 + */ + public List getRehearsalByMonth(String month) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.lambda().like(RehearsalRecordEntity::getCreateTime, month) + .orderByDesc(RehearsalRecordEntity::getCode); + return this.list(queryWrapper); + } +} diff --git a/hzims-service/safeproduct/src/main/resources/db/1.0.1.sql b/hzims-service/safeproduct/src/main/resources/db/1.0.1.sql index f63ae4c..4138082 100644 --- a/hzims-service/safeproduct/src/main/resources/db/1.0.1.sql +++ b/hzims-service/safeproduct/src/main/resources/db/1.0.1.sql @@ -9,4 +9,32 @@ create table document_management update_time datetime default current_timestamp on update current_timestamp comment '更新时间', is_deleted tinyint default 0 comment '逻辑删除' -) comment '文档管理'; \ No newline at end of file +) comment '文档管理'; + +CREATE TABLE `hzims`.`hzims_rehearsal_record` ( + `id` bigint(20) NOT NULL COMMENT '主键id', + `code` varchar(50) NOT NULL COMMENT '编号', + `unit` varchar(50) NOT NULL COMMENT '单位', + `subject` varchar(50) NOT NULL COMMENT '演练科目', + `scheduled_start_time` datetime NOT NULL COMMENT '演练计划开始时间', + `scheduled_end_time` datetime NOT NULL COMMENT '演练计划结束时间', + `location` varchar(255) NOT NULL COMMENT '演练地点', + `people_num` int(10) NOT NULL DEFAULT '0' COMMENT '参演人数', + `commander` varchar(10) NOT NULL COMMENT '总指挥', + `actual_start_time` datetime DEFAULT NULL COMMENT '演练实际开始时间', + `actual_end_time` datetime DEFAULT NULL COMMENT '演练实际结束时间', + `record` varchar(250) DEFAULT '' COMMENT '演练记录', + `comment` varchar(250) DEFAULT '' DEFAULT '' COMMENT '演练评价', + `rehearsal_method` varchar(20) DEFAULT '' COMMENT '演练方式', + `rehearsal_status` varchar(20) NOT NULL DEFAULT 'WAITING' COMMENT '演练状态', + `img_path` varchar(1000) NOT NULL DEFAULT '' COMMENT '演练图片', + `file_path` varchar(1000) NOT NULL DEFAULT '' COMMENT '演练附件', + `create_user` bigint(20) NOT NULL DEFAULT '-1' COMMENT '创建人', + `create_dept` bigint(20) NOT NULL DEFAULT '-1' COMMENT '创建部门', + `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `update_user` bigint(20) DEFAULT '-1' COMMENT '更新人', + `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后更新时间', + `status` int(2) NOT NULL DEFAULT '1' COMMENT '状态', + `is_deleted` int(2) NOT NULL DEFAULT '0' COMMENT '逻辑删除状态:0-未删除,1-删除', + PRIMARY KEY (`id`) USING BTREE +) ENGINE=INNODB CHARACTER SET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='演练记录表' ROW_FORMAT=Dynamic; \ No newline at end of file From dd0896c8755e340393d46e0d08914fc635f7f758 Mon Sep 17 00:00:00 2001 From: yang_shj <1069818635@QQ.com> Date: Fri, 15 Dec 2023 09:00:26 +0800 Subject: [PATCH 09/11] =?UTF-8?q?#=E5=85=89=E4=BC=8F=E5=AE=9E=E4=BD=93?= =?UTF-8?q?=E7=B1=BB=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/hnac/hzims/operational/fill/entity/PowerEntity.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/fill/entity/PowerEntity.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/fill/entity/PowerEntity.java index b92ca57..3224311 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/fill/entity/PowerEntity.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/fill/entity/PowerEntity.java @@ -5,14 +5,19 @@ import com.baomidou.mybatisplus.annotation.TableName; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import lombok.EqualsAndHashCode; import org.springblade.core.tenant.mp.TenantEntity; import java.io.Serializable; +/** + * @author ysj + */ +@EqualsAndHashCode(callSuper = true) @Data @TableName("hzims_fill_power") -@ApiModel(value="PowerEntity对象", description="电站填报") +@ApiModel(value="PowerEntity对象", description="光伏站填报") public class PowerEntity extends TenantEntity implements Serializable { @ApiModelProperty("月份") From acc979538fbcb88047e14ae460ef58534164edb3 Mon Sep 17 00:00:00 2001 From: liwen Date: Fri, 15 Dec 2023 11:34:09 +0800 Subject: [PATCH 10/11] =?UTF-8?q?update:=20=E4=BF=AE=E6=94=B9=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E3=80=81=E4=BF=AE=E6=94=B9=E6=BC=94=E7=BB=83=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hzims/safeproduct/dto/RehearsalRecordDTO.java | 95 ++++++++++++++++++++++ .../safeproduct/entity/RehearsalRecordEntity.java | 6 +- .../safeproduct/enums/RehearsalMethodEnum.java | 31 +++++++ .../controller/RehearsalRecordController.java | 18 +++- .../service/IRehearsalRecordService.java | 12 ++- .../service/impl/RehearsalRecordServiceImpl.java | 70 +++++++++++----- 6 files changed, 206 insertions(+), 26 deletions(-) create mode 100644 hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/dto/RehearsalRecordDTO.java create mode 100644 hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/enums/RehearsalMethodEnum.java diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/dto/RehearsalRecordDTO.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/dto/RehearsalRecordDTO.java new file mode 100644 index 0000000..4500ea5 --- /dev/null +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/dto/RehearsalRecordDTO.java @@ -0,0 +1,95 @@ +package com.hnac.hzims.safeproduct.dto; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.springblade.core.mp.base.BaseEntity; + +import javax.validation.constraints.Max; +import javax.validation.constraints.Min; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import java.util.Date; + +/** + * @author liwen + * @date 2023-12-15 + */ +@Data +@EqualsAndHashCode(callSuper = true) +@ApiModel(value = "演练记录DTO类") +public class RehearsalRecordDTO extends BaseEntity { + + @Size(max = 50, message = "编码字段长度不能超过50") + @ApiModelProperty("编码") + private String code; + + @NotNull + @Size(max = 50, message = "单位字段长度不能超过50") + @ApiModelProperty("单位") + private String unit; + + @NotNull + @Size(max = 50, message = "演练科目字段长度不能超过50") + @ApiModelProperty("演练科目") + private String subject; + + @NotNull + @ApiModelProperty("演练计划开始时间") + private Date scheduledStartTime; + + @NotNull + @ApiModelProperty("演练计划结束时间") + private Date scheduledEndTime; + + @NotNull + @Size(max = 255, message = "演练地点字段长度不能超过255") + @ApiModelProperty("演练地点") + private String location; + + @Min(value = 0, message = "参演人数不能小于0") + @Max(value = 1000, message = "参演人数字段长度超出限制范围") + @ApiModelProperty("参演人数") + private Integer peopleNum; + + @Size(max = 5000, message = "参演人员字段长度超出限制范围") + @ApiModelProperty("参演人员") + private String[] people; + + @NotNull + @Size(max = 10, message = "总指挥字段长度不能超过10") + @ApiModelProperty("总指挥") + private String commander; + + @ApiModelProperty("演练实际开始时间") + private Date actualStartTime; + + @ApiModelProperty("演练实际结束时间") + private Date actualEndTime; + + @Size(max = 250, message = "演练记录字段长度不能超过250") + @ApiModelProperty("演练记录") + private String record; + + @Size(max = 250, message = "演练评价字段长度不能超过250") + @ApiModelProperty("演练评价") + private String comment; + + @Size(max = 20, message = "演练方式字段长度不能超过20") + @ApiModelProperty("演练方式") + private String rehearsalMethod; + + @NotNull + @Size(max = 20, message = "演练状态字段长度不能超过20") + @ApiModelProperty("演练状态") + private String rehearsalStatus; + + @Size(max = 1000, message = "演练图片字段长度不能超过1000") + @ApiModelProperty("演练图片") + private String[] images; + + @Size(max = 1000, message = "演练附件字段长度不能超过1000") + @ApiModelProperty("演练附件") + private String[] files; +} diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/RehearsalRecordEntity.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/RehearsalRecordEntity.java index 1ae07b8..6d027ea 100644 --- a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/RehearsalRecordEntity.java +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/RehearsalRecordEntity.java @@ -51,10 +51,14 @@ public class RehearsalRecordEntity extends BaseEntity { private String location; @Min(value = 0, message = "参演人数不能小于0") - @Max(value = 1000000000, message = "参演人数超出限制范围") + @Max(value = 1000, message = "参演人数字段长度超出限制范围") @ApiModelProperty("参演人数") private Integer peopleNum; + @Size(max = 5000, message = "参演人员字段长度超出限制范围") + @ApiModelProperty("参演人员") + private String peopleName; + @NotNull @Size(max = 10, message = "总指挥字段长度不能超过10") @ApiModelProperty("总指挥") diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/enums/RehearsalMethodEnum.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/enums/RehearsalMethodEnum.java new file mode 100644 index 0000000..a1cb0f8 --- /dev/null +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/enums/RehearsalMethodEnum.java @@ -0,0 +1,31 @@ +package com.hnac.hzims.safeproduct.enums; + +/** + * 演练方式枚举类 + * + * @author liwen + * @date 2023-12-14 + */ +public enum RehearsalMethodEnum { + + ONLINE("ONLINE", "线上"), + OFFLINE("OFFLINE", "线下"), + MIXED("MIXED", "线上+线下"); + + private final String value; + + private final String desc; + + RehearsalMethodEnum(String value, String desc) { + this.value = value; + this.desc = desc; + } + + public String getValue() { + return value; + } + + public String getDesc() { + return desc; + } +} diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/RehearsalRecordController.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/RehearsalRecordController.java index 3d81120..bef9dfc 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/RehearsalRecordController.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/RehearsalRecordController.java @@ -3,6 +3,7 @@ package com.hnac.hzims.safeproduct.controller; import com.baomidou.mybatisplus.core.metadata.IPage; import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; import com.hnac.hzims.common.utils.Condition; +import com.hnac.hzims.safeproduct.dto.RehearsalRecordDTO; import com.hnac.hzims.safeproduct.entity.RehearsalRecordEntity; import com.hnac.hzims.safeproduct.service.IRehearsalRecordService; import com.hnac.hzims.safeproduct.vo.RehearsalMonthVO; @@ -38,15 +39,15 @@ public class RehearsalRecordController extends BladeController { @PostMapping("/save") @ApiOperation(value = "新增") @ApiOperationSupport(order = 1) - public R save(@Valid @RequestBody RehearsalRecordEntity rehearsalRecord) { + public R save(@Valid @RequestBody RehearsalRecordDTO rehearsalRecord) { return R.status(rehearsalRecordService.saveRehearsal(rehearsalRecord)); } @PostMapping("/update") @ApiOperation(value = "修改") @ApiOperationSupport(order = 2) - public R update(@Valid @RequestBody RehearsalRecordEntity rehearsalRecord) { - return R.status(rehearsalRecordService.updateById(rehearsalRecord)); + public R update(@Valid @RequestBody RehearsalRecordDTO rehearsalRecord) { + return R.status(rehearsalRecordService.updateRehearsal(rehearsalRecord)); } @PostMapping("/remove") @@ -65,7 +66,9 @@ public class RehearsalRecordController extends BladeController { @GetMapping("/page") @ApiImplicitParams({ - @ApiImplicitParam() + @ApiImplicitParam(name = "unit", value = "单位", dataType = "query", paramType = "string"), + @ApiImplicitParam(name = "actualStartTime", value = "实际开始时间", dataType = "query", paramType = "string"), + @ApiImplicitParam(name = "actualEndTime", value = "实际结束时间", dataType = "query", paramType = "string") }) @ApiOperation(value = "分页") @ApiOperationSupport(order = 5) @@ -90,4 +93,11 @@ public class RehearsalRecordController extends BladeController { IPage page = rehearsalRecordService.dataByYear(year, query); return R.data(page); } + + @GetMapping("/exportRehearsalData") + @ApiOperation(value = "导出演练页数据") + @ApiOperationSupport(order = 8) + public void exportRehearsalData() { + + } } diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/IRehearsalRecordService.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/IRehearsalRecordService.java index ae85eda..0cb3e1f 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/IRehearsalRecordService.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/IRehearsalRecordService.java @@ -2,6 +2,7 @@ package com.hnac.hzims.safeproduct.service; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.IService; +import com.hnac.hzims.safeproduct.dto.RehearsalRecordDTO; import com.hnac.hzims.safeproduct.entity.RehearsalRecordEntity; import com.hnac.hzims.safeproduct.vo.RehearsalMonthVO; import com.hnac.hzims.safeproduct.vo.RehearsalYearVO; @@ -33,8 +34,15 @@ public interface IRehearsalRecordService extends IService /** * 新增演练 - * @param rehearsalRecord 演练记录实体类 + * @param rehearsalRecord 演练记录DTO类 * @return 新增是否成功 */ - boolean saveRehearsal(RehearsalRecordEntity rehearsalRecord); + boolean saveRehearsal(RehearsalRecordDTO rehearsalRecord); + + /** + * 修改演练 + * @param rehearsalRecord 演练记录DTO类 + * @return 更新是否成功 + */ + boolean updateRehearsal(RehearsalRecordDTO rehearsalRecord); } diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/RehearsalRecordServiceImpl.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/RehearsalRecordServiceImpl.java index 98ed350..007f7ec 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/RehearsalRecordServiceImpl.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/RehearsalRecordServiceImpl.java @@ -7,6 +7,7 @@ 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.hnac.hzims.common.logs.utils.StringUtils; +import com.hnac.hzims.safeproduct.dto.RehearsalRecordDTO; import com.hnac.hzims.safeproduct.dto.RehearsalYearDTO; import com.hnac.hzims.safeproduct.entity.RehearsalRecordEntity; import com.hnac.hzims.safeproduct.mapper.RehearsalRecordMapper; @@ -14,10 +15,12 @@ import com.hnac.hzims.safeproduct.service.IRehearsalRecordService; import com.hnac.hzims.safeproduct.vo.RehearsalMonthVO; import com.hnac.hzims.safeproduct.vo.RehearsalYearVO; import org.springblade.core.mp.support.Query; +import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import java.math.BigDecimal; import java.math.RoundingMode; +import java.util.Arrays; import java.util.Date; import java.util.List; import java.util.Optional; @@ -37,12 +40,13 @@ public class RehearsalRecordServiceImpl extends ServiceImpl dataByMonth(String month, Query query) { - IPage page = new Page<>(query.getCurrent(), query.getSize()); // 查询当月各单位的演练总数 + IPage page = new Page<>(query.getCurrent(), query.getSize()); IPage unitPage = baseMapper.selectByMonth(page, month); List unitList = unitPage.getRecords(); // 查询当月各单位已完成的演练数据 - IPage finishedPage = baseMapper.selectFinishedDataByMonth(page, month); + IPage page1 = new Page<>(query.getCurrent(), query.getSize()); + IPage finishedPage = baseMapper.selectFinishedDataByMonth(page1, month); List finishedList = finishedPage.getRecords(); // 处理统计数据 for (RehearsalMonthVO unit : unitList) { @@ -123,31 +127,41 @@ public class RehearsalRecordServiceImpl extends ServiceImpl Date: Fri, 15 Dec 2023 15:41:15 +0800 Subject: [PATCH 11/11] =?UTF-8?q?add:=20=E6=BC=94=E7=BB=83=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=E6=96=B0=E5=A2=9E=E7=8A=B6=E6=80=81=E6=9B=B4=E6=94=B9?= =?UTF-8?q?=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1&=E5=AF=BC=E5=87=BA?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/RehearsalRecordController.java | 21 +-- .../hnac/hzims/safeproduct/jobs/RehearsalJob.java | 43 ++++++ .../service/IRehearsalRecordService.java | 24 +++- .../service/impl/RehearsalRecordServiceImpl.java | 154 +++++++++++++++++---- 4 files changed, 203 insertions(+), 39 deletions(-) create mode 100644 hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/jobs/RehearsalJob.java diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/RehearsalRecordController.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/RehearsalRecordController.java index bef9dfc..71b375f 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/RehearsalRecordController.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/RehearsalRecordController.java @@ -3,7 +3,6 @@ package com.hnac.hzims.safeproduct.controller; import com.baomidou.mybatisplus.core.metadata.IPage; import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; import com.hnac.hzims.common.utils.Condition; -import com.hnac.hzims.safeproduct.dto.RehearsalRecordDTO; import com.hnac.hzims.safeproduct.entity.RehearsalRecordEntity; import com.hnac.hzims.safeproduct.service.IRehearsalRecordService; import com.hnac.hzims.safeproduct.vo.RehearsalMonthVO; @@ -19,6 +18,7 @@ import org.springblade.core.tool.api.R; import org.springframework.web.bind.annotation.*; import springfox.documentation.annotations.ApiIgnore; +import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; import java.util.Map; @@ -39,14 +39,14 @@ public class RehearsalRecordController extends BladeController { @PostMapping("/save") @ApiOperation(value = "新增") @ApiOperationSupport(order = 1) - public R save(@Valid @RequestBody RehearsalRecordDTO rehearsalRecord) { + public R save(@Valid @RequestBody RehearsalRecordEntity rehearsalRecord) { return R.status(rehearsalRecordService.saveRehearsal(rehearsalRecord)); } @PostMapping("/update") @ApiOperation(value = "修改") @ApiOperationSupport(order = 2) - public R update(@Valid @RequestBody RehearsalRecordDTO rehearsalRecord) { + public R update(@Valid @RequestBody RehearsalRecordEntity rehearsalRecord) { return R.status(rehearsalRecordService.updateRehearsal(rehearsalRecord)); } @@ -67,8 +67,8 @@ public class RehearsalRecordController extends BladeController { @GetMapping("/page") @ApiImplicitParams({ @ApiImplicitParam(name = "unit", value = "单位", dataType = "query", paramType = "string"), - @ApiImplicitParam(name = "actualStartTime", value = "实际开始时间", dataType = "query", paramType = "string"), - @ApiImplicitParam(name = "actualEndTime", value = "实际结束时间", dataType = "query", paramType = "string") + @ApiImplicitParam(name = "scheduledStartTime", value = "计划开始时间", dataType = "query", paramType = "string"), + @ApiImplicitParam(name = "scheduledEndTime", value = "计划结束时间", dataType = "query", paramType = "string") }) @ApiOperation(value = "分页") @ApiOperationSupport(order = 5) @@ -95,9 +95,14 @@ public class RehearsalRecordController extends BladeController { } @GetMapping("/exportRehearsalData") - @ApiOperation(value = "导出演练页数据") + @ApiImplicitParams({ + @ApiImplicitParam(name = "unit", value = "单位", dataType = "query", paramType = "string"), + @ApiImplicitParam(name = "scheduledStartTime", value = "计划开始时间", dataType = "query", paramType = "string"), + @ApiImplicitParam(name = "scheduledEndTime", value = "计划结束时间", dataType = "query", paramType = "string") + }) + @ApiOperation(value = "演练数据导出") @ApiOperationSupport(order = 8) - public void exportRehearsalData() { - + public void exportRehearsalData(@ApiIgnore @RequestParam Map param, HttpServletResponse response) { + rehearsalRecordService.exportRehearsalData(param, response); } } diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/jobs/RehearsalJob.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/jobs/RehearsalJob.java new file mode 100644 index 0000000..5b69652 --- /dev/null +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/jobs/RehearsalJob.java @@ -0,0 +1,43 @@ +package com.hnac.hzims.safeproduct.jobs; + +import com.hnac.hzims.safeproduct.entity.RehearsalRecordEntity; +import com.hnac.hzims.safeproduct.enums.RehearsalStatusEnum; +import com.hnac.hzims.safeproduct.service.IRehearsalRecordService; +import com.xxl.job.core.biz.model.ReturnT; +import com.xxl.job.core.handler.annotation.XxlJob; +import org.springblade.core.tool.utils.DateUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.Date; +import java.util.List; + +/** + * 演练模块定时任务 + * + * @author liwen + * @date 2023-12-15 + */ +@Component +public class RehearsalJob { + + @Autowired + IRehearsalRecordService rehearsalRecordService; + + @XxlJob("autoChangeRehearsalStatus") + public ReturnT autoChangeRehearsalStatus(String param) { + // 获取时间范围 + Date current = DateUtil.now(); + Date before = DateUtil.minusDays(current, 1); + String today = DateUtil.format(current, "yyyy-mm-dd hh:MM:ss"); + String yesterday = DateUtil.format(before, "yyyy-mm-dd hh:MM:ss"); + // 查询前一天的超时未完成演练记录 + List list = rehearsalRecordService.getWaitingRehearsalInTimeRange(yesterday, today); + list.forEach(x -> { + x.setRehearsalStatus(RehearsalStatusEnum.UNFINISHED.getValue()); + }); + // 将状态置为未完成 + boolean flag = rehearsalRecordService.updateBatchById(list); + return flag ? ReturnT.SUCCESS : ReturnT.FAIL; + } +} diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/IRehearsalRecordService.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/IRehearsalRecordService.java index 0cb3e1f..2ee8bbf 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/IRehearsalRecordService.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/IRehearsalRecordService.java @@ -2,12 +2,15 @@ package com.hnac.hzims.safeproduct.service; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.IService; -import com.hnac.hzims.safeproduct.dto.RehearsalRecordDTO; import com.hnac.hzims.safeproduct.entity.RehearsalRecordEntity; import com.hnac.hzims.safeproduct.vo.RehearsalMonthVO; import com.hnac.hzims.safeproduct.vo.RehearsalYearVO; import org.springblade.core.mp.support.Query; +import javax.servlet.http.HttpServletResponse; +import java.util.List; +import java.util.Map; + /** * 演练记录服务类 * @@ -37,12 +40,27 @@ public interface IRehearsalRecordService extends IService * @param rehearsalRecord 演练记录DTO类 * @return 新增是否成功 */ - boolean saveRehearsal(RehearsalRecordDTO rehearsalRecord); + boolean saveRehearsal(RehearsalRecordEntity rehearsalRecord); /** * 修改演练 * @param rehearsalRecord 演练记录DTO类 * @return 更新是否成功 */ - boolean updateRehearsal(RehearsalRecordDTO rehearsalRecord); + boolean updateRehearsal(RehearsalRecordEntity rehearsalRecord); + + /** + * 演练数据导出 + * @param param 入参 + * @param response 响应类 + */ + void exportRehearsalData(Map param, HttpServletResponse response); + + /** + * 查询时间范围内未开始的演练数据 + * @param startTime 开始时间 + * @param endTime 结束时间 + * @return 演练数据 + */ + List getWaitingRehearsalInTimeRange(String startTime, String endTime); } diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/RehearsalRecordServiceImpl.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/RehearsalRecordServiceImpl.java index 007f7ec..0d8d844 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/RehearsalRecordServiceImpl.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/RehearsalRecordServiceImpl.java @@ -1,29 +1,38 @@ package com.hnac.hzims.safeproduct.service.impl; import cn.hutool.core.date.DatePattern; +import com.alibaba.druid.support.json.JSONUtils; +import com.alibaba.excel.EasyExcel; +import com.alibaba.excel.ExcelWriter; +import com.alibaba.excel.converters.longconverter.LongStringConverter; import com.alibaba.excel.util.CollectionUtils; +import com.alibaba.excel.write.metadata.WriteSheet; +import com.alibaba.excel.write.style.column.SimpleColumnWidthStyleStrategy; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; 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.hnac.hzims.common.logs.utils.StringUtils; -import com.hnac.hzims.safeproduct.dto.RehearsalRecordDTO; import com.hnac.hzims.safeproduct.dto.RehearsalYearDTO; import com.hnac.hzims.safeproduct.entity.RehearsalRecordEntity; +import com.hnac.hzims.safeproduct.enums.RehearsalStatusEnum; import com.hnac.hzims.safeproduct.mapper.RehearsalRecordMapper; import com.hnac.hzims.safeproduct.service.IRehearsalRecordService; import com.hnac.hzims.safeproduct.vo.RehearsalMonthVO; import com.hnac.hzims.safeproduct.vo.RehearsalYearVO; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.log.exception.ServiceException; import org.springblade.core.mp.support.Query; -import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; import java.math.BigDecimal; import java.math.RoundingMode; -import java.util.Arrays; -import java.util.Date; -import java.util.List; -import java.util.Optional; +import java.net.URLEncoder; +import java.util.*; import java.util.stream.Collectors; /** @@ -33,6 +42,7 @@ import java.util.stream.Collectors; * @date 2023-12-13 */ @Service +@Slf4j public class RehearsalRecordServiceImpl extends ServiceImpl implements IRehearsalRecordService { /** @@ -127,7 +137,7 @@ public class RehearsalRecordServiceImpl extends ServiceImpl param, HttpServletResponse response) { + ServletOutputStream outputStream = null; + try { + outputStream = response.getOutputStream(); + String unit = String.valueOf(param.get("unit")); + String startTime = String.valueOf(param.get("scheduledStartTime")); + String endTime = String.valueOf(param.get("scheduledEndTime")); + List rehearsalRecordList = getRehearsalByUnitAndDate(unit, startTime, endTime); + // 设置响应头 + // URLEncoder.encode防止中文乱码 + String fileName = URLEncoder.encode("演练记录表", "UTF-8"); + response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx"); + response.setContentType("application/vnd.ms-excel"); + response.setCharacterEncoding("UTF-8"); + // ExcelWriter初始化 + ExcelWriter excelWriter = EasyExcel + .write(response.getOutputStream()) + .autoCloseStream(Boolean.TRUE) + .registerConverter(new LongStringConverter()) + .registerWriteHandler(new SimpleColumnWidthStyleStrategy(25)) + .build(); + Set excludeColumnFiledNames = new HashSet<>(); + excludeColumnFiledNames.add("peopleName"); + excludeColumnFiledNames.add("commander"); + excludeColumnFiledNames.add("record"); + excludeColumnFiledNames.add("comment"); + excludeColumnFiledNames.add("rehearsalMethod"); + excludeColumnFiledNames.add("imgPath"); + excludeColumnFiledNames.add("filePath"); + excludeColumnFiledNames.add("id"); + excludeColumnFiledNames.add("createUser"); + excludeColumnFiledNames.add("createDept"); + excludeColumnFiledNames.add("createTime"); + excludeColumnFiledNames.add("updateUser"); + excludeColumnFiledNames.add("updateTime"); + excludeColumnFiledNames.add("status"); + excludeColumnFiledNames.add("isDeleted"); + WriteSheet writeSheet = EasyExcel.writerSheet(1, "演练记录表").head(RehearsalRecordEntity.class) + .excludeColumnFiledNames(excludeColumnFiledNames) + .build(); + excelWriter.write(rehearsalRecordList, writeSheet); + excelWriter.finish(); + } catch (Exception e) { + // 重置response + response.reset(); + response.setContentType("application/json"); + response.setCharacterEncoding("utf-8"); + throw new ServiceException("演练数据导出异常: " + e.getMessage()); + } finally { + if (outputStream != null) { + try { + outputStream.close(); + } catch (IOException e) { + log.error("演练导出响应头输出流关闭异常: " + e.getMessage()); + } + } + } } /** @@ -191,20 +272,37 @@ public class RehearsalRecordServiceImpl extends ServiceImpl getRehearsalByUnitAndDate(String unit, String startTime, String endTime) { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + if (!unit.equals("null")) { + queryWrapper.eq(RehearsalRecordEntity::getUnit, unit); + } + if (!startTime.equals("null")) { + queryWrapper.ge(RehearsalRecordEntity::getScheduledStartTime, startTime); + } + if (!endTime.equals("null")) { + queryWrapper.le(RehearsalRecordEntity::getScheduledEndTime, endTime); + } + queryWrapper.orderByDesc(RehearsalRecordEntity::getScheduledEndTime); + return this.list(queryWrapper); + } + + /** + * 查询时间范围内未开始的演练数据 + */ + @Override + public List getWaitingRehearsalInTimeRange(String startTime, String endTime) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.lambda().eq(RehearsalRecordEntity::getRehearsalStatus, RehearsalStatusEnum.WAITING.getValue()) + .ge(RehearsalRecordEntity::getScheduledEndTime, startTime) + .lt(RehearsalRecordEntity::getScheduledEndTime, endTime); + return this.list(queryWrapper); } + }