|  | @@ -0,0 +1,91 @@
 | 
												
													
														
															|  | 
 |  | +package com.bz.smart_city.service.sync;
 | 
												
													
														
															|  | 
 |  | +
 | 
												
													
														
															|  | 
 |  | +import com.bz.smart_city.commom.model.ListObjectWrapper;
 | 
												
													
														
															|  | 
 |  | +import com.bz.smart_city.dao.ClearingRecordItemMapper;
 | 
												
													
														
															|  | 
 |  | +import com.bz.smart_city.dao.CommunityMapper;
 | 
												
													
														
															|  | 
 |  | +import com.bz.smart_city.dao.DeviceMapper;
 | 
												
													
														
															|  | 
 |  | +import com.bz.smart_city.dao.MeterReadRecordMapper;
 | 
												
													
														
															|  | 
 |  | +import com.bz.smart_city.dto.ClearingDataDTO;
 | 
												
													
														
															|  | 
 |  | +import com.bz.smart_city.dto.syncdata.AreaRequstData;
 | 
												
													
														
															|  | 
 |  | +import com.bz.smart_city.dto.syncdata.AreaResponseData;
 | 
												
													
														
															|  | 
 |  | +import com.bz.smart_city.dto.syncdata.ClearDataDto;
 | 
												
													
														
															|  | 
 |  | +import com.bz.smart_city.dto.syncdata.MeterReadDataDto;
 | 
												
													
														
															|  | 
 |  | +import com.bz.smart_city.entity.Device;
 | 
												
													
														
															|  | 
 |  | +import com.bz.smart_city.entity.MeterReadRecord;
 | 
												
													
														
															|  | 
 |  | +import com.bz.smart_city.service.SyncDataService;
 | 
												
													
														
															|  | 
 |  | +import org.springframework.beans.factory.annotation.Autowired;
 | 
												
													
														
															|  | 
 |  | +import org.springframework.stereotype.Service;
 | 
												
													
														
															|  | 
 |  | +
 | 
												
													
														
															|  | 
 |  | +import java.util.ArrayList;
 | 
												
													
														
															|  | 
 |  | +import java.util.HashMap;
 | 
												
													
														
															|  | 
 |  | +import java.util.List;
 | 
												
													
														
															|  | 
 |  | +import java.util.Map;
 | 
												
													
														
															|  | 
 |  | +@Service
 | 
												
													
														
															|  | 
 |  | +public class SyncDataServiceImpl implements SyncDataService {
 | 
												
													
														
															|  | 
 |  | +    @Autowired
 | 
												
													
														
															|  | 
 |  | +    private ClearingRecordItemMapper clearingRecordItemMapper;
 | 
												
													
														
															|  | 
 |  | +    @Autowired
 | 
												
													
														
															|  | 
 |  | +    private DeviceMapper deviceMapper;
 | 
												
													
														
															|  | 
 |  | +    @Autowired
 | 
												
													
														
															|  | 
 |  | +    private MeterReadRecordMapper meterReadRecordMapper;
 | 
												
													
														
															|  | 
 |  | +    @Autowired
 | 
												
													
														
															|  | 
 |  | +    private CommunityMapper communityMapper;
 | 
												
													
														
															|  | 
 |  | +    @Override
 | 
												
													
														
															|  | 
 |  | +    public ListObjectWrapper<ClearDataDto> queryClearingDataList(String yyyymm, List<String> fileNos, String customerNo) {
 | 
												
													
														
															|  | 
 |  | +        Map<String, Object> deviceInfo = getDeviceInfo(fileNos, customerNo);
 | 
												
													
														
															|  | 
 |  | +        if(deviceInfo==null){
 | 
												
													
														
															|  | 
 |  | +            return null;
 | 
												
													
														
															|  | 
 |  | +        }
 | 
												
													
														
															|  | 
 |  | +        List<Long> deviceIds = (List<Long>)deviceInfo .get("ids");
 | 
												
													
														
															|  | 
 |  | +        List<ClearingDataDTO> sycnClearing = clearingRecordItemMapper.findSycnClearing(deviceIds, yyyymm);
 | 
												
													
														
															|  | 
 |  | +        Map<Long,String>idMatchFileNo= (Map<Long, String>) deviceInfo.get("matchs");
 | 
												
													
														
															|  | 
 |  | +        List<ClearDataDto>result=new ArrayList<>();
 | 
												
													
														
															|  | 
 |  | +        sycnClearing.forEach(clearingDataDTO -> {
 | 
												
													
														
															|  | 
 |  | +            ClearDataDto clearDataDto=new ClearDataDto();
 | 
												
													
														
															|  | 
 |  | +            clearDataDto.setFileNo(idMatchFileNo.get(clearingDataDTO.getDeviceId()));
 | 
												
													
														
															|  | 
 |  | +            clearDataDto.setReading(clearingDataDTO.getWsvCost());
 | 
												
													
														
															|  | 
 |  | +            result.add(clearDataDto);
 | 
												
													
														
															|  | 
 |  | +        });
 | 
												
													
														
															|  | 
 |  | +        return new ListObjectWrapper<ClearDataDto>(result);
 | 
												
													
														
															|  | 
 |  | +    }
 | 
												
													
														
															|  | 
 |  | +
 | 
												
													
														
															|  | 
 |  | +    @Override
 | 
												
													
														
															|  | 
 |  | +    public ListObjectWrapper<MeterReadDataDto> queryMeterReadData(String readTime, List<String> fileNos, String customerNo) {
 | 
												
													
														
															|  | 
 |  | +        Map<String, Object> deviceInfo = getDeviceInfo(fileNos, customerNo);
 | 
												
													
														
															|  | 
 |  | +        if(deviceInfo==null){
 | 
												
													
														
															|  | 
 |  | +            return null;
 | 
												
													
														
															|  | 
 |  | +        }
 | 
												
													
														
															|  | 
 |  | +        List<Long> deviceIds = (List<Long>)deviceInfo .get("ids");
 | 
												
													
														
															|  | 
 |  | +        List<MeterReadRecord> syncMeterRecords = meterReadRecordMapper.findSyncMeterRecord(deviceIds, readTime);
 | 
												
													
														
															|  | 
 |  | +        List<MeterReadDataDto> meterReadDataDtos = new ArrayList<>();
 | 
												
													
														
															|  | 
 |  | +        Map<Long,String>idMatchFileNo= (Map<Long, String>) deviceInfo.get("matchs");
 | 
												
													
														
															|  | 
 |  | +        syncMeterRecords.forEach(syncMeterRecord->{
 | 
												
													
														
															|  | 
 |  | +            MeterReadDataDto meterReadDataDto = new MeterReadDataDto();
 | 
												
													
														
															|  | 
 |  | +            meterReadDataDto.setFileNo(idMatchFileNo.get(syncMeterRecord.getDeviceId()));
 | 
												
													
														
															|  | 
 |  | +            meterReadDataDto.setReading(syncMeterRecord.getReadData());
 | 
												
													
														
															|  | 
 |  | +            meterReadDataDtos.add(meterReadDataDto);
 | 
												
													
														
															|  | 
 |  | +        });
 | 
												
													
														
															|  | 
 |  | +        return new ListObjectWrapper<MeterReadDataDto>(meterReadDataDtos);
 | 
												
													
														
															|  | 
 |  | +    }
 | 
												
													
														
															|  | 
 |  | +    private Map<String,Object>getDeviceInfo(List<String> fileNoList, String customerNo){
 | 
												
													
														
															|  | 
 |  | +
 | 
												
													
														
															|  | 
 |  | +        if(fileNoList.size()>30){
 | 
												
													
														
															|  | 
 |  | +            return null;
 | 
												
													
														
															|  | 
 |  | +        }
 | 
												
													
														
															|  | 
 |  | +        List<Device> byFileNo = deviceMapper.findByFileNo(fileNoList, customerNo);
 | 
												
													
														
															|  | 
 |  | +        Map<Long,String>idMatchFileNo=new HashMap<>();
 | 
												
													
														
															|  | 
 |  | +        List<Long>deviceIds=new ArrayList<>();
 | 
												
													
														
															|  | 
 |  | +        byFileNo.forEach(device -> {
 | 
												
													
														
															|  | 
 |  | +            deviceIds.add(device.getId());
 | 
												
													
														
															|  | 
 |  | +            idMatchFileNo.put(device.getId(),device.getWaterMeterFileNo());
 | 
												
													
														
															|  | 
 |  | +        });
 | 
												
													
														
															|  | 
 |  | +        Map<String,Object>result=new HashMap<>();
 | 
												
													
														
															|  | 
 |  | +        result.put("ids",deviceIds);
 | 
												
													
														
															|  | 
 |  | +        result.put("matchs",idMatchFileNo);
 | 
												
													
														
															|  | 
 |  | +        return  result;
 | 
												
													
														
															|  | 
 |  | +    }
 | 
												
													
														
															|  | 
 |  | +    @Override
 | 
												
													
														
															|  | 
 |  | +    public AreaResponseData queryAreaByName(AreaRequstData areaRequstData) {
 | 
												
													
														
															|  | 
 |  | +        return  communityMapper.findCommunityByArea(areaRequstData);
 | 
												
													
														
															|  | 
 |  | +    }
 | 
												
													
														
															|  | 
 |  | +}
 |