|
@@ -1,9 +1,12 @@
|
|
|
package com.huimv.env.produce.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.huimv.common.utils.Result;
|
|
|
import com.huimv.common.utils.ResultCode;
|
|
|
+import com.huimv.env.common.utils.DateUtil;
|
|
|
import com.huimv.env.produce.entity.FeedDay;
|
|
|
+import com.huimv.env.produce.entity.FeedMonth;
|
|
|
import com.huimv.env.produce.mapper.FeedDayMapper;
|
|
|
import com.huimv.env.produce.mapper.FeedMonthMapper;
|
|
|
import com.huimv.env.produce.service.FeedDayService;
|
|
@@ -18,7 +21,7 @@ import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
|
- * 服务实现类
|
|
|
+ * 服务实现类
|
|
|
* </p>
|
|
|
*
|
|
|
* @author zn
|
|
@@ -30,50 +33,101 @@ public class FeedDayServiceImpl extends ServiceImpl<FeedDayMapper, FeedDay> impl
|
|
|
private FeedDayMapper feedDayMapper;
|
|
|
@Autowired
|
|
|
private FeedMonthMapper feedMonthMapper;
|
|
|
+ @Autowired
|
|
|
+ private static final String globalFarmCode = "14";
|
|
|
+ @Autowired
|
|
|
+ private DateUtil dateUtil;
|
|
|
+
|
|
|
|
|
|
@Override
|
|
|
public Result getFeedCount(Map<String, String> paramsMap) {
|
|
|
- JSONObject resultJo = new JSONObject();
|
|
|
+
|
|
|
+
|
|
|
//计算今日消耗量、环比
|
|
|
BigDecimal todayCountBd = new BigDecimal(0);
|
|
|
BigDecimal todayRatioBd = new BigDecimal(0);
|
|
|
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 这里写代码计算今日消耗量、环比
|
|
|
+ String farmCode = paramsMap.get("farm_code");
|
|
|
+ if (farmCode == null) {
|
|
|
+ farmCode = globalFarmCode;
|
|
|
+ }
|
|
|
+ String index = paramsMap.get("index");
|
|
|
+ if (index==""||index==null) {
|
|
|
+ index = "6";
|
|
|
+ }
|
|
|
+ QueryWrapper<FeedDay> queryWrapper = new QueryWrapper();
|
|
|
+ queryWrapper.eq("farm_code", farmCode).orderByDesc("id").last("limit ".concat(index));
|
|
|
+ List<FeedDay> feedDays = feedDayMapper.selectList(queryWrapper);
|
|
|
+ if (!feedDays.isEmpty()) {
|
|
|
+ todayCountBd = feedDays.get(0).getConsumption();
|
|
|
+ if (feedDays.size() < 2) {
|
|
|
+ todayRatioBd = BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+ BigDecimal yesterdayCountBd = feedDays.get(1).getConsumption();
|
|
|
+ todayRatioBd = (todayCountBd.subtract(yesterdayCountBd)).divide(yesterdayCountBd);
|
|
|
+ } else {
|
|
|
+ todayCountBd = BigDecimal.ZERO;
|
|
|
+ todayRatioBd = BigDecimal.ZERO;
|
|
|
+ }
|
|
|
|
|
|
//计算本月消耗量、环比
|
|
|
BigDecimal thisMonthCountBd = new BigDecimal(0);
|
|
|
BigDecimal thisMonthRatioBd = new BigDecimal(0);
|
|
|
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 这里写代码计算本月消耗量、环比
|
|
|
+ QueryWrapper<FeedMonth> queryWrapper1 = new QueryWrapper<>();
|
|
|
+ queryWrapper1.eq("farm_code", farmCode).orderByDesc("id").last("limit ".concat(index));
|
|
|
+ List<FeedMonth> feedMonths = feedMonthMapper.selectList(queryWrapper1);
|
|
|
+ if (!feedMonths.isEmpty()) {
|
|
|
+ thisMonthCountBd = feedMonths.get(0).getConsumption();
|
|
|
+ if (feedDays.size() < 2) {
|
|
|
+ thisMonthRatioBd = BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+ BigDecimal LastMonthCountBd = feedDays.get(1).getConsumption();
|
|
|
+ thisMonthRatioBd = (thisMonthRatioBd.subtract(LastMonthCountBd)).divide(LastMonthCountBd);
|
|
|
+ } else {
|
|
|
+ thisMonthCountBd = BigDecimal.ZERO;
|
|
|
+ thisMonthRatioBd = BigDecimal.ZERO;
|
|
|
+ }
|
|
|
|
|
|
+ JSONObject resultJo = new JSONObject();
|
|
|
//计算历史记录
|
|
|
- List<Map<String,Object>> consumptionList = _getFeedHistoryConsumption(paramsMap);
|
|
|
+ List<Object> consumptionList = _getFeedHistoryConsumption(paramsMap);
|
|
|
|
|
|
//今日消耗量
|
|
|
- resultJo.put("todayCount",todayCountBd.toString());
|
|
|
+ resultJo.put("todayCount", todayCountBd.toString());
|
|
|
//今日环比
|
|
|
- resultJo.put("todayRatio",todayRatioBd.toString());
|
|
|
+ resultJo.put("todayRatio", todayRatioBd.toString());
|
|
|
//本月消耗量
|
|
|
- resultJo.put("thisMonthCount",thisMonthCountBd.toString());
|
|
|
+ resultJo.put("thisMonthCount", thisMonthCountBd.toString());
|
|
|
//本月环比
|
|
|
- resultJo.put("thisMonthRatio",thisMonthRatioBd.toString());
|
|
|
+ resultJo.put("thisMonthRatio", thisMonthRatioBd.toString());
|
|
|
//每月消耗记录
|
|
|
- resultJo.put("consumptionList",consumptionList);
|
|
|
- return new Result(ResultCode.SUCCESS,resultJo);
|
|
|
+ resultJo.put("consumptionList", consumptionList);
|
|
|
+ return new Result(ResultCode.SUCCESS, resultJo);
|
|
|
}
|
|
|
|
|
|
- private List<Map<String, Object>> _getFeedHistoryConsumption(Map<String, String> paramsMap) {
|
|
|
+ private List<Object> _getFeedHistoryConsumption(Map<String, String> paramsMap) {
|
|
|
String months = paramsMap.get("months");
|
|
|
String days = paramsMap.get("days");
|
|
|
-
|
|
|
- List<Map<String, Object>> consumptionList = new ArrayList<>();
|
|
|
- if(months == null && days != null){
|
|
|
+ String farmCode = paramsMap.get("farm_code");
|
|
|
+ if (farmCode == null) {
|
|
|
+ farmCode = globalFarmCode;
|
|
|
+ }
|
|
|
+ List<Object> consumptionList = new ArrayList<>();
|
|
|
+ if (months == null && days != null) {
|
|
|
//读取N天历史记录,以正序返回
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
-
|
|
|
-
|
|
|
- }else if(months != null && days == null){
|
|
|
+ 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);
|
|
|
+ } 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);
|
|
|
|
|
|
}
|
|
|
return consumptionList;
|