package beilv.web.controller.system;

import beilv.common.annotation.Log;
import beilv.common.core.controller.BaseController;
import beilv.common.core.domain.AjaxResult;
import beilv.common.core.page.TableDataInfo;
import beilv.common.enums.BusinessType;
import beilv.common.utils.poi.ExcelUtil;
import beilv.system.domain.SysMember;
import beilv.system.domain.dto.SysMemberDTO;
import beilv.system.service.ISysMemberService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 会员用户信息Controller
 *
 * @author ruoyi
 * @date 2025-01-02
 */
@Controller
@RequestMapping("/system/member")
public class SysMemberController extends BaseController {
    private String prefix = "system/member";

    @Autowired
    private ISysMemberService sysMemberService;

    @RequiresPermissions("system:member:view")
    @GetMapping()
    public String member() {
        return prefix + "/member";
    }

    /**
     * 查询会员用户信息列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysMember sysMember) {
        startPage();
        List<SysMember> list = sysMemberService.selectSysMemberList(sysMember);
        return getDataTable(list);
    }

    /**
     * 导出会员用户信息列表
     */
    @Log(title = "会员用户信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysMember sysMember) {
        List<SysMember> list = sysMemberService.selectSysMemberList(sysMember);
        ExcelUtil<SysMember> util = new ExcelUtil<SysMember>(SysMember.class);
        return util.exportExcel(list, "会员用户信息数据");
    }

    /**
     * 新增会员用户信息
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存会员用户信息
     */
    @Log(title = "会员用户信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysMember sysMember) {
        return toAjax(sysMemberService.insertSysMember(sysMember));
    }

    /**
     * 修改会员用户信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        SysMember sysMember = sysMemberService.selectSysMemberById(id);
        mmap.put("sysMember", sysMember);
        return prefix + "/edit";
    }

    /**
     * 修改保存会员用户信息
     */
    @Log(title = "会员用户信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysMember sysMember) {
        return toAjax(sysMemberService.updateSysMember(sysMember));
    }

    /**
     * 删除会员用户信息
     */
    @Log(title = "会员用户信息", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(sysMemberService.deleteSysMemberByIds(ids));
    }


}
