package me.zhengjie.modules.test;

import com.alibaba.fastjson.JSONObject;
import me.zhengjie.config.rabbitmq.test.SendTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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

@RestController
@RequestMapping("/api/send")
public class TestController {

    @Autowired
    public SendTemplate sendTemplate;

    @GetMapping("/send")
    public void testSend() throws ParseException {
        Map<String,Object> map = new HashMap<>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
        Date date = new Date();
        String timestamp =sdf.format(date);
        System.out.println("timestamp:"+timestamp);

        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String dateNowStr = simpleDateFormat.format(date);
        System.out.println("时间date"+dateNowStr);

        map.put("seq",Long.valueOf(timestamp));
        map.put("date",dateNowStr);
        map.put("shopname","餐厅");
        JSONObject jsonObject = new JSONObject(map);
        sendTemplate.sendMessage(jsonObject);
        System.out.println("消息發送成功success"+jsonObject);
    }

//    @GetMapping("/send1")
//    public void testSend1(){
//        Map<String,Object> map = new HashMap<>();
//        map.put("seq",1);
//        map.put("date","2021-12-09 00:00:00");
//        map.put("shopname","111");
//        sendTemplate.sendOrederMessage(map);
//        System.out.println("消息發送成功success"+map);
//    }
}
