| | |
| | | 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", 1); |
| | | 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 updateTaskStateToZero(long id) { |
| | | public void updateTaskState(String id) { |
| | | UpdateWrapper<DownGlassTask> updateWrapper = new UpdateWrapper<>(); |
| | | updateWrapper.set("task_stauts", 0).eq("id", id); |
| | | baseMapper.update(null, updateWrapper); |
| | | updateWrapper.set("task_status", 2).eq("id", id); |
| | | baseMapper.update(new DownGlassTask(), updateWrapper); |
| | | } |
| | | |
| | | @Override |
| | | public void deleteTask(long id) { |
| | | public void deleteTask(String id) { |
| | | LambdaQueryWrapper<DownGlassTask> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(DownGlassTask::getId, id); |
| | | queryWrapper.eq(DownGlassTask::getGlassId, id); |
| | | |
| | | baseMapper.delete(queryWrapper); |
| | | } |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Integer insertCacheTask(Long id, String start, String end, String type, double width, double height, String filmsId, double thickness, String flowCardId) { |
| | | DownGlassTask glassInfo = new DownGlassTask(); |
| | | glassInfo.setId(id); |
| | | glassInfo.setStartCell(start); |
| | | glassInfo.setEndCell(end); |
| | | glassInfo.setTaskType(type); |
| | | glassInfo.setWidth(width); |
| | | glassInfo.setHeight(height); |
| | | glassInfo.setFilmsid(filmsId); |
| | | glassInfo.setThickness(thickness); |
| | | glassInfo.setFlowCardId(flowCardId); |
| | | glassInfo.setTaskStauts(0); // 默认任务状态为0 |
| | | public Integer insertCacheTask(DownGlassTask downGlassTask) { |
| | | // 查询数据库,检查主键值是否已经存在 |
| | | DownGlassTask existingTask = baseMapper.selectById(downGlassTask.getId()); |
| | | if (existingTask != null) { |
| | | // 如果已存在相同主键值的任务,则不进行插入操作,返回 null 或者抛出异常 |
| | | // 这里简单起见,直接返回 null |
| | | return null; |
| | | } |
| | | |
| | | int rows = baseMapper.insert(glassInfo); |
| | | // 如果主键值不存在,则进行插入操作 |
| | | DownGlassTask newDownGlassTask = new DownGlassTask(); |
| | | BeanUtils.copyProperties(downGlassTask, newDownGlassTask); |
| | | newDownGlassTask.setTaskStatus(1); // 默认任务状态为1 |
| | | newDownGlassTask.setCreateTime(new Date()); |
| | | int rows = baseMapper.insert(newDownGlassTask); |
| | | return rows > 0 ? rows : null; |
| | | } |
| | | |
| | | |
| | | |
| | | @Override |
| | | public List<DownGlassTask> selectInputTaskCache() { |
| | | return baseMapper.selectList(new QueryWrapper<DownGlassTask>().eq("task_status", 0).eq("task_type", 1)); |
| | | } |
| | | |
| | | /** |
| | | * 查询待出片任务 |
| | | * |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<DownGlassTask> selectOutTaskCache() { |
| | | return baseMapper.selectList(new QueryWrapper<DownGlassTask>().eq("task_status", 0).eq("task_type", 2)); |
| | | } |
| | | |
| | | |
| | | } |