|
|
|
|
@ -1,19 +1,20 @@ |
|
|
|
|
|
|
|
|
|
package org.springblade.modules.business.service.impl; |
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
|
import org.apache.commons.collections.CollectionUtils; |
|
|
|
|
import org.springblade.core.mp.base.BaseServiceImpl; |
|
|
|
|
import org.springblade.core.tool.utils.CollectionUtil; |
|
|
|
|
import org.springblade.modules.business.pojo.entity.DeviceAttach; |
|
|
|
|
import org.springblade.modules.business.pojo.entity.DeviceMaintenance; |
|
|
|
|
import org.springblade.modules.business.pojo.entity.maintenance.MaintenancePlanDetail; |
|
|
|
|
import org.springblade.modules.business.pojo.entity.maintenance.MaintenanceTask; |
|
|
|
|
import org.springblade.modules.business.pojo.entity.maintenance.MaintenanceTaskDetail; |
|
|
|
|
import org.springblade.modules.business.service.IMaintenancePlanDetailService; |
|
|
|
|
import org.springblade.modules.business.service.IMaintenancePlanService; |
|
|
|
|
import org.springblade.modules.business.service.*; |
|
|
|
|
import org.springblade.modules.business.mapper.MaintenancePlanMapper; |
|
|
|
|
import org.springblade.modules.business.pojo.entity.maintenance.MaintenancePlan; |
|
|
|
|
import org.springblade.modules.business.service.IMaintenanceTaskDetailService; |
|
|
|
|
import org.springblade.modules.business.service.IMaintenanceTaskService; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
|
|
@ -38,6 +39,7 @@ public class MaintenancePlanServiceImpl extends BaseServiceImpl<MaintenancePlanM |
|
|
|
|
private final IMaintenancePlanDetailService planDetailService; |
|
|
|
|
private final IMaintenanceTaskService taskService; |
|
|
|
|
private final IMaintenanceTaskDetailService taskDetailService; |
|
|
|
|
private final IDeviceAttachService deviceAttachService; |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
|
@ -55,7 +57,17 @@ public class MaintenancePlanServiceImpl extends BaseServiceImpl<MaintenancePlanM |
|
|
|
|
List<MaintenancePlanDetail> details = plan.getDetails(); |
|
|
|
|
if (CollectionUtil.isNotEmpty(details)) { |
|
|
|
|
details.forEach(detail -> detail.setPlanId(plan.getId())); |
|
|
|
|
planDetailService.saveBatch(details); |
|
|
|
|
save = planDetailService.saveBatch(details); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 保存附件
|
|
|
|
|
List<DeviceAttach> attaches = plan.getAttaches(); |
|
|
|
|
if (CollectionUtil.isNotEmpty(attaches)) { |
|
|
|
|
attaches.forEach(attach -> { |
|
|
|
|
attach.setDeviceId(plan.getId()); |
|
|
|
|
attach.setStatus(2);// 实验室附件
|
|
|
|
|
}); |
|
|
|
|
save = deviceAttachService.saveBatch(attaches); |
|
|
|
|
} |
|
|
|
|
return save; |
|
|
|
|
} |
|
|
|
|
@ -70,6 +82,7 @@ public class MaintenancePlanServiceImpl extends BaseServiceImpl<MaintenancePlanM |
|
|
|
|
List<MaintenancePlanDetail> saveList = new ArrayList<>(); |
|
|
|
|
// 需要修改的详情
|
|
|
|
|
List<MaintenancePlanDetail> updateList = new ArrayList<>(); |
|
|
|
|
List<Long> ids = details.stream().filter(detail -> detail.getId() != null).map(MaintenancePlanDetail::getId).collect(Collectors.toList()); |
|
|
|
|
for (MaintenancePlanDetail detail : details) { |
|
|
|
|
if (detail.getId() != null) { |
|
|
|
|
updateList.add(detail); |
|
|
|
|
@ -78,8 +91,32 @@ public class MaintenancePlanServiceImpl extends BaseServiceImpl<MaintenancePlanM |
|
|
|
|
saveList.add(detail); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// 需要修改
|
|
|
|
|
planDetailService.updateBatchById(updateList); |
|
|
|
|
// 需要新增
|
|
|
|
|
planDetailService.saveBatch(saveList); |
|
|
|
|
// 需要删除
|
|
|
|
|
planDetailService.remove(Wrappers.lambdaQuery(MaintenancePlanDetail.class) |
|
|
|
|
.eq(MaintenancePlanDetail::getDeviceId, plan.getId()) |
|
|
|
|
.notIn(CollectionUtils.isNotEmpty(ids), MaintenancePlanDetail::getId, ids)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 保存附件
|
|
|
|
|
List<DeviceAttach> attaches = plan.getAttaches(); |
|
|
|
|
if (CollectionUtil.isNotEmpty(attaches)) { |
|
|
|
|
// 需要新增的巡检
|
|
|
|
|
List<DeviceAttach> newSave = attaches.stream().filter(attach -> attach.getId() == null).collect(Collectors.toList()); |
|
|
|
|
// 不删除的巡检ids
|
|
|
|
|
List<Long> ids = attaches.stream().filter(attach -> attach.getId() != null).map(DeviceAttach::getId).collect(Collectors.toList()); |
|
|
|
|
deviceAttachService.remove(Wrappers.lambdaQuery(DeviceAttach.class) |
|
|
|
|
.eq(DeviceAttach::getDeviceId, plan.getId()) |
|
|
|
|
.eq(DeviceAttach::getStatus, 2) |
|
|
|
|
.notIn(CollectionUtils.isNotEmpty(ids), DeviceAttach::getId, ids)); |
|
|
|
|
|
|
|
|
|
if (CollectionUtil.isNotEmpty(newSave)) { |
|
|
|
|
newSave.forEach(maintenance -> maintenance.setDeviceId(plan.getId())); |
|
|
|
|
deviceAttachService.saveBatch(newSave); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return this.updateById(plan); |
|
|
|
|
} |
|
|
|
|
@ -94,7 +131,25 @@ public class MaintenancePlanServiceImpl extends BaseServiceImpl<MaintenancePlanM |
|
|
|
|
@Override |
|
|
|
|
public MaintenancePlan planDetail(MaintenancePlan plan) { |
|
|
|
|
MaintenancePlan planDetail = this.getById(plan.getId()); |
|
|
|
|
planDetail.setDetails(planDetailService.list(Wrappers.lambdaQuery(MaintenancePlanDetail.class).eq(MaintenancePlanDetail::getPlanId, planDetail.getId()))); |
|
|
|
|
List<MaintenancePlanDetail> details = planDetailService.list(Wrappers.lambdaQuery(MaintenancePlanDetail.class).eq(MaintenancePlanDetail::getPlanId, planDetail.getId())); |
|
|
|
|
Map<String, List<MaintenancePlanDetail>> floorMap = details.stream().collect(Collectors.groupingBy(MaintenancePlanDetail::getFloorName)); |
|
|
|
|
List<MaintenancePlanDetail> floorList = new ArrayList<>(); |
|
|
|
|
for (Map.Entry<String, List<MaintenancePlanDetail>> stringListEntry : floorMap.entrySet()) { |
|
|
|
|
List<MaintenancePlanDetail> deptList = new ArrayList<>(); |
|
|
|
|
MaintenancePlanDetail floor = new MaintenancePlanDetail(); |
|
|
|
|
List<MaintenancePlanDetail> floors = stringListEntry.getValue(); |
|
|
|
|
Map<String, List<MaintenancePlanDetail>> deptMap = floors.stream().collect(Collectors.groupingBy(MaintenancePlanDetail::getDeptName)); |
|
|
|
|
for (Map.Entry<String, List<MaintenancePlanDetail>> listEntry : deptMap.entrySet()) { |
|
|
|
|
MaintenancePlanDetail dept = new MaintenancePlanDetail(); |
|
|
|
|
dept.setDeptName(listEntry.getKey()); |
|
|
|
|
dept.setDetails(listEntry.getValue()); |
|
|
|
|
deptList.add(dept); |
|
|
|
|
} |
|
|
|
|
floor.setFloorName(stringListEntry.getKey()); |
|
|
|
|
floor.setDetails(deptList); |
|
|
|
|
floorList.add(floor); |
|
|
|
|
} |
|
|
|
|
planDetail.setDetails(floorList); |
|
|
|
|
return planDetail; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|