package com.ruoyi.web.controller.dragForm;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.entity.DragTable;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.service.IDragTableService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 动态格Controller
 *
 * @author xzz
 * @date 2023-07-31
 */

@RestController
@RequestMapping("/system/table")
public class DragTableController extends BaseController {
    @Autowired
    private IDragTableService dragTableService;

    /**
     * 查询动态格列表
     */
    @GetMapping("/list")
    public TableDataInfo list(DragTable dragTable) {
        startPage();
        List<DragTable> list = dragTableService.selectDragTableList(dragTable);
        return getDataTable(list);
    }

    /**
     * 导出动态格列表
     */
    @Log(title = "动态格", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DragTable dragTable) {
        List<DragTable> list = dragTableService.selectDragTableList(dragTable);
        ExcelUtil<DragTable> util = new ExcelUtil<DragTable>(DragTable.class);
        util.exportExcel(response, list, "动态格数据");
    }

    /**
     * 获取动态格详细信息
     */
    @GetMapping(value = "/{tId}")
    public AjaxResult getInfo(@PathVariable("tId") Long tId) {
        return success(dragTableService.selectDragTableByTId(tId));
    }

    /**
     * 新增动态格
     */
    @Log(title = "动态格", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DragTable dragTable) {
        return toAjax(dragTableService.insertDragTable(dragTable));
    }

    /**
     * 修改动态格
     */
    @Log(title = "动态格", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DragTable dragTable) {
        return toAjax(dragTableService.updateDragTable(dragTable));
    }

    /**
     * 删除动态格
     */
    @Log(title = "动态格", businessType = BusinessType.DELETE)
    @DeleteMapping("/{tIds}")
    public AjaxResult remove(@PathVariable Long[] tIds) {
        return toAjax(dragTableService.deleteDragTableByTIds(tIds));
    }
}
