Bläddra i källkod

修改查询每月数据接口

523096025 2 år sedan
förälder
incheckning
10882a0074

+ 8 - 3
huimv-hy-production/huimv.hy.autoGetData/src/main/java/com/huimv/production/autoGetData/config/SaticScheduleTask.java

@@ -8,6 +8,7 @@ import org.springframework.scheduling.annotation.EnableScheduling;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.scheduling.annotation.SchedulingConfigurer;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RestController;
 
 import java.io.IOException;
@@ -158,9 +159,11 @@ public class SaticScheduleTask  {
     private void getSales() throws IOException, ParseException {
         System.out.println("");
         //读取销售数据
-        iAutoGetErpData.getSales();
-        //读取销售金额和销售数量
-        iAutoGetErpData.getSalesMoney();
+//        iAutoGetErpData.getSales();
+//        //读取销售金额和销售数量
+//        iAutoGetErpData.getSalesMoney();
+
+        iAutoGetErpData.getPlay();
     }
 
     @Scheduled(cron = "0 8 * * * ?  ")
@@ -169,4 +172,6 @@ public class SaticScheduleTask  {
         //读取多个牧场的PSY
         iAutoGetErpData.getManyFarmPsy();
     }
+
+
 }

+ 7 - 0
huimv-hy-production/huimv.hy.autoGetData/src/main/java/com/huimv/production/autoGetData/controller/DataControll.java

@@ -3,6 +3,7 @@ package com.huimv.production.autoGetData.controller;
 import com.huimv.production.autoGetData.service.IAutoGetErpData;
 import com.huimv.production.autoGetData.service.impl.AutoGetErpDataImpl;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RestController;
@@ -47,4 +48,10 @@ public class DataControll {
         //
         autoGetErpData.getCostWithManyFarm();
     }
+    @GetMapping(value = "/getPlay")
+    public void getPlay() throws IOException, ParseException {
+        //
+        autoGetErpData.getPlay();
+    }
+
 }

+ 2 - 0
huimv-hy-production/huimv.hy.autoGetData/src/main/java/com/huimv/production/autoGetData/service/IAutoGetErpData.java

@@ -54,4 +54,6 @@ public interface IAutoGetErpData {
     void testGetManyFarmPsy() throws IOException;
 
     void getSalesMoney() throws ParseException, IOException;
+
+    void getPlay() throws ParseException, IOException;
 }

+ 130 - 0
huimv-hy-production/huimv.hy.autoGetData/src/main/java/com/huimv/production/autoGetData/service/impl/AutoGetErpDataImpl.java

@@ -1987,6 +1987,136 @@ public class AutoGetErpDataImpl implements IAutoGetErpData {
     }
 
     @Override
+    public void getPlay() throws IOException, ParseException {
+        String todayText = dateUtil.getTodayDateText();
+        List<ProdFarmNameEntity> farmNameEntityList = prodFarmNameRepo.findAll();
+        Map<String, String> paramsMap = new HashMap<String, String>();
+        for (ProdFarmNameEntity farmNameEntity : farmNameEntityList) {
+            if (null != farmNameEntity.getErpFarmId()) {
+                System.out.println("" + farmNameEntity.getErpShortName());
+                //
+                paramsMap.put("farmID", farmNameEntity.getErpFarmId());
+                System.out.println("" + farmNameEntity.getErpFarmName() + " , " + farmNameEntity.getErpFarmId());
+                paramsMap.put("farmCode", farmNameEntity.getErpFarmId());
+                String url = apiIp + apiPort + serviceName + "/getSales2";
+                log.info("销售数据接口访问地址=" + url);
+                log.info("业务请求参数=" + paramsMap.toString());
+                log.info("开始取数=" + new Date(System.currentTimeMillis()));
+                //
+                JSONObject outJo = httpClientUtil.doGet(url, paramsMap);
+                if (outJo.getBoolean("status")) {
+                    JSONObject contentJo = outJo.getJSONObject("content");
+                    if (contentJo.getBoolean("success")) {
+//                        String data = contentJo.getString("data");
+//                        JSONArray dataJa = contentJo.getJSONArray("data");
+                        JSONArray dataJo = contentJo.getJSONArray("data");
+                        if (dataJo.size() == 0) {
+                            log.info("未取到数据 。");
+                        } else {
+                            BigDecimal totalBg = new BigDecimal(0);
+                            BigDecimal totalMoneyBg = new BigDecimal(0);
+
+                            BigDecimal totalBg1 = new BigDecimal(0);
+                            BigDecimal totalMoneyBg1 = new BigDecimal(0);
+
+                            String todayTotal1 ="0";
+                            String  todaySaleMoney1="0";
+                            for(int b=0;b<dataJo.size();b++) {
+                                List<Object> dataList = (List<Object>)dataJo.get(b);
+                                if (todayText.equals(dataList.get(2))){
+                                    if(  dataList.get(7) != null) {
+                                        todayTotal1 =dataList.get(7)+"";
+                                    }
+                                    if(   dataList.get(9) != null) {
+                                        todaySaleMoney1 =  dataList.get(9)+"";
+                                    }
+                                    totalMoneyBg1 = totalMoneyBg1.add(new BigDecimal(todaySaleMoney1));
+                                    totalBg1 = totalBg1.add(new BigDecimal(todayTotal1));
+                                }
+
+
+                                String todayTotal ="0";
+                                String  todaySaleMoney ="0";
+                                if(  dataList.get(7) != null) {
+                                    todayTotal =dataList.get(7)+"";
+                                }
+                                if(   dataList.get(9) != null) {
+                                    todaySaleMoney =  dataList.get(9)+"";
+                                }
+
+                                totalMoneyBg = totalMoneyBg.add(new BigDecimal(todaySaleMoney));
+                                totalBg = totalBg.add(new BigDecimal(todayTotal));
+                            }
+
+                            ProdSalesEntity salesEntity = new ProdSalesEntity();
+                            salesEntity.setAddDate(DateUtil.parse(todayText, "yyyy-MM-dd"));
+                            salesEntity.setFarmId(farmNameEntity.getFarmId());
+                            Example<ProdSalesEntity> example = Example.of(salesEntity);
+                            Optional<ProdSalesEntity> optional = salesRepo.findOne(example);
+                            if(optional.isPresent()){
+                                ProdSalesEntity prodSalesEntity = optional.get();
+                                prodSalesEntity.setTodayQuantity(totalBg1+"");
+                                prodSalesEntity.setTodayMoney(totalMoneyBg1+"");
+                                salesRepo.save(prodSalesEntity);
+                            }
+
+
+                            ProdSalesEntity salesEntity1 = new ProdSalesEntity();
+                            salesEntity1.setAddDate(DateUtil.parse(todayText, "yyyy-MM-dd"));
+                            salesEntity1.setFarmId(farmNameEntity.getFarmId());
+                            Example<ProdSalesEntity> example1 = Example.of(salesEntity1);
+                            Optional<ProdSalesEntity> optional1 = salesRepo.findOne(example1);
+                            if(optional1.isPresent()){
+                                ProdSalesEntity prodSalesEntity = optional.get();
+                                prodSalesEntity.setMonthMoney(totalMoneyBg+"");
+                                prodSalesEntity.setMonthQuantity(totalBg+"");
+                                salesRepo.save(prodSalesEntity);
+                            }
+
+                        }
+                    }
+                }
+
+        }
+
+
+//        for(int a=0;a<payableList.size();a++) {
+//            Object[] salesObj = (Object[]) payableList.get(a);
+////            System.out.println("salesObj.length="+salesObj.length);
+//            JSONObject saleJo = new JSONObject();
+//            saleJa.add(saleJo);
+//            //牧场名称
+//            saleJo.put("f00", salesObj[0]);
+//            saleJo.put("f01", salesObj[1]);
+//            saleJo.put("f02", salesObj[2]);
+//            saleJo.put("f03", salesObj[3]);
+//            saleJo.put("f04", salesObj[4]);
+//            saleJo.put("f05", salesObj[5]);
+//            saleJo.put("f06", salesObj[6]);
+//            saleJo.put("f07", salesObj[7]);
+//            saleJo.put("f08", salesObj[8]);
+//            saleJo.put("f09", salesObj[9]);
+//            saleJo.put("f10", salesObj[10]);
+//            saleJo.put("f11", salesObj[11]);
+//            saleJo.put("f12", salesObj[12]);
+//            saleJo.put("f13", salesObj[13]);
+//            saleJo.put("f14", salesObj[14]);
+//            saleJo.put("f15", salesObj[15]);
+//            saleJo.put("f16", salesObj[16]);
+//            String saleMoney = "0";
+//            if(salesObj[9] != null){
+//                saleMoney = salesObj[9] + "";
+//            }
+//            String total = "0";
+//            if(salesObj[7] != null){
+//                total = salesObj[7] + "";
+//            }
+
+        }
+
+    }
+
+    @Override
     public void getManyFarmPsy() throws IOException, InterruptedException {
         //
         Map timeoutMap = httpClientUtil.setTimeout(connectTimeout, requestTimeout, socketTimeout);

+ 3 - 3
huimv-hy-production/huimv.hy.erp.datasource/src/main/java/com/huimv/production/datasource/service/impl/ErpDataServiceImpl.java

@@ -701,7 +701,7 @@ public class ErpDataServiceImpl implements IErpDataService {
 //        List<Object[]> payableList = tDeliveryRepo.getSalesTest(farmCode);
         List<Object[]> payableList = tDeliveryRepo.getSales2(farmCode);
         JSONArray saleJa = new JSONArray();
-        BigDecimal totalBg = new BigDecimal(0);
+       /* BigDecimal totalBg = new BigDecimal(0);
         BigDecimal totalMoneyBg = new BigDecimal(0);
         for(int a=0;a<payableList.size();a++) {
             Object[] salesObj = (Object[]) payableList.get(a);
@@ -741,8 +741,8 @@ public class ErpDataServiceImpl implements IErpDataService {
 //        return new Result(ResultCode.SUCCESS,saleJa);
         JSONObject resultJo = new JSONObject();
         resultJo.put("totalMoney",totalMoneyBg.toString());
-        resultJo.put("sum",totalBg.toString());
-        return new Result(ResultCode.SUCCESS,resultJo);
+        resultJo.put("sum",totalBg.toString());*/
+        return new Result(ResultCode.SUCCESS,payableList);
     }
 
 }