public void message_trash(Integer ids[], HttpServletRequest request,
HttpServletResponse response, ModelMap model) throws JSONException {
CmsUser user = CmsUtils.getUser(request);
JSONObject object = new JSONObject();
CmsMessage message;
CmsReceiverMessage receiverMessage;
if (user == null) {
object.put("result", false);
} else {
Iterator<CmsReceiverMessage> it;
for (Integer i = 0; i < ids.length; i++) {
message = messageMng.findById(ids[i]);
receiverMessage = receiverMessageMng.findById(ids[i]);
if (message != null && message.getMsgSendUser().equals(user)) {
message.setMsgBox(3);
receiverMessage = new CmsReceiverMessage();
receiverMessage.setMsgBox(3);
receiverMessage.setMsgContent(message.getMsgContent());
receiverMessage.setMsgSendUser(message.getMsgSendUser());
receiverMessage.setMsgReceiverUser(user);
receiverMessage.setMsgStatus(message.getMsgStatus());
receiverMessage.setMsgTitle(message.getMsgTitle());
receiverMessage.setSendTime(message.getSendTime());
receiverMessage.setSite(message.getSite());
receiverMessage.setMessage(null);
// 接收端(有一定冗余)
receiverMessageMng.save(receiverMessage);
// 清空该发件对应的收件关联关系
Set<CmsReceiverMessage> receiverMessages = message
.getReceiverMsgs();
if (receiverMessages != null && receiverMessages.size() > 0) {
it = receiverMessages.iterator();
CmsReceiverMessage tempReceiverMessage;
while (it.hasNext()) {
tempReceiverMessage = it.next();
tempReceiverMessage.setMessage(null);
receiverMessageMng.update(tempReceiverMessage);
}
}
messageMng.deleteById(ids[i]);
}