diff --git a/mhd-api/mhd-api-system/src/main/java/com/mhd/system/api/XxlJobServiceFeign.java b/mhd-api/mhd-api-system/src/main/java/com/mhd/system/api/XxlJobServiceFeign.java new file mode 100644 index 000000000..7010ba691 --- /dev/null +++ b/mhd-api/mhd-api-system/src/main/java/com/mhd/system/api/XxlJobServiceFeign.java @@ -0,0 +1,23 @@ +package com.mhd.system.api; + + +import com.mhd.common.core.constant.ServiceNameConstants; +import com.mhd.common.core.domain.entity.R; +import com.mhd.common.core.domain.dto.YmsSysUserDTO; +import com.mhd.system.api.domain.YmsLoginUser; +import com.mhd.system.api.factory.RemoteBmsFeignFallbackFactory; +import com.mhd.system.api.factory.RemoteXxlJobFeignFallbackFactory; +import com.mhd.system.api.feign.FeignAutoConfiguration; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.*; + +import java.util.Map; + +@FeignClient(contextId = "XxlJobService", value = ServiceNameConstants.XXL_JOB_SERVICE,url = "http://127.0.0.1:8020",fallbackFactory = RemoteXxlJobFeignFallbackFactory.class, configuration = FeignAutoConfiguration.class) +public interface XxlJobServiceFeign { + + + @GetMapping("/user/openFeignTest") + public R> openFeignTest(@RequestParam("param") String string); + +} \ No newline at end of file diff --git a/mhd-api/mhd-api-system/src/main/java/com/mhd/system/api/factory/RemoteXxlJobFeignFallbackFactory.java b/mhd-api/mhd-api-system/src/main/java/com/mhd/system/api/factory/RemoteXxlJobFeignFallbackFactory.java new file mode 100644 index 000000000..90c72b51c --- /dev/null +++ b/mhd-api/mhd-api-system/src/main/java/com/mhd/system/api/factory/RemoteXxlJobFeignFallbackFactory.java @@ -0,0 +1,44 @@ +package com.mhd.system.api.factory; + +import com.mhd.common.core.domain.dto.BusinessDataPushDTO; +import com.mhd.common.core.domain.entity.R; +import com.mhd.common.core.domain.po.OrganizationPo; +import com.mhd.common.core.web.domain.AjaxResult; +import com.mhd.system.api.BmsServiceFeign; +import com.mhd.system.api.ProductServiceFeign; +import com.mhd.system.api.XxlJobServiceFeign; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.cloud.openfeign.FallbackFactory; +import org.springframework.stereotype.Component; +import org.springframework.web.bind.annotation.RequestBody; + +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Set; + + +/** + * @Description + * @Author zg + * @Version 1.0 + * @Date 2023/11/3 14:37 + */ +@Component +public class RemoteXxlJobFeignFallbackFactory implements FallbackFactory { + + private static final Logger log = LoggerFactory.getLogger(RemoteXxlJobFeignFallbackFactory.class); + + @Override + public XxlJobServiceFeign create(Throwable throwable) { + log.error("系统服务调用失败:{}", throwable.getMessage()); + return new XxlJobServiceFeign() { + + @Override + public R> openFeignTest(String string) { + return null; + } + }; + } +} \ No newline at end of file diff --git a/mhd-bi/src/main/java/com/mhd/bi/domain/biPlatformRealData/repository/mapper/BiPlatformRealDataMapper.java b/mhd-bi/src/main/java/com/mhd/bi/domain/biPlatformRealData/repository/mapper/BiPlatformRealDataMapper.java index 9fa3ed755..1f283297c 100644 --- a/mhd-bi/src/main/java/com/mhd/bi/domain/biPlatformRealData/repository/mapper/BiPlatformRealDataMapper.java +++ b/mhd-bi/src/main/java/com/mhd/bi/domain/biPlatformRealData/repository/mapper/BiPlatformRealDataMapper.java @@ -4,6 +4,8 @@ import com.mhd.bi.domain.biPlatformRealData.repository.po.RealPlatformVehiclePO; import com.mhd.bi.domain.biPlatformRealData.repository.po.RealPlatformOverviewPO; import com.mhd.bi.domain.biPlatformRealData.repository.po.RealVehicleStatusPO; import com.mhd.bi.domain.biPlatformRealData.repository.po.RealTaskLoadPO; +import com.mhd.bi.domain.biPlatformRealData.repository.po.RealBusinessTypeStatPO; +import com.mhd.bi.domain.biPlatformRealData.repository.po.RealPlatformFloorStatPO; import java.util.List; @@ -31,4 +33,10 @@ public interface BiPlatformRealDataMapper { /** 任务负荷(今日 24 小时) */ List queryTaskLoadToday(); + + /** 今日预约-业务类型统计(按 businessName 分组统计今日预约数量) */ + List queryTodayBusinessTypeStats(); + + /** 月台监控-按楼层统计月台车辆(楼层、月台数量、今日预约车辆、当前作业车辆) */ + List queryPlatformFloorStats(); } \ No newline at end of file diff --git a/mhd-bi/src/main/java/com/mhd/bi/domain/biPlatformRealData/repository/po/RealBusinessTypeStatPO.java b/mhd-bi/src/main/java/com/mhd/bi/domain/biPlatformRealData/repository/po/RealBusinessTypeStatPO.java new file mode 100644 index 000000000..d9df6ab91 --- /dev/null +++ b/mhd-bi/src/main/java/com/mhd/bi/domain/biPlatformRealData/repository/po/RealBusinessTypeStatPO.java @@ -0,0 +1,20 @@ +package com.mhd.bi.domain.biPlatformRealData.repository.po; + +import lombok.Data; + +import java.io.Serializable; + +/** + * 今日预约-业务类型统计(真实数据,来自 TEST_NGWL_YMS.QMS_MAIN_BUSINESS) + * 按业务类型分组统计今日预约数量 + */ +@Data +public class RealBusinessTypeStatPO implements Serializable { + private static final long serialVersionUID = 1L; + + /** 业务类型名称(qms_main_business.businessName) */ + private String businessName; + + /** 今日预约数量 */ + private Long count; +} diff --git a/mhd-bi/src/main/java/com/mhd/bi/domain/biPlatformRealData/repository/po/RealPlatformFloorStatPO.java b/mhd-bi/src/main/java/com/mhd/bi/domain/biPlatformRealData/repository/po/RealPlatformFloorStatPO.java new file mode 100644 index 000000000..c3c600faf --- /dev/null +++ b/mhd-bi/src/main/java/com/mhd/bi/domain/biPlatformRealData/repository/po/RealPlatformFloorStatPO.java @@ -0,0 +1,26 @@ +package com.mhd.bi.domain.biPlatformRealData.repository.po; + +import lombok.Data; + +import java.io.Serializable; + +/** + * 月台监控-月台车辆统计(按楼层分组) + * 数据来源:TEST_NGWL_YMS.QMS_WINDOW_INFO(楼层+月台)与 QMS_MAIN_BUSINESS(当日预约/作业) + */ +@Data +public class RealPlatformFloorStatPO implements Serializable { + private static final long serialVersionUID = 1L; + + /** 楼层(从叫号月台 WINDOW_NAME 解析,如 S1-01 -> F1) */ + private String floorNo; + + /** 该楼层的月台数量 */ + private Long platformCount; + + /** 今日预约车辆数(按 WINDOW_NAME 关联楼层) */ + private Long todayReservedVehicles; + + /** 当前作业车辆数(FLOW_STATUS IN 5,6,7,8,9,10) */ + private Long operatingVehicles; +} diff --git a/mhd-bi/src/main/java/com/mhd/bi/domain/biPlatformRealData/service/BiPlatformRealDataService.java b/mhd-bi/src/main/java/com/mhd/bi/domain/biPlatformRealData/service/BiPlatformRealDataService.java index a3c52b08d..9e2470dc6 100644 --- a/mhd-bi/src/main/java/com/mhd/bi/domain/biPlatformRealData/service/BiPlatformRealDataService.java +++ b/mhd-bi/src/main/java/com/mhd/bi/domain/biPlatformRealData/service/BiPlatformRealDataService.java @@ -1,22 +1,30 @@ package com.mhd.bi.domain.biPlatformRealData.service; +import com.fasterxml.jackson.databind.ObjectMapper; import com.mhd.bi.domain.biPlatformRealData.repository.mapper.BiPlatformRealDataMapper; import com.mhd.bi.domain.biPlatformRealData.repository.po.RealPlatformVehiclePO; import com.mhd.bi.domain.biPlatformRealData.repository.po.RealPlatformOverviewPO; import com.mhd.bi.domain.biPlatformRealData.repository.po.RealVehicleStatusPO; import com.mhd.bi.domain.biPlatformRealData.repository.po.RealTaskLoadPO; +import com.mhd.bi.domain.biPlatformRealData.repository.po.RealBusinessTypeStatPO; +import com.mhd.bi.domain.biPlatformRealData.repository.po.RealPlatformFloorStatPO; +import com.mhd.bi.domain.biPlatformSurveillance.repository.mapper.BiPlatformSurveillanceReportMapper; +import com.mhd.bi.domain.biSnapshotSync.repository.mapper.BiSnapshotWriteMapper; import com.mhd.bi.domain.biSnapshotSync.support.BiSnapshotWeeklyRandomDataBuilder; import com.mhd.bi.interfaces.facadeApi.biReport.vo.platform.PlatformSurveillanceVO; import com.mhd.bi.interfaces.facadeApi.biReport.vo.platform.PlatformVehicleItemVO; import com.mhd.bi.interfaces.facadeApi.biReport.vo.platform.TaskLoadItemVO; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.ArrayList; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Random; /** @@ -30,6 +38,96 @@ public class BiPlatformRealDataService { @Resource private BiPlatformRealDataMapper biPlatformRealDataMapper; + @Resource + private BiSnapshotWriteMapper biSnapshotWriteMapper; + + @Resource + private BiPlatformSurveillanceReportMapper biPlatformSurveillanceReportMapper; + + @Resource + private ObjectMapper objectMapper; + + private static final String REMARK_REALTIME = "realtime platform-surveillance"; + + /** + * 实时组装月台监测数据;仅当真实业务数据(YMS 库查出的字段)发生变化时, + * 才覆盖更新 BI_PLATFORM_SURVEILLANCE_SNAPSHOT 快照表最新一条后返回。 + * 写死字段变化不触发更新;表中尚无记录时插入一条兜底。 + */ + public PlatformSurveillanceVO buildRealTimePlatformSurveillanceAndPersist() { + PlatformSurveillanceVO vo = buildRealTimePlatformSurveillance(); + try { + String fullJson = objectMapper.writeValueAsString(vo); + String fingerprint = realDataFingerprint(vo); + + String latestJson = biPlatformSurveillanceReportMapper.selectLatestPayloadJson(); + if (StringUtils.isNotBlank(latestJson)) { + PlatformSurveillanceVO latestVo = objectMapper.readValue(latestJson.trim(), PlatformSurveillanceVO.class); + if (Objects.equals(fingerprint, realDataFingerprint(latestVo))) { + log.info("BI 月台监测真实业务数据未变化,跳过落库"); + return vo; + } + } + + int rows = biSnapshotWriteMapper.updateLatestPlatformSurveillanceSnapshot(fullJson, REMARK_REALTIME); + if (rows < 1) { + // 表中无最新记录可更新,插入一条兜底 + biSnapshotWriteMapper.insertPlatformSurveillanceSnapshot(fullJson, REMARK_REALTIME); + } + log.info("BI 月台监测实时数据已落库(覆盖最新, 数据变化), affectedRows={}", rows); + } catch (Exception e) { + log.error("BI 月台监测实时数据落库失败", e); + } + return vo; + } + + /** + * 提取月台监测的「真实业务数据」指纹(仅含 YMS 库查出的字段),用于判断业务数据是否变化。 + * 写死/随机字段不纳入指纹,故其变化不会触发更新。 + */ + private String realDataFingerprint(PlatformSurveillanceVO vo) throws Exception { + Map fp = new LinkedHashMap<>(); + if (vo.getPlatformOverview() != null) { + fp.put("totalPlatforms", vo.getPlatformOverview().getTotalPlatforms()); + fp.put("operatingPlatforms", vo.getPlatformOverview().getOperatingPlatforms()); + fp.put("todayTasks", vo.getPlatformOverview().getTodayTasks()); + } + if (vo.getVehicleStatus() != null) { + fp.put("todayReservedVehicles", vo.getVehicleStatus().getTodayReservedVehicles()); + fp.put("notCheckedIn", vo.getVehicleStatus().getNotCheckedIn()); + fp.put("operatingVehicles", vo.getVehicleStatus().getOperatingVehicles()); + fp.put("completedVehicles", vo.getVehicleStatus().getCompletedVehicles()); + } + if (vo.getMonthlyTaskStatistics() != null) { + fp.put("taskTotal", vo.getMonthlyTaskStatistics().getTaskTotal()); + } + if (vo.getVehicles() != null) { + List> vehicles = new ArrayList<>(); + for (PlatformVehicleItemVO v : vo.getVehicles()) { + Map m = new LinkedHashMap<>(); + m.put("appointmentTime", v.getAppointmentTime()); + m.put("workFloor", v.getWorkFloor()); + m.put("plateNumber", v.getPlateNumber()); + m.put("status", v.getStatus()); + m.put("platformId", v.getPlatformId()); + m.put("platformDuration", v.getPlatformDuration()); + vehicles.add(m); + } + fp.put("vehicles", vehicles); + } + if (vo.getTaskLoadStatistics() != null) { + List> loads = new ArrayList<>(); + for (TaskLoadItemVO item : vo.getTaskLoadStatistics()) { + Map m = new LinkedHashMap<>(); + m.put("time", item.getTime()); + m.put("taskCount", item.getTaskCount()); + loads.add(m); + } + fp.put("taskLoadStatistics", loads); + } + return objectMapper.writeValueAsString(fp); + } + public List queryVehicles() { try { return biPlatformRealDataMapper.queryVehicles(); @@ -106,12 +204,39 @@ public class BiPlatformRealDataService { } } + /** + * 今日预约-业务类型统计:按业务类型分组统计今日预约数量。 + * 例:今日预约航空打板 3 条 → 返回 {businessName:"航空打板", count:3} + */ + public List queryTodayBusinessTypeStats() { + try { + return biPlatformRealDataMapper.queryTodayBusinessTypeStats(); + } catch (Exception e) { + log.error("【YMS】统计今日业务类型失败: {}", e.getMessage(), e); + return java.util.Collections.emptyList(); + } + } + + /** + * 月台监控-按楼层统计月台车辆:返回 {floorNo, platformCount, todayReservedVehicles, operatingVehicles} + * 实时查 YMS 库,不落库。 + */ + public List queryPlatformFloorStats() { + try { + return biPlatformRealDataMapper.queryPlatformFloorStats(); + } catch (Exception e) { + log.error("【YMS】月台监控按楼层统计失败: {}", e.getMessage(), e); + return java.util.Collections.emptyList(); + } + } + /** * 实时组装月台监测数据:真实字段查 YMS 库,写死字段保留静态值。 * 每次调用实时查库,不经过快照表。 */ public PlatformSurveillanceVO buildRealTimePlatformSurveillance() { - Random r = new Random(); + // 固定种子,保证写死字段每次生成值一致(真实字段随后实时覆盖) + Random r = new Random(20260825L); PlatformSurveillanceVO template = BiSnapshotWeeklyRandomDataBuilder.platformSurveillance(r); // 作业车辆列表 diff --git a/mhd-bi/src/main/java/com/mhd/bi/domain/biSnapshotSync/repository/mapper/BiSnapshotWriteMapper.java b/mhd-bi/src/main/java/com/mhd/bi/domain/biSnapshotSync/repository/mapper/BiSnapshotWriteMapper.java index 10d4dfcfa..bf895ebbe 100644 --- a/mhd-bi/src/main/java/com/mhd/bi/domain/biSnapshotSync/repository/mapper/BiSnapshotWriteMapper.java +++ b/mhd-bi/src/main/java/com/mhd/bi/domain/biSnapshotSync/repository/mapper/BiSnapshotWriteMapper.java @@ -13,6 +13,8 @@ public interface BiSnapshotWriteMapper { int insertPlatformSurveillanceSnapshot(@Param("payloadJson") String payloadJson, @Param("remark") String remark); + int updateLatestPlatformSurveillanceSnapshot(@Param("payloadJson") String payloadJson, @Param("remark") String remark); + int insertOverallOperationSnapshot(@Param("payloadJson") String payloadJson, @Param("remark") String remark); int insertWarehouseOperationZoneSnapshot(@Param("payloadJson") String payloadJson, @Param("remark") String remark); diff --git a/mhd-bi/src/main/java/com/mhd/bi/domain/biSnapshotSync/service/BiReportSnapshotSyncService.java b/mhd-bi/src/main/java/com/mhd/bi/domain/biSnapshotSync/service/BiReportSnapshotSyncService.java index 6df016cbf..b682590a2 100644 --- a/mhd-bi/src/main/java/com/mhd/bi/domain/biSnapshotSync/service/BiReportSnapshotSyncService.java +++ b/mhd-bi/src/main/java/com/mhd/bi/domain/biSnapshotSync/service/BiReportSnapshotSyncService.java @@ -150,7 +150,8 @@ public class BiReportSnapshotSyncService { /** TODO 业务落地:部分字段改为真实数据,其余仍写死。 */ protected PlatformSurveillanceVO buildPlatformSurveillanceSnapshot() { - Random r = new Random(); + // 固定种子,保证写死字段每次生成值一致(真实字段随后实时覆盖) + Random r = new Random(20260825L); // 写死数据复用原 builder PlatformSurveillanceVO template = BiSnapshotWeeklyRandomDataBuilder.platformSurveillance(r); diff --git a/mhd-bi/src/main/java/com/mhd/bi/interfaces/facadeApi/biReport/BiReportApi.java b/mhd-bi/src/main/java/com/mhd/bi/interfaces/facadeApi/biReport/BiReportApi.java index 4aa56c70f..0375dc7d6 100644 --- a/mhd-bi/src/main/java/com/mhd/bi/interfaces/facadeApi/biReport/BiReportApi.java +++ b/mhd-bi/src/main/java/com/mhd/bi/interfaces/facadeApi/biReport/BiReportApi.java @@ -4,6 +4,8 @@ import com.mhd.bi.domain.biSnapshotSync.service.BiReportSnapshotSyncService; import com.mhd.bi.domain.biComprehensive.service.BiComprehensiveReportService; import com.mhd.bi.domain.biPlatformSurveillance.service.BiPlatformSurveillanceReportService; import com.mhd.bi.domain.biPlatformRealData.service.BiPlatformRealDataService; +import com.mhd.bi.domain.biPlatformRealData.repository.po.RealBusinessTypeStatPO; +import com.mhd.bi.domain.biPlatformRealData.repository.po.RealPlatformFloorStatPO; import com.mhd.bi.domain.biOverallOperation.service.BiOverallOperationReportService; import com.mhd.bi.domain.biHkMacaoServiceZone.service.BiHkMacaoServiceZoneReportService; import com.mhd.bi.domain.biTransportOperationZone.service.BiTransportOperationZoneReportService; @@ -30,6 +32,8 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import java.util.List; + /** * BI 报表接口 */ @@ -96,12 +100,32 @@ public class BiReportApi extends BaseController { } /** - * 月台监测指标查询(实时查 YMS 库,真实字段 + 写死字段) + * 月台监测指标查询(实时查 YMS 库,真实字段 + 写死字段),并落库一条到 BI_PLATFORM_SURVEILLANCE_SNAPSHOT */ - @ApiOperation(value = "月台监测指标查询", notes = "每次调用实时查询 YMS 库组装;部分字段为真实业务数据,部分为写死数据") + @ApiOperation(value = "月台监测指标查询", notes = "每次调用实时查询 YMS 库组装并写入快照表;部分字段为真实业务数据,部分为写死数据") @GetMapping("/platformSurveillance") public BiApiResult platformSurveillance() { - PlatformSurveillanceVO data = biPlatformRealDataService.buildRealTimePlatformSurveillance(); + PlatformSurveillanceVO data = biPlatformRealDataService.buildRealTimePlatformSurveillanceAndPersist(); + return BiApiResult.ok(data); + } + + /** + * 今日预约-业务类型统计(实时查 YMS 库,不落库) + */ + @ApiOperation(value = "今日预约业务类型统计", notes = "按业务类型分组统计今日预约数量,实时查询 YMS 库,不落库;例:航空打板 3 条") + @GetMapping("/businessTypeStats") + public BiApiResult> businessTypeStats() { + List data = biPlatformRealDataService.queryTodayBusinessTypeStats(); + return BiApiResult.ok(data); + } + + /** + * 月台监控-按楼层统计月台车辆(实时查 YMS 库,不落库) + */ + @ApiOperation(value = "月台车辆统计(按楼层)", notes = "按楼层统计月台数量、今日预约车辆、当前作业车辆,实时查询 YMS 库,不落库") + @GetMapping("/platformFloorStats") + public BiApiResult> platformFloorStats() { + List data = biPlatformRealDataService.queryPlatformFloorStats(); return BiApiResult.ok(data); } //园区物流大屏接口---------------------------------------------------------------------- diff --git a/mhd-bi/src/main/resources/bootstrap.yml b/mhd-bi/src/main/resources/bootstrap.yml index 8f1e2c236..b949b746f 100644 --- a/mhd-bi/src/main/resources/bootstrap.yml +++ b/mhd-bi/src/main/resources/bootstrap.yml @@ -14,19 +14,19 @@ spring: discovery: # server-addr: 127.0.0.1:8848 # 线上测试环境配置 容器名+端口号 - server-addr: 10.33.0.129:6010 +# server-addr: 10.33.0.129:6010 # server-addr: 10.102.192.5:6848 username: nacos password: manhuoda@2023 #线上正式环境 -# server-addr: 10.102.192.30:6848 + server-addr: 10.102.192.31:6848 # username: nacos # password: manhuoda@2023 config: # server-addr: 127.0.0.1:8848 # 线上测试环境配置 容器名+端口号 - server-addr: 10.33.0.129:6010 -# server-addr: 10.102.192.30:6848 +# server-addr: 10.33.0.129:6010 + server-addr: 10.102.192.31:6848 username: nacos password: manhuoda@2023 #线上正式环境 diff --git a/mhd-bi/src/main/resources/mapper/biPlatformRealData/BiPlatformRealDataMapper.xml b/mhd-bi/src/main/resources/mapper/biPlatformRealData/BiPlatformRealDataMapper.xml index 6397c6612..883d07526 100644 --- a/mhd-bi/src/main/resources/mapper/biPlatformRealData/BiPlatformRealDataMapper.xml +++ b/mhd-bi/src/main/resources/mapper/biPlatformRealData/BiPlatformRealDataMapper.xml @@ -46,11 +46,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" AND TRUNC(ENTRY_TIME) = TRUNC(SYSDATE) - + + + + + + \ No newline at end of file diff --git a/mhd_wms/pom.xml b/mhd_wms/pom.xml index c8afa6a88..cc6b6b9f1 100644 --- a/mhd_wms/pom.xml +++ b/mhd_wms/pom.xml @@ -80,6 +80,11 @@ opencc4j 1.8.1 + + com.xuxueli + xxl-job-core + 2.4.0 + com.mhd diff --git a/mhd_wms/src/main/java/com/mhd/wms/interfaces/facadeApi/stockInOrder/StockInOrderApi.java b/mhd_wms/src/main/java/com/mhd/wms/interfaces/facadeApi/stockInOrder/StockInOrderApi.java index b90157e39..81871c182 100644 --- a/mhd_wms/src/main/java/com/mhd/wms/interfaces/facadeApi/stockInOrder/StockInOrderApi.java +++ b/mhd_wms/src/main/java/com/mhd/wms/interfaces/facadeApi/stockInOrder/StockInOrderApi.java @@ -1,11 +1,13 @@ package com.mhd.wms.interfaces.facadeApi.stockInOrder; +import com.mhd.common.core.domain.entity.R; import com.mhd.common.core.web.controller.BaseController; import com.mhd.common.core.utils.bean.BeanUtils; import com.mhd.common.core.web.domain.AjaxResult; import com.mhd.common.core.web.page.TableDataInfo; import com.mhd.common.core.exception.ServiceException; import com.mhd.common.core.utils.StringUtils; +import com.mhd.system.api.XxlJobServiceFeign; import com.mhd.wms.application.service.stockInOrder.StockInOrderApplicationService; import com.mhd.wms.domain.inMaterialDetail.entity.InMaterialDetail; import com.mhd.wms.domain.inMaterialDetail.repository.po.InMaterialDetailPO; @@ -20,6 +22,8 @@ import com.mhd.wms.interfaces.assember.stockOutOrder.StockOutOrderAssembler; import com.mhd.wms.interfaces.dto.inMaterialDetail.InMaterialDetailDTO; import com.mhd.wms.interfaces.dto.stockInOrder.StockInOrderDTO; import com.mhd.wms.interfaces.dto.stockOutOrder.StockOutOrderDTO; +import com.xxl.job.core.context.XxlJobHelper; +import com.xxl.job.core.handler.annotation.XxlJob; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -49,6 +53,8 @@ public class StockInOrderApi extends BaseController { private StockInOrderAssembler stockInOrderAssembler; @Resource private StockOutOrderAssembler stockOutOrderAssembler; + @Autowired + private XxlJobServiceFeign xxlJobServiceFeign; /** * 分页查询入库单列表 @@ -347,4 +353,32 @@ public class StockInOrderApi extends BaseController { return stockInOrderApplicationService.batchSignature(dto); } + @GetMapping("/xxlopenfeign") + public AjaxResult xxlopenfeign(@RequestParam String param) { + R> mapR = xxlJobServiceFeign.openFeignTest(param); + return AjaxResult.success(mapR); + } + + /** + * 1. 简单任务示例(Bean模式) + * 这里的 demoJobHandler 必须和调度中心配置一致 + */ + @XxlJob("demoJobHandler") + public void demoJobHandler() { + // 获取任务参数 + String param = XxlJobHelper.getJobParam(); + logger.info("XXL-JOB 开始执行,参数:{}", param); + + try { + // ========== 你的业务逻辑 ========== + logger.info("执行若依微服务定时任务..."); + + // 设置任务执行结果 + XxlJobHelper.handleSuccess("执行成功"); + } catch (Exception e) { + logger.error("XXL-JOB 执行失败", e); + XxlJobHelper.handleFail("执行失败:" + e.getMessage()); + } + } + } \ No newline at end of file diff --git a/mhd_wms/src/main/java/com/mhd/wms/util/XxlJobConfig.java b/mhd_wms/src/main/java/com/mhd/wms/util/XxlJobConfig.java new file mode 100644 index 000000000..9627d0e7b --- /dev/null +++ b/mhd_wms/src/main/java/com/mhd/wms/util/XxlJobConfig.java @@ -0,0 +1,54 @@ +package com.mhd.wms.util; +import com.xxl.job.core.executor.impl.XxlJobSpringExecutor; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * XXL-JOB 配置类 + */ +@Configuration +public class XxlJobConfig { + private Logger logger = LoggerFactory.getLogger(XxlJobConfig.class); + + @Value("${xxl.job.admin.addresses}") + private String adminAddresses; + + @Value("${xxl.job.accessToken}") + private String accessToken; + + @Value("${xxl.job.executor.appname}") + private String appname; + + @Value("${xxl.job.executor.address}") + private String address; + + @Value("${xxl.job.executor.ip}") + private String ip; + + @Value("${xxl.job.executor.port}") + private int port; + + @Value("${xxl.job.executor.logpath}") + private String logPath; + + @Value("${xxl.job.executor.logretentiondays}") + private int logRetentionDays; + + @Bean + public XxlJobSpringExecutor xxlJobExecutor() { + logger.info(">>>>>>>>>>> xxl-job config init."); + XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor(); + xxlJobSpringExecutor.setAdminAddresses(adminAddresses); + xxlJobSpringExecutor.setAppname(appname); + xxlJobSpringExecutor.setAddress(address); + xxlJobSpringExecutor.setIp(ip); + xxlJobSpringExecutor.setPort(port); + xxlJobSpringExecutor.setAccessToken(accessToken); + xxlJobSpringExecutor.setLogPath(logPath); + xxlJobSpringExecutor.setLogRetentionDays(logRetentionDays); + return xxlJobSpringExecutor; + } +} \ No newline at end of file diff --git a/mhd_wms/src/main/resources/bootstrap.yml b/mhd_wms/src/main/resources/bootstrap.yml index 39eb710cb..503393ad1 100644 --- a/mhd_wms/src/main/resources/bootstrap.yml +++ b/mhd_wms/src/main/resources/bootstrap.yml @@ -34,4 +34,26 @@ spring: file-extension: yml # 共享配置 shared-configs: - - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} \ No newline at end of file + - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} +# XXL-JOB 配置 +xxl: + job: + # 调度中心地址(填你部署的地址) + admin: + addresses: http://192.168.1.6:8020/xxl-job-admin + # 执行器配置 + executor: + # 执行器名称(自定义,后面调度中心要用到) + appname: wms-service-executor + # 执行器注册地址,默认0表示自动获取 + address: + # 执行器IP,默认空自动获取 + ip: + # 执行器端口号(每个微服务不能重复,建议9997/9998/9999) + port: 9997 + # 执行器日志存放路径 + logpath: /data/applogs/xxl-job/jobhandler + # 日志保留天数 + logretentiondays: 30 + # 调度中心通讯令牌(默认空,安全可设置) + accessToken: default_token \ No newline at end of file