package com.tofly.water.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.tofly.water.entity.ScadaStatusDuration;
import com.tofly.water.entity.dto.OverviewDto;
import com.tofly.water.entity.dto.ScadaStatusDurationDto;
import com.tofly.water.entity.dto.StatisticsRealDto;
import com.tofly.water.entity.vo.DeviceBusPumpsVo;
import com.tofly.water.service.ScadaStatusDurationService;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import com.tofly.common.core.entity.ResultRespone;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import com.tofly.common.log.annotation.ToFlyAppLog;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * 记录设备运行时长状态(ScadaStatusDuration)表控制层
 *
 * @author HaiQiu
 * @since 2022-12-26 16:37:24
 */
@Api(tags = "记录设备运行时长状态")
@RestController
@RequestMapping("scadaStatusDuration")
public class ScadaStatusDurationController {
    /**
     * 服务对象
     */
    @Resource
    private ScadaStatusDurationService scadaStatusDurationService;

    /**
     * 分页查询数据
     *
     * @param page                分页对象
     * @param scadaStatusDuration 查询实体
     * @return 所有数据
     */
    @ToFlyAppLog(title = "记录设备运行时长状态-分页查询数据")
    @ApiOperation(value = "分页查询数据")
    @GetMapping("/page")
    public ResultRespone<Page<ScadaStatusDuration>> pageList(Page page, ScadaStatusDuration scadaStatusDuration) {
        return ResultRespone.success(scadaStatusDurationService.pageList(page, scadaStatusDuration), "查询成功");
    }

    /**
     * 查询所有数据
     *
     * @param scadaStatusDuration 查询实体
     * @return 所有数据
     */
    @ToFlyAppLog(title = "记录设备运行时长状态-查询所有数据")
    @ApiOperation(value = "查询所有数据")
    @GetMapping("/list")
    public ResultRespone<List<ScadaStatusDuration>> allList(ScadaStatusDuration scadaStatusDuration) {
        return ResultRespone.success(scadaStatusDurationService.allList(scadaStatusDuration), "查询成功");
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @ToFlyAppLog(title = "记录设备运行时长状态-通过主键查询单条数据")
    @ApiOperation(value = "通过主键查询单条数据")
    @ApiImplicitParam(name = "id", value = "数据ID")
    @GetMapping("{id}")
    public ResultRespone<ScadaStatusDuration> get(@PathVariable Serializable id) {
        return ResultRespone.success(scadaStatusDurationService.get(id), "查询成功");
    }

    /**
     * 新增数据
     *
     * @param scadaStatusDurationDto 实体
     * @return 新增结果
     */
    @ToFlyAppLog(title = "记录设备运行时长状态-新增数据")
    @ApiOperation(value = "新增数据")
    @PostMapping
    public ResultRespone insert(@Validated @RequestBody ScadaStatusDurationDto scadaStatusDurationDto) {
        scadaStatusDurationService.insert(scadaStatusDurationDto);
        return ResultRespone.success(null, "新增成功");
    }

    /**
     * 修改数据
     *
     * @param scadaStatusDurationDto 实体
     * @return 修改结果
     */
    @ToFlyAppLog(title = "记录设备运行时长状态-修改数据")
    @ApiOperation(value = "修改数据")
    @PutMapping
    public ResultRespone edit(@Validated @RequestBody ScadaStatusDurationDto scadaStatusDurationDto) {
        scadaStatusDurationService.edit(scadaStatusDurationDto);
        return ResultRespone.success(null, "修改成功");
    }

    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @ToFlyAppLog(title = "记录设备运行时长状态-删除数据")
    @ApiOperation(value = "删除数据")
    @ApiImplicitParam(name = "idList", value = "数据ID数组集合")
    @DeleteMapping
    public ResultRespone delete(@RequestParam("idList") List<Long> idList) {
        scadaStatusDurationService.delete(idList);
        return ResultRespone.success(null, "删除成功");
    }

    /**
     * 数据导入Excel模板下载
     */
    @ToFlyAppLog(title = "记录设备运行时长状态-模版下载")
    @ApiOperation(value = "模版下载")
    @GetMapping("/template")
    public void template() {
        scadaStatusDurationService.template();
    }

    /**
     * Excel数据导入
     *
     * @param file 导入的Excel数据文件
     * @return 导入结果
     */
    @ToFlyAppLog(title = "记录设备运行时长状态-Excel数据导入")
    @ApiOperation(value = "数据导入")
    @ApiImplicitParam(name = "file", value = "Excel文件", required = true)
    @PostMapping("/import")
    public ResultRespone importData(@RequestParam(name = "file") MultipartFile file) {
        scadaStatusDurationService.importData(file);
        return ResultRespone.success(null, "导入成功");
    }


    /**
     * 数据导出
     *
     * @param page                分页
     * @param scadaStatusDuration 查询模型
     * @param isAll               是否导出全部数据，true是，false否
     */
    @ToFlyAppLog(title = "记录设备运行时长状态-数据导出")
    @ApiOperation(value = "数据导出")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "isAll", value = "是否导出全部数据，true是，false否（默认否）"),
    })
    @GetMapping("/export")
    public void export(Page page, ScadaStatusDuration scadaStatusDuration, boolean isAll) {
        scadaStatusDurationService.export(page, scadaStatusDuration, isAll);
    }


    @ApiOperation(value = "手动同步运行时长状态数据")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "start", value = "开始时间：yyyy-MM-dd HH:mm:ss"),
            @ApiImplicitParam(name = "end", value = "结束时间：yyyy-MM-dd HH:mm:ss"),
    })
    @GetMapping("runTime")
    public ResultRespone timingInsertData(@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @RequestParam("start") Date start,
                                                  @RequestParam("end")@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date end ) {
        scadaStatusDurationService.timingInsertData(start,end);
        return ResultRespone.success("成功");
    }

    @ApiOperation(value = "调度分析 ")
    @GetMapping("/statistics/real")
    public ResultRespone statisticsReal(Page page, StatisticsRealDto dto) {
        return ResultRespone.success(scadaStatusDurationService.statisticsReal(page, dto));
    }

}

