Commit 4fde2e08 authored by qinxunjia's avatar qinxunjia

配置存数据库

parent d2273057
......@@ -15,7 +15,6 @@ public class BgySMSConfig {
// 请求地址
public static String url;
// 项目楼盘ID
public static String areaId;
// api
public static String api;
......@@ -35,11 +34,6 @@ public class BgySMSConfig {
BgySMSConfig.url = url;
}
@Value("${system.config.bgy.areaId}")
public void setAreaId(String areaId) {
BgySMSConfig.areaId = areaId;
}
@Value("${system.config.bgy.api}")
public void setApi(String api) {
BgySMSConfig.api = api;
......
......@@ -10,11 +10,11 @@ import java.util.List;
public interface BgySmsService {
CLBizResponse sendSms(String mobile, String content, String areaId,String api) throws Exception;
CLBizResponse sendSms(String mobile, String content, String areaId, String subModule, String api) throws Exception;
CLBizResponse sendBatchSms(List<JSONObject> data, String areaId, String api, String templateId) throws Exception;
CLBizResponse sendBatchSms(List<JSONObject> data, String areaId, String subModule, String api, String templateId) throws Exception;
CLBizResponse createTemplate(String content,String account,String templateType,String pkID) throws Exception;
CLBizResponse createTemplate(String content, String areaId, String account, String templateType, String pkID) throws Exception;
BGYResponse asyncNotify(TemplateNotify templateNotify);
}
......@@ -59,7 +59,7 @@ public class BgySmsServiceImpl implements BgySmsService {
private XiaoShuService xiaoShuService;
@Override
public CLBizResponse sendSms(String mobile, String content, String areaId, String api) throws Exception {
public CLBizResponse sendSms(String mobile, String content, String areaId, String subModule, String api) throws Exception {
log.info("进入碧桂园短信发送接口");
String appId = BgySMSConfig.appId;
String securityCode = BgySMSConfig.securityCode;
......@@ -71,8 +71,8 @@ public class BgySmsServiceImpl implements BgySmsService {
requestParams.put("api", api);
requestParams.put("appId", appId);
requestParams.put("security", Md5Util.encrypt(appId + securityCode.toUpperCase()));
requestParams.put("areaId", BgySMSConfig.areaId);
requestParams.put("subModule", areaId);
requestParams.put("areaId", areaId);
requestParams.put("subModule", subModule);
requestParams.put("content", content);
requestParams.put("mobile", mobile);
log.info("碧桂园短信接口参数:{}", requestParams);
......@@ -96,7 +96,7 @@ public class BgySmsServiceImpl implements BgySmsService {
}
@Override
public CLBizResponse sendBatchSms(List<JSONObject> data, String areaId, String api, String templateId) throws Exception {
public CLBizResponse sendBatchSms(List<JSONObject> data, String areaId, String subModule, String api, String templateId) throws Exception {
log.info("进入碧桂园短信发送接口");
String appId = BgySMSConfig.appId;
String securityCode = BgySMSConfig.securityCode;
......@@ -105,8 +105,8 @@ public class BgySmsServiceImpl implements BgySmsService {
requestParams.put("api", api);
requestParams.put("appId", appId);
requestParams.put("security", Md5Util.encrypt(appId + securityCode.toUpperCase()));
requestParams.put("areaId", BgySMSConfig.areaId);
requestParams.put("subModule", areaId);
requestParams.put("areaId", areaId);
requestParams.put("subModule", subModule);
requestParams.put("templateId", templateId);
requestParams.put("data", data);
log.info("碧桂园短信接口参数:{}", requestParams);
......@@ -164,7 +164,7 @@ public class BgySmsServiceImpl implements BgySmsService {
@Override
public CLBizResponse createTemplate(String content, String account, String templateType, String pkID) throws Exception {
public CLBizResponse createTemplate(String content, String areaId, String account, String templateType, String pkID) throws Exception {
log.info("进入碧桂园创建模板接口");
String appId = BgySMSConfig.appId;
String securityCode = BgySMSConfig.securityCode;
......@@ -173,7 +173,7 @@ public class BgySmsServiceImpl implements BgySmsService {
param.put("appid", appId);
param.put("security", Md5Util.encrypt(appId + securityCode.toUpperCase()));
param.put("content", content);
param.put("areaid", BgySMSConfig.areaId);
param.put("areaid", areaId);
param.put("pkID", pkID);
param.put("slxtID", account);
param.put("templateType", templateType);
......
......@@ -5,6 +5,6 @@ package com.bgy.sms.repository.mapper;
*/
public interface MessageMapper {
// int createTemplate(XXXX....)
String selectAreaId();
}
......@@ -10,6 +10,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.repository.domain.*;
import com.bgy.sms.repository.mapper.MessageMapper;
import com.bgy.sms.service.*;
import com.bgy.sms.service.bean.TemplateChangeBean;
import com.bgy.util.id.UUIDUtils;
......@@ -41,12 +42,12 @@ public class MessageServiceImpl implements MessageService {
private DmBatchService dmBatchService;
@Autowired
private DmCodeService dmCodeService;
@Autowired
private SysRecordService sysRecordService;
@Autowired
private XiaoShuService xiaoShuService;
@Autowired
private MessageMapper messageMapper;
private static final String REJECTED = "rejected"; // 创建模板响应数据
private static final String APPROVED = "approved"; // 创建模板响应数据
......@@ -83,6 +84,10 @@ public class MessageServiceImpl implements MessageService {
log.error("Dm Hub请求创建模板,模板id已存在,模板id:【{}】", templateId);
return new DmHubResponse(ResponseCode.TEMPLATE_ALREADY_EXISTED);
}
String areaId = messageMapper.selectAreaId();
if (StringUtils.isBlank(areaId)) {
return new DmHubResponse("500", "未获取到项目ID,请检查area_info配置");
}
SmsTemplateInfo info = new SmsTemplateInfo();
info.setContent(templateContent);
info.setType(smsType);
......@@ -112,7 +117,7 @@ public class MessageServiceImpl implements MessageService {
if (StringUtils.isBlank(account)) {
return new DmHubResponse(ResponseCode.NO_USER_ID);
}
response = bgySmsService.createTemplate(upCreateStr, account, TEMPLATETYPE, pkID);
response = bgySmsService.createTemplate(upCreateStr, areaId, account, TEMPLATETYPE, pkID);
String code = response.getCode();
String msg = response.getMsg();
if (code.equals(ResponseCode.SUCCESS.getCode())) {
......@@ -221,6 +226,11 @@ public class MessageServiceImpl implements MessageService {
if (templateInfo.getStatus().equals("abnormal")) {
return new DmHubResponse("1001", "短信模板正在审核中,请稍后重试");
}
String areaId = messageMapper.selectAreaId();
if (StringUtils.isBlank(areaId)) {
return new DmHubResponse("500", "未获取到项目ID,请检查area_info配置");
}
String params = templateInfo.getParams();
JSONArray paramsArr = JSONArray.parseArray(params);
String smsType = templateInfo.getType();
......@@ -281,7 +291,7 @@ public class MessageServiceImpl implements MessageService {
} else {
api = "SendNotifySMS";
}
response = bgySmsService.sendSms(mobile, content, channelAccount, api);
response = bgySmsService.sendSms(mobile, content, areaId, channelAccount, api);
//4.短信发送记录
SysRecordInfo sysRecordInfo = new SysRecordInfo();
sysRecordInfo.setId(UUIDUtils.getId());
......@@ -322,14 +332,18 @@ public class MessageServiceImpl implements MessageService {
CLBizResponse response = new CLBizResponse();
String content = "您的验证码是:" + code;
try {
String areaId = messageMapper.selectAreaId();
if (StringUtils.isBlank(areaId)) {
return new DmHubResponse("500", "未获取到项目ID,请检查area_info配置");
}
DmCodeInfo codeInfo = new DmCodeInfo();
codeInfo.setId(UUIDUtils.getId());
codeInfo.setAreaId(BgySMSConfig.areaId);
codeInfo.setAreaId(areaId);
codeInfo.setCode(code);
codeInfo.setMobile(mobile);
codeInfo.setDateCreated(new Date());
dmCodeService.insert(codeInfo);
response = bgySmsService.sendSms(mobile, content, BgySMSConfig.areaId, null);
response = bgySmsService.sendSms(mobile, content, areaId, null, null);
String retCode = response.getCode();
if (retCode.equals(ResponseCode.SUCCESS.getCode())) {
return new DmHubResponse(ResponseCode.SUCCESS);
......@@ -453,6 +467,11 @@ public class MessageServiceImpl implements MessageService {
sysRecordInfo.setDateCreated(date);
sysRecordInfo.setLastUpdated(date);
sysRecordInfo.setAreaId(channelAccount);
// TODO 获取AreaId;
String areaId = messageMapper.selectAreaId();
if (StringUtils.isBlank(areaId)) {
return new DmHubResponse("500", "未获取到项目ID,请检查area_info配置");
}
if (paramsArr == null || paramsArr.isEmpty()) {
List<JSONObject> list = new ArrayList<>();
......@@ -467,7 +486,7 @@ public class MessageServiceImpl implements MessageService {
}
try {
if (!list.isEmpty()) {
response = bgySmsService.sendBatchSms(list, channelAccount, api, templateRecordId);
response = bgySmsService.sendBatchSms(list, areaId, channelAccount, api, templateRecordId);
String code = response.getCode();
if (code.equals(ResponseCode.SUCCESS.getCode())) {
sysRecordInfo.setChargeNum(list.size());
......@@ -510,7 +529,7 @@ public class MessageServiceImpl implements MessageService {
list.add(jsonObject);
}
try {
response = bgySmsService.sendBatchSms(list, channelAccount, api, templateRecordId);
response = bgySmsService.sendBatchSms(list, areaId, channelAccount, api, templateRecordId);
String code = response.getCode();
if (code.equals(ResponseCode.SUCCESS.getCode())) {
sysRecordInfo.setChargeNum(list.size());
......
......@@ -2,4 +2,8 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bgy.sms.repository.mapper.MessageMapper">
<select id="selectAreaId" resultType="string">
select area_id from area_info limit 1;
</select>
</mapper>
\ No newline at end of file
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