给商品导入增加通过名称生成助记码的功能
This commit is contained in:
parent
34f65fcbf3
commit
6d20b6393f
@ -19,6 +19,7 @@ import com.jsh.erp.service.unit.UnitService;
|
||||
import com.jsh.erp.service.user.UserService;
|
||||
import com.jsh.erp.utils.BaseResponseInfo;
|
||||
import com.jsh.erp.utils.ExcelUtils;
|
||||
import com.jsh.erp.utils.PinYinUtil;
|
||||
import com.jsh.erp.utils.StringUtil;
|
||||
import jxl.Sheet;
|
||||
import jxl.Workbook;
|
||||
@ -626,6 +627,8 @@ public class MaterialService {
|
||||
m.setModel(model);
|
||||
m.setColor(color);
|
||||
m.setBrand(brand);
|
||||
//通过名称生成助记码
|
||||
m.setMnemonic(PinYinUtil.getFirstLettersLo(name));
|
||||
Long categoryId = materialCategoryService.getCategoryIdByName(categoryName);
|
||||
if(null!=categoryId){
|
||||
m.setCategoryId(categoryId);
|
||||
|
||||
52
jshERP-boot/src/main/java/com/jsh/erp/utils/PinYinUtil.java
Normal file
52
jshERP-boot/src/main/java/com/jsh/erp/utils/PinYinUtil.java
Normal file
@ -0,0 +1,52 @@
|
||||
package com.jsh.erp.utils;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.sourceforge.pinyin4j.PinyinHelper;
|
||||
import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;
|
||||
import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
|
||||
import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
|
||||
import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;
|
||||
|
||||
/**
|
||||
* @Author jishenghua
|
||||
* @Date 2024-01-08 23:03
|
||||
*/
|
||||
@Slf4j
|
||||
public class PinYinUtil {
|
||||
|
||||
public static String getFirstLettersLo(String ChineseLanguage) {
|
||||
return getFirstLetters(ChineseLanguage, HanyuPinyinCaseType.LOWERCASE);
|
||||
}
|
||||
|
||||
public static String getFirstLetters(String chineseLanguage, HanyuPinyinCaseType caseType) {
|
||||
char[] cl_chars = chineseLanguage.trim().toCharArray();
|
||||
StringBuilder pinyin = new StringBuilder();
|
||||
HanyuPinyinOutputFormat defaultFormat = new HanyuPinyinOutputFormat();
|
||||
// 输出拼音全部大写
|
||||
defaultFormat.setCaseType(caseType);
|
||||
// 不带声调
|
||||
defaultFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
|
||||
try {
|
||||
for (char cl_char : cl_chars) {
|
||||
String str = String.valueOf(cl_char);
|
||||
if (str.matches("[\u4e00-\u9fa5]+")) {
|
||||
// 如果字符是中文,则将中文转为汉语拼音,并取第一个字母
|
||||
pinyin.append(PinyinHelper.toHanyuPinyinStringArray(cl_char, defaultFormat)[0].substring(0, 1));
|
||||
} else if (str.matches("[0-9]+")) {
|
||||
// 如果字符是数字,取数字
|
||||
pinyin.append(cl_char);
|
||||
} else if (str.matches("[a-zA-Z]+")) {
|
||||
// 如果字符是字母,取字母
|
||||
pinyin.append(cl_char);
|
||||
} else {
|
||||
// 否则不转换
|
||||
//如果是标点符号的话,带着
|
||||
pinyin.append(cl_char);
|
||||
}
|
||||
}
|
||||
} catch (BadHanyuPinyinOutputFormatCombination e) {
|
||||
log.error(chineseLanguage + "转拼音失败!", e);
|
||||
}
|
||||
return pinyin.toString();
|
||||
}
|
||||
}
|
||||
@ -78,8 +78,8 @@
|
||||
</a-col>
|
||||
<a-col :md="6" :sm="24">
|
||||
<a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="助记码" data-step="7" data-title="助记码"
|
||||
data-intro="请填写商品的助记码,助记码是商品名称的首字母缩写">
|
||||
<a-input placeholder="请输入助记码" v-decorator.trim="[ 'mnemonic' ]" />
|
||||
data-intro="助记码自动生成,助记码是商品名称的首字母缩写">
|
||||
<a-input placeholder="" v-decorator.trim="[ 'mnemonic' ]" :readOnly="true" />
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :md="6" :sm="24">
|
||||
|
||||
Loading…
Reference in New Issue
Block a user