package com.ruoyi.frequency.illegaldeductionrecord.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.frequency.illegaldeductionrecord.entity.IllegalDeductionRecord;
import com.ruoyi.frequency.illegaldeductionrecord.service.IllegalDeductionRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 扣款记录Controller
 * 
 * @author liwenlong
 * @date 2023-11-08
 */
@RestController
@RequestMapping("/frequency/illegaldeductionrecord")
public class IllegalDeductionRecordController extends BaseController
{
    @Autowired
    private IllegalDeductionRecordService illegalDeductionRecordService;

    /**
     * 查询扣款记录列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:illegaldeductionrecord:list')")
    @PostMapping("/list")
    public TableDataInfo<IllegalDeductionRecord> list(@RequestBody IllegalDeductionRecord illegalDeductionRecord)
    {
        startPage();
        List<IllegalDeductionRecord> list = illegalDeductionRecordService.selectIllegalDeductionRecordList(illegalDeductionRecord);
        return getDataTable(list);
    }

    /**
     * 导出扣款记录列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:illegaldeductionrecord:export')")
    @Log(title = "扣款记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(IllegalDeductionRecord illegalDeductionRecord)
    {
        List<IllegalDeductionRecord> list = illegalDeductionRecordService.selectIllegalDeductionRecordList(illegalDeductionRecord);
        ExcelUtil<IllegalDeductionRecord> util = new ExcelUtil<IllegalDeductionRecord>(IllegalDeductionRecord.class);
        return util.exportExcel(list, "扣款记录数据");
    }

    /**
     * 获取扣款记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('frequency:illegaldeductionrecord:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult<IllegalDeductionRecord> getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(illegalDeductionRecordService.selectIllegalDeductionRecordById(id));
    }

    /**
     * 新增扣款记录
     */
    @PreAuthorize("@ss.hasPermi('frequency:illegaldeductionrecord:add')")
    @Log(title = "扣款记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody IllegalDeductionRecord illegalDeductionRecord)
    {
        return toAjax(illegalDeductionRecordService.insertIllegalDeductionRecord(illegalDeductionRecord));
    }

    /**
     * 修改扣款记录
     */
    @PreAuthorize("@ss.hasPermi('frequency:illegaldeductionrecord:edit')")
    @Log(title = "扣款记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody IllegalDeductionRecord illegalDeductionRecord)
    {
        return toAjax(illegalDeductionRecordService.updateIllegalDeductionRecord(illegalDeductionRecord));
    }

    /**
     * 删除扣款记录
     */
    @PreAuthorize("@ss.hasPermi('frequency:illegaldeductionrecord:remove')")
    @Log(title = "扣款记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}/{delFlag}")
    public AjaxResult remove(@PathVariable("ids") Long[] ids,@PathVariable("delFlag") Integer delFlag)
    {
        return toAjax(illegalDeductionRecordService.deleteIllegalDeductionRecordByIds(ids,delFlag));
    }

}
