DeviceInfoServiceImpl.java 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. package com.xy.service;
  2. import cn.hutool.core.bean.BeanUtil;
  3. import cn.hutool.core.collection.CollUtil;
  4. import cn.hutool.core.util.StrUtil;
  5. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  6. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  7. import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
  8. import com.baomidou.mybatisplus.core.metadata.IPage;
  9. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  10. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  11. import com.xy.collections.list.JArrayList;
  12. import com.xy.collections.list.JList;
  13. import com.xy.config.DeviceThreadPoolConfig;
  14. import com.xy.consts.DictConsts;
  15. import com.xy.dto.DeviceInfoDto;
  16. import com.xy.dto.DeviceRegisterDto;
  17. import com.xy.dto.DeviceStatusDto;
  18. import com.xy.dto.DeviceSysinfoDto;
  19. import com.xy.entity.DeviceInfo;
  20. import com.xy.entity.DeviceStatus;
  21. import com.xy.entity.SysDictRedis;
  22. import com.xy.error.CommRuntimeException;
  23. import com.xy.mapper.DeviceInfoMapper;
  24. import com.xy.mapper.entity.DeviceInfoQueryPage;
  25. import com.xy.util.ExcelUtils;
  26. import com.xy.utils.*;
  27. import com.xy.utils.enums.DictEnum;
  28. import com.xy.utils.enums.DictSonEnum;
  29. import io.swagger.annotations.Api;
  30. import io.swagger.annotations.ApiOperation;
  31. import jodd.introspector.MapperFunction;
  32. import lombok.RequiredArgsConstructor;
  33. import org.springframework.stereotype.Service;
  34. import org.springframework.transaction.annotation.Transactional;
  35. import org.springframework.validation.annotation.Validated;
  36. import org.springframework.web.bind.annotation.PostMapping;
  37. import org.springframework.web.bind.annotation.RequestBody;
  38. import javax.servlet.http.HttpServletResponse;
  39. import javax.validation.Valid;
  40. import java.io.IOException;
  41. import java.util.ArrayList;
  42. import java.util.Collections;
  43. import java.util.List;
  44. import java.util.Map;
  45. import java.util.stream.Collectors;
  46. import static com.xy.utils.PlusBeans.*;
  47. /**
  48. * <p>
  49. * 设备-信息 服务实现类
  50. * </p>
  51. *
  52. * @author lijin
  53. * @since 2022-12-23
  54. */
  55. @Service
  56. @RequiredArgsConstructor
  57. @Api(tags = "设备-信息")
  58. public class DeviceInfoServiceImpl extends ServiceImpl<DeviceInfoMapper, DeviceInfo> implements DeviceInfoService {
  59. private final DeviceSysinfoServiceImpl deviceSysinfoService;
  60. private final DeviceStatusServiceImpl deviceStatusService;
  61. private final DeviceRegisterServiceImpl deviceRegisterService;
  62. private final RedisService<String> redisService;
  63. private final String keyPrefix = "device:history:";
  64. @Override
  65. @ApiOperation("对象查询")
  66. public R<DeviceInfoDto.Vo> obj(DeviceInfoDto.Obj obj) {
  67. //设备信息
  68. LambdaQueryWrapper<DeviceInfo> lambdaQueryWrapper = new MybatisPlusQuery().eqWrapper(obj, DeviceInfo.class).build();
  69. List<DeviceInfo> list = list(lambdaQueryWrapper);
  70. if (!Emptys.check(list)) {
  71. return R.ok();
  72. }
  73. DeviceInfoDto.Vo deviceInfo = copy(DeviceInfoDto.Vo.class, list.get(0));
  74. ThreadPoolUtils.excPoll(DeviceThreadPoolConfig.DEVICE_COMMON_POLL, 3)
  75. .execute(() -> {
  76. //系统信息
  77. DeviceSysinfoDto.Vo deviceSysinfo = deviceSysinfoService.get(new DeviceSysinfoDto.Vo().setDeviceId(deviceInfo.getDeviceId())).getData();
  78. deviceInfo.setDeviceSysinfo(deviceSysinfo);
  79. })
  80. .execute(() -> {
  81. //状态信息
  82. DeviceStatusDto.Vo deviceStatus = deviceStatusService.obj(new DeviceStatusDto.Vo().setDeviceId(deviceInfo.getDeviceId())).getData();
  83. deviceInfo.setDeviceStatus(deviceStatus);
  84. })
  85. .execute(() -> {
  86. //注册信息
  87. DeviceRegisterDto.Vo deviceRegister = deviceRegisterService.obj(new DeviceRegisterDto.Vo().setDeviceId(deviceInfo.getDeviceId())).getData();
  88. deviceInfo.setDeviceRegister(deviceRegister);
  89. })
  90. .end();
  91. return R.ok(deviceInfo);
  92. }
  93. @Override
  94. @ApiOperation("设备访问历史添加")
  95. public R history(DeviceInfoDto.Obj obj) {
  96. //获取字典
  97. SysDictRedis sysDictRedis = SysDictUtils.get(DictEnum.DATA_CLEAR_SIZE.getKey(), "device_history_twig");
  98. Integer value = Integer.valueOf(sysDictRedis.getValue());
  99. //获取redis
  100. String key = keyPrefix + AuthorizeUtils.getLoginId(Long.class);
  101. List<String> list = redisService.getList(key);
  102. list.add(0, String.valueOf(obj.getDeviceId()));
  103. //去重
  104. List<String> redisList = new ArrayList<>();
  105. JList<String> comparing = new JArrayList<>(list).comparing();
  106. if (comparing.size() > value) {
  107. for (int i = 0; i < value; i++) {
  108. redisList.add(comparing.get(i));
  109. }
  110. } else {
  111. redisList = comparing;
  112. }
  113. redisService.removeList(key);
  114. redisService.setList(key, redisList);
  115. return R.ok();
  116. }
  117. @Override
  118. @ApiOperation("开门检测")
  119. public R checkOpenDoor(DeviceInfoDto.Obj obj) {
  120. DeviceInfoDto.Vo deviceInfo = obj(new DeviceInfoDto.Obj().setDeviceId(obj.getDeviceId())).getData();
  121. if (deviceInfo == null) {
  122. return R.fail("设备不存在");
  123. }
  124. DeviceStatusDto.Vo deviceStatus = deviceInfo.getDeviceStatus();
  125. check(deviceInfo.getFreezeStatus(), 2, "设备已冻结");
  126. SysDictRedis sysDictRedis = SysDictUtils.get(DictEnum.DEVICE_FAULT_LEVEL_PAY_THRESHOLD.getKey(), DictSonEnum.DEVICE_FAULT_LEVEL_PAY_THRESHOLD_NOT_PAY.getKey());
  127. if (deviceInfo.getFaultLevel() >= Integer.valueOf(sysDictRedis.getValue())) {
  128. return R.fail("设备故障");
  129. }
  130. check(deviceStatus.getNetState(), 2, "设备已离线");
  131. check(obj.getDoor() != null && obj.getDoor() == 1 ? deviceStatus.getDeviceStateR() : deviceStatus.getDeviceStateL(), 2, "设备已锁机");
  132. check(obj.getDoor() != null && obj.getDoor() == 1 ? deviceStatus.getLockStateR() : deviceStatus.getLockStateL(), 2, "设备正在使用中,请稍后");
  133. return R.ok();
  134. }
  135. @PostMapping("historyList")
  136. @ApiOperation("设备访问历史查询")
  137. public R<List<DeviceInfoDto.Vo>> historyList() {
  138. //获取redis
  139. String key = keyPrefix + AuthorizeUtils.getLoginId(Long.class);
  140. List<String> deviceIds = redisService.getList(key);
  141. if (!Emptys.check(deviceIds)) {
  142. return R.ok();
  143. }
  144. //查询数据库
  145. List<DeviceInfo> list = list(new LambdaQueryWrapper<DeviceInfo>().in(DeviceInfo::getDeviceId, deviceIds));
  146. return R.ok(copy(DeviceInfoDto.Vo.class, list));
  147. }
  148. @ApiOperation("修改")
  149. @PostMapping("update")
  150. public R update(@RequestBody @Validated DeviceInfoDto.Update update) {
  151. DeviceInfo deviceInfo = copy(DeviceInfo.class, update);
  152. updateById(deviceInfo);
  153. return R.ok();
  154. }
  155. @Override
  156. @ApiOperation("更新商户线路")
  157. public R updateLine(@RequestBody @Validated DeviceInfoDto.UpdateLine updateLine) {
  158. LambdaUpdateWrapper<DeviceInfo> luw = new LambdaUpdateWrapper<DeviceInfo>().eq(DeviceInfo::getMercId, updateLine.getMercId());
  159. //绑定线路,更换线路
  160. if (DeviceInfoDto.UPDATE.equals(updateLine.getType())) {
  161. DeviceInfo deviceInfo = new DeviceInfo();
  162. deviceInfo.setPlaceLineId(updateLine.getPlaceLineId());
  163. luw.in(DeviceInfo::getDeviceId, updateLine.getDeviceIds());
  164. baseMapper.update(deviceInfo, luw);
  165. }
  166. //删除线路
  167. if (DeviceInfoDto.DEL.equals(updateLine.getType())) {
  168. luw.eq(DeviceInfo::getPlaceLineId, updateLine.getWherePlaceLineId());
  169. luw.set(DeviceInfo::getPlaceLineId, null);
  170. baseMapper.update(null, luw);
  171. }
  172. //解绑线路 设置线路ID为null
  173. if (DeviceInfoDto.CLEAR.equals(updateLine.getType())) {
  174. luw.in(DeviceInfo::getDeviceId, updateLine.getDeviceIds());
  175. luw.set(DeviceInfo::getPlaceLineId, null);
  176. baseMapper.update(null, luw);
  177. }
  178. return R.ok();
  179. }
  180. @Override
  181. @ApiOperation("更新商户点位")
  182. public R updatePlace(@RequestBody @Validated DeviceInfoDto.UpdatePlace updatePlace) {
  183. LambdaUpdateWrapper<DeviceInfo> luw = new LambdaUpdateWrapper<DeviceInfo>().eq(DeviceInfo::getMercId, updatePlace.getMercId());
  184. //绑定点位,更换点位
  185. if (DeviceInfoDto.UPDATE.equals(updatePlace.getType())) {
  186. DeviceInfo deviceInfo = new DeviceInfo();
  187. deviceInfo.setPlaceId(updatePlace.getPlaceId());
  188. luw.in(DeviceInfo::getDeviceId, updatePlace.getDeviceIds());
  189. baseMapper.update(deviceInfo, luw);
  190. }
  191. //删除点位
  192. if (DeviceInfoDto.DEL.equals(updatePlace.getType())) {
  193. luw.eq(DeviceInfo::getPlaceId, updatePlace.getWherePlaceId());
  194. luw.set(DeviceInfo::getPlaceId, null);
  195. baseMapper.update(null, luw);
  196. }
  197. //解绑点位 设置点位ID为null
  198. if (DeviceInfoDto.CLEAR.equals(updatePlace.getType())) {
  199. luw.in(DeviceInfo::getDeviceId, updatePlace.getDeviceIds());
  200. luw.set(DeviceInfo::getPlaceId, null);
  201. baseMapper.update(null, luw);
  202. }
  203. return R.ok();
  204. }
  205. @PostMapping("page")
  206. @ApiOperation("分页查询")
  207. public R<PageBean<DeviceInfoDto.Vo2>> page(@RequestBody DeviceInfoDto.Page page) {
  208. return R.ok(queryPage(page));
  209. }
  210. @ApiOperation("导出设备列表")
  211. @PostMapping("exportDevices")
  212. public void exportDevices(HttpServletResponse response, @RequestBody @Valid DeviceInfoDto.Page page) throws IOException {
  213. PageBean<DeviceInfoDto.Vo2> pageBean = queryPage(page);
  214. List<DeviceInfoDto.Vo2> records = pageBean.getRecords();
  215. List<DeviceInfoDto.DeviceExcelVO> deviceExcelVOS = BeanUtil.copyToList(records, DeviceInfoDto.DeviceExcelVO.class);
  216. // 输出
  217. ExcelUtils.write(response, "设备列表.xls", "设备列表", DeviceInfoDto.DeviceExcelVO.class, deviceExcelVOS);
  218. }
  219. @PostMapping("nearbyPage")
  220. @ApiOperation("附近设备分页查询")
  221. public R<PageBean<DeviceInfoDto.Vo2>> nearbyPage(@RequestBody DeviceInfoDto.Page page) {
  222. if (!Emptys.check(page.getLon()) || !Emptys.check(page.getLat())) {
  223. throw new CommRuntimeException("经纬度不能为空");
  224. }
  225. return R.ok(queryPage(page));
  226. }
  227. @ApiOperation("商户设备授权")
  228. @Override
  229. @Transactional(rollbackFor = Exception.class)
  230. public R<Boolean> mercDeviceAuth(DeviceInfoDto.MercDeviceAuthDto auth) {
  231. Long mercId = auth.getMercId();
  232. String mercCode = auth.getMercCode();
  233. Long algorithmId = auth.getAlgorithmId();
  234. //商户最终设备列表
  235. List<Long> deviceIds = auth.getDeviceIds();
  236. List<DeviceInfo> devices = getDevicesByMercId(mercId);
  237. //取消商户设备授权
  238. if (CollUtil.isEmpty(deviceIds)) {
  239. if (CollUtil.isEmpty(devices)) {
  240. return R.ok(Boolean.TRUE);
  241. }
  242. return R.ok(removeMerRefDevices(devices));
  243. }
  244. //更新商户设备授权
  245. List<DeviceInfo> deviceInfos = this.listByIds(deviceIds);
  246. deviceInfos.forEach(deviceInfo -> {
  247. //绑定关系
  248. deviceInfo.setMercId(mercId).setMercCode(mercCode).setAlgorithmId(algorithmId);
  249. });
  250. updateBatchById(deviceInfos);
  251. //原来存在的设备关系,不在最终设备列表中的移除
  252. if (CollUtil.isNotEmpty(devices)) {
  253. List<Long> oldIds = new ArrayList<>();
  254. List<Long> removeIds = new ArrayList<>();
  255. devices.forEach(device -> oldIds.add(device.getDeviceId()));
  256. oldIds.forEach(deviceId -> {
  257. //不在最终设备列表中的待移除
  258. if (!deviceIds.contains(deviceId)) {
  259. removeIds.add(deviceId);
  260. }
  261. });
  262. if (CollUtil.isNotEmpty(removeIds)) {
  263. List<DeviceInfo> removeList = this.listByIds(removeIds);
  264. removeMerRefDevices(removeList);
  265. }
  266. }
  267. return R.ok(Boolean.TRUE);
  268. }
  269. /**
  270. * 批量移除商户设备绑定关系
  271. *
  272. * @param deviceInfos
  273. * @return
  274. */
  275. private Boolean removeMerRefDevices(List<DeviceInfo> deviceInfos) {
  276. deviceInfos.forEach(deviceInfo -> {
  277. //-1 释放关系
  278. deviceInfo.setMercId(-1L);
  279. });
  280. //批量更新
  281. updateBatchById(deviceInfos);
  282. return updateBatchById(deviceInfos);
  283. }
  284. @ApiOperation("集合查询")
  285. @Override
  286. public R<List<DeviceInfoDto.Vo>> list(DeviceInfoDto.ListDto dto) {
  287. List<DeviceInfo> list = list(new LambdaQueryWrapper<DeviceInfo>().in(CollUtil.isNotEmpty(dto.getDeviceIds()), DeviceInfo::getDeviceId, dto.getDeviceIds()));
  288. return R.ok(copy(DeviceInfoDto.Vo.class, list));
  289. }
  290. @Override
  291. public R<List<DeviceInfoDto.Vo>> listCommon(DeviceInfoDto.ListCommon dto) {
  292. String deviceSearch = dto.getDeviceSearch();
  293. QueryWrapper<DeviceInfo> queryWrapper = new MybatisPlusQuery().eqWrapper(dto.getVo(), DeviceInfo.class).buildQW();
  294. List<Long> placeLineIds = dto.getPlaceLineIds();
  295. List<Long> deviceIds = dto.getDeviceIds();
  296. List<String> columnList = dto.getColumnList();
  297. if (CollUtil.isNotEmpty(placeLineIds)) {
  298. queryWrapper.eq(LambdaUtils.getProperty(DeviceInfo::getPlaceLineId), placeLineIds);
  299. }
  300. if (StrUtil.isNotEmpty(deviceSearch)) {
  301. queryWrapper.and(wrapper -> wrapper.likeRight(LambdaUtils.getProperty(DeviceInfo::getDeviceName), deviceSearch).or()
  302. .eq(LambdaUtils.getProperty(DeviceInfo::getMercDeviceCode), deviceSearch));
  303. }
  304. if (CollUtil.isNotEmpty(columnList)) {
  305. queryWrapper.select(columnList.stream().toArray(String[]::new));
  306. }
  307. if (CollUtil.isNotEmpty(deviceIds)) {
  308. queryWrapper.eq(LambdaUtils.getProperty(DeviceInfo::getDeviceId), deviceIds);
  309. }
  310. return R.ok(copy(DeviceInfoDto.Vo.class, list(queryWrapper)));
  311. }
  312. @Override
  313. @ApiOperation("商户设备算法列表")
  314. public R<List<Long>> mercAlgorithmIdList(DeviceInfoDto.MercAlgorithmIdListDto dto) {
  315. String algorithmIdStr = LambdaUtils.getProperty(DeviceInfo::getAlgorithmId);
  316. String mercStr = StringTools.humpToLine(LambdaUtils.getProperty(DeviceInfo::getMercId));
  317. QueryWrapper<DeviceInfo> lqw = new QueryWrapper<DeviceInfo>()
  318. .isNotNull(StringTools.humpToLine(algorithmIdStr))
  319. .eq(mercStr, dto.getMercId())
  320. .select(String.format("DISTINCT (%s) as %s", StringTools.humpToLine(algorithmIdStr), algorithmIdStr));
  321. List<Long> list = listObjs(lqw, (MapperFunction<Object, Long>) o -> (Long) o);
  322. return R.ok(list);
  323. }
  324. @Override
  325. @ApiOperation("小程序-商户设备首页统计")
  326. public R<DeviceInfoDto.MercHomeStatisticalVO> mercHomeStatistical(DeviceInfoDto.MercHomeQueryDTO dto) {
  327. Long mercId = dto.getMercId();
  328. //初始化数据
  329. DeviceInfoDto.MercHomeStatisticalVO mercHomeStatisticalVO = new DeviceInfoDto.MercHomeStatisticalVO()
  330. .setClosedNum(0).setOfflineNum(0)
  331. .setOnlineNum(0).setOperatingNum(0).setNeedToFillNum(0);
  332. //获取商户机器
  333. List<DeviceInfo> mercDevices = getDevicesByMercId(mercId);
  334. if (CollUtil.isEmpty(mercDevices)) {
  335. return R.ok(mercHomeStatisticalVO);
  336. }
  337. List<Long> deviceIds = mercDevices.stream().map(DeviceInfo::getDeviceId).collect(Collectors.toList());
  338. //在线、离线
  339. List<DeviceStatus> deviceStatuses = deviceStatusService.listByIds(deviceIds);
  340. //分组统计
  341. Map<Integer, Long> countNetstateMap = deviceStatuses.stream().collect(Collectors
  342. .groupingBy(DeviceStatus::getNetState, Collectors.counting()));
  343. Integer onlineDictValue = SysDictUtils.getValue(DictEnum.DEVICE_ONLINE_STATUS.getKey(), DictSonEnum.DEVICE_ONLINE_STATUS_CONNECTED.getKey(), Integer.class);
  344. Integer offlineDictValue = SysDictUtils.getValue(DictEnum.DEVICE_ONLINE_STATUS.getKey(), DictSonEnum.DEVICE_ONLINE_STATUS_DISCONNECT.getKey(), Integer.class);
  345. int onlineNum = countNetstateMap.get(onlineDictValue) == null ? 0 : countNetstateMap.get(onlineDictValue).intValue();
  346. int offlineNum = countNetstateMap.get(offlineDictValue) == null ? 0 : countNetstateMap.get(offlineDictValue).intValue();
  347. mercHomeStatisticalVO.setOnlineNum(onlineNum);
  348. mercHomeStatisticalVO.setOfflineNum(offlineNum);
  349. //运营、停业
  350. Map<Integer, Long> countBusyStateMap = mercDevices.stream().collect(Collectors
  351. .groupingBy(DeviceInfo::getBusyState, Collectors.counting()));
  352. Integer busyState1 = SysDictUtils.getValue(DictEnum.DEVICE_BUSY_STATUS.getKey(), DictSonEnum.DEVICE_BUSY_STATUS1.getKey(), Integer.class);
  353. Integer busyState2 = SysDictUtils.getValue(DictEnum.DEVICE_BUSY_STATUS.getKey(), DictSonEnum.DEVICE_BUSY_STATUS2.getKey(), Integer.class);
  354. int operatingNum = countBusyStateMap.get(busyState1) == null ? 0 : countBusyStateMap.get(busyState1).intValue();
  355. int closedNum = countBusyStateMap.get(busyState2) == null ? 0 : countBusyStateMap.get(busyState2).intValue();
  356. mercHomeStatisticalVO.setOperatingNum(operatingNum);
  357. mercHomeStatisticalVO.setClosedNum(closedNum);
  358. //待补货
  359. //TODO: 此逻辑需要确认
  360. return R.ok(mercHomeStatisticalVO);
  361. }
  362. @Override
  363. @ApiOperation("小程序-商户设备首页列表")
  364. public R<List<DeviceInfoDto.MercHomeListVO>> mercHomeList(DeviceInfoDto.MercHomeQueryDTO dto) {
  365. Long mercId = dto.getMercId();
  366. String deviceName = dto.getDeviceName();
  367. Long deviceId = dto.getDeviceId();
  368. List<DeviceInfoDto.MercHomeCountVO> list = this.baseMapper.merHomeCountList(dto);
  369. if (CollUtil.isEmpty(list)) {
  370. return R.ok(Collections.emptyList());
  371. }
  372. List<DeviceInfoDto.MercHomeListVO> dataList = new ArrayList<>(list.size());
  373. //获取通条件设备信息
  374. LambdaQueryWrapper<DeviceInfo> lqw = new LambdaQueryWrapper<>();
  375. lqw.eq(mercId != null, DeviceInfo::getMercId, mercId);
  376. lqw.eq(deviceId != null, DeviceInfo::getDeviceId, deviceId);
  377. lqw.like(StrUtil.isNotEmpty(deviceName), DeviceInfo::getDeviceName, deviceName);
  378. List<DeviceInfo> deviceInfoList = this.list(lqw);
  379. //未分配线路的设置默认值
  380. deviceInfoList.stream().filter(s -> s.getPlaceLineId() == null).forEach(s -> s.setPlaceLineId(-1L));
  381. //根据线路id分组
  382. Map<Long, List<DeviceInfo>> deviceMap = deviceInfoList.stream().collect(Collectors.groupingBy(DeviceInfo::getPlaceLineId));
  383. list.forEach(v -> {
  384. DeviceInfoDto.MercHomeListVO vo = new DeviceInfoDto.MercHomeListVO();
  385. Long placeLineId = v.getPlaceLineId();
  386. vo.setDeviceNum(v.getDeviceNum());
  387. vo.setPlaceLineId(v.getPlaceLineId());
  388. //线路下的设备列表
  389. List<DeviceInfoDto.MercHomeDeviceVo> deviceInfos = Beans.copy(DeviceInfoDto.MercHomeDeviceVo.class, deviceMap.get(placeLineId));
  390. deviceInfos.forEach(device -> {
  391. //设备类型 反显
  392. SysDictRedis dictDeviceType = SysDictUtils.get(DictConsts.DEVICE_TYPE, String.valueOf(device.getDeviceType()));
  393. device.setDeviceTypeName(dictDeviceType.getMsg());
  394. //运营状态 反显
  395. SysDictRedis dictBusyState = SysDictUtils.get(DictConsts.DEVICE_BUSY_STATUS, String.valueOf(device.getBusyState()));
  396. device.setBusyStateName(dictBusyState.getMsg());
  397. //初始化数字
  398. device.setDayOrderNum(0).setOnSaleNum(0).setFillNum(0).setDaySalesPrice("0");
  399. //TODO: 数字统计
  400. });
  401. vo.setDeviceInfos(deviceInfos);
  402. dataList.add(vo);
  403. });
  404. return R.ok(dataList);
  405. }
  406. /**
  407. * 获取商户设备列表
  408. *
  409. * @param mercId
  410. * @return
  411. */
  412. private List<DeviceInfo> getDevicesByMercId(Long mercId) {
  413. return list(Wrappers.<DeviceInfo>lambdaQuery().eq(DeviceInfo::getMercId, mercId));
  414. }
  415. private PageBean<DeviceInfoDto.Vo2> queryPage(DeviceInfoDto.Page page) {
  416. IPage<DeviceInfoQueryPage> iPage = baseMapper.queryPage(toIPage(page.getPage()), page);
  417. return toPageBean(DeviceInfoDto.Vo2.class, iPage);
  418. }
  419. private <T> void check(T value, T value2, String msg) {
  420. if (value.toString().equals(value2.toString())) {
  421. throw new CommRuntimeException(msg);
  422. }
  423. }
  424. }