package cn.com.victorysoft.business.indicator.controller;

import cn.com.victorysoft.business.indicator.entity.Pump;
import cn.com.victorysoft.business.indicator.entity.PumpDevice;
import cn.com.victorysoft.business.indicator.entity.PumpRealtime;
import cn.com.victorysoft.business.indicator.entity.WaterStation;
import cn.com.victorysoft.business.indicator.param.PumpDeviceExportParam;
import cn.com.victorysoft.business.indicator.param.PumpDeviceParam;
import cn.com.victorysoft.business.indicator.param.PumpParam;
import cn.com.victorysoft.business.indicator.param.WaterStationParam;
import cn.com.victorysoft.business.indicator.service.PumpDeviceService;
import cn.com.victorysoft.business.indicator.service.PumpRealtimeService;
import cn.com.victorysoft.business.sys.entity.ExportResult;
import cn.com.victorysoft.business.util.DateUtils;
import cn.com.victorysoft.business.util.ExcelUtils;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

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


@Api(tags = "注水泵设备管理")
@RestController
@RequestMapping("indicator/pumpDevice")
public class PumpDeviceController {

    @Resource
    private PumpDeviceService pumpDeviceService;
    @Resource
    private PumpRealtimeService pumpRealtimeService;

    @GetMapping("/parameter")
    @ApiOperation("注水泵及设备参数查询")
    public PageInfo<PumpDevice> parameter(PumpDeviceParam param){
        return pumpDeviceService.selectPage(param);
    }


    @PostMapping("/PumpDeviceExport")
    @ApiOperation("注水泵效日度监测导出")
    public ExportResult PumpDeviceExport(@RequestBody PumpDeviceExportParam param){
        List<PumpDevice> list = pumpDeviceService.selectList(param);
        return ExcelUtils.export(param.getColumnConfig(), list, param.getFileName());
    }

    @GetMapping("/WaterStations")
    @ApiOperation("查询注水站")
    public List<WaterStation> WaterStations(WaterStationParam param){
        return pumpDeviceService.selectWaterStations(param);
    }


    @GetMapping("/selectPump")
    @ApiOperation("查询注水泵")
    public List<Pump> selectPump(PumpParam param){
        return pumpDeviceService.selectPump(param);
    }


    @PutMapping("/update")
    @ApiOperation("注水泵及设备参数修改")
    public int update(@RequestBody PumpDevice param) {
        return pumpDeviceService.updateData(param);
    }

    @GetMapping("/realtime")
    @ApiOperation("注水泵实时数据")
    public List<PumpRealtime> realtime(String pumpId) {
        Date endDate = new Date();
        Date startDate = DateUtils.addHours(endDate, -1);
        return pumpRealtimeService.getData(pumpId, startDate, endDate);
    }
}
