/**
* 统计查询 --人员查询列表
* @param page
* @param work
* @return
*/
@Override
public IPage<Map<String,Object>> queryUserWorkPage(Page page, Work work) {
// 返回数据
IPage<Map<String,Object>> workVoIPageList = new Page<>();
// 获取当前登录人
LoginUser currentUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
String userName = "";
// 人员查询条件
if(null != work.getUserName() && !"".equals(work.getUserName())){
userName = work.getUserName();
}else{
userName = currentUser.getUsername();
}
// 开始范围时间
Date startTime = null;
// 结束范围时间
Date endTime = null;
//获得时间范围
List<WorkVo> workDateList = workMapper.getWorkDatePage(work,userName);
if(null!= workDateList || workDateList.size() > 0){
if(workDateList.size()>1){// 开始 结束都有 //倒序排列大的时间在上面
startTime = workDateList.get(0).getWorkImplementDate();
endTime = workDateList.get(workDateList.size()-1).getWorkImplementDate();
}else{
startTime = workDateList.get(0).getWorkImplementDate();
endTime = workDateList.get(0).getWorkImplementDate();
}
}
// 计算两个日期相差多少天
long nd = 1000 * 24 * 60 * 60;
long diff = startTime.getTime() - endTime.getTime();
int day = (int) (diff / nd);
//获得total
workVoIPageList.setTotal(day+1);
// 计算开始时间结束时间
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
long l = (page.getCurrent() - 1) * 10 * 1000 * 24 * 60 * 60;
long startTimes = startTime.getTime();
long staartStamp = startTimes - l;
// 计算出页面开始时间
Date startDate = new Date(staartStamp);
long sizeDay = 9 * 1000 * 24 * 60 * 60;
// 页面结束时间范围
Long endStamp = startDate.getTime() - sizeDay;
Date endDate = new Date(endStamp);
String startStr = simpleDateFormat.format(startDate);
String endStr = simpleDateFormat.format(endDate);
// 如果最后一页时间小于时间范围的结束时间 那么最后一页时间等于世界范围结束时间
if(endDate.getTime()<endTime.getTime()){
endDate = endTime;
}
// 最后一页时间 与时间范围结束时间相差几天
long differDayL = staartStamp - endDate.getTime();
int differDay= (int) (differDayL / nd);
// 获取当前登录人相关工作
List<Work> worklist = workMapper.selectWorkList(endStr,startStr,userName);
Map<String,Map> map = new TreeMap<>();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
// 循环分类放入list
worklist.forEach(w->{
String key = sdf.format(w.getWorkImplementDate());
if(map.containsKey(key)){
Map<String,List> mapItem = map.get(key);
// 个人创建
if(w.getSponsor().equals(currentUser.getUsername()) && w.getPerson().equals(currentUser.getUsername())){
mapItem.get("personalWorkList").add(w);
}
// 领导指派
if(w.getSponsor().equals(currentUser.getUsername()) && !w.getPerson().equals(currentUser.getUsername())){
mapItem.get("leaderWorkList").add(w);
}
// 我创建的
if(!w.getSponsor().equals(currentUser.getUsername()) && w.getPerson().equals(currentUser.getUsername())){
mapItem.get("assignWorkList").add(w);
}
}else{
Map<String,List> mapItem = new TreeMap<>();
List listItem1 = new ArrayList();
List listItem2 = new ArrayList();
List listItem3 = new ArrayList();
// 个人创建
if(w.getSponsor().equals(currentUser.getUsername()) && w.getPerson().equals(currentUser.getUsername())){
listItem1.add(w);
}
// 领导指派
if(w.getSponsor().equals(currentUser.getUsername()) && !w.getPerson().equals(currentUser.getUsername())){
listItem2.add(w);
}
// 我创建的
if(!w.getSponsor().equals(currentUser.getUsername()) && w.getPerson().equals(currentUser.getUsername())){
listItem3.add(w);
}
mapItem.put("personalWorkList",listItem1);
mapItem.put("leaderWorkList",listItem2);
mapItem.put("assignWorkList",listItem3);
map.put(key,mapItem);
}
});
// 当前页时间
List<String> dateList = new ArrayList<>();
for (int i = 0; i < differDay; i++) {
Long time = staartStamp - (i * 1000 * 24 * 60 * 60L);
Date date = new Date(time);
String timestr = sdf.format(date);
dateList.add(timestr);
}
// mapkey
List<String> kyList = map.keySet().stream().collect(Collectors.toList());
// 加入占位数据
for (int i = 0; i < dateList.size(); i++) {
if(!kyList.contains(dateList.get(i))){
Map<String,Object> dateMap = new HashMap<>();
map.put(dateList.get(i),dateMap);
}
}
// treemap 倒序
Map<String,List> dataMap = new TreeMap<String,List>();
dataMap = ((TreeMap) map).descendingMap();
//迭代循环将map转为List<Map<String,Object>>
List<Map<String,Object>> workList=new ArrayList();
Iterator it=dataMap.keySet().iterator();
while(it.hasNext()){
Map map1 =new HashMap();
String key=it.next().toString();
map1.put("date",key);
map1.put("list",map.get(key));
workList.add(map1);
}
workVoIPageList.setRecords(workList);
String finalUserName = userName;
// 循环放入回显数据
workVoIPageList.getRecords().forEach(w->{
// 获取当天统计数量
Map<String, Object> workCount = workMapper.getworkCount(w.get("date").toString(), finalUserName);
w.put("workCount",workCount);
// TODO 获取相关附件
});
return workVoIPageList;
}
09-01
826
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
04-25
1943
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
07-22
1万+
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)