/*
 * 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.base.entity.Sdeversion;
import com.tofly.base.entity.UserSdeversion;
import com.tofly.base.service.SdeversionService;
import com.tofly.common.core.entity.ResultRespone;
import com.tofly.common.log.annotation.ToFlyAppLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 上图员数据版本记录表
 *
 * @author wangjian
 * @date Thu Apr 09 00:00:00 CST 2020
 */
@RestController
@AllArgsConstructor
@RequestMapping("/sdeversion")
@Api(tags="上图员数据版本记录表接口")
public class SdeversionController {

    private final  SdeversionService sdeversionService;

    /**
    * 分页查询
    * @param page 分页对象
    * @param sdeversion 上图员数据版本记录表
    * @return
    */
    @GetMapping("/page" )
    @ApiOperation(value = "分页查询")
    public ResultRespone getSdeversionPage(Page page, @ModelAttribute Sdeversion sdeversion) {
      return ResultRespone.success(sdeversionService.page(page, Wrappers.query(sdeversion)));
    }

    /**
     * 分页查询
     * @param page 分页对象
     * @param sdeversion 上图员数据版本记录表
     * @return
     */
    @GetMapping("/userPage" )
    @ApiOperation(value = "查询用户数据版本记录")
    public ResultRespone getUserPage(Page page, @ModelAttribute UserSdeversion sdeversion) {
        return ResultRespone.success(sdeversionService.getUserSdeversionMap(page,sdeversion));
    }


    /**
     * 通过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(sdeversionService.getById(id));
    }

    /**
     * 新增上图员数据版本记录表
     * @param sdeversion 上图员数据版本记录表
     * @return ResultRespone
     */
    @ToFlyAppLog(title="新增上图员数据版本记录表" )
    @ApiOperation(value = "新增上图员数据版本记录表")
    @PostMapping
    public ResultRespone save(@RequestBody Sdeversion sdeversion) {
      return ResultRespone.success(sdeversionService.save(sdeversion));
    }

    /**
     * 修改上图员数据版本记录表
     * @param sdeversion 上图员数据版本记录表
     * @return ResultRespone
     */
    @ToFlyAppLog(title="修改上图员数据版本记录表" )
    @ApiOperation(value = "修改上图员数据版本记录表")
    @PutMapping
    public ResultRespone updateById(@RequestBody Sdeversion sdeversion) {
      return ResultRespone.success(sdeversionService.updateById(sdeversion));
    }

    /**
     * 通过id删除上图员数据版本记录表
     * @param userId userId
     * @return ResultRespone
     */
    @ToFlyAppLog(title="通过用户id删除上图员数据版本记录表" )
    @ApiOperation(value = "通过用户ID删除上图员数据版本记录表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户ID", required = true, dataType = "Long")
    })
    @DeleteMapping("/{userId}" )
    public ResultRespone removeById(@PathVariable Long userId) {
      return ResultRespone.success(sdeversionService.remove(Wrappers.<Sdeversion>lambdaQuery()
              .eq(Sdeversion::getUserId,userId)));
    }
}
