Explorar o código

优化属性名获取方式

zhouhao %!s(int64=8) %!d(string=hai) anos
pai
achega
e15c06889c

+ 9 - 9
hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-simple/src/main/java/org/hswebframework/web/service/authorization/simple/SimpleUserService.java

@@ -47,6 +47,9 @@ public class SimpleUserService extends AbstractService<UserEntity, String>
     @Autowired(required = false)
     private PasswordEncoder passwordEncoder = (password, salt) -> DigestUtils.md5Hex(String.format("hsweb.%s.framework.%s", password, salt));
 
+    @Autowired(required = false)
+    private DataAccessFactory dataAccessFactory;
+
     @Autowired
     private UserDao userDao;
 
@@ -62,9 +65,6 @@ public class SimpleUserService extends AbstractService<UserEntity, String>
     @Autowired
     private RoleDao roleDao;
 
-    @Autowired(required = false)
-    private DataAccessFactory dataAccessFactory;
-
     @Override
     @Cacheable(value = USER_AUTH_CACHE_NAME, key = "#userId")
     public Authentication getByUserId(String userId) {
@@ -153,7 +153,7 @@ public class SimpleUserService extends AbstractService<UserEntity, String>
         userEntity.setId(userId);
         //判断用户是否存在
         boolean userExists = createQuery().where()
-                .is("username", userEntity.getUsername())
+                .is(UserEntity.username, userEntity.getUsername())
                 .and().not(GenericEntity.id, userId)
                 .total() > 0;
         tryValidateProperty(!userExists, GenericEntity.id, "{username_exists}");
@@ -161,10 +161,10 @@ public class SimpleUserService extends AbstractService<UserEntity, String>
         //修改密码
         if (!StringUtils.hasLength(userEntity.getPassword())) {
             //密码强度验证
-            tryValidateProperty(usernameValidator, "password", userEntity.getPassword());
+            tryValidateProperty(usernameValidator, UserEntity.password, userEntity.getPassword());
             //密码MD5
             userEntity.setPassword(encodePassword(userEntity.getPassword(), userEntity.getSalt()));
-            updateProperties.add("password");
+            updateProperties.add(UserEntity.password);
         }
         //修改数据
         DefaultDSLUpdateService.createUpdate(getDao(), userEntity)
@@ -183,7 +183,7 @@ public class SimpleUserService extends AbstractService<UserEntity, String>
     @Override
     public boolean enable(String userId) {
         return DefaultDSLUpdateService.createUpdate(getDao())
-                .set("enabled", true)
+                .set(UserEntity.enabled, true)
                 .where(GenericEntity.id, userId)
                 .exec() > 0;
     }
@@ -191,7 +191,7 @@ public class SimpleUserService extends AbstractService<UserEntity, String>
     @Override
     public boolean disable(String userId) {
         return DefaultDSLUpdateService.createUpdate(getDao())
-                .set("enabled", false)
+                .set(UserEntity.enabled, false)
                 .where(GenericEntity.id, userId)
                 .exec() > 0;
     }
@@ -206,7 +206,7 @@ public class SimpleUserService extends AbstractService<UserEntity, String>
         }
         newPassword = encodePassword(newPassword, userEntity.getSalt());
         DefaultDSLUpdateService.createUpdate(getDao())
-                .set("password", newPassword)
+                .set(UserEntity.password, newPassword)
                 .where(GenericEntity.id, userId)
                 .exec();
     }