Merge branch 'zjw'

This commit is contained in:
zhangjunwen 2024-09-06 08:36:29 +08:00
commit 67d28f7018
7 changed files with 1071 additions and 233 deletions

View File

@ -150,7 +150,7 @@ public class DateUtils {
}
public static String tranUTC2LocalDateTime(String utcTimeString) throws ParseException {
SimpleDateFormat utcFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
SimpleDateFormat utcFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
utcFormat.setTimeZone(TimeZone.getTimeZone("UTC")); // 设置UTC时区
Date utcDate = utcFormat.parse(utcTimeString); // 解析UTC时间
SimpleDateFormat localFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

View File

@ -1,7 +1,15 @@
package com.inspur.module.data.controller.admin.query;
import com.inspur.framework.apilog.core.annotation.ApiAccessLog;
import com.inspur.framework.common.pojo.CommonResult;
import com.inspur.framework.common.pojo.PageParam;
import com.inspur.framework.common.util.object.BeanUtils;
import com.inspur.framework.excel.core.util.ExcelUtils;
import com.inspur.module.data.controller.admin.query.vo.CurrentDataRespVO;
import com.inspur.module.data.service.IDataQueryService;
import com.inspur.module.system.controller.admin.alarm.vo.AlarmDataPageReqVO;
import com.inspur.module.system.controller.admin.alarm.vo.AlarmDataRespVO;
import com.inspur.module.system.dal.dataobject.alarm.AlarmDataDO;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
@ -9,10 +17,15 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.text.ParseException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static com.inspur.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
import static com.inspur.framework.common.pojo.CommonResult.success;
/**
@ -30,10 +43,10 @@ public class DataQueryController {
@GetMapping("/list")
@Operation(summary = "获取/查询网关数据列表")
@PreAuthorize("@ss.hasPermission('data:query:list')")
public CommonResult<Map<String, Object>> getData(String equipId, String startTime, String endTime, Integer pageSize, Integer pageNum){
public CommonResult<Map<String, Object>> getData(String equipId,String tableName, String startTime, String endTime, Integer pageSize, Integer pageNum){
Map<String,Object> resMap = new HashMap<>();
try {
resMap = dataQueryService.selectDataListByPages(equipId,startTime,endTime,pageSize,pageNum);
resMap = dataQueryService.selectDataListByPages(equipId,tableName,startTime,endTime,pageSize,pageNum);
} catch (ParseException e) {
e.printStackTrace();
return CommonResult.error(800,"时间格式错误");
@ -41,4 +54,16 @@ public class DataQueryController {
return success(resMap);
}
@GetMapping("/export-current-excel")
@Operation(summary = "导出机床电流传感器参数 Excel")
@PreAuthorize("@ss.hasPermission('data:query:export')")
@ApiAccessLog(operateType = EXPORT)
public void exportCurrentDataExcel(String equipId,String tableName, String startTime, String endTime,
HttpServletResponse response) throws IOException, ParseException {
List<CurrentDataRespVO> list = (List<CurrentDataRespVO>)dataQueryService.selectDataListByPages(equipId,tableName,startTime,endTime,null,null).get("list");
// 导出 Excel
ExcelUtils.write(response, "机床电流参数报警记录.xls", "电流数据", CurrentDataRespVO.class,
BeanUtils.toBean(list, CurrentDataRespVO.class));
}
}

View File

@ -0,0 +1,23 @@
package com.inspur.module.data.controller.admin.query.vo;
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.Data;
/**
* 电流传感器数据返回对象
* @Author zhangjunwen
* @create 2024/9/5
*/
@Data
public class CurrentDataRespVO {
@ExcelProperty("时间")
private String time;
@ExcelProperty("x轴推屑电流")
private String x_push_temp;
@ExcelProperty("y轴推屑电流")
private String y_push_temp;
}

View File

@ -24,32 +24,53 @@ public class DataQueryService implements IDataQueryService{
private InfluxDBService influxDBService;
@Override
public Map<String, Object> selectDataListByPages(String equipId,String startTime,String endTime, Integer pageSize, Integer pageNum) throws ParseException {
public Map<String, Object> selectDataListByPages(String equipId,String tableName,String startTime,String endTime, Integer pageSize, Integer pageNum){
Map<String, Object> resMap = new HashMap<>();
//TODO 分页查找条数根据设备id表名时间范围页码每页条数
List<Map<String, Object>> dataList = queryDataByTime("data", equipId, startTime, endTime, pageNum, pageSize);
List<Map<String, Object>> dataList = queryDataByTime(tableName, null, startTime, endTime, pageNum, pageSize);
dataList.forEach(map -> {
try {
map.put("time", DateUtils.tranUTC2LocalDateTime(map.get("time").toString()));
} catch (ParseException e) {
throw new RuntimeException(e);
}
});
//TODO 时间需要将查询到的UTC时间转为系统时间北京时间
DateUtils.tranUTC2LocalDateTime("2024-08-28T08:00:00Z");
// DateUtils.tranUTC2LocalDateTime("2024-08-28T08:00:00Z");
//TODO 查询数据总条数
long total = countDataList("data", "value", equipId, startTime, endTime);
resMap.put("data", dataList);
long total = countDataList(tableName, "x_push_temp", null, startTime, endTime);
resMap.put("list", dataList);
resMap.put("total", total);
return resMap;
}
private List<Map<String, Object>> queryDataByTime(String tableName, String equipId, String beginTime, String endTime, Integer pageNum, Integer pageSize) {
StringBuilder sql = new StringBuilder("select * from ")
.append("\"").append(tableName).append("\"")
.append(" where equip_id = '").append(equipId).append("'");
.append("\"").append(tableName).append("\"");
if(equipId != null){
sql.append(" where equip_id = '").append(equipId).append("'");
}
if(beginTime != null){
sql.append(" and time >= '").append(beginTime).append("'");
if(!sql.toString().contains("where")){
sql.append(" where");
}else{
sql.append(" and");
}
sql.append(" time >= '").append(beginTime).append("'");
}
if(endTime != null){
sql.append(" and time <= '").append(endTime).append("'");
if(!sql.toString().contains("where")){
sql.append(" where");
}else{
sql.append(" and");
}
sql.append(" time <= '").append(endTime).append("'");
}
if(pageNum != null || pageSize != null) {
sql.append(" order by time desc ")
.append(" limit ").append(pageSize)
.append(" offset ").append((pageNum - 1) * pageSize);
}
sql.append(" order by time desc ")
.append(" limit ").append(pageSize)
.append(" offset ").append((pageNum - 1) * pageSize);
// .append(" tz('Asia/Shanghai')");
return influxDBService.queryResultProcess(influxDBService.query(sql.toString()));
@ -57,13 +78,25 @@ public class DataQueryService implements IDataQueryService{
private long countDataList(String tableName,String field, String equipId, String beginTime, String endTime){
StringBuilder sql = new StringBuilder("select count(").append(field).append(") from ")
.append("\"").append(tableName).append("\"")
.append(" where equip_id = '").append(equipId).append("'");
.append("\"").append(tableName).append("\"");
if(equipId != null){
sql.append(" where equip_id = '").append(equipId).append("'");
}
if(beginTime != null){
sql.append(" and time >= '").append(beginTime).append("'");
if(!sql.toString().contains("where")){
sql.append(" where");
}else{
sql.append(" and");
}
sql.append(" time >= '").append(beginTime).append("'");
}
if(endTime != null){
sql.append(" and time <= '").append(endTime).append("'");
if(!sql.toString().contains("where")){
sql.append(" where");
}else{
sql.append(" and");
}
sql.append(" time <= '").append(endTime).append("'");
}
return influxDBService.countResultProcess(influxDBService.query(sql.toString()));
}

View File

@ -15,6 +15,6 @@ public interface IDataQueryService {
* @param pageSize 每页大小
* @param pageNum 当前页码
*/
Map<String, Object> selectDataListByPages(String equipId,String startTime,String endTime,Integer pageSize,Integer pageNum) throws ParseException;
Map<String, Object> selectDataListByPages(String equipId,String tableName,String startTime,String endTime,Integer pageSize,Integer pageNum) throws ParseException;
}

View File

@ -0,0 +1,20 @@
import request from "@/utils/request";
// 根据时间查询超压底缸数据
export function getDataList(params) {
return request({
url: "/data/query/list",
method: "get",
params: params,
});
}
// 导出机床电流参数报警记录 Excel
export function exportCurrentDataExcel(params) {
return request({
url: "/data/query/export-current-excel",
method: "get",
params,
responseType: "blob",
});
}

File diff suppressed because it is too large Load Diff