Selaa lähdekoodia

調整學生匯入檢核

osbert 4 vuotta sitten
vanhempi
commit
24ee7ac4de
1 muutettua tiedostoa jossa 177 lisäystä ja 68 poistoa
  1. 177 68
      TEAMModelOS/ClientApp/src/view/student-account/ImportStudent.vue

+ 177 - 68
TEAMModelOS/ClientApp/src/view/student-account/ImportStudent.vue

@@ -25,6 +25,10 @@
                     <span class="table-info-label">{{$t('stuAccount.importInfo1')}}</span>
                     <span class="table-info-num">{{totalNum}}</span>
                 </div>
+                <div class="table-info-item" v-if="excelFiledNum != 0">
+                    <span class="table-info-label">{{$t('Excel欄位有缺:')}}</span>
+                    <span class="table-info-num">{{ excelFiledNum }}</span>
+                </div>
                 <div class="table-info-item" v-if="repeatNum != 0">
                     <span class="table-info-label">{{$t('stuAccount.importInfo2')}}</span>
                     <span class="table-info-num">{{repeatNum}}</span>
@@ -59,10 +63,16 @@
                     <p>{{(row.pw == '' || row.pw == null)? '— —' : row.pw+''}}</p>
                 </template>
                 <template slot-scope="{ row,index }" slot="status">
+                    <!-- Excel 錯誤 -->
+                    <p :class="(excelValid.fieldIds.length == 0 || excelValid.fieldIds.indexOf(row.id) == -1) ? 'account-success-tips':'account-warning-tips'">{{(excelValid.fieldIds.length == 0 || excelValid.fieldIds.indexOf(row.id) == -1)?"":"警告:Excel 內欄未完整!" }}</p>
+                    <p :class="(excelValid.noReaptIds.length == 0 || excelValid.noReaptIds.indexOf(row.id) == -1) ? 'account-success-tips':'account-warning-tips'">{{(excelValid.noReaptIds.length == 0 || excelValid.noReaptIds.indexOf(row.id) == -1)?"":"警告:Excel 內的座位号重覆!" }}</p>
+                    <p :class="(excelValid.reaptIds.length == 0 || excelValid.reaptIds.indexOf(row.id) == -1) ? 'account-success-tips':'account-warning-tips'">{{(excelValid.reaptIds.length == 0 || excelValid.reaptIds.indexOf(row.id) == -1)?"":"警告:Excel 內账号重复!" }}</p>
+                    <p :class="row.seatRepeat? 'account-error-tips':''">{{row.seatRepeat ? "错误:座位号已在校內重复":"" }}</p>
+                    <!-- 
                     <p :class="(repeatAccounts.length == 0 || repeatAccounts.indexOf(row.id) == -1) ? 'account-success-tips':'account-error-tips'">{{(repeatAccounts.length == 0 || repeatAccounts.indexOf(row.id) == -1)?"":"错误:账号重复或已存在学校里!" }}</p>
                     <p :class="(row.classId == '' || row.classId == null) ? 'account-warning-tips':''">{{(row.classId == '' || row.classId == null)?"警告 :未找到指定班级":"" }}</p>
-                    <p :class="row.seatRepeat? 'account-error-tips':''">{{row.seatRepeat ? "错误:座位号重复或已存在於校內":"" }}</p>
-                    <p :class="(row.no == '' || row.no == null) ? 'account-warning-tips':''">{{(row.no == '' || row.no == null)?"警告 :沒有座號":"" }}</p>
+                    
+                    <p :class="(row.no == '' || row.no == null) ? 'account-warning-tips':''">{{(row.no == '' || row.no == null)?"警告 :沒有座號":"" }}</p> -->
 
                 </template>
             </Table>
@@ -92,9 +102,17 @@
         },
         data() {
             return {
+                // Excel 檢核
+                excelValid:{
+                    fieldIds: [],
+                    noReaptIds: [],
+                    reaptIds: []
+                },
                 totalNum: 0,
                 seatRepeatNum: 0,
                 repeatNum: 0,
+                excelFiledNum: 0,
+
                 existNum: 0,
                 repeatAccounts: [],
                 noClassroomNum: 0,
@@ -125,7 +143,8 @@
                 students: 'schoolBaseInfo/getStudent', // 學生List
             }),
             isError() {
-                return this.seatRepeatNum + this.repeatNum + this.existNum + this.noClassroomNum + this.noSeatNoNum
+                // return this.seatRepeatNum + this.repeatNum + this.existNum + this.noClassroomNum + this.noSeatNoNum
+                return this.repeatNum + this.seatRepeatNum + this.excelFiledNum
             },
             show: {
                 get() {
@@ -146,11 +165,16 @@
             },
             rowClassName(row, index) {
                 let className = ''
-                if (!(this.repeatAccounts.length == 0 || this.repeatAccounts.indexOf(row.id) == -1) || row.seatRepeat) {
-                    className = className + 'account-error-row-bg '
-                }
-                if (row.classId == '' || row.classId == null || row.no == '' || row.no == null) {
+
+                if( this.excelValid.fieldIds.indexOf(row.id) >= 0 || this.excelValid.noReaptIds.indexOf(row.id) >= 0 || this.excelValid.reaptIds.indexOf(row.id) >= 0){
                     className = className + 'account-warning-row-bg'
+                } else {
+                    if (!(this.repeatAccounts.length == 0 || this.repeatAccounts.indexOf(row.id) == -1) || row.seatRepeat) {
+                        className = className + 'account-error-row-bg '
+                    }
+                    if (row.classId == '' || row.classId == null || row.no == '' || row.no == null) {
+                        className = className + 'account-warning-row-bg'
+                    }
                 }
                 return className
             },
@@ -241,77 +265,112 @@
                             return item
                         })
 
