|
@@ -0,0 +1,174 @@
|
|
|
+package com.welampiot.controller;
|
|
|
+
|
|
|
+import com.welampiot.common.BaseResult;
|
|
|
+import com.welampiot.common.InterfaceResultEnum;
|
|
|
+import com.welampiot.dto.SmokeSensationDevInfoDTO;
|
|
|
+import com.welampiot.service.SmokeSensationDevInfoService;
|
|
|
+import com.welampiot.utils.ToolUtils;
|
|
|
+import com.welampiot.vo.SmokeSensationDevInfoVO;
|
|
|
+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.Arrays;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * ClassName: SmokeSensationController
|
|
|
+ * Package: com.welampiot.controller
|
|
|
+ * Description:
|
|
|
+ *
|
|
|
+ * @Author: zhj_Start
|
|
|
+ * @Create: 2023/5/31 - 15:41
|
|
|
+ * @Version: v1.0
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@CrossOrigin
|
|
|
+@RequestMapping("/smokeSensation")
|
|
|
+public class SmokeSensationController {
|
|
|
+ @Autowired
|
|
|
+ private SmokeSensationDevInfoService smokeSensationDevInfoService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ToolUtils toolUtils;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取智能烟感列表
|
|
|
+ * @param request 分页,关键字,路段筛选
|
|
|
+ * @return 返回智能烟感列表
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/getList", method = RequestMethod.POST)
|
|
|
+ public BaseResult<?> getList(HttpServletRequest request) {
|
|
|
+ int version = (int) toolUtils.getRequestContent(request,"version",1);
|
|
|
+ int online = (int) toolUtils.getRequestContent(request,"online",1);
|
|
|
+ int page = request.getParameter("page") == null ? 1 : Integer.parseInt(request.getParameter("page"));
|
|
|
+ int count = request.getParameter("count") == null ? 16 : Integer.parseInt(request.getParameter("count"));
|
|
|
+ String keyword = (String) toolUtils.getRequestContent(request,"keyword",2);
|
|
|
+
|
|
|
+ SmokeSensationDevInfoDTO smokeSensationDevInfoDTO = new SmokeSensationDevInfoDTO();
|
|
|
+ smokeSensationDevInfoDTO.setPage(count * (page - 1));
|
|
|
+ smokeSensationDevInfoDTO.setCount(count);
|
|
|
+ smokeSensationDevInfoDTO.setKeyword(keyword);
|
|
|
+ smokeSensationDevInfoDTO.setOnline(online);
|
|
|
+ smokeSensationDevInfoDTO.setSectionList(toolUtils.getSectionList(request));
|
|
|
+ SmokeSensationDevInfoVO smokeSensationDevInfoVO = smokeSensationDevInfoService.getListBySmokeSensationDevInfoDTO(smokeSensationDevInfoDTO);
|
|
|
+ return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,smokeSensationDevInfoVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加编辑智能烟感
|
|
|
+ * @param request 有id编辑,无id添加
|
|
|
+ * @return 更新数据
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "save", method = RequestMethod.POST)
|
|
|
+ public BaseResult<?> save(HttpServletRequest request) {
|
|
|
+ int version = (int) toolUtils.getRequestContent(request,"version",1);
|
|
|
+ int id = (int) toolUtils.getRequestContent(request,"id",1);
|
|
|
+ int model = (int) toolUtils.getRequestContent(request,"model",1);
|
|
|
+ int areaId = (int) toolUtils.getRequestContent(request,"areaId",1);
|
|
|
+ int sectionId = (int) toolUtils.getRequestContent(request,"sectionId",1);
|
|
|
+ String number = (String) toolUtils.getRequestContent(request,"number",2);
|
|
|
+ String name = (String) toolUtils.getRequestContent(request,"name",2);
|
|
|
+ String address = (String) toolUtils.getRequestContent(request,"address",2);
|
|
|
+ String longitude = (String) toolUtils.getRequestContent(request,"longitude",2);
|
|
|
+ String latitude = (String) toolUtils.getRequestContent(request,"latitude",2);
|
|
|
+
|
|
|
+ SmokeSensationDevInfoDTO smokeSensationDevInfoDTO = new SmokeSensationDevInfoDTO();
|
|
|
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ smokeSensationDevInfoDTO.setModel(model);
|
|
|
+ smokeSensationDevInfoDTO.setAreaId(areaId);
|
|
|
+ smokeSensationDevInfoDTO.setSectionId(sectionId);
|
|
|
+ smokeSensationDevInfoDTO.setNumber(number);
|
|
|
+ smokeSensationDevInfoDTO.setName(name);
|
|
|
+ smokeSensationDevInfoDTO.setAddress(address);
|
|
|
+ smokeSensationDevInfoDTO.setLongitude(longitude);
|
|
|
+ smokeSensationDevInfoDTO.setLatitude(latitude);
|
|
|
+ smokeSensationDevInfoDTO.setUpdateTime(simpleDateFormat.format(System.currentTimeMillis()));
|
|
|
+ if (id == 0) { // 添加
|
|
|
+ smokeSensationDevInfoDTO.setCreateTime(simpleDateFormat.format(System.currentTimeMillis()));
|
|
|
+ if (String.valueOf(model).length() == 0) return toolUtils.response(InterfaceResultEnum.LACK_SMOKE_SENSATION_MODEL_ERROR,version);
|
|
|
+ if (areaId == 0) return toolUtils.response(InterfaceResultEnum.LACK_AREA_ERROR,version);
|
|
|
+ if (sectionId == 0) return toolUtils.response(InterfaceResultEnum.LACK_SECTION_ERROR,version);
|
|
|
+ if (number == null || number.length() == 0) return toolUtils.response(InterfaceResultEnum.LACK_SMOKE_SENSATION_NUMBER_ERROR,version);
|
|
|
+ if (name == null || name.length() == 0) return toolUtils.response(InterfaceResultEnum.LACK_SMOKE_SENSATION_NAME_ERROR,version);
|
|
|
+ if (address == null || address.length() == 0) return toolUtils.response(InterfaceResultEnum.LACK_SMOKE_SENSATION_ADDRESS_ERROR,version);
|
|
|
+
|
|
|
+ SmokeSensationDevInfoDTO dto = new SmokeSensationDevInfoDTO();
|
|
|
+ dto.setSectionId(sectionId);
|
|
|
+ dto.setName(name);
|
|
|
+ if (smokeSensationDevInfoService.findSmokeSensationByDTO(dto) > 0)
|
|
|
+ return toolUtils.response(InterfaceResultEnum.SMOKE_SENSATION_NAME_UNIQUE_ERROR,version);
|
|
|
+ dto = new SmokeSensationDevInfoDTO();
|
|
|
+ dto.setSectionId(sectionId);
|
|
|
+ dto.setNumber(number);
|
|
|
+ if (smokeSensationDevInfoService.findSmokeSensationByDTO(dto) > 0)
|
|
|
+ return toolUtils.response(InterfaceResultEnum.SMOKE_SENSATION_NUMBER_UNIQUE_ERROR,version);
|
|
|
+ dto = new SmokeSensationDevInfoDTO();
|
|
|
+ dto.setAddress(address);
|
|
|
+ if (smokeSensationDevInfoService.findAddressBySmokeSensationDTO(dto) > 0)
|
|
|
+ return toolUtils.response(InterfaceResultEnum.SMOKE_SENSATION_ADDRESS_UNIQUE_ERROR,version);
|
|
|
+ smokeSensationDevInfoService.addSmokeSensationDataByDTO(smokeSensationDevInfoDTO);
|
|
|
+ } else { // 编辑
|
|
|
+ smokeSensationDevInfoDTO.setId(id);
|
|
|
+ if (String.valueOf(model).length() == 0) return toolUtils.response(InterfaceResultEnum.LACK_SMOKE_SENSATION_MODEL_ERROR,version);
|
|
|
+ if (areaId == 0) return toolUtils.response(InterfaceResultEnum.LACK_AREA_ERROR,version);
|
|
|
+ if (sectionId == 0) return toolUtils.response(InterfaceResultEnum.LACK_SECTION_ERROR,version);
|
|
|
+ if (number == null || number.length() == 0) return toolUtils.response(InterfaceResultEnum.LACK_SMOKE_SENSATION_NUMBER_ERROR,version);
|
|
|
+ if (name == null || name.length() == 0) return toolUtils.response(InterfaceResultEnum.LACK_SMOKE_SENSATION_NAME_ERROR,version);
|
|
|
+ if (address == null || address.length() == 0) return toolUtils.response(InterfaceResultEnum.LACK_SMOKE_SENSATION_ADDRESS_ERROR,version);
|
|
|
+
|
|
|
+ SmokeSensationDevInfoDTO dto = new SmokeSensationDevInfoDTO();
|
|
|
+ dto.setId(id);
|
|
|
+ dto.setSectionId(sectionId);
|
|
|
+ dto.setName(name);
|
|
|
+ if (smokeSensationDevInfoService.findSmokeSensationByDTO(dto) > 0)
|
|
|
+ return toolUtils.response(InterfaceResultEnum.SMOKE_SENSATION_NAME_UNIQUE_ERROR,version);
|
|
|
+ dto = new SmokeSensationDevInfoDTO();
|
|
|
+ dto.setId(id);
|
|
|
+ dto.setSectionId(sectionId);
|
|
|
+ dto.setNumber(number);
|
|
|
+ if (smokeSensationDevInfoService.findSmokeSensationByDTO(dto) > 0)
|
|
|
+ return toolUtils.response(InterfaceResultEnum.SMOKE_SENSATION_NUMBER_UNIQUE_ERROR,version);
|
|
|
+ dto = new SmokeSensationDevInfoDTO();
|
|
|
+ dto.setId(id);
|
|
|
+ dto.setAddress(address);
|
|
|
+ if (smokeSensationDevInfoService.findAddressBySmokeSensationDTO(dto) > 0)
|
|
|
+ return toolUtils.response(InterfaceResultEnum.SMOKE_SENSATION_ADDRESS_UNIQUE_ERROR,version);
|
|
|
+ smokeSensationDevInfoService.updateSmokeSensationDataByDTO(smokeSensationDevInfoDTO);
|
|
|
+ }
|
|
|
+ return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除烟感
|
|
|
+ * @param request id
|
|
|
+ * @return 删除成功
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "del")
|
|
|
+ public BaseResult<?> del(HttpServletRequest request) {
|
|
|
+ int version = (int) toolUtils.getRequestContent(request,"version",1);
|
|
|
+ String id = (String) toolUtils.getRequestContent(request,"id",2);
|
|
|
+ if (id == null || id.length() == 0) return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR,version);
|
|
|
+ List<String> smokeIds = Arrays.asList(id.split(","));
|
|
|
+ smokeSensationDevInfoService.deleteSmokeSensationById(smokeIds);
|
|
|
+ return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 智能烟感设备概览
|
|
|
+ * @param request 路段筛选
|
|
|
+ * @return 总数,正常、故障、报警、在线、新建数
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "data", method = RequestMethod.POST)
|
|
|
+ public BaseResult<?> data(HttpServletRequest request) {
|
|
|
+ int version = (int) toolUtils.getRequestContent(request,"version",1);
|
|
|
+ SmokeSensationDevInfoDTO smokeSensationDevInfoDTO = new SmokeSensationDevInfoDTO();
|
|
|
+ smokeSensationDevInfoDTO.setSectionList(toolUtils.getSectionList(request));
|
|
|
+ SmokeSensationDevInfoVO smokeSensationData = smokeSensationDevInfoService.getSmokeSensationData(smokeSensationDevInfoDTO);
|
|
|
+ return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,smokeSensationData);
|
|
|
+ }
|
|
|
+}
|