Esempio n. 1
0
 @Transactional(rollbackFor = Exception.class)
 public GeneralResponse doctorSendReportMessage(Doctor doctor, ReportChatMessage msg)
     throws Exception {
   try {
     User user = userRepo.findOne(msg.receiver.id);
     ChatParticipantInfo sender = new ChatParticipantInfo();
     sender.id = doctor.id;
     sender.role = 0;
     sender.name = doctor.name;
     sender.avatar = doctor.avatar;
     ChatParticipantInfo receiver = new ChatParticipantInfo();
     receiver.id = user.id;
     receiver.role = 1;
     receiver.name = user.name;
     ReportChatMessageResponse response = new ReportChatMessageResponse();
     response.category = 3;
     response.description = msg.description;
     response.suggestion = msg.suggestion;
     response.sender = sender;
     response.receiver = receiver;
     response.inquiryID = msg.inquiryID;
     IMScheduler.defaultSender.tell(
         new IMSenderMessage(user.jid, 1, user.clientID, user.deviceType, response), null);
     InquiryReport report = new InquiryReport();
     report.description = msg.description;
     report.suggestion = msg.suggestion;
     report.createTime = System.currentTimeMillis();
     Inquiry inquiry = inquiryRepo.findOne(msg.inquiryID);
     inquiry.report = report;
     inquiry.finished = true;
     inquiryRepo.save(inquiry);
     ChatRecord record = new ChatRecord();
     record.category = msg.category;
     record.senderID = doctor.id;
     record.receiverID = user.id;
     record.reportID = report.id;
     record.inquiryID = msg.inquiryID;
     record.createTime = System.currentTimeMillis();
     chatRepo.save(record);
     return new GeneralResponse();
   } catch (Exception e) {
     Logger.error("Send message failed", e);
     throw new IMServerException(e.getMessage());
   }
 }
Esempio n. 2
0
 @Transactional(rollbackFor = Exception.class)
 public GeneralResponse doctorSendReceptMessage(Doctor doctor, BaseChatMessage msg)
     throws Exception {
   try {
     User user = userRepo.findOne(msg.receiver.id);
     ChatParticipantInfo sender = new ChatParticipantInfo();
     sender.id = doctor.id;
     sender.role = 0;
     sender.name = doctor.name;
     sender.avatar = doctor.avatar;
     ChatParticipantInfo receiver = new ChatParticipantInfo();
     receiver.id = user.id;
     receiver.role = 1;
     receiver.name = user.name;
     ReceptChatMessageResponse response = new ReceptChatMessageResponse();
     response.sender = sender;
     response.receiver = receiver;
     response.category = 2;
     response.department = doctor.department.name;
     response.name = doctor.name;
     response.hospital = doctor.inHospital.name;
     response.title = doctor.title;
     response.inquiryID = msg.inquiryID;
     IMScheduler.defaultSender.tell(
         new IMSenderMessage(user.jid, 1, user.clientID, user.deviceType, response), null);
     ChatRecord record = new ChatRecord();
     record.category = msg.category;
     record.senderID = doctor.id;
     record.receiverID = user.id;
     record.doctorID = doctor.id;
     record.inquiryID = msg.inquiryID;
     record.createTime = System.currentTimeMillis();
     chatRepo.save(record);
     return new GeneralResponse();
   } catch (Exception e) {
     Logger.error("Send message failed", e);
     throw new IMServerException(e.getMessage());
   }
 }
