Reader层一些示例代码

This commit is contained in:
巴拉迪维 2021-09-08 13:39:17 +08:00
parent 67f5dedc6d
commit 9bebf6a120
6 changed files with 57 additions and 23 deletions

View File

@ -12,7 +12,7 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.Arrays;
import java.util.List;
@Service
@Service(value = "sysNotificationServiceImpl")
public class SysNotificationServiceImpl extends ServiceImpl<SysNotificationMapper, SysNotification> implements SysNotificationService {
@Override

View File

@ -2,6 +2,6 @@ spring:
datasource:
# 配置数据源类型
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://192.168.199.117/gitlink-notification-system?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&serverTimezone=GMT%2B8&allowMultiQueries=true
username: root
password: 950611
url: jdbc:mysql://localhost:33306/gitlink_notification?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&serverTimezone=GMT%2B8&allowMultiQueries=true
username: gitlink
password: giTlinK0^827

View File

@ -25,6 +25,11 @@
<artifactId>gns-common</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>cn.org.gitlink.notification</groupId>
<artifactId>gns-model</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
<build>

View File

@ -1,19 +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 org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class IndexController {
@Autowired
private RedisUtil redisUtil;
@GetMapping(value = "")
public ResponseData index() {
redisUtil.set("hello", "Hello reader!");
return DataPacketUtil.jsonSuccessResult(redisUtil.get("hello").toString());
}
}

View File

@ -0,0 +1,40 @@
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} 非法");
}
}
}

View File

@ -5,6 +5,7 @@ logging:
config: classpath:logback.xml
spring:
redis:
# Redis数据库索引默认为0
database: 0
@ -26,5 +27,12 @@ spring:
# 连接超时时间(毫秒)
timeout: 1000
datasource:
# 配置数据源类型
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:33306/gitlink_notification?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&serverTimezone=GMT%2B8&allowMultiQueries=true
username: gitlink
password: giTlinK0^827
#ip白名单列表多个ip用逗号隔开允许所有用*号
white-list: '*'