From 13e81b0a80794165bcb3a1070fb62fb625594b28 Mon Sep 17 00:00:00 2001 From: liuchengqian Date: Wed, 8 Jun 2022 10:09:15 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=97=A0=E7=94=A8=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- attach.txt | 10 ++ .../account/TokenAuthenticationService.java | 66 ++++++------- .../xkrs/common/config/WebSecurityConfig.java | 1 - .../xkrs/controller/FirePointController.java | 15 --- .../com/xkrs/controller/StreetController.java | 92 ------------------- .../com/xkrs/service/FirePointService.java | 8 -- .../service/impl/FirePointServiceImpl.java | 29 ------ 7 files changed, 37 insertions(+), 184 deletions(-) create mode 100644 attach.txt diff --git a/attach.txt b/attach.txt new file mode 100644 index 0000000..e8e1f6e --- /dev/null +++ b/attach.txt @@ -0,0 +1,10 @@ + +//调用封装好的工具 +ExcelImportUtil importUtil = new ExcelImportUtil(file); +//调用导入的方法,获取sheet表的内容 +List> maps = importUtil.readExcelContent(); + + +FileInputStream fileInputStream = IoUtil.toStream(file); +BufferedReader reader = IoUtil.getReader(fileInputStream, "UTF-8"); +Stream lines = reader.lines(); diff --git a/src/main/java/com/xkrs/common/account/TokenAuthenticationService.java b/src/main/java/com/xkrs/common/account/TokenAuthenticationService.java index 6c49ef8..4146114 100644 --- a/src/main/java/com/xkrs/common/account/TokenAuthenticationService.java +++ b/src/main/java/com/xkrs/common/account/TokenAuthenticationService.java @@ -2,7 +2,6 @@ package com.xkrs.common.account; import com.xkrs.common.encapsulation.OutputEncapsulation; import com.xkrs.common.encapsulation.PromptMessageEnum; -import com.xkrs.model.entity.SysUserEntity; import com.xkrs.model.vo.SysUserVo; import com.xkrs.utils.DateTimeUtil; import io.jsonwebtoken.Claims; @@ -26,6 +25,7 @@ import java.util.*; /** * token认证服务 + * * @author tajochen */ public class TokenAuthenticationService { @@ -35,9 +35,7 @@ public class TokenAuthenticationService { /** * 加密密钥 */ - static public final String SECRET_KEY = "0Y9H364Q9Y908262F25LMXGIKIN5N858XM3674GWL2DD8X1DS4W6I722IRY8PS4XPNB6U303" + - "45HBVCUL94STG8C3Z53T7A09JJ100I56YE9894CI11PX9J71HIZ8L5Y2O504C4E2K8276425UA8734833F45K36878FXAG799QV9LXU" + - "JOI3XA2046UPG8TB2OT84R5T6ZB127N9ZPJ7AJMC41JVHB2WK2B6H8NL45LZNAZ666KHZH3QUT65UX6F8"; + static public final String SECRET_KEY = "0Y9H364Q9Y908262F25LMXGIKIN5N858XM3674GWL2DD8X1DS4W6I722IRY8PS4XPNB6U303" + "45HBVCUL94STG8C3Z53T7A09JJ100I56YE9894CI11PX9J71HIZ8L5Y2O504C4E2K8276425UA8734833F45K36878FXAG799QV9LXU" + "JOI3XA2046UPG8TB2OT84R5T6ZB127N9ZPJ7AJMC41JVHB2WK2B6H8NL45LZNAZ666KHZH3QUT65UX6F8"; /** * Token前缀 */ @@ -51,27 +49,27 @@ public class TokenAuthenticationService { /** * JWT生成方法 + * * @param response * @param userName * @param authorities */ - static void addAuthentication(HttpServletResponse response, String userName, - Collection authorities, SysUserVo sysUserEntity, Map map1) { + static void addAuthentication(HttpServletResponse response, String userName, Collection authorities, SysUserVo sysUserEntity, Map map1) { Locale locale = new Locale("zh", "CN"); Map map = new HashMap(3); StringBuffer auths = new StringBuffer(); String authsList = ""; - for(GrantedAuthority r : authorities) { + for (GrantedAuthority r : authorities) { auths.append("," + r.getAuthority()); } authsList = auths.toString(); - if(authsList.length()>1){ - authsList=authsList.substring(1,authsList.length()); - }else{ - logger.warn(userName +" has no permission!"); + if (authsList.length() > 1) { + authsList = authsList.substring(1); + } else { + logger.warn(userName + " has no permission!"); } - if(sysUserEntity.getDayNum() == 7){ + if (sysUserEntity.getDayNum() == 7) { // 结束的时间 LocalDateTime overTime = DateTimeUtil.stringToDateTime(sysUserEntity.getOverTime()); // 计算距离结束时间的天数作为token @@ -79,51 +77,42 @@ public class TokenAuthenticationService { /** * 动态设置过期时间 */ - final long EXPIRATIONTIME = 60 * 60 * (duration.toDays()+1) * 24_000 ; + final long EXPIRATIONTIME = 60 * 60 * (duration.toDays() + 1) * 24_000; // 生成JWT - String jwt = Jwts.builder() - .setSubject(userName) - .setIssuer("https://www.microservice.com") - .setAudience(userName) + String jwt = Jwts.builder().setSubject(userName).setIssuer("https://www.microservice.com").setAudience(userName) // 保存权限 .claim("auths", authsList) // 有效期设置 .setExpiration(new Date(System.currentTimeMillis() + EXPIRATIONTIME)) // 签名设置 - .signWith(key) - .compact(); - map.put("token",jwt); - map.put("user",sysUserEntity); - map.put("cityAndCounty",map1); - }else { + .signWith(key).compact(); + map.put("token", jwt); + map.put("user", sysUserEntity); + map.put("cityAndCounty", map1); + } else { /** * 过期时间6小时 */ final long EXPIRATIONTIME = 21_600_000; // 生成JWT - String jwt = Jwts.builder() - .setSubject(userName) - .setIssuer("https://www.microservice.com") - .setAudience(userName) + String jwt = Jwts.builder().setSubject(userName).setIssuer("https://www.microservice.com").setAudience(userName) // 保存权限 .claim("auths", authsList) // 有效期设置 .setExpiration(new Date(System.currentTimeMillis() + EXPIRATIONTIME)) // 签名设置 - .signWith(key) - .compact(); - map.put("token",jwt); - map.put("user",sysUserEntity); - map.put("cityAndCounty",map1); + .signWith(key).compact(); + map.put("token", jwt); + map.put("user", sysUserEntity); + map.put("cityAndCounty", map1); } // 将 JWT 写入 body PrintWriter out = null; try { out = response.getWriter(); - } - catch (IOException e) { + } catch (IOException e) { e.printStackTrace(); } response.setStatus(HttpServletResponse.SC_OK); @@ -132,6 +121,7 @@ public class TokenAuthenticationService { /** * JWT验证方法 + * * @param request * @return */ @@ -141,17 +131,15 @@ public class TokenAuthenticationService { if (token != null) { try { // 解析 Token - Claims claims = Jwts.parserBuilder() - .setSigningKey(key).build() + Claims claims = Jwts.parserBuilder().setSigningKey(key).build() // 去掉 Bearer - .parseClaimsJws(token.replace(TOKEN_PREFIX, "")) - .getBody(); + .parseClaimsJws(token.replace(TOKEN_PREFIX, "")).getBody(); // 获取用户名 String userName = claims.getSubject(); // 获取权限 List authorities = AuthorityUtils.commaSeparatedStringToAuthorityList((String) claims.get("auths")); return new UsernamePasswordAuthenticationToken(userName, null, authorities); - } catch(Exception e) { + } catch (Exception e) { // the sub field was missing or did not have a value return null; } diff --git a/src/main/java/com/xkrs/common/config/WebSecurityConfig.java b/src/main/java/com/xkrs/common/config/WebSecurityConfig.java index cc1333a..9ca8ab3 100644 --- a/src/main/java/com/xkrs/common/config/WebSecurityConfig.java +++ b/src/main/java/com/xkrs/common/config/WebSecurityConfig.java @@ -58,7 +58,6 @@ class WebSecurityConfig extends WebSecurityConfigurerAdapter { .antMatchers(HttpMethod.GET, "/api/user/verificationCode").permitAll() .antMatchers(HttpMethod.POST, "/uploadFileMore").permitAll() .antMatchers(HttpMethod.POST, "/uploadFile").permitAll() - .antMatchers(HttpMethod.POST, "/importCityExcel").permitAll() .antMatchers(HttpMethod.POST, "/deleteShuiTi").permitAll() .antMatchers(HttpMethod.GET, "/selectBeijing").permitAll() .antMatchers(HttpMethod.GET, "/api/user/verificationCodeUpdate").permitAll() diff --git a/src/main/java/com/xkrs/controller/FirePointController.java b/src/main/java/com/xkrs/controller/FirePointController.java index 059eff0..33194ec 100644 --- a/src/main/java/com/xkrs/controller/FirePointController.java +++ b/src/main/java/com/xkrs/controller/FirePointController.java @@ -372,21 +372,6 @@ public class FirePointController { return outputEncapsulationObject(PromptMessageEnum.SUCCESS, byFireCode, locale); } - /** - * 导入全国省市区 - * - * @param file - * @return - * @throws Exception - */ - @PostMapping("/importCityExcel") - public String importCityExcel(MultipartFile file) throws Exception { - // 获取区域信息 - Locale locale = LocaleContextHolder.getLocale(); - firePointService.importCityExcel(file); - return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "导入成功", locale); - } - /** * 删除水体类型的火点信息 * diff --git a/src/main/java/com/xkrs/controller/StreetController.java b/src/main/java/com/xkrs/controller/StreetController.java index 4d3ef91..c665fd7 100644 --- a/src/main/java/com/xkrs/controller/StreetController.java +++ b/src/main/java/com/xkrs/controller/StreetController.java @@ -1,30 +1,18 @@ package com.xkrs.controller; -import cn.hutool.core.io.IoUtil; import com.xkrs.common.encapsulation.PromptMessageEnum; import com.xkrs.dao.CityDao; import com.xkrs.dao.CountyDao; import com.xkrs.dao.StreetDao; -import com.xkrs.model.entity.CityEntity; -import com.xkrs.model.entity.CountyEntity; -import com.xkrs.model.entity.StreetEntity; -import com.xkrs.model.vo.GaoDeIgGeocodeVo; -import com.xkrs.utils.GaoDeApiUtil; import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileInputStream; -import java.util.ArrayList; import java.util.List; import java.util.Locale; import java.util.Map; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.stream.Stream; import static com.xkrs.common.encapsulation.OutputEncapsulation.outputEncapsulationObject; @@ -93,84 +81,4 @@ public class StreetController { return outputEncapsulationObject(PromptMessageEnum.SUCCESS, streetList, locale); } - @GetMapping("/formatStreetData") - public String formatStreetData() { - File file = new File("/Users/liuchengqian/Downloads/Administrative-divisions-of-China-master/dist/streets2.csv"); - FileInputStream fileInputStream = IoUtil.toStream(file); - BufferedReader reader = IoUtil.getReader(fileInputStream, "UTF-8"); - Stream lines = reader.lines(); - AtomicInteger count = new AtomicInteger(); - lines.forEach(content -> { - try { - content = content.replace("\"", ""); - String[] split = content.split(","); - StreetEntity streetEntity = new StreetEntity(); - streetEntity.setProCode(split[3] + "0000"); - List byProCode1 = cityDao.findByProCode(streetEntity.getProCode()); - if (byProCode1 == null || byProCode1.isEmpty()) { - streetEntity.setProName(""); - } else { - streetEntity.setProName(byProCode1.get(0).getProName()); - } - streetEntity.setCityCode(split[4] + "00"); - List byCityCode1 = countyDao.findByCityCode(streetEntity.getCityCode()); - if (byCityCode1 == null || byCityCode1.isEmpty()) { - streetEntity.setCityName(""); - } else { - streetEntity.setCityName(byCityCode1.get(0).getCityName()); - } - streetEntity.setCountyCode(split[2]); - List byCountyCode = countyDao.findByCountyCode(streetEntity.getCountyCode()); - if (byCountyCode == null || byCountyCode.isEmpty()) { - streetEntity.setCountyName(""); - } else { - streetEntity.setCountyName(byCountyCode.get(0).getCountyName()); - } - streetEntity.setStreetCode(split[0]); - streetEntity.setStreetName(split[1]); - streetDao.save(streetEntity); - count.getAndIncrement(); - System.out.println(content + " >>> " + count); - System.out.println(streetEntity.toString()); - } catch (Exception e) { - e.printStackTrace(); - System.out.println("格式化街道数据时发生异常:" + e.getMessage()); - } - }); - return "666"; - } - - @GetMapping("/formatStreetData2") - public String formatStreetData2() { - StringBuilder stringBuilder = new StringBuilder(); - File file = new File("/Users/liuchengqian/Desktop/20200601-20220510火点统计.csv"); - FileInputStream fileInputStream = IoUtil.toStream(file); - BufferedReader reader = IoUtil.getReader(fileInputStream, "UTF-8"); - Stream lines = reader.lines(); -// AtomicInteger count = new AtomicInteger(); - lines.forEach(content -> { - try { - content = content.replace("\"", ""); - String[] split = content.split(","); - List locationList = new ArrayList<>(); - locationList.add(split[0]+ "," +split[1]); - GaoDeIgGeocodeVo geocode = GaoDeApiUtil.geocode(locationList); - String formattedAddress= geocode.getRegeocodes().get(0).getFormatted_address();//getAddressComponent().get(0).getTowncode(); - stringBuilder.append(content).append(",").append(formattedAddress).append("\n"); -// if (townCode.length() > 9) { -// townCode = townCode.substring(0, 9); -// } -// System.out.println(townCode); -// count.getAndIncrement(); -// System.out.println(content + " >>> " + count); -// stringBuilder.append(content).append(",").append() - } catch (Exception e) { - e.printStackTrace(); - System.out.println("格式化街道数据时发生异常:" + e.getMessage()); - } - }); - return stringBuilder.toString(); - } - - } diff --git a/src/main/java/com/xkrs/service/FirePointService.java b/src/main/java/com/xkrs/service/FirePointService.java index d9e3fd5..48881e5 100644 --- a/src/main/java/com/xkrs/service/FirePointService.java +++ b/src/main/java/com/xkrs/service/FirePointService.java @@ -122,14 +122,6 @@ public interface FirePointService { */ List> selectCountyName(String code); - /** - * 导入全国省市区 - * - * @param file - * @throws Exception - */ - void importCityExcel(MultipartFile file) throws Exception; - /** * 更新火点的街道编号数据 * diff --git a/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java b/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java index 21b6e86..50a5c7d 100644 --- a/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java +++ b/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java @@ -32,7 +32,6 @@ import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; import java.util.*; -import java.util.stream.Collectors; import static com.xkrs.common.encapsulation.OutputEncapsulation.outputEncapsulationObject; import static com.xkrs.utils.DateTimeUtil.dateTimeToString; @@ -767,34 +766,6 @@ public class FirePointServiceImpl implements FirePointService { return countyDao.selectCountyName(code); } - /** - * 导入全国省市区 - * - * @param file - * @throws Exception - */ - @Transactional(rollbackOn = Exception.class) - @Override - public void importCityExcel(MultipartFile file) throws Exception { - //调用封装好的工具 - ExcelImportUtil importUtil = new ExcelImportUtil(file); - //调用导入的方法,获取sheet表的内容 - List> maps = importUtil.readExcelContent(); - //导入订单详情表 - List orderDetails = maps.stream().filter(Objects::nonNull).map(map -> { - Nationwide nationwide = new Nationwide(); - nationwide.setProName(map.get("pro_name")); - nationwide.setProCode(map.get("pro_code")); - nationwide.setCityName(map.get("city_name")); - nationwide.setCityCode(map.get("city_code")); - nationwide.setCountyName(map.get("town_name")); - nationwide.setCountyCode(map.get("town_code")); - return nationwide; - }).collect(Collectors.toList()); - //批量添加到订单详情 - nationwideDao.saveAll(orderDetails); - } - /** * 更新火点的街道编号数据 *