luxiaotao1123
2024-04-08 53f4cc4d271fc723f7a9a2f3de89c4ea8ede49a2
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
package com.zy.asrs.wcs.core.controller;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zy.asrs.framework.common.BaseRes;
import com.zy.asrs.framework.common.Cools;
import com.zy.asrs.framework.common.R;
import com.zy.asrs.framework.common.SnowflakeIdWorker;
import com.zy.asrs.wcs.common.annotation.OperationLog;
import com.zy.asrs.wcs.common.domain.BaseParam;
import com.zy.asrs.wcs.common.domain.KeyValVo;
import com.zy.asrs.wcs.common.domain.PageParam;
import com.zy.asrs.wcs.core.domain.param.ShuttleOperatorParam;
import com.zy.asrs.wcs.core.entity.BasShuttle;
import com.zy.asrs.wcs.core.entity.Motion;
import com.zy.asrs.wcs.core.entity.Task;
import com.zy.asrs.wcs.core.entity.TaskCtg;
import com.zy.asrs.wcs.core.kernel.AnalyzeService;
import com.zy.asrs.wcs.core.model.enums.TaskStsType;
import com.zy.asrs.wcs.core.service.BasShuttleService;
import com.zy.asrs.wcs.core.service.MotionService;
import com.zy.asrs.wcs.core.service.TaskCtgService;
import com.zy.asrs.wcs.core.service.TaskService;
import com.zy.asrs.wcs.core.utils.Utils;
import com.zy.asrs.wcs.rcs.News;
import com.zy.asrs.wcs.system.controller.BaseController;
import com.zy.asrs.wcs.utils.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
 
import javax.servlet.http.HttpServletResponse;
import java.util.*;
 
@RestController
@RequestMapping("/api")
public class BasShuttleController extends BaseController {
 
    @Autowired
    private BasShuttleService basShuttleService;
    @Autowired
    private TaskCtgService taskCtgService;
    @Autowired
    private SnowflakeIdWorker snowflakeIdWorker;
    @Autowired
    private TaskService taskService;
    @Autowired
    private AnalyzeService analyzeService;
    @Autowired
    private MotionService motionService;
 
    @PreAuthorize("hasAuthority('core:basShuttle:list')")
    @PostMapping("/basShuttle/page")
    public R page(@RequestBody Map<String, Object> map) {
        BaseParam baseParam = buildParam(map, BaseParam.class);
        PageParam<BasShuttle, BaseParam> pageParam = new PageParam<>(baseParam, BasShuttle.class);
        return R.ok().add(basShuttleService.page(pageParam, pageParam.buildWrapper(true)));
    }
 
    @PreAuthorize("hasAuthority('core:basShuttle:list')")
    @PostMapping("/basShuttle/list")
    public R list(@RequestBody Map<String, Object> map) {
        return R.ok().add(basShuttleService.list());
    }
 
    @PreAuthorize("hasAuthority('core:basShuttle:list')")
    @GetMapping("/basShuttle/{id}")
    public R get(@PathVariable("id") Long id) {
        return R.ok().add(basShuttleService.getById(id));
    }
 
    @PreAuthorize("hasAuthority('core:basShuttle:save')")
    @OperationLog("添加四向车设备列表")
    @PostMapping("/basShuttle/save")
    public R save(@RequestBody BasShuttle basShuttle) {
        if (!basShuttleService.save(basShuttle)) {
            return R.error("添加失败");
        }
        return R.ok("添加成功");
    }
 
    @PreAuthorize("hasAuthority('core:basShuttle:update')")
    @OperationLog("修改四向车设备列表")
    @PostMapping("/basShuttle/update")
    public R update(@RequestBody BasShuttle basShuttle) {
        if (!basShuttleService.updateById(basShuttle)) {
            return R.error("修改失败");
        }
        return R.ok("修改成功");
    }
 
