From 088155b2d6f2c22da010fd693f7e9d0c70088d07 Mon Sep 17 00:00:00 2001 From: liuchengqian Date: Wed, 8 Jun 2022 11:29:05 +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 --- .../xkrs/common/account/JwtLoginFilter.java | 32 +--- .../account/TokenAuthenticationService.java | 4 +- src/main/java/com/xkrs/dao/NationwideDao.java | 40 ----- .../com/xkrs/model/entity/Nationwide.java | 137 ------------------ .../java/com/xkrs/service/SysUserService.java | 19 --- .../service/impl/FirePointServiceImpl.java | 3 - .../xkrs/service/impl/SysUserServiceImpl.java | 19 --- 7 files changed, 2 insertions(+), 252 deletions(-) delete mode 100644 src/main/java/com/xkrs/dao/NationwideDao.java delete mode 100644 src/main/java/com/xkrs/model/entity/Nationwide.java diff --git a/src/main/java/com/xkrs/common/account/JwtLoginFilter.java b/src/main/java/com/xkrs/common/account/JwtLoginFilter.java index dc52445..431b352 100644 --- a/src/main/java/com/xkrs/common/account/JwtLoginFilter.java +++ b/src/main/java/com/xkrs/common/account/JwtLoginFilter.java @@ -3,7 +3,6 @@ package com.xkrs.common.account; import com.xkrs.common.encapsulation.OutputEncapsulation; import com.xkrs.common.encapsulation.PromptMessageEnum; import com.xkrs.model.vo.SysUserVo; -import com.xkrs.service.StreetService; import com.xkrs.service.SysUserService; import com.xkrs.utils.IpUtil; import org.slf4j.Logger; @@ -28,10 +27,7 @@ import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.PrintWriter; import java.io.UnsupportedEncodingException; -import java.util.HashMap; -import java.util.List; import java.util.Locale; -import java.util.Map; /** * jwt登录过滤器 @@ -45,9 +41,6 @@ public class JwtLoginFilter extends AbstractAuthenticationProcessingFilter { @Resource private SysUserService sysUserService; - @Resource - private StreetService streetService; - public JwtLoginFilter(String url, AuthenticationManager authManager) { super(new AntPathRequestMatcher(url)); setAuthenticationManager(authManager); @@ -101,11 +94,6 @@ public class JwtLoginFilter extends AbstractAuthenticationProcessingFilter { WebApplicationContext webApplicationContext = WebApplicationContextUtils.getWebApplicationContext(servletContext); sysUserService = webApplicationContext.getBean(SysUserService.class); } - if (streetService == null) { - ServletContext servletContext = req.getServletContext(); - WebApplicationContext webApplicationContext = WebApplicationContextUtils.getWebApplicationContext(servletContext); - streetService = webApplicationContext.getBean(StreetService.class); - } //更新用户登录信息 sysUserService.updateSysUserLogin(auth.getName(), IpUtil.getIpAddr(req)); SysUserVo userByUserName = sysUserService.getUserByUserName(auth.getName()); @@ -113,25 +101,7 @@ public class JwtLoginFilter extends AbstractAuthenticationProcessingFilter { response.setHeader("Access-Control-Allow-Credentials", "false"); response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); - Map map = new HashMap(3); - if (9 == userByUserName.getCountyCode().length()) { - List> streetByCountyCode = streetService.selectStreetList(userByUserName.getCountyCode()); - map.put("county", streetByCountyCode); - TokenAuthenticationService.addAuthentication(response, auth.getName(), auth.getAuthorities(), userByUserName, map); - } else if (userByUserName.getCountyCode().substring(2).equals("0000")) { - List> cityByProCode = sysUserService.findCityByProCode(userByUserName.getCountyCode()); - map.put("city", cityByProCode); - List> countyByProCode = sysUserService.findCountyByProCode(userByUserName.getCountyCode()); - map.put("county", countyByProCode); - TokenAuthenticationService.addAuthentication(response, auth.getName(), auth.getAuthorities(), userByUserName, map); - } else if (userByUserName.getCountyCode().substring(4).equals("00") && !userByUserName.getCountyCode().substring(2).equals("0000")) { - List> countyByCityCode = sysUserService.findCountyByCityCode(userByUserName.getCountyCode()); - map.put("county", countyByCityCode); - TokenAuthenticationService.addAuthentication(response, auth.getName(), auth.getAuthorities(), userByUserName, map); - } else { - map.put("county", null); - TokenAuthenticationService.addAuthentication(response, auth.getName(), auth.getAuthorities(), userByUserName, map); - } + TokenAuthenticationService.addAuthentication(response, auth.getName(), auth.getAuthorities(), userByUserName); } /** diff --git a/src/main/java/com/xkrs/common/account/TokenAuthenticationService.java b/src/main/java/com/xkrs/common/account/TokenAuthenticationService.java index 4146114..f0bc1a7 100644 --- a/src/main/java/com/xkrs/common/account/TokenAuthenticationService.java +++ b/src/main/java/com/xkrs/common/account/TokenAuthenticationService.java @@ -54,7 +54,7 @@ public class TokenAuthenticationService { * @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) { Locale locale = new Locale("zh", "CN"); Map map = new HashMap(3); @@ -89,7 +89,6 @@ public class TokenAuthenticationService { .signWith(key).compact(); map.put("token", jwt); map.put("user", sysUserEntity); - map.put("cityAndCounty", map1); } else { /** * 过期时间6小时 @@ -106,7 +105,6 @@ public class TokenAuthenticationService { .signWith(key).compact(); map.put("token", jwt); map.put("user", sysUserEntity); - map.put("cityAndCounty", map1); } // 将 JWT 写入 body PrintWriter out = null; diff --git a/src/main/java/com/xkrs/dao/NationwideDao.java b/src/main/java/com/xkrs/dao/NationwideDao.java deleted file mode 100644 index f429328..0000000 --- a/src/main/java/com/xkrs/dao/NationwideDao.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.xkrs.dao; - -import com.xkrs.model.entity.Nationwide; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -import org.springframework.stereotype.Component; - -import java.util.List; -import java.util.Map; - -/** - * @author XinYi Song - */ -@Component -public interface NationwideDao extends JpaRepository { - - /** - * 通过省编码查询市名称和编码 - * @param proCode - * @return - */ - @Query(value = "select DISTINCT city_name,city_code from nationwide where pro_code = ?",nativeQuery = true) - List> findCityByProCode(String proCode); - - /** - * 通过省编码查询县名称和编码 - * @param proCode - * @return - */ - @Query(value = "select county_name,county_code from nationwide where pro_code = ?",nativeQuery = true) - List> findCountyByProCode(String proCode); - - /** - * 通过市编码查询区县名称和编码 - * @param cityCode - * @return - */ - @Query(value = "select county_name,county_code from nationwide where city_code = ?",nativeQuery = true) - List> findCountyByCityCode(String cityCode); -} diff --git a/src/main/java/com/xkrs/model/entity/Nationwide.java b/src/main/java/com/xkrs/model/entity/Nationwide.java deleted file mode 100644 index 802c6bc..0000000 --- a/src/main/java/com/xkrs/model/entity/Nationwide.java +++ /dev/null @@ -1,137 +0,0 @@ -package com.xkrs.model.entity; - -import javax.persistence.*; - -/** - * @author XinYi Song - * 全国省市区 - */ -@Entity -@Table(name = "nationwide") -public class Nationwide { - /** - * 主键id - */ - @Id - @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "nationwide_seq_gen") - @SequenceGenerator(name = "nationwide_seq_gen", sequenceName = "nationwide_id_seq",allocationSize = 1) - private Integer id; - - /** - * 省名称 - */ - @Column(length = 65, columnDefinition = "varchar(65)") - private String proName; - - /** - * 省编码 - */ - @Column(length = 65, columnDefinition = "varchar(65)") - private String proCode; - - /** - * 市名称 - */ - @Column(length = 65, columnDefinition = "varchar(65)") - private String cityName; - - /** - * 市编码 - */ - @Column(length = 65, columnDefinition = "varchar(65)") - private String cityCode; - - /** - * 区县名称 - */ - @Column(length = 65, columnDefinition = "varchar(65)") - private String countyName; - - /** - * 区县编码 - */ - @Column(length = 65, columnDefinition = "varchar(65)") - private String countyCode; - - public Nationwide() { - } - - public Nationwide(Integer id, String proName, String proCode, String cityName, String cityCode, String countyName, String countyCode) { - this.id = id; - this.proName = proName; - this.proCode = proCode; - this.cityName = cityName; - this.cityCode = cityCode; - this.countyName = countyName; - this.countyCode = countyCode; - } - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public String getProName() { - return proName; - } - - public void setProName(String proName) { - this.proName = proName; - } - - public String getProCode() { - return proCode; - } - - public void setProCode(String proCode) { - this.proCode = proCode; - } - - public String getCityName() { - return cityName; - } - - public void setCityName(String cityName) { - this.cityName = cityName; - } - - public String getCityCode() { - return cityCode; - } - - public void setCityCode(String cityCode) { - this.cityCode = cityCode; - } - - public String getCountyName() { - return countyName; - } - - public void setCountyName(String countyName) { - this.countyName = countyName; - } - - public String getCountyCode() { - return countyCode; - } - - public void setCountyCode(String countyCode) { - this.countyCode = countyCode; - } - - @Override - public String toString() { - return "Nationwide{" + - "id=" + id + - ", proName='" + proName + '\'' + - ", proCode='" + proCode + '\'' + - ", cityName='" + cityName + '\'' + - ", cityCode='" + cityCode + '\'' + - ", countyName='" + countyName + '\'' + - ", countyCode='" + countyCode + '\'' + - '}'; - } -} diff --git a/src/main/java/com/xkrs/service/SysUserService.java b/src/main/java/com/xkrs/service/SysUserService.java index 143a9d3..91135ab 100644 --- a/src/main/java/com/xkrs/service/SysUserService.java +++ b/src/main/java/com/xkrs/service/SysUserService.java @@ -6,7 +6,6 @@ import com.xkrs.model.vo.SysUserVo; import javax.servlet.http.HttpServletRequest; import java.util.List; -import java.util.Map; /** * 系统用户服务接口 @@ -182,22 +181,4 @@ public interface SysUserService { */ void updateLoginLastTime(Integer userId, String loginLastTime); - - List> findCityByProCode(String proCode); - - /** - * 通过省编码查询县名称和编码 - * - * @param proCode - * @return - */ - List> findCountyByProCode(String proCode); - - /** - * 通过市编码查询区县名称和编码 - * - * @param cityCode - * @return - */ - List> findCountyByCityCode(String cityCode); } diff --git a/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java b/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java index 7baea4e..97240eb 100644 --- a/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java +++ b/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java @@ -76,9 +76,6 @@ public class FirePointServiceImpl implements FirePointService { @Resource private StreetDao streetDao; - @Resource - private NationwideDao nationwideDao; - @Resource private CountyCodeWeiXinDao countyCodeWeiXinDao; diff --git a/src/main/java/com/xkrs/service/impl/SysUserServiceImpl.java b/src/main/java/com/xkrs/service/impl/SysUserServiceImpl.java index 088d4aa..c4feca4 100644 --- a/src/main/java/com/xkrs/service/impl/SysUserServiceImpl.java +++ b/src/main/java/com/xkrs/service/impl/SysUserServiceImpl.java @@ -19,7 +19,6 @@ import javax.servlet.http.HttpServletRequest; import java.time.LocalDateTime; 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; @@ -48,9 +47,6 @@ public class SysUserServiceImpl implements SysUserService { @Resource private RedisService redisService; - @Resource - private NationwideDao nationwideDao; - @Resource private StreetDao streetDao; @@ -468,19 +464,4 @@ public class SysUserServiceImpl implements SysUserService { sysUserDao.updateLoginLastTime(userId, loginLastTime); } - @Override - public List> findCityByProCode(String proCode) { - return nationwideDao.findCityByProCode(proCode); - } - - @Override - public List> findCountyByProCode(String proCode) { - return nationwideDao.findCountyByProCode(proCode); - } - - @Override - public List> findCountyByCityCode(String cityCode) { - return nationwideDao.findCountyByCityCode(cityCode); - } - }