package com.ruoyi.project.controller;

import java.util.List;
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.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.project.domain.TrsSiteconfig;
import com.ruoyi.project.service.ITrsSiteconfigService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 配置管理Controller
 * 
 * @author ruoyi
 * @date 2025-03-19
 */
@Controller
@RequestMapping("/project/siteconfig")
public class TrsSiteconfigController extends BaseController
{
    private String prefix = "project/siteconfig";

    @Autowired
    private ITrsSiteconfigService trsSiteconfigService;

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

    /**
     * 查询配置管理列表
     */
    @RequiresPermissions("project:siteconfig:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TrsSiteconfig trsSiteconfig)
    {
        startPage();
        List<TrsSiteconfig> list = trsSiteconfigService.selectTrsSiteconfigList(trsSiteconfig);
        return getDataTable(list);
    }

    /**
     * 导出配置管理列表
     */
    @RequiresPermissions("project:siteconfig:export")
    @Log(title = "配置管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TrsSiteconfig trsSiteconfig)
    {
        List<TrsSiteconfig> list = trsSiteconfigService.selectTrsSiteconfigList(trsSiteconfig);
        ExcelUtil<TrsSiteconfig> util = new ExcelUtil<TrsSiteconfig>(TrsSiteconfig.class);
        return util.exportExcel(list, "配置管理数据");
    }

    /**
     * 新增配置管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存配置管理
     */
    @RequiresPermissions("project:siteconfig:add")
    @Log(title = "配置管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TrsSiteconfig trsSiteconfig)
    {
        return toAjax(trsSiteconfigService.insertTrsSiteconfig(trsSiteconfig));
    }

    /**
     * 修改配置管理
     */
    @RequiresPermissions("project:siteconfig:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TrsSiteconfig trsSiteconfig = trsSiteconfigService.selectTrsSiteconfigById(id);
        mmap.put("trsSiteconfig", trsSiteconfig);
        return prefix + "/edit";
    }

    /**
     * 修改保存配置管理
     */
    @RequiresPermissions("project:siteconfig:edit")
    @Log(title = "配置管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TrsSiteconfig trsSiteconfig)
    {
        return toAjax(trsSiteconfigService.updateTrsSiteconfig(trsSiteconfig));
    }

    /**
     * 删除配置管理
     */
    @RequiresPermissions("project:siteconfig:remove")
    @Log(title = "配置管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(trsSiteconfigService.deleteTrsSiteconfigByIds(ids));
    }


    /**
     * 将数据库的信息同步到ES
     */
    @RequiresPermissions("system:datamsg:edit")
    @PostMapping("/dosysn")
    @ResponseBody
    public AjaxResult dosysn(Long id)
    {
        trsSiteconfigService.dosysn(id);
        return AjaxResult.success("执行完成");
    }

    /**
     * 扫描关键词并存入到数据库
     */
    //@RequiresPermissions("system:datamsg:edit")
    @PostMapping("/doscan")
    @ResponseBody
    public AjaxResult doscan(Long id,String type)
    {
        trsSiteconfigService.doscan(id,type,"");
        return AjaxResult.success("执行完成");
    }


    /**
     * 根据url扫描正文
     */
    @RequiresPermissions("system:datamsg:edit")
    @PostMapping("/docon")
    @ResponseBody
    public AjaxResult docon(Long id)
    {
        trsSiteconfigService.docon(id);
        return AjaxResult.success("执行完成");
    }

}
