|
@@ -6,8 +6,9 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.github.yitter.idgen.YitIdHelper;
|
|
|
import com.xy.collections.list.JArrayList;
|
|
|
import com.xy.collections.list.JList;
|
|
|
-import com.xy.device.EnumAlgorithmMoonConfig;
|
|
|
+import com.xy.device.EnumAlgorithmPayConfig;
|
|
|
import com.xy.device.EnumDeviceAlgorithmChargingHistoryStatus;
|
|
|
+import com.xy.device.EnumDeviceAlgorithmChargingType;
|
|
|
import com.xy.dto.DeviceAlgorithmChargingDto;
|
|
|
import com.xy.entity.DeviceAlgorithmCharging;
|
|
|
import com.xy.entity.DeviceAlgorithmChargingHistory;
|
|
@@ -57,6 +58,7 @@ public class DeviceAlgorithmChargingServiceImpl extends ServiceImpl<DeviceAlgori
|
|
|
.setAlgorithmId(deviceAlgorithmCharging.getAlgorithmId())
|
|
|
.setChargingSize(deviceAlgorithmCharging.getChargingSize())
|
|
|
.setChargingMoney(deviceAlgorithmCharging.getMoney())
|
|
|
+ .setType(deviceAlgorithmCharging.getType())
|
|
|
.setChargingType(pay.getPayType())
|
|
|
.setCreateTime(now)
|
|
|
.setUpdateTime(now);
|
|
@@ -76,28 +78,37 @@ public class DeviceAlgorithmChargingServiceImpl extends ServiceImpl<DeviceAlgori
|
|
|
if (!Emptys.check(list)) {
|
|
|
return R.ok();
|
|
|
}
|
|
|
- int give = 100;
|
|
|
JList<DeviceAlgorithmChargingHistory> deviceAlgorithmChargingHistories = new JArrayList<>(list);
|
|
|
+ JList<DeviceAlgorithmChargingHistory> infs = new JArrayList<>();
|
|
|
JList<DeviceAlgorithmChargingHistory> gives = new JArrayList<>();
|
|
|
LocalDateTime now = LocalDateTime.now();
|
|
|
//获取算法包月字典
|
|
|
- Map<String, SysDictRedis> algorithmMoonConfigMaps = SysDictUtils.get(EnumAlgorithmMoonConfig.Code.CODE.getCode());
|
|
|
- //处理购买
|
|
|
+ Map<String, SysDictRedis> algorithmMoonConfigMaps = SysDictUtils.get(EnumAlgorithmPayConfig.Code.CODE.getCode());
|
|
|
+ //获取类型字典
|
|
|
+ Map<String, SysDictRedis> deviceAlgorithmChargingTypeMaps = SysDictUtils.get(EnumDeviceAlgorithmChargingType.Code.CODE.getCode());
|
|
|
+ //处理有效期
|
|
|
deviceAlgorithmChargingHistories.forEach(deviceAlgorithmChargingHistory -> {
|
|
|
- Integer chargingType = deviceAlgorithmChargingHistory.getChargingType();
|
|
|
- if (chargingType == give) {
|
|
|
+ Integer type = deviceAlgorithmChargingHistory.getType();
|
|
|
+ SysDictRedis deviceAlgorithmChargingType2 = deviceAlgorithmChargingTypeMaps.get(EnumDeviceAlgorithmChargingType.N_2.getCode());
|
|
|
+ if (type.equals(Integer.valueOf(deviceAlgorithmChargingType2.getValue()))) {
|
|
|
+ infs.add(deviceAlgorithmChargingHistory);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ SysDictRedis deviceAlgorithmChargingType3 = deviceAlgorithmChargingTypeMaps.get(EnumDeviceAlgorithmChargingType.N_3.getCode());
|
|
|
+ if (type.equals(Integer.valueOf(deviceAlgorithmChargingType3.getValue()))) {
|
|
|
gives.add(deviceAlgorithmChargingHistory);
|
|
|
return;
|
|
|
}
|
|
|
- SysDictRedis sysDictRedis = algorithmMoonConfigMaps.get(deviceAlgorithmChargingHistory.getAlgorithmId().toString());
|
|
|
- DeviceAlgorithmChargingDto.AlgorithmMoonConfig algorithmMoonConfig = JSONUtil.parseObj(sysDictRedis.getValue()).toBean(DeviceAlgorithmChargingDto.AlgorithmMoonConfig.class);
|
|
|
+ SysDictRedis algorithmMoonConfigDict = algorithmMoonConfigMaps.get(deviceAlgorithmChargingHistory.getAlgorithmId().toString());
|
|
|
+ DeviceAlgorithmChargingDto.AlgorithmMoonConfig algorithmMoonConfig = JSONUtil.parseObj(algorithmMoonConfigDict.getValue()).toBean(DeviceAlgorithmChargingDto.AlgorithmMoonConfig.class);
|
|
|
+ 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::getIsGive, false)
|
|
|
+ .eq(DeviceAlgorithmCharging::getType, type)
|
|
|
.orderByDesc(DeviceAlgorithmCharging::getTimeout)
|
|
|
.last("limit 1");
|
|
|
DeviceAlgorithmCharging deviceAlgorithmCharging = getOne(lambdaQueryWrapper);
|
|
@@ -113,21 +124,47 @@ public class DeviceAlgorithmChargingServiceImpl extends ServiceImpl<DeviceAlgori
|
|
|
DeviceAlgorithmCharging deviceAlgorithmChargingInfo = new DeviceAlgorithmCharging()
|
|
|
.setDeviceId(deviceAlgorithmChargingHistory.getDeviceId())
|
|
|
.setAlgorithmId(deviceAlgorithmChargingHistory.getAlgorithmId())
|
|
|
- .setUnusedSize(algorithmMoonConfig.getSize())
|
|
|
- .setIsGive(false)
|
|
|
+ .setUnusedSize(moon.getSize())
|
|
|
+ .setType(type)
|
|
|
.setTimeout(timeout)
|
|
|
.setCreateTime(now)
|
|
|
.setUpdateTime(now);
|
|
|
save(deviceAlgorithmChargingInfo);
|
|
|
}
|
|
|
});
|
|
|
+ //处理无期限
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ });
|
|
|
//处理赠送
|
|
|
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::getIsGive, true)
|
|
|
+ .eq(DeviceAlgorithmCharging::getType, deviceAlgorithmChargingHistory.getType())
|
|
|
.eq(DeviceAlgorithmCharging::getTimeout, timeout);
|
|
|
DeviceAlgorithmCharging deviceAlgorithmCharging = getOne(lambdaQueryWrapper);
|
|
|
if (deviceAlgorithmCharging == null) {
|
|
@@ -135,7 +172,7 @@ public class DeviceAlgorithmChargingServiceImpl extends ServiceImpl<DeviceAlgori
|
|
|
.setDeviceId(deviceAlgorithmChargingHistory.getDeviceId())
|
|
|
.setAlgorithmId(deviceAlgorithmChargingHistory.getAlgorithmId())
|
|
|
.setUnusedSize(deviceAlgorithmChargingHistory.getChargingSize())
|
|
|
- .setIsGive(true)
|
|
|
+ .setType(deviceAlgorithmChargingHistory.getType())
|
|
|
.setTimeout(timeout)
|
|
|
.setCreateTime(now)
|
|
|
.setUpdateTime(now);
|