cl
2024-08-12 6f1a28c55c7744c471bd5edfee0a418fb0f23434
提交 | 用户 | 时间
b78728 1 package com.jcdm.main.plcserver.sub;
A 2
3
4 import cn.hutool.core.collection.CollUtil;
5 import cn.hutool.core.util.ObjectUtil;
6 import cn.hutool.http.HttpRequest;
7 import cn.hutool.http.HttpResponse;
8 import cn.hutool.json.JSONObject;
9 import cn.hutool.json.JSONUtil;
10 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
a90728 11 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
b78728 12 import com.jcdm.framework.websocket.WebSocketUsers;
A 13 import com.jcdm.main.constant.Constants;
14 import com.jcdm.main.da.cellData.service.IDaCellDataService;
15 import com.jcdm.main.da.collectionParamConf.domain.DaCollectionParamConf;
16 import com.jcdm.main.da.collectionParamConf.service.IDaCollectionParamConfService;
17 import com.jcdm.main.da.paramCollection.domain.DaParamCollection;
18 import com.jcdm.main.da.paramCollection.service.IDaParamCollectionService;
19 import com.jcdm.main.da.passingStationCollection.domain.DaPassingStationCollection;
20 import com.jcdm.main.da.passingStationCollection.service.IDaPassingStationCollectionService;
21 import com.jcdm.main.da.testDeviceInterfaceTemp.service.IDaTestDeviceInterfaceTempService;
22 import com.jcdm.main.om.productionOrde.domain.OmProductionOrdeInfo;
23 import com.jcdm.main.om.productionOrde.service.IOmProductionOrdeInfoService;
24 import com.jcdm.main.plcserver.util.TimeUtil;
25 import com.jcdm.main.restful.factoryMes.service.RestfulService;
26 import com.jcdm.main.restful.qingYan.doman.ChildVO;
27 import com.jcdm.main.restful.qingYan.doman.ParentVO;
28 import com.kangaroohy.milo.model.ReadWriteEntity;
3c3c4d 29 import com.kangaroohy.milo.model.WriteEntity;
b78728 30 import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
A 31 import com.kangaroohy.milo.service.MiloService;
32 import lombok.extern.slf4j.Slf4j;
3c3c4d 33 import org.apache.xmlbeans.GDate;
C 34 import org.eclipse.milo.opcua.stack.core.types.builtin.DateTime;
35 import org.eclipse.milo.opcua.stack.core.types.builtin.Variant;
b78728 36 import org.springframework.stereotype.Component;
A 37
38 import javax.websocket.Session;
39 import java.text.SimpleDateFormat;
3c3c4d 40 import java.time.LocalDateTime;
b78728 41 import java.util.*;
A 42 import java.util.concurrent.CompletableFuture;
43 import java.util.stream.Collectors;
44
45
46 @Slf4j
47 @Component
48 public class OPCUaSubscription implements SubscriptionCallback {
49
50     public static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
51
52
53     Map<String, Session> map = WebSocketUsers.getUsers();
54     public static MiloService miloService;
55
56
57     public static IDaPassingStationCollectionService daPassingStationCollectionService;
58
59     public static IDaCollectionParamConfService collectionParamConfService;
60
61     public static IDaParamCollectionService daParamCollectionService;
62
63     public static IOmProductionOrdeInfoService omProductionOrdeInfoService;
64
65     public static IDaTestDeviceInterfaceTempService daTestDeviceInterfaceTempService;
66
67     public static IDaCellDataService daCellDataService;
68
69     public OPCUaSubscription(MiloService miloService,
70                              IDaPassingStationCollectionService daPassingStationCollectionService,
71                              IDaCollectionParamConfService collectionParamConfService,
72                              IDaParamCollectionService daParamCollectionService,
73                              IOmProductionOrdeInfoService omProductionOrdeInfoService,
74                              IDaTestDeviceInterfaceTempService daTestDeviceInterfaceTempService,
75                              IDaCellDataService daCellDataService) {
76         OPCUaSubscription.miloService = miloService;
77         OPCUaSubscription.daPassingStationCollectionService = daPassingStationCollectionService;
78         OPCUaSubscription.collectionParamConfService = collectionParamConfService;
79         OPCUaSubscription.daParamCollectionService = daParamCollectionService;
80         OPCUaSubscription.omProductionOrdeInfoService = omProductionOrdeInfoService;
81         OPCUaSubscription.daTestDeviceInterfaceTempService = daTestDeviceInterfaceTempService;
82         OPCUaSubscription.daCellDataService = daCellDataService;
83     }
84
85
86     @Override
87     public void onSubscribe(String identifier, Object value) {
88         log.info("地址:"+identifier+"值:"+value);
89         try {
90             if(null != value && !Constants.ZERO.equals(value.toString())) {
91                 String[] nodes = identifier.split("[.]");
92                 String thoroughfare = nodes[0];//通道
93                 String device = nodes[1];//设备
94                 String tab = nodes[2];//标记
95                 String valueString = value.toString();//地址值
96
97                 CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> {
98                     subHandle(thoroughfare,device,tab,valueString);
99                 });
100
101             }
102         } catch (Exception e) {
103             log.error(e.getMessage());
104         }
105     }
106
107     public void subHandle(String thoroughfare,String device,String tab,String valueString){
108         try{
d819b1 109             if (Constants.RECORD_DATA.equals(tab)) {  //出入站
b321b8 110                 if (Constants.ONE.equals(valueString)) {//入站
5b939f 111                     if(Constants.OP040_OP160.contains(device)){//人工工位
8c09d8 112                         Object snCodeObjcet = miloService.readFromOpcUa(thoroughfare + "." + device + ".SNCode").getValue();
2b9842 113                         if (ObjectUtil.isNull(snCodeObjcet)){
C 114                             miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(12).build());
115                         }else{
116                             String productNum = snCodeObjcet.toString();
117                             //将产品SN发送到前台
118                             productNum = "productNum,"+ productNum;
119                             WebSocketUsers.sendMessageToUserByText(map.get(device), productNum);
120                             miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(11).build());
121                         }
5b939f 122                     }else {//自动工位
C 123                         //所有进站将进站时间写给PLC
124                         SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
125                         String currentDate = dateFormat.format(new Date());
126                         miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".StartTime").value(currentDate).build());
127
2b9842 128                         Integer recordDataDone = 11;
C 129                         miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(recordDataDone).build());
130                     }
5b939f 131
b321b8 132                 } else if(Constants.TWO.equals(valueString)){//出站
8c09d8 133                         if(Constants.OP040_OP160.contains(device)){//人工工位
C 134                             WebSocketUsers.sendMessageToUserByText(map.get(device), "END");
6f1a28 135                         } else if (Constants.OP165.equals(device)) {
C 136                             WebSocketUsers.sendMessageToUserByText(map.get(device), "print");//打印
137                         } else if (Constants.OP0170_OP230.contains(device)) {
138                             WebSocketUsers.sendMessageToUserByText(map.get(device), "END");
139                         } else{//自动工位
140                             //先判断是否有产品SN
8c09d8 141                             Object snCodeObjcet = miloService.readFromOpcUa(thoroughfare + "." + device + ".SNCode").getValue();
C 142                             Object orderObjcet = miloService.readFromOpcUa(thoroughfare + "." + device + ".WorkOrderNumber").getValue();
143                             if (ObjectUtil.isNull(snCodeObjcet)){
144                                 miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(25).build());
145                             }else {
5b939f 146                                 //所有出站将出站时间写给PLC
C 147                                 SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
148                                 String currentDate = dateFormat.format(new Date());
149                                 miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".StopTime").value(currentDate).build());
150
8c09d8 151                                 Integer result = 21;
C 152                                 String snCode = snCodeObjcet.toString();//产品SN
153                                 String orderNumber = orderObjcet.toString();//工单号
154                                 Object stationStatusObjcet = miloService.readFromOpcUa(thoroughfare + "." + device + ".StationStatus").getValue();//站状态地址
155                                 if (ObjectUtil.isNotNull(stationStatusObjcet)) {
156                                     String stationStatus = stationStatusObjcet.toString();
157                                     if (Constants.OP010.equals(device)) {
5b939f 158                                         CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> {
C 159                                             updateOrderStatus(snCode, "3");//OP010工位更新工单状态为执行中
160                                             reportFactoryMes(snCode, device, format.format(new Date()));//工厂MES报工
161                                         });
8c09d8 162                                     }
C 163                                     result = savePassingStation(thoroughfare, device, snCode, orderNumber, stationStatus);//保存过站
164                                     if (result == 21) {
165                                         result = saveParamCollection(device, snCode, orderNumber, stationStatus);//保存参数,发送工厂MES
166                                     }
167                                 } else {
168                                     result = 23;
169                                     log.info("读取到工位{}StationStatus数据:{},返回RecordDataDone的值为{}", device, "IS NULL!", result);
170                                 }
171                                 miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(result).build());
a90728 172                             }
d819b1 173                         }
C 174                 }
175             }else if (Constants.RECORD_SN.equals(tab)){//请求产品序列号
176                 if (Constants.ONE.equals(valueString)){
177                     //进站PLC给产品类型,MES读取产品类型
178                     Object productTypeObjcet = miloService.readFromOpcUa(thoroughfare + "." + device + ".ProductType").getValue();//产品类型
179                     if (ObjectUtil.isNotNull(productTypeObjcet)){
180                         String productType = productTypeObjcet.toString();//产品类型
181                         String materialCode = Constants.materialMap.get(productType);
182                         //接收工单,保存到数据库,并且将工单传给PLC
183                         CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> {
184                             receivingWorkOrders(thoroughfare, device,materialCode);
185                         });
186                     }else{
f3862f 187                         miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordSNDone").value(12).build());
d819b1 188                     }
f3862f 189
b78728 190                 }
f3862f 191             }else if(Constants.SCREW.equals(tab)){
C 192                 List<String> list = new ArrayList<>();
5b939f 193                 String[] suffixes = {"Torque1", "Angle1", "TorqueResult1", "AngleResult1"};
f3862f 194
C 195                 for (String suffix : suffixes) {
196                     String string = thoroughfare + "." + device + "." + suffix;
197                     list.add(string);
198                 }
199                 List<ReadWriteEntity> list1 = miloService.readFromOpcUa(list);
200                 List<Object> collect = list1.stream().map(ReadWriteEntity::getValue).collect(Collectors.toList());
201                 String joinedString = String.join(",", collect.toString());
202                 WebSocketUsers.sendMessageToUserByText(map.get(device), TightenTheConversionOkNg(joinedString));
b78728 203             }
A 204         }catch (Exception e) {
205             log.error(e.getMessage());
206         }
207     }
d819b1 208
C 209     /**
210      * 保存过站数据
211      * @param thoroughfare 通道
212      * @param device 工位
213      * @param snCode 产品序列号
214      * @param stationStatus 站状态
215      * @return Integer
216      * @throws Exception e
217      */
218     private static Integer savePassingStation(String thoroughfare, String device,String snCode,String orderNumber,String stationStatus){
219         Integer result = 21;
220         try {
221             //读进站时间
222             Date startTime = new Date();
223             ReadWriteEntity startTimeRead = miloService.readFromOpcUa(thoroughfare + "." + device + ".StartTime");//进站时间
224             if (ObjectUtil.isNotNull(startTimeRead.getValue())){
5b939f 225                 startTime = format.parse(startTimeRead.getValue().toString());
d819b1 226             }else{
C 227                 result = 23;
228                 log.info("读取到工位{}的StartTime数据:{},返回RecordDataDone的值为{}",device,"IS NULL!",result);
229                 return result;
230             }
231
232             DaPassingStationCollection passingStationCollection = new DaPassingStationCollection();
233             passingStationCollection.setSfcCode(snCode);//产品序列号
234             passingStationCollection.setWorkOrderNo(orderNumber);//工单号
235             passingStationCollection.setLocationCode(device);//工位
236             passingStationCollection.setInboundTime(startTime);//进站时间
237             passingStationCollection.setOutboundTime(new Date());//出站时间
238             passingStationCollection.setOutRsSign(stationStatus);//站状态值
239             passingStationCollection.setCollectionTime(new Date());//采集时间
240             daPassingStationCollectionService.save(passingStationCollection);
241
242         } catch (Exception e) {
243             throw new RuntimeException(e);
244         }
245
246         return result;
247     }
248
249     /**
250      * 保存参数数据和发送工厂MES
251      * @param device 工位
252      * @param snCode 产品SN
253      * @param orderNumber 工单号
254      * @param stationStatus 站状态
255      * @return result
256      * @throws Exception e
257      */
258     private static Integer saveParamCollection(String device,String snCode,String orderNumber,String stationStatus){
259         Integer result = 21;//返回结果
260         try {
261             //查询参数配置表
262             List<DaCollectionParamConf> list = collectionParamConfService.list(new LambdaQueryWrapper<DaCollectionParamConf>()
263                     .eq(DaCollectionParamConf::getProcessesCode, device)//工位
264                     .eq(DaCollectionParamConf::getWhetherToCollect, Constants.ONE)//是否采集
265             );
266             if (CollUtil.isNotEmpty(list)){
267
268                 List<String> collect = list.stream()
269                         .map(DaCollectionParamConf::getGatherAddress).collect(Collectors.toList());
270                 List<ReadWriteEntity> readWriteEntityList = miloService.readFromOpcUa(collect);
271
272                 List<DaParamCollection> collectionList = new ArrayList<>();
273                 List<ChildVO> mesList = new ArrayList<>();
274                 for (int i = 0; i < readWriteEntityList.size(); i++) {
275                     DaParamCollection daParamCollection = new DaParamCollection();
276                     daParamCollection.setSfcCode(snCode);//产品SN
277                     daParamCollection.setWorkOrderNo(orderNumber);//工单号
278                     daParamCollection.setParamCode(list.get(i).getCollectParameterId());//参数编码
279                     daParamCollection.setParamName(list.get(i).getCollectParameterName());//参数名称
280                     String paramValue = "";
281                     if (ObjectUtil.isNotNull(readWriteEntityList.get(i).getValue())){
282                         paramValue = readWriteEntityList.get(i).getValue().toString();//参数值
509744 283                         /*if("DATE".equals(list.get(i).getCollectParameterType()) && !paramValue.isEmpty()){
d819b1 284                             paramValue = format.parse(TimeUtil.test(TimeUtil.stringProcessing(paramValue))).toString();
C 285                         }else if("MODEL".equals(list.get(i).getCollectParameterType()) && !paramValue.isEmpty()){
286                             paramValue = Constants.materialMap.get(paramValue);
509744 287                         }*/
d819b1 288                     }
C 289                     daParamCollection.setParamValue(paramValue);//参数值
290                     daParamCollection.setLocationCode(device);//工位
291                     daParamCollection.setCollectionTime(new Date());//采集时间
292                     collectionList.add(daParamCollection);//封装参数采集list
293
294                     //发送给工厂mes参数封装
295                     ChildVO childVO = new ChildVO();
296                     childVO.setItemCode(list.get(i).getCollectParameterId());//参数编码
297                     childVO.setItemType(list.get(i).getItemType());
298                     childVO.setItemValue(paramValue);//参数值
299                     childVO.setItemText(list.get(i).getCollectParameterName());
300                     childVO.setCheckResult("1");
301                     childVO.setCheckTime(format.format(new Date()));
302                     mesList.add(childVO);
303                 }
304
509744 305                 CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> {
d819b1 306                     //插入参数采集表
C 307                     daParamCollectionService.insertBatch(collectionList);
308                     //上传到工厂mes
309                     ParentVO parentVO = new ParentVO();
310                     parentVO.setStationCode(device);//工位
311                     parentVO.setSiteCode("3983");
312                     parentVO.setRecordId(UUID.randomUUID().toString());
313                     if("2".equals(stationStatus)){//工站状态
314                         parentVO.setTotalResult("0");
315                     }
316                     parentVO.setProductNum(snCode);
317                     parentVO.setCheckList(mesList);
318                     log.info("执行工厂MES方法start,工位号{} 传入数据:{}",device ,parentVO);
319                     HttpResponse execute = HttpRequest.post(Constants.FACTORY_EMS_UAT_GET_RUL+"deviceResultFeedback").body(JSONUtil.toJsonStr(parentVO)).execute();
320                     log.info("执行工厂MES方法end,工位号{} 返回数据:{}",device,execute.body());
321
509744 322                 });
d819b1 323             }
C 324         }catch (Exception e) {
325             throw new RuntimeException(e);
326         }
327         return result;
328     }
329
330     /**
331      * 接收工单信息
332      * @param thoroughfare 通道
333      * @param device 工位
334      * @param materialCode 物料号
335      * @throws Exception e
336      */
337     public synchronized void receivingWorkOrders(String thoroughfare ,String device ,String materialCode)
338     {
339         try {
340             String productNum = "";//模组码
341             String orderNum = "";//工单号
342
343             //先查询表中是否有剩余工单
344             List<OmProductionOrdeInfo> orderList = omProductionOrdeInfoService.list(new LambdaQueryWrapper<OmProductionOrdeInfo>()
345                     .eq(OmProductionOrdeInfo::getOrderStatus, Constants.ONE)
346                     .eq(OmProductionOrdeInfo::getStationCode,device)//工位
347                     .eq(OmProductionOrdeInfo::getProductCode,materialCode));//产品类型
348             if (CollUtil.isNotEmpty(orderList)){
349                 Long id = orderList.get(0).getId();
509744 350                 productNum = orderList.get(0).getProductNum();//产品码
d819b1 351                 orderNum = orderList.get(0).getWorkOrderNo();
C 352             }else{
353                 // 查询最新的工单信息
354                 OmProductionOrdeInfo lastOrder = omProductionOrdeInfoService.getLastOrder();
355
356                 log.info("请求工厂MES工单:入参device{},materialCode:{}", device, materialCode);
509744 357                 String orderJsonString = RestfulService.getProductionWorkOrderRequest(lastOrder.getProductNum(), "OP010",materialCode);
d819b1 358                 log.info("请求工厂MES工单:出参pack:{}", orderJsonString);
C 359
360                 JSONObject jsonObject = new JSONObject(orderJsonString);
361                 // 从JSONObject中获取data对象
362                 JSONObject dataObject = jsonObject.getJSONObject("data");
363                 String code = jsonObject.getStr("code");
364                 // 判断接单是否成功
365                 if(code.equals("success")) {
366                     OmProductionOrdeInfo omProductionOrdeInfo = new OmProductionOrdeInfo();
367                     omProductionOrdeInfo.setWorkOrderNo(dataObject.getStr("productionOrderNum"));
368                     omProductionOrdeInfo.setProductNum(dataObject.getStr("productNum"));
369                     omProductionOrdeInfo.setStationCode(device);
370                     omProductionOrdeInfo.setProductCode(dataObject.getStr("materialCode"));
371                     omProductionOrdeInfo.setPlanQty(Long.valueOf(dataObject.getStr("plannedQuantity")));
372                     omProductionOrdeInfo.setOnlineCompletionMark("0");
373                     omProductionOrdeInfo.setSfResult("0");
374                     omProductionOrdeInfo.setProductModel(dataObject.getStr("model"));
375                     omProductionOrdeInfo.setCreateTime(new Date());
376                     omProductionOrdeInfo.setCreateUser("工厂MES");
377                     omProductionOrdeInfoService.save(omProductionOrdeInfo);
378
379                     productNum = dataObject.getStr("productNum");
380                     orderNum = dataObject.getStr("productionOrderNum");
381                 }
382             }
383             //下发产品SN和工单号
384             if(!productNum.isEmpty() && !orderNum.isEmpty()){
8c09d8 385                 miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".SNCode").value(productNum).build());
d819b1 386                 miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".WorkOrderNumber").value(orderNum).build());
f3862f 387                 miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordSNDone").value(11).build());
d819b1 388             }
C 389
390         } catch (Exception e) {
391             throw new RuntimeException(e);
392         }
393     }
394
395     /**
a90728 396      * 更新工单
C 397      * @param snCode 产品sn
398      * @param orderStatus 工单状态
399      * @throws Exception e
400      */
401     private static void updateOrderStatus(String snCode,String orderStatus){
402         try {
403             //更新工单状态为已执行
404             LambdaUpdateWrapper<OmProductionOrdeInfo> updateWrapper = new LambdaUpdateWrapper<>();
405             updateWrapper.set(OmProductionOrdeInfo::getOrderStatus,orderStatus);
406             updateWrapper.eq(OmProductionOrdeInfo::getProductNum,snCode);
407             omProductionOrdeInfoService.update(new OmProductionOrdeInfo(),updateWrapper);
408         } catch (Exception e) {
409             throw new RuntimeException(e);
410         }
411
412     }
413
414     /**
d819b1 415      * 工厂MES报工
C 416      * @param productNum  通道
417      * @param stationCode 工位
418      * @param confirmTime 物料号
419      * @throws Exception e
420      */
421     //{"code":"success","data":{"productNum":"LCV123456P0600036","stationCode":"1HZ01","resultCode":"S","resultText":"报工成功"},"message":"API调用成功"}
422     public static void reportFactoryMes(String productNum, String stationCode, String confirmTime)
423     {
424         try {
a90728 425             CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> {
C 426                 log.info("请求工厂MES报工:入参device{},productNum:{}", stationCode, productNum);
427                 String url = Constants.FACTORY_EMS_UAT_GET_RUL + "workReportResultFeedback?siteCode="+Constants.FACTORY_EMS_SITE_CODE+"&stationCode="+stationCode+"&productNum="+productNum+"&confirmTime="+confirmTime;
428                 HttpResponse response = HttpRequest.get(url).execute();
429                 /*HttpRequest httpRequest = HttpRequest.get(url);*/
430                 String result =  response.body();
431                 log.info("请求工厂MES报工:出参:{}", result);
432             });
433
d819b1 434         }catch (Exception e){
C 435             throw new RuntimeException(e);
436         }
437     }
f3862f 438
C 439     public static String TightenTheConversionOkNg(String param){
440         // 去除首尾的方括号,然后按照逗号分割字符串
441         String[] parts = param.substring(1, param.length() - 1).split(",");
442
443         // 创建一个新的StringBuilder来构建替换后的字符串
444         StringBuilder sb = new StringBuilder();
445         sb.append('['); // 添加左方括号
446
447         for (int i = 0; i < parts.length; i++) {
448             String part = parts[i].trim(); // 去除可能的空格
449             float value;
450             try {
451                 value = Float.parseFloat(part); // 尝试将字符串转换为浮点数
452                 String replacement;
453                 if(i<2){
454                     replacement = part;
455                 }else{
456                     if (value == 1f) {
457                         replacement = "OK";
458                     } else{
459                         replacement = "NG";
460                     }
461                 }
462             /*    if (value == 1f) {
463                     replacement = "OK";
464                 } else if (value == 2f) {
465                     replacement = "NG";
466                 } else {
467                     replacement = part; // 如果不是1或2,则保持不变
468                 }*/
469                 sb.append(replacement);
470                 if (i < parts.length - 1) {
471                     sb.append(','); // 添加逗号(除了最后一个元素)
472                 }
473             } catch (NumberFormatException e) {
474                 // 如果转换失败,则保持原样(或进行其他错误处理)
475                 sb.append(part);
476                 if (i < parts.length - 1) {
477                     sb.append(',');
478                 }
479             }
480         }
481         sb.append(']'); // 添加右方括号
482         return sb.toString();
483     }
5b939f 484
C 485  /*   public static void main(String[] args) {
486         SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
487         String currentDate = dateFormat.format(new Date());
488         System.out.println(currentDate);
489     }*/
b78728 490 }