Commit 9fe14032bfe5657a4976ad92e56f53473a530230

Authored by Jiang
0 parents

初始化项目

Showing 68 changed files with 4614 additions and 0 deletions

Too many changes to show.

To preserve performance only 68 of 212 files are displayed.

.gitignore 0 → 100644
  1 +++ a/.gitignore
  1 +*.iml
  2 +.idea
  3 +.classpath
  4 +*/target/
  5 +*/webapp/WEB-INF/classes
  6 +*/webapp/WEB-INF/lib
  7 +*.MF
  8 +**/WEB-INF/classes/
  9 +**/WEB-INF/lib
  10 +**/.settings/
  11 +**/.classpath
  12 +**/.project
0 13 \ No newline at end of file
... ...
dtms-client/pom.xml 0 → 100644
  1 +++ a/dtms-client/pom.xml
  1 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  3 + <modelVersion>4.0.0</modelVersion>
  4 + <parent>
  5 + <groupId>com.b2c.dtms</groupId>
  6 + <artifactId>dtms-parent</artifactId>
  7 + <version>0.0.1-SNAPSHOT</version>
  8 + </parent>
  9 + <artifactId>dtms-client</artifactId>
  10 +
  11 + <dependencies>
  12 + <dependency>
  13 + <groupId>org.slf4j</groupId>
  14 + <artifactId>slf4j-api</artifactId>
  15 + </dependency>
  16 + <dependency>
  17 + <groupId>org.apache.httpcomponents</groupId>
  18 + <artifactId>httpclient</artifactId>
  19 + </dependency>
  20 + <dependency>
  21 + <groupId>commons-lang</groupId>
  22 + <artifactId>commons-lang</artifactId>
  23 + </dependency>
  24 + <dependency>
  25 + <groupId>com.alibaba</groupId>
  26 + <artifactId>fastjson</artifactId>
  27 + </dependency>
  28 + <dependency>
  29 + <groupId>junit</groupId>
  30 + <artifactId>junit</artifactId>
  31 + <scope>test</scope>
  32 + </dependency>
  33 + </dependencies>
  34 +</project>
0 35 \ No newline at end of file
... ...
dtms-client/src/main/java/com/b2c/dtms/client/DtmsClient.java 0 → 100644
  1 +++ a/dtms-client/src/main/java/com/b2c/dtms/client/DtmsClient.java
  1 +package com.b2c.dtms.client;
  2 +
  3 +import org.apache.commons.lang.StringUtils;
  4 +
  5 +import com.alibaba.fastjson.JSON;
  6 +import com.b2c.dtms.client.domain.dto.request.DtmsProduceRequestDto;
  7 +import com.b2c.dtms.client.domain.dto.response.DtmsResponseDto;
  8 +import com.b2c.dtms.common.http.HttpRequester;
  9 +import com.b2c.dtms.common.http.HttpResponse;
  10 +
  11 +public class DtmsClient {
  12 +
  13 + public static final String DTMS_URL = "http://dtms.zandeapp.com";
  14 +
  15 + public DtmsResponseDto produceMessage(DtmsProduceRequestDto message) {
  16 + HttpResponse httpResponse;
  17 + try {
  18 + httpResponse = HttpRequester.sendPost(DTMS_URL + "/api/rest/produce", null, JSON.toJSONString(message));
  19 + if (httpResponse == null) {
  20 + return null;
  21 + }
  22 + if (httpResponse.getStatusCode() != 200) {
  23 + DtmsResponseDto response = new DtmsResponseDto();
  24 + response.setMessage(String.format("无法完成请求,响应码%d", httpResponse.getStatusCode()));
  25 + return response;
  26 + }
  27 + if (StringUtils.isBlank(httpResponse.getBody())) {
  28 + return null;
  29 + }
  30 + return JSON.parseObject(httpResponse.getBody(), DtmsResponseDto.class);
  31 + } catch (Exception e) {
  32 + DtmsResponseDto response = new DtmsResponseDto();
  33 + response.setMessage(e.getMessage());
  34 + return response;
  35 + }
  36 +
  37 + }
  38 +}
... ...
dtms-client/src/main/java/com/b2c/dtms/client/domain/dto/request/DtmsProduceRequestDto.java 0 → 100644
  1 +++ a/dtms-client/src/main/java/com/b2c/dtms/client/domain/dto/request/DtmsProduceRequestDto.java
  1 +package com.b2c.dtms.client.domain.dto.request;
  2 +
  3 +import java.io.Serializable;
  4 +import java.util.Date;
  5 +
  6 +public class DtmsProduceRequestDto implements Serializable {
  7 +
  8 + /**
  9 + *
  10 + */
  11 + private static final long serialVersionUID = 5709408209577989985L;
  12 +
  13 + /**
  14 + * 消息业务ID,比如订单id
  15 + */
  16 + private String bizId;
  17 +
  18 + /**
  19 + * 延迟多久开始消息开始被执行
  20 + */
  21 + private Integer delaySeconds;
  22 +
  23 + /**
  24 + * 期望运行时间,由DTMS服务时间+delaySeconds时间换算而来
  25 + */
  26 + private Date runtime;
  27 +
  28 + /**
  29 + * 消息内容
  30 + */
  31 + private String content;
  32 +
  33 + /**
  34 + * 消息备注
  35 + */
  36 + private String memo;
  37 +
  38 + /**
  39 + * 消息待重试处理次数,由输入设置,此处不设置默认值
  40 + */
  41 + private Long waitRetryNum;
  42 +
  43 + /**
  44 + * 消息关联业务处理url
  45 + */
  46 + private String callUrl;
  47 +
  48 + /**
  49 + * 二次确认url
  50 + */
  51 + private String confirmUrl;
  52 +
  53 + /** 非业务消息类型 */
  54 + private Integer type;
  55 +
  56 + public String getBizId() {
  57 + return bizId;
  58 + }
  59 +
  60 + public void setBizId(String bizId) {
  61 + this.bizId = bizId;
  62 + }
  63 +
  64 + public Integer getDelaySeconds() {
  65 + return delaySeconds;
  66 + }
  67 +
  68 + public void setDelaySeconds(Integer delaySeconds) {
  69 + this.delaySeconds = delaySeconds;
  70 + }
  71 +
  72 + public Date getRuntime() {
  73 + return runtime;
  74 + }
  75 +
  76 + public void setRuntime(Date runtime) {
  77 + this.runtime = runtime;
  78 + }
  79 +
  80 + public String getContent() {
  81 + return content;
  82 + }
  83 +
  84 + public void setContent(String content) {
  85 + this.content = content;
  86 + }
  87 +
  88 + public String getMemo() {
  89 + return memo;
  90 + }
  91 +
  92 + public void setMemo(String memo) {
  93 + this.memo = memo;
  94 + }
  95 +
  96 + public Long getWaitRetryNum() {
  97 + return waitRetryNum;
  98 + }
  99 +
  100 + public void setWaitRetryNum(Long waitRetryNum) {
  101 + this.waitRetryNum = waitRetryNum;
  102 + }
  103 +
  104 + public String getCallUrl() {
  105 + return callUrl;
  106 + }
  107 +
  108 + public void setCallUrl(String callUrl) {
  109 + this.callUrl = callUrl;
  110 + }
  111 +
  112 + public String getConfirmUrl() {
  113 + return confirmUrl;
  114 + }
  115 +
  116 + public void setConfirmUrl(String confirmUrl) {
  117 + this.confirmUrl = confirmUrl;
  118 + }
  119 +
  120 + public Integer getType() {
  121 + return type;
  122 + }
  123 +
  124 + public void setType(Integer type) {
  125 + this.type = type;
  126 + }
  127 +}
... ...
dtms-client/src/main/java/com/b2c/dtms/client/domain/dto/response/DtmsResponseDto.java 0 → 100644
  1 +++ a/dtms-client/src/main/java/com/b2c/dtms/client/domain/dto/response/DtmsResponseDto.java
  1 +package com.b2c.dtms.client.domain.dto.response;
  2 +
  3 +import java.io.Serializable;
  4 +
  5 +public class DtmsResponseDto implements Serializable {
  6 +
  7 + /**
  8 + *
  9 + */
  10 + private static final long serialVersionUID = 5684376067147968413L;
  11 +
  12 + public static final String CODE_SUCCESS = "SUCCESS";
  13 + public static final String CODE_FAILED = "FAILED";
  14 +
  15 + private String code = CODE_FAILED;
  16 + private String message;
  17 +
  18 + public String getCode() {
  19 + return code;
  20 + }
  21 +
  22 + public void setCode(String code) {
  23 + this.code = code;
  24 + }
  25 +
  26 + public String getMessage() {
  27 + return message;
  28 + }
  29 +
  30 + public void setMessage(String message) {
  31 + this.message = message;
  32 + }
  33 +
  34 + @Override
  35 + public String toString() {
  36 + return "DtmsResponseDto [code=" + code + ", message=" + message + "]";
  37 + }
  38 +
  39 +}
... ...
dtms-client/src/main/java/com/b2c/dtms/common/enums/dtms/ConfirmCode.java 0 → 100644
  1 +++ a/dtms-client/src/main/java/com/b2c/dtms/common/enums/dtms/ConfirmCode.java
  1 +package com.b2c.dtms.common.enums.dtms;
  2 +
  3 +
  4 +public enum ConfirmCode{
  5 + SUCCESS("SUCCESS"),//确认成功,需要执行消息
  6 + FAILED("FAILED"),//确认不成功,不能执行消息
  7 + UNKNOWN("UNKNOWN");//确认结果不明确,比如确认结果为空等,不能执行消息
  8 + private String code;
  9 +
  10 + private ConfirmCode(String code){
  11 + this.code=code;
  12 + }
  13 + public static ConfirmCode getConfirmCode(String code) {
  14 + for (ConfirmCode c : ConfirmCode.values()) {
  15 + if (c.code().equals(code)) {
  16 + return c;
  17 + }
  18 + }
  19 + return null;
  20 + }
  21 +
  22 + public String code(){
  23 + return this.code;
  24 + }
  25 +}
0 26 \ No newline at end of file
... ...
dtms-client/src/main/java/com/b2c/dtms/common/enums/dtms/DtmsHandlerType.java 0 → 100644
  1 +++ a/dtms-client/src/main/java/com/b2c/dtms/common/enums/dtms/DtmsHandlerType.java
  1 +package com.b2c.dtms.common.enums.dtms;
  2 +
  3 +
  4 +public enum DtmsHandlerType {
  5 +
  6 + /** 工厂bean */
  7 + FACTORYBEAN(10,"spring-Bean"),
  8 + /** 反射类 */
  9 + CLASSNAME(20,"Java-Class"),
  10 + /**Groovy 脚本*/
  11 + GROOVY_SCRIPT(30,"Groovy-script"),
  12 + /**Groovy task接口实现*/
  13 + GROOVY_TASKHANDLE(40,"Groovy-Task"),
  14 + /**HTTP URL调用*/
  15 + HTTP_URL(50,"HTTP-URL");
  16 +
  17 + private int index;
  18 + private String name;
  19 +
  20 + public static DtmsHandlerType getEnum(int index) {
  21 + for (DtmsHandlerType c : DtmsHandlerType.values()) {
  22 + if (c.getIndex() == index) {
  23 + return c;
  24 + }
  25 + }
  26 + return null;
  27 + }
  28 +
  29 + private DtmsHandlerType(int index,String name) {
  30 + this.index = index;
  31 + this.name = name;
  32 + }
  33 +
  34 + public int getIndex() {
  35 + return index;
  36 + }
  37 +
  38 + public void setIndex(int index) {
  39 + this.index = index;
  40 + }
  41 +
  42 +
  43 + public String getName() {
  44 + return name;
  45 + }
  46 +
  47 +
  48 + public void setName(String name) {
  49 + this.name = name;
  50 + }
  51 +}
... ...
dtms-client/src/main/java/com/b2c/dtms/common/enums/dtms/DtmsMessageConfigStatus.java 0 → 100644
  1 +++ a/dtms-client/src/main/java/com/b2c/dtms/common/enums/dtms/DtmsMessageConfigStatus.java
  1 +package com.b2c.dtms.common.enums.dtms;
  2 +
  3 +
  4 +/**
  5 + * 消息配置状态
  6 + */
  7 +public enum DtmsMessageConfigStatus {
  8 +
  9 + /**不可用*/
  10 + Disabled(0),
  11 + /**可用*/
  12 + Available(1);
  13 +
  14 + private int code;
  15 +
  16 + private DtmsMessageConfigStatus(int code) {
  17 + this.code = code;
  18 + }
  19 +
  20 + public static DtmsMessageConfigStatus getStatus(int code) {
  21 + for (DtmsMessageConfigStatus c : DtmsMessageConfigStatus.values()) {
  22 + if (c.code()==code) {
  23 + return c;
  24 + }
  25 + }
  26 + return null;
  27 + }
  28 +
  29 + public int code(){
  30 + return this.code;
  31 + }
  32 +}
0 33 \ No newline at end of file
... ...
dtms-client/src/main/java/com/b2c/dtms/common/enums/dtms/DtmsMessageStatus.java 0 → 100644
  1 +++ a/dtms-client/src/main/java/com/b2c/dtms/common/enums/dtms/DtmsMessageStatus.java
  1 +package com.b2c.dtms.common.enums.dtms;
  2 +
  3 +
  4 +/**
  5 + * 消息状态
  6 + */
  7 +public enum DtmsMessageStatus {
  8 +
  9 + /**待处理*/
  10 + WaitProcess(10),
  11 + /**已二次确认 消息可以直接被执行*/
  12 + SecondConfirmed(20),
  13 + /**已处理*/
  14 + Porcessed(30),
  15 + /**异常*/
  16 + Exception(40);
  17 +
  18 + private int code;
  19 +
  20 + private DtmsMessageStatus(int code) {
  21 + this.code = code;
  22 + }
  23 +
  24 + public static DtmsMessageStatus getStatus(int code) {
  25 + for (DtmsMessageStatus c : DtmsMessageStatus.values()) {
  26 + if (c.code()==code) {
  27 + return c;
  28 + }
  29 + }
  30 + return null;
  31 + }
  32 +
  33 + public int code(){
  34 + return this.code;
  35 + }
  36 +}
0 37 \ No newline at end of file
... ...
dtms-client/src/main/java/com/b2c/dtms/common/enums/dtms/DtmsMessageTopic.java 0 → 100644
  1 +++ a/dtms-client/src/main/java/com/b2c/dtms/common/enums/dtms/DtmsMessageTopic.java
  1 +package com.b2c.dtms.common.enums.dtms;
  2 +
  3 +import org.apache.commons.lang.StringUtils;
  4 +
  5 +/**
  6 + * DTMS业务消息类型
  7 + */
  8 +public enum DtmsMessageTopic {
  9 + /** 订单或代购单取消(含备货中申请退款)通知物流 */
  10 + NoticeLogistics("NoticeLogistics"),
  11 + /** MQ */
  12 + SendMq("SendMq"),
  13 + /** 短信 */
  14 + Sms("Sms"),
  15 + /** 发送消息中心消息提醒 */
  16 + SendNotice("SendNotice"),
  17 + /** 增加供应商库存 */
  18 + IncraseSupStockNum("IncraseSupStockNum"),
  19 + /** 扣减供应商库存 */
  20 + DecraseSupStockNum("DecraseSupStockNum"),
  21 + /** 增加网站库存 */
  22 + IncraseStockNum("IncraseStockNum"),
  23 + /** 扣减网站库存 */
  24 + DecraseStockNum("DecraseStockNum"),
  25 + /** 扣减用户信用额度 */
  26 + DecraseUserCredit("DecraseUserCredit"),
  27 + /** 返还(增加)用户信用额度 */
  28 + IncraseUserCredit("IncraseUserCredit"),
  29 + /** 创建交易*/
  30 + TradeCreate("TradeCreate"),
  31 + /** 关闭交易*/
  32 + TradeClose("TradeClose"),
  33 + /** 交易退款*/
  34 + TradeRefund("TradeRefund"),
  35 + /** 交易-卖家发货dili.payment.trade.sendGoods */
  36 + TradeSendGoods("TradeSendGoods"),
  37 + /** 交易-修改交易金额*/
  38 + TradeUpdateAmount("TradeUpdateAmount"),
  39 +
  40 + /** 保存服务 */
  41 + SrvceSave("SrvceSave"),
  42 + /** 取消服务 */
  43 + SrvceCancel("SrvceCancel"),
  44 + /** 暂停服务 */
  45 + SrvcePause("SrvcePause"),
  46 + /** 恢复服务 */
  47 + SrvceRestore("SrvceRestore"),
  48 + /** 增加供应商已代销数量(调用商品库远程接口) */
  49 + IncrasePopGenerationSales("IncrasePopGenerationSales"),
  50 + /** 订单自动定时增加评论 */
  51 + OrderAutoComment("OrderAutoComment"),
  52 + /** 执行callurl中的远程调用 */
  53 + CallUrl("CallUrl");
  54 +
  55 + // 成员变量
  56 + private String code;
  57 +
  58 + // 构造方法
  59 + private DtmsMessageTopic(String code) {
  60 + this.code = code;
  61 + }
  62 +
  63 + public static DtmsMessageTopic getTopic(String code) {
  64 + for (DtmsMessageTopic c : DtmsMessageTopic.values()) {
  65 + if (StringUtils.equals(c.code, code)) {
  66 + return c;
  67 + }
  68 + }
  69 + return null;
  70 + }
  71 +
  72 + public String code(){
  73 + return this.code;
  74 + }
  75 +}
0 76 \ No newline at end of file
... ...
dtms-client/src/main/java/com/b2c/dtms/common/enums/dtms/DtmsMessageType.java 0 → 100644
  1 +++ a/dtms-client/src/main/java/com/b2c/dtms/common/enums/dtms/DtmsMessageType.java
  1 +package com.b2c.dtms.common.enums.dtms;
  2 +
  3 +
  4 +/**
  5 + * DTMS内部消息类型
  6 + */
  7 +public enum DtmsMessageType {
  8 +
  9 + /**普通消息*/
  10 + Common(1),
  11 + /**定时消息(一次执行),执行成功之后不再执行 */
  12 + Timer(2),
  13 + /**定时消息(周期执行)*/
  14 + PeriodicTimer(3);
  15 +
  16 + // 成员变量
  17 + private int code;
  18 +
  19 + // 构造方法
  20 + private DtmsMessageType(int code) {
  21 + this.code = code;
  22 + }
  23 +
  24 + public static DtmsMessageType getTopic(int code) {
  25 + for (DtmsMessageType c : DtmsMessageType.values()) {
  26 + if (c.code==code) {
  27 + return c;
  28 + }
  29 + }
  30 + return null;
  31 + }
  32 +
  33 + public int code(){
  34 + return this.code;
  35 + }
  36 +}
0 37 \ No newline at end of file
... ...
dtms-client/src/main/java/com/b2c/dtms/common/enums/dtms/HandleCode.java 0 → 100644
  1 +++ a/dtms-client/src/main/java/com/b2c/dtms/common/enums/dtms/HandleCode.java
  1 +package com.b2c.dtms.common.enums.dtms;
  2 +
  3 +
  4 +public enum HandleCode{
  5 + SUCCESS("SUCCESS"),//处理成功
  6 + FAILED("FAILED"),//处理失败
  7 + CONFIRM_FAILED("CONFIRM_FAILED");//二次确认失败
  8 + private String code;
  9 +
  10 + private HandleCode(String code){
  11 + this.code=code;
  12 + }
  13 + public static HandleCode getHandleCode(String code) {
  14 + for (HandleCode c : HandleCode.values()) {
  15 + if (c.code().equals(code)) {
  16 + return c;
  17 + }
  18 + }
  19 + return null;
  20 + }
  21 +
  22 + public String code(){
  23 + return this.code;
  24 + }
  25 +}
0 26 \ No newline at end of file
... ...
dtms-client/src/main/java/com/b2c/dtms/common/enums/dtms/LockStatus.java 0 → 100644
  1 +++ a/dtms-client/src/main/java/com/b2c/dtms/common/enums/dtms/LockStatus.java
  1 +package com.b2c.dtms.common.enums.dtms;
  2 +
  3 +public enum LockStatus {
  4 +
  5 +
  6 + /** 未锁定 */
  7 + UNLOCK(0),
  8 + /** 锁定中 */
  9 + LOCKING(1);
  10 +
  11 + private int index;
  12 +
  13 + public static LockStatus getEnum(int index) {
  14 + for (LockStatus c : LockStatus.values()) {
  15 + if (c.getIndex() == index) {
  16 + return c;
  17 + }
  18 + }
  19 + return null;
  20 + }
  21 +
  22 + private LockStatus(int index) {
  23 + this.index = index;
  24 + }
  25 +
  26 + public int getIndex() {
  27 + return index;
  28 + }
  29 +
  30 + public void setIndex(int index) {
  31 + this.index = index;
  32 + }
  33 +}
... ...
dtms-client/src/main/java/com/b2c/dtms/common/enums/dtms/TimeUnit.java 0 → 100644
  1 +++ a/dtms-client/src/main/java/com/b2c/dtms/common/enums/dtms/TimeUnit.java
  1 +package com.b2c.dtms.common.enums.dtms;
  2 +
  3 +
  4 +/**
  5 + * 时间单位
  6 + */
  7 +public enum TimeUnit {
  8 +
  9 + MilliSecond(10),
  10 + Second(20),
  11 + Minute(30),
  12 + Hour(40),
  13 + Day(50);
  14 +
  15 + private int index;
  16 +
  17 + private TimeUnit(int index) {
  18 + this.index = index;
  19 + }
  20 +
  21 + public static TimeUnit getTimeUnit(int index) {
  22 + for (TimeUnit c : TimeUnit.values()) {
  23 + if (c.index()==index) {
  24 + return c;
  25 + }
  26 + }
  27 + return null;
  28 + }
  29 +
  30 + public int index(){
  31 + return this.index;
  32 + }
  33 +}
0 34 \ No newline at end of file
... ...
dtms-client/src/main/java/com/b2c/dtms/common/http/ExpiredConnMonitorThread.java 0 → 100644
  1 +++ a/dtms-client/src/main/java/com/b2c/dtms/common/http/ExpiredConnMonitorThread.java
  1 +package com.b2c.dtms.common.http;
  2 +
  3 +import org.slf4j.Logger;
  4 +import org.slf4j.LoggerFactory;
  5 +
  6 +import java.util.concurrent.TimeUnit;
  7 +
  8 +
  9 +
  10 +/**
  11 + *
  12 + * 守护线程,释放过期连接<p>
  13 + * 经典阻塞I/O模型的一个主要缺点就是只有当阻塞I/O时,socket才能对I/O事件做出反应。
  14 + * 当连接被管理器收回后,这个连接仍然存活,但是却无法监控socket的状态,也无法对I/O事件做出反馈。
  15 + * 如果连接被服务器端关闭了,客户端监测不到连接的状态变化(也就无法根据连接状态的变化,关闭本地的socket)。
  16 + * HttpClient为了缓解这一问题造成的影响,会在使用某个连接前,监测这个连接是否已经过时,如果服务器端关闭了连接,
  17 + * 那么连接就会失效。这种过时检查并不是100%有效,并且会给每个请求增加10到30毫秒额外开销。唯一一个可行的,
  18 + * 且does not involve a one thread per socket model for idle connections的解决办法,是建立一个监控线程,来专门回收由于长时间不活动而被判定为失效的连接。
  19 + * 这个监控线程可以周期性的调用ClientConnectionManager类的closeExpiredConnections()方法来关闭过期的连接,
  20 + * 回收连接池中被关闭的连接,也可以选择性的调用ClientConnectionManager类的closeIdleConnections()方法来关闭一段时间内不活动的连接。
  21 + */
  22 +public class ExpiredConnMonitorThread extends Thread {
  23 +
  24 + private static final Logger LOGGER = LoggerFactory.getLogger(ExpiredConnMonitorThread.class);
  25 +
  26 + private final HttpClientConnectionPoolManager connMgr;
  27 +
  28 + private volatile boolean shutdown;
  29 +
  30 + public ExpiredConnMonitorThread(HttpClientConnectionPoolManager connMgr,boolean isDaemon) {
  31 + super();
  32 + this.setName("expired-connection-monitor");
  33 + this.connMgr = connMgr;
  34 + this.setDaemon(isDaemon);
  35 + }
  36 +
  37 + @Override
  38 + public void run() {
  39 + try {
  40 + while(!shutdown){
  41 + synchronized(this){
  42 + wait(20*1000);
  43 + if(connMgr!=null){
  44 + // Close expired connections
  45 + LOGGER.debug("关闭过期和超过空闲设定值的http请求连接...");
  46 + connMgr.closeExpiredConnections();
  47 + // Optionally, close connections
  48 + // that have been idle longer than 30 sec
  49 + connMgr.closeIdleConnections(30, TimeUnit.SECONDS);
  50 + LOGGER.debug("关闭过期和超过空闲设定值的http请求连接完成");
  51 + }
  52 + }
  53 + }
  54 + } catch (Exception ex) {
  55 + shutdown();
  56 + }
  57 + }
  58 +
  59 + public void shutdown() {
  60 + shutdown = true;
  61 + synchronized (this) {
  62 + notifyAll();
  63 + }
  64 + }
  65 +}
  66 +
