From 329bc490f23cdfee1adc511fc78c388586f5fa89 Mon Sep 17 00:00:00 2001 From: liuchengqian Date: Thu, 19 May 2022 10:13:26 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=B0=E5=BD=95=E7=94=A8=E6=88=B7=E6=B3=A8?= =?UTF-8?q?=E5=86=8C=E6=97=B6=E7=9A=84UserAgent?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xkrs/controller/SysUserController.java | 5 ++- .../com/xkrs/model/entity/SysUserEntity.java | 38 ++++++++++++++++++- .../java/com/xkrs/service/SysUserService.java | 3 +- .../xkrs/service/impl/SysUserServiceImpl.java | 4 +- 4 files changed, 45 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/xkrs/controller/SysUserController.java b/src/main/java/com/xkrs/controller/SysUserController.java index b890ddc..7544240 100644 --- a/src/main/java/com/xkrs/controller/SysUserController.java +++ b/src/main/java/com/xkrs/controller/SysUserController.java @@ -21,6 +21,7 @@ import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; import java.util.HashMap; import java.util.List; import java.util.Locale; @@ -73,7 +74,7 @@ public class SysUserController { } @RequestMapping(value = "/add", method = RequestMethod.POST) - public String addUser(@Validated({SysUserQoInsert.class}) @RequestBody SysUserQo userQo, BindingResult bindingResult) { + public String addUser(@Validated({SysUserQoInsert.class}) @RequestBody SysUserQo userQo, BindingResult bindingResult, HttpServletRequest servletRequest) { // 获取区域信息 Locale locale = LocaleContextHolder.getLocale(); // 验证数据合法性 @@ -85,7 +86,7 @@ public class SysUserController { return outputEncapsulationObject(PromptMessageEnum.PARAM_ILLEGAL, "该账号已经注册,请勿重复注册", locale); } // 添加新用户 - return sysUserService.addUser(userQo); + return sysUserService.addUser(userQo, servletRequest); } /** diff --git a/src/main/java/com/xkrs/model/entity/SysUserEntity.java b/src/main/java/com/xkrs/model/entity/SysUserEntity.java index bec5427..8214360 100644 --- a/src/main/java/com/xkrs/model/entity/SysUserEntity.java +++ b/src/main/java/com/xkrs/model/entity/SysUserEntity.java @@ -98,6 +98,12 @@ public class SysUserEntity implements Serializable { */ private String loginLastTime; + /** + * 注册时的UA + */ + @Column(columnDefinition = "varchar(1024)") + private String userAgent; + public SysUserEntity() { } @@ -261,8 +267,38 @@ public class SysUserEntity implements Serializable { this.loginLastTime = loginLastTime; } + public String getUserAgent() { + return userAgent; + } + + public void setUserAgent(String userAgent) { + this.userAgent = userAgent; + } + @Override public String toString() { - return "SysUserEntity{" + "id=" + id + ", userName='" + userName + '\'' + ", reallyName='" + reallyName + '\'' + ", password='" + password + '\'' + ", salt='" + salt + '\'' + ", telephone='" + telephone + '\'' + ", countyCode='" + countyCode + '\'' + ", signature='" + signature + '\'' + ", activeFlag=" + activeFlag + ", statusCode=" + statusCode + ", addTime='" + addTime + '\'' + ", lastEntryTime=" + lastEntryTime + ", deleteFlag=" + deleteFlag + ", lastEntryIp='" + lastEntryIp + '\'' + ", dayNum=" + dayNum + ", overTime='" + overTime + '\'' + ", accountType='" + accountType + '\'' + ", countyName='" + countyName + '\'' + ", loginNum=" + loginNum + ", loginLastTime='" + loginLastTime + '\'' + '}'; + return "SysUserEntity{" + + "id=" + id + + ", userName='" + userName + '\'' + + ", reallyName='" + reallyName + '\'' + + ", password='" + password + '\'' + + ", salt='" + salt + '\'' + + ", telephone='" + telephone + '\'' + + ", countyCode='" + countyCode + '\'' + + ", signature='" + signature + '\'' + + ", activeFlag=" + activeFlag + + ", statusCode=" + statusCode + + ", addTime='" + addTime + '\'' + + ", lastEntryTime=" + lastEntryTime + + ", deleteFlag=" + deleteFlag + + ", lastEntryIp='" + lastEntryIp + '\'' + + ", dayNum=" + dayNum + + ", overTime='" + overTime + '\'' + + ", accountType='" + accountType + '\'' + + ", countyName='" + countyName + '\'' + + ", loginNum=" + loginNum + + ", loginLastTime='" + loginLastTime + '\'' + + ", userAgent='" + userAgent + '\'' + + '}'; } } diff --git a/src/main/java/com/xkrs/service/SysUserService.java b/src/main/java/com/xkrs/service/SysUserService.java index 442802f..143a9d3 100644 --- a/src/main/java/com/xkrs/service/SysUserService.java +++ b/src/main/java/com/xkrs/service/SysUserService.java @@ -4,6 +4,7 @@ import com.xkrs.model.entity.SysUserEntity; import com.xkrs.model.qo.SysUserQo; import com.xkrs.model.vo.SysUserVo; +import javax.servlet.http.HttpServletRequest; import java.util.List; import java.util.Map; @@ -28,7 +29,7 @@ public interface SysUserService { * @param sysUserQo * @return */ - String addUser(SysUserQo sysUserQo); + String addUser(SysUserQo sysUserQo, HttpServletRequest servletRequest); /** * 删除系统用户 diff --git a/src/main/java/com/xkrs/service/impl/SysUserServiceImpl.java b/src/main/java/com/xkrs/service/impl/SysUserServiceImpl.java index 48f78cc..1007caf 100644 --- a/src/main/java/com/xkrs/service/impl/SysUserServiceImpl.java +++ b/src/main/java/com/xkrs/service/impl/SysUserServiceImpl.java @@ -15,6 +15,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; import java.time.LocalDateTime; import java.util.List; import java.util.Locale; @@ -78,12 +79,13 @@ public class SysUserServiceImpl implements SysUserService { */ @Transactional(rollbackFor = Exception.class) @Override - public String addUser(SysUserQo sysUserQo) { + public String addUser(SysUserQo sysUserQo, HttpServletRequest servletRequest) { // 获取区域信息 Locale locale = LocaleContextHolder.getLocale(); String salt = KeyGenerators.string().generateKey(); SysUserEntity sysUserEntity = new SysUserEntity(); sysUserEntity.setUserName(sysUserQo.getUserName()); + sysUserEntity.setUserAgent(servletRequest.getHeader("user-agent")); String o = (String) redisService.get(sysUserQo.getUserName()); if ("".equals(o) || o == null) { return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG, "请先发送验证码!", locale);