消息处理增加一键清空,一键已读的接口

This commit is contained in:
daihh
2022-11-10 15:25:02 +08:00
parent 62851a321e
commit 0fec92bfb1
4 changed files with 72 additions and 0 deletions

View File

@@ -6,6 +6,7 @@ import java.util.Map;
import javax.annotation.Resource;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
@@ -123,6 +124,46 @@ public class MessageApi extends ApiBaseController {
return error("设置已读失败",e.getMessage());
}
}
/**
* 设置已读
* */
//@AutoLog(module = "消息",action = "未的全部设置为已读")
@GetMapping("/readall")
public JsonResponse<Boolean> readAll(){
String aid=getCurrent().getAccountId();
if(StringUtils.isBlank(aid)) {
return badRequest("获取用户信息异常");
}
try {
service.cleanByAcceptId(aid);
return success(true);
} catch (Exception e) {
log.error("设置已读失败",e);
return error("设置已读失败",e.getMessage());
}
}
@GetMapping("/clearall")
public JsonResponse<Boolean> clearAll(){
String aid=getCurrent().getAccountId();
if(StringUtils.isBlank(aid)) {
return badRequest("获取用户信息异常");
}
try {
service.cleanByAcceptId(aid);
return success(true);
} catch (Exception e) {
log.error("清空消息错误",e);
return error("清空消息失败",e.getMessage());
}
}
/**
* 移动端

View File

@@ -46,6 +46,10 @@ public class Message extends IdEntity {
@Column(name = "send_name",nullable = true)
private String sendName;
/**发送人id*/
@Column(name = "send_aid",nullable = true,length=20)
private String sendAid;
/**
* 发送方式,1直接消息邮件短信
* */

View File

@@ -35,6 +35,21 @@ public interface IMessageService {
* 未读消息条数
* */
Integer isRead(String aid);
/**
* 设置全部未读消息为已读
* @param aid
* @return
*/
Integer setReadByAcceptId(String aid);
/**
* 清空所有的消息,按接收人
* @param aid
* @return
*/
void cleanByAcceptId(String aid);
/**
* 批量设置已读
* */

View File

@@ -108,4 +108,16 @@ public class MessageServiceImpl implements IMessageService {
List<Message> list = dao.findList(builder.builder());
return list;
}
@Override
public Integer setReadByAcceptId(String aid) {
int n=dao.deleteByField("acceptId", aid);
return n;
}
@Override
public void cleanByAcceptId(String aid) {
dao.update("Update "+Message.class.getSimpleName()+" set isRead=?1 where acceptId=?2 and isRead=?3", true,aid,false);
}
}