Esempio n. 3
0
  @Transactional(rollbackFor = Exception.class)
  public GeneralResponse doctorSendNormalChat(
      Doctor doctor, NormalChatMessage msg, Http.MultipartFormData body) throws Exception {
    User user = userRepo.findOne(msg.receiver.id);
    String chatFileStore = Play.application().path() + "/store/chats";
    if (user != null) {
      try {
        ChatParticipantInfo sender = new ChatParticipantInfo();
        sender.id = doctor.id;
        sender.role = 0;
        sender.name = doctor.name;
        sender.avatar = doctor.avatar;
        ChatParticipantInfo receiver = new ChatParticipantInfo();
        receiver.id = user.id;
        receiver.role = 1;
        receiver.name = user.name;
        String fileDirPath = "";
        String id =
            MD5Generator.getMd5Value(
                UUIDGenerator.getUUID() + "doctor" + doctor.id + "user" + user.id);
        fileDirPath = chatFileStore + "/" + id;
        File filesDir = null;
        switch (msg.subCategory) {
          case 1:
            if (msg.content == null || msg.content.isEmpty()) {
              return new GeneralResponse(53, "Can't send empty content");
            } else {

              NormalChatMessageResponse response = new NormalChatMessageResponse();
              response.category = 1;
              response.sender = sender;
              response.receiver = receiver;
              response.subCategory = msg.subCategory;
              response.content = msg.content;
              response.inquiryID = msg.inquiryID;
              IMScheduler.defaultSender.tell(
                  new IMSenderMessage(user.jid, 1, user.clientID, user.deviceType, response), null);
              ChatRecord record = new ChatRecord();
              record.category = msg.category;
              record.content = msg.content;
              record.subCategory = msg.subCategory;
              record.senderID = doctor.id;
              record.receiverID = user.id;
              record.inquiryID = msg.inquiryID;
              record.createTime = System.currentTimeMillis();
              chatRepo.save(record);
            }
            break;
          case 2:
            filesDir = new File(fileDirPath);
            if (!filesDir.exists()) {
              filesDir.mkdirs();
            }
            Http.MultipartFormData.FilePart imgFlPart = body.getFile("file");
            if (imgFlPart != null) {
              NormalChatMessageResponse response = new NormalChatMessageResponse();
              response.sender = sender;
              response.receiver = receiver;
              response.category = 1;
              response.subCategory = msg.subCategory;
              response.inquiryID = msg.inquiryID;
              String fileName = imgFlPart.getFilename();
              String newFlName;
              if (!fileName.contains(".")) {
                newFlName = MD5Generator.getMd5Value(fileName + System.currentTimeMillis());
              } else {
                newFlName =
                    MD5Generator.getMd5Value(
                            fileName.substring(0, fileName.lastIndexOf("."))
                                + System.currentTimeMillis())
                        + fileName.substring(fileName.lastIndexOf("."));
              }
              FileUtils.moveFile(imgFlPart.getFile(), new File(filesDir, newFlName));
              response.content = "/chat/" + id + "/image/" + newFlName;
              IMScheduler.defaultSender.tell(
                  new IMSenderMessage(user.jid, 1, user.clientID, user.deviceType, response), null);
              ChatRecord record = new ChatRecord();
              record.category = msg.category;
              record.content = response.content;
              record.subCategory = msg.subCategory;
              record.senderID = doctor.id;
              record.receiverID = user.id;
              record.inquiryID = msg.inquiryID;
              record.createTime = System.currentTimeMillis();
              chatRepo.save(record);
            } else {
              return new GeneralResponse(56, "Not has file");
            }
            break;
          case 3:
            filesDir = new File(fileDirPath);
            if (!filesDir.exists()) {
              filesDir.mkdirs();
            }
            Http.MultipartFormData.FilePart sndFlPart = body.getFile("file");
            if (sndFlPart != null) {
              NormalChatMessageResponse response = new NormalChatMessageResponse();
              response.category = 1;
              response.sender = sender;
              response.receiver = receiver;
              response.subCategory = msg.subCategory;
              response.inquiryID = msg.inquiryID;
              String fileName = sndFlPart.getFilename();
              String newFlName;
              if (!fileName.contains(".")) {
                newFlName = MD5Generator.getMd5Value(fileName + System.currentTimeMillis());
              } else {
                newFlName =
                    MD5Generator.getMd5Value(
                            fileName.substring(0, fileName.lastIndexOf("."))
                                + System.currentTimeMillis())
                        + fileName.substring(fileName.lastIndexOf("."));
              }
              FileUtils.moveFile(sndFlPart.getFile(), new File(filesDir, newFlName));
              response.content = "/chat/" + id + "/audio/" + newFlName;
              IMScheduler.defaultSender.tell(
                  new IMSenderMessage(user.jid, 1, user.clientID, user.deviceType, response), null);
              ChatRecord record = new ChatRecord();
              record.category = msg.category;
              record.content = response.content;
              record.subCategory = msg.subCategory;
              record.senderID = doctor.id;
              record.receiverID = user.id;
              record.inquiryID = msg.inquiryID;
              record.createTime = System.currentTimeMillis();
              chatRepo.save(record);
            } else {
              return new GeneralResponse(56, "Not has file");
            }
            break;
          default:
            return new GeneralResponse(54, "Not indicate subcategory");
        }
        return new GeneralResponse();
      } catch (Exception e) {
        Logger.error("Send message failed", e);
        throw new IMServerException(e.getMessage());
      }
    } else {
      return new GeneralResponse(11, "Please push necessary data");
    }
  }