admin
5 天以前 0a926b3ce629047a88dbc65cc38ec86c43520336
jcdm-main/src/main/java/com/jcdm/main/da/paramCollection/service/impl/DaParamCollectionServiceImpl.java
@@ -17,6 +17,7 @@
import com.jcdm.common.utils.DateUtils;
import com.jcdm.common.utils.SecurityUtils;
import com.jcdm.common.utils.StringUtils;
import com.jcdm.framework.websocket.WebSocketUsers;
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;
@@ -53,6 +54,7 @@
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.websocket.Session;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.util.*;
@@ -108,6 +110,9 @@
    private IDaPassingStationCollectionService daPassingStationCollectionService;
    public SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    Map<String, Session> map = WebSocketUsers.getUsers();
    /**
     * 查询设备产品过程参数采集
@@ -522,12 +527,16 @@
            parentVO.setTotalResult("1");
            List<ChildVO> listChildVo = new ArrayList<>();
            String productModel = "PE01B";
            OmProductionOrdeInfo orderOne = omProductionOrdeInfoService.getOne(new LambdaQueryWrapper<OmProductionOrdeInfo>().eq(OmProductionOrdeInfo::getProductNum, packID));
            productModel = orderOne.getProductCode();
            for (DaParamCollectionTemp daParamCollection : paramList) {
                ChildVO childVO = new ChildVO();
                childVO.setItemCode(daParamCollection.getParamCode());
                List<DaCollectionParamConf> paramConfOneList = daCollectionParamConfService.list(new LambdaQueryWrapper<DaCollectionParamConf>()
                        .eq(DaCollectionParamConf::getCollectParameterId, daParamCollection.getParamCode())
                        .eq(DaCollectionParamConf::getProductModel, "PE01B")
                        .eq(DaCollectionParamConf::getProductModel, productModel)
                );
                DaCollectionParamConf paramConfOne = paramConfOneList.get(0);
                if(paramConfOne!=null){
@@ -591,6 +600,10 @@
            parentVO.setProductNum(packID);
            parentVO.setTotalResult("1");
            List<ChildVO> listChildVo = new ArrayList<>();
//            String productModel = "PE01B";
//            OmProductionOrdeInfo orderOne = omProductionOrdeInfoService.getOne(new LambdaQueryWrapper<OmProductionOrdeInfo>().eq(OmProductionOrdeInfo::getProductNum, packID));
//            productModel = orderOne.getProductCode();
            for (DaParamCollection daParamCollection : paramList) {
                ChildVO childVO = new ChildVO();
@@ -672,10 +685,10 @@
//        String url = "https://imes-uat-group.geelycv-test.com/api/mom-open/restful/aMesSysIntegration/deviceResultFeedback";
        try{
            daParamCollection.setWeightValue(getRandomNumberBetween(312.5, 313.5));
//            Object recordDataDone = miloService.readFromOpcUa("PACK" + "." + daParamCollection.getLocationCode() + ".MStepNumber").getValue();
//            if(ObjectUtil.isNotNull(recordDataDone)){
//                daParamCollection.setWeightValue(recordDataDone.toString());
//            }
            Object recordDataDone = miloService.readFromOpcUa("PACK" + "." + daParamCollection.getLocationCode() + ".weight").getValue();
            if(ObjectUtil.isNotNull(recordDataDone)){
                daParamCollection.setWeightValue(recordDataDone.toString());
            }
            long timestampMillis = Instant.now().toEpochMilli();
            ParentVO parentVO = new ParentVO();
            ChildVO childVO = new ChildVO();
@@ -703,14 +716,17 @@
                String resultCode = jsonObject.getJSONObject("data").getStr("resultCode");
                if("success".equals(code)&&"S".equals(resultCode)){
                    //如果成功,执行报工成功方法,修改是否报工为1,添加报工时间
                    WebSocketUsers.sendMessageToUserByText(map.get("POP430"), "reportSuccess");
                    omProductionOrdeInfoService.updateOrderByProductNum("1",daParamCollection.getProductBarcode(),"POP430");
                }else{
                    WebSocketUsers.sendMessageToUserByText(map.get("POP430"), "reportError");
                    //解析工厂mes返回结果,如果失败,执行报工失败方法,修改是否报工为2,添加报工时间
                    omProductionOrdeInfoService.updateOrderByProductNum("2",daParamCollection.getProductBarcode(),"POP430");
                }
                logger.info("OP430报工结束-工厂MES异步方法{}"+reportResult);
            });
        }catch (Exception e){
            WebSocketUsers.sendMessageToUserByText(map.get("POP430"), "reportError");
            System.out.println(e.getMessage());
        }
//        HttpResponse execute = HttpRequest.post(url).body(JSONUtil.toJsonStr(parentVO)).execute();
@@ -884,6 +900,75 @@
        }
    }
    @Override
    public void jrmPushGeelycvMesFeedback(String packID, String stationCode, String productCode) {
        logger.info("进入人工工位推送工厂MES数据方法-pushGeelycvMesFeedback-工位{}-pack码{}",stationCode,packID);
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        String url = "https://imes-uat-group.geelycv-test.com/api/mom-open/restful/aMesSysIntegration/deviceResultFeedback";
        String url = "https://imes-group.geelycv.com/api/mom-open/restful/aMesSysIntegration/deviceResultFeedback";
        String totalResult = "0";
        List<DaParamCollectionTemp> paramList = daParamCollectionTempService.list(new LambdaQueryWrapper<DaParamCollectionTemp>().eq(DaParamCollectionTemp::getSfcCode, packID).eq(DaParamCollectionTemp::getLocationCode, stationCode));
        if(paramList.size() > 0){
            ParentVO parentVO = new ParentVO();
            parentVO.setSiteCode("3983");
            parentVO.setRecordId(String.valueOf(Instant.now().toEpochMilli()));
            parentVO.setStationCode(stationCode);
            parentVO.setProductNum(packID);
            parentVO.setTotalResult("1");
            List<ChildVO> listChildVo = new ArrayList<>();
            for (DaParamCollectionTemp daParamCollection : paramList) {
                ChildVO childVO = new ChildVO();
                childVO.setItemCode(daParamCollection.getParamCode());
                List<DaCollectionParamConf> paramConfOneList = daCollectionParamConfService.list(new LambdaQueryWrapper<DaCollectionParamConf>()
                        .eq(DaCollectionParamConf::getCollectParameterId, daParamCollection.getParamCode())
                        .eq(DaCollectionParamConf::getProductModel, productCode)
                );
                DaCollectionParamConf paramConfOne = paramConfOneList.get(0);
                if(paramConfOne!=null){
                    childVO.setItemType(paramConfOne.getSpareField1());
                    childVO.setItemText(paramConfOne.getCollectParameterName());
                }else {
                    childVO.setItemType("3");
                    childVO.setItemText("");
                }
                childVO.setItemValue(daParamCollection.getParamValue());
                if(daParamCollection.getParamValue().equals("1")){
                    childVO.setCheckResult("1");
                }else if(daParamCollection.getParamValue().equals("2")){
                    childVO.setCheckResult("0");
                    parentVO.setTotalResult("0");
                    totalResult = "1";
                }else {
                    childVO.setCheckResult("1");
                }
                childVO.setCheckTime(format.format(daParamCollection.getCollectionTime()));
                listChildVo.add(childVO);
            }
            parentVO.setCheckList(listChildVo);
            try{
                CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> {
                    logger.info("工位{}---开始执行异步方法---pack码是{}"+stationCode,packID);
                    HttpResponse execute = HttpRequest.post(url).body(JSONUtil.toJsonStr(parentVO)).execute();
                    logger.info("工位{}---异步方法执行结束---pack码是{}"+stationCode,packID);
                    logger.info("手动工位{}传工厂入参VO{}---pack码是{}" + stationCode,new Gson().toJson(parentVO),packID);
                    logger.info("手动工位{}传工厂MES异步方法{}---pack码是{}"+stationCode,execute.body(),packID);
                    DaParamCollectionTemp daParamCollectionTemp = new DaParamCollectionTemp();
                    daParamCollectionTemp.setSfcCode(packID);
                    daParamCollectionTemp.setLocationCode(stationCode);
                    int i = daParamCollectionTempService.deleteDaParamCollectionTempBySfcCodeAndLocationCode(daParamCollectionTemp);
                    logger.info("删除临时表数据条数{}-工位{}-pack码{}",i,stationCode,packID);
                });
            }catch (Exception e){
                System.out.println(e.getMessage());
            }
            logger.info("结束人工工位推送工厂MES数据方法-pushGeelycvMesFeedback-工位{}-pack码{}",stationCode,packID);
        }
    }
    public static String getRandomNumberBetween(double min, double max) {
        return String.format("%.1f",min + (Math.random() * (max - min)));
    }