credit_account.go 3.5 KB
package domain

import (
	"bytes"
	"fmt"
	"time"
)

// CreditAccount 账期结算单实体
type CreditAccount struct {
	// 账期结算单ID
	CreditAccountId int64 `json:"creditAccountId,string"`
	// 账期结算实付金额
	ActuallyPaidAmount float64 `json:"actuallyPaidAmount"`
	// 账期结算单号
	CreditAccountOrderNum string `json:"creditAccountOrderNum"`
	// 账期结算支付状态,1待支付,2已支付
	PaymentStatus int32 `json:"paymentStatus"`
	// 共创账期结算支付时间
	PaymentTime time.Time `json:"paymentTime"`
	// 账期结算金额
	SettlementAmount float64 `json:"settlementAmount"`
	// 共创账期结算时间
	SettlementTime time.Time `json:"settlementTime"`
	// 关联共创合约编号
	CooperationContractNumber string `json:"cooperationContractNumber"`
	// 参与人uid,包括承接人、推荐人、关联业务员
	Participator *Participator `json:"participator"`
	// 参与类型
	ParticipateType string `json:"participateType"`
	// 结算明细
	AccountDetail []*AccountDetail `json:"accountDetail"`
	// 产品金额统计
	GoodAmountCount float64 `json:"goodAmountCount"`
	// 支付凭证附件
	PaymentDocumentAttachments []*Attachment `json:"paymentDocumentAttachments"`
	// 数据所属组织机构
	Org *Org `json:"org"`
	// 公司
	Company *Company `json:"company"`
	// 操作人
	Operator *User `json:"operator"`
	// 操作时间
	OperateTime time.Time `json:"operateTime"`
	// 创建时间
	CreatedAt time.Time `json:"createdAt"`
	// 删除时间
	DeletedAt time.Time `json:"deletedAt"`
	// 更新时间
	UpdatedAt time.Time `json:"updatedAt"`
	//备注
	Remarks string `json:"remarks"`
}

type CreditAccountRepository interface {
	Save(creditAccount *CreditAccount) (*CreditAccount, error)
	Remove(creditAccount *CreditAccount) (*CreditAccount, error)
	FindOne(queryOptions map[string]interface{}) (*CreditAccount, error)
	Find(queryOptions map[string]interface{}) (int64, []*CreditAccount, error)
}

func (creditAccount *CreditAccount) Identify() interface{} {
	if creditAccount.CreditAccountId == 0 {
		return nil
	}
	return creditAccount.CreditAccountId
}

func (creditAccount *CreditAccount) Update(data map[string]interface{}) error {
	if actuallyPaidAmount, ok := data["actuallyPaidAmount"]; ok {
		creditAccount.ActuallyPaidAmount = actuallyPaidAmount.(float64)
	}
	if creditAccountOrderNum, ok := data["creditAccountOrderNum"]; ok {
		creditAccount.CreditAccountOrderNum = creditAccountOrderNum.(string)
	}
	if paymentStatus, ok := data["paymentStatus"]; ok {
		creditAccount.PaymentStatus = paymentStatus.(int32)
	}
	if paymentDocumentAttachments, ok := data["paymentDocumentAttachments"]; ok {
		creditAccount.PaymentDocumentAttachments = paymentDocumentAttachments.([]*Attachment)
	}
	if remarks, ok := data["remarks"]; ok {
		creditAccount.Remarks = remarks.(string)
	}
	if actuallyPaidAmount, ok := data["actuallyPaidAmount"]; ok {
		creditAccount.ActuallyPaidAmount = actuallyPaidAmount.(float64)
	}
	creditAccount.UpdatedAt = time.Now()
	return nil
}

func ConditionInContractNumbers(numbers []string) string {
	var sqlBuilder = bytes.NewBuffer(nil)
	l := len(numbers)
	for i := range numbers {
		sqlBuilder.WriteString(fmt.Sprintf(`account_detail @> '[{"cooperationContractNumber":"%v"}]' `, numbers[i]))
		if i < (l - 1) {
			sqlBuilder.WriteString(" OR ")
		}
	}
	return sqlBuilder.String()
	//var response = make([]map[string]string, 0)
	//for i := range numbers {
	//	response = append(response, map[string]string{
	//		"cooperationContractNumber": numbers[i],
	//	})
	//}
	//return fmt.Sprintf("account_detail <@'%v'", json.MarshalToString(response))
}