dev
parent
92f3a501ed
commit
b419bb0d14
|
|
@ -1,5 +1,8 @@
|
|||
package com.cowr.common;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Const {
|
||||
public static final String DEFAULT_PASSWORD = "678910"; // 新建用户默认密码
|
||||
public static final int DEFAULT_PRODUCT_ID = 1; // 默认品类id
|
||||
|
|
@ -13,4 +16,12 @@ public class Const {
|
|||
public static final String REDIS_SEPARATE = ":"; // reids 分隔符
|
||||
public static final String REDIS_CACHENAME = "mian"; // redis 默认 cache 对象别名
|
||||
public static final String REDIS_JSON = "json"; // redis 按 json 存储对象
|
||||
|
||||
public static final String TEMP_CODE_PEIE = "SMS_200713899"; // 配额分配通知
|
||||
public static Map<String, String> SMS_TEMP_MAP;
|
||||
|
||||
static {
|
||||
SMS_TEMP_MAP = new HashMap<>();
|
||||
SMS_TEMP_MAP.put("SMS_200713899", "已经在${supermarket_name}分配了${weight}吨配额,请在${date}当天安排车辆前去运输。");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,12 @@ import java.util.Date;
|
|||
public class DateTimeUtil {
|
||||
public static final String ymdhms = "yyyy-MM-dd HH:mm:ss";
|
||||
|
||||
public static final ThreadLocal<SimpleDateFormat> yMd = new ThreadLocal<SimpleDateFormat>() {
|
||||
protected SimpleDateFormat initialValue() {
|
||||
return new SimpleDateFormat("yyyyMMdd");
|
||||
}
|
||||
};
|
||||
|
||||
public static final ThreadLocal<SimpleDateFormat> sdf = new ThreadLocal<SimpleDateFormat>() {
|
||||
protected SimpleDateFormat initialValue() {
|
||||
return new SimpleDateFormat("yyyy-MM-dd");
|
||||
|
|
@ -66,6 +72,21 @@ public class DateTimeUtil {
|
|||
}
|
||||
}
|
||||
|
||||
public static boolean isEarlyDate(Date d, Date flag){
|
||||
try {
|
||||
Calendar c = Calendar.getInstance();
|
||||
c.setTime(flag);
|
||||
c.set(Calendar.HOUR_OF_DAY,0);
|
||||
c.set(Calendar.MINUTE,0);
|
||||
c.set(Calendar.SECOND,0);
|
||||
c.set(Calendar.MILLISECOND,0);
|
||||
|
||||
return d.getTime() < c.getTime().getTime();
|
||||
}catch (Exception e){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isEarlyDate(String date, Date flag){
|
||||
try {
|
||||
Date d = sdf.get().parse(date);
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ public abstract class BaseSmsLog<M extends BaseSmsLog<M>> extends BaseModel<M> i
|
|||
|
||||
/**
|
||||
* name: id
|
||||
* type: CHAR(1)
|
||||
* type: CHAR(32)
|
||||
* isNullable: NO
|
||||
* isPrimaryKey: YES
|
||||
* defaultValue:
|
||||
|
|
|
|||
|
|
@ -19,7 +19,14 @@ public class AliyunSmsService {
|
|||
this.client = new DefaultAcsClient(DefaultProfile.getProfile(regionId, accessKeyId, secret));
|
||||
}
|
||||
|
||||
public JSONObject send(String phone, String temp_code, JSONObject param) {
|
||||
public String generator(String temp_code_str, JSONObject param) {
|
||||
for (String key : param.keySet()) {
|
||||
temp_code_str = temp_code_str.replace("${" + key + "}", param.getString(key));
|
||||
}
|
||||
return "【" + SignName + "】" + temp_code_str;
|
||||
}
|
||||
|
||||
public String send(String phone, String temp_code, JSONObject param) throws Exception {
|
||||
CommonRequest request = new CommonRequest();
|
||||
request.setSysMethod(MethodType.POST);
|
||||
request.setSysDomain("dysmsapi.aliyuncs.com");
|
||||
|
|
@ -31,21 +38,16 @@ public class AliyunSmsService {
|
|||
request.putQueryParameter("PhoneNumbers", phone);
|
||||
request.putQueryParameter("TemplateCode", temp_code);
|
||||
request.putQueryParameter("TemplateParam", param.toJSONString());
|
||||
try {
|
||||
|
||||
CommonResponse response = client.getCommonResponse(request);
|
||||
|
||||
JSONObject responseData = JSONObject.parseObject(response.getData());
|
||||
// {"Message":"OK","RequestId":"F4BE9B0D-ACFE-41AF-8D64-00F2980C766B","BizId":"944915800521045297^0","Code":"OK"}
|
||||
// {"Message":"1368888888invalid mobile number","RequestId":"866EBDB2-4BCE-4052-827D-48576792631B","Code":"isv.MOBILE_NUMBER_ILLEGAL"}
|
||||
|
||||
System.out.println(responseData);
|
||||
|
||||
return responseData;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
return response.getData();
|
||||
}
|
||||
|
||||
public JSONObject query(String phone, String send_date, String bizid) {
|
||||
public String query(String phone, String send_date, String bizid) throws Exception {
|
||||
CommonRequest request = new CommonRequest();
|
||||
request.setSysMethod(MethodType.POST);
|
||||
request.setSysDomain("dysmsapi.aliyuncs.com");
|
||||
|
|
@ -58,27 +60,25 @@ public class AliyunSmsService {
|
|||
request.putQueryParameter("PageSize", "10");
|
||||
request.putQueryParameter("CurrentPage", "1");
|
||||
request.putQueryParameter("BizId", bizid);
|
||||
try {
|
||||
|
||||
CommonResponse response = client.getCommonResponse(request);
|
||||
JSONObject responseData = JSONObject.parseObject(response.getData());
|
||||
|
||||
System.out.println(responseData);
|
||||
// {"TotalCount":1,"Message":"OK","RequestId":"710D29B5-3F13-463D-9935-62D2EB763A79","Code":"OK","SmsSendDetailDTOs":{"SmsSendDetailDTO":[{"TemplateCode":"SMS_66850327","ReceiveDate":"2020-09-13 00:28:16","PhoneNum":"13627293906","Content":"【智慧砂石】2020-09-13平台异常,异常信息:Windows 10Windows 10Windows 10Windows 10Windows 10Windows 10Windows 10Windows 10Windows 10","SendStatus":3,"SendDate":"2020-09-13 00:28:10","ErrCode":"DELIVERED"}]}}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
return response.getData();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
public static void main(String[] args) throws Exception {
|
||||
AliyunSmsService sms = new AliyunSmsService();
|
||||
// sms.send(
|
||||
// "13627293906",
|
||||
// "1368888888",
|
||||
// "SMS_66850327",
|
||||
// new JSONObject()
|
||||
// .fluentPut("time", DateTimeUtil.sdf.get().format(new Date()))
|
||||
// .fluentPut("code", System.getProperty("os.name")+System.getProperty("os.name")+System.getProperty("os.name")+System.getProperty("os.name")+System.getProperty("os.name")+System.getProperty("os.name")+System.getProperty("os.name")+System.getProperty("os.name")+System.getProperty("os.name"))
|
||||
// );
|
||||
sms.query("13627293906", "20200913", "198008899928089627^0");
|
||||
String ret = sms.query("13388888888", "202000831", "857623600524988341^0");
|
||||
|
||||
System.out.println(ret);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.cowr.service.ssjygl.jobs;
|
||||
|
||||
import com.cowr.service.ssjygl.smslog.SmsService;
|
||||
import com.cowr.service.ssjygl.synctask.SyncTaskService;
|
||||
import com.jfinal.log.Log;
|
||||
import org.quartz.Job;
|
||||
|
|
@ -10,6 +11,16 @@ public class SyncJob implements Job {
|
|||
private static Log log = Log.getLog(SyncJob.class);
|
||||
@Override
|
||||
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
|
||||
try {
|
||||
SyncTaskService.me.task();
|
||||
}catch (Exception e){
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
|
||||
try {
|
||||
SmsService.me.checkSendStatus();
|
||||
}catch (Exception e){
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import com.cowr.common.view.Result;
|
|||
import com.cowr.model.*;
|
||||
import com.cowr.service.ssjygl.base.BaseSyncService;
|
||||
import com.cowr.service.ssjygl.main.SvrCacheData;
|
||||
import com.cowr.service.ssjygl.smslog.SmsService;
|
||||
import com.cowr.service.ssjygl.synctask.SyncTaskService;
|
||||
import com.cowr.ssjygl.modifylog.ModifyLogService;
|
||||
import com.cowr.ssjygl.order.ordercluster.OrderclusterService;
|
||||
|
|
@ -72,6 +73,7 @@ public class OrderclusterSyncService extends BaseSyncService {
|
|||
}
|
||||
|
||||
List<Ordercluster> newlist = new ArrayList<>();
|
||||
List<String> uuids = new ArrayList<>();
|
||||
Map<Integer, SyncTask> syncmap = new HashMap<>();
|
||||
List<Integer> chksup = new ArrayList<>();
|
||||
|
||||
|
|
@ -160,6 +162,8 @@ public class OrderclusterSyncService extends BaseSyncService {
|
|||
model.setPayType(2);
|
||||
model.setUuid(StrKit.getRandomUUID());
|
||||
|
||||
uuids.add(model.getUuid());
|
||||
|
||||
newlist.add(model);
|
||||
syncmap.get(supermarket_id).addSaveData(model);
|
||||
} catch (Exception e) {
|
||||
|
|
@ -200,6 +204,13 @@ public class OrderclusterSyncService extends BaseSyncService {
|
|||
}
|
||||
});
|
||||
|
||||
if (ret) {
|
||||
List<Ordercluster> orderclusters = Ordercluster.dao.find("select * from ordercluster t where t.uuid in ('" + StrKit.join(uuids, "', '") + "')");
|
||||
for (Ordercluster cluster : orderclusters) {
|
||||
SmsService.me.sendPeiE(cluster);
|
||||
}
|
||||
}
|
||||
|
||||
return ret ? Result.success() : Result.failed("创建失败");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,168 @@
|
|||
package com.cowr.service.ssjygl.smslog;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.cowr.common.Const;
|
||||
import com.cowr.common.enums.UserTypeEnum;
|
||||
import com.cowr.common.utils.DateTimeUtil;
|
||||
import com.cowr.model.Ordercluster;
|
||||
import com.cowr.model.SmsLog;
|
||||
import com.cowr.model.Supermarket;
|
||||
import com.cowr.model.Sysuser;
|
||||
import com.cowr.service.ssjygl.main.SvrCacheData;
|
||||
import com.cowr.sms.AliyunSmsService;
|
||||
import com.jfinal.kit.StrKit;
|
||||
import com.jfinal.log.Log;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class SmsService {
|
||||
private static Log log = Log.getLog(SmsService.class);
|
||||
public static SmsService me = new SmsService();
|
||||
|
||||
private AliyunSmsService aliyunsms;
|
||||
|
||||
public SmsService() {
|
||||
this.aliyunsms = new AliyunSmsService();
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送配额通知短信
|
||||
* 模版内容: 已经在${supermarket_name}分配了${weight}吨配额,请在${date}当天安排车辆前去运输。
|
||||
* 变量属性: supermarket_name-其他;weight-其他;date-时间;
|
||||
*
|
||||
* @param ordercluster
|
||||
* @return
|
||||
*/
|
||||
public boolean sendPeiE(Ordercluster ordercluster) {
|
||||
Date now = new Date();
|
||||
if (ordercluster == null) {
|
||||
log.error("集团订单信息错误");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ordercluster.getCustomerId() == null) {
|
||||
log.error("集团订单没有关联用户信息");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ordercluster.getCutoffTime() == null) {
|
||||
log.error("集团订单运输截止时间错误 %s", ordercluster.getCutoffTime());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (DateTimeUtil.isEarlyDate(ordercluster.getCutoffTime(), now)) {
|
||||
log.error("集团订单截止时间不能早于当天 %s", ordercluster.getCutoffTime());
|
||||
return false;
|
||||
}
|
||||
|
||||
List<Sysuser> users = Sysuser.dao.find("select * from sysuser t where t.type = ? and t.entity_id = ?", UserTypeEnum.CUSTOMER.getTypeid(), ordercluster.getCustomerId());
|
||||
|
||||
if (users == null || users.isEmpty()) {
|
||||
log.error("没有找到有效的用户信息");
|
||||
return false;
|
||||
}
|
||||
|
||||
Supermarket supermarket = SvrCacheData.SUP_CACHE.get(ordercluster.getSupermarketId());
|
||||
|
||||
if (supermarket == null) {
|
||||
log.error("集团订单关联砂站信息错误");
|
||||
return false;
|
||||
}
|
||||
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("supermarket_name", supermarket.getName());
|
||||
obj.put("date", DateTimeUtil.sdfymd.get().format(ordercluster.getCutoffTime()));
|
||||
obj.put("weight", String.format("%.2f", ordercluster.getTotalWeight()));
|
||||
|
||||
String content = this.aliyunsms.generator(Const.SMS_TEMP_MAP.get(Const.SMS_TEMP_MAP), obj);
|
||||
|
||||
for (Sysuser sysuser : users) {
|
||||
try {
|
||||
String phone = sysuser.getPhone();
|
||||
|
||||
log.debug("给 %s 发送短信", phone);
|
||||
|
||||
String response = this.aliyunsms.send("13688888888", Const.TEMP_CODE_PEIE, obj);
|
||||
log.debug(response);
|
||||
|
||||
JSONObject ret = JSONObject.parseObject(response);
|
||||
|
||||
SmsLog smslog = new SmsLog();
|
||||
smslog.setId(StrKit.getRandomUUID());
|
||||
smslog.setPhone(phone);
|
||||
smslog.setContent(obj.toJSONString());
|
||||
smslog.setCreateTime(now);
|
||||
smslog.setSendcontent(content);
|
||||
|
||||
if (ret.containsKey("BizId")) {
|
||||
smslog.setBizid(ret.getString("BizId"));
|
||||
}
|
||||
|
||||
if (ret.containsKey("Code")) {
|
||||
smslog.setCode(ret.getString("Code"));
|
||||
}
|
||||
|
||||
if (ret.containsKey("RequestId")) {
|
||||
smslog.setRequestid(ret.getString("RequestId"));
|
||||
}
|
||||
|
||||
if (ret.containsKey("RequestId")) {
|
||||
smslog.setRequestid(ret.getString("RequestId"));
|
||||
}
|
||||
|
||||
smslog.setRelateTable(ordercluster.getTablename());
|
||||
smslog.setRelateId(ordercluster.getId().toString());
|
||||
|
||||
smslog.save();
|
||||
}catch (Exception e){
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void checkSendStatus(){
|
||||
List<SmsLog> logs = SmsLog.dao.find("select * from sms_log t where t.code = 'OK' and t.sendstatus is null limit 500");
|
||||
|
||||
log.debug("检查 %s 短信发送状态", logs.size());
|
||||
|
||||
for(SmsLog smslog : logs){
|
||||
try {
|
||||
String response = this.aliyunsms.query(smslog.getPhone(), DateTimeUtil.yMd.get().format(smslog.getCreateTime()), smslog.getBizid());
|
||||
log.debug(response);
|
||||
|
||||
JSONObject ret = JSONObject.parseObject(response);
|
||||
|
||||
if ("OK".equals(ret.getString("Code"))) {
|
||||
if(ret.getInteger("TotalCount") == 0){
|
||||
log.debug("还未处理完成,没有查询到发送结果");
|
||||
continue;
|
||||
}
|
||||
|
||||
JSONObject detail = ret.getJSONObject("SmsSendDetailDTOs").getJSONArray("SmsSendDetailDTO").getJSONObject(0);
|
||||
|
||||
smslog.setReceivedate(detail.getDate("ReceiveDate"));
|
||||
smslog.setSendcontent(detail.getString("Content"));
|
||||
smslog.setSenddate(detail.getDate("SendDate"));
|
||||
smslog.setSendstatus(detail.getIntValue("SendStatus"));
|
||||
|
||||
if(smslog.getSendcontent() != null){
|
||||
int len = smslog.getSendcontent().length();
|
||||
if(len <= 70){
|
||||
smslog.setBillNum(1);
|
||||
}else{
|
||||
smslog.setBillNum((int) Math.ceil(len/67.0));
|
||||
}
|
||||
}
|
||||
|
||||
smslog.update();
|
||||
}
|
||||
}catch (Exception e){
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue