mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 15:55:18 +08:00
完善
This commit is contained in:
@@ -36,6 +36,6 @@ public class MeterLogEntity extends OrgCommonEntity {
|
||||
|
||||
@Formula("( lag(value, 1, (select tm.init_value from t_meter tm where tm.id = meter_id)) over (partition by meter_id order by time asc ) )")
|
||||
private java.lang.Double previousValue;
|
||||
@Formula(" ( value - ( lag(value, 1, (select tm.init_value from t_meter tm where tm.id = meter_id)) over (partition by meter_id order by time asc ) ) )")
|
||||
@Formula(" (round(( value - ( lag(value, 1, (select tm.init_value from t_meter tm where tm.id = meter_id)) over (partition by meter_id order by time asc ) ) )::numeric, 2))")
|
||||
private java.lang.Double usage;
|
||||
}
|
||||
|
||||
@@ -118,6 +118,8 @@ public class MeterLogService extends BaseService<MeterLogEntity, MeterLogReposit
|
||||
this.repository.deleteAllById(request.getIds());
|
||||
}
|
||||
|
||||
@PersistenceContext EntityManager em;
|
||||
|
||||
@SneakyThrows
|
||||
public void excelImport(IdRequest fileId) {
|
||||
|
||||
@@ -173,7 +175,9 @@ public class MeterLogService extends BaseService<MeterLogEntity, MeterLogReposit
|
||||
*/
|
||||
case "数据行id" -> {}
|
||||
case "终端ID" -> {
|
||||
object.setMeter(meterGetter.apply(value.toString()));
|
||||
object.setMeter(
|
||||
meterGetter.apply(
|
||||
((Double) value).intValue() + ""));
|
||||
}
|
||||
case "IMEI" -> {}
|
||||
case "终端无线信号质量" -> {}
|
||||
@@ -198,7 +202,56 @@ public class MeterLogService extends BaseService<MeterLogEntity, MeterLogReposit
|
||||
}
|
||||
});
|
||||
|
||||
this.saveAll(logEntities.stream().filter(x -> x.getValue() != null).toList());
|
||||
saveWithoutDup(logEntities.stream().filter(x -> x.getValue() != null).toList());
|
||||
}
|
||||
|
||||
public void saveWithoutDup(List<MeterLogEntity> entities) {
|
||||
|
||||
List<MeterLogEntity> exists =
|
||||
em.createQuery(
|
||||
"""
|
||||
|
||||
select e from MeterLogEntity e where e.meter.id in :meterIds and e.time in :times
|
||||
""",
|
||||
MeterLogEntity.class)
|
||||
.setParameter(
|
||||
"meterIds",
|
||||
entities.stream().map(x -> x.getMeter().getId()).toList())
|
||||
.setParameter(
|
||||
"times", entities.stream().map(MeterLogEntity::getTime).toList())
|
||||
.getResultList();
|
||||
|
||||
if (exists.isEmpty()) {
|
||||
|
||||
this.repository.saveAll(entities);
|
||||
|
||||
} else {
|
||||
|
||||
for (MeterLogEntity entity : entities) {
|
||||
|
||||
boolean e = false;
|
||||
|
||||
for (MeterLogEntity exist : exists) {
|
||||
|
||||
if (entity.getMeter().getId().equals(exist.getMeter().getId())
|
||||
&& entity.getTime().equals(exist.getTime())
|
||||
&& entity.getValue().equals(exist.getValue())) {
|
||||
|
||||
log.info(
|
||||
"忽略重复抄表数据: {} {} {}",
|
||||
exist.getMeter().getName(),
|
||||
exist.getTime(),
|
||||
exist.getValue());
|
||||
|
||||
e = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!e) {
|
||||
this.repository.save(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Autowired MeterMonthLogService meterMonthLogService;
|
||||
|
||||
Reference in New Issue
Block a user