自动化立体仓库 - WMS系统
zwl
3 天以前 2acfc2d2a0e956910c51bd996f443b3cb9bd3dc9
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
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
package com.zy.asrs.controller;
 
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.core.annotations.ManagerAuth;
import com.core.common.BaseRes;
import com.core.common.Cools;
import com.core.common.DateUtils;
import com.core.common.R;
import com.zy.asrs.entity.BasCrnDepthRule;
import com.zy.asrs.entity.param.BasCrnDepthRuleRuntimePreviewParam;
import com.zy.asrs.entity.param.BasCrnDepthRuleTemplateParam;
import com.zy.asrs.service.BasCrnDepthRuleService;
import com.zy.common.service.CommonService;
import com.zy.common.web.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
@RestController
public class BasCrnDepthRuleController extends BaseController {
 
    @Autowired
    private BasCrnDepthRuleService basCrnDepthRuleService;
    @Autowired
    private CommonService commonService;
 
    /**
     * 查询单条堆垛机深浅规则。
     */
    @RequestMapping(value = "/basCrnDepthRule/{id}/auth")
    @ManagerAuth
    public R get(@PathVariable("id") Long id) {
        return R.ok(basCrnDepthRuleService.selectById(id));
    }
 
    /**
     * 分页查询堆垛机深浅规则列表。
     */
    @RequestMapping(value = "/basCrnDepthRule/list/auth")
    @ManagerAuth
    public R list(@RequestParam(defaultValue = "1") Integer curr,
                  @RequestParam(defaultValue = "10") Integer limit,
                  @RequestParam(required = false) String orderByField,
                  @RequestParam(required = false) String orderByType,
                  @RequestParam(required = false) String condition,
                  @RequestParam Map<String, Object> param) {
        EntityWrapper<BasCrnDepthRule> wrapper = new EntityWrapper<BasCrnDepthRule>();
        excludeTrash(param);
        convert(param, wrapper);
        allLike(BasCrnDepthRule.class, param.keySet(), wrapper, condition);
        if (!Cools.isEmpty(orderByField)) {
            wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType));
        } else {
            wrapper.orderBy("whs_type", true).orderBy("crn_no", true);
        }
        return R.ok(basCrnDepthRuleService.selectPage(new Page<BasCrnDepthRule>(curr, limit), wrapper));
    }
 
    /**
     * 把前端查询参数转换成 MyBatis Plus 的模糊/时间范围条件。
     */
    private <T> void convert(Map<String, Object> map, EntityWrapper<T> wrapper) {
        for (Map.Entry<String, Object> entry : map.entrySet()) {
            String val = String.valueOf(entry.getValue());
            if (val.contains(RANGE_TIME_LINK)) {
                String[] dates = val.split(RANGE_TIME_LINK);
                wrapper.ge(entry.getKey(), DateUtils.convert(dates[0]));
                wrapper.le(entry.getKey(), DateUtils.convert(dates[1]));
            } else {
                wrapper.like(entry.getKey(), val);
            }
        }
    }
 
    /**
     * 新增一条堆垛机深浅规则。
     */
    @RequestMapping(value = "/basCrnDepthRule/add/auth")
    @ManagerAuth(memo = "堆垛机深浅规则添加")
    public R add(BasCrnDepthRule basCrnDepthRule) {
        basCrnDepthRuleService.validateRule(basCrnDepthRule);
        Date now = new Date();
        basCrnDepthRule.setCreateBy(getUserId());
        basCrnDepthRule.setCreateTime(now);
        basCrnDepthRule.setUpdateBy(getUserId());
        basCrnDepthRule.setUpdateTime(now);
        basCrnDepthRuleService.insert(basCrnDepthRule);
        return R.ok("保存成功");
    }
 
    /**
     * 修改已有堆垛机深浅规则,并保留创建审计字段。
     */
    @RequestMapping(value = "/basCrnDepthRule/update/auth")
    @ManagerAuth(memo = "堆垛机深浅规则修改")
    public R update(BasCrnDepthRule basCrnDepthRule) {
        if (Cools.isEmpty(basCrnDepthRule) || basCrnDepthRule.getId() == null) {
            return R.error();
        }
        basCrnDepthRuleService.validateRule(basCrnDepthRule);
        BasCrnDepthRule dbRule = basCrnDepthRuleService.selectById(basCrnDepthRule.getId());
        if (dbRule == null) {
            return R.error("规则不存在");
        }
        basCrnDepthRule.setCreateBy(dbRule.getCreateBy());
        basCrnDepthRule.setCreateTime(dbRule.getCreateTime());
        basCrnDepthRule.setUpdateBy(getUserId());
        basCrnDepthRule.setUpdateTime(new Date());
        basCrnDepthRuleService.updateById(basCrnDepthRule);
        return R.ok("修改完成");
    }
 
    /**
     * 批量删除堆垛机深浅规则。
     */
    @RequestMapping(value = "/basCrnDepthRule/delete/auth")
    @ManagerAuth(memo = "堆垛机深浅规则删除")
    public R delete(@RequestParam String param) {
        List<BasCrnDepthRule> list = JSONArray.parseArray(param, BasCrnDepthRule.class);
        if (Cools.isEmpty(list)) {
            return R.error();
        }
        for (BasCrnDepthRule entity : list) {
            if (entity != null && entity.getId() != null) {
                basCrnDepthRuleService.deleteById(entity.getId());
            }
        }
        return R.ok();
    }
 
    /**
     * 导出当前查询条件命中的规则数据。
     */
    @RequestMapping(value = "/basCrnDepthRule/export/auth")
    @ManagerAuth(memo = "堆垛机深浅规则导出")
    public R export(@RequestBody JSONObject param) {
        List<String> fields = JSONObject.parseArray(param.getJSONArray("fields").toJSONString(), String.class);
        EntityWrapper<BasCrnDepthRule> wrapper = new EntityWrapper<BasCrnDepthRule>();
        Map<String, Object> map = excludeTrash(param.getJSONObject("basCrnDepthRule"));
        convert(map, wrapper);
        List<BasCrnDepthRule> list = basCrnDepthRuleService.selectList(wrapper);
        return R.ok(exportSupport(list, fields));
    }
 
    /**
     * 按模板预览某仓库范围内的默认深浅规则。
     */
    @RequestMapping(value = "/basCrnDepthRule/templatePreview/auth")
    @ManagerAuth(memo = "堆垛机深浅规则模板预览")
    public R templatePreview(BasCrnDepthRuleTemplateParam param) {
        return R.ok(basCrnDepthRuleService.previewTemplate(param));
    }
 
    /**
     * 按模板批量生成或覆盖某仓库的堆垛机深浅规则。
     */
    @RequestMapping(value = "/basCrnDepthRule/templateGenerate/auth")
    @ManagerAuth(memo = "堆垛机深浅规则模板生成")
    public R templateGenerate(BasCrnDepthRuleTemplateParam param) {
        basCrnDepthRuleService.saveTemplate(param, getUserId());
        return R.ok("模板生成完成");
    }
 
    /**
     * 预览某站点当前的库区、设备和深浅排参与顺序。
     */
    @RequestMapping(value = "/basCrnDepthRule/runtimePreview/auth")
    @ManagerAuth(memo = "堆垛机深浅规则运行预览")
    public R runtimePreview(BasCrnDepthRuleRuntimePreviewParam param) {
        return R.ok(commonService.previewRun2Allocation(param));
    }
 
    /**
     * 为前端自动完成提供规则主键查询。
     */
    @RequestMapping(value = "/basCrnDepthRuleQuery/auth")
    @ManagerAuth
    public R query(String condition) {
        EntityWrapper<BasCrnDepthRule> wrapper = new EntityWrapper<BasCrnDepthRule>();
        wrapper.like("crn_no", condition);
        Page<BasCrnDepthRule> page = basCrnDepthRuleService.selectPage(new Page<BasCrnDepthRule>(0, 10), wrapper);
        List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
        for (BasCrnDepthRule rule : page.getRecords()) {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("id", rule.getId());
            map.put("value", rule.getWhsType() + "-" + rule.getCrnNo());
            result.add(map);
        }
        return R.ok(result);
    }
 
    /**
     * 检查某个字段值是否已存在,用于前端重复校验。
     */
    @RequestMapping(value = "/basCrnDepthRule/check/column/auth")
    @ManagerAuth
    public R query(@RequestBody JSONObject param) {
        Wrapper<BasCrnDepthRule> wrapper = new EntityWrapper<BasCrnDepthRule>()
                .eq(humpToLine(String.valueOf(param.get("key"))), param.get("val"));
        if (null != basCrnDepthRuleService.selectOne(wrapper)) {
            return R.parse(BaseRes.REPEAT).add(getComment(BasCrnDepthRule.class, String.valueOf(param.get("key"))));
        }
        return R.ok();
    }
}