1
zhang
14 小时以前 70ff4954fec4483883e2485bc8c0ed59054b91a9
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
package com.zy.acs.manager.manager.controller;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zy.acs.framework.common.Cools;
import com.zy.acs.framework.common.R;
import com.zy.acs.manager.common.annotation.OperationLog;
import com.zy.acs.manager.common.domain.BaseParam;
import com.zy.acs.manager.common.domain.PageParam;
import com.zy.acs.manager.core.constant.LocGroupConstant;
import com.zy.acs.manager.core.service.MainService;
import com.zy.acs.manager.manager.controller.param.OpenBusSubmitParam;
import com.zy.acs.manager.manager.entity.Loc;
import com.zy.acs.manager.manager.entity.Sta;
import com.zy.acs.manager.manager.enums.StaStsType;
import com.zy.acs.manager.manager.service.LocService;
import com.zy.acs.manager.manager.service.StaService;
import com.zy.acs.manager.manager.service.TaskService;
import com.zy.acs.manager.system.controller.BaseController;
import com.zy.acs.manager.system.service.ConfigService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
 
/**
 * Created by vincent on 2023/6/12
 */
@Api(tags = "Open Api")
@RestController
@RequestMapping("/api/open")
public class OpenController extends BaseController {
 
    @Autowired
    private MainService mainService;
 
    @Autowired
    private LocService locService;
 
    @Autowired
    private StaService staService;
 
    @Autowired
    private ConfigService configService;
 
 
    @Autowired
    private TaskService taskService;
 
 
    //@PreAuthorize("hasAuthority('open:bus:submit')")
    @PostMapping("/bus/submit")
    @OperationLog("generate task from open api")
    public R save(@RequestBody OpenBusSubmitParam param) {
        if (!configService.getVal("TaskAssignMode", Boolean.class)) {
            if (configService.getVal("InAndOutMode", Boolean.class, false)) {
                mainService.generateBusAndTask(param, null);
                return R.ok("generate tasks success");
            }
        }
        return R.error("generate tasks error");
    }
 
 
    @OperationLog("Cancel Task")
    @PostMapping("/task/cancel")
    public R cancel(@RequestBody List<String> taskIds) {
        if (Cools.isEmpty(taskIds)) {
            return R.error("task cancel error");
        }
        List<Boolean> data = new ArrayList<>();
        for (String id : taskIds) {
            data.add(taskService.cancel(taskService.selectBySeqNum(id).getId(), 9527L));
        }
        return R.ok().add(data);
    }
 
 
    @PostMapping("/sta/update")
    @OperationLog("sync sta")
    public R updateLoc(@RequestBody Map<String, Object> map) {
        if (!configService.getVal("TaskAssignMode", Boolean.class)) {
            if (configService.getVal("InAndOutMode", Boolean.class, false)) {
                String staNo = map.get("staNo").toString();
                Sta loc = staService.selectByStaNo(staNo);
                if (staNo.equals("1001")) {
                    if (loc.getStaSts() == StaStsType.STOCK.val()) {
                        loc.setStaSts(Long.parseLong(map.get("sts").toString()));
                        return staService.updateById(loc) ? R.ok() : R.error("update loc fail");
                    }
                } else if (staNo.equals("1007")) {
                    if (loc.getStaSts() == StaStsType.IDLE.val()) {
                        loc.setStaSts(Long.parseLong(map.get("sts").toString()));
                        return staService.updateById(loc) ? R.ok() : R.error("update loc fail");
                    }
                }
            }
        }
        return R.error("update loc fail");
    }
 
    //@PreAuthorize("hasAuthority('open:bus:submit')")
    @PostMapping("/loc/sync")
    @OperationLog("sync loc")
    public R loc(@RequestBody Map<String, Object> map) {
        BaseParam baseParam = buildParam(map, BaseParam.class);
        PageParam<Loc, BaseParam> pageParam = new PageParam<>(baseParam, Loc.class);
        return R.ok().add(locService.page(pageParam, pageParam.buildWrapper(true)));
    }
 
    @PostMapping("/loc/one")
    @OperationLog("one loc")
    public R emptyLoc(@RequestBody Map<String, Object> map) {
        if (!configService.getVal("TaskAssignMode", Boolean.class)) {
            if (configService.getVal("InAndOutMode", Boolean.class, false)) {
                String staNo = map.get("staNo").toString();
                Integer startRow = null;
                Integer endRow = null;
                if (staNo.equals("101-2") || staNo.equals("101-3") || staNo.equals("102-2") || staNo.equals("102-3")) {
                    startRow = Collections.min(LocGroupConstant.FAR_RIGHT_LOC_ROW_LIST);
                    endRow = Collections.max(LocGroupConstant.FAR_RIGHT_LOC_ROW_LIST);
                } else if (staNo.equals("103-2") || staNo.equals("103-3") || staNo.equals("104-2") || staNo.equals("104-3")) {
                    startRow = Collections.min(LocGroupConstant.RIGHT_LOC_ROW_LIST);
                    endRow = Collections.max(LocGroupConstant.RIGHT_LOC_ROW_LIST);
                } else if (staNo.equals("105-2") || staNo.equals("105-3") || staNo.equals("106-2") || staNo.equals("106-3")) {
                    startRow = Collections.min(LocGroupConstant.MIDDLE_LOC_ROW_LIST);
                    endRow = Collections.max(LocGroupConstant.MIDDLE_LOC_ROW_LIST);
                } else if (staNo.equals("107-2") || staNo.equals("107-3") || staNo.equals("108-2") || staNo.equals("108-3")) {
                    startRow = Collections.min(LocGroupConstant.LEFT_LOC_ROW_LIST);
                    endRow = Collections.max(LocGroupConstant.LEFT_LOC_ROW_LIST);
                } else if (staNo.equals("1007") || staNo.equals("1001")) {
                    startRow = Collections.min(LocGroupConstant.FAR_LEFT_LOC_ROW_LIST);
                    endRow = Collections.max(LocGroupConstant.FAR_LEFT_LOC_ROW_LIST);
                } else {
                    return R.error("staNo is not support");
                }
                LambdaQueryWrapper<Loc> idleWrapper = new LambdaQueryWrapper<Loc>().eq(Loc::getLocSts, Long.parseLong(map.get("sts").toString()));
                if (null != startRow) {
                    idleWrapper.ge(Loc::getRow, startRow);
                }
                if (null != endRow) {
                    idleWrapper.le(Loc::getRow, endRow);
                }
                List<Loc> idleList = locService.list(idleWrapper);
                if (Cools.isEmpty(idleList)) {
                    return R.error("没空库位");
                }
                Collections.shuffle(idleList);
                return R.ok().add(idleList.get(0));
            }
        }
        return R.error("未开启该模式");
    }
 
}