yang_shj
1 year ago
6 changed files with 156 additions and 7 deletions
@ -0,0 +1,20 @@
|
||||
package com.hnac.hzims.operational.census.vo; |
||||
|
||||
import io.swagger.annotations.ApiModelProperty; |
||||
import lombok.Data; |
||||
|
||||
/** |
||||
* @author ysj |
||||
*/ |
||||
@Data |
||||
public class RealVo { |
||||
|
||||
@ApiModelProperty("realId") |
||||
private String realId; |
||||
|
||||
@ApiModelProperty("值") |
||||
private String value; |
||||
|
||||
@ApiModelProperty("质量值") |
||||
private String quality; |
||||
} |
@ -0,0 +1,42 @@
|
||||
package com.hnac.hzims.operational.census.controller; |
||||
|
||||
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; |
||||
import com.hnac.hzims.operational.census.service.DeviceDataService; |
||||
import com.hnac.hzims.operational.census.vo.RealVo; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import lombok.AllArgsConstructor; |
||||
import org.springblade.core.tool.api.R; |
||||
import org.springframework.web.bind.annotation.PostMapping; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RequestParam; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
|
||||
|
||||
/** |
||||
* @author ysj |
||||
*/ |
||||
@RestController |
||||
@AllArgsConstructor |
||||
@RequestMapping("/device") |
||||
@Api(value = "设备数据查询", tags = "设备数据查询") |
||||
public class DeviceDataController { |
||||
|
||||
private final DeviceDataService service; |
||||
|
||||
@ApiOperation("实时数据查询") |
||||
@PostMapping("/real") |
||||
@ApiOperationSupport(order = 1) |
||||
public R<RealVo> real(@RequestParam(value = "code") String code, |
||||
@RequestParam(value = "signages") String signages) { |
||||
return R.data(service.real(code,signages)); |
||||
} |
||||
|
||||
@ApiOperation("实时数据查询") |
||||
@PostMapping("/history") |
||||
@ApiOperationSupport(order = 1) |
||||
public R<RealVo> history(@RequestParam(value = "code") String code, |
||||
@RequestParam(value = "signages") String signages) { |
||||
return R.data(service.real(code,signages)); |
||||
} |
||||
} |
@ -0,0 +1,12 @@
|
||||
package com.hnac.hzims.operational.census.service; |
||||
|
||||
|
||||
import com.hnac.hzims.operational.census.vo.RealVo; |
||||
|
||||
/** |
||||
* @author ysj |
||||
*/ |
||||
public interface DeviceDataService { |
||||
|
||||
RealVo real(String code, String signages); |
||||
} |
@ -0,0 +1,75 @@
|
||||
package com.hnac.hzims.operational.census.service.impl; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.alibaba.fastjson.TypeReference; |
||||
import com.hnac.hzims.equipment.vo.EminfoAndEmParamVo; |
||||
import com.hnac.hzims.operational.census.service.DeviceDataService; |
||||
import com.hnac.hzims.operational.census.vo.RealVo; |
||||
import lombok.RequiredArgsConstructor; |
||||
import org.apache.commons.collections4.MapUtils; |
||||
import org.springblade.core.log.exception.ServiceException; |
||||
import org.springblade.core.tool.utils.CollectionUtil; |
||||
import org.springblade.core.tool.utils.StringUtil; |
||||
import org.springframework.beans.factory.annotation.Value; |
||||
import org.springframework.data.redis.core.RedisTemplate; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import java.util.List; |
||||
import java.util.Map; |
||||
import java.util.stream.Collectors; |
||||
|
||||
/** |
||||
* @author ysj |
||||
*/ |
||||
@Service |
||||
@RequiredArgsConstructor |
||||
public class DeviceDataServiceImpl implements DeviceDataService { |
||||
|
||||
private final RedisTemplate redisTemplate; |
||||
|
||||
@Value("${hzims.operation.realIdKey}") |
||||
public String real_id_cofig_final; |
||||
|
||||
public String device_cache_cofig_final = "hzims:equipment:emInfo:deviceCode.emInfoList"; |
||||
|
||||
@Override |
||||
public RealVo real(String code, String signages) { |
||||
// 缓存设备数据
|
||||
List<EminfoAndEmParamVo> devices = JSONObject.parseObject(redisTemplate.opsForValue().get(device_cache_cofig_final).toString(), new TypeReference<List<EminfoAndEmParamVo>>() { |
||||
}); |
||||
if(CollectionUtil.isEmpty(devices)){ |
||||
throw new ServiceException("不存在设备!"); |
||||
} |
||||
List<EminfoAndEmParamVo> filters = devices.stream().filter(device->device.getEmCode().equals(code)).collect(Collectors.toList()); |
||||
if(CollectionUtil.isEmpty(filters)){ |
||||
throw new ServiceException("不存在设备!"); |
||||
} |
||||
// 设备标识
|
||||
Map<String,String> point = filters.get(0).getPoint(); |
||||
if(MapUtils.isEmpty(point)){ |
||||
throw new ServiceException("设备未绑定模型实列监测点位!"); |
||||
} |
||||
if(!point.containsKey(signages)){ |
||||
throw new ServiceException("设备未绑定模型实列监测点位!"); |
||||
} |
||||
// 查找realId数据
|
||||
RealVo real = new RealVo(); |
||||
real.setRealId(point.get(signages)); |
||||
real.setValue(this.getRealMap().get(real.getRealId())); |
||||
real.setQuality("0"); |
||||
return real; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 获取实时数据 |
||||
* @return |
||||
*/ |
||||
private Map<String, String> getRealMap() { |
||||
String json = (String) redisTemplate.opsForValue().get(real_id_cofig_final); |
||||
if(StringUtil.isBlank(json)){ |
||||
return null; |
||||
} |
||||
return JSONObject.parseObject(json, new TypeReference<Map<String, String>>() {}); |
||||
} |
||||
} |
Loading…
Reference in new issue