|
@@ -2,7 +2,10 @@ package com.xy.service;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
import cn.hutool.core.collection.CollUtil;
|
|
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.text.StrBuilder;
|
|
|
|
+import cn.hutool.core.util.BooleanUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
@@ -14,10 +17,8 @@ import com.xy.collections.list.JArrayList;
|
|
import com.xy.collections.list.JList;
|
|
import com.xy.collections.list.JList;
|
|
import com.xy.config.DeviceThreadPoolConfig;
|
|
import com.xy.config.DeviceThreadPoolConfig;
|
|
import com.xy.consts.DictConsts;
|
|
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.DeviceInfo;
|
|
import com.xy.entity.DeviceStatus;
|
|
import com.xy.entity.DeviceStatus;
|
|
import com.xy.entity.SysDictRedis;
|
|
import com.xy.entity.SysDictRedis;
|
|
@@ -41,10 +42,7 @@ import org.springframework.web.bind.annotation.RequestBody;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.validation.Valid;
|
|
import javax.validation.Valid;
|
|
import java.io.IOException;
|
|
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 java.util.stream.Collectors;
|
|
|
|
|
|
import static com.xy.utils.PlusBeans.*;
|
|
import static com.xy.utils.PlusBeans.*;
|
|
@@ -68,6 +66,9 @@ public class DeviceInfoServiceImpl extends ServiceImpl<DeviceInfoMapper, DeviceI
|
|
|
|
|
|
private final DeviceRegisterServiceImpl deviceRegisterService;
|
|
private final DeviceRegisterServiceImpl deviceRegisterService;
|
|
|
|
|
|
|
|
+ private final DeviceErrorsRecordServiceImpl deviceErrorsRecordService;
|
|
|
|
+ private final DeviceDataServiceImpl deviceDataService;
|
|
|
|
+
|
|
private final RedisService<String> redisService;
|
|
private final RedisService<String> redisService;
|
|
|
|
|
|
private final String keyPrefix = "device:history:";
|
|
private final String keyPrefix = "device:history:";
|
|
@@ -251,6 +252,7 @@ public class DeviceInfoServiceImpl extends ServiceImpl<DeviceInfoMapper, DeviceI
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
public R<Boolean> mercDeviceAuth(DeviceInfoDto.MercDeviceAuthDto auth) {
|
|
public R<Boolean> mercDeviceAuth(DeviceInfoDto.MercDeviceAuthDto auth) {
|
|
Long mercId = auth.getMercId();
|
|
Long mercId = auth.getMercId();
|
|
|
|
+ Long parentId = auth.getParentId();
|
|
String mercCode = auth.getMercCode();
|
|
String mercCode = auth.getMercCode();
|
|
Long algorithmId = auth.getAlgorithmId();
|
|
Long algorithmId = auth.getAlgorithmId();
|
|
String mercName = auth.getMercName();
|
|
String mercName = auth.getMercName();
|
|
@@ -262,7 +264,7 @@ public class DeviceInfoServiceImpl extends ServiceImpl<DeviceInfoMapper, DeviceI
|
|
if (CollUtil.isEmpty(devices)) {
|
|
if (CollUtil.isEmpty(devices)) {
|
|
return R.ok(Boolean.TRUE);
|
|
return R.ok(Boolean.TRUE);
|
|
}
|
|
}
|
|
- return R.ok(removeMerRefDevices(devices));
|
|
|
|
|
|
+ return R.ok(removeMerRefDevices(devices, parentId));
|
|
}
|
|
}
|
|
//更新商户设备授权
|
|
//更新商户设备授权
|
|
List<DeviceInfo> deviceInfos = this.listByIds(deviceIds);
|
|
List<DeviceInfo> deviceInfos = this.listByIds(deviceIds);
|
|
@@ -298,7 +300,7 @@ public class DeviceInfoServiceImpl extends ServiceImpl<DeviceInfoMapper, DeviceI
|
|
});
|
|
});
|
|
if (CollUtil.isNotEmpty(removeIds)) {
|
|
if (CollUtil.isNotEmpty(removeIds)) {
|
|
List<DeviceInfo> removeList = this.listByIds(removeIds);
|
|
List<DeviceInfo> removeList = this.listByIds(removeIds);
|
|
- removeMerRefDevices(removeList);
|
|
|
|
|
|
+ removeMerRefDevices(removeList, parentId);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return R.ok(Boolean.TRUE);
|
|
return R.ok(Boolean.TRUE);
|
|
@@ -310,10 +312,18 @@ public class DeviceInfoServiceImpl extends ServiceImpl<DeviceInfoMapper, DeviceI
|
|
* @param deviceInfos
|
|
* @param deviceInfos
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- private Boolean removeMerRefDevices(List<DeviceInfo> deviceInfos) {
|
|
|
|
|
|
+ private Boolean removeMerRefDevices(List<DeviceInfo> deviceInfos, Long parentId) {
|
|
deviceInfos.forEach(deviceInfo -> {
|
|
deviceInfos.forEach(deviceInfo -> {
|
|
- //-1 释放关系
|
|
|
|
- deviceInfo.setMercId(-1L);
|
|
|
|
|
|
+ //非顶级兴元商户,解绑后,机器归父商户
|
|
|
|
+ if (parentId != 1) {
|
|
|
|
+ deviceInfo.setMercId(parentId);
|
|
|
|
+ }
|
|
|
|
+ //一级商户,解绑后,直接释放
|
|
|
|
+ if (parentId == 0) {
|
|
|
|
+ //-1 释放关系
|
|
|
|
+ deviceInfo.setMercId(-1L);
|
|
|
|
+ }
|
|
|
|
+
|
|
deviceInfo.setMercName(StrUtil.EMPTY);
|
|
deviceInfo.setMercName(StrUtil.EMPTY);
|
|
deviceInfo.setMercCode(StrUtil.EMPTY);
|
|
deviceInfo.setMercCode(StrUtil.EMPTY);
|
|
});
|
|
});
|
|
@@ -330,6 +340,7 @@ public class DeviceInfoServiceImpl extends ServiceImpl<DeviceInfoMapper, DeviceI
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
|
+ @ApiOperation("通用集合查询")
|
|
public R<List<DeviceInfoDto.Vo>> listCommon(DeviceInfoDto.ListCommon dto) {
|
|
public R<List<DeviceInfoDto.Vo>> listCommon(DeviceInfoDto.ListCommon dto) {
|
|
String deviceSearch = dto.getDeviceSearch();
|
|
String deviceSearch = dto.getDeviceSearch();
|
|
QueryWrapper<DeviceInfo> queryWrapper = new MybatisPlusQuery().eqWrapper(dto.getVo(), DeviceInfo.class).buildQW();
|
|
QueryWrapper<DeviceInfo> queryWrapper = new MybatisPlusQuery().eqWrapper(dto.getVo(), DeviceInfo.class).buildQW();
|
|
@@ -337,19 +348,19 @@ public class DeviceInfoServiceImpl extends ServiceImpl<DeviceInfoMapper, DeviceI
|
|
List<Long> deviceIds = dto.getDeviceIds();
|
|
List<Long> deviceIds = dto.getDeviceIds();
|
|
List<String> columnList = dto.getColumnList();
|
|
List<String> columnList = dto.getColumnList();
|
|
if (CollUtil.isNotEmpty(placeLineIds)) {
|
|
if (CollUtil.isNotEmpty(placeLineIds)) {
|
|
- queryWrapper.eq(LambdaUtils.getProperty(DeviceInfo::getPlaceLineId), placeLineIds);
|
|
|
|
|
|
+ queryWrapper.in(LambdaUtils.getUnderlineCaseName(DeviceInfo::getPlaceLineId), placeLineIds);
|
|
}
|
|
}
|
|
|
|
|
|
if (StrUtil.isNotEmpty(deviceSearch)) {
|
|
if (StrUtil.isNotEmpty(deviceSearch)) {
|
|
- queryWrapper.and(wrapper -> wrapper.likeRight(LambdaUtils.getProperty(DeviceInfo::getDeviceName), deviceSearch).or()
|
|
|
|
- .eq(LambdaUtils.getProperty(DeviceInfo::getMercDeviceCode), deviceSearch));
|
|
|
|
|
|
+ queryWrapper.and(wrapper -> wrapper.likeRight(LambdaUtils.getUnderlineCaseName(DeviceInfo::getDeviceName), deviceSearch).or()
|
|
|
|
+ .eq(LambdaUtils.getUnderlineCaseName(DeviceInfo::getMercDeviceCode), deviceSearch));
|
|
}
|
|
}
|
|
|
|
|
|
if (CollUtil.isNotEmpty(columnList)) {
|
|
if (CollUtil.isNotEmpty(columnList)) {
|
|
queryWrapper.select(columnList.stream().toArray(String[]::new));
|
|
queryWrapper.select(columnList.stream().toArray(String[]::new));
|
|
}
|
|
}
|
|
if (CollUtil.isNotEmpty(deviceIds)) {
|
|
if (CollUtil.isNotEmpty(deviceIds)) {
|
|
- queryWrapper.eq(LambdaUtils.getProperty(DeviceInfo::getDeviceId), deviceIds);
|
|
|
|
|
|
+ queryWrapper.eq(LambdaUtils.getUnderlineCaseName(DeviceInfo::getDeviceId), deviceIds);
|
|
}
|
|
}
|
|
return R.ok(copy(DeviceInfoDto.Vo.class, list(queryWrapper)));
|
|
return R.ok(copy(DeviceInfoDto.Vo.class, list(queryWrapper)));
|
|
}
|
|
}
|
|
@@ -423,7 +434,7 @@ public class DeviceInfoServiceImpl extends ServiceImpl<DeviceInfoMapper, DeviceI
|
|
return R.ok(Collections.emptyList());
|
|
return R.ok(Collections.emptyList());
|
|
}
|
|
}
|
|
List<DeviceInfoDto.MercHomeListVO> dataList = new ArrayList<>(list.size());
|
|
List<DeviceInfoDto.MercHomeListVO> dataList = new ArrayList<>(list.size());
|
|
- //获取通条件设备信息
|
|
|
|
|
|
+
|
|
LambdaQueryWrapper<DeviceInfo> lqw = new LambdaQueryWrapper<>();
|
|
LambdaQueryWrapper<DeviceInfo> lqw = new LambdaQueryWrapper<>();
|
|
lqw.eq(mercId != null, DeviceInfo::getMercId, mercId);
|
|
lqw.eq(mercId != null, DeviceInfo::getMercId, mercId);
|
|
lqw.eq(deviceId != null, DeviceInfo::getDeviceId, deviceId);
|
|
lqw.eq(deviceId != null, DeviceInfo::getDeviceId, deviceId);
|
|
@@ -440,21 +451,45 @@ public class DeviceInfoServiceImpl extends ServiceImpl<DeviceInfoMapper, DeviceI
|
|
vo.setPlaceLineId(v.getPlaceLineId());
|
|
vo.setPlaceLineId(v.getPlaceLineId());
|
|
//线路下的设备列表
|
|
//线路下的设备列表
|
|
List<DeviceInfoDto.MercHomeDeviceVo> deviceInfos = Beans.copy(DeviceInfoDto.MercHomeDeviceVo.class, deviceMap.get(placeLineId));
|
|
List<DeviceInfoDto.MercHomeDeviceVo> deviceInfos = Beans.copy(DeviceInfoDto.MercHomeDeviceVo.class, deviceMap.get(placeLineId));
|
|
-// deviceInfos.stream().map(DeviceInfoDto.MercHomeDeviceVo::getDeviceId);
|
|
|
|
- //状态信息
|
|
|
|
-// DeviceStatusDto.Vo deviceStatus = deviceStatusService.obj(new DeviceStatusDto.Vo().setDeviceId(deviceInfo.getDeviceId())).getData();
|
|
|
|
-// deviceStatusService.listByIds()
|
|
|
|
|
|
+
|
|
|
|
+ //设备销售统计
|
|
|
|
+ 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 -> {
|
|
deviceInfos.forEach(device -> {
|
|
|
|
+ Long dId = device.getDeviceId();
|
|
//设备类型 反显
|
|
//设备类型 反显
|
|
SysDictRedis dictDeviceType = SysDictUtils.get(DictConsts.DEVICE_TYPE, String.valueOf(device.getDeviceType()));
|
|
SysDictRedis dictDeviceType = SysDictUtils.get(DictConsts.DEVICE_TYPE, String.valueOf(device.getDeviceType()));
|
|
device.setDeviceTypeName(dictDeviceType.getMsg());
|
|
device.setDeviceTypeName(dictDeviceType.getMsg());
|
|
//运营状态 反显
|
|
//运营状态 反显
|
|
SysDictRedis dictBusyState = SysDictUtils.get(DictConsts.DEVICE_BUSY_STATUS, String.valueOf(device.getBusyState()));
|
|
SysDictRedis dictBusyState = SysDictUtils.get(DictConsts.DEVICE_BUSY_STATUS, String.valueOf(device.getBusyState()));
|
|
device.setBusyStateName(dictBusyState.getMsg());
|
|
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);
|
|
vo.setDeviceInfos(deviceInfos);
|
|
@@ -474,6 +509,55 @@ public class DeviceInfoServiceImpl extends ServiceImpl<DeviceInfoMapper, DeviceI
|
|
return list(Wrappers.<DeviceInfo>lambdaQuery().eq(DeviceInfo::getMercId, mercId));
|
|
return list(Wrappers.<DeviceInfo>lambdaQuery().eq(DeviceInfo::getMercId, mercId));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+ @ApiOperation("小程序商户设备搜索")
|
|
|
|
+ @Override
|
|
|
|
+ public R<PageBean<DeviceInfoDto.Vo2>> mercDeviceSearchPage(@RequestBody DeviceInfoDto.Page page) {
|
|
|
|
+ //小程序独有查询字段 缺货状态:stockStatus ,是否查故障设备:fault
|
|
|
|
+ Boolean fault = page.getFault();
|
|
|
|
+ Long mercId = page.getMercId();
|
|
|
|
+ if (BooleanUtil.isTrue(fault)) {
|
|
|
|
+ //查询故障设备
|
|
|
|
+ List<DeviceErrorsRecord> deviceErrorsRecords = deviceErrorsRecordService.list(Wrappers.<DeviceErrorsRecord>lambdaQuery()
|
|
|
|
+ .eq(mercId != null, DeviceErrorsRecord::getMercId, page.getMercId()));
|
|
|
|
+ List<Long> deviceIdList = deviceErrorsRecords.stream().map(DeviceErrorsRecord::getDeviceId).collect(Collectors.toList());
|
|
|
|
+ if (CollUtil.isEmpty(deviceIdList)) {
|
|
|
|
+ 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);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
private PageBean<DeviceInfoDto.Vo2> queryPage(DeviceInfoDto.Page page) {
|
|
private PageBean<DeviceInfoDto.Vo2> queryPage(DeviceInfoDto.Page page) {
|
|
IPage<DeviceInfoQueryPage> iPage = baseMapper.queryPage(toIPage(page.getPage()), page);
|
|
IPage<DeviceInfoQueryPage> iPage = baseMapper.queryPage(toIPage(page.getPage()), page);
|
|
return toPageBean(DeviceInfoDto.Vo2.class, iPage);
|
|
return toPageBean(DeviceInfoDto.Vo2.class, iPage);
|