dcs 4 bulan lalu
induk
melakukan
4731f17ef7

+ 2 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/dao/ReminderDao.java

@@ -13,6 +13,8 @@ public interface ReminderDao {
 
     int update(Reminder reminder);
 
+    int updateState(long id);
+
     int delete(long id);
 
     Reminder get(long id);

+ 25 - 1
virgo.api/src/main/java/com/bosshand/virgo/api/job/JobReminderQuartz.java

@@ -1,7 +1,9 @@
 package com.bosshand.virgo.api.job;
 
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.bosshand.virgo.api.service.ReminderService;
+import com.bosshand.virgo.core.utils.StringUtil;
 import org.quartz.JobDataMap;
 import org.quartz.JobExecutionContext;
 import org.quartz.JobExecutionException;
@@ -10,6 +12,9 @@ import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.quartz.QuartzJobBean;
 
+import java.util.ArrayList;
+import java.util.List;
+
 /**
  * 提醒任务
  */
@@ -26,10 +31,29 @@ public class JobReminderQuartz extends QuartzJobBean {
         JobDataMap mergedJobDataMap = jobExecutionContext.getMergedJobDataMap();
         String data = mergedJobDataMap.getString("data");
         JSONObject json = JSONObject.parseObject(data);
+        long id = json.getLongValue("id");
         long userId = json.getLongValue("creator");
         int type = json.getIntValue("type");
+        String userList = json.getString("userList");
+
+        List<String> userIds = new ArrayList<>();
+        userIds.add(String.valueOf(userId));
+
+        if (StringUtil.notBlank(userList)) {
+            JSONArray jsonArray = JSONObject.parseArray(userList);
+            if (jsonArray.size() > 0) {
+                for (int i = 0; i < jsonArray.size(); i++) {
+                    long uid = jsonArray.getJSONObject(i).getLongValue("id");
+                    userIds.add(String.valueOf(uid));
+                }
+            }
+        }
+
         String token = reminderService.getToken();
-        reminderService.send(token, String.valueOf(userId), json.toJSONString(), String.valueOf(type));
+        for (String d : userIds) {
+            reminderService.send(token, d, json.toJSONString(), String.valueOf(type));
+        }
+        reminderService.updateState(id);
     }
 
 }

+ 14 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/service/ManagerClient.java

@@ -0,0 +1,14 @@
+package com.bosshand.virgo.api.service;
+import com.bosshand.virgo.core.response.Response;
+import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+
+@FeignClient("virgo-manager")
+public interface ManagerClient {
+
+    @RequestMapping(value = "/message/reminder/{data}", method = RequestMethod.GET)
+    public Response pushReminderMessage(@PathVariable String data);
+
+}

+ 55 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/service/ReminderService.java

@@ -1,5 +1,6 @@
 package com.bosshand.virgo.api.service;
 
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.bosshand.virgo.api.dao.ReminderDao;
 import com.bosshand.virgo.api.model.Reminder;
@@ -11,6 +12,7 @@ import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
 import java.util.List;
 
 @Service
