feidee

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 15, 2020 License: Apache-2.0 Imports: 15 Imported by: 0

README

feidee

随手记API

Usage

创建并初始化客户端

	//创建客户端
	client := feidee.New()

	//登录
	err := client.Login("username", "password")
	if err != nil {
		return fmt.Errorf("登录失败:%s", err)
	}

	//(可选)获取账本列表
	err = client.SyncAccountBookList()
	if err != nil {
		return fmt.Errorf("刷新账本列表失败: %s", err)
	}

	//(可选)切换账本(此处需要上一步同步账本列表才能通过账本名查到账本ID,否则会报错找不到账本)
	err = client.SwitchBook("默认账本")
	if err != nil {
		return fmt.Errorf("切换账本失败: %s", err)
	}

	//同步基础数据(科目、成员、商家、项目、账户等)
	err = client.SyncMetaInfo()
	if err != nil {
		return fmt.Errorf("同步账户基础信息失败:%s", err)
	}

打印上个月对账信息

	now := time.Now()
	t := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, time.Local)
	start := t.AddDate(0, -1, 0)
	end := start.AddDate(0, 1, -1)

	for id, account := range FdCLient.AccountMap {
		list, err := FdCLient.CompareReport(id, start, end)
		if err != nil {
			fmt.Printf("\n\n账户%s错误:%s", account.Name, err)
			continue
		}
		fmt.Println("\n\n账户:", account.Name, "x", len(list))
		for _, info := range list {
			fmt.Printf("\t%+v\n", info)
		}
	}

查询并打印按月收支

	infoMap, err := FdCLient.MonthIncomeAndPayoutMap(2017, 2018)
	if err != nil {
		fmt.Printf("查询按月收支信息失败: %s", err)
		return
	}
	for key, info := range infoMap {
		fmt.Printf("%d: %+v\n", key, info)
	}

查询并打印上月流水

	now := time.Now()
	t := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, time.Local)
	start := t.AddDate(0, -1, 0)
	end := start.AddDate(0, 1, -1)

	info, err := FdCLient.TallyList(start, end, nil)
	if err != nil {
		fmt.Printf("查询失败:%s", err)
		return
	}

	fmt.Printf("%s - %s\n", info.BeginDate, info.EndDate)
	fmt.Printf("汇总:%+v\n", info.IncomeAndPayout)
	for i, group := range info.Groups {
		fmt.Printf("%+v\n", group.IncomeAndPayout)
		for j, t := range group.List {
			fmt.Printf("%d-%d %4s(%2d) %8s => %8s %10.2f\n", i, j, t.TranName, t.TranType, t.BuyerAcount, t.SellerAcount, t.ItemAmount)
		}
	}

Documentation

Index

Constants

View Source
const (
	BaseUrl  = "https://www.sui.com"
	LoginUrl = "https://login.sui.com"
)

请求的基础链接地址

View Source
const (
	TranTypePayout   = 1 //支出
	TranTypeTransfer = 2 //转账
	TranTypeIncome   = 5 //收入
)

交易类型

View Source
const MaxAuthRedirectCount = 5

自动跳转以刷新认证信息时,最大的递归调用次数

Variables

This section is empty.

Functions

This section is empty.

Types

type AccountBook

type AccountBook struct {
	Categories []Category
	Stores     []IdName
	Members    []IdName
	Accounts   []IdName
	Projects   []IdName
}

func (AccountBook) AccountIdByName

func (accountBook AccountBook) AccountIdByName(name string) int

根据账户名获取账户ID

func (AccountBook) CategoryIdByName

func (accountBook AccountBook) CategoryIdByName(name string) int

根据科目名获取科目ID

func (AccountBook) CategoryIdMap

func (accountBook AccountBook) CategoryIdMap() map[int]Category

根据科目名获取科目ID为索引的Map

func (AccountBook) MemberIdByName

func (accountBook AccountBook) MemberIdByName(name string) int

根据成员名获取成员ID

func (AccountBook) ProjectIdByName

func (accountBook AccountBook) ProjectIdByName(name string) int

根据项目名获取项目ID

func (AccountBook) StoreIdByName

func (accountBook AccountBook) StoreIdByName(name string) int

根据商户名获取商户ID

type Category

type Category struct {
	IdName
	Type   int  //科目类别:支出或收入,参见TranTypeXXX常量
	IsSub  bool //是否是子科目
	SubIds []int
}

账单科目

type Client

type Client struct {
	Verbose bool
	AccountBook
	AccountBookList []IdName
	// contains filtered or unexported fields
}

执行操作的Feidee客户端

func New

func New() *Client

创建客户端

func (*Client) BillEntry

func (cli *Client) BillEntry(id int, day time.Time, money float64) (string, error)

周期账手动入账

func (*Client) CompareReport

func (cli *Client) CompareReport(accountId int, begin, end time.Time) ([]CompareInfo, error)

获取所有对账报表

func (*Client) CompareReportByPage

func (cli *Client) CompareReportByPage(accountId int, begin, end time.Time, page int) (CompareReportResponse, error)

获取单页对账报表

func (*Client) DailyReport

func (cli *Client) DailyReport(begin, end time.Time, params url.Values) (DailyReport, error)

