Переглянути джерело

用户消息阅读功能

master
zouhantao 2 місяці тому
джерело
коміт
75cebc1ad6

+ 43
- 0
zhywpt-app-userw/src/main/java/cn/com/taiji/userw/api/MessageController.java Переглянути файл

@@ -0,0 +1,43 @@
package cn.com.taiji.userw.api;

import javax.validation.Valid;

import cn.com.taiji.userw.model.message.MessageViewRequest;
import cn.com.taiji.userw.model.message.MessageViewResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.com.taiji.common.manager.ManagerException;
import cn.com.taiji.common.model.dao.Pagination;
import cn.com.taiji.common.web.ApiResponse;
import cn.com.taiji.userw.manager.message.MessageManager;
import cn.com.taiji.userw.model.message.MessagePageRequest;
import cn.com.taiji.userw.model.protocol.dict.DictTypeDeleteRequest;
import cn.com.taiji.userw.model.protocol.dict.DictTypeDeleteResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = {"消息管理"})
@RestController
@RequestMapping("/message")
public class MessageController extends MyValidController {
@Autowired
private MessageManager messageManager;

@ApiOperation(value = "消息分页查询")
@PostMapping(value = "/page")
public ApiResponse<Pagination> page(@RequestBody @Valid MessagePageRequest req) throws ManagerException {
Pagination response = messageManager.page(req);
return ApiResponse.of(response);
}

@ApiOperation(value = "消息详情")
@PostMapping(value = "/view")
public ApiResponse<MessageViewResponse> view(@RequestBody @Valid MessageViewRequest req) throws ManagerException {
MessageViewResponse response = messageManager.view(req);
return ApiResponse.of(response);
}
}

+ 13
- 0
zhywpt-app-userw/src/main/java/cn/com/taiji/userw/manager/message/MessageManager.java Переглянути файл

@@ -0,0 +1,13 @@
package cn.com.taiji.userw.manager.message;

import cn.com.taiji.common.manager.ManagerException;
import cn.com.taiji.common.model.dao.Pagination;
import cn.com.taiji.userw.model.message.MessagePageRequest;
import cn.com.taiji.userw.model.message.MessageViewRequest;
import cn.com.taiji.userw.model.message.MessageViewResponse;
import cn.com.taiji.userw.model.protocol.dict.DictTypeQueryResponse;

public interface MessageManager {
Pagination page(MessagePageRequest req) throws ManagerException;
MessageViewResponse view(MessageViewRequest req) throws ManagerException;
}

+ 43
- 0
zhywpt-app-userw/src/main/java/cn/com/taiji/userw/manager/message/MessageManagerImpl.java Переглянути файл

@@ -0,0 +1,43 @@
package cn.com.taiji.userw.manager.message;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.com.taiji.common.manager.ManagerException;
import cn.com.taiji.common.model.dao.Pagination;
import cn.com.taiji.common.pub.CommonAbstract;
import cn.com.taiji.core.entity.msgw.MsgwUserMessage;
import cn.com.taiji.core.repo.jpa.msgw.MsgwUserMessageRepo;
import cn.com.taiji.core.repo.request.msgw.MsgwUserMessagePageRequest;
import cn.com.taiji.userw.model.message.MessagePageRequest;
import cn.com.taiji.userw.model.message.MessageViewRequest;
import cn.com.taiji.userw.model.message.MessageViewResponse;

@Service
public class MessageManagerImpl extends CommonAbstract implements MessageManager {

@Autowired
private MsgwUserMessageRepo userMessageRepo;
@Override
public Pagination page(MessagePageRequest req) {
MsgwUserMessagePageRequest pageRequest = new MsgwUserMessagePageRequest();
BeanUtils.copyProperties(req, pageRequest);
Pagination page = userMessageRepo.page(pageRequest);
return page;
}

@Override
public MessageViewResponse view(MessageViewRequest req) throws ManagerException {
MsgwUserMessage message = userMessageRepo.findById(req.getId()).orElse(null);
if (message == null){
throw new ManagerException("未找到该条通知!");
}
message.setIsReaded(1);
userMessageRepo.merge(message);
MessageViewResponse res = new MessageViewResponse();
res.setMessage(message);
return res;
}

}

+ 19
- 0
zhywpt-app-userw/src/main/java/cn/com/taiji/userw/model/message/MessagePageRequest.java Переглянути файл

@@ -0,0 +1,19 @@
package cn.com.taiji.userw.model.message;

import javax.validation.constraints.NotBlank;

import cn.com.taiji.core.dto.AbstractStaffBizRequestDTO;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class MessagePageRequest extends AbstractStaffBizRequestDTO {
@ApiModelProperty(value = "用户openId",required = true)
@NotBlank
private String openId;//用户openId
@ApiModelProperty(value = "是否已读",required = true)
@NotBlank
private Integer isReaded;//是否已读
}

+ 16
- 0
zhywpt-app-userw/src/main/java/cn/com/taiji/userw/model/message/MessageViewRequest.java Переглянути файл

@@ -0,0 +1,16 @@
package cn.com.taiji.userw.model.message;

import javax.validation.constraints.NotBlank;

import cn.com.taiji.core.dto.AbstractStaffBizRequestDTO;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class MessageViewRequest extends AbstractStaffBizRequestDTO {
@ApiModelProperty(value = "id",required = true)
@NotBlank
private String id;
}

+ 12
- 0
zhywpt-app-userw/src/main/java/cn/com/taiji/userw/model/message/MessageViewResponse.java Переглянути файл

@@ -0,0 +1,12 @@
package cn.com.taiji.userw.model.message;


import cn.com.taiji.core.entity.msgw.MsgwUserMessage;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class MessageViewResponse {
private MsgwUserMessage message;
}

Завантаження…
Відмінити
Зберегти