-                        // 現在的學生List
-                        let studIDs = this.students.map(item => { return item.id })
-
-                        // 计算重复账号数量和重复账号,过滤重复账号
+                        // 給予Excel 總數
                         this.totalNum = this.tableData.length
-                        // 取得Excel 全部的ID
-                        let accounts = this.tableData.map(item => { return item.id })
-                        // 合併
-                        let cocatIds = studIDs.concat(accounts);
-                        this.repeatAccounts = cocatIds.filter((item, index, self) => self.indexOf(item) != index)
-                        this.repeatAccounts = this.repeatAccounts.filter((item, index, self) => self.indexOf(item) === index)
 
-                        // 直接过滤重复账号
-                        // this.tableData = this.tableData.filter((item, index, self) => {
-                        //  if (accounts.indexOf(item.account) === index) {
-                        //    return 1;
-                        //  } else {
-                        //    return 0;
-                        //  }
-                        // });
-                        accounts = accounts.filter((item, index, self) => self.indexOf(item) === index)
-                        this.repeatNum = this.totalNum - accounts.length + this.repeatAccounts.length
+                        // 檢核現在的Excel 邏輯
+                        let excelFlag = this.validExcel(this.tableData)
 
-                        // 根据班级Code GroupBy,判断班级座位号是否重复
-                        let classStu = this.groupBy(this.tableData, 'classId')
+                        // Excel 檢核通過再網下檢核
+                        if(excelFlag){
+                            // 先歸零
+                            this.errNumReset()
 
-                        for (let item of classStu) {
-                            let seatNoArr = item.map(item => { return item.no })
-                            for (let index in item) {
-                                let flag = seatNoArr.indexOf(item[index]['no'])
-                                if (flag != index) {
-                                    let tableIndex = this.getIndex(this.tableData, item[flag])
-                                    if (this.tableData[tableIndex].seatRepeat != true) {
-                                        this.seatRepeatNum++
-                                        this.tableData[tableIndex].seatRepeat = true
-                                    }
-                                    tableIndex = this.getIndex(this.tableData, item[index])
-                                    this.tableData[tableIndex].seatRepeat = true
+                            // 修改與新增的學生檢核
+                            this.tableData.forEach( (item, index, array) => {
+                                
+                                // 檢查座號是否與校內的衝突
+                                let studdd = this.students.some( (studInfo, index) => {
+                                    return (item.classId == studInfo.classId && item.no == studInfo.no)
+                                })
+                                if(studdd) {
+                                    item.seatRepeat = true
                                     this.seatRepeatNum++
                                 }
-                            }
+
+                            })
+                            
+                            //整理TtableData
+                            this.tableData.map((item, index) => {
+                                if(item.pw == undefined || item.pw == null || item.pw == '') item.pw = item.id
+                                item['classroom'] = {}
+                                item.classroom.classId = item.classId
+                                item.classroom.className = item.className
+                                item.year = this.academicYear ? this.academicYear.toString() : ''
+                                item.no = item.no ? item.no.toString() : ''
+                                return item
+                            })
                         }
-                        // 筛选没有班级账号
-                        let noRoom = this.tableData.filter(item => { return (item.classId == '' || item.classId == null) })
-                        this.noClassroomNum = noRoom.length
 
-                        // 筛选沒有座號
-                        let noSeatNo = this.tableData.filter(item => { return (item.no == '' || item.no == null) })
-                        this.noSeatNoNum = noSeatNo.length
 
-                        //整理TtableData
-                        this.tableData.map((item, index) => {
-                            if(item.pw == undefined || item.pw == null || item.pw == '') item.pw = item.id
-                            item['classroom'] = {}
-                            item.classroom.classId = item.classId
-                            item.classroom.className = item.className
-                            item.year = this.academicYear ? this.academicYear.toString() : ''
-                            item.no = item.no ? item.no.toString() : ''
-                            return item
-                        })
+                        // // 计算重复账号数量和重复账号,过滤重复账号
+                        // this.totalNum = this.tableData.length
+                        // // 取得Excel 全部的ID
+                        // let accounts = this.tableData.map(item => { return item.id })
+                        // // 合併
+                        // let cocatIds = studIDs.concat(accounts);
+                        // this.repeatAccounts = cocatIds.filter((item, index, self) => self.indexOf(item) != index)
+                        // this.repeatAccounts = this.repeatAccounts.filter((item, index, self) => self.indexOf(item) === index)
 
-                        // 檢查與現在的學生名單同教室裡是否有重複座號
-                        this.tableData.forEach( (item) => {
-                            let studdd = this.students.filter( (studInfo) => {
-                                return (item.classId == studInfo.classId && item.no == studInfo.no)
-                            })
-                            if(studdd.length > 0) {
-                                item.seatRepeat = true
-                                this.seatRepeatNum++
-                            }
-                        })
+                        // // 直接过滤重复账号
+                        // // this.tableData = this.tableData.filter((item, index, self) => {
+                        // //  if (accounts.indexOf(item.account) === index) {
+                        // //    return 1;
+                        // //  } else {
+                        // //    return 0;
+                        // //  }
+                        // // });
+                        // accounts = accounts.filter((item, index, self) => self.indexOf(item) === index)
+                        // this.repeatNum = this.totalNum - accounts.length + this.repeatAccounts.length
+
+                        // // 根据班级Code GroupBy,判断班级座位号是否重复
+                        // let classStu = this.groupBy(this.tableData, 'classId')
+
+                        // for (let item of classStu) {
+                        //     let seatNoArr = item.map(item => { return item.no })
+                        //     for (let index in item) {
+                        //         let flag = seatNoArr.indexOf(item[index]['no'])
+                        //         if (flag != index) {
+                        //             let tableIndex = this.getIndex(this.tableData, item[flag])
+                        //             if (this.tableData[tableIndex].seatRepeat != true) {
+                        //                 this.seatRepeatNum++
+                        //                 this.tableData[tableIndex].seatRepeat = true
+                        //             }
+                        //             tableIndex = this.getIndex(this.tableData, item[index])
+                        //             this.tableData[tableIndex].seatRepeat = true
+                        //             this.seatRepeatNum++
+                        //         }
+                        //     }
+                        // }
+                        // // 筛选没有班级账号
+                        // let noRoom = this.tableData.filter(item => { return (item.classId == '' || item.classId == null) })
+                        // this.noClassroomNum = noRoom.length
+
+                        // // 筛选沒有座號
+                        // let noSeatNo = this.tableData.filter(item => { return (item.no == '' || item.no == null) })
+                        // this.noSeatNoNum = noSeatNo.length
+
+                        // //整理TtableData
+                        // this.tableData.map((item, index) => {
+                        //     if(item.pw == undefined || item.pw == null || item.pw == '') item.pw = item.id
+                        //     item['classroom'] = {}
+                        //     item.classroom.classId = item.classId
+                        //     item.classroom.className = item.className
+                        //     item.year = this.academicYear ? this.academicYear.toString() : ''
+                        //     item.no = item.no ? item.no.toString() : ''
+                        //     return item
+                        // })
+
+                        // // 檢查與現在的學生名單同教室裡是否有重複座號
+                        // this.tableData.forEach( (item) => {
+                        //     let studdd = this.students.filter( (studInfo) => {
+                        //         return (item.classId == studInfo.classId && item.no == studInfo.no)
+                        //     })
+                        //     if(studdd.length > 0) {
+                        //         item.seatRepeat = true
+                        //         this.seatRepeatNum++
+                        //     }
+                        // })
                         
                         this.$Message.info(this.$t('stuAccount.importTips11'))
                         this.tableLoading = false
@@ -445,6 +504,56 @@
                         slot: 'status'
                     }
                 ]
