| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- package com.kym.service.impl;
- import cn.dev33.satoken.stp.StpUtil;
- import com.github.pagehelper.PageHelper;
- import com.kym.common.utils.CommUtil;
- import com.kym.entity.WashDevice;
- import com.kym.entity.common.PageBean;
- import com.kym.entity.queryParams.DeviceQueryParams;
- import com.kym.entity.vo.WashDeviceVo;
- import com.kym.mapper.WashDeviceMapper;
- import com.kym.service.WashDeviceService;
- import com.kym.service.WashOrderService;
- import com.kym.service.cache.KymCache;
- import com.kym.service.mybatisplus.MyBaseServiceImpl;
- import org.springframework.beans.BeanUtils;
- import org.springframework.stereotype.Service;
- import java.util.ArrayList;
- import java.util.List;
- /**
- * <p>
- * 洗车设备表 服务实现类
- * </p>
- *
- * @author skyline
- * @since 2024-10-09
- */
- @Service
- public class WashDeviceServiceImpl extends MyBaseServiceImpl<WashDeviceMapper, WashDevice> implements WashDeviceService {
- private WashOrderService washOrderService;
- public WashDeviceServiceImpl(WashOrderService washOrderService) {
- this.washOrderService = washOrderService;
- }
- //region 小程序
- /**
- * 获取设备列表
- *
- * @param params
- * @return
- */
- @Override
- public List<WashDeviceVo> listWashDevice(DeviceQueryParams params) {
- var list = lambdaQuery()
- .eq(CommUtil.isNotEmptyAndNull(params.getId()), WashDevice::getId, params.getId())
- .eq(CommUtil.isNotEmptyAndNull(params.getStationId()), WashDevice::getStationId, params.getStationId())
- .orderByAsc(WashDevice::getDeviceName)
- .list();
- var voList = new ArrayList<WashDeviceVo>();
- //TODO 根据订单查询占用中的设备
- // var currentUserId = StpUtil.getLoginIdAsLong();
- for (WashDevice washDevice : list) {
- var vo = new WashDeviceVo();
- // .setCurrentUserId(currentUserId);
- BeanUtils.copyProperties(washDevice, vo);
- vo.setShortId(KymCache.INSTANCE.getShortIdByProductKeyAndDeviceName(washDevice.getProductKey(), washDevice.getDeviceName()));
- vo.setSeqName(KymCache.INSTANCE.getSeqNameByShortId(vo.getShortId()));
- voList.add(vo);
- }
- return voList;
- }
- /**
- * 根据设备短id获取设备信息
- *
- * @param shortId
- * @return
- */
- @Override
- public WashDeviceVo getDevice(String shortId) {
- var productKeyAndDeviceName = KymCache.INSTANCE.getProductKeyAndDeviceNameByWashShortId(shortId);
- var washDevice = lambdaQuery()
- .eq(WashDevice::getProductKey, productKeyAndDeviceName[0])
- .eq(WashDevice::getDeviceName, productKeyAndDeviceName[1])
- .one();
- //TODO 根据订单查询占用中的设备
- var vo = new WashDeviceVo().setCurrentUserId(StpUtil.getLoginIdAsLong());
- BeanUtils.copyProperties(washDevice, vo.setShortId(shortId));
- return vo;
- }
- @Override
- public String startDevice(String shortId) {
- var productKeyAndDeviceName = KymCache.INSTANCE.getProductKeyAndDeviceNameByWashShortId(shortId);
- return washOrderService.createOrder(new DeviceQueryParams(shortId, productKeyAndDeviceName[0], productKeyAndDeviceName[1]));
- }
- @Override
- public void stopDevice(String shortId) {
- var productKeyAndDeviceName = KymCache.INSTANCE.getProductKeyAndDeviceNameByWashShortId(shortId);
- washOrderService.closeOrder(new DeviceQueryParams(shortId, productKeyAndDeviceName[0], productKeyAndDeviceName[1]));
- }
- //endregion
- //region 管理后台
- @Override
- public Object detail(long id) {
- return getById(id);
- }
- @Override
- public void remove(long id) {
- }
- @Override
- public void modify(WashDevice device) {
- CommUtil.assertsNonNulls(List.of(device.getDeviceName(), device.getStationId(), device.getProductKey(), device.getId()), "参数异常");
- List<WashDevice> list = lambdaQuery()
- .eq(WashDevice::getStationId, device.getStationId())
- .eq(WashDevice::getDeviceName, device.getDeviceName())
- .eq(WashDevice::getProductKey, device.getProductKey())
- .list();
- CommUtil.asserts(list.size() <= 1, "设备信息异常");
- if (list.size() == 1) {
- CommUtil.asserts(list.get(0).getDeviceName().equalsIgnoreCase(device.getDeviceName()), "站点已存在");
- }
- updateById(device);
- }
- @Override
- public void add(WashDevice device) {
- CommUtil.assertsNonNulls(List.of(device.getDeviceName(), device.getStationId(), device.getProductKey()), "参数异常");
- Long count = lambdaQuery()
- .eq(WashDevice::getStationId, device.getStationId())
- .eq(WashDevice::getProductKey, device.getProductKey()).count();
- CommUtil.asserts(count == 0, "设备已存在");
- save(device);
- }
- @Override
- public PageBean<WashDeviceVo> list(DeviceQueryParams query) {
- PageHelper.startPage(query.getPageNum(), query.getPageSize());
- List<WashDevice> list = lambdaQuery()
- .eq(CommUtil.isNotEmptyAndNull(query.getStationId()), WashDevice::getStationId, query.getStationId())
- .list();
- var voList = new ArrayList<WashDeviceVo>();
- list.forEach(item -> {
- var vo = new WashDeviceVo();
- BeanUtils.copyProperties(item, vo);
- vo.setShortId(KymCache.INSTANCE.getShortIdByProductKeyAndDeviceName(item.getProductKey(), item.getDeviceName()));
- vo.setStationName(KymCache.INSTANCE.getStationNameById(item.getStationId()));
- voList.add(vo);
- });
- return new PageBean<>(voList);
- }
- //endregion
- }
|