diff --git a/.idea/artifacts/web_api_war_exploded.xml b/.idea/artifacts/web_api_war_exploded.xml
index 01ed77c..b1b9f77 100644
--- a/.idea/artifacts/web_api_war_exploded.xml
+++ b/.idea/artifacts/web_api_war_exploded.xml
@@ -33,6 +33,8 @@
+
+
@@ -107,7 +109,6 @@
-
diff --git a/.idea/libraries/Maven__cn_jpush_api_jpush_client_3_2_9.xml b/.idea/libraries/Maven__cn_jpush_api_jpush_client_3_2_9.xml
new file mode 100644
index 0000000..953cb34
--- /dev/null
+++ b/.idea/libraries/Maven__cn_jpush_api_jpush_client_3_2_9.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Maven__com_google_code_gson_gson_2_3.xml b/.idea/libraries/Maven__com_google_code_gson_gson_2_3.xml
new file mode 100644
index 0000000..4dcaf15
--- /dev/null
+++ b/.idea/libraries/Maven__com_google_code_gson_gson_2_3.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/mainData/pom.xml b/mainData/pom.xml
index 2a4c6e1..55d8434 100644
--- a/mainData/pom.xml
+++ b/mainData/pom.xml
@@ -17,6 +17,7 @@
base-common
${project.version}
+
diff --git a/mainData/src/main/java/com/lymsh/yimiao/main/data/service/PushTaskService.java b/mainData/src/main/java/com/lymsh/yimiao/main/data/service/PushTaskService.java
new file mode 100644
index 0000000..232f7be
--- /dev/null
+++ b/mainData/src/main/java/com/lymsh/yimiao/main/data/service/PushTaskService.java
@@ -0,0 +1,9 @@
+package com.lymsh.yimiao.main.data.service;
+
+/**
+ * Created by Administrator on 2016/5/24 0024.
+ */
+public interface PushTaskService {
+
+ public void pushTask();
+}
diff --git a/mainData/src/main/java/com/lymsh/yimiao/main/data/service/impl/PushTaskServiceImpl.java b/mainData/src/main/java/com/lymsh/yimiao/main/data/service/impl/PushTaskServiceImpl.java
new file mode 100644
index 0000000..2e6305b
--- /dev/null
+++ b/mainData/src/main/java/com/lymsh/yimiao/main/data/service/impl/PushTaskServiceImpl.java
@@ -0,0 +1,170 @@
+package com.lymsh.yimiao.main.data.service.impl;
+
+import cn.jpush.api.JPushClient;
+import cn.jpush.api.push.PushResult;
+import cn.jpush.api.push.model.Platform;
+import cn.jpush.api.push.model.PushPayload;
+import cn.jpush.api.push.model.audience.Audience;
+import cn.jpush.api.push.model.notification.Notification;
+import com.lymsh.mommybaby.basecommon.util.DateUtil;
+import com.lymsh.yimiao.main.data.enumdata.YnEnum;
+import com.lymsh.yimiao.main.data.model.*;
+import com.lymsh.yimiao.main.data.service.*;
+import com.lymsh.yimiao.main.data.util.JPushUtil;
+import org.apache.commons.collections.CollectionUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.util.Date;
+import java.util.List;
+
+/**
+ *
+ * 定时推送接种消息
+ *
+ * Created by Administrator on 2016/5/24 0024.
+ */
+@Service
+public class PushTaskServiceImpl implements PushTaskService{
+
+ @Autowired
+ private JPushClient jPushClient;
+ @Autowired
+ private MedInoculateOrderService medInoculateOrderService;
+ @Autowired
+ private YmUserKidMapsService ymUserKidMapsService;
+ @Autowired
+ private YmUsersService ymUsersService;
+ @Autowired
+ private YmPushMessagesService ymPushMessagesService;
+ @Autowired
+ private MedKidsService medKidsService;
+ @Autowired
+ private MedVaccineNameService medVaccineNameService;
+
+ private final static String isDelete = "1";
+
+ public static final int THREE_DAY_SECONDS = 86400 * 1000 * 3;
+
+ public static final int ONE_DAY_SECONDS = 86400 * 1000;
+
+ private static final String ALERT = "您有一条新的推送";
+
+ private static final String ALIAS = "yimiaoer";
+
+ @Override
+ public void pushTask() {
+ //距离三天
+ MedInoculateOrderQuery orderQuery = new MedInoculateOrderQuery();
+ orderQuery.setIoIsDelete(isDelete);
+ orderQuery.setIoInoculateDate(DateUtil.getyyyy_MM_dd(new Date(DateUtil.getStartTime() + THREE_DAY_SECONDS)).toString());
+ List orderList = medInoculateOrderService.queryMedInoculateOrder(orderQuery);
+ if (CollectionUtils.isNotEmpty(orderList)){
+ //距离当前还有三天就要接种的小孩
+ for (MedInoculateOrder data : orderList){
+
+ //接种的疫苗名称
+ MedVaccineName medVaccineName = medVaccineNameService.getMedVaccineName(data.getIoVaccineId());
+
+ YmUserKidMapsQuery mapsQuery = new YmUserKidMapsQuery();
+ mapsQuery.setYn(YnEnum.yes.getId());
+ mapsQuery.setKidId(data.getIoKidId());
+ List mapsList = ymUserKidMapsService.queryYmUserKidMaps(mapsQuery);
+ //得到和小孩关联的账号
+ if (CollectionUtils.isNotEmpty(mapsList)){
+ for (YmUserKidMaps temp : mapsList){
+
+ //得到小孩的名字
+ MedKids medKids = medKidsService.getMedKids(temp.getKidId());
+
+ YmUsersQuery usersQuery = new YmUsersQuery();
+ usersQuery.setYn(YnEnum.yes.getId());
+ usersQuery.setId(temp.getUserId());
+ //拿到最后所有需要发推送的用户
+ List usersList = ymUsersService.queryYmUsers(usersQuery);
+ if (CollectionUtils.isNotEmpty(usersList)) {
+ YmUsers users = usersList.get(0);
+ PushPayload pushPayload = JPushUtil.buildPushObject_all_alias_alert(ALIAS + users.getPhone(), ALERT);
+ if (pushPayload != null) {
+ YmPushMessages messages = new YmPushMessages();
+ messages.setCreated(new Date());
+ messages.setContent((medKids == null ? "" : medKids.getName() == null ? "" : medKids.getName()) + "小朋友按计划3天后将会接种" +
+ (medVaccineName == null ? "" : medVaccineName.getVnName()) + ",请提前做好准备,准时到接种点接种疫苗。");
+ messages.setReceptionId(users.getId());
+ messages.setYn(YnEnum.yes.getId());
+ ymPushMessagesService.addYmPushMessages(messages);
+
+ //成功后推送提示消息
+ try {
+ jPushClient.sendPush(pushPayload);
+ } catch (Exception e) {
+
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ //距离一天
+ MedInoculateOrderQuery orderQuery1 = new MedInoculateOrderQuery();
+ orderQuery1.setIoIsDelete(isDelete);
+ orderQuery1.setIoInoculateDate(DateUtil.getyyyy_MM_dd(new Date(DateUtil.getStartTime() + ONE_DAY_SECONDS)).toString());
+ List orderList1 = medInoculateOrderService.queryMedInoculateOrder(orderQuery1);
+ if (CollectionUtils.isNotEmpty(orderList1)){
+ for (MedInoculateOrder data : orderList1){
+
+ //接种的疫苗名称
+ MedVaccineName medVaccineName = medVaccineNameService.getMedVaccineName(data.getIoVaccineId());
+
+ YmUserKidMapsQuery mapsQuery = new YmUserKidMapsQuery();
+ mapsQuery.setYn(YnEnum.yes.getId());
+ mapsQuery.setKidId(data.getIoKidId());
+ List mapsList = ymUserKidMapsService.queryYmUserKidMaps(mapsQuery);
+ //得到和小孩关联的账号
+ if (CollectionUtils.isNotEmpty(mapsList)){
+ for (YmUserKidMaps temp : mapsList){
+
+ //得到小孩的名字
+ MedKids medKids = medKidsService.getMedKids(temp.getKidId());
+
+ YmUsersQuery usersQuery = new YmUsersQuery();
+ usersQuery.setYn(YnEnum.yes.getId());
+ usersQuery.setId(temp.getUserId());
+ //拿到最后所有需要发推送的用户
+ List usersList = ymUsersService.queryYmUsers(usersQuery);
+ if (CollectionUtils.isNotEmpty(usersList)) {
+ YmUsers users = usersList.get(0);
+ PushPayload pushPayload = JPushUtil.buildPushObject_all_alias_alert(ALIAS + users.getPhone(), ALERT);
+ if (pushPayload != null) {
+ YmPushMessages messages = new YmPushMessages();
+ messages.setCreated(new Date());
+ messages.setContent((medKids == null ? "" : medKids.getName() == null ? "" : medKids.getName()) + "小朋友按计划1天后将会接种" +
+ (medVaccineName == null ? "" : medVaccineName.getVnName()) + ",请提前做好准备,准时到接种点接种疫苗。");
+ messages.setReceptionId(users.getId());
+ messages.setYn(YnEnum.yes.getId());
+ ymPushMessagesService.addYmPushMessages(messages);
+
+ //成功后推送提示消息
+ try {
+ jPushClient.sendPush(pushPayload);
+ } catch (Exception e) {
+
+ }
+ }
+ }
+ }
+ }
+ }
+
+
+
+ }
+
+
+ }
+
+}
diff --git a/pom.xml b/pom.xml
index 1ed41c1..dfbf4c2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -44,6 +44,11 @@
+ cn.jpush.api
+ jpush-client
+ 3.2.9
+
+
org.springframework
spring-core
${org.springframework.version}
diff --git a/webApi/src/main/java/com/lyms/yimiao/web/controller/v1/NotificationsController.java b/webApi/src/main/java/com/lyms/yimiao/web/controller/v1/NotificationsController.java
index bb93189..18d5b71 100644
--- a/webApi/src/main/java/com/lyms/yimiao/web/controller/v1/NotificationsController.java
+++ b/webApi/src/main/java/com/lyms/yimiao/web/controller/v1/NotificationsController.java
@@ -8,7 +8,11 @@ import com.lymsh.mommybaby.basecommon.util.ResultUtils;
import com.lymsh.yimiao.main.data.enumdata.YnEnum;
import com.lymsh.yimiao.main.data.model.YmNotifications;
import com.lymsh.yimiao.main.data.model.YmNotificationsQuery;
+import com.lymsh.yimiao.main.data.model.YmPushMessages;
+import com.lymsh.yimiao.main.data.model.YmPushMessagesQuery;
import com.lymsh.yimiao.main.data.service.YmNotificationsService;
+import com.lymsh.yimiao.main.data.service.YmPushMessagesService;
+import com.lymsh.yimiao.main.data.util.LoginContext;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
@@ -17,11 +21,9 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import javax.management.Notification;
+import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
/**
*
@@ -35,17 +37,22 @@ public class NotificationsController extends BaseController{
@Autowired
private YmNotificationsService notificationsService;
+ @Autowired
+ private YmPushMessagesService ymPushMessagesService;
//获取消息(1.系统消息2.接种消息)
@RequestMapping(value = "/notifications", method = RequestMethod.GET)
@TokenRequired
- public void getNotifications(HttpServletResponse response){
-
+ public void getNotifications(HttpServletResponse response,
+ HttpServletRequest request
+// , @RequestParam(value = "time",required = false) long time
+ ){
+ //系统消息
YmNotificationsQuery notificationsQuery = new YmNotificationsQuery();
notificationsQuery.setYn(YnEnum.yes.getId());
-
notificationsQuery.setSort("created desc");
+// notificationsQuery.setCreated(new Date(time*1000));
List notificationsList = notificationsService.queryYmNotifications(notificationsQuery);
List