#
vincentlu
2025-12-18 2de9e897274f93ef5e90eaa068ab8645dea2de39
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
package com.zy.acs.manager.core.service;
 
import com.zy.acs.framework.common.Cools;
import com.zy.acs.manager.manager.entity.Loc;
import com.zy.acs.manager.manager.entity.Sta;
import com.zy.acs.manager.manager.entity.Task;
import com.zy.acs.manager.manager.service.AreaAgvService;
import com.zy.acs.manager.manager.service.LocService;
import com.zy.acs.manager.manager.service.StaService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import javax.annotation.PostConstruct;
import java.util.Collections;
import java.util.List;
 
@Slf4j
@Service
public class AgvAreaDispatcher {
 
    @Autowired
    private LocService locService;
    @Autowired
    private StaService staService;
    @Autowired
    private AreaGovernService areaGovernService;
    @Autowired
    private AreaAgvService areaAgvService;
 
    @PostConstruct
    public void init() {
    }
 
    public List<Long> getAgvNosByTask(Task task) {
        if (null == task) {
            return null;
        }
        Loc oriLoc = null;
        Sta oriSta = null;
        Loc destLoc = null;
        Sta destSta = null;
        if (null != task.getOriLoc()) {
            oriLoc = locService.getById(task.getOriLoc());
            return this.getAgvIdsByCode(oriLoc.getCode$());
        }
        if (null != task.getOriSta()) {
            oriSta = staService.getById(task.getOriSta());
            return this.getAgvIdsByCode(oriSta.getCode$());
        }
        if (null != task.getDestLoc()) {
            destLoc = locService.getById(task.getDestLoc());
            return this.getAgvIdsByCode(destLoc.getCode$());
        }
        if (null != task.getDestSta()) {
            destSta = staService.getById(task.getDestSta());
            return this.getAgvIdsByCode(destSta.getCode$());
        }
        return null;
    }
 
    public List<Long> getAgvIdsByCode(String code) {
        if (Cools.isEmpty(code)) {
            return Collections.emptyList();
        }
        List<Long> areaIds = areaGovernService.queryAreas(code);
        List<Long> agvIds = areaAgvService.queryAgvIdsByAreaIds(areaIds);
        agvIds.addAll(areaAgvService.findAgvIdsWithoutAreaAgv());
        return agvIds;
    }
 
    public List<String> getAgvNosByStaNo(String staNo) {
        return null;
    }
 
    // 如果都没有命中,就返回全部code
    public List<String> getCodesByAgvId(Long agvId) {
        List<Long> areaIds = areaAgvService.queryAreaIdsByAgvId(agvId);
        return areaGovernService.queryCodes(areaIds);
    }
 
    public Boolean isAgvExistsInAnyArea(Long agvId) {
        List<Long> agvIdsWithoutAreaAgv = areaAgvService.findAgvIdsWithoutAreaAgv();
        return !Cools.isEmpty(agvIdsWithoutAreaAgv) && agvIdsWithoutAreaAgv.contains(agvId);
    }
 
}