Explorar o código

重构同步逻辑,web来写主逻辑

Michael Wang %!s(int64=3) %!d(string=hai) anos
pai
achega
5bb8ec67e8

+ 14 - 14
src/api/api.ts

@@ -100,20 +100,20 @@ export function countStudents(examId: number, params) {
   return httpApp.post("/api/exam/students/count", new URLSearchParams(params));
 }
 
-// export function getPackages(examId, upload, withUrl) {
-//   let uri = "/api/package/count/" + examId;
-//   const param = [];
-//   if (upload != undefined) {
-//     param.push("upload=" + (upload ? "true" : "false"));
-//   }
-//   if (withUrl != undefined) {
-//     param.push("withUrl=" + (withUrl ? "true" : "false"));
-//   }
-//   if (param.length > 0) {
-//     uri = uri + "?" + param.join("&");
-//   }
-//   return execute(uri, "GET");
-// }
+export function getPackages(examId, upload, withUrl) {
+  let uri = "/api/package/count/" + examId;
+  const param = [];
+  if (upload != undefined) {
+    param.push("upload=" + (upload ? "true" : "false"));
+  }
+  if (withUrl != undefined) {
+    param.push("withUrl=" + (withUrl ? "true" : "false"));
+  }
+  if (param.length > 0) {
+    uri = uri + "?" + param.join("&");
+  }
+  return httpApp.get(uri);
+}
 
 export default {
   // execute,

+ 26 - 0
src/lib/sync.ts

@@ -18,6 +18,32 @@ export async function queryStudentCount(store) {
   return results[0].count;
 }
 
+export async function replaceStudents(students) {
+  db.init();
+  await db.batchQuery(
+    "select 1 from eb_exam_student",
+    []
+    // "replace into eb_exam_student(id, exam_id, school_id\
+    //           , exam_number, secret_number, name, student_code, subject_code, subject_name, campus_name\
+    //           , package_code, batch_code, sheet_count, slice_count, answers, is_upload\
+    //           , is_absent, is_manual_absent, is_breach, is_exception\
+    //           , objective_score, subjective_score, objective_score_list, subjective_score_list, subjective_status\
+    //           , exam_site, exam_room, remark, college, class_name, teacher, paper_type) \
+    //           values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,0,?,?,?,?,?,?,?,?,?,?,?,?)",
+    // students
+  );
+}
+
+export async function replacePackage(packageData) {
+  db.init();
+  await db.batchQuery(
+    "select 1 from eb_exam_student",
+    []
+    // "replace into eb_exam_package(exam_id, code, pic_count) values (?,?,?)",
+    // packageData
+  );
+}
+
 class executor extends EventEmitter {
   async start(env) {
     try {

+ 4 - 4
src/preload.ts

@@ -1,19 +1,19 @@
-import { contextBridge, ipcRenderer, remote } from "electron";
+import { contextBridge, remote } from "electron";
 
 import env from "./lib/env";
 import config from "./lib/config";
-// import api from "./lib/api";
 import { addWatermark } from "./lib/watermark";
-import { queryStudentCount } from "./lib/sync";
+import { queryStudentCount, replaceStudents, replacePackage } from "./lib/sync";
 import { receiveMessage } from "./lib/channel";
 
 export const electronInWindow = {
   dialog: remote.dialog,
   env: env,
   config,
-  // api,
   addWatermark,
   queryStudentCount,
+  replaceStudents,
+  replacePackage,
   receiveMessage,
 };
 

+ 1 - 0
src/types/global.d.ts

@@ -43,5 +43,6 @@ declare module "vue" {
     APopconfirm: typeof import("ant-design-vue")["Popconfirm"];
     ATooltip: typeof import("ant-design-vue")["Tooltip"];
     ASelect: typeof import("ant-design-vue")["Select"];
+    AProgress: typeof import("ant-design-vue")["Progress"];
   }
 }

+ 1 - 4
src/views/features/Sync/Sync.vue

@@ -32,10 +32,7 @@
 
 <script setup lang="ts">
 import { store } from "@/store";
-import { computed, onMounted, ref } from "vue";
-import router from "@/router";
-import { getStudents, countStudents } from "@/api/api";
-import { httpApp } from "@/plugins/axiosApp";
+import { onMounted, ref } from "vue";
 
 const lastTime =
   store.config["syncTime"][store.env.server.host + store.env.exam.id];

+ 92 - 28
src/views/features/SyncRun/SyncRun.vue

@@ -15,16 +15,18 @@
         <div class="progress-box">
           <h3 id="message">正在下载考生...</h3>
           <div class="progress">
-            <div class="progress-outer">
+            <!-- <div class="progress-outer">
               <div id="progress" class="progress-inner" style="width: 0%">
                 <span class="progress-text"></span>
               </div>
-            </div>
+            </div> -->
+            <a-progress
+              :percent="Math.round((finishCount / totalCount) * 100)"
+            />
           </div>
           <p>
-            已数据同步考生:<b id="finish-count"></b> / 全部考生:<b
-              id="total-count"
-            ></b>
+            已数据同步考生:<b id="finish-count">{{ finishCount }}</b> /
+            全部考生:<b id="total-count">{{ totalCount }}</b>
           </p>
         </div>
       </div>
@@ -52,35 +54,97 @@
 
 <script setup lang="ts">
 import { store } from "@/store";
-import { computed, onMounted, ref } from "vue";
+import { onMounted, ref } from "vue";
 import router from "@/router";
-import { getStudents, countStudents } from "@/api/api";
-import { httpApp } from "@/plugins/axiosApp";
+import { getStudents, countStudents, getPackages } from "@/api/api";
 
 const lastTime =
   store.config["syncTime"][store.env.server.host + store.env.exam.id];
 
-let studentCount = ref(0);
+let finishCount = ref(0);
+let totalCount = ref(0);
+let finished = ref(false);
 onMounted(async () => {
-  const studentCountRes = await window.electron.queryStudentCount(
-    JSON.parse(JSON.stringify(store))
-  );
-  console.log(studentCountRes);
-  studentCount.value = studentCountRes;
+  const res = await countStudents(store.env.examId);
+  totalCount.value = res.data;
 
-  console.log("waiting ipcMain");
-  window.electron.updateSyncRun((event) => {
-    console.log(event);
-  });
-});
-window.electron.receiveMessage((msg) => {
-  console.log(msg);
+  let pageNumber = 0;
+
+  while (true) {
+    pageNumber++;
+    const array = (
+      await getStudents(store.env.examId, pageNumber, 100, {
+        withScoreDetail: true,
+      })
+    ).data;
+    if (array == undefined || array.length == 0) {
+      break;
+    }
+    const datas = [];
+    for (let i = 0; i < array.length; i++) {
+      const obj = array[i];
+      var objList = [];
+      var subList = [];
+      if (obj.objectiveScoreDetail) {
+        obj.objectiveScoreDetail.forEach((detail) => {
+          const score = Math.round((detail.score * 10) / 10);
+          objList.push(detail.answer + ":" + score);
+        });
+      }
+      if (obj.subjectiveScoreDetail) {
+        obj.subjectiveScoreDetail.forEach((detail) => {
+          const score = Math.round((detail.score * 10) / 10);
+          subList.push(score);
+        });
+      }
+      datas.push([
+        obj["id"],
+        store.env.examId,
+        obj["schoolId"],
+        obj["examNumber"],
+        obj["examNumber"],
+        obj["name"],
+        obj["studentCode"],
+        obj["subjectCode"],
+        obj["subjectName"],
+        obj["campusName"],
+        obj["packageCode"],
+        obj["batchCode"],
+        obj["sheetCount"],
+        obj["sliceCount"],
+        obj["answers"],
+        obj["upload"] ? 1 : 0,
+        obj["absent"] ? 1 : 0,
+        obj["breach"] ? 1 : 0,
+        obj["manualAbsent"] ? 1 : 0,
+        obj["objectiveScore"].length > 0 ? obj["objectiveScore"] : 0,
+        obj["subjectiveScore"].length > 0 ? obj["subjectiveScore"] : 0,
+        objList.join(";"),
+        subList.join(";"),
+        obj["subjectiveStatus"] || "UNMARK",
+        obj["examSite"],
+        obj["examRoom"],
+        obj["remark"],
+        obj["college"] || "",
+        obj["className"] || "",
+        obj["teacher"] || "",
+        obj["paperType"] || "",
+      ]);
+    }
+    console.log("get:" + array.length);
+    await window.electron.replaceStudents(datas);
+    finishCount.value += array.length;
+  }
+
+  //get and save package
+  const packages = (await getPackages(store.env.examId)).data;
+  const packageData = [];
+  for (let i = 0; i < packages.length; i++) {
+    const obj = packages[i];
+    packageData.push([store.env.examId, obj["code"], obj["picCount"]]);
+  }
+  await window.electron.replacePackage(packageData);
+
+  finished.value = true;
 });
-console.log(window.electron.syncer);
-const _sync = window.electron.syncer;
-console.log(_sync);
-console.log(window.electron.dialog);
-window.electron.syncer(JSON.parse(JSON.stringify(store)));
-// _sync.on("total", (c) => console.log(c));
-// _sync.start();
 </script>