ycl-common/src/main/java/com/ycl/service/oss/impl/OssServiceImpl.java
@@ -13,6 +13,7 @@ import java.io.ByteArrayOutputStream; import java.io.InputStream; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.Date; @@ -20,6 +21,9 @@ public class OssServiceImpl implements OssService { @Override public String uploadImages(MultipartFile file) { DateTimeFormatter dtf2 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); System.out.println("开始上传--" + dtf2.format(LocalDateTime.now())); if (file == null) { return "上传文件为空"; } @@ -47,6 +51,7 @@ Date expiration = new Date(System.currentTimeMillis() + (long) 946080000 * 1000); String url = ossClient.generatePresignedUrl(bucketName, fileName, expiration).toString(); System.out.println("上传结束--" + dtf2.format(LocalDateTime.now())); return url; } catch (Exception e) { System.out.println("uploadImages上传图片失败:"); ycl-platform/src/main/java/com/ycl/controller/dingding/DingController.java
@@ -194,12 +194,16 @@ @PostMapping("/oss/sign") public CommonResult ossSign(@RequestBody OssFileDto dto) { log.info("接收到file"); DateTimeFormatter dtf2 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); if (StringUtils.isNullOrEmpty(dto.getMediaId()) || StringUtils.isNullOrEmpty(dto.getExtension())) { return CommonResult.failed("参数不能为空!"); } ExecutableClient executableClient = DdTest.getExecutableClient(); CloseableHttpResponse response = null; OSS ossClient = null; System.out.println("开始获取--" + dtf2.format(LocalDateTime.now())); try { //从钉钉获取视频流 String api = "/media/download"; @@ -212,12 +216,15 @@ response = getClient.getB(); HttpEntity entity = response.getEntity(); InputStream is = entity.getContent(); DateTimeFormatter dtf2 = DateTimeFormatter.ofPattern("yyyyMMddHHmmss"); String strDate2 = dtf2.format(LocalDateTime.now()); System.out.println("获取完成--" + dtf2.format(LocalDateTime.now())); DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyyMMddHHmmss"); String strDate2 = dtf.format(LocalDateTime.now()); String fileName = strDate2 + RandomUtils.generateRandomInt(4) + "." + dto.getExtension(); MultipartFile file = getMultipartFile(is, fileName); String url = ossService.uploadImages(file); return CommonResult.success(url); } catch (Exception e) { ycl-platform/src/main/java/com/ycl/controller/smoke/SmokeAlarmController.java
@@ -1,10 +1,26 @@ package com.ycl.controller.smoke; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.ycl.annotation.LogSave; import com.ycl.api.CommonPage; import com.ycl.api.CommonResult; import com.ycl.controller.BaseController; import com.ycl.entity.smoke.OdsAlarmMsg; import com.ycl.dto.smoker.QueryAlarmParam; import com.ycl.service.smoke.IOdsAlarmMsgService; import com.ycl.utils.EasyExcelUtils; import com.ycl.vo.smoke.OdsAlarmVo; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.net.URLEncoder; import java.text.SimpleDateFormat; import java.util.*; @RestController @RequestMapping("/smoke") @@ -17,91 +33,51 @@ public void setAlarmMsgService(IOdsAlarmMsgService alarmMsgService) { this.alarmMsgService = alarmMsgService; } // // @ApiOperation("获取所属单位") // @RequestMapping(value = "/customer/list", method = RequestMethod.GET) // @ResponseBody // @LogSave(operationType = "油烟模块", contain = "获取所属单位") // public CommonResult<CommonPage<OdsCustomer>> findCustomerList(@RequestParam(value = "keyword", required = false) String keyword, // @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize, // @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) { // Page<OdsCustomer> customerPage = customerService.findList(keyword, pageSize, pageNum); // return CommonResult.success(CommonPage.restPage(customerPage)); // } // // @ApiOperation("查询实时数据") // @RequestMapping(value = "/inTime/list", method = RequestMethod.GET) // @ResponseBody // @LogSave(operationType = "油烟模块", contain = "查询实时数据") // public CommonResult<CommonPage<OdsInTime>> findInTimeList(@RequestParam(value = "owner", required = false) String owner, // @RequestParam(value = "onlineStatus", required = false) String onlineStatus, // @RequestParam(value = "status", required = false) String status, // @RequestParam(value = "startTime", required = false) String startTime, // @RequestParam(value = "endTime", required = false) String endTime, // @RequestParam(value = "type", required = false) String type, // @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize, // @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) { // Page<OdsInTime> inTimePage = inTimeService.findList(owner, onlineStatus, startTime, endTime, type, status, pageSize, pageNum); // return CommonResult.success(CommonPage.restPage(inTimePage)); // } // // @ApiOperation("导出实时数据") // @PostMapping(value = "/inTime/export") // @LogSave(operationType = "油烟模块", contain = "查询实时数据") // public void exportInTimeList(HttpServletResponse response, QueryInTimeParam param) throws IOException { // Page<OdsInTime> inTimePage = inTimeService.findList(param.getOwner(), param.getOnlineStatus(), param.getStartTime(), // param.getEndTime(), param.getType(), param.getStatus(), 99999, 1); // // List<OdsInTimeVo> odsInTimeVos = new ArrayList<>(); // Dictionary<Integer, String> fanStatusDic = new Hashtable<>(); // fanStatusDic.put(1, "开"); // fanStatusDic.put(2, "关"); // fanStatusDic.put(3, "异常"); // fanStatusDic.put(0, "异常"); // // Dictionary<Integer, String> onlineStatusDic = new Hashtable<>(); // onlineStatusDic.put(1, "在线"); // onlineStatusDic.put(2, "离线"); // onlineStatusDic.put(3, "异常离线"); // onlineStatusDic.put(0, "异常离线"); // // Dictionary<String, String> statusDic = new Hashtable<>(); // statusDic.put("NORMAL", "正常"); // statusDic.put("ALARM", "预警"); // statusDic.put("EXCESS", "超标"); // statusDic.put("DOWN", "离线"); // statusDic.put("OFF", "异常离线"); // // inTimePage.getRecords().stream().forEach(o -> { // OdsInTimeVo vo = new OdsInTimeVo(); // BeanUtils.copyProperties(o, vo); // vo.setAcquitAtStr(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(o.getAcquitAt() * 1000))); // vo.setFanStatusStr(fanStatusDic.get(o.getFanStatus())); // vo.setFilterStatusStr(fanStatusDic.get(o.getFilterStatus())); // vo.setOnlineStatusStr(onlineStatusDic.get(o.getOnlineStatus())); // vo.setStatusStr(statusDic.get(o.getStatus())); // odsInTimeVos.add(vo); // }); // // String sheetName = "实时数据"; // // String fileName = URLEncoder.encode(sheetName + ".xlsx", "UTF-8"); // //设置响应字符集 // response.setCharacterEncoding("UTF-8"); // //设置响应媒体类型 // response.setContentType("application/vnd.ms-excel"); // response.setHeader("Content-Disposition", "attachment;filename=" + fileName); // // EasyExcelUtils.export(response, sheetName, OdsInTimeVo.class, odsInTimeVos); // } // // // @ApiOperation("获取设备在线情况") // @RequestMapping(value = "/inTime/count", method = RequestMethod.GET) // @ResponseBody // @LogSave(operationType = "油烟模块", contain = "获取设备在线情况") // public CommonResult<InTimeCountDto> getInTimeCount() { // InTimeCountDto dto = inTimeService.getInTimeCount(); // return CommonResult.success(dto); // } @ApiOperation("查询报警数据") @RequestMapping(value = "/alarm/list", method = RequestMethod.GET) @ResponseBody @LogSave(operationType = "油烟模块", contain = "查询报警数据") public CommonResult<CommonPage<OdsAlarmMsg>> findAlarmList(@RequestParam(value = "msgType", required = false) String type, @RequestParam(value = "startTime", required = false) String startTime, @RequestParam(value = "endTime", required = false) String endTime, @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize, @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) { Page<OdsAlarmMsg> page = alarmMsgService.findList(type, startTime, endTime, pageSize, pageNum); return CommonResult.success(CommonPage.restPage(page)); } @ApiOperation("导出报警数据") @PostMapping(value = "/alarm/export") @LogSave(operationType = "油烟模块", contain = "导出报警数据") public void exportAlarmList(HttpServletResponse response, QueryAlarmParam param) throws IOException { Page<OdsAlarmMsg> page = alarmMsgService.findList(param.getMsgType(), param.getStartTime(), param.getEndTime(), 99999, 1); List<OdsAlarmVo> alarmMsgs = new ArrayList<>(); Dictionary<String, String> msgTypeDic = new Hashtable<>(); msgTypeDic.put("ExceedStandard", "超标"); msgTypeDic.put("AbnormalOffline", "异常离线"); page.getRecords().stream().forEach(o -> { OdsAlarmVo vo = new OdsAlarmVo(); BeanUtils.copyProperties(o, vo); vo.setAcquitAtStr(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(o.getAcquitAt() * 1000))); vo.setMsgTypeStr(msgTypeDic.get(o.getMsgType())); alarmMsgs.add(vo); }); String sheetName = "报警消息"; String fileName = URLEncoder.encode(sheetName + ".xlsx", "UTF-8"); //设置响应字符集 response.setCharacterEncoding("UTF-8"); //设置响应媒体类型 response.setContentType("application/vnd.ms-excel"); response.setHeader("Content-Disposition", "attachment;filename=" + fileName); EasyExcelUtils.export(response, sheetName, OdsAlarmVo.class, alarmMsgs); } } ycl-platform/src/main/java/com/ycl/dto/smoker/QueryAlarmParam.java
New file @@ -0,0 +1,10 @@ package com.ycl.dto.smoker; import lombok.Data; @Data public class QueryAlarmParam { private String startTime; private String endTime; private String msgType; } ycl-platform/src/main/java/com/ycl/service/smoke/IOdsAlarmMsgService.java
@@ -1,5 +1,6 @@ package com.ycl.service.smoke; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.IService; import com.ycl.entity.smoke.OdsAlarmMsg; @@ -13,4 +14,5 @@ */ public interface IOdsAlarmMsgService extends IService<OdsAlarmMsg> { Page<OdsAlarmMsg> findList(String status, String startTime, String endTime, Integer pageSize, Integer pageNum); } ycl-platform/src/main/java/com/ycl/service/smoke/impl/OdsAlarmMsgServiceImpl.java
@@ -1,10 +1,19 @@ package com.ycl.service.smoke.impl; import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ycl.entity.smoke.OdsAlarmMsg; import com.ycl.entity.smoke.OdsInTime; import com.ycl.mapper.smoke.OdsAlarmMsgMapper; import com.ycl.service.smoke.IOdsAlarmMsgService; import org.springframework.stereotype.Service; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; /** * <p> @@ -17,4 +26,31 @@ @Service public class OdsAlarmMsgServiceImpl extends ServiceImpl<OdsAlarmMsgMapper, OdsAlarmMsg> implements IOdsAlarmMsgService { @Override public Page<OdsAlarmMsg> findList(String type, String startTime, String endTime, Integer pageSize, Integer pageNum) { Page<OdsAlarmMsg> page = new Page<>(pageNum, pageSize); QueryWrapper<OdsAlarmMsg> wrapper = new QueryWrapper<>(); LambdaQueryWrapper<OdsAlarmMsg> lambda = wrapper.lambda(); if (StrUtil.isNotEmpty(startTime)) { try { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date startdate = format.parse(startTime); Long startTimestamp = startdate.getTime() / 1000; Date enddate = format.parse(endTime); Long endTimestamp = enddate.getTime() / 1000; lambda.between(OdsAlarmMsg::getAcquitAt, startTimestamp, endTimestamp); } catch (ParseException e) { throw new RuntimeException(e); } } if (StrUtil.isNotEmpty(type)) { lambda.eq(OdsAlarmMsg::getMsgType, type); } wrapper.orderByDesc("id"); return this.page(page, wrapper); } } ycl-platform/src/main/java/com/ycl/service/smoke/impl/OdsInTimeServiceImpl.java
@@ -59,6 +59,7 @@ lambda.eq(OdsInTime::getStatus, status); } wrapper.orderByDesc("id"); return this.page(page, wrapper); } ycl-platform/src/main/java/com/ycl/vo/smoke/OdsAlarmVo.java
New file @@ -0,0 +1,34 @@ package com.ycl.vo.smoke; import com.alibaba.excel.annotation.ExcelProperty; import com.baomidou.mybatisplus.annotation.TableField; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; import java.math.BigDecimal; @Data @Builder @NoArgsConstructor @AllArgsConstructor public class OdsAlarmVo { @ExcelProperty(value = "设备编码", index = 0) private String mn; @ExcelProperty(value = "报警时间", index = 1) private String acquitAtStr; @ExcelProperty(value = "消息类型", index = 2) private String msgTypeStr; @ExcelProperty(value = "消息内容", index = 3) private String content; @ExcelProperty(value = "地址", index = 4) private String addr; } ycl-smoke/src/main/java/com/ycl/smoke/dto/DataIntimeParamChildDto.java
@@ -1,13 +1,14 @@ package com.ycl.smoke.dto; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Builder; import lombok.Data; import lombok.EqualsAndHashCode; @Data @Builder @EqualsAndHashCode(callSuper = false) @JsonInclude(JsonInclude.Include.NON_NULL) public class DataIntimeParamChildDto { /** * 否 筛选组织(Param内) ycl-smoke/src/main/java/com/ycl/smoke/dto/DataIntimeParamDto.java
@@ -1,5 +1,6 @@ package com.ycl.smoke.dto; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Builder; import lombok.Data; @@ -8,6 +9,7 @@ @Data @Builder @EqualsAndHashCode(callSuper = false) @JsonInclude(JsonInclude.Include.NON_NULL) public class DataIntimeParamDto { /** * 否 起始位置 ycl-smoke/src/main/java/com/ycl/smoke/entity/OdsInTimeCount.java
New file @@ -0,0 +1,39 @@ package com.ycl.smoke.entity; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Data; import lombok.EqualsAndHashCode; import java.io.Serializable; @Data @EqualsAndHashCode(callSuper = false) @TableName("ums_ods_in_time_count") public class OdsInTimeCount implements Serializable { @TableId("id") @JsonProperty("Id") private String id; @TableField("device_num") @JsonProperty("deviceNum") private Integer deviceNum; @TableField("locale_num") @JsonProperty("localeNum") private Integer localeNum; @TableField("online_num") @JsonProperty("onlineNum") private Integer onlineNum; @TableField("total") @JsonProperty("total") private Integer total; @TableField("type") @JsonProperty("type") private Integer type; } ycl-smoke/src/main/java/com/ycl/smoke/mapper/OdsInTimeCountMapper.java
New file @@ -0,0 +1,17 @@ package com.ycl.smoke.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.ycl.smoke.entity.OdsInTime; import com.ycl.smoke.entity.OdsInTimeCount; /** * <p> * 返回实时的设备数据 Mapper 接口 * </p> * * @author lyq * @since 2023-02-28 */ public interface OdsInTimeCountMapper extends BaseMapper<OdsInTimeCount> { } ycl-smoke/src/main/java/com/ycl/smoke/remote/service/ISmokeDetectionService.java
@@ -10,7 +10,7 @@ import java.util.List; @FeignClient(url = "116.62.234.187:8088", name = "smokeApi") @FeignClient(url = "116.62.234.187:8120", name = "smokeApi") public interface ISmokeDetectionService { @PostMapping(value = "/loginAction") ycl-smoke/src/main/java/com/ycl/smoke/service/IOdsInTimeCountService.java
New file @@ -0,0 +1,17 @@ package com.ycl.smoke.service; import com.baomidou.mybatisplus.extension.service.IService; import com.ycl.smoke.entity.OdsInTime; import com.ycl.smoke.entity.OdsInTimeCount; /** * <p> * 返回实时的设备数据 服务类 * </p> * * @author lyq * @since 2023-02-28 */ public interface IOdsInTimeCountService extends IService<OdsInTimeCount> { } ycl-smoke/src/main/java/com/ycl/smoke/service/impl/OdsInTimeCountServiceImpl.java
New file @@ -0,0 +1,23 @@ package com.ycl.smoke.service.impl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ycl.smoke.entity.OdsInTime; import com.ycl.smoke.entity.OdsInTimeCount; import com.ycl.smoke.mapper.OdsInTimeCountMapper; import com.ycl.smoke.mapper.OdsInTimeMapper; import com.ycl.smoke.service.IOdsInTimeCountService; import com.ycl.smoke.service.IOdsInTimeService; import org.springframework.stereotype.Service; /** * <p> * 返回实时的设备数据 服务实现类 * </p> * * @author lyq * @since 2023-02-28 */ @Service public class OdsInTimeCountServiceImpl extends ServiceImpl<OdsInTimeCountMapper, OdsInTimeCount> implements IOdsInTimeCountService { } ycl-smoke/src/main/java/com/ycl/smoke/task/ScheduledTask.java
@@ -1,6 +1,9 @@ package com.ycl.smoke.task; import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.ycl.service.redis.RedisService; import com.ycl.smoke.entity.*; import com.ycl.smoke.dto.*; @@ -31,6 +34,8 @@ IOdsInTimeService inTimeService; IOdsInTimeCountService iOdsInTimeCountService; IOdsLocaleService localeService; IOdsCustomerService customerService; @@ -45,6 +50,11 @@ @Autowired public void setSmokeDetectionService(ISmokeDetectionService smokeDetectionService) { this.smokeDetectionService = smokeDetectionService; } @Autowired public void setIOdsInTimeCountService(IOdsInTimeCountService iOdsInTimeCountService) { this.iOdsInTimeCountService = iOdsInTimeCountService; } @Autowired @@ -186,20 +196,52 @@ // @Scheduled(cron = "0 0 1 * * ?") // 每天零点执行 @Scheduled(cron = "0 */5 * * * ?") // 每5分钟执行 public void listDataIntime() { try { @Scheduled(cron = "0 */1 * * * ?") // 每5分钟执行 public void listDataInTime() { DataIntimeParamDto paramDto = DataIntimeParamDto.builder().build(); // {"StartAt":0,"Size":20,"Typ":2,"SortBy":"status","SortMode":"asc","Param":{"StatusOfRecord":"NORMAL"}}: paramDto.setSize(200); paramDto.setStartAt(0); paramDto.setTyp(2); paramDto.setSortBy("status"); paramDto.setSortMode("asc"); DataIntimeParamChildDto paramChildDto = new DataIntimeParamChildDto(); paramChildDto.setStatusOfRecord("NORMAL"); paramDto.setParam(paramChildDto); getInTimeData(paramDto); paramDto.setTyp(1); getInTimeData(paramDto); } private void getInTimeData(DataIntimeParamDto paramDto) { try { String jj = JSON.toJSONString(paramDto); String json = smokeDetectionService.listDataIntime(paramDto, redisService.get(RedisKey.SMOKE_TOKEN).toString()); SmokeResultResponseDto responseDto = JSON.parseObject(json, SmokeResultResponseDto.class); if (responseDto.getStatus() == 200) { DataIntimeResponseDto dataIntimeResponseDto = JSON.parseObject(responseDto.getData().toString(), DataIntimeResponseDto.class); List<OdsInTime> list = dataIntimeResponseDto.getContent(); OdsInTimeCount odsInTimeCount = new OdsInTimeCount(); LambdaQueryWrapper<OdsInTimeCount> queryWrapper = new LambdaQueryWrapper<OdsInTimeCount>().eq(OdsInTimeCount::getType, paramDto.getTyp()); List<OdsInTimeCount> countList = iOdsInTimeCountService.list(queryWrapper); if (countList.size() > 0) { odsInTimeCount = countList.get(0); } odsInTimeCount.setDeviceNum(dataIntimeResponseDto.getDeviceNum()); odsInTimeCount.setLocaleNum(dataIntimeResponseDto.getLocaleNum()); odsInTimeCount.setOnlineNum(dataIntimeResponseDto.getOnlineNum()); odsInTimeCount.setTotal(dataIntimeResponseDto.getTotal()); iOdsInTimeCountService.saveOrUpdate(odsInTimeCount); list.forEach(o -> { try { o.setModifyTime(LocalDateTime.now()); o.setTyp(paramDto.getTyp()); inTimeService.saveOrUpdate(o); } catch (Exception ex) { System.out.printf(ex.getMessage()); ycl-smoke/src/main/resources/mapper/smoke/OdsInTimeCountMapper.xml
New file @@ -0,0 +1,19 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.ycl.smoke.mapper.OdsInTimeCountMapper"> <!-- 通用查询映射结果 --> <resultMap id="BaseResultMap" type="com.ycl.smoke.entity.OdsInTimeCount"> <id column="id" property="id"/> <result column="device_num" property="deviceNum"/> <result column="locale_num" property="localeNum"/> <result column="online_num" property="onlineNum"/> <result column="total" property="total"/> </resultMap> <!-- 通用查询结果列 --> <sql id="Base_Column_List"> id , device_num, locale_num, online_num, total </sql> </mapper>