|
|
@@ -45,7 +45,7 @@ public class AttendanceServiceImpl extends BaseServiceImpl<AttendanceMapper, Att
|
|
|
|
|
|
@Override
|
|
|
public IPage<AttendanceVO> selectAttendancePage(AttendanceDto attendance, IPage<AttendanceVO> page) {
|
|
|
- if(StringUtil.isBlank(attendance.getYearAndMonth())) {
|
|
|
+ if (StringUtil.isBlank(attendance.getYearAndMonth())) {
|
|
|
throw new ServiceException("参数yearAndMonth不能为空");
|
|
|
}
|
|
|
List<AttendanceVO> list = baseMapper.selectAttendancePage(page, attendance);
|
|
|
@@ -108,15 +108,13 @@ public class AttendanceServiceImpl extends BaseServiceImpl<AttendanceMapper, Att
|
|
|
if (technicianId == null) {
|
|
|
throw new ServiceException("序号为[" + record.getSerialNumber() + "]的工号和者身份证都不存在");
|
|
|
}
|
|
|
-// List<AttendanceEntity> dataByTechnicianMonthly = dbList.stream().filter(e -> e.getTechnicianId().equals(technicianId) && Objects.equals(e.getWorkDate().substring(0, 6), yearAndMonth)).toList();
|
|
|
List<AttendanceEntity> dataByTechnicianMonthly = dbList.stream().filter(e -> e.getTechnicianId().equals(technicianId)).toList();
|
|
|
for (DailyAttendance dailyAttendance : record.getDailyAttendances()) {
|
|
|
|
|
|
List<Long> primaryKeyList = dataByTechnicianMonthly.stream().filter(e -> Objects.equals(e.getWorkDate(), dailyAttendance.getWorkDate())).map(AttendanceEntity::getId).toList();
|
|
|
Long primaryKey = CollectionUtil.isEmpty(primaryKeyList) ? null : primaryKeyList.get(0);
|
|
|
-// baseMapper.selectPrimaryKeyByTechnicianIdAndWorkDate(technicianId, dailyAttendance.getDate());
|
|
|
+ AttendanceEntity entity = new AttendanceEntity();
|
|
|
if (primaryKey == null) {
|
|
|
- AttendanceEntity entity = new AttendanceEntity();
|
|
|
entity.setTechnicianId(technicianId);
|
|
|
entity.setWorkDate(dailyAttendance.getWorkDate());
|
|
|
entity.setWorkHours(dailyAttendance.getWorkHours());
|
|
|
@@ -125,28 +123,72 @@ public class AttendanceServiceImpl extends BaseServiceImpl<AttendanceMapper, Att
|
|
|
entity.setCreateDept(Func.toLong(SecureUtil.getDeptId()));
|
|
|
insertList.add(entity);
|
|
|
} else {
|
|
|
- AttendanceEntity entity = new AttendanceEntity();
|
|
|
entity.setId(primaryKey);
|
|
|
entity.setWorkHours(dailyAttendance.getWorkHours());
|
|
|
updateList.add(entity);
|
|
|
}
|
|
|
- if (insertList.size() % batchCount == 0) {
|
|
|
- int insertCount = baseMapper.batchSave(insertList);
|
|
|
- insertList.clear();
|
|
|
+ if (!insertList.isEmpty() && insertList.size() % batchCount == 0) {
|
|
|
+ int insertCount = baseMapper.batchInsert(insertList);
|
|
|
+ if (insertCount == batchCount) {
|
|
|
+ insertList.clear();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ if (!insertList.isEmpty() && updateList.size() % batchCount == 0) {
|
|
|
+ int updateCount = baseMapper.batchUpdate(updateList);
|
|
|
+ if (updateCount == batchCount) {
|
|
|
+ updateList.clear();
|
|
|
+ }
|
|
|
}
|
|
|
-// if (updateList.size() % batchCount == 0) {
|
|
|
-// int updateCount = baseMapper.batchUpdate(updateList);
|
|
|
-// if (updateCount == batchCount) {
|
|
|
-// updateList.clear();
|
|
|
-// }
|
|
|
-// }
|
|
|
}
|
|
|
}
|
|
|
if (!insertList.isEmpty()) {
|
|
|
- baseMapper.batchSave(insertList);
|
|
|
+ baseMapper.batchInsert(insertList);
|
|
|
+ }
|
|
|
+ if (!updateList.isEmpty()) {
|
|
|
+ baseMapper.batchUpdate(updateList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean batchSubmit(AttendanceDto attendance) {
|
|
|
+ List<AttendanceEntity> dbList = baseMapper.selectByYearAndMonth(attendance.getYearAndMonth());
|
|
|
+ List<AttendanceEntity> dataByTechnicianMonthly = dbList.stream().filter(e -> e.getTechnicianId().equals(attendance.getTechnicianId())).toList();
|
|
|
+
|
|
|
+ //需要新增的,以便后续批量新增
|
|
|
+ List<AttendanceEntity> insertList = new ArrayList<>();
|
|
|
+ //需要更新的,以便后续批量修改
|
|
|
+ List<AttendanceEntity> updateList = new ArrayList<>();
|
|
|
+
|
|
|
+ for (DailyAttendance dailyAttendance : attendance.getDailyAttendances()) {
|
|
|
+
|
|
|
+ List<Long> primaryKeyList = dataByTechnicianMonthly.stream().filter(e -> Objects.equals(e.getWorkDate(), dailyAttendance.getWorkDate())).map(AttendanceEntity::getId).toList();
|
|
|
+ Long primaryKey = CollectionUtil.isEmpty(primaryKeyList) ? null : primaryKeyList.get(0);
|
|
|
+ AttendanceEntity entity = new AttendanceEntity();
|
|
|
+ if (primaryKey == null) {
|
|
|
+ entity.setTechnicianId(attendance.getTechnicianId());
|
|
|
+ entity.setWorkDate(dailyAttendance.getWorkDate());
|
|
|
+ entity.setWorkHours(dailyAttendance.getWorkHours());
|
|
|
+ entity.setTenantId(SecureUtil.getTenantId());
|
|
|
+ entity.setCreateUser(SecureUtil.getUserId());
|
|
|
+ entity.setCreateDept(Func.toLong(SecureUtil.getDeptId()));
|
|
|
+ insertList.add(entity);
|
|
|
+ } else {
|
|
|
+ entity.setId(primaryKey);
|
|
|
+ entity.setWorkHours(dailyAttendance.getWorkHours());
|
|
|
+ updateList.add(entity);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!insertList.isEmpty()) {
|
|
|
+ baseMapper.batchInsert(insertList);
|
|
|
+ insertList.clear();
|
|
|
+ }
|
|
|
+ if (!updateList.isEmpty()) {
|
|
|
+ baseMapper.batchUpdate(updateList);
|
|
|
+ updateList.clear();
|
|
|
}
|
|
|
-// if (!updateList.isEmpty()) {
|
|
|
-// baseMapper.batchUpdate(updateList);
|
|
|
-// }
|
|
|
+ return true;
|
|
|
}
|
|
|
}
|