Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
dmhub-plugin
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
qinxunjia
dmhub-plugin
Commits
ee15d7ea
Commit
ee15d7ea
authored
Apr 21, 2020
by
qinxunjia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加dao
parent
47bed68d
Changes
18
Show whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
749 additions
and
18 deletions
+749
-18
pom.xml
pom.xml
+13
-3
XfaceDmHubSendRequestDTO.java
src/main/java/com/jz/sms/dto/XfaceDmHubSendRequestDTO.java
+3
-3
SysBatchMapper.java
src/main/java/com/jz/sms/repository/SysBatchMapper.java
+10
-0
TemplateMapper.java
src/main/java/com/jz/sms/repository/TemplateMapper.java
+10
-0
BaseEntity.java
src/main/java/com/jz/sms/repository/domain/BaseEntity.java
+27
-0
DmBatchInfo.java
src/main/java/com/jz/sms/repository/domain/DmBatchInfo.java
+88
-0
SmsTemplateInfo.java
...in/java/com/jz/sms/repository/domain/SmsTemplateInfo.java
+85
-0
SysBatchInfo.java
src/main/java/com/jz/sms/repository/domain/SysBatchInfo.java
+116
-0
MessageServiceImpl.java
...main/java/com/jz/sms/service/impl/MessageServiceImpl.java
+41
-6
Id.java
src/main/java/com/jz/sms/util/id/Id.java
+193
-0
IdHandler.java
src/main/java/com/jz/sms/util/id/IdHandler.java
+27
-0
SystemClock.java
src/main/java/com/jz/sms/util/id/SystemClock.java
+69
-0
XfaceTempLateListWrapper.java
.../com/jz/sms/wrapper/inquiry/XfaceTempLateListWrapper.java
+2
-0
application-test.yml
src/main/resources/application-test.yml
+4
-4
application.yml
src/main/resources/application.yml
+12
-2
logback-spring.xml
src/main/resources/logback-spring.xml
+33
-0
MessageMapper.xml
src/main/resources/mapper/MessageMapper.xml
+0
-0
TemplateMapper.xml
src/main/resources/mapper/TemplateMapper.xml
+16
-0
No files found.
pom.xml
View file @
ee15d7ea
...
@@ -65,16 +65,26 @@
...
@@ -65,16 +65,26 @@
<version>
1.2.62
</version>
<version>
1.2.62
</version>
</dependency>
</dependency>
<dependency>
<groupId>
com.baomidou
</groupId>
<artifactId>
mybatis-plus-boot-starter
</artifactId>
<version>
2.3
</version>
</dependency>
</dependencies>
</dependencies>
<build>
<build>
<finalName>
dmhub-plugin
</finalName>
<plugins>
<plugins>
<plugin>
<plugin>
<groupId>
org.springframework.boot
</groupId>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-maven-plugin
</artifactId>
<artifactId>
spring-boot-maven-plugin
</artifactId>
</plugin>
</plugin>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-surefire-plugin
</artifactId>
<configuration>
<skipTests>
true
</skipTests>
</configuration>
</plugin>
</plugins>
</plugins>
</build>
</build>
...
...
src/main/java/com/jz/sms/dto/XfaceDmHubSendRequestDTO.java
View file @
ee15d7ea
...
@@ -18,7 +18,7 @@ public class XfaceDmHubSendRequestDTO {
...
@@ -18,7 +18,7 @@ public class XfaceDmHubSendRequestDTO {
private
String
audienceIdType
;
private
String
audienceIdType
;
// 发送数据
// 发送数据
private
List
<
JSONObject
>
data
;
private
JSONObject
data
;
public
String
getTemplateId
()
{
public
String
getTemplateId
()
{
...
@@ -45,11 +45,11 @@ public class XfaceDmHubSendRequestDTO {
...
@@ -45,11 +45,11 @@ public class XfaceDmHubSendRequestDTO {
this
.
audienceIdType
=
audienceIdType
;
this
.
audienceIdType
=
audienceIdType
;
}
}
public
List
<
JSONObject
>
getData
()
{
public
JSONObject
getData
()
{
return
data
;
return
data
;
}
}
public
void
setData
(
List
<
JSONObject
>
data
)
{
public
void
setData
(
JSONObject
data
)
{
this
.
data
=
data
;
this
.
data
=
data
;
}
}
}
}
src/main/java/com/jz/sms/repository/SysBatchMapper.java
0 → 100644
View file @
ee15d7ea
package
com
.
jz
.
sms
.
repository
;
import
com.baomidou.mybatisplus.mapper.BaseMapper
;
import
com.jz.sms.repository.domain.SmsTemplateInfo
;
import
com.jz.sms.repository.domain.SysBatchInfo
;
public
interface
SysBatchMapper
extends
BaseMapper
<
SysBatchInfo
>
{
}
src/main/java/com/jz/sms/repository/TemplateMapper.java
0 → 100644
View file @
ee15d7ea
package
com
.
jz
.
sms
.
repository
;
import
com.baomidou.mybatisplus.mapper.BaseMapper
;
import
com.jz.sms.repository.domain.SmsTemplateInfo
;
import
org.apache.ibatis.annotations.Mapper
;
public
interface
TemplateMapper
extends
BaseMapper
<
SmsTemplateInfo
>
{
}
src/main/java/com/jz/sms/repository/domain/BaseEntity.java
0 → 100644
View file @
ee15d7ea
package
com
.
jz
.
sms
.
repository
.
domain
;
import
com.fasterxml.jackson.annotation.JsonFormat
;
import
java.io.Serializable
;
import
java.util.Date
;
public
class
BaseEntity
implements
Serializable
{
private
static
final
long
serialVersionUID
=
8100192126279967648L
;
// 表关键字
protected
Long
id
;
// 记录是否逻辑删除(默认为false)
private
Boolean
delFlag
=
false
;
// 记录创建人信息
private
String
creater
;
// 记录创建日期
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
,
timezone
=
"GMT+8"
)
private
Date
createTime
;
// 记录更新人信息
private
String
updater
;
// 记录最近修改日期
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
,
timezone
=
"GMT+8"
)
private
Date
updateTime
;
//获取redis的key值
private
String
key
;
}
src/main/java/com/jz/sms/repository/domain/DmBatchInfo.java
0 → 100644
View file @
ee15d7ea
package
com
.
jz
.
sms
.
repository
.
domain
;
import
java.util.Date
;
public
class
DmBatchInfo
{
private
Long
id
;
private
String
dmBatchId
;
private
String
dmTemplateId
;
private
Integer
smsNum
;
private
Integer
successNum
;
private
Integer
failNum
;
private
Date
dateCreated
;
private
Date
lastUpdated
;
public
Long
getId
()
{
return
id
;
}
public
void
setId
(
Long
id
)
{
this
.
id
=
id
;
}
public
String
getDmBatchId
()
{
return
dmBatchId
;
}
public
void
setDmBatchId
(
String
dmBatchId
)
{
this
.
dmBatchId
=
dmBatchId
;
}
public
String
getDmTemplateId
()
{
return
dmTemplateId
;
}
public
void
setDmTemplateId
(
String
dmTemplateId
)
{
this
.
dmTemplateId
=
dmTemplateId
;
}
public
Integer
getSmsNum
()
{
return
smsNum
;
}
public
void
setSmsNum
(
Integer
smsNum
)
{
this
.
smsNum
=
smsNum
;
}
public
Integer
getSuccessNum
()
{
return
successNum
;
}
public
void
setSuccessNum
(
Integer
successNum
)
{
this
.
successNum
=
successNum
;
}
public
Integer
getFailNum
()
{
return
failNum
;
}
public
void
setFailNum
(
Integer
failNum
)
{
this
.
failNum
=
failNum
;
}
public
Date
getDateCreated
()
{
return
dateCreated
;
}
public
void
setDateCreated
(
Date
dateCreated
)
{
this
.
dateCreated
=
dateCreated
;
}
public
Date
getLastUpdated
()
{
return
lastUpdated
;
}
public
void
setLastUpdated
(
Date
lastUpdated
)
{
this
.
lastUpdated
=
lastUpdated
;
}
}
src/main/java/com/jz/sms/repository/domain/SmsTemplateInfo.java
0 → 100644
View file @
ee15d7ea
package
com
.
jz
.
sms
.
repository
.
domain
;
import
java.util.Date
;
public
class
SmsTemplateInfo
{
private
Long
id
;
private
String
dmTemplateId
;
private
String
type
;
private
String
status
;
private
String
content
;
private
Date
dateCreated
;
private
Date
lastUpdated
;
public
SmsTemplateInfo
()
{
}
public
SmsTemplateInfo
(
String
dmTemplateId
)
{
this
.
dmTemplateId
=
dmTemplateId
;
}
public
Long
getId
()
{
return
id
;
}
public
void
setId
(
Long
id
)
{
this
.
id
=
id
;
}
public
String
getDmTemplateId
()
{
return
dmTemplateId
;
}
public
void
setDmTemplateId
(
String
dmTemplateId
)
{
this
.
dmTemplateId
=
dmTemplateId
;
}
public
String
getType
()
{
return
type
;
}
public
void
setType
(
String
type
)
{
this
.
type
=
type
;
}
public
String
getStatus
()
{
return
status
;
}
public
void
setStatus
(
String
status
)
{
this
.
status
=
status
;
}
public
String
getContent
()
{
return
content
;
}
public
void
setContent
(
String
content
)
{
this
.
content
=
content
;
}
public
Date
getDateCreated
()
{
return
dateCreated
;
}
public
void
setDateCreated
(
Date
dateCreated
)
{
this
.
dateCreated
=
dateCreated
;
}
public
Date
getLastUpdated
()
{
return
lastUpdated
;
}
public
void
setLastUpdated
(
Date
lastUpdated
)
{
this
.
lastUpdated
=
lastUpdated
;
}
}
src/main/java/com/jz/sms/repository/domain/SysBatchInfo.java
0 → 100644
View file @
ee15d7ea
package
com
.
jz
.
sms
.
repository
.
domain
;
import
java.util.Date
;
public
class
SysBatchInfo
{
private
Long
id
;
private
String
dmBatchId
;
private
String
dmTemplateId
;
private
Long
batchId
;
private
String
report
;
private
String
extend
;
private
String
msgId
;
private
String
errorMsg
;
private
String
code
;
private
Date
dateCreated
;
private
Date
lastUpdated
;
public
Long
getId
()
{
return
id
;
}
public
void
setId
(
Long
id
)
{
this
.
id
=
id
;
}
public
String
getDmBatchId
()
{
return
dmBatchId
;
}
public
void
setDmBatchId
(
String
dmBatchId
)
{
this
.
dmBatchId
=
dmBatchId
;
}
public
String
getDmTemplateId
()
{
return
dmTemplateId
;
}
public
void
setDmTemplateId
(
String
dmTemplateId
)
{
this
.
dmTemplateId
=
dmTemplateId
;
}
public
Long
getBatchId
()
{
return
batchId
;
}
public
void
setBatchId
(
Long
batchId
)
{
this
.
batchId
=
batchId
;
}
public
String
getReport
()
{
return
report
;
}
public
void
setReport
(
String
report
)
{
this
.
report
=
report
;
}
public
String
getExtend
()
{
return
extend
;
}
public
void
setExtend
(
String
extend
)
{
this
.
extend
=
extend
;
}
public
String
getMsgId
()
{
return
msgId
;
}
public
void
setMsgId
(
String
msgId
)
{
this
.
msgId
=
msgId
;
}
public
String
getErrorMsg
()
{
return
errorMsg
;
}
public
void
setErrorMsg
(
String
errorMsg
)
{
this
.
errorMsg
=
errorMsg
;
}
public
String
getCode
()
{
return
code
;
}
public
void
setCode
(
String
code
)
{
this
.
code
=
code
;
}
public
Date
getDateCreated
()
{
return
dateCreated
;
}
public
void
setDateCreated
(
Date
dateCreated
)
{
this
.
dateCreated
=
dateCreated
;
}
public
Date
getLastUpdated
()
{
return
lastUpdated
;
}
public
void
setLastUpdated
(
Date
lastUpdated
)
{
this
.
lastUpdated
=
lastUpdated
;
}
}
src/main/java/com/jz/sms/service/impl/MessageServiceImpl.java
View file @
ee15d7ea
package
com
.
jz
.
sms
.
service
.
impl
;
package
com
.
jz
.
sms
.
service
.
impl
;
import
com.jz.sms.config.SMSConfig
;
import
com.alibaba.fastjson.JSONObject
;
import
com.jz.sms.chuanlan.service.ChuanLanSmsService
;
import
com.jz.sms.dto.*
;
import
com.jz.sms.dto.*
;
import
com.jz.sms.repository.MessageMapper
;
import
com.jz.sms.repository.SysBatchMapper
;
import
com.jz.sms.repository.TemplateMapper
;
import
com.jz.sms.repository.domain.SmsTemplateInfo
;
import
com.jz.sms.repository.domain.SysBatchInfo
;
import
com.jz.sms.service.MessageService
;
import
com.jz.sms.service.MessageService
;
import
com.jz.sms.util.id.IdHandler
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
@Service
@Service
public
class
MessageServiceImpl
implements
MessageService
{
public
class
MessageServiceImpl
implements
MessageService
{
/**
* 数据层
@Autowired
*/
private
SysBatchMapper
sysBatchMapper
;
@Autowired
@Autowired
private
MessageMapper
messageMapper
;
private
TemplateMapper
templateMapper
;
@Autowired
private
ChuanLanSmsService
chuanLanSmsService
;
/**
/**
* 短信模板创建
* 短信模板创建
...
@@ -41,6 +50,32 @@ public class MessageServiceImpl implements MessageService {
...
@@ -41,6 +50,32 @@ public class MessageServiceImpl implements MessageService {
@Override
@Override
public
XfaceDmHubSendResponseDTO
send
(
XfaceDmHubSendRequestDTO
requestDTO
)
{
public
XfaceDmHubSendResponseDTO
send
(
XfaceDmHubSendRequestDTO
requestDTO
)
{
try
{
String
dmHubBatchId
=
requestDTO
.
getBatchId
();
String
templateId
=
requestDTO
.
getTemplateId
();
String
audienceIdType
=
requestDTO
.
getAudienceIdType
();
JSONObject
data
=
requestDTO
.
getData
();
// 获取模板信息
SmsTemplateInfo
templateInfo
=
templateMapper
.
selectOne
(
new
SmsTemplateInfo
(
templateId
));
if
(
null
==
templateInfo
)
{
return
null
;
}
String
content
=
templateInfo
.
getContent
();
String
smsType
=
templateInfo
.
getType
();
// 系统记录批次,不管是单发还是批量发送都当是批量发送处理
SysBatchInfo
info
=
new
SysBatchInfo
();
info
.
setBatchId
(
IdHandler
.
nextId
());
Integer
insert
=
sysBatchMapper
.
insert
(
info
);
// chuanLanSmsService.sendByFixed(content);
}
catch
(
Exception
e
)
{
}
return
null
;
return
null
;
}
}
...
...
src/main/java/com/jz/sms/util/id/Id.java
0 → 100644
View file @
ee15d7ea
package
com
.
jz
.
sms
.
util
.
id
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
/**
* 基于Twitter的Snowflake算法实现分布式高效有序ID生产黑科技(sequence)
*
* <br>
* SnowFlake的结构如下(每部分用-分开):<br>
* <br>
* 0 - 0000000000 0000000000 0000000000 0000000000 0 - 00000 - 00000 - 000000000000 <br>
* <br>
* 1位标识,由于long基本类型在Java中是带符号的,最高位是符号位,正数是0,负数是1,所以id一般是正数,最高位是0<br>
* <br>
* 41位时间截(毫秒级),注意,41位时间截不是存储当前时间的时间截,而是存储时间截的差值(当前时间截 - 开始时间截)
* 得到的值),这里的的开始时间截,一般是我们的id生成器开始使用的时间,由我们程序来指定的(如下下面程序IdWorker类的startTime属性)。41位的时间截,可以使用69年,年T = (1L << 41) / (1000L * 60 * 60 * 24 * 365) = 69<br>
* <br>
* 10位的数据机器位,可以部署在1024个节点,包括5位datacenterId和5位workerId<br>
* <br>
* 12位序列,毫秒内的计数,12位的计数顺序号支持每个节点每毫秒(同一机器,同一时间截)产生4096个ID序号<br>
* <br>
* <br>
* 加起来刚好64位,为一个Long型。<br>
* SnowFlake的优点是,整体上按照时间自增排序,并且整个分布式系统内不会产生ID碰撞(由数据中心ID和机器ID作区分),并且效率较高,经测试,SnowFlake每秒能够产生26万ID左右。
*
* @author lry
* @modify shuliangxing
* @see <a href="https://tech.meituan.com/MT_Leaf.html">常见id策略对比分析</a>
* @see <a href="https://github.com/twitter/snowflake">twitter snowflake</a>
* @see <a href="https://gitee.com/yu120/sequence">sequence</a>
*/
public
class
Id
{
/**
* 起始时间戳,用于用当前时间戳减去这个时间戳,算出偏移量
**/
// 某一时刻时间戳, 2018-05-01 00:00:00 1525104000000
private
final
long
startTime
=
1525104000000L
;
/**
* workerId占用的位数5(表示只允许workId的范围为:0-1023)
**/
private
final
long
workerIdBits
=
5L
;
/**
* dataCenterId占用的位数:5
**/
private
final
long
dataCenterIdBits
=
5L
;
/**
* 序列号占用的位数:12(表示只允许workId的范围为:0-4095)
**/
private
final
long
sequenceBits
=
12L
;
/**
* workerId可以使用的最大数值:31
**/
private
final
long
maxWorkerId
=
-
1L
^
(-
1L
<<
workerIdBits
);
/**
* dataCenterId可以使用的最大数值:31
**/
private
final
long
maxDataCenterId
=
-
1L
^
(-
1L
<<
dataCenterIdBits
);
private
final
long
workerIdShift
=
sequenceBits
;
private
final
long
dataCenterIdShift
=
sequenceBits
+
workerIdBits
;
private
final
long
timestampLeftShift
=
sequenceBits
+
workerIdBits
+
dataCenterIdBits
;
/**
* 用mask防止溢出:位与运算保证计算的结果范围始终是 0-4095
**/
private
final
long
sequenceMask
=
-
1L
^
(-
1L
<<
sequenceBits
);
private
long
workerId
;
private
long
dataCenterId
;
private
long
sequence
=
0L
;
private
long
lastTimestamp
=
-
1L
;
private
boolean
isClock
=
false
;
/**
* 基于Snowflake创建分布式ID生成器
* <p>
* 注:sequence
*
* @param workerId 工作机器ID,数据范围为0~31
* @param dataCenterId 数据中心ID,数据范围为0~31
*/
public
Id
(
long
workerId
,
long
dataCenterId
)
{
if
(
workerId
>
maxWorkerId
||
workerId
<
0
)
{
throw
new
IllegalArgumentException
(
String
.
format
(
"worker Id can't be greater than %d or less than 0"
,
maxWorkerId
));
}
if
(
dataCenterId
>
maxDataCenterId
||
dataCenterId
<
0
)
{
throw
new
IllegalArgumentException
(
String
.
format
(
"dataCenter Id can't be greater than %d or less than 0"
,
maxDataCenterId
));
}
this
.
workerId
=
workerId
;
this
.
dataCenterId
=
dataCenterId
;
}
public
void
setClock
(
boolean
clock
)
{
isClock
=
clock
;
}
/**
* 获取ID
*
* @return
*/
public
synchronized
Long
nextId
()
{
long
timestamp
=
this
.
timeGen
();
// 闰秒:如果当前时间小于上一次ID生成的时间戳,说明系统时钟回退过这个时候应当抛出异常
if
(
timestamp
<
lastTimestamp
)
{
long
offset
=
lastTimestamp
-
timestamp
;
if
(
offset
<=
5
)
{
try
{
this
.
wait
(
offset
<<
1
);
timestamp
=
this
.
timeGen
();
if
(
timestamp
<
lastTimestamp
)
{
throw
new
RuntimeException
(
String
.
format
(
"Clock moved backwards. Refusing to generate id for %d milliseconds"
,
offset
));
}
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
e
);
}
}
else
{
throw
new
RuntimeException
(
String
.
format
(
"Clock moved backwards. Refusing to generate id for %d milliseconds"
,
offset
));
}
}
// 解决跨毫秒生成ID序列号始终为偶数的缺陷:如果是同一时间生成的,则进行毫秒内序列
if
(
lastTimestamp
==
timestamp
)
{
// 通过位与运算保证计算的结果范围始终是 0-4095
sequence
=
(
sequence
+
1
)
&
sequenceMask
;
if
(
sequence
==
0
)
{
timestamp
=
this
.
tilNextMillis
(
lastTimestamp
);
}
}
else
{
// 时间戳改变,毫秒内序列重置
sequence
=
0L
;
}
lastTimestamp
=
timestamp
;
/*
* 1.左移运算是为了将数值移动到对应的段(41、5、5,12那段因为本来就在最右,因此不用左移)
* 2.然后对每个左移后的值(la、lb、lc、sequence)做位或运算,是为了把各个短的数据合并起来,合并成一个二进制数
* 3.最后转换成10进制,就是最终生成的id
*/
return
((
timestamp
-
startTime
)
<<
timestampLeftShift
)
|
(
dataCenterId
<<
dataCenterIdShift
)
|
(
workerId
<<
workerIdShift
)
|
sequence
;
}
/**
* 保证返回的毫秒数在参数之后(阻塞到下一个毫秒,直到获得新的时间戳)
*
* @param lastTimestamp
* @return
*/
private
long
tilNextMillis
(
long
lastTimestamp
)
{
long
timestamp
=
this
.
timeGen
();
while
(
timestamp
<=
lastTimestamp
)
{
timestamp
=
this
.
timeGen
();
}
return
timestamp
;
}
/**
* 获得系统当前毫秒数
*
* @return timestamp
*/
private
long
timeGen
()
{
if
(
isClock
)
{
// 解决高并发下获取时间戳的性能问题
return
SystemClock
.
now
();
}
else
{
return
System
.
currentTimeMillis
();
}
}
public
static
void
main
(
String
[]
args
)
throws
ParseException
{
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
Date
date
=
sdf
.
parse
(
"2018-05-01 00:00:00"
);
//1525104000000
System
.
out
.
println
(
"\r\n----------Id.main()----------sdf.format(date)="
+
sdf
.
format
(
date
));
System
.
out
.
println
(
"\r\n----------Id.main()----------date.getTime()="
+
date
.
getTime
());
}
}
\ No newline at end of file
src/main/java/com/jz/sms/util/id/IdHandler.java
0 → 100644
View file @
ee15d7ea
package
com
.
jz
.
sms
.
util
.
id
;
public
class
IdHandler
{
private
IdHandler
()
{
super
();
}
private
static
final
Id
id
=
new
Id
(
0
,
0
);
public
static
Id
getInstance
()
{
return
id
;
}
public
static
long
nextId
()
{
return
id
.
nextId
();
}
public
static
String
nextIdStr
()
{
return
String
.
valueOf
(
nextId
());
}
public
static
void
main
(
String
[]
args
)
{
}
}
src/main/java/com/jz/sms/util/id/SystemClock.java
0 → 100644
View file @
ee15d7ea
package
com
.
jz
.
sms
.
util
.
id
;
import
java.sql.Timestamp
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.ScheduledExecutorService
;
import
java.util.concurrent.ThreadFactory
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.atomic.AtomicLong
;
/**
* 高并发场景下System.currentTimeMillis()的性能问题的优化
* <p><p>
* System.currentTimeMillis()的调用比new一个普通对象要耗时的多(具体耗时高出多少我还没测试过,有人说是100倍左右)<p>
* System.currentTimeMillis()之所以慢是因为去跟系统打了一次交道<p>
* 后台定时更新时钟,JVM退出时,线程自动回收<p>
* 10亿:43410,206,210.72815533980582%<p>
* 1亿:4699,29,162.0344827586207%<p>
* 1000万:480,12,40.0%<p>
* 100万:50,10,5.0%<p>
*
* @author lry
*/
public
class
SystemClock
{
private
final
long
period
;
private
final
AtomicLong
now
;
private
SystemClock
(
long
period
)
{
this
.
period
=
period
;
this
.
now
=
new
AtomicLong
(
System
.
currentTimeMillis
());
scheduleClockUpdating
();
}
private
static
class
InstanceHolder
{
public
static
final
SystemClock
INSTANCE
=
new
SystemClock
(
1
);
}
private
static
SystemClock
instance
()
{
return
InstanceHolder
.
INSTANCE
;
}
private
void
scheduleClockUpdating
()
{
ScheduledExecutorService
scheduler
=
Executors
.
newSingleThreadScheduledExecutor
(
new
ThreadFactory
()
{
public
Thread
newThread
(
Runnable
runnable
)
{
Thread
thread
=
new
Thread
(
runnable
,
"System Clock"
);
thread
.
setDaemon
(
true
);
return
thread
;
}
});
scheduler
.
scheduleAtFixedRate
(
new
Runnable
()
{
public
void
run
()
{
now
.
set
(
System
.
currentTimeMillis
());
}
},
period
,
period
,
TimeUnit
.
MILLISECONDS
);
}
private
long
currentTimeMillis
()
{
return
now
.
get
();
}
public
static
long
now
()
{
return
instance
().
currentTimeMillis
();
}
public
static
String
nowDate
()
{
return
new
Timestamp
(
instance
().
currentTimeMillis
()).
toString
();
}
}
src/main/java/com/jz/sms/wrapper/inquiry/XfaceTempLateListWrapper.java
View file @
ee15d7ea
package
com
.
jz
.
sms
.
wrapper
.
inquiry
;
package
com
.
jz
.
sms
.
wrapper
.
inquiry
;
public
class
XfaceTempLateListWrapper
{
public
class
XfaceTempLateListWrapper
{
}
}
src/main/resources/application-test.yml
View file @
ee15d7ea
# 测试环境配置
# 测试环境配置
server
:
server
:
port
:
9010
port
:
1
9010
#contextPath: /resource
#contextPath: /resource
spring
:
spring
:
datasource
:
datasource
:
url
:
jdbc:mysql://1
27.0.0.1:3306/dmp_web
?characterEncoding=utf8&useSSL=false
url
:
jdbc:mysql://1
19.23.32.151:3306/dmhub_plugin
?characterEncoding=utf8&useSSL=false
driver-class-name
:
com.mysql.jdbc.Driver
driver-class-name
:
com.mysql.jdbc.Driver
username
:
root
username
:
dmp
password
:
root
password
:
Ioubuy@2019@!
hikari
:
hikari
:
maxLifetime
:
1765000
maxLifetime
:
1765000
maximumPoolSize
:
20
maximumPoolSize
:
20
...
...
src/main/resources/application.yml
View file @
ee15d7ea
...
@@ -10,4 +10,14 @@ spring:
...
@@ -10,4 +10,14 @@ spring:
profiles
:
profiles
:
active
:
test
active
:
test
mybatis-plus
:
mapper-locations
:
classpath:mapper/*.xml
type-aliases-package
:
com.jz.sms.repository.domain
configuration
:
map-underscore-to-camel-case
:
true
logging
:
level
:
debug
level.com.jz
:
debug
# 单独指定包下的日志级别
config
:
classpath:logback-spring.xml
\ No newline at end of file
src/main/resources/logback-spring.xml
0 → 100644
View file @
ee15d7ea
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include
resource=
"org/springframework/boot/logging/logback/defaults.xml"
/>
<include
resource=
"org/springframework/boot/logging/logback/console-appender.xml"
/>
<appender
name=
"FILE"
class=
"ch.qos.logback.core.rolling.RollingFileAppender"
>
<File>
${LOG_PATH}${LOG_FILE}
</File>
<encoder>
<pattern>
%date [%level] [%thread] %logger{60} [%file : %line] %msg%n
</pattern>
</encoder>
<rollingPolicy
class=
"ch.qos.logback.core.rolling.TimeBasedRollingPolicy"
>
<fileNamePattern>
${LOG_PATH}daily/${LOG_FILE}.%d{yyyy-MM-dd}.gz
</fileNamePattern>
<maxHistory>
180
</maxHistory>
<!-- 保留180天 -->
</rollingPolicy>
</appender>
<root
level=
"INFO"
>
<appender-ref
ref=
"CONSOLE"
/>
<appender-ref
ref=
"FILE"
/>
</root>
<!-- 开发、测试环境 -->
<springProfile
name=
"dev,test"
>
<logger
name=
"org.springboot.sample"
level=
"DEBUG"
/>
<logger
name=
"com.jz"
level=
"DEBUG"
/>
</springProfile>
<!-- 生产环境 -->
<springProfile
name=
"prod"
>
<logger
name=
"org.springframework.web"
level=
"ERROR"
/>
<logger
name=
"org.springboot.sample"
level=
"ERROR"
/>
<logger
name=
"com.jz"
level=
"ERROR"
/>
</springProfile>
</configuration>
\ No newline at end of file
src/main/resources/
com.jz.sms.repository
/MessageMapper.xml
→
src/main/resources/
mapper
/MessageMapper.xml
View file @
ee15d7ea
File moved
src/main/resources/mapper/TemplateMapper.xml
0 → 100644
View file @
ee15d7ea
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"com.jz.sms.repository.TemplateMapper"
>
<resultMap
id=
"baseMap"
type=
"com.jz.sms.repository.domain.SmsTemplateInfo"
>
<id
column=
"id"
property=
"id"
/>
<id
column=
"dm_template_id"
property=
"dmTemplateId"
/>
<id
column=
"type"
property=
"type"
/>
<id
column=
"status"
property=
"status"
/>
<id
column=
"content"
property=
"content"
/>
<id
column=
"dateCreated"
property=
"dateCreated"
/>
<id
column=
"lastUpdated"
property=
"lastUpdated"
/>
</resultMap>
</mapper>
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