package com.ruoyi.project.controller;

import java.util.List;

import com.ruoyi.project.domain.TrsFileInfo;
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.TrsResultsLog;
import com.ruoyi.project.service.ITrsResultsLogService;
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-28
 */
@Controller
@RequestMapping("/project/resultlog")
public class TrsResultsLogController extends BaseController
{
    private String prefix = "project/resultlog";

    @Autowired
    private ITrsResultsLogService trsResultsLogService;

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

    /**
     * 查询审校日志列表
     */
    @RequiresPermissions("project:resultlog:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TrsResultsLog trsResultsLog)
    {
        startPage();
        List<TrsResultsLog> list = trsResultsLogService.selectTrsResultsLogList(trsResultsLog);
        return getDataTable(list);
    }

    /**
     * 导出审校日志列表
     */
    @RequiresPermissions("project:resultlog:export")
    @Log(title = "审校日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TrsResultsLog trsResultsLog)
    {
        List<TrsResultsLog> list = trsResultsLogService.selectTrsResultsLogList(trsResultsLog);
        ExcelUtil<TrsResultsLog> util = new ExcelUtil<TrsResultsLog>(TrsResultsLog.class);
        return util.exportExcel(list, "审校日志数据");
    }

    /**
     * 新增审校日志
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存审校日志
     */
    @RequiresPermissions("project:resultlog:add")
    @Log(title = "审校日志", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TrsResultsLog trsResultsLog)
    {
        trsResultsLog.setDeptId(getSysUser().getDeptId());
        trsResultsLog.setUserId(getSysUser().getUserId());
        return toAjax(trsResultsLogService.insertTrsResultsLog(trsResultsLog));
    }

    /**
     * 修改审校日志
     */
    @RequiresPermissions("project:resultlog:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TrsResultsLog trsResultsLog = trsResultsLogService.selectTrsResultsLogById(id);
        mmap.put("trsResultsLog", trsResultsLog);
        return prefix + "/edit";
    }

    /**
     * 修改保存审校日志
     */
    @RequiresPermissions("project:resultlog:edit")
    @Log(title = "审校日志", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TrsResultsLog trsResultsLog)
    {
        return toAjax(trsResultsLogService.updateTrsResultsLog(trsResultsLog));
    }

    /**
     * 删除审校日志
     */
    @RequiresPermissions("project:resultlog:remove")
    @Log(title = "审校日志", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(trsResultsLogService.deleteTrsResultsLogByIds(ids));
    }

    /**
     * 查看审校日志
     */
    /*@RequiresPermissions("project:resultlog:edit")*/
    @GetMapping("/view/{id}")
    public String view(@PathVariable("id") Long id, ModelMap mmap)
    {
        TrsResultsLog trsResultsLog = trsResultsLogService.selectTrsResultsLogById(id);
        mmap.put("trsResultsLog", trsResultsLog);
        return prefix + "/view";
    }

}
