| | |
| | | |
| | | |
| | | private static final String UPLOAD_DATA_URL = "/termite/syncDeviceState"; |
| | | |
| | | /*** |
| | | * 新设备传图片接口 |
| | | */ |
| | | private static final String UPLOAD_FILE_URL = "/termite/termiteDataup"; |
| | | /** |
| | | * 旧设备传图片接口 |
| | | * 没有Authorization验证 |
| | | */ |
| | | private static final String UPLOAD_FILE_URL_OLD = "/termite/termiteDataupOld"; |
| | | |
| | | private NettyHttpConfig nettyHttpConfig; |
| | | |
| | | private BaiyiPicService baiyiPicService; |
| | |
| | | |
| | | |
| | | protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest fullRequest) throws Exception { |
| | | // Authorization验证 |
| | | boolean isRequestValid = isValidHttpRequest(ctx, fullRequest); |
| | | if (!isRequestValid) { |
| | | HttpResponseUtils.sendResponseJson2(ctx, HttpResponseStatus.BAD_REQUEST, "验证失败",null); |
| | | return ; |
| | | } |
| | | |
| | | // 请求路径验证 |
| | | String urlyz = urlyz(ctx, fullRequest); |
| | | if (UPLOAD_FILE_URL.equals(urlyz)) { //传图片 |
| | | HttpPostMultipartRequestDecoder test = new HttpPostMultipartRequestDecoder(fullRequest); |
| | | List<InterfaceHttpData> bodyHttpDatas = test.getBodyHttpDatas(); |
| | | XfByPic xfByPic = new XfByPic(); |
| | | |
| | | for (InterfaceHttpData item : bodyHttpDatas ) { |
| | | if ( item instanceof Attribute){ |
| | | Attribute attribute = (Attribute)item; |
| | | System.out.println("getName:::"+attribute.getName()); |
| | | System.out.println("getValue:::"+attribute.getValue()); |
| | | String value = attribute.getValue(); |
| | | switch(attribute.getName()){ |
| | | case "mnNo": |
| | | xfByPic.setMnNo(value); |
| | | break; |
| | | case "order": |
| | | |
| | | xfByPic.setOrder(value); |
| | | break; |
| | | case "sn": |
| | | xfByPic.setSn(value); |
| | | break; |
| | | case "ap": |
| | | xfByPic.setAp(value); |
| | | break; |
| | | case "camera": |
| | | xfByPic.setCamera(value); |
| | | break; |
| | | case "hardware": |
| | | xfByPic.setHardware(value); |
| | | break; |
| | | case "rssi": |
| | | xfByPic.setRssi(value); |
| | | break; |
| | | case "software": |
| | | xfByPic.setSoftware(value); |
| | | break; |
| | | case "temperature": |
| | | xfByPic.setTemperature(value); |
| | | break; |
| | | case "voltage": |
| | | xfByPic.setVoltage(value); |
| | | break; |
| | | } |
| | | |
| | | |
| | | } else if (item instanceof FileUpload) { |
| | | |
| | | FileUpload file = (FileUpload)item; |
| | | String filename = file.getFilename(); |
| | | |
| | | ByteArrayInputStream stream = new ByteArrayInputStream(ByteBufUtil.getBytes(file.getByteBuf())); |
| | | MockMultipartFile multipartFile |
| | | = new MockMultipartFile("11", filename, "application/octet-stream", stream); |
| | | |
| | | String picurl = iOssClient.uploadFile(filename, multipartFile); |
| | | log.info("图片上传地址::"+picurl); |
| | | xfByPic.setImageurl(picurl); |
| | | } |
| | | // Authorization验证 |
| | | boolean isRequestValid = isValidHttpRequest(ctx, fullRequest); |
| | | if (!isRequestValid) { |
| | | HttpResponseUtils.sendResponseJson2(ctx, HttpResponseStatus.BAD_REQUEST, "验证失败",null); |
| | | return ; |
| | | } |
| | | xfByPic.setCreatedAt(new Date()); |
| | | |
| | | XfByPic xfByPic = setEntity(fullRequest); |
| | | |
| | | // 保存入库xfByPic |
| | | baiyiPicService.inserXfPicUrl(xfByPic); |
| | | |
| | | |
| | | |
| | | } else if(UPLOAD_DATA_URL.equals(urlyz)) { //传数据 |
| | | }else if(UPLOAD_FILE_URL_OLD.equals(urlyz)) { // 旧类型设备上传图片数据接口 |
| | | log.info("UPLOAD_FILE_URL_OLD接口调用成功!!!!:"); |
| | | System.err.println(fullRequest); |
| | | |
| | | XfByPic xfByPic = setEntity(fullRequest); |
| | | // 保存入库xfByPic |
| | | baiyiPicService.inserXfOldPicUrl(xfByPic); |
| | | |
| | | |
| | | }else if(UPLOAD_DATA_URL.equals(urlyz)) { //传数据 |
| | | HttpPostMultipartRequestDecoder test = new HttpPostMultipartRequestDecoder(fullRequest); |
| | | List<InterfaceHttpData> bodyHttpDatas = test.getBodyHttpDatas(); |
| | | for (InterfaceHttpData item : bodyHttpDatas ) { |
| | | if ( item instanceof Attribute){ |
| | | // FileUpload file = (FileUpload)item; |
| | | // String filename = file.getFilename(); |
| | | // ByteArrayInputStream stream = new ByteArrayInputStream(ByteBufUtil.getBytes(file.getByteBuf())); |
| | | // MockMultipartFile multipartFile |
| | | // = new MockMultipartFile("11", filename, "application/octet-stream", stream); |
| | | // String picurl = iOssClient.uploadFile(filename, multipartFile); |
| | | // log.info("图片上传地址::"+picurl); |
| | | |
| | | } else if (item instanceof FileUpload) { |
| | | System.out.println("Attribute:::"+item.getName()); |
| | |
| | | HttpResponseUtils.sendResponseJson(ctx, HttpResponseStatus.OK, "上传成功"); |
| | | } |
| | | |
| | | //请求参数注入实体 |
| | | public XfByPic setEntity(FullHttpRequest fullRequest) throws Exception { |
| | | HttpPostMultipartRequestDecoder test = new HttpPostMultipartRequestDecoder(fullRequest); |
| | | List<InterfaceHttpData> bodyHttpDatas = test.getBodyHttpDatas(); |
| | | XfByPic xfByPic = new XfByPic(); |
| | | for (InterfaceHttpData item : bodyHttpDatas ) { |
| | | if (item instanceof Attribute) { |
| | | Attribute attribute = (Attribute) item; |
| | | String value = attribute.getValue(); |
| | | switch (attribute.getName()) { |
| | | case "mnNo": |
| | | xfByPic.setMnNo(value); |
| | | break; |
| | | case "order": |
| | | |
| | | xfByPic.setOrder(value); |
| | | break; |
| | | case "sn": |
| | | xfByPic.setSn(value); |
| | | break; |
| | | case "ap": |
| | | xfByPic.setAp(value); |
| | | break; |
| | | case "camera": |
| | | xfByPic.setCamera(value); |
| | | break; |
| | | case "hardware": |
| | | xfByPic.setHardware(value); |
| | | break; |
| | | case "rssi": |
| | | xfByPic.setRssi(value); |
| | | break; |
| | | case "software": |
| | | xfByPic.setSoftware(value); |
| | | break; |
| | | case "temperature": |
| | | xfByPic.setTemperature(value); |
| | | break; |
| | | case "voltage": |
| | | xfByPic.setVoltage(value); |
| | | break; |
| | | } |
| | | |
| | | |
| | | } else if (item instanceof FileUpload) { |
| | | |
| | | FileUpload file = (FileUpload) item; |
| | | String filename = file.getFilename(); |
| | | |
| | | ByteArrayInputStream stream = new ByteArrayInputStream(ByteBufUtil.getBytes(file.getByteBuf())); |
| | | MockMultipartFile multipartFile |
| | | = new MockMultipartFile("11", filename, "application/octet-stream", stream); |
| | | |
| | | String picurl = iOssClient.uploadFile(filename, multipartFile); |
| | | log.info("图片上传地址::" + picurl); |
| | | xfByPic.setImageurl(picurl); |
| | | } |
| | | } |
| | | xfByPic.setCreatedAt(new Date()); |
| | | |
| | | return xfByPic; |
| | | } |
| | | |
| | | |
| | | // 请求路径验证 |
| | | public String urlyz(ChannelHandlerContext ctx, FullHttpRequest request) { |
| | | try { |