代码抽取优化、添加重要提示

This commit is contained in:
zhouyuejun
2018-12-13 18:15:41 +08:00
parent 95db4e4450
commit ffc263e7d1
26 changed files with 866 additions and 574 deletions
+479 -29
View File
@@ -152,7 +152,6 @@ export class FlightsDataHandle {
render_pre_flight[key] = preHasValue;
render_rea_flight[key] = reaHasValue;
}
flights_item['renderCombinedFlight'] = render_flight;
flights_item['renderPreFlight'] = render_pre_flight;
flights_item['renderReaFlight'] = render_rea_flight;
flights_item['renderFlight'] = Object.assign({}, render_flight);
@@ -161,10 +160,7 @@ export class FlightsDataHandle {
return flights_item;
}
/**
* 基础数据转换
*/
basicDataTransHandle(item, airports, citys, airlines, flightStatus) {
public basicDataTransHandle(item, airports, citys, airlines, flightStatus) {
if (this.orderHandle.isArriFlight(item) || this.orderHandle.isDeptFlight(item)) {
//航线处理
let erutCodeArray = item['renderFlight']['ERUT'].split(' - ');
@@ -246,32 +242,486 @@ export class FlightsDataHandle {
item['renderReaFlight']['ALCD'] = airlines[airlineReaIndex].airlineName;
//运营状态处理
item['renderReaFlight']['FTSS'] = flightStatus.find(val => val.sttc === item['renderReaFlight']['FTSS']).stdc
// //航线处理
// let erutCombinedCodeArray = item['renderCombinedFlight']['ERUT'].split(' - ');
// let erutCombinedChnArray = []
// for (let i = 0; i < erutCombinedCodeArray.length; i++) {
// try {
// let airportIndex = airports.findIndex(val => val.airportCodeIata === erutCombinedCodeArray[i]);
// let cityIndex = citys.findIndex(val => airports[airportIndex].cityId === val.cityId);
// erutCombinedChnArray.push(citys[cityIndex].cityNameChn);
// } catch (error) {
// erutCombinedChnArray.push(erutCombinedCodeArray[i]);
// }
// }
// item['renderCombinedFlight']['ERUT'] = erutCombinedChnArray.join(' - ');
// //航空公司处理
// let airlineCombinedIndex = airlines.findIndex(val => val.airlineCode === item['renderCombinedFlight']['ALCD']);
// item['renderCombinedFlight']['ALCD'] = airlines[airlineCombinedIndex].airlineName;
// //运营状态处理
// let ftssCombinedCodeArray = item['renderCombinedFlight']['FTSS'].split(' / ');
// let ftssCombinedChnArray = [];
// for (let i = 0; i < ftssCombinedCodeArray.length; i++) {
// ftssCombinedChnArray.push(flightStatus.find(val => val.sttc === ftssCombinedCodeArray[i]).stdc)
// }
// item['renderCombinedFlight']['FTSS'] = ftssCombinedChnArray.join(' / ');
}
return item;
}
public dynamicMessageHandle(message, combined_data, render_data, col_lists, filterItems, LASTSEARCH, LAST_SEL_COL, airports, citys, airlines, flightStatus) {
if (message.MVIN === 'A') {
//针对combined_data的处理
let index = combined_data.findIndex(element => {
if (this.orderHandle.isArriFlight(element) || this.orderHandle.isLinked(element)) {
if (element['preFlight']['FLID'] === message.FLID) {
return true;
} else {
return false;
}
} else {
return false;
}
});
if (index > -1) {
combined_data[index]['preFlight'] = message;
combined_data[index] = this.flightsRenderTransfer(combined_data[index], col_lists);
combined_data[index] = this.basicDataTransHandle(combined_data[index], airports, citys, airlines, flightStatus);
if (message.UPTP === 'FLOP-AOTP') {
if (this.orderHandle.isArriFlight(combined_data[index])) {
if (message.TAID) {
combined_data.splice(index, 1);
let i = combined_data.findIndex(element => {
if (this.orderHandle.isDeptFlight(element)) {
if (message.TAID === element['reaFlight']['FLID']) {
return true;
} else {
return false;
}
} else {
return false;
}
})
combined_data[i]['reaFlight']['TAID'] = message.FLID;
let newFlight = {};
newFlight['preFlight'] = message;
newFlight['reaFlight'] = combined_data[i]['reaFlight'];
combined_data.splice(i, 1);
newFlight = this.flightsRenderTransfer(newFlight, col_lists);
newFlight = this.basicDataTransHandle(newFlight, airports, citys, airlines, flightStatus);
combined_data.push(newFlight)
}
} else if (this.orderHandle.isLinked(combined_data[index])) {
if (!message.TAID) {
let newPreFlight = {},
newReaFlight = {};
newPreFlight['preFlight'] = combined_data[index]['preFlight'];
newPreFlight['renderFlight'] = combined_data[index]['renderPreFlight'];
combined_data.push(newPreFlight);
delete combined_data[index]['reaFlight']['TAID'];
newPreFlight['reaFlight'] = combined_data[index]['reaFlight'];
newPreFlight['renderFlight'] = combined_data[index]['renderReaFlight'];
combined_data.push(newReaFlight);
combined_data.splice(index, 1);
}
}
}
} else {
let newFlight = {};
newFlight['preFlight'] = message;
newFlight = this.flightsRenderTransfer(newFlight, col_lists);
newFlight = this.basicDataTransHandle(newFlight, airports, citys, airlines, flightStatus);
combined_data.push(newFlight);
}
//针对render_data的处理
let index1 = render_data.findIndex(element => {
if (this.orderHandle.isArriFlight(element) || this.orderHandle.isLinked(element)) {
if (element['preFlight']['FLID'] === message.FLID) {
return true;
} else {
return false;
}
} else {
return false;
}
})
if (index1 > -1) {
render_data[index1]['preFlight'] = message;
render_data[index1] = this.flightsRenderTransfer(render_data[index1], col_lists);
render_data[index1] = this.basicDataTransHandle(render_data[index1], airports, citys, airlines, flightStatus);
let is_satis = true;
for (const key in filterItems) {
if (filterItems.hasOwnProperty(key) && filterItems[key]) {
if (key === 'Abnormal_state') {
if (render_data[index1]['preFlight'][filterItems[key]]) {
is_satis = true;
continue;
} else {
is_satis = false;
break;
}
} else {
if (render_data[index1]['preFlight'][key] === filterItems[key]) {
is_satis = true;
continue;
} else {
is_satis = false;
break;
}
}
}
}
let search_satis = true;
if (LASTSEARCH) {
if (LAST_SEL_COL) {
if (render_data[index1]['preFlight'][LAST_SEL_COL]) {
if (render_data[index1]['preFlight'][LAST_SEL_COL].toString().match(new RegExp(LASTSEARCH, 'i'))) {
search_satis = true;
} else {
search_satis = false;
}
} else {
search_satis = false;
}
} else {
let cols = col_lists;
for (let i = 0; i < cols.length; i++) {
if (render_data[index1]['renderFlight'][cols[i]['COL_CODE']]) {
if (render_data[index1]['renderFlight'][cols[i]['COL_CODE']].toString().match(new RegExp(LASTSEARCH, 'i'))) {
search_satis = true;
break;
} else {
search_satis = false;
continue;
}
} else {
search_satis = false;
continue;
}
}
}
}
if (is_satis && search_satis) {
if (message.UPTP === 'FLOP-TAOP') {
if (this.orderHandle.isArriFlight(render_data[index1])) {
if (message.TAID) {
let i = render_data.findIndex(element => {
if (this.orderHandle.isDeptFlight(element)) {
if (message.TAID === element['reaFlight']['FLID']) {
return true;
} else {
return false;
}
} else {
return false;
}
})
if (i > -1) {
render_data.splice(index1, 1);
render_data[i]['reaFlight']['TAID'] = message.FLID;
let newFlight = {};
newFlight['preFlight'] = message;
newFlight['reaFlight'] = render_data[i]['reaFlight'];
render_data.splice(i, 1);
newFlight = this.flightsRenderTransfer(newFlight, col_lists);
newFlight = this.basicDataTransHandle(newFlight, airports, citys, airlines, flightStatus);
render_data.push(newFlight)
}
}
} else if (this.orderHandle.isLinked(render_data[index1])) {
if (!message.TAID) {
let newPreFlight = {},
newReaFlight = {};
delete render_data[index1]['preFlight']['TAID'];
newPreFlight['preFlight'] = render_data[index1]['preFlight'];
newPreFlight['renderFlight'] = render_data[index1]['renderPreFlight'];
delete render_data[index1]['reaFlight']['TAID'];
newPreFlight['reaFlight'] = render_data[index1]['reaFlight'];
newPreFlight['renderFlight'] = render_data[index1]['renderReaFlight'];
render_data.splice(index1, 1);
render_data.push(newPreFlight);
render_data.push(newReaFlight);
}
}
}
} else {
if (this.orderHandle.isArriFlight(render_data[index1])) {
render_data.splice(index1, 1);
} else if (this.orderHandle.isLinked(render_data[index1])) {
delete render_data[index1]['preFlight'];
delete render_data[index1]['renderPreFlight'];
render_data[index1] = this.flightsRenderTransfer(render_data[index1], col_lists);
render_data[index1] = this.basicDataTransHandle(render_data[index1], airports, citys, airlines, flightStatus);
}
}
} else {
let newFlight = {};
newFlight['preFlight'] = message;
newFlight = this.flightsRenderTransfer(newFlight, col_lists);
newFlight = this.basicDataTransHandle(newFlight, airports, citys, airlines, flightStatus);
let is_satis = true;
for (const key in filterItems) {
if (filterItems.hasOwnProperty(key) && filterItems[key]) {
if (key === 'Abnormal_state') {
if (newFlight['preFlight'][filterItems[key]]) {
is_satis = true;
continue;
} else {
is_satis = false;
break;
}
} else {
if (newFlight['preFlight'][key] === filterItems[key]) {
is_satis = true;
continue;
} else {
is_satis = false;
break;
}
}
}
}
let search_satis = true;
if (LASTSEARCH) {
if (LAST_SEL_COL) {
if (newFlight['preFlight'][LAST_SEL_COL]) {
if (newFlight['preFlight'][LAST_SEL_COL].toString().match(new RegExp(LASTSEARCH, 'i'))) {
search_satis = true;
} else {
search_satis = false;
}
} else {
search_satis = false;
}
} else {
let cols = col_lists;
for (let i = 0; i < cols.length; i++) {
if (newFlight['renderFlight'][cols[i]['COL_CODE']]) {
if (newFlight['renderFlight'][cols[i]['COL_CODE']].toString().match(new RegExp(LASTSEARCH, 'i'))) {
search_satis = true;
break;
} else {
search_satis = false;
continue;
}
} else {
search_satis = false;
continue;
}
}
}
}
if (is_satis && search_satis) {
let i = render_data.findIndex(element => {
if (this.orderHandle.isDeptFlight(element)) {
if (message.TAID === element['reaFlight']['FLID']) {
return true;
} else {
return false;
}
} else {
return false;
}
})
if (i > -1) {
let newFlight = {};
newFlight['preFlight'] = message;
newFlight['reaFlight'] = Object.assign({}, render_data[i]['reaFlight']);
render_data.splice(i, 1);
newFlight = this.flightsRenderTransfer(newFlight, col_lists);
newFlight = this.basicDataTransHandle(newFlight, airports, citys, airlines, flightStatus);
render_data.push(newFlight);
} else {
render_data.push(newFlight);
}
}
}
} else {
//针对combined_data的处理
let index = combined_data.findIndex(element => {
if (this.orderHandle.isDeptFlight(element) || this.orderHandle.isLinked(element)) {
if (element['reaFlight']['FLID'] === message.FLID) {
return true;
} else {
return false;
}
} else {
return false;
}
});
if (index > -1) {
combined_data[index]['reaFlight'] = message;
combined_data[index] = this.flightsRenderTransfer(combined_data[index], col_lists);
combined_data[index] = this.basicDataTransHandle(combined_data[index], airports, citys, airlines, flightStatus);
} else {
let newFlight = {};
newFlight['reaFlight'] = message;
newFlight = this.flightsRenderTransfer(newFlight, col_lists);
newFlight = this.basicDataTransHandle(newFlight, airports, citys, airlines, flightStatus);
combined_data.push(newFlight);
}
//针对render_data的处理
let index1 = render_data.findIndex(element => {
if (this.orderHandle.isDeptFlight(element) || this.orderHandle.isLinked(element)) {
if (element['reaFlight']['FLID'] === message.FLID) {
return true;
} else {
return false;
}
} else {
return false;
}
});
if (index1 > -1) {
render_data[index1]['reaFlight'] = message;
render_data[index1] = this.flightsRenderTransfer(render_data[index1], col_lists);
render_data[index1] = this.basicDataTransHandle(render_data[index1], airports, citys, airlines, flightStatus);
let is_satis = true;
for (const key in filterItems) {
if (filterItems.hasOwnProperty(key) && filterItems[key]) {
if (key === 'Abnormal_state') {
if (render_data[index1]['reaFlight'][filterItems[key]]) {
is_satis = true;
continue;
} else {
is_satis = false;
break;
}
} else {
if (render_data[index1]['reaFlight'][key] === filterItems[key]) {
is_satis = true;
continue;
} else {
is_satis = false;
break;
}
}
}
}
let search_satis = true;
if (LASTSEARCH) {
if (LAST_SEL_COL) {
if (render_data[index1]['reaFlight'][LAST_SEL_COL]) {
if (render_data[index1]['reaFlight'][LAST_SEL_COL].toString().match(new RegExp(LASTSEARCH, 'i'))) {
search_satis = true;
} else {
search_satis = false;
}
} else {
search_satis = false;
}
} else {
let cols = col_lists;
for (let i = 0; i < cols.length; i++) {
if (render_data[index1]['renderFlight'][cols[i]['COL_CODE']]) {
if (render_data[index1]['renderFlight'][cols[i]['COL_CODE']].toString().match(new RegExp(LASTSEARCH, 'i'))) {
search_satis = true;
break;
} else {
search_satis = false;
continue;
}
} else {
search_satis = false;
continue;
}
}
}
}
if (!is_satis || !search_satis) {
if (this.orderHandle.isDeptFlight(render_data[index1])) {
render_data.splice(index1, 1);
} else if (this.orderHandle.isLinked(render_data[index1])) {
delete render_data[index1]['reaFlight'];
delete render_data[index1]['renderReaFlight'];
render_data[index1] = this.flightsRenderTransfer(render_data[index1], col_lists);
render_data[index1] = this.basicDataTransHandle(render_data[index1], airports, citys, airlines, flightStatus);
}
}
} else {
let newFlight = {};
newFlight['reaFlight'] = message;
newFlight = this.flightsRenderTransfer(newFlight, col_lists);
newFlight = this.basicDataTransHandle(newFlight, airports, citys, airlines, flightStatus);
let is_satis = true;
for (const key in filterItems) {
if (filterItems.hasOwnProperty(key) && filterItems[key]) {
if (key === 'Abnormal_state') {
if (newFlight['reaFlight'][filterItems[key]]) {
is_satis = true;
continue;
} else {
is_satis = false;
break;
}
} else {
if (newFlight['reaFlight'][key] === filterItems[key]) {
is_satis = true;
continue;
} else {
is_satis = false;
break;
}
}
}
}
let search_satis = true;
if (LASTSEARCH) {
if (LAST_SEL_COL) {
if (newFlight['reaFlight'][LAST_SEL_COL]) {
if (newFlight['reaFlight'][LAST_SEL_COL].toString().match(new RegExp(LASTSEARCH, 'i'))) {
search_satis = true;
} else {
search_satis = false;
}
} else {
search_satis = false;
}
} else {
let cols = col_lists;
for (let i = 0; i < cols.length; i++) {
if (newFlight['renderFlight'][cols[i]['COL_CODE']]) {
if (newFlight['renderFlight'][cols[i]['COL_CODE']].toString().match(new RegExp(LASTSEARCH, 'i'))) {
search_satis = true;
break;
} else {
search_satis = false;
continue;
}
} else {
search_satis = false;
continue;
}
}
}
}
if (is_satis && search_satis) {
let i = render_data.findIndex(element => {
if (this.orderHandle.isArriFlight(element)) {
if (message.TAID === element['preFlight']['FLID']) {
return true;
} else {
return false;
}
} else {
return false;
}
})
if (i > -1) {
let newFlight = {};
newFlight['reaFlight'] = message;
newFlight['preFlight'] = Object.assign({}, render_data[i]['preFlight']);
render_data.splice(i, 1);
newFlight = this.flightsRenderTransfer(newFlight, col_lists);
newFlight = this.basicDataTransHandle(newFlight, airports, citys, airlines, flightStatus);
render_data.push(newFlight);
} else {
render_data.push(newFlight);
}
}
}
}
return {
'combined_data': combined_data,
'render_data': render_data
}
}
}