/**
 * Copyright 2019 DH
 * All right reserved.
 * 项目名称: 运维系统
 * 创建日期:2022/8/22
 */
package org.springblade.modules.baseinfo.rtu.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.*;
import lombok.AllArgsConstructor;
import org.springblade.constant.BusinessConstant;
import org.springblade.core.boot.ctrl.BladeController;

import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.secure.BladeUser;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;

import org.springblade.modules.baseinfo.org.entity.DeptRegionEntity;
import org.springblade.modules.baseinfo.org.service.IDeptRegionService;
import org.springblade.modules.baseinfo.region.entity.RegionInfoEntity;
import org.springblade.modules.baseinfo.region.entity.RegionTreeNodeEntity;
import org.springblade.modules.baseinfo.region.service.IBaseInfoRegionService;
import org.springblade.modules.baseinfo.rtu.dto.RtuInfoDTO;
import org.springblade.modules.baseinfo.rtu.entity.RtuInfoEntity;
import org.springblade.modules.baseinfo.rtu.service.IRtuBaseInfoService;
import org.springblade.modules.baseinfo.rtu.vo.RtuInfoVO;
import org.springblade.modules.baseinfo.rtu.vo.RtuStatisticsInfoVO;
import org.springblade.modules.baseinfo.rtu.wrapper.RtuInfoWrapper;

import org.springblade.modules.business.data.entity.RtuDataRainEntity;
import org.springblade.modules.business.data.entity.RtuDataRiverEntity;
import org.springblade.modules.business.data.entity.RtuDataRsvrEntity;
import org.springblade.modules.business.data.service.IRtuDataRainService;
import org.springblade.modules.business.data.service.IRtuDataRiverService;
import org.springblade.modules.business.data.service.IRtuDataRsvrService;
import org.springblade.modules.business.rtumanage.entity.RtuStatusEntity;
import org.springblade.modules.business.rtumanage.service.IRtuManageService;
import org.springblade.modules.business.warning.dto.RtuWarningInfoDTO;
import org.springblade.modules.business.warning.service.IRtuWarningService;
import org.springblade.modules.system.entity.Dept;
import org.springblade.modules.system.entity.DictBiz;
import org.springblade.modules.system.service.IDeptService;
import org.springblade.modules.system.service.IDictBizService;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;


/***
 * Date:2022/8/22
 * Title: 测站信息管理接口
 * Description：对本文件的详细描述，原则上不能少于30字
 * @author dylan
 * @version 1.0
 * Remark：认为有必要的其他信息
 */
@RestController
@RequestMapping("galaxy-business/rtu/base")
@AllArgsConstructor
@Api(value = "测站设备基础管理", tags = "测站设备基础管理")
public class RtuBaseInfoController extends BladeController {
	private final IRtuBaseInfoService rtuBaseInfoService;
	private final IDeptService deptService;
	private final IRtuWarningService rtuWarningService;
	private final IRtuManageService rtuManageService;
	private final IRtuDataRainService rtuDataRainService;
	private final IRtuDataRiverService rtuDataRiverService;
	private final IRtuDataRsvrService rtuDataRsvrService;
	private final IDictBizService dictBizService;
	private final IDeptRegionService deptRegionService;
	private final IBaseInfoRegionService regionService;


