/*
|
* 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.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.Wrappers;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.chinaztt.mes.quality.dto.PartsDTO;
|
import com.chinaztt.mes.quality.entity.*;
|
import com.chinaztt.mes.quality.mapper.*;
|
import com.chinaztt.mes.quality.service.PartsService;
|
import lombok.AllArgsConstructor;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
import java.util.List;
|
|
/**
|
* 零件检测
|
*
|
* @author liuth
|
* @date 2020-10-14 10:54:02
|
*/
|
@Service
|
@AllArgsConstructor
|
public class PartsServiceImpl extends ServiceImpl<PartsMapper, Parts> implements PartsService {
|
private RequirementsMapper requirementsMapper;
|
private ItemsMapper itemsMapper;
|
private TemplateMapper templateMapper;
|
private TaskMapper taskMapper;
|
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public boolean fullDelete(Long id) {
|
requirementsMapper.delete(Wrappers.<Requirements>lambdaQuery().eq(Requirements::getPartId,id));
|
baseMapper.delete(Wrappers.<Parts>lambdaQuery().eq(Parts::getPartId,id));
|
|
return true;
|
}
|
|
@Override
|
public PartsDTO getFullById(Long id) {
|
PartsDTO partsDTO = new PartsDTO();
|
//当不为空时获取零件检测信息
|
if (id != 0L) {
|
// 1.获取检测零件基本信息
|
partsDTO = baseMapper.selectDtoById(id);
|
|
//获取对应的检测模板信息
|
List<Template> templateList=templateMapper.selectList(Wrappers.<Template>lambdaQuery().eq(Template::getId, partsDTO.getTemplateId()));
|
if (CollectionUtil.isNotEmpty(templateList)) {
|
partsDTO.setTemplates(templateList);
|
}
|
|
}return partsDTO;
|
}
|
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public boolean fullSave(PartsDTO partsDTO) {
|
try {
|
baseMapper.insert(partsDTO);
|
if (CollectionUtil.isNotEmpty(partsDTO.getRequirements())) {
|
partsDTO.getRequirements().forEach(a -> {
|
a.setPartId(partsDTO.getPartId());
|
requirementsMapper.insert(a);
|
});
|
}
|
} catch (Exception e) {
|
log.error("创建检测要求失败", e);
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
return false;
|
}
|
return true;
|
}
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public boolean fullUpdate(PartsDTO partsDTO)
|
{
|
try {
|
//更新主表
|
baseMapper.delete(Wrappers.<Parts>lambdaQuery().eq(Parts::getPartId, partsDTO.getPartId()));
|
baseMapper.insert(partsDTO);
|
//删除原有检测要求信息
|
requirementsMapper.delete(Wrappers.<Requirements>lambdaQuery().eq(Requirements::getPartId, partsDTO.getPartId()));
|
//更新检验要求关系表
|
if (CollectionUtil.isNotEmpty(partsDTO.getRequirements())) {
|
partsDTO.getRequirements().forEach(r -> {
|
if (r.getId() == null || r.getId() == 0) {
|
r.setPartId(partsDTO.getPartId());
|
requirementsMapper.insert(r);
|
} else {
|
requirementsMapper.updateById(r);
|
}
|
|
});
|
}
|
} catch (Exception e) {
|
log.error("更新零件检测失败" , e);
|
throw new RuntimeException("更新检测要求失败");
|
}
|
return true;
|
}
|
|
@Override
|
public IPage<List<Parts>> getPartsPage(Page page, QueryWrapper<Parts> ew) {
|
return baseMapper.getPartsPage(page,ew);
|
}
|
|
@Override
|
public List<Items> selectItemsRequirementsByPartId(Long id) {
|
return itemsMapper.selectItemsRequirementsByPartId(id);
|
}
|
|
@Override
|
public Boolean getPartsJoinTemplateById(Long id) {
|
if (id != 0L) {
|
List<Parts> partsList=baseMapper.selectList(Wrappers.<Parts>lambdaQuery().eq(Parts::getPartId,id));
|
if(partsList.size()>0){
|
return false;
|
}
|
}
|
return true;
|
}
|
|
|
}
|