Commit 94b83dbabd54c789bb237e0828bc64981126ed6c
1 parent
c4e54cba
优化日志
Showing
4 changed files
with
140 additions
and
37 deletions
Bsth-admin/src/main/java/com/ruoyi/controller/RefreshController.java
| 1 | package com.ruoyi.controller; | 1 | package com.ruoyi.controller; |
| 2 | 2 | ||
| 3 | +import com.alibaba.fastjson2.JSON; | ||
| 3 | import com.ruoyi.common.core.domain.ResponseResult; | 4 | import com.ruoyi.common.core.domain.ResponseResult; |
| 4 | import com.ruoyi.common.utils.sign.Base64; | 5 | import com.ruoyi.common.utils.sign.Base64; |
| 5 | import com.ruoyi.controller.dss.DssFaceController; | 6 | import com.ruoyi.controller.dss.DssFaceController; |
| @@ -15,6 +16,7 @@ import com.ruoyi.service.scheduling.LinggangSchedulingService; | @@ -15,6 +16,7 @@ import com.ruoyi.service.scheduling.LinggangSchedulingService; | ||
| 15 | import com.ruoyi.utils.DateUtil; | 16 | import com.ruoyi.utils.DateUtil; |
| 16 | import io.swagger.annotations.ApiOperation; | 17 | import io.swagger.annotations.ApiOperation; |
| 17 | import lombok.extern.slf4j.Slf4j; | 18 | import lombok.extern.slf4j.Slf4j; |
| 19 | +import org.apache.commons.collections4.CollectionUtils; | ||
| 18 | import org.apache.commons.io.FileUtils; | 20 | import org.apache.commons.io.FileUtils; |
| 19 | import org.apache.commons.lang3.ArrayUtils; | 21 | import org.apache.commons.lang3.ArrayUtils; |
| 20 | import org.apache.commons.lang3.StringUtils; | 22 | import org.apache.commons.lang3.StringUtils; |
| @@ -26,10 +28,7 @@ import org.springframework.web.bind.annotation.*; | @@ -26,10 +28,7 @@ import org.springframework.web.bind.annotation.*; | ||
| 26 | import java.io.File; | 28 | import java.io.File; |
| 27 | import java.io.IOException; | 29 | import java.io.IOException; |
| 28 | import java.text.ParseException; | 30 | import java.text.ParseException; |
| 29 | -import java.util.Date; | ||
| 30 | -import java.util.List; | ||
| 31 | -import java.util.Objects; | ||
| 32 | -import java.util.Set; | 31 | +import java.util.*; |
| 33 | import java.util.stream.Collectors; | 32 | import java.util.stream.Collectors; |
| 34 | 33 | ||
| 35 | /** | 34 | /** |
| @@ -69,8 +68,8 @@ public class RefreshController { | @@ -69,8 +68,8 @@ public class RefreshController { | ||
| 69 | @GetMapping(value = "/key/info/local") | 68 | @GetMapping(value = "/key/info/local") |
| 70 | @ApiOperation("/key/info/local") | 69 | @ApiOperation("/key/info/local") |
| 71 | @PreAuthorize("@ss.hasPermi('refresh:key:info:local')") | 70 | @PreAuthorize("@ss.hasPermi('refresh:key:info:local')") |
| 72 | - public ResponseResult<Boolean> testKeyInfoLocal(@RequestParam(value = "dateStr",required = false) String dateStr) throws ParseException { | ||
| 73 | - if(StringUtils.isEmpty(dateStr)){ | 71 | + public ResponseResult<Boolean> testKeyInfoLocal(@RequestParam(value = "dateStr", required = false) String dateStr) throws ParseException { |
| 72 | + if (StringUtils.isEmpty(dateStr)) { | ||
| 74 | dateStr = DateUtil.YYYY_MM_DD_LINK.format(new Date()); | 73 | dateStr = DateUtil.YYYY_MM_DD_LINK.format(new Date()); |
| 75 | } | 74 | } |
| 76 | Date date = DateUtil.YYYY_MM_DD_LINK.parse(dateStr); | 75 | Date date = DateUtil.YYYY_MM_DD_LINK.parse(dateStr); |
| @@ -136,11 +135,15 @@ public class RefreshController { | @@ -136,11 +135,15 @@ public class RefreshController { | ||
| 136 | FaceRegisterDTO dto = new FaceRegisterDTO(); | 135 | FaceRegisterDTO dto = new FaceRegisterDTO(); |
| 137 | dto.setDevice(device); | 136 | dto.setDevice(device); |
| 138 | 137 | ||
| 139 | - String jobCode = StringUtils.trim(StringUtils.substringBeforeLast(file.getName(), ".")); | 138 | + String jobCode = StringUtils.trim(StringUtils.substringBeforeLast(fs[i].getName(), ".")); |
| 140 | dto.setStaffCode(jobCode); | 139 | dto.setStaffCode(jobCode); |
| 141 | 140 | ||
| 142 | 141 | ||
| 143 | NewDriver driver = newDriverService.getOne(jobCode); | 142 | NewDriver driver = newDriverService.getOne(jobCode); |
| 143 | + if (Objects.isNull(driver)) { | ||
| 144 | + log.info("没有人员信息:[{}]", dto); | ||
| 145 | + continue; | ||
| 146 | + } | ||
| 144 | if (StringUtils.isNotEmpty(driver.getImage())) { | 147 | if (StringUtils.isNotEmpty(driver.getImage())) { |
| 145 | log.info("人脸数据已经存在:[{}]", dto); | 148 | log.info("人脸数据已经存在:[{}]", dto); |
| 146 | continue; | 149 | continue; |
| @@ -163,6 +166,90 @@ public class RefreshController { | @@ -163,6 +166,90 @@ public class RefreshController { | ||
| 163 | return ResponseResult.success(); | 166 | return ResponseResult.success(); |
| 164 | } | 167 | } |
| 165 | 168 | ||
| 169 | + | ||
| 170 | + @PostMapping(value = "/driver/init/image/name") | ||
| 171 | + @ApiOperation("driver/init/image/name") | ||
| 172 | + @PreAuthorize("@ss.hasPermi('refresh:driver:init:image:name')") | ||
| 173 | + public ResponseResult<Object> insertDriverInitImageOfName(@RequestParam("imagePath") String imagePath, @RequestParam("device") String device) { | ||
| 174 | + if (StringUtils.isEmpty(device)) { | ||
| 175 | + return ResponseResult.error("注册设备号不能为空"); | ||
| 176 | + } | ||
| 177 | + | ||
| 178 | + if (StringUtils.isEmpty(imagePath)) { | ||
| 179 | + String path = StringUtils.join(System.getProperty("user.dir"), File.pathSeparator, "images"); | ||
| 180 | + | ||
| 181 | + log.info("[{}]", path); | ||
| 182 | + imagePath = path; | ||
| 183 | + } | ||
| 184 | + | ||
| 185 | + File file = new File(imagePath); | ||
| 186 | + if (!file.exists()) { | ||
| 187 | + return ResponseResult.error("文件路径不存在"); | ||
| 188 | + } | ||
| 189 | + if (!file.isDirectory()) { | ||
| 190 | + return ResponseResult.error("文件路径不是文件夹路径"); | ||
| 191 | + } | ||
| 192 | + | ||
| 193 | + File[] fs = file.listFiles(); | ||
| 194 | + int length = ArrayUtils.getLength(fs); | ||
| 195 | + if (0 == length) { | ||
| 196 | + return ResponseResult.error("文件路径下没有文件"); | ||
| 197 | + } | ||
| 198 | + | ||
| 199 | + Equipment equipment = equipmentService.getOneByDeviceId(device); | ||
| 200 | + if (Objects.isNull(equipment)) { | ||
| 201 | + return ResponseResult.error("设备号不正确,请确认设备信息"); | ||
| 202 | + } | ||
| 203 | + | ||
| 204 | + | ||
| 205 | + List<String> errors = new ArrayList<>(); | ||
| 206 | + for (int i = 0; i < length; i++) { | ||
| 207 | + FaceRegisterDTO dto = new FaceRegisterDTO(); | ||
| 208 | + dto.setDevice(device); | ||
| 209 | + String name = StringUtils.trim(StringUtils.substringBeforeLast(fs[i].getName(), ".")); | ||
| 210 | + | ||
| 211 | + NewDriver source = new NewDriver(); | ||
| 212 | + source.setPersonnelName(name); | ||
| 213 | + | ||
| 214 | + List<NewDriver> drivers = newDriverService.list(source); | ||
| 215 | + int size = CollectionUtils.size(drivers); | ||
| 216 | + if (size == 0) { | ||
| 217 | + errors.add(StringUtils.join(file.getName(), "没有找到用户")); | ||
| 218 | + continue; | ||
| 219 | + } else if (size > 1) { | ||
| 220 | + errors.add(StringUtils.join(file.getName(), "找到多个数据:", JSON.toJSONString(drivers))); | ||
| 221 | + continue; | ||
| 222 | + } | ||
| 223 | + | ||
| 224 | + NewDriver driver = drivers.get(0); | ||
| 225 | + if (StringUtils.isNotEmpty(driver.getImage())) { | ||
| 226 | + log.info("人脸数据已经存在:[{}]", driver); | ||
| 227 | + continue; | ||
| 228 | + } | ||
| 229 | + dto.setRegTime(DateUtil.shortDate(new Date())); | ||
| 230 | + dto.setStaffCode(driver.getJobCode()); | ||
| 231 | + try { | ||
| 232 | + byte[] bytes = FileUtils.readFileToByteArray(fs[i]); | ||
| 233 | + String imageContent = Base64.encode(bytes); | ||
| 234 | + dto.setFaceValue(imageContent); | ||
| 235 | + } catch (IOException e) { | ||
| 236 | + throw new RuntimeException(e); | ||
| 237 | + } | ||
| 238 | + ResponseResult<Object> responseResult = dssFaceController.faceRegister(dto); | ||
| 239 | + if (Objects.isNull(responseResult) || !responseResult.isSuccess()) { | ||
| 240 | + log.warn("[{}]数据没有执行成功;返回值为:[{}]", dto, responseResult); | ||
| 241 | + errors.add(StringUtils.join(file.getName(), "数据没有执行成功:", JSON.toJSONString(driver))); | ||
| 242 | + } | ||
| 243 | + } | ||
| 244 | + | ||
| 245 | + if (CollectionUtils.isNotEmpty(errors)) { | ||
| 246 | + return ResponseResult.error(JSON.toJSONString(errors)); | ||
| 247 | + } | ||
| 248 | + | ||
| 249 | + log.info("人员信息同步完毕"); | ||
| 250 | + return ResponseResult.success(); | ||
| 251 | + } | ||
| 252 | + | ||
| 166 | @GetMapping(value = "/jar/class/path") | 253 | @GetMapping(value = "/jar/class/path") |
| 167 | public ResponseResult<String> getJarClassPath() { | 254 | public ResponseResult<String> getJarClassPath() { |
| 168 | String path = StringUtils.join(System.getProperty("user.dir"), File.separator, "images"); | 255 | String path = StringUtils.join(System.getProperty("user.dir"), File.separator, "images"); |
Bsth-common/src/main/java/com/ruoyi/common/core/domain/entity/SysUser.java
| 1 | package com.ruoyi.common.core.domain.entity; | 1 | package com.ruoyi.common.core.domain.entity; |
| 2 | 2 | ||
| 3 | -import java.util.Date; | ||
| 4 | -import java.util.List; | ||
| 5 | -import javax.validation.constraints.*; | ||
| 6 | -import org.apache.commons.lang3.builder.ToStringBuilder; | ||
| 7 | -import org.apache.commons.lang3.builder.ToStringStyle; | 3 | +import com.alibaba.fastjson2.JSON; |
| 8 | import com.ruoyi.common.annotation.Excel; | 4 | import com.ruoyi.common.annotation.Excel; |
| 9 | import com.ruoyi.common.annotation.Excel.ColumnType; | 5 | import com.ruoyi.common.annotation.Excel.ColumnType; |
| 10 | import com.ruoyi.common.annotation.Excel.Type; | 6 | import com.ruoyi.common.annotation.Excel.Type; |
| @@ -12,6 +8,12 @@ import com.ruoyi.common.annotation.Excels; | @@ -12,6 +8,12 @@ import com.ruoyi.common.annotation.Excels; | ||
| 12 | import com.ruoyi.common.core.domain.BaseEntity; | 8 | import com.ruoyi.common.core.domain.BaseEntity; |
| 13 | import com.ruoyi.common.xss.Xss; | 9 | import com.ruoyi.common.xss.Xss; |
| 14 | 10 | ||
| 11 | +import javax.validation.constraints.Email; | ||
| 12 | +import javax.validation.constraints.NotBlank; | ||
| 13 | +import javax.validation.constraints.Size; | ||
| 14 | +import java.util.Date; | ||
| 15 | +import java.util.List; | ||
| 16 | + | ||
| 15 | /** | 17 | /** |
| 16 | * 用户对象 sys_user | 18 | * 用户对象 sys_user |
| 17 | * | 19 | * |
| @@ -299,26 +301,10 @@ public class SysUser extends BaseEntity | @@ -299,26 +301,10 @@ public class SysUser extends BaseEntity | ||
| 299 | 301 | ||
| 300 | @Override | 302 | @Override |
| 301 | public String toString() { | 303 | public String toString() { |
| 302 | - return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) | ||
| 303 | - .append("userId", getUserId()) | ||
| 304 | - .append("deptId", getDeptId()) | ||
| 305 | - .append("userName", getUserName()) | ||
| 306 | - .append("nickName", getNickName()) | ||
| 307 | - .append("email", getEmail()) | ||
| 308 | - .append("phonenumber", getPhonenumber()) | ||
| 309 | - .append("sex", getSex()) | ||
| 310 | - .append("avatar", getAvatar()) | ||
| 311 | - .append("password", getPassword()) | ||
| 312 | - .append("status", getStatus()) | ||
| 313 | - .append("delFlag", getDelFlag()) | ||
| 314 | - .append("loginIp", getLoginIp()) | ||
| 315 | - .append("loginDate", getLoginDate()) | ||
| 316 | - .append("createBy", getCreateBy()) | ||
| 317 | - .append("createTime", getCreateTime()) | ||
| 318 | - .append("updateBy", getUpdateBy()) | ||
| 319 | - .append("updateTime", getUpdateTime()) | ||
| 320 | - .append("remark", getRemark()) | ||
| 321 | - .append("dept", getDept()) | ||
| 322 | - .toString(); | 304 | + String pwd = this.getPassword(); |
| 305 | + this.setPassword(null); | ||
| 306 | + String str = JSON.toJSONString(this); | ||
| 307 | + this.setPassword(pwd); | ||
| 308 | + return str; | ||
| 323 | } | 309 | } |
| 324 | } | 310 | } |
Bsth-common/src/main/java/com/ruoyi/common/core/domain/model/LoginUser.java
| 1 | package com.ruoyi.common.core.domain.model; | 1 | package com.ruoyi.common.core.domain.model; |
| 2 | 2 | ||
| 3 | -import java.util.Collection; | ||
| 4 | -import java.util.Set; | ||
| 5 | -import org.springframework.security.core.GrantedAuthority; | ||
| 6 | -import org.springframework.security.core.userdetails.UserDetails; | ||
| 7 | import com.alibaba.fastjson2.annotation.JSONField; | 3 | import com.alibaba.fastjson2.annotation.JSONField; |
| 8 | import com.ruoyi.common.core.domain.entity.SysUser; | 4 | import com.ruoyi.common.core.domain.entity.SysUser; |
| 5 | +import org.springframework.security.core.GrantedAuthority; | ||
| 6 | +import org.springframework.security.core.userdetails.UserDetails; | ||
| 7 | + | ||
| 8 | +import java.util.Collection; | ||
| 9 | +import java.util.Set; | ||
| 9 | 10 | ||
| 10 | /** | 11 | /** |
| 11 | * 登录用户身份权限 | 12 | * 登录用户身份权限 |
| @@ -263,4 +264,21 @@ public class LoginUser implements UserDetails | @@ -263,4 +264,21 @@ public class LoginUser implements UserDetails | ||
| 263 | { | 264 | { |
| 264 | return null; | 265 | return null; |
| 265 | } | 266 | } |
| 267 | + | ||
| 268 | + @Override | ||
| 269 | + public String toString() { | ||
| 270 | + return "LoginUser{" + | ||
| 271 | + "userId=" + userId + | ||
| 272 | + ", deptId=" + deptId + | ||
| 273 | + ", token='" + token + '\'' + | ||
| 274 | + ", loginTime=" + loginTime + | ||
| 275 | + ", expireTime=" + expireTime + | ||
| 276 | + ", ipaddr='" + ipaddr + '\'' + | ||
| 277 | + ", loginLocation='" + loginLocation + '\'' + | ||
| 278 | + ", browser='" + browser + '\'' + | ||
| 279 | + ", os='" + os + '\'' + | ||
| 280 | + ", permissions=" + permissions + | ||
| 281 | + ", user=" + user + | ||
| 282 | + '}'; | ||
| 283 | + } | ||
| 266 | } | 284 | } |
Bsth-framework/src/main/java/com/ruoyi/framework/security/filter/JwtAuthenticationTokenFilter.java
| @@ -5,6 +5,8 @@ import com.ruoyi.common.core.domain.model.LoginUser; | @@ -5,6 +5,8 @@ import com.ruoyi.common.core.domain.model.LoginUser; | ||
| 5 | import com.ruoyi.common.utils.SecurityUtils; | 5 | import com.ruoyi.common.utils.SecurityUtils; |
| 6 | import com.ruoyi.common.utils.StringUtils; | 6 | import com.ruoyi.common.utils.StringUtils; |
| 7 | import com.ruoyi.framework.web.service.TokenService; | 7 | import com.ruoyi.framework.web.service.TokenService; |
| 8 | +import org.slf4j.Logger; | ||
| 9 | +import org.slf4j.LoggerFactory; | ||
| 8 | import org.slf4j.MDC; | 10 | import org.slf4j.MDC; |
| 9 | import org.springframework.beans.factory.annotation.Autowired; | 11 | import org.springframework.beans.factory.annotation.Autowired; |
| 10 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; | 12 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; |
| @@ -36,6 +38,8 @@ public class JwtAuthenticationTokenFilter extends OncePerRequestFilter { | @@ -36,6 +38,8 @@ public class JwtAuthenticationTokenFilter extends OncePerRequestFilter { | ||
| 36 | private final static String USER_ID_KEY = "userId"; | 38 | private final static String USER_ID_KEY = "userId"; |
| 37 | private final static String REQUEST_ID_KEY = "requestId"; | 39 | private final static String REQUEST_ID_KEY = "requestId"; |
| 38 | 40 | ||
| 41 | + private final static Logger LOGGER = LoggerFactory.getLogger(JwtAuthenticationTokenFilter.class); | ||
| 42 | + | ||
| 39 | @Override | 43 | @Override |
| 40 | protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) | 44 | protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) |
| 41 | throws ServletException, IOException { | 45 | throws ServletException, IOException { |
| @@ -62,6 +66,14 @@ public class JwtAuthenticationTokenFilter extends OncePerRequestFilter { | @@ -62,6 +66,14 @@ public class JwtAuthenticationTokenFilter extends OncePerRequestFilter { | ||
| 62 | return null; | 66 | return null; |
| 63 | } | 67 | } |
| 64 | 68 | ||
| 69 | + String authorization = null; | ||
| 70 | + HttpServletRequest request = getRequest(); | ||
| 71 | + if(Objects.nonNull(request)){ | ||
| 72 | + authorization = request.getHeader("Authorization"); | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + LOGGER.warn("device:[{}],authorization:[{}],loginUser:[{}]",device,authorization,loginUser); | ||
| 76 | + | ||
| 65 | return "登陆的设备和token不匹配"; | 77 | return "登陆的设备和token不匹配"; |
| 66 | } | 78 | } |
| 67 | 79 |