package com.ruoyi.frequency.integralrecord.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.integralrecord.entity.IntegralRecord;
import com.ruoyi.frequency.integralrecord.service.IntegralRecordService;
import com.ruoyi.frequency.wallerecord.entity.WalletRecord;
import com.ruoyi.frequency.wallerecord.model.result.WalletRecordCount;
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 2024-01-29
 */
@RestController
@RequestMapping("/frequency/integralrecord")
public class IntegralRecordController extends BaseController
{
    @Autowired
    private IntegralRecordService integralRecordService;

    /**
     * 查询积分记录列表
     */
//    @PreAuthorize("@ss.hasPermi('frequency:integralrecord:list')")
    @PostMapping("/list")
    public TableDataInfo<IntegralRecord> list(@RequestBody IntegralRecord integralRecord)
    {
        startPage();
        List<IntegralRecord> list = integralRecordService.selectIntegralRecordList(integralRecord);
        return getDataTable(list);
    }


    /**
     * 统计
     */
    @PostMapping("/statistics")
    public AjaxResult statistics(@RequestBody IntegralRecord integralRecord)
    {
        WalletRecordCount count = integralRecordService.statistics(integralRecord);
        return AjaxResult.success(count);
    }


    /**
     * 导出积分记录列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:integralrecord:export')")
    @Log(title = "积分记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(IntegralRecord integralRecord)
    {
        List<IntegralRecord> list = integralRecordService.selectIntegralRecordList(integralRecord);
        ExcelUtil<IntegralRecord> util = new ExcelUtil<IntegralRecord>(IntegralRecord.class);
        return util.exportExcel(list, "积分记录数据");
    }

    /**
     * 获取积分记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('frequency:integralrecord:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult<IntegralRecord> getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(integralRecordService.selectIntegralRecordById(id));
    }

    /**
     * 新增积分记录
     */
    @PreAuthorize("@ss.hasPermi('frequency:integralrecord:add')")
    @Log(title = "积分记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody IntegralRecord integralRecord)
    {
        return toAjax(integralRecordService.insertIntegralRecord(integralRecord));
    }

    /**
     * 修改积分记录
     */
    @PreAuthorize("@ss.hasPermi('frequency:integralrecord:edit')")
    @Log(title = "积分记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody IntegralRecord integralRecord)
    {
        return toAjax(integralRecordService.updateIntegralRecord(integralRecord));
    }

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