@Test public void readAirKeyData() throws Exception { mockMvc.perform((post("/api/device/air_data") .param("device_id", 1129 + "") .param("cmd", "power") .param("temp", "26"))).andExpect(status().isOk()) .andDo(print()); }
@RequestMapping(value = "/air_data", method = RequestMethod.POST) public @ResponseBody ResponseHeader readAirKeyData( @RequestParam(value = "device_id", required = true) int deviceId, @RequestParam(value = "cmd", required = true) String cmd, @RequestParam(value = "temp", required = true) String temp) { ResponseHeader header = new ResponseHeader(); header.setCode(RESPONSE_OK); System.out.println(deviceId + ":" + cmd + ":" + temp); try { AirKey airKey = airCmdDao.query(deviceId, cmd, temp); if (airKey == null || airKey.getData() == null) { String data = apiData.getAirData(deviceId, cmd, temp, LoadApiData.GOOGLE_FORMAT); System.out.println("request air data:" + cmd + ":" + temp + ":" + data); airKey = new AirKey(deviceId, cmd, temp, data); airCmdDao.insert(airKey); } else { header.setResult(airKey.getData()); return header; } header.setResult(airKey.getData()); } catch (Exception e) { e.printStackTrace(); header.setCode(RESPONSE_EXCEPTION); header.setErrorMsg("数据获取异常"); return header; } return header; }
DeviceController { @RequestMapping(value = "/air_data", method = RequestMethod.POST) public @ResponseBody ResponseHeader readAirKeyData( @RequestParam(value = "device_id", required = true) int deviceId, @RequestParam(value = "cmd", required = true) String cmd, @RequestParam(value = "temp", required = true) String temp) { ResponseHeader header = new ResponseHeader(); header.setCode(RESPONSE_OK); System.out.println(deviceId + ":" + cmd + ":" + temp); try { AirKey airKey = airCmdDao.query(deviceId, cmd, temp); if (airKey == null || airKey.getData() == null) { String data = apiData.getAirData(deviceId, cmd, temp, LoadApiData.GOOGLE_FORMAT); System.out.println("request air data:" + cmd + ":" + temp + ":" + data); airKey = new AirKey(deviceId, cmd, temp, data); airCmdDao.insert(airKey); } else { header.setResult(airKey.getData()); return header; } header.setResult(airKey.getData()); } catch (Exception e) { e.printStackTrace(); header.setCode(RESPONSE_EXCEPTION); header.setErrorMsg("数据获取异常"); return header; } return header; } }
DeviceController { @RequestMapping(value = "/air_data", method = RequestMethod.POST) public @ResponseBody ResponseHeader readAirKeyData( @RequestParam(value = "device_id", required = true) int deviceId, @RequestParam(value = "cmd", required = true) String cmd, @RequestParam(value = "temp", required = true) String temp) { ResponseHeader header = new ResponseHeader(); header.setCode(RESPONSE_OK); System.out.println(deviceId + ":" + cmd + ":" + temp); try { AirKey airKey = airCmdDao.query(deviceId, cmd, temp); if (airKey == null || airKey.getData() == null) { String data = apiData.getAirData(deviceId, cmd, temp, LoadApiData.GOOGLE_FORMAT); System.out.println("request air data:" + cmd + ":" + temp + ":" + data); airKey = new AirKey(deviceId, cmd, temp, data); airCmdDao.insert(airKey); } else { header.setResult(airKey.getData()); return header; } header.setResult(airKey.getData()); } catch (Exception e) { e.printStackTrace(); header.setCode(RESPONSE_EXCEPTION); header.setErrorMsg("数据获取异常"); return header; } return header; }  }
DeviceController { @RequestMapping(value = "/air_data", method = RequestMethod.POST) public @ResponseBody ResponseHeader readAirKeyData( @RequestParam(value = "device_id", required = true) int deviceId, @RequestParam(value = "cmd", required = true) String cmd, @RequestParam(value = "temp", required = true) String temp) { ResponseHeader header = new ResponseHeader(); header.setCode(RESPONSE_OK); System.out.println(deviceId + ":" + cmd + ":" + temp); try { AirKey airKey = airCmdDao.query(deviceId, cmd, temp); if (airKey == null || airKey.getData() == null) { String data = apiData.getAirData(deviceId, cmd, temp, LoadApiData.GOOGLE_FORMAT); System.out.println("request air data:" + cmd + ":" + temp + ":" + data); airKey = new AirKey(deviceId, cmd, temp, data); airCmdDao.insert(airKey); } else { header.setResult(airKey.getData()); return header; } header.setResult(airKey.getData()); } catch (Exception e) { e.printStackTrace(); header.setCode(RESPONSE_EXCEPTION); header.setErrorMsg("数据获取异常"); return header; } return header; }  @RequestMapping(value = "/types", method = RequestMethod.GET) @ResponseBody ResponseHeader readDeviceType(); @RequestMapping(value = "/brands", method = RequestMethod.POST) @ResponseBody ResponseHeader readBrands(@RequestParam(value = "type_id", required = true) int typeid); @RequestMapping(value = "/key_test", method = RequestMethod.POST) @ResponseBody ResponseHeader readKeyTests(
            @RequestParam(value = "type_id", required = true) int typeId,
            @RequestParam(value = "brand_id", required = true) int brandId); @RequestMapping(value = "/key_list", method = RequestMethod.POST) @ResponseBody ResponseHeader readKeyList(
            @RequestParam(value = "device_id", required = true) int deviceId); @RequestMapping(value = "/key_data", method = RequestMethod.POST) @ResponseBody ResponseHeader readDeviceKeyData(
            @RequestParam(value = "device_id", required = true) int deviceId,
            @RequestParam(value = "cmd", required = true) String cmd); @RequestMapping(value = "/air_data", method = RequestMethod.POST) @ResponseBody ResponseHeader readAirKeyData(
            @RequestParam(value = "device_id", required = true) int deviceId,
            @RequestParam(value = "cmd", required = true) String cmd,
            @RequestParam(value = "temp", required = true) String temp); }
