package com.jcdm.main.bs.formulaChild.service.impl; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.jcdm.common.core.domain.AjaxResult; import com.jcdm.common.utils.DateUtils; import com.jcdm.framework.websocket.WebSocketUsers; import com.jcdm.main.da.paramCollection.domain.DaParamCollection; import com.jcdm.main.da.paramCollection.mapper.DaParamCollectionMapper; import com.jcdm.main.da.paramCollection.service.IDaParamCollectionService; import com.jcdm.main.da.passingStationCollection.domain.DaPassingStationCollection; import com.jcdm.main.da.passingStationCollection.mapper.DaPassingStationCollectionMapper; import com.jcdm.main.da.testDeviceInterface.service.IDaTestDeviceInterfaceService; import com.jcdm.main.plcserver.util.TimeUtil; import com.kangaroohy.milo.model.ReadWriteEntity; import com.kangaroohy.milo.service.MiloService; import org.aspectj.weaver.loadtime.Aj; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.jcdm.main.bs.formulaChild.mapper.BsFormulaChildInfoMapper; import com.jcdm.main.bs.formulaChild.domain.BsFormulaChildInfo; import com.jcdm.main.bs.formulaChild.service.IBsFormulaChildInfoService; import javax.websocket.Session; /** * 配方配置子信息Service业务层处理 * * @author ruimin * @date 2023-12-26 */ @Service public class BsFormulaChildInfoServiceImpl extends ServiceImpl implements IBsFormulaChildInfoService { @Autowired private BsFormulaChildInfoMapper bsFormulaChildInfoMapper; @Autowired private IBsFormulaChildInfoService bsFormulaChildInfoService; @Autowired private DaParamCollectionMapper daParamCollectionMapper; @Autowired private MiloService miloService; @Autowired private DaPassingStationCollectionMapper daPassingStationCollectionMapper; @Autowired private IDaTestDeviceInterfaceService daTestDeviceInterfaceService; @Autowired private IDaParamCollectionService daParamCollectionService; Map map = WebSocketUsers.getUsers(); /** * 查询配方配置子信息 * * @param id 配方配置子信息主键 * @return 配方配置子信息 */ @Override public BsFormulaChildInfo selectBsFormulaChildInfoById(Long id) { return bsFormulaChildInfoMapper.selectBsFormulaChildInfoById(id); } /** * 查询配方配置子信息列表 * * @param bsFormulaChildInfo 配方配置子信息 * @return 配方配置子信息 */ @Override public List selectBsFormulaChildInfoList(BsFormulaChildInfo bsFormulaChildInfo) { return bsFormulaChildInfoMapper.selectBsFormulaChildInfoList(bsFormulaChildInfo); } /** * 新增配方配置子信息 * * @param bsFormulaChildInfo 配方配置子信息 * @return 结果 */ @Override public int insertBsFormulaChildInfo(BsFormulaChildInfo bsFormulaChildInfo) { bsFormulaChildInfo.setCreateTime(DateUtils.getNowDate()); return bsFormulaChildInfoMapper.insertBsFormulaChildInfo(bsFormulaChildInfo); } /** * 修改配方配置子信息 * * @param bsFormulaChildInfo 配方配置子信息 * @return 结果 */ @Override public int updateBsFormulaChildInfo(BsFormulaChildInfo bsFormulaChildInfo) { bsFormulaChildInfo.setUpdateTime(DateUtils.getNowDate()); return bsFormulaChildInfoMapper.updateBsFormulaChildInfo(bsFormulaChildInfo); } /** * 批量删除配方配置子信息 * * @param ids 需要删除的配方配置子信息主键 * @return 结果 */ @Override public int deleteBsFormulaChildInfoByIds(Long[] ids) { return bsFormulaChildInfoMapper.deleteBsFormulaChildInfoByIds(ids); } /** * 删除配方配置子信息信息 * * @param id 配方配置子信息主键 * @return 结果 */ @Override public int deleteBsFormulaChildInfoById(Long id) { return bsFormulaChildInfoMapper.deleteBsFormulaChildInfoById(id); } @Override public BsFormulaChildInfo selectBsFormulaChildInfoByTypeTopOne(String type,String productCode,String processesCode) { BsFormulaChildInfo info = new BsFormulaChildInfo(); info.setOperationType(type); info.setProcessesCode(processesCode); info.setProductCode(productCode); return bsFormulaChildInfoMapper.selectBsFormulaChildInfoByTypeTopOne(info); } @Override public BsFormulaChildInfo getCount(String productCode, String processesCode) { BsFormulaChildInfo info = new BsFormulaChildInfo(); info.setProcessesCode(processesCode); info.setProductCode(productCode); return bsFormulaChildInfoMapper.getCount(info); } @Override public AjaxResult yzUpdateResults(BsFormulaChildInfo bsFormulaChildInfo) { String result = ""; List bsFormulaChildInfos = new ArrayList<>(); List infos = bsFormulaChildInfoService.list(new LambdaQueryWrapper() .eq(BsFormulaChildInfo::getProcessesCode, bsFormulaChildInfo.getLocationCode()) .eq(BsFormulaChildInfo::getProductCode, bsFormulaChildInfo.getProductCode()) .eq(BsFormulaChildInfo::getOperationType, "2") ); for (BsFormulaChildInfo formulaChildInfo : infos) { if(bsFormulaChildInfo.getScanBarcode().contains(formulaChildInfo.getMaterialCode())){ bsFormulaChildInfos.add(formulaChildInfo); break; } } if(bsFormulaChildInfos.size()>0){ String spareField4 = bsFormulaChildInfos.get(0).getSpareField4(); bsFormulaChildInfos.get(0).setCollectData(bsFormulaChildInfo.getScanBarcode()); bsFormulaChildInfos.get(0).setResults("OK"); bsFormulaChildInfoMapper.updateBsFormulaChildInfo(bsFormulaChildInfos.get(0)); bsFormulaChildInfo.setParamValue(bsFormulaChildInfo.getScanBarcode()); bsFormulaChildInfo.setParamCode(bsFormulaChildInfos.get(0).getParamCode()); bsFormulaChildInfo.setSfcBarcode(bsFormulaChildInfo.getSfcBarcode()); addParameterCollection(bsFormulaChildInfo); if (spareField4 != null && !spareField4.isEmpty()) { // 执行操作 if(bsFormulaChildInfos.get(0).getSpareField4().equals("1")){ try { result = "3"; } catch (Exception e) { throw new RuntimeException(e); } } } }else { result = "1"; } return AjaxResult.success(result); } @Override public AjaxResult yzUpdateTighteningFormula(BsFormulaChildInfo bsFormulaChildInfo) { Boolean b = true; String result = "1"; BsFormulaChildInfo getMaterTwo = new BsFormulaChildInfo(); getMaterTwo.setProcessesCode(bsFormulaChildInfo.getLocationCode()); getMaterTwo.setOperationType("2"); List operationType = bsFormulaChildInfoMapper.selectBsFormulaChildInfoList(getMaterTwo); List collect = operationType.stream().map(BsFormulaChildInfo::getResults).collect(Collectors.toList()); for (String s : collect) { if(s.equals("")){ // return AjaxResult.success("扫描未完成,禁止拧紧操作!"); } } BsFormulaChildInfo listQuery = new BsFormulaChildInfo(); listQuery.setParamCode(bsFormulaChildInfo.getParamCode()); String paramCode = bsFormulaChildInfo.getTightenTheArray(); if(paramCode.contains("N")){ result = "3"; List bsFormulaChildInfos = bsFormulaChildInfoMapper.selectBsFormulaChildInfoList(listQuery); bsFormulaChildInfos.get(0).setResults("NG"); bsFormulaChildInfos.get(0).setCollectData(bsFormulaChildInfo.getTightenTheArray()); bsFormulaChildInfoMapper.updateBsFormulaChildInfo(bsFormulaChildInfos.get(0)); // return AjaxResult.success("扫描结果NG,请重新扫描!"); }else { List bsFormulaChildInfos = bsFormulaChildInfoMapper.selectBsFormulaChildInfoList(listQuery); if(bsFormulaChildInfos.get(0).getSpareField2()!=null&&bsFormulaChildInfos.get(0).getSpareField3()!=null){ String tightenArray = bsFormulaChildInfo.getTightenTheArray().replace("[", "").replace("]", "").replace(" ", ""); String[] tightenDataParts = tightenArray.split(","); b = TimeUtil.isNumberInRange(Double.parseDouble(tightenDataParts[0]),Double.parseDouble(bsFormulaChildInfos.get(0).getSpareField2()),Double.parseDouble(bsFormulaChildInfos.get(0).getSpareField3())); } if(b){ result = "3"; bsFormulaChildInfos.get(0).setResults("OK"); bsFormulaChildInfos.get(0).setCollectData(bsFormulaChildInfo.getTightenTheArray()); bsFormulaChildInfoMapper.updateBsFormulaChildInfo(bsFormulaChildInfos.get(0)); Integer stepNumber = Integer.valueOf(bsFormulaChildInfos.get(0).getStepSort()); try { miloService.writeToOpcShort(ReadWriteEntity.builder().identifier("PACK."+bsFormulaChildInfo.getLocationCode()+".MStepNumber").value(stepNumber+1).build()); } catch (Exception e) { throw new RuntimeException(e); } String spareField4 = bsFormulaChildInfos.get(0).getSpareField4(); if (spareField4 != null && !spareField4.isEmpty()) { // 执行操作 if(bsFormulaChildInfos.get(0).getSpareField4().equals("1")){ try { // WebSocketUsers.sendMessageToUserByText(map.get(bsFormulaChildInfo.getLocationCode()), "OUT"); result = "2"; } catch (Exception e) { throw new RuntimeException(e); } } } }else { result = "3"; List bsFormulaChildInfos1 = bsFormulaChildInfoMapper.selectBsFormulaChildInfoList(listQuery); bsFormulaChildInfos1.get(0).setResults("NG"); String originalString = bsFormulaChildInfo.getTightenTheArray(); String modifiedString = originalString.replaceFirst("OK", "NG"); bsFormulaChildInfos1.get(0).setCollectData(modifiedString); bsFormulaChildInfoMapper.updateBsFormulaChildInfo(bsFormulaChildInfos1.get(0)); // return AjaxResult.success("扫描结果NG,请重新扫描!"); } } return AjaxResult.success(result); } @Override public AjaxResult jrmUpdateResults(BsFormulaChildInfo bsFormulaChildInfo) { String result = ""; List bsFormulaChildInfos = new ArrayList<>(); List infos = bsFormulaChildInfoService.list(new LambdaQueryWrapper() .eq(BsFormulaChildInfo::getProcessesCode, bsFormulaChildInfo.getLocationCode()) .eq(BsFormulaChildInfo::getProductCode, bsFormulaChildInfo.getProductCode()) .eq(BsFormulaChildInfo::getOperationType, "2") ).stream().filter(x -> StrUtil.isBlank(x.getCollectData())).collect(Collectors.toList()); for (BsFormulaChildInfo formulaChildInfo : infos) { if(bsFormulaChildInfo.getScanBarcode().contains(formulaChildInfo.getMaterialCode())){ bsFormulaChildInfos.add(formulaChildInfo); break; } } if(bsFormulaChildInfos.size()>0){ String spareField4 = bsFormulaChildInfos.get(0).getSpareField4(); bsFormulaChildInfos.get(0).setCollectData(bsFormulaChildInfo.getScanBarcode()); bsFormulaChildInfos.get(0).setResults("OK"); bsFormulaChildInfoMapper.updateBsFormulaChildInfo(bsFormulaChildInfos.get(0)); bsFormulaChildInfo.setParamValue(bsFormulaChildInfo.getScanBarcode()); bsFormulaChildInfo.setParamCode(bsFormulaChildInfos.get(0).getParamCode()); bsFormulaChildInfo.setSfcBarcode(bsFormulaChildInfo.getSfcBarcode()); jrmAddParameterCollection(bsFormulaChildInfo); if (spareField4 != null && !spareField4.isEmpty()) { // 执行操作 if(bsFormulaChildInfos.get(0).getSpareField4().equals("1")){ try { result = "3"; // String strA = bsFormulaChildInfo.getLocationCode() + "A"; // String strB = bsFormulaChildInfo.getLocationCode() + "B"; // miloService.writeToOpcShort(ReadWriteEntity.builder().identifier("PACK."+strA+".RecordDataDone").value(21).build()); // miloService.writeToOpcShort(ReadWriteEntity.builder().identifier("PACK."+strB+".RecordDataDone").value(21).build()); String locationCode = bsFormulaChildInfo.getLocationCode(); miloService.writeToOpcShort(ReadWriteEntity.builder().identifier("PACK."+locationCode+".RecordDataDone").value(21).build()); } catch (Exception e) { throw new RuntimeException(e); } } } }else { result = "1"; } return AjaxResult.success(result); } @Override public BsFormulaChildInfo releaseCheck(BsFormulaChildInfo bsFormulaChildInfo) { return bsFormulaChildInfoMapper.releaseCheck(bsFormulaChildInfo); } //1-非本工位物料 2-正常扫描可继续下次 3-扫描结束已经是最后一位工步 @Override public AjaxResult updateResults(BsFormulaChildInfo bsFormulaChildInfo) { String result = ""; List bsFormulaChildInfos = new ArrayList<>(); List infos = bsFormulaChildInfoService.list(new LambdaQueryWrapper() .eq(BsFormulaChildInfo::getProcessesCode, bsFormulaChildInfo.getLocationCode()) .eq(BsFormulaChildInfo::getProductCode, bsFormulaChildInfo.getProductCode()) .eq(BsFormulaChildInfo::getOperationType, "2") ); for (BsFormulaChildInfo formulaChildInfo : infos) { if(bsFormulaChildInfo.getScanBarcode().contains(formulaChildInfo.getMaterialCode())){ bsFormulaChildInfos.add(formulaChildInfo); break; } } if(bsFormulaChildInfos.size()>0){ String spareField4 = bsFormulaChildInfos.get(0).getSpareField4(); bsFormulaChildInfos.get(0).setCollectData(bsFormulaChildInfo.getScanBarcode()); bsFormulaChildInfos.get(0).setResults("OK"); bsFormulaChildInfoMapper.updateBsFormulaChildInfo(bsFormulaChildInfos.get(0)); bsFormulaChildInfo.setParamValue(bsFormulaChildInfo.getScanBarcode()); bsFormulaChildInfo.setParamCode(bsFormulaChildInfos.get(0).getParamCode()); bsFormulaChildInfo.setSfcBarcode(bsFormulaChildInfo.getSfcBarcode()); addParameterCollection(bsFormulaChildInfo); // Integer stepNumber = Integer.valueOf(bsFormulaChildInfos.get(0).getStepSort()); // try { // miloService.writeToOpcShort(ReadWriteEntity.builder().identifier("PACK."+bsFormulaChildInfo.getLocationCode()+".StepNumber").value(stepNumber).build()); // } catch (Exception e) { // throw new RuntimeException(e); // } if (spareField4 != null && !spareField4.isEmpty()) { // 执行操作 if(bsFormulaChildInfos.get(0).getSpareField4().equals("1")){ try { result = "3"; miloService.writeToOpcShort(ReadWriteEntity.builder().identifier("PACK."+bsFormulaChildInfo.getLocationCode()+".RecordDataDone").value(21).build()); } catch (Exception e) { throw new RuntimeException(e); } } } }else { result = "1"; } return AjaxResult.success(result); } public void addParameterCollection(BsFormulaChildInfo bsFormulaChildInfo){ DaParamCollection daParamCollection = new DaParamCollection(); daParamCollection.setParamCode(bsFormulaChildInfo.getParamCode()); daParamCollection.setWorkOrderNo(bsFormulaChildInfo.getWorkOrderNo()); daParamCollection.setLocationCode(bsFormulaChildInfo.getLocationCode()); daParamCollection.setParamValue(bsFormulaChildInfo.getParamValue()); daParamCollection.setProductCode(bsFormulaChildInfo.getProductCode()); daParamCollection.setCollectionTime(new Date()); daParamCollection.setSfcCode(bsFormulaChildInfo.getSfcBarcode()); daParamCollectionMapper.insertDaParamCollection(daParamCollection); } public void jrmAddParameterCollection(BsFormulaChildInfo bsFormulaChildInfo){ String scanBarCode = bsFormulaChildInfo.getSfcBarcode(); String[] modeleSplit = scanBarCode.split(","); // for (String modele : modeleSplit) { DaParamCollection daParamCollection = new DaParamCollection(); daParamCollection.setParamCode(bsFormulaChildInfo.getParamCode()); daParamCollection.setWorkOrderNo(bsFormulaChildInfo.getWorkOrderNo()); daParamCollection.setLocationCode(bsFormulaChildInfo.getLocationCode()); daParamCollection.setParamValue(bsFormulaChildInfo.getParamValue()); daParamCollection.setProductCode(bsFormulaChildInfo.getProductCode()); daParamCollection.setCollectionTime(new Date()); if(bsFormulaChildInfo.getParamCode().contains("B")){ daParamCollection.setSfcCode(modeleSplit[1]); }else { daParamCollection.setSfcCode(modeleSplit[0]); } // daParamCollection.setSfcCode(modele); daParamCollectionMapper.insertDaParamCollection(daParamCollection); // } } @Override public AjaxResult workpieceRelease(BsFormulaChildInfo bsFormulaChildInfo) { try { daParamCollectionService.pushGeelycvMesFeedback(bsFormulaChildInfo.getProductBarcode(), bsFormulaChildInfo.getLocationCode()); }catch (Exception e){ } List list = bsFormulaChildInfoService.list(new LambdaQueryWrapper() .eq(BsFormulaChildInfo::getProcessesCode, bsFormulaChildInfo.getLocationCode()) .eq(BsFormulaChildInfo::getProductCode, bsFormulaChildInfo.getProductCode())); for (BsFormulaChildInfo info : list) { info.setCollectData(""); info.setResults(""); bsFormulaChildInfoService.saveOrUpdate(info); } return AjaxResult.success(); } @Override public AjaxResult updateTighteningFormula(BsFormulaChildInfo bsFormulaChildInfo) { Boolean b = true; BsFormulaChildInfo getMaterTwo = new BsFormulaChildInfo(); getMaterTwo.setProcessesCode(bsFormulaChildInfo.getLocationCode()); getMaterTwo.setOperationType("2"); List operationType = bsFormulaChildInfoMapper.selectBsFormulaChildInfoList(getMaterTwo); List collect = operationType.stream().map(BsFormulaChildInfo::getResults).collect(Collectors.toList()); for (String s : collect) { if(s.equals("")){ return AjaxResult.error("扫描未完成,禁止拧紧操作!"); } } BsFormulaChildInfo listQuery = new BsFormulaChildInfo(); listQuery.setParamCode(bsFormulaChildInfo.getParamCode()); String paramCode = bsFormulaChildInfo.getTightenTheArray(); if(paramCode.contains("N")){ List bsFormulaChildInfos = bsFormulaChildInfoMapper.selectBsFormulaChildInfoList(listQuery); bsFormulaChildInfos.get(0).setResults("NG"); bsFormulaChildInfos.get(0).setCollectData(bsFormulaChildInfo.getTightenTheArray()); bsFormulaChildInfoMapper.updateBsFormulaChildInfo(bsFormulaChildInfos.get(0)); return AjaxResult.error("扫描结果NG,请重新扫描!"); }else { List bsFormulaChildInfos = bsFormulaChildInfoMapper.selectBsFormulaChildInfoList(listQuery); if(bsFormulaChildInfos.get(0).getSpareField2()!=null&&bsFormulaChildInfos.get(0).getSpareField3()!=null){ String tightenArray = bsFormulaChildInfo.getTightenTheArray().replace("[", "").replace("]", "").replace(" ", ""); String[] tightenDataParts = tightenArray.split(","); b = TimeUtil.isNumberInRange(Double.parseDouble(tightenDataParts[0]),Double.parseDouble(bsFormulaChildInfos.get(0).getSpareField2()),Double.parseDouble(bsFormulaChildInfos.get(0).getSpareField3())); } if(b){ bsFormulaChildInfos.get(0).setResults("OK"); bsFormulaChildInfos.get(0).setCollectData(bsFormulaChildInfo.getTightenTheArray()); bsFormulaChildInfoMapper.updateBsFormulaChildInfo(bsFormulaChildInfos.get(0)); Integer stepNumber = Integer.valueOf(bsFormulaChildInfos.get(0).getStepSort()); try { miloService.writeToOpcShort(ReadWriteEntity.builder().identifier("PACK."+bsFormulaChildInfo.getLocationCode()+".MStepNumber").value(stepNumber+1).build()); } catch (Exception e) { throw new RuntimeException(e); } String spareField4 = bsFormulaChildInfos.get(0).getSpareField4(); if (spareField4 != null && !spareField4.isEmpty()) { // 执行操作 if(bsFormulaChildInfos.get(0).getSpareField4().equals("1")){ try { // //更新过站记录表出站时间 // DaPassingStationCollection daPassingStationCollection = new DaPassingStationCollection(); // daPassingStationCollection.setWorkOrderNo(bsFormulaChildInfo.getWorkOrderNo()); // List daPassingStationCollections = daPassingStationCollectionMapper.selectDaPassingStationCollectionList(daPassingStationCollection); // daPassingStationCollections.get(0).setOutboundTime(new Date()); // daPassingStationCollectionMapper.updateDaPassingStationCollection(daPassingStationCollections.get(0)); miloService.writeToOpcShort(ReadWriteEntity.builder().identifier("PACK."+bsFormulaChildInfo.getLocationCode()+".RecordDataDone").value(21).build()); WebSocketUsers.sendMessageToUserByText(map.get(bsFormulaChildInfo.getLocationCode()), "OUT"); } catch (Exception e) { throw new RuntimeException(e); } } } }else { List bsFormulaChildInfos1 = bsFormulaChildInfoMapper.selectBsFormulaChildInfoList(listQuery); bsFormulaChildInfos1.get(0).setResults("NG"); String originalString = bsFormulaChildInfo.getTightenTheArray(); String modifiedString = originalString.replaceFirst("OK", "NG"); bsFormulaChildInfos1.get(0).setCollectData(modifiedString); bsFormulaChildInfoMapper.updateBsFormulaChildInfo(bsFormulaChildInfos1.get(0)); return AjaxResult.error("扫描结果NG,请重新扫描!"); } } return AjaxResult.success("扫描成功!"); } }