com.quhaodian.notice.rest.resource.NotificationResource Maven / Gradle / Ivy
package com.quhaodian.notice.rest.resource;
import com.quhaodian.data.page.Filter;
import com.quhaodian.data.page.Page;
import com.quhaodian.data.page.Pageable;
import com.quhaodian.discover.rest.base.ResponseObject;
import com.quhaodian.notice.data.dao.UserNotificationDao;
import com.quhaodian.notice.data.dao.UserNotificationMemberDao;
import com.quhaodian.notice.data.entity.UserNotificationMember;
import com.quhaodian.notice.data.enums.NotificationState;
import com.quhaodian.notice.rest.api.NotificationApi;
import com.quhaodian.notice.rest.conver.UserNotificationSimpleFromMemberConver;
import com.quhaodian.notice.rest.domain.page.NotificationPage;
import com.quhaodian.notice.rest.domain.request.NotificationPageRequest;
import com.quhaodian.notice.rest.domain.request.NotificationReadRequest;
import com.quhaodian.user.data.dao.UserInfoDao;
import com.quhaodian.user.data.entity.UserInfo;
import com.quhaodian.user.utils.ConverResourceUtils;
import com.quhaodian.user.utils.UserUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
@Transactional
@Component
public class NotificationResource implements NotificationApi {
@Autowired
private UserNotificationDao notificationDao;
@Autowired
private UserInfoDao userDao;
@Autowired
private UserNotificationMemberDao notificationMemberDao;
@Override
public NotificationPage page(NotificationPageRequest request) {
NotificationPage result = new NotificationPage();
Long uid = UserUtils.getApp(request.getUserToken());
UserInfo user = userDao.findById(uid);
if (user == null) {
result.setMsg("该用户不存在!");
result.setCode(-101);
return result;
}
Pageable pageable = new Pageable();
pageable.setPageSize(request.getSize());
pageable.setPageNo(request.getNo());
pageable.getFilters().add(Filter.eq("user.id", uid));
Page page = notificationMemberDao.page(pageable);
ConverResourceUtils.coverPage(result, page, new UserNotificationSimpleFromMemberConver());
return result;
}
@Override
public ResponseObject read(NotificationReadRequest request) {
ResponseObject result = new ResponseObject();
Long uid = UserUtils.getApp(request.getUserToken());
UserInfo user = userDao.findById(uid);
if (user == null) {
result.setMsg("该用户不存在!");
result.setCode(-101);
return result;
}
UserNotificationMember notificationMember = notificationMemberDao.findById(request.getId());
if (notificationMember == null) {
result.setMsg("无效id!");
result.setCode(-102);
return result;
}
if (notificationMember.getUser() == null) {
result.setMsg("数据异常!");
result.setCode(-103);
return result;
}
if (!notificationMember.getUser().getId().equals(uid)) {
result.setMsg("非法操作!");
result.setCode(-104);
return result;
}
notificationMember.setState(NotificationState.read);
return result;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy