package com.web.api; import java.util.ArrayList; import com.web.pda.gltPda_wdPda.service.WDApiService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.app.base.control.WebController; import com.app.base.data.ApiResponseResult; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @Api(description = "设备接口") @CrossOrigin @ControllerAdvice //@RestController @Controller @RequestMapping(value = "api") public class ApiController extends WebController{ @Autowired private WDApiService wdApiService; protected Logger logger = LoggerFactory.getLogger(this.getClass()); @ApiOperation(value = "用于设备数据上传", notes = " 用于设备数据上传") @RequestMapping(value = "/uploadDeviceData", method = RequestMethod.POST, produces = "application/json") @ResponseBody public ApiResponseResult uploadDeviceData(@RequestBody JSONObject jsonObject) { try { logger.info("上传的原始数据是:"+JSONObject.toJSONString(jsonObject)); String factory = jsonObject.getString("factory"); String company = jsonObject.getString("company"); String prono = jsonObject.getString("prono"); ArrayList pDataList = (ArrayList) jsonObject.get("pData"); JSONArray pData = JSONArray.parseArray(JSONObject.toJSONString(pDataList)); return wdApiService.uploadDeviceData(factory, company, prono,pData); } catch (Exception e) { e.printStackTrace(); logger.info("上传数据JSON格式["+JSONObject.toJSONString(jsonObject)+"]校验不通过。:"+e.toString()); return ApiResponseResult.failure("上传数据JSON格式校验不通过。"+e.toString()); } } }