4
hao
2025-04-16 c5fb1fbcbb2bf4d511773d348f9ef625855c61fc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package com.web.pda.gltPda_wdPda.controller;
 
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 = "wd_api")
public class WDApiController 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());
        }
    }
 
}