pang.jiabao
2025-05-15 2c0e3414d8032b5cd5e673dd587afc7d1a9bab7c
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package com.zy.asrs.service.impl;
 
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.common.Cools;
import com.core.common.R;
import com.zy.asrs.domain.enums.TaskStatusType;
import com.zy.asrs.domain.enums.WorkNoType;
import com.zy.asrs.domain.param.ApplyInDevpDto;
import com.zy.asrs.entity.BasDevp;
import com.zy.asrs.entity.LocMast;
import com.zy.asrs.entity.TaskWrk;
import com.zy.asrs.entity.param.TaskCreateParam;
import com.zy.asrs.service.*;
import com.zy.asrs.utils.Utils;
import com.zy.common.service.CommonService;
import com.zy.core.DevpThread;
import com.zy.core.cache.MessageQueue;
import com.zy.core.cache.SlaveConnection;
import com.zy.core.enums.SlaveType;
import com.zy.core.model.Task;
import com.zy.core.model.protocol.StaProtocol;
import com.zy.core.properties.SlaveProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
 
import java.util.Date;
import java.util.HashMap;
 
@Service
public class OpenServiceImpl implements OpenService {
 
    @Autowired
    private TaskWrkService taskWrkService;
    @Autowired
    private SlaveProperties slaveProperties;
    @Autowired
    private ApiLogService apiLogService;
    @Autowired
    private StaDescService staDescService;
    @Autowired
    private CommonService commonService;
    @Autowired
    private LocMastService locMastService;
    @Autowired
    private BasDevpService basDevpService;
    @Value("${wms.url}")
    private String wmsUrl;
 
    @Override
    public HashMap<String, Object> taskCreate(TaskCreateParam param) {
        HashMap<String, Object> map = new HashMap<>();
        TaskWrk taskWrk = taskWrkService.selectByTaskNo(param.getTaskNo());
        if (taskWrk != null) {
            map.put("Code", "0");
            map.put("Msg", param.getTaskNo() + "任务已经生成!");
            return map;
        }
 
        Date now = new Date();
        taskWrk = new TaskWrk();
        LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no", param.getStartPoint()));
        if (locMast == null) {
            map.put("Code", "0");
            map.put("Msg", param.getStartPoint() + "库位号有误");
            return map;
        }
        int workNoType = WorkNoType.PAKOUT.type;
        // 出库到2,3号堆垛机,需要通过任务号区分大小托盘,任务号3001-6000为小托盘,即8~12列
        if (param.getIoType() == 2 && (locMast.getCrnNo() == 3 || locMast.getCrnNo() == 2) && locMast.getBay1() > 7){
            workNoType = WorkNoType.PICK.type;
        }
        int workNo1 = commonService.getWorkNo(workNoType);//获取入库工作号
        taskWrk.setTaskNo(param.getTaskNo());//任务号
        taskWrk.setWrkNo(workNo1);
        taskWrk.setStatus(TaskStatusType.RECEIVE.id);//任务状态:接收
        taskWrk.setCreateTime(now);
        taskWrk.setAssignTime(now);
        taskWrk.setIoType(param.getIoType());//任务类型
        taskWrk.setIoPri(param.getTaskPriority());//优先级
        taskWrk.setBarcode(param.getBarcode());//条码
        taskWrk.setCrnNo(locMast.getCrnNo());
        if (param.getIoType() == 1) {
            taskWrk.setWrkSts(1);
            if (!Cools.isEmpty(param.getTargetPoint())) {
                taskWrk.setTargetPoint(Utils.getWcsLocNo(param.getTargetPoint()));//终点
                taskWrk.setOriginTargetPoint(param.getTargetPoint());
            }
 
        } else if (param.getIoType() == 2) {
            taskWrk.setWrkSts(11);
//            if (!Cools.isEmpty(param.getStartPoint())) {
                taskWrk.setStartPoint(param.getStartPoint());//起点
                taskWrk.setTargetPoint(String.valueOf(Integer.parseInt(param.getTargetPoint())-1));
//            }
//            taskWrk.setTargetPoint(param.getTargetPoint());
        } else if (param.getIoType() == 3) {
            taskWrk.setWrkSts(11);
            if (!Cools.isEmpty(param.getStartPoint())) {
                taskWrk.setStartPoint(param.getStartPoint());//起点
                taskWrk.setTargetPoint(param.getTargetPoint());
            }
        }
 
 
        if (!Cools.isEmpty(param.getMemo())) {
            taskWrk.setMemo(param.getMemo());//备注
        }
 
        if (!taskWrkService.insert(taskWrk)) {
            map.put("Code", "0");
            map.put("Msg", param.getTaskNo() + "创建任务失败!");
            return map;
        }
        map.put("Code", "1");
        map.put("Msg", "ok");
        return map;
    }
 
    @Override
    public R applyInDevp(ApplyInDevpDto param) {
        Integer sourceSite = param.getSourceSite();
        BasDevp basDevp = basDevpService.selectById(sourceSite);
        if (basDevp == null) {
            return R.error("源站点不存在:" + param);
        }
        DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, 2);
        StaProtocol staProtocol = devpThread.getStation().get(sourceSite);
        if (staProtocol == null) {
            return R.parse(sourceSite + "线程为空!");
        } else {
            staProtocol = staProtocol.clone();
        }
        staProtocol.setWorkNo((short) commonService.getWorkNo(WorkNoType.PICK.type));
        staProtocol.setStaNo(param.getTargetSite().shortValue());
        basDevpService.updateById(basDevp);
        boolean result = MessageQueue.offer(SlaveType.Devp, 2, new Task(2, staProtocol));
        if (result) {
            return R.ok("成功");
        } else {
            return R.error("下发命令失败:" + param);
        }
    }
}