/*
 * Author: wangjian
 * 生成controller
 */
package com.tofly.base.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tofly.common.core.entity.ResultRespone;
import com.tofly.common.log.annotation.ToFlyAppLog;
import com.tofly.base.entity.Paramconfig;
import com.tofly.base.service.ParamconfigService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.web.bind.annotation.ModelAttribute;

import java.util.Arrays;

/**
 * 参数配置信息表：TF_YWPN_PARAMCONFIG_W
 *
 * @author admin
 * @date Thu May 13 00:00:00 CST 2021
 */
@RestController
@AllArgsConstructor
@RequestMapping("/paramconfig")
@Api(tags = "参数配置信息表接口")
public class ParamconfigController {

    private final ParamconfigService paramconfigService;

    /**
     * 分页查询
     *
     * @param page        分页对象
     * @param paramconfig 参数配置信息表：TF_YWPN_PARAMCONFIG_W
     * @return
     */
    @GetMapping("/page")
    @ApiOperation(value = "分页查询")
    public ResultRespone getParamconfigPage(Page page, @ModelAttribute Paramconfig paramconfig) {
        return ResultRespone.success(paramconfigService.page(page, Wrappers.query(paramconfig)));
    }


    /**
     * 通过id查询参数配置信息表：TF_YWPN_PARAMCONFIG_W
     *
     * @param id id
     * @return ResultRespone
     */
    @GetMapping("/{id}")
    @ApiOperation(value = "通过ID查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "Long")
    })
    public ResultRespone getById(@PathVariable("id") Long id) {
        return ResultRespone.success(paramconfigService.getById(id));
    }

    /**
     * 新增参数配置信息表：TF_YWPN_PARAMCONFIG_W
     *
     * @param paramconfig 参数配置信息表：TF_YWPN_PARAMCONFIG_W
     * @return ResultRespone
     */
    @ToFlyAppLog(title = "新增参数配置信息表：TF_YWPN_PARAMCONFIG_W")
    @ApiOperation(value = "新增参数配置信息表：TF_YWPN_PARAMCONFIG_W")
    @PostMapping
    public ResultRespone save(@RequestBody Paramconfig paramconfig) {
        return ResultRespone.success(paramconfigService.save(paramconfig));
    }

    /**
     * 修改参数配置信息表：TF_YWPN_PARAMCONFIG_W
     *
     * @param paramconfig 参数配置信息表：TF_YWPN_PARAMCONFIG_W
     * @return ResultRespone
     */
    @ToFlyAppLog(title = "修改参数配置信息表：TF_YWPN_PARAMCONFIG_W")
    @ApiOperation(value = "修改参数配置信息表：TF_YWPN_PARAMCONFIG_W")
    @PutMapping
    public ResultRespone updateById(@RequestBody Paramconfig paramconfig) {
        if (paramconfig.getId() != null && paramconfig.getId() > 0) {
            return ResultRespone.success(paramconfigService.updateById(paramconfig));
        } else {
            return ResultRespone.success(paramconfigService.save(paramconfig));
        }
    }

    /**
     * 通过id删除参数配置信息表：TF_YWPN_PARAMCONFIG_W
     *
     * @param id id
     * @return ResultRespone
     */
    @ToFlyAppLog(title = "通过id删除参数配置信息表：TF_YWPN_PARAMCONFIG_W")
    @ApiOperation(value = "通过ID删除参数配置信息表：TF_YWPN_PARAMCONFIG_W")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "Long")
    })
    @DeleteMapping("/{id}")
    public ResultRespone removeById(@PathVariable Long id) {
        return ResultRespone.success(paramconfigService.removeById(id));
    }

    /**
     * 通过id批量删除参数配置信息表：TF_YWPN_PARAMCONFIG_W
     *
     * @param ids id
     * @return ResultRespone
     */
    @ToFlyAppLog(title = "通过id批量删除参数配置信息表：TF_YWPN_PARAMCONFIG_W")
    @ApiOperation(value = "通过ID批量删除参数配置信息表：TF_YWPN_PARAMCONFIG_W")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "批量删除，多个id以逗号隔开", required = true, dataType = "String")
    })
    @DeleteMapping("/deleteByIds")
    public ResultRespone removeById(String ids) {
        return ResultRespone.success(paramconfigService.removeByIds(Arrays.asList(ids.split(","))));
    }
}
