package com.yiqi.admin.controller.app;

import com.yiqi.app.domain.AppUserWelfare;
import com.yiqi.app.service.IAppUserWelfareService;
import com.yiqi.common.annotation.Log;
import com.yiqi.common.constant.UrlConstants;
import com.yiqi.common.core.controller.BaseController;
import com.yiqi.common.core.domain.AjaxResult;
import com.yiqi.common.core.page.TableDataInfo;
import com.yiqi.common.enums.BusinessType;
import com.yiqi.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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 ruoyi
 * @date 2024-08-09
 */
@Api(tags = "管理后台 - 会员福利金")
@RestController
@RequestMapping(UrlConstants.managerApi + "/system/welfare")
public class AppUserWelfareController extends BaseController {
    @Autowired
    private IAppUserWelfareService appUserWelfareService;


    //<editor-folder desc="基础函数">
/**
 * 查询会员福利金列表
 */
@PreAuthorize("@ss.hasPermi('system:welfare:list')")
@GetMapping("/list")
    @ApiOperation(value = "查询会员福利金列表")
    public TableDataInfo list(AppUserWelfare appUserWelfare) {
        startPage();
        List<AppUserWelfare> list = appUserWelfareService.selectAppUserWelfareList(appUserWelfare);
        return getDataTable(list);
    }

    /**
     * 导出会员福利金列表
     */
    @PreAuthorize("@ss.hasPermi('system:welfare:export')")
    @Log(title = "会员福利金", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation(value = "导出会员福利金列表")
    public void export(HttpServletResponse response, AppUserWelfare appUserWelfare) {
        List<AppUserWelfare> list = appUserWelfareService.selectAppUserWelfareList(appUserWelfare);
        ExcelUtil<AppUserWelfare> util = new ExcelUtil<AppUserWelfare>(AppUserWelfare. class);
        util.exportExcel(response, list, "会员福利金数据");
    }

    /**
     * 获取会员福利金详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:welfare:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "获取会员福利金详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(appUserWelfareService.selectAppUserWelfareById(id));
    }

    /**
     * 新增会员福利金
     */
    @PreAuthorize("@ss.hasPermi('system:welfare:add')")
    @Log(title = "会员福利金", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增会员福利金")
    public AjaxResult add(@RequestBody AppUserWelfare appUserWelfare) {
        appUserWelfare.setCreateById(getUserId());
        appUserWelfare.setCreateBy(getUsername());
        return toAjax(appUserWelfareService.insertAppUserWelfare(appUserWelfare));
    }

    /**
     * 修改会员福利金
     */
    @PreAuthorize("@ss.hasPermi('system:welfare:edit')")
    @Log(title = "会员福利金", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改会员福利金")
    public AjaxResult edit(@RequestBody AppUserWelfare appUserWelfare) {
        appUserWelfare.setUpdateById(getUserId());
        appUserWelfare.setUpdateBy(getUsername());
        return toAjax(appUserWelfareService.updateAppUserWelfare(appUserWelfare));
    }

    /**
     * 删除会员福利金
     */
    @PreAuthorize("@ss.hasPermi('system:welfare:remove')")
    @Log(title = "会员福利金", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation(value = "删除会员福利金")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(appUserWelfareService.deleteAppUserWelfareByIds(ids));
    }

            /**
             * 修改会员福利金状态
             */
            @PreAuthorize("@ss.hasPermi('system:welfare:edit')")
            @Log(title = "会员福利金", businessType = BusinessType.UPDATE)
            @PostMapping(value = "updateStatus")
            @ApiOperation(value = "修改会员福利金状态")
            public AjaxResult updateAppUserWelfareStatus(@RequestBody AppUserWelfare appUserWelfare) {
                return toAjax(appUserWelfareService.updateAppUserWelfareStatus(appUserWelfare));
            }

    //</editor-folder>
}
