|
@@ -73,23 +73,27 @@ public class DeviceDataServiceImpl extends ServiceImpl<DeviceDataMapper, DeviceD
|
|
@Lock(value = "saveOrAccum.deviceId", prefix = "data_save_accum_")
|
|
@Lock(value = "saveOrAccum.deviceId", prefix = "data_save_accum_")
|
|
public R saveOrAccum(DeviceDataDto.SaveOrAccum saveOrAccum) {
|
|
public R saveOrAccum(DeviceDataDto.SaveOrAccum saveOrAccum) {
|
|
LocalDateTime now = LocalDateTime.now();
|
|
LocalDateTime now = LocalDateTime.now();
|
|
- String stringTime = DataTime.toString(now, "yyyyMMdd");
|
|
|
|
|
|
+ String yyyyMMdd = DataTime.toString(now, "yyyyMMdd");
|
|
//获取字典
|
|
//获取字典
|
|
Map<String, SysDictRedis> map = SysDictUtils.get(DictEnum.DEVICE_DATA_TYPE.getKey());
|
|
Map<String, SysDictRedis> map = SysDictUtils.get(DictEnum.DEVICE_DATA_TYPE.getKey());
|
|
|
|
+ JMap<String, Integer> jMap = new JHashMap<>(map.size());
|
|
|
|
+ map.forEach((type, sysDictRedis) -> {
|
|
|
|
+ Integer dateValue = Integer.valueOf(yyyyMMdd.substring(0, Integer.valueOf(sysDictRedis.getValue())));
|
|
|
|
+ jMap.put(type, dateValue);
|
|
|
|
+ });
|
|
//查询已存在数据
|
|
//查询已存在数据
|
|
List<DeviceData> list = list(new LambdaQueryWrapper<DeviceData>()
|
|
List<DeviceData> list = list(new LambdaQueryWrapper<DeviceData>()
|
|
.eq(DeviceData::getDeviceId, saveOrAccum.getDeviceId())
|
|
.eq(DeviceData::getDeviceId, saveOrAccum.getDeviceId())
|
|
- .in(DeviceData::getType, new JHashMap<>(map).toList().key())
|
|
|
|
|
|
+ .in(DeviceData::getDateValue, jMap.toList().value())
|
|
);
|
|
);
|
|
JMap<String, DeviceData> typeMaps = new JArrayList<>(list).toMap(DeviceData::getType).cover();
|
|
JMap<String, DeviceData> typeMaps = new JArrayList<>(list).toMap(DeviceData::getType).cover();
|
|
//新增或修改的多线程桶map集合
|
|
//新增或修改的多线程桶map集合
|
|
JMap<String, DeviceData> dbMaps = new JConcurrentHashMap<>(map.size());
|
|
JMap<String, DeviceData> dbMaps = new JConcurrentHashMap<>(map.size());
|
|
//封装新增或修改对象
|
|
//封装新增或修改对象
|
|
- map.forEach((type, sysDictRedis) -> {
|
|
|
|
|
|
+ jMap.forEach((type, dateValue) -> {
|
|
DeviceData deviceData = typeMaps.get(type);
|
|
DeviceData deviceData = typeMaps.get(type);
|
|
//添加
|
|
//添加
|
|
if (deviceData == null) {
|
|
if (deviceData == null) {
|
|
- Integer dateValue = Integer.valueOf(stringTime.substring(0, Integer.valueOf(sysDictRedis.getValue())));
|
|
|
|
DeviceData saveOrUpdateInfo = copy(DeviceData.class, saveOrAccum)
|
|
DeviceData saveOrUpdateInfo = copy(DeviceData.class, saveOrAccum)
|
|
.setCreateTime(now)
|
|
.setCreateTime(now)
|
|
.setUpdateTime(now)
|
|
.setUpdateTime(now)
|