/*
 * Author: wangjian
 * 生成controller
 */
package com.tofly.dispatch.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.common.oauth.util.SecurityUtils;
import com.tofly.dispatch.dto.DispatchLogDto;
import com.tofly.dispatch.dto.DispatchLogQuery;
import com.tofly.dispatch.entity.Dispatch;
import com.tofly.dispatch.entity.DispatchLog;
import com.tofly.dispatch.service.DispatchLogService;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.validation.annotation.Validated;
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 javax.validation.Valid;
import java.util.Arrays;

/**
 * 调度日志记录
 *
 * @author admin
 * @date Thu Nov 10 00:00:00 CST 2022
 */
@RestController
@AllArgsConstructor
@RequestMapping("/dispatchlog")
@Api(tags = "调度日志记录-接口")
public class DispatchLogController {

    private final DispatchLogService dispatchLogService;

    /**
     * 分页查询
     *
     * @param page        分页对象
     * @param dispatchLogQuery 调度日志记录
     * @return
     */
    @GetMapping("/page")
    @ApiOperation(value = "分页查询")
    public ResultRespone getDispatchLogPage(Page page, @ModelAttribute DispatchLogQuery dispatchLogQuery) {
        return ResultRespone.success(dispatchLogService.getPageData(page, dispatchLogQuery));
    }


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

    /**
     * 新增调度日志记录
     *
     * @param dispatchLogDto 调度日志记录
     * @return ResultRespone
     */
    @ToFlyAppLog(title = "新增调度日志记录")
    @ApiOperation(value = "新增调度日志记录")
    @PostMapping
    public ResultRespone save(@RequestBody @Valid DispatchLogDto dispatchLogDto) {
        return ResultRespone.success(dispatchLogService.saveDispatchLog(dispatchLogDto, true));
    }

    /**
     * 修改调度日志记录
     *
     * @param dispatchLogDto 调度日志记录
     * @return ResultRespone
     */
    @ToFlyAppLog(title = "修改调度日志记录")
    @ApiOperation(value = "修改调度日志记录")
    @PutMapping
    public ResultRespone updateById(@RequestBody @Valid DispatchLogDto dispatchLogDto) {
        return ResultRespone.success(dispatchLogService.saveDispatchLog(dispatchLogDto, false));
    }

    /**
     * 通过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(dispatchLogService.deleteByIds(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 removeById(String ids) {
        return ResultRespone.success(dispatchLogService.deleteByIds(ids));
    }
}
