| | |
| | | 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.DownGlassTaskMapper; |
| | | import com.mes.downglassinfo.service.DownGlassInfoService; |
| | | import com.mes.downglassinfo.service.DownGlassTaskService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | * @author zhoush |
| | | * @since 2024-04-07 |
| | | */ |
| | | @Slf4j |
| | | @Service |
| | | public class DownGlassTaskServiceImpl extends ServiceImpl<DownGlassTaskMapper, DownGlassTask> implements DownGlassTaskService { |
| | | |
| | | @Autowired |
| | | private DownGlassInfoService downGlassInfoService; // MySQL Mapper |
| | | |
| | | @Resource |
| | | private DownGlassTaskMapper downGlassTaskMapper; // SQL Server Mapper |
| | | |
| | | @Override |
| | | public List<DownGlassTask> getUnloadingTaskState() { |
| | | log.info("排除已经下片的出片或直通任务状态为1的任务"); |
| | | |
| | | // Step 1: 从 MySQL 中获取玻璃 ID 列表 |
| | | |
| | | // Step 2: 从 SQL Server 中过滤掉这些玻璃 ID 并查询任务 |
| | | QueryWrapper<DownGlassTask> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("task_stauts", 0).eq("task_type", 2).or().eq("task_stauts", 3); |
| | | queryWrapper.eq("task_status", 1) |
| | | .and(qw -> qw.eq("task_type", 2).or().eq("task_type", 3)); |
| | | |
| | | List<DownGlassInfo> 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<DownGlassTask> updateWrapper = new UpdateWrapper<>(); |
| | | updateWrapper.set("task_stauts", 2).eq("id", id); |
| | | updateWrapper.set("task_status", 2).eq("id", id); |
| | | baseMapper.update(new DownGlassTask(), updateWrapper); |
| | | } |
| | | |
| | |
| | | // 如果主键值不存在,则进行插入操作 |
| | | DownGlassTask newDownGlassTask = new DownGlassTask(); |
| | | BeanUtils.copyProperties(downGlassTask, newDownGlassTask); |
| | | newDownGlassTask.setTaskStauts(1); // 默认任务状态为1 |
| | | newDownGlassTask.setTaskStatus(1); // 默认任务状态为1 |
| | | newDownGlassTask.setCreateTime(new Date()); |
| | | int rows = baseMapper.insert(newDownGlassTask); |
| | | return rows > 0 ? rows : null; |