DeviceInfoServiceImpl.java 80 KB

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