package com.ruoyi.project.controller;

import java.util.List;

import com.ruoyi.project.domain.TrsSensitiveResults;
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.TrsTechnicalResults;
import com.ruoyi.project.service.ITrsTechnicalResultsService;
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-24
 */
@Controller
@RequestMapping("/project/technicalresult")
public class TrsTechnicalResultsController extends BaseController
{
    private String prefix = "project/technicalresult";

    @Autowired
    private ITrsTechnicalResultsService trsTechnicalResultsService;

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

    /**
     * 查询专业术语监测列表
     */
    @RequiresPermissions("project:technicalresult:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TrsTechnicalResults trsTechnicalResults)
    {
        startPage();
        List<TrsTechnicalResults> list = trsTechnicalResultsService.selectTrsTechnicalResultsList(trsTechnicalResults);
        return getDataTable(list);
    }

    /**
     * 导出专业术语监测列表
     */
    @RequiresPermissions("project:technicalresult:export")
    @Log(title = "专业术语监测", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TrsTechnicalResults trsTechnicalResults)
    {
        List<TrsTechnicalResults> list = trsTechnicalResultsService.selectTrsTechnicalResultsList(trsTechnicalResults);
        ExcelUtil<TrsTechnicalResults> util = new ExcelUtil<TrsTechnicalResults>(TrsTechnicalResults.class);
        return util.exportExcel(list, "专业术语监测数据");
    }

    /**
     * 新增专业术语监测
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存专业术语监测
     */
    @RequiresPermissions("project:technicalresult:add")
    @Log(title = "专业术语监测", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TrsTechnicalResults trsTechnicalResults)
    {
        return toAjax(trsTechnicalResultsService.insertTrsTechnicalResults(trsTechnicalResults));
    }

    /**
     * 修改专业术语监测
     */
    @RequiresPermissions("project:technicalresult:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TrsTechnicalResults trsTechnicalResults = trsTechnicalResultsService.selectTrsTechnicalResultsById(id);
        mmap.put("trsTechnicalResults", trsTechnicalResults);
        return prefix + "/edit";
    }

    /**
     * 修改保存专业术语监测
     */
    @RequiresPermissions("project:technicalresult:edit")
    @Log(title = "专业术语监测", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TrsTechnicalResults trsTechnicalResults)
    {
        return toAjax(trsTechnicalResultsService.updateTrsTechnicalResults(trsTechnicalResults));
    }

    /**
     * 修改保存常见错误监测
     */
    @RequiresPermissions("project:technicalresult:edit")
    @Log(title = "常见错误监测", businessType = BusinessType.UPDATE)
    @PostMapping("/biaoji")
    @ResponseBody
    public AjaxResult biaoji(String ids, TrsTechnicalResults trsSensitiveResults)
    {
        Integer count = 0;
        for (String id : ids.split(",")) {
            trsSensitiveResults.setId(Long.parseLong(id));
            trsSensitiveResults.setStatus(trsSensitiveResults.getStatus());
            trsTechnicalResultsService.updateTrsTechnicalResults(trsSensitiveResults);
        }
        return toAjax(count);
    }

    /**
     * 删除专业术语监测
     */
    @RequiresPermissions("project:technicalresult:remove")
    @Log(title = "专业术语监测", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(trsTechnicalResultsService.deleteTrsTechnicalResultsByIds(ids));
    }
}
