admin
2024-09-27 ac3856a47fe649cff0b7c6d0a7edd1d8b83f9253
jcdm-main/src/main/java/com/jcdm/main/bs/formulaChild/controller/BsFormulaChildInfoController.java
@@ -1,5 +1,7 @@
package com.jcdm.main.bs.formulaChild.controller;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse;
@@ -8,6 +10,8 @@
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.jcdm.main.constant.Constants;
import com.jcdm.main.om.productionOrde.domain.OmProductionOrdeInfo;
import com.jcdm.main.om.productionOrde.service.IOmProductionOrdeInfoService;
import com.kangaroohy.milo.model.ReadWriteEntity;
import com.kangaroohy.milo.service.MiloService;
import org.springframework.security.access.prepost.PreAuthorize;
@@ -43,7 +47,34 @@
    private IBsFormulaChildInfoService bsFormulaChildInfoService;
    @Autowired
    private IOmProductionOrdeInfoService omProductionOrdeInfoService;
    @Autowired
    private MiloService miloService;
    /**
     * 返修信息写入plc
     */
    @GetMapping("/writeRepairInformationIntoPlc")
    public AjaxResult writeRepairInformationIntoPlc(BsFormulaChildInfo bsFormulaChildInfo)
    {
        String thoroughfare = Constants.thoroughfareMap.get(bsFormulaChildInfo.getProcessesCode());//获取通道
        try {
            String prefix = thoroughfare+".OP165.";
            miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(prefix+"SNCode").value(bsFormulaChildInfo.getSfcCode()).build());
            miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(prefix+"WorkOrderNumber").value(bsFormulaChildInfo.getWorkOrderNo()).build());
            miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(prefix+"ProcessesCode").value(bsFormulaChildInfo.getProcessesCode()).build());
            miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(prefix+"EngravingStatus").value(bsFormulaChildInfo.getEngravingStatus()).build());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return AjaxResult.success();
    }
    public static void main(String[] args) {
        String str = "TZ180XSDSZX012409120000001";
        System.out.println(str.length());
    }
    /**
     * 未做完工序回复plc信号
@@ -51,9 +82,11 @@
    @GetMapping("/unfinishedProcess")
    public AjaxResult unfinishedProcess(BsFormulaChildInfo bsFormulaChildInfo)
    {
        String thoroughfare = Constants.thoroughfareMap.get(bsFormulaChildInfo.getProcessesCode());//获取通道
        try {
            String str = "MOZU1."+bsFormulaChildInfo.getProcessesCode()+".RecordDataDone";
            miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(str).value(bsFormulaChildInfo.getRecordDataDone()).build());
//            String str = "MOZU1."+bsFormulaChildInfo.getProcessesCode()+".RecordDataDone";
//            miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(str).value(bsFormulaChildInfo.getRecordDataDone()).build());
            miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare+"."+bsFormulaChildInfo.getProcessesCode()+".RecordDataDone").value(bsFormulaChildInfo.getRecordDataDone()).build());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
@@ -94,16 +127,33 @@
//        }
        Integer stepNumber = 1;
        try {
            List<BsFormulaChildInfo> op260 = bsFormulaChildInfoService.list(new LambdaQueryWrapper<BsFormulaChildInfo>().eq(BsFormulaChildInfo::getProcessesCode, bsFormulaChildInfo.getProcessesCode()));
            List<BsFormulaChildInfo> filteredList = op260.stream()
                    .filter(obj -> obj.getResults() != null && !obj.getResults().isEmpty())
                    .collect(Collectors.toList());
            if(filteredList.size() > 0){
                stepNumber = Integer.valueOf(filteredList.get(filteredList.size()-1).getStepSort())+1;
//            List<BsFormulaChildInfo> op260 = bsFormulaChildInfoService.list(new LambdaQueryWrapper<BsFormulaChildInfo>()
//                    .eq(BsFormulaChildInfo::getProcessesCode, bsFormulaChildInfo.getProcessesCode())
//                    .eq(BsFormulaChildInfo::getOperationType, "1")
//            );
//            List<BsFormulaChildInfo> filteredList = op260.stream()
//                    .filter(obj -> obj.getResults() != null && !obj.getResults().isEmpty())
//                    .collect(Collectors.toList());
//            if(filteredList.size() > 0){
//                stepNumber = Integer.valueOf(filteredList.get(filteredList.size()-1).getStepSort())+1;
//            }
            String thoroughfare = Constants.thoroughfareMap.get(bsFormulaChildInfo.getProcessesCode());//获取通道
            String str = thoroughfare+"."+bsFormulaChildInfo.getProcessesCode()+".MESScrew";
            miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(str).value(stepNumber).build());//拧紧步骤
            if("OP230".equals(bsFormulaChildInfo.getProcessesCode())){
                List<OmProductionOrdeInfo> list = omProductionOrdeInfoService.list(new LambdaQueryWrapper<OmProductionOrdeInfo>().like(OmProductionOrdeInfo::getProductNum, bsFormulaChildInfo.getSfcBarcode()));
                String sfcCode = list.get(0).getProductNum();
                //所有进站将进站时间写给PLC
                SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                String currentDate = dateFormat.format(new Date());
                miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + bsFormulaChildInfo.getProcessesCode() + ".StartTime").value(currentDate).build());
                miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + bsFormulaChildInfo.getProcessesCode() + ".SNCode").value(sfcCode).build());
                miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + bsFormulaChildInfo.getProcessesCode() + ".RecordDataDone").value(11).build());
            }else if("OP220".equals(bsFormulaChildInfo.getProcessesCode())){
                miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + bsFormulaChildInfo.getProcessesCode() + ".RecordDataDone").value(11).build());
            }
            String str = "PACK."+bsFormulaChildInfo.getProcessesCode()+".MStepNumber";
            miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(str).value(stepNumber).build());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
@@ -120,7 +170,7 @@
        List<BsFormulaChildInfo> list = bsFormulaChildInfoService.list(new LambdaQueryWrapper<BsFormulaChildInfo>()
                .eq(BsFormulaChildInfo::getProductCode,bsFormulaChildInfo.getProductCode())
                .eq(BsFormulaChildInfo::getProcessesCode,bsFormulaChildInfo.getProcessesCode())
                .orderByAsc(BsFormulaChildInfo::getStepSort)
//                .orderByAsc(BsFormulaChildInfo::getStepSort)
        );
        if (CollUtil.isNotEmpty(list)){
            List<BsFormulaChildInfo> collect1 = list.stream().filter(x -> Constants.OK.equals(x.getResults())).collect(Collectors.toList());