package com.jjt.order.controller;

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

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
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.jjt.common.annotation.Log;
import com.jjt.common.core.controller.BaseController;
import com.jjt.common.core.domain.AjaxResult;
import com.jjt.common.enums.BusinessType;
import com.jjt.order.domain.TwinOrderDetail;
import com.jjt.order.service.ITwinOrderDetailService;
import com.jjt.common.utils.poi.ExcelUtil;
import com.jjt.common.core.page.TableDataInfo;

/**
 * 销售订单明细信息Controller
 *
 * @author wukai
 * @date 2025-01-16
 */
@Api(tags="销售订单明细信息")
@RestController
@RequestMapping("/order/detail")
public class TwinOrderDetailController extends BaseController{
    @Resource
    private ITwinOrderDetailService twinOrderDetailService;

    /**
     * 查询销售订单明细信息列表
     */
    @ApiOperation("查询销售订单明细信息列表")
    @PreAuthorize("@ss.hasPermi('order:detail:list')")
    @GetMapping("/list")
    public TableDataInfo list(TwinOrderDetail twinOrderDetail)
    {
        startPage();
        List<TwinOrderDetail> list = twinOrderDetailService.selectTwinOrderDetailList(twinOrderDetail);
        return getDataTable(list);
    }

    /**
     * 导出销售订单明细信息列表
     */
    @ApiOperation("导出销售订单明细信息列表")
    @PreAuthorize("@ss.hasPermi('order:detail:export')")
    @Log(title = "销售订单明细信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TwinOrderDetail twinOrderDetail)
    {
        List<TwinOrderDetail> list = twinOrderDetailService.selectTwinOrderDetailList(twinOrderDetail);
        ExcelUtil<TwinOrderDetail> util = new ExcelUtil<TwinOrderDetail>(TwinOrderDetail.class);
        util.exportExcel(response, list, "销售订单明细信息数据");
    }

    /**
     * 获取销售订单明细信息详细信息
     */
    @ApiOperation("获取销售订单明细信息详细信息")
    @PreAuthorize("@ss.hasPermi('order:detail:query')")
    @GetMapping(value = "/{odId}")
    public AjaxResult getInfo(@PathVariable("odId") Long odId)
    {
        return success(twinOrderDetailService.selectTwinOrderDetailByOdId(odId));
    }

    /**
     * 新增销售订单明细信息
     */
    @ApiOperation("新增销售订单明细信息")
    @PreAuthorize("@ss.hasPermi('order:detail:add')")
    @Log(title = "销售订单明细信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TwinOrderDetail twinOrderDetail)
    {
        return toAjax(twinOrderDetailService.insertTwinOrderDetail(twinOrderDetail));
    }

    /**
     * 修改销售订单明细信息
     */
    @ApiOperation("修改销售订单明细信息")
    @PreAuthorize("@ss.hasPermi('order:detail:edit')")
    @Log(title = "销售订单明细信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TwinOrderDetail twinOrderDetail)
    {
        return toAjax(twinOrderDetailService.updateTwinOrderDetail(twinOrderDetail));
    }

    /**
     * 删除销售订单明细信息
     */
    @ApiOperation("删除销售订单明细信息")
    @PreAuthorize("@ss.hasPermi('order:detail:remove')")
    @Log(title = "销售订单明细信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{odIds}")
    public AjaxResult remove(@PathVariable Long[] odIds)
    {
        return toAjax(twinOrderDetailService.deleteTwinOrderDetailByOdIds(odIds));
    }
}
