新增看板接口

This commit is contained in:
2025-12-26 15:04:24 +08:00
parent d7bbd3c1f1
commit 19ef36511b
7 changed files with 260 additions and 10 deletions

View File

@@ -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());
}
}

View File

@@ -0,0 +1,20 @@
package com.fizz.business.mapper;
import org.apache.ibatis.annotations.Mapper;
import java.util.Map;
/**
* 计划相关仪表板 Mappercrm_pdi_plan
*/
@Mapper
public interface PlanDashboardMapper {
/**
* 查询当前生产中的计划status = 'PRODUCING'
* 返回字段至少包括:
* - coilid, planid, steel_grade, entry_weight, entry_thick, entry_width, start_date 等
*/
Map<String, Object> selectCurrentProducingPlan();
}

View File

@@ -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;
/**
* <p>
* 各机张力,电流等架跟踪表 Mapper 接口
* </p>
*
* @author baomidou
* @since 2023-10-26
* 带钢段工艺参数 Mappercpl_segment_total
*/
@Mapper
public interface SegmentTotalMapper extends BaseMapper<SegmentTotal> {
SegmentTotal getLatestRecord();
public interface SegmentTotalMapper {
/**
* 根据入库钢卷号查询最新一段的 total_values_json
*/
String selectLatestTotalValuesJsonByCoilId(@Param("coilId") String coilId);
}

View File

@@ -0,0 +1,27 @@
package com.fizz.business.service;
import java.util.Map;
/**
* 首页仪表板统计服务
*/
public interface DashboardService {
/**
* 当前生产中的计划信息(包含卷号、规格、时间等)
*/
Map<String, Object> getCurrentProducingPlan();
/**
* 当前生产卷的关键工艺参数
* 结构说明(示例):
* {
* "coilId": "...",
* "entrySection": { "POR1": { ... }, "POR2": { ... }, ... },
* "processSection":{ "CLEAN": { ... }, "FUR1": { ... }, ... },
* "exitSection": { "TR": { ... }, "CXL1": { ... }, ... }
* }
*/
Map<String, Object> getCurrentProcessParams();
}

View File

@@ -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<String, Object> getCurrentProducingPlan() {
// 查询当前 PRODUCING 的计划
Map<String, Object> plan = planDashboardMapper.selectCurrentProducingPlan();
if (plan == null) {
return Collections.emptyMap();
}
return plan;
}
@Override
public Map<String, Object> getCurrentProcessParams() {
Map<String, Object> result = new HashMap<>();
// 1. 当前生产计划
Map<String, Object> 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<String, Object>
Map<String, Object> valuesMap = objectMapper.readValue(
totalValuesJson,
new TypeReference<Map<String, Object>>() {}
);
// 4. 按设备 + 段类型整理数据
Map<String, Object> entrySection = new LinkedHashMap<>();
Map<String, Object> processSection = new LinkedHashMap<>();
Map<String, Object> exitSection = new LinkedHashMap<>();
for (DeviceEnum device : DeviceEnum.values()) {
List<String> fields = device.getParamFields();
if (fields == null || fields.isEmpty()) {
continue;
}
Map<String, Object> 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;
}
}

View File

@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.fizz.business.mapper.PlanDashboardMapper">
<!-- 当前生产中的计划status = 'PRODUCING',按 producing_time / start_date 倒序取最新一条) -->
<select id="selectCurrentProducingPlan" resultType="java.util.Map">
SELECT
id,
coilid,
planid,
steel_grade AS steelGrade,
entry_weight AS entryWeight,
entry_thick AS entryThick,
entry_width AS entryWidth,
entry_length AS entryLength,
status,
start_date AS startDate,
end_date AS endDate,
producing_time AS producingTime,
unit_code AS unitCode
FROM crm_pdi_plan
WHERE status = 'PRODUCING'
ORDER BY
producing_time DESC,
start_date DESC,
id DESC
LIMIT 1
</select>
</mapper>

View File

@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.fizz.business.mapper.SegmentTotalMapper">
<!-- 根据入库钢卷号查询最新一段的 total_values_json -->
<select id="selectLatestTotalValuesJsonByCoilId"
parameterType="java.lang.String"
resultType="java.lang.String">
SELECT
total_values_json
FROM cpl_segment_total
WHERE en_coil_id = #{coilId}
ORDER BY seg_no DESC
LIMIT 1
</select>
</mapper>