WashDeviceServiceImpl.java 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. package com.kym.service.miniapp.impl;
  2. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  3. import com.github.pagehelper.PageHelper;
  4. import com.github.yulichang.toolkit.JoinWrappers;
  5. import com.github.yulichang.wrapper.MPJLambdaWrapper;
  6. import com.kym.common.utils.CommUtil;
  7. import com.kym.entity.common.PageBean;
  8. import com.kym.entity.miniapp.OrderRechargeRights;
  9. import com.kym.entity.miniapp.UserRechargeRights;
  10. import com.kym.entity.miniapp.WashDevice;
  11. import com.kym.entity.miniapp.WashStation;
  12. import com.kym.entity.miniapp.queryParams.DeviceQueryParams;
  13. import com.kym.entity.miniapp.vo.UserOrderRechargeRightsVo;
  14. import com.kym.entity.miniapp.vo.WashDeviceVo;
  15. import com.kym.mapper.miniapp.WashDeviceMapper;
  16. import com.kym.service.cache.KymCache;
  17. import com.kym.service.miniapp.WashDeviceService;
  18. import com.kym.service.miniapp.WashOrderService;
  19. import com.kym.service.mybatisplus.MyBaseServiceImpl;
  20. import org.springframework.beans.BeanUtils;
  21. import org.springframework.stereotype.Service;
  22. import java.util.ArrayList;
  23. import java.util.List;
  24. /**
  25. * <p>
  26. * 洗车设备表 服务实现类
  27. * </p>
  28. *
  29. * @author skyline
  30. * @since 2024-10-09
  31. */
  32. @Service
  33. public class WashDeviceServiceImpl extends MyBaseServiceImpl<WashDeviceMapper, WashDevice> implements WashDeviceService {
  34. private WashOrderService washOrderService;
  35. public WashDeviceServiceImpl(WashOrderService washOrderService) {
  36. this.washOrderService = washOrderService;
  37. }
  38. //region 小程序
  39. /**
  40. * 获取设备列表
  41. *
  42. * @param params
  43. * @return
  44. */
  45. @Override
  46. public List<WashDeviceVo> listWashDevice(DeviceQueryParams params) {
  47. var list = lambdaQuery()
  48. .eq(CommUtil.isNotEmptyAndNull(params.getId()), WashDevice::getId, params.getId())
  49. .eq(CommUtil.isNotEmptyAndNull(params.getStationId()), WashDevice::getStationId, params.getStationId())
  50. .orderByAsc(WashDevice::getDeviceName)
  51. .list();
  52. var voList = new ArrayList<WashDeviceVo>();
  53. for (WashDevice washDevice : list) {
  54. var vo = new WashDeviceVo();
  55. BeanUtils.copyProperties(washDevice, vo);
  56. vo.setShortId(KymCache.INSTANCE.getShortIdByProductKeyAndDeviceName(washDevice.getProductKey(), washDevice.getDeviceName()));
  57. voList.add(vo);
  58. }
  59. return voList;
  60. }
  61. /**
  62. * 根据设备短id获取设备信息
  63. *
  64. * @param shortId
  65. * @return
  66. */
  67. @Override
  68. public WashDeviceVo getDevice(String shortId) {
  69. var productKeyAndDeviceName = KymCache.INSTANCE.getProductKeyAndDeviceNameByWashShortId(shortId);
  70. var washDevice = lambdaQuery()
  71. .eq(WashDevice::getProductKey, productKeyAndDeviceName[0])
  72. .eq(WashDevice::getDeviceName, productKeyAndDeviceName[1])
  73. .one();
  74. var vo = new WashDeviceVo();
  75. BeanUtils.copyProperties(washDevice, vo.setShortId(shortId));
  76. return vo;
  77. }
  78. @Override
  79. public String startDevice(String shortId) {
  80. var productKeyAndDeviceName = KymCache.INSTANCE.getProductKeyAndDeviceNameByWashShortId(shortId);
  81. return washOrderService.createOrder(new DeviceQueryParams(shortId, productKeyAndDeviceName[0], productKeyAndDeviceName[1]));
  82. }
  83. @Override
  84. public void stopDevice(String shortId) {
  85. var productKeyAndDeviceName = KymCache.INSTANCE.getProductKeyAndDeviceNameByWashShortId(shortId);
  86. washOrderService.closeOrder(new DeviceQueryParams(shortId, productKeyAndDeviceName[0], productKeyAndDeviceName[1]));
  87. }
  88. //endregion
  89. //region 管理后台
  90. @Override
  91. public Object detail(long id) {
  92. return getById(id);
  93. }
  94. @Override
  95. public void remove(long id) {
  96. }
  97. @Override
  98. public void modify(WashDevice device) {
  99. CommUtil.assertsNonNulls(List.of(device.getDeviceName(), device.getStationId(), device.getProductKey(), device.getId()), "参数异常");
  100. List<WashDevice> list = lambdaQuery()
  101. .eq(WashDevice::getStationId, device.getStationId())
  102. .eq(WashDevice::getProductKey, device.getProductKey()).list();
  103. CommUtil.asserts(list.size() <= 1, "设备信息异常");
  104. if (list.size() == 1) {
  105. CommUtil.asserts(list.get(0).getDeviceName().equalsIgnoreCase(device.getDeviceName()), "站点已存在");
  106. }
  107. updateById(device);
  108. }
  109. @Override
  110. public void add(WashDevice device) {
  111. CommUtil.assertsNonNulls(List.of(device.getDeviceName(), device.getStationId(), device.getProductKey()), "参数异常");
  112. Long count = lambdaQuery()
  113. .eq(WashDevice::getStationId, device.getStationId())
  114. .eq(WashDevice::getProductKey, device.getProductKey()).count();
  115. CommUtil.asserts(count == 0, "设备已存在");
  116. save(device);
  117. }
  118. @Override
  119. public Object list(DeviceQueryParams query) {
  120. PageHelper.startPage(query.getPageNum(), query.getPageSize());
  121. List<WashDevice> list = lambdaQuery()
  122. .like(CommUtil.isNotEmptyAndNull(query.getDeviceName()), WashDevice::getDeviceName, query.getDeviceName())
  123. .eq(CommUtil.isNotEmptyAndNull(query.getStationId()), WashDevice::getStationId, query.getStationId())
  124. .list();
  125. return new PageBean<>(list);
  126. }
  127. //endregion
  128. }