From d9cc58ecce404d1e906463c206e30271c10798a8 Mon Sep 17 00:00:00 2001 From: zch Date: Mon, 30 Sep 2024 16:48:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/EmsBaseEnergyPriceServiceImpl.java | 4 + .../impl/EmsBaseMonitorInfoServiceImpl.java | 7 + .../EmsBaseMonitorThresholdServiceImpl.java | 12 ++ .../impl/EmsBaseWorkUnitServiceImpl.java | 7 + .../impl/EmsRecordAlarmDataServiceImpl.java | 50 +++++++ .../service/impl/EmsReportServiceImpl.java | 129 +++++++++++------- .../mes/api/controller/ERPPortController.java | 17 +++ .../api/service/impl/ERPPortServiceImpl.java | 129 +++++++++++------- .../java/com/os/mes/api/utils/ApiUtils.java | 55 ++++---- .../impl/BaseProcessInfoServiceImpl.java | 12 ++ .../impl/BaseStaffInfoServiceImpl.java | 10 ++ .../service/impl/ProdBomInfoServiceImpl.java | 15 ++ 12 files changed, 316 insertions(+), 131 deletions(-) diff --git a/os-ems/src/main/java/com/os/ems/base/service/impl/EmsBaseEnergyPriceServiceImpl.java b/os-ems/src/main/java/com/os/ems/base/service/impl/EmsBaseEnergyPriceServiceImpl.java index 27b1b61..da44ad4 100644 --- a/os-ems/src/main/java/com/os/ems/base/service/impl/EmsBaseEnergyPriceServiceImpl.java +++ b/os-ems/src/main/java/com/os/ems/base/service/impl/EmsBaseEnergyPriceServiceImpl.java @@ -56,11 +56,15 @@ public class EmsBaseEnergyPriceServiceImpl implements IEmsBaseEnergyPriceService public int insertEmsBaseEnergyPrice(EmsBaseEnergyPrice emsBaseEnergyPrice) { try { + // 设置创建时间 emsBaseEnergyPrice.setCreateTime(DateUtils.getNowDate()); + // 插入能源月份单价 emsBaseEnergyPriceMapper.insertEmsBaseEnergyPrice(emsBaseEnergyPrice); } catch (Exception e) { + // 如果插入失败,抛出异常 throw new ServiceException("能源月份重复!"); } + // 返回结果 return 1; } diff --git a/os-ems/src/main/java/com/os/ems/base/service/impl/EmsBaseMonitorInfoServiceImpl.java b/os-ems/src/main/java/com/os/ems/base/service/impl/EmsBaseMonitorInfoServiceImpl.java index da1f401..9a7293b 100644 --- a/os-ems/src/main/java/com/os/ems/base/service/impl/EmsBaseMonitorInfoServiceImpl.java +++ b/os-ems/src/main/java/com/os/ems/base/service/impl/EmsBaseMonitorInfoServiceImpl.java @@ -141,21 +141,28 @@ public class EmsBaseMonitorInfoServiceImpl implements IEmsBaseMonitorInfoService @Override public List buildMonitorInfoTree(List baseMonitorInfos) { + // 定义一个返回的树结构列表 List returnList = new ArrayList(); + // 将所有节点的父节点id存入一个临时列表 List tempList = baseMonitorInfos.stream().map(EmsBaseMonitorInfo::getObjId).collect(Collectors.toList()); + // 遍历所有节点 for (EmsBaseMonitorInfo baseMonitorInfo : baseMonitorInfos) { // 如果是顶级节点, 遍历该父节点的所有子节点 if (!tempList.contains(baseMonitorInfo.getParentId())) { + // 递归遍历该父节点的所有子节点 recursionFn(baseMonitorInfos, baseMonitorInfo); + // 将该父节点加入返回列表 returnList.add(baseMonitorInfo); } } + // 如果返回列表为空,则返回所有节点 if (returnList.isEmpty()) { returnList = baseMonitorInfos; } + // 返回树结构列表 return returnList; } /** diff --git a/os-ems/src/main/java/com/os/ems/base/service/impl/EmsBaseMonitorThresholdServiceImpl.java b/os-ems/src/main/java/com/os/ems/base/service/impl/EmsBaseMonitorThresholdServiceImpl.java index 3c4ed3a..55970fa 100644 --- a/os-ems/src/main/java/com/os/ems/base/service/impl/EmsBaseMonitorThresholdServiceImpl.java +++ b/os-ems/src/main/java/com/os/ems/base/service/impl/EmsBaseMonitorThresholdServiceImpl.java @@ -46,18 +46,30 @@ public class EmsBaseMonitorThresholdServiceImpl implements IEmsBaseMonitorThresh */ @Override public List selectEmsBaseMonitorThresholdList(EmsBaseMonitorThreshold emsBaseMonitorThreshold) { + // 查询计量设备阈值维护列表 List monitorThresholds = emsBaseMonitorThresholdMapper.selectEmsBaseMonitorThresholdList(emsBaseMonitorThreshold); + // 如果查询结果为空,并且传入的监控编号不为空 if (monitorThresholds.size() == 0 && StringUtils.isNotEmpty(emsBaseMonitorThreshold.getMonitorCode())) { + // 创建监控信息对象 EmsBaseMonitorInfo monitorInfo = new EmsBaseMonitorInfo(); + // 设置监控编号 monitorInfo.setMonitorCode(emsBaseMonitorThreshold.getMonitorCode()); + // 查询监控信息列表 List monitorInfoList = emsBaseMonitorInfoMapper.selectEmsBaseMonitorInfoList(monitorInfo); + // 如果查询结果不为空,并且第一条数据的是否电表字段为1 if (monitorInfoList.size() > 0 && monitorInfoList.get(0).getIsAmmeter().equals("1")) { + // 创建计量设备阈值维护对象 EmsBaseMonitorInfo emsBaseMonitorInfo = monitorInfoList.get(0); + // 设置创建者 emsBaseMonitorThreshold.setCreateBy(SecurityUtils.getUsername()); + // 设置监控类型 emsBaseMonitorThreshold.setMonitorType(emsBaseMonitorInfo.getMonitorType()); + // 设置监控名称 emsBaseMonitorThreshold.setMonitorName(emsBaseMonitorInfo.getMonitorName()); + // 插入计量设备阈值维护 this.insertEmsBaseMonitorThreshold(emsBaseMonitorThreshold); + // 将插入的数据添加到查询结果列表中 monitorThresholds.add(emsBaseMonitorThreshold); } } diff --git a/os-ems/src/main/java/com/os/ems/base/service/impl/EmsBaseWorkUnitServiceImpl.java b/os-ems/src/main/java/com/os/ems/base/service/impl/EmsBaseWorkUnitServiceImpl.java index fe2181e..63b15d9 100644 --- a/os-ems/src/main/java/com/os/ems/base/service/impl/EmsBaseWorkUnitServiceImpl.java +++ b/os-ems/src/main/java/com/os/ems/base/service/impl/EmsBaseWorkUnitServiceImpl.java @@ -91,15 +91,22 @@ public class EmsBaseWorkUnitServiceImpl implements IEmsBaseWorkUnitService @Override public int deleteEmsBaseWorkUnitByObjIds(Long[] objIds) { + // 遍历统计单元信息主键数组 for (Long objId : objIds) { + // 根据主键查询统计单元信息 EmsBaseWorkUnit baseWorkUnit = this.selectEmsBaseWorkUnitByObjId(objId); + // 创建一个计量设备信息对象 EmsBaseMonitorWorkUnit monitorWorkUnit = new EmsBaseMonitorWorkUnit(); + // 设置计量设备信息对象的单位编码 monitorWorkUnit.setWorkUnitCode(baseWorkUnit.getWorkUnitCode()); + // 根据单位编码查询计量设备信息列表 List workUnits = emsBaseMonitorWorkUnitMapper.selectEmsBaseMonitorWorkUnitList(monitorWorkUnit); + // 如果计量设备信息列表长度大于0,则抛出异常 if (workUnits.size() > 0){ throw new ServiceException(baseWorkUnit.getWorkUnitName() + "已关联计量设备,无法删除!"); } } + // 返回删除统计单元信息的结果 return emsBaseWorkUnitMapper.deleteEmsBaseWorkUnitByObjIds(objIds); } diff --git a/os-ems/src/main/java/com/os/ems/record/service/impl/EmsRecordAlarmDataServiceImpl.java b/os-ems/src/main/java/com/os/ems/record/service/impl/EmsRecordAlarmDataServiceImpl.java index 5d2962f..9bdc29c 100644 --- a/os-ems/src/main/java/com/os/ems/record/service/impl/EmsRecordAlarmDataServiceImpl.java +++ b/os-ems/src/main/java/com/os/ems/record/service/impl/EmsRecordAlarmDataServiceImpl.java @@ -144,38 +144,60 @@ public class EmsRecordAlarmDataServiceImpl implements IEmsRecordAlarmDataService * 采集设备告警定时任务 */ public void collectDeviceAlarmsTask() { + // 定义分钟值 long minuteValue = 1000 * 60; + // 获取当前时间 Date date = new Date(); + // 实例化EmsRecordAlarmRule EmsRecordAlarmRule alarmRule = new EmsRecordAlarmRule(); + // 设置触发规则 alarmRule.setTriggerRule(1L); + // 查询告警规则 List alarmRules = emsRecordAlarmRuleMapper.selectEmsRecordAlarmRuleList(alarmRule); + // 如果查询结果不为空 if (alarmRules.size() > 0) { + // 设置分钟值 minuteValue = alarmRules.get(0).getDeviceOfflineTime() * minuteValue; } else { + // 如果查询结果为空,直接返回 return; } + // 实例化EmsBaseCollectDeviceInfo EmsBaseCollectDeviceInfo collectDeviceInfo = new EmsBaseCollectDeviceInfo(); + // 设置标志位 collectDeviceInfo.setIsFlag("1"); + // 查询采集设备信息 List deviceInfoList = emsBaseCollectDeviceInfoMapper.selectEmsBaseCollectDeviceInfoList(collectDeviceInfo); + // 如果查询结果不为空 if (deviceInfoList.size() > 0) { + // 实例化EmsRecordAlarmData EmsRecordAlarmData recordAlarmData = new EmsRecordAlarmData(); + // 设置告警类型 recordAlarmData.setAlarmType(1L); + // 设置告警状态 recordAlarmData.setAlarmStatus(1L); + // 查询告警数据 List alarmDataList = emsRecordAlarmDataMapper.selectEmsRecordAlarmDataList(recordAlarmData); + // 获取告警数据的collectDeviceId List collectDeviceIdList = alarmDataList.stream().map(EmsRecordAlarmData::getCollectDeviceId).collect(Collectors.toList()); + // 遍历采集设备信息 for (EmsBaseCollectDeviceInfo deviceInfo : deviceInfoList) { + // 如果告警数据中包含当前采集设备,跳过 if (collectDeviceIdList.contains(deviceInfo.getCollectDeviceId())) { continue; } + // 如果采集设备离线超过设置的分钟值,插入告警数据 if ((deviceInfo.getUpdateTime().getTime() + minuteValue) < date.getTime()) { EmsRecordAlarmData alarmData = new EmsRecordAlarmData(); alarmData.setCollectDeviceId(deviceInfo.getCollectDeviceId()); alarmData.setCollectTime(new Date()); alarmData.setAlarmType(1L); alarmData.setAlarmStatus(1L); + // 设置告警数据 alarmData.setAlarmData("设备离线已超过" + alarmRules.get(0).getDeviceOfflineTime() + "分钟"); + // 插入告警数据 this.insertEmsRecordAlarmData(alarmData); } } @@ -186,19 +208,28 @@ public class EmsRecordAlarmDataServiceImpl implements IEmsRecordAlarmDataService * 超过电阈值定时任务 */ public void exceedDnbThresholdAlarmsTask() { + // 创建EmsBaseMonitorThreshold对象,设置监测类型为2 EmsBaseMonitorThreshold monitorThreshold = new EmsBaseMonitorThreshold(); monitorThreshold.setMonitorType(2L); + // 查询阈值列表 List thresholdList = emsBaseMonitorThresholdMapper.selectEmsBaseMonitorThresholdList(monitorThreshold); + // 创建EmsRecordDnbInstant对象 EmsRecordDnbInstant dnbInstant = new EmsRecordDnbInstant(); + // 查询记录列表 List dnbInstantList = emsRecordDnbInstantMapper.selectEmsRecordDnbInstantList(dnbInstant); + // 比较阈值和记录,将超过阈值的记录存入map Map thresholdMap = compareThresholdAndRecord(thresholdList, dnbInstantList); //防止多次存入异常数据 + // 创建EmsRecordAlarmData对象,设置异常类型为0,异常状态为1 EmsRecordAlarmData recordAlarmData = new EmsRecordAlarmData(); recordAlarmData.setAlarmType(0L); recordAlarmData.setAlarmStatus(1L); + // 查询异常数据列表 List alarmDataList = emsRecordAlarmDataMapper.selectEmsRecordAlarmDataList(recordAlarmData); + // 将异常数据monitorId存入list List monitorIdList = alarmDataList.stream().map(EmsRecordAlarmData::getMonitorId).collect(Collectors.toList()); + // 遍历超过阈值的记录,如果已经存入异常数据,则跳过,否则存入异常数据 for (String monitorId : thresholdMap.keySet()) { if (monitorIdList.contains(monitorId)) { continue; @@ -222,23 +253,33 @@ public class EmsRecordAlarmDataServiceImpl implements IEmsRecordAlarmDataService * @return */ public Map compareThresholdAndRecord(List baseDnbThresholds, List recordDnbInstants) { + // 创建一个Map,用于存放结果 Map resultMap = new HashMap<>(); + // 遍历记录DnbInstants for (EmsRecordDnbInstant recordDnbInstant : recordDnbInstants) { + // 获取监测码 String monitorCode = recordDnbInstant.getMonitorCode(); + // 定义一个baseDnbThreshold,用于存放阈值 EmsBaseMonitorThreshold baseDnbThreshold = null; + // 遍历baseDnbThresholds,查找阈值 for (EmsBaseMonitorThreshold threshold : baseDnbThresholds) { if (threshold.getMonitorCode().equals(monitorCode)) { baseDnbThreshold = threshold; break; } } + // 如果baseDnbThreshold不为空 if (baseDnbThreshold != null) { + // 调用compare方法,比较记录和阈值 String reason = compare(recordDnbInstant, baseDnbThreshold); + // 如果比较结果不为空 if (reason != null) { + // 将结果存入Map resultMap.put(monitorCode, reason); } } } + // 返回结果 return resultMap; } @@ -294,16 +335,25 @@ public class EmsRecordAlarmDataServiceImpl implements IEmsRecordAlarmDataService * 小时耗量告警定时任务 */ public void hourlyConsumptionAlarmsTask() { + // 创建EmsBaseMonitorThreshold对象 EmsBaseMonitorThreshold monitorThreshold = new EmsBaseMonitorThreshold(); + // 设置监控类型为2 monitorThreshold.setMonitorType(2L); + // 查询监控阈值列表 List thresholdList = emsBaseMonitorThresholdMapper.selectEmsBaseMonitorThresholdList(monitorThreshold); + // 遍历监控阈值列表 for (EmsBaseMonitorThreshold threshold : thresholdList) { + // 获取小时耗量 BigDecimal consumption = threshold.getHourConsumption(); + // 如果小时耗量为0,则跳过本次循环 if (consumption.equals(new BigDecimal(0))){ continue; } + // 创建EmsReportPointDnb对象 EmsReportPointDnb reportPointDnb = new EmsReportPointDnb(); + // 设置监控编码 reportPointDnb.setMonitorCode(threshold.getMonitorCode()); + // 查询报告点列表 List dnbList = emsReportPointDnbMapper.selectEmsReportPointDnbList(reportPointDnb); } diff --git a/os-ems/src/main/java/com/os/ems/report/service/impl/EmsReportServiceImpl.java b/os-ems/src/main/java/com/os/ems/report/service/impl/EmsReportServiceImpl.java index 2835032..bff915d 100644 --- a/os-ems/src/main/java/com/os/ems/report/service/impl/EmsReportServiceImpl.java +++ b/os-ems/src/main/java/com/os/ems/report/service/impl/EmsReportServiceImpl.java @@ -35,25 +35,34 @@ public class EmsReportServiceImpl implements IEmsReportService { private EmsBaseWorkUnitMapper emsBaseWorkUnitMapper; - /** - * 统计能耗报表 - * - * @param hashMap - * @return - */ - @Override - public List energyStatisticalReportList(Map hashMap) { - if (!hashMap.containsKey("dateType") && !hashMap.containsKey("energyType")) { - return null; - } - hashMap.put("timeSub", Integer.parseInt(String.valueOf(hashMap.get("dateType")))); - List reportList = new ArrayList<>(); - - if (Objects.equals(String.valueOf(hashMap.get("energyType")), "2")){ - reportList = emsReportMapper.energyStatisticalDnbReportList(hashMap); - } - return reportList; +/** + * 统计能耗报表 + *

+ * 根据给定的参数,统计相应的能耗报表数据如果参数中不包含日期类型和能耗类型,则返回null + * 根据不同的能耗类型,可能会调用不同的数据处理逻辑 + *

+ * + * @param hashMap 包含查询参数的哈希表,包括日期类型(dateType)和能耗类型(energyType) + * @return 返回能耗报表列表,如果没有有效的参数,则可能返回null + */ +@Override +public List energyStatisticalReportList(Map hashMap) { + // 检查必要的参数是否缺失 + if (!hashMap.containsKey("dateType") && !hashMap.containsKey("energyType")) { + return null; + } + // 计算时间差,基于日期类型 + hashMap.put("timeSub", Integer.parseInt(String.valueOf(hashMap.get("dateType")))); + // 初始化能耗报表列表 + List reportList = new ArrayList<>(); + + // 根据能耗类型调用相应的报表生成逻辑 + if (Objects.equals(String.valueOf(hashMap.get("energyType")), "2")){ + reportList = emsReportMapper.energyStatisticalDnbReportList(hashMap); } + // 返回报表列表 + return reportList; +} /** * 峰平谷耗量报表 @@ -69,43 +78,57 @@ public class EmsReportServiceImpl implements IEmsReportService { return emsReportMapper.peaksValleysConsumptionReportList(hashMap); } - /** - * 能源预览接口 - * - * @param hashMap - * @return - */ - @Override - public List> energyPreviewReportList(Map hashMap) { - List> resultList = new ArrayList<>(); - if (!hashMap.containsKey("startTime") || !hashMap.containsKey("endTime")) { - return resultList; - } +/** + * 能源预览接口 + * 该方法用于生成能源预览报告列表,根据给定的参数筛选和统计能源消耗数据 + * + * @param hashMap 包含查询条件的键值对,如startTime, endTime, dateType, energyType + * @return 返回一个列表,包含每个工作单元在指定时间范围内的能源消耗报告 + */ +@Override +public List> energyPreviewReportList(Map hashMap) { + // 初始化结果列表 + List> resultList = new ArrayList<>(); + // 检查是否同时提供了开始时间和结束时间,如果未提供则直接返回空列表 + if (!hashMap.containsKey("startTime") || !hashMap.containsKey("endTime")) { + return resultList; + } - EmsBaseWorkUnit workUnit = new EmsBaseWorkUnit(); - List workUnits = emsBaseWorkUnitMapper.selectEmsBaseWorkUnitList(workUnit); - - HashMap selectMap = new HashMap<>(); - selectMap.put("dateType", String.valueOf(hashMap.get("dateType"))); - selectMap.put("energyType", String.valueOf(hashMap.get("energyType"))); - selectMap.put("beginCollectTime", String.valueOf(hashMap.get("startTime"))); - selectMap.put("endCollectTime", String.valueOf(hashMap.get("endTime"))); - - for (EmsBaseWorkUnit unit : workUnits) { - HashMap typeResultMap = new HashMap<>(); - typeResultMap.put("unitName", unit.getWorkUnitName()); - selectMap.put("workUnitCode", unit.getWorkUnitCode()); - List reportList = this.energyStatisticalReportList(selectMap); - BigDecimal expendSum = new BigDecimal(0); - for (EnergyStatisticalReport report : reportList) { - typeResultMap.put("expend" + report.getBeginTime(), report.getExpend()); - expendSum = expendSum.add(report.getExpend()); - } - typeResultMap.put("expendSum", expendSum.toPlainString()); - resultList.add(typeResultMap); + // 创建并查询所有工作单元信息 + EmsBaseWorkUnit workUnit = new EmsBaseWorkUnit(); + List workUnits = emsBaseWorkUnitMapper.selectEmsBaseWorkUnitList(workUnit); + + // 初始化用于查询能源统计报告的参数映射 + HashMap selectMap = new HashMap<>(); + selectMap.put("dateType", String.valueOf(hashMap.get("dateType"))); + selectMap.put("energyType", String.valueOf(hashMap.get("energyType"))); + selectMap.put("beginCollectTime", String.valueOf(hashMap.get("startTime"))); + selectMap.put("endCollectTime", String.valueOf(hashMap.get("endTime"))); + + // 遍历每个工作单元,查询并统计能源消耗数据 + for (EmsBaseWorkUnit unit : workUnits) { + // 初始化当前工作单元的能源消耗结果映射 + HashMap typeResultMap = new HashMap<>(); + typeResultMap.put("unitName", unit.getWorkUnitName()); + // 在查询映射中添加工作单元代码 + selectMap.put("workUnitCode", unit.getWorkUnitCode()); + // 调用方法查询当前工作单元的能源统计报告列表 + List reportList = this.energyStatisticalReportList(selectMap); + // 初始化能源消耗总和 + BigDecimal expendSum = new BigDecimal(0); + // 遍历报告列表,累加能源消耗数据 + for (EnergyStatisticalReport report : reportList) { + typeResultMap.put("expend" + report.getBeginTime(), report.getExpend()); + expendSum = expendSum.add(report.getExpend()); } - - return resultList; + // 将能源消耗总和添加到结果映射中 + typeResultMap.put("expendSum", expendSum.toPlainString()); + // 将当前工作单元的能源消耗结果映射添加到结果列表中 + resultList.add(typeResultMap); } + // 返回能源预览报告列表 + return resultList; +} + } diff --git a/os-mes/src/main/java/com/os/mes/api/controller/ERPPortController.java b/os-mes/src/main/java/com/os/mes/api/controller/ERPPortController.java index c610d0c..199d965 100644 --- a/os-mes/src/main/java/com/os/mes/api/controller/ERPPortController.java +++ b/os-mes/src/main/java/com/os/mes/api/controller/ERPPortController.java @@ -31,12 +31,19 @@ public class ERPPortController extends BaseController { */ @PostMapping("/getERPOrderData") public AjaxResult getERPOrderData(@RequestBody Map paramMap) { + // 创建ERPParamDto对象 ERPParamDto paramDto = new ERPParamDto(); + // 设置AppCode paramDto.setAppCode(String.valueOf(paramMap.get("AppCode"))); + // 设置Controller paramDto.setController(String.valueOf(paramMap.get("Controller"))); + // 设置ActionName paramDto.setActionName(String.valueOf(paramMap.get("ActionName"))); + // 设置OrderStartTime paramDto.setOrderStartTime(String.valueOf(paramMap.get("OrderStartTime"))); + // 设置OrderEndTime paramDto.setOrderEndTime(String.valueOf(paramMap.get("OrderEndTime"))); + // 调用portService的getERPOrderData方法,传入paramDto,获取ERP订单数据 return AjaxResult.success(portService.getERPOrderData(paramDto)); } @@ -48,10 +55,15 @@ public class ERPPortController extends BaseController { */ @PostMapping("/getERPEmployeeWageData") public AjaxResult getERPEmployeeWageData(@RequestBody Map paramMap) { + // 创建ERPParamDto对象 ERPParamDto paramDto = new ERPParamDto(); + // 设置AppCode paramDto.setAppCode(String.valueOf(paramMap.get("AppCode"))); + // 设置Controller paramDto.setController(String.valueOf(paramMap.get("Controller"))); + // 设置ActionName paramDto.setActionName(String.valueOf(paramMap.get("ActionName"))); + // 调用portService的getERPEmployeeWageData方法,并返回结果 return AjaxResult.success(portService.getERPEmployeeWageData(paramDto)); } @@ -63,10 +75,15 @@ public class ERPPortController extends BaseController { */ @PostMapping("/getERPLatestSalaryData") public AjaxResult getERPLatestSalaryData(@RequestBody Map paramMap) { + // 创建ERPParamDto对象 ERPParamDto paramDto = new ERPParamDto(); + // 设置AppCode paramDto.setAppCode(String.valueOf(paramMap.get("AppCode"))); + // 设置Controller paramDto.setController(String.valueOf(paramMap.get("Controller"))); + // 设置ActionName paramDto.setActionName(String.valueOf(paramMap.get("ActionName"))); + // 调用portService的getERPLatestSalaryData方法,并返回结果 return AjaxResult.success(portService.getERPLatestSalaryData(paramDto)); } diff --git a/os-mes/src/main/java/com/os/mes/api/service/impl/ERPPortServiceImpl.java b/os-mes/src/main/java/com/os/mes/api/service/impl/ERPPortServiceImpl.java index 4a64bd9..c3864cd 100644 --- a/os-mes/src/main/java/com/os/mes/api/service/impl/ERPPortServiceImpl.java +++ b/os-mes/src/main/java/com/os/mes/api/service/impl/ERPPortServiceImpl.java @@ -86,23 +86,34 @@ public class ERPPortServiceImpl implements IERPPortService { */ @Override public List getERPEmployeeWageData(ERPParamDto paramDto) { + // 定义一个返回的员工信息列表 List resultList = new ArrayList<>(); + // 定义一个请求参数 String requestParam = null; + // 定义一个接口返回结果 String result = null; try { // 创建ObjectMapper实例 对象转JSON字符串 ObjectMapper objectMapper = new ObjectMapper(); + // 设置对象转换为JSON字符串的命名策略 objectMapper.setPropertyNamingStrategy(PropertyNamingStrategy.UPPER_CAMEL_CASE); + // 将ERPParamDto对象转换为JSON字符串 requestParam = objectMapper.writeValueAsString(paramDto); + // 调用接口获取返回结果 result = ApiUtils.sendERPHttpPost(ERPConstants.ERP_URL, requestParam); // 处理接口返回消息 ObjectMapper resultMapper = new ObjectMapper(); // 将 JSON 字符串转换为 Java 对象 HashMap hashMap = resultMapper.readValue(result, HashMap.class); + // 获取返回数据 HashMap returnData = (HashMap)hashMap.get("ReturnData"); + // 获取数据列表 List> dataList = (List>)returnData.get("data"); + // 遍历数据列表 for (HashMap data : dataList) { + // 将数据插入员工信息表 BaseStaffInfo baseStaffInfo = staffInfoService.insertStaffByERP(data); + // 将员工信息添加到返回列表中 resultList.add(baseStaffInfo); } logger.warn("获取员工工资系数成功:" + requestParam + "|" + result); @@ -152,58 +163,74 @@ public class ERPPortServiceImpl implements IERPPortService { return latestSalary; } - /** - * 新增【薪资明细】 - * @param recordStaffSalary - * @return - */ - @Override - public String addSalaryBreakdown(RecordStaffSalary recordStaffSalary) { - String objectId = null;//ERP返回数据的ObjectId - String requestParam = null; - String result = null; - ERPStaffSalary erpStaffSalary = new ERPStaffSalary(); - erpStaffSalary.setAppCode(ERPConstants.addSalaryAppCode); - erpStaffSalary.setController(ERPConstants.addSalaryController); - erpStaffSalary.setActionName(ERPConstants.addSalaryActionName); - erpStaffSalary.setIdCard(recordStaffSalary.getIdCard()); - erpStaffSalary.setGroupId(recordStaffSalary.getGroupId()); - erpStaffSalary.setEventDate(recordStaffSalary.getEventDate()); - erpStaffSalary.setSalaryCategory(recordStaffSalary.getSalaryCategory()); - erpStaffSalary.setRevenueClass(recordStaffSalary.getRevenueClass()); - erpStaffSalary.setRevenueAmount(recordStaffSalary.getRevenueAmount()); - erpStaffSalary.setRevenueReason(recordStaffSalary.getRevenueReason()); - try { - // 创建ObjectMapper实例 对象转JSON字符串 - ObjectMapper objectMapper = new ObjectMapper(); - objectMapper.setPropertyNamingStrategy(PropertyNamingStrategy.UPPER_CAMEL_CASE); - requestParam = objectMapper.writeValueAsString(erpStaffSalary); -// result = ApiUtils.sendERPHttpPost(ERPConstants.ERP_URL, requestParam); - result = "{\n" + - "\t\"Successful\": true,\n" + - "\t\"ErrorMessage\": null,\n" + - "\t\"Logined\": false,\n" + - "\t\"ReturnData\": {\n" + - "\t\t\"data\": {\n" + - "\t\t\t\"ObjectId\": \"25ff81b4-fb0b-4f1c-b9b1-6a2afab1cd0f\"\n" + - "\t\t},\n" + - "\t\t\"result\": \"success\",\n" + - "\t\t\"message\": \"创建成功!\"\n" + - "\t},\n" + - "\t\"DataType\": 0\n" + - "}"; - // 处理接口返回消息 - ObjectMapper resultMapper = new ObjectMapper(); - // 将 JSON 字符串转换为 Java 对象 - HashMap hashMap = resultMapper.readValue(result, HashMap.class); - HashMap returnData = (HashMap)hashMap.get("ReturnData"); - HashMap data = (HashMap)returnData.get("data"); - objectId = String.valueOf(data.get("ObjectId")); - } catch (Exception e) { - logger.warn("新增【薪资明细】异常:" + requestParam + "|" + result + "|" + e); - } - return objectId; +/** + * 新增【薪资明细】 + * 该方法用于将员工的薪资明细添加到系统中,通过调用ERP系统的接口来完成 + * @param recordStaffSalary 包含员工薪资明细的RecordStaffSalary对象 + * @return 返回ERP系统生成的ObjectId,用于唯一标识新增的薪资记录 + */ +@Override +public String addSalaryBreakdown(RecordStaffSalary recordStaffSalary) { + // ERP返回数据的ObjectId,用于唯一标识新增的记录 + String objectId = null; + // 用于存储发送给ERP系统的请求参数的字符串 + String requestParam = null; + // ERP系统返回的结果 + String result = null; + // 创建一个ERPStaffSalary对象,用于准备发送给ERP系统的请求数据 + ERPStaffSalary erpStaffSalary = new ERPStaffSalary(); + + // 设置ERP系统请求的参数 + erpStaffSalary.setAppCode(ERPConstants.addSalaryAppCode); + erpStaffSalary.setController(ERPConstants.addSalaryController); + erpStaffSalary.setActionName(ERPConstants.addSalaryActionName); + erpStaffSalary.setIdCard(recordStaffSalary.getIdCard()); + erpStaffSalary.setGroupId(recordStaffSalary.getGroupId()); + erpStaffSalary.setEventDate(recordStaffSalary.getEventDate()); + erpStaffSalary.setSalaryCategory(recordStaffSalary.getSalaryCategory()); + erpStaffSalary.setRevenueClass(recordStaffSalary.getRevenueClass()); + erpStaffSalary.setRevenueAmount(recordStaffSalary.getRevenueAmount()); + erpStaffSalary.setRevenueReason(recordStaffSalary.getRevenueReason()); + + try { + // 创建ObjectMapper实例 对象转JSON字符串 + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.setPropertyNamingStrategy(PropertyNamingStrategy.UPPER_CAMEL_CASE); + // 将erpStaffSalary对象转换为JSON字符串,以便发送给ERP系统 + requestParam = objectMapper.writeValueAsString(erpStaffSalary); + // 使用API工具类发送HTTP POST请求到ERP系统,这里代码已省略 + // result = ApiUtils.sendERPHttpPost(ERPConstants.ERP_URL, requestParam); + + // 模拟ERP系统返回的结果 + result = "{\n" + + "\t\"Successful\": true,\n" + + "\t\"ErrorMessage\": null,\n" + + "\t\"Logined\": false,\n" + + "\t\"ReturnData\": {\n" + + "\t\t\"data\": {\n" + + "\t\t\t\"ObjectId\": \"25ff81b4-fb0b-4f1c-b9b1-6a2afab1cd0f\"\n" + + "\t\t},\n" + + "\t\t\"result\": \"success\",\n" + + "\t\t\"message\": \"创建成功!\"\n" + + "\t},\n" + + "\t\"DataType\": 0\n" + + "}"; + + // 处理接口返回消息 + ObjectMapper resultMapper = new ObjectMapper(); + // 将 JSON 字符串转换为 Java 对象 + HashMap hashMap = resultMapper.readValue(result, HashMap.class); + HashMap returnData = (HashMap)hashMap.get("ReturnData"); + HashMap data = (HashMap)returnData.get("data"); + // 提取并返回ObjectId + objectId = String.valueOf(data.get("ObjectId")); + } catch (Exception e) { + // 记录异常信息,包括请求参数、结果和异常详情 + logger.warn("新增【薪资明细】异常:" + requestParam + "|" + result + "|" + e); } + // 返回ERP系统生成的ObjectId + return objectId; +} } diff --git a/os-mes/src/main/java/com/os/mes/api/utils/ApiUtils.java b/os-mes/src/main/java/com/os/mes/api/utils/ApiUtils.java index 5de852c..53a48ed 100644 --- a/os-mes/src/main/java/com/os/mes/api/utils/ApiUtils.java +++ b/os-mes/src/main/java/com/os/mes/api/utils/ApiUtils.java @@ -14,32 +14,33 @@ import cn.hutool.http.HttpResponse; public class ApiUtils { - /** - * POST请求json格式 - * @param apiUrl - * @param jsonData - * @return - */ - public static String sendERPHttpPost(String apiUrl, String jsonData) { - try { - // 构建POST请求 - HttpRequest request = HttpRequest.post(apiUrl) - .header("EngineCode", ERPConstants.EngineCode) - .header("EngineSecret", ERPConstants.EngineSecret) - .body(jsonData) // 设置JSON格式的请求体 - .contentType("application/json") // 设置Content-Type为application/json - .setConnectionTimeout(1000 * 60 * 10) // 设置请求连接超时时间 - ; - - // 发送POST请求 - HttpResponse httpResponse = request.execute(); - - // 获取响应内容 - return httpResponse.body(); - } catch (Exception e) { - // 捕获异常并重新抛出自定义异常 - throw new RuntimeException("Failed to send ERP HTTP POST request: " + e.getMessage(), e); - } - +/** + * 发送ERP系统的POST请求,请求数据为JSON格式 + * 此方法用于与ERP系统交互,发送JSON格式的数据请求,并接收响应 + * + * @param apiUrl ERP系统的API网址 + * @param jsonData 要发送的JSON格式的数据 + * @return 返回ERP系统的响应数据 + */ +public static String sendERPHttpPost(String apiUrl, String jsonData) { + try { + // 构建POST请求 + HttpRequest request = HttpRequest.post(apiUrl) + .header("EngineCode", ERPConstants.EngineCode) + .header("EngineSecret", ERPConstants.EngineSecret) + .body(jsonData) // 设置JSON格式的请求体 + .contentType("application/json") // 设置Content-Type为application/json + .setConnectionTimeout(1000 * 60 * 10) // 设置请求连接超时时间为10分钟 + ; + + // 发送POST请求 + HttpResponse httpResponse = request.execute(); + + // 获取响应内容 + return httpResponse.body(); + } catch (Exception e) { + // 捕获异常并重新抛出自定义异常 + throw new RuntimeException("Failed to send ERP HTTP POST request: " + e.getMessage(), e); } } +} diff --git a/os-mes/src/main/java/com/os/mes/base/service/impl/BaseProcessInfoServiceImpl.java b/os-mes/src/main/java/com/os/mes/base/service/impl/BaseProcessInfoServiceImpl.java index 0faab61..dac1175 100644 --- a/os-mes/src/main/java/com/os/mes/base/service/impl/BaseProcessInfoServiceImpl.java +++ b/os-mes/src/main/java/com/os/mes/base/service/impl/BaseProcessInfoServiceImpl.java @@ -48,28 +48,40 @@ public class BaseProcessInfoServiceImpl implements IBaseProcessInfoService { */ @Override public List selectBaseProcessInfoList(BaseProcessInfo baseProcessInfo) { + // 查询工序信息列表 List processList = baseProcessInfoMapper.selectBaseProcessInfoList(baseProcessInfo); + // 查询产线信息列表 BaseProductLine productLine = new BaseProductLine(); productLine.setProductLineType("2"); List stationList = baseProductLineMapper.selectBaseProductLineList(productLine); + // 遍历工序信息列表 for (BaseProcessInfo processInfo : processList) { + // 获取工位编码 String stationCodes = processInfo.getStationCodes(); + // 如果工位编码为空,跳过此次循环 if (StringUtils.isEmpty(stationCodes)) { continue; } + // 将工位编码以逗号分割成数组 String[] stationCodeList = stationCodes.split(","); + // 遍历工位编码数组 for (String stationCode : stationCodeList) { + // 过滤出工位编码相同的产线信息 List baseProductLines = stationList.stream().filter(e -> Objects.equals(e.getProductLineCode(), stationCode)).collect(Collectors.toList()); + // 如果过滤出的产线信息不为空,获取产线名称,并设置到工序信息中 if (baseProductLines.size() > 0) { String productLineName = baseProductLines.get(0).getProductLineName(); + // 如果工序信息的工位名称称为空,将当前产线名称设置到工序信息中 if (StringUtils.isEmpty(processInfo.getStationNames())) { processInfo.setStationNames(productLineName); } else { + // 如果工序信息的工位名称不为空,将当前产线名称以逗号分割拼接到工序信息的工位名称中 processInfo.setStationNames(processInfo.getStationNames() + "," + productLineName); } } } } + // 返回工序信息列表 return processList; } diff --git a/os-mes/src/main/java/com/os/mes/base/service/impl/BaseStaffInfoServiceImpl.java b/os-mes/src/main/java/com/os/mes/base/service/impl/BaseStaffInfoServiceImpl.java index a339c71..5fbf6b7 100644 --- a/os-mes/src/main/java/com/os/mes/base/service/impl/BaseStaffInfoServiceImpl.java +++ b/os-mes/src/main/java/com/os/mes/base/service/impl/BaseStaffInfoServiceImpl.java @@ -47,21 +47,31 @@ public class BaseStaffInfoServiceImpl implements IBaseStaffInfoService { */ @Override public List selectBaseStaffInfoList(BaseStaffInfo baseStaffInfo) { + // 查询员工信息 List baseStaffInfos = baseStaffInfoMapper.selectBaseStaffInfoList(baseStaffInfo); + // 查询员工团队信息 List teamMembers = baseTeamMembersMapper.selectBaseTeamMembersList(new BaseTeamMembers()); + // 遍历员工信息 for (BaseStaffInfo staffInfo : baseStaffInfos) { + // 如果员工信息中存在团队编码 if (StringUtils.isNotEmpty(staffInfo.getTeamCode())){ + // 遍历员工团队信息 for (BaseTeamMembers teamMember : teamMembers) { + // 如果员工信息中的团队编码包含员工团队信息中的团队编码 if (staffInfo.getTeamCode().contains(teamMember.getTeamCode())){ + // 如果员工信息中的团队名称为空 if (StringUtils.isEmpty(staffInfo.getTeamName())){ + // 将员工团队信息中的团队名称赋值给员工信息 staffInfo.setTeamName(teamMember.getTeamName()); } else { + // 将员工团队信息中的团队名称拼接到员工信息中的团队名称后面 staffInfo.setTeamName(staffInfo.getTeamName() + "," + teamMember.getTeamName()); } } } } } + // 返回员工信息 return baseStaffInfos; } diff --git a/os-mes/src/main/java/com/os/mes/prod/service/impl/ProdBomInfoServiceImpl.java b/os-mes/src/main/java/com/os/mes/prod/service/impl/ProdBomInfoServiceImpl.java index 9568789..50c11a4 100644 --- a/os-mes/src/main/java/com/os/mes/prod/service/impl/ProdBomInfoServiceImpl.java +++ b/os-mes/src/main/java/com/os/mes/prod/service/impl/ProdBomInfoServiceImpl.java @@ -53,17 +53,25 @@ public class ProdBomInfoServiceImpl implements IProdBomInfoService { */ @Override public List selectProductionBomTreeList(ProdBomInfo prodBomInfo) { + // 创建一个用于存储ProdBomInfo对象的列表 List prodBomInfoList = new ArrayList<>(); + // 根据objId查询ProdBomInfo对象 ProdBomInfo info = prodBomInfoMapper.selectProdBomInfoByObjId(prodBomInfo.getObjId()); + // 将查询到的ProdBomInfo对象添加到prodBomInfoList中 prodBomInfoList.add(info); try { + // 创建一个新的ProdBomInfo对象 ProdBomInfo bomInfo = new ProdBomInfo(); + // 设置bomInfo的ancestors属性为info的objId bomInfo.setAncestors(info.getObjId().toString()); + // 根据bomInfo的ancestors属性查询ProdBomInfo列表 List infos = prodBomInfoMapper.selectProdBomInfoList(bomInfo); + // 将查询到的ProdBomInfo列表添加到prodBomInfoList中 prodBomInfoList.addAll(infos); } catch (Exception e) { e.printStackTrace(); } + // 返回prodBomInfoList return prodBomInfoList; } @@ -75,17 +83,24 @@ public class ProdBomInfoServiceImpl implements IProdBomInfoService { */ @Override public int insertProdBomInfo(ProdBomInfo prodBomInfo) { + // 根据物料编码查询生产BOM List baseBomInfos = prodBomInfoMapper.selectProdBomInfoList(prodBomInfo); + // 如果查询结果大于0,则抛出异常 if (baseBomInfos.size() > 0) { throw new BaseException("该物料BOM:" + prodBomInfo.getMaterialCode() + "已存在!"); } + // 根据父ID查询生产BOM ProdBomInfo info = prodBomInfoMapper.selectProdBomInfoByObjId(prodBomInfo.getParentId()); + // 如果查询结果为空,则设置 ancestors 为 parentId if (StringUtils.isNull(info)) { prodBomInfo.setAncestors(prodBomInfo.getParentId().toString()); } else { + // 否则设置 ancestors 为父ID的ancestors加上parentId prodBomInfo.setAncestors(info.getAncestors() + "," + prodBomInfo.getParentId()); } + // 设置创建时间 prodBomInfo.setCreateTime(DateUtils.getNowDate()); + // 插入生产BOM return prodBomInfoMapper.insertProdBomInfo(prodBomInfo); }