LampController.java 90 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790
  1. package com.welampiot.controller;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson.JSONArray;
  4. import com.alibaba.fastjson.JSONObject;
  5. import com.fasterxml.jackson.core.JsonProcessingException;
  6. import com.fasterxml.jackson.databind.ObjectMapper;
  7. import com.welampiot.common.BaseResult;
  8. import com.welampiot.common.InterfaceResultEnum;
  9. import com.welampiot.configuration.*;
  10. import com.welampiot.dto.*;
  11. import com.welampiot.service.*;
  12. import com.welampiot.utils.AESUtils;
  13. import com.welampiot.utils.JwtUtil;
  14. import com.welampiot.utils.ToolUtils;
  15. import com.welampiot.vo.*;
  16. import org.apache.commons.lang3.ArrayUtils;
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.transaction.annotation.Transactional;
  19. import org.springframework.util.DigestUtils;
  20. import org.springframework.web.bind.annotation.CrossOrigin;
  21. import org.springframework.web.bind.annotation.RequestMapping;
  22. import org.springframework.web.bind.annotation.RequestMethod;
  23. import org.springframework.web.bind.annotation.RestController;
  24. import javax.servlet.http.HttpServletRequest;
  25. import java.io.IOException;
  26. import java.nio.charset.StandardCharsets;
  27. import java.text.DecimalFormat;
  28. import java.text.ParseException;
  29. import java.text.SimpleDateFormat;
  30. import java.util.*;
  31. import java.util.stream.Collectors;
  32. @RestController
  33. @CrossOrigin
  34. @RequestMapping("/lamp")
  35. public class LampController {
  36. @Autowired
  37. private LampService lampService;
  38. @Autowired
  39. private ToolUtils toolUtils;
  40. @Autowired
  41. private NetworkService networkService;
  42. @Autowired
  43. private GroupService groupService;
  44. @Autowired
  45. private GlobalLocationService globalLocationService;
  46. @Autowired
  47. private SectionService sectionService;
  48. @Autowired
  49. private SolarDevService solarDevService;
  50. @Autowired
  51. private SolarInfoLogService solarInfoLogService;
  52. @Autowired
  53. private LampPoleService lampPoleService;
  54. @Autowired
  55. private QuHuiPlc quHuiPlc;
  56. @Autowired
  57. private ZhongLightPlc zhongLightPlc;
  58. @Autowired
  59. private AESUtils aesUtils;
  60. @Autowired
  61. private PlcAddressService plcAddressService;
  62. @Autowired
  63. private FreqMapConfig freqMapConfig;
  64. @Autowired
  65. private JwtUtil jwtUtil;
  66. @Autowired
  67. private LastSqlInterceptor lastSqlInterceptor; //获取sql语句
  68. /**
  69. * 灯控列表
  70. * @param request
  71. * @return
  72. */
  73. @RequestMapping(value = "/getlist",method = RequestMethod.POST)
  74. public BaseResult<InfoResponseVO> getList(HttpServletRequest request){
  75. Integer version = request.getParameter("version") == null ? 0 : Integer.parseInt(request.getParameter("version"));
  76. Integer page = request.getParameter("page") == null ? 1 : Integer.parseInt(request.getParameter("page"));
  77. Integer count = request.getParameter("count") == null ? 16 : Integer.parseInt(request.getParameter("count"));
  78. Integer online = request.getParameter("online") == null || request.getParameter("online") == "" ? null : Integer.parseInt(request.getParameter("online"));
  79. Integer light_status = request.getParameter("light_status") == null || request.getParameter("light_status") == "" ? null : Integer.parseInt(request.getParameter("light_status"));
  80. String keyword = request.getParameter("keyword") == null ? "" : request.getParameter("keyword");
  81. Integer limit = count;
  82. Integer offset = (page-1)*count;
  83. List sectionList = toolUtils.getSectionList(request);
  84. LampListResponseVO lampListResponseVO = new LampListResponseVO();
  85. if (keyword.length() > 0) lampListResponseVO.setKeyword(keyword);
  86. lampListResponseVO.setSectionList(sectionList);
  87. lampListResponseVO.setVersion(version);
  88. lampListResponseVO.setLimit(limit);
  89. lampListResponseVO.setOffset(offset);
  90. if (online != null) lampListResponseVO.setOnline(online);
  91. if (light_status != null) lampListResponseVO.setLightStatus(light_status);
  92. List<LampInfoDTO> listByVO = lampService.getListByVO(lampListResponseVO);
  93. LampListResponseVO lampListResponseVO1 = new LampListResponseVO();
  94. lampListResponseVO1.setList(listByVO);
  95. LampCountVO lampCountVO = new LampCountVO();
  96. lampCountVO.setSectionList(sectionList);
  97. if (online != null) lampCountVO.setOnlineStatus(online);
  98. if (light_status != null) lampCountVO.setLampStatus(light_status);
  99. if (keyword.length() > 0) lampCountVO.setKeyword(keyword);
  100. Integer countByVO = lampService.getCountByVO(lampCountVO);
  101. lampListResponseVO1.setTotal(countByVO/count);
  102. lampListResponseVO1.setTotal2(countByVO);
  103. lampCountVO = new LampCountVO();
  104. lampCountVO.setSectionList(sectionList);
  105. countByVO = lampService.getCountByVO(lampCountVO);
  106. lampListResponseVO1.setDevTotal(countByVO);
  107. lampCountVO.setOnlineStatus(1);
  108. countByVO = lampService.getCountByVO(lampCountVO);
  109. lampListResponseVO1.setOnlineCount(countByVO);
  110. lampCountVO.setLampStatus(1);
  111. countByVO = lampService.getCountByVO(lampCountVO);
  112. lampListResponseVO1.setLightCount(countByVO);
  113. lampCountVO.setAlarmStatus(1);
  114. lampListResponseVO1.setAlarmCount(countByVO);
  115. return BaseResult.success(lampListResponseVO1);
  116. }
  117. /**
  118. * 灯控详情
  119. * @param request
  120. * @return
  121. */
  122. @RequestMapping(value = "/details",method = RequestMethod.POST)
  123. public BaseResult<LampInfoDTO> details(HttpServletRequest request){
  124. Integer version = request.getParameter("version") == null ? 0 : Integer.parseInt(request.getParameter("version"));
  125. Integer lampId = request.getParameter("lampId") == null ? 0 : Integer.parseInt(request.getParameter("lampId"));
  126. LampInfoDTO detailsById = lampService.getDetailsById(lampId,version);
  127. return BaseResult.success(detailsById);
  128. }
  129. @RequestMapping(value = "/getkk", method = RequestMethod.POST)
  130. public Integer kk(HttpServletRequest request) {
  131. toolUtils.addOpertaionLog(request,null,null,null,null,null,null,null,null,null,null,null,null,null);
  132. return 0;
  133. }
  134. /**
  135. * 添加编辑灯控
  136. * @param request
  137. * @return
  138. */
  139. @RequestMapping(value = "/save",method = RequestMethod.POST)
  140. @Transactional
  141. public BaseResult save(HttpServletRequest request){
  142. Integer version = request.getParameter("version") == null ? 0 : Integer.parseInt(request.getParameter("version"));
  143. Integer lampId = request.getParameter("lampId") == null || request.getParameter("lampId").length() == 0? 0 : Integer.parseInt(request.getParameter("lampId"));
  144. String area = request.getParameter("areaId");// == null ? 0 : Integer.parseInt(request.getParameter("areaId"));
  145. if (area == null || area.equals("0")) return toolUtils.response(InterfaceResultEnum.LACK_AREA_ERROR,version);
  146. Integer areaId = Integer.parseInt(area);
  147. String section = request.getParameter("sectionId"); // == null ? 0 : Integer.parseInt(request.getParameter("sectionId"));
  148. if (section == null || section.equals("0")) return toolUtils.response(InterfaceResultEnum.LACK_SECTION_ERROR,version);
  149. Integer sectionId = Integer.parseInt(section);
  150. String protocol = request.getParameter("protocolType");// == null ? 0 : Integer.parseInt(request.getParameter("protocolType"));
  151. if (protocol == null) return toolUtils.response(InterfaceResultEnum.LACK_PROTOCOL_TYPE_ERROR,version);
  152. Integer protocolType = Integer.parseInt(protocol);
  153. String control = request.getParameter("controlType");// == null ? 0 : Integer.parseInt(request.getParameter("controlType"));
  154. if (control == null) return toolUtils.response(InterfaceResultEnum.LACK_LOOP_CONTROL_TYPE_ERROR,version);
  155. Integer controlType = Integer.parseInt(control);
  156. Integer power = request.getParameter("power") == null ? 0 : Integer.parseInt(request.getParameter("power"));
  157. String installDate = request.getParameter("installDate") == null ? "" : request.getParameter("installDate");
  158. String expirationDate = request.getParameter("expirationDate") == null ? "" : request.getParameter("expirationDate");
  159. String number = request.getParameter("number");
  160. if (number == null || number.length() == 0) return toolUtils.response(InterfaceResultEnum.LIGHT_NUMBER_ERROR,version);
  161. if (number.length() == 1 && number.equals("0")) return toolUtils.response(InterfaceResultEnum.LIGHT_NUMBER_ZERO_ERROR,version);
  162. if (number.length() > 6) return toolUtils.response(InterfaceResultEnum.LIGHT_NUMBER_LENGTH_ERROR,version);
  163. String regex = "^[A-Za-z0-9_]+$";
  164. if (number.matches(regex) == false) return toolUtils.response(InterfaceResultEnum.LIGHT_NUMBER_NAME_ERROR,version);
  165. if (number.length() < 6){
  166. //初全长度为6
  167. number = "000000"+number;
  168. number = number.substring(number.length() - 6,number.length());
  169. }
  170. String longitude = request.getParameter("longitude") == null || request.getParameter("longitude").length() == 0 ? "0" : request.getParameter("longitude");
  171. String latitude = request.getParameter("latitude") == null || request.getParameter("latitude").length() == 0 ? "0" : request.getParameter("latitude");
  172. String name = request.getParameter("name");
  173. String sn = request.getParameter("sn");
  174. if (sn == null || sn.length() == 0) return toolUtils.response(InterfaceResultEnum.LACK_ADDRESS_ERROR,version);
  175. sn = sn.trim();//去除两边的空格
  176. String devAddr = request.getParameter("devAddr");
  177. Integer bindStatus = 1;
  178. if (protocolType == 11 && (controlType == 4 || controlType == 8) ){
  179. if ( devAddr == null || devAddr.length() == 0) return toolUtils.response(InterfaceResultEnum.LACK_LIGHT_SERIAL_Number_ERROR,version);
  180. if (Integer.parseInt(devAddr) < 10) return toolUtils.response(InterfaceResultEnum.LIGHT_SERIAL_Number_RANGE_ERROR,version);
  181. bindStatus = 0;
  182. }
  183. String freqId = request.getParameter("freqId");
  184. if (protocolType == 6 && freqId == null) return toolUtils.response(InterfaceResultEnum.LACK_FREQUENCY_ERROR,version);
  185. String loopNumber = request.getParameter("loopNumber");
  186. if (protocolType == 5){
  187. //zigbee灯具所属的回路
  188. if (loopNumber == null || loopNumber.equals("0")) return toolUtils.response(InterfaceResultEnum.LACK_ZIGBEE_LOOP_NUMBER_ERROR,version);
  189. }
  190. String macAddress = request.getParameter("macAddress");
  191. if (protocolType == 11 || protocolType == 5){
  192. //macAddress的值不能为空
  193. if (macAddress == null) return toolUtils.response(InterfaceResultEnum.LACK_PLC_MACADDRESS__ERROR,version);
  194. }
  195. if (controlType == 26 || controlType == 27){
  196. if (macAddress != null && sn != null){
  197. bindStatus = 0;
  198. //微自然plc
  199. this.savePlcAddress(macAddress,sn);
  200. }
  201. }
  202. String groupId = request.getParameter("groupId");
  203. String lampPoleId = request.getParameter("lampPoleId");
  204. Date day = new Date();
  205. SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  206. String updateTime = sdf.format(day);
  207. Integer userId = toolUtils.getUser(request).getId();
  208. if (lampId == 0){ // 添加
  209. //同一个路段下不能有相同的编号
  210. LampInfoDTO lampInfo = new LampInfoDTO();
  211. lampInfo.setSectionId(sectionId);
  212. lampInfo.setNumber(number);
  213. //若两灯的,只添加其中一个的就要判断了
  214. // Integer byVO = lampService.findByVO(lampInfo);
  215. // if (byVO > 0) return toolUtils.response(InterfaceResultEnum.NUMBER_EXIST_ERROR,version);
  216. lampInfo.setSectionId(null);
  217. lampInfo.setNumber(null);
  218. lampInfo.setAddress(sn);
  219. NetworkDTO networkData = new NetworkDTO();
  220. //同一个plc下不允许有相同的序号/相同灯的地址
  221. Integer header = 0; //灯头:0代表没,1代表灯头1,2代表灯头2
  222. Integer plcNetCount = 0; //网关, 0:没有创建 ,1: 创建过了
  223. if (protocolType == 11 && controlType != 26 && controlType != 27){
  224. String otherDevAddr = ""; //另外一个
  225. lampInfo.setMacAddress(macAddress);
  226. if (controlType == 4 || controlType == 11 || controlType == 12 || controlType == 14 ){
  227. //同一个路段下编号不允相同
  228. LampInfoDTO newLamp = new LampInfoDTO();
  229. newLamp.setNumber(number);
  230. newLamp.setSectionId(sectionId);
  231. Integer byVO = lampService.findByVO(newLamp);
  232. if (byVO > 0) return toolUtils.response(InterfaceResultEnum.NUMBER_EXIST_ERROR,version);
  233. //单灯的情况下是不允许有重复地址的
  234. //灯地址
  235. Integer macAddressTotal = lampService.checkData(lampInfo);
  236. if (macAddressTotal > 0) return toolUtils.response(InterfaceResultEnum.PLC_ADDRESS_EXIST_ERROR,version);
  237. } else if (controlType == 8) {
  238. //双灯的情况,检查是否有两个了,若有则不能重复,若没有,则要知道有了哪个灯头
  239. List<LampInfoDTO> dtoList = lampService.getListByDto(lampInfo);
  240. if (dtoList != null && dtoList.size() == 2){
  241. //已经存在
  242. return toolUtils.response(InterfaceResultEnum.PLC_ADDRESS_EXIST_ERROR,version);
  243. }else {
  244. //不存在或只存在一个灯头
  245. if (dtoList != null && dtoList.size() == 1){
  246. //存在一个灯头
  247. header = dtoList.get(0).getMode() + 1;
  248. otherDevAddr = dtoList.get(0).getDevAddr();
  249. }else {
  250. //同一个路段下编号不允相同
  251. LampInfoDTO newLamp = new LampInfoDTO();
  252. newLamp.setNumber(number);
  253. newLamp.setSectionId(sectionId);
  254. Integer byVO = lampService.findByVO(newLamp);
  255. if (byVO > 0) return toolUtils.response(InterfaceResultEnum.NUMBER_EXIST_ERROR,version);
  256. }
  257. }
  258. }
  259. //灯序号
  260. if (header == 0){
  261. lampInfo.setMacAddress(null);
  262. lampInfo.setDevAddr(devAddr);
  263. Integer devAddrTotal = lampService.checkData(lampInfo);
  264. if (devAddrTotal > 0) return toolUtils.response(InterfaceResultEnum.PLC_SERIAL_NUMBER_EXIST_ERROR,version);
  265. lampInfo.setMacAddress(macAddress);
  266. }else {
  267. //双灯只添加其中一个
  268. if (!devAddr.equals(otherDevAddr)){
  269. //跟原来的不一样
  270. return toolUtils.response(InterfaceResultEnum.PLC_SERIAL_NUMBER_SAME__ERROR,version);
  271. }else {
  272. lampInfo.setDevAddr(devAddr);
  273. }
  274. }
  275. }else {
  276. //同一个路段下编号不允相同
  277. LampInfoDTO newLamp = new LampInfoDTO();
  278. newLamp.setNumber(number);
  279. newLamp.setSectionId(sectionId);
  280. Integer byVO = lampService.findByVO(newLamp);
  281. if (byVO > 0) return toolUtils.response(InterfaceResultEnum.NUMBER_EXIST_ERROR,version);
  282. }
  283. if (protocolType == 13 || controlType == 26 || controlType == 27){
  284. lampInfo.setMacAddress(macAddress);
  285. //lampInfo.setAddress(sn);
  286. Integer devAddrTotal = lampService.checkData(lampInfo);
  287. if (devAddrTotal > 0) return toolUtils.response(InterfaceResultEnum.PLC_ADDRESS_EXIST_ERROR,version);
  288. }
  289. if (protocolType == 5){
  290. //zigbee设备先判断有没有添加网关
  291. //NetworkDTO network = new NetworkDTO();
  292. networkData.setDeviceSn(sn);
  293. Integer networkTotal = networkService.checkNetworkData(networkData);
  294. if (networkTotal == 0) return toolUtils.response(InterfaceResultEnum.LACK_PLC_ADDRESS__ERROR,version);
  295. //获取网关id
  296. NetworkDTO network = networkService.getSimpleData(networkData);
  297. lampInfo.setNetworkId(network.getId());
  298. }
  299. Integer checkAddressTotal = lampService.checkData(lampInfo);
  300. if (protocolType != 11 && protocolType != 5 && protocolType != 13 && checkAddressTotal > 0){
  301. LampInfoDTO dataByVO = lampService.getDataByVO(lampInfo);
  302. //section
  303. SectionDTO sectionDTO = new SectionDTO();
  304. sectionDTO.setId(dataByVO.getSectionId());
  305. sectionDTO= sectionService.getDataByVO(sectionDTO);
  306. //location
  307. GlobalLocationDTO areaData = new GlobalLocationDTO();
  308. areaData.setId(sectionDTO.getPid());
  309. areaData = globalLocationService.getDataByDto(areaData);
  310. String chinaMsg = "无线模块地址已存在,区域: "+areaData.getChineseName()+"-->路段:"+sectionDTO.getName()+"-->路灯编号:"+dataByVO.getNumber();
  311. String engMsg = "The wireless address already exists,area: "+areaData.getEnglishName()+"-->section:"+sectionDTO.getName()+"-->number:"+dataByVO.getNumber();
  312. String ruMsg = "Беспроводной адрес уже существует,область: "+areaData.getRuName()+"-->участок дороги:"+sectionDTO.getName()+"-->Номер фонаря:"+dataByVO.getNumber();
  313. if (version == 0){
  314. String code = "0403";
  315. if (version == 0){
  316. BaseResult<Object> objectBaseResult = new BaseResult<>(code, chinaMsg, new Object());
  317. return objectBaseResult;
  318. } else if (version == 1) {
  319. BaseResult<Object> objectBaseResult = new BaseResult<>(code, engMsg, new Object());
  320. return objectBaseResult;
  321. }else {
  322. BaseResult<Object> objectBaseResult = new BaseResult<>(code, ruMsg, new Object());
  323. return objectBaseResult;
  324. }
  325. }
  326. }
  327. lampInfo.setBindStatus(bindStatus);
  328. //String netAddress = "";
  329. if (protocolType == 0 || protocolType == 3 || protocolType == 4 || protocolType == 5 || protocolType == 6 || protocolType == 7 || protocolType == 8 || protocolType == 9 || protocolType == 10 || protocolType == 11 || protocolType == 13){
  330. lampInfo.setNetType(1);
  331. //直连设备
  332. if (protocolType == 11 || protocolType == 5){
  333. //netAddress = sn;
  334. //plc下有单灯控制器和双灯控制器
  335. lampInfo.setBindStatus(0);
  336. }else {
  337. sn = sn.length() == 13 ? String.valueOf(Integer.parseInt(sn,10)) : sn;
  338. }
  339. //networkData = new NetworkDTO();
  340. networkData.setDeviceSn(sn);
  341. NetworkDTO simpleData = networkService.getSimpleData(networkData);
  342. //zigbee设备 plc
  343. if (protocolType == 5 && controlType == 13){
  344. //先添加控制器,再添加灯具
  345. lampInfo.setMacAddress(macAddress);
  346. //灯地址
  347. Integer macAddressTotal = lampService.checkData(lampInfo);
  348. if (macAddressTotal > 0) return toolUtils.response(InterfaceResultEnum.PLC_ADDRESS_EXIST_ERROR,version);
  349. Object lightObject = this.createCtrollLight(macAddress,simpleData.getUId(),Integer.parseInt(loopNumber),longitude,latitude,name);
  350. if (lightObject == null){
  351. return toolUtils.response(InterfaceResultEnum.CREATE_LIGHT_ERROR,version);
  352. }else {
  353. Integer times = ((ZhongLightPlcVO)lightObject).getTimes();
  354. Integer errorCode = ((ZhongLightPlcVO)lightObject).getErrorCode();
  355. if (errorCode > 0){
  356. if (times == 3) return toolUtils.response(InterfaceResultEnum.CREATE_CONTROL_ERROR,version);
  357. if (times == 4) return toolUtils.response(InterfaceResultEnum.CREATE_CONTROL_LIGHT_ERROR,version);
  358. }else {
  359. //成功
  360. lampInfo.setLampCtrId(((ZhongLightPlcVO)lightObject).getLampCtrlId());
  361. lampInfo.setUid(((ZhongLightPlcVO)lightObject).getUid());
  362. lampInfo.setBindStatus(1);
  363. }
  364. }
  365. }
  366. if (protocolType != 11 && protocolType != 13 && protocolType != 5 && simpleData != null){
  367. lampInfo.setAddress(null);
  368. lampInfo.setNetworkId(simpleData.getId());
  369. LampInfoDTO lamp = lampService.getDataByVO(lampInfo);
  370. if (lamp != null){
  371. networkService.deleteNetworkData(simpleData.getId());
  372. }
  373. lampInfo.setAddress(sn);
  374. }
  375. // plc只创建一个网络就可以了
  376. if (simpleData != null){
  377. if (protocolType == 11 && (controlType != 26 && controlType != 27)){
  378. plcNetCount = 1;
  379. }
  380. }
  381. networkData.setGatewayType("direct");
  382. networkData.setProtocolType(protocolType);
  383. networkData.setAreaId(areaId);
  384. networkData.setSectionId(sectionId);
  385. if (protocolType == 10) networkData.setDeviceType(4);
  386. if (protocolType == 8 && (controlType == 29 || controlType == 33 || controlType == 19)) networkData.setDeviceType(4);
  387. if (protocolType == 3 && controlType == 9) networkData.setDeviceType(4);
  388. if (controlType == 16 || controlType == 20) networkData.setDeviceType(5);
  389. networkData.setNetworkName(sn);
  390. networkData.setNetType(1);
  391. networkData.setCreateTime(updateTime);
  392. networkData.setUserId(userId);
  393. if (protocolType == 6) this.addDevice(sn,freqId);
  394. if (protocolType == 7){
  395. //添加onenet
  396. String deviceOnenet = toolUtils.addDeviceOnenet(sn);
  397. if (deviceOnenet != null && deviceOnenet.length() != 0){
  398. JSONObject onenetObject = JSON.parseObject(deviceOnenet);
  399. JSONObject data = onenetObject.getJSONObject("data");
  400. String onenetId = data.getString("device_id");
  401. if (onenetId != null && onenetId.length() != 0){
  402. lampInfo.setDeviceId(onenetId);
  403. networkData.setDeviceId(onenetId);
  404. }
  405. }
  406. }
  407. }
  408. if (protocolType == 10 && (controlType == 7 || controlType == 6 || controlType == 15 || controlType == 19 || controlType == 21 || controlType == 30 || controlType == 31 || controlType == 32 || controlType == 35)) lampInfo.setMode(1);
  409. if (protocolType == 8 && (controlType == 19 || controlType == 23 || controlType == 33 || controlType == 37)) lampInfo.setMode(1);
  410. if (protocolType == 11 && controlType != 26 && controlType != 27){
  411. if (plcNetCount == 0){
  412. if (controlType != 4 && controlType != 8){
  413. //广东启慧 - plc
  414. String url = "concentrator/deviceRegister";
  415. JSONObject qihuiObject = new JSONObject();
  416. qihuiObject.put("deviceId",sn);
  417. //添加网关
  418. String result = this.quiHuiPlcDevice(url, qihuiObject, 4);
  419. if (result == null || result.length() == 0){
  420. return toolUtils.response(InterfaceResultEnum.SEND_CMD_TIME_OUT,version);
  421. }else {
  422. JSONObject parseObject = JSON.parseObject(result);
  423. Integer code = parseObject.getInteger("code");
  424. if (code == 200){
  425. networkService.add(networkData);
  426. lampInfo.setNetworkId(networkData.getId());
  427. } else {
  428. String msg = parseObject.getString("msg");
  429. BaseResult<Object> objectBaseResult = new BaseResult<>(code.toString(), msg, new Object());
  430. return objectBaseResult;
  431. }
  432. }
  433. }else {
  434. //力合微 plc
  435. networkService.add(networkData);
  436. lampInfo.setNetworkId(networkData.getId());
  437. }
  438. }else {
  439. NetworkDTO network = networkService.getSimpleData(networkData);
  440. lampInfo.setNetworkId(network.getId());
  441. }
  442. } else {
  443. if (protocolType == 1){
  444. networkData.setGatewayType("direct");
  445. networkData.setProtocolType(protocolType);
  446. networkData.setAreaId(areaId);
  447. networkData.setSectionId(sectionId);
  448. networkData.setDeviceSn(sn);
  449. networkData.setNetworkName(sn);
  450. networkData.setNetType(1);
  451. networkData.setCreateTime(updateTime);
  452. }
  453. networkService.add(networkData);
  454. lampInfo.setNetworkId(networkData.getId());
  455. }
  456. SectionDTO sectionDTO = new SectionDTO();
  457. sectionDTO.setId(sectionId);
  458. sectionDTO = sectionService.getDataByVO(sectionDTO);
  459. GlobalLocationDTO areaDTO = new GlobalLocationDTO();
  460. areaDTO.setId(sectionDTO.getPid());
  461. areaDTO = globalLocationService.getDataByDto(areaDTO);
  462. lampInfo.setCreateTime(updateTime);
  463. //添加plc控制器节点 - 启慧
  464. if (protocolType == 11 && (controlType == 11 || controlType == 12 || controlType == 14)) {
  465. String url = "childnode/deviceRegister";
  466. String nodeType = this.selectNodeType(power);
  467. if (nodeType == null || nodeType.length() == 0) return toolUtils.response(InterfaceResultEnum.POWER_SELECT_ERROR,version);
  468. JSONObject qiObject = new JSONObject();
  469. if (groupId != null && groupId.length() != 0){
  470. String[] groupIds = groupId.split(",");
  471. List<GroupDTO> list = groupService.getListByIds(groupIds);
  472. //有分组 (只有: 1- 255)
  473. for (GroupDTO item:list) {
  474. Integer groupNumber = Integer.parseInt(item.getNumber());
  475. if (groupNumber < 1 || groupNumber > 255){
  476. //分组没有在规定的范围内
  477. return toolUtils.response(InterfaceResultEnum.GROUP_NUMBER_RAND_ERROR,version);
  478. }else {
  479. //注意:nodeId是12位数的,不够时,前面补0
  480. String nodeId = "";
  481. String zero = "";
  482. if (macAddress.length() <= 12){
  483. for (int i = 0; i < 12 - macAddress.length();i++){
  484. zero += "0";
  485. }
  486. nodeId = zero+macAddress;
  487. }else {
  488. //大于12位数了
  489. return toolUtils.response(InterfaceResultEnum.FILL_LAMP_ADDRESS__ERROR,version);
  490. }
  491. qiObject.put("nodeId",nodeId);
  492. qiObject.put("nodeType",nodeType);
  493. qiObject.put("deviceId",sn);
  494. qiObject.put("groupNum",groupNumber);
  495. }
  496. }
  497. }else {
  498. //没有分组的
  499. //注意:nodeId是12位数的,不够时,前面补0
  500. String nodeId = "";
  501. String zero = "";
  502. if (macAddress.length() <= 12){
  503. for (int i = 0; i < 12 - macAddress.length();i++){
  504. zero += "0";
  505. }
  506. nodeId = zero+macAddress;
  507. }else {
  508. //大于12位数了
  509. return toolUtils.response(InterfaceResultEnum.FILL_LAMP_ADDRESS__ERROR,version);
  510. }
  511. qiObject.put("nodeId",nodeId);
  512. qiObject.put("nodeType",nodeType);
  513. qiObject.put("deviceId",sn);
  514. }
  515. String respone = this.quiHuiPlcDevice(url, qiObject, 4);
  516. if (respone == null || respone.length() == 0){
  517. return toolUtils.response(InterfaceResultEnum.SEND_CMD_TIME_OUT,version);
  518. }else {
  519. JSONObject parseObject = JSON.parseObject(respone);
  520. Integer code = parseObject.getInteger("code");
  521. if (code != 200){
  522. String msg = parseObject.getString("msg");
  523. BaseResult<Object> objectBaseResult = new BaseResult<>(code.toString(), msg, new Object());
  524. return objectBaseResult;
  525. }else {
  526. lampInfo.setBindStatus(1);
  527. }
  528. }
  529. }
  530. lampInfo.setControlType(controlType);
  531. lampInfo.setRatedPower(power);
  532. lampInfo.setLongitude(Float.valueOf(longitude));
  533. lampInfo.setLatitude(Float.valueOf(latitude));
  534. lampInfo.setAreaId(areaId);
  535. lampInfo.setSectionId(sectionId);
  536. lampInfo.setAddress(sn);
  537. lampInfo.setNumber(number);
  538. lampInfo.setName(name);
  539. if (protocolType == 11 && controlType == 8 && header > 0){
  540. //添加其中一个灯头
  541. if (header == 1){//灯头1
  542. //设置灯头2
  543. lampInfo.setMode(1);
  544. }else {//灯头2
  545. //设置灯头1
  546. lampInfo.setMode(0);
  547. }
  548. lampService.addByDto(lampInfo);
  549. }else {
  550. lampService.addByDto(lampInfo);
  551. }
  552. //修改了 4G 双控 plc 双控 nb 双控 蓝牙双灯
  553. if (protocolType == 10 && (controlType == 5 || controlType == 22 || controlType == 34) || (protocolType == 11 && controlType == 8 && header == 0) || (protocolType == 3 && controlType == 9) || controlType == 25 || controlType == 27 || controlType ==29){
  554. lampInfo.setMode(1);
  555. lampService.addByDto(lampInfo);
  556. }
  557. String lastSql = lastSqlInterceptor.sqlContent; //插入的sql语句
  558. if (lampPoleId != null && lampPoleId.length() != 0){
  559. toolUtils.setPoleType(Integer.parseInt(lampPoleId),0);
  560. }
  561. // 添加到分组
  562. if (groupId != null && groupId.length() != 0){
  563. String[] groupIdArr = groupId.split(",");
  564. List<GroupDTO> groupDTOList = groupService.getListByIds(groupIdArr);
  565. for (GroupDTO item:groupDTOList) {
  566. String[] lampArr = item.getLampId().split(",");
  567. //是否包含某个元素
  568. boolean ifContain = Arrays.asList(lampArr).contains(lampInfo.getId());
  569. if (ifContain == false){
  570. //转换成list
  571. List<String> list = new ArrayList<>(Arrays.asList(lampArr));
  572. list.add(lampInfo.getId().toString());
  573. //list数组按规定拼接成字符串
  574. String newLampId= list.stream().collect(Collectors.joining(","));
  575. //更新
  576. item.setLampId(newLampId);
  577. groupService.updateGroupLampId(item);
  578. }
  579. }
  580. }
  581. networkData = networkService.getSimpleData(networkData);
  582. Integer lampCount = networkData.getLampCount();
  583. if (controlType == 1 || controlType == 3 || controlType == 5 || controlType == 8 || controlType == 9 || controlType == 22){
  584. //更新lampcount
  585. //如果两灯就是添加2个
  586. if (lampCount == null || lampCount == 0){
  587. networkData.setLampCount(2);
  588. }else {
  589. if (header > 0 && controlType == 8){
  590. //只增加一个
  591. lampCount = lampCount + 1;
  592. networkData.setLampCount(lampCount);
  593. }else {
  594. lampCount = lampCount + 2;
  595. networkData.setLampCount(lampCount);
  596. }
  597. }
  598. networkService.updateSimDate(networkData);
  599. }else {
  600. //单灯
  601. //如果两灯就是添加1个
  602. if (protocolType != 11 && protocolType != 5){
  603. networkData.setLampCount(1);
  604. networkService.updateSimDate(networkData);
  605. }else if((protocolType == 11 || protocolType == 5) && controlType != 26 && controlType != 27) {
  606. //plc可以带很多灯 ,//zigbee也是带多个灯
  607. if (lampCount == null || lampCount == 0){
  608. networkData.setLampCount(1);
  609. }else {
  610. lampCount = lampCount + 1;
  611. networkData.setLampCount(lampCount);
  612. }
  613. networkService.updateSimDate(networkData);
  614. }
  615. }
  616. String cRemark = "添加路灯 区域:"+areaDTO.getChineseName()+"->路段:"+sectionDTO.getName()+"->路灯编号:"+number+" id:"+lampInfo.getId();
  617. String eRemark = "Add lamp area:"+areaDTO.getEnglishName()+"->section:"+sectionDTO.getName()+"->number:"+number+" id:"+lampInfo.getId();
  618. String rRemark = "Добавить зону светильников:"+areaDTO.getRuName()+"->участок дороги:"+sectionDTO.getName()+"->нумерация:"+number+" id:"+lampInfo.getId();
  619. toolUtils.addOpertaionLog(request, "添加", cRemark, 0, 1, 1, number, areaDTO.getChineseName(), sectionDTO.getName(), sn, sectionId, sectionDTO.getId(), lampInfo.getId(), lastSql);
  620. toolUtils.addOpertaionLog(request, "Insert", eRemark, 1,1,1, number, areaDTO.getEnglishName(), sectionDTO.getName(), sn, sectionId, sectionDTO.getId(), lampInfo.getId(), lastSql);
  621. toolUtils.addOpertaionLog(request,"Подкючено",rRemark,2,1,1,number,areaDTO.getRuName(),sectionDTO.getName(),sn,sectionId,sectionDTO.getId(), lampInfo.getId(),lastSql);
  622. return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version);
  623. }else { // 编辑
  624. // LampInfoDTO oldLamp = lampService.getDetailsById(lampId,version);
  625. // if (oldLamp.getProtocolType() != protocolType){
  626. // NetworkDTO networkDTO = new NetworkDTO();
  627. // networkDTO.setId(oldLamp.getNetworkId());
  628. // networkDTO.setNetworkName(sn);
  629. // networkDTO.setDeviceSn(sn);
  630. // networkDTO.setAreaId(areaId);
  631. // networkDTO.setSectionId(sectionId);
  632. // if (protocolType == 10) networkDTO.setDeviceType(4);
  633. // networkDTO.setProtocolType(protocolType);
  634. // networkService.update(networkDTO);
  635. // }
  636. LampInfoDTO lampInfoDTO = new LampInfoDTO();
  637. lampInfoDTO.setId(lampId);
  638. lampInfoDTO.setNumber(number);
  639. lampInfoDTO.setSectionId(sectionId);
  640. lampInfoDTO.setName(name);
  641. // lampInfoDTO.setNetworkId(oldLamp.getNetworkId());
  642. lampInfoDTO.setLatitude(Float.valueOf(latitude));
  643. lampInfoDTO.setLongitude(Float.valueOf(longitude));
  644. lampInfoDTO.setNumber(number);
  645. lampInfoDTO.setSn(sn);
  646. lampInfoDTO.setAreaId(areaId);
  647. lampInfoDTO.setControlType(controlType);
  648. lampInfoDTO.setProtocolType(protocolType);
  649. lampInfoDTO.setInstallDate(installDate);
  650. lampInfoDTO.setExpirationDate(expirationDate);
  651. lampInfoDTO.setRatedPower(power);
  652. return lampService.update(lampInfoDTO);
  653. }
  654. }
  655. //微自然的plc
  656. private void savePlcAddress(String netAddress,String lampAddress){
  657. PlcAddressDTO plcAddressDTO = new PlcAddressDTO();
  658. plcAddressDTO.setLampAddress(lampAddress);
  659. plcAddressDTO.setNetAddress(netAddress);
  660. Integer total = plcAddressService.checkDataByVO(plcAddressDTO);
  661. if (total == 0){
  662. PlcAddressDTO result = plcAddressService.getMaxPvid(plcAddressDTO);
  663. if (result == null){
  664. plcAddressDTO.setPvid(1);
  665. }else {
  666. plcAddressDTO.setPvid(result.getPvid() + 1);
  667. }
  668. plcAddressService.insertDataByVO(plcAddressDTO);
  669. }
  670. }
  671. // 添加设备
  672. protected String addDevice(String deviceId,String freqId){
  673. Map<String, FreqConfig> maps = freqMapConfig.getMaps();
  674. FreqConfig freqConfig = maps.get(freqId);
  675. String deviceProfileID = "";
  676. String applicationID = "";
  677. if (freqConfig != null){
  678. deviceProfileID = freqConfig.getDeviceProfileID();
  679. applicationID = freqConfig.getApplicationID();
  680. }
  681. JSONObject device = new JSONObject();
  682. device.put("applicationID",applicationID);
  683. device.put("description",deviceId);
  684. device.put("devEUI","00000000"+deviceId);
  685. device.put("deviceProfileID",deviceProfileID);
  686. device.put("name",deviceId);
  687. device.put("referenceAltitude",0);
  688. device.put("skipFCntCheck",true);
  689. device.put("tags",new Object());
  690. device.put("variables",new Object());
  691. JSONObject data = new JSONObject();
  692. data.put("device",device);
  693. String token = jwtUtil.signatureToToken();
  694. String url = "http://47.112.108.98:8090/api/devices";
  695. String respone = null;
  696. try {
  697. respone = toolUtils.sendHttp("post", url, data.toString(), token, null, 5, null, ToolUtils.ContentTypeEnum.CONTENT_TYPE_JSON,null);
  698. System.out.println("=====dddd:"+respone);
  699. if (respone == null){
  700. respone = jwtUtil.setActivate(deviceId);
  701. System.out.println("=====再次:"+respone);
  702. }
  703. } catch (IOException e) {
  704. throw new RuntimeException(e);
  705. }
  706. return null;
  707. }
  708. /**
  709. * 删除灯控
  710. * @param request
  711. * @return
  712. */
  713. @RequestMapping(value = "/del",method = RequestMethod.POST)
  714. public BaseResult del(HttpServletRequest request){
  715. Integer version = request.getParameter("version") == null ? 0 : Integer.parseInt(request.getParameter("version"));
  716. String lampId = request.getParameter("lampId");
  717. if (lampId == null || lampId.length() == 0) return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR,version);
  718. String[] split = lampId.split(",");
  719. for (String id :split) {
  720. int l = Integer.parseInt(id);
  721. lampService.deleteById(l);
  722. }
  723. return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version);
  724. }
  725. /**
  726. * 灯控调光
  727. * @param request
  728. * @return
  729. */
  730. @RequestMapping(value = "/dimming",method = RequestMethod.POST)
  731. public BaseResult dimming(HttpServletRequest request){
  732. Integer version = request.getParameter("version") == null ? 0 : Integer.parseInt(request.getParameter("version"));
  733. Integer light = request.getParameter("light") == null ? 0 : Integer.parseInt(request.getParameter("light"));
  734. Integer isGroup = request.getParameter("isGroup") == null ? 0 : Integer.parseInt(request.getParameter("isGroup"));
  735. Integer id = request.getParameter("id") == null ? 0 : Integer.parseInt(request.getParameter("id"));
  736. LampInfoDTO lamp = lampService.getDetailsById(id, version);
  737. light = light > 100 ? 100 : light;
  738. Date day = new Date();
  739. SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  740. String updateTime = sdf.format(day);
  741. if (lamp.getProtocolType() == 10){ // 4G
  742. String sendTopic = "/Lamp/TransIn/"+lamp.getSn();
  743. String backTopic = "/Lamp/TransOut/"+lamp.getSn();
  744. if (isGroup == 1){
  745. String cmd;
  746. if (lamp.getMode() == 0){ // B 路
  747. cmd = "0110DF090102";
  748. }else { // A 路
  749. cmd = "0110DF0B0102";
  750. }
  751. if (light == 0){
  752. cmd += "5F";
  753. }else {
  754. cmd += "A0";
  755. }
  756. cmd += toolUtils.getCRC(cmd.getBytes());
  757. String s = toolUtils.sendMqttCmd(sendTopic, "0232"+cmd, backTopic, 10);
  758. if (s == null || s.length() == 0){
  759. return toolUtils.response(InterfaceResultEnum.SEND_CMD_TIME_OUT,version);
  760. }else {
  761. if (lamp.getMode() == 0){ // A 路
  762. cmd = "0106DF0A";
  763. }else { // B 路
  764. cmd = "0106DF0C";
  765. }
  766. String lightStr = "0000"+Integer.toHexString(light).toString();
  767. lightStr = lightStr.substring(-4);
  768. cmd += lightStr;
  769. cmd += toolUtils.getCRC(cmd.getBytes());
  770. s = toolUtils.sendMqttCmd(sendTopic, "0232"+cmd, backTopic, 10);
  771. if (s == null || s.length() == 0){
  772. return toolUtils.response(InterfaceResultEnum.SEND_CMD_TIME_OUT,version);
  773. }else {
  774. LampInfoDTO lampInfoDTO = new LampInfoDTO(lamp.getId());
  775. lampInfoDTO.setLighteness(light);
  776. lampInfoDTO.setPolicyId(0);
  777. lampInfoDTO.setPolicyType(0);
  778. lampService.updateLight(lampInfoDTO);
  779. return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version);
  780. }
  781. }
  782. }else {
  783. String cmd;
  784. if (lamp.getMode() == 0){ // A 路
  785. cmd = "0106DF0A";
  786. }else { // B 路
  787. cmd = "0106DF0C";
  788. }
  789. String lightStr = "0000"+Integer.toHexString(light).toString();
  790. lightStr = lightStr.substring(-4);
  791. cmd += lightStr;
  792. cmd += toolUtils.getCRC(cmd.getBytes());
  793. String s = toolUtils.sendMqttCmd(sendTopic, "0232"+cmd, backTopic, 10);
  794. if (s == null || s.length() == 0){
  795. return toolUtils.response(InterfaceResultEnum.SEND_CMD_TIME_OUT,version);
  796. }else {
  797. LampInfoDTO lampInfoDTO = new LampInfoDTO(lamp.getId());
  798. lampInfoDTO.setLighteness(light);
  799. lampService.updateLight(lampInfoDTO);
  800. return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version);
  801. }
  802. }
  803. } else if (lamp.getProtocolType() == 11) {//plc灯
  804. if (lamp.getControlType() == 8 || lamp.getControlType() == 4){
  805. //力合微
  806. String rthirdId = "LME:"+ lamp.getSn().toLowerCase();
  807. String thirdId = rthirdId + "-light:"+lamp.getDevAddr();
  808. Integer lampNumber = lamp.getMode() + 1;
  809. //当前时间
  810. String dataType = "adjustLightController";
  811. //对象
  812. JSONObject jsonObject = new JSONObject();
  813. jsonObject.put("thirdId",thirdId);
  814. jsonObject.put("RthirdId",rthirdId);
  815. jsonObject.put("lampNumber",lampNumber);
  816. jsonObject.put("dateTime",updateTime);
  817. jsonObject.put("dataType",dataType);
  818. jsonObject.put("brightness",light);
  819. String objectString = jsonObject.toString();
  820. //发送命令(获取数据)
  821. String sendTopic = "LME/streetLight/In/adjustLightController/"+rthirdId;
  822. String resTopic = "LME/streetLight/Out/lightStatus";
  823. String s = toolUtils.plcSendMqttCmd(sendTopic, objectString, resTopic, 20);
  824. if (s == null || s.length() == 0){
  825. return toolUtils.response(InterfaceResultEnum.SEND_CMD_TIME_OUT,version);
  826. }
  827. } else if (lamp.getControlType() == 11 || lamp.getControlType() == 12 || lamp.getControlType() == 14) {
  828. //广东启慧
  829. String url = "concentrator/singleLightDimmer";
  830. String macAddress = lamp.getMacAddress();
  831. if (lamp.getMacAddress().length() < 12){
  832. StringBuffer stringBuffer = new StringBuffer();
  833. for (int i = 0; i < 12 - lamp.getMacAddress().length(); i++){
  834. stringBuffer.append('0');
  835. }
  836. String zero = stringBuffer.toString();
  837. macAddress = zero+macAddress;
  838. }
  839. JSONObject jsonObject = new JSONObject();
  840. jsonObject.put("deviceId",lamp.getSn());
  841. jsonObject.put("nodeId",macAddress);
  842. jsonObject.put("ab",lamp.getMode()+1);
  843. jsonObject.put("luminance",light);
  844. //发送命令-调光
  845. String result = this.quiHuiPlcDevice(url, jsonObject, 4);
  846. if (result == null || result.length() == 0){
  847. return toolUtils.response(InterfaceResultEnum.SEND_CMD_TIME_OUT,version);
  848. }else {
  849. JSONObject parseObject = JSON.parseObject(result);
  850. Integer code = parseObject.getInteger("code");
  851. if (code == 200){
  852. LampInfoDTO lampInfoDTO = new LampInfoDTO(lamp.getId());
  853. lampInfoDTO.setLighteness(light);
  854. lampInfoDTO.setUpdateTime(updateTime);
  855. lampService.updateLight(lampInfoDTO);
  856. return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version);
  857. } else {
  858. String msg = parseObject.getString("msg");
  859. BaseResult<Object> objectBaseResult = new BaseResult<>(code.toString(), msg, new Object());
  860. return objectBaseResult;
  861. }
  862. }
  863. }
  864. } else if (lamp.getProtocolType() == 5) {
  865. if (lamp.getControlType() == 13){
  866. //中灯的plc,协议是zigbee
  867. Object zhogMsg = this.zhongDimming(lamp,light);
  868. if (zhogMsg == null){
  869. return toolUtils.response(InterfaceResultEnum.LACK_UNKNOWN_ERROR,version);
  870. }else {
  871. Integer times = ((ZhongLightPlcVO) zhogMsg).getTimes();
  872. Integer errorCode = ((ZhongLightPlcVO) zhogMsg).getErrorCode(); //错误码
  873. Integer succCode = ((ZhongLightPlcVO) zhogMsg).getSuccCode(); //错误码
  874. if (errorCode > 0){
  875. //失败
  876. if (times == 1){
  877. //获取token返回的错误
  878. if (errorCode == 1){
  879. return toolUtils.response(InterfaceResultEnum.PLC_CALL_ERROR,version);
  880. }else if (errorCode == 2) {
  881. return toolUtils.response(InterfaceResultEnum.PLC_KEY_ERROR,version);
  882. }else {
  883. return toolUtils.response(InterfaceResultEnum.PLC_token_ERROR,version);
  884. }
  885. } else if (times == 2) {
  886. //login时返回的错误
  887. if (errorCode == 1){
  888. return toolUtils.response(InterfaceResultEnum.USER_EXISTS_ERROR,version);
  889. } else if (errorCode == 2) {
  890. return toolUtils.response(InterfaceResultEnum.USER_DISABLED_ERROR,version);
  891. }else {
  892. return toolUtils.response(InterfaceResultEnum.USER_LOGIN_ERROR,version);
  893. }
  894. }else {
  895. //第三次
  896. if (errorCode == 780){
  897. return toolUtils.response(InterfaceResultEnum.DEVICE_OFFLINE_ERROR,version);
  898. } else if (errorCode == 201) {
  899. return toolUtils.response(InterfaceResultEnum.DEVICE_TIMEOUT_ERROR,version);
  900. } else if (errorCode == 203) {
  901. return toolUtils.response(InterfaceResultEnum.DEVICE_CONNECTED_ERROR,version);
  902. }else {
  903. return toolUtils.response(InterfaceResultEnum.INVALID_TOKEN_ERROR,version);
  904. }
  905. }
  906. }
  907. if (succCode == 0 && times == 3 && errorCode == 0){
  908. //调光成功
  909. LampInfoDTO lampInfoDTO = new LampInfoDTO(lamp.getId());
  910. lampInfoDTO.setLighteness(light);
  911. lampInfoDTO.setUpdateTime(updateTime);
  912. lampService.updateLight(lampInfoDTO);
  913. return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version);
  914. }
  915. }
  916. }
  917. }
  918. return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version);
  919. }
  920. private String selectNodeType(Integer power){
  921. String nodeType = "";
  922. switch (power){
  923. case 30:
  924. nodeType = "01";
  925. break;
  926. case 40:
  927. nodeType = "02";
  928. break;
  929. case 50:
  930. nodeType = "50";
  931. break;
  932. case 60:
  933. nodeType = "06";
  934. break;
  935. case 75:
  936. nodeType = "0A";
  937. break;
  938. case 80:
  939. nodeType = "12";
  940. break;
  941. case 90:
  942. nodeType = "15";
  943. break;
  944. case 100:
  945. nodeType = "19";
  946. break;
  947. case 120:
  948. nodeType = "1D";
  949. break;
  950. case 150:
  951. nodeType = "2C";
  952. break;
  953. case 160:
  954. nodeType = "27";
  955. break;
  956. case 180:
  957. nodeType = "36";
  958. break;
  959. case 185:
  960. nodeType = "38";
  961. break;
  962. case 200:
  963. nodeType = "40";
  964. break;
  965. case 240:
  966. nodeType = "45";
  967. break;
  968. case 260:
  969. nodeType = "48";
  970. break;
  971. default:
  972. nodeType = "";
  973. }
  974. return nodeType;
  975. }
  976. //中灯 - 调光
  977. private Object getToken(){
  978. String url = zhongLightPlc.getZhongUrl()+"query_token";
  979. JSONObject jsonObject = new JSONObject();
  980. jsonObject.put("OperatorID",zhongLightPlc.getOperatorID());
  981. jsonObject.put("OperatorSecret",zhongLightPlc.getOperatorSecret());
  982. String objectString = jsonObject.toString();
  983. //aes128位,模式:cbc,填充模式: pkcs5padding,返回是base64
  984. //hmac-md5加密32位后,小写要转换成大写
  985. String bodyStr = this.encryptAndMd5(objectString);
  986. String result = null;
  987. try {
  988. result = toolUtils.sendHttp("post", url, bodyStr,3, ToolUtils.ContentTypeEnum.CONTENT_TYPE_JSON,null);
  989. } catch (IOException e) {
  990. throw new RuntimeException(e);
  991. }
  992. if (result == null || result.length() == 0){
  993. return null;
  994. }else {
  995. //System.out.println("====result:"+result);
  996. JSONObject parseObject = JSON.parseObject(result);
  997. String data = parseObject.getString("Data");
  998. Integer ret = parseObject.getInteger("Ret");
  999. //{"Ret": 0, "Msg": "Successfully", "Data": "U/jy5Jq0OPFRB3xFNvLAUcEPg3eZjSSuG9KOKcCtu4/CqJgFI/sWTQyHrdiEcpC2sk0EofcZ3eurM4A7N0LFRbYRaiiiyK9I6vcWh8JyLLSIEUEsGSh66NjcxzdqrQX4LOYducgwxA+KZAh7d9iNIdeMhEpAIxJbM5PcTHwtcjOOygde0lLZdU3QDHvTltFmMh7HNvzd6/quXpYvfQoBMZpR9D81Ly7BaHljFqSzKBGaarW/Xbv6MnReqJo/IMla4l1nKjsjCiEHo2aAOGO0zLgRMzJ/t78tjAxf5V09Amb/M5K6/vw5AvMN/F/0e+fHzzfMEvlJ0RU/nqGpvjGrtFrgwioa6IjnZsB52yBWR2HNHENjDq1nUVs9AQ6hfyJb", "Sig": "7C4A204206F4F99DB8427C90F11A85B3"}
  1000. String dataString = null;
  1001. if (ret == 0){
  1002. //解密
  1003. try {
  1004. //{"OperatorID": "MA5G0DCR3", "SuccStat": 0, "AccessToken": "eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiJNQTVHMERDUjMiLCJpYXQiOjE2OTY5MzQ1MzEsInN1YiI6InVHeGR0OE5QNURZWStxWUQiLCJleHAiOjE2OTY5NDE3MzJ9.KIgJtlInWxLAyz2WYerbia5LqBVabLh6xB2M3TvRXYU", "TokenAvailableTime": 7200, "FailReason": 0}
  1005. dataString = aesUtils.decrypt(zhongLightPlc.getEncryptKey(),zhongLightPlc.getIv(),data);
  1006. JSONObject dataObject = JSON.parseObject(dataString);
  1007. Integer succStat = dataObject.getInteger("SuccStat");
  1008. Integer failReason = dataObject.getInteger("FailReason");
  1009. ZhongLightPlcVO zhongLightPlcVO = new ZhongLightPlcVO();
  1010. zhongLightPlcVO.setTimes(1);
  1011. zhongLightPlcVO.setErrorCode(failReason);
  1012. if (succStat == 0){
  1013. //成功
  1014. String accessToken = dataObject.getString("AccessToken");
  1015. System.out.println("===eee:"+accessToken);
  1016. zhongLightPlcVO.setToken(accessToken);
  1017. zhongLightPlcVO.setSuccCode(0);
  1018. //return accessToken; //有效期是2个小时
  1019. }else {
  1020. //失败
  1021. //zhongLightPlcVO.setErrorCode(failReason);
  1022. // return failReason.toString();
  1023. // if (failReason == 1){
  1024. // toolUtils.response(InterfaceResultEnum.PLC_CALL_ERROR,0);
  1025. // } else if (failReason == 2) {
  1026. // toolUtils.response(InterfaceResultEnum.PLC_KEY_ERROR,0);
  1027. // }else {
  1028. // toolUtils.response(InterfaceResultEnum.PLC_token_ERROR,0);
  1029. // }
  1030. }
  1031. return zhongLightPlcVO;
  1032. } catch (Exception e) {
  1033. throw new RuntimeException(e);
  1034. }
  1035. }
  1036. }
  1037. return null;
  1038. }
  1039. private Object zhongPlcLogin(ZhongLightPlcVO tokenObject){
  1040. String url = zhongLightPlc.getZhongUrl()+"user/v1_0/user_login";
  1041. JSONObject jsonObject = new JSONObject();
  1042. jsonObject.put("UserName",zhongLightPlc.getZhongUserName());
  1043. jsonObject.put("Password",zhongLightPlc.getZhongPassword());
  1044. String objectString = jsonObject.toString();
  1045. //aes128位,模式:cbc,填充模式: pkcs5padding
  1046. //hmac-md5加密后,小写要转换成大写
  1047. String bodyJsonString = this.encryptAndMd5(objectString);
  1048. String respone = null;
  1049. try {
  1050. respone = toolUtils.sendHttp("post",url,bodyJsonString,tokenObject.getToken(),null,4,"Bearer", ToolUtils.ContentTypeEnum.CONTENT_TYPE_JSON,null);
  1051. JSONObject parseObject = JSON.parseObject(respone);
  1052. System.out.println("======ddd:"+parseObject);
  1053. Integer ret = parseObject.getInteger("Ret");
  1054. if (ret == 0){
  1055. //解密
  1056. String data = parseObject.getString("Data");
  1057. // {"Role":1,"SuccStat":0,"Type":"3","Menus":[{"Title":"首页","Children":[{"Title":"首页","Code":"181"}],"Code":"18"},{"Title":"智慧照明","Children":[{"Title":"统计概览","Code":"2c"},{"Title":"基本信息","Code":"22"},{"Title":"实时监控","Code":"23"},{"Title":"实时监控","Code":"2b"},{"Title":"回路监控","Code":"24"},{"Title":"回路监控","Code":"2f"},{"Title":"场景策略","Code":"26"},{"Title":"历史数据","Code":"27"},{"Title":"故障告警","Code":"28"}],"Code":"2"},{"Title":"地图","Children":[{"Title":"地图","Code":"31"}],"Code":"3"},{"Title":"设备","Children":[{"Title":"监控H","Code":"52"},{"Title":"充电桩","Code":"54"},{"Title":"气象","Code":"55"},{"Title":"信息屏X","Code":"5a"},{"Title":"报警X","Code":"5e"},{"Title":"一键告警S","Code":"5x"},{"Title":"广播S","Code":"5d"},{"Title":"NB井盖","Code":"5z"},{"Title":"WiFi-AP","Code":"59"}],"Code":"5"},{"Title":"配置","Children":[{"Title":"参数配置","Code":"43"},{"Title":"网关配置","Code":"44"},{"Title":"策略配置","Code":"49"},{"Title":"项目配置","Code":"45"},{"Title":"首页配置","Code":"4a"},
  1058. // {"Title":"操作记录","Code":"9"}],"Code":"4"}],"ProjectId":"5ecd00d726b0673bf8d0f034","OrganizationId":"5ecd009826b0673bf8d0f032","SessionId":"27BA3664948557E419D6CFD260BD72B4","DivisionId":"5ecd006926b0673bf8d0f02c"}
  1059. String decryptJson = aesUtils.decrypt(zhongLightPlc.getEncryptKey(), zhongLightPlc.getIv(), data);
  1060. JSONObject resultObject = JSON.parseObject(decryptJson);
  1061. //0:成功;1:用户名密码对应用户不存在;2:该用户已被禁用;3~99:自定义
  1062. Integer code = resultObject.getInteger("SuccStat");
  1063. ZhongLightPlcVO loginZhongVO = new ZhongLightPlcVO();
  1064. loginZhongVO.setSuccCode(code);
  1065. loginZhongVO.setErrorCode(code);
  1066. loginZhongVO.setTimes(2);
  1067. if (code == 0){
  1068. //成功
  1069. String projectId = resultObject.getString("ProjectId");
  1070. String organizationId = resultObject.getString("OrganizationId");
  1071. String sessionId = resultObject.getString("SessionId");
  1072. String divisionId = resultObject.getString("DivisionId");
  1073. loginZhongVO.setProjectId(projectId);
  1074. loginZhongVO.setOrganizationId(organizationId);
  1075. loginZhongVO.setSessionId(sessionId);
  1076. loginZhongVO.setDivisionId(divisionId);
  1077. loginZhongVO.setToken(tokenObject.getToken());
  1078. }
  1079. return loginZhongVO;
  1080. }
  1081. } catch (Exception e) {
  1082. throw new RuntimeException(e);
  1083. }
  1084. return null;
  1085. }
  1086. private Object zhongDimming(LampInfoDTO lamp,Integer light){
  1087. //获取token
  1088. Object tokenObject = this.getToken();
  1089. if (tokenObject == null ){
  1090. //失败
  1091. return null;
  1092. }else {
  1093. Integer errorCode = ((ZhongLightPlcVO) tokenObject).getErrorCode();
  1094. if (errorCode > 0) return tokenObject; //也是失败的
  1095. }
  1096. //登录
  1097. Object loginObject = this.zhongPlcLogin((ZhongLightPlcVO) tokenObject);
  1098. if (loginObject == null ){
  1099. //失败
  1100. return null;
  1101. }else {
  1102. Integer errorCode = ((ZhongLightPlcVO) loginObject).getErrorCode();
  1103. if (errorCode > 0) return loginObject; //也是失败的
  1104. }
  1105. //开始调光
  1106. String url = zhongLightPlc.getZhongUrl() + "commons/v1_0/send";
  1107. List arrayList = new ArrayList();
  1108. JSONObject jsonObject = new JSONObject();
  1109. jsonObject.put("code",1);
  1110. jsonObject.put("headSerial",1);
  1111. jsonObject.put("ep",1);
  1112. jsonObject.put("gatewayAddr","0x"+lamp.getSn().toLowerCase());
  1113. jsonObject.put("addr","0x"+lamp.getMacAddress());
  1114. jsonObject.put("uid",lamp.getLampCtrId());
  1115. JSONObject controlObject = new JSONObject();
  1116. controlObject.put("devtype",23);
  1117. controlObject.put("bri",light);
  1118. jsonObject.put("control",controlObject);
  1119. arrayList.add(jsonObject);
  1120. JSONObject dataObject = new JSONObject();
  1121. dataObject.put("platform",1);
  1122. dataObject.put("cmds",arrayList);
  1123. String dataObjectString = dataObject.toString();
  1124. //aes128位,模式:cbc,填充模式: pkcs5padding
  1125. //hmac-md5加密后,小写要转换成大写
  1126. String bodyStr = this.encryptAndMd5(dataObjectString);
  1127. String token = ((ZhongLightPlcVO) loginObject).getToken();
  1128. String sessionId = ((ZhongLightPlcVO) loginObject).getSessionId();
  1129. // String token = "eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiJNQTVHMERDUjMiLCJpYXQiOjE2OTcwMTkwMzQsInN1YiI6InVHeGR0OE5QNURZWStxWUQiLCJleHAiOjE2OTcwMjYyMzV9.AN-Af_x7qmxAEb736fo6bgrcgd02cjXZTB0QYa-oMOc";
  1130. // String sessionId = "25D085219FEBFD8D6587F0B984FF7F4E";
  1131. String respone = null;
  1132. try {
  1133. respone = toolUtils.sendHttp("post",url,bodyStr,token,sessionId,4,"Bearer", ToolUtils.ContentTypeEnum.CONTENT_TYPE_JSON,null);
  1134. System.out.println("=====diming:"+respone);
  1135. JSONObject parseObject = JSON.parseObject(respone);
  1136. Integer ret = parseObject.getInteger("Ret");
  1137. //{"Ret": 0, "Msg": "Successfully", "Data": "/FZGtGawB4O9lTtef3Up4w8rUWVjXvpWXk7P36M792A=", "Sig": "57D14850E6FED20D242D0C958DAE8403"}
  1138. ZhongLightPlcVO zhongLightPlcVO = new ZhongLightPlcVO();
  1139. zhongLightPlcVO.setTimes(3);
  1140. if (ret == 0){
  1141. //成功
  1142. String data = parseObject.getString("Data");
  1143. //解密
  1144. String decryptJson = aesUtils.decrypt(zhongLightPlc.getEncryptKey(), zhongLightPlc.getIv(), data);
  1145. //解释json数组
  1146. JSONArray objects = JSON.parseArray(decryptJson);
  1147. JSONObject resultbject = (JSONObject)objects.get(0);
  1148. Integer resultCode = resultbject.getInteger("result");
  1149. zhongLightPlcVO.setErrorCode(resultCode);//是否调光成功
  1150. zhongLightPlcVO.setSuccCode(0);
  1151. System.out.println("===dd:"+zhongLightPlcVO);
  1152. return zhongLightPlcVO;
  1153. }else if (ret == 4002){
  1154. //Invalid token
  1155. zhongLightPlcVO.setErrorCode(ret);
  1156. zhongLightPlcVO.setSuccCode(ret);
  1157. return zhongLightPlcVO;
  1158. }
  1159. } catch (Exception e) {
  1160. throw new RuntimeException(e);
  1161. }
  1162. return null;
  1163. }
  1164. /* 0. 最先要有了网关
  1165. * 1. 先添加控制器
  1166. * 2. 再添加灯具
  1167. */
  1168. //添加设备 - 控制器
  1169. private Object createCtrollLight(String macAddress,String uId,Integer zibeeSectionId,String longitude, String latitude,String name){
  1170. Object tokenObject = this.getToken();
  1171. if (tokenObject == null ){
  1172. //失败
  1173. return null;
  1174. }else {
  1175. Integer errorCode = ((ZhongLightPlcVO) tokenObject).getErrorCode();
  1176. if (errorCode > 0) return tokenObject; //也是失败的
  1177. }
  1178. //登录
  1179. Object loginObject = this.zhongPlcLogin((ZhongLightPlcVO) tokenObject);
  1180. if (loginObject == null ){
  1181. //失败
  1182. return null;
  1183. }else {
  1184. Integer errorCode = ((ZhongLightPlcVO) loginObject).getErrorCode();
  1185. if (errorCode > 0) return loginObject; //也是失败的
  1186. }
  1187. //创建控制器
  1188. String url = zhongLightPlc.getZhongUrl() + "commons/v1_0/create";
  1189. //type: 23(v3控制器)
  1190. JSONObject jsonObject = new JSONObject();
  1191. jsonObject.put("type",23);
  1192. jsonObject.put("gateway_id",uId);
  1193. jsonObject.put("section_id",zibeeSectionId);
  1194. jsonObject.put("division_id",((ZhongLightPlcVO) loginObject).getDivisionId());
  1195. jsonObject.put("organization_id",((ZhongLightPlcVO) loginObject).getOrganizationId());
  1196. jsonObject.put("project_id",((ZhongLightPlcVO) loginObject).getProjectId());
  1197. jsonObject.put("lamp_post_type",20);
  1198. jsonObject.put("lamp_post_number",macAddress);
  1199. JSONObject controlObject = new JSONObject();
  1200. controlObject.put("platform",1);
  1201. controlObject.put("type",3);
  1202. controlObject.put("addr","0x"+macAddress);
  1203. controlObject.put("property",jsonObject);
  1204. String dataObjectString = controlObject.toString();
  1205. //aes128位,模式:cbc,填充模式: pkcs5padding
  1206. //hmac-md5加密后,小写要转换成大写
  1207. String bodyStr = this.encryptAndMd5(dataObjectString);
  1208. //发送请求
  1209. String token = ((ZhongLightPlcVO) loginObject).getToken();
  1210. String sessionId = ((ZhongLightPlcVO) loginObject).getSessionId();
  1211. String respone = null;
  1212. try {
  1213. respone = toolUtils.sendHttp("post", url, bodyStr, token, sessionId, 5,"Bearer", ToolUtils.ContentTypeEnum.CONTENT_TYPE_JSON,null);
  1214. System.out.println("===dd:"+respone);
  1215. JSONObject parseObject = JSON.parseObject(respone);
  1216. Integer ret = parseObject.getInteger("Ret");
  1217. //{"Ret": 0, "Msg": "Successfully", "Data": "/FZGtGawB4O9lTtef3Up4w8rUWVjXvpWXk7P36M792A=", "Sig": "57D14850E6FED20D242D0C958DAE8403"}
  1218. ZhongLightPlcVO zhongLightPlcVO = new ZhongLightPlcVO();
  1219. zhongLightPlcVO.setTimes(3);
  1220. if (ret == 0){
  1221. //成功
  1222. String data = parseObject.getString("Data");
  1223. //解密
  1224. String decryptJson = aesUtils.decrypt(zhongLightPlc.getEncryptKey(), zhongLightPlc.getIv(), data);
  1225. //解释json
  1226. JSONObject resultbject = JSON.parseObject(decryptJson);
  1227. Integer resultCode = resultbject.getInteger("result");
  1228. zhongLightPlcVO.setErrorCode(resultCode);//是否调光成功
  1229. if (resultCode == 0){
  1230. //成功
  1231. zhongLightPlcVO.setSuccCode(0);
  1232. String lampCtrId = resultbject.getString("uid");
  1233. //zhongLightPlcVO.setLampCtrlId(lampCtrId);
  1234. ((ZhongLightPlcVO) loginObject).setLampCtrlId(lampCtrId);
  1235. //创建灯具
  1236. Object lightObject = this.createLight(macAddress, lampCtrId, loginObject, longitude, latitude, name);
  1237. if (lightObject != null){
  1238. ((ZhongLightPlcVO)lightObject).setLampCtrlId(lampCtrId);
  1239. return lightObject;
  1240. }
  1241. }else {
  1242. //创建失败
  1243. return zhongLightPlcVO;
  1244. }
  1245. }
  1246. } catch (Exception e) {
  1247. throw new RuntimeException(e);
  1248. }
  1249. return null;
  1250. }
  1251. private Object createLight(String macAddress,String lampCtrId,Object loginObject, String longitude,String latitude,String name){
  1252. String url = zhongLightPlc.getZhongUrl() + "commons/v1_0/create";
  1253. //zigbee设备网关会设置变比和轮询时间,所以与网关设置一样就可以了,poll_interval与formula
  1254. //port_id:是针对双灯控制器的
  1255. //type: 5是zigbee的控制器
  1256. JSONObject jsonObject = new JSONObject();
  1257. jsonObject.put("type",5);
  1258. jsonObject.put("encryption",1);
  1259. jsonObject.put("poll_interval",15);
  1260. jsonObject.put("formula",1);
  1261. jsonObject.put("division_id",((ZhongLightPlcVO) loginObject).getDivisionId());
  1262. jsonObject.put("organization_id",((ZhongLightPlcVO) loginObject).getOrganizationId());
  1263. jsonObject.put("project_id",((ZhongLightPlcVO) loginObject).getProjectId());
  1264. jsonObject.put("longitude",longitude);
  1265. jsonObject.put("latitude",latitude);
  1266. jsonObject.put("port_id",1);
  1267. jsonObject.put("lamp_ctrl_id",((ZhongLightPlcVO) loginObject).getLampCtrlId());
  1268. jsonObject.put("name",name);
  1269. JSONObject dataObject = new JSONObject();
  1270. dataObject.put("platform",1);
  1271. dataObject.put("type",4);
  1272. dataObject.put("addr","0x"+macAddress);
  1273. dataObject.put("property",jsonObject);
  1274. String dataObjectString = dataObject.toString();
  1275. String bodyStr = this.encryptAndMd5(dataObjectString);
  1276. //发送请求
  1277. String token = ((ZhongLightPlcVO) loginObject).getToken();
  1278. String sessionId = ((ZhongLightPlcVO) loginObject).getSessionId();
  1279. String respone = null;
  1280. try {
  1281. respone = toolUtils.sendHttp("post", url, bodyStr, token, sessionId, 5,"Bearer", ToolUtils.ContentTypeEnum.CONTENT_TYPE_JSON,null);
  1282. System.out.println("===light:"+respone);
  1283. JSONObject parseObject = JSON.parseObject(respone);
  1284. Integer ret = parseObject.getInteger("Ret");
  1285. //{"Ret": 0, "Msg": "Successfully", "Data": "/FZGtGawB4O9lTtef3Up4w8rUWVjXvpWXk7P36M792A=", "Sig": "57D14850E6FED20D242D0C958DAE8403"}
  1286. ZhongLightPlcVO zhongLightPlcVO = new ZhongLightPlcVO();
  1287. zhongLightPlcVO.setTimes(4);
  1288. if (ret == 0){
  1289. //成功
  1290. String data = parseObject.getString("Data");
  1291. //解密
  1292. String decryptJson = aesUtils.decrypt(zhongLightPlc.getEncryptKey(), zhongLightPlc.getIv(), data);
  1293. //解释json
  1294. JSONObject resultbject = JSON.parseObject(decryptJson);
  1295. Integer resultCode = resultbject.getInteger("result");
  1296. zhongLightPlcVO.setErrorCode(resultCode);//是否调光成功
  1297. if (resultCode == 0){
  1298. //成功
  1299. zhongLightPlcVO.setSuccCode(0);
  1300. String uid = resultbject.getString("uid");
  1301. zhongLightPlcVO.setUid(uid);
  1302. }
  1303. return zhongLightPlcVO;
  1304. }
  1305. } catch (Exception e) {
  1306. throw new RuntimeException(e);
  1307. }
  1308. return null;
  1309. }
  1310. //
  1311. private String encryptAndMd5(String data){
  1312. String key = zhongLightPlc.getEncryptKey();
  1313. String iv = zhongLightPlc.getIv();
  1314. String encryptStr = null;
  1315. //测试
  1316. //String objectString = "{\"OperatorID\":\"MA5G0DCR3\",\"OperatorSecret\":\"uGxdt8NP5DYY+qYD\"}";
  1317. try {
  1318. //aes128位,模式:cbc,填充模式: pkcs5padding,返回是base64
  1319. encryptStr = aesUtils.encrypt(key,iv,data);
  1320. } catch (Exception e) {
  1321. throw new RuntimeException(e);
  1322. }
  1323. String seq = "001";
  1324. Date date = new Date();
  1325. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
  1326. String day = dateFormat.format(date);
  1327. String sig = zhongLightPlc.getOperatorID()+encryptStr+day+seq;
  1328. //hmac-md5加密32位后,小写要转换成大写 0B692762DA3A4BE698E859FA8B7F1DF3
  1329. String hamc = null;
  1330. byte[] bytes = zhongLightPlc.getSigSecret().getBytes(StandardCharsets.UTF_8);
  1331. try {
  1332. hamc = aesUtils.encodeHmacMD5(sig.getBytes(), bytes);
  1333. } catch (Exception e) {
  1334. throw new RuntimeException(e);
  1335. }
  1336. //转换成大写
  1337. String upperHamc = hamc.toUpperCase();
  1338. JSONObject bodyJson = new JSONObject();
  1339. bodyJson.put("OperatorID",zhongLightPlc.getOperatorID());
  1340. bodyJson.put("Data",encryptStr);
  1341. bodyJson.put("TimeStamp",day);
  1342. bodyJson.put("Seq",seq);
  1343. bodyJson.put("Sig",upperHamc);
  1344. String bodyJsonString = bodyJson.toString();
  1345. return bodyJsonString;
  1346. }
  1347. //广东启慧-调光/集中器设备注册(网关)/控制器
  1348. private String quiHuiPlcDevice(String url,JSONObject params,Integer timeOut) {
  1349. String plcUrl = quHuiPlc.getUrl()+url;
  1350. Random random = new Random();
  1351. int min = 10000;
  1352. int max = 99999999;
  1353. String id = "wecloud_"+(random.nextInt(max-min) + min);
  1354. long timestamp = System.currentTimeMillis() / 1000;//单位是秒
  1355. String sign = quHuiPlc.getClientId()+timestamp+id+quHuiPlc.getClientSecret();
  1356. String md5Sign = DigestUtils.md5DigestAsHex(sign.getBytes()); //md5加密
  1357. HashMap<String, Object> map = new HashMap<>();
  1358. map.put("ver","1.0");
  1359. map.put("client_id",quHuiPlc.getClientId());
  1360. map.put("timestamp",timestamp);
  1361. map.put("id",id);
  1362. map.put("sign",md5Sign);
  1363. map.put("params",params);
  1364. ObjectMapper mapper = new ObjectMapper();
  1365. String json = null;
  1366. try {
  1367. json = mapper.writeValueAsString(map).toString();
  1368. } catch (JsonProcessingException e) {
  1369. throw new RuntimeException(e);
  1370. }
  1371. //发送post请求
  1372. String result = null;
  1373. try {
  1374. result = toolUtils.sendHttp("post",plcUrl, json, timeOut, ToolUtils.ContentTypeEnum.CONTENT_TYPE_JSON,null);
  1375. } catch (IOException e) {
  1376. throw new RuntimeException(e);
  1377. }
  1378. return result;
  1379. }
  1380. //广东启慧-集中器设备注册(网关)
  1381. // private String plcDevice(String url,String params,Integer timeOut){
  1382. // String plcUrl = quHuiPlc.getUrl()+url;
  1383. // Random random = new Random();
  1384. // int min = 10000;
  1385. // int max = 99999999;
  1386. // String id = "wecloud_"+(random.nextInt(max-min) + min);
  1387. // long timestamp = System.currentTimeMillis() / 1000;//单位是秒
  1388. // String sign = quHuiPlc.getClientId()+timestamp+id+quHuiPlc.getClientSecret();
  1389. // String md5Sign = DigestUtils.md5DigestAsHex(sign.getBytes()); //md5加密
  1390. //
  1391. // HashMap<String, Object> map = new HashMap<>();
  1392. // map.put("ver","1.0");
  1393. // map.put("client_id",quHuiPlc.getClientId());
  1394. // map.put("timestamp",timestamp); //用map,timestamp不会打包成字符串,jsonObject会打包成字符串的
  1395. // map.put("id",id);
  1396. // map.put("sign",md5Sign);
  1397. // map.put("params",params);
  1398. // ObjectMapper mapper = new ObjectMapper();
  1399. // String json = null;
  1400. // try {
  1401. // json = mapper.writeValueAsString(map).toString();
  1402. // } catch (JsonProcessingException e) {
  1403. // throw new RuntimeException(e);
  1404. // }
  1405. // //发送post请求
  1406. // String result = null;
  1407. // try {
  1408. // result = toolUtils.sendHttp("post",plcUrl, json, timeOut, ToolUtils.ContentTypeEnum.CONTENT_TYPE_JSON);
  1409. // } catch (IOException e) {
  1410. // throw new RuntimeException(e);
  1411. // }
  1412. // return result;
  1413. // }
  1414. /**
  1415. * 新建分组选择灯控
  1416. * @param request
  1417. * @return
  1418. */
  1419. @RequestMapping(value = "/selectLamp",method = RequestMethod.POST)
  1420. public BaseResult selectLamp(HttpServletRequest request){
  1421. String version = request.getParameter("version") == null ? "0" : request.getParameter("version");
  1422. String type = request.getParameter("type") == null ? "0" : request.getParameter("type");
  1423. String groupid = request.getParameter("groupid") == null || request.getParameter("groupid").length() == 0? "0" : request.getParameter("groupid");
  1424. System.out.println(toolUtils);
  1425. List sectionList = toolUtils.getSectionList(request);
  1426. GroupVO groupVO = new GroupVO();
  1427. groupVO.setVersion(Integer.valueOf(version));
  1428. groupVO.setId(Integer.valueOf(groupid));
  1429. groupVO.setSectionList(sectionList);
  1430. GroupDTO group = groupService.getDetailByVO(groupVO);
  1431. String[] lampArr = null;
  1432. if (group != null && group.getLampId() != null){
  1433. lampArr = group.getLampId().split(",");
  1434. }
  1435. LampListResponseVO lampListResponseVO = new LampListResponseVO();
  1436. lampListResponseVO.setVersion(Integer.valueOf(version));
  1437. lampListResponseVO.setSectionList(sectionList);
  1438. List<LampInfoDTO> lampList = lampService.groupSelectLamp(lampListResponseVO);
  1439. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  1440. List list = new ArrayList<>();
  1441. for (LampInfoDTO lamp :lampList) {
  1442. if (lampArr != null && ArrayUtils.contains(lampArr,lamp.getId().toString())){
  1443. lamp.setSelect(1);
  1444. }else {
  1445. if (type.equals("1")) continue;
  1446. lamp.setSelect(0);
  1447. }
  1448. if (lamp.getLighteness() == 0){
  1449. lamp.setLampStatusStr("关");
  1450. }else {
  1451. lamp.setLampStatusStr("开");
  1452. }
  1453. list.add(lamp);
  1454. }
  1455. LampListResponseVO lampListResponseVO1 = new LampListResponseVO();
  1456. lampListResponseVO1.setList(list);
  1457. return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,Integer.parseInt(version),lampListResponseVO1);
  1458. }
  1459. /**
  1460. * 灯控下拉
  1461. * @param request
  1462. * @return
  1463. */
  1464. @RequestMapping(value = "/nav",method = RequestMethod.POST)
  1465. public BaseResult nav(HttpServletRequest request) {
  1466. List sectionList = toolUtils.getSectionList(request);
  1467. Integer version = (Integer) toolUtils.getRequestContent(request,"version",1);
  1468. Integer lampType = (Integer) toolUtils.getRequestContent(request,"lampType",1);
  1469. LampListResponseVO lampListResponseVO = new LampListResponseVO();
  1470. lampListResponseVO.setSectionList(sectionList);
  1471. if (lampType == 1){
  1472. lampListResponseVO.setLampType(lampType);
  1473. }
  1474. List<LampInfoDTO> navByVO = lampService.getNavByVO(lampListResponseVO);
  1475. ListResponseVO listResponseVO = new ListResponseVO();
  1476. listResponseVO.setList(navByVO);
  1477. return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,listResponseVO);
  1478. }
  1479. /**
  1480. * 频段信息列表
  1481. * @param request
  1482. * @return
  1483. */
  1484. @RequestMapping(value = "/freqList",method = RequestMethod.POST)
  1485. public BaseResult freqList(HttpServletRequest request) {
  1486. Integer version = (Integer) toolUtils.getRequestContent(request,"version",1);
  1487. ArrayList<FreqDTO> freqDTOS = new ArrayList<>();
  1488. FreqDTO freqDTO = new FreqDTO();
  1489. freqDTO.setId(1);
  1490. freqDTO.setName("US915");
  1491. freqDTOS.add(freqDTO);
  1492. freqDTO = new FreqDTO();
  1493. freqDTO.setId(2);
  1494. freqDTO.setName("EU868");
  1495. freqDTOS.add(freqDTO);
  1496. freqDTO = new FreqDTO();
  1497. freqDTO.setId(3);
  1498. freqDTO.setName("AS923");
  1499. freqDTOS.add(freqDTO);
  1500. ListResponseVO listResponseVO = new ListResponseVO();
  1501. listResponseVO.setList(freqDTOS);
  1502. return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,listResponseVO);
  1503. }
  1504. /**
  1505. * 获取经纬度
  1506. * @param request
  1507. * @return
  1508. */
  1509. @RequestMapping(value = "/sectionData",method = RequestMethod.POST)
  1510. public BaseResult sectionData(HttpServletRequest request) {
  1511. Integer version = (Integer) toolUtils.getRequestContent(request,"version",1);
  1512. Integer sectionId = (Integer) toolUtils.getRequestContent(request,"sectionId",1);
  1513. Integer areaId = (Integer) toolUtils.getRequestContent(request,"areaId",1);
  1514. LampInfoDTO lampInfoDTO = new LampInfoDTO();
  1515. if ((sectionId == null || sectionId.intValue() == 0) && (areaId == null || areaId.intValue() == 0)) {
  1516. lampInfoDTO.setLongitude(114.06807299140166f);
  1517. lampInfoDTO.setLatitude(22.5324106360218f);
  1518. return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,lampInfoDTO);
  1519. }
  1520. if (areaId == null || areaId.intValue() == 0){
  1521. SectionDTO oneById = sectionService.getOneById(sectionId);
  1522. GlobalLocationDTO oneById2 = globalLocationService.getOneById(oneById.getPid());
  1523. lampInfoDTO.setLongitude(oneById2.getLongitude());
  1524. lampInfoDTO.setLatitude(oneById2.getLatitude());
  1525. }else {
  1526. GlobalLocationDTO oneById = globalLocationService.getOneById(areaId);
  1527. lampInfoDTO.setLongitude(oneById.getLongitude());
  1528. lampInfoDTO.setLatitude(oneById.getLatitude());
  1529. }
  1530. return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,lampInfoDTO);
  1531. }
  1532. /**
  1533. * 获取太阳能控制器设备列表
  1534. * @param request 根据sectionId进行筛选
  1535. * @return 返回设备列表
  1536. */
  1537. @RequestMapping(value = "/getSolarList", method = RequestMethod.POST)
  1538. public BaseResult<?> getSolarList(HttpServletRequest request) {
  1539. int version = (int) toolUtils.getRequestContent(request,"version",1);
  1540. int online = (int) toolUtils.getRequestContent(request,"online",1);
  1541. int page = request.getParameter("page") == null ? 1 : Integer.parseInt(request.getParameter("page"));
  1542. int count = request.getParameter("count") == null ? 16 : Integer.parseInt(request.getParameter("count"));
  1543. String keyword = (String) toolUtils.getRequestContent(request,"online",2);
  1544. SolarDevDTO dto = new SolarDevDTO();
  1545. dto.setPage(count * (page - 1));
  1546. dto.setCount(count);
  1547. dto.setVersion(version);
  1548. dto.setOnline(online);
  1549. dto.setKeyword(keyword);
  1550. dto.setSectionList(toolUtils.getSectionList(request));
  1551. SolarDevVO solarDevVO = solarDevService.getSolarListByDTO(dto);
  1552. return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,solarDevVO);
  1553. }
  1554. /**
  1555. * 获取太阳能统计数据
  1556. * @param request 设备id
  1557. * @return 返回太阳能统计数据
  1558. */
  1559. @RequestMapping(value = "/solarStatistics", method = RequestMethod.POST)
  1560. public BaseResult<?> solarStatistics(HttpServletRequest request) throws ParseException {
  1561. int version = (int) toolUtils.getRequestContent(request,"version",1);
  1562. int id = (int) toolUtils.getRequestContent(request,"id",1);
  1563. if (id == 0) return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR,version);
  1564. Integer timezone = solarInfoLogService.getTimezoneBySolarId(id);
  1565. if (timezone == null) return toolUtils.response(InterfaceResultEnum.PARAM_FAIL,version);
  1566. long l = System.currentTimeMillis() - timezone * 3600 * 1000;
  1567. long startTime;
  1568. long endTime;
  1569. startTime = l - 24L * 3600 * 1000 * 29;
  1570. endTime = l;
  1571. HashMap<String, Integer> objectObjectHashMap = new HashMap<>();
  1572. long timeT = startTime;
  1573. int i = 0;
  1574. List<Object> dateList = new ArrayList<>();
  1575. List<Object> lightTimeList = new ArrayList<>();
  1576. List<Object> comList = new ArrayList<>();
  1577. List<Object> eleList = new ArrayList<>();
  1578. List<Object> totalLightTime = new ArrayList<>();
  1579. List<Object> totalCom = new ArrayList<>();
  1580. List<Object> totalEle = new ArrayList<>();
  1581. List<SolarInfoLogDTO> list = new ArrayList<>();
  1582. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
  1583. while (timeT <= endTime) {
  1584. objectObjectHashMap.put(simpleDateFormat.format(new Date(timeT)),i);
  1585. dateList.add(simpleDateFormat.format(new Date(timeT + timezone * 3600 * 1000)));
  1586. lightTimeList.add(0);
  1587. eleList.add(0);
  1588. comList.add(0);
  1589. totalLightTime.add(0);
  1590. totalCom.add(0);
  1591. totalEle.add(0);
  1592. list.add(null);
  1593. timeT += 3600 * 1000 * 24;
  1594. i++;
  1595. }
  1596. List<SolarInfoLogDTO> solarInfoLogList = solarInfoLogService.getSolarInfoLogByDTO(id);
  1597. for (SolarInfoLogDTO solarInfoLogDTO : solarInfoLogList) {
  1598. Date date = new Date(simpleDateFormat.parse(solarInfoLogDTO.getMaxTime()).getTime());
  1599. String s = simpleDateFormat.format(date);
  1600. if (objectObjectHashMap.containsKey(s)){
  1601. Integer integer = objectObjectHashMap.get(s);
  1602. list.set(integer,solarInfoLogDTO);
  1603. }
  1604. }
  1605. DecimalFormat decimalFormat = new DecimalFormat("0.000");
  1606. for (SolarInfoLogDTO solarInfoLogDTO : list) {
  1607. if (solarInfoLogDTO != null) {
  1608. Date date = new Date(simpleDateFormat.parse(solarInfoLogDTO.getMaxTime()).getTime());
  1609. String s = simpleDateFormat.format(date);
  1610. Integer integer = null;
  1611. if (objectObjectHashMap.containsKey(s)){
  1612. integer = objectObjectHashMap.get(s);
  1613. list.set(integer,solarInfoLogDTO);
  1614. }
  1615. if (solarInfoLogDTO.getMaxTotalLightTime() != null && solarInfoLogDTO.getMinTotalLightTime() != null && integer != null) {
  1616. totalLightTime.set(integer,Integer.parseInt(solarInfoLogDTO.getMaxTotalLightTime()));
  1617. Integer dayLightTime = Integer.parseInt(solarInfoLogDTO.getMaxTotalLightTime()) - Integer.parseInt(solarInfoLogDTO.getMinTotalLightTime());
  1618. lightTimeList.set(integer,dayLightTime);
  1619. }
  1620. if (solarInfoLogDTO.getMaxTotalConsumption() != null && solarInfoLogDTO.getMinTotalConsumption() != null && integer != null) {
  1621. totalCom.set(integer,Float.parseFloat(solarInfoLogDTO.getMaxTotalConsumption()));
  1622. Float dayCom = Float.parseFloat(solarInfoLogDTO.getMaxTotalConsumption()) - Float.parseFloat(solarInfoLogDTO.getMinTotalConsumption());
  1623. comList.set(integer,Float.parseFloat(decimalFormat.format(dayCom)));
  1624. }
  1625. if (solarInfoLogDTO.getMaxTotalEleSave() != null && solarInfoLogDTO.getMinTotalEleSave() != null && integer != null) {
  1626. totalEle.set(integer,Float.parseFloat(solarInfoLogDTO.getMaxTotalEleSave()));
  1627. Float daySave = Float.parseFloat(solarInfoLogDTO.getMaxTotalEleSave()) - Float.parseFloat(solarInfoLogDTO.getMinTotalEleSave());
  1628. eleList.set(integer,Float.parseFloat(decimalFormat.format(daySave)));
  1629. }
  1630. }
  1631. }
  1632. SolarInfoLogVO solarInfoLogVO = new SolarInfoLogVO();
  1633. solarInfoLogVO.setDateList(dateList);
  1634. solarInfoLogVO.setLightTimeList(lightTimeList);
  1635. solarInfoLogVO.setComList(comList);
  1636. solarInfoLogVO.setEleList(eleList);
  1637. solarInfoLogVO.setTotalLightTime(totalLightTime);
  1638. solarInfoLogVO.setTotalCom(totalCom);
  1639. solarInfoLogVO.setTotalEle(totalEle);
  1640. return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,solarInfoLogVO);
  1641. }
  1642. /**
  1643. * 新建分组下选择灯杆
  1644. * @param request sectionList,groupId,sectionId,type
  1645. * @return 新建分组下选择灯杆
  1646. */
  1647. @RequestMapping(value = "/selectLampPole", method = RequestMethod.POST)
  1648. public BaseResult<?> lampPoleData(HttpServletRequest request) {
  1649. Integer version = (Integer) toolUtils.getRequestContent(request,"version",1);
  1650. Integer type = (Integer) toolUtils.getRequestContent(request,"type",1);
  1651. Integer groupId = (Integer) toolUtils.getRequestContent(request,"groupId",1);
  1652. List<LampPoleDTO> lampPoleList;
  1653. if (type == 1) { // 查询分组下的灯杆
  1654. if (groupId == 0) return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR,version);
  1655. GroupDTO groupDTO = groupService.getGroupDTOById(groupId);
  1656. if (groupDTO == null) return toolUtils.response(InterfaceResultEnum.PARAM_FAIL,version);
  1657. if (groupDTO.getDevType() == 0) return toolUtils.response(InterfaceResultEnum.PARAM_FAIL,version);
  1658. String lampId = groupDTO.getLampId();
  1659. List<String> lampIds = Arrays.asList(lampId.split(","));
  1660. lampPoleList = lampPoleService.getLampPoleByLampIds(lampIds);
  1661. lampPoleList.forEach(dto -> dto.setSelect(1));
  1662. } else { //根据路段查询灯杆,分组可选
  1663. Integer sectionId = (Integer) toolUtils.getRequestContent(request,"sectionId",1);
  1664. LampPoleVO lampPoleVO = new LampPoleVO();
  1665. lampPoleVO.setVersion(version);
  1666. lampPoleVO.setSectionList(toolUtils.getSectionList(request));
  1667. lampPoleVO.setSectionId(sectionId);
  1668. if (groupId == 0) {
  1669. lampPoleList = lampPoleService.getSectionLampPoleList(lampPoleVO);
  1670. lampPoleList.forEach(dto -> dto.setSelect(0));
  1671. } else {
  1672. GroupDTO groupDTO = groupService.getGroupDTOById(groupId);
  1673. if (groupDTO == null) return toolUtils.response(InterfaceResultEnum.PARAM_FAIL,version);
  1674. if (groupDTO.getDevType() == 0) return toolUtils.response(InterfaceResultEnum.PARAM_FAIL,version);
  1675. lampPoleList = lampPoleService.getSectionLampPoleList(lampPoleVO);
  1676. String lampId = groupDTO.getLampId();
  1677. String[] lampIds = lampId.split(",");
  1678. for (LampPoleDTO l : lampPoleList) {
  1679. boolean isFlag = false;
  1680. for (String s : lampIds) {
  1681. if (l.getId().equals(Integer.valueOf(s))) {
  1682. l.setSelect(1);
  1683. isFlag = true;
  1684. break;
  1685. }
  1686. }
  1687. if (!isFlag) {
  1688. l.setSelect(0);
  1689. }
  1690. }
  1691. }
  1692. }
  1693. LampPoleVO lampPoleVO = new LampPoleVO();
  1694. lampPoleVO.setList(lampPoleList);
  1695. return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,lampPoleVO);
  1696. }
  1697. }