123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- 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.dao.RemoteReminderDao;
- import com.bosshand.virgo.api.model.Reminder;
- import com.bosshand.virgo.api.model.RemoteReminder;
- import com.bosshand.virgo.core.utils.StringUtil;
- import com.bosshand.virgo.core.utils.WeChatUtil;
- import org.apache.commons.codec.digest.DigestUtils;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Map;
- @Service
- public class ReminderService {
- static Logger log = LoggerFactory.getLogger(ReminderService.class);
- @Autowired
- ReminderDao reminderDao;
- @Autowired
- RemoteReminderDao remoteReminderDao;
- @Autowired
- ManagerClient managerClient;
- public int getTotalCount(Reminder reminder) {
- return reminderDao.getTotalCount(reminder);
- }
- public List<Reminder> getLimit(Reminder reminder, int currPage, int pageSize) {
- int currIndex = (currPage - 1) * pageSize;
- return reminderDao.getLimit(reminder, currIndex, pageSize);
- }
- public Reminder get(long id) {
- return reminderDao.get(id);
- }
- public Reminder insert(Reminder reminder) {
- reminderDao.insert(reminder);
- return reminder;
- }
- public Reminder update(Reminder reminder) {
- reminderDao.update(reminder);
- return reminder;
- }
- public void addMessage(long id) {
- Reminder reminder = reminderDao.get(id);
- 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);
- }
- public int updateState(long id) {
- this.addMessage(id);
- return reminderDao.updateState(id);
- }
- public List<Reminder> getList(Reminder reminder) {
- return reminderDao.getList(reminder);
- }
- public int delete(long id) {
- return reminderDao.delete(id);
- }
- public String getToken() {
- JSONObject js = new JSONObject();
- String userId = "system";
- long timestamp = System.currentTimeMillis() + 30000;
- String yei = "50abd47112ebe8c5a73f4694c96a49ce";
- String sign = DigestUtils.md5Hex(userId + timestamp + yei);
- js.put("userId", userId);
- js.put("timestamp", timestamp);
- js.put("sign", sign);
- String s = WeChatUtil.httpPost("https://www.waywish.com/im/user/token/get", js, null);
- if (StringUtil.notBlank(s)) {
- String token = JSONObject.parseObject(s).getJSONObject("data").getString("token");
- return token;
- }
- return null;
- }
- public void send(String token, String userId, String data, String type) {
- long m = System.currentTimeMillis();
- JSONObject js = new JSONObject();
- js.put("conversationId", userId);
- js.put("conversationType", "private");
- js.put("from", "system");
- js.put("to", userId);
- js.put("type", "text");
- js.put("isRead", 0);
- js.put("isRevoke", 0);
- js.put("isDeleted", 0);
- js.put("status", "unSend");
- js.put("time", m);
- js.put("extra", data);
- JSONObject jo = new JSONObject();
- jo.put("nickname", "系统通知");
- jo.put("avatarUrl", "https://file-node.oss-cn-shanghai.aliyuncs.com/youji/3156449b8a1a4874981b2a76d5947721");
- js.put("fromUserInfo", jo);
- JSONObject j = new JSONObject();
- j.put("text", type);
- js.put("body", j);
- String s = WeChatUtil.httpPost("https://www.waywish.com/im/message/save", js, token);
- log.info("在" + m + "时间点给userId:" + userId + "发送消息成功.");
- }
- //================================================远程提醒设备设置========================================================================
- public int getRemoteReminderTotalCount(RemoteReminder remotereminder) {
- return remoteReminderDao.getTotalCount(remotereminder);
- }
- public List<RemoteReminder> getRemoteReminderLimit(RemoteReminder remotereminder, int currPage, int pageSize) {
- int currIndex = (currPage - 1) * pageSize;
- return remoteReminderDao.getLimit(remotereminder, currIndex, pageSize);
- }
- public RemoteReminder getRemoteReminder(long id) {
- return remoteReminderDao.get(id);
- }
- public RemoteReminder insertRemoteReminder(RemoteReminder remotereminder) {
- remoteReminderDao.insert(remotereminder);
- return remotereminder;
- }
- public RemoteReminder updateRemoteReminder(RemoteReminder remotereminder) {
- remoteReminderDao.update(remotereminder);
- return remotereminder;
- }
- public int deleteRemoteReminder(long id) {
- return remoteReminderDao.delete(id);
- }
- public Map<String, Object> projectCount(long projectId) {
- Map<String, Object> map = reminderDao.projectCount(projectId);
- int number = remoteReminderDao.projectCount(projectId);
- map.put("remoteNumber", number);
- return map;
- }
- }
|