Browse Source

Merge remote-tracking branch 'origin/develop' into develop

develop
mengff 4 weeks ago
parent
commit
69a09be798
  1. 17
      zc-business/src/main/java/com/zc/business/controller/DcDeviceOnlineController.java
  2. 21
      zc-business/src/main/java/com/zc/business/controller/DcTrafficStatisticsController.java
  3. 263
      zc-business/src/main/java/com/zc/business/controller/DcTrafficSurveyDataController.java
  4. 172
      zc-business/src/main/java/com/zc/business/controller/SideSlopeController.java
  5. 130
      zc-business/src/main/java/com/zc/business/domain/DcTrafficSurveyData.java
  6. 8
      zc-business/src/main/java/com/zc/business/domain/OnlineSum.java
  7. 5
      zc-business/src/main/java/com/zc/business/enums/UniversalEnum.java
  8. 71
      zc-business/src/main/java/com/zc/business/mapper/DcTrafficSurveyDataMapper.java
  9. 6
      zc-business/src/main/java/com/zc/business/service/IDcTrafficStatisticsService.java
  10. 80
      zc-business/src/main/java/com/zc/business/service/IDcTrafficSurveyDataService.java
  11. 91
      zc-business/src/main/java/com/zc/business/service/impl/DcTrafficStatisticsServiceImpl.java
  12. 248
      zc-business/src/main/java/com/zc/business/service/impl/DcTrafficSurveyDataServiceImpl.java
  13. 4
      zc-business/src/main/java/com/zc/business/service/impl/DcWarningServiceImpl.java
  14. 124
      zc-business/src/main/resources/mapper/business/DcTrafficSurveyDataMapper.xml

17
zc-business/src/main/java/com/zc/business/controller/DcDeviceOnlineController.java

