package com.casic.missiles.modular.system.service.impl;

import com.baomidou.mybatisplus.plugins.Page;
import com.casic.missiles.core.util.SpringContextHolder;
import com.casic.missiles.modular.config.SluicewellProperties;
import com.casic.missiles.modular.system.constant.BusWellConst;
import com.casic.missiles.modular.system.enmus.HarmfulGasBusiness;
import com.casic.missiles.modular.system.enmus.TemphumBusiness;
import com.casic.missiles.modular.system.dto.*;
import com.casic.missiles.modular.system.model.BusWellInfo;
import com.casic.missiles.core.common.service.ICommonPermissionService;
import com.casic.missiles.core.datascope.DataScope;
import com.casic.missiles.core.util.ToolUtil;
import com.casic.missiles.modular.system.dao.BusWellInfoMapper;
import com.casic.missiles.modular.system.model.Dict;
import com.casic.missiles.modular.system.service.IBusWellInfoService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.casic.missiles.modular.system.util.Utility;
import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.BeanPropertyBindingResult;
import org.springframework.validation.FieldError;
import org.springframework.validation.Validator;

import java.io.Serializable;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * <p>
 * 闸井信息表 服务实现类
 * </p>
 *
 * @author stylefeng123
 * @since 2019-05-13
 */
@Service
public class BusWellInfoServiceImpl extends ServiceImpl<BusWellInfoMapper, BusWellInfo> implements IBusWellInfoService {
    private static final Logger logger = LoggerFactory.getLogger(BusWellInfoServiceImpl.class);

    @Autowired
    private ICommonPermissionService service;

    @Autowired
    private Validator validator;

    @Override
    public BusWellInfo selectById(Serializable id) {
        BusWellInfo wellInfo = super.selectById(id);
        wellInfo.setDeptName(service.getDeptName(wellInfo.getDeptid()));
        wellInfo.setAreaFullName(getAreaFullNameById(wellInfo.getArea()));

        return wellInfo;
    }

    @Transactional
    public List<BusWellInfo> selectDataScopePage(DataScope dataScope, Page<BusWellInfo> page, String keywords, String wellType, String deptid, String bfzt, String areaId) {
        List<BusWellInfo> list = this.baseMapper.selectDataScopePage(dataScope, page, keywords, wellType, deptid, bfzt, areaId);
        list.forEach(well -> {
            well.setDeptName(service.getDeptName(well.getDeptid()));
            well.setAreaFullName(getAreaFullNameById(well.getArea()));
        });
        return list;
    }