+            },
+            validExcel(data){
+                let _this = this
+                var excelData = data
+                let validFalg = false
+
+                // 先歸零
+                this.errNumReset()
+
+                excelData.forEach( (item, index, array) => {
+                    // 座號、ID、教室ID、教室名稱必填
+                    if(item.no == '' || item.no == null || item.id == '' || item.id == null || item.classId == '' || item.classId == null || item.className == '' || item.className == null) {
+                        _this.excelValid.fieldIds.push(item.id)
+                        _this.excelFiledNum++
+                    }
+
+                    // 座號重複檢核
+                    let repNo = array.filter( (i) => {
+                        return i.id != item.id && i.classId != undefined && i.classId != null && i.classId != '' && i.classId == item.classId && i.no == item.no 
+                    })
+                    if(repNo.length > 0){
+                        for( let no of repNo) {
+                            _this.excelValid.noReaptIds.push(no.id)
+                            _this.seatRepeatNum ++
+                            validFalg = true
+                        }
+                    }
+
+                    // ID 重複
+                    let repID = array.filter( (i, key) => {
+                        return i.id == item.id && index != key
+                    })
+                    if(repID.length > 0){
+                        for( let id of repID) {
+                            _this.excelValid.reaptIds.push(id.id)
+                            _this.repeatNum ++
+                            validFalg = true
+                        }
+                    }
+                })
+
+                if( (_this.excelValid.noReaptIds.length + _this.excelValid.fieldIds.length + _this.excelValid.reaptIds.length) == 0){
+                    validFalg = true
+                }
+                return validFalg
+            },
+            errNumReset(){
+                this.repeatNum = 0 // 帳號重複
+                this.seatRepeatNum = 0 // 座號重複
+                this.excelFiledNum = 0 // Excel 欄位空白檢核
             }
         },
         created() {