소스 검색

Merge branch 'master' of E:\Work\WorkItems\smart-city\git0617\water-iot with conflicts.

zhoujiangyuan 4 년 전
부모
커밋
0febe0291f

+ 72 - 0
gydatasync/src/main/java/com/huaxu/gydatasync/service/ReadMeter.java

@@ -0,0 +1,72 @@
+package com.huaxu.gydatasync.service;
+
+import com.huaxu.gydatasync.dao.mssql.SaveMeterDataDao;
+import com.huaxu.gydatasync.dao.mysql.ReadMeterDao;
+import com.huaxu.gydatasync.entity.MeterReadData;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.scheduling.annotation.Schedules;
+import org.springframework.stereotype.Component;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * @Author: ZJY
+ * @DATE: 2020-07-17 15:42
+ */
+@Component
+public class ReadMeter {
+
+    @Autowired
+    private ReadMeterDao readMeterDao;
+
+    @Autowired
+    private SaveMeterDataDao saveMeterDataDao;
+
+
+    //间隔x小时
+    //@Scheduled(cron = "* * 7 * * ?")
+    @Scheduled(fixedRate = 1000*60*60*24)
+    public void configureTasks(){
+        try {
+
+            int isExist = saveMeterDataDao.IsExist();
+            if(isExist > 0)
+            {
+
+                System.out.println("当天数据已存在!-----");
+                return;
+            }
+
+
+            //读取前一天的抄表数据
+            List<MeterReadData> meterReadDataList = readMeterDao.getAllList();
+
+            //插入到中间数据库表中
+            if(meterReadDataList != null)
+            {
+                int count = meterReadDataList.size();
+
+                int constNumber= 100; //一次插入100条记录 参数限制不能同时全部插入
+                int number  = count / constNumber + (count % constNumber>0 ? 1 : 0);
+                for (int i = 0;i<number;i++)
+                {
+                    int l = i+1;
+                    int copyNumber = count - l*constNumber >0 ?constNumber:count % constNumber;
+                    List<MeterReadData> subDataList = new ArrayList<>(constNumber);
+                    subDataList.addAll(meterReadDataList.subList(i*constNumber,i*constNumber + copyNumber ));
+
+                    saveMeterDataDao.SaveData(subDataList);
+                }
+            }
+        }
+        catch (Exception ex)
+        {
+
+        }
+
+    }
+}

+ 39 - 0
smart-city-platform/src/main/java/com/bz/smart_city/service/impl/pay/AmountSynByDayServiceImpl.java

@@ -24,7 +24,11 @@ import com.bz.smart_city.service.pay.AmountSynService;
 import com.google.common.collect.Lists;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.InitializingBean;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.data.mongodb.core.MongoTemplate;
+import org.springframework.data.mongodb.core.query.Criteria;
+import org.springframework.data.mongodb.core.query.Query;
 import org.springframework.stereotype.Component;
 
 import javax.annotation.Resource;