    public List<WatchDataDto> getWatchDatas(Long id) {

        List<DeviceInWellInfo> deviceInWellInfos = this.baseMapper.getDeviceInWellInfo(id);
        List<WatchDataDto> watchDataDtos = new ArrayList<>();

        for (DeviceInWellInfo deviceInWellInfo : deviceInWellInfos) {
            WatchDataDto watchDataDto = new WatchDataDto();
            watchDataDto.setDeviceId(deviceInWellInfo.getDeviceId());
            watchDataDto.setDevcode(deviceInWellInfo.getDevcode());
            watchDataDto.setInstallDate(deviceInWellInfo.getInstallDate());
            watchDataDto.setOnlineState(deviceInWellInfo.getOnlineState());
            watchDataDto.setOnlineStateName(service.getDictNameByCode("onlineStatus", deviceInWellInfo.getOnlineState()));

            DeviceData deviceData;
            DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

            switch (deviceInWellInfo.getTypeName()) {
                case "井盖状态监测仪":
                    deviceData = this.baseMapper.wellcoverData(deviceInWellInfo.getDevcode());
                    watchDataDto.setWatchType("井盖状态");
                    watchDataDto.setType("1");
                    if (ToolUtil.isNotEmpty(deviceData)) {
                        //井盖离线
                        if ("0".equals(watchDataDto.getOnlineState())) {
                            watchDataDto.setValue("离线");
                            watchDataDto.setData("离线");
                            watchDataDto.setLogtime(sdf.format(deviceData.getLogtime()));
                        } else if ("心跳".equals(deviceData.getData())) {
                            watchDataDto.setValue("井盖状态正常");
                            watchDataDto.setData("井盖状态正常");
                            watchDataDto.setLogtime(sdf.format(deviceData.getLogtime()));
                        } else {
                            watchDataDto.setValue(deviceData.getData());
                            watchDataDto.setData(deviceData.getData());
                            watchDataDto.setLogtime(sdf.format(deviceData.getLogtime()));
                        }
                    } else {
                        watchDataDto.setValue("无数据");
                        watchDataDto.setData("无数据");
                    }
                    watchDataDtos.add(watchDataDto);
                    break;

                case "液位监测仪":
                    deviceData = this.baseMapper.liquidData(deviceInWellInfo.getDevcode());
                    if (ToolUtil.isNotEmpty(deviceData)) {
                        watchDataDto.setWatchType("井内水位");
                        watchDataDto.setType("2");

                        watchDataDto.setValue(deviceData.getData() + "m");
                        watchDataDto.setData(deviceData.getData() + "m");
                        watchDataDto.setLogtime(sdf.format(deviceData.getLogtime()));
                        watchDataDtos.add(watchDataDto);
                    }
                    break;

                case "有害气体监测仪":
                    deviceData = this.baseMapper.harmfulgasData(deviceInWellInfo.getDevcode());
                    if (ToolUtil.isNotEmpty(deviceData)) {
                        String[] harmfulGasDatas = deviceData.getData().split(",");
                        HarmfulGasBusiness[] harmfulGasBusinesses = HarmfulGasBusiness.values();

                        for (int i = 0; i < harmfulGasDatas.length; i++) {
                            watchDataDto.setWatchType(harmfulGasBusinesses[i].getDesc());
                            watchDataDto.setType("3");
                            watchDataDto.setValue(harmfulGasDatas[i] + harmfulGasBusinesses[i].getUnit());
                            watchDataDto.setData(harmfulGasDatas[i] + harmfulGasBusinesses[i].getUnit());
                            watchDataDto.setLogtime(sdf.format(deviceData.getLogtime()));
                            watchDataDtos.add((WatchDataDto) watchDataDto.clone());
                        }
                    }
                    break;

                case "燃气智能监测终端":
                    deviceData = this.baseMapper.gasData(deviceInWellInfo.getDevcode());
                    if (ToolUtil.isNotEmpty(deviceData)) {
                        watchDataDto.setWatchType("燃气浓度");
                        watchDataDto.setType("4");

                        watchDataDto.setValue(deviceData.getData() + "%LEL");
                        watchDataDto.setData(deviceData.getData() + "%LEL");
                        watchDataDto.setLogtime(sdf.format(deviceData.getLogtime()));
                        watchDataDtos.add(watchDataDto);
                    }
                    break;

                case "温湿度监测仪":
                    deviceData = this.baseMapper.temphumData(deviceInWellInfo.getDevcode());
                    if (ToolUtil.isNotEmpty(deviceData)) {
                        String[] temphumDatas = deviceData.getData().split(",");
                        TemphumBusiness[] temphumBusinesses = TemphumBusiness.values();

                        for (int i = 0; i < temphumDatas.length; i++) {
                            watchDataDto.setWatchType(temphumBusinesses[i].getDesc());
                            watchDataDto.setType("5");
                            watchDataDto.setValue(temphumDatas[i] + temphumBusinesses[i].getUnit());
                            watchDataDto.setData(temphumDatas[i] + temphumBusinesses[i].getUnit());
                            watchDataDto.setLogtime(sdf.format(deviceData.getLogtime()));
                            watchDataDtos.add((WatchDataDto) watchDataDto.clone());
                        }
                    }
                    break;

                case "开挖监测仪":
                    deviceData = this.baseMapper.digData(deviceInWellInfo.getDevcode());
                    if (ToolUtil.isNotEmpty(deviceData)) {
                        watchDataDto.setWatchType("开挖状态");
                        watchDataDto.setType("6");

                        watchDataDto.setValue(deviceData.getData() + "mg");
                        watchDataDto.setData(deviceData.getData() + "mg");
                        watchDataDto.setLogtime(sdf.format(deviceData.getLogtime()));
                        watchDataDtos.add(watchDataDto);
                    }
                    break;

                case "噪声记录仪":
                    deviceData = this.baseMapper.noiseData(deviceInWellInfo.getDevcode());
                    if (ToolUtil.isNotEmpty(deviceData)) {
                        watchDataDto.setWatchType("管线噪声");
                        watchDataDto.setType("8");

                        watchDataDto.setValue(deviceData.getData() + "mg");
                        watchDataDto.setData(deviceData.getData() + "mg");
                        watchDataDto.setLogtime(sdf.format(deviceData.getLogtime()));
                        watchDataDtos.add(watchDataDto);
                    }
                    break;

                case "井盖定位监测仪":
                    deviceData = this.baseMapper.wellcoverlocaData(deviceInWellInfo.getDevcode());
                    if (ToolUtil.isNotEmpty(deviceData)) {
                        watchDataDto.setWatchType("井盖位置");
                        watchDataDto.setType("7");

                        watchDataDto.setValue(deviceData.getData());
                        watchDataDto.setData(deviceData.getData());
                        watchDataDto.setLogtime(sdf.format(deviceData.getLogtime()));
                        watchDataDtos.add(watchDataDto);
                    }
                    break;

                case "燃气智能监测终端(一体化)":
                    deviceData = this.baseMapper.lgGasData(deviceInWellInfo.getDevcode());
                    watchDataDto.setWatchType("燃气浓度");
                    watchDataDto.setType("10");
                    if (ToolUtil.isNotEmpty(deviceData)) {

                        Double dValue = Double.parseDouble(deviceData.getData());
                        if (dValue <= 20.0) {
                            watchDataDto.setValue(deviceData.getData() + "%LEL");
                            watchDataDto.setData(deviceData.getData() + "%LEL");
                        } else {
                            DecimalFormat df = new DecimalFormat("0.00");
                            dValue = dValue / 20.0;
                            watchDataDto.setValue(df.format(dValue) + "%VOL");
                            watchDataDto.setData(df.format(dValue) + "%VOL");
                        }
                        watchDataDto.setLogtime(sdf.format(deviceData.getLogtime()));
                    } else {
                        watchDataDto.setValue("无数据");
                        watchDataDto.setData("无数据");
                    }
                    watchDataDtos.add((WatchDataDto) watchDataDto.clone());

                    deviceData = this.baseMapper.lgLiquidData(deviceInWellInfo.getDevcode());
                    watchDataDto.setWatchType("井内水位");
                    watchDataDto.setType("10");
                    if (ToolUtil.isNotEmpty(deviceData)) {

                        watchDataDto.setValue(deviceData.getData() + "m");
                        watchDataDto.setData(deviceData.getData() + "m");
                        watchDataDto.setLogtime(sdf.format(deviceData.getLogtime()));
                    } else {
                        watchDataDto.setValue("无数据");
                        watchDataDto.setData("无数据");
                    }
                    watchDataDtos.add((WatchDataDto) watchDataDto.clone());
                    break;

                default://未知设备
                    logger.info("未知设备！");
                    break;
            }
        }

        return watchDataDtos;
    }