@ -151,7 +151,11 @@ public class DcDeviceOnlineController extends BaseController {
for (String type : types) {
Map<String, String> map = new HashMap<>();
List<OnlineSum> listOfType = stringListMap.getOrDefault(type, new ArrayList<>());
Map<LocalDate, List<OnlineSum>> localDateListMap = listOfType.stream()
.collect(Collectors.groupingBy(onlineSum -> onlineSum.getStatisticalDate().toLocalDate()));
/*
Map<LocalDate, List<OnlineSum>> localDateListMap = listOfType.stream().collect(Collectors.groupingBy(OnlineSum::getStatisticalDate));
*/
for (LocalDate date = start.toLocalDate(); date.isBefore(end.toLocalDate().plusDays(1)); date = date.plusDays(1)) {
List<OnlineSum> dayList = localDateListMap.getOrDefault(date, new ArrayList<>());
map.put(date.toString(), MathUtil.doubleTwoDecimalStr(dayList.stream().mapToDouble(OnlineSum::getOnlineRate).average().orElse(0.0)) + "%");
@ -191,7 +195,8 @@ public class DcDeviceOnlineController extends BaseController {
List<OnlineSum> listOfType = stringListMap.getOrDefault(type, new ArrayList<>());
// 按日期分组
Map<LocalDate, List<OnlineSum>> localDateListMap = listOfType.stream().collect(Collectors.groupingBy(OnlineSum::getStatisticalDate));
Map<LocalDate, List<OnlineSum>> localDateListMap = listOfType.stream() .collect(Collectors.groupingBy(onlineSum -> onlineSum.getStatisticalDate().toLocalDate()));
// 按日期统计
for (LocalDate date = start.toLocalDate(); date.isBefore(end.toLocalDate().plusDays(1)); date = date.plusDays(1)) {
@ -203,7 +208,7 @@ public class DcDeviceOnlineController extends BaseController {
LocalDateTime startHour = LocalDateTime.of(date, LocalTime.of(hour, 0));
LocalDateTime endHour = startHour.plusHours(1);
List<OnlineSum> hourList = dayList.stream()
.filter(os -> os.getStatisticalDate().isAfter(ChronoLocalDate.from(startHour)) && os.getStatisticalDate().isBefore(ChronoLocalDate.from(endHour)))
.filter(os -> os.getStatisticalDate().toLocalDate().isAfter(ChronoLocalDate.from(startHour)) && os.getStatisticalDate().toLocalDate().isBefore(ChronoLocalDate.from(endHour)))
.collect(Collectors.toList());
double averageRate = hourList.stream().mapToDouble(OnlineSum::getOnlineRate).average().orElse(0.0);
@ -315,8 +320,8 @@ public class DcDeviceOnlineController extends BaseController {
itemMap.put(SUCESS_RATE, formatPercentage(onlineRate*100));//在线率
itemMap.put(FAIL_RATE, formatPercentage(offlineRate*100));//离线率
// 累加总的在线和离线设备数量
/* totalOnline.addAndGet(onlineCount);
totalOffline.addAndGet(offlineCount);*/
totalOnline.addAndGet(onlineCount);
totalOffline.addAndGet(offlineCount);
returnMap.put(v, itemMap);
});
Map<String, Object> allMap = new HashMap<>();
@ -333,8 +338,8 @@ public class DcDeviceOnlineController extends BaseController {
Map<String, Long> totalOfflineMap = Collections.unmodifiableMap(new HashMap<String, Long>() {{
put(FAIL_RATE, totalOffline.get());
}});
allMap.put(SUCESS_RATE, formatPercentage((totalOnlineMap.get(SUCESS_RATE)/useDeviceList.size())*100) );
allMap.put(FAIL_RATE,formatPercentage((totalOfflineMap.get(FAIL_RATE)/useDeviceList.size())*100));
allMap.put(SUCESS_RATE, formatPercentage(((double)totalOnlineMap.get(SUCESS_RATE)/useDeviceList.size())*100) );
allMap.put(FAIL_RATE,formatPercentage(((double)totalOfflineMap.get(FAIL_RATE)/useDeviceList.size())*100));
returnMap.put(All_TYPE, allMap);
Map<String, Object> sortMap = new TreeMap<>();
String orderRule = redisCache.getCacheObject(ORDERRULE);

21
zc-business/src/main/java/com/zc/business/controller/DcTrafficStatisticsController.java

@ -303,6 +303,27 @@ public AjaxResult realTimeTrafficFlow(String startDate, String direction,String
// 将查询结果封装为成功响应并返回
return AjaxResult.success(mapList);
}
/**
* 车流量异常事件流量查询
* @param eventId 事件id
*/
@ApiOperation("车流量异常事件流量查询")
@GetMapping("/history/eventtrafficflowcnt")
public AjaxResult eventtrafficflowcnt(String eventId ) throws HttpException {
JSONArray mapList = dcTrafficStatisticsService.eventtrafficflowcnt(eventId);
// 将查询结果封装为成功响应并返回
return AjaxResult.success(mapList);
}
/**
* 交通流统计分析重点数据查询交通流异常信息
*/
@ApiOperation("交通流统计分析重点数据查询交通流异常信息")
@GetMapping("/history/exampleQueryTrafficFlowAnomalies")
public AjaxResult exampleQueryTrafficFlowAnomalies(String startTime,String endTime ) throws HttpException {
JSONArray mapList = dcTrafficStatisticsService.exampleQueryTrafficFlowAnomalies(startTime,endTime);
// 将查询结果封装为成功响应并返回
return AjaxResult.success(mapList);
}
/**
* 导出车流量时段分析

263
zc-business/src/main/java/com/zc/business/controller/DcTrafficSurveyDataController.java

@ -0,0 +1,263 @@
package com.zc.business.controller;
import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.zc.business.domain.DcDevice;
import com.zc.business.enums.UniversalEnum;
import com.zc.common.core.httpclient.exception.HttpException;
import io.swagger.v3.oas.annotations.Parameter;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.zc.business.domain.DcTrafficSurveyData;
import com.zc.business.service.IDcTrafficSurveyDataService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
/**
* 一类交调数据Controller
*
* @author liuwenge
* @date 2024-10-29
*/
@RestController
@RequestMapping("/trafficSurveyData/dcTrafficSurveyData")
public class DcTrafficSurveyDataController extends BaseController
{
@Autowired
private IDcTrafficSurveyDataService dcTrafficSurveyDataService;
@Resource
private DcDeviceController dcDeviceController;
@Scheduled(cron = "0 5 * * * ?")
public void syncTrafficSectionData() throws HttpException, IOException {
HashMap<String, Object> props = new HashMap<>();
// 设置查询条件的键为“timestamp$BTW”,表示时间戳在一定范围内
props.put("terms[0].column", "timestamp$BTW");
ArrayList<String> dateList = new ArrayList<>();
// 添加当前前一小时的开始和结束时间到列表,用于设定时间范围
Date now = new Date();
// 计算上一个小时的时间
Date lastHourStart = DateUtil.beginOfHour(DateUtil.offsetHour(now, -1));
Date lastHourEnd = DateUtil.endOfHour(DateUtil.offsetHour(now, -1));
// 将上一个小时的开始和结束时间添加到列表
dateList.add(DateUtil.format(lastHourStart, "yyyy-MM-dd HH:mm:ss"));
dateList.add(DateUtil.format(lastHourEnd, "yyyy-MM-dd HH:mm:ss"));
// 将日期列表以逗号分隔并设置为查询条件的值
props.put("terms[0].value", String.join(UniversalEnum.COMMA.getValue(), dateList));
props.put("paging", false);
props.put("sorts[0].order", "asc");
props.put("sorts[0].name", "timestamp");
List<DcDevice> deviceList = dcTrafficSurveyDataService.selectDeviceList();
String propertyId = "01"; //功能码
List<DcTrafficSurveyData> batchData = new ArrayList<>();
for (DcDevice dcDevice : deviceList) {
Object data = JSON.parseObject(dcDeviceController.queryDeviceProperties(dcDevice.getIotDeviceId(), propertyId, props).get("data").toString()).get("data");
JSONArray dataArray = JSON.parseArray(data.toString());
Integer hezeTotal = 0;
Integer jinanTotal = 0;
for (Object o : dataArray) {
JSONObject jsonObject = JSON.parseObject(o.toString());
JSONObject formatValue = JSON.parseObject(jsonObject.get("formatValue").toString());
hezeTotal += Integer.parseInt(formatValue.get("1").toString());
jinanTotal += Integer.parseInt(formatValue.get("3").toString());
}
//菏泽方向数据
DcTrafficSurveyData hezeData = new DcTrafficSurveyData();
hezeData.setIotDeviceId(dcDevice.getIotDeviceId());
hezeData.setStakeMark(dcDevice.getStakeMark());
hezeData.setDirection("1");
hezeData.setTimestamp(lastHourStart);
hezeData.setTrafficVolume(Long.valueOf(hezeTotal));
batchData.add(hezeData);
//济南方向数据
DcTrafficSurveyData jinanData = new DcTrafficSurveyData();
jinanData.setIotDeviceId(dcDevice.getIotDeviceId());
jinanData.setStakeMark(dcDevice.getStakeMark());
jinanData.setDirection("3");
jinanData.setTimestamp(lastHourStart);
jinanData.setTrafficVolume(Long.valueOf(jinanTotal));
batchData.add(jinanData);
}
dcTrafficSurveyDataService.batchInsert(batchData);
}
/**
* 查询一类交调数据列表
*/
@GetMapping("/list")
public AjaxResult list(DcTrafficSurveyData dcTrafficSurveyData)
{
return dcTrafficSurveyDataService.selectDcTrafficSurveyDataList(dcTrafficSurveyData);
}
/**
* 导出一类交调数据列表
*/
@Log(title = "一类交调数据", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, DcTrafficSurveyData dcTrafficSurveyData) throws IOException {
AjaxResult ajaxResult = dcTrafficSurveyDataService.selectDcTrafficSurveyDataList(dcTrafficSurveyData);
if (ajaxResult.get("code").equals(UniversalEnum.TWO_HUNDRED.getNumber())) {
Map<String,Object> data = (Map<String, Object>) ajaxResult.get("data");
List<Map<String,String>> columnList = (List<Map<String,String>>) data.get("columnList");
List<Map<String,Object>> rowList = (List<Map<String,Object>>) data.get("rowList");
XSSFWorkbook workbook = new XSSFWorkbook(); // 创建工作簿
Sheet sheet = workbook.createSheet("一类交调站"); // 创建工作表
// 创建数据行样式
CellStyle dataStyle = workbook.createCellStyle();
dataStyle.setAlignment(HorizontalAlignment.CENTER);
dataStyle.setVerticalAlignment(VerticalAlignment.CENTER);
dataStyle.setBorderRight(BorderStyle.THIN);
dataStyle.setRightBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
dataStyle.setBorderLeft(BorderStyle.THIN);
dataStyle.setLeftBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
dataStyle.setBorderTop(BorderStyle.THIN);
dataStyle.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
dataStyle.setBorderBottom(BorderStyle.THIN);
dataStyle.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
Font dataFont = workbook.createFont();
dataFont.setFontName(UniversalEnum.ARIAL.getValue());
dataFont.setFontHeightInPoints((short) UniversalEnum.TEN.getNumber());
dataStyle.setFont(dataFont);
// 创建表头样式
CellStyle headerStyle = workbook.createCellStyle();
headerStyle.cloneStyleFrom(dataStyle);
headerStyle.setAlignment(HorizontalAlignment.CENTER);
headerStyle.setVerticalAlignment(VerticalAlignment.CENTER);
headerStyle.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex());
headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
Font headerFont = workbook.createFont();
headerFont.setFontName(UniversalEnum.ARIAL.getValue());
headerFont.setFontHeightInPoints((short) UniversalEnum.TEN.getNumber());
headerFont.setBold(true);
headerFont.setColor(IndexedColors.WHITE.getIndex());
headerStyle.setFont(headerFont);
// 添加表头
Row row = sheet.createRow(UniversalEnum.ZERO.getNumber());
Cell cell = row.createCell(UniversalEnum.ZERO.getNumber());
cell.setCellValue("设备名称");
cell.setCellStyle(headerStyle);
cell = row.createCell(UniversalEnum.ONE.getNumber());
cell.setCellValue("方向");
cell.setCellStyle(headerStyle);
int i;
for (i = 0; i < columnList.size(); i++) {
cell = row.createCell(i + 2);
cell.setCellValue(columnList.get(i).get("label").toString());
cell.setCellStyle(headerStyle);;
}
cell = row.createCell(i + 2);
cell.setCellValue("合计");
cell.setCellStyle(headerStyle);
for (int j = 0; j < rowList.size(); j++) {
Row subHeaderRow = sheet.createRow(j+1);
cell = subHeaderRow.createCell(UniversalEnum.ZERO.getNumber());
cell.setCellValue("一类交调站"+rowList.get(j).get("stakeMark").toString());
cell.setCellStyle(dataStyle);
cell = subHeaderRow.createCell(UniversalEnum.ONE.getNumber());
cell.setCellValue(rowList.get(j).get("direction").toString().equals("1") ? "济南方向" : "菏泽方向");
cell.setCellStyle(dataStyle);
int k = 0;
for (k = 0; k < columnList.size(); k++) {
cell = subHeaderRow.createCell(k + 2);
cell.setCellValue(rowList.get(j).get(columnList.get(k).get("key")).toString());
cell.setCellStyle(dataStyle);;
}
cell = subHeaderRow.createCell(k+2);
cell.setCellValue(rowList.get(j).get("total").toString());
cell.setCellStyle(dataStyle);
}
// 写入文件
try (ServletOutputStream outputStream = response.getOutputStream()){
workbook.write(outputStream);
} finally {
workbook.close();
}
}
}
/**
* 获取一类交调数据详细信息
*/
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") Long id)
{
return AjaxResult.success(dcTrafficSurveyDataService.selectDcTrafficSurveyDataById(id));
}
/**
* 新增一类交调数据
*/
@Log(title = "一类交调数据", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody DcTrafficSurveyData dcTrafficSurveyData)
{
return toAjax(dcTrafficSurveyDataService.insertDcTrafficSurveyData(dcTrafficSurveyData));
}
/**
* 修改一类交调数据
*/
@Log(title = "一类交调数据", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody DcTrafficSurveyData dcTrafficSurveyData)
{
return toAjax(dcTrafficSurveyDataService.updateDcTrafficSurveyData(dcTrafficSurveyData));
}
/**
* 删除一类交调数据
*/
@Log(title = "一类交调数据", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] ids)
{
return toAjax(dcTrafficSurveyDataService.deleteDcTrafficSurveyDataByIds(ids));
}
}

172
zc-business/src/main/java/com/zc/business/controller/SideSlopeController.java

@ -2,28 +2,44 @@ package com.zc.business.controller;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.system.service.ISysConfigService;
import com.zc.business.domain.DcWarning;
import com.zc.business.enums.UniversalEnum;
import com.zc.business.service.IDcWarningService;
import com.zc.common.core.httpclient.OkHttp;
import com.zc.common.core.httpclient.exception.HttpException;
import com.zc.common.core.httpclient.request.RequestParams;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import okhttp3.*;
import org.eclipse.paho.client.mqttv3.*;
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.*;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.zip.GZIPInputStream;
/**
@ -38,7 +54,9 @@ import java.util.concurrent.TimeUnit;
@Component
@RequestMapping("/sideSlope")
public class SideSlopeController extends BaseController {
@Resource
private RedisCache redisCache;
public static final MediaType JSON = MediaType.get("application/json; charset=utf-8");
@Resource
private IDcWarningService dcWarningService;
@Autowired
@ -47,6 +65,156 @@ public class SideSlopeController extends BaseController {
private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
@ApiOperation("获取token")
@PostMapping("/authenticate")
public JSONObject authenticate() throws IOException {
OkHttpClient client = new OkHttpClient();
// 构造请求体
Map<String, String> map = new LinkedHashMap<>();
map.put("UserNameOrEmailAddress", configService.selectConfigByKey("UserNameOrEmailAddress"));//用户名
map.put("Password", configService.selectConfigByKey("Password"));//登录密码
ObjectMapper objectMapper = new ObjectMapper();
String jsonInput = objectMapper.writeValueAsString(map);
RequestBody requestBody = RequestBody.create(JSON, jsonInput);
// 创建请求
Request request = new Request.Builder()
.url(configService.selectConfigByKey("accessTokenApi"))
.post(requestBody)
.build();
// 发送请求并处理响应
try (Response response = client.newCall(request).execute()) {
if (!response.isSuccessful()) {
throw new IOException("Unexpected code " + response);
}
// 正确解析响应体中的JSON数据
String responseBody = response.body().string();
JSONObject jsonResult = JSONObject.parseObject(responseBody);
return jsonResult;
}
}
/**
* 获取测点列表
* @return
* @throws IOException
* @throws HttpException
*/
@ApiOperation("获取边坡测点列表")
@GetMapping("/GetMeasurePointList")
public AjaxResult GetMeasurePointList() throws IOException, HttpException {
JSONObject jsonResult = null;
OkHttp okHttp = new OkHttp();
RequestParams requestParams = new RequestParams();
requestParams.put("proCode", configService.selectConfigByKey("proCode"));
requestParams.put("unitCode", configService.selectConfigByKey("unitCode"));
Object accessToken = redisCache.getCacheObject("accessToken");
if (accessToken==null){
JSONObject authenticate = authenticate();
accessToken = authenticate.getJSONObject("result").getString("accessToken");
redisCache.setCacheObject("accessToken",accessToken);
redisCache.expire("accessToken", UniversalEnum.THREE.getNumber() * UniversalEnum.TWENTY_FOUR.getNumber() * UniversalEnum.THREE_THOUSAND_SIX_HUNDRED.getNumber());//设置过期时间s秒
}
// http://jsgl.sdgsbim.com:8616/api/RoadMajorPlatform/GetMeasurePointList?proCode=JHGKJ&unitCode=60-01.0002.00.00
Map<String, String> header = new HashMap<>();
header.put("Authorization", "Bearer "+accessToken.toString());
Response response // 请求响应
= okHttp
.headers(header)
.url(configService.selectConfigByKey("GetMeasurePointListAPI")) // 请求地址
.data(requestParams) // 请求参数
.get(); // 请求方法
if (response.body() != null) {
jsonResult = JSONObject.parseObject(response.body().string());
}
// 正确解析响应体中的JSON数据
return AjaxResult.success(jsonResult) ;
}
/**
* 获取长历史数据
* @return
* @throws IOException
* @throws HttpException
*/
@ApiOperation("获取边坡历史数据")
@GetMapping("/GetPointDataListAsync")
public AjaxResult GetPointDataListAsync(
@ApiParam(value = "测点编号", name = "meaPointNum", required = true) String meaPointNum,
@ApiParam(value = "开始时间(时间戳)", name = "starttime", required = true) long starttime,
@ApiParam(value = "结束时间(时间戳)", name = "endtime", required = true) long endtime
) throws IOException, HttpException {
JSONObject jsonResult = null;
JSONArray jsonArray = null;
OkHttp okHttp = new OkHttp();
RequestParams requestParams = new RequestParams();
requestParams.put("projCode",configService.selectConfigByKey("proCode"));//项目编号 如 JHGKJ
requestParams.put("unitCode", configService.selectConfigByKey("unitCode"));//项目单位工程编号 如 60-01.0002.00.00
requestParams.put("meaPointNum", meaPointNum);//测点编号如 PR-YLJ01-067441-05/05
requestParams.put("starttime", starttime);//开始时间如 1713369599000
requestParams.put("endtime", endtime);//结束时间 如 1713887999000
Object accessToken = redisCache.getCacheObject("accessToken");
if (accessToken==null){
System.out.println("null+++++++++++++++++++++++");
JSONObject authenticate = authenticate();
accessToken = authenticate.getJSONObject("result").getString("accessToken");
redisCache.setCacheObject("accessToken",accessToken);
redisCache.expire("accessToken", UniversalEnum.THREE.getNumber() * UniversalEnum.TWENTY_FOUR.getNumber() * UniversalEnum.THREE_THOUSAND_SIX_HUNDRED.getNumber());//设置过期时间s秒
}
// http://jsgl.sdgsbim.com:8616/api/RoadMajorPlatform/GetMeasurePointList?proCode=JHGKJ&unitCode=60-01.0002.00.00
Map<String, String> header = new HashMap<>();
header.put("Authorization", "Bearer "+accessToken.toString());
Response response // 请求响应
= okHttp
.headers(header)
.url(configService.selectConfigByKey("GetPointDataListAsyncAPI")) // 请求地址
.data(requestParams) // 请求参数
.get(); // 请求方法
if (response.body() != null) {
jsonResult = JSONObject.parseObject(response.body().string());
String jsonObjec =jsonResult.getString("result").replace("\r\n", UniversalEnum.EMPTY_STRING.getValue());
jsonArray = extracted(jsonObjec);
}
// 正确解析响应体中的JSON数据
return AjaxResult.success(jsonArray);
}
/**
* Base64解码
*/
private JSONArray extracted(String base64EncodedCompressedData) throws IOException {
// Base64解码
byte[] compressedData = Base64.getDecoder().decode(base64EncodedCompressedData);
StringBuilder output = new StringBuilder();
// 解压缩
try (ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(compressedData);
GZIPInputStream gzipInputStream = new GZIPInputStream(byteArrayInputStream);
InputStreamReader inputStreamReader = new InputStreamReader(gzipInputStream, StandardCharsets.UTF_8);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader)) {
String line;
while ((line = bufferedReader.readLine()) != null) {
output.append(line);
}
}
// 将StringBuilder转换为字符串
String jsonString = output.toString();
// 将字符串转换为JSONObject
JSONArray jsonObject = JSONArray.parseArray(jsonString);
return jsonObject;
}
@PostConstruct
private AjaxResult mqttSubscription() throws Exception {

130
zc-business/src/main/java/com/zc/business/domain/DcTrafficSurveyData.java

@ -0,0 +1,130 @@
package com.zc.business.domain;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity;
/**
* 一类交调数据对象 dc_traffic_survey_data
*
* @author liuwenge
* @date 2024-10-29
*/
public class DcTrafficSurveyData extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** $column.columnComment */
private Long id;
/** 物联设备主键 */
@Excel(name = "物联设备主键")
private String iotDeviceId;
/** 所在桩号 */
@Excel(name = "所在桩号")
private String stakeMark;
/** 方向1-上行,2-中,3-下行 */
@Excel(name = "方向1-上行,2-中,3-下行")
private String direction;
/** 采集时间 */
@JsonFormat(pattern = "yyyy-MM-dd")
@Excel(name = "采集时间", width = 30, dateFormat = "yyyy-MM-dd")
private Date timestamp;
/** 车流量 */
@Excel(name = "车流量")
private Long trafficVolume;
private String type;
private String times;
public void setId(Long id)
{
this.id = id;
}
public Long getId()
{
return id;
}
public void setIotDeviceId(String iotDeviceId)
{
this.iotDeviceId = iotDeviceId;
}
public String getIotDeviceId()
{
return iotDeviceId;
}
public void setStakeMark(String stakeMark)
{
this.stakeMark = stakeMark;
}
public String getStakeMark()
{
return stakeMark;
}
public void setDirection(String direction)
{
this.direction = direction;
}
public String getDirection()
{
return direction;
}
public void setTimestamp(Date timestamp)
{
this.timestamp = timestamp;
}
public Date getTimestamp()
{
return timestamp;
}
public void setTrafficVolume(Long trafficVolume)
{
this.trafficVolume = trafficVolume;
}
public Long getTrafficVolume()
{
return trafficVolume;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getTimes() {
return times;
}
public void setTimes(String times) {
this.times = times;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("id", getId())
.append("iotDeviceId", getIotDeviceId())
.append("stakeMark", getStakeMark())
.append("direction", getDirection())
.append("timestamp", getTimestamp())
.append("trafficVolume", getTrafficVolume())
.toString();
}
}

8
zc-business/src/main/java/com/zc/business/domain/OnlineSum.java

@ -39,7 +39,7 @@ public class OnlineSum implements java.io.Serializable {
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@Excel(name = "统计日期", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
private LocalDate statisticalDate;//统计日期
private LocalDateTime statisticalDate;//统计日期
private String deviceType;//设备类型
private int totalCount;//当天总次数
private int sendCount;//发送数据包总数
@ -134,11 +134,11 @@ public class OnlineSum implements java.io.Serializable {
this.networkQuality = networkQuality;
}
public LocalDate getStatisticalDate() {
public LocalDateTime getStatisticalDate() {
return statisticalDate;
}
public void setStatisticalDate(LocalDate statisticalDate) {
public void setStatisticalDate(LocalDateTime statisticalDate) {
this.statisticalDate = statisticalDate;
}
@ -296,7 +296,7 @@ public class OnlineSum implements java.io.Serializable {
this.networkQuality = onlineLog.getNetworkQuality();
if(this.deviceStatus.equals(DcDevice.ONLINE))
this.lastOnlineTime = onlineLog.getMonitorTime();
this.statisticalDate = onlineLog.getMonitorTime().toLocalDate();
this.statisticalDate = onlineLog.getMonitorTime();
return this;
}

5
zc-business/src/main/java/com/zc/business/enums/UniversalEnum.java

@ -1789,6 +1789,11 @@ RADAR_ASSOCIATED_MONITORING_POINT_QUERY_INTERFACE(0,"/api/radar/v1/selectRelateB
// 全路段双向实时车流量 /api/dc/query/gan_jihe_d_vehtypeflow
THE_WHOLE_SECTION_TWO_WAY_REAL_TIME_TRAFFIC_FLOW_URL(0, "/api/dc/query/gan_jihe_d_vehtypeflow"),
//车流量异常事件流量查询
QUERY_TRAFFIC_OF_ABNORMAL_TRAFFIC_EVENTS(0,"/api/dc/query/gan_jihe_d_eventtrafficflowcnt"),
// *交通流统计分析重点数据查询交通流异常信息
TRAFFIC_FLOW_STATISTICAL_KEY_DATA_QUERY(0,"/api/dc/query/gan_jihe_d_trafficexception"),
// 雷达数据 http://www.nmc.cn/publish/radar/chinaall.html
RADAR_DATA(0, "http://www.nmc.cn/publish/radar/chinaall.html"),

71
zc-business/src/main/java/com/zc/business/mapper/DcTrafficSurveyDataMapper.java

@ -0,0 +1,71 @@
package com.zc.business.mapper;
import java.util.List;
import com.zc.business.domain.DcDevice;
import com.zc.business.domain.DcTrafficSurveyData;
/**
* 一类交调数据Mapper接口
*
* @author liuwenge
* @date 2024-10-29
*/
public interface DcTrafficSurveyDataMapper
{
/**
* 查询一类交调数据
*
* @param id 一类交调数据主键
* @return 一类交调数据
*/
public DcTrafficSurveyData selectDcTrafficSurveyDataById(Long id);
/**
* 查询一类交调数据列表
*
* @param dcTrafficSurveyData 一类交调数据
* @return 一类交调数据集合
*/
List<DcTrafficSurveyData> selectDcTrafficSurveyDataList(DcTrafficSurveyData dcTrafficSurveyData);
List<DcTrafficSurveyData> selectDay(DcTrafficSurveyData dcTrafficSurveyData);
List<DcTrafficSurveyData> selectMonth(DcTrafficSurveyData dcTrafficSurveyData);
List<DcTrafficSurveyData> selectYear(DcTrafficSurveyData dcTrafficSurveyData);
/**
* 新增一类交调数据
*
* @param dcTrafficSurveyData 一类交调数据
* @return 结果
*/
int insertDcTrafficSurveyData(DcTrafficSurveyData dcTrafficSurveyData);
/**
* 修改一类交调数据
*
* @param dcTrafficSurveyData 一类交调数据
* @return 结果
*/
int updateDcTrafficSurveyData(DcTrafficSurveyData dcTrafficSurveyData);
/**
* 删除一类交调数据
*
* @param id 一类交调数据主键
* @return 结果
*/
int deleteDcTrafficSurveyDataById(Long id);
/**
* 批量删除一类交调数据
*
* @param ids 需要删除的数据主键集合
* @return 结果
*/
int deleteDcTrafficSurveyDataByIds(Long[] ids);
List<DcDevice> selectDeviceList();
int batchInsert(List<DcTrafficSurveyData> batchData);
}

6
zc-business/src/main/java/com/zc/business/service/IDcTrafficStatisticsService.java

@ -65,4 +65,10 @@ public interface IDcTrafficStatisticsService {
int trafficFlowAtToll(String startDate)throws HttpException, IOException;
int yesterdayTrafficFlowAtToll(String startDate)throws HttpException, IOException;
JSONArray eventtrafficflowcnt(String eventId) throws HttpException;
/**
* 交通流统计分析重点数据查询交通流异常信息
*/
JSONArray exampleQueryTrafficFlowAnomalies(String startTime, String endTime) throws HttpException;
}

80
zc-business/src/main/java/com/zc/business/service/IDcTrafficSurveyDataService.java

@ -0,0 +1,80 @@
package com.zc.business.service;
import java.util.List;
import com.ruoyi.common.core.domain.AjaxResult;
import com.zc.business.domain.DcDevice;
import com.zc.business.domain.DcTrafficSurveyData;
/**
* 一类交调数据Service接口
*
* @author liuwenge
* @date 2024-10-29
*/
public interface IDcTrafficSurveyDataService
{
/**
* 查询一类交调数据
*
* @param id 一类交调数据主键
* @return 一类交调数据
*/
public DcTrafficSurveyData selectDcTrafficSurveyDataById(Long id);
/**
* 查询一类交调数据列表
*
* @param dcTrafficSurveyData 一类交调数据
* @return 一类交调数据集合
*/
AjaxResult selectDcTrafficSurveyDataList(DcTrafficSurveyData dcTrafficSurveyData);
/**
* 新增一类交调数据
*
* @param dcTrafficSurveyData 一类交调数据
* @return 结果
*/
int insertDcTrafficSurveyData(DcTrafficSurveyData dcTrafficSurveyData);
/**
* 修改一类交调数据
*
* @param dcTrafficSurveyData 一类交调数据
* @return 结果
*/
int updateDcTrafficSurveyData(DcTrafficSurveyData dcTrafficSurveyData);
/**
* 批量删除一类交调数据
*
* @param ids 需要删除的一类交调数据主键集合
* @return 结果
*/
int deleteDcTrafficSurveyDataByIds(Long[] ids);
/**
* 删除一类交调数据信息
*
* @param id 一类交调数据主键
* @return 结果
*/
int deleteDcTrafficSurveyDataById(Long id);
/**
* 查询所有交调设备
*
* @param
* @return 结果
*/
List<DcDevice> selectDeviceList();
/**
* 批量插入
*
* @param batchData 一类交调数据
* @return 结果
*/
int batchInsert(List<DcTrafficSurveyData> batchData);
}

91
zc-business/src/main/java/com/zc/business/service/impl/DcTrafficStatisticsServiceImpl.java

@ -1368,6 +1368,97 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi
}
@Override
public JSONArray eventtrafficflowcnt(String eventId) throws HttpException {
OkHttp okHttp = new OkHttp();
RequestParams requestParams = new RequestParams();
requestParams.put("sysid", sysid);
JSONObject parameters = new JSONObject() {
{
put("event_id", eventId);
}
};
requestParams.put("parameters", parameters.toJSONString());
Map<String, String> headers = new HashMap<>();
headers.put("Authorization", getAccessToken());
try {
Response response // 请求响应
= okHttp
.headers(headers)
.url(baseUrl + UniversalEnum.QUERY_TRAFFIC_OF_ABNORMAL_TRAFFIC_EVENTS.getValue()) // 请求地址
.data(requestParams) // 请求参数
.post(); // 请求方法
ResponseBody body = response.body();
if (body != null) {
String jsonString = body.string();
if (JSON.isValidArray(jsonString)) {
return JSON.parseArray(jsonString);
} else {
return new JSONArray();
}
}
return new JSONArray();
} catch (IOException e) {
// 处理异常
e.printStackTrace();
return new JSONArray();
}
}
/**
* 交通流统计分析重点数据查询交通流异常信息
*/
@Override
public JSONArray exampleQueryTrafficFlowAnomalies(String startTime, String endTime) throws HttpException {
OkHttp okHttp = new OkHttp();
RequestParams requestParams = new RequestParams();
requestParams.put("sysid", sysid);
JSONObject parameters = new JSONObject() {
{
put("start_time", startTime);
put("end_time", endTime);
}
};
requestParams.put("parameters", parameters.toJSONString());
Map<String, String> headers = new HashMap<>();
headers.put("Authorization", getAccessToken());
try {
Response response // 请求响应
= okHttp
.headers(headers)
.url(baseUrl + UniversalEnum.TRAFFIC_FLOW_STATISTICAL_KEY_DATA_QUERY.getValue()) // 请求地址
.data(requestParams) // 请求参数
.post(); // 请求方法
ResponseBody body = response.body();
if (body != null) {
String jsonString = body.string();
if (JSON.isValidArray(jsonString)) {
return JSON.parseArray(jsonString);
} else {
return new JSONArray();
}
}
return new JSONArray();
} catch (IOException e) {
// 处理异常
e.printStackTrace();
return new JSONArray();
}
}
private Response getResponseTrafficFlowAtToll(String startDate, String stationType) throws HttpException, IOException {
// 创建OkHttpClient.Builder实例
OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder();

248
zc-business/src/main/java/com/zc/business/service/impl/DcTrafficSurveyDataServiceImpl.java

@ -0,0 +1,248 @@
package com.zc.business.service.impl;
import java.util.*;
import java.util.stream.Collectors;
import com.ruoyi.common.core.domain.AjaxResult;
import com.zc.business.domain.DcDevice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zc.business.mapper.DcTrafficSurveyDataMapper;
import com.zc.business.domain.DcTrafficSurveyData;
import com.zc.business.service.IDcTrafficSurveyDataService;
/**
* 一类交调数据Service业务层处理
*
* @author liuwenge
* @date 2024-10-29
*/
@Service
public class DcTrafficSurveyDataServiceImpl implements IDcTrafficSurveyDataService
{
@Autowired
private DcTrafficSurveyDataMapper dcTrafficSurveyDataMapper;
/**
* 查询一类交调数据
*
* @param id 一类交调数据主键
* @return 一类交调数据
*/
@Override
public DcTrafficSurveyData selectDcTrafficSurveyDataById(Long id)
{
return dcTrafficSurveyDataMapper.selectDcTrafficSurveyDataById(id);
}
/**
* 查询一类交调数据列表
*
* @param dcTrafficSurveyData 一类交调数据
* @return 一类交调数据
*/
@Override
public AjaxResult selectDcTrafficSurveyDataList(DcTrafficSurveyData dcTrafficSurveyData)
{
List<Map<String,Object>> rowList = new ArrayList<>();
List<Map<String,String>> columnList = getColumnList(dcTrafficSurveyData);
List<DcTrafficSurveyData> dataList = new ArrayList<>();
if (dcTrafficSurveyData.getType().equals("day")){
dataList = dcTrafficSurveyDataMapper.selectDay(dcTrafficSurveyData);
} else if (dcTrafficSurveyData.getType().equals("month")){
dataList = dcTrafficSurveyDataMapper.selectMonth(dcTrafficSurveyData);
} else if (dcTrafficSurveyData.getType().equals("year")){
dataList = dcTrafficSurveyDataMapper.selectYear(dcTrafficSurveyData);
}
Map<String,Map<String, Map<String, List<DcTrafficSurveyData>>>> groupedData = dataList.stream()
.collect(Collectors.groupingBy(
DcTrafficSurveyData::getIotDeviceId, // 第一级分组:按设备Id
Collectors.groupingBy(DcTrafficSurveyData::getDirection, // 第二级分组:按方向
Collectors.groupingBy(DcTrafficSurveyData::getTimes) // 第三级分组:按时间
)));
List<DcDevice> deviceList = dcTrafficSurveyDataMapper.selectDeviceList();
Map<String,Object> row = new HashMap<>();
for (DcDevice dcDevice : deviceList) {
if (groupedData.containsKey(dcDevice.getIotDeviceId())){
Map<String,Map<String, List<DcTrafficSurveyData>>> directionData = groupedData.get(dcDevice.getIotDeviceId());
//单个设备济南方向数据
row = new HashMap<>();
row.put("stakeMark",dcDevice.getStakeMark());
row.put("direction","1");
if (directionData.containsKey("1")){
Integer total = 0;
//单个设备济南方向分时数据
Map<String,List<DcTrafficSurveyData>> directionList = directionData.get("1");
for (Map<String, String> columnMap : columnList) {
if (directionList.containsKey(columnMap.get("key"))){
List<DcTrafficSurveyData> timeList = directionList.get(columnMap.get("key"));
row.put(columnMap.get("key"),timeList.get(0).getTrafficVolume());
total += timeList.get(0).getTrafficVolume().intValue();
} else {
row.put(columnMap.get("key"),0);
}
}
row.put("total",total);
} else {
for (Map<String, String> columnMap : columnList) {
row.put(columnMap.get("key"),0);
row.put("total",0);
}
}
rowList.add(row);
//单个设备菏泽方向数据
row = new HashMap<>();
row.put("stakeMark",dcDevice.getStakeMark());
row.put("direction","3");
if (directionData.containsKey("3")){
Integer total = 0;
//单个设备菏泽方向分时数据
Map<String,List<DcTrafficSurveyData>> directionList = directionData.get("3");
for (Map<String, String> columnMap : columnList) {
if (directionList.containsKey(columnMap.get("key"))){
List<DcTrafficSurveyData> timeList = directionList.get(columnMap.get("key"));
row.put(columnMap.get("key"),timeList.get(0).getTrafficVolume());
total += timeList.get(0).getTrafficVolume().intValue();
} else {
row.put(columnMap.get("key"),0);
}
}
row.put("total",total);
} else {
for (Map<String, String> columnMap : columnList) {
row.put(columnMap.get("key"),0);
row.put("total",0);
}
}
rowList.add(row);
} else {
row = new HashMap<>();
row.put("stakeMark",dcDevice.getStakeMark());
row.put("direction","1");
for (Map<String, String> columnMap : columnList) {
row.put(columnMap.get("key"),0);
}
row.put("total",0);
rowList.add(row);
row= new HashMap<>();
row.put("stakeMark",dcDevice.getStakeMark());
row.put("direction","3");
for (Map<String, String> columnMap : columnList) {
row.put(columnMap.get("key"),0);
}
row.put("total",0);
rowList.add(row);
}
}
Map<String,Object> result = new HashMap<>();
result.put("rowList",rowList);
result.put("columnList",columnList);
return AjaxResult.success(result);
}
public List<Map<String,String>> getColumnList(DcTrafficSurveyData dcTrafficSurveyData){
List<Map<String,String>> columnList = new ArrayList<>();
Map<String,String> column;
if (dcTrafficSurveyData.getType().equals("day")){
for (int i = 0; i < 24; i++) {
column = new HashMap<>();
column.put("label",i+"点");
column.put("key",String.valueOf(i));
columnList.add(column);
}
} else if (dcTrafficSurveyData.getType().equals("month")){
Calendar calendar = Calendar.getInstance();
calendar.setTime(dcTrafficSurveyData.getTimestamp());
int maxDay = calendar.getActualMaximum(Calendar.DAY_OF_MONTH); // 获取这个月的最大天数
for (int i = 1; i <= maxDay; i++) {
column = new HashMap<>();
column.put("label",i+"日");
column.put("key",String.valueOf(i));
columnList.add(column);
}
} else if (dcTrafficSurveyData.getType().equals("year")){
for (int i = 1; i <= 12; i++) {
column = new HashMap<>();
column.put("label",i+"月");
column.put("key",String.valueOf(i));
columnList.add(column);
}
}
return columnList;
}
/**
* 新增一类交调数据
*
* @param dcTrafficSurveyData 一类交调数据
* @return 结果
*/
@Override
public int insertDcTrafficSurveyData(DcTrafficSurveyData dcTrafficSurveyData)
{
return dcTrafficSurveyDataMapper.insertDcTrafficSurveyData(dcTrafficSurveyData);
}
/**
* 修改一类交调数据
*
* @param dcTrafficSurveyData 一类交调数据
* @return 结果
*/
@Override
public int updateDcTrafficSurveyData(DcTrafficSurveyData dcTrafficSurveyData)
{
return dcTrafficSurveyDataMapper.updateDcTrafficSurveyData(dcTrafficSurveyData);
}
/**
* 批量删除一类交调数据
*
* @param ids 需要删除的一类交调数据主键
* @return 结果
*/
@Override
public int deleteDcTrafficSurveyDataByIds(Long[] ids)
{
return dcTrafficSurveyDataMapper.deleteDcTrafficSurveyDataByIds(ids);
}
/**
* 删除一类交调数据信息
*
* @param id 一类交调数据主键
* @return 结果
*/
@Override
public int deleteDcTrafficSurveyDataById(Long id)
{
return dcTrafficSurveyDataMapper.deleteDcTrafficSurveyDataById(id);
}
/**
* 查询所有交调设备
*
* @param
* @return 结果
*/
@Override
public List<DcDevice> selectDeviceList(){
return dcTrafficSurveyDataMapper.selectDeviceList();
}
/**
* 批量插入
*
* @param batchData 一类交调数据
* @return 结果
*/
@Override
public int batchInsert(List<DcTrafficSurveyData> batchData){
return dcTrafficSurveyDataMapper.batchInsert(batchData);
}
}

4
zc-business/src/main/java/com/zc/business/service/impl/DcWarningServiceImpl.java

@ -1158,6 +1158,10 @@ public class DcWarningServiceImpl implements IDcWarningService {
JsonNode roocallPostApiGetRegionstNode = objectMapper.readTree(callPostApiGetRegions);
JsonNode jsonNode = roocallPostApiGetRegionstNode.get("data");
JsonNode jsonNodelist = jsonNode.get("list");
if (jsonNodelist.isEmpty()){
return "";
}
JsonNode code = jsonNodelist.get(UniversalEnum.ZERO.getNumber()).get("cameraIndexCode");
// 使用 textValue() 方法获取纯字符串
String codestring = code.textValue();

124
zc-business/src/main/resources/mapper/business/DcTrafficSurveyDataMapper.xml

@ -0,0 +1,124 @@
<?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.zc.business.mapper.DcTrafficSurveyDataMapper">
<resultMap type="DcTrafficSurveyData" id="DcTrafficSurveyDataResult">
<result property="id" column="id" />
<result property="iotDeviceId" column="iot_device_id" />
<result property="stakeMark" column="stake_mark" />
<result property="direction" column="direction" />
<result property="timestamp" column="timestamp" />
<result property="trafficVolume" column="traffic_volume" />
</resultMap>
<sql id="selectDcTrafficSurveyDataVo">
select id, iot_device_id, stake_mark, direction, timestamp, traffic_volume from dc_traffic_survey_data
</sql>
<select id="selectDcTrafficSurveyDataList" parameterType="DcTrafficSurveyData" resultMap="DcTrafficSurveyDataResult">
<include refid="selectDcTrafficSurveyDataVo"/>
<where>
<if test="iotDeviceId != null and iotDeviceId != ''"> and iot_device_id = #{iotDeviceId}</if>
<if test="stakeMark != null and stakeMark != ''"> and stake_mark = #{stakeMark}</if>
<if test="direction != null and direction != ''"> and direction = #{direction}</if>
<if test="trafficVolume != null "> and traffic_volume = #{trafficVolume}</if>
<if test="type != null and type == 'year'.toString">
and DATE_FORMAT(timestamp,'%Y') = DATE_FORMAT(#{thisTime},'%Y')
</if>
<if test="type != null and type == 'month'.toString">
and DATE_FORMAT(timestamp,'%Y-%m') = DATE_FORMAT(#{thisTime},'%Y-%m')
</if>
<if test="type != null and type == 'year'.toString">
and DATE_FORMAT(timestamp,'%Y-%m-%d') = DATE_FORMAT(#{thisTime},'%Y-%m-%d')
</if>
</where>
</select>
<select id="selectDcTrafficSurveyDataById" parameterType="Long" resultMap="DcTrafficSurveyDataResult">
<include refid="selectDcTrafficSurveyDataVo"/>
where id = #{id}
</select>
<select id="selectDeviceList" resultType="com.zc.business.domain.DcDevice">
SELECT * FROM `dc_device` where device_type = '11' and iot_device_id is not null
</select>
<select id="selectDay" resultType="com.zc.business.domain.DcTrafficSurveyData">
SELECT iot_device_id,stake_mark,direction,HOUR(`timestamp`) times,SUM(traffic_volume) trafficVolume
FROM `dc_traffic_survey_data`
where DATE_FORMAT(`timestamp`,'%Y-%m-%d') = DATE_FORMAT(#{timestamp},'%Y-%m-%d')
GROUP BY iot_device_id,direction,times
</select>
<select id="selectMonth" resultType="com.zc.business.domain.DcTrafficSurveyData">
SELECT iot_device_id,stake_mark,direction,DAY(`timestamp`) times,SUM(traffic_volume) trafficVolume
FROM `dc_traffic_survey_data`
where DATE_FORMAT(`timestamp`,'%Y-%m') = DATE_FORMAT(#{timestamp},'%Y-%m')
GROUP BY iot_device_id,direction,times
</select>
<select id="selectYear" resultType="com.zc.business.domain.DcTrafficSurveyData">
SELECT iot_device_id,stake_mark,direction,MONTH(`timestamp`) times,SUM(traffic_volume) trafficVolume
FROM `dc_traffic_survey_data`
where DATE_FORMAT(`timestamp`,'%Y') = DATE_FORMAT(#{timestamp},'%Y')
GROUP BY iot_device_id,direction,times
</select>
<insert id="insertDcTrafficSurveyData" parameterType="DcTrafficSurveyData" useGeneratedKeys="true" keyProperty="id">
insert into dc_traffic_survey_data
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="iotDeviceId != null">iot_device_id,</if>
<if test="stakeMark != null and stakeMark != ''">stake_mark,</if>
<if test="direction != null">direction,</if>
<if test="timestamp != null">timestamp,</if>
<if test="trafficVolume != null">traffic_volume,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="iotDeviceId != null">#{iotDeviceId},</if>
<if test="stakeMark != null and stakeMark != ''">#{stakeMark},</if>
<if test="direction != null">#{direction},</if>
<if test="timestamp != null">#{timestamp},</if>
<if test="trafficVolume != null">#{trafficVolume},</if>
</trim>
</insert>
<insert id="batchInsert">
<foreach collection="list" item="dcTrafficSurveyData" index="index" separator=";">
insert into dc_traffic_survey_data
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="dcTrafficSurveyData.iotDeviceId != null">iot_device_id,</if>
<if test="dcTrafficSurveyData.stakeMark != null">stake_mark,</if>
<if test="dcTrafficSurveyData.direction != null">direction,</if>
<if test="dcTrafficSurveyData.timestamp != null">timestamp,</if>
<if test="dcTrafficSurveyData.trafficVolume != null">traffic_volume,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="dcTrafficSurveyData.iotDeviceId != null">#{dcTrafficSurveyData.iotDeviceId},</if>
<if test="dcTrafficSurveyData.stakeMark != null">#{dcTrafficSurveyData.stakeMark},</if>
<if test="dcTrafficSurveyData.direction != null">#{dcTrafficSurveyData.direction},</if>
<if test="dcTrafficSurveyData.timestamp != null">#{dcTrafficSurveyData.timestamp},</if>
<if test="dcTrafficSurveyData.trafficVolume != null">#{dcTrafficSurveyData.trafficVolume},</if>
</trim>
</foreach>
</insert>
<update id="updateDcTrafficSurveyData" parameterType="DcTrafficSurveyData">
update dc_traffic_survey_data
<trim prefix="SET" suffixOverrides=",">
<if test="iotDeviceId != null">iot_device_id = #{iotDeviceId},</if>
<if test="stakeMark != null and stakeMark != ''">stake_mark = #{stakeMark},</if>
<if test="direction != null">direction = #{direction},</if>
<if test="timestamp != null">timestamp = #{timestamp},</if>
<if test="trafficVolume != null">traffic_volume = #{trafficVolume},</if>
</trim>
where id = #{id}
</update>
<delete id="deleteDcTrafficSurveyDataById" parameterType="Long">
delete from dc_traffic_survey_data where id = #{id}
</delete>
<delete id="deleteDcTrafficSurveyDataByIds" parameterType="String">
delete from dc_traffic_survey_data where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
</mapper>
Loading…
Cancel
Save