refactor(health): 按文档规范重构用药管理模块
【重大重构】完全按照功能规划文档重写 ## 表结构变更 - medication_plan: 用药计划表(按文档设计) - medication_task: 服药任务表(按文档设计) - medication_remind_log: 提醒日志表 - medicine_stock_log: 库存变动表 - medication_adherence_stats: 统计汇总表 ## 字段变更 - frequency_config: JSONB 频次配置 - time_slots: JSONB 时段配置 - family_member_ids: JSONB 家属通知 - status: 状态值按文档规范(0-待服药 1-已服药 2-漏服 3-跳过) ## 新增组件 - JsonNodeTypeHandler: PostgreSQL JSONB 类型处理器 ## SQL 脚本 - medication_module_pg.sql: 建表语句(PostgreSQL) - medication_menu_pg.sql: 菜单权限配置 - medication_job_pg.sql: 定时任务配置
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
package com.intc.common.core.handler;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.apache.ibatis.type.BaseTypeHandler;
|
||||
import org.apache.ibatis.type.JdbcType;
|
||||
import org.apache.ibatis.type.MappedTypes;
|
||||
import org.postgresql.util.PGobject;
|
||||
|
||||
import java.sql.CallableStatement;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* PostgreSQL JSONB 类型处理器
|
||||
* 用于 MyBatis 映射 JsonNode 类型
|
||||
*
|
||||
* @author bot5
|
||||
* @date 2026-03-19
|
||||
*/
|
||||
@MappedTypes(JsonNode.class)
|
||||
public class JsonNodeTypeHandler extends BaseTypeHandler<JsonNode> {
|
||||
|
||||
private static final ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
@Override
|
||||
public void setNonNullParameter(PreparedStatement ps, int i, JsonNode parameter, JdbcType jdbcType) throws SQLException {
|
||||
PGobject pgObject = new PGobject();
|
||||
pgObject.setType("jsonb");
|
||||
pgObject.setValue(parameter.toString());
|
||||
ps.setObject(i, pgObject);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonNode getNullableResult(ResultSet rs, String columnName) throws SQLException {
|
||||
String value = rs.getString(columnName);
|
||||
return parseJson(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonNode getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
|
||||
String value = rs.getString(columnIndex);
|
||||
return parseJson(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonNode getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
|
||||
String value = cs.getString(columnIndex);
|
||||
return parseJson(value);
|
||||
}
|
||||
|
||||
private JsonNode parseJson(String value) {
|
||||
if (value == null || value.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return objectMapper.readTree(value);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user