派生自 projectDept/qhighschool

EricsHu
2022-12-05 068fc7f2e81178e55fa191a13709af64b1a163f6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
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<UserRegistration> userList = dao.find(hql, CollectionUtils.newList(classId), UserRegistration.class);
        List<String> userIdList = new ArrayList<>();
        for (UserRegistration ur : userList) {
            userIdList.add(ur.getUserId());
        }
        OrgClass cls = dao.read(OrgClass.class, classId);
        String content = null;
            
        Map<String,String> extra = new HashMap<String,String>();
        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);
            }
        }
    }*/
//}