package com.game.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.game.common.core.domain.R;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
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 com.game.common.annotation.Log;
import com.game.common.core.controller.BaseController;
import com.game.common.core.domain.AjaxResult;
import com.game.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.game.business.domain.ShopSubOrder;
import com.game.business.service.IShopSubOrderService;
import com.game.common.utils.poi.ExcelUtil;
import com.game.common.core.page.TableDataInfo;

/**
 * 订单商品Controller
 * 
 * @author game
 * @date 2024-09-06
 */
@RestController
@RequestMapping("/business/subOrder")
@Api(value = "ShopSubOrderController", description = "订单商品接口", tags = {"订单商品"})
public class ShopSubOrderController extends BaseController
{
    @Autowired
    private IShopSubOrderService shopSubOrderService;

    /**
     * 查询订单商品列表
     */
    @PreAuthorize("@ss.hasPermi('business:order:list')")
    @GetMapping("/list")
    @ApiOperation(value = "查询订单商品列表", notes = "获取订单商品列表")
    public TableDataInfo<ShopSubOrder> list(ShopSubOrder shopSubOrder)
    {
        startPage();
        List<ShopSubOrder> list = shopSubOrderService.selectShopSubOrderList(shopSubOrder);
        return getDataTable(list);
    }

    /**
     * 导出订单商品列表
     */
    @PreAuthorize("@ss.hasPermi('business:order:export')")
    @Log(title = "订单商品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation(value = "导出订单商品列表", notes = "导出订单商品列表")
    public void export(HttpServletResponse response, ShopSubOrder shopSubOrder)
    {
        List<ShopSubOrder> list = shopSubOrderService.selectShopSubOrderList(shopSubOrder);
        ExcelUtil<ShopSubOrder> util = new ExcelUtil<ShopSubOrder>(ShopSubOrder.class);
        util.exportExcel(response, list, "订单商品数据");
    }

    /**
     * 获取订单商品详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:order:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "获取订单商品详细信息", notes = "获取订单商品详细信息")
    public R<ShopSubOrder> getInfo(@PathVariable("id") Long id)
    {
        return R.ok(shopSubOrderService.selectShopSubOrderById(id));
    }

    /**
     * 新增订单商品
     */
    @PreAuthorize("@ss.hasPermi('business:order:add')")
    @Log(title = "订单商品", businessType = BusinessType.INSERT)
    @ApiOperation(value = "新增订单商品", notes = "新增订单商品")
    @PostMapping
    public R add(@RequestBody ShopSubOrder shopSubOrder)
    {
        return R.ok(shopSubOrderService.insertShopSubOrder(shopSubOrder));
    }

    /**
     * 修改订单商品
     */
    @PreAuthorize("@ss.hasPermi('business:order:edit')")
    @Log(title = "订单商品", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "修改订单商品", notes = "修改订单商品")
    @PutMapping
    public R edit(@RequestBody ShopSubOrder shopSubOrder)
    {
        return R.ok(shopSubOrderService.updateShopSubOrder(shopSubOrder));
    }

    /**
     * 删除订单商品
     */
    @PreAuthorize("@ss.hasPermi('business:order:remove')")
    @Log(title = "订单商品", businessType = BusinessType.DELETE)
    @ApiOperation(value = "删除订单商品", notes = "删除订单商品")
	@DeleteMapping("/{ids}")
    public R remove(@PathVariable Long[] ids)
    {
        return R.ok(shopSubOrderService.deleteShopSubOrderByIds(ids));
    }
}
