|
@@ -0,0 +1,226 @@
|
|
|
+package com.welampiot.controller;
|
|
|
+
|
|
|
+import com.welampiot.common.BaseResult;
|
|
|
+import com.welampiot.common.InterfaceResultEnum;
|
|
|
+import com.welampiot.dto.EnvmonitorDTO;
|
|
|
+import com.welampiot.dto.NetworkDTO;
|
|
|
+import com.welampiot.dto.UserDTO;
|
|
|
+import com.welampiot.service.EnvmonitorInfoLogService;
|
|
|
+import com.welampiot.service.EnvmonitorService;
|
|
|
+import com.welampiot.service.NetworkService;
|
|
|
+import com.welampiot.service.UserService;
|
|
|
+import com.welampiot.utils.ToolUtils;
|
|
|
+import com.welampiot.vo.EnvmonitorDetailVO;
|
|
|
+import com.welampiot.vo.EnvmonitorVO;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.CrossOrigin;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * ClassName: IlluminanceController
|
|
|
+ * Package: com.welampiot.controller
|
|
|
+ * Description:
|
|
|
+ *
|
|
|
+ * @Author: zhj_Start
|
|
|
+ * @Create: 2023/8/22 - 18:02
|
|
|
+ * @Version: v1.0
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@CrossOrigin
|
|
|
+@RequestMapping("/illuminance")
|
|
|
+public class IlluminanceController {
|
|
|
+ @Autowired
|
|
|
+ private EnvmonitorService envmonitorService;
|
|
|
+ @Autowired
|
|
|
+ private EnvmonitorInfoLogService envmonitorInfoLogService;
|
|
|
+ @Autowired
|
|
|
+ private UserService userService;
|
|
|
+ @Autowired
|
|
|
+ private NetworkService networkService;
|
|
|
+ @Autowired
|
|
|
+ private ToolUtils toolUtils;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加编辑光照度传感器
|
|
|
+ * @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.getModel() == null || vo.getModel().trim().isEmpty())
|
|
|
+ return toolUtils.response(InterfaceResultEnum.LACK_NAME_ERROR,version);
|
|
|
+ if (vo.getName() == null || vo.getName().trim().isEmpty())
|
|
|
+ return toolUtils.response(InterfaceResultEnum.LACK_NAME_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.getAddress() == null || vo.getAddress().isEmpty())
|
|
|
+ return toolUtils.response(InterfaceResultEnum.LACK_DEV_ADDRESS_ERROR,version);
|
|
|
+ if (vo.getRemarks() == null || vo.getRemarks().trim().isEmpty())
|
|
|
+ return toolUtils.response(InterfaceResultEnum.LACK_REMARK_ERROR,version);
|
|
|
+ if (vo.getManuFactor() == null || vo.getManuFactor().trim().isEmpty())
|
|
|
+ return toolUtils.response(InterfaceResultEnum.LACK_FACTOR_ERROR,version);
|
|
|
+ if (vo.getLongitude() == null)
|
|
|
+ return toolUtils.response(InterfaceResultEnum.LACK_LOCATION_ERROR,version);
|
|
|
+ if (vo.getLatitude() == null)
|
|
|
+ return toolUtils.response(InterfaceResultEnum.LACK_LOCATION_ERROR,version);
|
|
|
+ if (vo.getProtocolType() == null)
|
|
|
+ return toolUtils.response(InterfaceResultEnum.LACK_PROTOCOL_TYPE_ERROR,version);
|
|
|
+
|
|
|
+ EnvmonitorDTO envmonitorDTO = new EnvmonitorDTO();
|
|
|
+ BeanUtils.copyProperties(vo,envmonitorDTO);
|
|
|
+ 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.setName(vo.getName());
|
|
|
+ if (envmonitorService.findDataByEnvmonitorDTO(dto) > 0)
|
|
|
+ return toolUtils.response(InterfaceResultEnum.DEV_NAME_UNIQUE_ERROR,version);
|
|
|
+ dto = new EnvmonitorDTO();
|
|
|
+ dto.setAddress(vo.getAddress());
|
|
|
+ if (envmonitorService.findDataByEnvmonitorDTO(dto) > 0)
|
|
|
+ return toolUtils.response(InterfaceResultEnum.DEV_ADDRESS_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.getAddress());
|
|
|
+ networkDTO.setDeviceSn(vo.getAddress());
|
|
|
+ networkDTO.setProtocolType(vo.getProtocolType());
|
|
|
+ networkDTO.setDeviceType(2);
|
|
|
+ networkDTO.setNetType(1);
|
|
|
+ networkDTO.setGatewayType("direct");
|
|
|
+ networkService.add(networkDTO);
|
|
|
+ Integer networkId = networkDTO.getId();
|
|
|
+ envmonitorDTO.setNetworkId(networkId);
|
|
|
+ envmonitorService.addIlluminanceData(envmonitorDTO);
|
|
|
+ } else { // 编辑
|
|
|
+ dto = new EnvmonitorDTO();
|
|
|
+ dto.setId(vo.getId());
|
|
|
+ dto.setSectionId(vo.getSectionId());
|
|
|
+ dto.setName(vo.getName());
|
|
|
+ if (envmonitorService.findDataByEnvmonitorDTO(dto) > 0)
|
|
|
+ return toolUtils.response(InterfaceResultEnum.DEV_NAME_UNIQUE_ERROR,version);
|
|
|
+ dto = new EnvmonitorDTO();
|
|
|
+ dto.setId(vo.getId());
|
|
|
+ dto.setAddress(vo.getAddress());
|
|
|
+ if (envmonitorService.findDataByEnvmonitorDTO(dto) > 0)
|
|
|
+ return toolUtils.response(InterfaceResultEnum.DEV_ADDRESS_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.getAddress());
|
|
|
+ networkDTO.setDeviceSn(vo.getAddress());
|
|
|
+ networkDTO.setProtocolType(vo.getProtocolType());
|
|
|
+ networkDTO.setDeviceType(2);
|
|
|
+ networkService.update(networkDTO);
|
|
|
+ envmonitorService.updateIlluminanceData(envmonitorDTO);
|
|
|
+ }
|
|
|
+ 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.setVersion(version);
|
|
|
+ vo.setSectionList(toolUtils.getSectionList(request));
|
|
|
+ List<EnvmonitorDTO> weatherList = envmonitorService.getIlluminanceListByVO(vo);
|
|
|
+ EnvmonitorVO envmonitorVO = new EnvmonitorVO();
|
|
|
+ envmonitorVO.setList(weatherList);
|
|
|
+ return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,envmonitorVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 光照传感器详情
|
|
|
+ * @param vo 环境监控id
|
|
|
+ * @return 光照传感器详情
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/details", method = RequestMethod.POST)
|
|
|
+ public BaseResult<?> details(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.getIlluminanceDetailByVO(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() == 4) {
|
|
|
+ envmonitorDetailVO.setProtocolTypeStr("NBIoT");
|
|
|
+ } else if (envmonitorDTO.getProtocolType() != null && envmonitorDTO.getProtocolType() == 3) {
|
|
|
+ envmonitorDetailVO.setProtocolTypeStr("LoraWan");
|
|
|
+ } else if (envmonitorDTO.getProtocolType() != null && envmonitorDTO.getProtocolType() == 2) {
|
|
|
+ envmonitorDetailVO.setProtocolTypeStr("4G");
|
|
|
+ } else {
|
|
|
+ envmonitorDetailVO.setProtocolTypeStr("GPRS");
|
|
|
+ }
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+}
|