Toggle navigation
Toggle navigation
This project
Loading...
Sign in
2021-1-capstone-design1
/
RIT_Project1
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
1
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
박권수
2021-09-14 20:24:52 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
8619f4bcf06c333a1669c6b33dcec667f623b372
8619f4bc
1 parent
0fc0bca5
feat. Batch System Apply
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
101 additions
and
6 deletions
server/index.js
server/src/util/Batch.js
server/index.js
View file @
8619f4b
const
Koa
=
require
(
'koa'
);
const
cors
=
require
(
'@koa/cors'
);
const
Router
=
require
(
'koa-router'
);
const
cors
=
require
(
'@koa/cors'
);
const
bodyparser
=
require
(
'koa-bodyparser'
);
const
Mongoose
=
require
(
'mongoose'
);
const
api
=
require
(
'./src/api'
);
const
updateMedicineInfo
=
require
(
'./src/lib/UpdatingMedicineInfo'
);
const
MqttServer
=
require
(
'./src/util/MqttServer'
);
const
BatchSystem
=
require
(
'./src/util/Batch'
);
require
(
'dotenv'
).
config
();
// eslint-disable-next-line no-undef
...
...
@@ -26,7 +28,7 @@ Mongoose.connect(MONGO_URL, {
// updateMedicineInfo.updateMedicineInfo();
}).
catch
(
e
=>
{
console
.
log
(
e
);
})
})
;
app
.
use
(
bodyparser
());
router
.
use
(
'/api'
,
api
.
routes
());
...
...
@@ -36,4 +38,6 @@ app.use(router.routes()).use(router.allowedMethods());
app
.
listen
(
SERVER_PORT
,
()
=>
{
console
.
log
(
'\x1b[1;36mPORT : '
,
SERVER_PORT
,
'is connected\x1b[0m'
);
MqttServer
.
on
();
})
\ No newline at end of file
BatchSystem
.
CheckNewYear
();
BatchSystem
.
PushNotifyByDosage
();
});
\ No newline at end of file
...
...
server/src/util/Batch.js
View file @
8619f4b
...
...
@@ -7,7 +7,98 @@
* 2) Dosage에 따라, Push Notification 발송
*/
const
cron
=
require
(
'node-cron'
);
const
cron
=
require
(
'node-cron'
);
const
Profile
=
require
(
'../models/profile'
);
const
User
=
require
(
'../models/user'
);
const
Hub
=
require
(
'../models/hub'
);
const
Bottle
=
require
(
'../models/bottle'
);
const
BottleMedicine
=
require
(
'../models/bottleMedicine'
);
//매년 1월 1일 00시 00분에 1살씩 추가
exports
.
CheckNewYear
=
()
=>
{
cron
.
schedule
(
'0 0 0 1 1 *'
,
async
()
=>
{
const
profileList
=
await
Profile
.
find
();
profileList
.
forEach
(
async
profile
=>
{
await
profile
.
updateUserAge
();
profile
.
save
();
});
},
{
timezone
:
'Asia/Tokyo'
,
});
};
//dosage에 따라, Push Notification을 발송한다.
//아침 8시, 점심 12시, 저녁 6시에 한번씩 발송
exports
.
PushNotifyByDosage
=
async
()
=>
{
//매일 아침 8시 : 복용량 상관 없이 보냄
cron
.
schedule
(
'0 0 8 * * *'
,
async
()
=>
{
const
bottleMedicineList
=
await
BottleMedicine
.
find
({
useYn
:
'Y'
,
dosage
:
{
$gte
:
1
}
});
bottleMedicineList
.
forEach
(
async
bottleMedicine
=>
{
const
bottle
=
await
Bottle
.
findOne
({
bottleId
:
bottleMedicine
.
bottleId
});
const
hub
=
await
Hub
.
findOne
({
hubId
:
bottle
.
hubId
});
const
user
=
await
User
.
findOne
({
userId
:
hub
.
userId
,
useYn
:
'Y'
});
if
(
user
)
{
const
profile
=
await
Profile
.
findOne
({
userId
:
user
.
userId
});
const
{
deviceToken
}
=
profile
;
PushNotify
(
deviceToken
);
}
});
},
{
timezone
:
'Asia/Tokyo'
,
});
//매일 점심 12시 : 복용량이 3인 환자들만
cron
.
schedule
(
'0 0 12 * * *'
,
async
()
=>
{
const
bottleMedicineList
=
await
BottleMedicine
.
find
({
useYn
:
'Y'
,
dosage
:
{
$gte
:
3
}
});
bottleMedicineList
.
forEach
(
async
bottleMedicine
=>
{
const
bottle
=
await
Bottle
.
findOne
({
bottleId
:
bottleMedicine
.
bottleId
});
const
hub
=
await
Hub
.
findOne
({
hubId
:
bottle
.
hubId
});
const
user
=
await
User
.
findOne
({
userId
:
hub
.
userId
,
useYn
:
'Y'
});
if
(
user
)
{
const
profile
=
await
Profile
.
findOne
({
userId
:
user
.
userId
});
const
{
deviceToken
}
=
profile
;
PushNotify
(
deviceToken
);
}
});
},
{
timezone
:
'Asia/Tokyo'
,
});
//매일 저녁 6시
cron
.
schedule
(
'0 0 18 * * *'
,
async
()
=>
{
const
bottleMedicineList
=
await
BottleMedicine
.
find
({
useYn
:
'Y'
,
dosage
:
{
$gte
:
2
}
});
bottleMedicineList
.
forEach
(
async
bottleMedicine
=>
{
const
bottle
=
await
Bottle
.
findOne
({
bottleId
:
bottleMedicine
.
bottleId
});
const
hub
=
await
Hub
.
findOne
({
hubId
:
bottle
.
hubId
});
const
user
=
await
User
.
findOne
({
userId
:
hub
.
userId
,
useYn
:
'Y'
});
if
(
user
)
{
const
profile
=
await
Profile
.
findOne
({
userId
:
user
.
userId
});
const
{
deviceToken
}
=
profile
;
PushNotify
(
deviceToken
);
}
});
},
{
timezone
:
'Asia/Tokyo'
,
});
};
const
PushNotify
=
async
(
deviceToken
)
=>
{
//toDo : deviceToken을 받아서 push notification을 발송하는 함수
if
(
deviceToken
)
{
console
.
log
(
deviceToken
);
}
};
\ No newline at end of file
const
Profile
=
require
(
'../models/profile'
);
const
BottleMedicine
=
require
(
'../models/bottleMedicine'
);
\ No newline at end of file
...
...
Please
register
or
login
to post a comment