@Override
public GenerateImportDto EquipmentRecImport(List list) {
//从jwt中获取当前的userid
Long userId = 1L;
//获取到userId传入Ordertils的方法中截取判断
String projectNo = OrderUtils.getProjectNo(userId);
//将获取到的projectNo放在redis中,当做key唯一值储存->唯一性,REDIS_ORDER = “keda:import:equipType_”,项目编号
String redisKey = OrderUtils.getRedisProjectNoKey(projectNo);
String redisRecordCountKey = OrderUtils.getRedisRecordCountKey(projectNo);
//3、存储到reids中,有效期为30分钟。
Map<String, Object> RedisRecordMap = new HashMap<>(1);
//首先设置返回的错误统计为0,设置一个参数
int errorCount = 0;
//reids的原子操作
AtomicDouble totalAmount = new AtomicDouble();
for (ExcelEquipVo vo : list
) {
//获取redis自增主键
long id = redisUtils.incr(projectNo, 1);
//4.验证 设备信息
List equipmentDtos = equipmentMapper.selectAllByEquipName(vo.getEquipName());
if (equipmentDtos.size()>0) {
vo.setError(true);
vo.setVerifyResult(“设备已存在”);
} else {
vo.setError(false);
List rpList = list.stream().map(ExcelEquipVo::getEquipTypeName)
.collect(Collectors.toList());
long count = rpList.stream().distinct().count();
if (rpList.size() != count) {
vo.setError(true);
vo.setVerifyResult(“设备” + vo.getEquipTypeName() + “的记录重复”);
}
}
redisUtils.addZset(redisRecordCountKey, String.valueOf(id), id);
vo.setId(id);
RedisRecordMap.put(String.valueOf(id), vo);
}
redisUtils.setHashMap(redisKey, RedisRecordMap, OrderUtils.ORDER_EXPIRE);
//redisUtils.set(redisKey, list, OrderUtils.ORDER_EXPIRE);
redisUtils.expire(redisRecordCountKey, OrderUtils.ORDER_EXPIRE);
//统计数据
GenerateImportDto dto = new GenerateImportDto();
dto.setErrorCount(errorCount);
dto.setProjectNo(projectNo);
dto.setTotalAmount(BigDecimal.valueOf(totalAmount.get()));
dto.setTotalCount(list.size());
//缓存统计数据,避免保存数据时重复统计
String statisticsKey = OrderUtils.getRedisStaticKey(projectNo);
redisUtils.set(statisticsKey, dto, OrderUtils.ORDER_EXPIRE);
return dto;
}