@@ -21,6 +23,9 @@ public class ReminderService {
     @Autowired
     ReminderDao reminderDao;
 
+    @Autowired
+    ManagerClient managerClient;
+
     public int getTotalCount(Reminder reminder) {
         return reminderDao.getTotalCount(reminder);
     }
@@ -44,6 +49,56 @@ public class ReminderService {
         return reminder;
     }
 
+    public void addMessage(Reminder reminder) {
+
+        long userId = reminder.getCreator();
+
+        long organizationId = reminder.getOrganizationId();
+        long projectId = reminder.getProjectId();
+
+        JSONObject json = new JSONObject();
+        json.put("organizationId", organizationId);
+        json.put("projectId", projectId);
+        json.put("dataId", reminder.getId());
+
+
+        List<Long> userIds = new ArrayList<>();
+        userIds.add(userId);
+
+        String userList = reminder.getUserList();
+        if (StringUtil.notBlank(userList)) {
+            JSONArray jsonArray = JSONObject.parseArray(userList);
+            if (jsonArray.size() > 0) {
+                for (int i = 0; i < jsonArray.size(); i++) {
+                    long uid = jsonArray.getJSONObject(i).getLongValue("id");
+                    userIds.add(uid);
+                }
+            }
+        }
+
+        JSONArray ja = new JSONArray();
+
+        for(Long d : userIds){
+            JSONObject js = new JSONObject();
+            js.put("messageType", 7);
+            js.put("sender", userId);
+            js.put("title", "提醒消息");
+            js.put("message","【提醒消息】");
+            js.put("userId",d);
+            js.put("viewed", false);
+            js.put("systemMessage", false);
+            js.put("pushed", false);
+            js.put("json", json.toJSONString());
+            js.put("isCC", false);
+            ja.add(js);
+        }
+        managerClient.pushReminderMessage(ja.toString());
+    }
+
+    public int updateState(long id) {
+        return reminderDao.updateState(id);
+    }
+
     public List<Reminder> getList(Reminder reminder) {
         return reminderDao.getList(reminder);
     }

+ 4 - 0
virgo.api/src/main/resources/mapper/ReminderMapper.xml

@@ -67,6 +67,10 @@
         DELETE FROM reminder WHERE id = #{id}
     </update>
 
+    <update id="updateState" parameterType="com.bosshand.virgo.api.model.Reminder">
+        UPDATE reminder set state = 1 WHERE id = #{id}
+    </update>
+
     <update id="update" parameterType="com.bosshand.virgo.api.model.Reminder">
         UPDATE reminder
         <trim prefix="set" suffixOverrides=",">

+ 1 - 0
virgo.core/src/main/java/com/bosshand/virgo/core/config/ShiroConfig.java

@@ -84,6 +84,7 @@ public class ShiroConfig {
 		filterChainDefinitionMap.put("/chain/**","anon");
 		filterChainDefinitionMap.put("/flowYuiDataFromYui/youjiProjectFlowId/","anon");
 		filterChainDefinitionMap.put("/department/userId/**","anon");
+		filterChainDefinitionMap.put("/message/reminder/**","anon");
 
 		filterChainDefinitionMap.put("/organization/listOnlyName","anon");
 		filterChainDefinitionMap.put("/pCode/**","anon");

+ 7 - 0
virgo.manager/src/main/java/com/bosshand/virgo/controller/MessageController.java

@@ -62,6 +62,13 @@ public class MessageController {
         return Response.ok();
     }
 
+    @ApiOperation(value = "提醒消息发送", notes = "提醒消息发送")
+    @RequestMapping(value = "/reminder/{data}", method = RequestMethod.GET)
+    public Response pushReminderMessage(@PathVariable String data) {
+        messageService.pushReminderMessage(data);
+        return Response.ok();
+    }
+
     @ApiOperation(value = "修改", notes = "修改")
     @RequestMapping(value = "/{id}", method = RequestMethod.PUT)
     public Response updateViewed(@PathVariable long id) {

+ 9 - 0
virgo.manager/src/main/java/com/bosshand/virgo/message/service/MessageService.java

@@ -1,5 +1,6 @@
 package com.bosshand.virgo.message.service;
 
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.bosshand.virgo.core.dao.MgrUserDao;
 import com.bosshand.virgo.exception.ServiceException;
@@ -168,4 +169,12 @@ public class MessageService {
 		}
 	}
 
+	public void pushReminderMessage(String data) {
+		JSONArray jsonArray = JSONArray.parseArray(data);
+		for (int i = 0; i < jsonArray.size(); i++) {
+			NotificationMessage message = JSONObject.parseObject(jsonArray.getJSONObject(i).toJSONString(), NotificationMessage.class);
+			notificationMessageDao.insert(message);
+		}
+	}
+
 }