package com.sooka.system.controller;

import java.util.List;

import com.sooka.common.annotation.Log;
import com.sooka.common.core.controller.BaseController;
import com.sooka.common.core.domain.AjaxResult;
import com.sooka.common.core.page.TableDataInfo;
import com.sooka.common.enums.BusinessType;
import com.sooka.common.utils.poi.ExcelUtil;
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.sooka.system.domain.TGuijiLibraryBorrow;
import com.sooka.system.service.ITGuijiLibraryBorrowService;


/**
 * 借书Controller
 *
 * @author lei
 * @date 2021-10-20
 */
@Controller
@RequestMapping("/system/library/borrow")
public class TGuijiLibraryBorrowController extends BaseController
{
    private String prefix = "system/library/borrow";

    @Autowired
    private ITGuijiLibraryBorrowService tGuijiLibraryBorrowService;

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

    /**
     * 查询借书列表
     */
    @RequiresPermissions("system:borrow:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TGuijiLibraryBorrow tGuijiLibraryBorrow)
    {
        startPage();
        List<TGuijiLibraryBorrow> list = tGuijiLibraryBorrowService.selectTGuijiLibraryBorrowList(tGuijiLibraryBorrow);
        return getDataTable(list);
    }

    /**
     * 导出借书列表
     */
    @RequiresPermissions("system:borrow:export")
    @Log(title = "借书", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TGuijiLibraryBorrow tGuijiLibraryBorrow)
    {
        List<TGuijiLibraryBorrow> list = tGuijiLibraryBorrowService.selectTGuijiLibraryBorrowList(tGuijiLibraryBorrow);
        ExcelUtil<TGuijiLibraryBorrow> util = new ExcelUtil<TGuijiLibraryBorrow>(TGuijiLibraryBorrow.class);
        return util.exportExcel(list, "borrow");
    }

    /**
     * 新增借书
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存借书
     */
    @RequiresPermissions("system:borrow:add")
    @Log(title = "借书", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TGuijiLibraryBorrow tGuijiLibraryBorrow)
    {
        return toAjax(tGuijiLibraryBorrowService.insertTGuijiLibraryBorrow(tGuijiLibraryBorrow));
    }

    /**
     * 修改借书
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        TGuijiLibraryBorrow tGuijiLibraryBorrow = tGuijiLibraryBorrowService.selectTGuijiLibraryBorrowById(id);
        mmap.put("tGuijiLibraryBorrow", tGuijiLibraryBorrow);
        return prefix + "/edit";
    }

    /**
     * 修改保存借书
     */
    @RequiresPermissions("system:borrow:edit")
    @Log(title = "借书", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TGuijiLibraryBorrow tGuijiLibraryBorrow)
    {
        return toAjax(tGuijiLibraryBorrowService.updateTGuijiLibraryBorrow(tGuijiLibraryBorrow));
    }

    /**
     * 删除借书
     */
    @RequiresPermissions("system:borrow:remove")
    @Log(title = "借书", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tGuijiLibraryBorrowService.deleteTGuijiLibraryBorrowByIds(ids));
    }

    /**
     * 借书详情
     */
    @GetMapping("/detail/{id}")
    public String detail(@PathVariable("id") String id, ModelMap mmap)
    {
        TGuijiLibraryBorrow tGuijiLibraryBorrow = tGuijiLibraryBorrowService.selectTGuijiLibraryBorrowById(id);
        mmap.put("tGuijiLibraryBorrow", tGuijiLibraryBorrow);
        return prefix + "/detail";
    }
}
