139 lines
6.5 KiB
Go

package newbond
import (
"database/sql/driver"
"fmt"
"time"
)
type BondData struct {
SecurityCode string `json:"SECURITY_CODE" db:"SecurityCode"`
SecuCode string `json:"SECUCODE" db:"SecuCode"`
TradeMarket string `json:"TRADE_MARKET" db:"TradeMarket"`
SecurityNameAbbr string `json:"SECURITY_NAME_ABBR" db:"SecurityNameAbbr"`
// DelistDate *CustomTime `json:"DELIST_DATE" db:"DelistDate"`
ListingDate *CustomTime `json:"LISTING_DATE" db:"ListingDate"`
ConvertStockCode string `json:"CONVERT_STOCK_CODE" db:"ConvertStockCode"`
BondExpire string `json:"BOND_EXPIRE" db:"BondExpire"`
Rating string `json:"RATING" db:"Rating"`
ValueDate CustomTime `json:"VALUE_DATE" db:"ValueDate"`
IssueYear string `json:"ISSUE_YEAR" db:"IssueYear"`
CeaseDate CustomTime `json:"CEASE_DATE" db:"CeaseDate"`
ExpireDate CustomTime `json:"EXPIRE_DATE" db:"ExpireDate"`
PayInterestDay string `json:"PAY_INTEREST_DAY" db:"PayInterestDay"`
InterestRateExplain string `json:"INTEREST_RATE_EXPLAIN" db:"InterestRateExplain"`
BondCombineCode string `json:"BOND_COMBINE_CODE" db:"BondCombineCode"`
ActualIssueScale float64 `json:"ACTUAL_ISSUE_SCALE" db:"ActualIssueScale"`
IssuePrice float64 `json:"ISSUE_PRICE" db:"IssuePrice"`
Remark string `json:"REMARK" db:"Remark"`
ParValue float64 `json:"PAR_VALUE" db:"ParValue"`
IssueObject string `json:"ISSUE_OBJECT" db:"IssueObject"`
// RedeemType *string `json:"REDEEM_TYPE" db:"RedeemType"`
// ExecuteReasonHS *string `json:"EXECUTE_REASON_HS" db:"ExecuteReasonHS"`
// NoticeDateHS *CustomTime `json:"NOTICE_DATE_HS" db:"NoticeDateHS"`
// NoticeDateSH *CustomTime `json:"NOTICE_DATE_SH" db:"NoticeDateSH"`
// ExecutePriceHS *float64 `json:"EXECUTE_PRICE_HS" db:"ExecutePriceHS"`
// ExecutePriceSH *float64 `json:"EXECUTE_PRICE_SH" db:"ExecutePriceSH"`
// RecordDateSH *CustomTime `json:"RECORD_DATE_SH" db:"RecordDateSH"`
// ExecuteStartDateSH *CustomTime `json:"EXECUTE_START_DATESH" db:"ExecuteStartDateSH"`
// ExecuteStartDateHS *CustomTime `json:"EXECUTE_START_DATEHS" db:"ExecuteStartDateHS"`
// ExecuteEndDate *CustomTime `json:"EXECUTE_END_DATE" db:"ExecuteEndDate"`
CorreCode string `json:"CORRECODE" db:"CorreCode"`
CorreCodeNameAbbr string `json:"CORRECODE_NAME_ABBR" db:"CorreCodeNameAbbr"`
PublicStartDate CustomTime `json:"PUBLIC_START_DATE" db:"PublicStartDate"`
CorreCodeO string `json:"CORRECODEO" db:"CorreCodeO"`
CorreCodeNameAbbrO string `json:"CORRECODE_NAME_ABBRO" db:"CorreCodeNameAbbrO"`
BondStartDate CustomTime `json:"BOND_START_DATE" db:"BondStartDate"`
SecurityStartDate CustomTime `json:"SECURITY_START_DATE" db:"SecurityStartDate"`
SecurityShortName string `json:"SECURITY_SHORT_NAME" db:"SecurityShortName"`
FirstPerPreplacing float64 `json:"FIRST_PER_PREPLACING" db:"FirstPerPreplacing"`
OnlineGeneralAAU float64 `json:"ONLINE_GENERAL_AAU" db:"OnlineGeneralAAU"`
OnlineGeneralLWR float64 `json:"ONLINE_GENERAL_LWR" db:"OnlineGeneralLWR"`
InitialTransferPrice float64 `json:"INITIAL_TRANSFER_PRICE" db:"InitialTransferPrice"`
TransferEndDate CustomTime `json:"TRANSFER_END_DATE" db:"TransferEndDate"`
TransferStartDate CustomTime `json:"TRANSFER_START_DATE" db:"TransferStartDate"`
ResaleClause string `json:"RESALE_CLAUSE" db:"ResaleClause"`
RedeemClause string `json:"REDEEM_CLAUSE" db:"RedeemClause"`
PartyName string `json:"PARTY_NAME" db:"PartyName"`
ConvertStockPrice interface{} `json:"CONVERT_STOCK_PRICE" db:"ConvertStockPrice"`
TransferPrice float64 `json:"TRANSFER_PRICE" db:"TransferPrice"`
TransferValue float64 `json:"TRANSFER_VALUE" db:"TransferValue"`
CurrentBondPrice interface{} `json:"CURRENT_BOND_PRICE" db:"CurrentBondPrice"`
TransferPremiumRatio float64 `json:"TRANSFER_PREMIUM_RATIO" db:"TransferPremiumRatio"`
// ConvertStockPriceHQ *float64 `json:"CONVERT_STOCK_PRICEHQ" db:"ConvertStockPriceHQ"`
// Market *string `json:"MARKET" db:"Market"`
ResaleTrigPrice float64 `json:"RESALE_TRIG_PRICE" db:"ResaleTrigPrice"`
RedeemTrigPrice float64 `json:"REDEEM_TRIG_PRICE" db:"RedeemTrigPrice"`
PBVRatio float64 `json:"PBV_RATIO" db:"PBVRatio"`
IBStartDate CustomTime `json:"IB_START_DATE" db:"IBStartDate"`
IBEndDate CustomTime `json:"IB_END_DATE" db:"IBEndDate"`
CashflowDate CustomTime `json:"CASHFLOW_DATE" db:"CashflowDate"`
CouponIR float64 `json:"COUPON_IR" db:"CouponIR"`
ParamName string `json:"PARAM_NAME" db:"ParamName"`
IssueType string `json:"ISSUE_TYPE" db:"IssueType"`
ExecuteReasonSH *string `json:"EXECUTE_REASON_SH" db:"ExecuteReasonSH"`
PaydayNew string `json:"PAYDAYNEW" db:"PaydayNew"`
CurrentBondPriceNew interface{} `json:"CURRENT_BOND_PRICENEW" db:"CurrentBondPriceNew"`
IsConvertStock string `json:"IS_CONVERT_STOCK" db:"IsConvertStock"`
IsRedeem string `json:"IS_REDEEM" db:"IsRedeem"`
IsSellback string `json:"IS_SELLBACK" db:"IsSellback"`
FirstProfit *float64 `json:"FIRST_PROFIT" db:"FirstProfit"`
}
type CustomTime struct {
time.Time
}
// 实现 driver.Valuer 接口
func (ct CustomTime) Value() (driver.Value, error) {
return ct.Time, nil
}
// 实现 sql.Scanner 接口
func (ct *CustomTime) Scan(value interface{}) error {
if value == nil {
ct.Time = time.Time{}
return nil
}
switch v := value.(type) {
case time.Time:
ct.Time = v
return nil
default:
return fmt.Errorf("cannot scan type %T into CustomTime", value)
}
}
// 实现 UnmarshalJSON 方法以支持自定义时间格式
func (ct *CustomTime) UnmarshalJSON(b []byte) error {
str := string(b)
str = str[1 : len(str)-1] // 去掉引号
if str == "null" {
return nil
}
// 使用正确的时间格式进行解析
parsedTime, err := time.Parse("2006-01-02 15:04:05", str)
if err != nil {
return err
}
ct.Time = parsedTime
return nil
}
type BondResponse struct {
Version string `json:"version"`
Result BondResult `json:"result"`
Success bool `json:"success"`
Message string `json:"message"`
Code int `json:"code"`
}
type BondResult struct {
Pages int `json:"pages"`
Data []BondData `json:"data"`
Count int `json:"count"`
}