Merge remote-tracking branch 'origin/master'
已删除6个文件
已修改33个文件
已复制1个文件
已添加50个文件
已重命名3个文件
| | |
| | | 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; |
| | | } |
| | | } |
| | |
| | | Map<String, Object> valueMap = new HashMap<String, Object>(); |
| | | if (SourceApiEnum.iHyperDB.getCode().equals(httpApi.getCode())) { |
| | | valueMap = httpCollectorForIhd.getLastValues(apiId, tagNames); |
| | | } |
| | | if (SourceApiEnum.ASDB.getCode().equals(httpApi.getCode())) { |
| | | valueMap = httpCollectorForAsdb.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; |
| | |
| | | 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; |
| | | } |
| | | } |
| | |
| | | INDEX `idx_schedule_model_id`(`schedule_model_id` ASC) USING BTREE |
| | | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='模拟调整结果表'; |
| | | |
| | | -- matlab |
| | | CREATE TABLE `t_ml_model` ( |
| | | `id` varchar(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL, |
| | | `model_name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '模型名称', |
| | | `model_file_name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '模型文件名', |
| | | `model_file_path` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '模型文件路径', |
| | | `model_type` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '模型类型', |
| | | `matlab_platform` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT 'matlab平台', |
| | | `matlab_version` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT 'matlab版本', |
| | | `remark` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '备注', |
| | | `creator` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '创建者', |
| | | `create_date` datetime NULL DEFAULT NULL COMMENT '创建时间', |
| | | `updater` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '更新者', |
| | | `update_date` datetime NULL DEFAULT NULL COMMENT '更新时间', |
| | | PRIMARY KEY (`id`) USING BTREE, |
| | | UNIQUE INDEX `model_file_name`(`model_file_name` ASC) USING BTREE |
| | | ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = 'matlab模型表' ROW_FORMAT = Dynamic; |
| | | |
| | | CREATE TABLE `t_ml_model_method` ( |
| | | `id` varchar(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL, |
| | | `ml_model_id` varchar(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '模型id', |
| | | `class_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '全类名', |
| | | `method_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '方法名', |
| | | `data_length` int NULL DEFAULT 1 COMMENT '数据长度', |
| | | `out_length` int NULL DEFAULT NULL COMMENT '输出长度', |
| | | `sort` int NULL DEFAULT NULL COMMENT '排序', |
| | | PRIMARY KEY (`id`, `ml_model_id`) USING BTREE, |
| | | INDEX `id`(`id` ASC) USING BTREE, |
| | | INDEX `index_model_id`(`ml_model_id` ASC) USING BTREE, |
| | | CONSTRAINT `t_ml_model_method_ibfk_1` FOREIGN KEY (`ml_model_id`) REFERENCES `t_ml_model` (`id`) ON DELETE CASCADE ON UPDATE RESTRICT |
| | | ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = 'matlab模型方法表' ROW_FORMAT = Dynamic; |
| | | |
| | | CREATE TABLE `t_ml_model_method_setting` ( |
| | | `id` varchar(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT 'id', |
| | | `ml_model_method_id` varchar(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '模型方法id', |
| | | `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '参数名称', |
| | | `setting_key` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '参数key', |
| | | `setting_value` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '参数值', |
| | | `value_type` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '参数类型', |
| | | `sort` int NULL DEFAULT NULL COMMENT '排序', |
| | | PRIMARY KEY (`id`) USING BTREE, |
| | | INDEX `id`(`id` ASC) USING BTREE, |
| | | INDEX `ml_model_method_id`(`ml_model_method_id` ASC) USING BTREE, |
| | | CONSTRAINT `t_ml_model_method_setting_ibfk_1` FOREIGN KEY (`ml_model_method_id`) REFERENCES `t_ml_model_method` (`id`) ON DELETE CASCADE ON UPDATE RESTRICT |
| | | ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = 'matlab模型方法参数表' ROW_FORMAT = Dynamic; |
| | | |
| | | CREATE TABLE `t_ml_project` ( |
| | | `id` varchar(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT 'id', |
| | | `project_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '项目名称', |
| | | `project_code` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '项目编码', |
| | | `create_time` timestamp NULL DEFAULT NULL COMMENT '创建时间', |
| | | `update_time` timestamp NULL DEFAULT NULL COMMENT '修改时间', |
| | | `publish_time` timestamp NULL DEFAULT NULL COMMENT '发布时间', |
| | | PRIMARY KEY (`id`) USING BTREE |
| | | ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = 'matlab项目表' ROW_FORMAT = DYNAMIC; |
| | | |
| | | CREATE TABLE `t_ml_project_model` ( |
| | | `id` varchar(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT 'id', |
| | | `project_id` varchar(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '项目id', |
| | | `model_id` varchar(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '模型id', |
| | | PRIMARY KEY (`id`, `project_id`, `model_id`) USING BTREE, |
| | | INDEX `model_id`(`model_id` ASC) USING BTREE, |
| | | INDEX `project_id`(`project_id` ASC) USING BTREE, |
| | | CONSTRAINT `t_ml_project_model_ibfk_1` FOREIGN KEY (`model_id`) REFERENCES `t_ml_model` (`id`) ON DELETE CASCADE ON UPDATE RESTRICT, |
| | | CONSTRAINT `t_ml_project_model_ibfk_2` FOREIGN KEY (`project_id`) REFERENCES `t_ml_project` (`id`) ON DELETE CASCADE ON UPDATE RESTRICT |
| | | ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = 'matlab项目模型关联表' ROW_FORMAT = DYNAMIC; |
| | | |
| | |
| | | <version>2.3.2</version> |
| | | </dependency> |
| | | |
| | | <!-- matlab --> |
| | | <dependency> |
| | | <groupId>com.matlab.javabuilder</groupId> |
| | | <artifactId>javabuilder</artifactId> |
| | | <version>9.6.0</version> |
| | | </dependency> |
| | | |
| | | </dependencies> |
| | | |
| | | <build> |
| | |
| | | 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; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 预测调整 |
| | | * |
对比新文件 |
| | |
| | | package com.iailab.module.model.matlab.common; |
| | | |
| | | /** |
| | | * @description: |
| | | * @author: dzd |
| | | * @date: 2025/2/14 10:59 |
| | | **/ |
| | | public interface MatlabConstant { |
| | | /** |
| | | * JNI |
| | | */ |
| | | String JNI = "JNI"; |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.matlab.common.exceptions; |
| | | |
| | | /** |
| | | * @description: 非法jar包异常 |
| | | * @author: dzd |
| | | * @date: 2025/2/26 17:52 |
| | | **/ |
| | | public class IllegalityJarException extends Exception { |
| | | private Throwable cause; |
| | | |
| | | public IllegalityJarException() { |
| | | } |
| | | |
| | | public IllegalityJarException(String msg) { |
| | | super(msg); |
| | | } |
| | | |
| | | public IllegalityJarException(String msg, Exception cause) { |
| | | super(msg, cause); |
| | | this.cause = cause; |
| | | } |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.matlab.common.utils; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.iail.model.IAILModel; |
| | | import com.iailab.module.model.matlab.common.exceptions.IllegalityJarException; |
| | | import com.iailab.module.model.matlab.dto.MatlabJarFileClassInfoDTO; |
| | | import com.iailab.module.model.matlab.dto.MatlabJarFileMethodInfoDTO; |
| | | import com.iailab.module.model.matlab.dto.MlModelMethodSettingDTO; |
| | | import com.iailab.module.model.mpk.common.MdkConstant; |
| | | import com.mathworks.toolbox.javabuilder.*; |
| | | import com.mathworks.toolbox.javabuilder.internal.MWFunctionSignature; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.lang.reflect.Field; |
| | | import java.lang.reflect.Method; |
| | | import java.lang.reflect.Modifier; |
| | | import java.net.MalformedURLException; |
| | | import java.net.URL; |
| | | import java.net.URLClassLoader; |
| | | import java.util.*; |
| | | import java.util.jar.JarEntry; |
| | | import java.util.jar.JarFile; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Slf4j |
| | | public class MatlabUtils { |
| | | |
| | | private static HashMap<String, URLClassLoader> classLoaderCache = new HashMap<>(); |
| | | private static HashMap<String, Object> classCache = new HashMap<>(); |
| | | private static HashMap<String, Method> classMethodCache = new HashMap<>(); |
| | | |
| | | /** |
| | | * @description: 解析matlab jar文件 |
| | | **/ |
| | | public static List<MatlabJarFileClassInfoDTO> parseJarInfo(String jarFilePath, String jatName) throws IllegalityJarException { |
| | | List<MatlabJarFileClassInfoDTO> classInfos = new ArrayList<>(); |
| | | //加载jar用于解析内部class method |
| | | URLClassLoader urlClassLoader = loadJar(null,jarFilePath); |
| | | try (JarFile jarFile = new JarFile(jarFilePath)) { |
| | | // 获取 JAR 文件中所有的条目 |
| | | Enumeration<JarEntry> entries = jarFile.entries(); |
| | | while (entries.hasMoreElements()) { |
| | | JarEntry entry = entries.nextElement(); |
| | | String entryName = entry.getName(); |
| | | // 检查条目是否为类文件 |
| | | if (entryName.endsWith(".class") && !entryName.endsWith("Remote.class") && !entryName.endsWith("MCRFactory.class")) { |
| | | MatlabJarFileClassInfoDTO classInfo = new MatlabJarFileClassInfoDTO(); |
| | | // 将类文件的路径转换为类的全限定名 |
| | | String className = entryName.replace('/', '.').substring(0, entryName.lastIndexOf(".class")); |
| | | // 校验包名是否和文件名一致,不一致则说明修改过jar包名,判定为非法包 |
| | | if (!className.startsWith(jatName)) { |
| | | throw new IllegalityJarException(); |
| | | } |
| | | |
| | | classInfo.setClassName(className); |
| | | try { |
| | | // 加载类 |
| | | Class<?> clazz = urlClassLoader.loadClass(className); |
| | | // 获取该类的所有属性 |
| | | Field[] fields = clazz.getDeclaredFields(); |
| | | List<MatlabJarFileMethodInfoDTO> methodInfos = new ArrayList<>(); |
| | | for (Field field : fields) { |
| | | int modifiers = field.getModifiers(); |
| | | if (Modifier.isPrivate(modifiers) && Modifier.isStatic(modifiers) && Modifier.isFinal(modifiers)) { |
| | | try { |
| | | // 绕过访问控制检查 |
| | | field.setAccessible(true); |
| | | Object value = field.get(null); // 静态字段不需要实例,传 null |
| | | if (value instanceof MWFunctionSignature) { |
| | | MatlabJarFileMethodInfoDTO methodInfo = new MatlabJarFileMethodInfoDTO(); |
| | | methodInfo.setMethodName(value.getClass().getField("name").get(value).toString()); |
| | | // 减1是为了排除最后面的setting |
| | | methodInfo.setDataLength((Integer) value.getClass().getField("numInputs").get(value) - 1); |
| | | methodInfo.setOutLength((Integer) value.getClass().getField("numOutputs").get(value)); |
| | | methodInfos.add(methodInfo); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("get matlab method info exception,className:" + className, e); |
| | | } |
| | | } |
| | | } |
| | | classInfo.setMethodInfos(methodInfos); |
| | | } catch (Exception e) { |
| | | log.error("get matlab class info exception,className:" + className, e); |
| | | } |
| | | classInfos.add(classInfo); |
| | | } |
| | | } |
| | | } catch (IOException e) { |
| | | log.error("get matlab jar info exception,jarFilePath:" + jarFilePath, e); |
| | | } finally { |
| | | unloadJar(urlClassLoader); |
| | | } |
| | | return classInfos; |
| | | } |
| | | |
| | | public static synchronized URLClassLoader loadJar(String projectId, String... jarPaths) { |
| | | try { |
| | | URL[] urls = new URL[jarPaths.length]; |
| | | for (int i = 0; i < jarPaths.length; i++) { |
| | | String jarPath = jarPaths[i]; |
| | | File jarFile = new File(jarPath); |
| | | if (!jarFile.exists()) { |
| | | throw new RuntimeException("jar沒有找到!" + jarPath); |
| | | } |
| | | urls[i] = new File(jarPath).toURI().toURL(); |
| | | } |
| | | |
| | | // 不能设置classloader的patent,让它使用双亲委派去找系统classloader中javabuilder.jar中的依赖。因为javabuilder.jar只能加载一次,加载多次会报资源占用 |
| | | URLClassLoader urlClassLoader = new URLClassLoader(urls); |
| | | if (projectId != null) { |
| | | addClassLoaderCache(projectId, urlClassLoader); |
| | | } |
| | | log.info("成功加载jar包:" + String.join(";",jarPaths)); |
| | | return urlClassLoader; |
| | | } catch (Exception e) { |
| | | throw new RuntimeException("加载jar异常", e); |
| | | } |
| | | } |
| | | |
| | | public static synchronized void unloadJar(URLClassLoader urlClassLoader) { |
| | | try { |
| | | urlClassLoader.close(); |
| | | log.info("成功卸载jar包。"); |
| | | } catch (Exception e) { |
| | | throw new RuntimeException("卸载jar异常", e); |
| | | } |
| | | } |
| | | |
| | | public static synchronized void addClassLoaderCache(String projectId, URLClassLoader urlClassLoader) { |
| | | classLoaderCache.put(projectId, urlClassLoader); |
| | | } |
| | | |
| | | public static synchronized URLClassLoader getClassLoader(String projectId) { |
| | | return classLoaderCache.get(projectId); |
| | | } |
| | | |
| | | public static synchronized void removeClassLoaderCache(String projectId) { |
| | | if (classLoaderCache.containsKey(projectId)) { |
| | | URLClassLoader urlClassLoader = classLoaderCache.get(projectId); |
| | | unloadJar(urlClassLoader); |
| | | classLoaderCache.remove(projectId); |
| | | removeClassCache(projectId); |
| | | removeClassMethodCache(projectId); |
| | | } |
| | | } |
| | | |
| | | public static synchronized void removeClassCache(String projectId) { |
| | | Iterator<String> iterator = classCache.keySet().iterator(); |
| | | while (iterator.hasNext()) { |
| | | String key = iterator.next(); |
| | | if (key.startsWith(projectId)) { |
| | | iterator.remove(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | public static synchronized void removeClassMethodCache(String projectId) { |
| | | Iterator<String> iterator = classMethodCache.keySet().iterator(); |
| | | while (iterator.hasNext()) { |
| | | String key = iterator.next(); |
| | | if (key.startsWith(projectId)) { |
| | | iterator.remove(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | public static void removeOldFile(String bakPath, String projectId) { |
| | | File dir = new File(bakPath); |
| | | if (dir.exists() && dir.isDirectory()) { |
| | | File[] files = dir.listFiles(); |
| | | if (null != files && files.length > 0) { |
| | | for (File file : files) { |
| | | if (file.getName().startsWith(projectId)) { |
| | | file.delete(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * @description: 项目启动加载已发布的dll和jar |
| | | * @author: dzd |
| | | * @date: 2024/10/10 11:58 |
| | | **/ |
| | | public static void loadProjectPublish(String bakPath) { |
| | | File dir = new File(bakPath); |
| | | if (dir.exists() && dir.isDirectory()) { |
| | | File[] files = dir.listFiles(); |
| | | if (null != files && files.length > 0) { |
| | | for (File file : files) { |
| | | String fileName = file.getName(); |
| | | if (fileName.endsWith(".jar")) { |
| | | String[] split = fileName.split(MdkConstant.SPLIT); |
| | | String projectId = split[0]; |
| | | |
| | | URLClassLoader urlClassLoader = null; |
| | | try { |
| | | // 加载新的jar |
| | | urlClassLoader = loadJar(projectId,file.getAbsolutePath()); |
| | | } catch (Exception e) { |
| | | throw new RuntimeException("加载jar异常", e); |
| | | } |
| | | // 成功后加入缓存 |
| | | addClassLoaderCache(projectId, urlClassLoader); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | public static HashMap<String, Object> run(IAILModel model, Object[] paramsValueArray, String projectId) throws Exception { |
| | | if (model == null) { |
| | | throw new RuntimeException("模型文件不能为空!"); |
| | | } else { |
| | | // 上传时校验文件名和class的开头是相同的,保证className唯一,可以用 projectId_className 作为唯一key |
| | | String classCacheKey = projectId + "_" + model.getClassName(); |
| | | String methodParams = Arrays.stream(model.getParamsArray()).map(e -> e.getName()).collect(Collectors.joining(",")); |
| | | String classMethodCacheKey = classCacheKey + "." + model.getMethodName() + "(" + methodParams + ")"; |
| | | // 因为一个类下可能有多多个方法,所以这里classCacheKey 和 classMethodCacheKey 要分开判断 |
| | | if (classCache.containsKey(classCacheKey)) { |
| | | if (classMethodCache.containsKey(classMethodCacheKey)) { |
| | | return (HashMap) classMethodCache.get(classMethodCacheKey).invoke(classCache.get(classCacheKey), paramsValueArray); |
| | | } else { |
| | | // 运行过这个类的其他方法,类从缓存中取,新建方法 |
| | | Object o = classCache.get(classCacheKey); |
| | | Class<?>[] paramsArray = new Class[2]; |
| | | paramsArray[0] = int.class; |
| | | paramsArray[1] = Object[].class; |
| | | Method method = o.getClass().getMethod(model.getMethodName(), paramsArray); |
| | | classMethodCache.put(classMethodCacheKey, method); |
| | | Object[] objects = (Object[]) method.invoke(o, paramsValueArray); |
| | | HashMap<String, Object> map = convertStructToMap((MWStructArray) objects[0]); |
| | | return map; |
| | | } |
| | | |
| | | } else { |
| | | URLClassLoader classLoader = getClassLoader(projectId); |
| | | if (null == classLoader) { |
| | | throw new RuntimeException("matlab未发布,classLoader为null"); |
| | | } |
| | | Class<?> clazz = classLoader.loadClass(model.getClassName()); |
| | | Object o = clazz.newInstance(); |
| | | Class<?>[] paramsArray = new Class[2]; |
| | | paramsArray[0] = int.class; |
| | | paramsArray[1] = Object[].class; |
| | | Method method = clazz.getMethod(model.getMethodName(), paramsArray); |
| | | classCache.put(classCacheKey, o); |
| | | classMethodCache.put(classMethodCacheKey, method); |
| | | Object[] objects = (Object[]) method.invoke(o, paramsValueArray); |
| | | HashMap<String, Object> map = convertStructToMap((MWStructArray) objects[0]); |
| | | return map; |
| | | } |
| | | } |
| | | } |
| | | |
| | | public static HashMap<String, Object> convertStructToMap(MWStructArray struct) { |
| | | HashMap<String, Object> map; |
| | | try { |
| | | map = new HashMap<>(); |
| | | String[] fieldNames = struct.fieldNames(); |
| | | int numElements = struct.numberOfElements(); |
| | | for (int i = 1; i <= numElements; i++) { |
| | | for (String fieldName : fieldNames) { |
| | | MWArray value = struct.getField(fieldName, i); |
| | | Object javaValue = convertMWArrayToJavaObject(value); |
| | | map.put(fieldName, javaValue); |
| | | } |
| | | } |
| | | } finally { |
| | | struct.dispose(); |
| | | } |
| | | return map; |
| | | } |
| | | |
| | | private static Object convertMWArrayToJavaObject(MWArray mwArray) { |
| | | try { |
| | | if (mwArray instanceof MWNumericArray) { |
| | | MWNumericArray numArray = (MWNumericArray) mwArray; |
| | | if (numArray.numberOfElements() == 1) { |
| | | MWClassID mwClassID = numArray.classID(); |
| | | if (mwClassID.equals(MWClassID.DOUBLE)) { |
| | | return numArray.getDouble(); |
| | | } else if (mwClassID.equals(MWClassID.SINGLE)) { |
| | | return numArray.getFloat(); |
| | | } else if (mwClassID.equals(MWClassID.INT8) || mwClassID.equals(MWClassID.UINT8)) { |
| | | return numArray.getByte(); |
| | | } else if (mwClassID.equals(MWClassID.INT16) || mwClassID.equals(MWClassID.UINT16)) { |
| | | return numArray.getShort(); |
| | | } else if (mwClassID.equals(MWClassID.INT32) || mwClassID.equals(MWClassID.UINT32)) { |
| | | return numArray.getInt(); |
| | | } else if (mwClassID.equals(MWClassID.INT64) || mwClassID.equals(MWClassID.UINT64)) { |
| | | return numArray.getLong(); |
| | | } else if (mwClassID.equals(MWClassID.LOGICAL)) { |
| | | return numArray.getByte(); |
| | | } |
| | | return null; |
| | | } else { |
| | | MWClassID mwClassID = numArray.classID(); |
| | | if (mwClassID.equals(MWClassID.DOUBLE)) { |
| | | return numArray.toDoubleArray(); |
| | | } else if (mwClassID.equals(MWClassID.SINGLE)) { |
| | | return numArray.toFloatArray(); |
| | | } else if (mwClassID.equals(MWClassID.INT8)) { |
| | | return numArray.toByteArray(); |
| | | } else if (mwClassID.equals(MWClassID.INT16) || mwClassID.equals(MWClassID.UINT16)) { |
| | | return numArray.toShortArray(); |
| | | } else if (mwClassID.equals(MWClassID.INT32) || mwClassID.equals(MWClassID.UINT32)) { |
| | | return numArray.toIntArray(); |
| | | } else if (mwClassID.equals(MWClassID.INT64) || mwClassID.equals(MWClassID.UINT64)) { |
| | | return numArray.toLongArray(); |
| | | } else if (mwClassID.equals(MWClassID.LOGICAL)) { |
| | | return numArray.toByteArray(); |
| | | } |
| | | return null; |
| | | } |
| | | } else if (mwArray instanceof MWCharArray) { |
| | | MWCharArray stringArray = (MWCharArray) mwArray; |
| | | if (stringArray.numberOfElements() == 1) { |
| | | return stringArray.getChar(1); |
| | | } else { |
| | | // 不支持string,string都是用char[]返回,所以这里将char[]转为string |
| | | int[] dimensions = stringArray.getDimensions(); |
| | | if (dimensions[0] == 1) { |
| | | //string |
| | | return stringArray.toString(); |
| | | } else { |
| | | //String[] 暂时只考虑一维string |
| | | char[][] array = (char[][]) stringArray.toArray(); |
| | | String[] list = new String[dimensions[0]]; |
| | | for (int i = 0; i < dimensions[0]; i++) { |
| | | list[i] = (String.valueOf(array[i])); |
| | | } |
| | | return list; |
| | | } |
| | | } |
| | | } else if (mwArray instanceof MWLogicalArray) { |
| | | MWLogicalArray logicalArray = (MWLogicalArray) mwArray; |
| | | if (logicalArray.numberOfElements() == 1) { |
| | | return logicalArray.getBoolean(1); |
| | | } else { |
| | | int[] dimensions = logicalArray.getDimensions(); |
| | | return logicalArray.toArray(); |
| | | } |
| | | } else if (mwArray instanceof MWStructArray) { |
| | | MWStructArray structArray = (MWStructArray) mwArray; |
| | | return convertStructToMap(structArray); |
| | | } |
| | | } finally { |
| | | mwArray.dispose(); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public static HashMap<String, Object> handleModelSettings(List<MlModelMethodSettingDTO> modelSettings) { |
| | | HashMap<String, Object> resultMap = null; |
| | | try { |
| | | resultMap = new HashMap<>(modelSettings.size()); |
| | | for (MlModelMethodSettingDTO modelSetting : modelSettings) { |
| | | switch (modelSetting.getValueType()) { |
| | | case "int": |
| | | resultMap.put(modelSetting.getSettingKey(), Integer.valueOf(modelSetting.getSettingValue())); |
| | | break; |
| | | case "string": |
| | | resultMap.put(modelSetting.getSettingKey(), modelSetting.getSettingValue()); |
| | | break; |
| | | case "decimal": |
| | | resultMap.put(modelSetting.getSettingKey(), Double.valueOf(modelSetting.getSettingValue())); |
| | | break; |
| | | case "decimalArray": |
| | | JSONArray jsonArray = JSON.parseArray(modelSetting.getSettingValue()); |
| | | double[] doubles = new double[jsonArray.size()]; |
| | | for (int i = 0; i < jsonArray.size(); i++) { |
| | | doubles[i] = Double.valueOf(String.valueOf(jsonArray.get(i))); |
| | | } |
| | | resultMap.put(modelSetting.getSettingKey(), doubles); |
| | | break; |
| | | } |
| | | } |
| | | } catch (NumberFormatException e) { |
| | | throw new RuntimeException("模型参数有误,请检查!!!"); |
| | | } |
| | | return resultMap; |
| | | } |
| | | |
| | | public static MWStructArray convertMapToStruct(Map<String, Object> map) { |
| | | String[] fieldNames = map.keySet().toArray(new String[0]); |
| | | MWStructArray struct = new MWStructArray(1, 1, fieldNames); |
| | | for (String key : map.keySet()) { |
| | | Object value = map.get(key); |
| | | if (value instanceof Number) { |
| | | struct.set(key, 1, ((Number) value).doubleValue()); |
| | | } else if (value instanceof String) { |
| | | struct.set(key, 1, value); |
| | | } |
| | | // 可以根据需要添加更多类型的处理 |
| | | } |
| | | return struct; |
| | | } |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.matlab.controller.admin; |
| | | |
| | | import com.iailab.framework.common.exception.enums.GlobalErrorCodeConstants; |
| | | import com.iailab.framework.common.page.PageData; |
| | | import com.iailab.framework.common.pojo.CommonResult; |
| | | import com.iailab.module.model.matlab.common.exceptions.IllegalityJarException; |
| | | import com.iailab.module.model.matlab.dto.MatlabJarFileInfoDTO; |
| | | import com.iailab.module.model.matlab.dto.MatlabRunDTO; |
| | | import com.iailab.module.model.matlab.dto.MlModelDTO; |
| | | import com.iailab.module.model.matlab.service.MlModelService; |
| | | import com.iailab.module.model.mpk.dto.MpkFileDTO; |
| | | import io.swagger.v3.oas.annotations.Operation; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | import static com.iailab.framework.common.pojo.CommonResult.success; |
| | | |
| | | |
| | | /** |
| | | * @author Dzd |
| | | * @since 1.0.0 2025-02-08 |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/model/matlab/model") |
| | | public class MlModelController { |
| | | @Autowired |
| | | private MlModelService mlModelService; |
| | | |
| | | @GetMapping("page") |
| | | @Operation(summary = "分页") |
| | | @PreAuthorize("@ss.hasPermission('ml:model:query')") |
| | | public CommonResult<PageData<MlModelDTO>> page(@RequestParam Map<String, Object> params) { |
| | | PageData<MlModelDTO> page = mlModelService.page(params); |
| | | return success(page); |
| | | } |
| | | |
| | | @GetMapping("{id}") |
| | | @Operation(summary = "信息") |
| | | @PreAuthorize("@ss.hasPermission('ml:model:query')") |
| | | public CommonResult<MlModelDTO> get(@PathVariable("id") String id){ |
| | | MlModelDTO data = mlModelService.get(id); |
| | | |
| | | return success(data); |
| | | } |
| | | |
| | | @PreAuthorize("@ss.hasPermission('ml:model:query')") |
| | | @GetMapping("list") |
| | | public CommonResult<List<MlModelDTO>> list(@RequestParam Map<String, Object> params) { |
| | | List<MlModelDTO> list = mlModelService.list(params); |
| | | |
| | | return success(list); |
| | | } |
| | | |
| | | @PostMapping |
| | | @Operation(summary = "保存") |
| | | @PreAuthorize("@ss.hasPermission('ml:model:create')") |
| | | public CommonResult save(@RequestBody MlModelDTO dto){ |
| | | mlModelService.save(dto); |
| | | |
| | | return success(); |
| | | } |
| | | |
| | | @PutMapping |
| | | @Operation(summary = "修改") |
| | | @PreAuthorize("@ss.hasPermission('ml:model:update')") |
| | | public CommonResult update(@RequestBody MlModelDTO dto){ |
| | | mlModelService.update(dto); |
| | | |
| | | return success(); |
| | | } |
| | | |
| | | @DeleteMapping |
| | | @Operation(summary = "删除") |
| | | @PreAuthorize("@ss.hasPermission('ml:model:delete')") |
| | | public CommonResult delete(String id){ |
| | | |
| | | mlModelService.delete(id); |
| | | |
| | | return success(); |
| | | } |
| | | |
| | | @PostMapping("/upload") |
| | | @Operation(summary = "算法封装jar文件上传") |
| | | public CommonResult<MatlabJarFileInfoDTO> upload(@RequestParam("file") MultipartFile file){ |
| | | MatlabJarFileInfoDTO result = null; |
| | | try { |
| | | result = mlModelService.uploadJarFile(file); |
| | | } catch (IllegalityJarException e) { |
| | | return CommonResult.error(GlobalErrorCodeConstants.BAD_REQUEST.getCode(),"非法jar包"); |
| | | } |
| | | return success(result); |
| | | } |
| | | |
| | | @PostMapping("/test") |
| | | @Operation(summary = "Matlab测试运行") |
| | | public CommonResult<String> test(@RequestBody MatlabRunDTO dto) { |
| | | return mlModelService.test(dto); |
| | | } |
| | | |
| | | @PostMapping("/importData") |
| | | @Operation(summary = "导入参数") |
| | | public CommonResult<List<HashMap<String,Object>>> importData(@RequestParam("file") MultipartFile file) throws Exception { |
| | | List<HashMap<String,Object>> result = mlModelService.importData(file); |
| | | return success(result); |
| | | } |
| | | |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.matlab.controller.admin; |
| | | |
| | | import com.iailab.framework.common.page.PageData; |
| | | import com.iailab.framework.common.pojo.CommonResult; |
| | | import com.iailab.module.model.matlab.dto.MlModelDTO; |
| | | import com.iailab.module.model.matlab.dto.MlProjectDTO; |
| | | import com.iailab.module.model.matlab.service.MlProjectService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | import static com.iailab.framework.common.pojo.CommonResult.success; |
| | | |
| | | |
| | | /** |
| | | * @description: |
| | | * @author: dzd |
| | | * @date: 2024/8/22 14:40 |
| | | **/ |
| | | @RestController |
| | | @RequestMapping("/model/matlab/project") |
| | | public class MlProjectController { |
| | | @Autowired |
| | | private MlProjectService mlProjectService; |
| | | |
| | | @PreAuthorize("@ss.hasPermission('matlab:project:query')") |
| | | @GetMapping("page") |
| | | public CommonResult<PageData<MlProjectDTO>> page(@RequestParam Map<String, Object> params){ |
| | | PageData<MlProjectDTO> page = mlProjectService.page(params); |
| | | |
| | | return success(page); |
| | | } |
| | | |
| | | @PreAuthorize("@ss.hasPermission('matlab:project:query')") |
| | | @GetMapping("list") |
| | | public CommonResult<List<MlProjectDTO>> list() { |
| | | List<MlProjectDTO> list = mlProjectService.list(new HashMap<>()); |
| | | |
| | | return success(list); |
| | | } |
| | | |
| | | @PreAuthorize("@ss.hasPermission('matlab:project:query')") |
| | | @GetMapping("{id}") |
| | | public CommonResult<MlProjectDTO> get(@PathVariable("id") String id){ |
| | | MlProjectDTO data = mlProjectService.get(id); |
| | | |
| | | return success(data); |
| | | } |
| | | |
| | | @PreAuthorize("@ss.hasPermission('matlab:project:create')") |
| | | @PostMapping |
| | | public CommonResult<Boolean> save(@RequestBody MlProjectDTO dto){ |
| | | mlProjectService.save(dto); |
| | | |
| | | return CommonResult.success(true); |
| | | } |
| | | |
| | | @PreAuthorize("@ss.hasPermission('matlab:project:update')") |
| | | @PutMapping |
| | | public CommonResult<Boolean> update(@RequestBody MlProjectDTO dto){ |
| | | dto.setUpdateTime(new Date()); |
| | | mlProjectService.update(dto); |
| | | |
| | | return CommonResult.success(true); |
| | | } |
| | | |
| | | @PreAuthorize("@ss.hasPermission('matlab:project:delete')") |
| | | @DeleteMapping |
| | | public CommonResult<Boolean> delete(String id){ |
| | | |
| | | mlProjectService.delete(id); |
| | | |
| | | return CommonResult.success(true); |
| | | } |
| | | |
| | | @GetMapping("getProjectModel") |
| | | public CommonResult<PageData<MlModelDTO>> getProjectModel(@RequestParam Map<String, Object> params){ |
| | | PageData<MlModelDTO> page = mlProjectService.getProjectModel(params); |
| | | |
| | | return CommonResult.success(page); |
| | | } |
| | | |
| | | @PostMapping("/publish") |
| | | public CommonResult<String> publish(@RequestBody Map<String, Object> params) { |
| | | return mlProjectService.publish(params); |
| | | } |
| | | |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.matlab.controller; |
对比新文件 |
| | |
| | | package com.iailab.module.model.matlab.dao; |
| | | |
| | | import com.iailab.framework.common.dao.BaseDao; |
| | | import com.iailab.framework.tenant.core.db.dynamic.TenantDS; |
| | | import com.iailab.module.model.matlab.dto.MlModelDTO; |
| | | import com.iailab.module.model.matlab.entity.MlModelEntity; |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | import org.apache.ibatis.annotations.Param; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * |
| | | * |
| | | * @author Dzd |
| | | * @since 1.0.0 2025-02-08 |
| | | */ |
| | | @TenantDS |
| | | @Mapper |
| | | public interface MlModelDao extends BaseDao<MlModelEntity> { |
| | | |
| | | List<MlModelDTO> list(Map<String, Object> params); |
| | | |
| | | MlModelDTO get(String id); |
| | | |
| | | int getProjectModelCount(String projectId); |
| | | |
| | | List<MlModelDTO> getProjectModel(@Param("params") Map<String, Object> params); |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.matlab.dao; |
| | | |
| | | import com.iailab.framework.common.dao.BaseDao; |
| | | import com.iailab.framework.tenant.core.db.dynamic.TenantDS; |
| | | import com.iailab.module.model.matlab.entity.MlModelMethodEntity; |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | |
| | | /** |
| | | * |
| | | * |
| | | * @author Dzd |
| | | * @since 1.0.0 2025-02-08 |
| | | */ |
| | | @TenantDS |
| | | @Mapper |
| | | public interface MlModelMethodDao extends BaseDao<MlModelMethodEntity> { |
| | | |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.matlab.dao; |
| | | |
| | | import com.iailab.framework.common.dao.BaseDao; |
| | | import com.iailab.framework.tenant.core.db.dynamic.TenantDS; |
| | | import com.iailab.module.model.matlab.entity.MlModelMethodSettingEntity; |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | |
| | | /** |
| | | * |
| | | * |
| | | * @author Dzd |
| | | * @since 1.0.0 2025-02-08 |
| | | */ |
| | | @TenantDS |
| | | @Mapper |
| | | public interface MlModelMethodSettingDao extends BaseDao<MlModelMethodSettingEntity> { |
| | | |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.matlab.dao; |
| | | |
| | | import com.iailab.framework.common.dao.BaseDao; |
| | | import com.iailab.framework.tenant.core.db.dynamic.TenantDS; |
| | | import com.iailab.module.model.matlab.entity.MlProjectEntity; |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | |
| | | /** |
| | | * @description: |
| | | * @author: dzd |
| | | * @date: 2025/2/25 14:11 |
| | | **/ |
| | | @TenantDS |
| | | @Mapper |
| | | public interface MlProjectDao extends BaseDao<MlProjectEntity> { |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.matlab.dao; |
| | | |
| | | import com.iailab.framework.common.dao.BaseDao; |
| | | import com.iailab.framework.tenant.core.db.dynamic.TenantDS; |
| | | import com.iailab.module.model.matlab.dto.MlModelDTO; |
| | | import com.iailab.module.model.matlab.entity.MlProjectModelEntity; |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | import org.apache.ibatis.annotations.Param; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @description: |
| | | * @author: dzd |
| | | * @date: 2025/2/25 14:10 |
| | | **/ |
| | | @TenantDS |
| | | @Mapper |
| | | public interface MlProjectModelDao extends BaseDao<MlProjectModelEntity> { |
| | | |
| | | List<MlModelDTO> getProjectModel(@Param("params") Map<String, Object> params); |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.matlab.dto; |
| | | |
| | | import lombok.Data; |
| | | |
| | | import java.util.List; |
| | | |
| | | @Data |
| | | public class MatlabJarFileClassInfoDTO { |
| | | |
| | | private String className; |
| | | |
| | | private List<MatlabJarFileMethodInfoDTO> methodInfos; |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.matlab.dto; |
| | | |
| | | import lombok.Data; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | |
| | | @Data |
| | | public class MatlabJarFileInfoDTO { |
| | | |
| | | private String fileName; |
| | | |
| | | private String filePath; |
| | | |
| | | private List<MatlabJarFileClassInfoDTO> classInfos; |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.matlab.dto; |
| | | |
| | | import lombok.Data; |
| | | |
| | | @Data |
| | | public class MatlabJarFileMethodInfoDTO { |
| | | |
| | | private String methodName; |
| | | |
| | | private Integer dataLength; |
| | | |
| | | private Integer outLength; |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.matlab.dto; |
| | | |
| | | import lombok.Data; |
| | | |
| | | import java.io.Serializable; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @description: |
| | | * @author: dzd |
| | | * @date: 2025/2/24 15:59 |
| | | **/ |
| | | @Data |
| | | public class MatlabRunDTO implements Serializable { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | private String modelFileName; |
| | | |
| | | private String className; |
| | | |
| | | private String methodName; |
| | | |
| | | private Integer outLength; |
| | | |
| | | private List<MlModelMethodSettingDTO> modelSettings; |
| | | |
| | | private List<String> uuids; |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.matlab.dto; |
| | | |
| | | import lombok.Data; |
| | | |
| | | import java.io.Serializable; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | |
| | | /** |
| | | * |
| | | * |
| | | * @author Dzd |
| | | * @since 1.0.0 2025-02-08 |
| | | */ |
| | | @Data |
| | | public class MlModelDTO implements Serializable { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | private String id; |
| | | |
| | | private String modelName; |
| | | |
| | | private String modelFileName; |
| | | |
| | | private String modelFilePath; |
| | | |
| | | private String modelType; |
| | | |
| | | private String matlabPlatform; |
| | | |
| | | private String matlabVersion; |
| | | |
| | | private String remark; |
| | | |
| | | private Long updater; |
| | | |
| | | private Date updateDate; |
| | | |
| | | private Long creator; |
| | | |
| | | private Date createDate; |
| | | |
| | | private List<MlModelMethodDTO> modelMethods; |
| | | |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.matlab.dto; |
| | | |
| | | import lombok.Data; |
| | | |
| | | import java.io.Serializable; |
| | | import java.util.List; |
| | | |
| | | |
| | | /** |
| | | * |
| | | * |
| | | * @author Dzd |
| | | * @since 1.0.0 2025-02-08 |
| | | */ |
| | | @Data |
| | | public class MlModelMethodDTO implements Serializable { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | private String id; |
| | | |
| | | private String mlModelId; |
| | | |
| | | private String className; |
| | | |
| | | private String methodName; |
| | | |
| | | private Integer dataLength; |
| | | |
| | | private Integer outLength; |
| | | |
| | | private Integer sort; |
| | | |
| | | private List<MlModelMethodSettingDTO> methodSettings; |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.matlab.dto; |
| | | |
| | | import lombok.Data; |
| | | |
| | | import java.io.Serializable; |
| | | |
| | | |
| | | /** |
| | | * |
| | | * |
| | | * @author Dzd |
| | | * @since 1.0.0 2025-02-08 |
| | | */ |
| | | @Data |
| | | public class MlModelMethodSettingDTO implements Serializable { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | private String id; |
| | | |
| | | private String mlModelMethodId; |
| | | |
| | | private String name; |
| | | |
| | | private String settingKey; |
| | | |
| | | private String settingValue; |
| | | |
| | | private String valueType; |
| | | |
| | | private String sort; |
| | | |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.matlab.dto; |
| | | |
| | | import lombok.Data; |
| | | |
| | | import java.io.Serializable; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | |
| | | /** |
| | | * @description: 项目表 |
| | | * @author: dzd |
| | | * @date: 2024/8/22 14:41 |
| | | **/ |
| | | @Data |
| | | public class MlProjectDTO implements Serializable { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | private String id; |
| | | |
| | | private String projectName; |
| | | |
| | | private String projectCode; |
| | | |
| | | private Date createTime; |
| | | |
| | | private Date updateTime; |
| | | |
| | | private List<MlModelDTO> models; |
| | | |
| | | |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.matlab.dto; |
| | | |
| | | import lombok.Data; |
| | | |
| | | import java.io.Serializable; |
| | | |
| | | |
| | | /** |
| | | * @description: |
| | | * @author: dzd |
| | | * @date: 2025/2/25 14:39 |
| | | **/ |
| | | @Data |
| | | public class MlProjectModelDTO implements Serializable { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | private String id; |
| | | |
| | | private String projectId; |
| | | |
| | | private String modelId; |
| | | |
| | | |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.matlab.entity; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.FieldFill; |
| | | import com.baomidou.mybatisplus.annotation.TableField; |
| | | import com.baomidou.mybatisplus.annotation.TableName; |
| | | import lombok.Data; |
| | | |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * |
| | | * |
| | | * @author Dzd |
| | | * @since 1.0.0 2025-02-08 |
| | | */ |
| | | @Data |
| | | @TableName("t_ml_model") |
| | | public class MlModelEntity { |
| | | |
| | | /** |
| | | * |
| | | */ |
| | | private String id; |
| | | /** |
| | | * 模型名称 |
| | | */ |
| | | private String modelName; |
| | | /** |
| | | * 模型文件名 |
| | | */ |
| | | private String modelFileName; |
| | | /** |
| | | * 模型文件路径 |
| | | */ |
| | | private String modelFilePath; |
| | | /** |
| | | * 模型类型 |
| | | */ |
| | | private String modelType; |
| | | /** |
| | | * matlab平台 |
| | | */ |
| | | private String matlabPlatform; |
| | | /** |
| | | * matlab版本 |
| | | */ |
| | | private String matlabVersion; |
| | | /** |
| | | * 备注 |
| | | */ |
| | | private String remark; |
| | | /** |
| | | * 更新者 |
| | | */ |
| | | @TableField(fill = FieldFill.INSERT_UPDATE) |
| | | private Long updater; |
| | | /** |
| | | * 更新时间 |
| | | */ |
| | | @TableField(fill = FieldFill.INSERT_UPDATE) |
| | | private Date updateDate; |
| | | |
| | | /** |
| | | * 创建者 |
| | | */ |
| | | @TableField(fill = FieldFill.INSERT) |
| | | private Long creator; |
| | | /** |
| | | * 创建时间 |
| | | */ |
| | | @TableField(fill = FieldFill.INSERT) |
| | | private Date createDate; |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.matlab.entity; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.TableName; |
| | | import lombok.Data; |
| | | |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * |
| | | * |
| | | * @author Dzd |
| | | * @since 1.0.0 2025-02-08 |
| | | */ |
| | | @Data |
| | | @TableName("t_ml_model_method") |
| | | public class MlModelMethodEntity { |
| | | |
| | | /** |
| | | * |
| | | */ |
| | | private String id; |
| | | /** |
| | | * 模型id |
| | | */ |
| | | private String mlModelId; |
| | | /** |
| | | * 全类名 |
| | | */ |
| | | private String className; |
| | | /** |
| | | * 方法名 |
| | | */ |
| | | private String methodName; |
| | | /** |
| | | * 数据长度 |
| | | */ |
| | | private Integer dataLength; |
| | | /** |
| | | * 输出长度 |
| | | */ |
| | | private Integer outLength; |
| | | /** |
| | | * 排序 |
| | | */ |
| | | private Integer sort; |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.matlab.entity; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.TableName; |
| | | import lombok.Data; |
| | | |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * |
| | | * |
| | | * @author Dzd |
| | | * @since 1.0.0 2025-02-08 |
| | | */ |
| | | @Data |
| | | @TableName("t_ml_model_method_setting") |
| | | public class MlModelMethodSettingEntity { |
| | | |
| | | /** |
| | | * id |
| | | */ |
| | | private String id; |
| | | /** |
| | | * 模型方法id |
| | | */ |
| | | private String mlModelMethodId; |
| | | /** |
| | | * 参数名称 |
| | | */ |
| | | private String name; |
| | | /** |
| | | * 参数key |
| | | */ |
| | | private String settingKey; |
| | | /** |
| | | * 参数值 |
| | | */ |
| | | private String settingValue; |
| | | /** |
| | | * 参数类型 |
| | | */ |
| | | private String valueType; |
| | | /** |
| | | * 排序 |
| | | */ |
| | | private Integer sort; |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.matlab.entity; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.TableName; |
| | | import lombok.Data; |
| | | |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * @description: |
| | | * @author: dzd |
| | | * @date: 2025/2/25 14:10 |
| | | **/ |
| | | @Data |
| | | @TableName("t_ml_project") |
| | | public class MlProjectEntity { |
| | | |
| | | /** |
| | | * id |
| | | */ |
| | | private String id; |
| | | /** |
| | | * 项目名称 |
| | | */ |
| | | private String projectName; |
| | | /** |
| | | * 项目编码 |
| | | */ |
| | | private String projectCode; |
| | | /** |
| | | * 创建时间 |
| | | */ |
| | | private Date createTime; |
| | | /** |
| | | * 修改时间 |
| | | */ |
| | | private Date updateTime; |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.matlab.entity; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.TableName; |
| | | import lombok.Data; |
| | | |
| | | /** |
| | | * @description: |
| | | * @author: dzd |
| | | * @date: 2025/2/25 14:16 |
| | | **/ |
| | | @Data |
| | | @TableName("t_ml_project_model") |
| | | public class MlProjectModelEntity { |
| | | |
| | | /** |
| | | * id |
| | | */ |
| | | private String id; |
| | | /** |
| | | * 项目id |
| | | */ |
| | | private String projectId; |
| | | /** |
| | | * 模型id |
| | | */ |
| | | private String modelId; |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.matlab.service; |
| | | |
| | | import com.iailab.framework.common.service.BaseService; |
| | | import com.iailab.module.model.matlab.dto.MlModelMethodDTO; |
| | | import com.iailab.module.model.matlab.entity.MlModelMethodEntity; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * |
| | | * |
| | | * @author Dzd |
| | | * @since 1.0.0 2025-02-08 |
| | | */ |
| | | public interface MlModelMethodService extends BaseService<MlModelMethodEntity> { |
| | | |
| | | void insertList(List<MlModelMethodDTO> modelMethods, String id); |
| | | |
| | | void deleteModelMethod(String modelId); |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.matlab.service; |
| | | |
| | | |
| | | import com.iailab.framework.common.service.BaseService; |
| | | import com.iailab.module.model.matlab.entity.MlModelMethodSettingEntity; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * |
| | | * |
| | | * @author Dzd |
| | | * @since 1.0.0 2025-02-08 |
| | | */ |
| | | public interface MlModelMethodSettingService extends BaseService<MlModelMethodSettingEntity> { |
| | | |
| | | void insertList(List<MlModelMethodSettingEntity> settingEntities); |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.matlab.service; |
| | | |
| | | |
| | | import com.iailab.framework.common.page.PageData; |
| | | import com.iailab.framework.common.pojo.CommonResult; |
| | | import com.iailab.framework.common.service.BaseService; |
| | | import com.iailab.framework.common.service.CrudService; |
| | | import com.iailab.module.model.matlab.common.exceptions.IllegalityJarException; |
| | | import com.iailab.module.model.matlab.dto.MatlabJarFileInfoDTO; |
| | | import com.iailab.module.model.matlab.dto.MatlabRunDTO; |
| | | import com.iailab.module.model.matlab.dto.MlModelDTO; |
| | | import com.iailab.module.model.matlab.entity.MlModelEntity; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * |
| | | * |
| | | * @author Dzd |
| | | * @since 1.0.0 2025-02-08 |
| | | */ |
| | | public interface MlModelService extends BaseService<MlModelEntity> { |
| | | PageData<MlModelDTO> page(Map<String, Object> params); |
| | | |
| | | List<MlModelDTO> list(Map<String, Object> params); |
| | | |
| | | MlModelDTO get(String id); |
| | | |
| | | void save(MlModelDTO dto); |
| | | |
| | | void update(MlModelDTO dto); |
| | | |
| | | void delete(String id); |
| | | |
| | | MatlabJarFileInfoDTO uploadJarFile(MultipartFile file) throws IllegalityJarException; |
| | | |
| | | CommonResult<String> test(MatlabRunDTO dto); |
| | | |
| | | List<HashMap<String, Object>> importData(MultipartFile file) throws IOException; |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.matlab.service; |
| | | |
| | | import com.iailab.framework.common.service.BaseService; |
| | | import com.iailab.module.model.matlab.dto.MlModelDTO; |
| | | import com.iailab.module.model.matlab.dto.MlProjectModelDTO; |
| | | import com.iailab.module.model.matlab.entity.MlProjectModelEntity; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @description: |
| | | * @author: dzd |
| | | * @date: 2024/8/22 14:41 |
| | | **/ |
| | | public interface MlProjectModelService extends BaseService<MlProjectModelEntity> { |
| | | |
| | | List<MlProjectModelDTO> list(Map<String, Object> params); |
| | | |
| | | void deleteByMap(Map<String,Object> map); |
| | | |
| | | void create(List<MlModelDTO> models, String projectId); |
| | | |
| | | List<MlModelDTO> getProjectModel(Map<String, Object> params); |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.matlab.service; |
| | | |
| | | import com.iailab.framework.common.page.PageData; |
| | | import com.iailab.framework.common.pojo.CommonResult; |
| | | import com.iailab.framework.common.service.BaseService; |
| | | import com.iailab.module.model.matlab.dto.MlModelDTO; |
| | | import com.iailab.module.model.matlab.dto.MlProjectDTO; |
| | | import com.iailab.module.model.matlab.entity.MlProjectEntity; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @description: |
| | | * @author: dzd |
| | | * @date: 2024/8/22 14:41 |
| | | **/ |
| | | public interface MlProjectService extends BaseService<MlProjectEntity> { |
| | | PageData<MlProjectDTO> page(Map<String, Object> params); |
| | | |
| | | List<MlProjectDTO> list(Map<String, Object> params); |
| | | |
| | | MlProjectDTO get(String id); |
| | | |
| | | void save(MlProjectDTO dto); |
| | | |
| | | void update(MlProjectDTO dto); |
| | | |
| | | void delete(String id); |
| | | |
| | | PageData<MlModelDTO> getProjectModel(Map<String, Object> params); |
| | | |
| | | CommonResult<String> publish(Map<String, Object> params); |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.matlab.service.impl; |
| | | |
| | | import com.iailab.framework.common.service.impl.BaseServiceImpl; |
| | | import com.iailab.framework.common.util.object.ConvertUtils; |
| | | import com.iailab.module.model.matlab.dao.MlModelMethodDao; |
| | | import com.iailab.module.model.matlab.dto.MlModelMethodDTO; |
| | | import com.iailab.module.model.matlab.entity.MlModelMethodEntity; |
| | | import com.iailab.module.model.matlab.entity.MlModelMethodSettingEntity; |
| | | import com.iailab.module.model.matlab.service.MlModelMethodService; |
| | | import com.iailab.module.model.matlab.service.MlModelMethodSettingService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * |
| | | * |
| | | * @author Dzd |
| | | * @since 1.0.0 2025-02-08 |
| | | */ |
| | | @Service |
| | | public class MlModelMethodServiceImpl extends BaseServiceImpl<MlModelMethodDao, MlModelMethodEntity> implements MlModelMethodService { |
| | | |
| | | @Autowired |
| | | private MlModelMethodSettingService mlModelMethodSettingService; |
| | | @Override |
| | | public void insertList(List<MlModelMethodDTO> list, String modelId) { |
| | | List<MlModelMethodEntity> methodEntities = new ArrayList<>(); |
| | | List<MlModelMethodSettingEntity> settingEntities = new ArrayList<>(); |
| | | for (int i = 0; i < list.size(); i++) { |
| | | MlModelMethodEntity entity = ConvertUtils.sourceToTarget(list.get(i), MlModelMethodEntity.class); |
| | | String methodId = UUID.randomUUID().toString(); |
| | | entity.setId(methodId); |
| | | entity.setMlModelId(modelId); |
| | | entity.setSort(i); |
| | | methodEntities.add(entity); |
| | | if (!CollectionUtils.isEmpty(list.get(i).getMethodSettings())) { |
| | | List<MlModelMethodSettingEntity> settingEntityList = ConvertUtils.sourceToTarget(list.get(i).getMethodSettings(), MlModelMethodSettingEntity.class); |
| | | for (int j = 0; j < settingEntityList.size(); j++) { |
| | | MlModelMethodSettingEntity mlModelMethodSettingEntity = settingEntityList.get(j); |
| | | mlModelMethodSettingEntity.setId(UUID.randomUUID().toString()); |
| | | mlModelMethodSettingEntity.setMlModelMethodId(methodId); |
| | | mlModelMethodSettingEntity.setSort(j); |
| | | settingEntities.add(mlModelMethodSettingEntity); |
| | | } |
| | | } |
| | | } |
| | | baseDao.insert(methodEntities); |
| | | mlModelMethodSettingService.insertList(settingEntities); |
| | | } |
| | | |
| | | @Override |
| | | public void deleteModelMethod(String modelId) { |
| | | Map<String,Object> map = new HashMap<>(); |
| | | map.put("ml_model_id", modelId); |
| | | baseDao.deleteByMap(map); |
| | | } |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.matlab.service.impl; |
| | | |
| | | import com.iailab.framework.common.service.impl.BaseServiceImpl; |
| | | import com.iailab.module.model.matlab.dao.MlModelMethodSettingDao; |
| | | import com.iailab.module.model.matlab.entity.MlModelMethodSettingEntity; |
| | | import com.iailab.module.model.matlab.service.MlModelMethodSettingService; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * |
| | | * |
| | | * @author Dzd |
| | | * @since 1.0.0 2025-02-08 |
| | | */ |
| | | @Service |
| | | public class MlModelMethodSettingServiceImpl extends BaseServiceImpl<MlModelMethodSettingDao, MlModelMethodSettingEntity> implements MlModelMethodSettingService { |
| | | |
| | | |
| | | @Override |
| | | public void insertList(List<MlModelMethodSettingEntity> settingEntities) { |
| | | baseDao.insert(settingEntities); |
| | | } |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.matlab.service.impl; |
| | | |
| | | |
| | | import cn.hutool.cache.CacheUtil; |
| | | import cn.hutool.cache.impl.FIFOCache; |
| | | import cn.hutool.core.io.FileUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.baomidou.dynamic.datasource.annotation.DSTransactional; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.iailab.framework.common.exception.enums.GlobalErrorCodeConstants; |
| | | import com.iailab.framework.common.page.PageData; |
| | | import com.iailab.framework.common.pojo.CommonResult; |
| | | import com.iailab.framework.common.service.impl.BaseServiceImpl; |
| | | import com.iailab.framework.common.util.object.ConvertUtils; |
| | | import com.iailab.framework.security.core.util.SecurityFrameworkUtils; |
| | | import com.iailab.framework.tenant.core.context.TenantContextHolder; |
| | | import com.iailab.module.model.common.utils.DateUtils; |
| | | import com.iailab.module.model.matlab.common.exceptions.IllegalityJarException; |
| | | import com.iailab.module.model.matlab.common.utils.MatlabUtils; |
| | | import com.iailab.module.model.matlab.dao.MlModelDao; |
| | | import com.iailab.module.model.matlab.dto.MatlabJarFileInfoDTO; |
| | | import com.iailab.module.model.matlab.dto.MatlabRunDTO; |
| | | import com.iailab.module.model.matlab.dto.MlModelDTO; |
| | | import com.iailab.module.model.matlab.entity.MlModelEntity; |
| | | import com.iailab.module.model.matlab.service.MlModelMethodService; |
| | | import com.iailab.module.model.matlab.service.MlModelService; |
| | | import com.iailab.module.model.mpk.common.MdkConstant; |
| | | import com.iailab.module.model.mpk.common.utils.Readtxt; |
| | | import com.mathworks.toolbox.javabuilder.MWStructArray; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.net.URLClassLoader; |
| | | import java.util.*; |
| | | |
| | | import static com.iailab.framework.common.pojo.CommonResult.error; |
| | | import static com.iailab.framework.common.pojo.CommonResult.success; |
| | | |
| | | /** |
| | | * |
| | | * |
| | | * @author Dzd |
| | | * @since 1.0.0 2025-02-08 |
| | | */ |
| | | @Slf4j |
| | | @Service |
| | | public class MlModelServiceImpl extends BaseServiceImpl<MlModelDao, MlModelEntity> implements MlModelService { |
| | | |
| | | @Value("${mablab.bak-file-path}") |
| | | private String mablabBakFilePath; |
| | | |
| | | @Autowired |
| | | private MlModelMethodService mlModelMethodService; |
| | | |
| | | // 先进先出缓存 临时保存导入的数据 |
| | | private static FIFOCache<String, String> cache = CacheUtil.newFIFOCache(100); |
| | | |
| | | @Override |
| | | public PageData<MlModelDTO> page(Map<String, Object> params) { |
| | | IPage<MlModelEntity> page = baseDao.selectPage( |
| | | getPage(params, "create_date", false), |
| | | getWrapper(params) |
| | | ); |
| | | |
| | | return getPageData(page, MlModelDTO.class); |
| | | } |
| | | |
| | | @Override |
| | | public List<MlModelDTO> list(Map<String, Object> params) { |
| | | List<MlModelDTO> list = baseDao.list(params); |
| | | |
| | | return list; |
| | | } |
| | | |
| | | private QueryWrapper<MlModelEntity> getWrapper(Map<String, Object> params) { |
| | | String modelName = (String) params.get("modelName"); |
| | | String modelFileName = (String) params.get("modelFileName"); |
| | | |
| | | QueryWrapper<MlModelEntity> wrapper = new QueryWrapper<>(); |
| | | wrapper.like(StringUtils.isNotBlank(modelName), "model_name", modelName) |
| | | .like(StringUtils.isNotBlank(modelFileName), "model_file_name", modelFileName); |
| | | return wrapper; |
| | | } |
| | | |
| | | @Override |
| | | public MlModelDTO get(String id) { |
| | | MlModelDTO entity = baseDao.get(id); |
| | | |
| | | return entity; |
| | | } |
| | | |
| | | @Override |
| | | @DSTransactional(rollbackFor = Exception.class) |
| | | public void save(MlModelDTO dto) { |
| | | MlModelEntity entity = ConvertUtils.sourceToTarget(dto, MlModelEntity.class); |
| | | entity.setId(UUID.randomUUID().toString()); |
| | | entity.setModelFilePath(dto.getModelFilePath().trim()); |
| | | entity.setModelFileName(dto.getModelFileName().trim()); |
| | | entity.setCreator(SecurityFrameworkUtils.getLoginUserId()); |
| | | entity.setCreateDate(new Date()); |
| | | insert(entity); |
| | | |
| | | mlModelMethodService.insertList(dto.getModelMethods(), entity.getId()); |
| | | |
| | | saveJarFile(dto.getModelFilePath(),dto.getModelFileName()); |
| | | } |
| | | |
| | | @Override |
| | | @DSTransactional(rollbackFor = Exception.class) |
| | | public void update(MlModelDTO dto) { |
| | | MlModelEntity entity = ConvertUtils.sourceToTarget(dto, MlModelEntity.class); |
| | | entity.setUpdater(SecurityFrameworkUtils.getLoginUserId()); |
| | | entity.setUpdateDate(new Date()); |
| | | updateById(entity); |
| | | mlModelMethodService.deleteModelMethod(entity.getId()); |
| | | mlModelMethodService.insertList(dto.getModelMethods(), entity.getId()); |
| | | |
| | | saveJarFile(dto.getModelFilePath(),dto.getModelFileName()); |
| | | } |
| | | |
| | | /** |
| | | * @description: 保存最新jar文件,用于测试运行 |
| | | * @author: dzd |
| | | * @date: 2025/2/24 16:25 |
| | | **/ |
| | | private void saveJarFile(String modelFilePath,String modelFileName) { |
| | | String matlabTenantBakFilePath = getMatlabTenantBakFilePath(); |
| | | |
| | | String jarBakPath = matlabTenantBakFilePath + File.separator + MdkConstant.JAR + File.separator + modelFileName + ".jar"; |
| | | FileUtil.copy(modelFilePath, jarBakPath, true); |
| | | } |
| | | |
| | | @Override |
| | | @DSTransactional(rollbackFor = Exception.class) |
| | | public void delete(String id) { |
| | | |
| | | //删除源文件 |
| | | MlModelEntity MlModelEntity = selectById(id); |
| | | if (StringUtils.isNoneBlank(MlModelEntity.getModelFilePath())) { |
| | | File mpkFile = new File(MlModelEntity.getModelFilePath()); |
| | | if (mpkFile.exists()) { |
| | | mpkFile.delete(); |
| | | log.info("删除源文件备份文件:" + MlModelEntity.getModelFilePath()); |
| | | } |
| | | } |
| | | //删除 会级联删除掉关联表 |
| | | deleteById(id); |
| | | } |
| | | |
| | | @Override |
| | | public MatlabJarFileInfoDTO uploadJarFile(MultipartFile file) throws IllegalityJarException { |
| | | String matlabTenantBakFilePath = getMatlabTenantBakFilePath(); |
| | | File bakDir = new File(matlabTenantBakFilePath); |
| | | |
| | | String jarName = null; |
| | | File jarBakFile = null; |
| | | try { |
| | | String fileName = file.getOriginalFilename(); |
| | | jarName = fileName.substring(0, fileName.lastIndexOf(".")); |
| | | String pyName_time = jarName + "_" + DateUtils.format(new Date(),DateUtils.DATE_TIME_STRING); |
| | | jarBakFile = new File(bakDir.getAbsolutePath() + File.separator + pyName_time + ".jar"); |
| | | file.transferTo(jarBakFile); |
| | | } catch (IOException e) { |
| | | throw new RuntimeException("保存算法封装jar文件失败!"); |
| | | } |
| | | |
| | | //解析jar info |
| | | MatlabJarFileInfoDTO result = new MatlabJarFileInfoDTO(); |
| | | result.setFilePath(jarBakFile.getAbsolutePath()); |
| | | result.setFileName(jarName); |
| | | result.setClassInfos(MatlabUtils.parseJarInfo(jarBakFile.getAbsolutePath(),jarName)); |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | public CommonResult<String> test(MatlabRunDTO dto) { |
| | | String matlabTenantBakFilePath = getMatlabTenantBakFilePath(); |
| | | |
| | | Class<?> clazz; |
| | | URLClassLoader classLoader; |
| | | try { |
| | | File jarFile = new File(matlabTenantBakFilePath + File.separator + MdkConstant.JAR + File.separator + dto.getModelFileName() + ".jar"); |
| | | if (!jarFile.exists()) { |
| | | throw new RuntimeException("jar包不存在,请检查。jarPath:" + jarFile.getAbsolutePath()); |
| | | } |
| | | // 加载jar包 |
| | | classLoader = MatlabUtils.loadJar(null,jarFile.getAbsolutePath()); |
| | | // 实现类 |
| | | clazz = classLoader.loadClass(dto.getClassName()); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | throw new RuntimeException("加载运行环境失败。"); |
| | | } |
| | | |
| | | try { |
| | | List<String> uuids = dto.getUuids(); |
| | | |
| | | Object[] paramsValueArray = new Object[uuids.size() + 1]; |
| | | |
| | | try { |
| | | for (int i = 0; i < uuids.size(); i++) { |
| | | String uuid = uuids.get(i); |
| | | if (!cache.containsKey(uuid)) { |
| | | return error(GlobalErrorCodeConstants.BAD_REQUEST.getCode(),"请重新导入模型参数"); |
| | | } |
| | | JSONArray jsonArray = JSON.parseArray(cache.get(uuid)); |
| | | double[][] data = new double[jsonArray.size()][jsonArray.getJSONArray(0).size()]; |
| | | for (int j = 0; j < jsonArray.size(); j++) { |
| | | for (int k = 0; k < jsonArray.getJSONArray(j).size(); k++) { |
| | | data[j][k] = jsonArray.getJSONArray(j).getDoubleValue(k); |
| | | } |
| | | } |
| | | paramsValueArray[i] = data; |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return error(GlobalErrorCodeConstants.BAD_REQUEST.getCode(),"模型参数错误,请检查!"); |
| | | } |
| | | |
| | | MWStructArray mwStructArraySetting; |
| | | try { |
| | | |
| | | HashMap<String, Object> settings = MatlabUtils.handleModelSettings(dto.getModelSettings()); |
| | | mwStructArraySetting = MatlabUtils.convertMapToStruct(settings); |
| | | paramsValueArray[uuids.size()] = mwStructArraySetting; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return error(GlobalErrorCodeConstants.BAD_REQUEST.getCode(),"模型设置错误,请检查!"); |
| | | } |
| | | |
| | | Class<?>[] paramsArray = new Class[2]; |
| | | paramsArray[0] = int.class; |
| | | paramsArray[1] = Object[].class; |
| | | Object[] objects = (Object[]) clazz.getDeclaredMethod(dto.getMethodName(), paramsArray).invoke(clazz.newInstance(), new Object[]{dto.getOutLength(), paramsValueArray}); |
| | | mwStructArraySetting.dispose(); |
| | | Map<String, Object> result = MatlabUtils.convertStructToMap((MWStructArray) objects[0]); |
| | | return success(JSON.toJSONString(result)); |
| | | } catch (Exception ex) { |
| | | ex.printStackTrace(); |
| | | return error(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR.getCode(),"运行异常"); |
| | | } finally { |
| | | if (classLoader != null) { |
| | | MatlabUtils.unloadJar(classLoader); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public List<HashMap<String, Object>> importData(MultipartFile file) throws IOException { |
| | | List<double[][]> datas = Readtxt.readMethodExcel(file); |
| | | List<HashMap<String,Object>> result = new ArrayList<>(); |
| | | if (!CollectionUtils.isEmpty(datas)) { |
| | | for (double[][] data : datas) { |
| | | if (data.length > 0) { |
| | | HashMap<String,Object> map = new HashMap<>(); |
| | | String uuid = UUID.randomUUID().toString(); |
| | | map.put("uuid",uuid); |
| | | map.put("data", JSON.toJSONString(data)); |
| | | cache.put(uuid,JSON.toJSONString(data)); |
| | | result.add(map); |
| | | } |
| | | } |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | private String getMatlabTenantBakFilePath() { |
| | | Long tenantId = TenantContextHolder.getTenantId(); |
| | | // 备份文件夹 租户隔离 |
| | | String matlabTenantBakFilePath = mablabBakFilePath + File.separator + tenantId; |
| | | File bakDir = new File(matlabTenantBakFilePath); |
| | | if (!bakDir.exists()) { |
| | | bakDir.mkdirs(); |
| | | } |
| | | return matlabTenantBakFilePath; |
| | | } |
| | | |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.matlab.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.iailab.framework.common.service.impl.BaseServiceImpl; |
| | | import com.iailab.framework.common.util.object.ConvertUtils; |
| | | import com.iailab.module.model.matlab.dao.MlProjectModelDao; |
| | | import com.iailab.module.model.matlab.dto.MlModelDTO; |
| | | import com.iailab.module.model.matlab.dto.MlProjectModelDTO; |
| | | import com.iailab.module.model.matlab.entity.MlProjectModelEntity; |
| | | import com.iailab.module.model.matlab.service.MlProjectModelService; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.UUID; |
| | | |
| | | /** |
| | | * @description: |
| | | * @author: dzd |
| | | * @date: 2024/8/22 14:41 |
| | | **/ |
| | | @Service |
| | | public class MlProjectModelServiceImpl extends BaseServiceImpl<MlProjectModelDao, MlProjectModelEntity> implements MlProjectModelService { |
| | | @Override |
| | | public List<MlProjectModelDTO> list(Map<String, Object> params) { |
| | | List<MlProjectModelEntity> entityList = baseDao.selectList(getWrapper(params)); |
| | | |
| | | return ConvertUtils.sourceToTarget(entityList, MlProjectModelDTO.class); |
| | | } |
| | | |
| | | @Override |
| | | public void deleteByMap(Map<String,Object> map) { |
| | | baseDao.delete(getWrapper(map)); |
| | | } |
| | | |
| | | @Override |
| | | public void create(List<MlModelDTO> models, String projectId) { |
| | | List<MlProjectModelEntity> list = new ArrayList<>(models.size()); |
| | | for (MlModelDTO model : models) { |
| | | MlProjectModelEntity projectModel = new MlProjectModelEntity(); |
| | | projectModel.setId(UUID.randomUUID().toString()); |
| | | projectModel.setProjectId(projectId); |
| | | projectModel.setModelId(model.getId()); |
| | | list.add(projectModel); |
| | | } |
| | | baseDao.insert(list); |
| | | } |
| | | |
| | | @Override |
| | | public List<MlModelDTO> getProjectModel(Map<String, Object> params) { |
| | | return baseDao.getProjectModel(params); |
| | | } |
| | | |
| | | public QueryWrapper<MlProjectModelEntity> getWrapper(Map<String, Object> params){ |
| | | String id = (String)params.get("id"); |
| | | String projectId = (String)params.get("projectId"); |
| | | String modelId = (String)params.get("modelId"); |
| | | |
| | | QueryWrapper<MlProjectModelEntity> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq(StringUtils.isNotBlank(id), "id", id) |
| | | .eq(StringUtils.isNotBlank(projectId), "project_id", projectId) |
| | | .eq(StringUtils.isNotBlank(modelId),"model_id",modelId); |
| | | |
| | | return wrapper; |
| | | } |
| | | |
| | | |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.matlab.service.impl; |
| | | |
| | | import cn.hutool.core.io.FileUtil; |
| | | import com.baomidou.dynamic.datasource.annotation.DSTransactional; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.iailab.framework.common.page.PageData; |
| | | import com.iailab.framework.common.pojo.CommonResult; |
| | | import com.iailab.framework.common.service.impl.BaseServiceImpl; |
| | | import com.iailab.framework.common.util.object.ConvertUtils; |
| | | import com.iailab.module.model.matlab.common.utils.MatlabUtils; |
| | | import com.iailab.module.model.matlab.dao.MlModelDao; |
| | | import com.iailab.module.model.matlab.dao.MlProjectDao; |
| | | import com.iailab.module.model.matlab.dto.MlModelDTO; |
| | | import com.iailab.module.model.matlab.dto.MlProjectDTO; |
| | | import com.iailab.module.model.matlab.dto.MlProjectModelDTO; |
| | | import com.iailab.module.model.matlab.entity.MlProjectEntity; |
| | | import com.iailab.module.model.matlab.service.MlProjectModelService; |
| | | import com.iailab.module.model.matlab.service.MlProjectService; |
| | | import com.iailab.module.model.mpk.common.MdkConstant; |
| | | import com.iailab.module.model.mpk.common.utils.DllUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.collections.CollectionUtils; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.io.File; |
| | | import java.net.URLClassLoader; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @description: |
| | | * @author: dzd |
| | | * @date: 2025/2/25 14:45 |
| | | **/ |
| | | @Service |
| | | @Slf4j |
| | | public class MlProjectServiceImpl extends BaseServiceImpl<MlProjectDao, MlProjectEntity> implements MlProjectService { |
| | | |
| | | @Autowired |
| | | MlProjectModelService mlProjectModelService; |
| | | @Autowired |
| | | MlModelDao mlModelDao; |
| | | |
| | | @Value("${mablab.bak-file-path}") |
| | | private String mablabBakFilePath; |
| | | |
| | | @Override |
| | | public PageData<MlProjectDTO> page(Map<String, Object> params) { |
| | | IPage<MlProjectEntity> page = baseDao.selectPage( |
| | | getPage(params, null, false), |
| | | getWrapper(params) |
| | | ); |
| | | |
| | | return getPageData(page, MlProjectDTO.class); |
| | | } |
| | | |
| | | @Override |
| | | public List<MlProjectDTO> list(Map<String, Object> params) { |
| | | List<MlProjectEntity> entityList = baseDao.selectList(getWrapper(params).orderByDesc("create_time")); |
| | | |
| | | return ConvertUtils.sourceToTarget(entityList, MlProjectDTO.class); |
| | | } |
| | | |
| | | @Override |
| | | public MlProjectDTO get(String id) { |
| | | MlProjectEntity entity = baseDao.selectById(id); |
| | | MlProjectDTO dto = ConvertUtils.sourceToTarget(entity, MlProjectDTO.class); |
| | | |
| | | Map<String,Object> map = new HashMap<>(); |
| | | map.put("projectId",id); |
| | | List<MlProjectModelDTO> projectModelList = mlProjectModelService.list(map); |
| | | dto.setModels(projectModelList.stream().map(e -> { |
| | | MlModelDTO mlModelDTO = new MlModelDTO(); |
| | | mlModelDTO.setId(e.getModelId()); |
| | | return mlModelDTO; |
| | | }).collect(Collectors.toList())); |
| | | |
| | | return dto; |
| | | } |
| | | |
| | | @Override |
| | | @DSTransactional(rollbackFor = Exception.class) |
| | | public void save(MlProjectDTO dto) { |
| | | MlProjectEntity entity = ConvertUtils.sourceToTarget(dto, MlProjectEntity.class); |
| | | String projectId = UUID.randomUUID().toString(); |
| | | entity.setId(projectId); |
| | | entity.setCreateTime(new Date()); |
| | | insert(entity); |
| | | |
| | | //关联模型 |
| | | List<MlModelDTO> models = dto.getModels(); |
| | | if (CollectionUtils.isNotEmpty(models)) { |
| | | mlProjectModelService.create(models,projectId); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @DSTransactional(rollbackFor = Exception.class) |
| | | public void update(MlProjectDTO dto) { |
| | | MlProjectEntity entity = ConvertUtils.sourceToTarget(dto, MlProjectEntity.class); |
| | | entity.setUpdateTime(new Date()); |
| | | updateById(entity); |
| | | |
| | | String projectId = dto.getId(); |
| | | //删除关联 |
| | | Map<String,Object> map = new HashMap<>(); |
| | | map.put("projectId",projectId); |
| | | mlProjectModelService.deleteByMap(map); |
| | | |
| | | //关联模型 |
| | | List<MlModelDTO> models = dto.getModels(); |
| | | if (CollectionUtils.isNotEmpty(models)) { |
| | | mlProjectModelService.create(models,projectId); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @DSTransactional(rollbackFor = Exception.class) |
| | | public void delete(String id) { |
| | | //删除 (级联删除) |
| | | baseDao.deleteById(id); |
| | | } |
| | | |
| | | @Override |
| | | public PageData<MlModelDTO> getProjectModel(Map<String, Object> params) { |
| | | String projectId = (String) params.get("projectId"); |
| | | |
| | | int total = mlModelDao.getProjectModelCount(projectId); |
| | | if (total == 0) { |
| | | return new PageData<>(new ArrayList<>(), 0); |
| | | } |
| | | int page = Integer.parseInt((String) params.get("page")); |
| | | int pageSize = Integer.parseInt((String) params.get("pageSize")); |
| | | int offset = (page - 1)*pageSize; |
| | | params.put("offset",offset); |
| | | params.put("pageSize",pageSize); |
| | | List<MlModelDTO> list = mlModelDao.getProjectModel(params); |
| | | |
| | | return new PageData<>(list,total); |
| | | } |
| | | |
| | | @Override |
| | | public CommonResult<String> publish(Map<String, Object> params) { |
| | | String projectId = (String) params.get("projectId"); |
| | | |
| | | // 卸载上次发布的classloader 并删除发布备份文件 |
| | | MatlabUtils.removeClassLoaderCache(projectId); |
| | | MatlabUtils.removeOldFile(mablabBakFilePath + File.separator + MdkConstant.PROJECT_PUBLISH,projectId); |
| | | |
| | | // 查询关联模型 |
| | | List<MlModelDTO> list = mlProjectModelService.getProjectModel(params); |
| | | // 将模型文件备份到发布文件 |
| | | String[] jarFilePaths = new String[list.size()]; |
| | | for (int i = 0; i < list.size(); i++) { |
| | | MlModelDTO mlModelDTO = list.get(i); |
| | | String jarFilePath = mablabBakFilePath + File.separator + MdkConstant.PROJECT_PUBLISH + File.separator + projectId + MdkConstant.SPLIT + mlModelDTO.getId() + ".jar"; |
| | | FileUtil.copy(mlModelDTO.getModelFilePath(),jarFilePath,true); |
| | | jarFilePaths[i] = jarFilePath; |
| | | } |
| | | |
| | | // 加载新的jar,将classloader存入缓存 |
| | | URLClassLoader urlClassLoader = null; |
| | | try { |
| | | // 加载新的jar |
| | | urlClassLoader = MatlabUtils.loadJar(projectId,jarFilePaths); |
| | | } catch (Exception e) { |
| | | throw new RuntimeException("加载新的jar异常",e); |
| | | } |
| | | |
| | | |
| | | return CommonResult.success(); |
| | | } |
| | | |
| | | public QueryWrapper<MlProjectEntity> getWrapper(Map<String, Object> params){ |
| | | String id = (String)params.get("id"); |
| | | String projectName = (String)params.get("projectName"); |
| | | String projectCode = (String)params.get("projectCode"); |
| | | |
| | | QueryWrapper<MlProjectEntity> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq(StringUtils.isNotBlank(id), "id", id) |
| | | .like(StringUtils.isNotBlank(projectName),"project_name",projectName) |
| | | .like(StringUtils.isNotBlank(projectCode),"project_code",projectCode); |
| | | |
| | | return wrapper; |
| | | } |
| | | |
| | | |
| | | } |
| | |
| | | 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); |
| | | } |
| | |
| | | |
| | | 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; |
| | | } |
| | |
| | | String jarSavePath = pkgJar(dirPath.getAbsolutePath()); |
| | | //备份jar文件,用于后续运行 |
| | | String jarBakPath = mpkTenantBakFilePath + File.separator + MdkConstant.JAR + File.separator + entity.getPyName() + ".jar"; |
| | | FileUtil.mkParentDirs(dllBakPath); |
| | | FileUtil.mkParentDirs(jarBakPath); |
| | | FileUtil.copy(jarSavePath, jarBakPath, true); |
| | | // 打zip包 |
| | | String zipPath = mpkTenantBakFilePath + File.separator + zipFileName; |
| | |
| | | bak-file-path: D:\DLUT\mpkBakFile |
| | | bak-resources: D:\DLUT\mpkResources |
| | | model-file-path: D:\DLUT\MDK\Model\miail\ |
| | | mablab: |
| | | bak-file-path: D:\DLUT\matlabBakFile |
| | | |
| | | influx-db: |
| | | org: iailab |
| | |
| | | - t_mpk_pack |
| | | - t_mm_item_status |
| | | - t_electricity_price_segmented |
| | | - t_ml_model |
| | | - t_ml_model_method |
| | | - t_ml_model_method_setting |
| | | - t_ml_project |
| | | - t_ml_project_model |
| | | app: |
| | | app-key: model |
| | | app-secret: 85b0df7edc3df3611913df34ed695011 |
对比新文件 |
| | |
| | | <?xml version="1.0" encoding="UTF-8" ?> |
| | | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > |
| | | <mapper namespace="com.iailab.module.model.matlab.dao.MlModelDao"> |
| | | <resultMap type="com.iailab.module.model.matlab.dto.MlModelDTO" id="mlModelMap"> |
| | | <result property="id" column="id"/> |
| | | <result property="modelName" column="model_name"/> |
| | | <result property="modelFileName" column="model_file_name"/> |
| | | <result property="modelFilePath" column="model_file_path"/> |
| | | <result property="modelType" column="model_type"/> |
| | | <result property="matlabPlatform" column="matlab_platform"/> |
| | | <result property="matlabVersion" column="matlab_version"/> |
| | | <result property="remark" column="remark"/> |
| | | <result property="creator" column="creator"/> |
| | | <result property="createDate" column="create_date"/> |
| | | <result property="updater" column="updater"/> |
| | | <result property="updateDate" column="update_date"/> |
| | | <collection property="modelMethods" ofType="com.iailab.module.model.matlab.dto.MlModelMethodDTO"> |
| | | <id property="id" column="method_id"/> |
| | | <result property="className" column="class_name"/> |
| | | <result property="methodName" column="method_name"/> |
| | | <result property="dataLength" column="data_length"/> |
| | | <result property="outLength" column="out_length"/> |
| | | <collection property="methodSettings" ofType="com.iailab.module.model.matlab.dto.MlModelMethodSettingDTO"> |
| | | <id property="id" column="setting_id"/> |
| | | <result property="name" column="setting_name"/> |
| | | <result property="settingKey" column="setting_key"/> |
| | | <result property="settingValue" column="setting_value"/> |
| | | <result property="valueType" column="value_type"/> |
| | | </collection> |
| | | </collection> |
| | | </resultMap> |
| | | |
| | | <select id="list" resultMap="mlModelMap" parameterType="java.util.Map"> |
| | | SELECT |
| | | a.*, |
| | | b.id method_id, |
| | | b.class_name, |
| | | b.method_name, |
| | | b.data_length, |
| | | b.out_length, |
| | | c.id setting_id, |
| | | c.NAME setting_name, |
| | | c.setting_key, |
| | | c.setting_value, |
| | | c.value_type |
| | | FROM |
| | | t_ml_model a |
| | | LEFT JOIN t_ml_model_method b ON a.id = b.ml_model_id |
| | | LEFT JOIN t_ml_model_method_setting c ON b.id = c.ml_model_method_id |
| | | <where> |
| | | <if test="params.modelType != null and params.modelType != ''"> |
| | | AND a.model_type = #{params.modelType} |
| | | </if> |
| | | </where> |
| | | ORDER BY |
| | | a.create_date, |
| | | b.sort, |
| | | c.sort |
| | | </select> |
| | | <select id="get" resultMap="mlModelMap" parameterType="java.lang.String"> |
| | | SELECT |
| | | a.*, |
| | | b.id method_id, |
| | | b.class_name, |
| | | b.method_name, |
| | | b.data_length, |
| | | b.out_length, |
| | | c.id setting_id, |
| | | c.NAME setting_name, |
| | | c.setting_key, |
| | | c.setting_value, |
| | | c.value_type |
| | | FROM |
| | | t_ml_model a |
| | | LEFT JOIN t_ml_model_method b ON a.id = b.ml_model_id |
| | | LEFT JOIN t_ml_model_method_setting c ON b.id = c.ml_model_method_id |
| | | WHERE a.id = #{id} |
| | | ORDER BY b.sort,c.sort |
| | | </select> |
| | | <select id="getProjectModelCount" resultType="java.lang.Integer" parameterType="java.lang.String"> |
| | | SELECT |
| | | count(*) |
| | | FROM |
| | | t_ml_project_model |
| | | WHERE |
| | | project_id = #{projectId} |
| | | </select> |
| | | <select id="getProjectModel" resultMap="mlModelMap" parameterType="java.util.Map"> |
| | | SELECT |
| | | t3.*, |
| | | t4.id method_id, |
| | | t4.class_name, |
| | | t4.method_name, |
| | | t4.data_length, |
| | | t4.out_length, |
| | | t5.id setting_id, |
| | | t5.setting_key, |
| | | t5.name setting_name, |
| | | t5.setting_value, |
| | | t5.value_type |
| | | FROM |
| | | ( |
| | | SELECT |
| | | t2.* |
| | | FROM |
| | | t_ml_project_model t1 |
| | | LEFT JOIN t_ml_model t2 ON t1.model_id = t2.id |
| | | WHERE |
| | | t1.project_id = #{params.projectId} |
| | | <if test="params.modelFileName != null and params.modelFileName != ''"> |
| | | AND t2.model_file_name LIKE CONCAT('%',#{params.modelFileName},'%') |
| | | </if> |
| | | ORDER BY |
| | | t2.create_date DESC |
| | | LIMIT #{params.offset},#{params.pageSize} |
| | | ) t3 |
| | | LEFT JOIN t_ml_model_method t4 ON t3.id = t4.ml_model_id |
| | | LEFT JOIN t_ml_model_method_setting t5 ON t4.id = t5.ml_model_method_id |
| | | </select> |
| | | </mapper> |
对比新文件 |
| | |
| | | <?xml version="1.0" encoding="UTF-8" ?> |
| | | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > |
| | | <mapper namespace="com.iailab.module.model.matlab.dao.MlProjectModelDao"> |
| | | <select id="getProjectModel" resultType="com.iailab.module.model.matlab.dto.MlModelDTO"> |
| | | SELECT |
| | | t2.id, |
| | | t2.model_file_path |
| | | FROM |
| | | t_ml_project_model t1 |
| | | LEFT JOIN t_ml_model t2 ON t1.model_id = t2.id |
| | | WHERE |
| | | t1.project_id = #{params.projectId} |
| | | </select> |
| | | </mapper> |