Browse Source

Merge branch 'develop3.0' into feat/studentManage

osbert 4 years ago
parent
commit
e33d5c88df

+ 3 - 0
TEAMModelOS/ClientApp/src/api/schoolUser.js

@@ -28,4 +28,7 @@ export default {
     rmvSchoolUser: function (data) {
         return post('/school/teacher/rmv-teacher', data)
     },
+    getUserFromCoreId: function (data) {
+        return post('/school/teacher/get-coreuser', data)
+    },
 }

+ 1 - 1
TEAMModelOS/ClientApp/src/common/BaseLayout.vue

@@ -113,7 +113,7 @@
                                 icon: 'iconfont icon-teacher-mgt',
                                 name: '老师账号',
                                 router: '/home/teachermgmt',
-                                tag: '*',
+                                tag: '',
                                 role: 'admin',
                                 permission: ''
                             },

+ 2 - 1
TEAMModelOS/ClientApp/src/locale/lang/en-US/teachermgmt.js

@@ -55,7 +55,8 @@ export default {
         info15: '您的 Excel 没资料',
         info16: '批准教师申请',
         info17: '请问您确定要批准',
-        info18: '的教师申请'
+        info18: '的教师申请',
+        info19: '找不到此教師的資料'
     },
     job: {
         'jobTitle': '添加職稱',

+ 2 - 1
TEAMModelOS/ClientApp/src/locale/lang/zh-CN/teachermgmt.js

@@ -54,7 +54,8 @@ export default {
         info15: '您的 Excel 没资料',
         info16: '批准教师申请',
         info17: '请问您确定要批准',
-        info18: '的教师申请'
+        info18: '的教师申请',
+        info19: '找不到此教师的资料'
     },
     job: {
         'jobTitle': '添加职称',

+ 2 - 1
TEAMModelOS/ClientApp/src/locale/lang/zh-TW/teachermgmt.js

@@ -54,7 +54,8 @@ export default {
         info15: '您的 Excel 沒資料',
         info16: '批准教師申請',
         info17: '請問您確定要批准',
-        info18: '的教師申請'
+        info18: '的教師申請',
+        info19: '找不到此教師的資料'
     },
     job: {
         'jobTitle': '添加職稱',

+ 25 - 0
TEAMModelOS/ClientApp/src/store/module/user.js

@@ -527,6 +527,31 @@ export default {
                     resolve([])
                 }
             })
+        },
+        // 向ID系統取得使用者資料 輸入項:(array[])
+        getUserFromCoreId(context, params) {
+            return new Promise(
+                (resolve, reject) => {
+                    apiTools.schoolUser.getUserFromCoreId(
+                        params
+                    ).then(
+                        res => {
+                            resolve({
+                                code: 1,
+                                data: res,
+                                message: ''
+                            })
+                        },
+                        err => {
+                            reject({
+                                code: 0,
+                                data: [],
+                                message: 'Add user to school API error!'
+                            })
+                        }
+                    )
+                }
+            )
         }
     }
 }

+ 69 - 52
TEAMModelOS/ClientApp/src/view/teachermgmt/components/personnel/Index.vue

@@ -164,7 +164,7 @@
                         <div class="searchFormBox">
                             <div class="caption" v-html="$t('teachermgmt.addTeacher.content')"></div>
                             <Input class="searchIpt" prefix="ios-search" v-model="serchText" />
-                            <p class="errorMsg"></p>
+                            <p class="errorMsg">{{searchIdErrorMsg}}</p>
                             <Button :loading="serchTHLoading" class="searchBtn" @click="searchTeacher()">{{ $t('teachermgmt.addTeacher.btn.search') }}</Button>
                         </div>
                     </div>
@@ -272,6 +272,7 @@ export default {
                 email: '',
                 name: ''
             },
+            searchIdErrorMsg: '',
         }
     },
     created(){
@@ -397,68 +398,84 @@ export default {
                 }
             });
 
-
             // 向CoreID取得使用者
