'use strict'; const Service = require('egg').Service; const Maps = ["舟山","博鳌机场","昌都机场"] const Weathers = ["晴天","雨天"]; const Times = ["白天","黑夜"]; const RoleNames = require("../const").RoleNames; const VehicleIds = {z8:0,z9:1,z10:2,m171:3,y12:4}; const VehicleNames = ["直8","直9","直10","米171","运12"] const StatisName = require("../const").StatisName; class HelpService extends Service { async bigScreen(query) { let id = query.id; let mysql = this.app.mysql; let where = `where r.id=${id}`; let sql = `select r.id, r.title,r.state, date_format(r.start_time,'%Y-%m-%d %H:%m:%s') as start_time, date_format(r.end_time,'%Y-%m-%d %H:%m:%s') as end_time, r.config, users.name as teacher_name, r.teacher_id, r.duration, r.playback, t.subject from train_records as r left join users on users.id=r.teacher_id left join train_templates as t on t.id = r.template_id ${where}` let ret = await mysql.query( sql ); let info = ret[0]; info.duration = Math.floor( info.duration / 60 ); let config = JSON.parse( info.config ); // { // return {pilots: [], comm, teacher, others: otherIds, fixer, task: [...taskTimes, ...TaskSumCount]}; // } // info.config = null; info.scene = config?config.scene.id:-1; let role = config?config.role:null; let urs = []; if( role ) { let n = role.length; let users = []; for(let i=0; i 0 ) { let ids = users.map(item=>item.user); ids = ids.join(","); let userInfo = await mysql.query(`select id, realname,name,code from users where id in (${ids})`); let usermap = {}; userInfo.forEach( item=>{ usermap[item.id] = item; }); users.forEach(item=>{ let id = item.user; let uinfo = usermap[id]; let uinfo2 = role[item.index]; let r = {realname: uinfo.realname, code: uinfo.code, role: RoleNames[uinfo2.role], team:uinfo2.team, group: uinfo2.group, id: uinfo.id}; if( uinfo2.vehicleid > -1) { r.vehicleid = VehicleNames[uinfo2.vehicleid]; } urs.push(r); }) } } info.users = urs; let comm = info; let teacher = { faultTotal:2, faultOk: 0, logs:["日志1","日志2"] }; teacher.users = urs; let others = [{name: '战勤',logs:['日志1'], id:1}]; let otherIds = []; const OtherRoleNames = ["总参谋长","支队长","融合力量","参谋终端","航管员","气象员","战勤","导调"]; let n = urs.length; for( let i=0; i -1 ) { otherIds.push({name:urs[i].role, logs: [], id: urs[i].id}) } } //获取其他终端的日志 n = otherIds.length; for( let i=0; iitem.text); //获取飞行员的日志 n = urs.length; let pilotsUsers = []; for( let i=0; i{ return StatisName.indexOf(item) }); let taskTimes = await mysql.query(`select state, max(value) as value from train_records_result where rid=${id} and state in(${taskStates.join(",")}) group by state`); taskTimes = taskTimes.map(item=>{ let v = Math.ceil(item.value / 60) + "分钟"; return `${StatisName[item.state]}:${v}`; }); //任务次数 let TaskSumCount = ["空中投送成功次数","悬停索降成功次数", "悬停索降失败次数", "机降成功次数","机降失败次数"]; taskStates = TaskSumCount.map(item=>{ return StatisName.indexOf(item) }); let taskT = await mysql.query(`select state, sum(value) as value from train_records_result where rid=${id} and state in(${taskStates.join(",")}) group by state`); TaskSumCount = []; if( taskT.length > 0 ) { TaskSumCount = taskT.map(item=>{ let v = item.value; return `${StatisName[item.state]}:${v}`; }); } return {pilots: pilotsUsers, comm, teacher, others: otherIds, fixer, task: [...taskTimes, ...TaskSumCount]}; } async getLogs(rid, uid) { let mysql = this.app.mysql; let url = `select text from train_records_logs where rid=${rid} and uid=${uid} order by tick limit 0, 10`; let logs = await mysql.query( url ); return logs.map(item=>item.text); } async getTwoLines(query) { let uid = query.uid; let rid = query.rid; if( !uid || !rid || uid == 'undefined') throw "ID为空!"; let mysql = this.app.mysql; let url = `select tick, speed from train_records_fly where rid=${rid} and uid=${uid} order by tick limit 0, 2000`; let speeds = await mysql.query( url ); url = `select tick, altitude from train_records_fly where rid=${rid} and uid=${uid} order by tick limit 0, 2000`; let heights = await mysql.query( url ); return {speeds, heights}; } async getNaviConfigLine(query) { let rid = query.rid; let mysql = this.app.mysql; let url = `select navi_config from train_records where id=${rid}`; let ret = await mysql.query( url ); let config = ret[0].navi_config; if( config ) { try { config = JSON.parse( config ); } catch (error) { console.error( error ); config = {lines:[] } } } else { config = {lines:[] } } return config; } async getUserNaviLines(query) { let uid = query.uid; let rid = query.rid; if( !uid || !rid || uid == 'undefined') throw "ID为空!"; let mysql = this.app.mysql; let url = `select tick, longtitude, latitude from train_records_fly where rid=${rid} and uid=${uid} order by tick limit 0, 5000`; let ret = await mysql.query( url ); ret.map(item=>{ return {lon: item.longtitude, lat: item.latitude} }) return {lines: [ret] }; } } module.exports = HelpService;