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.TGuijiLibraryGive;
import com.sooka.system.service.ITGuijiLibraryGiveService;


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

    @Autowired
    private ITGuijiLibraryGiveService tGuijiLibraryGiveService;

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

    /**
     * 查询还书列表
     */
    @RequiresPermissions("system:give:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TGuijiLibraryGive tGuijiLibraryGive)
    {
        startPage();
        List<TGuijiLibraryGive> list = tGuijiLibraryGiveService.selectTGuijiLibraryGiveList(tGuijiLibraryGive);
        return getDataTable(list);
    }

    /**
     * 导出还书列表
     */
    @RequiresPermissions("system:give:export")
    @Log(title = "还书", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TGuijiLibraryGive tGuijiLibraryGive)
    {
        List<TGuijiLibraryGive> list = tGuijiLibraryGiveService.selectTGuijiLibraryGiveList(tGuijiLibraryGive);
        ExcelUtil<TGuijiLibraryGive> util = new ExcelUtil<TGuijiLibraryGive>(TGuijiLibraryGive.class);
        return util.exportExcel(list, "give");
    }

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

    /**
     * 新增保存还书
     */
    @RequiresPermissions("system:give:add")
    @Log(title = "还书", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TGuijiLibraryGive tGuijiLibraryGive)
    {
        return toAjax(tGuijiLibraryGiveService.insertTGuijiLibraryGive(tGuijiLibraryGive));
    }

    /**
     * 修改还书
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        TGuijiLibraryGive tGuijiLibraryGive = tGuijiLibraryGiveService.selectTGuijiLibraryGiveById(id);
        mmap.put("tGuijiLibraryGive", tGuijiLibraryGive);
        return prefix + "/edit";
    }

    /**
     * 修改保存还书
     */
    @RequiresPermissions("system:give:edit")
    @Log(title = "还书", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TGuijiLibraryGive tGuijiLibraryGive)
    {
        return toAjax(tGuijiLibraryGiveService.updateTGuijiLibraryGive(tGuijiLibraryGive));
    }

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

    /**
     * 还书详细
     */
    @GetMapping("/detail/{id}")
    public String detail(@PathVariable("id") String id, ModelMap mmap)
    {
        TGuijiLibraryGive tGuijiLibraryGive = tGuijiLibraryGiveService.selectTGuijiLibraryGiveById(id);
        mmap.put("tGuijiLibraryGive", tGuijiLibraryGive);
        return prefix + "/detail";
    }
}
