吴羡
3 天以前 8ad863082097ffdcab4a8e7f426d344a1fe6f892
inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsProductServiceImpl.java
@@ -11,12 +11,14 @@
import com.ruoyi.framework.exception.ErrorException;
import com.ruoyi.inspect.dto.InsProductBindingDto;
import com.ruoyi.inspect.dto.WriteInspectionConditionDto;
import com.ruoyi.inspect.mapper.InsOrderDeviceRecordMapper;
import com.ruoyi.inspect.mapper.InsOrderMapper;
import com.ruoyi.inspect.mapper.InsOrderStandardTemplateMapper;
import com.ruoyi.inspect.mapper.InsOrderTemplateDeviceMapper;
import com.ruoyi.inspect.mapper.InsProductMapper;
import com.ruoyi.inspect.mapper.InsSampleMapper;
import com.ruoyi.inspect.pojo.InsOrder;
import com.ruoyi.inspect.pojo.InsOrderDeviceRecord;
import com.ruoyi.inspect.pojo.InsOrderStandardTemplate;
import com.ruoyi.inspect.pojo.InsOrderTemplateDevice;
import com.ruoyi.inspect.pojo.InsProduct;
@@ -28,6 +30,8 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
@@ -48,6 +52,8 @@
    private InsOrderStandardTemplateMapper insOrderStandardTemplateMapper;
    private InsOrderTemplateDeviceMapper insOrderTemplateDeviceMapper;
    private InsOrderDeviceRecordMapper insOrderDeviceRecordMapper;
    @Override
    public int selectOrderManDay(Integer orderId) {
@@ -77,7 +83,24 @@
            if (snapshot == null) {
                throw new ErrorException("未找到当前模板的原始记录快照");
            }
            boolean hasSnapshotField = dto.isTemperaturePresent() || dto.isDetectionTimePresent()
            boolean hasDetectionRange = dto.isDetectionTimePresent() || dto.isDetectionEndTimePresent();
            if (hasDetectionRange) {
                if (!dto.isDetectionTimePresent()) {
                    throw new ErrorException("请选择完整的检测时间范围");
                }
                // 兼容旧客户端只提交单个日期;新客户端必须同时提交起止日期或同时清空。
                if (!dto.isDetectionEndTimePresent()) {
                    dto.setDetectionEndTime(dto.getDetectionTime());
                }
                if ((dto.getDetectionTime() == null) != (dto.getDetectionEndTime() == null)) {
                    throw new ErrorException("请选择完整的检测时间范围");
                }
                if (dto.getDetectionTime() != null
                        && dto.getDetectionEndTime().isBefore(dto.getDetectionTime())) {
                    throw new ErrorException("检测结束日期不能早于开始日期");
                }
            }
            boolean hasSnapshotField = dto.isTemperaturePresent() || hasDetectionRange
                    || dto.isDetectionPlacePresent()
                    || dto.isInsResultPresent();
            if (hasSnapshotField) {
@@ -88,6 +111,8 @@
                                        InsOrderStandardTemplate::getTemperature, dto.getTemperature())
                                .set(dto.isDetectionTimePresent(),
                                        InsOrderStandardTemplate::getDetectionTime, dto.getDetectionTime())
                                .set(hasDetectionRange,
                                        InsOrderStandardTemplate::getDetectionEndTime, dto.getDetectionEndTime())
                                .set(dto.isDetectionPlacePresent(),
                                        InsOrderStandardTemplate::getDetectionPlace, dto.getDetectionPlace())
                                .set(dto.isInsResultPresent(),
@@ -125,6 +150,7 @@
            if (!hasSnapshotField && !dto.isDeviceIdsPresent()) {
                throw new ErrorException("没有需要保存的模板检验条件");
            }
            refreshPendingDeviceRecords(dto);
            return true;
        }
        InsOrder insOrder = new InsOrder();
@@ -134,6 +160,38 @@
        return true;
    }
    /**
     * 原始记录的环境条件后补时,同步到尚未填写的使用记录。
     * 已手工改动过的记录(已有开始日期)不覆盖。
     */
    private void refreshPendingDeviceRecords(WriteInspectionConditionDto dto) {
        boolean hasTemperature = dto.isTemperaturePresent()
                && dto.getTemperature() != null && !dto.getTemperature().trim().isEmpty();
        boolean hasDetectionRange = dto.isDetectionTimePresent() && dto.getDetectionTime() != null;
        if (!hasTemperature && !hasDetectionRange) {
            return;
        }
        List<Integer> deviceIds = insOrderTemplateDeviceMapper
                .selectDeviceIdsByOrderAndTemplate(dto.getId(), dto.getTemplateId());
        if (deviceIds == null || deviceIds.isEmpty()) {
            return;
        }
        LocalDateTime start = null;
        LocalDateTime end = null;
        if (hasDetectionRange) {
            start = dto.getDetectionTime().atTime(10, 0);
            LocalDate endDate = dto.getDetectionEndTime() != null ? dto.getDetectionEndTime() : dto.getDetectionTime();
            end = endDate.atTime(19, 30);
        }
        insOrderDeviceRecordMapper.update(null, Wrappers.<InsOrderDeviceRecord>lambdaUpdate()
                .eq(InsOrderDeviceRecord::getInsOrderId, dto.getId())
                .in(InsOrderDeviceRecord::getDeviceId, deviceIds)
                .isNull(InsOrderDeviceRecord::getUseStartDate)
                .set(hasTemperature, InsOrderDeviceRecord::getTemperature, dto.getTemperature())
                .set(hasDetectionRange, InsOrderDeviceRecord::getUseStartDate, start)
                .set(hasDetectionRange, InsOrderDeviceRecord::getUseEndDate, end));
    }
    //查询待检项目
    @Override
    public IPage<InsProduct> selectNoProducts(Page page, InsProduct insProduct, Integer orderId, String ids) {