合并代码
This commit is contained in:
parent
df6041fed4
commit
3bacd3b8a4
|
|
@ -1,6 +1,5 @@
|
|||
package com.bonus.canteen.basic.controller;
|
||||
|
||||
import com.bonus.canteen.common.utils.StringUtils;
|
||||
import com.bonus.canteen.basic.model.BasicsComplaint;
|
||||
import com.bonus.canteen.basic.service.BasicsComplaintService;
|
||||
import com.bonus.common.core.web.controller.BaseController;
|
||||
|
|
@ -12,6 +11,7 @@ import org.springframework.web.bind.annotation.*;
|
|||
import javax.annotation.Resource;
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import static com.bonus.common.core.utils.PageUtils.startPage;
|
||||
|
||||
|
|
@ -66,7 +66,7 @@ public class BasicsComplaintController extends BaseController {
|
|||
@PostMapping
|
||||
public AjaxResult add(@Valid @RequestBody BasicsComplaint basicsComplaint) {
|
||||
BasicsComplaint insert = this.basicsComplaintService.insert(basicsComplaint);
|
||||
if (StringUtils.isNull(insert)){
|
||||
if (Objects.isNull(insert)){
|
||||
return AjaxResult.error("未登录,请先登录");
|
||||
}
|
||||
return AjaxResult.success(insert);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package com.bonus.canteen.basic.service.impl;
|
||||
|
||||
|
||||
import com.bonus.canteen.common.utils.StringUtil;
|
||||
import com.bonus.canteen.common.utils.StringUtils;
|
||||
import com.bonus.canteen.basic.mapper.BasicsCanteenEvaluateMapper;
|
||||
import com.bonus.canteen.basic.model.BasicsCanteenEvaluate;
|
||||
|
|
@ -15,6 +14,7 @@ import org.springframework.data.domain.PageRequest;
|
|||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 食堂评价表(BasicsCanteenEvaluate)表服务实现类
|
||||
|
|
@ -66,13 +66,13 @@ public class BasicsCanteenEvaluateServiceImpl implements BasicsCanteenEvaluateSe
|
|||
basicsCanteenEvaluate.setUptime(new Date());
|
||||
//创建人
|
||||
Long userid = SecurityUtils.getLoginUser().getUserid();
|
||||
if (StringUtils.isNull(userid)){
|
||||
if (Objects.isNull(userid)){
|
||||
return null;
|
||||
}
|
||||
|
||||
basicsCanteenEvaluate.setCrby(userid.toString());
|
||||
basicsCanteenEvaluate.setUpby(userid.toString());
|
||||
basicsCanteenEvaluate.setEvaluateId(StringUtil.generateRandomLong(18));
|
||||
basicsCanteenEvaluate.setEvaluateId(StringUtils.generateRandomLong(18));
|
||||
basicsCanteenEvaluate.setEvaluateDate(new Date());
|
||||
this.basicsCanteenEvaluateDao.insert(basicsCanteenEvaluate);
|
||||
return basicsCanteenEvaluate;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
package com.bonus.canteen.basic.service.impl;
|
||||
|
||||
import com.bonus.canteen.common.utils.StringUtil;
|
||||
import com.bonus.canteen.common.utils.StringUtils;
|
||||
import com.bonus.canteen.basic.model.BasicsComplaint;
|
||||
import com.bonus.canteen.basic.mapper.BasicsComplaintMapper;
|
||||
|
|
@ -11,6 +10,7 @@ import org.springframework.stereotype.Service;
|
|||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 投诉建议 (BasicsComplaint)表服务实现类
|
||||
|
|
@ -54,9 +54,9 @@ public class BasicsComplaintServiceImpl implements BasicsComplaintService {
|
|||
*/
|
||||
@Override
|
||||
public BasicsComplaint insert(BasicsComplaint basicsComplaint) {
|
||||
basicsComplaint.setComplaintId(StringUtil.generateRandomLong(18));
|
||||
basicsComplaint.setComplaintId(StringUtils.generateRandomLong(18));
|
||||
Long userid = SecurityUtils.getLoginUser().getUserid();
|
||||
if (StringUtils.isNull(userid)){
|
||||
if (Objects.isNull(userid)){
|
||||
return null;
|
||||
}
|
||||
basicsComplaint.setCrby(userid.toString());
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
package com.bonus.canteen.basic.service.impl;
|
||||
|
||||
import com.bonus.canteen.common.utils.StringUtil;
|
||||
import com.bonus.canteen.common.utils.StringUtils;
|
||||
import com.bonus.canteen.basic.model.CustAddr;
|
||||
import com.bonus.canteen.basic.mapper.CustAddrMapper;
|
||||
|
|
@ -11,6 +10,7 @@ import org.springframework.stereotype.Service;
|
|||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 地址信息表(CustAddr)表服务实现类
|
||||
|
|
@ -53,9 +53,9 @@ public class CustAddrServiceImpl implements CustAddrService {
|
|||
*/
|
||||
@Override
|
||||
public Integer insert(CustAddr custAddr) {
|
||||
custAddr.setAddrId(StringUtil.generateRandomLong(18));
|
||||
custAddr.setAddrId(StringUtils.generateRandomLong(18));
|
||||
Long userid = SecurityUtils.getLoginUser().getUserid();
|
||||
if (StringUtils.isNull(userid)){
|
||||
if (Objects.isNull(userid)){
|
||||
return null;
|
||||
}
|
||||
custAddr.setCrby(userid.toString());
|
||||
|
|
|
|||
|
|
@ -1,64 +0,0 @@
|
|||
package com.bonus.canteen.common.utils;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.Random;
|
||||
|
||||
public class StringUtil {
|
||||
|
||||
/**
|
||||
* 生成订单编号
|
||||
* @return
|
||||
*/
|
||||
public String generateOrderNumber() {
|
||||
// 获取当前时间戳(毫秒级)
|
||||
long timestamp = System.currentTimeMillis();
|
||||
// 生成一个 4 位的随机数(可以根据需要修改长度)
|
||||
int randomPart = (int) (Math.random() * 10000);
|
||||
// 组合时间戳和随机数
|
||||
return timestamp + String.format("%04d", randomPart);
|
||||
}
|
||||
|
||||
/**
|
||||
* 升成 18位的随机数
|
||||
* @param numDigits
|
||||
* @return
|
||||
*/
|
||||
public static long generateRandomLong(int numDigits) {
|
||||
Random random = new Random();
|
||||
long number = 0;
|
||||
|
||||
// 确保生成的数字是 18 位
|
||||
for (int i = 0; i < numDigits; i++) {
|
||||
number = number * 10 + random.nextInt(10);
|
||||
}
|
||||
|
||||
// 确保生成的数字不会超过 long 的最大值
|
||||
if (number > Long.MAX_VALUE) {
|
||||
number = Long.MAX_VALUE;
|
||||
}
|
||||
|
||||
return number;
|
||||
}
|
||||
|
||||
/**
|
||||
* 升成 18位的随机数
|
||||
* @param numDigits
|
||||
* @return
|
||||
*/
|
||||
public static String generateRandomString(int numDigits) {
|
||||
Random random = new Random();
|
||||
long number = 0;
|
||||
|
||||
// 确保生成的数字是 18 位
|
||||
for (int i = 0; i < numDigits; i++) {
|
||||
number = number * 10 + random.nextInt(10);
|
||||
}
|
||||
|
||||
// 确保生成的数字不会超过 long 的最大值
|
||||
if (number > Long.MAX_VALUE) {
|
||||
number = Long.MAX_VALUE;
|
||||
}
|
||||
|
||||
return String.valueOf(number);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,546 +1,63 @@
|
|||
package com.bonus.canteen.common.utils;
|
||||
|
||||
import org.springframework.util.AntPathMatcher;
|
||||
import java.util.Random;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 字符串工具类
|
||||
*
|
||||
* @author dzw
|
||||
*/
|
||||
public class StringUtils extends org.apache.commons.lang3.StringUtils
|
||||
{
|
||||
/** 空字符串 */
|
||||
private static final String NULLSTR = "";
|
||||
|
||||
/** 下划线 */
|
||||
private static final char SEPARATOR = '_';
|
||||
public class StringUtils {
|
||||
|
||||
/**
|
||||
* 获取参数不为空值
|
||||
*
|
||||
* @param value defaultValue 要判断的value
|
||||
* @return value 返回值
|
||||
*/
|
||||
public static <T> T nvl(T value, T defaultValue)
|
||||
{
|
||||
return value != null ? value : defaultValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* * 判断一个Collection是否为空, 包含List,Set,Queue
|
||||
*
|
||||
* @param coll 要判断的Collection
|
||||
* @return true:为空 false:非空
|
||||
*/
|
||||
public static boolean isEmpty(Collection<?> coll)
|
||||
{
|
||||
return isNull(coll) || coll.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* * 判断一个Collection是否非空,包含List,Set,Queue
|
||||
*
|
||||
* @param coll 要判断的Collection
|
||||
* @return true:非空 false:空
|
||||
*/
|
||||
public static boolean isNotEmpty(Collection<?> coll)
|
||||
{
|
||||
return !isEmpty(coll);
|
||||
}
|
||||
|
||||
/**
|
||||
* * 判断一个对象数组是否为空
|
||||
*
|
||||
* @param objects 要判断的对象数组
|
||||
** @return true:为空 false:非空
|
||||
*/
|
||||
public static boolean isEmpty(Object[] objects)
|
||||
{
|
||||
return isNull(objects) || (objects.length == 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* * 判断一个对象数组是否非空
|
||||
*
|
||||
* @param objects 要判断的对象数组
|
||||
* @return true:非空 false:空
|
||||
*/
|
||||
public static boolean isNotEmpty(Object[] objects)
|
||||
{
|
||||
return !isEmpty(objects);
|
||||
}
|
||||
|
||||
/**
|
||||
* * 判断一个Map是否为空
|
||||
*
|
||||
* @param map 要判断的Map
|
||||
* @return true:为空 false:非空
|
||||
*/
|
||||
public static boolean isEmpty(Map<?, ?> map)
|
||||
{
|
||||
return isNull(map) || map.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* * 判断一个Map是否为空
|
||||
*
|
||||
* @param map 要判断的Map
|
||||
* @return true:非空 false:空
|
||||
*/
|
||||
public static boolean isNotEmpty(Map<?, ?> map)
|
||||
{
|
||||
return !isEmpty(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* * 判断一个字符串是否为空串
|
||||
*
|
||||
* @param str String
|
||||
* @return true:为空 false:非空
|
||||
*/
|
||||
public static boolean isEmpty(String str)
|
||||
{
|
||||
return isNull(str) || NULLSTR.equals(str.trim());
|
||||
}
|
||||
|
||||
/**
|
||||
* * 判断一个字符串是否为非空串
|
||||
*
|
||||
* @param str String
|
||||
* @return true:非空串 false:空串
|
||||
*/
|
||||
public static boolean isNotEmpty(String str)
|
||||
{
|
||||
return !isEmpty(str);
|
||||
}
|
||||
|
||||
/**
|
||||
* * 判断一个对象是否为空
|
||||
*
|
||||
* @param object Object
|
||||
* @return true:为空 false:非空
|
||||
*/
|
||||
public static boolean isNull(Object object)
|
||||
{
|
||||
return object == null;
|
||||
}
|
||||
|
||||
/**
|
||||
* * 判断一个对象是否非空
|
||||
*
|
||||
* @param object Object
|
||||
* @return true:非空 false:空
|
||||
*/
|
||||
public static boolean isNotNull(Object object)
|
||||
{
|
||||
return !isNull(object);
|
||||
}
|
||||
|
||||
/**
|
||||
* * 判断一个对象是否是数组类型(Java基本型别的数组)
|
||||
*
|
||||
* @param object 对象
|
||||
* @return true:是数组 false:不是数组
|
||||
*/
|
||||
public static boolean isArray(Object object)
|
||||
{
|
||||
return isNotNull(object) && object.getClass().isArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* 去空格
|
||||
*/
|
||||
public static String trim(String str)
|
||||
{
|
||||
return (str == null ? "" : str.trim());
|
||||
}
|
||||
|
||||
/**
|
||||
* 截取字符串
|
||||
*
|
||||
* @param str 字符串
|
||||
* @param start 开始
|
||||
* @return 结果
|
||||
*/
|
||||
public static String substring(final String str, int start)
|
||||
{
|
||||
if (str == null)
|
||||
{
|
||||
return NULLSTR;
|
||||
}
|
||||
|
||||
if (start < 0)
|
||||
{
|
||||
start = str.length() + start;
|
||||
}
|
||||
|
||||
if (start < 0)
|
||||
{
|
||||
start = 0;
|
||||
}
|
||||
if (start > str.length())
|
||||
{
|
||||
return NULLSTR;
|
||||
}
|
||||
|
||||
return str.substring(start);
|
||||
}
|
||||
|
||||
/**
|
||||
* 截取字符串
|
||||
*
|
||||
* @param str 字符串
|
||||
* @param start 开始
|
||||
* @param end 结束
|
||||
* @return 结果
|
||||
*/
|
||||
public static String substring(final String str, int start, int end)
|
||||
{
|
||||
if (str == null)
|
||||
{
|
||||
return NULLSTR;
|
||||
}
|
||||
|
||||
if (end < 0)
|
||||
{
|
||||
end = str.length() + end;
|
||||
}
|
||||
if (start < 0)
|
||||
{
|
||||
start = str.length() + start;
|
||||
}
|
||||
|
||||
if (end > str.length())
|
||||
{
|
||||
end = str.length();
|
||||
}
|
||||
|
||||
if (start > end)
|
||||
{
|
||||
return NULLSTR;
|
||||
}
|
||||
|
||||
if (start < 0)
|
||||
{
|
||||
start = 0;
|
||||
}
|
||||
if (end < 0)
|
||||
{
|
||||
end = 0;
|
||||
}
|
||||
|
||||
return str.substring(start, end);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 字符串转set
|
||||
*
|
||||
* @param str 字符串
|
||||
* @param sep 分隔符
|
||||
* @return set集合
|
||||
*/
|
||||
public static final Set<String> str2Set(String str, String sep)
|
||||
{
|
||||
return new HashSet<String>(str2List(str, sep, true, false));
|
||||
}
|
||||
|
||||
/**
|
||||
* 字符串转list
|
||||
*
|
||||
* @param str 字符串
|
||||
* @param sep 分隔符
|
||||
* @param filterBlank 过滤纯空白
|
||||
* @param trim 去掉首尾空白
|
||||
* @return list集合
|
||||
*/
|
||||
public static final List<String> str2List(String str, String sep, boolean filterBlank, boolean trim)
|
||||
{
|
||||
List<String> list = new ArrayList<String>();
|
||||
if (isEmpty(str))
|
||||
{
|
||||
return list;
|
||||
}
|
||||
|
||||
// 过滤空白字符串
|
||||
if (isBlank(str))
|
||||
{
|
||||
return list;
|
||||
}
|
||||
String[] split = str.split(sep);
|
||||
for (String string : split)
|
||||
{
|
||||
if (isBlank(string))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (trim)
|
||||
{
|
||||
string = string.trim();
|
||||
}
|
||||
list.add(string);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查找指定字符串是否包含指定字符串列表中的任意一个字符串同时串忽略大小写
|
||||
*
|
||||
* @param cs 指定字符串
|
||||
* @param searchCharSequences 需要检查的字符串数组
|
||||
* @return 是否包含任意一个字符串
|
||||
*/
|
||||
public static boolean containsAnyIgnoreCase(CharSequence cs, CharSequence... searchCharSequences)
|
||||
{
|
||||
if (isEmpty(cs) || isEmpty(searchCharSequences))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for (CharSequence testStr : searchCharSequences)
|
||||
{
|
||||
if (containsIgnoreCase(cs, testStr))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 驼峰转下划线命名
|
||||
*/
|
||||
public static String toUnderScoreCase(String str)
|
||||
{
|
||||
if (str == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
// 前置字符是否大写
|
||||
boolean preCharIsUpperCase = true;
|
||||
// 当前字符是否大写
|
||||
boolean curreCharIsUpperCase = true;
|
||||
// 下一字符是否大写
|
||||
boolean nexteCharIsUpperCase = true;
|
||||
for (int i = 0; i < str.length(); i++)
|
||||
{
|
||||
char c = str.charAt(i);
|
||||
if (i > 0)
|
||||
{
|
||||
preCharIsUpperCase = Character.isUpperCase(str.charAt(i - 1));
|
||||
}
|
||||
else
|
||||
{
|
||||
preCharIsUpperCase = false;
|
||||
}
|
||||
|
||||
curreCharIsUpperCase = Character.isUpperCase(c);
|
||||
|
||||
if (i < (str.length() - 1))
|
||||
{
|
||||
nexteCharIsUpperCase = Character.isUpperCase(str.charAt(i + 1));
|
||||
}
|
||||
|
||||
if (preCharIsUpperCase && curreCharIsUpperCase && !nexteCharIsUpperCase)
|
||||
{
|
||||
sb.append(SEPARATOR);
|
||||
}
|
||||
else if ((i != 0 && !preCharIsUpperCase) && curreCharIsUpperCase)
|
||||
{
|
||||
sb.append(SEPARATOR);
|
||||
}
|
||||
sb.append(Character.toLowerCase(c));
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否包含字符串
|
||||
*
|
||||
* @param str 验证字符串
|
||||
* @param strs 字符串组
|
||||
* @return 包含返回true
|
||||
*/
|
||||
public static boolean inStringIgnoreCase(String str, String... strs)
|
||||
{
|
||||
if (str != null && strs != null)
|
||||
{
|
||||
for (String s : strs)
|
||||
{
|
||||
if (str.equalsIgnoreCase(trim(s)))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将下划线大写方式命名的字符串转换为驼峰式。如果转换前的下划线大写方式命名的字符串为空,则返回空字符串。 例如:HELLO_WORLD->HelloWorld
|
||||
*
|
||||
* @param name 转换前的下划线大写方式命名的字符串
|
||||
* @return 转换后的驼峰式命名的字符串
|
||||
*/
|
||||
public static String convertToCamelCase(String name)
|
||||
{
|
||||
StringBuilder result = new StringBuilder();
|
||||
// 快速检查
|
||||
if (name == null || name.isEmpty())
|
||||
{
|
||||
// 没必要转换
|
||||
return "";
|
||||
}
|
||||
else if (!name.contains("_"))
|
||||
{
|
||||
// 不含下划线,仅将首字母大写
|
||||
return name.substring(0, 1).toUpperCase() + name.substring(1);
|
||||
}
|
||||
// 用下划线将原始字符串分割
|
||||
String[] camels = name.split("_");
|
||||
for (String camel : camels)
|
||||
{
|
||||
// 跳过原始字符串中开头、结尾的下换线或双重下划线
|
||||
if (camel.isEmpty())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
// 首字母大写
|
||||
result.append(camel.substring(0, 1).toUpperCase());
|
||||
result.append(camel.substring(1).toLowerCase());
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 驼峰式命名法 例如:user_name->userName
|
||||
*/
|
||||
public static String toCamelCase(String s)
|
||||
{
|
||||
if (s == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
s = s.toLowerCase();
|
||||
StringBuilder sb = new StringBuilder(s.length());
|
||||
boolean upperCase = false;
|
||||
for (int i = 0; i < s.length(); i++)
|
||||
{
|
||||
char c = s.charAt(i);
|
||||
|
||||
if (c == SEPARATOR)
|
||||
{
|
||||
upperCase = true;
|
||||
}
|
||||
else if (upperCase)
|
||||
{
|
||||
sb.append(Character.toUpperCase(c));
|
||||
upperCase = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.append(c);
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查找指定字符串是否匹配指定字符串列表中的任意一个字符串
|
||||
*
|
||||
* @param str 指定字符串
|
||||
* @param strs 需要检查的字符串数组
|
||||
* @return 是否匹配
|
||||
*/
|
||||
public static boolean matches(String str, List<String> strs)
|
||||
{
|
||||
if (isEmpty(str) || isEmpty(strs))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for (String pattern : strs)
|
||||
{
|
||||
if (isMatch(pattern, str))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断url是否与规则配置:
|
||||
* ? 表示单个字符;
|
||||
* * 表示一层路径内的任意字符串,不可跨层级;
|
||||
* ** 表示任意层路径;
|
||||
*
|
||||
* @param pattern 匹配规则
|
||||
* @param url 需要匹配的url
|
||||
* 生成订单编号
|
||||
* @return
|
||||
*/
|
||||
public static boolean isMatch(String pattern, String url)
|
||||
{
|
||||
AntPathMatcher matcher = new AntPathMatcher();
|
||||
return matcher.match(pattern, url);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T cast(Object obj)
|
||||
{
|
||||
return (T) obj;
|
||||
public String generateOrderNumber() {
|
||||
// 获取当前时间戳(毫秒级)
|
||||
long timestamp = System.currentTimeMillis();
|
||||
// 生成一个 4 位的随机数(可以根据需要修改长度)
|
||||
int randomPart = (int) (Math.random() * 10000);
|
||||
// 组合时间戳和随机数
|
||||
return timestamp + String.format("%04d", randomPart);
|
||||
}
|
||||
|
||||
/**
|
||||
* 数字左边补齐0,使之达到指定长度。注意,如果数字转换为字符串后,长度大于size,则只保留 最后size个字符。
|
||||
*
|
||||
* @param num 数字对象
|
||||
* @param size 字符串指定长度
|
||||
* @return 返回数字的字符串格式,该字符串为指定长度。
|
||||
* 升成 18位的随机数
|
||||
* @param numDigits
|
||||
* @return
|
||||
*/
|
||||
public static final String padl(final Number num, final int size)
|
||||
{
|
||||
return padl(num.toString(), size, '0');
|
||||
public static long generateRandomLong(int numDigits) {
|
||||
Random random = new Random();
|
||||
long number = 0;
|
||||
|
||||
// 确保生成的数字是 18 位
|
||||
for (int i = 0; i < numDigits; i++) {
|
||||
number = number * 10 + random.nextInt(10);
|
||||
}
|
||||
|
||||
// 确保生成的数字不会超过 long 的最大值
|
||||
if (number > Long.MAX_VALUE) {
|
||||
number = Long.MAX_VALUE;
|
||||
}
|
||||
|
||||
return number;
|
||||
}
|
||||
|
||||
/**
|
||||
* 字符串左补齐。如果原始字符串s长度大于size,则只保留最后size个字符。
|
||||
*
|
||||
* @param s 原始字符串
|
||||
* @param size 字符串指定长度
|
||||
* @param c 用于补齐的字符
|
||||
* @return 返回指定长度的字符串,由原字符串左补齐或截取得到。
|
||||
* 升成 18位的随机数
|
||||
* @param numDigits
|
||||
* @return
|
||||
*/
|
||||
public static final String padl(final String s, final int size, final char c)
|
||||
{
|
||||
final StringBuilder sb = new StringBuilder(size);
|
||||
if (s != null)
|
||||
{
|
||||
final int len = s.length();
|
||||
if (s.length() <= size)
|
||||
{
|
||||
for (int i = size - len; i > 0; i--)
|
||||
{
|
||||
sb.append(c);
|
||||
}
|
||||
sb.append(s);
|
||||
}
|
||||
else
|
||||
{
|
||||
return s.substring(len - size, len);
|
||||
}
|
||||
public static String generateRandomString(int numDigits) {
|
||||
Random random = new Random();
|
||||
long number = 0;
|
||||
|
||||
// 确保生成的数字是 18 位
|
||||
for (int i = 0; i < numDigits; i++) {
|
||||
number = number * 10 + random.nextInt(10);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = size; i > 0; i--)
|
||||
{
|
||||
sb.append(c);
|
||||
}
|
||||
|
||||
// 确保生成的数字不会超过 long 的最大值
|
||||
if (number > Long.MAX_VALUE) {
|
||||
number = Long.MAX_VALUE;
|
||||
}
|
||||
return sb.toString();
|
||||
|
||||
return String.valueOf(number);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,18 +7,10 @@ import com.alipay.api.DefaultAlipayClient;
|
|||
import com.alipay.api.domain.AlipayTradeWapPayModel;
|
||||
import com.alipay.api.request.AlipayTradeWapPayRequest;
|
||||
import com.alipay.api.response.AlipayTradeWapPayResponse;
|
||||
import com.bonus.canteen.common.utils.StringUtil;
|
||||
import com.bonus.canteen.pay.domain.PayDeviceDTO;
|
||||
import com.bonus.canteen.pay.domain.PayResDTO;
|
||||
import com.bonus.canteen.pay.domain.RechargeResDTO;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import java.util.HashMap;
|
||||
|
||||
@RestController
|
||||
@RequestMapping({"/leopen"})
|
||||
|
|
|
|||
Reference in New Issue