LocationServiceImp.java 3.4 KB
package com.sunyo.energy.location.service.imp;

import com.sunyo.energy.location.dao.LocationMapper;
import com.sunyo.energy.location.model.ElectricityMeter;
import com.sunyo.energy.location.model.WaterMeter;
import com.sunyo.energy.location.service.ElectricityMeterService;
import com.sunyo.energy.location.service.LocationService;
import com.sunyo.energy.location.service.WaterMeterService;
import com.sunyo.energy.location.utils.AllUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class LocationServiceImp implements LocationService {

    @Autowired
    LocationMapper locationMapper;


    @Autowired
    ElectricityMeterService electricityMeterService;

    @Autowired
    WaterMeterService waterMeterService;

    @Override
    public List userPayList(String roomNumber, int userId) {

        try {
            // 房间号如果为null  跳过
            if (!StringUtils.isEmpty(roomNumber)) {
                List<Map<String, Object>> list = new ArrayList<>();
                /**
                 * 水费查询
                 */
                // 查询房间号 水表本地查询list
                Map<String, Object> thisLocalityWaterMap = locationMapper.userPayList(roomNumber);
                Map<String, Object> distanceWaterMap = new HashMap<>();
                // 查询该房间号的水表编号
                String wmId = locationMapper.findWmId(roomNumber);
                if (!"".equals(wmId)) {
                    Map<String, Object> waterMaps = new HashMap<>();
                    WaterMeter realTime = waterMeterService.findRealTime(wmId);
                    String subtraction = AllUtils.nubmerSubtraction(realTime.getWmSacc(), realTime.getWmLacc());
                    distanceWaterMap.put("subtraction", subtraction);
                    distanceWaterMap.put("wmSacc", realTime.getWmSacc());
                    distanceWaterMap.put("wmFmstate", realTime.getWmFmstate());
                    distanceWaterMap.put("wmLacc", realTime.getWmLacc());
                    distanceWaterMap.put("wmId", wmId);
                    distanceWaterMap.put("roomNumber", roomNumber);
                    distanceWaterMap.put("userId", userId);
                    list.add(distanceWaterMap);
                }
                /**
                 * 电费查询  通过房间号查询设备id
                 */
                String eeId = locationMapper.eeId(roomNumber);
                if (!"".equals(eeId)) {
                    ElectricityMeter energyInfoForRealTime = electricityMeterService.getEnergyInfoForRealTime(eeId);
                    Map<String, Object> eeMap = new HashMap<>();
                    if (energyInfoForRealTime != null) {
                        eeMap.put("deviceId", energyInfoForRealTime.getDeviceId());
                        eeMap.put("balance", energyInfoForRealTime.getBalance());
                        eeMap.put("wmId", "");
                        eeMap.put("roomNumber", roomNumber);
                        eeMap.put("userId", userId);
                        list.add(eeMap);
                    }
                }
                return list;
            }
            return null;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }


}