信息获取完善
This commit is contained in:
parent
b37fbdf4ff
commit
95d7781abb
|
@ -1,17 +1,23 @@
|
|||
package com.jsl.oa.controllers;
|
||||
|
||||
import com.jsl.oa.common.constant.BusinessConstants;
|
||||
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.JwtUtil;
|
||||
import com.jsl.oa.utils.ResultUtil;
|
||||
import com.jsl.oa.utils.redis.TokenRedisUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.time.LocalDate;
|
||||
|
||||
/**
|
||||
* <h1>消息控制器</h1>
|
||||
|
@ -35,6 +41,36 @@ public class MessageController {
|
|||
return ResultUtil.error(ErrorCode.PARAMETER_ERROR);
|
||||
} else return messageService.messageDelete(id,request);
|
||||
}
|
||||
|
||||
@GetMapping("/message/get")
|
||||
public BaseResponse messageGet(@RequestParam(defaultValue = "1") Long page,
|
||||
@RequestParam(defaultValue = "10") Long pageSize,
|
||||
HttpServletRequest request,
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
|
||||
@DateTimeFormat (pattern = "yyyy-MM-dd") LocalDate end) {
|
||||
log.info("请求接口[GET]:/message/get");
|
||||
String token = request.getHeader("Authorization").replace("Bearer ", "");
|
||||
Long uid = JwtUtil.getUserId(token);
|
||||
if(uid == null){
|
||||
return ResultUtil.error(ErrorCode.USER_NOT_EXIST);
|
||||
} else return messageService.messageGet(begin,end,page,pageSize,uid);
|
||||
}
|
||||
|
||||
@GetMapping("/message/get/all")
|
||||
public BaseResponse messageGetAll(@RequestParam(defaultValue = "1") Long page,
|
||||
@RequestParam(defaultValue = "10") Long pageSize,
|
||||
HttpServletRequest request,
|
||||
@RequestParam Long uid,
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
|
||||
@DateTimeFormat (pattern = "yyyy-MM-dd") LocalDate end) {
|
||||
log.info("请求接口[GET]:/message/get/all");
|
||||
String token = request.getHeader("Authorization").replace("Bearer ", "");
|
||||
Long LoginId = JwtUtil.getUserId(token);
|
||||
if(LoginId == null){
|
||||
return ResultUtil.error(ErrorCode.USER_NOT_EXIST);
|
||||
} else return messageService.messageGetAll(request,begin,end,page,pageSize,LoginId,uid);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -6,6 +6,9 @@ import org.apache.ibatis.annotations.Mapper;
|
|||
import org.apache.ibatis.annotations.Select;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Mapper
|
||||
public interface MessageMapper {
|
||||
|
@ -17,4 +20,10 @@ public interface MessageMapper {
|
|||
|
||||
@Select("SELECT * FROM organize_oa.oa_message where id = #{mid}")
|
||||
MessageDO getMessageById(Long mid);
|
||||
|
||||
@Select("select count(*) from organize_oa.oa_message where uid = #{uid}")
|
||||
Long count(Long uid);
|
||||
|
||||
@Select("select * from organize_oa.oa_message where uid = #{uid}") //and created_at between #{begin} and #{end} limit #{start},#{pageSize}")
|
||||
List<MessageDO> page(LocalDate begin,LocalDate end,Long uid, Long start, Long pageSize);
|
||||
}
|
||||
|
|
15
src/main/java/com/jsl/oa/model/doData/PageBeanDO.java
Normal file
15
src/main/java/com/jsl/oa/model/doData/PageBeanDO.java
Normal file
|
@ -0,0 +1,15 @@
|
|||
package com.jsl.oa.model.doData;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class PageBeanDO {
|
||||
private Long total;//总记录数
|
||||
private List rows;//数据列表
|
||||
}
|
|
@ -3,6 +3,7 @@ package com.jsl.oa.services;
|
|||
import com.jsl.oa.utils.BaseResponse;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.time.LocalDate;
|
||||
|
||||
/**
|
||||
* <h1>消息服务接口</h1>
|
||||
|
@ -17,4 +18,7 @@ public interface MessageService {
|
|||
|
||||
BaseResponse messageDelete(Long mid,HttpServletRequest request);
|
||||
|
||||
BaseResponse messageGet(LocalDate begin,LocalDate end,Long page,Long pageSize,Long uid);
|
||||
|
||||
BaseResponse messageGetAll(HttpServletRequest request,LocalDate begin, LocalDate end, Long page, Long pageSize, Long loginId, Long uid);
|
||||
}
|
||||
|
|
|
@ -2,13 +2,19 @@ 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.model.doData.PageBeanDO;
|
||||
import com.jsl.oa.services.MessageService;
|
||||
import com.jsl.oa.utils.*;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Slf4j
|
||||
|
@ -17,6 +23,7 @@ import javax.servlet.http.HttpServletRequest;
|
|||
public class MessageServiceImpl implements MessageService {
|
||||
|
||||
private final MessageMapper messageMapper;
|
||||
private final RoleMapper roleMapper;
|
||||
|
||||
@Override
|
||||
public BaseResponse messageDelete(Long mid, HttpServletRequest request) {
|
||||
|
@ -34,6 +41,49 @@ public class MessageServiceImpl implements MessageService {
|
|||
return ResultUtil.success();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseResponse messageGet(LocalDate begin,LocalDate end,Long page,Long pageSize,Long uid) {
|
||||
//1.记录总数据数
|
||||
Long count = messageMapper.count(uid);
|
||||
|
||||
//2.获取分页数据列表
|
||||
//默认获取时间为最近30天
|
||||
if(begin == null){
|
||||
begin = LocalDate.now();
|
||||
end = begin.minus(30, ChronoUnit.DAYS);
|
||||
}
|
||||
Long start = (page-1) * pageSize;
|
||||
List<MessageDO> empList = messageMapper.page(begin,end,uid,start,pageSize);
|
||||
|
||||
//3.封装PageBean对象
|
||||
PageBeanDO pageBean = new PageBeanDO(count,empList);
|
||||
return ResultUtil.success(pageBean);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseResponse messageGetAll(HttpServletRequest request,LocalDate begin, LocalDate end, Long page, Long pageSize, Long loginId, Long uid) {
|
||||
log.info("请求接口服务层");
|
||||
if(!Processing.checkUserIsAdmin(request,roleMapper)){
|
||||
return ResultUtil.error(ErrorCode.NOT_ADMIN);
|
||||
}else {
|
||||
//1.记录总数据数
|
||||
Long count = messageMapper.count(uid);
|
||||
|
||||
//2.获取分页数据列表
|
||||
//默认获取时间为最近30天
|
||||
if(begin == null){
|
||||
begin = LocalDate.now();
|
||||
end = begin.minus(30, ChronoUnit.DAYS);
|
||||
}
|
||||
Long start = (page - 1) * pageSize;
|
||||
List<MessageDO> messageDOList = messageMapper.page(begin,end,uid, start, pageSize);
|
||||
|
||||
//3.封装PageBean对象
|
||||
PageBeanDO pageBean = new PageBeanDO(count, messageDOList);
|
||||
return ResultUtil.success(pageBean);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -3,14 +3,14 @@ server:
|
|||
spring:
|
||||
datasource:
|
||||
url: jdbc:mysql://localhost:3306
|
||||
username: root
|
||||
username: organize_oa
|
||||
password: 123456
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
redis:
|
||||
database: 0
|
||||
host: 192.168.80.129
|
||||
host: local
|
||||
port: 6379
|
||||
password: 123456
|
||||
password:
|
||||
profiles:
|
||||
active: dev
|
||||
mybatis:
|
||||
|
|
Loading…
Reference in New Issue
Block a user