Browse Source

工具类修改

tudc 5 years ago
parent
commit
ff8f9d376a

+ 19 - 0
src/main/java/com/minpay/common/util/CommonUtil.java

@@ -213,6 +213,21 @@ public class CommonUtil {
 		BigDecimal iRet = big1.divide(big2, 4, BigDecimal.ROUND_HALF_DOWN);
 		return iRet.setScale(2, BigDecimal.ROUND_HALF_DOWN).toString();
 	}
+	
+	public static String divide(String str1, String str2, int pointWs) {
+		
+		if (str1 == null || "".equals(str1) || "null".equals(str1)) {
+			str1 = "0";
+		}
+		if (str2 == null || "".equals(str2) || "null".equals(str2)) {
+			str2 = "0";
+		}
+		BigDecimal big1 = new BigDecimal(str1);
+		BigDecimal big2 = new BigDecimal(str2);
+		BigDecimal iRet = big1.divide(big2, pointWs, BigDecimal.ROUND_HALF_UP);
+		
+		return objToString(iRet);
+	}
 
 	/**
 	 * 相乘
@@ -233,6 +248,10 @@ public class CommonUtil {
 		BigDecimal iRet = big1.multiply(big2);
 		return iRet.toString();
 	}
+	
+	public static String multiply(String str1, String str2, int pointWs) {
+		return objToString(objToBigDecimal(multiply(str1, str2)).setScale(pointWs, BigDecimal.ROUND_HALF_UP));
+	}
 
 	/**
 	 * 生成15位随机码

+ 20 - 3
src/main/java/com/minpay/common/util/DateUtil.java

@@ -726,13 +726,30 @@ public class DateUtil {
 		 * @return
 		 * @throws ParseException 
 		 */
-		public static String dateAddDay(String time,String day) throws ParseException{
-			SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
+		public static String dateAddDay(String time,int day) throws ParseException{
+			SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
 			Date d = format.parse(time);
 			format.format(d);
 			Calendar cal=Calendar.getInstance();
 			cal.setTime(d);
-			cal.add(Calendar.DATE, 30);
+			cal.add(Calendar.DATE, day);
+			return format.format(cal.getTime());
+		}
+		
+		/**
+		 * 增加月份
+		 * @param time
+		 * @param day
+		 * @return
+		 * @throws ParseException
+		 */
+		public static String dateAddMonth(String time,int month) throws ParseException{
+			SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
+			Date d = format.parse(time);
+			format.format(d);
+			Calendar cal=Calendar.getInstance();
+			cal.setTime(d);
+			cal.add(Calendar.MONTH, month);
 			return format.format(cal.getTime());
 		}
 		

+ 17 - 1
src/main/java/com/minpay/common/util/FilesUtil.java

@@ -328,6 +328,8 @@ public class FilesUtil {
 		for(int i=firstrow; i<rownum; i++){
 			Row row = sheet.getRow(i);
 			Map<String,String> map = new HashMap<String,String>();
+			// 是否存在全为空的一行数据
+			boolean allIsNull = true;
 			for(int j=0; j<titleKey.length; j++){
 				System.out.println(i+":"+j);
 				Cell cell = row.getCell(j);
@@ -364,9 +366,15 @@ public class FilesUtil {
 		                    cellValue = "未知类型";  
 		                    break;  
 	                }
+					if (!CommonUtil.isEmpty(cellValue)) {
+						allIsNull = false;
+					}
 				}
 				map.put(titleKey[j], cellValue);
 			}
+			if (allIsNull) {
+				break;
+			}
 			list.add(map);
 		}
 		 return list;  
@@ -394,11 +402,13 @@ public class FilesUtil {
 			throw new BusinessCodeException("PBIM2800");//提示数据格式不正确
 		}
 		DecimalFormat df = new DecimalFormat("#");  
-		
+		// 是否存在全为空的一行数据
+		boolean allIsNull = true;
 		for(int i=firstrow; i<rownum; i++){
 			Row row = sheet.getRow(i);
 			short rowNum = row.getLastCellNum();
 			List<String> childList = new ArrayList<String>();
+			
 			for (short j = 0; j < rowNum; j ++) {
 				Cell cell = row.getCell(j);
 				String cellValue = "";
@@ -434,9 +444,15 @@ public class FilesUtil {
 						cellValue = "未知类型";  
 						break;  
 					}
+					if (!CommonUtil.isEmpty(cellValue)) {
+						allIsNull = false;
+					}
 				}
 				childList.add(cellValue);
 			}
+			if (allIsNull) {
+				break;
+			}
 			list.add(childList);
 		}
 		return list;