    @Override
    public List<DeviceDataDto> getDeviceDatas(String devTypeName, String devcode, String status) {
        List<DeviceDataDto> deviceDataDtoList = new ArrayList<>();
        DeviceDataDto deviceDataDto = new DeviceDataDto();
        DeviceData deviceData;
        DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        switch (devTypeName) {
            case "井盖状态监测仪":
                deviceData = this.baseMapper.wellcoverData(devcode);
                deviceDataDto.setTypeName("井盖状态");
                if (ToolUtil.isNotEmpty(deviceData)) {
                    //井盖离线
                    if ("0".equals(status)) {
                        deviceDataDto.setValue("离线");
                        deviceDataDto.setLogtime(sdf.format(deviceData.getLogtime()));
                    } else if ("心跳".equals(deviceData.getData())) {
                        deviceDataDto.setValue("井盖状态正常");
                        deviceDataDto.setLogtime(sdf.format(deviceData.getLogtime()));
                    } else {
                        deviceDataDto.setValue(deviceData.getData());
                        deviceDataDto.setLogtime(sdf.format(deviceData.getLogtime()));
                    }
                } else {
                    deviceDataDto.setValue("无数据");
                }
                deviceDataDtoList.add(deviceDataDto);
                break;

            case "液位监测仪":
                deviceData = this.baseMapper.liquidData(devcode);
                if (ToolUtil.isNotEmpty(deviceData)) {
                    deviceDataDto.setTypeName("井内水位");
                    deviceDataDto.setValue(deviceData.getData() + "m");
                    deviceDataDto.setLogtime(sdf.format(deviceData.getLogtime()));
                    deviceDataDtoList.add(deviceDataDto);
                }
                break;

            case "有害气体监测仪":
                deviceData = this.baseMapper.harmfulgasData(devcode);
                if (ToolUtil.isNotEmpty(deviceData)) {
                    String[] harmfulGasDatas = deviceData.getData().split(",");
                    HarmfulGasBusiness[] harmfulGasBusinesses = HarmfulGasBusiness.values();
                    for (int i = 0; i < harmfulGasDatas.length; i++) {
                        deviceDataDto = new DeviceDataDto();
                        deviceDataDto.setTypeName(harmfulGasBusinesses[i].getDesc());
                        deviceDataDto.setValue(harmfulGasDatas[i] + harmfulGasBusinesses[i].getUnit());
                        deviceDataDto.setLogtime(sdf.format(deviceData.getLogtime()));
                        deviceDataDtoList.add((DeviceDataDto) deviceDataDto.clone());
                    }
                }
                break;
            case "燃气智能监测终端":
                deviceData = this.baseMapper.gasData(devcode);
                if (ToolUtil.isNotEmpty(deviceData)) {
                    deviceDataDto.setTypeName("燃气浓度");
                    deviceDataDto.setValue(deviceData.getData() + "%LEL");
                    deviceDataDto.setLogtime(sdf.format(deviceData.getLogtime()));
                    deviceDataDtoList.add(deviceDataDto);
                }
                break;

            case "温湿度监测仪":
                deviceData = this.baseMapper.temphumData(devcode);
                if (ToolUtil.isNotEmpty(deviceData)) {
                    String[] temphumDatas = deviceData.getData().split(",");
                    TemphumBusiness[] temphumBusinesses = TemphumBusiness.values();
                    for (int i = 0; i < temphumDatas.length; i++) {
                        deviceDataDto = new DeviceDataDto();
                        deviceDataDto.setTypeName(temphumBusinesses[i].getDesc());
                        deviceDataDto.setValue(temphumDatas[i] + temphumBusinesses[i].getUnit());
                        deviceDataDto.setLogtime(sdf.format(deviceData.getLogtime()));
                        deviceDataDtoList.add((DeviceDataDto) deviceDataDto.clone());
                    }
                }
                break;

            case "开挖监测仪":
                deviceData = this.baseMapper.digData(devcode);
                if (ToolUtil.isNotEmpty(deviceData)) {
                    deviceDataDto.setTypeName("开挖状态");
                    deviceDataDto.setValue(deviceData.getData() + "mg");
                    deviceDataDto.setLogtime(sdf.format(deviceData.getLogtime()));
                    deviceDataDtoList.add(deviceDataDto);
                }
                break;

            case "噪声记录仪":
                deviceData = this.baseMapper.noiseData(devcode);
                if (ToolUtil.isNotEmpty(deviceData)) {
                    deviceDataDto.setTypeName("管线噪声");
                    deviceDataDto.setValue(deviceData.getData() + "mg");
                    deviceDataDto.setLogtime(sdf.format(deviceData.getLogtime()));
                    deviceDataDtoList.add(deviceDataDto);
                }
                break;
            case "井盖定位监测仪":
                deviceData = this.baseMapper.wellcoverlocaData(devcode);
                if (ToolUtil.isNotEmpty(deviceData)) {
                    deviceDataDto.setTypeName("井盖位置");
                    deviceDataDto.setValue(deviceData.getData());
                    deviceDataDto.setLogtime(sdf.format(deviceData.getLogtime()));
                    deviceDataDtoList.add(deviceDataDto);
                }
                break;

            case "燃气智能监测终端(一体化)":
                deviceData = this.baseMapper.lgGasData(devcode);
                deviceDataDto.setTypeName("燃气浓度");
                if (ToolUtil.isNotEmpty(deviceData)) {

                    Double dValue = Double.parseDouble(deviceData.getData());
                    if (dValue <= 20.0) {
                        deviceDataDto.setValue(deviceData.getData() + "%LEL");
                    } else {
                        DecimalFormat df = new DecimalFormat("0.00");
                        dValue = dValue / 20.0;
                        deviceDataDto.setValue(df.format(dValue) + "%VOL");
                    }
                    deviceDataDto.setLogtime(sdf.format(deviceData.getLogtime()));
                } else {
                    deviceDataDto.setValue("无数据");
                }
                deviceDataDtoList.add(deviceDataDto);

                deviceData = this.baseMapper.lgLiquidData(devcode);
                deviceDataDto.setTypeName("井内水位");
                if (ToolUtil.isNotEmpty(deviceData)) {

                    deviceDataDto.setValue(deviceData.getData() + "m");
                    deviceDataDto.setLogtime(sdf.format(deviceData.getLogtime()));
                } else {
                    deviceDataDto.setValue("无数据");
                }
                deviceDataDtoList.add((DeviceDataDto) deviceDataDto.clone());
                break;

            default://未知设备
                logger.info("未知设备！");
                break;
        }
        return deviceDataDtoList;
    }


