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.RwkAddressBook;
import com.rwk.system.service.IRwkAddressBookService;
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 ruoyi
 * @date 2024-12-11
 */
@Controller
@RequestMapping("/system/addressbook")
public class RwkAddressBookController extends BaseController
{
    private String prefix = "system/addressbook";

    @Autowired
    private IRwkAddressBookService rwkAddressBookService;

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

    /**
     * 查询通讯录主列表
     */
    @RequiresPermissions("system:book:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(RwkAddressBook rwkAddressBook)
    {

        List<RwkAddressBook> list = rwkAddressBookService.selectRwkAddressBookList(rwkAddressBook);
        return getDataTable(list);
    }


    /**
     * 导出通讯录主列表
     */
    @RequiresPermissions("system:book:export")
    @Log(title = "通讯录主", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(RwkAddressBook rwkAddressBook)
    {
        List<RwkAddressBook> list = rwkAddressBookService.selectRwkAddressBookList(rwkAddressBook);
        ExcelUtil<RwkAddressBook> util = new ExcelUtil<RwkAddressBook>(RwkAddressBook.class);
        return util.exportExcel(list, "通讯录主数据");
    }

    /**
     * 新增通讯录人员
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增通讯录分组
     */
    @GetMapping("/addgroup")
    public String addgroup()
    {
        return prefix + "/addgroup";
    }


    /**
     * 新增通讯录分组
     */
    @GetMapping("/addbook")
    public String addbook()
    {
        return prefix + "/addbook";
    }

    /**
     * 新增保存通讯录
     */
    @RequiresPermissions("system:book:add")
    @Log(title = "通讯录主", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(RwkAddressBook rwkAddressBook)
    {
        return toAjax(rwkAddressBookService.insertRwkAddressBook(rwkAddressBook));
    }

    /**
     * 修改通讯录
     */
    @RequiresPermissions("system:book:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        RwkAddressBook rwkAddressBook = rwkAddressBookService.selectRwkAddressBookById(id);
        mmap.put("rwkAddressBook", rwkAddressBook);
        return prefix + "/edit";
    }

    /**
     * 修改保存通讯录
     */
    @RequiresPermissions("system:book:edit")
    @Log(title = "通讯录主", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(RwkAddressBook rwkAddressBook)
    {
        return toAjax(rwkAddressBookService.updateRwkAddressBook(rwkAddressBook));
    }

    /**
     * 删除通讯录
     */
    @RequiresPermissions("system:book:remove")
    @Log(title = "通讯录主", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(rwkAddressBookService.deleteRwkAddressBookByIds(ids));
    }
}
