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

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.dispatch.common.FlowConstant;
import com.tofly.dispatch.dto.BatchDispatchInfoDto;
import com.tofly.dispatch.dto.LoadDispatchInfoDto;
import com.tofly.dispatch.dto.UpdateDispatchInfoDto;
import com.tofly.dispatch.service.DispatchInfoService;
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.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.Arrays;

/**
 * 供水调度详情（水压）时序数据
 *
 * @author xqf
 * @date Mon Mar 14 00:00:00 CST 2022
 */
@RestController
@AllArgsConstructor
@RequestMapping("/dispatchinfo")
@Api(tags="调度方案详情数据-接口")
public class DispatchInfoController {

    private final  DispatchInfoService dispatchInfoService;

    /**
    * 分页查询
    * @param page 分页对象
    * @param vo 供水调度详情（水压）时序数据
    * @return
    */
    @GetMapping("/page" )
    @ApiOperation(value = "分页查询")
    public ResultRespone getDispatchInfoPage(HttpServletResponse response, Page page, @ModelAttribute LoadDispatchInfoDto vo) {

        Object obj = dispatchInfoService.exportOrPageDispatchInfo(response,page,vo);
        if(obj instanceof String){
            return ResultRespone.failed(false,String.valueOf(obj));
        }else  {
            return ResultRespone.success(obj,FlowConstant.SUCCESS);
        }

    }


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

    /**
     * 批量新增供水调度详情（水压）时序数据
     * @param dto 供水调度详情（水压）时序数据
     * @return ResultRespone
     */
    @ToFlyAppLog(title="批量新增供水调度详情（水压）时序数据" )
    @ApiOperation(value = "批量新增供水调度详情（水压）时序数据")
    @PostMapping("/batchSave")
    public ResultRespone batchSave(@RequestBody BatchDispatchInfoDto dto) {
        Object obj = dispatchInfoService.saveDispatchInfo(dto);
        if(obj instanceof Boolean){
            if((boolean) obj){
                return ResultRespone.success(true,FlowConstant.SUCCESS);
            }else {
                return ResultRespone.failed(false,FlowConstant.FAILED);
            }
        }else {
            return ResultRespone.failed(false,String.valueOf(obj));
        }
    }

    /**
     * 导入供水调度信息 时序数据
     * @param id 方案id
     * @param fileList 文件
     * @return
     */
    @ToFlyAppLog(title="导入供水调度信息 时序数据" )
    @ApiOperation(value = "导入供水调度信息 时序数据")
    @PostMapping("/importSave")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "方案id", required = true, dataType = "Long")
    })
    public ResultRespone importSave(Long id, MultipartFile fileList){
        Object obj = dispatchInfoService.saveDispatchInfo(id,fileList);
        if(obj instanceof Boolean){
            if((boolean) obj){
                return ResultRespone.success(true,FlowConstant.SUCCESS);
            }else {
                return ResultRespone.failed(false,FlowConstant.FAILED);
            }
        }else {
            return ResultRespone.failed(false,String.valueOf(obj));
        }

    }

    /**
     * 修改调度方案信息，单条数据修改  时序数据
     * @param dto
     * @return
     */
    @ToFlyAppLog(title="修改调度方案信息，单条数据修改  时序数据" )
    @ApiOperation(value = "修改调度方案信息，单条数据修改  时序数据")
    @PostMapping("/update")
    public ResultRespone updateDispatchInfo(@RequestBody @Valid UpdateDispatchInfoDto dto){
        Object obj = dispatchInfoService.updateDispatchInfoDto(dto);
        if(obj instanceof Boolean){
            if((boolean) obj){
                return ResultRespone.success(true,FlowConstant.SUCCESS);
            }else {
                return ResultRespone.failed(false,FlowConstant.FAILED);
            }
        }else {
            return ResultRespone.failed(false,String.valueOf(obj));
        }
    }



    /**
     * 通过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(dispatchInfoService.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 removeById(String ids) {
        return ResultRespone.success(dispatchInfoService.removeByIds(Arrays.asList(ids.split(","))));
    }
}
