package com.ruoyi.frequency.wallerecord.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.enums.WalletDetailEnums;
import com.ruoyi.frequency.store.entity.Store;
import com.ruoyi.frequency.store.model.result.StoreCount;
import com.ruoyi.frequency.wallerecord.entity.WalletRecord;
import com.ruoyi.frequency.wallerecord.model.result.WalletRecordCount;
import com.ruoyi.frequency.wallerecord.model.result.WalletRecordTypeListResult;
import com.ruoyi.frequency.wallerecord.service.WalletRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * 钱包记录Controller
 * 
 * @author liwenlong
 * @date 2023-07-20
 */
@RestController
@RequestMapping("/frequency/wallerecord")
public class WalletRecordController extends BaseController
{
    @Autowired
    private WalletRecordService walletRecordService;

    /**
     * 查询钱包记录列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:wallerecord:list')")
    @PostMapping("/list")
    public TableDataInfo<WalletRecord> list(@RequestBody WalletRecord walletRecord)
    {
        startPage();
        List<WalletRecord> list = walletRecordService.selectWalletRecordList(walletRecord);
        return getDataTable(list);
    }


    /**
     * 统计
     */
    @PostMapping("/statistics")
    public AjaxResult statistics(@RequestBody WalletRecord walletRecord)
    {
        WalletRecordCount count = walletRecordService.statistics(walletRecord);
        return AjaxResult.success(count);
    }



    /**
     * 查询收支类型
     */
    @RequestMapping("/walletRecordTypeList")
    public AjaxResult walletRecordTypeList()
    {
        List<WalletRecordTypeListResult> walletRecordTypeListResultList = new ArrayList<>();
        walletRecordTypeListResultList.add(new WalletRecordTypeListResult(WalletDetailEnums.TEAM_COMMISSION));
        walletRecordTypeListResultList.add(new WalletRecordTypeListResult(WalletDetailEnums.WITH_DEDU));
        walletRecordTypeListResultList.add(new WalletRecordTypeListResult(WalletDetailEnums.WITH_FAIL_RETURN));
        walletRecordTypeListResultList.add(new WalletRecordTypeListResult(WalletDetailEnums.RECHARGE_BALANCE));
        walletRecordTypeListResultList.add(new WalletRecordTypeListResult(WalletDetailEnums.ORDER_PAY));

        walletRecordTypeListResultList.add(new WalletRecordTypeListResult(WalletDetailEnums.PLAT_ADD));
        walletRecordTypeListResultList.add(new WalletRecordTypeListResult(WalletDetailEnums.PLAT_SUB));
        walletRecordTypeListResultList.add(new WalletRecordTypeListResult(WalletDetailEnums.ORDER_INCOME));
        walletRecordTypeListResultList.add(new WalletRecordTypeListResult(WalletDetailEnums.ORDER_RETURN));
        walletRecordTypeListResultList.add(new WalletRecordTypeListResult(WalletDetailEnums.PLATFORM_AUTH_PAY));

        walletRecordTypeListResultList.add(new WalletRecordTypeListResult(WalletDetailEnums.HEIGHT_AUTH_PAY));
        walletRecordTypeListResultList.add(new WalletRecordTypeListResult(WalletDetailEnums.BOND_PAY));
        walletRecordTypeListResultList.add(new WalletRecordTypeListResult(WalletDetailEnums.RECHARGE_GIVE_BALANCE));
        walletRecordTypeListResultList.add(new WalletRecordTypeListResult(WalletDetailEnums.ADJUST_PRICE_PAY));
        walletRecordTypeListResultList.add(new WalletRecordTypeListResult(WalletDetailEnums.DEPOSIT_REFUND));


        walletRecordTypeListResultList.add(new WalletRecordTypeListResult(WalletDetailEnums.GIVE_ORDER_PAY));
        walletRecordTypeListResultList.add(new WalletRecordTypeListResult(WalletDetailEnums.MALL_ORDER_PAY));
        walletRecordTypeListResultList.add(new WalletRecordTypeListResult(WalletDetailEnums.GIVE_ORDER_RETURN));
        walletRecordTypeListResultList.add(new WalletRecordTypeListResult(WalletDetailEnums.GIVE_BALANCE));
        walletRecordTypeListResultList.add(new WalletRecordTypeListResult(WalletDetailEnums.BOND_WITHDRAWAL));
        walletRecordTypeListResultList.add(new WalletRecordTypeListResult(WalletDetailEnums.BOND_RECHARGE));

        return AjaxResult.success(walletRecordTypeListResultList);
    }

    /**
     * 导出钱包记录列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:wallerecord:export')")
    @Log(title = "钱包记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(WalletRecord walletRecord)
    {
        List<WalletRecord> list = walletRecordService.selectWalletRecordList(walletRecord);
        ExcelUtil<WalletRecord> util = new ExcelUtil<WalletRecord>(WalletRecord.class);
        return util.exportExcel(list, "钱包记录数据");
    }

    /**
     * 获取钱包记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('frequency:wallerecord:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(walletRecordService.selectWalletRecordById(id));
    }

    /**
     * 新增钱包记录
     */
    @PreAuthorize("@ss.hasPermi('frequency:wallerecord:add')")
    @Log(title = "钱包记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WalletRecord walletRecord)
    {
        return toAjax(walletRecordService.insertWalletRecord(walletRecord));
    }

    /**
     * 修改钱包记录
     */
    @PreAuthorize("@ss.hasPermi('frequency:wallerecord:edit')")
    @Log(title = "钱包记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WalletRecord walletRecord)
    {
        return toAjax(walletRecordService.updateWalletRecord(walletRecord));
    }

    /**
     * 删除钱包记录
     */
    @PreAuthorize("@ss.hasPermi('frequency:wallerecord:remove')")
    @Log(title = "钱包记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(walletRecordService.deleteWalletRecordByIds(ids));
    }
}
