Commit 4fde2e08 authored by qinxunjia's avatar qinxunjia

配置存数据库

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