/*
 * Author: wangjian
 * 生成controller
 */
package com.tofly.xrtymis.custom.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.xrtymis.custom.service.RedeployService;
import com.tofly.xrtymis.entity.Redeploy;
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 fcl
 * @date Fri Jun 11 00:00:00 CST 2021
 */
@RestController
@AllArgsConstructor
@RequestMapping("/redeploy")
@Api(tags="转派记录接口")
public class RedeployController {

    private final RedeployService redeployService;

    /**
    * 分页查询
    * @param page 分页对象
    * @param redeploy
    * @return
    */
    @GetMapping("/page" )
    @ApiOperation(value = "分页查询")
    public ResultRespone getRedeployPage(Page page, @ModelAttribute Redeploy redeploy) {
      return ResultRespone.success(redeployService.page(page, Wrappers.query(redeploy)));
    }


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

    /**
     * 新增${comments}
     * @param redeploy ${comments}
     * @return ResultRespone
     */
    @ToFlyAppLog(title="新增" )
    @ApiOperation(value = "新增")
    @PostMapping
    public ResultRespone save(@RequestBody Redeploy redeploy) {
      return ResultRespone.success(redeployService.save(redeploy));
    }

    /**
     * 修改${comments}
     * @param redeploy ${comments}
     * @return ResultRespone
     */
    @ToFlyAppLog(title="修改" )
    @ApiOperation(value = "修改")
    @PutMapping
    public ResultRespone updateById(@RequestBody Redeploy redeploy) {
      return ResultRespone.success(redeployService.updateById(redeploy));
    }

    /**
     * 通过id删除${comments}
     * @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(redeployService.removeById(id));
    }

    /**
     * 通过id批量删除${comments}
     * @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 removeById(String ids) {
        return ResultRespone.success(redeployService.removeByIds(Arrays.asList(ids.split(","))));
    }
}