DeviceController { @RequestMapping(value = "/air_data", method = RequestMethod.POST) public @ResponseBody ResponseHeader readAirKeyData( @RequestParam(value = "device_id", required = true) int deviceId, @RequestParam(value = "cmd", required = true) String cmd, @RequestParam(value = "temp", required = true) String temp) { ResponseHeader header = new ResponseHeader(); header.setCode(RESPONSE_OK); System.out.println(deviceId + ":" + cmd + ":" + temp); try { AirKey airKey = airCmdDao.query(deviceId, cmd, temp); if (airKey == null || airKey.getData() == null) { String data = apiData.getAirData(deviceId, cmd, temp, LoadApiData.GOOGLE_FORMAT); System.out.println("request air data:" + cmd + ":" + temp + ":" + data); airKey = new AirKey(deviceId, cmd, temp, data); airCmdDao.insert(airKey); } else { header.setResult(airKey.getData()); return header; } header.setResult(airKey.getData()); } catch (Exception e) { e.printStackTrace(); header.setCode(RESPONSE_EXCEPTION); header.setErrorMsg("数据获取异常"); return header; } return header; }  @RequestMapping(value = "/types", method = RequestMethod.GET) @ResponseBody ResponseHeader readDeviceType(); @RequestMapping(value = "/brands", method = RequestMethod.POST) @ResponseBody ResponseHeader readBrands(@RequestParam(value = "type_id", required = true) int typeid); @RequestMapping(value = "/key_test", method = RequestMethod.POST) @ResponseBody ResponseHeader readKeyTests(
            @RequestParam(value = "type_id", required = true) int typeId,
            @RequestParam(value = "brand_id", required = true) int brandId); @RequestMapping(value = "/key_list", method = RequestMethod.POST) @ResponseBody ResponseHeader readKeyList(
            @RequestParam(value = "device_id", required = true) int deviceId); @RequestMapping(value = "/key_data", method = RequestMethod.POST) @ResponseBody ResponseHeader readDeviceKeyData(
            @RequestParam(value = "device_id", required = true) int deviceId,
            @RequestParam(value = "cmd", required = true) String cmd); @RequestMapping(value = "/air_data", method = RequestMethod.POST) @ResponseBody ResponseHeader readAirKeyData(
            @RequestParam(value = "device_id", required = true) int deviceId,
            @RequestParam(value = "cmd", required = true) String cmd,
            @RequestParam(value = "temp", required = true) String temp);  }