Blame view

src/main/java/com/huaheng/api/acs/service/AcsServiceImpl.java 19.1 KB
pengcheng authored
1
2
package com.huaheng.api.acs.service;
周鸿 authored
3
import com.alibaba.fastjson.JSON;
4
5
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.huaheng.common.constant.QuantityConstant;
周鸿 authored
6
7
8
9
10
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.support.Convert;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.http.HttpUtils;
import com.huaheng.common.utils.security.ShiroUtils;
pengcheng authored
11
import com.huaheng.framework.web.domain.AjaxResult;
周鸿 authored
12
13
import com.huaheng.pc.config.address.domain.Address;
import com.huaheng.pc.config.address.service.AddressService;
周鸿 authored
14
15
import com.huaheng.pc.config.container.domain.Container;
import com.huaheng.pc.config.container.service.ContainerService;
周鸿 authored
16
import com.huaheng.pc.config.location.domain.LocationPosition;
周鸿 authored
17
18
19
20
import com.huaheng.pc.config.points.domain.Points;
import com.huaheng.pc.config.points.service.PointsService;
import com.huaheng.pc.config.pointsRecord.domain.PointsRecord;
import com.huaheng.pc.config.pointsRecord.service.PointsRecordService;
21
22
import com.huaheng.pc.monitor.agvcarinfo.domain.StateInfoUploadModel;
import com.huaheng.pc.monitor.agvcarinfo.service.AgvStateInfoService;
周鸿 authored
23
24
25
26
27
import com.huaheng.pc.system.user.domain.User;
import com.huaheng.pc.system.user.service.IUserService;
import com.huaheng.pc.system.user.service.UserServiceImpl;
import com.huaheng.pc.task.agvTask.domain.AgvTask;
import com.huaheng.pc.task.agvTask.service.IAgvTaskService;
周鸿 authored
28
29
import com.huaheng.pc.task.taskDetail.domain.TaskDetail;
import com.huaheng.pc.task.taskDetail.service.TaskDetailService;
周鸿 authored
30
31
32
import com.huaheng.pc.task.taskHeader.domain.TaskHeader;
import com.huaheng.pc.task.taskHeader.service.TaskHeaderAgvService;
import com.huaheng.pc.task.taskHeader.service.TaskHeaderService;
周鸿 authored
33
import io.swagger.models.auth.In;
周鸿 authored
34
35
36
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
pengcheng authored
37
import org.springframework.stereotype.Service;
周鸿 authored
38
39
40
41
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.HashMap;
42
import java.util.List;
周鸿 authored
43
import java.util.Map;
周鸿 authored
44
import java.util.stream.Collectors;
pengcheng authored
45
46
47
48
49
50
51
52
53

/**
 * @ClassName AcsServiceImpl
 * @Description TODO
 * @Author Administrator
 * @Date 2019/12/2615:38
 */
@Service
public class AcsServiceImpl implements AcsService {
周鸿 authored
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
    private static final Logger logger = LoggerFactory.getLogger(AcsServiceImpl.class);
    @Autowired
    private AddressService addressService;
    @Autowired
    private PointsService pointsService;
    @Autowired
    private IUserService userService;
    @Autowired
    private TaskHeaderService taskHeaderService;
    @Autowired
    private PointsRecordService pointsRecordService;
    @Autowired
    private IAgvTaskService agvTaskService;
    @Autowired
    private TaskHeaderAgvService taskHeaderAgvService;
周鸿 authored
69
70
    @Autowired
    private TaskDetailService taskDetailService;
周鸿 authored
71
72
    @Autowired
    private ContainerService containerService;
73
74
    @Autowired
    private AgvStateInfoService agvStateInfoService;
周鸿 authored
75
76
77

