From 6a24be086423f24f083e71f18e1094dc4eff0824 Mon Sep 17 00:00:00 2001 From: oneao Date: Tue, 9 Dec 2025 22:00:35 +0800 Subject: [PATCH] u --- .../(tabs)/money/components/ActionsMenu.tsx | 79 ++++++ .../money/components/TransactionsList.tsx | 77 +++--- .../base-app/src/app/(tabs)/money/index.tsx | 46 +++- .../base-project/base-app/src/app/_layout.tsx | 29 +- .../base-app/src/app/auth/login.tsx | 9 +- .../src/app/money/record/detail/index.tsx | 60 ++-- .../record/editor/components/CategoryGrid.tsx | 10 +- .../src/app/money/record/editor/index.tsx | 6 + .../src/app/system/settings/index.tsx | 14 +- .../src/components/common/ao/ListItem.tsx | 50 ++++ .../src/components/common/ao/index.ts | 2 + .../base-app/src/request/index.ts | 5 +- code/base-project/base-app/src/store/app.ts | 60 ++++ .../base-app/src/store/moneyCategory.ts | 11 +- .../base-app/src/store/moneyRecord.ts | 25 +- code/base-project/base-app/src/store/space.ts | 6 + code/base-project/base-app/src/store/user.ts | 4 +- .../base-app/src/types/money/record.ts | 1 + code/base-project/base-app/test.html | 260 +++++++----------- .../biz/handler/money/money_record_service.go | 16 +- .../base-go-v3/biz/model/api/api.pb.go | 2 +- .../base-go-v3/biz/model/money/money.pb.go | 2 +- .../model/money/money_category_types.pb.go | 2 +- .../biz/model/money/money_record_types.pb.go | 146 +++++----- .../base-go-v3/biz/router/middleware/auth.go | 4 +- .../base-go-v3/biz/router/middleware/jwt.go | 100 ------- .../base-go-v3/db/queries/space.sql | 3 +- .../idl/money/money_record_types.proto | 1 + 28 files changed, 572 insertions(+), 458 deletions(-) create mode 100644 code/base-project/base-app/src/app/(tabs)/money/components/ActionsMenu.tsx create mode 100644 code/base-project/base-app/src/components/common/ao/ListItem.tsx create mode 100644 code/base-project/base-app/src/store/app.ts delete mode 100644 code/base-project/base-go-v3/biz/router/middleware/jwt.go diff --git a/code/base-project/base-app/src/app/(tabs)/money/components/ActionsMenu.tsx b/code/base-project/base-app/src/app/(tabs)/money/components/ActionsMenu.tsx new file mode 100644 index 00000000..e3b93f7e --- /dev/null +++ b/code/base-project/base-app/src/app/(tabs)/money/components/ActionsMenu.tsx @@ -0,0 +1,79 @@ +import { Image, Text, View } from 'react-native' +import { useSafeAreaInsets } from 'react-native-safe-area-context' +import { AListItem, LucideIcon } from '@/components/common/ao' +import { + Drawer, + DrawerBackdrop, + DrawerBody, + DrawerContent, + DrawerHeader, +} from '@/components/ui/drawer' + +interface ActionsMenuProps { + isOpen?: boolean + onClose?: () => void +} + +export default function ActionsMenu({ + isOpen = false, + onClose, +}: ActionsMenuProps) { + const safeAreaInsets = useSafeAreaInsets() + + return ( + + + + + + + + + 常用菜单 + + + + + + + + 常用菜单 + + + + + + + + + + + ) +} diff --git a/code/base-project/base-app/src/app/(tabs)/money/components/TransactionsList.tsx b/code/base-project/base-app/src/app/(tabs)/money/components/TransactionsList.tsx index 3a0eae9b..173ce458 100644 --- a/code/base-project/base-app/src/app/(tabs)/money/components/TransactionsList.tsx +++ b/code/base-project/base-app/src/app/(tabs)/money/components/TransactionsList.tsx @@ -11,7 +11,6 @@ import { import { LucideIcon } from '@/components/common/ao' import EmptyState from '@/components/common/EmptyStatus' import MoneyCategoryIcon from '@/components/common/MoneyCategoryIcon' -import { useMoneyCategoryStore } from '@/store/moneyCategory' import { useUserStore } from '@/store/user' interface StaticTransactionsProps { @@ -119,7 +118,7 @@ export default function StaticTransactions({ )} - renderItem={({ item, index }) => { + renderItem={({ item }) => { return ( - { - onUpdate?.(item) - }} - > - - - 更新 - - - { - onDelete?.(item.id) - }} - > - - - 删除 - - + { + userID === item.user_id && ( + <> + { + onUpdate?.(item) + }} + > + + + 更新 + + + { + onDelete?.(item.id) + }} + > + + + 删除 + + + + ) + } { if (res.isSuccess) { - moneyRecordStore.setRecords(res.data.records, res.data.total_expense, res.data.total_income, searchParams.record_time) - - console.log(res.data.records) + moneyRecordStore.setRecords(res.data.records, res.data.total_expense, res.data.total_income, res.data.total_balance, searchParams.record_time, + ) } else { toast.show({ @@ -44,8 +48,10 @@ export default function Money() { } useEffect(() => { + if (!appStore.ready) + return getMoneyRecords() - }, [searchParams]) + }, [appStore.ready, searchParams]) return ( @@ -64,19 +70,30 @@ export default function Money() { onPress={() => setShowDatePicker(true)} className="flex flex-row items-center gap-1" > - {searchParams.record_time} + {searchParams.record_time} { + setShowActionsMenu(true) + }} > - - + + 收入 - 0.00 + {moneyRecordStore.total_balance} - 点击设置 - + */} @@ -177,6 +194,13 @@ export default function Money() { setShowDatePicker(false) }} /> + + { + setShowActionsMenu(false) + }} + /> ) } diff --git a/code/base-project/base-app/src/app/_layout.tsx b/code/base-project/base-app/src/app/_layout.tsx index 18a0440a..355cb3a6 100644 --- a/code/base-project/base-app/src/app/_layout.tsx +++ b/code/base-project/base-app/src/app/_layout.tsx @@ -1,7 +1,7 @@ import type { ErrorBoundaryProps } from 'expo-router' import { ToastProvider } from '@gluestack-ui/core/toast/creator' import { useFonts } from 'expo-font' -import { Stack, usePathname, useRouter } from 'expo-router' +import { Stack, usePathname } from 'expo-router' import * as SplashScreen from 'expo-splash-screen' import { StatusBar } from 'expo-status-bar' import { useEffect } from 'react' @@ -11,11 +11,8 @@ import { MenuProvider } from 'react-native-popup-menu' import { AButton } from '@/components/common/ao' import EmptyState from '@/components/common/EmptyStatus' import { GluestackUIProvider } from '@/components/ui/gluestack-ui-provider' -import { getUserSpaceApi } from '@/request/api/space/spaceUser' -import { useMoneyCategoryStore } from '@/store/moneyCategory' +import { useAppStore } from '@/store/app' import { useNavStore } from '@/store/navigation' -import { useSpaceStore } from '@/store/space' -import { useUserStore } from '@/store/user' import { ToastProviderWrapper } from '@/utils/toast' import '@/styles/global.css' import 'react-native-reanimated' @@ -44,13 +41,10 @@ export function ErrorBoundary({ error, retry }: ErrorBoundaryProps) { } export default function RootLayout() { - const router = useRouter() const pathname = usePathname() - const userStore = useUserStore() - const spaceStore = useSpaceStore() - const moneyCategoryStore = useMoneyCategoryStore() const navStore = useNavStore() + const appStore = useAppStore() const [fontsLoaded] = useFonts({ SpaceMono: require('@/static/fonts/SpaceMono-Regular.ttf'), @@ -64,22 +58,9 @@ export default function RootLayout() { if (!fontsLoaded) return - // 登录跳转 - if (!userStore.isLoggedIn()) { - navStore.navigateToAuth() - } - - // 如果登录的话,就初始化下 - moneyCategoryStore.init() - - getUserSpaceApi({}).then((res) => { - spaceStore.setUserSpace(res.data) - }).catch((err) => { - console.log(err) + appStore.init().finally(() => { + SplashScreen.hideAsync() }) - - // 隐藏 splash - SplashScreen.hideAsync() }, [fontsLoaded]) return ( diff --git a/code/base-project/base-app/src/app/auth/login.tsx b/code/base-project/base-app/src/app/auth/login.tsx index bb84d9be..8578e399 100644 --- a/code/base-project/base-app/src/app/auth/login.tsx +++ b/code/base-project/base-app/src/app/auth/login.tsx @@ -7,7 +7,7 @@ import { IconQq, IconWeixin, IconZhiwen } from '@/components/iconfont' import { Divider } from '@/components/ui/divider' import useFormValidation from '@/hooks/useFormValidation' import { loginDefaultApi } from '@/request/api/auth' -import { useMoneyCategoryStore } from '@/store/moneyCategory' +import { useAppStore } from '@/store/app' import { useUserStore } from '@/store/user' import { toast } from '@/utils/toast' @@ -21,7 +21,7 @@ interface LoginForm { export default function AuthLogin() { const router = useRouter() const userStore = useUserStore() - const moneyCategoryStore = useMoneyCategoryStore() + const appStore = useAppStore() const [loading, setLoading] = useState(false) const [form, setForm] = useState({ @@ -62,9 +62,10 @@ export default function AuthLogin() { refreshToken: res.data.refreshToken, rememberMe: form.rememberMe, }) - moneyCategoryStore.init() - router.replace('/user') + appStore.init() + + router.replace('/money') } else { toast.show({ diff --git a/code/base-project/base-app/src/app/money/record/detail/index.tsx b/code/base-project/base-app/src/app/money/record/detail/index.tsx index 53db9cd4..4c35c6de 100644 --- a/code/base-project/base-app/src/app/money/record/detail/index.tsx +++ b/code/base-project/base-app/src/app/money/record/detail/index.tsx @@ -5,11 +5,13 @@ import { AButton, ACell, ACellGroup, AModal } from '@/components/common/ao' import MoneyCategoryIcon from '@/components/common/MoneyCategoryIcon' import CustomHeader from '@/components/custom/Header' import { useMoneyRecordStore } from '@/store/moneyRecord' +import { useUserStore } from '@/store/user' import { toDateString, toDateTimeString } from '@/utils/time' export default function MoneyRecordDetail() { const router = useRouter() const moneyRecordStore = useMoneyRecordStore() + const userStore = useUserStore() const { id: detailId } = useLocalSearchParams<{ id: string }>() const moneryRecord = moneyRecordStore.getMoneyRecordById(Number(detailId)) @@ -36,31 +38,43 @@ export default function MoneyRecordDetail() { + - - { - setShowDeleteModal(true) - }} - > - 删除 - - { - router.navigate({ - pathname: '/money/record/editor', - params: { id: detailId }, - }) - }} - > - 编辑 - - + {userStore.userInfo?.id === moneryRecord.user_id && ( + + + { + setShowDeleteModal(true) + }} + > + 删除 + + { + router.navigate({ + pathname: '/money/record/editor', + params: { id: detailId }, + }) + }} + > + 编辑 + + + )} + diff --git a/code/base-project/base-app/src/app/money/record/editor/components/CategoryGrid.tsx b/code/base-project/base-app/src/app/money/record/editor/components/CategoryGrid.tsx index e34e8205..b5559a23 100644 --- a/code/base-project/base-app/src/app/money/record/editor/components/CategoryGrid.tsx +++ b/code/base-project/base-app/src/app/money/record/editor/components/CategoryGrid.tsx @@ -61,10 +61,16 @@ export default function CategoryGrid({ marginTop: 4, justifyContent: 'center', alignItems: 'center', - backgroundColor: isSelected ? '#BFDBFE' : '#F3F4F6', + backgroundColor: isSelected ? '#333' : '#F3F4F6', }} > - + - + ) } diff --git a/code/base-project/base-app/src/components/common/ao/ListItem.tsx b/code/base-project/base-app/src/components/common/ao/ListItem.tsx new file mode 100644 index 00000000..1d42f27e --- /dev/null +++ b/code/base-project/base-app/src/components/common/ao/ListItem.tsx @@ -0,0 +1,50 @@ +import type { icons } from 'lucide-react-native' +import { useRouter } from 'expo-router' +import { Text, TouchableOpacity } from 'react-native' +import LucideIcon from './LucideIcon' + +export interface ListItemProps { + icon: keyof typeof icons + text: string + href?: string + onPress?: () => void + showRightIcon?: boolean +} + +export default function ListItem({ icon, text, href, onPress, showRightIcon = false }: ListItemProps) { + const router = useRouter() + + const handlePress = () => { + if (onPress) { + onPress() + return + } + + if (href) { + router.navigate(href) + } + } + + return ( + + + + {text} + + { + showRightIcon && ( + + ) + } + + ) +} diff --git a/code/base-project/base-app/src/components/common/ao/index.ts b/code/base-project/base-app/src/components/common/ao/index.ts index 6939a3b0..53627787 100644 --- a/code/base-project/base-app/src/components/common/ao/index.ts +++ b/code/base-project/base-app/src/components/common/ao/index.ts @@ -6,6 +6,7 @@ import Divider from './Divider' import Form, { FormRef } from './Form' import FormItem from './FormItem' import Input from './Input' +import ListItem from './ListItem' import LucideIcon from './LucideIcon' import Modal from './Modal' import SegmentedTabs from './SegmentedTabs' @@ -22,6 +23,7 @@ export { FormItem as AFormItem, FormRef as AFormRef, Input as AInput, + ListItem as AListItem, Modal as AModal, SegmentedTabs as ASegmentedTabs, Tab as ATab, diff --git a/code/base-project/base-app/src/request/index.ts b/code/base-project/base-app/src/request/index.ts index 70db1f04..651ef3d0 100644 --- a/code/base-project/base-app/src/request/index.ts +++ b/code/base-project/base-app/src/request/index.ts @@ -32,8 +32,8 @@ function isWhiteListed(url: string) { } const alovaInstance = createAlova({ - // baseURL: 'http://192.168.5.6:8086/app', - baseURL: 'http://192.168.1.136:8086/app', + baseURL: 'http://192.168.5.6:8086/app', + // baseURL: 'http://192.168.1.136:8086/app', requestAdapter: axiosRequestAdapter(), timeout: 5000, cacheFor: null, @@ -154,6 +154,7 @@ const alovaInstance = createAlova({ const userSpace = useSpaceStore.getState().userSpace if (userSpace !== null) { const spaceID = userSpace.space_id + method.config.headers['x-space-id'] = spaceID } }, diff --git a/code/base-project/base-app/src/store/app.ts b/code/base-project/base-app/src/store/app.ts new file mode 100644 index 00000000..8f466252 --- /dev/null +++ b/code/base-project/base-app/src/store/app.ts @@ -0,0 +1,60 @@ +import { create } from 'zustand' +import { getUserSpaceApi } from '@/request/api/space/spaceUser' +import { useMoneyCategoryStore } from './moneyCategory' +import { useNavStore } from './navigation' +import { useSpaceStore } from './space' +import { useUserStore } from './user' + +interface AppState { + ready: boolean + setReady: (v: boolean) => void + init: () => Promise + reset: () => void +} + +export const useAppStore = create((set, get) => ({ + ready: false, + + setReady: (v: boolean) => set({ ready: v }), + + init: async () => { + // 如果已经初始化过就不重复执行(除非你手动 setReady(false) 再 init) + if (get().ready) + return + + const userStore = useUserStore.getState() + const navStore = useNavStore.getState() + const moneyCategoryStore = useMoneyCategoryStore.getState() + const spaceStore = useSpaceStore.getState() + + // 未登录:跳转到登录页,但认为初始化已完成(允许 UI 继续渲染) + if (!userStore.isLoggedIn()) { + navStore.navigateToAuth() + set({ ready: true }) + return + } + + // 登录状态:执行完整初始化流程 + try { + // 分类初始化 + await moneyCategoryStore.init() + + // 获取空间信息 + const res = await getUserSpaceApi({}) + spaceStore.setUserSpace(res.data) + } + catch (err) { + console.error('app init error:', err) + } + + // 初始化完成 + set({ ready: true }) + }, + reset: () => { + set({ ready: false }) + + useMoneyCategoryStore.getState().clear() + useUserStore.getState().clear() + useSpaceStore.getState().clear() + }, +})) diff --git a/code/base-project/base-app/src/store/moneyCategory.ts b/code/base-project/base-app/src/store/moneyCategory.ts index c61ce810..379077a2 100644 --- a/code/base-project/base-app/src/store/moneyCategory.ts +++ b/code/base-project/base-app/src/store/moneyCategory.ts @@ -22,17 +22,19 @@ interface MoneyCategoryStore { sysCategories: MoneyCategoryItem[] setSysCategories: (categories: MoneyCategoryItem[]) => void + + clear: () => void } export const useMoneyCategoryStore = create()( persist( (set, get) => ({ categories: [], - sysCategories:[], + sysCategories: [], setCategories: categories => set({ categories }), setSysCategories: categories => set({ categories }), - + addCategory: category => set({ categories: [...get().categories, category] }), @@ -56,6 +58,10 @@ export const useMoneyCategoryStore = create()( } }, + clear: () => { + set({ categories: [] }) + }, + getExpenseCategories: () => (get().categories || []).filter(c => c.type === 0), getIncomeCategories: () => (get().categories || []).filter(c => c.type === 1), @@ -132,7 +138,6 @@ export const useMoneyCategoryStore = create()( })) await updateMoneyCategorySortApi({ data: payload }) }, - }), { name: 'money-category-storage', diff --git a/code/base-project/base-app/src/store/moneyRecord.ts b/code/base-project/base-app/src/store/moneyRecord.ts index 49503c68..749ee58b 100644 --- a/code/base-project/base-app/src/store/moneyRecord.ts +++ b/code/base-project/base-app/src/store/moneyRecord.ts @@ -11,8 +11,9 @@ interface MoneyRecordStore { total_income: string total_expense: string + total_balance: string - setRecords: (records: MoneyRecordGroup[], total_expense: string, total_income: string, month: string) => void + setRecords: (records: MoneyRecordGroup[], total_expense: string, total_income: string, total_balance: string, month: string) => void setCurrentMonth: (month: string) => void addMoneyRecord: (data: MoneyRecordItem) => void @@ -28,9 +29,10 @@ export const useMoneyRecordStore = create((set, get) => ({ total_income: '0.00', total_expense: '0.00', + total_balance: '0.00', - setRecords: (records, total_expense, total_income, month) => { - set({ records, currentMonth: month, total_income, total_expense }) + setRecords: (records, total_expense, total_income, total_balance, month) => { + set({ records, currentMonth: month, total_income, total_expense, total_balance }) }, setCurrentMonth: month => set({ currentMonth: month }), @@ -66,11 +68,15 @@ export const useMoneyRecordStore = create((set, get) => ({ else records.splice(insertIndex, 0, newGroup) } + const totalExpense = category?.type === 0 ? add(prev.total_expense, amount) : prev.total_expense + const totalIncome = category?.type === 1 ? add(prev.total_income, amount) : prev.total_income + const totalBalance = sub(totalIncome, totalExpense) return { ...prev, records, - total_expense: category?.type === 0 ? add(prev.total_expense, amount) : prev.total_expense, - total_income: category?.type === 1 ? add(prev.total_income, amount) : prev.total_income, + total_expense: totalExpense, + total_income: totalIncome, + total_balance: totalBalance, } }) }, @@ -136,7 +142,9 @@ export const useMoneyRecordStore = create((set, get) => ({ if (updateRecordCategory?.type === 1) total_income = add(total_income, newAmount) - return { ...prev, records, total_expense, total_income } + const total_balance = sub(total_income, total_expense) + + return { ...prev, records, total_expense, total_income, total_balance } }) }, @@ -161,7 +169,10 @@ export const useMoneyRecordStore = create((set, get) => ({ }) const newRecords = records.filter(g => g.records.length > 0) - return { ...prev, records: newRecords, total_expense, total_income } + + const total_balance = sub(total_income, total_expense) + + return { ...prev, records: newRecords, total_expense, total_income, total_balance } }) deleteMoneyRecordApi({ id }).catch(console.error) diff --git a/code/base-project/base-app/src/store/space.ts b/code/base-project/base-app/src/store/space.ts index 9350a4d4..128e5e1f 100644 --- a/code/base-project/base-app/src/store/space.ts +++ b/code/base-project/base-app/src/store/space.ts @@ -3,9 +3,15 @@ import { create } from 'zustand' interface SpaceState { userSpace: UserSpace | null setUserSpace: (space: UserSpace | null) => void + clear: () => void } export const useSpaceStore = create(set => ({ userSpace: null, setUserSpace: space => set({ userSpace: space }), + clear: () => { + set({ + userSpace: null, + }) + }, })) diff --git a/code/base-project/base-app/src/store/user.ts b/code/base-project/base-app/src/store/user.ts index 9ff1536c..86dac85a 100644 --- a/code/base-project/base-app/src/store/user.ts +++ b/code/base-project/base-app/src/store/user.ts @@ -6,7 +6,7 @@ import { createJSONStorage, persist } from 'zustand/middleware' interface UserState { userInfo: UserInfo | null setUserInfo: (userInfo: UserInfo | null) => void - logout: () => void + clear: () => void isLoggedIn: () => boolean userSpace: UserSpace | null @@ -22,7 +22,7 @@ const useUserStore = create()( setUserInfo: userInfo => set({ userInfo }), setUserSpace: userSpace => set({ userSpace }), - logout: () => { + clear: () => { set({ userInfo: null, userSpace: null }) }, diff --git a/code/base-project/base-app/src/types/money/record.ts b/code/base-project/base-app/src/types/money/record.ts index b01e13d4..1c3ec725 100644 --- a/code/base-project/base-app/src/types/money/record.ts +++ b/code/base-project/base-app/src/types/money/record.ts @@ -38,6 +38,7 @@ export interface QueryMoneyRecordsResult { records: MoneyRecordGroup[] total_income: string total_expense: string + total_balance: string } // 新增请求参数 diff --git a/code/base-project/base-app/test.html b/code/base-project/base-app/test.html index 666408e8..89d6d266 100644 --- a/code/base-project/base-app/test.html +++ b/code/base-project/base-app/test.html @@ -1,180 +1,128 @@ - - - 字段配置示例 - + /* 打开 Drawer 按钮(演示用) */ + .open-btn { + margin: 30px; + padding: 10px 20px; + background: #0080ff; + color: #fff; + border-radius: 8px; + cursor: pointer; + display: inline-block; + } + +
打开菜单
-

字段配置示例

+ +
- - - - - - - - - - - -
字段名类型必填操作
+ +
+
功能菜单
- + - - \ No newline at end of file + diff --git a/code/base-project/base-go-v3/biz/handler/money/money_record_service.go b/code/base-project/base-go-v3/biz/handler/money/money_record_service.go index f4cbd407..6bf476b7 100644 --- a/code/base-project/base-go-v3/biz/handler/money/money_record_service.go +++ b/code/base-project/base-go-v3/biz/handler/money/money_record_service.go @@ -12,12 +12,14 @@ import ( "cn/oneao/base-go/utils/response" "context" "fmt" - "github.com/jackc/pgx/v5/pgtype" - "github.com/shopspring/decimal" "sort" "time" + "github.com/jackc/pgx/v5/pgtype" + "github.com/shopspring/decimal" + money "cn/oneao/base-go/biz/model/money" + "github.com/cloudwego/hertz/pkg/app" "github.com/cloudwego/hertz/pkg/protocol/consts" ) @@ -51,7 +53,8 @@ func QueryMoneyRecord(ctx context.Context, c *app.RequestContext) { // 最终返回统一类型 var records []*money.MoneyRecordItem - if ok { // 有空间ID,查询空间内所有用户 + // 有空间ID,查询空间内所有用户 + if ok { params := repo.FindMoneyRecordsBySpaceParams{ SpaceID: spaceID, RecordTime: pgtype.Timestamp{Time: startTime, Valid: true}, @@ -79,8 +82,8 @@ func QueryMoneyRecord(ctx context.Context, c *app.RequestContext) { UpdateTime: pgtypex.TimestampToDateTimeString(r.UpdateTime), }) } - - } else { // 没有空间ID,只查询单用户 + } else { + // 没有空间ID,只查询单用户 params := repo.FindUserMoneyRecordsParams{ UserID: userID, RecordTime: pgtype.Timestamp{Time: startTime, Valid: true}, @@ -100,7 +103,7 @@ func QueryMoneyRecord(ctx context.Context, c *app.RequestContext) { CategoryIcon: r.CategoryIcon.String, CategoryName: r.CategoryName.String, UserId: r.UserID, - Username: "", // 单用户查询没有 username + Username: "", Amount: pgtypex.NumericToString(r.Amount), Remark: r.Remark.String, RecordTime: pgtypex.TimestampToDateString(r.RecordTime), @@ -162,6 +165,7 @@ func QueryMoneyRecord(ctx context.Context, c *app.RequestContext) { Records: resultGroups, TotalIncome: totalIncome.Round(2).StringFixed(2), TotalExpense: totalExpense.Round(2).StringFixed(2), + TotalBalance: totalIncome.Sub(totalExpense).Round(2).StringFixed(2), } response.Success(c).Data(result).Send() diff --git a/code/base-project/base-go-v3/biz/model/api/api.pb.go b/code/base-project/base-go-v3/biz/model/api/api.pb.go index 09470162..37434df6 100644 --- a/code/base-project/base-go-v3/biz/model/api/api.pb.go +++ b/code/base-project/base-go-v3/biz/model/api/api.pb.go @@ -3,7 +3,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.28.0 -// protoc v4.25.3 +// protoc v6.33.1 // source: api.proto package api diff --git a/code/base-project/base-go-v3/biz/model/money/money.pb.go b/code/base-project/base-go-v3/biz/model/money/money.pb.go index f66054af..6beae543 100644 --- a/code/base-project/base-go-v3/biz/model/money/money.pb.go +++ b/code/base-project/base-go-v3/biz/model/money/money.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.28.0 -// protoc v4.25.3 +// protoc v6.33.1 // source: money.proto package money diff --git a/code/base-project/base-go-v3/biz/model/money/money_category_types.pb.go b/code/base-project/base-go-v3/biz/model/money/money_category_types.pb.go index 8505dc57..154eb7e1 100644 --- a/code/base-project/base-go-v3/biz/model/money/money_category_types.pb.go +++ b/code/base-project/base-go-v3/biz/model/money/money_category_types.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.28.0 -// protoc v4.25.3 +// protoc v6.33.1 // source: money/money_category_types.proto package money diff --git a/code/base-project/base-go-v3/biz/model/money/money_record_types.pb.go b/code/base-project/base-go-v3/biz/model/money/money_record_types.pb.go index da5bf116..c09982fa 100644 --- a/code/base-project/base-go-v3/biz/model/money/money_record_types.pb.go +++ b/code/base-project/base-go-v3/biz/model/money/money_record_types.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.28.0 -// protoc v4.25.3 +// protoc v6.33.1 // source: money/money_record_types.proto package money @@ -286,6 +286,7 @@ type QueryMoneyRecordsResult struct { Records []*MoneyRecordGroup `protobuf:"bytes,1,rep,name=Records,proto3" form:"records" json:"records"` TotalIncome string `protobuf:"bytes,2,opt,name=TotalIncome,proto3" form:"total_income" json:"total_income"` TotalExpense string `protobuf:"bytes,3,opt,name=TotalExpense,proto3" form:"total_expense" json:"total_expense"` + TotalBalance string `protobuf:"bytes,4,opt,name=TotalBalance,proto3" form:"total_balance" json:"total_balance"` } func (x *QueryMoneyRecordsResult) Reset() { @@ -341,6 +342,13 @@ func (x *QueryMoneyRecordsResult) GetTotalExpense() string { return "" } +func (x *QueryMoneyRecordsResult) GetTotalBalance() string { + if x != nil { + return x.TotalBalance + } + return "" +} + // 新增记账记录参数 type InsertMoneyRecordParams struct { state protoimpl.MessageState @@ -779,7 +787,7 @@ var file_money_money_record_types_proto_rawDesc = []byte{ 0x72, 0x64, 0x73, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x12, 0x2f, 0x0a, 0x0a, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, 0x0f, 0xca, 0xbb, 0x18, 0x0b, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x52, 0x0a, - 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x54, 0x69, 0x6d, 0x65, 0x22, 0xc4, 0x01, 0x0a, 0x17, 0x51, + 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x54, 0x69, 0x6d, 0x65, 0x22, 0xfb, 0x01, 0x0a, 0x17, 0x51, 0x75, 0x65, 0x72, 0x79, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x73, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, 0x3e, 0x0a, 0x07, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x17, 0x2e, 0x6d, 0x6f, 0x6e, 0x65, 0x79, 0x2e, @@ -792,71 +800,75 @@ var file_money_money_record_types_proto_rawDesc = []byte{ 0x74, 0x61, 0x6c, 0x45, 0x78, 0x70, 0x65, 0x6e, 0x73, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x42, 0x11, 0xca, 0xbb, 0x18, 0x0d, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x5f, 0x65, 0x78, 0x70, 0x65, 0x6e, 0x73, 0x65, 0x52, 0x0c, 0x54, 0x6f, 0x74, 0x61, 0x6c, 0x45, 0x78, 0x70, 0x65, 0x6e, 0x73, - 0x65, 0x22, 0xa4, 0x02, 0x0a, 0x17, 0x49, 0x6e, 0x73, 0x65, 0x72, 0x74, 0x4d, 0x6f, 0x6e, 0x65, - 0x79, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x12, 0x38, 0x0a, - 0x0a, 0x43, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x03, 0x42, 0x18, 0xca, 0xbb, 0x18, 0x0b, 0x63, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x5f, - 0x69, 0x64, 0xda, 0xbb, 0x18, 0x05, 0x24, 0x21, 0x3d, 0x27, 0x27, 0x52, 0x0a, 0x43, 0x61, 0x74, - 0x65, 0x67, 0x6f, 0x72, 0x79, 0x49, 0x64, 0x12, 0x4d, 0x0a, 0x06, 0x41, 0x6d, 0x6f, 0x75, 0x6e, - 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x42, 0x35, 0xca, 0xbb, 0x18, 0x06, 0x61, 0x6d, 0x6f, - 0x75, 0x6e, 0x74, 0xda, 0xbb, 0x18, 0x27, 0x24, 0x21, 0x3d, 0x27, 0x27, 0x20, 0x26, 0x26, 0x20, - 0x72, 0x65, 0x67, 0x65, 0x78, 0x70, 0x28, 0x27, 0x5e, 0x5c, 0x64, 0x2b, 0x28, 0x5c, 0x2e, 0x5c, - 0x64, 0x7b, 0x31, 0x2c, 0x32, 0x7d, 0x29, 0x3f, 0x24, 0x27, 0x2c, 0x20, 0x24, 0x29, 0x52, 0x06, - 0x41, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x22, 0x0a, 0x06, 0x52, 0x65, 0x6d, 0x61, 0x72, 0x6b, - 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x42, 0x0a, 0xca, 0xbb, 0x18, 0x06, 0x72, 0x65, 0x6d, 0x61, - 0x72, 0x6b, 0x52, 0x06, 0x52, 0x65, 0x6d, 0x61, 0x72, 0x6b, 0x12, 0x5c, 0x0a, 0x0a, 0x52, 0x65, - 0x63, 0x6f, 0x72, 0x64, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x42, 0x3c, - 0xca, 0xbb, 0x18, 0x0b, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0xda, - 0xbb, 0x18, 0x29, 0x24, 0x21, 0x3d, 0x27, 0x27, 0x20, 0x26, 0x26, 0x20, 0x72, 0x65, 0x67, 0x65, - 0x78, 0x70, 0x28, 0x27, 0x5e, 0x5c, 0x64, 0x7b, 0x34, 0x7d, 0x2d, 0x5c, 0x64, 0x7b, 0x32, 0x7d, - 0x2d, 0x5c, 0x64, 0x7b, 0x32, 0x7d, 0x24, 0x27, 0x2c, 0x20, 0x24, 0x29, 0x52, 0x0a, 0x52, 0x65, - 0x63, 0x6f, 0x72, 0x64, 0x54, 0x69, 0x6d, 0x65, 0x22, 0xe2, 0x02, 0x0a, 0x17, 0x49, 0x6e, 0x73, - 0x65, 0x72, 0x74, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x52, 0x65, - 0x73, 0x75, 0x6c, 0x74, 0x12, 0x16, 0x0a, 0x02, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, - 0x42, 0x06, 0xca, 0xbb, 0x18, 0x02, 0x69, 0x64, 0x52, 0x02, 0x49, 0x64, 0x12, 0x2f, 0x0a, 0x0a, - 0x43, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, - 0x42, 0x0f, 0xca, 0xbb, 0x18, 0x0b, 0x63, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x5f, 0x69, - 0x64, 0x52, 0x0a, 0x43, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x49, 0x64, 0x12, 0x23, 0x0a, - 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x42, 0x0b, 0xca, - 0xbb, 0x18, 0x07, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x52, 0x06, 0x55, 0x73, 0x65, 0x72, - 0x49, 0x64, 0x12, 0x22, 0x0a, 0x06, 0x41, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x04, 0x20, 0x01, - 0x28, 0x09, 0x42, 0x0a, 0xca, 0xbb, 0x18, 0x06, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x52, 0x06, - 0x41, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x22, 0x0a, 0x06, 0x52, 0x65, 0x6d, 0x61, 0x72, 0x6b, - 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x42, 0x0a, 0xca, 0xbb, 0x18, 0x06, 0x72, 0x65, 0x6d, 0x61, - 0x72, 0x6b, 0x52, 0x06, 0x52, 0x65, 0x6d, 0x61, 0x72, 0x6b, 0x12, 0x2f, 0x0a, 0x0a, 0x52, 0x65, - 0x63, 0x6f, 0x72, 0x64, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x42, 0x0f, - 0xca, 0xbb, 0x18, 0x0b, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x52, - 0x0a, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x2f, 0x0a, 0x0a, 0x43, - 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x42, - 0x0f, 0xca, 0xbb, 0x18, 0x0b, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x5f, 0x74, 0x69, 0x6d, 0x65, - 0x52, 0x0a, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x2f, 0x0a, 0x0a, - 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, - 0x42, 0x0f, 0xca, 0xbb, 0x18, 0x0b, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x5f, 0x74, 0x69, 0x6d, - 0x65, 0x52, 0x0a, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x22, 0xe3, 0x01, - 0x0a, 0x17, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x52, 0x65, 0x63, - 0x6f, 0x72, 0x64, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x12, 0x1e, 0x0a, 0x02, 0x49, 0x64, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x03, 0x42, 0x0e, 0xca, 0xbb, 0x18, 0x02, 0x69, 0x64, 0xda, 0xbb, 0x18, - 0x04, 0x24, 0x21, 0x3d, 0x30, 0x52, 0x02, 0x49, 0x64, 0x12, 0x2f, 0x0a, 0x0a, 0x43, 0x61, 0x74, - 0x65, 0x67, 0x6f, 0x72, 0x79, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x42, 0x0f, 0xca, - 0xbb, 0x18, 0x0b, 0x63, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x5f, 0x69, 0x64, 0x52, 0x0a, - 0x43, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x49, 0x64, 0x12, 0x22, 0x0a, 0x06, 0x41, 0x6d, - 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x42, 0x0a, 0xca, 0xbb, 0x18, 0x06, - 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x52, 0x06, 0x41, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x22, - 0x0a, 0x06, 0x52, 0x65, 0x6d, 0x61, 0x72, 0x6b, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x42, 0x0a, - 0xca, 0xbb, 0x18, 0x06, 0x72, 0x65, 0x6d, 0x61, 0x72, 0x6b, 0x52, 0x06, 0x52, 0x65, 0x6d, 0x61, - 0x72, 0x6b, 0x12, 0x2f, 0x0a, 0x0a, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x54, 0x69, 0x6d, 0x65, - 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x42, 0x0f, 0xca, 0xbb, 0x18, 0x0b, 0x72, 0x65, 0x63, 0x6f, - 0x72, 0x64, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x52, 0x0a, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x54, - 0x69, 0x6d, 0x65, 0x22, 0x19, 0x0a, 0x17, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x4d, 0x6f, 0x6e, - 0x65, 0x79, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x22, 0x39, - 0x0a, 0x17, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x52, 0x65, 0x63, - 0x6f, 0x72, 0x64, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x12, 0x1e, 0x0a, 0x02, 0x49, 0x64, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x03, 0x42, 0x0e, 0xca, 0xbb, 0x18, 0x02, 0x69, 0x64, 0xda, 0xbb, 0x18, - 0x04, 0x24, 0x21, 0x3d, 0x30, 0x52, 0x02, 0x49, 0x64, 0x22, 0x19, 0x0a, 0x17, 0x44, 0x65, 0x6c, - 0x65, 0x74, 0x65, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x52, 0x65, - 0x73, 0x75, 0x6c, 0x74, 0x42, 0x22, 0x5a, 0x20, 0x63, 0x6e, 0x2f, 0x6f, 0x6e, 0x65, 0x61, 0x6f, - 0x2f, 0x62, 0x61, 0x73, 0x65, 0x2d, 0x67, 0x6f, 0x2f, 0x62, 0x69, 0x7a, 0x2f, 0x6d, 0x6f, 0x64, - 0x65, 0x6c, 0x2f, 0x6d, 0x6f, 0x6e, 0x65, 0x79, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x65, 0x12, 0x35, 0x0a, 0x0c, 0x54, 0x6f, 0x74, 0x61, 0x6c, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, + 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x42, 0x11, 0xca, 0xbb, 0x18, 0x0d, 0x74, 0x6f, 0x74, + 0x61, 0x6c, 0x5f, 0x62, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x52, 0x0c, 0x54, 0x6f, 0x74, 0x61, + 0x6c, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x22, 0xa4, 0x02, 0x0a, 0x17, 0x49, 0x6e, 0x73, + 0x65, 0x72, 0x74, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x50, 0x61, + 0x72, 0x61, 0x6d, 0x73, 0x12, 0x38, 0x0a, 0x0a, 0x43, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, + 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x42, 0x18, 0xca, 0xbb, 0x18, 0x0b, 0x63, 0x61, + 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x5f, 0x69, 0x64, 0xda, 0xbb, 0x18, 0x05, 0x24, 0x21, 0x3d, + 0x27, 0x27, 0x52, 0x0a, 0x43, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x49, 0x64, 0x12, 0x4d, + 0x0a, 0x06, 0x41, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x42, 0x35, + 0xca, 0xbb, 0x18, 0x06, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0xda, 0xbb, 0x18, 0x27, 0x24, 0x21, + 0x3d, 0x27, 0x27, 0x20, 0x26, 0x26, 0x20, 0x72, 0x65, 0x67, 0x65, 0x78, 0x70, 0x28, 0x27, 0x5e, + 0x5c, 0x64, 0x2b, 0x28, 0x5c, 0x2e, 0x5c, 0x64, 0x7b, 0x31, 0x2c, 0x32, 0x7d, 0x29, 0x3f, 0x24, + 0x27, 0x2c, 0x20, 0x24, 0x29, 0x52, 0x06, 0x41, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x22, 0x0a, + 0x06, 0x52, 0x65, 0x6d, 0x61, 0x72, 0x6b, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x42, 0x0a, 0xca, + 0xbb, 0x18, 0x06, 0x72, 0x65, 0x6d, 0x61, 0x72, 0x6b, 0x52, 0x06, 0x52, 0x65, 0x6d, 0x61, 0x72, + 0x6b, 0x12, 0x5c, 0x0a, 0x0a, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x54, 0x69, 0x6d, 0x65, 0x18, + 0x04, 0x20, 0x01, 0x28, 0x09, 0x42, 0x3c, 0xca, 0xbb, 0x18, 0x0b, 0x72, 0x65, 0x63, 0x6f, 0x72, + 0x64, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0xda, 0xbb, 0x18, 0x29, 0x24, 0x21, 0x3d, 0x27, 0x27, 0x20, + 0x26, 0x26, 0x20, 0x72, 0x65, 0x67, 0x65, 0x78, 0x70, 0x28, 0x27, 0x5e, 0x5c, 0x64, 0x7b, 0x34, + 0x7d, 0x2d, 0x5c, 0x64, 0x7b, 0x32, 0x7d, 0x2d, 0x5c, 0x64, 0x7b, 0x32, 0x7d, 0x24, 0x27, 0x2c, + 0x20, 0x24, 0x29, 0x52, 0x0a, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x54, 0x69, 0x6d, 0x65, 0x22, + 0xe2, 0x02, 0x0a, 0x17, 0x49, 0x6e, 0x73, 0x65, 0x72, 0x74, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x52, + 0x65, 0x63, 0x6f, 0x72, 0x64, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, 0x16, 0x0a, 0x02, 0x49, + 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x42, 0x06, 0xca, 0xbb, 0x18, 0x02, 0x69, 0x64, 0x52, + 0x02, 0x49, 0x64, 0x12, 0x2f, 0x0a, 0x0a, 0x43, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x49, + 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x42, 0x0f, 0xca, 0xbb, 0x18, 0x0b, 0x63, 0x61, 0x74, + 0x65, 0x67, 0x6f, 0x72, 0x79, 0x5f, 0x69, 0x64, 0x52, 0x0a, 0x43, 0x61, 0x74, 0x65, 0x67, 0x6f, + 0x72, 0x79, 0x49, 0x64, 0x12, 0x23, 0x0a, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x18, 0x03, + 0x20, 0x01, 0x28, 0x03, 0x42, 0x0b, 0xca, 0xbb, 0x18, 0x07, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x69, + 0x64, 0x52, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x22, 0x0a, 0x06, 0x41, 0x6d, 0x6f, + 0x75, 0x6e, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x42, 0x0a, 0xca, 0xbb, 0x18, 0x06, 0x61, + 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x52, 0x06, 0x41, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x22, 0x0a, + 0x06, 0x52, 0x65, 0x6d, 0x61, 0x72, 0x6b, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x42, 0x0a, 0xca, + 0xbb, 0x18, 0x06, 0x72, 0x65, 0x6d, 0x61, 0x72, 0x6b, 0x52, 0x06, 0x52, 0x65, 0x6d, 0x61, 0x72, + 0x6b, 0x12, 0x2f, 0x0a, 0x0a, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x54, 0x69, 0x6d, 0x65, 0x18, + 0x06, 0x20, 0x01, 0x28, 0x09, 0x42, 0x0f, 0xca, 0xbb, 0x18, 0x0b, 0x72, 0x65, 0x63, 0x6f, 0x72, + 0x64, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x52, 0x0a, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x54, 0x69, + 0x6d, 0x65, 0x12, 0x2f, 0x0a, 0x0a, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, + 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x42, 0x0f, 0xca, 0xbb, 0x18, 0x0b, 0x63, 0x72, 0x65, 0x61, + 0x74, 0x65, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x52, 0x0a, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, + 0x69, 0x6d, 0x65, 0x12, 0x2f, 0x0a, 0x0a, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, + 0x65, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x42, 0x0f, 0xca, 0xbb, 0x18, 0x0b, 0x75, 0x70, 0x64, + 0x61, 0x74, 0x65, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x52, 0x0a, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, + 0x54, 0x69, 0x6d, 0x65, 0x22, 0xe3, 0x01, 0x0a, 0x17, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x4d, + 0x6f, 0x6e, 0x65, 0x79, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, + 0x12, 0x1e, 0x0a, 0x02, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x42, 0x0e, 0xca, 0xbb, + 0x18, 0x02, 0x69, 0x64, 0xda, 0xbb, 0x18, 0x04, 0x24, 0x21, 0x3d, 0x30, 0x52, 0x02, 0x49, 0x64, + 0x12, 0x2f, 0x0a, 0x0a, 0x43, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x49, 0x64, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x03, 0x42, 0x0f, 0xca, 0xbb, 0x18, 0x0b, 0x63, 0x61, 0x74, 0x65, 0x67, 0x6f, + 0x72, 0x79, 0x5f, 0x69, 0x64, 0x52, 0x0a, 0x43, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x49, + 0x64, 0x12, 0x22, 0x0a, 0x06, 0x41, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, + 0x09, 0x42, 0x0a, 0xca, 0xbb, 0x18, 0x06, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x52, 0x06, 0x41, + 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x22, 0x0a, 0x06, 0x52, 0x65, 0x6d, 0x61, 0x72, 0x6b, 0x18, + 0x04, 0x20, 0x01, 0x28, 0x09, 0x42, 0x0a, 0xca, 0xbb, 0x18, 0x06, 0x72, 0x65, 0x6d, 0x61, 0x72, + 0x6b, 0x52, 0x06, 0x52, 0x65, 0x6d, 0x61, 0x72, 0x6b, 0x12, 0x2f, 0x0a, 0x0a, 0x52, 0x65, 0x63, + 0x6f, 0x72, 0x64, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x42, 0x0f, 0xca, + 0xbb, 0x18, 0x0b, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x52, 0x0a, + 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x54, 0x69, 0x6d, 0x65, 0x22, 0x19, 0x0a, 0x17, 0x55, 0x70, + 0x64, 0x61, 0x74, 0x65, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x52, + 0x65, 0x73, 0x75, 0x6c, 0x74, 0x22, 0x39, 0x0a, 0x17, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x4d, + 0x6f, 0x6e, 0x65, 0x79, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, + 0x12, 0x1e, 0x0a, 0x02, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x42, 0x0e, 0xca, 0xbb, + 0x18, 0x02, 0x69, 0x64, 0xda, 0xbb, 0x18, 0x04, 0x24, 0x21, 0x3d, 0x30, 0x52, 0x02, 0x49, 0x64, + 0x22, 0x19, 0x0a, 0x17, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x52, + 0x65, 0x63, 0x6f, 0x72, 0x64, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x42, 0x22, 0x5a, 0x20, 0x63, + 0x6e, 0x2f, 0x6f, 0x6e, 0x65, 0x61, 0x6f, 0x2f, 0x62, 0x61, 0x73, 0x65, 0x2d, 0x67, 0x6f, 0x2f, + 0x62, 0x69, 0x7a, 0x2f, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x2f, 0x6d, 0x6f, 0x6e, 0x65, 0x79, 0x62, + 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/code/base-project/base-go-v3/biz/router/middleware/auth.go b/code/base-project/base-go-v3/biz/router/middleware/auth.go index 5fb892d6..863110db 100644 --- a/code/base-project/base-go-v3/biz/router/middleware/auth.go +++ b/code/base-project/base-go-v3/biz/router/middleware/auth.go @@ -5,8 +5,9 @@ import ( "cn/oneao/base-go/utils/pathx" "cn/oneao/base-go/utils/response" "context" - "github.com/cloudwego/hertz/pkg/app" "strconv" + + "github.com/cloudwego/hertz/pkg/app" ) // 私有 key,防止冲突 @@ -36,7 +37,6 @@ func Auth() app.HandlerFunc { token := string(c.GetHeader("token")) spaceId := string(c.GetHeader("x-space-id")) - if token == "" { response.Fail(c).Code(response.HttpCode.Unauthorized).Send() c.Abort() diff --git a/code/base-project/base-go-v3/biz/router/middleware/jwt.go b/code/base-project/base-go-v3/biz/router/middleware/jwt.go deleted file mode 100644 index 7bbaced0..00000000 --- a/code/base-project/base-go-v3/biz/router/middleware/jwt.go +++ /dev/null @@ -1,100 +0,0 @@ -package middleware - -import ( - "context" - "log" - "net/http" - "time" - - "github.com/cloudwego/hertz/pkg/app" - "github.com/hertz-contrib/jwt" -) - -var identityKey = "UserId" - -type loginForm struct { - Account string `form:"username,required" json:"username,required"` - Password string `form:"password,required" json:"password,required"` - Type int `form:"type,required" json:"type,required"` -} - -type User struct { - UserId int64 -} - -var hertzJWTMiddleware *jwt.HertzJWTMiddleware - -func init() { - middleware, err := jwt.New(&jwt.HertzJWTMiddleware{ - Realm: "test zone", - Key: []byte("secret key"), - Timeout: 30 * time.Minute, - MaxRefresh: 30 * 24 * time.Hour, - IdentityKey: identityKey, - // Token负载信息 - PayloadFunc: func(data interface{}) jwt.MapClaims { - if v, ok := data.(*User); ok { - return jwt.MapClaims{ - identityKey: v.UserId, - } - } - return jwt.MapClaims{} - }, - // 解析Token取出用户信息 - IdentityHandler: func(ctx context.Context, c *app.RequestContext) interface{} { - claims := jwt.ExtractClaims(ctx, c) - return &User{ - UserId: claims[identityKey].(int64), - } - }, - // 登录 - Authenticator: func(ctx context.Context, c *app.RequestContext) (interface{}, error) { - c.Request.RequestURI() - return nil, jwt.ErrFailedAuthentication - }, - // 权限控制 - Authorizator: func(data interface{}, ctx context.Context, c *app.RequestContext) bool { - return true - }, - // 未验证处理 - Unauthorized: func(ctx context.Context, c *app.RequestContext, code int, message string) { - c.JSON(code, map[string]interface{}{ - "code": code, - "message": message, - }) - }, - // 登录响应 - LoginResponse: func(ctx context.Context, c *app.RequestContext, code int, token string, expire time.Time) { - c.JSON(http.StatusOK, map[string]interface{}{ - "code": http.StatusOK, - "token": token, - "expire": expire.Format(time.RFC3339), - }) - }, - // 登出响应 - LogoutResponse: func(ctx context.Context, c *app.RequestContext, code int) { - c.JSON(http.StatusOK, map[string]interface{}{ - "code": http.StatusOK, - }) - }, - // 刷新Token - RefreshResponse: func(ctx context.Context, c *app.RequestContext, code int, token string, expire time.Time) { - c.JSON(http.StatusOK, map[string]interface{}{ - "code": http.StatusOK, - "token": token, - "expire": expire.Format(time.RFC3339), - }) - }, - TokenLookup: "header: Authorization", - }) - - if err != nil { - log.Fatal("JWT Error:" + err.Error()) - } - - hertzJWTMiddleware = middleware -} - -func JWT() *jwt.HertzJWTMiddleware { - return hertzJWTMiddleware -} diff --git a/code/base-project/base-go-v3/db/queries/space.sql b/code/base-project/base-go-v3/db/queries/space.sql index 91e2d37e..d18911a7 100644 --- a/code/base-project/base-go-v3/db/queries/space.sql +++ b/code/base-project/base-go-v3/db/queries/space.sql @@ -20,4 +20,5 @@ WHERE m.user_id = $1; -- 根据验证码获取空间 -- name: GetSpaceByInviteCode :one -SELECT * FROM space WHERE invite_code = $1; \ No newline at end of file +SELECT * FROM space WHERE invite_code = $1; + diff --git a/code/base-project/base-go-v3/idl/money/money_record_types.proto b/code/base-project/base-go-v3/idl/money/money_record_types.proto index cf23dd26..da8f9028 100644 --- a/code/base-project/base-go-v3/idl/money/money_record_types.proto +++ b/code/base-project/base-go-v3/idl/money/money_record_types.proto @@ -43,6 +43,7 @@ message QueryMoneyRecordsResult { string TotalIncome = 2 [(api.body)="total_income"]; string TotalExpense = 3 [(api.body)="total_expense"]; + string TotalBalance = 4 [(api.body)="total_balance"]; } // 新增记账记录参数