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 {
private MqService mqService;
private YzgMqProcedure yzgMqProcedure;
private QueueService queueService;
/**
* Set the ApplicationContext that this object runs in.
......@@ -45,10 +44,8 @@ public class YzgMqConsumer implements ApplicationContextAware {
*/
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
mqService = applicationContext.getBean(MqService.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 {
@RabbitListener(queues = {YzgMqProcedure.YZG_CLEAR_LOG})
public void yzgClearLog(String day, Message message, Channel channel) {
try {
queueService.clearLog(day);
mqService.clearLog(day);
} catch (CodeException ex) {
Log.error(YzgMqConsumer.class, ex);
} catch (Exception ex) {
......
package com.yanzuoguang.mq.plan;
import com.yanzuoguang.mq.MqConfig;
import com.yanzuoguang.mq.MqInit;
import com.yanzuoguang.mq.service.MqService;
import com.yanzuoguang.mq.vo.MessagePlan;
import com.yanzuoguang.mq.vo.MessageVo;
......@@ -14,6 +15,7 @@ import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanInitializationException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.*;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
......@@ -26,7 +28,8 @@ import java.util.List;
* @author 颜佐光
*/
@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
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
public void afterPropertiesSet() throws Exception {
public void initMq() {
mqService.createQueue(new QueueVo(YZG_CLEAR_LOG));
mqService.createQueue(new QueueVo(YZG_MQ_SYSTEM_QUEUE));
mqService.createQueue(new QueueVo(YZG_MQ_SYSTEM_QUEUE_PLAN));
......
......@@ -60,6 +60,13 @@ public interface MqService {
@ApiOperation(value = "删除一个消息")
String logRemove(MessageLogRemoveReqVo req);
/**
* 删除日期
*
* @param day
*/
void clearLog(String day);
/**
* 发送消息
*
......
......@@ -15,11 +15,4 @@ public interface QueueService {
* @param req 保存队列服务
*/
void create(QueueVo req);
/**
* 删除日期
*
* @param day
*/
void clearLog(String day);
}
......@@ -2,6 +2,7 @@ package com.yanzuoguang.mq.service.impl;
import com.alibaba.fastjson.TypeReference;
import com.rabbitmq.client.Channel;
import com.yanzuoguang.mq.MqInit;
import com.yanzuoguang.mq.base.MqConsumeDynamic;
import com.yanzuoguang.mq.dao.MessageLogDao;
import com.yanzuoguang.mq.dao.QueueServerDao;
......@@ -26,7 +27,9 @@ import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanInitializationException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.*;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import java.io.IOException;
import java.util.ArrayList;
......@@ -38,7 +41,8 @@ import java.util.List;
* @author 颜佐光
*/
@Component
public class MqServiceImpl implements MqService, InitializingBean, ApplicationContextAware {
@Order(1)
public class MqServiceImpl implements MqService, ApplicationContextAware, MqInit {
private QueueService queueService;
private MessageService messageService;
......@@ -70,29 +74,19 @@ public class MqServiceImpl implements MqService, InitializingBean, ApplicationCo
*/
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
queueService = applicationContext.getBean(QueueService.class);
messageService = applicationContext.getBean(MessageService.class);
mqConsumeDynamic = applicationContext.getBean(MqConsumeDynamic.class);
messageLogDao = applicationContext.getBean(MessageLogDao.class);
queueServerDao = applicationContext.getBean(QueueServerDao.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);
this.localName = UrlHelper.getIp();
}
/**
* 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 {
public void initMq() {
QueueVo removeToken = new QueueVo(YzgMqProcedure.YZG_MQ_CLEAR_TOKEN_QUEUE);
removeToken.check();
queueService.create(removeToken);
......@@ -160,6 +154,20 @@ public class MqServiceImpl implements MqService, InitializingBean, ApplicationCo
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;
public class QueueServiceImpl implements QueueService, ApplicationContextAware {
private BeanDao beanDao;
private MessageLogDao messageLogDao;
private MqService mqService;
private YzgMqProcedure mqProcedure;
/**
* Set the ApplicationContext that this object runs in.
......@@ -45,9 +42,6 @@ public class QueueServiceImpl implements QueueService, ApplicationContextAware {
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
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 {
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