LampController.java 90 KB

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