xuzhancheng преди 3 седмици
родител
ревизия
ccdcfe0dea

+ 3 - 0
tz-module-pressure2/tz-module-pressure2-biz/src/main/java/cn/start/tz/module/pressure2/controller/admin/equippipescheduling/vo/PipeShiftScheduleRespVO.java

@@ -104,4 +104,7 @@ public class PipeShiftScheduleRespVO {
 
     @Schema(description = "约检确认单ID(排期表的confirm_order_id)")
     private String confirmOrderId;
+
+    @Schema(description = "源排期id")
+    private String sourceId;
 }

+ 5 - 0
tz-module-pressure2/tz-module-pressure2-biz/src/main/java/cn/start/tz/module/pressure2/dal/dataobject/equippipescheduling/EquipPipeSchedulingDO.java

@@ -59,4 +59,9 @@ public class EquipPipeSchedulingDO extends BaseDO {
      * 约检确认id
      */
     private String confirmOrderId;
+
+    /**
+     * 源数据id
+     */
+    private String sourceId;
 }

+ 14 - 10
tz-module-pressure2/tz-module-pressure2-biz/src/main/java/cn/start/tz/module/pressure2/service/equipboilerscheduling/EquipBoilerSchedulingServiceImpl.java

@@ -369,19 +369,23 @@ public class EquipBoilerSchedulingServiceImpl extends ServiceImpl<EquipBoilerSch
             item.setEquipStreetName(AreaUtils.getAreaName(item.getEquipStreet()));
 
             // 默认 已排期
