|
@@ -4,6 +4,7 @@
|
|
|
*/
|
|
|
package com.tofly.gpsboot.service.sign.impl;
|
|
|
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
@@ -16,6 +17,7 @@ import com.tofly.common.oauth.util.SecurityUtils;
|
|
|
import com.tofly.gpsboot.common.system.SignFlagEnum;
|
|
|
import com.tofly.gpsboot.common.system.SignTypeEnum;
|
|
|
import com.tofly.pojo.plan.dto.PdasignhisDto;
|
|
|
+import com.tofly.pojo.plan.vo.AttendanceReportVo;
|
|
|
import com.tofly.pojo.plan.vo.PdasignhisVo;
|
|
|
import com.tofly.gpsboot.mapper.plan.PdasignhisMapper;
|
|
|
import com.tofly.pojo.User;
|
|
@@ -24,10 +26,9 @@ import com.tofly.gpsboot.service.sign.PdasignhisService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Set;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.*;
|
|
|
+import java.util.concurrent.atomic.AtomicInteger;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
@@ -93,4 +94,81 @@ public class PdasignhisServiceImpl extends ServiceImpl<PdasignhisMapper, Pdasign
|
|
|
infoPageList.setRecords(this.viewConversion(infoPageList.getRecords()));
|
|
|
return infoPageList;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<AttendanceReportVo> attendanceReport(String startTime, String endTime, String deptIds) {
|
|
|
+ List<AttendanceReportVo> res = new ArrayList<>();
|
|
|
+ List<Date> dateList = getBetweenDate(startTime, endTime, 1);
|
|
|
+ List<Long> queryUserIds = this.baseMapper.getUserIdList(deptIds);
|
|
|
+ List<Pdasignhis> pdasignhisList = this.list();
|
|
|
+ AtomicInteger num = new AtomicInteger(1);
|
|
|
+ dateList.forEach(date -> {
|
|
|
+ List<Pdasignhis> pdasignhisListFinal = pdasignhisList.stream()
|
|
|
+ .filter(e -> DateUtil.format(e.getSignTime(), "yyyy-MM-dd").equals(DateUtil.format(date, "yyyy-MM-dd")))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ Map<Long, List<Pdasignhis>> pdUserMap = pdasignhisListFinal.stream().collect(Collectors.groupingBy(Pdasignhis::getSignUser));
|
|
|
+ pdUserMap.forEach((k,v) -> {
|
|
|
+ if (!queryUserIds.contains(k)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ AttendanceReportVo vo = new AttendanceReportVo();
|
|
|
+ vo.setId(num.get());
|
|
|
+ vo.setUserId(k);
|
|
|
+ vo.setUserName(v.get(0).getSignUserName());
|
|
|
+ vo.setDeptName(v.get(0).getDeptName());
|
|
|
+ vo.setOnNumber(BigDecimal.ZERO);
|
|
|
+ vo.setOffNumber(BigDecimal.ZERO);
|
|
|
+ Map<String, List<Pdasignhis>> pdOnOffMap = v.stream().collect(Collectors.groupingBy(Pdasignhis::getSignType));
|
|
|
+ pdOnOffMap.forEach((k1,v1) -> {
|
|
|
+ v1.sort(Comparator.comparing(Pdasignhis::getSignTime));
|
|
|
+ if (k1.equals("1")) {
|
|
|
+ vo.setOnTime(v1.get(0).getSignTime());
|
|
|
+ vo.setOnAddress(v1.get(0).getSignAddress());
|
|
|
+ vo.setOnNumber(BigDecimal.valueOf(v1.size()));
|
|
|
+ } else if (k1.equals("2")) {
|
|
|
+ vo.setOffTime(v1.get(v1.size() - 1).getSignTime());
|
|
|
+ vo.setOffAddress(v1.get(v1.size() - 1).getSignAddress());
|
|
|
+ vo.setOffNumber(BigDecimal.valueOf(v1.size()));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ vo.setSignNumber(vo.getOnNumber().add(vo.getOffNumber()));
|
|
|
+ if (vo.getOnTime() != null && vo.getOffTime() != null) {
|
|
|
+ BigDecimal workHours = new BigDecimal(DateUtil.format(vo.getOffTime(), "HH"))
|
|
|
+ .subtract(new BigDecimal(DateUtil.format(vo.getOnTime(), "HH")));
|
|
|
+ vo.setWorkHour(workHours);
|
|
|
+ }
|
|
|
+ res.add(vo);
|
|
|
+ num.getAndIncrement();
|
|
|
+ });
|
|
|
+ });
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 获取两个日期之间的所有日期
|
|
|
+ * @param start 开始日期
|
|
|
+ * @param end 结束日期
|
|
|
+ * @param type 0小时 1天 2月
|
|
|
+ * @return list
|
|
|
+ */
|
|
|
+ List<Date> getBetweenDate(String start, String end, Integer type) {
|
|
|
+ Calendar cal = Calendar.getInstance();
|
|
|
+ cal.setTime(DateUtil.parse(start, "yyyy-MM-dd HH:mm:ss"));
|
|
|
+ List<Date> dateList = new ArrayList<>();
|
|
|
+ while (DateUtil.format(cal.getTime(), "yyyy-MM-dd HH:mm:ss").compareTo(end) < 0) {
|
|
|
+ dateList.add(cal.getTime());
|
|
|
+ switch (type) {
|
|
|
+ case 0:
|
|
|
+ cal.add(Calendar.HOUR, +1);
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ cal.add(Calendar.DATE, +1);
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ cal.add(Calendar.MONTH, +1);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return dateList;
|
|
|
+ }
|
|
|
}
|