23 changed files with 527 additions and 14 deletions
			
			
		@ -0,0 +1,53 @@ | 
				
			|||||||
 | 
					package com.hnac.hzims.history.entity; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.baomidou.mybatisplus.annotation.TableName; | 
				
			||||||
 | 
					import io.swagger.annotations.ApiModel; | 
				
			||||||
 | 
					import io.swagger.annotations.ApiModelProperty; | 
				
			||||||
 | 
					import lombok.Data; | 
				
			||||||
 | 
					import lombok.EqualsAndHashCode; | 
				
			||||||
 | 
					import org.springblade.core.tenant.mp.TenantEntity; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** | 
				
			||||||
 | 
					 * 设备树绑定巡检实体类 | 
				
			||||||
 | 
					 * @author tanghaihao | 
				
			||||||
 | 
					 * @date 2023年06月14日 16:46 | 
				
			||||||
 | 
					 */ | 
				
			||||||
 | 
					@Data | 
				
			||||||
 | 
					@TableName("hzims_device_history_template") | 
				
			||||||
 | 
					@EqualsAndHashCode(callSuper = true) | 
				
			||||||
 | 
					@ApiModel(value = "设备历史数据模板") | 
				
			||||||
 | 
					public class HistoryTemplateEntity extends TenantEntity { | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @ApiModelProperty(value = "模板名称") | 
				
			||||||
 | 
					    private Long templateName; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @ApiModelProperty(value = "站点编码") | 
				
			||||||
 | 
					    private String stationId; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @ApiModelProperty(value = "站点名称") | 
				
			||||||
 | 
					    private String stationName; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @ApiModelProperty(value = "属性1") | 
				
			||||||
 | 
					    private String realId1; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @ApiModelProperty(value = "属性1名称") | 
				
			||||||
 | 
					    private String realName1; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @ApiModelProperty(value = "属性2") | 
				
			||||||
 | 
					    private String realId2; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @ApiModelProperty(value = "属性2名称") | 
				
			||||||
 | 
					    private String realName2; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @ApiModelProperty(value = "属性3") | 
				
			||||||
 | 
					    private String realId3; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @ApiModelProperty(value = "属性3名称") | 
				
			||||||
 | 
					    private String realName3; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @ApiModelProperty(value = "属性4") | 
				
			||||||
 | 
					    private String realId4; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @ApiModelProperty(value = "属性4名称") | 
				
			||||||
 | 
					    private String realName4; | 
				
			||||||
 | 
					} | 
				
			||||||
@ -0,0 +1,53 @@ | 
				
			|||||||
 | 
					package com.hnac.hzims.history.vo; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.fasterxml.jackson.annotation.JsonFormat; | 
				
			||||||
 | 
					import io.swagger.annotations.ApiModel; | 
				
			||||||
 | 
					import io.swagger.annotations.ApiModelProperty; | 
				
			||||||
 | 
					import lombok.Data; | 
				
			||||||
 | 
					import org.springblade.core.tool.utils.DateUtil; | 
				
			||||||
 | 
					import org.springframework.format.annotation.DateTimeFormat; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.time.LocalDateTime; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** | 
				
			||||||
 | 
					 * @author ysj | 
				
			||||||
 | 
					 */ | 
				
			||||||
 | 
					@Data | 
				
			||||||
 | 
					@ApiModel(value = "设备历史查询参数") | 
				
			||||||
 | 
					public class HistoryDataParamVo { | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						@ApiModelProperty(value = "第一个点位") | 
				
			||||||
 | 
						private String firstAttrId; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						@ApiModelProperty(value = "第二个点位") | 
				
			||||||
 | 
						private String secondAttrId; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						@ApiModelProperty(value = "第三个点位") | 
				
			||||||
 | 
						private String thirdlyAttrId; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						@ApiModelProperty(value = "第四个点位") | 
				
			||||||
 | 
						private String fourthAttrId; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						@ApiModelProperty(value = "第五个点位") | 
				
			||||||
 | 
						private String fifthAttrId; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						@ApiModelProperty(value = "开始时间") | 
				
			||||||
 | 
						@DateTimeFormat(pattern = DateUtil.PATTERN_DATETIME) | 
				
			||||||
 | 
						@JsonFormat(pattern = DateUtil.PATTERN_DATETIME) | 
				
			||||||
 | 
						private LocalDateTime startTime; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						@ApiModelProperty(value = "结束时间") | 
				
			||||||
 | 
						@DateTimeFormat(pattern = DateUtil.PATTERN_DATETIME) | 
				
			||||||
 | 
						@JsonFormat(pattern = DateUtil.PATTERN_DATETIME) | 
				
			||||||
 | 
						private LocalDateTime endTime; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						@ApiModelProperty(value = "是否分页") | 
				
			||||||
 | 
						private Boolean isPage; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						@ApiModelProperty(value = "页码") | 
				
			||||||
 | 
						private Integer current; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						@ApiModelProperty(value = "页码条数") | 
				
			||||||
 | 
						private Integer pageSize; | 
				
			||||||
 | 
					} | 
				
			||||||
