package com.ruoyi.web.controller.tool;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.utils.R;
import com.ruoyi.system.domain.BerthingFloatConfig;
import com.ruoyi.system.domain.BerthingPoint;
import com.ruoyi.system.domain.BerthingPointConfig;
import com.ruoyi.system.domain.BerthingTimeConfig;
import com.ruoyi.system.dto.*;
import com.ruoyi.system.paramet.BerthingPointQuery;
import com.ruoyi.system.paramet.FloatPointQuery;
import com.ruoyi.system.paramet.StopPointQuery;
import com.ruoyi.system.paramet.TimePointQuery;
import com.ruoyi.system.service.BerthingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.ArrayList;

/**
 * @author ifei
 */
@RestController
@RequestMapping("/berthing")
@Api(tags = "断面接口")
@Anonymous
@Slf4j
public class BerthingController {


    @Resource
    private BerthingService berthingService;


    @PostMapping(value = "/uploadFile")
    @ApiOperation("上传断面Excel")
    public R<ArrayList<PrintExcelDTO>> uploadFile(@ApiParam(required = true, value = "The file to be uploaded", name = "file") @RequestPart("file") MultipartFile file) {
        return R.ok(berthingService.uploadFile(file));
    }

    @PostMapping(value = "/insertBerthing")
    @ApiOperation("新增断面")
    public R<Boolean> insertBerthing(@Valid @RequestBody BerthingPointDTO berthingPointDTO) {
        return R.ok(berthingService.insertBerthing(berthingPointDTO));
    }

    @PostMapping(value = "/queryBerthing")
    @ApiOperation("查询断面")
    public R<Page<BerthingPoint>> queryBerthing(@Valid @RequestBody BerthingPointQuery berthingPointQuery) {
        return R.ok(berthingService.queryBerthing(berthingPointQuery));
    }

    @GetMapping(value = "/{id}")
    @ApiOperation("查询断面")
    public R<BerthingPoint> queryBerthingById(@PathVariable("id") Long id) {
        return R.ok(berthingService.queryBerthingById(id));
    }

    @GetMapping(value = "/site/{id}")
    @ApiOperation("查询断面")
    public R<BerthingPoint> queryBerthingBySiteId(@PathVariable("id") Long siteId) {
        return R.ok(berthingService.queryBerthingBySiteId(siteId));
    }

    @DeleteMapping(value = "/{id}")
    @ApiOperation("删除断面")
    public R<Boolean> deleteBerthingById(@PathVariable("id") Long id) {
        return R.ok(berthingService.deleteBerthingById(id));
    }

    @GetMapping(value = "/downFile")
    @ApiOperation(value = "导出断面")
    public R<Boolean> downFile(Long siteId, HttpServletResponse response) {
        return R.ok(berthingService.downFile(siteId, response));
    }

    @GetMapping(value = "/downFile/{id}")
    @ApiOperation(value = "导出断面")
    public R<Boolean> downFileById(@PathVariable("id") Long id, HttpServletResponse response) {
        return R.ok(berthingService.downFileById(id, response));
    }

    @PostMapping(value = "/addStopPrint")
    @ApiOperation("增加或修改停泊点")
    public R<Boolean> addStopPrint(@Valid @RequestBody BerthingPointConfigDTO berthingPointConfigDTO) {
        return R.ok(berthingService.addStopPrint(berthingPointConfigDTO));
    }

    @GetMapping(value = "/stopPoint/{id}")
    @ApiOperation("查询停泊点策略")
    public R<BerthingPointConfig> queryStopPointsById(@PathVariable("id") Long id) {
        return R.ok(berthingService.queryStopPointsById(id));
    }

    @DeleteMapping(value = "/stopPoint/{id}")
    @ApiOperation("删除停泊点策略")
    public R<Boolean> deleteStopPointsById(@PathVariable("id") Long id) {
        return R.ok(berthingService.deleteStopPointsById(id));
    }

    @PostMapping(value = "/queryStopPrint")
    @ApiOperation("查询停泊点")
    public R<Page<BerthingPointConfig>> queryStopPrint(@RequestBody StopPointQuery stopPointQuery) {
        return R.ok(berthingService.queryStopPrint(stopPointQuery));
    }


    @PostMapping(value = "/addTimePrint")
    @ApiOperation("增加或修改时间策略")
    public R<Boolean> addTimePrint(@Valid @RequestBody BerthingTimeDTO berthingTimeDTO) {
        return R.ok(berthingService.addTimePrint(berthingTimeDTO));
    }

    @GetMapping(value = "/stopTime/{id}")
    @ApiOperation("查询时间策略")
    public R<BerthingTimeConfig> queryStopTimeById(@PathVariable("id") Long id) {
        return R.ok(berthingService.queryStopTimeById(id));
    }

    @DeleteMapping(value = "/stopTime/{id}")
    @ApiOperation("删除时间策略")
    public R<Boolean> deleteStopTimeById(@PathVariable("id") Long id) {
        return R.ok(berthingService.deleteStopTimeById(id));
    }

    @PostMapping(value = "/queryTimePrint")
    @ApiOperation("查询时间策略")
    public R<Page<BerthingTimeConfig>> queryTimePrint(@RequestBody TimePointQuery timePointQuery) {
        return R.ok(berthingService.queryTimePrint(timePointQuery));
    }

    @PostMapping(value = "/addFloatPrint")
    @ApiOperation("增加或修改水位变幅策略")
    public R<Boolean> addFloatPrint(@Valid @RequestBody BerthingFloatDTO berthingTimeDTO) {
        return R.ok(berthingService.addFloatPrint(berthingTimeDTO));
    }

    @PostMapping(value = "/queryFloatPrint")
    @ApiOperation("查询水位变幅策略")
    public R<Page<BerthingFloatConfig>> queryFloatPrint(@RequestBody FloatPointQuery floatPointQuery) {
        return R.ok(berthingService.queryFloatPrint(floatPointQuery));
    }

    @GetMapping(value = "/stopWater/{id}")
    @ApiOperation("查询水位变幅策略")
    public R<BerthingFloatConfig> queryStopWaterById(@PathVariable("id") Long id) {
        return R.ok(berthingService.queryStopWaterById(id));
    }

    @DeleteMapping(value = "/stopWater/{id}")
    @ApiOperation("删除水位变幅策略")
    public R<Boolean> deleteStopWaterById(@PathVariable("id") Long id) {
        return R.ok(berthingService.deleteStopWaterById(id));
    }

}
