|
@@ -17,7 +17,10 @@ import com.xy.device.EnumDeviceAlgorithmChargingType;
|
|
import com.xy.device.EnumDeviceType;
|
|
import com.xy.device.EnumDeviceType;
|
|
import com.xy.dto.*;
|
|
import com.xy.dto.*;
|
|
import com.xy.dto.be.MercDto;
|
|
import com.xy.dto.be.MercDto;
|
|
-import com.xy.entity.*;
|
|
|
|
|
|
+import com.xy.entity.DeviceAlgorithmCharging;
|
|
|
|
+import com.xy.entity.DeviceAlgorithmChargingHistory;
|
|
|
|
+import com.xy.entity.DeviceInfo;
|
|
|
|
+import com.xy.entity.SysDictRedis;
|
|
import com.xy.mapper.DeviceAlgorithmChargingMapper;
|
|
import com.xy.mapper.DeviceAlgorithmChargingMapper;
|
|
import com.xy.mapper.entity.DeviceAlgorithmChargingChargingQueryParams;
|
|
import com.xy.mapper.entity.DeviceAlgorithmChargingChargingQueryParams;
|
|
import com.xy.service.be.MercService;
|
|
import com.xy.service.be.MercService;
|
|
@@ -32,7 +35,6 @@ import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
|
-import javax.validation.constraints.NotEmpty;
|
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
@@ -65,42 +67,85 @@ public class DeviceAlgorithmChargingServiceImpl extends ServiceImpl<DeviceAlgori
|
|
|
|
|
|
private AlipayDeviceService alipayDeviceService;
|
|
private AlipayDeviceService alipayDeviceService;
|
|
|
|
|
|
|
|
+ private MercDeviceAlgorithmChargingService mercDeviceAlgorithmChargingService;
|
|
|
|
+
|
|
@PostMapping("count")
|
|
@PostMapping("count")
|
|
@ApiOperation("查询条数")
|
|
@ApiOperation("查询条数")
|
|
public R<List<DeviceAlgorithmChargingDto.CountVo>> count(@RequestBody @Validated DeviceAlgorithmChargingDto.Count count) {
|
|
public R<List<DeviceAlgorithmChargingDto.CountVo>> count(@RequestBody @Validated DeviceAlgorithmChargingDto.Count count) {
|
|
|
|
+ MercDto.Vo merc = mercService.obj(new MercDto.Vo().setId(count.getMercId())).getData();
|
|
//默认值
|
|
//默认值
|
|
- List<Long> deviceIds = count.getDeviceIds();
|
|
|
|
|
|
+ JList<Long> deviceIds = new JArrayList<>(count.getDeviceIds());
|
|
JList<DeviceAlgorithmChargingDto.CountVo> countVos = new JArrayList<>(deviceIds.size());
|
|
JList<DeviceAlgorithmChargingDto.CountVo> countVos = new JArrayList<>(deviceIds.size());
|
|
deviceIds.forEach(deviceId -> {
|
|
deviceIds.forEach(deviceId -> {
|
|
DeviceAlgorithmChargingDto.CountVo countVo = new DeviceAlgorithmChargingDto.CountVo()
|
|
DeviceAlgorithmChargingDto.CountVo countVo = new DeviceAlgorithmChargingDto.CountVo()
|
|
.setDeviceId(deviceId)
|
|
.setDeviceId(deviceId)
|
|
- .setCount(0)
|
|
|
|
- .setSize(0)
|
|
|
|
|
|
+ .setUnusedCount(0)
|
|
|
|
+ .setUnusedSize(0)
|
|
|
|
+ .setMakeSize(0)
|
|
.setArrearageBalance(0);
|
|
.setArrearageBalance(0);
|
|
countVos.add(countVo);
|
|
countVos.add(countVo);
|
|
});
|
|
});
|
|
JMap<Long, DeviceAlgorithmChargingDto.CountVo> cover = countVos.toMap(DeviceAlgorithmChargingDto.CountVo::getDeviceId).cover();
|
|
JMap<Long, DeviceAlgorithmChargingDto.CountVo> cover = countVos.toMap(DeviceAlgorithmChargingDto.CountVo::getDeviceId).cover();
|
|
- //查询数据
|
|
|
|
|
|
+ //查询全部
|
|
|
|
+ JList<JList<Long>> partition = deviceIds.partition(100);
|
|
|
|
+ JList<DeviceAlgorithmCharging> deviceAlgorithmChargings = new JArrayList<>();
|
|
|
|
+ partition.forEach(longs -> {
|
|
|
|
+ List<DeviceAlgorithmCharging> list = list(new LambdaQueryWrapper<DeviceAlgorithmCharging>()
|
|
|
|
+ .select(DeviceAlgorithmCharging::getDeviceId, DeviceAlgorithmCharging::getMakeSize, DeviceAlgorithmCharging::getUnusedSize, DeviceAlgorithmCharging::getTimeout, DeviceAlgorithmCharging::getBeginTime)
|
|
|
|
+ .in(DeviceAlgorithmCharging::getDeviceId, longs)
|
|
|
|
+ .eq(DeviceAlgorithmCharging::getMercCode, merc.getMercCode())
|
|
|
|
+ );
|
|
|
|
+ deviceAlgorithmChargings.addAll(list);
|
|
|
|
+ });
|
|
|
|
+ JMap<Long, List<DeviceAlgorithmCharging>> allGroup = deviceAlgorithmChargings.toMap(DeviceAlgorithmCharging::getDeviceId).group();
|
|
|
|
+ //查询未使用
|
|
String thisTime = DataTime.getSring("yyyyMMdd");
|
|
String thisTime = DataTime.getSring("yyyyMMdd");
|
|
- List<DeviceAlgorithmCharging> list = list(new LambdaQueryWrapper<DeviceAlgorithmCharging>()
|
|
|
|
- .in(DeviceAlgorithmCharging::getDeviceId, deviceIds)
|
|
|
|
|
|
+ JList<DeviceAlgorithmCharging> unuseds = deviceAlgorithmChargings.filter()
|
|
.gt(DeviceAlgorithmCharging::getUnusedSize, 0)
|
|
.gt(DeviceAlgorithmCharging::getUnusedSize, 0)
|
|
- .and(deviceAlgorithmChargingLambdaQueryWrapper -> deviceAlgorithmChargingLambdaQueryWrapper
|
|
|
|
- .eq(DeviceAlgorithmCharging::getTimeout, -1)
|
|
|
|
- .or()
|
|
|
|
- .ge(DeviceAlgorithmCharging::getTimeout, thisTime)
|
|
|
|
- )
|
|
|
|
|
|
+ .eq(DeviceAlgorithmCharging::getTimeout, -1)
|
|
.le(DeviceAlgorithmCharging::getBeginTime, thisTime)
|
|
.le(DeviceAlgorithmCharging::getBeginTime, thisTime)
|
|
- );
|
|
|
|
- JMap<Long, List<DeviceAlgorithmCharging>> group = new JArrayList<>(list).toMap(DeviceAlgorithmCharging::getDeviceId).group();
|
|
|
|
- group.forEach((deviceId, deviceAlgorithmChargings) -> {
|
|
|
|
- DeviceAlgorithmChargingDto.CountVo countVo = cover.get(deviceId);
|
|
|
|
- countVo.setCount(deviceAlgorithmChargings.size());
|
|
|
|
- int size = 0;
|
|
|
|
- for (DeviceAlgorithmCharging deviceAlgorithmCharging : deviceAlgorithmChargings) {
|
|
|
|
- size += deviceAlgorithmCharging.getUnusedSize();
|
|
|
|
|
|
+ .list();
|
|
|
|
+ JList<DeviceAlgorithmCharging> unuseds2 = deviceAlgorithmChargings.filter()
|
|
|
|
+ .gt(DeviceAlgorithmCharging::getUnusedSize, 0)
|
|
|
|
+ .ge(DeviceAlgorithmCharging::getTimeout, thisTime)
|
|
|
|
+ .le(DeviceAlgorithmCharging::getBeginTime, thisTime)
|
|
|
|
+ .list();
|
|
|
|
+ if (Emptys.check(unuseds2)) {
|
|
|
|
+ unuseds.addAll(unuseds2);
|
|
|
|
+ }
|
|
|
|
+ JMap<Long, List<DeviceAlgorithmCharging>> unusedGroup = unuseds.toMap(DeviceAlgorithmCharging::getDeviceId).group();
|
|
|
|
+ //统计设备欠费金额
|
|
|
|
+ List<MercDeviceAlgorithmChargingDto.CountArrearageBalanceVo> countArrearageBalanceVos = mercDeviceAlgorithmChargingService.countArrearageBalance(new MercDeviceAlgorithmChargingDto.CountArrearageBalance()
|
|
|
|
+ .setDeviceIds(deviceIds)
|
|
|
|
+ .setMercId(merc.getId())
|
|
|
|
+ ).getData();
|
|
|
|
+ JMap<Long, MercDeviceAlgorithmChargingDto.CountArrearageBalanceVo> countArrearageBalanceVosJMaps = new JArrayList<>(countArrearageBalanceVos).toMap(MercDeviceAlgorithmChargingDto.CountArrearageBalanceVo::getDeviceId).cover();
|
|
|
|
+ //封装数据
|
|
|
|
+ cover.forEach((deviceId, countVo) -> {
|
|
|
|
+ //未使用
|
|
|
|
+ List<DeviceAlgorithmCharging> deviceAlgorithmChargings1 = unusedGroup.get(deviceId);
|
|
|
|
+ if (Emptys.check(deviceAlgorithmChargings1)) {
|
|
|
|
+ countVo.setUnusedCount(deviceAlgorithmChargings1.size());
|
|
|
|
+ int unusedSize = 0;
|
|
|
|
+ for (DeviceAlgorithmCharging deviceAlgorithmCharging : deviceAlgorithmChargings1) {
|
|
|
|
+ unusedSize += deviceAlgorithmCharging.getUnusedSize();
|
|
|
|
+ }
|
|
|
|
+ countVo.setUnusedSize(unusedSize);
|
|
|
|
+ }
|
|
|
|
+ //已使用
|
|
|
|
+ List<DeviceAlgorithmCharging> deviceAlgorithmChargings2 = allGroup.get(deviceId);
|
|
|
|
+ if (Emptys.check(deviceAlgorithmChargings2)) {
|
|
|
|
+ int makeSize = 0;
|
|
|
|
+ for (DeviceAlgorithmCharging deviceAlgorithmCharging : deviceAlgorithmChargings2) {
|
|
|
|
+ makeSize += deviceAlgorithmCharging.getMakeSize();
|
|
|
|
+ }
|
|
|
|
+ countVo.setMakeSize(makeSize);
|
|
|
|
+ }
|
|
|
|
+ //欠费金额
|
|
|
|
+ MercDeviceAlgorithmChargingDto.CountArrearageBalanceVo countArrearageBalanceVo = countArrearageBalanceVosJMaps.get(deviceId);
|
|
|
|
+ if (Emptys.check(countArrearageBalanceVo)) {
|
|
|
|
+ countVo.setArrearageBalance(countArrearageBalanceVo.getArrearageBalance());
|
|
}
|
|
}
|
|
- countVo.setSize(size);
|
|
|
|
});
|
|
});
|
|
return R.ok(countVos);
|
|
return R.ok(countVos);
|
|
}
|
|
}
|