... ...
dtms-client/src/main/java/com/b2c/dtms/common/http/HttpClientConnectionPoolManager.java 0 → 100644
  1 +++ a/dtms-client/src/main/java/com/b2c/dtms/common/http/HttpClientConnectionPoolManager.java
  1 +package com.b2c.dtms.common.http;
  2 +
  3 +import org.apache.http.config.SocketConfig;
  4 +import org.apache.http.conn.ssl.AllowAllHostnameVerifier;
  5 +import org.apache.http.impl.client.CloseableHttpClient;
  6 +import org.apache.http.impl.client.DefaultHttpRequestRetryHandler;
  7 +import org.apache.http.impl.client.HttpClientBuilder;
  8 +import org.apache.http.impl.client.HttpClients;
  9 +import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
  10 +
  11 +import javax.net.ssl.KeyManagerFactory;
  12 +import javax.net.ssl.SSLContext;
  13 +import javax.net.ssl.TrustManager;
  14 +import javax.net.ssl.TrustManagerFactory;
  15 +import java.io.FileInputStream;
  16 +import java.io.IOException;
  17 +import java.io.InputStream;
  18 +import java.security.*;
  19 +import java.security.cert.CertificateException;
  20 +import java.util.concurrent.TimeUnit;
  21 +
  22 +
  23 +public class HttpClientConnectionPoolManager {
  24 +
  25 + private static PoolingHttpClientConnectionManager clientConnectionManager = null;
  26 + private int maxTotal = 50;//设置整个连接池最大连接数 根据自己的场景决定
  27 + private int defaultMaxPerRoute = 25; //每个路由最大连接数,一个服务端相当于1个路由,有多少个服务端(域名或者IP)就有多少个路由
  28 +
  29 + private HttpClientBuilder httpClientBuilder;
  30 +
  31 +
  32 + private CloseableHttpClient httpClient;
  33 +
  34 + private HttpClientBuilder httpsClientBuilder;
  35 + private CloseableHttpClient httpsClient;
  36 +
  37 + private static HttpClientConnectionPoolManager poolManager = null;
  38 +
  39 + private SocketConfig getCustomSocketConfig(){
  40 + SocketConfig socketConfig=SocketConfig.custom()
  41 + .setTcpNoDelay(true)//Nagle算法试图通过减少分片的数量来节省带宽。当应用程序希望降低网络延迟并提高性能时,可以关闭Nagle算法,这样数据将会更早地发送,但会增加网络消耗
  42 + .build();
  43 + return socketConfig;
  44 + }
  45 +
  46 + private HttpClientConnectionPoolManager(int maxTotal, int defaultMaxPerRoute){
  47 + this.maxTotal = maxTotal;
  48 + this.defaultMaxPerRoute = defaultMaxPerRoute;
  49 + clientConnectionManager=new PoolingHttpClientConnectionManager();
  50 + clientConnectionManager.setMaxTotal(maxTotal);
  51 + clientConnectionManager.setDefaultMaxPerRoute(defaultMaxPerRoute);
  52 + clientConnectionManager.setDefaultSocketConfig(getCustomSocketConfig());
  53 + buildHttpClient();
  54 + }
  55 +
  56 +
  57 + private HttpClientConnectionPoolManager(){
  58 + clientConnectionManager=new PoolingHttpClientConnectionManager();
  59 + clientConnectionManager.setMaxTotal(maxTotal);
  60 + clientConnectionManager.setDefaultMaxPerRoute(defaultMaxPerRoute);
  61 + clientConnectionManager.setDefaultSocketConfig(getCustomSocketConfig());
  62 + buildHttpClient();
  63 + }
  64 +
  65 + private void buildHttpClient(){
  66 + //HTTP
  67 + httpClientBuilder=HttpClients.custom().setConnectionManager(clientConnectionManager);
  68 + httpClientBuilder.setRetryHandler(new DefaultHttpRequestRetryHandler(0, false));//重试次数,设置不重试
  69 + httpClientBuilder.setHostnameVerifier(new AllowAllHostnameVerifier()); //忽略域名一致性验证
  70 + httpClientBuilder.setKeepAliveStrategy(new HttpConnectionKeepAliveStrategy());
  71 + httpClient=httpClientBuilder.build();
  72 +
  73 + //HTTPS
  74 + httpsClientBuilder=HttpClients.custom().setConnectionManager(clientConnectionManager);
  75 + httpsClientBuilder.setRetryHandler(new DefaultHttpRequestRetryHandler(0, false));//重试次数,设置不重试
  76 + httpsClientBuilder.setHostnameVerifier(new AllowAllHostnameVerifier()); //忽略域名一致性验证
  77 + httpsClientBuilder.setKeepAliveStrategy(new HttpConnectionKeepAliveStrategy());
  78 + try {
  79 + SSLContext sslContext = SSLContext.getInstance("SSL");
  80 + sslContext.init(null, new TrustManager[] {new TrustAllCertManager()}, null);
  81 + httpsClientBuilder.setSslcontext(sslContext);
  82 + } catch (Exception e) {
  83 + throw new RuntimeException(e);
  84 + }
  85 + httpsClient=httpsClientBuilder.build();
  86 + }
  87 +
  88 +
  89 +
  90 + /**
  91 + * 获取http client池管理器
  92 + * @return
  93 + */
  94 + public synchronized static HttpClientConnectionPoolManager getInstance(){
  95 + if(poolManager == null){
  96 + poolManager = new HttpClientConnectionPoolManager();
  97 + }
  98 + return poolManager;
  99 + }
  100 +
  101 + /**
  102 + * 获取http client池管理器
  103 + * @param maxTotal 连接池最大连接数
  104 + * @param defaultMaxPerRoute 每个路由最大连接数
  105 + * @return
  106 + */
  107 + public synchronized static HttpClientConnectionPoolManager getInstance(int maxTotal, int defaultMaxPerRoute){
  108 + if(poolManager == null){
  109 + poolManager = new HttpClientConnectionPoolManager(maxTotal, defaultMaxPerRoute);
  110 + }
  111 + return poolManager;
  112 + }
  113 +
  114 + /**
  115 + * 获取http client
  116 + * @return
  117 + */
  118 + public CloseableHttpClient getHttpClient(){
  119 + if(poolManager == null){
  120 + getInstance();
  121 + }
  122 + return httpClient;
  123 + }
  124 +
  125 + /**
  126 + * 获取仅服务端单向认证的https client
  127 + * @return
  128 + * @throws NoSuchAlgorithmException
  129 + * @throws KeyManagementException
  130 + */
  131 + public CloseableHttpClient getCommonHttpsClient() throws NoSuchAlgorithmException, KeyManagementException{
  132 + if(poolManager == null){
  133 + getInstance();
  134 + }
  135 + return httpsClient;
  136 + }
  137 +
  138 + /**
  139 + * 获取双向认证的https client
  140 + * @param certStoreType
  141 + * @param certStorePath
  142 + * @param certStorePassword
  143 + * @return
  144 + * @throws NoSuchAlgorithmException
  145 + * @throws KeyManagementException
  146 + * @throws KeyStoreException
  147 + * @throws CertificateException
  148 + * @throws IOException
  149 + * @throws UnrecoverableKeyException
  150 + */
  151 + public CloseableHttpClient getStrictHttpsClient(String certStoreType, String certStorePath, String certStorePassword) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, CertificateException, IOException, UnrecoverableKeyException{
  152 + if(poolManager == null){
  153 + getInstance();
  154 + }
  155 +
  156 + // KeyStore keyStore = KeyStore.getInstance("jks");
  157 + // KeyStore keyStore = KeyStore.getInstance("pkcs12");
  158 + KeyStore keyStore = KeyStore.getInstance(certStoreType);
  159 + InputStream in = new FileInputStream(certStorePath);
  160 + keyStore.load(in, certStorePassword.toCharArray());
  161 +
  162 + KeyManagerFactory kmf = KeyManagerFactory.getInstance("sunx509");
  163 + kmf.init(keyStore, certStorePassword.toCharArray());
  164 +
  165 + TrustManagerFactory tmf = TrustManagerFactory.getInstance("sunx509");
  166 + tmf.init(keyStore);
  167 +
  168 + SSLContext sslContext = SSLContext.getInstance("SSL");
  169 + sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
  170 + httpsClientBuilder.setSslcontext(sslContext);
  171 + return httpsClientBuilder.build();
  172 + }
  173 +
  174 + public void closeExpiredConnections(){
  175 + if(clientConnectionManager!=null){
  176 + clientConnectionManager.closeExpiredConnections();
  177 + }
  178 + }
  179 +
  180 + public void close(){
  181 + if(clientConnectionManager!=null){
  182 + clientConnectionManager.close();
  183 + }
  184 + }
  185 +
  186 + public void closeIdleConnections(int idleTimeout, TimeUnit timeUnit) {
  187 + if(clientConnectionManager!=null){
  188 + clientConnectionManager.closeIdleConnections(idleTimeout, timeUnit);
  189 + }
  190 + }
  191 +}
... ...
dtms-client/src/main/java/com/b2c/dtms/common/http/HttpConnectionKeepAliveStrategy.java 0 → 100644
  1 +++ a/dtms-client/src/main/java/com/b2c/dtms/common/http/HttpConnectionKeepAliveStrategy.java
  1 +package com.b2c.dtms.common.http;
  2 +
  3 +import org.apache.http.HeaderElement;
  4 +import org.apache.http.HeaderElementIterator;
  5 +import org.apache.http.HttpResponse;
  6 +import org.apache.http.conn.ConnectionKeepAliveStrategy;
  7 +import org.apache.http.message.BasicHeaderElementIterator;
  8 +import org.apache.http.protocol.HTTP;
  9 +import org.apache.http.protocol.HttpContext;
  10 +
  11 +
  12 +public class HttpConnectionKeepAliveStrategy implements ConnectionKeepAliveStrategy{
  13 +
  14 + @Override
  15 + public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
  16 + HeaderElementIterator it = new BasicHeaderElementIterator(response.headerIterator(HTTP.CONN_KEEP_ALIVE));
  17 + while (it.hasNext()) {
  18 + HeaderElement he = it.nextElement();
  19 + String param = he.getName();
  20 + String value = he.getValue();
  21 + if (value != null && param.equalsIgnoreCase("timeout")) {
  22 + try {
  23 + return Long.parseLong(value) * 1000;
  24 + } catch(NumberFormatException ignore) {
  25 + }
  26 + }
  27 + }
  28 + return 60 * 1000; //保持连接60s在连接池中可用,可用于处理多次请求
  29 + }
  30 +
  31 +}
... ...
dtms-client/src/main/java/com/b2c/dtms/common/http/HttpHeaders.java 0 → 100644
  1 +++ a/dtms-client/src/main/java/com/b2c/dtms/common/http/HttpHeaders.java
  1 +package com.b2c.dtms.common.http;
  2 +
  3 +
  4 +
  5 +
  6 +public class HttpHeaders {
  7 + public static final String ACCEPT = "Accept";
  8 + public static final String ACCEPT_CHARSET = "Accept-Charset";
  9 + public static final String ALLOW = "Allow";
  10 + public static final String CACHE_CONTROL = "Cache-Control";
  11 + public static final String CONTENT_DISPOSITION = "Content-Disposition";
  12 + public static final String CONTENT_LENGTH = "Content-Length";
  13 + public static final String CONTENT_TYPE = "Content-Type";
  14 + public static final String DATE = "Date";
  15 + public static final String ETAG = "ETag";
  16 + public static final String EXPIRES = "Expires";
  17 + public static final String IF_MODIFIED_SINCE = "If-Modified-Since";
  18 + public static final String IF_NONE_MATCH = "If-None-Match";
  19 + public static final String LAST_MODIFIED = "Last-Modified";
  20 + public static final String LOCATION = "Location";
  21 + public static final String PRAGMA = "Pragma";
  22 + public static final String TRANSFER_ENCODING = "Transfer-Encoding";
  23 + public static final String CONNECTION = "Connection";
  24 + public static final String SERVER = "Server";
  25 + public static final String REFERER = "Referer";
  26 + public static final String USER_AGENT = "User-Agent";
  27 + public static final String HOST = "Host";
  28 + public static final String RANGE = "Range";
  29 + public static final String CONTENT_RANGE = "Content_Range";
  30 + public static final String CONTENT_ENCODING = "Content-Encoding";
  31 + public static final String VARY = "Vary";
  32 + public static final String X_POWERED_BY = "X-Powered-By";
  33 + public static final String X_CACHE = "X_Cache";
  34 + public static final String AGE = "Age";
  35 + public static final String MAX_AGE = "Max-Age";
  36 + public static final String SET_COOKIE="Set-Cookie";
  37 + public static final String COOKIE="Cookie";
  38 + public static final String SESSION_ID="session_id";
  39 +}
... ...
dtms-client/src/main/java/com/b2c/dtms/common/http/HttpMethod.java 0 → 100644
  1 +++ a/dtms-client/src/main/java/com/b2c/dtms/common/http/HttpMethod.java
  1 +package com.b2c.dtms.common.http;
  2 +
  3 +import org.apache.http.client.config.RequestConfig;
  4 +import org.apache.http.client.methods.HttpGet;
  5 +import org.apache.http.client.methods.HttpPost;
  6 +import org.apache.http.entity.StringEntity;
  7 +
  8 +import java.io.UnsupportedEncodingException;
  9 +import java.net.URISyntaxException;
  10 +import java.nio.charset.Charset;
  11 +import java.util.Map;
  12 +import java.util.Map.Entry;
  13 +import java.util.Set;
  14 +
  15 +public class HttpMethod {
  16 +
  17 + public static String DEFAULT_CHARSET="UTF-8";
  18 +
  19 + public static String DEFAULT_CONTENT_TYPE="application/json;charset=UTF-8";
  20 +
  21 + public static String POST="POST";
  22 +
  23 + public static String GET="GET";
  24 +
  25 + private static RequestConfig requestConfig;
  26 +
  27 + static{
  28 + requestConfig = RequestConfig.custom()
  29 + .setSocketTimeout(60*1000) //获取数据的超时时间
  30 + .setConnectTimeout(60*1000)//建立连接超时时间
  31 + .setConnectionRequestTimeout(60*1000) //从连接管理器中获取连接超时时间
  32 + .build();
  33 + }
  34 +
  35 + /**
  36 + * 组装HTTP GET请求对象
  37 + * @param requestUrl 请求URL
  38 + * @param headersMap 请求头键值对Map
  39 + * @return {@link org.apache.http.client.methods.HttpGet}
  40 + * @throws URISyntaxException
  41 + */
  42 + public static HttpGet buildGet(String requestUrl,Map<String,String> headersMap)
  43 + throws URISyntaxException {
  44 + HttpGet get = new HttpGet(requestUrl);
  45 + get.setHeader(HttpHeaders.CONTENT_TYPE,DEFAULT_CONTENT_TYPE);
  46 + //get.setHeader("Connection", "close"); 重用连接,客户端不主动关闭,由调用HttpGet释放连接
  47 + get.setConfig(requestConfig);
  48 + if(headersMap==null){
  49 + return get;
  50 + }
  51 + Set<Entry<String,String>> headerEntrySet=headersMap.entrySet();
  52 + for(Entry<String,String> headerEntry:headerEntrySet){
  53 + get.setHeader(headerEntry.getKey(), headerEntry.getValue());
  54 + }
  55 + return get;
  56 + }
  57 +
  58 + /**
  59 + * 组装HTTP POST 请求对象
  60 + * @param requestUrl 请求URL
  61 + * @param headersMap 请求头键值对Map
  62 + * @param content 提交的内容
  63 + * @return {@link org.apache.http.client.methods.HttpPost}
  64 + * @throws URISyntaxException
  65 + * @throws UnsupportedEncodingException
  66 + */
  67 + public static HttpPost buildPost(String requestUrl,
  68 + Map<String,String> headersMap,
  69 + String content)
  70 + throws URISyntaxException, UnsupportedEncodingException {
  71 + HttpPost post = new HttpPost(requestUrl);
  72 + post.setHeader(HttpHeaders.CONTENT_TYPE, DEFAULT_CONTENT_TYPE);
  73 + //post.setHeader("Connection", "close");重用连接,客户端不主动关闭,由调用HttpGet释放连接
  74 + post.setConfig(requestConfig);
  75 + StringEntity httpEntity = new StringEntity(content,Charset.forName(DEFAULT_CHARSET));
  76 + post.setEntity(httpEntity);
  77 + if(headersMap==null){
  78 + return post;
  79 + }
  80 +
  81 + Set<Entry<String,String>> headerEntrySet=headersMap.entrySet();
  82 + for(Entry<String,String> headerEntry:headerEntrySet){
  83 + post.setHeader(headerEntry.getKey(), headerEntry.getValue());
  84 + }
  85 + return post;
  86 + }
  87 +}
... ...
dtms-client/src/main/java/com/b2c/dtms/common/http/HttpRequester.java 0 → 100644
  1 +++ a/dtms-client/src/main/java/com/b2c/dtms/common/http/HttpRequester.java
  1 +package com.b2c.dtms.common.http;
  2 +
  3 +import org.apache.commons.lang.StringUtils;
  4 +import org.apache.http.client.ResponseHandler;
  5 +import org.apache.http.client.methods.HttpGet;
  6 +import org.apache.http.client.methods.HttpPost;
  7 +import org.apache.http.impl.client.CloseableHttpClient;
  8 +import org.slf4j.Logger;
  9 +import org.slf4j.LoggerFactory;
  10 +
  11 +import java.util.Map;
  12 +
  13 +public class HttpRequester {
  14 +
  15 + private static final Logger LOGGER = LoggerFactory.getLogger(HttpRequester.class);
  16 + private static HttpClientConnectionPoolManager httpClientManager;
  17 + private static ResponseHandler<HttpResponse> responseHandler;
  18 +
  19 + static{
  20 + httpClientManager = HttpClientConnectionPoolManager.getInstance(120,30);
  21 +
  22 + //http response处理器
  23 + responseHandler=new HttpResponseHandler();
  24 +
  25 + //守护线程,释放过期连接
  26 + ExpiredConnMonitorThread monitor=new ExpiredConnMonitorThread(httpClientManager,true);
  27 + monitor.start();
  28 + }
  29 +
  30 +
  31 + /**
  32 + * 发送HTTP或者仅服务端认证HTTPS GET请求
  33 + * @param requestUrl GET请求URL
  34 + * @param headersMap 请求头键值对map
  35 + * @return {@link HttpResponse}
  36 + * @throws Exception
  37 + */
  38 + public static HttpResponse sendGet(String requestUrl, Map<String, String> headersMap) throws Exception {
  39 + HttpResponse httpResponse=null;
  40 + HttpGet get=null;
  41 + try{
  42 + CloseableHttpClient httpClient = null;
  43 + if (StringUtils.containsIgnoreCase(requestUrl, "https")) {
  44 + httpClient =httpClientManager.getCommonHttpsClient();
  45 + } else {
  46 + httpClient =httpClientManager.getHttpClient();
  47 + }
  48 + get=HttpMethod.buildGet(requestUrl, headersMap);
  49 + Long startTime=System.currentTimeMillis();
  50 + httpResponse=httpClient.execute(get,responseHandler);
  51 + LOGGER.info("http请求用时["+(System.currentTimeMillis()-startTime)+"ms]");
  52 + }catch(Exception e){
  53 + throw e;
  54 + }finally{
  55 + releaseGetConnection(get);
  56 + }
  57 + return httpResponse;
  58 + }
  59 +
  60 + /**
  61 + * 发送双向认证 HTTPS GET请求
  62 + * @param certStoreType 证书库类型
  63 + * @param certStorePath 证书库位置
  64 + * @param certStorePassword 证书库密码
  65 + * @param requestUrl 请求URL
  66 + * @param headersMap 请求头键值对map
  67 + * @return {@link HttpResponse}
  68 + * @throws Exception
  69 + */
  70 + public static HttpResponse sendGet(String certStoreType, String certStorePath, String certStorePassword, String requestUrl, Map<String, String> headersMap) throws Exception {
  71 + HttpResponse httpResponse=null;
  72 + HttpGet get=null;
  73 + try{
  74 + CloseableHttpClient httpClient = null;
  75 + if (StringUtils.containsIgnoreCase(requestUrl, "https")) {
  76 + httpClient = httpClientManager.getStrictHttpsClient(certStoreType, certStorePath, certStorePassword);
  77 + } else {
  78 + httpClient = httpClientManager.getHttpClient();
  79 + }
  80 + get=HttpMethod.buildGet(requestUrl, headersMap);
  81 + Long startTime=System.currentTimeMillis();
  82 + httpResponse=httpClient.execute(get,responseHandler);
  83 + LOGGER.info("http请求用时["+(System.currentTimeMillis()-startTime)+"ms]");
  84 + }catch(Exception e){
  85 + throw e;
  86 + }finally{
  87 + releaseGetConnection(get);
  88 + }
  89 + return httpResponse;
  90 + }
  91 +
  92 + /**
  93 + * 发送HTTP或者仅服务端认证HTTPS POST请求
  94 + * @param requestUrl POST请求URL
  95 + * @param headersMap 请求头键值对map
  96 + * @param content POST到服务端的内容
  97 + * @return {@link HttpResponse}
  98 + * @throws Exception
  99 + */
  100 + public static HttpResponse sendPost(String requestUrl, Map<String, String> headersMap, String content) throws Exception {
  101 + HttpResponse httpResponse=null;
  102 + HttpPost post=null;
  103 + try{
  104 + CloseableHttpClient httpClient = null;
  105 + if (StringUtils.containsIgnoreCase(requestUrl, "https")) {
  106 + httpClient = httpClientManager.getCommonHttpsClient();
  107 + } else {
  108 + httpClient = httpClientManager.getHttpClient();
  109 + }
  110 + post=HttpMethod.buildPost(requestUrl, headersMap, content);
  111 + Long startTime=System.currentTimeMillis();
  112 + httpResponse=httpClient.execute(post,responseHandler);
  113 + LOGGER.info("http请求用时["+(System.currentTimeMillis()-startTime)+"ms]");
  114 + }catch(Exception e){
  115 + throw e;
  116 + }finally{
  117 + releasePostConnection(post);
  118 + }
  119 + return httpResponse;
  120 + }
  121 +
  122 + /**
  123 + * 发送双向认证 HTTPS GET请求
  124 + * @param certStoreType 证书库类型
  125 + * @param certStorePath 证书库位置
  126 + * @param certStorePassword 证书库密码
  127 + * @param requestUrl 请求URL
  128 + * @param headersMap 请求头键值对map
  129 + * @param content POST到服务端的内容
  130 + * @return {@link HttpResponse}
  131 + * @throws Exception
  132 + */
  133 + public static HttpResponse sendPost(String certStoreType, String certStorePath, String certStorePassword, String requestUrl, Map<String, String> headersMap, String content) throws Exception {
  134 + HttpResponse httpResponse=null;
  135 + HttpPost post=null;
  136 + try{
  137 + CloseableHttpClient httpClient = null;
  138 + if (StringUtils.containsIgnoreCase(requestUrl, "https")) {
  139 + httpClient = httpClientManager.getStrictHttpsClient(certStoreType, certStorePath, certStorePassword);
  140 + } else {
  141 + httpClient = httpClientManager.getHttpClient();
  142 + }
  143 + post=HttpMethod.buildPost(requestUrl, headersMap, content);
  144 + Long startTime=System.currentTimeMillis();
  145 + httpResponse=httpClient.execute(post,responseHandler);
  146 + LOGGER.info("http请求用时["+(System.currentTimeMillis()-startTime)+"ms]");
  147 + }catch(Exception e){
  148 + throw e;
  149 + }finally{
  150 + releasePostConnection(post);
  151 + }
  152 + return httpResponse;
  153 + }
  154 +
  155 + private static void releasePostConnection(HttpPost post){
  156 + if(post!=null){
  157 + post.releaseConnection();
  158 + }
  159 + }
  160 +
  161 + private static void releaseGetConnection(HttpGet get){
  162 + if(get!=null){
  163 + get.releaseConnection();
  164 + }
  165 + }
  166 +
  167 +}
... ...
dtms-client/src/main/java/com/b2c/dtms/common/http/HttpResponse.java 0 → 100644
  1 +++ a/dtms-client/src/main/java/com/b2c/dtms/common/http/HttpResponse.java
  1 +/*
  2 + * Copyright (c) 2014 www.diligrp.com All rights reserved.
  3 + * 本软件源代码版权归----所有,未经许可不得任意复制与传播.
  4 + */
  5 +package com.b2c.dtms.common.http;
  6 +
  7 +import java.util.Map;
  8 +
  9 +/**
  10 + * HTTP回应对象
  11 + * @author dev-center
  12 + * @since 2014-11-05
  13 + */
  14 +public class HttpResponse {
  15 +
  16 + int statusCode;
  17 +
  18 + Map<String,String> headersMap;
  19 +
  20 + Map<String,String> cookiesMap;
  21 +
  22 + String body;
  23 +
  24 +
  25 + public int getStatusCode() {
  26 + return statusCode;
  27 + }
  28 +
  29 +
  30 + public void setStatusCode(int statusCode) {
  31 + this.statusCode = statusCode;
  32 + }
  33 +
  34 +
  35 + public Map<String, String> getHeadersMap() {
  36 + return headersMap;
  37 + }
  38 +
  39 +
  40 + public void setHeadersMap(Map<String, String> headersMap) {
  41 + this.headersMap = headersMap;
  42 + }
  43 +
  44 +
  45 + public String getBody() {
  46 + return body;
  47 + }
  48 +
  49 +
  50 + public void setBody(String body) {
  51 + this.body = body;
  52 + }
  53 +
  54 +
  55 +
  56 + public Map<String, String> getCookiesMap() {
  57 + return cookiesMap;
  58 + }
  59 +
  60 +
  61 +
  62 + public void setCookiesMap(Map<String, String> cookiesMap) {
  63 + this.cookiesMap = cookiesMap;
  64 + }
  65 +}
