package com.yiqi.admin.controller.order;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.yiqi.common.constant.UrlConstants;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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.yiqi.common.annotation.Log;
import com.yiqi.common.core.controller.BaseController;
import com.yiqi.common.core.domain.AjaxResult;
import com.yiqi.common.enums.BusinessType;
import com.yiqi.order.domain.OrderPurchaseGoodsItem;
import com.yiqi.order.service.IOrderPurchaseGoodsItemService;
import com.yiqi.common.utils.poi.ExcelUtil;
import com.yiqi.common.core.page.TableDataInfo;

/**
 * 商品订单商品信息Controller
 *
 * @author ruoyi
 * @date 2023-10-20
 */
@Api(tags = "管理后台 - 进出货商品订单商品信息")
@RestController
@RequestMapping(UrlConstants.managerApi + "/order/purchaseGoodsItem")
public class OrderPurchaseGoodsItemController extends BaseController {
    @Autowired
    private IOrderPurchaseGoodsItemService orderPurchaseGoodsItemService;

    /**
     * 查询商品订单商品信息列表
     */
    @PreAuthorize("@ss.hasPermi('order:purchaseGoodsItem:list')")
    @GetMapping("/list")
    @ApiOperation(value = "查询商品订单商品信息列表")
    public TableDataInfo list(OrderPurchaseGoodsItem orderPurchaseGoodsItem) {
        startPage();
        List<OrderPurchaseGoodsItem> list = orderPurchaseGoodsItemService.selectOrderPurchaseGoodsItemList(orderPurchaseGoodsItem);
        return getDataTable(list);
    }

    /**
     * 导出商品订单商品信息列表
     */
    @PreAuthorize("@ss.hasPermi('order:purchaseGoodsItem:export')")
    @Log(title = "商品订单商品信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation(value = "导出商品订单商品信息列表")
    public void export(HttpServletResponse response, OrderPurchaseGoodsItem orderPurchaseGoodsItem) {
        List<OrderPurchaseGoodsItem> list = orderPurchaseGoodsItemService.selectOrderPurchaseGoodsItemList(orderPurchaseGoodsItem);
        ExcelUtil<OrderPurchaseGoodsItem> util = new ExcelUtil<OrderPurchaseGoodsItem>(OrderPurchaseGoodsItem. class);
        util.exportExcel(response, list, "商品订单商品信息数据");
    }

    /**
     * 获取商品订单商品信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('order:purchaseGoodsItem:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "获取商品订单商品信息详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(orderPurchaseGoodsItemService.selectOrderPurchaseGoodsItemById(id));
    }

    /**
     * 新增商品订单商品信息
     */
    @PreAuthorize("@ss.hasPermi('order:purchaseGoodsItem:add')")
    @Log(title = "商品订单商品信息", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增商品订单商品信息")
    public AjaxResult add(@RequestBody OrderPurchaseGoodsItem orderPurchaseGoodsItem) {
        orderPurchaseGoodsItem.setCreateById(getUserId());
        orderPurchaseGoodsItem.setCreateBy(getUsername());
        return toAjax(orderPurchaseGoodsItemService.insertOrderPurchaseGoodsItem(orderPurchaseGoodsItem));
    }

    /**
     * 修改商品订单商品信息
     */
    @PreAuthorize("@ss.hasPermi('order:purchaseGoodsItem:edit')")
    @Log(title = "商品订单商品信息", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改商品订单商品信息")
    public AjaxResult edit(@RequestBody OrderPurchaseGoodsItem orderPurchaseGoodsItem) {
        orderPurchaseGoodsItem.setUpdateById(getUserId());
        orderPurchaseGoodsItem.setUpdateBy(getUsername());
        return toAjax(orderPurchaseGoodsItemService.updateOrderPurchaseGoodsItem(orderPurchaseGoodsItem));
    }

    /**
     * 删除商品订单商品信息
     */
    @PreAuthorize("@ss.hasPermi('order:purchaseGoodsItem:remove')")
    @Log(title = "商品订单商品信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation(value = "删除商品订单商品信息")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(orderPurchaseGoodsItemService.deleteOrderPurchaseGoodsItemByIds(ids));
    }

}
