From 9d7e020fb49c52068aba885fd84836490f7e31d5 Mon Sep 17 00:00:00 2001 From: 潘志宝 <979469083@qq.com> Date: 星期二, 20 八月 2024 11:36:31 +0800 Subject: [PATCH] data --- iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcua/dto/ChannelOPCUADeviceDTO.java | 53 - iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/point/DataPointApi.java | 48 + iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/service/impl/ChannelOPCDATagServiceImpl.java | 187 +++++ iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/ind/IndItemApi.java | 28 iailab-module-data/iailab-module-data-biz/pom.xml | 80 - iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/ind/dto/ApiIndItemValueDTO.java | 22 iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/point/dto/ApiPointsValueQueryDTO.java | 36 + iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/http/dao/HttpApiDao.java | 1 iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/ind/dto/ApiIndItemQueryDTO.java | 35 + iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/controller/ChannelOPCDADeviceController.java | 86 ++ iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/job/init/JobCommandLineRunner.java | 16 iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/point/dto/ApiPointDTO.java | 4 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/http/service/HttpTagService.java | 4 iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/point/dto/ApiPointValueQueryDTO.java | 37 + iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/dto/WriteDTO.java | 15 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/MeasureHandle.java | 61 - iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/dao/ChannelOPCDATagDao.java | 14 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/service/ChannelOPCDATagService.java | 70 ++ iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/collector/OpcDACollector.java | 115 +++ iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/service/impl/ChannelOPCDADeviceServiceImpl.java | 115 +++ iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/dao/ChannelOPCDADeviceDao.java | 16 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/http/service/impl/HttpTagServiceImpl.java | 216 ------ iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/entity/ChannelOPCDATagEntity.java | 62 + iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/point/dto/ApiPointValueDTO.java | 20 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/controller/ChannelOPCDATagController.java | 102 +++ iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/collector/OpcDAUtils.java | 115 +++ iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/dto/ChannelOPCDADeviceDTO.java | 46 + iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcua/entity/ChannelOPCUATagEntity.java | 2 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/dto/ChannelOPCDATagDTO.java | 43 + /dev/null | 40 - iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/entity/ChannelOPCDADeviceEntity.java | 67 ++ iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/service/ChannelOPCDADeviceService.java | 60 + iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/point/dto/ApiPointValueWriteDTO.java | 8 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/controller/DataController.java | 42 - 34 files changed, 1,405 insertions(+), 461 deletions(-) diff --git a/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/IFeignDataApi.java b/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/IFeignDataApi.java deleted file mode 100644 index b109cf3..0000000 --- a/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/IFeignDataApi.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.iailab.module.data.api; - -import com.iailab.module.data.dto.*; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.Parameter; -import org.springframework.cloud.openfeign.FeignClient; -import org.springframework.web.bind.annotation.*; - -import java.util.List; -import java.util.Map; - -/** - * @author DongYukun - * @Description - * @createTime 2024年03月01日 18:37:00 - */ -@FeignClient(value = "iailab-ntt-data", path = "/") -public interface IFeignDataApi { - @Parameter(name = "map", description = "查询InfluxDB", required = true) - @Operation(summary = "Feign接口-查询PointValue") - @PostMapping("/api/feign/influx-point-value") - List<ApiDataDTO> queryPointValues(@RequestBody FeignQueryPointDTO dto); - - @Parameter(name = "map", description = "查询InfluxDB", required = true) - @Operation(summary = "Feign接口-查询PointValue") - @PostMapping("/api/feign/sim-tag-value") - List<ApiDataDTO> querySimTagValues(@RequestBody FeignQueryPointDTO dto); - - @Parameter(name = "map", description = "查询InfluxDB", required = true) - @Operation(summary = "Feign接口-查询PointValue") - @PostMapping("/api/feign/currentValue") - Map<String, Object> getCurrentValue(@RequestParam("pointNos") List<String> pointNos); - - @Parameter(name = "map", description = "查询point", required = true) - @Operation(summary = "Feign接口-查询point") - @PostMapping("/api/feign/point/{pointNo}") - ApiDataPointDTO getPoint(@PathVariable("pointNo") String pointNo); - - @Parameter(name = "map", description = "查询HttpApi", required = true) - @Operation(summary = "Feign接口-查询HttpApi") - @GetMapping("/api/feign/http-api/{code}") - FeignHttpApiDTO getHttpApi(@PathVariable("code") String code); - - @Parameter(name = "map", description = "查询指标数据", required = true) - @Operation(summary = "Feign接口-查询指标数据") - @PostMapping("/api/feign/ind-item-values") - List<ApiDataDTO> queryIndItemValues(@RequestBody FeignQueryPointDTO dto); - - @Parameter(name = "map", description = "查询指标数据", required = true) - @Operation(summary = "Feign接口-查询指标数据") - @PostMapping("/api/feign/ind-item-values-range") - List<ApiIndValueDTO> queryIndItemValuesRange(@RequestBody FeignQueryPointDTO dto); - - @Parameter(name = "map", description = "设置测点值", required = true) - @Operation(summary = "Feign接口-设置测点值") - @PostMapping("/api/feign/set-point-value") - FeignResultDTO setPointValue(@RequestBody FeignWritePointValueDTO writePointValue); - - @Parameter(name = "map", description = "查询指标数据", required = true) - @Operation(summary = "Feign接口-查询指标数据") - @PostMapping("/api/feign/get-inditem-values") - List<ApiIndValueDTO> getIndItemValues(@RequestBody FeignQueryPointDTO dto); -} diff --git a/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/ind/IndItemApi.java b/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/ind/IndItemApi.java new file mode 100644 index 0000000..b14eba7 --- /dev/null +++ b/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/ind/IndItemApi.java @@ -0,0 +1,28 @@ +package com.iailab.module.data.api.ind; + +import com.iailab.module.data.api.ind.dto.ApiIndItemQueryDTO; +import com.iailab.module.data.api.ind.dto.ApiIndItemValueDTO; +import com.iailab.module.data.enums.ApiConstants; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; + +import java.util.List; + +/** + * @author PanZhibao + * @Description + * @createTime 2024年08月19日 + */ +@FeignClient(name = ApiConstants.NAME) +@Tag(name = "指标项服务") +public interface IndItemApi { + + String PREFIX = ApiConstants.PREFIX + "/ind-item"; + + @PostMapping(PREFIX + "/vlues") + @Operation(summary = "查询指标项") + List<ApiIndItemValueDTO> queryIndItemValues(@RequestBody ApiIndItemQueryDTO dto); +} \ No newline at end of file diff --git a/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/ind/dto/ApiIndItemQueryDTO.java b/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/ind/dto/ApiIndItemQueryDTO.java new file mode 100644 index 0000000..9259108 --- /dev/null +++ b/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/ind/dto/ApiIndItemQueryDTO.java @@ -0,0 +1,35 @@ +package com.iailab.module.data.api.ind.dto; + +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.Data; + +import javax.validation.constraints.NotNull; +import java.io.Serializable; +import java.util.Date; + +/** + * @author PanZhibao + * @Description + * @createTime 2024年08月19日 + */ +@Data +@Tag(name = "指标项值查询") +public class ApiIndItemQueryDTO implements Serializable { + private static final long serialVersionUID = 1L; + + @Schema(description = "itemNo") + @NotNull(message="itemNo不能为空") + private String itemNo; + + @Schema(description = "开始时间") + @NotNull(message="start不能为空") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Date start; + + @Schema(description = "结束时间") + @NotNull(message="end不能为空") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Date end; +} \ No newline at end of file diff --git a/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/ind/dto/ApiIndItemValueDTO.java b/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/ind/dto/ApiIndItemValueDTO.java new file mode 100644 index 0000000..b1e54cc --- /dev/null +++ b/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/ind/dto/ApiIndItemValueDTO.java @@ -0,0 +1,22 @@ +package com.iailab.module.data.api.ind.dto; + +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * @author PanZhibao + * @Description + * @createTime 2024年08月19日 + */ +@Data +@Tag(name = "指标项值结果") +public class ApiIndItemValueDTO implements Serializable { + private static final long serialVersionUID = 1L; + + private String dataTime; + + private double dataValue; +} \ No newline at end of file diff --git a/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/point/DataPointApi.java b/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/point/DataPointApi.java new file mode 100644 index 0000000..88f676e --- /dev/null +++ b/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/point/DataPointApi.java @@ -0,0 +1,48 @@ +package com.iailab.module.data.api.point; + +import com.iailab.module.data.api.point.dto.*; +import com.iailab.module.data.enums.ApiConstants; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; + +import java.util.List; +import java.util.Map; + +/** + * @author PanZhibao + * @Description + * @createTime 2024年08月19日 + */ +@FeignClient(name = ApiConstants.NAME) +@Tag(name = "数据测点服务") +public interface DataPointApi { + + String PREFIX = ApiConstants.PREFIX + "/point"; + + @PostMapping(PREFIX + "/point/{pointNo}") + @Operation(summary = "查询测点信息") + ApiPointDTO getPoint(@PathVariable("pointNo") String pointNo); + + @PostMapping(PREFIX + "/current") + @Operation(summary = "查询多个测点当前值") + Map<String, Object> pointsCurrent(@RequestParam("pointNos") List<String> pointNos); + + @PostMapping(PREFIX + "/history") + @Operation(summary = "查询多个测点历史值") + Map<String, List<Map<String, Object>>> pointsHistory(@RequestBody ApiPointsValueQueryDTO queryDto); + + @PostMapping(PREFIX + "/value/get") + @Operation(summary = "查询单个测点历史值") + List<ApiPointValueDTO> getValue(@RequestBody ApiPointValueQueryDTO queryDto); + + @PostMapping(PREFIX + "/value/set") + @Operation(summary = "设置单个测点值") + Boolean setValue(@RequestBody ApiPointValueWriteDTO queryDto); + + +} diff --git a/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/dto/ApiDataPointDTO.java b/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/point/dto/ApiPointDTO.java similarity index 84% rename from iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/dto/ApiDataPointDTO.java rename to iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/point/dto/ApiPointDTO.java index 4e075e7..24972b3 100644 --- a/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/dto/ApiDataPointDTO.java +++ b/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/point/dto/ApiPointDTO.java @@ -1,4 +1,4 @@ -package com.iailab.module.data.dto; +package com.iailab.module.data.api.point.dto; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; @@ -12,7 +12,7 @@ */ @Data @Schema(description = "测点") -public class ApiDataPointDTO implements Serializable { +public class ApiPointDTO implements Serializable { private static final long serialVersionUID = 1L; @Schema(description = "测点编码", required = true) diff --git a/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/point/dto/ApiPointValueDTO.java b/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/point/dto/ApiPointValueDTO.java new file mode 100644 index 0000000..24398c3 --- /dev/null +++ b/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/point/dto/ApiPointValueDTO.java @@ -0,0 +1,20 @@ +package com.iailab.module.data.api.point.dto; + +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * @author PanZhibao + * @Description + * @createTime 2024年08月19日 + */ +@Data +public class ApiPointValueDTO implements Serializable { + private static final long serialVersionUID = 1L; + + private Date dataTime; + + private double dataValue; +} \ No newline at end of file diff --git a/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/point/dto/ApiPointValueQueryDTO.java b/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/point/dto/ApiPointValueQueryDTO.java new file mode 100644 index 0000000..ec5e111 --- /dev/null +++ b/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/point/dto/ApiPointValueQueryDTO.java @@ -0,0 +1,37 @@ +package com.iailab.module.data.api.point.dto; + +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.Data; + +import javax.validation.constraints.NotNull; +import java.io.Serializable; +import java.util.Date; +import java.util.List; + +/** + * @author PanZhibao + * @Description + * @createTime 2024年08月19日 + */ +@Data +@Tag(name = "测点值查询") +public class ApiPointValueQueryDTO implements Serializable { + private static final long serialVersionUID = 1L; + + @Schema(description = "pointNos") + @NotNull(message="pointNo不能为空") + private String pointNo; + + @Schema(description = "开始时间") + @NotNull(message="start不能为空") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Date start; + + @Schema(description = "结束时间") + @NotNull(message="end不能为空") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Date end; + +} \ No newline at end of file diff --git a/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/dto/FeignWritePointValueDTO.java b/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/point/dto/ApiPointValueWriteDTO.java similarity index 69% rename from iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/dto/FeignWritePointValueDTO.java rename to iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/point/dto/ApiPointValueWriteDTO.java index b526828..48e19cf 100644 --- a/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/dto/FeignWritePointValueDTO.java +++ b/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/point/dto/ApiPointValueWriteDTO.java @@ -1,4 +1,4 @@ -package com.iailab.module.data.dto; +package com.iailab.module.data.api.point.dto; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; @@ -9,15 +9,15 @@ /** * @author PanZhibao * @Description - * @createTime 2024年06月05日 + * @createTime 2024年08月19日 */ @Data @EqualsAndHashCode(callSuper = false) @Schema(description = "写入测点值") -public class FeignWritePointValueDTO implements Serializable { +public class ApiPointValueWriteDTO implements Serializable { @Schema(description = "测点编号") - private String pointCode; + private String pointNo; @Schema(description = "测点值") private Object pointValue; diff --git a/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/point/dto/ApiPointsValueQueryDTO.java b/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/point/dto/ApiPointsValueQueryDTO.java new file mode 100644 index 0000000..5960057 --- /dev/null +++ b/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/point/dto/ApiPointsValueQueryDTO.java @@ -0,0 +1,36 @@ +package com.iailab.module.data.api.point.dto; + +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.Data; + +import javax.validation.constraints.NotNull; +import java.io.Serializable; +import java.util.Date; +import java.util.List; + +/** + * @author PanZhibao + * @Description + * @createTime 2024年08月19日 + */ +@Data +@Tag(name = "测点值查询") +public class ApiPointsValueQueryDTO implements Serializable { + private static final long serialVersionUID = 1L; + + @Schema(description = "pointNos") + @NotNull(message="pointNos不能为空") + private List<String> pointNos; + + @Schema(description = "开始时间") + @NotNull(message="start不能为空") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Date start; + + @Schema(description = "结束时间") + @NotNull(message="end不能为空") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Date end; +} \ No newline at end of file diff --git a/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/dto/AlarmTaskDto.java b/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/dto/AlarmTaskDto.java deleted file mode 100644 index 305eb15..0000000 --- a/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/dto/AlarmTaskDto.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.iailab.module.data.dto; - -import lombok.Data; - -import java.util.Date; - -/** - * @author Lujiaxin - * @Description - * @createTime 2023年03月09日 10:05:00 - */ - -@Data -public class AlarmTaskDto { - - private String id; - - /** - * 设备编号 - */ - private String equipmentNumber; - - /** - * 设备名称 - */ - private String equipmentName; - - /** - * 报警场所 - */ - private String alarmPlace; - - /** - * 报警内容 - */ - private String alarmContent; - - /** - * 报警时间 - */ - private Date alarmTime; - - /** - * 推送对象 - */ - private String acceptBy; - - /** - * 工单创建方式(自动:auto 手动:manual) - */ - private String orderCreateType; - - /** - * 工单创建状态(未创建:0 已创建:1) - */ - private String orderCreateStatus; - -} diff --git a/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/dto/ApiDataDTO.java b/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/dto/ApiDataDTO.java deleted file mode 100644 index fdcd93c..0000000 --- a/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/dto/ApiDataDTO.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.iailab.module.data.dto; - -import lombok.Data; - -import java.io.Serializable; -import java.util.Date; - -@Data -public class ApiDataDTO implements Serializable { - private static final long serialVersionUID = 1L; - - private Date timeStamp; - - private String dataTime; - - private double dataValue; - -} diff --git a/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/dto/ApiIndValueDTO.java b/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/dto/ApiIndValueDTO.java deleted file mode 100644 index f5ca841..0000000 --- a/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/dto/ApiIndValueDTO.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.iailab.module.data.dto; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -import java.io.Serializable; -import java.math.BigDecimal; - -/** - * @author PanZhibao - * @Description - * @createTime 2024年06月17日 - */ -@Data -public class ApiIndValueDTO implements Serializable { - private static final long serialVersionUID = 1L; - - @Schema(description = "数据时间") - private String dataTime; - - @Schema(description = "数据值") - private BigDecimal dataValue; -} \ No newline at end of file diff --git a/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/dto/ApiPointValueQueryDTO.java b/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/dto/ApiPointValueQueryDTO.java deleted file mode 100644 index afa9d29..0000000 --- a/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/dto/ApiPointValueQueryDTO.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.iailab.module.data.dto; - -import com.fasterxml.jackson.annotation.JsonFormat; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -import javax.validation.constraints.NotNull; -import java.util.Date; -import java.util.List; - -/** - * @author PanZhibao - * @Description - * @createTime 2023年05月05日 16:08:00 - */ -@Data -@Schema(name = "测点值查询") -public class ApiPointValueQueryDTO { - @Schema(name = "pointNos") - @NotNull(message="pointNos不能为空") - private List<String> pointNos; - - @Schema(name = "开始时间") - @NotNull(message="start不能为空") - @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") - private Date start; - - @Schema(name = "结束时间") - @NotNull(message="end不能为空") - @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") - private Date end; -} diff --git a/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/dto/FeignFileQueryDto.java b/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/dto/FeignFileQueryDto.java deleted file mode 100644 index 5298253..0000000 --- a/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/dto/FeignFileQueryDto.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.iailab.module.data.dto; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; - -/** - * @author PanZhibao - * @Description - * @createTime 2023年08月21日 13:50:00 - */ -@Data -@EqualsAndHashCode(callSuper = false) -@Schema(name = "文件") -public class FeignFileQueryDto { - private String businessId; - - private String type; -} diff --git a/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/dto/FeignFileSaveDto.java b/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/dto/FeignFileSaveDto.java deleted file mode 100644 index 41d2cfa..0000000 --- a/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/dto/FeignFileSaveDto.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.iailab.module.data.dto; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; - -import java.util.List; - -/** - * @author PanZhibao - * @Description - * @createTime 2023年08月16日 13:26:00 - */ -@Data -@EqualsAndHashCode(callSuper = false) -@Schema(name = "文件") -public class FeignFileSaveDto { - - private String businessId; - - private String type; - - private List<FileDto> fileList; -} diff --git a/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/dto/FeignFixDetDTO.java b/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/dto/FeignFixDetDTO.java deleted file mode 100644 index abb59f7..0000000 --- a/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/dto/FeignFixDetDTO.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.iailab.module.data.dto; - -/** - * @author PanZhibao - * @Description - * @createTime 2023年12月09日 09:49:00 - */ -public class FeignFixDetDTO { -} diff --git a/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/dto/FeignHttpApiDTO.java b/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/dto/FeignHttpApiDTO.java deleted file mode 100644 index d90de7a..0000000 --- a/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/dto/FeignHttpApiDTO.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.iailab.module.data.dto; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; - -import java.io.Serializable; -import java.util.Date; - -/** - * @author PanZhibao - * @Description - * @createTime 2024年05月26日 - */ -@Data -@EqualsAndHashCode(callSuper = false) -@Schema(description = "http接口") -public class FeignHttpApiDTO implements Serializable { - private static final long serialVersionUID = 1L; - - private String id; - private String name; - private String code; - private String url; - private String method; - private String collectType; - private String param; - private String descp; - private Integer status; - private Date createTime; - private Date updateTime; -} \ No newline at end of file diff --git a/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/dto/FeignOrderTaskDTO.java b/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/dto/FeignOrderTaskDTO.java deleted file mode 100644 index 27dbde4..0000000 --- a/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/dto/FeignOrderTaskDTO.java +++ /dev/null @@ -1,140 +0,0 @@ -package com.iailab.module.data.dto; - -import com.fasterxml.jackson.annotation.JsonFormat; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -import java.util.Date; -import java.util.List; - -/** - * @author Lujiaxin - * @Description - * @createTime 2023年03月09日 10:05:00 - */ - -@Data -public class FeignOrderTaskDTO { - - @Schema(name = "工单编号") - private String orderNumber; - - @Schema(name = "工单类型") - private String orderType; - - @Schema(name = "工单类型名") - private String orderTypeName; - - @Schema(name = "工单来源") - private String orderSource; - - @Schema(name = "优先级") - private Integer priority; - - @Schema(name = "优先级") - private String priorityName; - - @Schema(name = "标题") - private String title; - - @Schema(name = "内容") - private String content; - - @Schema(name = "工单状态") - private String status; - - @Schema(name = "工单状态名称") - private String statusName; - - @Schema(name = "完成期限") - @JsonFormat(pattern = "yyyy-MM-dd HH:mm", timezone = "GMT+8") - private Date deadline; - - @Schema(name = "发布人") - private String publisher; - - @Schema(name = "发布人姓名") - private String publisherName; - - @Schema(name = "发布人部门") - private String publisherDept; - - @Schema(name = "发布时间") - @JsonFormat(pattern = "yyyy-MM-dd HH:mm", timezone = "GMT+8") - private Date publishTime; - - @Schema(name = "审核人") - private String reviewer; - - @Schema(name = "审核人姓名") - private String reviewerName; - - @Schema(name = "审核时间") - private Date reviewTime; - - @Schema(name = "审核结果") - private String reviewResult; - - @Schema(name = "办理人") - private String assigner; - - @Schema(name = "办理人姓名") - private String assignerName; - - @Schema(name = "办理人部门") - private String assignerDept; - - @Schema(name = "指派时间") - private Date assignTime; - - @Schema(name = "开始处理时间") - @JsonFormat(pattern = "yyyy-MM-dd HH:mm", timezone = "GMT+8") - private Date processStartTime; - - @Schema(name = "处理完成时间") - @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") - private Date processCompletedTime; - - @Schema(name = "已耗时(毫秒)") - private Long timeConsuming; - - @Schema(name = "已耗时(HH小时mm分钟)") - private String consuming; - - @Schema(name = "是否超时") - private Integer isTimeout; - - @Schema(name = "是否超时") - private String isTimeoutName; - - @Schema(name = "超时时长(毫秒)") - private Long timeoutLength; - - @Schema(name = "超时时长(HH小时mm分钟)") - private String timeoutHHmm; - - @Schema(name = "创建人") - private String createBy; - - @Schema(name = "创建人姓名") - private String createByName; - - @Schema(name = "抄送人") - private List<String> copyPerson; - - @Schema(name = "检修类型") - private String checkFixType; - - @Schema(name = "反馈内容") - private String backContent; - - @Schema(name = "创建时间") - private Date createDate; - - @Schema(name = "修改人") - private String updateBy; - - @Schema(name = "修改时间") - private Date updateDate; - -} diff --git a/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/dto/FeignQueryPointDTO.java b/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/dto/FeignQueryPointDTO.java deleted file mode 100644 index 7650785..0000000 --- a/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/dto/FeignQueryPointDTO.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.iailab.module.data.dto; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; - -import java.io.Serializable; -import java.util.Date; - -/** - * @author PanZhibao - * @Description - * @createTime 2023年06月28日 09:19:00 - */ -@Data -@EqualsAndHashCode(callSuper = false) -@Schema(description = "运行时长") -public class FeignQueryPointDTO implements Serializable { - - @Schema(description = "测点编号") - private String pointCode; - - @Schema(description = "类型") - private String type; - - @Schema(description = "开始时间") - private Date startTime; - - @Schema(description = "结束时间") - private Date endTime; - - @Schema(description = "开始日期") - private String startDate; - - @Schema(description = "结束日期") - private String endDate; -} diff --git a/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/dto/FeignResultDTO.java b/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/dto/FeignResultDTO.java deleted file mode 100644 index 153dd5f..0000000 --- a/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/dto/FeignResultDTO.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.iailab.module.data.dto; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; - -import java.io.Serializable; - -/** - * @author PanZhibao - * @Description - * @createTime 2024年06月05日 - */ -@Data -@EqualsAndHashCode(callSuper = false) -@Schema(description = "结果") -public class FeignResultDTO implements Serializable { - - private Integer code; - - private String msg; -} \ No newline at end of file diff --git a/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/dto/FileDto.java b/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/dto/FileDto.java deleted file mode 100644 index 4ed6b4d..0000000 --- a/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/dto/FileDto.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.iailab.module.data.dto; - -import lombok.Data; - -/** - * @author PanZhibao - * @Description - * @createTime 2023年03月05日 17:52:00 - */ -@Data -public class FileDto { - - private String uid; - - private String name; - - private String url; -} diff --git a/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/package-info.java b/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/package-info.java deleted file mode 100644 index c343803..0000000 --- a/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/package-info.java +++ /dev/null @@ -1 +0,0 @@ -package com.iailab.module; \ No newline at end of file diff --git a/iailab-module-data/iailab-module-data-biz/pom.xml b/iailab-module-data/iailab-module-data-biz/pom.xml index 0da9f4b..bac12f8 100644 --- a/iailab-module-data/iailab-module-data-biz/pom.xml +++ b/iailab-module-data/iailab-module-data-biz/pom.xml @@ -95,35 +95,38 @@ <artifactId>quartz</artifactId> <version>2.3.2</version> </dependency> -<!-- <dependency>--> -<!-- <groupId>cn.afterturn</groupId>--> -<!-- <artifactId>easypoi-base</artifactId>--> -<!-- <version>${easypoi.version}</version>--> -<!-- </dependency>--> -<!-- <dependency>--> -<!-- <groupId>cn.afterturn</groupId>--> -<!-- <artifactId>easypoi-web</artifactId>--> -<!-- <version>${easypoi.version}</version>--> -<!-- </dependency>--> -<!-- <dependency>--> -<!-- <groupId>cn.afterturn</groupId>--> -<!-- <artifactId>easypoi-annotation</artifactId>--> -<!-- <version>${easypoi.version}</version>--> -<!-- </dependency>--> - <!-- 引用POI --> -<!-- <dependency>--> -<!-- <groupId>org.apache.poi</groupId>--> -<!-- <artifactId>poi</artifactId>--> -<!-- <version>4.1.1</version>--> -<!-- </dependency>--> - -<!-- <dependency>--> -<!-- <groupId>org.jetbrains</groupId>--> -<!-- <artifactId>annotations</artifactId>--> -<!-- <version>17.0.0</version>--> -<!-- <scope>compile</scope>--> -<!-- </dependency>--> + <!-- OPC DA --> + <dependency> + <groupId>org.openscada.external</groupId> + <artifactId>org.openscada.external.jcifs</artifactId> + <version>1.2.25</version> + </dependency> + <dependency> + <groupId>org.openscada.jinterop</groupId> + <artifactId>org.openscada.jinterop.core</artifactId> + <version>2.1.8</version> + </dependency> + <dependency> + <groupId>org.openscada.jinterop</groupId> + <artifactId>org.openscada.jinterop.deps</artifactId> + <version>1.5.0</version> + </dependency> + <dependency> + <groupId>org.openscada.utgard</groupId> + <artifactId>org.openscada.opc.dcom</artifactId> + <version>1.5.0</version> + </dependency> + <dependency> + <groupId>org.openscada.utgard</groupId> + <artifactId>org.openscada.opc.lib</artifactId> + <version>1.5.0</version> + </dependency> + <dependency> + <groupId>org.bouncycastle</groupId> + <artifactId>bcprov-jdk15on</artifactId> + <version>1.61</version> + </dependency> <!-- ModBus TCP --> <dependency> @@ -162,12 +165,6 @@ <scope>test</scope> </dependency> -<!-- <!– websocket –>--> -<!-- <dependency>--> -<!-- <groupId>org.springframework.boot</groupId>--> -<!-- <artifactId>spring-boot-starter-websocket</artifactId>--> -<!-- </dependency>--> - </dependencies> <build> @@ -180,21 +177,6 @@ <artifactId>maven-compiler-plugin</artifactId> <version>3.1</version> </plugin> - - <!-- <plugin>--> -<!-- <groupId>org.springframework.boot</groupId>--> -<!-- <artifactId>spring-boot-maven-plugin</artifactId>--> -<!-- <version>${spring.boot.version}</version>--> -<!-- <executions>--> -<!-- <execution>--> -<!-- <goals>--> -<!-- <goal>repackage</goal> <!– 将引入的 jar 打入其中 –>--> -<!-- </goals>--> -<!-- </execution>--> -<!-- </executions>--> -<!-- </plugin>--> </plugins> </build> - - </project> \ No newline at end of file diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/controller/DataController.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/controller/DataController.java index cd54c25..0c83c57 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/controller/DataController.java +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/controller/DataController.java @@ -1,6 +1,5 @@ package com.iailab.module.data.api.controller; -import com.iailab.api.IFeignModelApi; import com.iailab.framework.common.pojo.CommonResult; import com.iailab.framework.common.util.date.DateUtils; import com.iailab.module.data.common.dto.IndexQueryDTO; @@ -60,9 +59,6 @@ @Resource private IndItemCollector indItemCollector; - - @Resource - private IFeignModelApi feignModelApi; @PostMapping("/point/history") @Operation(summary = "point历史数据") @@ -238,44 +234,6 @@ }); return R.ok().put("data", data); } catch (Exception ex) { - return R.error(ex.getMessage()); - } - } - - @PostMapping("/ind-item/values-trend") - @Operation(summary = "point当前实时数据") - public R indItemValuesTrend(HttpServletResponse response, HttpServletRequest - request, @RequestBody List<String> itemNos) { - try { - apiSecurityUtils.validate(request); - Map<String, Object> CommonResult = new HashMap<>(); - Map<String, List<IndItemValueDTO>> values = indItemCollector.getValueList(itemNos); - CommonResult.put("values", values); - - Map<String, Map<String, Object>> trend = new HashMap<>(); - Map<String, Object> params = new HashMap<>(1); - params.put("modelCode", "trend_analysis"); - values.forEach((k, v) -> { - try { - List<double[][]> sampleDataList = new ArrayList<>(); - List<IndItemValueDTO> nv = v.stream().filter(dto -> { - return dto.getDataValue() != null; - }).collect(Collectors.toList()); - double[][] mix = new double[nv.size()][1]; - for (int i = 0; i < nv.size(); i++) { - mix[i][0] = nv.get(i).getDataValue().doubleValue(); - } - sampleDataList.add(mix); - Map<String, Object> trendItem = feignModelApi.runModel(params, sampleDataList); - trend.put(k, trendItem); - } catch (Exception ex) { - ex.printStackTrace(); - } - }); - CommonResult.put("trend", trend); - return R.ok().put("data", CommonResult); - } catch (Exception ex) { - ex.printStackTrace(); return R.error(ex.getMessage()); } } diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/collector/OpcDACollector.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/collector/OpcDACollector.java new file mode 100644 index 0000000..b000572 --- /dev/null +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/collector/OpcDACollector.java @@ -0,0 +1,115 @@ +package com.iailab.module.data.channel.opcda.collector; + +import com.iailab.module.data.channel.opcda.entity.ChannelOPCDADeviceEntity; +import com.iailab.module.data.channel.opcda.service.ChannelOPCDADeviceService; +import com.iailab.module.data.common.enums.CommonConstant; +import com.iailab.module.data.common.enums.DataSourceType; +import com.iailab.module.data.common.utils.TagUtils; +import lombok.extern.slf4j.Slf4j; +import org.jinterop.dcom.common.JIException; +import org.jinterop.dcom.core.JIVariant; +import org.openscada.opc.lib.da.Group; +import org.openscada.opc.lib.da.Item; +import org.openscada.opc.lib.da.ItemState; +import org.openscada.opc.lib.da.Server; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.util.CollectionUtils; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.stream.Collectors; + +@Slf4j +@Component +public class OpcDACollector { + + @Autowired + private OpcDAUtils opcDAUtils; + + @Autowired + private ChannelOPCDADeviceService channelOPCDADeviceService; + + private Map<String, Server> serverMap = new ConcurrentHashMap<>(); + private Map<String, Group> groupMap = new ConcurrentHashMap<>(); + + private Map<String, ChannelOPCDADeviceEntity> deviceMap = new HashMap<>(); + + private Server getServer(String sourceId) throws Exception { + try { + if (!serverMap.containsKey(sourceId)) { + log.info("根据数据源获取opcDAServer,sourceId=" + sourceId); + ChannelOPCDADeviceEntity OPCDADevice = channelOPCDADeviceService.info(sourceId); + deviceMap.put(sourceId, OPCDADevice); + Server server = opcDAUtils.createServer(OPCDADevice); + if (server != null) { + serverMap.put(sourceId, server); + } + } + } catch (Exception ex) { + log.info("=========getOPCDAServer Exception============"); + log.info("ex.message+" + ex.getMessage()); + ex.printStackTrace(); + throw new Exception(ex.getMessage()); + } + return serverMap.get(sourceId); + } + + public Map<String, Object> getTagValues(List<String[]> tags) { + if (CollectionUtils.isEmpty(tags)) { + return new HashMap<>(); + } + Map<String, Object> result = new HashMap<>(tags.size()); + // 按照sourceId分组 + Map<String, List<String[]>> sourceIdTagMap = tags.stream().collect(Collectors.groupingBy(t -> t[0])); + + for (Map.Entry<String, List<String[]>> entry : sourceIdTagMap.entrySet()) { + try { + Server server = this.getServer(entry.getKey()); + Group group = this.getGroup(server, entry.getKey()); + Map<Item, ItemState> read = OpcDAUtils.readA(group, entry.getValue()); + + for (Map.Entry<Item, ItemState> itemStateEntry : read.entrySet()) { + try { + result.put(TagUtils.genTagId(DataSourceType.OPCDA.getCode(), deviceMap.get(entry.getKey()).getServerName(), itemStateEntry.getKey().getId()), OpcDAUtils.getObjectValue(itemStateEntry.getValue())); + } catch (JIException e) { + result.put(TagUtils.genTagId(DataSourceType.OPCDA.getCode(), deviceMap.get(entry.getKey()).getServerName(), itemStateEntry.getKey().getId()), CommonConstant.BAD_VALUE); + } + } + } catch (Exception ex) { + ex.printStackTrace(); + for (String[] tag : entry.getValue()) { + result.put(TagUtils.genTagId(DataSourceType.OPCDA.getCode(), deviceMap.get(entry.getKey()).getServerName(), tag[1]), CommonConstant.BAD_VALUE); + } + } + } + return result; + } + + private Group getGroup(Server server, String sourceId) throws Exception { + try { + if (!groupMap.containsKey(sourceId)) { + log.info("根据数据源获取opcDAGroup,sourceId=" + sourceId); + Group group = server.addGroup(sourceId); + if (group != null) { + groupMap.put(sourceId, group); + } + } + } catch (Exception ex) { + log.info("=========getOPCDAGroup Exception============"); + log.info("ex.message+" + ex.getMessage()); + ex.printStackTrace(); + throw new Exception(ex.getMessage()); + } + return groupMap.get(sourceId); + } + + public void write(String serverId) throws Exception { + Server server = this.getServer(serverId); + Group group = server.addGroup(); + Item item = group.addItem("通道 1.设备 1.item001"); + OpcDAUtils.write(item, new JIVariant("999")); + } +} diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/collector/OpcDAUtils.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/collector/OpcDAUtils.java new file mode 100644 index 0000000..7d5ba56 --- /dev/null +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/collector/OpcDAUtils.java @@ -0,0 +1,115 @@ +package com.iailab.module.data.channel.opcda.collector; + +import com.iailab.module.data.channel.opcda.dto.WriteDTO; +import com.iailab.module.data.channel.opcda.entity.ChannelOPCDADeviceEntity; +import com.iailab.module.data.channel.opcda.entity.ChannelOPCDATagEntity; +import lombok.extern.slf4j.Slf4j; +import org.jinterop.dcom.common.JIException; +import org.jinterop.dcom.core.JIVariant; +import org.openscada.opc.lib.common.ConnectionInformation; +import org.openscada.opc.lib.da.*; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.concurrent.Executors; +import java.util.stream.Collectors; + +@Slf4j +@Component +public class OpcDAUtils { + + // 上次获取时间 + private static long nextGetTime; + // 获取间隔时间 + private static long expGetTime = 1000 * 60; + + public synchronized Server createServer(ChannelOPCDADeviceEntity config) { + if (System.currentTimeMillis() - nextGetTime < expGetTime) { + throw new RuntimeException("获取OpcUaClient过快"); + } + nextGetTime = System.currentTimeMillis(); + Server server; + try { + ConnectionInformation ci = new ConnectionInformation(); + ci.setHost(config.getHost()); + ci.setUser(config.getUser()); + ci.setPassword(config.getPassword()); + ci.setClsid(config.getClsId()); + ci.setProgId(config.getProgId()); + + server = new Server(ci, Executors.newSingleThreadScheduledExecutor()); + server.connect(); + log.info("创建OpcUA客户端完成"); + } catch (Exception e) { + log.error("创建OpcUA客户端失败", e.getMessage()); + throw new RuntimeException(e.getMessage()); + } + return server; + } + + public static Map<Item, ItemState> readA(Group group, List<String[]> tags) throws AddFailedException, JIException { + List<String> itemIds = tags.stream().map(t -> t[1]).collect(Collectors.toList()); + Map<String, Item> stringItemMap = addItems(group, itemIds); + List<Item> list = new ArrayList<>(stringItemMap.size()); + for (Map.Entry<String, Item> entry : stringItemMap.entrySet()) { + list.add(entry.getValue()); + } + Item[] items = list.toArray(new Item[stringItemMap.size()]); + return group.read(true, items); + } + + public static Map<Item, ItemState> read(Group group, List<ChannelOPCDATagEntity> tags) throws AddFailedException, JIException { + List<String> itemIds = tags.stream().map(ChannelOPCDATagEntity::getItemId).collect(Collectors.toList()); + Map<String, Item> stringItemMap = addItems(group, itemIds); + List<Item> list = new ArrayList<>(stringItemMap.size()); + for (Map.Entry<String, Item> entry : stringItemMap.entrySet()) { + list.add(entry.getValue()); + } + Item[] items = list.toArray(new Item[stringItemMap.size()]); + return group.read(true, items); + } + + public static ItemState read(Item item) throws AddFailedException, JIException { + return item.read(true); + } + + public static Integer write(Item item,JIVariant value) throws AddFailedException, JIException { + return item.write(value); + } + + public static Map<Item, Integer> write(Group group, List<WriteDTO> writeDTOS) throws AddFailedException, JIException { + WriteRequest[] writeRequests = new WriteRequest[writeDTOS.size()]; + for (int i = 0; i < writeDTOS.size(); i++) { + WriteDTO writeDTO = writeDTOS.get(i); + WriteRequest writeRequest = new WriteRequest(writeDTO.getItem(),writeDTO.getValue()); + writeRequests[i] = writeRequest; + } + return group.write(writeRequests); + } + + public static Item addItem(Group group, String itemId) throws AddFailedException, JIException { + List<String> itemIds = new ArrayList<>(1); + itemIds.add(itemId); + Map<String, Item> stringItemMap = addItems(group, itemIds); + return stringItemMap.get(itemId); + } + + public static Map<String, Item> addItems(Group group, List<String> itemIds) throws AddFailedException, JIException { + String[] items = itemIds.toArray(new String[itemIds.size()]); + return group.addItems(items); + } + + public static Object getObjectValue(ItemState itemState) throws JIException { + JIVariant value = itemState.getValue(); + if (value.getType() == JIVariant.VT_UI2 || value.getType() == JIVariant.VT_UI4){ + return value.getObjectAsUnsigned().getValue(); + }else if (value.getType() == JIVariant.VT_I2){ + return value.getObjectAsShort(); + }else { + return value.getObject(); + } + } + +} diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/controller/ChannelOPCDADeviceController.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/controller/ChannelOPCDADeviceController.java new file mode 100644 index 0000000..01e53fc --- /dev/null +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/controller/ChannelOPCDADeviceController.java @@ -0,0 +1,86 @@ +package com.iailab.module.data.channel.opcda.controller; + +import com.iailab.module.data.channel.opcda.entity.ChannelOPCDADeviceEntity; +import com.iailab.module.data.channel.opcda.service.ChannelOPCDADeviceService; +import com.iailab.module.data.common.utils.PageUtils; +import com.iailab.module.data.common.utils.R; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.Date; +import java.util.Map; +import java.util.UUID; + +/** + * 操作opc ua配置 + * + * @author DongYukun + * @createTime 2023年04月26日 10:33:00 + */ +@RestController +@RequestMapping("/channel/opcda/device") +public class ChannelOPCDADeviceController { + @Autowired + private ChannelOPCDADeviceService channelOPCDADeviceService; + + /** + * 分页查询opc da 配置 + * + * @param params + */ + @GetMapping("/list") + public R list(@RequestParam Map<String, Object> params) { + PageUtils page = channelOPCDADeviceService.queryPage(params); + + return R.ok().put("page", page); + } + + /** + * 根据id查询opc da配置详情 + * + * @param id + */ + @GetMapping("/info/{id}") + public R info(@PathVariable("id") String id) { + ChannelOPCDADeviceEntity info = channelOPCDADeviceService.info(id); + return R.ok().put("data", info); + } + + /** + * 添加opc ua配置 + * + * @param channelOPCDADeviceEntity + */ + @PostMapping("/add") + public R add(@RequestBody ChannelOPCDADeviceEntity channelOPCDADeviceEntity) { + String id = UUID.randomUUID().toString(); + channelOPCDADeviceEntity.setId(id); + channelOPCDADeviceEntity.setCreateTime(new Date()); + channelOPCDADeviceService.add(channelOPCDADeviceEntity); + return R.ok(); + } + + /** + * 修改opc ua配置 + * + * @param channelOPCDADeviceEntity + */ + @PostMapping("/update") + public R update(@RequestBody ChannelOPCDADeviceEntity channelOPCDADeviceEntity) { + channelOPCDADeviceEntity.setUpdateTime(new Date()); + channelOPCDADeviceService.update(channelOPCDADeviceEntity); + return R.ok(); + } + + /** + * 删除opc ua配置 + * + * @param params + */ + @PostMapping("/delete") + public R delete(@RequestBody Map<String, Object> params) { + String id = (String) params.get("id"); + channelOPCDADeviceService.delete(id); + return R.ok(); + } +} \ No newline at end of file diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/controller/ChannelOPCDATagController.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/controller/ChannelOPCDATagController.java new file mode 100644 index 0000000..22d3aca --- /dev/null +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/controller/ChannelOPCDATagController.java @@ -0,0 +1,102 @@ +package com.iailab.module.data.channel.opcda.controller; + +import com.iailab.module.data.channel.opcda.entity.ChannelOPCDATagEntity; +import com.iailab.module.data.channel.opcda.service.ChannelOPCDATagService; +import com.iailab.module.data.common.exception.RRException; +import com.iailab.module.data.common.utils.PageUtils; +import com.iailab.module.data.common.utils.R; +import jodd.util.Base64; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +import java.util.Map; +import java.util.UUID; + +/** + * 操作OPCDA tag配置 + * + * @author DongYukun + * @createTime 2023年05月6日 17:44:00 + */ +@RestController +@RequestMapping("/channel/opcda/tag") +public class ChannelOPCDATagController { + @Autowired + private ChannelOPCDATagService channelOPCDATagService; + /** + * 分页查询tag + * + * @param params + */ + @GetMapping("/list") + public R tagList(@RequestParam Map<String, Object> params){ + PageUtils page = channelOPCDATagService.queryPage(params); + + return R.ok().put("page", page); + } + /** + * 根据id查询tag详情 + * + * @param id + */ + @GetMapping("/info/{id}") + public R tagInfo(@PathVariable("id") String id){ + ChannelOPCDATagEntity info= channelOPCDATagService.info(Base64.decodeToString(id)); + return R.ok().put("data", info); + } + /** + * 添加tag + * + * @param entity + */ + @PostMapping("/add") + public R tagAdd(@RequestBody ChannelOPCDATagEntity entity){ + entity.setId(UUID.randomUUID().toString()); + channelOPCDATagService.add(entity); + return R.ok(); + } + + /** + * 修改tag + * + * @param channelOPCDATagEntity + */ + @PostMapping("/update") + public R tagUpdate(@RequestBody ChannelOPCDATagEntity channelOPCDATagEntity) { + channelOPCDATagService.update(channelOPCDATagEntity); + return R.ok(); + } + + /** + * 删除tag + * @param params + * + */ + @PostMapping("/delete") + public R tagDelete(@RequestBody Map<String, Object> params) { + String id = (String)params.get("id"); + channelOPCDATagService.delete(id); + return R.ok(); + } + + /** + * 导入 + * + * @param serverId + * @param file + * @return + */ + @PostMapping("/import/{serverId}") + public R importTag(@PathVariable("serverId") String serverId, @RequestParam("file") MultipartFile file) { + try { + if (file.isEmpty()) { + throw new RRException("上传文件不能为空"); + } + channelOPCDATagService.importTag(serverId, file); + } catch (Exception ex) { + return R.error(ex.getMessage()); + } + return R.ok(); + } +} diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/dao/ChannelOPCDADeviceDao.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/dao/ChannelOPCDADeviceDao.java new file mode 100644 index 0000000..0fbe2a5 --- /dev/null +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/dao/ChannelOPCDADeviceDao.java @@ -0,0 +1,16 @@ +package com.iailab.module.data.channel.opcda.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.iailab.module.data.channel.opcda.entity.ChannelOPCDADeviceEntity; +import org.apache.ibatis.annotations.Mapper; + + +/** + * @author PanZhibao + * @Description + * @createTime 2023年04月26日 11:31:00 + */ +@Mapper +public interface ChannelOPCDADeviceDao extends BaseMapper<ChannelOPCDADeviceEntity> { + +} diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/dao/ChannelOPCDATagDao.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/dao/ChannelOPCDATagDao.java new file mode 100644 index 0000000..638d384 --- /dev/null +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/dao/ChannelOPCDATagDao.java @@ -0,0 +1,14 @@ +package com.iailab.module.data.channel.opcda.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.iailab.module.data.channel.opcda.entity.ChannelOPCDATagEntity; +import org.apache.ibatis.annotations.Mapper; + +/** + * @author DongYukun + * @Description + * @createTime 2023年05月8日 15:01:00 + */ +@Mapper +public interface ChannelOPCDATagDao extends BaseMapper<ChannelOPCDATagEntity> { +} diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/dto/ChannelOPCDADeviceDTO.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/dto/ChannelOPCDADeviceDTO.java new file mode 100644 index 0000000..ad8fda3 --- /dev/null +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/dto/ChannelOPCDADeviceDTO.java @@ -0,0 +1,46 @@ +package com.iailab.module.data.channel.opcda.dto; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * @description: opcda_device + * @author: dzd + * @date: 2024/7/12 10:42 + **/ +@Schema(description = "OPC DA设备") +@Data +public class ChannelOPCDADeviceDTO implements Serializable { + private static final long serialVersionUID = 1L; + + @Schema(description = "主键", example = "主键") + private String id; + + @Schema(description = "服务名", example = "服务名") + private String serverName; + + @Schema(description = "主机IP", example = "主机IP") + private String host; + + @Schema(description = "用户名", example = "用户名") + private String user; + + @Schema(description = "密码", example = "密码") + private String password; + + @Schema(description = "设备名", example = "设备名") + private String progId; + + @Schema(description = "设备注册表ID", example = "设备注册表ID") + private String clsId; + + @Schema(description = "创建时间", example = "创建时间") + private Date createTime; + + @Schema(description = "更新时间", example = "更新时间") + private Date updateTime; +} + diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/dto/ChannelOPCDATagDTO.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/dto/ChannelOPCDATagDTO.java new file mode 100644 index 0000000..cca58dd --- /dev/null +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/dto/ChannelOPCDATagDTO.java @@ -0,0 +1,43 @@ +package com.iailab.module.data.channel.opcda.dto; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * @description: opcda_tag + * @author: dzd + * @date: 2024/7/12 11:00 + **/ +@Schema(description = "OPC DA TAG") +@Data +public class ChannelOPCDATagDTO implements Serializable { + private static final long serialVersionUID = 1L; + + @Schema(description = "主键", example = "主键") + private String id; + + @Schema(description = "服务id", example = "服务id") + private String serverId; + + @Schema(description = "TagName", example = "TagName") + private String tagName; + + @Schema(description = "数据类型", example = "数据类型") + private String dataType; + + @Schema(description = "是否可以tag", example = "是否可以tag") + private Boolean enabled; + + @Schema(description = "itemId", example = "itemId") + private String itemId; + + @Schema(description = "创建时间", example = "创建时间") + private Date createTime; + + @Schema(description = "修改时间", example = "修改时间") + private Date updateTime; + +} \ No newline at end of file diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/dto/WriteDTO.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/dto/WriteDTO.java new file mode 100644 index 0000000..9517b48 --- /dev/null +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/dto/WriteDTO.java @@ -0,0 +1,15 @@ +package com.iailab.module.data.channel.opcda.dto; + +import lombok.Data; +import org.jinterop.dcom.core.JIVariant; +import org.openscada.opc.lib.da.Item; + +import java.io.Serializable; + +@Data +public class WriteDTO implements Serializable { + private static final long serialVersionUID = 1L; + + private Item item; + private JIVariant value; +} diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/entity/ChannelOPCDADeviceEntity.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/entity/ChannelOPCDADeviceEntity.java new file mode 100644 index 0000000..9202bf9 --- /dev/null +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/entity/ChannelOPCDADeviceEntity.java @@ -0,0 +1,67 @@ +package com.iailab.module.data.channel.opcda.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * @description: opcda_device + * @author: dzd + * @date: 2024/7/12 10:42 + **/ +@Data +@TableName("t_channel_opcda_device") +public class ChannelOPCDADeviceEntity implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * 主键 + */ + @TableId(value = "id",type = IdType.INPUT) + private String id; + /** + * ServerName 服务名 + */ + private String serverName; + + + /** + * ip + */ + private String host; + + /** + * 用户名 + */ + private String user; + + /** + * 密码 + */ + private String password; + + /** + * 设备名 + */ + private String progId; + + /** + * 设备注册表ID + */ + private String clsId; + + /** + * 创建时间 + */ + private Date createTime; + + /** + * 更新时间 + */ + private Date updateTime; +} + diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/entity/ChannelOPCDATagEntity.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/entity/ChannelOPCDATagEntity.java new file mode 100644 index 0000000..9a4cf85 --- /dev/null +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/entity/ChannelOPCDATagEntity.java @@ -0,0 +1,62 @@ +package com.iailab.module.data.channel.opcda.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * @description: opcda_tag + * @author: dzd + * @date: 2024/7/12 11:00 + **/ +@Data +@TableName("t_channel_opcda_tag") +public class ChannelOPCDATagEntity implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * 主键 + */ + @TableId(value = "id",type = IdType.INPUT) + private String id; + + /** + * 服务id + */ + private String serverId; + + /** + * TagName + */ + private String tagName; + + /** + * 数据类型 + */ + private String dataType; + + /** + * 是否可以tag,如果为false,即使定义了但是runtime不会读取该数据 + */ + private Boolean enabled; + + /** + * itemId + */ + private String itemId; + + /** + * 创建时间 + */ + private Date createTime; + + /** + * 修改时间 + */ + private Date updateTime; + +} \ No newline at end of file diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/service/ChannelOPCDADeviceService.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/service/ChannelOPCDADeviceService.java new file mode 100644 index 0000000..c760f9d --- /dev/null +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/service/ChannelOPCDADeviceService.java @@ -0,0 +1,60 @@ +package com.iailab.module.data.channel.opcda.service; + +import com.iailab.module.data.channel.opcda.dto.ChannelOPCDADeviceDTO; +import com.iailab.module.data.channel.opcda.entity.ChannelOPCDADeviceEntity; +import com.iailab.module.data.common.utils.PageUtils; + +import java.util.List; +import java.util.Map; + +/** + * @author DongYukun + * @Description + * @createTime 2023年05月08日 15:04:00 + */ +public interface ChannelOPCDADeviceService { + /** + * 分页查询设备 + * + * @param params + */ + PageUtils queryPage(Map<String, Object> params); + /** + * 查询设备详情 + * + * @param id + */ + ChannelOPCDADeviceEntity info(String id); + + /** + * 列表 + * + * @param params + * @return + */ + List<ChannelOPCDADeviceEntity> list(Map<String, Object> params); + + /** + * 添加设备 + * + * @param channelOPCDADeviceEntity + */ + void add(ChannelOPCDADeviceEntity channelOPCDADeviceEntity); + /** + * 修改设备 + * + * @param channelOPCDADeviceEntity + */ + void update(ChannelOPCDADeviceEntity channelOPCDADeviceEntity); + /** + * 删除设备 + * + * @param id + */ + void delete(String id); + /** + * 查询全部设备 + * + */ + List<ChannelOPCDADeviceDTO> selectAll(); +} diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/service/ChannelOPCDATagService.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/service/ChannelOPCDATagService.java new file mode 100644 index 0000000..f5d4cff --- /dev/null +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/service/ChannelOPCDATagService.java @@ -0,0 +1,70 @@ +package com.iailab.module.data.channel.opcda.service; + +import com.iailab.module.data.channel.opcda.dto.ChannelOPCDATagDTO; +import com.iailab.module.data.channel.opcda.entity.ChannelOPCDATagEntity; +import com.iailab.module.data.common.utils.PageUtils; +import org.springframework.web.multipart.MultipartFile; + +import java.util.List; +import java.util.Map; + +/** + * @author DongYukun + * @Description + * @createTime 2023年05月08日 15:04:00 + */ +public interface ChannelOPCDATagService { + /** + * 分页查询tag + * + * @param params + */ + PageUtils queryPage(Map<String, Object> params); + + /** + * 查询tag详情 + * @param id + * + */ + ChannelOPCDATagEntity info(String id); + /** + * 添加tag + * + * @param channelOPCDATagEntity + */ + void add(ChannelOPCDATagEntity channelOPCDATagEntity); + /** + * 修改tag + * + * @param channelOPCDATagEntity + */ + void update(ChannelOPCDATagEntity channelOPCDATagEntity); + /** + * 删除tag + * @param id + * + */ + void delete(String id); + + List<ChannelOPCDATagEntity> getByserverId(String serverId); + + + List<ChannelOPCDATagDTO> selectAll(); + + List<ChannelOPCDATagEntity> listByIds(List<String> ids); + + /** + * 通过serverId删除 + * + */ + void deleteByServerId(String serverId); + + /** + * 导入Tag + * + * @param serverId + * @param file + * @throws Exception + */ + void importTag(String serverId, MultipartFile file) throws Exception; +} diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/service/impl/ChannelOPCDADeviceServiceImpl.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/service/impl/ChannelOPCDADeviceServiceImpl.java new file mode 100644 index 0000000..2c79766 --- /dev/null +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/service/impl/ChannelOPCDADeviceServiceImpl.java @@ -0,0 +1,115 @@ +package com.iailab.module.data.channel.opcda.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.toolkit.StringUtils; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.iailab.framework.common.util.object.ConvertUtils; +import com.iailab.module.data.channel.opcda.dao.ChannelOPCDADeviceDao; +import com.iailab.module.data.channel.opcda.dto.ChannelOPCDADeviceDTO; +import com.iailab.module.data.channel.opcda.entity.ChannelOPCDADeviceEntity; +import com.iailab.module.data.channel.opcda.service.ChannelOPCDADeviceService; +import com.iailab.module.data.channel.opcda.service.ChannelOPCDATagService; +import com.iailab.module.data.common.utils.PageUtils; +import com.iailab.module.data.common.utils.Query; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.List; +import java.util.Map; + +/** + * @author DongYukun + * @Description + * @createTime 2023年05月08日 15:04:00 + */ +@Service +public class ChannelOPCDADeviceServiceImpl extends ServiceImpl<ChannelOPCDADeviceDao, ChannelOPCDADeviceEntity> implements ChannelOPCDADeviceService { + @Resource + private ChannelOPCDADeviceDao channelOPCDADeviceDao; + + @Autowired + private ChannelOPCDATagService channelOPCDATagService; + /** + * 分页查询opc ua配置 + * + * @param params + */ + @Override + public PageUtils queryPage(Map<String, Object> params) { + String serverName = (String) params.get("serverName"); + + IPage<ChannelOPCDADeviceEntity> page = this.page( + new Query<ChannelOPCDADeviceEntity>().getPage(params), + new QueryWrapper<ChannelOPCDADeviceEntity>() + .like(StringUtils.isNotBlank(serverName), "server_name", serverName) + .orderByDesc("create_time") + ); + return new PageUtils(page); + } + + /** + * 查询opc ua配置详情 + * + * @param id + */ + @Override + public ChannelOPCDADeviceEntity info(String id) { + return channelOPCDADeviceDao.selectById(id); + } + + /** + * 列表 + * + * @param params + * @return + */ + @Override + public List<ChannelOPCDADeviceEntity> list(Map<String, Object> params) { + return channelOPCDADeviceDao.selectList(new QueryWrapper<ChannelOPCDADeviceEntity>().orderByAsc("server_name")); + } + + /** + * 添加opc ua配置 + * + * @param channelOPCDADeviceEntity + */ + @Override + public void add(ChannelOPCDADeviceEntity channelOPCDADeviceEntity) { + channelOPCDADeviceDao.insert(channelOPCDADeviceEntity); + } + + /** + * 修改opc ua配置 + * + * @param channelOPCDADeviceEntity + */ + @Override + public void update(ChannelOPCDADeviceEntity channelOPCDADeviceEntity) { + channelOPCDADeviceDao.updateById(channelOPCDADeviceEntity); + } + + /** + * 删除opc ua配置 + * + * @param id + */ + @Override + public void delete(String id) { + + //先删除device下的tag + channelOPCDATagService.deleteByServerId(id); + + channelOPCDADeviceDao.deleteById(id); + } + + @Override + public List<ChannelOPCDADeviceDTO> selectAll() { + + List<ChannelOPCDADeviceEntity> entityList = baseMapper.selectList( + null + ); + return ConvertUtils.sourceToTarget(entityList, ChannelOPCDADeviceDTO.class); + } +} diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/service/impl/ChannelOPCDATagServiceImpl.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/service/impl/ChannelOPCDATagServiceImpl.java new file mode 100644 index 0000000..e274fad --- /dev/null +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcda/service/impl/ChannelOPCDATagServiceImpl.java @@ -0,0 +1,187 @@ +package com.iailab.module.data.channel.opcda.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; +import com.baomidou.mybatisplus.core.toolkit.StringUtils; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.iailab.framework.common.util.object.ConvertUtils; +import com.iailab.module.data.channel.opcda.dao.ChannelOPCDATagDao; +import com.iailab.module.data.channel.opcda.dto.ChannelOPCDATagDTO; +import com.iailab.module.data.channel.opcda.entity.ChannelOPCDATagEntity; +import com.iailab.module.data.channel.opcda.service.ChannelOPCDATagService; +import com.iailab.module.data.common.utils.PageUtils; +import com.iailab.module.data.common.utils.Query; +import lombok.extern.slf4j.Slf4j; +import org.apache.poi.ss.usermodel.CellType; +import org.apache.poi.xssf.usermodel.XSSFRow; +import org.apache.poi.xssf.usermodel.XSSFSheet; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.multipart.MultipartFile; + +import javax.annotation.Resource; +import java.io.File; +import java.io.FileInputStream; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +/** + * @author DongYukun + * @Description + * @createTime 2023年05月08日 15:04:00 + */ +@Slf4j +@Service +public class ChannelOPCDATagServiceImpl extends ServiceImpl<ChannelOPCDATagDao, ChannelOPCDATagEntity> implements ChannelOPCDATagService { + @Resource + private ChannelOPCDATagDao channelOPCDATagDao; + + @Value("${iems.upload-dir}") + private String uploadDir; + + /** + * 分页查询tag + * + * @param params + */ + @Override + public PageUtils queryPage(Map<String, Object> params) { + String tagName = (String) params.get("tagName"); + String serverId = (String) params.get("serverId"); + + IPage<ChannelOPCDATagEntity> page = this.page( + new Query<ChannelOPCDATagEntity>().getPage(params), + new QueryWrapper<ChannelOPCDATagEntity>() + .like(StringUtils.isNotBlank(tagName), "tag_name", tagName) + .eq(StringUtils.isNotBlank(serverId), "server_id", serverId) + .orderByDesc("create_time") + ); + return new PageUtils(page); + } + + /** + * 查询tag详情 + * + * @param id + */ + @Override + public ChannelOPCDATagEntity info(String id) { + return channelOPCDATagDao.selectById(id); + } + + @Override + public List<ChannelOPCDATagEntity> getByserverId(String serverId) { + QueryWrapper<ChannelOPCDATagEntity> queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("server_id", serverId).orderByDesc ("create_time"); + return channelOPCDATagDao.selectList(queryWrapper); + + } + + /** + * 添加tag + * + * @param channelOPCDATagEntity + */ + @Override + public void add(ChannelOPCDATagEntity channelOPCDATagEntity) { + channelOPCDATagDao.insert(channelOPCDATagEntity); + } + + /** + * 修改tag + * + * @param channelOPCDATagEntity + */ + @Override + public void update(ChannelOPCDATagEntity channelOPCDATagEntity) { + channelOPCDATagDao.updateById(channelOPCDATagEntity); + } + + /** + * 删除tag + * + * @param id + */ + @Override + public void delete(String id) { + channelOPCDATagDao.deleteById(id); + } + + @Override + public List<ChannelOPCDATagDTO> selectAll() { + + List<ChannelOPCDATagEntity> entityList = baseMapper.selectList( + null + ); + return ConvertUtils.sourceToTarget(entityList, ChannelOPCDATagDTO.class); + } + + @Override + public List<ChannelOPCDATagEntity> listByIds(List<String> ids) { + return baseMapper.selectList(new QueryWrapper<ChannelOPCDATagEntity>().in("id", ids)); + } + + @Override + public void deleteByServerId(String serverId) { + baseMapper.delete(new QueryWrapper<ChannelOPCDATagEntity>().eq("server_id",serverId)); + } + + /** + * 导入Tag + * + * @param serverId + * @param file + * @throws Exception + */ + @Override + @Transactional(rollbackFor = Exception.class) + public void importTag(String serverId, MultipartFile file) throws Exception { + try { + String suffix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")); + String fileName = UUID.randomUUID().toString() + suffix; + String path = uploadDir + fileName; + file.transferTo(new File(path)); + + XSSFWorkbook hssfWorkbook = new XSSFWorkbook(new FileInputStream(path)); + XSSFSheet sheet = hssfWorkbook.getSheetAt(0); + int lastRowNum = sheet.getLastRowNum(); + log.info("最后一行:" + lastRowNum); + int lastCellNum = 4; + List<ChannelOPCDATagEntity> dangerList = new ArrayList<>(); + for (int i = 2; i <= lastRowNum; i++) { + XSSFRow row = sheet.getRow(i); + for (int j = row.getFirstCellNum(); j < lastCellNum; j++) { + row.getCell(j).setCellType(CellType.STRING); + } + ChannelOPCDATagEntity tagEntity = new ChannelOPCDATagEntity(); + tagEntity.setId(UUID.randomUUID().toString()); + tagEntity.setTagName(row.getCell(1).getStringCellValue()); + tagEntity.setDataType(row.getCell(2).getStringCellValue()); + tagEntity.setItemId(row.getCell(3).getStringCellValue()); + tagEntity.setEnabled(true); + tagEntity.setServerId(serverId); + dangerList.add(tagEntity); + } + if (CollectionUtils.isEmpty(dangerList)) { + return; + } + //getBaseMapper().insertList(dangerList); + dangerList.forEach(item -> { + try { + getBaseMapper().insert(item); + } catch (Exception ex) { + log.warn("插入异常:" + item.getTagName()); + } + }); + } catch (Exception ex) { + ex.printStackTrace(); + log.warn("导入失败!"); + throw ex; + } + } +} diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcua/dto/ChannelOPCUADeviceDTO.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcua/dto/ChannelOPCUADeviceDTO.java index 2a29dbd..a962b56 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcua/dto/ChannelOPCUADeviceDTO.java +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcua/dto/ChannelOPCUADeviceDTO.java @@ -1,6 +1,7 @@ package com.iailab.module.data.channel.opcua.dto; import com.alibaba.fastjson.annotation.JSONField; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import java.io.Serializable; @@ -10,67 +11,39 @@ * @Description * @createTime 2023年04月23日 14:25:00 */ +@Schema(description = "OPC UA设备") @Data public class ChannelOPCUADeviceDTO implements Serializable { private static final long serialVersionUID = 1L; - /** - * ServerName - */ - @JSONField(name="ServerName") + @Schema(description = "ServerName", example = "ServerName") private String ServerName; - /** - * EndpointUrl - */ - @JSONField(name="EndpointUrl") + @Schema(description = "EndpointUrl", example = "EndpointUrl") private String EndpointUrl; - /** - * SecurityPolicy - */ - @JSONField(name="SecurityPolicy") + @Schema(description = "SecurityPolicy", example = "SecurityPolicy") private String SecurityPolicy; - /** - * SecurityMode - */ - @JSONField(name="SecurityMode") + @Schema(description = "SecurityMode", example = "SecurityMode") private String SecurityMode; - /** - * 连接方式(0,匿名;1,用户名密码; 2,安全证书) - */ - @JSONField(name="ConnectionType") + @Schema(description = "连接方式", example = "连接方式(0,匿名;1,用户名密码; 2,安全证书)") private String ConnectionType; - /** - * 用户名 - */ - @JSONField(name="UserName") + @Schema(description = "用户名", example = "用户名") private String UserName; - /** - * 密码 - */ - @JSONField(name="Password") + @Schema(description = "密码", example = "密码") private String Password; - /** - * 安全证书路径 - */ - @JSONField(name="CertificatePath") + @Schema(description = "安全证书路径", example = "安全证书路径") private String CertificatePath; - /** - * 设备不活动超时时间 - */ - @JSONField(name="ConnectInactivityTimeout") + @Schema(description = "设备不活动超时时间", example = "设备不活动超时时间") private Integer ConnectInactivityTimeout; - /** - * 重连超时 - */ - @JSONField(name="ConnectInactivityTimeout") + + @Schema(description = "重连超时", example = "重连超时") private Integer ReconnectInterval; } diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcua/entity/ChannelOPCUATagEntity.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcua/entity/ChannelOPCUATagEntity.java index fb489c5..e487db4 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcua/entity/ChannelOPCUATagEntity.java +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcua/entity/ChannelOPCUATagEntity.java @@ -3,7 +3,6 @@ import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; -import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import java.io.Serializable; @@ -24,7 +23,6 @@ /** * 主键 */ - @Schema(description = "主键") @TableId(value = "id",type = IdType.INPUT) private String id; /** diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/feign/FeignDataImpl.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/feign/FeignDataImpl.java deleted file mode 100644 index 794d57f..0000000 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/feign/FeignDataImpl.java +++ /dev/null @@ -1,192 +0,0 @@ -package com.iailab.module.data.feign; - -import com.alibaba.cloud.commons.lang.StringUtils; -import com.iailab.module.data.api.IFeignDataApi; -import com.iailab.framework.common.util.date.DateUtils; -import com.iailab.framework.common.util.object.BeanUtils; -import com.iailab.module.data.common.enums.DataTypeEnum; -import com.iailab.module.data.dto.*; -import com.iailab.module.data.http.entity.HttpApiEntity; -import com.iailab.module.data.influxdb.pojo.InfluxPointValuePOJO; -import com.iailab.module.data.point.collection.PointCollector; -import com.iailab.module.data.point.dto.DaPointDTO; -import com.iailab.module.data.point.dto.DaPointWriteValueDTO; -import com.iailab.module.data.point.service.DaPointService; -import com.iailab.module.data.http.service.HttpApiService; -import com.iailab.module.data.ind.collection.IndItemCollector; -import com.iailab.module.data.ind.dto.IndItemValueDTO; -import com.iailab.module.data.influxdb.service.InfluxDBService; -import javax.annotation.Resource; -import org.springframework.util.CollectionUtils; -import org.springframework.web.bind.annotation.RestController; - -import java.math.BigDecimal; -import java.util.*; - -/** - * @author PanZhibao - * @Description - * @createTime 2023年06月28日 08:53:00 - */ -@RestController -public class FeignDataImpl implements IFeignDataApi { - @Resource - private InfluxDBService influxDBService; - - @Resource - DaPointService daPointService; - - @Resource - private HttpApiService httpApiService; - - @Resource - private IndItemCollector indItemCollector; - - @Resource - private PointCollector pointCollector; - - @Override - public List<ApiDataDTO> queryPointValues(FeignQueryPointDTO dto) { - DaPointDTO daPointDTO = daPointService.getByNo(dto.getPointCode()); - InfluxPointValuePOJO pojo = new InfluxPointValuePOJO(); - pojo.setPoint(dto.getPointCode()); - pojo.setType(daPointDTO.getDataType()); - Date startTime = dto.getStartTime(); - Date endTime = dto.getEndTime(); - List<Map<String, Object>> list = influxDBService.queryPointValues(pojo, startTime, endTime); - List<ApiDataDTO> dataEntityList = new ArrayList<>(); - for (int i = 0; list.size() - i >= 1; i++) { - ApiDataDTO dataEntity = new ApiDataDTO(); - dataEntity.setDataValue(Double.parseDouble(list.get(i).get("value").toString())); - dataEntity.setTimeStamp((Date)(list.get(i).get("time"))); - dataEntityList.add(dataEntity); - } - return dataEntityList; - } - - @Override - public List<ApiDataDTO> querySimTagValues(FeignQueryPointDTO dto) { - - InfluxPointValuePOJO pojo = new InfluxPointValuePOJO(); - pojo.setPoint(dto.getPointCode()); - pojo.setType(DataTypeEnum.FLOAT.getCode()); - Date startTime = dto.getStartTime(); - Date endTime = dto.getEndTime(); - List<Map<String, Object>> list = influxDBService.queryPointValues(pojo, startTime, endTime); - List<ApiDataDTO> dataEntityList = new ArrayList<>(); - for (int i = 0; list.size() - i >= 1; i++) { - ApiDataDTO dataEntity = new ApiDataDTO(); - dataEntity.setDataValue(Double.parseDouble(list.get(i).get("value").toString())); - dataEntity.setTimeStamp((Date)(list.get(i).get("time"))); - dataEntityList.add(dataEntity); - } - return dataEntityList; - } - - @Override - public Map<String, Object> getCurrentValue(List<String> pointNos) { - return pointCollector.getCurrentValue(pointNos); - } - - @Override - public ApiDataPointDTO getPoint(String pointNo) { - DaPointDTO daPointDTO = daPointService.getByNo(pointNo); - return BeanUtils.toBean(daPointDTO, ApiDataPointDTO.class); - - } - - @Override - public FeignHttpApiDTO getHttpApi(String code) { - HttpApiEntity entity = httpApiService.getByCode(code); - return BeanUtils.toBean(entity, FeignHttpApiDTO.class); - - } - - @Override - public List<ApiDataDTO> queryIndItemValues(FeignQueryPointDTO dto) { - List<ApiDataDTO> result = new ArrayList<>(); - List<String> itemNos = new ArrayList<>(); - itemNos.add(dto.getPointCode()); - Map<String, List<IndItemValueDTO>> data = indItemCollector.getValueList(itemNos); - List<IndItemValueDTO> list = data.get(dto.getPointCode()); - if (CollectionUtils.isEmpty(list)) { - return result; - } - list.forEach(item -> { - BigDecimal dv = null; - ApiDataDTO entity = new ApiDataDTO(); - entity.setDataTime(item.getDataTime()); - entity.setDataValue(item.getDataValue() == null ? 0 : item.getDataValue().doubleValue()); - result.add(entity); - }); - return result; - } - - @Override - public List<ApiIndValueDTO> getIndItemValues(FeignQueryPointDTO dto) { - List<ApiIndValueDTO> result = new ArrayList<>(); - List<String> itemNos = new ArrayList<>(); - itemNos.add(dto.getPointCode()); - Map<String, List<IndItemValueDTO>> data = indItemCollector.getValueList(itemNos); - List<IndItemValueDTO> list = data.get(dto.getPointCode()); - if (CollectionUtils.isEmpty(list)) { - return result; - } - list.forEach(item -> { - BigDecimal dv = null; - ApiIndValueDTO entity = new ApiIndValueDTO(); - entity.setDataTime(item.getDataTime()); - entity.setDataValue(item.getDataValue()); - result.add(entity); - }); - return result; - } - - @Override - public List<ApiIndValueDTO> queryIndItemValuesRange(FeignQueryPointDTO dto) { - List<ApiIndValueDTO> result = new ArrayList<>(); - List<String> itemNos = new ArrayList<>(); - itemNos.add(dto.getPointCode()); - Map<String, List<IndItemValueDTO>> data = new HashMap<>(); - if (StringUtils.isBlank(dto.getStartDate()) && StringUtils.isBlank(dto.getEndDate())) { - data = indItemCollector.getValueList(itemNos); - } else { - if (dto.getStartDate() == null) { - dto.setStartDate(DateUtils.format(new Date())); - } - if (dto.getEndDate() == null) { - dto.setEndDate(DateUtils.format(new Date())); - } - data = indItemCollector.getValueListRange(itemNos, dto.getStartDate(), dto.getEndDate()); - } - List<IndItemValueDTO> list = data.get(dto.getPointCode()); - if (CollectionUtils.isEmpty(list)) { - return result; - } - list.forEach(item -> { - BigDecimal dv = null; - ApiIndValueDTO entity = new ApiIndValueDTO(); - entity.setDataTime(item.getDataTime()); - entity.setDataValue(item.getDataValue()); - result.add(entity); - }); - return result; - } - - @Override - public FeignResultDTO setPointValue(FeignWritePointValueDTO writePointValue) { - FeignResultDTO result = new FeignResultDTO(); - try { - DaPointWriteValueDTO wr = new DaPointWriteValueDTO(); - wr.setPointNo(writePointValue.getPointCode()); - wr.setPointValue(writePointValue.getPointValue()); - pointCollector.setValue(wr); - result.setCode(0); - result.setMsg(""); - } catch (Exception ex) { - result.setCode(-1); - result.setMsg(ex.getMessage()); - } - return result; - } -} diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/framework/filter/MyFilter.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/framework/filter/MyFilter.java deleted file mode 100644 index 1fb6d26..0000000 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/framework/filter/MyFilter.java +++ /dev/null @@ -1,31 +0,0 @@ -//package com.iailab.module.data.framework.filter; -// -//import org.apache.logging.log4j.LogManager; -//import org.apache.logging.log4j.Logger; -//import org.springframework.stereotype.Component; -// -//import javax.servlet.*; -//import javax.servlet.http.HttpServletRequest; -//import java.io.IOException; -// -//public class MyFilter implements Filter { -// -// private static final Logger LOGGER = LogManager.getLogger(LogManager.ROOT_LOGGER_NAME); -// -// @Override -// public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { -// LOGGER.info("过滤器filter3开始 doFilter"); -// ServletRequest requestWrapper = null; -// if(request instanceof HttpServletRequest) { -// requestWrapper = new MyHttpServletRequestWrapper((HttpServletRequest) request); -// } -// //获取请求中的流如何,将取出来的字符串,再次转换成流,然后把它放入到新request对象中。 -// // 在chain.doFiler方法中传递新的request对象 -// if(requestWrapper == null) { -// -// chain.doFilter(request, response); -// } else { -// chain.doFilter(requestWrapper, response); -// } -// } -//} diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/framework/filter/MyHttpServletRequestWrapper.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/framework/filter/MyHttpServletRequestWrapper.java deleted file mode 100644 index ee33943..0000000 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/framework/filter/MyHttpServletRequestWrapper.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.iailab.module.data.framework.filter; - -import groovy.util.logging.Slf4j; -import lombok.Getter; - -import javax.servlet.ReadListener; -import javax.servlet.ServletInputStream; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletRequestWrapper; -import java.io.BufferedReader; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStreamReader; - -@Slf4j -@Getter -public class MyHttpServletRequestWrapper extends HttpServletRequestWrapper { - /** 复制请求body */ - private final String body; - - public MyHttpServletRequestWrapper (HttpServletRequest request) { - super(request); - try { - //设置编码格式, 防止中文乱码 - request.setCharacterEncoding("UTF-8"); - //将请求中的流取出来放到body里,后面都只操作body就行 - this.body = RequestReadUtils.read(request); - } catch (Exception e) { - throw new RuntimeException("MyHttpServletRequestWrapper 拦截器异常"); - } - } - - @Override - public ServletInputStream getInputStream() { - //返回body的流信息即可 - try(final ByteArrayInputStream bais = new ByteArrayInputStream(body.getBytes())){ - return getServletInputStream(bais); - }catch(IOException e){ - throw new RuntimeException("MyHttpServletRequestWrapper 获取input流异常"); - } - } - - @Override - public BufferedReader getReader(){ - return new BufferedReader(new InputStreamReader(this.getInputStream())); - } - - /** - * 重写getInputStream流 - * @param bais - * @return - */ - private static ServletInputStream getServletInputStream(ByteArrayInputStream bais) { - return new ServletInputStream() { - @Override - public boolean isFinished() { - return false; - } - - @Override - public boolean isReady() { - return false; - } - - @Override - public void setReadListener(ReadListener readListener) { - } - @Override - public int read() { - return bais.read(); - } - }; - } -} \ No newline at end of file diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/framework/filter/RequestReadUtils.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/framework/filter/RequestReadUtils.java deleted file mode 100644 index da35579..0000000 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/framework/filter/RequestReadUtils.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.iailab.module.data.framework.filter; - -import groovy.util.logging.Slf4j; - -import javax.servlet.http.HttpServletRequest; -import java.io.BufferedReader; - -@Slf4j -public class RequestReadUtils { - /** - * 读取请求流 - * @param request - * @return - */ - public static String read(HttpServletRequest request){ - try(BufferedReader reader = request.getReader()){ - StringBuilder sb = new StringBuilder(); - String line; - while ((line = reader.readLine()) != null) { - sb.append(line); - } - return sb.toString(); - }catch (Exception e){ - throw new RuntimeException("MyHttpServletRequestWrapper.RequestReadUtils.read 获取请求流异常"); - } - } -} \ No newline at end of file diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/framework/filter/RewriteRequestFilter.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/framework/filter/RewriteRequestFilter.java deleted file mode 100644 index c132da9..0000000 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/framework/filter/RewriteRequestFilter.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.iailab.module.data.framework.filter; - -import org.apache.commons.lang3.StringUtils; -import org.springframework.core.annotation.Order; -import org.springframework.stereotype.Component; - -import javax.servlet.*; -import javax.servlet.annotation.WebFilter; -import javax.servlet.http.HttpServletRequest; -import java.io.IOException; -import java.util.Objects; -import java.util.Optional; - -@Component -@WebFilter(filterName = "RewriteRequestFilter", urlPatterns = "/*") -@Order(1) -public class RewriteRequestFilter implements Filter { - - @Override - public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { - //文件上传类型 不需要处理,否则会报java.nio.charset.MalformedInputException: Input length = 1异常 - if (Objects.isNull(request) || Optional.ofNullable(request.getContentType()).orElse(StringUtils.EMPTY).startsWith("multipart/")) { - chain.doFilter(request, response); - return; - } - //自定义wrapper 处理流,必须在过滤器中处理,然后通过FilterChain传下去, 否则重写后的getInputStream()方法不会被调用 - MyHttpServletRequestWrapper requestWrapper = new MyHttpServletRequestWrapper((HttpServletRequest)request); - chain.doFilter(requestWrapper,response); - } -} \ No newline at end of file diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/framework/interceptor/CommonData.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/framework/interceptor/CommonData.java deleted file mode 100644 index eb2d934..0000000 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/framework/interceptor/CommonData.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.iailab.module.data.framework.interceptor; - -import lombok.Getter; -import lombok.Setter; -import lombok.extern.slf4j.Slf4j; - -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; - -@Slf4j -@Getter -@Setter -public class CommonData { - private static ThreadLocal<Map<String, Object>> threadLocal = new ThreadLocal<>(); - - /** - * 添加数据 - * @param key - * @param value - */ - public static void set(String key, Object value) { - if (threadLocal.get() == null) { - Map<String, Object> map = new HashMap<>(); - threadLocal.set(map); - } - threadLocal.get().put(key, value); - } - - - /** - * 清除数据 - */ - public static void clearAll() { - threadLocal.set(null); - } - - - public static Map<String, Object> getSignParam() { - Object o = threadLocal.get().get("param"); - if (Objects.isNull(o)) { - log.info("CommonData.getSignParam is null"); - return null; - } - return (Map<String, Object>) o; - } -} \ No newline at end of file diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/framework/interceptor/WebMvcConfig.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/framework/interceptor/WebMvcConfig.java deleted file mode 100644 index c423599..0000000 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/framework/interceptor/WebMvcConfig.java +++ /dev/null @@ -1,22 +0,0 @@ -//package com.iailab.module.data.framework.interceptor; -// -//import com.iailab.module.data.framework.filter.MyFilter; -//import org.springframework.boot.web.servlet.FilterRegistrationBean; -//import org.springframework.context.annotation.Bean; -//import org.springframework.context.annotation.Configuration; -//import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; -// -//@Configuration -//public class WebMvcConfig implements WebMvcConfigurer { -// -// @Bean -// public FilterRegistrationBean httpServletRequestReplacedFilter() { -// FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(); -// filterRegistrationBean.setFilter(new MyFilter()); -// filterRegistrationBean.addUrlPatterns("/*"); -// filterRegistrationBean.setName("myFilter"); -// filterRegistrationBean.setOrder(1); -// return filterRegistrationBean; -// } -// -//} diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/framework/package-info.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/framework/package-info.java deleted file mode 100644 index 843bf56..0000000 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/framework/package-info.java +++ /dev/null @@ -1,6 +0,0 @@ -/** - * 属于 infra 模块的 framework 封装 - * - * @author iailab - */ -package com.iailab.module.data.framework; diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/framework/rpc/config/RpcConfiguration.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/framework/rpc/config/RpcConfiguration.java deleted file mode 100644 index 8bee8c9..0000000 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/framework/rpc/config/RpcConfiguration.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.iailab.module.data.framework.rpc.config; - -import com.iailab.api.IFeignModelApi; -import com.iailab.api.IFeignProddispApi; -import com.iailab.module.infra.api.config.ConfigApi; -import com.iailab.module.system.api.permission.RoleApi; -import com.iailab.module.system.api.user.AdminUserApi; -import org.springframework.cloud.openfeign.EnableFeignClients; -import org.springframework.context.annotation.Configuration; - -@Configuration(proxyBeanMethods = false) -@EnableFeignClients(clients = {IFeignModelApi.class, AdminUserApi.class, RoleApi.class, IFeignProddispApi.class, ConfigApi.class}) -public class RpcConfiguration { -} diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/framework/rpc/package-info.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/framework/rpc/package-info.java deleted file mode 100644 index 804e4d1..0000000 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/framework/rpc/package-info.java +++ /dev/null @@ -1,4 +0,0 @@ -/** - * 占位 - */ -package com.iailab.module.data.framework.rpc; diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/framework/security/config/SecurityConfiguration.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/framework/security/config/SecurityConfiguration.java deleted file mode 100644 index a9883af..0000000 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/framework/security/config/SecurityConfiguration.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.iailab.module.data.framework.security.config; - -import com.iailab.framework.security.config.AuthorizeRequestsCustomizer; -import com.iailab.module.data.enums.ApiConstants; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.security.config.annotation.web.builders.HttpSecurity; -import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer; - -/** - * data 模块的 Security 配置 - */ -@Configuration(proxyBeanMethods = false, value = "dataSecurityConfiguration") -public class SecurityConfiguration { - - @Value("${spring.boot.admin.context-path:''}") - private String adminSeverContextPath; - - @Bean("infraAuthorizeRequestsCustomizer") - public AuthorizeRequestsCustomizer authorizeRequestsCustomizer() { - return new AuthorizeRequestsCustomizer() { - - @Override - public void customize(ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry registry) { - // Swagger 接口文档 - registry.antMatchers("/v3/api-docs/**").permitAll() // 元数据 - .antMatchers("/swagger-ui.html").permitAll(); // Swagger UI - // Spring Boot Actuator 的安全配置 - registry.antMatchers("/actuator").anonymous() - .antMatchers("/actuator/**").anonymous(); - // Druid 监控 - registry.antMatchers("/druid/**").anonymous(); - // Spring Boot Admin Server 的安全配置 - registry.antMatchers(adminSeverContextPath).anonymous() - .antMatchers(adminSeverContextPath + "/**").anonymous(); - // 文件读取 - registry.antMatchers(buildAdminApi("/data/point/**")).permitAll(); - - // TODO iailab:这个每个项目都需要重复配置,得捉摸有没通用的方案 - // RPC 服务的安全配置 - registry.antMatchers(ApiConstants.PREFIX + "/**").permitAll(); - } - - }; - } - -} diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/framework/security/core/package-info.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/framework/security/core/package-info.java deleted file mode 100644 index a90b23c..0000000 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/framework/security/core/package-info.java +++ /dev/null @@ -1,4 +0,0 @@ -/** - * 占位 - */ -package com.iailab.module.data.framework.security.core; diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/http/collector/HttpCollectorForSD.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/http/collector/HttpCollectorForSD.java deleted file mode 100644 index 9602de5..0000000 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/http/collector/HttpCollectorForSD.java +++ /dev/null @@ -1,187 +0,0 @@ -package com.iailab.module.data.http.collector; - -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.iailab.module.data.common.utils.HttpsRequest; -import com.iailab.api.IFeignModelApi; -import com.iailab.module.data.http.entity.HttpApiEntity; -import com.iailab.module.data.http.service.HttpTokenService; -import com.iailab.module.data.http.service.HttpApiService; -import com.iailab.module.data.http.service.HttpTagService; -import com.iailab.module.data.influxdb.service.InfluxDBService; -import lombok.extern.slf4j.Slf4j; -import javax.annotation.Resource; -import org.springframework.stereotype.Component; -import org.springframework.util.CollectionUtils; - -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * 山大设备数据采集 - * - * @author lirm - * @Description - * @createTime 2024年05月21日 - */ -@Slf4j -@Component -public class HttpCollectorForSD { - - @Resource - private HttpApiService httpApiService; - - @Resource - private HttpTagService httpTagService; - - @Resource - HttpTokenService httpTokenService; - @Resource - HttpsRequest httpsRequest; - - @Resource - private IFeignModelApi feignModelApi; - - @Resource - private InfluxDBService influxDBService; - - public void getRunStateValue(Map<String, String> tMap) { - Map<String, Integer> monitorCountMap = new HashMap<>(); - HttpApiEntity httpApi = httpApiService.getByCode(tMap.get("code")); - String token = httpTokenService.queryToken(tMap.get("client_id")); - Map<String, String> queryParams = new HashMap<>(); - queryParams.put("cu_ids", tMap.get("cu_ids")); - queryParams.put("t", tMap.get("t")); - String responseStr = httpsRequest.doGetSDData(httpApi.getUrl(), queryParams, "utf-8", token, tMap); - JSONObject responseObj = JSON.parseObject(responseStr); - if ("0".equals(responseObj.get("code").toString())) { - JSONObject dataObject = (JSONObject) responseObj.get("data"); - - JSONArray hasSensorArray = dataObject.getJSONArray("has_sensor"); - if (!CollectionUtils.isEmpty(hasSensorArray)) { - for (int i = 0; i < hasSensorArray.size(); i++) { - JSONObject item = hasSensorArray.getJSONObject(i); - String value = item.get("de_has_sensor").toString(); - if ("yes".equals(value)) { - monitorCountMap.put("total_count", Integer.parseInt(item.get("count").toString()));//在线监控设备数量 - } - } - } - JSONArray stateArray = dataObject.getJSONArray("state"); - if (!CollectionUtils.isEmpty(stateArray)) { - monitorCountMap.put("offline_count", 0); - monitorCountMap.put("halt_count", 0); - monitorCountMap.put("run_count", 0); - for (int i = 0; i < stateArray.size(); i++) { - JSONObject item = stateArray.getJSONObject(i); - String value = item.get("device_state").toString(); - if ("0".equals(value)) { - monitorCountMap.put("offline_count", Integer.parseInt(item.get("count").toString()));//离线设备数量 - } else if ("1".equals(value)) { - monitorCountMap.put("halt_count", Integer.parseInt(item.get("count").toString()));//停机设备数量 - } else if ("2".equals(value)) { - monitorCountMap.put("run_count", Integer.parseInt(item.get("count").toString()));//运行设备数量 - } - } - } - if (!monitorCountMap.isEmpty()) { - feignModelApi.insertRunState(monitorCountMap); - } - } - } - - public void getHealthStateValue(Map<String, String> tMap) { - Map<String, Object> monitorCountMap = new HashMap<>(); - HttpApiEntity httpApi = httpApiService.getByCode(tMap.get("code")); - String token = httpTokenService.queryToken(tMap.get("client_id")); - Map<String, String> queryParams = new HashMap<>(); - queryParams.put("cu_ids", tMap.get("cu_ids")); - queryParams.put("t", tMap.get("t")); - String responseStr = httpsRequest.doGetSDData(httpApi.getUrl(), queryParams, "utf-8", token, tMap); - JSONObject responseObj = JSON.parseObject(responseStr); - if ("0".equals(responseObj.get("code").toString())) { - JSONArray hasSensorArray = responseObj.getJSONArray("data"); - if (!CollectionUtils.isEmpty(hasSensorArray)) { - for (int i = 0; i < hasSensorArray.size(); i++) { - JSONObject item = hasSensorArray.getJSONObject(i); - String value = item.get("fault_level").toString(); - if ("0".equals(value)) { - monitorCountMap.put("normal", item.get("count"));//正常 - } else if ("1".equals(value)) { - monitorCountMap.put("common", item.get("count"));//一般 - } else if ("2".equals(value)) { - monitorCountMap.put("heavy", item.get("count"));//较重 - } else if ("3".equals(value)) { - monitorCountMap.put("serious", item.get("count"));//严重 - } else if ("4".equals(value)) { - monitorCountMap.put("espSerious", item.get("count"));//特别严重 - } - } - } - if (!monitorCountMap.isEmpty()) { - feignModelApi.insertHealthState(monitorCountMap); - } - } - } - - public void getDeviceList(Map<String, String> tMap) { - HttpApiEntity httpApi = httpApiService.getByCode(tMap.get("code")); - tMap.put("url", httpApi.getUrl()); - - feignModelApi.insertDeviceList(tMap); - } - - public void getTemperatureValue(Map<String, String> tMap, Date date) { - Map<String, Object> monitorCountMap = new HashMap<>(); - HttpApiEntity httpApi = httpApiService.getByCode(tMap.get("code")); - String token = httpTokenService.queryToken(tMap.get("client_id")); - List<String> deviceIdList = feignModelApi.getDeviceIdList(); - if (!CollectionUtils.isEmpty(deviceIdList)) { - for (String deviceId : deviceIdList) { - List<String> tagNoList = httpTagService.getByTagType(deviceId); - if (CollectionUtils.isEmpty(tagNoList)) { - continue; - } - StringBuffer sb = new StringBuffer(); - sb.append(httpApi.getUrl()); - sb.append("/"); - sb.append(deviceId); - Map<String, String> queryParams = new HashMap<>(); - String responseStr = httpsRequest.doGetSDData(sb.toString(), queryParams, "utf-8", token, tMap); - JSONObject responseObj = JSON.parseObject(responseStr); - if ("200".equals(responseObj.get("status").toString())) { - JSONObject dataObject = (JSONObject) responseObj.get("data"); - JSONArray jsonArray = dataObject.getJSONArray("realtime-params"); - if (!CollectionUtils.isEmpty(jsonArray)) { - for (int i = 0; i < jsonArray.size(); i++) { - JSONObject item = jsonArray.getJSONObject(i); - String order = item.get("cp_order").toString(); - String name = item.get("param_name").toString(); - if ("1".equals(order) && "温度".equals(name)) { - for (String tagCode : tagNoList) { - String value = item.get("last_value").toString(); - // Date date = DateUtils.parse(item.get("last_time").toString(),"yyyy-MM-dd HH:mm:ss"); - if (tagCode.contains("Temperature")) { - influxDBService.syncWriteFloatValue(tagCode, value, date.getTime()); - } - } - } - if ("1".equals(order) && "1倍频振幅".equals(name)) { - for (String tagCode : tagNoList) { - String value = item.get("last_value").toString(); - // Date date = DateUtils.parse(item.get("last_time").toString(),"yyyy-MM-dd HH:mm:ss"); - if (tagCode.contains("Flutter")) { - influxDBService.syncWriteFloatValue(tagCode, value, date.getTime()); - } - } - } - } - } - } - } - } - } -} \ No newline at end of file diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/http/collector/HttpCollectorForUser.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/http/collector/HttpCollectorForUser.java deleted file mode 100644 index a12a0d4..0000000 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/http/collector/HttpCollectorForUser.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.iailab.module.data.http.collector; - -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.iailab.module.data.common.utils.HttpsRequest; -import com.iailab.module.data.http.entity.HttpApiEntity; -import com.iailab.module.data.http.service.HttpApiService; -import com.iailab.module.system.api.permission.RoleApi; -import com.iailab.module.system.api.permission.dto.RoleDTO; -import com.iailab.module.system.api.user.AdminUserApi; -import com.iailab.module.system.api.user.dto.AdminUserRespDTO; -import lombok.extern.slf4j.Slf4j; -import javax.annotation.Resource; -import org.springframework.stereotype.Component; - -import java.util.*; - -/** - * 山大设备数据采集 - * - * @author lirm - * @Description - * @createTime 2024年05月21日 - */ -@Slf4j -@Component -public class HttpCollectorForUser { - - @Resource - private HttpApiService httpApiService; - - @Resource - HttpsRequest httpsRequest; - - @Resource - private AdminUserApi adminUserApi; - - @Resource - private RoleApi roleApi; - - public void saveJobInfo(Map<String, String> tMap) { - HttpApiEntity httpApi = httpApiService.getByCode(tMap.get("code")); - String responseStr = httpsRequest.doGet(httpApi.getUrl(), null, "utf-8", ""); - log.info("JobInfo responseStr:" + responseStr); - JSONObject responseObj = JSON.parseObject(responseStr); - if ("true".equals(responseObj.get("sta").toString())) { - JSONArray jsonArray = responseObj.getJSONArray("res"); - for (int i = 0; i < jsonArray.size(); i++) { - JSONObject jsonObject = jsonArray.getJSONObject(i); - RoleDTO role = new RoleDTO(); - role.setName(jsonObject.getString("name")); - role.setUpdateDate(new Date()); - log.info("同步保存的角色名称为:" + role.getName()); - roleApi.saveRoleInfo(role); - } - } - - } - public void saveUserInfo(Map<String, String> tMap) { - HttpApiEntity httpApi = httpApiService.getByCode(tMap.get("code")); - String responseStr = httpsRequest.doGet(httpApi.getUrl(), null, "utf-8", ""); - log.info("responseStr:" + responseStr); - JSONObject responseObj = JSON.parseObject(responseStr); - if ("true".equals(responseObj.get("sta").toString())) { - JSONArray jsonArray = responseObj.getJSONArray("res"); - for (int i = 0; i < jsonArray.size(); i++) { - JSONObject jsonObject = jsonArray.getJSONObject(i); - AdminUserRespDTO sysUser = new AdminUserRespDTO(); - sysUser.setUsername(jsonObject.getString("no")); - sysUser.setNickname(jsonObject.getString("name")); - sysUser.setMobile(jsonObject.getString("phone")); - sysUser.setStatus(1); - //添加用户角色 - RoleDTO role = roleApi.getRoleByName(jsonObject.getString("job")); - Set<Long> roleIdList = new HashSet<>(); - roleIdList.add(role.getId()); - //为用户添加默认角色 - roleIdList.add(2L); - sysUser.setRoleIdList(roleIdList); - adminUserApi.saveOrUpdateUserInfo(sysUser); - } - } - } -} \ No newline at end of file diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/http/dao/EleLowTagDao.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/http/dao/EleLowTagDao.java deleted file mode 100644 index 3fe1b57..0000000 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/http/dao/EleLowTagDao.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.iailab.module.data.http.dao; - -import com.iailab.framework.common.dao.BaseDao; -import com.iailab.module.data.http.entity.EleLowTagEntity; -import org.apache.ibatis.annotations.Mapper; - -/** - * @author PanZhibao - * @Description - * @createTime 2023年12月19日 08:35:00 - */ -@Mapper -public interface EleLowTagDao extends BaseDao<EleLowTagEntity> { -} diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/http/dao/FxjyTagDao.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/http/dao/FxjyTagDao.java deleted file mode 100644 index bcfabae..0000000 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/http/dao/FxjyTagDao.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.iailab.module.data.http.dao; - -import com.iailab.framework.common.dao.BaseDao; -import com.iailab.module.data.http.entity.FxjyTagEntity; -import org.apache.ibatis.annotations.Mapper; - -/** - * @author DongYukun - * @Description - * @createTime 2024年01月17日 13:13:00 - */ -@Mapper -public interface FxjyTagDao extends BaseDao<FxjyTagEntity> { -} diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/http/dao/HttpApiDao.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/http/dao/HttpApiDao.java index 7db6b0f..80a5bec 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/http/dao/HttpApiDao.java +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/http/dao/HttpApiDao.java @@ -2,7 +2,6 @@ import com.iailab.framework.common.dao.BaseDao; import com.iailab.module.data.http.entity.HttpApiEntity; -import com.iailab.module.data.http.entity.HttpApiEntity; import org.apache.ibatis.annotations.Mapper; @Mapper diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/http/dao/XSTTagDao.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/http/dao/XSTTagDao.java deleted file mode 100644 index a0920e2..0000000 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/http/dao/XSTTagDao.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.iailab.module.data.http.dao; - -import com.iailab.framework.common.dao.BaseDao; -import com.iailab.module.data.http.entity.XSTTagEntity; -import com.iailab.module.data.http.entity.XSTTagEntity; -import org.apache.ibatis.annotations.Mapper; - -@Mapper -public interface XSTTagDao extends BaseDao<XSTTagEntity> { - -} diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/http/dto/TokenJsonDto.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/http/dto/TokenJsonDto.java deleted file mode 100644 index 061885d..0000000 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/http/dto/TokenJsonDto.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.iailab.module.data.http.dto; - -import lombok.Data; - -import java.io.Serializable; -import java.util.Map; - -@Data -public class TokenJsonDto implements Serializable { - - private Map<String,String> result; - private String targetUrl; - private String success; - private String error; - private String unAuthorizedRequest; - private String __abp; -} diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/http/service/HttpTagService.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/http/service/HttpTagService.java index 0769aff..e3bec59 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/http/service/HttpTagService.java +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/http/service/HttpTagService.java @@ -22,11 +22,7 @@ List<HttpTagEntity> selectList(Map<String, Object> params); - Map<String, BigDecimal> getTagsValues(String httpApiCode, List<TagCommonCurrentDto> tags); - List<HttpTagEntity> getByCode(String code); - - List<String> getByTagType(String deviceId); List<HttpTagDTO> list(Map<String, Object> params); } diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/http/service/impl/FxjyTagServiceImpl.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/http/service/impl/FxjyTagServiceImpl.java deleted file mode 100644 index e11f6a7..0000000 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/http/service/impl/FxjyTagServiceImpl.java +++ /dev/null @@ -1,238 +0,0 @@ -//package com.iailab.module.http.service.impl; -// -//import com.alibaba.fastjson.JSONObject; -//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -//import com.baomidou.mybatisplus.core.metadata.IPage; -//import com.baomidou.mybatisplus.core.toolkit.StringUtils; -//import com.iailab.framework.common.service.impl.BaseServiceImpl; -//import com.iailab.common.utils.HttpsRequest; -//import com.iailab.common.utils.PageUtils; -//import com.iailab.common.utils.Query; -//import com.iailab.module.http.dao.FxjyTagDao; -//import com.iailab.module.http.entity.FxjyTagEntity; -//import com.iailab.module.http.service.HttpApiService; -//import lombok.extern.slf4j.Slf4j; -//import javax.annotation.Resource; -//import org.springframework.stereotype.Service; -// -//import java.lang.reflect.Field; -//import java.math.BigDecimal; -//import java.util.HashMap; -//import java.util.List; -//import java.util.Map; -// -//@Slf4j -//@Service -//public class FxjyTagServiceImpl extends BaseServiceImpl<FxjyTagDao, FxjyTagEntity> implements FxjyTagService { -// -// @Resource -// private HttpsRequest httpsRequest; -// -// @Resource -// private HttpApiService httpApiService; -// -// private final String API_CODE = "fxjyHttpTag"; -// -// /** -// * 分页查询tag -// * -// * @param params -// */ -// @Override -// public PageUtils queryPage(Map<String, Object> params) { -// String tagType = (String) params.get("tagType"); -// String tagCode = (String) params.get("tagCode"); -// String tagName = (String) params.get("tagName"); -// -// IPage<FxjyTagEntity> page = baseDao.selectPage( -// new Query<FxjyTagEntity>().getPage(params), -// new QueryWrapper<FxjyTagEntity>() -// .like(StringUtils.isNotBlank(tagType), "tag_type", tagType) -// .like(StringUtils.isNotBlank(tagCode), "tag_code", tagCode) -// .like(StringUtils.isNotBlank(tagName), "tag_name", tagName) -// .orderByDesc("create_time") -// ); -// return new PageUtils(page); -// } -// -// @Override -// public Map<String, BigDecimal> getTagsValues(List<FxjyCurrentDto> tags){ -// Map<String, BigDecimal> result = new HashMap<>(tags.size()); -// Map<String, String> params = new HashMap<>(2); -// String url = httpApiService.getByCode(API_CODE).getUrl(); -//// String responseStr = httpsRequest.doGet(url, params,"utf-8", ""); -// String responseStr = "{\n" + -// "\"flag\":true,\n" + -// "\"data\":{\n" + -// "\"ST\":\"2024-01-1616:42:36\",\n" + -// "\"JYJ1\":{\n" + -// "\"CURRENT_SPEED\":199.17,\n" + -// "\"DL\":4.5,\n" + -// "\"CW\":false,\n" + -// "\"EN\":true,\n" + -// "\"FAULT\":false,\n" + -// "\"GL\":false,\n" + -// "\"GY\":false,\n" + -// "\"QY\":false,\n" + -// "\"RUNING\":true,\n" + -// "\"SPEED_SET\":200.0\n" + -// "},\n" + -// "\"JYJ2\":{\n" + -// "\"CURRENT_SPEED\":0.0,\n" + -// "\"DL\":1.8,\n" + -// "\"CW\":false,\n" + -// "\"EN\":true,\n" + -// "\"FAULT\":false,\n" + -// "\"GL\":false,\n" + -// "\"GY\":false,\n" + -// "\"QY\":false,\n" + -// "\"RUNING\":false,\n" + -// "\"SPEED_SET\":50.0\n" + -// "},\n" + -// "\"JYJ3\":{\n" + -// "\"CURRENT_SPEED\":199.17,\n" + -// "\"DL\":4.5,\n" + -// "\"CW\":false,\n" + -// "\"EN\":true,\n" + -// "\"FAULT\":false,\n" + -// "\"GL\":false,\n" + -// "\"GY\":false,\n" + -// "\"QY\":false,\n" + -// "\"RUNING\":true,\n" + -// "\"SPEED_SET\":200.0\n" + -// "},\n" + -// "\"JYJ4\":{\n" + -// "\"CURRENT_SPEED\":0.0,\n" + -// "\"DL\":1.8,\n" + -// "\"CW\":false,\n" + -// "\"EN\":true,\n" + -// "\"FAULT\":false,\n" + -// "\"GL\":false,\n" + -// "\"GY\":false,\n" + -// "\"QY\":false,\n" + -// "\"RUNING\":false,\n" + -// "\"SPEED_SET\":50.0\n" + -// "},\n" + -// "\"FXJY\":{\n" + -// "\"YW401\":5.49,\n" + -// "\"YW407\":66.83,\n" + -// "\"YW408\":19.92,\n" + -// "\"PumpRun_402A\":true,\n" + -// "\"PumpRun_402B\":true,\n" + -// "\"YCLQ_Run_403A\":true,\n" + -// "\"YCLQ_Run_403B\":true,\n" + -// "\"Valve1_GDW\":false,\n" + -// "\"Valve1_KDW\":true,\n" + -// "\"Valve1_ZZK\":false,\n" + -// "\"Valve1_ZZG\":false,\n" + -// "\"Valve2_GDW\":true,\n" + -// "\"Valve2_KDW\":false,\n" + -// "\"Valve2_ZZK\":false,\n" + -// "\"Valve2_ZZG\":false,\n" + -// "\"Valve3_GDW\":false,\n" + -// "\"Valve3_KDW\":true,\n" + -// "\"Valve3_ZZK\":false,\n" + -// "\"Valve3_ZZG\":false,\n" + -// "\"Valve4_GDW\":true,\n" + -// "\"Valve4_KDW\":false,\n" + -// " \"Valve4_ZZK\": false,\n" + -// "\"Valve4_ZZG\": false,\n" + -// "\"ZLLLJ1_403A\": 19.35,\n" + -// "\"ZLLLJ2_403A\": 2.73,\n" + -// "\"ZLLLJ1_403B\": 15.99,\n" + -// "\"ZLLLJ2_403B\": 5.19,\n" + -// "\"FXRL_LLJ_403A1\": 983.75,\n" + -// "\"FXRL_LLJ_403A2\": 583.91,\n" + -// "\"FXPMHDJC1\": 5.11,\n" + -// "\"FXPMHDJC2\": 1.95,\n" + -// "\"LD3_LD1\": 0.0,\n" + -// "\"LD3_LD2\": 0.0,\n" + -// "\"LD3_ND\": 0.0\n" + -// "},\n" + -// "\"YLXT\": {\n" + -// "\"YW405A\": 21.98,\n" + -// "\"YW405B\": 17.04,\n" + -// "\"YW601\": 33.79,\n" + -// "\"VF861_Run\": true,\n" + -// "\"VF862_Run\": true,\n" + -// "\"VF863_Run\": true,\n" + -// "\"KM414A_Run\": false,\n" + -// "\"KM414B_Run\": false,\n" + -// "\"KM418A_Run\": false,\n" + -// "\"KM418B_Run\": false,\n" + -// "\"KM602A_Run\": false,\n" + -// "\"KM602B_Run\": false,\n" + -// "\"KM602C_Run\": true,\n" + -// "\"KM416A_Run\": false,\n" + -// "\"KM416B_Run\": false,\n" + -// "\"KM420A_Run\": false,\n" + -// "\"KM420B_Run\": false,\n" + -// "\"KM606A_Run\": false,\n" + -// "\"KM606B_Run\": false,\n" + -// "\"KM606C_Run\": false\n" + -// "},\n" + -// "\"LJL\": {\n" + -// "\"Timestamp\": \"2024-01-16\",\n" + -// "\"JYJ1\": 120.53,\n" + -// "\"JYJ2\": 0.0,\n" + -// "\"JYJ3\": 117.66,\n" + -// "\"JYJ4\": 0.0\n" + -// "},\n" + -// "\"YCZ\": {\n" + -// "\"JYJ1\": 249.6,\n" + -// "\"JYJ2\": 0.0,\n" + -// "\"JYJ3\": 248.23,\n" + -// "\"JYJ4\": 0.0\n" + -// "},\n" + -// "\"YLCS\": {\n" + -// "\"YL415A_GLCSXS\": 7,\n" + -// "\"YL415B_GLCSXS\": 8,\n" + -// "\"YL419A_GLCSXS\": 7,\n" + -// "\"YL419B_GLCSXS\": 8,\n" + -// "\"YL603A_GLCSXS\": 1,\n" + -// "\"YL603B_GLCSXS\": 0,\n" + -// "\"YL603C_GLCSXS\": 3\n" + -// "},\n" + -// "\"TEMP\": {\n" + -// "\"FXRLNDJ403A\": 67.12\n" + -// "}\n" + -// "},\n" + -// "\"msg\": \"查询成功\"\n" + -// "}"; -// if (StringUtils.isNotBlank(responseStr)) { -// FxjyJsonDto fxjyJsonDto = parseDto(responseStr); -// fxjyJsonDto.getData().getLJL().getJYJ1(); -// tags.stream().forEach( -// item->{ -// Class<?> fxjyClass= fxjyJsonDto.getData().getClass(); -// try { -// Class<?> fxjyTypeClass = fxjyClass.getDeclaredField(item.getTagType()).getClass(); -// Field field = fxjyTypeClass.getDeclaredField(item.getTagCode()); -// field.setAccessible(true); -// BigDecimal value = new BigDecimal((String)field.get(fxjyJsonDto.getData())); -// result.put(item.getTagType()+"_"+item.getTagCode(), value); -// }catch (NoSuchFieldException e){ -// log.info("没有找到tag"+item.getTagType()+";"+item.getTagCode()); -// }catch(IllegalAccessException e){ -// log.info("没有反射权限"); -// } -// } -// ); -// } -// return result; -// } -// -// @Override -// public List<FxjyTagEntity> selectList() { -// return baseDao.selectList(new QueryWrapper<FxjyTagEntity>().orderByDesc("create_time")); -// } -// -// private FxjyJsonDto parseDto(String responseStr) { -// FxjyJsonDto result = new FxjyJsonDto(); -// if (!org.apache.commons.lang.StringUtils.isEmpty(responseStr)) { -// JSONObject items = JSONObject.parseObject(responseStr); -// result = items.toJavaObject(FxjyJsonDto.class); -// } -// return result; -// } -//} diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/http/service/impl/HttpTagCollector.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/http/service/impl/HttpTagCollector.java deleted file mode 100644 index 1a22110..0000000 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/http/service/impl/HttpTagCollector.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.iailab.module.data.http.service.impl; - -import com.iailab.module.data.http.dto.TagCommonCurrentDto; -import com.iailab.module.data.http.service.HttpTagService; -import javax.annotation.Resource; -import org.springframework.stereotype.Component; -import org.springframework.util.CollectionUtils; - -import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -@Component -public class HttpTagCollector { - - @Resource - private HttpTagService httpTagService; - - - public Map<String, Object> collect(String httpApiCode, List<String> tagIds) { - Map<String, Object> result = new HashMap<>(); - if (CollectionUtils.isEmpty(tagIds)) { - return null; - } - List<TagCommonCurrentDto> tags = new ArrayList<>(); - for (String tagId : tagIds) { - String[] parts = tagId.split("_"); - TagCommonCurrentDto dto=new TagCommonCurrentDto(); - dto.setTagType(parts[0]); - dto.setTagCode(tagId); - tags.add(dto); - } - Map<String, BigDecimal> tagsValues = httpTagService.getTagsValues(httpApiCode, tags); - if (!CollectionUtils.isEmpty(tagsValues)) { - tagsValues.forEach((k, v) -> { - result.put(k, v); - }); - } - return result; - } - -} diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/http/service/impl/HttpTagServiceImpl.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/http/service/impl/HttpTagServiceImpl.java index f984e1e..461e014 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/http/service/impl/HttpTagServiceImpl.java +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/http/service/impl/HttpTagServiceImpl.java @@ -81,224 +81,8 @@ } @Override - public List<String> getByTagType(String deviceId) { - QueryWrapper<HttpTagEntity> queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("tag_type", deviceId); - List<HttpTagEntity> entityList = baseDao.selectList(queryWrapper); - List<String> list = new ArrayList<>(); - if(ObjectUtils.isNotEmpty(entityList)) { - entityList.stream().forEach(entity -> { - String tagCode = entity.getTagCode(); - list.add(tagCode); - }); - } - return list; - } - - @Override public List<HttpTagDTO> list(Map<String, Object> params) { List<HttpTagDTO> list = baseDao.getList(params); return list; - } - - @Override - public Map<String, BigDecimal> getTagsValues(String httpApiCode, List<TagCommonCurrentDto> tags) { - Map<String, BigDecimal> stringBigDecimalMap = new HashMap<>(); - if (CommonConstant.YEAR_PEI_HTTP_TAG.equals(httpApiCode)) { - stringBigDecimalMap = yearPeiTagsValues(tags); - } else if(CommonConstant.CURRENT_PERFORMANCE_HTTP_TAG.equals(httpApiCode)) { - stringBigDecimalMap = currentPerformanceTagsValues(tags); - } else if(CommonConstant.CURRENT_SALE_HTTP_TAG.equals(httpApiCode)) { - stringBigDecimalMap = currentSaleTagsValues(tags); - } else if(CommonConstant.PRD_TIME_DIST_HTTP_TAG.equals(httpApiCode)) { - stringBigDecimalMap = prdTimeDistTagsValues(tags); - } - return stringBigDecimalMap; - } - - private Map<String, BigDecimal> yearPeiTagsValues(List<TagCommonCurrentDto> tags) { - Map<String, BigDecimal> result = new HashMap<>(tags.size()); - Calendar calendar = Calendar.getInstance(); - int currentMonth = calendar.get(Calendar.MONTH) + 1; -// String url = httpApiService.getByCode(API_CODE).getUrl(); -// String responseStr = httpsRequest.doGet(url, params,"utf-8", ""); - String url = "http://192.168.55.121/Sunny/Action/BdApi/Invoke?code=Prd.YearPEI"; - String responseStr = "{\"sta\":true,\"msg\":null,\"res\":{\"yearData\":{\"year\":2024,\"xxPlan\":21850000.00,\"xxPerformance\":6794492.00,\"zqPlan\":12500000.00,\"zqPerformance\":3149110.41},\"monthData\":[{\"month\":1,\"xxPlan\":1400000.00,\"xxPerformance\":2022725.00,\"zqPlan\":800000.00,\"zqPerformance\":955066.76},{\"month\":2,\"xxPlan\":1400000.00,\"xxPerformance\":1829671.00,\"zqPlan\":800000.00,\"zqPerformance\":809494.02},{\"month\":3,\"xxPlan\":1700000.00,\"xxPerformance\":2225923.00,\"zqPlan\":1000000.00,\"zqPerformance\":971406.22},{\"month\":4,\"xxPlan\":1620000.00,\"xxPerformance\":716173.00,\"zqPlan\":1000000.00,\"zqPerformance\":345324.75},{\"month\":5,\"xxPlan\":0.0,\"xxPerformance\":0.00,\"zqPlan\":0.0,\"zqPerformance\":0.0},{\"month\":6,\"xxPlan\":0.0,\"xxPerformance\":0.0,\"zqPlan\":0.0,\"zqPerformance\":0.0},{\"month\":7,\"xxPlan\":0.0,\"xxPerformance\":0.0,\"zqPlan\":0.0,\"zqPerformance\":0.0},{\"month\":8,\"xxPlan\":0.0,\"xxPerformance\":0.0,\"zqPlan\":0.0,\"zqPerformance\":0.0},{\"month\":9,\"xxPlan\":0.0,\"xxPerformance\":0.0,\"zqPlan\":0.0,\"zqPerformance\":0.0},{\"month\":10,\"xxPlan\":0.0,\"xxPerformance\":0.0,\"zqPlan\":0.0,\"zqPerformance\":0.0},{\"month\":11,\"xxPlan\":0.0,\"xxPerformance\":0.0,\"zqPlan\":0.0,\"zqPerformance\":0.0},{\"month\":12,\"xxPlan\":0.0,\"xxPerformance\":0.0,\"zqPlan\":0.0,\"zqPerformance\":0.0}]}}"; - if (StringUtils.isNotBlank(responseStr)) { - TagYearPeiJsonDto yearPeiJsonDto = parseYearPeiDto(responseStr); - tags.stream().forEach( - item -> { - String tagType = item.getTagType(); - String tagCode = item.getTagCode().split(CommonConstant.UNDERLINE)[1]; - TagYearPeiJsonDto.DATA res = yearPeiJsonDto.getRes(); - TagYearPeiJsonDto.DATA.YEAR yearData = res.getYearData(); - List<TagYearPeiJsonDto.DATA.MONTH> monthDataList = res.getMonthData(); - TagYearPeiJsonDto.DATA.MONTH month = monthDataList.get(currentMonth - 1); - Class<?> yearPeiClass = res.getClass(); - String name = yearPeiClass.getName(); - try { - BigDecimal value; - Class<?> yearPeiTypeClass1 = Class.forName(name + CommonConstant.DOLLAR + tagType.toUpperCase()); - Field field = yearPeiTypeClass1.getDeclaredField(tagCode); - field.setAccessible(true); - if(CommonConstant.YEAR.equals(tagType)){ - value = new BigDecimal((String) field.get(yearData)); - result.put(item.getTagCode(), value); - } else if(CommonConstant.MONTH.equals(tagType)){ - value = new BigDecimal((String) field.get(month)); - result.put(item.getTagCode(), value); - } - } catch (NoSuchFieldException e) { - log.info("没有找到tag" + item.getTagType() + ";" + item.getTagCode()); - } catch (IllegalAccessException e) { - log.info("没有反射权限"); - } catch (ClassNotFoundException e) { - throw new RuntimeException(e); - } - } - ); - } - return result; - } - - private Map<String, BigDecimal> currentPerformanceTagsValues(List<TagCommonCurrentDto> tags) { - Map<String, BigDecimal> result = new HashMap<>(tags.size()); - Map<String, String> params = new HashMap<>(2); -// String url = httpApiService.getByCode(API_CODE).getUrl(); -// String responseStr = httpsRequest.doGet(url, params,"utf-8", ""); - String responseStr = "{\"sta\":true,\"msg\":null,\"res\":{\"today\":{\"xxPerformance\":30866.00,\"zqPerformance\":0.0},\"yesterday\":{\"xxPerformance\":65748.00,\"zqPerformance\":36263.20},\"currentMonth\":{\"xxPerformance\":716173.00,\"zqPerformance\":345324.75},\"currentYear\":{\"xxPerformance\":6794492.00,\"zqPerformance\":3149110.41}}}"; - if (StringUtils.isNotBlank(responseStr)) { - TagCurrentPerformanceJsonDto currentPerformanceJsonDto = parseCurrentPerformanceDto(responseStr); - tags.stream().forEach( - item -> { - String tagType = item.getTagType(); - String tagCode = item.getTagCode().split(CommonConstant.UNDERLINE)[1]; - Class<?> currentPerformanceClass = currentPerformanceJsonDto.getRes().getClass(); - String name = currentPerformanceClass.getName(); - try { - Field declaredField = currentPerformanceClass.getDeclaredField(tagType); - Class<?> typeClass = Class.forName(name + CommonConstant.DOLLAR + tagType.toUpperCase()); - Field field = typeClass.getDeclaredField(tagCode); - field.setAccessible(true); - declaredField.setAccessible(true); - BigDecimal value = new BigDecimal((String) field.get(declaredField.get(currentPerformanceJsonDto.getRes()))); - result.put(item.getTagCode(), value); - } catch (NoSuchFieldException e) { - log.info("没有找到tag" + item.getTagType() + ";" + item.getTagCode()); - } catch (IllegalAccessException e) { - log.info("没有反射权限"); - } catch (ClassNotFoundException e) { - throw new RuntimeException(e); - } - } - ); - } - return result; - } - - private Map<String, BigDecimal> currentSaleTagsValues(List<TagCommonCurrentDto> tags) { - Map<String, BigDecimal> result = new HashMap<>(tags.size()); - Map<String, String> params = new HashMap<>(2); -// String url = httpApiService.getByCode(API_CODE).getUrl(); -// String responseStr = httpsRequest.doGet(url, params,"utf-8", ""); - String responseStr = "{\"sta\":true,\"msg\":null,\"res\":{\"today\":{\"groundsales\":0.0,\"medblock\":0.0,\"nubmeasure\":0.0,\"gangue\":0.0,\"reshipped\":0.0,\"trainTon\":0.0,\"trainCount\":0},\"yesterday\":{\"groundsales\":15696.00,\"medblock\":14757.00,\"nubmeasure\":0.00,\"gangue\":4384.00,\"reshipped\":2447.00,\"trainTon\":36263.20,\"trainCount\":10},\"currentMonth\":{\"groundsales\":0.0,\"medblock\":0.0,\"nubmeasure\":0.0,\"gangue\":0.0,\"reshipped\":0.0,\"trainTon\":0.0,\"trainCount\":0},\"currentYear\":{\"groundsales\":521638.00,\"medblock\":266372.00,\"nubmeasure\":0.00,\"gangue\":143475.00,\"reshipped\":139695.00,\"trainTon\":0.0,\"trainCount\":0}}}"; - if (StringUtils.isNotBlank(responseStr)) { - TagCurrentSaleJsonDto currentPerformanceJsonDto = parseCurrentSaleDto(responseStr); - tags.stream().forEach( - item -> { - String tagType = item.getTagType(); - String tagCode = item.getTagCode().split(CommonConstant.UNDERLINE)[1]; - Class<?> currentSaleClass = currentPerformanceJsonDto.getRes().getClass(); - String name = currentSaleClass.getName(); - try { - Field declaredField = currentSaleClass.getDeclaredField(tagType); - Class<?> typeClass = Class.forName(name + CommonConstant.DOLLAR + tagType.toUpperCase()); - Field field = typeClass.getDeclaredField(tagCode); - field.setAccessible(true); - declaredField.setAccessible(true); - BigDecimal value = new BigDecimal((String) field.get(declaredField.get(currentPerformanceJsonDto.getRes()))); - result.put(item.getTagCode(), value); - } catch (NoSuchFieldException e) { - log.info("没有找到tag" + item.getTagType() + ";" + item.getTagCode()); - } catch (IllegalAccessException e) { - log.info("没有反射权限"); - } catch (ClassNotFoundException e) { - throw new RuntimeException(e); - } - } - ); - } - return result; - } - - private Map<String, BigDecimal> prdTimeDistTagsValues(List<TagCommonCurrentDto> tags) { - Map<String, BigDecimal> result = new HashMap<>(tags.size()); - Map<String, String> params = new HashMap<>(2); -// String url = httpApiService.getByCode(API_CODE).getUrl(); -// String responseStr = httpsRequest.doGet(url, params,"utf-8", ""); - String responseStr = "{\"sta\":true,\"msg\":null,\"res\":{\"xx\":{\"runMinutes\":1120.0,\"overhaulMinutes\":305.0,\"affectMinutes\":15.0},\"zq\":{\"runMinutes\":645.0,\"overhaulMinutes\":223.0,\"affectMinutes\":572.0}}}"; - if (StringUtils.isNotBlank(responseStr)) { - TagPrdTimeDistJsonDto prdTimeDistJsonDto = parsePrdTimeDistDto(responseStr); - tags.stream().forEach( - item -> { - String tagType = item.getTagType(); - String tagCode = item.getTagCode().split(CommonConstant.UNDERLINE)[1]; - Class<?> prdTimeDistClass = prdTimeDistJsonDto.getRes().getClass(); - String name = prdTimeDistClass.getName(); - try { - Field declaredField = prdTimeDistClass.getDeclaredField(tagType); - Class<?> typeClass = Class.forName(name + CommonConstant.DOLLAR + tagType.toUpperCase()); - Field field = typeClass.getDeclaredField(tagCode); - field.setAccessible(true); - declaredField.setAccessible(true); - BigDecimal value = new BigDecimal((String) field.get(declaredField.get(prdTimeDistJsonDto.getRes()))); - result.put(item.getTagCode(), value); - } catch (NoSuchFieldException e) { - log.info("没有找到tag" + item.getTagType() + ";" + item.getTagCode()); - } catch (IllegalAccessException e) { - log.info("没有反射权限"); - } catch (ClassNotFoundException e) { - throw new RuntimeException(e); - } - } - ); - } - return result; - } - - private TagYearPeiJsonDto parseYearPeiDto(String responseStr) { - TagYearPeiJsonDto result = new TagYearPeiJsonDto(); - if (!StringUtils.isEmpty(responseStr)) { - JSONObject items = JSONObject.parseObject(responseStr); - result = items.toJavaObject(TagYearPeiJsonDto.class); - } - return result; - } - - private TagCurrentPerformanceJsonDto parseCurrentPerformanceDto(String responseStr) { - TagCurrentPerformanceJsonDto result = new TagCurrentPerformanceJsonDto(); - if (!StringUtils.isEmpty(responseStr)) { - JSONObject items = JSONObject.parseObject(responseStr); - result = items.toJavaObject(TagCurrentPerformanceJsonDto.class); - } - return result; - } - - private TagCurrentSaleJsonDto parseCurrentSaleDto(String responseStr) { - TagCurrentSaleJsonDto result = new TagCurrentSaleJsonDto(); - if (!StringUtils.isEmpty(responseStr)) { - JSONObject items = JSONObject.parseObject(responseStr); - result = items.toJavaObject(TagCurrentSaleJsonDto.class); - } - return result; - } - - private TagPrdTimeDistJsonDto parsePrdTimeDistDto(String responseStr) { - TagPrdTimeDistJsonDto result = new TagPrdTimeDistJsonDto(); - if (!StringUtils.isEmpty(responseStr)) { - JSONObject items = JSONObject.parseObject(responseStr); - result = items.toJavaObject(TagPrdTimeDistJsonDto.class); - } - return result; } } diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/indexdata/common/ClockSuffix.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/indexdata/common/ClockSuffix.java deleted file mode 100644 index d3c3171..0000000 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/indexdata/common/ClockSuffix.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.iailab.module.data.indexdata.common; - -/** - * @author PanZhibao - * @Description - * @createTime 2022年09月11日 09:52:00 - */ -public enum ClockSuffix { - BB,YB,RI -} diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/indexdata/common/IndexDataBc.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/indexdata/common/IndexDataBc.java deleted file mode 100644 index 60679b9..0000000 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/indexdata/common/IndexDataBc.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.iailab.module.data.indexdata.common; - -/** - * @author PanZhibao - * @Description - * @createTime 2022年09月10日 23:29:00 - */ -public enum IndexDataBc { - BC_B_ST,BC_Y_ST,BC_TIME -} diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/indexdata/common/IndexDataConstant.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/indexdata/common/IndexDataConstant.java deleted file mode 100644 index 88ff93e..0000000 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/indexdata/common/IndexDataConstant.java +++ /dev/null @@ -1,79 +0,0 @@ -package com.iailab.module.data.indexdata.common; - -/** - * @author PanZhibao - * @Description - * @createTime 2022年09月12日 08:57:00 - */ -public interface IndexDataConstant { - - /** - * 数据项类别 原煤 - */ - String DATA_ITEM_TYPE_YM = "1"; - - /** - * 数据项类别 洗选 - */ - String DATA_ITEM_TYPE_XX = "2"; - - /** - * 数据项类别 装车 - */ - String DATA_ITEM_TYPE_ZC = "3"; - - /** - * 数据项类别 装车 - */ - String DATA_ITEM_TYPE_ZJ = "4"; - - /** - * 运行时长全部 - */ - String RUN_TIME = "run-time"; - - /** - * 运行时长正常 - */ - String RUN_TIME_ZC = "run-time-zc"; - - /** - * 运行时长空载 - */ - String RUN_TIME_KZ = "run-time-kz"; - - /** - * 消耗指标 - */ - String CONSUME_TARGET = "consume-target"; - - /** - * 电耗 - */ - String POWER_CONSUME = "power-consume"; - - /** - * 调入量 - */ - String WASH_TRANSFER_IN = "wash-transfer-in"; - - /** - * 入洗量 - */ - String WASH_TO_WASH = "wash-to-wash"; - - /** - * 生产量 - */ - String WASH_PROD_VOLUME = "wash-prod-volume"; - - /** - * 仓位 - */ - String WAREHOUSE_POSITION = "warehouse-position"; - - /** - * 小时量 - */ - String HOUR_VOLUME = "hour-volume"; -} diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/indexdata/common/IndexDataUtils.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/indexdata/common/IndexDataUtils.java deleted file mode 100644 index fd26933..0000000 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/indexdata/common/IndexDataUtils.java +++ /dev/null @@ -1,768 +0,0 @@ -package com.iailab.module.data.indexdata.common; - -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONObject; -import com.iailab.dto.*; -import com.iailab.module.data.common.enums.CommonConstant; -import com.iailab.api.IFeignProddispApi; -import com.iailab.framework.common.util.date.DateUtils; -import com.iailab.module.data.point.dto.DaPointDTO; -import com.iailab.module.data.point.service.DaPointService; -import com.iailab.module.data.indexdata.entity.IndexDataItemEntity; -import com.iailab.module.data.indexdata.entity.IndexDataValueEntity; -import com.iailab.module.data.indexdata.service.IndexDataItemService; -import com.iailab.module.data.indexdata.service.IndexDataValueService; -import com.iailab.module.data.influxdb.pojo.InfluxPointValuePOJO; -import com.iailab.module.data.influxdb.service.InfluxDBService; -import com.iailab.module.infra.api.config.ConfigApi; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; -import org.joda.time.LocalDate; -import javax.annotation.Resource; -import org.springframework.stereotype.Component; -import org.springframework.util.CollectionUtils; - -import java.math.BigDecimal; -import java.math.RoundingMode; -import java.text.SimpleDateFormat; -import java.util.*; -import java.util.stream.Collectors; - -/** - * @author PanZhibao - * @Description - * @createTime 2022年09月11日 14:11:00 - */ -@Slf4j -@Component -public class IndexDataUtils { - - private BigDecimal hourMins = new BigDecimal("60"); - - private String DATA_TYPE_BOOLEAN = "boolean"; - - private final int granularity = 5; - - @Resource - private InfluxDBService influxDBService; - - @Resource - private IndexDataValueService indexDataValueService; - - @Resource - private IFeignProddispApi feignProddispApi; - - @Resource - private ConfigApi configApi; - - @Resource - private DaPointService daPointService; - - @Resource - private IndexDataItemService indexDataItemService; - - public void doCal(Date startTime, Date endTime, String CLOCK_CODE, String DICT_DC) throws Exception { - log.info("startTime=" + DateUtils.format(startTime, DateUtils.FORMAT_YEAR_MONTH_DAY)); - log.info("endTime=" + DateUtils.format(endTime, DateUtils.FORMAT_YEAR_MONTH_DAY)); - // 获取数据项 - List<IndexDataItemEntity> indexDataItemList = indexDataItemService.getListByClockConfig(CLOCK_CODE); - if (CollectionUtils.isEmpty(indexDataItemList)) { - log.warn("indexDataItemEntityList为空, clockCode=" + CLOCK_CODE); - throw new Exception("indexDataItemEntityList为空, clockCode=" + CLOCK_CODE); - } - indexDataItemList.forEach(dataItem -> { - switch (dataItem.getItemType()) { - case IndexDataConstant.RUN_TIME: - // 运行时长 - this.createRunTime(CLOCK_CODE, dataItem, "all" ,startTime, endTime); - break; - case IndexDataConstant.RUN_TIME_ZC: - // 运行时长正常 - this.createRunTime(CLOCK_CODE, dataItem, "zc",startTime, endTime); - break; - case IndexDataConstant.RUN_TIME_KZ: - // 运行时长空载 - this.createRunTime(CLOCK_CODE, dataItem, "kz",startTime, endTime); - break; - case IndexDataConstant.POWER_CONSUME: - // 电耗 - this.createPowerConsume(CLOCK_CODE, dataItem, startTime, endTime); - break; - case IndexDataConstant.WASH_TRANSFER_IN: - // 调入量 - this.createWashTransferIn(CLOCK_CODE, dataItem, startTime, endTime); - break; - case IndexDataConstant.WASH_TO_WASH: - // 入洗量 - this.createWashToWash(CLOCK_CODE, dataItem, startTime, endTime); - break; - case IndexDataConstant.WASH_PROD_VOLUME: - // 生产量 - this.createWashProdVolume(CLOCK_CODE, dataItem, startTime, endTime); - break; - case IndexDataConstant.WAREHOUSE_POSITION: - // 仓位 - this.createWarehousePosition(CLOCK_CODE, dataItem, startTime, endTime); - break; - default: - break; - } - }); - - // 统计库存 - this.createWarehouseStock(DateUtils.format(startTime), DICT_DC); - - // 统计总电量 - FeignConsumeTargetDTO dto = new FeignConsumeTargetDTO(); - Map param = new HashMap(); - param.put("rq",new LocalDate()); - param.put("bc",DICT_DC); - BigDecimal hdl = feignProddispApi.sumData(param); - dto.setRq(DateUtils.format(startTime)); - dto.setBc(DICT_DC); - dto.setXhzb("hdl"); - dto.setDw("kw.h"); - dto.setNbdrl(hdl); - dto.setNbtzl(new BigDecimal(0)); - dto.setWbdrl(new BigDecimal(0)); - dto.setWbtzl(new BigDecimal(0)); - dto.setCjr(CommonConstant.CJS_SYS); - dto.setCjsj(new Date()); - dto.setXgsj(new Date()); - feignProddispApi.createConsumeTarget(dto); - - } - - public void doHourVolume(Date startTime, Date endTime, String CLOCK_CODE, String DICT_DC) throws Exception { - log.info("startTime=" + DateUtils.format(startTime, DateUtils.FORMAT_YEAR_MONTH_DAY)); - log.info("endTime=" + DateUtils.format(endTime, DateUtils.FORMAT_YEAR_MONTH_DAY)); - // 获取数据项 - List<IndexDataItemEntity> indexDataItemList = indexDataItemService.getListByClockConfig(CLOCK_CODE); - if (CollectionUtils.isEmpty(indexDataItemList)) { - log.warn("indexDataItemEntityList为空, clockCode=" + CLOCK_CODE); - throw new Exception("indexDataItemEntityList为空, clockCode=" + CLOCK_CODE); - } - indexDataItemList.forEach(dataItem -> {this.createHourVolume(CLOCK_CODE, dataItem, startTime, endTime);}); - - } - public void createRunTime(String clockCode, IndexDataItemEntity dataItem, String runTimeType,Date startTime, Date endTime) { - try{ - log.info("计算运行时长开始,itemCode=" + dataItem.getPointCode()); - InfluxPointValuePOJO pojo = new InfluxPointValuePOJO(); - pojo.setPoint(dataItem.getPointCode()); - pojo.setType(DATA_TYPE_BOOLEAN); - List<Map<String, Object>> pointData = influxDBService.queryPointValues(pojo, startTime, endTime); - if (CollectionUtils.isEmpty(pointData)) { - log.warn("历史值为空,PointCode=" + dataItem.getPointCode()); - return; - } - int mins = this.getRunMins(pointData); - int times = this.getStartUpTimes(pointData); - - Map<String, BigDecimal> valueMap = new HashMap<>(2); - valueMap.put("sumValue", new BigDecimal(mins)); - valueMap.put("startUpTimes", new BigDecimal(times)); - IndexDataValueEntity indexDataValue = this.buildIndexDataValueEntity(dataItem, clockCode, valueMap); - indexDataValueService.add(indexDataValue); - - FeignRunTimeDTO dto = new FeignRunTimeDTO(); - dto.setRq(DateUtils.format(startTime)); - dto.setBc(dataItem.getBc()); - dto.setScxm(dataItem.getXtCode()); - dto.setRunTimeType(runTimeType); - dto.setXss(Long.valueOf((mins / 60))); - dto.setFzs(Long.valueOf((mins % 60))); - dto.setZsc(Long.valueOf(mins)); - dto.setCjr(CommonConstant.CJS_SYS); - dto.setCjsj(new Date()); - dto.setXgsj(new Date()); - feignProddispApi.createRunTime(dto); - log.info("计算运行时长结束,itemCode=" + dataItem.getPointCode()); - } catch (Exception ex) { - log.info("计算运行时长异常,itemCode=" + dataItem.getPointCode()); - ex.printStackTrace(); - } - } - - public void createConsumeTarget(String clockCode, IndexDataItemEntity dataItem, Date startTime, Date endTime) { - try{ - log.info("计算消耗指标开始,itemCode=" + dataItem.getPointCode()); - - // 插入指标数据表 - Map<String, BigDecimal> valueMap = new HashMap<>(2); - valueMap.put("sumValue", new BigDecimal(0)); - IndexDataValueEntity indexDataValue = this.buildIndexDataValueEntity(dataItem, clockCode, valueMap); - indexDataValueService.add(indexDataValue); - - FeignConsumeTargetDTO dto = new FeignConsumeTargetDTO(); - dto.setRq(DateUtils.format(startTime)); - dto.setBc(dataItem.getBc()); - dto.setXhzb(dataItem.getExt1()); - dto.setDw(dataItem.getUnit()); - dto.setNbdrl(new BigDecimal(0)); - dto.setNbtzl(new BigDecimal(0)); - dto.setWbdrl(new BigDecimal(0)); - dto.setWbtzl(new BigDecimal(0)); - dto.setCjr(CommonConstant.CJS_SYS); - dto.setCjsj(new Date()); - dto.setXgsj(new Date()); - feignProddispApi.createConsumeTarget(dto); - log.info("计算消耗指标结束,itemCode=" + dataItem.getPointCode()); - } catch (Exception ex) { - log.info("计算消耗指标异常,itemCode=" + dataItem.getPointCode()); - ex.printStackTrace(); - } - } - - public void createPowerConsume(String clockCode, IndexDataItemEntity dataItem, Date startTime, Date endTime) { - try{ - DaPointDTO daPoint = daPointService.getByNo(dataItem.getPointCode()); - - if (daPoint == null) { - log.info("daPoint is null"); - return; - } - InfluxPointValuePOJO pojo = new InfluxPointValuePOJO(); - pojo.setPoint(daPoint.getPointNo()); - pojo.setType(daPoint.getPointType()); - // 取10min内最大值 - Object startPointValue = influxDBService.queryPointMaxValue(pojo, new Date(startTime.getTime() - 1000 * 60 * 10)); - Object endPointValue = influxDBService.queryPointMaxValue(pojo, new Date(endTime.getTime() - 1000 * 60 * 10)); - BigDecimal startValue = startPointValue == null ? BigDecimal.ZERO : new BigDecimal(startPointValue.toString()); - BigDecimal endValue = endPointValue == null ? BigDecimal.ZERO : new BigDecimal(endPointValue.toString()); - BigDecimal value = new BigDecimal(0); - if(endValue.compareTo(startValue) == 1){ - value = endValue.subtract(startValue); - } - // 插入指标数据表 - Map<String, BigDecimal> valueMap = new HashMap<>(1); - valueMap.put("sumValue", value); - IndexDataValueEntity indexDataValue = this.buildIndexDataValueEntity(dataItem, clockCode, valueMap); - indexDataValueService.add(indexDataValue); - - String xt = configApi.queryConfigByCode(dataItem.getExt1()); - // 插入统计表 - FeignPowerConsumeDTO dto = new FeignPowerConsumeDTO(); - dto.setRq(DateUtils.format(startTime)); - dto.setBc(dataItem.getBc()); - dto.setXt(xt); - dto.setNbdrl(value); - dto.setNbtzl(new BigDecimal(0)); - dto.setWbdrl(value); - dto.setWbtzl(new BigDecimal(0)); - dto.setCjr(CommonConstant.CJS_SYS); - dto.setCjsj(new Date()); - dto.setXgsj(new Date()); - feignProddispApi.createPowerConsume(dto); - log.info("计算电耗结束,itemCode=" + dataItem.getPointCode()); - } catch (Exception ex) { - log.info("计算电耗异常,itemCode=" + dataItem.getPointCode()); - ex.printStackTrace(); - } - } - public void createHourVolume(String clockCode, IndexDataItemEntity dataItem, Date startTime, Date endTime) { - try{ - /** - * 861 精煤 - * 862 混煤 - * 903 矸石 - * 603ABC 煤泥板数 - */ - log.info("计算小时量开始,itemCode=" + dataItem.getPointCode()); - List<String> pointNos = new ArrayList<>(); - pointNos.add(dataItem.getPointCode()); - if(StringUtils.isNotBlank(dataItem.getExt1())) { - pointNos.add(dataItem.getExt1()); - } - if(StringUtils.isNotBlank(dataItem.getExt2())) { - pointNos.add(dataItem.getExt2()); - } - if(StringUtils.isNotBlank(dataItem.getExt3())) { - pointNos.add(dataItem.getExt3()); - } - if(StringUtils.isNotBlank(dataItem.getExt4())) { - pointNos.add(dataItem.getExt4()); - } - if(StringUtils.isNotBlank(dataItem.getExt5())) { - pointNos.add(dataItem.getExt5()); - } - List<DaPointDTO> pointList = daPointService.getByNos(pointNos); - if (CollectionUtils.isEmpty(pointList)) { - log.warn("pointNos查询为空!"); - return; - } - List<InfluxPointValuePOJO> influxParams = pointList.stream().map(item -> { - InfluxPointValuePOJO pojo = new InfluxPointValuePOJO(); - pojo.setPoint(item.getPointNo()); - pojo.setType(item.getDataType()); - return pojo; - }).collect(Collectors.toList()); - Map<String, Object> data = influxDBService.queryPointsSpread(influxParams, startTime, endTime); - log.info("查询完成!"); - - log.info("插入统计表"); - FeignHourVolumeDTO dto = new FeignHourVolumeDTO(); - dto.setRq(DateUtils.format(startTime)); - dto.setBc(this.getBcByTime(endTime)); - dto.setSj(endTime); - if (StringUtils.isNotBlank(dataItem.getPointCode()) && data.get(dataItem.getPointCode()) != null) { - dto.setRxl(new BigDecimal(data.get(dataItem.getPointCode()).toString())); - log.info(" 插入指标数据表"); - Map<String, BigDecimal> valueMap = new HashMap<>(1); - valueMap.put("sumValue", new BigDecimal(data.get(dataItem.getPointCode()).toString())); - IndexDataValueEntity indexDataValue = this.buildIndexDataValueEntity(dataItem, clockCode, valueMap); - indexDataValueService.add(indexDataValue); - } - if (StringUtils.isNotBlank(dataItem.getExt1()) && data.get(dataItem.getExt1()) != null) { - dto.setJml(new BigDecimal(data.get(dataItem.getExt1()).toString())); - } - if (StringUtils.isNotBlank(dataItem.getExt2()) && data.get(dataItem.getExt2()) != null) { - dto.setHml(new BigDecimal(data.get(dataItem.getExt2()).toString())); - } - if (StringUtils.isNotBlank(dataItem.getExt3()) && data.get(dataItem.getExt3()) != null) { - dto.setGsl(new BigDecimal(data.get(dataItem.getExt3()).toString())); - } - if (StringUtils.isNotBlank(dataItem.getExt4()) && data.get(dataItem.getExt4()) != null) { - dto.setFjbs(new BigDecimal(data.get(dataItem.getExt4()).toString())); - } - if (StringUtils.isNotBlank(dataItem.getExt5()) && data.get(dataItem.getExt5()) != null) { - dto.setMnbs(new BigDecimal(data.get(dataItem.getExt5()).toString())); - } - dto.setCjr(CommonConstant.CJS_SYS); - dto.setCjsj(new Date()); - dto.setXgsj(new Date()); - feignProddispApi.createHourVolume(dto); - log.info("计算小时量结束,itemCode=" + dataItem.getPointCode()); - } catch (Exception ex) { - log.info("计算小时量异常,itemCode=" + dataItem.getPointCode()); - ex.printStackTrace(); - } - } - - - private String getBcByTime(Date dateTime) { - String bc = "bb"; - Calendar calendar = Calendar.getInstance(); - calendar.setTime(dateTime); - if (calendar.get(Calendar.HOUR_OF_DAY) >= 21 || calendar.get(Calendar.HOUR_OF_DAY) <= 8) { - bc = "yb"; - } - return bc; - } - - public void createWashTransferIn(String clockCode, IndexDataItemEntity dataItem, Date startTime, Date endTime) { - try{ - log.info("计算调入量开始,itemCode=" + dataItem.getPointCode()); - // 查询测点里的累计产量 - DaPointDTO daPoint = daPointService.getByNo(dataItem.getPointCode()); - - if (daPoint == null) { - log.info("daPoint is null"); - return; - } - InfluxPointValuePOJO pojo = new InfluxPointValuePOJO(); - pojo.setPoint(daPoint.getPointNo()); - pojo.setType(daPoint.getDataType()); - // 取10min内最大值 - Object pointValue = influxDBService.queryPointMaxValue(pojo, new Date(endTime.getTime() - 1000 * 60 * 10)); - BigDecimal sumValue = pointValue == null ? BigDecimal.ZERO : new BigDecimal(pointValue.toString()); - - // 插入指标数据表 - Map<String, BigDecimal> valueMap = new HashMap<>(1); - valueMap.put("sumValue", sumValue); - IndexDataValueEntity indexDataValue = this.buildIndexDataValueEntity(dataItem, clockCode, valueMap); - indexDataValueService.add(indexDataValue); - - String mz = configApi.queryConfigByCode(dataItem.getExt1()); - // 插入统计表 - FeignWashTransferInDTO dto = new FeignWashTransferInDTO(); - dto.setRq(DateUtils.format(startTime)); - dto.setBc(dataItem.getBc()); - dto.setDrly(mz); - dto.setNbdrl(sumValue); - dto.setNbtzl(new BigDecimal(0)); - dto.setWbdrl(sumValue); - dto.setWbtzl(new BigDecimal(0)); - dto.setCjr(CommonConstant.CJS_SYS); - dto.setCjsj(new Date()); - dto.setXgsj(new Date()); - feignProddispApi.createWashTransferIn(dto); - log.info("计算调入量结束,itemCode=" + dataItem.getPointCode()); - } catch (Exception ex) { - log.info("计算调入量异常,itemCode=" + dataItem.getPointCode()); - ex.printStackTrace(); - } - } - - public void createWashToWash(String clockCode, IndexDataItemEntity dataItem, Date startTime, Date endTime) { - try{ - log.info("计算入洗量开始,itemCode=" + dataItem.getPointCode()); - // 查询测点里的累计产量 - DaPointDTO daPoint = daPointService.getByNo(dataItem.getPointCode()); - if (daPoint == null) { - log.info("daPoint is null"); - return; - } - InfluxPointValuePOJO pojo = new InfluxPointValuePOJO(); - pojo.setPoint(daPoint.getPointNo()); - pojo.setType(daPoint.getDataType()); - // 取10min内最大值 - Object pointValue = influxDBService.queryPointMaxValue(pojo, new Date(endTime.getTime() - 1000 * 60 * 10)); - BigDecimal sumValue = pointValue == null ? BigDecimal.ZERO : new BigDecimal(pointValue.toString()); - log.info("插入指标数据表"); - Map<String, BigDecimal> valueMap = new HashMap<>(1); - log.info("sumValue"+sumValue); - valueMap.put("sumValue", sumValue); - IndexDataValueEntity indexDataValue = this.buildIndexDataValueEntity(dataItem, clockCode, valueMap); - indexDataValueService.add(indexDataValue); - List<FeignMcMzDTO> mzList = feignProddispApi.selectMcMzByMc(dataItem.getExt1()); - log.info("dataItem.getExt1()"+dataItem.getExt1()); - - //获取总入洗量 - pojo.setPoint(dataItem.getExt2()); - pojo.setType("float"); - Object rxlPointValue = influxDBService.queryPointMaxValue(pojo, new Date(endTime.getTime() - 1000 * 60 * 10)); - BigDecimal sumRXL = rxlPointValue == null ? BigDecimal.ZERO : new BigDecimal(rxlPointValue.toString()); - - mzList.stream().forEach( - mz->{ - log.info("插入统计表,mc:"+mz.getMc()+";mz:"+mz.getMz()); - FeignWashToWashDTO dto = new FeignWashToWashDTO(); - dto.setRq(DateUtils.format(startTime)); - dto.setBc(dataItem.getBc()); - dto.setXxjm(mz.getMz()); - dto.setNbdrl(sumValue.multiply(BigDecimal.valueOf(mz.getProportion())).divide(BigDecimal.valueOf(mz.getDen())) ); - dto.setRxbl(dto.getNbdrl().divide(sumRXL, 2, RoundingMode.HALF_UP)); - dto.setRxly(dataItem.getExt1()); - dto.setNbtzl(new BigDecimal(0)); - dto.setWbdrl(dto.getNbdrl()); - dto.setWbtzl(new BigDecimal(0)); - dto.setCjr(CommonConstant.CJS_SYS); - dto.setCjsj(new Date()); - dto.setXgsj(new Date()); - feignProddispApi.createWashToWash(dto); - } - ); - - - log.info("计算入洗量结束,itemCode=" + dataItem.getPointCode()); - } catch (Exception ex) { - log.info("计算入洗量异常,itemCode=" + dataItem.getPointCode()); - ex.printStackTrace(); - } - } - - public void createWashProdVolume(String clockCode, IndexDataItemEntity dataItem, Date startTime, Date endTime) { - try{ - log.info("计算生产量开始,itemCode=" + dataItem.getPointCode()); - // 查询测点里的累计产量 - DaPointDTO daPoint = daPointService.getByNo(dataItem.getPointCode()); - if (daPoint == null) { - log.info("daPoint is null"); - return; - } - InfluxPointValuePOJO pojo = new InfluxPointValuePOJO(); - pojo.setPoint(daPoint.getPointNo()); - pojo.setType(daPoint.getDataType()); - // 取10min内最大值 - Object pointValue = influxDBService.queryPointMaxValue(pojo, new Date(endTime.getTime() - 1000 * 60 * 10)); - BigDecimal sumValue = pointValue == null ? BigDecimal.ZERO : new BigDecimal(pointValue.toString()); - - log.info("插入指标数据表"); - Map<String, BigDecimal> valueMap = new HashMap<>(1); - valueMap.put("sumValue", sumValue); - IndexDataValueEntity indexDataValue = this.buildIndexDataValueEntity(dataItem, clockCode, valueMap); - indexDataValueService.add(indexDataValue); - - log.info("插入统计表"); - FeignWashProdVolumeDTO dto = new FeignWashProdVolumeDTO(); - dto.setRq(DateUtils.format(startTime)); - dto.setBc(dataItem.getBc()); - dto.setClmz(dataItem.getExt1()); - dto.setNbdrl(sumValue); - dto.setNbtzl(new BigDecimal(0)); - dto.setWbdrl(sumValue); - dto.setWbtzl(new BigDecimal(0)); - dto.setCjr(CommonConstant.CJS_SYS); - dto.setCjsj(new Date()); - dto.setXgsj(new Date()); - feignProddispApi.createWashProdVolume(dto); - log.info("计算生产量结束,itemCode=" + dataItem.getPointCode()); - } catch (Exception ex) { - log.info("计算生产量异常,itemCode=" + dataItem.getPointCode()); - ex.printStackTrace(); - } - } - - public void createWarehousePosition(String clockCode, IndexDataItemEntity dataItem, Date startTime, Date endTime) { - try{ - log.info("计算仓位开始,itemCode=" + dataItem.getPointCode()); - DaPointDTO daPoint = daPointService.getByNo(dataItem.getPointCode()); - if (daPoint == null) { - log.info("daPoint is null"); - return; - } - InfluxPointValuePOJO pojo = new InfluxPointValuePOJO(); - pojo.setPoint(daPoint.getPointNo()); - pojo.setType(daPoint.getDataType()); - List<Map<String, Object>> pointValues = influxDBService.queryPointValues(pojo, new Date(endTime.getTime() - 1000 * 30), endTime); - String point = JSON.toJSONString(pointValues); - log.info("pointValues :"+point); - if (CollectionUtils.isEmpty(pointValues)) { - log.info("pointValues is null"); - return; - } - - Map<String, Object> pointValue = pointValues.get(pointValues.size() - 1); - JSONObject json = new JSONObject(pointValue); - log.info("插入指标数据表:"+json); - Map<String, BigDecimal> valueMap = new HashMap<>(1); - BigDecimal sumValue = new BigDecimal(pointValue.get("value").toString()); - valueMap.put("sumValue",sumValue); - IndexDataValueEntity indexDataValue = this.buildIndexDataValueEntity(dataItem, clockCode, valueMap); - indexDataValueService.add(indexDataValue); - log.info("mc:"+dataItem.getExt1()); - FeignWarehouseItemDTO warehouseItem = feignProddispApi.selectWarehouseItemByMc(dataItem.getExt1()); - log.info("插入仓位统计表开始"); - FeignWarehousePositionDTO dto = new FeignWarehousePositionDTO(); - dto.setRq(DateUtils.format(startTime)); - dto.setBc(dataItem.getBc()); - dto.setMc(dataItem.getExt1()); - dto.setMclx(dataItem.getExt2()); - log.info(Integer.toString(warehouseItem.getCapacity())); - dto.setCrl(Integer.toString(warehouseItem.getCapacity())); - BigDecimal dqcc = sumValue.multiply(new BigDecimal(dto.getCrl())).divide(new BigDecimal(100), 1, BigDecimal.ROUND_HALF_UP); - dto.setNbgl(dqcc); - dto.setWbgl(dqcc); - dto.setCjr(CommonConstant.CJS_SYS); - dto.setCjsj(new Date()); - dto.setXgsj(new Date()); - feignProddispApi.createWarehousePosition(dto); - log.info("计算仓位结束,itemCode=" + dataItem.getPointCode()); - } catch (Exception ex) { - log.info("计算仓位异常,itemCode=" + dataItem.getPointCode()); - ex.printStackTrace(); - } - } - - public void createWarehouseStock(String rq, String bc) { - try{ - log.info("计算库存开始,rq=" + rq); - - Map<String, Object> params = new HashMap<>(); - params.put("rq", rq); - params.put("bc", bc); - List<FeignWarehousePositionDTO> list = feignProddispApi.selectWarehouseGroupByCp(params); - list.forEach(item -> { - log.info("遍历" + item.getMc()+"煤仓煤种"); - List<FeignMcMzDTO> mzList = feignProddispApi.selectMcMzByMc(item.getMc()); - mzList.stream().forEach( - mz->{ - log.info("插入" + mz.getMz()+"库存"); - FeignWarehouseStockDTO dto = new FeignWarehouseStockDTO(); - dto.setRq(rq); - dto.setBc(bc); - dto.setLsh(new SimpleDateFormat("yyyyMMddhhmmssSSS").format(new Date())); - dto.setBs(item.getMclx()); - dto.setKcmz(mz.getMz()); - dto.setNbzrkc(new BigDecimal(0)); - dto.setNbjrrk(new BigDecimal(0)); - log.info(mz.getProportion().toString()); - log.info(mz.getDen().toString()); - BigDecimal math = item.getNbgl().multiply(BigDecimal.valueOf(mz.getProportion()).divide(BigDecimal.valueOf(mz.getDen()))); - BigDecimal nbjrkc = math.setScale(2, RoundingMode.HALF_UP); - dto.setNbjrkc(nbjrkc); - dto.setNbtzl(new BigDecimal(0)); - dto.setWbzrkc(new BigDecimal(0)); - dto.setWbjrrk(new BigDecimal(0)); - dto.setWbjrkc(dto.getNbjrkc()); - dto.setWbtzl(new BigDecimal(0)); - dto.setCjr(CommonConstant.CJS_SYS); - dto.setCjsj(new Date()); - dto.setXgsj(new Date()); - feignProddispApi.createWarehouseStock(dto); - } - ); - }); - log.info("计算库存结束,rq=" + rq); - } catch (Exception ex) { - log.info("计算库存异常,rq=" + rq); - ex.printStackTrace(); - } - } - - public int getRunMins(List<Map<String, Object>> pointData) { - int seconds = 0; - for (Map<String, Object> item: - pointData) { - if (Boolean.parseBoolean(item.get("value").toString())) { - seconds = seconds + granularity; - } - } - return (seconds / 60); - } - - /** - * getAvgOutput - * - * @param indexDataItemEntity - * @param output - * @param hours - * @return - */ - public BigDecimal getAvgOutput(IndexDataItemEntity indexDataItemEntity, BigDecimal output, BigDecimal hours) { - BigDecimal result = BigDecimal.ZERO; - if (hours.compareTo(BigDecimal.ZERO) > 0) { - result = output.divide(hours, 0, BigDecimal.ROUND_HALF_UP); - } - return result; - } - - /** - * buildIndexDataValueEntity - * - * @param indexDataItemEntity - * @param clock - * @param valueMap - * @return - */ - public IndexDataValueEntity buildIndexDataValueEntity(IndexDataItemEntity indexDataItemEntity, String clock, - Map<String, BigDecimal> valueMap) { - IndexDataValueEntity entity = new IndexDataValueEntity(); - entity.setId(UUID.randomUUID().toString().replace("-","")); - entity.setConfigId(indexDataItemEntity.getId()); - entity.setUnit2(indexDataItemEntity.getUnit2()); - entity.setSsdw(indexDataItemEntity.getSsdw()); - entity.setItemCode(indexDataItemEntity.getItemCode()); - entity.setItemName(indexDataItemEntity.getItemName()); - entity.setUnit(indexDataItemEntity.getUnit()); - entity.setClock(clock); - entity.setSumValue(valueMap.get("sumValue")); - entity.setAvgValue(valueMap.get("avgValue")); - entity.setReportValue(valueMap.get("reportValue")); - entity.setReportHourValue(valueMap.get("reportHourValue")); - entity.setCollectValue(valueMap.get("collectValue")); - entity.setCollectHourValue(valueMap.get("collectHourValue")); - entity.setStartUpTimes(valueMap.get("startUpTimes")); - entity.setCreateTime(new Date()); - return entity; - } - - /** - * getAvgValue - * - * @param dataMap - * @return - */ - public BigDecimal getAvgValue (LinkedHashMap<String, BigDecimal> dataMap) { - BigDecimal avgValue = BigDecimal.ZERO; - double sumValue = 0d; - if (!CollectionUtils.isEmpty(dataMap)) { - int size = dataMap.size(); - for (Map.Entry<String, BigDecimal> item : dataMap.entrySet()) { - if (item.getValue() != null && item.getValue().compareTo(BigDecimal.ZERO) > 0) { - sumValue = sumValue + item.getValue().doubleValue(); - } - } - avgValue = new BigDecimal(sumValue).divide(new BigDecimal(size), 2, BigDecimal.ROUND_HALF_UP); - } - return avgValue; - } - - /** - * getRunHours - * - * @param dataMap - * @return - */ - public BigDecimal getRunHours (LinkedHashMap<String, BigDecimal> dataMap) { - BigDecimal result = BigDecimal.ZERO; - if (!CollectionUtils.isEmpty(dataMap)) { - int mins = 0; - for (Map.Entry<String, BigDecimal> item : dataMap.entrySet()) { - if (item.getValue() != null && item.getValue().compareTo(BigDecimal.ZERO) > 0) { - mins++; - } - } - result = new BigDecimal(mins).divide(hourMins, 2, BigDecimal.ROUND_HALF_UP); - } - return result; - } - - /** - * getStartUpTimes - * - * @param pointData - * @return - */ - public int getStartUpTimes (List<Map<String, Object>> pointData) { - int times = 0; - Boolean lastValue = Boolean.FALSE; - for (Map<String, Object> item: - pointData) { - Boolean itemValue = Boolean.parseBoolean(item.get("value").toString()); - if (itemValue.compareTo(lastValue) != 0) { - times++; - } - lastValue = itemValue; - } - return times; - } - - /** - * 完善数据 - * - * @param length - * @param sourceDataMap - * @param startTime - * @param endTime - * @return - */ - public LinkedHashMap<String, BigDecimal> completionData(int length, LinkedHashMap<String, BigDecimal> sourceDataMap, Date startTime, Date endTime) { - if (CollectionUtils.isEmpty(sourceDataMap) || length <= sourceDataMap.size()) { - return sourceDataMap; - } - log.info("补全数据, length =" + length + "; size = " + sourceDataMap.size() + "; startTime = " + startTime.getTime() + "; endTime = " + endTime.getTime()); - - //找出缺少项 - long oneMin = 1000 * 60; - long start = startTime.getTime(); - long end = endTime.getTime(); - long mins = ((end - start) / oneMin); - LinkedHashMap<String, BigDecimal> dataMap = new LinkedHashMap<>(); - for (int i = 0; i < mins; i ++) { - String key = DateUtils.format(new Date(start + oneMin * i), ""); - dataMap.put(key, sourceDataMap.get(key)); - } - - //补充缺少项 - int k = 0; - Map.Entry<String, BigDecimal> lastItem = null; - for (Map.Entry<String, BigDecimal> item : dataMap.entrySet()) { - if (k == 0 && item.getValue() == null) { - item.setValue(getFirstValue(dataMap)); - } else if (item.getValue() == null) { - item.setValue(lastItem.getValue()); - } - k ++; - lastItem = item; - } - log.info("补全完成"); - return dataMap; - } - - /** - * getFirstValue - * - * @param dataMap - * @return - */ - private BigDecimal getFirstValue(LinkedHashMap<String, BigDecimal> dataMap) { - for (Map.Entry<String, BigDecimal> item : dataMap.entrySet()) { - if (item.getValue() != null) { - return item.getValue(); - } - } - return null; - } -} diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/indexdata/controller/admin/IndexDataClockController.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/indexdata/controller/admin/IndexDataClockController.java deleted file mode 100644 index dfab56b..0000000 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/indexdata/controller/admin/IndexDataClockController.java +++ /dev/null @@ -1,109 +0,0 @@ -package com.iailab.module.data.indexdata.controller.admin; - -import com.iailab.module.data.common.utils.PageUtils; -import com.iailab.module.data.common.utils.R; -import com.iailab.framework.security.core.util.SecurityFrameworkUtils; -import com.iailab.module.data.indexdata.entity.IndexDataClockEntity; -import com.iailab.module.data.indexdata.service.IndexDataClockService; -import javax.annotation.Resource; - -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.tags.Tag; -import org.springframework.web.bind.annotation.*; - -import java.util.Date; -import java.util.List; -import java.util.Map; - -/** - * @author PanZhibao - * @Description - * @createTime 2022年09月08日 21:52:00 - */ -@RestController -@RequestMapping("/data/index-data/clock") -@Tag(name = "数据采集-index-data-clock") -public class IndexDataClockController { - - @Resource - private IndexDataClockService indexDataClockService; - - /** - * 所有时钟配置列表 - */ - @GetMapping("/list") - @Operation(summary = "查询列表") - public R list(@RequestParam Map<String, Object> params){ - PageUtils page = indexDataClockService.queryPage(params); - return R.ok().put("page", page); - } - - /** - * 采集点列表(全部) - */ - @GetMapping("/list/all") - public R queryAll(@RequestParam Map<String, Object> params){ - List<IndexDataClockEntity> data = indexDataClockService.queryList(params); - return R.ok().put("data", data); - } - - /** - * 新增时钟配置 - * - * @param indexDataClockEntity - * @return - */ - @PostMapping("/add") - public R add(@RequestBody IndexDataClockEntity indexDataClockEntity) { - int count = indexDataClockService.cheack(indexDataClockEntity); - if (count > 0) { - return R.error("名称或编号重复"); - } - indexDataClockEntity.setCreateBy(SecurityFrameworkUtils.getLoginUserId().toString()); - indexDataClockEntity.setCreateTime(new Date()); - indexDataClockService.add(indexDataClockEntity); - return R.ok(); - } - - /** - * 更新时钟配置 - * - * @param indexDataClockEntity - * @return - */ - @PostMapping("/update") - public R update(@RequestBody IndexDataClockEntity indexDataClockEntity) { - int count = indexDataClockService.cheack(indexDataClockEntity); - if (count > 0) { - return R.error("名称或编号重复"); - } - indexDataClockEntity.setUpdateBy(SecurityFrameworkUtils.getLoginUserId().toString()); - indexDataClockService.update(indexDataClockEntity); - return R.ok(); - } - - /** - * 删除时钟配置 - * - * @param params - * @return - */ - @PostMapping("/delete") - public R delete(@RequestParam Map<String, Object> params) { - String id = (String)params.get("id"); - indexDataClockService.deleteById(id); - return R.ok(); - } - - /** - * 时钟配置详情 - * - * @param id - * @return - */ - @RequestMapping("/info/{id}") - public R info(@PathVariable("id") String id){ - IndexDataClockEntity indexDataClockEntity = indexDataClockService.getInfoById(id); - return R.ok().put("data", indexDataClockEntity); - } -} diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/indexdata/controller/admin/IndexDataItemController.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/indexdata/controller/admin/IndexDataItemController.java deleted file mode 100644 index 0c80f84..0000000 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/indexdata/controller/admin/IndexDataItemController.java +++ /dev/null @@ -1,93 +0,0 @@ -package com.iailab.module.data.indexdata.controller.admin; - -import com.iailab.module.data.common.utils.PageUtils; -import com.iailab.module.data.common.utils.R; -import com.iailab.framework.security.core.util.SecurityFrameworkUtils; -import com.iailab.module.data.indexdata.service.IndexDataItemService; -import com.iailab.module.data.indexdata.entity.IndexDataItemEntity; -import javax.annotation.Resource; -import org.springframework.web.bind.annotation.*; - -import java.util.Date; -import java.util.Map; - -/** - * @author PanZhibao - * @Description - * @createTime 2022年09月08日 21:53:00 - */ -@RestController -@RequestMapping("/data/index-data/item") -public class IndexDataItemController { - @Resource - private IndexDataItemService indexDataItemService; - - /** - * 所有数据项目列表 - */ - @GetMapping("/list") - public R list(@RequestParam Map<String, Object> params){ - PageUtils page = indexDataItemService.queryPage(params); - return R.ok().put("page", page); - } - - /** - * 新增数据项目 - * - * @param enity - * @return - */ - @PostMapping("/add") - public R add(@RequestBody IndexDataItemEntity enity) { - enity.setId(null); - int count = indexDataItemService.cheack(enity); - if (count > 0) { - return R.error("名称或编号重复"); - } - enity.setCreateBy(SecurityFrameworkUtils.getLoginUserId().toString()); - enity.setCreateTime(new Date()); - indexDataItemService.add(enity); - return R.ok(); - } - - /** - * 更新数据项目 - * - * @param enity - * @return - */ - @PostMapping("/update") - public R update(@RequestBody IndexDataItemEntity enity) { - int count = indexDataItemService.cheack(enity); - if (count > 0) { - return R.error("名称或编号重复"); - } - enity.setUpdateBy(SecurityFrameworkUtils.getLoginUserId().toString()); - indexDataItemService.update(enity); - return R.ok(); - } - - /** - * 删除数据项目 - * - * @param ids - * @return - */ - @PostMapping("/delete") - public R delete(@RequestBody String[] ids) { - indexDataItemService.deleteBatch(ids); - return R.ok(); - } - - /** - * 数据项目详情 - * - * @param id - * @return - */ - @RequestMapping("/info/{id}") - public R info(@PathVariable("id") String id){ - IndexDataItemEntity enity = indexDataItemService.getInfoById(id); - return R.ok().put("data", enity); - } -} diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/indexdata/controller/admin/IndexDataValueController.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/indexdata/controller/admin/IndexDataValueController.java deleted file mode 100644 index b7c284b..0000000 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/indexdata/controller/admin/IndexDataValueController.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.iailab.module.data.indexdata.controller.admin; - -import com.iailab.module.data.common.utils.PageUtils; -import com.iailab.module.data.common.utils.R; -import com.iailab.module.data.indexdata.service.IndexDataValueService; -import javax.annotation.Resource; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; - -import java.util.Map; - -/** - * @author PanZhibao - * @Description - * @createTime 2022年09月08日 21:53:00 - */ -@RestController -@RequestMapping("/data/index-data/value") -public class IndexDataValueController { - - @Resource - private IndexDataValueService indexDataValueService; - - /** - * 所有数据值列表 - */ - @GetMapping("/list") - public R list(@RequestParam Map<String, Object> params){ - PageUtils page = indexDataValueService.queryPage(params); - return R.ok().put("page", page); - } -} diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/indexdata/controller/package-info.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/indexdata/controller/package-info.java deleted file mode 100644 index 6855a76..0000000 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/indexdata/controller/package-info.java +++ /dev/null @@ -1 +0,0 @@ -package com.iailab.module.data.indexdata.controller; \ No newline at end of file diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/indexdata/dao/IndexDataClockDao.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/indexdata/dao/IndexDataClockDao.java deleted file mode 100644 index 48bad3b..0000000 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/indexdata/dao/IndexDataClockDao.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.iailab.module.data.indexdata.dao; - -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.iailab.module.data.indexdata.entity.IndexDataClockEntity; -import org.apache.ibatis.annotations.Mapper; - -/** - * @author PanZhibao - * @Description - * @createTime 2022年09月08日 21:36:00 - */ -@Mapper -public interface IndexDataClockDao extends BaseMapper<IndexDataClockEntity> { -} diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/indexdata/dao/IndexDataItemDao.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/indexdata/dao/IndexDataItemDao.java deleted file mode 100644 index 9761202..0000000 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/indexdata/dao/IndexDataItemDao.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.iailab.module.data.indexdata.dao; - -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.iailab.module.data.indexdata.entity.IndexDataItemEntity; -import org.apache.ibatis.annotations.Mapper; - -/** - * @author PanZhibao - * @Description - * @createTime 2022年09月08日 21:45:00 - */ -@Mapper -public interface IndexDataItemDao extends BaseMapper<IndexDataItemEntity> { -} diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/indexdata/dao/IndexDataValueDao.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/indexdata/dao/IndexDataValueDao.java deleted file mode 100644 index ced54b6..0000000 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/indexdata/dao/IndexDataValueDao.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.iailab.module.data.indexdata.dao; - -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.iailab.module.data.indexdata.entity.IndexDataValueEntity; -import com.iailab.module.data.indexdata.entity.IndexDataValueEntity; -import com.iailab.module.data.indexdata.entity.IndexDataValueEntity; -import com.iailab.module.data.indexdata.entity.IndexDataValueEntity; -import org.apache.ibatis.annotations.Mapper; - -/** - * @author PanZhibao - * @Description - * @createTime 2022年09月08日 21:45:00 - */ -@Mapper -public interface IndexDataValueDao extends BaseMapper<IndexDataValueEntity> { -} diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/indexdata/entity/IndexDataClockEntity.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/indexdata/entity/IndexDataClockEntity.java deleted file mode 100644 index 86dc14e..0000000 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/indexdata/entity/IndexDataClockEntity.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.iailab.module.data.indexdata.entity; - -import com.baomidou.mybatisplus.annotation.IdType; -import com.baomidou.mybatisplus.annotation.TableField; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; -import com.iailab.framework.excel.core.annotations.DictFormat; -import lombok.Data; - -import java.util.Date; - -/** - * @author PanZhibao - * @Description - * @createTime 2022年09月08日 18:26:00 - */ -@Data -@TableName("t_index_data_clock") -public class IndexDataClockEntity { - - /** - * ID - */ - @TableId(type = IdType.ASSIGN_ID) - private String id; - - /** - * 时钟代码 - */ - private String clockCode; - - /** - * 时钟名称 - */ - private String clockName; - - /** - * 类别 - */ - private String clockType; - - /** - * 类别 - */ - @DictFormat("clock-type") - @TableField(exist = false) - private String clockTypeName; - - /** - * 描述 - */ - private String description; - - /** - * 状态 - */ - private Integer status; - - /** - * 状态 - */ - @DictFormat("enable") - @TableField(exist = false) - private String statusName; - - /** - * 创建人 - */ - private String createBy; - - /** - * 创建时间 - */ - private Date createTime; - - /** - * 更新人 - */ - private String updateBy; - - /** - * 更新时间 - */ - private Date updateTime; -} diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/indexdata/entity/IndexDataItemEntity.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/indexdata/entity/IndexDataItemEntity.java deleted file mode 100644 index 7fe6d71..0000000 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/indexdata/entity/IndexDataItemEntity.java +++ /dev/null @@ -1,184 +0,0 @@ -package com.iailab.module.data.indexdata.entity; - -import com.baomidou.mybatisplus.annotation.IdType; -import com.baomidou.mybatisplus.annotation.TableField; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; -import com.iailab.framework.excel.core.annotations.DictFormat; -import lombok.Data; - -import java.math.BigDecimal; -import java.util.Date; - -/** - * @author PanZhibao - * @Description - * @createTime 2022年09月08日 18:28:00 - */ -@Data -@TableName("t_index_data_item") -public class IndexDataItemEntity { - - /** - * ID - */ - @TableId(type = IdType.ASSIGN_ID) - private String id; - - /** - * 所属公司 - */ - private String unit2; - - /** - * 所属公司 - */ - //@Dict(dicCode = "unit2", itemValue = "unit2") - @TableField(exist = false) - private String unit2Name; - - /** - * 所属单位 - */ - private String ssdw; - - /** - * 所属单位 - */ - //@Dict(dicCode = "ssdw", itemValue = "ssdw") - @TableField(exist = false) - private String ssdwName; - - /** - * 项目代码 - */ - private String itemCode; - - /** - * 项目名称 - */ - private String itemName; - - /** - * 点编码 - */ - private String pointCode; - - /** - * 点名称 - */ - private String pointName; - - /** - * 类别 - */ - private String itemType; - - /** - * 类别 - */ - @DictFormat("data-item-type") - @TableField(exist = false) - private String itemTypeName; - - /** - * 默认值 - */ - private BigDecimal defaultValue; - - /** - * 描述 - */ - private String description; - - /** - * 单位 - */ - private String unit; - - /** - * 配置时间 - */ - private String clockConfig; - - /** - * 班次 - */ - private String bc; - - /** - * 班次 - */ - @DictFormat("bc") - @TableField(exist = false) - private String bcName; - - /** - * 系统 - */ - private String xtCode; - - /** - * 系统 - */ - @DictFormat("scxt") - @TableField(exist = false) - private String xtName; - - /** - * 拓展字段1 - */ - private String ext1; - - /** - * 拓展字段2 - */ - private String ext2; - - /** - * 拓展字段3 - */ - private String ext3; - - /** - * 拓展字段4 - */ - private String ext4; - - /** - * 拓展字段5 - */ - private String ext5; - - /** - * 状态 - */ - private Integer status; - - /** - * 状态 - */ - @DictFormat("enable") - @TableField(exist = false) - private String statusName; - - /** - * 创建人 - */ - private String createBy; - - /** - * 创建时间 - */ - private Date createTime; - - /** - * 更新人 - */ - private String updateBy; - - /** - * 更新时间 - */ - private Date updateTime; -} diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/indexdata/entity/IndexDataValueEntity.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/indexdata/entity/IndexDataValueEntity.java deleted file mode 100644 index 332917d..0000000 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/indexdata/entity/IndexDataValueEntity.java +++ /dev/null @@ -1,121 +0,0 @@ -package com.iailab.module.data.indexdata.entity; - -import com.baomidou.mybatisplus.annotation.IdType; -import com.baomidou.mybatisplus.annotation.TableField; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; -import com.iailab.framework.excel.core.annotations.DictFormat; -import lombok.Data; - -import java.math.BigDecimal; -import java.util.Date; - -/** - * @author PanZhibao - * @Description - * @createTime 2022年09月08日 18:30:00 - */ -@Data -@TableName("t_index_data_value") -public class IndexDataValueEntity { - - /** - * ID - */ - @TableId(type = IdType.ASSIGN_ID) - private String id; - - /** - * 配置ID - */ - private String configId; - - /** - * 所属公司 - */ - private String unit2; - - /** - * 所属公司 - */ - @DictFormat("unit2") - @TableField(exist = false) - private String unit2Name; - - /** - * 所属单位 - */ - private String ssdw; - - /** - * 所属单位 - */ - @DictFormat("ssdw") - @TableField(exist = false) - private String ssdwName; - - /** - * 项目代码 - */ - private String itemCode; - - /** - * 项目名称 - */ - private String itemName; - - /** - * 单位 - */ - private String unit; - - /** - * 时间 - */ - private String clock; - - /** - * 累计值 - */ - private BigDecimal sumValue; - - /** - * 平均值 - */ - private BigDecimal avgValue; - - /** - * 上报值 - */ - private BigDecimal reportValue; - - /** - * 上报小时值 - */ - private BigDecimal reportHourValue; - - /** - * 采集值 - */ - private BigDecimal collectValue; - - /** - * 采集小时值 - */ - private BigDecimal collectHourValue; - - /** - * 启动次数 - */ - private BigDecimal startUpTimes; - - /** - * 创建时间 - */ - private Date createTime; - - /** - * 更新时间 - */ - private Date updateTime; -} diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/indexdata/service/IndexDataClockService.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/indexdata/service/IndexDataClockService.java deleted file mode 100644 index 1147bd5..0000000 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/indexdata/service/IndexDataClockService.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.iailab.module.data.indexdata.service; - -import com.iailab.module.data.common.utils.PageUtils; -import com.iailab.module.data.indexdata.entity.IndexDataClockEntity; - -import java.util.List; -import java.util.Map; - -/** - * @author PanZhibao - * @Description - * @createTime 2022年09月08日 21:47:00 - */ -public interface IndexDataClockService { - - PageUtils queryPage(Map<String, Object> params); - - List<IndexDataClockEntity> queryList(Map<String, Object> params); - - void add(IndexDataClockEntity indexDataClockEntity); - - void update(IndexDataClockEntity indexDataClockEntity); - - void deleteById(String id); - - IndexDataClockEntity getInfoById(String id); - - IndexDataClockEntity getInfoByCode(String clockCode); - - int cheack(IndexDataClockEntity idexDataClockEntity); -} diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/indexdata/service/IndexDataItemService.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/indexdata/service/IndexDataItemService.java deleted file mode 100644 index 22d6369..0000000 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/indexdata/service/IndexDataItemService.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.iailab.module.data.indexdata.service; - -import com.iailab.module.data.common.utils.PageUtils; -import com.iailab.module.data.indexdata.entity.IndexDataItemEntity; - -import java.util.List; -import java.util.Map; - -/** - * @author PanZhibao - * @Description - * @createTime 2022年09月08日 21:47:00 - */ -public interface IndexDataItemService { - - PageUtils queryPage(Map<String, Object> params); - - List<IndexDataItemEntity> getListByClockConfig(String clockConfig); - - void add(IndexDataItemEntity enity); - - void update(IndexDataItemEntity enity); - - void deleteById(String id); - - void deleteBatch(String[] ids); - - IndexDataItemEntity getInfoById(String id); - - int cheack(IndexDataItemEntity enity); -} diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/indexdata/service/IndexDataValueService.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/indexdata/service/IndexDataValueService.java deleted file mode 100644 index cab2841..0000000 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/indexdata/service/IndexDataValueService.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.iailab.module.data.indexdata.service; - -import com.iailab.module.data.common.utils.PageUtils; -import com.iailab.module.data.indexdata.entity.IndexDataValueEntity; - -import java.util.Map; - -/** - * @author PanZhibao - * @Description - * @createTime 2022年09月08日 21:48:00 - */ -public interface IndexDataValueService { - - PageUtils queryPage(Map<String, Object> params); - - void add(IndexDataValueEntity indexDataValueEntity); -} diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/indexdata/service/impl/IndexDataClockServiceImpl.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/indexdata/service/impl/IndexDataClockServiceImpl.java deleted file mode 100644 index 176952f..0000000 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/indexdata/service/impl/IndexDataClockServiceImpl.java +++ /dev/null @@ -1,87 +0,0 @@ -package com.iailab.module.data.indexdata.service.impl; - -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.iailab.module.data.common.enums.CommonConstant; -import com.iailab.module.data.common.utils.PageUtils; -import com.iailab.module.data.common.utils.Query; -import com.iailab.module.data.indexdata.dao.IndexDataClockDao; -import com.iailab.module.data.indexdata.entity.IndexDataClockEntity; -import com.iailab.module.data.indexdata.service.IndexDataClockService; -import org.apache.commons.lang3.StringUtils; -import org.springframework.stereotype.Service; - -import java.util.List; -import java.util.Map; - -/** - * @author PanZhibao - * @Description - * @createTime 2022年09月08日 21:49:00 - */ -@Service -public class IndexDataClockServiceImpl extends ServiceImpl<IndexDataClockDao, IndexDataClockEntity> implements IndexDataClockService { - - @Override - public PageUtils queryPage(Map<String, Object> params) { - String clockCode = (String)params.get("clockCode"); - String clockName = (String)params.get("clockName"); - - IPage<IndexDataClockEntity> page = this.page( - new Query<IndexDataClockEntity>().getPage(params), - new QueryWrapper<IndexDataClockEntity>() - .like(StringUtils.isNotBlank(clockCode),"clock_code", clockCode) - .like(StringUtils.isNotBlank(clockName),"clock_name", clockName) - .orderByDesc("create_time") - ); - return new PageUtils(page); - } - - @Override - public List<IndexDataClockEntity> queryList(Map<String, Object> params) { - return getBaseMapper().selectList( - new QueryWrapper<IndexDataClockEntity>().eq("status", CommonConstant.IS_ENABLE) - .orderByDesc("create_time") - ); - } - - @Override - public void add(IndexDataClockEntity indexDataClockEntity) { - this.save(indexDataClockEntity); - } - - @Override - public void update(IndexDataClockEntity indexDataClockEntity) { - this.updateById(indexDataClockEntity); - } - - @Override - public void deleteById(String id) { - this.removeById(id); - } - - @Override - public IndexDataClockEntity getInfoById(String id) { - return this.getById(id); - } - - @Override - public IndexDataClockEntity getInfoByCode(String clockCode) { - return getBaseMapper().selectOne(new QueryWrapper<IndexDataClockEntity>() - .eq("clock_code", clockCode) - .eq("status", CommonConstant.IS_ENABLE)); - } - - @Override - public int cheack(IndexDataClockEntity indexDataClockEntity) { - String id = indexDataClockEntity.getId(); - String clockCode = indexDataClockEntity.getClockCode(); - String clockName = indexDataClockEntity.getClockName(); - QueryWrapper<IndexDataClockEntity> queryWrapper = new QueryWrapper<>(); - queryWrapper.ne(StringUtils.isNotBlank(id), "id", id); - queryWrapper.and(wrapper -> wrapper.eq("clock_code", clockCode).or(). - eq(StringUtils.isNotBlank(clockName),"clock_name", clockName)); - return (int)this.count(queryWrapper); - } -} diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/indexdata/service/impl/IndexDataItemServiceImpl.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/indexdata/service/impl/IndexDataItemServiceImpl.java deleted file mode 100644 index c0558a4..0000000 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/indexdata/service/impl/IndexDataItemServiceImpl.java +++ /dev/null @@ -1,86 +0,0 @@ -package com.iailab.module.data.indexdata.service.impl; - -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.iailab.module.data.common.enums.CommonConstant; -import com.iailab.module.data.common.utils.PageUtils; -import com.iailab.module.data.common.utils.Query; -import com.iailab.module.data.indexdata.dao.IndexDataItemDao; -import com.iailab.module.data.indexdata.service.IndexDataItemService; -import com.iailab.module.data.indexdata.entity.IndexDataItemEntity; -import org.apache.commons.lang3.StringUtils; -import org.springframework.stereotype.Service; - -import java.util.Arrays; -import java.util.List; -import java.util.Map; - -/** - * @author PanZhibao - * @Description - * @createTime 2022年09月08日 21:49:00 - */ -@Service -public class IndexDataItemServiceImpl extends ServiceImpl<IndexDataItemDao, IndexDataItemEntity> implements IndexDataItemService { - - @Override - public PageUtils queryPage(Map<String, Object> params) { - String itemCode = (String)params.get("itemCode"); - String itemName = (String)params.get("itemName"); - - IPage<IndexDataItemEntity> page = this.page( - new Query<IndexDataItemEntity>().getPage(params), - new QueryWrapper<IndexDataItemEntity>() - .like(StringUtils.isNotBlank(itemCode),"item_code", itemCode) - .like(StringUtils.isNotBlank(itemName),"item_name", itemName) - .orderByDesc("create_time") - ); - return new PageUtils(page); - } - - @Override - public List<IndexDataItemEntity> getListByClockConfig(String clockConfig) { - return getBaseMapper().selectList(new QueryWrapper<IndexDataItemEntity>() - .eq("clock_config", clockConfig) - .eq("status", CommonConstant.IS_ENABLE)); - - } - - @Override - public void add(IndexDataItemEntity enity) { - this.save(enity); - } - - @Override - public void update(IndexDataItemEntity enity) { - this.updateById(enity); - } - - @Override - public void deleteById(String id) { - this.removeById(id); - } - - @Override - public void deleteBatch(String[] ids) { - this.removeByIds(Arrays.asList(ids)); - } - - @Override - public IndexDataItemEntity getInfoById(String id) { - return this.getById(id); - } - - @Override - public int cheack(IndexDataItemEntity enity) { - String id = enity.getId(); - String itemCode = enity.getItemCode(); - String itemName = enity.getItemName(); - QueryWrapper<IndexDataItemEntity> queryWrapper = new QueryWrapper<>(); - queryWrapper.ne(StringUtils.isNotBlank(id), "id", id); - queryWrapper.and(wrapper -> wrapper.eq("item_code", itemCode).or(). - eq(StringUtils.isNotBlank(itemName),"item_name", itemName)); - return (int)this.count(queryWrapper); - } -} diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/indexdata/service/impl/IndexDataValueServiceImpl.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/indexdata/service/impl/IndexDataValueServiceImpl.java deleted file mode 100644 index b49a921..0000000 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/indexdata/service/impl/IndexDataValueServiceImpl.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.iailab.module.data.indexdata.service.impl; - -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.iailab.module.data.common.utils.PageUtils; -import com.iailab.module.data.common.utils.Query; -import com.iailab.module.data.indexdata.dao.IndexDataValueDao; -import com.iailab.module.data.indexdata.entity.IndexDataValueEntity; -import com.iailab.module.data.indexdata.service.IndexDataValueService; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.util.Map; - -/** - * @author PanZhibao - * @Description - * @createTime 2022年09月08日 21:49:00 - */ - -@Slf4j -@Service -public class IndexDataValueServiceImpl extends ServiceImpl<IndexDataValueDao, IndexDataValueEntity> implements IndexDataValueService { - - @Override - public PageUtils queryPage(Map<String, Object> params) { - String clock = (String)params.get("clock"); - String itemCode = (String)params.get("itemCode"); - - IPage<IndexDataValueEntity> page = this.page( - new Query<IndexDataValueEntity>().getPage(params), - new QueryWrapper<IndexDataValueEntity>() - .like(StringUtils.isNotBlank(clock),"clock", clock) - .like(StringUtils.isNotBlank(itemCode),"item_code", itemCode) - .orderByDesc("create_time") - ); - return new PageUtils(page); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void add(IndexDataValueEntity indexDataValueEntity) { - log.info("插入指标数据表2"); - getBaseMapper().delete(new QueryWrapper<IndexDataValueEntity>() - .eq("unit2", indexDataValueEntity.getUnit2()) - .eq("ssdw", indexDataValueEntity.getSsdw()) - .eq("item_code", indexDataValueEntity.getItemCode()) - .eq("clock", indexDataValueEntity.getClock())); - - this.save(indexDataValueEntity); - } -} diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/job/init/JobCommandLineRunner.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/job/init/JobCommandLineRunner.java index cd15b19..7c8c632 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/job/init/JobCommandLineRunner.java +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/job/init/JobCommandLineRunner.java @@ -1,23 +1,9 @@ -/** - * Copyright (c) 2018 人人开源 All rights reserved. - * - * https://www.renren.io - * - * 版权所有,侵权必究! - */ - package com.iailab.module.data.job.init; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.iailab.module.data.job.entity.ScheduleJobEntity; import com.iailab.module.data.job.utils.ScheduleUtils; -import com.iailab.module.data.job.entity.ScheduleJobEntity; -import com.iailab.module.data.job.utils.ScheduleUtils; import com.iailab.module.data.job.dao.ScheduleJobDao; -import com.iailab.module.data.job.entity.ScheduleJobEntity; -import com.iailab.module.data.job.utils.ScheduleUtils; -import com.iailab.module.data.job.entity.ScheduleJobEntity; -import com.iailab.module.data.job.utils.ScheduleUtils; import org.quartz.CronTrigger; import org.quartz.Scheduler; import javax.annotation.Resource; @@ -28,8 +14,6 @@ /** * 初始化定时任务数据 - * - * @author Mark sunlightcs@gmail.com */ @Component public class JobCommandLineRunner implements CommandLineRunner { diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/job/task/HttpCollectDeviceTask.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/job/task/HttpCollectDeviceTask.java deleted file mode 100644 index 3e93df7..0000000 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/job/task/HttpCollectDeviceTask.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.iailab.module.data.job.task; - -import com.iailab.module.data.common.enums.CommonConstant; -import com.iailab.module.data.http.collector.HttpCollectorForSD; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import javax.annotation.Resource; -import org.springframework.stereotype.Component; - -import java.time.LocalDateTime; -import java.util.HashMap; -import java.util.Map; - -/** - *山大设备设备列表数据采集 - * - * @author lirm - * @Description - * @createTime 2024年05月21日 - */ -@Component("httpCollectDeviceTask") -public class HttpCollectDeviceTask implements ITask { - private Logger logger = LoggerFactory.getLogger(getClass()); - - @Resource - private HttpCollectorForSD httpCollectorForSD; - - @Override - public void run(String params) { - logger.info("HttpCollectDeviceTask定时任务正在执行,参数为:{}", params); - try { - Map<String,String> map = new HashMap<>(); - map.put("code", CommonConstant.HTTP_API_SD_DEVICE_LIST); - map.put("token", "914df3ebd91bc54b5b294f13477f497611d278aa4a8727249f8490cb274a0ed9"); - httpCollectorForSD.getDeviceList(map); - logger.info("HttpCollectDeviceTask定时任务完成时间:" + LocalDateTime.now()); - } catch (Exception ex) { - ex.printStackTrace(); - logger.info("HttpCollectDeviceTask定时任务失败时间:" + LocalDateTime.now()); - } - } -} diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/job/task/HttpCollectHealthStateTask.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/job/task/HttpCollectHealthStateTask.java deleted file mode 100644 index 4d3c0e3..0000000 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/job/task/HttpCollectHealthStateTask.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.iailab.module.data.job.task; - -import com.iailab.module.data.common.enums.CommonConstant; -import com.iailab.module.data.http.collector.HttpCollectorForSD; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import javax.annotation.Resource; -import org.springframework.stereotype.Component; - -import java.time.LocalDateTime; -import java.util.HashMap; -import java.util.Map; - -/** - *山大设备健康状态数据采集 - * - * @author lirm - * @Description - * @createTime 2024年05月21日 - */ -@Component("httpCollectHealthStateTask") -public class HttpCollectHealthStateTask implements ITask { - private Logger logger = LoggerFactory.getLogger(getClass()); - - @Resource - private HttpCollectorForSD httpCollectorForSD; - - @Override - public void run(String params) { - logger.info("HttpCollectHealthStateTask定时任务正在执行,参数为:{}", params); - try { - Map<String,String> map = new HashMap<>(); - map.put("cu_ids", "3"); - map.put("t", "1716274632482"); - map.put("code", CommonConstant.HTTP_API_SD_HEALTH_STATE); - map.put("client_id", "sd"); - map.put("X-Forwarded-OrgSet", "1000000000000003"); - map.put("X-Forwarded-PrId", "300005001,300005002"); - map.put("X-Request-Id", "-c8048bc7-a206-4f71-a512-d6ade2272289"); - httpCollectorForSD.getHealthStateValue(map); - logger.info("HttpCollectHealthStateTask定时任务完成时间:" + LocalDateTime.now()); - } catch (Exception ex) { - ex.printStackTrace(); - logger.info("HttpCollectHealthStateTask定时任务失败时间:" + LocalDateTime.now()); - } - } -} diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/job/task/HttpCollectRunStateTask.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/job/task/HttpCollectRunStateTask.java deleted file mode 100644 index 8a5046f..0000000 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/job/task/HttpCollectRunStateTask.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.iailab.module.data.job.task; - -import com.iailab.module.data.common.enums.CommonConstant; -import com.iailab.module.data.http.collector.HttpCollectorForSD; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import javax.annotation.Resource; -import org.springframework.stereotype.Component; - -import java.time.LocalDateTime; -import java.util.HashMap; -import java.util.Map; - -/** - *山大设备运行状态数据采集 - * - * @author lirm - * @Description - * @createTime 2024年05月21日 - */ -@Component("httpCollectRunStateTask") -public class HttpCollectRunStateTask implements ITask { - private Logger logger = LoggerFactory.getLogger(getClass()); - - @Resource - private HttpCollectorForSD httpCollectorForSD; - - @Override - public void run(String params) { - logger.info("HttpCollectRunStateTask定时任务正在执行,参数为:{}", params); - try { - Map<String,String> map = new HashMap<>(); - map.put("cu_ids", "3"); - map.put("t", "1716274632482"); - map.put("code", CommonConstant.HTTP_API_SD_RUN_STATE); - map.put("client_id", "sd"); - map.put("X-Forwarded-OrgSet", "1000000000000003"); - map.put("X-Forwarded-PrId", "300002001,300002002"); - map.put("X-Request-Id", "-3cfeef03-9f1f-48bb-98ec-5494012081d1"); - httpCollectorForSD.getRunStateValue(map); - logger.info("HttpCollectRunStateTask定时任务完成时间:" + LocalDateTime.now()); - } catch (Exception ex) { - ex.printStackTrace(); - logger.info("HttpCollectRunStateTask定时任务失败时间:" + LocalDateTime.now()); - } - } -} diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/job/task/HttpCollectTemperatureTask.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/job/task/HttpCollectTemperatureTask.java deleted file mode 100644 index ada255d..0000000 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/job/task/HttpCollectTemperatureTask.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.iailab.module.data.job.task; - -import com.iailab.module.data.common.enums.CommonConstant; -import com.iailab.module.data.http.collector.HttpCollectorForSD; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import javax.annotation.Resource; -import org.springframework.stereotype.Component; - -import java.time.LocalDateTime; -import java.util.Calendar; -import java.util.HashMap; -import java.util.Map; - -/** - *山大设备温度 振动数据采集 - * - * @author lirm - * @Description - * @createTime 2024年6月3日 - */ -@Component("httpCollectTemperatureTask") -public class HttpCollectTemperatureTask implements ITask { - private Logger logger = LoggerFactory.getLogger(getClass()); - - @Resource - private HttpCollectorForSD httpCollectorForSD; - - @Override - public void run(String params) { - logger.info("HttpCollectTemperatureTask定时任务正在执行,参数为:{}", params); - Calendar calendar = Calendar.getInstance(); - calendar.set(Calendar.MILLISECOND, 0); - calendar.set(Calendar.SECOND, 0); - try { - Map<String,String> map = new HashMap<>(); - map.put("code", CommonConstant.HTTP_API_SD_DEVICE_TEMPERATURE); - map.put("X-Forwarded-OrgSet", "1000000000000003"); - map.put("client_id", "sd"); - httpCollectorForSD.getTemperatureValue(map, calendar.getTime()); - logger.info("HttpCollectTemperatureTask定时任务完成时间:" + LocalDateTime.now()); - } catch (Exception ex) { - ex.printStackTrace(); - logger.info("HttpCollectTemperatureTask定时任务失败时间:" + LocalDateTime.now()); - } - } -} diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/job/task/HttpCollectUserTask.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/job/task/HttpCollectUserTask.java deleted file mode 100644 index c5fc2a7..0000000 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/job/task/HttpCollectUserTask.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.iailab.module.data.job.task; - -import com.iailab.module.data.common.enums.CommonConstant; -import com.iailab.module.data.http.collector.HttpCollectorForUser; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import javax.annotation.Resource; -import org.springframework.stereotype.Component; - -import java.time.LocalDateTime; -import java.util.HashMap; -import java.util.Map; - -/** - * 同步用户 - * 0 0 12 2 * ? - * - * - * @author lirm - * @Description - * @createTime 2024年05月21日 - */ -@Component("httpCollectUserTask") -public class HttpCollectUserTask implements ITask { - private Logger logger = LoggerFactory.getLogger(getClass()); - - @Resource - private HttpCollectorForUser httpCollectorForUser; - - @Override - public void run(String params) { - logger.info("HttpCollectUserTask定时任务正在执行,参数为:{}", params); - try { - Map<String,String> map1 = new HashMap<>(); - map1.put("code", CommonConstant.HTTP_API_JOB_LIST); - httpCollectorForUser.saveJobInfo(map1); - Map<String,String> map2 = new HashMap<>(); - map2.put("code", CommonConstant.HTTP_API_PERSON_LIST); - httpCollectorForUser.saveUserInfo(map2); - logger.info("HttpCollectUserTask定时任务完成时间:" + LocalDateTime.now()); - } catch (Exception ex) { - ex.printStackTrace(); - logger.info("HttpCollectUserTask定时任务失败时间:" + LocalDateTime.now()); - } - } -} diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/job/task/HttpTokenTask.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/job/task/HttpTokenTask.java deleted file mode 100644 index 92e120e..0000000 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/job/task/HttpTokenTask.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.iailab.module.data.job.task; - -import com.iailab.module.data.common.enums.CommonConstant; -import com.iailab.module.data.http.service.HttpTokenService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import javax.annotation.Resource; -import org.springframework.stereotype.Component; - -import java.time.LocalDateTime; - -/** - * 更新httpToken - * 每天更新一次,token每两天过期 - * - * @author lirm - * @Description - * @createTime 2024年05月21日 - */ -@Component("httpTokenTask") -public class HttpTokenTask implements ITask { - private Logger logger = LoggerFactory.getLogger(getClass()); - - @Resource - HttpTokenService httpTokenService; - - @Override - public void run(String params) { - logger.info("httpTokenTask定时任务正在执行,参数为:{}", params); - - try { - logger.info("clientId=" + CommonConstant.HTTP_CLIENT_ID_SD); - httpTokenService.updateToken(CommonConstant.HTTP_CLIENT_ID_SD); - logger.info("httpTokenTask定时任务完成时间:" + LocalDateTime.now()); - } catch (Exception ex) { - ex.printStackTrace(); - logger.info("httpTokenTask定时任务失败时间:" + LocalDateTime.now()); - } - } -} diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/MeasureHandle.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/MeasureHandle.java index 44850d5..c9af776 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/MeasureHandle.java +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/MeasureHandle.java @@ -1,5 +1,6 @@ package com.iailab.module.data.point.collection.handler; +import com.iailab.module.data.channel.opcda.collector.OpcDACollector; import com.iailab.module.data.common.enums.CommonConstant; import com.iailab.module.data.common.enums.DataSourceType; import com.iailab.module.data.common.enums.DataTypeEnum; @@ -12,10 +13,11 @@ import com.iailab.module.data.point.dto.DaPointDTO; import com.iailab.module.data.point.service.DaPointService; import com.iailab.module.data.http.collector.HttpCollectorForZxzk; -import com.iailab.module.data.http.service.impl.HttpTagCollector; import com.iailab.module.data.influxdb.pojo.InfluxPointValuePOJO; import lombok.extern.slf4j.Slf4j; import javax.annotation.Resource; + +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; @@ -46,8 +48,8 @@ @Resource private OpcUaCollector opcUaCollector; - @Resource - private HttpTagCollector httpTagCollector; + @Autowired + private OpcDACollector opcDACollector; @Resource private HttpCollectorForZxzk httpCollectorForZxzk; @@ -62,74 +64,43 @@ return result; } - List<String[]> opcuaTagIds = new ArrayList<>(); + List<String[]> opcUaTagIds = new ArrayList<>(); List<String[]> opcDaTagIds = new ArrayList<>(); List<String[]> modbusTagIds = new ArrayList<>(); List<String[]> kioTagIds = new ArrayList<>(); List<String[]> httpTagZxzk = new ArrayList<>(); - List<String> tagYearPeiIds = new ArrayList<>(); - List<String> tagCurrentPerformanceIds = new ArrayList<>(); - List<String> tagCurrentSaleIds = new ArrayList<>(); - List<String> tagPrdTimeDistIds = new ArrayList<>(); - dtos.stream().forEach(item -> { if (DataSourceType.OPCUA.getCode().equals(item.getSourceType())) { - opcuaTagIds.add(new String[]{item.getSourceId(), item.getTagNo()}); + opcUaTagIds.add(new String[]{item.getSourceId(), item.getTagNo()}); } else if (DataSourceType.OPCDA.getCode().equals(item.getSourceType())) { opcDaTagIds.add(new String[]{item.getSourceId(), item.getTagNo()}); } else if (DataSourceType.ModBus.getCode().equals(item.getSourceType())) { modbusTagIds.add(new String[]{item.getSourceId(), item.getTagNo()}); } else if (DataSourceType.KIO.getCode().equals(item.getSourceType())) { kioTagIds.add(new String[]{item.getSourceId(), item.getTagNo()}); - } else if (DataSourceType.HTTP.getCode().equals(item.getSourceType())) { - if (CommonConstant.YEAR_PEI_HTTP_TAG.equals(item.getSourceId())) { - tagYearPeiIds.add(item.getTagNo()); - } else if (CommonConstant.CURRENT_PERFORMANCE_HTTP_TAG.equals(item.getSourceId())) { - tagCurrentPerformanceIds.add(item.getTagNo()); - } else if (CommonConstant.CURRENT_SALE_HTTP_TAG.equals(item.getSourceId())) { - tagCurrentSaleIds.add(item.getTagNo()); - } else if (CommonConstant.PRD_TIME_DIST_HTTP_TAG.equals(item.getSourceId())) { - tagPrdTimeDistIds.add(item.getTagNo()); - } else if (CommonConstant.HTTP_API_ZXZK_IH.equals(item.getSourceName())) { - httpTagZxzk.add(new String[]{item.getSourceId(), item.getTagNo()}); - } } }); - if (!CollectionUtils.isEmpty(opcuaTagIds)) { - Map<String, Object> tagValues = opcUaCollector.getTagValues(opcuaTagIds); - this.toCommonResult(collectTime, dtos, tagValues, dataMap, result); + Map<String, Object> tagValues = new HashMap<>(); + if (!CollectionUtils.isEmpty(opcUaTagIds)) { + tagValues.putAll(opcUaCollector.getTagValues(opcUaTagIds)); } if (!CollectionUtils.isEmpty(opcDaTagIds)) { + tagValues.putAll(opcDACollector.getTagValues(modbusTagIds)); } if (!CollectionUtils.isEmpty(modbusTagIds)) { - Map<String, Object> tagValues = modBusCollector.getTagValues(modbusTagIds); - this.toCommonResult(collectTime, dtos, tagValues, dataMap, result); + tagValues.putAll(modBusCollector.getTagValues(modbusTagIds)); } if (!CollectionUtils.isEmpty(kioTagIds)) { - Map<String, Object> tagValues = kingIOCollector.getTagValues(kioTagIds); - this.toCommonResult(collectTime, dtos, tagValues, dataMap, result); + tagValues.putAll(kingIOCollector.getTagValues(kioTagIds)); } if (!CollectionUtils.isEmpty(httpTagZxzk)) { - Map<String, Object> tagValues = httpCollectorForZxzk.getTagValues(httpTagZxzk); - this.toCommonResult(collectTime, dtos, tagValues, dataMap, result); - } - if (!CollectionUtils.isEmpty(tagYearPeiIds)) { - Map<String, Object> tagValues = httpTagCollector.collect(CommonConstant.YEAR_PEI_HTTP_TAG, tagYearPeiIds); - this.toCommonResult(collectTime, dtos, tagValues, dataMap, result); - } else if (!CollectionUtils.isEmpty(tagCurrentPerformanceIds)) { - Map<String, Object> tagValues = httpTagCollector.collect(CommonConstant.CURRENT_PERFORMANCE_HTTP_TAG, tagCurrentPerformanceIds); - this.toCommonResult(collectTime, dtos, tagValues, dataMap, result); - } else if (!CollectionUtils.isEmpty(tagCurrentSaleIds)) { - Map<String, Object> tagValues = httpTagCollector.collect(CommonConstant.CURRENT_SALE_HTTP_TAG, tagCurrentSaleIds); - this.toCommonResult(collectTime, dtos, tagValues, dataMap, result); - } else if (!CollectionUtils.isEmpty(tagPrdTimeDistIds)) { - Map<String, Object> tagValues = httpTagCollector.collect(CommonConstant.PRD_TIME_DIST_HTTP_TAG, tagPrdTimeDistIds); - this.toCommonResult(collectTime, dtos, tagValues, dataMap, result); - } + tagValues.putAll(httpCollectorForZxzk.getTagValues(httpTagZxzk)); + } + this.toCommonResult(collectTime, dtos, tagValues, dataMap, result); log.info("测量点处理结束"); return result; } -- Gitblit v1.9.3