0 66 \ No newline at end of file
... ...
dtms-client/src/main/java/com/b2c/dtms/common/http/HttpResponseHandler.java 0 → 100644
  1 +++ a/dtms-client/src/main/java/com/b2c/dtms/common/http/HttpResponseHandler.java
  1 +package com.b2c.dtms.common.http;
  2 +
  3 +import org.apache.commons.lang.StringUtils;
  4 +import org.apache.http.Header;
  5 +import org.apache.http.client.ClientProtocolException;
  6 +import org.apache.http.client.ResponseHandler;
  7 +import org.apache.http.util.EntityUtils;
  8 +
  9 +import java.io.IOException;
  10 +import java.util.HashMap;
  11 +import java.util.Map;
  12 +
  13 +/**
  14 + * http response处理器<p>
  15 + * 接口中有handleResponse(HttpResponse response)方法。使用这个方法,用户完全不用关心http连接管理器。
  16 + * 当使用ResponseHandler时,HttpClient会自动地将Http连接释放给Http管理器,即使http请求失败了或者抛出了异常。
  17 + */
  18 +public class HttpResponseHandler implements ResponseHandler<HttpResponse> {
  19 +
  20 + @Override
  21 + public HttpResponse handleResponse(org.apache.http.HttpResponse response)
  22 + throws ClientProtocolException, IOException {
  23 + HttpResponse hr = new HttpResponse();
  24 + try {
  25 + hr.setStatusCode(response.getStatusLine().getStatusCode());
  26 + hr.setBody(EntityUtils.toString(response.getEntity()));
  27 + hr.setHeadersMap(resolveResponseHeader(response.getAllHeaders()));
  28 + hr.setCookiesMap(resolveResponseCookie(response.getAllHeaders()));
  29 + } catch (IllegalStateException e) {
  30 + throw e;
  31 + } catch (Exception e) {
  32 + throw new RuntimeException(e);
  33 + }
  34 + return hr;
  35 + }
  36 +
  37 + /**
  38 + * 解析返回消息头
  39 + * @param headers {@link org.apache.http.Header} 键值对Hader对象
  40 + * @return 键值对消息头Map
  41 + */
  42 + private static Map<String, String> resolveResponseHeader(Header[] headers) {
  43 + if (headers == null || headers.length == 0) {
  44 + return null;
  45 + }
  46 + Map<String, String> headersMap = new HashMap<String, String>();
  47 + for (Header header : headers) {
  48 + // Cookie头放在Cookie中resolveResponseCookie解析
  49 + if (StringUtils.equalsIgnoreCase(HttpHeaders.SET_COOKIE, header.getName())) {
  50 + continue;
  51 + }
  52 + headersMap.put(StringUtils.trim(header.getName()), StringUtils.trim(header.getValue()));
  53 + }
  54 + return headersMap;
  55 + }
  56 +
  57 + /**
  58 + * 解析返回消息头中的cookie
  59 + * @param headers {@link org.apache.http.Header} 键值对Hader对象
  60 + * @return 键值对消息头Map
  61 + */
  62 + private static Map<String, String> resolveResponseCookie(Header[] headers) {
  63 + if (headers == null || headers.length == 0) {
  64 + return null;
  65 + }
  66 + Map<String, String> cookiesMap = new HashMap<String, String>();
  67 + for (Header header : headers) {
  68 + // Cookie
  69 + if (StringUtils.equalsIgnoreCase(HttpHeaders.SET_COOKIE, header.getName()) && StringUtils.isNotBlank(header.getValue())) {
  70 + String[] cookieItemArray = header.getValue().split(";");
  71 + if(cookieItemArray==null || cookieItemArray.length==0){
  72 + continue;
  73 + }
  74 + for (String cookieItem : cookieItemArray) {
  75 + if (StringUtils.isBlank(cookieItem)) {
  76 + continue;
  77 + }
  78 + String[] cookieItemValueArray = cookieItem.split("=");
  79 + if(cookieItemValueArray==null || cookieItemValueArray.length==0 ||cookieItemValueArray.length==1){
  80 + continue;
  81 + }
  82 + cookiesMap.put(StringUtils.trim(cookieItemValueArray[0]), StringUtils.trim(cookieItemValueArray[1]));
  83 + }
  84 + break;
  85 + }
  86 + }
  87 + return cookiesMap;
  88 + }
  89 +
  90 +}
... ...
dtms-client/src/main/java/com/b2c/dtms/common/http/TrustAllCertManager.java 0 → 100644
  1 +++ a/dtms-client/src/main/java/com/b2c/dtms/common/http/TrustAllCertManager.java
  1 +package com.b2c.dtms.common.http;
  2 +
  3 +import javax.net.ssl.X509TrustManager;
  4 +import java.security.cert.CertificateException;
  5 +import java.security.cert.X509Certificate;
  6 +
  7 +
  8 +public class TrustAllCertManager implements X509TrustManager {
  9 +
  10 + @Override
  11 + public void checkClientTrusted(X509Certificate[] chain, String authType)
  12 + throws CertificateException {
  13 + // 忽略,信任所有
  14 + }
  15 +
  16 + @Override
  17 + public void checkServerTrusted(X509Certificate[] chain, String authType)
  18 + throws CertificateException {
  19 + // 忽略,信任所有
  20 + }
  21 +
  22 + @Override
  23 + public X509Certificate[] getAcceptedIssuers() {
  24 + // 忽略,信任所有
  25 + return null;
  26 + }
  27 +
  28 +}
... ...
dtms-client/src/main/java/com/b2c/dtms/domain/DtmsCallBackReturn.java 0 → 100644
  1 +++ a/dtms-client/src/main/java/com/b2c/dtms/domain/DtmsCallBackReturn.java
  1 +package com.b2c.dtms.domain;
  2 +
  3 +
  4 +public class DtmsCallBackReturn {
  5 +
  6 + private String code;
  7 +
  8 + private String message;
  9 +
  10 +
  11 + public String getCode() {
  12 + return code;
  13 + }
  14 +
  15 + public void setCode(String code) {
  16 + this.code = code;
  17 + }
  18 +
  19 +
  20 + public String getMessage() {
  21 + return message;
  22 + }
  23 +
  24 +
  25 + public void setMessage(String message) {
  26 + this.message = message;
  27 + }
  28 +
  29 + @Override
  30 + public String toString() {
  31 + return "[code=" + code + ", message=" + message
  32 + + "]";
  33 + }
  34 +}
... ...
dtms-client/src/test/java/com/b2c/dtms/client/DtmsClientTestCase.java 0 → 100644
  1 +++ a/dtms-client/src/test/java/com/b2c/dtms/client/DtmsClientTestCase.java
  1 +package com.b2c.dtms.client;
  2 +
  3 +import org.junit.Test;
  4 +
  5 +import com.b2c.dtms.client.domain.dto.request.DtmsProduceRequestDto;
  6 +import com.b2c.dtms.client.domain.dto.response.DtmsResponseDto;
  7 +import com.b2c.dtms.common.enums.dtms.DtmsMessageType;
  8 +
  9 +public class DtmsClientTestCase {
  10 +
  11 + @Test
  12 + public void test() {
  13 + DtmsClient client = new DtmsClient();
  14 + DtmsProduceRequestDto message = new DtmsProduceRequestDto();
  15 + message.setBizId("123456");
  16 + message.setCallUrl("http://orders.zandeapp.com");
  17 + message.setContent("abcdefg");
  18 + message.setDelaySeconds(10);
  19 + message.setType(DtmsMessageType.Timer.code());
  20 + DtmsResponseDto response = client.produceMessage(message);
  21 + System.out.println(response);
  22 + }
  23 +
  24 +}
... ...
dtms-dao/pom.xml 0 → 100644
  1 +++ a/dtms-dao/pom.xml
  1 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  3 + <modelVersion>4.0.0</modelVersion>
  4 + <parent>
  5 + <groupId>com.b2c.dtms</groupId>
  6 + <artifactId>dtms-parent</artifactId>
  7 + <version>0.0.1-SNAPSHOT</version>
  8 + </parent>
  9 + <artifactId>dtms-dao</artifactId>
  10 +
  11 + <dependencies>
  12 + <dependency>
  13 + <groupId>${project.groupId}</groupId>
  14 + <artifactId>dtms-domain</artifactId>
  15 + <version>${project.version}</version>
  16 + </dependency>
  17 + <dependency>
  18 + <groupId>org.mybatis</groupId>
  19 + <artifactId>mybatis</artifactId>
  20 + </dependency>
  21 + <dependency>
  22 + <groupId>org.mybatis</groupId>
  23 + <artifactId>mybatis-spring</artifactId>
  24 + </dependency>
  25 + <dependency>
  26 + <groupId>com.alibaba</groupId>
  27 + <artifactId>druid</artifactId>
  28 + </dependency>
  29 + <!-- https://mvnrepository.com/artifact/org.mariadb.jdbc/mariadb-java-client -->
  30 + <!-- <dependency> <groupId>org.mariadb.jdbc</groupId> <artifactId>mariadb-java-client</artifactId>
  31 + </dependency> -->
  32 + <dependency>
  33 + <groupId>mysql</groupId>
  34 + <artifactId>mysql-connector-java</artifactId>
  35 + </dependency>
  36 + <dependency>
  37 + <groupId>org.springframework</groupId>
  38 + <artifactId>spring-jdbc</artifactId>
  39 + </dependency>
  40 + <dependency>
  41 + <groupId>org.aspectj</groupId>
  42 + <artifactId>aspectjweaver</artifactId>
  43 + </dependency>
  44 + </dependencies>
  45 +</project>
0 46 \ No newline at end of file
... ...
dtms-dao/src/main/java/com/b2c/dtms/dao/DtmsMaxidDao.java 0 → 100644
  1 +++ a/dtms-dao/src/main/java/com/b2c/dtms/dao/DtmsMaxidDao.java
  1 +/*
  2 + * Copyright (c) 2014 www.diligrp.com All rights reserved.
  3 + * 本软件源代码版权归----所有,未经许可不得任意复制与传播.
  4 + */
  5 +package com.b2c.dtms.dao;
  6 +
  7 +import java.util.concurrent.atomic.AtomicLong;
  8 +
  9 +import com.b2c.dtms.dao.base.BaseDao;
  10 +import com.b2c.dtms.domain.OrderMaxid;
  11 +
  12 +/**
  13 + * OrderMaxidDao 接口
  14 + * @author dev-center
  15 + * @since 2014-05-19
  16 + */
  17 +public interface DtmsMaxidDao extends BaseDao<OrderMaxid,Long>{
  18 + //自定义扩展
  19 + public OrderMaxid getOrderMaxIdByIdType(String idType);
  20 +
  21 + /**
  22 + * 在一个独立新事务中更新
  23 + * @param t
  24 + * @return
  25 + */
  26 + public SequenceNo getSeqNoByNewTransactional(SequenceNo idSequence,String seqIdKey,Long startSeq);
  27 +
  28 + /**
  29 + * Sequence本地缓存对象 <br />
  30 + * <B>Copyright</B> Copyright (c) 2014 www.diligrp.com All rights reserved. <br />
  31 + * 本软件源代码版权归地利集团,未经许可不得任意复制与传播.<br />
  32 + * <B>Company</B> 地利集团
  33 + */
  34 + public class SequenceNo{
  35 + private Long step =50L;//步长
  36 + private AtomicLong startSeq =new AtomicLong(1);//开始ID
  37 + private Long finishSeq =0L;//结束ID
  38 + public Long next(){
  39 + return startSeq.getAndIncrement();
  40 + }
  41 + public Long getStep() {
  42 + return step;
  43 + }
  44 + public Long getStartSeq() {
  45 + return startSeq.get();
  46 + }
  47 +
  48 + public void setStartSeq(Long startSeq) {
  49 + this.startSeq = new AtomicLong(startSeq);
  50 + }
  51 +
  52 + public Long getFinishSeq() {
  53 + return finishSeq;
  54 + }
  55 +
  56 + public void setFinishSeq(Long finishSeq) {
  57 + this.finishSeq = finishSeq;
  58 + }
  59 + }
  60 +}
0 61 \ No newline at end of file
... ...
dtms-dao/src/main/java/com/b2c/dtms/dao/base/BaseDao.java 0 → 100644
  1 +++ a/dtms-dao/src/main/java/com/b2c/dtms/dao/base/BaseDao.java
  1 +/*
  2 + * Copyright (c) 2014 www.diligrp.com All rights reserved.
  3 + * 本软件源代码版权归----所有,未经许可不得任意复制与传播.
  4 + */
  5 +package com.b2c.dtms.dao.base;
  6 +
  7 +import java.io.Serializable;
  8 +import java.util.List;
  9 +
  10 +/**
  11 + * dao基类<实体,主键>
  12 + * @author dev-center
  13 + * @since 2014-05-15
  14 + * @param <T> 实体
  15 + * @param <KEY> 主键
  16 + */
  17 +public interface BaseDao<T,KEY extends Serializable> {
  18 +
  19 + /**
  20 + * 添加对象
  21 + * @param t
  22 + * @return 影响条数
  23 + */
  24 + @SuppressWarnings("unchecked")
  25 + int insertEntry(T...t);
  26 +
  27 +// /**
  28 +// * 添加对象并设置ID到对象上(需开启事务)
  29 +// * @param t
  30 +// * @return 影响条数
  31 +// */
  32 +// int insertEntryCreateId(T t);
  33 +
  34 + /**
  35 + * 删除对象,主键
  36 + * @param key
  37 + * @return 影响条数
  38 + */
  39 + @SuppressWarnings("unchecked")
  40 + int deleteByKey(KEY...key);
  41 +
  42 + /**
  43 + * 删除对象,条件
  44 + * @param condtion
  45 + * @return 影响条数
  46 + */
  47 + int deleteByKey(T condtion);
  48 +
  49 + /**
  50 + * 更新对象,条件主键ID
  51 + * @param t
  52 + * @return 影响条数
  53 + */
  54 + int updateByKey(T t);
  55 +
  56 + /**
  57 + * 查询对象,条件主键
  58 + * @param key
  59 + * @return
  60 + */
  61 + T selectEntry(KEY key);
  62 +
  63 + /**
  64 + * 查询对象,条件主键数组
  65 + * @param key
  66 + * @return
  67 + */
  68 + @SuppressWarnings("unchecked")
  69 + List<T> selectEntryList(KEY...key);
  70 +
  71 + /**
  72 + * 查询对象,只要不为NULL与空则为条件
  73 + * @param t
  74 + * @return
  75 + */
  76 + List<T> selectEntryList(T t);
  77 +
  78 + /**
  79 + * 查询对象总数
  80 + * @param t
  81 + * @return
  82 + */
  83 + Integer selectEntryListCount(T t);
  84 +
  85 + /**
  86 + * 批量更新
  87 + * @param t
  88 + * @return
  89 + */
  90 + int updateBatch(List<T> t);
  91 +
  92 + /**
  93 + * 批量更新
  94 + * @param t
  95 + * @return
  96 + */
  97 + @SuppressWarnings("unchecked")
  98 + int updateBatch(T ... t);
  99 +
  100 +
  101 + /**
  102 + * 批量插入
  103 + * @param t
  104 + * @return
  105 + */
  106 + int insertBatch(List<T> t);
  107 +
  108 + /**
  109 + * 批量插入
  110 + * @param t
  111 + * @return
  112 + */
  113 + @SuppressWarnings("unchecked")
  114 + int insertBatch(T ... t);
  115 +}
... ...
dtms-dao/src/main/java/com/b2c/dtms/dao/base/BaseDaoImpl.java 0 → 100644
  1 +++ a/dtms-dao/src/main/java/com/b2c/dtms/dao/base/BaseDaoImpl.java
  1 +/*
  2 + * Copyright (c) 2014 www.diligrp.com All rights reserved.
  3 + * 本软件源代码版权归----所有,未经许可不得任意复制与传播.
  4 + */
  5 +package com.b2c.dtms.dao.base;
  6 +
  7 +import java.io.Serializable;
  8 +import java.util.List;
  9 +
  10 +/**
  11 + * dao实现类
  12 + * @author dev-center
  13 + * @since 2014-05-15
  14 + * @param <T> 实体
  15 + * @param <KEY> 主键
  16 + */
  17 +public abstract class BaseDaoImpl<T, KEY extends Serializable> extends MyBatisSupport implements BaseDao<T, KEY> {
  18 + private static final String DEFAULT_INSERT_KEY = "insertEntry";
  19 + //private static final String DEFAULT_INSERT_LAST_SEQUENCE_KEY = "lastSequence";
  20 + private static final String DEFAULT_DELETE_ARRAY_KEY = "deleteByArrayKey";
  21 + private static final String DEFAULT_DELETE_CONDTION = "deleteByCondtion";
  22 + private static final String DEFAULT_UPDATE_KEY = "updateByKey";
  23 + private static final String DEFAULT_SELECT_ARRAY_KEY = "selectEntryArray";
  24 + private static final String DEFAULT_SELECT_CONDTION = "selectEntryList";
  25 + private static final String DEFAULT_SELECT_CONDTION_COUNT = "selectEntryListCount";
  26 +
  27 + /**
  28 + * 获取命名空前前缀
  29 + * @param statement
  30 + * @return
  31 + */
  32 + public abstract String getNameSpace(String statement);
  33 +
  34 + @SuppressWarnings("unchecked")
  35 + public int insertEntry(T...t){
  36 + int result = 0;
  37 + if (t == null || t.length <= 0) {return result;}
  38 + for (T o : t) {
  39 + if(o != null) {
  40 + result += this.insert(getNameSpace(DEFAULT_INSERT_KEY), o);
  41 + }
  42 + }
  43 + return result;
  44 + }
  45 +
  46 +// public int insertEntryCreateId(T t) {
  47 +// @SuppressWarnings("unchecked")
  48 +// int result = this.insertEntry(t);
  49 +// if (result > 0) {
  50 +// Integer id = (Integer)select(getNameSpace(DEFAULT_INSERT_LAST_SEQUENCE_KEY),null);
  51 +// if (id != null && id >0) {
  52 +// try {
  53 +// Class<?> clz = t.getClass();
  54 +// clz.getMethod("setId", Long.class).invoke(t, id.longValue());//最后一次插入编号
  55 +// } catch (Exception e) {
  56 +// throw new AppException("设置新增主键失败", e);
  57 +// }
  58 +// }
  59 +// }
  60 +// return result;
  61 +// }
  62 +
  63 + @SuppressWarnings("unchecked")
  64 + public int deleteByKey(KEY...key) {
  65 + return this.delete(getNameSpace(DEFAULT_DELETE_ARRAY_KEY), key);
  66 + }
  67 +
  68 + public int deleteByKey(T t) {
  69 + return this.delete(getNameSpace(DEFAULT_DELETE_CONDTION), t);
  70 + }
  71 +
  72 + public int updateByKey(T t) {
  73 + return this.update(getNameSpace(DEFAULT_UPDATE_KEY), t);
  74 + }
  75 +
  76 + public int updateBatch(List<T> t) {
  77 + return this.updateBatch(getNameSpace(DEFAULT_UPDATE_KEY),t);
  78 + }
  79 +
  80 +
  81 + @SuppressWarnings("unchecked")
  82 + public int updateBatch(T ... t) {
  83 + return this.updateBatch(getNameSpace(DEFAULT_UPDATE_KEY), t);
  84 + }
  85 +
  86 + public int insertBatch(List<T> t) {
  87 + return this.insertBatch(getNameSpace(DEFAULT_INSERT_KEY),t);
  88 + }
  89 +
  90 + @SuppressWarnings("unchecked")
  91 + public int insertBatch(T ... t) {
  92 + return this.insertBatch(getNameSpace(DEFAULT_INSERT_KEY),t);
  93 + }
  94 +
  95 + public T selectEntry(KEY key) {
  96 + @SuppressWarnings("unchecked")
  97 + List<T> list = this.selectEntryList(key);
  98 + if(list != null && list.size() > 0) {
  99 + return list.get(0);
  100 + }
  101 + return null;
  102 + }
  103 +
  104 + @SuppressWarnings("unchecked")
  105 + public List<T> selectEntryList(KEY...key) {
  106 + if (key == null || key.length <= 0) {return null;}
  107 + return this.selectList(getNameSpace(DEFAULT_SELECT_ARRAY_KEY), key);
  108 + }
  109 +
  110 + public List<T> selectEntryList(T t) {
  111 + return this.selectList(getNameSpace(DEFAULT_SELECT_CONDTION), t);
  112 + }
  113 +
  114 + public Integer selectEntryListCount(T t) {
  115 + return this.select(getNameSpace(DEFAULT_SELECT_CONDTION_COUNT), t);
  116 + }
  117 +}
... ...
dtms-dao/src/main/java/com/b2c/dtms/dao/base/MyBatisSupport.java 0 → 100644
  1 +++ a/dtms-dao/src/main/java/com/b2c/dtms/dao/base/MyBatisSupport.java
  1 +/*
  2 + * Copyright (c) 2014 www.diligrp.com All rights reserved.
  3 + * 本软件源代码版权归----所有,未经许可不得任意复制与传播.
  4 + */
  5 +package com.b2c.dtms.dao.base;
  6 +
  7 +import org.apache.ibatis.session.SqlSession;
  8 +import org.mybatis.spring.SqlSessionTemplate;
  9 +import org.slf4j.Logger;
  10 +import org.slf4j.LoggerFactory;
  11 +
  12 +import com.b2c.dtms.common.exception.AppException;
  13 +
  14 +import javax.annotation.Resource;
  15 +import java.util.List;
  16 +import java.util.Map;
  17 +
  18 +/**
  19 + * 对mybatis的支持<br/>
  20 + * spring配置文件需定义sqlTemplate与batchSqlTemplate
  21 + * @author dev-center
  22 + * @since 2014-05-15
  23 + */
  24 +abstract class MyBatisSupport {
  25 + protected static final Logger LOGGER = LoggerFactory.getLogger(MyBatisSupport.class);
  26 + @Resource private SqlSessionTemplate sqlTemplate;
  27 + @Resource private SqlSessionTemplate batchSqlTemplate;
  28 +
  29 + /**
  30 + * SqlSessionTemplate
  31 + * @param batch 是否批处理
  32 + * @param readonly 是否只读
  33 + * @return
  34 + */
  35 + protected SqlSessionTemplate getSqlTemplate(boolean batch,boolean readonly) {
  36 +
  37 + if(readonly) {
  38 + }
  39 +
  40 + if(batch) {
  41 + return batchSqlTemplate;
  42 + }
  43 + return sqlTemplate;
  44 + }
  45 +
  46 + /**
  47 + * 新增对象
  48 + * @param statement
  49 + * @param parameter
  50 + * @return
  51 + */
  52 + protected int insert(String statement,Object parameter){
  53 + int res = 0;
  54 + try {
  55 + if(parameter != null) {
  56 + res = getSqlTemplate(false,false).insert(statement, parameter);
  57 + }
  58 + } catch (Exception ex) {
  59 + throw new AppException("Mybatis执行新增异常", ex);
  60 + }
  61 + return res;
  62 + }
  63 +
  64 + /**
  65 + * 删除对象
  66 + * @param statement
  67 + * @param parameter
  68 + * @return
  69 + */
  70 + protected int delete(String statement,Object parameter){
  71 + int res = 0;
  72 + try {
  73 + res = getSqlTemplate(false,false).delete(statement, parameter);
  74 + } catch (Exception ex) {
  75 + throw new AppException("Mybatis执行删除异常", ex);
  76 + }
  77 + return res;
  78 + }
  79 +
  80 + /**
  81 + * 更新对象
  82 + * @param statement
  83 + * @param parameter
  84 + * @return
  85 + */
  86 + protected int update(String statement,Object parameter){
  87 + int res = 0;
  88 + try {
  89 + if(parameter != null) {
  90 + res = getSqlTemplate(false,false).update(statement, parameter);
  91 + }
  92 + } catch (Exception ex) {
  93 + throw new AppException("Mybatis执行更新异常", ex);
  94 + }
  95 + return res;
  96 + }
  97 +
  98 + /**
  99 + * 批量更新对象
  100 + * @param statement
  101 + * @param list
  102 + * @return
  103 + */
  104 + @SuppressWarnings("rawtypes")
  105 + protected int updateBatch(String statement,List parameterList){
  106 + int res = 0;
  107 + SqlSession session=null;
  108 + try {
  109 + if(parameterList!=null&&parameterList.size()>0){
  110 + session= getSqlTemplate(true,false).getSqlSessionFactory().openSession();
  111 + for(int i=0;i<parameterList.size();i++){
  112 + int row=session.update(statement, parameterList.get(i));
  113 + res+=row;
  114 + }
  115 + session.flushStatements();
  116 + session.commit();
  117 + }
  118 + } catch (Exception ex) {
  119 + //回滚由外层服务决定
  120 + throw new AppException("Mybatis执行批量更新异常", ex);
  121 + } finally{
  122 + if(session!=null){
  123 + session.close();
  124 + }
  125 + }
  126 + return res;
  127 + }
  128 +
  129 + /**
  130 + * 批量更新对象
  131 + * @param statement
  132 + * @param list
  133 + * @return
  134 + */
  135 + protected int updateBatch(String statement,Object ... parameterArray){
  136 + int res = 0;
  137 + SqlSession session=null;
  138 + try {
  139 + if(parameterArray!=null&&parameterArray.length>0){
  140 + session= getSqlTemplate(true,false).getSqlSessionFactory().openSession();
  141 + for(int i=0;i<parameterArray.length;i++){
  142 + int row=session.update(statement, parameterArray[i]);
  143 + res+=row;
  144 + }
  145 + session.flushStatements();
  146 + session.commit();
  147 + }
  148 + } catch (Exception ex) {
  149 + //回滚由外层服务决定
  150 + throw new AppException("Mybatis执行批量更新异常", ex);
  151 + } finally{
  152 + if(session!=null){
  153 + session.close();
  154 + }
  155 + }
  156 + return res;
  157 + }
  158 +
  159 + /**
  160 + *
  161 + * 批量插入对象
  162 + * @param statement
  163 + * @param parameterList
  164 + * @return
  165 + */
  166 + @SuppressWarnings("rawtypes")
  167 + protected int insertBatch(String statement,List parameterList){
  168 + int res = 0;
  169 + SqlSession session=null;
  170 + try {
  171 + if(parameterList!=null&&parameterList.size()>0){
  172 + session= getSqlTemplate(true,false).getSqlSessionFactory().openSession();
  173 + for(int i=0;i<parameterList.size();i++){
  174 + int row=session.insert(statement, parameterList.get(i));
  175 + res+=row;
  176 + }
  177 + session.flushStatements();
  178 + session.commit();
  179 + }
  180 + } catch (Exception ex) {
  181 + //回滚由外层服务决定
  182 + throw new AppException("Mybatis执行批量插入异常", ex);
  183 + } finally{
  184 + if(session!=null){
  185 + session.close();
  186 + }
  187 + }
  188 + return res;
  189 + }
  190 +
  191 + /**
  192 + * 批量更新对象
  193 + * @param statement
  194 + * @param list
  195 + * @return
  196 + */
  197 + protected int insertBatch(String statement,Object ... parameterArray){
  198 + int res = 0;
  199 + SqlSession session=null;
  200 + try {
  201 + if(parameterArray!=null&&parameterArray.length>0){
  202 + session= getSqlTemplate(true,false).getSqlSessionFactory().openSession();
  203 + for(int i=0;i<parameterArray.length;i++){
  204 + int row=session.insert(statement, parameterArray[i]);
  205 + res+=row;
  206 + }
  207 + session.flushStatements();
  208 + session.commit();
  209 + }
  210 + } catch (Exception ex) {
  211 + //回滚由外层服务决定
  212 + throw new AppException("Mybatis执行批量插入异常", ex);
  213 + } finally{
  214 + if(session!=null){
  215 + session.close();
  216 + }
  217 + }
  218 + return res;
  219 + }
  220 +
  221 + /**
  222 + * 查询一条记录
  223 + * @param <T>
  224 + * @param statement
  225 + * @param parameter
  226 + * @param clz
  227 + * @return
  228 + */
  229 + @SuppressWarnings("unchecked")
  230 + protected <T> T select(String statement,Object parameter) {
  231 + T obj = null;
  232 + try {
  233 + obj = (T)getSqlTemplate(false,true).selectOne(statement, parameter);
  234 + } catch (Exception ex) {
  235 + throw new AppException("Mybatis执行单条查询异常",ex);
  236 + }
  237 + return obj;
  238 + }
  239 +
  240 + /**
  241 + * 查询列表
  242 + * @param <T>
  243 + * @param statement
  244 + * @param parameter
  245 + * @param clz
  246 + * @return
  247 + */
  248 + protected <T> List<T> selectList(String statement,Object parameter) {
  249 + List<T> list = null;
  250 + try {
  251 + list = getSqlTemplate(false,true).selectList(statement, parameter);
  252 + } catch (Exception ex) {
  253 + throw new AppException("Mybatis执行列表查询异常",ex);
  254 + }
  255 + return list;
  256 + }
  257 +
  258 + /**
  259 + * 查询Map
  260 + * @param <K>
  261 + * @param <V>
  262 + * @param statement
  263 + * @param parameter
  264 + * @param mapKey
  265 + * @return
  266 + */
  267 + protected <K, V> Map<K, V> selectMap(String statement,Object parameter, String mapKey) {
  268 + Map<K, V> map = null;
  269 + try {
  270 + map = getSqlTemplate(false,true).selectMap(statement, parameter,mapKey);
  271 + } catch (Exception ex) {
  272 + throw new AppException("Mybatis执行Map查询异常",ex);
  273 + }
  274 + return map;
  275 + }
  276 +}
