删除系统消息
This commit is contained in:
parent
6d4729ed7b
commit
41361fcba9
|
@ -7,40 +7,16 @@ import javax.validation.constraints.NotBlank;
|
|||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Pattern;
|
||||
|
||||
public class UpdateNotificationStatusVo {
|
||||
//平台编码
|
||||
private String platform;
|
||||
|
||||
public class DeleteNotificationsVo {
|
||||
@ApiModelProperty(value = "消息ids", required = true)
|
||||
@NotBlank
|
||||
@Pattern(regexp = "^\\d+(,\\d+)*$", message = "消息id串非法")
|
||||
private String notificationIds;
|
||||
|
||||
@ApiModelProperty(value = "已读状态: 1未读,2已读", required = true)
|
||||
@NotNull
|
||||
@Range(min = 1, max = 2)
|
||||
private Integer status;
|
||||
|
||||
@ApiModelProperty(value = "消息接收者", required = true)
|
||||
@NotNull(message = "消息接收者不能为空")
|
||||
private Integer receiver;
|
||||
|
||||
public Integer getReceiver() {
|
||||
return receiver;
|
||||
}
|
||||
|
||||
public void setReceiver(Integer receiver) {
|
||||
this.receiver = receiver;
|
||||
}
|
||||
|
||||
public String getPlatform() {
|
||||
return platform;
|
||||
}
|
||||
|
||||
public void setPlatform(String platform) {
|
||||
this.platform = platform;
|
||||
}
|
||||
|
||||
public String getNotificationIds() {
|
||||
return notificationIds;
|
||||
}
|
||||
|
@ -49,11 +25,11 @@ public class UpdateNotificationStatusVo {
|
|||
this.notificationIds = notificationIds;
|
||||
}
|
||||
|
||||
public Integer getStatus() {
|
||||
return status;
|
||||
public Integer getReceiver() {
|
||||
return receiver;
|
||||
}
|
||||
|
||||
public void setStatus(Integer status) {
|
||||
this.status = status;
|
||||
public void setReceiver(Integer receiver) {
|
||||
this.receiver = receiver;
|
||||
}
|
||||
}
|
|
@ -42,4 +42,8 @@ public interface SysNotificationMapper extends BaseMapper<SysNotification> {
|
|||
int getSysNotificationNumberByType(@Param("platform") String platform,
|
||||
@Param("receiver") Integer receiver,
|
||||
@Param("type") Integer type);
|
||||
|
||||
int deleteNotificationByIds(@Param("platform") String platform,
|
||||
@Param("receiver") Integer receiver,
|
||||
@Param("notificationIds") String notificationIds);
|
||||
}
|
||||
|
|
|
@ -64,4 +64,15 @@ public interface SysNotificationService extends IService<SysNotification> {
|
|||
* @return
|
||||
*/
|
||||
Page<SysNotification> getNotification(int type, int page, int size, String orderBy, String platform, Integer receiver) throws Exception;
|
||||
|
||||
/**
|
||||
* @Description: 批量删除系统消息
|
||||
*
|
||||
* @Param platform 平台编码
|
||||
* @Param notificationIds 消息编号列表,中英文逗号隔开,eg:221,2323,4,111,23123
|
||||
* @return: int
|
||||
* @Author: wanjia
|
||||
* @Date: 2021/9/13
|
||||
*/
|
||||
int deleteNotifications(String platform, Integer receiver, String notificationIds) throws Exception;
|
||||
}
|
||||
|
|
|
@ -106,6 +106,14 @@ public class SysNotificationServiceImpl extends ServiceImpl<SysNotificationMappe
|
|||
return pageItem;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteNotifications(String platform, Integer receiver, String notificationIds) throws Exception {
|
||||
int count = baseMapper.deleteNotificationByIds(platform, receiver, notificationIds);
|
||||
if (count > 0) {
|
||||
this.delUserCache(platform, receiver);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
//////////////////////////////// 私有方法 ////////////////////////////////
|
||||
private void delUserCache(String platform, Integer receiver) {
|
||||
|
|
|
@ -188,4 +188,7 @@
|
|||
</if>
|
||||
ORDER BY id DESC
|
||||
</select>
|
||||
<update id="deleteNotificationByIds">
|
||||
update ${platform}_sys_notification set is_delete = 1 where receiver=#{receiver} and id in (${notificationIds})
|
||||
</update>
|
||||
</mapper>
|
|
@ -5,11 +5,11 @@ import cn.org.gitlink.notification.common.response.DataPacketUtil;
|
|||
import cn.org.gitlink.notification.common.response.ResponseData;
|
||||
import cn.org.gitlink.notification.common.utils.KafkaUtil;
|
||||
import cn.org.gitlink.notification.common.utils.ValidatorUtils;
|
||||
import cn.org.gitlink.notification.model.dao.entity.vo.DeleteNotificationsVo;
|
||||
import cn.org.gitlink.notification.model.dao.entity.vo.NewSysNotificationParamsVo;
|
||||
import cn.org.gitlink.notification.model.dao.entity.vo.NewSysNotificationVo;
|
||||
import cn.org.gitlink.notification.model.dao.entity.vo.UpdateNotificationStatusParamsVo;
|
||||
import cn.org.gitlink.notification.model.service.notification.SysNotificationService;
|
||||
import cn.org.gitlink.notification.model.dao.entity.vo.UpdateNotificationStatusVo;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
|
@ -107,19 +107,36 @@ public class NotificationController {
|
|||
ResponseData jsonFailResult = validatePlatformCode(platform);
|
||||
if (jsonFailResult != null) return jsonFailResult;
|
||||
|
||||
//platform和UpdateNotificationStatusParamsVo拼装
|
||||
UpdateNotificationStatusVo updateNotificationStatusVo = new UpdateNotificationStatusVo();
|
||||
try {
|
||||
BeanUtils.copyProperties(updateNotificationStatusParamsVo, updateNotificationStatusVo);
|
||||
} catch (BeansException e) {
|
||||
int count = sysNotificationService.markNotificationAs(platform, updateNotificationStatusParamsVo.getReceiver(), updateNotificationStatusParamsVo.getNotificationIds(), updateNotificationStatusParamsVo.getStatus());
|
||||
return count > 0 ? DataPacketUtil.jsonSuccessResult() : DataPacketUtil.jsonFailResult();
|
||||
} catch (Exception e) {
|
||||
logger.error(e);
|
||||
return DataPacketUtil.jsonFailResult(e.getMessage());
|
||||
}
|
||||
updateNotificationStatusVo.setPlatform(platform);
|
||||
}
|
||||
|
||||
@ApiOperation("删除系统消息状态")
|
||||
@RequestMapping(path = "/{platform}", method = RequestMethod.DELETE)
|
||||
@ResponseBody
|
||||
public ResponseData changeNotificationStatus(@ApiParam(value = "平台编码", required = true)
|
||||
@PathVariable(name = "platform") String platform,
|
||||
|
||||
@Validated @RequestBody DeleteNotificationsVo deleteNotificationsVo,
|
||||
|
||||
BindingResult bindingResult) {
|
||||
|
||||
//参数合法性验证
|
||||
Map<String, String> errors = ValidatorUtils.buildValidationErrorMessageMap(bindingResult);
|
||||
if (!errors.isEmpty()) {
|
||||
return DataPacketUtil.jsonFailResult(errors);
|
||||
}
|
||||
ResponseData jsonFailResult = validatePlatformCode(platform);
|
||||
if (jsonFailResult != null) return jsonFailResult;
|
||||
|
||||
try {
|
||||
sysNotificationService.markNotificationAs(platform, updateNotificationStatusVo.getReceiver(), updateNotificationStatusVo.getNotificationIds(), updateNotificationStatusVo.getStatus());
|
||||
return DataPacketUtil.jsonSuccessResult();
|
||||
int count = sysNotificationService.deleteNotifications(platform, deleteNotificationsVo.getReceiver(), deleteNotificationsVo.getNotificationIds());
|
||||
return count > 0 ? DataPacketUtil.jsonSuccessResult() : DataPacketUtil.jsonFailResult();
|
||||
} catch (Exception e) {
|
||||
logger.error(e);
|
||||
return DataPacketUtil.jsonFailResult(e.getMessage());
|
||||
|
|
Loading…
Reference in New Issue