Browse Source

一类交调站数据统计

develop
lau572 4 weeks ago
parent
commit
3541efe6c1
  1. 263
      zc-business/src/main/java/com/zc/business/controller/DcTrafficSurveyDataController.java
  2. 130
      zc-business/src/main/java/com/zc/business/domain/DcTrafficSurveyData.java
  3. 71
      zc-business/src/main/java/com/zc/business/mapper/DcTrafficSurveyDataMapper.java
  4. 80
      zc-business/src/main/java/com/zc/business/service/IDcTrafficSurveyDataService.java
  5. 248
      zc-business/src/main/java/com/zc/business/service/impl/DcTrafficSurveyDataServiceImpl.java
  6. 124
      zc-business/src/main/resources/mapper/business/DcTrafficSurveyDataMapper.xml

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));
}
}

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();
}
}

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);
}

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);
}

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);
}
}

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