-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp_func.js
More file actions
186 lines (161 loc) · 4.86 KB
/
app_func.js
File metadata and controls
186 lines (161 loc) · 4.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
var createError = require('http-errors');
var express = require('express');
var path = require('path');
var logger = require('morgan');
var cors = require('cors');
var dotenv = require('dotenv');
// var sequelize = require('sequelize');
let deliveryService = require('./services/deliveryService');
const { time } = require('console');
function self_door_open() {
console.log('func: self_door_open');
}
function itempush(goal) {
console.log('func: itempush');
}
function self_door_close() {
console.log('func: self_door_close');
}
function human_door_open() {
console.log('func: human_door_open');
}
function human_door_close() {
console.log('func: human_door_close');
}
function destination_middle() {
console.log('destination_middle');
}
function destination_final() {
console.log('destination_final');
}
function destination_start() {
console.log('destination_start');
}
async function middleArrive() {
let id = await deliveryService.findDelivery('접수지로 출발');
console.log('currentId', id);
await deliveryService.changeStatus(id, '접수지 도착');
}
let timeOut = true;
// 도착 신호 받으면 실행되는 함수
async function finalArrive() {
let id = await deliveryService.findDelivery('배송 출발');
await deliveryService.changeStatus(id, '배송지 도착');
let isPerson = await deliveryService.findDeliveryPerson(id);
if (isPerson) {
timeOut = true;
console.log('직접 수령인 경우');
console.log(currentId);
setTimeout(function () {
if (timeOut) {
console.log('timeout, 직접 수령 불가');
self_door_open();
setTimeout(function () {
itempush();
}, 1000 * 3);
setTimeout(function () {
self_door_close();
}, 1000 * 4);
setTimeout(async function () {
let id = await deliveryService.findDelivery('배송지 도착');
await deliveryService.changeStatus(id, '배송 완료');
destination_start();
}, 1000 * 6);
}
}, 1000 * 30);
} else {
console.log('두고 가기인 경우');
self_door_open();
setTimeout(function () {
itempush();
}, 1000 * 2);
setTimeout(function () {
self_door_close();
}, 1000 * 4);
setTimeout(async function () {
let id = await deliveryService.findDelivery('배송지 도착');
await deliveryService.changeStatus(id, '배송 완료');
destination_start();
}, 1000 * 6);
}
}
function test() {
console.log('This is test!');
}
var app = express();
let currentId = 0;
let currentDelivery = null;
let currentStatus = 0; // 0이면 대기 중, 1이면 사용 중
const corsOptions = {
origin: '*',
credentials: true,
};
app.use(cors(corsOptions));
app.get('/arrive', async function (req, res) {
console.log('arrive start');
finalArrive();
});
app.get('/index.html', (req, res) => {
test();
res.send('hello');
});
app.get('/start/:id', async function (req, res) {
try {
let id = req.params.id;
timeOut = true;
await deliveryService.changeStatus(id, '접수지로 출발');
console.log('start');
destination_middle();
console.log(currentDelivery);
res.send('start success');
} catch (err) {
console.log(err);
res.send('start error');
}
});
app.get('/useropen', async function (req, res) {
console.log('직접 수령 시도');
try {
res.send('open start');
timeOut = false;
human_door_open();
setTimeout(function () {
human_door_close();
}, 1000 * 2);
setTimeout(async function () {
let id = await deliveryService.findDelivery('배송지 도착');
await deliveryService.changeStatus(id, '배송 완료');
destination_start();
open = false;
}, 1000 * 4);
} catch (err) {
console.log(err);
}
});
app.get('/middleArrive', async function (req, res) {
console.log('middlestart');
middleArrive();
});
app.get('/test', async function (req, res) {
console.log('test');
res.send('test');
});
app.get('/adminopen', async function (req, res) {
human_door_open();
res.send(true);
});
app.get('/adminclose', async function (req, res) {
human_door_close();
res.send(true);
});
app.get('/adminstart/:id', async function (req, res) {
let id = req.params.id;
await deliveryService.changeStatus(id, '배송 출발');
destination_final();
res.send(true);
});
// setInterval(async function () {
// // currentDelivery = await deliveryService.findDelivery();
// // currentId = currentDelivery[0].id;
// }, 1000);
module.exports = app;