123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252 |
- '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<n; i++) {
- if(role[i].user == -1) continue;
- users.push({index:i, user:role[i].user});
- // {
- // "role": 20,
- // "team": 1,
- // "group": 2,
- // "num": 2,
- // "vehicleid": 1,
- // "user": -1
- // }
- }
- if( users.length > 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<n; i++) {
- if( OtherRoleNames.indexOf(urs[i].role) > -1 ) {
- otherIds.push({name:urs[i].role, logs: [], id: urs[i].id})
- }
- }
- //获取其他终端的日志
- n = otherIds.length;
- for( let i=0; i<n; i++) {
- otherIds[i].logs = await this.getLogs(id, otherIds[i].id)
- }
- //获取导调的飞行日志
- let url = `select text from train_records_logs where rid=${id} and uid=${info.teacher_id} order by tick limit 0, 10`;
- let logs = await mysql.query( url );
- teacher.logs = logs.map(item=>item.text);
- //获取飞行员的日志
- n = urs.length;
- let pilotsUsers = [];
- for( let i=0; i<n; i++) {
- if( urs[i].role == '飞行员' ) {
- let data = [];
- data.push({name:"编号", value:urs[i].code});
- data.push({name:"所属分队", value:`小队${urs[i].team}`});
- data.push({name:"所属分组", value:`小队${urs[i].group}`});
- data.push({name:"飞机型号", value:`${urs[i].vehicleid}`});
- data.push({name:"机务", value:`${urs[i].vehicleid}`});
-
- let crash = await mysql.query("select value from train_records_result where rid=? and uid=? and state=?", [id, urs[i].id, StatisName.indexOf("坠毁次数")]);
- crash = crash[0]?crash[0].value:0;
- data.push({name:"坠毁次数", value: crash});
- let logCount = await mysql.query("select count(id) as count from train_records_logs where rid=? and uid=?", [id, urs[i].id]);
- logCount = logCount[0]?logCount[0].count:0;
- data.push({name:"日志数量", value: logCount});
-
- let maxS = await mysql.query("select max(speed) as speed, max(altitude) as height from train_records_fly where rid=? and uid=?", [id, urs[i].id]);
- let h = maxS[0]?maxS[0].height:0;
- let sped = maxS[0]?maxS[0].speed:0;
- data.push({name:"最大高度", value: h});
- data.push({name:"最大速度", value: sped});
- pilotsUsers.push({
- name:urs[i].role,
- data:data,
- logs: await this.getLogs(id, urs[i].id),
- id: urs[i].id});
- }
- }
- //获取机务终端数据
- // let url = `select `
- let fixerNames = ["接收故障总数量", "成功排查故障次数"];
- n = fixerNames.length;
-
- let fixer = [];
- for( let i=0; i<n; i++) {
- let index = StatisName.indexOf( fixerNames[i] );
- let sql = `select sum(value) as value from train_records_result where rid=${id} and state=${index}`;
- let v = await mysql.query(sql);
- let vl = 0;
- if( v[0] && v[0].value ) vl = v[0].value;
- fixer.push({name: fixerNames[i], value: vl});
- }
- fixer.push({name:"失败排查故障次数",value: fixer[0].value - fixer[1].value});
- teacher.faultTotal = fixer[0].value;
- teacher.faultOk = fixer[1].value;
- //任务时间
- let TaskNames = ["灭火任务完成时间","舱门射击任务完成时间", "搜索任务完成时间", "抢险救援完成时间"];
- n = TaskNames.length;
- let taskStates = TaskNames.map(item=>{ 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;
|