@@ -33,6 +37,7 @@ import java.math.BigInteger;
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
 import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
 import java.util.*;
 
 /**
@@ -58,6 +63,9 @@ public class AmountSynByDayServiceImpl implements AmountSynByDayService, Initial
     @Resource
     private JobAndTriggerService jobAndTriggerService;
 
+    @Autowired
+    private MongoTemplate mongoTemplate;
+
     @Override
     public void afterPropertiesSet() {
         saveQrtzTask();
@@ -124,12 +132,43 @@ public class AmountSynByDayServiceImpl implements AmountSynByDayService, Initial
             //获取同步数据
             HashMap<BigInteger, MeterReadRecordDto> meterReadRecordHashMap = new HashMap<>();
 
+/*          //使用mysql数据----------------------------------<
             List<List<BigInteger>> lists = Lists.partition(idList, 500);
             for (List<BigInteger> bigIntegers :
                     lists) {
                 HashMap<BigInteger, MeterReadRecordDto> childMap = amountWaterUsedAmountMapper.getMeterReadRecord(idList);
                 meterReadRecordHashMap.putAll(childMap);
             }
+            //----------------------------------------------->
+            */
+
+            //使用mongodb数据-------------------------<
+            Query query = new Query();
+            DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyyMMdd");
+            LocalDateTime time = LocalDateTime.now();
+            time = time.plusDays(-1);
+            String localTime = df.format(time);
+            Integer rDate = new Integer(localTime);
+
+            Criteria criteria = new Criteria();
+            criteria.and("readDate").is(rDate);
+            criteria.and("siteId").is(siteId);
+            criteria.and("customerId").is(customerId);
+
+            query.addCriteria(criteria);
+            query.fields().include("deviceId");
+            query.fields().include("readDate");
+            query.fields().include("readData");
+            query.fields().exclude("_id");
+            List<MeterReadRecordDto> childMap = mongoTemplate.find(query,MeterReadRecordDto.class,"sc_meter_read_record");
+
+            if(childMap.size() > 0){
+                for (int i=0;i<childMap.size();i++){
+                    meterReadRecordHashMap.put(childMap.get(i).getDeviceId(),childMap.get(i));
+                }
+            }
+            //---------------------------------------->
+
             if(meterReadRecordHashMap.size()>0) {
                 //批量更新水量信息
                 List<AmountWaterUsedAmountByDay> updates = new ArrayList<>();

+ 62 - 1
smart-city-platform/src/main/java/com/bz/smart_city/service/impl/pay/PaySysDictServiceImpl.java

@@ -2,19 +2,27 @@ package com.bz.smart_city.service.impl.pay;
 
 import com.bz.smart_city.commom.exception.ServiceException;
 import com.bz.smart_city.commom.model.Pagination;
-import com.bz.smart_city.commom.model.ResultStatus;
 import com.bz.smart_city.commom.util.UserUtil;
+import com.bz.smart_city.dao.pay.AmountWaterUsedAmountMapper;
 import com.bz.smart_city.dao.pay.PaySysDictMapper;
 import com.bz.smart_city.dto.LoginUser;
+import com.bz.smart_city.dto.pay.MeterReadRecordDto;
 import com.bz.smart_city.dto.pay.PaySysDictSelectDto;
 import com.bz.smart_city.entity.pay.PaySysDict;
 import com.bz.smart_city.service.pay.PaySysDictService;
 import com.github.pagehelper.PageHelper;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.mongodb.core.MongoTemplate;
+import org.springframework.data.mongodb.core.query.Criteria;
+import org.springframework.data.mongodb.core.query.Query;
 import org.springframework.stereotype.Service;
+import java.time.format.*;
 
 import javax.annotation.Resource;
 import java.math.BigInteger;
 import java.time.LocalDateTime;
+import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 
 /**
@@ -26,6 +34,11 @@ public class PaySysDictServiceImpl implements PaySysDictService {
     @Resource
     PaySysDictMapper paySysDictMapper;
 
+    @Autowired
+    private MongoTemplate mongoTemplate;
+    @Resource
+    private AmountWaterUsedAmountMapper amountWaterUsedAmountMapper;
+
     @Override
     public Pagination<PaySysDictSelectDto> getAll(String value, String label ,String type, int pageNum, int pageSize)
     {
@@ -73,10 +86,58 @@ public class PaySysDictServiceImpl implements PaySysDictService {
     public List<String> findAllType()
     {
         LoginUser loginUser = UserUtil.getCurrentUser();
+
+        //测试
+        loginUser.setCustomerId(11);
+
         BigInteger customerId = new BigInteger(String.valueOf(loginUser.getCustomerId()));
         BigInteger siteId = new BigInteger(String.valueOf(loginUser.getSiteId()));
 
         List<String> stringList = paySysDictMapper.findAllType(siteId,customerId);
+        //----------测试mongotemp------------<
+        Query query = new Query();
+
+        HashMap<BigInteger, MeterReadRecordDto> meterReadRecordHashMap = new HashMap<>();
+
+        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyyMMdd");
+        LocalDateTime time = LocalDateTime.now();
+        time = time.plusDays(-1);
+        String localTime = "20200531";//df.format(time);
+        Integer readDate = new Integer(localTime);
+
+        Integer sd = new Integer(1);
+        Integer cd = new Integer(3);;
+        Criteria criteria = new Criteria();
+        criteria.and("readDate").is(readDate);
+        criteria.and("siteId").is(sd);
+        criteria.and("customerId").is(cd);
+        //Criteria selCtr = Criteria.where("readDate").is(20200531);
+
+        //in操作
+        ArrayList<String> listVa = new ArrayList<>();
+/*        listVa.add(new BigInteger("705506563531603968"));
+        listVa.add(new BigInteger("705506562667577344"));
+        listVa.add(new BigInteger("705505954141175808"));*/
+        listVa.add("004a7701240164e8");
+        listVa.add("004a770124013b39");
+        Criteria inCtr = Criteria.where("deviceNo").all().in(listVa);
+
+        //Criteria inCtr = Criteria.where("deviceId").in("705506563531603968","705506562667577344");
+        query.addCriteria(criteria);
+        query.addCriteria(inCtr);
+        query.fields().include("deviceId");
+        query.fields().include("readDate");
+        query.fields().include("readData");
+        query.fields().exclude("_id");
+
+
+        List<MeterReadRecordDto> childMap = mongoTemplate.find(query,MeterReadRecordDto.class,"sc_meter_read_record");
+        if(childMap.size() > 0){
+            for (int i=0;i<childMap.size();i++){
+                meterReadRecordHashMap.put(childMap.get(i).getDeviceId(),childMap.get(i));
+            }
+        }
+        //------------------------>
         return stringList;
     }