    final String interactionId = "6EAB7794-CFD7-449A-A754-FFDB98CE44C7";
pengcheng authored
78
79
    @Override
    public AjaxResult StateInfoUpload(StateInfoUploadModel model) {
80
        try {
周鸿 authored
81
82
83
            if(StringUtils.isEmpty(model.getWarehouseCode())){
                return AjaxResult.error("请填写warehouseCode字段");
            }
周鸿 authored
84
85
            String json = JSON.toJSONString(model);
            logger.info("信息上传改变货架状态1:{}",json);
86
87
88
            if(model.getState().equals("2")) {
                Points points = new Points();
                points.setGoodsShelfNo(model.getShelfNo());
周鸿 authored
89
                points.setWarehouseCode(model.getWarehouseCode());
周鸿 authored
90
//                points.setIsLocked(1);
91
92
                points=pointsService.selectEntity(points);
                if(points!=null) {
周鸿 authored
93
94
95
96
97
98
99
100
101
102
103
104
105
106
                    logger.info("信息上传改变货架状态2:{}",json);
                    points.setIsLocked(2);
                    boolean result = pointsService.updateById(points);
                    if (!result) {
                        throw new ServiceException("小车回传状态时修改货架状态失败");
                    }
                    agvStateInfoService.insertModel(model);
                }
            }
        }catch (Exception e){
            return AjaxResult.error("没有数据");
        }
        return AjaxResult.success("收到");
pengcheng authored
107
108
109
    }

    @Override
110
    public AjaxResult TaskConfirm(AgvTask model) {
周鸿 authored
111
112
113
114
//        model.setWarehouseCode(ShiroUtils.getWarehouseCode());
        if(StringUtils.isEmpty(model.getWarehouseCode())){
            return AjaxResult.error("没有填写warehouseCode");
        }
115
116
117
118
        boolean result=agvTaskService.save(model);
        if(!result){
            throw new ServiceException("数据插入失败");
        }
周鸿 authored
119
        String shelfNo = model.getShelfNo().substring(0, 5);
120
121
        String warehouseCode = ShiroUtils.getWarehouseCode();
        Points points=new Points();
周鸿 authored
122
//        points.setWarehouseCode(warehouseCode);
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
        points.setGoodsShelfNo(shelfNo);
        points=pointsService.selectEntity(points);
        if(points==null){
            throw new ServiceException("没有对应的货架");
        }
        if(model.getTaskType().equals("pick") && model.getState().equals("1")){
            points.setIsLocked(0);
            boolean rt=pointsService.updateById(points);
            if(!rt){
                throw new ServiceException("删除AGV出库任务后修改货架状态失败");
            }
        }
        //回传任务为putway时,查找到改货架中物料为agv的任务,并完成任务。

        return AjaxResult.success(model);
pengcheng authored
138
    }
周鸿 authored
139
140
141
142
143
144
145
146
147
148
149
150

    private String getUrl(){
        Address address =new Address();
        address.setParam("AGV");
        address.setWarehouseCode(ShiroUtils.getWarehouseCode());
        String url=addressService.selectEntity(address).getUrl();
        return url;
    }
    /**
     * AGV 任务取消
     */
    @Override
肖超群 authored
151
    @Transactional(rollbackFor = Exception.class)
周鸿 authored
152
153
154
155
156
157
158
    public AjaxResult taskCancel(String message)
    {
        Map<String, Object> map = new HashMap<>();
        map.put("interactionId", interactionId);
        map.put("reason", message);
        String JsonParam = JSON.toJSONString(map);
        String url= this.getUrl()+"TaskCancel";
周鸿 authored
159
        String result = HttpUtils.bodypost(url, JsonParam,"KS0001");
周鸿 authored
160
161
162
163
164
165
166
167
168
169
170
171
172
173
        AjaxResult ajaxResult = JSON.parseObject(result, AjaxResult.class);
        return ajaxResult;
    }
    /**
     * AGV 旋转方向
     */
    @Override
    public AjaxResult TurnOriention(String carNo,String orientation)
    {
        Map<String, String> map = new HashMap<>();
        map.put("carNo", carNo);
        map.put("orientation", orientation);
        String JsonParam = JSON.toJSONString(map);
        String url= this.getUrl()+"TurnOriention";
周鸿 authored
174
        String result = HttpUtils.bodypost(url, JsonParam,"KS0001");
周鸿 authored
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
        AjaxResult ajaxResult = JSON.parseObject(result, AjaxResult.class);
        return ajaxResult;
    }
    //手动叫车
    @Transactional
    @Override
    public AjaxResult ManualCalling(String station,String shelfNo){
        AgvTask model = new AgvTask();
        model.setTaskHeaderId(666);
        model.setTaskDetailId(666);
        model.setWarehouseCode(ShiroUtils.getWarehouseCode());
        model.setCompanyId(ShiroUtils.getCompanyIdList().get(0));
        model.setCompanyCode(ShiroUtils.getCompanyCodeList().get(0));
        model.setTaskType("pick");
        model.setShelfNo(shelfNo);
        model.setStation(station);
        model.setStatus(20);
        Points points=new Points();
        points.setWarehouseCode(ShiroUtils.getWarehouseCode());
        points.setGoodsShelfNo(shelfNo);
        AjaxResult ajaxResult=new AjaxResult();
        points=pointsService.selectEntity(points);
        if(points==null){
            throw new ServiceException("没有此货架");
        }
        if(points.getIsLocked()!=1 && points.getIsLocked()!=2) {
            model.setFromLocationNo("");
            model.setToLocationNo("");
            model.setOrientation("A");
            ajaxResult = this.TaskAssign(model);
            if (!ajaxResult.hasErr()) {
                points.setIsLocked(1);
                points.setStation(station);
                points.setOIntX(points.getIntX());
                points.setOIntY(points.getIntY());
                pointsService.updateById(points);
            }
        }else {
            throw new ServiceException("该货架已出库");
        }
        return ajaxResult;
    }
    /**
     * AGV 任务下发
     */

