云
2026-10-25 d54fbc9d4f8981fa0f7f613b33a28a8cd4f764ea
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/checkrecord/MesDvCheckRecordServiceImpl.java
@@ -28,6 +28,16 @@
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.*;
import cn.iocoder.yudao.module.mes.controller.admin.dv.checkrecord.vo.MesDvCheckRecordImportExcelVO;
import cn.iocoder.yudao.module.mes.controller.admin.dv.checkrecord.vo.MesDvCheckRecordImportRespVO;
import cn.iocoder.yudao.module.mes.dal.dataobject.dv.machinery.MesDvMachineryDO;
import cn.iocoder.yudao.module.mes.dal.mysql.dv.machinery.MesDvMachineryMapper;
import cn.iocoder.yudao.module.mes.dal.dataobject.dv.checkplan.MesDvCheckPlanDO;
import cn.iocoder.yudao.module.mes.dal.mysql.dv.checkplan.MesDvCheckPlanMapper;
import cn.iocoder.yudao.framework.common.exception.ServiceException;
import cn.hutool.core.util.StrUtil;
import java.util.LinkedHashMap;
import java.util.concurrent.atomic.AtomicInteger;
/**
 * MES 设备点检记录 Service 实现类
@@ -37,6 +47,12 @@
@Service
@Validated
public class MesDvCheckRecordServiceImpl implements MesDvCheckRecordService {
    @Resource
    private MesDvCheckPlanMapper checkPlanMapper;
    @Resource
    private MesDvMachineryMapper machineryMapper;
    @Resource
@@ -198,4 +214,52 @@
        checkRecordLineService.createCheckRecordLineList(lines);
    }
    @Override
    public MesDvCheckRecordImportRespVO importCheckRecordList(List<MesDvCheckRecordImportExcelVO> importList, boolean updateSupport) {
        if (CollUtil.isEmpty(importList)) {
            throw exception(DV_CHECK_RECORD_IMPORT_LIST_IS_EMPTY);
        }
        MesDvCheckRecordImportRespVO respVO = MesDvCheckRecordImportRespVO.builder()
                .createCodes(new ArrayList<>()).updateCodes(new ArrayList<>())
                .failureCodes(new LinkedHashMap<>()).build();
        AtomicInteger index = new AtomicInteger(1);
        importList.forEach(importItem -> {
            int currentIndex = index.getAndIncrement();
            String key = "第 " + currentIndex + " 行";
            if (StrUtil.isBlank(importItem.getMachineryCode())) {
                respVO.getFailureCodes().put(key, "设备编码不能为空");
                return;
            }
            if (importItem.getCheckTime() == null) {
                respVO.getFailureCodes().put(key, "点检时间不能为空");
                return;
            }
            MesDvMachineryDO machinery = machineryMapper.selectByCode(importItem.getMachineryCode());
            if (machinery == null) {
                respVO.getFailureCodes().put(key, "设备不存在:" + importItem.getMachineryCode());
                return;
            }
            Long planId = null;
            if (StrUtil.isNotBlank(importItem.getPlanCode())) {
                MesDvCheckPlanDO plan = checkPlanMapper.selectByCode(importItem.getPlanCode());
                if (plan == null) {
                    respVO.getFailureCodes().put(key, "点检保养方案不存在:" + importItem.getPlanCode());
                    return;
                }
                planId = plan.getId();
            }
            try {
                MesDvCheckRecordSaveReqVO saveReqVO = BeanUtils.toBean(importItem, MesDvCheckRecordSaveReqVO.class);
                saveReqVO.setMachineryId(machinery.getId());
                saveReqVO.setPlanId(planId);
                Long id = createCheckRecord(saveReqVO);
                respVO.getCreateCodes().add(String.valueOf(id));
            } catch (ServiceException e) {
                respVO.getFailureCodes().put(key, e.getMessage());
            }
        });
        return respVO;
    }
}