package com.srs.web.controller.comprehensive;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
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.srs.common.annotation.Log;
import com.srs.common.core.controller.BaseController;
import com.srs.common.core.domain.AjaxResult;
import com.srs.common.enums.BusinessType;
import com.srs.comprehensive.domain.CphRules;
import com.srs.comprehensive.service.ICphRulesService;
import com.srs.common.utils.poi.ExcelUtil;
import com.srs.common.core.page.TableDataInfo;

/**
 * 规则Controller
 * 
 * @author srs
 * @date 2023-07-03
 */
@RestController
@RequestMapping("/system/rules")
public class CphRulesController extends BaseController
{
    @Autowired
    private ICphRulesService cphRulesService;

    @GetMapping("/listAllRules")
    public AjaxResult listAllRules(){
        List<CphRules> list = cphRulesService.listAllRules();
        return success(list);
    }

    /**
     * 查询规则列表
     */
//    @PreAuthorize("@ss.hasPermi('system:rules:list')")
    @GetMapping("/list")
    public TableDataInfo list(CphRules cphRules)
    {
        startPage();
        List<CphRules> list = cphRulesService.selectCphRulesList(cphRules);
        return getDataTable(list);
    }
    /**
     * 查询规则列表 树形结构
     */
//    @PreAuthorize("@ss.hasPermi('system:rules:list')")
    @GetMapping("/lists")
    public AjaxResult listTree( )
    {
        return AjaxResult.success(cphRulesService.selectCphRulesListTree());
    }
    
    /**
     * 获取思想品德子类
     * @author zhy
     * @date 2023-07-03 20:29:50
     * @return
     **/
    @PostMapping("/listIamChild")
    public AjaxResult getIamChildType(){
        List<CphRules> li = cphRulesService.selectIamChildType();
        return AjaxResult.success(li);
    }

    /**
     * 获取第二课堂子类
     * @author zhy
     * @date 2023-07-03 17:27:20
     * @return
     **/
    @PostMapping("/listClassTwoChild")
    public AjaxResult getClassTwoChildType(){
        List<CphRules> li = cphRulesService.selectClassTwoChildType();
        return AjaxResult.success(li);
    }

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

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

    /**
     * 新增规则
     */
//    @PreAuthorize("@ss.hasPermi('system:rules:add')")
    @Log(title = "规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CphRules cphRules)
    {
        return toAjax(cphRulesService.insertCphRules(cphRules));
    }

    /**
     * 修改规则
     */
//    @PreAuthorize("@ss.hasPermi('system:rules:edit')")
    @Log(title = "规则", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    public AjaxResult edit(@RequestBody CphRules cphRules)
    {
        return toAjax(cphRulesService.updateCphRules(cphRules));
    }

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