作者 陈志颖

修改pg/model和现金池领域

... ... @@ -7,14 +7,10 @@ import (
)
type ExchangeSuMoneyCommand struct {
// 兑换人UID
Uid int64 `json:"uid" valid:"Required"`
// 素币值
SuMoney float64 `json:"suMoney" valid:"Required"`
// 操作人UID
Operator int64 `json:"operator,omitempty"`
// 兑换描述
ExchangeDescription string `json:"exchangeDescription" valid:"Required"`
Uid int64 `json:"uid" valid:"Required"` // 兑换人UID
SuMoney float64 `json:"suMoney" valid:"Required"` // 素币值
Operator int64 `json:"operator,omitempty"` // 操作人UID
ExchangeDescription string `json:"exchangeDescription" valid:"Required"` // 兑换描述
}
func (exchangeSuMoneyCommand *ExchangeSuMoneyCommand) ValidateCommand() error {
... ...
... ... @@ -336,10 +336,10 @@ func (taskService *TaskService) AcceptanceTask(acceptanceTaskCommand *command.Ac
// 搜索任务
func (taskService *TaskService) SearchTask(searchTaskCommand *command.SearchTaskCommand) (interface{}, error) {
if err := searchTaskCommand.ValidateCommand(); err != nil {
if err := searchTaskCommand.ValidateCommand(); err != nil { // 校验搜索命令
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
transactionContext, err := factory.CreateTransactionContext(nil) // 工厂类创建事务上下文
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
... ...
... ... @@ -4,9 +4,12 @@ import "os"
var POSTGRESQL_DB_NAME = "mmm-worth"
var POSTGRESQL_USER = "postgres"
var POSTGRESQL_PASSWORD = "abc123456"
//var POSTGRESQL_PASSWORD = "abc123456"
//var POSTGRESQL_HOST = "127.0.0.1"
//var POSTGRESQL_PORT = "32432"
var POSTGRESQL_PASSWORD = "1993618jack"
var POSTGRESQL_HOST = "127.0.0.1"
var POSTGRESQL_PORT = "32432"
var POSTGRESQL_PORT = "5432"
var DISABLE_CREATE_TABLE = false
var DISABLE_SQL_GENERATE_PRINT = false
... ...
package domain
// 现金池信息
type CashPoolInfo struct {
type CashPool struct {
Cash float64 `json:"cash"` // 投入现金池的现金
ExchangedCash float64 `json:"exchangedCash"` // 已兑换的现金
UnExchangeCash float64 `json:"unExchangeCash"` // 未兑换的现金
... ...
package domain
import "time"
// 现金池事务记录
type CashPoolTransactionRecord struct {
CashPoolTransactionRecordId int64 `json:"cashPoolTransactionRecordId"` // 现金池事务记录ID
RecordType int `json:"recordType"` // 记录类型
CashPoolBeforeTransaction *CashPool `json:"cashPoolBeforeTransaction"` // 事务处理前现金池
CurrentCashPool *CashPool `json:"CurrentCashPool"` // 当前现金池
Cash float64 `json:"CashPool"` // 事务现金值
Operator *EmployeeInfo `json:"operator"` // 操作人
RecordDescription string `json:"recordDescription"` // 现金池事务记录描述
CreateTime time.Time `json:"createTime"` // 创建时间
}
type CashPoolTransactionRecordRepository interface {
Save(cashPoolTransactionRecord *CashPoolTransactionRecord) (*CashPoolTransactionRecord, error)
}
func (cashPoolTransactionRecord *CashPoolTransactionRecord) Identity() interface{} {
if cashPoolTransactionRecord.CashPoolTransactionRecordId == 0 {
return nil
}
return cashPoolTransactionRecord.CashPoolTransactionRecordId
}
// 计算当前现金池中的未兑换现金
func (cashPoolTransactionRecord *CashPoolTransactionRecord) TransferUnExchangeCash(cash float64) error {
cashPoolTransactionRecord.CurrentCashPool.UnExchangeCash += cash
return nil
}
\ No newline at end of file
... ...
package domain
import "time"
// 兑换活动
type ExchangeActivity struct {
ActivityId int64 `json:"activityId"` // 活动编号
ExchangedCash float64 `json:"exchangedCash"` // 已兑换的现金
ExchangedSuMoney float64 `json:"exchangedSuMoney"` // 已兑换的素币
Rate float64 `json:"rate"` // 兑换汇率
ExchangeActivityId int64 `json:"exchangeActivityId"` // 兑换素币活动编号
ExchangeActivityName string `json:"exchangeActivityName"` // 兑换素币活动名称
CompanyId int64 `json:"companyId"` // 公司ID
ExchangedCash float64 `json:"exchangedCash"` // 已兑换的现金
ExchangedSuMoney float64 `json:"exchangedSuMoney"` // 已兑换的素币
CreateTime time.Time `json:"createTime"` // 创建兑换素币活动时间
Deadline time.Time `json:"deadline"` // 兑换素币活动截止时间
CountDown string `json:"countDown"` // 兑换素币活动结束倒计时
Rate float64 `json:"rate"` // 兑换汇率
LastRate float64 `json:"lastRate"` // 上期兑换汇率
ExchangeSuMoneyList []*ExchangePerson `json:"exchangeSuMoneyList"` // 素币兑换清单
}
type ExchangeActivityRepository interface {
... ... @@ -16,13 +25,23 @@ type ExchangeActivityRepository interface {
}
func (activity *ExchangeActivity) Identity() interface{} {
if activity.ActivityId == 0 {
if activity.ExchangeActivityId == 0 {
return nil
}
return activity.ActivityId
return activity.ExchangeActivityId
}
func (activity *ExchangeActivity) TransferSuMoney(rate float64) error {
activity.ExchangedSuMoney = activity.ExchangedCash * rate
return nil
}
func (activity *ExchangeActivity) TransferLastRate(lastRate float64) error {
activity.LastRate = lastRate
return nil
}
func (activity *ExchangeActivity) TransferCountDown() error {
activity.CountDown = string(time.Until(activity.Deadline))
return nil
}
... ...
... ... @@ -36,6 +36,9 @@ func init() {
(*models.RejectTaskRecord)(nil),
(*models.Notification)(nil),
(*models.SentNotification)(nil),
(*models.ExchangeActivities)(nil),
(*models.CashPoolTransactionRecord)(nil),
(*models.ExchangePerson)(nil),
} {
err := DB.CreateTable(model, &orm.CreateTableOptions{
Temp: false,
... ...
... ... @@ -6,6 +6,13 @@ import (
)
type CashPoolTransactionRecord struct {
TableName string `pg:"cash_pool"`
CreateTime time.Time // 创建时间
TableName string `pg:"cash_pool_transaction_records,alias:cash_pool_transaction_record"`
Id int64 `pg:",pk"` // 现金池事务记录ID
RecordType int // 记录类型
CashPoolBeforeTransaction *domain.CashPoolInfo // 事务处理前现金池
CurrentCashPool *domain.CashPoolInfo // 当前现金池
Cash float64 // 事务现金值
Operator *domain.EmployeeInfo // 操作人
RecordDescription string // 现金投入事务记录描述
CreateTime time.Time // 创建时间
}
... ...
package models
import (
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
"time"
)
type ExchangeActivities struct {
TableName string `pg:"exchange_activities,alias:exchange_activity"`
Id int64 `pg:",pk"` // 兑换活动ID
CompanyId int64 // 公司ID
ActivityName string // 兑换活动名称
ActivityStart time.Time // 兑换活动开始时间
ActivityEnd time.Time // 兑换活动结束时间
ActivityPeriod string // 兑换活动持续时间
ExchangedCash float64 // 已兑换现金
ExchangedSuMoney float64 // 已兑换素币
ExchangeRate float64 // 兑换汇率
ExchangeSuMoneyList []*domain.ExchangePerson // 素币兑换人员清单
Sponsor *domain.EmployeeInfo // 活动发布人
CreateTime time.Time // 创建时间
}
\ No newline at end of file
... ...
package repository
import (
"github.com/go-pg/pg"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
)
type CashPoolTransactionRecordRepository struct {
transactionContext *pgTransaction.TransactionContext
}
func (repository *CashPoolTransactionRecordRepository) Save(cashPoolTransactionRecord *domain.CashPoolTransactionRecord) (*domain.CashPoolTransactionRecord, error) {
tx := repository.transactionContext.PgTx
if cashPoolTransactionRecord.Identity() == nil {
if _, err := tx.QueryOne(
pg.Scan(&cashPoolTransactionRecord.CashPoolTransactionRecordId, &cashPoolTransactionRecord.RecordType, &cashPoolTransactionRecord.Cash, &cashPoolTransactionRecord.CashPoolBeforeTransaction, &cashPoolTransactionRecord.CurrentCashPool, &cashPoolTransactionRecord.Operator, &cashPoolTransactionRecord.CreateTime, &cashPoolTransactionRecord.RecordDescription),
"INSERT INTO cash_pool_transaction_records ()"); err != nil {
return cashPoolTransactionRecord, err
}
} else {
if _, err := tx.QueryOne(
pg.Scan(&cashPoolTransactionRecord.CashPoolTransactionRecordId, &cashPoolTransactionRecord.RecordType, &cashPoolTransactionRecord.Cash, &cashPoolTransactionRecord.CashPoolBeforeTransaction, &cashPoolTransactionRecord.CurrentCashPool, &cashPoolTransactionRecord.Operator, &cashPoolTransactionRecord.CreateTime, &cashPoolTransactionRecord.RecordDescription),
"UPDATE cash_pool_transaction_records SET "); err != nil {
return cashPoolTransactionRecord, err
}
}
return cashPoolTransactionRecord, nil
}
\ No newline at end of file
... ...
package controllers
import (
"github.com/astaxie/beego"
)
type CashPoolController struct {
beego.Controller
}
/**
* 现金池投入
*/
func (controller *CashPoolController) CashInput() {
}
/**
* 返回兑换活动列表
*/
func (controller *CashPoolController) ListExchangeActivities () {
}
/**
* 更新兑换活动信息
*/
func (controller *CashPoolController) UpdateExchangeActivities () {
}
/**
* 新增兑换活动
*/
func (controller *CashPoolController) CreateExchangeActivities () {
}
/**
* 删除兑换活动
*/
func (controller *CashPoolController) DeleteExchangeActivities () {
}
/**
* 搜索兑换素币活动
*/
func (controller *CashPoolController) searchExchangeActivities () {
}
/**
* 兑换活动数据统计
*/
func (controller *CashPoolController) exchangeActivitiesStatistics () {
}
/**
* 获取素币兑换清单
*/
func (controller *CashPoolController) ListExchangeList () {
}
/**
* 新增素币兑换清单
*/
func (controller *CashPoolController) CreateExchangeList () {
}
/**
* 更新素币兑换清单
*/
func (controller *CashPoolController) UpdateExchangeList () {
}
/**
* 删除素币兑换清单
*/
func (controller *CashPoolController) DeleteExchangeList () {
}
/**
* 搜索素币兑换清单
*/
func (controller *CashPoolController) searchExchangeList () {
}
/**
* 导出素币兑换清单
*/
func (controller *CashPoolController) ExportExchangeList () {
}
/**
* 导入素币兑换清单
*/
func (controller *CashPoolController) ImportExchangeList () {
}
... ...
package routers
// TODO
//func init() {
// /*****************************************现金池**********************************/
// beego.Router("/", &controllers.ConfigController{}, "POST:CashInput") // 现金池投入
// beego.Router("/cash_pool/input", &controllers.ConfigController{}, "POST:CashInput") // 现金池投入
//
// /*****************************************兑换活动*********************************/
// beego.Router("/", &controllers.ConfigController{}, "GET:ListExchangeActivities") // 返回兑换活动列表
// beego.Router("/", &controllers.ConfigController{}, "PUT:UpdateExchangeActivities") // 更新兑换活动信息
// beego.Router("/", &controllers.ConfigController{}, "POST:CreateExchangeActivities") // 新增兑换活动
// beego.Router("/", &controllers.ConfigController{}, "DELETE:DeleteExchangeActivities") // 删除兑换活动
// beego.Router("/", &controllers.ConfigController{}, "POST:SearchExchangeActivities") // 搜索兑换素币活动
// beego.Router("/", &controllers.ConfigController{}, "GET:ExchangeActivitiesStatistics") // 兑换活动数据统计
// beego.Router("/cash_pool/", &controllers.ConfigController{}, "GET:ListExchangeActivities") // 返回兑换活动列表
// beego.Router("/cash_pool/:aid", &controllers.ConfigController{}, "PUT:UpdateExchangeActivities") // 编辑兑换活动信息
// beego.Router("/cash_pool/", &controllers.ConfigController{}, "POST:CreateExchangeActivities") // 新增兑换活动
// beego.Router("/cash_pool/:aid", &controllers.ConfigController{}, "DELETE:DeleteExchangeActivities") // 删除兑换活动
//
// /*****************************************兑换素币清单****************************/
// beego.Router("/", &controllers.ConfigController{}, "GET:ListExchangeList") // 返回素币兑换清单列表
// beego.Router("/", &controllers.ConfigController{}, "GET:GetExchangeList") // 返回素币兑换清单
// beego.Router("/", &controllers.ConfigController{}, "POST:CreateExchangeList") // 新增素币兑换清单
// beego.Router("/", &controllers.ConfigController{}, "PUT:UpdateExchangeList") // 更新素币兑换清单
// beego.Router("/", &controllers.ConfigController{}, "DELETE:RemoveExchangeList") // 删除素币兑换清单
// beego.Router("/", &controllers.ConfigController{}, "POST:SearchExchangeList") // 搜索素币兑换记录
// beego.Router("/", &controllers.ConfigController{}, "POST:ExportExchangeList") // 导出素币兑换清单
// beego.Router("/", &controllers.ConfigController{}, "POST:ImportExchangeList") // 导入素币兑换清单
// beego.Router("/cash_pool/exchange", &controllers.ConfigController{}, "GET:ListExchangeList") // 返回素币兑换清单
// beego.Router("/cash_pool/exchange", &controllers.ConfigController{}, "POST:CreateExchangeList") // 新增素币兑换清单列表
// beego.Router("/cash_pool/exchange/:eid", &controllers.ConfigController{}, "PUT:UpdateExchangeList") // 编辑素币兑换清单
// beego.Router("/cash_pool/exchange/:eid", &controllers.ConfigController{}, "DELETE:RemoveExchangeList") // 删除素币兑换清单
// beego.Router("/cash_pool/export", &controllers.ConfigController{}, "POST:ExportExchangeList") // 导出素币兑换清单
// beego.Router("/cash_pool/import", &controllers.ConfigController{}, "POST:ImportExchangeList") // 导入素币兑换清单
//}
\ No newline at end of file
... ...
package cash_pool
import (
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg"
)
var _ = Describe("投入现金", func() {
Describe("投入现金并更新现金池数据", func() {
Context("提交正确的现金值(>=已兑换的现金)", func() {
It("返回现金池数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"cashAmount": 100,
}
httpExpect.POST("/cash_pool/input").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM ")
Expect(err).NotTo(HaveOccurred())
})
})
\ No newline at end of file
... ...
package cashPool
package cash_pool
import (
"github.com/onsi/ginkgo"
... ... @@ -13,14 +13,14 @@ import (
)
func TestConfig(t *testing.T) {
gomega.RegisterFailHandler(Fail)
ginkgo.RunSpecs()
gomega.RegisterFailHandler(ginkgo.Fail)
ginkgo.RunSpecs(t, "Beego Port Cash Pool Correlations Test Case Suite")
}
var handler http.Handler
var server *httptest.Server
var _ = BeforeSuite(func() {
var _ = ginkgo.BeforeSuite(func() {
handler = beego.BeeApp.Handlers
server = httptest.NewServer(handler)
})
... ...