... ...
dtms-dao/src/main/java/com/b2c/dtms/dao/dtms/DtmsMessageConfigDao.java 0 → 100644
  1 +++ a/dtms-dao/src/main/java/com/b2c/dtms/dao/dtms/DtmsMessageConfigDao.java
  1 +/*
  2 + * Copyright (c) 2015 www.diligrp.com All rights reserved.
  3 + * 本软件源代码版权归----所有,未经许可不得任意复制与传播.
  4 + */
  5 +package com.b2c.dtms.dao.dtms;
  6 +
  7 +import com.b2c.dtms.dao.base.BaseDao;
  8 +import com.b2c.dtms.domain.DtmsMessageConfig;
  9 +
  10 +/**
  11 + * DtmsMessageHandlerDao 接口
  12 + * @author dev-center
  13 + * @since 2015-03-30
  14 + */
  15 +public interface DtmsMessageConfigDao extends BaseDao<DtmsMessageConfig,Long>{
  16 + //自定义扩展
  17 +
  18 +}
0 19 \ No newline at end of file
... ...
dtms-dao/src/main/java/com/b2c/dtms/dao/dtms/DtmsMessageDao.java 0 → 100644
  1 +++ a/dtms-dao/src/main/java/com/b2c/dtms/dao/dtms/DtmsMessageDao.java
  1 +/*
  2 + * Copyright (c) 2015 www.diligrp.com All rights reserved.
  3 + * 本软件源代码版权归----所有,未经许可不得任意复制与传播.
  4 + */
  5 +package com.b2c.dtms.dao.dtms;
  6 +
  7 +import com.b2c.dtms.dao.base.BaseDao;
  8 +import com.b2c.dtms.domain.DtmsMessage;
  9 +
  10 +import java.util.List;
  11 +
  12 +
  13 +/**
  14 + * DtmsMessageDao 接口
  15 + * @author dev-center
  16 + * @since 2015-03-30
  17 + */
  18 +public interface DtmsMessageDao extends BaseDao<DtmsMessage,Long>{
  19 +
  20 + //自定义扩展
  21 + List<DtmsMessage> getListUnLockedBeforeSepcTime(DtmsMessage condition);
  22 +
  23 + /**
  24 + * 获取锁定超时的消息
  25 + * @param condition
  26 + * @return
  27 + */
  28 + List<DtmsMessage> getLockTimeOutList(DtmsMessage condition);
  29 +
  30 + int updateByCondition(DtmsMessage dtmsMessage);
  31 +
  32 + int deleteByCondition(DtmsMessage condition);
  33 +
  34 + /**
  35 + * 尝试对消息进行加锁
  36 + * @param message
  37 + * @return
  38 + */
  39 + int tryAddLock(DtmsMessage message);
  40 +
  41 + /**
  42 + * 获取被加锁消息的个数
  43 + * @param dtmsMessage
  44 + * @return
  45 + */
  46 + int selectLockedCount(DtmsMessage dtmsMessage);
  47 +
  48 + /**
  49 + * 解锁被加锁超时的消息
  50 + * @param updateMessage
  51 + * @return
  52 + */
  53 + int tryReleaseLock(DtmsMessage updateMessage);
  54 +
  55 + /**
  56 + * 解锁被加锁超时的消息
  57 + * @param updateMessage
  58 + * @return
  59 + */
  60 + int tryReleaseLock(List<DtmsMessage> list);
  61 +
  62 + /**
  63 + * 删除消息,根据消息id和版本号.
  64 + *
  65 + * @param message the message。必须参数值id和version
  66 + * @return the int
  67 + */
  68 + int deleteByKeyAndVersion(DtmsMessage message);
  69 +
  70 + /**
  71 + * 减少消息重试次数
  72 + * @param message
  73 + * @return
  74 + */
  75 + int reduceRetryCount(DtmsMessage message);
  76 +
  77 + /**
  78 + * 减少消息重试次数及下次运行时间
  79 + * @param toUpdateMessage
  80 + * @return
  81 + */
  82 + int reduceRetryCountAndSetNextRuntime(DtmsMessage message);
  83 +
  84 +}
0 85 \ No newline at end of file
... ...
dtms-dao/src/main/java/com/b2c/dtms/dao/dtms/DtmsMessageExceptionDao.java 0 → 100644
  1 +++ a/dtms-dao/src/main/java/com/b2c/dtms/dao/dtms/DtmsMessageExceptionDao.java
  1 +/*
  2 + * Copyright (c) 2015 www.diligrp.com All rights reserved.
  3 + * 本软件源代码版权归----所有,未经许可不得任意复制与传播.
  4 + */
  5 +package com.b2c.dtms.dao.dtms;
  6 +
  7 +import com.b2c.dtms.dao.base.BaseDao;
  8 +import com.b2c.dtms.domain.DtmsMessageException;
  9 +
  10 +/**
  11 + * DtmsMessageExceptionDao 接口
  12 + * @author dev-center
  13 + * @since 2015-03-30
  14 + */
  15 +public interface DtmsMessageExceptionDao extends BaseDao<DtmsMessageException,Long>{
  16 + //自定义扩展
  17 +
  18 +}
0 19 \ No newline at end of file
... ...
dtms-dao/src/main/java/com/b2c/dtms/dao/dtms/DtmsMessageHistoryDao.java 0 → 100644
  1 +++ a/dtms-dao/src/main/java/com/b2c/dtms/dao/dtms/DtmsMessageHistoryDao.java
  1 +/*
  2 + * Copyright (c) 2015 www.diligrp.com All rights reserved.
  3 + * 本软件源代码版权归----所有,未经许可不得任意复制与传播.
  4 + */
  5 +package com.b2c.dtms.dao.dtms;
  6 +
  7 +import com.b2c.dtms.dao.base.BaseDao;
  8 +import com.b2c.dtms.domain.DtmsMessageHistory;
  9 +
  10 +/**
  11 + * DtmsMessageHistoryDao 接口
  12 + * @author dev-center
  13 + * @since 2015-03-30
  14 + */
  15 +public interface DtmsMessageHistoryDao extends BaseDao<DtmsMessageHistory,Long>{
  16 + //自定义扩展
  17 +
  18 +}
0 19 \ No newline at end of file
... ...
dtms-dao/src/main/java/com/b2c/dtms/dao/impl/DtmsMaxidDaoImpl.java 0 → 100644
  1 +++ a/dtms-dao/src/main/java/com/b2c/dtms/dao/impl/DtmsMaxidDaoImpl.java
  1 +/*
  2 + * Copyright (c) 2014 www.diligrp.com All rights reserved.
  3 + * 本软件源代码版权归----所有,未经许可不得任意复制与传播.
  4 + */
  5 +package com.b2c.dtms.dao.impl;
  6 +
  7 +import com.b2c.dtms.common.CommonUtils;
  8 +import com.b2c.dtms.dao.DtmsMaxidDao;
  9 +import com.b2c.dtms.dao.base.BaseDaoImpl;
  10 +import com.b2c.dtms.domain.OrderMaxid;
  11 +
  12 +import org.springframework.stereotype.Repository;
  13 +import org.springframework.transaction.annotation.Propagation;
  14 +import org.springframework.transaction.annotation.Transactional;
  15 +
  16 +import java.util.List;
  17 +
  18 +/**
  19 + * OrderMaxidDao 实现类
  20 + *
  21 + * @author dev-center
  22 + * @since 2014-05-19
  23 + */
  24 +@Repository("orderMaxidDao")
  25 +public class DtmsMaxidDaoImpl extends BaseDaoImpl<OrderMaxid, Long> implements DtmsMaxidDao {
  26 + private final static String NAMESPACE = "com.b2c.dtms.dao.OrderMaxidDao.";
  27 +
  28 + // 返回本DAO命名空间,并添加statement
  29 + public String getNameSpace(String statement) {
  30 + return NAMESPACE + statement;
  31 + }
  32 +
  33 + @Override
  34 + public OrderMaxid getOrderMaxIdByIdType(String idType) {
  35 + OrderMaxid orderMaxid = new OrderMaxid();
  36 + orderMaxid.setIdType(idType);
  37 + List<OrderMaxid> list = this.selectEntryList(orderMaxid);
  38 + if (list == null || list.isEmpty()) {
  39 + return null;
  40 + }
  41 + if (list.size() > 1) {
  42 + StringBuilder sb = new StringBuilder();
  43 + sb.append("重复的id生成类型");
  44 + sb.append(idType);
  45 + sb.append(",无法确定使用哪一个");
  46 + CommonUtils.throwDataError(true, sb.toString());
  47 + }
  48 + return list.get(0);
  49 + }
  50 +
  51 + @Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
  52 + public SequenceNo getSeqNoByNewTransactional(SequenceNo idSequence, String seqIdKey, Long startSeq) {
  53 + OrderMaxid orderMaxid = this.getOrderMaxIdByIdType(seqIdKey);
  54 + if (startSeq != null && startSeq > orderMaxid.getIdValue()) {// orderMaxid.getIdValue()
  55 + idSequence.setStartSeq(startSeq);
  56 + } else {
  57 + idSequence.setStartSeq(orderMaxid.getIdValue());
  58 + }
  59 + idSequence.setFinishSeq(idSequence.getStartSeq() + idSequence.getStep());
  60 + orderMaxid.setIdValue(idSequence.getFinishSeq());
  61 + Integer result = this.updateByKey(orderMaxid);
  62 + // 当更新失败后,返回空,外层进行重试
  63 + if (null == result || result < 1) {
  64 + return null;
  65 + }
  66 + return idSequence;
  67 + }
  68 +}
0 69 \ No newline at end of file
... ...
dtms-dao/src/main/java/com/b2c/dtms/dao/impl/DtmsMessageConfigDaoImpl.java 0 → 100644
  1 +++ a/dtms-dao/src/main/java/com/b2c/dtms/dao/impl/DtmsMessageConfigDaoImpl.java
  1 +/*
  2 + * Copyright (c) 2015 www.diligrp.com All rights reserved.
  3 + * 本软件源代码版权归----所有,未经许可不得任意复制与传播.
  4 + */
  5 +package com.b2c.dtms.dao.impl;
  6 +
  7 +import com.b2c.dtms.dao.base.BaseDaoImpl;
  8 +import com.b2c.dtms.dao.dtms.DtmsMessageConfigDao;
  9 +import com.b2c.dtms.domain.DtmsMessageConfig;
  10 +
  11 +import org.springframework.stereotype.Repository;
  12 +
  13 +/**
  14 + * DtmsMessageHandlerDao 实现类
  15 + * @author dev-center
  16 + * @since 2015-03-30
  17 + */
  18 +@Repository("dtmsMessageHandlerDao")
  19 +public class DtmsMessageConfigDaoImpl extends BaseDaoImpl<DtmsMessageConfig,Long> implements DtmsMessageConfigDao {
  20 + private final static String NAMESPACE = "com.b2c.dtms.dao.DtmsMessageConfigDao.";
  21 +
  22 + //返回本DAO命名空间,并添加statement
  23 + public String getNameSpace(String statement) {
  24 + return NAMESPACE + statement;
  25 + }
  26 +
  27 +}
0 28 \ No newline at end of file
... ...
dtms-dao/src/main/java/com/b2c/dtms/dao/impl/DtmsMessageDaoImpl.java 0 → 100644
  1 +++ a/dtms-dao/src/main/java/com/b2c/dtms/dao/impl/DtmsMessageDaoImpl.java
  1 +/*
  2 + * Copyright (c) 2015 www.diligrp.com All rights reserved.
  3 + * 本软件源代码版权归----所有,未经许可不得任意复制与传播.
  4 + */
  5 +package com.b2c.dtms.dao.impl;
  6 +
  7 +import com.b2c.dtms.dao.base.BaseDaoImpl;
  8 +import com.b2c.dtms.dao.dtms.DtmsMessageDao;
  9 +import com.b2c.dtms.domain.DtmsMessage;
  10 +
  11 +import org.springframework.stereotype.Repository;
  12 +
  13 +import java.util.List;
  14 +
  15 +/**
  16 + * DtmsMessageDao 实现类
  17 + *
  18 + * @author dev-center
  19 + * @since 2015-03-30
  20 + */
  21 +@Repository("dtmsMessageDao")
  22 +public class DtmsMessageDaoImpl extends BaseDaoImpl<DtmsMessage, Long> implements DtmsMessageDao {
  23 + private final static String NAMESPACE = "com.b2c.dtms.dao.DtmsMessageDao.";
  24 +
  25 + // 返回本DAO命名空间,并添加statement
  26 + public String getNameSpace(String statement) {
  27 + return NAMESPACE + statement;
  28 + }
  29 +
  30 + @Override
  31 + public List<DtmsMessage> getListUnLockedBeforeSepcTime(DtmsMessage condition) {
  32 + return this.selectList(this.getNameSpace("getListUnLockedBeforeSepcTime"), condition);
  33 + }
  34 +
  35 + @Override
  36 + public List<DtmsMessage> getLockTimeOutList(DtmsMessage condition) {
  37 + return this.selectList(this.getNameSpace("getLockTimeOutList"), condition);
  38 + }
  39 +
  40 + @Override
  41 + public int updateByCondition(DtmsMessage condition) {
  42 + return this.update(this.getNameSpace("updateByCondtion"), condition);
  43 + }
  44 +
  45 + @Override
  46 + public int deleteByCondition(DtmsMessage condition) {
  47 + return this.delete(this.getNameSpace("deleteByCondtion"), condition);
  48 + }
  49 +
  50 + @Override
  51 + public int tryAddLock(DtmsMessage message) {
  52 + return this.update(this.getNameSpace("tryAddLock"), message);
  53 + }
  54 +
  55 + @Override
  56 + public int selectLockedCount(DtmsMessage message) {
  57 + return this.select(this.getNameSpace("selectLockedCount"), message);
  58 + }
  59 +
  60 + @Override
  61 + public int tryReleaseLock(DtmsMessage message) {
  62 + return this.update(this.getNameSpace("tryReleaseLock"), message);
  63 + }
  64 +
  65 + @Override
  66 + public int tryReleaseLock(List<DtmsMessage> list) {
  67 + return this.updateBatch(this.getNameSpace("tryReleaseLock"), list);
  68 + }
  69 +
  70 + @Override
  71 + public int deleteByKeyAndVersion(DtmsMessage message) {
  72 + return this.delete(this.getNameSpace("deleteByKeyAndVersion"), message);
  73 + }
  74 +
  75 + @Override
  76 + public int reduceRetryCount(DtmsMessage message) {
  77 + return this.update(this.getNameSpace("reduceRetryCount"), message);
  78 + }
  79 +
  80 + @Override
  81 + public int reduceRetryCountAndSetNextRuntime(DtmsMessage message) {
  82 + return this.update(this.getNameSpace("reduceRetryCountAndSetNextRuntime"), message);
  83 + }
  84 +}
0 85 \ No newline at end of file
... ...
dtms-dao/src/main/java/com/b2c/dtms/dao/impl/DtmsMessageExceptionDaoImpl.java 0 → 100644
  1 +++ a/dtms-dao/src/main/java/com/b2c/dtms/dao/impl/DtmsMessageExceptionDaoImpl.java
  1 +/*
  2 + * Copyright (c) 2015 www.diligrp.com All rights reserved.
  3 + * 本软件源代码版权归----所有,未经许可不得任意复制与传播.
  4 + */
  5 +package com.b2c.dtms.dao.impl;
  6 +
  7 +import com.b2c.dtms.dao.base.BaseDaoImpl;
  8 +import com.b2c.dtms.dao.dtms.DtmsMessageExceptionDao;
  9 +import com.b2c.dtms.domain.DtmsMessageException;
  10 +
  11 +import org.springframework.stereotype.Repository;
  12 +
  13 +/**
  14 + * DtmsMessageExceptionDao 实现类
  15 + *
  16 + * @author dev-center
  17 + * @since 2015-03-30
  18 + */
  19 +@Repository("dtmsMessageExceptionDao")
  20 +public class DtmsMessageExceptionDaoImpl extends BaseDaoImpl<DtmsMessageException, Long>
  21 + implements DtmsMessageExceptionDao {
  22 + private final static String NAMESPACE = "com.b2c.dtms.dao.DtmsMessageExceptionDao.";
  23 +
  24 + // 返回本DAO命名空间,并添加statement
  25 + public String getNameSpace(String statement) {
  26 + return NAMESPACE + statement;
  27 + }
  28 +
  29 +}
0 30 \ No newline at end of file
... ...
dtms-dao/src/main/java/com/b2c/dtms/dao/impl/DtmsMessageHistoryDaoImpl.java 0 → 100644
  1 +++ a/dtms-dao/src/main/java/com/b2c/dtms/dao/impl/DtmsMessageHistoryDaoImpl.java
  1 +/*
  2 + * Copyright (c) 2015 www.diligrp.com All rights reserved.
  3 + * 本软件源代码版权归----所有,未经许可不得任意复制与传播.
  4 + */
  5 +package com.b2c.dtms.dao.impl;
  6 +
  7 +import com.b2c.dtms.dao.base.BaseDaoImpl;
  8 +import com.b2c.dtms.dao.dtms.DtmsMessageHistoryDao;
  9 +import com.b2c.dtms.domain.DtmsMessageHistory;
  10 +
  11 +import org.springframework.stereotype.Repository;
  12 +
  13 +/**
  14 + * DtmsMessageLogDao 实现类
  15 + * @author dev-center
  16 + * @since 2015-03-30
  17 + */
  18 +@Repository("dtmsMessageHistoryDao")
  19 +public class DtmsMessageHistoryDaoImpl extends BaseDaoImpl<DtmsMessageHistory,Long> implements DtmsMessageHistoryDao {
  20 + private final static String NAMESPACE = "com.b2c.dtms.dao.DtmsMessageHistoryDao.";
  21 +
  22 + //返回本DAO命名空间,并添加statement
  23 + public String getNameSpace(String statement) {
  24 + return NAMESPACE + statement;
  25 + }
  26 +
  27 +}
0 28 \ No newline at end of file
... ...
dtms-dao/src/main/java/com/b2c/dtms/dao/typehandler/LongToDate.java 0 → 100644
  1 +++ a/dtms-dao/src/main/java/com/b2c/dtms/dao/typehandler/LongToDate.java
  1 +package com.b2c.dtms.dao.typehandler;
  2 +
  3 +import java.sql.CallableStatement;
  4 +import java.sql.PreparedStatement;
  5 +import java.sql.ResultSet;
  6 +import java.sql.SQLException;
  7 +import java.util.Date;
  8 +
  9 +import org.apache.ibatis.type.BaseTypeHandler;
  10 +import org.apache.ibatis.type.JdbcType;
  11 +
  12 +public class LongToDate extends BaseTypeHandler<Date> {
  13 +
  14 + @Override
  15 + public void setNonNullParameter(PreparedStatement ps, int i, Date parameter, JdbcType jdbcType)
  16 + throws SQLException {
  17 + ps.setObject(i, parameter.getTime());
  18 + }
  19 +
  20 + @Override
  21 + public Date getNullableResult(ResultSet rs, String columnName) throws SQLException {
  22 + long value = rs.getLong(columnName);
  23 + if (value <= 0) {
  24 + return null;
  25 + }
  26 + return new Date(value);
  27 + }
  28 +
  29 + @Override
  30 + public Date getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
  31 + if (rs.wasNull()) {
  32 + return null;
  33 + }
  34 + long value = rs.getLong(columnIndex);
  35 + if (value <= 0) {
  36 + return null;
  37 + }
  38 + return new Date(value);
  39 + }
  40 +
  41 + @Override
  42 + public Date getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
  43 + if (cs.wasNull()) {
  44 + return null;
  45 + }
  46 + long value = cs.getLong(columnIndex);
  47 + if (value <= 0) {
  48 + return null;
  49 + }
  50 + return new Date(value);
  51 + }
  52 +
  53 +}
... ...
dtms-dao/src/main/resources/spring-config-dao.xml 0 → 100644
  1 +++ a/dtms-dao/src/main/resources/spring-config-dao.xml
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<beans xmlns="http://www.springframework.org/schema/beans"
  3 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4 + xmlns:context="http://www.springframework.org/schema/context"
  5 + xmlns:aop="http://www.springframework.org/schema/aop"
  6 + xsi:schemaLocation="http://www.springframework.org/schema/beans
  7 + http://www.springframework.org/schema/beans/spring-beans.xsd
  8 + http://www.springframework.org/schema/context
  9 + http://www.springframework.org/schema/context/spring-context.xsd
  10 + http://www.springframework.org/schema/aop
  11 + http://www.springframework.org/schema/aop/spring-aop.xsd"
  12 + default-autowire="byName">
  13 +
  14 + <context:component-scan base-package="com.b2c.dtms.dao"/>
  15 +
  16 + <bean id="masterDataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
  17 + <property name="driverClassName" value="${jdbc.driverClass}" />
  18 + <property name="url" value="${jdbc.jdbcUrl}" />
  19 + <property name="username" value="${jdbc.username}" />
  20 + <property name="password" value="${jdbc.password}" />
  21 + <!-- 添加监控,SQL注入防火墙-->
  22 + <property name="filters" value="stat,logback" />
  23 + <!-- 慢查询 -->
  24 + <property name="connectionProperties" value="druid.stat.slowSqlMillis=1000" />
  25 + <property name="maxActive" value="100" />
  26 + <property name="initialSize" value="1" />
  27 + <property name="maxWait" value="60000" />
  28 + <property name="minIdle" value="1" />
  29 + <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
  30 + <property name="timeBetweenEvictionRunsMillis" value="60000" />
  31 + <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
  32 + <property name="minEvictableIdleTimeMillis" value="300000" />
  33 + <property name="validationQuery" value="SELECT now()" />
  34 + <property name="testWhileIdle" value="true" />
  35 + <property name="testOnBorrow" value="false" />
  36 + <property name="testOnReturn" value="false" />
  37 + <!-- 打开PSCache,并且指定每个连接上PSCache的大小 -->
  38 + <property name="poolPreparedStatements" value="true" />
  39 + <property name="maxOpenPreparedStatements" value="20" />
  40 +
  41 + <!-- 超过时间限制是否回收 -->
  42 + <property name="removeAbandoned" value="true" />
  43 + <!-- 超时时间;单位为秒。180秒=3分钟 -->
  44 + <property name="removeAbandonedTimeout" value="180" />
  45 + <!-- 关闭abanded连接时输出错误日志 -->
  46 + <property name="logAbandoned" value="true" />
  47 +
  48 + <!-- 配置公用监控数据 -->
  49 + <property name="useGlobalDataSourceStat" value="true" />
  50 + </bean>
  51 +
  52 + <!-- 配置事务管理器 -->
  53 + <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  54 + <property name="dataSource" ref="masterDataSource" />
  55 + </bean>
  56 +
  57 + <!-- 集成Mybatis -->
  58 + <bean id="sessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
  59 + <property name="dataSource" ref="masterDataSource" />
  60 + <property name="configLocation" value="classpath:sqlmap-config.xml" />
  61 + </bean>
  62 + <bean id="sqlTemplate" class="org.mybatis.spring.SqlSessionTemplate">
  63 + <constructor-arg index="0" ref="sessionFactory" />
  64 + </bean>
  65 + <bean id="batchSqlTemplate" class="org.mybatis.spring.SqlSessionTemplate">
  66 + <constructor-arg index="0" ref="sessionFactory" />
  67 + <constructor-arg index="1" value="BATCH" />
  68 + </bean>
  69 +
  70 + <!-- druid spring监控 -->
  71 + <bean id="druid-stat-interceptor"
  72 + class="com.alibaba.druid.support.spring.stat.DruidStatInterceptor">
  73 + </bean>
  74 + <bean id="druid-stat-pointcut" class="org.springframework.aop.support.JdkRegexpMethodPointcut" scope="prototype">
  75 + <property name="patterns">
  76 + <list>
  77 + <value>com.b2c.dtms.service.*</value>
  78 + <value>com.b2c.dtms.dao.*</value>
  79 + </list>
  80 + </property>
  81 + </bean>
  82 + <aop:config>
  83 + <aop:advisor advice-ref="druid-stat-interceptor"
  84 + pointcut-ref="druid-stat-pointcut" />
  85 + </aop:config>
  86 +</beans>
