package com.rwk.web.controller.ability;

import java.util.List;
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.rwk.common.annotation.Log;
import com.rwk.common.enums.BusinessType;
import com.rwk.system.domain.RwkFamilyMember;
import com.rwk.system.service.IRwkFamilyMemberService;
import com.rwk.common.core.controller.BaseController;
import com.rwk.common.core.domain.AjaxResult;
import com.rwk.common.utils.poi.ExcelUtil;
import com.rwk.common.core.page.TableDataInfo;

/**
 * 家庭成员Controller
 * 
 * @author rick
 * @date 2024-11-06
 */
@Controller
@RequestMapping("/system/member")
public class RwkFamilyMemberController extends BaseController
{
    private String prefix = "system/member";

    @Autowired
    private IRwkFamilyMemberService rwkFamilyMemberService;

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

    /**
     * 查询家庭成员列表
     */
    @RequiresPermissions("system:member:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(RwkFamilyMember rwkFamilyMember)
    {
        startPage();
        List<RwkFamilyMember> list = rwkFamilyMemberService.selectRwkFamilyMemberList(rwkFamilyMember);
        return getDataTable(list);
    }

    /**
     * 导出家庭成员列表
     */
    @RequiresPermissions("system:member:export")
    @Log(title = "家庭成员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(RwkFamilyMember rwkFamilyMember)
    {
        List<RwkFamilyMember> list = rwkFamilyMemberService.selectRwkFamilyMemberList(rwkFamilyMember);
        ExcelUtil<RwkFamilyMember> util = new ExcelUtil<RwkFamilyMember>(RwkFamilyMember.class);
        return util.exportExcel(list, "家庭成员数据");
    }

    /**
     * 新增家庭成员
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存家庭成员
     */
    @RequiresPermissions("system:member:add")
    @Log(title = "家庭成员", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(RwkFamilyMember rwkFamilyMember)
    {
        return toAjax(rwkFamilyMemberService.insertRwkFamilyMember(rwkFamilyMember));
    }

    /**
     * 修改家庭成员
     */
    @RequiresPermissions("system:member:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        RwkFamilyMember rwkFamilyMember = rwkFamilyMemberService.selectRwkFamilyMemberById(id);
        mmap.put("rwkFamilyMember", rwkFamilyMember);
        return prefix + "/edit";
    }

    /**
     * 修改保存家庭成员
     */
    @RequiresPermissions("system:member:edit")
    @Log(title = "家庭成员", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(RwkFamilyMember rwkFamilyMember)
    {
        return toAjax(rwkFamilyMemberService.updateRwkFamilyMember(rwkFamilyMember));
    }

    /**
     * 删除家庭成员
     */
    @RequiresPermissions("system:member:remove")
    @Log(title = "家庭成员", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(rwkFamilyMemberService.deleteRwkFamilyMemberByIds(ids));
    }
}
