package com.muyu.system.controller;

import com.muyu.common.core.domain.Result;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.core.web.domain.BaseEntity;
import com.muyu.common.system.domain.SysFirmDatasource;
import com.muyu.system.service.SysFirmDatasourceService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 数据源信息控制层
 * @Author WangXin
 * @Data 2024/10/2
 * @Description 数据源信息控制层
 * @Version 1.0.0
 */
@RestController
@RequestMapping("/firmDatasource")
@Tag(name = "sysFirmDatasourceController", description = "数据源信息控制层")
public class SysFirmDatasourceController extends BaseController<BaseEntity> {

    @Resource
    private SysFirmDatasourceService sysFirmDatasourceService;

    /**
     * 根据id查询数据源信息
     * @param id 数据源id
     * @return 数据原信息结果集
     */
    @GetMapping("/findById/{id}")
    @Operation(summary = "根据id查询数据源信息",description = "根据id查询数据源信息")
    public Result<SysFirmDatasource> findById(@PathVariable("id") Long id) {
        return success(sysFirmDatasourceService.getById(id));
    }

    /**
     * 添加数据原信息
     * @param sysFirmDatasource 数据源信息
     * @return 添加的主键
     */
    @Operation(summary = "添加数据原信息",description = "在给公司分配数据源时添加数据源")
    @PostMapping("/addFirmDatasource")
    public Result<?> addFirmDatasource(@RequestBody SysFirmDatasource sysFirmDatasource) {
        return success(sysFirmDatasourceService.save(sysFirmDatasource));
    }


    @Operation(summary = "根据id修改数据源信息", description = "根据id修改数据源信息")
    @PutMapping("/updFindById")
    public Result<?> updFindById(@RequestBody SysFirmDatasource sysFirmDatasource) {
        return success(sysFirmDatasourceService.updateById(sysFirmDatasource));
    }

}