0 87 \ No newline at end of file
... ...
dtms-dao/src/main/resources/sqlmap-config.xml 0 → 100644
  1 +++ a/dtms-dao/src/main/resources/sqlmap-config.xml
  1 +<?xml version="1.0" encoding="UTF-8" ?>
  2 +<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
  3 +
  4 +<configuration>
  5 + <settings>
  6 + <!-- 全局映射器启用缓存 -->
  7 + <setting name="cacheEnabled" value="true" />
  8 + <!-- 对于未知的SQL查询,允许返回不同的结果集以达到通用的效果 -->
  9 + <setting name="multipleResultSetsEnabled" value="true" />
  10 + <!-- 允许使用列标签代替列名 -->
  11 + <setting name="useColumnLabel" value="true" />
  12 + <!-- 数据库超过25000秒仍未响应则超时 -->
  13 + <setting name="defaultStatementTimeout" value="25000" />
  14 + <setting name="logImpl" value="STDOUT_LOGGING" />
  15 + </settings>
  16 +
  17 + <!-- 全局别名设置,在映射文件中只需写别名,而不必写出整个类路径 -->
  18 + <typeAliases>
  19 + <typeAlias type="com.b2c.dtms.domain.OrderMaxid" alias="orderMaxid" />
  20 + <typeAlias type="com.b2c.dtms.domain.DtmsMessage" alias="dtmsMessage" />
  21 + <typeAlias type="com.b2c.dtms.domain.DtmsMessageException"
  22 + alias="dtmsMessageException" />
  23 + <typeAlias type="com.b2c.dtms.domain.DtmsMessageConfig"
  24 + alias="dtmsMessageConfig" />
  25 + <typeAlias type="com.b2c.dtms.domain.DtmsMessageHistory"
  26 + alias="dtmsMessageHistory" />
  27 + </typeAliases>
  28 +
  29 + <typeHandlers>
  30 + <typeHandler handler="com.b2c.dtms.dao.typehandler.LongToDate"
  31 + javaType="java.util.Date" />
  32 + </typeHandlers>
  33 +
  34 + <!-- 映射文件路径 -->
  35 + <mappers>
  36 + <mapper resource="sqlmap/OrderMaxid.xml" />
  37 + <mapper resource="sqlmap/dtms/DtmsMessage.xml" />
  38 + <mapper resource="sqlmap/dtms/DtmsMessageException.xml" />
  39 + <mapper resource="sqlmap/dtms/DtmsMessageConfig.xml" />
  40 + <mapper resource="sqlmap/dtms/DtmsMessageHistory.xml" />
  41 + </mappers>
  42 +
  43 +
  44 +</configuration>
