From 1cbbb341d22e3c46b15af65b6f97d738bae7ca95 Mon Sep 17 00:00:00 2001 From: yangbin <yangbin> Date: 星期二, 20 五月 2025 10:46:57 +0800 Subject: [PATCH] 自动化 --- lxzn-module-msi/src/main/java/org/jeecg/modules/msi/webapi/controller/MsiWebapiJsonController.java | 24 ++-- lxzn-module-msi/src/main/java/org/jeecg/modules/msi/webapi/mapper/MsiWebapiJsonMapper.java | 2 lxzn-module-msi/src/main/java/org/jeecg/modules/msi/webapi/service/IMsiWebapiJsonService.java | 12 ++ lxzn-boot-base-core/src/main/java/org/jeecg/common/util/DateUtils.java | 42 ++++++++ lxzn-module-msi/src/main/java/org/jeecg/modules/msi/webapi/service/impl/MsiWebapiJsonServiceImpl.java | 167 +++++++++++++++++++++++++++++++++ 5 files changed, 236 insertions(+), 11 deletions(-) diff --git a/lxzn-boot-base-core/src/main/java/org/jeecg/common/util/DateUtils.java b/lxzn-boot-base-core/src/main/java/org/jeecg/common/util/DateUtils.java index 92f023e..f7ee46f 100644 --- a/lxzn-boot-base-core/src/main/java/org/jeecg/common/util/DateUtils.java +++ b/lxzn-boot-base-core/src/main/java/org/jeecg/common/util/DateUtils.java @@ -85,6 +85,48 @@ return new SimpleDateFormat("yyyy"); } }; + + public static final String STR_DATE = "yyyy-MM-dd"; + public static final String STRDATE = "yyyyMMdd"; + public static final String STR_YEAR_MONTH = "yyyy-MM"; + public static final String STRYEARMONTH = "yyyyMM"; + public static final String STR_DATE_TIME = "yyyy-MM-dd HH:mm:ss.SSS"; + public static final String STR_DATE_TIME_SMALL = "yyyy-MM-dd HH:mm:ss"; + public static final String STR_DD_MM_YYYY = "dd/MM/yyyy HH:mm:ss"; + public static final String STR_DATE_TIME_MIN = "yyyy-MM-dd HH:mm"; + public static final String STR_DATE_TIME_HOUR = "yyyy-MM-dd HH"; + public static final String STR_DATE_TIME_FULL = "yyyyMMddHHmmssSSS"; + public static final String STR_HHMMSS = "HH:mm:ss"; + public static final String STR_HHMM = "HH:mm"; + + public static String format(Date date, String format) { + SimpleDateFormat df = new SimpleDateFormat(format); + return df.format(date); + } + + public static String formattedDate(String dateString, String dateformat, String format) { + // 瀹氫箟鍘熷鏃ユ湡瀛楃涓插拰鍏舵牸寮� + SimpleDateFormat originalFormat = new SimpleDateFormat(dateformat); + // 瀹氫箟鐩爣鏃ユ湡鏍煎紡 + SimpleDateFormat targetFormat = new SimpleDateFormat(format); + try { + // 瑙f瀽鍘熷鏃ユ湡瀛楃涓� + Date date = originalFormat.parse(dateString); + // 灏嗘棩鏈熸牸寮忓寲涓虹洰鏍囨牸寮� + String formattedDate = targetFormat.format(date); + + // 杈撳嚭杞崲鍚庣殑鏃ユ湡瀛楃涓� + System.out.println(formattedDate); + return formattedDate; + } catch (ParseException e) { + e.printStackTrace(); + } + return null; + } + + + + /** * 浠ユ绉掕〃绀虹殑鏃堕棿 */ diff --git a/lxzn-module-msi/src/main/java/org/jeecg/modules/msi/webapi/controller/MsiWebapiJsonController.java b/lxzn-module-msi/src/main/java/org/jeecg/modules/msi/webapi/controller/MsiWebapiJsonController.java index 0a5734b..c8459f1 100644 --- a/lxzn-module-msi/src/main/java/org/jeecg/modules/msi/webapi/controller/MsiWebapiJsonController.java +++ b/lxzn-module-msi/src/main/java/org/jeecg/modules/msi/webapi/controller/MsiWebapiJsonController.java @@ -1,5 +1,6 @@ package org.jeecg.modules.msi.webapi.controller; +import com.alibaba.fastjson.JSON; import com.fasterxml.jackson.core.type.TypeReference; import io.swagger.annotations.Api; @@ -15,6 +16,7 @@ import org.jeecg.modules.msi.webapi.service.IMsiWebapiJsonService; import org.jeecg.modules.msi.webapi.vo.MachineEquipentInfo; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -27,31 +29,31 @@ @RequestMapping("/msi/webapi") public class MsiWebapiJsonController extends JeecgController<MsiWebapiJsonEntity, IMsiWebapiJsonService> { + + @AutoLog(value = "鑷姩鍖栫嚎鏁版嵁鎺ユ敹") @ApiOperation(value = "鑷姩鍖栫嚎鏁版嵁鎺ユ敹 ", notes = "鑷姩鍖栫嚎鏁版嵁鎺ユ敹") - @PostMapping(value = "/receiveAutomation") - public Result<?> receiveSaveMsiWebApiJson(String data) { + @RequestMapping(value = "/receiveAutomation") + public Result<?> receiveSaveMsiWebApiJson(@RequestBody List<MachineEquipentInfo> data) { MsiWebapiJsonEntity entity = new MsiWebapiJsonEntity(); - if (StringUtils.isBlank(data)) { + if (StringUtils.isBlank(data.toString())) { return Result.error("鏁版嵁涓虹┖",""); } entity.setModuleType("MDC"); - entity.setWebapiInfo(data); + entity.setWebapiInfo(data.toString()); //鍚庣画杩涜鍏朵粬涓氬姟鍏宠仈 JsonMapper mapper = new JsonMapper(); try { - List<MachineEquipentInfo> machineInfoList = mapper.fromJson(data, new TypeReference<List<MachineEquipentInfo>>(){}); - for (MachineEquipentInfo machineInfo : machineInfoList) { - + //List<MachineEquipentInfo> machineInfoList = mapper.fromJson(data, new TypeReference<List<MachineEquipentInfo>>(){}); + for (MachineEquipentInfo machineInfo : data) { System.out.println(machineInfo); - // Add additional processing logic here for each item + //瑙f瀽鏁版嵁 + service.saveTableAutomationOne(data); } - } catch (IOException e) { + } catch (Exception e) { log.error("JSON parsing error: {}", e.getMessage()); return Result.error("鏁版嵁寮傚父", e.getMessage()); - } - service.save(entity); return Result.OK("鎺ユ敹鎴愬姛"); } diff --git a/lxzn-module-msi/src/main/java/org/jeecg/modules/msi/webapi/mapper/MsiWebapiJsonMapper.java b/lxzn-module-msi/src/main/java/org/jeecg/modules/msi/webapi/mapper/MsiWebapiJsonMapper.java index 3d4ca98..8d4a775 100644 --- a/lxzn-module-msi/src/main/java/org/jeecg/modules/msi/webapi/mapper/MsiWebapiJsonMapper.java +++ b/lxzn-module-msi/src/main/java/org/jeecg/modules/msi/webapi/mapper/MsiWebapiJsonMapper.java @@ -5,4 +5,6 @@ import org.jeecg.modules.msi.webapi.entity.MsiWebapiJsonEntity; public interface MsiWebapiJsonMapper extends BaseMapper<MsiWebapiJsonEntity> { + + } diff --git a/lxzn-module-msi/src/main/java/org/jeecg/modules/msi/webapi/service/IMsiWebapiJsonService.java b/lxzn-module-msi/src/main/java/org/jeecg/modules/msi/webapi/service/IMsiWebapiJsonService.java index 3fa4d5b..f49f041 100644 --- a/lxzn-module-msi/src/main/java/org/jeecg/modules/msi/webapi/service/IMsiWebapiJsonService.java +++ b/lxzn-module-msi/src/main/java/org/jeecg/modules/msi/webapi/service/IMsiWebapiJsonService.java @@ -2,6 +2,18 @@ import com.baomidou.mybatisplus.extension.service.IService; import org.jeecg.modules.msi.webapi.entity.MsiWebapiJsonEntity; +import org.jeecg.modules.msi.webapi.vo.MachineEquipentInfo; + +import java.util.List; public interface IMsiWebapiJsonService extends IService<MsiWebapiJsonEntity> { + + + /** + * 瑙f瀽鍗曟潯鏁版嵁淇濆瓨鍒板崟琛� + * @param machineInfo + * @return + */ + boolean saveTableAutomationOne(List<MachineEquipentInfo> data); + } 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 ab23abd..72e2db6 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 @@ -1,11 +1,178 @@ package org.jeecg.modules.msi.webapi.service.impl; +import cn.hutool.core.date.DateUtil; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.apache.commons.lang3.StringUtils; +import org.jeecg.common.util.DateUtils; import org.jeecg.modules.msi.webapi.entity.MsiWebapiJsonEntity; import org.jeecg.modules.msi.webapi.mapper.MsiWebapiJsonMapper; import org.jeecg.modules.msi.webapi.service.IMsiWebapiJsonService; +import org.jeecg.modules.msi.webapi.vo.DetailedListVo; +import org.jeecg.modules.msi.webapi.vo.MachineEquipentInfo; import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; @Service public class MsiWebapiJsonServiceImpl extends ServiceImpl<MsiWebapiJsonMapper, MsiWebapiJsonEntity> implements IMsiWebapiJsonService { + + + @Override + public boolean saveTableAutomationOne(List<MachineEquipentInfo> data) { + if (data ==null || data.isEmpty()) { + return false; + } + List<String> listStatus = new ArrayList<>(); + List<String> listParameter = new ArrayList<>(); + for (MachineEquipentInfo machineInfo : data) { + System.out.println(machineInfo); + String stutus = listSqls(machineInfo); + if (stutus != null && !stutus.equals("")) { + listStatus.add(stutus); + } + String parameter = listSqlParameter(machineInfo); + if (parameter != null && !parameter.equals("")) { + listParameter.add(parameter); + } + } + //鐘舵�佹暟鎹� + + return false; + } + + + /** + * 鎻掑叆鍒癊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); + } + 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("")) { + return null; + } else { + sql = sql + "'" + machineInfo.getMachineNo() + "', "; + } + //EquipmentName + sql = sql + null + ", "; + //CollectTime + if (machineInfo.getEndTime() != null) { + sql = sql + "'" + DateUtils.formattedDate(machineInfo.getEndTime(),DateUtils.STR_DD_MM_YYYY,DateUtils.STR_DATE_TIME_SMALL) + "', "; + } else { + sql = sql + "'" + DateUtils.format(DateUtils.getDate(),DateUtils.STR_DATE_TIME) + "', "; + } + //runningStatus + if (itemMap.containsKey("runningStatus")) { + sql = sql + "'" + itemMap.get("runningStatus").getItemValue() + "', "; + } else { + sql = sql + null + ", "; + } + //spindleSpeed + if (itemMap.containsKey("spindleSpeed")) { + sql = sql + "'" + itemMap.get("spindleSpeed").getItemValue() + "', "; + } else { + sql = sql + null + ", "; + } + //runDuration + if (itemMap.containsKey("runDuration")) { + sql = sql + "'" + itemMap.get("runDuration").getItemValue() + "', "; + } else { + sql = sql + null + ", "; + } + //spindleDuration + if (itemMap.containsKey("spindleDuration")) { + sql = sql + "'" + itemMap.get("spindleDuration").getItemValue() + "', "; + } else { + sql = sql + null + ", "; + } + //progName + if (itemMap.containsKey("spindleSpeed")) { + sql = sql + "'" + itemMap.get("spindleSpeed").getItemValue() + "', "; + } else { + sql = sql + null + ", "; + } + //progStatus + if (itemMap.containsKey("progStatus")) { + sql = sql + "'" + itemMap.get("progStatus").getItemValue() + "', "; + } else { + sql = sql + null + ", "; + } + //toolNo + if (itemMap.containsKey("toolNo")) { + sql = sql + "'" + itemMap.get("toolNo").getItemValue() + "' "; + } else { + sql = sql + null; + } + + sql = sql + "); \n"; + if (StringUtils.isBlank(listSqls) ) { + listSqls = sql; + } else { + listSqls += sql; + } + return listSqls; + } + + + /** + * 鎻掑叆鍒癊quipmentLog + * @param machineInfo + * @return + */ + public String listSqls(MachineEquipentInfo machineInfo) { + String listSqls = null; + List<DetailedListVo> itemList = machineInfo.getItemList(); + String sql = "insert into EquipmentLog (EquipmentID,EquipmentName,CollectTime,Oporation,Alarm) values ( "; + if (machineInfo.getMachineNo() == null) { + return null; + } else { + sql = sql + "'" + machineInfo.getMachineNo() + "', "; + } + sql = sql + null + ", "; + if (machineInfo.getEndTime() != null) { + + sql = sql + "'" + DateUtils.formattedDate(machineInfo.getEndTime(),DateUtils.STR_DD_MM_YYYY,DateUtils.STR_DATE_TIME_SMALL) + "', "; + } else { + return null; + } + 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; + } + sql = sql + " " + oporation + ", "; + } else { + return null; + } + sql = sql + null + " ); \n"; + if (StringUtils.isBlank(listSqls) ) { + listSqls = sql; + } + return listSqls; + } } -- Gitblit v1.9.3