-
admin
2024-05-08 4a5f2a21686b42761cccb4c64a6fcaaf778f071a
jcdm-main/src/main/java/com/jcdm/main/da/paramCollection/service/impl/DaParamCollectionServiceImpl.java
@@ -1,10 +1,15 @@
package com.jcdm.main.da.paramCollection.service.impl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.db.Db;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jcdm.common.utils.DateUtils;
import com.jcdm.main.bs.formula.service.IBsFormulaInfoService;
import com.jcdm.main.bs.formula.service.impl.BsFormulaInfoServiceImpl;
import com.jcdm.main.bs.formulaChild.domain.BsFormulaChildInfo;
import com.jcdm.main.bs.formulaChild.mapper.BsFormulaChildInfoMapper;
import com.jcdm.main.bs.formulaChild.service.IBsFormulaChildInfoService;
import com.jcdm.main.da.collectionParamConf.domain.DaCollectionParamConf;
import com.jcdm.main.da.collectionParamConf.mapper.DaCollectionParamConfMapper;
import com.jcdm.main.da.paramCollection.domain.DaParamCollection;
@@ -44,6 +49,9 @@
    private BsFormulaChildInfoMapper bsFormulaChildInfoMapper;
    @Autowired
    private IBsFormulaChildInfoService bsFormulaChildInfoService;
    @Autowired
    private MiloService miloService;
    @Autowired
@@ -51,6 +59,9 @@
    @Resource
    private SqlSessionFactory sqlSessionFactory;
    @Autowired
    private IDaParamCollectionService daParamCollectionService;
    /**
     * 查询设备产品过程参数采集
@@ -195,6 +206,18 @@
    @Override
    public void saveCampaignTimeParameters(DaParamCollection daParamCollection) {
        List<BsFormulaChildInfo> list = bsFormulaChildInfoService.list(new LambdaQueryWrapper<BsFormulaChildInfo>()
                .eq(BsFormulaChildInfo::getProcessesCode, daParamCollection.getLocationCode())
                .eq(BsFormulaChildInfo::getSpareField4, "1")
        );
        if(!list.get(0).getResults().equals("OK")){
            try {
                miloService.writeToOpcShort(ReadWriteEntity.builder().identifier("PACK."+daParamCollection.getLocationCode()+".RecordDataDone").value(22).build());
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
            return;
        }
        BsFormulaChildInfo bsFormulaChildInfo = new BsFormulaChildInfo();
        bsFormulaChildInfo.setProcessesCode(daParamCollection.getLocationCode());
        bsFormulaChildInfo.setProductCode(daParamCollection.getProductCode());
@@ -227,13 +250,67 @@
                daPassingStationCollections.get(0).setOutboundTime(new Date());
                int i = daPassingStationCollectionMapper.updateDaPassingStationCollection(daPassingStationCollections.get(0));
                OPCUaSubscription.SaveParamData(daParamCollection.getProductBarcode(),"OP",daParamCollection.getLocationCode(),daParamCollection.getWorkOrderNo(),daParamCollection.getProductCode());
//                OPCUaSubscription.SaveParamData(daParamCollection.getProductBarcode(),"OP",daParamCollection.getLocationCode(),daParamCollection.getWorkOrderNo(),daParamCollection.getProductCode());
                //给opc发21
                miloService.writeToOpcShort(ReadWriteEntity.builder().identifier("OP."+daParamCollection.getLocationCode()+".RecordDataDone").value(21).build());
                miloService.writeToOpcShort(ReadWriteEntity.builder().identifier("PACK."+daParamCollection.getLocationCode()+".RecordDataDone").value(21).build());
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    }
    @Override
    public void insertBatch(List<DaParamCollection> confList){
        try{
            this.saveBatch(confList);
        }catch (Exception e){
            return;
        }
    }
    @Override
    public void replaceAssemblyCode(DaParamCollection daParamCollection) {
        List<DaParamCollection> list = daParamCollectionService.list(new LambdaQueryWrapper<DaParamCollection>()
                .eq(DaParamCollection::getSfcCode, daParamCollection.getYzSfcCode())
        );
        if(list.size() > 0){
            for (DaParamCollection paramCollection : list) {
                paramCollection.setSfcCode(daParamCollection.getSfcCode());
                daParamCollectionService.saveOrUpdate(paramCollection);
            }
        }
    }
    @Override
    public void yzAddBasicParameters(DaParamCollection daParamCollection) {
        // 假设这是从数据库或其他地方获取的参数数据
        Map<String, String> map = new HashMap<>();
//        map.put("GC", "南浔工厂");
//        map.put("CXBH", "Pack线");
//        map.put("SBBH", "设备001");
//        map.put("YGBH", "员工001");
//        map.put("GDBH", daParamCollection.getWorkOrderNo());
//        map.put("CPXH", daParamCollection.getModel());
        map.put("INT", DateUtil.formatDateTime(new Date()));
        map.forEach((key, value) -> {
            DaCollectionParamConf daCollectionParamConf = new DaCollectionParamConf();
            daCollectionParamConf.setProcessesCode(daParamCollection.getLocationCode());
            daCollectionParamConf.setCollectParameterId(key);
            List<DaCollectionParamConf> daCollectionParamConfs = daCollectionParamConfMapper.selectDaCollectionParamConfList(daCollectionParamConf);
            DaParamCollection saveData = new DaParamCollection();
            saveData.setWorkOrderNo(daParamCollection.getWorkOrderNo());
            saveData.setProductCode(daParamCollection.getProductCode());
            saveData.setLocationCode(daParamCollection.getLocationCode());
            saveData.setSfcCode(daParamCollection.getProductBarcode());
            saveData.setParamCode(daCollectionParamConfs.get(0).getCollectParameterId());
            saveData.setParamName(daCollectionParamConfs.get(0).getCollectParameterName());
            saveData.setCollectionTime(new Date());
            saveData.setParamValue(value);
            daParamCollectionMapper.insertDaParamCollection(saveData);
        });
    }
}