    public BfztCountDataDto getBfztCountData(List<Long> deptIds, Boolean isApp) {
        return this.baseMapper.bfztCountData(deptIds, isApp);
    }

    @Override
    public List<BatchExportDataDto> selectDataScope(DataScope dataScope, Page<BatchExportDataDto> page, String deviceType, String deptid, String keywords) {
        return this.baseMapper.selectDataScope(dataScope, page, deviceType, deptid, keywords);
    }

    @Override
    public List<BatchExportDataDto> getBatchExportData(DataScope dataScope, Page<BatchExportDataDto> page, String deviceType, String deptid, String keywords) {
        return this.baseMapper.getBatchExportData(dataScope, page, deviceType, deptid, keywords);
    }

    public Integer getDeviceCountData(Long id) {
        return this.baseMapper.deviceCountData(id);
    }

    public String getDeptNameData(String deptid) {
        return this.baseMapper.deptNameData(deptid);
    }

    public String getAreaFullNameById(String area) {
        String fullName = this.baseMapper.getArea(area);
        String pid = this.baseMapper.getAreaPId(area);
        if (pid == null) {
            return fullName;
        }
        if (pid.equals("0")) {
            return fullName;
        } else {
            fullName = getAreaFullNameById(pid) + "/" + fullName;
            return fullName;
        }
    }

