package com.ruoyi.order.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
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.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.order.domain.TbOrderDetail;
import com.ruoyi.order.service.ITbOrderDetailService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 单据明细Controller
 * 
 * @author 原动力
 * @date 2023-05-24
 */
@RestController
@RequestMapping("/order/detail")
public class TbOrderDetailController extends BaseController
{
    @Autowired
    private ITbOrderDetailService tbOrderDetailService;

    /**
     * 查询单据明细列表
     */
    @PreAuthorize("@ss.hasPermi('order:detail:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbOrderDetail tbOrderDetail)
    {
        startPage();
        List<TbOrderDetail> list = tbOrderDetailService.selectTbOrderDetailList(tbOrderDetail);
        return getDataTable(list);
    }

    /**
     * 导出单据明细列表
     */
    @PreAuthorize("@ss.hasPermi('order:detail:export')")
    @Log(title = "单据明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbOrderDetail tbOrderDetail)
    {
        List<TbOrderDetail> list = tbOrderDetailService.selectTbOrderDetailList(tbOrderDetail);
        ExcelUtil<TbOrderDetail> util = new ExcelUtil<TbOrderDetail>(TbOrderDetail.class);
        util.exportExcel(response, list, "单据明细数据");
    }

    /**
     * 获取单据明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('order:detail:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tbOrderDetailService.selectTbOrderDetailById(id));
    }

    /**
     * 新增单据明细
     */
    @PreAuthorize("@ss.hasPermi('order:detail:add')")
    @Log(title = "单据明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbOrderDetail tbOrderDetail)
    {
        return toAjax(tbOrderDetailService.insertTbOrderDetail(tbOrderDetail));
    }

    /**
     * 修改单据明细
     */
    @PreAuthorize("@ss.hasPermi('order:detail:edit')")
    @Log(title = "单据明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbOrderDetail tbOrderDetail)
    {
        return toAjax(tbOrderDetailService.updateTbOrderDetail(tbOrderDetail));
    }

    /**
     * 删除单据明细
     */
    @PreAuthorize("@ss.hasPermi('order:detail:remove')")
    @Log(title = "单据明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbOrderDetailService.deleteTbOrderDetailByIds(ids));
    }
}
