|
@@ -5,54 +5,40 @@ import com.bz.smart_city.commom.exception.ServiceException;
|
|
|
import com.bz.smart_city.commom.util.*;
|
|
|
import com.bz.smart_city.dto.*;
|
|
|
|
|
|
+import com.mongodb.client.result.UpdateResult;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.data.domain.Sort;
|
|
|
+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.data.mongodb.core.query.Update;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import javax.annotation.Resource;
|
|
|
-import javax.servlet.http.HttpServletResponse;
|
|
|
-
|
|
|
import java.math.BigDecimal;
|
|
|
-import java.time.LocalDate;
|
|
|
-import java.time.format.DateTimeFormatter;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-
|
|
|
-import com.bz.smart_city.entity.ClearingRecord;
|
|
|
+import java.util.regex.Pattern;
|
|
|
import com.bz.smart_city.entity.Customer;
|
|
|
-import com.bz.smart_city.entity.Device;
|
|
|
-import com.bz.smart_city.entity.DeviceDataDim;
|
|
|
-import com.bz.smart_city.entity.JobCard;
|
|
|
import com.bz.smart_city.entity.MeterReadRate;
|
|
|
import com.bz.smart_city.entity.MeterReadRecord;
|
|
|
-import com.bz.smart_city.entity.MeterRecordStat;
|
|
|
-import com.bz.smart_city.entity.Site;
|
|
|
-import com.bz.smart_city.entity.WMeterType;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
import com.bz.smart_city.commom.model.CommonQueryCondition;
|
|
|
import com.bz.smart_city.commom.model.ListObjectWrapper;
|
|
|
import com.bz.smart_city.commom.model.Pagination;
|
|
|
import com.bz.smart_city.commom.model.ResultStatus;
|
|
|
import com.bz.smart_city.dao.BuildingMapper;
|
|
|
-import com.bz.smart_city.dao.DeviceDataDimMapper;
|
|
|
import com.bz.smart_city.dao.DeviceMapper;
|
|
|
import com.bz.smart_city.dao.MeterReadRateMapper;
|
|
|
import com.bz.smart_city.dao.MeterReadRecordMapper;
|
|
|
import com.bz.smart_city.dao.StatMeterReadRateByBuildingMapper;
|
|
|
import com.bz.smart_city.dao.UserMapper;
|
|
|
-import com.bz.smart_city.dao.WMeterTypeMapper;
|
|
|
import com.bz.smart_city.service.CustomerService;
|
|
|
import com.bz.smart_city.service.MeterReadRecordService;
|
|
|
-import com.bz.smart_city.service.UserService;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
-
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
-import static com.google.common.collect.Lists.newArrayList;
|
|
|
|
|
|
/**
|
|
|
* 抄表记录服务实现类
|
|
@@ -81,15 +67,9 @@ public class MeterReadRecordServiceImpl implements MeterReadRecordService{
|
|
|
@Resource
|
|
|
private RedisUtil redisUtil;
|
|
|
|
|
|
- @Resource
|
|
|
- private DeviceDataDimMapper deviceDataDimMapper;
|
|
|
-
|
|
|
@Resource
|
|
|
UserMapper userMapper;
|
|
|
-
|
|
|
- @Resource
|
|
|
- WMeterTypeMapper wneterTypeMapper;
|
|
|
-
|
|
|
+
|
|
|
@Resource
|
|
|
private BuildingMapper buildingMapper;
|
|
|
|
|
@@ -97,421 +77,96 @@ public class MeterReadRecordServiceImpl implements MeterReadRecordService{
|
|
|
private StatMeterReadRateByBuildingMapper statMeterReadRateByBuildingMapper;
|
|
|
|
|
|
@Resource
|
|
|
- CustomerService customerService;
|
|
|
+ CustomerService customerService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ MongoTemplate mongoTemplate ;
|
|
|
|
|
|
- @Override
|
|
|
- public Pagination<MeterReadRecord> queryMeterReadRecord(CommonQueryCondition condition, int pageNum, int pageSize) {
|
|
|
- log.info("begin MeterReadRecordService queryMeterReadRecord , param = "+JSON.toJSONString(condition));
|
|
|
- List<Integer> siteList = new ArrayList<Integer>();
|
|
|
- siteList.add(condition.getSiteId());
|
|
|
-
|
|
|
- List<Integer> buildingIds = buildingMapper.getIdsByDataPermission(siteList, condition.getProgramItems());
|
|
|
- condition.setBuildingIds(buildingIds);
|
|
|
-
|
|
|
- PageHelper.startPage(pageNum, pageSize);
|
|
|
- List<MeterReadRecord> result = meterReadRecordMapper.queryMeterReadRecordWithCondtion(condition);
|
|
|
- log.info("end MeterReadRecordService queryMeterReadRecord , result.size = "+result.size());
|
|
|
- return new Pagination<MeterReadRecord>(result);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<MeterReadRate> analysisMeterReadRate(CommonQueryCondition condition){
|
|
|
- List<MeterReadRate> result = new ArrayList<MeterReadRate>();
|
|
|
- // 1,计算查询日期
|
|
|
- Integer period = condition.getPeriod();
|
|
|
- if(period == 0) { // 自定义
|
|
|
- if(condition.getStartDate() == 0 && condition.getEndDate() == 0) throw new RuntimeException("获取不到查询开始与结束时间");
|
|
|
- }
|
|
|
- else if(period == 1) {
|
|
|
- condition.setStartDate(Integer.parseInt(DateTimeUtil.formatNow("yyyyMMdd")));
|
|
|
- condition.setEndDate(Integer.parseInt(DateTimeUtil.formatNow("yyyyMMdd")));
|
|
|
- }
|
|
|
- else if(period == 2) {
|
|
|
- condition.setStartDate(Integer.parseInt(DateTimeUtil.formatDate(DateTimeUtil.beforeNow(1), "yyyyMMdd")));
|
|
|
- condition.setEndDate(Integer.parseInt(DateTimeUtil.formatDate(DateTimeUtil.beforeNow(1), "yyyyMMdd")));
|
|
|
- }
|
|
|
- else if(period == 7) {
|
|
|
- condition.setStartDate( Integer.parseInt(DateTimeUtil.formatDate(DateTimeUtil.beforeNow(7), "yyyyMMdd")));
|
|
|
- condition.setEndDate(Integer.parseInt(DateTimeUtil.formatDate(DateTimeUtil.beforeNow(1), "yyyyMMdd")));
|
|
|
- }
|
|
|
- else if(period == 30) {
|
|
|
- condition.setStartDate(Integer.parseInt(DateTimeUtil.formatDate(DateTimeUtil.beforeNow(30), "yyyyMMdd")));
|
|
|
- condition.setEndDate(Integer.parseInt(DateTimeUtil.formatDate(DateTimeUtil.beforeNow(1), "yyyyMMdd")));
|
|
|
- }
|
|
|
- // 2,查询数据
|
|
|
- List<StatMeterReadRateDto> datas = statMeterReadRateByBuildingMapper.analysisMeterReadRate(condition);
|
|
|
-
|
|
|
- // 3,数据不够则补齐数据
|
|
|
- List<String> dateStrs = DateTimeUtil.betweenDate(DateTimeUtil.parseDate(condition.getStartDate() + "", "yyyyMMdd"),
|
|
|
- DateTimeUtil.parseDate(condition.getEndDate() + "", "yyyyMMdd"));
|
|
|
-
|
|
|
- if (result.size() != dateStrs.size()) {
|
|
|
- for (String dateStr : dateStrs) {
|
|
|
- boolean exist = false;
|
|
|
- for (StatMeterReadRateDto data : datas) {
|
|
|
- Integer statDate = data.getStatDay();
|
|
|
- if (dateStr.equals(String.valueOf(statDate))) {
|
|
|
- exist = true;
|
|
|
- MeterReadRate tmp = new MeterReadRate();
|
|
|
- tmp.setStatDate(statDate);
|
|
|
- tmp.setReadRate(data.getReadRate().doubleValue());
|
|
|
- tmp.setRealReadTimes(data.getRealReadTimes().longValue());
|
|
|
- tmp.setReadTimes(data.getReadTimes().longValue());
|
|
|
- tmp.setUnReadTimes(data.getUnReadTimes().longValue());
|
|
|
- result.add(tmp);
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- if (!exist) {
|
|
|
- MeterReadRate tmp = new MeterReadRate();
|
|
|
- tmp.setReadRate(0.0);
|
|
|
- tmp.setStatDate(Integer.parseInt(dateStr));
|
|
|
- tmp.setRealReadTimes(0l);
|
|
|
- tmp.setUnReadTimes(0l);
|
|
|
- tmp.setReadTimes(0l);
|
|
|
- result.add(tmp);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return result ;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<MeterReadRate> analysisMeterReadRate(MeterReadRate param) {
|
|
|
- log.info("begin MeterReadRecordService analysisMeterReadRate , param = "+JSON.toJSONString(param));
|
|
|
- // 1,先根据周期判断开始与结束时间 ,统计周期:0 表示自定义,1表示今天,2表示昨天,7表示近7天,30表示近30天
|
|
|
- Integer period = param.getPeriod();
|
|
|
- if(period == 0) { // 自定义
|
|
|
- if(param.getStartDate() == 0 && param.getEndDate() == 0) throw new RuntimeException("获取不到查询开始与结束时间");
|
|
|
- }
|
|
|
- else if(period == 1) {
|
|
|
- param.setStartDate(Integer.parseInt(DateTimeUtil.formatNow("yyyyMMdd")));
|
|
|
- param.setEndDate(Integer.parseInt(DateTimeUtil.formatNow("yyyyMMdd")));
|
|
|
- }
|
|
|
- else if(period == 2) {
|
|
|
- param.setStartDate(Integer.parseInt(DateTimeUtil.formatDate(DateTimeUtil.beforeNow(1), "yyyyMMdd")));
|
|
|
- param.setEndDate(Integer.parseInt(DateTimeUtil.formatNow("yyyyMMdd")));
|
|
|
- }
|
|
|
- else if(period == 7) {
|
|
|
- param.setStartDate( Integer.parseInt(DateTimeUtil.formatDate(DateTimeUtil.beforeNow(7), "yyyyMMdd")));
|
|
|
- param.setEndDate(Integer.parseInt(DateTimeUtil.formatNow("yyyyMMdd")));
|
|
|
- }
|
|
|
- else if(period == 30) {
|
|
|
- param.setStartDate(Integer.parseInt(DateTimeUtil.formatDate(DateTimeUtil.beforeNow(30), "yyyyMMdd")));
|
|
|
- param.setEndDate(Integer.parseInt(DateTimeUtil.formatNow("yyyyMMdd")));
|
|
|
- }
|
|
|
- // 2,查询数据
|
|
|
- List<MeterReadRate> result = meterReadRateMapper.analysisMeterReadRate(param);
|
|
|
- // 3,数据不够则补齐数据
|
|
|
- List<String> dateStrs = DateTimeUtil.betweenDate(DateTimeUtil.parseDate(param.getStartDate() + "", "yyyyMMdd"),
|
|
|
- DateTimeUtil.parseDate(param.getEndDate() + "", "yyyyMMdd"));
|
|
|
- if (result.size() != dateStrs.size()) {
|
|
|
- for (String dateStr : dateStrs) {
|
|
|
- boolean exist = false;
|
|
|
- for (MeterReadRate data : result) {
|
|
|
- Integer statDate = data.getStatDate();
|
|
|
- if (dateStr.equals(String.valueOf(statDate))) {
|
|
|
- exist = true;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- if (!exist) {
|
|
|
- MeterReadRate tmp = new MeterReadRate();
|
|
|
- tmp.setReadRate(0.0);
|
|
|
- tmp.setStatDate(Integer.parseInt(dateStr));
|
|
|
- tmp.setRealReadTimes(0l);
|
|
|
- tmp.setUnReadTimes(0l);
|
|
|
- tmp.setReadTimes(0l);
|
|
|
- result.add(tmp);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- SortList<MeterReadRate> sortList = new SortList<MeterReadRate>();
|
|
|
- sortList.Sort(result, "getStatDate", "asc");
|
|
|
- log.info("end MeterReadRecordService analysisMeterReadRate , result.size = "+result.size());
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
- public Pagination<MeterReadRate> queryMeterReadRate(MeterReadRate param, int pageNum, int pageSize) {
|
|
|
- log.info("begin MeterReadRecordService queryMeterReadRate , param = "+JSON.toJSONString(param));
|
|
|
- PageHelper.startPage(pageNum, pageSize);
|
|
|
- List<MeterReadRate> result = meterReadRateMapper.queryMeterReadRate(param);
|
|
|
- log.info("end MeterReadRecordService queryMeterReadRate , result.size = "+result.size());
|
|
|
- return new Pagination<MeterReadRate>(result);
|
|
|
+ public Long updateMeterReadRecords(Long deviceId, com.zcxk.zoniot.smartcity.common.model.MeterReadRecord param) {
|
|
|
+ Query query = new Query();
|
|
|
+ query.addCriteria(Criteria.where("deviceId").is(deviceId));
|
|
|
+ query.addCriteria(Criteria.where("status").is(1));
|
|
|
+ Update update = buildUpdate(param) ;
|
|
|
+ UpdateResult result = mongoTemplate.updateMulti(query, update, com.zcxk.zoniot.smartcity.common.model.MeterReadRecord.class);
|
|
|
+ return result.getModifiedCount();
|
|
|
}
|
|
|
-
|
|
|
- @Override
|
|
|
- @Deprecated
|
|
|
- public MeterReadRate summaryMeterReadRate(CommonQueryCondition condition) {
|
|
|
- // 1,先根据周期判断开始与结束时间 ,统计周期:0 表示自定义,1表示今天,2表示昨天,7表示近7天,30表示近30天
|
|
|
- MeterReadRate result = new MeterReadRate(); ;
|
|
|
- Integer period = condition.getPeriod();
|
|
|
- if(period == 0) { // 自定义
|
|
|
- if(condition.getStartDate() == 0 && condition.getEndDate() == 0) throw new RuntimeException("获取不到查询开始与结束时间");
|
|
|
- }
|
|
|
- else if(period == 1) {
|
|
|
- condition.setStartDate(Integer.parseInt(DateTimeUtil.formatNow("yyyyMMdd")));
|
|
|
- condition.setEndDate(Integer.parseInt(DateTimeUtil.formatNow("yyyyMMdd")));
|
|
|
- }
|
|
|
- else if(period == 2) {
|
|
|
- condition.setStartDate(Integer.parseInt(DateTimeUtil.formatDate(DateTimeUtil.beforeNow(1), "yyyyMMdd")));
|
|
|
- condition.setEndDate(Integer.parseInt(DateTimeUtil.formatDate(DateTimeUtil.beforeNow(1), "yyyyMMdd")));
|
|
|
- }
|
|
|
- else if(period == 7) {
|
|
|
- condition.setStartDate( Integer.parseInt(DateTimeUtil.formatDate(DateTimeUtil.beforeNow(7), "yyyyMMdd")));
|
|
|
- condition.setEndDate(Integer.parseInt(DateTimeUtil.formatDate(DateTimeUtil.beforeNow(1), "yyyyMMdd")));
|
|
|
- }
|
|
|
- else if(period == 30) {
|
|
|
- condition.setStartDate(Integer.parseInt(DateTimeUtil.formatDate(DateTimeUtil.beforeNow(30), "yyyyMMdd")));
|
|
|
- condition.setEndDate(Integer.parseInt(DateTimeUtil.formatDate(DateTimeUtil.beforeNow(1), "yyyyMMdd")));
|
|
|
- }
|
|
|
- StatMeterReadRateDto resp = statMeterReadRateByBuildingMapper.summaryRateListByBuilding(condition);
|
|
|
- if(resp == null) {
|
|
|
- result.setReadRate(0.0);
|
|
|
- result.setRealReadTimes(0l);
|
|
|
- result.setUnReadTimes(0l);
|
|
|
- result.setReadTimes(0l);
|
|
|
- }
|
|
|
- else {
|
|
|
- result.setReadRate(resp.getReadRate().doubleValue());
|
|
|
- result.setRealReadTimes(resp.getRealReadTimes().longValue());
|
|
|
- result.setUnReadTimes(resp.getRealReadTimes().longValue());
|
|
|
- result.setReadTimes(resp.getReadTimes().longValue());
|
|
|
+ protected Update buildUpdate(com.zcxk.zoniot.smartcity.common.model.MeterReadRecord param){
|
|
|
+ Update update = new Update();
|
|
|
+ if(param.getChannelId() != null){
|
|
|
+ update.set("channelId",param.getChannelId());
|
|
|
}
|
|
|
- return result;
|
|
|
+ return update;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- @Override
|
|
|
- public MeterReadRate summaryMeterReadRate(MeterReadRate param) {
|
|
|
- log.info("begin MeterReadRecordService summaryMeterReadRate , param = "+JSON.toJSONString(param));
|
|
|
- // 1,先根据周期判断开始与结束时间 ,统计周期:0 表示自定义,1表示今天,2表示昨天,7表示近7天,30表示近30天
|
|
|
- Integer period = param.getPeriod();
|
|
|
- if(period == 0) { // 自定义
|
|
|
- if(param.getStartDate() == 0 && param.getEndDate() == 0) throw new RuntimeException("获取不到查询开始与结束时间");
|
|
|
- }
|
|
|
- else if(period == 1) {
|
|
|
- param.setStartDate(Integer.parseInt(DateTimeUtil.formatNow("yyyyMMdd")));
|
|
|
- param.setEndDate(Integer.parseInt(DateTimeUtil.formatNow("yyyyMMdd")));
|
|
|
- }
|
|
|
- else if(period == 2) {
|
|
|
- param.setStartDate(Integer.parseInt(DateTimeUtil.formatDate(DateTimeUtil.beforeNow(1), "yyyyMMdd")));
|
|
|
- param.setEndDate(Integer.parseInt(DateTimeUtil.formatNow("yyyyMMdd")));
|
|
|
- }
|
|
|
- else if(period == 7) {
|
|
|
- param.setStartDate( Integer.parseInt(DateTimeUtil.formatDate(DateTimeUtil.beforeNow(7), "yyyyMMdd")));
|
|
|
- param.setEndDate(Integer.parseInt(DateTimeUtil.formatNow("yyyyMMdd")));
|
|
|
- }
|
|
|
- else if(period == 30) {
|
|
|
- param.setStartDate(Integer.parseInt(DateTimeUtil.formatDate(DateTimeUtil.beforeNow(30), "yyyyMMdd")));
|
|
|
- param.setEndDate(Integer.parseInt(DateTimeUtil.formatNow("yyyyMMdd")));
|
|
|
- }
|
|
|
- // 1,先计算汇总信息
|
|
|
- MeterReadRate result = meterReadRateMapper.sumMeterReadRate(param);
|
|
|
- if(result == null) {
|
|
|
- result = new MeterReadRate();
|
|
|
- result.setReadRate(0.0);
|
|
|
- result.setRealReadTimes(0l);
|
|
|
- result.setUnReadTimes(0l);
|
|
|
- result.setReadTimes(0l);
|
|
|
- }
|
|
|
- // 2,单独计算设备总数
|
|
|
-// if(period == 1) {
|
|
|
-// Device p = new Device();
|
|
|
-// WMeterType type = wneterTypeMapper.getWMeterTypeByDeviceTypeCode(deviceTypeCode);
|
|
|
-// p.setSysId(type.getChannelId());
|
|
|
-// List<Integer> statusList = new ArrayList<Integer>();
|
|
|
-// statusList.add(1);
|
|
|
-// statusList.add(2);
|
|
|
-// statusList.add(3);
|
|
|
-// statusList.add(4);
|
|
|
-// p.setDeviceStatusList(statusList);
|
|
|
-// int total = deviceMapper.countDevice(p);
|
|
|
-// result.setDeviceCount((long)total);
|
|
|
-// }
|
|
|
-// else {
|
|
|
-// List<MeterReadRate> rates = meterReadRateMapper.analysisMeterReadRate(param);
|
|
|
-// if(rates.size() > 0 ) {
|
|
|
-// result.setDeviceCount(rates.get(0).getDeviceCount());
|
|
|
-// }
|
|
|
-// }
|
|
|
- log.info("end MeterReadRecordService summaryMeterReadRate , result = "+JSON.toJSONString(result));
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- @Async
|
|
|
@Override
|
|
|
- public int createMeterReadRecordAsync(Date date) {
|
|
|
- return createMeterReadRecord(date);
|
|
|
+ public List<com.zcxk.zoniot.smartcity.common.model.MeterReadRecord> queryMeterReadRecord(MeterReadRecordQueryDTO param) {
|
|
|
+ Query query = buildBaseQuery(param);
|
|
|
+ List<com.zcxk.zoniot.smartcity.common.model.MeterReadRecord> results =
|
|
|
+ mongoTemplate.find(query, com.zcxk.zoniot.smartcity.common.model.MeterReadRecord.class);
|
|
|
+ return results;
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- @Deprecated
|
|
|
- public int createMeterReadRecord(Date date) {
|
|
|
- log.info("begin MeterReadRecordService createMeterReadRecord ,date = "+ JSON.toJSONString(date));
|
|
|
- Integer result = 0;
|
|
|
- // 1,获取场景下设备总量
|
|
|
- WMeterType type = wneterTypeMapper.getWMeterTypeByDeviceTypeCode(deviceTypeCode);
|
|
|
- Device param = new Device();
|
|
|
- List<Integer> channelIds = new ArrayList<Integer>();
|
|
|
- channelIds.add(-99); // 新装水表
|
|
|
- channelIds.add(type.getChannelId());
|
|
|
- param.setSysIds(channelIds);
|
|
|
- List<Integer> statusList = new ArrayList<Integer>();
|
|
|
- statusList.add(1); // 正常
|
|
|
- statusList.add(2); // 故障
|
|
|
-// statusList.add(3);
|
|
|
- statusList.add(4); // 预警
|
|
|
- statusList.add(5); // 未启用
|
|
|
- param.setDeviceStatusList(statusList);
|
|
|
- param.setDeviceType(type.getDeviceTypeId());
|
|
|
- int total = deviceMapper.countDevice(param);
|
|
|
-
|
|
|
- // 2,分页获取设备并生成抄表记录
|
|
|
- int pageSize = 1000 ;
|
|
|
-
|
|
|
- int totalPage = total / pageSize;
|
|
|
- if (total % pageSize != 0){
|
|
|
- totalPage++;
|
|
|
+ protected Query buildBaseQuery(MeterReadRecordQueryDTO param){
|
|
|
+ Query query = new Query();
|
|
|
+ if(param.getBuildingIds()!= null && param.getBuildingIds().size() != 0){
|
|
|
+ query.addCriteria(Criteria.where("buildingId").in(param.getBuildingIds()));
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- for(int i = 1 ;i <= totalPage; i++) {
|
|
|
- int start = (i - 1) * pageSize;
|
|
|
-
|
|
|
- List<DeviceDto> deviceList = deviceMapper.getDeviceList(param, start, pageSize);
|
|
|
- List<MeterReadRecord> records = new ArrayList<MeterReadRecord>();
|
|
|
- for(DeviceDto device : deviceList) {
|
|
|
- String readStatus = "1" ; // 1:未抄,2:已抄
|
|
|
- Integer startDate = Integer.parseInt(DateTimeUtil.formatDate(DateTimeUtil.before(date, 1), "yyyyMMdd"));
|
|
|
- Integer endDate = Integer.parseInt(DateTimeUtil.formatDate(date, "yyyyMMdd"));
|
|
|
- MeterReadRecord record = new MeterReadRecord();
|
|
|
- String deviceNo = device.getDeviceNo() ;
|
|
|
- Long deviceId = device.getId();
|
|
|
- record.setId(idWorker.nextId());
|
|
|
- record.setSiteId(device.getSiteId());
|
|
|
- record.setSysId(device.getSysId());
|
|
|
- record.setProvince(device.getProvince());
|
|
|
- record.setRegion(device.getRegion());
|
|
|
- record.setCity(device.getCity());
|
|
|
- record.setCommunityId(device.getCommunity());
|
|
|
- record.setBuildingId(device.getBuildingId());
|
|
|
- record.setLocation(device.getLocDesc());
|
|
|
- record.setDeviceTypeId(device.getDeviceType());
|
|
|
- record.setDeviceId(device.getId());
|
|
|
- record.setDeviceNo(deviceNo);
|
|
|
- record.setMeterFileNo(device.getWaterMeterFileNo());
|
|
|
- record.setMeterNo(device.getWaterMeterNo());
|
|
|
- record.setReadDate(startDate);
|
|
|
- record.setCustomerId(device.getCustomerId());
|
|
|
- // 先从缓存中获取数据
|
|
|
- String deviceDataJSONStr = redisUtil.get(String.valueOf(device.getId()));
|
|
|
- if(StringUtils.isNotEmpty(deviceDataJSONStr)) {
|
|
|
- JSONObject dataObj = (JSONObject)JSON.parse(deviceDataJSONStr);
|
|
|
- // 分别获取用水测点与上报时间测点
|
|
|
- JSONObject timeData = (JSONObject)dataObj.get("TIME");
|
|
|
- JSONObject wsvData = (JSONObject)dataObj.get("WSV");
|
|
|
- String timeStr = (String)timeData.get("measuringVaule"); // 格式 20181221100659
|
|
|
- // 判断上报时间是超时
|
|
|
- Date cacheDate = DateTimeUtil.parseDate(timeStr, "yyyyMMddhhmmss");
|
|
|
- if(cacheDate.after(DateTimeUtil.parseDate(String.valueOf(startDate), "yyyyMMdd")) && cacheDate.before(DateTimeUtil.parseDate(String.valueOf(endDate), "yyyyMMdd"))) {
|
|
|
- readStatus = "2"; //已抄
|
|
|
- record.setReadTime(cacheDate);
|
|
|
- record.setReadData(wsvData.getString("measuringVaule"));
|
|
|
- }
|
|
|
- else {
|
|
|
- DeviceDataDim p = new DeviceDataDim();
|
|
|
- p.setDeviceId(deviceId);
|
|
|
- p.setDeviceNo(deviceNo);
|
|
|
- p.setStartDate(startDate);
|
|
|
- p.setEndDate(endDate);
|
|
|
- p.setMeasuringCode("WSV");
|
|
|
- List<DeviceDataDim> data = deviceDataDimMapper.queryDeviceDataDim(p,1);
|
|
|
-
|
|
|
- if(data.size() > 0) {
|
|
|
- readStatus = "2" ; // 已抄
|
|
|
- record.setReadTime(data.get(0).getSendTime()); // 抄表时间
|
|
|
- record.setReadData(data.get(0).getMeasuringData());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- else { // 缓存中没有数据则从数据库中进行查询
|
|
|
- DeviceDataDim p = new DeviceDataDim();
|
|
|
- p.setDeviceNo(deviceNo);
|
|
|
- p.setDeviceId(deviceId);
|
|
|
- p.setStartDate(startDate);
|
|
|
- p.setEndDate(endDate);
|
|
|
- p.setMeasuringCode("WSV");
|
|
|
- List<DeviceDataDim> data = deviceDataDimMapper.queryDeviceDataDim(p,1);
|
|
|
-
|
|
|
- if(data.size() > 0) {
|
|
|
- readStatus = "2" ; // 已抄
|
|
|
- record.setReadTime(data.get(0).getSendTime()); // 抄表时间
|
|
|
- record.setReadData(data.get(0).getMeasuringData());
|
|
|
- }
|
|
|
- }
|
|
|
- record.setReadStatus(readStatus); // 抄表状态
|
|
|
- record.setStatus(1);
|
|
|
-
|
|
|
- // 计算当日用水量
|
|
|
- Integer lastDate = Integer.parseInt(DateTimeUtil.formatDate(DateTimeUtil.before(date, 2), "yyyyMMdd"));
|
|
|
- MeterReadRecord lastDayRecord = meterReadRecordMapper.getLastDayData(deviceId, lastDate);
|
|
|
- String rd = record.getReadData();
|
|
|
- if (lastDayRecord == null) {
|
|
|
- if (rd == null || rd.equals("")) {
|
|
|
- record.setLastCost(BigDecimal.ZERO);
|
|
|
- record.setLastValid("0");
|
|
|
- } else {
|
|
|
- record.setLastValid(rd);
|
|
|
- BigDecimal lastC = new BigDecimal(Double.parseDouble(rd));
|
|
|
- record.setLastCost(lastC);
|
|
|
- }
|
|
|
- } else {
|
|
|
- if (rd == null || rd.equals("")) {
|
|
|
- record.setLastCost(BigDecimal.ZERO);
|
|
|
- record.setLastValid(lastDayRecord.getLastValid());
|
|
|
- } else {
|
|
|
- record.setLastValid(rd);
|
|
|
- BigDecimal lastC = new BigDecimal(Double.parseDouble(rd) - Double.parseDouble(lastDayRecord.getLastValid()));
|
|
|
- record.setLastCost(lastC);
|
|
|
- }
|
|
|
- }
|
|
|
- records.add(record);
|
|
|
- }
|
|
|
- // 保存抄表记录
|
|
|
- meterReadRecordMapper.insertList(records);
|
|
|
- try {
|
|
|
- Thread.sleep(10000l);
|
|
|
- } catch (InterruptedException e) {
|
|
|
- log.error("thread interrupted", e);
|
|
|
- }
|
|
|
+ if(param.getDeviceId() != null){
|
|
|
+ query.addCriteria(Criteria.where("deviceId").is(param.getDeviceId()));
|
|
|
}
|
|
|
-
|
|
|
- log.info("end MeterReadRecordService createMeterReadRecord ,result = "+ result);
|
|
|
- return total;
|
|
|
+ if(StringUtils.isNotBlank(param.getCollectorCode())){
|
|
|
+ // TODO
|
|
|
+ }
|
|
|
+ if(StringUtils.isNotBlank(param.getConcentratorCode())){
|
|
|
+ // TODO
|
|
|
+ }
|
|
|
+ if(StringUtils.isNotBlank(param.getDeviceNo())){
|
|
|
+ query.addCriteria(Criteria.where("deviceNo").regex(Pattern.compile("^.*"+param.getDeviceNo()+".*$", Pattern.CASE_INSENSITIVE)));
|
|
|
+ }
|
|
|
+ if(param.getCustomerId() != null){
|
|
|
+ query.addCriteria(Criteria.where("customerId").is(param.getCustomerId()));
|
|
|
+ }
|
|
|
+ if(param.getCommunityId() != null){
|
|
|
+ query.addCriteria(Criteria.where("communityId").is(param.getCommunityId()));
|
|
|
+ }
|
|
|
+ if(StringUtils.isNotBlank(param.getReadStatus())){
|
|
|
+ query.addCriteria(Criteria.where("readStatus").is(param.getReadStatus()));
|
|
|
+ }
|
|
|
+ if(param.getStartDate() != null && param.getEndDate() != null){
|
|
|
+ query.addCriteria(Criteria.where("readDate").gte(param.getStartDate()).lte(param.getEndDate()));
|
|
|
+ }
|
|
|
+ else if(param.getStartDate() != null && param.getEndDate() == null){
|
|
|
+ query.addCriteria(Criteria.where("readDate").gte(param.getStartDate()));
|
|
|
+ }
|
|
|
+ else if(param.getStartDate() == null && param.getEndDate() != null){
|
|
|
+ query.addCriteria(Criteria.where("readDate").lte(param.getEndDate()));
|
|
|
+ }
|
|
|
+ if(param.getSiteIds() != null && param.getSiteIds().size() == 0){
|
|
|
+ query.addCriteria(Criteria.where("siteId").in(param.getSiteIds()));
|
|
|
+ }
|
|
|
+ if(param.getChannelId() != null){
|
|
|
+ query.addCriteria(Criteria.where("channelId").is(param.getChannelId()));
|
|
|
+ }
|
|
|
+ if(param.getSort() == null){
|
|
|
+ // 默认按照抄表时间降序
|
|
|
+ query.with(new Sort(Sort.Direction.DESC,"readTime"));
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ query.with(param.getSort());
|
|
|
+ }
|
|
|
+ return query ;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public int insert(MeterReadRecord meterReadRecord){
|
|
|
- return meterReadRecordMapper.insert(meterReadRecord);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public int insertSelective(MeterReadRecord meterReadRecord){
|
|
|
- return meterReadRecordMapper.insertSelective(meterReadRecord);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public int insertList(List<MeterReadRecord> meterReadRecords){
|
|
|
- return meterReadRecordMapper.insertList(meterReadRecords);
|
|
|
- }
|
|
|
+ public Pagination<MeterReadRate> queryMeterReadRate(MeterReadRate param, int pageNum, int pageSize) {
|
|
|
+ log.info("begin MeterReadRecordService queryMeterReadRate , param = "+JSON.toJSONString(param));
|
|
|
+ PageHelper.startPage(pageNum, pageSize);
|
|
|
+ List<MeterReadRate> result = meterReadRateMapper.queryMeterReadRate(param);
|
|
|
+ log.info("end MeterReadRecordService queryMeterReadRate , result.size = "+result.size());
|
|
|
+ return new Pagination<MeterReadRate>(result);
|
|
|
+ }
|
|
|
|
|
|
- @Override
|
|
|
- public int updateByPrimaryKeySelective(MeterReadRecord meterReadRecord){
|
|
|
- return meterReadRecordMapper.updateByPrimaryKeySelective(meterReadRecord);
|
|
|
- }
|
|
|
|
|
|
@Override
|
|
|
public WaterConsumptionSummaryDto waterConsumptionSummary(CommonQueryCondition condition) {
|
|
@@ -569,126 +224,6 @@ public class MeterReadRecordServiceImpl implements MeterReadRecordService{
|
|
|
log.info("结束用水量恢复");
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public int createMeterReadRecordForRollback(Date date) {
|
|
|
- log.info("begin MeterReadRecordService createMeterReadRecord ,date = "+ JSON.toJSONString(date));
|
|
|
- Integer result = 0;
|
|
|
- // 1,获取场景下设备总量
|
|
|
- WMeterType type = wneterTypeMapper.getWMeterTypeByDeviceTypeCode(deviceTypeCode);
|
|
|
- Device param = new Device();
|
|
|
- List<Integer> channelIds = new ArrayList<Integer>();
|
|
|
- channelIds.add(-99); // 新装水表
|
|
|
- channelIds.add(type.getChannelId());
|
|
|
- param.setSysIds(channelIds);
|
|
|
- List<Integer> statusList = new ArrayList<Integer>();
|
|
|
- statusList.add(1); // 正常
|
|
|
- statusList.add(2); // 故障
|
|
|
-// statusList.add(3);
|
|
|
- statusList.add(4); // 预警
|
|
|
- param.setDeviceStatusList(statusList);
|
|
|
- int total = deviceMapper.countDevice(param);
|
|
|
-
|
|
|
- // 2,分页获取设备并生成抄表记录
|
|
|
- int pageSize = 1000 ;
|
|
|
-
|
|
|
- int totalPage = total / pageSize;
|
|
|
- if (total % pageSize != 0){
|
|
|
- totalPage++;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- for(int i = 1 ;i <= totalPage; i++) {
|
|
|
- int start = (i - 1) * pageSize;
|
|
|
-
|
|
|
- List<DeviceDto> deviceList = deviceMapper.getDeviceList(param, start, pageSize);
|
|
|
- List<MeterReadRecord> records = new ArrayList<MeterReadRecord>();
|
|
|
- for(DeviceDto device : deviceList) {
|
|
|
- String readStatus = "1" ; // 1:未抄,2:已抄
|
|
|
- Integer startDate = Integer.parseInt(DateTimeUtil.formatDate(DateTimeUtil.before(date, 1), "yyyyMMdd"));
|
|
|
- Integer endDate = Integer.parseInt(DateTimeUtil.formatDate(date, "yyyyMMdd"));
|
|
|
- MeterReadRecord record = new MeterReadRecord();
|
|
|
- String deviceNo = device.getDeviceNo() ;
|
|
|
- Long deviceId = device.getId();
|
|
|
- record.setId(idWorker.nextId());
|
|
|
- record.setSiteId(device.getSiteId());
|
|
|
- record.setSysId(device.getSysId());
|
|
|
- record.setProvince(device.getProvince());
|
|
|
- record.setRegion(device.getRegion());
|
|
|
- record.setCity(device.getCity());
|
|
|
- record.setCommunityId(device.getCommunity());
|
|
|
- record.setBuildingId(device.getBuildingId());
|
|
|
- record.setLocation(device.getLocDesc());
|
|
|
- record.setDeviceTypeId(device.getDeviceType());
|
|
|
- record.setDeviceId(device.getId());
|
|
|
- record.setDeviceNo(deviceNo);
|
|
|
- record.setMeterFileNo(device.getWaterMeterFileNo());
|
|
|
- record.setMeterNo(device.getWaterMeterNo());
|
|
|
- record.setReadDate(startDate);
|
|
|
- record.setCustomerId(device.getCustomerId());
|
|
|
- // 先从缓存中获取数据
|
|
|
- //String deviceDataJSONStr = redisUtil.get(deviceNo);
|
|
|
- String deviceDataJSONStr = "";
|
|
|
- if(StringUtils.isNotEmpty(deviceDataJSONStr)) {
|
|
|
- JSONObject dataObj = (JSONObject)JSON.parse(deviceDataJSONStr);
|
|
|
- // 分别获取用水测点与上报时间测点
|
|
|
- JSONObject timeData = (JSONObject)dataObj.get("TIME");
|
|
|
- JSONObject wsvData = (JSONObject)dataObj.get("WSV");
|
|
|
- String timeStr = (String)timeData.get("measuringVaule"); // 格式 20181221100659
|
|
|
- // 判断上报时间是超时
|
|
|
- Date cacheDate = DateTimeUtil.parseDate(timeStr, "yyyyMMddhhmmss");
|
|
|
- if(cacheDate.after(DateTimeUtil.parseDate(String.valueOf(startDate), "yyyyMMdd")) && cacheDate.before(DateTimeUtil.parseDate(String.valueOf(endDate), "yyyyMMdd"))) {
|
|
|
- readStatus = "2"; //已抄
|
|
|
- record.setReadTime(cacheDate);
|
|
|
- record.setReadData(wsvData.getString("measuringVaule"));
|
|
|
- }
|
|
|
- else {
|
|
|
- DeviceDataDim p = new DeviceDataDim();
|
|
|
- p.setDeviceId(deviceId);
|
|
|
- p.setDeviceNo(deviceNo);
|
|
|
- p.setStartDate(startDate);
|
|
|
- p.setEndDate(endDate);
|
|
|
- p.setMeasuringCode("WSV");
|
|
|
- List<DeviceDataDim> data = deviceDataDimMapper.queryDeviceDataDim(p,1);
|
|
|
-
|
|
|
- if(data.size() > 0) {
|
|
|
- readStatus = "2" ; // 已抄
|
|
|
- record.setReadTime(data.get(0).getSendTime()); // 抄表时间
|
|
|
- record.setReadData(data.get(0).getMeasuringData());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- else { // 缓存中没有数据则从数据库中进行查询
|
|
|
- DeviceDataDim p = new DeviceDataDim();
|
|
|
- p.setDeviceNo(deviceNo);
|
|
|
- p.setDeviceId(deviceId);
|
|
|
- p.setStartDate(startDate);
|
|
|
- p.setEndDate(endDate);
|
|
|
- p.setMeasuringCode("WSV");
|
|
|
- List<DeviceDataDim> data = deviceDataDimMapper.queryDeviceDataDim(p,1);
|
|
|
-
|
|
|
- if(data.size() > 0) {
|
|
|
- readStatus = "2" ; // 已抄
|
|
|
- record.setReadTime(data.get(0).getSendTime()); // 抄表时间
|
|
|
- record.setReadData(data.get(0).getMeasuringData());
|
|
|
- }
|
|
|
- }
|
|
|
- record.setReadStatus(readStatus); // 抄表状态
|
|
|
- record.setStatus(1);
|
|
|
-
|
|
|
- records.add(record);
|
|
|
- }
|
|
|
- // 保存抄表记录
|
|
|
- meterReadRecordMapper.insertList(records);
|
|
|
- try {
|
|
|
- Thread.sleep(10000l);
|
|
|
- } catch (InterruptedException e) {
|
|
|
- log.error("thread interrupted", e);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- log.info("end MeterReadRecordService createMeterReadRecord ,result = "+ result);
|
|
|
- return total;
|
|
|
- }
|
|
|
|
|
|
@Override
|
|
|
public ListObjectWrapper<MeterReadDataDTO> queryMeterReadData(String meterReadDate, String deviceNo,
|
|
@@ -713,190 +248,5 @@ public class MeterReadRecordServiceImpl implements MeterReadRecordService{
|
|
|
return new ListObjectWrapper<MeterReadDataDTO>(dataList);
|
|
|
}
|
|
|
}
|
|
|
- @Override
|
|
|
- public int waterMeterReadDataByType(Date date, String waterMeterCode, String wsvCode) {
|
|
|
- log.info("Begin WaterMeterReadDataByType , WaterMeterCode = {}",waterMeterCode);
|
|
|
- // 1,获取场景下设备总量
|
|
|
- Device param = buildQueryParam(waterMeterCode);
|
|
|
-
|
|
|
- Integer total = countWaterMeterByType(waterMeterCode);
|
|
|
- log.info("Water Meters With Code {},Total = {}",waterMeterCode ,total );
|
|
|
- // 2,分页获取设备并生成抄表记录
|
|
|
- int pageSize = 1000 ;
|
|
|
-
|
|
|
- int totalPage = total / pageSize;
|
|
|
- if (total % pageSize != 0){
|
|
|
- totalPage++;
|
|
|
- }
|
|
|
- for(int i = 1 ;i <= totalPage; i++) {
|
|
|
- int start = (i - 1) * pageSize;
|
|
|
- log.info("Current Page Size is {}, From {} With {}",i,start,pageSize);
|
|
|
- List<DeviceDto> deviceList = deviceMapper.getDeviceList(param, start, pageSize);
|
|
|
- List<MeterReadRecord> records = new ArrayList<MeterReadRecord>();
|
|
|
- for(DeviceDto device : deviceList) {
|
|
|
- MeterReadRecord readRecord = genrateMeterRecord(date, device, wsvCode);
|
|
|
- if(readRecord != null){
|
|
|
- long id = idWorker.nextId();
|
|
|
- readRecord.setId(id);
|
|
|
- records.add(readRecord);
|
|
|
- }
|
|
|
- }
|
|
|
- // 保存抄表记录
|
|
|
- log.info("Begin Save Read Record List ,Size ={}",records.size());
|
|
|
- meterReadRecordMapper.insertList(records);
|
|
|
- log.info("End Save Read Record List !");
|
|
|
- try {
|
|
|
- Thread.sleep(10000L);
|
|
|
- } catch (InterruptedException e) {
|
|
|
- log.error("thread interrupted", e);
|
|
|
- }
|
|
|
- }
|
|
|
- log.info("End WaterMeterReadDataByType createMeterReadRecord ,Total = {}",total);
|
|
|
- return total;
|
|
|
- }
|
|
|
-
|
|
|
- protected MeterReadRecord genrateMeterRecord(Date current ,DeviceDto device,String wsvCode){
|
|
|
- MeterReadRecord record = null ;
|
|
|
- try{
|
|
|
- Integer startDate = Integer.parseInt(DateTimeUtil.formatDate(DateTimeUtil.before(current, 1), "yyyyMMdd"));
|
|
|
- Integer endDate = Integer.parseInt(DateTimeUtil.formatDate(current, "yyyyMMdd"));
|
|
|
- // 先从缓存中获取数据
|
|
|
- String deviceDataJSONStr = redisUtil.get(String.valueOf(device.getId()));
|
|
|
- if(StringUtils.isNotEmpty(deviceDataJSONStr)) {
|
|
|
- record = genrateMeterRecordFromCache(device,startDate,endDate,wsvCode);
|
|
|
- }
|
|
|
- else {
|
|
|
- record = genrateMeterRecordFromDB(device,startDate,endDate,wsvCode) ;
|
|
|
- }
|
|
|
- // 计算当日用水量
|
|
|
- calcWsvIncrement(current,device,record);
|
|
|
- }catch (Exception e){
|
|
|
- log.error("Genrate Meter Record Failed !",e);
|
|
|
- }
|
|
|
- return record ;
|
|
|
- }
|
|
|
-
|
|
|
- protected Device buildQueryParam(String waterMeterCode){
|
|
|
- WMeterType type = wneterTypeMapper.getWMeterTypeByDeviceTypeCode(waterMeterCode);
|
|
|
- Device param = new Device();
|
|
|
- List<Integer> channelIds = new ArrayList<Integer>();
|
|
|
- channelIds.add(-99); // 新装水表
|
|
|
- channelIds.add(type.getChannelId());
|
|
|
- param.setSysIds(channelIds);
|
|
|
- List<Integer> statusList = new ArrayList<Integer>();
|
|
|
- statusList.add(1); // 正常
|
|
|
- statusList.add(2); // 故障
|
|
|
- statusList.add(4); // 预警
|
|
|
- statusList.add(5); // 未启用
|
|
|
- param.setDeviceStatusList(statusList);
|
|
|
- param.setDeviceType(type.getDeviceTypeId());
|
|
|
- return param;
|
|
|
- }
|
|
|
- protected void calcWsvIncrement(Date current , DeviceDto device , MeterReadRecord record){
|
|
|
- Integer lastDate = Integer.parseInt(DateTimeUtil.formatDate(DateTimeUtil.before(current, 2), "yyyyMMdd"));
|
|
|
- MeterReadRecord lastDayRecord = meterReadRecordMapper.getLastDayData(device.getId(), lastDate);
|
|
|
- String rd = record.getReadData();
|
|
|
- if (lastDayRecord == null) {
|
|
|
- if (rd == null || rd.equals("")) {
|
|
|
- record.setLastCost(BigDecimal.ZERO);
|
|
|
- record.setLastValid("0");
|
|
|
- } else {
|
|
|
- record.setLastValid(rd);
|
|
|
- BigDecimal lastC = new BigDecimal(Double.parseDouble(rd));
|
|
|
- record.setLastCost(lastC);
|
|
|
- }
|
|
|
- } else {
|
|
|
- if (rd == null || rd.equals("")) {
|
|
|
- record.setLastCost(BigDecimal.ZERO);
|
|
|
- record.setLastValid(lastDayRecord.getLastValid());
|
|
|
- } else {
|
|
|
- record.setLastValid(rd);
|
|
|
- BigDecimal lastC = new BigDecimal(Double.parseDouble(rd) - Double.parseDouble(lastDayRecord.getLastValid()));
|
|
|
- record.setLastCost(lastC);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- protected Integer countWaterMeterByType(String waterMeterCode){
|
|
|
- Device param = buildQueryParam(waterMeterCode);
|
|
|
- log.info("Count Water Meter by Type , Param = {}",JSON.toJSONString(param));
|
|
|
- int total = deviceMapper.countDevice(param);
|
|
|
- return total ;
|
|
|
- }
|
|
|
|
|
|
- protected MeterReadRecord buildRecordBaseInfo(DeviceDto device,Integer startDate){
|
|
|
- MeterReadRecord record = new MeterReadRecord();
|
|
|
- //record.setId(idWorker.nextId());
|
|
|
- record.setSiteId(device.getSiteId());
|
|
|
- record.setSysId(device.getSysId());
|
|
|
- record.setProvince(device.getProvince());
|
|
|
- record.setRegion(device.getRegion());
|
|
|
- record.setCity(device.getCity());
|
|
|
- record.setCommunityId(device.getCommunity());
|
|
|
- record.setBuildingId(device.getBuildingId());
|
|
|
- record.setLocation(device.getLocDesc());
|
|
|
- record.setDeviceTypeId(device.getDeviceType());
|
|
|
- record.setDeviceId(device.getId());
|
|
|
- record.setDeviceNo(device.getDeviceNo());
|
|
|
- record.setMeterFileNo(device.getWaterMeterFileNo());
|
|
|
- record.setMeterNo(device.getWaterMeterNo());
|
|
|
- record.setReadDate(startDate);
|
|
|
- record.setCustomerId(device.getCustomerId());
|
|
|
- record.setStatus(1);
|
|
|
- record.setReadStatus("1"); // 设置成未抄
|
|
|
- return record ;
|
|
|
- }
|
|
|
- /**
|
|
|
- * 从缓存数据中生成抄表记录
|
|
|
- */
|
|
|
- protected MeterReadRecord genrateMeterRecordFromCache(DeviceDto device, Integer startDate,Integer endDate , String wsvCode){
|
|
|
- log.info("Generate Meter Record From Cache ,Device No = {}",device.getDeviceNo());
|
|
|
- MeterReadRecord readRecord = null;
|
|
|
- readRecord = buildRecordBaseInfo(device,startDate);
|
|
|
- String deviceDataJSONStr = redisUtil.get(String.valueOf(device.getId()));
|
|
|
- log.info(" Device {} Cache Data Log ,Data = {} ",device.getDeviceNo(),deviceDataJSONStr);
|
|
|
- JSONObject dataObj = (JSONObject)JSON.parse(deviceDataJSONStr);
|
|
|
- // 分别获取用水测点与上报时间测点
|
|
|
- JSONObject timeData = (JSONObject)dataObj.get("TIME");
|
|
|
- JSONObject wsvData = (JSONObject)dataObj.get(wsvCode);
|
|
|
- String timeStr = (String)timeData.get("measuringVaule"); // 格式 20181221100659
|
|
|
- // 判断上报时间是超时
|
|
|
- Date cacheDate = DateTimeUtil.parseDate(timeStr, "yyyyMMddhhmmss");
|
|
|
- if(cacheDate.after(DateTimeUtil.parseDate(String.valueOf(startDate), "yyyyMMdd"))
|
|
|
- && cacheDate.before(DateTimeUtil.parseDate(String.valueOf(endDate), "yyyyMMdd"))) {
|
|
|
- readRecord.setReadStatus("2"); // 已抄
|
|
|
- readRecord.setReadTime(cacheDate);
|
|
|
- readRecord.setReadData(wsvData.getString("measuringVaule"));
|
|
|
- }
|
|
|
- else{
|
|
|
- readRecord = genrateMeterRecordFromDB(device,startDate,endDate,wsvCode);
|
|
|
- }
|
|
|
- return readRecord ;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 从数据库记录中生成抄表记录
|
|
|
- */
|
|
|
- protected MeterReadRecord genrateMeterRecordFromDB(DeviceDto device,Integer startDate,Integer endDate,String wsvCode){
|
|
|
- log.info("Generate Meter Record From DB ,Device No = {}",device.getDeviceNo());
|
|
|
- MeterReadRecord readRecord = null;
|
|
|
- readRecord = buildRecordBaseInfo(device,startDate);
|
|
|
-
|
|
|
- DeviceDataDim p = new DeviceDataDim();
|
|
|
- p.setDeviceNo(device.getDeviceNo());
|
|
|
- p.setDeviceId(device.getId());
|
|
|
- p.setStartDate(startDate);
|
|
|
- p.setEndDate(endDate);
|
|
|
- p.setMeasuringCode(wsvCode);
|
|
|
- List<DeviceDataDim> data = deviceDataDimMapper.queryDeviceDataDim(p,1);
|
|
|
-
|
|
|
- if(data.size() > 0) {
|
|
|
- readRecord.setReadStatus("2"); // 已抄
|
|
|
- readRecord.setReadTime(data.get(0).getSendTime()); // 抄表时间
|
|
|
- readRecord.setReadData(data.get(0).getMeasuringData());
|
|
|
- }
|
|
|
- else{
|
|
|
- readRecord.setReadStatus("1"); // 未抄
|
|
|
- }
|
|
|
- return readRecord ;
|
|
|
- }
|
|
|
}
|