package com.welampiot.controller; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.welampiot.common.BaseResult; import com.welampiot.common.InterfaceResultEnum; import com.welampiot.configuration.*; import com.welampiot.dto.*; import com.welampiot.service.*; import com.welampiot.utils.AESUtils; import com.welampiot.utils.JwtUtil; import com.welampiot.utils.ToolUtils; import com.welampiot.vo.*; import org.apache.commons.lang3.ArrayUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.DigestUtils; import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import javax.servlet.http.HttpServletRequest; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.text.DecimalFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; import java.util.stream.Collectors; @RestController @CrossOrigin @RequestMapping("/lamp") public class LampController { @Autowired private LampService lampService; @Autowired private ToolUtils toolUtils; @Autowired private NetworkService networkService; @Autowired private GroupService groupService; @Autowired private GlobalLocationService globalLocationService; @Autowired private SectionService sectionService; @Autowired private SolarDevService solarDevService; @Autowired private SolarInfoLogService solarInfoLogService; @Autowired private LampPoleService lampPoleService; @Autowired private QuHuiPlc quHuiPlc; @Autowired private ZhongLightPlc zhongLightPlc; @Autowired private AESUtils aesUtils; @Autowired private PlcAddressService plcAddressService; @Autowired private FreqMapConfig freqMapConfig; @Autowired private JwtUtil jwtUtil; @Autowired private LastSqlInterceptor lastSqlInterceptor; //获取sql语句 /** * 灯控列表 * @param request * @return */ @RequestMapping(value = "/getlist",method = RequestMethod.POST) public BaseResult getList(HttpServletRequest request){ Integer version = request.getParameter("version") == null ? 0 : Integer.parseInt(request.getParameter("version")); Integer page = request.getParameter("page") == null ? 1 : Integer.parseInt(request.getParameter("page")); Integer count = request.getParameter("count") == null ? 16 : Integer.parseInt(request.getParameter("count")); Integer online = request.getParameter("online") == null || request.getParameter("online") == "" ? null : Integer.parseInt(request.getParameter("online")); Integer light_status = request.getParameter("light_status") == null || request.getParameter("light_status") == "" ? null : Integer.parseInt(request.getParameter("light_status")); String keyword = request.getParameter("keyword") == null ? "" : request.getParameter("keyword"); Integer limit = count; Integer offset = (page-1)*count; List sectionList = toolUtils.getSectionList(request); LampListResponseVO lampListResponseVO = new LampListResponseVO(); if (keyword.length() > 0) lampListResponseVO.setKeyword(keyword); lampListResponseVO.setSectionList(sectionList); lampListResponseVO.setVersion(version); lampListResponseVO.setLimit(limit); lampListResponseVO.setOffset(offset); if (online != null) lampListResponseVO.setOnline(online); if (light_status != null) lampListResponseVO.setLightStatus(light_status); List listByVO = lampService.getListByVO(lampListResponseVO); LampListResponseVO lampListResponseVO1 = new LampListResponseVO(); lampListResponseVO1.setList(listByVO); LampCountVO lampCountVO = new LampCountVO(); lampCountVO.setSectionList(sectionList); if (online != null) lampCountVO.setOnlineStatus(online); if (light_status != null) lampCountVO.setLampStatus(light_status); if (keyword.length() > 0) lampCountVO.setKeyword(keyword); Integer countByVO = lampService.getCountByVO(lampCountVO); lampListResponseVO1.setTotal(countByVO/count); lampListResponseVO1.setTotal2(countByVO); lampCountVO = new LampCountVO(); lampCountVO.setSectionList(sectionList); countByVO = lampService.getCountByVO(lampCountVO); lampListResponseVO1.setDevTotal(countByVO); lampCountVO.setOnlineStatus(1); countByVO = lampService.getCountByVO(lampCountVO); lampListResponseVO1.setOnlineCount(countByVO); lampCountVO.setLampStatus(1); countByVO = lampService.getCountByVO(lampCountVO); lampListResponseVO1.setLightCount(countByVO); lampCountVO.setAlarmStatus(1); lampListResponseVO1.setAlarmCount(countByVO); return BaseResult.success(lampListResponseVO1); } /** * 灯控详情 * @param request * @return */ @RequestMapping(value = "/details",method = RequestMethod.POST) public BaseResult details(HttpServletRequest request){ Integer version = request.getParameter("version") == null ? 0 : Integer.parseInt(request.getParameter("version")); Integer lampId = request.getParameter("lampId") == null ? 0 : Integer.parseInt(request.getParameter("lampId")); LampInfoDTO detailsById = lampService.getDetailsById(lampId,version); return BaseResult.success(detailsById); } @RequestMapping(value = "/getkk", method = RequestMethod.POST) public Integer kk(HttpServletRequest request) { toolUtils.addOpertaionLog(request,null,null,null,null,null,null,null,null,null,null,null,null,null); return 0; } /** * 添加编辑灯控 * @param request * @return */ @RequestMapping(value = "/save",method = RequestMethod.POST) @Transactional public BaseResult save(HttpServletRequest request){ Integer version = request.getParameter("version") == null ? 0 : Integer.parseInt(request.getParameter("version")); Integer lampId = request.getParameter("lampId") == null || request.getParameter("lampId").length() == 0? 0 : Integer.parseInt(request.getParameter("lampId")); String area = request.getParameter("areaId");// == null ? 0 : Integer.parseInt(request.getParameter("areaId")); if (area == null || area.equals("0")) return toolUtils.response(InterfaceResultEnum.LACK_AREA_ERROR,version); Integer areaId = Integer.parseInt(area); String section = request.getParameter("sectionId"); // == null ? 0 : Integer.parseInt(request.getParameter("sectionId")); if (section == null || section.equals("0")) return toolUtils.response(InterfaceResultEnum.LACK_SECTION_ERROR,version); Integer sectionId = Integer.parseInt(section); String protocol = request.getParameter("protocolType");// == null ? 0 : Integer.parseInt(request.getParameter("protocolType")); if (protocol == null) return toolUtils.response(InterfaceResultEnum.LACK_PROTOCOL_TYPE_ERROR,version); Integer protocolType = Integer.parseInt(protocol); String control = request.getParameter("controlType");// == null ? 0 : Integer.parseInt(request.getParameter("controlType")); if (control == null) return toolUtils.response(InterfaceResultEnum.LACK_LOOP_CONTROL_TYPE_ERROR,version); Integer controlType = Integer.parseInt(control); Integer power = request.getParameter("power") == null ? 0 : Integer.parseInt(request.getParameter("power")); String installDate = request.getParameter("installDate") == null ? "" : request.getParameter("installDate"); String expirationDate = request.getParameter("expirationDate") == null ? "" : request.getParameter("expirationDate"); String number = request.getParameter("number"); if (number == null || number.length() == 0) return toolUtils.response(InterfaceResultEnum.LIGHT_NUMBER_ERROR,version); if (number.length() == 1 && number.equals("0")) return toolUtils.response(InterfaceResultEnum.LIGHT_NUMBER_ZERO_ERROR,version); if (number.length() > 6) return toolUtils.response(InterfaceResultEnum.LIGHT_NUMBER_LENGTH_ERROR,version); String regex = "^[A-Za-z0-9_]+$"; if (number.matches(regex) == false) return toolUtils.response(InterfaceResultEnum.LIGHT_NUMBER_NAME_ERROR,version); if (number.length() < 6){ //初全长度为6 number = "000000"+number; number = number.substring(number.length() - 6,number.length()); } String longitude = request.getParameter("longitude") == null || request.getParameter("longitude").length() == 0 ? "0" : request.getParameter("longitude"); String latitude = request.getParameter("latitude") == null || request.getParameter("latitude").length() == 0 ? "0" : request.getParameter("latitude"); String name = request.getParameter("name"); String sn = request.getParameter("sn"); if (sn == null || sn.length() == 0) return toolUtils.response(InterfaceResultEnum.LACK_ADDRESS_ERROR,version); sn = sn.trim();//去除两边的空格 String devAddr = request.getParameter("devAddr"); Integer bindStatus = 1; if (protocolType == 11 && (controlType == 4 || controlType == 8) ){ if ( devAddr == null || devAddr.length() == 0) return toolUtils.response(InterfaceResultEnum.LACK_LIGHT_SERIAL_Number_ERROR,version); if (Integer.parseInt(devAddr) < 10) return toolUtils.response(InterfaceResultEnum.LIGHT_SERIAL_Number_RANGE_ERROR,version); bindStatus = 0; } String freqId = request.getParameter("freqId"); if (protocolType == 6 && freqId == null) return toolUtils.response(InterfaceResultEnum.LACK_FREQUENCY_ERROR,version); String loopNumber = request.getParameter("loopNumber"); if (protocolType == 5){ //zigbee灯具所属的回路 if (loopNumber == null || loopNumber.equals("0")) return toolUtils.response(InterfaceResultEnum.LACK_ZIGBEE_LOOP_NUMBER_ERROR,version); } String macAddress = request.getParameter("macAddress"); if (protocolType == 11 || protocolType == 5){ //macAddress的值不能为空 if (macAddress == null) return toolUtils.response(InterfaceResultEnum.LACK_PLC_MACADDRESS__ERROR,version); } if (controlType == 26 || controlType == 27){ if (macAddress != null && sn != null){ bindStatus = 0; //微自然plc this.savePlcAddress(macAddress,sn); } } String groupId = request.getParameter("groupId"); String lampPoleId = request.getParameter("lampPoleId"); Date day = new Date(); SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String updateTime = sdf.format(day); Integer userId = toolUtils.getUser(request).getId(); if (lampId == 0){ // 添加 //同一个路段下不能有相同的编号 LampInfoDTO lampInfo = new LampInfoDTO(); lampInfo.setSectionId(sectionId); lampInfo.setNumber(number); //若两灯的,只添加其中一个的就要判断了 // Integer byVO = lampService.findByVO(lampInfo); // if (byVO > 0) return toolUtils.response(InterfaceResultEnum.NUMBER_EXIST_ERROR,version); lampInfo.setSectionId(null); lampInfo.setNumber(null); lampInfo.setAddress(sn); NetworkDTO networkData = new NetworkDTO(); //同一个plc下不允许有相同的序号/相同灯的地址 Integer header = 0; //灯头:0代表没,1代表灯头1,2代表灯头2 Integer plcNetCount = 0; //网关, 0:没有创建 ,1: 创建过了 if (protocolType == 11 && controlType != 26 && controlType != 27){ String otherDevAddr = ""; //另外一个 lampInfo.setMacAddress(macAddress); if (controlType == 4 || controlType == 11 || controlType == 12 || controlType == 14 ){ //同一个路段下编号不允相同 LampInfoDTO newLamp = new LampInfoDTO(); newLamp.setNumber(number); newLamp.setSectionId(sectionId); Integer byVO = lampService.findByVO(newLamp); if (byVO > 0) return toolUtils.response(InterfaceResultEnum.NUMBER_EXIST_ERROR,version); //单灯的情况下是不允许有重复地址的 //灯地址 Integer macAddressTotal = lampService.checkData(lampInfo); if (macAddressTotal > 0) return toolUtils.response(InterfaceResultEnum.PLC_ADDRESS_EXIST_ERROR,version); } else if (controlType == 8) { //双灯的情况,检查是否有两个了,若有则不能重复,若没有,则要知道有了哪个灯头 List dtoList = lampService.getListByDto(lampInfo); if (dtoList != null && dtoList.size() == 2){ //已经存在 return toolUtils.response(InterfaceResultEnum.PLC_ADDRESS_EXIST_ERROR,version); }else { //不存在或只存在一个灯头 if (dtoList != null && dtoList.size() == 1){ //存在一个灯头 header = dtoList.get(0).getMode() + 1; otherDevAddr = dtoList.get(0).getDevAddr(); }else { //同一个路段下编号不允相同 LampInfoDTO newLamp = new LampInfoDTO(); newLamp.setNumber(number); newLamp.setSectionId(sectionId); Integer byVO = lampService.findByVO(newLamp); if (byVO > 0) return toolUtils.response(InterfaceResultEnum.NUMBER_EXIST_ERROR,version); } } } //灯序号 if (header == 0){ lampInfo.setMacAddress(null); lampInfo.setDevAddr(devAddr); Integer devAddrTotal = lampService.checkData(lampInfo); if (devAddrTotal > 0) return toolUtils.response(InterfaceResultEnum.PLC_SERIAL_NUMBER_EXIST_ERROR,version); lampInfo.setMacAddress(macAddress); }else { //双灯只添加其中一个 if (!devAddr.equals(otherDevAddr)){ //跟原来的不一样 return toolUtils.response(InterfaceResultEnum.PLC_SERIAL_NUMBER_SAME__ERROR,version); }else { lampInfo.setDevAddr(devAddr); } } }else { //同一个路段下编号不允相同 LampInfoDTO newLamp = new LampInfoDTO(); newLamp.setNumber(number); newLamp.setSectionId(sectionId); Integer byVO = lampService.findByVO(newLamp); if (byVO > 0) return toolUtils.response(InterfaceResultEnum.NUMBER_EXIST_ERROR,version); } if (protocolType == 13 || controlType == 26 || controlType == 27){ lampInfo.setMacAddress(macAddress); //lampInfo.setAddress(sn); Integer devAddrTotal = lampService.checkData(lampInfo); if (devAddrTotal > 0) return toolUtils.response(InterfaceResultEnum.PLC_ADDRESS_EXIST_ERROR,version); } if (protocolType == 5){ //zigbee设备先判断有没有添加网关 //NetworkDTO network = new NetworkDTO(); networkData.setDeviceSn(sn); Integer networkTotal = networkService.checkNetworkData(networkData); if (networkTotal == 0) return toolUtils.response(InterfaceResultEnum.LACK_PLC_ADDRESS__ERROR,version); //获取网关id NetworkDTO network = networkService.getSimpleData(networkData); lampInfo.setNetworkId(network.getId()); } Integer checkAddressTotal = lampService.checkData(lampInfo); if (protocolType != 11 && protocolType != 5 && protocolType != 13 && checkAddressTotal > 0){ LampInfoDTO dataByVO = lampService.getDataByVO(lampInfo); //section SectionDTO sectionDTO = new SectionDTO(); sectionDTO.setId(dataByVO.getSectionId()); sectionDTO= sectionService.getDataByVO(sectionDTO); //location GlobalLocationDTO areaData = new GlobalLocationDTO(); areaData.setId(sectionDTO.getPid()); areaData = globalLocationService.getDataByDto(areaData); String chinaMsg = "无线模块地址已存在,区域: "+areaData.getChineseName()+"-->路段:"+sectionDTO.getName()+"-->路灯编号:"+dataByVO.getNumber(); String engMsg = "The wireless address already exists,area: "+areaData.getEnglishName()+"-->section:"+sectionDTO.getName()+"-->number:"+dataByVO.getNumber(); String ruMsg = "Беспроводной адрес уже существует,область: "+areaData.getRuName()+"-->участок дороги:"+sectionDTO.getName()+"-->Номер фонаря:"+dataByVO.getNumber(); if (version == 0){ String code = "0403"; if (version == 0){ BaseResult objectBaseResult = new BaseResult<>(code, chinaMsg, new Object()); return objectBaseResult; } else if (version == 1) { BaseResult objectBaseResult = new BaseResult<>(code, engMsg, new Object()); return objectBaseResult; }else { BaseResult objectBaseResult = new BaseResult<>(code, ruMsg, new Object()); return objectBaseResult; } } } lampInfo.setBindStatus(bindStatus); //String netAddress = ""; if (protocolType == 0 || protocolType == 3 || protocolType == 4 || protocolType == 5 || protocolType == 6 || protocolType == 7 || protocolType == 8 || protocolType == 9 || protocolType == 10 || protocolType == 11 || protocolType == 13){ lampInfo.setNetType(1); //直连设备 if (protocolType == 11 || protocolType == 5){ //netAddress = sn; //plc下有单灯控制器和双灯控制器 lampInfo.setBindStatus(0); }else { sn = sn.length() == 13 ? String.valueOf(Integer.parseInt(sn,10)) : sn; } //networkData = new NetworkDTO(); networkData.setDeviceSn(sn); NetworkDTO simpleData = networkService.getSimpleData(networkData); //zigbee设备 plc if (protocolType == 5 && controlType == 13){ //先添加控制器,再添加灯具 lampInfo.setMacAddress(macAddress); //灯地址 Integer macAddressTotal = lampService.checkData(lampInfo); if (macAddressTotal > 0) return toolUtils.response(InterfaceResultEnum.PLC_ADDRESS_EXIST_ERROR,version); Object lightObject = this.createCtrollLight(macAddress,simpleData.getUId(),Integer.parseInt(loopNumber),longitude,latitude,name); if (lightObject == null){ return toolUtils.response(InterfaceResultEnum.CREATE_LIGHT_ERROR,version); }else { Integer times = ((ZhongLightPlcVO)lightObject).getTimes(); Integer errorCode = ((ZhongLightPlcVO)lightObject).getErrorCode(); if (errorCode > 0){ if (times == 3) return toolUtils.response(InterfaceResultEnum.CREATE_CONTROL_ERROR,version); if (times == 4) return toolUtils.response(InterfaceResultEnum.CREATE_CONTROL_LIGHT_ERROR,version); }else { //成功 lampInfo.setLampCtrId(((ZhongLightPlcVO)lightObject).getLampCtrlId()); lampInfo.setUid(((ZhongLightPlcVO)lightObject).getUid()); lampInfo.setBindStatus(1); } } } if (protocolType != 11 && protocolType != 13 && protocolType != 5 && simpleData != null){ lampInfo.setAddress(null); lampInfo.setNetworkId(simpleData.getId()); LampInfoDTO lamp = lampService.getDataByVO(lampInfo); if (lamp != null){ networkService.deleteNetworkData(simpleData.getId()); } lampInfo.setAddress(sn); } // plc只创建一个网络就可以了 if (simpleData != null){ if (protocolType == 11 && (controlType != 26 && controlType != 27)){ plcNetCount = 1; } } networkData.setGatewayType("direct"); networkData.setProtocolType(protocolType); networkData.setAreaId(areaId); networkData.setSectionId(sectionId); if (protocolType == 10) networkData.setDeviceType(4); if (protocolType == 8 && (controlType == 29 || controlType == 33 || controlType == 19)) networkData.setDeviceType(4); if (protocolType == 3 && controlType == 9) networkData.setDeviceType(4); if (controlType == 16 || controlType == 20) networkData.setDeviceType(5); networkData.setNetworkName(sn); networkData.setNetType(1); networkData.setCreateTime(updateTime); networkData.setUserId(userId); if (protocolType == 6) this.addDevice(sn,freqId); if (protocolType == 7){ //添加onenet String deviceOnenet = toolUtils.addDeviceOnenet(sn); if (deviceOnenet != null && deviceOnenet.length() != 0){ JSONObject onenetObject = JSON.parseObject(deviceOnenet); JSONObject data = onenetObject.getJSONObject("data"); String onenetId = data.getString("device_id"); if (onenetId != null && onenetId.length() != 0){ lampInfo.setDeviceId(onenetId); networkData.setDeviceId(onenetId); } } } } if (protocolType == 10 && (controlType == 7 || controlType == 6 || controlType == 15 || controlType == 19 || controlType == 21 || controlType == 30 || controlType == 31 || controlType == 32 || controlType == 35)) lampInfo.setMode(1); if (protocolType == 8 && (controlType == 19 || controlType == 23 || controlType == 33 || controlType == 37)) lampInfo.setMode(1); if (protocolType == 11 && controlType != 26 && controlType != 27){ if (plcNetCount == 0){ if (controlType != 4 && controlType != 8){ //广东启慧 - plc String url = "concentrator/deviceRegister"; JSONObject qihuiObject = new JSONObject(); qihuiObject.put("deviceId",sn); //添加网关 String result = this.quiHuiPlcDevice(url, qihuiObject, 4); if (result == null || result.length() == 0){ return toolUtils.response(InterfaceResultEnum.SEND_CMD_TIME_OUT,version); }else { JSONObject parseObject = JSON.parseObject(result); Integer code = parseObject.getInteger("code"); if (code == 200){ networkService.add(networkData); lampInfo.setNetworkId(networkData.getId()); } else { String msg = parseObject.getString("msg"); BaseResult objectBaseResult = new BaseResult<>(code.toString(), msg, new Object()); return objectBaseResult; } } }else { //力合微 plc networkService.add(networkData); lampInfo.setNetworkId(networkData.getId()); } }else { NetworkDTO network = networkService.getSimpleData(networkData); lampInfo.setNetworkId(network.getId()); } } else { if (protocolType == 1){ networkData.setGatewayType("direct"); networkData.setProtocolType(protocolType); networkData.setAreaId(areaId); networkData.setSectionId(sectionId); networkData.setDeviceSn(sn); networkData.setNetworkName(sn); networkData.setNetType(1); networkData.setCreateTime(updateTime); } networkService.add(networkData); lampInfo.setNetworkId(networkData.getId()); } SectionDTO sectionDTO = new SectionDTO(); sectionDTO.setId(sectionId); sectionDTO = sectionService.getDataByVO(sectionDTO); GlobalLocationDTO areaDTO = new GlobalLocationDTO(); areaDTO.setId(sectionDTO.getPid()); areaDTO = globalLocationService.getDataByDto(areaDTO); lampInfo.setCreateTime(updateTime); //添加plc控制器节点 - 启慧 if (protocolType == 11 && (controlType == 11 || controlType == 12 || controlType == 14)) { String url = "childnode/deviceRegister"; String nodeType = this.selectNodeType(power); if (nodeType == null || nodeType.length() == 0) return toolUtils.response(InterfaceResultEnum.POWER_SELECT_ERROR,version); JSONObject qiObject = new JSONObject(); if (groupId != null && groupId.length() != 0){ String[] groupIds = groupId.split(","); List list = groupService.getListByIds(groupIds); //有分组 (只有: 1- 255) for (GroupDTO item:list) { Integer groupNumber = Integer.parseInt(item.getNumber()); if (groupNumber < 1 || groupNumber > 255){ //分组没有在规定的范围内 return toolUtils.response(InterfaceResultEnum.GROUP_NUMBER_RAND_ERROR,version); }else { //注意:nodeId是12位数的,不够时,前面补0 String nodeId = ""; String zero = ""; if (macAddress.length() <= 12){ for (int i = 0; i < 12 - macAddress.length();i++){ zero += "0"; } nodeId = zero+macAddress; }else { //大于12位数了 return toolUtils.response(InterfaceResultEnum.FILL_LAMP_ADDRESS__ERROR,version); } qiObject.put("nodeId",nodeId); qiObject.put("nodeType",nodeType); qiObject.put("deviceId",sn); qiObject.put("groupNum",groupNumber); } } }else { //没有分组的 //注意:nodeId是12位数的,不够时,前面补0 String nodeId = ""; String zero = ""; if (macAddress.length() <= 12){ for (int i = 0; i < 12 - macAddress.length();i++){ zero += "0"; } nodeId = zero+macAddress; }else { //大于12位数了 return toolUtils.response(InterfaceResultEnum.FILL_LAMP_ADDRESS__ERROR,version); } qiObject.put("nodeId",nodeId); qiObject.put("nodeType",nodeType); qiObject.put("deviceId",sn); } String respone = this.quiHuiPlcDevice(url, qiObject, 4); if (respone == null || respone.length() == 0){ return toolUtils.response(InterfaceResultEnum.SEND_CMD_TIME_OUT,version); }else { JSONObject parseObject = JSON.parseObject(respone); Integer code = parseObject.getInteger("code"); if (code != 200){ String msg = parseObject.getString("msg"); BaseResult objectBaseResult = new BaseResult<>(code.toString(), msg, new Object()); return objectBaseResult; }else { lampInfo.setBindStatus(1); } } } lampInfo.setControlType(controlType); lampInfo.setRatedPower(power); lampInfo.setLongitude(Float.valueOf(longitude)); lampInfo.setLatitude(Float.valueOf(latitude)); lampInfo.setAreaId(areaId); lampInfo.setSectionId(sectionId); lampInfo.setAddress(sn); lampInfo.setNumber(number); lampInfo.setName(name); if (protocolType == 11 && controlType == 8 && header > 0){ //添加其中一个灯头 if (header == 1){//灯头1 //设置灯头2 lampInfo.setMode(1); }else {//灯头2 //设置灯头1 lampInfo.setMode(0); } lampService.addByDto(lampInfo); }else { lampService.addByDto(lampInfo); } //修改了 4G 双控 plc 双控 nb 双控 蓝牙双灯 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){ lampInfo.setMode(1); lampService.addByDto(lampInfo); } String lastSql = lastSqlInterceptor.sqlContent; //插入的sql语句 if (lampPoleId != null && lampPoleId.length() != 0){ toolUtils.setPoleType(Integer.parseInt(lampPoleId),0); } // 添加到分组 if (groupId != null && groupId.length() != 0){ String[] groupIdArr = groupId.split(","); List groupDTOList = groupService.getListByIds(groupIdArr); for (GroupDTO item:groupDTOList) { String[] lampArr = item.getLampId().split(","); //是否包含某个元素 boolean ifContain = Arrays.asList(lampArr).contains(lampInfo.getId()); if (ifContain == false){ //转换成list List list = new ArrayList<>(Arrays.asList(lampArr)); list.add(lampInfo.getId().toString()); //list数组按规定拼接成字符串 String newLampId= list.stream().collect(Collectors.joining(",")); //更新 item.setLampId(newLampId); groupService.updateGroupLampId(item); } } } networkData = networkService.getSimpleData(networkData); Integer lampCount = networkData.getLampCount(); if (controlType == 1 || controlType == 3 || controlType == 5 || controlType == 8 || controlType == 9 || controlType == 22){ //更新lampcount //如果两灯就是添加2个 if (lampCount == null || lampCount == 0){ networkData.setLampCount(2); }else { if (header > 0 && controlType == 8){ //只增加一个 lampCount = lampCount + 1; networkData.setLampCount(lampCount); }else { lampCount = lampCount + 2; networkData.setLampCount(lampCount); } } networkService.updateSimDate(networkData); }else { //单灯 //如果两灯就是添加1个 if (protocolType != 11 && protocolType != 5){ networkData.setLampCount(1); networkService.updateSimDate(networkData); }else if((protocolType == 11 || protocolType == 5) && controlType != 26 && controlType != 27) { //plc可以带很多灯 ,//zigbee也是带多个灯 if (lampCount == null || lampCount == 0){ networkData.setLampCount(1); }else { lampCount = lampCount + 1; networkData.setLampCount(lampCount); } networkService.updateSimDate(networkData); } } String cRemark = "添加路灯 区域:"+areaDTO.getChineseName()+"->路段:"+sectionDTO.getName()+"->路灯编号:"+number+" id:"+lampInfo.getId(); String eRemark = "Add lamp area:"+areaDTO.getEnglishName()+"->section:"+sectionDTO.getName()+"->number:"+number+" id:"+lampInfo.getId(); String rRemark = "Добавить зону светильников:"+areaDTO.getRuName()+"->участок дороги:"+sectionDTO.getName()+"->нумерация:"+number+" id:"+lampInfo.getId(); toolUtils.addOpertaionLog(request, "添加", cRemark, 0, 1, 1, number, areaDTO.getChineseName(), sectionDTO.getName(), sn, sectionId, sectionDTO.getId(), lampInfo.getId(), lastSql); toolUtils.addOpertaionLog(request, "Insert", eRemark, 1,1,1, number, areaDTO.getEnglishName(), sectionDTO.getName(), sn, sectionId, sectionDTO.getId(), lampInfo.getId(), lastSql); toolUtils.addOpertaionLog(request,"Подкючено",rRemark,2,1,1,number,areaDTO.getRuName(),sectionDTO.getName(),sn,sectionId,sectionDTO.getId(), lampInfo.getId(),lastSql); return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version); }else { // 编辑 // LampInfoDTO oldLamp = lampService.getDetailsById(lampId,version); // if (oldLamp.getProtocolType() != protocolType){ // NetworkDTO networkDTO = new NetworkDTO(); // networkDTO.setId(oldLamp.getNetworkId()); // networkDTO.setNetworkName(sn); // networkDTO.setDeviceSn(sn); // networkDTO.setAreaId(areaId); // networkDTO.setSectionId(sectionId); // if (protocolType == 10) networkDTO.setDeviceType(4); // networkDTO.setProtocolType(protocolType); // networkService.update(networkDTO); // } LampInfoDTO lampInfoDTO = new LampInfoDTO(); lampInfoDTO.setId(lampId); lampInfoDTO.setNumber(number); lampInfoDTO.setSectionId(sectionId); lampInfoDTO.setName(name); // lampInfoDTO.setNetworkId(oldLamp.getNetworkId()); lampInfoDTO.setLatitude(Float.valueOf(latitude)); lampInfoDTO.setLongitude(Float.valueOf(longitude)); lampInfoDTO.setNumber(number); lampInfoDTO.setSn(sn); lampInfoDTO.setAreaId(areaId); lampInfoDTO.setControlType(controlType); lampInfoDTO.setProtocolType(protocolType); lampInfoDTO.setInstallDate(installDate); lampInfoDTO.setExpirationDate(expirationDate); lampInfoDTO.setRatedPower(power); return lampService.update(lampInfoDTO); } } //微自然的plc private void savePlcAddress(String netAddress,String lampAddress){ PlcAddressDTO plcAddressDTO = new PlcAddressDTO(); plcAddressDTO.setLampAddress(lampAddress); plcAddressDTO.setNetAddress(netAddress); Integer total = plcAddressService.checkDataByVO(plcAddressDTO); if (total == 0){ PlcAddressDTO result = plcAddressService.getMaxPvid(plcAddressDTO); if (result == null){ plcAddressDTO.setPvid(1); }else { plcAddressDTO.setPvid(result.getPvid() + 1); } plcAddressService.insertDataByVO(plcAddressDTO); } } // 添加设备 protected String addDevice(String deviceId,String freqId){ Map maps = freqMapConfig.getMaps(); FreqConfig freqConfig = maps.get(freqId); String deviceProfileID = ""; String applicationID = ""; if (freqConfig != null){ deviceProfileID = freqConfig.getDeviceProfileID(); applicationID = freqConfig.getApplicationID(); } JSONObject device = new JSONObject(); device.put("applicationID",applicationID); device.put("description",deviceId); device.put("devEUI","00000000"+deviceId); device.put("deviceProfileID",deviceProfileID); device.put("name",deviceId); device.put("referenceAltitude",0); device.put("skipFCntCheck",true); device.put("tags",new Object()); device.put("variables",new Object()); JSONObject data = new JSONObject(); data.put("device",device); String token = jwtUtil.signatureToToken(); String url = "http://47.112.108.98:8090/api/devices"; String respone = null; try { respone = toolUtils.sendHttp("post", url, data.toString(), token, null, 5, null, ToolUtils.ContentTypeEnum.CONTENT_TYPE_JSON,null); System.out.println("=====dddd:"+respone); if (respone == null){ respone = jwtUtil.setActivate(deviceId); System.out.println("=====再次:"+respone); } } catch (IOException e) { throw new RuntimeException(e); } return null; } /** * 删除灯控 * @param request * @return */ @RequestMapping(value = "/del",method = RequestMethod.POST) public BaseResult del(HttpServletRequest request){ Integer version = request.getParameter("version") == null ? 0 : Integer.parseInt(request.getParameter("version")); String lampId = request.getParameter("lampId"); if (lampId == null || lampId.length() == 0) return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR,version); String[] split = lampId.split(","); for (String id :split) { int l = Integer.parseInt(id); lampService.deleteById(l); } return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version); } /** * 灯控调光 * @param request * @return */ @RequestMapping(value = "/dimming",method = RequestMethod.POST) public BaseResult dimming(HttpServletRequest request){ Integer version = request.getParameter("version") == null ? 0 : Integer.parseInt(request.getParameter("version")); Integer light = request.getParameter("light") == null ? 0 : Integer.parseInt(request.getParameter("light")); Integer isGroup = request.getParameter("isGroup") == null ? 0 : Integer.parseInt(request.getParameter("isGroup")); Integer id = request.getParameter("id") == null ? 0 : Integer.parseInt(request.getParameter("id")); LampInfoDTO lamp = lampService.getDetailsById(id, version); light = light > 100 ? 100 : light; Date day = new Date(); SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String updateTime = sdf.format(day); if (lamp.getProtocolType() == 10){ // 4G String sendTopic = "/Lamp/TransIn/"+lamp.getSn(); String backTopic = "/Lamp/TransOut/"+lamp.getSn(); if (isGroup == 1){ String cmd; if (lamp.getMode() == 0){ // B 路 cmd = "0110DF090102"; }else { // A 路 cmd = "0110DF0B0102"; } if (light == 0){ cmd += "5F"; }else { cmd += "A0"; } cmd += toolUtils.getCRC(cmd.getBytes()); String s = toolUtils.sendMqttCmd(sendTopic, "0232"+cmd, backTopic, 10); if (s == null || s.length() == 0){ return toolUtils.response(InterfaceResultEnum.SEND_CMD_TIME_OUT,version); }else { if (lamp.getMode() == 0){ // A 路 cmd = "0106DF0A"; }else { // B 路 cmd = "0106DF0C"; } String lightStr = "0000"+Integer.toHexString(light).toString(); lightStr = lightStr.substring(-4); cmd += lightStr; cmd += toolUtils.getCRC(cmd.getBytes()); s = toolUtils.sendMqttCmd(sendTopic, "0232"+cmd, backTopic, 10); if (s == null || s.length() == 0){ return toolUtils.response(InterfaceResultEnum.SEND_CMD_TIME_OUT,version); }else { LampInfoDTO lampInfoDTO = new LampInfoDTO(lamp.getId()); lampInfoDTO.setLighteness(light); lampInfoDTO.setPolicyId(0); lampInfoDTO.setPolicyType(0); lampService.updateLight(lampInfoDTO); return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version); } } }else { String cmd; if (lamp.getMode() == 0){ // A 路 cmd = "0106DF0A"; }else { // B 路 cmd = "0106DF0C"; } String lightStr = "0000"+Integer.toHexString(light).toString(); lightStr = lightStr.substring(-4); cmd += lightStr; cmd += toolUtils.getCRC(cmd.getBytes()); String s = toolUtils.sendMqttCmd(sendTopic, "0232"+cmd, backTopic, 10); if (s == null || s.length() == 0){ return toolUtils.response(InterfaceResultEnum.SEND_CMD_TIME_OUT,version); }else { LampInfoDTO lampInfoDTO = new LampInfoDTO(lamp.getId()); lampInfoDTO.setLighteness(light); lampService.updateLight(lampInfoDTO); return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version); } } } else if (lamp.getProtocolType() == 11) {//plc灯 if (lamp.getControlType() == 8 || lamp.getControlType() == 4){ //力合微 String rthirdId = "LME:"+ lamp.getSn().toLowerCase(); String thirdId = rthirdId + "-light:"+lamp.getDevAddr(); Integer lampNumber = lamp.getMode() + 1; //当前时间 String dataType = "adjustLightController"; //对象 JSONObject jsonObject = new JSONObject(); jsonObject.put("thirdId",thirdId); jsonObject.put("RthirdId",rthirdId); jsonObject.put("lampNumber",lampNumber); jsonObject.put("dateTime",updateTime); jsonObject.put("dataType",dataType); jsonObject.put("brightness",light); String objectString = jsonObject.toString(); //发送命令(获取数据) String sendTopic = "LME/streetLight/In/adjustLightController/"+rthirdId; String resTopic = "LME/streetLight/Out/lightStatus"; String s = toolUtils.plcSendMqttCmd(sendTopic, objectString, resTopic, 20); if (s == null || s.length() == 0){ return toolUtils.response(InterfaceResultEnum.SEND_CMD_TIME_OUT,version); } } else if (lamp.getControlType() == 11 || lamp.getControlType() == 12 || lamp.getControlType() == 14) { //广东启慧 String url = "concentrator/singleLightDimmer"; String macAddress = lamp.getMacAddress(); if (lamp.getMacAddress().length() < 12){ StringBuffer stringBuffer = new StringBuffer(); for (int i = 0; i < 12 - lamp.getMacAddress().length(); i++){ stringBuffer.append('0'); } String zero = stringBuffer.toString(); macAddress = zero+macAddress; } JSONObject jsonObject = new JSONObject(); jsonObject.put("deviceId",lamp.getSn()); jsonObject.put("nodeId",macAddress); jsonObject.put("ab",lamp.getMode()+1); jsonObject.put("luminance",light); //发送命令-调光 String result = this.quiHuiPlcDevice(url, jsonObject, 4); if (result == null || result.length() == 0){ return toolUtils.response(InterfaceResultEnum.SEND_CMD_TIME_OUT,version); }else { JSONObject parseObject = JSON.parseObject(result); Integer code = parseObject.getInteger("code"); if (code == 200){ LampInfoDTO lampInfoDTO = new LampInfoDTO(lamp.getId()); lampInfoDTO.setLighteness(light); lampInfoDTO.setUpdateTime(updateTime); lampService.updateLight(lampInfoDTO); return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version); } else { String msg = parseObject.getString("msg"); BaseResult objectBaseResult = new BaseResult<>(code.toString(), msg, new Object()); return objectBaseResult; } } } } else if (lamp.getProtocolType() == 5) { if (lamp.getControlType() == 13){ //中灯的plc,协议是zigbee Object zhogMsg = this.zhongDimming(lamp,light); if (zhogMsg == null){ return toolUtils.response(InterfaceResultEnum.LACK_UNKNOWN_ERROR,version); }else { Integer times = ((ZhongLightPlcVO) zhogMsg).getTimes(); Integer errorCode = ((ZhongLightPlcVO) zhogMsg).getErrorCode(); //错误码 Integer succCode = ((ZhongLightPlcVO) zhogMsg).getSuccCode(); //错误码 if (errorCode > 0){ //失败 if (times == 1){ //获取token返回的错误 if (errorCode == 1){ return toolUtils.response(InterfaceResultEnum.PLC_CALL_ERROR,version); }else if (errorCode == 2) { return toolUtils.response(InterfaceResultEnum.PLC_KEY_ERROR,version); }else { return toolUtils.response(InterfaceResultEnum.PLC_token_ERROR,version); } } else if (times == 2) { //login时返回的错误 if (errorCode == 1){ return toolUtils.response(InterfaceResultEnum.USER_EXISTS_ERROR,version); } else if (errorCode == 2) { return toolUtils.response(InterfaceResultEnum.USER_DISABLED_ERROR,version); }else { return toolUtils.response(InterfaceResultEnum.USER_LOGIN_ERROR,version); } }else { //第三次 if (errorCode == 780){ return toolUtils.response(InterfaceResultEnum.DEVICE_OFFLINE_ERROR,version); } else if (errorCode == 201) { return toolUtils.response(InterfaceResultEnum.DEVICE_TIMEOUT_ERROR,version); } else if (errorCode == 203) { return toolUtils.response(InterfaceResultEnum.DEVICE_CONNECTED_ERROR,version); }else { return toolUtils.response(InterfaceResultEnum.INVALID_TOKEN_ERROR,version); } } } if (succCode == 0 && times == 3 && errorCode == 0){ //调光成功 LampInfoDTO lampInfoDTO = new LampInfoDTO(lamp.getId()); lampInfoDTO.setLighteness(light); lampInfoDTO.setUpdateTime(updateTime); lampService.updateLight(lampInfoDTO); return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version); } } } } return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version); } private String selectNodeType(Integer power){ String nodeType = ""; switch (power){ case 30: nodeType = "01"; break; case 40: nodeType = "02"; break; case 50: nodeType = "50"; break; case 60: nodeType = "06"; break; case 75: nodeType = "0A"; break; case 80: nodeType = "12"; break; case 90: nodeType = "15"; break; case 100: nodeType = "19"; break; case 120: nodeType = "1D"; break; case 150: nodeType = "2C"; break; case 160: nodeType = "27"; break; case 180: nodeType = "36"; break; case 185: nodeType = "38"; break; case 200: nodeType = "40"; break; case 240: nodeType = "45"; break; case 260: nodeType = "48"; break; default: nodeType = ""; } return nodeType; } //中灯 - 调光 private Object getToken(){ String url = zhongLightPlc.getZhongUrl()+"query_token"; JSONObject jsonObject = new JSONObject(); jsonObject.put("OperatorID",zhongLightPlc.getOperatorID()); jsonObject.put("OperatorSecret",zhongLightPlc.getOperatorSecret()); String objectString = jsonObject.toString(); //aes128位,模式:cbc,填充模式: pkcs5padding,返回是base64 //hmac-md5加密32位后,小写要转换成大写 String bodyStr = this.encryptAndMd5(objectString); String result = null; try { result = toolUtils.sendHttp("post", url, bodyStr,3, ToolUtils.ContentTypeEnum.CONTENT_TYPE_JSON,null); } catch (IOException e) { throw new RuntimeException(e); } if (result == null || result.length() == 0){ return null; }else { //System.out.println("====result:"+result); JSONObject parseObject = JSON.parseObject(result); String data = parseObject.getString("Data"); Integer ret = parseObject.getInteger("Ret"); //{"Ret": 0, "Msg": "Successfully", "Data": "U/jy5Jq0OPFRB3xFNvLAUcEPg3eZjSSuG9KOKcCtu4/CqJgFI/sWTQyHrdiEcpC2sk0EofcZ3eurM4A7N0LFRbYRaiiiyK9I6vcWh8JyLLSIEUEsGSh66NjcxzdqrQX4LOYducgwxA+KZAh7d9iNIdeMhEpAIxJbM5PcTHwtcjOOygde0lLZdU3QDHvTltFmMh7HNvzd6/quXpYvfQoBMZpR9D81Ly7BaHljFqSzKBGaarW/Xbv6MnReqJo/IMla4l1nKjsjCiEHo2aAOGO0zLgRMzJ/t78tjAxf5V09Amb/M5K6/vw5AvMN/F/0e+fHzzfMEvlJ0RU/nqGpvjGrtFrgwioa6IjnZsB52yBWR2HNHENjDq1nUVs9AQ6hfyJb", "Sig": "7C4A204206F4F99DB8427C90F11A85B3"} String dataString = null; if (ret == 0){ //解密 try { //{"OperatorID": "MA5G0DCR3", "SuccStat": 0, "AccessToken": "eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiJNQTVHMERDUjMiLCJpYXQiOjE2OTY5MzQ1MzEsInN1YiI6InVHeGR0OE5QNURZWStxWUQiLCJleHAiOjE2OTY5NDE3MzJ9.KIgJtlInWxLAyz2WYerbia5LqBVabLh6xB2M3TvRXYU", "TokenAvailableTime": 7200, "FailReason": 0} dataString = aesUtils.decrypt(zhongLightPlc.getEncryptKey(),zhongLightPlc.getIv(),data); JSONObject dataObject = JSON.parseObject(dataString); Integer succStat = dataObject.getInteger("SuccStat"); Integer failReason = dataObject.getInteger("FailReason"); ZhongLightPlcVO zhongLightPlcVO = new ZhongLightPlcVO(); zhongLightPlcVO.setTimes(1); zhongLightPlcVO.setErrorCode(failReason); if (succStat == 0){ //成功 String accessToken = dataObject.getString("AccessToken"); System.out.println("===eee:"+accessToken); zhongLightPlcVO.setToken(accessToken); zhongLightPlcVO.setSuccCode(0); //return accessToken; //有效期是2个小时 }else { //失败 //zhongLightPlcVO.setErrorCode(failReason); // return failReason.toString(); // if (failReason == 1){ // toolUtils.response(InterfaceResultEnum.PLC_CALL_ERROR,0); // } else if (failReason == 2) { // toolUtils.response(InterfaceResultEnum.PLC_KEY_ERROR,0); // }else { // toolUtils.response(InterfaceResultEnum.PLC_token_ERROR,0); // } } return zhongLightPlcVO; } catch (Exception e) { throw new RuntimeException(e); } } } return null; } private Object zhongPlcLogin(ZhongLightPlcVO tokenObject){ String url = zhongLightPlc.getZhongUrl()+"user/v1_0/user_login"; JSONObject jsonObject = new JSONObject(); jsonObject.put("UserName",zhongLightPlc.getZhongUserName()); jsonObject.put("Password",zhongLightPlc.getZhongPassword()); String objectString = jsonObject.toString(); //aes128位,模式:cbc,填充模式: pkcs5padding //hmac-md5加密后,小写要转换成大写 String bodyJsonString = this.encryptAndMd5(objectString); String respone = null; try { respone = toolUtils.sendHttp("post",url,bodyJsonString,tokenObject.getToken(),null,4,"Bearer", ToolUtils.ContentTypeEnum.CONTENT_TYPE_JSON,null); JSONObject parseObject = JSON.parseObject(respone); System.out.println("======ddd:"+parseObject); Integer ret = parseObject.getInteger("Ret"); if (ret == 0){ //解密 String data = parseObject.getString("Data"); // {"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"}, // {"Title":"操作记录","Code":"9"}],"Code":"4"}],"ProjectId":"5ecd00d726b0673bf8d0f034","OrganizationId":"5ecd009826b0673bf8d0f032","SessionId":"27BA3664948557E419D6CFD260BD72B4","DivisionId":"5ecd006926b0673bf8d0f02c"} String decryptJson = aesUtils.decrypt(zhongLightPlc.getEncryptKey(), zhongLightPlc.getIv(), data); JSONObject resultObject = JSON.parseObject(decryptJson); //0:成功;1:用户名密码对应用户不存在;2:该用户已被禁用;3~99:自定义 Integer code = resultObject.getInteger("SuccStat"); ZhongLightPlcVO loginZhongVO = new ZhongLightPlcVO(); loginZhongVO.setSuccCode(code); loginZhongVO.setErrorCode(code); loginZhongVO.setTimes(2); if (code == 0){ //成功 String projectId = resultObject.getString("ProjectId"); String organizationId = resultObject.getString("OrganizationId"); String sessionId = resultObject.getString("SessionId"); String divisionId = resultObject.getString("DivisionId"); loginZhongVO.setProjectId(projectId); loginZhongVO.setOrganizationId(organizationId); loginZhongVO.setSessionId(sessionId); loginZhongVO.setDivisionId(divisionId); loginZhongVO.setToken(tokenObject.getToken()); } return loginZhongVO; } } catch (Exception e) { throw new RuntimeException(e); } return null; } private Object zhongDimming(LampInfoDTO lamp,Integer light){ //获取token Object tokenObject = this.getToken(); if (tokenObject == null ){ //失败 return null; }else { Integer errorCode = ((ZhongLightPlcVO) tokenObject).getErrorCode(); if (errorCode > 0) return tokenObject; //也是失败的 } //登录 Object loginObject = this.zhongPlcLogin((ZhongLightPlcVO) tokenObject); if (loginObject == null ){ //失败 return null; }else { Integer errorCode = ((ZhongLightPlcVO) loginObject).getErrorCode(); if (errorCode > 0) return loginObject; //也是失败的 } //开始调光 String url = zhongLightPlc.getZhongUrl() + "commons/v1_0/send"; List arrayList = new ArrayList(); JSONObject jsonObject = new JSONObject(); jsonObject.put("code",1); jsonObject.put("headSerial",1); jsonObject.put("ep",1); jsonObject.put("gatewayAddr","0x"+lamp.getSn().toLowerCase()); jsonObject.put("addr","0x"+lamp.getMacAddress()); jsonObject.put("uid",lamp.getLampCtrId()); JSONObject controlObject = new JSONObject(); controlObject.put("devtype",23); controlObject.put("bri",light); jsonObject.put("control",controlObject); arrayList.add(jsonObject); JSONObject dataObject = new JSONObject(); dataObject.put("platform",1); dataObject.put("cmds",arrayList); String dataObjectString = dataObject.toString(); //aes128位,模式:cbc,填充模式: pkcs5padding //hmac-md5加密后,小写要转换成大写 String bodyStr = this.encryptAndMd5(dataObjectString); String token = ((ZhongLightPlcVO) loginObject).getToken(); String sessionId = ((ZhongLightPlcVO) loginObject).getSessionId(); // String token = "eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiJNQTVHMERDUjMiLCJpYXQiOjE2OTcwMTkwMzQsInN1YiI6InVHeGR0OE5QNURZWStxWUQiLCJleHAiOjE2OTcwMjYyMzV9.AN-Af_x7qmxAEb736fo6bgrcgd02cjXZTB0QYa-oMOc"; // String sessionId = "25D085219FEBFD8D6587F0B984FF7F4E"; String respone = null; try { respone = toolUtils.sendHttp("post",url,bodyStr,token,sessionId,4,"Bearer", ToolUtils.ContentTypeEnum.CONTENT_TYPE_JSON,null); System.out.println("=====diming:"+respone); JSONObject parseObject = JSON.parseObject(respone); Integer ret = parseObject.getInteger("Ret"); //{"Ret": 0, "Msg": "Successfully", "Data": "/FZGtGawB4O9lTtef3Up4w8rUWVjXvpWXk7P36M792A=", "Sig": "57D14850E6FED20D242D0C958DAE8403"} ZhongLightPlcVO zhongLightPlcVO = new ZhongLightPlcVO(); zhongLightPlcVO.setTimes(3); if (ret == 0){ //成功 String data = parseObject.getString("Data"); //解密 String decryptJson = aesUtils.decrypt(zhongLightPlc.getEncryptKey(), zhongLightPlc.getIv(), data); //解释json数组 JSONArray objects = JSON.parseArray(decryptJson); JSONObject resultbject = (JSONObject)objects.get(0); Integer resultCode = resultbject.getInteger("result"); zhongLightPlcVO.setErrorCode(resultCode);//是否调光成功 zhongLightPlcVO.setSuccCode(0); System.out.println("===dd:"+zhongLightPlcVO); return zhongLightPlcVO; }else if (ret == 4002){ //Invalid token zhongLightPlcVO.setErrorCode(ret); zhongLightPlcVO.setSuccCode(ret); return zhongLightPlcVO; } } catch (Exception e) { throw new RuntimeException(e); } return null; } /* 0. 最先要有了网关 * 1. 先添加控制器 * 2. 再添加灯具 */ //添加设备 - 控制器 private Object createCtrollLight(String macAddress,String uId,Integer zibeeSectionId,String longitude, String latitude,String name){ Object tokenObject = this.getToken(); if (tokenObject == null ){ //失败 return null; }else { Integer errorCode = ((ZhongLightPlcVO) tokenObject).getErrorCode(); if (errorCode > 0) return tokenObject; //也是失败的 } //登录 Object loginObject = this.zhongPlcLogin((ZhongLightPlcVO) tokenObject); if (loginObject == null ){ //失败 return null; }else { Integer errorCode = ((ZhongLightPlcVO) loginObject).getErrorCode(); if (errorCode > 0) return loginObject; //也是失败的 } //创建控制器 String url = zhongLightPlc.getZhongUrl() + "commons/v1_0/create"; //type: 23(v3控制器) JSONObject jsonObject = new JSONObject(); jsonObject.put("type",23); jsonObject.put("gateway_id",uId); jsonObject.put("section_id",zibeeSectionId); jsonObject.put("division_id",((ZhongLightPlcVO) loginObject).getDivisionId()); jsonObject.put("organization_id",((ZhongLightPlcVO) loginObject).getOrganizationId()); jsonObject.put("project_id",((ZhongLightPlcVO) loginObject).getProjectId()); jsonObject.put("lamp_post_type",20); jsonObject.put("lamp_post_number",macAddress); JSONObject controlObject = new JSONObject(); controlObject.put("platform",1); controlObject.put("type",3); controlObject.put("addr","0x"+macAddress); controlObject.put("property",jsonObject); String dataObjectString = controlObject.toString(); //aes128位,模式:cbc,填充模式: pkcs5padding //hmac-md5加密后,小写要转换成大写 String bodyStr = this.encryptAndMd5(dataObjectString); //发送请求 String token = ((ZhongLightPlcVO) loginObject).getToken(); String sessionId = ((ZhongLightPlcVO) loginObject).getSessionId(); String respone = null; try { respone = toolUtils.sendHttp("post", url, bodyStr, token, sessionId, 5,"Bearer", ToolUtils.ContentTypeEnum.CONTENT_TYPE_JSON,null); System.out.println("===dd:"+respone); JSONObject parseObject = JSON.parseObject(respone); Integer ret = parseObject.getInteger("Ret"); //{"Ret": 0, "Msg": "Successfully", "Data": "/FZGtGawB4O9lTtef3Up4w8rUWVjXvpWXk7P36M792A=", "Sig": "57D14850E6FED20D242D0C958DAE8403"} ZhongLightPlcVO zhongLightPlcVO = new ZhongLightPlcVO(); zhongLightPlcVO.setTimes(3); if (ret == 0){ //成功 String data = parseObject.getString("Data"); //解密 String decryptJson = aesUtils.decrypt(zhongLightPlc.getEncryptKey(), zhongLightPlc.getIv(), data); //解释json JSONObject resultbject = JSON.parseObject(decryptJson); Integer resultCode = resultbject.getInteger("result"); zhongLightPlcVO.setErrorCode(resultCode);//是否调光成功 if (resultCode == 0){ //成功 zhongLightPlcVO.setSuccCode(0); String lampCtrId = resultbject.getString("uid"); //zhongLightPlcVO.setLampCtrlId(lampCtrId); ((ZhongLightPlcVO) loginObject).setLampCtrlId(lampCtrId); //创建灯具 Object lightObject = this.createLight(macAddress, lampCtrId, loginObject, longitude, latitude, name); if (lightObject != null){ ((ZhongLightPlcVO)lightObject).setLampCtrlId(lampCtrId); return lightObject; } }else { //创建失败 return zhongLightPlcVO; } } } catch (Exception e) { throw new RuntimeException(e); } return null; } private Object createLight(String macAddress,String lampCtrId,Object loginObject, String longitude,String latitude,String name){ String url = zhongLightPlc.getZhongUrl() + "commons/v1_0/create"; //zigbee设备网关会设置变比和轮询时间,所以与网关设置一样就可以了,poll_interval与formula //port_id:是针对双灯控制器的 //type: 5是zigbee的控制器 JSONObject jsonObject = new JSONObject(); jsonObject.put("type",5); jsonObject.put("encryption",1); jsonObject.put("poll_interval",15); jsonObject.put("formula",1); jsonObject.put("division_id",((ZhongLightPlcVO) loginObject).getDivisionId()); jsonObject.put("organization_id",((ZhongLightPlcVO) loginObject).getOrganizationId()); jsonObject.put("project_id",((ZhongLightPlcVO) loginObject).getProjectId()); jsonObject.put("longitude",longitude); jsonObject.put("latitude",latitude); jsonObject.put("port_id",1); jsonObject.put("lamp_ctrl_id",((ZhongLightPlcVO) loginObject).getLampCtrlId()); jsonObject.put("name",name); JSONObject dataObject = new JSONObject(); dataObject.put("platform",1); dataObject.put("type",4); dataObject.put("addr","0x"+macAddress); dataObject.put("property",jsonObject); String dataObjectString = dataObject.toString(); String bodyStr = this.encryptAndMd5(dataObjectString); //发送请求 String token = ((ZhongLightPlcVO) loginObject).getToken(); String sessionId = ((ZhongLightPlcVO) loginObject).getSessionId(); String respone = null; try { respone = toolUtils.sendHttp("post", url, bodyStr, token, sessionId, 5,"Bearer", ToolUtils.ContentTypeEnum.CONTENT_TYPE_JSON,null); System.out.println("===light:"+respone); JSONObject parseObject = JSON.parseObject(respone); Integer ret = parseObject.getInteger("Ret"); //{"Ret": 0, "Msg": "Successfully", "Data": "/FZGtGawB4O9lTtef3Up4w8rUWVjXvpWXk7P36M792A=", "Sig": "57D14850E6FED20D242D0C958DAE8403"} ZhongLightPlcVO zhongLightPlcVO = new ZhongLightPlcVO(); zhongLightPlcVO.setTimes(4); if (ret == 0){ //成功 String data = parseObject.getString("Data"); //解密 String decryptJson = aesUtils.decrypt(zhongLightPlc.getEncryptKey(), zhongLightPlc.getIv(), data); //解释json JSONObject resultbject = JSON.parseObject(decryptJson); Integer resultCode = resultbject.getInteger("result"); zhongLightPlcVO.setErrorCode(resultCode);//是否调光成功 if (resultCode == 0){ //成功 zhongLightPlcVO.setSuccCode(0); String uid = resultbject.getString("uid"); zhongLightPlcVO.setUid(uid); } return zhongLightPlcVO; } } catch (Exception e) { throw new RuntimeException(e); } return null; } // private String encryptAndMd5(String data){ String key = zhongLightPlc.getEncryptKey(); String iv = zhongLightPlc.getIv(); String encryptStr = null; //测试 //String objectString = "{\"OperatorID\":\"MA5G0DCR3\",\"OperatorSecret\":\"uGxdt8NP5DYY+qYD\"}"; try { //aes128位,模式:cbc,填充模式: pkcs5padding,返回是base64 encryptStr = aesUtils.encrypt(key,iv,data); } catch (Exception e) { throw new RuntimeException(e); } String seq = "001"; Date date = new Date(); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); String day = dateFormat.format(date); String sig = zhongLightPlc.getOperatorID()+encryptStr+day+seq; //hmac-md5加密32位后,小写要转换成大写 0B692762DA3A4BE698E859FA8B7F1DF3 String hamc = null; byte[] bytes = zhongLightPlc.getSigSecret().getBytes(StandardCharsets.UTF_8); try { hamc = aesUtils.encodeHmacMD5(sig.getBytes(), bytes); } catch (Exception e) { throw new RuntimeException(e); } //转换成大写 String upperHamc = hamc.toUpperCase(); JSONObject bodyJson = new JSONObject(); bodyJson.put("OperatorID",zhongLightPlc.getOperatorID()); bodyJson.put("Data",encryptStr); bodyJson.put("TimeStamp",day); bodyJson.put("Seq",seq); bodyJson.put("Sig",upperHamc); String bodyJsonString = bodyJson.toString(); return bodyJsonString; } //广东启慧-调光/集中器设备注册(网关)/控制器 private String quiHuiPlcDevice(String url,JSONObject params,Integer timeOut) { String plcUrl = quHuiPlc.getUrl()+url; Random random = new Random(); int min = 10000; int max = 99999999; String id = "wecloud_"+(random.nextInt(max-min) + min); long timestamp = System.currentTimeMillis() / 1000;//单位是秒 String sign = quHuiPlc.getClientId()+timestamp+id+quHuiPlc.getClientSecret(); String md5Sign = DigestUtils.md5DigestAsHex(sign.getBytes()); //md5加密 HashMap map = new HashMap<>(); map.put("ver","1.0"); map.put("client_id",quHuiPlc.getClientId()); map.put("timestamp",timestamp); map.put("id",id); map.put("sign",md5Sign); map.put("params",params); ObjectMapper mapper = new ObjectMapper(); String json = null; try { json = mapper.writeValueAsString(map).toString(); } catch (JsonProcessingException e) { throw new RuntimeException(e); } //发送post请求 String result = null; try { result = toolUtils.sendHttp("post",plcUrl, json, timeOut, ToolUtils.ContentTypeEnum.CONTENT_TYPE_JSON,null); } catch (IOException e) { throw new RuntimeException(e); } return result; } //广东启慧-集中器设备注册(网关) // private String plcDevice(String url,String params,Integer timeOut){ // String plcUrl = quHuiPlc.getUrl()+url; // Random random = new Random(); // int min = 10000; // int max = 99999999; // String id = "wecloud_"+(random.nextInt(max-min) + min); // long timestamp = System.currentTimeMillis() / 1000;//单位是秒 // String sign = quHuiPlc.getClientId()+timestamp+id+quHuiPlc.getClientSecret(); // String md5Sign = DigestUtils.md5DigestAsHex(sign.getBytes()); //md5加密 // // HashMap map = new HashMap<>(); // map.put("ver","1.0"); // map.put("client_id",quHuiPlc.getClientId()); // map.put("timestamp",timestamp); //用map,timestamp不会打包成字符串,jsonObject会打包成字符串的 // map.put("id",id); // map.put("sign",md5Sign); // map.put("params",params); // ObjectMapper mapper = new ObjectMapper(); // String json = null; // try { // json = mapper.writeValueAsString(map).toString(); // } catch (JsonProcessingException e) { // throw new RuntimeException(e); // } // //发送post请求 // String result = null; // try { // result = toolUtils.sendHttp("post",plcUrl, json, timeOut, ToolUtils.ContentTypeEnum.CONTENT_TYPE_JSON); // } catch (IOException e) { // throw new RuntimeException(e); // } // return result; // } /** * 新建分组选择灯控 * @param request * @return */ @RequestMapping(value = "/selectLamp",method = RequestMethod.POST) public BaseResult selectLamp(HttpServletRequest request){ String version = request.getParameter("version") == null ? "0" : request.getParameter("version"); String type = request.getParameter("type") == null ? "0" : request.getParameter("type"); String groupid = request.getParameter("groupid") == null || request.getParameter("groupid").length() == 0? "0" : request.getParameter("groupid"); System.out.println(toolUtils); List sectionList = toolUtils.getSectionList(request); GroupVO groupVO = new GroupVO(); groupVO.setVersion(Integer.valueOf(version)); groupVO.setId(Integer.valueOf(groupid)); groupVO.setSectionList(sectionList); GroupDTO group = groupService.getDetailByVO(groupVO); String[] lampArr = null; if (group != null && group.getLampId() != null){ lampArr = group.getLampId().split(","); } LampListResponseVO lampListResponseVO = new LampListResponseVO(); lampListResponseVO.setVersion(Integer.valueOf(version)); lampListResponseVO.setSectionList(sectionList); List lampList = lampService.groupSelectLamp(lampListResponseVO); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); List list = new ArrayList<>(); for (LampInfoDTO lamp :lampList) { if (lampArr != null && ArrayUtils.contains(lampArr,lamp.getId().toString())){ lamp.setSelect(1); }else { if (type.equals("1")) continue; lamp.setSelect(0); } if (lamp.getLighteness() == 0){ lamp.setLampStatusStr("关"); }else { lamp.setLampStatusStr("开"); } list.add(lamp); } LampListResponseVO lampListResponseVO1 = new LampListResponseVO(); lampListResponseVO1.setList(list); return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,Integer.parseInt(version),lampListResponseVO1); } /** * 灯控下拉 * @param request * @return */ @RequestMapping(value = "/nav",method = RequestMethod.POST) public BaseResult nav(HttpServletRequest request) { List sectionList = toolUtils.getSectionList(request); Integer version = (Integer) toolUtils.getRequestContent(request,"version",1); Integer lampType = (Integer) toolUtils.getRequestContent(request,"lampType",1); LampListResponseVO lampListResponseVO = new LampListResponseVO(); lampListResponseVO.setSectionList(sectionList); if (lampType == 1){ lampListResponseVO.setLampType(lampType); } List navByVO = lampService.getNavByVO(lampListResponseVO); ListResponseVO listResponseVO = new ListResponseVO(); listResponseVO.setList(navByVO); return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,listResponseVO); } /** * 频段信息列表 * @param request * @return */ @RequestMapping(value = "/freqList",method = RequestMethod.POST) public BaseResult freqList(HttpServletRequest request) { Integer version = (Integer) toolUtils.getRequestContent(request,"version",1); ArrayList freqDTOS = new ArrayList<>(); FreqDTO freqDTO = new FreqDTO(); freqDTO.setId(1); freqDTO.setName("US915"); freqDTOS.add(freqDTO); freqDTO = new FreqDTO(); freqDTO.setId(2); freqDTO.setName("EU868"); freqDTOS.add(freqDTO); freqDTO = new FreqDTO(); freqDTO.setId(3); freqDTO.setName("AS923"); freqDTOS.add(freqDTO); ListResponseVO listResponseVO = new ListResponseVO(); listResponseVO.setList(freqDTOS); return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,listResponseVO); } /** * 获取经纬度 * @param request * @return */ @RequestMapping(value = "/sectionData",method = RequestMethod.POST) public BaseResult sectionData(HttpServletRequest request) { Integer version = (Integer) toolUtils.getRequestContent(request,"version",1); Integer sectionId = (Integer) toolUtils.getRequestContent(request,"sectionId",1); Integer areaId = (Integer) toolUtils.getRequestContent(request,"areaId",1); LampInfoDTO lampInfoDTO = new LampInfoDTO(); if ((sectionId == null || sectionId.intValue() == 0) && (areaId == null || areaId.intValue() == 0)) { lampInfoDTO.setLongitude(114.06807299140166f); lampInfoDTO.setLatitude(22.5324106360218f); return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,lampInfoDTO); } if (areaId == null || areaId.intValue() == 0){ SectionDTO oneById = sectionService.getOneById(sectionId); GlobalLocationDTO oneById2 = globalLocationService.getOneById(oneById.getPid()); lampInfoDTO.setLongitude(oneById2.getLongitude()); lampInfoDTO.setLatitude(oneById2.getLatitude()); }else { GlobalLocationDTO oneById = globalLocationService.getOneById(areaId); lampInfoDTO.setLongitude(oneById.getLongitude()); lampInfoDTO.setLatitude(oneById.getLatitude()); } return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,lampInfoDTO); } /** * 获取太阳能控制器设备列表 * @param request 根据sectionId进行筛选 * @return 返回设备列表 */ @RequestMapping(value = "/getSolarList", method = RequestMethod.POST) public BaseResult getSolarList(HttpServletRequest request) { int version = (int) toolUtils.getRequestContent(request,"version",1); int online = (int) toolUtils.getRequestContent(request,"online",1); int page = request.getParameter("page") == null ? 1 : Integer.parseInt(request.getParameter("page")); int count = request.getParameter("count") == null ? 16 : Integer.parseInt(request.getParameter("count")); String keyword = (String) toolUtils.getRequestContent(request,"online",2); SolarDevDTO dto = new SolarDevDTO(); dto.setPage(count * (page - 1)); dto.setCount(count); dto.setVersion(version); dto.setOnline(online); dto.setKeyword(keyword); dto.setSectionList(toolUtils.getSectionList(request)); SolarDevVO solarDevVO = solarDevService.getSolarListByDTO(dto); return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,solarDevVO); } /** * 获取太阳能统计数据 * @param request 设备id * @return 返回太阳能统计数据 */ @RequestMapping(value = "/solarStatistics", method = RequestMethod.POST) public BaseResult solarStatistics(HttpServletRequest request) throws ParseException { int version = (int) toolUtils.getRequestContent(request,"version",1); int id = (int) toolUtils.getRequestContent(request,"id",1); if (id == 0) return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR,version); Integer timezone = solarInfoLogService.getTimezoneBySolarId(id); if (timezone == null) return toolUtils.response(InterfaceResultEnum.PARAM_FAIL,version); long l = System.currentTimeMillis() - timezone * 3600 * 1000; long startTime; long endTime; startTime = l - 24L * 3600 * 1000 * 29; endTime = l; HashMap objectObjectHashMap = new HashMap<>(); long timeT = startTime; int i = 0; List dateList = new ArrayList<>(); List lightTimeList = new ArrayList<>(); List comList = new ArrayList<>(); List eleList = new ArrayList<>(); List totalLightTime = new ArrayList<>(); List totalCom = new ArrayList<>(); List totalEle = new ArrayList<>(); List list = new ArrayList<>(); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); while (timeT <= endTime) { objectObjectHashMap.put(simpleDateFormat.format(new Date(timeT)),i); dateList.add(simpleDateFormat.format(new Date(timeT + timezone * 3600 * 1000))); lightTimeList.add(0); eleList.add(0); comList.add(0); totalLightTime.add(0); totalCom.add(0); totalEle.add(0); list.add(null); timeT += 3600 * 1000 * 24; i++; } List solarInfoLogList = solarInfoLogService.getSolarInfoLogByDTO(id); for (SolarInfoLogDTO solarInfoLogDTO : solarInfoLogList) { Date date = new Date(simpleDateFormat.parse(solarInfoLogDTO.getMaxTime()).getTime()); String s = simpleDateFormat.format(date); if (objectObjectHashMap.containsKey(s)){ Integer integer = objectObjectHashMap.get(s); list.set(integer,solarInfoLogDTO); } } DecimalFormat decimalFormat = new DecimalFormat("0.000"); for (SolarInfoLogDTO solarInfoLogDTO : list) { if (solarInfoLogDTO != null) { Date date = new Date(simpleDateFormat.parse(solarInfoLogDTO.getMaxTime()).getTime()); String s = simpleDateFormat.format(date); Integer integer = null; if (objectObjectHashMap.containsKey(s)){ integer = objectObjectHashMap.get(s); list.set(integer,solarInfoLogDTO); } if (solarInfoLogDTO.getMaxTotalLightTime() != null && solarInfoLogDTO.getMinTotalLightTime() != null && integer != null) { totalLightTime.set(integer,Integer.parseInt(solarInfoLogDTO.getMaxTotalLightTime())); Integer dayLightTime = Integer.parseInt(solarInfoLogDTO.getMaxTotalLightTime()) - Integer.parseInt(solarInfoLogDTO.getMinTotalLightTime()); lightTimeList.set(integer,dayLightTime); } if (solarInfoLogDTO.getMaxTotalConsumption() != null && solarInfoLogDTO.getMinTotalConsumption() != null && integer != null) { totalCom.set(integer,Float.parseFloat(solarInfoLogDTO.getMaxTotalConsumption())); Float dayCom = Float.parseFloat(solarInfoLogDTO.getMaxTotalConsumption()) - Float.parseFloat(solarInfoLogDTO.getMinTotalConsumption()); comList.set(integer,Float.parseFloat(decimalFormat.format(dayCom))); } if (solarInfoLogDTO.getMaxTotalEleSave() != null && solarInfoLogDTO.getMinTotalEleSave() != null && integer != null) { totalEle.set(integer,Float.parseFloat(solarInfoLogDTO.getMaxTotalEleSave())); Float daySave = Float.parseFloat(solarInfoLogDTO.getMaxTotalEleSave()) - Float.parseFloat(solarInfoLogDTO.getMinTotalEleSave()); eleList.set(integer,Float.parseFloat(decimalFormat.format(daySave))); } } } SolarInfoLogVO solarInfoLogVO = new SolarInfoLogVO(); solarInfoLogVO.setDateList(dateList); solarInfoLogVO.setLightTimeList(lightTimeList); solarInfoLogVO.setComList(comList); solarInfoLogVO.setEleList(eleList); solarInfoLogVO.setTotalLightTime(totalLightTime); solarInfoLogVO.setTotalCom(totalCom); solarInfoLogVO.setTotalEle(totalEle); return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,solarInfoLogVO); } /** * 新建分组下选择灯杆 * @param request sectionList,groupId,sectionId,type * @return 新建分组下选择灯杆 */ @RequestMapping(value = "/selectLampPole", method = RequestMethod.POST) public BaseResult lampPoleData(HttpServletRequest request) { Integer version = (Integer) toolUtils.getRequestContent(request,"version",1); Integer type = (Integer) toolUtils.getRequestContent(request,"type",1); Integer groupId = (Integer) toolUtils.getRequestContent(request,"groupId",1); List lampPoleList; if (type == 1) { // 查询分组下的灯杆 if (groupId == 0) return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR,version); GroupDTO groupDTO = groupService.getGroupDTOById(groupId); if (groupDTO == null) return toolUtils.response(InterfaceResultEnum.PARAM_FAIL,version); if (groupDTO.getDevType() == 0) return toolUtils.response(InterfaceResultEnum.PARAM_FAIL,version); String lampId = groupDTO.getLampId(); List lampIds = Arrays.asList(lampId.split(",")); lampPoleList = lampPoleService.getLampPoleByLampIds(lampIds); lampPoleList.forEach(dto -> dto.setSelect(1)); } else { //根据路段查询灯杆,分组可选 Integer sectionId = (Integer) toolUtils.getRequestContent(request,"sectionId",1); LampPoleVO lampPoleVO = new LampPoleVO(); lampPoleVO.setVersion(version); lampPoleVO.setSectionList(toolUtils.getSectionList(request)); lampPoleVO.setSectionId(sectionId); if (groupId == 0) { lampPoleList = lampPoleService.getSectionLampPoleList(lampPoleVO); lampPoleList.forEach(dto -> dto.setSelect(0)); } else { GroupDTO groupDTO = groupService.getGroupDTOById(groupId); if (groupDTO == null) return toolUtils.response(InterfaceResultEnum.PARAM_FAIL,version); if (groupDTO.getDevType() == 0) return toolUtils.response(InterfaceResultEnum.PARAM_FAIL,version); lampPoleList = lampPoleService.getSectionLampPoleList(lampPoleVO); String lampId = groupDTO.getLampId(); String[] lampIds = lampId.split(","); for (LampPoleDTO l : lampPoleList) { boolean isFlag = false; for (String s : lampIds) { if (l.getId().equals(Integer.valueOf(s))) { l.setSelect(1); isFlag = true; break; } } if (!isFlag) { l.setSelect(0); } } } } LampPoleVO lampPoleVO = new LampPoleVO(); lampPoleVO.setList(lampPoleList); return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,lampPoleVO); } }