Reader 层面根据约定的格式修改 #20

Merged
baladiwei merged 1 commits from baladiwei/gitlink-notification-system:master into master 2021-09-08 14:31:53 +08:00
2 changed files with 77 additions and 40 deletions

View File

@ -0,0 +1,77 @@
package cn.org.gitlink.notification.reader.controller;
import cn.org.gitlink.notification.common.response.DataPacketUtil;
import cn.org.gitlink.notification.common.response.ResponseData;
import cn.org.gitlink.notification.common.utils.RedisUtil;
import cn.org.gitlink.notification.model.dao.entity.SysNotification;
import cn.org.gitlink.notification.model.service.notification.SysNotificationService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping(value = "/gns/notification")
public class NotificationController {
private static final String PLATFORM_CODE_GITLINK = "gitlink";
@Autowired
private RedisUtil redisUtil;
@Autowired
@Qualifier(value = "sysNotificationServiceImpl")
private SysNotificationService notificationService;
private Logger logger = LogManager.getLogger(NotificationController.class);
/**
* http://{domain}:{port}/gns/notification/list/
* http://{domain}:{port}/gns/notification/count
*
* @param type
* @param receiver
* @return
*/
@GetMapping(value = "/{type}")
public ResponseData index(@PathVariable(name = "type", required = true) String type,
@RequestParam(name = "receiver", required = true) Integer receiver,
@RequestParam(name = "page", required = false, defaultValue = "1") Integer pageNum,
@RequestParam(name = "size", required = false, defaultValue = "20") Integer pageSize) {
if (receiver <= 0 || receiver >= Integer.MAX_VALUE) {
logger.debug("------>输入参数 {receiver} 的值 {" + receiver + "} 超出约定范围");
DataPacketUtil.jsonFailResult("参数 {receiver} 非法");
}
if (type.trim().toLowerCase().equals("list")) {
//用户请求的是 list
logger.debug("------>{type} 参数是 list");
//TODO: 获取约定的必要参数
//调用业务逻辑获取数据结果
List<SysNotification> foundList = notificationService.getUnreadSysNotificationsList(PLATFORM_CODE_GITLINK, receiver, pageSize);
//拼装约定的 json 格式并返回
return DataPacketUtil.jsonSuccessResult(foundList);
} else if (type.trim().toLowerCase().equals("count")) {
//用户请求的是数字
logger.debug("------>{type} 参数是 count");
//TODO: 获取必要的参数
//调用业务逻辑获取数据结果
Integer foundCount = notificationService.getSysNotificationNumberByType(PLATFORM_CODE_GITLINK, receiver, 1);
//拼装约定的 json 格式并返回
return DataPacketUtil.jsonSuccessResult(foundCount);
} else {
logger.debug("------>输入参数 {type} 的值 {" + type + "} 无效");
return DataPacketUtil.jsonFailResult("参数 {type} 非法");
}//end of if-else
}//end of method
}//end of class

View File

@ -1,40 +0,0 @@
package cn.org.gitlink.notification.reader.controller;
import cn.org.gitlink.notification.common.response.DataPacketUtil;
import cn.org.gitlink.notification.common.response.ResponseData;
import cn.org.gitlink.notification.common.utils.RedisUtil;
import cn.org.gitlink.notification.model.dao.entity.SysNotification;
import cn.org.gitlink.notification.model.service.notification.SysNotificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
@RequestMapping(value = "/gns/sys_notification")
public class SysNotificationController {
public static final String GITLINK_PLATFORM_CODE = "gitlink";
@Autowired
private RedisUtil redisUtil;
@Autowired
@Qualifier(value = "sysNotificationServiceImpl")
private SysNotificationService notificationService;
@GetMapping(value = "/unread_message_count/{receiver}")
public ResponseData unreadMessageCount(@PathVariable(name = "receiver", required = true) Integer receiver) {
if (receiver > 0) {
List<SysNotification> foundList = notificationService.getUnreadSysNotificationsList(SysNotificationController.GITLINK_PLATFORM_CODE, receiver, 20);
return DataPacketUtil.jsonSuccessResult(foundList);
} else {
return DataPacketUtil.jsonFailResult("参数 {receiver} 非法");
}
}
}