diff --git a/das/src/main/java/com/das/modules/data/service/TDEngineService.java b/das/src/main/java/com/das/modules/data/service/TDEngineService.java index 184ed25a..625ab571 100644 --- a/das/src/main/java/com/das/modules/data/service/TDEngineService.java +++ b/das/src/main/java/com/das/modules/data/service/TDEngineService.java @@ -67,6 +67,9 @@ public class TDEngineService { } } + public HikariDataSource getHikariDataSource(){ + return hikariDataSource; + } /** * 创建超级表 */ diff --git a/das/src/main/java/com/das/modules/data/service/impl/DataServiceImpl.java b/das/src/main/java/com/das/modules/data/service/impl/DataServiceImpl.java index e88d9d07..e0220cf7 100644 --- a/das/src/main/java/com/das/modules/data/service/impl/DataServiceImpl.java +++ b/das/src/main/java/com/das/modules/data/service/impl/DataServiceImpl.java @@ -25,6 +25,7 @@ import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; import org.springframework.util.StopWatch; +import java.text.SimpleDateFormat; import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.function.Function; @@ -85,7 +86,6 @@ public class DataServiceImpl implements DataService { */ @Override public Map> querySnapshotValues(List paramList) { - long start = System.currentTimeMillis(); Map> result = new HashMap<>(paramList.size()); ListUtil.page(paramList, COMMIT_COUNT, list -> { List keyList = new ArrayList<>(); @@ -122,8 +122,6 @@ public class DataServiceImpl implements DataService { } } }); - long end = System.currentTimeMillis(); - log.debug("querySnapshotValues {}个,耗时: {}秒", paramList.size(), (end - start) / 1000.0); return result; } diff --git a/das/src/main/java/com/das/modules/data/service/impl/ExportTdDataServiceImpl.java b/das/src/main/java/com/das/modules/data/service/impl/ExportTdDataServiceImpl.java new file mode 100644 index 00000000..a9d9754b --- /dev/null +++ b/das/src/main/java/com/das/modules/data/service/impl/ExportTdDataServiceImpl.java @@ -0,0 +1,122 @@ +package com.das.modules.data.service.impl; + +import cn.hutool.core.io.FileUtil; +import cn.hutool.core.util.ZipUtil; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.das.modules.data.service.TDEngineService; +import com.das.modules.equipment.entity.SysEquipment; +import com.das.modules.equipment.mapper.SysEquipmentMapper; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; +import org.springframework.util.StopWatch; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.nio.file.Files; +import java.sql.*; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.List; +import java.util.concurrent.TimeUnit; + +@Slf4j +@Service +public class ExportTdDataServiceImpl { + + @Autowired + SysEquipmentMapper sysEquipmentMapper; + + @Autowired + private TDEngineService tdEngineService; + + @Value("${zipUrl}") + private String fileUrl; + + + public void exportDataCsvZip() throws IOException, SQLException { + StopWatch stopWatch = new StopWatch(); + stopWatch.start("导出风机数据zip"); + Calendar calendar = Calendar.getInstance(); + calendar.add(Calendar.DAY_OF_MONTH, -1); + String yesterday = new SimpleDateFormat("yyyy-MM-dd").format(calendar.getTime()); + + //获取所有风机数据 + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("object_type", 10002); + List sysEquipments = sysEquipmentMapper.selectList(queryWrapper); + //获取临时目录文件路径 + String tempDir = String.valueOf(Files.createTempDirectory(null)); + File zipFile = new File(fileUrl + "/data_"+yesterday+".zip"); + List fileList = new ArrayList<>(); + try { + for (SysEquipment item : sysEquipments) { + + String hTableName = "h" + item.getId(); + String lTableName = "l" + item.getId(); + File fileHighSpeed = new File(tempDir +"/" + "h_"+item.getCode()+"_"+yesterday + ".csv"); + File fileLowSpeed = new File(tempDir +"/" + "l_"+item.getCode()+"_"+yesterday + ".csv"); + getYesterdayData(hTableName, yesterday, fileHighSpeed.getPath()); + getYesterdayData(lTableName, yesterday, fileLowSpeed.getPath()); + fileList.add(fileLowSpeed); + fileList.add(fileHighSpeed); + } + //压缩文件 + // 将文件添加到压缩文件中 + ZipUtil.zip(zipFile, false, fileList.toArray(new File[0])); + stopWatch.stop(); + log.debug(stopWatch.prettyPrint(TimeUnit.SECONDS)); + }catch (Exception e){ + log.error("导出风机数据zip失败{}",e); + } + finally { + if (!CollectionUtils.isEmpty(fileList)){ + FileUtil.del(new File(fileList.get(0).getParent())); + } + } + + } + + public void getYesterdayData(String tableName, String time, String csvFilePath) { + // TDengine 查询语句 + String query = "SELECT * FROM " + tableName + " WHERE updatetime >= '" + time + " 00:00:00' AND updatetime < '" + time + " 23:59:59.999'"; + try (Connection conn = tdEngineService.getHikariDataSource().getConnection(); + Statement smt = conn.createStatement(); + ResultSet rs = smt.executeQuery(query)) { + writeResultSetToCsv(rs, csvFilePath); + }catch (Exception e){ + log.error(tableName +"获取数据异常{}",e); + } + + } + + private void writeResultSetToCsv(ResultSet resultSet, String csvFilePath) throws IOException, SQLException { + try (BufferedWriter writer = new BufferedWriter(new FileWriter(csvFilePath))) { + // 写入列名 + ResultSetMetaData metaData = resultSet.getMetaData(); + int columnCount = metaData.getColumnCount(); + for (int i = 1; i <= columnCount; i++) { + writer.write(metaData.getColumnName(i)); + if (i < columnCount) writer.write(","); + } + writer.newLine(); + + // 写入数据 + while (resultSet.next()) { + for (int i = 1; i <= columnCount; i++) { + String value = resultSet.getString(i); + writer.write(value == null ? "" : resultSet.getString(i)); + if (i < columnCount) writer.write(","); + } + writer.newLine(); + } + }catch (Exception e){ + log.error("数据写入csv文件失败{}",e); + } + } +} diff --git a/das/src/main/java/com/das/modules/node/service/impl/SysNodeServiceImpl.java b/das/src/main/java/com/das/modules/node/service/impl/SysNodeServiceImpl.java index 21a25e32..02f1743b 100644 --- a/das/src/main/java/com/das/modules/node/service/impl/SysNodeServiceImpl.java +++ b/das/src/main/java/com/das/modules/node/service/impl/SysNodeServiceImpl.java @@ -32,6 +32,7 @@ import com.das.modules.node.mapper.SysCommunicationLinkMapper; import com.das.modules.node.mapper.SysImpTabMappingMapper; import com.das.modules.node.mapper.SysNodeMapper; import com.das.modules.node.service.SysNodeService; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import jakarta.servlet.http.HttpServletRequest; @@ -407,22 +408,21 @@ public class SysNodeServiceImpl implements SysNodeService { */ @Override public void saveMappingList(List impList) { + if (impList.get(0).getProtocol() == 9 || impList.get(0).getProtocol() == 17){ + Map collect = sysImptabmappingMapper.getMappingInfoListByLinkId(impList.get(0).getLinkId()).stream().collect(Collectors.toMap(SysTabMappingVo::getId, SysTabMappingVo::getMeasPointType, (value1, value2) -> value1)); + List analogList = impList.stream().filter(item -> collect.get(item.getId()) == 138).collect(Collectors.toList()); + List accumulator = impList.stream().filter(item -> collect.get(item.getId()) == 139).collect(Collectors.toList()); + List discrete = impList.stream().filter(item -> collect.get(item.getId()) == 140).collect(Collectors.toList()); + List setPoint = impList.stream().filter(item -> collect.get(item.getId()) == 146).collect(Collectors.toList()); + List control = impList.stream().filter(item -> collect.get(item.getId()) == 147).collect(Collectors.toList()); + //校验param里面order不重复 + if (checkOrderRepeated(analogList) || checkOrderRepeated(accumulator) || checkOrderRepeated(discrete) || checkOrderRepeated(setPoint) || checkOrderRepeated(control)){ + throw new ServiceException("检查顺序,排序不能重复"); + } + } try { if (!CollectionUtils.isEmpty(impList)) { List list = new ArrayList<>(); - - if (impList.get(0).getProtocol() == 9 || impList.get(0).getProtocol() == 17){ - Map collect = sysImptabmappingMapper.getMappingInfoListByLinkId(impList.get(0).getLinkId()).stream().collect(Collectors.toMap(SysTabMappingVo::getId, SysTabMappingVo::getMeasPointType, (value1, value2) -> value1)); - List analogList = impList.stream().filter(item -> collect.get(item.getId()) == 138).collect(Collectors.toList()); - List accumulator = impList.stream().filter(item -> collect.get(item.getId()) == 139).collect(Collectors.toList()); - List discrete = impList.stream().filter(item -> collect.get(item.getId()) == 140).collect(Collectors.toList()); - List setPoint = impList.stream().filter(item -> collect.get(item.getId()) == 146).collect(Collectors.toList()); - List control = impList.stream().filter(item -> collect.get(item.getId()) == 147).collect(Collectors.toList()); - //校验param里面order不重复 - if (checkOrderRepeated(analogList) || checkOrderRepeated(accumulator) || checkOrderRepeated(discrete) || checkOrderRepeated(setPoint) || checkOrderRepeated(control)){ - throw new ServiceException("检查顺序,排序不能重复"); - } - } SysUserVo sysUserVo = (SysUserVo) StpUtil.getTokenSession().get(SessionUtil.SESSION_USER_KEY); for (SysTabMappingVo imp : impList) { SysTabMapping rec = sysImptabmappingMapper.selectById(imp.getId()); @@ -540,12 +540,19 @@ public class SysNodeServiceImpl implements SysNodeService { private Boolean checkOrderRepeated(List mappings) { ObjectMapper objectMapper = new ObjectMapper(); - + List orderCollect = mappings.stream().filter(item -> { + try { + JsonNode jsonNode = objectMapper.readTree(item.getParams()); + return StringUtils.isNotEmpty(jsonNode.get("order").asText()); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + }).collect(Collectors.toList()); Boolean orderRepeated = false; try { // 提取所有的 order 字段,转换为 Set Set orderSet = new HashSet<>(); - orderRepeated = mappings.stream() + orderRepeated = orderCollect.stream() .map(SysTabMappingVo::getParams) // 提取 param 字段 .map(param -> { try { @@ -556,7 +563,16 @@ public class SysNodeServiceImpl implements SysNodeService { throw new RuntimeException("JSON 解析失败: " + param, e); } }) - .anyMatch(order -> !orderSet.add(order)); + .anyMatch(order -> { + if (StringUtils.isNotEmpty(order)){ + boolean b = !orderSet.add(order); + if (b){ + log.error("排序重复{}",order); + } + return b; + } + return false; + }); }catch (Exception e){ log.error("校验order不重复失败",e); } diff --git a/das/src/main/java/com/das/modules/page/controller/HomeParamSetController.java b/das/src/main/java/com/das/modules/page/controller/HomeParamSetController.java index 05e0c63a..97fa5f16 100644 --- a/das/src/main/java/com/das/modules/page/controller/HomeParamSetController.java +++ b/das/src/main/java/com/das/modules/page/controller/HomeParamSetController.java @@ -6,6 +6,7 @@ import com.das.modules.page.domian.dto.SysHomeParamSetDto; import com.das.modules.page.domian.vo.SysHomeParamSetVo; import com.das.modules.page.service.HomeParamSetService; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -29,6 +30,9 @@ public class HomeParamSetController { /** 新增系统参数设置页面 */ @PostMapping("/add") public R add(@RequestBody SysHomeParamSetDto sysHomeParamSetDto) { + if (StringUtils.isBlank(sysHomeParamSetDto.getParamType())) { + throw new ServiceException("参数类型不能为空"); + } SysHomeParamSetVo sysHomeParamSetVo = homeParamSetService.add(sysHomeParamSetDto); return R.success(sysHomeParamSetVo); } @@ -50,4 +54,14 @@ public class HomeParamSetController { SysHomeParamSetVo sysHomeParamSetVo = homeParamSetService.update(sysHomeParamSetDto); return R.success(sysHomeParamSetVo); } + + /** 删除系统参数设置 */ + @PostMapping("/delete") + public R delete(@RequestBody SysHomeParamSetDto sysHomeParamSetDto) { + if (sysHomeParamSetDto.getId() == null) { + throw new ServiceException("id不能为空"); + } + homeParamSetService.delete(sysHomeParamSetDto); + return R.success(); + } } diff --git a/das/src/main/java/com/das/modules/page/domian/dto/SysHomeParamSetDto.java b/das/src/main/java/com/das/modules/page/domian/dto/SysHomeParamSetDto.java index 4d25bc16..34bf57ec 100644 --- a/das/src/main/java/com/das/modules/page/domian/dto/SysHomeParamSetDto.java +++ b/das/src/main/java/com/das/modules/page/domian/dto/SysHomeParamSetDto.java @@ -6,7 +6,7 @@ import lombok.Data; @Data public class SysHomeParamSetDto { - private Long id; + private String id; private String paramName; @@ -15,4 +15,6 @@ public class SysHomeParamSetDto { private JSONArray paramValueJson; private String paramDesc; + + private String paramType; } diff --git a/das/src/main/java/com/das/modules/page/domian/vo/SysHomeParamSetVo.java b/das/src/main/java/com/das/modules/page/domian/vo/SysHomeParamSetVo.java index 98e42c03..9ca99150 100644 --- a/das/src/main/java/com/das/modules/page/domian/vo/SysHomeParamSetVo.java +++ b/das/src/main/java/com/das/modules/page/domian/vo/SysHomeParamSetVo.java @@ -6,7 +6,7 @@ import lombok.Data; @Data public class SysHomeParamSetVo { - private Long id; + private String id; private String paramName; @@ -15,4 +15,6 @@ public class SysHomeParamSetVo { private JSONArray paramValueJson; private String paramDesc; + + private String paramType; } diff --git a/das/src/main/java/com/das/modules/page/entity/SysHomeParamSet.java b/das/src/main/java/com/das/modules/page/entity/SysHomeParamSet.java index c2e74643..f22dc688 100644 --- a/das/src/main/java/com/das/modules/page/entity/SysHomeParamSet.java +++ b/das/src/main/java/com/das/modules/page/entity/SysHomeParamSet.java @@ -29,4 +29,6 @@ public class SysHomeParamSet extends BaseEntity { private String paramValue; private String paramDesc; + + private String paramType; } diff --git a/das/src/main/java/com/das/modules/page/service/HomeParamSetService.java b/das/src/main/java/com/das/modules/page/service/HomeParamSetService.java index f3a023a5..8f29981b 100644 --- a/das/src/main/java/com/das/modules/page/service/HomeParamSetService.java +++ b/das/src/main/java/com/das/modules/page/service/HomeParamSetService.java @@ -12,4 +12,6 @@ public interface HomeParamSetService { List getList(SysHomeParamSetDto sysHomeParamSetDto); SysHomeParamSetVo update(SysHomeParamSetDto sysHomeParamSetDto); + + void delete(SysHomeParamSetDto sysHomeParamSetDto); } diff --git a/das/src/main/java/com/das/modules/page/service/impl/HomeParamSetServiceImpl.java b/das/src/main/java/com/das/modules/page/service/impl/HomeParamSetServiceImpl.java index 19aa6384..f55d7c19 100644 --- a/das/src/main/java/com/das/modules/page/service/impl/HomeParamSetServiceImpl.java +++ b/das/src/main/java/com/das/modules/page/service/impl/HomeParamSetServiceImpl.java @@ -61,9 +61,15 @@ public class HomeParamSetServiceImpl implements HomeParamSetService { if (sysHomeParamSetDto.getParamValueJson() !=null){ sysHomeParamSet.setParamValue(sysHomeParamSetDto.getParamValueJson().toString()); } + sysHomeParamSet.setId(Long.valueOf(sysHomeParamSetDto.getId())); sysHomeParamSetMapper.updateById(sysHomeParamSet); SysHomeParamSetVo sysHomeParamSetVo = new SysHomeParamSetVo(); SysHomeParamSetVo result = BeanCopyUtils.copy(sysHomeParamSet, sysHomeParamSetVo); return result; } + + @Override + public void delete(SysHomeParamSetDto sysHomeParamSetDto) { + sysHomeParamSetMapper.deleteById(Long.valueOf(sysHomeParamSetDto.getId())); + } } diff --git a/das/src/main/resources/application-dev.yml b/das/src/main/resources/application-dev.yml index bb481740..1c1a88fb 100644 --- a/das/src/main/resources/application-dev.yml +++ b/das/src/main/resources/application-dev.yml @@ -110,4 +110,6 @@ minio: url: http://192.168.109.187:9000 bucket: das accessKey: das - secretKey: zaq12WSX \ No newline at end of file + secretKey: zaq12WSX + +zipUrl: /log/zip/ \ No newline at end of file diff --git a/das/src/main/resources/application.yml b/das/src/main/resources/application.yml index cdd4455a..4dcd6bb7 100644 --- a/das/src/main/resources/application.yml +++ b/das/src/main/resources/application.yml @@ -113,4 +113,6 @@ minio: bucket: das publicBucket: das-dock accessKey: das - secretKey: zaq12WSX \ No newline at end of file + secretKey: zaq12WSX + +zipUrl: /log/zip/ \ No newline at end of file diff --git a/das/src/main/resources/mapper/SysIotModelFieldMapper.xml b/das/src/main/resources/mapper/SysIotModelFieldMapper.xml index ce265982..f3d487b1 100644 --- a/das/src/main/resources/mapper/SysIotModelFieldMapper.xml +++ b/das/src/main/resources/mapper/SysIotModelFieldMapper.xml @@ -19,6 +19,9 @@ and t.iot_model_id = #{info.iotModelId} + + and t.highSpeed = #{info.highSpeed} + and t.attribute_name like concat('%',#{info.attributeName},'%') diff --git a/ui/dasadmin/src/api/backend/SystemParam/request.ts b/ui/dasadmin/src/api/backend/SystemParam/request.ts index cfb96f26..27441b84 100644 --- a/ui/dasadmin/src/api/backend/SystemParam/request.ts +++ b/ui/dasadmin/src/api/backend/SystemParam/request.ts @@ -15,4 +15,18 @@ export function Paramupdate(params: object = {}) { data: params, }) } +export function ParamAdd(params: object = {}) { + return createAxios({ + url: '/api/page/home/set/add', + method: 'POST', + data: params, + }) +} +export function Paramdelete(params: object = {}) { + return createAxios({ + url: '/api/page/home/set/delete ', + method: 'POST', + data: params, + }) +} diff --git a/ui/dasadmin/src/api/backend/historyData/request.ts b/ui/dasadmin/src/api/backend/historyData/request.ts new file mode 100644 index 00000000..1411e4b3 --- /dev/null +++ b/ui/dasadmin/src/api/backend/historyData/request.ts @@ -0,0 +1,57 @@ +import createAxios from '/@/utils/axios' + +export const getTemplateListReq = (data: { category: '历史数据' & string; pageNum: number; pageSize: number }) => { + return createAxios< + never, + Promise<{ + code: number + msg: string + data: { + total: number + rows: { id: string; category: '历史数据' & string; template: string }[] + code: number + msg: string + } + success: boolean + }> + >({ + url: '/api/page/report/template/getList', + method: 'post', + data, + }) +} + +export const addTemplateListReq = (data: { category: '历史数据' & string; template: string }) => { + return createAxios< + never, + Promise<{ + code: number + msg: string + data: { + id: string + category: '历史数据' & string + template: string + }[] + success: boolean + }> + >({ + url: '/api/page/report/template/add', + method: 'post', + data, + }) +} + +export const delTemplateListReq = (data: { id: string }) => { + return createAxios< + never, + Promise<{ + code: number + msg: string + success: boolean + }> + >({ + url: '/api/page/report/template/del', + method: 'post', + data, + }) +} \ No newline at end of file diff --git a/ui/dasadmin/src/views/backend/SystemParam/index.vue b/ui/dasadmin/src/views/backend/SystemParam/index.vue index f8c1caac..b8499568 100644 --- a/ui/dasadmin/src/views/backend/SystemParam/index.vue +++ b/ui/dasadmin/src/views/backend/SystemParam/index.vue @@ -2,7 +2,8 @@
- 风机矩阵设置 + 系统参数设置 + 新增
@@ -11,7 +12,7 @@ - + @@ -202,13 +206,61 @@
+ + + + + + + + + + + + + + + + + + + + + 确定是否删除? + + + + diff --git a/ui/dasadmin/src/views/backend/historyData/type.ts b/ui/dasadmin/src/views/backend/historyData/type.ts new file mode 100644 index 00000000..4c1a7598 --- /dev/null +++ b/ui/dasadmin/src/views/backend/historyData/type.ts @@ -0,0 +1,10 @@ +export type selectData = + { + id: string + attributeName: string + attributeCode: string + interpolation: boolean + average: boolean + max: boolean + min: boolean + } diff --git a/ui/dasadmin/src/views/backend/home/windMatrixpage.vue b/ui/dasadmin/src/views/backend/home/windMatrixpage.vue index a85782df..2738c424 100644 --- a/ui/dasadmin/src/views/backend/home/windMatrixpage.vue +++ b/ui/dasadmin/src/views/backend/home/windMatrixpage.vue @@ -148,7 +148,7 @@ const props = defineProps({ const getAnimationStyle = (item) => { const irotorspeed = item.attributeMap?.irotorspeed ?? 0 let animationDuration; - animationDuration = 60 / irotorspeed / 3 + animationDuration = 60 / irotorspeed / 2 const processedoperationmode = item.attributeMap?.processedoperationmode ?? 0 if(processedoperationmode==33||processedoperationmode==0){ return {