feature-zrx #32
|
@ -16,7 +16,7 @@ import org.springframework.validation.annotation.Validated;
|
|||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
@ -65,10 +65,18 @@ public class ProjectDailyController {
|
|||
@GetMapping("/daily/search")
|
||||
public BaseResponse searchMyDaily(@RequestParam Integer page,
|
||||
@RequestParam Integer pageSize,
|
||||
Date beginTime,
|
||||
Date endTime,
|
||||
Integer projectId,
|
||||
String beginTime,
|
||||
String endTime,
|
||||
HttpServletRequest request) {
|
||||
return projectDailyService.searchMyDaily(page, pageSize, beginTime, endTime, request);
|
||||
|
||||
|
||||
return projectDailyService.searchMyDaily(projectId,
|
||||
page,
|
||||
pageSize,
|
||||
Processing.convertStringToDate(beginTime),
|
||||
Processing.convertStringToDate(endTime),
|
||||
request);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -12,6 +12,8 @@ import lombok.extern.slf4j.Slf4j;
|
|||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
@ -58,6 +60,42 @@ public class ProjectDailyDAO {
|
|||
List<ProjectDailyDO> myProjectDaily = projectDailyMapper.getProjectDailyByUser(userId);
|
||||
projectDailyDOList.addAll(myProjectDaily);
|
||||
|
||||
// 排序并去重
|
||||
projectDailyDOList = sortaAndNotRepeatDailyDO(projectDailyDOList);
|
||||
|
||||
return projectDailyDOList;
|
||||
}
|
||||
|
||||
|
||||
public List<ProjectDailyDO> getMyProjectDailyByTime(Long userId, Date beginTime, Date endTime) {
|
||||
|
||||
// 日报数据数组
|
||||
List<ProjectDailyDO> projectDailyDOList = new ArrayList<>();
|
||||
|
||||
// 先获取我负责的项目下的日报数据
|
||||
//获取我负责的项目
|
||||
List<ProjectDO> projectDOS = projectMapper.getAllProjectByUserId(userId);
|
||||
//获取项目下对应日报,并根据时间筛选
|
||||
for (ProjectDO projectDO:projectDOS) {
|
||||
List dailyFromProject = projectDailyMapper.getProjectDailyByProjectAndTime(projectDO.getId(),
|
||||
beginTime, endTime);
|
||||
projectDailyDOList.addAll(dailyFromProject);
|
||||
}
|
||||
|
||||
// 在获取本人的发布日报,并根据时间筛选
|
||||
List<ProjectDailyDO> myProjectDaily = projectDailyMapper.
|
||||
getProjectDailyByUserAndTime(userId, beginTime, endTime);
|
||||
projectDailyDOList.addAll(myProjectDaily);
|
||||
|
||||
// 排序并去重
|
||||
projectDailyDOList = sortaAndNotRepeatDailyDO(projectDailyDOList);
|
||||
|
||||
return projectDailyDOList;
|
||||
}
|
||||
|
||||
|
||||
public List<ProjectDailyDO> sortaAndNotRepeatDailyDO(List<ProjectDailyDO> projectDailyDOList) {
|
||||
|
||||
// 去除重复的日报信息
|
||||
projectDailyDOList = projectDailyDOList.stream()
|
||||
// 根据 id 属性进行去重
|
||||
|
@ -66,12 +104,13 @@ public class ProjectDailyDAO {
|
|||
.values().stream()
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 根据时间进行排序
|
||||
projectDailyDOList = projectDailyDOList.stream()
|
||||
.sorted(Comparator.comparing(ProjectDailyDO::getCreatedAt).reversed())
|
||||
.collect(Collectors.toList());
|
||||
|
||||
return projectDailyDOList;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ package com.jsl.oa.mapper;
|
|||
import com.jsl.oa.model.dodata.ProjectDailyDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
|
@ -23,6 +24,9 @@ public interface ProjectDailyMapper {
|
|||
|
||||
List<ProjectDailyDO> getProjectDailyByProject(Long pid);
|
||||
|
||||
List getProjectDailyByProjectAndTime(Long id, Date beginTime, Date endTime);
|
||||
|
||||
List<ProjectDailyDO> getProjectDailyByUserAndTime(Long userId, Date beginTime, Date endTime);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -22,7 +22,8 @@ public interface ProjectDailyService {
|
|||
|
||||
BaseResponse getMyDaily(Integer page, Integer pageSize, HttpServletRequest request);
|
||||
|
||||
BaseResponse searchMyDaily(Integer page,
|
||||
BaseResponse searchMyDaily(Integer projectId,
|
||||
Integer page,
|
||||
Integer pageSize,
|
||||
Date beginTime,
|
||||
Date endTime,
|
||||
|
|
|
@ -88,19 +88,40 @@ public class ProjectDailyServiceImpl implements ProjectDailyService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public BaseResponse searchMyDaily(Integer page,
|
||||
public BaseResponse searchMyDaily(Integer projectId,
|
||||
Integer page,
|
||||
Integer pageSize,
|
||||
Date beginTime,
|
||||
Date endTime,
|
||||
HttpServletRequest request) {
|
||||
// 获取用户id
|
||||
Long userId = Processing.getAuthHeaderToUserId(request);
|
||||
// 获取 我发布的及自己负责的项目下 的日报
|
||||
List<ProjectDailyDO> projectDailyDOList =
|
||||
|
||||
// 根据时间筛选---获取 我发布的及自己负责的项目下 的日报
|
||||
List<ProjectDailyDO> projectDailyDOList = new ArrayList<>();
|
||||
//如果时间不为空,则先根据时间筛选
|
||||
if (beginTime != null && endTime != null) {
|
||||
projectDailyDOList = projectDailyDAO.
|
||||
getMyProjectDailyByTime(userId, beginTime, endTime);
|
||||
} else {
|
||||
//否则获取全部数据
|
||||
projectDailyDOList =
|
||||
projectDailyDAO.getMyProjectDaily(userId);
|
||||
}
|
||||
|
||||
// 再根据项目id进行筛选
|
||||
if (projectId != null) {
|
||||
projectDailyDOList.removeIf(projectDailyDO -> projectDailyDO.getProjectId() != Long.valueOf(projectId));
|
||||
}
|
||||
|
||||
return null;
|
||||
// 进行分页
|
||||
List<ProjectDailyDO> dailyPage = Processing.getPage(projectDailyDOList, page, pageSize);
|
||||
// 封装结果类
|
||||
List<ProjectDailyVO> projectDailyVOS = encapsulateArrayClass(dailyPage);
|
||||
ProjectDailyDataVO projectDailyDataVO =
|
||||
new ProjectDailyDataVO(projectDailyDOList.size(), page, pageSize, projectDailyVOS);
|
||||
|
||||
return ResultUtil.success(projectDailyDataVO);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -23,10 +23,9 @@ import org.springframework.validation.ObjectError;
|
|||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* <h1>自定义快捷工具类</h1>
|
||||
|
@ -409,4 +408,26 @@ public class Processing {
|
|||
int toIndex = Math.min(fromIndex + pageSize, list.size());
|
||||
return list.subList(fromIndex, toIndex);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @Description: 字符与时间类型转换方法
|
||||
* @Date: 2024/4/19
|
||||
* @Param dateString:
|
||||
**/
|
||||
public static Date convertStringToDate(String dateString) {
|
||||
if (dateString.isEmpty()) {
|
||||
return null; // 如果字符串为空,返回空的Date对象
|
||||
} else {
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
try {
|
||||
return dateFormat.parse(dateString);
|
||||
} catch (ParseException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -37,5 +37,20 @@
|
|||
and is_delete = 0
|
||||
</select>
|
||||
|
||||
<select id="getProjectDailyByProjectAndTime" parameterType="java.util.Map"
|
||||
resultType="com.jsl.oa.model.dodata.ProjectDailyDO">
|
||||
select * from oa_project_daily
|
||||
where project_id = #{id}
|
||||
and created_at between #{beginTime} and #{endTime}
|
||||
and is_delete = 0
|
||||
</select>
|
||||
|
||||
<select id="getProjectDailyByUserAndTime" parameterType="java.util.Map"
|
||||
resultType="com.jsl.oa.model.dodata.ProjectDailyDO">
|
||||
select * from oa_project_daily
|
||||
where user_id = #{userId}
|
||||
and created_at between #{beginTime} and #{endTime}
|
||||
and is_delete = 0
|
||||
</select>
|
||||
|
||||
</mapper>
|
Loading…
Reference in New Issue
Block a user