feat(dict): 新增字典注解删除标记字段支持并修复库存计算空指针异常

- 在Dict注解中新增deleteFlag字段用于指定删除标记字段名
- 修改DictAspect切面逻辑支持删除标记字段的过滤查询
- 更新ProductDetailAppMapper.xml中的关联查询条件排序
- 修复ProductDetailAppServiceImpl中partPercent为空时的空指针异常
- 为ReceiptPageDto中的字典字段添加删除标记过滤配置
- 新增药物统计管理门户页面提供各类统计报表入口
This commit is contained in:
2026-02-24 17:30:23 +08:00
parent 8b993d5ddd
commit ff41aa9c04
6 changed files with 306 additions and 105 deletions

View File

@@ -11,4 +11,5 @@ public @interface Dict {
String dictCode(); // 字典类型字段
String dictText() default ""; // 回显字段,默认为空
String dictTable() default ""; // 表名,默认为空
String deleteFlag() default ""; // 删除标记字段名,默认为空(不过滤)
}

View File

@@ -95,8 +95,9 @@ public class DictAspect {
String dictCode = dictAnnotation.dictCode();
String dictText = dictAnnotation.dictText();
String dictTable = dictAnnotation.dictTable();
String deleteFlag = dictAnnotation.deleteFlag();
// 查询字典值
String dictLabel = queryDictLabel(dictTable, dictCode, dictText, fieldValue.toString());
String dictLabel = queryDictLabel(dictTable, dictCode, dictText, deleteFlag, fieldValue.toString());
if (dictLabel != null) {
try {
// 动态生成 _dictText 字段名
@@ -115,7 +116,7 @@ public class DictAspect {
}
}
private String queryDictLabel(String dictTable, String dictCode, String dictText, String dictValue) {
private String queryDictLabel(String dictTable, String dictCode, String dictText, String deleteFlag, String dictValue) {
if (!StringUtils.hasText(dictTable)) {
// 场景 1默认字典走DictUtils缓存dictTable 为空时)
return DictUtils.getDictLabel(dictCode, dictValue);
@@ -126,7 +127,15 @@ public class DictAspect {
// 如果 dictText 为空,回退到字典缓存查询
return DictUtils.getDictLabel(dictCode, dictValue);
}
String sql = String.format("SELECT %s FROM %s WHERE %s::varchar = ? LIMIT 1", dictText, dictTable, dictCode);
// 构建SQL支持 delete_flag 过滤
StringBuilder sqlBuilder = new StringBuilder();
sqlBuilder.append(String.format("SELECT %s FROM %s WHERE %s::varchar = ?", dictText, dictTable, dictCode));
// 如果指定了 deleteFlag 字段名,添加过滤条件
if (StringUtils.hasText(deleteFlag)) {
sqlBuilder.append(String.format(" AND %s = '0'", deleteFlag));
}
sqlBuilder.append(" LIMIT 1");
String sql = sqlBuilder.toString();
try {
return jdbcTemplate.queryForObject(sql, String.class, dictValue);
} catch (DataAccessException e) {