Insite emails, send them in group or all. Gson parses the result,. gsonresult

Source: Internet
Author: User

Insite emails, send them in group or all. Gson parses the result,. gsonresult

/**
* Send an insite email
*/
@ Permission (Module. TZGL)
@ RequestMapping (value = "/sendznx", method = RequestMethod. POST)
@ ResponseBody
Public String sendZnx (HttpSession session, Model model,
@ RequestParam (defaultValue = "") String [] userList,
@ RequestParam (defaultValue = "") String content) throws Exception {
Int rows = 0; // record the number of sent messages
String msg = ""; // record returned information
System. out. println ("length --->" + userList. length );
System. out. println ("content --->" + content );
Try {
If (userList. length = 0) {// send a system notification to all Members
// Send all members
Try {
String result = Jsoup. connect (NMApi. url () + "/message/userlist"). timeout (10000)
. Get ()
. Text ();
// ---> Use Gson to convert the data returned from the request into a MAP structure
Map <String, Object> data = new Gson (). fromJson (result, new TypeToken <Map <String, Object> () {}. getType ());
// ---> Extract the Object data required by MAP and convert it to List
List list = (List) data. get ("RecList ");
// ---> Convert List to Json using Gson
String str = new Gson (). toJson (list );
// ---> Use Gson to convert Json to the desired type.
List <UserInfo> userInfoList = new Gson (). fromJson (str, new TypeToken <List <UserInfo> () {}. getType ());
Try {
For (UserInfo userInfo: userInfoList ){
WebMessage webMessage = new WebMessage ();
WebMessage. setClientId (userInfo. getIcid ());
WebMessage. setReceiveTime (new Date ());
WebMessage. setType ("system notification ");
WebMessage. setContent (content );
WebMessage. setStatus (0 );
WebMessageService. add (webMessage );
Rows ++;
}
Msg = "insite message sent successfully, number of successful messages:" + rows;
} Catch (Exception e ){
E. printStackTrace ();
Return "An error occurred while sending Group emails ";
}
} Catch (Exception e ){
E. printStackTrace ();
Return "An error occurred while querying the user list ";
}
} Else {
For (int I = 0; I <userList. length; I ++) {// send administrator messages to some Members
WebMessage webMessage = new WebMessage ();
WebMessage. setClientId (Integer. parseInt (userList [I]);
WebMessage. setReceiveTime (new Date ());
WebMessage. setType ("Administrator message ");
WebMessage. setContent (content );
WebMessage. setStatus (0 );
WebMessageService. add (webMessage );
Rows ++;
}
Msg = "insite message sent successfully, number of successful messages:" + rows;
// Sending record
Try {
User user = (User) session. getAttribute ("user ");
MessageLog messageLog = new MessageLog ();
MessageLog. setSendTime (new Date ());
MessageLog. setType ("insite email ");
MessageLog. setSender (user. getUnitName ());
MessageLog. setReceiver (userList. toString ());
MessageLog. setContent (content );
MessageLog. setResult (msg );
MessageLog. setError ("");
Int num = messageLogService. add (messageLog );
System. out. println ("generate record --->" + num );
} Catch (Exception e ){
E. printStackTrace ();
Return "An error occurred while generating the mail record ";
}
}
} Catch (Exception e ){
E. printStackTrace ();
Return "system error ";
}
Return msg;
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.