临时导入火点信息
This commit is contained in:
parent
aa6cde425d
commit
bb98df5bed
@ -38,6 +38,7 @@ class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
.antMatchers("/queryFirePoint").permitAll()
|
||||
.antMatchers(HttpMethod.POST, "/api/user/updateSysUser").permitAll()
|
||||
.antMatchers(HttpMethod.GET, "/selectGlobalConfigDict").permitAll()
|
||||
.antMatchers(HttpMethod.GET, "/importThree").permitAll()
|
||||
.antMatchers(HttpMethod.GET, "/selectGlobalConfigValue").permitAll()
|
||||
.antMatchers(HttpMethod.GET, "/selectGlobalConfig").permitAll()
|
||||
.antMatchers(HttpMethod.POST, "/globalConfig").permitAll()
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.xkrs.controller;
|
||||
|
||||
import cn.hutool.core.date.SystemClock;
|
||||
import com.xkrs.common.encapsulation.PromptMessageEnum;
|
||||
import com.xkrs.common.tool.TokenUtil;
|
||||
import com.xkrs.dao.FirePointDao;
|
||||
@ -7,14 +8,16 @@ import com.xkrs.dao.ShanDongFirePointDao;
|
||||
import com.xkrs.dao.SysUserDao;
|
||||
import com.xkrs.model.entity.FirePointEntity;
|
||||
import com.xkrs.model.entity.ShanDongFirePointEntity;
|
||||
import com.xkrs.model.entity.StreetEntity;
|
||||
import com.xkrs.model.entity.SysUserEntity;
|
||||
import com.xkrs.model.qo.AuditFireTypeQo;
|
||||
import com.xkrs.model.qo.FirePointQo;
|
||||
import com.xkrs.model.qo.ShanDongFirePointVerifyStateQo;
|
||||
import com.xkrs.model.vo.GaoDeIgGeocodeVo;
|
||||
import com.xkrs.service.FirePointService;
|
||||
import com.xkrs.service.StreetService;
|
||||
import com.xkrs.service.impl.FirePointServiceImpl;
|
||||
import com.xkrs.utils.FirePointQueryHelper;
|
||||
import com.xkrs.utils.*;
|
||||
import org.apache.hc.core5.util.TextUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -28,12 +31,15 @@ import javax.persistence.criteria.Predicate;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.transaction.Transactional;
|
||||
import java.io.File;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.xkrs.common.encapsulation.OutputEncapsulation.outputEncapsulationObject;
|
||||
import static com.xkrs.utils.DateTimeUtil.dateTimeToString;
|
||||
|
||||
@RestController
|
||||
public class FirePointController {
|
||||
@ -60,6 +66,67 @@ public class FirePointController {
|
||||
@Resource
|
||||
private FirePointQueryHelper firePointQueryHelper;
|
||||
|
||||
@GetMapping("/importThree")
|
||||
public String importThree() throws Exception {
|
||||
String rootDir = "/Users/liuchengqian/Desktop/source_three/";
|
||||
ExcelImportUtil importUtil = new ExcelImportUtil(new File(rootDir+"1023.xlsx"));
|
||||
List<Map<String, String>> excelMapList = importUtil.readExcelContent();
|
||||
//20221024084045098124080
|
||||
for (int i = 0; i < excelMapList.size(); i++) {
|
||||
Map<String, String> excelMap = excelMapList.get(i);
|
||||
String 火点监测时间 = excelMap.get("火点监测时间");
|
||||
String 经度 = excelMap.get("经度");
|
||||
String 纬度 = excelMap.get("纬度");
|
||||
String 区县名称 = excelMap.get("区县名称");
|
||||
String 地表类型 = excelMap.get("地表类型");
|
||||
String 卫星源 = excelMap.get("卫星源");
|
||||
String 置信度 = excelMap.get("置信度");
|
||||
|
||||
FirePointEntity firePointEntity = new FirePointEntity();
|
||||
firePointEntity.setFireCode(String.valueOf(System.currentTimeMillis()));
|
||||
firePointEntity.setSatelliteTime(火点监测时间);
|
||||
firePointEntity.setLongitude(Double.parseDouble(经度));
|
||||
firePointEntity.setLatitude(Double.parseDouble(纬度));
|
||||
firePointEntity.setSatelliteType(卫星源);
|
||||
firePointEntity.setLandType(地表类型);
|
||||
firePointEntity.setConfidence(置信度);
|
||||
firePointEntity.setAddTime(火点监测时间);
|
||||
firePointEntity.setFireType("0");
|
||||
firePointEntity.setFireImage(null);
|
||||
firePointEntity.setSatelliteImage(null);
|
||||
firePointEntity.setAuditFireType("0");//初始化火点为未审核状态
|
||||
try {
|
||||
bindAddress(firePointEntity);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.info("添加火点信息 逆地理编码请求街道编号失败:" + e.getMessage());
|
||||
}
|
||||
firePointDao.save(firePointEntity);
|
||||
Thread.sleep(20);
|
||||
System.out.println("已完成" + (i) + "/" + excelMapList.size());
|
||||
}
|
||||
|
||||
Locale locale = LocaleContextHolder.getLocale();
|
||||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "OKK", locale);
|
||||
}
|
||||
private void bindAddress(FirePointEntity firePointEntity) throws Exception {
|
||||
List<String> locationList = new ArrayList<>();
|
||||
locationList.add(firePointEntity.getLongitude() + "," + firePointEntity.getLatitude());
|
||||
GaoDeIgGeocodeVo geocode = GaoDeApiUtil.geocode(locationList);
|
||||
GaoDeIgGeocodeVo.Regeocode reGeoCode = geocode.getRegeocodes().get(0);
|
||||
String formattedAddress = reGeoCode.getFormatted_address();
|
||||
firePointEntity.setFirePointAddress(formattedAddress);
|
||||
GaoDeIgGeocodeVo.AddressComponent addressComponent = reGeoCode.getAddressComponent().get(0);
|
||||
firePointEntity.setCountyCode(addressComponent.getAdcode());
|
||||
firePointEntity.setCountyName(addressComponent.getDistrict());
|
||||
String townCode = addressComponent.getTowncode();
|
||||
String fixedTownCode = townCode.length() > 9 ? townCode.substring(0, 9) : townCode;
|
||||
firePointEntity.setStreetCode(fixedTownCode);
|
||||
firePointEntity.setStreetName(addressComponent.getTownship());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@GetMapping("/queryzzhd")
|
||||
public String queryzzhd() {
|
||||
List<FirePointEntity> firePointEntities1 = firePointQueryHelper.queryZZHD("371482", "2022-01-01 00:00:10", "2022-06-26 00:00:10");
|
||||
|
@ -5,6 +5,8 @@ import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
@ -40,9 +42,22 @@ public class ExcelImportUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public ExcelImportUtil(File file) throws Exception {
|
||||
String filename = file.getAbsolutePath();
|
||||
String ext = filename.substring(filename.lastIndexOf("."));
|
||||
InputStream is = new FileInputStream(file);
|
||||
if (xls.equals(ext)) {
|
||||
wb = new HSSFWorkbook(is);
|
||||
} else if (xlsx.equals(ext)) {
|
||||
wb = new XSSFWorkbook(is);
|
||||
} else {
|
||||
wb = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 读取Excel表格表头的内容输出
|
||||
*
|
||||
*/
|
||||
public List<Map<String, Object>> readExcelTitleOut() {
|
||||
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
|
||||
@ -68,7 +83,6 @@ public class ExcelImportUtil {
|
||||
|
||||
/**
|
||||
* 读取Excel表格表头
|
||||
*
|
||||
*/
|
||||
public String[] readExcelTitle() {
|
||||
String[] title = {};
|
||||
@ -92,23 +106,23 @@ public class ExcelImportUtil {
|
||||
|
||||
/**
|
||||
* 读取Excel表格的某一个数值
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Map<String, Object> readExcelSomeTitle(){
|
||||
public Map<String, Object> readExcelSomeTitle() {
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
if (wb != null) {
|
||||
sheet = wb.getSheetAt(0);
|
||||
String title = parseExcel(sheet.getRow(2).getCell(1));
|
||||
String remark = parseExcel(sheet.getRow(3).getCell(1));
|
||||
map.put("date",title);
|
||||
map.put("remark",remark);
|
||||
map.put("date", title);
|
||||
map.put("remark", remark);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取Excel数据内容
|
||||
*
|
||||
*/
|
||||
public List<Map<String, String>> readExcelContent() {
|
||||
List<Map<String, String>> list = new ArrayList<>();
|
||||
@ -136,7 +150,7 @@ public class ExcelImportUtil {
|
||||
}
|
||||
}
|
||||
//判段添加的对象是否为空
|
||||
if (!map.isEmpty()){
|
||||
if (!map.isEmpty()) {
|
||||
list.add(map);
|
||||
}
|
||||
}
|
||||
@ -145,12 +159,11 @@ public class ExcelImportUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* 根据Cell类型设置数据
|
||||
*
|
||||
*/
|
||||
int ss = 20;
|
||||
int xx = 58;
|
||||
|
||||
private String parseExcel(Cell cell) {
|
||||
String result = "";
|
||||
if (cell != null) {
|
||||
|
52
src/main/java/com/xkrs/utils/FileUploadUtils.java
Normal file
52
src/main/java/com/xkrs/utils/FileUploadUtils.java
Normal file
@ -0,0 +1,52 @@
|
||||
package com.xkrs.utils;
|
||||
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class FileUploadUtils {
|
||||
|
||||
public static final boolean release = false;
|
||||
|
||||
private FileUploadUtils() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传单个文件
|
||||
*/
|
||||
public static String uploadFile(MultipartFile file) throws Exception {
|
||||
String uploadDirPath = "/Users/liuchengqian/Desktop/DaJiang/";
|
||||
String originalFilename = file.getOriginalFilename();
|
||||
int lastPointIndex = originalFilename.lastIndexOf(".");
|
||||
String extensionName = originalFilename.substring(lastPointIndex);
|
||||
String newFileName = UUID.randomUUID().toString() + extensionName;
|
||||
File uploadDir = new File(uploadDirPath);
|
||||
if ((!uploadDir.exists()) || (!uploadDir.isDirectory())) {
|
||||
uploadDir.mkdirs();
|
||||
}
|
||||
String uploadFilePath = uploadDirPath + newFileName;
|
||||
//实现上传
|
||||
file.transferTo(new File(uploadFilePath));
|
||||
|
||||
return uploadFilePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传多个文件
|
||||
*/
|
||||
public static List<String> uploadFileArray(MultipartFile[] fileArray) throws Exception {
|
||||
List<String> pathList = new ArrayList<>();
|
||||
if (fileArray == null || fileArray.length == 0) {
|
||||
return pathList;
|
||||
}
|
||||
for (MultipartFile file : fileArray) {
|
||||
if (file != null) {
|
||||
pathList.add(uploadFile(file));
|
||||
}
|
||||
}
|
||||
return pathList;
|
||||
}
|
||||
}
|
@ -57,7 +57,7 @@ public class GaoDeApiUtil {
|
||||
public static void main(String[] args) {
|
||||
|
||||
List<String> location = new ArrayList<>();
|
||||
location.add("120,36");
|
||||
location.add("117.849,35.59209");
|
||||
GaoDeIgGeocodeVo geocode = geocode(location);
|
||||
System.out.println("sdfghjm");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user