package com.mes.yield.controller;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.mes.utils.Result;
|
import com.mes.yield.entity.Yield;
|
import com.mes.yield.service.YieldService;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiOperation;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.*;
|
import org.springframework.util.StringUtils;
|
|
import java.util.Calendar;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.Map;
|
|
@Api(tags = "单小时产量接口")
|
@RestController
|
@RequestMapping("/yield")
|
public class YieldController {
|
|
@Autowired
|
private YieldService yieldService;
|
|
@ApiOperation("获取单小时产量数据列表")
|
@PostMapping("/listYield")
|
@ResponseBody
|
public Result listYield(@RequestBody Map<String, Object> params) {
|
Integer page = params.get("page") == null ? 1 : (Integer) params.get("page");
|
Integer pageSize = params.get("pageSize") == null ? 10 : (Integer) params.get("pageSize");
|
String lineNo = (String) params.get("lineNo");
|
|
QueryWrapper<Yield> queryWrapper = new QueryWrapper<Yield>().orderByDesc("record_time");
|
if (StringUtils.hasText(lineNo)) {
|
queryWrapper.eq("line_no", lineNo);
|
}
|
|
Page<Yield> pageData = yieldService.page(
|
new Page<>(page, pageSize),
|
queryWrapper
|
);
|
|
return Result.build(200, "查询成功", pageData);
|
}
|
|
@ApiOperation("添加单小时产量记录")
|
@PostMapping("/addYield")
|
@ResponseBody
|
public Result addYield(@RequestBody Yield yieldValue) {
|
yieldValue.setCreateTime(new Date());
|
yieldValue.setUpdateTime(new Date());
|
boolean success = yieldService.save(yieldValue);
|
int count = success ? 1 : 0;
|
String message = count > 0 ? "添加成功:" + count : "添加失败!";
|
return Result.build(200, message, count);
|
}
|
|
@ApiOperation("修改单小时产量记录")
|
@PostMapping("/updateYield")
|
@ResponseBody
|
public Result updateYield(@RequestBody Yield yieldValue) {
|
yieldValue.setUpdateTime(new Date());
|
boolean success = yieldService.updateById(yieldValue);
|
int count = success ? 1 : 0;
|
String message = count > 0 ? "修改成功:" + count : "修改失败!";
|
return Result.build(200, message, count);
|
}
|
|
@ApiOperation("删除单小时产量记录")
|
@PostMapping("/deleteYield")
|
@ResponseBody
|
public Result deleteYield(@RequestBody Yield yield) {
|
boolean success = yieldService.removeById(yield.getId());
|
int count = success ? 1 : 0;
|
String message = count > 0 ? "删除成功:" + count : "删除失败!";
|
return Result.build(200, message, count);
|
}
|
|
@ApiOperation("获取图表数据")
|
@PostMapping("/chartYield")
|
@ResponseBody
|
public Result getChartData(@RequestBody(required = false) Map<String, Object> params) {
|
String lineNo = params != null ? (String) params.get("lineNo") : null;
|
Integer dayCount = params != null && params.get("dayCount") != null ? (Integer) params.get("dayCount") : null;
|
|
QueryWrapper<Yield> queryWrapper = new QueryWrapper<Yield>().orderByAsc("record_time");
|
if (StringUtils.hasText(lineNo)) {
|
queryWrapper.eq("line_no", lineNo);
|
}
|
|
// 如果指定了天数,则查询最近N天的数据,否则查询全部数据
|
if (dayCount != null && dayCount > 0) {
|
// 计算N天前的日期
|
Calendar calendar = Calendar.getInstance();
|
calendar.add(Calendar.DAY_OF_MONTH, -dayCount);
|
Date startDate = calendar.getTime();
|
queryWrapper.ge("record_time", startDate);
|
}
|
|
// 移除了固定limit限制,允许获取全部数据
|
|
List<Yield> data = yieldService.list(queryWrapper);
|
|
return Result.build(200, "查询成功", data);
|
}
|
}
|