0 45 \ No newline at end of file
... ...
dtms-dao/src/main/resources/sqlmap/OrderMaxid.xml 0 → 100644
  1 +++ a/dtms-dao/src/main/resources/sqlmap/OrderMaxid.xml
  1 +<?xml version="1.0" encoding="UTF-8" ?>
  2 +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  3 + "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  4 +<mapper namespace="com.b2c.dtms.dao.OrderMaxidDao">
  5 +
  6 + <!-- order_maxid 所有查询列 -->
  7 + <sql id="QUERY_COLUMN_LIST">
  8 + <!-- [CDATA[id,id_type AS idType,id_value AS idValue,memo,version_num AS versionNum]]-->
  9 + <![CDATA[id,id_value AS idValue,version_num AS versionNum]]>
  10 + </sql>
  11 +
  12 + <!-- order_maxid 查询列来源表-->
  13 + <sql id="QUERY_FROM_TABLE"><![CDATA[FROM order_maxid]]></sql>
  14 +
  15 + <!-- 全部条件(更多功能可以通过queryData扩展实现) -->
  16 + <sql id="QUERY_WHERE_CLAUSE">
  17 + <where>
  18 + <if test="id != null and id != ''"><![CDATA[AND id = #{id}]]></if>
  19 + <if test="idType != null and idType != ''"><![CDATA[AND id_type = #{idType}]]></if>
  20 + <if test="idValue != null and idValue != ''"><![CDATA[AND id_value = #{idValue}]]></if>
  21 + <if test="memo != null and memo != ''"><![CDATA[AND memo = #{memo}]]></if>
  22 + <if test="versionNum != null and versionNum != ''"><![CDATA[AND version_num = #{versionNum}]]></if>
  23 + </where>
  24 + </sql>
  25 +
  26 + <!-- 智能排序与分页 -->
  27 + <sql id="QUERY_ORDER_LIMIT_CONDTION">
  28 + <choose>
  29 + <when test="orderField != null and orderField != ''">
  30 + <choose>
  31 + <when test="orderFieldType != null and orderFieldType != ''">
  32 + <![CDATA[ORDER BY ${orderField} ${orderFieldType}]]>
  33 + </when>
  34 + <otherwise>
  35 + <![CDATA[ORDER BY ${orderField} desc]]>
  36 + </otherwise>
  37 + </choose>
  38 + </when>
  39 + <otherwise>
  40 + <![CDATA[ORDER BY id desc]]>
  41 + </otherwise>
  42 + </choose>
  43 + <if test="startIndex != null and startIndex &gt;= 0 and pageSize != null and pageSize &gt; 0"><![CDATA[LIMIT #{startIndex},#{pageSize}]]></if>
  44 + </sql>
  45 +
  46 + <!-- 更新列字段,只要不为NULL则更新,除开主键列 -->
  47 + <sql id="UPDATE_COLUMN_SET">
  48 + <set>
  49 + <if test="idType != null"><![CDATA[id_type = #{idType},]]></if>
  50 + <if test="idValue != null"><![CDATA[id_value = #{idValue},]]></if>
  51 + <if test="memo != null"><![CDATA[memo = #{memo},]]></if>
  52 + <![CDATA[version_num = version_num + 1,]]>
  53 + </set>
  54 + </sql>
  55 +
  56 + <!-- 插入order_maxid记录 -->
  57 + <insert id="insertEntry" parameterType="orderMaxid" >
  58 + <![CDATA[
  59 + INSERT INTO order_maxid (id,id_type,id_value,memo,version_num)
  60 + VALUES (#{id},#{idType},#{idValue},#{memo},#{versionNum})
  61 + ]]>
  62 + </insert>
  63 +
  64 + <!-- 返回插入的编号,在事务开启状态下有效 -->
  65 + <select id="lastSequence" resultType="int"><![CDATA[SELECT LAST_INSERT_ID() AS id]]></select>
  66 +
  67 + <!-- 删除记录,主键IN(array) -->
  68 + <delete id="deleteByArrayKey" parameterType="java.lang.reflect.Array" >
  69 + <![CDATA[DELETE FROM order_maxid WHERE id IN]]>
  70 + <foreach collection="array" item="id" open="(" separator="," close=")">
  71 + <![CDATA[#{id}]]>
  72 + </foreach>
  73 + </delete>
  74 +
  75 + <!-- 删除,通过条件 -->
  76 + <update id="deleteByCondtion" parameterType="orderMaxid" >
  77 + <![CDATA[DELETE FROM order_maxid]]>
  78 + <include refid="QUERY_WHERE_CLAUSE"/>
  79 + </update>
  80 +
  81 + <!-- 修改记录通过主键 -->
  82 + <update id="updateByKey" parameterType="orderMaxid" >
  83 + <![CDATA[UPDATE order_maxid]]>
  84 + <include refid="UPDATE_COLUMN_SET"/>
  85 + <![CDATA[WHERE id = #{id} AND version_num = #{versionNum}]]>
  86 + </update>
  87 +
  88 + <!-- 查询,通过主键IN(array) -->
  89 + <select id="selectEntryArray" parameterType="java.lang.reflect.Array" resultType="orderMaxid">
  90 + <![CDATA[SELECT]]>
  91 + <include refid="QUERY_COLUMN_LIST"/>
  92 + <include refid="QUERY_FROM_TABLE"/>
  93 + <![CDATA[WHERE id IN]]>
  94 + <foreach collection="array" item="id" open="(" separator="," close=")">
  95 + <![CDATA[#{id}]]>
  96 + </foreach>
  97 + </select>
  98 +
  99 + <!-- 查询,通过条件 -->
  100 + <select id="selectEntryList" parameterType="orderMaxid" resultType="orderMaxid">
  101 + <![CDATA[SELECT]]>
  102 + <include refid="QUERY_COLUMN_LIST"/>
  103 + <include refid="QUERY_FROM_TABLE"/>
  104 + <include refid="QUERY_WHERE_CLAUSE"/>
  105 + <include refid="QUERY_ORDER_LIMIT_CONDTION"/>
  106 + </select>
  107 +
  108 + <!-- 总数查询,通过条件 -->
  109 + <select id="selectEntryListCount" parameterType="orderMaxid" resultType="int">
  110 + <![CDATA[SELECT COUNT(id) AS dataCount]]>
  111 + <include refid="QUERY_FROM_TABLE"/>
  112 + <include refid="QUERY_WHERE_CLAUSE"/>
  113 + </select>
  114 +
  115 + <!-- 其它SQL语句 -->
  116 +
  117 +
  118 +</mapper>
0 119 \ No newline at end of file
... ...
dtms-dao/src/main/resources/sqlmap/dtms/DtmsMessage.xml 0 → 100644
  1 +++ a/dtms-dao/src/main/resources/sqlmap/dtms/DtmsMessage.xml
  1 +<?xml version="1.0" encoding="UTF-8" ?>
  2 +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  3 + "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  4 +<mapper namespace="com.b2c.dtms.dao.DtmsMessageDao">
  5 +
  6 + <!-- dtms_message 所有查询列 -->
  7 + <sql id="QUERY_COLUMN_LIST">
  8 + <![CDATA[id,biz_id AS bizId,delay_seconds as delaySeconds,runtime,topic,content,memo,create_time AS createTime,wait_retry_num AS waitRetryNum,version,call_url AS callUrl,confirm_url AS confirmUrl,tag AS tag,lock_status AS lockStatus,lock_time AS lockTime,status,type,latest_consume_log AS latestConsumeLog]]>
  9 + </sql>
  10 +
  11 + <!-- dtms_message 查询列来源表-->
  12 + <sql id="QUERY_FROM_TABLE"><![CDATA[FROM dtms_message]]></sql>
  13 +
  14 + <!-- 全部条件(更多功能可以通过queryData扩展实现) -->
  15 + <sql id="QUERY_WHERE_CLAUSE">
  16 + <where>
  17 + <if test="id != null and id != ''"><![CDATA[AND id = #{id}]]></if>
  18 + <if test="bizId != null and bizId != ''"><![CDATA[AND biz_id = #{bizId}]]></if>
  19 + <if test="delaySeconds != null and delaySeconds != ''"><![CDATA[AND delay_seconds = #{delaySeconds}]]></if>
  20 + <if test="runtime != null and runtime != ''"><![CDATA[AND runtime = #{runtime}]]></if>
  21 + <if test="topic != null and topic != ''"><![CDATA[AND topic = #{topic}]]></if>
  22 + <if test="content != null and content != ''"><![CDATA[AND content = #{content}]]></if>
  23 + <if test="memo != null and memo != ''"><![CDATA[AND memo = #{memo}]]></if>
  24 + <if test="createTime != null and createTime != ''"><![CDATA[AND create_time = #{createTime}]]></if>
  25 + <if test="waitRetryNum != null and waitRetryNum != ''"><![CDATA[AND wait_retry_num = #{waitRetryNum}]]></if>
  26 + <if test="callUrl != null and callUrl != ''"><![CDATA[AND call_url = #{callUrl}]]></if>
  27 + <if test="confirmUrl != null and confirmUrl != ''"><![CDATA[AND confirm_url = #{confirmUrl}]]></if>
  28 + <if test="version != null"><![CDATA[AND version = #{version}]]></if>
  29 + <if test="lockStatus != null and lockStatus != ''"><![CDATA[AND lock_status = #{lockStatus}]]></if>
  30 + <if test="lockTime != null and lockTime != ''"><![CDATA[AND lock_time = #{lockTime}]]></if>
  31 + <if test="status != null and status != ''"><![CDATA[AND status = #{status}]]></if>
  32 + <if test="type != null and type != ''"><![CDATA[AND type = #{type}]]></if>
  33 + <choose>
  34 + <when test="tag != null and tag != ''">
  35 + <![CDATA[AND tag = #{tag}]]>
  36 + </when>
  37 + <otherwise>
  38 + <if test="queryData != null and queryData != '' and queryData.tags!=null and queryData.tags.size>0">
  39 + <![CDATA[ AND tag in ]]>
  40 + <foreach item="item" index="index" collection="queryData.tags" open="(" separator="," close=")">
  41 + #{item}
  42 + </foreach>
  43 + </if>
  44 + </otherwise>
  45 + </choose>
  46 + </where>
  47 + </sql>
  48 +
  49 + <!-- 智能排序与分页 -->
  50 + <sql id="QUERY_ORDER_LIMIT_CONDTION">
  51 + <if test="orderField != null and orderField != '' and orderFieldType != null and orderFieldType != ''"><![CDATA[ORDER BY ${orderField} ${orderFieldType}]]></if>
  52 + <if test="startIndex != null and startIndex &gt;= 0 and pageSize != null and pageSize &gt; 0"><![CDATA[LIMIT #{startIndex},#{pageSize}]]></if>
  53 + </sql>
  54 +
  55 + <!-- 更新列字段,只要不为NULL则更新,除开主键列 -->
  56 + <sql id="UPDATE_COLUMN_SET">
  57 + <set>
  58 + <if test="bizId != null"><![CDATA[biz_id = #{bizId},]]></if>
  59 + <if test="delaySeconds != null"><![CDATA[delay_seconds = #{delaySeconds},]]></if>
  60 + <if test="runtime != null"><![CDATA[runtime = #{runtime},]]></if>
  61 + <if test="topic != null"><![CDATA[topic = #{topic},]]></if>
  62 + <if test="content != null"><![CDATA[content = #{content},]]></if>
  63 + <if test="memo != null"><![CDATA[memo = #{memo},]]></if>
  64 + <if test="createTime != null"><![CDATA[create_time = #{createTime},]]></if>
  65 + <if test="waitRetryNum != null"><![CDATA[wait_retry_num = #{waitRetryNum},]]></if>
  66 + <if test="version != null"><![CDATA[version = #{version},]]></if>
  67 + <if test="callUrl != null"><![CDATA[call_url = #{callUrl},]]></if>
  68 + <if test="confirmUrl != null"><![CDATA[confirm_url = #{confirmUrl},]]></if>
  69 + <if test="tag != null"><![CDATA[tag = #{tag},]]></if>
  70 + <if test="lockStatus != null"><![CDATA[lock_status = #{lockStatus},]]></if>
  71 + <if test="type != null"><![CDATA[type = #{type},]]></if>
  72 + <if test="latestConsumeLog != null"><![CDATA[latest_consume_log = #{latestConsumeLog},]]></if>
  73 + <choose>
  74 + <when test="queryData != null and queryData.ignoreLockTimeNullCheck=='true'">
  75 + <![CDATA[lock_time = #{lockTime},]]>
  76 + </when>
  77 + <otherwise>
  78 + <if test="lockTime != null"><![CDATA[lock_time = #{lockTime},]]></if>
  79 + </otherwise>
  80 + </choose>
  81 + <if test="status != null"><![CDATA[status = #{status},]]></if>
  82 + <![CDATA[version = version + 1,]]>
  83 + </set>
  84 + </sql>
  85 +
  86 + <!-- 插入dtms_message记录 -->
  87 + <insert id="insertEntry" parameterType="dtmsMessage" >
  88 + <![CDATA[
  89 + INSERT INTO dtms_message (id,biz_id,delay_seconds,runtime,topic,content,memo,create_time,wait_retry_num,version,call_url,confirm_url,tag,lock_status,lock_time,status,type,latest_consume_log)
  90 + VALUES (#{id},#{bizId},#{delaySeconds},#{runtime},#{topic},#{content},#{memo},#{createTime},#{waitRetryNum},#{version},#{callUrl},#{confirmUrl},#{tag},0,#{lockTime},#{status},#{type},#{latestConsumeLog})
  91 + ]]>
  92 + </insert>
  93 +
  94 + <!-- 返回插入的编号,在事务开启状态下有效 -->
  95 + <select id="lastSequence" resultType="int"><![CDATA[SELECT LAST_INSERT_ID() AS id]]></select>
  96 +
  97 + <!-- 删除记录,主键IN(array) -->
  98 + <delete id="deleteByArrayKey" parameterType="java.lang.reflect.Array" >
  99 + <![CDATA[DELETE FROM dtms_message WHERE id IN]]>
  100 + <foreach collection="array" item="id" open="(" separator="," close=")">
  101 + <![CDATA[#{id}]]>
  102 + </foreach>
  103 + </delete>
  104 +
  105 + <!-- 删除,通过条件 -->
  106 + <update id="deleteByCondtion" parameterType="dtmsMessage" >
  107 + <![CDATA[DELETE FROM dtms_message]]>
  108 + <include refid="QUERY_WHERE_CLAUSE"/>
  109 + </update>
  110 +
  111 + <!-- 修改记录通过主键 -->
  112 + <update id="updateByKey" parameterType="dtmsMessage" >
  113 + <![CDATA[UPDATE dtms_message]]>
  114 + <include refid="UPDATE_COLUMN_SET"/>
  115 + <where>
  116 + <if test="id != null"><![CDATA[AND id = #{id}]]></if>
  117 + <if test="queryData != null and queryData.ignoreVersion!='true'">
  118 + AND version =#{version}
  119 + </if>
  120 + </where>
  121 + </update>
  122 +
  123 + <update id="updateByCondtion" parameterType="dtmsMessage" >
  124 + <![CDATA[UPDATE dtms_message]]>
  125 + <include refid="UPDATE_COLUMN_SET"/>
  126 + <where>
  127 + <if test="queryData != null and queryData != ''">
  128 + <if test="queryData.id!=null"><![CDATA[AND id = #{queryData.id}]]></if>
  129 + <if test="queryData.bizId != null"><![CDATA[AND biz_id = #{queryData.bizId}]]></if>
  130 + <if test="queryData.delaySeconds != null"><![CDATA[AND delay_seconds = #{queryData.delaySeconds}]]></if>
  131 + <if test="queryData.runtime != null"><![CDATA[AND runtime = #{queryData.runtime}]]></if>
  132 + <if test="queryData.topic != null"><![CDATA[AND a.topic <= #{queryData.topic}]]></if>
  133 + <if test="queryData.content != null"><![CDATA[AND content = #{queryData.content}]]></if>
  134 + <if test="queryData.memo != null"><![CDATA[AND memo = #{queryData.memo}]]></if>
  135 + <if test="queryData.createTime != null"><![CDATA[AND create_time = #{queryData.createTime}]]></if>
  136 + <if test="queryData.waitRetryNum != null"><![CDATA[AND wait_retry_num = #{queryData.waitRetryNum}]]></if>
  137 + <if test="queryData.callUrl != null"><![CDATA[AND call_url = #{queryData.callUrl}]]></if>
  138 + <if test="queryData.confirmUrl != null"><![CDATA[AND confirm_url = #{queryData.confirmUrl}]]></if>
  139 + <if test="queryData.version != null"><![CDATA[AND version = #{queryData.version}]]></if>
  140 + <if test="queryData.lockStatus != null"><![CDATA[AND lock_status = #{queryData.lockStatus}]]></if>
  141 + <if test="queryData.lockTime != null"><![CDATA[AND lock_time = #{queryData.lockTime}]]></if>
  142 + <if test="queryData.status != null"><![CDATA[AND status = #{queryData.status}]]></if>
  143 + <if test="queryData.tag != null"><![CDATA[AND tag = #{queryData.tag}]]></if>
  144 + <if test="queryData.type != null"><![CDATA[AND type = #{queryData.type}]]></if>
  145 + <if test="queryData.idList!=null and queryData.idList.size>0">
  146 + <![CDATA[ AND id in ]]>
  147 + <foreach item="item" index="index" collection="queryData.idList" open="(" separator="," close=")">
  148 + #{item}
  149 + </foreach>
  150 + </if>
  151 + </if>
  152 + </where>
  153 + </update>
  154 +
  155 + <!-- 查询,通过主键IN(array) -->
  156 + <select id="selectEntryArray" parameterType="java.lang.reflect.Array" resultType="dtmsMessage">
  157 + <![CDATA[SELECT]]>
  158 + <include refid="QUERY_COLUMN_LIST"/>
  159 + <include refid="QUERY_FROM_TABLE"/>
  160 + <![CDATA[WHERE id IN]]>
  161 + <foreach collection="array" item="id" open="(" separator="," close=")">
  162 + <![CDATA[#{id}]]>
  163 + </foreach>
  164 + </select>
  165 +
  166 + <!-- 查询,通过条件 -->
  167 + <select id="selectEntryList" parameterType="dtmsMessage" resultType="dtmsMessage">
  168 + <![CDATA[SELECT]]>
  169 + <include refid="QUERY_COLUMN_LIST"/>
  170 + <include refid="QUERY_FROM_TABLE"/>
  171 + <include refid="QUERY_WHERE_CLAUSE"/>
  172 + <include refid="QUERY_ORDER_LIMIT_CONDTION"/>
  173 + </select>
  174 +
  175 + <!-- 总数查询,通过条件 -->
  176 + <select id="selectEntryListCount" parameterType="dtmsMessage" resultType="int">
  177 + <![CDATA[SELECT COUNT(id) AS dataCount]]>
  178 + <include refid="QUERY_FROM_TABLE"/>
  179 + <include refid="QUERY_WHERE_CLAUSE"/>
  180 + </select>
  181 +
  182 + <!-- 其它SQL语句 -->
  183 + <!--
  184 + 查询场景:
  185 + 1 非定时任务未经过二次确认,且运行时间未到达时,不能被执行
  186 + 2 非定时任务经过二次确认,忽略运行时间,可以直接被执行
  187 + 3 定时任务,无论是否经过二次确认,都需要等待运行时间到达时才能被运行
  188 + -->
  189 + <select id="getListUnLockedBeforeSepcTime" parameterType="dtmsMessage" resultType="dtmsMessage">
  190 + <![CDATA[SELECT distinct]]>
  191 + <include refid="QUERY_COLUMN_LIST"/>
  192 + <include refid="QUERY_FROM_TABLE"/>
  193 + <where>
  194 + <![CDATA[AND lock_status =0]]>
  195 + <![CDATA[AND lock_time is null]]>
  196 + <![CDATA[AND ((status=10 and runtime<= #{runtime} and type=1) or
  197 + (status=20 and type=1) or
  198 + (status in (10,20) and runtime<= #{runtime} and type in (2,3)))]]>
  199 + </where>
  200 + <![CDATA[LIMIT #{startIndex},#{endIndex}]]>
  201 + </select>
  202 +
  203 + <select id="getLockTimeOutList" parameterType="dtmsMessage" resultType="dtmsMessage">
  204 + SELECT a.id,
  205 + a.biz_id AS bizId,
  206 + a.topic,
  207 + a.version,
  208 + a.tag AS tag,
  209 + a.lock_status AS lockStatus,
  210 + a.lock_time AS lockTime
  211 + from dtms_message a ,dtms_message_config b
  212 + <where>
  213 + a.topic=b.msg_topic
  214 + <if test="lockStatus != null and lockStatus != ''"><![CDATA[AND a.lock_status=#{lockStatus}]]></if>
  215 + <if test="queryData != null and queryData != ''">
  216 + <if test="queryData.currentTime !=null">
  217 + <![CDATA[AND timediff(#{queryData.currentTime},a.lock_time) > b.lock_timeout]]>
  218 + </if>
  219 + </if>
  220 + </where>
  221 + <![CDATA[LIMIT #{startIndex},#{endIndex}]]>
  222 + </select>
  223 +
  224 +
  225 + <update id="tryAddLock" parameterType="dtmsMessage" >
  226 + <![CDATA[
  227 + update dtms_message
  228 + set lock_status =1,
  229 + lock_time=#{lockTime},
  230 + version = version + 1
  231 + where id=#{id} and version=#{version} and lock_status=0 and lock_time is null
  232 + ]]>
  233 + </update>
  234 +
  235 + <select id="selectLockedCount" parameterType="dtmsMessage" resultType="int">
  236 + <![CDATA[
  237 + select count(id) from dtms_message where id=#{id} and version=#{version} and lock_status=#{lockStatus} and lock_time=#{lockTime}
  238 + ]]>
  239 + </select>
  240 +
  241 + <update id="tryReleaseLock" parameterType="dtmsMessage" >
  242 + <![CDATA[
  243 + update dtms_message
  244 + set lock_status=0,
  245 + lock_time=null,
  246 + version = version + 1
  247 + where id=#{id} and version=#{version} and lock_status=#{lockStatus} and lock_time=#{lockTime}
  248 + ]]>
  249 + </update>
  250 +
  251 + <delete id="deleteByKeyAndVersion" parameterType="dtmsMessage" >
  252 + delete from dtms_message where id=#{id} and version=#{version}
  253 + </delete>
  254 +
  255 + <update id="reduceRetryCount" parameterType="dtmsMessage" >
  256 + <![CDATA[
  257 + update dtms_message
  258 + set wait_retry_num = #{waitRetryNum},
  259 + latest_consume_log = #{latestConsumeLog},
  260 + version = version + 1
  261 + where id=#{id} and version=#{version}
  262 + ]]>
  263 + </update>
  264 +
  265 + <update id="reduceRetryCountAndSetNextRuntime" parameterType="dtmsMessage" >
  266 + <![CDATA[
  267 + update dtms_message
  268 + set wait_retry_num = #{waitRetryNum},
  269 + runtime = #{runtime},
  270 + latest_consume_log = #{latestConsumeLog},
  271 + version = version + 1
  272 + where id=#{id} and version=#{version}
  273 + ]]>
  274 + </update>
  275 +
  276 +</mapper>
0 277 \ No newline at end of file
... ...
dtms-dao/src/main/resources/sqlmap/dtms/DtmsMessageConfig.xml 0 → 100644
  1 +++ a/dtms-dao/src/main/resources/sqlmap/dtms/DtmsMessageConfig.xml
  1 +<?xml version="1.0" encoding="UTF-8" ?>
  2 +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  3 + "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  4 +<mapper namespace="com.b2c.dtms.dao.DtmsMessageConfigDao">
  5 +
  6 + <!-- dtms_message_config 所有查询列 -->
  7 + <sql id="QUERY_COLUMN_LIST">
  8 + <![CDATA[id,msg_topic AS msgTopic,handler_type AS handlerType,handler,status,retry_step AS retryStep,retry_step_unit AS retryStepUnit,lock_timeout AS lockTimeout,memo]]>
  9 + </sql>
  10 +
  11 + <!-- dtms_message_config 查询列来源表-->
  12 + <sql id="QUERY_FROM_TABLE"><![CDATA[FROM dtms_message_config]]></sql>
  13 +
  14 + <!-- 全部条件(更多功能可以通过queryData扩展实现) -->
  15 + <sql id="QUERY_WHERE_CLAUSE">
  16 + <where>
  17 + <if test="id != null and id != ''"><![CDATA[AND id = #{id}]]></if>
  18 + <if test="msgTopic != null and msgTopic != ''"><![CDATA[AND msg_topic = #{msgTopic}]]></if>
  19 + <if test="handlerType != null and handlerType != ''"><![CDATA[AND handler_type = #{handlerType}]]></if>
  20 + <if test="handler != null and handler != ''"><![CDATA[AND handler = #{handler}]]></if>
  21 + <if test="status != null and status != ''"><![CDATA[AND status = #{status}]]></if>
  22 + <if test="retryStep != null and retryStep != ''"><![CDATA[AND retry_step = #{retryStep}]]></if>
  23 + <if test="retryStepUnit != null and retryStepUnit != ''"><![CDATA[AND retry_step_unit = #{retryStepUnit}]]></if>
  24 + <if test="lockTimeout != null and lockTimeout != ''"><![CDATA[AND lock_timeout = #{lockTimeout}]]></if>
  25 + <if test="memo != null and memo != ''"><![CDATA[AND memo = #{memo}]]></if>
  26 + </where>
  27 + </sql>
  28 +
  29 + <!-- 智能排序与分页 -->
  30 + <sql id="QUERY_ORDER_LIMIT_CONDTION">
  31 + <if test="orderField != null and orderField != '' and orderFieldType != null and orderFieldType != ''"><![CDATA[ORDER BY ${orderField} ${orderFieldType}]]></if>
  32 + <if test="startIndex != null and startIndex &gt;= 0 and pageSize != null and pageSize &gt; 0"><![CDATA[LIMIT #{startIndex},#{pageSize}]]></if>
  33 + </sql>
  34 +
  35 + <!-- 更新列字段,只要不为NULL则更新,除开主键列 -->
  36 + <sql id="UPDATE_COLUMN_SET">
  37 + <set>
  38 + <if test="msgTopic != null"><![CDATA[msg_topic = #{msgTopic},]]></if>
  39 + <if test="handlerType != null"><![CDATA[handler_type = #{handlerType},]]></if>
  40 + <if test="handler != null"><![CDATA[handler = #{handler},]]></if>
  41 + <if test="status != null"><![CDATA[status = #{status},]]></if>
  42 + <if test="retryStep != null"><![CDATA[retry_step = #{retryStep},]]></if>
  43 + <if test="retryStepUnit != null"><![CDATA[retry_step_unit = #{retryStepUnit},]]></if>
  44 + <if test="lockTimeout != null"><![CDATA[lock_timeout = #{lockTimeout},]]></if>
  45 + <if test="memo != null"><![CDATA[memo = #{memo},]]></if>
  46 + </set>
  47 + </sql>
  48 +
  49 + <!-- 插入dtms_message_config记录 -->
  50 + <insert id="insertEntry" parameterType="dtmsMessageConfig" >
  51 + <![CDATA[
  52 + INSERT INTO dtms_message_config (id,msg_topic,handler_type,handler,status,retry_step,retry_step_unit,lock_timeout,memo)
  53 + VALUES (#{id},#{msgTopic},#{handlerType},#{handler},#{status},#{retryStep},#{retryStepUnit},#{lockTimeout},#{memo)
  54 + ]]>
  55 + </insert>
  56 +
  57 + <!-- 返回插入的编号,在事务开启状态下有效 -->
  58 + <select id="lastSequence" resultType="int"><![CDATA[SELECT LAST_INSERT_ID() AS id]]></select>
  59 +
  60 + <!-- 删除记录,主键IN(array) -->
  61 + <delete id="deleteByArrayKey" parameterType="java.lang.reflect.Array" >
  62 + <![CDATA[DELETE FROM dtms_message_config WHERE id IN]]>
  63 + <foreach collection="array" item="id" open="(" separator="," close=")">
  64 + <![CDATA[#{id}]]>
  65 + </foreach>
  66 + </delete>
  67 +
  68 + <!-- 删除,通过条件 -->
  69 + <update id="deleteByCondtion" parameterType="dtmsMessageConfig" >
  70 + <![CDATA[DELETE FROM dtms_message_config]]>
  71 + <include refid="QUERY_WHERE_CLAUSE"/>
  72 + </update>
  73 +
  74 + <!-- 修改记录通过主键 -->
  75 + <update id="updateByKey" parameterType="dtmsMessageConfig" >
  76 + <![CDATA[UPDATE dtms_message_config]]>
  77 + <include refid="UPDATE_COLUMN_SET"/>
  78 + <![CDATA[WHERE id = #{id}]]>
  79 + </update>
  80 +
  81 + <!-- 查询,通过主键IN(array) -->
  82 + <select id="selectEntryArray" parameterType="java.lang.reflect.Array" resultType="dtmsMessageConfig">
  83 + <![CDATA[SELECT]]>
  84 + <include refid="QUERY_COLUMN_LIST"/>
  85 + <include refid="QUERY_FROM_TABLE"/>
  86 + <![CDATA[WHERE id IN]]>
  87 + <foreach collection="array" item="id" open="(" separator="," close=")">
  88 + <![CDATA[#{id}]]>
  89 + </foreach>
  90 + </select>
  91 +
  92 + <!-- 查询,通过条件 -->
  93 + <select id="selectEntryList" parameterType="dtmsMessageConfig" resultType="dtmsMessageConfig">
  94 + <![CDATA[SELECT]]>
  95 + <include refid="QUERY_COLUMN_LIST"/>
  96 + <include refid="QUERY_FROM_TABLE"/>
  97 + <include refid="QUERY_WHERE_CLAUSE"/>
  98 + <include refid="QUERY_ORDER_LIMIT_CONDTION"/>
  99 + </select>
  100 +
  101 + <!-- 总数查询,通过条件 -->
  102 + <select id="selectEntryListCount" parameterType="dtmsMessageConfig" resultType="int">
  103 + <![CDATA[SELECT COUNT(id) AS dataCount]]>
  104 + <include refid="QUERY_FROM_TABLE"/>
  105 + <include refid="QUERY_WHERE_CLAUSE"/>
  106 + </select>
  107 +
  108 + <!-- 其它SQL语句 -->
  109 +
  110 +
  111 +</mapper>
0 112 \ No newline at end of file
... ...
dtms-dao/src/main/resources/sqlmap/dtms/DtmsMessageException.xml 0 → 100644
  1 +++ a/dtms-dao/src/main/resources/sqlmap/dtms/DtmsMessageException.xml
  1 +<?xml version="1.0" encoding="UTF-8" ?>
  2 +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  3 + "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  4 +<mapper namespace="com.b2c.dtms.dao.DtmsMessageExceptionDao">
  5 +
  6 + <!-- dtms_message_exception 所有查询列 -->
  7 + <sql id="QUERY_COLUMN_LIST">
  8 + <![CDATA[id,
  9 + msg_id AS msgId,
  10 + biz_id AS bizId,
  11 + status,
  12 + topic,
  13 + content,
  14 + memo,
  15 + create_time AS createTime,
  16 + exception_time AS exceptionTime,
  17 + exception_memo AS exceptionMemo,
  18 + latest_consume_log AS latestConsumeLog,
  19 + process_user_id AS processUserId,
  20 + process_user_name AS processUserName,
  21 + process_memo AS processMemo,
  22 + process_time AS processTime]]>
  23 + </sql>
  24 +
  25 + <!-- dtms_message_exception 查询列来源表-->
  26 + <sql id="QUERY_FROM_TABLE"><![CDATA[FROM dtms_message_exception]]></sql>
  27 +
  28 + <!-- 全部条件(更多功能可以通过queryData扩展实现) -->
  29 + <sql id="QUERY_WHERE_CLAUSE">
  30 + <where>
  31 + <if test="id != null and id != ''"><![CDATA[AND id = #{id}]]></if>
  32 + <if test="msgId != null and msgId != ''"><![CDATA[AND msg_id = #{msgId}]]></if>
  33 + <if test="bizId != null and bizId != ''"><![CDATA[AND biz_id = #{bizId}]]></if>
  34 + <if test="status != null and status != ''"><![CDATA[AND status = #{status}]]></if>
  35 + <if test="topic != null and topic != ''"><![CDATA[AND topic = #{topic}]]></if>
  36 + <if test="content != null and content != ''"><![CDATA[AND content = #{content}]]></if>
  37 + <if test="memo != null and memo != ''"><![CDATA[AND memo = #{memo}]]></if>
  38 + <if test="createTime != null and createTime != ''"><![CDATA[AND create_time = #{createTime}]]></if>
  39 + <if test="exceptionTime != null and exceptionTime != ''"><![CDATA[AND exception_time = #{exceptionTime}]]></if>
  40 + <if test="exceptionMemo != null and exceptionMemo != ''"><![CDATA[AND exception_memo = #{exceptionMemo}]]></if>
  41 + <if test="processUserId != null and processUserId != ''"><![CDATA[AND process_user_id = #{processUserId}]]></if>
  42 + <if test="processUserName != null and processUserName != ''"><![CDATA[AND process_user_name = #{processUserName}]]></if>
  43 + <if test="processMemo != null and processMemo != ''"><![CDATA[AND process_memo = #{processMemo}]]></if>
  44 + <if test="processTime != null and processTime != ''"><![CDATA[AND process_time = #{processTime}]]></if>
  45 + </where>
  46 + </sql>
  47 +
  48 + <!-- 智能排序与分页 -->
  49 + <sql id="QUERY_ORDER_LIMIT_CONDTION">
  50 + <if test="orderField != null and orderField != '' and orderFieldType != null and orderFieldType != ''"><![CDATA[ORDER BY ${orderField} ${orderFieldType}]]></if>
  51 + <if test="startIndex != null and startIndex &gt;= 0 and pageSize != null and pageSize &gt; 0"><![CDATA[LIMIT #{startIndex},#{pageSize}]]></if>
  52 + </sql>
  53 +
  54 + <!-- 更新列字段,只要不为NULL则更新,除开主键列 -->
  55 + <sql id="UPDATE_COLUMN_SET">
  56 + <set>
  57 + <if test="msgId != null"><![CDATA[msg_id = #{msgId},]]></if>
  58 + <if test="bizId != null"><![CDATA[biz_id = #{bizId},]]></if>
  59 + <if test="status != null"><![CDATA[status = #{status},]]></if>
  60 + <if test="topic != null"><![CDATA[topic = #{topic},]]></if>
  61 + <if test="content != null"><![CDATA[content = #{content},]]></if>
  62 + <if test="memo != null"><![CDATA[memo = #{memo},]]></if>
  63 + <if test="createTime != null"><![CDATA[create_time = #{createTime},]]></if>
  64 + <if test="exceptionTime != null"><![CDATA[exception_time = #{exceptionTime},]]></if>
  65 + <if test="exceptionMemo != null"><![CDATA[exception_memo = #{exceptionMemo},]]></if>
  66 + <if test="latestConsumeLog != null"><![CDATA[latest_consume_log = #{latestConsumeLog},]]></if>
  67 + <if test="processUserId != null"><![CDATA[process_user_id = #{processUserId},]]></if>
  68 + <if test="processUserName != null"><![CDATA[process_user_name = #{processUserName},]]></if>
  69 + <if test="processMemo != null"><![CDATA[process_memo = #{processMemo},]]></if>
  70 + <if test="processTime != null"><![CDATA[process_time = #{processTime},]]></if>
  71 +
  72 + </set>
  73 + </sql>
  74 +
  75 + <!-- 插入dtms_message_exception记录 -->
  76 + <insert id="insertEntry" parameterType="dtmsMessageException" >
  77 + <![CDATA[
  78 + INSERT INTO dtms_message_exception (id,msg_id,biz_id,status,topic,content,memo,create_time,exception_time,exception_memo,latest_consume_log,process_user_id,process_user_name,process_memo,process_time)
  79 + VALUES (#{id},#{msgId},#{bizId},#{status},#{topic},#{content},#{memo},#{createTime},#{exceptionTime},#{exceptionMemo},#{latestConsumeLog},#{processUserId},#{processUserName},#{processMemo},#{processTime})
  80 + ]]>
  81 + </insert>
  82 +
  83 + <!-- 返回插入的编号,在事务开启状态下有效 -->
  84 + <select id="lastSequence" resultType="int"><![CDATA[SELECT LAST_INSERT_ID() AS id]]></select>
  85 +
  86 + <!-- 删除记录,主键IN(array) -->
  87 + <delete id="deleteByArrayKey" parameterType="java.lang.reflect.Array" >
  88 + <![CDATA[DELETE FROM dtms_message_exception WHERE id IN]]>
  89 + <foreach collection="array" item="id" open="(" separator="," close=")">
  90 + <![CDATA[#{id}]]>
  91 + </foreach>
  92 + </delete>
  93 +
  94 + <!-- 删除,通过条件 -->
  95 + <update id="deleteByCondtion" parameterType="dtmsMessageException" >
  96 + <![CDATA[DELETE FROM dtms_message_exception]]>
  97 + <include refid="QUERY_WHERE_CLAUSE"/>
  98 + </update>
  99 +
  100 + <!-- 修改记录通过主键 -->
  101 + <update id="updateByKey" parameterType="dtmsMessageException" >
  102 + <![CDATA[UPDATE dtms_message_exception]]>
  103 + <include refid="UPDATE_COLUMN_SET"/>
  104 + <![CDATA[WHERE id = #{id}]]>
  105 + </update>
  106 +
  107 + <!-- 查询,通过主键IN(array) -->
  108 + <select id="selectEntryArray" parameterType="java.lang.reflect.Array" resultType="dtmsMessageException">
  109 + <![CDATA[SELECT]]>
  110 + <include refid="QUERY_COLUMN_LIST"/>
  111 + <include refid="QUERY_FROM_TABLE"/>
  112 + <![CDATA[WHERE id IN]]>
  113 + <foreach collection="array" item="id" open="(" separator="," close=")">
  114 + <![CDATA[#{id}]]>
  115 + </foreach>
  116 + </select>
  117 +
  118 + <!-- 查询,通过条件 -->
  119 + <select id="selectEntryList" parameterType="dtmsMessageException" resultType="dtmsMessageException">
  120 + <![CDATA[SELECT]]>
  121 + <include refid="QUERY_COLUMN_LIST"/>
  122 + <include refid="QUERY_FROM_TABLE"/>
  123 + <include refid="QUERY_WHERE_CLAUSE"/>
  124 + <include refid="QUERY_ORDER_LIMIT_CONDTION"/>
  125 + </select>
  126 +
  127 + <!-- 总数查询,通过条件 -->
  128 + <select id="selectEntryListCount" parameterType="dtmsMessageException" resultType="int">
  129 + <![CDATA[SELECT COUNT(id) AS dataCount]]>
  130 + <include refid="QUERY_FROM_TABLE"/>
  131 + <include refid="QUERY_WHERE_CLAUSE"/>
  132 + </select>
  133 +
  134 + <!-- 其它SQL语句 -->
  135 +
  136 +
  137 +</mapper>
0 138 \ No newline at end of file
... ...
dtms-dao/src/main/resources/sqlmap/dtms/DtmsMessageHistory.xml 0 → 100644
  1 +++ a/dtms-dao/src/main/resources/sqlmap/dtms/DtmsMessageHistory.xml
  1 +<?xml version="1.0" encoding="UTF-8" ?>
  2 +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  3 + "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  4 +<mapper namespace="com.b2c.dtms.dao.DtmsMessageHistoryDao">
  5 +
  6 + <!-- dtms_message_history 所有查询列 -->
  7 + <sql id="QUERY_COLUMN_LIST">
  8 + <![CDATA[id,msg_id AS msgId,biz_id AS bizId,delay_seconds as delaySeconds,runtime,topic,content,memo,create_time AS createTime,wait_retry_num AS waitRetryNum,version,call_url AS callUrl,confirm_url AS confirmUrl,tag AS tag,history_time AS historyTime,history_memo AS historyMemo,lock_status AS lockStatus,lock_time AS lockTime,status,type,latest_consume_log AS latestConsumeLog]]>
  9 + </sql>
  10 +
  11 + <!-- dtms_message_history 查询列来源表-->
  12 + <sql id="QUERY_FROM_TABLE"><![CDATA[FROM dtms_message_history]]></sql>
  13 +
  14 + <!-- 全部条件(更多功能可以通过queryData扩展实现) -->
  15 + <sql id="QUERY_WHERE_CLAUSE">
  16 + <where>
  17 + <if test="id != null and id != ''"><![CDATA[AND id = #{id}]]></if>
  18 + <if test="msgId != null and msgId != ''"><![CDATA[AND msg_id = #{msgId}]]></if>
  19 + <if test="bizId != null and bizId != ''"><![CDATA[AND biz_id = #{bizId}]]></if>
  20 + <if test="delaySeconds != null and delaySeconds != ''"><![CDATA[AND delay_seconds = #{delaySeconds}]]></if>
  21 + <if test="runtime != null and runtime != ''"><![CDATA[AND runtime = #{runtime}]]></if>
  22 + <if test="topic != null and topic != ''"><![CDATA[AND topic = #{topic}]]></if>
  23 + <if test="content != null and content != ''"><![CDATA[AND content = #{content}]]></if>
  24 + <if test="memo != null and memo != ''"><![CDATA[AND memo = #{memo}]]></if>
  25 + <if test="createTime != null and createTime != ''"><![CDATA[AND create_time = #{createTime}]]></if>
  26 + <if test="waitRetryNum != null and waitRetryNum != ''"><![CDATA[AND wait_retry_num = #{waitRetryNum}]]></if>
  27 + <if test="version != null and version != ''"><![CDATA[AND version = #{version}]]></if>
  28 + <if test="callUrl != null and callUrl != ''"><![CDATA[AND call_url = #{callUrl}]]></if>
  29 + <if test="confirmUrl != null and confirmUrl != ''"><![CDATA[AND confirm_url = #{confirmUrl}]]></if>
  30 + <if test="tag != null and tag != ''"><![CDATA[AND tag = #{tag}]]></if>
  31 + <if test="historyTime != null and historyTime != ''"><![CDATA[AND history_time = #{historyTime}]]></if>
  32 + <if test="historyMemo != null and historyMemo != ''"><![CDATA[AND history_memo = #{historyMemo}]]></if>
  33 + <if test="lockStatus != null and lockStatus != ''"><![CDATA[AND lock_status = #{lockStatus}]]></if>
  34 + <if test="lockTtime != null and lockTtime != ''"><![CDATA[AND lock_time = #{lockTtime}]]></if>
  35 + <if test="status != null and status != ''"><![CDATA[AND status = #{status}]]></if>
  36 + <if test="type != null and type != ''"><![CDATA[AND type = #{type}]]></if>
  37 + </where>
  38 + </sql>
  39 +
  40 + <!-- 智能排序与分页 -->
  41 + <sql id="QUERY_ORDER_LIMIT_CONDTION">
  42 + <if test="orderField != null and orderField != '' and orderFieldType != null and orderFieldType != ''"><![CDATA[ORDER BY ${orderField} ${orderFieldType}]]></if>
  43 + <if test="startIndex != null and startIndex &gt;= 0 and pageSize != null and pageSize &gt; 0"><![CDATA[LIMIT #{startIndex},#{pageSize}]]></if>
  44 + </sql>
  45 +
  46 + <!-- 更新列字段,只要不为NULL则更新,除开主键列 -->
  47 + <sql id="UPDATE_COLUMN_SET">
  48 + <set>
  49 + <if test="msgId != null"><![CDATA[msg_id = #{msgId},]]></if>
  50 + <if test="bizId != null"><![CDATA[biz_id = #{bizId},]]></if>
  51 + <if test="delaySeconds != null"><![CDATA[delay_seconds = #{delaySeconds},]]></if>
  52 + <if test="runtime != null"><![CDATA[runtime = #{runtime},]]></if>
  53 + <if test="topic != null"><![CDATA[topic = #{topic},]]></if>
  54 + <if test="content != null"><![CDATA[content = #{content},]]></if>
  55 + <if test="memo != null"><![CDATA[memo = #{memo},]]></if>
  56 + <if test="createTime != null"><![CDATA[create_time = #{createTime},]]></if>
  57 + <if test="waitRetryNum != null"><![CDATA[wait_retry_num = #{waitRetryNum},]]></if>
  58 + <if test="version != null"><![CDATA[version = #{version},]]></if>
  59 + <if test="callUrl != null"><![CDATA[call_url = #{callUrl},]]></if>
  60 + <if test="confirmUrl != null"><![CDATA[confirm_url = #{confirmUrl},]]></if>
  61 + <if test="tag != null"><![CDATA[tag = #{tag},]]></if>
  62 + <if test="historyTime != null"><![CDATA[history_time = #{historyTime},]]></if>
  63 + <if test="historyMemo != null"><![CDATA[history_memo = #{historyMemo},]]></if>
  64 + <if test="lockStatus != null"><![CDATA[lock_status = #{lockStatus},]]></if>
  65 + <if test="lockTime != null"><![CDATA[lock_time = #{lockTime},]]></if>
  66 + <if test="status != null"><![CDATA[status = #{status},]]></if>
  67 + <if test="type != null"><![CDATA[type = #{type},]]></if>
  68 + <if test="latestConsumeLog != null"><![CDATA[latest_consume_log = #{latestConsumeLog},]]></if>
  69 + </set>
  70 + </sql>
  71 +
  72 + <!-- 插入dtms_message_history记录 -->
  73 + <insert id="insertEntry" parameterType="dtmsMessageHistory" >
  74 + <![CDATA[
  75 + INSERT INTO dtms_message_history (id,msg_id,biz_id,delay_seconds,runtime,topic,content,memo,create_time,wait_retry_num,version,call_url,confirm_url,tag,history_time,history_memo,lock_status,lock_time,status,type,latest_consume_log)
  76 + VALUES (#{id},#{msgId},#{bizId},#{delaySeconds},#{runtime},#{topic},#{content},#{memo},#{createTime},#{waitRetryNum},#{version},#{callUrl},#{confirmUrl},#{tag},#{historyTime},#{historyMemo},#{lockStatus},#{lockTime},#{status},#{type},#{latestConsumeLog})
  77 + ]]>
  78 + </insert>
  79 +
  80 + <!-- 返回插入的编号,在事务开启状态下有效 -->
  81 + <select id="lastSequence" resultType="int"><![CDATA[SELECT LAST_INSERT_ID() AS id]]></select>
  82 +
  83 + <!-- 删除记录,主键IN(array) -->
  84 + <delete id="deleteByArrayKey" parameterType="java.lang.reflect.Array" >
  85 + <![CDATA[DELETE FROM dtms_message_history WHERE id IN]]>
  86 + <foreach collection="array" item="id" open="(" separator="," close=")">
  87 + <![CDATA[#{id}]]>
  88 + </foreach>
  89 + </delete>
  90 +
  91 + <!-- 删除,通过条件 -->
  92 + <update id="deleteByCondtion" parameterType="dtmsMessageHistory" >
  93 + <![CDATA[DELETE FROM dtms_message_history]]>
  94 + <include refid="QUERY_WHERE_CLAUSE"/>
  95 + </update>
  96 +
  97 + <!-- 修改记录通过主键 -->
  98 + <update id="updateByKey" parameterType="dtmsMessageHistory" >
  99 + <![CDATA[UPDATE dtms_message_history]]>
  100 + <include refid="UPDATE_COLUMN_SET"/>
  101 + <![CDATA[WHERE id = #{id}]]>
  102 + </update>
  103 +
  104 + <!-- 查询,通过主键IN(array) -->
  105 + <select id="selectEntryArray" parameterType="java.lang.reflect.Array" resultType="dtmsMessageHistory">
  106 + <![CDATA[SELECT]]>
  107 + <include refid="QUERY_COLUMN_LIST"/>
  108 + <include refid="QUERY_FROM_TABLE"/>
  109 + <![CDATA[WHERE id IN]]>
  110 + <foreach collection="array" item="id" open="(" separator="," close=")">
  111 + <![CDATA[#{id}]]>
  112 + </foreach>
  113 + </select>
  114 +
  115 + <!-- 查询,通过条件 -->
  116 + <select id="selectEntryList" parameterType="dtmsMessageHistory" resultType="dtmsMessageHistory">
  117 + <![CDATA[SELECT]]>
  118 + <include refid="QUERY_COLUMN_LIST"/>
  119 + <include refid="QUERY_FROM_TABLE"/>
  120 + <include refid="QUERY_WHERE_CLAUSE"/>
  121 + <include refid="QUERY_ORDER_LIMIT_CONDTION"/>
  122 + </select>
  123 +
  124 + <!-- 总数查询,通过条件 -->
  125 + <select id="selectEntryListCount" parameterType="dtmsMessageHistory" resultType="int">
  126 + <![CDATA[SELECT COUNT(id) AS dataCount]]>
  127 + <include refid="QUERY_FROM_TABLE"/>
  128 + <include refid="QUERY_WHERE_CLAUSE"/>
  129 + </select>
  130 +
  131 + <!-- 其它SQL语句 -->
  132 +
  133 +
  134 +</mapper>
0 135 \ No newline at end of file
... ...
dtms-domain/pom.xml 0 → 100644
  1 +++ a/dtms-domain/pom.xml
  1 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  3 + <modelVersion>4.0.0</modelVersion>
  4 + <parent>
  5 + <groupId>com.b2c.dtms</groupId>
  6 + <artifactId>dtms-parent</artifactId>
  7 + <version>0.0.1-SNAPSHOT</version>
  8 + </parent>
  9 + <artifactId>dtms-domain</artifactId>
  10 +
  11 + <dependencies>
  12 + <dependency>
  13 + <groupId>org.springframework</groupId>
  14 + <artifactId>spring-webmvc</artifactId>
  15 + <exclusions>
  16 + <exclusion>
  17 + <groupId>commons-logging</groupId>
  18 + <artifactId>commons-logging</artifactId>
  19 + </exclusion>
  20 + </exclusions>
  21 + </dependency>
  22 + <!-- google sets,maps -->
  23 + <dependency>
  24 + <groupId>com.google.guava</groupId>
  25 + <artifactId>guava</artifactId>
  26 + </dependency>
  27 + <dependency>
  28 + <groupId>org.projectlombok</groupId>
  29 + <artifactId>lombok</artifactId>
  30 + </dependency>
  31 + <dependency>
  32 + <groupId>commons-lang</groupId>
  33 + <artifactId>commons-lang</artifactId>
  34 + </dependency>
  35 + <dependency>
  36 + <groupId>org.springframework.data</groupId>
  37 + <artifactId>spring-data-redis</artifactId>
  38 + </dependency>
  39 + <dependency>
  40 + <groupId>com.alibaba</groupId>
  41 + <artifactId>fastjson</artifactId>
  42 + </dependency>
  43 + <dependency>
  44 + <groupId>${project.groupId}</groupId>
  45 + <artifactId>dtms-client</artifactId>
  46 + <version>${project.version}</version>
  47 + </dependency>
  48 + </dependencies>
  49 +</project>
0 50 \ No newline at end of file
... ...
dtms-domain/src/main/java/com/b2c/dtms/common/CommonConstants.java 0 → 100644
  1 +++ a/dtms-domain/src/main/java/com/b2c/dtms/common/CommonConstants.java
  1 +package com.b2c.dtms.common;
  2 +
  3 +import java.util.Date;
  4 +
  5 +import com.b2c.dtms.common.tools.DateUtils;
  6 +
  7 +public class CommonConstants {
  8 +
  9 + public static final int COMMONS_ZERO_INT = 0;
  10 + public static final int COMMONS_ONE_INT = 1;
  11 + public static final String COMMONS_NINE_STR = "9";
  12 + public static final String COMMONS_FIVE_STR = "5";
  13 +
  14 + /**前端匿名会员ID*/
  15 + public static final long ANONYMOUS_WEB_USER_ID = 999L;
  16 +
  17 + /**系统用户*/
  18 + public static final long SYSTEM_USER_ID = 9999999999999L;
  19 +
  20 +
  21 + /**订单状态父节点ID*/
  22 + public static final String ORDER_STATUS_DICT_PID="DIC_ORDER_STATUS";
  23 +// /**工作流订单相关说明(描述/备注)关键字orderMemo*/
  24 + public static final String STATE_ORDER_MEMO_KEY="orderMemo";
  25 +
  26 + public static final String notSupportActionErrorMsg = "当前状态不支持本动作";
  27 + public static final String updateOrderErrorMsg = "未更新到表数据,操作失败或者数据有更新,请刷新数据重试!";
  28 + public static final String unSelectOrderErrorMsg = "未查到关联订单数据,请确认订单是否存在";
  29 + public static final String unPayActionOrderErrorMsg = "未支付订单不能执行本操作";
  30 + public static final String commonOperationFailure="操作失败或者数据已发生改变,请刷新重试!";
  31 + public static final String unSelectSettleBillErrorMsg = "未查到关联结算单数据,请确认结算单是否存在";
  32 + public static final String SETTLE_SOURCE_NO_SEPARATOR=",";
  33 + public static final String SUPPLY_ORDER_ID_SEPARATOR=",";
  34 + public static final String HOT_LINE_1 = "HOT_LINE_1";
  35 + public static final String LINE_SEPARATOR="-";
  36 + public static final String CACHE_KEY_SEPARATOR="_";
  37 +
  38 + public static final String CACHE_KEY_ORDERPRINTTEMPLETE="1n4j_orders" + CACHE_KEY_SEPARATOR +"orderPrintTemplete";
  39 +
  40 + /**系统本次启动日期时间*/
  41 + public static final Date SYSTEM_START_TIME = DateUtils.getCurrentDate();
  42 +
  43 + public static final String SuccTagKey="SuccTagKey";
  44 + public static final String FailTagKey="FailTagKey";
  45 +
  46 + public static final String DtmsSuccID="DtmsSuccID";
  47 + public static final String DtmsFailID="DtmsFailID";
  48 +
  49 + public static final String MARKET_CODE="1n4j_orders_market_code";
  50 +}
... ...
dtms-domain/src/main/java/com/b2c/dtms/common/CommonUtils.java 0 → 100644
  1 +++ a/dtms-domain/src/main/java/com/b2c/dtms/common/CommonUtils.java
  1 +package com.b2c.dtms.common;
  2 +
  3 +import org.springframework.web.context.ContextLoader;
  4 +import org.springframework.web.context.WebApplicationContext;
  5 +
  6 +import com.b2c.dtms.common.exception.*;
  7 +
  8 +public class CommonUtils {
  9 +
  10 + public static void throwAppException(boolean expect,String msg) throws AppException {
  11 + if (expect) {
  12 + throw new AppException(msg);
  13 + }
  14 + }
  15 +
  16 + public static void throwAppException(Exception e) throws AppException {
  17 + throw new AppException(e);
  18 + }
  19 + /**
  20 + * expect=true时抛出DataErrorException异常
  21 + * @param expect
  22 + * @param msg
  23 + */
  24 + public static void throwDataError(boolean expect, String msg) throws DataErrorException {
  25 + if (expect) {
  26 + throw new DataErrorException(msg);
  27 + }
  28 + }
  29 +
  30 + public static void throwDataError(boolean expect,String code,String data, String msg) throws DataErrorException {
  31 + if (expect) {
  32 + throw new DataErrorException(code,data,msg);
  33 + }
  34 + }
  35 +
  36 + /**
  37 + * expect=true时抛出NotAuthException异常
  38 + * @param expect
  39 + * @param msg
  40 + */
  41 + public static void throwNotAuth(boolean expect, String msg) throws NotAuthException {
  42 + if (expect) {
  43 + throw new NotAuthException(msg);
  44 + }
  45 + }
  46 +
  47 + /**
  48 + * expect=true时抛出ParamErrorException异常
  49 + * @param expect
  50 + * @param msg
  51 + */
  52 + public static void throwParamError(boolean expect, String msg) throws ParamErrorException {
  53 + if (expect) {
  54 + throw new ParamErrorException(msg);
  55 + }
  56 + }
  57 +
  58 + public static void throwParamError(boolean expect,String code,String data, String msg) throws ParamErrorException {
  59 + if (expect) {
  60 + throw new ParamErrorException(code,data,msg);
  61 + }
  62 + }
  63 +
  64 + public static void throwParamError(boolean expect,String code, String msg) throws ParamErrorException {
  65 + if (expect) {
  66 + throw new ParamErrorException(code,msg);
  67 + }
  68 + }
  69 +
  70 + /**
  71 + * expect=true时抛出RpcConnectException异常
  72 + * @param expect
  73 + * @param msg
  74 + */
  75 + public static void throwRpcConnect(boolean expect, String msg) throws RpcConnectException {
  76 + if (expect) {
  77 + throw new RpcConnectException(msg);
  78 + }
  79 + }
  80 + /**
  81 + * 抛出RpcConnectException异常
  82 + * @param e
  83 + */
  84 + public static void throwRpcConnect(Exception e) throws RpcConnectException {
  85 + throw new RpcConnectException(e);
  86 + }
  87 + /**
  88 + * 抛出RpcConnectException异常
  89 + * @param msg
  90 + * @param e
  91 + */
  92 + public static void throwRpcConnect(String msg,Exception e) throws RpcConnectException {
  93 + throw new RpcConnectException(msg,e);
  94 + }
  95 +
  96 + public static void throwRpcConnect(String code,String message) throws RpcConnectException {
  97 + throw new RpcConnectException(code,message);
  98 + }
  99 +
  100 + public static void throwRpcConnect(String msg) throws RpcConnectException {
  101 + throw new RpcConnectException(msg);
  102 + }
  103 +
  104 + public static void throwRpcPayment(boolean expect, String msg) throws RpcPaymentException {
  105 + if (expect) {
  106 + throw new RpcPaymentException(msg);
  107 + }
  108 + }
  109 +
  110 + public static void throwRpcPayment(String code,String message) throws RpcPaymentException {
  111 + throw new RpcPaymentException(code,message);
  112 + }
  113 +
  114 + public static void throwRpcPayment(String msg,Exception e) throws RpcPaymentException {
  115 + throw new RpcPaymentException(msg,e);
  116 + }
  117 +
  118 + public static void throwRpcPayment(String msg) throws RpcPaymentException {
  119 + throw new RpcPaymentException(msg);
  120 + }
  121 +
  122 + public static void throwRpcGuard(boolean expect, String msg) throws RpcGuardException {
  123 + if (expect) {
  124 + throw new RpcGuardException(msg);
  125 + }
  126 + }
  127 +
  128 + public static void throwRpcGuard(String code,String message) throws RpcGuardException {
  129 + throw new RpcGuardException(code,message);
  130 + }
  131 +
  132 + public static void throwRpcGuard(String msg,Exception e) throws RpcGuardException {
  133 + throw new RpcGuardException(msg,e);
  134 + }
  135 +
  136 + public static void throwRpcGuard(String msg) throws RpcGuardException {
  137 + throw new RpcGuardException(msg);
  138 + }
  139 +
  140 + public static WebApplicationContext getWebApplicationContext() {
  141 + return ContextLoader.getCurrentWebApplicationContext();
  142 + }
  143 +}
... ...
dtms-domain/src/main/java/com/b2c/dtms/common/DataDictionaryCode.java 0 → 100644
  1 +++ a/dtms-domain/src/main/java/com/b2c/dtms/common/DataDictionaryCode.java
  1 +/*
  2 + * Copyright (c) 2014 www.diligrp.com All rights reserved.
  3 + * 本软件源代码版权归----所有,未经许可不得任意复制与传播.
  4 + */
  5 +package com.b2c.dtms.common;
  6 +
  7 +import com.b2c.dtms.publics.constants.PublicDataDictCode;
  8 +
  9 +/**
  10 + *
  11 + * <B>Description</B>数据字典代码 <br />
  12 + * <B>Copyright</B> Copyright (c) 2014 www.diligrp.com All rights reserved. <br />
  13 + * 本软件源代码版权归地利集团,未经许可不得任意复制与传播.<br />
  14 + * <B>Company</B> 地利集团
  15 + * @createTime 2014-6-16 下午03:37:14
  16 + * @author xiongdeqiang
  17 + */
  18 +public final class DataDictionaryCode extends PublicDataDictCode {
  19 + /** 代购服务项 */
  20 + public final static String DIC_PURCHASE_SERVICE_ITEM = "DIC_PURCHASE_SERVICE_ITEM";
  21 + /** 地利服务. */
  22 + public final static String DIC_DL_SERVICE = "DIC_DL_SERVICE";
  23 +
  24 + /** 订单服务状态. */
  25 + public final static String DIC_ORDER_SERVER_STATUS = "DIC_ORDER_SERVER_STATUS";
  26 +
  27 + /** 国家. */
  28 + public final static String DIC_COUNTRY = "DIC_COUNTRY";
  29 +
  30 + /** 退款申请理由. */
  31 + public final static String DIC_REORDER_APPLY_REASON = "DIC_REORDER_APPLY_REASON";
  32 +
  33 + /** 退款申请状态. */
  34 + public final static String DIC_REORDER_APPLY_STATUS = "DIC_REORDER_APPLY_STATUS";
  35 +
  36 + /** 账单结算来源. */
  37 + public final static String DIC_BILL_SETTLE_SOURCE_CODE = "DIC_BILL_SETTLE_SOURCE_CODE";
  38 +
  39 + /** 账单结算状态. */
  40 + public final static String DIC_BILL_SETTLE_STATUS = "DIC_BILL_SETTLE_STATUS";
  41 +
  42 + /** 账单结算类型. */
  43 + public final static String DIC_BILL_SETTLE_TYPE = "DIC_BILL_SETTLE_TYPE";
  44 +
  45 + /** 增值服务处理状态. */
  46 + public final static String DIC_SERVICE_PROCESS_STATUS = "DIC_SERVICE_PROCESS_STATUS";
  47 +
  48 + /** 供应商类别 */
  49 + public final static String DIC_SUPPLIER_TYPE = "DIC_SUPPLIER_TYPE";
  50 +
  51 + /** 性别类别 */
  52 + public final static String DIC_SIX_TYPE = "DIC_SIX_TYPE";
  53 +
  54 + /** 识别卡类型 */
  55 + public final static String DIC_CARD_TYPE = "DIC_CARD_TYPE";
  56 +
  57 + /** 供应单状态 */
  58 + public final static String DIC_SUPPLY_ORDER_STATUS = "DIC_SUPPLY_ORDER_STATUS";
  59 +
  60 + /** [订单]订单状态枚举(前端) */
  61 + public final static String DIC_ORDER_WEB_STATUS = "DIC_ORDER_WEB_STATUS";
  62 +
  63 + /** 买卖对接订单状态 */
  64 + public final static String DIC_THIRD_SALE_ORDER_BACKEND_STATUS = "DIC_THIRD_SALE_ORDER_BACKEND_STATUS";
  65 +
  66 + /** 代购单前台状态 */
  67 + public final static String PURCHASE_ORDER_WEB_STATUS = "PURCHASE_ORDER_WEB_STATUS";
  68 +
  69 + /** 自营/代销订单状态 */
  70 + public final static String DIC_SELF_AGENT_SALE_ORDER_BACKEND_STATUS = "DIC_SELF_AGENT_SALE_ORDER_BACKEND_STATUS";
  71 +
  72 + /** 销售中心订单描述 */
  73 + public final static String DIC_THIRD_SALE_ORDER_BACKEND_DESCRIPTION = "DIC_THIRD_SALE_ORDER_BACKEND_DESCRIPTION";
  74 +
  75 + /** 采购中心订单描述 */
  76 + public final static String DIC_SELF_AGENT_SALE_ORDER_DESCRIPTION = "DIC_SELF_AGENT_SALE_ORDER_DESCRIPTION";
  77 +
  78 + /** 支付方式*/
  79 + public final static String DIC_PAY_WAY = "DIC_PAY_WAY";
  80 +
  81 + /** 地利集团银行帐号 转账汇款及查看流水时使用*/
  82 + public final static String DIC_DL_BANK_ACCOUNT="DIC_DL_BANK_ACCOUNT";
  83 +
  84 + /**结算单与转账汇款记录匹配状态*/
  85 + public final static String DIC_BILL_SETTLE_REMIT_MATCH_STATUS="DIC_BILL_SETTLE_REMIT_MATCH_STATUS";
  86 +
  87 + /** 银行*/
  88 + public final static String DIC_BANK="DIC_BANK";
  89 +
  90 + /** 发送短信模板*/
  91 + public final static String DIC_SMS_CONTENT="DIC_SMS_CONTENT";
  92 +
  93 + public static final String DIC_CLAIMS_APPEAL_RESULTS = "DIC_CLAIMS_APPEAL_RESULTS";
  94 + /**用户渠道配置KEY*/
  95 + public static final String CLIENT_SOURCE = "CLIENT_SOURCE";
  96 +}
... ...
dtms-domain/src/main/java/com/b2c/dtms/common/DateFormat.java 0 → 100644
  1 +++ a/dtms-domain/src/main/java/com/b2c/dtms/common/DateFormat.java
  1 +package com.b2c.dtms.common;
  2 +
  3 +
  4 +public class DateFormat {
  5 +
  6 + /** 所有地方可用*/
  7 + public final static String YYYY_MM_DD_HH_mm_ss="yyyy-MM-dd HH:mm:ss";
  8 +
  9 + public final static String YYYY_MM_DD_HH_mm_ss_SSS="yyyy-MM-dd HH:mm:ss SSS";
  10 +
  11 + /** Activiti流程中专用*/
  12 + public final static String YYYY_MM_DD_T_HH_mm_ss="yyyy-MM-dd'T'HH:mm:ss";
  13 +
  14 + /** 所有地方可用*/
  15 + public final static String YYYY_MM_DD="yyyy-MM-dd";
  16 +
  17 + public final static String CST="EEE MMM dd HH:mm:ss 'CST' yyyy";
  18 +
  19 + public final static String YYYY_MM_DD_ZN_CH="yyyy年MM月dd日";
  20 +}
... ...
dtms-domain/src/main/java/com/b2c/dtms/common/MessageCode.java 0 → 100644
  1 +++ a/dtms-domain/src/main/java/com/b2c/dtms/common/MessageCode.java
  1 +package com.b2c.dtms.common;
  2 +
  3 +/**
  4 + * 结果编码集;<br />
  5 + * 请保持与client包中的ResultCode类一至 <br />
  6 + * <B>Copyright</B> Copyright (c) 2014 www.diligrp.com All rights reserved. <br />
  7 + * 本软件源代码版权归地利集团,未经许可不得任意复制与传播.<br />
  8 + * <B>Company</B> 地利集团
  9 + */
  10 +public class MessageCode {
  11 + public static final String OK="200";//成功
  12 + public static final String PARAMS_ERROR="1000";//输入参数错误(输入参数类型,值,null错误等)
  13 + public static final String NOT_AUTH_ERROR="2000";//无权限(未登录,数据权限不满足,功能权限不满足等)
  14 + public static final String DATA_ERROR="3000";//数据错误(未查询到数据,数据验证不通过等)
  15 + public static final String APP_ERROR="5000";//服务器内部错误(系统错误,代码BUG,系统间调用超时等错误)
  16 +}
... ...
dtms-domain/src/main/java/com/b2c/dtms/common/SystemConfigCode.java 0 → 100644
  1 +++ a/dtms-domain/src/main/java/com/b2c/dtms/common/SystemConfigCode.java
  1 +/*
  2 + * Copyright (c) 2014 www.diligrp.com All rights reserved.
  3 + * 本软件源代码版权归----所有,未经许可不得任意复制与传播.
  4 + */
  5 +package com.b2c.dtms.common;
  6 +
  7 +public interface SystemConfigCode {
  8 +
  9 + /** [订单]第三方订单买家最大允许提交退款申请次数 */
  10 + String Order_Third_Buyer_SubmitReOrder_Num="Order_Third_Buyer_SubmitReOrder_Num";
  11 + /** [订单]第三方订单买家最大允许提交理赔申请次数 */
  12 + String Order_Third_Buyer_SubmitClaimsOrder_Num="Order_Third_Buyer_SubmitClaimsOrder_Num";
  13 + /** [订单]第三方订单买家最大允许延期结算次数 */
  14 + String Order_Third_Buyer_Delay_Payment_Num="Order_Third_Buyer_Delay_Payment_Num";
  15 + /** [订单]第三方订单卖家最大允许延期结算次数 */
  16 + String Order_Third_Seller_Delay_Payment_Num="Order_Third_Seller_Delay_Payment_Num";
  17 +
  18 + /** 线上付款/提货付款 待付款订单有效时间,单位:小时 */
  19 + String Order_PaymentWait_ValidIdle="Order_PaymentWait_ValidIdle";
  20 + /** 线下付款 待付款订单有效时间,单位:小时 */
  21 + String Order_Offline_PaymentWait_ValidIdle="Order_Offline_PaymentWait_ValidIdle";
  22 + /** 赊账付款 待审核订单有效时间,单位:小时 */
  23 + String Order_Credit_AuditWait_ValidIdle="Order_Credit_AuditWait_ValidIdle";
  24 + /** 线下付款,现场交易自动完成时间,单位:分钟 */
  25 + String Order_Spot_Delivered_ValidIdle="Order_Spot_Delivered_ValidIdle";
  26 +
  27 + /** 待分单超时告警时间,单位:小时 */
  28 + String Order_DivideWait_ValidIdle="Order_DivideWait_ValidIdle";
  29 +
  30 + /** 第三方订单-待提货-自动结算等待时间,单位:小时 */
  31 + String Order_Third_DeliveredWait_ValidIdle="Order_Third_DeliveredWait_ValidIdle";
  32 + /** 第三方订单-待收货-自动结算等待时间,单位:小时 */
  33 + String Order_Third_DeliveredWait_Receive_ValidIdle="Order_Third_DeliveredWait_Receive_ValidIdle";
  34 + /** 第三方订单延期结算默认天数,单位:天 */
  35 + String Order_Third_delayClearing_DefaultDay="Order_Third_delayClearing_DefaultDay";
  36 +
  37 + /** 第三方订单付款后多少小时未发货,短信通知卖家,单位:小时 */
  38 + String Order_Third_Not_Send_Hint_ValidIdle="Order_Third_Not_Send_Hint_ValidIdle";
  39 +
  40 + /** 市场配送列表 json格式*/
  41 + String Order_Third_Market_Delivery = "Order_Third_Market_Delivery";
  42 +
  43 + /** 第三方订单-上门自提 线下付款 订单自动结算时间到达前多少个小时 发送短信提醒 单位:小时*/
  44 + String Order_Third_Self_Offline_AutoDelivered_Hint_ValidIdle="Order_Third_Self_Offline_AutoDelivered_Hint_ValidIdle";
  45 + /** 第三方订单-上门自提 线上付款 订单自动结算时间到达前多少个小时 发送短信提醒 单位:小时*/
  46 + String Order_Third_Self_Online_AutoDelivered_Hint_ValidIdle="Order_Third_Self_Online_AutoDelivered_Hint_ValidIdle";
  47 + /** 第三方订单-送货上门 线下付款 订单自动结算时间到达前多少个小时 发送短信提醒 单位:小时*/
  48 + String Order_Third_Delivery_Offline_AutoDelivered_Hint_ValidIdle="Order_Third_Delivery_Offline_AutoDelivered_Hint_ValidIdle";
  49 + /** 第三方订单-送货上门 线上付款 订单自动结算时间到达前多少个小时 发送短信提醒 单位:小时*/
  50 + String Order_Third_Delivery_Online_AutoDelivered_Hint_ValidIdle="Order_Third_Delivery_Online_AutoDelivered_Hint_ValidIdle";
  51 +
  52 +
  53 + /** 第三方订单-订单自动通过退款申请有效时间(单位:小时) */
  54 + String Order_Third_AutoRefundPass_Wait_ValidIdle="Order_Third_AutoRefundPass_Wait_ValidIdle";
  55 +
  56 +
  57 + /** 财务复核,0:不需要财务复核;1:需要财务复核*/
  58 + String Financial_Review="Financial_Review ";
  59 +
  60 + /** 订单确认提货后等待评论有效时间,单位:小时 */
  61 + String Order_Auto_Commented_ValidIdle="Order_Auto_Commented_ValidIdle";
  62 +
  63 + /** 订单提交成功,支付方式为(线上/线下付款)且超过N小时未支付提醒,单位:小时 */
  64 + String Order_PaymentWait_Prompt_ValidIdle="Order_PaymentWait_Prompt_ValidIdle";
  65 +
  66 + /** 服务热线*/
  67 + String Client_Service_Hot_Line = "Client_Service_Hot_Line";
  68 +
  69 + /** 农丰网RSA私钥 */
  70 + String NONG12_RSA_PRIVATE_KEY="NONG12_RSA_PRIVATE_KEY";
  71 +
  72 + /** 农丰网RSA公钥 */
  73 + String NONG12_RSA_PUBLIC_KEY="NONG12_RSA_PUBLIC_KEY";
  74 +
  75 + /** 支付RSA公钥 */
  76 + String PAY_RSA_PUBLIC_KEY="PAY_RSA_PUBLIC_KEY";
  77 +
  78 + /** 订单的佣金率 */
  79 + String ORDER_BROKERAGE_RATE="ORDER_BROKERAGE_RATE";
  80 + /** 订单的佣金最大抽取值 */
  81 + String ORDER_BROKERAGE_MAX_VALUE="ORDER_BROKERAGE_MAX_VALUE";
  82 + /** 订单完成后允许提交理赔申请的最大小时数(单位:小时) */
  83 + String AFTER_RECEIVE_CAN_APPLY_CLAIMS_HOURS = "AFTER_RECEIVE_CAN_APPLY_CLAIMS_HOURS";
  84 + /** 触发自动审核理赔单小时数(单位:小时) */
  85 + String AUTO_AUDIT_CLAIMS_TRIGGER_HOURS = "AUTO_AUDIT_CLAIMS_TRIGGER_HOURS";
  86 + /** 触发禁用理赔申诉小时数(单位:小时) */
  87 + String AUTO_DISABLE_CLAIMS_APPEAL_TRIGGER_HOURS = "AUTO_DISABLE_CLAIMS_APPEAL_TRIGGER_HOURS";
  88 +
  89 +}
... ...
dtms-domain/src/main/java/com/b2c/dtms/common/exception/AppException.java 0 → 100644
  1 +++ a/dtms-domain/src/main/java/com/b2c/dtms/common/exception/AppException.java
  1 +/*
  2 + * Copyright (c) 2014 www.diligrp.com All rights reserved.
  3 + * 本软件源代码版权归----所有,未经许可不得任意复制与传播.
  4 + */
  5 +package com.b2c.dtms.common.exception;
  6 +
  7 +/**
  8 + * AppException
  9 + * @author dev-center
  10 + * @since 2014-05-15
  11 + */
  12 +public class AppException extends RuntimeException{
  13 + private static final long serialVersionUID = 1L;
  14 + public static final String CODE_NEGLECTABLE = "201";
  15 + private String code;
  16 + private String errorData;
  17 + public AppException() {
  18 + super();
  19 + }
  20 +
  21 + public AppException(String message) {
  22 + super(message);
  23 + }
  24 +
  25 + public AppException(String message, Throwable cause) {
  26 + super(message, cause);
  27 + }
  28 +
  29 + public AppException(Throwable cause) {
  30 + super(cause);
  31 + }
  32 +
  33 + public AppException(String code, String message) {
  34 + super(message);
  35 + this.code=code;
  36 + }
  37 +
  38 + public AppException(String code, String errorData,String message) {
  39 + super(message);
  40 + this.code=code;
  41 + this.errorData=errorData;
  42 + }
  43 +
  44 +
  45 + public String getCode() {
  46 + return code;
  47 + }
  48 +
  49 + public void setCode(String code) {
  50 + this.code = code;
  51 + }
  52 +
  53 +
  54 + public String getErrorData() {
  55 + return errorData;
  56 + }
  57 +
  58 +
  59 + public void setErrorData(String errorData) {
  60 + this.errorData = errorData;
  61 + }
  62 +
  63 + @Override
  64 + public String toString() {
  65 + return "AppException [code=" + getCode() + ", errorData="
  66 + + getErrorData() + ", message=" + getMessage()
  67 + + ", cause=" + getCause() + "]";
  68 + }
  69 +}
... ...
dtms-domain/src/main/java/com/b2c/dtms/common/exception/DataErrorException.java 0 → 100644
  1 +++ a/dtms-domain/src/main/java/com/b2c/dtms/common/exception/DataErrorException.java
  1 +/*
  2 + * Copyright (c) 2014 www.diligrp.com All rights reserved.
  3 + * 本软件源代码版权归----所有,未经许可不得任意复制与传播.
  4 + */
  5 +package com.b2c.dtms.common.exception;
  6 +
  7 +
  8 +/**
  9 + * AppException
  10 + * @author dev-center
  11 + * @since 2014-05-15
  12 + */
  13 +public class DataErrorException extends AppException{
  14 + private static final long serialVersionUID = 1L;
  15 + public DataErrorException() {
  16 + super();
  17 + }
  18 +
  19 + public DataErrorException(String message) {
  20 + super(message);
  21 + }
  22 +
  23 + public DataErrorException(String message, Throwable cause) {
  24 + super(message, cause);
  25 + }
  26 +
  27 + public DataErrorException(Throwable cause) {
  28 + super(cause);
  29 + }
  30 +
  31 + public DataErrorException(String code, String errorData,String message) {
  32 + super(code,errorData,message);
  33 + }
  34 +
  35 + @Override
  36 + public String toString() {
  37 + return "DataErrorException [code=" + getCode() + ", errorData="
  38 + + getErrorData() + ", message=" + getMessage()
  39 + + ", cause=" + getCause() + "]";
  40 + }
  41 +}
... ...
dtms-domain/src/main/java/com/b2c/dtms/common/exception/DtmsException.java 0 → 100644
  1 +++ a/dtms-domain/src/main/java/com/b2c/dtms/common/exception/DtmsException.java
  1 +/*
  2 + * Copyright (c) 2014 www.diligrp.com All rights reserved.
  3 + * 本软件源代码版权归----所有,未经许可不得任意复制与传播.
  4 + */
  5 +package com.b2c.dtms.common.exception;
  6 +
  7 +/**
  8 + * AppException
  9 + * @author dev-center
  10 + * @since 2014-05-15
  11 + */
  12 +public class DtmsException extends RuntimeException{
  13 + private static final long serialVersionUID = 1L;
  14 + private String code;
  15 + public DtmsException() {
  16 + super();
  17 + }
  18 +
  19 + public DtmsException(String message) {
  20 + super(message);
  21 + }
  22 +
  23 + public DtmsException(String message, Throwable cause) {
  24 + super(message, cause);
  25 + }
  26 +
  27 + public DtmsException(Throwable cause) {
  28 + super(cause);
  29 + }
  30 +
  31 + public DtmsException(String code, String message) {
  32 + super(message);
  33 + this.code=code;
  34 + }
  35 +
  36 + public String getCode() {
  37 + return code;
  38 + }
  39 +
  40 + public void setCode(String code) {
  41 + this.code = code;
  42 + }
  43 +}
... ...
dtms-domain/src/main/java/com/b2c/dtms/common/exception/NotAuthException.java 0 → 100644
  1 +++ a/dtms-domain/src/main/java/com/b2c/dtms/common/exception/NotAuthException.java
  1 +/*
  2 + * Copyright (c) 2014 www.diligrp.com All rights reserved.
  3 + * 本软件源代码版权归----所有,未经许可不得任意复制与传播.
  4 + */
  5 +package com.b2c.dtms.common.exception;
  6 +
  7 +/**
  8 + * AppException
  9 + * @author dev-center
  10 + * @since 2014-05-15
  11 + */
  12 +public class NotAuthException extends AppException{
  13 + private static final long serialVersionUID = 1L;
  14 + public NotAuthException() {
  15 + super();
  16 + }
  17 +
  18 + public NotAuthException(String message) {
  19 + super(message);
  20 + }
  21 +
  22 + public NotAuthException(String message, Throwable cause) {
  23 + super(message, cause);
  24 + }
  25 +
  26 + public NotAuthException(Throwable cause) {
  27 + super(cause);
  28 + }
  29 +
  30 + public NotAuthException(String code, String errorData,String message) {
  31 + super(code,errorData,message);
  32 + }
  33 +
  34 + @Override
  35 + public String toString() {
  36 + return "NotAuthException [code=" + getCode() + ", errorData="
  37 + + getErrorData() + ", message=" + getMessage()
  38 + + ", cause=" + getCause() + "]";
  39 + }
  40 +}
... ...
dtms-domain/src/main/java/com/b2c/dtms/common/exception/ParamErrorException.java 0 → 100644
  1 +++ a/dtms-domain/src/main/java/com/b2c/dtms/common/exception/ParamErrorException.java
  1 +/*
  2 + * Copyright (c) 2014 www.diligrp.com All rights reserved.
  3 + * 本软件源代码版权归----所有,未经许可不得任意复制与传播.
  4 + */
  5 +package com.b2c.dtms.common.exception;
  6 +
  7 +/**
  8 + * AppException
  9 + * @author dev-center
  10 + * @since 2014-05-15
  11 + */
  12 +public class ParamErrorException extends AppException{
  13 + private static final long serialVersionUID = 1L;
  14 + public ParamErrorException() {
  15 + super();
  16 + }
  17 +
  18 + public ParamErrorException(String message) {
  19 + super(message);
  20 + }
  21 +
  22 + public ParamErrorException(String message, Throwable cause) {
  23 + super(message, cause);
  24 + }
  25 +
  26 + public ParamErrorException(Throwable cause) {
  27 + super(cause);
  28 + }
  29 +
  30 + public ParamErrorException(String code, String message) {
  31 + super(code,message);
  32 + }
  33 +
  34 + public ParamErrorException(String code, String errorData,String message) {
  35 + super(code,errorData,message);
  36 + }
  37 +
  38 + @Override
  39 + public String toString() {
  40 + return "ParamErrorException [code=" + getCode() + ", errorData="
  41 + + getErrorData() + ", message=" + getMessage()
  42 + + ", cause=" + getCause() + "]";
  43 + }
  44 +}
... ...
dtms-domain/src/main/java/com/b2c/dtms/common/exception/RpcConnectException.java 0 → 100644
  1 +++ a/dtms-domain/src/main/java/com/b2c/dtms/common/exception/RpcConnectException.java
  1 +package com.b2c.dtms.common.exception;
  2 +
  3 +public class RpcConnectException extends AppException {
  4 +
  5 + /**
  6 + * 接口调用异常
  7 + */
  8 + private static final long serialVersionUID = 1L;
  9 + public RpcConnectException() {
  10 + super();
  11 + }
  12 +
  13 + public RpcConnectException(String message) {
  14 + super(message);
  15 + }
  16 +
  17 + public RpcConnectException(String message, Throwable cause) {
  18 + super(message, cause);
  19 + }
  20 +
  21 + public RpcConnectException(Throwable cause) {
  22 + super(cause);
  23 + }
  24 +
  25 +
  26 + public RpcConnectException(String code,String message) {
  27 + super(code,message);
  28 + }
  29 +
  30 + public RpcConnectException(String code, String errorData,String message) {
  31 + super(code,errorData,message);
  32 + }
  33 +
  34 + @Override
  35 + public String toString() {
  36 + return "RpcConnectException [code=" + getCode() + ", errorData="
  37 + + getErrorData() + ", message=" + getMessage()
  38 + + ", cause=" + getCause() + "]";
  39 + }
  40 +}
... ...
dtms-domain/src/main/java/com/b2c/dtms/common/exception/RpcGuardException.java 0 → 100644
  1 +++ a/dtms-domain/src/main/java/com/b2c/dtms/common/exception/RpcGuardException.java
  1 +package com.b2c.dtms.common.exception;
  2 +
  3 +public class RpcGuardException extends RpcConnectException {
  4 +
  5 + private static final long serialVersionUID = 1L;
  6 +
  7 + public RpcGuardException() {
  8 + super();
  9 + }
  10 +
  11 + public RpcGuardException(String message) {
  12 + super(message);
  13 + }
  14 +
  15 + public RpcGuardException(String message, Throwable cause) {
  16 + super(message, cause);
  17 + }
  18 +
  19 + public RpcGuardException(Throwable cause) {
  20 + super(cause);
  21 + }
  22 +
  23 +
  24 + public RpcGuardException(String code,String message) {
  25 + super(code,message);
  26 + }
  27 +
  28 + public RpcGuardException(String code, String data,String message) {
  29 + super(code,data,message);
  30 + }
  31 +
  32 + @Override
  33 + public String toString() {
  34 + return "RpcGuardException [code=" + getCode() + ", errorData="
  35 + + getErrorData() + ", message=" + getMessage()
  36 + + ", cause=" + getCause() + "]";
  37 + }
  38 +}
... ...
dtms-domain/src/main/java/com/b2c/dtms/common/exception/RpcPaymentException.java 0 → 100644
  1 +++ a/dtms-domain/src/main/java/com/b2c/dtms/common/exception/RpcPaymentException.java
  1 +package com.b2c.dtms.common.exception;
  2 +
  3 +public class RpcPaymentException extends RpcConnectException {
  4 +
  5 + private static final long serialVersionUID = 1L;
  6 +
  7 + public RpcPaymentException() {
  8 + super();
  9 + }
  10 +
  11 + public RpcPaymentException(String message) {
  12 + super(message);
  13 + }
  14 +
  15 + public RpcPaymentException(String message, Throwable cause) {
  16 + super(message, cause);
  17 + }
  18 +
  19 + public RpcPaymentException(Throwable cause) {
  20 + super(cause);
  21 + }
  22 +
  23 +
  24 + public RpcPaymentException(String code,String message) {
  25 + super(code,message);
  26 + }
  27 +
  28 + public RpcPaymentException(String code, String data,String message) {
  29 + super(code,data,message);
  30 + }
  31 +
  32 + @Override
  33 + public String toString() {
  34 + return "RpcPaymentException [code=" + getCode() + ", errorData="
  35 + + getErrorData() + ", message=" + getMessage()
  36 + + ", cause=" + getCause() + "]";
  37 + }
  38 +}
... ...
dtms-domain/src/main/java/com/b2c/dtms/common/exception/WebException.java 0 → 100644
  1 +++ a/dtms-domain/src/main/java/com/b2c/dtms/common/exception/WebException.java
  1 +package com.b2c.dtms.common.exception;
  2 +
  3 +public class WebException extends AppException{
  4 + private static final long serialVersionUID = -4573550295666184287L;
  5 +
  6 + public WebException(String msg){
  7 + super(msg);
  8 + }
  9 +
  10 + public WebException(Throwable cause){
  11 + super(cause);
  12 + }
  13 +
  14 + public WebException(String msg, Throwable cause){
  15 + super(msg, cause);
  16 + }
  17 +
  18 + public WebException(String code, String data,String message) {
  19 + super(code,data,message);
  20 + }
  21 +}
... ...
dtms-domain/src/main/java/com/b2c/dtms/common/sql/OrderFieldType.java 0 → 100644
  1 +++ a/dtms-domain/src/main/java/com/b2c/dtms/common/sql/OrderFieldType.java
  1 +package com.b2c.dtms.common.sql;
  2 +
  3 +
  4 +public final class OrderFieldType {
  5 +
  6 + public static String DESC="DESC";
  7 +
  8 + public static String ASC="ASC";
  9 +}
... ...
dtms-domain/src/main/java/com/b2c/dtms/common/tools/Base64.java 0 → 100644
  1 +++ a/dtms-domain/src/main/java/com/b2c/dtms/common/tools/Base64.java
  1 +package com.b2c.dtms.common.tools;
  2 +
  3 +import org.apache.commons.lang.StringUtils;
  4 +
  5 +/**
  6 + * Base64编码
  7 + *
  8 + */
  9 +public final class Base64 {
  10 +
  11 + static private final int BASELENGTH = 128;
  12 + static private final int LOOKUPLENGTH = 64;
  13 + static private final int TWENTYFOURBITGROUP = 24;
  14 + static private final int EIGHTBIT = 8;
  15 + static private final int SIXTEENBIT = 16;
  16 + static private final int FOURBYTE = 4;
  17 + static private final int SIGN = -128;
  18 + static private final char PAD = '=';
  19 + static private final boolean fDebug = false;
  20 + static final private byte[] base64Alphabet = new byte[BASELENGTH];
  21 + static final private char[] lookUpBase64Alphabet = new char[LOOKUPLENGTH];
  22 + static {
  23 + for (int i = 0; i < BASELENGTH; ++i) {
  24 + base64Alphabet[i] = -1;
  25 + }
  26 + for (int i = 'Z'; i >= 'A'; i--) {
  27 + base64Alphabet[i] = (byte) (i - 'A');
  28 + }
  29 + for (int i = 'z'; i >= 'a'; i--) {
  30 + base64Alphabet[i] = (byte) (i - 'a' + 26);
  31 + }
  32 + for (int i = '9'; i >= '0'; i--) {
  33 + base64Alphabet[i] = (byte) (i - '0' + 52);
  34 + }
  35 + base64Alphabet['+'] = 62;
  36 + base64Alphabet['/'] = 63;
  37 + for (int i = 0; i <= 25; i++) {
  38 + lookUpBase64Alphabet[i] = (char) ('A' + i);
  39 + }
  40 + for (int i = 26, j = 0; i <= 51; i++, j++) {
  41 + lookUpBase64Alphabet[i] = (char) ('a' + j);
  42 + }
  43 + for (int i = 52, j = 0; i <= 61; i++, j++) {
  44 + lookUpBase64Alphabet[i] = (char) ('0' + j);
  45 + }
  46 + lookUpBase64Alphabet[62] = (char) '+';
  47 + lookUpBase64Alphabet[63] = (char) '/';
  48 + }
  49 +
  50 +
  51 + private static boolean isWhiteSpace(char octect) {
  52 + return (octect == 0x20 || octect == 0xd || octect == 0xa || octect == 0x9);
  53 + }
  54 +
  55 +
  56 + private static boolean isPad(char octect) {
  57 + return (octect == PAD);
  58 + }
  59 +
  60 +
  61 + private static boolean isData(char octect) {
  62 + return (octect < BASELENGTH && base64Alphabet[octect] != -1);
  63 + }
  64 +
  65 + /**
  66 + * Encodes hex octects into Base64
  67 + *
  68 + * @param binaryData
  69 + * Array containing binaryData
  70 + * @return Encoded Base64 array
  71 + */
  72 + public static String encode(byte[] binaryData) {
  73 +
  74 + if (binaryData == null) {
  75 + return null;
  76 + }
  77 + int lengthDataBits = binaryData.length * EIGHTBIT;
  78 + if (lengthDataBits == 0) {
  79 + return "";
  80 + }
  81 + int fewerThan24bits = lengthDataBits % TWENTYFOURBITGROUP;
  82 + int numberTriplets = lengthDataBits / TWENTYFOURBITGROUP;
  83 + int numberQuartet = fewerThan24bits != 0 ? numberTriplets + 1 : numberTriplets;
  84 + char encodedData[] = null;
  85 + encodedData = new char[numberQuartet * 4];
  86 + byte k = 0, l = 0, b1 = 0, b2 = 0, b3 = 0;
  87 + int encodedIndex = 0;
  88 + int dataIndex = 0;
  89 + if (fDebug) {
  90 + System.out.println("number of triplets = " + numberTriplets);
  91 + }
  92 + for (int i = 0; i < numberTriplets; i++) {
  93 + b1 = binaryData[dataIndex++];
  94 + b2 = binaryData[dataIndex++];
  95 + b3 = binaryData[dataIndex++];
  96 + if (fDebug) {
  97 + System.out.println("b1= " + b1 + ", b2= " + b2 + ", b3= " + b3);
  98 + }
  99 + l = (byte) (b2 & 0x0f);
  100 + k = (byte) (b1 & 0x03);
  101 +
  102 + byte val1 = ((b1 & SIGN) == 0) ? (byte) (b1 >> 2) : (byte) ((b1) >> 2 ^ 0xc0);
  103 + byte val2 = ((b2 & SIGN) == 0) ? (byte) (b2 >> 4) : (byte) ((b2) >> 4 ^ 0xf0);
  104 + byte val3 = ((b3 & SIGN) == 0) ? (byte) (b3 >> 6) : (byte) ((b3) >> 6 ^ 0xfc);
  105 + if (fDebug) {
  106 + System.out.println("val2 = " + val2);
  107 + System.out.println("k4 = " + (k << 4));
  108 + System.out.println("vak = " + (val2 | (k << 4)));
  109 + }
  110 + encodedData[encodedIndex++] = lookUpBase64Alphabet[val1];
  111 + encodedData[encodedIndex++] = lookUpBase64Alphabet[val2 | (k << 4)];
  112 + encodedData[encodedIndex++] = lookUpBase64Alphabet[(l << 2) | val3];
  113 + encodedData[encodedIndex++] = lookUpBase64Alphabet[b3 & 0x3f];
  114 + }
  115 + // form integral number of 6-bit groups
  116 + if (fewerThan24bits == EIGHTBIT) {
  117 + b1 = binaryData[dataIndex];
  118 + k = (byte) (b1 & 0x03);
  119 + if (fDebug) {
  120 + System.out.println("b1=" + b1);
  121 + System.out.println("b1<<2 = " + (b1 >> 2));
  122 + }
  123 + byte val1 = ((b1 & SIGN) == 0) ? (byte) (b1 >> 2) : (byte) ((b1) >> 2 ^ 0xc0);
  124 + encodedData[encodedIndex++] = lookUpBase64Alphabet[val1];
  125 + encodedData[encodedIndex++] = lookUpBase64Alphabet[k << 4];
  126 + encodedData[encodedIndex++] = PAD;
  127 + encodedData[encodedIndex++] = PAD;
  128 + }
  129 + else if (fewerThan24bits == SIXTEENBIT) {
  130 + b1 = binaryData[dataIndex];
  131 + b2 = binaryData[dataIndex + 1];
  132 + l = (byte) (b2 & 0x0f);
  133 + k = (byte) (b1 & 0x03);
  134 +
  135 + byte val1 = ((b1 & SIGN) == 0) ? (byte) (b1 >> 2) : (byte) ((b1) >> 2 ^ 0xc0);
  136 + byte val2 = ((b2 & SIGN) == 0) ? (byte) (b2 >> 4) : (byte) ((b2) >> 4 ^ 0xf0);
  137 + encodedData[encodedIndex++] = lookUpBase64Alphabet[val1];
  138 + encodedData[encodedIndex++] = lookUpBase64Alphabet[val2 | (k << 4)];
  139 + encodedData[encodedIndex++] = lookUpBase64Alphabet[l << 2];
  140 + encodedData[encodedIndex++] = PAD;
  141 + }
  142 + return new String(encodedData);
  143 + }
  144 +
  145 + /**
  146 + * Decodes Base64 data into octects
  147 + *
  148 + * @param encoded
  149 + * string containing Base64 data
  150 + * @return Array containind decoded data.
  151 + */
  152 + public static byte[] decode(String encoded) {
  153 +
  154 + if (encoded == null) {
  155 + return null;
  156 + }
  157 + char[] base64Data = encoded.toCharArray();
  158 + // remove white spaces
  159 + int len = removeWhiteSpace(base64Data);
  160 + if (len % FOURBYTE != 0) {
  161 + return null;// should be divisible by four
  162 + }
  163 + int numberQuadruple = (len / FOURBYTE);
  164 +
  165 + if (numberQuadruple == 0) {
  166 + return new byte[0];
  167 + }
  168 + byte decodedData[] = null;
  169 + byte b1 = 0, b2 = 0, b3 = 0, b4 = 0;
  170 + char d1 = 0, d2 = 0, d3 = 0, d4 = 0;
  171 + int i = 0;
  172 + int encodedIndex = 0;
  173 + int dataIndex = 0;
  174 + decodedData = new byte[(numberQuadruple) * 3];
  175 + for (; i < numberQuadruple - 1; i++) {
  176 +
  177 + if (!isData((d1 = base64Data[dataIndex++])) || !isData((d2 = base64Data[dataIndex++])) || !isData((d3 = base64Data[dataIndex++])) || !isData((d4 = base64Data[dataIndex++]))) {
  178 + return null;
  179 + }// if found "no data" just return null
  180 + b1 = base64Alphabet[d1];
  181 + b2 = base64Alphabet[d2];
  182 + b3 = base64Alphabet[d3];
  183 + b4 = base64Alphabet[d4];
  184 + decodedData[encodedIndex++] = (byte) (b1 << 2 | b2 >> 4);
  185 + decodedData[encodedIndex++] = (byte) (((b2 & 0xf) << 4) | ((b3 >> 2) & 0xf));
  186 + decodedData[encodedIndex++] = (byte) (b3 << 6 | b4);
  187 + }
  188 +
  189 + if (!isData((d1 = base64Data[dataIndex++])) || !isData((d2 = base64Data[dataIndex++]))) {
  190 + return null;// if found "no data" just return null
  191 + }
  192 + b1 = base64Alphabet[d1];
  193 + b2 = base64Alphabet[d2];
  194 + d3 = base64Data[dataIndex++];
  195 + d4 = base64Data[dataIndex++];
  196 + if (!isData((d3)) || !isData((d4))) {// Check if they are PAD characters
  197 + if (isPad(d3) && isPad(d4)) {
  198 + if ((b2 & 0xf) != 0)// last 4 bits should be zero
  199 + {
  200 + return null;
  201 + }
  202 + byte[] tmp = new byte[i * 3 + 1];
  203 + System.arraycopy(decodedData, 0, tmp, 0, i * 3);
  204 + tmp[encodedIndex] = (byte) (b1 << 2 | b2 >> 4);
  205 + return tmp;
  206 + }
  207 + else if (!isPad(d3) && isPad(d4)) {
  208 + b3 = base64Alphabet[d3];
  209 + if ((b3 & 0x3) != 0)// last 2 bits should be zero
  210 + {
  211 + return null;
  212 + }
  213 + byte[] tmp = new byte[i * 3 + 2];
  214 + System.arraycopy(decodedData, 0, tmp, 0, i * 3);
  215 + tmp[encodedIndex++] = (byte) (b1 << 2 | b2 >> 4);
  216 + tmp[encodedIndex] = (byte) (((b2 & 0xf) << 4) | ((b3 >> 2) & 0xf));
  217 + return tmp;
  218 + }
  219 + else {
  220 + return null;
  221 + }
  222 + }
  223 + else { // No PAD e.g 3cQl
  224 + b3 = base64Alphabet[d3];
  225 + b4 = base64Alphabet[d4];
  226 + decodedData[encodedIndex++] = (byte) (b1 << 2 | b2 >> 4);
  227 + decodedData[encodedIndex++] = (byte) (((b2 & 0xf) << 4) | ((b3 >> 2) & 0xf));
  228 + decodedData[encodedIndex++] = (byte) (b3 << 6 | b4);
  229 + }
  230 + return decodedData;
  231 + }
  232 +
  233 +
  234 + /**
  235 + * remove WhiteSpace from MIME containing encoded Base64 data.
  236 + *
  237 + * @param data
  238 + * the byte array of base64 data (with WS)
  239 + * @return the new length
  240 + */
  241 + private static int removeWhiteSpace(char[] data) {
  242 + if (data == null) {
  243 + return 0;
  244 + }
  245 +
  246 + // count characters that's not whitespace
  247 + int newSize = 0;
  248 + int len = data.length;
  249 + for (int i = 0; i < len; i++) {
  250 + if (!isWhiteSpace(data[i])) {
  251 + data[newSize++] = data[i];
  252 + }
  253 + }
  254 + return newSize;
  255 + }
  256 +}
... ...
dtms-domain/src/main/java/com/b2c/dtms/common/tools/CacheKeyGenerator.java 0 → 100644
  1 +++ a/dtms-domain/src/main/java/com/b2c/dtms/common/tools/CacheKeyGenerator.java
  1 +package com.b2c.dtms.common.tools;
  2 +
  3 +import lombok.Getter;
  4 +import lombok.NoArgsConstructor;
  5 +import lombok.Setter;
  6 +import org.springframework.cache.interceptor.KeyGenerator;
  7 +
  8 +import java.lang.reflect.Method;
  9 +
  10 +/**
  11 + * Created by yuehongbo on 2016/8/25.
  12 + */
  13 +@NoArgsConstructor
  14 +public class CacheKeyGenerator implements KeyGenerator {
  15 +
  16 + @Getter
  17 + @Setter
  18 + private String prefix="";
  19 +
  20 + @Override
  21 + public Object generate(Object target, Method method, Object... params) {
  22 + StringBuffer key = new StringBuffer();
  23 + if (prefix != null) {
  24 + key.append(prefix);
  25 + key.append(":");
  26 + }
  27 + key.append(target.getClass().getName());
  28 + key.append(".");
  29 + key.append(method.getName());
  30 + key.append(":");
  31 + return key;
  32 + }
  33 +}
... ...
dtms-domain/src/main/java/com/b2c/dtms/common/tools/CloneUtils.java 0 → 100644
  1 +++ a/dtms-domain/src/main/java/com/b2c/dtms/common/tools/CloneUtils.java
  1 +package com.b2c.dtms.common.tools;
  2 +
  3 +import java.io.*;
  4 +
  5 +
  6 +public class CloneUtils {
  7 +
  8 + public static Object clone(Object clonedObject){
  9 + ByteArrayOutputStream byteArrayOut=null;
  10 + ObjectOutputStream objectOut=null;
  11 + try {
  12 + byteArrayOut=new ByteArrayOutputStream();
  13 + objectOut = new ObjectOutputStream(byteArrayOut);
  14 + objectOut.writeObject(clonedObject);
  15 +
  16 + ByteArrayInputStream byteArrayIn=new ByteArrayInputStream(byteArrayOut.toByteArray());
  17 + ObjectInputStream objectIn=new ObjectInputStream(byteArrayIn);
  18 +
  19 + return objectIn.readObject();
  20 +
  21 + } catch (IOException e) {
  22 + new RuntimeException(e.getMessage());
  23 + } catch (ClassNotFoundException e) {
  24 + new RuntimeException(e.getMessage());
  25 + }
  26 + return null;
  27 + }
  28 +}
... ...
dtms-domain/src/main/java/com/b2c/dtms/common/tools/CollectionUtils.java 0 → 100644
  1 +++ a/dtms-domain/src/main/java/com/b2c/dtms/common/tools/CollectionUtils.java
  1 +package com.b2c.dtms.common.tools;
  2 +
  3 +import java.util.Collection;
  4 +import java.util.List;
  5 +
  6 +
  7 +public class CollectionUtils {
  8 +
  9 + public static boolean isEmpty(Collection<?> collection) {
  10 + return (collection == null || collection.isEmpty());
  11 + }
  12 +
  13 + public static String[] strList2Array(List<String> list ){
  14 + return list.toArray(new String[list.size()]);
  15 + }
  16 +
  17 + public static Long[] longList2Array(List<Long> list ){
  18 + return list.toArray(new Long[list.size()]);
  19 + }
  20 +}
... ...