/*
 * 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.BaseSys;
import com.tofly.base.service.BaseSysService;
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;
/**
 * 
 *
 * @author wangjian
 * @date Tue Jul 07 00:00:00 CST 2020
 */
@RestController
@AllArgsConstructor
@RequestMapping("/basesys")
@Api(tags="系统接口")
public class BaseSysController {

    private final  BaseSysService baseSysService;

    /**
    * 分页查询
    * @param page 分页对象
    * @param baseSys 
    * @return
    */
    @GetMapping("/page" )
    @ApiOperation(value = "分页查询")
    public ResultRespone getBaseSysPage(Page page, @ModelAttribute BaseSys baseSys) {
      return ResultRespone.success(baseSysService.page(page, Wrappers.query(baseSys).lambda().orderByAsc(BaseSys::getCreateTime)));
    }


    /**
     * 通过id查询
     * @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(baseSysService.getById(id));
    }

    /**
     * 新增
     * @param baseSys 
     * @return ResultRespone
     */
    @ToFlyAppLog(title="新增" )
    @ApiOperation(value = "新增")
    @PostMapping
    public ResultRespone save(@RequestBody BaseSys baseSys) {
      return ResultRespone.success(baseSysService.save(baseSys));
    }

    /**
     * 修改
     * @param baseSys 
     * @return ResultRespone
     */
    @ToFlyAppLog(title="修改" )
    @ApiOperation(value = "修改")
    @PutMapping
    public ResultRespone updateById(@RequestBody BaseSys baseSys) {
      return ResultRespone.success(baseSysService.updateById(baseSys));
    }

    /**
     * 通过id删除
     * @param id id
     * @return ResultRespone
     */
    @ToFlyAppLog(title="通过id删除" )
    @ApiOperation(value = "通过ID删除")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "Long")
    })
    @DeleteMapping("/{id}" )
    public ResultRespone removeById(@PathVariable Long id) {
      return ResultRespone.success(baseSysService.removeById(id));
    }

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