|
@@ -412,151 +412,147 @@ public class MeterReadRecordServiceImpl implements MeterReadRecordService{
|
|
|
|
|
|
@Override
|
|
|
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++;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- for(int i = 1 ;i <= totalPage; i++) {
|
|
|
- int start = (i - 1) * pageSize;
|
|
|
- log.info("Meter Reading Start :{},PageSize :{},Param : {} ",start,pageSize,pageSize);
|
|
|
- List<DeviceDto> deviceList = deviceMapper.getDeviceList(param, start, pageSize);
|
|
|
- List<MeterReadRecord> records = new ArrayList<MeterReadRecord>();
|
|
|
- for(DeviceDto device : deviceList) {
|
|
|
- try{
|
|
|
- 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);
|
|
|
- }catch (Exception e){
|
|
|
- log.error("Meter {} Reading Failed !",device.getDeviceNo(),e);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- // 保存抄表记录
|
|
|
- meterReadRecordMapper.insertList(records);
|
|
|
- try {
|
|
|
- Thread.sleep(10000L);
|
|
|
- } catch (InterruptedException e) {
|
|
|
- log.error("thread interrupted", e);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- log.info("end MeterReadRecordService createMeterReadRecord ,result = "+ result);
|
|
|
+ log.info("begin MeterReadRecordService createMeterReadRecord ,date = {}", JSON.toJSONString(date));
|
|
|
+ int total = 0;
|
|
|
+ try{
|
|
|
+ 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(4); // 预警
|
|
|
+ statusList.add(5); // 未启用
|
|
|
+ param.setDeviceStatusList(statusList);
|
|
|
+ param.setDeviceType(type.getDeviceTypeId());
|
|
|
+ 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;
|
|
|
+ log.info("Meter Reading Start :{},PageSize :{},Param : {} ",start,pageSize,pageSize);
|
|
|
+ List<DeviceDto> deviceList = deviceMapper.getDeviceList(param, start, pageSize);
|
|
|
+ List<MeterReadRecord> records = new ArrayList<MeterReadRecord>();
|
|
|
+ for(DeviceDto device : deviceList) {
|
|
|
+ try{
|
|
|
+ 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);
|
|
|
+ }catch (Exception e){
|
|
|
+ log.error("Meter {} Reading Failed !",device.getDeviceNo(),e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 保存抄表记录
|
|
|
+ meterReadRecordMapper.insertList(records);
|
|
|
+ Thread.sleep(10000L);
|
|
|
+ }
|
|
|
+ log.info("end MeterReadRecordService createMeterReadRecord ,result = {} ", result);
|
|
|
+ }catch (Exception e){
|
|
|
+ log.error("Execute Create MeterReadRecord Tast Failed !",e);
|
|
|
+ }
|
|
|
return total;
|
|
|
}
|
|
|
|