优化商品的条码的自增逻辑,解决长条码的问题
This commit is contained in:
@@ -28,6 +28,7 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.File;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.util.*;
|
||||
|
||||
@Service
|
||||
@@ -1329,13 +1330,14 @@ public class MaterialService {
|
||||
public String getMaxBarCode() {
|
||||
List<String> barCodeOldList = materialMapperEx.getBarCodeList();
|
||||
// 使用 Stream API 处理条码列表
|
||||
OptionalLong maxBarcode = barCodeOldList.stream()
|
||||
// 使用 BigInteger 处理可能的大数字
|
||||
Optional<BigInteger> maxBarcode = barCodeOldList.stream()
|
||||
.filter(StringUtil::isNumeric) // 过滤掉非数字条码
|
||||
.mapToLong(Long::parseLong) // 将字符串转换为 Long 类型
|
||||
.max(); // 获取最大值
|
||||
.map(BigInteger::new) // 使用 BigInteger 构造函数
|
||||
.max(Comparator.naturalOrder()); // 获取最大值
|
||||
// 如果存在最大值,返回它;否则返回 1000L
|
||||
Long maxBarCodeOld = maxBarcode.orElse(1000L);
|
||||
return maxBarCodeOld + "";
|
||||
BigInteger maxBarCodeOld = maxBarcode.orElse(new BigInteger("1000"));
|
||||
return maxBarCodeOld.toString();
|
||||
}
|
||||
|
||||
public List<String> getMaterialNameList() {
|
||||
|
||||
@@ -564,6 +564,36 @@ export function getPrevMonthFormatDate(monthNum) {
|
||||
return prevMonth.getFullYear() + seperator1 + month + seperator1 + strDate
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义大数加法函数,两个数字相加
|
||||
* @param a
|
||||
* @param b
|
||||
* @returns {string}
|
||||
*/
|
||||
export function addBigNumbers(a, b) {
|
||||
a = a.toString();
|
||||
b = b.toString();
|
||||
// 反转字符串,从个位开始计算
|
||||
let aRev = a.split('').reverse();
|
||||
let bRev = b.split('').reverse();
|
||||
const maxLength = Math.max(aRev.length, bRev.length);
|
||||
let result = [];
|
||||
let carry = 0;
|
||||
for (let i = 0; i < maxLength; i++) {
|
||||
const digitA = i < aRev.length ? parseInt(aRev[i]) : 0;
|
||||
const digitB = i < bRev.length ? parseInt(bRev[i]) : 0;
|
||||
const sum = digitA + digitB + carry;
|
||||
result.push(sum % 10);
|
||||
carry = Math.floor(sum / 10);
|
||||
}
|
||||
// 处理最后的进位
|
||||
if (carry > 0) {
|
||||
result.push(carry);
|
||||
}
|
||||
// 反转回来得到正确的结果
|
||||
return result.reverse().join('');
|
||||
}
|
||||
|
||||
/**
|
||||
* JS中根据指定值删除数组中的元素
|
||||
* @param arrylist
|
||||
|
||||
@@ -294,7 +294,7 @@
|
||||
import JEditableTable from '@/components/jeecg/JEditableTable'
|
||||
import { FormTypes, getRefPromise, VALIDATE_NO_PASSED, validateFormAndTables } from '@/utils/JEditableTableUtil'
|
||||
import { changeNameToPinYin, checkMaterial, checkMaterialBarCode, getMaterialAttributeNameList, getMaterialAttributeValueListById, getMaxBarCode, queryMaterialCategoryTreeList } from '@/api/api'
|
||||
import { autoJumpNextInput, handleIntroJs, removeByVal } from '@/utils/util'
|
||||
import { autoJumpNextInput, handleIntroJs, removeByVal, addBigNumbers } from '@/utils/util'
|
||||
import { getAction, httpAction } from '@/api/manage'
|
||||
import JImageUpload from '@/components/jeecg/JImageUpload'
|
||||
import JDate from '@/components/jeecg/JDate'
|
||||
@@ -578,11 +578,14 @@
|
||||
if(this.action === 'copyAdd') {
|
||||
getMaxBarCode({}).then((res)=> {
|
||||
if (res && res.code === 200) {
|
||||
let maxBarCode = res.data.barCode - 0
|
||||
let maxBarCode = res.data.barCode
|
||||
let meTableData = []
|
||||
for (let i = 0; i < tab.dataSource.length; i++) {
|
||||
let meInfo = tab.dataSource[i]
|
||||
meInfo.barCode = maxBarCode + i + 1
|
||||
console.log(maxBarCode)
|
||||
console.log(addBigNumbers(maxBarCode, i+1))
|
||||
meInfo.barCode = addBigNumbers(maxBarCode, i+1)
|
||||
console.log(meInfo.barCode)
|
||||
meTableData.push(meInfo)
|
||||
}
|
||||
tab.dataSource = meTableData
|
||||
@@ -1025,7 +1028,7 @@
|
||||
getMaxBarCode({}).then((res)=>{
|
||||
if(res && res.code===200) {
|
||||
let k = 0
|
||||
let maxBarCode = res.data.barCode-0
|
||||
let maxBarCode = res.data.barCode
|
||||
for (let i = 0; i < barCodeSku.length; i++) {
|
||||
let currentBarCode = ''
|
||||
let currentId = ''
|
||||
@@ -1050,7 +1053,7 @@
|
||||
wholesaleDecimal: wholesaleDecimal, lowDecimal: lowDecimal})
|
||||
} else {
|
||||
k = k+1
|
||||
currentBarCode = maxBarCode + k
|
||||
currentBarCode = addBigNumbers(maxBarCode, k)
|
||||
meTableData.push({barCode: currentBarCode, commodityUnit: unit, sku: barCodeSku[i]})
|
||||
}
|
||||
}
|
||||
@@ -1080,13 +1083,13 @@
|
||||
if(this.maxBarCodeInfo === '') {
|
||||
getMaxBarCode({}).then((res)=> {
|
||||
if (res && res.code === 200) {
|
||||
this.maxBarCodeInfo = res.data.barCode - 0
|
||||
this.maxBarCodeInfo = this.maxBarCodeInfo + 1
|
||||
this.maxBarCodeInfo = res.data.barCode
|
||||
this.maxBarCodeInfo = addBigNumbers(this.maxBarCodeInfo, 1)
|
||||
target.setValues([{rowKey: row.id, values: {barCode: this.maxBarCodeInfo, commodityUnit: unit?unit:''}}])
|
||||
}
|
||||
})
|
||||
} else {
|
||||
this.maxBarCodeInfo = this.maxBarCodeInfo + 1
|
||||
this.maxBarCodeInfo = addBigNumbers(this.maxBarCodeInfo, 1)
|
||||
target.setValues([{rowKey: row.id, values: {barCode: this.maxBarCodeInfo, commodityUnit: unit?unit:''}}])
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user