package com.dgtly.member.controller;

import java.util.List;

import com.dgtly.member.service.IMemberInfoService;
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.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.dgtly.common.annotation.Log;
import com.dgtly.common.enums.BusinessType;
import com.dgtly.member.domain.MemberInfo;
import com.dgtly.common.core.controller.BaseController;
import com.dgtly.common.core.domain.AjaxResult;
import com.dgtly.common.utils.poi.ExcelUtil;
import com.dgtly.common.core.page.TableDataInfo;

/**
 * 会员信息Controller
 * 
 * @author dgtly
 * @date 2020-02-13
 */
@Controller
@RequestMapping("/member/info")
public class MemberInfoController extends BaseController
{
    private String prefix = "member/info";

    @Autowired
    private IMemberInfoService memberInfoService;

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

    /**
     * 查询会员信息列表
     */
    @RequiresPermissions("member:info:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MemberInfo memberInfo)
    {
        startPage();
        List<MemberInfo> list = memberInfoService.selectMemberInfoList(memberInfo);
        return getDataTable(list);
    }

    /**
     * 导出会员信息列表
     */
    @RequiresPermissions("member:info:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MemberInfo memberInfo)
    {
        List<MemberInfo> list = memberInfoService.selectMemberInfoList(memberInfo);
        ExcelUtil<MemberInfo> util = new ExcelUtil<MemberInfo>(MemberInfo.class);
        return util.exportExcel(list, "info");
    }

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

    /**
     * 新增保存会员信息
     */
    @RequiresPermissions("member:info:add")
    @Log(title = "会员信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MemberInfo memberInfo)
    {
        return toAjax(memberInfoService.insertMemberInfo(memberInfo));
    }

    /**
     * 修改会员信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        MemberInfo memberInfo = memberInfoService.selectMemberInfoById(id);
        mmap.put("memberInfo", memberInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存会员信息
     */
    @RequiresPermissions("member:info:edit")
    @Log(title = "会员信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MemberInfo memberInfo)
    {
        return toAjax(memberInfoService.updateMemberInfo(memberInfo));
    }

    /**
     * 删除会员信息
     */
    @RequiresPermissions("member:info:remove")
    @Log(title = "会员信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(memberInfoService.deleteMemberInfoByIds(ids));
    }
}
