Commit cffcb177 by Ren Ping

feat:消息模块开发

1 parent b86cbc10
...@@ -81,9 +81,9 @@ public class MsgController { ...@@ -81,9 +81,9 @@ public class MsgController {
* @date 2023/10/24 * @date 2023/10/24
*/ */
@PostMapping("/msg/read") @PostMapping("/msg/read")
public Result<Boolean> read(@RequestHeader(name = "userId", required = true) String userId, @RequestBody @Valid MsgDTO.DeleteDto dto) { public Result<Boolean> read(@RequestHeader(name = "userId", required = true) String userId, @RequestBody @Valid MsgDTO.ReadDto dto) {
AssertUtil.isNotEmpty(userId, "用户ID不能为空"); AssertUtil.isNotEmpty(userId, "用户ID不能为空");
msgService.readMsg(dto.getId(), userId); msgService.readMsg(dto.getIds(), userId);
return Result.success(true); return Result.success(true);
} }
......
...@@ -2,6 +2,14 @@ package com.dituhui.pea.order.dao; ...@@ -2,6 +2,14 @@ package com.dituhui.pea.order.dao;
import com.dituhui.pea.order.entity.MsgReceiverEntity; import com.dituhui.pea.order.entity.MsgReceiverEntity;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import java.util.List;
public interface MsgReceiverDao extends JpaRepository<MsgReceiverEntity, Integer> { public interface MsgReceiverDao extends JpaRepository<MsgReceiverEntity, Integer> {
@Modifying
@Query(value = "update zzz_msg_receiver set is_read=1 where msg_id in (:msgIds) and user_id=:userId", nativeQuery = true)
void read(@Param("msgIds") List<Integer> msgIds, @Param("userId") String userId);
} }
...@@ -5,10 +5,12 @@ import org.springframework.format.annotation.DateTimeFormat; ...@@ -5,10 +5,12 @@ import org.springframework.format.annotation.DateTimeFormat;
import javax.validation.constraints.Max; import javax.validation.constraints.Max;
import javax.validation.constraints.Min; import javax.validation.constraints.Min;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.Date; import java.util.Date;
import java.util.List;
import static com.dituhui.pea.order.config.OrderConfig.DEFAULT_PAGE_SIZE; import static com.dituhui.pea.order.config.OrderConfig.DEFAULT_PAGE_SIZE;
...@@ -67,6 +69,16 @@ public class MsgDTO { ...@@ -67,6 +69,16 @@ public class MsgDTO {
private Integer id; private Integer id;
} }
@lombok.Data
public static class ReadDto {
/**
* 消息Id集合
*/
@NotEmpty(message = "消息Id集合不能为空")
private List<Integer> ids;
}
@lombok.Data @lombok.Data
public static class addDto { public static class addDto {
......
...@@ -5,6 +5,8 @@ import com.dituhui.pea.order.dto.MsgDTO; ...@@ -5,6 +5,8 @@ import com.dituhui.pea.order.dto.MsgDTO;
import com.dituhui.pea.order.dto.MsgGroupResp; import com.dituhui.pea.order.dto.MsgGroupResp;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.List;
public interface MsgService { public interface MsgService {
/** /**
...@@ -30,13 +32,13 @@ public interface MsgService { ...@@ -30,13 +32,13 @@ public interface MsgService {
/** /**
* 设置消息已读 * 设置消息已读
* *
* @param msgId 味精标识 * @param msgIds 消息标识
* @param userId 用户标识 * @param userId 用户标识
* @author RenPing * @author RenPing
* @date 2023/10/25 * @date 2023/10/25
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
void readMsg(Integer msgId, String userId); void readMsg(List<Integer> msgIds, String userId);
/** /**
* 新增消息 * 新增消息
......
...@@ -94,12 +94,8 @@ public class MsgServiceImpl implements MsgService { ...@@ -94,12 +94,8 @@ public class MsgServiceImpl implements MsgService {
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void readMsg(Integer msgId, String userId) { public void readMsg(List<Integer> msgIds, String userId) {
List<MsgReceiverEntity> list = msgReceiverDao.findAll(Example.of(new MsgReceiverEntity().setMsgId(msgId).setUserId(userId))); msgReceiverDao.read(msgIds, userId);
list.forEach(msgReceiverEntity -> {
msgReceiverEntity.setIsRead(1).setUpdateTime(new Date());
msgReceiverDao.save(msgReceiverEntity);
});
} }
@Override @Override
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!