Browse Source

#水电站bug解决

zhongwei
yang_shj 1 year ago
parent
commit
64a9db5db3
  1. 53
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/impl/GenerateServiceImpl.java
  2. 7
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/HomeServiceImpl.java

53
hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/impl/GenerateServiceImpl.java

@ -5,7 +5,6 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.hnac.hzims.operational.fill.entity.GenerateEntity;
import com.hnac.hzims.operational.fill.entity.UseEntity;
import com.hnac.hzims.operational.fill.mapper.GenerateMapper;
import com.hnac.hzims.operational.fill.service.GenerateService;
import com.hnac.hzims.operational.fill.vo.GenerateVo;
@ -13,7 +12,6 @@ import com.hnac.hzims.operational.fill.vo.QueryVo;
import com.hnac.hzims.operational.fill.wrapper.GenerateWrapper;
import com.hnac.hzims.operational.main.vo.GenerationPowerVo;
import com.hnac.hzims.operational.main.vo.PowerMonthVo;
import com.hnac.hzims.operational.main.vo.UsrPowerVo;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.log.exception.ServiceException;
@ -29,6 +27,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;
@ -154,19 +153,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;
}
}

7
hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/HomeServiceImpl.java

@ -153,7 +153,12 @@ public class HomeServiceImpl implements HomeService {
if(HomePageConstant.CHARGE.equals(type) && "2".equals(serve)){
TargetVo target = (TargetVo) redisTemplate.opsForValue().get(charge);
if(ObjectUtil.isNotEmpty(target)){
count.setCount(Long.valueOf(Optional.ofNullable(target.getCharge()).orElse(0)));
TargetVo charge = this.chargeTarget();
if(ObjectUtil.isNotEmpty(charge)){
count.setCount(Long.valueOf(charge.getCharge()));
}else{
count.setCount(92L);
}
}
}else if(HomePageConstant.WATER_CONSERVANCY.equals(type) && "2".equals(serve)){
count.setCount(stations.stream().filter(station->serve.equals(station.getServeType()) && HomePageConstant.waterList.contains(station.getType())).count());

Loading…
Cancel
Save