/**
 * Copyright 2019 DH
 * All right reserved.
 * 项目名称: 大恒泰山系统
 * 创建日期:2022/8/31
 */
package org.springblade.modules.business.data.manage.controller;


import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.read.listener.ReadListener;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.bstek.ureport.parser.impl.searchform.DatetimeInputParser;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springblade.common.cache.DictBizCache;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.launch.constant.AppConstant;
import org.springblade.core.log.annotation.ApiLog;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.ConcurrentDateFormat;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.baseinfo.stbase.entity.MvAttStBaseEntity;
import org.springblade.modules.baseinfo.stbase.service.IMvAttStBaseService;
import org.springblade.modules.business.data.manage.entity.RtuImportRecordEntity;
import org.springblade.modules.business.data.manage.entity.RtuInfoTableDataEntity;
import org.springblade.modules.business.data.manage.service.IRtuImportRecordService;
import org.springblade.modules.business.project.base.entity.ProjectInfoEntity;
import org.springblade.modules.business.project.base.service.IProjectBaseInfoService;
import org.springblade.modules.business.rtu.base.entity.RtuInfoEntity;
import org.springblade.modules.business.rtu.base.service.IRtuBaseInfoService;
import org.springblade.modules.system.entity.Dept;
import org.springblade.modules.system.entity.DictBiz;
import org.springblade.modules.system.service.IDeptService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;
import java.time.format.DateTimeFormatter;
import java.util.*;

/***
 * Date:2022/8/31
 * Title:文件所属模块（必须填写）
 * Description：对本文件的详细描述，原则上不能少于30字
 * @author dylan
 * @version 1.0
 * Remark：认为有必要的其他信息
 */
@RestController
@RequestMapping("galaxy-business/data/manage")
@AllArgsConstructor
@Api(value = "数据管理模块", tags = "数据管理模块")
public class DataManageController extends BladeController {

	final IProjectBaseInfoService projectBaseInfoService;

	final IRtuBaseInfoService rtuBaseInfoService;

	final IRtuImportRecordService rtuImportRecordService;
	final IDeptService deptService;

	final IMvAttStBaseService mvAttStBaseService;

	private Double tranformPos(String lng) {
		lng = lng
			.trim()
			.replace("g", "");
		if (lng.indexOf("o") >= 0 || lng.indexOf("°") >= 0 || lng.indexOf("°") >= 0 || lng.indexOf("°") >= 0) {
			lng = lng
				.trim()
				.replace("o", ":")
				.replace("°", ":")
				.replace("°", ":")
				.replace("°", ":")
				.replace("′", ":")
				.replace("'", ":")
				.replace("\"", "")
				.replace("″", "")
				.replace(".", ":");

			String[] lntArr = lng.split(":");
			Double result = 0D;
			if (lntArr.length == 1) {
				String[] lntArr2 = new String[3];
				lntArr2[0] = lntArr[0];
				lntArr2[1] = "0";
				lntArr2[2] = "0";
				lntArr = lntArr2;
			} else if (lntArr.length == 2) {
				String[] lntArr2 = new String[3];
				lntArr2[0] = lntArr[0];
				lntArr2[1] = lntArr[1];
				lntArr2[2] = "0";
				lntArr = lntArr2;
			}
			for (int i = lntArr.length; i > 0; i--) {
				String str = lntArr[i - 1];
				if (null != str) {
					str = str.trim();
					if (null != str && str.length() > 0) {
						double v = Double.parseDouble(str);
						if (i == 1) {
							result = v + result;
						} else {
							result = (result + v) / 60;
						}
					} else {
						double v = 0.0;
						if (i == 1) {
							result = v + result;
						} else {
							result = (result + v) / 60;
						}
					}
				} else {
					double v = 0.0;
					if (i == 1) {
						result = v + result;
					} else {
						result = (result + v) / 60;
					}
				}
			}
			return result;
		} else {
			String lng2 = lng;
			lng2 = lng2
				.trim()
				.replace(".", ":");
			String[] vs = lng2.split(":");
			if (vs.length > 1) {
				lng = lng
					.trim()
					.replace("o", ":")
					.replace("°", ":")
					.replace("°", ":")
					.replace("°", ":")
					.replace("′", ":")
					.replace("'", ":")
					.replace("\"", "")
					.replace("″", "")
					.replace(".", ":");

				String[] lntArr = lng.split(":");
				Double result = 0D;
				if (lntArr.length == 1) {
					String[] lntArr2 = new String[3];
					lntArr2[0] = lntArr[0];
					lntArr2[1] = "0";
					lntArr2[2] = "0";
					lntArr = lntArr2;
				} else if (lntArr.length == 2) {
					String[] lntArr2 = new String[3];
					lntArr2[0] = lntArr[0];
					lntArr2[1] = lntArr[1];
					lntArr2[2] = "0";
					lntArr = lntArr2;
				}
				for (int i = lntArr.length; i > 0; i--) {
					String str = lntArr[i - 1];
					if (null != str) {
						str = str.trim();
						if (null != str && str.length() > 0) {
							double v = Double.parseDouble(str);
							if (i == 1) {
								result = v + result;
							} else {
								result = (result + v) / 60;
							}
						} else {
							double v = 0.0;
							if (i == 1) {
								result = v + result;
							} else {
								result = (result + v) / 60;
							}
						}
					} else {
						double v = 0.0;
						if (i == 1) {
							result = v + result;
						} else {
							result = (result + v) / 60;
						}
					}
				}
				return result;
			} else {
				double v = Double.parseDouble(lng);
				return v;
			}

		}

	}