    public AjaxResult TaskAssign(AgvTask model)
    {
        model.setInteractionId(interactionId);
        User user =  userService.selectUserByLoginName(ShiroUtils.getLoginName());
        if(user == null){
            model.setPlatform("wms");
        }else {
            model.setPlatform(user.getUserName());
        }
        String url = this.getUrl()+"TaskAssign";
        String JsonParam = JSON.toJSONString(model);
        logger.info("任务下发:{}",JsonParam);
周鸿 authored
233
        String result = HttpUtils.bodypost(url, JsonParam,model.getWarehouseCode());
周鸿 authored
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
        if(StringUtils.isEmpty(result)){
            throw new ServiceException("ACS接口地址错误或服务器连接不到或返回为空");
        }
        AjaxResult ajaxResult = JSON.parseObject(result, AjaxResult.class);
        return ajaxResult;
    }
    /**
     * 设置agv下发任务的实体
     *
     */
    @Transactional
    @Override
    public AjaxResult TaskModel(String station,Integer id){
        AjaxResult ajaxResult=new AjaxResult();
        AgvTask model=new AgvTask();

        //通过id查找任务
        TaskHeader task= taskHeaderService.getById(id);
        if(task==null){
            return AjaxResult.error("任务不存在");
        }

        String containerCode=task.getContainerCode();
周鸿 authored
257
258
//        String code=containerCode.substring(0,4);
        Container container=containerService.getContainerByCode(containerCode,task.getWarehouseCode());
周鸿 authored
259
260
        Points points=new Points();
        points.setWarehouseCode(ShiroUtils.getWarehouseCode());
周鸿 authored
261
        points.setGoodsShelfNo(container.getGoodsShelfNo());
周鸿 authored
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
        points=pointsService.selectEntity(points);

        //任务下发实体
        model.setTaskHeaderId(task.getId());
        model.setTaskDetailId(task.getId());
        model.setTaskType("pick");
        model.setStation(station);
        model.setWarehouseId(task.getWarehouseId());
        model.setWarehouseCode(task.getWarehouseCode());
        model.setCompanyId(task.getCompanyId());
        model.setCompanyCode(task.getCompanyCode());
        model.setStatus(10);
        if(containerCode.substring(5,6).equals("1")) {
            model.setOrientation("A");
        }else {
            model.setOrientation("C");
        }
        //判断货架是否处于1阶段,1阶段为pick阶段。
        if (points == null) {
            throw new ServiceException("货架不存在!");
        }
283
284
285
286
287
288
289
290
291
292
293
294
        //如果其他人有这个货架的任务已下发,则提示该货架有任务
        List<TaskHeader> agvUncompletedTasks = taskHeaderService.list(
                new LambdaQueryWrapper<TaskHeader>()
                        .eq(TaskHeader::getGoodsShelfNo, points.getGoodsShelfNo())
                        .ne(TaskHeader::getCreatedBy, task.getCreatedBy())
                        .eq(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_RELEASE)
        );
        if (agvUncompletedTasks!=null&&agvUncompletedTasks.size()>0) {
            throw new ServiceException("货架存在其他任务,请稍后下发!");
        }
周鸿 authored
295
        Integer[] ids=null;
296
297
298
299
        if(points.getGoodsShelfNo()!=null){
            List<TaskHeader> agvUncompletedTask = taskHeaderService.list(
                    new LambdaQueryWrapper<TaskHeader>()
                            .eq(TaskHeader::getGoodsShelfNo, points.getGoodsShelfNo())
300
                            .eq(TaskHeader::getCreatedBy, task.getCreatedBy())
周鸿 authored
301
                            .ge(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_BUILD)
302
303
                            .lt(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_COMPLETED)
            );
周鸿 authored
304
            /*if(!agvUncompletedTask.isEmpty()){
周鸿 authored
305
                return AjaxResult.error(""+points.getGoodsShelfNo()+"有在执行任务");
周鸿 authored
306
            }*/
周鸿 authored
307
            List<Integer> codeList = agvUncompletedTask.stream().map(t -> t.getId()).collect(Collectors.toList());
周鸿 authored
308
            ids=codeList.toArray(new Integer[codeList.size()]);
309
310
        }
周鸿 authored
311
312

//        String ids=id.toString();
周鸿 authored
313
314
        //islocked  1出库中2在站台3在库内
        if((points.getIsLocked()==0 || points.getIsLocked()==3) || !station.equals(points.getStation())){
周鸿 authored
315
316
317
            model.setShelfNo(points.getGoodsShelfNo());
            model.setFromLocationNo("");
            model.setToLocationNo("");
周鸿 authored
318
            model.setDate(new Date());
319
320
            ajaxResult=this.TaskAssign(model);
//            ajaxResult=AjaxResult.success();
周鸿 authored
321
322
323
324
325
326
327
328
329
330
            if(!ajaxResult.hasErr()){
                //修改points表,设为出库状态,修改出库前位置
                points.setIsLocked(1);
                points.setOIntX(points.getIntX());
                points.setOIntY(points.getIntY());
                points.setStation(station);
                pointsService.updateById(points);
                if(!agvTaskService.save(model)){
                    throw new ServiceException("agv任务下发失败");
                }
周鸿 authored
331
                if(taskHeaderAgvService.sendTaskToAGV(ids,station).hasErr()){
周鸿 authored
332
333
334
335
336
337
338
339
340
341
342
343
344
                    throw new ServiceException("执行任务失败");
                }

                PointsRecord pointsRecord = new PointsRecord();
                pointsRecord.setCode(points.getGoodsShelfNo());
                pointsRecord.setStation(station);
                pointsRecord.setCreated(new Date());
                pointsRecord.setCreatedby(ShiroUtils.getLoginName());
                pointsRecordService.save(pointsRecord);
            }else{
                return ajaxResult;
            }
        }else{
周鸿 authored
345
            if(taskHeaderAgvService.sendTaskToAGV(ids,station).hasErr()){
周鸿 authored
346
347
348
349
350
351
                throw new ServiceException("执行任务失败");
            }
            return AjaxResult.success("任务执行成功,该货架已出库");
        }
        return  ajaxResult;
    }
周鸿 authored
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378