@ -0,0 +1,17 @@ | 
				
			|||||||
 | 
					package com.hnac.hzims.history.vo; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import io.swagger.annotations.ApiModelProperty; | 
				
			||||||
 | 
					import lombok.Data; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** | 
				
			||||||
 | 
					 * @author ysj | 
				
			||||||
 | 
					 */ | 
				
			||||||
 | 
					@Data | 
				
			||||||
 | 
					public class HistoryTemplateParamVo { | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @ApiModelProperty(value = "站点Id") | 
				
			||||||
 | 
					    private String stationId; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @ApiModelProperty(value = "用户Id") | 
				
			||||||
 | 
					    private Long createUser; | 
				
			||||||
 | 
					} | 
				
			||||||
@ -0,0 +1,17 @@ | 
				
			|||||||
 | 
					package com.hnac.hzims.history.vo; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import io.swagger.annotations.ApiModelProperty; | 
				
			||||||
 | 
					import lombok.Data; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** | 
				
			||||||
 | 
					 * @author ysj | 
				
			||||||
 | 
					 */ | 
				
			||||||
 | 
					@Data | 
				
			||||||
 | 
					public class MonitorPointVo { | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @ApiModelProperty(value = "站点Id") | 
				
			||||||
 | 
					    private String monitorId; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @ApiModelProperty(value = "用户Id") | 
				
			||||||
 | 
					    private String monitorName; | 
				
			||||||
 | 
					} | 
				
			||||||
