|
|
|
@ -2,6 +2,8 @@ package com.zh.project0512.controller.wxApp;
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
|
|
import com.zh.project0512.annotation.TokenValid;
|
|
|
|
|
import com.zh.project0512.model.AppMessage;
|
|
|
|
|
import com.zh.project0512.model.User;
|
|
|
|
|
import com.zh.project0512.service.IAppMessageService;
|
|
|
|
@ -9,15 +11,23 @@ import com.zh.project0512.service.IUserService;
|
|
|
|
|
import com.zh.project0512.utils.JwtUtil;
|
|
|
|
|
import com.zh.project0512.utils.MybatisPlusUtil;
|
|
|
|
|
import com.zh.project0512.utils.result.Result;
|
|
|
|
|
import io.jsonwebtoken.Claims;
|
|
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
|
|
import io.swagger.v3.oas.annotations.Parameter;
|
|
|
|
|
import io.swagger.v3.oas.annotations.media.Schema;
|
|
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
|
|
import lombok.Data;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
import javax.validation.constraints.Max;
|
|
|
|
|
import javax.validation.constraints.Min;
|
|
|
|
|
import javax.validation.constraints.NotNull;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <p>
|
|
|
|
|
* app消息
|
|
|
|
|
* app消息
|
|
|
|
|
* </p>
|
|
|
|
|
*
|
|
|
|
|
* @author zh
|
|
|
|
@ -29,16 +39,44 @@ import org.springframework.web.bind.annotation.*;
|
|
|
|
|
public class AppMessageController {
|
|
|
|
|
@Autowired
|
|
|
|
|
private IAppMessageService appMessageService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private IUserService userService;
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "消息列表")
|
|
|
|
|
@PostMapping("/list")
|
|
|
|
|
public Result list( @RequestBody JSONObject obj, @RequestHeader(value = "token") @Parameter(name = "登录token") String token){
|
|
|
|
|
@TokenValid
|
|
|
|
|
public Result list(@RequestBody JSONObject obj, @RequestHeader(value = "token") @Parameter(name = "登录token") String token) {
|
|
|
|
|
String openid = new JwtUtil().parseOpenid(token);
|
|
|
|
|
User user = userService.selByOpenid(openid);
|
|
|
|
|
QueryWrapper<AppMessage> queryWrapper = new QueryWrapper<>();
|
|
|
|
|
queryWrapper.eq("receiverId",user.getId());
|
|
|
|
|
queryWrapper.orderByDesc("createDate");
|
|
|
|
|
return Result.success( appMessageService.page(MybatisPlusUtil.SetPage(obj),queryWrapper),"请求成功");
|
|
|
|
|
queryWrapper.eq("receiverId", user.getId());
|
|
|
|
|
queryWrapper.orderByDesc("settled","createDate");
|
|
|
|
|
return Result.success(appMessageService.page(MybatisPlusUtil.SetPage(obj), queryWrapper), "请求成功");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private IUserService userService;
|
|
|
|
|
|
|
|
|
|
@Data
|
|
|
|
|
static class AMParam {
|
|
|
|
|
@NotNull(message = "消息id不能为空")
|
|
|
|
|
private Integer id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "标记已读")
|
|
|
|
|
@PostMapping("/read")
|
|
|
|
|
@TokenValid
|
|
|
|
|
public Result read(@RequestBody AMParam param, @RequestHeader(value = "token") @Parameter(name = "登录token") String token) {
|
|
|
|
|
UpdateWrapper<AppMessage> updateWrapper = new UpdateWrapper<>();
|
|
|
|
|
updateWrapper.eq("id", param.getId()).set("settled", 1);
|
|
|
|
|
return MybatisPlusUtil.sqlResult(appMessageService.update(updateWrapper), "标记");
|
|
|
|
|
}
|
|
|
|
|
@Operation(summary = "全部已读")
|
|
|
|
|
@PostMapping("/readAll")
|
|
|
|
|
@TokenValid
|
|
|
|
|
public Result readAll(@RequestHeader(value = "token") @Parameter(name = "登录token") String token) {
|
|
|
|
|
Claims claims = new JwtUtil().parseJWT(token);
|
|
|
|
|
Integer useId = userService.selByOpenid(claims.getId()).getId();
|
|
|
|
|
UpdateWrapper<AppMessage> updateWrapper = new UpdateWrapper<>();
|
|
|
|
|
updateWrapper.eq("receiverId", useId).eq("settled",0).set("settled", 1);
|
|
|
|
|
return MybatisPlusUtil.sqlResult(appMessageService.update(updateWrapper), "标记");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|