Merge remote-tracking branch 'origin/master'
已重命名3个文件
已修改31个文件
已删除6个文件
已添加13个文件
已复制1个文件
| | |
| | | MODIFY COLUMN `data_time` datetime NULL DEFAULT NULL COMMENT '数据时间' AFTER `item_no`; |
| | | |
| | | CREATE TABLE `t_arc_data` ( |
| | | `id` varchar(255) NOT NULL COMMENT 'id', |
| | | `arc_id` varchar(255) DEFAULT NULL COMMENT '归档id', |
| | | `arc_time` varchar(255) DEFAULT NULL COMMENT '归档时间', |
| | | `value` varchar(255) DEFAULT NULL COMMENT '归档时间', |
| | | `id` varchar(36) NOT NULL COMMENT 'id', |
| | | `arc_id` varchar(36) DEFAULT NULL COMMENT '归档id', |
| | | `code` varchar(30) DEFAULT NULL COMMENT '编码', |
| | | `arc_time` varchar(30) DEFAULT NULL COMMENT '归档时间', |
| | | `arc_value` DECIMAL(18,6) DEFAULT NULL COMMENT '归档值', |
| | | `create_time` datetime DEFAULT NULL COMMENT '创建时间', |
| | | PRIMARY KEY (`id`) |
| | | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='归档数据表'; |
| | | |
| | | CREATE TABLE `t_arc_setting` ( |
| | | `id` varchar(255) NOT NULL COMMENT 'id', |
| | | `name` varchar(255) DEFAULT NULL COMMENT '名称', |
| | | `type` varchar(255) DEFAULT NULL COMMENT '归档周期(shift、day、month、year)', |
| | | `point` varchar(255) DEFAULT NULL COMMENT '归档点位', |
| | | `calculate` varchar(255) DEFAULT NULL COMMENT '计算方法(none、sum、diff、avg)', |
| | | `is_enable` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '是否启用', |
| | | `id` varchar(36) NOT NULL COMMENT 'id', |
| | | `code` varchar(30) DEFAULT NULL COMMENT '编码', |
| | | `name` varchar(30) DEFAULT NULL COMMENT '名称', |
| | | `type` varchar(10) DEFAULT NULL COMMENT '归档周期(shift、day、month、year)', |
| | | `point` varchar(36) DEFAULT NULL COMMENT '归档点位', |
| | | `calculate` varchar(10) DEFAULT NULL COMMENT '计算方法(none、sum、diff、avg)', |
| | | `sort` int COMMENT '排序', |
| | | `is_enable` tinyint(1) DEFAULT 1 COMMENT '是否启用', |
| | | `create_time` datetime DEFAULT NULL COMMENT '创建时间', |
| | | `update_time` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', |
| | | PRIMARY KEY (`id`) |
| | | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='定时归档设置表'; |
| | | PRIMARY KEY (`id`), |
| | | UNIQUE KEY `uk_code` (`code`) USING BTREE |
| | | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci ROW_FORMAT=DYNAMIC COMMENT='定时归档设置表'; |
对比新文件 |
| | |
| | | package com.iailab.module.data.arc.controller.admin; |
| | | |
| | | import com.iailab.framework.common.pojo.CommonResult; |
| | | import com.iailab.framework.common.pojo.PageResult; |
| | | import com.iailab.module.data.arc.entity.ArcDataEntity; |
| | | import com.iailab.module.data.arc.service.ArcDataService; |
| | | import com.iailab.module.data.arc.vo.ArcDataPageReqVO; |
| | | import io.swagger.v3.oas.annotations.tags.Tag; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.validation.Valid; |
| | | |
| | | import static com.iailab.framework.common.pojo.CommonResult.success; |
| | | |
| | | /** |
| | | * @author PanZhibao |
| | | * @Description |
| | | * @createTime 2025年02月26日 |
| | | */ |
| | | @Tag(name = "数据归档数据") |
| | | @RestController |
| | | @RequestMapping("/data/arc/data") |
| | | @Validated |
| | | public class ArcDataController { |
| | | |
| | | @Autowired |
| | | private ArcDataService arcDataService; |
| | | |
| | | @PostMapping("archiving") |
| | | public CommonResult<Boolean> archiving(@RequestBody String type) { |
| | | arcDataService.archiving(type); |
| | | return success(true); |
| | | } |
| | | |
| | | @GetMapping("page") |
| | | public CommonResult<PageResult<ArcDataEntity>> dataPage(@Valid ArcDataPageReqVO reqVO) { |
| | | PageResult<ArcDataEntity> page = arcDataService.queryPage(reqVO); |
| | | return success(page); |
| | | } |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.data.arc.controller.admin; |
| | | |
| | | import com.iailab.framework.common.pojo.CommonResult; |
| | | import com.iailab.framework.common.pojo.PageResult; |
| | | import com.iailab.module.data.arc.entity.ArcSettingEntity; |
| | | import com.iailab.module.data.arc.service.ArcSettingService; |
| | | import com.iailab.module.data.arc.vo.ArcSettingPageReqVO; |
| | | import io.swagger.v3.oas.annotations.Operation; |
| | | import io.swagger.v3.oas.annotations.tags.Tag; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.validation.Valid; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.UUID; |
| | | |
| | | import static com.iailab.framework.common.pojo.CommonResult.success; |
| | | |
| | | @Tag(name = "数据归档设置") |
| | | @RestController |
| | | @RequestMapping("/data/arc/setting") |
| | | @Validated |
| | | public class ArcSettingController { |
| | | |
| | | @Autowired |
| | | private ArcSettingService arcSettingService; |
| | | |
| | | @GetMapping("page") |
| | | public CommonResult<PageResult<ArcSettingEntity>> page(@Valid ArcSettingPageReqVO reqVO) { |
| | | PageResult<ArcSettingEntity> page = arcSettingService.queryPage(reqVO); |
| | | return success(page); |
| | | } |
| | | |
| | | @GetMapping("/list") |
| | | @Operation(summary = "列表") |
| | | public CommonResult<List<ArcSettingEntity>> list(@Valid @RequestParam Map<String, Object> params) { |
| | | List<ArcSettingEntity> list = arcSettingService.list(params); |
| | | return success(list); |
| | | } |
| | | |
| | | @GetMapping("/info/{id}") |
| | | public CommonResult<ArcSettingEntity> info(@PathVariable("id") String id) { |
| | | ArcSettingEntity info = arcSettingService.info(id); |
| | | return success(info); |
| | | } |
| | | |
| | | @PreAuthorize("@ss.hasPermission('data:arc:create')") |
| | | @PostMapping("create") |
| | | public CommonResult<Boolean> create(@RequestBody ArcSettingEntity arcSettingEntity) { |
| | | String id = UUID.randomUUID().toString(); |
| | | arcSettingEntity.setId(id); |
| | | arcSettingService.add(arcSettingEntity); |
| | | return success(true); |
| | | } |
| | | |
| | | @PreAuthorize("@ss.hasPermission('data:arc:update')") |
| | | @PutMapping("/update") |
| | | public CommonResult<Boolean> update(@RequestBody ArcSettingEntity arcSettingEntity) { |
| | | arcSettingService.update(arcSettingEntity); |
| | | return success(true); |
| | | } |
| | | |
| | | @PreAuthorize("@ss.hasPermission('data:arc:delete')") |
| | | @DeleteMapping("/delete") |
| | | public CommonResult<Boolean> delete(String id) { |
| | | arcSettingService.delete(id); |
| | | return success(true); |
| | | } |
| | | |
| | | @PutMapping("/enable") |
| | | @Operation(summary = "启用") |
| | | public CommonResult<Boolean> enable(@RequestBody String[] ids) { |
| | | arcSettingService.enableByIds(ids); |
| | | return success(true); |
| | | } |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.data.arc.controller; |
对比新文件 |
| | |
| | | package com.iailab.module.data.arc.dao; |
| | | |
| | | import com.iailab.framework.common.pojo.PageResult; |
| | | import com.iailab.framework.mybatis.core.mapper.BaseMapperX; |
| | | import com.iailab.framework.mybatis.core.query.LambdaQueryWrapperX; |
| | | import com.iailab.framework.tenant.core.db.dynamic.TenantDS; |
| | | import com.iailab.module.data.arc.entity.ArcDataEntity; |
| | | import com.iailab.module.data.arc.vo.ArcDataPageReqVO; |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | |
| | | @TenantDS |
| | | @Mapper |
| | | public interface ArcDataDao extends BaseMapperX<ArcDataEntity> { |
| | | |
| | | default PageResult<ArcDataEntity> selectPage(ArcDataPageReqVO reqVO) { |
| | | return selectPage(reqVO, new LambdaQueryWrapperX<ArcDataEntity>() |
| | | .eq(ArcDataEntity::getArcId, reqVO.getArcId()) |
| | | .ge(reqVO.getStartTime()!=null, ArcDataEntity::getCreateTime, reqVO.getStartTime()) |
| | | .le(reqVO.getEndTime()!=null, ArcDataEntity::getCreateTime, reqVO.getEndTime()) |
| | | .orderByDesc(ArcDataEntity::getCreateTime)); |
| | | } |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.data.arc.dao; |
| | | |
| | | import com.iailab.framework.common.pojo.PageResult; |
| | | import com.iailab.framework.mybatis.core.mapper.BaseMapperX; |
| | | import com.iailab.framework.mybatis.core.query.LambdaQueryWrapperX; |
| | | import com.iailab.framework.tenant.core.db.dynamic.TenantDS; |
| | | import com.iailab.module.data.arc.entity.ArcSettingEntity; |
| | | import com.iailab.module.data.arc.vo.ArcSettingPageReqVO; |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | |
| | | @TenantDS |
| | | @Mapper |
| | | public interface ArcSettingDao extends BaseMapperX<ArcSettingEntity> { |
| | | |
| | | default PageResult<ArcSettingEntity> selectPage(ArcSettingPageReqVO reqVO) { |
| | | return selectPage(reqVO, new LambdaQueryWrapperX<ArcSettingEntity>() |
| | | .likeIfPresent(ArcSettingEntity::getName, reqVO.getName()) |
| | | .likeIfPresent(ArcSettingEntity::getType, reqVO.getType()) |
| | | .orderByDesc(ArcSettingEntity::getCreateTime)); |
| | | } |
| | | } |
文件名从 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/entity/ArcPointDataEntity.java 修改 |
| | |
| | | package com.iailab.module.data.point.entity; |
| | | package com.iailab.module.data.arc.entity; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.IdType; |
| | | import com.baomidou.mybatisplus.annotation.TableId; |
| | |
| | | import lombok.Data; |
| | | |
| | | import java.io.Serializable; |
| | | import java.math.BigDecimal; |
| | | |
| | | @Data |
| | | @TableName("t_arc_data") |
| | | public class ArcPointDataEntity implements Serializable { |
| | | public class ArcDataEntity implements Serializable { |
| | | |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | |
| | | private String arcId; |
| | | |
| | | /** |
| | | * 编码 |
| | | */ |
| | | private String code; |
| | | |
| | | /** |
| | | * 值 |
| | | */ |
| | | private String value; |
| | | private BigDecimal arcValue; |
| | | |
| | | /** |
| | | * 归档时间 |
文件名从 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/entity/ArcPointSettingEntity.java 修改 |
| | |
| | | package com.iailab.module.data.point.entity; |
| | | package com.iailab.module.data.arc.entity; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.IdType; |
| | | import com.baomidou.mybatisplus.annotation.TableId; |
| | |
| | | import lombok.Data; |
| | | |
| | | import java.io.Serializable; |
| | | import java.util.Date; |
| | | |
| | | @Data |
| | | @TableName("t_arc_setting") |
| | | public class ArcPointSettingEntity implements Serializable { |
| | | public class ArcSettingEntity implements Serializable { |
| | | |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | |
| | | private String calculate; |
| | | |
| | | /** |
| | | * 排序 |
| | | */ |
| | | private Integer sort; |
| | | |
| | | /** |
| | | * 是否启用 |
| | | */ |
| | | private String isEnable; |
| | |
| | | /** |
| | | * 创建时间 |
| | | */ |
| | | private String createTime; |
| | | private Date createTime; |
| | | |
| | | /** |
| | | * 更新时间 |
| | | */ |
| | | private String updateTime; |
| | | private Date updateTime; |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.data.arc; |
对比新文件 |
| | |
| | | package com.iailab.module.data.arc.service; |
| | | |
| | | import com.iailab.framework.common.pojo.PageResult; |
| | | import com.iailab.framework.common.service.BaseService; |
| | | import com.iailab.module.data.arc.entity.ArcDataEntity; |
| | | import com.iailab.module.data.arc.vo.ArcDataPageReqVO; |
| | | |
| | | public interface ArcDataService extends BaseService<ArcDataEntity> { |
| | | //根据归档类型进行归档 |
| | | void archiving(String type); |
| | | |
| | | PageResult<ArcDataEntity> queryPage(ArcDataPageReqVO reqVO); |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.data.arc.service; |
| | | |
| | | import com.iailab.framework.common.pojo.PageResult; |
| | | import com.iailab.framework.common.service.BaseService; |
| | | import com.iailab.module.data.arc.entity.ArcSettingEntity; |
| | | import com.iailab.module.data.arc.vo.ArcSettingPageReqVO; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | @Service |
| | | public interface ArcSettingService extends BaseService<ArcSettingEntity> { |
| | | |
| | | List<ArcSettingEntity> list(Map<String, Object> params); |
| | | |
| | | void update(ArcSettingEntity arcSettingEntity); |
| | | |
| | | void delete(String id); |
| | | |
| | | void enableByIds(String[] ids); |
| | | |
| | | void add(ArcSettingEntity arcSettingEntity); |
| | | |
| | | ArcSettingEntity info(String id); |
| | | |
| | | PageResult<ArcSettingEntity> queryPage(ArcSettingPageReqVO reqVO); |
| | | } |
文件名从 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/service/impl/ArcPointDataServiceImpl.java 修改 |
| | |
| | | package com.iailab.module.data.point.service.impl; |
| | | package com.iailab.module.data.arc.service.impl; |
| | | |
| | | import com.iailab.framework.common.pojo.PageResult; |
| | | import com.iailab.framework.common.service.impl.BaseServiceImpl; |
| | | import com.iailab.module.data.api.point.DataPointApiImpl; |
| | | import com.iailab.module.data.api.point.dto.ApiPointValueDTO; |
| | | import com.iailab.module.data.api.point.dto.ApiPointValueQueryDTO; |
| | | import com.iailab.module.data.common.enums.ArcCalculateTypeEnum; |
| | | import com.iailab.module.data.point.dao.ArcPointDataDao; |
| | | import com.iailab.module.data.point.entity.ArcPointDataEntity; |
| | | import com.iailab.module.data.point.entity.ArcPointSettingEntity; |
| | | import com.iailab.module.data.point.service.ArcPointDataService; |
| | | import com.iailab.module.data.arc.dao.ArcDataDao; |
| | | import com.iailab.module.data.arc.entity.ArcDataEntity; |
| | | import com.iailab.module.data.arc.entity.ArcSettingEntity; |
| | | import com.iailab.module.data.arc.service.ArcDataService; |
| | | import com.iailab.module.data.common.enums.ArcTypeEnum; |
| | | import com.iailab.module.data.point.service.ArcPointSettingService; |
| | | import com.iailab.module.data.arc.service.ArcSettingService; |
| | | import com.iailab.module.data.arc.vo.ArcDataPageReqVO; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | |
| | | |
| | | |
| | | @Service |
| | | public class ArcPointDataServiceImpl extends BaseServiceImpl<ArcPointDataDao, ArcPointDataEntity> implements ArcPointDataService { |
| | | public class ArcDataServiceImpl extends BaseServiceImpl<ArcDataDao, ArcDataEntity> implements ArcDataService { |
| | | |
| | | @Autowired |
| | | private ArcPointSettingService arcPointSettingService; |
| | | private ArcSettingService arcPointSettingService; |
| | | |
| | | @Autowired |
| | | private DataPointApiImpl dataPointApi; |
| | | |
| | | @Autowired |
| | | private ArcDataDao arcDataDao; |
| | | |
| | | //根据归档类型进行归档 |
| | | @Override |
| | |
| | | switch (ArcTypeEnum.getEumByCode(type)) { |
| | | case HOUR: |
| | | //查询对应类型的归档设置列表 |
| | | List<ArcPointSettingEntity> arcHourList = arcPointSettingService.list(params); |
| | | List<ArcSettingEntity> arcHourList = arcPointSettingService.list(params); |
| | | //遍历列表 |
| | | arcHourList.forEach(item -> { |
| | | log.debug("开始归档,point:"+item.getPoint()); |
| | |
| | | //归档 |
| | | SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH"); |
| | | String arcTime = dateFormat.format(startTime); |
| | | ArcPointDataEntity arcPointDataEntity = new ArcPointDataEntity(); |
| | | arcPointDataEntity.setId(String.valueOf(new Date().getTime())); |
| | | arcPointDataEntity.setArcTime(arcTime); |
| | | arcPointDataEntity.setArcId(item.getId()); |
| | | arcPointDataEntity.setValue(String.valueOf(value)); |
| | | insert(arcPointDataEntity); |
| | | ArcDataEntity arcDataEntity = new ArcDataEntity(); |
| | | arcDataEntity.setId(String.valueOf(new Date().getTime())); |
| | | arcDataEntity.setArcTime(arcTime); |
| | | arcDataEntity.setArcId(item.getId()); |
| | | arcDataEntity.setArcValue(value); |
| | | insert(arcDataEntity); |
| | | log.debug("归档完成,point:"+item.getPoint()); |
| | | }); |
| | | break; |
| | | case SHIFT: |
| | | //查询对应类型的归档设置列表 |
| | | List<ArcPointSettingEntity> arcShiftList = arcPointSettingService.list(params); |
| | | List<ArcSettingEntity> arcShiftList = arcPointSettingService.list(params); |
| | | //遍历列表 |
| | | arcShiftList.forEach(item -> { |
| | | log.debug("开始归档,point:"+item.getPoint()); |
| | |
| | | //归档 |
| | | SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH"); |
| | | String arcTime = dateFormat.format(startTime); |
| | | ArcPointDataEntity arcPointDataEntity = new ArcPointDataEntity(); |
| | | arcPointDataEntity.setId(String.valueOf(new Date().getTime())); |
| | | arcPointDataEntity.setArcTime(arcTime); |
| | | arcPointDataEntity.setArcId(item.getId()); |
| | | arcPointDataEntity.setValue(String.valueOf(value)); |
| | | insert(arcPointDataEntity); |
| | | ArcDataEntity arcDataEntity = new ArcDataEntity(); |
| | | arcDataEntity.setId(String.valueOf(new Date().getTime())); |
| | | arcDataEntity.setArcTime(arcTime); |
| | | arcDataEntity.setArcId(item.getId()); |
| | | arcDataEntity.setArcValue(value); |
| | | insert(arcDataEntity); |
| | | log.debug("归档完成,point:"+item.getPoint()); |
| | | }); |
| | | break; |
| | | case DAY: |
| | | //查询对应类型的归档设置列表 |
| | | List<ArcPointSettingEntity> arcDayList = arcPointSettingService.list(params); |
| | | List<ArcSettingEntity> arcDayList = arcPointSettingService.list(params); |
| | | //遍历列表 |
| | | arcDayList.forEach(item -> { |
| | | log.debug("开始归档,point:"+item.getPoint()); |
| | |
| | | //归档 |
| | | SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); |
| | | String arcTime = dateFormat.format(startTime); |
| | | ArcPointDataEntity arcPointDataEntity = new ArcPointDataEntity(); |
| | | arcPointDataEntity.setId(String.valueOf(new Date().getTime())); |
| | | arcPointDataEntity.setArcTime(arcTime); |
| | | arcPointDataEntity.setArcId(item.getId()); |
| | | arcPointDataEntity.setValue(String.valueOf(value)); |
| | | insert(arcPointDataEntity); |
| | | ArcDataEntity arcDataEntity = new ArcDataEntity(); |
| | | arcDataEntity.setId(String.valueOf(new Date().getTime())); |
| | | arcDataEntity.setArcTime(arcTime); |
| | | arcDataEntity.setArcId(item.getId()); |
| | | arcDataEntity.setArcValue(value); |
| | | insert(arcDataEntity); |
| | | log.debug("归档完成,point:"+item.getPoint()); |
| | | }); |
| | | break; |
| | | case MONTH: |
| | | //查询对应类型的归档设置列表 |
| | | List<ArcPointSettingEntity> arcMonthList = arcPointSettingService.list(params); |
| | | List<ArcSettingEntity> arcMonthList = arcPointSettingService.list(params); |
| | | //遍历列表 |
| | | arcMonthList.forEach(item -> { |
| | | log.debug("开始归档,point:"+item.getPoint()); |
| | |
| | | //归档 |
| | | SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM"); |
| | | String arcTime = dateFormat.format(startTime); |
| | | ArcPointDataEntity arcPointDataEntity = new ArcPointDataEntity(); |
| | | arcPointDataEntity.setId(String.valueOf(new Date().getTime())); |
| | | arcPointDataEntity.setArcTime(arcTime); |
| | | arcPointDataEntity.setArcId(item.getId()); |
| | | arcPointDataEntity.setValue(String.valueOf(value)); |
| | | insert(arcPointDataEntity); |
| | | ArcDataEntity arcDataEntity = new ArcDataEntity(); |
| | | arcDataEntity.setId(String.valueOf(new Date().getTime())); |
| | | arcDataEntity.setArcTime(arcTime); |
| | | arcDataEntity.setArcId(item.getId()); |
| | | arcDataEntity.setArcValue(value); |
| | | insert(arcDataEntity); |
| | | log.debug("归档完成,point:"+item.getPoint()); |
| | | }); |
| | | break; |
| | | case YEAR: |
| | | //查询对应类型的归档设置列表 |
| | | List<ArcPointSettingEntity> arcYearList = arcPointSettingService.list(params); |
| | | List<ArcSettingEntity> arcYearList = arcPointSettingService.list(params); |
| | | //遍历列表 |
| | | arcYearList.forEach(item -> { |
| | | log.debug("开始归档,point:"+item.getPoint()); |
| | |
| | | //归档 |
| | | SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy"); |
| | | String arcTime = dateFormat.format(startTime); |
| | | ArcPointDataEntity arcPointDataEntity = new ArcPointDataEntity(); |
| | | arcPointDataEntity.setId(String.valueOf(new Date().getTime())); |
| | | arcPointDataEntity.setArcTime(arcTime); |
| | | arcPointDataEntity.setArcId(item.getId()); |
| | | arcPointDataEntity.setValue(String.valueOf(value)); |
| | | insert(arcPointDataEntity); |
| | | ArcDataEntity arcDataEntity = new ArcDataEntity(); |
| | | arcDataEntity.setId(String.valueOf(new Date().getTime())); |
| | | arcDataEntity.setArcTime(arcTime); |
| | | arcDataEntity.setArcId(item.getId()); |
| | | arcDataEntity.setArcValue(value); |
| | | insert(arcDataEntity); |
| | | log.debug("归档完成,point:"+item.getPoint()); |
| | | }); |
| | | break; |
| | |
| | | } |
| | | return value; |
| | | } |
| | | |
| | | @Override |
| | | public PageResult<ArcDataEntity> queryPage(ArcDataPageReqVO reqVO) { |
| | | return arcDataDao.selectPage(reqVO); |
| | | } |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.data.arc.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.iailab.framework.common.pojo.PageResult; |
| | | import com.iailab.framework.common.service.impl.BaseServiceImpl; |
| | | import com.iailab.module.data.common.enums.IsEnableEnum; |
| | | import com.iailab.module.data.arc.dao.ArcSettingDao; |
| | | import com.iailab.module.data.arc.entity.ArcSettingEntity; |
| | | import com.iailab.module.data.arc.service.ArcSettingService; |
| | | import com.iailab.module.data.arc.vo.ArcSettingPageReqVO; |
| | | import org.apache.commons.lang3.ObjectUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.util.*; |
| | | |
| | | @Service |
| | | public class ArcSettingServiceImpl extends BaseServiceImpl<ArcSettingDao, ArcSettingEntity> implements ArcSettingService { |
| | | |
| | | @Autowired |
| | | private ArcSettingDao arcPointSettingDao; |
| | | |
| | | @Override |
| | | public List<ArcSettingEntity> list(Map<String, Object> params) { |
| | | Object type = params.get("type"); |
| | | QueryWrapper<ArcSettingEntity> queryWrapper = new QueryWrapper(); |
| | | queryWrapper.eq(!ObjectUtils.isEmpty(type), "type", type); |
| | | return arcPointSettingDao.selectList(queryWrapper); |
| | | } |
| | | |
| | | @Override |
| | | public void update(ArcSettingEntity arcSettingEntity) { |
| | | arcPointSettingDao.updateById(arcSettingEntity); |
| | | } |
| | | |
| | | @Override |
| | | public void delete(String id) { |
| | | arcPointSettingDao.deleteById(id); |
| | | } |
| | | |
| | | @Override |
| | | public void enableByIds(String[] ids) { |
| | | if (CollectionUtils.isEmpty(Arrays.asList(ids))) { |
| | | return; |
| | | } |
| | | Arrays.asList(ids).forEach(item -> { |
| | | ArcSettingEntity entity = new ArcSettingEntity(); |
| | | entity.setId(item); |
| | | entity.setIsEnable(IsEnableEnum.ENABLE.getCode().toString()); |
| | | entity.setUpdateTime(new Date()); |
| | | arcPointSettingDao.updateById(entity); |
| | | }); |
| | | } |
| | | |
| | | @Override |
| | | public void add(ArcSettingEntity arcSettingEntity) { |
| | | arcPointSettingDao.insert(arcSettingEntity); |
| | | } |
| | | |
| | | @Override |
| | | public ArcSettingEntity info(String id) { |
| | | return arcPointSettingDao.selectById(id); |
| | | } |
| | | |
| | | @Override |
| | | public PageResult<ArcSettingEntity> queryPage(ArcSettingPageReqVO reqVO) { |
| | | return arcPointSettingDao.selectPage(reqVO); |
| | | } |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.data.arc.vo; |
| | | |
| | | import com.iailab.framework.common.pojo.PageParam; |
| | | import lombok.Data; |
| | | import lombok.EqualsAndHashCode; |
| | | import lombok.ToString; |
| | | import org.springframework.format.annotation.DateTimeFormat; |
| | | |
| | | import java.util.Date; |
| | | |
| | | import static com.iailab.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; |
| | | |
| | | @Data |
| | | @EqualsAndHashCode(callSuper = true) |
| | | @ToString(callSuper = true) |
| | | public class ArcDataPageReqVO extends PageParam { |
| | | |
| | | /** |
| | | * 归档id |
| | | */ |
| | | private String arcId; |
| | | |
| | | /** |
| | | * 开始时间 |
| | | */ |
| | | @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) |
| | | private Date startTime; |
| | | |
| | | /** |
| | | * 结束时间 |
| | | */ |
| | | @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) |
| | | private Date endTime; |
| | | } |
copy from iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/entity/ArcPointSettingEntity.java
copy to iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/arc/vo/ArcSettingPageReqVO.java
文件从 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/entity/ArcPointSettingEntity.java 复制 |
| | |
| | | package com.iailab.module.data.point.entity; |
| | | package com.iailab.module.data.arc.vo; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.IdType; |
| | | import com.baomidou.mybatisplus.annotation.TableId; |
| | | import com.baomidou.mybatisplus.annotation.TableName; |
| | | import com.iailab.framework.common.pojo.PageParam; |
| | | import lombok.Data; |
| | | import lombok.EqualsAndHashCode; |
| | | import lombok.ToString; |
| | | |
| | | import java.io.Serializable; |
| | | |
| | | /** |
| | | * @author lirm |
| | | * @Description |
| | | * @createTime 2024年09月2日 |
| | | */ |
| | | @Data |
| | | @TableName("t_arc_setting") |
| | | public class ArcPointSettingEntity implements Serializable { |
| | | |
| | | private static final long serialVersionUID = 1L; |
| | | @EqualsAndHashCode(callSuper = true) |
| | | @ToString(callSuper = true) |
| | | public class ArcSettingPageReqVO extends PageParam { |
| | | |
| | | /** |
| | | * id |
| | |
| | | * 更新时间 |
| | | */ |
| | | private String updateTime; |
| | | } |
| | | } |
| | |
| | | */ |
| | | |
| | | import com.iailab.framework.common.constant.CommonConstant; |
| | | import com.iailab.module.data.channel.http.collector.asdb.HttpCollectorForAsdb; |
| | | import com.iailab.module.data.channel.http.collector.ihdb.HttpCollectorForIhd; |
| | | import com.iailab.module.data.channel.http.entity.HttpApiEntity; |
| | | import com.iailab.module.data.channel.http.service.HttpApiService; |
| | |
| | | @Autowired |
| | | private HttpCollectorForIhd httpCollectorForIhd; |
| | | |
| | | @Autowired |
| | | private HttpCollectorForAsdb httpCollectorForAsdb; |
| | | |
| | | public Object getTagValue(String apiId, String tag) { |
| | | HttpApiEntity httpApi = httpApiService.getFromCatch(apiId); |
| | | if (httpApi == null) { |
| | |
| | | Map<String, Object> valueMap = new HashMap<String, Object>(); |
| | | if (SourceApiEnum.iHyperDB.getCode().equals(httpApi.getCode())) { |
| | | valueMap = httpCollectorForIhd.getLastValues(apiId, tagNames); |
| | | } else if (SourceApiEnum.ASDB.getCode().equals(httpApi.getCode())) { |
| | | valueMap = httpCollectorForAsdb.getTagValues(apiId, tagNames); |
| | | } |
| | | if (valueMap.get(tag) == null) { |
| | | return CommonConstant.BAD_VALUE; |
| | |
| | | @Getter |
| | | @AllArgsConstructor |
| | | public enum SourceApiEnum { |
| | | iHyperDB("iHyperDB", "宝信IHD"); |
| | | iHyperDB("iHyperDB", "宝信IHD"), |
| | | ASDB("ASDB", "鞍钢DB"); |
| | | |
| | | private String code; |
| | | private String desc; |
| | |
| | | import com.iailab.module.data.common.utils.TagUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.redis.core.BoundHashOperations; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.util.*; |
| | | import java.util.concurrent.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * AnSteelDB采集 |
| | |
| | | @Autowired |
| | | private RedisTemplate redisTemplate; |
| | | |
| | | ThreadPoolExecutor threadPool = new ThreadPoolExecutor(18, 36, 30, TimeUnit.SECONDS, |
| | | new ArrayBlockingQueue<Runnable>(36), new ThreadPoolExecutor.AbortPolicy()); |
| | | |
| | | private static final String STA_TRUE = "true"; |
| | | |
| | | private static final int GROUP_MAX_COUNT = 300; |
| | | |
| | | private static final int MAX_WAIT = 30; |
| | | |
| | | private static final String pattern = "yyyyMMddHHmm00"; |
| | | |
| | | private static final String IS_SUCCESS = "isSuccess"; |
| | | |
| | | /** |
| | | * tagName |
| | | */ |
| | | private static final String N = "n"; |
| | | |
| | | /** |
| | | * dimension |
| | | */ |
| | | private static final String D = "d"; |
| | | |
| | | /** |
| | | * 类型 |
| | | */ |
| | | private static final String P = "p"; |
| | | |
| | | /** |
| | | * dataValue |
| | | */ |
| | | private static final String V = "v"; |
| | | |
| | | /** |
| | | * dataTime |
| | | */ |
| | | private static final String T = "t"; |
| | | |
| | | /** |
| | | * 数据质量G:good,B:bad |
| | | */ |
| | | private static final String Q = "q"; |
| | | public static final long offset = 10; |
| | | |
| | | private HttpApiEntity getHttpApi(String id) { |
| | | if (apiMap.containsKey(id)) { |
| | |
| | | return httpApi; |
| | | } |
| | | |
| | | public BigDecimal getTagValue(String sourceId, String tagNo, Integer dimension, String valueType) { |
| | | public BigDecimal getTagValue(String sourceId, String tagNo) { |
| | | BigDecimal value = CommonConstant.BAD_VALUE; |
| | | HttpApiEntity httpApi = this.getHttpApi(sourceId); |
| | | String responseStr = HttpUtils.sendGet(httpApi.getUrl(), null, ""); |
| | | if (responseStr == null) { |
| | | return value; |
| | | //先查缓存 |
| | | String catchKey = "IailabData:" + httpApi.getCode() + ":" + tagNo; |
| | | if (redisTemplate.hasKey(catchKey)) { |
| | | log.info("查找IailabData缓存: " + catchKey); |
| | | return new BigDecimal(redisTemplate.opsForValue().get(catchKey).toString()); |
| | | } |
| | | String responseStr = HttpUtils.sendGet(httpApi.getUrl(), null, ""); |
| | | List<HttpAsdbRespDataVO> dataList = JSON.parseArray(responseStr, HttpAsdbRespDataVO.class); |
| | | value = Objects.requireNonNull(dataList.stream().filter(data -> tagNo.equals(data.getPoint())).findFirst().orElse(null)).getValue(); |
| | | log.info("存入IailabData缓存: " + catchKey); |
| | | dataList.forEach(item -> { |
| | | redisTemplate.opsForValue().set(catchKey, item.getValue().toString(), offset, TimeUnit.SECONDS); |
| | | }); |
| | | for (HttpAsdbRespDataVO data : dataList){ |
| | | if (tagNo.equals(data.getPoint())){ |
| | | value = data.getValue(); |
| | | break; |
| | | } |
| | | } |
| | | return value; |
| | | } |
| | | |
| | | public Map<String, Object> getLastValues(String sourceId, List<String> tagNames) { |
| | | public Map<String, Object> getTagValues(String sourceId, List<String> tagNames) { |
| | | Map<String, Object> result = new HashMap<>(); |
| | | HttpApiEntity httpApi = this.getHttpApi(sourceId); |
| | | try { |
| | | if (CollectionUtils.isEmpty(tagNames)) { |
| | | return result; |
| | | } |
| | | List<String> noCacheTagNames = new ArrayList<>();//未缓存的tag |
| | | for (int i = 0; i < tagNames.size(); i++) { |
| | | //先查缓存 |
| | | BoundHashOperations<String, String, Object> ops = redisTemplate.boundHashOps(tagNames.get(i)); |
| | | if (ops.get(V) != null) { |
| | | BigDecimal value = new BigDecimal(ops.get(V).toString()); |
| | | result.put(tagNames.get(i), value.setScale(3, RoundingMode.HALF_UP)); |
| | | } else { |
| | | noCacheTagNames.add(tagNames.get(i)); |
| | | } |
| | | } |
| | | if (CollectionUtils.isEmpty(noCacheTagNames)) { |
| | | log.info("全部读取缓存"); |
| | | return result; |
| | | } |
| | | log.info("查询未缓存的数据"); |
| | | String responseStr = HttpUtils.sendGet(httpApi.getUrl(), null, ""); |
| | | List<HttpAsdbRespDataVO> dataList = JSON.parseArray(responseStr, HttpAsdbRespDataVO.class); |
| | | List<HttpAsdbRespDataVO> noCacheDataList = dataList.stream().filter(data -> noCacheTagNames.contains(data.getPoint())).collect(Collectors.toList()); |
| | | for (HttpAsdbRespDataVO data : noCacheDataList ){ |
| | | if (data.getValue() != null){ |
| | | //存缓存 |
| | | BoundHashOperations<String, String, Object> ops = redisTemplate.boundHashOps(data.getValue().toString()); |
| | | ops.put(V, data.getValue().toString()); |
| | | //设置过期时间 |
| | | redisTemplate.expire(data.getValue().toString(), 10, TimeUnit.SECONDS); |
| | | //把查询到的数据插入结果集 |
| | | BigDecimal value = new BigDecimal(data.getValue().toString()); |
| | | result.put(data.getPoint(), value.setScale(3, RoundingMode.HALF_UP)); |
| | | } else { |
| | | result.put(data.getPoint(), CommonConstant.BAD_VALUE); |
| | | } |
| | | for (String tagName : tagNames) { |
| | | result.put(tagName, getTagValue(sourceId, tagName)); |
| | | } |
| | | } catch (Exception ex) { |
| | | log.info("getCurrentValue异常"); |
| | |
| | | return new HashMap<>(); |
| | | } |
| | | try { |
| | | Map<Integer, List<Object[]>> measurePointsCountGroup = new HashMap<>(); |
| | | int pointListSize = params.size(); |
| | | int groupCount = pointListSize / GROUP_MAX_COUNT + ((pointListSize % GROUP_MAX_COUNT) > 0 ? 1 : 0); |
| | | log.info("groupCount=" + groupCount); |
| | | for (int i = 0; i < groupCount; i++) { |
| | | int end = (i + 1) * GROUP_MAX_COUNT; |
| | | if (end > pointListSize) { |
| | | end = pointListSize; |
| | | } |
| | | measurePointsCountGroup.put(i, params.subList(i * GROUP_MAX_COUNT, end)); |
| | | } |
| | | log.info("measurePointsCountGroup.size()=" + measurePointsCountGroup.size()); |
| | | result = new ConcurrentHashMap<>(params.size()); |
| | | CountDownLatch countDownLatch = new CountDownLatch(measurePointsCountGroup.size()); |
| | | for (Map.Entry<Integer, List<Object[]>> measurePointsItem : measurePointsCountGroup.entrySet()) { |
| | | HttpApiEntity httpApi = this.getHttpApi(measurePointsItem.getValue().get(0)[0].toString()); |
| | | // 并发 |
| | | Thread.sleep(1000); |
| | | threadPool.submit(new Task(httpApi.getUrl(), httpApi.getCode(), result, measurePointsItem.getValue(), |
| | | collectTime, countDownLatch)); |
| | | // 顺序 |
| | | //this.getByHtp(result, measurePointsItem.getValue(), collectTime); |
| | | } |
| | | countDownLatch.await(MAX_WAIT, TimeUnit.SECONDS); |
| | | |
| | | HttpApiEntity httpApi = this.getHttpApi(params.get(0)[0].toString()); |
| | | this.getByHtp(httpApi.getUrl(), httpApi.getCode(), result, params); |
| | | } catch (Exception ex) { |
| | | ex.printStackTrace(); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * 异步采集任务 |
| | | */ |
| | | private class Task implements Runnable { |
| | | String url; |
| | | String sourceName; |
| | | Date collectTime; |
| | | Map<String, Object> result; |
| | | List<Object[]> params; |
| | | CountDownLatch countDownLatch; |
| | | |
| | | public Task(String url, String sourceName, Map<String, Object> result, List<Object[]> params, |
| | | Date collectTime, CountDownLatch countDownLatch) { |
| | | this.url = url; |
| | | this.sourceName = sourceName; |
| | | this.result = result; |
| | | this.collectTime = collectTime; |
| | | this.params = params; |
| | | this.countDownLatch = countDownLatch; |
| | | private void getByHtp(String url, String sourceName, Map<String, Object> result, List<Object[]> params) { |
| | | String responseStr = HttpUtils.sendGet(url, null, ""); |
| | | List<HttpAsdbRespDataVO> dataList = JSON.parseArray(responseStr, HttpAsdbRespDataVO.class); |
| | | Map<String, HttpAsdbRespDataVO> valueGroup = new HashMap<>(); |
| | | for (HttpAsdbRespDataVO data : dataList) { |
| | | valueGroup.put(data.getPoint(), data); |
| | | } |
| | | |
| | | @Override |
| | | public void run() { |
| | | try { |
| | | log.info("请求的Tag数量:" + params.size()); |
| | | this.getByHtp(url, sourceName, result, params, collectTime); |
| | | log.info("请求结束:url=" + url); |
| | | } catch (Exception ex) { |
| | | log.info("获取采集值失败," + ex.getMessage()); |
| | | ex.printStackTrace(); |
| | | } finally { |
| | | countDownLatch.countDown(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * getTagDataByHttp |
| | | * |
| | | * @param url |
| | | * @param sourceName |
| | | * @param result |
| | | * @param params |
| | | * @param collectTime |
| | | */ |
| | | private void getByHtp(String url, String sourceName, Map<String, Object> result, List<Object[]> params, Date collectTime) { |
| | | String responseStr = HttpUtils.sendGet(url, null, ""); |
| | | List<HttpAsdbRespDataVO> dataList = JSON.parseArray(responseStr, HttpAsdbRespDataVO.class); |
| | | for (HttpAsdbRespDataVO data : dataList){ |
| | | for (Object[] item : params) { |
| | | if (valueGroup.containsKey(item[1].toString())) { |
| | | HttpAsdbRespDataVO data = valueGroup.get(item[1].toString()); |
| | | result.put(TagUtils.genTagId(DataSourceType.HTTP.getCode(), sourceName, data.getPoint()), data.getValue()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void getByHtp(String url, String sourceName, Map<String, Object> result, List<Object[]> params, Date collectTime) {String responseStr = HttpUtils.sendGet(url, null, ""); |
| | | List<HttpAsdbRespDataVO> dataList = JSON.parseArray(responseStr, HttpAsdbRespDataVO.class); |
| | | for (HttpAsdbRespDataVO data : dataList){ |
| | | result.put(TagUtils.genTagId(DataSourceType.HTTP.getCode(), sourceName, data.getPoint()), data.getValue()); |
| | | }} |
| | | } |
| | |
| | | package com.iailab.module.data.job.task; |
| | | |
| | | import com.iailab.module.data.common.enums.ArcTypeEnum; |
| | | import com.iailab.module.data.point.collection.PointCollector; |
| | | import com.iailab.module.data.point.service.ArcPointDataService; |
| | | import com.iailab.module.data.arc.service.ArcDataService; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.time.LocalDateTime; |
| | | import java.util.Calendar; |
| | | |
| | | /** |
| | | * @description: Point归档1h |
| | |
| | | private final String NET = "1h"; |
| | | |
| | | @Resource |
| | | private ArcPointDataService arcPointDataService; |
| | | private ArcDataService arcPointDataService; |
| | | |
| | | @Override |
| | | public void run(String params){ |
| | |
| | | package com.iailab.module.data.job.task; |
| | | |
| | | import com.iailab.module.data.common.enums.ArcTypeEnum; |
| | | import com.iailab.module.data.point.service.ArcPointDataService; |
| | | import com.iailab.module.data.arc.service.ArcDataService; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | |
| | |
| | | private final String NET = "1h"; |
| | | |
| | | @Resource |
| | | private ArcPointDataService arcPointDataService; |
| | | private ArcDataService arcPointDataService; |
| | | |
| | | @Override |
| | | public void run(String params){ |
| | |
| | | package com.iailab.module.data.job.task; |
| | | |
| | | import com.iailab.module.data.common.enums.ArcTypeEnum; |
| | | import com.iailab.module.data.point.service.ArcPointDataService; |
| | | import com.iailab.module.data.arc.service.ArcDataService; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | |
| | |
| | | private final String NET = "1h"; |
| | | |
| | | @Resource |
| | | private ArcPointDataService arcPointDataService; |
| | | private ArcDataService arcPointDataService; |
| | | |
| | | @Override |
| | | public void run(String params){ |
| | |
| | | package com.iailab.module.data.job.task; |
| | | |
| | | import com.iailab.module.data.common.enums.ArcTypeEnum; |
| | | import com.iailab.module.data.point.service.ArcPointDataService; |
| | | import com.iailab.module.data.arc.service.ArcDataService; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | |
| | |
| | | private final String NET = "1h"; |
| | | |
| | | @Resource |
| | | private ArcPointDataService arcPointDataService; |
| | | private ArcDataService arcPointDataService; |
| | | |
| | | @Override |
| | | public void run(String params){ |
| | |
| | | package com.iailab.module.data.job.task; |
| | | |
| | | import com.iailab.module.data.common.enums.ArcTypeEnum; |
| | | import com.iailab.module.data.point.service.ArcPointDataService; |
| | | import com.iailab.module.data.arc.service.ArcDataService; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | |
| | |
| | | private final String NET = "1h"; |
| | | |
| | | @Resource |
| | | private ArcPointDataService arcPointDataService; |
| | | private ArcDataService arcPointDataService; |
| | | |
| | | @Override |
| | | public void run(String params){ |
| | |
| | | |
| | | import com.iailab.framework.common.util.string.StrUtils; |
| | | import com.iailab.module.data.channel.http.collector.SourceApiEnum; |
| | | import com.iailab.module.data.channel.http.collector.asdb.HttpCollectorForAsdb; |
| | | import com.iailab.module.data.channel.http.collector.ihdb.HttpCollectorForIhd; |
| | | import com.iailab.module.data.channel.opcda.collector.OpcDACollector; |
| | | import com.iailab.module.data.common.enums.CommonConstant; |
| | |
| | | @Autowired |
| | | private HttpCollectorForIhd httpCollectorForIhd; |
| | | |
| | | @Autowired |
| | | private HttpCollectorForAsdb httpCollectorForAsdb; |
| | | |
| | | @Resource |
| | | private DaPointService daPointService; |
| | | |
| | |
| | | List<String[]> modbusTagIds = new ArrayList<>(); |
| | | List<String[]> kioTagIds = new ArrayList<>(); |
| | | List<Object[]> httpTagIhd = new ArrayList<>(); |
| | | |
| | | List<Object[]> httpTagAsdb = new ArrayList<>(); |
| | | |
| | | dtos.stream().forEach(item -> { |
| | | if (DataSourceType.OPCUA.getCode().equals(item.getSourceType())) { |
| | |
| | | if (SourceApiEnum.iHyperDB.getCode().equals(item.getSourceName())) { |
| | | if (item.getTagNo() != null && item.getDimension() != null && item.getValueType() != null) { |
| | | httpTagIhd.add(new Object[]{item.getSourceId(), item.getTagNo(), item.getDimension(), item.getValueType()}); |
| | | } |
| | | } else if (SourceApiEnum.ASDB.getCode().equals(item.getSourceName())) { |
| | | if (item.getTagNo() != null && item.getDimension() != null && item.getValueType() != null) { |
| | | httpTagAsdb.add(new Object[]{item.getSourceId(), item.getTagNo(), item.getDimension(), item.getValueType()}); |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | if (!CollectionUtils.isEmpty(httpTagIhd)) { |
| | | tagValues.putAll(httpCollectorForIhd.getTagValues(httpTagIhd, collectTime)); |
| | | } |
| | | if (!CollectionUtils.isEmpty(httpTagAsdb)) { |
| | | tagValues.putAll(httpCollectorForAsdb.getTagValues(httpTagAsdb, collectTime)); |
| | | } |
| | | this.toCommonResult(collectTime, dtos, tagValues, dataMap, result,listGood,listBad); |
| | | log.info("测量点处理结束"); |
| | |
| | | } else if (DataSourceType.KIO.getCode().equals(item.getSourceType())) { |
| | | value = kingIOCollector.getTagValue(item.getSourceId(), item.getTagNo()); |
| | | } else if (DataSourceType.HTTP.getCode().equals(item.getSourceType())) { |
| | | value = httpCollectorForIhd.getTagValue(item.getSourceId(), item.getTagNo(), item.getDimension(), item.getValueType()); |
| | | if (SourceApiEnum.iHyperDB.getCode().equals(item.getSourceName())) { |
| | | value = httpCollectorForIhd.getTagValue(item.getSourceId(), item.getTagNo(), item.getDimension(), item.getValueType()); |
| | | } else if (SourceApiEnum.ASDB.getCode().equals(item.getSourceName())) { |
| | | value = httpCollectorForAsdb.getTagValue(item.getSourceId(), item.getTagNo()); |
| | | } |
| | | } else { |
| | | log.info("没有匹配的TagNo=" + item.getTagNo()); |
| | | } |
| | |
| | | - t_plan_item |
| | | - t_da_cumulate_point |
| | | - t_da_point_collect_status |
| | | - t_arc_data |
| | | - t_arc_setting |
| | | app: |
| | | app-key: data |
| | | app-secret: 85b0df7edc3df3611913df34ed695011 |
| | |
| | | @Operation(summary = "执行单独预测") |
| | | MdkPredictItemRespDTO predictItem(@Valid @RequestBody MdkPredictReqDTO reqDTO); |
| | | |
| | | @PostMapping(PREFIX + "/predict-sim-adjust") |
| | | @Operation(summary = "模拟调整") |
| | | Boolean predictSimAdjust(@Valid @RequestBody MdkPredictSimAdjustReqDTO reqDTO); |
| | | |
| | | @PostMapping(PREFIX + "/predict-adjust") |
| | | @Operation(summary = "预测自动调整") |
| | | Boolean predictAutoAdjust(@Valid @RequestBody MdkPredictReqDTO reqDTO); |
对比新文件 |
| | |
| | | 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; |
| | | |
| | | import javax.validation.constraints.NotNull; |
| | | import java.util.Date; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @author PanZhibao |
| | | * @Description |
| | | * @createTime 2025年02月24日 |
| | | */ |
| | | @Schema(description = "RPC 模型 - 模拟调整 DTO") |
| | | @Data |
| | | public class MdkPredictSimAdjustReqDTO { |
| | | |
| | | @Schema(description = "预测时间") |
| | | @NotNull(message="预测时间不能为空") |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") |
| | | private Date predictTime; |
| | | |
| | | @Schema(description = "调度方案编号") |
| | | @NotNull(message="调度方案编号不能为空") |
| | | private String scheduleCode; |
| | | |
| | | @Schema(description = "调度模型结果") |
| | | @NotNull(message="调度模型结果不能为空") |
| | | private Map<String, Object> modelResult; |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.enums; |
| | | |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.Getter; |
| | | |
| | | /** |
| | | * @author PanZhibao |
| | | * @Description |
| | | * @createTime 2025年02月24日 |
| | | */ |
| | | @Getter |
| | | @AllArgsConstructor |
| | | public enum PredictItemTypeEnum { |
| | | |
| | | NormalItem("48dffaa8-ac91-42f4-9369-79c9c2080ef5", "com.iailab.predictHandler.impl.PredictItemImpl"), |
| | | MergeItem("773ed6fb-3929-47c0-8749-0d6d11111111", "com.iailab.predictHandler.impl.PredictMergeItemImpl"); |
| | | |
| | | private String id; |
| | | private String type; |
| | | |
| | | public static PredictItemTypeEnum getEumById(String id) { |
| | | if (id == null) { |
| | | return null; |
| | | } |
| | | |
| | | for (PredictItemTypeEnum statusEnum : PredictItemTypeEnum.values()) { |
| | | if (statusEnum.getId().equals(id)) { |
| | | return statusEnum; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | } |
| | |
| | | |
| | | CREATE TABLE `t_st_adjust_result` ( |
| | | `id` varchar(36) NOT NULL COMMENT 'ID', |
| | | `predict_item_id` varchar(36) DEFAULT NULL COMMENT '预测项ID', |
| | | `config_id` varchar(36) DEFAULT NULL COMMENT '配置ID', |
| | | `output_id` varchar(36) DEFAULT NULL COMMENT '预测项输出ID', |
| | | `schedule_model_id` varchar(36) DEFAULT NULL COMMENT '调度模型ID', |
| | | `adjust_time` datetime NULL DEFAULT NULL COMMENT '模拟调整时间', |
| | | `adjust_value` varchar(500) DEFAULT NULL COMMENT '模拟调整值', |
| | | `json_value` varchar(1000) DEFAULT NULL COMMENT '模拟调整结果', |
| | | PRIMARY KEY (`id`) USING BTREE, |
| | | INDEX `idx_predict_item_id`(`predict_item_id` ASC) USING BTREE, |
| | | INDEX `idx_output_id`(`output_id` ASC) USING BTREE, |
| | | INDEX `idx_schedule_model_id`(`schedule_model_id` ASC) USING BTREE |
| | | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='模拟调整结果表'; |
| | | |
| | |
| | | package com.iailab.module.model.api; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.iailab.module.data.api.point.DataPointApi; |
| | | import com.iailab.module.data.api.point.dto.ApiPointValueWriteDTO; |
| | | import com.iailab.module.model.api.mcs.dto.StScheduleModelOutDTO; |
| | |
| | | import com.iailab.module.model.api.mdk.dto.*; |
| | | import com.iailab.module.model.common.enums.IsWriteEnum; |
| | | import com.iailab.module.model.common.enums.ModelOutResultType; |
| | | import com.iailab.module.model.common.enums.OutResultType; |
| | | import com.iailab.module.model.enums.CommonConstant; |
| | | import com.iailab.module.model.enums.PredictItemTypeEnum; |
| | | import com.iailab.module.model.mcs.pre.entity.DmModuleEntity; |
| | | import com.iailab.module.model.mcs.pre.service.DmModuleService; |
| | | import com.iailab.module.model.mcs.pre.service.MmPredictItemService; |
| | | import com.iailab.module.model.mcs.sche.entity.StAdjustConfigDetEntity; |
| | | import com.iailab.module.model.mcs.sche.entity.StScheduleSchemeEntity; |
| | | import com.iailab.module.model.mcs.sche.service.StAdjustConfigService; |
| | | import com.iailab.module.model.mcs.sche.service.StScheduleModelOutService; |
| | | import com.iailab.module.model.mcs.sche.service.StScheduleRecordService; |
| | | import com.iailab.module.model.mcs.sche.service.StScheduleSchemeService; |
| | | import com.iailab.module.model.mdk.predict.PredictModuleHandler; |
| | | import com.iailab.module.model.mdk.predict.PredictResultHandler; |
| | | import com.iailab.module.model.mdk.schedule.ScheduleModelHandler; |
| | | 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 com.iailab.module.model.mdk.vo.ScheduleResultVO; |
| | | import com.iailab.module.model.mdk.vo.*; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.*; |
| | | import java.util.concurrent.TimeUnit; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import static com.iailab.module.model.common.enums.ModelOutResultType.D; |
| | | |
| | | /** |
| | | * @author PanZhibao |
| | |
| | | |
| | | @Autowired |
| | | private DataPointApi dataPointApi; |
| | | |
| | | @Autowired |
| | | private StAdjustConfigService stAdjustConfigService; |
| | | |
| | | @Autowired |
| | | private RedisTemplate<String, Object> redisTemplate; |
| | |
| | | return resp; |
| | | } |
| | | |
| | | @Override |
| | | public Boolean predictSimAdjust(MdkPredictSimAdjustReqDTO reqDTO) { |
| | | StScheduleSchemeEntity scheduleScheme = stScheduleSchemeService.getByCode(reqDTO.getScheduleCode()); |
| | | List<StAdjustConfigDetEntity> detList = stAdjustConfigService.getDetByModelId(scheduleScheme.getModelId()); |
| | | if (CollectionUtils.isEmpty(detList)) { |
| | | return Boolean.FALSE; |
| | | } |
| | | for (StAdjustConfigDetEntity det : detList) { |
| | | ItemVO predictItem = mmPredictItemService.getItemById(det.getPredictItemId()); |
| | | List<StAdjustDeviationDTO> deviationList = new ArrayList<>(); |
| | | switch (PredictItemTypeEnum.getEumById(det.getItemTypeId())) { |
| | | case NormalItem: |
| | | double adjustValue = new BigDecimal(reqDTO.getModelResult().get(det.getOutKey()).toString()).doubleValue(); |
| | | StAdjustDeviationDTO deviationItem = new StAdjustDeviationDTO(); |
| | | deviationItem.setPortIdx(det.getModelParamPortOrder()); |
| | | deviationItem.setParamIdx(det.getModelParamPortOrder()); |
| | | deviationItem.setValue(adjustValue); |
| | | deviationList.add(deviationItem); |
| | | break; |
| | | case MergeItem: |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | // 开始预测 |
| | | predictModuleHandler.predictAdjust(predictItem, reqDTO.getPredictTime(), deviationList, scheduleScheme.getModelId()); |
| | | } |
| | | return Boolean.TRUE; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 预测调整 |
| | | * |
| | |
| | | List<MmItemOutputEntity> getByItemid(String itemId); |
| | | |
| | | MmItemOutputEntity getByItemid(String itemid, String resultstr, String resultIndex); |
| | | |
| | | List<MmItemOutputEntity> getByItemid(String itemid, String resultstr, List<Integer> resultIndexs); |
| | | |
| | | void deleteByItemId(String itemId); |
| | |
| | | |
| | | List<Object[]> getData(String outputId, Date predictTime, String timeFormat, int scale); |
| | | |
| | | double[] getSimpleData(String outputId, Date predictTime, int predictLength); |
| | | |
| | | void insert(List<MmItemResultJsonEntity> resultJsonList); |
| | | |
| | | void cleanResultJson(Map<String, Date> tMap); |
| | |
| | | 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; |
| | |
| | | } |
| | | |
| | | @Override |
| | | public double[] getSimpleData(String outputId, Date predictTime, int predictLength) { |
| | | double[] result = new double[predictLength]; |
| | | QueryWrapper<MmItemResultJsonEntity> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("outputid", outputId) |
| | | .eq("predicttime", DateUtils.format(predictTime, DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)); |
| | | MmItemResultJsonEntity data = baseDao.selectOne(wrapper); |
| | | if (data == null || StringUtils.isBlank(data.getJsonvalue())) { |
| | | return null; |
| | | } |
| | | List<Double> valueList = JSONArray.parseArray(data.getJsonvalue(), Double.class); |
| | | if (CollectionUtils.isEmpty(valueList)) { |
| | | return result; |
| | | } |
| | | for (int i = 0; i < predictLength; i++) { |
| | | result[i] = valueList.get(i); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | public void insert(List<MmItemResultJsonEntity> resultJsonList) { |
| | | baseDao.insertBatch(resultJsonList); |
| | | } |
| | |
| | | private String id; |
| | | |
| | | /** |
| | | * 预测项ID |
| | | * 配置ID |
| | | */ |
| | | private String predictItemId; |
| | | private String configId; |
| | | |
| | | /** |
| | | * 预测项输出ID |
| | | */ |
| | | private String outputId; |
| | | |
| | | /** |
| | | * 调度模型ID |
| | |
| | | |
| | | import com.iailab.framework.common.service.BaseService; |
| | | import com.iailab.module.model.mcs.sche.entity.StAdjustResultEntity; |
| | | import com.iailab.module.model.mdk.vo.DataValueVO; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @author PanZhibao |
| | |
| | | * @createTime 2025年02月23日 |
| | | */ |
| | | public interface StAdjustResultService extends BaseService<StAdjustResultEntity> { |
| | | |
| | | void saveResult(Map<String, List<DataValueVO>> resultMap, Date predictTime, String adjustValue, String scheduleModelId); |
| | | |
| | | double[] getSimpleData(String outputId, Date predictTime, int predictLength); |
| | | } |
| | |
| | | package com.iailab.module.model.mcs.sche.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.iailab.framework.common.service.impl.BaseServiceImpl; |
| | | import com.iailab.framework.common.util.date.DateUtils; |
| | | import com.iailab.module.model.mcs.sche.dao.StAdjustResultDao; |
| | | import com.iailab.module.model.mcs.sche.entity.StAdjustResultEntity; |
| | | import com.iailab.module.model.mcs.sche.service.StAdjustResultService; |
| | | import com.iailab.module.model.mdk.vo.DataValueVO; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.UUID; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @author PanZhibao |
| | |
| | | @Slf4j |
| | | @Service |
| | | public class StAdjustResultServiceImpl extends BaseServiceImpl<StAdjustResultDao, StAdjustResultEntity> implements StAdjustResultService { |
| | | |
| | | @Override |
| | | public void saveResult(Map<String, List<DataValueVO>> resultMap, Date predictTime, String adjustValue, String scheduleModelId) { |
| | | for (Map.Entry<String, List<DataValueVO>> entry : resultMap.entrySet()) { |
| | | StAdjustResultEntity entity = new StAdjustResultEntity(); |
| | | entity.setId(UUID.randomUUID().toString()); |
| | | entity.setScheduleModelId(scheduleModelId); |
| | | entity.setAdjustTime(predictTime); |
| | | entity.setAdjustValue(adjustValue); |
| | | entity.setOutputId(entry.getKey()); |
| | | List<Double> jsonValueList = entry.getValue().stream().map(valueVO -> valueVO.getDataValue()).collect(Collectors.toList()); |
| | | entity.setAdjustValue(JSONArray.toJSONString(jsonValueList)); |
| | | baseDao.insert(entity); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public double[] getSimpleData(String outputId, Date predictTime, int predictLength) { |
| | | double[] result = new double[predictLength]; |
| | | QueryWrapper<StAdjustResultEntity> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("output_id", outputId) |
| | | .eq("adjust_time", DateUtils.format(predictTime, DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)); |
| | | StAdjustResultEntity data = baseDao.selectOne(wrapper); |
| | | if (data == null || StringUtils.isBlank(data.getAdjustValue())) { |
| | | return null; |
| | | } |
| | | List<Double> valueList = JSONArray.parseArray(data.getAdjustValue(), Double.class); |
| | | if (CollectionUtils.isEmpty(valueList)) { |
| | | return result; |
| | | } |
| | | for (int i = 0; i < predictLength; i++) { |
| | | result[i] = valueList.get(i); |
| | | } |
| | | return result; |
| | | } |
| | | } |
| | |
| | | package com.iailab.module.model.mdk.predict; |
| | | |
| | | import com.iailab.module.model.common.exception.ModelResultErrorException; |
| | | 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 com.iailab.module.model.mdk.vo.StAdjustDeviationDTO; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | |
| | | * |
| | | * @param predictTime |
| | | * @param predictItemDto |
| | | * @param predictValueMap |
| | | * @return |
| | | * @throws ItemInvokeException |
| | | */ |
| | | PredictResultVO predict(Date predictTime, ItemVO predictItemDto, Map<String, double[]> predictValueMap) throws ItemInvokeException; |
| | | |
| | | /** |
| | | * 单个预测项预测(模拟调整) |
| | | * |
| | | * @param predictTime |
| | | * @param predictItemDto |
| | | * @param deviationList |
| | | * @return |
| | | * @throws ItemInvokeException |
| | | * @throws ModelResultErrorException |
| | | */ |
| | | PredictResultVO predictAdjust(Date predictTime, ItemVO predictItemDto, List<StAdjustDeviationDTO> deviationList) throws ItemInvokeException, ModelResultErrorException; |
| | | } |
| | |
| | | package com.iailab.module.model.mdk.predict; |
| | | |
| | | import com.iailab.module.model.mdk.vo.StAdjustDeviationDTO; |
| | | 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; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @author PanZhibao |
| | |
| | | * @param predictModel |
| | | * @param itemName |
| | | * @param itemNo |
| | | * @param deviation |
| | | * @param adjustValList |
| | | * @return |
| | | */ |
| | | PredictResultVO predictByModel(Date predictTime, MmPredictModelEntity predictModel,String itemName,String itemNo, double[][] deviation) throws ModelInvokeException; |
| | | PredictResultVO predictByModel(Date predictTime, MmPredictModelEntity predictModel,String itemName,String itemNo, List<StAdjustDeviationDTO> adjustValList) throws ModelInvokeException; |
| | | } |
| | |
| | | package com.iailab.module.model.mdk.predict; |
| | | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | 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.mdk.factory.PredictItemFactory; |
| | | import com.iailab.module.model.mdk.vo.ItemVO; |
| | | import com.iailab.module.model.mdk.vo.PredictResultVO; |
| | | import com.iailab.module.model.mdk.vo.StAdjustDeviationDTO; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | |
| | | * @param intervalTime |
| | | * @return |
| | | */ |
| | | public void predict(List<ItemVO> predictItemList, Date predictTime, int intervalTime,Map<String, PredictResultVO> predictResultMap) { |
| | | 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()); |
| | | predictValueMap.put(mmItemOutputEntityEntry.getKey().getId(), mmItemOutputEntityEntry.getValue()); |
| | | } |
| | | } |
| | | } |
| | |
| | | calendar.set(Calendar.MILLISECOND, 0); |
| | | calendar.set(Calendar.SECOND, 0); |
| | | if (PredGranularityEnum.H1.getCode().equals(predictItem.getGranularity())) { |
| | | calendar.set(Calendar.MINUTE,0); |
| | | }else if (PredGranularityEnum.D1.getCode().equals(predictItem.getGranularity())) { |
| | | calendar.set(Calendar.MINUTE,0); |
| | | calendar.set(Calendar.HOUR_OF_DAY,0); |
| | | calendar.set(Calendar.MINUTE, 0); |
| | | } else if (PredGranularityEnum.D1.getCode().equals(predictItem.getGranularity())) { |
| | | calendar.set(Calendar.MINUTE, 0); |
| | | calendar.set(Calendar.HOUR_OF_DAY, 0); |
| | | } |
| | | PredictResultVO predictResult; |
| | | if (!predictItem.getStatus().equals(ItemStatus.STATUS1.getCode())) { |
| | |
| | | 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}", |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | public void predictAdjust(ItemVO predictItem, Date predictTime, List<StAdjustDeviationDTO> deviationList, String scheduleModelId) { |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(predictTime); |
| | | calendar.set(Calendar.MILLISECOND, 0); |
| | | calendar.set(Calendar.SECOND, 0); |
| | | if (PredGranularityEnum.H1.getCode().equals(predictItem.getGranularity())) { |
| | | calendar.set(Calendar.MINUTE, 0); |
| | | } else if (PredGranularityEnum.D1.getCode().equals(predictItem.getGranularity())) { |
| | | calendar.set(Calendar.MINUTE, 0); |
| | | calendar.set(Calendar.HOUR_OF_DAY, 0); |
| | | } |
| | | |
| | | try { |
| | | PredictItemHandler predictItemHandler = predictItemFactory.create(predictItem.getId()); |
| | | PredictResultVO predictResult = predictItemHandler.predictAdjust(calendar.getTime(), predictItem, deviationList); |
| | | |
| | | // 保存预测结果 |
| | | predictResultHandler.savePredictAdjustResult(predictResult, JSONArray.toJSONString(deviationList), scheduleModelId); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | log.error(MessageFormat.format("预测项编号:{0},预测项名称:{1},预测失败:{2} 预测时刻:{3}", |
| | | predictItem.getId(), predictItem.getItemName(), e.getMessage(), predictTime)); |
| | | } |
| | | } |
| | | } |
| | |
| | | import com.iailab.module.model.common.enums.CommonDict; |
| | | import com.iailab.module.model.mcs.pre.entity.MmItemOutputEntity; |
| | | import com.iailab.module.model.mcs.pre.service.MmItemResultService; |
| | | import com.iailab.module.model.mcs.sche.service.StAdjustResultService; |
| | | import com.iailab.module.model.mdk.factory.ItemEntityFactory; |
| | | import com.iailab.module.model.mdk.vo.DataValueVO; |
| | | import com.iailab.module.model.mdk.vo.PredictResultVO; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.scheduling.annotation.Async; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | |
| | | @Autowired |
| | | private ItemEntityFactory itemEntityFactory; |
| | | |
| | | @Autowired |
| | | private StAdjustResultService stAdjustResultService; |
| | | |
| | | /** |
| | | * convertToPredictData |
| | | * |
| | |
| | | */ |
| | | 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; |
| | | // } |
| | | 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()) { |
| | | Map<MmItemOutputEntity, double[]> predictMatrixs = predictResult.getPredictMatrixs(); |
| | | HashMap<String, List<DataValueVO>> predictLists = new HashMap<>(); |
| | | for (Map.Entry<MmItemOutputEntity, double[]> entry : predictMatrixs.entrySet()) { |
| | | Integer rows = entry.getValue().length; |
| | | List<DataValueVO> predictDataList = new ArrayList<>(); |
| | | Calendar calendar = Calendar.getInstance(); |
| | |
| | | |
| | | //处理累计计算 |
| | | if (entry.getKey().getIscumulant() == 1) { |
| | | resultMap.put(entry.getKey().getId() + CommonDict.CUMULANT_SUFFIX, new ArrayList<DataValueVO>(){{ |
| | | resultMap.put(entry.getKey().getId() + CommonDict.CUMULANT_SUFFIX, new ArrayList<DataValueVO>() {{ |
| | | DataValueVO predictData = new DataValueVO(); |
| | | // 时间 预测时间+预测长度*粒度 |
| | | Calendar calendar = Calendar.getInstance(); |
| | |
| | | mmItemResultService.savePredictValue(resultMap, predictResult.getLt(), "n", predictResult.getPredictTime()); |
| | | } |
| | | |
| | | /** |
| | | * savePredictAdjustResult |
| | | * |
| | | * @param predictResult |
| | | */ |
| | | @DSTransactional |
| | | public void savePredictAdjustResult(PredictResultVO predictResult, String adjustValue, String scheduleModelId) { |
| | | Map<String, List<DataValueVO>> resultMap = convertToPredictData(predictResult); |
| | | stAdjustResultService.saveResult(resultMap, predictResult.getPredictTime(), adjustValue, scheduleModelId); |
| | | } |
| | | |
| | | public List<DataValueVO> getPredictValueByItemNo(String itemNo, Date start, Date end) { |
| | | String itemId = itemEntityFactory.getItemByItemNo(itemNo).getId(); |
| | | List<MmItemOutputEntity> outputList = itemEntityFactory.getOutPutByItemId(itemId); |
| | |
| | | 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.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.mcs.pre.service.MmItemResultJsonService; |
| | | import com.iailab.module.model.mcs.sche.service.StAdjustResultService; |
| | | 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.ItemVO; |
| | | import com.iailab.module.model.mdk.vo.PredictResultVO; |
| | | import com.iailab.module.model.mdk.vo.StAdjustDeviationDTO; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | |
| | | private ItemEntityFactory itemEntityFactory; |
| | | |
| | | @Autowired |
| | | private DataPointApi dataPointApi; |
| | | |
| | | @Autowired |
| | | private PredictItemFactory predictItemFactory; |
| | | |
| | | @Autowired |
| | | private PredictResultHandler predictResultHandler; |
| | | |
| | | @Autowired |
| | | private MmItemResultService mmItemResultService; |
| | | private MmItemResultJsonService mmItemResultJsonService; |
| | | |
| | | @Autowired |
| | | private MmItemOutputService mmItemOutputService; |
| | | |
| | | @Autowired |
| | | private StAdjustResultService stAdjustResultService; |
| | | |
| | | /** |
| | | * MergeItem预测 |
| | |
| | | String[] mathOutPutId = expression.split("[\\+ \\-]"); |
| | | ArrayList<Character> operator = new ArrayList<>(); |
| | | for (int i = 0; i < expression.length(); i++) { |
| | | if (expression.charAt(i)=='+' || expression.charAt(i)=='-'){ |
| | | if (expression.charAt(i) == '+' || expression.charAt(i) == '-') { |
| | | operator.add(expression.charAt(i)); |
| | | } |
| | | } |
| | | // String[] compositionItem = expression.split(String.valueOf("&".toCharArray())); |
| | | //是否为计算预测项 |
| | | if (mathOutPutId.length > 1) { |
| | | // 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); |
| | | // } |
| | | // } |
| | | |
| | | for (Integer i = 0; i < predictLength; i++) { |
| | | double sum =0.0; |
| | | double sum = 0.0; |
| | | sum = predictValueMap.get(mathOutPutId[0])[i]; |
| | | for (int j = 1; j < mathOutPutId.length; j++) { |
| | | if (operator.get(j-1)=='+') |
| | | {sum += predictValueMap.get(mathOutPutId[j])[i];} |
| | | if (operator.get(j-1)=='-') |
| | | {sum -= predictValueMap.get(mathOutPutId[j])[i];} |
| | | if (operator.get(j - 1) == '+') { |
| | | sum += predictValueMap.get(mathOutPutId[j])[i]; |
| | | } |
| | | if (operator.get(j - 1) == '-') { |
| | | sum -= predictValueMap.get(mathOutPutId[j])[i]; |
| | | } |
| | | } |
| | | 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); |
| | | // } |
| | | predictResult.setPredictId(itemId); |
| | | List<MmItemOutputEntity> outputServiceByItemid = mmItemOutputService.getByItemid(itemId); |
| | | if (!CollectionUtils.isEmpty(outputServiceByItemid)) { |
| | | Map<MmItemOutputEntity, double[]> predictMatrixs = new HashMap<>(); |
| | | predictMatrixs.put(outputServiceByItemid.get(0),predictResultMat); |
| | | predictMatrixs.put(outputServiceByItemid.get(0), predictResultMat); |
| | | predictResult.setPredictMatrixs(predictMatrixs); |
| | | } |
| | | predictResult.setPredictTime(predictTime); |
| | | } catch (Exception e) { |
| | | log.error("merge项预测失败,itemId:" + itemId); |
| | | e.printStackTrace(); |
| | | throw e; |
| | | } |
| | | log.info("merge项预测完成,itemId:" + itemId + ",结果:" + JSON.toJSONString(predictResult)); |
| | | return predictResult; |
| | | } |
| | | |
| | | @Override |
| | | public PredictResultVO predictAdjust(Date predictTime, ItemVO predictItemDto, List<StAdjustDeviationDTO> deviationList) |
| | | throws ItemInvokeException { |
| | | PredictResultVO predictResult = new PredictResultVO(); |
| | | String itemId = predictItemDto.getId(); |
| | | try { |
| | | String expression = itemEntityFactory.getMergeItem(itemId).getExpression(); |
| | | int predictLength = itemEntityFactory.getItemById(itemId).getPredictLength(); |
| | | double[] predictResultMat = new double[predictLength]; |
| | | String[] mathOutPutId = expression.split("[\\+ \\-]"); |
| | | ArrayList<Character> operator = new ArrayList<>(); |
| | | for (int i = 0; i < expression.length(); i++) { |
| | | if (expression.charAt(i) == '+' || expression.charAt(i) == '-') { |
| | | operator.add(expression.charAt(i)); |
| | | } |
| | | } |
| | | Map<String, double[]> predictValueMap = new HashMap<>(); |
| | | for (int k = 0; k < mathOutPutId.length; k++) { |
| | | String outPutId = mathOutPutId[k]; |
| | | double[] outPutValue = stAdjustResultService.getSimpleData(outPutId, predictTime, predictLength); |
| | | if (outPutValue == null) { |
| | | outPutValue = mmItemResultJsonService.getSimpleData(outPutId, predictTime, predictLength); |
| | | } |
| | | predictValueMap.put(outPutId, outPutValue); |
| | | } |
| | | |
| | | //是否为计算预测项 |
| | | if (mathOutPutId.length > 1) { |
| | | for (int i = 0; i < predictLength; i++) { |
| | | double sum = predictValueMap.get(mathOutPutId[0])[i]; |
| | | for (int j = 1; j < mathOutPutId.length; j++) { |
| | | if (operator.get(j - 1) == '+') { |
| | | sum += predictValueMap.get(mathOutPutId[j])[i]; |
| | | } |
| | | if (operator.get(j - 1) == '-') { |
| | | sum -= predictValueMap.get(mathOutPutId[j])[i]; |
| | | } |
| | | } |
| | | predictResultMat[i] = sum; |
| | | } |
| | | } |
| | | predictResult.setPredictId(itemId); |
| | | 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); |
| | |
| | | import com.iailab.module.model.mdk.predict.PredictModelHandler; |
| | | import com.iailab.module.model.mdk.vo.ItemVO; |
| | | import com.iailab.module.model.mdk.vo.PredictResultVO; |
| | | import com.iailab.module.model.mdk.vo.StAdjustDeviationDTO; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.text.MessageFormat; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | |
| | | } |
| | | return predictResult; |
| | | } |
| | | |
| | | /** |
| | | * NormalItem预测 |
| | | * |
| | | * @param predictTime |
| | | * @param predictItemDto |
| | | * @return |
| | | * @throws ItemInvokeException |
| | | */ |
| | | @Override |
| | | public PredictResultVO predictAdjust(Date predictTime, ItemVO predictItemDto, List<StAdjustDeviationDTO> deviationList) throws ItemInvokeException,ModelResultErrorException { |
| | | PredictResultVO predictResult = new PredictResultVO(); |
| | | String itemId = predictItemDto.getId(); |
| | | 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,predictItemDto.getItemName(),predictItemDto.getItemNo(), deviationList); |
| | | predictResult.setPredictId(itemId); |
| | | } catch (ModelResultErrorException ex) { |
| | | throw ex; |
| | | } catch (Exception ex) { |
| | | throw new ItemInvokeException(MessageFormat.format("{0},itemId={1}", |
| | | ItemInvokeException.errorItemFailed, itemId)); |
| | | } |
| | | return predictResult; |
| | | } |
| | | } |
| | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.iail.model.IAILModel; |
| | | import com.iailab.module.model.mdk.vo.StAdjustDeviationDTO; |
| | | import com.iailab.module.model.enums.CommonConstant; |
| | | import com.iailab.module.model.common.enums.OutResultType; |
| | | import com.iailab.module.model.common.exception.ModelResultErrorException; |
| | |
| | | * @throws ModelInvokeException |
| | | */ |
| | | @Override |
| | | public synchronized PredictResultVO predictByModel(Date predictTime, MmPredictModelEntity predictModel,String itemName,String itemNo) throws ModelInvokeException { |
| | | public PredictResultVO predictByModel(Date predictTime, MmPredictModelEntity predictModel, String itemName, String itemNo) throws ModelInvokeException { |
| | | PredictResultVO result = new PredictResultVO(); |
| | | if (predictModel == null) { |
| | | throw new ModelInvokeException("modelEntity is null"); |
| | |
| | | HashMap<String, Object> settings = getPredictSettingsByModelId(modelId); |
| | | // 校验setting必须有pyFile,否则可能导致程序崩溃 |
| | | if (!settings.containsKey(MdkConstant.PY_FILE_KEY)) { |
| | | throw new RuntimeException("模型设置参数缺少必要信息【" + MdkConstant.PY_FILE_KEY + "】,请重新上传模型!"); |
| | | throw new RuntimeException("模型设置参数缺少必要信息【" + MdkConstant.PY_FILE_KEY + "】,请重新上传模型!"); |
| | | } |
| | | |
| | | if (settings == null) { |
| | |
| | | param2Values[portLength] = newModelBean.getDataMap().get("models"); |
| | | param2Values[portLength + 1] = settings; |
| | | |
| | | log.info("####################### 预测模型 "+ "【itemId:" + predictModel.getItemid() + ",itemName:" + itemName + ",itemNo:" + itemNo + "】 ##########################"); |
| | | // JSONObject jsonObjNewModelBean = new JSONObject(); |
| | | // jsonObjNewModelBean.put("newModelBean", newModelBean); |
| | | // log.info(String.valueOf(jsonObjNewModelBean)); |
| | | // JSONObject jsonObjParam2Values = new JSONObject(); |
| | | // jsonObjParam2Values.put("param2Values", param2Values); |
| | | log.info("####################### 预测模型 " + "【itemId:" + predictModel.getItemid() + ",itemName:" + itemName + ",itemNo:" + itemNo + "】 ##########################"); |
| | | log.info("参数: " + JSON.toJSONString(param2Values)); |
| | | |
| | | //IAILMDK.run |
| | |
| | | * @param predictModel |
| | | * @param itemName |
| | | * @param itemNo |
| | | * @param deviationList |
| | | * @return |
| | | * @throws ModelInvokeException |
| | | */ |
| | | @Override |
| | | public synchronized PredictResultVO predictByModel(Date predictTime, MmPredictModelEntity predictModel,String itemName,String itemNo, double[][] deviation) throws ModelInvokeException { |
| | | public PredictResultVO predictByModel(Date predictTime, MmPredictModelEntity predictModel, String itemName, String itemNo, List<StAdjustDeviationDTO> deviationList) 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, itemName, new HashMap<>()); |
| | | List<SampleData> sampleDataList = sampleConstructor.constructSample(TypeA.Predict.name(), modelId, predictTime, itemName, new HashMap<>(), deviationList); |
| | | String modelPath = predictModel.getModelpath(); |
| | | if (modelPath == null) { |
| | | log.info("模型路径不存在,modelId=" + modelId); |
| | |
| | | HashMap<String, Object> settings = getPredictSettingsByModelId(modelId); |
| | | // 校验setting必须有pyFile,否则可能导致程序崩溃 |
| | | if (!settings.containsKey(MdkConstant.PY_FILE_KEY)) { |
| | | throw new RuntimeException("模型设置参数缺少必要信息【" + MdkConstant.PY_FILE_KEY + "】,请重新上传模型!"); |
| | | throw new RuntimeException("模型设置参数缺少必要信息【" + MdkConstant.PY_FILE_KEY + "】,请重新上传模型!"); |
| | | } |
| | | |
| | | if (settings == null) { |
| | |
| | | param2Values[portLength] = newModelBean.getDataMap().get("models"); |
| | | param2Values[portLength + 1] = settings; |
| | | |
| | | log.info("####################### 模拟调整 "+ "【itemId:" + predictModel.getItemid() + ",itemName:" + itemName + ",itemNo:" + itemNo + "】 ##########################"); |
| | | log.info("####################### 模拟调整 " + "【itemId:" + predictModel.getItemid() + ",itemName:" + itemName + ",itemNo:" + itemNo + "】 ##########################"); |
| | | log.info("参数: " + JSON.toJSONString(param2Values)); |
| | | |
| | | //IAILMDK.run |
| | |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * 构造IAILMDK.run()方法的newModelBean参数 |
| | | * |
| | |
| | | } |
| | | } |
| | | |
| | | int deviationIndex = 0; |
| | | |
| | | int portIdx = 0; |
| | | //对每个爪分别进行计算 |
| | | for (ColumnItemPort entry : sampleInfo.getColumnInfo()) { |
| | | double[][] matrix = new double[0][0]; |
| | |
| | | if (!CollectionUtils.isEmpty(indItemValueList)) { |
| | | matrix = new double[entry.getDataLength()][0]; |
| | | if (indItemValueList.size() > entry.getDataLength()) { |
| | | indItemValueList = indItemValueList.subList(0,entry.getDataLength()); |
| | | indItemValueList = indItemValueList.subList(0, entry.getDataLength()); |
| | | } |
| | | for (int i = 0; i < indItemValueList.size(); i++) { |
| | | String stringValue = indItemValueList.get(i).getDataValue().toString(); |
| | |
| | | matrix[i] = asciiArray; |
| | | } |
| | | } |
| | | }else { |
| | | } else { |
| | | //先依据爪内数据项的modelParamOrder进行排序——重写comparator匿名函数 |
| | | Collections.sort(entry.getColumnItemList(), new Comparator<ColumnItem>() { |
| | | @Override |
| | |
| | | } |
| | | } |
| | | |
| | | //找出对应的调整值 |
| | | double[] deviationItem = null; |
| | | if (sampleInfo.getDeviation() != null && sampleInfo.getDeviation().length > 0) { |
| | | deviationItem = sampleInfo.getDeviation()[deviationIndex]; |
| | | } |
| | | deviationIndex ++; |
| | | |
| | | //对每一项依次进行数据查询,然后将查询出的值赋给matrix对应的位置 |
| | | for (int i = 0; i < entry.getColumnItemList().size(); i++) { |
| | | try { |
| | | List<DataValueVO> dataEntityList = getData(entry.getColumnItemList().get(i), pointMap, planMap,indMap); |
| | | List<DataValueVO> dataEntityList = getData(entry.getColumnItemList().get(i), pointMap, planMap, indMap); |
| | | |
| | | //设置调整值 |
| | | if (deviationItem != null && deviationItem.length > 0) { |
| | | logger.info("设置调整值, i = " + i); |
| | | if (deviationItem[i] <= 0) { |
| | | continue; |
| | | } |
| | | for(int dataKey = 1; dataKey < dataEntityList.size(); dataKey ++) { |
| | | double adjustVal = SampleInfo.getAdjustValueFromDeviation(portIdx, i, sampleInfo.getDeviation()); |
| | | if (adjustVal != 0) { |
| | | logger.info("设置调整值adjustVal:" + adjustVal); |
| | | for (int dataKey = 1; dataKey < dataEntityList.size(); dataKey++) { |
| | | DataValueVO item = dataEntityList.get(dataKey); |
| | | item.setDataValue(item.getDataValue() + deviationItem[i]); |
| | | item.setDataValue(item.getDataValue() + adjustVal); |
| | | } |
| | | } |
| | | |
| | | //补全数据 |
| | | ColumnItem columnItem = entry.getColumnItemList().get(i); |
| | | dataEntityList = super.completionData(matrix.length, dataEntityList, columnItem.startTime, columnItem.endTime, columnItem.getParamType(),columnItem.getGranularity()); |
| | | dataEntityList = super.completionData(matrix.length, dataEntityList, columnItem.startTime, columnItem.endTime, columnItem.getParamType(), columnItem.getGranularity()); |
| | | |
| | | /** 如果数据取不满,把缺失的数据点放在后面 */ |
| | | if (dataEntityList != null && dataEntityList.size() != 0) { |
| | |
| | | throw e; |
| | | } |
| | | } |
| | | |
| | | portIdx++; |
| | | } |
| | | SampleData sampleData = new SampleData(); |
| | | sampleData.setMatrix(matrix); |
| | |
| | | package com.iailab.module.model.mdk.sample; |
| | | |
| | | import com.iailab.module.model.mdk.vo.StAdjustDeviationDTO; |
| | | import com.iailab.module.model.mdk.common.exceptions.ModelInvokeException; |
| | | import com.iailab.module.model.mdk.sample.dto.ColumnItemPort; |
| | | import com.iailab.module.model.mdk.sample.dto.SampleData; |
| | | import com.iailab.module.model.mdk.sample.dto.SampleInfo; |
| | | 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.util.Date; |
| | |
| | | } |
| | | |
| | | public List<SampleData> constructSample(String typeA, String modelId, Date runTime,String itemName, |
| | | Map<Integer, Integer> dynamicDataLength, double[][] deviation) throws ModelInvokeException { |
| | | Map<Integer, Integer> dynamicDataLength, List<StAdjustDeviationDTO> deviationList) throws ModelInvokeException { |
| | | try { |
| | | SampleInfoConstructor sampleInfoConstructor = sampleFactory.createSampleInfo(typeA, modelId); |
| | | SampleInfo sampleInfo = sampleInfoConstructor.prepareSampleInfo(modelId, runTime, dynamicDataLength); |
| | | sampleInfo.setDeviation(deviation); |
| | | sampleInfo.setDeviation(deviationList); |
| | | SampleDataConstructor sampleDataConstructor = sampleFactory.createSampleData(typeA); |
| | | return sampleDataConstructor.prepareSampleData(sampleInfo); |
| | | } catch (Exception e) { |
| | |
| | | import com.iailab.module.data.api.ind.dto.ApiIndItemDTO; |
| | | import com.iailab.module.data.api.plan.dto.ApiPlanItemDTO; |
| | | import com.iailab.module.data.api.point.dto.ApiPointDTO; |
| | | import com.iailab.module.model.mdk.vo.StAdjustDeviationDTO; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.Builder; |
| | | import lombok.Data; |
| | | import lombok.NoArgsConstructor; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.sql.Timestamp; |
| | |
| | | private Integer sampleCycle; |
| | | |
| | | // 调整值 |
| | | private double[][] deviation; |
| | | private List<StAdjustDeviationDTO> deviation; |
| | | // 所有测点信息,避免重复查询 |
| | | private Map<String, ApiPointDTO> pointMap; |
| | | // 所有计划数据信息,避免重复查询 |
| | | private Map<String, ApiPlanItemDTO> planMap; |
| | | // 所有计划数据信息,避免重复查询 |
| | | private Map<String, ApiIndItemDTO> indMap; |
| | | |
| | | public static double getAdjustValueFromDeviation(int portIdx, int paramIdx, List<StAdjustDeviationDTO> deviation) { |
| | | if (CollectionUtils.isEmpty(deviation)) { |
| | | return 0; |
| | | } |
| | | for (StAdjustDeviationDTO deviationItem : deviation) { |
| | | if (deviationItem.getPortIdx() == portIdx && deviationItem.getParamIdx() == paramIdx) { |
| | | return deviationItem.getValue(); |
| | | } |
| | | } |
| | | return 0; |
| | | } |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.mdk.vo; |
| | | |
| | | import io.swagger.v3.oas.annotations.media.Schema; |
| | | import lombok.Data; |
| | | |
| | | /** |
| | | * @author PanZhibao |
| | | * @Description |
| | | * @createTime 2025年02月24日 |
| | | */ |
| | | @Schema(description = "模型服务 - 模拟调整值 DTO") |
| | | @Data |
| | | public class StAdjustDeviationDTO { |
| | | |
| | | private int portIdx; |
| | | |
| | | private int paramIdx; |
| | | |
| | | private double value; |
| | | } |