package com.ruoyi.report.service.impl;
|
|
import cn.hutool.core.date.DateUtil;
|
import com.ruoyi.report.dto.WorkStatisticsDto;
|
import com.ruoyi.report.mapper.WorkStatisticsMapper;
|
import com.ruoyi.report.service.WorkStatisticsService;
|
import com.ruoyi.report.vo.WorkStatisticsVo;
|
import lombok.AllArgsConstructor;
|
import org.springframework.stereotype.Service;
|
|
import java.util.*;
|
|
/**
|
* 工作统计服务实现
|
*/
|
@Service
|
@AllArgsConstructor
|
public class WorkStatisticsServiceImpl implements WorkStatisticsService {
|
|
private WorkStatisticsMapper workStatisticsMapper;
|
|
@Override
|
public List<WorkStatisticsVo> getByUser(WorkStatisticsDto dto) {
|
// 处理时间类型
|
processDateType(dto);
|
|
List<WorkStatisticsVo> list = workStatisticsMapper.getByUser(dto);
|
|
// 计算及时率
|
for (WorkStatisticsVo vo : list) {
|
int timely = vo.getTimelyCount() != null ? vo.getTimelyCount() : 0;
|
int overdue = vo.getOverdueCount() != null ? vo.getOverdueCount() : 0;
|
int total = timely + overdue;
|
if (total > 0) {
|
vo.setTimelyRate((timely * 100.0) / total);
|
} else {
|
vo.setTimelyRate(0.0);
|
}
|
}
|
|
return list;
|
}
|
|
@Override
|
public List<Map<String, Object>> getTimelyRate(WorkStatisticsDto dto) {
|
processDateType(dto);
|
return workStatisticsMapper.getTimelyRate(dto);
|
}
|
|
@Override
|
public Map<String, Object> getTrend(WorkStatisticsDto dto) {
|
processDateType(dto);
|
|
List<Map<String, Object>> trendData = workStatisticsMapper.getTrend(dto);
|
|
Map<String, Object> result = new HashMap<>();
|
List<String> dates = new ArrayList<>();
|
List<Integer> sampleCounts = new ArrayList<>();
|
List<Integer> itemCounts = new ArrayList<>();
|
|
for (Map<String, Object> item : trendData) {
|
dates.add((String) item.get("date"));
|
sampleCounts.add(((Number) item.get("sampleCount")).intValue());
|
itemCounts.add(((Number) item.get("itemCount")).intValue());
|
}
|
|
result.put("dates", dates);
|
result.put("sampleCounts", sampleCounts);
|
result.put("itemCounts", itemCounts);
|
return result;
|
}
|
|
/**
|
* 处理时间类型
|
*/
|
private void processDateType(WorkStatisticsDto dto) {
|
if (dto.getStartTime() != null && dto.getEndTime() != null) {
|
return;
|
}
|
|
String dateType = dto.getDateType();
|
if (dateType == null || dateType.isEmpty()) {
|
dateType = "2"; // 默认本月
|
}
|
|
Date now = new Date();
|
switch (dateType) {
|
case "1": // 本周
|
dto.setStartTime(DateUtil.format(DateUtil.beginOfWeek(now), "yyyy-MM-dd HH:mm:ss"));
|
dto.setEndTime(DateUtil.format(DateUtil.endOfWeek(now), "yyyy-MM-dd HH:mm:ss"));
|
break;
|
case "2": // 本月
|
dto.setStartTime(DateUtil.format(DateUtil.beginOfMonth(now), "yyyy-MM-dd HH:mm:ss"));
|
dto.setEndTime(DateUtil.format(DateUtil.endOfMonth(now), "yyyy-MM-dd HH:mm:ss"));
|
break;
|
case "3": // 本年
|
dto.setStartTime(DateUtil.format(DateUtil.beginOfYear(now), "yyyy-MM-dd HH:mm:ss"));
|
dto.setEndTime(DateUtil.format(DateUtil.endOfYear(now), "yyyy-MM-dd HH:mm:ss"));
|
break;
|
}
|
}
|
|
}
|