Prechádzať zdrojové kódy

ADD 区级IOT导出

onepsycho@163.com 11 mesiacov pred
rodič
commit
c2eace2eaa
1 zmenil súbory, kde vykonal 256 pridanie a 52 odobranie
  1. 256 52
      TEAMModelOS/ClientApp/src/view/iot/areaiot.vue

+ 256 - 52
TEAMModelOS/ClientApp/src/view/iot/areaiot.vue

@@ -336,7 +336,10 @@ export default {
       },
       exportData: {
         school: '',
-        area: ''
+        area: '',
+        areaIotData: '',
+        sdate: '',
+        edate: '',
       },
       basicaListInfo: [
         // { title: '学校简码', icon: '#icon-xuanzexuexiao-01', value: 'hbcn', key: 'code' },
@@ -475,6 +478,9 @@ export default {
         //整体数据
         this.exportData.school = res.school
         this.exportData.area = res.area
+        this.exportData.areaIotData = res.iotData
+        this.exportData.sdate = res.area.sdate
+        this.exportData.edate = res.area.edate
         //header基础数据
         let { classCnt, deviceAuthCnt, tmidCnt, teacherCnt, stuShow, studentCnt, stuLessonLengMin, lessonRecord, lessonLengMin, htcDevCnt } = res.area
         let iotData = res.iotData
@@ -626,70 +632,268 @@ export default {
     //数据导出
     exportTable() {
       let sheets = []
-      let schoolArr = this.exportData.school; let areaArr = this.exportData.area
-      //整体学区
-      let list = [{
-        areaName: this.schoolInfo.names,
-        areaId: sessionStorage.getItem('areaId'),
-        classRoom: areaArr.htcDevCnt,
-        teachNum: areaArr.tmidCnt,
-        classTotal: areaArr.lessonRecord,
-        classTime: Math.round(areaArr.lessonLengMin / 60),
-        studentParticipation: areaArr.stuShow,
-        studentTime: Math.round(areaArr.stuLessonLengMin / 60),
-        taskNum: areaArr.mission,
-        worksNum: areaArr.missionFin,
-        subjectNum: areaArr.item,
-        interactionNum: areaArr.interact,
-        cooperation: areaArr.lTypeCoop,
-        interaction: areaArr.lTypeIact,
-        task: areaArr.lTypeMis,
-        differentiation: areaArr.lTypeDif,
-        test: areaArr.lTypeTst,
-      }]
+      let schoolArr = this.exportData.school; let areaArr = this.exportData.area; let areaIotDatas = this.exportData.areaIotData
+      //处理学区每个月的数据
+      let startTime = new Date(this.exportData.sdate); let endTime = new Date(this.exportData.edate)
+      let startYear = startTime.getFullYear()
+      let startMonth = startTime.getMonth() + 1
+      let endYear = endTime.getFullYear()
+      let endMonth = endTime.getMonth() + 1
+      let monthLength = this.monthsBetweenDates(startTime, endTime)
+      console.log(monthLength, '相差月数')
+      let monthAreaData = []
+      if (monthLength) {
+        monthLength.forEach((item) => {
+          let nowYear = item.year; let nowMonth = item.month;
+          monthAreaData.push({
+            year: nowYear,
+            month: nowMonth + this.$t('schoolBaseInfo.monthHolder'),
+            monthNum: nowMonth,
+            areaName: this.schoolInfo.names,
+            areaId: sessionStorage.getItem('areaId'),
+            classRoom: [],
+            teachNum: [],
+            classTotal: 0,
+            classTime: 0,
+            studentParticipation: 0,
+            studentTime: 0,
+            taskNum: 0,
+            worksNum: 0,
+            subjectNum: 0,
+            interactionNum: 0,
+            cooperation: 0,
+            interaction: 0,
+            task: 0,
+            differentiation: 0,
+            test: 0,
+          })
+        })
+      }
+      let totalClassRoom = []
+      areaIotDatas.forEach((item) => {
+        let years = item.year; let months = item.month;
+        if (item.toolType === 'HiTeach') {
+          let result = monthAreaData.find(items => items.monthNum == months && items.year == years)
+          if (result !== undefined) {
+            // result.schoolName = item.school.name
+            // result.schoolCode = item.schoolId
+            //result.classRoom += item.deviceList.length
+            //result.teachNum += item.tmidList.length
+            result.classRoom.push(...item.deviceList)
+            totalClassRoom.push(...item.deviceList)
+            result.teachNum.push(...item.tmidList)
+            result.classTotal += item.lessonRecord
+            result.classTime += item.lessonLengMin
+            result.studentParticipation += item.stuShow
+            result.studentTime += item.stuLessonLengMin
+            result.taskNum += item.mission
+            result.worksNum += item.missionFin
+            result.subjectNum += item.item
+            result.interactionNum += item.interact
+            result.cooperation += item.lTypeCoop
+            result.interaction += item.lTypeIact
+            result.task += item.lTypeMis
+            result.differentiation += item.lTypeDif
+            result.test += item.lTypeTst
+          }
+        }
+      })
+      monthAreaData.forEach((item) => {
+        item.classRoom = [...new Set(item.classRoom)].length
+        item.teachNum = [...new Set(item.teachNum)].length
+        item.classTime = Math.ceil(item.classTime / 60);
+        item.studentTime = Math.ceil(item.studentTime / 60);
+      })
+      totalClassRoom = [...new Set(totalClassRoom)].length
       const totalSheet = {
-        title: [this.$t('cusMgt.listName'), 'ID', ...this.basicaListInfo.map(i => i.title), ...this.inuseListInfo.map(i => i.title), ...this.bars.xdata],
-        key: ['areaName', 'areaId', 'classRoom', 'teachNum', 'classTotal', 'classTime', 'studentParticipation', 'studentTime', 'taskNum', 'worksNum', 'subjectNum', 'interactionNum', 'cooperation', 'interaction', 'task', 'differentiation', 'test'],
-        data: list,
+        title: [this.$t('schoolBaseInfo.monthHolder'), this.$t('cusMgt.listName'), 'ID', ...this.basicaListInfo.map(i => i.title), ...this.inuseListInfo.map(i => i.title), ...this.bars.xdata],
+        key: ['month', 'areaName', 'areaId', 'classRoom', 'teachNum', 'classTotal', 'classTime', 'studentParticipation', 'studentTime', 'taskNum', 'worksNum', 'subjectNum', 'interactionNum', 'cooperation', 'interaction', 'task', 'differentiation', 'test'],
+        data: monthAreaData,
         autoWidth: true,
         filename: this.schoolInfo.names
       };
+      console.log(monthAreaData, '月份数据')
+      console.log(totalClassRoom, '数据')
       sheets.push(totalSheet);
-      console.log(schoolArr.map(i => i.lessonRecord))
-      //区内各个学校
-      schoolArr.forEach((item) => {
-        let schoolData = [{
-          schoolName: item.schName,
-          schoolCode: item.schId,
-          classRoom: item.htcDevCnt,
-          teachNum: item.tmidCnt,
-          classTotal: item.lessonRecord,
-          classTime: Math.round(item.lessonLengMin / 60),
-          studentParticipation: item.stuShow,
-          studentTime: Math.round(item.stuLessonLengMin / 60),
-          taskNum: item.mission,
-          worksNum: item.missionFin,
-          subjectNum: item.item,
-          interactionNum: item.interact,
-          cooperation: item.lTypeCoop,
-          interaction: item.lTypeIact,
-          task: item.lTypeMis,
-          differentiation: item.lTypeDif,
-          test: item.lTypeTst,
-        }]
+      //学校列表
+      let monthSchoolData = []
+      monthLength.forEach((item) => {
+        let nowYear = item.year; let nowMonth = item.month;
+        let monthSchool = []
+        schoolArr.forEach((items) => {
+          monthSchool.push({
+            year: nowYear,
+            month: nowMonth + this.$t('schoolBaseInfo.monthHolder'),
+            monthNum: nowMonth,
+            schoolName: items.schName,
+            schoolCode: items.schId,
+            classRoom: [],
+            teachNum: [],
+            classTotal: 0,
+            classTime: 0,
+            studentParticipation: 0,
+            studentTime: 0,
+            taskNum: 0,
+            worksNum: 0,
+            subjectNum: 0,
+            interactionNum: 0,
+            cooperation: 0,
+            interaction: 0,
+            task: 0,
+            differentiation: 0,
+            test: 0,
+          })
+        })
+        monthSchoolData.push({ year: nowYear, month: item.month, data: monthSchool })
+      })
+
+      areaIotDatas.forEach((item) => {
+        let years = item.year; let months = item.month; let schoolCodes = item.schoolId
+        if (item.toolType === 'HiTeach') {
+          let result = monthSchoolData.find(items => items.month == months && items.year == years)
+          if (result !== undefined) {
+            let resultSchool = result.data.find(itemc => itemc.schoolCode === schoolCodes)
+            if (resultSchool !== undefined) {
+              resultSchool.classRoom.push(...item.deviceList)
+              resultSchool.teachNum.push(...item.tmidList)
+              resultSchool.classTotal += item.lessonRecord
+              resultSchool.classTime += item.lessonLengMin
+              resultSchool.studentParticipation += item.stuShow
+              resultSchool.studentTime += item.stuLessonLengMin
+              resultSchool.taskNum += item.mission
+              resultSchool.worksNum += item.missionFin
+              resultSchool.subjectNum += item.item
+              resultSchool.interactionNum += item.interact
+              resultSchool.cooperation += item.lTypeCoop
+              resultSchool.interaction += item.lTypeIact
+              resultSchool.task += item.lTypeMis
+              resultSchool.differentiation += item.lTypeDif
+              resultSchool.test += item.lTypeTst
+            }
+          }
+        }
+        // if (item.toolType === 'HiTeach') {
+        //   let result = monthAreaData.find(items => items.monthNum == months && items.year == years && item.)
+        //   if (result !== undefined) {
+        //     result.schoolName = item.school.name
+        //     result.schoolCode = item.schoolId
+        //     //result.classRoom += item.deviceList.length
+        //     //result.teachNum += item.tmidList.length
+        //     result.classRoom.push(...item.deviceList)
+        //     totalClassRoom.push(...item.deviceList)
+        //     result.teachNum.push(...item.tmidList)
+        //     result.classTotal += item.lessonRecord
+        //     result.classTime += item.lessonLengMin
+        //     result.studentParticipation += item.stuShow
+        //     result.studentTime += item.stuLessonLengMin
+        //     result.taskNum += item.mission
+        //     result.worksNum += item.missionFin
+        //     result.subjectNum += item.item
+        //     result.interactionNum += item.interact
+        //     result.cooperation += item.lTypeCoop
+        //     result.interaction += item.lTypeIact
+        //     result.task += item.lTypeMis
+        //     result.differentiation += item.lTypeDif
+        //     result.test += item.lTypeTst
+        //   }
+        // }
+      })
+      monthSchoolData.forEach((item) => {
+        console.log(item, '3333')
+        item.data.forEach((items) => {
+          items.classRoom = [...new Set(items.classRoom)].length
+          items.teachNum = [...new Set(items.teachNum)].length
+          items.classTime = Math.ceil(items.classTime / 60);
+          items.studentTime = Math.ceil(items.studentTime / 60);
+        })
         const schoolSheet = {
-          title: [this.$t('schoolList.columns.name'), this.$t('schoolList.columns.shortCode'), ...this.basicaList.map(i => i.title), ...this.inuseList.map(i => i.title), ...this.bars.xdata],
-          key: ['schoolName', 'schoolCode', 'classRoom', 'teachNum', 'classTotal', 'classTime', 'studentParticipation', 'studentTime', 'taskNum', 'worksNum', 'subjectNum', 'interactionNum', 'cooperation', 'interaction', 'task', 'differentiation', 'test'],
-          data: schoolData,
+          title: [this.$t('schoolBaseInfo.monthHolder'), this.$t('schoolList.columns.name'), this.$t('schoolList.columns.shortCode'), ...this.basicaList.map(i => i.title), ...this.inuseList.map(i => i.title), ...this.bars.xdata],
+          key: ['month', 'schoolName', 'schoolCode', 'classRoom', 'teachNum', 'classTotal', 'classTime', 'studentParticipation', 'studentTime', 'taskNum', 'worksNum', 'subjectNum', 'interactionNum', 'cooperation', 'interaction', 'task', 'differentiation', 'test'],
+          data: item.data,
           autoWidth: true,
-          filename: item.schName
+          filename: item.month + '月'
         };
         sheets.push(schoolSheet);
       })
+
+      console.log(monthSchoolData, '学校数据')
+      //整体学区
+      // let list = [{
+      //   areaName: this.schoolInfo.names,
+      //   areaId: sessionStorage.getItem('areaId'),
+      //   classRoom: areaArr.htcDevCnt,
+      //   teachNum: areaArr.tmidCnt,
+      //   classTotal: areaArr.lessonRecord,
+      //   classTime: Math.round(areaArr.lessonLengMin / 60),
+      //   studentParticipation: areaArr.stuShow,
+      //   studentTime: Math.round(areaArr.stuLessonLengMin / 60),
+      //   taskNum: areaArr.mission,
+      //   worksNum: areaArr.missionFin,
+      //   subjectNum: areaArr.item,
+      //   interactionNum: areaArr.interact,
+      //   cooperation: areaArr.lTypeCoop,
+      //   interaction: areaArr.lTypeIact,
+      //   task: areaArr.lTypeMis,
+      //   differentiation: areaArr.lTypeDif,
+      //   test: areaArr.lTypeTst,
+      // }]
+      // const totalSheet = {
+      //   title: ['学区名称', '学区ID', ...this.basicaListInfo.map(i => i.title), ...this.inuseListInfo.map(i => i.title), ...this.bars.xdata],
+      //   key: ['areaName', 'areaId', 'classRoom', 'teachNum', 'classTotal', 'classTime', 'studentParticipation', 'studentTime', 'taskNum', 'worksNum', 'subjectNum', 'interactionNum', 'cooperation', 'interaction', 'task', 'differentiation', 'test'],
+      //   data: list,
+      //   autoWidth: true,
+      //   filename: this.schoolInfo.names
+      // };
+      // sheets.push(totalSheet);
+      //区内各个学校
+      // schoolArr.forEach((item) => {
+      //   let schoolData = [{
+      //     schoolName: item.schName,
+      //     schoolCode: item.schId,
+      //     classRoom: item.htcDevCnt,
+      //     teachNum: item.tmidCnt,
+      //     classTotal: item.lessonRecord,
+      //     classTime: Math.round(item.lessonLengMin / 60),
+      //     studentParticipation: item.stuShow,
+      //     studentTime: Math.round(item.stuLessonLengMin / 60),
+      //     taskNum: item.mission,
+      //     worksNum: item.missionFin,
+      //     subjectNum: item.item,
+      //     interactionNum: item.interact,
+      //     cooperation: item.lTypeCoop,
+      //     interaction: item.lTypeIact,
+      //     task: item.lTypeMis,
+      //     differentiation: item.lTypeDif,
+      //     test: item.lTypeTst,
+      //   }]
+      //   const schoolSheet = {
+      //     title: [this.$t('schoolList.columns.name'), this.$t('schoolList.columns.shortCode'), ...this.basicaList.map(i => i.title), ...this.inuseList.map(i => i.title), ...this.bars.xdata],
+      //     key: ['schoolName', 'schoolCode', 'classRoom', 'teachNum', 'classTotal', 'classTime', 'studentParticipation', 'studentTime', 'taskNum', 'worksNum', 'subjectNum', 'interactionNum', 'cooperation', 'interaction', 'task', 'differentiation', 'test'],
+      //     data: schoolData,
+      //     autoWidth: true,
+      //     filename: item.schName
+      //   };
+      //   sheets.push(schoolSheet);
+      // })
       let excelName = this.schoolInfo.names + "- iot" + this.$t('totalAnalysis.totalIndex.tab1')
       excel.export_array_to_sheet(sheets, excelName);
       console.log(sheets, '总数据')
-    }
+    },
+    monthsBetweenDates(timestamp1, timestamp2) {
+      const startDate = new Date(Math.min(timestamp1, timestamp2)); // 较早的时间戳作为起始日期
+      const endDate = new Date(Math.max(timestamp1, timestamp2)); // 较晚的时间戳作为结束日期
+
+      const monthRange = []; // 用于存储月份的数组
+
+      let currentDate = new Date(startDate); // 从起始日期开始
+      while (currentDate <= endDate) {
+        const year = currentDate.getFullYear();
+        const month = currentDate.getMonth() + 1; // 月份需要加 1,因为 JavaScript 的月份是从 0 开始计数的
+        monthRange.push({ year, month }); // 存储当前月份的年份和月份
+        currentDate.setMonth(currentDate.getMonth() + 1); // 将日期推进到下一个月
+      }
+      return monthRange;
+    },
   }
 }
 </script>