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;
}