/**
* 带逗号的字符串转换成SQL里的inStr("a,b,c"->'a','b','c')
*
* @param stringWithComma 用逗号分隔的字符串 "a,b,c"
* @return inStr可以用在SQL的in语句内 'a','b','c'
*/
public String getInStr(String stringWithComma) {
String splitSymbolComma = ",";
ArrayList<String> strList = CollectionUtil.toList(stringWithComma.split(splitSymbolComma));
return strList.stream().collect(Collectors.joining("\',\'", "\'", "\'"));
}
/**
* 处理字符串后边的0(4100->41)
*
* @param str 字符串
* @return 不带0的字符串
*/
public String dealZero(String str) {
String zeroStr = "0";
if (str.endsWith(zeroStr)) {
str = str.substring(0, str.length() - 1);
return dealZero(str);
} else {
return str;
}
}
/**
* 获取三者最小值
*
* @param one 值1
* @param two 值2
* @param three 值3
* @return 最小值
*/
public int min(int one, int two, int three) {
return (one = Math.min(one, two)) < three ? one : three;
}
/**
* 计算表达式的值(1+1->2)
*
* @param scoreStr 表达式
* @return 分数
*/
private double calculateScoreByStr(String scoreStr) {
double score = 0.0;
if (StringUtils.isNotBlank(scoreStr)) {
ScriptEngineManager sem = new ScriptEngineManager();
ScriptEngine se = sem.getEngineByName("js");
try {
score = (double) se.eval(scoreStr + "*1.0");
} catch (ScriptException e) {
log.error("计算[{}]时出现异常", scoreStr);
}
}
return score;
}
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。