|
|
@@ -13,21 +13,23 @@ import common.websocket.WebSocket;
|
|
|
import utility.email.Email;
|
|
|
import utility.email.EmailContent;
|
|
|
import utility.sms.Sms;
|
|
|
+import utility.tools.Encryption;
|
|
|
+import utility.wechat.WechatService;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Calendar;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.LinkedHashSet;
|
|
|
|
|
|
/**
|
|
|
* 系统提醒公共方法,包括弹窗、短信、邮件等相关功能
|
|
|
*/
|
|
|
public class Remind {
|
|
|
-
|
|
|
-
|
|
|
/**
|
|
|
* 发送一个系统提醒,系统将自动判断发送的方式及自动生成发送的内容
|
|
|
*/
|
|
|
public static void autoRemind(Controller controller, String remindname, long dataid) throws YosException {
|
|
|
- Rows sys_remind_configsRows = controller.dbConnect.runSqlQuery("select t2.ownertable,t1.remindtitle,t1.remindmode,t1.content,t1.isrole,t1.roleids,t1.isuser,t1.userids,t1.issql,t1.sqlstr from sys_remind_configs t1 " +
|
|
|
+ Rows sys_remind_configsRows = controller.dbConnect.runSqlQuery("select t2.ownertable,t1.remindtitle,t1.remindmode,t1.content,t1.isrole,t1.roleids,t1.isuser,t1.userids,t1.issql,t1.sqlstr,t1.wechatservice_systemclient,t1.wechatservice_content,t1.systemappids from sys_remind_configs t1 " +
|
|
|
"inner join sys_remind_config t2 on t1.sys_remind_configid=t2.sys_remind_configid where siteid='" + controller.siteid + "' and t2.remindname='" + remindname + "'");
|
|
|
if (sys_remind_configsRows.isNotEmpty()) {
|
|
|
String ownertable = sys_remind_configsRows.get(0).getString("ownertable");
|
|
|
@@ -37,6 +39,7 @@ public class Remind {
|
|
|
boolean isrole = sys_remind_configsRows.get(0).getBoolean("isrole");
|
|
|
boolean isuser = sys_remind_configsRows.get(0).getBoolean("isuser");
|
|
|
boolean issql = sys_remind_configsRows.get(0).getBoolean("issql");
|
|
|
+ JSONArray systemappids = sys_remind_configsRows.get(0).getJSONArray("systemappids");
|
|
|
|
|
|
LinkedHashSet<Long> useridList = new LinkedHashSet<>();
|
|
|
if (isrole) {
|
|
|
@@ -110,6 +113,8 @@ public class Remind {
|
|
|
remind.setTitle(remindtitle);
|
|
|
remind.setToemail(User.getUserMailAddress(controller, userid));
|
|
|
remind.setContent(emailContent);
|
|
|
+ remind.setSystemappids(systemappids);
|
|
|
+
|
|
|
remind.sendByMail();
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
@@ -123,6 +128,7 @@ public class Remind {
|
|
|
Remind remind = new Remind(controller);
|
|
|
remind.setContent(content);
|
|
|
remind.setTophonenumber(User.getUserPhonenumber(controller, userid));
|
|
|
+ remind.setSystemappids(systemappids);
|
|
|
remind.sendBySms();
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
@@ -138,6 +144,7 @@ public class Remind {
|
|
|
remind.setContent(content);
|
|
|
remind.setTouserid(userid);
|
|
|
remind.setTophonenumber(User.getUserPhonenumber(controller, userid));
|
|
|
+ remind.setSystemappids(systemappids);
|
|
|
remind.sendByDialogMsg();
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
@@ -145,6 +152,79 @@ public class Remind {
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
+ case "微信公众号": {
|
|
|
+ String wechatservice_systemclient = sys_remind_configsRows.get(0).getString("wechatservice_systemclient");
|
|
|
+ JSONObject wechatservice_content = null;
|
|
|
+ try {
|
|
|
+ wechatservice_content = JSONObject.parseObject(Encryption.Decode_Base64(sys_remind_configsRows.get(0).getString("wechatservice_content").replace(" ", "\n")));
|
|
|
+ } catch (Exception e) {
|
|
|
+ wechatservice_content = new JSONObject();
|
|
|
+ }
|
|
|
+ if (wechatservice_content.isEmpty() || wechatservice_systemclient.equals("")) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ String template_id = wechatservice_content.getJSONObject("templates").getStringValue("template_id");
|
|
|
+ if (template_id.equals("")) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ String tourl = wechatservice_content.getJSONObject("data").getString("tourl");
|
|
|
+
|
|
|
+ JSONArray dataparams = wechatservice_content.getJSONObject("data").getJSONArray("param");
|
|
|
+
|
|
|
+ HashMap<String, String> datamap = new HashMap<>();
|
|
|
+ for (Object dataparam : dataparams) {
|
|
|
+ JSONObject dataparamObject = (JSONObject) dataparam;
|
|
|
+ String key = dataparamObject.getString("key");
|
|
|
+ String value = String.valueOf(dataparamObject.get("value"));
|
|
|
+
|
|
|
+
|
|
|
+ if (value.contains(":")) {
|
|
|
+ Rows datarows = controller.dbConnect.runSqlQuery("select * from " + ownertable + " where " + controller.getuniquecolumnname(ownertable) + "=" + dataid);
|
|
|
+ if (datarows.isNotEmpty()) {
|
|
|
+ for (String field : datarows.get(0).keySet()) {
|
|
|
+ if (value.contains(":" + field)) {
|
|
|
+ value = value.replace(":" + field, "'" + datarows.get(0).getString(field) + "'");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ int max2 = 10;
|
|
|
+ while (value.contains("{") && value.contains("}")) {
|
|
|
+ int start = value.indexOf("{");
|
|
|
+ int end = value.indexOf("}");
|
|
|
+ String parm = value.substring(start, end + 1);
|
|
|
+ String sql = parm.replace("{", "").replace("}", "");
|
|
|
+ Rows rows = controller.dbConnect.runSqlQuery(sql);
|
|
|
+ if (rows.size() != 1 || rows.getFieldList().size() != 1) {
|
|
|
+ break;
|
|
|
+ } else {
|
|
|
+ value = value.replace(parm, rows.get(0).getString(rows.getFieldList().get(0)));
|
|
|
+ }
|
|
|
+ if (max2-- == 0) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ datamap.put(key, value);
|
|
|
+ }
|
|
|
+
|
|
|
+ String tominiprogram_appid = "";
|
|
|
+ String tominiprogram_pagepath = "";
|
|
|
+ Rows wechatapps = controller.dbConnect.runSqlQuery("select *from sys_wechatapp where systemclient='" + wechatservice_content.getJSONObject("data").getString("tominiprogram_systemclient") + "'");
|
|
|
+ if (wechatapps.isNotEmpty()) {
|
|
|
+ tominiprogram_appid = wechatapps.get(0).getString("appid");
|
|
|
+ tominiprogram_pagepath = wechatservice_content.getJSONObject("data").getString("tominiprogram_pagepath");
|
|
|
+ }
|
|
|
+
|
|
|
+ WechatService wechatService = new WechatService(wechatservice_systemclient);
|
|
|
+ for (Long userid : useridList) {
|
|
|
+ try {
|
|
|
+ wechatService.send(userid, template_id, String.valueOf(Calendar.getInstance().getTimeInMillis()), tourl, datamap, tominiprogram_appid, tominiprogram_pagepath);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -153,6 +233,7 @@ public class Remind {
|
|
|
private String type = "";
|
|
|
private String title = "";
|
|
|
private String content = "";
|
|
|
+ private JSONArray systemappids = new JSONArray();
|
|
|
private ArrayList<String> tophonenumber = new ArrayList<>();
|
|
|
private ArrayList<String> toemail = new ArrayList<>();
|
|
|
private String objectname = "null";
|
|
|
@@ -247,6 +328,18 @@ public class Remind {
|
|
|
this.toemail = User.getUserMailAddress(controller, userid);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 邮件发送对象。邮件发送时必填
|
|
|
+ *
|
|
|
+ * @param userids
|
|
|
+ */
|
|
|
+ public void setToemails(ArrayList<Long> userids) throws YosException {
|
|
|
+ for (Long userid : userids) {
|
|
|
+ this.toemail.addAll(User.getUserMailAddress(controller, userid));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
public void setObjectname(String objectname) {
|
|
|
this.objectname = objectname;
|
|
|
}
|
|
|
@@ -283,6 +376,15 @@ public class Remind {
|
|
|
this.type = type;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 设置跳转应用id
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public void setSystemappids(JSONArray systemappids) {
|
|
|
+ this.systemappids = systemappids;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 邮件发送
|
|
|
*
|
|
|
@@ -299,8 +401,8 @@ public class Remind {
|
|
|
Email email = new Email(siteid, title, toemail);
|
|
|
if (emailContent == null) {
|
|
|
EmailContent content = new EmailContent();
|
|
|
- content.addText(title);
|
|
|
- content.addBr();
|
|
|
+// content.addText(title);
|
|
|
+// content.addBr();
|
|
|
content.addText(this.content);
|
|
|
email.send(siteid, content);
|
|
|
} else {
|
|
|
@@ -366,11 +468,13 @@ public class Remind {
|
|
|
}
|
|
|
for (Long userid : touserid) {
|
|
|
SQLFactory factory = new SQLFactory("系统消息插入");
|
|
|
+ factory.addParameter("messageid", controller.createTableID("sys_message"));
|
|
|
factory.addParameter("siteid", siteid);
|
|
|
factory.addParameter("type", type);
|
|
|
factory.addParameter("title", title);
|
|
|
factory.addParameter("message", content);
|
|
|
factory.addParameter("userid", userid);
|
|
|
+ factory.addParameter("systemappids", systemappids);
|
|
|
factory.addParameter("objectid", objectid == 0 ? "null" : objectid);
|
|
|
factory.addParameter("objectname", objectname);
|
|
|
controller.dbConnect.runSqlUpdate(factory.getSQL());
|