package com.huijy.web.controller.management;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.huijy.common.annotation.Log;
import com.huijy.common.core.controller.BaseController;
import com.huijy.common.core.domain.AjaxResult;
import com.huijy.common.enums.BusinessType;
import com.huijy.management.domain.Member;
import com.huijy.management.service.IMemberService;
import com.huijy.common.utils.poi.ExcelUtil;
import com.huijy.common.core.page.TableDataInfo;

/**
 * 会员信息(游客)Controller
 *
 * @author luobo
 * @date 2021-09-12
 */
@RestController
@RequestMapping("/management/member")
public class MemberController extends BaseController
{
    @Autowired
    private IMemberService memberService;

    /**
     * 查询会员信息(游客)列表
     */
    @PreAuthorize("@ss.hasPermi('management:member:list')")
    @GetMapping("/list")
    public TableDataInfo list(Member member)
    {
        startPage();
        List<Member> list = memberService.selectMemberList(member);
        return getDataTable(list);
    }

    /**
     * 导出会员信息(游客)列表
     */
    @PreAuthorize("@ss.hasPermi('management:member:export')")
    @Log(title = "会员信息(游客)", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Member member)
    {
        List<Member> list = memberService.selectMemberList(member);
        ExcelUtil<Member> util = new ExcelUtil<Member>(Member.class);
        return util.exportExcel(list, "会员信息(游客)数据");
    }

    /**
     * 获取会员信息(游客)详细信息
     */
    @PreAuthorize("@ss.hasPermi('management:member:query')")
    @GetMapping(value = "/{memberId}")
    public AjaxResult getInfo(@PathVariable("memberId") Long memberId)
    {
        return AjaxResult.success(memberService.selectMemberByMemberId(memberId));
    }

    /**
     * 新增会员信息(游客)
     */
    @PreAuthorize("@ss.hasPermi('management:member:add')")
    @Log(title = "会员信息(游客)", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Member member)
    {
        return toAjax(memberService.insertMember(member));
    }

    /**
     * 修改会员信息(游客)
     */
    @PreAuthorize("@ss.hasPermi('management:member:edit')")
    @Log(title = "会员信息(游客)", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Member member)
    {
        return toAjax(memberService.updateMember(member));
    }

    /**
     * 删除会员信息(游客)
     */
    @PreAuthorize("@ss.hasPermi('management:member:remove')")
    @Log(title = "会员信息(游客)", businessType = BusinessType.DELETE)
	@DeleteMapping("/{memberIds}")
    public AjaxResult remove(@PathVariable Long[] memberIds)
    {
        return toAjax(memberService.deleteMemberByMemberIds(memberIds));
    }
}
