package com.jsowell.web.controller.pile;

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

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.jsowell.common.annotation.Log;
import com.jsowell.common.core.controller.BaseController;
import com.jsowell.common.core.domain.AjaxResult;
import com.jsowell.common.enums.BusinessType;
import com.jsowell.pile.domain.DockingPlatformConfig;
import com.jsowell.pile.service.IDockingPlatformConfigService;
import com.jsowell.common.util.poi.ExcelUtil;
import com.jsowell.common.core.page.TableDataInfo;

/**
 * 对接平台配置信息Controller
 *
 * @author jsowell
 * @date 2023-05-27
 */
@RestController
@RequestMapping("/pile/config")
public class DockingPlatformConfigController extends BaseController {
    @Autowired
    private IDockingPlatformConfigService dockingPlatformConfigService;

    /**
     * 查询对接平台配置信息列表
     */
    @PreAuthorize("@ss.hasPermi('pile:config:list')")
    @GetMapping("/list")
    public TableDataInfo list(DockingPlatformConfig dockingPlatformConfig) {
        startPage();
        List<DockingPlatformConfig> list = dockingPlatformConfigService.selectDockingPlatformConfigList(dockingPlatformConfig);
        return getDataTable(list);
    }

    /**
     * 导出对接平台配置信息列表
     */
    @PreAuthorize("@ss.hasPermi('pile:config:export')")
    @Log(title = "对接平台配置信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DockingPlatformConfig dockingPlatformConfig) {
        List<DockingPlatformConfig> list = dockingPlatformConfigService.selectDockingPlatformConfigList(dockingPlatformConfig);
        ExcelUtil<DockingPlatformConfig> util = new ExcelUtil<DockingPlatformConfig>(DockingPlatformConfig.class);
        util.exportExcel(response, list, "对接平台配置信息数据");
    }

    /**
     * 获取对接平台配置信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('pile:config:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return AjaxResult.success(dockingPlatformConfigService.selectDockingPlatformConfigById(id));
    }

    /**
     * 新增对接平台配置信息
     */
    @PreAuthorize("@ss.hasPermi('pile:config:add')")
    @Log(title = "对接平台配置信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DockingPlatformConfig dockingPlatformConfig) {
        return toAjax(dockingPlatformConfigService.insertDockingPlatformConfig(dockingPlatformConfig));
    }

    /**
     * 修改对接平台配置信息
     */
    @PreAuthorize("@ss.hasPermi('pile:config:edit')")
    @Log(title = "对接平台配置信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DockingPlatformConfig dockingPlatformConfig) {
        return toAjax(dockingPlatformConfigService.updateDockingPlatformConfig(dockingPlatformConfig));
    }

    /**
     * 删除对接平台配置信息
     */
    @PreAuthorize("@ss.hasPermi('pile:config:remove')")
    @Log(title = "对接平台配置信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return toAjax(dockingPlatformConfigService.deleteDockingPlatformConfigByIds(ids));
    }
}
