| | |
| | | package com.mes.device.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.mes.device.entity.GlassInfo; |
| | | import com.mes.device.mapper.DeviceGlassInfoMapper; |
| | | import com.mes.device.service.GlassInfoService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.util.Collections; |
| | | import java.util.Date; |
| | |
| | | GlassInfo existing = baseMapper.selectByGlassId(glassInfo.getGlassId()); |
| | | if (existing != null) { |
| | | glassInfo.setId(existing.getId()); |
| | | // 保留原始创建信息 |
| | | if (glassInfo.getCreatedTime() == null) { |
| | | glassInfo.setCreatedTime(existing.getCreatedTime()); |
| | | } |
| | | if (glassInfo.getCreatedBy() == null) { |
| | | glassInfo.setCreatedBy(existing.getCreatedBy()); |
| | | } |
| | | // 更新为当前时间 |
| | | if (glassInfo.getUpdatedTime() == null) { |
| | | glassInfo.setUpdatedTime(new Date()); |
| | | } |
| | | if (glassInfo.getUpdatedBy() == null) { |
| | | glassInfo.setUpdatedBy("system"); |
| | | } |
| | | return updateById(glassInfo); |
| | | } else { |
| | | Date now = new Date(); |
| | | if (glassInfo.getCreatedTime() == null) { |
| | | glassInfo.setCreatedTime(now); |
| | | } |
| | | if (glassInfo.getUpdatedTime() == null) { |
| | | glassInfo.setUpdatedTime(now); |
| | | } |
| | | if (glassInfo.getCreatedBy() == null) { |
| | | glassInfo.setCreatedBy("system"); |
| | | } |
| | | if (glassInfo.getUpdatedBy() == null) { |
| | | glassInfo.setUpdatedBy("system"); |
| | | } |
| | | return save(glassInfo); |
| | | } |
| | | } catch (Exception e) { |
| | |
| | | Date timeThreshold = new Date(System.currentTimeMillis() - minutes * 60 * 1000L); |
| | | |
| | | LambdaQueryWrapper<GlassInfo> wrapper = new LambdaQueryWrapper<>(); |
| | | wrapper.eq(GlassInfo::getStatus, GlassInfo.Status.ACTIVE) |
| | | wrapper.eq(GlassInfo::getStatus, GlassInfo.Status.PENDING) |
| | | .ge(GlassInfo::getCreatedTime, timeThreshold) |
| | | .orderByDesc(GlassInfo::getCreatedTime) |
| | | .last("LIMIT " + limit); |
| | |
| | | return Collections.emptyList(); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public boolean updateGlassStatus(List<String> glassIds, String status) { |
| | | if (CollectionUtils.isEmpty(glassIds) || status == null) { |
| | | return true; |
| | | } |
| | | try { |
| | | LambdaUpdateWrapper<GlassInfo> wrapper = new LambdaUpdateWrapper<>(); |
| | | wrapper.in(GlassInfo::getGlassId, glassIds); |
| | | GlassInfo update = new GlassInfo(); |
| | | update.setStatus(status); |
| | | update.setUpdatedTime(new Date()); |
| | | update.setUpdatedBy("system"); |
| | | return this.update(update, wrapper); |
| | | } catch (Exception e) { |
| | | log.error("批量更新玻璃状态失败, glassIds={}, status={}", glassIds, status, e); |
| | | return false; |
| | | } |
| | | } |
| | | } |
| | | |