Newer
Older
huludao / src / main / java / com / newfiber / modules / gate / controller / MonitorController.java
package com.newfiber.modules.gate.controller;

import com.newfiber.common.utils.R;
import com.newfiber.modules.gate.entity.request.GateParams;
import com.newfiber.modules.gate.entity.request.RemoteParams;
import com.newfiber.modules.gate.service.MonitorService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 闸门数据监测
 * */
@RestController
@RequestMapping("/monitor")
public class MonitorController {

    @Autowired
    private MonitorService monitorService;

    /**
     * 站点列表
     * */
    @RequestMapping("/siteList")
    public R querySiteList(){
       return R.ok().put("result",monitorService.querySiteList());
    }

    @RequestMapping("/selectByCode")
    public R selectByCode(String stCode){
        return R.ok().put("result",monitorService.selectByCode(stCode));
    }

    /**
     * 水位信息
     * */
    @PostMapping("/siteLevel")
    public R siteLevel(@RequestBody GateParams gateParams){
        String stCode=gateParams.getStCode();
        String beginTime=gateParams.getBeginTime();
        String endTime=gateParams.getEndTime();
        if(StringUtils.isNotEmpty(stCode) && StringUtils.isNotEmpty(beginTime) && StringUtils.isNotEmpty(endTime)){
            return R.ok().put("result",monitorService.queryLevel(stCode,beginTime,endTime));
        }else{
            return R.error("参数不正确!");
        }
    }

    /**
     * 闸站闸门状态
     * */
    @PostMapping("/status")
    public R status(@RequestBody GateParams gateParams){
        String stCode=gateParams.getStCode();
        if(StringUtils.isNotEmpty(stCode)){
            return R.ok().put("result",monitorService.queryStatus(stCode));
        }else{
            return R.error("参数不正确!");
        }
    }

    /**
     * 远程控制
     * */
    @PostMapping("/remote")
    @Transactional
    public R remote(@RequestBody RemoteParams params){
        String stCode=params.getStCode();
        String deviceCode=params.getDeviceCode();
        String downLinkPoint= params.getDownLinkPoint();
        if(StringUtils.isNotEmpty(stCode) && StringUtils.isNotEmpty(deviceCode) || StringUtils.isNotEmpty(downLinkPoint)){
            monitorService.updateStatus(stCode,deviceCode,downLinkPoint);
            //增加任务
            monitorService.saveTask(stCode,downLinkPoint);
        }else{
            return R.error("参数不正确!");
        }
        return R.ok();
    }

    /**
     * 实时数据
     * */
    @PostMapping("/currentData")
    public R currentData(@RequestBody GateParams gateParams){
        String stCode=gateParams.getStCode();
        if(StringUtils.isNotEmpty(stCode)){
            return R.ok().put("result",monitorService.getCurrentData(stCode));
        }else{
            return R.error("参数不正确!");
        }
    }

    /**
     * 历史数据
     * */
    @PostMapping("/history")
    public R history(@RequestBody GateParams gateParams){
        String stCode=gateParams.getStCode();
        if(StringUtils.isNotEmpty(stCode)){
            return R.ok().put("result",monitorService.history(gateParams));
        }else{
            return R.error("参数不正确!");
        }
    }

}