| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287 |
- package com.xcgl.weixin.service;
- import java.nio.charset.Charset;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import cn.com.lzt.message.send.util.MessageSendUtil;
- import org.apache.commons.lang3.StringUtils;
- import org.apache.http.HttpResponse;
- import org.apache.http.HttpStatus;
- import org.apache.http.client.methods.HttpPost;
- import org.apache.http.entity.StringEntity;
- import org.apache.http.impl.client.DefaultHttpClient;
- import org.apache.log4j.Logger;
- import org.jeecgframework.core.util.DateUtils;
- import org.jeecgframework.web.system.pojo.base.TSUser;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import com.alibaba.fastjson.JSONObject;
- import com.xcgl.utils.XcglConstant;
- import com.xcgl.weixin.dao.WXDao;
- import cn.com.lzt.message.data.dto.MessageSimpleRowViewer;
- import cn.com.lzt.message.send.entity.MessageWxTemplateConfig;
- import cn.com.lzt.message.send.entity.MMessageEntity.MessageSendWay;
- import cn.com.lzt.message.send.service.MMessageSendServiceI;
- import cn.com.lzt.warehouse.entity.WarehouseEntity;
- @Service("WXService")
- public class WXServiceImpl implements WXServiceI {
- @Autowired
- WXDao wxdao;
- @Autowired
- MMessageSendServiceI mMessageSend;
- private static final Logger logger = Logger.getLogger(WXServiceImpl.class);
-
-
- @Override
- public void sendMsgToWXInMorning() throws Exception {
- logger.error("###########weixin-sendmsg begain:"+DateUtils.formatDate(new Date(),"yyyy-MM-dd HH:mm:ss"));
- Map<String,Object> reqParams = new HashMap<String,Object>();
- List<Map<String,Object>> listParams = new ArrayList<Map<String,Object>>();
- List<Map<String,Object>> ret = wxdao.getTodayWork4PushMsg(DateUtils.formatDate(new Date(),"yyyy-MM-dd"));
- for(Map<String,Object> oneRecord : ret) {
- if(oneRecord.get("openid") == null || oneRecord.get("openid").toString().trim().length() == 0
- || (Integer.parseInt(oneRecord.get("notexectasknum").toString()) == 0 && Integer.parseInt(oneRecord.get("outtimetasknum").toString()) == 0)) {
- continue;
- }
- logger.error(oneRecord.get("name")+" "+oneRecord.get("openid")+" "+oneRecord.get("userid"));
- Map<String,Object> oneMsg = new HashMap<String,Object>();
- Map<String,Object> userMsgParms = new HashMap<String,Object>();
- userMsgParms.put("first", "早上好:"+oneRecord.get("name")+",快速浏览下你今天的工作吧!");
- userMsgParms.put("keyword1", DateUtils.formatDate(new Date(),"yyyy-MM-dd"));
- userMsgParms.put("keyword2", "\n今日待完成工作:"+oneRecord.get("notexectasknum")+"条 \n已逾期工作:"+
- oneRecord.get("outtimetasknum")+"条 \n紧急任务工作:0条");
- oneMsg.put("openid", oneRecord.get("openid"));
- oneMsg.put("userid", oneRecord.get("userid"));
- oneMsg.put("tplParams", userMsgParms);
- oneMsg.put("url", "http://www.shenqin.work/h5/task_list.html");
- listParams.add(oneMsg);
- }
- reqParams.put("templateId", XcglConstant.TEMPLATE_WXMSG_TODAYTASK);
- reqParams.put("list", listParams);
- //String content = JSONArray.fromObject(syncRecord,jsonConfig).toString();
- org.apache.http.client.HttpClient client = new DefaultHttpClient();
- try {
- String url = "http://www.shenqin.work/api/wx/sendTplMsg";
- HttpPost httpPost = new HttpPost(url);
- httpPost.addHeader("Content-type","application/json; charset=utf-8");
- httpPost.setEntity(new StringEntity(JSONObject.toJSONString(reqParams), Charset.forName("UTF-8")));
- HttpResponse response = client.execute(httpPost);
- // 检验返回码
- int statusCode = response.getStatusLine().getStatusCode();
- if (statusCode != HttpStatus.SC_OK) {
- logger.error("发送微信msg错误:" + statusCode);
- }
- }catch (Exception e) {
- logger.error("发送微信msg错误:" + e.getMessage());
- }
- logger.error("###########weixin-sendmsg end:"+DateUtils.formatDate(new Date(),"yyyy-MM-dd HH:mm:ss"));
- }
-
- @Override
- public void sendMsgToWXForWarning(String userid,String openid,String msg,String warningType,String first,
- String keyword1,String keyword2,String keyword3,String keyword4,String remark,String url) throws Exception {
- logger.error("###########weixin-sendmsg begain:"+DateUtils.formatDate(new Date(),"yyyy-MM-dd HH:mm:ss"));
- Map<String,Object> reqParams = new HashMap<String,Object>();
- List<Map<String,Object>> listParams = new ArrayList<Map<String,Object>>();
- Map<String, Object> oneMsg = new HashMap<String, Object>();
-
- Map<String, Object> userMsgParms = new HashMap<String, Object>();
- userMsgParms.put("first", "合同到期预警提醒");
- userMsgParms.put("keyword1", "2018-12-31");
- userMsgParms.put("keyword2", "群艺馆项目保洁部陈艳合同将于2018年12月31日到期,请及时续签。");
- // userMsgParms.put("keyword3", keyword3);
- // userMsgParms.put("remark", "请及时关注");
- oneMsg.put("openid", "oQ2vj04CDPxjrvp9WlyJkXEfg4S8");
- oneMsg.put("userid", "000000006120dd1c01612cf525390279");
- oneMsg.put("tplParams", userMsgParms);
- oneMsg.put("url", "http://www.baidu.com");
-
- // Map<String, Object> oneMsg2 = new HashMap<String, Object>();
- // Map<String, Object> userMsgParms2 = new HashMap<String, Object>();
- // userMsgParms2.put("first", "上周美都环卫职能部门未完成工作情况统计");
- // userMsgParms2.put("keyword1", "2018-11-26 ~ 2018-12-02");
- // userMsgParms2.put("keyword2", "上周美都环卫职能部门尚未完成工作28个,其中:\n xxx部12个、\n xxx部7个、\n xxx部5个、\n xxx部4个");
- //// userMsgParms.put("keyword3", keyword3);
- // userMsgParms2.put("remark", "请及时关注");
- // oneMsg2.put("openid", "oQ2vj04CDPxjrvp9WlyJkXEfg4S8");
- // oneMsg2.put("userid", "000000006120dd1c01612cf525390279");
- // oneMsg2.put("tplParams", userMsgParms2);
- //
- // Map<String, Object> oneMsg3 = new HashMap<String, Object>();
- // Map<String, Object> userMsgParms3 = new HashMap<String, Object>();
- // userMsgParms3.put("first", "上周群艺馆未完成工作情况统计");
- // userMsgParms3.put("keyword1", "2018-11-26 ~ 2018-12-02");
- // userMsgParms3.put("keyword2", "上周群艺馆项目尚未完成工作12个,其中: \n 邓超5个、\n 鹿晗4个、\n 孙俪3个");
- //// userMsgParms.put("keyword3", keyword3);
- // userMsgParms3.put("remark", "请及时关注");
- // oneMsg3.put("openid", "oQ2vj04CDPxjrvp9WlyJkXEfg4S8");
- // oneMsg3.put("userid", "000000006120dd1c01612cf525390279");
- // oneMsg3.put("tplParams", userMsgParms3);
-
-
- listParams.add(oneMsg);
- // listParams.add(oneMsg2);
- // listParams.add(oneMsg3);
- reqParams.put("templateId", XcglConstant.TEMPLATE_WXMSG_TODAYTASK);
- reqParams.put("list", listParams);
- //String content = JSONArray.fromObject(syncRecord,jsonConfig).toString();
- org.apache.http.client.HttpClient client = new DefaultHttpClient();
- try {
- String wxurl = "http://www.shenqin.work/api/wx/sendTplMsg";
- HttpPost httpPost = new HttpPost(wxurl);
- httpPost.addHeader("Content-type","application/json; charset=utf-8");
- httpPost.setEntity(new StringEntity(JSONObject.toJSONString(reqParams), Charset.forName("UTF-8")));
- HttpResponse response = client.execute(httpPost);
- // 检验返回码
- int statusCode = response.getStatusLine().getStatusCode();
- if (statusCode != HttpStatus.SC_OK) {
- logger.error("发送微信msg错误:" + statusCode);
- }
- }catch (Exception e) {
- logger.error("发送微信msg错误:" + e.getMessage());
- }
- logger.error("###########weixin-sendmsg end:"+DateUtils.formatDate(new Date(),"yyyy-MM-dd HH:mm:ss"));
- }
-
-
- @Override
- public void sendMsgToWXForNewWork(String userid,String openid,String msg,String warningType,String first,
- String keyword1,String keyword2,String keyword3,String keyword4,String remark,String url) throws Exception {
- logger.error("###########weixin-sendmsg begain:"+DateUtils.formatDate(new Date(),"yyyy-MM-dd HH:mm:ss"));
- Map<String,Object> reqParams = new HashMap<String,Object>();
- List<Map<String,Object>> listParams = new ArrayList<Map<String,Object>>();
- Map<String, Object> oneMsg = new HashMap<String, Object>();
- Map<String, Object> userMsgParms = new HashMap<String, Object>();
- // userMsgParms.put("first", first);
- // userMsgParms.put("keyword1", keyword1);
- // userMsgParms.put("keyword2", keyword2);
- // userMsgParms.put("keyword3", keyword3);
- // userMsgParms.put("keyword4", keyword4);
- userMsgParms.put("first", "你好,你有一个新工作");
- userMsgParms.put("keyword1", "项目申购提交统计提醒");
- userMsgParms.put("keyword2", "闵欢");
- userMsgParms.put("keyword3", "2018-12-02 8:00:00");
- userMsgParms.put("keyword4", "电话通知");
- oneMsg.put("openid", "oQ2vj04CDPxjrvp9WlyJkXEfg4S8");
- oneMsg.put("userid", "000000006120dd1c01612cf525390279");
- oneMsg.put("tplParams", userMsgParms);
- oneMsg.put("url", "http://www.shenqin.work/h5/task.html?id=2c9358a867532a020167561cff730002");
- listParams.add(oneMsg);
- reqParams.put("templateId", XcglConstant.TEMPLATE_WXMSG_NEWWORK);
- reqParams.put("list", listParams);
- //String content = JSONArray.fromObject(syncRecord,jsonConfig).toString();
- org.apache.http.client.HttpClient client = new DefaultHttpClient();
- try {
- String wxurl = "http://www.shenqin.work/api/wx/sendTplMsg";
- HttpPost httpPost = new HttpPost(wxurl);
- httpPost.addHeader("Content-type","application/json; charset=utf-8");
- httpPost.setEntity(new StringEntity(JSONObject.toJSONString(reqParams), Charset.forName("UTF-8")));
- HttpResponse response = client.execute(httpPost);
- // 检验返回码
- int statusCode = response.getStatusLine().getStatusCode();
- if (statusCode != HttpStatus.SC_OK) {
- logger.error("发送微信msg错误:" + statusCode);
- }
- }catch (Exception e) {
- logger.error("发送微信msg错误:" + e.getMessage());
- }
- logger.error("###########weixin-sendmsg end:"+DateUtils.formatDate(new Date(),"yyyy-MM-dd HH:mm:ss"));
- }
-
- public void sendMsgToWXForOrdersNotSubmit(String yearmonth) throws Exception {
- logger.error("###########weixin-sendmsg-orders not submit warning begain:"+DateUtils.formatDate(new Date(),"yyyy-MM-dd HH:mm:ss"));
- List<WarehouseEntity> warehouses = wxdao.getNotSubmitOnhandReportWarehouseList(yearmonth);
- List<Map<String,Object>> users = wxdao.getXZBFJLUsers("A_XZBFJL");
- if(warehouses.size() == 0 || users.size() == 0)
- return;
- Map<String,Object> reqParams = new HashMap<String,Object>();
- List<Map<String,Object>> listParams = new ArrayList<Map<String,Object>>();
- for(Map<String,Object> user :users) {
- Map<String, Object> oneMsg = new HashMap<String, Object>();
- Map<String, Object> userMsgParms = new HashMap<String, Object>();
- // userMsgParms.put("first", first);
- // userMsgParms.put("keyword1", keyword1);
- // userMsgParms.put("keyword2", keyword2);
- // userMsgParms.put("keyword3", keyword3);
- // userMsgParms.put("keyword4", keyword4);
- userMsgParms.put("first", "你好,申购单未提交预警");
- userMsgParms.put("keyword1", "截至今日,尚有"+warehouses.size()+"个项目未提交"+yearmonth+"月度申购单");
- userMsgParms.put("keyword2", "美都环卫物料管理系统");
- userMsgParms.put("keyword3", DateUtils.formatDate(new Date(),"yyyy-MM-dd HH:mm:ss"));
- userMsgParms.put("keyword4", "未提交的项目有:"+warehouses.get(0).getWarehouseName()+"等\n 详情请点击消息链接");
- oneMsg.put("openid", user.get("openid"));
- oneMsg.put("userid", user.get("id"));
- oneMsg.put("tplParams", userMsgParms);
- oneMsg.put("url", "http://hgl.shenqin.work/hgl/dsdemoController.do?showNoOrderWarehouse&yearmonth="+yearmonth);
- listParams.add(oneMsg);
- }
- sendMsgToWX(listParams, XcglConstant.TEMPLATE_WXMSG_WARNING);
- logger.error("###########weixin-sendmsg-orders not submit warning end:"+DateUtils.formatDate(new Date(),"yyyy-MM-dd HH:mm:ss"));
- }
-
-
- public void sendMsgToWXForTodayWork(List<Map<String,Object>> listParams) throws Exception {
- logger.error("###########weixin-sendmsg-todaywork begain:"+DateUtils.formatDate(new Date(),"yyyy-MM-dd HH:mm:ss"));
- sendMsgToWX(listParams, XcglConstant.TEMPLATE_WXMSG_TODAYTASK);
- logger.error("###########weixin-sendmsg-todaywork end:"+DateUtils.formatDate(new Date(),"yyyy-MM-dd HH:mm:ss"));
- }
- public void sendMsgToWXForPayComplete(List<Map<String,Object>> listParams) throws Exception {
- logger.error("###########weixin-sendmsg-payment-complete begain:"+DateUtils.formatDate(new Date(),"yyyy-MM-dd HH:mm:ss"));
- sendMsgToWX(listParams, XcglConstant.TEMPLATE_WXMSG_PAY_COMPLETE);
- logger.error("###########weixin-sendmsg-payment-complete end:"+DateUtils.formatDate(new Date(),"yyyy-MM-dd HH:mm:ss"));
- }
- public void sendMsgToWXForAuditComplete(List<Map<String,Object>> listParams) throws Exception {
- logger.error("###########weixin-sendmsg-audit-complete begain:"+DateUtils.formatDate(new Date(),"yyyy-MM-dd HH:mm:ss"));
- sendMsgToWX(listParams, XcglConstant.TEMPLATE_WXMSG_AUDIT_COMPLETE);
- logger.error("###########weixin-sendmsg-audit-complete end:"+DateUtils.formatDate(new Date(),"yyyy-MM-dd HH:mm:ss"));
- }
- public void sendMsgToWX(List<Map<String,Object>> listParams,String templateID) throws Exception {
- MessageSendUtil.sendMsgToWX(listParams,templateID);
- }
- /**
- * 每周五下午一点发送未配置工资策略人员清单给人事助理
- * 使用微信发送统一接口:MMessageSendService
- * */
- public void sendMsgToWXForNo_wagestrategy() throws Exception {
- logger.error("###########weixin-sendmsg-no wagestrategy orders not submit warning begain:"+DateUtils.formatDate(new Date(),"yyyy-MM-dd HH:mm:ss"));
- List<TSUser> noWageUsers = wxdao.getNoWageUserList();
- List<Map<String,Object>> users = wxdao.getXZBFJLUsers("A_HRZL");
- List<String> receiveidList = new ArrayList<String>();
- if(noWageUsers.size() == 0 || users.size() == 0)
- return;
- for (Map<String,Object> map : users) {
- receiveidList.add(map.get("id").toString());
- }
- MessageSimpleRowViewer viewer = new MessageSimpleRowViewer();
- List<String> columns = new ArrayList<String>();
- columns.add("人员及所属项目");
- List<Object[]> data = new ArrayList<Object[]>();
- for (TSUser user : noWageUsers) {
- if(StringUtils.isNotEmpty(user.getRealName()))
- data.add(new String[] {user.getRealName()});
- }
- viewer.setData(data);
- viewer.setTitle("未配置或未更新工资策略人员清单");
- viewer.setColumns(columns);
- MessageWxTemplateConfig config = new MessageWxTemplateConfig();
- config.setTemplateId(XcglConstant.TEMPLATE_WXMSG_WARNING);
- Map<String, Object> userMsgParms = new HashMap<String, Object>();
- userMsgParms.put("first", "你好,未配置工资策略提醒");
- userMsgParms.put("keyword1", "截至今日,尚有"+data.size()+"个员工未配置工资策略或员工工资策略未更新");
- userMsgParms.put("keyword2", "美都环卫慧管理系统");
- userMsgParms.put("keyword3", DateUtils.formatDate(new Date(),"yyyy-MM-dd HH:mm"));
- userMsgParms.put("keyword4", "详情请点击消息链接");
- config.setUserMsgParms(userMsgParms);
- mMessageSend.sendViewer(receiveidList, viewer, config, new MessageSendWay[] {MessageSendWay.wx});
- logger.error("##########weixin-sendmsg-no wagestrategy warning end:"+DateUtils.formatDate(new Date(),"yyyy-MM-dd HH:mm:ss"));
- }
-
- }
|