AcDeviceController.java 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. package com.welampiot.controller;
  2. import com.welampiot.common.BaseResult;
  3. import com.welampiot.common.InterfaceResultEnum;
  4. import com.welampiot.dto.AcDevInfoDTO;
  5. import com.welampiot.service.AcDevInfoService;
  6. import com.welampiot.utils.ExcelUtil;
  7. import com.welampiot.utils.ToolUtils;
  8. import com.welampiot.vo.AcDevInfoVO;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.web.bind.annotation.CrossOrigin;
  11. import org.springframework.web.bind.annotation.RequestMapping;
  12. import org.springframework.web.bind.annotation.RequestMethod;
  13. import org.springframework.web.bind.annotation.RestController;
  14. import javax.servlet.http.HttpServletRequest;
  15. import java.text.SimpleDateFormat;
  16. import java.util.ArrayList;
  17. import java.util.Arrays;
  18. import java.util.List;
  19. /**
  20. * ClassName: AcDeviceController
  21. * Package: com.welampiot.controller
  22. * Description:
  23. *
  24. * @Author: zhj_Start
  25. * @Create: 2023/8/3 - 14:53
  26. * @Version: v1.0
  27. */
  28. @RestController
  29. @CrossOrigin
  30. @RequestMapping("/acDevice")
  31. public class AcDeviceController {
  32. @Autowired
  33. private ToolUtils toolUtils;
  34. @Autowired
  35. private AcDevInfoService acDevInfoService;
  36. /**
  37. * 获取AC的列表
  38. * @param request sectionList,page,count,keyword
  39. * @return 获取AC的列表
  40. */
  41. @RequestMapping(value = "/acGetList", method = RequestMethod.POST)
  42. public BaseResult<?> acGetList(HttpServletRequest request) {
  43. Integer version = (Integer) toolUtils.getRequestContent(request,"version",1);
  44. Integer areaId = (Integer) toolUtils.getRequestContent(request,"areaId",1);
  45. Integer sectionId = (Integer) toolUtils.getRequestContent(request,"sectionId",1);
  46. Integer page = (Integer) toolUtils.getRequestContent(request,"page",1);
  47. Integer count = (Integer) toolUtils.getRequestContent(request,"count",1);
  48. Integer download = (Integer) toolUtils.getRequestContent(request,"download",1);
  49. String keyword = (String) toolUtils.getRequestContent(request,"keyword",2);
  50. if (page == 0) page = 1;
  51. if (count == 0) count = 16;
  52. AcDevInfoVO acDevInfoVO = new AcDevInfoVO();
  53. acDevInfoVO.setAreaId(areaId);
  54. acDevInfoVO.setSectionId(sectionId);
  55. acDevInfoVO.setVersion(version);
  56. if (download == 0) {
  57. acDevInfoVO.setPage(count * (page - 1));
  58. acDevInfoVO.setCount(count);
  59. }
  60. acDevInfoVO.setKeyword(keyword);
  61. acDevInfoVO.setSectionList(toolUtils.getSectionList(request));
  62. List<AcDevInfoDTO> acDevList = acDevInfoService.getAcDevListByVO(acDevInfoVO);
  63. AcDevInfoVO vo = new AcDevInfoVO();
  64. vo.setList(acDevList);
  65. if (download == 0) {
  66. Integer acDevTotal = acDevInfoService.getAcDevTotal(acDevInfoVO);
  67. double total = Math.ceil((double) acDevTotal / count);
  68. vo.setTotal((int) total);
  69. }
  70. if (download == 1) {
  71. String title;
  72. if (version == 0) {
  73. title = "编号,ac设备地址,ac设备名称,ip,行政区,路段,创建时间";
  74. } else if (version == 1) {
  75. title = "Number,Ac Device Address,Ac Device Name,IP,District,Road Section,Creation Time";
  76. } else {
  77. title = "Номер,адрес оборудования ac,название оборудования ac," +
  78. "ip,административный район,участок дороги,время создания";
  79. }
  80. List<String> titleList = Arrays.asList(title.split(","));
  81. List<List<String>> contentList = new ArrayList<>();
  82. for (AcDevInfoDTO a : acDevList) {
  83. List<String> newString = new ArrayList<>();
  84. newString.add(0, String.valueOf(acDevList.indexOf(a) + 1));
  85. newString.add(1,a.getAcAddress());
  86. newString.add(2,a.getDeviceName());
  87. newString.add(3,a.getNetworkIP());
  88. newString.add(4,a.getArea());
  89. newString.add(5,a.getSection());
  90. newString.add(6,a.getCreateTime());
  91. contentList.add(acDevList.indexOf(a),newString);
  92. }
  93. String path = ExcelUtil.outExcel(titleList, contentList);
  94. vo.setPath(path);
  95. }
  96. return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,vo);
  97. }
  98. /**
  99. * 删除AC设备
  100. * @param request 设备id
  101. * @return 删除AC设备
  102. */
  103. @RequestMapping(value = "/acDel", method = RequestMethod.POST)
  104. public BaseResult<?> acDel(HttpServletRequest request) {
  105. Integer version = (Integer) toolUtils.getRequestContent(request,"version",1);
  106. String id = (String) toolUtils.getRequestContent(request,"id",2);
  107. if (id.length() == 0) return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR,version);
  108. List<String> strings = Arrays.asList(id.split(","));
  109. acDevInfoService.deleteAcDevData(strings);
  110. return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version);
  111. }
  112. /**
  113. * 添加编辑AC设备
  114. * @param request 设备属性
  115. * @return 添加编辑AC设备
  116. */
  117. @RequestMapping(value = "/acAdd", method = RequestMethod.POST)
  118. public BaseResult<?> acAdd(HttpServletRequest request) {
  119. Integer version = (Integer) toolUtils.getRequestContent(request,"version",1);
  120. Integer id = (Integer) toolUtils.getRequestContent(request,"id",1);
  121. Integer type = (Integer) toolUtils.getRequestContent(request,"type",1);
  122. Integer areaId = (Integer) toolUtils.getRequestContent(request,"areaId",1);
  123. Integer sectionId = (Integer) toolUtils.getRequestContent(request,"sectionId",1);
  124. String deviceName = (String) toolUtils.getRequestContent(request,"deviceName",2);
  125. String acAddress = (String) toolUtils.getRequestContent(request,"acAddress",2);
  126. String networkIP = (String) toolUtils.getRequestContent(request,"networkIP",2);
  127. String longitude = (String) toolUtils.getRequestContent(request,"longitude",2);
  128. String latitude = (String) toolUtils.getRequestContent(request,"latitude",2);
  129. if (areaId == 0) return toolUtils.response(InterfaceResultEnum.LACK_AREA_ERROR,version);
  130. if (sectionId == 0) return toolUtils.response(InterfaceResultEnum.LACK_SECTION_ERROR,version);
  131. if (deviceName.length() == 0 || acAddress.length() == 0)
  132. return toolUtils.response(InterfaceResultEnum.LACK_NEED_PARAM,version);
  133. if (type == 0) {
  134. if (networkIP.length() == 0)
  135. return toolUtils.response(InterfaceResultEnum.LACK_NEED_PARAM,version);
  136. }
  137. if (latitude.length() == 0) latitude = "0";
  138. if (longitude.length() == 0) longitude = "0";
  139. AcDevInfoDTO acDevInfoDTO = new AcDevInfoDTO();
  140. acDevInfoDTO.setType(type);
  141. acDevInfoDTO.setAcAddress(acAddress);
  142. acDevInfoDTO.setDeviceName(deviceName);
  143. acDevInfoDTO.setAreaId(areaId);
  144. acDevInfoDTO.setSectionId(sectionId);
  145. acDevInfoDTO.setNetworkIP(networkIP);
  146. acDevInfoDTO.setLongitude(Double.valueOf(longitude));
  147. acDevInfoDTO.setLatitude(Double.valueOf(latitude));
  148. long l = System.currentTimeMillis();
  149. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  150. String format = simpleDateFormat.format(l);
  151. if (id == 0) { // 添加
  152. acDevInfoDTO.setCreateTime(format);
  153. acDevInfoDTO.setUpdateTime(format);
  154. AcDevInfoDTO dto = new AcDevInfoDTO();
  155. dto.setSectionId(sectionId);
  156. dto.setDeviceName(deviceName);
  157. if (acDevInfoService.checkAcDevData(dto) > 0)
  158. return toolUtils.response(InterfaceResultEnum.AC_NAME_UNIQUE_ERROR,version);
  159. dto = new AcDevInfoDTO();
  160. dto.setAcAddress(acAddress);
  161. if (acDevInfoService.checkAcDevData(dto) > 0)
  162. return toolUtils.response(InterfaceResultEnum.AC_ADDRESS_UNIQUE_ERROR,version);
  163. acDevInfoService.addAcDevData(acDevInfoDTO);
  164. } else { // 编辑
  165. acDevInfoDTO.setId(id);
  166. acDevInfoDTO.setUpdateTime(format);
  167. AcDevInfoDTO dto = new AcDevInfoDTO();
  168. dto.setId(id);
  169. dto.setSectionId(sectionId);
  170. dto.setDeviceName(deviceName);
  171. if (acDevInfoService.checkAcDevData(dto) > 0)
  172. return toolUtils.response(InterfaceResultEnum.AC_NAME_UNIQUE_ERROR,version);
  173. dto = new AcDevInfoDTO();
  174. dto.setId(id);
  175. dto.setAcAddress(acAddress);
  176. if (acDevInfoService.checkAcDevData(dto) > 0)
  177. return toolUtils.response(InterfaceResultEnum.AC_ADDRESS_UNIQUE_ERROR,version);
  178. acDevInfoService.updateAcDevData(acDevInfoDTO);
  179. }
  180. return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version);
  181. }
  182. }