package com.bz.rmcp.dap.controller;

import com.alibaba.fastjson.JSON;
import com.bz.rmcp.dap.model.DeviceOrigDataDTO;
import com.bz.rmcp.dap.model.OfflineData;
import com.bz.rmcp.dap.mq.MqMessageSender;
import com.bz.rmcp.dap.service.DeviceDataService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @author linqingwei
 * @date 2021-08-09 17:40
 */
@Slf4j
@RequestMapping("rabbitmq")
@RestController
public class RabbitMqMsgController {
    @Autowired
    private MqMessageSender sender;
    @Autowired
    private DeviceDataService deviceDataService;

    @PostMapping("sendmsg")
    public void sendMsg(OfflineData data){
        log.info("当前时间：{},收到请求，data:{}", new Date(), data);
        sender.sendDelayMsg(data);
    }

    @PostMapping("sendDeviceData")
    public void sendDeviceData(){
        Map<String,Object> param = new HashMap<>();
        param.put("currentQuantity",107.4);
        param.put("valveState","1");
        param.put("temp","0");
        param.put("WSV",90);
        param.put("VALVE","01");

        Map<Date,String> map = new HashMap<>();
        map.put(new Date(), JSON.toJSONString(param));

        DeviceOrigDataDTO dto = new DeviceOrigDataDTO();
        dto.setId(1L);
        dto.setAgentIdentifier("");
        dto.setDeviceNo("11111111111");
        dto.setMode("");
        dto.setType("");
        dto.setManufacturer("");
        dto.setOriginalDataFormat("");
        dto.setOriginalData("");
        dto.setParsedData(map);
        dto.setEventTime(new Date());
        dto.setReceiveTime(new Date());


        deviceDataService.saveDeviceData(dto);
    }
}
