package com.ruoyi.web.controller.dragForm;

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.CommonEntity;
import com.ruoyi.system.entity.DragTableGroup;
import com.ruoyi.system.entity.vo.DragTableGroupVo;
import com.ruoyi.system.service.IDragTableGroupService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;

/**
 * @author hmc
 * @date 2023-11-01 14:29
 * @Description:
 */
@RestController
@RequestMapping("/system/group")
@Api(value = "/system/group", description = "拖拽格组-接口")
public class DragTableGroupController extends BaseController {

    @Autowired
    private IDragTableGroupService dragTableGroupService;

    /**
     * 传groupKey获取当前组下的所有动态表格
     * @param commonEntity
     * @return
     */
    @GetMapping("/dragGroupTableInfo")
    public AjaxResult dragGroupTableInfo(CommonEntity commonEntity) {
        return   AjaxResult.success(dragTableGroupService.selectDragTableGroup(commonEntity.getQueryMap().get("groupKey").toString()));
    }

    /**
     * 查询拖拽格组列表
     * @PreAuthorize("@ss.hasPermi('system:group:list')")
     */
    @GetMapping("/list")
    @ApiOperation(value = "查询拖拽格组列表")
    public TableDataInfo list(DragTableGroup dragTableGroup)
    {
        startPage();
        List<DragTableGroup> list = dragTableGroupService.selectDragTableGroupList(dragTableGroup);
        return getDataTable(list);
    }

    /**
     * 查询拖拽表格组详细信息
     * @param dragTableGroup
     * @return
     */
    @GetMapping("/listDetail")
    @ApiOperation(value = "查询拖拽格组列表")
    public AjaxResult listDetail(DragTableGroup dragTableGroup)
    {
        DragTableGroupVo list = dragTableGroupService.selectDragTableGroupListDetail(dragTableGroup);
        return AjaxResult.success(list);
    }


    /**
     * 导出拖拽格组列表
     */
    @PreAuthorize("@ss.hasPermi('system:group:export')")
    @Log(title = "拖拽格组", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation(value = "导出拖拽格组列表")
    public void export(HttpServletResponse response, DragTableGroup dragTableGroup)
    {
        List<DragTableGroup> list = dragTableGroupService.selectDragTableGroupList(dragTableGroup);
        ExcelUtil<DragTableGroup> util = new ExcelUtil<DragTableGroup>(DragTableGroup.class);
        util.exportExcel(response, list, "拖拽格组数据");
    }


    /**
     * 获取拖拽格组详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:group:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "获取拖拽格组详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(dragTableGroupService.selectDragTableGroupById(id));
    }


    /**
     * 新增拖拽格组
     */
    @Log(title = "拖拽格组", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增拖拽格组")
    public AjaxResult add(@RequestBody DragTableGroupVo dragTableGroupVo)
    {
        return toAjax(dragTableGroupService.insertDragTableGroup(dragTableGroupVo));
    }

    /**
     * 新增配置表格组
     */
    @Log(title = "新增配置组", businessType = BusinessType.INSERT)
    @PostMapping("/addConfigurationGroup")
    @ApiOperation(value = "新增拖拽格组")
    public AjaxResult addConfigurationGroup(@RequestBody DragTableGroupVo dragTableGroupVo)
    {
        return toAjax(dragTableGroupService.insertDragTableConfigurationGroup(dragTableGroupVo));
    }

    /**
     * 修改拖拽格组
     */
    @PreAuthorize("@ss.hasPermi('system:group:edit')")
    @Log(title = "拖拽格组", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改拖拽格组")
    public AjaxResult edit(@RequestBody DragTableGroupVo dragTableGroupVo)
    {
        return toAjax(dragTableGroupService.updateDragTableGroup(dragTableGroupVo));
    }

    /**
     * 修改拖拽配置表格组
     */
    @PreAuthorize("@ss.hasPermi('system:group:edit')")
    @Log(title = "拖拽格组", businessType = BusinessType.UPDATE)
    @PutMapping("/editConfigurationGroup")
    @ApiOperation(value = "修改拖拽配置表格组")
    public AjaxResult editConfigurationGroup(@RequestBody DragTableGroupVo dragTableGroupVo)
    {
        return toAjax(dragTableGroupService.editConfigurationGroup(dragTableGroupVo));
    }


    /**
     * 批量删除拖拽格组
     */
    @PreAuthorize("@ss.hasPermi('system:group:remove')")
    @Log(title = "拖拽格组", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation(value = "删除拖拽格组")
    public AjaxResult batchRemove(@PathVariable Long[] ids)
    {
        //Boolean aBoolean = dragTableGroupService.selectDragTableGroupTableListSize(ids);
        return toAjax(dragTableGroupService.deleteDragTableGroupByIds(ids));
    }

    ///**
    // * 下发给BPM工艺工序的弹窗信息
    // */
    //@GetMapping("/getProcessPopupResultInfo")
    //@ApiOperation(value = "下发给BPM工艺工序的弹窗信息")
    //public CommonEntity get(CommonEntity commonEntity)
    //{
    //    CommonEntity commonEntityResult = dragTableGroupService.queryProcessPopupResultInfo(commonEntity);
    //    return commonEntityResult;
    //}

    /**
     * 获取拖拽格组详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:group:query')")
    @GetMapping("/getInfoBySqlKey/{groupKey}")
    public AjaxResult getInfoBySqlKey(@PathVariable("groupKey") String groupKey)
    {
        return success(dragTableGroupService.selectDragTableGroupInfoByGroupKey(groupKey));
    }

}
