瀏覽代碼

优化登录逻辑。

lighter 4 年之前
父節點
當前提交
7f4acc9e77

+ 10 - 1
src/main/java/thyyxxk/webserver/dao_his/LoginDao.java

@@ -1,5 +1,6 @@
 package thyyxxk.webserver.dao_his;
 
+import org.apache.ibatis.annotations.Insert;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
@@ -14,7 +15,15 @@ public interface LoginDao {
             "deptCode=(select dept_code from a_employee_mi where code=a.code) " +
             "from dj_user_base a " +
             "where code_rs=#{codeRs} and del_flag=0")
-    UserPojo findUserByCodeRs(@Param("codeRs") String codeRs);
+    UserPojo findUserByCodeRsFromDjUserBase(@Param("codeRs") String codeRs);
+
+    @Select("select code, name, code_rs, password='123456' " +
+            "from a_employee_mi where code_rs=#{codeRs} and del_flag=0")
+    UserPojo findUserByCodeRsFromAEmployeeMi(@Param("codeRs") String codeRs);
+
+    @Insert("insert into dj_user_base (code, code_rs, name, password, del_flag) " +
+            "values (#{code}, #{codeRs}, #{name}, '123456', 0)")
+    void insertNewUserToDjUserBase(UserPojo user);
 
     @Select("select code, name, password, code_rs, " +
             "deptCode=(select dept_code from a_employee_mi where code=#{code}) " +

+ 13 - 11
src/main/java/thyyxxk/webserver/service/LoginService.java

@@ -27,20 +27,22 @@ public class LoginService {
     }
 
     public ResultVo<UserPojo> login(UserPojo userPojo) {
-        UserPojo tempUserPojo = dao.findUserByCodeRs(userPojo.getCodeRs());
+        UserPojo tempUserPojo = dao.findUserByCodeRsFromDjUserBase(userPojo.getCodeRs());
         if (null == tempUserPojo) {
-            return ResultVoUtil.fail(ExceptionEnum.USER_NOT_EXIST);
-        } else {
-            if (!userPojo.getPassword().equals(tempUserPojo.getPassword())) {
-                return ResultVoUtil.fail(ExceptionEnum.INVALID_PASSWORD);
-            } else {
-                String token = tokenService.getToken(tempUserPojo);
-                tempUserPojo.setToken(token);
-                tempUserPojo.setSid(makeSid(tempUserPojo.getCode(), token));
-                tempUserPojo.setRoles(dao.getUserRoles(tempUserPojo.getCode()));
-                return ResultVoUtil.success(tempUserPojo);
+            tempUserPojo = dao.findUserByCodeRsFromAEmployeeMi(userPojo.getCodeRs());
+            if (null == tempUserPojo) {
+                return ResultVoUtil.fail(ExceptionEnum.USER_NOT_EXIST);
             }
+            dao.insertNewUserToDjUserBase(tempUserPojo);
+        }
+        if (!userPojo.getPassword().equals(tempUserPojo.getPassword())) {
+            return ResultVoUtil.fail(ExceptionEnum.INVALID_PASSWORD);
         }
+        String token = tokenService.getToken(tempUserPojo);
+        tempUserPojo.setToken(token);
+        tempUserPojo.setSid(makeSid(tempUserPojo.getCode(), token));
+        tempUserPojo.setRoles(dao.getUserRoles(tempUserPojo.getCode()));
+        return ResultVoUtil.success(tempUserPojo);
     }
 
     public ResultVo<List<String>> getMenus() {