DeviceInfoServiceImpl.java 61 KB

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