package com.ruoyi.web.controller.dragForm;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.entity.DragForm;
import com.ruoyi.system.service.IDragFormService;
import org.springframework.web.bind.annotation.*;

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

/**
 * 动态表单
 * Controller
 *
 * @author hzh
 * @date 2023-07-12
 */
@Anonymous
@RestController
@RequestMapping("/dragform/form")
public class DragFormController extends BaseController {
    @Resource
    private IDragFormService dragFormService;

    /**
     * 查询动态表单
     * 列表
     */
    //@PreAuthorize("@ss.hasPermi('system:form:list')")
    @GetMapping("/list")
    public TableDataInfo list(DragForm dragForm) {
        startPage();
        List<DragForm> list = dragFormService.selectDragFormList(dragForm);
        return getDataTable(list);
    }

    /**
     * 导出动态表单
     * 列表
     */
    //@PreAuthorize("@ss.hasPermi('system:form:export')")
    @Log(title = "动态表单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DragForm dragForm) {
        List<DragForm> list = dragFormService.selectDragFormList(dragForm);
        ExcelUtil<DragForm> util = new ExcelUtil<DragForm>(DragForm.class);
        util.exportExcel(response, list, "动态表单数据");
    }

    /**
     * 获取动态表单
     * 详细信息
     */
    //@PreAuthorize("@ss.hasPermi('system:form:query')")
    @GetMapping(value = "/{fId}")
    public AjaxResult getInfo(@PathVariable("fId") Long fId) {
        return success(dragFormService.selectDragFormByFId(fId));
    }

    /**
     * 新增动态表单
     */
    //@PreAuthorize("@ss.hasPermi('system:form:add')")
    @Log(title = "动态表单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DragForm dragForm) {
        return toAjax(dragFormService.insertDragForm(dragForm));
    }

    /**
     * 修改动态表单
     */
    //@PreAuthorize("@ss.hasPermi('system:form:edit')")
    @Log(title = "动态表单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DragForm dragForm) {
        return toAjax(dragFormService.updateDragForm(dragForm));
    }

    /**
     * 删除动态表单
     */
    //@PreAuthorize("@ss.hasPermi('system:form:remove')")
    @Log(title = "动态表单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{fIds}")
    public AjaxResult remove(@PathVariable Long[] fIds) {
        return toAjax(dragFormService.deleteDragFormByFIds(fIds));
    }

}
