From 9cfb31b01520a5a54d7c091ee0c59625728ebb12 Mon Sep 17 00:00:00 2001 From: Timi Date: Thu, 10 Sep 2026 20:27:32 +0800 Subject: [PATCH 1/4] support pinyin for product --- .../api/modules/gao/entity/GaoProduct.java | 14 +++++ .../implement/GaoProductServiceImplement.java | 12 ++++ .../api/modules/gao/vo/GaoProductPage.java | 2 +- .../modules/gao/vo/GaoProductStockPage.java | 2 +- .../gao/vo/GaoProductStockRecordPage.java | 2 +- .../system/controller/SettingController.java | 19 ------- ...8__backfill_gao_product_pinyin_search.java | 55 +++++++++++++++++++ ..._add_gao_product_pinyin_search_columns.sql | 7 +++ .../timi-server/gao/GaoProductMapper.xml | 4 +- .../timi-server/gao/GaoProductStockMapper.xml | 8 +-- .../gao/GaoProductStockRecordMapper.xml | 2 +- 11 files changed, 98 insertions(+), 29 deletions(-) delete mode 100644 src/main/java/com/imyeyu/api/modules/system/controller/SettingController.java create mode 100644 src/main/java/db/migration/timiserver/V78__backfill_gao_product_pinyin_search.java create mode 100644 src/main/resources/db/migration/timiserver/V77__add_gao_product_pinyin_search_columns.sql diff --git a/src/main/java/com/imyeyu/api/modules/gao/entity/GaoProduct.java b/src/main/java/com/imyeyu/api/modules/gao/entity/GaoProduct.java index 6186823..e9fb4a3 100644 --- a/src/main/java/com/imyeyu/api/modules/gao/entity/GaoProduct.java +++ b/src/main/java/com/imyeyu/api/modules/gao/entity/GaoProduct.java @@ -1,6 +1,8 @@ package com.imyeyu.api.modules.gao.entity; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.imyeyu.api.modules.common.entity.Attachment; +import com.imyeyu.spring.annotation.table.Column; import com.imyeyu.spring.annotation.table.Transient; import com.imyeyu.spring.entity.UUIDEntity; import lombok.Data; @@ -61,6 +63,18 @@ public class GaoProduct extends UUIDEntity { /// 产品名称 private String name; + @Column("name_pinyin_full") + @JsonIgnore + private String namePinyinFull; + + @Column("name_pinyin_initial") + @JsonIgnore + private String namePinyinInitial; + + @Column("name_pinyin_mixed") + @JsonIgnore + private String namePinyinMixed; + /// 产品类型 private ProductType productType; diff --git a/src/main/java/com/imyeyu/api/modules/gao/service/implement/GaoProductServiceImplement.java b/src/main/java/com/imyeyu/api/modules/gao/service/implement/GaoProductServiceImplement.java index 806dba3..6ecef9d 100644 --- a/src/main/java/com/imyeyu/api/modules/gao/service/implement/GaoProductServiceImplement.java +++ b/src/main/java/com/imyeyu/api/modules/gao/service/implement/GaoProductServiceImplement.java @@ -17,6 +17,7 @@ import com.imyeyu.api.modules.gao.vo.GaoProductPage; import com.imyeyu.api.modules.system.audit.AuditOperation; import com.imyeyu.api.modules.system.audit.OperationAudit; import com.imyeyu.api.modules.user.service.UserLoginService; +import com.imyeyu.api.util.PinyinUtil; import com.imyeyu.java.TimiJava; import com.imyeyu.java.bean.timi.TimiCode; import com.imyeyu.java.bean.timi.TimiException; @@ -166,6 +167,7 @@ public class GaoProductServiceImplement extends AbstractEntityService= BATCH_SIZE) { + update.executeBatch(); + batchSize = 0; + } + } + if (0 < batchSize) { + update.executeBatch(); + } + } + } + } +} diff --git a/src/main/resources/db/migration/timiserver/V77__add_gao_product_pinyin_search_columns.sql b/src/main/resources/db/migration/timiserver/V77__add_gao_product_pinyin_search_columns.sql new file mode 100644 index 0000000..6c81fc2 --- /dev/null +++ b/src/main/resources/db/migration/timiserver/V77__add_gao_product_pinyin_search_columns.sql @@ -0,0 +1,7 @@ +ALTER TABLE `gao_product` + ADD COLUMN `name_pinyin_full` VARCHAR(768) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL COMMENT '产品名称全拼' AFTER `name`, + ADD COLUMN `name_pinyin_initial` VARCHAR(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL COMMENT '产品名称拼音首字母' AFTER `name_pinyin_full`, + ADD COLUMN `name_pinyin_mixed` VARCHAR(768) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL COMMENT '产品名称混合拼音' AFTER `name_pinyin_initial`, + ADD KEY `idx_gao_product_store_name_pinyin_full` (`store_id`, `deleted_at`, `name_pinyin_full`(128)), + ADD KEY `idx_gao_product_store_name_pinyin_initial` (`store_id`, `deleted_at`, `name_pinyin_initial`), + ADD KEY `idx_gao_product_store_name_pinyin_mixed` (`store_id`, `deleted_at`, `name_pinyin_mixed`(128)); diff --git a/src/main/resources/mapper/timi-server/gao/GaoProductMapper.xml b/src/main/resources/mapper/timi-server/gao/GaoProductMapper.xml index b638e34..66a45e9 100644 --- a/src/main/resources/mapper/timi-server/gao/GaoProductMapper.xml +++ b/src/main/resources/mapper/timi-server/gao/GaoProductMapper.xml @@ -13,7 +13,7 @@ AND `status` = #{status} AND `product_type` = #{productType} - AND (`code` LIKE CONCAT('%', #{keyword}, '%') OR `name` LIKE CONCAT('%', #{keyword}, '%')) + AND (`code` LIKE CONCAT('%', #{keyword}, '%') OR `name` LIKE CONCAT('%', #{keyword}, '%') OR `name_pinyin_full` LIKE CONCAT(#{keyword}, '%') OR `name_pinyin_initial` LIKE CONCAT(#{keyword}, '%') OR `name_pinyin_mixed` LIKE CONCAT(#{keyword}, '%')) diff --git a/src/main/resources/mapper/timi-server/gao/GaoProductStockMapper.xml b/src/main/resources/mapper/timi-server/gao/GaoProductStockMapper.xml index c28beb9..7a3a673 100644 --- a/src/main/resources/mapper/timi-server/gao/GaoProductStockMapper.xml +++ b/src/main/resources/mapper/timi-server/gao/GaoProductStockMapper.xml @@ -23,7 +23,7 @@ AND k.`stock_enabled` = 1 AND k.`status` = 'ACTIVE' AND p.`store_id` = #{storeId} AND k.`product_id` = #{productId} - AND (p.`code` LIKE CONCAT('%', #{keyword}, '%') OR p.`name` LIKE CONCAT('%', #{keyword}, '%') OR k.`code` LIKE CONCAT('%', #{keyword}, '%') OR k.`name` LIKE CONCAT('%', #{keyword}, '%') OR k.`spec_summary` LIKE CONCAT('%', #{keyword}, '%') OR k.`barcode` LIKE CONCAT('%', #{keyword}, '%')) + AND (p.`code` LIKE CONCAT('%', #{keyword}, '%') OR p.`name` LIKE CONCAT('%', #{keyword}, '%') OR p.`name_pinyin_full` LIKE CONCAT(#{keyword}, '%') OR p.`name_pinyin_initial` LIKE CONCAT(#{keyword}, '%') OR p.`name_pinyin_mixed` LIKE CONCAT(#{keyword}, '%') OR k.`code` LIKE CONCAT('%', #{keyword}, '%') OR k.`name` LIKE CONCAT('%', #{keyword}, '%') OR k.`spec_summary` LIKE CONCAT('%', #{keyword}, '%') OR k.`barcode` LIKE CONCAT('%', #{keyword}, '%')) @@ -57,7 +57,7 @@ AND p.`stock_enabled` = 1 AND k.`stock_enabled` = 1 AND k.`status` = 'ACTIVE' AND p.`store_id` = #{storeId} - AND (p.`code` LIKE CONCAT('%', #{keyword}, '%') OR p.`name` LIKE CONCAT('%', #{keyword}, '%')) + AND (p.`code` LIKE CONCAT('%', #{keyword}, '%') OR p.`name` LIKE CONCAT('%', #{keyword}, '%') OR p.`name_pinyin_full` LIKE CONCAT(#{keyword}, '%') OR p.`name_pinyin_initial` LIKE CONCAT(#{keyword}, '%') OR p.`name_pinyin_mixed` LIKE CONCAT(#{keyword}, '%'))