解决多账户金额计算的bug
This commit is contained in:
@@ -526,10 +526,10 @@ public class AccountService {
|
|||||||
public String getAccountStrByIdAndMoney(Map<Long,String> accountMap, String accountIdList, String accountMoneyList){
|
public String getAccountStrByIdAndMoney(Map<Long,String> accountMap, String accountIdList, String accountMoneyList){
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuffer sb = new StringBuffer();
|
||||||
List<Long> idList = StringUtil.strToLongList(accountIdList);
|
List<Long> idList = StringUtil.strToLongList(accountIdList);
|
||||||
List<Long> moneyList = StringUtil.strToLongList(accountMoneyList);
|
List<BigDecimal> moneyList = StringUtil.strToBigDecimalList(accountMoneyList);
|
||||||
for (int i = 0; i < idList.size(); i++) {
|
for (int i = 0; i < idList.size(); i++) {
|
||||||
Long id = idList.get(i);
|
Long id = idList.get(i);
|
||||||
BigDecimal money = BigDecimal.valueOf(moneyList.get(i)).abs();
|
BigDecimal money = moneyList.get(i).abs();
|
||||||
sb.append(accountMap.get(id) + "(" + money + "元) ");
|
sb.append(accountMap.get(id) + "(" + money + "元) ");
|
||||||
}
|
}
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import org.springframework.util.StringUtils;
|
|||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@@ -177,10 +178,10 @@ public class StringUtil {
|
|||||||
return new ArrayList<String>();
|
return new ArrayList<String>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getArrSum(String[] strings) {
|
public static BigDecimal getArrSum(String[] strings) {
|
||||||
int sum = 0;
|
BigDecimal sum = BigDecimal.ZERO;
|
||||||
for(int i=0;i<strings.length;i++){
|
for(int i=0;i<strings.length;i++){
|
||||||
sum=sum+ Integer.parseInt(strings[i]);
|
sum = sum.add(new BigDecimal(strings[i]));
|
||||||
}
|
}
|
||||||
return sum;
|
return sum;
|
||||||
}
|
}
|
||||||
@@ -203,6 +204,24 @@ public class StringUtil {
|
|||||||
return idList;
|
return idList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* String字符串转成List<BigDecimal>数据格式
|
||||||
|
* String str = "1,2,3,4,5,6" -> List<BigDecimal> listBigDecimal [1,2,3,4,5,6];
|
||||||
|
*
|
||||||
|
* @param strArr
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static List<BigDecimal> strToBigDecimalList(String strArr) {
|
||||||
|
List<BigDecimal> idList=new ArrayList<>();
|
||||||
|
String[] d=strArr.split(",");
|
||||||
|
for (int i = 0, size = d.length; i < size; i++) {
|
||||||
|
if(d[i]!=null) {
|
||||||
|
idList.add(new BigDecimal(d[i]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return idList;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* String字符串转成List<String>数据格式
|
* String字符串转成List<String>数据格式
|
||||||
* String str = "1,2,3,4,5,6" -> List<Long> listLong [1,2,3,4,5,6];
|
* String str = "1,2,3,4,5,6" -> List<Long> listLong [1,2,3,4,5,6];
|
||||||
|
|||||||
Reference in New Issue
Block a user