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_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_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_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("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);
|
}
|
}
|
}
|
}
|