support pinyin for product
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
+12
@@ -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<GaoProduct
|
||||
TimiException.required(product.getStoreId(), "not found product.storeId");
|
||||
product.setCode(requiredText(product.getCode(), "产品编码不能为空"));
|
||||
product.setName(requiredText(product.getName(), "产品名称不能为空"));
|
||||
fillPinyin(product);
|
||||
product.setProductType(TimiJava.defaultIfNull(product.getProductType(), GaoProduct.ProductType.GOODS));
|
||||
product.setStockEnabled(TimiJava.defaultIfNull(product.getStockEnabled(), product.getProductType() != GaoProduct.ProductType.SERVICE));
|
||||
TimiException.requiredTrue(product.getProductType() != GaoProduct.ProductType.SERVICE || !product.getStockEnabled(), "SERVICE 产品不能启用库存");
|
||||
@@ -261,4 +263,14 @@ public class GaoProductServiceImplement extends AbstractEntityService<GaoProduct
|
||||
TimiException.requiredTrue(!result.isEmpty(), message);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// 填充产品名称拼音搜索字段
|
||||
///
|
||||
/// @param product 产品
|
||||
private void fillPinyin(GaoProduct product) {
|
||||
String name = product.getName();
|
||||
product.setNamePinyinFull(PinyinUtil.full(name));
|
||||
product.setNamePinyinInitial(PinyinUtil.initial(name));
|
||||
product.setNamePinyinMixed(PinyinUtil.mixed(name));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,6 @@ public class GaoProductPage extends BasePage {
|
||||
/// 产品类型
|
||||
private GaoProduct.ProductType productType;
|
||||
|
||||
/// 名称或编码关键词
|
||||
/// 名称、拼音或编码关键词
|
||||
private String keyword;
|
||||
}
|
||||
|
||||
@@ -18,6 +18,6 @@ public class GaoProductStockPage extends BasePage {
|
||||
/// 产品 ID
|
||||
private String productId;
|
||||
|
||||
/// 产品或 SKU 名称、编码、规格摘要关键词
|
||||
/// 产品或 SKU 名称、拼音、编码、规格摘要关键词
|
||||
private String keyword;
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ public class GaoProductStockRecordPage extends BasePage {
|
||||
/// 产品 ID
|
||||
private String productId;
|
||||
|
||||
/// 产品名称或编码关键词
|
||||
/// 产品名称、拼音或编码关键词
|
||||
private String keyword;
|
||||
|
||||
/// 来源业务类型
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
package com.imyeyu.api.modules.system.controller;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author 夜雨
|
||||
* @since 2026-04-23 16:31
|
||||
*/
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/system/setting")
|
||||
public class SettingController {
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package db.migration.timiserver;
|
||||
|
||||
import com.imyeyu.api.util.PinyinUtil;
|
||||
import org.flywaydb.core.api.migration.BaseJavaMigration;
|
||||
import org.flywaydb.core.api.migration.Context;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
|
||||
/// 回填 GAO 产品名称拼音搜索字段
|
||||
///
|
||||
/// @author Codex
|
||||
/// @since 2026-09-10
|
||||
public class V78__backfill_gao_product_pinyin_search extends BaseJavaMigration {
|
||||
|
||||
private static final int BATCH_SIZE = 500;
|
||||
|
||||
@Override
|
||||
public void migrate(Context context) throws Exception {
|
||||
Connection connection = context.getConnection();
|
||||
try (
|
||||
PreparedStatement select = connection.prepareStatement("""
|
||||
SELECT `id`, `name`
|
||||
FROM `gao_product`
|
||||
WHERE `name` IS NOT NULL
|
||||
AND (`name_pinyin_full` IS NULL OR `name_pinyin_initial` IS NULL OR `name_pinyin_mixed` IS NULL)
|
||||
""");
|
||||
PreparedStatement update = connection.prepareStatement("""
|
||||
UPDATE `gao_product`
|
||||
SET `name_pinyin_full` = ?, `name_pinyin_initial` = ?, `name_pinyin_mixed` = ?
|
||||
WHERE `id` = ?
|
||||
""")) {
|
||||
try (ResultSet resultSet = select.executeQuery()) {
|
||||
int batchSize = 0;
|
||||
while (resultSet.next()) {
|
||||
String name = resultSet.getString("name");
|
||||
update.setString(1, PinyinUtil.full(name));
|
||||
update.setString(2, PinyinUtil.initial(name));
|
||||
update.setString(3, PinyinUtil.mixed(name));
|
||||
update.setString(4, resultSet.getString("id"));
|
||||
update.addBatch();
|
||||
batchSize++;
|
||||
if (batchSize >= BATCH_SIZE) {
|
||||
update.executeBatch();
|
||||
batchSize = 0;
|
||||
}
|
||||
}
|
||||
if (0 < batchSize) {
|
||||
update.executeBatch();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user