Commit 767e04f9 authored by qinxunjia's avatar qinxunjia

修改ID生成方式

parent a57bd496
...@@ -5,6 +5,7 @@ import com.bgy.sms.channel.dmHub.config.DmHubConfig; ...@@ -5,6 +5,7 @@ import com.bgy.sms.channel.dmHub.config.DmHubConfig;
import com.bgy.sms.channel.dto.*; import com.bgy.sms.channel.dto.*;
import com.bgy.sms.config.ResponseCode; import com.bgy.sms.config.ResponseCode;
import com.bgy.sms.service.MessageService; import com.bgy.sms.service.MessageService;
import com.bgy.sms.service.XiaoShuService;
import com.bgy.util.Md5Util; import com.bgy.util.Md5Util;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -20,6 +21,11 @@ public class DmHubApi { ...@@ -20,6 +21,11 @@ public class DmHubApi {
@Autowired @Autowired
private MessageService messageService; private MessageService messageService;
@Autowired
private XiaoShuService xiaoShuService;
private static final String REJECTED = "rejected"; // 创建模板响应数据
private static final String APPROVED = "approved"; // 创建模板响应数据
@GetMapping("/ping") @GetMapping("/ping")
public String ping() { public String ping() {
...@@ -34,22 +40,20 @@ public class DmHubApi { ...@@ -34,22 +40,20 @@ public class DmHubApi {
* @return * @return
*/ */
@PostMapping("/sms/template") @PostMapping("/sms/template")
public DmHubResponse template(@RequestBody DmHubTemplateRequest params, String appId, String timestamp, String signature) { public void template(@RequestBody DmHubTemplateRequest params, String appId, String timestamp, String signature) {
log.info("**********创建模板接口入参*******:{},\r\n appId:{},timestamp:{},signature:{}", JSONObject.toJSONString(params), appId, timestamp, signature); log.info("**********创建模板接口入参*******:{},\r\n appId:{},timestamp:{},signature:{}", JSONObject.toJSONString(params), appId, timestamp, signature);
DmHubResponse response; DmHubResponse response;
try { try {
boolean checkResult = this.checkSignature(timestamp, signature); boolean checkResult = this.checkSignature(timestamp, signature);
if (!checkResult) { if (!checkResult) {
response = new DmHubResponse("555", "接口请求签名校验不通过"); xiaoShuService.updateDmhubSmsTempStatus(REJECTED, params.getTemplateId(), "接口请求签名校验不通过");
log.info("**********创建模板接口出参*******:{}", JSONObject.toJSONString(response)); log.info("**********创建模板接口出参*******:{}", "接口请求签名校验不通过");
return response;
} }
messageService.createTemplate(params); messageService.createTemplate(params);
} catch (Exception e) { } catch (Exception e) {
log.error("创建模板短信异常", e); log.error("创建模板短信异常", e);
new DmHubResponse("999", "创建模板短信异常"); new DmHubResponse("999", "创建模板短信异常");
} }
return null;
} }
/** /**
......
...@@ -160,7 +160,7 @@ public class BgySmsServiceImpl implements BgySmsService { ...@@ -160,7 +160,7 @@ public class BgySmsServiceImpl implements BgySmsService {
updateInfo.setUpRejectMsg(auditReason); updateInfo.setUpRejectMsg(auditReason);
updateInfo.setLastUpdated(new Date()); updateInfo.setLastUpdated(new Date());
smsTemplateService.updateById(updateInfo); smsTemplateService.updateById(updateInfo);
xiaoShuService.updateDmhubSmsTempStatus(dmhubStatue,smsTemplateInfo.getDmTemplateId()); xiaoShuService.updateDmhubSmsTempStatus(dmhubStatue,smsTemplateInfo.getDmTemplateId(),auditReason);
return new BGYResponse(); return new BGYResponse();
} }
......
...@@ -9,7 +9,7 @@ import java.util.Date; ...@@ -9,7 +9,7 @@ import java.util.Date;
public class DmBatchInfo { public class DmBatchInfo {
private Long id; private String id;
private String dmBatchId; private String dmBatchId;
...@@ -26,11 +26,11 @@ public class DmBatchInfo { ...@@ -26,11 +26,11 @@ public class DmBatchInfo {
private Date lastUpdated; private Date lastUpdated;
public Long getId() { public String getId() {
return id; return id;
} }
public void setId(Long id) { public void setId(String id) {
this.id = id; this.id = id;
} }
......
...@@ -9,7 +9,7 @@ import java.util.Date; ...@@ -9,7 +9,7 @@ import java.util.Date;
public class DmCodeInfo { public class DmCodeInfo {
private Long id; private String id;
private String mobile; private String mobile;
...@@ -19,11 +19,11 @@ public class DmCodeInfo { ...@@ -19,11 +19,11 @@ public class DmCodeInfo {
private Date dateCreated; private Date dateCreated;
public Long getId() { public String getId() {
return id; return id;
} }
public void setId(Long id) { public void setId(String id) {
this.id = id; this.id = id;
} }
......
...@@ -10,7 +10,7 @@ import java.util.Date; ...@@ -10,7 +10,7 @@ import java.util.Date;
public class SmsTemplateInfo { public class SmsTemplateInfo {
private Long id; private String id;
private String dmTemplateId; private String dmTemplateId;
...@@ -91,11 +91,11 @@ public class SmsTemplateInfo { ...@@ -91,11 +91,11 @@ public class SmsTemplateInfo {
this.tenantId = tenantId; this.tenantId = tenantId;
} }
public Long getId() { public String getId() {
return id; return id;
} }
public void setId(Long id) { public void setId(String id) {
this.id = id; this.id = id;
} }
......
...@@ -7,13 +7,13 @@ import java.util.Date; ...@@ -7,13 +7,13 @@ import java.util.Date;
@TableName("sys_batch") @TableName("sys_batch")
public class SysBatchInfo { public class SysBatchInfo {
private Long id; private String id;
private String dmBatchId; private String dmBatchId;
private String dmTemplateId; private String dmTemplateId;
private Long batchId; private String batchId;
private String report; private String report;
...@@ -31,11 +31,11 @@ public class SysBatchInfo { ...@@ -31,11 +31,11 @@ public class SysBatchInfo {
private Date lastUpdated; private Date lastUpdated;
public Long getId() { public String getId() {
return id; return id;
} }
public void setId(Long id) { public void setId(String id) {
this.id = id; this.id = id;
} }
...@@ -55,11 +55,11 @@ public class SysBatchInfo { ...@@ -55,11 +55,11 @@ public class SysBatchInfo {
this.dmTemplateId = dmTemplateId; this.dmTemplateId = dmTemplateId;
} }
public Long getBatchId() { public String getBatchId() {
return batchId; return batchId;
} }
public void setBatchId(Long batchId) { public void setBatchId(String batchId) {
this.batchId = batchId; this.batchId = batchId;
} }
......
...@@ -7,9 +7,9 @@ import java.util.Date; ...@@ -7,9 +7,9 @@ import java.util.Date;
@TableName("sms_record") @TableName("sms_record")
public class SysRecordInfo { public class SysRecordInfo {
private Long id; private String id;
private Long sysBatchId; private String sysBatchId;
private String mobile; private String mobile;
...@@ -39,19 +39,19 @@ public class SysRecordInfo { ...@@ -39,19 +39,19 @@ public class SysRecordInfo {
this.areaId = areaId; this.areaId = areaId;
} }
public Long getId() { public String getId() {
return id; return id;
} }
public void setId(Long id) { public void setId(String id) {
this.id = id; this.id = id;
} }
public Long getSysBatchId() { public String getSysBatchId() {
return sysBatchId; return sysBatchId;
} }
public void setSysBatchId(Long sysBatchId) { public void setSysBatchId(String sysBatchId) {
this.sysBatchId = sysBatchId; this.sysBatchId = sysBatchId;
} }
......
...@@ -5,5 +5,5 @@ import org.apache.ibatis.annotations.Param; ...@@ -5,5 +5,5 @@ import org.apache.ibatis.annotations.Param;
public interface XiaoShuMapper { public interface XiaoShuMapper {
String getLoginNameByTempId(@Param("tempId") String templateId); String getLoginNameByTempId(@Param("tempId") String templateId);
void updateDmhubTemp(@Param("status")String status, @Param("tempId")String tempId); void updateDmhubTemp(@Param("status")String status, @Param("tempId")String tempId,@Param("desc") String desc);
} }
...@@ -3,5 +3,5 @@ package com.bgy.sms.service; ...@@ -3,5 +3,5 @@ package com.bgy.sms.service;
public interface XiaoShuService { public interface XiaoShuService {
String selectUserIdByTemplate(String templateId); String selectUserIdByTemplate(String templateId);
void updateDmhubSmsTempStatus(String dmhubStatue, String dmTemplateId); void updateDmhubSmsTempStatus(String dmhubStatue, String dmTemplateId,String desc);
} }
...@@ -11,7 +11,7 @@ import com.bgy.sms.config.ResponseCode; ...@@ -11,7 +11,7 @@ import com.bgy.sms.config.ResponseCode;
import com.bgy.sms.repository.domain.*; import com.bgy.sms.repository.domain.*;
import com.bgy.sms.service.*; import com.bgy.sms.service.*;
import com.bgy.sms.service.bean.TemplateChangeBean; import com.bgy.sms.service.bean.TemplateChangeBean;
import com.bgy.util.id.IdHandler; import com.bgy.util.id.UUIDUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -47,6 +47,9 @@ public class MessageServiceImpl implements MessageService { ...@@ -47,6 +47,9 @@ public class MessageServiceImpl implements MessageService {
@Autowired @Autowired
private XiaoShuService xiaoShuService; private XiaoShuService xiaoShuService;
private static final String REJECTED = "rejected"; // 创建模板响应数据
private static final String APPROVED = "approved"; // 创建模板响应数据
/** /**
* 短信模板创建 * 短信模板创建
* *
...@@ -58,14 +61,14 @@ public class MessageServiceImpl implements MessageService { ...@@ -58,14 +61,14 @@ public class MessageServiceImpl implements MessageService {
log.info("进入创建短信模板业务逻辑,入参:{}", requestDTO); log.info("进入创建短信模板业务逻辑,入参:{}", requestDTO);
DmHubResponse responseDTO = new DmHubResponse(ResponseCode.SUCCESS); DmHubResponse responseDTO = new DmHubResponse(ResponseCode.SUCCESS);
String templateId = null;
try { try {
String templateContent = requestDTO.getTemplateContent(); String templateContent = requestDTO.getTemplateContent();
String signature = requestDTO.getSignature(); String signature = requestDTO.getSignature();
String smsType = requestDTO.getSmsType(); String smsType = requestDTO.getSmsType();
String tenantId = requestDTO.getTenantId(); String tenantId = requestDTO.getTenantId();
String templateId = requestDTO.getTemplateId(); templateId = requestDTO.getTemplateId();
String templateName = requestDTO.getTemplateName(); String templateName = requestDTO.getTemplateName();
// 替换模板格式,保存适合碧桂园发送短信的模板,避免发送时修改模板格式 // 替换模板格式,保存适合碧桂园发送短信的模板,避免发送时修改模板格式
TemplateChangeBean bean = dmHub2BgyTemplateSend(templateContent); TemplateChangeBean bean = dmHub2BgyTemplateSend(templateContent);
String bgySendStr = bean.getUpSendStr(); String bgySendStr = bean.getUpSendStr();
...@@ -73,6 +76,7 @@ public class MessageServiceImpl implements MessageService { ...@@ -73,6 +76,7 @@ public class MessageServiceImpl implements MessageService {
SmsTemplateInfo dbInfo = smsTemplateService.selectOne(new EntityWrapper<SmsTemplateInfo>().eq("dm_template_id", templateId)); SmsTemplateInfo dbInfo = smsTemplateService.selectOne(new EntityWrapper<SmsTemplateInfo>().eq("dm_template_id", templateId));
if (dbInfo != null) { if (dbInfo != null) {
log.error("Dm Hub请求创建模板,模板id已存在,模板id:【{}】", templateId); log.error("Dm Hub请求创建模板,模板id已存在,模板id:【{}】", templateId);
xiaoShuService.updateDmhubSmsTempStatus(REJECTED, templateId, "模板id已存在,请重新创建");
return new DmHubResponse(ResponseCode.TEMPLATE_ALREADY_EXISTED); return new DmHubResponse(ResponseCode.TEMPLATE_ALREADY_EXISTED);
} }
SmsTemplateInfo info = new SmsTemplateInfo(); SmsTemplateInfo info = new SmsTemplateInfo();
...@@ -80,7 +84,7 @@ public class MessageServiceImpl implements MessageService { ...@@ -80,7 +84,7 @@ public class MessageServiceImpl implements MessageService {
info.setType(smsType); info.setType(smsType);
info.setDmTemplateId(templateId); info.setDmTemplateId(templateId);
info.setTenantId(tenantId); info.setTenantId(tenantId);
info.setId(IdHandler.nextId()); info.setId(UUIDUtils.getId());
info.setSignature(signature); info.setSignature(signature);
info.setTemplateName(templateName); info.setTemplateName(templateName);
info.setDateCreated(new Date()); info.setDateCreated(new Date());
...@@ -91,9 +95,10 @@ public class MessageServiceImpl implements MessageService { ...@@ -91,9 +95,10 @@ public class MessageServiceImpl implements MessageService {
boolean insert = smsTemplateService.insert(info); boolean insert = smsTemplateService.insert(info);
if (!insert) { if (!insert) {
log.error("模板插入DB异常:【{}】", JSONObject.toJSONString(info)); log.error("模板插入DB异常:【{}】", JSONObject.toJSONString(info));
xiaoShuService.updateDmhubSmsTempStatus(REJECTED, templateId, "插件系统异常");
return new DmHubResponse(ResponseCode.SYSTEM_ERROR); return new DmHubResponse(ResponseCode.SYSTEM_ERROR);
} else { } else {
String pkID = info.getId() + ""; String pkID = info.getId();
String TEMPLATETYPE = ""; String TEMPLATETYPE = "";
if ("marketing".equals(smsType)) { if ("marketing".equals(smsType)) {
TEMPLATETYPE = "52"; TEMPLATETYPE = "52";
...@@ -103,6 +108,7 @@ public class MessageServiceImpl implements MessageService { ...@@ -103,6 +108,7 @@ public class MessageServiceImpl implements MessageService {
CLBizResponse response = new CLBizResponse(); CLBizResponse response = new CLBizResponse();
String account = xiaoShuService.selectUserIdByTemplate(templateId); String account = xiaoShuService.selectUserIdByTemplate(templateId);
if (StringUtils.isBlank(account)) { if (StringUtils.isBlank(account)) {
xiaoShuService.updateDmhubSmsTempStatus(REJECTED, templateId, "未找到当前登录用户的售楼系统ID");
return new DmHubResponse(ResponseCode.NO_USER_ID); return new DmHubResponse(ResponseCode.NO_USER_ID);
} }
response = bgySmsService.createTemplate(bgySendStr, account, TEMPLATETYPE, pkID); response = bgySmsService.createTemplate(bgySendStr, account, TEMPLATETYPE, pkID);
...@@ -111,15 +117,19 @@ public class MessageServiceImpl implements MessageService { ...@@ -111,15 +117,19 @@ public class MessageServiceImpl implements MessageService {
if (code.equals(ResponseCode.SUCCESS.getCode())) { if (code.equals(ResponseCode.SUCCESS.getCode())) {
SmsTemplateInfo updateInfo = new SmsTemplateInfo(); SmsTemplateInfo updateInfo = new SmsTemplateInfo();
updateInfo.setTemplateRecordId(msg); updateInfo.setTemplateRecordId(msg);
updateInfo.setId(Long.parseLong(pkID)); updateInfo.setId(pkID);
smsTemplateService.updateById(updateInfo); smsTemplateService.updateById(updateInfo);
return new DmHubResponse(ResponseCode.SUCCESS); return new DmHubResponse(ResponseCode.SUCCESS);
} else { } else {
xiaoShuService.updateDmhubSmsTempStatus(REJECTED, templateId, msg);
return new DmHubResponse(code, msg); return new DmHubResponse(code, msg);
} }
} }
} catch (Exception exception) { } catch (Exception exception) {
log.error("创建模板业务逻辑异常,错误信息", exception); log.error("创建模板业务逻辑异常,错误信息", exception);
if (!StringUtils.isBlank(templateId)) {
xiaoShuService.updateDmhubSmsTempStatus(REJECTED, templateId, "插件系统异常");
}
responseDTO = new DmHubResponse(ResponseCode.SYSTEM_ERROR); responseDTO = new DmHubResponse(ResponseCode.SYSTEM_ERROR);
} }
return responseDTO; return responseDTO;
...@@ -252,10 +262,10 @@ public class MessageServiceImpl implements MessageService { ...@@ -252,10 +262,10 @@ public class MessageServiceImpl implements MessageService {
String type = templateInfo.getType(); String type = templateInfo.getType();
// 3、记录批次信息 // 3、记录批次信息
SysBatchInfo sysBatchInfo = new SysBatchInfo(); SysBatchInfo sysBatchInfo = new SysBatchInfo();
long sysBatchId = IdHandler.nextId(); String sysBatchId = UUIDUtils.getId();
sysBatchInfo.setBatchId(sysBatchId); sysBatchInfo.setBatchId(sysBatchId);
sysBatchInfo.setDmBatchId(dmHubBatchId); sysBatchInfo.setDmBatchId(dmHubBatchId);
sysBatchInfo.setId(IdHandler.nextId()); sysBatchInfo.setId(UUIDUtils.getId());
sysBatchInfo.setDmTemplateId(templateId); sysBatchInfo.setDmTemplateId(templateId);
sysBatchInfo.setReport("1"); sysBatchInfo.setReport("1");
sysBatchInfo.setSmsNum(1); sysBatchInfo.setSmsNum(1);
...@@ -280,13 +290,11 @@ public class MessageServiceImpl implements MessageService { ...@@ -280,13 +290,11 @@ public class MessageServiceImpl implements MessageService {
} else { } else {
api = "SendNotifySMS"; api = "SendNotifySMS";
} }
response = bgySmsService.sendSms(mobile, content, channelAccount, api); response = bgySmsService.sendSms(mobile, content, channelAccount, api);
//4.短信发送记录 //4.短信发送记录
SysRecordInfo sysRecordInfo = new SysRecordInfo(); SysRecordInfo sysRecordInfo = new SysRecordInfo();
sysRecordInfo.setId(IdHandler.nextId()); sysRecordInfo.setId(UUIDUtils.getId());
long sysRecordInfoBatchId = IdHandler.nextId(); String sysRecordInfoBatchId = UUIDUtils.getId();
sysRecordInfo.setSysBatchId(sysRecordInfoBatchId); sysRecordInfo.setSysBatchId(sysRecordInfoBatchId);
sysRecordInfo.setMobile(mobile); sysRecordInfo.setMobile(mobile);
sysRecordInfo.setChargeNum(1); sysRecordInfo.setChargeNum(1);
...@@ -324,7 +332,7 @@ public class MessageServiceImpl implements MessageService { ...@@ -324,7 +332,7 @@ public class MessageServiceImpl implements MessageService {
String content = "您的验证码是:" + code; String content = "您的验证码是:" + code;
try { try {
DmCodeInfo codeInfo = new DmCodeInfo(); DmCodeInfo codeInfo = new DmCodeInfo();
codeInfo.setId(IdHandler.nextId()); codeInfo.setId(UUIDUtils.getId());
codeInfo.setAreaId(BgySMSConfig.areaId); codeInfo.setAreaId(BgySMSConfig.areaId);
codeInfo.setCode(code); codeInfo.setCode(code);
codeInfo.setMobile(mobile); codeInfo.setMobile(mobile);
...@@ -428,17 +436,17 @@ public class MessageServiceImpl implements MessageService { ...@@ -428,17 +436,17 @@ public class MessageServiceImpl implements MessageService {
dmInfo.setDmBatchId(batchId); dmInfo.setDmBatchId(batchId);
dmInfo.setDmTemplateId(templateId); dmInfo.setDmTemplateId(templateId);
dmInfo.setSmsNum(data.size()); dmInfo.setSmsNum(data.size());
dmInfo.setId(IdHandler.nextId()); dmInfo.setId(UUIDUtils.getId());
dmInfo.setDateCreated(new Date()); dmInfo.setDateCreated(new Date());
dmInfo.setLastUpdated(new Date()); dmInfo.setLastUpdated(new Date());
dmBatchService.insert(dmInfo); dmBatchService.insert(dmInfo);
SysBatchInfo info = new SysBatchInfo(); SysBatchInfo info = new SysBatchInfo();
info.setId(info.getBatchId()); String sysBatchId = UUIDUtils.getId();
info.setId(sysBatchId);
info.setDmBatchId(batchId); info.setDmBatchId(batchId);
info.setSmsNum(data.size()); info.setSmsNum(data.size());
info.setDmTemplateId(templateId); info.setDmTemplateId(templateId);
Long sysBatchId = IdHandler.nextId();
info.setBatchId(sysBatchId); info.setBatchId(sysBatchId);
info.setDateCreated(new Date()); info.setDateCreated(new Date());
info.setLastUpdated(new Date()); info.setLastUpdated(new Date());
...@@ -447,8 +455,8 @@ public class MessageServiceImpl implements MessageService { ...@@ -447,8 +455,8 @@ public class MessageServiceImpl implements MessageService {
//4.短信发送记录 //4.短信发送记录
SysRecordInfo sysRecordInfo = new SysRecordInfo(); SysRecordInfo sysRecordInfo = new SysRecordInfo();
sysRecordInfo.setId(IdHandler.nextId()); sysRecordInfo.setId(UUIDUtils.getId());
long sysRecordInfoBatchId = IdHandler.nextId(); String sysRecordInfoBatchId = UUIDUtils.getId();
sysRecordInfo.setSysBatchId(sysRecordInfoBatchId); sysRecordInfo.setSysBatchId(sysRecordInfoBatchId);
Date date = new Date(); Date date = new Date();
sysRecordInfo.setDateCreated(date); sysRecordInfo.setDateCreated(date);
...@@ -494,8 +502,7 @@ public class MessageServiceImpl implements MessageService { ...@@ -494,8 +502,7 @@ public class MessageServiceImpl implements MessageService {
return new DmHubResponse("999", "插件服务系统异常"); return new DmHubResponse("999", "插件服务系统异常");
} }
} } else {
else {
// 变量短信 // 变量短信
Set<Map.Entry<String, List<String>>> entries = paramsMap.entrySet(); Set<Map.Entry<String, List<String>>> entries = paramsMap.entrySet();
List<JSONObject> list = new ArrayList<>(); List<JSONObject> list = new ArrayList<>();
......
...@@ -25,7 +25,7 @@ public class XiaoShuServiceImpl implements XiaoShuService { ...@@ -25,7 +25,7 @@ public class XiaoShuServiceImpl implements XiaoShuService {
@Override @Override
@DB(value = DataSourceType.DB2) @DB(value = DataSourceType.DB2)
public void updateDmhubSmsTempStatus(String dmhubStatue, String dmTemplateId) { public void updateDmhubSmsTempStatus(String dmhubStatue, String dmTemplateId,String desc) {
xiaoShuMapper.updateDmhubTemp( dmhubStatue, dmTemplateId); xiaoShuMapper.updateDmhubTemp( dmhubStatue, dmTemplateId,desc);
} }
} }
This diff is collapsed.
package com.bgy.util.id; //package com.bgy.util.id;
//
//
public class IdHandler { //public class IdHandler {
private IdHandler() { // private IdHandler() {
super(); // super();
} // }
//
private static final Id id = new Id(0, 0); // private static final Id id = new Id(0, 0);
//
public static Id getInstance() { // public static Id getInstance() {
return id; // return id;
} // }
//
public static long nextId() { // public static long nextId() {
return id.nextId(); // return id.nextId();
} // }
//
public static String nextIdStr() { // public static String nextIdStr() {
return String.valueOf(nextId()); // return String.valueOf(nextId());
} // }
//
public static void main(String[] args) { // public static void main(String[] args) {
//
} // }
//
} //}
package com.bgy.util.id; //package com.bgy.util.id;
//
import java.sql.Timestamp; //import java.sql.Timestamp;
import java.util.concurrent.Executors; //import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService; //import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadFactory; //import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit; //import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong; //import java.util.concurrent.atomic.AtomicLong;
//
/** ///**
* 高并发场景下System.currentTimeMillis()的性能问题的优化 // * 高并发场景下System.currentTimeMillis()的性能问题的优化
* <p><p> // * <p><p>
* System.currentTimeMillis()的调用比new一个普通对象要耗时的多(具体耗时高出多少我还没测试过,有人说是100倍左右)<p> // * System.currentTimeMillis()的调用比new一个普通对象要耗时的多(具体耗时高出多少我还没测试过,有人说是100倍左右)<p>
* System.currentTimeMillis()之所以慢是因为去跟系统打了一次交道<p> // * System.currentTimeMillis()之所以慢是因为去跟系统打了一次交道<p>
* 后台定时更新时钟,JVM退出时,线程自动回收<p> // * 后台定时更新时钟,JVM退出时,线程自动回收<p>
* 10亿:43410,206,210.72815533980582%<p> // * 10亿:43410,206,210.72815533980582%<p>
* 1亿:4699,29,162.0344827586207%<p> // * 1亿:4699,29,162.0344827586207%<p>
* 1000万:480,12,40.0%<p> // * 1000万:480,12,40.0%<p>
* 100万:50,10,5.0%<p> // * 100万:50,10,5.0%<p>
* // *
* @author lry // * @author lry
*/ // */
public class SystemClock { //public class SystemClock {
//
private final long period; // private final long period;
private final AtomicLong now; // private final AtomicLong now;
//
private SystemClock(long period) { // private SystemClock(long period) {
this.period = period; // this.period = period;
this.now = new AtomicLong(System.currentTimeMillis()); // this.now = new AtomicLong(System.currentTimeMillis());
scheduleClockUpdating(); // scheduleClockUpdating();
} // }
//
private static class InstanceHolder { // private static class InstanceHolder {
public static final SystemClock INSTANCE = new SystemClock(1); // public static final SystemClock INSTANCE = new SystemClock(1);
} // }
//
private static SystemClock instance() { // private static SystemClock instance() {
return InstanceHolder.INSTANCE; // return InstanceHolder.INSTANCE;
} // }
//
private void scheduleClockUpdating() { // private void scheduleClockUpdating() {
ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() { // ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() {
public Thread newThread(Runnable runnable) { // public Thread newThread(Runnable runnable) {
Thread thread = new Thread(runnable, "System Clock"); // Thread thread = new Thread(runnable, "System Clock");
thread.setDaemon(true); // thread.setDaemon(true);
return thread; // return thread;
} // }
}); // });
scheduler.scheduleAtFixedRate(new Runnable() { // scheduler.scheduleAtFixedRate(new Runnable() {
public void run() { // public void run() {
now.set(System.currentTimeMillis()); // now.set(System.currentTimeMillis());
} // }
}, period, period, TimeUnit.MILLISECONDS); // }, period, period, TimeUnit.MILLISECONDS);
} // }
//
private long currentTimeMillis() { // private long currentTimeMillis() {
return now.get(); // return now.get();
} // }
//
public static long now() { // public static long now() {
return instance().currentTimeMillis(); // return instance().currentTimeMillis();
} // }
//
public static String nowDate() { // public static String nowDate() {
return new Timestamp(instance().currentTimeMillis()).toString(); // return new Timestamp(instance().currentTimeMillis()).toString();
} // }
//
} //}
package com.bgy.util.id;
import java.util.UUID;
public class UUIDUtils {
public static String getId() {
String id = UUID.randomUUID().toString().replaceAll("-", "");
return id;
}
}
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
</select> </select>
<update id="updateDmhubTemp" parameterType="string"> <update id="updateDmhubTemp" parameterType="string">
update sms_template set status = #{status} where id = #{tempId} update sms_template set status = #{status},reject_msg = #{desc} where id = #{tempId}
</update> </update>
</mapper> </mapper>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment