Browse Source

任务进展通知企业微信消息提醒

yurk 2 years ago
parent
commit
ecb6ca08cb

+ 45 - 3
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/TaskProgressServiceImpl.java

@@ -1,11 +1,14 @@
 package com.management.platform.service.impl;
 package com.management.platform.service.impl;
 
 
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.management.platform.entity.*;
 import com.management.platform.entity.*;
 import com.management.platform.mapper.*;
 import com.management.platform.mapper.*;
 import com.management.platform.service.TaskProgressService;
 import com.management.platform.service.TaskProgressService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.management.platform.service.TprogressPaticipatorsService;
 import com.management.platform.service.TprogressPaticipatorsService;
+import com.management.platform.service.WxCorpInfoService;
 import com.management.platform.util.HttpRespMsg;
 import com.management.platform.util.HttpRespMsg;
 import com.management.platform.util.ListUtil;
 import com.management.platform.util.ListUtil;
 import com.management.platform.util.MessageUtils;
 import com.management.platform.util.MessageUtils;
@@ -45,6 +48,10 @@ public class TaskProgressServiceImpl extends ServiceImpl<TaskProgressMapper, Tas
     private ProjectMapper projectMapper;
     private ProjectMapper projectMapper;
     @Resource
     @Resource
     private TaskCommentMapper taskCommentMapper;
     private TaskCommentMapper taskCommentMapper;
+    @Resource
+    private WxCorpInfoService wxCorpInfoService;
+    @Resource
+    private WxCorpInfoMapper wxCorpInfoMapper;
     //String[] statusList = new String[]{"状态正常", "存在风险", "进展逾期"};
     //String[] statusList = new String[]{"状态正常", "存在风险", "进展逾期"};
     @Override
     @Override
     public HttpRespMsg addProgress(TaskProgress progress, String participatorIds, HttpServletRequest request) {
     public HttpRespMsg addProgress(TaskProgress progress, String participatorIds, HttpServletRequest request) {
@@ -77,7 +84,9 @@ public class TaskProgressServiceImpl extends ServiceImpl<TaskProgressMapper, Tas
         String updateStr = creator.getName()+MessageUtils.message("stages.upTask") + status;
         String updateStr = creator.getName()+MessageUtils.message("stages.upTask") + status;
         comment.setContent(updateStr);
         comment.setContent(updateStr);
         taskCommentMapper.insert(comment);
         taskCommentMapper.insert(comment);
-
+        Task task = taskMapper.selectById(progress.getTaskId());
+        Project project = projectMapper.selectById(task.getProjectId());
+        WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectOne(new QueryWrapper<WxCorpInfo>().eq("company_id", creator.getCompanyId()));
         if (!StringUtils.isEmpty(participatorIds)) {
         if (!StringUtils.isEmpty(participatorIds)) {
             List<String> ids = ListUtil.convertLongIdsArrayToList(participatorIds);
             List<String> ids = ListUtil.convertLongIdsArrayToList(participatorIds);
             List<User> userList = userMapper.selectList(new QueryWrapper<User>().in("id", ids));
             List<User> userList = userMapper.selectList(new QueryWrapper<User>().in("id", ids));
@@ -87,7 +96,6 @@ public class TaskProgressServiceImpl extends ServiceImpl<TaskProgressMapper, Tas
                 item.setUserId(user.getId());
                 item.setUserId(user.getId());
                 item.setUserName(user.getName());
                 item.setUserName(user.getName());
                 tprogressPaticipatorsMapper.insert(item);
                 tprogressPaticipatorsMapper.insert(item);
-
                 //发消息通知进展
                 //发消息通知进展
                 Information information = new Information();
                 Information information = new Information();
                 information.setContent(""+progress.getTaskId());
                 information.setContent(""+progress.getTaskId());
@@ -95,8 +103,42 @@ public class TaskProgressServiceImpl extends ServiceImpl<TaskProgressMapper, Tas
                 information.setUserId(user.getId());
                 information.setUserId(user.getId());
                 information.setType(2);
                 information.setType(2);
                 informationMapper.insert(information);
                 informationMapper.insert(information);
-
                 //TODO:如果关联了微信或者企业微信,可以推送通知
                 //TODO:如果关联了微信或者企业微信,可以推送通知
+                if(user.getCorpwxUserid()!=null){
+                    String corpwxUserid = user.getCorpwxUserid();
+                    //推送到企业微信
+                    JSONObject json=new JSONObject();
+                    JSONArray dataJson=new JSONArray();
+                    JSONObject jsonObj=new JSONObject();
+                    jsonObj.put("key", "项目名称");
+                    jsonObj.put("value",project.getProjectName());
+
+                    JSONObject jsonObj1=new JSONObject();
+                    jsonObj1.put("key", "任务名称");
+                    jsonObj1.put("value",task.getName());
+
+                    JSONObject jsonObj2=new JSONObject();
+                    jsonObj2.put("key", "进展内容");
+                    jsonObj2.put("value",progress.getContent());
+
+                    JSONObject jsonObj3=new JSONObject();
+                    jsonObj3.put("key", "任务状态");
+                    switch (progress.getStatus()){
+                        case 0:jsonObj3.put("value","状态正常");
+                        break;
+                        case 1:jsonObj3.put("value","存在风险");
+                        break;
+                        case 2:jsonObj3.put("value","进展逾期");
+                    }
+                    dataJson.add(jsonObj);
+                    dataJson.add(jsonObj1);
+                    dataJson.add(jsonObj2);
+                    dataJson.add(jsonObj3);
+                    json.put("template_id","tty9TkCAAASja8aiHGlheqEHQ7OIpRyg");
+                    json.put("url","https://open.weixin.qq.com/connect/oauth2/authorize?appid=ww4e237fd6abb635af&redirect_uri=http://worktime.ttkuaiban.com/api/corpWXAuth&response_type=code&scope=snsapi_base&state=0#wechat_redirect");
+                    json.put("content_item",dataJson);
+                    wxCorpInfoService.sendWXCorpTemplateMsg(wxCorpInfo, corpwxUserid, json);
+                }
             }
             }
         }
         }