src/main/java/com/ruoyi/project/system/controller/SysNoticeController.java
@@ -5,17 +5,11 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.ruoyi.framework.web.domain.R; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.*; import com.ruoyi.framework.aspectj.lang.annotation.Log; import com.ruoyi.framework.aspectj.lang.enums.BusinessType; import com.ruoyi.framework.web.controller.BaseController; @@ -99,4 +93,11 @@ { return toAjax(noticeService.readAll()); } @PostMapping("appReadNotice") @ApiOperation("移动端根据消息ID进行已读") public AjaxResult appReadNotice(@RequestParam("noticeId") Long noticeId) { boolean result = noticeService.appReadNotice(noticeId); return toAjax(result); } } src/main/java/com/ruoyi/project/system/domain/SysNotice.java
@@ -3,8 +3,7 @@ import javax.validation.constraints.NotBlank; import javax.validation.constraints.Size; import com.baomidou.mybatisplus.annotation.FieldFill; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.*; import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Data; import org.apache.commons.lang3.builder.ToStringBuilder; @@ -20,11 +19,13 @@ * @author ruoyi */ @Data @TableName("sys_notice") public class SysNotice { private static final long serialVersionUID = 1L; /** 公告ID */ @TableId(value = "notice_id", type = IdType.AUTO) private Long noticeId; /** 公告标题 */ src/main/java/com/ruoyi/project/system/service/ISysNoticeService.java
@@ -82,4 +82,11 @@ */ void simpleNoticeAll(final String title, final String message,final String jumpPath); /** * APP点击推送消息更改为已读状态 * * @param noticeId 消息ID * @return 失败/成功 */ boolean appReadNotice(Long noticeId); } src/main/java/com/ruoyi/project/system/service/impl/SysNoticeServiceImpl.java
@@ -28,6 +28,7 @@ import com.ruoyi.project.system.domain.SysNotice; import com.ruoyi.project.system.mapper.SysNoticeMapper; import com.ruoyi.project.system.service.ISysNoticeService; import org.springframework.transaction.annotation.Transactional; /** * 公告 服务层实现 @@ -230,4 +231,20 @@ return sysNotice; } @Override @Transactional(rollbackFor = Exception.class) public boolean appReadNotice(Long noticeId) { if (noticeId == null) { return false; } SysNotice sysNotice = noticeMapper.selectNoticeById(noticeId); if (sysNotice == null) { return false; } sysNotice.setStatus("1"); return noticeMapper.update(null, Wrappers.<SysNotice>lambdaUpdate() .eq(SysNotice::getNoticeId, noticeId) .eq(SysNotice::getStatus, "0") .set(SysNotice::getStatus, "1")) > 0; } } src/main/java/com/ruoyi/project/system/service/impl/UnipushService.java
@@ -1,5 +1,6 @@ package com.ruoyi.project.system.service.impl; import com.alibaba.fastjson2.JSON; import com.getui.push.v2.sdk.ApiHelper; import com.getui.push.v2.sdk.GtApiConfiguration; import com.getui.push.v2.sdk.api.PushApi; @@ -25,6 +26,7 @@ import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -84,6 +86,7 @@ // 推送 sendRoutingPush( sysNotice.getNoticeId(), client.getCid(), sysNotice.getNoticeTitle(), sysNotice.getRemark() != null ? sysNotice.getRemark() : sysNotice.getNoticeContent(), @@ -139,18 +142,23 @@ /** * 发送单人路由推送 */ private void sendRoutingPush(String cid, String title, String content, String targetPath) { log.info("准备推送消息: CID={}, Title={}, TargetPath={}", cid, title, targetPath); private void sendRoutingPush(Long noticeId, String cid, String title, String content, String targetPath) { log.info("准备推送消息:NoticeId={}, CID={}, Title={}, TargetPath={}", noticeId, cid, title, targetPath); PushDTO<Audience> pushDTO = new PushDTO<>(); pushDTO.setRequestId("REQ_" + System.currentTimeMillis()); // 在线透传内容 PushMessage pushMessage = new PushMessage(); String transmissionContent = String.format( "{\"title\":\"%s\",\"content\":\"%s\",\"payload\":\"%s\"}", title, content, targetPath ); Map<String, Object> pushMessageMap = new HashMap<>(); Map<String, Object> payloadMap = new HashMap<>(); pushMessageMap.put("title", title); pushMessageMap.put("content", content); payloadMap.put("url", targetPath); payloadMap.put("noticeId", noticeId); pushMessageMap.put("payload", JSON.toJSONString(payloadMap)); String transmissionContent = JSON.toJSONString(pushMessageMap); pushMessage.setTransmission(transmissionContent); pushDTO.setPushMessage(pushMessage); @@ -160,7 +168,7 @@ pushDTO.setAudience(audience); // 离线推送通道 pushDTO.setPushChannel(getPushChannel(title, content, targetPath)); // pushDTO.setPushChannel(getPushChannel(noticeId, title, content, targetPath)); try { ApiResult<Map<String, Map<String, String>>> result = pushApi.pushToSingleByCid(pushDTO); @@ -175,7 +183,7 @@ } @NotNull private PushChannel getPushChannel(String title, String content, String targetPath) { private PushChannel getPushChannel(Long noticeId, String title, String content, String targetPath) { PushChannel pushChannel = new PushChannel(); AndroidDTO androidDTO = new AndroidDTO(); Ups ups = new Ups();