소스 검색

增加地磅称重接口unit1参数

zhuoning 2 년 전
부모
커밋
c80d809921

+ 5 - 6
huimv-farm-produce/src/main/java/com/huimv/produce/produce/controller/WeightController.java

@@ -28,11 +28,11 @@ public class WeightController {
     @Autowired
     private DateUtil dateUtil;
 
-//    @RequestMapping(value = "/getEggWeightDetails")
-//    public Result getEggWeightDetails() throws ParseException {
-//        //
-//        return weight.getEggWeightDetails();
-//    }
+    @RequestMapping(value = "/getEggWeightDetails")
+    public Result getEggWeightDetails(@RequestParam(value = "date",required = true) String date) throws ParseException {
+        //
+        return weight.getEggWeightDetails(date);
+    }
 
     // 读取前N天的记录
     @GetMapping("/getManyDayWeight")
@@ -66,7 +66,6 @@ public class WeightController {
         return weight.getWeightDetails(poundType, carNumber,consigner,consignee,variety,startDate2 ,endDate2,pageNo,pageSize);
     }
 
-
     //指定查询日期期间
     @RequestMapping(value = "/getWeight")
     public Result getDayWeight(@RequestParam(value = "farmId", required = true) Integer farmId, @RequestParam(value = "startDate", required = true) String startDate, @RequestParam(value = "endDate", required = true) String endDate) {

+ 3 - 0
huimv-farm-produce/src/main/java/com/huimv/produce/produce/entity/ProdWeightDetailsEntity.java

@@ -88,4 +88,7 @@ public class ProdWeightDetailsEntity implements Serializable {
     @Column(name = "weighing_type")
     private String weighingType;
 
+    @Column(name = "unit1")
+    private String unit1;
+
 }

+ 3 - 1
huimv-farm-produce/src/main/java/com/huimv/produce/produce/service/IWeight.java

@@ -9,7 +9,9 @@ import java.util.Date;
 
 public interface IWeight {
 
-    Result getEggWeightDetails() throws ParseException;
+    Result getEggWeightDetails(String todayDate) throws ParseException;
+
+    Result autoGenerateDayWeight() throws ParseException;
 
     //查询称重
     Result getDayWeight(Integer farmId, String startDate, String endDate);

+ 38 - 26
huimv-farm-produce/src/main/java/com/huimv/produce/produce/service/impl/WeightImpl.java

@@ -60,16 +60,39 @@ public class WeightImpl implements IWeight {
     private String weightPath;
 
     @Override
-    public Result getEggWeightDetails() throws ParseException {
+    public Result getEggWeightDetails(String todayDate) throws ParseException {
+//        String url = "http://39.171.45.196:9200/egg/getWeightDetails?date=2022-06-10";
+//        String url = "http://39.171.45.196:9200/egg/getWeightDetails";
+
+        // 获取今天数据
+        if(StringUtils.isBlank(todayDate)){
+            todayDate = new DateUtil().getTodayDateText();
+        }
+        String url = weightHttp + weightPath + "?date=" + todayDate;
+        System.out.println("url=" + url);
+        String result = restTemplate.getForObject(url, String.class);
+        JSONArray resultJa = JSONArray.parseArray(result);
+        log.info("接口返回数量=" + resultJa.size());
+
+        // 保存每天明细
+        saveWeightDetails(resultJa, todayDate);
+
+        // 保存汇总每天总重
+        saveDayWeight(resultJa, todayDate);
+
+        return new Result(ResultCode.SUCCESS);
+    }
+
+    @Override
+    public Result autoGenerateDayWeight() throws ParseException {
 //        String url = "http://39.171.45.196:9200/egg/getWeightDetails?date=2022-06-10";
 //        String url = "http://39.171.45.196:9200/egg/getWeightDetails";
 
         // 获取今天数据
         String todayDate = new DateUtil().getTodayDateText();
         // test
-//        String todayDate = "2022-06-10";
-        String url = weightHttp + weightPath;
-        url += "?date=" + todayDate;
+//        todayDate = "2022-06-11";
+        String url = weightHttp + weightPath + "?date=" + todayDate;
         System.out.println("url=" + url);
         String result = restTemplate.getForObject(url, String.class);
         JSONArray resultJa = JSONArray.parseArray(result);
@@ -84,6 +107,8 @@ public class WeightImpl implements IWeight {
         return new Result(ResultCode.SUCCESS);
     }
 
+
+
     /**
      * @Method : saveDayWeight
      * @Description :
@@ -111,6 +136,7 @@ public class WeightImpl implements IWeight {
         List<ProdWeightDayEntity> ProdWeightDayEntityList = getDayWeightList(todayDate);
         prodWeightDayRepo.deleteAll(ProdWeightDayEntityList);
 
+        // 添加采购每日汇总
         if(purchaseJa.size()>0){
             BigDecimal grossTotalPurchaseBg = new BigDecimal("0");
             BigDecimal tareTotalPurchaseBg = new BigDecimal("0");
@@ -134,7 +160,6 @@ public class WeightImpl implements IWeight {
                 }
                 netTotalPurchaseBg = netTotalPurchaseBg.add(nw);
             }
-
             ProdWeightDayEntity purchaseWeightDayEntity = new ProdWeightDayEntity();
             purchaseWeightDayEntity.setAddDate(new java.sql.Date(dateUtil.parseDate(todayDate).getTime()));
             purchaseWeightDayEntity.setGrossWeight(grossTotalPurchaseBg.floatValue());
@@ -144,13 +169,14 @@ public class WeightImpl implements IWeight {
             prodWeightDayRepo.save(purchaseWeightDayEntity);
         }
 
+        // 添加销售每日汇总
         if(salesJa.size()>0){
             BigDecimal grossTotalSalesBg = new BigDecimal("0");
             BigDecimal tareTotalSalesBg = new BigDecimal("0");
             BigDecimal netTotalSalesBg = new BigDecimal("0");
             for (int a = 0; a < salesJa.size(); a++) {
                 JSONObject salesJo = salesJa.getJSONObject(a);
-//            System.out.println("" + salesJo.getBigDecimal("grossWeight") + " " + salesJo.getBigDecimal("tareWeight") + " " + salesJo.getBigDecimal("netWeight"));
+            System.out.println("" + salesJo.getBigDecimal("grossWeight") + " " + salesJo.getBigDecimal("tareWeight") + " " + salesJo.getBigDecimal("netWeight"));
                 BigDecimal gw = salesJo.getBigDecimal("grossWeight");
                 if (gw == null) {
                     gw = new BigDecimal("0");
@@ -192,27 +218,13 @@ public class WeightImpl implements IWeight {
      * @Time : 4:03
      */
     private void saveWeightDetails(JSONArray resultJa, String todayDate) throws ParseException {
-        // 读取每天的一个称重数据
+        // 删除每天历史记录
         List<ProdWeightDetailsEntity> existEntityList = getTodayWeightDetails(todayDate);
-        System.out.println("今天已经取回数量=" + existEntityList.size());
-        JSONArray dataJa = new JSONArray();
+        System.out.println("今天历史记录数量=" + existEntityList.size());
+        prodWeightDetailsRepo.deleteAll(existEntityList);
+
         for (int a = 0; a < resultJa.size(); a++) {
-            JSONObject resultJo = resultJa.getJSONObject(a);
-            boolean isExist = false;
-            for (ProdWeightDetailsEntity weightDetailsEntity : existEntityList) {
-                if (weightDetailsEntity.getSerialNumber().equalsIgnoreCase(resultJo.getString("serialNumber"))) {
-                    isExist = true;
-                    break;
-                }
-            }
-            if (!isExist) {
-                dataJa.add(resultJo);
-            }
-        }
-        System.out.println("dataJa.size=" + dataJa.size());
-        for (int a = 0; a < dataJa.size(); a++) {
-            System.out.println("" + (a + 1));
-            JSONObject dataJo = dataJa.getJSONObject(a);
+            JSONObject dataJo = resultJa.getJSONObject(a);
             ProdWeightDetailsEntity prodWeightDetailsEntity = new ProdWeightDetailsEntity();
             prodWeightDetailsEntity.setSerialNumber(dataJo.getString("serialNumber"));
             prodWeightDetailsEntity.setCarNumber(dataJo.getString("carNumber"));
@@ -231,6 +243,7 @@ public class WeightImpl implements IWeight {
             prodWeightDetailsEntity.setWeighingTime(new java.sql.Date(new DateUtil().parseDateTime(dataJo.getString("weighingTime")).getTime()));
             prodWeightDetailsEntity.setWeighingType(dataJo.getString("weighingType"));
             prodWeightDetailsEntity.setAddDate(new Timestamp(new Date().getTime()));
+            prodWeightDetailsEntity.setUnit1(dataJo.getString("unit1"));
             prodWeightDetailsRepo.save(prodWeightDetailsEntity);
         }
     }
@@ -620,7 +633,6 @@ public class WeightImpl implements IWeight {
 //            if (null != deliverState) {
 //                predList.add(criteriaBuilder.equal(root.get("deliverState").as(Integer.class), deliverState));
 //            }
-            System.out.println("predList.size()="+predList.size());
             //
             Predicate[] pred = new Predicate[predList.size()];
             Predicate and = criteriaBuilder.and(predList.toArray(pred));

+ 1 - 1
huimv-farm-produce/src/main/java/com/huimv/produce/task/MyScheduledTask.java

@@ -23,6 +23,6 @@ public class MyScheduledTask {
     @Scheduled(cron = "0 0/10 * * * ?")
 //    @Scheduled(cron = "0/10 * * * * ?")
     public void scheduledTask1() throws ParseException {
-        iWeight.getEggWeightDetails();
+        iWeight.autoGenerateDayWeight();
     }
 }