-            item.setStatus(100);
-
-            if (org.apache.commons.lang3.StringUtils.isNotBlank(item.getAppointmentId())) {
-                item.setStatus(200);
+            int status = 100; // 默认已排期
+            if (item.getAppointmentId() != null) {
+                status = 200; // 待约检
             }
-
-            if (org.apache.commons.lang3.StringUtils.isNotBlank(item.getAcceptOrderId())) {
-                item.setStatus(300);
+            if (item.getAcceptStatus() != null){
+                status = 300;
             }
-
-            if ((item.getAcceptStatus() != null && item.getAcceptStatus() == AcceptOrderStatusEnum.CANCEL.getStatus().intValue()) || (item.getTaskStatus() != null && item.getTaskStatus() == TaskOrderStatusEnum.CANCEL.getStatus().intValue())) {
-                item.setStatus(400);
+            if (item.getTaskStatus() != null && item.getTaskStatus() >= 400) {
+                status = 400; // 检测中
+            }
+            // TaskStatusEnum: 710办结确认, 800报告办结
+            if (status >= 400) {
+                if (item.getTaskStatus() >= 800) {
+                    status = 600; // 已办结
+                }
             }
+            item.setStatus(status);
         });
 
         map.forEach((key,values)->{

+ 204 - 118
tz-module-pressure2/tz-module-pressure2-biz/src/main/java/cn/start/tz/module/pressure2/service/equippipescheduling/EquipPipeSchedulingServiceImpl.java

@@ -29,6 +29,8 @@ import cn.start.tz.module.pressure2.dal.dataobject.equippipeschedulinguser.Equip
 import cn.start.tz.module.pressure2.dal.dataobject.pipeappointmentconfirmorderitem.PipeAppointmentConfirmOrderItemDO;
 import cn.start.tz.module.pressure2.dal.dataobject.pipeappointmentconfirmorderitemdetail.PipeAppointmentConfirmOrderItemDetailDO;
 import cn.start.tz.module.pressure2.dal.dataobject.pipeappointmentconfirmorderuser.PipeAppointmentConfirmOrderUserDO;
+import cn.start.tz.module.pressure2.dal.dataobject.boilertaskorder.BoilerTaskOrderDO;
+import cn.start.tz.module.pressure2.dal.dataobject.pipetaskorderuser.PipeTaskOrderUserDO;
 import cn.start.tz.module.pressure2.dal.mysql.appointmentconfirmorder.AppointmentConfirmOrderMapper;
 import cn.start.tz.module.pressure2.dal.mysql.equippipe.EquipPipeMapper;
 import cn.start.tz.module.pressure2.dal.mysql.equippipedetail.EquipPipeDetailMapper;
@@ -40,6 +42,8 @@ import cn.start.tz.module.pressure2.dal.mysql.equippipeschedulinguser.EquipPipeS
 import cn.start.tz.module.pressure2.dal.mysql.pipeappointmentconfirmorderitem.PipeAppointmentConfirmOrderItemMapper;
 import cn.start.tz.module.pressure2.dal.mysql.pipeappointmentconfirmorderitemdetail.PipeAppointmentConfirmOrderItemDetailMapper;
 import cn.start.tz.module.pressure2.dal.mysql.pipeappointmentconfirmorderuser.PipeAppointmentConfirmOrderUserMapper;
+import cn.start.tz.module.pressure2.dal.mysql.boilertaskorder.BoilerTaskOrderMapper;
+import cn.start.tz.module.pressure2.dal.mysql.pipetaskorderuser.PipeTaskOrderUserMapper;
 import cn.start.tz.module.pressure2.service.appointmentconfirmorder.AppointmentConfirmOrderService;
 import cn.start.tz.module.pressure2.service.appointmentconfirmorder.PipeAppointmentConfirmOrderService;
 import cn.start.tz.module.pressure2.service.equippipeschedulingcheck.EquipPipeSchedulingCheckService;
@@ -147,6 +151,10 @@ public class EquipPipeSchedulingServiceImpl extends ServiceImpl<EquipPipeSchedul
 
     @Resource
     private PipeAppointmentConfirmOrderUserMapper pipeAppointmentConfirmOrderUserMapper;
+    @Resource
+    private BoilerTaskOrderMapper boilerTaskOrderMapper;
+    @Resource
+    private PipeTaskOrderUserMapper pipeTaskOrderUserMapper;
 
     @Resource
     private DeptApi deptApi;
@@ -473,19 +481,23 @@ public class EquipPipeSchedulingServiceImpl extends ServiceImpl<EquipPipeSchedul
             item.setEquipDistrictName(AreaUtils.getAreaName(item.getEquipDistrict()));
             item.setEquipStreetName(AreaUtils.getAreaName(item.getEquipStreet()));
             // 默认 已排期
-            item.setStatus(100);
-
-            if (org.apache.commons.lang3.StringUtils.isNotBlank(item.getAppointmentId())) {
-                item.setStatus(200);
+            int status = 100; // 默认已排期
+            if (item.getAppointmentId() != null) {
+                status = 200; // 待约检
             }
-
-            if (org.apache.commons.lang3.StringUtils.isNotBlank(item.getAcceptOrderId())) {
-                item.setStatus(300);
+            if (item.getAcceptStatus() != null){
+                status = 300;
+            }
+            if (item.getTaskStatus() != null && item.getTaskStatus() >= 400) {
+                status = 400; // 检测中
             }
 
-            if ((item.getAcceptStatus() != null && item.getAcceptStatus() == AcceptOrderStatusEnum.CANCEL.getStatus().intValue()) || (item.getTaskStatus() != null && item.getTaskStatus() == TaskOrderStatusEnum.CANCEL.getStatus().intValue())) {
-                item.setStatus(400);
+            if (status >= 400) {
+                if (item.getTaskStatus() >= 800) {
+                    status = 600; // 已办结
+                }
             }
+            item.setStatus(status);
         });
 
         map.forEach((key,values)->{
@@ -559,51 +571,66 @@ public class EquipPipeSchedulingServiceImpl extends ServiceImpl<EquipPipeSchedul
 
     @Override
     public void deleteTask(BoilerDeleteTask deleteTask) {
-
-        deleteTask.getIds().forEach(scheduleId->{
-            List<EquipPipeSchedulingItemDO> equipItems = equipPipeSchedulingItemMapper.selectList(EquipPipeSchedulingItemDO::getSchedulingId, scheduleId);
-            List<String> equipIds = equipItems.stream().map(item -> item.getEquipId()).filter(Objects::nonNull).toList();
-
-            EquipPipeDO equipPipeDO = new EquipPipeDO();
-            equipPipeDO.setHasLegalScheduling(false);
-
+         // 收集需要同步的 confirmOrderId
+        Set<String> confirmOrderIds = new HashSet<>();
+        deleteTask.getIds().forEach(scheduleId -> {
             EquipPipeSchedulingDO schedulingDO = equipPipeSchedulingMapper.selectById(scheduleId);
-            if(schedulingDO != null && schedulingDO.getType() == 200){
-                equipPipeDO.setHasLegalScheduling(null);
-                equipPipeDO.setHasYearScheduling(false);
+            if (schedulingDO != null && schedulingDO.getConfirmOrderId() != null) {
+                // 找出所有同 confirmOrderId 的子排期一起删除
+                List<EquipPipeSchedulingDO> childSchedulings = equipPipeSchedulingMapper.selectList(
+                        new LambdaQueryWrapperX<EquipPipeSchedulingDO>()
+                                .eq(EquipPipeSchedulingDO::getConfirmOrderId, schedulingDO.getConfirmOrderId()));
+                confirmOrderIds.add(schedulingDO.getConfirmOrderId());
+
+                for (EquipPipeSchedulingDO child : childSchedulings) {
+                    doDeleteSingleScheduling(child.getId());
+                }
+            } else {
+                doDeleteSingleScheduling(scheduleId);
             }
+        });
+        // 删除后代同步任务单检验员
+        for (String confirmOrderId : confirmOrderIds) {
+            syncTaskOrderUsers(confirmOrderId);
+        }
+    }
 
-            if(!equipIds.isEmpty()){
-                // 设备状态
-                equipPipeMapper.update(equipPipeDO,new LambdaQueryWrapperX<EquipPipeDO>().in(EquipPipeDO::getId,equipIds));
-            }
+    private void doDeleteSingleScheduling(String scheduleId) {
+        List<EquipPipeSchedulingItemDO> equipItems = equipPipeSchedulingItemMapper.selectList(EquipPipeSchedulingItemDO::getSchedulingId, scheduleId);
+        List<String> equipIds = equipItems.stream().map(item -> item.getEquipId()).filter(Objects::nonNull).toList();
 
-            List<EquipPipeSchedulingItemDetailDO> equipDetailItems = equipPipeSchedulingItemDetailMapper.selectList(EquipPipeSchedulingItemDetailDO::getSchedulingId, scheduleId);
-            List<String> equipDetailIds = equipDetailItems.stream().map(EquipPipeSchedulingItemDetailDO::getEquipDetailId).filter(Objects::nonNull).toList();
+        EquipPipeDO equipPipeDO = new EquipPipeDO();
+        equipPipeDO.setHasLegalScheduling(false);
 
-            EquipPipeDetailDO equipPipeDetailDO = new EquipPipeDetailDO();
-            equipPipeDetailDO.setHasLegalScheduling(false);
+        EquipPipeSchedulingDO schedulingDO = equipPipeSchedulingMapper.selectById(scheduleId);
+        if (schedulingDO != null && schedulingDO.getType() == 200) {
+            equipPipeDO.setHasLegalScheduling(null);
+            equipPipeDO.setHasYearScheduling(false);
+        }
 
+        if (!equipIds.isEmpty()) {
+            equipPipeMapper.update(equipPipeDO, new LambdaQueryWrapperX<EquipPipeDO>().in(EquipPipeDO::getId, equipIds));
+        }
 
-            if(schedulingDO != null && schedulingDO.getType() == 200){
-                equipPipeDetailDO.setHasLegalScheduling(null);
-                equipPipeDetailDO.setHasYearScheduling(false);
-            }
+        List<EquipPipeSchedulingItemDetailDO> equipDetailItems = equipPipeSchedulingItemDetailMapper.selectList(EquipPipeSchedulingItemDetailDO::getSchedulingId, scheduleId);
+        List<String> equipDetailIds = equipDetailItems.stream().map(EquipPipeSchedulingItemDetailDO::getEquipDetailId).filter(Objects::nonNull).toList();
 
-            if(!equipDetailIds.isEmpty()){
-                // 设备状态
-                equipPipeDetailMapper.update(equipPipeDetailDO,new LambdaQueryWrapperX<EquipPipeDetailDO>().in(EquipPipeDetailDO::getId,equipDetailIds));
-            }
+        EquipPipeDetailDO equipPipeDetailDO = new EquipPipeDetailDO();
+        equipPipeDetailDO.setHasLegalScheduling(false);
 
-            // 人员清理
-            equipPipeSchedulingUserMapper.delete(EquipPipeSchedulingUserDO::getSchedulingId,scheduleId);
-            // 设备清理
-            equipPipeSchedulingItemMapper.delete(EquipPipeSchedulingItemDO::getSchedulingId,scheduleId);
-            // 设备明细清理
-            equipPipeSchedulingItemDetailMapper.delete(EquipPipeSchedulingItemDetailDO::getSchedulingId,scheduleId);
+        if (schedulingDO != null && schedulingDO.getType() == 200) {
+            equipPipeDetailDO.setHasLegalScheduling(null);
+            equipPipeDetailDO.setHasYearScheduling(false);
+        }
 
-            equipPipeSchedulingMapper.deleteById(scheduleId);
-        });
+        if (!equipDetailIds.isEmpty()) {
+            equipPipeDetailMapper.update(equipPipeDetailDO, new LambdaQueryWrapperX<EquipPipeDetailDO>().in(EquipPipeDetailDO::getId, equipDetailIds));
+        }
+
+        equipPipeSchedulingUserMapper.delete(EquipPipeSchedulingUserDO::getSchedulingId, scheduleId);
+        equipPipeSchedulingItemMapper.delete(EquipPipeSchedulingItemDO::getSchedulingId, scheduleId);
+        equipPipeSchedulingItemDetailMapper.delete(EquipPipeSchedulingItemDetailDO::getSchedulingId, scheduleId);
+        equipPipeSchedulingMapper.deleteById(scheduleId);
     }
 
     @Override
@@ -634,10 +661,14 @@ public class EquipPipeSchedulingServiceImpl extends ServiceImpl<EquipPipeSchedul
         for (EquipPipeSchedulingDO schedulingDO : equipPipeSchedulingDOS) {
             String id = schedulingDO.getId();
 
-            //
+            // 计划已提交
             if (schedulingDO.getConfirmOrderId() != null){
                 continue;
             }
+            // 复制行不可提交
+            if (schedulingDO.getSourceId() != null){
+                continue;
+            }
             List<EquipPipeSchedulingItemDO> equipPipeSchedulingItemDOS = equipPipeSchedulingItemMapper.selectList(EquipPipeSchedulingItemDO::getSchedulingId, id);
 
             //获取管道排期设备信息
@@ -769,6 +800,18 @@ public class EquipPipeSchedulingServiceImpl extends ServiceImpl<EquipPipeSchedul
             String confirmOrderId = appointmentConfirmOrderService.create(appointmentConfirmOrderDO);
             schedulingDO.setConfirmOrderId(confirmOrderId);
             equipPipeSchedulingMapper.updateById(schedulingDO);
+
+            // 同步 confirmOrderId 到所有复制行(通过 sourceId 关联)
+            List<EquipPipeSchedulingDO> copiedSchedulings = equipPipeSchedulingMapper.selectList(
+                    new LambdaQueryWrapperX<EquipPipeSchedulingDO>()
+                            .eq(EquipPipeSchedulingDO::getSourceId, schedulingDO.getId()));
+            if (copiedSchedulings != null && !copiedSchedulings.isEmpty()) {
+                for (EquipPipeSchedulingDO copied : copiedSchedulings) {
+                    copied.setConfirmOrderId(confirmOrderId);
+                    equipPipeSchedulingMapper.updateById(copied);
+                }
+            }
+
             // 创建任务单项目
             equipPipeSchedulingItemDOS.forEach(item->{
                 PipeAppointmentConfirmOrderItemDO orderItem = new PipeAppointmentConfirmOrderItemDO();
@@ -819,16 +862,30 @@ public class EquipPipeSchedulingServiceImpl extends ServiceImpl<EquipPipeSchedul
                 //创建约检确认单退回记录
                 //createAppointmentConfirmRollbackRecord(appointmentConfirmOrderDO, orderItem, 0, getLoginUserId(), confirmOrderId);
             });
-            // 创建任务单人员
-            List<EquipPipeSchedulingUserDO> equipBoilerSchedulingUserDOS = equipPipeSchedulingUserMapper.selectList(EquipPipeSchedulingUserDO::getSchedulingId, schedulingDO.getId());
-            List<PipeAppointmentConfirmOrderUserDO> confirmOrderUserDOS = equipBoilerSchedulingUserDOS.stream().map(item -> {
-                PipeAppointmentConfirmOrderUserDO appointmentConfirmOrderUserDO = new PipeAppointmentConfirmOrderUserDO();
-                appointmentConfirmOrderUserDO.setOrderId(confirmOrderId);
-                appointmentConfirmOrderUserDO.setUserId(item.getUserId());
-                appointmentConfirmOrderUserDO.setGroupTeamId(item.getGroupTeamId());
-                appointmentConfirmOrderUserDO.setType(item.getType());
-                return appointmentConfirmOrderUserDO;
-            }).toList();
+            // 创建约检确认单人员:汇总源排期和所有复制行的检验员,去重
+            List<String> allSchedulingIds = new ArrayList<>();
+            allSchedulingIds.add(schedulingDO.getId());
+            if (copiedSchedulings != null && !copiedSchedulings.isEmpty()) {
+                copiedSchedulings.forEach(c -> allSchedulingIds.add(c.getId()));
+            }
+            List<EquipPipeSchedulingUserDO> allSchedulingUsers = equipPipeSchedulingUserMapper.selectList(
+                    new LambdaQueryWrapperX<EquipPipeSchedulingUserDO>()
+                            .in(EquipPipeSchedulingUserDO::getSchedulingId, allSchedulingIds));
+            Set<String> dedupKeys = new LinkedHashSet<>();
+            List<PipeAppointmentConfirmOrderUserDO> confirmOrderUserDOS = new ArrayList<>();
+            if (allSchedulingUsers != null) {
+                for (EquipPipeSchedulingUserDO user : allSchedulingUsers) {
+                    String key = user.getGroupTeamId() + ":" + user.getUserId();
+                    if (dedupKeys.add(key)) {
+                        PipeAppointmentConfirmOrderUserDO appointmentConfirmOrderUserDO = new PipeAppointmentConfirmOrderUserDO();
+                        appointmentConfirmOrderUserDO.setOrderId(confirmOrderId);
+                        appointmentConfirmOrderUserDO.setUserId(user.getUserId());
+                        appointmentConfirmOrderUserDO.setGroupTeamId(user.getGroupTeamId());
+                        appointmentConfirmOrderUserDO.setType(user.getType());
+                        confirmOrderUserDOS.add(appointmentConfirmOrderUserDO);
+                    }
+                }
+            }
 
             appointmentConfirmOrderUserMapper.insert(confirmOrderUserDOS);
 
@@ -851,7 +908,7 @@ public class EquipPipeSchedulingServiceImpl extends ServiceImpl<EquipPipeSchedul
 //              submitVO.setUserList(equipBoilerSchedulingUserDOS.stream().map(EquipPipeSchedulingUserDO::getUserId).toList());
                 Map<String, SubmitTeamItemVO> teamMap = new HashMap<>();
 
-                equipBoilerSchedulingUserDOS.forEach(user -> {
+                confirmOrderUserDOS.forEach(user -> {
                     String groupTeamId = user.getGroupTeamId();
                     SubmitTeamItemVO teamItem = teamMap.computeIfAbsent(groupTeamId, k -> {
                         SubmitTeamItemVO item = new SubmitTeamItemVO();
@@ -1331,12 +1388,19 @@ public class EquipPipeSchedulingServiceImpl extends ServiceImpl<EquipPipeSchedul
             if (item.getAppointmentId() != null) {
                 status = 200; // 待约检
             }
-            if (item.getAcceptStatus() != null && item.getAcceptStatus() == 200){
+            if (item.getAcceptStatus() != null){
                 status = 300;
             }
-            if (item.getTaskStatus() != null) {
+            if (item.getTaskStatus() != null && item.getTaskStatus() >= 400) {
                 status = 400; // 检测中
             }
+
+            // TaskStatusEnum: 710办结确认, 800报告办结
+            if (status >= 400) {
+                if (item.getTaskStatus() >= 800) {
+                    status = 600; // 已办结
+                }
+            }
             item.setStatus(status);
 
             // 复制出来的行没有约检确认单,通过 confirmOrderId 找源排期,用源排期的关联状态
@@ -1353,6 +1417,11 @@ public class EquipPipeSchedulingServiceImpl extends ServiceImpl<EquipPipeSchedul
                     }
                     if (sourceItem.getTaskStatus() != null) {
                         status = 400; // 检测中
+                        if (sourceItem.getTaskStatus() >= 800) {
+                            status = 600;
+                        } else if (sourceItem.getTaskStatus() >= 710) {
+                            status = 500;
+                        }
                     }
                 }
             }
@@ -1516,8 +1585,8 @@ public class EquipPipeSchedulingServiceImpl extends ServiceImpl<EquipPipeSchedul
             equipPipeSchedulingUserMapper.insert(newUsers);
         }
 
-        // 同步更新约检确认单的检验员
-        addAppointmentConfirmOrderUsers(schedulingDO.getConfirmOrderId(), teamList);
+        // 同步更新约检确认单的检验员和任务单检验员
+        syncTaskOrderUsers(schedulingDO.getConfirmOrderId());
     }
 
     /**
@@ -1535,25 +1604,33 @@ public class EquipPipeSchedulingServiceImpl extends ServiceImpl<EquipPipeSchedul
             throw new ServiceException(500,"源排期不存在: " + sourceId);
         }
 
-        // 2. 校验:原行必须有 confirmOrderId 才能复制
-        if (StringUtils.isBlank(sourceScheduling.getConfirmOrderId())) {
-            throw new ServiceException(500,"原行没有约检确认单,无法复制");
-        }
-
-        // 3. 校验:同一个 confirmOrderId 的日期不能重复
-        List<EquipPipeSchedulingDO> sameConfirmList = equipPipeSchedulingMapper.selectList(
+        // 2. 校验:日期不能与源排期及其他复制行重复(通过 sourceId 关联)
+        Set<String> relatedIds = new HashSet<>();
+        relatedIds.add(sourceId);
+        // 查出同源的复制行(sourceId 指向同一个源)
+        List<EquipPipeSchedulingDO> sameSourceList = equipPipeSchedulingMapper.selectList(
                 new LambdaQueryWrapperX<EquipPipeSchedulingDO>()
-                        .eq(EquipPipeSchedulingDO::getConfirmOrderId, sourceScheduling.getConfirmOrderId()));
-        boolean dateDuplicate = sameConfirmList.stream()
-                .anyMatch(item -> vo.getDate().equals(item.getPlanDate()));
+                        .eq(EquipPipeSchedulingDO::getSourceId, sourceId));
+        if (sameSourceList != null) {
+            for (EquipPipeSchedulingDO item : sameSourceList) {
+                relatedIds.add(item.getId());
+            }
+        }
+        List<EquipPipeSchedulingDO> relatedSchedulings = equipPipeSchedulingMapper.selectByIds(new ArrayList<>(relatedIds));
+        boolean dateDuplicate = false;
+        if (relatedSchedulings != null) {
+            dateDuplicate = relatedSchedulings.stream()
+                    .anyMatch(item -> vo.getDate().equals(item.getPlanDate()));
+        }
         if (dateDuplicate) {
-            throw new ServiceException(500,"同一个约检确认单下日期不能重复: " + vo.getDate());
+            throw new ServiceException(500,"同一源排期下日期不能重复: " + vo.getDate());
         }
 
         // 4. 创建新排期主表(复制所有字段,使用原行的 confirmOrderId)
         EquipPipeSchedulingDO newScheduling = new EquipPipeSchedulingDO();
         cn.hutool.core.bean.BeanUtil.copyProperties(sourceScheduling, newScheduling, "id", "createTime", "updateTime", "deleted", "planDate");
         newScheduling.setPlanDate(vo.getDate());
+        newScheduling.setSourceId(sourceId);
         equipPipeSchedulingMapper.insert(newScheduling);
         String newSchedulingId = newScheduling.getId();
 
@@ -1653,66 +1730,75 @@ public class EquipPipeSchedulingServiceImpl extends ServiceImpl<EquipPipeSchedul
             equipPipeSchedulingUserMapper.insert(newUsers);
         }
 
-        // 增量添加约检确认单的检验员(源排期的 confirmOrderId)
-        addAppointmentConfirmOrderUsers(sourceScheduling.getConfirmOrderId(), teamList);
+        // 增量添加约检确认单的检验员和方法单检验员
+        syncTaskOrderUsers(sourceScheduling.getConfirmOrderId());
     }
 
     /**
-     * 增量添加约检确认单子表 PipeAppointmentConfirmOrderUserDO 的检验员
-     * 按 groupTeamId + userId 去重,不可重复添加
-     *
-     * @param confirmOrderId AppointmentConfirmOrderDO 的 id
-     * @param teamList 团队列表
+     * 同步任务单检验员:收集同一 confirmOrderId 下所有排期的检验员,去重后重建到任务单
      */
-    private void addAppointmentConfirmOrderUsers(String confirmOrderId, List<BoilerPlanSchedulingAssignTeamItemVO> teamList) {
-        if (confirmOrderId == null || confirmOrderId.isEmpty() || teamList == null || teamList.isEmpty()) {
+    private void syncTaskOrderUsers(String confirmOrderId) {
+        if (confirmOrderId == null || confirmOrderId.isEmpty()) {
             return;
         }
-        AppointmentConfirmOrderDO order = appointmentConfirmOrderMapper.selectById(confirmOrderId);
-        if (order == null) {
+        // 1. 找到所有关联此 confirmOrderId 的排期
+        List<EquipPipeSchedulingDO> schedulings = equipPipeSchedulingMapper.selectList(
+                new LambdaQueryWrapperX<EquipPipeSchedulingDO>()
+                        .eq(EquipPipeSchedulingDO::getConfirmOrderId, confirmOrderId));
+        if (schedulings == null || schedulings.isEmpty()) {
             return;
         }
-        // 查询已有的检验员,构建 (groupTeamId + ":" + userId) 去重集合
-        List<PipeAppointmentConfirmOrderUserDO> existingUsers = appointmentConfirmOrderUserMapper.selectList(
-                PipeAppointmentConfirmOrderUserDO::getOrderId, order.getId());
-        Set<String> existingKeys = existingUsers.stream()
-                .map(u -> u.getGroupTeamId() + ":" + u.getUserId())
-                .collect(Collectors.toSet());
-
-        List<PipeAppointmentConfirmOrderUserDO> newAppointmentUsers = new ArrayList<>();
-        for (BoilerPlanSchedulingAssignTeamItemVO team : teamList) {
-            String groupTeamId = team.getGroupTeamId();
-            // 添加组长
-            if (StringUtils.isNotBlank(team.getLeaderId())) {
-                String key = groupTeamId + ":" + team.getLeaderId();
-                if (!existingKeys.contains(key)) {
-                    PipeAppointmentConfirmOrderUserDO leader = new PipeAppointmentConfirmOrderUserDO();
-                    leader.setOrderId(order.getId());
-                    leader.setType(100);
-                    leader.setGroupTeamId(groupTeamId);
-                    leader.setUserId(team.getLeaderId());
-                    newAppointmentUsers.add(leader);
-                    existingKeys.add(key); // 本次批量内也去重
+        Set<String> schedulingIds = schedulings.stream().map(EquipPipeSchedulingDO::getId).collect(Collectors.toSet());
+
+        // 2. 收集所有排期的检验员,按 (groupTeamId + userId) 去重
+        List<EquipPipeSchedulingUserDO> allUsers = equipPipeSchedulingUserMapper.selectList(
+                new LambdaQueryWrapperX<EquipPipeSchedulingUserDO>()
+                        .in(EquipPipeSchedulingUserDO::getSchedulingId, schedulingIds));
+        Set<String> userKeys = new LinkedHashSet<>();
+        List<EquipPipeSchedulingUserDO> dedupedUsers = new ArrayList<>();
+        if (allUsers != null) {
+            for (EquipPipeSchedulingUserDO user : allUsers) {
+                String key = user.getGroupTeamId() + ":" + user.getUserId();
+                if (userKeys.add(key)) {
+                    dedupedUsers.add(user);
                 }
             }
-            // 添加组员
-            if (team.getMemberIdList() != null) {
-                for (String memberId : team.getMemberIdList()) {
-                    String key = groupTeamId + ":" + memberId;
-                    if (!existingKeys.contains(key)) {
-                        PipeAppointmentConfirmOrderUserDO member = new PipeAppointmentConfirmOrderUserDO();
-                        member.setOrderId(order.getId());
-                        member.setType(200);
-                        member.setGroupTeamId(groupTeamId);
-                        member.setUserId(memberId);
-                        newAppointmentUsers.add(member);
-                        existingKeys.add(key); // 本次批量内也去重
-                    }
+        }
+
+        // 3. 找到任务单:通过第一个有约检确认单的排期查找
+        BoilerTaskOrderDO taskOrder = null;
+        for (EquipPipeSchedulingDO scheduling : schedulings) {
+            List<AppointmentConfirmOrderDO> appointments = appointmentConfirmOrderMapper.selectList(
+                    AppointmentConfirmOrderDO::getSchedulingId, scheduling.getId());
+            if (appointments != null && !appointments.isEmpty()) {
+                List<BoilerTaskOrderDO> taskOrders = boilerTaskOrderMapper.selectList(
+                        new LambdaQueryWrapperX<BoilerTaskOrderDO>()
+                                .eq(BoilerTaskOrderDO::getSchedulingId, scheduling.getId()));
+                if (taskOrders != null && !taskOrders.isEmpty()) {
+                    taskOrder = taskOrders.get(0);
+                    break;
                 }
             }
         }
-        if (!newAppointmentUsers.isEmpty()) {
-            appointmentConfirmOrderUserMapper.insert(newAppointmentUsers);
+        if (taskOrder == null) {
+            return;
+        }
+
+        // 4. 删除任务单现有检验员,重建
+        pipeTaskOrderUserMapper.delete(new LambdaQueryWrapperX<PipeTaskOrderUserDO>()
+                .eq(PipeTaskOrderUserDO::getOrderId, taskOrder.getId()));
+
+        if (!dedupedUsers.isEmpty()) {
+            BoilerTaskOrderDO finalTaskOrder = taskOrder;
+            List<PipeTaskOrderUserDO> newTaskUsers = dedupedUsers.stream().map(user -> {
+                PipeTaskOrderUserDO taskUser = new PipeTaskOrderUserDO();
+                taskUser.setOrderId(finalTaskOrder.getId());
+                taskUser.setUserId(user.getUserId());
+                taskUser.setType(user.getType());
+                taskUser.setGroupTeamId(user.getGroupTeamId());
+                return taskUser;
+            }).collect(Collectors.toList());
+            pipeTaskOrderUserMapper.insert(newTaskUsers);
         }
     }
 

+ 2 - 2
tz-module-pressure2/tz-module-pressure2-biz/src/main/resources/mapper/equippipescheduling/EquipPipeSchedulingMapper.xml

@@ -555,7 +555,7 @@
             </if>
 
             <if test="unitName != null and unitName!='' ">
-                and a.UNIT_NAME = #{unitName}
+                and b.UNIT_NAME like CONCAT('%',#{unitName},'%')
             </if>
         </where>
         group by b.unit_code,a.plan_date,a.type,a.ID
@@ -565,7 +565,7 @@
         select a.ID task_id,a.TYPE check_type,b.unit_code,b.unit_name,b.unit_address,a.plan_date,count(distinct c.ID) equip_count,
         b.equip_district,b.equip_street,a.source,FIRST_VALUE(b.lng) lng,FIRST_VALUE(b.lat) lat,
         b.CONTACT,b.CONTACT_PHONE,b.PIPE_LENGTH_TOTAL,b.LAST_LEGAL_PERIODICAL_INSPECTION_REPORT_NO,b.LAST_YEAR_REPORT_NO,b.LAST_MAINTENANCE_REPORT_NO,
-        e.id APPOINTMENT_ID,f.id ACCEPT_ORDER_ID,f.STATUS accept_status, g.TASK_STATUS ,b.PIPE_ADDRESS,a.confirm_order_id
+        e.id APPOINTMENT_ID,f.id ACCEPT_ORDER_ID,f.STATUS accept_status, g.TASK_STATUS ,b.PIPE_ADDRESS,a.confirm_order_id,a.SOURCE_ID
         from PRESSURE2_EQUIP_PIPE_SCHEDULING a
         inner join PRESSURE2_EQUIP_PIPE_SCHEDULING_ITEM c on c.SCHEDULING_ID = a.ID and c.DELETED = 0
         inner join PRESSURE2_EQUIP_PIPE b on b.ID = c.equip_id and b.DELETED = 0