Просмотр исходного кода

部分报表的同比月份按设置日期划分

chenwen 3 лет назад
Родитель
Сommit
35fedaa4ca

+ 5 - 15
src/main/java/com/hb/proj/car/controller/EnergyWaterCompareController.java

@@ -24,6 +24,7 @@ import com.hb.proj.model.OtherConsume;
 import com.hb.proj.model.Wpg;
 import com.hb.proj.model.WpgCorrect;
 import com.hb.proj.utils.JsonOutUtils;
+import com.hb.proj.utils.RptMonthUtil;
 import com.hb.proj.utils.RptOuter;
 import com.hb.xframework.util.SessionThreadLocal;
 /**
@@ -85,14 +86,9 @@ public class EnergyWaterCompareController {
 			if(StringUtils.isEmpty(year)){
 				year=String.valueOf(ca.get(Calendar.YEAR));
 			}
-			if(Integer.parseInt(year)==ca.get(Calendar.YEAR)){ //等于当前年份,月份就应该为当前月份,否则为12月份
-				//当年且当月>25号,否则用上一个月
-				if(ca.get(Calendar.DAY_OF_MONTH)>25){
-					month=String.format("%02d", ca.get(Calendar.MONTH)+1);
-				}
-				else{
-					month=String.format("%02d", ca.get(Calendar.MONTH));
-				}
+			if(Integer.parseInt(year)==ca.get(Calendar.YEAR)){ //等于当前年份,根据当前日期决定用本月还是上月,否则为12月份
+				
+				month=String.format("%02d",RptMonthUtil.getFullMonthNum(ca));
 			}
 			
 			String preyear=String.valueOf(Integer.parseInt(year)-1);
@@ -146,13 +142,7 @@ public class EnergyWaterCompareController {
 				year=String.valueOf(ca.get(Calendar.YEAR));
 			}
 			if(Integer.parseInt(year)==ca.get(Calendar.YEAR)){ //等于当前年份,月份就应该为当前月份,否则为12月份
-				//当年且当月>25号,否则用上一个月
-				if(ca.get(Calendar.DAY_OF_MONTH)>25){
-					month=String.format("%02d", ca.get(Calendar.MONTH)+1);
-				}
-				else{
-					month=String.format("%02d", ca.get(Calendar.MONTH));
-				}
+				month=String.format("%02d",RptMonthUtil.getFullMonthNum(ca));
 			}
 			
 			String preyear=String.valueOf(Integer.parseInt(year)-1);

+ 2 - 15
src/main/java/com/hb/proj/car/controller/HomeRptController.java

@@ -142,13 +142,7 @@ public class HomeRptController {
 				year=String.valueOf(ca.get(Calendar.YEAR));
 			}
 			if(Integer.parseInt(year)==ca.get(Calendar.YEAR)){ //等于当前年份,月份就应该为当前月份,否则为12月份
-				//当年且当月>25号,否则用上一个月
-				if(ca.get(Calendar.DAY_OF_MONTH)>25){
-					month=String.format("%02d", ca.get(Calendar.MONTH)+1);
-				}
-				else{
-					month=String.format("%02d", ca.get(Calendar.MONTH));
-				}
+				month=String.format("%02d",RptMonthUtil.getFullMonthNum(ca));
 				
 			}
 			String preyear=String.valueOf(Integer.parseInt(year)-1);
@@ -191,14 +185,7 @@ public class HomeRptController {
 				year=String.valueOf(ca.get(Calendar.YEAR));
 			}
 			if(Integer.parseInt(year)==ca.get(Calendar.YEAR)){ //等于当前年份,月份就应该为当前月份,否则为12月份
-				//当年且当月>25号,否则用上一个月
-				if(ca.get(Calendar.DAY_OF_MONTH)>25){
-					month=String.format("%02d", ca.get(Calendar.MONTH)+1);
-				}
-				else{
-					month=String.format("%02d", ca.get(Calendar.MONTH));
-				}
-				
+				month=String.format("%02d",RptMonthUtil.getFullMonthNum(ca));
 			}
 			String preyear=String.valueOf(Integer.parseInt(year)-1);
 			String startMonth=year+"-01",endMonth=year+"-"+month;

+ 4 - 6
src/main/java/com/hb/proj/car/controller/WpgSumRptController.java

@@ -19,6 +19,7 @@ import com.hb.proj.car.service.CarSumRptService;
 import com.hb.proj.model.Wpg;
 import com.hb.proj.utils.JsonOutUtils;
 import com.hb.proj.utils.MapUtils;
+import com.hb.proj.utils.RptMonthUtil;
 import com.hb.proj.utils.RptOuter;
 import com.hb.xframework.util.DateUtil;
 
@@ -40,12 +41,9 @@ public class WpgSumRptController {
 		try{
 			if(StringUtils.isEmpty(rptMonth)){
 				Calendar ca=Calendar.getInstance();
-				if(ca.get(Calendar.DAY_OF_MONTH)>25){  //超过25号才用本月否则用上一月
-					rptMonth=String.valueOf(ca.get(Calendar.YEAR))+"-"+String.format("%02d", ca.get(Calendar.MONTH)+1);
-				}
-				else{
-					rptMonth=String.valueOf(ca.get(Calendar.YEAR))+"-"+String.format("%02d", ca.get(Calendar.MONTH));
-				}
+				
+				rptMonth=String.valueOf(ca.get(Calendar.YEAR))+"-"+String.format("%02d", RptMonthUtil.getFullMonthNum(ca));
+				
 			}
 			String[] ymtr=rptMonth.split("-");
 			String startMonth=ymtr[0]+"-01";

+ 16 - 0
src/main/java/com/hb/proj/utils/RptMonthUtil.java

@@ -19,6 +19,8 @@ public class RptMonthUtil {
 		monthSplitDay=day;
 	}*/
 	
+	
+	
 	public static int getMonthSplitDay(){
 		Integer day=QuotaStandardSupport.getConfig().getMonthSplitDay();
 		return day!=null?day.intValue():16;
@@ -31,6 +33,20 @@ public class RptMonthUtil {
 		monthSplitDay=day;
 	}*/
 	
+	/**
+	 * 获得上一个足月的月份值
+	 * @param ca
+	 * @return
+	 */
+	public static int getFullMonthNum(Calendar ca){
+		if(ca.get(Calendar.DAY_OF_MONTH)>=getMonthSplitDay()){ 
+			return ca.get(Calendar.MONTH)+1;  //日历中是本月,统计中算下个月,但下个月还不足月
+		}
+		else{
+			return ca.get(Calendar.MONTH);
+		}
+	}
+	
 	public static int getMonthNum(Calendar ca){
 		if(ca.get(Calendar.DAY_OF_MONTH)>=getMonthSplitDay()){ 
 			ca.add(Calendar.MONTH, 1);