自动化立体仓库 - WMS系统
chen.llin
昨天 6246673dd42d9faeab27c1372e3eff6aa58d3f0c
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
package com.zy.asrs.controller;
 
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.zy.asrs.entity.CrnTiltRecord;
import com.zy.asrs.service.CrnTiltRecordService;
import com.zy.common.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
 
import java.util.Map;
 
/**
 * 堆垛机倾斜度记录 Controller
 */
@Slf4j
@RestController
@RequestMapping("/crnTiltRecord")
@Api(tags = "堆垛机倾斜度记录管理")
public class CrnTiltRecordController extends BaseController {
 
    @Autowired
    private CrnTiltRecordService crnTiltRecordService;
 
    /**
     * 查询倾斜度记录列表(分页)
     */
    @RequestMapping(value = "/list/auth", method = RequestMethod.GET)
    @ManagerAuth
    @ApiOperation(value = "查询倾斜度记录列表", notes = "支持分页和多条件查询")
    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) {
        try {
            EntityWrapper<CrnTiltRecord> wrapper = new EntityWrapper<>();
            
            // 处理查询条件
            excludeTrash(param);
            convert(param, wrapper);
            allLike(CrnTiltRecord.class, param.keySet(), wrapper, condition);
            
            // 排序
            if (!Cools.isEmpty(orderByField)) {
                wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType));
            } else {
                // 默认按记录日期倒序
                wrapper.orderBy("record_date", false);
                wrapper.orderBy("record_time", false);
            }
            
            Page<CrnTiltRecord> page = new Page<>(curr, limit);
            Page<CrnTiltRecord> result = crnTiltRecordService.selectPage(page, wrapper);
            
            return R.ok(result);
        } catch (Exception e) {
            log.error("查询倾斜度记录列表失败", e);
            return R.error("查询失败:" + e.getMessage());
        }
    }
 
    /**
     * 根据ID查询详情
     */
    @RequestMapping(value = "/detail/auth", method = RequestMethod.GET)
    @ManagerAuth
    @ApiOperation(value = "查询倾斜度记录详情")
    public R detail(@RequestParam Long id) {
        try {
            if (Cools.isEmpty(id)) {
                return R.error("ID不能为空");
            }
            
            CrnTiltRecord record = crnTiltRecordService.selectById(id);
            if (Cools.isEmpty(record)) {
                return R.error("记录不存在");
            }
            
            return R.ok(record);
        } catch (Exception e) {
            log.error("查询倾斜度记录详情失败", e);
            return R.error("查询失败:" + e.getMessage());
        }
    }
 
    /**
     * 根据堆垛机编号查询最近的记录
     */
    @RequestMapping(value = "/latest/auth", method = RequestMethod.GET)
    @ManagerAuth
    @ApiOperation(value = "查询堆垛机最近的倾斜度记录")
    public R latest(@RequestParam Integer crnNo) {
        try {
            if (Cools.isEmpty(crnNo)) {
                return R.error("堆垛机编号不能为空");
            }
            
            EntityWrapper<CrnTiltRecord> wrapper = new EntityWrapper<>();
            wrapper.eq("crn_no", crnNo);
            wrapper.orderBy("record_date", false);
            wrapper.orderBy("record_time", false);
            wrapper.last("OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY");
            
            CrnTiltRecord record = crnTiltRecordService.selectOne(wrapper);
            return R.ok(record);
        } catch (Exception e) {
            log.error("查询堆垛机最近倾斜度记录失败", e);
            return R.error("查询失败:" + e.getMessage());
        }
    }
 
    /**
     * 导出倾斜度记录
     */
    @RequestMapping(value = "/export/auth", method = RequestMethod.GET)
    @ManagerAuth
    @ApiOperation(value = "导出倾斜度记录")
    public R export(@RequestParam(required = false) String condition,
                    @RequestParam Map<String, Object> param) {
        try {
            EntityWrapper<CrnTiltRecord> wrapper = new EntityWrapper<>();
            
            // 处理查询条件
            excludeTrash(param);
            convert(param, wrapper);
            allLike(CrnTiltRecord.class, param.keySet(), wrapper, condition);
            
            // 排序:默认按记录日期倒序
            wrapper.orderBy("record_date", false);
            wrapper.orderBy("record_time", false);
            
            // 查询所有数据(不分页)
            java.util.List<CrnTiltRecord> list = crnTiltRecordService.selectList(wrapper);
            
            // 定义导出字段
            java.util.List<String> fields = new java.util.ArrayList<>();
            fields.add("id");
            fields.add("crnNo");
            fields.add("tiltValue");
            fields.add("tiltX");
            fields.add("tiltY");
            fields.add("tiltZ");
            fields.add("recordDate");
            fields.add("recordTime");
            fields.add("prevTiltValue");
            fields.add("tiltChange");
            fields.add("recordType");
            
            return R.ok(exportSupport(list, fields));
        } catch (Exception e) {
            log.error("导出倾斜度记录失败", e);
            return R.error("导出失败:" + e.getMessage());
        }
    }
 
    /**
     * 转换查询条件
     */
    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());
            // 跳过空值和null
            if (Cools.isEmpty(val) || "null".equals(val) || "undefined".equals(val)) {
                continue;
            }
            String columnKey = humpToLine(entry.getKey());
            
            if (val.contains(RANGE_TIME_LINK)) {
                // 时间范围查询
                String[] dates = val.split(RANGE_TIME_LINK);
                if (dates.length == 2 && !Cools.isEmpty(dates[0]) && !Cools.isEmpty(dates[1])) {
                    wrapper.ge(columnKey, DateUtils.convert(dates[0]));
                    wrapper.le(columnKey, DateUtils.convert(dates[1]));
                }
            } else {
                wrapper.like(columnKey, val);
            }
        }
    }
}