package com.ruoyi.web.controller.coffee;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.vo.ResultVo;
import com.ruoyi.system.service.impl.MachineApiServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/v1")
@Slf4j
public class MachineApiController {
    @Autowired
    private MachineApiServiceImpl machineApiService;
    @PostMapping("/down/material/update")
    public ResultVo shopGoodsUpdate(@RequestBody String body){
        log.info("/down/material/update 请求内容为 【{}】",body);
        JSONObject jsonObject = JSONObject.parseObject(body);
        return ResultVo.success(machineApiService.shopGoodsUpdate(jsonObject));
    }
    @PostMapping("/down/order/update")
    public ResultVo updateOrder(@RequestBody String body){
        log.info("/down/order/update 请求内容为 【{}】",body);
        JSONObject jsonObject = JSONObject.parseObject(body);
        return ResultVo.success(machineApiService.updateOrder(jsonObject));
    }
    @PostMapping("/down/robot/status")
    public ResultVo robotUpdate(@RequestBody String body){
        log.info("/down/robot/status 请求内容为 【{}】",body);
        JSONObject jsonObject = JSONObject.parseObject(body);
        try{
            return ResultVo.success(machineApiService.robotUpdate(jsonObject));
        }catch (Exception e){
            return ResultVo.error(e.getMessage());
        }


    }
    @GetMapping("/testOrder")
    public void testOrder(String orderId){
        machineApiService.testOrder(orderId);
    }
    @GetMapping("/testOrderUpdate")
    public void testOrderUpdate(String orderId){
        machineApiService.testOrderUpdate(orderId);
    }
}