-            console.log('向CoreID搜尋用資料:');
-            console.log(this.userListImportClear);
-            this.userListFromCoreID = this.$Mock.data.userListFromCoreID
-            console.log('CoreID返回資料:');
-            console.log(this.userListFromCoreID);
-
-            // 第一階段資料比對:匯入的使用者 比對 CoreID使用者
-            this.userListImportClear.forEach((userI) => {
-                let userMatchFlg = false;
-                this.userListFromCoreID.forEach((userC) => {
-                    if (userI == userC.id || userI == userC.mail || userI == userC.mobile) {
-                        userMatchFlg = true;
-                        if(userListImportPreMatchSuccessIDList.indexOf(userC.id.toString()) === -1) { //資料未重複
-                            userListImportPreMatchSuccessIDList.push(userC.id);
-                            if(userI == userC.id) { //畫面顯示用欄位
-                                userC.excelVal = userC.id;
-                            } else if(userI == userC.mail) {
-                                userC.excelVal = userC.mail;
-                            } else if(userI == userC.mobile) {
-                                userC.excelVal = userC.mobile;
+            this.$store.dispatch('user/getUserFromCoreId', this.userListImportClear).then(
+                (res) => {
+                    if (res.code == 1) {
+                        this.userListFromCoreID = res.data;
+                        // 第一階段資料比對:匯入的使用者 比對 CoreID使用者
+                        this.userListImportClear.forEach((userI) => {
+                            let userMatchFlg = false;
+                            this.userListFromCoreID.forEach((userC) => {
+                                if (userI == userC.searchKey) {
+                                    userMatchFlg = true;
+                                    if (userListImportPreMatchSuccessIDList.indexOf(userC.id.toString()) === -1) { //資料未重複
+                                        userListImportPreMatchSuccessIDList.push(userC.id);
+                                        userC.excelVal = userC.searchKey; //畫面顯示用欄位
+                                        userListImportPreMatchSuccess.push(userC);
+                                    } else { //重複資料(不同行的excel資料取到同一位使用者)
+                                        this.userListImportDuplicate.push(userI);
+                                    }
+                                }
+                            })
+                            if (!userMatchFlg) {
+                                this.userListImportInvalid.push(userI)
                             }
-                            userListImportPreMatchSuccess.push(userC);
-                        } else { //重複資料(不同行的excel資料取到同一位使用者)
-                            this.userListImportDuplicate.push(userI);
+                        });
+                        // 第一階段資料比對通過,與學校使用者比對
+                        let selectUserList = this.$store.getters['user/getSchoolUserAll'];
+                        if (userListImportPreMatchSuccess.length > 0) {
+                            userListImportPreMatchSuccess.forEach((userM) => {
+                                let userAlreadyInSchoolFlg = false;
+                                selectUserList.forEach((userSc) => {
+                                    if (userM.id == userSc.id) {
+                                        this.userListImportClear.forEach((userI) => {
+                                            if (userI == userM.searchKey) {
+                                                this.userListImportInvalid.push(userM.searchKey);
+                                            }
+                                        });
+                                        userAlreadyInSchoolFlg = true;
+                                    }
+                                })
+                                if (!userAlreadyInSchoolFlg) {
+                                    this.userListImportSuccess.push(userM);
+                                }
+                            })
                         }
+                        //結果顯示
+                        this.serchModel = 'excel';
+                    } else {
+                        this.$Message.error('user/getUserFromCoreId API error!')
                     }
-                })
-                if (!userMatchFlg) {
-                    this.userListImportInvalid.push(userI)
+                },
+                (err) => {
+                    this.$Message.error('user/getUserFromCoreId API error!')
                 }
-            });
-            // 第一階段資料比對通過,與學校使用者比對
-            let selectUserList = this.$store.getters['user/getSchoolUserAll'];
-            if (userListImportPreMatchSuccess.length > 0) {
-                userListImportPreMatchSuccess.forEach((userM) => {
-                    let userAlreadyInSchoolFlg = false;
-                    selectUserList.forEach((userSc) => {
-                        if (userM.id == userSc.id) {
-                            this.userListImportInvalid.push(userM.id);
-                            userAlreadyInSchoolFlg = true;
-                        }
-                    })
-                    if (!userAlreadyInSchoolFlg) {
-                        this.userListImportSuccess.push(userM);
-                    }
-                })
-            }
-            //結果顯示
-            this.serchModel = 'excel';
+            )
         },
         removeImpUser: function(user){
              this.userListImportSuccess.splice(this.userListImportSuccess.indexOf(user),1)
         },
         searchTeacher() {
+            this.searchIdErrorMsg = '';
             if (this.serchText) {
-                this.searchInfo = this.$Mock.data.userFromCoreID;
-                this.searchInfo.status = 'invite'; //學校邀請
-                this.userListImportSuccess = [];
-                this.userListImportSuccess.push(this.searchInfo);
-                this.serchModel = 'user'
+                // 向CoreID取得使用者
+                this.$store.dispatch('user/getUserFromCoreId', [this.serchText]).then(
+                    (res) => {
+                        if (res.code == 1 && res.data.length > 0) {
+                            this.userListImportSuccess = res.data;
+                            this.searchInfo = res.data[0];
+                            this.searchInfo.status = 'invite'; //學校邀請
+                            this.serchModel = 'user';
+                        }
+                        else {
+                            this.searchIdErrorMsg = this.$t('teachermgmt.message.info19');
+                        }
+                    },
+                    (err) => {
+                        this.$Message.error('user/getUserFromCoreId API error!')
+                    }
+                );
             } else {
                 this.$Message.warning({
                     content: this.$t('teachermgmt.message.info11'),

+ 36 - 0
TEAMModelOS/Controllers/School/SchoolTeacherController.cs

@@ -18,6 +18,10 @@ using System.IO;
 using TEAMModelOS.Models.TeacherInfo;
 using System.Linq;
 using Microsoft.Extensions.Options;
+using System.Net.Http;
+using Newtonsoft.Json;
+using TEAMModelOS.SDK.Context.Configuration;
+using System.Net;
 
 namespace TEAMModelOS.Controllers
 {
@@ -402,5 +406,37 @@ namespace TEAMModelOS.Controllers
                 return BadRequest();
             }
         }
+
+        /// <summary>
+        /// 取得CoreID資訊
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        [ProducesDefaultResponseType]
+        //[AuthToken(Roles = "admin")]
+        [HttpPost("get-coreuser")]
+        public async Task<IActionResult> GetUserFromCoreID(JsonElement request)
+        {
+            try
+            {
+                string url = BaseConfigModel.Configuration["HaBookAuth:CoreId:userinfo"];
+                HttpClient client = new HttpClient();
+                var content = new StringContent(request.ToString(), Encoding.UTF8, "application/json");
+                HttpResponseMessage responseMessage = await client.PostAsync(url, content);
+                if(responseMessage.StatusCode == HttpStatusCode.OK)
+                {
+                    string responseBody = responseMessage.Content.ReadAsStringAsync().Result;
+                    return Ok(responseBody);
+                }
+                else
+                {
+                    return BadRequest();
+                }
+            }
+            catch (Exception ex)
+            {
+                return BadRequest();
+            }
+        }
     }
 }

+ 1 - 0
TEAMModelOS/TEAMModelOS.csproj

@@ -15,6 +15,7 @@
   <PropertyGroup>
     <SpaRoot>ClientApp\</SpaRoot>
     <DefaultItemExcludes>$(DefaultItemExcludes);$(SpaRoot)node_modules\**</DefaultItemExcludes>
+    <UserSecretsId>df088159-30c9-42c2-8385-46a7e7a93995</UserSecretsId>
   </PropertyGroup>
   <ItemGroup>
     <!-- Don't publish the SPA source files, but do show them in the project files list -->

+ 3 - 0
TEAMModelOS/appsettings.Development.json

@@ -65,6 +65,9 @@
         "refresh_token": "{access_token}"
       },
       "url": "https://api2.teammodel.cn/oauth2/token"
+    },
+    "CoreId": {
+      "userinfo": "https://api2.teammodel.cn/Oauth2/GetUserInfos"
     }
   },
   "SmsSendCloud": {

+ 4 - 1
TEAMModelOS/appsettings.json

@@ -64,8 +64,11 @@
         "refresh_token": "{access_token}"
       },
       "url": "https://api2.teammodel.cn/oauth2/token"
+    },
+    "CoreId": {
+      "userinfo": "https://api2.teammodel.cn/Oauth2/GetUserInfos"
     }
-  },
+    },
   "SmsSendCloud": {
     "SmsUrl": "http://www.sendcloud.net/smsapi/send",
     "SmsUser": "Chengdu",