1464 发货系统-条码打印-物料码打印页面的条码号规则更改

This commit is contained in:
10002617 2026-05-07 15:58:00 +08:00
parent 70bac66fcd
commit 9ec0603c06
3 changed files with 83 additions and 6 deletions

View File

@ -266,7 +266,7 @@ public class MaterialCodeController extends BaseController {
items.add(item);
qrs.add(new WmsShipmentMaterialCodeItemQr()
.setItemId(item.getId())
.setNo(KeyUtil.next())
.setNo(KeyUtil.nextFCode())
.setNum(item.getMinPackagingNum())
.setCreateBy(UserUtil.getUserName())
.setCreateTime(LocalDateTime.now())
@ -318,7 +318,7 @@ public class MaterialCodeController extends BaseController {
for (int i = 1; i <= item.getPackingNum(); i++) {
materialCodeItemQrService.save(new WmsShipmentMaterialCodeItemQr()
.setItemId(item.getId())
.setNo(KeyUtil.next())
.setNo(KeyUtil.nextFCode())
// .setNum(i == count && decimalValue.compareTo(BigDecimal.ZERO) > 0 ? decimalValue : item.getMinPackagingNum())
.setNum(NumberUtil.getPackageNum(item.getNum(), item.getMinPackagingNum(), item.getPackingNum(), i))
.setCreateBy(UserUtil.getUserName())
@ -367,7 +367,7 @@ public class MaterialCodeController extends BaseController {
for (int i = 1; i <= item.getPackingNum(); i++) {
materialCodeItemQrService.save(new WmsShipmentMaterialCodeItemQr()
.setItemId(item.getId())
.setNo(KeyUtil.next())
.setNo(KeyUtil.nextFCode())
.setNum(NumberUtil.getPackageNum(item.getNum(), item.getMinPackagingNum(), item.getPackingNum(), i))
.setCreateBy(UserUtil.getUserName())
.setCreateTime(LocalDateTime.now())
@ -449,7 +449,7 @@ public class MaterialCodeController extends BaseController {
itemsForAdd.add(item);
qrsForAdd.add(new WmsShipmentMaterialCodeItemQr()
.setItemId(item.getId())
.setNo(KeyUtil.next())
.setNo(KeyUtil.nextFCode())
.setNum(item.getMinPackagingNum())
.setCreateBy(UserUtil.getUserName())
.setCreateTime(LocalDateTime.now())
@ -465,7 +465,7 @@ public class MaterialCodeController extends BaseController {
itemsForAdd.add(item);
qrsForAdd.add(new WmsShipmentMaterialCodeItemQr()
.setItemId(item.getId())
.setNo(KeyUtil.next())
.setNo(KeyUtil.nextFCode())
.setNum(item.getMinPackagingNum())
.setCreateBy(UserUtil.getUserName())
.setCreateTime(LocalDateTime.now())
@ -494,7 +494,7 @@ public class MaterialCodeController extends BaseController {
} else {
qrsForAdd.add(new WmsShipmentMaterialCodeItemQr()
.setItemId(item.getId())
.setNo(KeyUtil.next())
.setNo(KeyUtil.nextFCode())
.setNum(item.getMinPackagingNum())
.setCreateBy(UserUtil.getUserName())
.setCreateTime(LocalDateTime.now())

View File

@ -1,9 +1,27 @@
package com.nflg.wms.shipment.util;
import com.nflg.wms.common.constant.STATE;
import com.nflg.wms.common.exception.NflgException;
import com.nflg.wms.repository.entity.WmsShipmentMaterialCodeItemQr;
import com.nflg.wms.repository.service.IWmsShipmentMaterialCodeItemQrService;
import com.nflg.wms.starter.utils.SpringContextHolder;
import io.hypersistence.tsid.TSID;
import java.security.SecureRandom;
public class KeyUtil {
private static final SecureRandom RANDOM = new SecureRandom();
private static final int MAX_RETRY = 100;
private static IWmsShipmentMaterialCodeItemQrService wmsShipmentMaterialCodeItemQrService;
private static IWmsShipmentMaterialCodeItemQrService getWmsShipmentMaterialCodeItemQrService() {
if (wmsShipmentMaterialCodeItemQrService == null) {
wmsShipmentMaterialCodeItemQrService = SpringContextHolder.getBean(IWmsShipmentMaterialCodeItemQrService.class);
}
return wmsShipmentMaterialCodeItemQrService;
}
public static String next(){
return TSID.Factory.getTsid().toString();
}
@ -11,4 +29,30 @@ public class KeyUtil {
public static String nextBase62(){
return TSID.Factory.getTsid().encode(62);
}
/**
* 生成规则F + 12位随机数字保证唯一性
* 如果生成的编码已存在则重新生成最多重试100次
* 例如F123456789012
*/
public static String nextFCode(){
for (int i = 0; i < MAX_RETRY; i++) {
String code = generateCode("F");
long count = getWmsShipmentMaterialCodeItemQrService().lambdaQuery()
.eq(WmsShipmentMaterialCodeItemQr::getNo, code)
.count();
if (count == 0) {
return code;
}
}
throw new NflgException(STATE.BusinessError, "生成唯一条码号失败,请重试");
}
private static String generateCode(String prefix){
StringBuilder sb = new StringBuilder(prefix);
for (int i = 0; i < 12; i++) {
sb.append(RANDOM.nextInt(10));
}
return sb.toString();
}
}

View File

@ -0,0 +1,33 @@
package com.nflg.wms.starter.utils;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
@Component
public class SpringContextHolder implements ApplicationContextAware {
private static ApplicationContext applicationContext;
@Override
public void setApplicationContext(ApplicationContext context) throws BeansException {
applicationContext = context;
}
public static <T> T getBean(Class<T> clazz) {
return applicationContext.getBean(clazz);
}
public static <T> T getBean(String name, Class<T> clazz) {
return applicationContext.getBean(name, clazz);
}
public static Object getBean(String name) {
return applicationContext.getBean(name);
}
public static ApplicationContext getApplicationContext() {
return applicationContext;
}
}