	/**
	 * 分页
	 */
	@GetMapping("/list")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "rtuName", value = "测站名称", paramType = "query", dataType = "string"),
		@ApiImplicitParam(name = "rtuCode", value = "测站编码", paramType = "query", dataType = "string"),
	})
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "不分页")
	public R<List<RtuInfoVO>> list(@ApiIgnore RtuInfoDTO rtuInfoDTO) {
		if (rtuInfoDTO.getRtuKind() != null && "1".equals(rtuInfoDTO.getRtuKind())) {
			rtuInfoDTO.setIsRain(1);
		} else if (rtuInfoDTO.getRtuKind() != null && "2".equals(rtuInfoDTO.getRtuKind())) {
			rtuInfoDTO.setIsRiver(1);
			//rtuInfoDTO.setIsRes(1);
		} else if (rtuInfoDTO.getRtuKind() != null && "3".equals(rtuInfoDTO.getRtuKind())) {
			rtuInfoDTO.setIsGround(1);
		} else if (rtuInfoDTO.getRtuKind() != null && "4".equals(rtuInfoDTO.getRtuKind())) {
			rtuInfoDTO.setIsVideo(1);
		}
		LambdaQueryWrapper<RtuInfoEntity> wrapper = Wrappers.<RtuInfoEntity>query().lambda();
		if (null != rtuInfoDTO.getRtuName()) {
			wrapper.like(RtuInfoEntity::getRtuName, rtuInfoDTO.getRtuName());
		}
		if (null != rtuInfoDTO.getRtuCode()) {
			wrapper.like(RtuInfoEntity::getRtuCode, rtuInfoDTO.getRtuCode());
		}
		wrapper.orderByAsc(RtuInfoEntity::getRtuCode);
		List<RtuInfoEntity> pages = rtuBaseInfoService.list(wrapper);
		return R.data(RtuInfoWrapper.build().listVO(pages));
	}

	/**
	 * 多表联合查询自定义分页
	 */
	@GetMapping("/page")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "rtuName", value = "测站名称", paramType = "query", dataType = "string"),
		@ApiImplicitParam(name = "rtuCode", value = "测站编码", paramType = "query", dataType = "string"),
		@ApiImplicitParam(name = "adCode", value = "行政区划编码", paramType = "query", dataType = "string"),
	})
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "分页")
	public R<IPage<RtuInfoVO>> page(@ApiIgnore RtuInfoDTO rtuInfoDTO, Query query) {
		BladeUser user = AuthUtil.getUser();
//		if (BusinessConstant.ROLE_SYS_ADMIN.equals(user.getRoleName())) {
//			if (rtuInfoDTO.getAdCode() == null) {
//				rtuInfoDTO.setAdCode(BusinessConstant.REGION_NM_ADCODE);
//			}
//		} else if (BusinessConstant.ROLE_ORG_ADMIN.equals(user.getRoleName()) || BusinessConstant.ROLE_COMPANY_ADMIN.equals(user.getRoleName()) || BusinessConstant.ROLE_COMPANY_SERVICE_PERSON.equals(user.getRoleName())) {
//			if (rtuInfoDTO.getAdCode() == null) {
//				LambdaQueryWrapper<DeptRegionEntity> deptRegionEntityLambdaQueryWrapper = Wrappers.<DeptRegionEntity>query().lambda();
//				deptRegionEntityLambdaQueryWrapper.eq(DeptRegionEntity::getIsDeleted, 0);
//				deptRegionEntityLambdaQueryWrapper.eq(DeptRegionEntity::getDeptId, Func.toLong(user.getDeptId()));
//				DeptRegionEntity deptRegionEntity = deptRegionService.getOne(deptRegionEntityLambdaQueryWrapper);
//				rtuInfoDTO.setAdCode(deptRegionEntity.getAdcd());
//			}
//		}
//		if (rtuInfoDTO.getAdCode() != null) {
//			RegionTreeNodeEntity node = this.regionService.getRegionNode(user.getRoleName(), user.getDeptId(), rtuInfoDTO.getAdCode());
//			if (null != node) {
//				rtuInfoDTO.setExcludeCode(node.getExclude());
//			}
//		}
//		if (rtuInfoDTO.getRtuKind() != null && "1".equals(rtuInfoDTO.getRtuKind())) {
//			rtuInfoDTO.setIsRain(1);
//		} else if (rtuInfoDTO.getRtuKind() != null && "2".equals(rtuInfoDTO.getRtuKind())) {
//			rtuInfoDTO.setIsRiver(1);
//		} else if (rtuInfoDTO.getRtuKind() != null && "3".equals(rtuInfoDTO.getRtuKind())) {
//			rtuInfoDTO.setIsGround(1);
//		} else if (rtuInfoDTO.getRtuKind() != null && "4".equals(rtuInfoDTO.getRtuKind())) {
//			rtuInfoDTO.setIsVideo(1);
//		}
		IPage<RtuInfoVO> pages = rtuBaseInfoService.selectPage(Condition.getPage(query), rtuInfoDTO);
		List<RtuInfoVO> list = pages.getRecords();
		for (RtuInfoVO vo : list) {
			RtuInfoWrapper.build().entityVO(vo);
		}
		return R.data(pages);
	}


	/**
	 * 详情
	 */
	@GetMapping("/detail")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "详情", notes = "传入rtuInfoEntity")
	public R<RtuInfoVO> detail(RtuInfoEntity rtuInfoEntity) {
		RtuInfoEntity detail = rtuBaseInfoService.getOne(Condition.getQueryWrapper(rtuInfoEntity));
		RtuInfoVO rtuInfoVO = RtuInfoWrapper.build().entityVO(detail);
		Dept dept = deptService.getById(detail.getOrgId());
		if (null != dept) {
			rtuInfoVO.setOrgName(dept.getDeptName());
		}
		LambdaQueryWrapper<RtuStatusEntity> statusWwrapper = Wrappers.<RtuStatusEntity>query().lambda();
		statusWwrapper.eq(RtuStatusEntity::getIsDeleted, 0);
		statusWwrapper.eq(RtuStatusEntity::getRtuCode, detail.getRtuCode());
		RtuStatusEntity statusEntity = rtuManageService.getOne(statusWwrapper);
		if (null != statusEntity) {
			rtuInfoVO.setLastUpTime(statusEntity.getLastUpTime());
		}
		if (detail.getIsRain() != null && detail.getIsRain() == 1) {
			LambdaQueryWrapper<RtuDataRainEntity> rainwrapper = Wrappers.<RtuDataRainEntity>query().lambda();
			rainwrapper.eq(RtuDataRainEntity::getRtuCode, detail.getRtuCode());
			rainwrapper.eq(RtuDataRainEntity::getIsDeleted, 0L);
			RtuDataRainEntity rainEntity = rtuDataRainService.getOne(rainwrapper);
			if (null != rainEntity) {
				rtuInfoVO.setDrp(rainEntity.getDrp());
			}
		}
		if (detail.getIsRiver() != null && detail.getIsRiver() == 1) {
			LambdaQueryWrapper<RtuDataRiverEntity> riverwrapper = Wrappers.<RtuDataRiverEntity>query().lambda();
			riverwrapper.eq(RtuDataRiverEntity::getRtuCode, detail.getRtuCode());
			riverwrapper.eq(RtuDataRiverEntity::getIsDeleted, 0L);
			RtuDataRiverEntity riverEntity = rtuDataRiverService.getOne(riverwrapper);
			if (null != riverEntity) {
				rtuInfoVO.setZ(riverEntity.getZ());
			}
		}
		if (detail.getIsRes() != null && detail.getIsRes() == 1) {
			LambdaQueryWrapper<RtuDataRsvrEntity> rsvrWrapper = Wrappers.<RtuDataRsvrEntity>query().lambda();
			rsvrWrapper.eq(RtuDataRsvrEntity::getRtuCode, detail.getRtuCode());
			rsvrWrapper.eq(RtuDataRsvrEntity::getIsDeleted, 0L);
			RtuDataRsvrEntity rsvrEntity = rtuDataRsvrService.getOne(rsvrWrapper);
			if (null != rsvrEntity) {
				rtuInfoVO.setRz(rsvrEntity.getRz());
			}
		}
		if (detail.getIsGround() != null && detail.getIsGround() == 1) {

		}
		if (null != detail.getWaterSensorType()) {
			DictBiz dictBiz = dictBizService.getById(detail.getWaterSensorType());
			if (null != dictBiz) {
				rtuInfoVO.setWaterSensorTypeText(dictBiz.getDictValue());
			}
		}
		if (null != detail.getGroundSensorType()) {
			DictBiz dictBiz = dictBizService.getById(detail.getGroundSensorType());
			if (null != dictBiz) {
				rtuInfoVO.setGroundSensorTypeText(dictBiz.getDictValue());
			}
		}
		if (null != detail.getSatelliteModel()) {
			DictBiz dictBiz = dictBizService.getById(detail.getSatelliteModel());
			if (null != dictBiz) {
				rtuInfoVO.setSatelliteModelText(dictBiz.getDictValue());
			}
		}
		return R.data(rtuInfoVO);
	}


	/**
	 * 新增
	 */
	@PostMapping("/save")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "新增", notes = "传入rtuInfoEntity")
	public R save(@RequestBody RtuInfoDTO dto) {
		if (Func.isNull(dto.getRtuCode())){
			R.fail("参数错误");
		}
		LambdaQueryWrapper<RtuInfoEntity> rtuwrapper = Wrappers.<RtuInfoEntity>query().lambda();
		rtuwrapper.eq(RtuInfoEntity::getRtuCode, dto.getRtuCode());
		rtuwrapper.last("limit 1");
		RtuInfoEntity entity = rtuBaseInfoService.getOne(rtuwrapper);
		if (null != entity) {
			return R.fail("测站编码已存在，请确认！");
		}
//		LambdaQueryWrapper<RegionInfoEntity> wrapper = Wrappers.<RegionInfoEntity>query().lambda();
//		wrapper.eq(RegionInfoEntity::getAdcd, dto.getAdCode());
//		wrapper.eq(RegionInfoEntity::getIsDeleted, 0L);
//		RegionInfoEntity regionInfoEntity = this.regionService.getOne(wrapper);
//		dto.setAdDist(regionInfoEntity.getAdnm());
//		LambdaQueryWrapper<RegionInfoEntity> citywrapper = Wrappers.<RegionInfoEntity>query().lambda();
//		citywrapper.eq(RegionInfoEntity::getAdcd, regionInfoEntity.getParentCode());
//		citywrapper.eq(RegionInfoEntity::getIsDeleted, 0L);
//		regionInfoEntity = this.regionService.getOne(citywrapper);
//		dto.setAdCity(regionInfoEntity.getAdnm());
		dto.setIsRain(0);
		dto.setIsRiver(0);
		dto.setIsRes(0);
		dto.setIsGround(0);
		dto.setIsVideo(0);
//		if (dto.getSiteKind() != null && dto.getSiteKind().length > 0) {
//			for (String kind : dto.getSiteKind()) {
//				if ("1".equals(kind)) {
//					dto.setIsRain(1);
//				} else if ("2".equals(kind)) {
//					dto.setIsRiver(1);
//				} else if ("3".equals(kind)) {
//					dto.setIsRes(1);
//				} else if ("4".equals(kind)) {
//					dto.setIsGround(1);
//				} else if ("5".equals(kind)) {
//					dto.setIsVideo(1);
//				}
//			}
//		}
		if (null != dto.getLng() && dto.getLng().trim().length() > 0) {
			String lng = this.getLng(dto.getLng().trim());
			dto.setLng(lng);
		}
		if (null != dto.getLat() && dto.getLat().trim().length() > 0) {
			String lat = this.getLat(dto.getLat().trim());
			dto.setLat(lat);
		}
		return R.status(rtuBaseInfoService.save(dto));
	}

	/**
	 * 修改
	 */
	@PostMapping("/update")
	@ApiOperationSupport(order = 5)
	@ApiOperation(value = "修改", notes = "传入RtuInfoDTO")
	public R update(@RequestBody RtuInfoDTO dto) {
		if (Func.isNull(dto.getId())){
			return R.fail("参数错误");
		}
//		LambdaQueryWrapper<RegionInfoEntity> wrapper = Wrappers.<RegionInfoEntity>query().lambda();
//		wrapper.eq(RegionInfoEntity::getAdcd, dto.getAdCode());
//		wrapper.eq(RegionInfoEntity::getIsDeleted, 0L);
//		RegionInfoEntity regionInfoEntity = this.regionService.getOne(wrapper);
//		dto.setAdDist(regionInfoEntity.getAdnm());
//		LambdaQueryWrapper<RegionInfoEntity> citywrapper = Wrappers.<RegionInfoEntity>query().lambda();
//		citywrapper.eq(RegionInfoEntity::getAdcd, regionInfoEntity.getParentCode());
//		citywrapper.eq(RegionInfoEntity::getIsDeleted, 0L);
//		regionInfoEntity = this.regionService.getOne(citywrapper);
//		dto.setAdCity(regionInfoEntity.getAdnm());
//		dto.setIsRain(0);
//		dto.setIsRiver(0);
//		dto.setIsRes(0);
//		dto.setIsGround(0);
//		dto.setIsVideo(0);
//		if (dto.getSiteKind() != null && dto.getSiteKind().length > 0) {
//			for (String kind : dto.getSiteKind()) {
//				if ("1".equals(kind)) {
//					dto.setIsRain(1);
//				} else if ("2".equals(kind)) {
//					dto.setIsRiver(1);
//				} else if ("3".equals(kind)) {
//					dto.setIsRes(1);
//				} else if ("4".equals(kind)) {
//					dto.setIsGround(1);
//				} else if ("5".equals(kind)) {
//					dto.setIsVideo(1);
//				}
//			}
//		}
		if (null != dto.getLng() && dto.getLng().trim().length() > 0) {
			String lng = this.getLng(dto.getLng().trim());
			dto.setLng(lng);
		}
		if (null != dto.getLat() && dto.getLat().trim().length() > 0) {
			String lat = this.getLat(dto.getLat().trim());
			dto.setLat(lat);
		}
		return R.status(rtuBaseInfoService.updateById(dto));
	}

	/**
	 * 新增或修改
	 */
	@PostMapping("/submit")
	@ApiOperationSupport(order = 6)
	@ApiOperation(value = "新增或修改", notes = "传入RtuInfoDTO")
	public R submit(@RequestBody RtuInfoDTO dto) {
//		LambdaQueryWrapper<RegionInfoEntity> wrapper = Wrappers.<RegionInfoEntity>query().lambda();
//		wrapper.eq(RegionInfoEntity::getAdcd, dto.getAdCode());
//		wrapper.eq(RegionInfoEntity::getIsDeleted, 0L);
//		RegionInfoEntity regionInfoEntity = this.regionService.getOne(wrapper);
//		dto.setAdDist(regionInfoEntity.getAdnm());
//		LambdaQueryWrapper<RegionInfoEntity> citywrapper = Wrappers.<RegionInfoEntity>query().lambda();
//		citywrapper.eq(RegionInfoEntity::getAdcd, regionInfoEntity.getParentCode());
//		citywrapper.eq(RegionInfoEntity::getIsDeleted, 0L);
//		regionInfoEntity = this.regionService.getOne(citywrapper);
//		dto.setAdCity(regionInfoEntity.getAdnm());
//		dto.setIsRain(0);
//		dto.setIsRiver(0);
//		dto.setIsRes(0);
//		dto.setIsGround(0);
//		dto.setIsVideo(0);
//		if (dto.getSiteKind() != null && dto.getSiteKind().length > 0) {
//			for (String kind : dto.getSiteKind()) {
//				if ("1".equals(kind)) {
//					dto.setIsRain(1);
//				} else if ("2".equals(kind)) {
//					dto.setIsRiver(1);
//				} else if ("3".equals(kind)) {
//					dto.setIsRes(1);
//				} else if ("4".equals(kind)) {
//					dto.setIsGround(1);
//				} else if ("5".equals(kind)) {
//					dto.setIsVideo(1);
//				}
//			}
//		}
		if (null != dto.getLng() && dto.getLng().trim().length() > 0) {
			String lng = this.getLng(dto.getLng().trim());
			dto.setLng(lng);
		}
		if (null != dto.getLat() && dto.getLat().trim().length() > 0) {
			String lat = this.getLat(dto.getLat().trim());
			dto.setLat(lat);
		}
		return R.status(rtuBaseInfoService.saveOrUpdate(dto));
	}

	/**
	 * 删除
	 */
	@PostMapping("/remove")
	@ApiOperationSupport(order = 7)
	@ApiOperation(value = "逻辑删除", notes = "传入ID数组")
	public R remove(@ApiParam(value = "主键集合") @RequestParam String ids) {
		boolean temp = rtuBaseInfoService.deleteLogic(Func.toLongList(ids));
		return R.status(temp);
	}

	@GetMapping("/dict/list")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "分页")
	public R<List<DictBiz>> dictList(@RequestParam String code) {
		List<DictBiz> dicts = dictBizService.getList(code);
		return R.data(dicts);
	}

	/**
	 * 按机构统计测站信息
	 *
	 * @return
	 */
	@GetMapping("/statistics")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "分页")
	public R<List<RtuStatisticsInfoVO>> rtuStatistics() {
		List<RtuStatisticsInfoVO> list = new LinkedList<>();
		BladeUser user = AuthUtil.getUser();
		List<Dept> root = this.deptService.getDeptChild(Func.toLong(user.getDeptId()));
		for (Dept dept : root) {
			RtuStatisticsInfoVO rtuStatisticsInfoVO = new RtuStatisticsInfoVO();
			rtuStatisticsInfoVO.setId(dept.getId());
			rtuStatisticsInfoVO.setOrgName(dept.getDeptName());
			LambdaQueryWrapper<RtuInfoEntity> wrapper = Wrappers.<RtuInfoEntity>query().lambda();
			wrapper.eq(RtuInfoEntity::getOrgId, dept.getId());
			wrapper.eq(RtuInfoEntity::getIsDeleted, 0);
			Long rtus = rtuBaseInfoService.count(wrapper);
			rtuStatisticsInfoVO.setRtuCount(rtus);
			RtuWarningInfoDTO rtuWarningInfoDTO = new RtuWarningInfoDTO();
			rtuWarningInfoDTO.setDeptId(dept.getId());
			Long warningRtus = rtuWarningService.warningRtuCount(rtuWarningInfoDTO);
			rtuStatisticsInfoVO.setWarningRtuCount(warningRtus);
			list.add(rtuStatisticsInfoVO);
		}
		return R.data(list);
	}

	private String getLng(String lngText) {
		ArrayList<String> textArr = new ArrayList<>();
		textArr.add("");
		for (int l = 0; l < lngText.length(); l++) {
			String subtext = lngText.substring(l, l + 1);
			if (Func.isNumeric(subtext)) {
				String str = textArr.get(textArr.size() - 1);
				str += subtext;
				textArr.set(textArr.size() - 1, str);
			} else {
				textArr.add("");
			}
		}
		ArrayList<String> tmp = new ArrayList<>();
		for (String text : textArr) {
			if (text.length() > 0) {
				tmp.add(text);
			}
		}
		if (tmp.size() >= 4) {
			//度分秒，秒有小数点
			String v = tmp.get(2) + "." + tmp.get(3);
			double lat = Double.parseDouble(v);
			lat = lat / 60.0;
			v = tmp.get(1);
			lat = (Double.parseDouble(v) + lat) / 60.0;
			v = tmp.get(0);
			lat = Double.parseDouble(v) + lat;
			return String.format("%.06f", lat);
		} else if (tmp.size() == 3) {
			//度分秒
			String v = tmp.get(2);
			double lat = Double.parseDouble(v);
			lat = lat / 60.0;
			v = tmp.get(1);
			lat = (Double.parseDouble(v) + lat) / 60.0;
			v = tmp.get(0);
			lat = Double.parseDouble(v) + lat;
			return String.format("%.06f", lat);
		} else if (tmp.size() == 2) {
			//度
			String v = tmp.get(0) + "." + tmp.get(1);
			double lat = Double.parseDouble(v);
			return String.format("%.06f", lat);
		}
		return null;
	}

	private String getLat(String latText) {
		ArrayList<String> textArr = new ArrayList<>();
		textArr.add("");
		for (int l = 0; l < latText.length(); l++) {
			String subtext = latText.substring(l, l + 1);
			if (Func.isNumeric(subtext)) {
				String str = textArr.get(textArr.size() - 1);
				str += subtext;
				textArr.set(textArr.size() - 1, str);
			} else {
				textArr.add("");
			}
		}
		ArrayList<String> tmp = new ArrayList<>();
		for (String text : textArr) {
			if (text.length() > 0) {
				tmp.add(text);
			}
		}
		if (tmp.size() >= 4) {
			//度分秒，秒有小数点
			String v = tmp.get(2) + "." + tmp.get(3);
			double lat = Double.parseDouble(v);
			lat = lat / 60.0;
			v = tmp.get(1);
			lat = (Double.parseDouble(v) + lat) / 60.0;
			v = tmp.get(0);
			lat = Double.parseDouble(v) + lat;
			return String.format("%.06f", lat);
		} else if (tmp.size() == 3) {
			//度分秒
			String v = tmp.get(2);
			double lat = Double.parseDouble(v);
			lat = lat / 60.0;
			v = tmp.get(1);
			lat = (Double.parseDouble(v) + lat) / 60.0;
			v = tmp.get(0);
			lat = Double.parseDouble(v) + lat;
			return String.format("%.06f", lat);
		} else if (tmp.size() == 2) {
			//度
			String v = tmp.get(0) + "." + tmp.get(1);
			double lat = Double.parseDouble(v);
			return String.format("%.06f", lat);
		}
		return null;
	}
}
