cl
2024-08-07 346fa4579d97d115f9737fb5be0417896c454596
生产1P1S码
已修改3个文件
156 ■■■■■ 文件已修改
jcdm-main/src/main/java/com/jcdm/main/constant/Constants.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
jcdm-main/src/main/java/com/jcdm/main/plcserver/CustomRunner.java 82 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
jcdm-main/src/main/java/com/jcdm/main/plcserver/sub/OPCUaSubscription.java 69 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
jcdm-main/src/main/java/com/jcdm/main/constant/Constants.java
@@ -1,5 +1,6 @@
package com.jcdm.main.constant;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -19,6 +20,10 @@
    public static final Map<String,String> materialMap = new HashMap();//人工工位
    public static final Map<Integer,String> YEARSMAP = new HashMap();//年集合
    public static final Map<Integer,String> MONTHSMAP = new HashMap();//月集合
    public static final Map<Integer,String> DAYMAP = new HashMap();//日集合
    public static final String NG = "2";
    public static final String UN_PASS= "不合格";
    public static final String PASS= "合格";
jcdm-main/src/main/java/com/jcdm/main/plcserver/CustomRunner.java
@@ -9,6 +9,7 @@
import com.jcdm.main.da.opcuaconfig.service.IDaOpcuaConfigService;
import com.jcdm.main.da.paramCollection.service.IDaParamCollectionService;
import com.jcdm.main.da.passingStationCollection.service.IDaPassingStationCollectionService;
import com.jcdm.main.da.psConf.service.IDaPsConfService;
import com.jcdm.main.da.testDeviceInterfaceTemp.service.IDaTestDeviceInterfaceTempService;
import com.jcdm.main.om.productionOrde.service.IOmProductionOrdeInfoService;
import com.jcdm.main.plcserver.sub.OPCUaSubscription;
@@ -50,6 +51,9 @@
    @Autowired
    private IDaCellDataService daCellDataService;
    @Autowired
    private IDaPsConfService daPsConfService;
    @Override
    public void run(ApplicationArguments args) throws Exception {
@@ -82,6 +86,8 @@
        Constants.ModuleList.add(Constants.OP210);
        Constants.ModuleList.add(Constants.OP220);
        getDate();//将日期放入MAP集合,1P1S用
        OPCUaSubscription opcUaSubscription = new OPCUaSubscription(
                miloService,
                daPassingStationCollectionService,
@@ -89,7 +95,8 @@
                daParamCollectionService,
                omProductionOrdeInfoService,
                daTestDeviceInterfaceTempService,
                daCellDataService);
                daCellDataService,
                daPsConfService);
        List<String> lists = getSubList();
        System.out.println("订阅内容:"+lists);
