自动化立体仓库 - WCS系统
*
lsh
2025-01-15 a25037d44427756e6ab9dd0ed1360425d660362a
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
package com.zy.system.controller;
 
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.core.annotations.ManagerAuth;
import com.core.common.Cools;
import com.core.common.DateUtils;
import com.core.common.R;
import com.core.controller.AbstractBaseController;
import com.zy.system.entity.Resource;
import com.zy.system.service.ResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import java.util.*;
 
@RestController
public class ResourceController extends AbstractBaseController {
 
    @Autowired
    private ResourceService resourceService;
 
    @RequestMapping(value = "/resource/{id}/auth")
    @ManagerAuth
    public R get(@PathVariable("id") Long id) {
        return R.ok(resourceService.selectById(String.valueOf(id)));
    }
 
    @RequestMapping(value = "/resource/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 Map<String, Object> param){
        excludeTrash(param);
        EntityWrapper<Resource> wrapper = new EntityWrapper<>();
        convert(param, wrapper);
        wrapper.orderBy("id", false);
        return R.ok(resourceService.selectPage(new Page<>(curr, limit), wrapper));
    }
 
    private void convert(Map<String, Object> map, EntityWrapper wrapper){
        for (Map.Entry<String, Object> entry : map.entrySet()){
            if (entry.getKey().endsWith(">")) {
                wrapper.ge(Cools.deleteChar(entry.getKey()), DateUtils.convert(String.valueOf(entry.getValue())));
            } else if (entry.getKey().endsWith("<")) {
                wrapper.le(Cools.deleteChar(entry.getKey()), DateUtils.convert(String.valueOf(entry.getValue())));
            } else {
                wrapper.eq(entry.getKey(), String.valueOf(entry.getValue()));
            }
        }
    }
 
    @RequestMapping(value = "/resource/edit/auth")
    @ManagerAuth(memo = "菜单编辑")
    public R edit(Resource resource) {
        if (Cools.isEmpty(resource)){
            return R.error();
        }
        if (null == resource.getId()){
            if (resource.getSort() == null){
                resource.setSort(999);
            }
            resourceService.insert(resource);
        } else {
            resourceService.updateById(resource);
        }
        return R.ok();
    }
 
    @RequestMapping(value = "/resource/add/auth")
    @ManagerAuth(memo = "菜单添加")
    public R add(Resource resource) {
        resourceService.insert(resource);
        return R.ok();
    }
 
    @RequestMapping(value = "/resource/update/auth")
    @ManagerAuth(memo = "菜单修改")
    public R update(Resource resource){
        if (Cools.isEmpty(resource) || null==resource.getId()){
            return R.error();
        }
        resourceService.updateById(resource);
        return R.ok();
    }
 
    @RequestMapping(value = "/resource/delete/auth")
    @ManagerAuth(memo = "菜单删除")
    public R delete(Integer[] ids){
        if (Cools.isEmpty(ids)){
            return R.error();
        }
        resourceService.deleteBatchIds(Arrays.asList(ids));
        return R.ok();
    }
 
    @RequestMapping(value = "/resource/export/auth")
    @ManagerAuth(memo = "菜单导出")
    public R export(@RequestBody JSONObject param){
        List<String> fields = JSONObject.parseArray(param.getJSONArray("fields").toJSONString(), String.class);
        EntityWrapper<Resource> wrapper = new EntityWrapper<>();
        Map<String, Object> map = excludeTrash(param.getJSONObject("resource"));
        convert(map, wrapper);
        List<Resource> list = resourceService.selectList(wrapper);
        return R.ok(exportSupport(list, fields));
    }
 
    @RequestMapping(value = "/resourceQuery/auth")
    @ManagerAuth
    public R query(String condition) {
        EntityWrapper<Resource> wrapper = new EntityWrapper<>();
        wrapper.like("name", condition);
        Page<Resource> page = resourceService.selectPage(new Page<>(0, 10), wrapper);
        List<Map<String, Object>> result = new ArrayList<>();
        for (Resource resource : page.getRecords()){
            Map<String, Object> map = new HashMap<>();
            map.put("id", resource.getId());
            map.put("value", resource.getName().concat("(").concat(resource.getLevel$().substring(0, 2).concat(")")));
            result.add(map);
        }
        return R.ok(result);
    }
 
}