diff --git a/zc-business/src/main/java/com/zc/business/controller/BroadcastController.java b/zc-business/src/main/java/com/zc/business/controller/BroadcastController.java index 5c594912..379183cd 100644 --- a/zc-business/src/main/java/com/zc/business/controller/BroadcastController.java +++ b/zc-business/src/main/java/com/zc/business/controller/BroadcastController.java @@ -121,6 +121,4 @@ public class BroadcastController extends BaseController { return null; } - ///** - } 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 47413189..33572392 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 @@ -1,6 +1,8 @@ package com.zc.business.controller; + import com.ruoyi.common.utils.spring.SpringUtils; -import com.zc.business.service.IDeviceService; +import com.zc.business.domain.DcDevice; +import com.zc.business.service.IDcDeviceService; import com.zc.business.service.impl.ExcelExportService; import com.zc.business.service.impl.StatusService; import org.apache.poi.ss.usermodel.Workbook; @@ -9,7 +11,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.stereotype.Component; import com.zc.business.domain.Status; -import com.zc.business.domain.Device; import java.io.BufferedReader; import java.io.FileOutputStream; @@ -29,7 +30,7 @@ import java.util.stream.Collectors; @EnableScheduling public class DeviceStatus { @Autowired - private IDeviceService deviceService; + private IDcDeviceService deviceService; @Autowired private StatusService statusService; @@ -38,19 +39,18 @@ public class DeviceStatus { private ExcelExportService excelExportService; - //每天凌晨0点到晚上23点整点测试设备状态 - // @Scheduled(cron = "0 0 0-23 * * ?") + //每天凌晨0点到晚上23点整点测试设备状态 + // @Scheduled(cron = "0 0 0-23 * * ?") // @Scheduled(cron = "0 0 1,5,7,8,11,14,17,19,21,23") public void deviceStatus() { - Device devices=new Device(); - IDeviceService deviceService= SpringUtils.getBean(IDeviceService.class); + IDcDeviceService deviceService= SpringUtils.getBean(IDcDeviceService.class); StatusService statusService= SpringUtils.getBean(StatusService.class); ExecutorService executor = Executors.newFixedThreadPool(100); - List deviceList = deviceService.selectDeviceList(devices); + List deviceList = deviceService.list(); List> futures = new ArrayList<>(); - for (Device device : deviceList) { + for (DcDevice device : deviceList) { Callable task = () -> { try { Status status = new Status(); @@ -58,7 +58,7 @@ public class DeviceStatus { String lostRate = getPingPacketLossRate(device.getDeviceIp()); boolean reachable = address.isReachable(5000); // Timeout: 5 seconds - status.setDeviceNo(device.getDeviceNo()); + status.setDeviceNo(device.getStakeMark()); status.setDeviceName(device.getDeviceName()); status.setDeviceIp(device.getDeviceIp()); LocalDateTime localDateTime = LocalDateTime.now(); @@ -116,7 +116,7 @@ public class DeviceStatus { // Extract the number of packets sent and lost String[] stats = line.split(", "); packetsSent = Integer.parseInt(stats[0].split(" ")[0]); - packetsLost = Integer.parseInt(stats[0].split(" ")[0])-Integer.parseInt(stats[1].split(" ")[0]); + packetsLost = Integer.parseInt(stats[0].split(" ")[0]) - Integer.parseInt(stats[1].split(" ")[0]); } } @@ -138,9 +138,9 @@ public class DeviceStatus { * 每天17点 23点 30分导出excel表 */ - // @Scheduled(cron = "0 30 17,23 * * ?") + // @Scheduled(cron = "0 30 17,23 * * ?") public void calculateSuccessRate() { - StatusService statusService= SpringUtils.getBean(StatusService.class); + StatusService statusService = SpringUtils.getBean(StatusService.class); ExcelExportService excelExportService= SpringUtils.getBean(ExcelExportService.class); LocalDateTime todayStart = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS); @@ -155,28 +155,28 @@ public class DeviceStatus { Map> map = listStatus.stream() .collect(Collectors.groupingBy(Status -> Status.getTime().getHour())); //根据类型分组 - Map> maps = listStatus.stream().filter(iteam->iteam.getType()!=null).collect(Collectors.groupingBy(Status::getType)); + Map> maps = listStatus.stream().filter(iteam -> iteam.getType() != null).collect(Collectors.groupingBy(Status::getType)); - String filePath=CreateNamedExcel(); - excelExportService.exportDataToExcel(map,maps,filePath); + String filePath = CreateNamedExcel(); + excelExportService.exportDataToExcel(map, maps, filePath); } public String CreateNamedExcel() { - LocalDateTime dateTime = LocalDateTime.now(); - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); - String formattedDateTime = dateTime.format(formatter); - //修改成服务器地址 - String filePath = "/home/excel/"+formattedDateTime+"--deviceStatus.xlsx"; - try (Workbook workbook = new XSSFWorkbook()) { - FileOutputStream fileOut = new FileOutputStream(filePath); - workbook.write(fileOut); - System.out.println("Empty named Excel created successfully."); - } catch (IOException e) { - e.printStackTrace(); - } - return filePath; + LocalDateTime dateTime = LocalDateTime.now(); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + String formattedDateTime = dateTime.format(formatter); + //修改成服务器地址 + String filePath = "/home/excel/" + formattedDateTime + "--deviceStatus.xlsx"; + try (Workbook workbook = new XSSFWorkbook()) { + FileOutputStream fileOut = new FileOutputStream(filePath); + workbook.write(fileOut); + System.out.println("Empty named Excel created successfully."); + } catch (IOException e) { + e.printStackTrace(); } + return filePath; + } } diff --git a/zc-business/src/main/java/com/zc/business/controller/NonAutomaticWarningController.java b/zc-business/src/main/java/com/zc/business/controller/NonAutomaticWarningController.java index 1a45e07b..e3548fa0 100644 --- a/zc-business/src/main/java/com/zc/business/controller/NonAutomaticWarningController.java +++ b/zc-business/src/main/java/com/zc/business/controller/NonAutomaticWarningController.java @@ -132,7 +132,7 @@ public class NonAutomaticWarningController extends BaseController { String illegalTrafficEvent = data.getString("illegalTrafficEvent"); String directionName = data.getString("directionName"); String crossingName = data.getString("crossingName"); - String targetPicUrl = "https://10.0.81.28" + data.getString("targetPicUrl"); + String targetPicUrl = "http://10.0.81.202/fjyj" + data.getString("targetPicUrl"); String laneNo = data.getString("laneNo"); ArrayList pictures = new ArrayList<>(); diff --git a/zc-business/src/main/java/com/zc/business/controller/WeatherForecastController.java b/zc-business/src/main/java/com/zc/business/controller/WeatherForecastController.java new file mode 100644 index 00000000..9e8b9cbe --- /dev/null +++ b/zc-business/src/main/java/com/zc/business/controller/WeatherForecastController.java @@ -0,0 +1,169 @@ +package com.zc.business.controller; + +import com.alibaba.fastjson.JSONObject; +import com.ruoyi.common.core.controller.BaseController; +import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.common.core.redis.RedisCache; +import com.zc.business.domain.DcRegion; +import com.zc.business.service.impl.DcRegionServiceImpl; +import com.zc.common.core.httpclient.OkHttp; +import com.zc.common.core.httpclient.exception.HttpException; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import okhttp3.Response; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; +import java.io.IOException; +import java.util.*; +import java.util.concurrent.TimeUnit; + + +/** + * License + * + * @author Athena-zhaoxianglong + */ +@Api(tags = "天气预报接口") +@RestController +@RequestMapping("/weatherForecast") +public class WeatherForecastController extends BaseController { + + private static final String WEATHERFACTSURI = "https://devapi.qweather.com/v7/weather/now?location="; + private static final String WEATHERFACTS = "weatherFacts"; + private static final String WEATHERFACTSKEY = "f72f6415b3f04515be1cceb868b33a7e"; //谢朴峰 + private static final String METEOROLOGICALEARLYWARNINGURI = "https://devapi.qweather.com/v7/warning/now?location="; + private static final String METEOROLOGICALEARLYWARNING = "meteorologicalEarlyWarning"; + private static final String METEOROLOGICALEARLYWARNINGKEY = "8b5e521388154799a86e73444db76b1d"; // 高广超 + private static final String HOURLYWEATHERURI = "https://devapi.qweather.com/v7/weather/24h?location="; + private static final String HOURLYWEATHER = "hourlyWeather"; + private static final String HOURLYWEATHERKEY = "cfd87e0502684ac3a681eb19a712aec6"; // 孟凡峰 + private static final String KEY = "&key="; + @Resource + private RedisCache redisCache; + + @Resource + private DcRegionServiceImpl dcRegionService; + + /* + * 天气实况查询 + * */ + @ApiOperation("天气实况查询") + @PostMapping(value = "/weatherFacts") + public AjaxResult weatherFacts() throws HttpException, IOException { + return getAjaxResult(WEATHERFACTSURI, WEATHERFACTSKEY, WEATHERFACTS); + } + + /* + * 气象预警查询 + * */ + @ApiOperation("气象预警查询") + @PostMapping(value = "/meteorologicalEarlyWarning") + public AjaxResult meteorologicalEarlyWarning() throws HttpException, IOException { + return getAjaxResult(METEOROLOGICALEARLYWARNINGURI, METEOROLOGICALEARLYWARNINGKEY, METEOROLOGICALEARLYWARNING); + } + + /* + * 气象预警查询 + * */ + @ApiOperation("逐小时天气查询") + @PostMapping(value = "/hourlyWeather") + public AjaxResult hourlyWeather() throws HttpException, IOException { + return getAjaxResult(HOURLYWEATHERURI, HOURLYWEATHERKEY, HOURLYWEATHER); + } + + private AjaxResult getAjaxResult(String uri, String accessKey, String redisKey) throws HttpException, IOException { + + JSONObject cacheObject = redisCache.getCacheObject(redisKey); + + if (cacheObject != null) { + + return AjaxResult.success(cacheObject); + + } else { + + List list = dcRegionService.list(); + + JSONObject jsonObject = new JSONObject(); + + for (DcRegion dcRegion : list) { + OkHttp okHttp = new OkHttp(); + + Response response // 请求响应 + = okHttp + .headers(new HashMap<>()) + .url(uri + dcRegion.getLongitude() + "," + dcRegion.getLatitude() + KEY + accessKey) // 请求地址 + .get(); // 请求方法 + + if (response.body() != null) { + + JSONObject jsonResult = JSONObject.parseObject(response.body().string()); + if (jsonResult.getInteger("code") == 200) { + + if (Objects.equals(redisKey, WEATHERFACTS)) { + + jsonObject.put(redisKey + dcRegion.getId(), extracted(jsonResult, "now")); + + } else if (Objects.equals(redisKey, METEOROLOGICALEARLYWARNING)) { + + jsonObject.put(redisKey + dcRegion.getId(), extracted(jsonResult, "warning")); + + } else if (Objects.equals(redisKey, HOURLYWEATHER)) { + + jsonObject.put(redisKey + dcRegion.getId(), extracted(jsonResult, "hourly")); + } + } else { + return AjaxResult.error(jsonResult.getInteger("code"), "请求失败"); + } + } + } + + + if (Objects.equals(redisKey, WEATHERFACTS)) { + + redisCache.setCacheObject(redisKey, jsonObject, 13, TimeUnit.MINUTES); + + } else if (Objects.equals(redisKey, METEOROLOGICALEARLYWARNING)) { + + redisCache.setCacheObject(redisKey, jsonObject, 13, TimeUnit.MINUTES); + + } else if (Objects.equals(redisKey, HOURLYWEATHER)) { + + redisCache.setCacheObject(redisKey, jsonObject, 13, TimeUnit.MINUTES); + } + + return AjaxResult.success(jsonObject); + } + } + + private static Object extracted(JSONObject jsonResult, String type) { + JSONObject jsonObject = new JSONObject(); + jsonObject.put("code", jsonResult.getString("code")); + if (Objects.equals(jsonResult.getString("code"), "200")) { + if (Objects.equals(type, "now")) { + return jsonResult.getJSONObject(type); + } else { + return jsonResult.getJSONArray(type); + } + } else if (Objects.equals(jsonResult.getString("code"), "500")) { + jsonObject.put("msg", "请求失败:无响应或超时"); + } else if (Objects.equals(jsonResult.getString("code"), "429")) { + jsonObject.put("msg", "请求失败:每分钟访问次数过多,请稍后重试"); + } else if (Objects.equals(jsonResult.getString("code"), "404")) { + jsonObject.put("msg", "请求失败:查询的地区或者数据不存在"); + } else if (Objects.equals(jsonResult.getString("code"), "403")) { + jsonObject.put("msg", "请求失败:无访问权限,可能是绑定的PackageName、BundleID、域名IP地址不一致"); + } else if (Objects.equals(jsonResult.getString("code"), "402")) { + jsonObject.put("msg", "请求失败:超过访问次数或余额不足以支持继续访问服务"); + } else if (Objects.equals(jsonResult.getString("code"), "401")) { + jsonObject.put("msg", "请求失败:认证失败,可能使用了错误的KEY、数字签名错误、KEY的类型错误"); + } else if (Objects.equals(jsonResult.getString("code"), "400")) { + jsonObject.put("msg", "请求失败:请求错误,可能包含错误的请求参数或缺少必选的请求参数"); + } else if (Objects.equals(jsonResult.getString("code"), "204")) { + jsonObject.put("msg", "请求失败:请求成功,但你查询的地区暂时没有你需要的数据"); + } + return jsonObject; + } +} diff --git a/zc-business/src/main/java/com/zc/business/domain/DcRegion.java b/zc-business/src/main/java/com/zc/business/domain/DcRegion.java new file mode 100644 index 00000000..f15246e6 --- /dev/null +++ b/zc-business/src/main/java/com/zc/business/domain/DcRegion.java @@ -0,0 +1,21 @@ +package com.zc.business.domain; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +@Data +@ApiModel(value = "DcRegion", description = "地区实体类") +public class DcRegion { + @ApiModelProperty("ID") + @TableId(value = "id", type = IdType.AUTO) + private Long id; + @ApiModelProperty("地区名称") + private String regionName; + @ApiModelProperty("经度") + private String longitude; + @ApiModelProperty("纬度") + private String latitude; +} diff --git a/zc-business/src/main/java/com/zc/business/mapper/DcRegionMapper.java b/zc-business/src/main/java/com/zc/business/mapper/DcRegionMapper.java new file mode 100644 index 00000000..20d0ee45 --- /dev/null +++ b/zc-business/src/main/java/com/zc/business/mapper/DcRegionMapper.java @@ -0,0 +1,14 @@ +package com.zc.business.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.zc.business.domain.DcRegion; +import org.apache.ibatis.annotations.Mapper; + +/** + * 地区Mapper接口 + * + * @author zhaoxianglong + */ +@Mapper +public interface DcRegionMapper extends BaseMapper { +} diff --git a/zc-business/src/main/java/com/zc/business/service/IDcRegionService.java b/zc-business/src/main/java/com/zc/business/service/IDcRegionService.java new file mode 100644 index 00000000..e42eb485 --- /dev/null +++ b/zc-business/src/main/java/com/zc/business/service/IDcRegionService.java @@ -0,0 +1,14 @@ +package com.zc.business.service; + + +import com.baomidou.mybatisplus.extension.service.IService; +import com.zc.business.domain.DcRegion; + + +/** + * 地区Service接口 + * + * @author zhaoxianglong + */ +public interface IDcRegionService extends IService { +} diff --git a/zc-business/src/main/java/com/zc/business/service/impl/DcRegionServiceImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/DcRegionServiceImpl.java new file mode 100644 index 00000000..2b05dce9 --- /dev/null +++ b/zc-business/src/main/java/com/zc/business/service/impl/DcRegionServiceImpl.java @@ -0,0 +1,16 @@ +package com.zc.business.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.zc.business.domain.DcRegion; +import com.zc.business.mapper.DcRegionMapper; +import com.zc.business.service.IDcRegionService; +import org.springframework.stereotype.Service; + +/** + * 路网设施Service业务层处理 + * + * @author zhaoxianglong + */ +@Service +public class DcRegionServiceImpl extends ServiceImpl implements IDcRegionService { +} diff --git a/zc-business/src/main/resources/mapper/business/DcEventMapper.xml b/zc-business/src/main/resources/mapper/business/DcEventMapper.xml index 93ce8525..ec472c71 100644 --- a/zc-business/src/main/resources/mapper/business/DcEventMapper.xml +++ b/zc-business/src/main/resources/mapper/business/DcEventMapper.xml @@ -334,7 +334,7 @@ and in_tunnel = #{inTunnel} and is_perceived = #{isPerceived} - + ORDER BY create_time desc