|
@@ -3,13 +3,10 @@ package com.welampiot.controller;
|
|
import com.welampiot.common.BaseResult;
|
|
import com.welampiot.common.BaseResult;
|
|
import com.welampiot.common.DevInfoEnum;
|
|
import com.welampiot.common.DevInfoEnum;
|
|
import com.welampiot.common.InterfaceResultEnum;
|
|
import com.welampiot.common.InterfaceResultEnum;
|
|
-import com.welampiot.dto.EnvmonitorDTO;
|
|
|
|
-import com.welampiot.dto.WeatherRS485DevInfoDTO;
|
|
|
|
-import com.welampiot.dto.WifiDTO;
|
|
|
|
-import com.welampiot.service.EnvmonitorService;
|
|
|
|
-import com.welampiot.service.WeatherRS485DevInfoService;
|
|
|
|
-import com.welampiot.service.WifiService;
|
|
|
|
|
|
+import com.welampiot.dto.*;
|
|
|
|
+import com.welampiot.service.*;
|
|
import com.welampiot.utils.ToolUtils;
|
|
import com.welampiot.utils.ToolUtils;
|
|
|
|
+import com.welampiot.vo.EnvmonitorDetailVO;
|
|
import com.welampiot.vo.EnvmonitorVO;
|
|
import com.welampiot.vo.EnvmonitorVO;
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -19,6 +16,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -42,6 +40,12 @@ public class WeatherController {
|
|
private WifiService wifiService;
|
|
private WifiService wifiService;
|
|
@Autowired
|
|
@Autowired
|
|
private WeatherRS485DevInfoService weatherRS485DevInfoService;
|
|
private WeatherRS485DevInfoService weatherRS485DevInfoService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private EnvmonitorInfoLogService envmonitorInfoLogService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private UserService userService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private NetworkService networkService;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 设置plc气象站开、关灯时间
|
|
* 设置plc气象站开、关灯时间
|
|
@@ -239,4 +243,177 @@ public class WeatherController {
|
|
}
|
|
}
|
|
return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version);
|
|
return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 环境监控列表
|
|
|
|
+ * @param request 路段,关键字搜索,分页
|
|
|
|
+ * @return 环境监控列表
|
|
|
|
+ */
|
|
|
|
+ @RequestMapping(value = "/getList", method = RequestMethod.POST)
|
|
|
|
+ public BaseResult<?> getList(HttpServletRequest request) {
|
|
|
|
+ Integer version = (Integer) toolUtils.getRequestContent(request,"version",1);
|
|
|
|
+ Integer page = (Integer) toolUtils.getRequestContent(request,"page",1);
|
|
|
|
+ Integer count = (Integer) toolUtils.getRequestContent(request,"count",1);
|
|
|
|
+ Integer areaId = (Integer) toolUtils.getRequestContent(request,"areaId",1);
|
|
|
|
+ Integer sectionId = (Integer) toolUtils.getRequestContent(request,"sectionId",1);
|
|
|
|
+ String keyword = (String) toolUtils.getRequestContent(request,"keyword",2);
|
|
|
|
+ if (page == 0) page = 1;
|
|
|
|
+ if (count == 0) count = 16;
|
|
|
|
+ EnvmonitorVO vo = new EnvmonitorVO();
|
|
|
|
+ vo.setPage(count * (page - 1));
|
|
|
|
+ vo.setCount(count);
|
|
|
|
+ vo.setAreaId(areaId);
|
|
|
|
+ vo.setSectionId(sectionId);
|
|
|
|
+ vo.setKeyword(keyword);
|
|
|
|
+ vo.setSectionList(toolUtils.getSectionList(request));
|
|
|
|
+ List<EnvmonitorDTO> weatherList = envmonitorService.getEnvmonitorListByVO(vo);
|
|
|
|
+ Integer total = envmonitorService.getEnvmonitorTotalByVO(vo);
|
|
|
|
+ EnvmonitorVO envmonitorVO = new EnvmonitorVO();
|
|
|
|
+ envmonitorVO.setList(weatherList);
|
|
|
|
+ envmonitorVO.setTotal((int) Math.ceil(total / (double) count));
|
|
|
|
+ return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,envmonitorVO);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 添加/编辑环境监控
|
|
|
|
+ * @param vo 环境监控属性
|
|
|
|
+ * @return 添加/编辑环境监控
|
|
|
|
+ */
|
|
|
|
+ @RequestMapping(value = "/save", method = RequestMethod.POST)
|
|
|
|
+ public BaseResult<?> save(EnvmonitorDetailVO vo) {
|
|
|
|
+ if (vo.getVersion() == null) vo.setVersion(0);
|
|
|
|
+ Integer version = vo.getVersion();
|
|
|
|
+ Integer id = vo.getId();
|
|
|
|
+ if (vo.getUsername() == null || vo.getUsername().isEmpty())
|
|
|
|
+ return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR,version);
|
|
|
|
+ if (vo.getNumber() == null || vo.getNumber().isEmpty())
|
|
|
|
+ return toolUtils.response(InterfaceResultEnum.LACK_NUMBER_ERROR,version);
|
|
|
|
+ if (vo.getAreaId() == null || vo.getAreaId() == 0)
|
|
|
|
+ return toolUtils.response(InterfaceResultEnum.LACK_AREA_ERROR,version);
|
|
|
|
+ if (vo.getSectionId() == null || vo.getSectionId() == 0)
|
|
|
|
+ return toolUtils.response(InterfaceResultEnum.LACK_SECTION_ERROR,version);
|
|
|
|
+ if (vo.getSn() == null || vo.getSn().isEmpty())
|
|
|
|
+ return toolUtils.response(InterfaceResultEnum.LACK_DEV_SN_ERROR,version);
|
|
|
|
+ if (vo.getProtocolType() == null)
|
|
|
|
+ return toolUtils.response(InterfaceResultEnum.LACK_PROTOCOL_TYPE_ERROR,version);
|
|
|
|
+
|
|
|
|
+ EnvmonitorDTO envmonitorDTO = new EnvmonitorDTO();
|
|
|
|
+ BeanUtils.copyProperties(vo,envmonitorDTO);
|
|
|
|
+ envmonitorDTO.setNum(vo.getSn());
|
|
|
|
+ EnvmonitorDTO dto = new EnvmonitorDTO();
|
|
|
|
+ UserDTO userDTO = userService.queryUserIdByUsername(vo.getUsername());
|
|
|
|
+ if (userDTO == null) return toolUtils.response(InterfaceResultEnum.PARAM_FAIL,version);
|
|
|
|
+ if (id == null || id == 0) { // 添加
|
|
|
|
+ dto.setSectionId(vo.getSectionId());
|
|
|
|
+ dto.setNumber(vo.getNumber());
|
|
|
|
+ if (envmonitorService.findDataByEnvmonitorDTO(dto) > 0)
|
|
|
|
+ return toolUtils.response(InterfaceResultEnum.DEV_NUMBER_UNIQUE_ERROR,version);
|
|
|
|
+ dto = new EnvmonitorDTO();
|
|
|
|
+ dto.setNum(vo.getSn());
|
|
|
|
+ if (envmonitorService.findDataByEnvmonitorDTO(dto) > 0)
|
|
|
|
+ return toolUtils.response(InterfaceResultEnum.DEV_SN_UNIQUE_ERROR,version);
|
|
|
|
+ long l = System.currentTimeMillis();
|
|
|
|
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
+ String format = simpleDateFormat.format(l);
|
|
|
|
+ envmonitorDTO.setCreateTime(format);
|
|
|
|
+ envmonitorDTO.setUpdateTime(format);
|
|
|
|
+
|
|
|
|
+ // 添加网络
|
|
|
|
+ NetworkDTO networkDTO = new NetworkDTO();
|
|
|
|
+ networkDTO.setUserId(userDTO.getId());
|
|
|
|
+ networkDTO.setCreateTime(format);
|
|
|
|
+ networkDTO.setAreaId(vo.getAreaId());
|
|
|
|
+ networkDTO.setSectionId(vo.getSectionId());
|
|
|
|
+ networkDTO.setNetworkName(vo.getSn());
|
|
|
|
+ networkDTO.setDeviceSn(vo.getSn());
|
|
|
|
+ networkDTO.setProtocolType(vo.getProtocolType());
|
|
|
|
+ networkDTO.setDeviceType(1);
|
|
|
|
+ networkDTO.setNetType(1);
|
|
|
|
+ networkDTO.setGatewayType("direct");
|
|
|
|
+ networkService.add(networkDTO);
|
|
|
|
+ Integer networkId = networkDTO.getId();
|
|
|
|
+ envmonitorDTO.setNetworkId(networkId);
|
|
|
|
+ envmonitorService.addEnvmonitorData(envmonitorDTO);
|
|
|
|
+ } else { // 编辑
|
|
|
|
+ dto = new EnvmonitorDTO();
|
|
|
|
+ dto.setId(vo.getId());
|
|
|
|
+ dto.setSectionId(vo.getSectionId());
|
|
|
|
+ dto.setNumber(vo.getNumber());
|
|
|
|
+ if (envmonitorService.findDataByEnvmonitorDTO(dto) > 0)
|
|
|
|
+ return toolUtils.response(InterfaceResultEnum.DEV_NUMBER_UNIQUE_ERROR,version);
|
|
|
|
+ dto = new EnvmonitorDTO();
|
|
|
|
+ dto.setId(vo.getId());
|
|
|
|
+ dto.setNum(vo.getSn());
|
|
|
|
+ if (envmonitorService.findDataByEnvmonitorDTO(dto) > 0)
|
|
|
|
+ return toolUtils.response(InterfaceResultEnum.DEV_SN_UNIQUE_ERROR,version);
|
|
|
|
+ long l = System.currentTimeMillis();
|
|
|
|
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
+ String format = simpleDateFormat.format(l);
|
|
|
|
+ envmonitorDTO.setUpdateTime(format);
|
|
|
|
+
|
|
|
|
+ // 编辑网络
|
|
|
|
+ NetworkDTO networkDTO = new NetworkDTO();
|
|
|
|
+ networkDTO.setAreaId(vo.getAreaId());
|
|
|
|
+ networkDTO.setSectionId(vo.getSectionId());
|
|
|
|
+ networkDTO.setNetworkName(vo.getSn());
|
|
|
|
+ networkDTO.setDeviceSn(vo.getSn());
|
|
|
|
+ networkDTO.setProtocolType(vo.getProtocolType());
|
|
|
|
+ networkDTO.setDeviceType(1);
|
|
|
|
+ networkService.update(networkDTO);
|
|
|
|
+ envmonitorService.updateEnvmonitorData(envmonitorDTO);
|
|
|
|
+ }
|
|
|
|
+ return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 环境监控详情
|
|
|
|
+ * @param vo 环境监控id
|
|
|
|
+ * @return 环境监控详情
|
|
|
|
+ */
|
|
|
|
+ @RequestMapping(value = "/info", method = RequestMethod.POST)
|
|
|
|
+ public BaseResult<?> info(EnvmonitorDetailVO vo) {
|
|
|
|
+ if (vo.getVersion() == null) vo.setVersion(0);
|
|
|
|
+ Integer version = vo.getVersion();
|
|
|
|
+ Integer id = vo.getId();
|
|
|
|
+ if (id == null || id == 0)
|
|
|
|
+ return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR,version);
|
|
|
|
+ EnvmonitorDTO envmonitorDTO = envmonitorService.getEnvmonitorDetailByVO(vo);
|
|
|
|
+ if (envmonitorDTO == null) return toolUtils.response(InterfaceResultEnum.PARAM_FAIL,version);
|
|
|
|
+ EnvmonitorDetailVO envmonitorDetailVO = new EnvmonitorDetailVO();
|
|
|
|
+ BeanUtils.copyProperties(envmonitorDTO,envmonitorDetailVO);
|
|
|
|
+ if (envmonitorDTO.getProtocolType() != null && envmonitorDTO.getProtocolType() == 5) {
|
|
|
|
+ envmonitorDetailVO.setProtocolTypeStr("zigbee");
|
|
|
|
+ } else if (envmonitorDTO.getProtocolType() != null && envmonitorDTO.getProtocolType() == 4) {
|
|
|
|
+ envmonitorDetailVO.setProtocolTypeStr("gprs_direct");
|
|
|
|
+ } else if (envmonitorDTO.getProtocolType() != null && envmonitorDTO.getProtocolType() == 3) {
|
|
|
|
+ envmonitorDetailVO.setProtocolTypeStr("nbIot");
|
|
|
|
+ } else if (envmonitorDTO.getProtocolType() != null && envmonitorDTO.getProtocolType() == 2) {
|
|
|
|
+ envmonitorDetailVO.setProtocolTypeStr("rf mesh");
|
|
|
|
+ } else if (envmonitorDTO.getProtocolType() != null && envmonitorDTO.getProtocolType() == 1) {
|
|
|
|
+ envmonitorDetailVO.setProtocolTypeStr("lora mesh");
|
|
|
|
+ } else {
|
|
|
|
+ envmonitorDetailVO.setProtocolTypeStr("lorawan");
|
|
|
|
+ }
|
|
|
|
+ return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,envmonitorDetailVO);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 删除环境监控
|
|
|
|
+ * @param request id
|
|
|
|
+ * @return 删除环境监控
|
|
|
|
+ */
|
|
|
|
+ @RequestMapping(value = "/del", method = RequestMethod.POST)
|
|
|
|
+ public BaseResult<?> del(HttpServletRequest request) {
|
|
|
|
+ Integer version = (Integer) toolUtils.getRequestContent(request,"version",1);
|
|
|
|
+ String id = (String) toolUtils.getRequestContent(request,"id",2);
|
|
|
|
+ if (id == null || id.isEmpty())
|
|
|
|
+ return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR,version);
|
|
|
|
+ String[] split = id.split(",");
|
|
|
|
+ for (String s : split) {
|
|
|
|
+ Integer integer = Integer.valueOf(s);
|
|
|
|
+ envmonitorService.deleteEnvmonitorById(integer);
|
|
|
|
+ envmonitorInfoLogService.deleteEnvmonitorInfoLogData(integer);
|
|
|
|
+ }
|
|
|
|
+ return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version);
|
|
|
|
+ }
|
|
}
|
|
}
|