#
luxiaotao1123
2024-10-23 7a68bbe9a032df8c54b2263be097002e01383bce
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package com.zy.acs.manager.core.service;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zy.acs.framework.common.Cools;
import com.zy.acs.manager.common.utils.LocUtils;
import com.zy.acs.manager.manager.entity.Agv;
import com.zy.acs.manager.manager.entity.AgvModel;
import com.zy.acs.manager.manager.entity.Task;
import com.zy.acs.manager.manager.enums.TaskStsType;
import com.zy.acs.manager.manager.service.AgvModelService;
import com.zy.acs.manager.manager.service.AgvService;
import com.zy.acs.manager.manager.service.TaskService;
import com.zy.acs.manager.system.service.ConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.Collections;
import java.util.List;
import java.util.Map;
 
/**
 * Created by vincent on 8/12/2024
 */
@Slf4j
@Service
public class MissionAssignService {
 
    @Autowired
    private AgvService agvService;
    @Autowired
    private AgvModelService agvModelService;
    @Autowired
    private ConfigService configService;
    @Autowired
    private TaskService taskService;
 
    public synchronized Agv execute(Task task, Map<String, List<Long>> taskAllot, List<Long> taskIds) {
        String oriLocNo = task.getOriLoc$();
        int oriLocRow = LocUtils.getRow(oriLocNo);
        String destLocNo = task.getDestLoc$();
        int destLocRow = LocUtils.getRow(destLocNo);
 
        Agv hit = null;
 
        List<Agv> agvList = agvService.list(new LambdaQueryWrapper<Agv>().eq(Agv::getStatus, 1));
        Collections.shuffle(agvList);
        for (Agv agv : agvList) {
            AgvModel agvModel = agvModelService.getById(agv.getAgvModel());
            int allotTaskCount = 0;
            List<Long> allotTaskIds = taskAllot.get(agv.getUuid());
            if (!Cools.isEmpty(allotTaskIds)) {
                allotTaskCount = allotTaskIds.size();
            }
            if (allotTaskCount >= agvModel.getBackpack()) {
                continue;
            }
            if (taskService.count(new LambdaQueryWrapper<Task>()
                    .eq(Task::getAgvId, agv.getId())
                    .notIn(Task::getId, taskIds)
                    .and(i -> {
                        i.eq(Task::getTaskSts, TaskStsType.WAITING.val())   // 已经有waiting任务的车不能再分配
                                .or().eq(Task::getTaskSts, TaskStsType.ASSIGN.val())
                                .or().eq(Task::getTaskSts, TaskStsType.PROGRESS.val());
                    })) > 0) {
                log.info(agv.getUuid() + "号AGV不可用,已经存在进行中的任务...");
                continue;
            }
            final Agv finalAgv = agv;
            if (!agvService.judgeEnable(finalAgv.getId(), agvDetail -> agvDetail.getVol() > finalAgv.getChargeLine())) {
                log.info(finalAgv.getUuid() + "号AGV不可用," + task.getSeqNum() + "任务无法计算...");
                continue;
            }
 
            hit = agv;
            break;
        }
 
        return hit;
    }
 
    public synchronized Agv execute1(Task task, Map<String, List<Long>> taskAllot, List<Long> taskIds) {
        String oriLocNo = task.getOriLoc$();
        int oriLocRow = LocUtils.getRow(oriLocNo);
        String destLocNo = task.getDestLoc$();
        int destLocRow = LocUtils.getRow(destLocNo);
 
        Agv agv = null;
        if (oriLocRow <= 2 && destLocRow <= 2) {
            agv = agvService.selectByUuid(String.valueOf(1));
        }
        if (oriLocRow > 2 && destLocRow > 2) {
            agv = agvService.selectByUuid(String.valueOf(2));
        }
        assert agv != null;
        AgvModel agvModel = agvModelService.getById(agv.getAgvModel());
        int allotTaskCount = 0;
        List<Long> allotTaskIds = taskAllot.get(agv.getUuid());
        if (!Cools.isEmpty(allotTaskIds)) {
            allotTaskCount = allotTaskIds.size();
        }
        if (allotTaskCount >= agvModel.getBackpack()) {
            return null;
        }
        if (taskService.count(new LambdaQueryWrapper<Task>()
                .eq(Task::getAgvId, agv.getId())
                .notIn(Task::getId, taskIds)
                .and(i -> {
                    i.eq(Task::getTaskSts, TaskStsType.WAITING.val())   // 已经有waiting任务的车不能再分配
                            .or().eq(Task::getTaskSts, TaskStsType.ASSIGN.val())
                            .or().eq(Task::getTaskSts, TaskStsType.PROGRESS.val());
                })) > 0) {
            log.info(agv.getUuid() + "号AGV不可用,已经存在进行中的任务...");
            return null;
        }
        final Agv finalAgv = agv;
        if (!agvService.judgeEnable(finalAgv.getId(), agvDetail -> agvDetail.getVol() > finalAgv.getChargeLine())) {
            log.info(finalAgv.getUuid() + "号AGV不可用," + task.getSeqNum() + "任务无法计算...");
            return null;
        }
 
        return agv;
    }
 
}