DeviceInfoServiceImpl.java 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378
  1. package com.xy.service;
  2. import cn.hutool.core.bean.BeanUtil;
  3. import cn.hutool.core.collection.CollUtil;
  4. import cn.hutool.core.collection.ListUtil;
  5. import cn.hutool.core.date.DatePattern;
  6. import cn.hutool.core.date.DateTime;
  7. import cn.hutool.core.date.DateUtil;
  8. import cn.hutool.core.map.MapUtil;
  9. import cn.hutool.core.text.StrBuilder;
  10. import cn.hutool.core.util.BooleanUtil;
  11. import cn.hutool.core.util.NumberUtil;
  12. import cn.hutool.core.util.ObjectUtil;
  13. import cn.hutool.core.util.StrUtil;
  14. import cn.hutool.json.JSONUtil;
  15. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  16. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  17. import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
  18. import com.baomidou.mybatisplus.core.metadata.IPage;
  19. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  20. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  21. import com.xy.collections.list.JArrayList;
  22. import com.xy.collections.list.JList;
  23. import com.xy.collections.map.JMap;
  24. import com.xy.config.DeviceThreadPoolConfig;
  25. import com.xy.consts.DictConsts;
  26. import com.xy.device.*;
  27. import com.xy.dto.*;
  28. import com.xy.dto.api.biz.ContainerAddDTO;
  29. import com.xy.dto.be.MercDto;
  30. import com.xy.dto.common.MercRegionDto;
  31. import com.xy.entity.*;
  32. import com.xy.enums.FileExportType;
  33. import com.xy.error.CommRuntimeException;
  34. import com.xy.mapper.DeviceInfoMapper;
  35. import com.xy.mapper.entity.DeviceInfoQueryPage;
  36. import com.xy.service.be.MercFeignService;
  37. import com.xy.service.common.MercRegionService;
  38. import com.xy.sys.EnumDataClearSize;
  39. import com.xy.util.ExcelUtils;
  40. import com.xy.utils.*;
  41. import com.xy.utils.Enum.AlgorithmTypeEnum;
  42. import com.xy.utils.enums.DeviceActiveStateEnum;
  43. import com.xy.utils.enums.DeviceLockState;
  44. import com.xy.utils.enums.DeviceNetSateType;
  45. import com.xy.utils.enums.DeviceTypeEnum;
  46. import io.swagger.annotations.Api;
  47. import io.swagger.annotations.ApiOperation;
  48. import jodd.introspector.MapperFunction;
  49. import lombok.RequiredArgsConstructor;
  50. import lombok.extern.slf4j.Slf4j;
  51. import org.springframework.stereotype.Service;
  52. import org.springframework.transaction.annotation.Transactional;
  53. import org.springframework.validation.annotation.Validated;
  54. import org.springframework.web.bind.annotation.PostMapping;
  55. import org.springframework.web.bind.annotation.RequestBody;
  56. import javax.servlet.http.HttpServletResponse;
  57. import javax.validation.Valid;
  58. import java.io.IOException;
  59. import java.math.BigDecimal;
  60. import java.time.LocalDateTime;
  61. import java.util.*;
  62. import java.util.stream.Collectors;
  63. import static com.xy.utils.PlusBeans.*;
  64. /**
  65. * <p>
  66. * 设备-信息 服务实现类
  67. * </p>
  68. *
  69. * @author lijin
  70. * @since 2022-12-23
  71. */
  72. @Slf4j
  73. @Service
  74. @RequiredArgsConstructor
  75. @Api(tags = "设备-信息")
  76. public class DeviceInfoServiceImpl extends ServiceImpl<DeviceInfoMapper, DeviceInfo> implements DeviceInfoService {
  77. private final CloudWalkApiService cloudWalkApiService;
  78. private final AlgorithmService algorithmService;
  79. private final CountApiService countApiService;
  80. /**
  81. * 质检商户code
  82. */
  83. public static final String QA_MERC_CODE = "10001";
  84. private final MercFeignService mercFeignService;
  85. private final DeviceSysinfoServiceImpl deviceSysinfoService;
  86. private final DeviceStatusServiceImpl deviceStatusService;
  87. private final DeviceRegisterServiceImpl deviceRegisterService;
  88. private final DeviceEventMsgServiceImpl deviceEventMsgService;
  89. private final DeviceDataServiceImpl deviceDataService;
  90. private final DeviceTempRecordsServiceImpl deviceTempRecordsService;
  91. private final DeviceNetRecordServiceImpl deviceNetRecordService;
  92. private final GoodsDeviceService goodsDeviceService;
  93. private final FileExportService fileExportService;
  94. private final RedisService<String> redisService;
  95. private final GoodsService goodsService;
  96. private final AlipayDeviceService alipayDeviceService;
  97. private final String keyPrefix = "device:history:";
  98. private final MercRegionService mercRegionService;
  99. private final DeviceAlgorithmChargingServiceImpl deviceAlgorithmChargingService;
  100. /**
  101. * 商户设备列表分页-穿梭框用
  102. *
  103. * @param dto
  104. * @return {@link R}<{@link List}<{@link DeviceInfoDto.MyDeviceInfo}>>
  105. */
  106. public R<PageBean<DeviceInfoDto.MyDeviceInfo>> myDeviceList(@RequestBody @Validated DeviceInfoDto.MyDeviceDTO dto) {
  107. PageBean pageBean = dto.getPage();
  108. String searchKey = dto.getSearchKey();
  109. Long mercId = dto.getMercId();
  110. Integer type = dto.getType();
  111. Long strategyId = dto.getStrategyId();
  112. GoodsDeviceDto.SelectList selectList = new GoodsDeviceDto.SelectList();
  113. selectList.setMercId(mercId).setPriceStrategyId(strategyId);
  114. List<GoodsDeviceDto.Vo> goodsDevices = R.feignCheckData(goodsDeviceService.list(selectList));
  115. if (type == 2 && CollUtil.isEmpty(goodsDevices)) {
  116. //右侧已选的
  117. return R.ok(new PageBean<>());
  118. }
  119. List<Long> deviceIds = goodsDevices.stream().map(GoodsDeviceDto.Vo::getDeviceId).collect(Collectors.toList());
  120. LambdaQueryWrapper<DeviceInfo> lqw = new MybatisPlusQuery().eqWrapper(dto, DeviceInfo.class)
  121. .build();
  122. lqw.in(type == 2 && CollUtil.isNotEmpty(deviceIds), DeviceInfo::getDeviceId, deviceIds);
  123. //左侧排除掉已关联的
  124. lqw.notIn(type == 1 && CollUtil.isNotEmpty(deviceIds), DeviceInfo::getDeviceId, deviceIds);
  125. lqw.and(StrUtil.isNotEmpty(searchKey), wrapper -> wrapper
  126. .eq(DeviceInfo::getDeviceId, searchKey)
  127. .or()
  128. .likeRight(DeviceInfo::getDeviceName, searchKey));
  129. IPage<DeviceInfo> iPage = page(toIPage(pageBean), lqw);
  130. return R.ok(toPageBean(DeviceInfoDto.MyDeviceInfo.class, iPage));
  131. }
  132. @ApiOperation("点位设备数量查询")
  133. @Override
  134. public R<List<DeviceInfoDto.PlaceDeviceNumVo>> placeDeviceNum(@RequestBody @Validated DeviceInfoDto.PlaceDeviceNumDto dto) {
  135. return R.ok(baseMapper.placeDeviceNum(dto));
  136. }
  137. @Override
  138. @ApiOperation("设备列表带卡包数")
  139. public R<PageBean<DeviceInfoDto.AlgorithmChargingVo>> algorithmChargingDevice(@RequestBody @Validated DeviceInfoDto.AlgorithmCharging algorithmCharging) {
  140. PageBean pageBean = algorithmCharging.getPage();
  141. //查询设备
  142. Integer value = SysDictUtils.getValue(EnumDeviceActiveStatus.Code.CODE.getCode(), EnumDeviceActiveStatus.N_1.getCode(), Integer.class);
  143. LambdaUpdateWrapper<DeviceInfo> lambdaUpdateWrapper = new LambdaUpdateWrapper<DeviceInfo>()
  144. .eq(DeviceInfo::getMercId, algorithmCharging.getMercId())
  145. .eq(DeviceInfo::getActiveState, value)
  146. .in(Emptys.check(algorithmCharging.getDeviceIds()), DeviceInfo::getDeviceId, algorithmCharging.getDeviceIds())
  147. .orderByDesc(DeviceInfo::getCreateTime);
  148. IPage<DeviceInfo> page = page(toIPage(pageBean), lambdaUpdateWrapper);
  149. PageBean<DeviceInfoDto.AlgorithmChargingVo> algorithmChargingVoPageBean = toPageBean(DeviceInfoDto.AlgorithmChargingVo.class, page);
  150. List<DeviceInfoDto.AlgorithmChargingVo> algorithmChargingVos = algorithmChargingVoPageBean.getRecords();
  151. if (!Emptys.check(algorithmChargingVos)) {
  152. return R.ok(algorithmChargingVoPageBean);
  153. }
  154. //查询卡包数量
  155. List<DeviceAlgorithmChargingDto.CountVo> data = deviceAlgorithmChargingService.count(new DeviceAlgorithmChargingDto.Count()
  156. .setDeviceIds(new JArrayList<>(algorithmChargingVos).getProperty(DeviceInfoDto.AlgorithmChargingVo::getDeviceId))
  157. .setMercId(algorithmCharging.getMercId())
  158. ).getData();
  159. JMap<Long, DeviceAlgorithmChargingDto.CountVo> cover = new JArrayList<>(data).toMap(DeviceAlgorithmChargingDto.CountVo::getDeviceId).cover();
  160. algorithmChargingVos.forEach(algorithmChargingVo -> {
  161. DeviceAlgorithmChargingDto.CountVo countVo = cover.get(algorithmChargingVo.getDeviceId());
  162. Beans.copy(algorithmChargingVo, countVo);
  163. });
  164. return R.ok(algorithmChargingVoPageBean);
  165. }
  166. @Override
  167. @ApiOperation("设备在线数查询")
  168. public R<Map<Long, DeviceInfoDto.NetStateCountVo>> netStateCount(DeviceInfoDto.NetStateCountDto dto) {
  169. List<DeviceInfoDto.NetStateCount> netStateCountList = baseMapper.netStateCount(dto.getMercIdList());
  170. List<Long> netStateCountMercList = netStateCountList.stream().map(DeviceInfoDto.NetStateCount::getMercId).distinct().collect(Collectors.toList());
  171. Map<Long, DeviceInfoDto.NetStateCountVo> voMap = new HashMap<>();
  172. List<Long> mercIdList = Emptys.check(dto.getMercIdList()) ? dto.getMercIdList() : netStateCountMercList;
  173. if (!Emptys.check(mercIdList)) {
  174. return R.ok();
  175. }
  176. for (Long mercId : mercIdList) {
  177. Integer count = 0;
  178. Integer offline = 0;
  179. DeviceInfoDto.NetStateCountVo vo = new DeviceInfoDto.NetStateCountVo().setMercId(mercId);
  180. for (DeviceInfoDto.NetStateCount i : netStateCountList) {
  181. if (Objects.equals(i.getMercId(), mercId)) {
  182. count += i.getCount();
  183. if ("1".equals(i.getNetState())) {
  184. vo.setOnLineCount(i.getCount());
  185. } else {
  186. offline += i.getCount();
  187. }
  188. }
  189. }
  190. vo.setCount(count).setOffLineCount(offline);
  191. voMap.put(mercId, vo);
  192. }
  193. return R.ok(voMap);
  194. }
  195. @Override
  196. @ApiOperation("分页")
  197. public R<PageBean<DeviceInfoDto.Vo>> pageSingle(DeviceInfoDto.PageSingle dto) {
  198. PageBean pageBean = dto.getPage();
  199. LambdaQueryWrapper<DeviceInfo> lqw = new MybatisPlusQuery().eqWrapper(dto, DeviceInfo.class)
  200. .build();
  201. IPage<DeviceInfo> iPage = page(toIPage(pageBean), lqw);
  202. return R.ok(toPageBean(DeviceInfoDto.Vo.class, iPage));
  203. }
  204. @Override
  205. @ApiOperation("对象查询")
  206. public R<DeviceInfoDto.Vo> obj(DeviceInfoDto.Obj obj) {
  207. //设备信息
  208. LambdaQueryWrapper<DeviceInfo> lambdaQueryWrapper = new MybatisPlusQuery().eqWrapper(obj, DeviceInfo.class).build();
  209. List<DeviceInfo> list = list(lambdaQueryWrapper);
  210. if (!Emptys.check(list)) {
  211. return R.ok();
  212. }
  213. DeviceInfoDto.Vo deviceInfo = copy(DeviceInfoDto.Vo.class, list.get(0));
  214. int num = 0;
  215. if (obj.getIsSysinfo()) {
  216. num++;
  217. }
  218. if (obj.getIsStatus()) {
  219. num++;
  220. }
  221. if (obj.getIsRegister()) {
  222. num++;
  223. }
  224. if (num > 0) {
  225. ThreadPoolUtils.Execute execute = ThreadPoolUtils.excPoll(DeviceThreadPoolConfig.DEVICE_COMMON_POLL, num);
  226. if (obj.getIsSysinfo()) {
  227. execute.execute(() -> {
  228. //系统信息
  229. DeviceSysinfoDto.Vo deviceSysinfo = deviceSysinfoService.get(new DeviceSysinfoDto.Vo().setDeviceId(deviceInfo.getDeviceId())).getData();
  230. deviceInfo.setDeviceSysinfo(deviceSysinfo);
  231. });
  232. }
  233. if (obj.getIsStatus()) {
  234. execute.execute(() -> {
  235. //状态信息
  236. DeviceStatusDto.Vo deviceStatus = deviceStatusService.obj(new DeviceStatusDto.Vo().setDeviceId(deviceInfo.getDeviceId())).getData();
  237. deviceInfo.setDeviceStatus(deviceStatus);
  238. });
  239. }
  240. if (obj.getIsRegister()) {
  241. execute.execute(() -> {
  242. //注册信息
  243. DeviceRegisterDto.Vo deviceRegister = deviceRegisterService.obj(new DeviceRegisterDto.Vo().setDeviceId(deviceInfo.getDeviceId())).getData();
  244. deviceInfo.setDeviceRegister(deviceRegister);
  245. });
  246. }
  247. execute.end();
  248. }
  249. return R.ok(deviceInfo);
  250. }
  251. @ApiOperation("反显设备名称")
  252. @Override
  253. public R<Map<Long, String>> getDeviceNameList(DeviceInfoDto.DeviceIdDto dto) {
  254. LambdaQueryWrapper<DeviceInfo> lqw = new LambdaQueryWrapper<DeviceInfo>()
  255. .in(DeviceInfo::getDeviceId, dto.getDeviceId())
  256. .select(DeviceInfo::getDeviceId, DeviceInfo::getDeviceName);
  257. List<DeviceInfo> deviceInfoList = list(lqw);
  258. return R.ok(deviceInfoList.stream().collect(Collectors.toMap(DeviceInfo::getDeviceId, i -> Optional.ofNullable(i.getDeviceName()).orElse(""))));
  259. }
  260. @Override
  261. public R<DeviceSysinfoDto.Vo> getDeviceSysinfo(DeviceSysinfoDto.DeviceSysInfo dto) {
  262. String dtoDeviceSN = dto.getDeviceSN();
  263. DeviceSysinfo one = deviceSysinfoService.getOne(Wrappers.<DeviceSysinfo>lambdaQuery().eq(DeviceSysinfo::getDeviceSn, dtoDeviceSN));
  264. return R.ok(BeanUtil.copyProperties(one, DeviceSysinfoDto.Vo.class));
  265. }
  266. @Override
  267. @ApiOperation("设备访问历史添加")
  268. public R history(DeviceInfoDto.Obj obj) {
  269. //获取字典
  270. SysDictRedis sysDictRedis = SysDictUtils.get(EnumDataClearSize.Code.CODE.getCode(), EnumDataClearSize.DEVICE_HISTORY_TWIG.getCode());
  271. Integer value = Integer.valueOf(sysDictRedis.getValue());
  272. //获取redis
  273. String key = keyPrefix + AuthorizeUtils.getLoginId(Long.class);
  274. List<String> list = redisService.getList(key);
  275. list.add(0, String.valueOf(obj.getDeviceId()));
  276. //去重
  277. List<String> redisList = new ArrayList<>();
  278. JList<String> comparing = new JArrayList<>(list).comparing();
  279. if (comparing.size() > value) {
  280. for (int i = 0; i < value; i++) {
  281. redisList.add(comparing.get(i));
  282. }
  283. } else {
  284. redisList = comparing;
  285. }
  286. redisService.removeList(key);
  287. redisService.setList(key, redisList);
  288. return R.ok();
  289. }
  290. @Override
  291. @ApiOperation("开门检测")
  292. public R<DeviceInfoDto.Vo> checkOpenDoor(DeviceInfoDto.Obj obj) {
  293. DeviceInfoDto.Vo deviceInfo = obj(new DeviceInfoDto.Obj()
  294. .setDeviceId(obj.getDeviceId())
  295. .setIsStatus(true)
  296. ).getData();
  297. if (deviceInfo == null) {
  298. return R.fail("设备不存在");
  299. }
  300. Integer busyState = deviceInfo.getBusyState();
  301. SysDictRedis sdr = SysDictUtils.get(EnumDeviceBusyStatus.Code.CODE.getCode(), EnumDeviceBusyStatus.N_2.getCode());
  302. if (busyState.intValue() == Integer.valueOf(sdr.getValue()).intValue()) {
  303. return R.fail("设备已停运");
  304. }
  305. DeviceStatusDto.Vo deviceStatus = deviceInfo.getDeviceStatus();
  306. SysDictRedis sysDictRedis = SysDictUtils.get(EnumDeviceFaultLevelPayThreshold.Code.CODE.getCode(), EnumDeviceFaultLevelPayThreshold.NOT_PAY.getCode());
  307. if (deviceInfo.getFaultLevel() >= Integer.valueOf(sysDictRedis.getValue())) {
  308. return R.fail("设备故障");
  309. }
  310. check(deviceStatus.getNetState(), 2, "设备已离线");
  311. if (!deviceStatus.getIsPay()) {
  312. return R.fail("设备不可交易");
  313. }
  314. check(obj.getDoor() != null && obj.getDoor() == 1 ? deviceStatus.getDoorStateR() : deviceStatus.getDoorStateL(), 1, "设备正在使用中,请稍后");
  315. //质检用户不检查
  316. SysDictRedis qualitySets = SysDictUtils.get(EnumQualityMercSets.Code.CODE.getCode(), EnumQualityMercSets.MERC_CODE.getCode());
  317. if (!qualitySets.getValue().equals(deviceInfo.getMercCode())) {
  318. check(deviceInfo.getFreezeStatus(), 2, "设备已冻结");
  319. check(obj.getDoor() != null && obj.getDoor() == 1 ? deviceStatus.getLockStateR() : deviceStatus.getLockStateL(), 2, "设备已锁机");
  320. }
  321. return R.ok(deviceInfo);
  322. }
  323. @PostMapping("historyList")
  324. @ApiOperation("设备访问历史查询")
  325. public R<List<DeviceInfoDto.Vo>> historyList() {
  326. //获取redis
  327. String key = keyPrefix + AuthorizeUtils.getLoginId(Long.class);
  328. List<String> deviceIds = redisService.getList(key);
  329. if (!Emptys.check(deviceIds)) {
  330. return R.ok();
  331. }
  332. //查询数据库
  333. List<DeviceInfo> list = list(new LambdaQueryWrapper<DeviceInfo>().in(DeviceInfo::getDeviceId, deviceIds));
  334. return R.ok(copy(DeviceInfoDto.Vo.class, list));
  335. }
  336. @ApiOperation("修改")
  337. @PostMapping("update")
  338. public R update(@RequestBody @Validated DeviceInfoDto.Update update) {
  339. DeviceInfo deviceInfo = copy(DeviceInfo.class, update)
  340. .setUpdateTime(LocalDateTime.now());
  341. updateById(deviceInfo);
  342. Long deviceId = deviceInfo.getDeviceId();
  343. DeviceInfoDto.Vo device = R.feignCheckData(this.obj(new DeviceInfoDto.Obj().setDeviceId(deviceId).setIsSysinfo(true)));
  344. Long algorithmId = update.getAlgorithmId();
  345. if (algorithmId != null && AlgorithmTypeEnum.CLOUD.getId() == algorithmId) {
  346. //云从算法
  347. boolean b = cloudWalkApiService.checkDeviceExist(deviceId);
  348. if (!b) {
  349. //货柜不存在,新增
  350. cloudWalkApiService.containerAdd(new ContainerAddDTO().setContainerCode(String.valueOf(deviceId)));
  351. }
  352. }
  353. Integer deviceType = device.getDeviceType();
  354. if (ObjectUtil.equals(DeviceTypeEnum.TYPE5.getCode(), deviceType)) {
  355. DeviceUpdateDTO deviceUpdateDTO = new DeviceUpdateDTO();
  356. if (StrUtil.isNotEmpty(update.getDeviceName())) {
  357. deviceUpdateDTO.setDeviceName(update.getDeviceName());
  358. }
  359. String deviceSn = device.getDeviceSysinfo().getDeviceSn();
  360. if (deviceUpdateDTO != null) {
  361. deviceUpdateDTO.setTerminalId(String.valueOf(update.getDeviceId()));
  362. deviceUpdateDTO.setBoardSn(deviceSn);
  363. alipayDeviceService.deviceUpdate(deviceUpdateDTO);
  364. }
  365. }
  366. return R.ok();
  367. }
  368. @ApiOperation("批量修改")
  369. @PostMapping("updateBatch")
  370. public R updateBatch(@RequestBody List<DeviceInfoDto.Update> updates) {
  371. LocalDateTime now = LocalDateTime.now();
  372. List<DeviceInfo> deviceInfos = new ArrayList<>(updates.size());
  373. updates.forEach(update -> deviceInfos.add(copy(DeviceInfo.class, update).setUpdateTime(now)));
  374. updateBatchById(deviceInfos);
  375. return R.ok();
  376. }
  377. @Override
  378. @ApiOperation("更新商户线路")
  379. public R updateLine(@RequestBody @Validated DeviceInfoDto.UpdateLine updateLine) {
  380. LambdaUpdateWrapper<DeviceInfo> luw = new LambdaUpdateWrapper<DeviceInfo>().eq(DeviceInfo::getMercId, updateLine.getMercId());
  381. //绑定线路,更换线路
  382. if (DeviceInfoDto.UPDATE.equals(updateLine.getType())) {
  383. DeviceInfo deviceInfo = new DeviceInfo();
  384. deviceInfo.setPlaceLineId(updateLine.getPlaceLineId());
  385. luw.in(DeviceInfo::getDeviceId, updateLine.getDeviceIds());
  386. baseMapper.update(deviceInfo, luw);
  387. }
  388. //删除线路
  389. if (DeviceInfoDto.DEL.equals(updateLine.getType())) {
  390. luw.eq(DeviceInfo::getPlaceLineId, updateLine.getWherePlaceLineId());
  391. luw.set(DeviceInfo::getPlaceLineId, null);
  392. baseMapper.update(null, luw);
  393. }
  394. //解绑线路 设置线路ID为null
  395. if (DeviceInfoDto.CLEAR.equals(updateLine.getType())) {
  396. luw.in(DeviceInfo::getDeviceId, updateLine.getDeviceIds());
  397. luw.set(DeviceInfo::getPlaceLineId, null);
  398. baseMapper.update(null, luw);
  399. }
  400. return R.ok();
  401. }
  402. @Override
  403. @ApiOperation("更新商户点位")
  404. public R updatePlace(@RequestBody @Validated DeviceInfoDto.UpdatePlace updatePlace) {
  405. LambdaUpdateWrapper<DeviceInfo> luw = new LambdaUpdateWrapper<DeviceInfo>().eq(DeviceInfo::getMercId, updatePlace.getMercId());
  406. //绑定点位,更换点位
  407. if (DeviceInfoDto.UPDATE.equals(updatePlace.getType())) {
  408. DeviceInfo deviceInfo = new DeviceInfo();
  409. deviceInfo.setPlaceId(updatePlace.getPlaceId());
  410. luw.in(DeviceInfo::getDeviceId, updatePlace.getDeviceIds());
  411. baseMapper.update(deviceInfo, luw);
  412. }
  413. //删除点位
  414. if (DeviceInfoDto.DEL.equals(updatePlace.getType())) {
  415. luw.eq(DeviceInfo::getPlaceId, updatePlace.getWherePlaceId());
  416. luw.set(DeviceInfo::getPlaceId, null);
  417. baseMapper.update(null, luw);
  418. }
  419. //解绑点位 设置点位ID为null
  420. if (DeviceInfoDto.CLEAR.equals(updatePlace.getType())) {
  421. luw.in(DeviceInfo::getDeviceId, updatePlace.getDeviceIds());
  422. luw.set(DeviceInfo::getPlaceId, null);
  423. baseMapper.update(null, luw);
  424. }
  425. return R.ok();
  426. }
  427. @ApiOperation("分页查询")
  428. @Override
  429. public R<PageBean<DeviceInfoDto.Vo2>> page(@RequestBody DeviceInfoDto.Page page) {
  430. return R.ok(queryPage(page));
  431. }
  432. @ApiOperation("导出设备列表")
  433. @PostMapping("exportDevices")
  434. public void exportDevices(HttpServletResponse response, @RequestBody @Valid DeviceInfoDto.Page page) throws IOException {
  435. PageBean<DeviceInfoDto.Vo2> pageBean = queryPage(page);
  436. List<DeviceInfoDto.Vo2> records = pageBean.getRecords();
  437. List<DeviceInfoDto.DeviceExcelVO> deviceExcelVOS = BeanUtil.copyToList(records, DeviceInfoDto.DeviceExcelVO.class);
  438. // 输出
  439. ExcelUtils.write(response, "设备列表.xls", "设备列表", DeviceInfoDto.DeviceExcelVO.class, deviceExcelVOS);
  440. }
  441. @ApiOperation("导出设备(异步)")
  442. @PostMapping("exportDevices/async")
  443. public void exportDevicesAsync(@RequestBody @Validated DeviceInfoDto.Page page) {
  444. PageBean<DeviceInfoDto.Vo2> pageBean = queryPage(page);
  445. List<DeviceInfoDto.Vo2> records = pageBean.getRecords();
  446. List<DeviceInfoDto.DeviceExcelVO> deviceExcelVOS = BeanUtil.copyToList(records, DeviceInfoDto.DeviceExcelVO.class);
  447. //异步导出参数封装
  448. ExcelDTO<DeviceInfoDto.DeviceExcelVO> excelDTO = new ExcelDTO<>();
  449. excelDTO.setData(deviceExcelVOS);
  450. excelDTO.setHead(DeviceInfoDto.DeviceExcelVO.class);
  451. excelDTO.setSheetName(FileExportType.DEVICE_INFO.getDescription());
  452. excelDTO.setFileExportType(FileExportType.DEVICE_INFO);
  453. //执行导出
  454. fileExportService.exportExcelAsync(excelDTO);
  455. }
  456. @PostMapping("nearbyPage")
  457. @ApiOperation("附近设备分页查询")
  458. public R<PageBean<DeviceInfoDto.Vo2>> nearbyPage(@RequestBody DeviceInfoDto.Page page) {
  459. if (!Emptys.check(page.getLon()) || !Emptys.check(page.getLat())) {
  460. throw new CommRuntimeException("经纬度不能为空");
  461. }
  462. return R.ok(queryPage(page));
  463. }
  464. @ApiOperation(value = "商户设备授权", hidden = true)
  465. @Override
  466. @Transactional(rollbackFor = Exception.class)
  467. public R<Boolean> mercDeviceAuth(DeviceInfoDto.MercDeviceAuthDto auth) {
  468. Long mercId = auth.getMercId();
  469. String mercCode = auth.getMercCode();
  470. Long algorithmId = auth.getAlgorithmId();
  471. String mercName = auth.getMercName();
  472. //商户最终设备列表
  473. List<Long> deviceIds = auth.getDeviceIds();
  474. List<DeviceInfo> devices = getDevicesByMercId(mercId);
  475. //取消商户设备授权
  476. if (CollUtil.isEmpty(deviceIds)) {
  477. if (CollUtil.isEmpty(devices)) {
  478. return R.ok(Boolean.TRUE);
  479. }
  480. }
  481. //更新商户设备授权
  482. List<DeviceInfo> deviceInfos = this.listByIds(deviceIds);
  483. List<DeviceStatus> deviceStatuses = new ArrayList<>();
  484. for (DeviceInfo deviceInfo : deviceInfos) {
  485. Integer deviceType = deviceInfo.getDeviceType();
  486. Long deviceId = deviceInfo.getDeviceId();
  487. if (ObjectUtil.equals(deviceType, DeviceTypeEnum.TYPE5.getCode())) {
  488. //支付宝设备算法
  489. algorithmId = AlgorithmTypeEnum.ALIPAY.getId();
  490. } else {
  491. //非支付宝算法
  492. if (AlgorithmTypeEnum.CLOUD.getId() == algorithmId) {
  493. //云从算法
  494. boolean b = cloudWalkApiService.checkDeviceExist(deviceId);
  495. if (!b) {
  496. //货柜不存在,新增
  497. cloudWalkApiService.containerAdd(new ContainerAddDTO().setContainerCode(String.valueOf(deviceId)));
  498. }
  499. }
  500. }
  501. int refMercId = deviceInfo.getMercId().intValue();
  502. String refMercCode = deviceInfo.getMercCode();
  503. // 只有解绑后,才能给顶级商户授权
  504. if (refMercId != -1 && refMercId != mercId.intValue()) {
  505. StrBuilder sb = StrBuilder.create();
  506. String errMsg = sb.append("设备[")
  507. .append(deviceInfo.getDeviceId())
  508. .append("]")
  509. .append("已被商户[")
  510. .append(deviceInfo.getMercName())
  511. .append("]绑定,请先进行解绑!")
  512. .toString();
  513. //非质检商户需要进行判断,质检商户跳过
  514. if (!QA_MERC_CODE.equals(refMercCode)) {
  515. //已关联别商户
  516. return R.fail(errMsg, Boolean.FALSE);
  517. }
  518. }
  519. //绑定关系
  520. deviceInfo.setMercId(mercId).setMercCode(mercCode).setAlgorithmId(algorithmId).setMercName(mercName);
  521. //标记机器可交易
  522. DeviceStatus deviceStatus = new DeviceStatus()
  523. .setDeviceId(deviceInfo.getDeviceId())
  524. .setIsPay(true);
  525. deviceStatuses.add(deviceStatus);
  526. }
  527. saveOrUpdateBatch(deviceInfos);
  528. if (Emptys.check(deviceStatuses)) {
  529. deviceStatusService.updateBatchById(deviceStatuses);
  530. }
  531. return R.ok(Boolean.TRUE);
  532. }
  533. /**
  534. * 解绑机器 回收
  535. *
  536. * @param dto
  537. * @return
  538. */
  539. @Override
  540. public R<Boolean> unBindMercDevice(DeviceInfoDto.MercDeviceUnBindDto dto) {
  541. List<DeviceInfo> deviceInfos = this.listByIds(dto.getDeviceIds());
  542. return R.ok(removeMerRefDevicesToTopMerc(deviceInfos));
  543. }
  544. /**
  545. * 回收机器
  546. *
  547. * @param deviceInfos
  548. * @return
  549. */
  550. private Boolean removeMerRefDevicesToTopMerc(List<DeviceInfo> deviceInfos) {
  551. MercDto.Vo mercCheck = R.feignCheckData(mercFeignService.obj(new MercDto.ListDTO().setMercCode(QA_MERC_CODE)));
  552. if (CollUtil.isNotEmpty(deviceInfos)) {
  553. deviceInfos.forEach(deviceInfo -> {
  554. //回收
  555. deviceInfo.setMercId(mercCheck.getId());
  556. deviceInfo.setMercDeviceCode(StrUtil.EMPTY);
  557. deviceInfo.setMercName(mercCheck.getName());
  558. deviceInfo.setMercCode(QA_MERC_CODE);
  559. });
  560. //批量更新
  561. return updateBatchById(deviceInfos);
  562. }
  563. return Boolean.FALSE;
  564. }
  565. /**
  566. * 批量移除商户设备绑定关系
  567. *
  568. * @param deviceInfos
  569. * @return
  570. */
  571. private Boolean removeMerRefDevices(List<DeviceInfo> deviceInfos, Long parentId) {
  572. if (CollUtil.isNotEmpty(deviceInfos) && parentId != null) {
  573. deviceInfos.forEach(deviceInfo -> {
  574. //非顶级兴元商户,解绑后,机器归父商户
  575. if (parentId != 1) {
  576. MercDto.Vo mercParent = R.feignCheckData(mercFeignService.obj(new MercDto.ListDTO().setId(parentId)));
  577. if (mercParent != null) {
  578. deviceInfo.setMercId(mercParent.getId());
  579. deviceInfo.setMercName(mercParent.getName());
  580. deviceInfo.setMercCode(mercParent.getMercCode());
  581. } else {
  582. deviceInfo.setMercId(-1L);
  583. deviceInfo.setMercName(StrUtil.EMPTY);
  584. deviceInfo.setMercCode(StrUtil.EMPTY);
  585. }
  586. }
  587. //一级商户,解绑后,直接释放
  588. if (parentId == 0) {
  589. MercDto.Vo mercCheck = R.feignCheckData(mercFeignService.obj(new MercDto.ListDTO().setMercCode(QA_MERC_CODE)));
  590. if (mercCheck != null) {
  591. deviceInfo.setMercId(mercCheck.getId());
  592. deviceInfo.setMercName(mercCheck.getName());
  593. deviceInfo.setMercCode(mercCheck.getMercCode());
  594. } else {
  595. deviceInfo.setMercId(-1L);
  596. deviceInfo.setMercName(StrUtil.EMPTY);
  597. deviceInfo.setMercCode(StrUtil.EMPTY);
  598. }
  599. }
  600. });
  601. //批量更新
  602. return updateBatchById(deviceInfos);
  603. }
  604. return Boolean.FALSE;
  605. }
  606. @ApiOperation("集合查询")
  607. @Override
  608. public R<List<DeviceInfoDto.Vo>> list(DeviceInfoDto.ListDto dto) {
  609. List<DeviceInfo> list = list(new LambdaQueryWrapper<DeviceInfo>()
  610. .in(CollUtil.isNotEmpty(dto.getDeviceIds()), DeviceInfo::getDeviceId, dto.getDeviceIds())
  611. .eq(Emptys.check(dto.getMercId()), DeviceInfo::getMercId, dto.getMercId())
  612. );
  613. return R.ok(copy(DeviceInfoDto.Vo.class, list));
  614. }
  615. @Override
  616. @ApiOperation("通用集合查询")
  617. public R<List<DeviceInfoDto.Vo>> listCommon(DeviceInfoDto.ListCommon dto) {
  618. String deviceSearch = dto.getDeviceSearch();
  619. DeviceInfoDto.Vo vo = dto.getVo();
  620. QueryWrapper<DeviceInfo> queryWrapper = new MybatisPlusQuery().eqWrapper(vo == null ? new DeviceInfoDto.Vo() : vo, DeviceInfo.class).buildQW();
  621. // List<Long> placeLineIds = dto.getPlaceLineIds();
  622. List<Long> deviceIds = dto.getDeviceIds();
  623. List<String> columnList = dto.getColumnList();
  624. // if (CollUtil.isNotEmpty(placeLineIds)) {
  625. // queryWrapper.in(LambdaUtils.getUnderlineCaseName(DeviceInfo::getPlaceLineId), placeLineIds);
  626. // }
  627. //fixed
  628. if (StrUtil.isNotEmpty(deviceSearch)) {
  629. queryWrapper.and(wrapper -> wrapper.likeRight(LambdaUtils.getUnderlineCaseName(DeviceInfo::getDeviceName), deviceSearch).or()
  630. .eq(LambdaUtils.getUnderlineCaseName(DeviceInfo::getDeviceId), deviceSearch));
  631. }
  632. if (CollUtil.isNotEmpty(columnList)) {
  633. queryWrapper.select(columnList.stream().toArray(String[]::new));
  634. }
  635. if (CollUtil.isNotEmpty(deviceIds)) {
  636. queryWrapper.in(LambdaUtils.getUnderlineCaseName(DeviceInfo::getDeviceId), deviceIds);
  637. }
  638. return R.ok(copy(DeviceInfoDto.Vo.class, list(queryWrapper)));
  639. }
  640. @Override
  641. @ApiOperation("商户设备算法列表")
  642. public R<List<Long>> mercAlgorithmIdList(DeviceInfoDto.MercAlgorithmIdListDto dto) {
  643. String algorithmIdStr = LambdaUtils.getProperty(DeviceInfo::getAlgorithmId);
  644. String mercStr = StringTools.humpToLine(LambdaUtils.getProperty(DeviceInfo::getMercId));
  645. QueryWrapper<DeviceInfo> lqw = new QueryWrapper<DeviceInfo>()
  646. .isNotNull(StringTools.humpToLine(algorithmIdStr))
  647. .eq(mercStr, dto.getMercId())
  648. .select(String.format("DISTINCT (%s) as %s", StringTools.humpToLine(algorithmIdStr), algorithmIdStr));
  649. List<Long> list = listObjs(lqw, (MapperFunction<Object, Long>) o -> (Long) o);
  650. return R.ok(list);
  651. }
  652. @Override
  653. @ApiOperation("小程序-商户设备首页统计")
  654. public R<DeviceInfoDto.MercHomeStatisticalVO> mercHomeStatistical(DeviceInfoDto.MercHomeQueryDTO dto) {
  655. Long mercId = dto.getMercId();
  656. List<Long> myDeviceIds = dto.getMyDeviceIds();
  657. //初始化数据
  658. DeviceInfoDto.MercHomeStatisticalVO mercHomeStatisticalVO = new DeviceInfoDto.MercHomeStatisticalVO()
  659. .setClosedNum(0).setOfflineNum(0)
  660. .setOnlineNum(0).setOperatingNum(0).setNeedToFillNum(0);
  661. if (CollUtil.isEmpty(myDeviceIds)) {
  662. return R.ok(mercHomeStatisticalVO);
  663. }
  664. List<DeviceInfo> mercDevices = listByIds(myDeviceIds);
  665. if (CollUtil.isEmpty(mercDevices)) {
  666. return R.ok(mercHomeStatisticalVO);
  667. }
  668. //在线、离线
  669. List<DeviceStatus> deviceStatuses = deviceStatusService.listByIds(myDeviceIds);
  670. //分组统计
  671. Map<Integer, Long> countNetstateMap = deviceStatuses.stream().collect(Collectors
  672. .groupingBy(DeviceStatus::getNetState, Collectors.counting()));
  673. Integer onlineDictValue = SysDictUtils.getValue(EnumDeviceOnlineStatus.Code.CODE.getCode(), EnumDeviceOnlineStatus.CONNECTED.getCode(), Integer.class);
  674. Integer offlineDictValue = SysDictUtils.getValue(EnumDeviceOnlineStatus.Code.CODE.getCode(), EnumDeviceOnlineStatus.DISCONNECT.getCode(), Integer.class);
  675. int onlineNum = countNetstateMap.get(onlineDictValue) == null ? 0 : countNetstateMap.get(onlineDictValue).intValue();
  676. int offlineNum = countNetstateMap.get(offlineDictValue) == null ? 0 : countNetstateMap.get(offlineDictValue).intValue();
  677. mercHomeStatisticalVO.setOnlineNum(onlineNum);
  678. mercHomeStatisticalVO.setOfflineNum(offlineNum);
  679. //锁机、未锁机
  680. Map<Integer, Long> countLockLstateMap = deviceStatuses.stream().collect(Collectors
  681. .groupingBy(DeviceStatus::getLockStateL, Collectors.counting()));
  682. Long lockLStateNum = countLockLstateMap.get(DeviceLockState.LOCK.getCode());
  683. Long unLockLStateNum = countLockLstateMap.get(DeviceLockState.UN_LOCK.getCode());
  684. mercHomeStatisticalVO.setOperatingNum(unLockLStateNum == null ? 0 : unLockLStateNum.intValue());
  685. mercHomeStatisticalVO.setClosedNum(lockLStateNum == null ? 0 : lockLStateNum.intValue());
  686. //待补货
  687. Integer deviceNum = R.feignCheckData(goodsDeviceService.countOutOfStockDevice(new GoodsDeviceDto.CountOutOfStockDevice().setMercId(mercId)));
  688. mercHomeStatisticalVO.setNeedToFillNum(deviceNum);
  689. return R.ok(mercHomeStatisticalVO);
  690. }
  691. @Override
  692. @ApiOperation("小程序-商户设备首页列表")
  693. public R<List<DeviceInfoDto.MercHomeListVO>> mercHomeList(DeviceInfoDto.MercHomeQueryDTO dto) {
  694. String searchKey = dto.getSearchKey();
  695. Long mercId = dto.getMercId();
  696. String deviceName = dto.getDeviceName();
  697. Long deviceId = dto.getDeviceId();
  698. boolean isQa = false;
  699. if ("393010594508869".equals(String.valueOf(mercId))) {
  700. isQa = true;
  701. } else {
  702. dto.setActiveState("1");
  703. }
  704. List<Long> searchDeviceIds = new ArrayList<>();
  705. if (StrUtil.isNotEmpty(searchKey)) {
  706. //名称或者编号搜索设备
  707. List<DeviceInfo> list = list(Wrappers.<DeviceInfo>lambdaQuery()
  708. .eq(DeviceInfo::getMercId, mercId)
  709. .and(wrapper -> wrapper
  710. .eq(DeviceInfo::getDeviceId, searchKey)
  711. .or()
  712. .likeRight(DeviceInfo::getDeviceName, searchKey)
  713. )
  714. );
  715. if (CollUtil.isEmpty(list)) {
  716. return R.ok(new ArrayList<>());
  717. }
  718. searchDeviceIds = list.stream().map(DeviceInfo::getDeviceId).collect(Collectors.toList());
  719. }
  720. List<Long> myDeviceIds = dto.getDeviceIdList();
  721. Integer busyStatus = dto.getBusyStatus();
  722. Integer onlineStatus = dto.getOnlineStatus();
  723. Integer deviceType = dto.getDeviceType();
  724. //条件查询 在线状态,运营状态,设备类型,
  725. List<Long> deviceIdList = new ArrayList<>();
  726. if (deviceId != null && myDeviceIds.indexOf(deviceId) > 0) {
  727. deviceIdList.add(deviceId);
  728. }
  729. if (CollUtil.isNotEmpty(myDeviceIds) && deviceId == null) {
  730. deviceIdList.addAll(myDeviceIds);
  731. }
  732. if (CollUtil.isNotEmpty(deviceIdList)) {
  733. dto.setDeviceIdList(deviceIdList);
  734. List<Long> queryDeviceIds = new ArrayList<>();
  735. if (CollUtil.isNotEmpty(searchDeviceIds)) {
  736. for (Long id : searchDeviceIds) {
  737. int index = deviceIdList.indexOf(id);
  738. if (index > 0) {
  739. queryDeviceIds.add(id);
  740. }
  741. }
  742. //无符合权限的搜索设备,返空
  743. if (CollUtil.isEmpty(queryDeviceIds)) {
  744. return R.ok(new ArrayList<>());
  745. } else {
  746. deviceIdList = queryDeviceIds;
  747. dto.setDeviceIdList(queryDeviceIds);
  748. }
  749. }
  750. } else {
  751. return R.ok(new ArrayList<>());
  752. }
  753. if (onlineStatus != null) {
  754. List<DeviceStatus> deviceStatusList = deviceStatusService.list(Wrappers.<DeviceStatus>lambdaQuery()
  755. .eq(DeviceStatus::getNetState, onlineStatus)
  756. .in(CollUtil.isNotEmpty(myDeviceIds), DeviceStatus::getDeviceId, deviceIdList)
  757. );
  758. if (CollUtil.isNotEmpty(deviceStatusList)) {
  759. List<Long> dbDeviceIdList = deviceStatusList.stream().map(DeviceStatus::getDeviceId).collect(Collectors.toList());
  760. deviceIdList = dbDeviceIdList;
  761. } else {
  762. return R.ok(new ArrayList<>());
  763. }
  764. }
  765. List<DeviceInfoDto.MercHomeCountVO> list = this.baseMapper.merHomeCountList(dto);
  766. if (CollUtil.isEmpty(list)) {
  767. return R.ok(Collections.emptyList());
  768. }
  769. List<DeviceInfoDto.MercHomeListVO> dataList = new ArrayList<>(list.size());
  770. LambdaQueryWrapper<DeviceInfo> lqw = new LambdaQueryWrapper<>();
  771. //非质检商户才需要激活
  772. lqw.eq(!isQa, DeviceInfo::getActiveState, DeviceActiveStateEnum.TRUE.getCode());
  773. lqw.eq(mercId != null, DeviceInfo::getMercId, mercId);
  774. lqw.eq(busyStatus != null, DeviceInfo::getBusyState, busyStatus);
  775. lqw.eq(deviceType != null, DeviceInfo::getDeviceType, deviceType);
  776. lqw.in(CollUtil.isNotEmpty(deviceIdList), DeviceInfo::getDeviceId, deviceIdList);
  777. lqw.like(StrUtil.isNotEmpty(deviceName), DeviceInfo::getDeviceName, deviceName).orderByAsc(true, DeviceInfo::getDeviceName, DeviceInfo::getDeviceId);
  778. List<DeviceInfo> deviceInfoList = this.list(lqw);
  779. //未分区域的设置默认值
  780. deviceInfoList.stream().filter(s -> s.getDistrictId() == null).forEach(s -> s.setDistrictId(-1L));
  781. Map<Long, String> districtMap = new HashMap<>();
  782. List<Long> districtIdList = list.stream().map(DeviceInfoDto.MercHomeCountVO::getDistrictId).filter(i -> i != -1).collect(Collectors.toList());
  783. districtMap = mercRegionService.getNameList(new MercRegionDto.GetNameListDto().setIds(districtIdList)).getData();
  784. //根据区域id分组
  785. Map<Long, List<DeviceInfo>> deviceMap = deviceInfoList.stream().collect(Collectors.groupingBy(DeviceInfo::getDistrictId));
  786. DateTime date = DateTime.now();
  787. DateTime start = DateUtil.beginOfDay(date);
  788. DateTime end = DateUtil.endOfDay(date);
  789. for (DeviceInfoDto.MercHomeCountVO v : list) {
  790. DeviceInfoDto.MercHomeListVO vo = new DeviceInfoDto.MercHomeListVO();
  791. Long districtId = v.getDistrictId();
  792. vo.setDeviceNum(v.getDeviceNum());
  793. vo.setDistrictId(v.getDistrictId());
  794. vo.setDistrictName(v.getDistrictId() == -1L ? "未分配区域" : districtMap.get(v.getDistrictId()));
  795. //区域下的设备列表
  796. List<DeviceInfoDto.MercHomeDeviceVo> deviceInfos = BeanUtil.copyToList(deviceMap.get(districtId), DeviceInfoDto.MercHomeDeviceVo.class);
  797. if (CollUtil.isEmpty(deviceInfos)) {
  798. continue;
  799. }
  800. //设备销售统计
  801. List<Long> deviceIds = deviceInfos.stream().map(DeviceInfoDto.MercHomeDeviceVo::getDeviceId).collect(Collectors.toList());
  802. //设备状态查询
  803. List<DeviceStatusDto.Vo> deviceStatusList = deviceStatusService.list(new DeviceStatusDto.SelectList().setDeviceIds(deviceIds)).getData();
  804. Map<Long, DeviceStatusDto.Vo> datdeviceStatusMap = new HashMap<>();
  805. if (CollUtil.isNotEmpty(deviceStatusList)) {
  806. datdeviceStatusMap = deviceStatusList.stream().collect(Collectors.toMap(DeviceStatusDto.Vo::getDeviceId, d -> d));
  807. }
  808. List<GoodsDeviceDto.Vo> goodsDeviceList = R.feignCheckData(goodsService.queryGoodsDeviceInfo(new GoodsDto.QueryGoodsDeviceInfo().setMercId(mercId).setDeviceIds(deviceIds)));
  809. Map<Long, List<GoodsDeviceDto.Vo>> deviceIdGoodsMap = goodsDeviceList.stream()
  810. .collect(Collectors.groupingBy(GoodsDeviceDto.Vo::getDeviceId));
  811. List<AlgorithmDto.ListNameId> algorithmList = R.feignCheckData(algorithmService.ListNameId());
  812. Map<Long, String> algorithmListMap = algorithmList.stream().collect(Collectors.toMap(AlgorithmDto.ListNameId::getId, AlgorithmDto.ListNameId::getAlias));
  813. for (DeviceInfoDto.MercHomeDeviceVo device : deviceInfos) {
  814. Long dId = device.getDeviceId();
  815. //设备类型 反显
  816. SysDictRedis dictDeviceType = SysDictUtils.get(DictConsts.DEVICE_TYPE, String.valueOf(device.getDeviceType()));
  817. device.setDeviceTypeName(dictDeviceType.getMsg());
  818. //运营状态 反显
  819. SysDictRedis dictBusyState = SysDictUtils.get(DictConsts.DEVICE_BUSY_STATUS, String.valueOf(device.getBusyState()));
  820. device.setBusyStateName(dictBusyState.getMsg());
  821. Integer zero = new Integer(0);
  822. CountDto.OrderByCreateTimeAndMercId orderByCreateTimeAndMercId = new CountDto.OrderByCreateTimeAndMercId()
  823. .setMerdId(mercId).setBeginTime(start).setEndTime(end).setDeviceIds(CollUtil.newArrayList(dId));
  824. log.info("设备订单统计:{}", JSONUtil.toJsonPrettyStr(orderByCreateTimeAndMercId));
  825. //完成订单
  826. CountDto.SuccessVo successVo = R.feignCheckData(countApiService.orderBySuccess(orderByCreateTimeAndMercId));
  827. //今日销售、库存情况 反显
  828. device.setDayOrderNum(successVo != null ? successVo.getOrdersSize() : zero);
  829. device.setDaySalesPrice(successVo != null ? successVo.getOrderTotalMoney() : zero);
  830. DeviceStatusDto.Vo deviceStatus = datdeviceStatusMap.get(device.getDeviceId());
  831. if (CollUtil.isNotEmpty(deviceIdGoodsMap)) {
  832. List<GoodsDeviceDto.Vo> goodsDevice = deviceIdGoodsMap.get(dId);
  833. if (CollUtil.isNotEmpty(goodsDevice)) {
  834. device.setOnSaleNum(goodsDevice.stream().mapToInt(GoodsDeviceDto.Vo::getStock).sum());
  835. device.setFillNum(goodsDevice.stream().mapToInt(GoodsDeviceDto.Vo::getFillCount).sum());
  836. }
  837. }
  838. //算法類型
  839. Long algorithmId = device.getAlgorithmId();
  840. if (algorithmId != null) {
  841. String name = algorithmListMap.get(algorithmId);
  842. device.setAlgorithmAlias(name);
  843. }
  844. //联网状态
  845. Integer netState = deviceStatus == null ? DeviceNetSateType.DISCONNECT.getCode() : deviceStatus.getNetState();
  846. device.setNetState(netState);
  847. if (netState == null) {
  848. device.setNetStateName(StrUtil.EMPTY);
  849. } else {
  850. device.setNetStateName(DeviceNetSateType.getEnumByCode(netState).getDescription());
  851. }
  852. if (deviceStatus != null) {
  853. Integer deviceStateL = deviceStatus.getLockStateL();
  854. Integer deviceStateR = deviceStatus.getLockStateR();
  855. device.setTempValue(deviceStatus.getTempValue());
  856. device.setDeviceStateL(deviceStateL);
  857. device.setDeviceStateR(deviceStateR);
  858. device.setSysPower(deviceStatus.getSysPower());
  859. DeviceLockState deviceLockStateL = DeviceLockState.getEnumByCode(deviceStateL);
  860. DeviceLockState deviceLockStateR = DeviceLockState.getEnumByCode(deviceStateR);
  861. device.setDeviceStateRName(deviceLockStateR == null ? "未知" : deviceLockStateR.getDescription());
  862. device.setDeviceStateLName(deviceLockStateL == null ? "未知" : deviceLockStateL.getDescription());
  863. }
  864. }
  865. //名称排序
  866. if (CollUtil.isNotEmpty(deviceInfos)) {
  867. deviceInfos = ListUtil.sortByProperty(deviceInfos, LambdaUtils.getProperty(DeviceInfoDto.MercHomeDeviceVo::getDeviceName));
  868. deviceInfos = ListUtil.sortByProperty(deviceInfos, LambdaUtils.getProperty(DeviceInfoDto.MercHomeDeviceVo::getDeviceId));
  869. }
  870. vo.setDeviceInfos(deviceInfos);
  871. dataList.add(vo);
  872. }
  873. return R.ok(dataList);
  874. }
  875. /**
  876. * 获取商户设备列表
  877. *
  878. * @param mercId
  879. * @return
  880. */
  881. private List<DeviceInfo> getDevicesByMercId(Long mercId) {
  882. return list(Wrappers.<DeviceInfo>lambdaQuery().eq(DeviceInfo::getMercId, mercId).eq(DeviceInfo::getActiveState, DeviceActiveStateEnum.TRUE.getCode()));
  883. }
  884. /**
  885. * 小程序商户设备搜索
  886. *
  887. * @param page
  888. * @return
  889. */
  890. @Override
  891. public R<PageBean<DeviceInfoDto.MerHomeSearchVO>> mercDeviceSearchPage(@RequestBody DeviceInfoDto.Page page) {
  892. PageBean<DeviceInfoDto.MerHomeSearchVO> pageData = new PageBean<>();
  893. //小程序独有查询字段 缺货状态:stockStatus ,是否查故障设备:fault
  894. Boolean fault = page.getFault();
  895. Long mercId = page.getMercId();
  896. List<Long> myDeviceIds = page.getMyDeviceIds();
  897. if (CollUtil.isEmpty(myDeviceIds)) {
  898. //无设备
  899. return R.ok(pageData);
  900. }
  901. if (BooleanUtil.isTrue(fault)) {
  902. //查询故障设备
  903. List<DeviceEventMsg> deviceEventMsgs = deviceEventMsgService.list(Wrappers.<DeviceEventMsg>lambdaQuery()
  904. .eq(mercId != null, DeviceEventMsg::getMercId, page.getMercId())
  905. .in(DeviceEventMsg::getDeviceId, myDeviceIds));
  906. List<Long> deviceIdList = deviceEventMsgs.stream().map(DeviceEventMsg::getDeviceId).collect(Collectors.toList());
  907. if (CollUtil.isEmpty(deviceIdList)) {
  908. return R.ok(new PageBean<>());
  909. }
  910. page.setDeviceIdList(deviceIdList);
  911. } else {
  912. page.setDeviceIdList(myDeviceIds);
  913. }
  914. PageBean<DeviceInfoDto.Vo2> pageBean = queryPage(page);
  915. List<DeviceInfoDto.Vo2> records = pageBean.getRecords();
  916. if (CollUtil.isEmpty(records)) {
  917. return R.ok(pageData);
  918. }
  919. List<DeviceInfoDto.MerHomeSearchVO> merHomeSearchRecords = new ArrayList<>();
  920. BeanUtil.copyProperties(pageBean, pageData);
  921. if (CollUtil.isNotEmpty(records)) {
  922. List<Long> deviceIds = records.stream().map(DeviceInfoDto.Vo2::getDeviceId).collect(Collectors.toList());
  923. String type = EnumDeviceDataType.DAY.getCode();
  924. String todayDate = DateUtil.format(new Date(), DatePattern.PURE_DATE_PATTERN);
  925. //查询当天
  926. DeviceDataDto.ListDTO dto = new DeviceDataDto.ListDTO()
  927. .setDeviceIds(deviceIds).setType(type).setDateValue(Integer.valueOf(todayDate)).setMercId(mercId);
  928. List<DeviceDataDto.Vo> deviceDataList = deviceDataService.list(dto);
  929. Map<Long, DeviceDataDto.Vo> dataMap = MapUtil.newHashMap();
  930. //统计数据反显
  931. if (CollUtil.isNotEmpty(deviceDataList)) {
  932. dataMap = deviceDataList.stream().collect(Collectors.toMap(DeviceDataDto.Vo::getDeviceId, d -> d));
  933. }
  934. for (DeviceInfoDto.Vo2 v : records) {
  935. DeviceInfoDto.MerHomeSearchVO merHomeSearchVO = new DeviceInfoDto.MerHomeSearchVO();
  936. Long deviceId = v.getDeviceId();
  937. DeviceDataDto.Vo vo = dataMap.get(deviceId);
  938. if (vo != null) {
  939. //今日订单数
  940. v.setDayOrderNum(vo != null ? vo.getSalesCount() : 0);
  941. v.setDaySalesPrice(vo != null ? vo.getSalesMoney() : 0);
  942. BeanUtil.copyProperties(vo, merHomeSearchVO);
  943. }
  944. DeviceSysinfoDto.Vo deviceSysinfo = v.getDeviceSysinfo();
  945. DeviceStatusDto.Vo deviceStatus = v.getDeviceStatus();
  946. merHomeSearchVO.setAppUpmVersion(deviceSysinfo.getAppUpmVersion());
  947. merHomeSearchVO.setTempValue(deviceStatus.getTempValue());
  948. merHomeSearchVO.setNetDbm(deviceStatus.getNetDbm());
  949. Integer deviceStateL = deviceStatus.getLockStateL();
  950. Integer deviceStateR = deviceStatus.getLockStateR();
  951. merHomeSearchVO.setDeviceStateL(deviceStateL);
  952. merHomeSearchVO.setDeviceStateR(deviceStateR);
  953. DeviceLockState deviceLockStateL = DeviceLockState.getEnumByCode(deviceStateL);
  954. DeviceLockState deviceLockStateR = DeviceLockState.getEnumByCode(deviceStateR);
  955. merHomeSearchVO.setDeviceStateRName(deviceLockStateR == null ? "未知" : deviceLockStateR.getDescription());
  956. merHomeSearchVO.setDeviceStateLName(deviceLockStateL == null ? "未知" : deviceLockStateL.getDescription());
  957. merHomeSearchRecords.add(merHomeSearchVO);
  958. }
  959. pageData.setRecords(merHomeSearchRecords);
  960. }
  961. return R.ok(pageData);
  962. }
  963. /**
  964. * 小程序商户设备详情-数据统计
  965. *
  966. * @param dto
  967. * @return
  968. */
  969. @Override
  970. @ApiOperation("商户设备详情-数据统计")
  971. public R<DeviceInfoDto.DeviceDataCountVO> dataCount(DeviceInfoDto.DeviceDataCountDTO dto) {
  972. // 统计类型(1=经营数据,2=经营图表,3=温度图表,4=信号图表,5=商品管理)
  973. Integer type = dto.getType();
  974. switch (type) {
  975. case 1:
  976. //经营数据
  977. return R.ok(dataCount1(dto));
  978. case 2:
  979. //经营图表
  980. return R.ok(dataCount2(dto));
  981. case 3:
  982. //温度图表
  983. return R.ok(dataCount3(dto));
  984. case 4:
  985. //信号图表
  986. return R.ok(dataCount4(dto));
  987. case 5:
  988. //商品管理
  989. return R.ok(dataCount5(dto));
  990. default:
  991. break;
  992. }
  993. return R.ok();
  994. }
  995. /**
  996. * 经营数据
  997. *
  998. * @param dto
  999. * @return
  1000. */
  1001. private DeviceInfoDto.DeviceDataCountVO dataCount1(DeviceInfoDto.DeviceDataCountDTO dto) {
  1002. Long deviceId = dto.getDeviceId();
  1003. Long mercId = dto.getMercId();
  1004. DeviceInfoDto.DeviceDataCountVO vo = new DeviceInfoDto.DeviceDataCountVO();
  1005. //当天
  1006. DateTime date = DateTime.now();
  1007. DateTime start = DateUtil.beginOfDay(date);
  1008. DateTime end = DateUtil.endOfDay(date);
  1009. List<Long> deviceIds = CollUtil.newArrayList(deviceId);
  1010. CountDto.OrderByCreateTimeAndMercId orderByCreateTimeAndMercId = new CountDto.OrderByCreateTimeAndMercId()
  1011. .setMerdId(mercId).setBeginTime(start).setEndTime(end).setDeviceIds(deviceIds);
  1012. //完成订单
  1013. CountDto.SuccessVo successVo = R.feignCheckData(countApiService.orderBySuccess(orderByCreateTimeAndMercId));
  1014. DeviceDataDto.Vo dayData = new DeviceDataDto.Vo();
  1015. if (successVo != null) {
  1016. dayData.setSalesMoney(successVo.getOrderTotalMoney());
  1017. dayData.setRefundMoney(successVo.getRefundMoney());
  1018. dayData.setSalesCount(successVo.getOrdersSize());
  1019. }
  1020. //当月
  1021. DeviceDataDto.Vo monthData = new DeviceDataDto.Vo();
  1022. //月度统计
  1023. DateTime startM = DateUtil.beginOfMonth(date);
  1024. DateTime endM = DateUtil.endOfMonth(date);
  1025. CountDto.OrderByCreateTimeAndMercId monthOrder = new CountDto.OrderByCreateTimeAndMercId()
  1026. .setMerdId(mercId).setBeginTime(startM).setEndTime(endM).setDeviceIds(deviceIds);
  1027. //完成订单
  1028. CountDto.SuccessVo successVoM = R.feignCheckData(countApiService.orderBySuccess(monthOrder));
  1029. if (monthData != null) {
  1030. monthData.setRefundMoney(successVoM.getRefundMoney());
  1031. monthData.setSalesMoney(successVoM.getOrderTotalMoney());
  1032. monthData.setSalesCount(successVoM.getOrdersSize());
  1033. }
  1034. vo.setDayBusinessData(copy(DeviceInfoDto.BusinessData.class, dayData));
  1035. vo.setMonthBusinessData(copy(DeviceInfoDto.BusinessData.class, monthData));
  1036. return vo;
  1037. }
  1038. /**
  1039. * 经营图表
  1040. *
  1041. * @param dto
  1042. * @return
  1043. */
  1044. private DeviceInfoDto.DeviceDataCountVO dataCount2(DeviceInfoDto.DeviceDataCountDTO dto) {
  1045. Long deviceId = dto.getDeviceId();
  1046. //近一个月 (销售额,订单数,退款金额,退款数)
  1047. DeviceInfoDto.DeviceDataCountVO vo = new DeviceInfoDto.DeviceDataCountVO();
  1048. DeviceInfoDto.BusinessChart businessChart = new DeviceInfoDto.BusinessChart();
  1049. List<String> categories = DataTime.dayListByLastDay(30);
  1050. List<Integer> dateList = new ArrayList<>(30);
  1051. businessChart.setCategories(categories);
  1052. categories.forEach(d -> {
  1053. dateList.add(Integer.valueOf(d.replaceAll(StrUtil.DASHED, StrUtil.EMPTY)));
  1054. });
  1055. Integer startDay = dateList.get(0);
  1056. Integer endDay = dateList.get(categories.size() - 1);
  1057. List<DeviceDataDto.Vo> listByDay = deviceDataService.getListByDay(deviceId, startDay, endDay);
  1058. if (CollUtil.isEmpty(listByDay)) {
  1059. return vo;
  1060. }
  1061. //每天的数据
  1062. Map<Integer, DeviceDataDto.Vo> dataDayMap = listByDay.stream().collect(Collectors.toMap(DeviceDataDto.Vo::getDateValue, i -> i));
  1063. List<DeviceInfoDto.MyChartSeries3> series = new ArrayList<>();
  1064. String[] names = {"销售额", "订单数", "退款金额", "退款数"};
  1065. for (int i = 0; i < names.length; i++) {
  1066. DeviceInfoDto.MyChartSeries3 myChartSeries = new DeviceInfoDto.MyChartSeries3();
  1067. //某个类型每天的数据
  1068. List<String> data = new ArrayList<>();
  1069. if (i == 0) {
  1070. //销售额
  1071. dateList.forEach(d -> {
  1072. //每日数据填充
  1073. DeviceDataDto.Vo deviceData = dataDayMap.get(d);
  1074. if (deviceData == null) {
  1075. data.add(String.valueOf(BigDecimal.ZERO));
  1076. } else {
  1077. Integer salesMoney = deviceData.getSalesMoney() == null ? 0 : deviceData.getSalesMoney();
  1078. BigDecimal day = BigDecimal.valueOf(salesMoney).divide(BigDecimal.valueOf(100));
  1079. data.add(String.valueOf(day));
  1080. }
  1081. });
  1082. } else if (i == 1) {
  1083. //订单数
  1084. dateList.forEach(d -> {
  1085. //每日数据填充
  1086. DeviceDataDto.Vo deviceData = dataDayMap.get(d);
  1087. String value = "0";
  1088. if (deviceData == null) {
  1089. data.add(value);
  1090. } else {
  1091. data.add(deviceData == null ? value : String.valueOf(deviceData.getSalesCount()));
  1092. }
  1093. });
  1094. } else if (i == 2) {
  1095. //退款金额
  1096. dateList.forEach(d -> {
  1097. //每日数据填充
  1098. DeviceDataDto.Vo deviceData = dataDayMap.get(d);
  1099. if (deviceData == null) {
  1100. data.add(String.valueOf(BigDecimal.ZERO));
  1101. } else {
  1102. Integer refundMoney = deviceData.getRefundMoney() == null ? 0 : deviceData.getRefundMoney();
  1103. BigDecimal day = BigDecimal.valueOf(refundMoney).divide(BigDecimal.valueOf(100));
  1104. data.add(String.valueOf(day));
  1105. }
  1106. });
  1107. } else if (i == 3) {
  1108. //退款数
  1109. dateList.forEach(d -> {
  1110. //每日数据填充
  1111. DeviceDataDto.Vo deviceData = dataDayMap.get(d);
  1112. if (deviceData == null) {
  1113. data.add("0");
  1114. } else {
  1115. data.add(deviceData == null ? "0" : String.valueOf(deviceData.getRefundCount()));
  1116. }
  1117. });
  1118. }
  1119. myChartSeries.setName(names[i]);
  1120. myChartSeries.setData(data);
  1121. series.add(myChartSeries);
  1122. }
  1123. businessChart.setSeries(series);
  1124. vo.setBusinessChart(businessChart);
  1125. return vo;
  1126. }
  1127. /**
  1128. * 温度图表
  1129. *
  1130. * @param dto
  1131. * @return
  1132. */
  1133. private DeviceInfoDto.DeviceDataCountVO dataCount3(DeviceInfoDto.DeviceDataCountDTO dto) {
  1134. DeviceInfoDto.DeviceDataCountVO vo = new DeviceInfoDto.DeviceDataCountVO();
  1135. Long deviceId = dto.getDeviceId();
  1136. String choosDate = dto.getChoosDate();
  1137. if (StrUtil.isEmpty(choosDate)) {
  1138. choosDate = DateUtil.formatDate(new Date());
  1139. }
  1140. String startTime = choosDate + " 00:00:00";
  1141. String endTime = choosDate + " 23:59:59";
  1142. //查询选定日期的温度数据
  1143. List<DeviceTempRecords> deviceTempRecords = deviceTempRecordsService.list(Wrappers.<DeviceTempRecords>lambdaQuery()
  1144. .eq(DeviceTempRecords::getDeviceId, deviceId).between(DeviceTempRecords::getCreateTime, startTime, endTime)
  1145. .orderBy(true, true, DeviceTempRecords::getCreateTime));
  1146. if (CollUtil.isEmpty(deviceTempRecords)) {
  1147. return vo;
  1148. }
  1149. DeviceInfoDto.TemperatureChart temperatureChart = new DeviceInfoDto.TemperatureChart();
  1150. List<String> categories = new ArrayList<>();
  1151. String name = "温度";
  1152. List<DeviceInfoDto.MyChartSeries2> series = new ArrayList<>();
  1153. List<BigDecimal> data = new ArrayList<>();
  1154. deviceTempRecords.forEach(d -> {
  1155. Integer tempValue = d.getTempValue();
  1156. LocalDateTime createTime = d.getCreateTime();
  1157. String time = DateUtil.format(createTime, "HH:mm:ss");
  1158. categories.add(time);
  1159. data.add(tempValue == null ? null : NumberUtil.toBigDecimal(tempValue));
  1160. });
  1161. DeviceInfoDto.MyChartSeries2 myChartSeries = new DeviceInfoDto.MyChartSeries2();
  1162. myChartSeries.setName(name);
  1163. myChartSeries.setData(data);
  1164. series.add(myChartSeries);
  1165. temperatureChart.setSeries(series);
  1166. temperatureChart.setCategories(categories);
  1167. vo.setTemperatureChart(temperatureChart);
  1168. return vo;
  1169. }
  1170. /**
  1171. * 信号图表
  1172. *
  1173. * @param dto
  1174. * @return
  1175. */
  1176. private DeviceInfoDto.DeviceDataCountVO dataCount4(DeviceInfoDto.DeviceDataCountDTO dto) {
  1177. DeviceInfoDto.DeviceDataCountVO vo = new DeviceInfoDto.DeviceDataCountVO();
  1178. Long deviceId = dto.getDeviceId();
  1179. String choosDate = dto.getChoosDate();
  1180. if (StrUtil.isEmpty(choosDate)) {
  1181. choosDate = DateUtil.formatDate(new Date());
  1182. }
  1183. String startTime = choosDate + " 00:00:00";
  1184. String endTime = choosDate + " 23:59:59";
  1185. //查询选定日期的温度数据
  1186. List<DeviceNetRecord> deviceNetRecords = deviceNetRecordService.list(Wrappers.<DeviceNetRecord>lambdaQuery()
  1187. .eq(DeviceNetRecord::getDeviceId, deviceId).between(DeviceNetRecord::getCreateTime, startTime, endTime)
  1188. .orderBy(true, true, DeviceNetRecord::getCreateTime));
  1189. if (CollUtil.isEmpty(deviceNetRecords)) {
  1190. return vo;
  1191. }
  1192. DeviceInfoDto.SignalChart signalChart = new DeviceInfoDto.SignalChart();
  1193. List<String> categories = new ArrayList<>();
  1194. String name = "信号";
  1195. List<DeviceInfoDto.MyChartSeries> series = new ArrayList<>();
  1196. List<Integer> data = new ArrayList<>();
  1197. deviceNetRecords.forEach(d -> {
  1198. Integer value = d.getSimDbm();
  1199. LocalDateTime createTime = d.getCreateTime();
  1200. String time = DateUtil.format(createTime, "HH:mm:ss");
  1201. categories.add(time);
  1202. data.add(value);
  1203. });
  1204. DeviceInfoDto.MyChartSeries myChartSeries = new DeviceInfoDto.MyChartSeries();
  1205. myChartSeries.setName(name);
  1206. myChartSeries.setData(data);
  1207. series.add(myChartSeries);
  1208. signalChart.setSeries(series);
  1209. signalChart.setCategories(categories);
  1210. vo.setSignalChart(signalChart);
  1211. return vo;
  1212. }
  1213. /**
  1214. * 商品管理
  1215. *
  1216. * @param dto
  1217. * @return
  1218. */
  1219. private DeviceInfoDto.DeviceDataCountVO dataCount5(DeviceInfoDto.DeviceDataCountDTO dto) {
  1220. Long deviceId = dto.getDeviceId();
  1221. DeviceInfoDto.DeviceDataCountVO vo = new DeviceInfoDto.DeviceDataCountVO();
  1222. DeviceInfoDto.GoodsData goodsData = new DeviceInfoDto.GoodsData();
  1223. //在售商品种类
  1224. //根据设备ID查商品id
  1225. GoodsDeviceDto.SelectList selectList = new GoodsDeviceDto.SelectList();
  1226. selectList.setDeviceIds(CollUtil.newArrayList(deviceId));
  1227. selectList.setMercId(dto.getMercId());
  1228. R<List<GoodsDeviceDto.Vo>> r = R.feignCheck(goodsDeviceService.list(selectList));
  1229. List<GoodsDeviceDto.Vo> goodsDeviceList = r.getData();
  1230. Integer stock = 0;
  1231. Integer afterFillStock = 0;
  1232. if (CollUtil.isNotEmpty(goodsDeviceList)) {
  1233. stock = goodsDeviceList.stream().mapToInt(GoodsDeviceDto.Vo::getStock).sum();
  1234. afterFillStock = goodsDeviceList.stream().mapToInt(GoodsDeviceDto.Vo::getFillCount).sum();
  1235. }
  1236. goodsData.setAfterFillStock(afterFillStock);
  1237. goodsData.setStock(stock);
  1238. goodsData.setCategoryNum(CollUtil.isNotEmpty(goodsDeviceList) ? goodsDeviceList.size() : new Integer(0));
  1239. vo.setGoodsData(goodsData);
  1240. return vo;
  1241. }
  1242. public PageBean<DeviceInfoDto.Vo2> queryPage(DeviceInfoDto.Page page) {
  1243. IPage<DeviceInfoQueryPage> iPage = baseMapper.queryPage(toIPage(page.getPage()), page);
  1244. return toPageBean(DeviceInfoDto.Vo2.class, iPage);
  1245. }
  1246. private <T> void check(T value, T value2, String msg) {
  1247. if (value.toString().equals(value2.toString())) {
  1248. throw new CommRuntimeException(msg);
  1249. }
  1250. }
  1251. }