package com.kym.service.miniapp.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.github.pagehelper.PageHelper; import com.github.yulichang.toolkit.JoinWrappers; import com.github.yulichang.wrapper.MPJLambdaWrapper; import com.kym.common.utils.CommUtil; import com.kym.entity.common.PageBean; import com.kym.entity.miniapp.OrderRechargeRights; import com.kym.entity.miniapp.UserRechargeRights; import com.kym.entity.miniapp.WashDevice; import com.kym.entity.miniapp.WashStation; import com.kym.entity.miniapp.queryParams.DeviceQueryParams; import com.kym.entity.miniapp.vo.UserOrderRechargeRightsVo; import com.kym.entity.miniapp.vo.WashDeviceVo; import com.kym.mapper.miniapp.WashDeviceMapper; import com.kym.service.cache.KymCache; import com.kym.service.miniapp.WashDeviceService; import com.kym.service.miniapp.WashOrderService; import com.kym.service.mybatisplus.MyBaseServiceImpl; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.List; /** *

* 洗车设备表 服务实现类 *

* * @author skyline * @since 2024-10-09 */ @Service public class WashDeviceServiceImpl extends MyBaseServiceImpl implements WashDeviceService { private WashOrderService washOrderService; public WashDeviceServiceImpl(WashOrderService washOrderService) { this.washOrderService = washOrderService; } //region 小程序 /** * 获取设备列表 * * @param params * @return */ @Override public List 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(); for (WashDevice washDevice : list) { var vo = new WashDeviceVo(); BeanUtils.copyProperties(washDevice, vo); vo.setShortId(KymCache.INSTANCE.getShortIdByProductKeyAndDeviceName(washDevice.getProductKey(), washDevice.getDeviceName())); 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(); var vo = new WashDeviceVo(); 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 list = lambdaQuery() .eq(WashDevice::getStationId, device.getStationId()) .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 Object list(DeviceQueryParams query) { PageHelper.startPage(query.getPageNum(), query.getPageSize()); List list = lambdaQuery() .like(CommUtil.isNotEmptyAndNull(query.getDeviceName()), WashDevice::getDeviceName, query.getDeviceName()) .eq(CommUtil.isNotEmptyAndNull(query.getStationId()), WashDevice::getStationId, query.getStationId()) .list(); return new PageBean<>(list); } //endregion }