调整 service 层面的部分代码规范 #25
|
|
@ -8,21 +8,58 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
|||
import java.util.List;
|
||||
|
||||
public interface SysNotificationService extends IService<SysNotification> {
|
||||
|
||||
//给用户发送消息
|
||||
boolean addSysNotificationForUsers(NewSysNotificationVo sysNotification);
|
||||
boolean sendNotification(NewSysNotificationVo sysNotification);
|
||||
|
||||
//变更消息状态
|
||||
int changeStatusByNotificationIds(String platform, String notificationIds, Integer status);
|
||||
/**
|
||||
* 设置系统消息状态为:
|
||||
*
|
||||
* @param platform 平台编号
|
||||
* @param notificationIds 消息编号列表,中英文逗号隔开,eg:221,2323,4,111,23123
|
||||
* @param status 1 未读 2已读
|
||||
* @return
|
||||
*/
|
||||
int markNotificationAs(String platform, String notificationIds, Integer status);
|
||||
|
||||
//获取全部未读消息数量
|
||||
int getAllNewSysNotificationNumber(String platform, Integer receiver);
|
||||
/**
|
||||
* 获取所有未读消息总数
|
||||
*
|
||||
* @param platform 平台编号
|
||||
* @param receiver 信息接收者
|
||||
* @return
|
||||
*/
|
||||
int getUnreadNotificationCount(String platform, Integer receiver);
|
||||
|
||||
//获取未读消息列表
|
||||
List<SysNotification> getUnreadSysNotificationsList(String platform, Integer receiver, Integer notificationNumber);
|
||||
/**
|
||||
* 获取所有未读消息
|
||||
*
|
||||
* @param platform 平台编号
|
||||
* @param receiver 消息接收者
|
||||
* @param size 页大小
|
||||
* @return
|
||||
*/
|
||||
List<SysNotification> getUnreadNotificationByType(String platform, Integer receiver, Integer size);
|
||||
|
||||
//根据类型获取未读系统消息数量
|
||||
int getSysNotificationNumberByType(String platform, Integer receiver, Integer type);
|
||||
/**
|
||||
*按分类获取未读消息总数
|
||||
*
|
||||
* @param type 1 系统消息 2 @我
|
||||
* @param platform 平台编号
|
||||
* @param receiver 消息接收者
|
||||
* @return
|
||||
*/
|
||||
int getUnreadNotificationByType(Integer type, String platform, Integer receiver);
|
||||
|
||||
//获取全部消息分页列表
|
||||
Page<SysNotification> getAllSysNotificationsPageList(int curPage, int pageSize, String orderBy, String platform, Integer receiver);
|
||||
/**
|
||||
* 获取所有系统消息
|
||||
*
|
||||
* @param page 页码
|
||||
* @param size 页大小
|
||||
* @param orderBy 排序
|
||||
* @param platform 平台编号
|
||||
* @param receiver 消息接收者
|
||||
* @return
|
||||
*/
|
||||
Page<SysNotification> getNotification(int page, int size, String orderBy, String platform, Integer receiver);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,98 +15,45 @@ import java.util.List;
|
|||
@Service(value = "sysNotificationServiceImpl")
|
||||
public class SysNotificationServiceImpl extends ServiceImpl<SysNotificationMapper, SysNotification> implements SysNotificationService {
|
||||
|
||||
/**
|
||||
* @Description: 给用户发送消息
|
||||
* @Param newSysNotificationVo
|
||||
* @return: boolean
|
||||
* @Author: wanjia
|
||||
* @Date: 2021/9/8
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean addSysNotificationForUsers(NewSysNotificationVo newSysNotificationVo) {
|
||||
public boolean sendNotification(NewSysNotificationVo newSysNotificationVo) {
|
||||
SysNotification sysNotification = new SysNotification();
|
||||
sysNotification.setSender(newSysNotificationVo.getSender());
|
||||
sysNotification.setContent(newSysNotificationVo.getContent());
|
||||
sysNotification.setNotificationUrl(newSysNotificationVo.getNotification_url());
|
||||
sysNotification.setType(newSysNotificationVo.getType());
|
||||
List<String> list = Arrays.asList(newSysNotificationVo.getReceivers().split(","));
|
||||
for(String s : list){
|
||||
for (String s : list) {
|
||||
sysNotification.setReceiver(Long.parseLong(s));
|
||||
baseMapper.insertSelective(newSysNotificationVo.getPlatform(), sysNotification);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Description: 变更消息状态
|
||||
* @Param platform:平台编码
|
||||
* @Param notificationIds:消息ids example-"23,24,25"
|
||||
* @Param status:1-未读2-已读
|
||||
* @return: int
|
||||
* @Author: wanjia
|
||||
* @Date: 2021/9/8
|
||||
*/
|
||||
@Override
|
||||
public int changeStatusByNotificationIds(String platform, String notificationIds, Integer status) {
|
||||
public int markNotificationAs(String platform, String notificationIds, Integer status) {
|
||||
return baseMapper.updateStatusByNotificationId(platform, notificationIds, status);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Description: 获取全部未读消息数量
|
||||
* @Param platform:平台编码
|
||||
* @Param receiver:接收者id
|
||||
* @return: int
|
||||
* @Author: wanjia
|
||||
* @Date: 2021/9/8
|
||||
*/
|
||||
@Override
|
||||
public int getAllNewSysNotificationNumber(String platform, Integer receiver) {
|
||||
public int getUnreadNotificationCount(String platform, Integer receiver) {
|
||||
return baseMapper.getNewSysNotificationNumber(platform, receiver);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Description: 获取未读消息列表
|
||||
* @Param platform:平台编码
|
||||
* @Param receiver:接收者id
|
||||
* @Param notificationNumber:消息limit数
|
||||
* @return: java.util.List<SysNotification>
|
||||
* @Author: wanjia
|
||||
* @Date: 2021/9/8
|
||||
*/
|
||||
@Override
|
||||
public List<SysNotification> getUnreadSysNotificationsList(String platform, Integer receiver, Integer notificationNumber) {
|
||||
List<SysNotification> sysNotificationList = baseMapper.getUnreadSysNotificationsList(platform, receiver, 1, notificationNumber);
|
||||
public List<SysNotification> getUnreadNotificationByType(String platform, Integer receiver, Integer size) {
|
||||
List<SysNotification> sysNotificationList = baseMapper.getUnreadSysNotificationsList(platform, receiver, 1, size);
|
||||
return sysNotificationList;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Description: 根据类型获取未读系统消息数量
|
||||
* @Param platform:平台编码
|
||||
* @Param receiver:接收者id
|
||||
* @Param type:消息类型1-系统消息2-@我
|
||||
* @return: int
|
||||
* @Author: wanjia
|
||||
* @Date: 2021/9/8
|
||||
*/
|
||||
@Override
|
||||
public int getSysNotificationNumberByType(String platform, Integer receiver, Integer type) {
|
||||
public int getUnreadNotificationByType(Integer type, String platform, Integer receiver) {
|
||||
return baseMapper.getSysNotificationNumberByType(platform, receiver, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Description: 获取全部消息分页列表
|
||||
* @Param curPage
|
||||
* @Param pageSize
|
||||
* @Param orderBy
|
||||
* @Param platform:平台编码
|
||||
* @Param receiver:接受者id
|
||||
* @return: Page<SysNotification>
|
||||
* @Author: wanjia
|
||||
* @Date: 2021/9/8
|
||||
*/
|
||||
@Override
|
||||
public Page<SysNotification> getAllSysNotificationsPageList(int curPage, int pageSize, String orderBy, String platform, Integer receiver) {
|
||||
public Page<SysNotification> getNotification(int curPage, int pageSize, String orderBy, String platform, Integer receiver) {
|
||||
Page page = new Page<SysNotification>(curPage, pageSize);
|
||||
List<SysNotification> sysNotificationList = baseMapper.getSysNotificationPageList(
|
||||
page, orderBy, platform, receiver
|
||||
|
|
|
|||
|
|
@ -28,26 +28,26 @@ public class ServiceTests {
|
|||
Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
@Test
|
||||
public void testSysNotificationService(){
|
||||
int i = sysNotificationService.getAllNewSysNotificationNumber("gitlink", 234);
|
||||
List<SysNotification> sysNotificationList = sysNotificationService.getUnreadSysNotificationsList("gitlink", 100, 20);
|
||||
Page<SysNotification> sysNotificationPage = sysNotificationService.getAllSysNotificationsPageList(1,10,"","gitlink", 100);
|
||||
public void testSysNotificationService() {
|
||||
int i = sysNotificationService.getUnreadNotificationCount("gitlink", 234);
|
||||
List<SysNotification> sysNotificationList = sysNotificationService.getUnreadNotificationByType("gitlink", 100, 20);
|
||||
Page<SysNotification> sysNotificationPage = sysNotificationService.getNotification(1, 10, "", "gitlink", 100);
|
||||
NewSysNotificationVo newSysNotificationVo = new NewSysNotificationVo();
|
||||
newSysNotificationVo.setSender((long) -1);
|
||||
newSysNotificationVo.setReceivers("7,8");
|
||||
newSysNotificationVo.setContent("baladiwei 在 gitlink-notification-system 修改ReadMe 文件的标题");
|
||||
newSysNotificationVo.setNotification_url("www.baidu.com");
|
||||
newSysNotificationVo.setPlatform("gitlink");
|
||||
boolean j = sysNotificationService.addSysNotificationForUsers(newSysNotificationVo);
|
||||
boolean j = sysNotificationService.sendNotification(newSysNotificationVo);
|
||||
logger.info("insertResult:" + j);
|
||||
int k = sysNotificationService.changeStatusByNotificationIds("gitlink", "2,3", 2);
|
||||
int k = sysNotificationService.markNotificationAs("gitlink", "2,3", 2);
|
||||
logger.info("updateStatus:" + k);
|
||||
int l = sysNotificationService.getSysNotificationNumberByType("gitlink", 100, 1);
|
||||
int l = sysNotificationService.getUnreadNotificationByType(1,"gitlink",1);
|
||||
logger.info("SysNotificationNumber:" + l);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test2(){
|
||||
public void test2() {
|
||||
operateTableService.createTableByPlatform("trustie");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -46,13 +46,13 @@ public class NotificationController {
|
|||
//验证 {platform} 参数合法性,以判断请求来源
|
||||
if (!platform.trim().toLowerCase().equals(PLATFORM_CODE_GITLINK)) {
|
||||
logger.debug("------>输入参数 {platform} 的值 {" + platform + "} 无效");
|
||||
DataPacketUtil.jsonFailResult("参数 {platform} 非法");
|
||||
return DataPacketUtil.jsonFailResult("参数 {platform} 非法");
|
||||
}
|
||||
|
||||
//验证 {receiver} 参数合法性
|
||||
if (receiver <= 0 || receiver >= Integer.MAX_VALUE) {
|
||||
logger.debug("------>输入参数 {receiver} 的值 {" + receiver + "} 超出约定范围");
|
||||
DataPacketUtil.jsonFailResult("参数 {receiver} 非法");
|
||||
return DataPacketUtil.jsonFailResult("参数 {receiver} 非法");
|
||||
}
|
||||
|
||||
//判断 {type} 参数合法性,正确的值只能是 list、count
|
||||
|
|
@ -63,7 +63,7 @@ public class NotificationController {
|
|||
//TODO: 获取约定的必要参数
|
||||
|
||||
//调用业务逻辑获取数据结果
|
||||
List<SysNotification> foundList = notificationService.getUnreadSysNotificationsList(platform, receiver, pageSize);
|
||||
List<SysNotification> foundList = notificationService.getUnreadNotificationByType(platform, receiver, pageSize);
|
||||
|
||||
//拼装约定的 json 格式并返回
|
||||
return DataPacketUtil.jsonSuccessResult(foundList);
|
||||
|
|
@ -74,7 +74,7 @@ public class NotificationController {
|
|||
//TODO: 获取必要的参数
|
||||
|
||||
//调用业务逻辑获取数据结果
|
||||
Integer foundCount = notificationService.getSysNotificationNumberByType(platform, receiver, 1);
|
||||
Integer foundCount = notificationService.getUnreadNotificationCount(platform,receiver);
|
||||
|
||||
//拼装约定的 json 格式并返回
|
||||
return DataPacketUtil.jsonSuccessResult(foundCount);
|
||||
|
|
|
|||
Loading…
Reference in New Issue