    @PreAuthorize("hasAuthority('core:basShuttle:remove')")
    @OperationLog("删除四向车设备列表")
    @PostMapping("/basShuttle/remove/{ids}")
    public R remove(@PathVariable Long[] ids) {
        if (!basShuttleService.removeByIds(Arrays.asList(ids))) {
            return R.error("删除失败");
        }
        return R.ok("删除成功");
    }
 
    @PreAuthorize("hasAuthority('core:basShuttle:list')")
    @PostMapping("/basShuttle/query")
    public R query(@RequestParam(required = false) String condition) {
        List<KeyValVo> vos = new ArrayList<>();
        LambdaQueryWrapper<BasShuttle> wrapper = new LambdaQueryWrapper<>();
        if (!Cools.isEmpty(condition)) {
            wrapper.like(BasShuttle::getShuttleNo, condition);
        }
        basShuttleService.page(new Page<>(1, 30), wrapper).getRecords().forEach(
                item -> vos.add(new KeyValVo(item.getShuttleNo(), item.getShuttleNo()))
        );
        return R.ok().add(vos);
    }
 
    @PreAuthorize("hasAuthority('core:basShuttle:list')")
    @PostMapping("/basShuttle/export")
    public void export(@RequestBody Map<String, Object> map, HttpServletResponse response) throws Exception {
        ExcelUtil.build(ExcelUtil.create(basShuttleService.list(), BasShuttle.class), response);
    }
 
    @PreAuthorize("hasAuthority('core:basShuttle:operator')")
    @PostMapping("/basShuttle/operator/shuttle")
    @Transactional
    public R shuttleOperator(@RequestBody ShuttleOperatorParam param) {
        if (Cools.isEmpty(param.getShuttleNo(), param.getShuttleTaskMode())) {
            return R.error("参数为空");
        }
 
        Integer shuttleNo = param.getShuttleNo();
 
        //获取迁移任务类型
        TaskCtg taskCtg = taskCtgService.getOne(new LambdaQueryWrapper<TaskCtg>()
                .eq(TaskCtg::getFlag, "MANUAL")
                .eq(TaskCtg::getStatus, 1));
        if (taskCtg == null) {
            return R.error();
        }
 
        String targetLoc = null;//任务目标(借用字段)
        String targetSite = param.getShuttleTaskMode();//任务类型(借用字段)
        if (param.getShuttleTaskMode().equals("moveLoc")) {
            //迁移任务
            targetLoc = param.getTargetLocNo();
        }
 
        Task task = new Task();
        task.setUuid(String.valueOf(snowflakeIdWorker.nextId()));
        task.setTaskNo(String.valueOf(Utils.getTaskNo("MANUAL")));
        task.setTaskSts(TaskStsType.NEW_MANUAL.sts);
        task.setTaskCtg(taskCtg.getId());
        task.setPriority(10);
        task.setOriginSite(null);
        task.setOriginLoc(null);
        task.setDestSite(targetSite);
        task.setDestLoc(targetLoc);
        task.setIoTime(new Date());
        task.setStartTime(new Date());
        task.setStatus(1);
        task.setMemo("manual");
        task.setShuttleNo(param.getShuttleNo());
        boolean result = taskService.save(task);
        if (!result) {
            return R.error();
        }
 
        task = taskService.getById(task.getId());
 
        // generate motion list
        List<Motion> motionList = analyzeService.generateShuttleManualMotion(task);
        if (Cools.isEmpty(motionList)) {
            News.error("保存{}号四向穿梭车手动任务失败!!!", shuttleNo);
            return R.error();
        }
        motionService.batchInsert(motionList, task.getUuid(), Integer.valueOf(task.getTaskNo()));
 
        task.setTaskSts(TaskStsType.ANALYZE_MANUAL.sts);
        if (!taskService.updateById(task)) {
            News.error("保存{}号四向穿梭车手动任务失败!!!", shuttleNo);
            return R.error();
        }
        return R.ok();
    }
 
}