    public List<Long> deleteBatchByIds(List<Long> ids) {

        List<Long> lists = new ArrayList<>();
        for (Long id : ids) {
            Integer count = this.baseMapper.deviceCountData(id);
            if (count > 0) {
                //井中有有效设备，不允许删除
                lists.add(id);
            } else {
                this.baseMapper.deleteById(id);
            }
        }

        return lists;
    }

    @Transactional
    @Override
    public List<String> addWellBatch(List<BusWellInfo> results) {

        BeanPropertyBindingResult beanPropertyBindingResult = new BeanPropertyBindingResult(BusWellInfo.class, "井导入校验");

        List<String> list = new ArrayList<>();
        List<String> gpsCoordinates = new ArrayList<>();

        if (ToolUtil.isNotEmpty(results)) {
            List<Dict> dicts = service.findInDictByCode(BusWellConst.SLUICEWELL_TYPE);//闸井类型
            Map<String, String> sluicewellTypeMap = new HashMap<>();
            dicts.forEach(dict -> {
                sluicewellTypeMap.put(dict.getName(), dict.getCode());
            });

            final Integer[] index = {0};
            for (BusWellInfo well : results) {
                index[0]++;
                validator.validate(well, beanPropertyBindingResult);
                if (beanPropertyBindingResult.hasErrors()) {
                    List<FieldError> errors = beanPropertyBindingResult.getFieldErrors();

                    //导入表格总共有10个字段，如果同一行有多于10个错误，则表示此行为空
                    if (errors.size() >= 10) {
                        break;
                    }

                    errors.forEach(error -> {
                                list.add("第" + index[0] + "行，".concat(error.getDefaultMessage()));
                            }
                    );
                    break;
                }

                //其他相关性校验
                String areaId = this.baseMapper.getAreaId(well.getQu(), well.getArea());
                if (ToolUtil.isNotEmpty(areaId)) {
                    well.setArea(areaId);
                } else {
                    list.add("第" + index[0] + "行，区与街道名不对应！");
                    break;
                }

                if (sluicewellTypeMap.containsKey(well.getWellType())) {
                    well.setWellType(sluicewellTypeMap.get(well.getWellType()));
                } else {
                    list.add("第" + index[0] + "行，井类型不存在！");
                    break;
                }

                String coordinateX = well.getCoordinateX().length() > 10 ? well.getCoordinateX().substring(0, 10) : well.getCoordinateX();
                String coordinateY = well.getCoordinateY().length() > 9 ? well.getCoordinateY().substring(0, 9) : well.getCoordinateY();
                well.setCoordinateX(coordinateX);
                well.setCoordinateY(coordinateY);

                gpsCoordinates.add(coordinateX + "," + coordinateY);

                logger.info("第" + index[0] + "行校验完毕！");
            }

            if (ToolUtil.isNotEmpty(list)) {
                return list;
            }

            SluicewellProperties sluicewellProperties = SpringContextHolder.getBean(SluicewellProperties.class);
            String coordinate = sluicewellProperties.getCoordinate().toLowerCase();
            List<String> convertCoordinates = null;

            if ("baidu".equals(coordinate)) {
                convertCoordinates = Utility.convertBaiduAPI(gpsCoordinates);
            } else if ("gaode".equals(coordinate)) {
                convertCoordinates = Utility.convertGaodeAPI(gpsCoordinates);
            }

            if (ToolUtil.isNotEmpty(convertCoordinates) &&
                    results.size() == convertCoordinates.size()) {

                if ("baidu".equals(coordinate)) {
                    for (int i = 0; i < convertCoordinates.size(); i++) {
                        String[] xy = convertCoordinates.get(i).split(",");
                        results.get(i).setLngBaidu(xy[0]);
                        results.get(i).setLatBaidu(xy[1]);
                    }
                } else if ("gaode".equals(coordinate)) {
                    for (int i = 0; i < convertCoordinates.size(); i++) {
                        String[] xy = convertCoordinates.get(i).split(",");
                        results.get(i).setLngGaode(xy[0]);
                        results.get(i).setLatGaode(xy[1]);
                    }
                }
            }

            this.insertBatch(results);

        } else {
            list.add("导入数据不能为空");
        }
        return list;
    }

