package com.flossom.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.flossom.common.core.domain.entity.IntegralGlobal;
import com.flossom.common.core.utils.poi.ExcelUtil;
import com.flossom.common.core.web.controller.BaseController;
import com.flossom.common.core.web.domain.AjaxResult;
import com.flossom.common.core.web.page.TableDataInfo;
import com.flossom.common.log.annotation.Log;
import com.flossom.common.log.enums.BusinessType;
import com.flossom.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.flossom.system.service.IIntegralGlobalService;

/**
 * 奖励积分Controller
 *
 * @author flossom
 * @date 2023-12-11
 */
@RestController
@RequestMapping("/globalIntegral")
public class IntegralGlobalController extends BaseController
{
    @Autowired
    private IIntegralGlobalService integralGlobalService;

    /**
     * 查询奖励积分列表
     */
    @RequiresPermissions("system:globalIntegral:list")
    @GetMapping("/list")
    public TableDataInfo list(IntegralGlobal integralGlobal)
    {
        startPage();
        List<IntegralGlobal> list = integralGlobalService.selectIntegralGlobalList(integralGlobal);
        return getDataTable(list);
    }

    /**
     * 导出奖励积分列表
     */
    @RequiresPermissions("system:globalIntegral:export")
    @Log(title = "奖励积分", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, IntegralGlobal integralGlobal)
    {
        List<IntegralGlobal> list = integralGlobalService.selectIntegralGlobalList(integralGlobal);
        ExcelUtil<IntegralGlobal> util = new ExcelUtil<IntegralGlobal>(IntegralGlobal.class);
        util.exportExcel(response, list, "奖励积分数据");
    }

    /**
     * 获取奖励积分详细信息
     */
    @RequiresPermissions("system:globalIntegral:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(integralGlobalService.selectIntegralGlobalById(id));
    }

    /**
     * 新增奖励积分
     */
    @RequiresPermissions("system:globalIntegral:add")
    @Log(title = "奖励积分", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody IntegralGlobal integralGlobal)
    {
        return toAjax(integralGlobalService.insertIntegralGlobal(integralGlobal));
    }

    /**
     * 修改奖励积分
     */
    @RequiresPermissions("system:globalIntegral:edit")
    @Log(title = "奖励积分", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody IntegralGlobal integralGlobal)
    {
        return toAjax(integralGlobalService.updateIntegralGlobal(integralGlobal));
    }

    /**
     * 删除奖励积分
     */
    @RequiresPermissions("system:globalIntegral:remove")
    @Log(title = "奖励积分", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(integralGlobalService.deleteIntegralGlobalByIds(ids));
    }
}
