|
@@ -12,6 +12,7 @@ import com.usky.iot.service.PmWorkContentService;
|
|
|
import com.usky.iot.service.PmWorkReportService;
|
|
|
import com.usky.common.mybatis.core.AbstractCrudService;
|
|
|
import com.usky.iot.service.config.DingTalkAndMessage;
|
|
|
+import com.usky.iot.service.vo.PmProjectTotalWorkTimeVo;
|
|
|
import com.usky.iot.service.vo.PmProjectWorkTimeVo;
|
|
|
import com.usky.system.domain.SysUser;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -25,6 +26,7 @@ import java.math.RoundingMode;
|
|
|
import java.time.DayOfWeek;
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
|
+import java.time.Year;
|
|
|
import java.time.temporal.TemporalAdjusters;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -292,23 +294,24 @@ public class PmWorkReportServiceImpl extends AbstractCrudService<PmWorkReportMap
|
|
|
pmWorkContentMapper.insert(newContent);
|
|
|
pmWorkContents.add(newContent);
|
|
|
}
|
|
|
- //抄送人不为空,非定时发送
|
|
|
- if (StringUtils.isNotEmpty(pmWorkReport.getCcTo())) {
|
|
|
- if (timingTime == null) {
|
|
|
- //推送消息中心
|
|
|
- dingTalkAndMessage.sendAsyncMessage(newReport);
|
|
|
+ if (timingTime == null) {
|
|
|
+ //推送消息中心
|
|
|
+ dingTalkAndMessage.sendAsyncMessage(newReport);
|
|
|
|
|
|
- //是否同步钉钉
|
|
|
- if (pmWorkReport.getSendDingTalk() == 1) {
|
|
|
- dingTalkAndMessage.sendDingTalkDailyReport(newReport, pmWorkContents);
|
|
|
- }
|
|
|
+ //是否同步钉钉
|
|
|
+ if (pmWorkReport.getSendDingTalk() == 1) {
|
|
|
+ dingTalkAndMessage.sendDingTalkDailyReport(newReport, pmWorkContents);
|
|
|
}
|
|
|
+
|
|
|
//存入报告消息表
|
|
|
List<Long> longList = Arrays.stream(pmWorkReport.getCcTo().split(","))
|
|
|
.map(Long::parseLong)
|
|
|
.collect(Collectors.toList());
|
|
|
receiveMessages(longList, newReport.getId());
|
|
|
}
|
|
|
+ //抄送人不为空,非定时发送
|
|
|
+ if (StringUtils.isNotEmpty(pmWorkReport.getCcTo())) {
|
|
|
+ }
|
|
|
} else if (repeat.size() > 0) {
|
|
|
PmWorkReport rp = new PmWorkReport();
|
|
|
rp.setId(pmWorkReport.getId());
|
|
@@ -388,89 +391,167 @@ public class PmWorkReportServiceImpl extends AbstractCrudService<PmWorkReportMap
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<Map<String, Object>> countTime() {
|
|
|
- int scale = 2;
|
|
|
+ public PmProjectTotalWorkTimeVo countTime(Integer dateType, Integer dateNum) {
|
|
|
+ int scale = 4;
|
|
|
RoundingMode roundingMode = RoundingMode.HALF_UP;
|
|
|
- List<Map<String, Object>> returnList = new ArrayList<>();
|
|
|
- Map<String, Object> weekTotalMap = new HashMap<>();
|
|
|
- Map<String, Object> monthTotalMap = new HashMap<>();
|
|
|
- Map<String, Object> weekMap = new HashMap<>();
|
|
|
- Map<String, Object> monthMap = new HashMap<>();
|
|
|
+// List<Map<String, Object>> returnList = new ArrayList<>();
|
|
|
+// Map<String, Object> weekTotalMap = new HashMap<>();
|
|
|
+// Map<String, Object> monthTotalMap = new HashMap<>();
|
|
|
+// Map<String, Object> weekMap = new HashMap<>();
|
|
|
+// Map<String, Object> monthMap = new HashMap<>();
|
|
|
+ PmProjectTotalWorkTimeVo projectTotalWorkTimeVo = new PmProjectTotalWorkTimeVo();
|
|
|
List<PmProjectWorkTimeVo> returnListW = new ArrayList<>();
|
|
|
- List<PmProjectWorkTimeVo> returnListM = new ArrayList<>();
|
|
|
- LocalDate today = LocalDate.now();
|
|
|
- LocalDate startOfWeek = today.with(TemporalAdjusters.previousOrSame(java.time.DayOfWeek.MONDAY));
|
|
|
- LocalDate endOfWeek = today.with(TemporalAdjusters.nextOrSame(java.time.DayOfWeek.SUNDAY));
|
|
|
- LocalDateTime startOfWeekDateTime = startOfWeek.atStartOfDay();
|
|
|
- LocalDateTime endOfWeekDateTime = endOfWeek.atTime(23, 59, 59);
|
|
|
- LocalDate startOfMonth = today.withDayOfMonth(1);
|
|
|
- LocalDate endOfMonth = today.withDayOfMonth(today.lengthOfMonth());
|
|
|
- LocalDateTime startOfMonthDateTime = startOfMonth.atStartOfDay();
|
|
|
- LocalDateTime endOfMonthDateTime = endOfMonth.atTime(23, 59, 59);
|
|
|
-
|
|
|
- BigDecimal weekTotal = BigDecimal.ZERO;
|
|
|
- List<PmProjectWorkTimeVo> week = pmWorkContentMapper.workTimeCount(startOfWeekDateTime, endOfWeekDateTime, SecurityUtils.getUserId());
|
|
|
+ //List<PmProjectWorkTimeVo> returnListM = new ArrayList<>();
|
|
|
+ //LocalDate today = LocalDate.now();
|
|
|
+
|
|
|
+// LocalDate startOfWeek = today.with(TemporalAdjusters.previousOrSame(java.time.DayOfWeek.MONDAY));
|
|
|
+// LocalDate endOfWeek = today.with(TemporalAdjusters.nextOrSame(java.time.DayOfWeek.SUNDAY));
|
|
|
+// LocalDateTime startOfWeekDateTime = startOfWeek.atStartOfDay();
|
|
|
+// LocalDateTime endOfWeekDateTime = endOfWeek.atTime(23, 59, 59);
|
|
|
+ Map<String, LocalDateTime> stringLocalDateTimeMap = countWeekOrMonth(dateType, dateNum);
|
|
|
+ LocalDateTime startTime = stringLocalDateTimeMap.get("start");
|
|
|
+ LocalDateTime endTime = stringLocalDateTimeMap.get("end");
|
|
|
+ BigDecimal totalWorkTime = BigDecimal.ZERO;
|
|
|
+ List<PmProjectWorkTimeVo> week = pmWorkContentMapper.workTimeCount(startTime, endTime, SecurityUtils.getUserId());
|
|
|
if (week.isEmpty()) {
|
|
|
- weekTotalMap.put("WeekWorkTimeTotal", 0);
|
|
|
- weekMap.put("WeeklyData", week);
|
|
|
+ projectTotalWorkTimeVo.setTotalWorkTime(totalWorkTime);
|
|
|
+ projectTotalWorkTimeVo.setProjectWorkTime(week);
|
|
|
+ return projectTotalWorkTimeVo;
|
|
|
}
|
|
|
- for (int i = 0; i < week.size(); i++) {
|
|
|
- weekTotal = weekTotal.add(week.get(i).getWorkTime());
|
|
|
- }
|
|
|
- BigDecimal totalPercentageW = BigDecimal.ZERO;
|
|
|
- for (int a = 0; a < week.size(); a++) {
|
|
|
- PmProjectWorkTimeVo workTimeVo = new PmProjectWorkTimeVo();
|
|
|
- workTimeVo.setProjectName(week.get(a).getProjectName());
|
|
|
- workTimeVo.setWorkTime(week.get(a).getWorkTime());
|
|
|
- if (a != week.size() - 1) {
|
|
|
- BigDecimal percentage = week.get(a).getWorkTime().divide(weekTotal, scale, roundingMode);
|
|
|
- workTimeVo.setPercentage(percentage);
|
|
|
- totalPercentageW = totalPercentageW.add(percentage);
|
|
|
- } else {
|
|
|
- BigDecimal lastPercentage = BigDecimal.ONE.subtract(totalPercentageW);
|
|
|
- workTimeVo.setPercentage(lastPercentage);
|
|
|
+// for (int i = 0; i < week.size(); i++) {
|
|
|
+// weekTotal = weekTotal.add(week.get(i).getWorkTime());
|
|
|
+// }
|
|
|
+ totalWorkTime = week.stream()
|
|
|
+ .map(PmProjectWorkTimeVo::getWorkTime)
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+
|
|
|
+// BigDecimal totalPercentageW = BigDecimal.ZERO;
|
|
|
+// for (int a = 0; a < week.size(); a++) {
|
|
|
+// PmProjectWorkTimeVo workTimeVo = new PmProjectWorkTimeVo();
|
|
|
+// workTimeVo.setProjectName(week.get(a).getProjectName());
|
|
|
+// workTimeVo.setWorkTime(week.get(a).getWorkTime());
|
|
|
+// if (a != week.size() - 1) {
|
|
|
+// BigDecimal percentage = week.get(a).getWorkTime().divide(weekTotal, scale, roundingMode);
|
|
|
+// workTimeVo.setPercentage(percentage);
|
|
|
+// totalPercentageW = totalPercentageW.add(percentage);
|
|
|
+// } else {
|
|
|
+// BigDecimal lastPercentage = BigDecimal.ONE.subtract(totalPercentageW);
|
|
|
+// workTimeVo.setPercentage(lastPercentage);
|
|
|
+// }
|
|
|
+// workTimeVo.setPercentage(week.get(a).getWorkTime().divide(weekTotal, scale, roundingMode));
|
|
|
+// returnListW.add(workTimeVo);
|
|
|
+// }
|
|
|
+// projectTotalWorkTimeVo.setProjectWorkTime(returnListW);
|
|
|
+ List<PmProjectWorkTimeVo> projectWorkTimeWithPercentage = calculatePercentage(week, totalWorkTime, scale, roundingMode);
|
|
|
+ projectTotalWorkTimeVo.setTotalWorkTime(totalWorkTime);
|
|
|
+ projectTotalWorkTimeVo.setProjectWorkTime(projectWorkTimeWithPercentage);
|
|
|
+ return projectTotalWorkTimeVo;
|
|
|
+
|
|
|
+
|
|
|
+// LocalDate startOfMonth = today.withDayOfMonth(1);
|
|
|
+// LocalDate endOfMonth = today.withDayOfMonth(today.lengthOfMonth());
|
|
|
+// LocalDateTime startOfMonthDateTime = startOfMonth.atStartOfDay();
|
|
|
+// LocalDateTime endOfMonthDateTime = endOfMonth.atTime(23, 59, 59);
|
|
|
+// BigDecimal monthTotal = BigDecimal.ZERO;
|
|
|
+// List<PmProjectWorkTimeVo> month = pmWorkContentMapper.workTimeCount(startOfMonthDateTime, endOfMonthDateTime, SecurityUtils.getUserId());
|
|
|
+// if (month.isEmpty()) {
|
|
|
+// weekTotalMap.put("MonthWorkTimeTotal", 0);
|
|
|
+// weekMap.put("MonthlyData", month);
|
|
|
+// }
|
|
|
+// for (int i = 0; i < month.size(); i++) {
|
|
|
+// monthTotal = monthTotal.add(month.get(i).getWorkTime());
|
|
|
+// }
|
|
|
+// BigDecimal totalPercentageM = BigDecimal.ZERO;
|
|
|
+// for (int b = 0; b < month.size(); b++) {
|
|
|
+// PmProjectWorkTimeVo workTimeVo = new PmProjectWorkTimeVo();
|
|
|
+// workTimeVo.setProjectName(month.get(b).getProjectName());
|
|
|
+// workTimeVo.setWorkTime(month.get(b).getWorkTime());
|
|
|
+// if (b != month.size() - 1) {
|
|
|
+// BigDecimal percentage = month.get(b).getWorkTime().divide(monthTotal, scale, roundingMode);
|
|
|
+// workTimeVo.setPercentage(percentage);
|
|
|
+// totalPercentageM = totalPercentageM.add(percentage);
|
|
|
+// } else {
|
|
|
+// BigDecimal lastPercentage = BigDecimal.ONE.subtract(totalPercentageM);
|
|
|
+// workTimeVo.setPercentage(lastPercentage);
|
|
|
+// }
|
|
|
+//
|
|
|
+// returnListM.add(workTimeVo);
|
|
|
+// }
|
|
|
+
|
|
|
+// weekTotalMap.put("WeekWorkTimeTotal", weekTotal);
|
|
|
+// monthTotalMap.put("MonthWorkTimeTotal", monthTotal);
|
|
|
+// weekMap.put("WeeklyData", returnListW);
|
|
|
+// monthMap.put("MonthlyData", returnListM);
|
|
|
+// returnList.add(weekTotalMap);
|
|
|
+// returnList.add(monthTotalMap);
|
|
|
+// returnList.add(weekMap);
|
|
|
+// returnList.add(monthMap);
|
|
|
+ //return null;
|
|
|
+ }
|
|
|
+ //计算百分比
|
|
|
+ private List<PmProjectWorkTimeVo> calculatePercentage(List<PmProjectWorkTimeVo> workTimeList, BigDecimal totalWorkTime, int scale, RoundingMode roundingMode) {
|
|
|
+ BigDecimal totalPercentage = BigDecimal.ZERO;
|
|
|
+ List<PmProjectWorkTimeVo> projectWorkTimeWithPercentage = new ArrayList<>();
|
|
|
+
|
|
|
+ for (int i = 0; i < workTimeList.size(); i++) {
|
|
|
+ PmProjectWorkTimeVo workTimeVo = workTimeList.get(i);
|
|
|
+ BigDecimal percentage = workTimeVo.getWorkTime().divide(totalWorkTime, scale, roundingMode);
|
|
|
+ totalPercentage = totalPercentage.add(percentage);
|
|
|
+
|
|
|
+ if (totalPercentage.compareTo(BigDecimal.ONE) > 0) {
|
|
|
+ percentage = BigDecimal.ONE.subtract(totalPercentage.subtract(percentage));
|
|
|
}
|
|
|
- workTimeVo.setPercentage(week.get(a).getWorkTime().divide(weekTotal, scale, roundingMode));
|
|
|
- returnListW.add(workTimeVo);
|
|
|
- }
|
|
|
|
|
|
- BigDecimal monthTotal = BigDecimal.ZERO;
|
|
|
- List<PmProjectWorkTimeVo> month = pmWorkContentMapper.workTimeCount(startOfMonthDateTime, endOfMonthDateTime, SecurityUtils.getUserId());
|
|
|
- if (month.isEmpty()) {
|
|
|
- weekTotalMap.put("MonthWorkTimeTotal", 0);
|
|
|
- weekMap.put("MonthlyData", month);
|
|
|
- }
|
|
|
- for (int i = 0; i < month.size(); i++) {
|
|
|
- monthTotal = monthTotal.add(month.get(i).getWorkTime());
|
|
|
+ workTimeVo.setPercentage(percentage);
|
|
|
+ projectWorkTimeWithPercentage.add(workTimeVo);
|
|
|
}
|
|
|
- BigDecimal totalPercentageM = BigDecimal.ZERO;
|
|
|
- for (int b = 0; b < month.size(); b++) {
|
|
|
- PmProjectWorkTimeVo workTimeVo = new PmProjectWorkTimeVo();
|
|
|
- workTimeVo.setProjectName(month.get(b).getProjectName());
|
|
|
- workTimeVo.setWorkTime(month.get(b).getWorkTime());
|
|
|
- if (b != month.size() - 1) {
|
|
|
- BigDecimal percentage = month.get(b).getWorkTime().divide(monthTotal, scale, roundingMode);
|
|
|
- workTimeVo.setPercentage(percentage);
|
|
|
- totalPercentageM = totalPercentageM.add(percentage);
|
|
|
- } else {
|
|
|
- BigDecimal lastPercentage = BigDecimal.ONE.subtract(totalPercentageM);
|
|
|
- workTimeVo.setPercentage(lastPercentage);
|
|
|
+
|
|
|
+ return projectWorkTimeWithPercentage;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ //计算周和月
|
|
|
+ public Map<String, LocalDateTime> countWeekOrMonth(Integer dateType, Integer dateNum) {
|
|
|
+ Map<String, LocalDateTime> timePeriod = new HashMap<>();
|
|
|
+ LocalDate today = LocalDate.now();
|
|
|
+ Year currentYear = Year.from(today);
|
|
|
+
|
|
|
+ if (dateType == 1) {
|
|
|
+ LocalDate lastDayOfYear = currentYear.atDay(currentYear.length());
|
|
|
+ LocalDate lastMondayOfYear = lastDayOfYear.with(TemporalAdjusters.previousOrSame(java.time.DayOfWeek.MONDAY));
|
|
|
+ long totalWeeks = lastMondayOfYear.getDayOfYear() / 7 + 1;
|
|
|
+ if (dateNum > totalWeeks) {
|
|
|
+ throw new BusinessException("周数错误!请重新选择");
|
|
|
+ }
|
|
|
+
|
|
|
+ LocalDate firstMonday = currentYear.atDay(1).with(TemporalAdjusters.firstInMonth(DayOfWeek.MONDAY));
|
|
|
+ LocalDate startOfWeek = firstMonday.plusWeeks(dateNum - 1);
|
|
|
+ LocalDate endOfWeek = startOfWeek.plusWeeks(1).minusDays(1);
|
|
|
+ LocalDateTime startTimeOfWeek = startOfWeek.atStartOfDay();
|
|
|
+ LocalDateTime endTimeOfWeek = endOfWeek.atTime(23, 59, 59);
|
|
|
+ timePeriod.put("start", startTimeOfWeek);
|
|
|
+ timePeriod.put("end", endTimeOfWeek);
|
|
|
+
|
|
|
+ } else if (dateType == 2) {
|
|
|
+ if (dateNum < 1 || dateNum > 12) {
|
|
|
+ throw new BusinessException("月数错误!请重新选择");
|
|
|
}
|
|
|
+ LocalDate startOfMonth = currentYear.atMonth(dateNum).atDay(1);
|
|
|
+ LocalDate endOfMonth = startOfMonth.with(TemporalAdjusters.lastDayOfMonth());
|
|
|
+ LocalDateTime startTimeOfMonth = startOfMonth.atStartOfDay();
|
|
|
+ LocalDateTime endTimeOfMonth = endOfMonth.atTime(23, 59, 59);
|
|
|
+ timePeriod.put("start", startTimeOfMonth);
|
|
|
+ timePeriod.put("end", endTimeOfMonth);
|
|
|
|
|
|
- returnListM.add(workTimeVo);
|
|
|
+ } else {
|
|
|
+ throw new BusinessException("类型选择错误!请选择周或月");
|
|
|
}
|
|
|
|
|
|
- weekTotalMap.put("WeekWorkTimeTotal", weekTotal);
|
|
|
- monthTotalMap.put("MonthWorkTimeTotal", monthTotal);
|
|
|
- weekMap.put("WeeklyData", returnListW);
|
|
|
- monthMap.put("MonthlyData", returnListM);
|
|
|
- returnList.add(weekTotalMap);
|
|
|
- returnList.add(monthTotalMap);
|
|
|
- returnList.add(weekMap);
|
|
|
- returnList.add(monthMap);
|
|
|
- return returnList;
|
|
|
+ return timePeriod;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
@Transactional
|
|
|
@Override
|
|
|
public void timedSending(LocalDateTime time) {
|