处理部分冲突

This commit is contained in:
巴拉迪维 2021-09-14 10:46:46 +08:00
commit b5b0eba04e
6 changed files with 64 additions and 39 deletions

View File

@ -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;
}
}

View File

@ -45,4 +45,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);
}

View File

@ -44,5 +44,16 @@ public interface SysNotificationService extends IService<SysNotification> {
* @param status 状态 -1 全部1 未读 2 已读
* @return
*/
Page<SysNotification> getNotification(String platform, Integer receiver, Integer status, Integer type, Integer page, Integer size) throws Exception;
/**
* @Description: 批量删除系统消息
* @Param platform 平台编码
* @Param notificationIds 消息编号列表中英文逗号隔开eg221,2323,4,111,23123
* @return: int
* @Author: wanjia
* @Date: 2021/9/13
*/
int deleteNotifications(String platform, Integer receiver, String notificationIds) throws Exception;
}

View File

@ -84,6 +84,15 @@ 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) {
redisUtil.scanAndDel(cachePrefixForPlatform(platform, receiver) + "*");

View File

@ -162,8 +162,10 @@
</update>
<update id="updateStatusByNotificationId">
update ${platform}_sys_notification set status = #{status} where receiver=#{receiver} and id in
(${notificationIds})
update ${platform}_sys_notification set status = #{status} where receiver=#{receiver}
<if test="notificationIds != '-1'">
and id in (${notificationIds})
</if>
</update>
<select id="getNewSysNotificationNumber" resultType="java.lang.Integer">
select count(`receiver`)
@ -199,4 +201,10 @@
</if>
ORDER BY id DESC
</select>
<update id="deleteNotificationByIds">
update ${platform}_sys_notification set is_delete = 1 where receiver=#{receiver}
<if test="notificationIds != '-1'">
and id in (${notificationIds})
</if>
</update>
</mapper>

View File

@ -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());