From dec2e227d9219a1ccff32c6c82e4cf32b19bce24 Mon Sep 17 00:00:00 2001 From: Wizzer Date: Wed, 15 Feb 2017 12:50:20 +0800 Subject: [PATCH] =?UTF-8?q?add:=20=E6=89=A9=E5=B1=95=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E7=B1=BB=20&=20fix:=20=E5=90=AF=E5=8A=A8=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=BB=BA=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/wizzer/app/web/commons/core/Setup.java | 4 +- .../app/web/commons/quartz/job/TestJob.java | 33 +++ .../commons/services/email/EmailService.java | 34 +++ .../services/qrcode/QrcodeService.java | 53 +++++ .../web/commons/services/wx/TplService.java | 66 ++++++ .../web/commons/services/wx/WxHandler.java | 195 ++++++++++++++++++ .../controllers/open/wx/WeixinController.java | 2 +- .../platform/sys/SysTaskController.java | 52 +++++ .../views/platform/sys/task/index.html | 20 ++ 9 files changed, 456 insertions(+), 3 deletions(-) create mode 100644 wk-app/wk-web/src/main/java/cn/wizzer/app/web/commons/quartz/job/TestJob.java create mode 100644 wk-app/wk-web/src/main/java/cn/wizzer/app/web/commons/services/email/EmailService.java create mode 100644 wk-app/wk-web/src/main/java/cn/wizzer/app/web/commons/services/qrcode/QrcodeService.java create mode 100644 wk-app/wk-web/src/main/java/cn/wizzer/app/web/commons/services/wx/TplService.java create mode 100644 wk-app/wk-web/src/main/java/cn/wizzer/app/web/commons/services/wx/WxHandler.java diff --git a/wk-app/wk-web/src/main/java/cn/wizzer/app/web/commons/core/Setup.java b/wk-app/wk-web/src/main/java/cn/wizzer/app/web/commons/core/Setup.java index ff40a2629..5f768622c 100644 --- a/wk-app/wk-web/src/main/java/cn/wizzer/app/web/commons/core/Setup.java +++ b/wk-app/wk-web/src/main/java/cn/wizzer/app/web/commons/core/Setup.java @@ -127,7 +127,7 @@ private void initSysTask(NutConfig config, Dao dao) { Sys_task task = new Sys_task(); task.setDisabled(true); task.setName("测试任务"); - task.setJobClass("cn.wizzer.common.quartz.job.TestJob"); + task.setJobClass("cn.wizzer.app.web.commons.quartz.job.TestJob"); task.setCron("*/5 * * * * ?"); task.setData("{\"hi\":\"Wechat:wizzer | send red packets of support,thank u\"}"); task.setNote("微信号:wizzer | 欢迎发送红包以示支持,多谢。。"); @@ -157,7 +157,7 @@ private void initSysTask(NutConfig config, Dao dao) { * @param dao */ private void initSysData(NutConfig config, Dao dao) { - Daos.createTablesInPackage(dao, "cn.wizzer.modules", false); + Daos.createTablesInPackage(dao, "cn.wizzer.app", false); // 若必要的数据表不存在,则初始化数据库 if (0 == dao.count(Sys_user.class)) { //初始化配置表 diff --git a/wk-app/wk-web/src/main/java/cn/wizzer/app/web/commons/quartz/job/TestJob.java b/wk-app/wk-web/src/main/java/cn/wizzer/app/web/commons/quartz/job/TestJob.java new file mode 100644 index 000000000..76f8d1770 --- /dev/null +++ b/wk-app/wk-web/src/main/java/cn/wizzer/app/web/commons/quartz/job/TestJob.java @@ -0,0 +1,33 @@ +package cn.wizzer.app.web.commons.quartz.job; + +import cn.wizzer.app.sys.modules.models.Sys_task; +import org.nutz.dao.Chain; +import org.nutz.dao.Cnd; +import org.nutz.dao.Dao; +import org.nutz.ioc.loader.annotation.Inject; +import org.nutz.ioc.loader.annotation.IocBean; +import org.nutz.log.Log; +import org.nutz.log.Logs; +import org.quartz.Job; +import org.quartz.JobDataMap; +import org.quartz.JobExecutionContext; +import org.quartz.JobExecutionException; + +/** + * Created by Wizzer.cn on 2015/6/27. + */ +@IocBean +public class TestJob implements Job { + + private static final Log log = Logs.get(); + @Inject + protected Dao dao; + + public void execute(JobExecutionContext context) throws JobExecutionException { + JobDataMap data = context.getJobDetail().getJobDataMap(); + String taskId = context.getJobDetail().getKey().getName(); + String hi = data.getString("hi"); + log.info("Test Job hi::" + hi); + dao.update(Sys_task.class, Chain.make("exeAt", (int) (System.currentTimeMillis() / 1000)).add("exeResult", "执行成功"), Cnd.where("id", "=", taskId)); + } +} diff --git a/wk-app/wk-web/src/main/java/cn/wizzer/app/web/commons/services/email/EmailService.java b/wk-app/wk-web/src/main/java/cn/wizzer/app/web/commons/services/email/EmailService.java new file mode 100644 index 000000000..5ef46ab3f --- /dev/null +++ b/wk-app/wk-web/src/main/java/cn/wizzer/app/web/commons/services/email/EmailService.java @@ -0,0 +1,34 @@ +package cn.wizzer.app.web.commons.services.email; + +import org.apache.commons.mail.HtmlEmail; +import org.nutz.ioc.Ioc; +import org.nutz.ioc.loader.annotation.Inject; +import org.nutz.ioc.loader.annotation.IocBean; +import org.nutz.log.Log; +import org.nutz.log.Logs; + +/** + * Created by Wizzer on 2016/7/31. + */ +@IocBean +public class EmailService { + private static final Log log = Logs.get(); + + @Inject("refer:$ioc") + protected Ioc ioc; + + public boolean send(String to, String subject, String html) { + try { + HtmlEmail email = ioc.get(HtmlEmail.class); + email.setSubject(subject); + email.setHtmlMsg(html); + email.addTo(to); + email.buildMimeMessage(); + email.sendMimeMessage(); + return true; + } catch (Throwable e) { + log.info("send email fail", e); + return false; + } + } +} diff --git a/wk-app/wk-web/src/main/java/cn/wizzer/app/web/commons/services/qrcode/QrcodeService.java b/wk-app/wk-web/src/main/java/cn/wizzer/app/web/commons/services/qrcode/QrcodeService.java new file mode 100644 index 000000000..999975333 --- /dev/null +++ b/wk-app/wk-web/src/main/java/cn/wizzer/app/web/commons/services/qrcode/QrcodeService.java @@ -0,0 +1,53 @@ +package cn.wizzer.app.web.commons.services.qrcode; + +import com.google.zxing.BarcodeFormat; +import com.google.zxing.EncodeHintType; +import com.google.zxing.MultiFormatWriter; +import com.google.zxing.WriterException; +import com.google.zxing.client.j2se.MatrixToImageWriter; +import com.google.zxing.common.BitMatrix; +import org.nutz.ioc.loader.annotation.IocBean; +import org.nutz.lang.Strings; +import org.nutz.log.Log; +import org.nutz.log.Logs; +import org.nutz.mvc.view.HttpStatusView; + +import java.util.HashMap; +import java.util.Map; + +/** + * Created by Wizzer on 2016/7/31. + */ +@IocBean +public class QrcodeService { + private static final Log log = Logs.get(); + + protected MultiFormatWriter writer = new MultiFormatWriter(); + public Object get(String data, int w, int h) { + if (Strings.isBlank(data)) + return new HttpStatusView(404); + // 修正长宽 + if (w < 1) + w = 256; + else if (w > 1024) + w = 1024; + if (h < 1) + h = 256; + else if (h > 1024) + h = 1024; + // 接受Base64编码,例如内容是中文 + byte[] tmp = data.getBytes(); + if (tmp != null) + data = new String(tmp); + try { + Map hints = new HashMap(); + hints.put(EncodeHintType.CHARACTER_SET, "utf-8"); + BitMatrix matrix = writer.encode(data, BarcodeFormat.QR_CODE, w, h, hints); + return MatrixToImageWriter.toBufferedImage(matrix); + } catch (WriterException e) { + // 生成失败,一般是文本太长,指定的尺寸放不下 + log.debug("qrcode write fail", e); + return new HttpStatusView(500); + } + } +} diff --git a/wk-app/wk-web/src/main/java/cn/wizzer/app/web/commons/services/wx/TplService.java b/wk-app/wk-web/src/main/java/cn/wizzer/app/web/commons/services/wx/TplService.java new file mode 100644 index 000000000..beb40fda1 --- /dev/null +++ b/wk-app/wk-web/src/main/java/cn/wizzer/app/web/commons/services/wx/TplService.java @@ -0,0 +1,66 @@ +package cn.wizzer.app.web.commons.services.wx; + +import cn.wizzer.app.wx.modules.models.Wx_tpl_id; +import cn.wizzer.app.wx.modules.models.Wx_tpl_log; +import cn.wizzer.app.wx.modules.models.Wx_user; +import cn.wizzer.app.wx.modules.services.WxConfigService; +import cn.wizzer.app.wx.modules.services.WxTplIdService; +import cn.wizzer.app.wx.modules.services.WxTplLogService; +import cn.wizzer.app.wx.modules.services.WxUserService; +import org.nutz.dao.Cnd; +import org.nutz.ioc.loader.annotation.Inject; +import org.nutz.ioc.loader.annotation.IocBean; +import org.nutz.json.Json; +import org.nutz.weixin.bean.WxTemplateData; +import org.nutz.weixin.spi.WxApi2; +import org.nutz.weixin.spi.WxResp; + +import java.util.Map; + +/** + * Created by wizzer on 2016/8/6. + */ +@IocBean +public class TplService { + @Inject + private WxTplIdService wxTplIdService; + @Inject + private WxUserService wxUserService; + @Inject + private WxTplLogService wxTplLogService; + @Inject + private WxConfigService wxConfigService; + + /** + * 通过模板编号发送模板消息,并记录到日志表 + * + * @param wxid + * @param openid + * @param tplId + * @param url + * @param data + * @return + */ + public String send(String wxid, String openid, String tplId, String url, Map data) { + WxApi2 wxApi2 = wxConfigService.getWxApi2(wxid); + Wx_tpl_id tpl = wxTplIdService.fetch(tplId); + if (tpl != null) { + WxResp wxResp = wxApi2.template_send(openid, tpl.getTemplate_id(), url, data); + Wx_user user = wxUserService.fetch(Cnd.where("openid", "=", openid)); + Wx_tpl_log l = new Wx_tpl_log(); + l.setWxid(wxid); + l.setOpenid(openid); + l.setNickname(""); + if (user != null) { + l.setNickname(user.getNickname()); + } + l.setContent(Json.toJson(data)); + if (wxResp.errcode() == 0) { + l.setStatus(1);//发送成功 + } else l.setStatus(2);//发送失败 + Wx_tpl_log rl = wxTplLogService.insert(l); + return rl == null ? null : rl.getId(); + } + return null; + } +} diff --git a/wk-app/wk-web/src/main/java/cn/wizzer/app/web/commons/services/wx/WxHandler.java b/wk-app/wk-web/src/main/java/cn/wizzer/app/web/commons/services/wx/WxHandler.java new file mode 100644 index 000000000..4885dc329 --- /dev/null +++ b/wk-app/wk-web/src/main/java/cn/wizzer/app/web/commons/services/wx/WxHandler.java @@ -0,0 +1,195 @@ +package cn.wizzer.app.web.commons.services.wx; + +import cn.wizzer.app.wx.modules.models.*; +import cn.wizzer.app.wx.modules.services.*; +import com.vdurmont.emoji.EmojiParser; +import org.nutz.dao.Chain; +import org.nutz.dao.Cnd; +import org.nutz.ioc.loader.annotation.Inject; +import org.nutz.ioc.loader.annotation.IocBean; +import org.nutz.json.Json; +import org.nutz.lang.Strings; +import org.nutz.log.Log; +import org.nutz.log.Logs; +import org.nutz.weixin.bean.WxArticle; +import org.nutz.weixin.bean.WxInMsg; +import org.nutz.weixin.bean.WxOutMsg; +import org.nutz.weixin.impl.AbstractWxHandler; +import org.nutz.weixin.repo.com.qq.weixin.mp.aes.AesException; +import org.nutz.weixin.repo.com.qq.weixin.mp.aes.WXBizMsgCrypt; +import org.nutz.weixin.spi.WxApi2; +import org.nutz.weixin.spi.WxResp; +import org.nutz.weixin.util.Wxs; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created by wizzer on 2016/7/3. + */ +@IocBean(name = "wxHandler") +public class WxHandler extends AbstractWxHandler { + private final static Log log = Logs.get(); + protected String token; + protected String aeskey; + protected WXBizMsgCrypt msgCrypt; + protected String appid; + protected WxApi2 api; + @Inject + private WxConfigService wxConfigService; + @Inject + private WxUserService wxUserService; + @Inject + private WxReplyService wxReplyService; + @Inject + private WxReplyNewsService wxReplyNewsService; + @Inject + private WxReplyTxtService wxReplyTxtService; + @Inject + private WxMsgService wxMsgService; + + public boolean check(String signature, String timestamp, String nonce, String key) { + Wx_config appInfo = wxConfigService.fetch(Cnd.where("id", "=", key)); + if(appInfo!=null){ + this.token=appInfo.getToken(); + this.aeskey=appInfo.getEncodingAESKey(); + this.appid=appInfo.getAppid(); + return Wxs.check(appInfo.getToken(), signature, timestamp, nonce); + } + return false; + } + + public WXBizMsgCrypt getMsgCrypt() { + if (this.msgCrypt == null) { + try { + // 若抛异常Illegal key size ,需更新JDK的加密库为不限制长度 + this.msgCrypt = new WXBizMsgCrypt(this.token, this.aeskey, this.appid); + } catch (AesException var2) { + throw new RuntimeException(var2); + } + } + + return this.msgCrypt; + } + + // 用户发送的是文本的时候调用这个方法 + public WxOutMsg text(WxInMsg msg) { + Wx_reply reply = wxReplyService.fetch(Cnd.where("wxid", "=", msg.getExtkey()).and("type", "=", "keyword").and("keyword", "=", msg.getContent())); + if (reply != null) { + if ("txt".equals(reply.getMsgType())) { + String txtId = reply.getContent(); + Wx_reply_txt txt = wxReplyTxtService.fetch(txtId); + return Wxs.respText(null, txt == null ? "" : txt.getContent()); + } else if ("news".equals(reply.getMsgType())) { + String[] newsIds = Strings.sBlank(reply.getContent()).split(","); + List list = new ArrayList<>(); + List newsList = wxReplyNewsService.query(Cnd.where("id", "in", newsIds).asc("location")); + for (Wx_reply_news news : newsList) { + WxArticle wxArticle = new WxArticle(); + wxArticle.setDescription(news.getDescription()); + wxArticle.setPicUrl(news.getPicUrl()); + wxArticle.setTitle(news.getTitle()); + wxArticle.setUrl(news.getUrl()); + list.add(wxArticle); + } + return Wxs.respNews(null, list); + } + } + Wx_user usr = wxUserService.fetch(Cnd.where("openid", "=", msg.getFromUserName())); + Wx_msg wxMsg = new Wx_msg(); + wxMsg.setOpenid(msg.getFromUserName()); + wxMsg.setContent(EmojiParser.parseToAliases(msg.getContent(), EmojiParser.FitzpatrickAction.REMOVE)); + wxMsg.setWxid(msg.getExtkey()); + wxMsg.setType("txt"); + wxMsg.setNickname(usr == null ? "匿名" : usr.getNickname()); + wxMsg.setDelFlag(false); + wxMsgService.insert(wxMsg); + return Wxs.respText(null, "您的留言已收到!"); + } + + public WxOutMsg eventClick(WxInMsg msg) { + String eventKey = msg.getEventKey(); + log.debug("eventKey: " + eventKey); + Wx_reply reply=wxReplyService.fetch(Cnd.where("type","=","keyword").and("wxid","=",msg.getExtkey()).and("keyword","=",eventKey)); + if (reply != null) { + if ("txt".equals(reply.getMsgType())) { + String txtId = reply.getContent(); + Wx_reply_txt txt = wxReplyTxtService.fetch(txtId); + return Wxs.respText(null, txt == null ? "" : txt.getContent()); + } else if ("news".equals(reply.getMsgType())) { + String[] newsIds = Strings.sBlank(reply.getContent()).split(","); + List list = new ArrayList<>(); + List newsList = wxReplyNewsService.query(Cnd.where("id", "in", newsIds).asc("location")); + for (Wx_reply_news news : newsList) { + WxArticle wxArticle = new WxArticle(); + wxArticle.setDescription(news.getDescription()); + wxArticle.setPicUrl(news.getPicUrl()); + wxArticle.setTitle(news.getTitle()); + wxArticle.setUrl(news.getUrl()); + list.add(wxArticle); + } + return Wxs.respNews(null, list); + } + } + return defaultMsg(msg); + } + + @Override + public WxOutMsg eventSubscribe(WxInMsg msg) { + if (api == null) + api = wxConfigService.getWxApi2(msg.getExtkey()); + Wx_user usr = wxUserService.fetch(Cnd.where("openid", "=", msg.getFromUserName())); + WxResp resp = api.user_info(msg.getFromUserName(), "zh_CN"); + if (usr == null) { + usr = Json.fromJson(Wx_user.class, Json.toJson(resp.user())); + usr.setNickname(EmojiParser.parseToAliases(usr.getNickname(), EmojiParser.FitzpatrickAction.REMOVE)); + usr.setSubscribeAt((int) (resp.user().getSubscribe_time())); + usr.setWxid(msg.getExtkey()); + wxUserService.insert(usr); + } else { + String id = usr.getId(); + usr = Json.fromJson(Wx_user.class, Json.toJson(resp.user())); + usr.setNickname(EmojiParser.parseToAliases(usr.getNickname(), EmojiParser.FitzpatrickAction.REMOVE)); + usr.setOpAt((int) (System.currentTimeMillis() / 1000)); + usr.setWxid(msg.getExtkey()); + usr.setId(id); + wxUserService.updateIgnoreNull(usr); + } + Wx_reply reply = wxReplyService.fetch(Cnd.where("wxid", "=", msg.getExtkey()).and("type", "=", "follow")); + if (reply != null) { + if ("txt".equals(reply.getMsgType())) { + String txtId = reply.getContent(); + Wx_reply_txt txt = wxReplyTxtService.fetch(txtId); + return Wxs.respText(null, txt == null ? "" : txt.getContent()); + } else if ("news".equals(reply.getMsgType())) { + String[] newsIds = Strings.sBlank(reply.getContent()).split(","); + List list = new ArrayList<>(); + List newsList = wxReplyNewsService.query(Cnd.where("id", "in", newsIds).asc("location")); + for (Wx_reply_news news : newsList) { + WxArticle wxArticle = new WxArticle(); + wxArticle.setDescription(news.getDescription()); + wxArticle.setPicUrl(news.getPicUrl()); + wxArticle.setTitle(news.getTitle()); + wxArticle.setUrl(news.getUrl()); + list.add(wxArticle); + } + return Wxs.respNews(null, list); + } + } + return Wxs.respText(null, "谢谢您的关注!"); + } + + @Override + public WxOutMsg eventUnsubscribe(WxInMsg msg) { + Wx_user usr = wxUserService.fetch(Cnd.where("openid", "=", msg.getFromUserName())); + if (usr != null) { + wxUserService.update(Chain.make("subscribe", false).add("opAt", (int) (System.currentTimeMillis() / 1000)), Cnd.where("openid", "=", msg.getFromUserName())); + } + return super.eventUnsubscribe(msg); + } + + @Override + public WxOutMsg defaultMsg(WxInMsg msg) { + return Wxs.respText("这是缺省回复哦.你发送的类型是:" + msg.getMsgType()); + } +} \ No newline at end of file diff --git a/wk-app/wk-web/src/main/java/cn/wizzer/app/web/modules/controllers/open/wx/WeixinController.java b/wk-app/wk-web/src/main/java/cn/wizzer/app/web/modules/controllers/open/wx/WeixinController.java index 28e9e2a68..0f28006d0 100644 --- a/wk-app/wk-web/src/main/java/cn/wizzer/app/web/modules/controllers/open/wx/WeixinController.java +++ b/wk-app/wk-web/src/main/java/cn/wizzer/app/web/modules/controllers/open/wx/WeixinController.java @@ -1,5 +1,6 @@ package cn.wizzer.app.web.modules.controllers.open.wx; +import cn.wizzer.app.web.commons.services.wx.WxHandler; import cn.wizzer.app.wx.modules.services.WxConfigService; import org.nutz.ioc.loader.annotation.Inject; import org.nutz.ioc.loader.annotation.IocBean; @@ -8,7 +9,6 @@ import org.nutz.mvc.View; import org.nutz.mvc.annotation.At; import org.nutz.mvc.annotation.Fail; -import org.nutz.weixin.spi.WxHandler; import org.nutz.weixin.util.Wxs; import javax.servlet.http.HttpServletRequest; diff --git a/wk-app/wk-web/src/main/java/cn/wizzer/app/web/modules/controllers/platform/sys/SysTaskController.java b/wk-app/wk-web/src/main/java/cn/wizzer/app/web/modules/controllers/platform/sys/SysTaskController.java index 35fbcd11c..b0f68e0ef 100644 --- a/wk-app/wk-web/src/main/java/cn/wizzer/app/web/modules/controllers/platform/sys/SysTaskController.java +++ b/wk-app/wk-web/src/main/java/cn/wizzer/app/web/modules/controllers/platform/sys/SysTaskController.java @@ -223,4 +223,56 @@ public Object disable(String id, HttpServletRequest req) { return Result.error("system.error"); } } +// +// @At("/suspend/?") +// @Ok("json") +// @RequiresPermissions("sys.manager.task.edit") +// @SLog(tag = "暂停任务", msg = "任务名:${req.getAttribute('name')}") +// public Object suspend(String id, HttpServletRequest req) { +// try { +// Sys_task sysTask = taskService.fetch(id); +// try { +// boolean isExist = quartzManager.exist(new JobKey(sysTask.getId(), sysTask.getId())); +// if (!isExist) { +// QuartzJob qj = new QuartzJob(); +// qj.setJobName(sysTask.getId()); +// qj.setJobGroup(sysTask.getId()); +// quartzManager.pause(qj); +// } +// } catch (Exception e) { +// log.error(e.getMessage()); +// } +// req.setAttribute("name", sysTask.getName()); +// taskService.update(org.nutz.dao.Chain.make("disabled", false), Cnd.where("id", "=", id)); +// return Result.success("system.success"); +// } catch (Exception e) { +// return Result.error("system.error"); +// } +// } +// +// @At("/restore/?") +// @Ok("json") +// @RequiresPermissions("sys.manager.task.edit") +// @SLog(tag = "恢复任务", msg = "任务名:${req.getAttribute('name')}") +// public Object restore(String id, HttpServletRequest req) { +// try { +// Sys_task sysTask = taskService.fetch(id); +// try { +// boolean isExist = quartzManager.exist(new JobKey(sysTask.getId(), sysTask.getId())); +// if (!isExist) { +// QuartzJob qj = new QuartzJob(); +// qj.setJobName(sysTask.getId()); +// qj.setJobGroup(sysTask.getId()); +// quartzManager.resume(qj); +// } +// } catch (Exception e) { +// log.error(e.getMessage()); +// } +// req.setAttribute("name", sysTask.getName()); +// taskService.update(org.nutz.dao.Chain.make("disabled", false), Cnd.where("id", "=", id)); +// return Result.success("system.success"); +// } catch (Exception e) { +// return Result.error("system.error"); +// } +// } } diff --git a/wk-app/wk-web/src/main/webapp/WEB-INF/views/platform/sys/task/index.html b/wk-app/wk-web/src/main/webapp/WEB-INF/views/platform/sys/task/index.html index 36647aa2d..414cd5955 100644 --- a/wk-app/wk-web/src/main/webapp/WEB-INF/views/platform/sys/task/index.html +++ b/wk-app/wk-web/src/main/webapp/WEB-INF/views/platform/sys/task/index.html @@ -115,6 +115,8 @@ '
  • ' + '
  • 启用
  • ' + '
  • 禁用
  • ' + +// '
  • 暂停
  • ' + +// '
  • 恢复
  • ' + ''; }, "targets": 6 @@ -146,6 +148,24 @@ } }, "json"); } + function suspend(id) { + $.post("${base}/platform/sys/task/suspend/" + id, {}, function (data) { + if (data.code == 0) { + $("#disable_" + id).attr("class", "fa fa-circle text-danger ml5"); + } else { + Toast.error(data.msg); + } + }, "json"); + } + function restore(id) { + $.post("${base}/platform/sys/task/restore/" + id, {}, function (data) { + if (data.code == 0) { + $("#disable_" + id).attr("class", "fa fa-circle text-success ml5"); + } else { + Toast.error(data.msg); + } + }, "json"); + } function del(id) { var dialog = $("#dialogDelete"); dialog.modal("show");