@RequestMapping("/message/v_trash.do")
public void 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)) {
// 清空发信表的同时复制该数据到收信表(收信人未空)
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();
CmsReceiverMessage tempReceiverMessage;
if (receiverMessages != null && receiverMessages.size() > 0) {
it = receiverMessages.iterator();
while (it.hasNext()) {
tempReceiverMessage= it.next();
tempReceiverMessage.setMessage(null);
receiverMessageMng.update(tempReceiverMessage);
}
}
messageMng.deleteById(ids[i]);
cmsLogMng.operating(request, "cmsMessage.log.trash", "id="
+ message.getId() + ";title="
+ message.getMsgTitle());
}
if (receiverMessage != null
&& receiverMessage.getMsgReceiverUser().equals(user)) {
receiverMessage.setMsgBox(3);
receiverMessageMng.update(receiverMessage);