2023-05-12-01-bug

master
喻忠伟 2 years ago
parent d7d615dfe8
commit 282e5196c4
  1. 23
      ant-design-vue-jeecg/src/views/zygoods/modules/ZyGoodsForm.vue
  2. 83
      jeecg-boot/jeecg-boot-base/jeecg-boot-base-tools/src/main/java/org/jeecg/common/util/UniqueRanNumUtils.java
  3. 9
      jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/demo/zygoods/controller/ZyGoodsController.java

@ -223,16 +223,21 @@
});
},
getspbh(){
getAction(this.url.zy, {lxid:this.model.clothsTypeId,xhid:this.model.modelId}).then((res) => {
if (res.success) {
// console.log(res.result.nums)
// this.$forceUpdate();
//
this.$set(this.model,'goodsCode',res.result);
} else {
// //-
if(!this.model.id)
{
getAction(this.url.zy, {lxid:this.model.clothsTypeId,xhid:this.model.modelId}).then((res) => {
if (res.success) {
// console.log(res.result.nums)
// this.$forceUpdate();
//
this.$set(this.model,'goodsCode',res.result);
} else {
}
});
}
}
});
},
add () {
this.edit(this.modelDefault);

@ -0,0 +1,83 @@
package org.jeecg.common.util;
import java.util.Random;
public class UniqueRanNumUtils {
/**
* 自定义进制(排除0,1,o,l)
*/
private static final char[] CUSTOM = new char[]{'Q', 'W', 'E', '8', 'A', 'S', '2', 'D', 'Z', 'X', '9', 'C', '7', 'P', '5', 'I', 'K', '3', 'M', 'J', 'U', 'F', 'R', '4', 'V', 'Y', 'L', 'T', 'N', '6', 'B', 'G'};
/**
* 不能与自定义进制有重复
*/
private static final char FLAG = 'H';
/**
* 进制长度
*/
private static final int LENGTH = CUSTOM.length;
/**
* 序列最小长度
*/
private static final int MINLENGTH = 6;
/**
* 根据ID生成六位随机码
* @return 随机码
*/
public static String generateCode(long id) {
char[] buf = new char[32];
int charPos = 32;
while ((id / LENGTH) > 0) {
int ind = (int) (id % LENGTH);
buf[--charPos] = CUSTOM[ind];
id /= LENGTH;
}
buf[--charPos] = CUSTOM[(int) (id % LENGTH)];
String str = new String(buf, charPos, (32 - charPos));
// 不够长度的自动随机补全
if (str.length() < MINLENGTH) {
StringBuilder sb = new StringBuilder();
sb.append(FLAG);
Random rnd = new Random();
for (int i = 1; i < MINLENGTH - str.length(); i++) {
sb.append(CUSTOM[rnd.nextInt(LENGTH)]);
}
str += sb.toString();
}
return str;
}
public static long codeToId(String code) {
char chs[] = code.toCharArray();
long res = 0L;
for (int i = 0; i < chs.length; i++) {
int ind = 0;
for (int j = 0; j < LENGTH; j++) {
if (chs[i] == CUSTOM[j]) {
ind = j;
break;
}
}
if (chs[i] == FLAG) {
break;
}
if (i > 0) {
res = res * LENGTH + ind;
} else {
res = ind;
}
}
return res;
}
public static void main(String[] args) {
for (int i = 0; i < 10; i++) {
System.out.println(generateCode(i));
}
}
}

@ -9,6 +9,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.util.UniqueRanNumUtils;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.demo.base.entity.ZyClothsModular;
import org.jeecg.modules.demo.base.entity.ZyClothsType;
@ -399,12 +400,18 @@ public class ZyGoodsController extends JeecgController<ZyGoods, IZyGoodsService>
//顺序号
String sxh = "";
ZyGoods zyGoods = new ZyGoods();
//随机6位随机码
QueryWrapper<ZyGoods> qw =new QueryWrapper();
List<ZyGoods> zyGoodslong = zyGoodsService.list(qw);
String rcode=UniqueRanNumUtils.generateCode(zyGoodslong.size());
QueryWrapper<ZyGoods> queryWrapper = QueryGenerator.initQueryWrapper(zyGoods, req.getParameterMap());
queryWrapper.eq("cloths_type_id",lxid);
queryWrapper.eq("model_id",xhid);
List<ZyGoods> list = zyGoodsService.list(queryWrapper);
sxh = list.size()+1+"";
spbh = lxbh + xhbm + sxh;
//随机数=服装类型编号+随机6位+型号编码+该类型商品长度
spbh = lxbh+rcode+ xhbm + sxh;
return Result.OK(spbh);
}

Loading…
Cancel
Save