Commit 298e0892 authored by yanzg's avatar yanzg

修复实体关系

parent 34d85fa4
package com.yanzuoguang.mq;
/**
* Mq初始化
* @author 颜佐光
*/
public interface MqInit {
/**
* 初始化颜佐光
*/
void initMq();
}
package com.yanzuoguang.mq;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* 最终初始化执行
* @author 颜佐光
*/
@Component
public class MqStart implements InitializingBean, ApplicationContextAware {
@Autowired
private List<MqInit> mqInitList;
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
}
@Override
public void afterPropertiesSet() throws Exception {
for(MqInit init : mqInitList ){
init.initMq();
}
}
}
...@@ -27,7 +27,6 @@ public class YzgMqConsumer implements ApplicationContextAware { ...@@ -27,7 +27,6 @@ public class YzgMqConsumer implements ApplicationContextAware {
private MqService mqService; private MqService mqService;
private YzgMqProcedure yzgMqProcedure; private YzgMqProcedure yzgMqProcedure;
private QueueService queueService;
/** /**
* Set the ApplicationContext that this object runs in. * Set the ApplicationContext that this object runs in.
...@@ -45,10 +44,8 @@ public class YzgMqConsumer implements ApplicationContextAware { ...@@ -45,10 +44,8 @@ public class YzgMqConsumer implements ApplicationContextAware {
*/ */
@Override @Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
mqService = applicationContext.getBean(MqService.class);
yzgMqProcedure = applicationContext.getBean(YzgMqProcedure.class); yzgMqProcedure = applicationContext.getBean(YzgMqProcedure.class);
queueService = applicationContext.getBean(QueueService.class); mqService = applicationContext.getBean(MqService.class);
} }
/** /**
...@@ -133,7 +130,7 @@ public class YzgMqConsumer implements ApplicationContextAware { ...@@ -133,7 +130,7 @@ public class YzgMqConsumer implements ApplicationContextAware {
@RabbitListener(queues = {YzgMqProcedure.YZG_CLEAR_LOG}) @RabbitListener(queues = {YzgMqProcedure.YZG_CLEAR_LOG})
public void yzgClearLog(String day, Message message, Channel channel) { public void yzgClearLog(String day, Message message, Channel channel) {
try { try {
queueService.clearLog(day); mqService.clearLog(day);
} catch (CodeException ex) { } catch (CodeException ex) {
Log.error(YzgMqConsumer.class, ex); Log.error(YzgMqConsumer.class, ex);
} catch (Exception ex) { } catch (Exception ex) {
......
package com.yanzuoguang.mq.plan; package com.yanzuoguang.mq.plan;
import com.yanzuoguang.mq.MqConfig; import com.yanzuoguang.mq.MqConfig;
import com.yanzuoguang.mq.MqInit;
import com.yanzuoguang.mq.service.MqService; import com.yanzuoguang.mq.service.MqService;
import com.yanzuoguang.mq.vo.MessagePlan; import com.yanzuoguang.mq.vo.MessagePlan;
import com.yanzuoguang.mq.vo.MessageVo; import com.yanzuoguang.mq.vo.MessageVo;
...@@ -14,6 +15,7 @@ import org.springframework.beans.BeansException; ...@@ -14,6 +15,7 @@ import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanInitializationException; import org.springframework.beans.factory.BeanInitializationException;
import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.*; import org.springframework.context.*;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -26,7 +28,8 @@ import java.util.List; ...@@ -26,7 +28,8 @@ import java.util.List;
* @author 颜佐光 * @author 颜佐光
*/ */
@Component @Component
public class YzgMqProcedure implements InitializingBean, ApplicationContextAware { @Order(2)
public class YzgMqProcedure implements ApplicationContextAware, MqInit {
/** /**
* 执行的消息队列 * 执行的消息队列
*/ */
...@@ -72,18 +75,8 @@ public class YzgMqProcedure implements InitializingBean, ApplicationContextAware ...@@ -72,18 +75,8 @@ public class YzgMqProcedure implements InitializingBean, ApplicationContextAware
mqConfig = applicationContext.getBean(MqConfig.class); mqConfig = applicationContext.getBean(MqConfig.class);
} }
/**
* Invoked by a BeanFactory after it has set all bean properties supplied
* (and satisfied BeanFactoryAware and ApplicationContextAware).
* <p>This method allows the bean instance to perform initialization only
* possible when all bean properties have been set and to throw an
* exception in the event of misconfiguration.
*
* @throws Exception in the event of misconfiguration (such
* as failure to set an essential property) or if initialization fails.
*/
@Override @Override
public void afterPropertiesSet() throws Exception { public void initMq() {
mqService.createQueue(new QueueVo(YZG_CLEAR_LOG)); mqService.createQueue(new QueueVo(YZG_CLEAR_LOG));
mqService.createQueue(new QueueVo(YZG_MQ_SYSTEM_QUEUE)); mqService.createQueue(new QueueVo(YZG_MQ_SYSTEM_QUEUE));
mqService.createQueue(new QueueVo(YZG_MQ_SYSTEM_QUEUE_PLAN)); mqService.createQueue(new QueueVo(YZG_MQ_SYSTEM_QUEUE_PLAN));
......
...@@ -60,6 +60,13 @@ public interface MqService { ...@@ -60,6 +60,13 @@ public interface MqService {
@ApiOperation(value = "删除一个消息") @ApiOperation(value = "删除一个消息")
String logRemove(MessageLogRemoveReqVo req); String logRemove(MessageLogRemoveReqVo req);
/**
* 删除日期
*
* @param day
*/
void clearLog(String day);
/** /**
* 发送消息 * 发送消息
* *
......
...@@ -15,11 +15,4 @@ public interface QueueService { ...@@ -15,11 +15,4 @@ public interface QueueService {
* @param req 保存队列服务 * @param req 保存队列服务
*/ */
void create(QueueVo req); void create(QueueVo req);
/**
* 删除日期
*
* @param day
*/
void clearLog(String day);
} }
...@@ -2,6 +2,7 @@ package com.yanzuoguang.mq.service.impl; ...@@ -2,6 +2,7 @@ package com.yanzuoguang.mq.service.impl;
import com.alibaba.fastjson.TypeReference; import com.alibaba.fastjson.TypeReference;
import com.rabbitmq.client.Channel; import com.rabbitmq.client.Channel;
import com.yanzuoguang.mq.MqInit;
import com.yanzuoguang.mq.base.MqConsumeDynamic; import com.yanzuoguang.mq.base.MqConsumeDynamic;
import com.yanzuoguang.mq.dao.MessageLogDao; import com.yanzuoguang.mq.dao.MessageLogDao;
import com.yanzuoguang.mq.dao.QueueServerDao; import com.yanzuoguang.mq.dao.QueueServerDao;
...@@ -26,7 +27,9 @@ import org.springframework.beans.BeansException; ...@@ -26,7 +27,9 @@ import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanInitializationException; import org.springframework.beans.factory.BeanInitializationException;
import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.*; import org.springframework.context.*;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -38,7 +41,8 @@ import java.util.List; ...@@ -38,7 +41,8 @@ import java.util.List;
* @author 颜佐光 * @author 颜佐光
*/ */
@Component @Component
public class MqServiceImpl implements MqService, InitializingBean, ApplicationContextAware { @Order(1)
public class MqServiceImpl implements MqService, ApplicationContextAware, MqInit {
private QueueService queueService; private QueueService queueService;
private MessageService messageService; private MessageService messageService;
...@@ -70,29 +74,19 @@ public class MqServiceImpl implements MqService, InitializingBean, ApplicationCo ...@@ -70,29 +74,19 @@ public class MqServiceImpl implements MqService, InitializingBean, ApplicationCo
*/ */
@Override @Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
queueService = applicationContext.getBean(QueueService.class); messageLogDao = applicationContext.getBean(MessageLogDao.class);
messageService = applicationContext.getBean(MessageService.class);
mqConsumeDynamic = applicationContext.getBean(MqConsumeDynamic.class);
queueServerDao = applicationContext.getBean(QueueServerDao.class); queueServerDao = applicationContext.getBean(QueueServerDao.class);
queueServerTokenDao = applicationContext.getBean(QueueServerTokenDao.class); queueServerTokenDao = applicationContext.getBean(QueueServerTokenDao.class);
messageLogDao = applicationContext.getBean(MessageLogDao.class);
messageService = applicationContext.getBean(MessageService.class);
mqConsumeDynamic = applicationContext.getBean(MqConsumeDynamic.class);
queueService = applicationContext.getBean(QueueService.class);
yzgMqProcedure = applicationContext.getBean(YzgMqProcedure.class); yzgMqProcedure = applicationContext.getBean(YzgMqProcedure.class);
this.localName = UrlHelper.getIp(); this.localName = UrlHelper.getIp();
} }
/** public void initMq() {
* Invoked by a BeanFactory after it has set all bean properties supplied
* (and satisfied BeanFactoryAware and ApplicationContextAware).
* <p>This method allows the bean instance to perform initialization only
* possible when all bean properties have been set and to throw an
* exception in the event of misconfiguration.
*
* @throws Exception in the event of misconfiguration (such
* as failure to set an essential property) or if initialization fails.
*/
@Override
public void afterPropertiesSet() throws Exception {
QueueVo removeToken = new QueueVo(YzgMqProcedure.YZG_MQ_CLEAR_TOKEN_QUEUE); QueueVo removeToken = new QueueVo(YzgMqProcedure.YZG_MQ_CLEAR_TOKEN_QUEUE);
removeToken.check(); removeToken.check();
queueService.create(removeToken); queueService.create(removeToken);
...@@ -160,6 +154,20 @@ public class MqServiceImpl implements MqService, InitializingBean, ApplicationCo ...@@ -160,6 +154,20 @@ public class MqServiceImpl implements MqService, InitializingBean, ApplicationCo
return load.getId(); return load.getId();
} }
/**
* 删除日期
*
* @param day
*/
@Override
@Transactional(rollbackFor = Exception.class)
public void clearLog(String day) {
// 添加去重方法,只执行1次
this.log(new MessageLogReqVo(YzgMqProcedure.YZG_CLEAR_LOG, day));
messageLogDao.removeLastTime();
yzgMqProcedure.clearLog();
}
/** /**
* 删除一个消息 * 删除一个消息
* *
......
...@@ -24,9 +24,6 @@ import org.springframework.transaction.annotation.Transactional; ...@@ -24,9 +24,6 @@ import org.springframework.transaction.annotation.Transactional;
public class QueueServiceImpl implements QueueService, ApplicationContextAware { public class QueueServiceImpl implements QueueService, ApplicationContextAware {
private BeanDao beanDao; private BeanDao beanDao;
private MessageLogDao messageLogDao;
private MqService mqService;
private YzgMqProcedure mqProcedure;
/** /**
* Set the ApplicationContext that this object runs in. * Set the ApplicationContext that this object runs in.
...@@ -45,9 +42,6 @@ public class QueueServiceImpl implements QueueService, ApplicationContextAware { ...@@ -45,9 +42,6 @@ public class QueueServiceImpl implements QueueService, ApplicationContextAware {
@Override @Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
beanDao = applicationContext.getBean(BeanDao.class); beanDao = applicationContext.getBean(BeanDao.class);
messageLogDao = applicationContext.getBean(MessageLogDao.class);
mqService = applicationContext.getBean(MqService.class);
mqProcedure = applicationContext.getBean(YzgMqProcedure.class);
} }
/** /**
...@@ -61,20 +55,6 @@ public class QueueServiceImpl implements QueueService, ApplicationContextAware { ...@@ -61,20 +55,6 @@ public class QueueServiceImpl implements QueueService, ApplicationContextAware {
initBean(req); initBean(req);
} }
/**
* 删除日期
*
* @param day
*/
@Override
@Transactional(rollbackFor = Exception.class)
public void clearLog(String day) {
// 添加去重方法,只执行1次
mqService.log(new MessageLogReqVo(YzgMqProcedure.YZG_CLEAR_LOG, day));
messageLogDao.removeLastTime();
mqProcedure.clearLog();
}
/** /**
* 初始化实体 * 初始化实体
* *
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment