diff --git a/business/src/main/java/com/fizz/business/controller/DashboardController.java b/business/src/main/java/com/fizz/business/controller/DashboardController.java new file mode 100644 index 0000000..11a8ac2 --- /dev/null +++ b/business/src/main/java/com/fizz/business/controller/DashboardController.java @@ -0,0 +1,37 @@ +package com.fizz.business.controller; + +import com.fizz.common.core.domain.AjaxResult; +import com.fizz.business.service.DashboardService; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; + +/** + * 首页仪表板相关接口 + */ +@RestController +public class DashboardController { + + @Resource + private DashboardService dashboardService; + + /** + * 当前生产中的计划信息(crm_pdi_plan.status = 'PRODUCING') + */ + @GetMapping("/api/business/dashboard/currentPlan") + public AjaxResult getCurrentProducingPlan() { + return AjaxResult.success(dashboardService.getCurrentProducingPlan()); + } + + /** + * 当前生产卷的关键工艺参数 + * - 从 cpl_segment_total.total_values_json 解析 + * - 键名来自 DeviceEnum.paramFields + */ + @GetMapping("/api/business/dashboard/currentProcess") + public AjaxResult getCurrentProcessParams() { + return AjaxResult.success(dashboardService.getCurrentProcessParams()); + } +} + diff --git a/business/src/main/java/com/fizz/business/mapper/PlanDashboardMapper.java b/business/src/main/java/com/fizz/business/mapper/PlanDashboardMapper.java new file mode 100644 index 0000000..df1a41d --- /dev/null +++ b/business/src/main/java/com/fizz/business/mapper/PlanDashboardMapper.java @@ -0,0 +1,20 @@ +package com.fizz.business.mapper; + +import org.apache.ibatis.annotations.Mapper; + +import java.util.Map; + +/** + * 计划相关仪表板 Mapper(crm_pdi_plan) + */ +@Mapper +public interface PlanDashboardMapper { + + /** + * 查询当前生产中的计划(status = 'PRODUCING') + * 返回字段至少包括: + * - coilid, planid, steel_grade, entry_weight, entry_thick, entry_width, start_date 等 + */ + Map selectCurrentProducingPlan(); +} + diff --git a/business/src/main/java/com/fizz/business/mapper/SegmentTotalMapper.java b/business/src/main/java/com/fizz/business/mapper/SegmentTotalMapper.java index cc74d2c..9124dcb 100644 --- a/business/src/main/java/com/fizz/business/mapper/SegmentTotalMapper.java +++ b/business/src/main/java/com/fizz/business/mapper/SegmentTotalMapper.java @@ -1,18 +1,16 @@ package com.fizz.business.mapper; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.fizz.business.domain.SegmentTotal; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; /** - *

- * 各机张力,电流等架跟踪表 Mapper 接口 - *

- * - * @author baomidou - * @since 2023-10-26 + * 带钢段工艺参数 Mapper(cpl_segment_total) */ @Mapper -public interface SegmentTotalMapper extends BaseMapper { - SegmentTotal getLatestRecord(); +public interface SegmentTotalMapper { + + /** + * 根据入库钢卷号查询最新一段的 total_values_json + */ + String selectLatestTotalValuesJsonByCoilId(@Param("coilId") String coilId); } diff --git a/business/src/main/java/com/fizz/business/service/DashboardService.java b/business/src/main/java/com/fizz/business/service/DashboardService.java new file mode 100644 index 0000000..e503e3c --- /dev/null +++ b/business/src/main/java/com/fizz/business/service/DashboardService.java @@ -0,0 +1,27 @@ +package com.fizz.business.service; + +import java.util.Map; + +/** + * 首页仪表板统计服务 + */ +public interface DashboardService { + + /** + * 当前生产中的计划信息(包含卷号、规格、时间等) + */ + Map getCurrentProducingPlan(); + + /** + * 当前生产卷的关键工艺参数 + * 结构说明(示例): + * { + * "coilId": "...", + * "entrySection": { "POR1": { ... }, "POR2": { ... }, ... }, + * "processSection":{ "CLEAN": { ... }, "FUR1": { ... }, ... }, + * "exitSection": { "TR": { ... }, "CXL1": { ... }, ... } + * } + */ + Map getCurrentProcessParams(); +} + diff --git a/business/src/main/java/com/fizz/business/service/impl/DashboardServiceImpl.java b/business/src/main/java/com/fizz/business/service/impl/DashboardServiceImpl.java new file mode 100644 index 0000000..5fbba29 --- /dev/null +++ b/business/src/main/java/com/fizz/business/service/impl/DashboardServiceImpl.java @@ -0,0 +1,113 @@ +package com.fizz.business.service.impl; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fizz.business.constants.enums.DeviceEnum; +import com.fizz.business.mapper.PlanDashboardMapper; +import com.fizz.business.mapper.SegmentTotalMapper; +import com.fizz.business.service.DashboardService; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.*; + +/** + * 首页仪表板统计服务实现 + */ +@Service +public class DashboardServiceImpl implements DashboardService { + + @Resource + private PlanDashboardMapper planDashboardMapper; + + @Resource + private SegmentTotalMapper segmentTotalMapper; + + private final ObjectMapper objectMapper = new ObjectMapper(); + + @Override + public Map getCurrentProducingPlan() { + // 查询当前 PRODUCING 的计划 + Map plan = planDashboardMapper.selectCurrentProducingPlan(); + if (plan == null) { + return Collections.emptyMap(); + } + return plan; + } + + @Override + public Map getCurrentProcessParams() { + Map result = new HashMap<>(); + + // 1. 当前生产计划 + Map plan = planDashboardMapper.selectCurrentProducingPlan(); + if (plan == null || plan.get("coilid") == null) { + return result; + } + String coilId = String.valueOf(plan.get("coilid")); + result.put("coilId", coilId); + + // 2. 查询该卷最新一段的 total_values_json + String totalValuesJson = segmentTotalMapper.selectLatestTotalValuesJsonByCoilId(coilId); + if (totalValuesJson == null || totalValuesJson.isEmpty()) { + return result; + } + + try { + // 3. 解析 JSON -> Map + Map valuesMap = objectMapper.readValue( + totalValuesJson, + new TypeReference>() {} + ); + + // 4. 按设备 + 段类型整理数据 + Map entrySection = new LinkedHashMap<>(); + Map processSection = new LinkedHashMap<>(); + Map exitSection = new LinkedHashMap<>(); + + for (DeviceEnum device : DeviceEnum.values()) { + List fields = device.getParamFields(); + if (fields == null || fields.isEmpty()) { + continue; + } + + Map devData = new LinkedHashMap<>(); + for (String field : fields) { + if (valuesMap.containsKey(field)) { + devData.put(field, valuesMap.get(field)); + } + } + + if (devData.isEmpty()) { + continue; + } + + // key 用设备英文枚举名,如 POR1/FUR1/TM/TL/COAT 等 + String key = device.name(); + switch (device.getSectionType()) { + case ENTRY: + entrySection.put(key, devData); + break; + case PROCESS: + processSection.put(key, devData); + break; + case EXIT: + exitSection.put(key, devData); + break; + default: + break; + } + } + + result.put("entrySection", entrySection); + result.put("processSection", processSection); + result.put("exitSection", exitSection); + } catch (Exception e) { + // 解析异常时,可按你项目的日志方案记录 + e.printStackTrace(); + } + + return result; + } +} + diff --git a/business/src/main/resources/mapper/business/PlanDashboardMapper.xml b/business/src/main/resources/mapper/business/PlanDashboardMapper.xml new file mode 100644 index 0000000..d61c54d --- /dev/null +++ b/business/src/main/resources/mapper/business/PlanDashboardMapper.xml @@ -0,0 +1,34 @@ + + + + + + + + + + diff --git a/business/src/main/resources/mapper/business/SegmentTotalMapper.xml b/business/src/main/resources/mapper/business/SegmentTotalMapper.xml new file mode 100644 index 0000000..fd12118 --- /dev/null +++ b/business/src/main/resources/mapper/business/SegmentTotalMapper.xml @@ -0,0 +1,21 @@ + + + + + + + + + +