a3c628d8 康伟

kangwei :格式化输出

1 个父辈 79358c7d
package com.skua.modules.quartz.util;
import com.skua.core.util.ConvertUtils;
import org.apache.commons.lang3.StringUtils;
import java.math.BigDecimal;
......@@ -16,6 +17,18 @@ import java.util.regex.Pattern;
public class BaseUtil {
private static DecimalFormat df = new DecimalFormat("#.00");
/**
* 格式化
* @param obj
* @param defval
* @return
*/
public static String getValue(Object obj ,Double defval ){
return df.format( ConvertUtils.getDouble(obj,defval) );
}
/***
* 计算时间的前几个月的月份
* @param month
......
......@@ -67,7 +67,7 @@ public class JTDisplayScreenServiceImpl implements IJTDisplayScreenService {
dataList = masterDB.queryForList(dataViewName2119);
for(Map<String, Object> dataMap : dataList) {
factoryInfoVO = factoryInfoMap.get(dataMap.get("depart_id").toString());
if(factoryInfoVO != null ) factoryInfoVO.setCsl_lastDay(dataMap.get("CSL").toString() ) ;
if(factoryInfoVO != null ) factoryInfoVO.setCsl_lastDay( BaseUtil.getValue( dataMap.get("CSL"),0d) ) ;
// resultMap.put(ConvertUtils.getString(dataMap.get("id")), ConvertUtils.getString(dataMap.get("create_by"))+""+ConvertUtils.getString(dataMap.get("title")));
}
//本月处理水量(m³)
......@@ -75,7 +75,7 @@ public class JTDisplayScreenServiceImpl implements IJTDisplayScreenService {
dataList = masterDB.queryForList(dataViewName2119);
for(Map<String, Object> dataMap : dataList) {
factoryInfoVO = factoryInfoMap.get(dataMap.get("depart_id").toString());
if(factoryInfoVO != null ) factoryInfoVO.setCsl_month(dataMap.get("CSL").toString() ) ;
if(factoryInfoVO != null ) factoryInfoVO.setCsl_month( BaseUtil.getValue( dataMap.get("CSL"),0d) ) ;
// resultMap.put(ConvertUtils.getString(dataMap.get("id")), ConvertUtils.getString(dataMap.get("create_by"))+""+ConvertUtils.getString(dataMap.get("title")));
}
//本年处理水量(万m³)
......@@ -84,8 +84,8 @@ public class JTDisplayScreenServiceImpl implements IJTDisplayScreenService {
for(Map<String, Object> dataMap : dataList) {
factoryInfoVO = factoryInfoMap.get(dataMap.get("depart_id").toString());
if(factoryInfoVO != null ){
factoryInfoVO.setCsl_year(dataMap.get("CSL").toString() ) ;
factoryInfoVO.setCsl_avg_day(DigitalUtils.division( dataMap.get("CSL").toString() ,differenceTime+"" ) );
factoryInfoVO.setCsl_year( BaseUtil.getValue( ConvertUtils.getDouble(dataMap.get("CSL"),0d) / 10000,0d) ) ;
factoryInfoVO.setCsl_avg_day( BaseUtil.getValue( ConvertUtils.getDouble(dataMap.get("CSL"),0d) / differenceTime,0d) );
}
// resultMap.put(ConvertUtils.getString(dataMap.get("id")), ConvertUtils.getString(dataMap.get("create_by"))+""+ConvertUtils.getString(dataMap.get("title")));
}
......
package com.skua.modules.report.vo;
import com.skua.tool.util.DateUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.Calendar;
/**
* 季度时间
* @auther kangwei
......@@ -24,7 +28,7 @@ public class SeasonTimeVO {
@ApiModelProperty(value = "季度结束时间")
private String endTime;
@ApiModelProperty(value = "季度天数")
private String disparityDay;
private Long disparityDay;
public SeasonTimeVO(){
......@@ -38,37 +42,32 @@ public class SeasonTimeVO {
public void getTimeBySeason(int year,int season){
int startMonth = 0;
int endMonth = 0;
int startDay = 1;
int endDay = 31;
switch (season) {
case 1:
startMonth = 1;
endMonth = 3;
break;
case 2:
startMonth = 4;
endMonth = 6;
break;
case 3:
startMonth = 7;
endMonth = 9;
break;
case 4:
startMonth = 10;
endMonth = 12;
break;
default:
System.out.println("季度输入无效,请输入1-4之间的数字。");
case 1: startMonth = 1;endMonth = 3; endDay=31; break;
case 2: startMonth = 4;endMonth = 6; endDay=30; break;
case 3:startMonth = 7;endMonth = 9;endDay=30; break;
case 4: startMonth = 10; endMonth = 12; endDay=31; break;
default:System.out.println("季度输入无效,请输入1-4之间的数字。");return ;
}
Calendar startDate = Calendar.getInstance();
/* startDate.set(Calendar.YEAR,year);
startDate.set(Calendar.MONTH, startMonth-1);
startDate.set(Calendar.DATE, startDay);*/
startDate.set(year,startMonth-1,startDay);
LocalDate startDate = LocalDate.of(year, startMonth, 1);
LocalDate endDate = LocalDate.of(year, endMonth, startDate.lengthOfMonth());
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
Calendar endDate = Calendar.getInstance();
/* endDate.set(Calendar.YEAR,year);
endDate.set(Calendar.MONTH, endMonth-1);
endDate.set(Calendar.DATE, endDay);*/
endDate.set(year,endMonth-1,endDay);
this.startTime = startDate.format(formatter);;
this.endTime = endDate.format(formatter); ;
long daysBetween = daysBetween(startDate, endDate);
this.disparityDay = daysBetween+"";
}
public static long daysBetween(LocalDate startDate, LocalDate endDate) {
return ChronoUnit.DAYS.between(startDate, endDate);
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
this.startTime = formatter.format(startDate.getTime());
this.endTime = formatter.format(endDate.getTime());
//long daysBetween = daysBetween(this.startTime, this.endTime );
this.disparityDay = DateUtils.differenceDay( this.startTime, this.endTime );
}
}
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!