    /**
     * agv  putway任务下发
     *
     */
    @Override
    @Transactional
    public AjaxResult TaskAssigns(Integer taskId,String shlfNo,String station,String row,String line)
    {
        //查找下发任务
        int result=0;
        String warehouseCode=ShiroUtils.getWarehouseCode();
        AgvTask agvTask=new AgvTask();
        if(taskId==null){
            agvTask.setTaskHeaderId(666);
            agvTask.setTaskDetailId(666);
        }else {
            TaskDetail task = taskDetailService.getById(taskId);
            agvTask.setTaskHeaderId(task.getId());
            agvTask.setTaskDetailId(task.getId());
            agvTask.setCompanyId(task.getCompanyId());
            agvTask.setCompanyCode(task.getCompanyCode());
        }
        agvTask.setWarehouseCode(ShiroUtils.getWarehouseCode());
        agvTask.setTaskType("putway");
        AjaxResult ajaxResult = new AjaxResult();
        //查找需要回去的对应的货架
周鸿 authored
379
        String containCode=shlfNo.substring(0, 5);
周鸿 authored
380
381
382
383
        Points points=new Points();
        points.setWarehouseCode(warehouseCode);
        points.setGoodsShelfNo(containCode);
        points.setIsLocked(2);
周鸿 authored
384
        points=pointsService.selectEntityV(points);
周鸿 authored
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
        if(points!=null) {
            AgvTask model = new AgvTask();
            model.setTaskHeaderId(agvTask.getTaskHeaderId());
            model.setTaskDetailId(agvTask.getTaskDetailId());
            model.setTaskType("putway");
            model.setShelfNo(points.getGoodsShelfNo());
            model.setStation(station);
            model.setFromLocationNo("");

            //给出目的位置
            //找出已出库的货架
            Points point=new Points();
            point.setWarehouseCode(warehouseCode);
            point.setGoodsShelfNo(points.getGoodsShelfNo());
//            Integer number=pointsService.selectRanking(point);
//            if(number == null){
//                return AjaxResult.error("该货架不处于在站台状态,无法回库");
//            }
//
//            List<Points> pointsList = pointsService.selectILPointsList();
//            point = pointsList.get(number-1);

            point=pointsService.selectEntity(point);


            //如果查找到的货架和回库任务的货架相同,就不做操作
            if(point.getOIntX().equals(points.getIntX()) && point.getOIntY().equals(points.getIntY())){
                model.setToLocationNo("");
            }else {
                //如果不同,则目的位置为该货架的oIntX,oIntY
                model.setToLocationNo(point.getOIntX() + "," + point.getOIntY());
            }

            model.setOrientation("A");
周鸿 authored
419
            //#####################
周鸿 authored
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
            ajaxResult = this.TaskAssign(model);
            String jsons = JSON.toJSONString(ajaxResult);
            logger.info("回库回传信息:{}",jsons);
            String shelfNo=points.getGoodsShelfNo().substring(1, 5);
            LocationPosition lps=new LocationPosition();
            lps.setWarehouseCode(warehouseCode);
            lps.setIntX(point.getOIntX());
            lps.setIntY(point.getOIntY());

            LocationPosition lpss=new LocationPosition();
            lpss.setWarehouseCode(warehouseCode);
            lpss.setIntX(points.getIntX());
            lpss.setIntY(points.getIntY());


            if (!ajaxResult.hasErr()) {

                //回去位置与货架位置不一样时
                if(!lps.getIntX().equals(points.getIntX()) || !lps.getIntY().equals(points.getIntY()) ) {

                    //位置不同时,修改回库货架的x,y值
                    points.setIntX(lps.getIntX());
                    points.setIntY(lps.getIntY());
                    pointsService.updateById(points);

                    //位置不同,货架编号不同时,修改回去位置的货架的o属性x,y值
                    if(!point.getGoodsShelfNo().equals(points.getGoodsShelfNo())) {
                        point.setOIntX(points.getOIntX());
                        point.setOIntY(points.getOIntY());
                        pointsService.updateById(point);
                    }
                }

                points.setIsLocked(3);
                points.setNum(points.getNum()+1);
                points.setStation("");

                pointsService.updateById(points);
                String json = JSON.toJSONString(points);
                logger.info("回库后货架信息:{}",json);
//                model.setCompanyId(agvTask.getCompanyId());
//                model.setCompanyCode(agvTask.getCompanyCode());
//                model.setWarehouseId(agvTask.getWarehouseId());
//                model.setWarehouseCode(agvTask.getWarehouseCode());
//                if (agvTaskMapper.insertModel(model) < 1) {
//                    throw new ServiceException("agv任务下发失败");
//                }
            }
        }else {
            throw new ServiceException("该货架已建立回库任务");
        }
        return ajaxResult;
    }
pengcheng authored
476
}