diff --git a/src/main/java/com/xkrs/common/config/WebSecurityConfig.java b/src/main/java/com/xkrs/common/config/WebSecurityConfig.java index 9cd0285..d0970dc 100644 --- a/src/main/java/com/xkrs/common/config/WebSecurityConfig.java +++ b/src/main/java/com/xkrs/common/config/WebSecurityConfig.java @@ -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() diff --git a/src/main/java/com/xkrs/controller/FirePointController.java b/src/main/java/com/xkrs/controller/FirePointController.java index bc4e95b..c6e11ac 100644 --- a/src/main/java/com/xkrs/controller/FirePointController.java +++ b/src/main/java/com/xkrs/controller/FirePointController.java @@ -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> excelMapList = importUtil.readExcelContent(); + //20221024084045098124080 + for (int i = 0; i < excelMapList.size(); i++) { + Map 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 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 firePointEntities1 = firePointQueryHelper.queryZZHD("371482", "2022-01-01 00:00:10", "2022-06-26 00:00:10"); diff --git a/src/main/java/com/xkrs/utils/ExcelImportUtil.java b/src/main/java/com/xkrs/utils/ExcelImportUtil.java index 8788901..57d86a6 100644 --- a/src/main/java/com/xkrs/utils/ExcelImportUtil.java +++ b/src/main/java/com/xkrs/utils/ExcelImportUtil.java @@ -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> readExcelTitleOut() { List> list = new ArrayList>(); @@ -68,7 +83,6 @@ public class ExcelImportUtil { /** * 读取Excel表格表头 - * */ public String[] readExcelTitle() { String[] title = {}; @@ -92,23 +106,23 @@ public class ExcelImportUtil { /** * 读取Excel表格的某一个数值 + * * @return */ - public Map readExcelSomeTitle(){ + public Map readExcelSomeTitle() { Map 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> readExcelContent() { List> 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) { diff --git a/src/main/java/com/xkrs/utils/FileUploadUtils.java b/src/main/java/com/xkrs/utils/FileUploadUtils.java new file mode 100644 index 0000000..38f83d5 --- /dev/null +++ b/src/main/java/com/xkrs/utils/FileUploadUtils.java @@ -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 uploadFileArray(MultipartFile[] fileArray) throws Exception { + List pathList = new ArrayList<>(); + if (fileArray == null || fileArray.length == 0) { + return pathList; + } + for (MultipartFile file : fileArray) { + if (file != null) { + pathList.add(uploadFile(file)); + } + } + return pathList; + } +} diff --git a/src/main/java/com/xkrs/utils/GaoDeApiUtil.java b/src/main/java/com/xkrs/utils/GaoDeApiUtil.java index 34a78d9..ab58188 100644 --- a/src/main/java/com/xkrs/utils/GaoDeApiUtil.java +++ b/src/main/java/com/xkrs/utils/GaoDeApiUtil.java @@ -57,7 +57,7 @@ public class GaoDeApiUtil { public static void main(String[] args) { List location = new ArrayList<>(); - location.add("120,36"); + location.add("117.849,35.59209"); GaoDeIgGeocodeVo geocode = geocode(location); System.out.println("sdfghjm");