package com.trade.admin.tradingPlatform.controller;


import com.trade.admin.system.controller.BaseController;
import com.trade.common.core.domain.ResponseResult;
import com.trade.common.core.page.GridPage;
import com.trade.common.enums.BusinessType;
import com.trade.admin.annotation.Log;
import com.trade.service.tradingPlatform.dto.TradingPlatformBaseInfo;
import com.trade.service.tradingPlatform.dto.TradingPlatformDto;
import com.trade.service.tradingPlatform.dto.TradingPlatformSearchDto;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.trade.admin.tradingPlatform.service.TradingPlatformService;


import javax.annotation.Resource;


/**
 * 贸易平台接口
 *
 * @author hlb
 * @since 2024-06-05 17:00:43
 */
@RestController
@RequestMapping("/tradingPlatform")
public class TradingPlatformController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private TradingPlatformService tradingPlatformService;

    /**
     * 贸易平台基础信息列表查询
     *
     * @param search 查询实体
     * @return 所有数据
     */
    @GetMapping("/pages")
    @PreAuthorize("@ss.hasPermi('tradingPlatform:tradingPlatform:query')")
    public ResponseResult<GridPage<TradingPlatformBaseInfo>> getPages(@RequestBody TradingPlatformSearchDto search) {
        GridPage<TradingPlatformBaseInfo> pages = tradingPlatformService.getPages(search);
        return success(pages);
    }

    /**
     * 根据id查询贸易平台详细信息
     *
     * @param id 主键
     * @return 贸易平台
     */
    @GetMapping("/{id}")
    @PreAuthorize("@ss.hasPermi('tradingPlatform:tradingPlatform:query')")
    public ResponseResult<TradingPlatformDto> queryById(@PathVariable Long id) {
        TradingPlatformDto tradingPlatformDto = tradingPlatformService.queryById(id);
        return success(tradingPlatformDto);
    }

    /**
     * 新增、编辑贸易平台
     *
     * @param confirmed          是否是确认，新增时必填（true or false），编辑时不填
     * @param tradingPlatformDto 实体对象
     * @return 贸易平台id
     */
    @PostMapping("/upsert")
    @PreAuthorize("@ss.hasPermi('tradingPlatform:tradingPlatform:add')")
    @Log(title = "贸易平台", businessType = BusinessType.INSERT)
    public ResponseResult<Long> saveTradingPlatform(@RequestParam(value = "confirmed", required = false, defaultValue = "false") Boolean confirmed,
                                                    @RequestBody TradingPlatformDto tradingPlatformDto) {
        Long id = tradingPlatformService.saveTradingPlatform(confirmed, tradingPlatformDto);
        return success(id);
    }
}

