|
|
@ -151,9 +151,56 @@ public class RecordService implements IRecordService{ |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<RecordVo.WeightAndRfid> queryWeightAndRfid(RecordDto.WeightAndRfid param, Long userId) { |
|
|
|
List<RecordVo.WeightAndRfid> list = queryWeightAndRfid(param.getCarId(), param.getStartTime(), param.getEndTime()); |
|
|
|
List<RecordVo.WeightAndRfid> list = queryRecord(param.getCarId(), param.getStartTime(), param.getEndTime(), param.getTypes()); |
|
|
|
return list; |
|
|
|
} |
|
|
|
private List<RecordVo.WeightAndRfid> queryRecord(Long carId, Long startTime, Long endTime, byte[] types) { |
|
|
|
List<RecordVo.WeightAndRfid> records = new ArrayList<>(); |
|
|
|
if (types == null || types.length == 0) { |
|
|
|
log.info("没有输入查询记录类型,直接返回"); |
|
|
|
return records; |
|
|
|
} |
|
|
|
|
|
|
|
for (byte type : types) { |
|
|
|
List<RecordVo.WeightAndRfid> list = wisdomCarRecordDao.queryRecords(carId, startTime, endTime, type); |
|
|
|
RecordVo.WeightAndRfid prev = null; |
|
|
|
for (int i = 0; i < list.size(); i++) { |
|
|
|
RecordVo.WeightAndRfid cur = list.get(i); |
|
|
|
if (i == 0) { |
|
|
|
records.add(cur); |
|
|
|
prev = cur; |
|
|
|
continue; |
|
|
|
} |
|
|
|
// i > 0 && cur.type == prev.type
|
|
|
|
//称重
|
|
|
|
if (cur.getType() == Constant.CAR_RECORD_WEIGHT) { |
|
|
|
// 重量差大于10KG或时间间隔大于10分钟,保留
|
|
|
|
if (Math.abs(Integer.parseInt(cur.getValue()) - Integer.parseInt(prev.getValue())) > weightMinus |
|
|
|
|| Math.abs(cur.getTime() - prev.getTime()) > timeMinus) { |
|
|
|
records.add(cur); |
|
|
|
prev = cur; |
|
|
|
} |
|
|
|
continue; |
|
|
|
} |
|
|
|
// 非称重 值不重复 或 非称重 值重复 最后一条数据
|
|
|
|
if(!cur.getValue().equals(prev.getValue()) || i == list.size() -1){ |
|
|
|
records.add(cur); |
|
|
|
|
|
|
|
} else if (!cur.getValue().equals(list.get(i+1).getValue()) ) { |
|
|
|
// 非称重 值重复 非最后一条数据
|
|
|
|
// 判断与下一个是否一致,一致,则不保留第一个和最后一个
|
|
|
|
records.add(cur); |
|
|
|
} |
|
|
|
prev = cur; |
|
|
|
} |
|
|
|
} |
|
|
|
if (types.length > 1) { |
|
|
|
log.info("重新排序"); |
|
|
|
Collections.sort(records, (o1, o2) -> (int) (o1.getTime() - o2.getTime())); |
|
|
|
} |
|
|
|
return records; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 查询数据 |
|
|
@ -218,7 +265,7 @@ public class RecordService implements IRecordService{ |
|
|
|
@Override |
|
|
|
public Workbook exportWeightAndRfid(RecordDto.WeightAndRfidExport param) { |
|
|
|
log.info("数据导出:{}", param); |
|
|
|
List<RecordVo.WeightAndRfid> list = queryWeightAndRfid(param.getCarId(), param.getStartTime(), param.getEndTime()); |
|
|
|
List<RecordVo.WeightAndRfid> list = queryRecord(param.getCarId(), param.getStartTime(), param.getEndTime(), param.getTypes()); |
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|
|
|
// 参数封装
|
|
|
|
List<List<PoiUtil.PoiUtilCell>> rows = new ArrayList<>(); |
|
|
@ -246,7 +293,18 @@ public class RecordService implements IRecordService{ |
|
|
|
Date time = new Date(); |
|
|
|
time.setTime(record.getTime()); |
|
|
|
row.add(new PoiUtil.PoiUtilCell(sdf.format(time))); |
|
|
|
row.add(new PoiUtil.PoiUtilCell(record.getType() == Constant.CAR_RECORD_WEIGHT ? "称重" : "rfid")); |
|
|
|
String type = "称重"; |
|
|
|
switch (record.getType()) { |
|
|
|
case Constant.CAR_RECORD_WEIGHT: type = "称重";break; |
|
|
|
case Constant.CAR_RECORD_RFID: type = "rfid";break; |
|
|
|
case Constant.WEIGHT_SENSOR_1: type = "称重1";break; |
|
|
|
case Constant.WEIGHT_SENSOR_2: type = "称重2";break; |
|
|
|
case Constant.WEIGHT_SENSOR_3: type = "称重3";break; |
|
|
|
case Constant.WEIGHT_SENSOR_4: type = "称重4";break; |
|
|
|
case Constant.SHAKE_SENSOR: type = "震动";break; |
|
|
|
case Constant.THROMBOLYTIC: type = "剂量";break; |
|
|
|
} |
|
|
|
row.add(new PoiUtil.PoiUtilCell(type)); |
|
|
|
row.add(new PoiUtil.PoiUtilCell(record.getType() == Constant.CAR_RECORD_WEIGHT ? new BigDecimal(record.getValue()).divide(new BigDecimal(1000), 3).toString() + "Kg" : record.getName())); |
|
|
|
rows.add(row); |
|
|
|
} |
|
|
|