package org.jeecg.modules.dnc.service.impl;
|
|
import com.alibaba.fastjson.JSONObject;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import org.jeecg.modules.dnc.exception.ExceptionCast;
|
import org.jeecg.modules.dnc.mapper.ProcessStreamMapper;
|
import org.jeecg.modules.dnc.response.CommonCode;
|
import org.jeecg.modules.dnc.response.ComponentInfoCode;
|
import org.jeecg.modules.dnc.response.DeviceCode;
|
import org.jeecg.modules.dnc.response.ProcessInfoCode;
|
|
import org.jeecg.modules.dnc.service.*;
|
import org.jeecg.modules.dnc.utils.ValidateUtil;
|
|
|
import org.jeecg.modules.dnc.request.ProcessStreamRequest;
|
import org.jeecg.modules.dnc.entity.*;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.context.annotation.Lazy;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import java.util.Collections;
|
import java.util.List;
|
|
@Service
|
public class ProcessStreamServiceImpl extends ServiceImpl<ProcessStreamMapper, ProcessStream> implements IProcessStreamService {
|
@Autowired
|
@Lazy
|
private IComponentInfoService componentInfoService;
|
@Autowired
|
private IProcessInfoService processInfoService;
|
@Autowired
|
private IPartsInfoService partsInfoService;
|
@Autowired
|
private IDocInfoService docInfoService;
|
@Autowired
|
@Lazy
|
private IDeviceInfoService deviceInfoService;
|
@Autowired
|
private INcLogInfoService iNcLogInfoService;
|
|
@Override
|
@Transactional(rollbackFor = {Exception.class})
|
public boolean addProcessStream(ProcessStream stream) {
|
if(stream == null)
|
ExceptionCast.cast(CommonCode.INVALID_PARAM);
|
if(!ValidateUtil.validateString(stream.getProductId()))
|
ExceptionCast.cast(ProcessInfoCode.PROCESS_PRODUCT_NONE);
|
if(!ValidateUtil.validateString(stream.getComponentId()))
|
ExceptionCast.cast(ProcessInfoCode.PROCESS_COMPONENT_NONE);
|
if(!ValidateUtil.validateString(stream.getProcessName()))
|
ExceptionCast.cast(ProcessInfoCode.PROCESS_NAME_NONE);
|
if(!ValidateUtil.validateString(stream.getProcessCode()))
|
ExceptionCast.cast(ProcessInfoCode.PROCESS_CODE_NONE);
|
if(ValidateUtil.validateString(stream.getPartsId())) {
|
PartsInfo partsInfo = partsInfoService.getById(stream.getPartsId());
|
if(partsInfo == null)
|
ExceptionCast.cast(ProcessInfoCode.PROCESS_PARTS_NONE);
|
if(!stream.getProductId().equals(partsInfo.getProductId()))
|
ExceptionCast.cast(ProcessInfoCode.PROCESS_PRODUCT_NONE);
|
if(!stream.getComponentId().equals(partsInfo.getComponentId()))
|
ExceptionCast.cast(ProcessInfoCode.PROCESS_COMPONENT_NONE);
|
ProcessStream en = findByProcessNoAndPartsId(stream.getProcessCode(), partsInfo.getPartsId());
|
if(en != null) {
|
ExceptionCast.cast(ProcessInfoCode.PROCESS_IS_EXIST);
|
}
|
}else {
|
ComponentInfo componentInfo = componentInfoService.getById(stream.getComponentId());
|
if(componentInfo == null)
|
ExceptionCast.cast(ProcessInfoCode.PROCESS_COMPONENT_NONE);
|
if(!stream.getProductId().equals(componentInfo.getProductId()))
|
ExceptionCast.cast(ProcessInfoCode.PROCESS_PRODUCT_NONE);
|
stream.setPartsId(null);
|
ProcessStream en = findByProcessNoAndComponentId(stream.getProcessCode(), componentInfo.getComponentId());
|
if(en != null) {
|
ExceptionCast.cast(ProcessInfoCode.PROCESS_IS_EXIST);
|
}
|
}
|
//添加日志
|
NcLogInfo ncLogInfo = new NcLogInfo();
|
//模块
|
ncLogInfo.setModuleInfo("产品结构树");
|
//类型
|
ncLogInfo.setOperateType(2);
|
//日志内容
|
ncLogInfo.setLogContent("工序名称:"+stream.getProcessName()+",工序号:"+stream.getProcessCode());
|
iNcLogInfoService.saveLogNcInfos(ncLogInfo);
|
boolean b = super.save(stream);
|
if(!b)
|
ExceptionCast.cast(CommonCode.FAIL);
|
ProcessInfo processInfo = new ProcessInfo();
|
processInfo.setProcessName(stream.getProcessName());
|
processInfo.setDescription(stream.getDescription());
|
return processInfoService.addOrEdit(processInfo);
|
}
|
|
@Override
|
@Transactional(rollbackFor = {Exception.class})
|
public boolean editProcessStream(String id, ProcessStream stream) {
|
if(!ValidateUtil.validateString(id) || stream == null)
|
ExceptionCast.cast(CommonCode.INVALID_PARAM);
|
if(!ValidateUtil.validateString(stream.getProcessName()))
|
ExceptionCast.cast(ProcessInfoCode.PROCESS_NAME_NONE);
|
ProcessStream en = super.getById(id);
|
if(en == null)
|
ExceptionCast.cast(ProcessInfoCode.PROCESS_NOT_EXIST);
|
stream.setProcessId(id);
|
stream.setProductId(null);
|
stream.setComponentId(null);
|
stream.setPartsId(null);
|
stream.setProcessName(stream.getProcessName().toUpperCase());
|
stream.setProcessCode(null);
|
//添加日志
|
NcLogInfo ncLogInfo = new NcLogInfo();
|
//模块
|
ncLogInfo.setModuleInfo("产品结构树");
|
//类型
|
ncLogInfo.setOperateType(3);
|
//日志内容
|
ncLogInfo.setLogContent("工序号:"+en.getProcessCode());
|
ncLogInfo.setRemark(JSONObject.toJSONString(en));
|
iNcLogInfoService.saveLogNcInfos(ncLogInfo);
|
boolean b = super.updateById(stream);
|
if(!b)
|
ExceptionCast.cast(CommonCode.FAIL);
|
ProcessInfo processInfo = new ProcessInfo();
|
processInfo.setProcessName(stream.getProcessName());
|
processInfo.setDescription(stream.getDescription());
|
return processInfoService.addOrEdit(processInfo);
|
}
|
|
@Override
|
@Transactional(rollbackFor = {Exception.class})
|
public boolean deleteProcessStream(String id) {
|
if(!ValidateUtil.validateString(id))
|
ExceptionCast.cast(CommonCode.INVALID_PARAM);
|
ProcessStream en = super.getById(id);
|
if(en == null)
|
ExceptionCast.cast(ProcessInfoCode.PROCESS_NOT_EXIST);
|
boolean b = docInfoService.deleteByProcessId(en.getProcessId());
|
if(!b)
|
ExceptionCast.cast(CommonCode.FAIL);
|
//添加日志
|
NcLogInfo ncLogInfo = new NcLogInfo();
|
//模块
|
ncLogInfo.setModuleInfo("产品结构树");
|
//类型
|
ncLogInfo.setOperateType(4);
|
//日志内容
|
ncLogInfo.setLogContent("工序号:"+en.getProcessCode());
|
iNcLogInfoService.saveLogNcInfos(ncLogInfo);
|
return super.removeById(id);
|
}
|
|
@Override
|
public List<ProcessStream> findByNodeParams(ProcessStreamRequest request) {
|
if(request == null || !ValidateUtil.validateString(request.getProductId()) || !ValidateUtil.validateString(request.getComponentId()))
|
return Collections.emptyList();
|
LambdaQueryChainWrapper<ProcessStream> lambdaQuery = super.lambdaQuery().eq(ProcessStream::getProductId, request.getProductId()).eq(ProcessStream::getComponentId, request.getComponentId());
|
if(ValidateUtil.validateString(request.getPartsId())) {
|
lambdaQuery.eq(ProcessStream::getPartsId, request.getPartsId());
|
}else {
|
lambdaQuery.isNull(ProcessStream::getPartsId);
|
}
|
return lambdaQuery.list();
|
}
|
|
@Override
|
public List<ProcessStream> findByProductId(String productId) {
|
return super.lambdaQuery().eq(ProcessStream::getProductId, productId).list();
|
}
|
|
@Override
|
public List<ProcessStream> findByComponentId(String componentId) {
|
return super.lambdaQuery().eq(ProcessStream::getComponentId, componentId).list();
|
}
|
|
@Override
|
public List<ProcessStream> findByPartsId(String partsId) {
|
return super.lambdaQuery().eq(ProcessStream::getPartsId, partsId).list();
|
}
|
|
@Override
|
public ProcessStream findByProcessNoAndPartsId(String processNo, String partsId) {
|
List<ProcessStream> list = super.lambdaQuery().eq(ProcessStream::getPartsId, partsId).eq(ProcessStream::getProcessCode, processNo).list();
|
if(list == null || list.isEmpty())
|
return null;
|
return list.get(0);
|
}
|
|
@Override
|
public ProcessStream findByProcessNoAndComponentId(String processNo, String componentId) {
|
List<ProcessStream> list = super.lambdaQuery().eq(ProcessStream::getComponentId, componentId).eq(ProcessStream::getProcessCode, processNo).list();
|
if(list == null || list.isEmpty())
|
return null;
|
return list.get(0);
|
}
|
|
@Override
|
public List<ProcessStream> validateDeviceProcessInfo(String pnCode, String deviceNo) {
|
if(!ValidateUtil.validateString(pnCode) || !ValidateUtil.validateString(deviceNo))
|
ExceptionCast.cast(CommonCode.INVALID_PARAM);
|
DeviceInfo deviceInfo = deviceInfoService.getByDeviceNo(deviceNo);
|
if(deviceInfo == null)
|
ExceptionCast.cast(DeviceCode.DEVICE_NOT_EXIST);
|
PermissionStream stream = componentInfoService.validateComponentOrPartsPnCode(pnCode);
|
if(stream == null)
|
ExceptionCast.cast(ComponentInfoCode.COMPONENT_PN_NOT_EXIST);
|
LambdaQueryWrapper<ProcessStream> lambdaQueryWrapper = Wrappers.lambdaQuery();
|
lambdaQueryWrapper.eq(ProcessStream::getProductId, stream.getProductId());
|
lambdaQueryWrapper.eq(ProcessStream::getComponentId, stream.getComponentId());
|
if(ValidateUtil.validateString(stream.getPartsId())) {
|
lambdaQueryWrapper.eq(ProcessStream::getPartsId, stream.getPartsId());
|
}
|
lambdaQueryWrapper.like(ProcessStream::getProcessingEquipmentCode, deviceNo);
|
List<ProcessStream> list = super.list(lambdaQueryWrapper);
|
if(list == null || list.isEmpty())
|
ExceptionCast.cast(ProcessInfoCode.PROCESS_NOT_EXIST);
|
return list;
|
}
|
}
|