package com.mes.plannedAmount.controller;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.mes.plannedAmount.entity.PlannedAmount;
|
import com.mes.plannedAmount.service.PlannedAmountService;
|
import com.mes.utils.Result;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiOperation;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.util.StringUtils;
|
import org.springframework.web.bind.annotation.*;
|
|
import java.util.Calendar;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.Map;
|
|
@Api(tags = "计划产量接口")
|
@RestController
|
@RequestMapping("/plannedAmount")
|
public class PlannedAmountController {
|
|
@Autowired
|
private PlannedAmountService plannedAmountService;
|
|
@ApiOperation("获取计划量数据列表")
|
@PostMapping("/listPlanned")
|
@ResponseBody
|
public Result listPlanned(@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 type = (String) params.get("type");
|
|
QueryWrapper<PlannedAmount> queryWrapper = new QueryWrapper<PlannedAmount>().orderByDesc("record_time");
|
if (StringUtils.hasText(type)) {
|
queryWrapper.eq("type", type);
|
}
|
|
Page<PlannedAmount> pageData = plannedAmountService.page(
|
new Page<>(page, pageSize),
|
queryWrapper
|
);
|
|
return Result.build(200, "查询成功", pageData);
|
}
|
|
@ApiOperation("添加计划量")
|
@PostMapping("/addPlanned")
|
@ResponseBody
|
public Result addPlanned(@RequestBody PlannedAmount value) {
|
value.setCreateTime(new Date());
|
value.setUpdateTime(new Date());
|
boolean success = plannedAmountService.save(value);
|
int count = success ? 1 : 0;
|
String message = count > 0 ? "添加成功:" + count : "添加失败!";
|
return Result.build(200, message, count);
|
}
|
|
@ApiOperation("修改计划量")
|
@PostMapping("/updatePlanned")
|
@ResponseBody
|
public Result updatePlanned(@RequestBody PlannedAmount value) {
|
value.setUpdateTime(new Date());
|
boolean success = plannedAmountService.updateById(value);
|
int count = success ? 1 : 0;
|
String message = count > 0 ? "修改成功:" + count : "修改失败!";
|
return Result.build(200, message, count);
|
}
|
|
@ApiOperation("删除计划量")
|
@PostMapping("/deletePlanned")
|
@ResponseBody
|
public Result deletePlanned(@RequestBody PlannedAmount value) {
|
boolean success = plannedAmountService.removeById(value.getId());
|
int count = success ? 1 : 0;
|
String message = count > 0 ? "删除成功:" + count : "删除失败!";
|
return Result.build(200, message, count);
|
}
|
|
@ApiOperation("获取图表数据")
|
@PostMapping("/chartPlanned")
|
@ResponseBody
|
public Result getChartData(@RequestBody(required = false) Map<String, Object> params) {
|
String type = params != null ? (String) params.get("type") : null;
|
Integer dayCount = params != null && params.get("dayCount") != null ? (Integer) params.get("dayCount") : null;
|
|
QueryWrapper<PlannedAmount> queryWrapper = new QueryWrapper<PlannedAmount>().orderByAsc("record_time");
|
if (StringUtils.hasText(type)) {
|
queryWrapper.eq("type", type);
|
}
|
|
if (dayCount != null && dayCount > 0) {
|
Calendar calendar = Calendar.getInstance();
|
calendar.add(Calendar.DAY_OF_MONTH, -dayCount);
|
Date startDate = calendar.getTime();
|
queryWrapper.ge("record_time", startDate);
|
}
|
|
List<PlannedAmount> data = plannedAmountService.list(queryWrapper);
|
|
return Result.build(200, "查询成功", data);
|
}
|
}
|