From e596de5c34baa729d5a4e7984761640660ea7207 Mon Sep 17 00:00:00 2001 From: zhaoxianglong Date: Fri, 12 Jul 2024 09:51:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=AE=BE=E5=A4=87=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E7=9B=B8=E5=85=B3=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../zc/business/controller/DeviceStatus.java | 10 ++ .../business/controller/StatusController.java | 103 ++++++++++-------- .../com/zc/business/mapper/StatusMapper.java | 1 + .../business/service/impl/StatusService.java | 3 + .../mapper/business/StatusMapper.xml | 10 ++ 5 files changed, 80 insertions(+), 47 deletions(-) diff --git a/zc-business/src/main/java/com/zc/business/controller/DeviceStatus.java b/zc-business/src/main/java/com/zc/business/controller/DeviceStatus.java index 44d9df34..85e57e8a 100644 --- a/zc-business/src/main/java/com/zc/business/controller/DeviceStatus.java +++ b/zc-business/src/main/java/com/zc/business/controller/DeviceStatus.java @@ -15,6 +15,7 @@ import com.zc.business.service.impl.StatusService; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import java.io.BufferedReader; @@ -94,6 +95,15 @@ public class DeviceStatus { executor.shutdown(); } + @Scheduled(cron = "0 30 23 * * ?") + //@Scheduled(cron = "0 30 * * * ?") + public void periodicDataClearing() { + StatusService statusService = SpringUtils.getBean(StatusService.class); + LocalDateTime startTime = LocalDateTime.now().minusMonths(UniversalEnum.THREE.getNumber()); + Status status = new Status(); + status.setStartTime(startTime); + statusService.delStatusByTime(status); + } private void extracted(StatusService statusService, DcDevice device, boolean reachable, String packetLossRate) { Status status = new Status(); status.setDeviceNo(device.getStakeMark()); diff --git a/zc-business/src/main/java/com/zc/business/controller/StatusController.java b/zc-business/src/main/java/com/zc/business/controller/StatusController.java index 9ab72129..c66dc55d 100644 --- a/zc-business/src/main/java/com/zc/business/controller/StatusController.java +++ b/zc-business/src/main/java/com/zc/business/controller/StatusController.java @@ -32,7 +32,7 @@ import java.util.*; import java.util.stream.Collectors; -@Api(tags="设备状态") +@Api(tags = "设备状态") @RestController @RequestMapping("/system/status") public class StatusController extends BaseController { @@ -50,14 +50,16 @@ public class StatusController extends BaseController { //设备列表 @ApiOperation("设备状态列表按时间和类型") - @GetMapping ("/tablist") - public TableDataInfo getTabList(Status status) - { - if (status.getDeviceName()!=null) { - status.setDeviceName(status.getDeviceName().replaceAll(UniversalEnum.BLANK_SPACE.getValue(),UniversalEnum.PLUS_SIGN.getValue())); + @GetMapping("/tablist") + public TableDataInfo getTabList(Status status) { + if (status.getDeviceName() != null) { + status.setDeviceName(status.getDeviceName().replaceAll(UniversalEnum.BLANK_SPACE.getValue(), UniversalEnum.PLUS_SIGN.getValue())); } startPage(); - status.setTypes(status.getType().split(UniversalEnum.COMMA.getValue())); + String type = status.getType(); + if (type != null) { + status.setTypes(type.split(UniversalEnum.COMMA.getValue())); + } List listStatus = statusService.listStatusByTypes(status); return getDataTable(listStatus); } @@ -69,12 +71,14 @@ public class StatusController extends BaseController { @ApiOperation("设备状态导出") @Log(title = "【设备状态导出】", businessType = BusinessType.EXPORT) @PostMapping("/export") - public void export(HttpServletResponse response, Status status) - { - if (status.getDeviceName()!=null) { - status.setDeviceName(status.getDeviceName().replaceAll(UniversalEnum.BLANK_SPACE.getValue(),UniversalEnum.PLUS_SIGN.getValue())); + public void export(HttpServletResponse response, Status status) { + if (status.getDeviceName() != null) { + status.setDeviceName(status.getDeviceName().replaceAll(UniversalEnum.BLANK_SPACE.getValue(), UniversalEnum.PLUS_SIGN.getValue())); + } + String type = status.getType(); + if (type != null) { + status.setTypes(type.split(UniversalEnum.COMMA.getValue())); } - status.setTypes(status.getType().split(UniversalEnum.COMMA.getValue())); List listStatus = statusService.export(status); ExcelUtil util = new ExcelUtil<>(Status.class); util.exportExcel(response, listStatus, UniversalEnum.DEVICE_STATUS_LIST.getValue()); @@ -84,26 +88,33 @@ public class StatusController extends BaseController { @ApiOperation("设备状态柱状图按时间和类型") @GetMapping("/list") public AjaxResult getStatusList(Status status) { - if (status.getDeviceName()!=null) { - status.setDeviceName(status.getDeviceName().replaceAll(UniversalEnum.BLANK_SPACE.getValue(),UniversalEnum.PLUS_SIGN.getValue())); + if (status.getDeviceName() != null) { + status.setDeviceName(status.getDeviceName().replaceAll(UniversalEnum.BLANK_SPACE.getValue(), UniversalEnum.PLUS_SIGN.getValue())); } LocalDateTime todayStart = status.getStartTime().truncatedTo(ChronoUnit.DAYS); LocalDateTime currentTime = status.getTime().truncatedTo(ChronoUnit.DAYS).plusDays(UniversalEnum.ONE.getNumber()); status.setStartTime(todayStart); status.setTime(currentTime); - String[] types = status.getType().split(UniversalEnum.COMMA.getValue()); - status.setTypes(types); + String statusType = status.getType(); + String[] types = null; + if (statusType != null) { + + types = statusType.split(UniversalEnum.COMMA.getValue()); + status.setTypes(types); + } Map> maps = new HashMap<>(); List statuses = statusService.getStatusList(status); - for (String type : types) { - Map collect = statuses.stream().filter(item -> Objects.equals(item.getType(), type)) - .collect(Collectors.toMap( - item -> item.getTime().getYear() + UniversalEnum.SHORT_BAR.getValue() + item.getTime().getMonthValue() + UniversalEnum.SHORT_BAR.getValue() + item.getTime().getDayOfMonth(), - Status::getSuccessRate - )); - maps.put(type, collect); + if (types != null) { + for (String type : types) { + Map collect = statuses.stream().filter(item -> Objects.equals(item.getType(), type)) + .collect(Collectors.toMap( + item -> item.getTime().getYear() + UniversalEnum.SHORT_BAR.getValue() + item.getTime().getMonthValue() + UniversalEnum.SHORT_BAR.getValue() + item.getTime().getDayOfMonth(), + Status::getSuccessRate + )); + maps.put(type, collect); + } } return AjaxResult.success(maps); } @@ -111,10 +122,9 @@ public class StatusController extends BaseController { //按时间划分设备柱状图 @ApiOperation("更新缓存规则") - @GetMapping ("/rule") - public AjaxResult setRule(String rule) - { - redisCache.setCacheObject(ORDERRULE,rule); + @GetMapping("/rule") + public AjaxResult setRule(String rule) { + redisCache.setCacheObject(ORDERRULE, rule); return AjaxResult.success(); } @@ -158,9 +168,8 @@ public class StatusController extends BaseController { //按类型划分设备 @ApiOperation("设备状态列表按类型") - @GetMapping ("/type") - public AjaxResult getTypeList() - { + @GetMapping("/type") + public AjaxResult getTypeList() { //DcDevice dcDevice = new DcDevice(); //dcDevice.setUseState(1); //List dcDeviceList = dcDeviceService.numberOfDevicesByType(dcDevice); @@ -352,32 +361,32 @@ public class StatusController extends BaseController { // // } //} - Map maps=new HashMap<>(); + Map maps = new HashMap<>(); double lostRate = lastEntry.stream() .mapToDouble(Status -> Double.parseDouble(Status.getLostRate().replace(UniversalEnum.PER_CENT.getValue(), UniversalEnum.EMPTY_STRING.getValue()))) // 去掉%,并转换为double .average().getAsDouble(); double sucessRate = lastEntry.stream() .mapToDouble(Status -> Double.parseDouble(Status.getSuccessRate().replace(UniversalEnum.PER_CENT.getValue(), UniversalEnum.EMPTY_STRING.getValue()))) // 去掉%,并转换为double .average().getAsDouble(); - String failRate=String.format("%.2f", (UniversalEnum.ONE_HUNDRED.getNumber()-sucessRate))+UniversalEnum.PER_CENT.getValue(); + String failRate = String.format("%.2f", (UniversalEnum.ONE_HUNDRED.getNumber() - sucessRate)) + UniversalEnum.PER_CENT.getValue(); //丢包率 - maps.put("lostRate",String.format("%.2f", lostRate)+UniversalEnum.PER_CENT.getValue()); + maps.put("lostRate", String.format("%.2f", lostRate) + UniversalEnum.PER_CENT.getValue()); //在线率 - maps.put("sucessRate",String.format("%.2f", sucessRate)+UniversalEnum.PER_CENT.getValue()); + maps.put("sucessRate", String.format("%.2f", sucessRate) + UniversalEnum.PER_CENT.getValue()); //离线率 - maps.put("failRate",failRate); + maps.put("failRate", failRate); List list = dcDeviceService.list(); //已使用数量 - maps.put("sumUseState",String.valueOf(lastEntry.size())); + maps.put("sumUseState", String.valueOf(lastEntry.size())); //总数 - maps.put("sum",String.valueOf(list.size())); - subMap.put("全部设备",maps); - Map ruleMap=new HashMap<>(); - String orderRule=redisCache.getCacheObject(ORDERRULE); - if(StringUtil.isNotEmpty(orderRule)){ - ruleMap.put("rule",orderRule); - subMap.put("排序规则",ruleMap); - }else{ + maps.put("sum", String.valueOf(list.size())); + subMap.put("全部设备", maps); + Map ruleMap = new HashMap<>(); + String orderRule = redisCache.getCacheObject(ORDERRULE); + if (StringUtil.isNotEmpty(orderRule)) { + ruleMap.put("rule", orderRule); + subMap.put("排序规则", ruleMap); + } else { String[] rules = {UniversalEnum.ALL_EQUIPMENT.getValue(), UniversalEnum.HD_NETWORK_GUN_TYPE_FIXED_CAMERA.getValue(), UniversalEnum.HD_NETWORK_SPHERICAL_CAMERA.getValue(), @@ -400,9 +409,9 @@ public class StatusController extends BaseController { UniversalEnum.SOLAR_PANEL.getValue(), UniversalEnum.REMOTE_COMPUTER.getValue() }; - orderRule= Arrays.toString(rules).replace(UniversalEnum.LEFT_CENTER_BRACKET.getValue(),UniversalEnum.EMPTY_STRING.getValue()).replace(UniversalEnum.CLOSE_CENTER_BRACKET.getValue(),UniversalEnum.EMPTY_STRING.getValue()).replace(UniversalEnum.BLANK_SPACE.getValue(),UniversalEnum.EMPTY_STRING.getValue()); - ruleMap.put("rule",orderRule); - subMap.put("排序规则",ruleMap); + orderRule = Arrays.toString(rules).replace(UniversalEnum.LEFT_CENTER_BRACKET.getValue(), UniversalEnum.EMPTY_STRING.getValue()).replace(UniversalEnum.CLOSE_CENTER_BRACKET.getValue(), UniversalEnum.EMPTY_STRING.getValue()).replace(UniversalEnum.BLANK_SPACE.getValue(), UniversalEnum.EMPTY_STRING.getValue()); + ruleMap.put("rule", orderRule); + subMap.put("排序规则", ruleMap); } return AjaxResult.success(subMap); } diff --git a/zc-business/src/main/java/com/zc/business/mapper/StatusMapper.java b/zc-business/src/main/java/com/zc/business/mapper/StatusMapper.java index 290beffb..1eb83909 100644 --- a/zc-business/src/main/java/com/zc/business/mapper/StatusMapper.java +++ b/zc-business/src/main/java/com/zc/business/mapper/StatusMapper.java @@ -25,4 +25,5 @@ public interface StatusMapper { List listStatusByTypes(@Param("status")Status status); List getStatusList(@Param("status")Status status); + int delStatusByTime(Status status); } diff --git a/zc-business/src/main/java/com/zc/business/service/impl/StatusService.java b/zc-business/src/main/java/com/zc/business/service/impl/StatusService.java index 9afb97c9..4951accf 100644 --- a/zc-business/src/main/java/com/zc/business/service/impl/StatusService.java +++ b/zc-business/src/main/java/com/zc/business/service/impl/StatusService.java @@ -53,4 +53,7 @@ public class StatusService { return list; } + public int delStatusByTime(Status status) { + return statusMapper.delStatusByTime(status); + } } diff --git a/zc-business/src/main/resources/mapper/business/StatusMapper.xml b/zc-business/src/main/resources/mapper/business/StatusMapper.xml index cce1976e..6d9e9f7d 100644 --- a/zc-business/src/main/resources/mapper/business/StatusMapper.xml +++ b/zc-business/src/main/resources/mapper/business/StatusMapper.xml @@ -328,4 +328,14 @@ + + DELETE FROM status + + + AND status.time < #{startTime,jdbcType=DATE} + + + + +