zhoushihao
2024-05-25 8db5b45c853fe5e49f2bca9047ea63e739cb8d79
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
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.DownGlassTask;
import com.mes.downglassinfo.mapper.DownGlassTaskMapper;
import com.mes.downglassinfo.service.DownGlassTaskService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
 
import java.util.Date;
import java.util.List;
 
/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author zhoush
 * @since 2024-04-07
 */
@Service
public class DownGlassTaskServiceImpl extends ServiceImpl<DownGlassTaskMapper, DownGlassTask> implements DownGlassTaskService {
 
 
    @Override
    public List<DownGlassTask> getUnloadingTaskState() {
        QueryWrapper<DownGlassTask> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("task_stauts", 0).eq("task_type", 2).or().eq("task_stauts", 3);
        return baseMapper.selectList(queryWrapper);
    }
 
    @Override
    public void updateTaskState(String id) {
        UpdateWrapper<DownGlassTask> updateWrapper = new UpdateWrapper<>();
        updateWrapper.set("task_stauts", 2).eq("id", id);
        baseMapper.update(new DownGlassTask(), updateWrapper);
    }
 
    @Override
    public void deleteTask(String id) {
        LambdaQueryWrapper<DownGlassTask> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(DownGlassTask::getGlassId, id);
 
        baseMapper.delete(queryWrapper);
    }
 
    @Override
    public DownGlassTask selectLastOutCacheInfo(String endCell) {
        QueryWrapper<DownGlassTask> 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<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));
    }
 
 
}