@@ -106,5 +113,78 @@
                .stream().map(DaOpcuaConfig::getNode).collect(Collectors.toList());
        return lists;
    }
    /**
     * 将日期放入MAP集合,1P1S用
     */
    public static  void getDate(){
        //年
        Constants.YEARSMAP.put(2024,"E");
        Constants.YEARSMAP.put(2025,"F");
        Constants.YEARSMAP.put(2026,"G");
        Constants.YEARSMAP.put(2027,"H");
        Constants.YEARSMAP.put(2028,"J");
        Constants.YEARSMAP.put(2029,"K");
        Constants.YEARSMAP.put(2030,"L");
        Constants.YEARSMAP.put(2031,"M");
        Constants.YEARSMAP.put(2032,"N");
        Constants.YEARSMAP.put(2033,"P");
        Constants.YEARSMAP.put(2034,"R");
        Constants.YEARSMAP.put(2035,"S");
        Constants.YEARSMAP.put(2036,"T");
        Constants.YEARSMAP.put(2037,"V");
        Constants.YEARSMAP.put(2038,"W");
        Constants.YEARSMAP.put(2039,"X");
        Constants.YEARSMAP.put(2040,"Y");
        //月
        Constants.MONTHSMAP.put(1,"1");
        Constants.MONTHSMAP.put(2,"2");
        Constants.MONTHSMAP.put(3,"3");
        Constants.MONTHSMAP.put(4,"4");
        Constants.MONTHSMAP.put(5,"5");
        Constants.MONTHSMAP.put(6,"6");
        Constants.MONTHSMAP.put(7,"7");
        Constants.MONTHSMAP.put(8,"8");
        Constants.MONTHSMAP.put(9,"9");
        Constants.MONTHSMAP.put(10,"A");
        Constants.MONTHSMAP.put(11,"B");
        Constants.MONTHSMAP.put(12,"C");
        //日
        Constants.DAYMAP.put(1,"1");
        Constants.DAYMAP.put(2,"2");
        Constants.DAYMAP.put(3,"3");
        Constants.DAYMAP.put(4,"4");
        Constants.DAYMAP.put(5,"5");
        Constants.DAYMAP.put(6,"6");
        Constants.DAYMAP.put(7,"7");
        Constants.DAYMAP.put(8,"8");
        Constants.DAYMAP.put(9,"9");
        Constants.DAYMAP.put(10,"A");
        Constants.DAYMAP.put(11,"B");
        Constants.DAYMAP.put(12,"C");
        Constants.DAYMAP.put(13,"D");
        Constants.DAYMAP.put(14,"E");
        Constants.DAYMAP.put(15,"F");
        Constants.DAYMAP.put(16,"G");
        Constants.DAYMAP.put(17,"H");
        Constants.DAYMAP.put(18,"J");
        Constants.DAYMAP.put(19,"K");
        Constants.DAYMAP.put(20,"L");
        Constants.DAYMAP.put(21,"M");
        Constants.DAYMAP.put(22,"N");
        Constants.DAYMAP.put(23,"P");
        Constants.DAYMAP.put(24,"R");
        Constants.DAYMAP.put(25,"S");
        Constants.DAYMAP.put(26,"T");
        Constants.DAYMAP.put(27,"V");
        Constants.DAYMAP.put(28,"W");
        Constants.DAYMAP.put(29,"X");
        Constants.DAYMAP.put(30,"Y");
        Constants.DAYMAP.put(31,"0");
    }
}
jcdm-main/src/main/java/com/jcdm/main/plcserver/sub/OPCUaSubscription.java
@@ -3,13 +3,12 @@
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.jcdm.common.core.domain.AjaxResult;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.jcdm.framework.websocket.WebSocketUsers;
import com.jcdm.main.constant.Constants;
import com.jcdm.main.da.cellData.domain.DaCellData;
@@ -20,6 +19,8 @@
import com.jcdm.main.da.paramCollection.service.IDaParamCollectionService;
import com.jcdm.main.da.passingStationCollection.domain.DaPassingStationCollection;
import com.jcdm.main.da.passingStationCollection.service.IDaPassingStationCollectionService;
import com.jcdm.main.da.psConf.domain.DaPsConf;
import com.jcdm.main.da.psConf.service.IDaPsConfService;
import com.jcdm.main.da.testDeviceInterfaceTemp.domain.DaTestDeviceInterfaceTemp;
import com.jcdm.main.da.testDeviceInterfaceTemp.service.IDaTestDeviceInterfaceTempService;
import com.jcdm.main.om.productionOrde.domain.OmProductionOrdeInfo;
@@ -32,12 +33,12 @@
import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
import com.kangaroohy.milo.service.MiloService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import javax.websocket.Session;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
@@ -48,7 +49,7 @@
public class OPCUaSubscription implements SubscriptionCallback {
    public static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    public static Calendar calendar = Calendar.getInstance();
    Map<String, Session> map = WebSocketUsers.getUsers();
    public static MiloService miloService;
@@ -66,6 +67,8 @@
    public static IDaCellDataService daCellDataService;
    public static IDaPsConfService daPsConfService;
/*    @Value("${orderLineUrl}")
    private static String orderLineUrl;*/
@@ -75,7 +78,8 @@
                             IDaParamCollectionService daParamCollectionService,
                             IOmProductionOrdeInfoService omProductionOrdeInfoService,
                             IDaTestDeviceInterfaceTempService daTestDeviceInterfaceTempService,
                             IDaCellDataService daCellDataService) {
                             IDaCellDataService daCellDataService,
                             IDaPsConfService daPsConfService) {
        OPCUaSubscription.miloService = miloService;
        OPCUaSubscription.daPassingStationCollectionService = daPassingStationCollectionService;
        OPCUaSubscription.collectionParamConfService = collectionParamConfService;
@@ -83,6 +87,7 @@
        OPCUaSubscription.omProductionOrdeInfoService = omProductionOrdeInfoService;
        OPCUaSubscription.daTestDeviceInterfaceTempService = daTestDeviceInterfaceTempService;
        OPCUaSubscription.daCellDataService = daCellDataService;
        OPCUaSubscription.daPsConfService = daPsConfService;
    }
