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. @ApiOperation("设备列表带卡包数")
  106. @PostMapping("algorithmChargingDevice")
  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. .orderByDesc(DeviceInfo::getCreateTime);
  115. IPage<DeviceInfo> page = page(toIPage(pageBean), lambdaUpdateWrapper);
  116. PageBean<DeviceInfoDto.AlgorithmChargingVo> algorithmChargingVoPageBean = toPageBean(DeviceInfoDto.AlgorithmChargingVo.class, page);
  117. List<DeviceInfoDto.AlgorithmChargingVo> algorithmChargingVos = algorithmChargingVoPageBean.getRecords();
  118. if (!Emptys.check(algorithmChargingVos)) {
  119. return R.ok(algorithmChargingVoPageBean);
  120. }
  121. //查询卡包数量
  122. List<DeviceAlgorithmChargingDto.CountVo> data = deviceAlgorithmChargingService.count(new DeviceAlgorithmChargingDto.Count().setDeviceIds(new JArrayList<>(algorithmChargingVos).getProperty(DeviceInfoDto.AlgorithmChargingVo::getDeviceId))).getData();
  123. JMap<Long, DeviceAlgorithmChargingDto.CountVo> cover = new JArrayList<>(data).toMap(DeviceAlgorithmChargingDto.CountVo::getDeviceId).cover();
  124. algorithmChargingVos.forEach(algorithmChargingVo -> {
  125. DeviceAlgorithmChargingDto.CountVo countVo = cover.get(algorithmChargingVo.getDeviceId());
  126. algorithmChargingVo.setAlgorithmChargingSize(countVo.getCount());
  127. });
  128. return R.ok(algorithmChargingVoPageBean);
  129. }
  130. @Override
  131. @ApiOperation("设备在线数查询")
  132. public R<Map<Long, DeviceInfoDto.NetStateCountVo>> netStateCount(DeviceInfoDto.NetStateCountDto dto) {
  133. List<DeviceInfoDto.NetStateCount> netStateCountList = baseMapper.netStateCount(dto.getMercIdList());
  134. List<Long> netStateCountMercList = netStateCountList.stream().map(DeviceInfoDto.NetStateCount::getMercId).distinct().collect(Collectors.toList());
  135. Map<Long, DeviceInfoDto.NetStateCountVo> voMap = new HashMap<>();
  136. List<Long> mercIdList = Emptys.check(dto.getMercIdList()) ? dto.getMercIdList() : netStateCountMercList;
  137. if (!Emptys.check(mercIdList)) {
  138. return R.ok();
  139. }
  140. for (Long mercId : mercIdList) {
  141. Integer count = 0;
  142. Integer offline = 0;
  143. DeviceInfoDto.NetStateCountVo vo = new DeviceInfoDto.NetStateCountVo().setMercId(mercId);
  144. for (DeviceInfoDto.NetStateCount i : netStateCountList) {
  145. if (Objects.equals(i.getMercId(), mercId)) {
  146. count += i.getCount();
  147. if ("1".equals(i.getNetState())) {
  148. vo.setOnLineCount(i.getCount());
  149. } else {
  150. offline += i.getCount();
  151. }
  152. }
  153. }
  154. vo.setCount(count).setOffLineCount(offline);
  155. voMap.put(mercId, vo);
  156. }
  157. return R.ok(voMap);
  158. }
  159. @Override
  160. @ApiOperation("分页")
  161. public R<PageBean<DeviceInfoDto.Vo>> pageSingle(DeviceInfoDto.PageSingle dto) {
  162. PageBean pageBean = dto.getPage();
  163. LambdaQueryWrapper<DeviceInfo> lqw = new MybatisPlusQuery().eqWrapper(dto, DeviceInfo.class)
  164. .build();
  165. IPage<DeviceInfo> iPage = page(toIPage(pageBean), lqw);
  166. return R.ok(toPageBean(DeviceInfoDto.Vo.class, iPage));
  167. }
  168. @Override
  169. @ApiOperation("对象查询")
  170. public R<DeviceInfoDto.Vo> obj(DeviceInfoDto.Obj obj) {
  171. //设备信息
  172. LambdaQueryWrapper<DeviceInfo> lambdaQueryWrapper = new MybatisPlusQuery().eqWrapper(obj, DeviceInfo.class).build();
  173. List<DeviceInfo> list = list(lambdaQueryWrapper);
  174. if (!Emptys.check(list)) {
  175. return R.ok();
  176. }
  177. DeviceInfoDto.Vo deviceInfo = copy(DeviceInfoDto.Vo.class, list.get(0));
  178. int num = 0;
  179. if (obj.getIsSysinfo()) {
  180. num++;
  181. }
  182. if (obj.getIsStatus()) {
  183. num++;
  184. }
  185. if (obj.getIsRegister()) {
  186. num++;
  187. }
  188. if (num > 0) {
  189. ThreadPoolUtils.Execute execute = ThreadPoolUtils.excPoll(DeviceThreadPoolConfig.DEVICE_COMMON_POLL, num);
  190. if (obj.getIsSysinfo()) {
  191. execute.execute(() -> {
  192. //系统信息
  193. DeviceSysinfoDto.Vo deviceSysinfo = deviceSysinfoService.get(new DeviceSysinfoDto.Vo().setDeviceId(deviceInfo.getDeviceId())).getData();
  194. deviceInfo.setDeviceSysinfo(deviceSysinfo);
  195. });
  196. }
  197. if (obj.getIsStatus()) {
  198. execute.execute(() -> {
  199. //状态信息
  200. DeviceStatusDto.Vo deviceStatus = deviceStatusService.obj(new DeviceStatusDto.Vo().setDeviceId(deviceInfo.getDeviceId())).getData();
  201. deviceInfo.setDeviceStatus(deviceStatus);
  202. });
  203. }
  204. if (obj.getIsRegister()) {
  205. execute.execute(() -> {
  206. //注册信息
  207. DeviceRegisterDto.Vo deviceRegister = deviceRegisterService.obj(new DeviceRegisterDto.Vo().setDeviceId(deviceInfo.getDeviceId())).getData();
  208. deviceInfo.setDeviceRegister(deviceRegister);
  209. });
  210. }
  211. execute.end();
  212. }
  213. return R.ok(deviceInfo);
  214. }
  215. @ApiOperation("反显设备名称")
  216. @Override
  217. public R<Map<Long, String>> getDeviceNameList(DeviceInfoDto.DeviceIdDto dto) {
  218. LambdaQueryWrapper<DeviceInfo> lqw = new LambdaQueryWrapper<DeviceInfo>()
  219. .in(DeviceInfo::getDeviceId, dto.getDeviceId())
  220. .select(DeviceInfo::getDeviceId, DeviceInfo::getDeviceName);
  221. List<DeviceInfo> deviceInfoList = list(lqw);
  222. return R.ok(deviceInfoList.stream().collect(Collectors.toMap(DeviceInfo::getDeviceId, i -> Optional.ofNullable(i.getDeviceName()).orElse(""))));
  223. }
  224. @Override
  225. public R<DeviceSysinfoDto.Vo> getDeviceSysinfo(DeviceSysinfoDto.DeviceSysInfo dto) {
  226. String dtoDeviceSN = dto.getDeviceSN();
  227. DeviceSysinfo one = deviceSysinfoService.getOne(Wrappers.<DeviceSysinfo>lambdaQuery().eq(DeviceSysinfo::getDeviceSn, dtoDeviceSN));
  228. return R.ok(BeanUtil.copyProperties(one, DeviceSysinfoDto.Vo.class));
  229. }
  230. @Override
  231. @ApiOperation("设备访问历史添加")
  232. public R history(DeviceInfoDto.Obj obj) {
  233. //获取字典
  234. SysDictRedis sysDictRedis = SysDictUtils.get(EnumDataClearSize.Code.CODE.getCode(), EnumDataClearSize.DEVICE_HISTORY_TWIG.getCode());
  235. Integer value = Integer.valueOf(sysDictRedis.getValue());
  236. //获取redis
  237. String key = keyPrefix + AuthorizeUtils.getLoginId(Long.class);
  238. List<String> list = redisService.getList(key);
  239. list.add(0, String.valueOf(obj.getDeviceId()));
  240. //去重
  241. List<String> redisList = new ArrayList<>();
  242. JList<String> comparing = new JArrayList<>(list).comparing();
  243. if (comparing.size() > value) {
  244. for (int i = 0; i < value; i++) {
  245. redisList.add(comparing.get(i));
  246. }
  247. } else {
  248. redisList = comparing;
  249. }
  250. redisService.removeList(key);
  251. redisService.setList(key, redisList);
  252. return R.ok();
  253. }
  254. @Override
  255. @ApiOperation("开门检测")
  256. public R<DeviceInfoDto.Vo> checkOpenDoor(DeviceInfoDto.Obj obj) {
  257. DeviceInfoDto.Vo deviceInfo = obj(new DeviceInfoDto.Obj()
  258. .setDeviceId(obj.getDeviceId())
  259. .setIsStatus(true)
  260. ).getData();
  261. if (deviceInfo == null) {
  262. return R.fail("设备不存在");
  263. }
  264. Integer busyState = deviceInfo.getBusyState();
  265. SysDictRedis sdr = SysDictUtils.get(EnumDeviceBusyStatus.Code.CODE.getCode(), EnumDeviceBusyStatus.N_2.getCode());
  266. if (busyState.intValue() == Integer.valueOf(sdr.getValue()).intValue()) {
  267. return R.fail("设备已停运");
  268. }
  269. DeviceStatusDto.Vo deviceStatus = deviceInfo.getDeviceStatus();
  270. SysDictRedis sysDictRedis = SysDictUtils.get(EnumDeviceFaultLevelPayThreshold.Code.CODE.getCode(), EnumDeviceFaultLevelPayThreshold.NOT_PAY.getCode());
  271. if (deviceInfo.getFaultLevel() >= Integer.valueOf(sysDictRedis.getValue())) {
  272. return R.fail("设备故障");
  273. }
  274. check(deviceStatus.getNetState(), 2, "设备已离线");
  275. check(obj.getDoor() != null && obj.getDoor() == 1 ? deviceStatus.getDoorStateR() : deviceStatus.getDoorStateL(), 1, "设备正在使用中,请稍后");
  276. //质检用户不检查
  277. SysDictRedis qualitySets = SysDictUtils.get(EnumQualityMercSets.Code.CODE.getCode(), EnumQualityMercSets.MERC_CODE.getCode());
  278. if (!qualitySets.getValue().equals(deviceInfo.getMercCode())) {
  279. check(deviceInfo.getFreezeStatus(), 2, "设备已冻结");
  280. check(obj.getDoor() != null && obj.getDoor() == 1 ? deviceStatus.getLockStateR() : deviceStatus.getLockStateL(), 2, "设备已锁机");
  281. }
  282. return R.ok(deviceInfo);
  283. }
  284. @PostMapping("historyList")
  285. @ApiOperation("设备访问历史查询")
  286. public R<List<DeviceInfoDto.Vo>> historyList() {
  287. //获取redis
  288. String key = keyPrefix + AuthorizeUtils.getLoginId(Long.class);
  289. List<String> deviceIds = redisService.getList(key);
  290. if (!Emptys.check(deviceIds)) {
  291. return R.ok();
  292. }
  293. //查询数据库
  294. List<DeviceInfo> list = list(new LambdaQueryWrapper<DeviceInfo>().in(DeviceInfo::getDeviceId, deviceIds));
  295. return R.ok(copy(DeviceInfoDto.Vo.class, list));
  296. }
  297. @ApiOperation("修改")
  298. @PostMapping("update")
  299. public R update(@RequestBody @Validated DeviceInfoDto.Update update) {
  300. DeviceInfo deviceInfo = copy(DeviceInfo.class, update)
  301. .setUpdateTime(LocalDateTime.now());
  302. updateById(deviceInfo);
  303. Long deviceId = deviceInfo.getDeviceId();
  304. DeviceInfoDto.Vo device = R.feignCheckData(this.obj(new DeviceInfoDto.Obj().setDeviceId(deviceId).setIsSysinfo(true)));
  305. Long algorithmId = update.getAlgorithmId();
  306. if (algorithmId != null && AlgorithmTypeEnum.CLOUD.getId() == algorithmId) {
  307. //云从算法
  308. boolean b = cloudWalkApiService.checkDeviceExist(deviceId);
  309. if (!b) {
  310. //货柜不存在,新增
  311. cloudWalkApiService.containerAdd(new ContainerAddDTO().setContainerCode(String.valueOf(deviceId)));
  312. }
  313. }
  314. Integer deviceType = device.getDeviceType();
  315. if (ObjectUtil.equals(DeviceTypeEnum.TYPE5.getCode(), deviceType)) {
  316. DeviceUpdateDTO deviceUpdateDTO = new DeviceUpdateDTO();
  317. if (StrUtil.isNotEmpty(update.getDeviceName())) {
  318. deviceUpdateDTO.setDeviceName(update.getDeviceName());
  319. }
  320. String deviceSn = device.getDeviceSysinfo().getDeviceSn();
  321. if (deviceUpdateDTO != null) {
  322. deviceUpdateDTO.setTerminalId(String.valueOf(update.getDeviceId()));
  323. deviceUpdateDTO.setBoardSn(deviceSn);
  324. alipayDeviceService.deviceUpdate(deviceUpdateDTO);
  325. }
  326. }
  327. return R.ok();
  328. }
  329. @ApiOperation("批量修改")
  330. @PostMapping("updateBatch")
  331. public R updateBatch(@RequestBody List<DeviceInfoDto.Update> updates) {
  332. LocalDateTime now = LocalDateTime.now();
  333. List<DeviceInfo> deviceInfos = new ArrayList<>(updates.size());
  334. updates.forEach(update -> deviceInfos.add(copy(DeviceInfo.class, update).setUpdateTime(now)));
  335. updateBatchById(deviceInfos);
  336. return R.ok();
  337. }
  338. @Override
  339. @ApiOperation("更新商户线路")
  340. public R updateLine(@RequestBody @Validated DeviceInfoDto.UpdateLine updateLine) {
  341. LambdaUpdateWrapper<DeviceInfo> luw = new LambdaUpdateWrapper<DeviceInfo>().eq(DeviceInfo::getMercId, updateLine.getMercId());
  342. //绑定线路,更换线路
  343. if (DeviceInfoDto.UPDATE.equals(updateLine.getType())) {
  344. DeviceInfo deviceInfo = new DeviceInfo();
  345. deviceInfo.setPlaceLineId(updateLine.getPlaceLineId());
  346. luw.in(DeviceInfo::getDeviceId, updateLine.getDeviceIds());
  347. baseMapper.update(deviceInfo, luw);
  348. }
  349. //删除线路
  350. if (DeviceInfoDto.DEL.equals(updateLine.getType())) {
  351. luw.eq(DeviceInfo::getPlaceLineId, updateLine.getWherePlaceLineId());
  352. luw.set(DeviceInfo::getPlaceLineId, null);
  353. baseMapper.update(null, luw);
  354. }
  355. //解绑线路 设置线路ID为null
  356. if (DeviceInfoDto.CLEAR.equals(updateLine.getType())) {
  357. luw.in(DeviceInfo::getDeviceId, updateLine.getDeviceIds());
  358. luw.set(DeviceInfo::getPlaceLineId, null);
  359. baseMapper.update(null, luw);
  360. }
  361. return R.ok();
  362. }
  363. @Override
  364. @ApiOperation("更新商户点位")
  365. public R updatePlace(@RequestBody @Validated DeviceInfoDto.UpdatePlace updatePlace) {
  366. LambdaUpdateWrapper<DeviceInfo> luw = new LambdaUpdateWrapper<DeviceInfo>().eq(DeviceInfo::getMercId, updatePlace.getMercId());
  367. //绑定点位,更换点位
  368. if (DeviceInfoDto.UPDATE.equals(updatePlace.getType())) {
  369. DeviceInfo deviceInfo = new DeviceInfo();
  370. deviceInfo.setPlaceId(updatePlace.getPlaceId());
  371. luw.in(DeviceInfo::getDeviceId, updatePlace.getDeviceIds());
  372. baseMapper.update(deviceInfo, luw);
  373. }
  374. //删除点位
  375. if (DeviceInfoDto.DEL.equals(updatePlace.getType())) {
  376. luw.eq(DeviceInfo::getPlaceId, updatePlace.getWherePlaceId());
  377. luw.set(DeviceInfo::getPlaceId, null);
  378. baseMapper.update(null, luw);
  379. }
  380. //解绑点位 设置点位ID为null
  381. if (DeviceInfoDto.CLEAR.equals(updatePlace.getType())) {
  382. luw.in(DeviceInfo::getDeviceId, updatePlace.getDeviceIds());
  383. luw.set(DeviceInfo::getPlaceId, null);
  384. baseMapper.update(null, luw);
  385. }
  386. return R.ok();
  387. }
  388. @ApiOperation("分页查询")
  389. @Override
  390. public R<PageBean<DeviceInfoDto.Vo2>> page(@RequestBody DeviceInfoDto.Page page) {
  391. return R.ok(queryPage(page));
  392. }
  393. @ApiOperation("导出设备列表")
  394. @PostMapping("exportDevices")
  395. public void exportDevices(HttpServletResponse response, @RequestBody @Valid DeviceInfoDto.Page page) throws IOException {
  396. PageBean<DeviceInfoDto.Vo2> pageBean = queryPage(page);
  397. List<DeviceInfoDto.Vo2> records = pageBean.getRecords();
  398. List<DeviceInfoDto.DeviceExcelVO> deviceExcelVOS = BeanUtil.copyToList(records, DeviceInfoDto.DeviceExcelVO.class);
  399. // 输出
  400. ExcelUtils.write(response, "设备列表.xls", "设备列表", DeviceInfoDto.DeviceExcelVO.class, deviceExcelVOS);
  401. }
  402. @ApiOperation("导出设备(异步)")
  403. @PostMapping("exportDevices/async")
  404. public void exportDevicesAsync(@RequestBody @Validated DeviceInfoDto.Page page) {
  405. PageBean<DeviceInfoDto.Vo2> pageBean = queryPage(page);
  406. List<DeviceInfoDto.Vo2> records = pageBean.getRecords();
  407. List<DeviceInfoDto.DeviceExcelVO> deviceExcelVOS = BeanUtil.copyToList(records, DeviceInfoDto.DeviceExcelVO.class);
  408. //异步导出参数封装
  409. ExcelDTO<DeviceInfoDto.DeviceExcelVO> excelDTO = new ExcelDTO<>();
  410. excelDTO.setData(deviceExcelVOS);
  411. excelDTO.setHead(DeviceInfoDto.DeviceExcelVO.class);
  412. excelDTO.setSheetName(FileExportType.DEVICE_INFO.getDescription());
  413. excelDTO.setFileExportType(FileExportType.DEVICE_INFO);
  414. //执行导出
  415. fileExportService.exportExcelAsync(excelDTO);
  416. }
  417. @PostMapping("nearbyPage")
  418. @ApiOperation("附近设备分页查询")
  419. public R<PageBean<DeviceInfoDto.Vo2>> nearbyPage(@RequestBody DeviceInfoDto.Page page) {
  420. if (!Emptys.check(page.getLon()) || !Emptys.check(page.getLat())) {
  421. throw new CommRuntimeException("经纬度不能为空");
  422. }
  423. return R.ok(queryPage(page));
  424. }
  425. @ApiOperation(value = "商户设备授权", hidden = true)
  426. @Override
  427. @Transactional(rollbackFor = Exception.class)
  428. public R<Boolean> mercDeviceAuth(DeviceInfoDto.MercDeviceAuthDto auth) {
  429. Long mercId = auth.getMercId();
  430. String mercCode = auth.getMercCode();
  431. Long algorithmId = auth.getAlgorithmId();
  432. String mercName = auth.getMercName();
  433. //商户最终设备列表
  434. List<Long> deviceIds = auth.getDeviceIds();
  435. List<DeviceInfo> devices = getDevicesByMercId(mercId);
  436. //取消商户设备授权
  437. if (CollUtil.isEmpty(deviceIds)) {
  438. if (CollUtil.isEmpty(devices)) {
  439. return R.ok(Boolean.TRUE);
  440. }
  441. }
  442. //更新商户设备授权
  443. List<DeviceInfo> deviceInfos = this.listByIds(deviceIds);
  444. for (DeviceInfo deviceInfo : deviceInfos) {
  445. Integer deviceType = deviceInfo.getDeviceType();
  446. Long deviceId = deviceInfo.getDeviceId();
  447. if (ObjectUtil.equals(deviceType, DeviceTypeEnum.TYPE5.getCode())) {
  448. //支付宝设备算法
  449. algorithmId = AlgorithmTypeEnum.ALIPAY.getId();
  450. } else {
  451. //非支付宝算法
  452. if (AlgorithmTypeEnum.CLOUD.getId() == algorithmId) {
  453. //云从算法
  454. boolean b = cloudWalkApiService.checkDeviceExist(deviceId);
  455. if (!b) {
  456. //货柜不存在,新增
  457. cloudWalkApiService.containerAdd(new ContainerAddDTO().setContainerCode(String.valueOf(deviceId)));
  458. }
  459. }
  460. }
  461. int refMercId = deviceInfo.getMercId().intValue();
  462. String refMercCode = deviceInfo.getMercCode();
  463. // 只有解绑后,才能给顶级商户授权
  464. if (refMercId != -1 && refMercId != mercId.intValue()) {
  465. StrBuilder sb = StrBuilder.create();
  466. String errMsg = sb.append("设备[")
  467. .append(deviceInfo.getDeviceId())
  468. .append("]")
  469. .append("已被商户[")
  470. .append(deviceInfo.getMercName())
  471. .append("]绑定,请先进行解绑!")
  472. .toString();
  473. //非质检商户需要进行判断,质检商户跳过
  474. if (!QA_MERC_CODE.equals(refMercCode)) {
  475. //已关联别商户
  476. return R.fail(errMsg, Boolean.FALSE);
  477. }
  478. }
  479. //绑定关系
  480. deviceInfo.setMercId(mercId).setMercCode(mercCode).setAlgorithmId(algorithmId).setMercName(mercName);
  481. }
  482. saveOrUpdateBatch(deviceInfos);
  483. // //原来存在的设备关系,不在最终设备列表中的移除
  484. // if (CollUtil.isNotEmpty(devices)) {
  485. // List<Long> oldIds = new ArrayList<>();
  486. // List<Long> removeIds = new ArrayList<>();
  487. // devices.forEach(device -> oldIds.add(device.getDeviceId()));
  488. // oldIds.forEach(deviceId -> {
  489. // //不在最终设备列表中的待移除
  490. // if (!deviceIds.contains(deviceId)) {
  491. // removeIds.add(deviceId);
  492. // }
  493. // });
  494. // if (CollUtil.isNotEmpty(removeIds)) {
  495. // List<DeviceInfo> removeList = this.listByIds(removeIds);
  496. // removeMerRefDevices(removeList, parentId);
  497. // }
  498. // }
  499. return R.ok(Boolean.TRUE);
  500. }
  501. /**
  502. * 解绑机器 回收
  503. *
  504. * @param dto
  505. * @return
  506. */
  507. @Override
  508. public R<Boolean> unBindMercDevice(DeviceInfoDto.MercDeviceUnBindDto dto) {
  509. List<DeviceInfo> deviceInfos = this.listByIds(dto.getDeviceIds());
  510. return R.ok(removeMerRefDevicesToTopMerc(deviceInfos));
  511. }
  512. /**
  513. * 回收机器
  514. *
  515. * @param deviceInfos
  516. * @return
  517. */
  518. private Boolean removeMerRefDevicesToTopMerc(List<DeviceInfo> deviceInfos) {
  519. MercDto.Vo mercCheck = R.feignCheckData(mercFeignService.obj(new MercDto.ListDTO().setMercCode(QA_MERC_CODE)));
  520. if (CollUtil.isNotEmpty(deviceInfos)) {
  521. deviceInfos.forEach(deviceInfo -> {
  522. //回收
  523. deviceInfo.setMercId(mercCheck.getId());
  524. deviceInfo.setMercDeviceCode(StrUtil.EMPTY);
  525. deviceInfo.setMercName(mercCheck.getName());
  526. deviceInfo.setMercCode(QA_MERC_CODE);
  527. });
  528. //批量更新
  529. return updateBatchById(deviceInfos);
  530. }
  531. return Boolean.FALSE;
  532. }
  533. /**
  534. * 批量移除商户设备绑定关系
  535. *
  536. * @param deviceInfos
  537. * @return
  538. */
  539. private Boolean removeMerRefDevices(List<DeviceInfo> deviceInfos, Long parentId) {
  540. if (CollUtil.isNotEmpty(deviceInfos) && parentId != null) {
  541. deviceInfos.forEach(deviceInfo -> {
  542. //非顶级兴元商户,解绑后,机器归父商户
  543. if (parentId != 1) {
  544. MercDto.Vo mercParent = R.feignCheckData(mercFeignService.obj(new MercDto.ListDTO().setId(parentId)));
  545. if (mercParent != null) {
  546. deviceInfo.setMercId(mercParent.getId());
  547. deviceInfo.setMercName(mercParent.getName());
  548. deviceInfo.setMercCode(mercParent.getMercCode());
  549. } else {
  550. deviceInfo.setMercId(-1L);
  551. deviceInfo.setMercName(StrUtil.EMPTY);
  552. deviceInfo.setMercCode(StrUtil.EMPTY);
  553. }
  554. }
  555. //一级商户,解绑后,直接释放
  556. if (parentId == 0) {
  557. MercDto.Vo mercCheck = R.feignCheckData(mercFeignService.obj(new MercDto.ListDTO().setMercCode(QA_MERC_CODE)));
  558. if (mercCheck != null) {
  559. deviceInfo.setMercId(mercCheck.getId());
  560. deviceInfo.setMercName(mercCheck.getName());
  561. deviceInfo.setMercCode(mercCheck.getMercCode());
  562. } else {
  563. deviceInfo.setMercId(-1L);
  564. deviceInfo.setMercName(StrUtil.EMPTY);
  565. deviceInfo.setMercCode(StrUtil.EMPTY);
  566. }
  567. }
  568. });
  569. //批量更新
  570. return updateBatchById(deviceInfos);
  571. }
  572. return Boolean.FALSE;
  573. }
  574. @ApiOperation("集合查询")
  575. @Override
  576. public R<List<DeviceInfoDto.Vo>> list(DeviceInfoDto.ListDto dto) {
  577. List<DeviceInfo> list = list(new LambdaQueryWrapper<DeviceInfo>()
  578. .in(CollUtil.isNotEmpty(dto.getDeviceIds()), DeviceInfo::getDeviceId, dto.getDeviceIds())
  579. .eq(Emptys.check(dto.getMercId()), DeviceInfo::getMercId, dto.getMercId())
  580. );
  581. return R.ok(copy(DeviceInfoDto.Vo.class, list));
  582. }
  583. @Override
  584. @ApiOperation("通用集合查询")
  585. public R<List<DeviceInfoDto.Vo>> listCommon(DeviceInfoDto.ListCommon dto) {
  586. String deviceSearch = dto.getDeviceSearch();
  587. DeviceInfoDto.Vo vo = dto.getVo();
  588. QueryWrapper<DeviceInfo> queryWrapper = new MybatisPlusQuery().eqWrapper(vo == null ? new DeviceInfoDto.Vo() : vo, DeviceInfo.class).buildQW();
  589. // List<Long> placeLineIds = dto.getPlaceLineIds();
  590. List<Long> deviceIds = dto.getDeviceIds();
  591. List<String> columnList = dto.getColumnList();
  592. // if (CollUtil.isNotEmpty(placeLineIds)) {
  593. // queryWrapper.in(LambdaUtils.getUnderlineCaseName(DeviceInfo::getPlaceLineId), placeLineIds);
  594. // }
  595. //fixed
  596. if (StrUtil.isNotEmpty(deviceSearch)) {
  597. queryWrapper.and(wrapper -> wrapper.likeRight(LambdaUtils.getUnderlineCaseName(DeviceInfo::getDeviceName), deviceSearch).or()
  598. .eq(LambdaUtils.getUnderlineCaseName(DeviceInfo::getDeviceId), deviceSearch));
  599. }
  600. if (CollUtil.isNotEmpty(columnList)) {
  601. queryWrapper.select(columnList.stream().toArray(String[]::new));
  602. }
  603. if (CollUtil.isNotEmpty(deviceIds)) {
  604. queryWrapper.in(LambdaUtils.getUnderlineCaseName(DeviceInfo::getDeviceId), deviceIds);
  605. }
  606. return R.ok(copy(DeviceInfoDto.Vo.class, list(queryWrapper)));
  607. }
  608. @Override
  609. @ApiOperation("商户设备算法列表")
  610. public R<List<Long>> mercAlgorithmIdList(DeviceInfoDto.MercAlgorithmIdListDto dto) {
  611. String algorithmIdStr = LambdaUtils.getProperty(DeviceInfo::getAlgorithmId);
  612. String mercStr = StringTools.humpToLine(LambdaUtils.getProperty(DeviceInfo::getMercId));
  613. QueryWrapper<DeviceInfo> lqw = new QueryWrapper<DeviceInfo>()
  614. .isNotNull(StringTools.humpToLine(algorithmIdStr))
  615. .eq(mercStr, dto.getMercId())
  616. .select(String.format("DISTINCT (%s) as %s", StringTools.humpToLine(algorithmIdStr), algorithmIdStr));
  617. List<Long> list = listObjs(lqw, (MapperFunction<Object, Long>) o -> (Long) o);
  618. return R.ok(list);
  619. }
  620. @Override
  621. @ApiOperation("小程序-商户设备首页统计")
  622. public R<DeviceInfoDto.MercHomeStatisticalVO> mercHomeStatistical(DeviceInfoDto.MercHomeQueryDTO dto) {
  623. Long mercId = dto.getMercId();
  624. List<Long> myDeviceIds = dto.getMyDeviceIds();
  625. //初始化数据
  626. DeviceInfoDto.MercHomeStatisticalVO mercHomeStatisticalVO = new DeviceInfoDto.MercHomeStatisticalVO()
  627. .setClosedNum(0).setOfflineNum(0)
  628. .setOnlineNum(0).setOperatingNum(0).setNeedToFillNum(0);
  629. if (CollUtil.isEmpty(myDeviceIds)) {
  630. return R.ok(mercHomeStatisticalVO);
  631. }
  632. List<DeviceInfo> mercDevices = listByIds(myDeviceIds);
  633. if (CollUtil.isEmpty(mercDevices)) {
  634. return R.ok(mercHomeStatisticalVO);
  635. }
  636. //在线、离线
  637. List<DeviceStatus> deviceStatuses = deviceStatusService.listByIds(myDeviceIds);
  638. //分组统计
  639. Map<Integer, Long> countNetstateMap = deviceStatuses.stream().collect(Collectors
  640. .groupingBy(DeviceStatus::getNetState, Collectors.counting()));
  641. Integer onlineDictValue = SysDictUtils.getValue(EnumDeviceOnlineStatus.Code.CODE.getCode(), EnumDeviceOnlineStatus.CONNECTED.getCode(), Integer.class);
  642. Integer offlineDictValue = SysDictUtils.getValue(EnumDeviceOnlineStatus.Code.CODE.getCode(), EnumDeviceOnlineStatus.DISCONNECT.getCode(), Integer.class);
  643. int onlineNum = countNetstateMap.get(onlineDictValue) == null ? 0 : countNetstateMap.get(onlineDictValue).intValue();
  644. int offlineNum = countNetstateMap.get(offlineDictValue) == null ? 0 : countNetstateMap.get(offlineDictValue).intValue();
  645. mercHomeStatisticalVO.setOnlineNum(onlineNum);
  646. mercHomeStatisticalVO.setOfflineNum(offlineNum);
  647. //锁机、未锁机
  648. Map<Integer, Long> countLockLstateMap = deviceStatuses.stream().collect(Collectors
  649. .groupingBy(DeviceStatus::getLockStateL, Collectors.counting()));
  650. Long lockLStateNum = countLockLstateMap.get(DeviceLockState.LOCK.getCode());
  651. Long unLockLStateNum = countLockLstateMap.get(DeviceLockState.UN_LOCK.getCode());
  652. mercHomeStatisticalVO.setOperatingNum(unLockLStateNum == null ? 0 : unLockLStateNum.intValue());
  653. mercHomeStatisticalVO.setClosedNum(lockLStateNum == null ? 0 : lockLStateNum.intValue());
  654. //待补货
  655. Integer deviceNum = R.feignCheckData(goodsDeviceService.countOutOfStockDevice(new GoodsDeviceDto.CountOutOfStockDevice().setMercId(mercId)));
  656. mercHomeStatisticalVO.setNeedToFillNum(deviceNum);
  657. return R.ok(mercHomeStatisticalVO);
  658. }
  659. @Override
  660. @ApiOperation("小程序-商户设备首页列表")
  661. public R<List<DeviceInfoDto.MercHomeListVO>> mercHomeList(DeviceInfoDto.MercHomeQueryDTO dto) {
  662. String searchKey = dto.getSearchKey();
  663. Long mercId = dto.getMercId();
  664. String deviceName = dto.getDeviceName();
  665. Long deviceId = dto.getDeviceId();
  666. boolean isQa = false;
  667. if ("393010594508869".equals(String.valueOf(mercId))) {
  668. isQa = true;
  669. } else {
  670. dto.setActiveState("1");
  671. }
  672. List<Long> searchDeviceIds = new ArrayList<>();
  673. if (StrUtil.isNotEmpty(searchKey)) {
  674. //名称或者编号搜索设备
  675. List<DeviceInfo> list = list(Wrappers.<DeviceInfo>lambdaQuery()
  676. .eq(DeviceInfo::getMercId, mercId)
  677. .and(wrapper -> wrapper
  678. .eq(DeviceInfo::getDeviceId, searchKey)
  679. .or()
  680. .likeRight(DeviceInfo::getDeviceName, searchKey)
  681. )
  682. );
  683. if (CollUtil.isEmpty(list)) {
  684. return R.ok(new ArrayList<>());
  685. }
  686. searchDeviceIds = list.stream().map(DeviceInfo::getDeviceId).collect(Collectors.toList());
  687. }
  688. List<Long> myDeviceIds = dto.getDeviceIdList();
  689. Integer busyStatus = dto.getBusyStatus();
  690. Integer onlineStatus = dto.getOnlineStatus();
  691. Integer deviceType = dto.getDeviceType();
  692. //条件查询 在线状态,运营状态,设备类型,
  693. List<Long> deviceIdList = new ArrayList<>();
  694. if (deviceId != null && myDeviceIds.indexOf(deviceId) > 0) {
  695. deviceIdList.add(deviceId);
  696. }
  697. if (CollUtil.isNotEmpty(myDeviceIds) && deviceId == null) {
  698. deviceIdList.addAll(myDeviceIds);
  699. }
  700. if (CollUtil.isNotEmpty(deviceIdList)) {
  701. dto.setDeviceIdList(deviceIdList);
  702. List<Long> queryDeviceIds = new ArrayList<>();
  703. if (CollUtil.isNotEmpty(searchDeviceIds)) {
  704. for (Long id : searchDeviceIds) {
  705. int index = deviceIdList.indexOf(id);
  706. if (index > 0) {
  707. queryDeviceIds.add(id);
  708. }
  709. }
  710. //无符合权限的搜索设备,返空
  711. if (CollUtil.isEmpty(queryDeviceIds)) {
  712. return R.ok(new ArrayList<>());
  713. } else {
  714. deviceIdList = queryDeviceIds;
  715. dto.setDeviceIdList(queryDeviceIds);
  716. }
  717. }
  718. } else {
  719. return R.ok(new ArrayList<>());
  720. }
  721. if (onlineStatus != null) {
  722. List<DeviceStatus> deviceStatusList = deviceStatusService.list(Wrappers.<DeviceStatus>lambdaQuery()
  723. .eq(DeviceStatus::getNetState, onlineStatus)
  724. .in(CollUtil.isNotEmpty(myDeviceIds), DeviceStatus::getDeviceId, deviceIdList)
  725. );
  726. if (CollUtil.isNotEmpty(deviceStatusList)) {
  727. List<Long> dbDeviceIdList = deviceStatusList.stream().map(DeviceStatus::getDeviceId).collect(Collectors.toList());
  728. deviceIdList = dbDeviceIdList;
  729. } else {
  730. return R.ok(new ArrayList<>());
  731. }
  732. }
  733. List<DeviceInfoDto.MercHomeCountVO> list = this.baseMapper.merHomeCountList(dto);
  734. if (CollUtil.isEmpty(list)) {
  735. return R.ok(Collections.emptyList());
  736. }
  737. List<DeviceInfoDto.MercHomeListVO> dataList = new ArrayList<>(list.size());
  738. LambdaQueryWrapper<DeviceInfo> lqw = new LambdaQueryWrapper<>();
  739. //非质检商户才需要激活
  740. lqw.eq(!isQa, DeviceInfo::getActiveState, DeviceActiveStateEnum.TRUE.getCode());
  741. lqw.eq(mercId != null, DeviceInfo::getMercId, mercId);
  742. lqw.eq(busyStatus != null, DeviceInfo::getBusyState, busyStatus);
  743. lqw.eq(deviceType != null, DeviceInfo::getDeviceType, deviceType);
  744. lqw.in(CollUtil.isNotEmpty(deviceIdList), DeviceInfo::getDeviceId, deviceIdList);
  745. lqw.like(StrUtil.isNotEmpty(deviceName), DeviceInfo::getDeviceName, deviceName).orderByAsc(true, DeviceInfo::getDeviceName, DeviceInfo::getDeviceId);
  746. List<DeviceInfo> deviceInfoList = this.list(lqw);
  747. //未分区域的设置默认值
  748. deviceInfoList.stream().filter(s -> s.getDistrictId() == null).forEach(s -> s.setDistrictId(-1L));
  749. Map<Long, String> districtMap = new HashMap<>();
  750. List<Long> districtIdList = list.stream().map(DeviceInfoDto.MercHomeCountVO::getDistrictId).filter(i -> i != -1).collect(Collectors.toList());
  751. districtMap = mercRegionService.getNameList(new MercRegionDto.GetNameListDto().setIds(districtIdList)).getData();
  752. //根据区域id分组
  753. Map<Long, List<DeviceInfo>> deviceMap = deviceInfoList.stream().collect(Collectors.groupingBy(DeviceInfo::getDistrictId));
  754. DateTime date = DateTime.now();
  755. DateTime start = DateUtil.beginOfDay(date);
  756. DateTime end = DateUtil.endOfDay(date);
  757. for (DeviceInfoDto.MercHomeCountVO v : list) {
  758. DeviceInfoDto.MercHomeListVO vo = new DeviceInfoDto.MercHomeListVO();
  759. Long districtId = v.getDistrictId();
  760. vo.setDeviceNum(v.getDeviceNum());
  761. vo.setDistrictId(v.getDistrictId());
  762. vo.setDistrictName(v.getDistrictId() == -1L ? "未分配区域" : districtMap.get(v.getDistrictId()));
  763. //区域下的设备列表
  764. List<DeviceInfoDto.MercHomeDeviceVo> deviceInfos = BeanUtil.copyToList(deviceMap.get(districtId), DeviceInfoDto.MercHomeDeviceVo.class);
  765. if (CollUtil.isEmpty(deviceInfos)) {
  766. continue;
  767. }
  768. //设备销售统计
  769. List<Long> deviceIds = deviceInfos.stream().map(DeviceInfoDto.MercHomeDeviceVo::getDeviceId).collect(Collectors.toList());
  770. //设备状态查询
  771. List<DeviceStatusDto.Vo> deviceStatusList = deviceStatusService.list(new DeviceStatusDto.SelectList().setDeviceIds(deviceIds)).getData();
  772. Map<Long, DeviceStatusDto.Vo> datdeviceStatusMap = new HashMap<>();
  773. if (CollUtil.isNotEmpty(deviceStatusList)) {
  774. datdeviceStatusMap = deviceStatusList.stream().collect(Collectors.toMap(DeviceStatusDto.Vo::getDeviceId, d -> d));
  775. }
  776. List<GoodsDeviceDto.Vo> goodsDeviceList = R.feignCheckData(goodsService.queryGoodsDeviceInfo(new GoodsDto.QueryGoodsDeviceInfo().setMercId(mercId).setDeviceIds(deviceIds)));
  777. Map<Long, List<GoodsDeviceDto.Vo>> deviceIdGoodsMap = goodsDeviceList.stream()
  778. .collect(Collectors.groupingBy(GoodsDeviceDto.Vo::getDeviceId));
  779. List<AlgorithmDto.ListNameId> algorithmList = R.feignCheckData(algorithmService.ListNameId());
  780. Map<Long, String> algorithmListMap = algorithmList.stream().collect(Collectors.toMap(AlgorithmDto.ListNameId::getId, AlgorithmDto.ListNameId::getAlias));
  781. for (DeviceInfoDto.MercHomeDeviceVo device : deviceInfos) {
  782. Long dId = device.getDeviceId();
  783. //设备类型 反显
  784. SysDictRedis dictDeviceType = SysDictUtils.get(DictConsts.DEVICE_TYPE, String.valueOf(device.getDeviceType()));
  785. device.setDeviceTypeName(dictDeviceType.getMsg());
  786. //运营状态 反显
  787. SysDictRedis dictBusyState = SysDictUtils.get(DictConsts.DEVICE_BUSY_STATUS, String.valueOf(device.getBusyState()));
  788. device.setBusyStateName(dictBusyState.getMsg());
  789. Integer zero = new Integer(0);
  790. CountDto.OrderByCreateTimeAndMercId orderByCreateTimeAndMercId = new CountDto.OrderByCreateTimeAndMercId()
  791. .setMerdId(mercId).setBeginTime(start).setEndTime(end).setDeviceIds(CollUtil.newArrayList(dId));
  792. log.info("设备订单统计:{}", JSONUtil.toJsonPrettyStr(orderByCreateTimeAndMercId));
  793. //完成订单
  794. CountDto.SuccessVo successVo = R.feignCheckData(countApiService.orderBySuccess(orderByCreateTimeAndMercId));
  795. //今日销售、库存情况 反显
  796. device.setDayOrderNum(successVo != null ? successVo.getOrdersSize() : zero);
  797. device.setDaySalesPrice(successVo != null ? successVo.getOrderTotalMoney() : zero);
  798. DeviceStatusDto.Vo deviceStatus = datdeviceStatusMap.get(device.getDeviceId());
  799. if (CollUtil.isNotEmpty(deviceIdGoodsMap)) {
  800. List<GoodsDeviceDto.Vo> goodsDevice = deviceIdGoodsMap.get(dId);
  801. if (CollUtil.isNotEmpty(goodsDevice)) {
  802. device.setOnSaleNum(goodsDevice.stream().mapToInt(GoodsDeviceDto.Vo::getStock).sum());
  803. device.setFillNum(goodsDevice.stream().mapToInt(GoodsDeviceDto.Vo::getFillCount).sum());
  804. }
  805. }
  806. //算法類型
  807. Long algorithmId = device.getAlgorithmId();
  808. if (algorithmId != null) {
  809. String name = algorithmListMap.get(algorithmId);
  810. device.setAlgorithmAlias(name);
  811. }
  812. //联网状态
  813. Integer netState = deviceStatus == null ? DeviceNetSateType.DISCONNECT.getCode() : deviceStatus.getNetState();
  814. device.setNetState(netState);
  815. if (netState == null) {
  816. device.setNetStateName(StrUtil.EMPTY);
  817. } else {
  818. device.setNetStateName(DeviceNetSateType.getEnumByCode(netState).getDescription());
  819. }
  820. if (deviceStatus != null) {
  821. Integer deviceStateL = deviceStatus.getLockStateL();
  822. Integer deviceStateR = deviceStatus.getLockStateR();
  823. device.setTempValue(deviceStatus.getTempValue());
  824. device.setDeviceStateL(deviceStateL);
  825. device.setDeviceStateR(deviceStateR);
  826. device.setSysPower(deviceStatus.getSysPower());
  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. }