package com.jsowell.web.controller.thirdparty;

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

/**
 * 对接三方平台配置Controller
 *
 * @author jsowell
 * @date 2024-04-18
 */
@RestController
@RequestMapping("/thirdparty/secret")
public class ThirdpartySecretInfoController extends BaseController {
    @Autowired
    private ThirdpartySecretInfoService thirdpartySecretInfoService;

    /**
     * 查询对接三方平台配置列表
     */
    @PreAuthorize("@ss.hasPermi('thirdparty:secret:list')")
    @GetMapping("/list")
    public TableDataInfo list(ThirdpartySecretInfo thirdpartySecretInfo) {
        startPage();
        List<ThirdpartySecretInfo> list = thirdpartySecretInfoService.selectThirdpartySecretInfoList(thirdpartySecretInfo);
        return getDataTable(list);
    }

    /**
     * 导出对接三方平台配置列表
     */
    @PreAuthorize("@ss.hasPermi('thirdparty:secret:export')")
    @Log(title = "对接三方平台配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ThirdpartySecretInfo thirdpartySecretInfo) {
        List<ThirdpartySecretInfo> list = thirdpartySecretInfoService.selectThirdpartySecretInfoList(thirdpartySecretInfo);
        ExcelUtil<ThirdpartySecretInfo> util = new ExcelUtil<ThirdpartySecretInfo>(ThirdpartySecretInfo.class);
        util.exportExcel(response, list, "对接三方平台配置数据");
    }

    /**
     * 获取对接三方平台配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('thirdparty:secret:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(thirdpartySecretInfoService.selectThirdpartySecretInfoById(id));
    }

    /**
     * 新增对接三方平台配置
     */
    @PreAuthorize("@ss.hasPermi('thirdparty:secret:add')")
    @Log(title = "对接三方平台配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ThirdpartySecretInfo thirdpartySecretInfo) {
        return toAjax(thirdpartySecretInfoService.insertThirdpartySecretInfo(thirdpartySecretInfo));
    }

    /**
     * 修改对接三方平台配置
     */
    @PreAuthorize("@ss.hasPermi('thirdparty:secret:edit')")
    @Log(title = "对接三方平台配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ThirdpartySecretInfo thirdpartySecretInfo) {
        return toAjax(thirdpartySecretInfoService.updateThirdpartySecretInfo(thirdpartySecretInfo));
    }

    /**
     * 删除对接三方平台配置
     */
    @PreAuthorize("@ss.hasPermi('thirdparty:secret:remove')")
    @Log(title = "对接三方平台配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(thirdpartySecretInfoService.deleteThirdpartySecretInfoByIds(ids));
    }

    /**
     * 根据第三方平台类型查询对接第三方平台的站点列表
     */
    @PostMapping("/selectStationList")
    public AjaxResult selectStationList(@RequestBody ThirdpartySecretInfo thirdpartySecretInfo) {
        return AjaxResult.success(thirdpartySecretInfoService.selectStationList(thirdpartySecretInfo.getPlatformType()));
    }

}
