package im.zhaojun.system.controller;

import com.github.pagehelper.PageInfo;
import im.zhaojun.common.util.PageResultBean;
import im.zhaojun.common.util.ResultBean;
import im.zhaojun.system.model.*;
import im.zhaojun.system.service.EventWriteService;
import im.zhaojun.system.service.TraffdevicewriteresultService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.List;

@RestController
@RequestMapping("/traffresult")
public class TraffdevicewriteresultController {
    @Autowired
    private TraffdevicewriteresultService traffdevicewriteresultService;

    @Value("${eventsend.url}")
    String eventsendurl;

    @Value("${devicesend.url}")
    String devicesendurl;

    @Value("${devicesend.timeout}")
    private Integer timeout;

    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private EventWriteService eventWriteService;


    /**
     * 查询推送成功分页
     */
    @PostMapping("/queryTraffdevicewriteresultByPage")
    public PageResultBean<Traffdevicewriteresult> queryTraffdevicewriteresultByPage(@RequestBody TraffdevicewriteresultParams traffdevicewriteresult) {

        List<Traffdevicewriteresult> list= traffdevicewriteresultService.queryTraffdevicewriteresultByPage(traffdevicewriteresult);
        PageInfo<Traffdevicewriteresult> rolePageInfo = new PageInfo<>(list);
        return new  PageResultBean<>(rolePageInfo.getTotal(), rolePageInfo.getList());
    }

    /**
     * 查询所有监控推送状态分页
     */
    @PostMapping("/querySbtdspsrResultByPage")
    public PageResultBean<SbtdspsrResult>  querySbtdspsrResultByPage(@RequestBody SbtdspsrParams sbtdspsr) {
        List<SbtdspsrResult> list=traffdevicewriteresultService.querySbtdspsrResultByPage(sbtdspsr);
        PageInfo<SbtdspsrResult> rolePageInfo = new PageInfo<>(list);
        return new PageResultBean<>(rolePageInfo.getTotal(), rolePageInfo.getList());
    }
    /**
     * 推送数据到推送平台     */
    @PostMapping("/sendEvents")
    public List<ResultObj> sendEvents(@RequestBody  List<Traffalarmrecord> recordidlist){

        return eventWriteService.sendAllMessage(recordidlist);

    }

    /**
     * 推送数据到推送平台     */
    @PostMapping("/sendDevices")
    public List<ResultObj> sendDevices(@RequestBody  List<SbtdspsrParams> sbtdspsrlist){
        return traffdevicewriteresultService.sendDevices(sbtdspsrlist);
    }



    /**
     * 添加
     */
    @PostMapping("/saveTraffdevicewriteresult")
    public ResultObj saveTraffdevicewriteresult(Traffdevicewriteresult traffdevicewriteresult) {
        return traffdevicewriteresultService.saveTraffdevicewriteresult(traffdevicewriteresult);
    }

    /**
     * 批量添加
     */
    @PostMapping("/saveTraffdevicewriteresultList")
    public  ResultBean saveTraffdevicewriteresultList(List<Traffdevicewriteresult> traffdevicewriteresultList) {
         traffdevicewriteresultService.saveTraffdevicewriteresultList(traffdevicewriteresultList);
        return ResultBean.success();
    }

    /**
     * 更新
     */
    @PostMapping("/updateTraffdevicewriteresult")
    public ResultBean updateTraffdevicewriteresult(Traffdevicewriteresult traffdevicewriteresult) {
         traffdevicewriteresultService.updateTraffdevicewriteresult(traffdevicewriteresult);
         return ResultBean.success();
    }

    /**
     * 删除
     */
    @PostMapping("/deleteTraffdevicewriteresult")
    public ResultBean deleteTraffdevicewriteresult(Traffdevicewriteresult traffdevicewriteresult) {
        traffdevicewriteresultService.deleteTraffdevicewriteresult(traffdevicewriteresult);
        return ResultBean.success();
    }

    /**
     * 批量删除
     */
    @PostMapping("/deleteTraffdevicewriteresultList")
    public ResultBean deleteTraffdevicewriteresultList(List<Traffdevicewriteresult> traffdevicewriteresultList) {
        traffdevicewriteresultService.deleteTraffdevicewriteresultList(traffdevicewriteresultList);
        return ResultBean.success();
    }

}