	public static boolean isLetterDigit(String str) {
		String regex = "^[a-z0-9A-Z]+$";
		return str.matches(regex);
	}

	@GetMapping("/page")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "分页")
	public R<IPage<RtuImportRecordEntity>> list(Query query) {
		LambdaQueryWrapper<RtuImportRecordEntity> wrapper = Wrappers.<RtuImportRecordEntity>query().lambda();
		wrapper.orderByDesc(RtuImportRecordEntity::getImportTime);
		return R.data(rtuImportRecordService.page(Condition.getPage(query),wrapper));
	}


	@ApiLog("测站信息-导入")
	@GetMapping(value = "/import/rtu/test")
	@ApiOperationSupport(order = 6)
	@ApiOperation(value = "导入测站信息", notes = "")
	public R importTest() {
		try {


			String filePath = "D:\\tmp\\rtu\\xa.xlsx";

			// 这里 需要指定读用哪个class去读，然后读取第一个sheet 文件流会自动关闭
			EasyExcel.read(filePath, RtuInfoTableDataEntity.class, new ReadListener() {
				@Override
				public void invoke(Object o, AnalysisContext analysisContext) {
					System.out.println(JSON.toJSONString(o));
				}

				@Override
				public void doAfterAllAnalysed(AnalysisContext analysisContext) {

				}
			}).sheet().doRead();


//			int sheetIndex = 0;
//
//			// 定义输入流
//			FileInputStream fis = null;
//			List<Map> datas = null;
//
//			try {
//				// 创建输入流对象
//				fis = new FileInputStream(filePath);
//				// 创建一个easypoi使用的配置类
//				ImportParams params = new ImportParams();
//				// 设置表格坐标
//				params.setStartSheetIndex(sheetIndex);
//				// 校验Excel文件，去掉空行
//				params.setNeedVerify(true);
//				// 读取数据
//				datas = ExcelImportUtil.importExcel(fis, Map.class, params);
//			} catch (Exception e) {
//				e.printStackTrace();
//			} finally {
//				try {
//					if (fis != null) {
//						fis.close();
//					}
//				} catch (IOException e) {
//					e.printStackTrace();
//				}
//			}
//
//			for (Map apiInfo : datas) {
//				System.out.println(apiInfo);
//			}

			return R.success("导入成功");
		} catch (Exception e) {
			return R.fail("导入错误 " + e.getMessage());
		}
	}


	@ApiLog("测站信息-导入")
	@PostMapping(value = "/import/rtu2")
	@ApiOperationSupport(order = 6)
	@ApiOperation(value = "导入测站信息", notes = "")
	public R<Map<String, String>> importRtuTable2(MultipartFile file, @RequestParam Map<String, Object> postData) {
		try {
			if (file.isEmpty() || !postData.containsKey("projectId")) {
				return R.fail("上传文件为空");
			}
			if (!postData.containsKey("projectId")) {
				return R.fail("参数为空");
			}
			String projectIdText = (String) postData.get("projectId");
			Long projectId = Long.parseLong(projectIdText);
			ProjectInfoEntity projectInfoEntity = projectBaseInfoService.getById(projectId);
			Long orgId = projectInfoEntity.getOrgId();

			InputStream inputStream = file.getInputStream();
			String fileName = file.getOriginalFilename();
			List<RtuInfoTableDataEntity> list = new LinkedList<>();
			if (fileName.endsWith("xlsx")) {
				EasyExcel.read(inputStream, RtuInfoTableDataEntity.class, new ReadListener() {
					@Override
					public void invoke(Object o, AnalysisContext analysisContext) {
						RtuInfoTableDataEntity dataEntity = (RtuInfoTableDataEntity) o;
						list.add(dataEntity);
					}

					@Override
					public void doAfterAllAnalysed(AnalysisContext analysisContext) {
						for (int i = 2; i < list.size(); i++) {
							RtuInfoTableDataEntity dataEntity = list.get(i);
							if (null != dataEntity.getRtuCode()) {
								String rtuCode = dataEntity.getRtuCode().trim();
								if (rtuCode.length() > 0) {
									if (isLetterDigit(rtuCode)) {
										RtuInfoEntity rtuInfoEntity = new RtuInfoEntity();
										rtuInfoEntity.setRtuCode(rtuCode);
										if (null != dataEntity.getCity()) {
											rtuInfoEntity.setAdCity(dataEntity.getCity().trim());
										}
										if (null != dataEntity.getDist()) {
											rtuInfoEntity.setAdDist(dataEntity.getDist().trim());
										}
										if (null != dataEntity.getRtuName()) {
											rtuInfoEntity.setRtuName(dataEntity.getRtuName().trim());
										}
										if (null != dataEntity.getRtuKind()) {
											rtuInfoEntity.setIsRain(0);
											rtuInfoEntity.setIsRiver(0);
											rtuInfoEntity.setIsRes(0);
											rtuInfoEntity.setIsGround(0);
											String kinds = dataEntity.getRtuKind().trim();
											if (kinds.length() > 0) {
												List<DictBiz> bizs = DictBizCache.getList("rtu_kind");
												String kindList = "";
												if (kinds.contains("水位")) {
													rtuInfoEntity.setIsRes(1);
													rtuInfoEntity.setIsRiver(1);
													for (DictBiz biz : bizs) {
														if (biz.getDictKey().equals("river")) {
															if (kindList.length() > 0) {
																kindList += ",";
															}
															kindList += Long.toString(biz.getId());
														} else if (biz.getDictKey().equals("rsvr")) {
															if (kindList.length() > 0) {
																kindList += ",";
															}
															kindList += Long.toString(biz.getId());
														}
													}
													rtuInfoEntity.setRtuKinds(kindList);
												}
												if (kinds.contains("雨量")) {
													rtuInfoEntity.setIsRain(1);
													for (DictBiz biz : bizs) {
														if (biz.getDictKey().equals("rain")) {
															if (kindList.length() > 0) {
																kindList += ",";
															}
															kindList += Long.toString(biz.getId());
															break;
														}
													}
												}
												if (kinds.contains("墒情")) {
													rtuInfoEntity.setIsGround(1);
													for (DictBiz biz : bizs) {
														if (biz.getDictKey().equals("ground")) {
															if (kindList.length() > 0) {
																kindList += ",";
															}
															kindList += Long.toString(biz.getId());
															break;
														}
													}
												}
												rtuInfoEntity.setRtuKinds(kindList);
											}
										}

										if (null != dataEntity.getLocationDesc()) {
											rtuInfoEntity.setLocationDesc(dataEntity.getLocationDesc().trim());
										}

										if (null != dataEntity.getLng()) {
											ArrayList<String> textArr = new ArrayList<>();
											textArr.add("");
											String location = dataEntity.getLng().trim();
											for (int l = 0; l < location.length(); l++) {
												String subtext = location.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;
												rtuInfoEntity.setLng(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;
												rtuInfoEntity.setLng(String.format("%.06f", lat));

											} else if (tmp.size() == 2) {
												//度
												String v = tmp.get(0) + "." + tmp.get(1);
												double lat = Double.parseDouble(v);
												rtuInfoEntity.setLng(String.format("%.06f", lat));
											}

										}

										if (null != dataEntity.getLat()) {
											ArrayList<String> textArr = new ArrayList<>();
											textArr.add("");
											String location = dataEntity.getLat().trim();
											for (int l = 0; l < location.length(); l++) {
												String subtext = location.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;
												rtuInfoEntity.setLat(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;
												rtuInfoEntity.setLat(String.format("%.06f", lat));

											} else if (tmp.size() == 2) {
												//度
												String v = tmp.get(0) + "." + tmp.get(1);
												double lat = Double.parseDouble(v);
												rtuInfoEntity.setLat(String.format("%.06f", lat));
											}

										}
										if (null != dataEntity.getManageCompany()) {
											rtuInfoEntity.setManageCompany(dataEntity.getManageCompany().trim());
										}


										if (null != dataEntity.getRtuBrand()) {
											rtuInfoEntity.setRtuBrand(dataEntity.getRtuBrand().trim());
										}

										if (null != dataEntity.getRtuModel()) {
											rtuInfoEntity.setRtuModel(dataEntity.getRtuModel().trim());
										}

										if (null != dataEntity.getRtuReplaceDate()) {
											ArrayList<String> textArr = new ArrayList<>();
											textArr.add("");
											String replaceDate = dataEntity.getRtuReplaceDate().trim();
											for (int l = 0; l < replaceDate.length(); l++) {
												String subtext = replaceDate.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() >= 3) {
												String v = tmp.get(0) + "-" + tmp.get(1) + "-" + tmp.get(2);
												Date dt = Func.parse(v, ConcurrentDateFormat.of("yyyy-MM-dd"));
												rtuInfoEntity.setRtuReplaceDate(dt);
											} else if (tmp.size() == 2) {
												String v = tmp.get(0) + "-" + tmp.get(1) + "-01";
												Date dt = Func.parse(v, ConcurrentDateFormat.of("yyyy-MM-dd"));
												rtuInfoEntity.setRtuReplaceDate(dt);
											}

										}
										if (null != dataEntity.getToSheng()) {
											if (dataEntity.getToSheng().trim().equals("是")) {
												rtuInfoEntity.setDatagramToSheng(1);
											} else {
												rtuInfoEntity.setDatagramToSheng(0);
											}
										} else {
											rtuInfoEntity.setDatagramToSheng(0);
										}

										if (null != dataEntity.getToShi()) {
											if (dataEntity.getToShi().trim().equals("是")) {
												rtuInfoEntity.setDatagramToShi(1);
											} else {
												rtuInfoEntity.setDatagramToShi(0);
											}
										} else {
											rtuInfoEntity.setDatagramToShi(0);
										}

										if (null != dataEntity.getToQu()) {
											if (dataEntity.getToQu().trim().equals("是")) {
												rtuInfoEntity.setDatagramToQu(1);
											} else {
												rtuInfoEntity.setDatagramToQu(0);
											}
										} else {
											rtuInfoEntity.setDatagramToQu(0);
										}

										if (null != dataEntity.getRainSensorBrand()) {
											rtuInfoEntity.setRainSensorBrand(dataEntity.getRainSensorBrand().trim());
										}

										if (null != dataEntity.getRainSensorModel()) {
											rtuInfoEntity.setRainSensorModel(dataEntity.getRainSensorModel().trim());
										}

										if (null != dataEntity.getRainSensorReplaceDate()) {

											ArrayList<String> textArr = new ArrayList<>();
											textArr.add("");
											String replaceDate = dataEntity.getRainSensorReplaceDate().trim();
											for (int l = 0; l < replaceDate.length(); l++) {
												String subtext = replaceDate.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() >= 3) {
												String v = tmp.get(0) + "-" + tmp.get(1) + "-" + tmp.get(2);
												Date dt = Func.parse(v, ConcurrentDateFormat.of("yyyy-MM-dd"));
												rtuInfoEntity.setRainSensorReplaceDate(dt);
											} else if (tmp.size() == 2) {
												String v = tmp.get(0) + "-" + tmp.get(1) + "-01";
												Date dt = Func.parse(v, ConcurrentDateFormat.of("yyyy-MM-dd"));
												rtuInfoEntity.setRainSensorReplaceDate(dt);
											}


										}

										if (null != dataEntity.getWaterSensorType()) {
											List<DictBiz> bizs = DictBizCache.getList("water_level_sensor_type");
											for (DictBiz biz : bizs) {
												if (dataEntity.getWaterSensorType().trim().contains(biz.getDictValue())) {
													rtuInfoEntity.setWaterSensorType(biz.getId());
													break;
												}
											}
										}

										if (null != dataEntity.getWaterSensorBrand()) {
											rtuInfoEntity.setWaterSensorBrand(dataEntity.getWaterSensorBrand().trim());
										}

										if (null != dataEntity.getWaterSensorModel()) {
											rtuInfoEntity.setWaterSensorModel(dataEntity.getWaterSensorModel().trim());
										}

										if (null != dataEntity.getWaterSensorReplaceDate()) {
											ArrayList<String> textArr = new ArrayList<>();
											textArr.add("");
											String replaceDate = dataEntity.getWaterSensorReplaceDate().trim();
											for (int l = 0; l < replaceDate.length(); l++) {
												String subtext = replaceDate.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() >= 3) {
												String v = tmp.get(0) + "-" + tmp.get(1) + "-" + tmp.get(2);
												Date dt = Func.parse(v, ConcurrentDateFormat.of("yyyy-MM-dd"));
												rtuInfoEntity.setWaterSensorReplaceDate(dt);
											} else if (tmp.size() == 2) {
												String v = tmp.get(0) + "-" + tmp.get(1) + "-01";
												Date dt = Func.parse(v, ConcurrentDateFormat.of("yyyy-MM-dd"));
												rtuInfoEntity.setWaterSensorReplaceDate(dt);
											}


										}

										if (null != dataEntity.getGroundSensorType()) {
											List<DictBiz> bizs = DictBizCache.getList("ground_water_sensor_type");
											for (DictBiz biz : bizs) {
												if (dataEntity.getGroundSensorType().trim().contains(biz.getDictValue())) {
													rtuInfoEntity.setGroundSensorType(biz.getId());
													break;
												}
											}
										}

										if (null != dataEntity.getGroundSensorBrand()) {
											rtuInfoEntity.setGroundSensorBrand(dataEntity.getGroundSensorBrand().trim());
										}

										if (null != dataEntity.getGroundSensorModel()) {
											rtuInfoEntity.setGroundSensorModel(dataEntity.getGroundSensorModel().trim());
										}

										if (null != dataEntity.getGroundSensorReplaceDate()) {
											ArrayList<String> textArr = new ArrayList<>();
											textArr.add("");
											String replaceDate = dataEntity.getGroundSensorReplaceDate().trim();
											for (int l = 0; l < replaceDate.length(); l++) {
												String subtext = replaceDate.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() >= 3) {
												String v = tmp.get(0) + "-" + tmp.get(1) + "-" + tmp.get(2);
												Date dt = Func.parse(v, ConcurrentDateFormat.of("yyyy-MM-dd"));
												rtuInfoEntity.setGroundSensorReplaceDate(dt);
											} else if (tmp.size() == 2) {
												String v = tmp.get(0) + "-" + tmp.get(1) + "-01";
												Date dt = Func.parse(v, ConcurrentDateFormat.of("yyyy-MM-dd"));
												rtuInfoEntity.setGroundSensorReplaceDate(dt);
											}


										}

										if (null != dataEntity.getBatteryModel()) {
											rtuInfoEntity.setBatteryModel(dataEntity.getBatteryModel().trim());
										}

										if (null != dataEntity.getBatteryReplaceDate()) {
											ArrayList<String> textArr = new ArrayList<>();
											textArr.add("");
											String replaceDate = dataEntity.getBatteryReplaceDate().trim();
											for (int l = 0; l < replaceDate.length(); l++) {
												String subtext = replaceDate.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() >= 3) {
												String v = tmp.get(0) + "-" + tmp.get(1) + "-" + tmp.get(2);
												Date dt = Func.parse(v, ConcurrentDateFormat.of("yyyy-MM-dd"));
												rtuInfoEntity.setBatteryReplaceDate(dt);
											} else if (tmp.size() == 2) {
												String v = tmp.get(0) + "-" + tmp.get(1) + "-01";
												Date dt = Func.parse(v, ConcurrentDateFormat.of("yyyy-MM-dd"));
												rtuInfoEntity.setBatteryReplaceDate(dt);
											}


										}

										if (null != dataEntity.getSunModel()) {
											rtuInfoEntity.setSunPowerModel(dataEntity.getSunModel().trim());
										}

										if (null != dataEntity.getSimId()) {
											rtuInfoEntity.setNetworkSimId(dataEntity.getSimId().trim());
										}

										if (null != dataEntity.getSimPay()) {
											rtuInfoEntity.setNetworkPayer(dataEntity.getSimPay().trim());
										}

										if (null != dataEntity.getSimOverdate()) {
											ArrayList<String> textArr = new ArrayList<>();
											textArr.add("");
											String replaceDate = dataEntity.getSimOverdate().trim();
											for (int l = 0; l < replaceDate.length(); l++) {
												String subtext = replaceDate.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() >= 3) {
												String v = tmp.get(0) + "-" + tmp.get(1) + "-" + tmp.get(2);
												Date dt = Func.parse(v, ConcurrentDateFormat.of("yyyy-MM-dd"));
												rtuInfoEntity.setNetworkPayEndDate(dt);
											} else if (tmp.size() == 2) {
												String v = tmp.get(0) + "-" + tmp.get(1) + "-01";
												Date dt = Func.parse(v, ConcurrentDateFormat.of("yyyy-MM-dd"));
												rtuInfoEntity.setNetworkPayEndDate(dt);
											}


										}

										if (null != dataEntity.getSatellite()) {
											if (dataEntity.getSatellite().trim().equals("是")) {
												rtuInfoEntity.setIsSatellite(1);
											} else {
												rtuInfoEntity.setIsSatellite(0);
											}

										} else {
											rtuInfoEntity.setIsSatellite(0);
										}

										if (null != dataEntity.getSatelliteModel()) {
											List<DictBiz> bizs = DictBizCache.getList("satellite_model");
											for (DictBiz biz : bizs) {
												if (dataEntity.getSatelliteModel().trim().contains(biz.getDictValue())) {
													rtuInfoEntity.setSatelliteModel(biz.getId());
													break;
												}
											}

										}

										if (null != dataEntity.getRemark()) {
											rtuInfoEntity.setRemark(dataEntity.getRemark().trim());
										}

										rtuInfoEntity.setProjectId(projectId);
										rtuInfoEntity.setOrgId(orgId);


										RtuInfoEntity entity = rtuBaseInfoService.rtuInfoByRtuCode(rtuInfoEntity.getRtuCode());
										if (null != entity) {
											rtuInfoEntity.setId(entity.getId());
										}
										rtuBaseInfoService.saveOrUpdate(rtuInfoEntity);

										System.out.println("save record********************");

									} else {
										System.out.println(" record is null ********************");
										System.out.println(JSON.toJSON(dataEntity).toString());
									}
								} else {
									System.out.println(" record is null ********************");
									System.out.println(JSON.toJSON(dataEntity).toString());
								}
							} else {
								System.out.println(" record is null ********************");
								System.out.println(JSON.toJSON(dataEntity).toString());
							}

						}

						//更新导入时间
						projectBaseInfoService.updateImportTime(projectId, new Date());
					}
				}).sheet().doRead();

			} else {
				return R.fail("上传文件格式错误");
			}

			return R.success("导入成功");
		} catch (IOException e) {
			e.printStackTrace();
			return R.fail("导入错误 " + e.getMessage());
		} catch (Exception e) {
			e.printStackTrace();
			return R.fail("导入错误 " + e.getMessage());
		}
	}

	@ApiLog("测站信息-导入")
	@PostMapping(value = "/import/rtu")
	@ApiOperationSupport(order = 6)
	@ApiOperation(value = "导入测站信息", notes = "")
	public R<Map<String, String>> importRtuTable(MultipartFile file, @RequestParam Map<String, Object> postData) {
		try {
			if (file.isEmpty() || !postData.containsKey("orgId")) {
				return R.fail("上传文件为空");
			}
			if (!postData.containsKey("orgId")) {
				return R.fail("参数为空");
			}
			String orgIdText = (String) postData.get("orgId");
			Long orgId = Long.parseLong(orgIdText);

			Dept dept=deptService.getById(orgId);

			RtuImportRecordEntity recordEntity=new RtuImportRecordEntity();
			recordEntity.setImportStatus(0L);
			recordEntity.setOrgName(dept.getDeptName());
			recordEntity.setOrgId(orgId);
			recordEntity.setImportTime(Func.formatDateTime(new Date()));
			this.rtuImportRecordService.save(recordEntity);



			//	ProjectInfoEntity projectInfoEntity = projectBaseInfoService.getById(projectId);
			//	Long orgId = projectInfoEntity.getOrgId();

			InputStream inputStream = file.getInputStream();
			String fileName = file.getOriginalFilename();
			List<RtuInfoTableDataEntity> list = new LinkedList<>();
			if (fileName.endsWith("xlsx")) {
				EasyExcel.read(inputStream, RtuInfoTableDataEntity.class, new ReadListener() {
					@Override
					public void invoke(Object o, AnalysisContext analysisContext) {
						RtuInfoTableDataEntity dataEntity = (RtuInfoTableDataEntity) o;
						list.add(dataEntity);
					}

					@Override
					public void doAfterAllAnalysed(AnalysisContext analysisContext) {
						for (int i = 2; i < list.size(); i++) {
							RtuInfoTableDataEntity dataEntity = list.get(i);
							if (null != dataEntity.getRtuCode()) {
								String rtuCode = dataEntity.getRtuCode().trim();
								if (rtuCode.length() > 0) {
									if (isLetterDigit(rtuCode)) {
										RtuInfoEntity rtuInfoEntity = new RtuInfoEntity();
										rtuInfoEntity.setRtuCode(rtuCode);
										if (null != dataEntity.getCity()) {
											rtuInfoEntity.setAdCity(dataEntity.getCity().trim());
										}
										if (null != dataEntity.getDist()) {
											rtuInfoEntity.setAdDist(dataEntity.getDist().trim());
										}
										if (null != dataEntity.getRtuName()) {
											rtuInfoEntity.setRtuName(dataEntity.getRtuName().trim());
										}
										if (null != dataEntity.getRtuKind()) {
											rtuInfoEntity.setIsRain(0);
											rtuInfoEntity.setIsRiver(0);
											rtuInfoEntity.setIsRes(0);
											rtuInfoEntity.setIsGround(0);
											String kinds = dataEntity.getRtuKind().trim();
											if (kinds.length() > 0) {
												List<DictBiz> bizs = DictBizCache.getList("rtu_kind");
												String kindList = "";
												if (kinds.contains("水位")) {
													rtuInfoEntity.setIsRes(1);
													rtuInfoEntity.setIsRiver(1);
													for (DictBiz biz : bizs) {
														if (biz.getDictKey().equals("river")) {
															if (kindList.length() > 0) {
																kindList += ",";
															}
															kindList += Long.toString(biz.getId());
														} else if (biz.getDictKey().equals("rsvr")) {
															if (kindList.length() > 0) {
																kindList += ",";
															}
															kindList += Long.toString(biz.getId());
														}
													}
													rtuInfoEntity.setRtuKinds(kindList);
												}
												if (kinds.contains("雨量")) {
													rtuInfoEntity.setIsRain(1);
													for (DictBiz biz : bizs) {
														if (biz.getDictKey().equals("rain")) {
															if (kindList.length() > 0) {
																kindList += ",";
															}
															kindList += Long.toString(biz.getId());
															break;
														}
													}
												}
												if (kinds.contains("墒情")) {
													rtuInfoEntity.setIsGround(1);
													for (DictBiz biz : bizs) {
														if (biz.getDictKey().equals("ground")) {
															if (kindList.length() > 0) {
																kindList += ",";
															}
															kindList += Long.toString(biz.getId());
															break;
														}
													}
												}
												rtuInfoEntity.setRtuKinds(kindList);
											}
										}

										if (null != dataEntity.getLocationDesc()) {
											rtuInfoEntity.setLocationDesc(dataEntity.getLocationDesc().trim());
										}

										if (null != dataEntity.getLng()) {
											ArrayList<String> textArr = new ArrayList<>();
											textArr.add("");
											String location = dataEntity.getLng().trim();
											for (int l = 0; l < location.length(); l++) {
												String subtext = location.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;
												rtuInfoEntity.setLng(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;
												rtuInfoEntity.setLng(String.format("%.06f", lat));

											} else if (tmp.size() == 2) {
												//度
												String v = tmp.get(0) + "." + tmp.get(1);
												double lat = Double.parseDouble(v);
												rtuInfoEntity.setLng(String.format("%.06f", lat));
											}

										}

										if (null != dataEntity.getLat()) {
											ArrayList<String> textArr = new ArrayList<>();
											textArr.add("");
											String location = dataEntity.getLat().trim();
											for (int l = 0; l < location.length(); l++) {
												String subtext = location.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;
												rtuInfoEntity.setLat(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;
												rtuInfoEntity.setLat(String.format("%.06f", lat));

											} else if (tmp.size() == 2) {
												//度
												String v = tmp.get(0) + "." + tmp.get(1);
												double lat = Double.parseDouble(v);
												rtuInfoEntity.setLat(String.format("%.06f", lat));
											}

										}
										if (null != dataEntity.getManageCompany()) {
											rtuInfoEntity.setManageCompany(dataEntity.getManageCompany().trim());
										}


										if (null != dataEntity.getRtuBrand()) {
											rtuInfoEntity.setRtuBrand(dataEntity.getRtuBrand().trim());
										}

										if (null != dataEntity.getRtuModel()) {
											rtuInfoEntity.setRtuModel(dataEntity.getRtuModel().trim());
										}

										if (null != dataEntity.getRtuReplaceDate()) {
											ArrayList<String> textArr = new ArrayList<>();
											textArr.add("");
											String replaceDate = dataEntity.getRtuReplaceDate().trim();
											for (int l = 0; l < replaceDate.length(); l++) {
												String subtext = replaceDate.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() >= 3) {
												String v = tmp.get(0) + "-" + tmp.get(1) + "-" + tmp.get(2);
												Date dt = Func.parse(v, ConcurrentDateFormat.of("yyyy-MM-dd"));
												rtuInfoEntity.setRtuReplaceDate(dt);
											} else if (tmp.size() == 2) {
												String v = tmp.get(0) + "-" + tmp.get(1) + "-01";
												Date dt = Func.parse(v, ConcurrentDateFormat.of("yyyy-MM-dd"));
												rtuInfoEntity.setRtuReplaceDate(dt);
											}

										}
										if (null != dataEntity.getToSheng()) {
											if (dataEntity.getToSheng().trim().equals("是")) {
												rtuInfoEntity.setDatagramToSheng(1);
											} else {
												rtuInfoEntity.setDatagramToSheng(0);
											}
										} else {
											rtuInfoEntity.setDatagramToSheng(0);
										}

										if (null != dataEntity.getToShi()) {
											if (dataEntity.getToShi().trim().equals("是")) {
												rtuInfoEntity.setDatagramToShi(1);
											} else {
												rtuInfoEntity.setDatagramToShi(0);
											}
										} else {
											rtuInfoEntity.setDatagramToShi(0);
										}

										if (null != dataEntity.getToQu()) {
											if (dataEntity.getToQu().trim().equals("是")) {
												rtuInfoEntity.setDatagramToQu(1);
											} else {
												rtuInfoEntity.setDatagramToQu(0);
											}
										} else {
											rtuInfoEntity.setDatagramToQu(0);
										}

										if (null != dataEntity.getRainSensorBrand()) {
											rtuInfoEntity.setRainSensorBrand(dataEntity.getRainSensorBrand().trim());
										}

										if (null != dataEntity.getRainSensorModel()) {
											rtuInfoEntity.setRainSensorModel(dataEntity.getRainSensorModel().trim());
										}

										if (null != dataEntity.getRainSensorReplaceDate()) {

											ArrayList<String> textArr = new ArrayList<>();
											textArr.add("");
											String replaceDate = dataEntity.getRainSensorReplaceDate().trim();
											for (int l = 0; l < replaceDate.length(); l++) {
												String subtext = replaceDate.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() >= 3) {
												String v = tmp.get(0) + "-" + tmp.get(1) + "-" + tmp.get(2);
												Date dt = Func.parse(v, ConcurrentDateFormat.of("yyyy-MM-dd"));
												rtuInfoEntity.setRainSensorReplaceDate(dt);
											} else if (tmp.size() == 2) {
												String v = tmp.get(0) + "-" + tmp.get(1) + "-01";
												Date dt = Func.parse(v, ConcurrentDateFormat.of("yyyy-MM-dd"));
												rtuInfoEntity.setRainSensorReplaceDate(dt);
											}


										}

										if (null != dataEntity.getWaterSensorType()) {
											List<DictBiz> bizs = DictBizCache.getList("water_level_sensor_type");
											for (DictBiz biz : bizs) {
												if (dataEntity.getWaterSensorType().trim().contains(biz.getDictValue())) {
													rtuInfoEntity.setWaterSensorType(biz.getId());
													break;
												}
											}
										}

										if (null != dataEntity.getWaterSensorBrand()) {
											rtuInfoEntity.setWaterSensorBrand(dataEntity.getWaterSensorBrand().trim());
										}

										if (null != dataEntity.getWaterSensorModel()) {
											rtuInfoEntity.setWaterSensorModel(dataEntity.getWaterSensorModel().trim());
										}

										if (null != dataEntity.getWaterSensorReplaceDate()) {
											ArrayList<String> textArr = new ArrayList<>();
											textArr.add("");
											String replaceDate = dataEntity.getWaterSensorReplaceDate().trim();
											for (int l = 0; l < replaceDate.length(); l++) {
												String subtext = replaceDate.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() >= 3) {
												String v = tmp.get(0) + "-" + tmp.get(1) + "-" + tmp.get(2);
												Date dt = Func.parse(v, ConcurrentDateFormat.of("yyyy-MM-dd"));
												rtuInfoEntity.setWaterSensorReplaceDate(dt);
											} else if (tmp.size() == 2) {
												String v = tmp.get(0) + "-" + tmp.get(1) + "-01";
												Date dt = Func.parse(v, ConcurrentDateFormat.of("yyyy-MM-dd"));
												rtuInfoEntity.setWaterSensorReplaceDate(dt);
											}


										}

										if (null != dataEntity.getGroundSensorType()) {
											List<DictBiz> bizs = DictBizCache.getList("ground_water_sensor_type");
											for (DictBiz biz : bizs) {
												if (dataEntity.getGroundSensorType().trim().contains(biz.getDictValue())) {
													rtuInfoEntity.setGroundSensorType(biz.getId());
													break;
												}
											}
										}

										if (null != dataEntity.getGroundSensorBrand()) {
											rtuInfoEntity.setGroundSensorBrand(dataEntity.getGroundSensorBrand().trim());
										}

										if (null != dataEntity.getGroundSensorModel()) {
											rtuInfoEntity.setGroundSensorModel(dataEntity.getGroundSensorModel().trim());
										}

										if (null != dataEntity.getGroundSensorReplaceDate()) {
											ArrayList<String> textArr = new ArrayList<>();
											textArr.add("");
											String replaceDate = dataEntity.getGroundSensorReplaceDate().trim();
											for (int l = 0; l < replaceDate.length(); l++) {
												String subtext = replaceDate.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() >= 3) {
												String v = tmp.get(0) + "-" + tmp.get(1) + "-" + tmp.get(2);
												Date dt = Func.parse(v, ConcurrentDateFormat.of("yyyy-MM-dd"));
												rtuInfoEntity.setGroundSensorReplaceDate(dt);
											} else if (tmp.size() == 2) {
												String v = tmp.get(0) + "-" + tmp.get(1) + "-01";
												Date dt = Func.parse(v, ConcurrentDateFormat.of("yyyy-MM-dd"));
												rtuInfoEntity.setGroundSensorReplaceDate(dt);
											}


										}

										if (null != dataEntity.getBatteryModel()) {
											rtuInfoEntity.setBatteryModel(dataEntity.getBatteryModel().trim());
										}

										if (null != dataEntity.getBatteryReplaceDate()) {
											ArrayList<String> textArr = new ArrayList<>();
											textArr.add("");
											String replaceDate = dataEntity.getBatteryReplaceDate().trim();
											for (int l = 0; l < replaceDate.length(); l++) {
												String subtext = replaceDate.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() >= 3) {
												String v = tmp.get(0) + "-" + tmp.get(1) + "-" + tmp.get(2);
												Date dt = Func.parse(v, ConcurrentDateFormat.of("yyyy-MM-dd"));
												rtuInfoEntity.setBatteryReplaceDate(dt);
											} else if (tmp.size() == 2) {
												String v = tmp.get(0) + "-" + tmp.get(1) + "-01";
												Date dt = Func.parse(v, ConcurrentDateFormat.of("yyyy-MM-dd"));
												rtuInfoEntity.setBatteryReplaceDate(dt);
											}


										}

										if (null != dataEntity.getSunModel()) {
											rtuInfoEntity.setSunPowerModel(dataEntity.getSunModel().trim());
										}

										if (null != dataEntity.getSimId()) {
											rtuInfoEntity.setNetworkSimId(dataEntity.getSimId().trim());
										}

										if (null != dataEntity.getSimPay()) {
											rtuInfoEntity.setNetworkPayer(dataEntity.getSimPay().trim());
										}

										if (null != dataEntity.getSimOverdate()) {
											ArrayList<String> textArr = new ArrayList<>();
											textArr.add("");
											String replaceDate = dataEntity.getSimOverdate().trim();
											for (int l = 0; l < replaceDate.length(); l++) {
												String subtext = replaceDate.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() >= 3) {
												String v = tmp.get(0) + "-" + tmp.get(1) + "-" + tmp.get(2);
												Date dt = Func.parse(v, ConcurrentDateFormat.of("yyyy-MM-dd"));
												rtuInfoEntity.setNetworkPayEndDate(dt);
											} else if (tmp.size() == 2) {
												String v = tmp.get(0) + "-" + tmp.get(1) + "-01";
												Date dt = Func.parse(v, ConcurrentDateFormat.of("yyyy-MM-dd"));
												rtuInfoEntity.setNetworkPayEndDate(dt);
											}


										}

										if (null != dataEntity.getSatellite()) {
											if (dataEntity.getSatellite().trim().equals("是")) {
												rtuInfoEntity.setIsSatellite(1);
											} else {
												rtuInfoEntity.setIsSatellite(0);
											}

										} else {
											rtuInfoEntity.setIsSatellite(0);
										}

										if (null != dataEntity.getSatelliteModel()) {
											List<DictBiz> bizs = DictBizCache.getList("satellite_model");
											for (DictBiz biz : bizs) {
												if (dataEntity.getSatelliteModel().trim().contains(biz.getDictValue())) {
													rtuInfoEntity.setSatelliteModel(biz.getId());
													break;
												}
											}

										}

										if (null != dataEntity.getRemark()) {
											rtuInfoEntity.setRemark(dataEntity.getRemark().trim());
										}

										//rtuInfoEntity.setProjectId(projectId);
										rtuInfoEntity.setOrgId(orgId);

										LambdaQueryWrapper<MvAttStBaseEntity> wrapper = Wrappers.<MvAttStBaseEntity>query().lambda();
										wrapper.eq(MvAttStBaseEntity::getIsDeleted,0);
										wrapper.eq(MvAttStBaseEntity::getStCode,rtuInfoEntity.getRtuCode());


//										MvAttStBaseEntity mvAttStBaseEntity=mvAttStBaseService.getOne(wrapper);
//										if (null != mvAttStBaseEntity){
//											rtuInfoEntity.
//										}

										RtuInfoEntity entity = rtuBaseInfoService.rtuInfoByRtuCode(rtuInfoEntity.getRtuCode());
										if (null != entity) {
											rtuInfoEntity.setId(entity.getId());
										}
										rtuBaseInfoService.saveOrUpdate(rtuInfoEntity);

										System.out.println("save record********************");

									} else {
										System.out.println(" record is null ********************");
										System.out.println(JSON.toJSON(dataEntity).toString());
									}
								} else {
									System.out.println(" record is null ********************");
									System.out.println(JSON.toJSON(dataEntity).toString());
								}
							} else {
								System.out.println(" record is null ********************");
								System.out.println(JSON.toJSON(dataEntity).toString());
							}

						}

						recordEntity.setImportStatus(1L);
						rtuImportRecordService.saveOrUpdate(recordEntity);
						//更新导入时间
						//projectBaseInfoService.updateImportTime(orgId, new Date());
					}
				}).sheet().doRead();

			} else {
				recordEntity.setImportStatus(2L);
				rtuImportRecordService.saveOrUpdate(recordEntity);
				return R.fail("上传文件格式错误");
			}

			return R.success("导入成功");
		} catch (IOException e) {
			e.printStackTrace();
			return R.fail("导入错误 " + e.getMessage());
		} catch (Exception e) {
			e.printStackTrace();
			return R.fail("导入错误 " + e.getMessage());
		}
	}
}
