|
@@ -2,6 +2,7 @@ package com.huimv.env.produce.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.alibaba.fastjson.serializer.BigDecimalCodec;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.huimv.common.utils.Result;
|
|
|
import com.huimv.common.utils.ResultCode;
|
|
@@ -40,7 +41,7 @@ public class FeedDayServiceImpl extends ServiceImpl<FeedDayMapper, FeedDay> impl
|
|
|
|
|
|
|
|
|
@Override
|
|
|
- public Result getFeedCount(Map<String, String> paramsMap) {
|
|
|
+ public Result getFeedCount(Map<String, String> paramsMap) throws ParseException {
|
|
|
|
|
|
|
|
|
//计算今日消耗量、环比
|
|
@@ -65,7 +66,7 @@ public class FeedDayServiceImpl extends ServiceImpl<FeedDayMapper, FeedDay> impl
|
|
|
}
|
|
|
if (feedDays.size()>=2) {
|
|
|
BigDecimal yesterdayCountBd = feedDays.get(1).getConsumption();
|
|
|
- todayRatioBd = (todayCountBd.subtract(yesterdayCountBd)).divide(yesterdayCountBd,1,BigDecimal.ROUND_HALF_UP);
|
|
|
+ todayRatioBd = (todayCountBd.subtract(yesterdayCountBd)).divide(yesterdayCountBd,3,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100)).setScale(1, BigDecimal.ROUND_HALF_UP);
|
|
|
}
|
|
|
} else {
|
|
|
todayCountBd = BigDecimal.ZERO;
|
|
@@ -86,7 +87,7 @@ public class FeedDayServiceImpl extends ServiceImpl<FeedDayMapper, FeedDay> impl
|
|
|
}
|
|
|
if (feedMonths.size()>=2) {
|
|
|
BigDecimal LastMonthCountBd = feedMonths.get(1).getConsumption();
|
|
|
- thisMonthRatioBd = (thisMonthCountBd.subtract(LastMonthCountBd)).divide(LastMonthCountBd,1,BigDecimal.ROUND_HALF_UP);
|
|
|
+ thisMonthRatioBd = (thisMonthCountBd.subtract(LastMonthCountBd)).divide(LastMonthCountBd,3,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100)).setScale(1, BigDecimal.ROUND_HALF_UP);
|
|
|
}
|
|
|
} else {
|
|
|
thisMonthCountBd = BigDecimal.ZERO;
|
|
@@ -163,7 +164,7 @@ public class FeedDayServiceImpl extends ServiceImpl<FeedDayMapper, FeedDay> impl
|
|
|
}
|
|
|
|
|
|
|
|
|
- private List<Object> _getFeedHistoryConsumption(Map<String, String> paramsMap) {
|
|
|
+ private List<Object> _getFeedHistoryConsumption(Map<String, String> paramsMap) throws ParseException {
|
|
|
String months = paramsMap.get("months");
|
|
|
String days = paramsMap.get("days");
|
|
|
String farmCode = paramsMap.get("farm_code");
|
|
@@ -171,21 +172,35 @@ public class FeedDayServiceImpl extends ServiceImpl<FeedDayMapper, FeedDay> impl
|
|
|
farmCode = globalFarmCode;
|
|
|
}
|
|
|
List<Object> consumptionList = new ArrayList<>();
|
|
|
+ DateUtil dateUtil = new DateUtil();
|
|
|
if (months == null && days != null) {
|
|
|
//读取N天历史记录,以正序返回
|
|
|
- //+++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
QueryWrapper<FeedDay> queryWrapper = new QueryWrapper<>();
|
|
|
queryWrapper.eq("farm_code", farmCode).orderByAsc("id").last("limit ".concat(days));
|
|
|
- List<FeedDay> feedDays = feedDayMapper.selectList(queryWrapper);
|
|
|
- consumptionList.addAll(feedDays);
|
|
|
+ List<FeedDay> feedDaysList = feedDayMapper.selectList(queryWrapper);
|
|
|
+ JSONArray dayListJa = new JSONArray();
|
|
|
+ for(int a=0;a<feedDaysList.size();a++){
|
|
|
+ FeedDay feedDay = feedDaysList.get(a);
|
|
|
+ JSONObject newJo = new JSONObject();
|
|
|
+ dayListJa.add(newJo);
|
|
|
+ newJo.put("datetime",dateUtil.formatDateText(feedDay.getAddDate()));
|
|
|
+ newJo.put("water",feedDay.getConsumption());
|
|
|
+ }
|
|
|
+ consumptionList.addAll(dayListJa);
|
|
|
} else if (months != null && days == null) {
|
|
|
//读取N月历史记录,以正序返回
|
|
|
- //+++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
QueryWrapper<FeedMonth> queryWrapper2 = new QueryWrapper<>();
|
|
|
queryWrapper2.eq("farm_code", farmCode).orderByAsc("id").last("limit ".concat(months));
|
|
|
- List<FeedMonth> feedMonths = feedMonthMapper.selectList(queryWrapper2);
|
|
|
- consumptionList.addAll(feedMonths);
|
|
|
-
|
|
|
+ List<FeedMonth> feedMonthsList = feedMonthMapper.selectList(queryWrapper2);
|
|
|
+ JSONArray monthListJa = new JSONArray();
|
|
|
+ for(int a=0;a<feedMonthsList.size();a++){
|
|
|
+ FeedMonth feedMonth = feedMonthsList.get(a);
|
|
|
+ JSONObject newJo = new JSONObject();
|
|
|
+ monthListJa.add(newJo);
|
|
|
+ newJo.put("datetime",feedMonth.getYear()+"-"+feedMonth.getMonth());
|
|
|
+ newJo.put("water",feedMonth.getConsumption());
|
|
|
+ }
|
|
|
+ consumptionList.addAll(monthListJa);
|
|
|
}
|
|
|
return consumptionList;
|
|
|
}
|