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.TGuijiLibraryCreditpoints;
import com.sooka.system.service.ITGuijiLibraryCreditpointsService;


/**
 * 信用积分Controller
 *
 * @author lei
 * @date 2021-10-20
 */
@Controller
@RequestMapping("/system/library/creditpoints")
public class TGuijiLibraryCreditpointsController extends BaseController
{
    private String prefix = "system/library/creditpoints";

    @Autowired
    private ITGuijiLibraryCreditpointsService tGuijiLibraryCreditpointsService;

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

    /**
     * 查询信用积分列表
     */
    @RequiresPermissions("system:creditpoints:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TGuijiLibraryCreditpoints tGuijiLibraryCreditpoints)
    {
        startPage();
        List<TGuijiLibraryCreditpoints> list = tGuijiLibraryCreditpointsService.selectTGuijiLibraryCreditpointsList(tGuijiLibraryCreditpoints);
        return getDataTable(list);
    }

    /**
     * 导出信用积分列表
     */
    @RequiresPermissions("system:creditpoints:export")
    @Log(title = "信用积分", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TGuijiLibraryCreditpoints tGuijiLibraryCreditpoints)
    {
        List<TGuijiLibraryCreditpoints> list = tGuijiLibraryCreditpointsService.selectTGuijiLibraryCreditpointsList(tGuijiLibraryCreditpoints);
        ExcelUtil<TGuijiLibraryCreditpoints> util = new ExcelUtil<TGuijiLibraryCreditpoints>(TGuijiLibraryCreditpoints.class);
        return util.exportExcel(list, "creditpoints");
    }

    /**
     * 新增信用积分
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存信用积分
     */
    @RequiresPermissions("system:creditpoints:add")
    @Log(title = "信用积分", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TGuijiLibraryCreditpoints tGuijiLibraryCreditpoints)
    {
        return toAjax(tGuijiLibraryCreditpointsService.insertTGuijiLibraryCreditpoints(tGuijiLibraryCreditpoints));
    }

    /**
     * 修改信用积分
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        TGuijiLibraryCreditpoints tGuijiLibraryCreditpoints = tGuijiLibraryCreditpointsService.selectTGuijiLibraryCreditpointsById(id);
        mmap.put("tGuijiLibraryCreditpoints", tGuijiLibraryCreditpoints);
        return prefix + "/edit";
    }

    /**
     * 修改保存信用积分
     */
    @RequiresPermissions("system:creditpoints:edit")
    @Log(title = "信用积分", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TGuijiLibraryCreditpoints tGuijiLibraryCreditpoints)
    {
        return toAjax(tGuijiLibraryCreditpointsService.updateTGuijiLibraryCreditpoints(tGuijiLibraryCreditpoints));
    }

    /**
     * 删除信用积分
     */
    @RequiresPermissions("system:creditpoints:remove")
    @Log(title = "信用积分", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tGuijiLibraryCreditpointsService.deleteTGuijiLibraryCreditpointsByIds(ids));
    }

    /**
     * 信用积分详细
     */
    @GetMapping("/detail/{id}")
    public String detail(@PathVariable("id") String id, ModelMap mmap)
    {
        TGuijiLibraryCreditpoints tGuijiLibraryCreditpoints = tGuijiLibraryCreditpointsService.selectTGuijiLibraryCreditpointsById(id);
        mmap.put("tGuijiLibraryCreditpoints", tGuijiLibraryCreditpoints);
        return prefix + "/detail";
    }
}
