|
|
@@ -0,0 +1,293 @@
|
|
|
+package com.yunfeiyun.agmp.iotm.device.pest.service;
|
|
|
+
|
|
|
+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.DateUtils;
|
|
|
+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.domain.*;
|
|
|
+import com.yunfeiyun.agmp.iot.common.domain.reqvo.IotCbdConfigEditReqVo;
|
|
|
+import com.yunfeiyun.agmp.iot.common.enums.EnumDevRecogType;
|
|
|
+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.*;
|
|
|
+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.pest.domain.IotCbdModifyDevRecogTypeReqVo;
|
|
|
+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 javax.annotation.Resource;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+public class IIotCbdCommService extends IotDeviceBaseServiceImpl implements IotDeviceBaseService {
|
|
|
+ @Resource
|
|
|
+ private IIotDeviceconfigService iIotDeviceconfigService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IIotCmdtaskService iIotCmdtaskService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IIotDeviceService iotDeviceService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MongoService mongoService;
|
|
|
+
|
|
|
+ public Class getTableClass(String devtypeBid) {
|
|
|
+ Class tableClass = null;
|
|
|
+ switch (devtypeBid){
|
|
|
+ case IotDeviceDictConst.TYPE_YF_CBD:
|
|
|
+ tableClass = IotCbddata.class;
|
|
|
+ break;
|
|
|
+ case IotDeviceDictConst.TYPE_YF_XCT:
|
|
|
+ tableClass = IotXctdata.class;
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return tableClass;
|
|
|
+ }
|
|
|
+
|
|
|
+ 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);
|
|
|
+
|
|
|
+ String devBid = reqVo.getDevBid();
|
|
|
+ String startTime = reqVo.getStartTime();
|
|
|
+ String endTime = reqVo.getEndTime();
|
|
|
+
|
|
|
+ if (startTime == null || endTime == null) {
|
|
|
+ throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(), "请输入正确的起止时间");
|
|
|
+ }
|
|
|
+
|
|
|
+ IotDevice findDevice = iotDeviceService.selectIotDeviceByDevBid(devBid);
|
|
|
+ if (findDevice == null) {
|
|
|
+ throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(), "设备不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.put("devBid", reqVo.getDevBid());
|
|
|
+ if (StringUtils.isNotEmpty(reqVo.getStartTime()) && StringUtils.isEmpty(reqVo.getEndTime())) {
|
|
|
+ map.put("gte_cbddataCreatedDate", reqVo.getStartTime());
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(reqVo.getStartTime()) && StringUtils.isNotEmpty(reqVo.getEndTime())) {
|
|
|
+ map.put("lte_cbddataCreatedDate", reqVo.getEndTime());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(reqVo.getStartTime()) && StringUtils.isNotEmpty(reqVo.getEndTime())) {
|
|
|
+ map.put("time_cbddataCreatedDate", reqVo.getStartTime() + "," + reqVo.getEndTime());
|
|
|
+ }
|
|
|
+
|
|
|
+ PageDomain pageDomain = TableSupport.buildPageRequest();
|
|
|
+ String orderByColumn = pageDomain.getOrderByColumn();
|
|
|
+ if (Objects.equals(orderByColumn, "cdbdataContent.stamp")){
|
|
|
+ pageDomain.setOrderByColumn("cbddataCreatedDate");
|
|
|
+ }
|
|
|
+
|
|
|
+ Class tableClass = getTableClass(findDevice.getDevtypeBid());
|
|
|
+ IPage page = mongoService.findListPage(tableClass, map, pageDomain);
|
|
|
+ List<?> data = page.getRecords();
|
|
|
+ List<JSONObject> list = new ArrayList<>();
|
|
|
+ for (Object datum : data) {
|
|
|
+ JSONObject jsonObject = JSONObject.from(datum);
|
|
|
+ JSONObject cdbdataContent = jsonObject.getJSONObject("cdbdataContent");
|
|
|
+ jsonObject.putAll(cdbdataContent);
|
|
|
+ jsonObject.remove("cdbdataContent");
|
|
|
+ list.add(jsonObject);
|
|
|
+ }
|
|
|
+ rspData.setData(list);
|
|
|
+ rspData.setTotal(page.getTotal());
|
|
|
+ return rspData;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public String takePhoto(String devBid) {
|
|
|
+ log.info("【{}】【测报灯】【拍照】客户id {}", LogCore.getSeq());
|
|
|
+ IotDevice iotDevice = iotDeviceService.selectIotDeviceByDevBid(devBid);
|
|
|
+ if (iotDevice == null) {
|
|
|
+ throw new IotBizException(ErrorCode.FAILURE.getCode(),"设备不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ IotDeviceconfig iotDeviceconfig = new IotDeviceconfig();
|
|
|
+ iotDeviceconfig.setTid(iotDevice.getTid());
|
|
|
+ iotDeviceconfig.setDevBid(devBid);
|
|
|
+
|
|
|
+ CmdGroupModel cmdGroupModel = iIotDeviceconfigService.createTakePhotoCmd(iotDeviceconfig);
|
|
|
+ cmdGroupModel.setRequestId(IdUtils.fastUUID());
|
|
|
+ // 适配增加详细日志使用
|
|
|
+ cmdGroupModel.setDevCode(iotDevice.getDevCode());
|
|
|
+ cmdGroupModel.setCtBiztitle(iotDevice.getDevtypeName() + ":" + iotDevice.getDevCode());
|
|
|
+ cmdGroupModel.setCtBiztype("3");
|
|
|
+ cmdGroupModel.setCtDevtype(iotDevice.getDevtypeBid());
|
|
|
+ //cmdGroupModel.setCtParam(deviceConfigurationTranslator.logTakePhoto(iotDevice.getDevBid()));
|
|
|
+ cmdGroupModel.setCtParam("设备id:"+devBid);
|
|
|
+ iIotCmdtaskService.handInternalCmd(cmdGroupModel);
|
|
|
+ return cmdGroupModel.getTaskUuid();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发送更改配置
|
|
|
+ * @param iotCbdConfigEditReqVo
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String sendConfigCmd(IotCbdConfigEditReqVo iotCbdConfigEditReqVo) {
|
|
|
+ log.info("【{}】【测报灯】【下发指令配置】客户id {}", LogCore.getSeq());
|
|
|
+ String devBid = iotCbdConfigEditReqVo.getDevBid();
|
|
|
+ if (StringUtils.isEmpty(devBid)) {
|
|
|
+ throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(),"设备标识不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ IotDevice iotDevice = iotCbdConfigEditReqVo.getIotDevice();
|
|
|
+ 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(iotCbdConfigEditReqVo.getIotCbdConfig()));
|
|
|
+ iotDeviceconfig.setDevcfgDelstatus("0");
|
|
|
+ iIotDeviceconfigService.insertIotDeviceconfig(iotDeviceconfig);
|
|
|
+ } else {
|
|
|
+ // 如果测报灯配置不为空,则更新测报灯配置
|
|
|
+ iotDeviceconfig.setDevcfgContext(JSONUtils.toJSONString(iotCbdConfigEditReqVo.getIotCbdConfig()));
|
|
|
+ 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(deviceConfigurationTranslator.configTranslate(iotCbdConfigEditReqVo));
|
|
|
+ cmdGroupModel.setCtParam(JSONUtils.toJSONString(iotCbdConfigEditReqVo));
|
|
|
+ iIotCmdtaskService.handInternalCmd(cmdGroupModel);
|
|
|
+ return cmdGroupModel.getTaskUuid();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 数据导出
|
|
|
+ *
|
|
|
+ * @param iotDeviceExportReqVo
|
|
|
+ */
|
|
|
+ public void dataExport(IotDeviceExportReqVo iotDeviceExportReqVo) {
|
|
|
+ HttpServletResponse response = iotDeviceExportReqVo.getResponse();
|
|
|
+ IotDeviceDataListReqVo reqVo = iotDeviceExportReqVo.getReqVo();
|
|
|
+
|
|
|
+ String startTime = reqVo.getStartTime();
|
|
|
+ String endTime = reqVo.getEndTime();
|
|
|
+
|
|
|
+ if (startTime == null || endTime == null) {
|
|
|
+ throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(), "请输入正确的起止时间");
|
|
|
+ }
|
|
|
+
|
|
|
+ IotDevice iotDevice = iotDeviceService.selectIotDeviceByDevBid(reqVo.getDevBid());
|
|
|
+ if (iotDevice == null) {
|
|
|
+ throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(), "设备不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.put("devBid", reqVo.getDevBid());
|
|
|
+ if (StringUtils.isNotEmpty(reqVo.getStartTime()) && StringUtils.isEmpty(reqVo.getEndTime())) {
|
|
|
+ map.put("gte_cbddataCreatedDate", reqVo.getStartTime());
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(reqVo.getStartTime()) && StringUtils.isNotEmpty(reqVo.getEndTime())) {
|
|
|
+ map.put("lte_cbddataCreatedDate", reqVo.getEndTime());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(reqVo.getStartTime()) && StringUtils.isNotEmpty(reqVo.getEndTime())) {
|
|
|
+ map.put("time_cbddataCreatedDate", reqVo.getStartTime() + "," + reqVo.getEndTime());
|
|
|
+ }
|
|
|
+
|
|
|
+ Class tableClass = getTableClass(iotDevice.getDevtypeBid());
|
|
|
+ List<CbdBaseDataEntity> dataList = mongoService.findAll(tableClass, map, "cbddataCreatedDate desc");
|
|
|
+ if(iotDevice.getDevtypeBid().equals(IotDeviceDictConst.TYPE_YF_XCT)) {
|
|
|
+ List<IotDeviceXctDataListResVo> list = new ArrayList<>();
|
|
|
+ for(CbdBaseDataEntity item: dataList){
|
|
|
+ String cbddataCreatedDate = item.getCbddataCreatedDate();
|
|
|
+ IotDeviceXctDataListResVo resVo = JSONUtils.toObject(item.getCdbdataContent().toJSONString(), IotDeviceXctDataListResVo.class);
|
|
|
+ resVo.setCbddataCreatedDate(cbddataCreatedDate);
|
|
|
+ list.add(resVo);
|
|
|
+ }
|
|
|
+ ExcelUtil<IotDeviceXctDataListResVo> util = new ExcelUtil<>(IotDeviceXctDataListResVo.class);
|
|
|
+ util.exportExcel(response, list, "设备数据");
|
|
|
+ }else{
|
|
|
+ List<IotDeviceDataListResVo> list = new ArrayList<>();
|
|
|
+ for(CbdBaseDataEntity item: dataList){
|
|
|
+ String cbddataCreatedDate = item.getCbddataCreatedDate();
|
|
|
+ IotDeviceDataListResVo resVo = JSONUtils.toObject(item.getCdbdataContent().toJSONString(), IotDeviceDataListResVo.class);
|
|
|
+ resVo.setCbddataCreatedDate(cbddataCreatedDate);
|
|
|
+ list.add(resVo);
|
|
|
+ }
|
|
|
+ ExcelUtil<IotDeviceDataListResVo> util = new ExcelUtil<>(IotDeviceDataListResVo.class);
|
|
|
+ util.exportExcel(response, list, "设备数据");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void refresh(DeviceRefreshDto reqVo) {
|
|
|
+ IotDevice iotDevice = reqVo.getIotDevice();
|
|
|
+ String devBid = iotDevice.getDevBid();
|
|
|
+
|
|
|
+ log.info("创建【“刷新”指令集任务】,设备类型:CBD");
|
|
|
+ JSONObject payload = new JSONObject();
|
|
|
+ payload.put("cmd", "read");
|
|
|
+ payload.put("ext", "data");
|
|
|
+ IotDeviceconfig iotDeviceconfig = new IotDeviceconfig();
|
|
|
+ iotDeviceconfig.setTid(iotDevice.getTid());
|
|
|
+ iotDeviceconfig.setDevBid(devBid);
|
|
|
+ iotDeviceconfig.setDevcfgContext(JSONUtils.toJSONString(payload));
|
|
|
+
|
|
|
+ CmdGroupModel cmdGroupModel = iIotDeviceconfigService.createRefreshCmd(iotDeviceconfig);
|
|
|
+
|
|
|
+ // 构建日志需要用的内容
|
|
|
+ cmdGroupModel.setRequestId(IdUtils.fastUUID());
|
|
|
+ cmdGroupModel.setDevCode(iotDevice.getDevCode());
|
|
|
+ cmdGroupModel.setCtBiztype("3");
|
|
|
+ cmdGroupModel.setCtDevtype(iotDevice.getDevtypeBid());
|
|
|
+ cmdGroupModel.setCtBiztitle(iotDevice.getDevtypeName() + ":" + iotDevice.getDevCode());
|
|
|
+ //cmdGroupModel.setCtParam(cbdDeviceConfigurationTranslator.logTakeRefresh(iotDevice.getDevBid()));
|
|
|
+ cmdGroupModel.setCtParam("设备id:"+devBid);
|
|
|
+ iIotCmdtaskService.handInternalCmd(cmdGroupModel);
|
|
|
+ }
|
|
|
+
|
|
|
+ public int modifyRecog(IotCbdModifyDevRecogTypeReqVo reqVo) {
|
|
|
+ log.info("【{}】【测报灯】【修改识别类型】客户id {}", LogCore.getSeq(), reqVo);
|
|
|
+ String devBid = reqVo.getDevBid();
|
|
|
+ String devRecogtype = reqVo.getDevRecogtype();
|
|
|
+
|
|
|
+ if(EnumDevRecogType.findEnumByCode(devRecogtype) == null){
|
|
|
+ throw new IotBizException(ErrorCode.FAILURE.getCode(),"识别类型不正确");
|
|
|
+ }
|
|
|
+ IotDevice iotDevice = iotDeviceService.selectIotDeviceByDevBid(devBid);
|
|
|
+ if(iotDevice == null){
|
|
|
+ throw new IotBizException(ErrorCode.FAILURE.getCode(),"设备不存在");
|
|
|
+ }
|
|
|
+ IotDevice iotDeviceUpdate = new IotDevice();
|
|
|
+ iotDeviceUpdate.setDevBid(devBid);
|
|
|
+ iotDeviceUpdate.setDevRecogtype(devRecogtype);
|
|
|
+ iotDeviceUpdate.setDevModifieddate(DateUtils.dateTimeNow());
|
|
|
+ return iotDeviceService.updateIotDevice(iotDeviceUpdate, null, null);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|