日常收支报表

func (*Client) ExportToBuffer

func (cli *Client) ExportToBuffer() ([]byte, error)

func (*Client) ExportToFile

func (cli *Client) ExportToFile(filename string) error

数据导出到文件(随手记WEB版格式的xls文件)

func (cli *Client) GetExportLink() (string, error)

获取数据导出的链接(导出为随手记WEB版格式的xls文件)

func (*Client) Login

func (cli *Client) Login(email, password string) error

登录

func (*Client) MonthIncomeAndPayoutMap

func (cli *Client) MonthIncomeAndPayoutMap(beginYear, endYear int) (map[int]IncomeAndPayout, error)

获取按月汇总的收支情况,key为201707格式

func (*Client) SwitchAccountBook

func (cli *Client) SwitchAccountBook(name string) error

切换账本

func (*Client) SyncAccountBookList

func (cli *Client) SyncAccountBookList() error

刷新账本列表

func (*Client) SyncMetaInfo

func (cli *Client) SyncMetaInfo() error

初始化账本、分类、账户、商家、项目、成员等信息

func (*Client) TallyCreate

func (cli *Client) TallyCreate(tally Tally, when time.Time) error

添加交易的接口 //TODO:增加对其他交易类型的支持

func (*Client) TallyDelete

func (cli *Client) TallyDelete(tranIds ...string) error

(批量)删除交易的接口

func (*Client) TallyList

func (cli *Client) TallyList(begin, end time.Time, data url.Values) (TallyResponseInfo, error)

获取流水,可用参数包括

bids账户、cids科目、mids类型、pids项目、sids商户、memids成员,这几个参数都是逗号分割的ID列表
order:  排序字段,支持: project_id项目排序、buyer_name账户、item_amount金额、tran_type类型、category_id科目、tran_time时间
isDesc: 是否降序,0升序、1降序
note:   搜备注关键字

func (*Client) TallyUpdate

func (cli *Client) TallyUpdate(tally Tally, updateData url.Values) error

更新交易的接口

type CompareInfo

type CompareInfo struct {
	Balance    float32 //当前余额
	DayBalance float32 //当日余额(当日收入-当日支出)
	Money      struct {
		Claims float32
		Income float32
		In     float32 //流入
		Debet  float32
		Out    float32 //留出
		Payout float32
	}
	Date DateInfo
}

对账报表

type CompareReportResponse

type CompareReportResponse struct {
	PageInfo
	List []CompareInfo
}

报表页响应

type DailyReport

type DailyReport struct {
	InAmount  float32
	OutAmount float32

	Symbol string
	MaxIn  float32 `json:"maxI"`
	MaxOut float32 `json:"maxO"`

	InList  DailyReportList `json:"inlst"`
	OutList DailyReportList `json:"outlst"`
}

type DailyReportList

type DailyReportList []struct {
	IdName
	Total float32
	List  []struct {
		IdName
		Amount float32
	} `json:"c"`
}

日常收支报表

type DateInfo

type DateInfo struct {
	Year           int //从1900算起第N年
	Month          int //从0开始的月份
	Date           int //日期
	Day            int //星期
	Hours          int //时北京时间
	Minutes        int //分
	Seconds        int //秒
	Time           int //Unix时间戳* 1000
	TimezoneOffset int //与UTC时间的相差的小时数
}

多个响应使用的日期结构

type IdName

type IdName struct {
	Id   int
	Name string
}

包含ID、Name两个属性的结构

type IncomeAndPayout

type IncomeAndPayout struct {
	Income float32
	Payout float32
}

包含收入、支出两个属性的结构

type PageInfo

type PageInfo struct {
	PageCount int
	PageNo    int
}

多个响应使用的分页结构

type Tally

type Tally struct {
	Account        int
	BuyerAcount    string //支出、收入时为交易账户,转账时为转出账户
	BuyerAcountId  int    //支出、收入时为交易账户,转账时为转出账户
	CategoryId     int
	CategoryName   string
	MemberId       int
	MemberName     string
	TranType       int
	TranName       string
	ProjectId      int
	ProjectName    string
	SellerAcount   string //转账时表示转入账户
	SellerAcountId int    //转账时表示转入账户

	ItemAmount     float32 //交易金额,转账时该数值和CurrencyAmount相同
	CurrencyAmount float32 //转账金额

	Relation        string
	CategoryIcon    string
	Url             string
	Content         string
	ImgId           int
	TranId          int
	TransferStoreId int
	Memo            string

	Date DateInfo
}

流水信息

func (Tally) ToUpdateParams

func (t Tally) ToUpdateParams() url.Values

生成用于更新的url.Values参数

type TallyGroup

type TallyGroup struct {
	IncomeAndPayout
	List []Tally
}

流水组(通常是按天分组)

type TallyResponseInfo

type TallyResponseInfo struct {
	IncomeAndPayout
	PageNo    int
	PageCount int
	Symbol    string
	EndDate   string
	BeginDate string
	Groups    []TallyGroup
}

查询流水接口的响应

type VCCodeInfo

type VCCodeInfo struct {
	VCCode string
	Uid    string
}

Directories

Path Synopsis
example
exporter
随手记导出工具
随手记导出工具

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL