package com.youchain.test;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.youchain.annotation.AnonymousAccess;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import static org.springframework.http.HttpStatus.OK;

@RestController
public class TestController {
    JSONObject jsonObject;
    JSONArray jsonArray;
    @PostMapping("/interfaces/api/amr/submitMission")
    @AnonymousAccess
    public ResponseEntity<Object> submitMission(@RequestBody JSON resources){
        System.out.println("AGV接受报文:"+resources);
        jsonObject=new JSONObject();
        jsonArray=new JSONArray();
        jsonObject.put("code","0");
        jsonObject.put("message","");
        jsonObject.put("data","");
        jsonObject.put("success","false");
        return new ResponseEntity<>(jsonObject, OK);
    }
    @PostMapping ("/queryPoint")
    @AnonymousAccess
    public ResponseEntity<Object>  queryPoint(@RequestBody JSONObject json){
        System.out.println("光电点位状态查询 仿真测试:"+json);
        jsonObject=new JSONObject();
        jsonArray=new JSONArray();
        jsonObject.put("status","200");
        jsonObject.put("message","");
        String pointType=json.getString("pointType");
        JSONObject jsonObject1=new JSONObject();
        if (pointType.equals("1")){
            jsonObject1.put("pointCode",json.get("pointCode"));
            jsonObject1.put("pointStatus","0");
        }else if (pointType.equals("2")){
            jsonObject1.put("pointCode",json.get("pointCode"));
            jsonObject1.put("pointStatus","1");
        }else if (pointType.equals("3")){
            jsonObject1.put("pointCode",json.get("pointCode"));
            jsonObject1.put("pointStatus","0");
        }

        jsonArray.add(jsonObject1);
        jsonObject.put("data",jsonArray);
        return new ResponseEntity<>(jsonObject, OK);
    }

    @PostMapping ("/lineApply")
    @AnonymousAccess
    public ResponseEntity<Object>  lineApply(@RequestBody JSONObject json){
        System.out.println("输送线安全交互 仿真测试:"+json);
        jsonObject=new JSONObject();
        jsonArray=new JSONArray();
        jsonObject.put("status","200");
        jsonObject.put("message","");
        JSONObject jsonObject1=new JSONObject();
        jsonObject1.put("pointCode",json.get("lineCode"));
        jsonObject1.put("pointStatus","1");
        if (json.getString("type").equals("2")){
            jsonObject1.put("pointStatus","0");
        }
        jsonObject1.put("stockCode","AAA11");
        jsonArray.add(jsonObject1);
        jsonObject.put("data",jsonArray);
        return new ResponseEntity<>(jsonObject, OK);
    }
}
