package com.ximai.mes.od.controller;

import com.ximai.common.annotation.Log;
import com.ximai.common.core.controller.BaseController;
import com.ximai.common.core.domain.AjaxResult;
import com.ximai.common.core.page.TableDataInfo;
import com.ximai.common.enums.BusinessType;
import com.ximai.mes.od.domain.OdSalesOrderProductDetail;
import com.ximai.mes.od.service.IOdSalesOrderProductDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 销售订单产品详情Controller
 *
 * @author yinjinlu
 * @date 2024-01-18
 */
@RestController
@RequestMapping("/od/salesOrderProduct")
public class OdSalesOrderProductDetailController extends BaseController {
    @Autowired
    private IOdSalesOrderProductDetailService odSalesOrderProductDetailService;

    /**
     * 查询销售订单产品详情列表
     */
    @PreAuthorize("@ss.hasPermi('od:salesOrderProduct:list')")
    @GetMapping("/list")
    public TableDataInfo list(OdSalesOrderProductDetail odSalesOrderProductDetail) {
        startPage();
        List<OdSalesOrderProductDetail> list = odSalesOrderProductDetailService.selectOdSalesOrderProductDetailList(odSalesOrderProductDetail);
        return getDataTable(list);
    }

    /**
     * 获取销售订单产品详情详细信息
     */
    @PreAuthorize("@ss.hasPermi('od:salesOrderProduct:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(odSalesOrderProductDetailService.selectOdSalesOrderProductDetailById(id));
    }

    /**
     * 新增销售订单产品详情
     */
    @PreAuthorize("@ss.hasPermi('od:salesOrderProduct:add')")
    @Log(title = "销售订单产品详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OdSalesOrderProductDetail odSalesOrderProductDetail) {
        return toAjax(odSalesOrderProductDetailService.insertOdSalesOrderProductDetail(odSalesOrderProductDetail));
    }

    /**
     * 修改销售订单产品详情
     */
    @PreAuthorize("@ss.hasPermi('od:salesOrderProduct:edit')")
    @Log(title = "销售订单产品详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OdSalesOrderProductDetail odSalesOrderProductDetail) {
        return toAjax(odSalesOrderProductDetailService.updateOdSalesOrderProductDetail(odSalesOrderProductDetail));
    }

    /**
     * 删除销售订单产品详情
     */
    @PreAuthorize("@ss.hasPermi('od:salesOrderProduct:remove')")
    @Log(title = "销售订单产品详情", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(odSalesOrderProductDetailService.deleteOdSalesOrderProductDetailByIds(ids));
    }
}
