|
@@ -2,6 +2,8 @@ package com.xy.service;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.date.DatePattern;
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.text.StrBuilder;
|
|
|
import cn.hutool.core.util.BooleanUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
@@ -15,10 +17,7 @@ import com.xy.collections.list.JArrayList;
|
|
|
import com.xy.collections.list.JList;
|
|
|
import com.xy.config.DeviceThreadPoolConfig;
|
|
|
import com.xy.consts.DictConsts;
|
|
|
-import com.xy.dto.DeviceInfoDto;
|
|
|
-import com.xy.dto.DeviceRegisterDto;
|
|
|
-import com.xy.dto.DeviceStatusDto;
|
|
|
-import com.xy.dto.DeviceSysinfoDto;
|
|
|
+import com.xy.dto.*;
|
|
|
import com.xy.entity.DeviceErrorsRecord;
|
|
|
import com.xy.entity.DeviceInfo;
|
|
|
import com.xy.entity.DeviceStatus;
|
|
@@ -43,10 +42,7 @@ import org.springframework.web.bind.annotation.RequestBody;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import javax.validation.Valid;
|
|
|
import java.io.IOException;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Collections;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import static com.xy.utils.PlusBeans.*;
|
|
@@ -71,6 +67,7 @@ public class DeviceInfoServiceImpl extends ServiceImpl<DeviceInfoMapper, DeviceI
|
|
|
private final DeviceRegisterServiceImpl deviceRegisterService;
|
|
|
|
|
|
private final DeviceErrorsRecordServiceImpl deviceErrorsRecordService;
|
|
|
+ private final DeviceDataServiceImpl deviceDataService;
|
|
|
|
|
|
private final RedisService<String> redisService;
|
|
|
|
|
@@ -437,7 +434,7 @@ public class DeviceInfoServiceImpl extends ServiceImpl<DeviceInfoMapper, DeviceI
|
|
|
return R.ok(Collections.emptyList());
|
|
|
}
|
|
|
List<DeviceInfoDto.MercHomeListVO> dataList = new ArrayList<>(list.size());
|
|
|
- //获取通条件设备信息
|
|
|
+
|
|
|
LambdaQueryWrapper<DeviceInfo> lqw = new LambdaQueryWrapper<>();
|
|
|
lqw.eq(mercId != null, DeviceInfo::getMercId, mercId);
|
|
|
lqw.eq(deviceId != null, DeviceInfo::getDeviceId, deviceId);
|
|
@@ -455,17 +452,44 @@ public class DeviceInfoServiceImpl extends ServiceImpl<DeviceInfoMapper, DeviceI
|
|
|
//线路下的设备列表
|
|
|
List<DeviceInfoDto.MercHomeDeviceVo> deviceInfos = Beans.copy(DeviceInfoDto.MercHomeDeviceVo.class, deviceMap.get(placeLineId));
|
|
|
|
|
|
+ //设备销售统计
|
|
|
+ String type = SysDictUtils.getValue(DictEnum.DEVICE_DATA_TYPE.getKey(), DictSonEnum.DEVICE_DATA_TYPE_DAY.getKey(), String.class);
|
|
|
+ String todayDate = DateUtil.format(new Date(), DatePattern.PURE_DATE_PATTERN);
|
|
|
+ List<Long> deviceIds = deviceInfos.stream().map(DeviceInfoDto.MercHomeDeviceVo::getDeviceId).collect(Collectors.toList());
|
|
|
+ //统计条件:当天
|
|
|
+ DeviceDataDto.ListDTO deviceDataListDTO = new DeviceDataDto.ListDTO()
|
|
|
+ .setDeviceIds(deviceIds).setType(type).setDateValue(Integer.valueOf(todayDate)).setMercId(mercId);
|
|
|
+ List<DeviceDataDto.Vo> deviceDataList = deviceDataService.list(deviceDataListDTO);
|
|
|
+ Map<Long, DeviceDataDto.Vo> dataMap = new HashMap<>();
|
|
|
+ if (CollUtil.isNotEmpty(deviceDataList)) {
|
|
|
+ dataMap = deviceDataList.stream().collect(Collectors.toMap(DeviceDataDto.Vo::getDeviceId, d -> d));
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //设备状态查询
|
|
|
+ List<DeviceStatusDto.Vo> deviceStatusList = deviceStatusService.list(new DeviceStatusDto.SelectList().setDeviceIds(deviceIds)).getData();
|
|
|
+ Map<Long, DeviceStatusDto.Vo> datdeviceStatusMap = new HashMap<>();
|
|
|
+ if (CollUtil.isNotEmpty(deviceStatusList)) {
|
|
|
+ datdeviceStatusMap = deviceStatusList.stream().collect(Collectors.toMap(DeviceStatusDto.Vo::getDeviceId, d -> d));
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<Long, DeviceDataDto.Vo> finalDataMap = dataMap;
|
|
|
+ Map<Long, DeviceStatusDto.Vo> finalDatdeviceStatusMap = datdeviceStatusMap;
|
|
|
deviceInfos.forEach(device -> {
|
|
|
+ Long dId = device.getDeviceId();
|
|
|
//设备类型 反显
|
|
|
SysDictRedis dictDeviceType = SysDictUtils.get(DictConsts.DEVICE_TYPE, String.valueOf(device.getDeviceType()));
|
|
|
device.setDeviceTypeName(dictDeviceType.getMsg());
|
|
|
//运营状态 反显
|
|
|
SysDictRedis dictBusyState = SysDictUtils.get(DictConsts.DEVICE_BUSY_STATUS, String.valueOf(device.getBusyState()));
|
|
|
device.setBusyStateName(dictBusyState.getMsg());
|
|
|
- //初始化数字
|
|
|
- device.setDayOrderNum(0).setOnSaleNum(0).setFillNum(0).setDaySalesPrice("0");
|
|
|
- //TODO: 数字统计
|
|
|
- //可售库存
|
|
|
+ DeviceDataDto.Vo deviceData = finalDataMap.get(dId);
|
|
|
+ //今日销售、库存情况 反显
|
|
|
+ device.setDayOrderNum(deviceData != null ? deviceData.getSalesCount() : 0);
|
|
|
+ device.setDaySalesPrice(deviceData != null ? deviceData.getSalesMoney() : 0);
|
|
|
+ DeviceStatusDto.Vo deviceStatus = finalDatdeviceStatusMap.get(deviceId);
|
|
|
+ device.setOnSaleNum(deviceStatus != null ? deviceStatus.getStock() : 0);
|
|
|
+ device.setFillNum(deviceStatus != null ? deviceStatus.getAfterFillStock() : 0);
|
|
|
|
|
|
});
|
|
|
vo.setDeviceInfos(deviceInfos);
|
|
@@ -501,9 +525,35 @@ public class DeviceInfoServiceImpl extends ServiceImpl<DeviceInfoMapper, DeviceI
|
|
|
return R.ok(new PageBean<>());
|
|
|
}
|
|
|
page.setDeviceIdList(deviceIdList);
|
|
|
-
|
|
|
}
|
|
|
+
|
|
|
PageBean<DeviceInfoDto.Vo2> pageBean = queryPage(page);
|
|
|
+ List<DeviceInfoDto.Vo2> records = pageBean.getRecords();
|
|
|
+ if (CollUtil.isNotEmpty(records)) {
|
|
|
+ List<Long> deviceIds = records.stream().map(DeviceInfoDto.Vo2::getDeviceId).collect(Collectors.toList());
|
|
|
+
|
|
|
+
|
|
|
+ String type = SysDictUtils.getValue(DictEnum.DEVICE_DATA_TYPE.getKey(), DictSonEnum.DEVICE_DATA_TYPE_DAY.getKey(), String.class);
|
|
|
+ String todayDate = DateUtil.format(new Date(), DatePattern.PURE_DATE_PATTERN);
|
|
|
+ //查询当天
|
|
|
+ DeviceDataDto.ListDTO dto = new DeviceDataDto.ListDTO()
|
|
|
+ .setDeviceIds(deviceIds).setType(type).setDateValue(Integer.valueOf(todayDate)).setMercId(mercId);
|
|
|
+ List<DeviceDataDto.Vo> deviceDataList = deviceDataService.list(dto);
|
|
|
+ if (CollUtil.isNotEmpty(deviceDataList)) {
|
|
|
+ //统计数据反显
|
|
|
+ Map<Long, DeviceDataDto.Vo> dataMap = deviceDataList.stream().collect(Collectors.toMap(DeviceDataDto.Vo::getDeviceId, d -> d));
|
|
|
+ records.forEach(v -> {
|
|
|
+ Long deviceId = v.getDeviceId();
|
|
|
+ DeviceDataDto.Vo vo = dataMap.get(deviceId);
|
|
|
+ //今日订单数
|
|
|
+ v.setDayOrderNum(vo != null ? vo.getSalesCount() : 0);
|
|
|
+ v.setDaySalesPrice(vo != null ? vo.getSalesMoney() : 0);
|
|
|
+ });
|
|
|
+ pageBean.setRecords(records);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
return R.ok(pageBean);
|
|
|
}
|
|
|
|