package com.ruoyi.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.cs.domain.CsTransferRecord;
import com.ruoyi.cs.domain.template.CsTransferRecordTemplate;
import com.ruoyi.cs.service.ICsTransferRecordService;
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 ruoyi
 * @date 2024-05-29
 */
@RestController
@RequestMapping("/cs/csTransferRecord")
public class CsTransferRecordController extends BaseController
{
    @Resource
    private ICsTransferRecordService csTransferRecordService;

    /**
     * 查询转单记录列表
     */
    @PreAuthorize("@ss.hasPermi('cs:csTransferRecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(CsTransferRecord csTransferRecord)
    {
        startPage();
        csTransferRecord.setDelFlag("0");
        List<CsTransferRecord> list = csTransferRecordService.selectCsTransferRecordList(csTransferRecord);
        return getDataTable(list);
    }

    /**
     * 导出转单记录列表
     */
    @PreAuthorize("@ss.hasPermi('cs:csTransferRecord:export')")
    @Log(title = "转单记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CsTransferRecord csTransferRecord)
    {
        csTransferRecord.setDelFlag("0");
        List<CsTransferRecord> list = csTransferRecordService.selectCsTransferRecordList(csTransferRecord);
        ExcelUtil<CsTransferRecord> util = new ExcelUtil<CsTransferRecord>(CsTransferRecord.class);
        util.exportExcel(response, list, "转单记录数据");
    }

    /**
     * 导出转单记录列表模版
     */
    @Log(title = "转单记录模版", businessType = BusinessType.EXPORT)
    @PostMapping("/exportTemplate")
    public void exportTemplate(HttpServletResponse response)
    {
        ExcelUtil<CsTransferRecordTemplate> util = new ExcelUtil<CsTransferRecordTemplate>(CsTransferRecordTemplate.class);
        util.exportExcel(response, null, "转单记录数据模版");
    }

    /**
     * 获取转单记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('cs:csTransferRecord:query')")
    @GetMapping(value = "/{transferRecordId}")
    public AjaxResult getInfo(@PathVariable("transferRecordId") String transferRecordId)
    {
        return AjaxResult.success(csTransferRecordService.selectCsTransferRecordByTransferRecordId(transferRecordId));
    }

    /**
     * 新增转单记录
     */
    @PreAuthorize("@ss.hasPermi('cs:csTransferRecord:add')")
    @Log(title = "转单记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CsTransferRecord csTransferRecord)
    {
        return toAjax(csTransferRecordService.insertCsTransferRecord(csTransferRecord));
    }

    /**
     * 修改转单记录
     */
    @PreAuthorize("@ss.hasPermi('cs:csTransferRecord:edit')")
    @Log(title = "转单记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CsTransferRecord csTransferRecord)
    {
        return toAjax(csTransferRecordService.updateCsTransferRecord(csTransferRecord));
    }

    /**
     * 删除转单记录
     */
    @PreAuthorize("@ss.hasPermi('cs:csTransferRecord:remove')")
    @Log(title = "转单记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{transferRecordIds}")
    public AjaxResult remove(@PathVariable String[] transferRecordIds)
    {
        return toAjax(csTransferRecordService.deleteCsTransferRecordByTransferRecordIds(transferRecordIds));
    }
}
