#
luxiaotao1123
2024-09-29 2ab3366ad79370c1fbe7b665e6a50148463ab640
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
package com.zy.acs.manager.manager.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zy.acs.framework.common.Cools;
import com.zy.acs.manager.manager.controller.result.MissionVo;
import com.zy.acs.manager.manager.entity.Action;
import com.zy.acs.manager.manager.entity.AgvDetail;
import com.zy.acs.manager.manager.entity.Code;
import com.zy.acs.manager.manager.entity.Segment;
import com.zy.acs.manager.manager.enums.SegmentStateType;
import com.zy.acs.manager.manager.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
 
/**
 * Created by vincent on 9/27/2024
 */
@Service("missionService")
public class MissionServiceImpl implements MissionService {
 
    @Autowired
    private SegmentService segmentService;
    @Autowired
    private ActionService actionService;
    @Autowired
    private CodeService codeService;
    @Autowired
    private AgvDetailService agvDetailService;
 
    @Override
    public List<MissionVo> getList(Long agvId, String groupNo) {
        List<MissionVo> result = new ArrayList<>();
        List<String> runningGroupNos = segmentService.getGroupNo(SegmentStateType.RUNNING, agvId, groupNo);
        for (String runningGroupNo : runningGroupNos) {
            MissionVo vo = generateVo(runningGroupNo);
            if (null != vo) {
                result.add(vo);
            }
        }
 
        return result;
    }
 
    @Override
    public MissionVo generateVo(String groupNo) {
        if (Cools.isEmpty(groupNo)) {
            return null;
        }
        List<Segment> list = segmentService.list(new LambdaQueryWrapper<Segment>().eq(Segment::getGroupId, groupNo).orderByAsc(Segment::getSerial));
        if (Cools.isEmpty(list)) {
            return null;
        }
        Segment segment = list.get(0);
 
        MissionVo vo = new MissionVo();
        vo.setGroupNo(groupNo);
        vo.setId(segment.getId());
        vo.setPosType(segment.getPosType());
        vo.setAgv(segment.getAgvId$());
        vo.setTaskNos(list.stream().map(Segment::getTaskId$).collect(Collectors.toList()));
        vo.setBackpack(segment.getBackpack());
        vo.setDestCode(segment.getEndNode$());
        vo.setProgress(calcProgress(groupNo));
        return vo;
    }
 
    public Double calcProgress(String groupNo) {
        double progress = 0D;
        List<Action> actionList = actionService.list(new LambdaQueryWrapper<Action>()
                .eq(Action::getGroupId, groupNo).
                        orderByDesc(Action::getPriority));
 
        if (Cools.isEmpty(actionList)) {
            return progress;
        }
 
        Action action = actionList.get(0);
        AgvDetail agvDetail = agvDetailService.selectByAgvId(action.getAgvId());
        Long recentCode = agvDetail.getRecentCode();
        if (null == recentCode) {
            return progress;
        }
        Code code = codeService.getById(recentCode);
 
        List<String> codeList = actionList.stream().map(Action::getCode).collect(Collectors.toList());
 
        int totalCodes = codeList.size();
        int currentIndex = codeList.indexOf(code.getData());
 
        if (currentIndex >= 0) {
            progress = (currentIndex + 1) * 100.0 / totalCodes;
        }
 
        return progress;
    }
 
}