|
|
@@ -8,8 +8,10 @@ import com.yunfeiyun.agmp.common.core.page.TableDataInfo;
|
|
|
import com.yunfeiyun.agmp.common.core.page.TableSupport;
|
|
|
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;
|
|
|
@@ -18,8 +20,12 @@ 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.qxsqz.domain.IotDeviceQxzDataListReqVo;
|
|
|
+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.IotYfFxsScdDataExportVo;
|
|
|
+import com.yunfeiyun.agmp.iotm.device.scd.domain.IotYfScdDataExportVo;
|
|
|
import com.yunfeiyun.agmp.iotm.device.scd.domain.IotYfScdPolylineResVo;
|
|
|
+import com.yunfeiyun.agmp.iotm.device.scd.domain.IotYfScdStatusExportVo;
|
|
|
import com.yunfeiyun.agmp.iotm.device.scd.service.IIotScdCommService;
|
|
|
import com.yunfeiyun.agmp.iotm.util.MongoUtil;
|
|
|
import com.yunfeiyun.agmp.iotm.web.service.IIotCmdtaskService;
|
|
|
@@ -33,11 +39,8 @@ import org.springframework.data.mongodb.core.query.Criteria;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.text.ParseException;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.util.*;
|
|
|
|
|
|
@Service(value = ServiceNameConst.SERVICE_YF_SCD)
|
|
|
@Slf4j
|
|
|
@@ -54,24 +57,23 @@ public class IotYfScdServiceImpl extends IIotScdCommService {
|
|
|
@Resource
|
|
|
private IIotDeviceconfigService iIotDeviceconfigService;
|
|
|
|
|
|
- /**
|
|
|
- * 获取数据列表接口
|
|
|
- *
|
|
|
- */
|
|
|
- public TableDataInfo dataList(IotDeviceQxzDataListReqVo reqVo) throws ParseException {
|
|
|
+ public TableDataInfo dataList(IotDeviceDataListReqVo reqVo, boolean isCheckDevice) {
|
|
|
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(), "设备不存在");
|
|
|
+ if (isCheckDevice) {
|
|
|
+ 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){
|
|
|
+ if (startTime == null || endTime == null) {
|
|
|
throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(), "请输入正确的起止时间");
|
|
|
}
|
|
|
|
|
|
@@ -87,10 +89,18 @@ public class IotYfScdServiceImpl extends IIotScdCommService {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 获取数据列表接口
|
|
|
+ */
|
|
|
+ public TableDataInfo dataList(IotDeviceDataListReqVo reqVo) {
|
|
|
+ return dataList(reqVo, true);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 获取折线图数据列表接口
|
|
|
+ *
|
|
|
* @param reqVo
|
|
|
*/
|
|
|
- public List<IotYfScdPolylineResVo> chartList(IotDeviceQxzDataListReqVo reqVo) throws ParseException {
|
|
|
+ public List<IotYfScdPolylineResVo> chartList(IotDeviceDataListReqVo reqVo) {
|
|
|
String devBid = reqVo.getDevBid();
|
|
|
if (StringUtils.isEmpty(devBid)) {
|
|
|
throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "设备标识不能为空");
|
|
|
@@ -197,6 +207,7 @@ public class IotYfScdServiceImpl extends IIotScdCommService {
|
|
|
|
|
|
/**
|
|
|
* 刷新指令集
|
|
|
+ *
|
|
|
* @param reqVo
|
|
|
*/
|
|
|
public void refresh(DeviceRefreshDto reqVo) {
|
|
|
@@ -220,9 +231,132 @@ public class IotYfScdServiceImpl extends IIotScdCommService {
|
|
|
cmdGroupModel.setCtBiztype("3");
|
|
|
cmdGroupModel.setCtDevtype(findDevice.getDevtypeBid());
|
|
|
cmdGroupModel.setCtBiztitle(findDevice.getDevtypeName() + ":" + findDevice.getDevCode());
|
|
|
- cmdGroupModel.setCtParam("设备id:"+devBid);
|
|
|
+ cmdGroupModel.setCtParam("设备id:" + devBid);
|
|
|
iIotCmdtaskService.handInternalCmd(cmdGroupModel);
|
|
|
String taskUuid = cmdGroupModel.getTaskUuid();
|
|
|
log.info("【“刷新”指令集任务】创建成功,taskUuid:{}", taskUuid);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 数据导出
|
|
|
+ *
|
|
|
+ * @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(), "设备不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ TableDataInfo tableDataInfo = dataList(iotDeviceDataListReqVo, false);
|
|
|
+ List<IotYfScddata> iotYfScddataList = (List<IotYfScddata>) tableDataInfo.getData();
|
|
|
+ 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(), "设备不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ TableDataInfo tableDataInfo = dataList(iotDeviceDataListReqVo, false);
|
|
|
+ List<IotYfScddata> iotYfScddataList = (List<IotYfScddata>) tableDataInfo.getData();
|
|
|
+ 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, "状态数据");
|
|
|
+ }
|
|
|
}
|