|
@@ -0,0 +1,444 @@
|
|
|
|
|
+package com.yunfeiyun.agmp.iotm.device.scd.service.impl;
|
|
|
|
|
+
|
|
|
|
|
+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.log.LogCore;
|
|
|
|
|
+import com.yunfeiyun.agmp.common.utils.JSONUtils;
|
|
|
|
|
+import com.yunfeiyun.agmp.common.utils.StringUtils;
|
|
|
|
|
+import com.yunfeiyun.agmp.common.utils.poi.ExcelUtil;
|
|
|
|
|
+import com.yunfeiyun.agmp.common.utils.uuid.IdUtils;
|
|
|
|
|
+import com.yunfeiyun.agmp.iot.common.constant.IotErrorCode;
|
|
|
|
|
+import com.yunfeiyun.agmp.iot.common.constant.devicetype.IotDeviceDictConst;
|
|
|
|
|
+import com.yunfeiyun.agmp.iot.common.constant.devicetype.ServiceNameConst;
|
|
|
|
|
+import com.yunfeiyun.agmp.iot.common.domain.IotDevice;
|
|
|
|
|
+import com.yunfeiyun.agmp.iot.common.domain.IotDeviceconfig;
|
|
|
|
|
+import com.yunfeiyun.agmp.iot.common.domain.IotYfScddata;
|
|
|
|
|
+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.domin.IotDeviceDataListReqVo;
|
|
|
|
|
+import com.yunfeiyun.agmp.iotm.device.common.domin.IotDeviceExportReqVo;
|
|
|
|
|
+import com.yunfeiyun.agmp.iotm.device.scd.domain.*;
|
|
|
|
|
+import com.yunfeiyun.agmp.iotm.device.scd.service.IIotScdCommService;
|
|
|
|
|
+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 lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+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 org.springframework.stereotype.Service;
|
|
|
|
|
+
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
+
|
|
|
|
|
+@Service(value = ServiceNameConst.SERVICE_YF_SCD)
|
|
|
|
|
+@Slf4j
|
|
|
|
|
+public class IotYfScdServiceImpl extends IIotScdCommService {
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private IIotDeviceService iotDeviceService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private MongoService mongoService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private IIotCmdtaskService iIotCmdtaskService;
|
|
|
|
|
+
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private IIotDeviceconfigService iIotDeviceconfigService;
|
|
|
|
|
+
|
|
|
|
|
+ public TableDataInfo dataList(IotDeviceDataListReqVo reqVo) {
|
|
|
|
|
+ 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());
|
|
|
|
|
+ if (findDevice == null) {
|
|
|
|
|
+ throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(), "设备不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ String startTime = reqVo.getStartTime();
|
|
|
|
|
+ String endTime = reqVo.getEndTime();
|
|
|
|
|
+ if (startTime == null || endTime == null) {
|
|
|
|
|
+ throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(), "请输入正确的起止时间");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Map<String, Object> cases = new HashMap<>();
|
|
|
|
|
+ cases.put("devBid", reqVo.getDevBid());
|
|
|
|
|
+ cases.put("time_scddataCreatedDate", startTime + "," + endTime);
|
|
|
|
|
+
|
|
|
|
|
+ PageDomain pageDomain = TableSupport.buildPageRequest();
|
|
|
|
|
+ pageDomain.setIsAsc("desc");
|
|
|
|
|
+ pageDomain.setOrderByColumn("scddataCreatedDate");
|
|
|
|
|
+ IPage<IotYfScddata> iotYfScddataIPage = mongoService.findListPage(IotYfScddata.class, cases, pageDomain);
|
|
|
|
|
+ rspData.setData(iotYfScddataIPage.getRecords());
|
|
|
|
|
+ rspData.setTotal(iotYfScddataIPage.getTotal());
|
|
|
|
|
+ return rspData;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取折线图数据列表接口
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param reqVo
|
|
|
|
|
+ */
|
|
|
|
|
+ public List<IotYfScdPolylineResVo> chartList(IotDeviceDataListReqVo reqVo) {
|
|
|
|
|
+ String devBid = reqVo.getDevBid();
|
|
|
|
|
+ if (StringUtils.isEmpty(devBid)) {
|
|
|
|
|
+ throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "设备标识不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ String startDate = reqVo.getStartTime();
|
|
|
|
|
+ String endDate = reqVo.getEndTime();
|
|
|
|
|
+ if (StringUtils.isEmpty(startDate) && StringUtils.isEmpty(endDate)) {
|
|
|
|
|
+ throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(), "请输入正确的起止时间");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ String unit = MongoUtil.getDateTruncUnit(startDate, endDate);
|
|
|
|
|
+ Criteria criteria = new Criteria().and("devBid").is(devBid);
|
|
|
|
|
+ criteria = criteria.andOperator(
|
|
|
|
|
+ Criteria.where("scddataCreatedDate").gte(startDate),
|
|
|
|
|
+ Criteria.where("scddataCreatedDate").lte(endDate)
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * $mtch {"devBid": devBid, "$add": [{"scddataCreatedDate": {"$gte": startDate}}, {"scddataCreatedDate": {"$lte": endDate}}]}
|
|
|
|
|
+ */
|
|
|
|
|
+ MatchOperation matchOperation = Aggregation.match(criteria);
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * $project
|
|
|
|
|
+ * {
|
|
|
|
|
+ * "ah": "$scddataContent.ah",
|
|
|
|
|
+ * "createDate": "$scddataCreatedDate"
|
|
|
|
|
+ * }
|
|
|
|
|
+ */
|
|
|
|
|
+ ProjectionOperation projectionOperation = Aggregation.project()
|
|
|
|
|
+ .and("scddataContent.ah").as("ah")
|
|
|
|
|
+ .and("scddataContent.at").as("at")
|
|
|
|
|
+ .and("scddataContent.bv").as("bv")
|
|
|
|
|
+ .and("scddataContent.cv").as("cv")
|
|
|
|
|
+ .and("scddataContent.ct").as("ct")
|
|
|
|
|
+ .and("scddataCreatedDate").as("createDate");
|
|
|
|
|
+ /**
|
|
|
|
|
+ * $project
|
|
|
|
|
+ * {
|
|
|
|
|
+ * "at": {$convert: {input: '$at', to: 'double', onError: -99, onNull: -99}},
|
|
|
|
|
+ * "createDate": {$dateTrunc: {date: {$toDate: '$createDate'}, unit: 'minute'}}
|
|
|
|
|
+ * }
|
|
|
|
|
+ */
|
|
|
|
|
+
|
|
|
|
|
+ ProjectionOperation projectionOperation2 = Aggregation.project()
|
|
|
|
|
+ .andExpression("{$convert: {input: '$ct', to: 'int', onError: -99, onNull: -99}}").as("ct")
|
|
|
|
|
+ .andExpression("{$convert: {input: '$at', to: 'double', onError: -99, onNull: -99}}").as("at")
|
|
|
|
|
+ .andExpression("{$convert: {input: '$ah', to: 'double', onError: -99, onNull: -99}}").as("ah")
|
|
|
|
|
+ .andExpression("{$convert: {input: '$bv', to: 'double', onError: -99, onNull: -99}}").as("bv")
|
|
|
|
|
+ .andExpression("{$convert: {input: '$cv', to: 'double', onError: -99, onNull: -99}}").as("cv")
|
|
|
|
|
+ .andExpression("{$dateTrunc: {date: {$toDate: '$createDate'}, unit:'" + unit + "'}}").as("createDate");
|
|
|
|
|
+
|
|
|
|
|
+ Criteria criteria2 = new Criteria()
|
|
|
|
|
+ .and("at").gt(-99)
|
|
|
|
|
+ .and("ah").gt(-99)
|
|
|
|
|
+ .and("bv").gt(-99)
|
|
|
|
|
+ .and("cv").gt(-99)
|
|
|
|
|
+ .and("ct").gt(-99);
|
|
|
|
|
+ MatchOperation matchOperation2 = Aggregation.match(criteria2);
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * {
|
|
|
|
|
+ * "$group" : {
|
|
|
|
|
+ * "_id" : "$createDate", "ah" : { "$avg" : "$ah"}, "at" : { "$avg" : "$at"}, "bv" : { "$avg" : "$bv"}, "cv" : { "$avg" : "$cv"}, "ct" : { "$sum" : "$ct"}
|
|
|
|
|
+ * }
|
|
|
|
|
+ * }
|
|
|
|
|
+ */
|
|
|
|
|
+ GroupOperation groupOperation = Aggregation.group("createDate")
|
|
|
|
|
+ .avg("ah").as("ah")
|
|
|
|
|
+ .avg("at").as("at")
|
|
|
|
|
+ .avg("bv").as("bv")
|
|
|
|
|
+ .avg("cv").as("cv")
|
|
|
|
|
+ .sum("ct").as("ct");
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * { "$project" : { "ct" : 1, "bv" : { "$trunc" : ["$bv", 3]}, "createDate" : { "$dateToString" : { "format" : "%Y-%m-%d %H:%M:%S", "date" : "$_id"}}}}
|
|
|
|
|
+ */
|
|
|
|
|
+ ProjectionOperation projectionOperation3 = Aggregation.project("ct")
|
|
|
|
|
+ .andExpression("{$trunc: {'$bv', 3}}").as("bv")
|
|
|
|
|
+ .andExpression("{$trunc: {'$cv', 3}}").as("cv")
|
|
|
|
|
+ .andExpression("{$trunc: {'$ah', 1}}").as("ah")
|
|
|
|
|
+ .andExpression("{$trunc: {'$at', 1}}").as("at")
|
|
|
|
|
+ .andExpression("{$dateToString: {format: '%Y-%m-%d %H:%M:%S', date: '$_id'}}").as("createDate");
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * { "$sort" : { "createDate" : 1}}
|
|
|
|
|
+ */
|
|
|
|
|
+ SortOperation sortOperation = Aggregation.sort(Sort.Direction.ASC, "createDate");
|
|
|
|
|
+
|
|
|
|
|
+ Aggregation aggregation = Aggregation.newAggregation(
|
|
|
|
|
+ matchOperation,
|
|
|
|
|
+ projectionOperation,
|
|
|
|
|
+ projectionOperation2,
|
|
|
|
|
+ matchOperation2,
|
|
|
|
|
+ groupOperation,
|
|
|
|
|
+ projectionOperation3,
|
|
|
|
|
+ sortOperation
|
|
|
|
|
+ );
|
|
|
|
|
+ List<IotYfScdPolylineResVo> iotYfScdPolylineResVoList = mongoService.aggregate(
|
|
|
|
|
+ IotYfScddata.class, aggregation, IotYfScdPolylineResVo.class
|
|
|
|
|
+ );
|
|
|
|
|
+ return iotYfScdPolylineResVoList;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 刷新指令集
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param reqVo
|
|
|
|
|
+ */
|
|
|
|
|
+ public void refresh(DeviceRefreshDto reqVo) {
|
|
|
|
|
+
|
|
|
|
|
+ IotDevice findDevice = reqVo.getIotDevice();
|
|
|
|
|
+ String devBid = findDevice.getDevBid();
|
|
|
|
|
+ log.info("创建【“刷新”指令集任务】,设备类型:{}", findDevice.getDevtypeName());
|
|
|
|
|
+ JSONObject payload = new JSONObject();
|
|
|
|
|
+ payload.put("cmd", "read");
|
|
|
|
|
+ payload.put("ext", "data");
|
|
|
|
|
+ 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);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 数据导出列表
|
|
|
|
|
+ */
|
|
|
|
|
+ public List<IotYfScddata> getExportDataList(IotDeviceDataListReqVo reqVo) {
|
|
|
|
|
+ String startTime = reqVo.getStartTime();
|
|
|
|
|
+ String endTime = reqVo.getEndTime();
|
|
|
|
|
+
|
|
|
|
|
+ Map<String, Object> mapParam = new HashMap<>();
|
|
|
|
|
+ mapParam.put("devBid", reqVo.getDevBid());
|
|
|
|
|
+ mapParam.put("time_scddataCreatedDate", startTime + "," + endTime);
|
|
|
|
|
+ List<IotYfScddata> iotYfScddataList = mongoService.findAll(IotYfScddata.class, mapParam, "scddataCreatedDate desc");
|
|
|
|
|
+ return iotYfScddataList;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 数据导出
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param iotDeviceExportReqVo
|
|
|
|
|
+ */
|
|
|
|
|
+ public void dataExport(IotDeviceExportReqVo iotDeviceExportReqVo) {
|
|
|
|
|
+ HttpServletResponse response = iotDeviceExportReqVo.getResponse();
|
|
|
|
|
+ IotDeviceDataListReqVo reqVo = iotDeviceExportReqVo.getReqVo();
|
|
|
|
|
+
|
|
|
|
|
+ String devBid = reqVo.getDevBid();
|
|
|
|
|
+ String startTime = reqVo.getStartTime();
|
|
|
|
|
+ String endTime = reqVo.getEndTime();
|
|
|
|
|
+ String[] params = {devBid, startTime, endTime};
|
|
|
|
|
+ for (String k : params) {
|
|
|
|
|
+ if (StringUtils.isEmpty(k)) {
|
|
|
|
|
+ throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(), "参数不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ IotDeviceDataListReqVo iotDeviceDataListReqVo = new IotDeviceDataListReqVo();
|
|
|
|
|
+ iotDeviceDataListReqVo.setDevBid(devBid);
|
|
|
|
|
+ iotDeviceDataListReqVo.setStartTime(startTime);
|
|
|
|
|
+ iotDeviceDataListReqVo.setEndTime(endTime);
|
|
|
|
|
+
|
|
|
|
|
+ IotDevice findDevice = iotDeviceService.selectIotDeviceByDevBid(reqVo.getDevBid());
|
|
|
|
|
+ if (findDevice == null) {
|
|
|
|
|
+ throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(), "设备不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ List<IotYfScddata> iotYfScddataList = getExportDataList(iotDeviceDataListReqVo);
|
|
|
|
|
+ if (Objects.equals(findDevice.getDevtypeBid(), IotDeviceDictConst.TYPE_YF_SCD)) {
|
|
|
|
|
+ List<IotYfScdDataExportVo> exportVoList = new ArrayList<>();
|
|
|
|
|
+ for (IotYfScddata iotYfScddata : iotYfScddataList) {
|
|
|
|
|
+ JSONObject jsonObject = iotYfScddata.getScddataContent();
|
|
|
|
|
+ IotYfScdDataExportVo exportVo = new IotYfScdDataExportVo();
|
|
|
|
|
+ exportVo.setDevCode(findDevice.getDevCode());
|
|
|
|
|
+ exportVo.setDevTypeName(findDevice.getDevtypeName());
|
|
|
|
|
+ exportVo.setElectricCount(jsonObject.getString("ct"));
|
|
|
|
|
+ exportVo.setRainStatus(jsonObject.getString("rps"));
|
|
|
|
|
+ exportVo.setSunStatus(jsonObject.getString("lps"));
|
|
|
|
|
+ exportVo.setTempStatus(jsonObject.getString("tps"));
|
|
|
|
|
+ exportVo.setTippingStatus(jsonObject.getString("dps"));
|
|
|
|
|
+ exportVo.setWorkStatus(jsonObject.getString("ws"));
|
|
|
|
|
+ exportVo.setScddataCreatedDate(iotYfScddata.getScddataCreatedDate());
|
|
|
|
|
+ exportVoList.add(exportVo);
|
|
|
|
|
+ }
|
|
|
|
|
+ //初始化 表头,需要附加 最近数据 中的要素名称
|
|
|
|
|
+
|
|
|
|
|
+ ExcelUtil<IotYfScdDataExportVo> util = new ExcelUtil<>(IotYfScdDataExportVo.class);
|
|
|
|
|
+ util.exportExcel(response, exportVoList, "设备数据");
|
|
|
|
|
+ } else {
|
|
|
|
|
+ List<IotYfFxsScdDataExportVo> exportVoList = new ArrayList<>();
|
|
|
|
|
+ for (IotYfScddata iotYfScddata : iotYfScddataList) {
|
|
|
|
|
+ JSONObject jsonObject = iotYfScddata.getScddataContent();
|
|
|
|
|
+ IotYfFxsScdDataExportVo exportVo = new IotYfFxsScdDataExportVo();
|
|
|
|
|
+ exportVo.setDevCode(findDevice.getDevCode());
|
|
|
|
|
+ exportVo.setDevTypeName(findDevice.getDevtypeName());
|
|
|
|
|
+ exportVo.setRainStatus(jsonObject.getString("rps"));
|
|
|
|
|
+ exportVo.setSunStatus(jsonObject.getString("lps"));
|
|
|
|
|
+ exportVo.setTempStatus(jsonObject.getString("tps"));
|
|
|
|
|
+ exportVo.setTippingStatus(jsonObject.getString("dps"));
|
|
|
|
|
+ exportVo.setWorkStatus(jsonObject.getString("ws"));
|
|
|
|
|
+ exportVo.setScddataCreatedDate(iotYfScddata.getScddataCreatedDate());
|
|
|
|
|
+ exportVoList.add(exportVo);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //初始化 表头,需要附加 最近数据 中的要素名称
|
|
|
|
|
+ ExcelUtil<IotYfFxsScdDataExportVo> util = new ExcelUtil<>(IotYfFxsScdDataExportVo.class);
|
|
|
|
|
+ util.exportExcel(response, exportVoList, "设备数据");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 状态导出
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param iotDeviceExportReqVo
|
|
|
|
|
+ */
|
|
|
|
|
+ public void statusExport(IotDeviceExportReqVo iotDeviceExportReqVo) {
|
|
|
|
|
+ HttpServletResponse response = iotDeviceExportReqVo.getResponse();
|
|
|
|
|
+ IotDeviceDataListReqVo reqVo = iotDeviceExportReqVo.getReqVo();
|
|
|
|
|
+
|
|
|
|
|
+ String devBid = reqVo.getDevBid();
|
|
|
|
|
+ String startTime = reqVo.getStartTime();
|
|
|
|
|
+ String endTime = reqVo.getEndTime();
|
|
|
|
|
+ String[] params = {devBid, startTime, endTime};
|
|
|
|
|
+ for (String k : params) {
|
|
|
|
|
+ if (StringUtils.isEmpty(k)) {
|
|
|
|
|
+ throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(), "参数不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ IotDeviceDataListReqVo iotDeviceDataListReqVo = new IotDeviceDataListReqVo();
|
|
|
|
|
+ iotDeviceDataListReqVo.setDevBid(devBid);
|
|
|
|
|
+ iotDeviceDataListReqVo.setStartTime(startTime);
|
|
|
|
|
+ iotDeviceDataListReqVo.setEndTime(endTime);
|
|
|
|
|
+
|
|
|
|
|
+ IotDevice findDevice = iotDeviceService.selectIotDeviceByDevBid(reqVo.getDevBid());
|
|
|
|
|
+ if (findDevice == null) {
|
|
|
|
|
+ throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(), "设备不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ List<IotYfScddata> iotYfScddataList = getExportDataList(iotDeviceDataListReqVo);
|
|
|
|
|
+ List<IotYfScdStatusExportVo> exportVoList = new ArrayList<>();
|
|
|
|
|
+ for (IotYfScddata iotYfScddata : iotYfScddataList) {
|
|
|
|
|
+ JSONObject jsonObject = iotYfScddata.getScddataContent();
|
|
|
|
|
+ IotYfScdStatusExportVo exportVo = new IotYfScdStatusExportVo();
|
|
|
|
|
+ exportVo.setDevCode(findDevice.getDevCode());
|
|
|
|
|
+ exportVo.setDevTypeName(findDevice.getDevtypeName());
|
|
|
|
|
+ exportVo.setAh(jsonObject.getString("ah"));
|
|
|
|
|
+ exportVo.setAt(jsonObject.getString("at"));
|
|
|
|
|
+ exportVo.setCv(jsonObject.getString("cv"));
|
|
|
|
|
+ exportVo.setBv(jsonObject.getString("bv"));
|
|
|
|
|
+ exportVo.setScddataCreatedDate(iotYfScddata.getScddataCreatedDate());
|
|
|
|
|
+ exportVoList.add(exportVo);
|
|
|
|
|
+ }
|
|
|
|
|
+ //初始化 表头,需要附加 最近数据 中的要素名称
|
|
|
|
|
+
|
|
|
|
|
+ ExcelUtil<IotYfScdStatusExportVo> util = new ExcelUtil<>(IotYfScdStatusExportVo.class);
|
|
|
|
|
+ util.exportExcel(response, exportVoList, "状态数据");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public JSONObject configInfo(IotDeviceDataListReqVo reqVo){
|
|
|
|
|
+ String devBid = reqVo.getDevBid();
|
|
|
|
|
+ if(StringUtils.isEmpty(devBid)){
|
|
|
|
|
+ throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(),"参数不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ IotDevice iotDevice = iotDeviceService.selectIotDeviceByDevBid(devBid);
|
|
|
|
|
+ if(iotDevice == null){
|
|
|
|
|
+ throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(),"设备不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ IotDeviceconfig iotDeviceconfig = iIotDeviceconfigService.selectIotDeviceConfigByDevBid(devBid);
|
|
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
|
|
+ if(iotDeviceconfig != null){
|
|
|
|
|
+ jsonObject = JSONObject.parseObject(iotDeviceconfig.getDevcfgContext());
|
|
|
|
|
+ }
|
|
|
|
|
+ return jsonObject;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public String sendConfigCmd(IotScdConfigEditReqVo reqVo){
|
|
|
|
|
+ IotDevice iotDevice = reqVo.getIotDevice();
|
|
|
|
|
+ String devBid = iotDevice.getDevBid();
|
|
|
|
|
+ IotScdConfig iotScdConfig = reqVo.getIotScdConfig();
|
|
|
|
|
+ if(iotScdConfig == null){
|
|
|
|
|
+ throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(),"参数不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ IotDeviceconfig iotDeviceconfig = iIotDeviceconfigService.selectIotDeviceConfigByDevBid(devBid);
|
|
|
|
|
+ if (null == iotDeviceconfig) {
|
|
|
|
|
+ // 如果测报灯配置为空,则新增测报灯配置
|
|
|
|
|
+ iotDeviceconfig = new IotDeviceconfig();
|
|
|
|
|
+ iotDeviceconfig.setDevcfgBid(iotDeviceconfig.getUUId());
|
|
|
|
|
+ iotDeviceconfig.setTid(iotDevice.getTid());
|
|
|
|
|
+ iotDeviceconfig.setDevBid(devBid);
|
|
|
|
|
+ iotDeviceconfig.setDevcfgContext(JSONUtils.toJSONString(iotScdConfig));
|
|
|
|
|
+ iotDeviceconfig.setDevcfgDelstatus("0");
|
|
|
|
|
+ iIotDeviceconfigService.insertIotDeviceconfig(iotDeviceconfig);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 如果测报灯配置不为空,则更新测报灯配置
|
|
|
|
|
+ iotDeviceconfig.setDevcfgContext(JSONUtils.toJSONString(iotScdConfig));
|
|
|
|
|
+ iIotDeviceconfigService.updateIotDeviceconfig(iotDeviceconfig);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ CmdGroupModel cmdGroupModel = iIotDeviceconfigService.createConfigCmd(iotDeviceconfig);
|
|
|
|
|
+ log.info("【{}】【杀虫灯 [下发配置]】【构建 cmdGroupModel】{}", LogCore.getSeq(), JSONUtils.toJSONString(cmdGroupModel));
|
|
|
|
|
+ cmdGroupModel.setRequestId(IdUtils.fastUUID());
|
|
|
|
|
+
|
|
|
|
|
+ // 适配增加详细日志使用
|
|
|
|
|
+ cmdGroupModel.setDevCode(iotDevice.getDevCode());
|
|
|
|
|
+ cmdGroupModel.setCtBiztitle(iotDevice.getDevtypeName() + ":" + iotDevice.getDevCode());
|
|
|
|
|
+ cmdGroupModel.setCtBiztype("3");
|
|
|
|
|
+ cmdGroupModel.setCtDevtype(iotDevice.getDevtypeBid());
|
|
|
|
|
+ cmdGroupModel.setCtParam(JSONUtils.toJSONString(reqVo));
|
|
|
|
|
+ iIotCmdtaskService.handInternalCmd(cmdGroupModel);
|
|
|
|
|
+ return cmdGroupModel.getTaskUuid();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public String clearPest(IotScdClearPestDto iotScdClearPestDto){
|
|
|
|
|
+ IotDevice iotDevice = iotScdClearPestDto.getIotDevice();
|
|
|
|
|
+
|
|
|
|
|
+ JSONObject payload = new JSONObject();
|
|
|
|
|
+ payload.put("cmd", "ctr_clear");
|
|
|
|
|
+
|
|
|
|
|
+ IotDeviceconfig iotDeviceconfig = new IotDeviceconfig();
|
|
|
|
|
+ iotDeviceconfig.setDevBid(iotDevice.getDevBid());
|
|
|
|
|
+ iotDeviceconfig.setDevcfgContext(JSONUtils.toJSONString(payload));
|
|
|
|
|
+
|
|
|
|
|
+ CmdGroupModel cmdGroupModel = iIotDeviceconfigService.createCommonCmd(iotDeviceconfig);
|
|
|
|
|
+ log.info("【{}】【杀虫灯 [一键清虫]】【构建 cmdGroupModel】{}", LogCore.getSeq(), JSONUtils.toJSONString(cmdGroupModel));
|
|
|
|
|
+ cmdGroupModel.setRequestId(IdUtils.fastUUID());
|
|
|
|
|
+
|
|
|
|
|
+ // 适配增加详细日志使用
|
|
|
|
|
+ cmdGroupModel.setDevCode(iotDevice.getDevCode());
|
|
|
|
|
+ cmdGroupModel.setCtBiztitle(iotDevice.getDevtypeName() + ":" + iotDevice.getDevCode());
|
|
|
|
|
+ cmdGroupModel.setCtBiztype("3");
|
|
|
|
|
+ cmdGroupModel.setCtDevtype(iotDevice.getDevtypeBid());
|
|
|
|
|
+// cmdGroupModel.setCtParam(JSONUtils.toJSONString(iotDeviceconfig));
|
|
|
|
|
+ iIotCmdtaskService.handInternalCmd(cmdGroupModel);
|
|
|
|
|
+ return cmdGroupModel.getTaskUuid();
|
|
|
|
|
+ }
|
|
|
|
|
+}
|