package com.pj.tb_goods_cart;

import com.pj.tb_goods_cart.dto.GoodsCartInfoDto;
import com.pj.tb_goods_cart.vo.GoodsCartVo;
import com.pj.utils.sg.AjaxJson;
import com.pj.utils.so.SoMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;


/**
 * Controller: tb_goods_cart -- 购物车
 *
 * @author qzy
 */
@RestController
@RequestMapping("/app/TbGoodsCart/")
public class TbGoodsCartApiController {

    /**
     * 底层 Service 对象
     */
    @Autowired
    TbGoodsCartService tbGoodsCartService;


    /**
     * 查 - 根据id
     */
    @RequestMapping("getById")
//		@SaCheckPermission(TbGoodsCart.PERMISSION_CODE)
    public AjaxJson getById(String id) {
        TbGoodsCart t = tbGoodsCartService.getById(id);
        return AjaxJson.getSuccessData(t);
    }

    /**
     * 查集合 - 根据条件（参数为空时代表忽略指定条件）
     */
    @RequestMapping("getList")
    public AjaxJson getList() {
        SoMap so = SoMap.getRequestSoMap();
        return AjaxJson.getSuccessData(tbGoodsCartService.getList(so));
    }

    /**
     * 添加购物车
     */
    @RequestMapping("addGoodsInShopCart")
    public AjaxJson addGoodsInShopCart(@Validated @RequestBody GoodsCartInfoDto goodsCartInfoDto) {
        AjaxJson ajaxJson = tbGoodsCartService.addGoodsInShopCart(goodsCartInfoDto);
        return ajaxJson;
    }

    /**
     * 清理购物车,可批量
     */
    @RequestMapping("cleanCart/{ids}")
    public AjaxJson cleanCart(@PathVariable Long[] ids) {
        return AjaxJson.getSuccessData(tbGoodsCartService.removeByIds(Arrays.asList(ids)));
    }


}
