Bläddra i källkod

填充部分饲料消耗计算代码

zhuoning 2 år sedan
förälder
incheckning
98a90d69e8

+ 17 - 1
huimv-env-platform/huimv-env-produce/src/main/java/com/huimv/env/produce/controller/FeedDayController.java

@@ -1,10 +1,18 @@
 package com.huimv.env.produce.controller;
 
 
+import com.huimv.common.utils.Result;
+import com.huimv.env.produce.service.FeedDayService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 
 import org.springframework.web.bind.annotation.RestController;
 
+import java.text.ParseException;
+import java.util.Map;
+
 /**
  * <p>
  *  前端控制器
@@ -14,8 +22,16 @@ import org.springframework.web.bind.annotation.RestController;
  * @since 2022-11-03
  */
 @RestController
-@RequestMapping("/feed-day")
+@RequestMapping("/v1.0.0/feed")
 public class FeedDayController {
+    @Autowired
+    private FeedDayService feedDayService;
 
+    //查询
+    @PostMapping("/getFeedCount")
+    public Result getFeedCount(@RequestBody Map<String, String> paramsMap) throws ParseException {
+        //
+        return feedDayService.getFeedCount(paramsMap);
+    }
 }
 

+ 4 - 0
huimv-env-platform/huimv-env-produce/src/main/java/com/huimv/env/produce/service/FeedDayService.java

@@ -1,8 +1,11 @@
 package com.huimv.env.produce.service;
 
+import com.huimv.common.utils.Result;
 import com.huimv.env.produce.entity.FeedDay;
 import com.baomidou.mybatisplus.extension.service.IService;
 
+import java.util.Map;
+
 /**
  * <p>
  *  服务类
@@ -13,4 +16,5 @@ import com.baomidou.mybatisplus.extension.service.IService;
  */
 public interface FeedDayService extends IService<FeedDay> {
 
+    Result getFeedCount(Map<String, String> paramsMap);
 }

+ 61 - 0
huimv-env-platform/huimv-env-produce/src/main/java/com/huimv/env/produce/service/impl/FeedDayServiceImpl.java

@@ -1,11 +1,21 @@
 package com.huimv.env.produce.service.impl;
 
+import com.alibaba.fastjson.JSONObject;
+import com.huimv.common.utils.Result;
+import com.huimv.common.utils.ResultCode;
 import com.huimv.env.produce.entity.FeedDay;
 import com.huimv.env.produce.mapper.FeedDayMapper;
+import com.huimv.env.produce.mapper.FeedMonthMapper;
 import com.huimv.env.produce.service.FeedDayService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
 /**
  * <p>
  *  服务实现类
@@ -16,5 +26,56 @@ import org.springframework.stereotype.Service;
  */
 @Service
 public class FeedDayServiceImpl extends ServiceImpl<FeedDayMapper, FeedDay> implements FeedDayService {
+    @Autowired
+    private FeedDayMapper feedDayMapper;
+    @Autowired
+    private FeedMonthMapper feedMonthMapper;
+
+    @Override
+    public Result getFeedCount(Map<String, String> paramsMap) {
+        JSONObject resultJo = new JSONObject();
+        //计算今日消耗量、环比
+        BigDecimal todayCountBd = new BigDecimal(0);
+        BigDecimal todayRatioBd = new BigDecimal(0);
+        // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 这里写代码计算今日消耗量、环比
+
+        //计算本月消耗量、环比
+        BigDecimal thisMonthCountBd = new BigDecimal(0);
+        BigDecimal thisMonthRatioBd = new BigDecimal(0);
+        // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 这里写代码计算本月消耗量、环比
+
+        //计算历史记录
+        List<Map<String,Object>> consumptionList = _getFeedHistoryConsumption(paramsMap);
+
+        //今日消耗量
+        resultJo.put("todayCount",todayCountBd.toString());
+        //今日环比
+        resultJo.put("todayRatio",todayRatioBd.toString());
+        //本月消耗量
+        resultJo.put("thisMonthCount",thisMonthCountBd.toString());
+        //本月环比
+        resultJo.put("thisMonthRatio",thisMonthRatioBd.toString());
+        //每月消耗记录
+        resultJo.put("consumptionList",consumptionList);
+        return new Result(ResultCode.SUCCESS,resultJo);
+    }
+
+    private List<Map<String, 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){
+            //读取N天历史记录,以正序返回
+            //+++++++++++++++++++++++++++++++++++++++++++++++
+
+
+        }else if(months != null && days == null){
+            //读取N月历史记录,以正序返回
+            //+++++++++++++++++++++++++++++++++++++++++++++++
+
 
+        }
+        return consumptionList;
+    }
 }