package com.dgtly.member.controller;

import java.util.List;

import com.dgtly.member.service.IMemberFollowService;
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.MemberFollow;
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/follow")
public class MemberFollowController extends BaseController
{
    private String prefix = "member/follow";

    @Autowired
    private IMemberFollowService memberFollowService;

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

    /**
     * 查询会员关注列表
     */
    @RequiresPermissions("member:follow:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MemberFollow memberFollow)
    {
        startPage();
        List<MemberFollow> list = memberFollowService.selectMemberFollowList(memberFollow);
        return getDataTable(list);
    }

    /**
     * 导出会员关注列表
     */
    @RequiresPermissions("member:follow:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MemberFollow memberFollow)
    {
        List<MemberFollow> list = memberFollowService.selectMemberFollowList(memberFollow);
        ExcelUtil<MemberFollow> util = new ExcelUtil<MemberFollow>(MemberFollow.class);
        return util.exportExcel(list, "follow");
    }

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

    /**
     * 新增保存会员关注
     */
    @RequiresPermissions("member:follow:add")
    @Log(title = "会员关注", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MemberFollow memberFollow)
    {
        return toAjax(memberFollowService.insertMemberFollow(memberFollow));
    }

    /**
     * 修改会员关注
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        MemberFollow memberFollow = memberFollowService.selectMemberFollowById(id);
        mmap.put("memberFollow", memberFollow);
        return prefix + "/edit";
    }

    /**
     * 修改保存会员关注
     */
    @RequiresPermissions("member:follow:edit")
    @Log(title = "会员关注", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MemberFollow memberFollow)
    {
        return toAjax(memberFollowService.updateMemberFollow(memberFollow));
    }

    /**
     * 删除会员关注
     */
    @RequiresPermissions("member:follow:remove")
    @Log(title = "会员关注", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(memberFollowService.deleteMemberFollowByIds(ids));
    }
}
