package com.ruoyi.web.controller.system;

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.system.domain.TaskData;
import com.ruoyi.system.service.ITaskDataService;
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 2023-10-29
 */
@Controller
@RequestMapping("/system/data")
public class TaskDataController extends BaseController
{
    private String prefix = "system/data";

    @Autowired
    private ITaskDataService taskDataService;

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

    /**
     * 查询归因数据回传列表
     */
    @RequiresPermissions("system:data:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TaskData taskData)
    {
        startPage();
        List<TaskData> list = taskDataService.selectTaskDataList(taskData);
        return getDataTable(list);
    }

    /**
     * 导出归因数据回传列表
     */
    @RequiresPermissions("system:data:export")
    @Log(title = "归因数据回传", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TaskData taskData)
    {
        List<TaskData> list = taskDataService.selectTaskDataList(taskData);
        ExcelUtil<TaskData> util = new ExcelUtil<TaskData>(TaskData.class);
        return util.exportExcel(list, "归因数据回传数据");
    }

    /**
     * 新增归因数据回传
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存归因数据回传
     */
    @RequiresPermissions("system:data:add")
    @Log(title = "归因数据回传", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TaskData taskData)
    {
        return toAjax(taskDataService.insertTaskData(taskData));
    }

    /**
     * 修改归因数据回传
     */
    @RequiresPermissions("system:data:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TaskData taskData = taskDataService.selectTaskDataById(id);
        mmap.put("taskData", taskData);
        return prefix + "/edit";
    }

    /**
     * 修改保存归因数据回传
     */
    @RequiresPermissions("system:data:edit")
    @Log(title = "归因数据回传", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TaskData taskData)
    {
        return toAjax(taskDataService.updateTaskData(taskData));
    }

    /**
     * 删除归因数据回传
     */
    @RequiresPermissions("system:data:remove")
    @Log(title = "归因数据回传", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(taskDataService.deleteTaskDataByIds(ids));
    }
}
