Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
Y
yzg-util
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
YZG
yzg-util
Commits
836362cb
Commit
836362cb
authored
Aug 04, 2021
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改保存历史记录
parent
2c6a8b8f
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
127 additions
and
38 deletions
+127
-38
MessageLogDao.java
...q/src/main/java/com/yanzuoguang/mq/dao/MessageLogDao.java
+1
-1
MessageLogDaoImpl.java
...n/java/com/yanzuoguang/mq/dao/impl/MessageLogDaoImpl.java
+12
-12
YzgMqConsumer.java
.../src/main/java/com/yanzuoguang/mq/plan/YzgMqConsumer.java
+27
-0
YzgMqProcedure.java
...src/main/java/com/yanzuoguang/mq/plan/YzgMqProcedure.java
+28
-0
MqService.java
...q/src/main/java/com/yanzuoguang/mq/service/MqService.java
+4
-4
QueueService.java
...rc/main/java/com/yanzuoguang/mq/service/QueueService.java
+7
-2
MqServiceImpl.java
...n/java/com/yanzuoguang/mq/service/impl/MqServiceImpl.java
+9
-9
QueueServiceImpl.java
...ava/com/yanzuoguang/mq/service/impl/QueueServiceImpl.java
+29
-0
MessageLogVo.java
...-mq/src/main/java/com/yanzuoguang/mq/vo/MessageLogVo.java
+3
-3
MessageLogRemoveReqVo.java
...java/com/yanzuoguang/mq/vo/req/MessageLogRemoveReqVo.java
+3
-3
MessageLogReqVo.java
.../main/java/com/yanzuoguang/mq/vo/req/MessageLogReqVo.java
+4
-4
No files found.
yzg-util-mq/src/main/java/com/yanzuoguang/mq/dao/Message
Plan
Dao.java
→
yzg-util-mq/src/main/java/com/yanzuoguang/mq/dao/Message
Log
Dao.java
View file @
836362cb
...
...
@@ -8,7 +8,7 @@ import com.yanzuoguang.dao.BaseDao;
*
* @author 颜佐光
*/
public
interface
Message
Plan
Dao
extends
BaseDao
{
public
interface
Message
Log
Dao
extends
BaseDao
{
/**
* 删除超时数据
*/
...
...
yzg-util-mq/src/main/java/com/yanzuoguang/mq/dao/impl/Message
Plan
DaoImpl.java
→
yzg-util-mq/src/main/java/com/yanzuoguang/mq/dao/impl/Message
Log
DaoImpl.java
View file @
836362cb
package
com
.
yanzuoguang
.
mq
.
dao
.
impl
;
import
com.yanzuoguang.dao.impl.BaseDaoImpl
;
import
com.yanzuoguang.mq.dao.Message
Plan
Dao
;
import
com.yanzuoguang.mq.vo.Message
Plan
Vo
;
import
com.yanzuoguang.mq.dao.Message
Log
Dao
;
import
com.yanzuoguang.mq.vo.Message
Log
Vo
;
import
com.yanzuoguang.util.vo.MapRow
;
import
org.springframework.beans.factory.InitializingBean
;
import
org.springframework.stereotype.Component
;
...
...
@@ -15,9 +15,9 @@ import java.util.List;
* @author 颜佐光
*/
@Component
public
class
Message
PlanDaoImpl
extends
BaseDaoImpl
implements
MessagePlan
Dao
,
InitializingBean
{
private
static
final
String
QUERY_TABLE_SQL
=
"SHOW TABLES LIKE 'queue_
plan
'"
;
private
static
final
String
CREATE_TABLE_SQL
=
"CREATE TABLE `queue_
plan
` ( "
+
public
class
Message
LogDaoImpl
extends
BaseDaoImpl
implements
MessageLog
Dao
,
InitializingBean
{
private
static
final
String
QUERY_TABLE_SQL
=
"SHOW TABLES LIKE 'queue_
log
'"
;
private
static
final
String
CREATE_TABLE_SQL
=
"CREATE TABLE `queue_
log
` ( "
+
" `id` varchar(32) NOT NULL COMMENT '消息编号', "
+
" `queue` varchar(255) NOT NULL DEFAULT '' COMMENT '队列名称', "
+
" `messageId` varchar(255) NOT NULL DEFAULT '' COMMENT '消息编号', "
+
...
...
@@ -27,8 +27,8 @@ public class MessagePlanDaoImpl extends BaseDaoImpl implements MessagePlanDao, I
" INDEX `IndexLastTime` (`lastTime`) "
+
" UNIQUE INDEX `IndexQueueMessageId` (`queue`,`queue`) "
+
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='消息任务表'"
;
private
static
final
String
REMOVE_TABLE_SQL
=
"DELETE queue_
plan
WHERE IndexLastTime<NOW()"
;
private
static
final
String
CALC_TABLE_SQL
=
"optimize table queue_
plan
"
;
private
static
final
String
REMOVE_TABLE_SQL
=
"DELETE queue_
log
WHERE IndexLastTime<NOW()"
;
private
static
final
String
CALC_TABLE_SQL
=
"optimize table queue_
log
"
;
/**
* 注册SQL语句
...
...
@@ -36,7 +36,7 @@ public class MessagePlanDaoImpl extends BaseDaoImpl implements MessagePlanDao, I
@Override
protected
void
init
()
{
// 注册表结构
register
(
Message
Plan
Vo
.
class
);
register
(
Message
Log
Vo
.
class
);
}
/**
...
...
@@ -51,9 +51,9 @@ public class MessagePlanDaoImpl extends BaseDaoImpl implements MessagePlanDao, I
*/
@Override
public
void
afterPropertiesSet
()
throws
Exception
{
List
<
MapRow
>
tables
=
this
.
getDb
().
query
(
Message
Plan
DaoImpl
.
class
,
"QUERY_TABLE_SQL"
,
QUERY_TABLE_SQL
);
List
<
MapRow
>
tables
=
this
.
getDb
().
query
(
Message
Log
DaoImpl
.
class
,
"QUERY_TABLE_SQL"
,
QUERY_TABLE_SQL
);
if
(
tables
.
isEmpty
())
{
this
.
getDb
().
update
(
Message
Plan
DaoImpl
.
class
,
"CREATE_TABLE_SQL"
,
CREATE_TABLE_SQL
);
this
.
getDb
().
update
(
Message
Log
DaoImpl
.
class
,
"CREATE_TABLE_SQL"
,
CREATE_TABLE_SQL
);
}
}
...
...
@@ -62,7 +62,7 @@ public class MessagePlanDaoImpl extends BaseDaoImpl implements MessagePlanDao, I
*/
@Override
public
void
removeLastTime
()
{
this
.
getDb
().
update
(
Message
Plan
DaoImpl
.
class
,
"REMOVE_TABLE_SQL"
,
REMOVE_TABLE_SQL
);
this
.
getDb
().
update
(
Message
Plan
DaoImpl
.
class
,
"CALC_TABLE_SQL"
,
CALC_TABLE_SQL
);
this
.
getDb
().
update
(
Message
Log
DaoImpl
.
class
,
"REMOVE_TABLE_SQL"
,
REMOVE_TABLE_SQL
);
this
.
getDb
().
update
(
Message
Log
DaoImpl
.
class
,
"CALC_TABLE_SQL"
,
CALC_TABLE_SQL
);
}
}
yzg-util-mq/src/main/java/com/yanzuoguang/mq/plan/YzgMqConsumer.java
View file @
836362cb
...
...
@@ -2,6 +2,7 @@ package com.yanzuoguang.mq.plan;
import
com.rabbitmq.client.Channel
;
import
com.yanzuoguang.mq.service.MqService
;
import
com.yanzuoguang.mq.service.QueueService
;
import
com.yanzuoguang.mq.vo.MessagePlan
;
import
com.yanzuoguang.mq.vo.MessageVo
;
import
com.yanzuoguang.mq.vo.req.RegisterServerTokenReqVo
;
...
...
@@ -28,6 +29,9 @@ public class YzgMqConsumer implements InitializingBean {
@Autowired
private
YzgMqProcedure
yzgMqProcedure
;
@Autowired
private
QueueService
queueService
;
/**
* Invoked by a BeanFactory after it has set all bean properties supplied
* (and satisfied BeanFactoryAware and ApplicationContextAware).
...
...
@@ -40,6 +44,7 @@ public class YzgMqConsumer implements InitializingBean {
*/
@Override
public
void
afterPropertiesSet
()
throws
Exception
{
yzgMqProcedure
.
clearLog
();
}
/**
...
...
@@ -113,4 +118,26 @@ public class YzgMqConsumer implements InitializingBean {
mqService
.
basicAck
(
message
,
channel
);
}
}
/**
* 删除日期
*
* @param day
* @param message
* @param channel
*/
@RabbitListener
(
queues
=
{
YzgMqProcedure
.
YZG_CLEAR_LOG
})
public
void
yzgClearLog
(
String
day
,
Message
message
,
Channel
channel
)
{
try
{
queueService
.
clearLog
(
day
);
}
catch
(
CodeException
ex
)
{
Log
.
error
(
YzgMqConsumer
.
class
,
ex
);
}
catch
(
Exception
ex
)
{
Log
.
error
(
YzgMqConsumer
.
class
,
ex
);
// 等待100ms再次执行
yzgMqProcedure
.
clearLog
(
day
,
100
);
}
finally
{
mqService
.
basicAck
(
message
,
channel
);
}
}
}
yzg-util-mq/src/main/java/com/yanzuoguang/mq/plan/YzgMqProcedure.java
View file @
836362cb
...
...
@@ -6,6 +6,7 @@ import com.yanzuoguang.mq.vo.MessageVo;
import
com.yanzuoguang.mq.vo.QueueVo
;
import
com.yanzuoguang.mq.vo.req.RegisterServerTokenReqVo
;
import
com.yanzuoguang.util.exception.CodeException
;
import
com.yanzuoguang.util.helper.DateHelper
;
import
com.yanzuoguang.util.helper.JsonHelper
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
org.springframework.beans.factory.InitializingBean
;
...
...
@@ -14,6 +15,7 @@ import org.springframework.beans.factory.annotation.Value;
import
org.springframework.stereotype.Component
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.List
;
/**
...
...
@@ -23,6 +25,10 @@ import java.util.List;
*/
@Component
public
class
YzgMqProcedure
implements
InitializingBean
{
/**
* 执行的消息队列
*/
public
static
final
String
YZG_CLEAR_LOG
=
"YZG_CLEAR_LOG"
;
/**
* 执行的消息队列
*/
...
...
@@ -65,6 +71,7 @@ public class YzgMqProcedure implements InitializingBean {
*/
@Override
public
void
afterPropertiesSet
()
throws
Exception
{
mqService
.
createQueue
(
new
QueueVo
(
YZG_CLEAR_LOG
));
mqService
.
createQueue
(
new
QueueVo
(
YZG_MQ_SYSTEM_QUEUE
));
mqService
.
createQueue
(
new
QueueVo
(
YZG_MQ_SYSTEM_QUEUE_PLAN
));
if
(
YZG_MQ_SYSTEM_QUEUE_PLAN_TIME
.
isEmpty
())
{
...
...
@@ -209,4 +216,25 @@ public class YzgMqProcedure implements InitializingBean {
public
String
sendRemove
(
String
json
,
long
dedTime
)
{
return
mqService
.
message
(
new
MessageVo
(
YZG_MQ_CLEAR_TOKEN_QUEUE
,
YZG_MQ_CLEAR_TOKEN_QUEUE
,
json
,
dedTime
));
}
/**
* 定时删除log
*
* @return
*/
public
String
clearLog
()
{
Date
date
=
DateHelper
.
addDay
(
DateHelper
.
getDateTime
(
DateHelper
.
getToday
()),
1
);
String
nextDay
=
DateHelper
.
getToday
(
date
);
long
delayTime
=
date
.
getTime
()
-
System
.
currentTimeMillis
();
return
clearLog
(
nextDay
,
delayTime
);
}
/**
* 定时删除log
*
* @return
*/
public
String
clearLog
(
String
day
,
long
dedTime
)
{
return
mqService
.
message
(
new
MessageVo
(
YZG_CLEAR_LOG
,
day
,
dedTime
));
}
}
yzg-util-mq/src/main/java/com/yanzuoguang/mq/service/MqService.java
View file @
836362cb
...
...
@@ -39,7 +39,7 @@ public interface MqService {
*
* @return
*/
@ApiOperation
(
value
=
"记录一个消息已完成"
)
@ApiOperation
(
value
=
"记录一个消息已完成
,重复时抛出CodeException异常
"
)
String
log
();
/**
...
...
@@ -48,8 +48,8 @@ public interface MqService {
* @param req 消息的内容
* @return
*/
@ApiOperation
(
value
=
"记录一个消息已完成"
)
String
log
(
Message
PlanSave
ReqVo
req
);
@ApiOperation
(
value
=
"记录一个消息已完成
,重复时抛出CodeException异常
"
)
String
log
(
Message
Log
ReqVo
req
);
/**
* 删除一个消息
...
...
@@ -58,7 +58,7 @@ public interface MqService {
* @return
*/
@ApiOperation
(
value
=
"删除一个消息"
)
String
logRemove
(
Message
Plan
RemoveReqVo
req
);
String
logRemove
(
Message
Log
RemoveReqVo
req
);
/**
* 发送消息
...
...
yzg-util-mq/src/main/java/com/yanzuoguang/mq/service/QueueService.java
View file @
836362cb
...
...
@@ -2,8 +2,6 @@ package com.yanzuoguang.mq.service;
import
com.yanzuoguang.mq.vo.QueueVo
;
import
com.yanzuoguang.mq.vo.req.QueueQueryReqVo
;
import
com.yanzuoguang.util.vo.PageSizeData
;
/**
* 队列服务
...
...
@@ -17,4 +15,11 @@ public interface QueueService {
* @param req 保存队列服务
*/
void
create
(
QueueVo
req
);
/**
* 删除日期
*
* @param day
*/
void
clearLog
(
String
day
);
}
yzg-util-mq/src/main/java/com/yanzuoguang/mq/service/impl/MqServiceImpl.java
View file @
836362cb
...
...
@@ -3,7 +3,7 @@ package com.yanzuoguang.mq.service.impl;
import
com.alibaba.fastjson.TypeReference
;
import
com.rabbitmq.client.Channel
;
import
com.yanzuoguang.mq.base.MqConsumeDynamic
;
import
com.yanzuoguang.mq.dao.Message
Plan
Dao
;
import
com.yanzuoguang.mq.dao.Message
Log
Dao
;
import
com.yanzuoguang.mq.dao.QueueServerDao
;
import
com.yanzuoguang.mq.dao.QueueServerTokenDao
;
import
com.yanzuoguang.mq.plan.YzgMqProcedure
;
...
...
@@ -54,7 +54,7 @@ public class MqServiceImpl implements MqService, InitializingBean {
private
QueueServerTokenDao
queueServerTokenDao
;
@Autowired
private
Message
PlanDao
messagePlan
Dao
;
private
Message
LogDao
messageLog
Dao
;
@Autowired
private
YzgMqProcedure
yzgMqProcedure
;
...
...
@@ -128,14 +128,14 @@ public class MqServiceImpl implements MqService, InitializingBean {
* @return
*/
@Override
public
String
log
(
Message
PlanSave
ReqVo
req
)
{
Message
PlanRemoveReqVo
loadReq
=
new
MessagePlan
RemoveReqVo
(
req
.
getQueue
(),
req
.
getMessageId
());
Message
PlanVo
load
=
messagePlanDao
.
load
(
loadReq
,
MessagePlan
Vo
.
class
);
public
String
log
(
Message
Log
ReqVo
req
)
{
Message
LogRemoveReqVo
loadReq
=
new
MessageLog
RemoveReqVo
(
req
.
getQueue
(),
req
.
getMessageId
());
Message
LogVo
load
=
messageLogDao
.
load
(
loadReq
,
MessageLog
Vo
.
class
);
if
(
load
!=
null
)
{
throw
new
CodeException
(
"消息队列"
+
req
.
getQueue
()
+
"消息"
+
req
.
getMessageId
()
+
"已经执行"
);
}
load
=
JsonHelper
.
to
(
req
,
Message
Plan
Vo
.
class
);
message
Plan
Dao
.
create
(
load
);
load
=
JsonHelper
.
to
(
req
,
Message
Log
Vo
.
class
);
message
Log
Dao
.
create
(
load
);
return
load
.
getId
();
}
...
...
@@ -146,8 +146,8 @@ public class MqServiceImpl implements MqService, InitializingBean {
* @return
*/
@Override
public
String
logRemove
(
Message
Plan
RemoveReqVo
req
)
{
message
PlanDao
.
load
(
req
,
MessagePlan
Vo
.
class
);
public
String
logRemove
(
Message
Log
RemoveReqVo
req
)
{
message
LogDao
.
load
(
req
,
MessageLog
Vo
.
class
);
return
req
.
getMessageId
();
}
...
...
yzg-util-mq/src/main/java/com/yanzuoguang/mq/service/impl/QueueServiceImpl.java
View file @
836362cb
package
com
.
yanzuoguang
.
mq
.
service
.
impl
;
import
com.yanzuoguang.mq.dao.BeanDao
;
import
com.yanzuoguang.mq.dao.MessageLogDao
;
import
com.yanzuoguang.mq.plan.YzgMqProcedure
;
import
com.yanzuoguang.mq.service.MqService
;
import
com.yanzuoguang.mq.service.QueueService
;
import
com.yanzuoguang.mq.vo.QueueVo
;
import
com.yanzuoguang.mq.vo.req.MessageLogReqVo
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
org.springframework.transaction.annotation.Transactional
;
/**
* 交换器服务类
...
...
@@ -17,6 +22,16 @@ public class QueueServiceImpl implements QueueService {
@Autowired
private
BeanDao
beanDao
;
@Autowired
private
MessageLogDao
messageLogDao
;
@Autowired
private
MqService
mqService
;
@Autowired
private
YzgMqProcedure
mqProcedure
;
/**
* 保存接口请求日志
*
...
...
@@ -28,6 +43,20 @@ public class QueueServiceImpl implements QueueService {
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
.
sendClearLog
();
}
/**
* 初始化实体
*
...
...
yzg-util-mq/src/main/java/com/yanzuoguang/mq/vo/Message
Plan
Vo.java
→
yzg-util-mq/src/main/java/com/yanzuoguang/mq/vo/Message
Log
Vo.java
View file @
836362cb
package
com
.
yanzuoguang
.
mq
.
vo
;
import
com.yanzuoguang.dao.TableAnnotation
;
import
com.yanzuoguang.mq.vo.req.Message
PlanSave
ReqVo
;
import
com.yanzuoguang.mq.vo.req.Message
Log
ReqVo
;
import
com.yanzuoguang.util.helper.DateHelper
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
com.yanzuoguang.util.vo.InitDao
;
...
...
@@ -11,8 +11,8 @@ import com.yanzuoguang.util.vo.InitDao;
*
* @author 颜佐光
*/
@TableAnnotation
(
"queue_
plan
"
)
public
class
Message
PlanVo
extends
MessagePlanSave
ReqVo
implements
InitDao
{
@TableAnnotation
(
"queue_
log
"
)
public
class
Message
LogVo
extends
MessageLog
ReqVo
implements
InitDao
{
/**
* 消息临时Id
...
...
yzg-util-mq/src/main/java/com/yanzuoguang/mq/vo/req/Message
Plan
RemoveReqVo.java
→
yzg-util-mq/src/main/java/com/yanzuoguang/mq/vo/req/Message
Log
RemoveReqVo.java
View file @
836362cb
...
...
@@ -7,7 +7,7 @@ import com.yanzuoguang.util.vo.BaseVo;
*
* @author 颜佐光
*/
public
class
Message
Plan
RemoveReqVo
extends
BaseVo
{
public
class
Message
Log
RemoveReqVo
extends
BaseVo
{
/**
* 队列名称,在队列名称为空时会去获取当前的消息队列
...
...
@@ -19,10 +19,10 @@ public class MessagePlanRemoveReqVo extends BaseVo {
*/
protected
String
messageId
;
public
Message
Plan
RemoveReqVo
()
{
public
Message
Log
RemoveReqVo
()
{
}
public
Message
Plan
RemoveReqVo
(
String
queue
,
String
messageId
)
{
public
Message
Log
RemoveReqVo
(
String
queue
,
String
messageId
)
{
this
.
queue
=
queue
;
this
.
messageId
=
messageId
;
}
...
...
yzg-util-mq/src/main/java/com/yanzuoguang/mq/vo/req/Message
PlanSave
ReqVo.java
→
yzg-util-mq/src/main/java/com/yanzuoguang/mq/vo/req/Message
Log
ReqVo.java
View file @
836362cb
...
...
@@ -5,21 +5,21 @@ package com.yanzuoguang.mq.vo.req;
*
* @author 颜佐光
*/
public
class
Message
PlanSaveReqVo
extends
MessagePlan
RemoveReqVo
{
public
class
Message
LogReqVo
extends
MessageLog
RemoveReqVo
{
/**
* 消息最后删除时间,默认为24小时之后,但是不会超过25小时
*/
protected
String
lastTime
;
public
Message
PlanSave
ReqVo
()
{
public
Message
Log
ReqVo
()
{
}
public
Message
PlanSave
ReqVo
(
String
queue
,
String
messageId
)
{
public
Message
Log
ReqVo
(
String
queue
,
String
messageId
)
{
super
(
queue
,
messageId
);
}
public
Message
PlanSave
ReqVo
(
String
queue
,
String
messageId
,
String
lastTime
)
{
public
Message
Log
ReqVo
(
String
queue
,
String
messageId
,
String
lastTime
)
{
super
(
queue
,
messageId
);
this
.
lastTime
=
lastTime
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment