WashDeviceServiceImpl.java 5.7 KB

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