派生自 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
package com.qxueyou.scc.school.service.impl;
 
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.util.Enumeration;
 
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.stereotype.Service;
 
import com.qxueyou.scc.base.service.IONSExceptionLogService;
import com.qxueyou.scc.config.AliOnsConfig;
import com.qxueyou.scc.school.service.IHandoutService;
 
/**
 * 文档处理消息队列接收服务
 * 
 * @author 德虎
 * 
 */
@Service("DocdealMsgDealService")
@EnableConfigurationProperties(AliOnsConfig.class)
public class DocdealMsgDealService{
//public class DocdealMsgDealService extends ONSBaseMsgConsumer implements IONSMsgDealService {
 
    @Autowired
    AliOnsConfig aliOnsConfig;
    
    @Autowired
    IHandoutService handoutService;
    
    @Autowired
    IONSExceptionLogService onsExceptionLogService;
    
    @SuppressWarnings("unused")
    private static Logger log = LogManager.getLogger("ONSExceptionLogService");
    
 
//    @Override
//    public void doHandle(Message msg, ConsumeContext context) {
//        
//        //TODO 严格异常处理,两次就直接返回,暂时一次
//        try {
//            // get params
//            String docPath = msg.getUserProperties("docPath");
//            String handoutId = msg.getUserProperties("handoutId");
//            String uploadModule = msg.getUserProperties("uploadModule");
//            String userId = msg.getUserProperties("userId");
//
//            // parse office file(ppt\pptx)
//            
//            handoutService.insertHandoutPages(docPath, handoutId,uploadModule,userId,"PPT");
//            
//        }catch(Exception e){
//            
//            String businessId = getTopic() + "-" + UUIDUtils.generateUUID();
//            String desp = "handoutId:" + msg.getUserProperties("handoutId")+ 
//                    ";docPath:" + msg.getUserProperties("docPath") +
//                    ";userId:" + msg.getUserProperties("userId") + 
//                    ";uploadModule:" + msg.getUserProperties("uploadModule") ;
//
//            log.error( businessId + " :上传讲义ppt消息发送失败:" + e , e);
//            onsExceptionLogService.logSaveExceptionLog(getTopic(), "", businessId , desp );
//        }
//        
//    }
//    
    /**
     * 配置项ons-docdeal-receive-urls配置了多个ip地址,如果其中包含本机地址,说明支持文档处理
     */
    protected boolean turnOn(){
        String docdealUrls =aliOnsConfig.getDocdealReceiveUrls();
        try {
            Enumeration<NetworkInterface> nienum = NetworkInterface.getNetworkInterfaces();
            while (nienum.hasMoreElements()) {
                NetworkInterface ni = nienum.nextElement();
                Enumeration<InetAddress> iaenum = ni.getInetAddresses();
                while (iaenum.hasMoreElements()) {
                    InetAddress ia = iaenum.nextElement();
                    if (ia instanceof Inet4Address&&docdealUrls.contains("#" + ia.getHostAddress() + "#")) {
                            return true;
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }
 
//    @Override
//    protected String getConsumerId() {
//        return cfg.getConfigByEnv("ons-docdeal-customer-id");
//    }
//
//    @Override
//    protected String getTopic() {
//        return cfg.getConfigByEnv("ons-docdeal-topic");
//    }
 
}