package com.mes.downglassinfo.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.mes.downglassinfo.entity.DownGlassInfo; import com.mes.downglassinfo.entity.DownGlassTask; import com.mes.downglassinfo.mapper.DownGlassInfoMapper; import com.mes.downglassinfo.mapper.DownGlassTaskMapper; import com.mes.downglassinfo.service.DownGlassInfoService; import com.mes.downglassinfo.service.DownGlassTaskService; import com.mes.downworkstation.entity.DownWorkstation; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.Date; import java.util.List; import java.util.stream.Collectors; /** *

* 服务实现类 *

* * @author zhoush * @since 2024-04-07 */ @Slf4j @Service public class DownGlassTaskServiceImpl extends ServiceImpl implements DownGlassTaskService { @Autowired private DownGlassInfoService downGlassInfoService; // MySQL Mapper @Autowired private DownGlassTaskMapper downGlassTaskMapper; // SQL Server Mapper @Override public List getUnloadingTaskState() { log.info("排除已经下片的出片或直通任务状态为1的任务"); // Step 1: 从 MySQL 中获取玻璃 ID 列表 // Step 2: 从 SQL Server 中过滤掉这些玻璃 ID 并查询任务 QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("task_stauts", 1) .and(qw -> qw.eq("task_type", 2).or().eq("task_type", 3)); List excludedGlassIds = downGlassInfoService.list(); if (!excludedGlassIds.isEmpty()) { queryWrapper.notIn("glass_id", excludedGlassIds.stream().map(DownGlassInfo::getGlassId).collect(Collectors.toList())); } log.info(String.valueOf(excludedGlassIds)); return baseMapper.selectList(queryWrapper); } @Override public void updateTaskState(String id) { UpdateWrapper updateWrapper = new UpdateWrapper<>(); updateWrapper.set("task_stauts", 2).eq("id", id); baseMapper.update(new DownGlassTask(), updateWrapper); } @Override public void deleteTask(String id) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(DownGlassTask::getGlassId, id); baseMapper.delete(queryWrapper); } @Override public DownGlassTask selectLastOutCacheInfo(String endCell) { QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("task_type", "2") .eq("task_status", "2") .eq("end_cell", endCell) .last("LIMIT 1"); return baseMapper.selectOne(queryWrapper); } @Override public Integer insertCacheTask(DownGlassTask downGlassTask) { // 查询数据库,检查主键值是否已经存在 DownGlassTask existingTask = baseMapper.selectById(downGlassTask.getId()); if (existingTask != null) { // 如果已存在相同主键值的任务,则不进行插入操作,返回 null 或者抛出异常 // 这里简单起见,直接返回 null return null; } // 如果主键值不存在,则进行插入操作 DownGlassTask newDownGlassTask = new DownGlassTask(); BeanUtils.copyProperties(downGlassTask, newDownGlassTask); newDownGlassTask.setTaskStauts(1); // 默认任务状态为1 newDownGlassTask.setCreateTime(new Date()); int rows = baseMapper.insert(newDownGlassTask); return rows > 0 ? rows : null; } @Override public List selectInputTaskCache() { return baseMapper.selectList(new QueryWrapper().eq("task_status", 0).eq("task_type", 1)); } /** * 查询待出片任务 * * @return */ @Override public List selectOutTaskCache() { return baseMapper.selectList(new QueryWrapper().eq("task_status", 0).eq("task_type", 2)); } }