|
|
@@ -71,6 +71,14 @@ public class XmTechnicianHoursServiceImpl extends BaseServiceImpl<XmTechnicianHo
|
|
|
//月度工时列表
|
|
|
List<XmTechnicianHours> dbList = baseMapper.selectByYearAndMonth(yearAndMonth, null, null);
|
|
|
|
|
|
+ List<JSONObject> objects = baseMapper.countByUnicodeAndWorkDate(yearAndMonth);
|
|
|
+ JSONObject usedHoursByUnicodeAndDate = new JSONObject();
|
|
|
+ for (JSONObject object : objects) {
|
|
|
+ usedHoursByUnicodeAndDate.put(object.getString("unicode") + ":" + object.getString("workDate"), object.getDoubleValue("hoursTotal"));
|
|
|
+ }
|
|
|
+// Collector<T, ?, Map<K, D>> tMapCollector = Collectors.groupingBy(XmTechnicianHours::getUnicode, Collectors.summingDouble(XmTechnicianHours::getWorkHours));
|
|
|
+ //按人员筛选、根据日期分组,再对工时求和
|
|
|
+// Map<String, Double> usedByUnicodeAndDateMap = new HashMap<>();
|
|
|
//将研发项目信息缓存起来
|
|
|
Map<String, Long> xmMap = new HashMap<>();
|
|
|
//将研发人员信息缓存起来
|
|
|
@@ -105,10 +113,19 @@ public class XmTechnicianHoursServiceImpl extends BaseServiceImpl<XmTechnicianHo
|
|
|
technicianMap.put(techniciankey, unicode);
|
|
|
}
|
|
|
|
|
|
- //根据人员和项目获取工时列表,用于后续决定是新增还是修改
|
|
|
- Long finalXmId = xmId;
|
|
|
String finalUnicode = unicode;
|
|
|
- List<XmTechnicianHours> byXmAndUnicodeList = dbList.stream().filter(e -> e.getXmId().equals(finalXmId) && e.getUnicode().equals(finalUnicode)).toList();
|
|
|
+ Long finalXmId = xmId;
|
|
|
+
|
|
|
+// String finalUnicode1 = unicode;
|
|
|
+// Map<String, Double> collect = dbList.stream().filter(e -> e.getUnicode().equals(finalUnicode1)).collect(Collectors.groupingBy(XmTechnicianHours::getWorkDate, Collectors.summingDouble(XmTechnicianHours::getWorkHours)));
|
|
|
+// for (String workDate : collect.keySet()) {
|
|
|
+// Double v = usedByUnicodeAndDateMap.get(workDate);
|
|
|
+// }
|
|
|
+
|
|
|
+ //根据人员和项目获取工时列表,用于后续决定是新增还是修改
|
|
|
+// Long finalXmId = xmId;
|
|
|
+// String finalUnicode = unicode;
|
|
|
+// List<XmTechnicianHours> byXmAndUnicodeList = dbList.stream().filter(e->e.getUnicode().equals(finalUnicode)).toList();
|
|
|
|
|
|
//根据unicode、yearAndMonth获取考勤明细
|
|
|
List<DailyAttendance> dailyAttendanceList = attendanceMapper.selectDailyAttendanceByUnicodeAndMonth(unicode, yearAndMonth);
|
|
|
@@ -118,25 +135,24 @@ public class XmTechnicianHoursServiceImpl extends BaseServiceImpl<XmTechnicianHo
|
|
|
//每天的考勤总时长
|
|
|
Map<String, Double> hoursByDateMap = dailyAttendanceList.stream().collect(Collectors.groupingBy(DailyAttendance::getWorkDate, Collectors.summingDouble(DailyAttendance::getWorkHours)));
|
|
|
|
|
|
- //按人员筛选、根据日期分组,再对工时求和
|
|
|
- Map<String, Double> usedByUnicodeAndDateMap = dbList.stream().filter(e -> e.getUnicode().equals(finalUnicode)).collect(Collectors.groupingBy(XmTechnicianHours::getWorkDate, Collectors.summingDouble(XmTechnicianHours::getWorkHours)));
|
|
|
|
|
|
for (DailyAttendance dailyAttendance : record.getDailyAttendances()) {
|
|
|
|
|
|
-
|
|
|
+ String key = unicode + ":" + dailyAttendance.getWorkDate();
|
|
|
Double hoursTotal = hoursByDateMap.get(dailyAttendance.getWorkDate());
|
|
|
if (hoursTotal == null || hoursTotal <= 0) {
|
|
|
throw new ServiceException(dailyAttendance.getWorkDate() + "当天无考勤数据");
|
|
|
}
|
|
|
- Double usedHours = usedByUnicodeAndDateMap.get(dailyAttendance.getWorkDate());
|
|
|
- if(usedHours==null){
|
|
|
- usedHours = 0.0;
|
|
|
- }
|
|
|
+ Double usedHours = usedHoursByUnicodeAndDate.getDoubleValue(key);
|
|
|
+
|
|
|
if (hoursTotal - usedHours < dailyAttendance.getWorkHours()) {
|
|
|
//当 考勤时长 - 当天以用工时 < 新的工时 ,则提示“考勤时长不足”
|
|
|
throw new ServiceException("[序号"+record.getSerialNumber()+",日期"+dailyAttendance.getWorkDate()+"工时"+dailyAttendance.getWorkHours()+"]的考勤时长不足,出勤总时长" + hoursTotal + ",已用" + usedHours + ",可用"+(hoursTotal-usedHours)+",请核对数据");
|
|
|
}
|
|
|
- List<Long> primaryKeyList = byXmAndUnicodeList.stream().filter(e -> Objects.equals(e.getWorkDate(), dailyAttendance.getWorkDate()) && Objects.equals(e.getXmId(), finalXmId) && Objects.equals(e.getUnicode(), finalUnicode)).map(XmTechnicianHours::getId).toList();
|
|
|
+
|
|
|
+ double doubleValue = usedHoursByUnicodeAndDate.getDoubleValue(key) + dailyAttendance.getWorkHours();
|
|
|
+
|
|
|
+ List<Long> primaryKeyList = dbList.stream().filter(e -> Objects.equals(e.getWorkDate(), dailyAttendance.getWorkDate()) && Objects.equals(e.getXmId(), finalXmId) && Objects.equals(e.getUnicode(), finalUnicode)).map(XmTechnicianHours::getId).toList();
|
|
|
Long primaryKey = CollectionUtil.isEmpty(primaryKeyList) ? null : primaryKeyList.get(0);
|
|
|
XmTechnicianHours entity = new XmTechnicianHours();
|
|
|
if (primaryKey == null) {
|
|
|
@@ -150,15 +166,19 @@ public class XmTechnicianHoursServiceImpl extends BaseServiceImpl<XmTechnicianHo
|
|
|
insertList.add(entity);
|
|
|
|
|
|
//已用工时 加上新增的工时
|
|
|
- usedByUnicodeAndDateMap.put(dailyAttendance.getWorkDate(), usedHours + dailyAttendance.getWorkHours());
|
|
|
+// double doubleValue = usedHoursByUnicodeAndDate.getDoubleValue(key) + dailyAttendance.getWorkHours();
|
|
|
+ usedHoursByUnicodeAndDate.put(key, doubleValue);
|
|
|
} else {
|
|
|
entity.setId(primaryKey);
|
|
|
entity.setWorkHours(dailyAttendance.getWorkHours());
|
|
|
updateList.add(entity);
|
|
|
|
|
|
//查询数据库中的原有的工时,需要加上旧值,在减去新值
|
|
|
- double oldHours = byXmAndUnicodeList.stream().filter(e -> Objects.equals(e.getWorkDate(), dailyAttendance.getWorkDate())).mapToDouble(XmTechnicianHours::getWorkHours).sum();
|
|
|
- usedByUnicodeAndDateMap.put(dailyAttendance.getWorkDate(), usedHours - oldHours + dailyAttendance.getWorkHours());
|
|
|
+ double oldHours = dbList.stream().filter(e -> Objects.equals(e.getWorkDate(), dailyAttendance.getWorkDate()) && Objects.equals(e.getXmId(), finalXmId) && Objects.equals(e.getUnicode(), finalUnicode)).mapToDouble(XmTechnicianHours::getWorkHours).sum();
|
|
|
+
|
|
|
+ //double oldHours = byXmAndUnicodeList.stream().filter(e -> Objects.equals(e.getWorkDate(), dailyAttendance.getWorkDate())).mapToDouble(XmTechnicianHours::getWorkHours).sum();
|
|
|
+// double doubleValue = usedHoursByUnicodeAndDate.getDoubleValue(key) + dailyAttendance.getWorkHours();
|
|
|
+ usedHoursByUnicodeAndDate.put(key, usedHours - oldHours + dailyAttendance.getWorkHours());
|
|
|
}
|
|
|
if (!insertList.isEmpty() && insertList.size() % batchCount == 0) {
|
|
|
if (this.saveBatch(insertList)) {
|