消息删除接口补丁
This commit is contained in:
parent
eb2caee36a
commit
5a70c6cedc
40
src/main/java/com/jsl/oa/controllers/MessageController.java
Normal file
40
src/main/java/com/jsl/oa/controllers/MessageController.java
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
package com.jsl.oa.controllers;
|
||||||
|
|
||||||
|
import com.jsl.oa.services.MessageService;
|
||||||
|
import com.jsl.oa.services.impl.MessageServiceImpl;
|
||||||
|
import com.jsl.oa.utils.BaseResponse;
|
||||||
|
import com.jsl.oa.utils.ErrorCode;
|
||||||
|
import com.jsl.oa.utils.ResultUtil;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>消息控制器</h1>
|
||||||
|
* <hr/>
|
||||||
|
* 消息控制器,包含信息获取接口
|
||||||
|
*
|
||||||
|
* @author 张睿相
|
||||||
|
* @version v1.1.0
|
||||||
|
* @since v1.1.0
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class MessageController {
|
||||||
|
|
||||||
|
private final MessageService messageService;
|
||||||
|
|
||||||
|
@DeleteMapping("/message/delete")
|
||||||
|
public BaseResponse messageDelete(@RequestParam Long id, HttpServletRequest request){
|
||||||
|
if(id == null){
|
||||||
|
return ResultUtil.error(ErrorCode.PARAMETER_ERROR);
|
||||||
|
} else return messageService.messageDelete(id,request);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
20
src/main/java/com/jsl/oa/mapper/MessageMapper.java
Normal file
20
src/main/java/com/jsl/oa/mapper/MessageMapper.java
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
package com.jsl.oa.mapper;
|
||||||
|
|
||||||
|
import com.jsl.oa.model.doData.MessageDO;
|
||||||
|
import org.apache.ibatis.annotations.Delete;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
import org.apache.ibatis.annotations.Update;
|
||||||
|
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface MessageMapper {
|
||||||
|
|
||||||
|
@Update("UPDATE organize_oa.oa_message " +
|
||||||
|
"SET `read` = 1, deleted_at = CURRENT_TIMESTAMP " +
|
||||||
|
"WHERE id = #{mid}")
|
||||||
|
boolean deleteMessage(Long mid);
|
||||||
|
|
||||||
|
@Select("SELECT * FROM organize_oa.oa_message where id = #{mid}")
|
||||||
|
MessageDO getMessageById(Long mid);
|
||||||
|
}
|
33
src/main/java/com/jsl/oa/model/doData/MessageDO.java
Normal file
33
src/main/java/com/jsl/oa/model/doData/MessageDO.java
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
package com.jsl.oa.model.doData;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>meesage 数据表</h1>
|
||||||
|
* <hr/>
|
||||||
|
* 映射 oa_message 数据表内容进入自定义实体类
|
||||||
|
*
|
||||||
|
* @author 张睿相
|
||||||
|
* @since v1.1.0
|
||||||
|
* @version v1.1.0
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Accessors(chain = true)
|
||||||
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
|
public class MessageDO {
|
||||||
|
|
||||||
|
private Long id;
|
||||||
|
private Long uid;
|
||||||
|
private String title;
|
||||||
|
private String text;
|
||||||
|
private Short read;
|
||||||
|
private Timestamp createdAt;
|
||||||
|
private Timestamp deletedAt;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
49
src/main/java/com/jsl/oa/model/voData/UserEditVO.java
Normal file
49
src/main/java/com/jsl/oa/model/voData/UserEditVO.java
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
package com.jsl.oa.model.voData;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.validation.constraints.Max;
|
||||||
|
import javax.validation.constraints.Min;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import javax.validation.constraints.Pattern;
|
||||||
|
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class UserEditVO {
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private String username;
|
||||||
|
|
||||||
|
private String address;
|
||||||
|
|
||||||
|
@Pattern(regexp = "^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\\d{8}$", message = "电话格式错误")
|
||||||
|
private String phone;
|
||||||
|
|
||||||
|
@Pattern(regexp = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$", message = "邮箱格式错误")
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
@Min(value = 0, message = "保密:0,男:1,女:2")
|
||||||
|
@Max(value = 2, message = "保密:0,男:1,女:2")
|
||||||
|
private Short sex;
|
||||||
|
|
||||||
|
private Short age;
|
||||||
|
private String signature;
|
||||||
|
private String avatar;
|
||||||
|
private String nickname;
|
||||||
|
private String description;
|
||||||
|
@NotNull
|
||||||
|
private Boolean enabled;
|
||||||
|
@NotNull
|
||||||
|
private Boolean isExpired;
|
||||||
|
@NotNull
|
||||||
|
private Boolean passwordExpired;
|
||||||
|
@NotNull
|
||||||
|
private Boolean recommend;
|
||||||
|
@NotNull
|
||||||
|
private Boolean isLocked;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
20
src/main/java/com/jsl/oa/services/MessageService.java
Normal file
20
src/main/java/com/jsl/oa/services/MessageService.java
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
package com.jsl.oa.services;
|
||||||
|
|
||||||
|
import com.jsl.oa.utils.BaseResponse;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>消息服务接口</h1>
|
||||||
|
* <hr/>
|
||||||
|
* 用于消息控制
|
||||||
|
*
|
||||||
|
* @author 张睿相
|
||||||
|
* @version v1.1.0
|
||||||
|
* @since v1.1.0
|
||||||
|
*/
|
||||||
|
public interface MessageService {
|
||||||
|
|
||||||
|
BaseResponse messageDelete(Long mid,HttpServletRequest request);
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
package com.jsl.oa.services.impl;
|
||||||
|
|
||||||
|
|
||||||
|
import com.jsl.oa.mapper.MessageMapper;
|
||||||
|
import com.jsl.oa.mapper.RoleMapper;
|
||||||
|
import com.jsl.oa.model.doData.MessageDO;
|
||||||
|
import com.jsl.oa.services.MessageService;
|
||||||
|
import com.jsl.oa.utils.*;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.swing.*;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class MessageServiceImpl implements MessageService {
|
||||||
|
|
||||||
|
private final MessageMapper messageMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BaseResponse messageDelete(Long mid, HttpServletRequest request) {
|
||||||
|
//获取消息数据
|
||||||
|
MessageDO messageDO = messageMapper.getMessageById(mid);
|
||||||
|
//检测用户id与消息的uid是否相同
|
||||||
|
String token = request.getHeader("Authorization").replace("Bearer ", "");
|
||||||
|
if (!(messageDO.getUid() == JwtUtil.getUserId(token))) {
|
||||||
|
return ResultUtil.error(ErrorCode.MESSAGE_ONLY_DELETE_BY_THEMSELVES);
|
||||||
|
}
|
||||||
|
//执行删除
|
||||||
|
if(!messageMapper.deleteMessage(mid)){
|
||||||
|
return ResultUtil.error(ErrorCode.DATABASE_UPDATE_ERROR);
|
||||||
|
}
|
||||||
|
return ResultUtil.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user