| | |
| | | server: |
| | | port: 48080 |
| | | servlet: |
| | | context-path: / |
| | | session: |
| | | timeout: 120s |
| | | |
| | |
| | | |
| | | import com.iailab.module.data.api.plan.dto.ApiPlanDataDTO; |
| | | import com.iailab.module.data.api.plan.dto.ApiPlanItemDTO; |
| | | import com.iailab.module.data.api.point.dto.ApiPointDTO; |
| | | import com.iailab.module.data.common.ApiDataQueryDTO; |
| | | import com.iailab.module.data.common.ApiDataValueDTO; |
| | | 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.GetMapping; |
| | | 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.*; |
| | | |
| | | import java.util.LinkedHashMap; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | |
| | | /** |
| | | * @author PanZhibao |
| | |
| | | LinkedHashMap<String, List<ApiPlanDataDTO>> queryPlanItemRecordValue(@RequestBody ApiDataQueryDTO dto); |
| | | |
| | | @GetMapping(PREFIX + "/info/no/{itemNo}") |
| | | @Operation(summary = "根据测点编号查询测点信息") |
| | | @Operation(summary = "根据编号查询计划数据信息") |
| | | ApiPlanItemDTO getInfoByNo(@PathVariable("itemNo") String itemNo); |
| | | |
| | | @GetMapping(PREFIX + "/info/id/{id}") |
| | | @Operation(summary = "根据测点编号查询测点信息") |
| | | @Operation(summary = "根据id查询计划数据信息") |
| | | ApiPlanItemDTO getInfoById(@PathVariable("id") String id); |
| | | |
| | | @PostMapping(PREFIX + "/info/ids") |
| | | @Operation(summary = "根据多个id查询计划数据信息") |
| | | List<ApiPlanItemDTO> getInfoByIds(@RequestParam("planIds") Set<String> planIds); |
| | | } |
| | |
| | | import org.springframework.cloud.openfeign.FeignClient; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.annotation.security.PermitAll; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | |
| | | /** |
| | | * @author PanZhibao |
| | |
| | | @Operation(summary = "根据测点ID查询测点信息") |
| | | ApiPointDTO getInfoById(@PathVariable("pointId") String pointId); |
| | | |
| | | @PostMapping(PREFIX + "/info/ids") |
| | | @Operation(summary = "根据多个测点ID查询测点信息") |
| | | List<ApiPointDTO> getInfoByIds(@RequestParam("pointNos") Set<String> pointIds); |
| | | |
| | | @PostMapping(PREFIX + "/query-points/real-value") |
| | | @Operation(summary = "查询多个测点当前值") |
| | | Map<String, Object> queryPointsRealValue(@RequestParam("pointNos") List<String> pointNos); |
| | |
| | | public class ApiPointDTO implements Serializable { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | @Schema(description = "id", required = true) |
| | | private String id; |
| | | |
| | | @Schema(description = "测点编码", required = true) |
| | | private String pointNo; |
| | | |
| | |
| | | import com.iailab.framework.common.util.object.ConvertUtils; |
| | | import com.iailab.module.data.api.plan.dto.ApiPlanDataDTO; |
| | | import com.iailab.module.data.api.plan.dto.ApiPlanItemDTO; |
| | | import com.iailab.module.data.api.point.dto.ApiPointDTO; |
| | | import com.iailab.module.data.common.ApiDataQueryDTO; |
| | | import com.iailab.module.data.common.ApiDataValueDTO; |
| | | import com.iailab.module.data.plan.item.collection.PlanItemCollector; |
| | |
| | | import org.springframework.web.bind.annotation.PathVariable; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | |
| | | /** |
| | | * @author PanZhibao |
| | |
| | | return ConvertUtils.sourceToTarget(entity, ApiPlanItemDTO.class); |
| | | } |
| | | |
| | | @Override |
| | | public List<ApiPlanItemDTO> getInfoByIds(Set<String> planIds) { |
| | | List<PlanItemEntity> plans = planItemService.getInfoByIds(planIds); |
| | | return ConvertUtils.sourceToTarget(plans,ApiPlanItemDTO.class); |
| | | } |
| | | |
| | | } |
| | |
| | | |
| | | @Override |
| | | public ApiPointDTO getInfoById(String pointId) { |
| | | return ConvertUtils.sourceToTarget(daPointService.getSimpleInfoById(pointId), ApiPointDTO.class); |
| | | return daPointService.getSimpleInfoById(pointId); |
| | | } |
| | | |
| | | @Override |
| | | public List<ApiPointDTO> getInfoByIds(Set<String> pointIds) { |
| | | List<ApiPointDTO> result = new ArrayList<>(pointIds.size()); |
| | | for (String pointId : pointIds) { |
| | | result.add(daPointService.getSimpleInfoById(pointId)); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | import com.iailab.framework.common.pojo.PageResult; |
| | | import com.iailab.framework.common.service.BaseService; |
| | | import com.iailab.module.data.api.plan.dto.ApiPlanItemDTO; |
| | | import com.iailab.module.data.plan.item.entity.PlanItemEntity; |
| | | import com.iailab.module.data.plan.item.vo.PlanItemDataVO; |
| | | import com.iailab.module.data.plan.item.vo.PlanItemPageReqVO; |
| | |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | |
| | | /** |
| | | * @author PanZhibao |
| | |
| | | void delete(String id); |
| | | |
| | | List<PlanItemDataVO> getSourceValue(Map<String, Object> params); |
| | | |
| | | List<PlanItemEntity> getInfoByIds(Set<String> planIds); |
| | | } |
| | |
| | | import com.iailab.framework.common.pojo.PageResult; |
| | | import com.iailab.framework.common.service.impl.BaseServiceImpl; |
| | | import com.iailab.framework.common.util.object.BeanUtils; |
| | | import com.iailab.module.data.api.plan.dto.ApiPlanItemDTO; |
| | | import com.iailab.module.data.plan.item.dao.PlanItemDao; |
| | | import com.iailab.module.data.plan.item.entity.PlanItemEntity; |
| | | import com.iailab.module.data.plan.item.service.PlanItemService; |
| | |
| | | public List<PlanItemDataVO> getSourceValue(Map<String, Object> params) { |
| | | return baseDao.getSourceValue(params); |
| | | } |
| | | |
| | | @Override |
| | | public List<PlanItemEntity> getInfoByIds(Set<String> planIds) { |
| | | return baseDao.selectBatchIds(planIds); |
| | | } |
| | | } |
| | |
| | | data.putAll(constantHandle.getCurrent(pointNos)); |
| | | data.putAll(measureHandle.getCurrent(pointNos)); |
| | | data.putAll(calculateHandle.getCurrent(pointNos)); |
| | | data.putAll(cumulateHandle.getCurrent(pointNos)); |
| | | return data; |
| | | } catch (Exception ex) { |
| | | return R.error(ex.getMessage()); |
| | |
| | | import com.iailab.module.data.influxdb.pojo.InfluxPointValuePOJO; |
| | | import com.iailab.module.data.point.collection.utils.GenInfluxPointValueUtils; |
| | | import com.iailab.module.data.point.dto.DaPointDTO; |
| | | import com.iailab.module.data.point.service.DaPointService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.util.*; |
| | | |
| | |
| | | @Slf4j |
| | | @Component |
| | | public class CumulateHandle { |
| | | |
| | | @Resource |
| | | private DaPointService daPointService; |
| | | |
| | | @Autowired |
| | | @Lazy |
| | |
| | | return result; |
| | | } |
| | | |
| | | public Map<String, Object> getCurrent(List<String> pointNos) { |
| | | Map<String, Object> data = new HashMap<>(); |
| | | List<DaPointDTO> pointMathList = daPointService.getCumulatePoint(pointNos); |
| | | if (CollectionUtils.isEmpty(pointMathList)) { |
| | | return data; |
| | | } |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.set(Calendar.MILLISECOND, 0); |
| | | pointMathList.forEach(item -> { |
| | | data.put(item.getPointNo(), singleCompute(item, calendar.getTime())); |
| | | }); |
| | | return data; |
| | | } |
| | | |
| | | |
| | | private Object singleCompute(DaPointDTO dto, Date collectTime) { |
| | | ApiPointDTO pointDTO = dataPointApi.getInfoByNo(dto.getMomentPoint()); |
| | |
| | | package com.iailab.module.data.point.service; |
| | | |
| | | import com.iailab.framework.common.pojo.PageResult; |
| | | import com.iailab.module.data.api.point.dto.ApiPointDTO; |
| | | import com.iailab.module.data.point.dto.DaPointDTO; |
| | | import com.iailab.module.data.point.vo.*; |
| | | |
| | |
| | | |
| | | DaPointDTO info(String id); |
| | | |
| | | DaPointDTO getSimpleInfoById(String id); |
| | | ApiPointDTO getSimpleInfoById(String id); |
| | | |
| | | DaPointDTO getSimpleInfoByNo(String no); |
| | | |
| | |
| | | |
| | | List<DaPointDTO> getCumulatePoint(String freq); |
| | | |
| | | List<DaPointDTO> getCumulatePoint(List<String> pointNos); |
| | | |
| | | List<DaPointDTO> getCumulatePoint(DaPointPageReqVO reqVO); |
| | | |
| | | DaPointDTO getByNo(String pointNo); |
| | |
| | | import com.iailab.framework.common.pojo.PageResult; |
| | | import com.iailab.framework.common.util.object.BeanUtils; |
| | | import com.iailab.framework.common.util.object.ConvertUtils; |
| | | import com.iailab.module.data.api.point.dto.ApiPointDTO; |
| | | import com.iailab.module.data.channel.common.service.ChannelSourceService; |
| | | import com.iailab.module.data.common.enums.CommonConstant; |
| | | import com.iailab.module.data.common.enums.IsEnableEnum; |
| | |
| | | @Resource |
| | | private DaPointCollectStatusService daPointCollectStatusService; |
| | | |
| | | private static Map<String, DaPointDTO> pointIdMap = new ConcurrentHashMap<>(); |
| | | private static Map<String, ApiPointDTO> pointIdMap = new ConcurrentHashMap<>(); |
| | | |
| | | private static Map<String, DaPointDTO> pointNoMap = new ConcurrentHashMap<>(); |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public DaPointDTO getSimpleInfoById(String id) { |
| | | public ApiPointDTO getSimpleInfoById(String id) { |
| | | if (pointIdMap.containsKey(id)) { |
| | | return pointIdMap.get(id); |
| | | } |
| | | DaPointDTO dto = ConvertUtils.sourceToTarget(daPointDao.selectById(id), DaPointDTO.class); |
| | | ApiPointDTO dto = ConvertUtils.sourceToTarget(daPointDao.selectById(id), ApiPointDTO.class); |
| | | if (dto == null) { |
| | | return null; |
| | | } |
| | | pointIdMap.put(id, dto); |
| | | return pointIdMap.get(id); |
| | | return dto; |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<DaPointDTO> getCumulatePoint(List<String> pointNos) { |
| | | Map<String, Object> params = new HashMap<>(3); |
| | | params.put("pointType", PointTypeEnum.CUMULATE.getCode()); |
| | | params.put("isEnable", CommonConstant.IS_ENABLE); |
| | | params.put("pointNos", pointNos); |
| | | return daPointDao.getCumulatePoint(params); |
| | | } |
| | | |
| | | @Override |
| | | public List<DaPointDTO> getCumulatePoint(DaPointPageReqVO reqVO) { |
| | | Map<String, Object> params = new HashMap<>(3); |
| | | params.put("pointType", PointTypeEnum.CUMULATE.getCode()); |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <configuration scan="true"> |
| | | <property name="LOG_TEMP" value="./logs"/> |
| | | <configuration> |
| | | <!-- 引用 Spring Boot 的 logback 基础配置 --> |
| | | <include resource="org/springframework/boot/logging/logback/defaults.xml" /> |
| | | <!-- <include resource="org/springframework/boot/logging/logback/base.xml" /> --> |
| | | <logger name="org.springframework.web" level="INFO"/> |
| | | <logger name="org.springboot.sample" level="TRACE" /> |
| | | <!-- 变量 iailab.info.base-package,基础业务包 --> |
| | | <springProperty scope="context" name="iailab.info.base-package" source="iailab.info.base-package"/> |
| | | <!-- 格式化输出:%d 表示日期,%X{tid} SkWalking 链路追踪编号,%thread 表示线程名,%-5level:级别从左显示 5 个字符宽度,%msg:日志消息,%n是换行符 --> |
| | | <property name="PATTERN_DEFAULT" value="%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd HH:mm:ss.SSS}} | %highlight(${LOG_LEVEL_PATTERN:-%5p} ${PID:- }) | %boldYellow(%thread [%tid]) %boldGreen(%-40.40logger{39}) | %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}"/> |
| | | |
| | | <!-- 开发、测试环境 --> |
| | | <springProfile name="dev,test,prod"> |
| | | <logger name="org.springframework.web" level="INFO"/> |
| | | <logger name="org.springboot.sample" level="INFO" /> |
| | | <logger name="com.iailab" level="DEBUG" /> |
| | | </springProfile> |
| | | |
| | | <!-- 生产环境 --> |
| | | <!--<springProfile name="prod">--> |
| | | <!--<logger name="org.springframework.web" level="ERROR"/>--> |
| | | <!--<logger name="org.springboot.sample" level="ERROR" />--> |
| | | <!--<logger name="io.renren" level="ERROR" />--> |
| | | <!--</springProfile>--> |
| | | |
| | | <!-- 日志文件存放路径 --> |
| | | <property name="log_home" value="./logs" /> |
| | | <!-- 日志输出格式 --> |
| | | <!--生产用--> |
| | | <property name="log.pattern" value="[%d{yyyy-MM-dd HH:mm:ss.SSS}] | [%thread][%-5level] | [%logger{20}.%method,line : %line] %msg%n" /> |
| | | <!--本地测试使用--> |
| | | <!--<property name="log.pattern" value="[%boldGreen(%d{yyyy-MM-dd HH:mm:ss.SSS})] | [%highlight(%thread][%-5level)] | [%boldYellow(%logger{20}.%method,%line)] %msg%n" />--> |
| | | <!-- 日志输出格式【控制台】 --> |
| | | <!--<property name="log.pattern" value="%date{yyyy-MM-dd HH:mm:ss} | [ line: %line ] | %boldGreen(%thread) | %highlight(%-5level) | %boldYellow(%logger).%method | %msg%n"/>--> |
| | | |
| | | <!-- 控制台输出 --> |
| | | <appender name="console" class="ch.qos.logback.core.ConsoleAppender"> |
| | | <encoder> |
| | | <!--<pattern>${logPatternConsoleLog}</pattern>--> |
| | | <pattern>${log.pattern}</pattern> |
| | | <!-- 控制台 Appender --> |
| | | <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> |
| | | <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder"> |
| | | <layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout"> |
| | | <pattern>${PATTERN_DEFAULT}</pattern> |
| | | </layout> |
| | | </encoder> |
| | | </appender> |
| | | |
| | | <logger name="m-shop-mybatis-sql" level="debug"></logger> |
| | | |
| | | <!-- debug级别设置 --> |
| | | <appender name="file_debug" class="ch.qos.logback.core.rolling.RollingFileAppender"> |
| | | <prudent>true</prudent> |
| | | <filter class="ch.qos.logback.classic.filter.LevelFilter"> |
| | | <!--过滤 DEBUG--> |
| | | <level>DEBUG</level> |
| | | <!--匹配到就禁止--> |
| | | <!--<onMatch>ACCEPT</onMatch>--> |
| | | <!--没有匹配到就允许--> |
| | | <!--<onMismatch>DENY</onMismatch>--> |
| | | </filter> |
| | | <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> |
| | | <!--<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">--> |
| | | <!--日志文件输出的文件名--> |
| | | <!--<FileNamePattern>${log_home}/log-info.%d{yyyy-MM-dd}.%i.log</FileNamePattern>--> |
| | | <FileNamePattern>${log_home}/log-debug.%d{yyyy-MM-dd}.log</FileNamePattern> |
| | | <!--<maxFileSize>100MB</maxFileSize>--> |
| | | <!-- 日志最大的历史 7天 --> |
| | | <maxHistory>7</maxHistory> |
| | | <totalSizeCap>2GB</totalSizeCap> |
| | | <cleanHistoryOnStart>true</cleanHistoryOnStart> |
| | | <!-- 文件 Appender --> |
| | | <!-- 参考 Spring Boot 的 file-appender.xml 编写 --> |
| | | <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> |
| | | <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder"> |
| | | <layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout"> |
| | | <pattern>${PATTERN_DEFAULT}</pattern> |
| | | </layout> |
| | | </encoder> |
| | | <!-- 日志文件名 --> |
| | | <file>${LOG_FILE}</file> |
| | | <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy"> |
| | | <!-- 滚动后的日志文件名 --> |
| | | <fileNamePattern>${LOGBACK_ROLLINGPOLICY_FILE_NAME_PATTERN:-${LOG_FILE}.%d{yyyy-MM-dd}.%i.gz}</fileNamePattern> |
| | | <!-- 启动服务时,是否清理历史日志,一般不建议清理 --> |
| | | <cleanHistoryOnStart>${LOGBACK_ROLLINGPOLICY_CLEAN_HISTORY_ON_START:-false}</cleanHistoryOnStart> |
| | | <!-- 日志文件,到达多少容量,进行滚动 --> |
| | | <maxFileSize>${LOGBACK_ROLLINGPOLICY_MAX_FILE_SIZE:-10MB}</maxFileSize> |
| | | <!-- 日志文件的总大小,0 表示不限制 --> |
| | | <totalSizeCap>${LOGBACK_ROLLINGPOLICY_TOTAL_SIZE_CAP:-0}</totalSizeCap> |
| | | <!-- 日志文件的保留天数 --> |
| | | <maxHistory>${LOGBACK_ROLLINGPOLICY_MAX_HISTORY:-30}</maxHistory> |
| | | </rollingPolicy> |
| | | <!--<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">--> |
| | | <!--<!– 单文件最大50MB –>--> |
| | | <!--<maxFileSize>50MB</maxFileSize>--> |
| | | <!--</triggeringPolicy>--> |
| | | <encoder> |
| | | <pattern>${log.pattern}</pattern> |
| | | </appender> |
| | | <!-- 异步写入日志,提升性能 --> |
| | | <appender name="ASYNC" class="ch.qos.logback.classic.AsyncAppender"> |
| | | <!-- 不丢失日志。默认的,如果队列的 80% 已满,则会丢弃 TRACT、DEBUG、INFO 级别的日志 --> |
| | | <discardingThreshold>0</discardingThreshold> |
| | | <!-- 更改默认的队列的深度,该值会影响性能。默认值为 256 --> |
| | | <queueSize>256</queueSize> |
| | | <appender-ref ref="FILE"/> |
| | | </appender> |
| | | |
| | | <!-- SkyWalking GRPC 日志收集,实现日志中心。注意:SkyWalking 8.4.0 版本开始支持 --> |
| | | <appender name="GRPC" class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.log.GRPCLogClientAppender"> |
| | | <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder"> |
| | | <layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout"> |
| | | <pattern>${PATTERN_DEFAULT}</pattern> |
| | | </layout> |
| | | </encoder> |
| | | </appender> |
| | | |
| | | <!-- 系统模块日志级别控制 --> |
| | | <!--<logger name="com.btrh" level="info" />--> |
| | | |
| | | <!-- Spring日志级别控制 --> |
| | | <!--<logger name="org.springframework" level="info" />--> |
| | | |
| | | <!--系统操作日志--> |
| | | <root level="INFO"> |
| | | <appender-ref ref="console" /> |
| | | <appender-ref ref="file_debug" /> |
| | | </root> |
| | | <!-- 本地环境 --> |
| | | <springProfile name="local"> |
| | | <root level="INFO"> |
| | | <appender-ref ref="STDOUT"/> |
| | | <appender-ref ref="GRPC"/> <!-- 本地环境下,如果不想接入 SkyWalking 日志服务,可以注释掉本行 --> |
| | | <appender-ref ref="ASYNC"/> <!-- 本地环境下,如果不想打印日志,可以注释掉本行 --> |
| | | </root> |
| | | </springProfile> |
| | | <!-- 其它环境 --> |
| | | <springProfile name="dev,test,stage,prod,default"> |
| | | <root level="INFO"> |
| | | <appender-ref ref="STDOUT"/> |
| | | <appender-ref ref="ASYNC"/> |
| | | <appender-ref ref="GRPC"/> |
| | | </root> |
| | | </springProfile> |
| | | |
| | | </configuration> |
| | |
| | | <if test="minfreqid != null and minfreqid != ''"> |
| | | AND t1.minfreqid = #{minfreqid} |
| | | </if> |
| | | <if test="pointNos != null"> |
| | | AND t1.point_no in |
| | | <foreach collection="pointNos" item="item" index="item" open="(" close=")" separator=","> |
| | | #{item} |
| | | </foreach> |
| | | </if> |
| | | </where> |
| | | </select> |
| | | |
| | |
| | | <if test="minfreqid != null and minfreqid != ''"> |
| | | AND t1.minfreqid = #{minfreqid} |
| | | </if> |
| | | <if test="pointNos != null"> |
| | | AND t1.point_no in |
| | | <foreach collection="pointNos" item="item" index="item" open="(" close=")" separator=","> |
| | | #{item} |
| | | </foreach> |
| | | </if> |
| | | </where> |
| | | </select> |
| | | |
| | |
| | | import io.swagger.v3.oas.annotations.media.Schema; |
| | | import lombok.Data; |
| | | |
| | | import javax.validation.constraints.NotNull; |
| | | import java.io.Serializable; |
| | | import java.math.BigDecimal; |
| | | import java.util.Date; |
| | |
| | | private String id; |
| | | |
| | | @Schema(description = "标题") |
| | | @NotNull(message = "应用编号不能为空") |
| | | private String title; |
| | | |
| | | @Schema(description = "内容") |
| | | @NotNull(message = "应用编号不能为空") |
| | | private String content; |
| | | |
| | | @Schema(description = "排序") |
| | | @NotNull(message = "应用编号不能为空") |
| | | private Integer sort; |
| | | |
| | | @Schema(description = "方案ID") |
| | | private String schemeId; |
| | | |
| | | @Schema(description = "预警ID") |
| | | private String alarmId; |
| | |
| | | private String modelId; |
| | | |
| | | @Schema(description = "调整对象") |
| | | private String adjustObj; |
| | | @NotNull(message = "应用编号不能为空") |
| | | private String scheduleObj; |
| | | |
| | | @Schema(description = "调整介质") |
| | | private String adjustMedium; |
| | | @Schema(description = "调整类型") |
| | | private String scheduleType; |
| | | |
| | | @Schema(description = "调整策略") |
| | | private String adjustStrategy; |
| | | private String scheduleStrategy; |
| | | |
| | | @Schema(description = "调整方式") |
| | | private String adjustMode; |
| | |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") |
| | | private Date adjustEnd; |
| | | |
| | | @Schema(description = "建议时间") |
| | | private Date suggestTime; |
| | | @Schema(description = "调度时间") |
| | | private Date scheduleTime; |
| | | |
| | | @Schema(description = "状态(0未处理 1已采纳 2已忽略)") |
| | | private Integer status; |
| | | |
| | | @Schema(description = "处理人") |
| | | private String handler; |
| | | |
| | | @Schema(description = "处理时间") |
| | | private Date handleTime; |
| | | |
| | | @Schema(description = "创建时间") |
| | | private Date createTime; |
| | | } |
| | |
| | | package com.iailab.module.model.api.mdk.dto; |
| | | |
| | | import com.fasterxml.jackson.annotation.JsonFormat; |
| | | import io.swagger.v3.oas.annotations.media.Schema; |
| | | import lombok.Data; |
| | | |
| | |
| | | |
| | | @Schema(description = "调度方案时间") |
| | | @NotNull(message="调度方案时间不能为空") |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") |
| | | private Date scheduleTime; |
| | | } |
| | |
| | | import com.iailab.module.model.mcs.sche.entity.StScheduleSuggestEntity; |
| | | import com.iailab.module.model.mcs.sche.service.StScheduleSchemeService; |
| | | import com.iailab.module.model.mcs.sche.service.StScheduleSuggestService; |
| | | import com.iailab.module.model.mcs.sche.vo.StScheduleSuggestSaveReqVO; |
| | | import com.iailab.module.model.mdk.vo.ItemVO; |
| | | import com.iailab.module.model.mpk.service.ChartService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | |
| | | Date predictTime = reqVO.getPredictTime(); |
| | | if (predictTime == null) { |
| | | MmItemOutputEntity output = mmItemOutputService.getOutPutById(reqVO.getOutIds().get(0)); |
| | | ItemVO predictItem = mmPredictItemService.getItemById(output.getItemid()); |
| | | ItemVO predictItem = mmPredictItemService.getItemByIdFromCache(output.getItemid()); |
| | | if (predictItem.getLastTime() != null) { |
| | | predictTime = predictItem.getLastTime(); |
| | | } else { |
| | |
| | | for (MmItemOutputEntity out : outs) { |
| | | legend.add(out.getResultName()); |
| | | PreDataSampleViewRespDTO viewDto = new PreDataSampleViewRespDTO(); |
| | | viewDto.setRealData(getHisData(out.getPointid(), startTime, endTime)); |
| | | if (StringUtils.isNotBlank(out.getPointid())) { |
| | | viewDto.setRealData(getHisData(out.getPointid(), startTime, endTime)); |
| | | } |
| | | viewDto.setPreDataN(mmItemResultService.getData(out.getId(), startTime, endTime, DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)); |
| | | viewMap.put(out.getResultName(), viewDto); |
| | | } |
| | |
| | | |
| | | @Override |
| | | public Boolean createScheduleSuggest(ScheduleSuggestRespDTO dto) { |
| | | stScheduleSuggestService.create(ConvertUtils.sourceToTarget(dto, StScheduleSuggestSaveReqVO.class)); |
| | | return true; |
| | | } |
| | | |
| | |
| | | intervalTime = (int) (reqDTO.getPredictTime().getTime() - module.getPredicttime().getTime()) / (1000 * 60); |
| | | } |
| | | List<ItemVO> predictItemList = mmPredictItemService.getByModuleId(module.getId()); |
| | | Map<String, PredictResultVO> predictResultMap = predictModuleHandler.predict(predictItemList, reqDTO.getPredictTime(), intervalTime); |
| | | Map<String, PredictResultVO> predictResultMap = new HashMap<>(predictItemList.size()); |
| | | // 分组,先运行normal预测项,再将结果传递给merge预测项 |
| | | List<ItemVO> normalItems = predictItemList.stream().filter(e -> e.getItemType().equals("NormalItem")).collect(Collectors.toList()); |
| | | if (!CollectionUtils.isEmpty(normalItems)) { |
| | | predictModuleHandler.predict(normalItems, reqDTO.getPredictTime(), intervalTime,predictResultMap); |
| | | List<ItemVO> mergeItems = predictItemList.stream().filter(e -> e.getItemType().equals("MergeItem")).collect(Collectors.toList()); |
| | | if (!CollectionUtils.isEmpty(mergeItems)) { |
| | | predictModuleHandler.predict(mergeItems, reqDTO.getPredictTime(), intervalTime,predictResultMap); |
| | | } |
| | | } |
| | | // 更新Module时间 |
| | | dmModuleService.updatePredictTime(module.getId(), reqDTO.getPredictTime()); |
| | | if (reqDTO.getIsResult() == null || !reqDTO.getIsResult()) { |
| | |
| | | @Override |
| | | public MdkPredictItemRespDTO predictItem(MdkPredictReqDTO reqDTO) { |
| | | MdkPredictItemRespDTO resp = new MdkPredictItemRespDTO(); |
| | | |
| | | try { |
| | | log.info("预测计算开始: " + System.currentTimeMillis()); |
| | | Map<String, List<MdkPredictDataDTO>> predictData = new HashMap<>(); |
| | | ItemVO predictItem = itemEntityFactory.getItemByItemNo(reqDTO.getItemNo()); |
| | | PredictItemHandler predictItemHandler = predictItemFactory.create(predictItem.getId()); |
| | | PredictResultVO predictResult = predictItemHandler.predict(reqDTO.getPredictTime(), predictItem); |
| | | Map<String, List<DataValueVO>> resultMap = predictResultHandler.convertToPredictData(predictResult); |
| | | if (!CollectionUtils.isEmpty(resultMap)) { |
| | | for (Map.Entry<String, List<DataValueVO>> entry : resultMap.entrySet()) { |
| | | List<MdkPredictDataDTO> data = ConvertUtils.sourceToTarget(entry.getValue(), MdkPredictDataDTO.class); |
| | | predictData.put(entry.getKey(), data); |
| | | } |
| | | |
| | | ItemVO itemByItemNo = mmPredictItemService.getItemByItemNo(reqDTO.getItemNo()); |
| | | List<ItemVO> predictItemList = new ArrayList<>(); |
| | | predictItemList.add(itemByItemNo); |
| | | Map<String, PredictResultVO> predictResultMap = new HashMap<>(predictItemList.size()); |
| | | predictModuleHandler.predict(predictItemList, reqDTO.getPredictTime(), 0,predictResultMap); |
| | | |
| | | Map<String, List<MdkPredictDataDTO>> itemPredictData = new HashMap<>(); |
| | | |
| | | Map<String, List<DataValueVO>> predictLists = predictResultHandler.convertToPredictData2(predictResultMap.get(reqDTO.getItemNo())); |
| | | for (Map.Entry<String, List<DataValueVO>> dataListEntry : predictLists.entrySet()) { |
| | | List<MdkPredictDataDTO> predictData = dataListEntry.getValue().stream().map(t -> { |
| | | MdkPredictDataDTO dto1 = new MdkPredictDataDTO(); |
| | | dto1.setDataTime(t.getDataTime()); |
| | | dto1.setDataValue(t.getDataValue()); |
| | | return dto1; |
| | | }).collect(Collectors.toList()); |
| | | itemPredictData.put(dataListEntry.getKey(), predictData); |
| | | } |
| | | resp.setPredictData(predictData); |
| | | resp.setItemId(predictItem.getId()); |
| | | resp.setItemId(reqDTO.getItemNo()); |
| | | resp.setPredictTime(reqDTO.getPredictTime()); |
| | | log.info("预测计算结束: " + System.currentTimeMillis()); |
| | | } catch (Exception ex) { |
| | | log.info("预测计算异常: " + System.currentTimeMillis(), ex); |
| | | return resp; |
| | | resp.setPredictData(itemPredictData); |
| | | } catch (Exception e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | |
| | | return resp; |
| | |
| | | log.info("预测计算结束: " + System.currentTimeMillis()); |
| | | } catch (Exception ex) { |
| | | log.info("调度计算异常: " + System.currentTimeMillis()); |
| | | ex.printStackTrace(); |
| | | // ex.printStackTrace(); |
| | | return resp; |
| | | } |
| | | return resp; |
| | |
| | | @AllArgsConstructor |
| | | public enum OutResultType { |
| | | D1(1, "一维数组"), |
| | | D2(2, "二维数组"); |
| | | D2(2, "二维数组"), |
| | | D(3, "二维数组"); |
| | | |
| | | private Integer code; |
| | | private String desc; |
对比新文件 |
| | |
| | | package com.iailab.module.model.common.exception; |
| | | |
| | | /** |
| | | * 模型结果错误异常 |
| | | */ |
| | | public class ModelResultErrorException extends RuntimeException { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | private String msg; |
| | | private int code = 200; |
| | | |
| | | public ModelResultErrorException(String msg) { |
| | | super(msg); |
| | | this.msg = msg; |
| | | } |
| | | |
| | | public ModelResultErrorException(String msg, Throwable e) { |
| | | super(msg, e); |
| | | this.msg = msg; |
| | | } |
| | | |
| | | public ModelResultErrorException(String msg, int code) { |
| | | super(msg); |
| | | this.msg = msg; |
| | | this.code = code; |
| | | } |
| | | |
| | | public ModelResultErrorException(String msg, int code, Throwable e) { |
| | | super(msg, e); |
| | | this.msg = msg; |
| | | this.code = code; |
| | | } |
| | | |
| | | public String getMsg() { |
| | | return msg; |
| | | } |
| | | |
| | | public void setMsg(String msg) { |
| | | this.msg = msg; |
| | | } |
| | | |
| | | public int getCode() { |
| | | return code; |
| | | } |
| | | |
| | | public void setCode(int code) { |
| | | this.code = code; |
| | | } |
| | | |
| | | |
| | | } |
| | |
| | | private List<MmModelParamEntity> mmModelParamList; |
| | | |
| | | private List<MmItemResultEntity> mmItemResultList; |
| | | |
| | | /** |
| | | * 计算预测项真实数据点 |
| | | */ |
| | | private String pointId; |
| | | } |
| | |
| | | public enum ItemRunStatusEnum { |
| | | PROCESSING(1, "处理中"), |
| | | SUCCESS(2, "成功"), |
| | | FAIL(3, "失败"); |
| | | FAIL(3, "失败"), |
| | | MODELRESULTERROR(4, "模型结果异常"), |
| | | MODELRESULTSAVEERROR(5, "模型结果保存异常"); |
| | | |
| | | private Integer code; |
| | | private String desc; |
| | |
| | | package com.iailab.module.model.mcs.pre.service; |
| | | |
| | | import com.iailab.module.model.mcs.pre.entity.MmItemOutputEntity; |
| | | import com.iailab.module.model.mdk.vo.DataValueVO; |
| | | |
| | | import java.util.Date; |
| | |
| | | List<DataValueVO> getPredictValue(String outputid, Date startTime, Date endTime); |
| | | |
| | | List<Object[]> getData(String outputid, Date startTime, Date endTime, String timeFormat); |
| | | |
| | | void savePredictValue(Map<MmItemOutputEntity, Double> predictDoubleValues, Date predictTime); |
| | | } |
| | |
| | | import com.iailab.module.model.mdk.vo.ItemVO; |
| | | import com.iailab.module.model.mdk.vo.MergeItemVO; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | |
| | | |
| | | ItemVO getItemByItemNo(String itemNo); |
| | | |
| | | ItemVO getItemByIdFromCache(String itemId); |
| | | ItemVO getItemById(String itemId); |
| | | |
| | | ItemVO getItemByOutPutId(String outPutId); |
| | |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.iailab.framework.common.util.date.DateUtils; |
| | | import com.iailab.module.model.mcs.pre.dao.MmItemResultDao; |
| | | import com.iailab.module.model.mcs.pre.entity.MmItemOutputEntity; |
| | | import com.iailab.module.model.mcs.pre.entity.MmItemResultEntity; |
| | | import com.iailab.module.model.mcs.pre.entity.MmItemResultJsonEntity; |
| | | import com.iailab.module.model.mcs.pre.service.MmItemResultService; |
| | |
| | | }); |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | public void savePredictValue(Map<MmItemOutputEntity, Double> predictDoubleValues, Date predictTime) { |
| | | for (Map.Entry<MmItemOutputEntity, Double> entry : predictDoubleValues.entrySet()) { |
| | | MmItemResultJsonEntity resultJson = new MmItemResultJsonEntity(); |
| | | resultJson.setId(UUID.randomUUID().toString()); |
| | | resultJson.setOutputid(entry.getKey().getId()); |
| | | resultJson.setPredicttime(predictTime); |
| | | resultJson.setCumulant(String.valueOf(entry.getValue())); |
| | | Map<String, Object> map4 = new HashMap(2); |
| | | map4.put("TABLENAME", "T_MM_ITEM_RESULT_JSON"); |
| | | map4.put("entity", resultJson); |
| | | mmItemResultDao.savePredictJsonValue(map4); |
| | | } |
| | | } |
| | | } |
| | |
| | | @Override |
| | | public void updatePyFile(String pyModule, String fileName) { |
| | | baseMapper.updatePyFile(pyModule + "." + fileName.substring(0,fileName.lastIndexOf("_")+1),pyModule + "." + fileName); |
| | | // 清空缓存 |
| | | modelIdMap.clear(); |
| | | } |
| | | } |
| | |
| | | MmPredictMergeItemEntity mMmPredictMergeItem = mmPredictItemDto.getMmPredictMergeItem(); |
| | | mMmPredictMergeItem.setItemid(predictItem.getId()); |
| | | mmPredictMergeItemService.savePredictMergeItem(mMmPredictMergeItem); |
| | | // 添加一条默认output |
| | | List<MmItemOutputEntity> mergeItemOutput = new ArrayList<>(1); |
| | | MmItemOutputEntity entity = new MmItemOutputEntity(); |
| | | entity.setPointid(mmPredictItemDto.getPointId()); |
| | | entity.setResultName(mmPredictItemDto.getMmPredictItem().getItemname()); |
| | | entity.setResultstr("result"); |
| | | mergeItemOutput.add(entity); |
| | | mmPredictItemDto.setMmItemOutputList(mergeItemOutput); |
| | | } |
| | | mmPredictItemDao.insert(predictItem); |
| | | DmModuleItemEntity dmModuleItem = mmPredictItemDto.getDmModuleItem(); |
| | |
| | | } else if (itemType != null && ItemTypeEnum.MERGE_ITEM.getName().equals(itemType.getItemtypename())) { |
| | | MmPredictMergeItemEntity mMmPredictMergeItem = mmPredictItemDto.getMmPredictMergeItem(); |
| | | mmPredictMergeItemService.update(mMmPredictMergeItem); |
| | | // 修改默认output |
| | | List<MmItemOutputEntity> mmItemOutputList = mmPredictItemDto.getMmItemOutputList(); |
| | | if (CollectionUtils.isEmpty(mmItemOutputList)) { |
| | | mmItemOutputList = new ArrayList<>(1); |
| | | MmItemOutputEntity entity = new MmItemOutputEntity(); |
| | | entity.setPointid(mmPredictItemDto.getPointId()); |
| | | entity.setResultName(mmPredictItemDto.getMmPredictItem().getItemname()); |
| | | entity.setResultstr("result"); |
| | | mmItemOutputList.add(entity); |
| | | mmPredictItemDto.setMmItemOutputList(mmItemOutputList); |
| | | } else { |
| | | mmPredictItemDto.getMmItemOutputList().forEach(e -> e.setPointid(mmPredictItemDto.getPointId())); |
| | | } |
| | | } |
| | | DmModuleItemEntity dmModuleItem = mmPredictItemDto.getDmModuleItem(); |
| | | if (!"".equals(dmModuleItem.getId()) && dmModuleItem.getId() != null) { |
| | |
| | | mmPredictItemDto.setMmModelParamList(new ArrayList<>()); |
| | | mmPredictItemDto.setMmPredictMergeItem(new MmPredictMergeItemEntity()); |
| | | mmPredictItemDto.setMmPredictMergeItem(mmPredictMergeItemService.getByItemid(id)); |
| | | if (!CollectionUtils.isEmpty(mmPredictItemDto.getMmItemOutputList())) { |
| | | mmPredictItemDto.setPointId(mmPredictItemDto.getMmItemOutputList().get(0).getPointid()); |
| | | } |
| | | } |
| | | return mmPredictItemDto; |
| | | } |
| | |
| | | } |
| | | |
| | | @Override |
| | | public ItemVO getItemById(String itemId) { |
| | | public ItemVO getItemByIdFromCache(String itemId) { |
| | | if (StringUtils.isBlank(itemId)) { |
| | | return null; |
| | | } |
| | |
| | | } |
| | | |
| | | @Override |
| | | public ItemVO getItemById(String itemId) { |
| | | Map<String, Object> params = new HashMap<>(1); |
| | | params.put("ITEMID", itemId); |
| | | List<ItemVO> list = mmPredictItemDao.getItem(params); |
| | | if (CollectionUtils.isEmpty(list)) { |
| | | return null; |
| | | } |
| | | return list.get(0); |
| | | } |
| | | |
| | | @Override |
| | | public ItemVO getItemByOutPutId(String outPutId) { |
| | | if (StringUtils.isBlank(outPutId)) { |
| | | return null; |
| | |
| | | return null; |
| | | } |
| | | String itemId = outPutById.getItemid(); |
| | | return getItemById(itemId); |
| | | return getItemByIdFromCache(itemId); |
| | | } |
| | | |
| | | @Override |
| | |
| | | @Override |
| | | public List<StScheduleSchemeDTO> list(Map<String, Object> params) { |
| | | QueryWrapper<StScheduleSchemeEntity> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("trigger_method", "1"); |
| | | queryWrapper.eq("trigger_method", params.get("trigger_method")); |
| | | queryWrapper.eq("trigger_condition", params.get("trigger_condition")); |
| | | List<StScheduleSchemeEntity> list = baseDao.selectList(queryWrapper); |
| | | return ConvertUtils.sourceToTarget(list, StScheduleSchemeDTO.class); |
| | |
| | | package com.iailab.module.model.mcs.sche.vo; |
| | | |
| | | import com.fasterxml.jackson.annotation.JsonFormat; |
| | | import io.swagger.v3.oas.annotations.media.Schema; |
| | | import lombok.Data; |
| | | |
| | |
| | | private BigDecimal adjustTimes; |
| | | |
| | | @Schema(description = "调整开始时间") |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") |
| | | private Date adjustStart; |
| | | |
| | | @Schema(description = "调整结束时间") |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") |
| | | private Date adjustEnd; |
| | | |
| | | @Schema(description = "调度时间") |
| | |
| | | * @return |
| | | */ |
| | | public ItemVO getItemById(String itemId) { |
| | | ItemVO ItemVO = mmPredictItemService.getItemById(itemId); |
| | | ItemVO ItemVO = mmPredictItemService.getItemByIdFromCache(itemId); |
| | | if (!ItemVOHashMap.containsKey(itemId)) { |
| | | if (ItemVO != null) { |
| | | ItemVOHashMap.put(itemId, ItemVO); |
| | |
| | | package com.iailab.module.model.mdk.predict; |
| | | |
| | | import com.iailab.module.model.mcs.pre.enums.ItemRunStatusEnum; |
| | | import com.iailab.module.model.mdk.common.exceptions.ItemInvokeException; |
| | | import com.iailab.module.model.mdk.vo.ItemVO; |
| | | import com.iailab.module.model.mdk.vo.PredictResultVO; |
| | | |
| | | import java.util.Date; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @author PanZhibao |
| | |
| | | * @return |
| | | * @throws ItemInvokeException |
| | | */ |
| | | PredictResultVO predict(Date predictTime, ItemVO predictItemDto) throws ItemInvokeException; |
| | | PredictResultVO predict(Date predictTime, ItemVO predictItemDto, Map<String, double[]> predictValueMap) throws ItemInvokeException; |
| | | } |
| | |
| | | package com.iailab.module.model.mdk.predict; |
| | | |
| | | import com.iailab.module.model.mcs.pre.entity.MmPredictModelEntity; |
| | | import com.iailab.module.model.mcs.pre.enums.ItemRunStatusEnum; |
| | | import com.iailab.module.model.mdk.common.exceptions.ModelInvokeException; |
| | | import com.iailab.module.model.mdk.vo.PredictResultVO; |
| | | |
| | |
| | | * @return |
| | | * @throws ModelInvokeException |
| | | */ |
| | | PredictResultVO predictByModel(Date predictTime, MmPredictModelEntity predictModel) throws ModelInvokeException; |
| | | PredictResultVO predictByModel(Date predictTime, MmPredictModelEntity predictModel,String itemName) throws ModelInvokeException; |
| | | } |
| | |
| | | package com.iailab.module.model.mdk.predict; |
| | | |
| | | import com.iailab.module.model.common.exception.ModelResultErrorException; |
| | | import com.iailab.module.model.mcs.pre.entity.MmItemOutputEntity; |
| | | import com.iailab.module.model.mcs.pre.enums.ItemRunStatusEnum; |
| | | import com.iailab.module.model.mcs.pre.enums.ItemStatus; |
| | | import com.iailab.module.model.mcs.pre.service.MmItemStatusService; |
| | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.text.MessageFormat; |
| | | import java.time.Duration; |
| | |
| | | * @param intervalTime |
| | | * @return |
| | | */ |
| | | public Map<String, PredictResultVO> predict(List<ItemVO> predictItemList, Date predictTime, int intervalTime) { |
| | | Map<String, PredictResultVO> result = new HashMap<>(); |
| | | |
| | | PredictResultVO predictResult = new PredictResultVO(); |
| | | public void predict(List<ItemVO> predictItemList, Date predictTime, int intervalTime,Map<String, PredictResultVO> predictResultMap) { |
| | | Map<String, double[]> predictValueMap = null; |
| | | if (!CollectionUtils.isEmpty(predictResultMap)) { |
| | | // 将predictResultMap处理成Map<outPutId, double[]> |
| | | predictValueMap = new HashMap<>(); |
| | | for (Map.Entry<String, PredictResultVO> entry : predictResultMap.entrySet()) { |
| | | for (Map.Entry<MmItemOutputEntity, double[]> mmItemOutputEntityEntry : entry.getValue().getPredictMatrixs().entrySet()) { |
| | | predictValueMap.put(mmItemOutputEntityEntry.getKey().getId(),mmItemOutputEntityEntry.getValue()); |
| | | } |
| | | } |
| | | } |
| | | for (ItemVO predictItem : predictItemList) { |
| | | PredictResultVO predictResult; |
| | | if (!predictItem.getStatus().equals(ItemStatus.STATUS1.getCode())) { |
| | | continue; |
| | | } |
| | | Long totalDur = 0L; |
| | | ItemRunStatusEnum itemRunStatusEnum = ItemRunStatusEnum.PROCESSING; |
| | | try { |
| | | mmItemStatusService.recordStatus(predictItem.getId(), ItemRunStatusEnum.PROCESSING, totalDur, predictTime); |
| | | mmItemStatusService.recordStatus(predictItem.getId(), itemRunStatusEnum, totalDur, predictTime); |
| | | PredictItemHandler predictItemHandler = predictItemFactory.create(predictItem.getId()); |
| | | long start = System.currentTimeMillis(); |
| | | try { |
| | | // 预测项开始预测 |
| | | predictResult = predictItemHandler.predict(predictTime, predictItem); |
| | | predictResult = predictItemHandler.predict(predictTime, predictItem, predictValueMap); |
| | | } catch (ModelResultErrorException e) { |
| | | itemRunStatusEnum = ItemRunStatusEnum.MODELRESULTERROR; |
| | | continue; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | log.error(String.valueOf(e)); |
| | | mmItemStatusService.recordStatus(predictItem.getId(), ItemRunStatusEnum.FAIL, totalDur, predictTime); |
| | | itemRunStatusEnum = ItemRunStatusEnum.FAIL; |
| | | continue; |
| | | } |
| | | long end = System.currentTimeMillis(); |
| | | Long drtPre = end - start; |
| | | log.info(MessageFormat.format("预测项:{0},预测时间:{1}ms", predictItem.getItemName(), drtPre)); |
| | | totalDur = totalDur + drtPre; |
| | | |
| | | predictResult.setGranularity(predictItem.getGranularity()); |
| | | predictResult.setT(intervalTime); |
| | | predictResult.setSaveIndex(predictItem.getSaveIndex()); |
| | | predictResult.setLt(1); |
| | | predictResultMap.put(predictItem.getItemNo(), predictResult); |
| | | |
| | | // 保存预测结果 |
| | | predictResultHandler.savePredictResult(predictResult); |
| | | long endSave = System.currentTimeMillis(); |
| | | Long drtSave = endSave - end; |
| | | log.info(MessageFormat.format("预测项:{0},保存时间:{1}ms", predictItem.getItemName(), |
| | | drtSave)); |
| | | totalDur = totalDur + drtSave; |
| | | mmItemStatusService.recordStatus(predictItem.getId(), ItemRunStatusEnum.SUCCESS, totalDur, predictTime); |
| | | result.put(predictItem.getItemNo(), predictResult); |
| | | try { |
| | | predictResultHandler.savePredictResult(predictResult); |
| | | } catch (Exception e) { |
| | | itemRunStatusEnum = ItemRunStatusEnum.MODELRESULTSAVEERROR; |
| | | throw new RuntimeException("模型结果保存异常,result:" + predictResult); |
| | | } |
| | | itemRunStatusEnum = ItemRunStatusEnum.SUCCESS; |
| | | // long endSave = System.currentTimeMillis(); |
| | | // Long drtSave = endSave - end; |
| | | // log.info(MessageFormat.format("预测项:{0},保存时间:{1}ms", predictItem.getItemName(), |
| | | // drtSave)); |
| | | // totalDur = totalDur + drtSave; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | log.error(MessageFormat.format("预测项编号:{0},预测项名称:{1},预测失败:{2} 预测时刻:{3}", |
| | | predictItem.getId(), predictItem.getItemName(), e.getMessage(), predictTime)); |
| | | mmItemStatusService.recordStatus(predictItem.getId(), ItemRunStatusEnum.FAIL, totalDur, predictTime); |
| | | } finally { |
| | | mmItemStatusService.recordStatus(predictItem.getId(), itemRunStatusEnum, totalDur, predictTime); |
| | | } |
| | | } |
| | | return result; |
| | | } |
| | | } |
| | |
| | | */ |
| | | public Map<String, List<DataValueVO>> convertToPredictData(PredictResultVO predictResult) { |
| | | Map<String, List<DataValueVO>> resultMap = new HashMap<>(); |
| | | List<MmItemOutputEntity> itemOutPutList = itemEntityFactory.getOutPutByItemId(predictResult.getPredictId()); |
| | | |
| | | if (!CollectionUtils.isEmpty(predictResult.getPredictList())) { |
| | | resultMap.put(itemOutPutList.get(0).getId(), predictResult.getPredictList()); |
| | | return resultMap; |
| | | } |
| | | // List<MmItemOutputEntity> itemOutPutList = itemEntityFactory.getOutPutByItemId(predictResult.getPredictId()); |
| | | // |
| | | // if (!CollectionUtils.isEmpty(predictResult.getPredictList())) { |
| | | // resultMap.put(itemOutPutList.get(0).getId(), predictResult.getPredictList()); |
| | | // return resultMap; |
| | | // } |
| | | Map<com.iailab.module.model.mcs.pre.entity.MmItemOutputEntity, double[]> predictMatrixs = predictResult.getPredictMatrixs(); |
| | | HashMap<String,List<DataValueVO>> predictLists = new HashMap<>(); |
| | | for (Map.Entry<com.iailab.module.model.mcs.pre.entity.MmItemOutputEntity, double[]> entry : predictMatrixs.entrySet()) { |
| | |
| | | public void savePredictResult(PredictResultVO predictResult) { |
| | | Map<String, List<DataValueVO>> resultMap = convertToPredictData(predictResult); |
| | | mmItemResultService.savePredictValue(resultMap, predictResult.getLt(), "n", predictResult.getPredictTime()); |
| | | // 存double类型输出 |
| | | if (!CollectionUtils.isEmpty(predictResult.getPredictDoubleValues())) { |
| | | mmItemResultService.savePredictValue(predictResult.getPredictDoubleValues(), predictResult.getPredictTime()); |
| | | } |
| | | } |
| | | |
| | | public List<DataValueVO> getPredictValueByItemNo(String itemNo, Date start, Date end) { |
| | |
| | | package com.iailab.module.model.mdk.predict.impl; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.iailab.module.data.api.point.DataPointApi; |
| | | import com.iailab.module.data.api.point.dto.ApiPointDTO; |
| | | import com.iailab.module.data.enums.DataPointFreqEnum; |
| | | import com.iailab.module.model.mcs.pre.entity.MmItemOutputEntity; |
| | | import com.iailab.module.model.mcs.pre.service.MmItemOutputService; |
| | | import com.iailab.module.model.mcs.pre.service.MmItemResultService; |
| | | import com.iailab.module.model.mdk.common.enums.ItemPredictStatus; |
| | | import com.iailab.module.model.mdk.common.exceptions.ItemInvokeException; |
| | | import com.iailab.module.model.mdk.factory.ItemEntityFactory; |
| | | import com.iailab.module.model.mdk.factory.PredictItemFactory; |
| | | import com.iailab.module.model.mdk.predict.PredictItemHandler; |
| | | import com.iailab.module.model.mdk.predict.PredictResultHandler; |
| | | import com.iailab.module.model.mdk.vo.DataValueVO; |
| | | import com.iailab.module.model.mdk.vo.ItemVO; |
| | | import com.iailab.module.model.mdk.vo.PredictResultVO; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.sql.Timestamp; |
| | | import java.util.*; |
| | | |
| | | /** |
| | |
| | | * @throws ItemInvokeException |
| | | */ |
| | | @Override |
| | | public PredictResultVO predict(Date predictTime, ItemVO predictItemDto) |
| | | public PredictResultVO predict(Date predictTime, ItemVO predictItemDto, Map<String, double[]> predictValueMap) |
| | | throws ItemInvokeException { |
| | | PredictResultVO predictResult = new PredictResultVO(); |
| | | ItemPredictStatus itemStatus = ItemPredictStatus.PREDICTING; |
| | | String itemId = predictItemDto.getId(); |
| | | try { |
| | | String expression = itemEntityFactory.getMergeItem(itemId).getExpression(); |
| | | int predictLength = itemEntityFactory.getItemById(itemId).getPredictLength(); |
| | | double[][] predictResultMat = new double[predictLength][1]; |
| | | Map<String, List<DataValueVO>> predictValueMap = new HashMap<>(); |
| | | double[] predictResultMat = new double[predictLength]; |
| | | String[] mathOutPutId = expression.split("[\\+ \\-]"); |
| | | ArrayList<Character> operator = new ArrayList<>(); |
| | | for (int i = 0; i < expression.length(); i++) { |
| | |
| | | operator.add(expression.charAt(i)); |
| | | } |
| | | } |
| | | String[] compositionItem = expression.split(String.valueOf("&".toCharArray())); |
| | | // String[] compositionItem = expression.split(String.valueOf("&".toCharArray())); |
| | | //是否为计算预测项 |
| | | if (mathOutPutId.length > 1) { |
| | | for (String outPutId : mathOutPutId) { |
| | | if (outPutId.length() > 4) { |
| | | Date endTime = predictTime; |
| | | // ItemVO itemEntity = itemEntityFactory.getItemByItemNo(itemNo); |
| | | // List<MmItemOutputEntity> outPutList = itemEntityFactory.getOutPutByItemId(itemEntity.getId()); |
| | | MmItemOutputEntity outPut = mmItemOutputService.getOutPutById(outPutId); |
| | | ApiPointDTO pointEntity = dataPointApi.getInfoById(outPut.getPointid()); |
| | | // Map<String, List<DataValueVO>> predictValueMap = new HashMap<>(); |
| | | // for (String outPutId : mathOutPutId) { |
| | | // if (outPutId.length() > 4) { |
| | | // Date endTime = predictTime; |
| | | //// ItemVO itemEntity = itemEntityFactory.getItemByItemNo(itemNo); |
| | | //// List<MmItemOutputEntity> outPutList = itemEntityFactory.getOutPutByItemId(itemEntity.getId()); |
| | | // MmItemOutputEntity outPut = mmItemOutputService.getOutPutById(outPutId); |
| | | // ApiPointDTO pointEntity = dataPointApi.getInfoById(outPut.getPointid()); |
| | | // |
| | | // Calendar calendar = Calendar.getInstance(); |
| | | // calendar.setTime(endTime); |
| | | // calendar.add(Calendar.SECOND, (predictLength - 1) * DataPointFreqEnum.getEumByCode(pointEntity.getMinfreqid()).getValue()); |
| | | // endTime = new Timestamp(calendar.getTime().getTime()); |
| | | //// List<DataValueVO> predictValueList = predictResultHandler.getPredictValueByItemNo(itemNo, predictTime, endTime); |
| | | // List<DataValueVO> predictValueList = mmItemResultService.getPredictValue(outPutId, predictTime, endTime); |
| | | // if (predictValueList.size() != predictLength) { |
| | | // log.debug("merge项融合失败:缺少子项预测数据,对应子项outPutId=" + outPutId); |
| | | // return null; |
| | | // } |
| | | // predictValueMap.put(outPutId, predictValueList); |
| | | // } |
| | | // } |
| | | |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(endTime); |
| | | calendar.add(Calendar.SECOND, (predictLength - 1) * DataPointFreqEnum.getEumByCode(pointEntity.getMinfreqid()).getValue()); |
| | | endTime = new Timestamp(calendar.getTime().getTime()); |
| | | // List<DataValueVO> predictValueList = predictResultHandler.getPredictValueByItemNo(itemNo, predictTime, endTime); |
| | | List<DataValueVO> predictValueList = mmItemResultService.getPredictValue(outPutId, predictTime, endTime); |
| | | if (predictValueList.size() != predictLength) { |
| | | log.debug("merge项融合失败:缺少子项预测数据,对应子项outPutId=" + outPutId); |
| | | return null; |
| | | } |
| | | predictValueMap.put(outPutId, predictValueList); |
| | | } |
| | | } |
| | | for (Integer i = 0; i < predictLength; i++) { |
| | | double sum =0.0; |
| | | sum = predictValueMap.get(mathOutPutId[0]).get(i).getDataValue(); |
| | | sum = predictValueMap.get(mathOutPutId[0])[i]; |
| | | for (int j = 1; j < mathOutPutId.length; j++) { |
| | | if (operator.get(j-1)=='+') |
| | | {sum += predictValueMap.get(mathOutPutId[j]).get(i).getDataValue();} |
| | | {sum += predictValueMap.get(mathOutPutId[j])[i];} |
| | | if (operator.get(j-1)=='-') |
| | | {sum -= predictValueMap.get(mathOutPutId[j]).get(i).getDataValue();} |
| | | {sum -= predictValueMap.get(mathOutPutId[j])[i];} |
| | | } |
| | | predictResultMat[i][0] = sum; |
| | | predictResultMat[i] = sum; |
| | | } |
| | | } |
| | | //是否为组合预测项 |
| | | if (compositionItem.length > 1) { |
| | | Map<String, PredictResultVO> predictResultMap = new HashMap<>(); |
| | | Integer columnTotalNumber = 0; |
| | | Integer rowNumber = 0; |
| | | for (String itemNo : compositionItem) { |
| | | PredictItemHandler predictItem = (PredictItemHandler) predictItemFactory.create(itemEntityFactory. |
| | | getItemByItemNo(itemNo).getId()); |
| | | predictResult = predictItem.predict(predictTime, predictItemDto); |
| | | columnTotalNumber += Integer.valueOf(predictResult.getPredictMatrix().length); |
| | | predictResultMap.put(itemNo, predictItem.predict(predictTime, predictItemDto)); |
| | | } |
| | | double[][] matrix = new double[columnTotalNumber][1]; |
| | | for (String itemNo : compositionItem) { |
| | | for (Integer i = 0; i < predictResultMap.get(itemNo).getPredictMatrix().length; i++) { |
| | | matrix[rowNumber][0] = predictResultMap.get(itemNo).getPredictMatrix()[i][0]; |
| | | rowNumber++; |
| | | } |
| | | } |
| | | predictResult.setPredictMatrix(matrix); |
| | | } |
| | | // if (compositionItem.length > 1) { |
| | | // Map<String, PredictResultVO> predictResultMap = new HashMap<>(); |
| | | // Integer columnTotalNumber = 0; |
| | | // Integer rowNumber = 0; |
| | | // for (String itemNo : compositionItem) { |
| | | // PredictItemHandler predictItem = (PredictItemHandler) predictItemFactory.create(itemEntityFactory. |
| | | // getItemByItemNo(itemNo).getId()); |
| | | // predictResult = predictItem.predict(predictTime, predictItemDto); |
| | | // columnTotalNumber += Integer.valueOf(predictResult.getPredictMatrix().length); |
| | | // predictResultMap.put(itemNo, predictItem.predict(predictTime, predictItemDto)); |
| | | // } |
| | | // double[][] matrix = new double[columnTotalNumber][1]; |
| | | // for (String itemNo : compositionItem) { |
| | | // for (Integer i = 0; i < predictResultMap.get(itemNo).getPredictMatrix().length; i++) { |
| | | // matrix[rowNumber][0] = predictResultMap.get(itemNo).getPredictMatrix()[i][0]; |
| | | // rowNumber++; |
| | | // } |
| | | // } |
| | | // predictResult.setPredictMatrix(matrix); |
| | | // } |
| | | predictResult.setPredictId(itemId); |
| | | predictResult.setPredictMatrix(predictResultMat); |
| | | List<MmItemOutputEntity> outputServiceByItemid = mmItemOutputService.getByItemid(itemId); |
| | | if (!CollectionUtils.isEmpty(outputServiceByItemid)) { |
| | | Map<MmItemOutputEntity, double[]> predictMatrixs = new HashMap<>(); |
| | | predictMatrixs.put(outputServiceByItemid.get(0),predictResultMat); |
| | | predictResult.setPredictMatrixs(predictMatrixs); |
| | | } |
| | | predictResult.setPredictTime(predictTime); |
| | | //预测项预测成功的状态 |
| | | itemStatus = ItemPredictStatus.SUCCESS; |
| | | } catch (Exception e) { |
| | | //预测项预测失败的状态 |
| | | itemStatus = ItemPredictStatus.FAILED; |
| | | log.debug("merge项预测失败,itemId:" + itemId); |
| | | log.error("merge项预测失败,itemId:" + itemId); |
| | | e.printStackTrace(); |
| | | throw e; |
| | | } |
| | | log.debug("预测完成,itemId:" + itemId + ",itemStatus:" + itemStatus.getValue()); |
| | | log.info("merge项预测完成,itemId:" + itemId + ",结果:" + JSON.toJSONString(predictResult)); |
| | | return predictResult; |
| | | } |
| | | } |
| | |
| | | package com.iailab.module.model.mdk.predict.impl; |
| | | |
| | | import com.iailab.module.model.common.exception.ModelResultErrorException; |
| | | import com.iailab.module.model.mcs.pre.entity.MmPredictModelEntity; |
| | | import com.iailab.module.model.mcs.pre.enums.ItemRunStatusEnum; |
| | | import com.iailab.module.model.mcs.pre.service.MmPredictModelService; |
| | | import com.iailab.module.model.mdk.common.exceptions.ItemInvokeException; |
| | | import com.iailab.module.model.mdk.common.exceptions.ModelInvokeException; |
| | |
| | | |
| | | import java.text.MessageFormat; |
| | | import java.util.Date; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @author PanZhibao |
| | |
| | | * @throws ItemInvokeException |
| | | */ |
| | | @Override |
| | | public PredictResultVO predict(Date predictTime, ItemVO predictItemDto) throws ItemInvokeException { |
| | | public PredictResultVO predict(Date predictTime, ItemVO predictItemDto, Map<String, double[]> predictValueMap) throws ItemInvokeException,ModelResultErrorException { |
| | | PredictResultVO predictResult = new PredictResultVO(); |
| | | String itemId = predictItemDto.getId(); |
| | | predictResult.setPredictId(itemId); |
| | | try { |
| | | MmPredictModelEntity predictModel = mmPredictModelService.getActiveModelByItemId(itemId); |
| | | if (predictModel == null) { |
| | | throw new ModelInvokeException(MessageFormat.format("{0},itemId={1}", |
| | | ModelInvokeException.errorGetModelEntity, itemId)); |
| | | } |
| | | predictResult = predictModelHandler.predictByModel(predictTime, predictModel); |
| | | predictResult = predictModelHandler.predictByModel(predictTime, predictModel,predictItemDto.getItemName()); |
| | | predictResult.setPredictId(itemId); |
| | | } catch (ModelResultErrorException ex) { |
| | | throw ex; |
| | | } catch (Exception ex) { |
| | | throw new ItemInvokeException(MessageFormat.format("{0},itemId={1}", |
| | | ItemInvokeException.errorItemFailed, itemId)); |
| | |
| | | package com.iailab.module.model.mdk.predict.impl; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.iail.model.IAILModel; |
| | | import com.iailab.module.model.common.enums.CommonConstant; |
| | | import com.iailab.module.model.common.enums.OutResultType; |
| | | import com.iailab.module.model.common.exception.ModelResultErrorException; |
| | | import com.iailab.module.model.mcs.pre.entity.MmItemOutputEntity; |
| | | import com.iailab.module.model.mcs.pre.entity.MmModelArithSettingsEntity; |
| | | import com.iailab.module.model.mcs.pre.entity.MmPredictModelEntity; |
| | | import com.iailab.module.model.mcs.pre.enums.ItemRunStatusEnum; |
| | | import com.iailab.module.model.mcs.pre.service.MmItemOutputService; |
| | | import com.iailab.module.model.mcs.pre.service.MmModelArithSettingsService; |
| | | import com.iailab.module.model.mdk.common.enums.TypeA; |
| | |
| | | * @throws ModelInvokeException |
| | | */ |
| | | @Override |
| | | public synchronized PredictResultVO predictByModel(Date predictTime, MmPredictModelEntity predictModel) throws ModelInvokeException { |
| | | public synchronized PredictResultVO predictByModel(Date predictTime, MmPredictModelEntity predictModel,String itemName) throws ModelInvokeException { |
| | | PredictResultVO result = new PredictResultVO(); |
| | | if (predictModel == null) { |
| | | throw new ModelInvokeException("modelEntity is null"); |
| | | } |
| | | String modelId = predictModel.getId(); |
| | | try { |
| | | List<SampleData> sampleDataList = sampleConstructor.constructSample(TypeA.Predict.name(), modelId, predictTime); |
| | | List<SampleData> sampleDataList = sampleConstructor.constructSample(TypeA.Predict.name(), modelId, predictTime, itemName); |
| | | String modelPath = predictModel.getModelpath(); |
| | | if (modelPath == null) { |
| | | log.info("模型路径不存在,modelId=" + modelId); |
| | |
| | | param2Values[portLength] = newModelBean.getDataMap().get("models"); |
| | | param2Values[portLength + 1] = settings; |
| | | |
| | | log.info("#######################预测模型 " + predictModel.getItemid() + " ##########################"); |
| | | JSONObject jsonObjNewModelBean = new JSONObject(); |
| | | jsonObjNewModelBean.put("newModelBean", newModelBean); |
| | | log.info(String.valueOf(jsonObjNewModelBean)); |
| | | JSONObject jsonObjParam2Values = new JSONObject(); |
| | | jsonObjParam2Values.put("param2Values", param2Values); |
| | | log.info(String.valueOf(jsonObjParam2Values)); |
| | | log.info("####################### 预测模型 "+ "【itemId:" + predictModel.getItemid() + ",itemName" + itemName + "】 ##########################"); |
| | | // JSONObject jsonObjNewModelBean = new JSONObject(); |
| | | // jsonObjNewModelBean.put("newModelBean", newModelBean); |
| | | // log.info(String.valueOf(jsonObjNewModelBean)); |
| | | // JSONObject jsonObjParam2Values = new JSONObject(); |
| | | // jsonObjParam2Values.put("param2Values", param2Values); |
| | | log.info("参数: " + JSON.toJSONString(param2Values)); |
| | | |
| | | //IAILMDK.run |
| | | HashMap<String, Object> modelResult = DllUtils.run(newModelBean, param2Values, predictModel.getMpkprojectid()); |
| | | if (!modelResult.containsKey(CommonConstant.MDK_STATUS_CODE) || !modelResult.containsKey(CommonConstant.MDK_RESULT) || |
| | | !modelResult.get(CommonConstant.MDK_STATUS_CODE).toString().equals(CommonConstant.MDK_STATUS_100)) { |
| | | throw new RuntimeException("模型结果异常:" + modelResult); |
| | | throw new ModelResultErrorException("模型结果异常:" + modelResult); |
| | | } |
| | | modelResult = (HashMap<String, Object>) modelResult.get(CommonConstant.MDK_RESULT); |
| | | //打印结果 |
| | | log.info("预测模型计算完成:modelId=" + modelId + modelResult); |
| | | log.info("预测模型计算完成:modelId=" + modelId + ",modelName" + predictModel.getMethodname()); |
| | | JSONObject jsonObjResult = new JSONObject(); |
| | | jsonObjResult.put("result", modelResult); |
| | | log.info(String.valueOf(jsonObjResult)); |
| | | |
| | | List<MmItemOutputEntity> itemOutputList = mmItemOutputService.getByItemid(predictModel.getItemid()); |
| | | Map<MmItemOutputEntity, double[]> predictMatrixs = new HashMap<>(itemOutputList.size()); |
| | | Map<MmItemOutputEntity, double[]> predictMatrixs = new HashMap<>(); |
| | | Map<MmItemOutputEntity, Double> predictDoubleValues = new HashMap<>(); |
| | | for (MmItemOutputEntity output : itemOutputList) { |
| | | if (!modelResult.containsKey(output.getResultstr())) { |
| | | continue; |
| | |
| | | } |
| | | predictMatrixs.put(output, tempColumn); |
| | | break; |
| | | case D: |
| | | Double temp3 = (Double) modelResult.get(output.getResultstr()); |
| | | predictDoubleValues.put(output, temp3); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | result.setPredictMatrixs(predictMatrixs); |
| | | result.setPredictDoubleValues(predictDoubleValues); |
| | | result.setModelResult(modelResult); |
| | | result.setPredictTime(predictTime); |
| | | } catch (Exception ex) { |
| | | log.error("调用发生异常,异常信息为:{}", ex); |
| | | } catch (ModelResultErrorException ex) { |
| | | ex.printStackTrace(); |
| | | throw ex; |
| | | } catch (Exception ex) { |
| | | log.error("调用发生异常,异常信息为:{1}", ex); |
| | | // ex.printStackTrace(); |
| | | throw new ModelInvokeException(ex.getMessage()); |
| | | } |
| | | return result; |
| | |
| | | package com.iailab.module.model.mdk.sample; |
| | | |
| | | import com.iailab.module.data.api.plan.PlanItemApi; |
| | | import com.iailab.module.data.api.plan.dto.ApiPlanItemDTO; |
| | | import com.iailab.module.data.api.point.DataPointApi; |
| | | import com.iailab.module.data.api.point.dto.ApiPointDTO; |
| | | import com.iailab.module.data.api.point.dto.ApiPointValueDTO; |
| | | import com.iailab.module.data.api.point.dto.ApiPointValueQueryDTO; |
| | | import com.iailab.module.data.common.ApiDataQueryDTO; |
| | | import com.iailab.module.data.common.ApiDataValueDTO; |
| | | import com.iailab.module.model.mcs.pre.entity.MmItemOutputEntity; |
| | | import com.iailab.module.model.mcs.pre.service.MmItemOutputService; |
| | | import com.iailab.module.model.mcs.pre.service.MmItemResultService; |
| | |
| | | import com.iailab.module.model.mdk.sample.dto.SampleData; |
| | | import com.iailab.module.model.mdk.sample.dto.SampleInfo; |
| | | import com.iailab.module.model.mdk.vo.DataValueVO; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 预测样本数据构造 |
| | | */ |
| | | @Slf4j |
| | | @Component |
| | | public class PredictSampleDataConstructor extends SampleDataConstructor { |
| | | |
| | |
| | | |
| | | @Autowired |
| | | private DataPointApi dataPointApi; |
| | | |
| | | @Autowired |
| | | private PlanItemApi planItemApi; |
| | | |
| | | @Autowired |
| | | private MmItemResultService mmItemResultService; |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<SampleData> prepareSampleData(SampleInfo sampleInfo) { |
| | | public List<SampleData> prepareSampleData(SampleInfo sampleInfo) throws Exception { |
| | | List<SampleData> sampleDataList = new ArrayList<>(); |
| | | Map<String, ApiPointDTO> pointMap = sampleInfo.getPointMap(); |
| | | Map<String, ApiPlanItemDTO> planMap = sampleInfo.getPlanMap(); |
| | | //对每个爪分别进行计算 |
| | | for (ColumnItemPort entry : sampleInfo.getColumnInfo()) { |
| | | //先依据爪内数据项的modelParamOrder进行排序——重写comparator匿名函数 |
| | |
| | | //对每一项依次进行数据查询,然后将查询出的值赋给matrix对应的位置 |
| | | for (int i = 0; i < entry.getColumnItemList().size(); i++) { |
| | | try { |
| | | List<DataValueVO> dataEntityList = getData(entry.getColumnItemList().get(i)); |
| | | List<DataValueVO> dataEntityList = getData(entry.getColumnItemList().get(i),pointMap,planMap); |
| | | //补全数据 |
| | | ColumnItem columnItem = entry.getColumnItemList().get(i); |
| | | dataEntityList = super.completionData(matrix.length, dataEntityList, columnItem.startTime, columnItem.endTime, |
| | | columnItem.paramId, columnItem.getParamType()); |
| | | columnItem.paramId, columnItem.getParamType(),pointMap,planMap); |
| | | |
| | | /** 如果数据取不满,把缺失的数据点放在后面 */ |
| | | if (dataEntityList != null && dataEntityList.size() != 0) { |
| | |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | throw e; |
| | | } |
| | | } |
| | | SampleData sampleData = new SampleData(); |
| | |
| | | * getData |
| | | * |
| | | * @param columnItem |
| | | * @param pointMap |
| | | * @param planMap |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | private List<DataValueVO> getData(ColumnItem columnItem) throws Exception { |
| | | private List<DataValueVO> getData(ColumnItem columnItem, Map<String, ApiPointDTO> pointMap, Map<String, ApiPlanItemDTO> planMap) throws Exception { |
| | | List<DataValueVO> dataList = new ArrayList<>(); |
| | | String paramType = columnItem.getParamType(); |
| | | switch (ModelParamType.getEumByCode(paramType)) { |
| | | case DATAPOINT: |
| | | ApiPointDTO point = dataPointApi.getInfoById(columnItem.getParamId()); |
| | | ApiPointValueQueryDTO queryDto = new ApiPointValueQueryDTO(); |
| | | queryDto.setPointNo(point.getPointNo()); |
| | | queryDto.setPointNo(pointMap.get(columnItem.getParamId()).getPointNo()); |
| | | queryDto.setStart(columnItem.getStartTime()); |
| | | queryDto.setEnd(columnItem.getEndTime()); |
| | | List<ApiPointValueDTO> pointValueList = dataPointApi.queryPointHistoryValue(queryDto); |
| | | if (CollectionUtils.isEmpty(pointValueList)) { |
| | | break; |
| | | } |
| | | dataList = pointValueList.stream().map(t -> { |
| | | DataValueVO vo = new DataValueVO(); |
| | | vo.setDataTime(t.getT()); |
| | |
| | | case NORMALITEM: |
| | | case MERGEITEM: |
| | | MmItemOutputEntity outPut = mmItemOutputService.getOutPutById(columnItem.getParamId()); |
| | | dataList = mmItemResultService.getPredictValue(outPut.getId(), |
| | | columnItem.getStartTime(), columnItem.getEndTime()); |
| | | if (dataList == null) { |
| | | throw new Exception("没有预测值"); |
| | | List<DataValueVO> predictValue = mmItemResultService.getPredictValue(outPut.getId(), columnItem.getStartTime(), columnItem.getEndTime()); |
| | | if (CollectionUtils.isEmpty(predictValue)) { |
| | | break; |
| | | } |
| | | dataList = predictValue; |
| | | break; |
| | | case PLAN: |
| | | ApiDataQueryDTO queryPlanItemDto = new ApiDataQueryDTO(); |
| | | queryPlanItemDto.setItemNo(planMap.get(columnItem.getParamId()).getItemNo()); |
| | | queryPlanItemDto.setStart(columnItem.getStartTime()); |
| | | queryPlanItemDto.setEnd(columnItem.getEndTime()); |
| | | List<ApiDataValueDTO> planValueList = planItemApi.queryPlanItemHistoryValue(queryPlanItemDto); |
| | | if (CollectionUtils.isEmpty(planValueList)) { |
| | | break; |
| | | } |
| | | dataList = planValueList.stream().map(t -> { |
| | | DataValueVO vo = new DataValueVO(); |
| | | vo.setDataTime(t.getDataTime()); |
| | | vo.setDataValue(t.getDataValue()); |
| | | return vo; |
| | | }).collect(Collectors.toList()); |
| | | default: |
| | | break; |
| | | } |
| | | log.info("数据获取,columnItem:" + columnItem + ",dataList" + dataList); |
| | | return dataList; |
| | | } |
| | | } |
| | |
| | | package com.iailab.module.model.mdk.sample; |
| | | |
| | | import com.iailab.module.data.api.plan.PlanItemApi; |
| | | import com.iailab.module.data.api.plan.dto.ApiPlanItemDTO; |
| | | import com.iailab.module.data.api.point.DataPointApi; |
| | | import com.iailab.module.data.api.point.dto.ApiPointDTO; |
| | | import com.iailab.module.model.mcs.pre.entity.MmModelParamEntity; |
| | | import com.iailab.module.model.mcs.pre.service.MmModelParamService; |
| | | import com.iailab.module.model.mcs.pre.service.MmPredictItemService; |
| | | import com.iailab.module.model.mcs.pre.service.MmPredictModelService; |
| | | import com.iailab.module.model.mdk.common.enums.ModelParamType; |
| | | import com.iailab.module.model.mdk.sample.dto.ColumnItem; |
| | | import com.iailab.module.model.mdk.sample.dto.ColumnItemPort; |
| | | import com.iailab.module.model.mdk.sample.dto.SampleInfo; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | import java.util.function.Function; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @author PanZhibao |
| | |
| | | |
| | | @Autowired |
| | | private MmPredictItemService mmPredictItemService; |
| | | |
| | | @Autowired |
| | | private DataPointApi dataPointApi; |
| | | |
| | | @Autowired |
| | | private PlanItemApi planItemApi; |
| | | |
| | | /** |
| | | * 返回样本矩阵的列数 |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | protected List<ColumnItemPort> getColumnInfo(String modelId, Date predictTime) { |
| | | protected SampleInfo getColumnInfo(String modelId, Date predictTime) { |
| | | SampleInfo sampleInfo = new SampleInfo(); |
| | | List<ColumnItemPort> resultList = new ArrayList<>(); |
| | | List<ColumnItem> columnItemList = new ArrayList<>(); |
| | | ColumnItem columnInfo = new ColumnItem(); |
| | |
| | | int curPortOrder = modelInputParamEntityList.get(0).getModelparamportorder(); |
| | | //设置当前查询数据长度,初始值为最小端口数据长度 |
| | | int curDataLength = modelInputParamEntityList.get(0).getDatalength(); |
| | | // 统一获取测点的信息 |
| | | Set<String> pointIds = modelInputParamEntityList.stream().filter(e -> ModelParamType.getEumByCode(e.getModelparamtype()).equals(ModelParamType.DATAPOINT)).map(MmModelParamEntity::getModelparamid).collect(Collectors.toSet()); |
| | | List<ApiPointDTO> points = dataPointApi.getInfoByIds(pointIds); |
| | | Map<String, ApiPointDTO> pointMap = points.stream().collect(Collectors.toMap(ApiPointDTO::getId, Function.identity(), (e1,e2) -> e1)); |
| | | // 统一获取计划数据的信息 |
| | | Set<String> planIds = modelInputParamEntityList.stream().filter(e -> ModelParamType.getEumByCode(e.getModelparamtype()).equals(ModelParamType.PLAN)).map(MmModelParamEntity::getModelparamid).collect(Collectors.toSet()); |
| | | List<ApiPlanItemDTO> plans = planItemApi.getInfoByIds(planIds); |
| | | Map<String, ApiPlanItemDTO> planMap = plans.stream().collect(Collectors.toMap(ApiPlanItemDTO::getId, Function.identity(), (e1,e2) -> e1)); |
| | | |
| | | for (MmModelParamEntity entry : modelInputParamEntityList) { |
| | | columnInfo.setParamType(entry.getModelparamtype()); |
| | | columnInfo.setParamId(entry.getModelparamid()); |
| | | columnInfo.setDataLength(entry.getDatalength()); |
| | | columnInfo.setModelParamOrder(entry.getModelparamorder()); |
| | | columnInfo.setModelParamPortOrder(entry.getModelparamportorder()); |
| | | columnInfo.setStartTime(getStartTime(columnInfo, predictTime)); |
| | | columnInfo.setEndTime(getEndTime(columnInfo, predictTime)); |
| | | columnInfo.setGranularity(super.getGranularity(columnInfo)); |
| | | columnInfo.setStartTime(getStartTime(columnInfo, predictTime,pointMap,planMap)); |
| | | columnInfo.setEndTime(getEndTime(columnInfo, predictTime,pointMap,planMap)); |
| | | columnInfo.setGranularity(super.getGranularity(columnInfo,pointMap,planMap)); |
| | | |
| | | //对每一个爪进行数据项归并 |
| | | if (curPortOrder != entry.getModelparamportorder()){ |
| | |
| | | curPort.setDataLength(curDataLength); |
| | | curPort.setPortOrder(curPortOrder); |
| | | resultList.add(curPort); |
| | | return resultList; |
| | | sampleInfo.setColumnInfo(resultList); |
| | | sampleInfo.setPointMap(pointMap); |
| | | sampleInfo.setPlanMap(planMap); |
| | | return sampleInfo; |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Override |
| | | protected Integer getSampleCycle(String modelId) { |
| | | return mmPredictItemService.getItemById(mmPredictModelService.getInfoFromCatch(modelId).getItemid()).getGranularity(); |
| | | return mmPredictItemService.getItemByIdFromCache(mmPredictModelService.getInfoFromCatch(modelId).getItemid()).getGranularity(); |
| | | } |
| | | |
| | | |
| | |
| | | package com.iailab.module.model.mdk.sample; |
| | | |
| | | import com.iailab.module.model.mdk.common.exceptions.DataAccessException; |
| | | import com.iailab.module.model.mdk.common.exceptions.ModelInvokeException; |
| | | import com.iailab.module.model.mdk.sample.dto.SampleData; |
| | | import com.iailab.module.model.mdk.sample.dto.SampleInfo; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | @Autowired |
| | | private SampleFactory sampleFactory; |
| | | |
| | | public List<SampleData> constructSample(String typeA, String modelId, Date runTime) { |
| | | public List<SampleData> constructSample(String typeA, String modelId, Date runTime,String itemName) throws ModelInvokeException { |
| | | try { |
| | | SampleInfoConstructor sampleInfoConstructor = sampleFactory.createSampleInfo(typeA, modelId); |
| | | SampleInfo sampleInfo = sampleInfoConstructor.prepareSampleInfo(modelId, runTime); |
| | | SampleDataConstructor sampleDataConstructor = sampleFactory.createSampelData(typeA); |
| | | return sampleDataConstructor.prepareSampleData(sampleInfo); |
| | | } catch (Exception e) { |
| | | DataAccessException exception = new DataAccessException(MessageFormat.format("{0},类名为{1}", |
| | | DataAccessException.errorDataAccess, Thread.currentThread().getStackTrace()[1].getClassName())); |
| | | System.out.println(exception); |
| | | e.printStackTrace(); |
| | | return null; |
| | | throw new ModelInvokeException(MessageFormat.format("{0},Name:{1}", |
| | | ModelInvokeException.errorGetModelArithParam, itemName)); |
| | | } |
| | | |
| | | |
| | |
| | | package com.iailab.module.model.mdk.sample; |
| | | |
| | | import com.iailab.module.data.api.plan.PlanItemApi; |
| | | import com.iailab.module.data.api.plan.dto.ApiPlanItemDTO; |
| | | import com.iailab.module.data.api.point.DataPointApi; |
| | | import com.iailab.module.data.api.point.dto.ApiPointDTO; |
| | | import com.iailab.module.data.enums.DataPointFreqEnum; |
| | | import com.iailab.module.data.enums.TimeGranularitySecEnum; |
| | | import com.iailab.module.model.mdk.common.enums.ModelParamType; |
| | | import com.iailab.module.model.mdk.sample.dto.SampleData; |
| | | import com.iailab.module.model.mdk.sample.dto.SampleInfo; |
| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.sql.Timestamp; |
| | | import java.util.*; |
| | | |
| | | abstract class SampleDataConstructor { |
| | |
| | | |
| | | @Autowired |
| | | private DataPointApi dataPointApi; |
| | | @Autowired |
| | | private PlanItemApi planItemApi; |
| | | |
| | | /** |
| | | * prepareSampleData |
| | |
| | | * @param sampleInfo |
| | | * @return |
| | | */ |
| | | public abstract List<SampleData> prepareSampleData(SampleInfo sampleInfo); |
| | | public abstract List<SampleData> prepareSampleData(SampleInfo sampleInfo) throws Exception; |
| | | |
| | | /** |
| | | * 补全数据 |
| | |
| | | * @param dataEntityList |
| | | * @param startTime |
| | | * @param endTime |
| | | * @param planMap |
| | | * @return |
| | | */ |
| | | public List<DataValueVO> completionData(int length, List<DataValueVO> dataEntityList, Date startTime, Date endTime, |
| | | String paramId, String paramType) { |
| | | String paramId, String paramType, Map<String, ApiPointDTO> pointMap, Map<String, ApiPlanItemDTO> planMap) { |
| | | if (CollectionUtils.isEmpty(dataEntityList) || length == dataEntityList.size()) { |
| | | return dataEntityList; |
| | | } else if (length < dataEntityList.size()) { |
| | |
| | | endTime = calendar.getTime(); |
| | | end = endTime.getTime(); |
| | | |
| | | oneMin = 24 * 60 * 60 * 1000; |
| | | oneMin = 60 * 1000L; |
| | | mins = ((end - start) / oneMin); |
| | | break; |
| | | case DATAPOINT: |
| | | // 测点值 |
| | | ApiPointDTO dataPoint = dataPointApi.getInfoById(paramId); |
| | | ApiPointDTO dataPoint = pointMap.get(paramId); |
| | | oneMin = 1000L * DataPointFreqEnum.getEumByCode(dataPoint.getMinfreqid()).getValue(); |
| | | // 设置时间偏移量 |
| | | start = start - (start % oneMin) + oneMin; |
| | |
| | | end = calendar2.getTime().getTime(); |
| | | mins = ((end - start) / oneMin); |
| | | break; |
| | | case PLAN: |
| | | // 计划数据 |
| | | ApiPlanItemDTO planItem = planMap.get(paramId); |
| | | oneMin = 1000L * TimeGranularitySecEnum.getEumByCode(planItem.getTimeGranularity()).getValue(); |
| | | // 设置时间偏移量 |
| | | start = start - (start % oneMin) + oneMin; |
| | | end = end - (end % oneMin) + oneMin; |
| | | mins = ((end - start) / oneMin); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | |
| | | import java.util.Calendar; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @author PanZhibao |
| | |
| | | * @return |
| | | */ |
| | | protected SampleInfo prepareSampleInfo(String modelId, Date predictTime) { |
| | | SampleInfo sampleInfo = new SampleInfo(); |
| | | //调用样本列数的方法 |
| | | // sampleInfo.setSampleColumn(getSampleColumn(modelId)); |
| | | //样本的列信息 |
| | | sampleInfo.setColumnInfo(getColumnInfo(modelId, predictTime)); |
| | | //样本的采样周期 |
| | | // sampleInfo.setSampleCycle(getSampleCycle(modelId)); |
| | | return sampleInfo; |
| | | return getColumnInfo(modelId, predictTime); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param predictTime |
| | | * @return |
| | | */ |
| | | protected abstract List<ColumnItemPort> getColumnInfo(String modelId, Date predictTime); |
| | | protected abstract SampleInfo getColumnInfo(String modelId, Date predictTime); |
| | | |
| | | /** |
| | | * 样本的采样周期 |
| | |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | protected Date getStartTime(ColumnItem columnItem, Date originalTime) { |
| | | protected Date getStartTime(ColumnItem columnItem, Date originalTime, Map<String, ApiPointDTO> pointMap, Map<String, ApiPlanItemDTO> planMap) { |
| | | Date dateTime = new Date(); |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(originalTime); |
| | | switch (ModelParamType.getEumByCode(columnItem.getParamType())) { |
| | | case DATAPOINT: |
| | | ApiPointDTO dataPoint = dataPointApi.getInfoById(columnItem.getParamId()); |
| | | ApiPointDTO dataPoint = pointMap.get(columnItem.getParamId()); |
| | | if (dataPoint == null) { |
| | | return null; |
| | | } |
| | |
| | | dateTime = calculateTime(originalTime, true, columnItem.getDataLength(), 60); |
| | | break; |
| | | case PLAN: |
| | | dateTime = calendar.getTime(); |
| | | ApiPlanItemDTO apiPlanItemDTO = planMap.get(columnItem.getParamId()); |
| | | if (apiPlanItemDTO == null) { |
| | | return null; |
| | | } |
| | | dateTime = calculateTime(originalTime, true, columnItem.getDataLength(), TimeGranularitySecEnum.getEumByCode(apiPlanItemDTO.getTimeGranularity()).getValue()); |
| | | break; |
| | | default: |
| | | break; |
| | |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | protected Date getEndTime(ColumnItem columnItem, Date originalTime) { |
| | | protected Date getEndTime(ColumnItem columnItem, Date originalTime,Map<String, ApiPointDTO> pointMap, Map<String, ApiPlanItemDTO> planMap) { |
| | | Date dateTime = new Date(); |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(originalTime); |
| | | switch (ModelParamType.getEumByCode(columnItem.getParamType())) { |
| | | case DATAPOINT: |
| | | ApiPointDTO dataPoint = dataPointApi.getInfoById(columnItem.getParamId()); |
| | | ApiPointDTO dataPoint = pointMap.get(columnItem.getParamId()); |
| | | if (dataPoint == null) { |
| | | return null; |
| | | } |
| | |
| | | dateTime = calendar.getTime(); |
| | | break; |
| | | case PLAN: |
| | | ApiPlanItemDTO planItem = planItemApi.getInfoByNo(columnItem.getParamId()); |
| | | if (planItem == null) { |
| | | ApiPlanItemDTO apiPlanItemDTO = planMap.get(columnItem.getParamId()); |
| | | if (apiPlanItemDTO == null) { |
| | | return null; |
| | | } |
| | | dateTime = calculateDate(originalTime, false, columnItem.getDataLength(), |
| | | TimeGranularityEnum.getEumByCode(planItem.getTimeGranularity()).getValue()); |
| | | dateTime = calculateDate(originalTime, false, columnItem.getDataLength(), TimeGranularitySecEnum.getEumByCode(apiPlanItemDTO.getTimeGranularity()).getValue()); |
| | | break; |
| | | default: |
| | | break; |
| | |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | protected Integer getGranularity(ColumnItem columnItem) { |
| | | protected Integer getGranularity(ColumnItem columnItem,Map<String, ApiPointDTO> pointMap, Map<String, ApiPlanItemDTO> planMap) { |
| | | // 默认60s |
| | | Integer granularity = 60; |
| | | switch (ModelParamType.getEumByCode(columnItem.getParamType())) { |
| | | case DATAPOINT: |
| | | ApiPointDTO dataPoint = dataPointApi.getInfoById(columnItem.getParamId()); |
| | | ApiPointDTO dataPoint = pointMap.get(columnItem.getParamId()); |
| | | granularity = DataPointFreqEnum.getEumByCode(dataPoint.getMinfreqid()).getValue(); |
| | | break; |
| | | case NORMALITEM: |
| | | granularity = mmPredictItemService.getItemByOutPutId(columnItem.getParamId()).getGranularity(); |
| | | break; |
| | | case MERGEITEM: |
| | | granularity = mmPredictItemService.getItemById(columnItem.getParamId()).getGranularity(); |
| | | granularity = mmPredictItemService.getItemByOutPutId(columnItem.getParamId()).getGranularity(); |
| | | break; |
| | | case IND: |
| | | ApiIndItemDTO indItemDTO = indItemApi.getInfoById(columnItem.getParamId()); |
| | | granularity = TimeGranularitySecEnum.getEumByCode(indItemDTO.getTimeGranularity()).getValue();; |
| | | break; |
| | | case PLAN: |
| | | ApiPlanItemDTO apiPlanItemDTO = planItemApi.getInfoById(columnItem.getParamId()); |
| | | ApiPlanItemDTO apiPlanItemDTO = planMap.get(columnItem.getParamId()); |
| | | granularity = TimeGranularitySecEnum.getEumByCode(apiPlanItemDTO.getTimeGranularity()).getValue(); |
| | | break; |
| | | default: |
| | |
| | | package com.iailab.module.model.mdk.sample; |
| | | |
| | | import com.iailab.module.data.api.plan.PlanItemApi; |
| | | import com.iailab.module.data.api.plan.dto.ApiPlanItemDTO; |
| | | import com.iailab.module.data.api.point.DataPointApi; |
| | | import com.iailab.module.data.api.point.dto.ApiPointDTO; |
| | | import com.iailab.module.model.mcs.sche.entity.StScheduleModelParamEntity; |
| | | import com.iailab.module.model.mcs.sche.service.StScheduleModelParamService; |
| | | import com.iailab.module.model.mdk.common.enums.ModelParamType; |
| | | import com.iailab.module.model.mdk.sample.dto.ColumnItem; |
| | | import com.iailab.module.model.mdk.sample.dto.ColumnItemPort; |
| | | import com.iailab.module.model.mdk.sample.dto.SampleInfo; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | import java.util.function.Function; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Component |
| | | public class ScheduleSampleInfoConstructor extends SampleInfoConstructor { |
| | |
| | | @Autowired |
| | | private StScheduleModelParamService stScheduleModelParamService; |
| | | |
| | | @Autowired |
| | | private DataPointApi dataPointApi; |
| | | |
| | | @Autowired |
| | | private PlanItemApi planItemApi; |
| | | |
| | | @Override |
| | | protected Integer getSampleColumn(String modelId) { |
| | | return null; |
| | | } |
| | | |
| | | @Override |
| | | protected List<ColumnItemPort> getColumnInfo(String modelId, Date predictTime) { |
| | | protected SampleInfo getColumnInfo(String modelId, Date predictTime) { |
| | | SampleInfo sampleInfo = new SampleInfo(); |
| | | List<ColumnItemPort> resultList = new ArrayList<>(); |
| | | List<ColumnItem> columnItemList = new ArrayList<>(); |
| | | ColumnItem columnInfo = new ColumnItem(); |
| | |
| | | int curPortOrder = modelInputParamEntityList.get(0).getModelparamportorder(); |
| | | //设置当前查询数据长度,初始值为最小端口数据长度 |
| | | int curDataLength = modelInputParamEntityList.get(0).getDatalength(); |
| | | // 统一获取测点的信息 |
| | | Set<String> pointIds = modelInputParamEntityList.stream().filter(e -> ModelParamType.getEumByCode(e.getModelparamtype()).equals(ModelParamType.DATAPOINT)).map(StScheduleModelParamEntity::getModelparamid).collect(Collectors.toSet()); |
| | | List<ApiPointDTO> points = dataPointApi.getInfoByIds(pointIds); |
| | | Map<String, ApiPointDTO> pointMap = points.stream().collect(Collectors.toMap(ApiPointDTO::getId, Function.identity())); |
| | | // 统一获取计划数据的信息 |
| | | Set<String> planIds = modelInputParamEntityList.stream().filter(e -> ModelParamType.getEumByCode(e.getModelparamtype()).equals(ModelParamType.PLAN)).map(StScheduleModelParamEntity::getModelparamid).collect(Collectors.toSet()); |
| | | List<ApiPlanItemDTO> plans = planItemApi.getInfoByIds(planIds); |
| | | Map<String, ApiPlanItemDTO> planMap = plans.stream().collect(Collectors.toMap(ApiPlanItemDTO::getId, Function.identity(), (e1,e2) -> e1)); |
| | | |
| | | for (StScheduleModelParamEntity entry : modelInputParamEntityList) { |
| | | columnInfo.setParamType(entry.getModelparamtype()); |
| | | columnInfo.setParamId(entry.getModelparamid()); |
| | | columnInfo.setDataLength(entry.getDatalength()); |
| | | columnInfo.setModelParamOrder(entry.getModelparamorder()); |
| | | columnInfo.setModelParamPortOrder(entry.getModelparamportorder()); |
| | | columnInfo.setStartTime(getStartTime(columnInfo, predictTime)); |
| | | columnInfo.setEndTime(getEndTime(columnInfo, predictTime)); |
| | | columnInfo.setGranularity(super.getGranularity(columnInfo)); |
| | | columnInfo.setStartTime(getStartTime(columnInfo, predictTime,pointMap,planMap)); |
| | | columnInfo.setEndTime(getEndTime(columnInfo, predictTime,pointMap,planMap)); |
| | | columnInfo.setGranularity(super.getGranularity(columnInfo,pointMap,planMap)); |
| | | |
| | | //对每一个爪进行数据项归并 |
| | | if (curPortOrder != entry.getModelparamportorder()){ |
| | |
| | | curPort.setDataLength(curDataLength); |
| | | curPort.setPortOrder(curPortOrder); |
| | | resultList.add(curPort); |
| | | return resultList; |
| | | sampleInfo.setColumnInfo(resultList); |
| | | sampleInfo.setPointMap(pointMap); |
| | | sampleInfo.setPlanMap(planMap); |
| | | return sampleInfo; |
| | | } |
| | | |
| | | @Override |
| | |
| | | package com.iailab.module.model.mdk.sample.dto; |
| | | |
| | | import com.iailab.module.data.api.plan.dto.ApiPlanItemDTO; |
| | | import com.iailab.module.data.api.point.dto.ApiPointDTO; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.Builder; |
| | | import lombok.Data; |
| | |
| | | import java.math.BigDecimal; |
| | | import java.sql.Timestamp; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | @Data |
| | | @AllArgsConstructor |
| | |
| | | private Integer sampleCycle; |
| | | |
| | | private BigDecimal[][] deviation; |
| | | // 所有测点信息,避免重复查询 |
| | | private Map<String, ApiPointDTO> pointMap; |
| | | // 所有计划数据信息,避免重复查询 |
| | | private Map<String, ApiPlanItemDTO> planMap; |
| | | } |
| | |
| | | package com.iailab.module.model.mdk.schedule.impl; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.iail.model.IAILModel; |
| | |
| | | String modelId = scheduleModel.getId(); |
| | | try { |
| | | //1.根据模型id构造模型输入样本 |
| | | List<SampleData> sampleDataList = sampleConstructor.constructSample(TypeA.Schedule.name(), modelId, scheduleTime); |
| | | long now = System.currentTimeMillis(); |
| | | List<SampleData> sampleDataList = sampleConstructor.constructSample(TypeA.Schedule.name(), modelId, scheduleTime,scheduleScheme.getName()); |
| | | log.info("构造模型输入样本消耗时长:" + (System.currentTimeMillis() - now) / 1000 + "秒"); |
| | | if (CollectionUtils.isEmpty(sampleDataList)) { |
| | | log.info("调度模型构造样本失败,schemeCode=" + schemeCode); |
| | | return null; |
| | |
| | | param2Values[portLength] = settings; |
| | | |
| | | log.info("#######################调度模型 " + scheduleModel.getModelName() + " ##########################"); |
| | | JSONObject jsonObjNewModelBean = new JSONObject(); |
| | | jsonObjNewModelBean.put("newModelBean", newModelBean); |
| | | log.info(String.valueOf(jsonObjNewModelBean)); |
| | | JSONObject jsonObjParam2Values = new JSONObject(); |
| | | jsonObjParam2Values.put("param2Values", param2Values); |
| | | log.info(String.valueOf(jsonObjParam2Values)); |
| | | // JSONObject jsonObjNewModelBean = new JSONObject(); |
| | | // jsonObjNewModelBean.put("newModelBean", newModelBean); |
| | | // log.info(String.valueOf(jsonObjNewModelBean)); |
| | | // JSONObject jsonObjParam2Values = new JSONObject(); |
| | | // jsonObjParam2Values.put("param2Values", param2Values); |
| | | log.info("参数: " + JSON.toJSONString(param2Values)); |
| | | |
| | | //IAILMDK.run |
| | | HashMap<String, Object> modelResult = DllUtils.run(newModelBean, param2Values, scheduleScheme.getMpkprojectid()); |
| | |
| | | private Map<MmItemOutputEntity, double[]> predictMatrixs; |
| | | |
| | | /** |
| | | * double类型的模型输出 |
| | | */ |
| | | private Map<MmItemOutputEntity, Double> predictDoubleValues; |
| | | |
| | | /** |
| | | * 时间间隔 (当前预测时间 与 上一次预测时间 相差的分钟数;系统计算得出) |
| | | */ |
| | | private int t; |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <configuration scan="true"> |
| | | <property name="LOG_TEMP" value="./logs"/> |
| | | <configuration> |
| | | <!-- 引用 Spring Boot 的 logback 基础配置 --> |
| | | <include resource="org/springframework/boot/logging/logback/defaults.xml" /> |
| | | <!-- <include resource="org/springframework/boot/logging/logback/base.xml" /> --> |
| | | <logger name="org.springframework.web" level="INFO"/> |
| | | <logger name="org.springboot.sample" level="TRACE" /> |
| | | <!-- 变量 iailab.info.base-package,基础业务包 --> |
| | | <springProperty scope="context" name="iailab.info.base-package" source="iailab.info.base-package"/> |
| | | <!-- 格式化输出:%d 表示日期,%X{tid} SkWalking 链路追踪编号,%thread 表示线程名,%-5level:级别从左显示 5 个字符宽度,%msg:日志消息,%n是换行符 --> |
| | | <property name="PATTERN_DEFAULT" value="%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd HH:mm:ss.SSS}} | %highlight(${LOG_LEVEL_PATTERN:-%5p} ${PID:- }) | %boldYellow(%thread [%tid]) %boldGreen(%-40.40logger{39}) | %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}"/> |
| | | |
| | | <!-- 开发、测试环境 --> |
| | | <springProfile name="dev,test,prod"> |
| | | <logger name="org.springframework.web" level="INFO"/> |
| | | <logger name="org.springboot.sample" level="INFO" /> |
| | | <logger name="com.iailab" level="DEBUG" /> |
| | | <!-- 控制台 Appender --> |
| | | <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> |
| | | <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder"> |
| | | <layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout"> |
| | | <pattern>${PATTERN_DEFAULT}</pattern> |
| | | </layout> |
| | | </encoder> |
| | | </appender> |
| | | |
| | | <!-- 文件 Appender --> |
| | | <!-- 参考 Spring Boot 的 file-appender.xml 编写 --> |
| | | <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> |
| | | <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder"> |
| | | <layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout"> |
| | | <pattern>${PATTERN_DEFAULT}</pattern> |
| | | </layout> |
| | | </encoder> |
| | | <!-- 日志文件名 --> |
| | | <file>${LOG_FILE}</file> |
| | | <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy"> |
| | | <!-- 滚动后的日志文件名 --> |
| | | <fileNamePattern>${LOGBACK_ROLLINGPOLICY_FILE_NAME_PATTERN:-${LOG_FILE}.%d{yyyy-MM-dd}.%i.gz}</fileNamePattern> |
| | | <!-- 启动服务时,是否清理历史日志,一般不建议清理 --> |
| | | <cleanHistoryOnStart>${LOGBACK_ROLLINGPOLICY_CLEAN_HISTORY_ON_START:-false}</cleanHistoryOnStart> |
| | | <!-- 日志文件,到达多少容量,进行滚动 --> |
| | | <maxFileSize>${LOGBACK_ROLLINGPOLICY_MAX_FILE_SIZE:-10MB}</maxFileSize> |
| | | <!-- 日志文件的总大小,0 表示不限制 --> |
| | | <totalSizeCap>${LOGBACK_ROLLINGPOLICY_TOTAL_SIZE_CAP:-0}</totalSizeCap> |
| | | <!-- 日志文件的保留天数 --> |
| | | <maxHistory>${LOGBACK_ROLLINGPOLICY_MAX_HISTORY:-30}</maxHistory> |
| | | </rollingPolicy> |
| | | </appender> |
| | | <!-- 异步写入日志,提升性能 --> |
| | | <appender name="ASYNC" class="ch.qos.logback.classic.AsyncAppender"> |
| | | <!-- 不丢失日志。默认的,如果队列的 80% 已满,则会丢弃 TRACT、DEBUG、INFO 级别的日志 --> |
| | | <discardingThreshold>0</discardingThreshold> |
| | | <!-- 更改默认的队列的深度,该值会影响性能。默认值为 256 --> |
| | | <queueSize>256</queueSize> |
| | | <appender-ref ref="FILE"/> |
| | | </appender> |
| | | |
| | | <!-- SkyWalking GRPC 日志收集,实现日志中心。注意:SkyWalking 8.4.0 版本开始支持 --> |
| | | <appender name="GRPC" class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.log.GRPCLogClientAppender"> |
| | | <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder"> |
| | | <layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout"> |
| | | <pattern>${PATTERN_DEFAULT}</pattern> |
| | | </layout> |
| | | </encoder> |
| | | </appender> |
| | | |
| | | <!-- 本地环境 --> |
| | | <springProfile name="local"> |
| | | <root level="INFO"> |
| | | <appender-ref ref="STDOUT"/> |
| | | <appender-ref ref="GRPC"/> <!-- 本地环境下,如果不想接入 SkyWalking 日志服务,可以注释掉本行 --> |
| | | <appender-ref ref="ASYNC"/> <!-- 本地环境下,如果不想打印日志,可以注释掉本行 --> |
| | | </root> |
| | | </springProfile> |
| | | <!-- 其它环境 --> |
| | | <springProfile name="dev,test,stage,prod,default"> |
| | | <root level="INFO"> |
| | | <appender-ref ref="STDOUT"/> |
| | | <appender-ref ref="ASYNC"/> |
| | | <appender-ref ref="GRPC"/> |
| | | </root> |
| | | </springProfile> |
| | | |
| | | <!-- 生产环境 --> |
| | | <!--<springProfile name="prod">--> |
| | | <!--<logger name="org.springframework.web" level="ERROR"/>--> |
| | | <!--<logger name="org.springboot.sample" level="ERROR" />--> |
| | | <!--<logger name="io.renren" level="ERROR" />--> |
| | | <!--</springProfile>--> |
| | | |
| | | <!-- 日志文件存放路径 --> |
| | | <property name="log_home" value="./logs" /> |
| | | <!-- 日志输出格式 --> |
| | | <!--生产用--> |
| | | <property name="log.pattern" value="[%d{yyyy-MM-dd HH:mm:ss.SSS}] | [%thread][%-5level] | [%logger{20}.%method,line : %line] %msg%n" /> |
| | | <!--本地测试使用--> |
| | | <!--<property name="log.pattern" value="[%boldGreen(%d{yyyy-MM-dd HH:mm:ss.SSS})] | [%highlight(%thread][%-5level)] | [%boldYellow(%logger{20}.%method,%line)] %msg%n" />--> |
| | | <!-- 日志输出格式【控制台】 --> |
| | | <!--<property name="log.pattern" value="%date{yyyy-MM-dd HH:mm:ss} | [ line: %line ] | %boldGreen(%thread) | %highlight(%-5level) | %boldYellow(%logger).%method | %msg%n"/>--> |
| | | |
| | | <!-- 控制台输出 --> |
| | | <appender name="console" class="ch.qos.logback.core.ConsoleAppender"> |
| | | <encoder> |
| | | <!--<pattern>${logPatternConsoleLog}</pattern>--> |
| | | <pattern>${log.pattern}</pattern> |
| | | </encoder> |
| | | </appender> |
| | | |
| | | <logger name="m-shop-mybatis-sql" level="debug"></logger> |
| | | |
| | | <!-- debug级别设置 --> |
| | | <appender name="file_debug" class="ch.qos.logback.core.rolling.RollingFileAppender"> |
| | | <prudent>true</prudent> |
| | | <filter class="ch.qos.logback.classic.filter.LevelFilter"> |
| | | <!--过滤 DEBUG--> |
| | | <level>DEBUG</level> |
| | | <!--匹配到就禁止--> |
| | | <!--<onMatch>ACCEPT</onMatch>--> |
| | | <!--没有匹配到就允许--> |
| | | <!--<onMismatch>DENY</onMismatch>--> |
| | | </filter> |
| | | <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> |
| | | <!--<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">--> |
| | | <!--日志文件输出的文件名--> |
| | | <!--<FileNamePattern>${log_home}/log-info.%d{yyyy-MM-dd}.%i.log</FileNamePattern>--> |
| | | <FileNamePattern>${log_home}/log-debug.%d{yyyy-MM-dd}.log</FileNamePattern> |
| | | <!--<maxFileSize>100MB</maxFileSize>--> |
| | | <!-- 日志最大的历史 7天 --> |
| | | <maxHistory>7</maxHistory> |
| | | <totalSizeCap>2GB</totalSizeCap> |
| | | <cleanHistoryOnStart>true</cleanHistoryOnStart> |
| | | </rollingPolicy> |
| | | <!--<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">--> |
| | | <!--<!– 单文件最大50MB –>--> |
| | | <!--<maxFileSize>50MB</maxFileSize>--> |
| | | <!--</triggeringPolicy>--> |
| | | <encoder> |
| | | <pattern>${log.pattern}</pattern> |
| | | </encoder> |
| | | </appender> |
| | | |
| | | <!-- 系统模块日志级别控制 --> |
| | | <!--<logger name="com.btrh" level="info" />--> |
| | | |
| | | <!-- Spring日志级别控制 --> |
| | | <!--<logger name="org.springframework" level="info" />--> |
| | | |
| | | <!--系统操作日志--> |
| | | <root level="INFO"> |
| | | <appender-ref ref="console" /> |
| | | <appender-ref ref="file_debug" /> |
| | | </root> |
| | | |
| | | </configuration> |
| | | </configuration> |
| | |
| | | import com.iailab.framework.common.pojo.CommonResult; |
| | | import com.iailab.framework.common.util.object.BeanUtils; |
| | | import com.iailab.framework.common.util.object.ConvertUtils; |
| | | import com.iailab.framework.datapermission.core.annotation.DataPermission; |
| | | import com.iailab.module.system.api.user.dto.AdminUserRespDTO; |
| | | import com.iailab.module.system.controller.admin.user.vo.user.UserSaveReqVO; |
| | | import com.iailab.module.system.dal.dataobject.dept.DeptDO; |
| | |
| | | private PermissionService permissionService; |
| | | |
| | | @Override |
| | | @DataPermission(enable = false) // 关闭数据权限,避免只查看自己时,查询不到部门。 |
| | | public CommonResult<AdminUserRespDTO> getUser(Long id) { |
| | | AdminUserDO user = userService.getUser(id); |
| | | return success(BeanUtils.toBean(user, AdminUserRespDTO.class)); |
| | |
| | | Set<Long> menuIds = permissionService.getRoleMenuListByRoleId(convertSet(roles, RoleDO::getId)); |
| | | List<MenuDO> menuList = menuService.getMenuList(menuIds); |
| | | menuList = menuService.filterDisableMenus(menuList); |
| | | // menuList = menuService.filterMenus(menuList, "system"); |
| | | menuList = menuService.filterMenus(menuList, "system"); |
| | | |
| | | // 2. 拼接结果返回 |
| | | return success(AuthConvert.INSTANCE.convert(user, roles, menuList)); |
| | |
| | | } |
| | | children.retainAll(menuList); |
| | | List<MenuDO> tempChildren = new LinkedList<>(); |
| | | //为每一个二级菜单增加一个隐藏父级目录 |
| | | //为每一个二级菜单(非外链菜单)增加一个隐藏父级目录 |
| | | children.stream().forEach(menu -> { |
| | | if (menu.getParentId().equals(menuDO.getId())) { |
| | | if(menu.getType().equals(MenuTypeEnum.MENU.getType())) { |
| | |
| | | tempChildren.add(parentMenu); |
| | | } else if(menu.getType().equals(MenuTypeEnum.DIR.getType())) { |
| | | // 为应用菜单二级目录前增加“/” |
| | | menu.setPath("/" + menu.getPath()); |
| | | if(!menu.getPath().contains("http:") && !menu.getPath().contains("https:")) { |
| | | menu.setPath("/" + menu.getPath()); |
| | | } |
| | | } |
| | | } |
| | | tempChildren.add(menu); |