From 3d4e5941c728ff1c13d05195299c9c2163060ea4 Mon Sep 17 00:00:00 2001 From: Lius <Lius2225@163.com> Date: 星期六, 28 六月 2025 10:17:20 +0800 Subject: [PATCH] update --- lxzn-module-msi/src/main/java/org/jeecg/modules/msi/webapi/service/impl/MsiWebapiJsonServiceImpl.java | 148 +++++++++++++++++++++++++++++++++---------------- 1 files changed, 99 insertions(+), 49 deletions(-) diff --git a/lxzn-module-msi/src/main/java/org/jeecg/modules/msi/webapi/service/impl/MsiWebapiJsonServiceImpl.java b/lxzn-module-msi/src/main/java/org/jeecg/modules/msi/webapi/service/impl/MsiWebapiJsonServiceImpl.java index 5364928..d0f9f2c 100644 --- a/lxzn-module-msi/src/main/java/org/jeecg/modules/msi/webapi/service/impl/MsiWebapiJsonServiceImpl.java +++ b/lxzn-module-msi/src/main/java/org/jeecg/modules/msi/webapi/service/impl/MsiWebapiJsonServiceImpl.java @@ -3,8 +3,10 @@ import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import liquibase.util.JdbcUtils; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.jeecg.common.util.DateUtils; +import org.jeecg.common.util.RedisUtil; import org.jeecg.modules.msi.webapi.entity.MsiWebapiJsonEntity; import org.jeecg.modules.msi.webapi.mapper.MsiWebapiJsonMapper; import org.jeecg.modules.msi.webapi.service.IMsiWebapiJsonService; @@ -15,7 +17,9 @@ import org.springframework.jdbc.datasource.DataSourceUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.interceptor.TransactionAspectSupport; +import org.jetbrains.annotations.NotNull; +import javax.annotation.Resource; import java.sql.Connection; import java.sql.SQLException; import java.sql.Statement; @@ -24,29 +28,33 @@ import java.util.*; @Service +@Slf4j public class MsiWebapiJsonServiceImpl extends ServiceImpl<MsiWebapiJsonMapper, MsiWebapiJsonEntity> implements IMsiWebapiJsonService { @Autowired private JdbcTemplate jdbcTemplate; + @Resource + private RedisUtil redisUtil; + + private final static String ZDHKEY = "ZDHKEY_"; + /** * 瑙f瀽鍗曟潯鏁版嵁淇濆瓨鍒板崟琛� + * * @param data * @return */ @Override public boolean saveTableAutomationOne(List<MachineEquipentInfo> data) { - if (data ==null || data.isEmpty()) { + if (data == null || data.isEmpty()) { return false; } List<String> listStatus = new ArrayList<>(); List<String> listParameter = new ArrayList<>(); - // 鐢ㄤ簬璁板綍鍓嶄竴鏉¤褰曠殑鐘舵�佸�� - String prevRunningStatus = null; - for (MachineEquipentInfo machineInfo : data) { - System.out.println(machineInfo); +// log.info("鎺ユ敹鑷姩鍖栨暟鎹細" + machineInfo); // 鑾峰彇褰撳墠璁板綍鐨剅unningStatus鍊� String currentRunningStatus = null; @@ -57,23 +65,38 @@ } } - // 濡傛灉褰撳墠鐘舵�佷笌鍓嶄竴鏉$浉鍚岋紝鍒欒烦杩� - if (currentRunningStatus != null && currentRunningStatus.equals(prevRunningStatus)) { - continue; - } + // 鑾峰彇鍓嶄竴鏉$姸鎬� + if (redisUtil.hasKey(ZDHKEY + machineInfo.getMachineNo())) { + String prevRunningStatus = (String) redisUtil.get(ZDHKEY + machineInfo.getMachineNo()); - // 鏇存柊鍓嶄竴鏉¤褰曠殑鐘舵�佸�� - prevRunningStatus = currentRunningStatus; + // 濡傛灉褰撳墠鐘舵�佷笌鍓嶄竴鏉$浉鍚岋紝鍒欏彧鍐欏叆鍗曡〃鏁版嵁 + if (currentRunningStatus != null && currentRunningStatus.equals(prevRunningStatus)) { + String parameter = listSqlParameter(machineInfo); + if (parameter != null && !parameter.equals("")) { + listParameter.add(parameter); + } + continue; + } + + // 鏇存柊鍓嶄竴鏉¤褰曠殑鐘舵�佸�� + redisUtil.set(ZDHKEY + machineInfo.getMachineNo(), currentRunningStatus); + } else { + if (currentRunningStatus != null) { + redisUtil.set(ZDHKEY + machineInfo.getMachineNo(), currentRunningStatus); + } + } // 鐢熸垚SQL String stutus = listSqls(machineInfo); if (stutus != null && !stutus.equals("")) { listStatus.add(stutus); } + String parameter = listSqlParameter(machineInfo); if (parameter != null && !parameter.equals("")) { listParameter.add(parameter); } + } // 鎵ц鐘舵�佹暟鎹甋QL try { @@ -91,6 +114,7 @@ /** * 鎵归噺鎵цSQL璇彞 + * * @param sqlList SQL璇彞鍒楄〃 * @throws SQLException */ @@ -126,22 +150,23 @@ /** - * 鎻掑叆鍒癊quipmentLog + * 鎻掑叆鍒拌澶囧崟琛� + * * @param machineInfo * @return */ public String listSqlParameter(MachineEquipentInfo machineInfo) { String listSqls = null; List<DetailedListVo> itemList = machineInfo.getItemList(); - Map<String ,DetailedListVo> itemMap = new HashMap<String ,DetailedListVo>(); - for (DetailedListVo item: itemList) { - itemMap.put(item.getItemName(),item); + Map<String, DetailedListVo> itemMap = new HashMap<String, DetailedListVo>(); + for (DetailedListVo item : itemList) { + itemMap.put(item.getItemName(), item); } String sql = "insert into "; sql = sql + "ZDH_" + machineInfo.getMachineNo() + " "; sql = sql + "(EquipmentID,EquipmentName,CollectTime,runningStatus,spindleSpeed,feedRatio,runDuration,spindleDuration,progName,progStatus,toolNo) values ( "; //EquipmentID - if (machineInfo.getMachineNo() == null || machineInfo.getMachineNo().equals("")) { + if (machineInfo.getMachineNo() == null || machineInfo.getMachineNo().equals("")) { return null; } else { sql = sql + "'" + machineInfo.getMachineNo() + "', "; @@ -151,18 +176,7 @@ //CollectTime // 鍋囪 endTime 鏄� "MM/dd/yyyy HH:mm:ss" 鏍煎紡鐨勫瓧绗︿覆 if (machineInfo.getEndTime() != null && !machineInfo.getEndTime().isEmpty()) { - try { - // 1. 灏嗗瓧绗︿覆瑙f瀽涓� Date 瀵硅薄 - SimpleDateFormat inputFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss"); - Date endDate = inputFormat.parse(machineInfo.getEndTime()); - - // 2. 灏� Date 鏍煎紡鍖栦负鐩爣 SQL 鏍煎紡锛堝 "yyyy-MM-dd HH:mm:ss"锛� - SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - sql = sql + "'" + outputFormat.format(endDate) + "', "; - } catch (ParseException e) { - // 澶勭悊瑙f瀽澶辫触鐨勬儏鍐碉紙濡傛棩蹇楄褰曟垨鎶涘嚭寮傚父锛� - throw new RuntimeException("Invalid end time format: " + machineInfo.getEndTime(), e); - } + sql = getTime(machineInfo, sql); } else { // 濡傛灉 endTime 涓� null 鎴栫┖锛屼娇鐢ㄥ綋鍓嶆椂闂� sql = sql + "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) + "', "; @@ -182,7 +196,7 @@ //feedRatio if (itemMap.containsKey("feedRatio")) { sql = sql + "'" + itemMap.get("feedRatio").getItemValue() + "', "; - }else { + } else { sql = sql + "NULL, "; } //runDuration @@ -217,7 +231,7 @@ } sql = sql + "); \n"; - if (StringUtils.isBlank(listSqls) ) { + if (StringUtils.isBlank(listSqls)) { listSqls = sql; } else { listSqls += sql; @@ -227,7 +241,8 @@ /** - * 鎻掑叆鍒癊quipmentLog + * 鎻掑叆鍒癊quipmentLog + * * @param machineInfo * @return */ @@ -242,37 +257,72 @@ } sql = sql + null + ", "; if (machineInfo.getEndTime() != null) { - - sql = sql + "'" + DateUtils.formattedDate(machineInfo.getEndTime(),DateUtils.STR_DD_MM_YYYY,DateUtils.STR_DATE_TIME_SMALL) + "', "; + sql = getTime(machineInfo, sql); } else { return null; } - Map<String ,DetailedListVo> itemMap = new HashMap<String ,DetailedListVo>(); - for (DetailedListVo item: itemList) { - itemMap.put(item.getItemName(),item); + Map<String, DetailedListVo> itemMap = new HashMap<String, DetailedListVo>(); + for (DetailedListVo item : itemList) { + itemMap.put(item.getItemName(), item); } if (itemMap.containsKey("runningStatus")) { int oporation = 0; switch (itemMap.get("runningStatus").getItemValue()) { - case "0" : oporation =0;break; - case "1" : oporation =2;break; - case "2" : oporation =3;break; - case "3" : oporation =2;break; - case "4" : oporation =2;break; - case "10" : oporation =2;break; - case "13" : oporation =2;break; - case "14" : oporation =2;break; - case "10001" : oporation =2;break; - default: break; + case "0": + oporation = 0; + break; + case "1": + oporation = 2; + break; + case "2": + oporation = 3; + break; + case "3": + oporation = 2; + break; + case "4": + oporation = 2; + break; + case "10": + oporation = 2; + break; + case "13": + oporation = 2; + break; + case "14": + oporation = 2; + break; + case "10001": + oporation = 2; + break; + default: + break; } - sql = sql + " " + oporation + ", "; + sql = sql + " " + oporation + ", "; } else { return null; } - sql = sql + null + " ); \n"; - if (StringUtils.isBlank(listSqls) ) { + sql = sql + null + " ); \n"; + if (StringUtils.isBlank(listSqls)) { listSqls = sql; } return listSqls; } + + @NotNull + private String getTime(MachineEquipentInfo machineInfo, String sql) { + try { + // 1. 灏嗗瓧绗︿覆瑙f瀽涓� Date 瀵硅薄 + SimpleDateFormat inputFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss"); + Date endDate = inputFormat.parse(machineInfo.getEndTime()); + + // 2. 灏� Date 鏍煎紡鍖栦负鐩爣 SQL 鏍煎紡锛堝 "yyyy-MM-dd HH:mm:ss"锛� + SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + sql = sql + "'" + outputFormat.format(endDate) + "', "; + } catch (ParseException e) { + // 澶勭悊瑙f瀽澶辫触鐨勬儏鍐碉紙濡傛棩蹇楄褰曟垨鎶涘嚭寮傚父锛� + throw new RuntimeException("Invalid end time format: " + machineInfo.getEndTime(), e); + } + return sql; + } } -- Gitblit v1.9.3