package com.srs.web.controller.comprehensive;

import com.srs.common.annotation.Log;
import com.srs.common.core.controller.BaseController;
import com.srs.common.core.domain.AjaxResult;
import com.srs.common.core.page.TableDataInfo;
import com.srs.common.enums.BusinessType;
import com.srs.common.utils.poi.ExcelUtil;
import com.srs.comprehensive.domain.SrsBonusRules;
import com.srs.comprehensive.service.IStsBonusRulesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 加分规则Controller
 * 
 * @author srs
 * @date 2023-06-19
 */
@RestController
@RequestMapping("/system/rulesqqqq")
public class StsBonusRulesController extends BaseController
{
    @Autowired
    private IStsBonusRulesService stsBonusRulesService;

    /**
     * 查询加分规则列表
     */
//    @PreAuthorize("@ss.hasPermi('system:rules:list')")
    @GetMapping("/list")
    public TableDataInfo list(SrsBonusRules srsBonusRules)
    {
        startPage();
        List<SrsBonusRules> list = stsBonusRulesService.selectStsBonusRulesList(srsBonusRules);
        return getDataTable(list);
    }

    /**
     * 导出加分规则列表
     */
//    @PreAuthorize("@ss.hasPermi('system:rules:export')")
    @Log(title = "加分规则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SrsBonusRules srsBonusRules)
    {
        List<SrsBonusRules> list = stsBonusRulesService.selectStsBonusRulesList(srsBonusRules);
        ExcelUtil<SrsBonusRules> util = new ExcelUtil<SrsBonusRules>(SrsBonusRules.class);
        util.exportExcel(response, list, "加分规则数据");
    }

    /**
     * 获取加分规则详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:rules:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(stsBonusRulesService.selectStsBonusRulesById(id));
    }

    /**
     * 新增加分规则
     */
//    @PreAuthorize("@ss.hasPermi('system:rules:add')")
    @Log(title = "加分规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SrsBonusRules srsBonusRules)
    {
        return toAjax(stsBonusRulesService.insertStsBonusRules(srsBonusRules));
    }

    /**
     * 修改加分规则
     */
//    @PreAuthorize("@ss.hasPermi('system:rules:edit')")
    @Log(title = "加分规则", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    public AjaxResult edit(@RequestBody SrsBonusRules srsBonusRules)
    {
        return toAjax(stsBonusRulesService.updateStsBonusRules(srsBonusRules));
    }

    /**
     * 删除加分规则
     */
//    @PreAuthorize("@ss.hasPermi('system:rules:remove')")
    @Log(title = "加分规则", businessType = BusinessType.DELETE)
	@PostMapping("/delete/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(stsBonusRulesService.deleteStsBonusRulesByIds(ids));
    }
}
