Przeglądaj źródła

新建重要指标试点数据:对百分比进行优化处理。

zhuoning 3 lat temu
rodzic
commit
b6156eb191

+ 80 - 8
huimv-hy-production/huimv.hy.autoGetData/src/main/java/com/huimv/production/autoGetData/service/impl/AutoGetErpDataImpl.java

@@ -707,13 +707,16 @@ public class AutoGetErpDataImpl implements IAutoGetErpData {
                         //////////////////////////////////////////////////////////////////////
                         //重要指标试点
                         //平均窝产仔数 avg_farrow_1
-                        saveImportIndicator(farmId, year, month, pjwczz,"avg_farrow_1","平均窝产仔猪");
+//                        saveImportIndicator(farmId, year, month, df.format(Float.parseFloat(pjwczz)),"avg_farrow_1","平均窝产仔猪");
+                        saveImportIndicator(farmId, year, month, pjwczz, "avg_farrow_1", "平均窝产仔猪");
 
                         //产房成活率 grice_rate
-                        saveImportIndicator(farmId, year, month, cfchl,"grice_rate","产房成活率");
+//                        saveImportIndicator(farmId, year, month, mathUtil.formatBit(Float.parseFloat(cfchl)),"grice_rate","产房成活率");
+                        saveImportIndicator(farmId, year, month, cfchl, "grice_rate", "产房成活率");
 
                         //保育成活率 piglet_rate
-                        saveImportIndicator(farmId, year, month, bychl,"piglet_rate","保育成活率");
+//                        saveImportIndicator(farmId, year, month, mathUtil.formatBit(Float.parseFloat(bychl)),"piglet_rate","保育成活率");
+                        saveImportIndicator(farmId, year, month, bychl, "piglet_rate", "保育成活率");
 
                         //Step2:更新动态统计表
                         updateDynamicCount(farmId, year, month);
@@ -728,13 +731,22 @@ public class AutoGetErpDataImpl implements IAutoGetErpData {
     }
 
     //保存平均窝产仔数 avg_farrow_1、产房成活率 grice_rate、保育成活率 piglet_rate
-    private void saveImportIndicator(Integer farmId, String year, String month, String pjwczz, String type, String title) {
+    private void saveImportIndicator(Integer farmId, String year, String month, String inQuantity, String type, String title) {
         DecimalFormat df = new DecimalFormat("0.00");
-
+        System.out.println("//////////////////////////////////////////////////////////////////////////////////");
+        System.out.println("inQuantity>>" + inQuantity);
         //计算前一个月(年、月)
         Map beforeMonthMap = dateUtil.getBeforeMonth();
-        //计算涨跌和统计动态变化指标数量
-        JSONObject riseFallJo = getBeforeLastMonth(farmId, beforeMonthMap, type, pjwczz);
+
+        //计算涨跌
+        JSONObject riseFallJo = new JSONObject();
+        if (type.trim().equalsIgnoreCase("avg_farrow_1")) {
+            riseFallJo = getBeforeLastMonth(farmId, beforeMonthMap, type, df.format(Float.parseFloat(inQuantity)));
+//            riseFallJo = getBeforeLastMonth(farmId, beforeMonthMap, type, inQuantity);
+        }else{
+//            riseFallJo = getBeforeLastMonth2(farmId, beforeMonthMap, type, mathUtil.formatBit(Float.parseFloat(inQuantity),3));
+            riseFallJo = getBeforeLastMonth2(farmId, beforeMonthMap, type, inQuantity);
+        }
         System.out.println("## riseFallJo>>" + riseFallJo);
 
         //Step1:保存到重要指标
@@ -751,13 +763,18 @@ public class AutoGetErpDataImpl implements IAutoGetErpData {
         addEntity4.setFarmId(farmId);
         addEntity4.setStockType(type);
         addEntity4.setStockName(title);
-        addEntity4.setStockQuantity(df.format(Float.parseFloat(pjwczz)));
+        if (type.trim().equalsIgnoreCase("avg_farrow_1")) {
+            addEntity4.setStockQuantity(df.format(Float.parseFloat(inQuantity)));
+        } else {
+            addEntity4.setStockQuantity(mathUtil.countRate(Float.parseFloat(inQuantity),1)+"%");
+        }
         addEntity4.setMonth(Integer.valueOf(month));
         addEntity4.setYear(Integer.parseInt(year));
         //涨跌
         addEntity4.setRiseFall(riseFallJo.getInteger("rise_fall"));
         //幅度
         addEntity4.setRange1(riseFallJo.getString("range"));
+        System.out.println("addEntity4>>" + addEntity4);
         prodImportantIndicatorRepo.saveAndFlush(addEntity4);
     }
 
@@ -813,6 +830,8 @@ public class AutoGetErpDataImpl implements IAutoGetErpData {
 
     //
     private JSONObject getBeforeLastMonth(Integer farmId, Map beforeMonthMap, String type, String newValue) {
+        System.out.println("##22 newValue>>" + newValue);
+//        df.format(Float.parseFloat(inQuantity))
         String beforeMonth = beforeMonthMap.get("month").toString();
         String beforeYear = beforeMonthMap.get("year").toString();
         //查找前一个月的数据
@@ -825,27 +844,80 @@ public class AutoGetErpDataImpl implements IAutoGetErpData {
 //        List<ProdImportantIndicatorEntity> beforeImportantEntityList = prodImportantIndicatorRepo.findAll(beforeExample);
         Optional<ProdImportantIndicatorEntity> optional = prodImportantIndicatorRepo.findOne(beforeExample);
         JSONObject outJo = new JSONObject();
+        System.out.println("optional.isPresent()>>" + optional.isPresent());
         if (optional.isPresent()) {
+            System.out.println("true");
             ProdImportantIndicatorEntity importantEntity = optional.get();
+            System.out.println(">>importantEntity.getStockQuantity()>>" + importantEntity.getStockQuantity());
             BigDecimal beforeQuantityBd = new BigDecimal(importantEntity.getStockQuantity());
             BigDecimal quantityBd = new BigDecimal(newValue);
             if (quantityBd.compareTo(beforeQuantityBd) == 0) {
                 outJo.put("rise_fall", 1);
                 outJo.put("range", "0");
+                System.out.println("1");
             } else if (quantityBd.compareTo(beforeQuantityBd) == 1) {
                 outJo.put("rise_fall", 1);
                 outJo.put("range", quantityBd.subtract(beforeQuantityBd));
+                System.out.println("2");
             } else {
                 outJo.put("rise_fall", 0);
                 outJo.put("range", beforeQuantityBd.subtract(quantityBd));
+                System.out.println("3");
             }
         } else {
+            System.out.println("false");
             outJo.put("rise_fall", 1);
             outJo.put("range", newValue);
         }
         return outJo;
     }
 
+    //
+    private JSONObject getBeforeLastMonth2(Integer farmId, Map beforeMonthMap, String type, String newValue) {
+        System.out.println("##22 newValue>>" + newValue);
+        newValue = mathUtil.countRate(Float.parseFloat(newValue),1);
+//        mathUtil.formatBit(Float.parseFloat(inQuantity),3)
+        String beforeMonth = beforeMonthMap.get("month").toString();
+        String beforeYear = beforeMonthMap.get("year").toString();
+        //查找前一个月的数据
+        ProdImportantIndicatorEntity findImportantEntity = new ProdImportantIndicatorEntity();
+        findImportantEntity.setYear(Integer.parseInt(beforeYear));
+        findImportantEntity.setMonth(Integer.parseInt(beforeMonth));
+        findImportantEntity.setStockType(type);
+        findImportantEntity.setFarmId(farmId);
+        Example<ProdImportantIndicatorEntity> beforeExample = Example.of(findImportantEntity);
+//        List<ProdImportantIndicatorEntity> beforeImportantEntityList = prodImportantIndicatorRepo.findAll(beforeExample);
+        Optional<ProdImportantIndicatorEntity> optional = prodImportantIndicatorRepo.findOne(beforeExample);
+        JSONObject outJo = new JSONObject();
+        System.out.println("optional.isPresent()>>" + optional.isPresent());
+        if (optional.isPresent()) {
+            System.out.println("true");
+            ProdImportantIndicatorEntity importantEntity = optional.get();
+            System.out.println(">>importantEntity.getStockQuantity()>>" + importantEntity.getStockQuantity());
+            System.out.println(">>newValue>>"+newValue);
+            BigDecimal beforeQuantityBd = new BigDecimal(importantEntity.getStockQuantity().replace("%",""));
+            BigDecimal quantityBd = new BigDecimal(newValue);
+            if (quantityBd.compareTo(beforeQuantityBd) == 0) {
+                outJo.put("rise_fall", 1);
+                outJo.put("range", "0");
+                System.out.println("1");
+            } else if (quantityBd.compareTo(beforeQuantityBd) == 1) {
+                outJo.put("rise_fall", 1);
+                outJo.put("range", mathUtil.countRate(Float.parseFloat(quantityBd.subtract(beforeQuantityBd).toString()),1)+"%");
+                System.out.println("2");
+            } else {
+                outJo.put("rise_fall", 0);
+                outJo.put("range", mathUtil.countRate(Float.parseFloat(beforeQuantityBd.subtract(quantityBd).toString()),1) +"%");
+                System.out.println("3");
+            }
+        } else {
+            System.out.println("false");
+            outJo.put("rise_fall", 1);
+            outJo.put("range", mathUtil.countRate(Float.parseFloat(newValue),1) +"%");
+        }
+        return outJo;
+    }
+
     //读取ERP数据中对应的名称
     private int _getFarmIdByFullName(String pigfarm, List<ProdFarmNameEntity> farmNameEntityList) {
         //