|
@@ -0,0 +1,398 @@
|
|
|
|
|
+package com.yunfeiyun.agmp.iotm.device.qxsqz.service;
|
|
|
|
|
+
|
|
|
|
|
+import com.alibaba.fastjson2.JSONArray;
|
|
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
|
|
+import com.yunfeiyun.agmp.common.constant.ErrorCode;
|
|
|
|
|
+import com.yunfeiyun.agmp.common.core.page.PageDomain;
|
|
|
|
|
+import com.yunfeiyun.agmp.common.core.page.TableDataInfo;
|
|
|
|
|
+import com.yunfeiyun.agmp.common.core.page.TableSupport;
|
|
|
|
|
+import com.yunfeiyun.agmp.common.framework.manager.RedisCacheManager;
|
|
|
|
|
+import com.yunfeiyun.agmp.common.utils.DateUtils;
|
|
|
|
|
+import com.yunfeiyun.agmp.common.utils.JSONUtils;
|
|
|
|
|
+import com.yunfeiyun.agmp.common.utils.StringUtils;
|
|
|
|
|
+import com.yunfeiyun.agmp.common.utils.uuid.IdUtils;
|
|
|
|
|
+import com.yunfeiyun.agmp.iot.common.constant.IotErrorCode;
|
|
|
|
|
+import com.yunfeiyun.agmp.iot.common.constant.device.ElementFactorUtil;
|
|
|
|
|
+import com.yunfeiyun.agmp.iot.common.constant.devicetype.IotDeviceDictConst;
|
|
|
|
|
+import com.yunfeiyun.agmp.iot.common.domain.*;
|
|
|
|
|
+import com.yunfeiyun.agmp.iot.common.exception.IotBizException;
|
|
|
|
|
+import com.yunfeiyun.agmp.iot.common.model.cmd.CmdGroupModel;
|
|
|
|
|
+import com.yunfeiyun.agmp.iot.common.service.MongoService;
|
|
|
|
|
+import com.yunfeiyun.agmp.iotm.device.common.domin.DeviceRefreshDto;
|
|
|
|
|
+import com.yunfeiyun.agmp.iotm.device.common.service.IotDeviceBaseService;
|
|
|
|
|
+import com.yunfeiyun.agmp.iotm.device.common.service.impl.IotDeviceBaseServiceImpl;
|
|
|
|
|
+import com.yunfeiyun.agmp.iotm.device.qxsqz.domain.IotDeviceQxzDataListReqVo;
|
|
|
|
|
+import com.yunfeiyun.agmp.iotm.device.qxsqz.domain.QxzDataLast24hDto;
|
|
|
|
|
+import com.yunfeiyun.agmp.iotm.util.MongoUtil;
|
|
|
|
|
+import com.yunfeiyun.agmp.iotm.web.service.IIotCmdtaskService;
|
|
|
|
|
+import com.yunfeiyun.agmp.iotm.web.service.IIotDeviceService;
|
|
|
|
|
+import com.yunfeiyun.agmp.iotm.web.service.IIotDeviceconfigService;
|
|
|
|
|
+import com.yunfeiyun.agmp.iotm.web.service.IIotDevicefactorService;
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.data.domain.Sort;
|
|
|
|
|
+import org.springframework.data.mongodb.core.aggregation.*;
|
|
|
|
|
+import org.springframework.data.mongodb.core.query.Criteria;
|
|
|
|
|
+
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
|
+import java.text.ParseException;
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
+
|
|
|
|
|
+@Slf4j
|
|
|
|
|
+public class IIotYfQxzCommService extends IotDeviceBaseServiceImpl implements IotDeviceBaseService {
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private MongoService mongoService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private IIotDevicefactorService iotDevicefactorService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private IIotDeviceService iotDeviceService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private RedisCacheManager redisCacheManager;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private IIotCmdtaskService iIotCmdtaskService;
|
|
|
|
|
+
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private IIotDeviceconfigService iIotDeviceconfigService;
|
|
|
|
|
+
|
|
|
|
|
+ public Class getTableClass(String devtypeBid) {
|
|
|
|
|
+ Class tableClass = null;
|
|
|
|
|
+ switch (devtypeBid){
|
|
|
|
|
+ case IotDeviceDictConst.TYPE_YF_QXZ:
|
|
|
|
|
+ case IotDeviceDictConst.TYPE_YF_SQZ:
|
|
|
|
|
+ tableClass = IotYfqxzdata.class;
|
|
|
|
|
+ break;
|
|
|
|
|
+ case IotDeviceDictConst.TYPE_XPH_YF_QXZ:
|
|
|
|
|
+ case IotDeviceDictConst.TYPE_XPH_YF_SQZ:
|
|
|
|
|
+ tableClass = IotXphYfqxzdata.class;
|
|
|
|
|
+ break;
|
|
|
|
|
+ default:
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ return tableClass;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取数据列表接口
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param reqVo
|
|
|
|
|
+ * @param isNow
|
|
|
|
|
+ * @param isDisable
|
|
|
|
|
+ */
|
|
|
|
|
+ public TableDataInfo dataList(IotDeviceQxzDataListReqVo reqVo, boolean isNow, boolean isDisable) throws ParseException {
|
|
|
|
|
+ TableDataInfo rspData = new TableDataInfo();
|
|
|
|
|
+ rspData.setCode(ErrorCode.SUCCESS.getCode());
|
|
|
|
|
+ rspData.setMsg(ErrorCode.SUCCESS.getMessage());
|
|
|
|
|
+ rspData.setData(new ArrayList<>());
|
|
|
|
|
+ rspData.setTotal(0);
|
|
|
|
|
+
|
|
|
|
|
+ IotDevice findDevice = iotDeviceService.selectIotDeviceByDevBid(reqVo.getDevBid());
|
|
|
|
|
+
|
|
|
|
|
+ String devBid = findDevice.getDevBid();
|
|
|
|
|
+ Criteria criteria = new Criteria().and("devBid").is(devBid);
|
|
|
|
|
+ if(isNow){
|
|
|
|
|
+ Date startDate = null;
|
|
|
|
|
+ Date endDate = null;
|
|
|
|
|
+ try{
|
|
|
|
|
+ startDate = DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS, reqVo.getStartTime());
|
|
|
|
|
+ endDate = DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS, reqVo.getEndTime());
|
|
|
|
|
+ }catch (Exception e){
|
|
|
|
|
+ log.error("时间格式错误", e);
|
|
|
|
|
+ throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(), "请输入正确的起止时间");
|
|
|
|
|
+ }
|
|
|
|
|
+ criteria = criteria.andOperator(
|
|
|
|
|
+ Criteria.where("time").gte(startDate),
|
|
|
|
|
+ Criteria.where("time").lte(endDate)
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ MatchOperation matchOperation = Aggregation.match(criteria);
|
|
|
|
|
+
|
|
|
|
|
+ GroupOperation groupOperation = Aggregation.group("time")
|
|
|
|
|
+ .push("$$ROOT").as("data");
|
|
|
|
|
+
|
|
|
|
|
+ ProjectionOperation projectionOperationResult = Aggregation.project("_id")
|
|
|
|
|
+ .and("_id").as("time")
|
|
|
|
|
+ .and("data").as("dataList");
|
|
|
|
|
+
|
|
|
|
|
+ SortOperation sortOperation = Aggregation.sort(Sort.Direction.DESC, "time");
|
|
|
|
|
+
|
|
|
|
|
+ Aggregation aggregation = Aggregation.newAggregation(
|
|
|
|
|
+ matchOperation,
|
|
|
|
|
+ groupOperation,
|
|
|
|
|
+ projectionOperationResult,
|
|
|
|
|
+ sortOperation
|
|
|
|
|
+ );
|
|
|
|
|
+ Class tableClass = getTableClass(findDevice.getDevtypeBid());
|
|
|
|
|
+ if(tableClass == null){
|
|
|
|
|
+ throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(), "设备类型不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ PageDomain pageDomain = TableSupport.buildPageRequest();
|
|
|
|
|
+ IPage<QxzDataListDto> qxzDataListDtoIPage = mongoService.aggregate(tableClass, aggregation, QxzDataListDto.class, pageDomain);
|
|
|
|
|
+ //查出该设备的“自定义要素信息列表”
|
|
|
|
|
+ IotDevicefactor param = new IotDevicefactor();
|
|
|
|
|
+ param.setDevBid(devBid);
|
|
|
|
|
+ List<IotDevicefactor> factorList = iotDevicefactorService.selectIotDevicefactorList(param);
|
|
|
|
|
+
|
|
|
|
|
+ List<List<IotQxzDataListRseVo>> rest = new ArrayList<>();
|
|
|
|
|
+ for(QxzDataListDto item: qxzDataListDtoIPage.getRecords()){
|
|
|
|
|
+ List<QxzDataDto> dataList = item.getDataList();
|
|
|
|
|
+ List<IotQxzDataListRseVo> iotQxzDataListRseVoList = ElementFactorUtil.qxzListProcessData(dataList, factorList, findDevice, isDisable);
|
|
|
|
|
+ rest.add(iotQxzDataListRseVoList);
|
|
|
|
|
+ }
|
|
|
|
|
+ rspData.setData(rest);
|
|
|
|
|
+ rspData.setTotal(qxzDataListDtoIPage.getTotal());
|
|
|
|
|
+ return rspData;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public TableDataInfo dataList(IotDeviceQxzDataListReqVo reqVo) throws ParseException {
|
|
|
|
|
+ return dataList(reqVo, true, false);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取折线图数据列表接口
|
|
|
|
|
+ * @param reqVo
|
|
|
|
|
+ */
|
|
|
|
|
+ public List<IotQxzDataListRseVo> chartList(IotDeviceQxzDataListReqVo reqVo) throws ParseException {
|
|
|
|
|
+
|
|
|
|
|
+ //1、查出总条数 2、查出“符合条件的、当前页的”数据 3、json结构重组(如果需要的话) 4、附加 要素自定义 信息
|
|
|
|
|
+
|
|
|
|
|
+ String devBid = reqVo.getDevBid();
|
|
|
|
|
+ if(StringUtils.isEmpty(devBid)){
|
|
|
|
|
+ throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "设备标识不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ IotDevice findDevice = iotDeviceService.selectIotDeviceByDevBid(reqVo.getDevBid());
|
|
|
|
|
+
|
|
|
|
|
+ String startDate = reqVo.getStartTime();
|
|
|
|
|
+ String endDate = reqVo.getEndTime();
|
|
|
|
|
+ String unit = "day";
|
|
|
|
|
+
|
|
|
|
|
+ Criteria criteria = new Criteria().and("devBid").is(devBid);
|
|
|
|
|
+
|
|
|
|
|
+ //必须设置起止时间
|
|
|
|
|
+ if(StringUtils.isNotEmpty(startDate) && StringUtils.isNotEmpty(endDate)){
|
|
|
|
|
+ //限制 起止时间
|
|
|
|
|
+ criteria = criteria.andOperator(
|
|
|
|
|
+ Criteria.where("time").gte(DateUtils.parseDate(startDate)),
|
|
|
|
|
+ Criteria.where("time").lte(DateUtils.parseDate(endDate))
|
|
|
|
|
+ );
|
|
|
|
|
+ //选择 数据粒度
|
|
|
|
|
+ unit = MongoUtil.getDateTruncUnit(startDate, endDate);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ MatchOperation matchOperation = Aggregation.match(criteria);
|
|
|
|
|
+
|
|
|
|
|
+ ProjectionOperation projectionOperation = Aggregation.project()
|
|
|
|
|
+ .and("eName").as("eName")
|
|
|
|
|
+ .and("eNum").as("eNum")
|
|
|
|
|
+ .and("eKey").as("eKey")
|
|
|
|
|
+ .andExpression("{$convert: {input: '$eValue', to: 'double', onError: -99, onNull: -99}}").as("eValue")
|
|
|
|
|
+ .andExpression("{$dateTrunc: {date: {$toDate: '$time'}, unit:'" + unit + "'}}").as("time");
|
|
|
|
|
+
|
|
|
|
|
+ GroupOperation groupOperation = Aggregation.group("eName", "eNum", "eKey")
|
|
|
|
|
+ .push("$$ROOT").as("data");
|
|
|
|
|
+
|
|
|
|
|
+ UnwindOperation unwindOperation = Aggregation.unwind("$data");
|
|
|
|
|
+ GroupOperation groupOperation2 = Aggregation.group("data.eName", "data.eNum", "data.eKey", "data.time")
|
|
|
|
|
+ .avg("data.eValue").as("eValue");
|
|
|
|
|
+
|
|
|
|
|
+ SortOperation sortOperation = Aggregation.sort(Sort.Direction.ASC, "_id.time");
|
|
|
|
|
+ JSONArray roundArray = new JSONArray();
|
|
|
|
|
+ roundArray.add("$eValue");
|
|
|
|
|
+ roundArray.add(2);
|
|
|
|
|
+ Map<String, Object> roundMap = new HashMap<>();
|
|
|
|
|
+ roundMap.put("$round", roundArray);
|
|
|
|
|
+ Map<String, Object> pushMapStr = new HashMap<>();
|
|
|
|
|
+ pushMapStr.put("$toString", roundMap);
|
|
|
|
|
+
|
|
|
|
|
+ Map<String, Object> pushMap = new HashMap<>();
|
|
|
|
|
+ pushMap.put("number", pushMapStr);
|
|
|
|
|
+ pushMap.put("time", "$_id.time");
|
|
|
|
|
+
|
|
|
|
|
+ GroupOperation groupOperation3 = Aggregation.group("_id.eName", "_id.eNum", "_id.eKey")
|
|
|
|
|
+ .push(pushMap).as("dataList");
|
|
|
|
|
+
|
|
|
|
|
+ ProjectionOperation projectionOperation2 = Aggregation.project()
|
|
|
|
|
+ .and("eName").as("eName")
|
|
|
|
|
+ .and("eNum").as("eNum")
|
|
|
|
|
+ .and("eKey").as("eKey")
|
|
|
|
|
+ .and("dataList").as("dataList");
|
|
|
|
|
+ SortOperation sortOperation2 = Aggregation.sort(Sort.Direction.ASC, "eKey");
|
|
|
|
|
+
|
|
|
|
|
+ Aggregation aggregation = Aggregation.newAggregation(
|
|
|
|
|
+ matchOperation,
|
|
|
|
|
+ projectionOperation,
|
|
|
|
|
+ groupOperation,
|
|
|
|
|
+ unwindOperation,
|
|
|
|
|
+ groupOperation2,
|
|
|
|
|
+ sortOperation,
|
|
|
|
|
+ groupOperation3,
|
|
|
|
|
+ projectionOperation2,
|
|
|
|
|
+ sortOperation2
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ Class tableClass = getTableClass(findDevice.getDevtypeBid());
|
|
|
|
|
+ if(tableClass == null){
|
|
|
|
|
+ throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(), "设备类型不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ List<QxzDataDto> dataList = mongoService.aggregate(tableClass, aggregation, QxzDataDto.class);
|
|
|
|
|
+
|
|
|
|
|
+ //查出该设备的“自定义要素信息列表”
|
|
|
|
|
+ IotDevicefactor param = new IotDevicefactor();
|
|
|
|
|
+ param.setDevBid(devBid);
|
|
|
|
|
+ List<IotDevicefactor> factorList = iotDevicefactorService.selectIotDevicefactorList(param);
|
|
|
|
|
+ List<IotQxzDataListRseVo> iotQxzDataListRseVoList = ElementFactorUtil.qxzChartProcessData(dataList, factorList, findDevice, false);
|
|
|
|
|
+ return iotQxzDataListRseVoList;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取24小时数据列表接口
|
|
|
|
|
+ * @param reqVo
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ public List<IotQxzDataListRseVo> dataList24h(IotDeviceQxzDataListReqVo reqVo){
|
|
|
|
|
+ String devBid = reqVo.getDevBid();
|
|
|
|
|
+ long endTime = DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS, DateUtils.dateNow()).getTime();
|
|
|
|
|
+ long begintime = endTime-86400000;
|
|
|
|
|
+
|
|
|
|
|
+ IotDevice findDevice = iotDeviceService.selectIotDeviceByDevBid(reqVo.getDevBid());
|
|
|
|
|
+
|
|
|
|
|
+ Criteria criteria = new Criteria().and("devBid").is(devBid);
|
|
|
|
|
+ criteria = criteria.andOperator(
|
|
|
|
|
+ Criteria.where("time").gte(new Date(begintime)),
|
|
|
|
|
+ Criteria.where("time").lte(new Date(endTime))
|
|
|
|
|
+ );
|
|
|
|
|
+ MatchOperation matchOperation = Aggregation.match(criteria);
|
|
|
|
|
+ AddFieldsOperation addFieldsOperation = Aggregation.addFields()
|
|
|
|
|
+ .addField("eValueNum")
|
|
|
|
|
+ .withValueOfExpression("{$convert: {input: '$eValue', to: 'double', onError: -99, onNull: -99}}")
|
|
|
|
|
+ .build();
|
|
|
|
|
+
|
|
|
|
|
+ SortOperation sortOperation = Aggregation.sort(Sort.Direction.ASC, "eValueNum");
|
|
|
|
|
+
|
|
|
|
|
+ GroupOperation groupOperation = Aggregation.group("eNum", "eName", "eKey")
|
|
|
|
|
+ .push("$$ROOT").as("data");
|
|
|
|
|
+ SortOperation sortOperation2 = Aggregation.sort(Sort.Direction.ASC, "data.eValueNum")
|
|
|
|
|
+ .and(Sort.Direction.ASC, "data.time");
|
|
|
|
|
+
|
|
|
|
|
+ ProjectionOperation projectionOperationResult = Aggregation.project("_id")
|
|
|
|
|
+ .and("_id").as("elem")
|
|
|
|
|
+ .andExpression("{$last: '$data'}").as("max_data")
|
|
|
|
|
+ .andExpression("{$first: '$data'}").as("min_data");
|
|
|
|
|
+
|
|
|
|
|
+ ProjectionOperation projectionOperationResult2 = Aggregation.project("_id")
|
|
|
|
|
+ .and("elem").as("elem")
|
|
|
|
|
+ .and("elem.eNum").as("eNum")
|
|
|
|
|
+ .and("elem.eName").as("eName")
|
|
|
|
|
+ .and("elem.eKey").as("eKey")
|
|
|
|
|
+ .and("max_data.eValue").as("maxVal")
|
|
|
|
|
+ .and("max_data.time").as("maxValdate")
|
|
|
|
|
+ .and("min_data.eValue").as("minVal")
|
|
|
|
|
+ .and("min_data.time").as("minValdate");
|
|
|
|
|
+
|
|
|
|
|
+ SortOperation sortOperation3 = Aggregation.sort(Sort.Direction.ASC, "eNum")
|
|
|
|
|
+ .and(Sort.Direction.ASC, "eName")
|
|
|
|
|
+ .and(Sort.Direction.ASC, "eKey");
|
|
|
|
|
+
|
|
|
|
|
+ Aggregation aggregation = Aggregation.newAggregation(
|
|
|
|
|
+ matchOperation,
|
|
|
|
|
+ addFieldsOperation,
|
|
|
|
|
+ sortOperation,
|
|
|
|
|
+ groupOperation,
|
|
|
|
|
+ sortOperation2,
|
|
|
|
|
+ projectionOperationResult,
|
|
|
|
|
+ projectionOperationResult2,
|
|
|
|
|
+ sortOperation3
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ Class tableClass = getTableClass(findDevice.getDevtypeBid());
|
|
|
|
|
+ if(tableClass == null){
|
|
|
|
|
+ throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(), "设备类型不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ List<QxzDataLast24hDto> qxzDataLast24hDtoList = mongoService.aggregate(tableClass, aggregation, QxzDataLast24hDto.class);
|
|
|
|
|
+ //查出该设备的“自定义要素信息列表”
|
|
|
|
|
+ IotDevicefactor param = new IotDevicefactor();
|
|
|
|
|
+ param.setDevBid(devBid);
|
|
|
|
|
+ List<IotDevicefactor> factorList = iotDevicefactorService.selectIotDevicefactorList(param);
|
|
|
|
|
+ Map<String, QxzDataLast24hDto> iotXphLast24hDtoMap = new HashMap<>();
|
|
|
|
|
+ List<QxzDataDto> dataList = new ArrayList<>();
|
|
|
|
|
+ for(QxzDataLast24hDto item: qxzDataLast24hDtoList){
|
|
|
|
|
+ String key = ElementFactorUtil.getAddress(item.getEName(), item.getEKey());
|
|
|
|
|
+ iotXphLast24hDtoMap.put(key, item);
|
|
|
|
|
+ QxzDataDto dto = new QxzDataDto();
|
|
|
|
|
+ BeanUtils.copyProperties(item, dto);
|
|
|
|
|
+ dataList.add(dto);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ List<IotQxzDataListRseVo> iotQxzDataListRseVoList = ElementFactorUtil.qxzListProcessData(dataList, factorList, findDevice, false);
|
|
|
|
|
+ for(IotQxzDataListRseVo item: iotQxzDataListRseVoList){
|
|
|
|
|
+ QxzDataLast24hDto qxzDataLast24hDto = iotXphLast24hDtoMap.get(item.getAddress());
|
|
|
|
|
+ item.setMinVal(qxzDataLast24hDto.getMinVal());
|
|
|
|
|
+ item.setMinValdate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, qxzDataLast24hDto.getMinValdate()));
|
|
|
|
|
+ item.setMaxVal(qxzDataLast24hDto.getMaxVal());
|
|
|
|
|
+ item.setMaxValdate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, qxzDataLast24hDto.getMaxValdate()));
|
|
|
|
|
+ }
|
|
|
|
|
+ return iotQxzDataListRseVoList;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取最近数据列表接口
|
|
|
|
|
+ * @param reqVo
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ public IotDevicelasteddata dataLatest(IotDeviceQxzDataListReqVo reqVo) throws ParseException {
|
|
|
|
|
+ String devBid = reqVo.getDevBid();
|
|
|
|
|
+
|
|
|
|
|
+ IotDevice findDevice = iotDeviceService.selectIotDeviceByDevBid(reqVo.getDevBid());
|
|
|
|
|
+ TableDataInfo tableDataInfo = dataList(reqVo, false, true);
|
|
|
|
|
+ List<List<IotQxzDataListRseVo>> rest = (List<List<IotQxzDataListRseVo>>) tableDataInfo.getData();
|
|
|
|
|
+ if(rest == null || rest.isEmpty()){
|
|
|
|
|
+ log.info("devBid:{},【最近数据】empty",devBid);
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ List<IotQxzDataListRseVo> iotQxzDataListRseVoList = rest.get(0);
|
|
|
|
|
+ IotQxzDataListRseVo iotQxzDataListRseVo = iotQxzDataListRseVoList.get(0);
|
|
|
|
|
+ IotDevicelasteddata latestData = new IotDevicelasteddata();
|
|
|
|
|
+ BeanUtils.copyProperties(findDevice, latestData);
|
|
|
|
|
+ latestData.setDevldCreateddate(iotQxzDataListRseVo.getTime());
|
|
|
|
|
+ latestData.setDevldUpdateddate(iotQxzDataListRseVo.getTime());
|
|
|
|
|
+ latestData.setDevldContent(JSONArray.toJSONString(iotQxzDataListRseVoList));
|
|
|
|
|
+ return latestData;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void refresh(DeviceRefreshDto reqVo) {
|
|
|
|
|
+ IotDevice findDevice = reqVo.getIotDevice();
|
|
|
|
|
+ String devBid = findDevice.getDevBid();
|
|
|
|
|
+ log.info("创建【“刷新”指令集任务】,设备类型:{}", findDevice.getDevtypeName());
|
|
|
|
|
+ JSONObject ext = new JSONObject();
|
|
|
|
|
+ ext.put("type", "data");
|
|
|
|
|
+ JSONObject payload = new JSONObject();
|
|
|
|
|
+ payload.put("cmd", "read");
|
|
|
|
|
+ payload.put("ext", ext);
|
|
|
|
|
+ IotDeviceconfig iotDeviceconfig = new IotDeviceconfig();
|
|
|
|
|
+ iotDeviceconfig.setTid(findDevice.getTid());
|
|
|
|
|
+ iotDeviceconfig.setDevBid(devBid);
|
|
|
|
|
+ iotDeviceconfig.setDevcfgContext(JSONUtils.toJSONString(payload));
|
|
|
|
|
+
|
|
|
|
|
+ CmdGroupModel cmdGroupModel = iIotDeviceconfigService.createRefreshCmd(iotDeviceconfig);
|
|
|
|
|
+
|
|
|
|
|
+ // 构建日志需要用的内容
|
|
|
|
|
+ cmdGroupModel.setRequestId(IdUtils.fastUUID());
|
|
|
|
|
+ cmdGroupModel.setDevCode(findDevice.getDevCode());
|
|
|
|
|
+ cmdGroupModel.setCtBiztype("3");
|
|
|
|
|
+ cmdGroupModel.setCtDevtype(findDevice.getDevtypeBid());
|
|
|
|
|
+ cmdGroupModel.setCtBiztitle(findDevice.getDevtypeName() + ":" + findDevice.getDevCode());
|
|
|
|
|
+ cmdGroupModel.setCtParam("设备id:"+devBid);
|
|
|
|
|
+ iIotCmdtaskService.handInternalCmd(cmdGroupModel);
|
|
|
|
|
+ String taskUuid = cmdGroupModel.getTaskUuid();
|
|
|
|
|
+ log.info("【“刷新”指令集任务】创建成功,taskUuid:{}", taskUuid);
|
|
|
|
|
+ }
|
|
|
|
|
+}
|