@@ -1070,8 +1075,8 @@
            if (CollUtil.isNotEmpty(list)){
                for(DaCollectionParamConf conf:list){
                    //1P1S生成
                    if(conf.getCollectParameterId().equals("OCV_1P1SMID")){
                        String result = "";
                    if(conf.getCollectParameterId().equals("1P1S")){
                        String result = get1P1S(sfcCode);
                        conf.setParamCentral(result);
                    }
                    ChildVO childVO = new ChildVO();
@@ -1084,7 +1089,7 @@
                    basicList.add(childVO);
                    DaParamCollection daParamCollection = new DaParamCollection();
                    daParamCollection.setSfcCode(sfcCode);//模组码
                    daParamCollection.setSfcCode(sfcCode);//总成码
                    daParamCollection.setParamCode(conf.getCollectParameterId());//参数编码
                    daParamCollection.setParamName(conf.getCollectParameterName());//参数名称
@@ -1101,6 +1106,52 @@
        }
    }
    /**
     * 生成1P1S码
     * @param sfcCode
     * @return list
     */
    public static String get1P1S(String sfcCode) {
        String result = "";
        LocalDate now = LocalDate.now();
        String supplierCode  = sfcCode.substring(0,3);
        try {
            List<DaPsConf> list = daPsConfService.list(new LambdaQueryWrapper<DaPsConf>()
                    .eq(DaPsConf::getSpareField1, supplierCode)//供应商识别码
                    .eq(DaPsConf::getState,"1"));//状态
            if(!list.isEmpty()){
                String mfCode = list.get(0).getMfCode();//厂商代码
                String proTypeCode = list.get(0).getProTypeCode();//产品类型代码
                String batteryTypeCode = list.get(0).getBatteryTypeCode();//电池类型代码
                String specificationsCode = list.get(0).getSpecificationsCode();//规格代码
                String traceInfoCode = list.get(0).getTraceInfoCode();//追溯信息代码
                String proDateCode = Constants.YEARSMAP.get(now.getYear())
                        + Constants.MONTHSMAP.get(now.getMonthValue())
                        + Constants.DAYMAP.get(now.getDayOfMonth());//生产日期
                String code = list.get(0).getSfcCode();//序列号
                code = StringUtils.leftPad(String.valueOf(Integer.valueOf(code)+1),7, "0");;//序列号
                result = mfCode+proTypeCode+batteryTypeCode+specificationsCode+traceInfoCode+proDateCode+code;
                //更新日期和序列号
                LambdaUpdateWrapper<DaPsConf> lambdaUpdateWrapper = new LambdaUpdateWrapper<DaPsConf>();
                lambdaUpdateWrapper.set(DaPsConf::getProDateCode,proDateCode);//生产日期
                lambdaUpdateWrapper.set(DaPsConf::getSfcCode,code);//序列号
                lambdaUpdateWrapper.eq(DaPsConf::getSpareField1,supplierCode);//供应商识别码
                lambdaUpdateWrapper.eq(DaPsConf::getState,"1");//状态
                daPsConfService.update(lambdaUpdateWrapper);
            }else{
                log.info("请先去1P1S配置页面配置规则!");
            }
            return result;
        }catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    public static void main(String[] args) throws Exception {
        get1P1S("");
    }
}