package com.qxueyou.scc.exercise.service.impl; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.qxueyou.scc.base.dao.CommonDAO; import com.qxueyou.scc.base.service.IONSExceptionLogService; @Service("ExerciseSysMsgDealService") public class ExerciseSysMsgDealService { @Autowired CommonDAO dao; /* @Autowired IMsgVenderService easemobService;*/ @Autowired IONSExceptionLogService onsExceptionLogService; /*@Autowired protected IConfigService cfg;*/ //private static Logger log = LogManager.getLogger("ONSExceptionLogService"); // @PostConstruct // void init() { // CommonONSConsumer.registerHandler("SYS_EXER_SAVE", "ExerciseSysMsgDealService"); // } // // @Override // public void doHandle(Message msg, ConsumeContext context) { /*try { // String groupId = msg.getUserProperties("groupId"); // String classId = msg.getUserProperties("classId"); // String actionType = msg.getUserProperties("actionType"); // 练习不再发系统通知 by cyq 20160823 //sendSysNotice(groupId, classId, actionType); } catch (Exception e) { String businessId = cfg.getConfigByEnv("ons-common-topic") + "-" + UUIDUtils.generateUUID(); String desp = "classId:" + msg.getUserProperties("classId") + ";groupId:" + msg.getUserProperties("groupId") + ";actionType:" + msg.getUserProperties("actionType") ; log.error( businessId + " :更新练习系统消息发送失败:" + e , e); onsExceptionLogService.doSaveExceptionLog(cfg.getConfigByEnv("ons-common-topic"), "SYS_EXER_SAVE", businessId , desp ); }*/ } /** * 发送消息 * @param groupId * @param classId * @param actionType *//* private void sendSysNotice(String groupId, String classId, String actionType) { ExerciseGroup group = dao.read(ExerciseGroup.class, groupId); String hql = "from UserRegistration u where u.classId = ? and deleteFlag is false"; List userList = dao.find(hql, CollectionUtils.newList(classId), UserRegistration.class); List userIdList = new ArrayList<>(); for (UserRegistration ur : userList) { userIdList.add(ur.getUserId()); } OrgClass cls = dao.read(OrgClass.class, classId); String content = null; Map extra = new HashMap(); extra.put("classId", classId); extra.put("className", cls.getName()); if ("new".equalsIgnoreCase(actionType)) { extra.put("title", "有新的习题啦"); content = cls.getName() + "班有新的习题哦,赶快去瞄瞄吧!"; } else if ("update".equalsIgnoreCase(actionType)) { extra.put("title", "习题有更新啦"); content = cls.getName() + "班习题有更新哦,赶快去瞄瞄吧!"; } // add cyq JSONObject androidParam = new JSONObject(); JSONObject iOSParam = new JSONObject(); if (group.getType() == ExerciseGroup.TYPE_HOMEWORK) { extra.put("type", SysNoticeConfigMetadata.TYPE_EXERCISE_HOMEWORK); androidParam.put("key_exercise_type_name", "家庭作业"); androidParam.put("key_exercise_list_url", "http://www.qxueyou.com/qxueyou/exercise/Exercise/homeWorkListNew"); androidParam.put("key_exercise_type", "1"); iOSParam.put("Titlename", "家庭作业"); } else if (group.getType() == ExerciseGroup.TYPE_MOCK_EXAM) { extra.put("type", SysNoticeConfigMetadata.TYPE_EXERCISE_ANALOGY); androidParam.put("key_exercise_type_name", "模拟考试"); androidParam.put("key_exercise_list_url", "http://www.qxueyou.com/qxueyou/exercise/Exercise/examsListNew"); androidParam.put("key_exercise_type", "4"); iOSParam.put("Titlename", "模拟考试"); } else if (group.getType() == ExerciseGroup.TYPE_CHAPTER_ITEM) { extra.put("type", SysNoticeConfigMetadata.TYPE_EXERCISE_CHAPTER); androidParam.put("key_exercise_type_name", "章节练习"); androidParam.put("key_exercise_list_url", "http://www.qxueyou.com/qxueyou/exercise/Exercise/chapterListNew"); androidParam.put("key_exercise_type", "6"); iOSParam.put("Titlename", "章节练习"); } else if (group.getType() == ExerciseGroup.TYPE_EXERCISE_TOPIC) { extra.put("type", SysNoticeConfigMetadata.TYPE_EXERCISE_CHAPTER); androidParam.put("key_exercise_type_name", "专项练习"); androidParam.put("key_exercise_list_url", "http://www.qxueyou.com/qxueyou/exercise/Exercise/topicListNew"); androidParam.put("key_exercise_type", "9"); iOSParam.put("Titlename", "专项练习"); } else if (group.getType() == ExerciseGroup.TYPE_EXERCISE_FREE) { extra.put("type", SysNoticeConfigMetadata.TYPE_EXERCISE_FREEDOM); androidParam.put("key_exercise_type_name", "自由练习"); androidParam.put("key_exercise_list_url", "http://www.qxueyou.com/qxueyou/exercise/Exercise/freeListNew"); androidParam.put("key_exercise_type", "10"); iOSParam.put("Titlename", "自由练习"); } extra.put("androidParams", androidParam.toString()); extra.put("iosParams", iOSParam.toString()); if (StringUtils.isNotEmpty(content)) { // 对消息接收人按每批最多20人分批发送 String[] receivers; int loop = (userIdList.size() + 19) / 20; for (int i = 0; i < loop; i ++) { int len = (i == (loop - 1)) ? userIdList.size() - 20 * i : 20; receivers = new String[len]; userIdList.subList(i * 20, i * 20 + len).toArray(receivers); easemobService.doSendTextMsgToUsers("notice-sys", receivers, content, extra); } } }*/ //}