package com.zbf.web.controller.system;


import com.zbf.common.annotation.Log;
import com.zbf.common.core.controller.BaseController;
import com.zbf.common.core.domain.AjaxResult;
import com.zbf.common.core.page.TableDataInfo;
import com.zbf.common.enums.BusinessType;
import com.zbf.common.utils.poi.ExcelUtil;
import com.zbf.system.domain.TransferOrder;
import com.zbf.system.service.ITransferOrderService;
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 tony
 * @date 2024-11-03
 */
@RestController
@RequestMapping("/system/order")
public class TransferOrderController extends BaseController {
    @Autowired
    private ITransferOrderService transferOrderService;

    /**
     * 查询调拨单
     * 列表
     */
    @PreAuthorize("@ss.hasPermi('system:order:list')")
    @GetMapping("/list")
    public TableDataInfo list(TransferOrder transferOrder) {
        startPage();
        List<TransferOrder> list = transferOrderService.selectTransferOrderList(transferOrder);
        return getDataTable(list);
    }

    /**
     * 导出调拨单
     * 列表
     */
    @PreAuthorize("@ss.hasPermi('system:order:export')")
    @Log(title = "调拨单 ", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TransferOrder transferOrder) {
        List<TransferOrder> list = transferOrderService.selectTransferOrderList(transferOrder);
        ExcelUtil<TransferOrder> util = new ExcelUtil<TransferOrder>(TransferOrder.class);
        util.exportExcel(response, list, "调拨单数据");
    }

    /**
     * 获取调拨单
     * 详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:order:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(transferOrderService.selectTransferOrderById(id));
    }

    /**
     * 新增调拨单
     */
    @PreAuthorize("@ss.hasPermi('system:order:add')")
    @Log(title = "调拨单 ", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TransferOrder transferOrder) {
        return toAjax(transferOrderService.insertTransferOrder(transferOrder));
    }

    /**
     * 修改调拨单
     */
    @PreAuthorize("@ss.hasPermi('system:order:edit')")
    @Log(title = "调拨单 ", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TransferOrder transferOrder) {
        return toAjax(transferOrderService.updateTransferOrder(transferOrder));
    }

    /**
     * 删除调拨单
     */
    @PreAuthorize("@ss.hasPermi('system:order:remove')")
    @Log(title = "调拨单 ", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(transferOrderService.deleteTransferOrderByIds(ids));
    }

    /**
     * 启用
     */
    @PreAuthorize("@ss.hasPermi('system:order:remove')")
    @Log(title = "调拨单 ", businessType = BusinessType.UPDATE)
    @DeleteMapping("/disable/{ids}")
    public AjaxResult disable(@PathVariable Long[] ids) {
        return toAjax(transferOrderService.disabledTransferOrderByIds(ids));
    }

    /**
     * 禁用
     */
    @PreAuthorize("@ss.hasPermi('system:order:edit')")
    @Log(title = "调拨单 ", businessType = BusinessType.UPDATE)
    @DeleteMapping("/enable/{ids}")
    public AjaxResult enable(@PathVariable Long[] ids) {
        return toAjax(transferOrderService.enableTransferOrderByIds(ids));
    }

    /**
     * 修改状态
     */
    @PreAuthorize("@ss.hasPermi('system:order:edit')")
    @Log(title = "调拨单 ", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody TransferOrder transferOrder) {
        return toAjax(transferOrderService.updateStatus(transferOrder));
    }
}


