package com.zkqy.web.controller.dragForm;

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

import com.zkqy.system.entity.DragFormGroup;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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.zkqy.common.annotation.Log;
import com.zkqy.common.core.controller.BaseController;
import com.zkqy.common.core.domain.AjaxResult;
import com.zkqy.common.enums.BusinessType;
import com.zkqy.system.service.IDragFormGroupService;
import com.zkqy.common.utils.poi.ExcelUtil;
import com.zkqy.common.core.page.TableDataInfo;

/**
 * 动态表单组Controller
 *
 * @author hzh
 * @date 2024-01-26
 */
@RestController
@RequestMapping("/system/formGroup")
@Api(value = "/system/formGroup", description = "动态表单组-接口")
public class DragFormGroupController extends BaseController {
    @Autowired
    private IDragFormGroupService dragFormGroupService;

    /**
     * 查询动态表单组列表
     */
////@PreAuthorize("@ss.hasPermi('system:formGroup:list')")
    @GetMapping("/list")
    @ApiOperation(value = "查询动态表单组列表")
    public TableDataInfo list(DragFormGroup dragFormGroup) {
        startPage();
        List<DragFormGroup> list = dragFormGroupService.selectDragFormGroupList(dragFormGroup);
        return getDataTable(list);
    }

    /**
     * 导出动态表单组列表
     */
    //@PreAuthorize("@ss.hasPermi('system:formGroup:export')")
    @Log(title = "动态表单组", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation(value = "导出动态表单组列表")
    public void export(HttpServletResponse response, DragFormGroup dragFormGroup) {
        List<DragFormGroup> list = dragFormGroupService.selectDragFormGroupList(dragFormGroup);
        ExcelUtil<DragFormGroup> util = new ExcelUtil<DragFormGroup>(DragFormGroup.class);
        util.exportExcel(response, list, "动态表单组数据");
    }

    /**
     * 获取动态表单组详细信息
     */
//    //@PreAuthorize("@ss.hasPermi('system:formGroup:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "获取动态表单组详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(dragFormGroupService.selectDragFormGroupById(id));
    }

    /**
     * 获取动态表单组详细信息
     */
//    //@PreAuthorize("@ss.hasPermi('system:formGroup:query')")
    @GetMapping(value = "/getInfoByGroupKey/{groupKey}")
    @ApiOperation(value = "获取动态表单组详细信息")
    public AjaxResult getInfoByGroupKey(@PathVariable("groupKey") String groupKey) {
        return success(dragFormGroupService.selectDragFormGroupByGroupKey(groupKey));
    }

    /**
     * 新增动态表单组
     */
//    //@PreAuthorize("@ss.hasPermi('system:formGroup:add')")
    @Log(title = "动态表单组", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增动态表单组")
    public AjaxResult add(@RequestBody DragFormGroup dragFormGroup) {
        return toAjax(dragFormGroupService.insertDragFormGroup(dragFormGroup));
    }

    /**
     * 修改动态表单组
     */
//    //@PreAuthorize("@ss.hasPermi('system:formGroup:edit')")
    @Log(title = "动态表单组", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改动态表单组")
    public AjaxResult edit(@RequestBody DragFormGroup dragFormGroup) {
        return toAjax(dragFormGroupService.updateDragFormGroup(dragFormGroup));
    }

    /**
     * 删除动态表单组
     */
//    //@PreAuthorize("@ss.hasPermi('system:formGroup:remove')")
    @Log(title = "动态表单组", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation(value = "删除动态表单组")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(dragFormGroupService.deleteDragFormGroupByIds(ids));
    }
}
