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 nienum = NetworkInterface.getNetworkInterfaces(); while (nienum.hasMoreElements()) { NetworkInterface ni = nienum.nextElement(); Enumeration 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"); // } }