Pārlūkot izejas kodu

修改饲料返回字段

zhuoning 2 gadi atpakaļ
vecāks
revīzija
e0ece4d16f

+ 3 - 6
huimv-env-platform/huimv-env-produce/src/main/java/com/huimv/env/produce/controller/FeedDayController.java

@@ -5,11 +5,7 @@ import com.huimv.common.utils.Result;
 import com.huimv.env.produce.entity.FeedDay;
 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 org.springframework.web.bind.annotation.*;
 
 import java.text.ParseException;
 import java.util.ArrayList;
@@ -24,6 +20,7 @@ import java.util.Map;
  * @author zn
  * @since 2022-11-03
  */
+@CrossOrigin
 @RestController
 @RequestMapping("/v1.0.0/feed")
 public class FeedDayController {
@@ -31,7 +28,7 @@ public class FeedDayController {
     private FeedDayService feedDayService;
 
     //查询
-    @PostMapping("/getDayFeed")
+    @PostMapping("/getFeedCount")
     public Result getFeedCount(@RequestBody Map<String, String> paramsMap) throws ParseException {
         //
         return feedDayService.getFeedCount(paramsMap);

+ 2 - 5
huimv-env-platform/huimv-env-produce/src/main/java/com/huimv/env/produce/controller/FeedMonthController.java

@@ -5,11 +5,7 @@ import com.huimv.common.utils.Result;
 import com.huimv.env.produce.entity.FeedMonth;
 import com.huimv.env.produce.service.FeedMonthService;
 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 org.springframework.web.bind.annotation.*;
 
 import java.util.List;
 import java.util.Map;
@@ -22,6 +18,7 @@ import java.util.Map;
  * @author zn
  * @since 2022-11-03
  */
+@CrossOrigin
 @RestController
 @RequestMapping("/v1.0.0/feedMonth")
 public class FeedMonthController {

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

@@ -18,7 +18,7 @@ import java.util.Map;
  */
 public interface FeedDayService extends IService<FeedDay> {
 
-    Result getFeedCount(Map<String, String> paramsMap);
+    Result getFeedCount(Map<String, String> paramsMap) throws ParseException;
 
     Result newFeedCount(List<FeedDay> list);
 

+ 26 - 11
huimv-env-platform/huimv-env-produce/src/main/java/com/huimv/env/produce/service/impl/FeedDayServiceImpl.java

@@ -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;
     }