    @Override
    public List<BusWellInfoDto> getWellList(DataScope dataScope, String keywords, String wellType, String deptid) {
        return this.baseMapper.getWellList(dataScope, keywords, wellType, deptid);
    }

    @Override
    public List<BusWellInfoDto> getAlarmWellList(DataScope dataScope, String keywords, String wellType, String deptid) {
        return this.baseMapper.getAlarmWellList(dataScope, keywords, wellType, deptid);
    }

    @Override
    public List<BusWellInfoDto> getNotAlarmWellList(DataScope dataScope, String keywords, String wellType, String deptid) {
        return this.baseMapper.getNotAlarmWellList(dataScope, keywords, wellType, deptid);
    }

    public String getAreaPid(String id) {
        return this.baseMapper.getAreaPId(id);
    }

    @Transactional
    public void updateBatchBfcf(String keywords, String wellType, String deptid, String bfzt, List<Long> deptIds) {

        this.baseMapper.updateBatchBfcf(keywords, wellType, deptid, bfzt, deptIds);
    }


    @Override
    public Boolean isExistWellCode(String wellCode) {
        return this.baseMapper.isExistWellCode(wellCode);
    }

    @Override
    public Boolean changeCoordinates(int startNumber) {
        //
        List<BusWellInfo> wellList = this.baseMapper.getWellListAll();
        try {
            for (int i = 0; i < wellList.size(); i++) {
                if (i < startNumber) {
                    continue;
                }
                BusWellInfo wellInfo = wellList.get(i);
                // 获取84坐标
                String coordinateX = wellInfo.getCoordinateX();
                String coordinateY = wellInfo.getCoordinateY();
                // 转换高德百度坐标
                Map<String, Object> baiduCoordinate = Utility.convertBaiduAPI(coordinateX, coordinateY);
                Map<String, Object> gaodeCoordinate = Utility.convertGaodeAPI(coordinateX, coordinateY);
                // 设置百度坐标
                wellInfo.setLngBaidu(baiduCoordinate.get("x").toString());
                wellInfo.setLatBaidu(baiduCoordinate.get("y").toString());
                // 设置高德坐标
                wellInfo.setLngGaode(gaodeCoordinate.get("x").toString());
                wellInfo.setLatGaode(gaodeCoordinate.get("y").toString());
                this.baseMapper.updateById(wellInfo);
                System.out.println(i + " : " + wellInfo.getWellCode() + "|" + wellInfo.getCoordinateX() + "," + wellInfo.getCoordinateY() + "|" + wellInfo.getLngBaidu() + "," + wellInfo.getLatBaidu() + "|" + wellInfo.getLngGaode() + "," + wellInfo.getLatGaode());
            }
            return true;
        } catch (Exception e) {
            return false;
        }
    }

    @Override
    public List<DeviceInfoDto> getDeviceList(DataScope dataScope) {
        return this.baseMapper.getDeviceList(dataScope);
    }

    @Override
    public DeviceInfoDto selectDeviceById(Long id) {
        return this.baseMapper.selectDeviceById(id);
    }
}
