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.changeBalance.domain.ChangeBalance;
import com.ruoyi.ss.changeBalance.service.IChangeBalanceService;
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 qzz
 * @date 2024-09-28
 */
@RestController
@RequestMapping("/system/changeBalance")
public class ChangeBalanceController extends BaseController
{
    @Autowired
    private IChangeBalanceService rlChangeBalanceService;

    /**
     * 查询余额变动列表
     */
    @PreAuthorize("@ss.hasPermi('system:changeBalance:list')")
    @GetMapping("/list")
    public TableDataInfo list(ChangeBalance rlChangeBalance)
    {
        startPage();
        List<ChangeBalance> list = rlChangeBalanceService.selectRlChangeBalanceList(rlChangeBalance);
        return getDataTable(list);
    }

    /**
     * 导出余额变动列表
     */
    @PreAuthorize("@ss.hasPermi('system:changeBalance:export')")
    @Log(title = "余额变动", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ChangeBalance rlChangeBalance)
    {
        List<ChangeBalance> list = rlChangeBalanceService.selectRlChangeBalanceList(rlChangeBalance);
        ExcelUtil<ChangeBalance> util = new ExcelUtil<ChangeBalance>(ChangeBalance.class);
        util.exportExcel(response, list, "余额变动数据");
    }

    /**
     * 获取余额变动详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:changeBalance:query')")
    @GetMapping(value = "/{changeId}")
    public AjaxResult getInfo(@PathVariable("changeId") Long changeId)
    {
        return success(rlChangeBalanceService.selectRlChangeBalanceByChangeId(changeId));
    }

    /**
     * 新增余额变动
     */
    @PreAuthorize("@ss.hasPermi('system:changeBalance:add')")
    @Log(title = "余额变动", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ChangeBalance rlChangeBalance)
    {
        return toAjax(rlChangeBalanceService.insertRlChangeBalance(rlChangeBalance));
    }

    /**
     * 修改余额变动
     */
    @PreAuthorize("@ss.hasPermi('system:changeBalance:edit')")
    @Log(title = "余额变动", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ChangeBalance rlChangeBalance)
    {
        return toAjax(rlChangeBalanceService.updateRlChangeBalance(rlChangeBalance));
    }

    /**
     * 删除余额变动
     */
    @PreAuthorize("@ss.hasPermi('system:changeBalance:remove')")
    @Log(title = "余额变动", businessType = BusinessType.DELETE)
	@DeleteMapping("/{changeIds}")
    public AjaxResult remove(@PathVariable Long[] changeIds)
    {
        return toAjax(rlChangeBalanceService.deleteRlChangeBalanceByChangeIds(changeIds));
    }
}
