package com.jjt.order.controller;

import com.jjt.common.annotation.Log;
import com.jjt.common.core.controller.BaseController;
import com.jjt.common.core.domain.AjaxResult;
import com.jjt.common.core.page.TableDataInfo;
import com.jjt.common.enums.BusinessType;
import com.jjt.common.utils.poi.ExcelUtil;
import com.jjt.order.domain.TwinOrder;
import com.jjt.order.service.ITwinOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 销售订单信息Controller
 *
 * @author wukai
 * @date 2025-01-16
 */
@Api(tags = "销售订单信息")
@RestController
@RequestMapping("/order/order")
public class TwinOrderController extends BaseController {
    @Resource
    private ITwinOrderService twinOrderService;

    /**
     * 查询销售订单信息列表
     */
    @ApiOperation("查询销售订单信息列表")
    @PreAuthorize("@ss.hasPermi('order:order:list')")
    @GetMapping("/list")
    public TableDataInfo list(TwinOrder twinOrder) {
        startPage();
        List<TwinOrder> list = twinOrderService.selectTwinOrderList(twinOrder);
        return getDataTable(list);
    }

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

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

    /**
     * 新增销售订单信息
     */
    @ApiOperation("新增销售订单信息")
    @PreAuthorize("@ss.hasPermi('order:order:add')")
    @Log(title = "销售订单信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TwinOrder twinOrder) {
        return toAjax(twinOrderService.insertTwinOrder(twinOrder));
    }

    /**
     * 修改销售订单信息
     */
    @ApiOperation("修改销售订单信息")
    @PreAuthorize("@ss.hasPermi('order:order:edit')")
    @Log(title = "销售订单信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TwinOrder twinOrder) {
        return toAjax(twinOrderService.updateTwinOrder(twinOrder));
    }

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