package com.warewms.hailiang.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.warewms.common.core.domain.base.page.PageDomain; import com.warewms.common.core.domain.base.page.TableDataInfo; import com.warewms.common.utils.StringUtils; import com.warewms.hailiang.config.DeviceMessageSocket; import com.warewms.hailiang.domain.DeviceLog; import com.warewms.hailiang.mapper.DeviceLogMapper; import com.warewms.hailiang.service.DeviceLogService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.event.EventListener; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import java.util.List; import java.util.Map; /** * @author AD * @description 针对表【device_log(设备日志表)】的数据库操作Service实现 * @createDate 2023-08-21 13:24:57 */ @Service public class DeviceLogServiceImpl extends ServiceImpl implements DeviceLogService { @Autowired DeviceLogMapper deviceLogMapper; @Autowired DeviceMessageSocket deviceMessageSocket; @Override public TableDataInfo getList(DeviceLog deviceLog, PageDomain pageDomain) { Map params = deviceLog.getParams(); IPage deviceLogIPage = deviceLogMapper.selectPage(pageDomain.build(), new LambdaQueryWrapper() .eq(StringUtils.isNotEmpty(deviceLog.getDeviceId()), DeviceLog::getDeviceId, deviceLog.getDeviceId()) .eq(StringUtils.isNotEmpty(deviceLog.getDeviceName()), DeviceLog::getDeviceName, deviceLog.getDeviceName()) .eq(StringUtils.isNotEmpty(deviceLog.getStatus()), DeviceLog::getStatus, deviceLog.getStatus()) .between(params.get("beginTime") != null && params.get("endTime") != null, DeviceLog::getCreateTime, params.get("beginTime"), params.get("endTime")) .orderByDesc(DeviceLog::getCreateTime)); return TableDataInfo.build(deviceLogIPage); } @Override @Async @EventListener public void createLog(DeviceLog deviceLog) { deviceLog.setCreateBy("system"); deviceLog.setUpdateBy("system"); deviceLogMapper.insert(deviceLog); //推送消息 deviceMessageSocket.sendAllMessage(deviceLog.toString()); } }