Commit 3caee45f by ilal Committed by chenzg

消息提醒

parent 80338fca
package cn.timer.api.controller.htzz.atttimer;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import cn.timer.api.bean.admin.AdminMsgTemplate;
import cn.timer.api.bean.htzz.HtzzAdminZzda;
import cn.timer.api.config.enums.PinType;
import cn.timer.api.controller.kqgl.ClockInTool;
@Transactional
@Component
public class AlicloudSMS {
@Value("${config-8timer.Aliyun.PROJECT_NAME}")
public String PROJECT_NAME;
@Value("${config-8timer.Aliyun.REGION_ID}")
public String REGION_ID;
@Value("${config-8timer.Aliyun.ACCESSKEY_ID}")
public String ACCESSKEY_ID;
@Value("${config-8timer.Aliyun.SECRET}")
public String SECRET;
final static String CODE_NAME = "TemplateCode";// 短信模板代码参数名
final static String TEMPLATE_PARAM = "TemplateParam";// 自定义参数
final static String DOMAIN = "dysmsapi.aliyuncs.com";
final static String VERSION = "2017-05-25";
final static String ACTION_SEND = "SendSms"; // 发短信
final static String ACTION_QUERY = "QuerySendDetails"; // 短信查询
final static String PAGE_SIZE = "1";
final static String CURRENT_PAGE = "1";
/**
* 提醒功能
*/
@SuppressWarnings("deprecation")
public List<Object> remind(HtzzAdminZzda zzda, String phone,String tzname) {
//短信模板详情
AdminMsgTemplate dxmb = AdminMsgTemplate.builder().id(zzda.getTemplateId()).build().selectById();
String str = dxmb.getContent();
String code = dxmb.getPlatformNum();
DefaultProfile profile = DefaultProfile.getProfile(REGION_ID, ACCESSKEY_ID, SECRET);
IAcsClient client = new DefaultAcsClient(profile);
CommonRequest request = new CommonRequest();
request.setMethod(MethodType.POST);
request.setDomain(DOMAIN);
request.setVersion(VERSION);
request.setAction(ACTION_SEND);
request.putQueryParameter("RegionId", REGION_ID);
request.putQueryParameter("PhoneNumbers", phone);
request.putQueryParameter("SignName", PROJECT_NAME);
request.putQueryParameter(CODE_NAME, code);//模版CODE
ArrayList<String> word = new ArrayList<String>();
int m = 0, n = 0;
int count = 0;
for (int i = 0; i < str.length(); i++) {
if (str.charAt(i) == '{') {
if (count == 0) {
m = i;
}
count++;
}
if (str.charAt(i) == '}') {
count--;
if (count == 0) {
n = i;
word.add(str.substring(m, n + 1).replace("{","").replace("}",""));
}
}
}
JsonArray array=new JsonArray();
JsonObject lan=new JsonObject();
for (String bl : word) {
if(bl.equals("name")) {
lan.addProperty(bl, tzname);
}else if(bl.equals("yxdqr")){
lan.addProperty(bl, ClockInTool.SunNovCSTYMD(zzda.getYxdqr()));
}else {
String strjson = JSON.toJSONString(zzda);
JSONObject jsonObject = JSONObject.parseObject(strjson);
String value = jsonObject.getString(bl);
lan.addProperty(bl, value);
}
}
array.add(lan);
String SMSformat = String.valueOf(array).replace("[","").replace("]","");
System.out.println(SMSformat);
//短信模板格式
request.putQueryParameter(TEMPLATE_PARAM,SMSformat);
CommonResponse response = null;
String a = null;
try {
response = client.getCommonResponse(request);
a = response.getData();
System.err.println("response:"+a); // 短信服务响应内容
} catch (ServerException e) {
e.printStackTrace();
} catch (ClientException e) {
e.printStackTrace();
}
Integer id = null;
if (a != null && a.contains("OK")) {
List<Object> list = new ArrayList<Object>();
list.add(id);
list.add(JSONObject.parseObject(response.getData()));
return list;// 代表请求成功
}
return null;
}
}
package cn.timer.api.controller.htzz.atttimer;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import cn.timer.api.bean.htzz.HtzzAdminZzda;
import cn.timer.api.bean.htzz.HtzzAssoHtgx;
import cn.timer.api.bean.htzz.HtzzAssoZztx;
import cn.timer.api.controller.kqgl.ClockInTool;
/**
* 消息定时器
*
*/
@Configuration // 1.主要用于标记配置类,兼备Component的效果。
@EnableScheduling // 2.开启定时任务
public class NewsTaskTiming {
@Autowired
private AlicloudSMS sms;
@Scheduled(cron = "0 33 14 * * ?")
public void MessageAlert() throws ParseException {
//当前时间
String nowdate = new SimpleDateFormat("yyyy-MM-dd").format(new Date()).toString();//
List<HtzzAdminZzda> htzzs = HtzzAdminZzda.builder().build().selectList(new QueryWrapper<HtzzAdminZzda>().lambda().eq(HtzzAdminZzda::getTxkgType, 1)
.ge(HtzzAdminZzda::getYxdqr, nowdate));
for(HtzzAdminZzda zz : htzzs) {
String dqrq = ClockInTool.SunNovCSTYMD(zz.getYxdqr());//有效期到期日
//合同证照提醒表设置
HtzzAssoZztx zzsz = HtzzAssoZztx.builder().build().selectOne(new QueryWrapper<HtzzAssoZztx>().lambda().eq(HtzzAssoZztx::getZzdaId, zz.getId()));
if(zzsz != null) {
int txsj = zzsz.getTxsj();//提醒时间周期 0-到期提醒 1-提前一天 2-提前二天 ...
String tqsj = ClockInTool.requires_extra_times(dqrq,-txsj,3,1);
if(nowdate.equals(tqsj)) {
List<HtzzAssoHtgx> txrs = HtzzAssoHtgx.builder().build().selectList(new QueryWrapper<HtzzAssoHtgx>().lambda().eq(HtzzAssoHtgx::getHtid, zz.getId()));
for(HtzzAssoHtgx rt : txrs) {
//发送短信
List<Object> list = sms.remind(zz, rt.getPhone(),rt.getName());
}
}
}
}
}
}
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