WXServiceImpl.java 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. package com.xcgl.weixin.service;
  2. import java.nio.charset.Charset;
  3. import java.util.ArrayList;
  4. import java.util.Date;
  5. import java.util.HashMap;
  6. import java.util.List;
  7. import java.util.Map;
  8. import cn.com.lzt.message.send.util.MessageSendUtil;
  9. import org.apache.commons.lang3.StringUtils;
  10. import org.apache.http.HttpResponse;
  11. import org.apache.http.HttpStatus;
  12. import org.apache.http.client.methods.HttpPost;
  13. import org.apache.http.entity.StringEntity;
  14. import org.apache.http.impl.client.DefaultHttpClient;
  15. import org.apache.log4j.Logger;
  16. import org.jeecgframework.core.util.DateUtils;
  17. import org.jeecgframework.web.system.pojo.base.TSUser;
  18. import org.springframework.beans.factory.annotation.Autowired;
  19. import org.springframework.stereotype.Service;
  20. import com.alibaba.fastjson.JSONObject;
  21. import com.xcgl.utils.XcglConstant;
  22. import com.xcgl.weixin.dao.WXDao;
  23. import cn.com.lzt.message.data.dto.MessageSimpleRowViewer;
  24. import cn.com.lzt.message.send.entity.MessageWxTemplateConfig;
  25. import cn.com.lzt.message.send.entity.MMessageEntity.MessageSendWay;
  26. import cn.com.lzt.message.send.service.MMessageSendServiceI;
  27. import cn.com.lzt.warehouse.entity.WarehouseEntity;
  28. @Service("WXService")
  29. public class WXServiceImpl implements WXServiceI {
  30. @Autowired
  31. WXDao wxdao;
  32. @Autowired
  33. MMessageSendServiceI mMessageSend;
  34. private static final Logger logger = Logger.getLogger(WXServiceImpl.class);
  35. @Override
  36. public void sendMsgToWXInMorning() throws Exception {
  37. logger.error("###########weixin-sendmsg begain:"+DateUtils.formatDate(new Date(),"yyyy-MM-dd HH:mm:ss"));
  38. Map<String,Object> reqParams = new HashMap<String,Object>();
  39. List<Map<String,Object>> listParams = new ArrayList<Map<String,Object>>();
  40. List<Map<String,Object>> ret = wxdao.getTodayWork4PushMsg(DateUtils.formatDate(new Date(),"yyyy-MM-dd"));
  41. for(Map<String,Object> oneRecord : ret) {
  42. if(oneRecord.get("openid") == null || oneRecord.get("openid").toString().trim().length() == 0
  43. || (Integer.parseInt(oneRecord.get("notexectasknum").toString()) == 0 && Integer.parseInt(oneRecord.get("outtimetasknum").toString()) == 0)) {
  44. continue;
  45. }
  46. logger.error(oneRecord.get("name")+" "+oneRecord.get("openid")+" "+oneRecord.get("userid"));
  47. Map<String,Object> oneMsg = new HashMap<String,Object>();
  48. Map<String,Object> userMsgParms = new HashMap<String,Object>();
  49. userMsgParms.put("first", "早上好:"+oneRecord.get("name")+",快速浏览下你今天的工作吧!");
  50. userMsgParms.put("keyword1", DateUtils.formatDate(new Date(),"yyyy-MM-dd"));
  51. userMsgParms.put("keyword2", "\n今日待完成工作:"+oneRecord.get("notexectasknum")+"条 \n已逾期工作:"+
  52. oneRecord.get("outtimetasknum")+"条 \n紧急任务工作:0条");
  53. oneMsg.put("openid", oneRecord.get("openid"));
  54. oneMsg.put("userid", oneRecord.get("userid"));
  55. oneMsg.put("tplParams", userMsgParms);
  56. oneMsg.put("url", "http://www.shenqin.work/h5/task_list.html");
  57. listParams.add(oneMsg);
  58. }
  59. reqParams.put("templateId", XcglConstant.TEMPLATE_WXMSG_TODAYTASK);
  60. reqParams.put("list", listParams);
  61. //String content = JSONArray.fromObject(syncRecord,jsonConfig).toString();
  62. org.apache.http.client.HttpClient client = new DefaultHttpClient();
  63. try {
  64. String url = "http://www.shenqin.work/api/wx/sendTplMsg";
  65. HttpPost httpPost = new HttpPost(url);
  66. httpPost.addHeader("Content-type","application/json; charset=utf-8");
  67. httpPost.setEntity(new StringEntity(JSONObject.toJSONString(reqParams), Charset.forName("UTF-8")));
  68. HttpResponse response = client.execute(httpPost);
  69. // 检验返回码
  70. int statusCode = response.getStatusLine().getStatusCode();
  71. if (statusCode != HttpStatus.SC_OK) {
  72. logger.error("发送微信msg错误:" + statusCode);
  73. }
  74. }catch (Exception e) {
  75. logger.error("发送微信msg错误:" + e.getMessage());
  76. }
  77. logger.error("###########weixin-sendmsg end:"+DateUtils.formatDate(new Date(),"yyyy-MM-dd HH:mm:ss"));
  78. }
  79. @Override
  80. public void sendMsgToWXForWarning(String userid,String openid,String msg,String warningType,String first,
  81. String keyword1,String keyword2,String keyword3,String keyword4,String remark,String url) throws Exception {
  82. logger.error("###########weixin-sendmsg begain:"+DateUtils.formatDate(new Date(),"yyyy-MM-dd HH:mm:ss"));
  83. Map<String,Object> reqParams = new HashMap<String,Object>();
  84. List<Map<String,Object>> listParams = new ArrayList<Map<String,Object>>();
  85. Map<String, Object> oneMsg = new HashMap<String, Object>();
  86. Map<String, Object> userMsgParms = new HashMap<String, Object>();
  87. userMsgParms.put("first", "合同到期预警提醒");
  88. userMsgParms.put("keyword1", "2018-12-31");
  89. userMsgParms.put("keyword2", "群艺馆项目保洁部陈艳合同将于2018年12月31日到期,请及时续签。");
  90. // userMsgParms.put("keyword3", keyword3);
  91. // userMsgParms.put("remark", "请及时关注");
  92. oneMsg.put("openid", "oQ2vj04CDPxjrvp9WlyJkXEfg4S8");
  93. oneMsg.put("userid", "000000006120dd1c01612cf525390279");
  94. oneMsg.put("tplParams", userMsgParms);
  95. oneMsg.put("url", "http://www.baidu.com");
  96. // Map<String, Object> oneMsg2 = new HashMap<String, Object>();
  97. // Map<String, Object> userMsgParms2 = new HashMap<String, Object>();
  98. // userMsgParms2.put("first", "上周美都环卫职能部门未完成工作情况统计");
  99. // userMsgParms2.put("keyword1", "2018-11-26 ~ 2018-12-02");
  100. // userMsgParms2.put("keyword2", "上周美都环卫职能部门尚未完成工作28个,其中:\n xxx部12个、\n xxx部7个、\n xxx部5个、\n xxx部4个");
  101. //// userMsgParms.put("keyword3", keyword3);
  102. // userMsgParms2.put("remark", "请及时关注");
  103. // oneMsg2.put("openid", "oQ2vj04CDPxjrvp9WlyJkXEfg4S8");
  104. // oneMsg2.put("userid", "000000006120dd1c01612cf525390279");
  105. // oneMsg2.put("tplParams", userMsgParms2);
  106. //
  107. // Map<String, Object> oneMsg3 = new HashMap<String, Object>();
  108. // Map<String, Object> userMsgParms3 = new HashMap<String, Object>();
  109. // userMsgParms3.put("first", "上周群艺馆未完成工作情况统计");
  110. // userMsgParms3.put("keyword1", "2018-11-26 ~ 2018-12-02");
  111. // userMsgParms3.put("keyword2", "上周群艺馆项目尚未完成工作12个,其中: \n 邓超5个、\n 鹿晗4个、\n 孙俪3个");
  112. //// userMsgParms.put("keyword3", keyword3);
  113. // userMsgParms3.put("remark", "请及时关注");
  114. // oneMsg3.put("openid", "oQ2vj04CDPxjrvp9WlyJkXEfg4S8");
  115. // oneMsg3.put("userid", "000000006120dd1c01612cf525390279");
  116. // oneMsg3.put("tplParams", userMsgParms3);
  117. listParams.add(oneMsg);
  118. // listParams.add(oneMsg2);
  119. // listParams.add(oneMsg3);
  120. reqParams.put("templateId", XcglConstant.TEMPLATE_WXMSG_TODAYTASK);
  121. reqParams.put("list", listParams);
  122. //String content = JSONArray.fromObject(syncRecord,jsonConfig).toString();
  123. org.apache.http.client.HttpClient client = new DefaultHttpClient();
  124. try {
  125. String wxurl = "http://www.shenqin.work/api/wx/sendTplMsg";
  126. HttpPost httpPost = new HttpPost(wxurl);
  127. httpPost.addHeader("Content-type","application/json; charset=utf-8");
  128. httpPost.setEntity(new StringEntity(JSONObject.toJSONString(reqParams), Charset.forName("UTF-8")));
  129. HttpResponse response = client.execute(httpPost);
  130. // 检验返回码
  131. int statusCode = response.getStatusLine().getStatusCode();
  132. if (statusCode != HttpStatus.SC_OK) {
  133. logger.error("发送微信msg错误:" + statusCode);
  134. }
  135. }catch (Exception e) {
  136. logger.error("发送微信msg错误:" + e.getMessage());
  137. }
  138. logger.error("###########weixin-sendmsg end:"+DateUtils.formatDate(new Date(),"yyyy-MM-dd HH:mm:ss"));
  139. }
  140. @Override
  141. public void sendMsgToWXForNewWork(String userid,String openid,String msg,String warningType,String first,
  142. String keyword1,String keyword2,String keyword3,String keyword4,String remark,String url) throws Exception {
  143. logger.error("###########weixin-sendmsg begain:"+DateUtils.formatDate(new Date(),"yyyy-MM-dd HH:mm:ss"));
  144. Map<String,Object> reqParams = new HashMap<String,Object>();
  145. List<Map<String,Object>> listParams = new ArrayList<Map<String,Object>>();
  146. Map<String, Object> oneMsg = new HashMap<String, Object>();
  147. Map<String, Object> userMsgParms = new HashMap<String, Object>();
  148. // userMsgParms.put("first", first);
  149. // userMsgParms.put("keyword1", keyword1);
  150. // userMsgParms.put("keyword2", keyword2);
  151. // userMsgParms.put("keyword3", keyword3);
  152. // userMsgParms.put("keyword4", keyword4);
  153. userMsgParms.put("first", "你好,你有一个新工作");
  154. userMsgParms.put("keyword1", "项目申购提交统计提醒");
  155. userMsgParms.put("keyword2", "闵欢");
  156. userMsgParms.put("keyword3", "2018-12-02 8:00:00");
  157. userMsgParms.put("keyword4", "电话通知");
  158. oneMsg.put("openid", "oQ2vj04CDPxjrvp9WlyJkXEfg4S8");
  159. oneMsg.put("userid", "000000006120dd1c01612cf525390279");
  160. oneMsg.put("tplParams", userMsgParms);
  161. oneMsg.put("url", "http://www.shenqin.work/h5/task.html?id=2c9358a867532a020167561cff730002");
  162. listParams.add(oneMsg);
  163. reqParams.put("templateId", XcglConstant.TEMPLATE_WXMSG_NEWWORK);
  164. reqParams.put("list", listParams);
  165. //String content = JSONArray.fromObject(syncRecord,jsonConfig).toString();
  166. org.apache.http.client.HttpClient client = new DefaultHttpClient();
  167. try {
  168. String wxurl = "http://www.shenqin.work/api/wx/sendTplMsg";
  169. HttpPost httpPost = new HttpPost(wxurl);
  170. httpPost.addHeader("Content-type","application/json; charset=utf-8");
  171. httpPost.setEntity(new StringEntity(JSONObject.toJSONString(reqParams), Charset.forName("UTF-8")));
  172. HttpResponse response = client.execute(httpPost);
  173. // 检验返回码
  174. int statusCode = response.getStatusLine().getStatusCode();
  175. if (statusCode != HttpStatus.SC_OK) {
  176. logger.error("发送微信msg错误:" + statusCode);
  177. }
  178. }catch (Exception e) {
  179. logger.error("发送微信msg错误:" + e.getMessage());
  180. }
  181. logger.error("###########weixin-sendmsg end:"+DateUtils.formatDate(new Date(),"yyyy-MM-dd HH:mm:ss"));
  182. }
  183. public void sendMsgToWXForOrdersNotSubmit(String yearmonth) throws Exception {
  184. logger.error("###########weixin-sendmsg-orders not submit warning begain:"+DateUtils.formatDate(new Date(),"yyyy-MM-dd HH:mm:ss"));
  185. List<WarehouseEntity> warehouses = wxdao.getNotSubmitOnhandReportWarehouseList(yearmonth);
  186. List<Map<String,Object>> users = wxdao.getXZBFJLUsers("A_XZBFJL");
  187. if(warehouses.size() == 0 || users.size() == 0)
  188. return;
  189. Map<String,Object> reqParams = new HashMap<String,Object>();
  190. List<Map<String,Object>> listParams = new ArrayList<Map<String,Object>>();
  191. for(Map<String,Object> user :users) {
  192. Map<String, Object> oneMsg = new HashMap<String, Object>();
  193. Map<String, Object> userMsgParms = new HashMap<String, Object>();
  194. // userMsgParms.put("first", first);
  195. // userMsgParms.put("keyword1", keyword1);
  196. // userMsgParms.put("keyword2", keyword2);
  197. // userMsgParms.put("keyword3", keyword3);
  198. // userMsgParms.put("keyword4", keyword4);
  199. userMsgParms.put("first", "你好,申购单未提交预警");
  200. userMsgParms.put("keyword1", "截至今日,尚有"+warehouses.size()+"个项目未提交"+yearmonth+"月度申购单");
  201. userMsgParms.put("keyword2", "美都环卫物料管理系统");
  202. userMsgParms.put("keyword3", DateUtils.formatDate(new Date(),"yyyy-MM-dd HH:mm:ss"));
  203. userMsgParms.put("keyword4", "未提交的项目有:"+warehouses.get(0).getWarehouseName()+"等\n 详情请点击消息链接");
  204. oneMsg.put("openid", user.get("openid"));
  205. oneMsg.put("userid", user.get("id"));
  206. oneMsg.put("tplParams", userMsgParms);
  207. oneMsg.put("url", "http://hgl.shenqin.work/hgl/dsdemoController.do?showNoOrderWarehouse&yearmonth="+yearmonth);
  208. listParams.add(oneMsg);
  209. }
  210. sendMsgToWX(listParams, XcglConstant.TEMPLATE_WXMSG_WARNING);
  211. logger.error("###########weixin-sendmsg-orders not submit warning end:"+DateUtils.formatDate(new Date(),"yyyy-MM-dd HH:mm:ss"));
  212. }
  213. public void sendMsgToWXForTodayWork(List<Map<String,Object>> listParams) throws Exception {
  214. logger.error("###########weixin-sendmsg-todaywork begain:"+DateUtils.formatDate(new Date(),"yyyy-MM-dd HH:mm:ss"));
  215. sendMsgToWX(listParams, XcglConstant.TEMPLATE_WXMSG_TODAYTASK);
  216. logger.error("###########weixin-sendmsg-todaywork end:"+DateUtils.formatDate(new Date(),"yyyy-MM-dd HH:mm:ss"));
  217. }
  218. public void sendMsgToWXForPayComplete(List<Map<String,Object>> listParams) throws Exception {
  219. logger.error("###########weixin-sendmsg-payment-complete begain:"+DateUtils.formatDate(new Date(),"yyyy-MM-dd HH:mm:ss"));
  220. sendMsgToWX(listParams, XcglConstant.TEMPLATE_WXMSG_PAY_COMPLETE);
  221. logger.error("###########weixin-sendmsg-payment-complete end:"+DateUtils.formatDate(new Date(),"yyyy-MM-dd HH:mm:ss"));
  222. }
  223. public void sendMsgToWXForAuditComplete(List<Map<String,Object>> listParams) throws Exception {
  224. logger.error("###########weixin-sendmsg-audit-complete begain:"+DateUtils.formatDate(new Date(),"yyyy-MM-dd HH:mm:ss"));
  225. sendMsgToWX(listParams, XcglConstant.TEMPLATE_WXMSG_AUDIT_COMPLETE);
  226. logger.error("###########weixin-sendmsg-audit-complete end:"+DateUtils.formatDate(new Date(),"yyyy-MM-dd HH:mm:ss"));
  227. }
  228. public void sendMsgToWX(List<Map<String,Object>> listParams,String templateID) throws Exception {
  229. MessageSendUtil.sendMsgToWX(listParams,templateID);
  230. }
  231. /**
  232. * 每周五下午一点发送未配置工资策略人员清单给人事助理
  233. * 使用微信发送统一接口:MMessageSendService
  234. * */
  235. public void sendMsgToWXForNo_wagestrategy() throws Exception {
  236. logger.error("###########weixin-sendmsg-no wagestrategy orders not submit warning begain:"+DateUtils.formatDate(new Date(),"yyyy-MM-dd HH:mm:ss"));
  237. List<TSUser> noWageUsers = wxdao.getNoWageUserList();
  238. List<Map<String,Object>> users = wxdao.getXZBFJLUsers("A_HRZL");
  239. List<String> receiveidList = new ArrayList<String>();
  240. if(noWageUsers.size() == 0 || users.size() == 0)
  241. return;
  242. for (Map<String,Object> map : users) {
  243. receiveidList.add(map.get("id").toString());
  244. }
  245. MessageSimpleRowViewer viewer = new MessageSimpleRowViewer();
  246. List<String> columns = new ArrayList<String>();
  247. columns.add("人员及所属项目");
  248. List<Object[]> data = new ArrayList<Object[]>();
  249. for (TSUser user : noWageUsers) {
  250. if(StringUtils.isNotEmpty(user.getRealName()))
  251. data.add(new String[] {user.getRealName()});
  252. }
  253. viewer.setData(data);
  254. viewer.setTitle("未配置或未更新工资策略人员清单");
  255. viewer.setColumns(columns);
  256. MessageWxTemplateConfig config = new MessageWxTemplateConfig();
  257. config.setTemplateId(XcglConstant.TEMPLATE_WXMSG_WARNING);
  258. Map<String, Object> userMsgParms = new HashMap<String, Object>();
  259. userMsgParms.put("first", "你好,未配置工资策略提醒");
  260. userMsgParms.put("keyword1", "截至今日,尚有"+data.size()+"个员工未配置工资策略或员工工资策略未更新");
  261. userMsgParms.put("keyword2", "美都环卫慧管理系统");
  262. userMsgParms.put("keyword3", DateUtils.formatDate(new Date(),"yyyy-MM-dd HH:mm"));
  263. userMsgParms.put("keyword4", "详情请点击消息链接");
  264. config.setUserMsgParms(userMsgParms);
  265. mMessageSend.sendViewer(receiveidList, viewer, config, new MessageSendWay[] {MessageSendWay.wx});
  266. logger.error("##########weixin-sendmsg-no wagestrategy warning end:"+DateUtils.formatDate(new Date(),"yyyy-MM-dd HH:mm:ss"));
  267. }
  268. }