|
|
@@ -14,10 +14,12 @@ import com.xzjmyk.pm.activity.bean.message.SubscriptionMessage;
|
|
|
import com.xzjmyk.pm.activity.bean.message.XmppMessage;
|
|
|
import com.xzjmyk.pm.activity.broadcast.MsgBroadcast;
|
|
|
import com.xzjmyk.pm.activity.db.dao.FriendDao;
|
|
|
+import com.xzjmyk.pm.activity.db.dao.MessageDao;
|
|
|
import com.xzjmyk.pm.activity.sortlist.BaseSortModel;
|
|
|
import com.xzjmyk.pm.activity.sortlist.PingYinUtil;
|
|
|
import com.xzjmyk.pm.activity.ui.MainActivity;
|
|
|
import com.xzjmyk.pm.activity.ui.erp.activity.oa.MsgsSecondCommonActivity;
|
|
|
+import com.xzjmyk.pm.activity.ui.erp.model.MessageModel;
|
|
|
import com.xzjmyk.pm.activity.ui.erp.presenter.imp.IMessageView;
|
|
|
import com.xzjmyk.pm.activity.ui.erp.util.CommonUtil;
|
|
|
import com.xzjmyk.pm.activity.ui.erp.util.ListUtils;
|
|
|
@@ -27,7 +29,6 @@ import com.xzjmyk.pm.activity.ui.message.MucChatActivity;
|
|
|
import com.xzjmyk.pm.activity.ui.message.NewFriendActivity;
|
|
|
import com.xzjmyk.pm.activity.util.StringUtils;
|
|
|
import com.xzjmyk.pm.activity.util.TimeUtils;
|
|
|
-import com.xzjmyk.pm.activity.util.WorkHandlerUtil;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Collections;
|
|
|
@@ -87,7 +88,7 @@ public class MessagePresenter implements HttpHandler.OnResultListener {
|
|
|
param.put("count", 100);
|
|
|
param.put("condition", "where to_char(createdate_,'yyyymmdd')='" + TimeUtils.int_long_2_str(System.currentTimeMillis()) + "'");
|
|
|
param.put("sessionId", CommonUtil.getSharedPreferences(ct, "sessionId"));
|
|
|
- HttpHandler.getInstance().loadERPByNet(LOAD_SUBS, "common/desktop/subs/getSubs.action", param, null, this,"get");
|
|
|
+ HttpHandler.getInstance().loadERPByNet(LOAD_SUBS, "common/desktop/subs/getSubs.action", param, null, this, "get");
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -98,7 +99,7 @@ public class MessagePresenter implements HttpHandler.OnResultListener {
|
|
|
Map<String, Object> param = new HashMap<>();
|
|
|
param.put("count", "1000");
|
|
|
param.put("page", 1);//默认获取第一页
|
|
|
- HttpHandler.getInstance().loadERPByNet(LOAD_PROCESS, "common/desktop/process/toDo.action", param, null, this,"get");
|
|
|
+ HttpHandler.getInstance().loadERPByNet(LOAD_PROCESS, "common/desktop/process/toDo.action", param, null, this, "get");
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -111,7 +112,7 @@ public class MessagePresenter implements HttpHandler.OnResultListener {
|
|
|
JSONObject object = JSON.parseObject(message);
|
|
|
switch (what) {
|
|
|
case LOAD_EMNEWS:
|
|
|
- emnewsNum = WorkHandlerUtil.getIntByJson(object, "allCount");
|
|
|
+// emnewsNum = WorkHandlerUtil.getIntByJson(object, "allCount");
|
|
|
if (!object.containsKey("listdata")) return;
|
|
|
JSONArray array = object.getJSONArray("listdata");
|
|
|
handlerNewsFormErp(array);
|
|
|
@@ -146,6 +147,7 @@ public class MessagePresenter implements HttpHandler.OnResultListener {
|
|
|
processNum = 0;
|
|
|
}
|
|
|
iMessageView.updateHeaderView(0, processNum, subTitle);
|
|
|
+ updateForUnReader();
|
|
|
}
|
|
|
|
|
|
private void handlerSub(JSONObject object) {
|
|
|
@@ -170,51 +172,89 @@ public class MessagePresenter implements HttpHandler.OnResultListener {
|
|
|
* @param array
|
|
|
*/
|
|
|
private void handlerNewsFormErp(JSONArray array) {
|
|
|
- if (mFriendList == null)
|
|
|
- mFriendList = new ArrayList<>();
|
|
|
- else
|
|
|
- mFriendList.clear();
|
|
|
if (ListUtils.isEmpty(array)) {
|
|
|
//TODO 为空数据情况下
|
|
|
return;
|
|
|
}
|
|
|
JSONObject object = null;
|
|
|
- Friend friend = null;
|
|
|
- List<BaseSortModel<Friend>> erpFriend = new ArrayList<>();
|
|
|
+ List<MessageModel> models = new ArrayList<>();
|
|
|
+ MessageModel model = null;
|
|
|
for (int i = 0; i < array.size(); i++) {
|
|
|
object = array.getJSONObject(i);
|
|
|
- friend = new Friend();
|
|
|
- friend.setNickName(object.getString("title"));
|
|
|
+ model = new MessageModel();
|
|
|
+ model.setTitle(object.getString("title"));
|
|
|
+ model.setSubTitle(object.getString("lastMessage"));
|
|
|
+ model.setTime(object.getString("lastTime"));
|
|
|
+ model.setType(object.getString("type"));
|
|
|
if (object.containsKey("count") && object.get("count") != null)
|
|
|
- friend.setUnReadNum(object.getInteger("count"));
|
|
|
- friend.setContent(object.getString("lastMessage"));
|
|
|
- friend.setTimeSend(getErpTime(object, "lastTime"));
|
|
|
- friend.setType(XmppMessage.TYPE_ERP);
|
|
|
- friend.setDescription(object.getString("type"));
|
|
|
- BaseSortModel<Friend> mode = new BaseSortModel<>();
|
|
|
- mode.setBean(friend);
|
|
|
- setSortCondition(mode);
|
|
|
- erpFriend.add(mode);
|
|
|
- }
|
|
|
- if (erpComparator == null) {
|
|
|
- erpComparator = new Comparator<BaseSortModel<Friend>>() {
|
|
|
- public int compare(BaseSortModel<Friend> s1, BaseSortModel<Friend> s2) {
|
|
|
- return (s1.getBean().getTimeSend() - s2.getBean().getTimeSend());
|
|
|
- }
|
|
|
- };
|
|
|
+ model.setCount(object.getInteger("count"));
|
|
|
+ if (StringUtils.isEmpty(model.getTitle()) || StringUtils.isEmpty(model.getSubTitle()))
|
|
|
+ continue;
|
|
|
+ if (model.getSubTitle().length() > 100)
|
|
|
+ model.setSubTitle(model.getSubTitle().substring(0, 18));
|
|
|
+ models.add(model);
|
|
|
}
|
|
|
- Collections.sort(erpFriend, erpComparator);
|
|
|
+ saveErp2DB(models);
|
|
|
+ }
|
|
|
|
|
|
- mFriendList.addAll(0, erpFriend);
|
|
|
- iMessageView.showModel(erpFriend);
|
|
|
+ /**
|
|
|
+ * 保存erp数据到数据库
|
|
|
+ *
|
|
|
+ * @param models
|
|
|
+ */
|
|
|
+ private void saveErp2DB(List<MessageModel> models) {
|
|
|
+ boolean saveOk = MessageDao.getInstance().createOrinstart(models);
|
|
|
}
|
|
|
|
|
|
- private int getErpTime(JSONObject object, String lastTime) {
|
|
|
- String time = object.getString(lastTime);
|
|
|
- if (StringUtils.isEmpty(time)) {
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理消息红点消息
|
|
|
+ */
|
|
|
+// private void handlerNewsFormErp(JSONArray array) {
|
|
|
+// if (mFriendList == null)
|
|
|
+// mFriendList = new ArrayList<>();
|
|
|
+// else
|
|
|
+// mFriendList.clear();
|
|
|
+// if (ListUtils.isEmpty(array)) {
|
|
|
+// //TODO 为空数据情况下
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// JSONObject object = null;
|
|
|
+// Friend friend = null;
|
|
|
+// List<BaseSortModel<Friend>> erpFriend = new ArrayList<>();
|
|
|
+// for (int i = 0; i < array.size(); i++) {
|
|
|
+// object = array.getJSONObject(i);
|
|
|
+// friend = new Friend();
|
|
|
+// friend.setNickName(object.getString("title"));
|
|
|
+// if (object.containsKey("count") && object.get("count") != null)
|
|
|
+// friend.setUnReadNum(object.getInteger("count"));
|
|
|
+// friend.setContent(object.getString("lastMessage"));
|
|
|
+// friend.setTimeSend(getErpTime(object, "lastTime"));
|
|
|
+// friend.setType(XmppMessage.TYPE_ERP);
|
|
|
+// friend.setDescription(object.getString("type"));
|
|
|
+// BaseSortModel<Friend> mode = new BaseSortModel<>();
|
|
|
+//
|
|
|
+// mode.setBean(friend);
|
|
|
+// setSortCondition(mode);
|
|
|
+// erpFriend.add(mode);
|
|
|
+// }
|
|
|
+// if (erpComparator == null) {
|
|
|
+// erpComparator = new Comparator<BaseSortModel<Friend>>() {
|
|
|
+// public int compare(BaseSortModel<Friend> s1, BaseSortModel<Friend> s2) {
|
|
|
+// return (s1.getBean().getTimeSend() - s2.getBean().getTimeSend());
|
|
|
+// }
|
|
|
+// };
|
|
|
+// }
|
|
|
+// Collections.sort(erpFriend, erpComparator);
|
|
|
+//
|
|
|
+// mFriendList.addAll(0, erpFriend);
|
|
|
+// iMessageView.showModel(erpFriend);
|
|
|
+// }
|
|
|
+ private int getErpTime(String lastTime) {
|
|
|
+ if (StringUtils.isEmpty(lastTime)) {
|
|
|
return (int) (System.currentTimeMillis() / 1000);
|
|
|
} else {
|
|
|
- return (int) (TimeUtils.f_str_2_long(time) / 1000);
|
|
|
+ return (int) (TimeUtils.f_str_2_long(lastTime) / 1000);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -248,32 +288,71 @@ public class MessagePresenter implements HttpHandler.OnResultListener {
|
|
|
new Thread(new Runnable() {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
+ if (mFriendList == null) mFriendList = new ArrayList<>();
|
|
|
+ mFriendList.clear();
|
|
|
String mLoginUserId = MyApplication.getInstance().mLoginUser.getUserId();
|
|
|
long startTime = System.currentTimeMillis();
|
|
|
final List<Friend> friends = FriendDao.getInstance().getNearlyFriendMsg(mLoginUserId);
|
|
|
+ List<MessageModel> model = MessageDao.getInstance().queryFirstFloor();
|
|
|
setFriendName(friends, mLoginUserId);
|
|
|
long delayTime = 200 - (startTime - System.currentTimeMillis());// 保证至少200ms的刷新过程
|
|
|
if (delayTime < 0) {
|
|
|
delayTime = 0;
|
|
|
}
|
|
|
+ handlerErpAndIm(friends, model);
|
|
|
HttpHandler.getInstance().postDelayed(new Runnable() {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
- if (friends != null && friends.size() > 0) {
|
|
|
- for (int i = 0; i < friends.size(); i++) {
|
|
|
- BaseSortModel<Friend> mode = new BaseSortModel<>();
|
|
|
- mode.setBean(friends.get(i));
|
|
|
- setSortCondition(mode);
|
|
|
- mFriendList.add(mode);
|
|
|
- }
|
|
|
- }
|
|
|
iMessageView.showModel(mFriendList);
|
|
|
+ updateForUnReader();
|
|
|
}
|
|
|
}, delayTime);
|
|
|
}
|
|
|
}).start();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 整合erp和im消息内容
|
|
|
+ *
|
|
|
+ * @param friends
|
|
|
+ * @param models
|
|
|
+ */
|
|
|
+ private void handlerErpAndIm(List<Friend> friends, List<MessageModel> models) {
|
|
|
+ if (friends == null) friends = new ArrayList<>();
|
|
|
+ emnewsNum = 0;
|
|
|
+ if (!ListUtils.isEmpty(models)) {
|
|
|
+ for (MessageModel m : models) {
|
|
|
+ Friend friend = new Friend();
|
|
|
+ friend.setNickName(m.getTitle());
|
|
|
+ friend.setContent(m.getSubTitle());
|
|
|
+ friend.setTimeSend(getErpTime(m.getTime()));
|
|
|
+ friend.setType(XmppMessage.TYPE_ERP);
|
|
|
+ friend.setDescription(m.getType());
|
|
|
+ friend.set_id(m.getId());
|
|
|
+ int count = m.isReaded() ? 0 : m.getCount();
|
|
|
+ emnewsNum += count;
|
|
|
+ friend.setUnReadNum(count);
|
|
|
+ friends.add(friend);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (friends != null && friends.size() > 0) {
|
|
|
+ for (int i = 0; i < friends.size(); i++) {
|
|
|
+ BaseSortModel<Friend> mode = new BaseSortModel<>();
|
|
|
+ mode.setBean(friends.get(i));
|
|
|
+ setSortCondition(mode);
|
|
|
+ mFriendList.add(mode);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (erpComparator == null) {
|
|
|
+ erpComparator = new Comparator<BaseSortModel<Friend>>() {
|
|
|
+ public int compare(BaseSortModel<Friend> s1, BaseSortModel<Friend> s2) {
|
|
|
+ return (s1.getBean().getTimeSend() - s2.getBean().getTimeSend());
|
|
|
+ }
|
|
|
+ };
|
|
|
+ }
|
|
|
+ Collections.sort(mFriendList, erpComparator);
|
|
|
+ }
|
|
|
+
|
|
|
private void setFriendName(List<Friend> friends, String id) {
|
|
|
List<Friend> f = FriendDao.getInstance().getFriends(id);
|
|
|
if (friends == null) return;
|
|
|
@@ -333,13 +412,14 @@ public class MessagePresenter implements HttpHandler.OnResultListener {
|
|
|
intent.putExtra("title", friend.getNickName());
|
|
|
intent.putExtra("emcode", CommonUtil.getSharedPreferences(ct, "erp_username"));
|
|
|
ct.startActivity(intent);
|
|
|
+ MessageDao.getInstance().upStatus(friend.get_id(), true);
|
|
|
}
|
|
|
|
|
|
|
|
|
/*跟新未读红点信息*/
|
|
|
private void updateForUnReader() {
|
|
|
int num = subsNum + processNum + emnewsNum;
|
|
|
- if (ct!=null)
|
|
|
+ if (ct != null)
|
|
|
ct.setUnReader(num);
|
|
|
}
|
|
|
}
|