package com.huimv.eartag.controller;

import com.huimv.eartag.producer.ManageProducer;
import com.huimv.eartag.service.IDeviceManageService;
import com.huimv.eartag.utils.Const;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.util.HashMap;
import java.util.Map;

/**
 * @Project : huimv.shiwan
 * @Package : com.huimv.biosafety.uface.controller
 * @Description : TODO
 * @Version : 1.0
 * @Author : ZhuoNing
 * @Create : 2020-12-25
 **/
@RestController
@RequestMapping("/test")
public class TestController {
    @Autowired
    private IDeviceManageService deviceService;
    @Autowired
    RabbitTemplate rabbitTemplate;  //使用RabbitTemplate,这提供了接收/发送等等方法
    @Autowired
    private ManageProducer producer;

    @GetMapping("/sendMq")
    public void sendMq(){
        Map map = new HashMap();
        String askText = "hm+202007239999866+4+1+247+20220407140548+0+end";
        map.put("askText",askText);
        rabbitTemplate.convertAndSend(Const.EXCHANGE_ASK_DEVICE, Const.ROUTING_KEY_ASK_DEVICE, map);
        System.out.println("同步设备注册信息 >>"+map.toString());
    }

    @GetMapping("/getName")
    public String getName(){
        return "Hello,World.";
    }

    //
    @PostMapping("/testRemoteProcessFarmAllStatus")
    public void testRemoteProcessFarmAllStatus() throws ParseException {
//        deviceService.remoteProcessFarmAllStatus("101");
    }

    @PostMapping("/testSendMq")
    public void testSendMq() throws ParseException {
        System.out.println("2.");
        Map map = new HashMap();
        map.put("deviceRegister","{\"activeStatus\":0,\"chipId\":\"30\",\"createDate\":1647878400000,\"deviceAlias\":\"\",\"deviceCode\":\"30\",\"deviceStatus\":0,\"farmId\":\"101\",\"id\":52,\"location\":\"\",\"registerTime\":1647955296670,\"remark\":\"\"}");
//        map.put("deviceRegister","123");

        rabbitTemplate.convertAndSend(Const.EXCHANGE_SYNC_DEVICE_REGISTER, Const.ROUTING_KEY_SYNC_DEVICE_REGISTER, map);
        System.out.println("同步设备注册信息 >>"+map.toString());
        System.out.println("2.1");
//        return "ok";
    }


    @PostMapping("/testSendMq2")
    public void testSendMq2() throws ParseException {
        String msg = "{\"activeStatus\":0,\"chipId\":\"30\",\"createDate\":1647878400000,\"deviceAlias\":\"\",\"deviceCode\":\"30\",\"deviceStatus\":0,\"farmId\":\"101\",\"id\":52,\"location\":\"\",\"registerTime\":1647955296670,\"remark\":\"\"}";
        producer.sendSyncDeviceRegister(msg);
//        producer.sendSyncDeviceRegister("456");
    }
    //
//    @PostMapping("/testRemoteProcessFarmAllStatus2")
//    public void testRemoteProcessFarmAllStatus2() throws ParseException {
//        deviceService.remoteProcessFarmAllStatus2("101");
//    }
}
