Parcourir la source

jwt签名的设备添加

weclouds il y a 2 ans
Parent
commit
5772bab59b

+ 7 - 0
pom.xml

@@ -176,6 +176,13 @@
             <version>4.5.13</version>
         </dependency>
 
+<!--        通过JWT(JSON Web Token)进行数字签名-->
+        <dependency>
+            <groupId>io.jsonwebtoken</groupId>
+            <artifactId>jjwt</artifactId>
+            <version>0.9.1</version>
+        </dependency>
+
     </dependencies>
 
     <repositories>  <!-- 配置阿里云镜像仓库 -->

+ 1 - 0
src/main/java/com/welampiot/common/InterfaceResultEnum.java

@@ -225,6 +225,7 @@ public enum InterfaceResultEnum {
     PLC_SERIAL_NUMBER_EXIST_ERROR("0500","灯的序号重复","The serial number of the lamp is repeated","серийный номер лампы"),
     PLC_ADDRESS_EXIST_ERROR("0501","灯的地址重复","The address of the lamp is repeated","повторение адреса лампы"),
     LACK_PLC_ADDRESS__ERROR("0501","请先添加网关","Please add gateway first","Сначала добавьте шлюз"),
+    LACK_PLC_MACADDRESS__ERROR("0502","请添加灯地址","Please add a light address","Пожалуйста, добавьте адрес лампы."),
 
     ;
     private String code;

+ 17 - 0
src/main/java/com/welampiot/configuration/FreqConfig.java

@@ -0,0 +1,17 @@
+package com.welampiot.configuration;
+
+import lombok.Data;
+import org.springframework.stereotype.Component;
+
+@Component
+@Data
+public class FreqConfig {
+    public String name;
+    private Integer id;
+    private String applicationID;
+    private String deviceProfileID;
+    private String networkServerID;
+    private String serviceProfileID;
+    private Integer dr;
+    private Long frequency;
+}

+ 15 - 0
src/main/java/com/welampiot/configuration/FreqMapConfig.java

@@ -0,0 +1,15 @@
+package com.welampiot.configuration;
+
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+import java.util.Map;
+
+@Component
+@ConfigurationProperties(prefix = "freqlist")
+@Data
+public class FreqMapConfig {
+    private Map<String , FreqConfig> maps;
+}

+ 289 - 75
src/main/java/com/welampiot/controller/LampController.java

@@ -7,11 +7,14 @@ 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.FreqConfig;
+import com.welampiot.configuration.FreqMapConfig;
 import com.welampiot.configuration.QuHuiPlc;
 import com.welampiot.configuration.ZhongLightPlc;
 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.codec.DecoderException;
@@ -77,7 +80,10 @@ public class LampController {
     private AESUtils aesUtils;
     @Autowired
     private PlcAddressService plcAddressService;
-
+    @Autowired
+    private FreqMapConfig freqMapConfig;
+    @Autowired
+    private JwtUtil jwtUtil;
     /**
      * 灯控列表
      * @param request
@@ -145,7 +151,12 @@ public class LampController {
         LampInfoDTO detailsById = lampService.getDetailsById(lampId,version);
         return BaseResult.success(detailsById);
     }
-
+//    @RequestMapping(value = "/getkk",method = RequestMethod.POST)
+//public Integer kk(HttpServletRequest request){
+//        UserDTO user = toolUtils.getUser(request);
+//        System.out.println("===dd===:"+user);
+//        return user.getId();
+//}
     /**
      * 添加编辑灯控
      * @param request
@@ -211,7 +222,10 @@ public class LampController {
         }
 
         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;
@@ -219,6 +233,11 @@ public class LampController {
                 this.savePlcAddress(macAddress,sn);
             }
         }
+        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){  // 添加
             //同一个路段下不能有相同的编号
@@ -231,19 +250,39 @@ public class LampController {
             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){
                 lampInfo.setMacAddress(macAddress);
-                //灯地址
-                Integer macAddressTotal = lampService.checkData(lampInfo);
-                if (macAddressTotal > 0) return toolUtils.response(InterfaceResultEnum.PLC_ADDRESS_EXIST_ERROR,version);
-               //灯序号
+                if (controlType == 4 || controlType == 11 || controlType == 12 || controlType == 14 ){
+                    //单灯的情况下是不允许有重复地址的
+                    //灯地址
+                    Integer macAddressTotal = lampService.checkData(lampInfo);
+                    if (macAddressTotal > 0) return toolUtils.response(InterfaceResultEnum.PLC_ADDRESS_EXIST_ERROR,version);
+                } else if (controlType == 8) {
+                    //双灯的情况,检查是否有两个了,若有则不能重复,若没有,则要知道有了哪个灯头
+                    List<LampInfoDTO> dtoList = lampService.getListByDto(lampInfo);
+                    if (dtoList != null  && dtoList.size() == 2){
+                        //已经存在
+                        return toolUtils.response(InterfaceResultEnum.PLC_ADDRESS_EXIST_ERROR,version);
+                    }else {
+                        //不存在或只存在一个灯头
+                        if (dtoList != null){
+                            //存在一个灯头
+                            header = dtoList.get(0).getMode() + 1;
+                        }
+                    }
+                }
+                //灯序号
                 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);
             }
-            if (protocolType == 13 || controlType == 26 || controlType ==27){
+            if (protocolType == 13 || controlType == 26 || controlType == 27){
                 lampInfo.setMacAddress(macAddress);
                 //lampInfo.setAddress(sn);
                 Integer devAddrTotal = lampService.checkData(lampInfo);
@@ -251,10 +290,14 @@ public class LampController {
             }
             if (protocolType == 5){
                 //zigbee设备先判断有没有添加网关
-                NetworkDTO networkData = new NetworkDTO();
+                //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){
@@ -297,10 +340,10 @@ public class LampController {
                 }else {
                     netAddress = sn.length() == 13 ? String.valueOf(Integer.parseInt(sn,10)) : sn;
                 }
-                NetworkDTO networkData = new NetworkDTO();
-                networkData.setDeviceSn(sn);
+                //networkData = new NetworkDTO();
+                networkData.setDeviceSn(netAddress);
                 NetworkDTO simpleData = networkService.getSimpleData(networkData);
-                //zigbee设备
+                //zigbee设备 plc
                 if (protocolType == 5 && controlType == 13){
                     //先添加控制器,再添加灯具
                     lampInfo.setMacAddress(macAddress);
@@ -333,68 +376,165 @@ public class LampController {
                     }
                     lampInfo.setAddress(sn);
                 }
-                if (protocolType != 11 && simpleData != null){
-                   return toolUtils.response(InterfaceResultEnum.DEVICE_ADDRESS_EXITS_ERROR,version);
+                // plc只创建一个网络就可以了
+                if (simpleData != null){
+                   if (protocolType == 11 && (controlType != 26 && controlType != 27)){
+                       plcNetCount = 1;
+                   }
                 }
-            }
 
-//            if ($protocoltype == 0 || $protocoltype == 3 || $protocoltype == 4 || $protocoltype == 5 || $protocoltype == 6
-//                    || $protocoltype == 7 || $protocoltype == 8 || $protocoltype == 9 || $protocoltype == 10 || $protocoltype == 11 || $protocoltype == 13) {
-//                $data['net_type'] = 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(netAddress);
+                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){
+                                Integer networkId = networkService.add(networkData);
+                                lampInfo.setNetworkId(networkId);
+                            } else  {
+                                String msg = parseObject.getString("msg");
+                                BaseResult<Object> objectBaseResult = new BaseResult<>(code.toString(), msg, new Object());
+                                return objectBaseResult;
+                            }
+                        }
+                    }else {
+                        //力合微 plc
+                        Integer networkId = networkService.add(networkData);
+                        lampInfo.setNetworkId(networkId);
+                    }
+                }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(netAddress);
+                    networkData.setNetworkName(netAddress);
+                    networkData.setNetType(1);
+                    networkData.setCreateTime(updateTime);
+                }
+                Integer networkId =  networkService.add(networkData);
+                lampInfo.setNetworkId(networkId);
+            }
+            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";
+//                $nodeType = $this->selectNodeType($data['ratedpower']);
+            }
+//            if (($protocoltype == 11 && $data['control_type'] == 11) || ($protocoltype == 11 &&  $data['control_type'] == 12) || ($protocoltype == 11 &&  $data['control_type'] == 14)){
 //
-//                if ( $protocoltype != 11 && $protocoltype != 13 && $protocoltype != 5 && !empty($net_info)) {
-//                    $lamp_info = $this->Lampinfo_model->get_one(array('networkid'=>$net_info['id']),'id');
-//                    if (!empty($lamp_info)) {
-//                        $this->Network_model->delete(array('id'=>$net_info['id']));
-//                    }
-//                }
+//                $url = 'childnode/deviceRegister';
+//                $nodeType = $this->selectNodeType($data['ratedpower']);
 //
-//                // if ( $protocoltype != 11 && $this->Network_model->getDataCount(array('devicesn'=>$number))) {
-//                //     exit(json_result('0309',$this->response['0309'],array()));
-//                // }
-//                // plc只创建一个网络就可以了
-//                $plcNetCount = 0; //0:没有创建 ,1: 创建过了
-//                if ($this->Network_model->getDataCount(array('devicesn'=>$number))) {
-//                    if ($protocoltype == 11 && ($data['control_type'] != 26 && $data['control_type'] != 27)){
-//                        $plcNetCount = 1;
+//                if (empty($nodeType))  exit(json_result('0323',$this->response['0323']));
+//                $params = '';
+//                if (!empty($groupid)){
+//                    //有分组 (只有: 1- 255)
+//                    $groupid = implode(',', explode(',', $groupid));
+//                    $groupList = $this->db->query('select id,`name` from `group` where id in ('.$groupid.')')->result_array();
+//                    foreach ($groupList as $key=>$item){
+//                        if (is_numeric($item)){
+//                            if (intval($item) > 225 || intval($item) < 1){
+//                                //分组没有在规定的范围内
+//                                exit(json_result('0420',$this->response['0420']));
+//                            }else{
+//                                //注意:nodeId是12位数的,不够时,前面补0
+//                                $nodeId = '';
+//                                $zero = '';
+//                                if (mb_strlen($data['macAddress']) <= 12){
+//                                    for ($i = 0; $i < 12-(mb_strlen($data['macAddress'])); $i ++){
+//                                        $zero .= '0';
+//                                    }
+//                                    $nodeId = $zero.$data['macAddress'];
+//                                }else{
+//                                    //大于12位数了
+//                                    exit(json_result('0324',$this->response['0324']));
+//                                }
+//                                $params = array('nodeId'=>$nodeId,'nodeType'=>$nodeType,'deviceId'=>$data['address'],'groupNum'=>intval($item));
+//                            }
+//                        }else{
+//                            //分组没有在规定的范围内
+//                            exit(json_result('0420',$this->response['0420']));
+//                        }
+//                    }
+//                }else{
+//                    //没有分组的
+//                    //注意:nodeId是12位数的,不够时,前面补0
+//                    $nodeId = '';
+//                    $zero = '';
+//                    if (mb_strlen($data['macAddress']) <= 12){
+//                        for ($i = 0; $i < 12-(mb_strlen($data['macAddress'])); $i ++){
+//                            $zero .= '0';
+//                        }
+//                        $nodeId = $zero.$data['macAddress'];
+//                    }else{
+//                        //大于12位数了
+//                        exit(json_result('0324',$this->response['0324']));
 //                    }
+//                    $params = array('nodeId'=>$nodeId,'nodeType'=>$nodeType,'deviceId'=>$data['address']);
 //                }
 //
+//                $result = $this->plcDevice($url,$params,3);
+//                $resultObj = json_decode($result);
 //
-//                $networkData['gatewaytype'] = 'direct';
-//                $networkData['protocoltype'] = empty($protocoltype) ? 0 : $protocoltype;
-//                $networkData['areaid'] = $data['areaid'];
-//                $networkData['sectionid'] = $data['sectionid'];
-//                $networkData['devicesn'] = $number;
-//                if ($protocoltype == 10) $networkData['devicetype'] = 4;
-//                if ($protocoltype == 8 && ($data['control_type'] == 29 || $data['control_type'] == 33)) $networkData['devicetype'] = 4;
-//                if ($protocoltype == 3 && $data['control_type'] == 9) $networkData['devicetype'] = 4;
-//                if ($protocoltype == 8 && $data['control_type'] == 19) $networkData['devicetype'] = 4;
-//                if ($control_type == 16 || $control_type == 20) {
-//                    $networkData['devicetype'] = 5;
-//                }
-//                $networkData['network_name'] = $number;
-//                $networkData['net_type'] = 1;
-//                $networkData['createtime'] = date('Y-m-d H:i:s',time());
-//                $networkData['userId'] = $userId;
-//
-//                //$data['networkid'] = $this->Network_model->add($networkData);
-//                if ($protocoltype == 6) $this->add_device($data['address'],$freqId);
-//                if($protocoltype ==7 ) {
-//                    $onenet=$this->add_device_onenet($data['address']);
-//                    $file = fopen('./file/onenet_group_cmdURL.txt', 'a+');
-//                    fwrite($file, date('Y-m-d H:i:s').'----'.json_encode($onenet).' ');
-//                    fclose($file);
-//                    if (isset($onenet["data"])) {
-//                        $onenetId=$onenet['data']['device_id'];
-//                        if($onenetId){
-//                            $data['deviceid']=$onenetId;
-//                            $networkData['deviceid']=$onenetId;
-//                        }
-//                    }
+//                if ($resultObj->code != 200){
+//                    //不成功
+//                    exit(json_result($resultObj->code,$resultObj->msg));
 //                }
-//            }
-            //添加网关
+
+
+                //添加网关
             NetworkDTO networkDTO = new NetworkDTO();
             networkDTO.setDeviceSn(sn);
             //查询有没有网关
@@ -471,6 +611,46 @@ public class LampController {
             plcAddressService.insertDataByVO(plcAddressDTO);
         }
     }
+    // 添加设备
+    protected String addDevice(String deviceId,String freqId){
+        Map<String, FreqConfig> 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);
+            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
@@ -608,8 +788,8 @@ public class LampController {
                 jsonObject.put("nodeId",macAddress);
                 jsonObject.put("ab",lamp.getMode()+1);
                 jsonObject.put("luminance",light);
-                //发送命令
-                String result = this.quiHuiPlcDeviceDimming(url, jsonObject, 4);
+                //发送命令-调光
+                String result = this.quiHuiPlcDevice(url, jsonObject, 4);
 
                 if (result == null || result.length() == 0){
                     return toolUtils.response(InterfaceResultEnum.SEND_CMD_TIME_OUT,version);
@@ -700,7 +880,7 @@ public class LampController {
         String bodyStr = this.encryptAndMd5(objectString);
         String result = null;
         try {
-            result = toolUtils.sendHttp("post", url, bodyStr,3);
+            result = toolUtils.sendHttp("post", url, bodyStr,3, ToolUtils.ContentTypeEnum.CONTENT_TYPE_JSON);
         } catch (IOException e) {
             throw new RuntimeException(e);
         }
@@ -767,7 +947,7 @@ public class LampController {
 
         String respone = null;
         try {
-            respone = toolUtils.sendHttp("post",url,bodyJsonString,tokenObject.getToken(),null,4);
+            respone = toolUtils.sendHttp("post",url,bodyJsonString,tokenObject.getToken(),null,4,"Bearer", ToolUtils.ContentTypeEnum.CONTENT_TYPE_JSON);
             JSONObject parseObject = JSON.parseObject(respone);
             System.out.println("======ddd:"+parseObject);
             Integer ret = parseObject.getInteger("Ret");
@@ -855,7 +1035,7 @@ public class LampController {
 
         String respone = null;
         try {
-            respone = toolUtils.sendHttp("post",url,bodyStr,token,sessionId,4);
+            respone = toolUtils.sendHttp("post",url,bodyStr,token,sessionId,4,"Bearer", ToolUtils.ContentTypeEnum.CONTENT_TYPE_JSON);
             System.out.println("=====diming:"+respone);
             JSONObject parseObject = JSON.parseObject(respone);
             Integer ret = parseObject.getInteger("Ret");
@@ -939,7 +1119,7 @@ public class LampController {
         String sessionId = ((ZhongLightPlcVO) loginObject).getSessionId();
         String respone = null;
         try {
-            respone = toolUtils.sendHttp("post", url, bodyStr, token, sessionId, 5);
+            respone = toolUtils.sendHttp("post", url, bodyStr, token, sessionId, 5,"Bearer", ToolUtils.ContentTypeEnum.CONTENT_TYPE_JSON);
             System.out.println("===dd:"+respone);
 
             JSONObject parseObject = JSON.parseObject(respone);
@@ -1012,7 +1192,7 @@ public class LampController {
         String sessionId = ((ZhongLightPlcVO) loginObject).getSessionId();
         String respone = null;
         try {
-            respone = toolUtils.sendHttp("post", url, bodyStr, token, sessionId, 5);
+            respone = toolUtils.sendHttp("post", url, bodyStr, token, sessionId, 5,"Bearer", ToolUtils.ContentTypeEnum.CONTENT_TYPE_JSON);
             System.out.println("===light:"+respone);
 
             JSONObject parseObject = JSON.parseObject(respone);
@@ -1083,8 +1263,8 @@ public class LampController {
         String bodyJsonString = bodyJson.toString();
         return bodyJsonString;
     }
-    //广东启慧-调光
-    private String quiHuiPlcDeviceDimming(String url,JSONObject params,Integer timeOut) {
+    //广东启慧-调光/集中器设备注册(网关)
+    private String quiHuiPlcDevice(String url,JSONObject params,Integer timeOut) {
         String plcUrl = quHuiPlc.getUrl()+url;
         Random random = new Random();
         int min = 10000;
@@ -1111,12 +1291,46 @@ public class LampController {
         //发送post请求
         String result = null;
         try {
-             result = toolUtils.sendHttp("post",plcUrl, json, 4);
+             result = toolUtils.sendHttp("post",plcUrl, json, timeOut, ToolUtils.ContentTypeEnum.CONTENT_TYPE_JSON);
         } 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<String, Object> 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;
+//    }
 
     /**
      * 新建分组选择灯控

+ 1 - 0
src/main/java/com/welampiot/dao/LampDao.java

@@ -63,4 +63,5 @@ public interface LampDao {
     LampInfoDTO getLampOfLampPoleById(@Param("lampPoleId") Integer lampPoleId, @Param("lampId") Integer lampId);
     List<LampInfoDTO> findLampDeviceBySn(@Param("address") String address, @Param("version") Integer version);
     LampInfoDTO getDataByVO(LampInfoDTO vo);
+    List<LampInfoDTO> getListByDto(LampInfoDTO dto);
 }

+ 1 - 0
src/main/java/com/welampiot/dto/LampInfoDTO.java

@@ -108,6 +108,7 @@ public class LampInfoDTO {
     private List<Object> dateList; // 日期列表
     private List<Object> energyList; // 用电量列表
     private List<Object> powerSaveList; // 省电量列表
+    private String deviceId;
     public LampInfoDTO(){
     }
     public LampInfoDTO(Integer id){

+ 1 - 0
src/main/java/com/welampiot/dto/NetworkDTO.java

@@ -38,4 +38,5 @@ public class NetworkDTO {
     private String date;
     private String simId;
     private String uId;
+    private String deviceId;
 }

+ 19 - 19
src/main/java/com/welampiot/security/CustomizeFilterInvocationSecurityMetadataSource.java

@@ -33,25 +33,25 @@ public class CustomizeFilterInvocationSecurityMetadataSource implements FilterIn
         // 不需要鉴权,开发可打开,注释后续代码即可
 //        return null;
         //获取请求地址
-        String requestUrl = ((FilterInvocation) o).getRequestUrl();
-        if("/image/getImage".equals(requestUrl)){//获取登录验证码放行
-            return null;
-        }
-        Object user = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
-        if(user instanceof String && user.equals("anonymousUser")){
-            //禁止匿名访问(禁止未登录访问)
-            return SecurityConfig.createList("ROLE_LOGIN");
-        }
-        User userDetails = (User) user;
-        //查询具体某个接口的权限
-        List<PathDTO> permissionList = userService.queryUserGrantUrl(userDetails.getUsername());
-        if(CollectionUtils.isEmpty(permissionList)){
-            return SecurityConfig.createList("ROLE_NO_AUTH");
-        }
-        PathDTO path = permissionList.stream().filter(e->e.getUrl().equals(requestUrl)).findFirst().orElse(null);
-        if(path==null){
-            return SecurityConfig.createList("ROLE_NO_AUTH");
-        }
+//        String requestUrl = ((FilterInvocation) o).getRequestUrl();
+//        if("/image/getImage".equals(requestUrl)){//获取登录验证码放行
+//            return null;
+//        }
+//        Object user = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
+//        if(user instanceof String && user.equals("anonymousUser")){
+//            //禁止匿名访问(禁止未登录访问)
+//            return SecurityConfig.createList("ROLE_LOGIN");
+//        }
+//        User userDetails = (User) user;
+//        //查询具体某个接口的权限
+//        List<PathDTO> permissionList = userService.queryUserGrantUrl(userDetails.getUsername());
+//        if(CollectionUtils.isEmpty(permissionList)){
+//            return SecurityConfig.createList("ROLE_NO_AUTH");
+//        }
+//        PathDTO path = permissionList.stream().filter(e->e.getUrl().equals(requestUrl)).findFirst().orElse(null);
+//        if(path==null){
+//            return SecurityConfig.createList("ROLE_NO_AUTH");
+//        }
         //表明该请求接口可以访问
         return null;
     }

+ 1 - 0
src/main/java/com/welampiot/service/LampService.java

@@ -63,4 +63,5 @@ public interface LampService {
     LampDetailVO getLampCountByDTO(LampInfoDTO dto);
     List<LampInfoDTO> findLampDeviceBySn(String address, Integer version);
     LampInfoDTO getDataByVO(LampInfoDTO vo);
+    List<LampInfoDTO> getListByDto(LampInfoDTO dto);
 }

+ 4 - 0
src/main/java/com/welampiot/service/impl/LampServiceImpl.java

@@ -770,4 +770,8 @@ public class LampServiceImpl implements LampService {
     public LampInfoDTO getDataByVO(LampInfoDTO vo){
         return lampDao.getDataByVO(vo);
     }
+    @Override
+    public List<LampInfoDTO> getListByDto(LampInfoDTO dto){
+        return lampDao.getListByDto(dto);
+    }
 }

+ 3 - 3
src/main/java/com/welampiot/utils/AESUtils.java

@@ -31,7 +31,7 @@ public class AESUtils {
      * @return 返回base64编码的String
      * @throws Exception
      */
-    public static String encrypt(String encryptKey, String iv, String content) throws Exception {
+    public  String encrypt(String encryptKey, String iv, String content) throws Exception {
         byte[] raw = encryptKey.getBytes(charsetName);
         SecretKeySpec skeySpec = new SecretKeySpec(raw, algorithm);
         Cipher cipher = Cipher.getInstance(transformation);
@@ -49,7 +49,7 @@ public class AESUtils {
      * @return 返回原文
      * @throws Exception
      */
-    public static String decrypt(String encryptKey, String iv, String content) throws Exception {
+    public  String decrypt(String encryptKey, String iv, String content) throws Exception {
         byte[] raw = encryptKey.getBytes(charsetName);
         SecretKeySpec skeySpec = new SecretKeySpec(raw, algorithm);
         Cipher cipher = Cipher.getInstance(transformation);
@@ -69,7 +69,7 @@ public class AESUtils {
      * @return
      * @throws Exception
      */
-    public static String encodeHmacMD5(byte[] data, byte[] key)throws Exception {
+    public  String encodeHmacMD5(byte[] data, byte[] key)throws Exception {
         // 还原密钥
         SecretKey secretKey = new SecretKeySpec(key, "HmacMD5");
         // 实例化Mac

+ 201 - 0
src/main/java/com/welampiot/utils/JwtUtil.java

@@ -0,0 +1,201 @@
+package com.welampiot.utils;
+
+import com.alibaba.fastjson.JSONObject;
+import io.jsonwebtoken.*;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import javax.crypto.Mac;
+import javax.crypto.spec.SecretKeySpec;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+import java.util.Base64;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+@Component
+public class JwtUtil {
+    //头部
+    //private static String header = "{\"alg\":\"HS256\",\"typ\":\"JWT\"}";
+    //使用HMAC生成信息摘要时所使用的密钥
+    private static String secretKey="GQLs5BQwnTAel5iwqh/IbVWJW/xPjMCqCZ+sL82/g/4=";
+
+    @Autowired
+    private ToolUtils toolUtils;
+    /**
+     * 获取jwt token
+     * @param array $payload jwt载荷   格式如下非必须
+     * [
+     *  'iss'=>'jwt_admin',  //该JWT的签发者
+     *  'iat'=>time(),  //签发时间
+     *  'exp'=>time()+7200,  //过期时间
+     *  'nbf'=>time()+60,  //该时间之前不接收处理该Token
+     *  'sub'=>'www.admin.com',  //面向的用户
+     *  'jti'=>md5(uniqid('JWT').time())  //该Token唯一标识
+     * ]
+     * @return string
+     */
+    public String signatureToToken() {// String message
+        Map<String, Object> header = new HashMap<>();
+        header.put("alg","HS256");
+        header.put("typ","JWT");
+
+        Date date = new Date();
+        long time = date.getTime() / 1000; //是秒
+
+        Map<String, Object> jsonObject = new HashMap<>();
+        jsonObject.put("iss","chirpstack-application-server");
+        jsonObject.put("aud","chirpstack-application-server");
+        jsonObject.put("nbf",time-60);
+        jsonObject.put("exp",time+7200);
+        jsonObject.put("sub","user");
+        jsonObject.put("username","admin");
+
+        JwtBuilder jwtBuilder = Jwts.builder();
+        String jwtToken = jwtBuilder.setHeader(header) //header
+                .setClaims(jsonObject) //内容
+                .signWith(SignatureAlgorithm.HS256, secretKey) //签名
+                        .compact();
+        return jwtToken;
+
+    }
+    //解释 jwt token
+    public void parse(String token) {
+         JwtParser jwtParser = Jwts.parser();
+        Jws<Claims> claimsJws = jwtParser.setSigningKey(secretKey).parseClaimsJws(token);
+        Claims claims = claimsJws.getBody();
+        JwsHeader header = claimsJws.getHeader();
+//        System.out.println(claims.get("username"));
+//        System.out.println(claims.get("role"));
+//        System.out.println(claims.getId());
+//        System.out.println(claims.getSubject());
+//        System.out.println(claims.getExpiration());
+    }
+
+    // 设置设备网关参数,返回json字符串|null
+    public String setActivate(String deviceId){
+        JSONObject device = new JSONObject();
+
+        device.put("aFCntDown",0);
+        device.put("appSKey","a8a6a0a7a6a9a8a8a0a1a0a8a8a8a0a0");
+        device.put("devAddr",deviceId);
+        device.put("devEUI","00000000"+deviceId);
+        device.put("fCntUp",0);
+        device.put("fNwkSIntKey","a8a6a0a7a6a9a8a8a0a1a0a8a8a8a0a0");
+        device.put("nFCntDown",0);
+        device.put("nwkSEncKey","a8a6a0a7a6a9a8a8a0a1a0a8a8a8a0a0");
+        device.put("sNwkSIntKey","a8a6a0a7a6a9a8a8a0a1a0a8a8a8a0a0");
+
+        JSONObject data = new JSONObject();
+        data.put("deviceActivation",device);
+        String token = this.signatureToToken();
+
+        String url = "http://47.112.108.98:8090/api/devices/00000000"+deviceId+"/activate";
+        String respone = null;
+        try {
+            respone = toolUtils.sendHttp("post", url, data.toString(), token, null, 5, null, ToolUtils.ContentTypeEnum.CONTENT_TYPE_JSON);
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+        return respone;
+    }
+
+
+//    public static function getToken($payload)
+//    {
+//        if(is_array($payload))
+//        {
+//            $base64header=self::base64UrlEncode(json_encode(self::$header,JSON_UNESCAPED_UNICODE));
+//            $base64payload=self::base64UrlEncode(json_encode($payload,JSON_UNESCAPED_UNICODE));
+//            $token=$base64header.'.'.$base64payload.'.'.self::signature($base64header.'.'.$base64payload,self::$key,self::$header['alg']);
+//            return $token;
+//        }else{
+//            return false;
+//        }
+//    }
+//
+//
+//    /**
+//     * 验证token是否有效,默认验证exp,nbf,iat时间
+//     * @param string $Token 需要验证的token
+//     * @return bool|string
+//     */
+//    public static function verifyToken($Token)
+//    {
+//        $tokens = explode('.', $Token);
+//        if (count($tokens) != 3)
+//            return false;
+//
+//        list($base64header, $base64payload, $sign) = $tokens;
+//
+//        //获取jwt算法
+//        $base64decodeheader = json_decode(self::base64UrlDecode($base64header), JSON_OBJECT_AS_ARRAY);
+//        if (empty($base64decodeheader['alg']))
+//            return false;
+//
+//        //签名验证
+//        if (self::signature($base64header . '.' . $base64payload, self::$key, $base64decodeheader['alg']) !== $sign)
+//        return false;
+//
+//        $payload = json_decode(self::base64UrlDecode($base64payload), JSON_OBJECT_AS_ARRAY);
+//
+//        //签发时间大于当前服务器时间验证失败
+//        if (isset($payload['iat']) && $payload['iat'] > time())
+//            return false;
+//
+//        //过期时间小宇当前服务器时间验证失败
+//        if (isset($payload['exp']) && $payload['exp'] < time())
+//            return false;
+//
+//        //该nbf时间之前不接收处理该Token
+//        if (isset($payload['nbf']) && $payload['nbf'] > time())
+//            return false;
+//
+//        return $payload;
+//    }
+//
+//
+//
+//
+//    /**
+//     * base64UrlEncode   https://jwt.io/  中base64UrlEncode编码实现
+//     * @param string $input 需要编码的字符串
+//     * @return string
+//     */
+//    private static function base64UrlEncode($input)
+//    {
+//        return str_replace('=', '', strtr(base64_encode($input), '+/', '-_'));
+//    }
+//
+//    /**
+//     * base64UrlEncode  https://jwt.io/  中base64UrlEncode解码实现
+//     * @param string $input 需要解码的字符串
+//     * @return bool|string
+//     */
+//    private static function base64UrlDecode($input)
+//    {
+//        $remainder = strlen($input) % 4;
+//        if ($remainder) {
+//            $addlen = 4 - $remainder;
+//            $input .= str_repeat('=', $addlen);
+//        }
+//        return base64_decode(strtr($input, '-_', '+/'));
+//    }
+//
+//    /**
+//     * HMACSHA256签名   https://jwt.io/  中HMACSHA256签名实现
+//     * @param string $input 为base64UrlEncode(header).".".base64UrlEncode(payload)
+//     * @param string $key
+//     * @param string $alg   算法方式
+//     * @return mixed
+//     */
+//    private static function signature($input,$key,$alg = 'HS256')
+//    {
+//        $alg_config=array(
+//                'HS256'=>'sha256'
+//        );
+//        return self::base64UrlEncode(hash_hmac($alg_config[$alg], $input, $key,true));
+//    }
+}

+ 80 - 12
src/main/java/com/welampiot/utils/ToolUtils.java

@@ -35,10 +35,8 @@ import org.springframework.stereotype.Component;
 import javax.servlet.http.HttpServletRequest;
 import java.io.*;
 import java.lang.reflect.Field;
-import java.net.HttpURLConnection;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.net.URLConnection;
+import java.net.*;
+import java.nio.charset.StandardCharsets;
 import java.text.DecimalFormat;
 import java.util.*;
 import java.util.regex.Pattern;
@@ -46,6 +44,17 @@ import java.util.zip.CRC32;
 
 @Component
 public class ToolUtils {
+    //http的编码
+    public  enum ContentTypeEnum {
+        CONTENT_TYPE_JSON("application/json;charset=utf-8"),
+        CONTENT_TYPE_FORM("application/x-www-form-urlencoded;charset=utf-8")
+        ;
+        private String contentType;
+
+        ContentTypeEnum(String contentType) {
+            this.contentType = contentType;
+        }
+    }
     private UserDTO user;
     @Autowired
     private UserService userService;
@@ -73,7 +82,6 @@ public class ToolUtils {
     public List getSectionList(HttpServletRequest request){
         String username = request.getParameter("username");
         ArrayList<Object> sectionList = new ArrayList<>();
-
         if (username == null || username.toString().length() == 0) {
             sectionList.add(0);
             return sectionList;
@@ -1068,9 +1076,10 @@ System.out.println(res);
      *@param  request:请求方式
      * @param  url:路径
      * @param param:参数
+     * @param ContentTypeEnum: 编码类型
      * @return 返回类型字符串
     */
-    public  String sendHttp(String request,String url, String param,Integer timeOut) throws IOException {
+    public  String sendHttp(String request,String url, String param,Integer timeOut,ContentTypeEnum typeEnum) throws IOException {
         String result = "";
         URL postUrl = new URL(url);
         // 打开连接
@@ -1079,6 +1088,13 @@ System.out.println(res);
         // http正文内,因此需要设为true
         connection.setDoOutput(true);
         connection.setDoInput(true);
+        if (timeOut == null || timeOut == 0){
+            connection.setConnectTimeout( 5000); //单位:毫秒
+            connection.setReadTimeout( 5000); //单位:毫秒
+        }else {
+            connection.setConnectTimeout(timeOut * 1000); //单位:毫秒
+            connection.setReadTimeout(timeOut * 1000); //单位:毫秒
+        }
         // Set the post method. Default is GET
         connection.setRequestMethod(request.toUpperCase());
         // Post 请求不能使用缓存
@@ -1086,7 +1102,12 @@ System.out.println(res);
         // URLConnection.setInstanceFollowRedirects是成员函数,仅作用于当前函数
         connection.setInstanceFollowRedirects(true);
         // 进行编码
-        connection.setRequestProperty("Content-Type","application/json;charset=utf-8");
+        if (typeEnum == null){
+            //默认是"application/json;charset=utf-8"
+            connection.setRequestProperty("Content-Type","application/json;charset=utf-8");
+        }else {
+            connection.setRequestProperty("Content-Type",typeEnum.contentType);
+        }
         // 连接,从postUrl.openConnection()至此的配置必须要在connect之前完成,
         // 要注意的是connection.getOutputStream会隐含的进行connect。
         connection.connect();
@@ -1111,9 +1132,14 @@ System.out.println(res);
      *@param  request:请求方式
      * @param  url:路径
      * @param param:参数
+     *  @param token:令牌
+     *  @param sessionId:会话id
+     *  @param timeOut:超时
+     *  @param mark:标记Authorization是传哪种方式
+     * @param typeEnum: 编码类型
      * @return 返回类型字符串
      */
-    public  String sendHttp(String request,String url, String param,String token,String sessionId,Integer timeOut) throws IOException {
+    public  String sendHttp(String request,String url, String param,String token,String sessionId,Integer timeOut,String mark,ContentTypeEnum typeEnum) throws IOException {
         String result = "";
         URL postUrl = new URL(url);
         // 打开连接
@@ -1129,11 +1155,32 @@ System.out.println(res);
         // URLConnection.setInstanceFollowRedirects是成员函数,仅作用于当前函数
         connection.setInstanceFollowRedirects(true);
         // 进行编码
-        connection.setRequestProperty("Content-Type","application/json;charset=utf-8");
-        connection.setRequestProperty("Authorization","Bearer "+token);
+        //connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
+        if (typeEnum == null){
+            //默认是"application/json;charset=utf-8"
+            connection.setRequestProperty("Content-Type","application/json;charset=utf-8");
+        }else {
+            connection.setRequestProperty("Content-Type",typeEnum.contentType);
+        }
+
+        if (mark != null && mark.toLowerCase().equals("bearer")){
+            connection.setRequestProperty("Authorization","Bearer "+token);
+        }else if(mark != null && mark.equals("api-key")) {
+            connection.setRequestProperty("api-key"," "+token);
+        }else {
+            connection.setRequestProperty("Authorization",token);
+        }
+
         if (sessionId != null){
             connection.setRequestProperty("SessionId"," "+sessionId);
         }
+        if (timeOut == null || timeOut == 0){
+            connection.setConnectTimeout( 5000); //单位:毫秒
+            connection.setReadTimeout( 5000); //单位:毫秒
+        }else {
+            connection.setConnectTimeout(timeOut * 1000); //单位:毫秒
+            connection.setReadTimeout(timeOut * 1000); //单位:毫秒
+        }
         // 连接,从postUrl.openConnection()至此的配置必须要在connect之前完成,
         // 要注意的是connection.getOutputStream会隐含的进行connect。
         connection.connect();
@@ -1143,8 +1190,7 @@ System.out.println(res);
         out.writeBytes(param);
         out.flush();
         out.close(); // flush and close
-        BufferedReader reader = new BufferedReader(new InputStreamReader(
-                connection.getInputStream()));
+        BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
         String line;
         while ((line = reader.readLine()) != null) {
             result += line;
@@ -1153,4 +1199,26 @@ System.out.println(res);
         connection.disconnect();
         return result;
     }
+
+    // 添加设备onenet
+    public String addDeviceOnenet(String deviceId){
+        JSONObject device = new JSONObject();
+        device.put("title",deviceId);
+        device.put("protocol","LWM2M");
+
+        JSONObject authInfo = new JSONObject();
+        authInfo.put(deviceId,deviceId);
+
+        device.put("auth_info",authInfo);
+        String url="http://api.heclouds.com/devices";
+        String token = "HpumrF3BKBo3mOFIhkyf5MtIIOc=";
+        String respone = null;
+        try {
+            respone = this.sendHttp("post", url, device.toString(), token, null, 5, "api-key", ContentTypeEnum.CONTENT_TYPE_JSON);
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+        return respone;
+
+    }
 }

+ 18 - 1
src/main/resources/mapper/LampMapper.xml

@@ -1254,13 +1254,30 @@
             <if test="id != null">
                 id = #{id} or
             </if>
-            <if test="sn != null and sn != ''">
+            <if test="address != null and address != ''">
                 address = #{sn} or
             </if>
             <if test="networkId != null and networkId != 0">
                 networkid = #{networkId} or
             </if>
+            <if test="macAddress != null and macAddress = ''">
+                macAddress = #{macAddress} or
+            </if>
+
         </trim>
         limit 0,1
     </select>
+    <select id="getListByDto" resultType="LampInfoDTO">
+        select id,address,mode,control_type as controlType from lampinfo
+        <trim prefix="where" suffixOverrides="and|or">
+            <if test="id != null">
+                id = #{id} or
+            </if>
+            <if test="address != null and macAddress != ''">
+                address = #{address} and macAddress = #{macAddress} or
+            </if>
+
+        </trim>
+        limit 0,2
+    </select>
 </mapper>

+ 5 - 1
src/main/resources/mapper/NetworkMapper.xml

@@ -3,8 +3,12 @@
 <mapper namespace="com.welampiot.dao.NetworkDao">
     <insert id="add" parameterType="com.welampiot.dto.NetworkDTO" useGeneratedKeys="true" keyProperty="id">
         insert into network(network_name,devicesn,protocoltype,areaid,sectionid,createtime,net_type,gatewaytype,devicetype,userId)
+        <if test="deviceId != null">,deviceid</if>
         values
-        (#{networkName},#{deviceSn},#{protocolType},#{areaId},#{sectionId},#{createTime},#{netType},#{gatewayType},#{deviceType},#{userId})
+        (#{networkName},#{deviceSn},#{protocolType},#{areaId},#{sectionId},#{createTime},#{netType},#{gatewayType},#{deviceType},#{userId}
+        <if test="deviceId != null">,#{deviceId}</if>
+        )
+
 <!--        <if test="sectionList != null and !sectionList.isEmpty()">-->
 <!--            where l.sectionid in-->
 <!--            <foreach item="dto" collection="sectionList" open="(" separator="," close=")">-->

+ 29 - 0
src/main/resources/prod/application.yml

@@ -67,6 +67,35 @@ zhonglight: #中灯智慧科技(深圳)有限公司 zigbee
     zhongUserName: zdzh1935 #用户名
     zhongPassword: Zhld2021 #密码
 
+freqlist:
+  maps:
+    1:
+      name: US915
+      id: 1
+      applicationID: 1
+      deviceProfileID: e02c9c58-ae71-41f2-aab5-0f701e29810b
+      networkServerID: 1
+      serviceProfileID: 98b510c6-49ce-4c9b-8f22-7e56bd337ab4
+      dr: 8
+      frequency: 923300000
+    2:
+      name: EU868
+      id: 2
+      applicationID: 7
+      deviceProfileID: 0e5ea48e-1265-431a-be52-484a3a1d693a
+      networkServerID: 76
+      serviceProfileID: 7bd2cd5b-7390-4391-96f5-8c69760a6d3c
+      dr: 0
+      frequency: 869525000
+    3:
+      name: AS923
+      id: 3
+      applicationID: 6
+      deviceProfileID: 454e382e-e9d5-4dad-8d37-b8a51851befa
+      networkServerID: 77
+      serviceProfileID: 998c48eb-7f77-4517-beb4-871e22899dd7
+      dr: 3
+      frequency: 921600000
 
 mybatis:
   mapper-locations: classpath:/mapper/*.xml

+ 29 - 0
src/main/resources/test/application.yml

@@ -67,6 +67,35 @@ zhonglight: #中灯智慧科技(深圳)有限公司 zigbee
     zhongUserName: zdzh1935 #用户名
     zhongPassword: Zhld2021 #密码
 
+freqlist:
+  maps:
+    1:
+      name: US915
+      id: 1
+      applicationID: 1
+      deviceProfileID: e02c9c58-ae71-41f2-aab5-0f701e29810b
+      networkServerID: 1
+      serviceProfileID: 98b510c6-49ce-4c9b-8f22-7e56bd337ab4
+      dr: 8
+      frequency: 923300000
+    2:
+      name: EU868
+      id: 2
+      applicationID: 7
+      deviceProfileID: 0e5ea48e-1265-431a-be52-484a3a1d693a
+      networkServerID: 76
+      serviceProfileID: 7bd2cd5b-7390-4391-96f5-8c69760a6d3c
+      dr: 0
+      frequency: 869525000
+    3:
+      name: AS923
+      id: 3
+      applicationID: 6
+      deviceProfileID: 454e382e-e9d5-4dad-8d37-b8a51851befa
+      networkServerID: 77
+      serviceProfileID: 998c48eb-7f77-4517-beb4-871e22899dd7
+      dr: 3
+      frequency: 921600000
 
 mybatis:
   mapper-locations: classpath:/mapper/*.xml

+ 15 - 16
src/test/java/com/welampiot/service/UserServiceTest.java

@@ -1,12 +1,9 @@
 package com.welampiot.service;
 
-import com.welampiot.configuration.BroadcastConfig;
-import com.welampiot.configuration.ScreenConfig;
+import com.alibaba.fastjson.JSONObject;
+import com.welampiot.configuration.FreqConfig;
+import com.welampiot.configuration.FreqMapConfig;
 import com.welampiot.dto.LampInfoDTO;
-import com.welampiot.dto.NetworkDTO;
-import com.welampiot.dto.PlcAddressDTO;
-import com.welampiot.service.UserService;
-import com.welampiot.service.impl.LampServiceImpl;
 import com.welampiot.utils.*;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -17,11 +14,9 @@ import org.springframework.test.context.junit4.SpringRunner;
 import javax.annotation.Resource;
 import javax.sql.DataSource;
 import java.io.IOException;
-import java.sql.Connection;
+import java.nio.charset.StandardCharsets;
 import java.sql.SQLException;
-import java.text.SimpleDateFormat;
 import java.util.*;
-import java.util.zip.CRC32;
 
 @RunWith(SpringRunner.class)
 @SpringBootTest
@@ -35,15 +30,19 @@ public class UserServiceTest {
     @Autowired
     private VideoGbInfoService videoGbInfoService;
     @Resource
-    private NetworkService plcAddressService;
+    private LampService lampService;
+
 
     @Test
-    public void testConnection() throws SQLException, IOException {
-        NetworkDTO networkDTO = new NetworkDTO();
-        networkDTO.setDeviceSn("fefed436");
-        //plcAddressDTO.setLampAddress("C20102010400");
-        networkDTO = plcAddressService.getSimpleData(networkDTO);
-        System.out.println("===d===:"+networkDTO);
+    public void testConnection() throws Exception {
+        LampInfoDTO lampInfoDTO = new LampInfoDTO();
+        String sn = "06780064";
+        String macAddress = "352011200865";
+        lampInfoDTO.setMacAddress(macAddress);
+        lampInfoDTO.setAddress(sn);
+        List<LampInfoDTO> listByDto = lampService.getListByDto(lampInfoDTO);
+        System.out.println("===dd=:"+listByDto);
+
 //        long l = System.currentTimeMillis() - (24L * 3600 * 30*1000);
 //        Date date = new Date(l);
 //        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");