/* * Copyright (c) 2018-2025, ztt All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * Neither the name of the pig4cloud.com developer nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * Author: ztt */ package com.chinaztt.mes.quality.service.impl; import cn.hutool.core.collection.CollectionUtil; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.chinaztt.mes.basic.entity.Part; import com.chinaztt.mes.basic.mapper.PartMapper; import com.chinaztt.mes.common.numgen.NumberGenerator; import com.chinaztt.mes.quality.dto.ReportDTO; import com.chinaztt.mes.quality.dto.ReportItemsDTO; import com.chinaztt.mes.quality.entity.*; import com.chinaztt.mes.quality.mapper.*; import com.chinaztt.mes.quality.service.TestReportService; import com.chinaztt.ztt.common.security.service.ZttUser; import com.chinaztt.ztt.common.security.util.SecurityUtils; import lombok.AllArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.interceptor.TransactionAspectSupport; import java.time.LocalDateTime; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; /** * 检测汇报 * * @author liuth * @date 2020-10-21 09:04:30 */ @Service @AllArgsConstructor public class TestReportServiceImpl extends ServiceImpl implements TestReportService { public static final Pattern QUOTATION_MARK_PATTERN = Pattern.compile("\"(.*?)\""); private NumberGenerator numberGenerator; private ReportItemsMapper reportItemsMapper; private TaskMapper taskMapper; private TemplateMapper templateMapper; private ItemsMapper itemsMapper; private PartMapper partMapper; private TestReportProcessingMapper testReportProcessingMapper; /** * 关联删除 * * @param id */ @Override @Transactional(rollbackFor = Exception.class) public boolean fullDelete(Long id) { baseMapper.deleteById(id); //删除检测汇报对应的检测项信息 reportItemsMapper.delete(Wrappers.lambdaQuery().eq(ReportItems::getTestReportId, id)); return true; } @Override @Transactional(rollbackFor = Exception.class) public boolean fullSave(ReportDTO reportDTO) { try { ZttUser currentUser = SecurityUtils.getUser(); reportDTO.setTestUser(currentUser.getUsername()); reportDTO.setOrderNo(numberGenerator.generateNumberWithPrefix(TestReport.DIGIT, TestReport.PREFIX, TestReport::getOrderNo)); reportDTO.setTestTime(LocalDateTime.now()); baseMapper.insert(reportDTO); if (CollectionUtil.isNotEmpty(reportDTO.getReportItems())) { System.out.println(reportDTO.getReportItems()); reportDTO.getReportItems().forEach(a -> { a.setTestReportId(reportDTO.getId()); reportItemsMapper.insert(a); }); } } catch (Exception e) { log.error("创建检测汇报失败", e); TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); return false; } return true; } @Override public ReportDTO getFullById(Long id) { ReportDTO reportDTO = new ReportDTO(); //当不为空时获取零件检测信息 if (id != 0L) { // 1.获取检测汇报基本信息 reportDTO = baseMapper.selectDtoById(id); //获取相关汇报检测项信息 List reportItemsList = reportItemsMapper.selectList(Wrappers.lambdaQuery().eq(ReportItems::getTestReportId, reportDTO.getId())); if (CollectionUtil.isNotEmpty(reportItemsList)) { reportDTO.setReportItems(reportItemsList); } //2.获取相关待检测任务信息 List taskList = taskMapper.selectList(Wrappers.lambdaQuery().eq(Task::getId, reportDTO.getTestTaskId())); if (CollectionUtil.isNotEmpty(taskList)) { reportDTO.setTasks(taskList); } // 3.获取相关检测模板信息 List