kangwei :格式化输出
正在显示
3 个修改的文件
包含
45 行增加
和
33 行删除
1 | package com.skua.modules.quartz.util; | 1 | package com.skua.modules.quartz.util; |
2 | 2 | ||
3 | import com.skua.core.util.ConvertUtils; | ||
3 | import org.apache.commons.lang3.StringUtils; | 4 | import org.apache.commons.lang3.StringUtils; |
4 | 5 | ||
5 | import java.math.BigDecimal; | 6 | import java.math.BigDecimal; |
... | @@ -16,6 +17,18 @@ import java.util.regex.Pattern; | ... | @@ -16,6 +17,18 @@ import java.util.regex.Pattern; |
16 | public class BaseUtil { | 17 | public class BaseUtil { |
17 | 18 | ||
18 | 19 | ||
20 | private static DecimalFormat df = new DecimalFormat("#.00"); | ||
21 | |||
22 | /** | ||
23 | * 格式化 | ||
24 | * @param obj | ||
25 | * @param defval | ||
26 | * @return | ||
27 | */ | ||
28 | public static String getValue(Object obj ,Double defval ){ | ||
29 | return df.format( ConvertUtils.getDouble(obj,defval) ); | ||
30 | } | ||
31 | |||
19 | /*** | 32 | /*** |
20 | * 计算时间的前几个月的月份 | 33 | * 计算时间的前几个月的月份 |
21 | * @param month | 34 | * @param month | ... | ... |
... | @@ -67,7 +67,7 @@ public class JTDisplayScreenServiceImpl implements IJTDisplayScreenService { | ... | @@ -67,7 +67,7 @@ public class JTDisplayScreenServiceImpl implements IJTDisplayScreenService { |
67 | dataList = masterDB.queryForList(dataViewName2119); | 67 | dataList = masterDB.queryForList(dataViewName2119); |
68 | for(Map<String, Object> dataMap : dataList) { | 68 | for(Map<String, Object> dataMap : dataList) { |
69 | factoryInfoVO = factoryInfoMap.get(dataMap.get("depart_id").toString()); | 69 | factoryInfoVO = factoryInfoMap.get(dataMap.get("depart_id").toString()); |
70 | if(factoryInfoVO != null ) factoryInfoVO.setCsl_lastDay(dataMap.get("CSL").toString() ) ; | 70 | if(factoryInfoVO != null ) factoryInfoVO.setCsl_lastDay( BaseUtil.getValue( dataMap.get("CSL"),0d) ) ; |
71 | // resultMap.put(ConvertUtils.getString(dataMap.get("id")), ConvertUtils.getString(dataMap.get("create_by"))+""+ConvertUtils.getString(dataMap.get("title"))); | 71 | // resultMap.put(ConvertUtils.getString(dataMap.get("id")), ConvertUtils.getString(dataMap.get("create_by"))+""+ConvertUtils.getString(dataMap.get("title"))); |
72 | } | 72 | } |
73 | //本月处理水量(m³) | 73 | //本月处理水量(m³) |
... | @@ -75,7 +75,7 @@ public class JTDisplayScreenServiceImpl implements IJTDisplayScreenService { | ... | @@ -75,7 +75,7 @@ public class JTDisplayScreenServiceImpl implements IJTDisplayScreenService { |
75 | dataList = masterDB.queryForList(dataViewName2119); | 75 | dataList = masterDB.queryForList(dataViewName2119); |
76 | for(Map<String, Object> dataMap : dataList) { | 76 | for(Map<String, Object> dataMap : dataList) { |
77 | factoryInfoVO = factoryInfoMap.get(dataMap.get("depart_id").toString()); | 77 | factoryInfoVO = factoryInfoMap.get(dataMap.get("depart_id").toString()); |
78 | if(factoryInfoVO != null ) factoryInfoVO.setCsl_month(dataMap.get("CSL").toString() ) ; | 78 | if(factoryInfoVO != null ) factoryInfoVO.setCsl_month( BaseUtil.getValue( dataMap.get("CSL"),0d) ) ; |
79 | // resultMap.put(ConvertUtils.getString(dataMap.get("id")), ConvertUtils.getString(dataMap.get("create_by"))+""+ConvertUtils.getString(dataMap.get("title"))); | 79 | // resultMap.put(ConvertUtils.getString(dataMap.get("id")), ConvertUtils.getString(dataMap.get("create_by"))+""+ConvertUtils.getString(dataMap.get("title"))); |
80 | } | 80 | } |
81 | //本年处理水量(万m³) | 81 | //本年处理水量(万m³) |
... | @@ -84,8 +84,8 @@ public class JTDisplayScreenServiceImpl implements IJTDisplayScreenService { | ... | @@ -84,8 +84,8 @@ public class JTDisplayScreenServiceImpl implements IJTDisplayScreenService { |
84 | for(Map<String, Object> dataMap : dataList) { | 84 | for(Map<String, Object> dataMap : dataList) { |
85 | factoryInfoVO = factoryInfoMap.get(dataMap.get("depart_id").toString()); | 85 | factoryInfoVO = factoryInfoMap.get(dataMap.get("depart_id").toString()); |
86 | if(factoryInfoVO != null ){ | 86 | if(factoryInfoVO != null ){ |
87 | factoryInfoVO.setCsl_year(dataMap.get("CSL").toString() ) ; | 87 | factoryInfoVO.setCsl_year( BaseUtil.getValue( ConvertUtils.getDouble(dataMap.get("CSL"),0d) / 10000,0d) ) ; |
88 | factoryInfoVO.setCsl_avg_day(DigitalUtils.division( dataMap.get("CSL").toString() ,differenceTime+"" ) ); | 88 | factoryInfoVO.setCsl_avg_day( BaseUtil.getValue( ConvertUtils.getDouble(dataMap.get("CSL"),0d) / differenceTime,0d) ); |
89 | } | 89 | } |
90 | // resultMap.put(ConvertUtils.getString(dataMap.get("id")), ConvertUtils.getString(dataMap.get("create_by"))+""+ConvertUtils.getString(dataMap.get("title"))); | 90 | // resultMap.put(ConvertUtils.getString(dataMap.get("id")), ConvertUtils.getString(dataMap.get("create_by"))+""+ConvertUtils.getString(dataMap.get("title"))); |
91 | } | 91 | } | ... | ... |
1 | package com.skua.modules.report.vo; | 1 | package com.skua.modules.report.vo; |
2 | 2 | ||
3 | import com.skua.tool.util.DateUtils; | ||
3 | import io.swagger.annotations.ApiModel; | 4 | import io.swagger.annotations.ApiModel; |
4 | import io.swagger.annotations.ApiModelProperty; | 5 | import io.swagger.annotations.ApiModelProperty; |
5 | import lombok.Data; | 6 | import lombok.Data; |
6 | 7 | ||
8 | import java.text.SimpleDateFormat; | ||
7 | import java.time.LocalDate; | 9 | import java.time.LocalDate; |
8 | import java.time.format.DateTimeFormatter; | 10 | import java.time.format.DateTimeFormatter; |
9 | import java.time.temporal.ChronoUnit; | 11 | import java.time.temporal.ChronoUnit; |
12 | import java.util.Calendar; | ||
13 | |||
10 | /** | 14 | /** |
11 | * 季度时间 | 15 | * 季度时间 |
12 | * @auther kangwei | 16 | * @auther kangwei |
... | @@ -24,7 +28,7 @@ public class SeasonTimeVO { | ... | @@ -24,7 +28,7 @@ public class SeasonTimeVO { |
24 | @ApiModelProperty(value = "季度结束时间") | 28 | @ApiModelProperty(value = "季度结束时间") |
25 | private String endTime; | 29 | private String endTime; |
26 | @ApiModelProperty(value = "季度天数") | 30 | @ApiModelProperty(value = "季度天数") |
27 | private String disparityDay; | 31 | private Long disparityDay; |
28 | 32 | ||
29 | public SeasonTimeVO(){ | 33 | public SeasonTimeVO(){ |
30 | 34 | ||
... | @@ -38,37 +42,32 @@ public class SeasonTimeVO { | ... | @@ -38,37 +42,32 @@ public class SeasonTimeVO { |
38 | public void getTimeBySeason(int year,int season){ | 42 | public void getTimeBySeason(int year,int season){ |
39 | int startMonth = 0; | 43 | int startMonth = 0; |
40 | int endMonth = 0; | 44 | int endMonth = 0; |
45 | int startDay = 1; | ||
46 | int endDay = 31; | ||
41 | switch (season) { | 47 | switch (season) { |
42 | case 1: | 48 | case 1: startMonth = 1;endMonth = 3; endDay=31; break; |
43 | startMonth = 1; | 49 | case 2: startMonth = 4;endMonth = 6; endDay=30; break; |
44 | endMonth = 3; | 50 | case 3:startMonth = 7;endMonth = 9;endDay=30; break; |
45 | break; | 51 | case 4: startMonth = 10; endMonth = 12; endDay=31; break; |
46 | case 2: | 52 | default:System.out.println("季度输入无效,请输入1-4之间的数字。");return ; |
47 | startMonth = 4; | ||
48 | endMonth = 6; | ||
49 | break; | ||
50 | case 3: | ||
51 | startMonth = 7; | ||
52 | endMonth = 9; | ||
53 | break; | ||
54 | case 4: | ||
55 | startMonth = 10; | ||
56 | endMonth = 12; | ||
57 | break; | ||
58 | default: | ||
59 | System.out.println("季度输入无效,请输入1-4之间的数字。"); | ||
60 | } | 53 | } |
54 | Calendar startDate = Calendar.getInstance(); | ||
55 | /* startDate.set(Calendar.YEAR,year); | ||
56 | startDate.set(Calendar.MONTH, startMonth-1); | ||
57 | startDate.set(Calendar.DATE, startDay);*/ | ||
58 | startDate.set(year,startMonth-1,startDay); | ||
61 | 59 | ||
62 | LocalDate startDate = LocalDate.of(year, startMonth, 1); | 60 | Calendar endDate = Calendar.getInstance(); |
63 | LocalDate endDate = LocalDate.of(year, endMonth, startDate.lengthOfMonth()); | 61 | /* endDate.set(Calendar.YEAR,year); |
64 | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); | 62 | endDate.set(Calendar.MONTH, endMonth-1); |
63 | endDate.set(Calendar.DATE, endDay);*/ | ||
64 | endDate.set(year,endMonth-1,endDay); | ||
65 | 65 | ||
66 | this.startTime = startDate.format(formatter);; | 66 | SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); |
67 | this.endTime = endDate.format(formatter); ; | 67 | this.startTime = formatter.format(startDate.getTime()); |
68 | long daysBetween = daysBetween(startDate, endDate); | 68 | this.endTime = formatter.format(endDate.getTime()); |
69 | this.disparityDay = daysBetween+""; | 69 | //long daysBetween = daysBetween(this.startTime, this.endTime ); |
70 | } | 70 | this.disparityDay = DateUtils.differenceDay( this.startTime, this.endTime ); |
71 | public static long daysBetween(LocalDate startDate, LocalDate endDate) { | ||
72 | return ChronoUnit.DAYS.between(startDate, endDate); | ||
73 | } | 71 | } |
72 | |||
74 | } | 73 | } | ... | ... |
-
请 注册 或 登录 后发表评论