| | |
| | | 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; |
| | |
| | | @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); |
| | | } |
| | | queryWrapper.last("limit 30"); |
| | | |
| | | // 如果指定了天数,则查询最近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); |
| | | |