|
@@ -0,0 +1,188 @@
|
|
|
+package com.welampiot.controller;
|
|
|
+
|
|
|
+import com.welampiot.common.BaseResult;
|
|
|
+import com.welampiot.common.InterfaceResultEnum;
|
|
|
+import com.welampiot.dto.AcDevInfoDTO;
|
|
|
+import com.welampiot.service.AcDevInfoService;
|
|
|
+import com.welampiot.utils.ExcelUtil;
|
|
|
+import com.welampiot.utils.ToolUtils;
|
|
|
+import com.welampiot.vo.AcDevInfoVO;
|
|
|
+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.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * ClassName: AcDeviceController
|
|
|
+ * Package: com.welampiot.controller
|
|
|
+ * Description:
|
|
|
+ *
|
|
|
+ * @Author: zhj_Start
|
|
|
+ * @Create: 2023/8/3 - 14:53
|
|
|
+ * @Version: v1.0
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@CrossOrigin
|
|
|
+@RequestMapping("/acDevice")
|
|
|
+public class AcDeviceController {
|
|
|
+ @Autowired
|
|
|
+ private ToolUtils toolUtils;
|
|
|
+ @Autowired
|
|
|
+ private AcDevInfoService acDevInfoService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取AC的列表
|
|
|
+ * @param request sectionList,page,count,keyword
|
|
|
+ * @return 获取AC的列表
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/acGetList", method = RequestMethod.POST)
|
|
|
+ public BaseResult<?> acGetList(HttpServletRequest request) {
|
|
|
+ Integer version = (Integer) toolUtils.getRequestContent(request,"version",1);
|
|
|
+ Integer areaId = (Integer) toolUtils.getRequestContent(request,"areaId",1);
|
|
|
+ Integer sectionId = (Integer) toolUtils.getRequestContent(request,"sectionId",1);
|
|
|
+ Integer page = (Integer) toolUtils.getRequestContent(request,"page",1);
|
|
|
+ Integer count = (Integer) toolUtils.getRequestContent(request,"count",1);
|
|
|
+ Integer download = (Integer) toolUtils.getRequestContent(request,"download",1);
|
|
|
+ String keyword = (String) toolUtils.getRequestContent(request,"keyword",2);
|
|
|
+ if (page == 0) page = 1;
|
|
|
+ if (count == 0) count = 16;
|
|
|
+ AcDevInfoVO acDevInfoVO = new AcDevInfoVO();
|
|
|
+ acDevInfoVO.setAreaId(areaId);
|
|
|
+ acDevInfoVO.setSectionId(sectionId);
|
|
|
+ acDevInfoVO.setVersion(version);
|
|
|
+ if (download == 0) {
|
|
|
+ acDevInfoVO.setPage(count * (page - 1));
|
|
|
+ acDevInfoVO.setCount(count);
|
|
|
+ }
|
|
|
+ acDevInfoVO.setKeyword(keyword);
|
|
|
+ acDevInfoVO.setSectionList(toolUtils.getSectionList(request));
|
|
|
+ List<AcDevInfoDTO> acDevList = acDevInfoService.getAcDevListByVO(acDevInfoVO);
|
|
|
+ AcDevInfoVO vo = new AcDevInfoVO();
|
|
|
+ vo.setList(acDevList);
|
|
|
+ if (download == 0) {
|
|
|
+ Integer acDevTotal = acDevInfoService.getAcDevTotal(acDevInfoVO);
|
|
|
+ double total = Math.ceil((double) acDevTotal / count);
|
|
|
+ vo.setTotal((int) total);
|
|
|
+ }
|
|
|
+ if (download == 1) {
|
|
|
+ String title;
|
|
|
+ if (version == 0) {
|
|
|
+ title = "编号,ac设备地址,ac设备名称,ip,行政区,路段,创建时间";
|
|
|
+ } else if (version == 1) {
|
|
|
+ title = "Number,Ac Device Address,Ac Device Name,IP,District,Road Section,Creation Time";
|
|
|
+ } else {
|
|
|
+ title = "Номер,адрес оборудования ac,название оборудования ac," +
|
|
|
+ "ip,административный район,участок дороги,время создания";
|
|
|
+ }
|
|
|
+ List<String> titleList = Arrays.asList(title.split(","));
|
|
|
+ List<List<String>> contentList = new ArrayList<>();
|
|
|
+ for (AcDevInfoDTO a : acDevList) {
|
|
|
+ List<String> newString = new ArrayList<>();
|
|
|
+ newString.add(0, String.valueOf(acDevList.indexOf(a) + 1));
|
|
|
+ newString.add(1,a.getAcAddress());
|
|
|
+ newString.add(2,a.getDeviceName());
|
|
|
+ newString.add(3,a.getNetworkIP());
|
|
|
+ newString.add(4,a.getArea());
|
|
|
+ newString.add(5,a.getSection());
|
|
|
+ newString.add(6,a.getCreateTime());
|
|
|
+ contentList.add(acDevList.indexOf(a),newString);
|
|
|
+ }
|
|
|
+ String path = ExcelUtil.outExcel(titleList, contentList);
|
|
|
+ vo.setPath(path);
|
|
|
+ }
|
|
|
+ return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,vo);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除AC设备
|
|
|
+ * @param request 设备id
|
|
|
+ * @return 删除AC设备
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/acDel", method = RequestMethod.POST)
|
|
|
+ public BaseResult<?> acDel(HttpServletRequest request) {
|
|
|
+ Integer version = (Integer) toolUtils.getRequestContent(request,"version",1);
|
|
|
+ String id = (String) toolUtils.getRequestContent(request,"id",2);
|
|
|
+ if (id.length() == 0) return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR,version);
|
|
|
+ List<String> strings = Arrays.asList(id.split(","));
|
|
|
+ acDevInfoService.deleteAcDevData(strings);
|
|
|
+ return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加编辑AC设备
|
|
|
+ * @param request 设备属性
|
|
|
+ * @return 添加编辑AC设备
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/acAdd", method = RequestMethod.POST)
|
|
|
+ public BaseResult<?> acAdd(HttpServletRequest request) {
|
|
|
+ Integer version = (Integer) toolUtils.getRequestContent(request,"version",1);
|
|
|
+ Integer id = (Integer) toolUtils.getRequestContent(request,"id",1);
|
|
|
+ Integer type = (Integer) toolUtils.getRequestContent(request,"type",1);
|
|
|
+ Integer areaId = (Integer) toolUtils.getRequestContent(request,"areaId",1);
|
|
|
+ Integer sectionId = (Integer) toolUtils.getRequestContent(request,"sectionId",1);
|
|
|
+ String deviceName = (String) toolUtils.getRequestContent(request,"deviceName",2);
|
|
|
+ String acAddress = (String) toolUtils.getRequestContent(request,"acAddress",2);
|
|
|
+ String networkIP = (String) toolUtils.getRequestContent(request,"networkIP",2);
|
|
|
+ String longitude = (String) toolUtils.getRequestContent(request,"longitude",2);
|
|
|
+ String latitude = (String) toolUtils.getRequestContent(request,"latitude",2);
|
|
|
+ if (areaId == 0) return toolUtils.response(InterfaceResultEnum.LACK_AREA_ERROR,version);
|
|
|
+ if (sectionId == 0) return toolUtils.response(InterfaceResultEnum.LACK_SECTION_ERROR,version);
|
|
|
+ if (deviceName.length() == 0 || acAddress.length() == 0)
|
|
|
+ return toolUtils.response(InterfaceResultEnum.LACK_NEED_PARAM,version);
|
|
|
+ if (type == 0) {
|
|
|
+ if (networkIP.length() == 0)
|
|
|
+ return toolUtils.response(InterfaceResultEnum.LACK_NEED_PARAM,version);
|
|
|
+ }
|
|
|
+ if (latitude.length() == 0) latitude = "0";
|
|
|
+ if (longitude.length() == 0) longitude = "0";
|
|
|
+ AcDevInfoDTO acDevInfoDTO = new AcDevInfoDTO();
|
|
|
+ acDevInfoDTO.setType(type);
|
|
|
+ acDevInfoDTO.setAcAddress(acAddress);
|
|
|
+ acDevInfoDTO.setDeviceName(deviceName);
|
|
|
+ acDevInfoDTO.setAreaId(areaId);
|
|
|
+ acDevInfoDTO.setSectionId(sectionId);
|
|
|
+ acDevInfoDTO.setNetworkIP(networkIP);
|
|
|
+ acDevInfoDTO.setLongitude(Double.valueOf(longitude));
|
|
|
+ acDevInfoDTO.setLatitude(Double.valueOf(latitude));
|
|
|
+ long l = System.currentTimeMillis();
|
|
|
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ String format = simpleDateFormat.format(l);
|
|
|
+ if (id == 0) { // 添加
|
|
|
+ acDevInfoDTO.setCreateTime(format);
|
|
|
+ acDevInfoDTO.setUpdateTime(format);
|
|
|
+ AcDevInfoDTO dto = new AcDevInfoDTO();
|
|
|
+ dto.setSectionId(sectionId);
|
|
|
+ dto.setDeviceName(deviceName);
|
|
|
+ if (acDevInfoService.checkAcDevData(dto) > 0)
|
|
|
+ return toolUtils.response(InterfaceResultEnum.AC_NAME_UNIQUE_ERROR,version);
|
|
|
+ dto = new AcDevInfoDTO();
|
|
|
+ dto.setAcAddress(acAddress);
|
|
|
+ if (acDevInfoService.checkAcDevData(dto) > 0)
|
|
|
+ return toolUtils.response(InterfaceResultEnum.AC_ADDRESS_UNIQUE_ERROR,version);
|
|
|
+ acDevInfoService.addAcDevData(acDevInfoDTO);
|
|
|
+ } else { // 编辑
|
|
|
+ acDevInfoDTO.setId(id);
|
|
|
+ acDevInfoDTO.setUpdateTime(format);
|
|
|
+ AcDevInfoDTO dto = new AcDevInfoDTO();
|
|
|
+ dto.setId(id);
|
|
|
+ dto.setSectionId(sectionId);
|
|
|
+ dto.setDeviceName(deviceName);
|
|
|
+ if (acDevInfoService.checkAcDevData(dto) > 0)
|
|
|
+ return toolUtils.response(InterfaceResultEnum.AC_NAME_UNIQUE_ERROR,version);
|
|
|
+ dto = new AcDevInfoDTO();
|
|
|
+ dto.setId(id);
|
|
|
+ dto.setAcAddress(acAddress);
|
|
|
+ if (acDevInfoService.checkAcDevData(dto) > 0)
|
|
|
+ return toolUtils.response(InterfaceResultEnum.AC_ADDRESS_UNIQUE_ERROR,version);
|
|
|
+ acDevInfoService.updateAcDevData(acDevInfoDTO);
|
|
|
+ }
|
|
|
+ return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version);
|
|
|
+ }
|
|
|
+}
|