|
@@ -1,5 +1,6 @@
|
|
|
// 添加账本
|
|
|
import express from "express";
|
|
|
+import dayjs from "dayjs";
|
|
|
const router = express.Router();
|
|
|
import {
|
|
|
record_insert,
|
|
@@ -14,9 +15,16 @@ import {
|
|
|
getTypesById,
|
|
|
delFileByRecordId,
|
|
|
delByRecordId,
|
|
|
+ getMoreRecordsInfoByMonth,
|
|
|
+ getMoreRecordsInfoByTime,
|
|
|
} from "#db";
|
|
|
import { shanghaiTime, shanghaiTimeFormat } from "#utils";
|
|
|
-import { getTypeInfoFn,setFilesById,setFilesByRecord, getFileUrl } from './utils.js'
|
|
|
+import {
|
|
|
+ getTypeInfoFn,
|
|
|
+ setFilesById,
|
|
|
+ setFilesByRecord,
|
|
|
+ getFileUrl,
|
|
|
+} from "./utils.js";
|
|
|
|
|
|
// middleware that is specific to this router
|
|
|
router.use(function timeLog(req, res, next) {
|
|
@@ -24,7 +32,6 @@ router.use(function timeLog(req, res, next) {
|
|
|
next();
|
|
|
});
|
|
|
|
|
|
-
|
|
|
// 添加单个账单记录
|
|
|
router.post("/", async function (req, res) {
|
|
|
const {
|
|
@@ -52,8 +59,8 @@ router.post("/", async function (req, res) {
|
|
|
files,
|
|
|
insertId,
|
|
|
book_id,
|
|
|
- userInfo
|
|
|
- })
|
|
|
+ userInfo,
|
|
|
+ });
|
|
|
|
|
|
res.json({
|
|
|
code: 200,
|
|
@@ -106,15 +113,13 @@ router.put("/:record_id", async function (req, res) {
|
|
|
userInfo = {},
|
|
|
} = req.body;
|
|
|
|
|
|
-
|
|
|
// 更新附件信息
|
|
|
await setFilesById({
|
|
|
record_id,
|
|
|
userInfo,
|
|
|
book_id,
|
|
|
- files
|
|
|
- })
|
|
|
-
|
|
|
+ files,
|
|
|
+ });
|
|
|
|
|
|
// 更新类型
|
|
|
const typeId = await getTypeInfoFn({
|
|
@@ -148,15 +153,35 @@ router.get("/:book_id/:time", async function (req, res) {
|
|
|
const time = req.params.time; // 获取 fileId 参数
|
|
|
const book_id = req.params.book_id; // 获取 fileId 参数
|
|
|
const recordsInfoRes = await getRecordsInfoByTime(time, book_id);
|
|
|
+ const moreRecordsInfoRes = await getMoreRecordsInfoByTime(
|
|
|
+ time,
|
|
|
+ dayjs(time).date(),
|
|
|
+ book_id
|
|
|
+ );
|
|
|
+ console.log(157, moreRecordsInfoRes);
|
|
|
|
|
|
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),
|
|
|
- })),
|
|
|
+ data: recordsInfoRes
|
|
|
+ .map((elm) => ({
|
|
|
+ ...elm,
|
|
|
+ time: shanghaiTimeFormat(elm.time, "YYYY-MM-DD"),
|
|
|
+ create_time: shanghaiTimeFormat(elm.create_time),
|
|
|
+ update_time: shanghaiTimeFormat(elm.update_time),
|
|
|
+ }))
|
|
|
+ .concat(
|
|
|
+ moreRecordsInfoRes.map((elm) => {
|
|
|
+ return {
|
|
|
+ ...elm,
|
|
|
+ time: shanghaiTimeFormat(`${time}-${elm.log_day}`, "YYYY-MM-DD"),
|
|
|
+ create_time: shanghaiTimeFormat(elm.create_time),
|
|
|
+ update_time: shanghaiTimeFormat(elm.update_time),
|
|
|
+ };
|
|
|
+ })
|
|
|
+ )
|
|
|
+ .sort(
|
|
|
+ (a, b) => dayjs(b.update_time).unix() - dayjs(a.update_time).unix()
|
|
|
+ ),
|
|
|
});
|
|
|
});
|
|
|
|
|
@@ -165,15 +190,28 @@ router.get("/:book_id/m/:time", async function (req, res) {
|
|
|
const time = req.params.time; // 获取 fileId 参数
|
|
|
const book_id = req.params.book_id; // 获取 fileId 参数
|
|
|
const recordsInfoRes = await getRecordsInfoByMonth(time, book_id);
|
|
|
+ const moreRecordsInfoRes = await getMoreRecordsInfoByMonth(time, book_id);
|
|
|
|
|
|
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),
|
|
|
- })),
|
|
|
+ data: recordsInfoRes
|
|
|
+ .map((elm) => ({
|
|
|
+ ...elm,
|
|
|
+ time: shanghaiTimeFormat(elm.time, "YYYY-MM-DD"),
|
|
|
+ create_time: shanghaiTimeFormat(elm.create_time),
|
|
|
+ update_time: shanghaiTimeFormat(elm.update_time),
|
|
|
+ }))
|
|
|
+ .concat(
|
|
|
+ moreRecordsInfoRes.map((elm) => {
|
|
|
+ return {
|
|
|
+ ...elm,
|
|
|
+ time: shanghaiTimeFormat(`${time}-${elm.log_day}`, "YYYY-MM-DD"),
|
|
|
+ create_time: shanghaiTimeFormat(elm.create_time),
|
|
|
+ update_time: shanghaiTimeFormat(elm.update_time),
|
|
|
+ };
|
|
|
+ })
|
|
|
+ )
|
|
|
+ .sort((a, b) => dayjs(a.time).unix() - dayjs(b.time).unix()),
|
|
|
});
|
|
|
});
|
|
|
|
|
@@ -187,9 +225,7 @@ router.delete("/:record_id", async function (req, res) {
|
|
|
const getAllfiles = await getFileByRecordId(record_id);
|
|
|
if (getAllfiles.length) {
|
|
|
await Promise.all(
|
|
|
- getAllfiles.map((elm) =>
|
|
|
- delFileByRecordId(record_id, elm.file_id)
|
|
|
- )
|
|
|
+ getAllfiles.map((elm) => delFileByRecordId(record_id, elm.file_id))
|
|
|
);
|
|
|
}
|
|
|
|
|
@@ -198,7 +234,7 @@ router.delete("/:record_id", async function (req, res) {
|
|
|
|
|
|
res.json({
|
|
|
code: 200,
|
|
|
- data: '',
|
|
|
+ data: "",
|
|
|
});
|
|
|
});
|
|
|
export default router;
|