|
|
@@ -41,6 +41,7 @@ import java.time.YearMonth;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 科研仪器设备工时 服务实现类
|
|
|
@@ -62,7 +63,7 @@ public class XmAssetHoursServiceImpl extends BaseServiceImpl<XmAssetHoursMapper,
|
|
|
@Override
|
|
|
public void importXmAssetHours(MultipartFile file, String yearAndMonth) {
|
|
|
XmAssetHoursListener listener = new XmAssetHoursListener(yearAndMonth);
|
|
|
- EasyExcel.read(new BufferedInputStream(file.getInputStream()))
|
|
|
+ EasyExcel.read(new BufferedInputStream(file.getInputStream()))
|
|
|
.registerReadListener(listener)
|
|
|
.sheet(0)
|
|
|
.headRowNumber(3) // 重要:设置表头行数(0-based)
|
|
|
@@ -102,8 +103,27 @@ public class XmAssetHoursServiceImpl extends BaseServiceImpl<XmAssetHoursMapper,
|
|
|
updateZgs(dbAsset.getId(), record.getZgs(), yearAndMonth);
|
|
|
|
|
|
List<XmAssetHoursEntity> byXmAndAssetList = dbList.stream().filter(e -> e.getXmId().equals(xmId) && e.getAssetId().equals(dbAsset.getId())).toList();
|
|
|
+
|
|
|
+ List<XmAssetHoursEntity> dbAssetHours = baseMapper.selectByYearAndMonth(yearAndMonth, null, dbAsset.getId());
|
|
|
for (DailyAttendance dailyAttendance : record.getDailyAttendances()) {
|
|
|
|
|
|
+ Map<String, List<XmAssetHoursEntity>> mapByDate = dbAssetHours.stream().collect(Collectors.groupingBy(XmAssetHoursEntity::getWorkDate));
|
|
|
+ List<XmAssetHoursEntity> dbHourList = mapByDate.get(dailyAttendance.getWorkDate());
|
|
|
+ if(Func.isEmpty(dbHourList) ){
|
|
|
+ dbHourList = new ArrayList<>();
|
|
|
+ mapByDate.put(dailyAttendance.getWorkDate(), dbHourList);
|
|
|
+ }
|
|
|
+ for (XmAssetHoursEntity hours : dbHourList) {
|
|
|
+ if(Func.equals(hours.getWorkDate(), dailyAttendance.getWorkDate()) && Func.equals(hours.getXmId(), xmId)){
|
|
|
+ hours.setWorkHours(dailyAttendance.getWorkHours());
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ double totalHoursByDay = dbHourList.stream().mapToDouble(XmAssetHoursEntity::getWorkHours).sum();
|
|
|
+ if(totalHoursByDay > 24){
|
|
|
+ throw new ServiceException("设备在" + dailyAttendance.getWorkDate() +"这天的工时超过了24小时,请核对数据");
|
|
|
+ }
|
|
|
+
|
|
|
List<Long> primaryKeyList = byXmAndAssetList.stream().filter(e -> Objects.equals(e.getWorkDate(), dailyAttendance.getWorkDate())).map(XmAssetHoursEntity::getId).toList();
|
|
|
Long primaryKey = CollectionUtil.isEmpty(primaryKeyList) ? null : primaryKeyList.get(0);
|
|
|
XmAssetHoursEntity entity = new XmAssetHoursEntity();
|
|
|
@@ -160,7 +180,7 @@ public class XmAssetHoursServiceImpl extends BaseServiceImpl<XmAssetHoursMapper,
|
|
|
return page.setRecords(list);
|
|
|
}
|
|
|
|
|
|
- private void updateZgs(Long assetId, Double zgs, String yearAndMonth){
|
|
|
+ private void updateZgs(Long assetId, Double zgs, String yearAndMonth) {
|
|
|
if (zgs != null) {
|
|
|
//不能大于当月工作天数(自然天数)X24小时
|
|
|
// 解析年份和月份
|
|
|
@@ -208,8 +228,25 @@ public class XmAssetHoursServiceImpl extends BaseServiceImpl<XmAssetHoursMapper,
|
|
|
//需要更新的,以便后续批量修改
|
|
|
List<XmAssetHoursEntity> updateList = new ArrayList<>();
|
|
|
|
|
|
- for (DailyAttendance dailyAttendance : dto.getDailyHoursList()) {
|
|
|
+ List<XmAssetHoursEntity> dbAssetHours = baseMapper.selectByYearAndMonth(dto.getYearAndMonth(), null, dto.getAssetId());
|
|
|
|
|
|
+ for (DailyAttendance dailyAttendance : dto.getDailyHoursList()) {
|
|
|
+ Map<String, List<XmAssetHoursEntity>> mapByDate = dbAssetHours.stream().collect(Collectors.groupingBy(XmAssetHoursEntity::getWorkDate));
|
|
|
+ List<XmAssetHoursEntity> dbHourList = mapByDate.get(dailyAttendance.getWorkDate());
|
|
|
+ if(Func.isEmpty(dbHourList) ){
|
|
|
+ dbHourList = new ArrayList<>();
|
|
|
+ mapByDate.put(dailyAttendance.getWorkDate(), dbHourList);
|
|
|
+ }
|
|
|
+ for (XmAssetHoursEntity hours : dbHourList) {
|
|
|
+ if(Func.equals(hours.getWorkDate(), dailyAttendance.getWorkDate()) && Func.equals(hours.getXmId(), dto.getXmId())){
|
|
|
+ hours.setWorkHours(dailyAttendance.getWorkHours());
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ double totalHoursByDay = dbHourList.stream().mapToDouble(XmAssetHoursEntity::getWorkHours).sum();
|
|
|
+ if(totalHoursByDay > 24){
|
|
|
+ throw new ServiceException("设备在" + dailyAttendance.getWorkDate() +"这天的工时超过了24小时,请核对数据");
|
|
|
+ }
|
|
|
List<Long> primaryKeyList = dbList.stream().filter(e -> Objects.equals(e.getWorkDate(), dailyAttendance.getWorkDate())).map(XmAssetHoursEntity::getId).toList();
|
|
|
Long primaryKey = CollectionUtil.isEmpty(primaryKeyList) ? null : primaryKeyList.get(0);
|
|
|
XmAssetHoursEntity entity = new XmAssetHoursEntity();
|