|
@@ -61,18 +61,13 @@ public class DeviceAlgorithmChargingServiceImpl extends ServiceImpl<DeviceAlgori
|
|
|
List<DeviceAlgorithmCharging> deviceAlgorithmChargings = list(new LambdaQueryWrapper<DeviceAlgorithmCharging>()
|
|
|
.eq(DeviceAlgorithmCharging::getDeviceId, deviceInfo.getDeviceId())
|
|
|
.eq(DeviceAlgorithmCharging::getAlgorithmId, deviceInfo.getAlgorithmId())
|
|
|
- .in(DeviceAlgorithmCharging::getTimeout, Arrays.asList(DataTime.getSring("yyyyMM"), -1))
|
|
|
+ .gt(DeviceAlgorithmCharging::getUnusedSize, 0)
|
|
|
+ .gt(DeviceAlgorithmCharging::getTimeout, 0)
|
|
|
+ .in(DeviceAlgorithmCharging::getBeginTime, Arrays.asList(DataTime.getSring("yyyyMM"), -1))
|
|
|
);
|
|
|
if (!Emptys.check(deviceAlgorithmChargings)) {
|
|
|
throw new CommRuntimeException("设备欠费,请充值");
|
|
|
}
|
|
|
- int size = 0;
|
|
|
- for (DeviceAlgorithmCharging deviceAlgorithmCharging : deviceAlgorithmChargings) {
|
|
|
- size += deviceAlgorithmCharging.getUnusedSize();
|
|
|
- }
|
|
|
- if (size == 0) {
|
|
|
- throw new CommRuntimeException("设备欠费,请充值");
|
|
|
- }
|
|
|
return R.ok();
|
|
|
}
|
|
|
|
|
@@ -114,6 +109,7 @@ public class DeviceAlgorithmChargingServiceImpl extends ServiceImpl<DeviceAlgori
|
|
|
JList<DeviceAlgorithmChargingHistory> infs = new JArrayList<>();
|
|
|
JList<DeviceAlgorithmChargingHistory> gives = new JArrayList<>();
|
|
|
LocalDateTime now = LocalDateTime.now();
|
|
|
+ int yyyyMM = Integer.valueOf(DataTime.getSring("yyyyMM"));
|
|
|
//获取算法包月字典
|
|
|
Map<String, SysDictRedis> algorithmMoonConfigMaps = SysDictUtils.get(EnumAlgorithmPayConfig.Code.CODE.getCode());
|
|
|
//获取类型字典
|
|
@@ -136,29 +132,30 @@ public class DeviceAlgorithmChargingServiceImpl extends ServiceImpl<DeviceAlgori
|
|
|
DeviceAlgorithmChargingDto.AlgorithmMoonConfig.Moon moon = algorithmMoonConfig.getMoon();
|
|
|
Integer chargingSize = deviceAlgorithmChargingHistory.getChargingSize();
|
|
|
for (Integer integer = 0; integer < chargingSize; integer++) {
|
|
|
- //查询过期时间最大的算法计费
|
|
|
+ //查询生效时间最大的算法计费
|
|
|
LambdaQueryWrapper<DeviceAlgorithmCharging> lambdaQueryWrapper = new LambdaQueryWrapper<DeviceAlgorithmCharging>()
|
|
|
.eq(DeviceAlgorithmCharging::getDeviceId, deviceAlgorithmChargingHistory.getDeviceId())
|
|
|
.eq(DeviceAlgorithmCharging::getAlgorithmId, deviceAlgorithmChargingHistory.getAlgorithmId())
|
|
|
.eq(DeviceAlgorithmCharging::getType, type)
|
|
|
- .orderByDesc(DeviceAlgorithmCharging::getTimeout)
|
|
|
+ .orderByDesc(DeviceAlgorithmCharging::getBeginTime)
|
|
|
.last("limit 1");
|
|
|
DeviceAlgorithmCharging deviceAlgorithmCharging = getOne(lambdaQueryWrapper);
|
|
|
- int timeout;
|
|
|
+ int beginTime;
|
|
|
if (deviceAlgorithmCharging == null) {
|
|
|
- timeout = Integer.valueOf(DataTime.toString(deviceAlgorithmChargingHistory.getCreateTime(), "yyyyMM"));
|
|
|
+ beginTime = Integer.valueOf(DataTime.toString(deviceAlgorithmChargingHistory.getCreateTime(), "yyyyMM"));
|
|
|
} else {
|
|
|
- LocalDateTime localDateTime = DataTime.toLocal(deviceAlgorithmCharging.getTimeout() + "01000000", "yyyyMMddHHmmss");
|
|
|
+ LocalDateTime localDateTime = DataTime.toLocal(deviceAlgorithmCharging.getBeginTime() + "01000000", "yyyyMMddHHmmss");
|
|
|
String s = DataTime.toString(localDateTime, "yyyy-MM-dd HH:mm:ss");
|
|
|
String stringAround = DataTime.getStringAround(0, 1, 0, 0, 0, 0, s);
|
|
|
- timeout = Integer.valueOf(DataTime.toString(DataTime.toLocal(stringAround), "yyyyMM"));
|
|
|
+ beginTime = Integer.valueOf(DataTime.toString(DataTime.toLocal(stringAround), "yyyyMM"));
|
|
|
}
|
|
|
DeviceAlgorithmCharging deviceAlgorithmChargingInfo = new DeviceAlgorithmCharging()
|
|
|
.setDeviceId(deviceAlgorithmChargingHistory.getDeviceId())
|
|
|
.setAlgorithmId(deviceAlgorithmChargingHistory.getAlgorithmId())
|
|
|
.setUnusedSize(moon.getSize())
|
|
|
.setType(type)
|
|
|
- .setTimeout(timeout)
|
|
|
+ .setTimeout(30)
|
|
|
+ .setBeginTime(beginTime)
|
|
|
.setCreateTime(now)
|
|
|
.setUpdateTime(now);
|
|
|
save(deviceAlgorithmChargingInfo);
|
|
@@ -166,54 +163,32 @@ public class DeviceAlgorithmChargingServiceImpl extends ServiceImpl<DeviceAlgori
|
|
|
});
|
|
|
//处理无期限
|
|
|
infs.forEach(deviceAlgorithmChargingHistory -> {
|
|
|
- LambdaQueryWrapper<DeviceAlgorithmCharging> lambdaQueryWrapper = new LambdaQueryWrapper<DeviceAlgorithmCharging>()
|
|
|
- .eq(DeviceAlgorithmCharging::getDeviceId, deviceAlgorithmChargingHistory.getDeviceId())
|
|
|
- .eq(DeviceAlgorithmCharging::getAlgorithmId, deviceAlgorithmChargingHistory.getAlgorithmId())
|
|
|
- .eq(DeviceAlgorithmCharging::getType, deviceAlgorithmChargingHistory.getType());
|
|
|
- DeviceAlgorithmCharging deviceAlgorithmCharging = getOne(lambdaQueryWrapper);
|
|
|
SysDictRedis algorithmMoonConfigDict = algorithmMoonConfigMaps.get(deviceAlgorithmChargingHistory.getAlgorithmId().toString());
|
|
|
DeviceAlgorithmChargingDto.AlgorithmMoonConfig algorithmMoonConfig = JSONUtil.parseObj(algorithmMoonConfigDict.getValue()).toBean(DeviceAlgorithmChargingDto.AlgorithmMoonConfig.class);
|
|
|
DeviceAlgorithmChargingDto.AlgorithmMoonConfig.Inf inf = algorithmMoonConfig.getInf();
|
|
|
- if (deviceAlgorithmCharging == null) {
|
|
|
- DeviceAlgorithmCharging deviceAlgorithmChargingInfo = new DeviceAlgorithmCharging()
|
|
|
- .setDeviceId(deviceAlgorithmChargingHistory.getDeviceId())
|
|
|
- .setAlgorithmId(deviceAlgorithmChargingHistory.getAlgorithmId())
|
|
|
- .setUnusedSize(inf.getSize() * deviceAlgorithmChargingHistory.getChargingSize())
|
|
|
- .setType(deviceAlgorithmChargingHistory.getType())
|
|
|
- .setTimeout(-1)
|
|
|
- .setCreateTime(now)
|
|
|
- .setUpdateTime(now);
|
|
|
- save(deviceAlgorithmChargingInfo);
|
|
|
- } else {
|
|
|
- deviceAlgorithmCharging.setUnusedSize(deviceAlgorithmCharging.getUnusedSize() + (inf.getSize() * deviceAlgorithmChargingHistory.getChargingSize()))
|
|
|
- .setUpdateTime(now);
|
|
|
- updateById(deviceAlgorithmCharging);
|
|
|
- }
|
|
|
+ DeviceAlgorithmCharging deviceAlgorithmChargingInfo = new DeviceAlgorithmCharging()
|
|
|
+ .setDeviceId(deviceAlgorithmChargingHistory.getDeviceId())
|
|
|
+ .setAlgorithmId(deviceAlgorithmChargingHistory.getAlgorithmId())
|
|
|
+ .setUnusedSize(inf.getSize() * deviceAlgorithmChargingHistory.getChargingSize())
|
|
|
+ .setType(deviceAlgorithmChargingHistory.getType())
|
|
|
+ .setTimeout(-1)
|
|
|
+ .setBeginTime(yyyyMM)
|
|
|
+ .setCreateTime(now)
|
|
|
+ .setUpdateTime(now);
|
|
|
+ save(deviceAlgorithmChargingInfo);
|
|
|
});
|
|
|
//处理赠送
|
|
|
gives.forEach(deviceAlgorithmChargingHistory -> {
|
|
|
- int timeout = Integer.valueOf(DataTime.toString(deviceAlgorithmChargingHistory.getCreateTime(), "yyyyMM"));
|
|
|
- LambdaQueryWrapper<DeviceAlgorithmCharging> lambdaQueryWrapper = new LambdaQueryWrapper<DeviceAlgorithmCharging>()
|
|
|
- .eq(DeviceAlgorithmCharging::getDeviceId, deviceAlgorithmChargingHistory.getDeviceId())
|
|
|
- .eq(DeviceAlgorithmCharging::getAlgorithmId, deviceAlgorithmChargingHistory.getAlgorithmId())
|
|
|
- .eq(DeviceAlgorithmCharging::getType, deviceAlgorithmChargingHistory.getType())
|
|
|
- .eq(DeviceAlgorithmCharging::getTimeout, timeout);
|
|
|
- DeviceAlgorithmCharging deviceAlgorithmCharging = getOne(lambdaQueryWrapper);
|
|
|
- if (deviceAlgorithmCharging == null) {
|
|
|
- DeviceAlgorithmCharging deviceAlgorithmChargingInfo = new DeviceAlgorithmCharging()
|
|
|
- .setDeviceId(deviceAlgorithmChargingHistory.getDeviceId())
|
|
|
- .setAlgorithmId(deviceAlgorithmChargingHistory.getAlgorithmId())
|
|
|
- .setUnusedSize(deviceAlgorithmChargingHistory.getChargingSize())
|
|
|
- .setType(deviceAlgorithmChargingHistory.getType())
|
|
|
- .setTimeout(timeout)
|
|
|
- .setCreateTime(now)
|
|
|
- .setUpdateTime(now);
|
|
|
- save(deviceAlgorithmChargingInfo);
|
|
|
- } else {
|
|
|
- deviceAlgorithmCharging.setUnusedSize(deviceAlgorithmCharging.getUnusedSize() + deviceAlgorithmChargingHistory.getChargingSize())
|
|
|
- .setUpdateTime(now);
|
|
|
- updateById(deviceAlgorithmCharging);
|
|
|
- }
|
|
|
+ DeviceAlgorithmCharging deviceAlgorithmChargingInfo = new DeviceAlgorithmCharging()
|
|
|
+ .setDeviceId(deviceAlgorithmChargingHistory.getDeviceId())
|
|
|
+ .setAlgorithmId(deviceAlgorithmChargingHistory.getAlgorithmId())
|
|
|
+ .setUnusedSize(deviceAlgorithmChargingHistory.getChargingSize())
|
|
|
+ .setType(deviceAlgorithmChargingHistory.getType())
|
|
|
+ .setTimeout(30)
|
|
|
+ .setBeginTime(yyyyMM)
|
|
|
+ .setCreateTime(now)
|
|
|
+ .setUpdateTime(now);
|
|
|
+ save(deviceAlgorithmChargingInfo);
|
|
|
});
|
|
|
if (Emptys.check(deviceAlgorithmChargingHistories)) {
|
|
|
Integer status = SysDictUtils.getValue(EnumDeviceAlgorithmChargingHistoryStatus.Code.CODE.getCode(), EnumDeviceAlgorithmChargingHistoryStatus.N_2.getCode(), Integer.class);
|
|
@@ -234,7 +209,14 @@ public class DeviceAlgorithmChargingServiceImpl extends ServiceImpl<DeviceAlgori
|
|
|
LambdaQueryWrapper<DeviceAlgorithmCharging> lambdaQueryWrapper = new LambdaQueryWrapper<DeviceAlgorithmCharging>()
|
|
|
.in(DeviceAlgorithmCharging::getDeviceId, list.getProperty(DeviceAlgorithmChargingDto.Charging::getDeviceId))
|
|
|
.in(DeviceAlgorithmCharging::getAlgorithmId, list.getProperty(DeviceAlgorithmChargingDto.Charging::getAlgorithmId))
|
|
|
- .in(DeviceAlgorithmCharging::getTimeout, list.getProperty(DeviceAlgorithmChargingDto.Charging::getAlgorithmDate).set(-1));
|
|
|
+ .gt(DeviceAlgorithmCharging::getUnusedSize, 0)
|
|
|
+ .and(deviceAlgorithmChargingLambdaQueryWrapper -> deviceAlgorithmChargingLambdaQueryWrapper
|
|
|
+ .gt(DeviceAlgorithmCharging::getTimeout, 0)
|
|
|
+ .or()
|
|
|
+ .eq(DeviceAlgorithmCharging::getTimeout, -1)
|
|
|
+ )
|
|
|
+ .in(DeviceAlgorithmCharging::getBeginTime, list.getProperty(DeviceAlgorithmChargingDto.Charging::getAlgorithmDate))
|
|
|
+ .orderByAsc(DeviceAlgorithmCharging::getBeginTime, DeviceAlgorithmCharging::getCreateTime);
|
|
|
List<DeviceAlgorithmCharging> deviceAlgorithmChargingsList = list(lambdaQueryWrapper);
|
|
|
if (!Emptys.check(deviceAlgorithmChargingsList)) {
|
|
|
return R.ok(map);
|
|
@@ -253,13 +235,12 @@ public class DeviceAlgorithmChargingServiceImpl extends ServiceImpl<DeviceAlgori
|
|
|
JList<DeviceAlgorithmCharging> deviceAlgorithmChargingJlist = deviceAlgorithmChargings.filter()
|
|
|
.eq(DeviceAlgorithmCharging::getDeviceId, charging.getDeviceId())
|
|
|
.eq(DeviceAlgorithmCharging::getAlgorithmId, charging.getAlgorithmId())
|
|
|
- .in(DeviceAlgorithmCharging::getTimeout, Arrays.asList(charging.getAlgorithmDate(), -1))
|
|
|
.list();
|
|
|
if (!Emptys.check(deviceAlgorithmChargingJlist)) {
|
|
|
return;
|
|
|
}
|
|
|
- JMap<Integer, DeviceAlgorithmCharging> deviceAlgorithmChargingJMap = deviceAlgorithmChargingJlist.toMap(DeviceAlgorithmCharging::getType).cover();
|
|
|
- //递归扣费
|
|
|
+ JMap<Integer, List<DeviceAlgorithmCharging>> deviceAlgorithmChargingJMap = deviceAlgorithmChargingJlist.toMap(DeviceAlgorithmCharging::getType).group();
|
|
|
+ //递归扣费 扣费顺序为:赠送 -> 有期限 -> 无期限
|
|
|
int size2 = charging(size, deviceAlgorithmChargingJMap, new JArrayList<SysDictRedis>().set(sysDictRedis3).set(sysDictRedis1).set(sysDictRedis2));
|
|
|
map.put(charging.getMercDeviceAlgorithmChargingId(), size2);
|
|
|
});
|
|
@@ -271,31 +252,33 @@ public class DeviceAlgorithmChargingServiceImpl extends ServiceImpl<DeviceAlgori
|
|
|
*
|
|
|
* @return 未扣条数
|
|
|
*/
|
|
|
- private int charging(int size, JMap<Integer, DeviceAlgorithmCharging> deviceAlgorithmChargingJMap, List<SysDictRedis> sysDictRediss) {
|
|
|
+ private int charging(int size, JMap<Integer, List<DeviceAlgorithmCharging>> deviceAlgorithmChargingJMap, List<SysDictRedis> sysDictRediss) {
|
|
|
if (size > 0 && Emptys.check(sysDictRediss)) {
|
|
|
SysDictRedis sysDictRedis = sysDictRediss.remove(0);
|
|
|
LocalDateTime now = LocalDateTime.now();
|
|
|
- DeviceAlgorithmCharging deviceAlgorithmCharging = deviceAlgorithmChargingJMap.get(Integer.valueOf(sysDictRedis.getValue()));
|
|
|
- if (deviceAlgorithmCharging != null) {
|
|
|
- int unusedSize = deviceAlgorithmCharging.getUnusedSize();
|
|
|
- if (unusedSize > 0) {
|
|
|
- int newUnusedSize = unusedSize - size;
|
|
|
- int makeSize;
|
|
|
- //扣除后=负数则算法条数不足
|
|
|
- if (newUnusedSize < 0) {
|
|
|
- size = (~(newUnusedSize - 1));
|
|
|
- newUnusedSize = 0;
|
|
|
- makeSize = unusedSize;
|
|
|
- } else {
|
|
|
- makeSize = size;
|
|
|
- size = 0;
|
|
|
+ List<DeviceAlgorithmCharging> deviceAlgorithmChargings = deviceAlgorithmChargingJMap.get(Integer.valueOf(sysDictRedis.getValue()));
|
|
|
+ if (Emptys.check(deviceAlgorithmChargings)) {
|
|
|
+ for (DeviceAlgorithmCharging deviceAlgorithmCharging : deviceAlgorithmChargings) {
|
|
|
+ int unusedSize = deviceAlgorithmCharging.getUnusedSize();
|
|
|
+ if (unusedSize > 0) {
|
|
|
+ int newUnusedSize = unusedSize - size;
|
|
|
+ int makeSize;
|
|
|
+ //扣除后=负数则算法条数不足
|
|
|
+ if (newUnusedSize < 0) {
|
|
|
+ size = (~(newUnusedSize - 1));
|
|
|
+ newUnusedSize = 0;
|
|
|
+ makeSize = unusedSize;
|
|
|
+ } else {
|
|
|
+ makeSize = size;
|
|
|
+ size = 0;
|
|
|
+ }
|
|
|
+ DeviceAlgorithmCharging updateDeviceAlgorithmCharging = new DeviceAlgorithmCharging()
|
|
|
+ .setId(deviceAlgorithmCharging.getId())
|
|
|
+ .setUnusedSize(newUnusedSize)
|
|
|
+ .setMakeSize(deviceAlgorithmCharging.getMakeSize() + makeSize)
|
|
|
+ .setUpdateTime(now);
|
|
|
+ updateById(updateDeviceAlgorithmCharging);
|
|
|
}
|
|
|
- DeviceAlgorithmCharging updateDeviceAlgorithmCharging = new DeviceAlgorithmCharging()
|
|
|
- .setId(deviceAlgorithmCharging.getId())
|
|
|
- .setUnusedSize(newUnusedSize)
|
|
|
- .setMakeSize(deviceAlgorithmCharging.getMakeSize() + makeSize)
|
|
|
- .setUpdateTime(now);
|
|
|
- updateById(updateDeviceAlgorithmCharging);
|
|
|
}
|
|
|
}
|
|
|
if (size > 0 && Emptys.check(sysDictRediss)) {
|