@ -0,0 +1,54 @@ | 
				
			|||||||
 | 
					package com.hnac.hzims.history.controller; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; | 
				
			||||||
 | 
					import com.hnac.hzims.history.service.IHistoryDeviceService; | 
				
			||||||
 | 
					import com.hnac.hzims.history.vo.HistoryDataParamVo; | 
				
			||||||
 | 
					import com.hnac.hzinfo.sdk.v5.device.vo.DeviceInstanceAttrVO; | 
				
			||||||
 | 
					import com.hnac.hzinfo.sdk.v5.device.vo.DeviceInstanceVO; | 
				
			||||||
 | 
					import io.swagger.annotations.Api; | 
				
			||||||
 | 
					import io.swagger.annotations.ApiOperation; | 
				
			||||||
 | 
					import lombok.AllArgsConstructor; | 
				
			||||||
 | 
					import org.springblade.core.boot.ctrl.BladeController; | 
				
			||||||
 | 
					import org.springblade.core.tool.api.R; | 
				
			||||||
 | 
					import org.springframework.web.bind.annotation.*; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.util.List; | 
				
			||||||
 | 
					import java.util.Map; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** | 
				
			||||||
 | 
					 * @author ysj | 
				
			||||||
 | 
					 */ | 
				
			||||||
 | 
					@RestController | 
				
			||||||
 | 
					@AllArgsConstructor | 
				
			||||||
 | 
					@RequestMapping("/history") | 
				
			||||||
 | 
					@Api(value = "设备历史数据", tags = "设备历史数据") | 
				
			||||||
 | 
					public class DeviceHistoryController extends BladeController { | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						private final IHistoryDeviceService service; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						@GetMapping ("/device") | 
				
			||||||
 | 
						@ApiOperationSupport(order = 1) | 
				
			||||||
 | 
						@ApiOperation(value = "查询项目设备列表", notes = "传入TrainEntity") | 
				
			||||||
 | 
						public R<List<DeviceInstanceVO>> device(@RequestParam(value="projectId") String projectId) { | 
				
			||||||
 | 
							return R.data(service.device(projectId)); | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						@GetMapping ("/monitor_point") | 
				
			||||||
 | 
						@ApiOperationSupport(order = 1) | 
				
			||||||
 | 
						@ApiOperation(value = "设备监测点查询", notes = "传入TrainEntity") | 
				
			||||||
 | 
						public R<List<DeviceInstanceAttrVO>> monitor_point(@RequestParam(value="projectId",required = false) String projectId, | 
				
			||||||
 | 
																		   @RequestParam(value="deviceCode",required = false) String deviceCode, | 
				
			||||||
 | 
																		   @RequestParam(value="deviceName",required = false) String deviceName, | 
				
			||||||
 | 
																		   @RequestParam(value="attrName",required = false) String attrName) { | 
				
			||||||
 | 
							return R.data(service.monitor_point(projectId,deviceCode,deviceName,attrName)); | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						@PostMapping("/history_curve") | 
				
			||||||
 | 
						@ApiOperationSupport(order = 5) | 
				
			||||||
 | 
						@ApiOperation(value = "设备历史数据曲线图", notes = "获取设备历史数据曲线图") | 
				
			||||||
 | 
						public R<Map<String, Object>> historyCurve(@RequestBody HistoryDataParamVo param) { | 
				
			||||||
 | 
							return R.data(service.historyCurve(param)); | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
					} | 
				
			||||||
@ -0,0 +1,43 @@ | 
				
			|||||||
 | 
					package com.hnac.hzims.history.controller; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.baomidou.mybatisplus.core.metadata.IPage; | 
				
			||||||
 | 
					import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; | 
				
			||||||
 | 
					import com.hnac.hzims.history.entity.HistoryTemplateEntity; | 
				
			||||||
 | 
					import com.hnac.hzims.history.service.IHistoryTemplateService; | 
				
			||||||
 | 
					import com.hnac.hzims.history.vo.HistoryTemplateParamVo; | 
				
			||||||
 | 
					import com.hnac.hzims.safeproduct.train.entity.InstitutionalEntity; | 
				
			||||||
 | 
					import com.hnac.hzims.safeproduct.train.vo.InstitutionalParamVo; | 
				
			||||||
 | 
					import io.swagger.annotations.Api; | 
				
			||||||
 | 
					import io.swagger.annotations.ApiOperation; | 
				
			||||||
 | 
					import lombok.AllArgsConstructor; | 
				
			||||||
 | 
					import org.springblade.core.boot.ctrl.BladeController; | 
				
			||||||
 | 
					import org.springblade.core.mp.support.Condition; | 
				
			||||||
 | 
					import org.springblade.core.mp.support.Query; | 
				
			||||||
 | 
					import org.springblade.core.tool.api.R; | 
				
			||||||
 | 
					import org.springframework.web.bind.annotation.*; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** | 
				
			||||||
 | 
					 * @author ysj | 
				
			||||||
 | 
					 */ | 
				
			||||||
 | 
					@RestController | 
				
			||||||
 | 
					@AllArgsConstructor | 
				
			||||||
 | 
					@RequestMapping("/history/template") | 
				
			||||||
 | 
					@Api(value = "设备历史数据模板", tags = "设备历史数据模板") | 
				
			||||||
 | 
					public class HistoryTemplateController extends BladeController { | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						private final IHistoryTemplateService service; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						@PostMapping("/save") | 
				
			||||||
 | 
						@ApiOperationSupport(order = 1) | 
				
			||||||
 | 
						@ApiOperation(value = "新增历史数据模板", notes = "传入TrainEntity") | 
				
			||||||
 | 
						public R save(@RequestBody HistoryTemplateEntity entity) { | 
				
			||||||
 | 
							return R.status(service.save(entity)); | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						@GetMapping("/pages") | 
				
			||||||
 | 
						@ApiOperationSupport(order = 5) | 
				
			||||||
 | 
						@ApiOperation(value = "分页历史数据模板", notes = "查询条件:entity") | 
				
			||||||
 | 
						public R<IPage<HistoryTemplateEntity>> pageCondition(HistoryTemplateParamVo params, Query query) { | 
				
			||||||
 | 
							return R.data(service.pageCondition(params, Condition.getPage(query))); | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
					} | 
				
			||||||
@ -0,0 +1,11 @@ | 
				
			|||||||
 | 
					package com.hnac.hzims.history.mapper; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.hnac.hzims.history.entity.HistoryTemplateEntity; | 
				
			||||||
 | 
					import org.springblade.core.datascope.mapper.UserDataScopeBaseMapper; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** | 
				
			||||||
 | 
					 * @author ysj | 
				
			||||||
 | 
					 */ | 
				
			||||||
 | 
					public interface HistoryTemplateMapper extends UserDataScopeBaseMapper<HistoryTemplateEntity> { | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					} | 
				
			||||||
@ -0,0 +1,5 @@ | 
				
			|||||||
 | 
					<?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.hnac.hzims.history.mapper.HistoryTemplateMapper" > | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					</mapper> | 
				
			||||||
@ -0,0 +1,20 @@ | 
				
			|||||||
 | 
					package com.hnac.hzims.history.service; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.hnac.hzims.history.vo.HistoryDataParamVo; | 
				
			||||||
 | 
					import com.hnac.hzinfo.sdk.v5.device.vo.DeviceInstanceAttrVO; | 
				
			||||||
 | 
					import com.hnac.hzinfo.sdk.v5.device.vo.DeviceInstanceVO; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.util.List; | 
				
			||||||
 | 
					import java.util.Map; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** | 
				
			||||||
 | 
					 * @author ysj | 
				
			||||||
 | 
					 */ | 
				
			||||||
 | 
					public interface IHistoryDeviceService { | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						List<DeviceInstanceVO> device(String projectId); | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						List<DeviceInstanceAttrVO> monitor_point(String projectId,String deviceCode,String deviceName, String attrName); | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Map<String, Object> historyCurve(HistoryDataParamVo param); | 
				
			||||||
 | 
					} | 
				
			||||||
@ -0,0 +1,15 @@ | 
				
			|||||||
 | 
					package com.hnac.hzims.history.service; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.baomidou.mybatisplus.core.metadata.IPage; | 
				
			||||||
 | 
					import com.baomidou.mybatisplus.extension.service.IService; | 
				
			||||||
 | 
					import com.hnac.hzims.history.entity.HistoryTemplateEntity; | 
				
			||||||
 | 
					import com.hnac.hzims.history.vo.HistoryTemplateParamVo; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** | 
				
			||||||
 | 
					 * @author ysj | 
				
			||||||
 | 
					 */ | 
				
			||||||
 | 
					public interface IHistoryTemplateService extends IService<HistoryTemplateEntity> { | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						IPage<HistoryTemplateEntity> pageCondition(HistoryTemplateParamVo params, IPage<HistoryTemplateEntity> page); | 
				
			||||||
 | 
					} | 
				
			||||||
@ -0,0 +1,147 @@ | 
				
			|||||||
 | 
					package com.hnac.hzims.history.service.impl; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.hnac.hzims.history.service.IHistoryDeviceService; | 
				
			||||||
 | 
					import com.hnac.hzims.history.vo.HistoryDataParamVo; | 
				
			||||||
 | 
					import com.hnac.hzinfo.sdk.core.response.Result; | 
				
			||||||
 | 
					import com.hnac.hzinfo.sdk.v5.device.DeviceDataClient; | 
				
			||||||
 | 
					import com.hnac.hzinfo.sdk.v5.device.client.DeviceClient; | 
				
			||||||
 | 
					import com.hnac.hzinfo.sdk.v5.device.vo.DeviceInstanceAttrVO; | 
				
			||||||
 | 
					import com.hnac.hzinfo.sdk.v5.device.vo.DeviceInstanceVO; | 
				
			||||||
 | 
					import lombok.AllArgsConstructor; | 
				
			||||||
 | 
					import org.springblade.core.log.exception.ServiceException; | 
				
			||||||
 | 
					import org.springblade.core.tool.api.R; | 
				
			||||||
 | 
					import org.springblade.core.tool.utils.CollectionUtil; | 
				
			||||||
 | 
					import org.springblade.core.tool.utils.StringUtil; | 
				
			||||||
 | 
					import org.springframework.stereotype.Service; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.time.LocalDateTime; | 
				
			||||||
 | 
					import java.time.ZoneOffset; | 
				
			||||||
 | 
					import java.util.*; | 
				
			||||||
 | 
					import java.util.stream.Collectors; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** | 
				
			||||||
 | 
					 * @author ysj | 
				
			||||||
 | 
					 */ | 
				
			||||||
 | 
					@Service | 
				
			||||||
 | 
					@AllArgsConstructor | 
				
			||||||
 | 
					public class HistoryDeviceServiceImpl implements IHistoryDeviceService { | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						private final DeviceClient deviceClient; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						private final DeviceDataClient deviceDataClient; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/** | 
				
			||||||
 | 
						 * 项目设备列表 | 
				
			||||||
 | 
						 * @param projectId | 
				
			||||||
 | 
						 * @return | 
				
			||||||
 | 
						 */ | 
				
			||||||
 | 
						@Override | 
				
			||||||
 | 
						public List<DeviceInstanceVO> device(String projectId) { | 
				
			||||||
 | 
							R<List<DeviceInstanceVO>> result = deviceClient.getOnlineDeviceInstanceSearchName(projectId,""); | 
				
			||||||
 | 
							if(!result.isSuccess() || CollectionUtil.isEmpty(result.getData())){ | 
				
			||||||
 | 
								return new ArrayList<>(); | 
				
			||||||
 | 
							} | 
				
			||||||
 | 
							return result.getData(); | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/** | 
				
			||||||
 | 
						 * 设备点位列表 | 
				
			||||||
 | 
						 * @param deviceCode | 
				
			||||||
 | 
						 * @param attrName | 
				
			||||||
 | 
						 * @return | 
				
			||||||
 | 
						 */ | 
				
			||||||
 | 
						@Override | 
				
			||||||
 | 
						public List<DeviceInstanceAttrVO> monitor_point(String projectId,String deviceCode,String deviceName, String attrName) { | 
				
			||||||
 | 
							List<DeviceInstanceAttrVO> result = new ArrayList<>(); | 
				
			||||||
 | 
							// 查询所有
 | 
				
			||||||
 | 
							if(StringUtil.isEmpty(deviceCode)){ | 
				
			||||||
 | 
								R<List<DeviceInstanceVO>> instances = deviceClient.getOnlineDeviceInstanceSearchName(projectId,""); | 
				
			||||||
 | 
								if(!instances.isSuccess() || CollectionUtil.isEmpty(instances.getData())){ | 
				
			||||||
 | 
									return result; | 
				
			||||||
 | 
								} | 
				
			||||||
 | 
								instances.getData().stream().sorted(Comparator.comparing(DeviceInstanceVO::getName)).forEach(instance->{ | 
				
			||||||
 | 
									Result<List<DeviceInstanceAttrVO>> attrs = deviceClient.getDeviceAttrByName(instance.getCode(),""); | 
				
			||||||
 | 
									if(!attrs.isSuccess() || CollectionUtil.isEmpty(attrs.getData())){ | 
				
			||||||
 | 
										return; | 
				
			||||||
 | 
									} | 
				
			||||||
 | 
									result.addAll(attrs.getData().stream().filter(o-> StringUtil.isNotBlank(o.getFacDeviceAttrId())).peek(attr->{ | 
				
			||||||
 | 
										attr.setName(instance.getName() + "-" + attr.getName()); | 
				
			||||||
 | 
									}).collect(Collectors.toList())); | 
				
			||||||
 | 
								}); | 
				
			||||||
 | 
							} | 
				
			||||||
 | 
							// 根据设备查询
 | 
				
			||||||
 | 
							Result<List<DeviceInstanceAttrVO>> attrs = deviceClient.getDeviceAttrByName(deviceCode,attrName); | 
				
			||||||
 | 
							if(!attrs.isSuccess() || CollectionUtil.isEmpty(attrs.getData())){ | 
				
			||||||
 | 
								return result; | 
				
			||||||
 | 
							} | 
				
			||||||
 | 
							return attrs.getData().stream().filter(o-> StringUtil.isNotBlank(o.getFacDeviceAttrId())).peek(attr->{ | 
				
			||||||
 | 
								attr.setName(deviceName + "-" + attr.getName()); | 
				
			||||||
 | 
							}).collect(Collectors.toList()); | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/** | 
				
			||||||
 | 
						 * 设备历史数据曲线图 | 
				
			||||||
 | 
						 * @param param | 
				
			||||||
 | 
						 * @return | 
				
			||||||
 | 
						 */ | 
				
			||||||
 | 
						@Override | 
				
			||||||
 | 
						public Map<String, Object> historyCurve(HistoryDataParamVo param) { | 
				
			||||||
 | 
							// 计算查询数据维度 :  0-10秒 、 1-1分钟 、2-5分钟 .....
 | 
				
			||||||
 | 
							Integer intervalType = this.computeInterval(param.getStartTime(),param.getEndTime()); | 
				
			||||||
 | 
							// 查询数据
 | 
				
			||||||
 | 
							Result<Map<String, Object>> result = deviceDataClient.getLineDataByRealId( | 
				
			||||||
 | 
									param.getFirstAttrId(), | 
				
			||||||
 | 
									param.getSecondAttrId(), | 
				
			||||||
 | 
									param.getThirdlyAttrId(), | 
				
			||||||
 | 
									param.getFourthAttrId(), | 
				
			||||||
 | 
									param.getFifthAttrId(), | 
				
			||||||
 | 
									param.getStartTime(), | 
				
			||||||
 | 
									param.getEndTime(), | 
				
			||||||
 | 
									// 默认查询设备 : 0-厂组点, 1-设备
 | 
				
			||||||
 | 
									1, | 
				
			||||||
 | 
									intervalType, | 
				
			||||||
 | 
									param.getIsPage(), | 
				
			||||||
 | 
									param.getCurrent(), | 
				
			||||||
 | 
									param.getPageSize() | 
				
			||||||
 | 
							); | 
				
			||||||
 | 
							if(!result.isSuccess()){ | 
				
			||||||
 | 
								throw new ServiceException(result.getMsg()); | 
				
			||||||
 | 
							} | 
				
			||||||
 | 
							if(CollectionUtil.isEmpty(result.getData())){ | 
				
			||||||
 | 
								return new HashMap<>(); | 
				
			||||||
 | 
							} | 
				
			||||||
 | 
							return result.getData(); | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/** | 
				
			||||||
 | 
						 * 计算查询数据维度 | 
				
			||||||
 | 
						 * @param startTime | 
				
			||||||
 | 
						 * @param endTime | 
				
			||||||
 | 
						 * @return | 
				
			||||||
 | 
						 */ | 
				
			||||||
 | 
						private Integer computeInterval(LocalDateTime startTime, LocalDateTime endTime) { | 
				
			||||||
 | 
							long seconds = endTime.toEpochSecond(ZoneOffset.UTC) - startTime.toEpochSecond(ZoneOffset.UTC); | 
				
			||||||
 | 
							// 小于一天 : 10秒一条数据
 | 
				
			||||||
 | 
							if(seconds < 60 * 60 * 24L){ | 
				
			||||||
 | 
								return 0; | 
				
			||||||
 | 
							// 小于5天 : 1分钟一条数据
 | 
				
			||||||
 | 
							}else if(seconds < 60 * 60 * 24 * 5L){ | 
				
			||||||
 | 
								return 1; | 
				
			||||||
 | 
							// 小于15天 : 5分钟一条数据
 | 
				
			||||||
 | 
							}else if(seconds < 60 * 60 * 24 * 15L){ | 
				
			||||||
 | 
								return 2; | 
				
			||||||
 | 
							// 小于30天 : 10分钟一条数据
 | 
				
			||||||
 | 
							}else if(seconds < 60 * 60 * 24 * 30L){ | 
				
			||||||
 | 
								return 3; | 
				
			||||||
 | 
							// 小于90天 : 30分钟一条数据
 | 
				
			||||||
 | 
							}else if(seconds < 60 * 60 * 24 * 90L){ | 
				
			||||||
 | 
								return 4; | 
				
			||||||
 | 
							// 小于180天 : 60分钟一条数据
 | 
				
			||||||
 | 
							}else if(seconds < 60 * 60 * 24 * 180L){ | 
				
			||||||
 | 
								return 5; | 
				
			||||||
 | 
							} | 
				
			||||||
 | 
							return 5; | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
					} | 
				
			||||||
@ -0,0 +1,39 @@ | 
				
			|||||||
 | 
					package com.hnac.hzims.history.service.impl; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 
				
			||||||
 | 
					import com.baomidou.mybatisplus.core.metadata.IPage; | 
				
			||||||
 | 
					import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | 
				
			||||||
 | 
					import com.hnac.hzims.history.entity.HistoryTemplateEntity; | 
				
			||||||
 | 
					import com.hnac.hzims.history.mapper.HistoryTemplateMapper; | 
				
			||||||
 | 
					import com.hnac.hzims.history.service.IHistoryTemplateService; | 
				
			||||||
 | 
					import com.hnac.hzims.history.vo.HistoryTemplateParamVo; | 
				
			||||||
 | 
					import org.springblade.core.tool.utils.ObjectUtil; | 
				
			||||||
 | 
					import org.springblade.core.tool.utils.StringUtil; | 
				
			||||||
 | 
					import org.springframework.stereotype.Service; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** | 
				
			||||||
 | 
					 * @author ysj | 
				
			||||||
 | 
					 */ | 
				
			||||||
 | 
					@Service | 
				
			||||||
 | 
					public class HistoryTemplateServiceImpl extends ServiceImpl<HistoryTemplateMapper, HistoryTemplateEntity> implements IHistoryTemplateService { | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/** | 
				
			||||||
 | 
						 * 分页历史数据模板 | 
				
			||||||
 | 
						 * @param params | 
				
			||||||
 | 
						 * @param page | 
				
			||||||
 | 
						 * @return | 
				
			||||||
 | 
						 */ | 
				
			||||||
 | 
						@Override | 
				
			||||||
 | 
						public IPage<HistoryTemplateEntity> pageCondition(HistoryTemplateParamVo params, IPage<HistoryTemplateEntity> page) { | 
				
			||||||
 | 
							LambdaQueryWrapper<HistoryTemplateEntity> wrapper = new LambdaQueryWrapper(); | 
				
			||||||
 | 
							wrapper.orderByDesc(HistoryTemplateEntity::getCreateTime); | 
				
			||||||
 | 
							if(StringUtil.isNotBlank(params.getStationId())){ | 
				
			||||||
 | 
								wrapper.eq(HistoryTemplateEntity::getStationId,params.getStationId()); | 
				
			||||||
 | 
							} | 
				
			||||||
 | 
							if(ObjectUtil.isNotEmpty(params.getCreateUser())){ | 
				
			||||||
 | 
								wrapper.eq(HistoryTemplateEntity::getCreateUser,params.getCreateUser()); | 
				
			||||||
 | 
							} | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							return super.page(page,wrapper); | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
					} | 
				
			||||||
					Loading…
					
					
				
		Reference in new issue