package com.ruoyi.web.controller.system;

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.ss.transferDetail.domain.TransferDetail;
import com.ruoyi.ss.transferDetail.domain.TransferDetailQuery;
import com.ruoyi.ss.transferDetail.domain.TransferDetailVO;
import com.ruoyi.ss.transferDetail.service.ITransferDetailService;
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 ruoyi
 * @date 2024-08-09
 */
@RestController
@RequestMapping("/system/transferDetail")
public class TransferDetailController extends BaseController
{
    @Autowired
    private ITransferDetailService transferDetailService;

    /**
     * 查询转账明细列表
     */
    @PreAuthorize("@ss.hasPermi('system:transferDetail:list')")
    @GetMapping("/list")
    public TableDataInfo list(TransferDetailQuery query)
    {
        startPage();
        startOrderBy();
        List<TransferDetailVO> list = transferDetailService.selectTransferDetailList(query);
        return getDataTable(list);
    }

    /**
     * 导出转账明细列表
     */
    @PreAuthorize("@ss.hasPermi('system:transferDetail:export')")
    @Log(title = "转账明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TransferDetailQuery query)
    {
        List<TransferDetailVO> list = transferDetailService.selectTransferDetailList(query);
        ExcelUtil<TransferDetailVO> util = new ExcelUtil<TransferDetailVO>(TransferDetailVO.class);
        util.exportExcel(response, list, "转账明细数据");
    }

    /**
     * 获取转账明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:transferDetail:query')")
    @GetMapping(value = "/{detailId}")
    public AjaxResult getInfo(@PathVariable("detailId") Long detailId)
    {
        return success(transferDetailService.selectTransferDetailByDetailId(detailId));
    }

    /**
     * 新增转账明细
     */
    @PreAuthorize("@ss.hasPermi('system:transferDetail:add')")
    @Log(title = "转账明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TransferDetail transferDetail)
    {
        return toAjax(transferDetailService.insertTransferDetail(transferDetail));
    }

    /**
     * 修改转账明细
     */
    @PreAuthorize("@ss.hasPermi('system:transferDetail:edit')")
    @Log(title = "转账明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TransferDetail transferDetail)
    {
        return toAjax(transferDetailService.updateTransferDetail(transferDetail));
    }

    /**
     * 删除转账明细
     */
    @PreAuthorize("@ss.hasPermi('system:transferDetail:remove')")
    @Log(title = "转账明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{detailIds}")
    public AjaxResult remove(@PathVariable Long[] detailIds)
    {
        return toAjax(transferDetailService.deleteTransferDetailByDetailIds(detailIds));
    }
}
