package com.ruoyi.system.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.system.domain.Order;
import com.ruoyi.system.domain.ShopGoods;
import com.ruoyi.system.domain.ShopGoodsSku;
import com.ruoyi.system.mapper.OrderMapper;
import com.ruoyi.system.mapper.ShopGoodsMapper;
import com.ruoyi.system.mapper.ShopGoodsSkuMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MachineApiServiceImpl {
    @Autowired
    private ShopGoodsMapper shopGoodsMapper;
    @Autowired
    private OrderMapper orderMapper;
    @Autowired
    private ShopGoodsSkuMapper shopGoodsSkuMapper;
    public String shopGoodsUpdate(JSONObject jsonObject) {
        String shopID = jsonObject.getString("shopID");
        String skuIDs = jsonObject.getString("skuID");
        List<String> skuIds = JSONObject.parseArray(skuIDs, String.class);
        String robotID = jsonObject.getString("robotID");
        String status = jsonObject.getString("status");
        if("11".equals(status)){
            status ="2";
        }else{
            status ="1";
        }
        shopGoodsSkuMapper.updateSkuStatus(skuIds, robotID, shopID, status);

        return "0";

    }

    public String updateOrder(JSONObject jsonObject) {
        String orderID = jsonObject.getString("orderID");
        String status = jsonObject.getString("status");
        Order order = new Order();
        order.setId(orderID);
        order.setState(status);
        orderMapper.updateOrder(order);
        return "0";

    }
}
