Browse Source

#MOD b端设备列表反显锁机状态

谭斌 2 years ago
parent
commit
3258ad1965

+ 23 - 16
device-api-service/src/main/java/com/xy/service/DeviceInfoServiceImpl.java

@@ -6,6 +6,7 @@ import cn.hutool.core.collection.ListUtil;
 import cn.hutool.core.date.DatePattern;
 import cn.hutool.core.date.DateTime;
 import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.map.MapUtil;
 import cn.hutool.core.text.StrBuilder;
 import cn.hutool.core.util.BooleanUtil;
 import cn.hutool.core.util.NumberUtil;
@@ -670,7 +671,7 @@ public class DeviceInfoServiceImpl extends ServiceImpl<DeviceInfoMapper, DeviceI
         //小程序独有查询字段 缺货状态:stockStatus ,是否查故障设备:fault
         Boolean fault = page.getFault();
         Long mercId = page.getMercId();
-        List<Long> myDeviceIds = page.getDeviceIdList();
+        List<Long> myDeviceIds = page.getMyDeviceIds();
         if (CollUtil.isEmpty(myDeviceIds)) {
             //无设备
             return R.ok(pageData);
@@ -695,27 +696,33 @@ public class DeviceInfoServiceImpl extends ServiceImpl<DeviceInfoMapper, DeviceI
             return R.ok(pageData);
         }
         List<DeviceInfoDto.MerHomeSearchVO> merHomeSearchRecords = new ArrayList<>();
-        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);
+
         BeanUtil.copyProperties(pageBean, pageData);
-        List<DeviceDataDto.Vo> deviceDataList = deviceDataService.list(dto);
-        if (CollUtil.isNotEmpty(deviceDataList)) {
+        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);
+            Map<Long, DeviceDataDto.Vo> dataMap = MapUtil.newHashMap();
             //统计数据反显
-            Map<Long, DeviceDataDto.Vo> dataMap = deviceDataList.stream().collect(Collectors.toMap(DeviceDataDto.Vo::getDeviceId, d -> d));
-            records.forEach(v -> {
+            if (CollUtil.isNotEmpty(deviceDataList)) {
+                dataMap = deviceDataList.stream().collect(Collectors.toMap(DeviceDataDto.Vo::getDeviceId, d -> d));
+            }
+            for (DeviceInfoDto.Vo2 v : records) {
                 DeviceInfoDto.MerHomeSearchVO merHomeSearchVO = new DeviceInfoDto.MerHomeSearchVO();
                 Long deviceId = v.getDeviceId();
                 DeviceDataDto.Vo vo = dataMap.get(deviceId);
-                //今日订单数
-                v.setDayOrderNum(vo != null ? vo.getSalesCount() : 0);
-                v.setDaySalesPrice(vo != null ? vo.getSalesMoney() : 0);
+                if (vo != null) {
+                    //今日订单数
+                    v.setDayOrderNum(vo != null ? vo.getSalesCount() : 0);
+                    v.setDaySalesPrice(vo != null ? vo.getSalesMoney() : 0);
+                    BeanUtil.copyProperties(vo, merHomeSearchVO);
+                }
                 DeviceSysinfoDto.Vo deviceSysinfo = v.getDeviceSysinfo();
                 DeviceStatusDto.Vo deviceStatus = v.getDeviceStatus();
-                BeanUtil.copyProperties(vo, merHomeSearchVO);
                 merHomeSearchVO.setAppUpmVersion(deviceSysinfo.getAppUpmVersion());
                 merHomeSearchVO.setTempValue(deviceStatus.getTempValue());
                 merHomeSearchVO.setNetDbm(deviceStatus.getNetDbm());
@@ -728,7 +735,7 @@ public class DeviceInfoServiceImpl extends ServiceImpl<DeviceInfoMapper, DeviceI
                 merHomeSearchVO.setDeviceStateRName(deviceLockStateR == null ? "未知" : deviceLockStateR.getDescription());
                 merHomeSearchVO.setDeviceStateLName(deviceLockStateL == null ? "未知" : deviceLockStateL.getDescription());
                 merHomeSearchRecords.add(merHomeSearchVO);
-            });
+            }
             pageData.setRecords(merHomeSearchRecords);
         }
         return R.ok(pageData);

+ 1 - 1
device-api-service/src/main/resources/mapper/DeviceInfoMapper.xml

@@ -164,7 +164,7 @@
             and LOCATE(#{queryPage.deviceId}, info.device_id) > 0
         </if>
         <if test="queryPage.deviceIdList != null">
-            and device_id IN
+            and info.device_id IN
             <foreach collection="queryPage.deviceIdList" item="deviceId" open="(" close=")" separator=",">
                 #{deviceId}
             </foreach>