@Override
 public Calendar marshal(LocalDateTime localTime) throws Exception {
   if (localTime == null) {
     return null;
   }
   Calendar calendar = Calendar.getInstance();
   calendar.setTimeInMillis(localTime.getMillisOfDay());
   return calendar;
 }
Esempio n. 2
0
  @Transactional
  public CheckMonitor saveProduceOfCheckMonitor(CheckMonitor checkMonitor) {

    LocalDateTime now = LocalDateTime.now();

    // 关联消息ID
    String relatemsgid = checkMonitor.getMsgid();
    if (StringUtils.hasLength(relatemsgid)) {
      CheckMonitor relateCheckMonitor = checkMonitorRepository.findOne(relatemsgid);
      // 查岗消息时间
      LocalDateTime checktime;
      if (relateCheckMonitor != null) {
        relateCheckMonitor.setStatus(1);
        checkMonitorRepository.save(relateCheckMonitor);
        checktime = relateCheckMonitor.getTimestamp();

        // 获取时间差,设置查岗类型
        long diff = now.getMillisOfDay() - checktime.getMillisOfDay();

        long diffSec = diff / 1000;
        if (diffSec > relateCheckMonitor.getResponsetime()) {
          checkMonitor.setChecktype("TG");
        } else {
          checkMonitor.setChecktype("ZG");
        }
      }
    }

    if (!StringUtils.hasLength(checkMonitor.getUserid())) {}

    // 设置关联MSGID
    checkMonitor.setRelatemsg(relatemsgid);

    // 生成UUID
    String msgid = UUID.randomUUID().toString().replaceAll("-", "");
    checkMonitor.setMsgid(msgid);

    // 当前发送时间
    checkMonitor.setTimestamp(now);
    checkMonitor.setStatus(1);

    // 保存响应的查岗消息
    checkMonitor = checkMonitorRepository.save(checkMonitor);

    // 构造查岗消息字符串
    final String message =
        String.format(
            "{\"msgid\":\"%s\",\"msgtype\":\"%s\",\"syscode\":\"%s\",\"timestamp\":\"%s\",\"checktype\":\"%s\",\"relatemsg\":\"%s\",\"description\":\"%s\",\"userid\":\"\",\"usertel\":\"\"}",
            msgid,
            "CG",
            checkMonitor.getSyscode(),
            now.toString("yyyy-MM-dd'T'HH:mm:ss"),
            checkMonitor.getChecktype(),
            checkMonitor.getRelatemsg(),
            checkMonitor.getDescription(),
            checkMonitor.getUserid(),
            checkMonitor.getUsertel());

    // 发送查岗消息
    jmsTemplate.send(
        "checkmonitor",
        new MessageCreator() {

          public Message createMessage(Session session) throws JMSException {

            logger.info("response checkmonitor:" + message);

            return session.createTextMessage(message);
          }
        });

    return checkMonitor;
  }