|
|
@ -3,8 +3,10 @@ package com.zc.business.service.impl; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
|
import com.ruoyi.common.constant.HttpStatus; |
|
|
|
import com.ruoyi.common.core.redis.RedisCache; |
|
|
|
import com.ruoyi.common.exception.ServiceException; |
|
|
|
import com.ruoyi.common.utils.PageUtils; |
|
|
|
import com.zc.business.constant.RedisKeyConstants; |
|
|
|
import com.zc.business.domain.DcDevice; |
|
|
|
import com.zc.business.domain.DcProduct; |
|
|
|
import com.zc.business.domain.DcStakeMark; |
|
|
@ -15,6 +17,7 @@ import com.zc.business.service.IDcStakeMarkService; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.util.StringUtils; |
|
|
|
|
|
|
|
import javax.annotation.PostConstruct; |
|
|
|
import javax.annotation.Resource; |
|
|
|
import java.util.*; |
|
|
|
import java.util.regex.Matcher; |
|
|
@ -35,6 +38,42 @@ public class DcDeviceServiceImpl extends ServiceImpl<DcDeviceMapper, DcDevice> i |
|
|
|
@Resource |
|
|
|
private DcDeviceMapper dcDeviceMapper; |
|
|
|
|
|
|
|
@Resource |
|
|
|
private RedisCache redisCache; |
|
|
|
|
|
|
|
@PostConstruct |
|
|
|
public void init() |
|
|
|
{ |
|
|
|
/* |
|
|
|
添加数据到 redis 缓存 |
|
|
|
*/ |
|
|
|
updateRedisCache(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 添加数据到 redis 缓存 |
|
|
|
*/ |
|
|
|
public void updateRedisCache() |
|
|
|
{ |
|
|
|
// 获取全部设备列表数据
|
|
|
|
List<DcDevice> dcDevices = list(); |
|
|
|
if (dcDevices == null || dcDevices.isEmpty()) |
|
|
|
{ |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
// 清楚 redis 缓存数据
|
|
|
|
redisCache.deleteObject(RedisKeyConstants.DC_DEVICES); |
|
|
|
|
|
|
|
// 添加 redis 缓存数据
|
|
|
|
dcDevices.forEach(val -> { |
|
|
|
String iotDeviceId = val.getIotDeviceId(); |
|
|
|
if (StringUtils.hasText(iotDeviceId)) { |
|
|
|
redisCache.setCacheMapValue(RedisKeyConstants.DC_DEVICES, val.getIotDeviceId(), val); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
private static String REGEX_CHINESE = "[\u4e00-\u9fa5]";// 中文正则
|
|
|
|
|
|
|
|
public LambdaQueryWrapper<DcDevice> deviceQueryWrapper(DcDevice dcDevice) { |
|
|
@ -176,7 +215,14 @@ public class DcDeviceServiceImpl extends ServiceImpl<DcDeviceMapper, DcDevice> i |
|
|
|
|
|
|
|
dcDevice.setCreateTime(new Date()); |
|
|
|
dcDevice.setUseState(DcDevice.UNUSEDSTATE); |
|
|
|
return save(dcDevice); |
|
|
|
|
|
|
|
if (save(dcDevice)) { |
|
|
|
// 更新缓存
|
|
|
|
updateRedisCache(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@ -198,7 +244,14 @@ public class DcDeviceServiceImpl extends ServiceImpl<DcDeviceMapper, DcDevice> i |
|
|
|
} |
|
|
|
|
|
|
|
dcDevice.setUpdateTime(new Date()); |
|
|
|
return updateById(dcDevice); |
|
|
|
|
|
|
|
if (updateById(dcDevice)) { |
|
|
|
// 更新缓存
|
|
|
|
updateRedisCache(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@ -218,7 +271,14 @@ public class DcDeviceServiceImpl extends ServiceImpl<DcDeviceMapper, DcDevice> i |
|
|
|
throw new ServiceException("设备正在使用", HttpStatus.MOVED_PERM); |
|
|
|
} |
|
|
|
}); |
|
|
|
return removeByIds(ids); |
|
|
|
|
|
|
|
if (removeByIds(ids)) { |
|
|
|
// 更新缓存
|
|
|
|
updateRedisCache(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@ -258,6 +318,9 @@ public class DcDeviceServiceImpl extends ServiceImpl<DcDeviceMapper, DcDevice> i |
|
|
|
queryWrapper.eq(DcDevice::getIotDeviceId, device.getIotDeviceId()); |
|
|
|
update(device, queryWrapper); |
|
|
|
} |
|
|
|
|
|
|
|
// 更新缓存
|
|
|
|
updateRedisCache(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
@ -298,14 +361,18 @@ public class DcDeviceServiceImpl extends ServiceImpl<DcDeviceMapper, DcDevice> i |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<DcDevice> devicePileNumberQueryDevice(Map<String, List> parameter) { |
|
|
|
public List<DcDevice> devicePileNumberQueryDevice(Map<String, Object> parameter) { |
|
|
|
ArrayList<DcDevice> dcDevices = new ArrayList<>(); |
|
|
|
Integer startStakeMark = Integer.parseInt(String.valueOf(parameter.get("startStakeMark").get(0)) + String.valueOf(parameter.get("startStakeMark").get(1))); |
|
|
|
Integer endStakeMark = Integer.parseInt(String.valueOf(parameter.get("endStakeMark").get(0)) + String.valueOf(parameter.get("endStakeMark").get(1))); |
|
|
|
List<String> startStakeMarks = castList(parameter.get("startStakeMark"), String.class); |
|
|
|
List<String> endStakeMarks = castList(parameter.get("endStakeMark"), String.class); |
|
|
|
String deviceType = String.valueOf(parameter.get("deviceType")); |
|
|
|
Integer startStakeMark = Integer.parseInt(startStakeMarks.get(0) + startStakeMarks.get(1)); |
|
|
|
Integer endStakeMark = Integer.parseInt(endStakeMarks.get(0) + endStakeMarks.get(1)); |
|
|
|
LambdaQueryWrapper<DcDevice> lambdaQueryWrapper = new LambdaQueryWrapper<>(); |
|
|
|
ArrayList<Integer> integers = new ArrayList<>(); |
|
|
|
integers.add(6); |
|
|
|
lambdaQueryWrapper.notIn(DcDevice::getDeviceType,integers); |
|
|
|
lambdaQueryWrapper.notIn(DcDevice::getDeviceType, integers); |
|
|
|
lambdaQueryWrapper.eq(DcDevice::getDeviceType, deviceType); |
|
|
|
List<DcDevice> list = list(lambdaQueryWrapper); |
|
|
|
for (DcDevice dcDevice : list) { |
|
|
|
String stakeMark = dcDevice.getStakeMark(); |
|
|
@ -336,5 +403,16 @@ public class DcDeviceServiceImpl extends ServiceImpl<DcDeviceMapper, DcDevice> i |
|
|
|
|
|
|
|
return dcDevices; |
|
|
|
} |
|
|
|
|
|
|
|
public static <T> List<T> castList(Object obj, Class<T> clazz) { |
|
|
|
List<T> result = new ArrayList<T>(); |
|
|
|
if (obj instanceof List<?>) { |
|
|
|
for (Object o : (List<?>) obj) { |
|
|
|
result.add(clazz.cast(o)); |
|
|
|
} |
|
|
|
return result; |
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|