|
@@ -5,9 +5,13 @@ import {
|
|
|
record_insert,
|
|
|
isType,
|
|
|
type_insert,
|
|
|
- getRecordInfoById
|
|
|
+ getRecordInfoById,
|
|
|
+ addFileByRecordId,
|
|
|
+ getFileByRecordId,
|
|
|
+ getRecordsInfoByTime
|
|
|
} from "#db";
|
|
|
-import {shanghaiTime} from '#utils'
|
|
|
+import {shanghaiTime, shanghaiTimeFormat} from '#utils'
|
|
|
+import dayjs from "dayjs";
|
|
|
|
|
|
// middleware that is specific to this router
|
|
|
router.use(function timeLog(req, res, next) {
|
|
@@ -21,6 +25,7 @@ router.post("/", async function (req, res) {
|
|
|
book_id = "",
|
|
|
total_fee = 0,
|
|
|
type = "",
|
|
|
+ time = "",
|
|
|
remark = "",
|
|
|
files = [],
|
|
|
userInfo = {},
|
|
@@ -28,21 +33,21 @@ router.post("/", async function (req, res) {
|
|
|
// type 是否存在重复项,有就返回id,没有就新增 再返回id
|
|
|
const isAddType = await isType({
|
|
|
book_id,
|
|
|
- user_id: userInfo.user_id,
|
|
|
+ author_id: userInfo.user_id,
|
|
|
type,
|
|
|
});
|
|
|
let typeInfo = {};
|
|
|
if (!isAddType) {
|
|
|
await type_insert({
|
|
|
book_id,
|
|
|
- user_id: userInfo.user_id,
|
|
|
+ author_id: userInfo.user_id,
|
|
|
type,
|
|
|
create_time: shanghaiTime().format("YYYY-MM-DD HH:mm:ss"),
|
|
|
update_time: shanghaiTime().format("YYYY-MM-DD HH:mm:ss"),
|
|
|
});
|
|
|
typeInfo = await isType({
|
|
|
book_id,
|
|
|
- user_id: userInfo.user_id,
|
|
|
+ author_id: userInfo.user_id,
|
|
|
type,
|
|
|
});
|
|
|
} else {
|
|
@@ -63,10 +68,25 @@ router.post("/", async function (req, res) {
|
|
|
author_id: userInfo.user_id,
|
|
|
total_fee,
|
|
|
remark,
|
|
|
+ time: shanghaiTimeFormat(time),
|
|
|
create_time: shanghaiTime().format("YYYY-MM-DD HH:mm:ss"),
|
|
|
update_time: shanghaiTime().format("YYYY-MM-DD HH:mm:ss"),
|
|
|
});
|
|
|
|
|
|
+ console.log(7171, userInfo);
|
|
|
+
|
|
|
+
|
|
|
+ const filesRes = await Promise.all(files.map((file_id) => addFileByRecordId({
|
|
|
+ file_id,
|
|
|
+ record_id: insertId,
|
|
|
+ book_id,
|
|
|
+ author_id: userInfo.user_id,
|
|
|
+ create_time: shanghaiTime().format("YYYY-MM-DD HH:mm:ss"),
|
|
|
+ update_time: shanghaiTime().format("YYYY-MM-DD HH:mm:ss"),
|
|
|
+ })))
|
|
|
+
|
|
|
+ console.log(82, filesRes);
|
|
|
+
|
|
|
res.json({
|
|
|
code: 200,
|
|
|
data: {
|
|
@@ -75,6 +95,23 @@ router.post("/", async function (req, res) {
|
|
|
});
|
|
|
});
|
|
|
|
|
|
+// define the home page route
|
|
|
+router.get("/:record_id", async function (req, res) {
|
|
|
+ const record_id = req.params.record_id; // 获取 fileId 参数
|
|
|
+ const recordInfo = await getRecordInfoById(record_id)
|
|
|
+ const files = await getFileByRecordId(record_id)
|
|
|
+ res.json({
|
|
|
+ code: 200,
|
|
|
+ data: {
|
|
|
+ ...recordInfo,
|
|
|
+ "time": shanghaiTimeFormat(recordInfo.time, 'YYYY-MM-DD'),
|
|
|
+ "create_time": shanghaiTimeFormat(recordInfo.create_time),
|
|
|
+ "update_time": shanghaiTimeFormat(recordInfo.update_time),
|
|
|
+ files: files.map(elm =>`http://127.0.0.1:3000/api/v1/files/${elm.file_id}`)
|
|
|
+ }
|
|
|
+ });
|
|
|
+});
|
|
|
+
|
|
|
// define the home page route
|
|
|
router.get("/:record_id", async function (req, res) {
|
|
|
const record_id = req.params.record_id; // 获取 fileId 参数
|
|
@@ -90,4 +127,22 @@ router.get("/about", function (req, res) {
|
|
|
res.send("About record");
|
|
|
});
|
|
|
|
|
|
+// 根据日期获取数据
|
|
|
+router.get("/:book_id/:time", async function (req, res) {
|
|
|
+ console.log(13423);
|
|
|
+ const time = req.params.time; // 获取 fileId 参数
|
|
|
+ const book_id = req.params.book_id; // 获取 fileId 参数
|
|
|
+ const recordsInfoRes = await getRecordsInfoByTime(time, book_id);
|
|
|
+ console.log(136, recordsInfoRes);
|
|
|
+
|
|
|
+ res.json({
|
|
|
+ code: 200,
|
|
|
+ data: recordsInfoRes.map(elm => ({
|
|
|
+ ...elm,
|
|
|
+ "time": shanghaiTimeFormat(elm.time, 'YYYY-MM-DD'),
|
|
|
+ "create_time": shanghaiTimeFormat(elm.create_time),
|
|
|
+ "update_time": shanghaiTimeFormat(elm.update_time),
|
|
|
+ }))
|
|
|
+ });
|
|
|
+});
|
|
|
export default router;
|