package com.flossom.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.flossom.common.core.domain.R;
import com.flossom.common.core.domain.entity.WxUserIntegralLog;
import com.flossom.common.core.utils.poi.ExcelUtil;
import com.flossom.common.core.web.controller.BaseController;
import com.flossom.common.core.web.domain.AjaxResult;
import com.flossom.common.core.web.page.TableDataInfo;
import com.flossom.common.log.annotation.Log;
import com.flossom.common.log.enums.BusinessType;
import com.flossom.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.flossom.system.service.IWxUserIntegralLogService;

/**
 * 微信用户积分流水Controller
 *
 * @author flossom
 * @date 2023-12-14
 */
@RestController
@RequestMapping("/integralLog")
public class WxUserIntegralLogController extends BaseController {
    @Autowired
    private IWxUserIntegralLogService wxUserIntegralLogService;

    /**
     * 查询微信用户积分流水列表
     */
    @RequiresPermissions("system:integralLog:list")
    @GetMapping("/list")
    public TableDataInfo list(WxUserIntegralLog wxUserIntegralLog) {
        startPage();
        List<WxUserIntegralLog> list = wxUserIntegralLogService.selectWxUserIntegralLogList(wxUserIntegralLog);
        return getDataTable(list);
    }

    /**
     * 导出微信用户积分流水列表
     */
    @RequiresPermissions("system:integralLog:export")
    @Log(title = "微信用户积分流水", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WxUserIntegralLog wxUserIntegralLog) {
        List<WxUserIntegralLog> list = wxUserIntegralLogService.selectWxUserIntegralLogList(wxUserIntegralLog);
        ExcelUtil<WxUserIntegralLog> util = new ExcelUtil<WxUserIntegralLog>(WxUserIntegralLog.class);
        util.exportExcel(response, list, "微信用户积分流水数据");
    }

    /**
     * 获取微信用户积分流水详细信息
     */
    @RequiresPermissions("system:integralLog:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(wxUserIntegralLogService.selectWxUserIntegralLogById(id));
    }

    /**
     * 新增微信用户积分流水
     */
    @RequiresPermissions("system:integralLog:add")
    @Log(title = "微信用户积分流水", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WxUserIntegralLog wxUserIntegralLog) {
        return toAjax(wxUserIntegralLogService.insertWxUserIntegralLog(wxUserIntegralLog));
    }

    /**
     * 修改微信用户积分流水
     */
    @RequiresPermissions("system:integralLog:edit")
    @Log(title = "微信用户积分流水", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WxUserIntegralLog wxUserIntegralLog) {
        return toAjax(wxUserIntegralLogService.updateWxUserIntegralLog(wxUserIntegralLog));
    }

    /**
     * 删除微信用户积分流水
     */
    @RequiresPermissions("system:integralLog:remove")
    @Log(title = "微信用户积分流水", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(wxUserIntegralLogService.deleteWxUserIntegralLogByIds(ids));
    }

    /**
     * 计算所有用户得过期积分
     */
    @GetMapping("/countUserExpireIntegral")
    public R countUserExpireIntegral(@RequestParam(required = false, value = "idList") List<Long> idList) {
        wxUserIntegralLogService.countUserExpireIntegral(idList);
        return R.ok();
    }
}
