张艾宸

完整版1.0

@@ -2,7 +2,8 @@ const GETCLASSURL = "http://139.196.126.156:8081/getLogs/recordClassList" @@ -2,7 +2,8 @@ const GETCLASSURL = "http://139.196.126.156:8081/getLogs/recordClassList"
2 const GETCLASSURLPARAMETER = { 2 const GETCLASSURLPARAMETER = {
3 siteId:["BuzzKID","kuaikuenglish"], 3 siteId:["BuzzKID","kuaikuenglish"],
4 key:"xdymp4record20191225", 4 key:"xdymp4record20191225",
5 - page:1 5 + page:1,
  6 + maxMedia:1,
6 } 7 }
7 8
8 const PROJECTWINCATALOG = "E:/project/web_capture_release/win-x64" 9 const PROJECTWINCATALOG = "E:/project/web_capture_release/win-x64"
@@ -22,7 +23,9 @@ const BACKMEDIACONFIG = { @@ -22,7 +23,9 @@ const BACKMEDIACONFIG = {
22 d:0.5*60*60*1000, 23 d:0.5*60*60*1000,
23 s:0, 24 s:0,
24 fa:15, 25 fa:15,
25 - k:1 26 + k:1,
  27 + w:1600,
  28 + h:789,
26 } 29 }
27 module.exports = { 30 module.exports = {
28 GETCLASSURL, 31 GETCLASSURL,
@@ -13,10 +13,9 @@ const { startTime, endTime, ymd } = YesterdayTime() @@ -13,10 +13,9 @@ const { startTime, endTime, ymd } = YesterdayTime()
13 let siteIds = GETCLASSURLPARAMETER.siteId 13 let siteIds = GETCLASSURLPARAMETER.siteId
14 14
15 let classid = [] 15 let classid = []
16 -let parentData = [] 16 +let parentData = {}
17 var classobj = {}; 17 var classobj = {};
18 let className = "" 18 let className = ""
19 -let maxMedia = 2  
20 /** 19 /**
21 * 20 *
22 * @param {*} id 课堂id 21 * @param {*} id 课堂id
@@ -27,40 +26,32 @@ class MediaCreat { @@ -27,40 +26,32 @@ class MediaCreat {
27 async allData() { 26 async allData() {
28 let page = 1 27 let page = 1
29 className = siteIds.shift() 28 className = siteIds.shift()
30 - let result = await getRequestClassIds(GETCLASSURL, className, GETCLASSURLPARAMETER.key, startTime, endTime, page)  
31 - for (let j = 0; j < result.data.data.list.length; j++) {  
32 - classid.push(result.data.data.list[j])  
33 - }  
34 - const { siteId, list, totalPage } = result.data.data  
35 - for (let i = page += 1; i <= totalPage; i++) {  
36 - let result = await getRequestClassIds(GETCLASSURL, className, GETCLASSURLPARAMETER.key, startTime, endTime, i) 29 + if (className) {
  30 + let result = await getRequestClassIds(GETCLASSURL, className, GETCLASSURLPARAMETER.key, startTime, endTime, page)
  31 + parentData[result.data.data.siteId] = []
  32 +
37 for (let j = 0; j < result.data.data.list.length; j++) { 33 for (let j = 0; j < result.data.data.list.length; j++) {
38 classid.push(result.data.data.list[j]) 34 classid.push(result.data.data.list[j])
39 } 35 }
40 - }  
41 -  
42 - classid = classid.reduce(function (item, next) {  
43 - classobj[next.classId] ? '' : classobj[next.classId] = true && item.push(next);  
44 - return item;  
45 - }, []);  
46 - parentData = JSON.parse(JSON.stringify(classid))  
47 - return true  
48 - }  
49 -  
50 - // 取出不同的值  
51 - async notResult(data1, data2) {  
52 - new Promise((resolve, reject) => {  
53 - let data = []  
54 - for (let i = 0; i < data2.length; i++) {  
55 - // for(let j=0;j<data1.length;j++){  
56 - if (data1.indexOf(data2[i].classId+".mp4") == -1) {  
57 - console.log("不存在:"+data2[i])  
58 - data.push(data2[i]) 36 + const { siteId, list, totalPage } = result.data.data
  37 + for (let i = page += 1; i <= totalPage; i++) {
  38 + let result = await getRequestClassIds(GETCLASSURL, className, GETCLASSURLPARAMETER.key, startTime, endTime, i)
  39 + for (let j = 0; j < result.data.data.list.length; j++) {
  40 + classid.push(result.data.data.list[j])
59 } 41 }
60 } 42 }
61 - console.log("data",data)  
62 - return resolve(data)  
63 - }) 43 +
  44 + classid = classid.reduce(function (item, next) {
  45 + classobj[next.classId] ? '' : classobj[next.classId] = true && item.push(next);
  46 + return item;
  47 + }, []);
  48 + for (let i = 0; i < classid.length; i++) {
  49 + parentData[result.data.data.siteId].push(classid[i].classId)
  50 + }
  51 + return true
  52 + } else {
  53 + return false
  54 + }
64 } 55 }
65 async mediaCreat(id, siteId) { 56 async mediaCreat(id, siteId) {
66 let mediaDir = PROJECTCATALOG + "/media/" 57 let mediaDir = PROJECTCATALOG + "/media/"
@@ -75,23 +66,34 @@ class MediaCreat { @@ -75,23 +66,34 @@ class MediaCreat {
75 if (!fs.existsSync(ymdDir)) { 66 if (!fs.existsSync(ymdDir)) {
76 fs.mkdirSync(ymdDir); 67 fs.mkdirSync(ymdDir);
77 } 68 }
78 - let url = `web_capture_c -o=../media/${siteId}/${ymd}/${id}.mp4 -u="${BACKMEDIACONFIG.url}?classId=${id}&userId=${BACKMEDIACONFIG.userId}&userName=${BACKMEDIACONFIG.userName}&userRole=${BACKMEDIACONFIG.userRole}&portalIP=${BACKMEDIACONFIG.portalIP}&portalPort=${BACKMEDIACONFIG.portalPort}&channels=${BACKMEDIACONFIG.channels}&playRecord=${BACKMEDIACONFIG.playRecord}" -d=${BACKMEDIACONFIG.d} -s=${BACKMEDIACONFIG.s} -fa=${BACKMEDIACONFIG.fa} -k=${BACKMEDIACONFIG}` 69 + let url = `web_capture_c -o=../media/${siteId}/${ymd}/${id}.mp4 -u="${BACKMEDIACONFIG.url}?classId=${id}&userId=${BACKMEDIACONFIG.userId}&userName=${BACKMEDIACONFIG.userName}&userRole=${BACKMEDIACONFIG.userRole}&portalIP=${BACKMEDIACONFIG.portalIP}&portalPort=${BACKMEDIACONFIG.portalPort}&channels=${BACKMEDIACONFIG.channels}&playRecord=${BACKMEDIACONFIG.playRecord}" -d=${BACKMEDIACONFIG.d} -s=${BACKMEDIACONFIG.s} -fa=${BACKMEDIACONFIG.fa} -k=${BACKMEDIACONFIG.k} -w=${BACKMEDIACONFIG.w} -h=${BACKMEDIACONFIG.h}`
79 var workerProcess = spawn(url, { cwd: PROJECTWINCATALOG, shell: true }) 70 var workerProcess = spawn(url, { cwd: PROJECTWINCATALOG, shell: true })
80 // workerProcess.stdout.on('data', async function (data) { 71 // workerProcess.stdout.on('data', async function (data) {
81 72
82 // }); 73 // });
83 74
84 workerProcess.on('close', async function (code) { 75 workerProcess.on('close', async function (code) {
85 - if (code == 0) { 76 + let files = fs.readdirSync(ymdDir);
  77 + if (files.indexOf(id + ".mp4") == -1) {
  78 + //当前课堂没有写入到文件夹,进入重录
  79 + new MediaCreat().mediaCreat(id, siteId)
  80 + return false
  81 + } else {
  82 + if (parentData[siteId].indexOf(id.toString()) != -1) {
  83 + parentData[siteId].splice(parentData[siteId].indexOf(id.toString()), 1)
  84 + }
  85 + if (parentData[siteId].length == 0) {
  86 + // //全部录制完毕
  87 + fs.writeFile(ymdDir + "/download.json", `{ "code": "0", "success": "ok"}`, function (err) {
  88 + if (err) {
  89 + console.log(err);
  90 + }
  91 + });
  92 + }
86 if (classid.length) { 93 if (classid.length) {
87 let shiftData = classid.shift() 94 let shiftData = classid.shift()
88 new MediaCreat().mediaCreat(shiftData['classId'], shiftData['siteId']) 95 new MediaCreat().mediaCreat(shiftData['classId'], shiftData['siteId'])
89 } else { 96 } else {
90 - // 判断是否有缺录  
91 - // let files = fs.readdirSync(ymdDir);  
92 - // if (files.length != parentData.length) {  
93 - // let notResult = await new MediaCreat().notResult(files,parentData)  
94 - // }  
95 if (siteIds.length) { 97 if (siteIds.length) {
96 // 如果有多家需要录制,继续录制下一家 98 // 如果有多家需要录制,继续录制下一家
97 let isAppend = await new MediaCreat().allData() 99 let isAppend = await new MediaCreat().allData()
@@ -101,8 +103,6 @@ class MediaCreat { @@ -101,8 +103,6 @@ class MediaCreat {
101 } 103 }
102 } 104 }
103 } 105 }
104 - } else {  
105 - new MediaCreat().mediaCreat(id, siteId)  
106 } 106 }
107 }); 107 });
108 } 108 }
@@ -113,7 +113,7 @@ router.get('/', async function (req, res, next) { @@ -113,7 +113,7 @@ router.get('/', async function (req, res, next) {
113 let isAppend = await new MediaCreat().allData() 113 let isAppend = await new MediaCreat().allData()
114 if (isAppend) { 114 if (isAppend) {
115 if (classid.length) { 115 if (classid.length) {
116 - for (let i = 0; i < maxMedia; i++) { 116 + for (let i = 0; i < GETCLASSURLPARAMETER.maxMedia; i++) {
117 let shiftData = classid.shift() 117 let shiftData = classid.shift()
118 if (shiftData) { 118 if (shiftData) {
119 new MediaCreat().mediaCreat(shiftData['classId'], shiftData['siteId']) 119 new MediaCreat().mediaCreat(shiftData['classId'], shiftData['siteId'])
webScreen @ 3ad40110
1 -Subproject commit 3ad4011072147004f3e1cc8db37eada85d7fcc17  
不能预览此文件类型