Browse Source

#水电站bug解决

zhongwei
yang_shj 1 year ago
parent
commit
4f8d2f2fc4
  1. 51
      hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/impl/GenerateServiceImpl.java

51
hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/impl/GenerateServiceImpl.java

@ -15,6 +15,7 @@ import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
@ -94,19 +95,45 @@ public class GenerateServiceImpl extends BaseServiceImpl<GenerateMapper, Generat
if(CollectionUtil.isEmpty(records)){
return new ArrayList<>();
}
List<String> mons = this.mons(2,12,false);
List<GenerateEntity> format = records.stream().peek(record-> record.setFillDate(DateUtil.format(DateUtil.parse(record.getFillDate(),"yyyy-MM"),"yyyy-MM") + "-01")).collect(Collectors.toList());
// 返回结果
return records.stream().peek(
record-> record.setFillDate(DateUtil.format(DateUtil.parse(record.getFillDate(),"yyyy-MM"),"yyyy-MM") + "-01")
).collect(Collectors.toMap(GenerateEntity::getFillDate,GenerateEntity::getGenerate,Double::sum)).
entrySet().stream().map(entry->{
PowerMonthVo mon = new PowerMonthVo();
mon.setStrMonth(entry.getKey());
if(Math.abs(entry.getValue()) <= 0){
mon.setPower(0f);
}else{
mon.setPower(Float.parseFloat(entry.getValue().toString()));
}
return mon;
return mons.stream().map(mon->{
PowerMonthVo powerMonth = new PowerMonthVo();
powerMonth.setStrMonth(mon);
powerMonth.setPower((float) format.stream().filter(o->o.getFillDate().equals(mon)).mapToDouble(GenerateEntity::getGenerate).sum());
return powerMonth;
}).collect(Collectors.toList());
}
/**
* 获取近年月份集合
* @param year
* @return
*/
public List<String> mons(int year, int endMoth, boolean nextMon) {
List<String> list = new ArrayList<>();
// 开始日期
Calendar endCal = Calendar.getInstance();
endCal.setTime(new Date());
endCal.add(Calendar.MONTH, -endCal.get(Calendar.MONTH) + endMoth);
endCal.add(Calendar.DATE, -endCal.get(Calendar.DATE) + 1);
// 结束日期
Calendar startCal = Calendar.getInstance();
startCal.setTime(new Date());
startCal.set(Calendar.YEAR, startCal.get(Calendar.YEAR) - year);
startCal.add(Calendar.MONTH, -startCal.get(Calendar.MONTH));
startCal.add(Calendar.DATE, -startCal.get(Calendar.DATE) + 1);
// 获取日期之间的月份
while (endCal.after(startCal)) {
list.add(DateUtil.format(startCal.getTime(),DateUtil.PATTERN_DATE));
startCal.add(Calendar.MONTH, 1);
}
if(nextMon){
list.add(DateUtil.format(endCal.getTime(),DateUtil.PATTERN_DATE));
}
return list;
}
}

Loading…
Cancel
Save