Commit 767e04f9 authored by qinxunjia's avatar qinxunjia

修改ID生成方式

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