package com.ruoyi.web.controller.record;

import java.util.List;

import com.ruoyi.system.domain.DataRecord;
import com.ruoyi.system.service.IDataRecordService;
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.DataMsg;
import com.ruoyi.system.service.IDataMsgService;
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 2024-10-09
 */
@Controller
@RequestMapping("/system/datamsg")
public class DataMsgController extends BaseController
{
    private String prefix = "system/datamsg";

    @Autowired
    private IDataMsgService dataMsgService;

    @Autowired
    private IDataRecordService dataRecordService;

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

    /**
     * 查询配置信息列表
     */
    @RequiresPermissions("system:datamsg:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DataMsg dataMsg)
    {
        startPage();
        List<DataMsg> list = dataMsgService.selectDataMsgList(dataMsg);
        return getDataTable(list);
    }

    /**
     * 导出配置信息列表
     */
    @RequiresPermissions("system:datamsg:export")
    @Log(title = "配置信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DataMsg dataMsg)
    {
        List<DataMsg> list = dataMsgService.selectDataMsgList(dataMsg);
        ExcelUtil<DataMsg> util = new ExcelUtil<DataMsg>(DataMsg.class);
        return util.exportExcel(list, "配置信息数据");
    }

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

    /**
     * 新增保存配置信息
     */
    @RequiresPermissions("system:datamsg:add")
    @Log(title = "配置信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DataMsg dataMsg)
    {
        return toAjax(dataMsgService.insertDataMsg(dataMsg));
    }

    /**
     * 修改配置信息
     */
    @RequiresPermissions("system:datamsg:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        DataMsg dataMsg = dataMsgService.selectDataMsgById(id);
        mmap.put("dataMsg", dataMsg);
        return prefix + "/edit";
    }

    /**
     * 修改保存配置信息
     */
    @RequiresPermissions("system:datamsg:edit")
    @Log(title = "配置信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DataMsg dataMsg)
    {
        return toAjax(dataMsgService.updateDataMsg(dataMsg));
    }

    /**
     * 删除配置信息
     */
    @RequiresPermissions("system:datamsg:remove")
    @Log(title = "配置信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(dataMsgService.deleteDataMsgByIds(ids));
    }

    /**
     * 修改配置信息
     */
    @RequiresPermissions("system:datamsg:edit")
    @PostMapping("/dowith")
    @ResponseBody
    public AjaxResult dowith(Long id)
    {
        DataMsg dataMsg = dataMsgService.selectDataMsgById(id);
        Integer res = dataMsgService.dowithsaomaotask(dataMsg);
        //插入数据库
        dataMsgService.insertsaomaodata(dataMsg);
        return AjaxResult.success("执行完成");
    }

    /**
     * 查询扫描详细
     */
    @RequiresPermissions("system:datamsg:edit")
    @GetMapping("/detail/{dataid}")
    public String detail(@PathVariable("dataid") Long dataid, ModelMap mmap)
    {
        //mmap.put("datamsg", dataMsgService.selectDataMsgById(dataid));
//        DataRecord dataRecord = new DataRecord();
//        dataRecord.setRecord(dataid);
//        mmap.put("record", dataRecordService.selectDataRecordAllList(dataRecord));
         DataMsg dataMsg = dataMsgService.selectDataMsgById(dataid);
        mmap.put("record", dataid);
        mmap.put("msgurl", dataMsg.getUrl());
        return "system/record/record";
    }

}
