|
@@ -0,0 +1,114 @@
|
|
|
+package com.example.nngkxxdp.util;
|
|
|
+
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.context.annotation.Configuration;
|
|
|
+import org.springframework.scheduling.annotation.EnableScheduling;
|
|
|
+import org.springframework.scheduling.annotation.Scheduled;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.example.nngkxxdp.dao.SmsMessageDao;
|
|
|
+
|
|
|
+import cn.hutool.core.convert.Convert;
|
|
|
+import cn.hutool.crypto.SecureUtil;
|
|
|
+import cn.hutool.http.HttpRequest;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @ApplicationName: nngkxxdp
|
|
|
+ * @Title: ArticleSmsUtil.java
|
|
|
+ * @Package: com.example.nngkxxdp.util
|
|
|
+ * @Description: 文章未更新通知主要领导、分管领导、工作人员
|
|
|
+ * @author: LEIHY
|
|
|
+ * @date: 2022年6月23日 下午8:54:56
|
|
|
+ * @version: V1.0
|
|
|
+ */
|
|
|
+@Configuration
|
|
|
+@EnableScheduling
|
|
|
+public class ArticleSmsUtil {
|
|
|
+
|
|
|
+ @Value("${sms.custom}")
|
|
|
+ private String custom;
|
|
|
+
|
|
|
+ private String contentZyld = "尊敬的{name},您好!南岸区人民政府门户网站{colume}栏目存在超期未更新情况,本单位当月政务公开工作检查考评将扣分,如在全市区县政府网站考核中被检查扣分,将纳入全区通报事项,请尽快更新。如有疑问,可与区政务办联系,联系人:林昌玫 联系电话:62988214,感谢您对政务公开工作的支持。";
|
|
|
+ private String contentFgld = "尊敬的{name},您好!南岸区人民政府门户网站{colume}栏目已经{day}天未更新,距离最低更新时限要求仅余2天,如逾期未更新将有考核扣分风险,请尽快更新。如有疑问,请与区政务办联系,联系人:林昌玫 联系电话:62988214,感谢您对政务公开工作的支持。";
|
|
|
+ private String contentGzry = "您好,南岸区人民政府门户网站{colume}栏目已有{day}天未更新,距离最低更新时限要求仅余4天,如逾期未更新将有考核扣分风险,请尽快更新。如有疑问,请与区政务办联系,联系人:林昌玫 联系电话:62988214,感谢您的支持。";
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SmsMessageDao smsMessageDao;
|
|
|
+
|
|
|
+ private void setAndSendSms(Integer type, List<Map<String, Object>> list) {
|
|
|
+ if (Blank.notBlank(list)) {
|
|
|
+ Map<String, Object> map = null;
|
|
|
+ String person = null;
|
|
|
+ String phone = null;
|
|
|
+ String chnlidname = null;
|
|
|
+ String content = null;
|
|
|
+ Integer frequency = null;
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
+ map = list.get(i);
|
|
|
+ person = Convert.toStr(map.get("main_leader"));
|
|
|
+ phone = Convert.toStr(map.get("main_leader_phone"));
|
|
|
+ chnlidname = Convert.toStr(map.get("chnlidname"));
|
|
|
+ frequency = Convert.toInt(map.get("frequency"));
|
|
|
+ if (Blank.isEmpty(person) || Blank.isEmpty(phone) || Blank.isEmpty(chnlidname)
|
|
|
+ || Blank.isEmpty(frequency)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (type == 1) {
|
|
|
+ System.err.println("文章未更新通知主要领导");
|
|
|
+ content = contentZyld.replace("{name}", person).replace("{colume}", chnlidname);
|
|
|
+ } else if (type == 2) {
|
|
|
+ System.err.println("文章未更新通知分管领导");
|
|
|
+ content = contentFgld.replace("{name}", person).replace("{colume}", chnlidname).replace("{day}",
|
|
|
+ Integer.toString(frequency - 2));
|
|
|
+ } else if (type == 3) {
|
|
|
+ System.err.println("文章未更新通知工作人员");
|
|
|
+ content = contentGzry.replace("{colume}", chnlidname).replace("{day}",
|
|
|
+ Integer.toString(frequency - 4));
|
|
|
+ }
|
|
|
+ sendSms(phone, content);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Scheduled(cron = "0 0 9 * * ?")
|
|
|
+ private void task() {
|
|
|
+ Map<String, Object> queryMap = new HashMap<>();
|
|
|
+ queryMap.put("day", 0);
|
|
|
+ List<Map<String, Object>> zyldList = smsMessageDao.getArticleFrequencyList(queryMap);
|
|
|
+ if (Blank.notBlank(zyldList)) {
|
|
|
+ setAndSendSms(1, zyldList);
|
|
|
+ }
|
|
|
+ queryMap.put("day", 2);
|
|
|
+ List<Map<String, Object>> fgldList = smsMessageDao.getArticleFrequencyList(queryMap);
|
|
|
+ if (Blank.notBlank(fgldList)) {
|
|
|
+ setAndSendSms(2, fgldList);
|
|
|
+ }
|
|
|
+ queryMap.put("day", 4);
|
|
|
+ List<Map<String, Object>> gzryList = smsMessageDao.getArticleFrequencyList(queryMap);
|
|
|
+ if (Blank.notBlank(gzryList)) {
|
|
|
+ setAndSendSms(3, gzryList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean sendSms(String phone, String sms) {
|
|
|
+ long time = new Date().getTime();
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.put("phoneNumber", phone);
|
|
|
+ map.put("content", sms);
|
|
|
+ System.err.println("phoneNumber:" + phone + "==========:" + sms);
|
|
|
+ String result = HttpRequest.post(custom).header("_t", String.valueOf(time))
|
|
|
+ .header("_yz", SecureUtil.md5(phone + "," + (sms) + "," + time)).form(map).execute().body();
|
|
|
+ System.err.println("body==========:" + result);
|
|
|
+ if (!Blank.notBlank(result)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ JSONObject obj = JSONObject.parseObject(result);
|
|
|
+ return obj.getBoolean("result");
|
|
|
+ }
|
|
|
+}
|