修改耗材代码生成规则
This commit is contained in:
parent
b6df6fd74d
commit
5226b1719a
|
|
@ -18,10 +18,7 @@ import cn.ysk.cashier.repository.product.TbProductStockOperateRepository;
|
|||
import cn.ysk.cashier.repository.shop.TbShopInfoRepository;
|
||||
import cn.ysk.cashier.repository.shop.TbShopPurveyorRepository;
|
||||
import cn.ysk.cashier.repository.shop.TbShopPurveyorTransactRepository;
|
||||
import cn.ysk.cashier.utils.FileUtil;
|
||||
import cn.ysk.cashier.utils.PageUtil;
|
||||
import cn.ysk.cashier.utils.QueryHelp;
|
||||
import cn.ysk.cashier.utils.ValidationUtil;
|
||||
import cn.ysk.cashier.utils.*;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
|
@ -44,6 +41,8 @@ import java.math.RoundingMode;
|
|||
import java.sql.Timestamp;
|
||||
import java.util.*;
|
||||
|
||||
import static cn.ysk.cashier.utils.StringCodeUtil.TYPE.LETTER_CAPITAL_NUMBER;
|
||||
|
||||
/**
|
||||
* @author admin
|
||||
* @website https://eladmin.vip
|
||||
|
|
@ -115,7 +114,7 @@ public class TbConsInfoServiceImpl implements TbConsInfoService {
|
|||
// }
|
||||
|
||||
|
||||
resources.setConCode(UUID.randomUUID().toString());
|
||||
resources.setConCode(StringCodeUtil.getRandom(8,LETTER_CAPITAL_NUMBER));
|
||||
resources.setConTypeName(tbConsType.getConTypeName());
|
||||
resources.setLasterInStock(BigDecimal.ZERO);
|
||||
resources.setStockNumber(BigDecimal.ZERO);
|
||||
|
|
@ -391,7 +390,7 @@ public class TbConsInfoServiceImpl implements TbConsInfoService {
|
|||
TbConsInfo consInfo = tbConsInfoRepository.findByConCode(cell0.toString());
|
||||
if (ObjectUtil.isEmpty(consInfo) || ObjectUtil.isNull(consInfo)) {
|
||||
consInfo = new TbConsInfo();
|
||||
consInfo.setConCode(UUID.randomUUID().toString());
|
||||
consInfo.setConCode(StringCodeUtil.getRandom(8,LETTER_CAPITAL_NUMBER));
|
||||
consInfo.setShopId(Integer.valueOf(shopId));
|
||||
consInfo.setConTypeId(tbConsType.getId());
|
||||
consInfo.setConTypeName(tbConsType.getConTypeName());
|
||||
|
|
@ -447,7 +446,7 @@ public class TbConsInfoServiceImpl implements TbConsInfoService {
|
|||
}
|
||||
} else {
|
||||
TbConsInfo consInfo = new TbConsInfo();
|
||||
consInfo.setConCode(UUID.randomUUID().toString());
|
||||
consInfo.setConCode(StringCodeUtil.getRandom(8,LETTER_CAPITAL_NUMBER));
|
||||
consInfo.setShopId(Integer.valueOf(shopId));
|
||||
consInfo.setConTypeId(tbConsType.getId());
|
||||
consInfo.setConTypeName(tbConsType.getConTypeName());
|
||||
|
|
|
|||
|
|
@ -3,10 +3,7 @@ package cn.ysk.cashier.cons.service.impl;
|
|||
import cn.ysk.cashier.cons.domain.TbConsInfo;
|
||||
import cn.ysk.cashier.cons.domain.TbConsType;
|
||||
import cn.ysk.cashier.cons.repository.TbConsInfoRepository;
|
||||
import cn.ysk.cashier.utils.FileUtil;
|
||||
import cn.ysk.cashier.utils.PageUtil;
|
||||
import cn.ysk.cashier.utils.QueryHelp;
|
||||
import cn.ysk.cashier.utils.ValidationUtil;
|
||||
import cn.ysk.cashier.utils.*;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import cn.ysk.cashier.cons.repository.TbConsTypeRepository;
|
||||
import cn.ysk.cashier.cons.service.TbConsTypeService;
|
||||
|
|
@ -22,6 +19,8 @@ import java.util.*;
|
|||
import java.io.IOException;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import static cn.ysk.cashier.utils.StringCodeUtil.TYPE.LETTER_CAPITAL_NUMBER;
|
||||
|
||||
/**
|
||||
* @website https://eladmin.vip
|
||||
* @description 服务实现
|
||||
|
|
@ -61,7 +60,7 @@ public class TbConsTypeServiceImpl implements TbConsTypeService {
|
|||
public TbConsTypeDto create(TbConsType resources) throws Exception {
|
||||
|
||||
|
||||
resources.setConTypeCode(UUID.randomUUID().toString());
|
||||
resources.setConTypeCode(StringCodeUtil.getRandom(8,LETTER_CAPITAL_NUMBER));
|
||||
return tbConsTypeMapper.toDto(tbConsTypeRepository.save(resources));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,200 @@
|
|||
package cn.ysk.cashier.utils;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* @author admin
|
||||
* @description 随机编码生成工具类
|
||||
* @date 2020-11-24 16:07
|
||||
* @menu
|
||||
*/
|
||||
public class StringCodeUtil {
|
||||
public static enum TYPE {
|
||||
/**
|
||||
* 字符型
|
||||
*/
|
||||
LETTER,
|
||||
/**
|
||||
* 大写字符型
|
||||
*/
|
||||
CAPITAL,
|
||||
/**
|
||||
* 数字型
|
||||
*/
|
||||
NUMBER,
|
||||
/**
|
||||
* 符号型
|
||||
*/
|
||||
SIGN,
|
||||
/**
|
||||
* 大+小字符 型
|
||||
*/
|
||||
LETTER_CAPITAL,
|
||||
/**
|
||||
* 小字符+数字 型
|
||||
*/
|
||||
LETTER_NUMBER,
|
||||
/**
|
||||
* 大+小字符+数字 型
|
||||
*/
|
||||
LETTER_CAPITAL_NUMBER,
|
||||
/**
|
||||
* 大+小字符+数字+符号 型
|
||||
*/
|
||||
LETTER_CAPITAL_NUMBER_SIGN
|
||||
}
|
||||
|
||||
private static String[] lowercase = {
|
||||
"a","b","c","d","e","f","g","h","i","j","k",
|
||||
"l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
|
||||
|
||||
private static String[] capital = {
|
||||
"A","B","C","D","E","F","G","H","I","J","K",
|
||||
"L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
|
||||
|
||||
private static String[] number = {
|
||||
"1","2","3","4","5","6","7","8","9","0"};
|
||||
|
||||
private static String[] sign = {
|
||||
"~","!","@","#","$","%","^","&","*","(",")","_","+","`","-","=",
|
||||
"{","}","|",":","\"","<",">","?",
|
||||
"[","]","\\",";","'",",",".","/"};
|
||||
|
||||
/**
|
||||
* 静态随机数
|
||||
*/
|
||||
private static Random random = new Random();
|
||||
|
||||
|
||||
/**
|
||||
* 获取随机组合码
|
||||
* @param num 位数
|
||||
* @param type 类型
|
||||
* @type
|
||||
* <br>字符型 LETTER,
|
||||
* <br>大写字符型 CAPITAL,
|
||||
* <br>数字型 NUMBER,
|
||||
* <br>符号型 SIGN,
|
||||
* <br>大+小字符型 LETTER_CAPITAL,
|
||||
* <br>小字符+数字 型 LETTER_NUMBER,
|
||||
* <br>大+小字符+数字 型 LETTER_CAPITAL_NUMBER,
|
||||
* <br>大+小字符+数字+符号 型 LETTER_CAPITAL_NUMBER_SIGN
|
||||
*/
|
||||
public static String getRandom(int num,TYPE type){
|
||||
ArrayList<String> temp = new ArrayList<String>();
|
||||
StringBuffer code = new StringBuffer();
|
||||
if(type == TYPE.LETTER){
|
||||
temp.addAll(Arrays.asList(lowercase));
|
||||
}else if(type == TYPE.CAPITAL){
|
||||
temp.addAll(Arrays.asList(capital));
|
||||
}else if(type == TYPE.NUMBER){
|
||||
temp.addAll(Arrays.asList(number));
|
||||
}else if(type == TYPE.SIGN){
|
||||
temp.addAll(Arrays.asList(sign));
|
||||
}else if(type == TYPE.LETTER_CAPITAL){
|
||||
temp.addAll(Arrays.asList(lowercase));
|
||||
temp.addAll(Arrays.asList(capital));
|
||||
}else if(type == TYPE.LETTER_NUMBER){
|
||||
temp.addAll(Arrays.asList(lowercase));
|
||||
temp.addAll(Arrays.asList(number));
|
||||
}else if(type == TYPE.LETTER_CAPITAL_NUMBER){
|
||||
temp.addAll(Arrays.asList(lowercase));
|
||||
temp.addAll(Arrays.asList(capital));
|
||||
temp.addAll(Arrays.asList(number));
|
||||
}else if(type == TYPE.LETTER_CAPITAL_NUMBER_SIGN){
|
||||
temp.addAll(Arrays.asList(lowercase));
|
||||
temp.addAll(Arrays.asList(capital));
|
||||
temp.addAll(Arrays.asList(number));
|
||||
temp.addAll(Arrays.asList(sign));
|
||||
}
|
||||
for (int i = 0; i < num; i++) {
|
||||
code.append(temp.get(random.nextInt(temp.size())));
|
||||
}
|
||||
return code.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 手机掩码
|
||||
* @param phone
|
||||
* @return
|
||||
*/
|
||||
public static String maskPhone(String phone){
|
||||
return wordMask(phone,3,4,"*");
|
||||
}
|
||||
|
||||
/**
|
||||
* 身份证掩码
|
||||
* @param idCardNo
|
||||
* @return
|
||||
*/
|
||||
public static String maskIdCardNo(String idCardNo){
|
||||
return wordMask(idCardNo,3,3,"*");
|
||||
}
|
||||
|
||||
/**
|
||||
* 真实姓名掩码
|
||||
* @param realName
|
||||
* @return
|
||||
*/
|
||||
public static String maskRealName(String realName){
|
||||
return wordMask(realName,1,1,"*");
|
||||
}
|
||||
|
||||
/**
|
||||
* 邮箱掩码
|
||||
* @param email
|
||||
* @return
|
||||
*/
|
||||
public static String maskEmail(String email){
|
||||
return wordMask(email,3,3,"*");
|
||||
}
|
||||
|
||||
/**
|
||||
* QQ掩码
|
||||
* @param qq
|
||||
* @return
|
||||
*/
|
||||
public static String maskQQ(String qq){
|
||||
return wordMask(qq,3,3,"*");
|
||||
}
|
||||
|
||||
/**
|
||||
* 邮箱掩码
|
||||
* @param weChat
|
||||
* @return
|
||||
*/
|
||||
public static String maskWeChat(String weChat){
|
||||
return wordMask(weChat,3,3,"*");
|
||||
}
|
||||
|
||||
/**
|
||||
* 对字符串进行脱敏处理
|
||||
* @param word 被脱敏的字符
|
||||
* @param startLength 被保留的开始长度 0代表不保留
|
||||
* @param endLength 被保留的结束长度 0代表不保留
|
||||
* @param pad 填充字符
|
||||
* */
|
||||
public static String wordMask(String word,int startLength ,int endLength,String pad) {
|
||||
if(word==null) {
|
||||
return StringUtils.leftPad("", startLength+endLength,pad);
|
||||
}
|
||||
if(word.length()<=startLength+endLength) {
|
||||
return StringUtils.leftPad("", startLength+endLength,pad);
|
||||
}
|
||||
String startStr = "";
|
||||
String endStr = "";
|
||||
int padLength = 0;
|
||||
if(word.length()>startLength) {
|
||||
startStr = StringUtils.substring(word, 0,startLength);
|
||||
}
|
||||
if(word.length()>startLength+endLength) {
|
||||
endStr = StringUtils.substring(word, word.length()-endLength);
|
||||
}
|
||||
padLength = word.length()-startLength-endLength;
|
||||
return startStr + StringUtils.repeat(pad, padLength)+endStr;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue