DeviceInfoServiceImpl.java 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380
  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. Long strategyId = dto.getStrategyId();
  111. List<Long> deviceIds = new ArrayList<>();
  112. if (strategyId != null) {
  113. GoodsDeviceDto.SelectList selectList = new GoodsDeviceDto.SelectList();
  114. selectList.setMercId(mercId).setPriceStrategyId(strategyId);
  115. List<GoodsDeviceDto.Vo> goodsDevices = R.feignCheckData(goodsDeviceService.list(selectList));
  116. if (CollUtil.isEmpty(goodsDevices)) {
  117. log.info("111111111111111111111111");
  118. return R.ok(new PageBean<>());
  119. }
  120. deviceIds = goodsDevices.stream().map(GoodsDeviceDto.Vo::getDeviceId).collect(Collectors.toList());
  121. }
  122. LambdaQueryWrapper<DeviceInfo> lqw = new MybatisPlusQuery().eqWrapper(dto, DeviceInfo.class)
  123. .build();
  124. lqw.in(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. check(obj.getDoor() != null && obj.getDoor() == 1 ? deviceStatus.getDoorStateR() : deviceStatus.getDoorStateL(), 1, "设备正在使用中,请稍后");
  312. //质检用户不检查
  313. SysDictRedis qualitySets = SysDictUtils.get(EnumQualityMercSets.Code.CODE.getCode(), EnumQualityMercSets.MERC_CODE.getCode());
  314. if (!qualitySets.getValue().equals(deviceInfo.getMercCode())) {
  315. check(deviceInfo.getFreezeStatus(), 2, "设备已冻结");
  316. check(obj.getDoor() != null && obj.getDoor() == 1 ? deviceStatus.getLockStateR() : deviceStatus.getLockStateL(), 2, "设备已锁机");
  317. }
  318. return R.ok(deviceInfo);
  319. }
  320. @PostMapping("historyList")
  321. @ApiOperation("设备访问历史查询")
  322. public R<List<DeviceInfoDto.Vo>> historyList() {
  323. //获取redis
  324. String key = keyPrefix + AuthorizeUtils.getLoginId(Long.class);
  325. List<String> deviceIds = redisService.getList(key);
  326. if (!Emptys.check(deviceIds)) {
  327. return R.ok();
  328. }
  329. //查询数据库
  330. List<DeviceInfo> list = list(new LambdaQueryWrapper<DeviceInfo>().in(DeviceInfo::getDeviceId, deviceIds));
  331. return R.ok(copy(DeviceInfoDto.Vo.class, list));
  332. }
  333. @ApiOperation("修改")
  334. @PostMapping("update")
  335. public R update(@RequestBody @Validated DeviceInfoDto.Update update) {
  336. DeviceInfo deviceInfo = copy(DeviceInfo.class, update)
  337. .setUpdateTime(LocalDateTime.now());
  338. updateById(deviceInfo);
  339. Long deviceId = deviceInfo.getDeviceId();
  340. DeviceInfoDto.Vo device = R.feignCheckData(this.obj(new DeviceInfoDto.Obj().setDeviceId(deviceId).setIsSysinfo(true)));
  341. Long algorithmId = update.getAlgorithmId();
  342. if (algorithmId != null && AlgorithmTypeEnum.CLOUD.getId() == algorithmId) {
  343. //云从算法
  344. boolean b = cloudWalkApiService.checkDeviceExist(deviceId);
  345. if (!b) {
  346. //货柜不存在,新增
  347. cloudWalkApiService.containerAdd(new ContainerAddDTO().setContainerCode(String.valueOf(deviceId)));
  348. }
  349. }
  350. Integer deviceType = device.getDeviceType();
  351. if (ObjectUtil.equals(DeviceTypeEnum.TYPE5.getCode(), deviceType)) {
  352. DeviceUpdateDTO deviceUpdateDTO = new DeviceUpdateDTO();
  353. if (StrUtil.isNotEmpty(update.getDeviceName())) {
  354. deviceUpdateDTO.setDeviceName(update.getDeviceName());
  355. }
  356. String deviceSn = device.getDeviceSysinfo().getDeviceSn();
  357. if (deviceUpdateDTO != null) {
  358. deviceUpdateDTO.setTerminalId(String.valueOf(update.getDeviceId()));
  359. deviceUpdateDTO.setBoardSn(deviceSn);
  360. alipayDeviceService.deviceUpdate(deviceUpdateDTO);
  361. }
  362. }
  363. return R.ok();
  364. }
  365. @ApiOperation("批量修改")
  366. @PostMapping("updateBatch")
  367. public R updateBatch(@RequestBody List<DeviceInfoDto.Update> updates) {
  368. LocalDateTime now = LocalDateTime.now();
  369. List<DeviceInfo> deviceInfos = new ArrayList<>(updates.size());
  370. updates.forEach(update -> deviceInfos.add(copy(DeviceInfo.class, update).setUpdateTime(now)));
  371. updateBatchById(deviceInfos);
  372. return R.ok();
  373. }
  374. @Override
  375. @ApiOperation("更新商户线路")
  376. public R updateLine(@RequestBody @Validated DeviceInfoDto.UpdateLine updateLine) {
  377. LambdaUpdateWrapper<DeviceInfo> luw = new LambdaUpdateWrapper<DeviceInfo>().eq(DeviceInfo::getMercId, updateLine.getMercId());
  378. //绑定线路,更换线路
  379. if (DeviceInfoDto.UPDATE.equals(updateLine.getType())) {
  380. DeviceInfo deviceInfo = new DeviceInfo();
  381. deviceInfo.setPlaceLineId(updateLine.getPlaceLineId());
  382. luw.in(DeviceInfo::getDeviceId, updateLine.getDeviceIds());
  383. baseMapper.update(deviceInfo, luw);
  384. }
  385. //删除线路
  386. if (DeviceInfoDto.DEL.equals(updateLine.getType())) {
  387. luw.eq(DeviceInfo::getPlaceLineId, updateLine.getWherePlaceLineId());
  388. luw.set(DeviceInfo::getPlaceLineId, null);
  389. baseMapper.update(null, luw);
  390. }
  391. //解绑线路 设置线路ID为null
  392. if (DeviceInfoDto.CLEAR.equals(updateLine.getType())) {
  393. luw.in(DeviceInfo::getDeviceId, updateLine.getDeviceIds());
  394. luw.set(DeviceInfo::getPlaceLineId, null);
  395. baseMapper.update(null, luw);
  396. }
  397. return R.ok();
  398. }
  399. @Override
  400. @ApiOperation("更新商户点位")
  401. public R updatePlace(@RequestBody @Validated DeviceInfoDto.UpdatePlace updatePlace) {
  402. LambdaUpdateWrapper<DeviceInfo> luw = new LambdaUpdateWrapper<DeviceInfo>().eq(DeviceInfo::getMercId, updatePlace.getMercId());
  403. //绑定点位,更换点位
  404. if (DeviceInfoDto.UPDATE.equals(updatePlace.getType())) {
  405. DeviceInfo deviceInfo = new DeviceInfo();
  406. deviceInfo.setPlaceId(updatePlace.getPlaceId());
  407. luw.in(DeviceInfo::getDeviceId, updatePlace.getDeviceIds());
  408. baseMapper.update(deviceInfo, luw);
  409. }
  410. //删除点位
  411. if (DeviceInfoDto.DEL.equals(updatePlace.getType())) {
  412. luw.eq(DeviceInfo::getPlaceId, updatePlace.getWherePlaceId());
  413. luw.set(DeviceInfo::getPlaceId, null);
  414. baseMapper.update(null, luw);
  415. }
  416. //解绑点位 设置点位ID为null
  417. if (DeviceInfoDto.CLEAR.equals(updatePlace.getType())) {
  418. luw.in(DeviceInfo::getDeviceId, updatePlace.getDeviceIds());
  419. luw.set(DeviceInfo::getPlaceId, null);
  420. baseMapper.update(null, luw);
  421. }
  422. return R.ok();
  423. }
  424. @ApiOperation("分页查询")
  425. @Override
  426. public R<PageBean<DeviceInfoDto.Vo2>> page(@RequestBody DeviceInfoDto.Page page) {
  427. return R.ok(queryPage(page));
  428. }
  429. @ApiOperation("导出设备列表")
  430. @PostMapping("exportDevices")
  431. public void exportDevices(HttpServletResponse response, @RequestBody @Valid DeviceInfoDto.Page page) throws IOException {
  432. PageBean<DeviceInfoDto.Vo2> pageBean = queryPage(page);
  433. List<DeviceInfoDto.Vo2> records = pageBean.getRecords();
  434. List<DeviceInfoDto.DeviceExcelVO> deviceExcelVOS = BeanUtil.copyToList(records, DeviceInfoDto.DeviceExcelVO.class);
  435. // 输出
  436. ExcelUtils.write(response, "设备列表.xls", "设备列表", DeviceInfoDto.DeviceExcelVO.class, deviceExcelVOS);
  437. }
  438. @ApiOperation("导出设备(异步)")
  439. @PostMapping("exportDevices/async")
  440. public void exportDevicesAsync(@RequestBody @Validated DeviceInfoDto.Page page) {
  441. PageBean<DeviceInfoDto.Vo2> pageBean = queryPage(page);
  442. List<DeviceInfoDto.Vo2> records = pageBean.getRecords();
  443. List<DeviceInfoDto.DeviceExcelVO> deviceExcelVOS = BeanUtil.copyToList(records, DeviceInfoDto.DeviceExcelVO.class);
  444. //异步导出参数封装
  445. ExcelDTO<DeviceInfoDto.DeviceExcelVO> excelDTO = new ExcelDTO<>();
  446. excelDTO.setData(deviceExcelVOS);
  447. excelDTO.setHead(DeviceInfoDto.DeviceExcelVO.class);
  448. excelDTO.setSheetName(FileExportType.DEVICE_INFO.getDescription());
  449. excelDTO.setFileExportType(FileExportType.DEVICE_INFO);
  450. //执行导出
  451. fileExportService.exportExcelAsync(excelDTO);
  452. }
  453. @PostMapping("nearbyPage")
  454. @ApiOperation("附近设备分页查询")
  455. public R<PageBean<DeviceInfoDto.Vo2>> nearbyPage(@RequestBody DeviceInfoDto.Page page) {
  456. if (!Emptys.check(page.getLon()) || !Emptys.check(page.getLat())) {
  457. throw new CommRuntimeException("经纬度不能为空");
  458. }
  459. return R.ok(queryPage(page));
  460. }
  461. @ApiOperation(value = "商户设备授权", hidden = true)
  462. @Override
  463. @Transactional(rollbackFor = Exception.class)
  464. public R<Boolean> mercDeviceAuth(DeviceInfoDto.MercDeviceAuthDto auth) {
  465. Long mercId = auth.getMercId();
  466. String mercCode = auth.getMercCode();
  467. Long algorithmId = auth.getAlgorithmId();
  468. String mercName = auth.getMercName();
  469. //商户最终设备列表
  470. List<Long> deviceIds = auth.getDeviceIds();
  471. List<DeviceInfo> devices = getDevicesByMercId(mercId);
  472. //取消商户设备授权
  473. if (CollUtil.isEmpty(deviceIds)) {
  474. if (CollUtil.isEmpty(devices)) {
  475. return R.ok(Boolean.TRUE);
  476. }
  477. }
  478. //更新商户设备授权
  479. List<DeviceInfo> deviceInfos = this.listByIds(deviceIds);
  480. for (DeviceInfo deviceInfo : deviceInfos) {
  481. Integer deviceType = deviceInfo.getDeviceType();
  482. Long deviceId = deviceInfo.getDeviceId();
  483. if (ObjectUtil.equals(deviceType, DeviceTypeEnum.TYPE5.getCode())) {
  484. //支付宝设备算法
  485. algorithmId = AlgorithmTypeEnum.ALIPAY.getId();
  486. } else {
  487. //非支付宝算法
  488. if (AlgorithmTypeEnum.CLOUD.getId() == algorithmId) {
  489. //云从算法
  490. boolean b = cloudWalkApiService.checkDeviceExist(deviceId);
  491. if (!b) {
  492. //货柜不存在,新增
  493. cloudWalkApiService.containerAdd(new ContainerAddDTO().setContainerCode(String.valueOf(deviceId)));
  494. }
  495. }
  496. }
  497. int refMercId = deviceInfo.getMercId().intValue();
  498. String refMercCode = deviceInfo.getMercCode();
  499. // 只有解绑后,才能给顶级商户授权
  500. if (refMercId != -1 && refMercId != mercId.intValue()) {
  501. StrBuilder sb = StrBuilder.create();
  502. String errMsg = sb.append("设备[")
  503. .append(deviceInfo.getDeviceId())
  504. .append("]")
  505. .append("已被商户[")
  506. .append(deviceInfo.getMercName())
  507. .append("]绑定,请先进行解绑!")
  508. .toString();
  509. //非质检商户需要进行判断,质检商户跳过
  510. if (!QA_MERC_CODE.equals(refMercCode)) {
  511. //已关联别商户
  512. return R.fail(errMsg, Boolean.FALSE);
  513. }
  514. }
  515. //绑定关系
  516. deviceInfo.setMercId(mercId).setMercCode(mercCode).setAlgorithmId(algorithmId).setMercName(mercName);
  517. }
  518. saveOrUpdateBatch(deviceInfos);
  519. // //原来存在的设备关系,不在最终设备列表中的移除
  520. // if (CollUtil.isNotEmpty(devices)) {
  521. // List<Long> oldIds = new ArrayList<>();
  522. // List<Long> removeIds = new ArrayList<>();
  523. // devices.forEach(device -> oldIds.add(device.getDeviceId()));
  524. // oldIds.forEach(deviceId -> {
  525. // //不在最终设备列表中的待移除
  526. // if (!deviceIds.contains(deviceId)) {
  527. // removeIds.add(deviceId);
  528. // }
  529. // });
  530. // if (CollUtil.isNotEmpty(removeIds)) {
  531. // List<DeviceInfo> removeList = this.listByIds(removeIds);
  532. // removeMerRefDevices(removeList, parentId);
  533. // }
  534. // }
  535. return R.ok(Boolean.TRUE);
  536. }
  537. /**
  538. * 解绑机器 回收
  539. *
  540. * @param dto
  541. * @return
  542. */
  543. @Override
  544. public R<Boolean> unBindMercDevice(DeviceInfoDto.MercDeviceUnBindDto dto) {
  545. List<DeviceInfo> deviceInfos = this.listByIds(dto.getDeviceIds());
  546. return R.ok(removeMerRefDevicesToTopMerc(deviceInfos));
  547. }
  548. /**
  549. * 回收机器
  550. *
  551. * @param deviceInfos
  552. * @return
  553. */
  554. private Boolean removeMerRefDevicesToTopMerc(List<DeviceInfo> deviceInfos) {
  555. MercDto.Vo mercCheck = R.feignCheckData(mercFeignService.obj(new MercDto.ListDTO().setMercCode(QA_MERC_CODE)));
  556. if (CollUtil.isNotEmpty(deviceInfos)) {
  557. deviceInfos.forEach(deviceInfo -> {
  558. //回收
  559. deviceInfo.setMercId(mercCheck.getId());
  560. deviceInfo.setMercDeviceCode(StrUtil.EMPTY);
  561. deviceInfo.setMercName(mercCheck.getName());
  562. deviceInfo.setMercCode(QA_MERC_CODE);
  563. });
  564. //批量更新
  565. return updateBatchById(deviceInfos);
  566. }
  567. return Boolean.FALSE;
  568. }
  569. /**
  570. * 批量移除商户设备绑定关系
  571. *
  572. * @param deviceInfos
  573. * @return
  574. */
  575. private Boolean removeMerRefDevices(List<DeviceInfo> deviceInfos, Long parentId) {
  576. if (CollUtil.isNotEmpty(deviceInfos) && parentId != null) {
  577. deviceInfos.forEach(deviceInfo -> {
  578. //非顶级兴元商户,解绑后,机器归父商户
  579. if (parentId != 1) {
  580. MercDto.Vo mercParent = R.feignCheckData(mercFeignService.obj(new MercDto.ListDTO().setId(parentId)));
  581. if (mercParent != null) {
  582. deviceInfo.setMercId(mercParent.getId());
  583. deviceInfo.setMercName(mercParent.getName());
  584. deviceInfo.setMercCode(mercParent.getMercCode());
  585. } else {
  586. deviceInfo.setMercId(-1L);
  587. deviceInfo.setMercName(StrUtil.EMPTY);
  588. deviceInfo.setMercCode(StrUtil.EMPTY);
  589. }
  590. }
  591. //一级商户,解绑后,直接释放
  592. if (parentId == 0) {
  593. MercDto.Vo mercCheck = R.feignCheckData(mercFeignService.obj(new MercDto.ListDTO().setMercCode(QA_MERC_CODE)));
  594. if (mercCheck != null) {
  595. deviceInfo.setMercId(mercCheck.getId());
  596. deviceInfo.setMercName(mercCheck.getName());
  597. deviceInfo.setMercCode(mercCheck.getMercCode());
  598. } else {
  599. deviceInfo.setMercId(-1L);
  600. deviceInfo.setMercName(StrUtil.EMPTY);
  601. deviceInfo.setMercCode(StrUtil.EMPTY);
  602. }
  603. }
  604. });
  605. //批量更新
  606. return updateBatchById(deviceInfos);
  607. }
  608. return Boolean.FALSE;
  609. }
  610. @ApiOperation("集合查询")
  611. @Override
  612. public R<List<DeviceInfoDto.Vo>> list(DeviceInfoDto.ListDto dto) {
  613. List<DeviceInfo> list = list(new LambdaQueryWrapper<DeviceInfo>()
  614. .in(CollUtil.isNotEmpty(dto.getDeviceIds()), DeviceInfo::getDeviceId, dto.getDeviceIds())
  615. .eq(Emptys.check(dto.getMercId()), DeviceInfo::getMercId, dto.getMercId())
  616. );
  617. return R.ok(copy(DeviceInfoDto.Vo.class, list));
  618. }
  619. @Override
  620. @ApiOperation("通用集合查询")
  621. public R<List<DeviceInfoDto.Vo>> listCommon(DeviceInfoDto.ListCommon dto) {
  622. String deviceSearch = dto.getDeviceSearch();
  623. DeviceInfoDto.Vo vo = dto.getVo();
  624. QueryWrapper<DeviceInfo> queryWrapper = new MybatisPlusQuery().eqWrapper(vo == null ? new DeviceInfoDto.Vo() : vo, DeviceInfo.class).buildQW();
  625. // List<Long> placeLineIds = dto.getPlaceLineIds();
  626. List<Long> deviceIds = dto.getDeviceIds();
  627. List<String> columnList = dto.getColumnList();
  628. // if (CollUtil.isNotEmpty(placeLineIds)) {
  629. // queryWrapper.in(LambdaUtils.getUnderlineCaseName(DeviceInfo::getPlaceLineId), placeLineIds);
  630. // }
  631. //fixed
  632. if (StrUtil.isNotEmpty(deviceSearch)) {
  633. queryWrapper.and(wrapper -> wrapper.likeRight(LambdaUtils.getUnderlineCaseName(DeviceInfo::getDeviceName), deviceSearch).or()
  634. .eq(LambdaUtils.getUnderlineCaseName(DeviceInfo::getDeviceId), deviceSearch));
  635. }
  636. if (CollUtil.isNotEmpty(columnList)) {
  637. queryWrapper.select(columnList.stream().toArray(String[]::new));
  638. }
  639. if (CollUtil.isNotEmpty(deviceIds)) {
  640. queryWrapper.in(LambdaUtils.getUnderlineCaseName(DeviceInfo::getDeviceId), deviceIds);
  641. }
  642. return R.ok(copy(DeviceInfoDto.Vo.class, list(queryWrapper)));
  643. }
  644. @Override
  645. @ApiOperation("商户设备算法列表")
  646. public R<List<Long>> mercAlgorithmIdList(DeviceInfoDto.MercAlgorithmIdListDto dto) {
  647. String algorithmIdStr = LambdaUtils.getProperty(DeviceInfo::getAlgorithmId);
  648. String mercStr = StringTools.humpToLine(LambdaUtils.getProperty(DeviceInfo::getMercId));
  649. QueryWrapper<DeviceInfo> lqw = new QueryWrapper<DeviceInfo>()
  650. .isNotNull(StringTools.humpToLine(algorithmIdStr))
  651. .eq(mercStr, dto.getMercId())
  652. .select(String.format("DISTINCT (%s) as %s", StringTools.humpToLine(algorithmIdStr), algorithmIdStr));
  653. List<Long> list = listObjs(lqw, (MapperFunction<Object, Long>) o -> (Long) o);
  654. return R.ok(list);
  655. }
  656. @Override
  657. @ApiOperation("小程序-商户设备首页统计")
  658. public R<DeviceInfoDto.MercHomeStatisticalVO> mercHomeStatistical(DeviceInfoDto.MercHomeQueryDTO dto) {
  659. Long mercId = dto.getMercId();
  660. List<Long> myDeviceIds = dto.getMyDeviceIds();
  661. //初始化数据
  662. DeviceInfoDto.MercHomeStatisticalVO mercHomeStatisticalVO = new DeviceInfoDto.MercHomeStatisticalVO()
  663. .setClosedNum(0).setOfflineNum(0)
  664. .setOnlineNum(0).setOperatingNum(0).setNeedToFillNum(0);
  665. if (CollUtil.isEmpty(myDeviceIds)) {
  666. return R.ok(mercHomeStatisticalVO);
  667. }
  668. List<DeviceInfo> mercDevices = listByIds(myDeviceIds);
  669. if (CollUtil.isEmpty(mercDevices)) {
  670. return R.ok(mercHomeStatisticalVO);
  671. }
  672. //在线、离线
  673. List<DeviceStatus> deviceStatuses = deviceStatusService.listByIds(myDeviceIds);
  674. //分组统计
  675. Map<Integer, Long> countNetstateMap = deviceStatuses.stream().collect(Collectors
  676. .groupingBy(DeviceStatus::getNetState, Collectors.counting()));
  677. Integer onlineDictValue = SysDictUtils.getValue(EnumDeviceOnlineStatus.Code.CODE.getCode(), EnumDeviceOnlineStatus.CONNECTED.getCode(), Integer.class);
  678. Integer offlineDictValue = SysDictUtils.getValue(EnumDeviceOnlineStatus.Code.CODE.getCode(), EnumDeviceOnlineStatus.DISCONNECT.getCode(), Integer.class);
  679. int onlineNum = countNetstateMap.get(onlineDictValue) == null ? 0 : countNetstateMap.get(onlineDictValue).intValue();
  680. int offlineNum = countNetstateMap.get(offlineDictValue) == null ? 0 : countNetstateMap.get(offlineDictValue).intValue();
  681. mercHomeStatisticalVO.setOnlineNum(onlineNum);
  682. mercHomeStatisticalVO.setOfflineNum(offlineNum);
  683. //锁机、未锁机
  684. Map<Integer, Long> countLockLstateMap = deviceStatuses.stream().collect(Collectors
  685. .groupingBy(DeviceStatus::getLockStateL, Collectors.counting()));
  686. Long lockLStateNum = countLockLstateMap.get(DeviceLockState.LOCK.getCode());
  687. Long unLockLStateNum = countLockLstateMap.get(DeviceLockState.UN_LOCK.getCode());
  688. mercHomeStatisticalVO.setOperatingNum(unLockLStateNum == null ? 0 : unLockLStateNum.intValue());
  689. mercHomeStatisticalVO.setClosedNum(lockLStateNum == null ? 0 : lockLStateNum.intValue());
  690. //待补货
  691. Integer deviceNum = R.feignCheckData(goodsDeviceService.countOutOfStockDevice(new GoodsDeviceDto.CountOutOfStockDevice().setMercId(mercId)));
  692. mercHomeStatisticalVO.setNeedToFillNum(deviceNum);
  693. return R.ok(mercHomeStatisticalVO);
  694. }
  695. @Override
  696. @ApiOperation("小程序-商户设备首页列表")
  697. public R<List<DeviceInfoDto.MercHomeListVO>> mercHomeList(DeviceInfoDto.MercHomeQueryDTO dto) {
  698. String searchKey = dto.getSearchKey();
  699. Long mercId = dto.getMercId();
  700. String deviceName = dto.getDeviceName();
  701. Long deviceId = dto.getDeviceId();
  702. boolean isQa = false;
  703. if ("393010594508869".equals(String.valueOf(mercId))) {
  704. isQa = true;
  705. } else {
  706. dto.setActiveState("1");
  707. }
  708. List<Long> searchDeviceIds = new ArrayList<>();
  709. if (StrUtil.isNotEmpty(searchKey)) {
  710. //名称或者编号搜索设备
  711. List<DeviceInfo> list = list(Wrappers.<DeviceInfo>lambdaQuery()
  712. .eq(DeviceInfo::getMercId, mercId)
  713. .and(wrapper -> wrapper
  714. .eq(DeviceInfo::getDeviceId, searchKey)
  715. .or()
  716. .likeRight(DeviceInfo::getDeviceName, searchKey)
  717. )
  718. );
  719. if (CollUtil.isEmpty(list)) {
  720. return R.ok(new ArrayList<>());
  721. }
  722. searchDeviceIds = list.stream().map(DeviceInfo::getDeviceId).collect(Collectors.toList());
  723. }
  724. List<Long> myDeviceIds = dto.getDeviceIdList();
  725. Integer busyStatus = dto.getBusyStatus();
  726. Integer onlineStatus = dto.getOnlineStatus();
  727. Integer deviceType = dto.getDeviceType();
  728. //条件查询 在线状态,运营状态,设备类型,
  729. List<Long> deviceIdList = new ArrayList<>();
  730. if (deviceId != null && myDeviceIds.indexOf(deviceId) > 0) {
  731. deviceIdList.add(deviceId);
  732. }
  733. if (CollUtil.isNotEmpty(myDeviceIds) && deviceId == null) {
  734. deviceIdList.addAll(myDeviceIds);
  735. }
  736. if (CollUtil.isNotEmpty(deviceIdList)) {
  737. dto.setDeviceIdList(deviceIdList);
  738. List<Long> queryDeviceIds = new ArrayList<>();
  739. if (CollUtil.isNotEmpty(searchDeviceIds)) {
  740. for (Long id : searchDeviceIds) {
  741. int index = deviceIdList.indexOf(id);
  742. if (index > 0) {
  743. queryDeviceIds.add(id);
  744. }
  745. }
  746. //无符合权限的搜索设备,返空
  747. if (CollUtil.isEmpty(queryDeviceIds)) {
  748. return R.ok(new ArrayList<>());
  749. } else {
  750. deviceIdList = queryDeviceIds;
  751. dto.setDeviceIdList(queryDeviceIds);
  752. }
  753. }
  754. } else {
  755. return R.ok(new ArrayList<>());
  756. }
  757. if (onlineStatus != null) {
  758. List<DeviceStatus> deviceStatusList = deviceStatusService.list(Wrappers.<DeviceStatus>lambdaQuery()
  759. .eq(DeviceStatus::getNetState, onlineStatus)
  760. .in(CollUtil.isNotEmpty(myDeviceIds), DeviceStatus::getDeviceId, deviceIdList)
  761. );
  762. if (CollUtil.isNotEmpty(deviceStatusList)) {
  763. List<Long> dbDeviceIdList = deviceStatusList.stream().map(DeviceStatus::getDeviceId).collect(Collectors.toList());
  764. deviceIdList = dbDeviceIdList;
  765. } else {
  766. return R.ok(new ArrayList<>());
  767. }
  768. }
  769. List<DeviceInfoDto.MercHomeCountVO> list = this.baseMapper.merHomeCountList(dto);
  770. if (CollUtil.isEmpty(list)) {
  771. return R.ok(Collections.emptyList());
  772. }
  773. List<DeviceInfoDto.MercHomeListVO> dataList = new ArrayList<>(list.size());
  774. LambdaQueryWrapper<DeviceInfo> lqw = new LambdaQueryWrapper<>();
  775. //非质检商户才需要激活
  776. lqw.eq(!isQa, DeviceInfo::getActiveState, DeviceActiveStateEnum.TRUE.getCode());
  777. lqw.eq(mercId != null, DeviceInfo::getMercId, mercId);
  778. lqw.eq(busyStatus != null, DeviceInfo::getBusyState, busyStatus);
  779. lqw.eq(deviceType != null, DeviceInfo::getDeviceType, deviceType);
  780. lqw.in(CollUtil.isNotEmpty(deviceIdList), DeviceInfo::getDeviceId, deviceIdList);
  781. lqw.like(StrUtil.isNotEmpty(deviceName), DeviceInfo::getDeviceName, deviceName).orderByAsc(true, DeviceInfo::getDeviceName, DeviceInfo::getDeviceId);
  782. List<DeviceInfo> deviceInfoList = this.list(lqw);
  783. //未分区域的设置默认值
  784. deviceInfoList.stream().filter(s -> s.getDistrictId() == null).forEach(s -> s.setDistrictId(-1L));
  785. Map<Long, String> districtMap = new HashMap<>();
  786. List<Long> districtIdList = list.stream().map(DeviceInfoDto.MercHomeCountVO::getDistrictId).filter(i -> i != -1).collect(Collectors.toList());
  787. districtMap = mercRegionService.getNameList(new MercRegionDto.GetNameListDto().setIds(districtIdList)).getData();
  788. //根据区域id分组
  789. Map<Long, List<DeviceInfo>> deviceMap = deviceInfoList.stream().collect(Collectors.groupingBy(DeviceInfo::getDistrictId));
  790. DateTime date = DateTime.now();
  791. DateTime start = DateUtil.beginOfDay(date);
  792. DateTime end = DateUtil.endOfDay(date);
  793. for (DeviceInfoDto.MercHomeCountVO v : list) {
  794. DeviceInfoDto.MercHomeListVO vo = new DeviceInfoDto.MercHomeListVO();
  795. Long districtId = v.getDistrictId();
  796. vo.setDeviceNum(v.getDeviceNum());
  797. vo.setDistrictId(v.getDistrictId());
  798. vo.setDistrictName(v.getDistrictId() == -1L ? "未分配区域" : districtMap.get(v.getDistrictId()));
  799. //区域下的设备列表
  800. List<DeviceInfoDto.MercHomeDeviceVo> deviceInfos = BeanUtil.copyToList(deviceMap.get(districtId), DeviceInfoDto.MercHomeDeviceVo.class);
  801. if (CollUtil.isEmpty(deviceInfos)) {
  802. continue;
  803. }
  804. //设备销售统计
  805. List<Long> deviceIds = deviceInfos.stream().map(DeviceInfoDto.MercHomeDeviceVo::getDeviceId).collect(Collectors.toList());
  806. //设备状态查询
  807. List<DeviceStatusDto.Vo> deviceStatusList = deviceStatusService.list(new DeviceStatusDto.SelectList().setDeviceIds(deviceIds)).getData();
  808. Map<Long, DeviceStatusDto.Vo> datdeviceStatusMap = new HashMap<>();
  809. if (CollUtil.isNotEmpty(deviceStatusList)) {
  810. datdeviceStatusMap = deviceStatusList.stream().collect(Collectors.toMap(DeviceStatusDto.Vo::getDeviceId, d -> d));
  811. }
  812. List<GoodsDeviceDto.Vo> goodsDeviceList = R.feignCheckData(goodsService.queryGoodsDeviceInfo(new GoodsDto.QueryGoodsDeviceInfo().setMercId(mercId).setDeviceIds(deviceIds)));
  813. Map<Long, List<GoodsDeviceDto.Vo>> deviceIdGoodsMap = goodsDeviceList.stream()
  814. .collect(Collectors.groupingBy(GoodsDeviceDto.Vo::getDeviceId));
  815. List<AlgorithmDto.ListNameId> algorithmList = R.feignCheckData(algorithmService.ListNameId());
  816. Map<Long, String> algorithmListMap = algorithmList.stream().collect(Collectors.toMap(AlgorithmDto.ListNameId::getId, AlgorithmDto.ListNameId::getAlias));
  817. for (DeviceInfoDto.MercHomeDeviceVo device : deviceInfos) {
  818. Long dId = device.getDeviceId();
  819. //设备类型 反显
  820. SysDictRedis dictDeviceType = SysDictUtils.get(DictConsts.DEVICE_TYPE, String.valueOf(device.getDeviceType()));
  821. device.setDeviceTypeName(dictDeviceType.getMsg());
  822. //运营状态 反显
  823. SysDictRedis dictBusyState = SysDictUtils.get(DictConsts.DEVICE_BUSY_STATUS, String.valueOf(device.getBusyState()));
  824. device.setBusyStateName(dictBusyState.getMsg());
  825. Integer zero = new Integer(0);
  826. CountDto.OrderByCreateTimeAndMercId orderByCreateTimeAndMercId = new CountDto.OrderByCreateTimeAndMercId()
  827. .setMerdId(mercId).setBeginTime(start).setEndTime(end).setDeviceIds(CollUtil.newArrayList(dId));
  828. log.info("设备订单统计:{}", JSONUtil.toJsonPrettyStr(orderByCreateTimeAndMercId));
  829. //完成订单
  830. CountDto.SuccessVo successVo = R.feignCheckData(countApiService.orderBySuccess(orderByCreateTimeAndMercId));
  831. //今日销售、库存情况 反显
  832. device.setDayOrderNum(successVo != null ? successVo.getOrdersSize() : zero);
  833. device.setDaySalesPrice(successVo != null ? successVo.getOrderTotalMoney() : zero);
  834. DeviceStatusDto.Vo deviceStatus = datdeviceStatusMap.get(device.getDeviceId());
  835. if (CollUtil.isNotEmpty(deviceIdGoodsMap)) {
  836. List<GoodsDeviceDto.Vo> goodsDevice = deviceIdGoodsMap.get(dId);
  837. if (CollUtil.isNotEmpty(goodsDevice)) {
  838. device.setOnSaleNum(goodsDevice.stream().mapToInt(GoodsDeviceDto.Vo::getStock).sum());
  839. device.setFillNum(goodsDevice.stream().mapToInt(GoodsDeviceDto.Vo::getFillCount).sum());
  840. }
  841. }
  842. //算法類型
  843. Long algorithmId = device.getAlgorithmId();
  844. if (algorithmId != null) {
  845. String name = algorithmListMap.get(algorithmId);
  846. device.setAlgorithmAlias(name);
  847. }
  848. //联网状态
  849. Integer netState = deviceStatus == null ? DeviceNetSateType.DISCONNECT.getCode() : deviceStatus.getNetState();
  850. device.setNetState(netState);
  851. if (netState == null) {
  852. device.setNetStateName(StrUtil.EMPTY);
  853. } else {
  854. device.setNetStateName(DeviceNetSateType.getEnumByCode(netState).getDescription());
  855. }
  856. if (deviceStatus != null) {
  857. Integer deviceStateL = deviceStatus.getLockStateL();
  858. Integer deviceStateR = deviceStatus.getLockStateR();
  859. device.setTempValue(deviceStatus.getTempValue());
  860. device.setDeviceStateL(deviceStateL);
  861. device.setDeviceStateR(deviceStateR);
  862. device.setSysPower(deviceStatus.getSysPower());
  863. DeviceLockState deviceLockStateL = DeviceLockState.getEnumByCode(deviceStateL);
  864. DeviceLockState deviceLockStateR = DeviceLockState.getEnumByCode(deviceStateR);
  865. device.setDeviceStateRName(deviceLockStateR == null ? "未知" : deviceLockStateR.getDescription());
  866. device.setDeviceStateLName(deviceLockStateL == null ? "未知" : deviceLockStateL.getDescription());
  867. }
  868. }
  869. //名称排序
  870. if (CollUtil.isNotEmpty(deviceInfos)) {
  871. deviceInfos = ListUtil.sortByProperty(deviceInfos, LambdaUtils.getProperty(DeviceInfoDto.MercHomeDeviceVo::getDeviceName));
  872. deviceInfos = ListUtil.sortByProperty(deviceInfos, LambdaUtils.getProperty(DeviceInfoDto.MercHomeDeviceVo::getDeviceId));
  873. }
  874. vo.setDeviceInfos(deviceInfos);
  875. dataList.add(vo);
  876. }
  877. return R.ok(dataList);
  878. }
  879. /**
  880. * 获取商户设备列表
  881. *
  882. * @param mercId
  883. * @return
  884. */
  885. private List<DeviceInfo> getDevicesByMercId(Long mercId) {
  886. return list(Wrappers.<DeviceInfo>lambdaQuery().eq(DeviceInfo::getMercId, mercId).eq(DeviceInfo::getActiveState, DeviceActiveStateEnum.TRUE.getCode()));
  887. }
  888. /**
  889. * 小程序商户设备搜索
  890. *
  891. * @param page
  892. * @return
  893. */
  894. @Override
  895. public R<PageBean<DeviceInfoDto.MerHomeSearchVO>> mercDeviceSearchPage(@RequestBody DeviceInfoDto.Page page) {
  896. PageBean<DeviceInfoDto.MerHomeSearchVO> pageData = new PageBean<>();
  897. //小程序独有查询字段 缺货状态:stockStatus ,是否查故障设备:fault
  898. Boolean fault = page.getFault();
  899. Long mercId = page.getMercId();
  900. List<Long> myDeviceIds = page.getMyDeviceIds();
  901. if (CollUtil.isEmpty(myDeviceIds)) {
  902. //无设备
  903. return R.ok(pageData);
  904. }
  905. if (BooleanUtil.isTrue(fault)) {
  906. //查询故障设备
  907. List<DeviceEventMsg> deviceEventMsgs = deviceEventMsgService.list(Wrappers.<DeviceEventMsg>lambdaQuery()
  908. .eq(mercId != null, DeviceEventMsg::getMercId, page.getMercId())
  909. .in(DeviceEventMsg::getDeviceId, myDeviceIds));
  910. List<Long> deviceIdList = deviceEventMsgs.stream().map(DeviceEventMsg::getDeviceId).collect(Collectors.toList());
  911. if (CollUtil.isEmpty(deviceIdList)) {
  912. return R.ok(new PageBean<>());
  913. }
  914. page.setDeviceIdList(deviceIdList);
  915. } else {
  916. page.setDeviceIdList(myDeviceIds);
  917. }
  918. PageBean<DeviceInfoDto.Vo2> pageBean = queryPage(page);
  919. List<DeviceInfoDto.Vo2> records = pageBean.getRecords();
  920. if (CollUtil.isEmpty(records)) {
  921. return R.ok(pageData);
  922. }
  923. List<DeviceInfoDto.MerHomeSearchVO> merHomeSearchRecords = new ArrayList<>();
  924. BeanUtil.copyProperties(pageBean, pageData);
  925. if (CollUtil.isNotEmpty(records)) {
  926. List<Long> deviceIds = records.stream().map(DeviceInfoDto.Vo2::getDeviceId).collect(Collectors.toList());
  927. String type = EnumDeviceDataType.DAY.getCode();
  928. String todayDate = DateUtil.format(new Date(), DatePattern.PURE_DATE_PATTERN);
  929. //查询当天
  930. DeviceDataDto.ListDTO dto = new DeviceDataDto.ListDTO()
  931. .setDeviceIds(deviceIds).setType(type).setDateValue(Integer.valueOf(todayDate)).setMercId(mercId);
  932. List<DeviceDataDto.Vo> deviceDataList = deviceDataService.list(dto);
  933. Map<Long, DeviceDataDto.Vo> dataMap = MapUtil.newHashMap();
  934. //统计数据反显
  935. if (CollUtil.isNotEmpty(deviceDataList)) {
  936. dataMap = deviceDataList.stream().collect(Collectors.toMap(DeviceDataDto.Vo::getDeviceId, d -> d));
  937. }
  938. for (DeviceInfoDto.Vo2 v : records) {
  939. DeviceInfoDto.MerHomeSearchVO merHomeSearchVO = new DeviceInfoDto.MerHomeSearchVO();
  940. Long deviceId = v.getDeviceId();
  941. DeviceDataDto.Vo vo = dataMap.get(deviceId);
  942. if (vo != null) {
  943. //今日订单数
  944. v.setDayOrderNum(vo != null ? vo.getSalesCount() : 0);
  945. v.setDaySalesPrice(vo != null ? vo.getSalesMoney() : 0);
  946. BeanUtil.copyProperties(vo, merHomeSearchVO);
  947. }
  948. DeviceSysinfoDto.Vo deviceSysinfo = v.getDeviceSysinfo();
  949. DeviceStatusDto.Vo deviceStatus = v.getDeviceStatus();
  950. merHomeSearchVO.setAppUpmVersion(deviceSysinfo.getAppUpmVersion());
  951. merHomeSearchVO.setTempValue(deviceStatus.getTempValue());
  952. merHomeSearchVO.setNetDbm(deviceStatus.getNetDbm());
  953. Integer deviceStateL = deviceStatus.getLockStateL();
  954. Integer deviceStateR = deviceStatus.getLockStateR();
  955. merHomeSearchVO.setDeviceStateL(deviceStateL);
  956. merHomeSearchVO.setDeviceStateR(deviceStateR);
  957. DeviceLockState deviceLockStateL = DeviceLockState.getEnumByCode(deviceStateL);
  958. DeviceLockState deviceLockStateR = DeviceLockState.getEnumByCode(deviceStateR);
  959. merHomeSearchVO.setDeviceStateRName(deviceLockStateR == null ? "未知" : deviceLockStateR.getDescription());
  960. merHomeSearchVO.setDeviceStateLName(deviceLockStateL == null ? "未知" : deviceLockStateL.getDescription());
  961. merHomeSearchRecords.add(merHomeSearchVO);
  962. }
  963. pageData.setRecords(merHomeSearchRecords);
  964. }
  965. return R.ok(pageData);
  966. }
  967. /**
  968. * 小程序商户设备详情-数据统计
  969. *
  970. * @param dto
  971. * @return
  972. */
  973. @Override
  974. @ApiOperation("商户设备详情-数据统计")
  975. public R<DeviceInfoDto.DeviceDataCountVO> dataCount(DeviceInfoDto.DeviceDataCountDTO dto) {
  976. // 统计类型(1=经营数据,2=经营图表,3=温度图表,4=信号图表,5=商品管理)
  977. Integer type = dto.getType();
  978. switch (type) {
  979. case 1:
  980. //经营数据
  981. return R.ok(dataCount1(dto));
  982. case 2:
  983. //经营图表
  984. return R.ok(dataCount2(dto));
  985. case 3:
  986. //温度图表
  987. return R.ok(dataCount3(dto));
  988. case 4:
  989. //信号图表
  990. return R.ok(dataCount4(dto));
  991. case 5:
  992. //商品管理
  993. return R.ok(dataCount5(dto));
  994. default:
  995. break;
  996. }
  997. return R.ok();
  998. }
  999. /**
  1000. * 经营数据
  1001. *
  1002. * @param dto
  1003. * @return
  1004. */
  1005. private DeviceInfoDto.DeviceDataCountVO dataCount1(DeviceInfoDto.DeviceDataCountDTO dto) {
  1006. Long deviceId = dto.getDeviceId();
  1007. Long mercId = dto.getMercId();
  1008. DeviceInfoDto.DeviceDataCountVO vo = new DeviceInfoDto.DeviceDataCountVO();
  1009. //当天
  1010. DateTime date = DateTime.now();
  1011. DateTime start = DateUtil.beginOfDay(date);
  1012. DateTime end = DateUtil.endOfDay(date);
  1013. List<Long> deviceIds = CollUtil.newArrayList(deviceId);
  1014. CountDto.OrderByCreateTimeAndMercId orderByCreateTimeAndMercId = new CountDto.OrderByCreateTimeAndMercId()
  1015. .setMerdId(mercId).setBeginTime(start).setEndTime(end).setDeviceIds(deviceIds);
  1016. //完成订单
  1017. CountDto.SuccessVo successVo = R.feignCheckData(countApiService.orderBySuccess(orderByCreateTimeAndMercId));
  1018. DeviceDataDto.Vo dayData = new DeviceDataDto.Vo();
  1019. if (successVo != null) {
  1020. dayData.setSalesMoney(successVo.getOrderTotalMoney());
  1021. dayData.setRefundMoney(successVo.getRefundMoney());
  1022. dayData.setSalesCount(successVo.getOrdersSize());
  1023. }
  1024. //当月
  1025. DeviceDataDto.Vo monthData = new DeviceDataDto.Vo();
  1026. //月度统计
  1027. DateTime startM = DateUtil.beginOfMonth(date);
  1028. DateTime endM = DateUtil.endOfMonth(date);
  1029. CountDto.OrderByCreateTimeAndMercId monthOrder = new CountDto.OrderByCreateTimeAndMercId()
  1030. .setMerdId(mercId).setBeginTime(startM).setEndTime(endM).setDeviceIds(deviceIds);
  1031. //完成订单
  1032. CountDto.SuccessVo successVoM = R.feignCheckData(countApiService.orderBySuccess(monthOrder));
  1033. if (monthData != null) {
  1034. monthData.setRefundMoney(successVoM.getRefundMoney());
  1035. monthData.setSalesMoney(successVoM.getOrderTotalMoney());
  1036. monthData.setSalesCount(successVoM.getOrdersSize());
  1037. }
  1038. vo.setDayBusinessData(copy(DeviceInfoDto.BusinessData.class, dayData));
  1039. vo.setMonthBusinessData(copy(DeviceInfoDto.BusinessData.class, monthData));
  1040. return vo;
  1041. }
  1042. /**
  1043. * 经营图表
  1044. *
  1045. * @param dto
  1046. * @return
  1047. */
  1048. private DeviceInfoDto.DeviceDataCountVO dataCount2(DeviceInfoDto.DeviceDataCountDTO dto) {
  1049. Long deviceId = dto.getDeviceId();
  1050. //近一个月 (销售额,订单数,退款金额,退款数)
  1051. DeviceInfoDto.DeviceDataCountVO vo = new DeviceInfoDto.DeviceDataCountVO();
  1052. DeviceInfoDto.BusinessChart businessChart = new DeviceInfoDto.BusinessChart();
  1053. List<String> categories = DataTime.dayListByLastDay(30);
  1054. List<Integer> dateList = new ArrayList<>(30);
  1055. businessChart.setCategories(categories);
  1056. categories.forEach(d -> {
  1057. dateList.add(Integer.valueOf(d.replaceAll(StrUtil.DASHED, StrUtil.EMPTY)));
  1058. });
  1059. Integer startDay = dateList.get(0);
  1060. Integer endDay = dateList.get(categories.size() - 1);
  1061. List<DeviceDataDto.Vo> listByDay = deviceDataService.getListByDay(deviceId, startDay, endDay);
  1062. if (CollUtil.isEmpty(listByDay)) {
  1063. return vo;
  1064. }
  1065. //每天的数据
  1066. Map<Integer, DeviceDataDto.Vo> dataDayMap = listByDay.stream().collect(Collectors.toMap(DeviceDataDto.Vo::getDateValue, i -> i));
  1067. List<DeviceInfoDto.MyChartSeries3> series = new ArrayList<>();
  1068. String[] names = {"销售额", "订单数", "退款金额", "退款数"};
  1069. for (int i = 0; i < names.length; i++) {
  1070. DeviceInfoDto.MyChartSeries3 myChartSeries = new DeviceInfoDto.MyChartSeries3();
  1071. //某个类型每天的数据
  1072. List<String> data = new ArrayList<>();
  1073. if (i == 0) {
  1074. //销售额
  1075. dateList.forEach(d -> {
  1076. //每日数据填充
  1077. DeviceDataDto.Vo deviceData = dataDayMap.get(d);
  1078. if (deviceData == null) {
  1079. data.add(String.valueOf(BigDecimal.ZERO));
  1080. } else {
  1081. Integer salesMoney = deviceData.getSalesMoney() == null ? 0 : deviceData.getSalesMoney();
  1082. BigDecimal day = BigDecimal.valueOf(salesMoney).divide(BigDecimal.valueOf(100));
  1083. data.add(String.valueOf(day));
  1084. }
  1085. });
  1086. } else if (i == 1) {
  1087. //订单数
  1088. dateList.forEach(d -> {
  1089. //每日数据填充
  1090. DeviceDataDto.Vo deviceData = dataDayMap.get(d);
  1091. String value = "0";
  1092. if (deviceData == null) {
  1093. data.add(value);
  1094. } else {
  1095. data.add(deviceData == null ? value : String.valueOf(deviceData.getSalesCount()));
  1096. }
  1097. });
  1098. } else if (i == 2) {
  1099. //退款金额
  1100. dateList.forEach(d -> {
  1101. //每日数据填充
  1102. DeviceDataDto.Vo deviceData = dataDayMap.get(d);
  1103. if (deviceData == null) {
  1104. data.add(String.valueOf(BigDecimal.ZERO));
  1105. } else {
  1106. Integer refundMoney = deviceData.getRefundMoney() == null ? 0 : deviceData.getRefundMoney();
  1107. BigDecimal day = BigDecimal.valueOf(refundMoney).divide(BigDecimal.valueOf(100));
  1108. data.add(String.valueOf(day));
  1109. }
  1110. });
  1111. } else if (i == 3) {
  1112. //退款数
  1113. dateList.forEach(d -> {
  1114. //每日数据填充
  1115. DeviceDataDto.Vo deviceData = dataDayMap.get(d);
  1116. if (deviceData == null) {
  1117. data.add("0");
  1118. } else {
  1119. data.add(deviceData == null ? "0" : String.valueOf(deviceData.getRefundCount()));
  1120. }
  1121. });
  1122. }
  1123. myChartSeries.setName(names[i]);
  1124. myChartSeries.setData(data);
  1125. series.add(myChartSeries);
  1126. }
  1127. businessChart.setSeries(series);
  1128. vo.setBusinessChart(businessChart);
  1129. return vo;
  1130. }
  1131. /**
  1132. * 温度图表
  1133. *
  1134. * @param dto
  1135. * @return
  1136. */
  1137. private DeviceInfoDto.DeviceDataCountVO dataCount3(DeviceInfoDto.DeviceDataCountDTO dto) {
  1138. DeviceInfoDto.DeviceDataCountVO vo = new DeviceInfoDto.DeviceDataCountVO();
  1139. Long deviceId = dto.getDeviceId();
  1140. String choosDate = dto.getChoosDate();
  1141. if (StrUtil.isEmpty(choosDate)) {
  1142. choosDate = DateUtil.formatDate(new Date());
  1143. }
  1144. String startTime = choosDate + " 00:00:00";
  1145. String endTime = choosDate + " 23:59:59";
  1146. //查询选定日期的温度数据
  1147. List<DeviceTempRecords> deviceTempRecords = deviceTempRecordsService.list(Wrappers.<DeviceTempRecords>lambdaQuery()
  1148. .eq(DeviceTempRecords::getDeviceId, deviceId).between(DeviceTempRecords::getCreateTime, startTime, endTime)
  1149. .orderBy(true, true, DeviceTempRecords::getCreateTime));
  1150. if (CollUtil.isEmpty(deviceTempRecords)) {
  1151. return vo;
  1152. }
  1153. DeviceInfoDto.TemperatureChart temperatureChart = new DeviceInfoDto.TemperatureChart();
  1154. List<String> categories = new ArrayList<>();
  1155. String name = "温度";
  1156. List<DeviceInfoDto.MyChartSeries2> series = new ArrayList<>();
  1157. List<BigDecimal> data = new ArrayList<>();
  1158. deviceTempRecords.forEach(d -> {
  1159. Integer tempValue = d.getTempValue();
  1160. LocalDateTime createTime = d.getCreateTime();
  1161. String time = DateUtil.format(createTime, "HH:mm:ss");
  1162. categories.add(time);
  1163. data.add(tempValue == null ? null : NumberUtil.toBigDecimal(tempValue));
  1164. });
  1165. DeviceInfoDto.MyChartSeries2 myChartSeries = new DeviceInfoDto.MyChartSeries2();
  1166. myChartSeries.setName(name);
  1167. myChartSeries.setData(data);
  1168. series.add(myChartSeries);
  1169. temperatureChart.setSeries(series);
  1170. temperatureChart.setCategories(categories);
  1171. vo.setTemperatureChart(temperatureChart);
  1172. return vo;
  1173. }
  1174. /**
  1175. * 信号图表
  1176. *
  1177. * @param dto
  1178. * @return
  1179. */
  1180. private DeviceInfoDto.DeviceDataCountVO dataCount4(DeviceInfoDto.DeviceDataCountDTO dto) {
  1181. DeviceInfoDto.DeviceDataCountVO vo = new DeviceInfoDto.DeviceDataCountVO();
  1182. Long deviceId = dto.getDeviceId();
  1183. String choosDate = dto.getChoosDate();
  1184. if (StrUtil.isEmpty(choosDate)) {
  1185. choosDate = DateUtil.formatDate(new Date());
  1186. }
  1187. String startTime = choosDate + " 00:00:00";
  1188. String endTime = choosDate + " 23:59:59";
  1189. //查询选定日期的温度数据
  1190. List<DeviceNetRecord> deviceNetRecords = deviceNetRecordService.list(Wrappers.<DeviceNetRecord>lambdaQuery()
  1191. .eq(DeviceNetRecord::getDeviceId, deviceId).between(DeviceNetRecord::getCreateTime, startTime, endTime)
  1192. .orderBy(true, true, DeviceNetRecord::getCreateTime));
  1193. if (CollUtil.isEmpty(deviceNetRecords)) {
  1194. return vo;
  1195. }
  1196. DeviceInfoDto.SignalChart signalChart = new DeviceInfoDto.SignalChart();
  1197. List<String> categories = new ArrayList<>();
  1198. String name = "信号";
  1199. List<DeviceInfoDto.MyChartSeries> series = new ArrayList<>();
  1200. List<Integer> data = new ArrayList<>();
  1201. deviceNetRecords.forEach(d -> {
  1202. Integer value = d.getSimDbm();
  1203. LocalDateTime createTime = d.getCreateTime();
  1204. String time = DateUtil.format(createTime, "HH:mm:ss");
  1205. categories.add(time);
  1206. data.add(value);
  1207. });
  1208. DeviceInfoDto.MyChartSeries myChartSeries = new DeviceInfoDto.MyChartSeries();
  1209. myChartSeries.setName(name);
  1210. myChartSeries.setData(data);
  1211. series.add(myChartSeries);
  1212. signalChart.setSeries(series);
  1213. signalChart.setCategories(categories);
  1214. vo.setSignalChart(signalChart);
  1215. return vo;
  1216. }
  1217. /**
  1218. * 商品管理
  1219. *
  1220. * @param dto
  1221. * @return
  1222. */
  1223. private DeviceInfoDto.DeviceDataCountVO dataCount5(DeviceInfoDto.DeviceDataCountDTO dto) {
  1224. Long deviceId = dto.getDeviceId();
  1225. DeviceInfoDto.DeviceDataCountVO vo = new DeviceInfoDto.DeviceDataCountVO();
  1226. DeviceInfoDto.GoodsData goodsData = new DeviceInfoDto.GoodsData();
  1227. //在售商品种类
  1228. //根据设备ID查商品id
  1229. GoodsDeviceDto.SelectList selectList = new GoodsDeviceDto.SelectList();
  1230. selectList.setDeviceIds(CollUtil.newArrayList(deviceId));
  1231. selectList.setMercId(dto.getMercId());
  1232. R<List<GoodsDeviceDto.Vo>> r = R.feignCheck(goodsDeviceService.list(selectList));
  1233. List<GoodsDeviceDto.Vo> goodsDeviceList = r.getData();
  1234. Integer stock = 0;
  1235. Integer afterFillStock = 0;
  1236. if (CollUtil.isNotEmpty(goodsDeviceList)) {
  1237. stock = goodsDeviceList.stream().mapToInt(GoodsDeviceDto.Vo::getStock).sum();
  1238. afterFillStock = goodsDeviceList.stream().mapToInt(GoodsDeviceDto.Vo::getFillCount).sum();
  1239. }
  1240. goodsData.setAfterFillStock(afterFillStock);
  1241. goodsData.setStock(stock);
  1242. goodsData.setCategoryNum(CollUtil.isNotEmpty(goodsDeviceList) ? goodsDeviceList.size() : new Integer(0));
  1243. vo.setGoodsData(goodsData);
  1244. return vo;
  1245. }
  1246. public PageBean<DeviceInfoDto.Vo2> queryPage(DeviceInfoDto.Page page) {
  1247. IPage<DeviceInfoQueryPage> iPage = baseMapper.queryPage(toIPage(page.getPage()), page);
  1248. return toPageBean(DeviceInfoDto.Vo2.class, iPage);
  1249. }
  1250. private <T> void check(T value, T value2, String msg) {
  1251. if (value.toString().equals(value2.toString())) {
  1252. throw new CommRuntimeException(msg);
  1253. }
  1254. }
  1255. }