作者 陈志颖

feat:修改基础设施层资源库,更新应用层素币管理模块,完善增删改查功能

... ... @@ -3,6 +3,7 @@ module gitlab.fjmaimaimai.com/linmadan/mmm-worth
go 1.14
require (
github.com/360EntSecGroup-Skylar/excelize/v2 v2.3.1
github.com/ajg/form v1.5.1 // indirect
github.com/astaxie/beego v1.12.1
github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072 // indirect
... ...
github.com/360EntSecGroup-Skylar/excelize v1.4.1 h1:l55mJb6rkkaUzOpSsgEeKYtS6/0gHwBYyfo5Jcjv/Ks=
github.com/360EntSecGroup-Skylar/excelize/v2 v2.3.1 h1:j56fC19WoD3z+u+ZHxm2XwRGyS1XmdSMk7058BLhdsM=
github.com/360EntSecGroup-Skylar/excelize/v2 v2.3.1/go.mod h1:gXEhMjm1VadSGjAzyDlBxmdYglP8eJpYWxpwJnmXRWw=
github.com/DataDog/zstd v1.3.6-0.20190409195224-796139022798/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo=
github.com/Knetic/govaluate v3.0.0+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
github.com/OwnLocal/goes v1.0.0/go.mod h1:8rIFjBGTue3lCU0wplczcUgt9Gxgrkkrw7etMIcn8TM=
... ... @@ -84,6 +87,8 @@ github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-sqlite3 v1.10.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
github.com/moul/http2curl v1.0.0 h1:dRMWoAtb+ePxMlLkrCbAqh4TlPHXvoGUSQ323/9Zahs=
github.com/moul/http2curl v1.0.0/go.mod h1:8UbvGypXm98wA/IqH45anm5Y2Z6ep6O31QGOAZ3H0fQ=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
... ... @@ -98,6 +103,10 @@ github.com/pkg/profile v1.2.1/go.mod h1:hJw3o1OdXxsrSjjVksARp5W95eeEaEfptyVZyv6J
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
github.com/richardlehane/mscfb v1.0.3 h1:rD8TBkYWkObWO0oLDFCbwMeZ4KoalxQy+QgniCj3nKI=
github.com/richardlehane/mscfb v1.0.3/go.mod h1:YzVpcZg9czvAuhk9T+a3avCpcFPMUWm7gK3DypaEsUk=
github.com/richardlehane/msoleps v1.0.1 h1:RfrALnSNXzmXLbGct/P2b4xkFz4e8Gmj/0Vj9M9xC1o=
github.com/richardlehane/msoleps v1.0.1/go.mod h1:BWev5JBpU9Ko2WAgmZEuiz4/u3ZYTKbjLycmwiWUfWg=
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644 h1:X+yvsM2yrEktyI+b2qND5gpH8YhURn0k8OCaeRnkINo=
... ... @@ -119,6 +128,7 @@ github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/syndtr/goleveldb v0.0.0-20181127023241-353a9fca669c/go.mod h1:Z4AUp2Km+PwemOoO/VB5AOx9XSsIItzFjoJlOSiYmn0=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
... ... @@ -134,6 +144,8 @@ github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 h1:EzJWgHo
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ=
github.com/xeipuuv/gojsonschema v1.2.0 h1:LhYJRs+L4fBtjZUfuSZIKGeVu0QRy8e5Xi7D17UxZ74=
github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y=
github.com/xuri/efp v0.0.0-20200605144744-ba689101faaf h1:spotWVWg9DP470pPFQ7LaYtUqDpWEOS/BUrSmwFZE4k=
github.com/xuri/efp v0.0.0-20200605144744-ba689101faaf/go.mod h1:uBiSUepVYMhGTfDeBKKasV4GpgBlzJ46gXUBAqV8qLk=
github.com/yalp/jsonpath v0.0.0-20180802001716-5cc68e5049a0 h1:6fRhSjgLCkTD3JnJxvaJ4Sj+TYblw757bqYgZaOq5ZY=
github.com/yalp/jsonpath v0.0.0-20180802001716-5cc68e5049a0/go.mod h1:/LWChgwKmvncFJFHJ7Gvn9wZArjbV5/FppcK2fKk/tI=
github.com/yudai/gojsondiff v1.0.0 h1:27cbfqXLVEJ1o8I6v3y9lg8Ydm53EKqHXAOMxEGlCOA=
... ... @@ -150,6 +162,10 @@ golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191029031824-8986dd9e96cf h1:fnPsqIDRbCSgumaMCRpoIoF2s4qxv0xSSS0BVZUE/ss=
golang.org/x/crypto v0.0.0-20191029031824-8986dd9e96cf/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a h1:vclmkQCjlDX5OydZ9wv8rBCcS0QyQY66Mpf/7BZbInM=
golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/image v0.0.0-20200922025426-e59bae62ef32/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
... ... @@ -160,6 +176,8 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL
golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20190923162816-aa69164e4478 h1:l5EDrHhldLYb3ZRHDUhXF7Om7MvYXnkV9/iQNo1lX6g=
golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200904194848-62affa334b73 h1:MXfv8rhZWmFeqX3GNZRsd6vOLoaCHjYEX3qkRo3YBUA=
golang.org/x/net v0.0.0-20200904194848-62affa334b73/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
... ... @@ -173,9 +191,13 @@ golang.org/x/sys v0.0.0-20191010194322-b09406accb47/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae h1:/WDfKMnPU+m5M4xB+6x4kaepxRw6jWvR5iDRdvjHgy8=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd h1:xhmwyvizuTgC2qz7ZlMluP20uW+C3Rm0FD/WLDX8884=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
... ... @@ -198,5 +220,6 @@ gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
mellium.im/sasl v0.2.1 h1:nspKSRg7/SyO0cRGY71OkfHab8tf9kCts6a6oTDut0w=
mellium.im/sasl v0.2.1/go.mod h1:ROaEDLQNuf9vjKqE1SrAfnsobm2YKXT1gnN1uDp1PjQ=
... ...
... ... @@ -28,3 +28,11 @@ func CreateNotificationDao(options map[string]interface{}) (*dao.NotificationDao
}
return dao.NewNotificationDao(transactionContext)
}
func CreateCashPoolDao(options map[string]interface{}) (*dao.CashPoolDao, error) {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pg.TransactionContext)
}
return dao.NewCashPoolDao(transactionContext)
}
\ No newline at end of file
... ...
... ... @@ -110,13 +110,5 @@ func CreateExchangeSuMoneyService(options map[string]interface{}) (service.Excha
return domainService.NewExchangeSuMoneyService(transactionContext)
}
func CreateInputCashPoolService(options map[string]interface{}) (service.InputCashPoolService, error) {
var transactionContext *pgTransaction.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pgTransaction.TransactionContext)
}
return domainService.NewCashPoolService(transactionContext)
}
... ...
... ... @@ -216,16 +216,16 @@ func (statisticsService *StatisticsService) SystemSuMoneyStatistics(systemSuMone
transactionContext.RollbackTransaction()
}()
var employeeDao *dao.EmployeeDao
if value, err := factory.CreateEmployeeDao(map[string]interface{}{
var cashPoolDao *dao.CashPoolDao
if value, err := factory.CreateCashPoolDao(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
employeeDao = value
cashPoolDao = value
}
if systemSuMoneyStatistics, err := employeeDao.CalculateSystemCash(systemSuMoneyStatisticsCommand.CompanyId); err != nil {
if systemSuMoneyStatistics, err := cashPoolDao.CalculateSystemCash(systemSuMoneyStatisticsCommand.CompanyId); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
... ...
... ... @@ -8,14 +8,15 @@ import (
// 创建现金池
type CreateCashPoolCommand struct {
//Uid int64 `json:"uid"` // 统一用户id
//CashPoolId int64 `json:"cashPoolId" valid:"Required"` // 现金池ID
CompanyId int64 `json:"companyId" valid:"Required"` // 公司ID
CompanyId int64 `json:"companyId"` // 公司ID
Cash float64 `json:"cash" valid:"Required"` // 投入的现金值
ExchangedCash float64 `json:"exchangedCash,omitempty"` // 现金池已兑换现金值
UnExchangeCash float64 `json:"unExchangeCash,omitempty"` // 现金池未兑换现金值
ExchangedSuMoney float64 `json:"exchangedSuMoney,omitempty"` // 现金池已兑换素币值
UnExchangeSuMoney float64 `json:"unExchangeSuMoney,omitempty"` // 现金池未兑换素币值
Operator int64 `json:"operator,omitempty"` // 操作人UID
//ExchangedCash float64 `json:"exchangedCash,omitempty"` // 现金池已兑换现金值
//UnExchangeCash float64 `json:"unExchangeCash,omitempty"` // 现金池未兑换现金值
//ExchangedSuMoney float64 `json:"exchangedSuMoney,omitempty"` // 现金池已兑换素币值
//UnExchangeSuMoney float64 `json:"unExchangeSuMoney,omitempty"` // 现金池未兑换素币值
//Operator int64 `json:"operator,omitempty"` // 操作人UID
}
func (createCashPoolCommand *CreateCashPoolCommand) ValidateCommand() error {
... ...
... ... @@ -3,7 +3,6 @@ package command
import (
"fmt"
"github.com/astaxie/beego/validation"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
"time"
)
... ... @@ -11,13 +10,14 @@ import (
type CreateExchangeCashActivityCommand struct {
CompanyId int64 `json:"companyId" valid:"Required"` // 公司id
ExchangeActivityName string `json:"exchangeActivityName"` // 活动名称
CashPool *domain.CashPool `json:"cashPool"` // 兑换现金活动关联的现金池,最新的现金池
//CashPool *domain.CashPool `json:"cashPool"` // 兑换现金活动关联的现金池,最新的现金池
Deadline time.Time `json:"deadline"` // 活动截止时间
CountDown int64 `json:"countDown"` // 活动倒计时
ExchangedSuMoney float64 `json:"exchangedSuMoney"` // 已兑换素币
ExchangedCash float64 `json:"exchangedCash"` // 已兑换现金
ExchangeRate float64 `json:"exchangeRate"` // 兑换汇率
ExchangeCashPeople []*domain.ExchangeCashPersonList `json:"exchangeList"` // 兑换活动清单
CreateTime time.Time `json:"createTime"` // 创建时间
//ExchangeCashPeople []*domain.ExchangeCashPersonList `json:"exchangeList"` // 兑换活动清单
}
func (createExchangeActivityCommand *CreateExchangeCashActivityCommand) ValidateCommand() error {
... ...
... ... @@ -3,20 +3,19 @@ package command
import (
"fmt"
"github.com/astaxie/beego/validation"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
"time"
)
type UpdateExchangeCashActivityCommand struct {
ExchangeCashActivityId int64 `json:"exchangeCashActivityId"` // 兑换现金活动id
CompanyId int64 `json:"companyId" valid:"Required"` // 公司id
//CompanyId int64 `json:"companyId" valid:"Required"` // 公司id
ExchangeActivityName string `json:"exchangeActivityName"` // 活动名称
Deadline time.Time `json:"deadline"` // 活动截止时间
CountDown int64 `json:"countDown"` // 活动倒计时
ExchangedSuMoney float64 `json:"exchangedSuMoney"` // 已兑换素币
ExchangedCash float64 `json:"exchangedCash"` // 已兑换现金
ExchangeRate float64 `json:"exchangeRate"` // 兑换汇率
ExchangeCashPeople []*domain.ExchangeCashPersonList `json:"exchangeCashPeople"` // 兑换活动清单
//ExchangeCashPeople []*domain.ExchangeCashPersonList `json:"exchangeCashPeople"` // 兑换活动清单
}
func (updateExchangeCashActivity *UpdateExchangeCashActivityCommand) ValidateCommand() error {
... ...
... ... @@ -2,13 +2,14 @@ package service
import (
"fmt"
"github.com/linmadan/egglib-go/utils/tool_funs"
"time"
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/factory"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/suMoney/command"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/suMoney/query"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain/service"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/dao"
)
... ... @@ -16,93 +17,104 @@ import (
type CashPoolService struct {
}
// 投入现金
func (cashPoolService *CashPoolService) OperationCashPool(createCashPoolCommand *command.CreateCashPoolCommand) (interface{}, error) {
// 投入现金池
func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *command.CreateCashPoolCommand) (interface{}, error) {
// 校验命令
if err := createCashPoolCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
// 新建现金池事务
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var employeeDao *dao.EmployeeDao
if value, err := factory.CreateEmployeeDao(map[string]interface{}{
// 新建现金池数据访问对象
var cashPoolDao *dao.CashPoolDao
if value, err := factory.CreateCashPoolDao(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
employeeDao = value
cashPoolDao = value
}
// 获取系统已兑换现金值
var systemExchangedCash float64
if value, err := employeeDao.CalculateSystemCash(createCashPoolCommand.CompanyId); err != nil {
if value, err := cashPoolDao.CalculateSystemCash(createCashPoolCommand.CompanyId); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
systemExchangedCash = value
}
// 获取系统素币兑换情况
var (
systemChangedSuMoney float64
systemUnChangeSuMoney float64
)
if value1, value2, err := employeeDao.CalculateSystemSuMoney(createCashPoolCommand.CompanyId); err != nil {
if value1, value2, err := cashPoolDao.CalculateSystemSuMoney(createCashPoolCommand.CompanyId); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
systemChangedSuMoney = value1
systemUnChangeSuMoney = value2
}
var inputCashPoolService service.InputCashPoolService
newCashPool := &domain.CashPool{
CompanyId: createCashPoolCommand.CompanyId,
Cash: createCashPoolCommand.Cash,
ExchangedCash: systemExchangedCash,
UnExchangeCash: 0,
ExchangedSuMoney: systemChangedSuMoney,
UnExchangeSuMoney: systemUnChangeSuMoney,
Rate: 0,
CreateTime: time.Now(),
}
if value, err := factory.CreateInputCashPoolService(map[string]interface{}{
var cashPoolRepository domain.CashPoolRepository
if value, err := factory.CreateCashPoolRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
inputCashPoolService = value
cashPoolRepository = value
}
if task, err := inputCashPoolService.Input(createCashPoolCommand.CompanyId, createCashPoolCommand.Operator, createCashPoolCommand.Cash, systemChangedSuMoney, systemUnChangeSuMoney, systemExchangedCash); err != nil {
if activity, err := cashPoolRepository.Save(newCashPool); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return task, nil
return activity, nil
}
}
// 返回现金池
func (cashPoolService *CashPoolService) CashPool(getCashPoolQuery *query.GetCashPoolQuery) (interface{}, error) {
func (cashPoolService *CashPoolService) GetCashPool(getCashPoolQuery *query.GetCashPoolQuery) (interface{}, error) {
if err := getCashPoolQuery.ValidateQuery(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
// 新建事务
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
// 现金池资源库
var cashPoolRepository domain.CashPoolRepository
if value, err := factory.CreateCashPoolRepository(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -111,274 +123,457 @@ func (cashPoolService *CashPoolService) CashPool(getCashPoolQuery *query.GetCash
} else {
cashPoolRepository = value
}
cashPool, err := cashPoolRepository.FindOne(map[string]interface{}{})
if err != nil {
if count, cashPools, err := cashPoolRepository.Find(tool_funs.SimpleStructToMap(getCashPoolQuery)); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if cashPool == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getCashPoolQuery.CompanyId)))
} else {
return cashPool, nil
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return map[string]interface{}{
"count": count,
"cashPools": cashPools,
}, nil
}
}
// TODO 返回兑换现金活动
func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCashActivityQuery *query.ListExchangeCashActivityQuery) (interface{}, error) {
if err := listExchangeCashActivityQuery.ValidateQuery(); err != nil {
// 新增兑换现金活动
func (cashPoolService *CashPoolService) CreateExchangeCashActivity(createExchangeCashActivityCommand *command.CreateExchangeCashActivityCommand) (interface{}, error) {
// 校验新增任务命令
if err := createExchangeCashActivityCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
// 新建校验任务事务
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
return nil, nil
}
// TODO 新增兑换现金活动
func (cashPoolService *CashPoolService) CreateExchangeCashActivity(createExchangeCashActivityCommand *command.CreateExchangeCashActivityCommand) (interface{}, error) {
if err := createExchangeCashActivityCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
// 创建兑换活动
newActivity := &domain.ExchangeCashActivity{
ExchangeActivityName: createExchangeCashActivityCommand.ExchangeActivityName,
CompanyId: createExchangeCashActivityCommand.CompanyId,
ExchangedCash: createExchangeCashActivityCommand.ExchangedCash,
ExchangedSuMoney: createExchangeCashActivityCommand.ExchangedSuMoney,
Deadline: createExchangeCashActivityCommand.Deadline,
CountDown: createExchangeCashActivityCommand.CountDown,
Rate: createExchangeCashActivityCommand.ExchangeRate,
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
// 兑换活动资源库
var exchangeCashActivityRepository domain.ExchangeActivityRepository
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
exchangeCashActivityRepository = value
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
if activity, err := exchangeCashActivityRepository.Save(newActivity); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return activity, nil
}
defer func() {
transactionContext.RollbackTransaction()
}()
return nil, nil
}
// TODO 返回兑换现金活动列表
func (cashPoolService *CashPoolService) ExchangeCashActivityList(listExchangeCashActivityQuery *query.ListExchangeCashActivityQuery) (interface{}, error) {
// 返回兑换现金活动列表
func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCashActivityQuery *query.ListExchangeCashActivityQuery) (interface{}, error) {
if err := listExchangeCashActivityQuery.ValidateQuery(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
return nil, nil
var cashPoolRepository domain.CashPoolRepository
if value, err := factory.CreateCashPoolRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
cashPoolRepository = value
}
if count, activities, err := cashPoolRepository.Find(tool_funs.SimpleStructToMap(listExchangeCashActivityQuery)); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return map[string]interface{}{
"count": count,
"activities": activities,
}, nil
}
}
// TODO 移除兑换现金活动
// 移除兑换现金活动
func (cashPoolService *CashPoolService) RemoveExchangeCashActivity(removeExchangeCashActivityCommand *command.RemoveExchangeCashActivityCommand) (interface{}, error) {
if err := removeExchangeCashActivityCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
return nil, nil
var exchangeCashActivityRepository domain.ExchangeActivityRepository
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
exchangeCashActivityRepository = value
}
activity, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": removeExchangeCashActivityCommand.ExchangeCashActivityId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if activity == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeExchangeCashActivityCommand.ExchangeCashActivityId)))
}
if activityDeleted, err := exchangeCashActivityRepository.Remove(activity); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return activityDeleted, nil
}
}
// TODO 返回兑换现金活动
// 返回兑换现金活动
func (cashPoolService *CashPoolService) GetExchangeCashActivity(getExchangeCashActivityQuery *query.GetExchangeCashActivityQuery) (interface{}, error) {
if err := getExchangeCashActivityQuery.ValidateQuery(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
return nil, nil
var exchangeCashActivityRepository domain.ExchangeActivityRepository
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
exchangeCashActivityRepository = value
}
activity, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": getExchangeCashActivityQuery.ExchangeCashActivityId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if activity == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getExchangeCashActivityQuery.ExchangeCashActivityId)))
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return activity, nil
}
}
// TODO 更新兑换现金活动
// 更新兑换现金活动
func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchangeCashActivityCommand *command.UpdateExchangeCashActivityCommand) (interface{}, error) {
if err := updateExchangeCashActivityCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
return nil, nil
var exchangeCashActivityRepository domain.ExchangeActivityRepository
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
exchangeCashActivityRepository = value
}
activity, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": updateExchangeCashActivityCommand.ExchangeCashActivityId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if activity == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashActivityCommand.ExchangeCashActivityId)))
}
if activity == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashActivityCommand.ExchangeCashActivityId)))
}
if err := activity.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
if activityUpdated, err := exchangeCashActivityRepository.Save(activity); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return activityUpdated, nil
}
}
// TODO 新建兑换现金人员
// 新建兑换现金人员
func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeCashPersonCommand *command.CreateExchangeCashPersonCommand) (interface{}, error) {
if err := createExchangeCashPersonCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
return nil, nil
// 创建兑换清单
newPerson := &domain.ExchangeCashPersonList{
CompanyId: createExchangeCashPersonCommand.ExchangeCashPerson.CompanyId,
ExchangeCashActivityId: createExchangeCashPersonCommand.ExchangeCashActivityId,
ExchangeCashPerson: createExchangeCashPersonCommand.ExchangeCashPerson,
ExchangedSuMoney: createExchangeCashPersonCommand.ExchangedSuMoney,
ExchangedCash: createExchangeCashPersonCommand.ExchangedCash,
}
// 兑换活动资源库
var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository
if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
exchangeCashPersonListRepository = value
}
if person, err := exchangeCashPersonListRepository.Save(newPerson); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return person, nil
}
}
// TODO 返回兑换现金人员
// 返回兑换现金人员
func (cashPoolService *CashPoolService) GetExchangeCashPerson(getExchangeCashPersonQuery *query.GetExchangeCashPersonQuery) (interface{}, error) {
if err := getExchangeCashPersonQuery.ValidateQuery(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
return nil, nil
var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository
if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
exchangeCashPersonListRepository = value
}
person, err := exchangeCashPersonListRepository.FindOne(map[string]interface{}{"personId": getExchangeCashPersonQuery.ExchangeCashPersonId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if person == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getExchangeCashPersonQuery.ExchangeCashPersonId)))
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return person, nil
}
}
// TODO 返回兑换现金人员列表
// 返回兑换现金人员列表
func (cashPoolService *CashPoolService) ListExchangeCashPerson(listExchangeCashPersonQuery *query.ListExchangeCashPersonQuery) (interface{}, error) {
if err := listExchangeCashPersonQuery.ValidateQuery(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
return nil, nil
var cashPoolRepository domain.CashPoolRepository
if value, err := factory.CreateCashPoolRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
cashPoolRepository = value
}
if count, people, err := cashPoolRepository.Find(tool_funs.SimpleStructToMap(listExchangeCashPersonQuery)); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return map[string]interface{}{
"count": count,
"people": people,
}, nil
}
}
// TODO 移除兑换现金人员
// 移除兑换现金人员
func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeCashPersonCommand *command.RemoveExchangeCashPersonCommand) (interface{}, error) {
if err := removeExchangeCashPersonCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
return nil, nil
var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository
if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
exchangeCashPersonListRepository = value
}
person, err := exchangeCashPersonListRepository.FindOne(map[string]interface{}{"personId": removeExchangeCashPersonCommand.ExchangeCashPersonId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if person == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeExchangeCashPersonCommand.ExchangeCashPersonId)))
}
if personDeleted, err := exchangeCashPersonListRepository.Remove(person); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return personDeleted, nil
}
}
// TODO 更新兑换现金人员
func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeCashCommand *command.UpdateExchangeCashPersonCommand) (interface{}, error) {
if err := updateExchangeCashCommand.ValidateCommand(); err != nil {
// 更新兑换现金人员
func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeCashPersonCommand *command.UpdateExchangeCashPersonCommand) (interface{}, error) {
if err := updateExchangeCashPersonCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
// TODO 新增流水记录
var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository
if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
exchangeCashPersonListRepository = value
}
return nil, nil
person, err := exchangeCashPersonListRepository.FindOne(map[string]interface{}{"personId": updateExchangeCashPersonCommand.ExchangeCashPersonId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if person == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashPersonCommand.ExchangeCashPersonId)))
}
if err := person.Update(tool_funs.SimpleStructToMap(updateExchangeCashPersonCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
if personUpdated, err := exchangeCashPersonListRepository.Save(person); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return personUpdated, nil
}
}
func NewCashPoolService(options map[string]interface{}) *CashPoolService {
... ...
... ... @@ -774,9 +774,12 @@ func (taskService *TaskService) GetRejectTaskRecord(getRejectTaskRecordQuery *qu
// 创建新任务
func (taskService *TaskService) CreateTask(createTaskCommand *command.CreateTaskCommand) (interface{}, error) {
// 校验创建任务命令
if err := createTaskCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
// 新建事务
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ... @@ -787,6 +790,8 @@ func (taskService *TaskService) CreateTask(createTaskCommand *command.CreateTask
defer func() {
transactionContext.RollbackTransaction()
}()
// 新建任务数据访问对象
var taskDao *dao.TaskDao
if value, err := factory.CreateTaskDao(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -795,6 +800,8 @@ func (taskService *TaskService) CreateTask(createTaskCommand *command.CreateTask
} else {
taskDao = value
}
// 获取任务发布者信息
var employeeRepository domain.EmployeeRepository
if value, err := factory.CreateEmployeeRepository(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -803,6 +810,7 @@ func (taskService *TaskService) CreateTask(createTaskCommand *command.CreateTask
} else {
employeeRepository = value
}
sponsor, err := employeeRepository.FindOne(map[string]interface{}{
"uid": createTaskCommand.Sponsor,
})
... ... @@ -812,6 +820,8 @@ func (taskService *TaskService) CreateTask(createTaskCommand *command.CreateTask
if sponsor == nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的发布者")
}
// 获取任务指派人
var assignedPerson *domain.EmployeeInfo
if createTaskCommand.AssignedPerson != 0 {
employee, err := employeeRepository.FindOne(map[string]interface{}{
... ... @@ -825,6 +835,8 @@ func (taskService *TaskService) CreateTask(createTaskCommand *command.CreateTask
}
assignedPerson = employee.EmployeeInfo
}
// 创建新任务
newTask := &domain.Task{
TaskStatus: domain.TASK_STATUS_UNRELEASED,
CompanyId: createTaskCommand.CompanyId,
... ... @@ -847,6 +859,7 @@ func (taskService *TaskService) CreateTask(createTaskCommand *command.CreateTask
PlannedCompletionTime: createTaskCommand.PlannedCompletionTime,
CreateTime: time.Now(),
}
var taskRepository domain.TaskRepository
if value, err := factory.CreateTaskRepository(map[string]interface{}{
"transactionContext": transactionContext,
... ...
... ... @@ -6,25 +6,25 @@ import "time"
type CashPool struct {
CashPoolId int64 `json:"cashPoolId"` // 现金池id
CompanyId int64 `json:"companyId"` // 公司id
Cash float64 `json:"cashPool"` // 投入现金池的现金
Cash float64 `json:"cash"` // 投入现金池的现金
ExchangedCash float64 `json:"exchangedCash"` // 已兑换的现金
UnExchangeCash float64 `json:"unExchangeCash"` // 未兑换的现金
ExchangedSuMoney float64 `json:"exchangedSuMoney"` // 已兑换的素币
UnExchangeSuMoney float64 `json:"unExchangeSuMoney"` // 未兑换的素币
Operator *EmployeeInfo `json:"operator"` // 操作人
//Operator *EmployeeInfo `json:"operator"` // 操作人
Rate float64 `json:"rate"` // 平均兑换汇率
CreateTime time.Time `json:"createTime"` // 现金投入现金池时间
}
type CashPoolRepository interface {
Save(cashPool *CashPool) (*CashPool, error)
FindOne(queryOptions map[string]interface{}) (*CashPool, error)
Find(queryOptions map[string]interface{}) (int64, []*CashPool, error)
}
func (cashPool *CashPool) Identity() interface{} {
if cashPool.CompanyId == 0 {
if cashPool.CashPoolId == 0 {
return nil
}
return cashPool.CompanyId
return cashPool.CashPoolId
}
... ...
... ... @@ -4,18 +4,18 @@ import "time"
// 兑换现金活动
type ExchangeCashActivity struct {
ExchangeCashActivityId int64 `json:"exchangeActivityId"` // 兑换现金活动id
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"` // 上期兑换汇率
Operator *EmployeeInfo `json:"operator"` // 活动发布人
ExchangeCashPeople []*ExchangeCashPersonList `json:"exchangeCashPeople"` // 兑换现金人员清单
ActivityId int64 `json:"activityId"` // 兑换现金活动id
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 int64 `json:"countDown"` // 兑换现金活动结束倒计时
Rate float64 `json:"rate"` // 兑换汇率
//LastRate float64 `json:"lastRate"` // 上期兑换汇率
//Operator *EmployeeInfo `json:"operator"` // 活动发布人
//ExchangeCashPeople []*ExchangeCashPersonList `json:"exchangeCashPeople"` // 兑换现金人员清单
}
type ExchangeActivityRepository interface {
... ... @@ -26,23 +26,29 @@ type ExchangeActivityRepository interface {
}
func (exchangeCashActivity *ExchangeCashActivity) Identity() interface{} {
if exchangeCashActivity.ExchangeCashActivityId == 0 {
if exchangeCashActivity.ActivityId == 0 {
return nil
}
return exchangeCashActivity.ExchangeCashActivityId
return exchangeCashActivity.ActivityId
}
func (exchangeCashActivity *ExchangeCashActivity) TransferSuMoney(rate float64) error {
exchangeCashActivity.ExchangedSuMoney = exchangeCashActivity.ExchangedCash * rate
// TODO
func (exchangeCashActivity *ExchangeCashActivity) Update(data map[string]interface{}) error {
return nil
}
func (exchangeCashActivity *ExchangeCashActivity) TransferLastRate(lastRate float64) error {
exchangeCashActivity.LastRate = lastRate
func (exchangeCashActivity *ExchangeCashActivity) TransferSuMoney(rate float64) error {
exchangeCashActivity.ExchangedSuMoney = exchangeCashActivity.ExchangedCash * rate
return nil
}
//func (exchangeCashActivity *ExchangeCashActivity) TransferLastRate(lastRate float64) error {
// exchangeCashActivity.LastRate = lastRate
// return nil
//}
func (exchangeCashActivity *ExchangeCashActivity) TransferCountDown() error {
exchangeCashActivity.CountDown = string(time.Until(exchangeCashActivity.Deadline))
exchangeCashActivity.CountDown = int64(time.Until(exchangeCashActivity.Deadline))
return nil
}
... ...
... ... @@ -22,4 +22,10 @@ func (exchangeCashPersonList *ExchangeCashPersonList) Identity() interface{} {
return nil
}
return exchangeCashPersonList.ExchangeCashPersonListId
}
// TODO
func (exchangeCashPersonList *ExchangeCashPersonList) Update(data map[string]interface{}) error {
return nil
}
\ No newline at end of file
... ...
package service
import (
coreDomain "github.com/linmadan/egglib-go/core/domain"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
)
type InputCashPoolService interface {
coreDomain.DomainEventPublisher
Input(companyId int64, operatorUid int64, cash float64, exchangedSuMoney float64, unExchangeSuMoney float64, exchangedCash float64) (*domain.CashPool, error)
}
package dao
import (
"fmt"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg/models"
)
type CashPoolDao struct {
transactionContext *pgTransaction.TransactionContext
}
// 计算系统素币
func (dao *CashPoolDao) CalculateSystemSuMoney(companyId int64) ( float64, float64, error) {
var systemUnExchangeSuMoney float64
var systemExchangedSuMoney float64
tx := dao.transactionContext.PgTx
employeeModel := new(models.Employee)
if err := tx.Model(employeeModel).
ColumnExpr("sum(employee.su_money) AS system_unExchange_su_money").
Where("employee.company_id = ?", companyId).
Select(&systemUnExchangeSuMoney); err != nil {
return 0, 0, err
}
exchangeCashActivityModel := new(models.ExchangeCashActivity)
if err := tx.Model(exchangeCashActivityModel).
ColumnExpr("sum(exchange_cash_activity.exchanged_su_money) AS system_changed_su_money").
Where("exchange_cash_activity.company_id = ?", companyId).
Select(&systemExchangedSuMoney); err != nil {
return 0, 0, err
}
return systemUnExchangeSuMoney, systemExchangedSuMoney, nil
}
// 计算系统已兑换现金
func (dao *CashPoolDao) CalculateSystemCash(companyId int64) (float64, error) {
var systemExchangedCash float64 // 系统已兑换现金
tx := dao.transactionContext.PgTx
exchangeCashActivityModel := new(models.ExchangeCashActivity)
if err := tx.Model(exchangeCashActivityModel).
ColumnExpr("sum(exchange_cash_activity.exchanged_cash) AS system_exchanged_cash").
Where("exchange_cash_activity.company_id = ?", companyId).
Select(&systemExchangedCash) ; err != nil {
return 0, err
}
return systemExchangedCash, nil
}
func NewCashPoolDao(transactionContext *pgTransaction.TransactionContext) (*CashPoolDao, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &CashPoolDao{
transactionContext: transactionContext,
}, nil
}
}
\ No newline at end of file
... ...
... ... @@ -143,49 +143,6 @@ func (dao *EmployeeDao) CalculateSuMoneyTransactionRecord(uid int64, transaction
}, nil
}
// 计算系统素币
func (dao *EmployeeDao) CalculateSystemSuMoney(companyId int64) ( float64, float64, error) {
var systemUnExchangeSuMoney float64
var systemExchangedSuMoney float64
tx := dao.transactionContext.PgTx
employeeModel := new(models.Employee)
if err := tx.Model(employeeModel).
ColumnExpr("sum(employee.su_money) AS system_unExchange_su_money").
Where("employee.company_id = ?", companyId).
Select(&systemUnExchangeSuMoney); err != nil {
return 0, 0, err
}
exchangeCashActivityModel := new(models.ExchangeCashActivity)
if err := tx.Model(exchangeCashActivityModel).
ColumnExpr("sum(exchange_cash_activity.exchanged_su_money) AS system_changed_su_money").
Where("exchange_cash_activity.company_id = ?", companyId).
Select(&systemExchangedSuMoney); err != nil {
return 0, 0, err
}
return systemUnExchangeSuMoney, systemExchangedSuMoney, nil
}
// 计算系统已兑换现金
func (dao *EmployeeDao) CalculateSystemCash(companyId int64) (float64, error) {
var systemExchangedCash float64 // 系统已兑换现金
tx := dao.transactionContext.PgTx
exchangeCashActivityModel := new(models.ExchangeCashActivity)
if err := tx.Model(exchangeCashActivityModel).
ColumnExpr("sum(exchange_cash_activity.exchanged_cash) AS system_exchanged_cash").
Where("exchange_cash_activity.company_id = ?", companyId).
Select(&systemExchangedCash) ; err != nil {
return 0, err
}
return systemExchangedCash, nil
}
func NewEmployeeDao(transactionContext *pgTransaction.TransactionContext) (*EmployeeDao, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
... ...
package domain_service
import (
"fmt"
coreDomain "github.com/linmadan/egglib-go/core/domain"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/repository"
"time"
)
type CashPoolService struct {
coreDomain.BaseEventPublisher
transactionContext *pgTransaction.TransactionContext
}
func (service *CashPoolService) Input(companyId int64, operatorUid int64, cash float64, systemUnExchangeSuMoney float64, systemExchangedSuMoney float64, systemExchangedCash float64) (*domain.CashPool, error) {
var cashPoolRepository domain.CashPoolRepository
var employeeRepository domain.EmployeeRepository
if repository, err := repository.NewEmployeeRepository(service.transactionContext); err != nil {
return nil, err
} else {
employeeRepository = repository
}
operator, err := employeeRepository.FindOne(map[string]interface{}{
"uid": operatorUid,
})
if err != nil {
return nil, err
}
if operator == nil {
return nil, fmt.Errorf("无效的操作者")
}
currentCashPool, err := cashPoolRepository.FindOne(map[string]interface{}{
"companyId": companyId,
})
if err != nil {
return nil, err
}
if currentCashPool.ExchangedCash > cash {
return nil, fmt.Errorf("当前投入现金少于系统已兑换现金值")
}
cashPoolInfo := &domain.CashPool{
CompanyId: companyId,
Cash: cash,
ExchangedCash: systemExchangedCash,
UnExchangeCash: currentCashPool.UnExchangeCash + cash,
ExchangedSuMoney: systemExchangedSuMoney,
UnExchangeSuMoney: systemUnExchangeSuMoney,
Rate: systemExchangedCash / systemExchangedSuMoney,
Operator: operator.EmployeeInfo,
CreateTime: time.Now(),
}
if cashPool, err := cashPoolRepository.Save(cashPoolInfo); err != nil {
return nil, err
} else {
return cashPool, nil
}
}
func NewCashPoolService(transactionContext *pgTransaction.TransactionContext) (*CashPoolService, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &CashPoolService{
transactionContext: transactionContext,
}, nil
}
}
\ No newline at end of file
... ... @@ -3,6 +3,7 @@ package models
type CashPool struct {
TableName string `pg:"cash_pools,alias:cash_pool"`
Id int64 `pg:",pk"` // 现金池id
Cash float64 // 投入的现金
CompanyId int64 // 公司id
ExchangedCash float64 // 系统已兑换现金
UnExchangeCash float64 // 系统未兑换现金
... ...
package models
import (
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
"time"
)
... ... @@ -11,12 +10,12 @@ type ExchangeCashActivity struct {
CompanyId int64 // 公司ID
ActivityName string // 兑换活动名称
Deadline time.Time // 兑换活动结束时间
CountDown string // 兑换活动结束倒计时
CountDown int64 // 兑换活动结束倒计时
ExchangedCash float64 // 已兑换现金
ExchangedSuMoney float64 // 已兑换素币
ExchangeRate float64 // 兑换汇率
LastExchangeRate float64 // 上期活动兑换汇率
ExchangeSuMoneyList []*domain.ExchangeCashPersonList `pg:",array"` // 素币兑换人员清单
Sponsor *domain.EmployeeInfo // 活动发布人
//LastExchangeRate float64 // 上期活动兑换汇率
//ExchangeSuMoneyList []*domain.ExchangeCashPersonList `pg:",array"` // 素币兑换人员清单
//Sponsor *domain.EmployeeInfo // 活动发布人
CreateTime time.Time // 创建时间
}
\ No newline at end of file
... ...
... ... @@ -17,14 +17,14 @@ func (repository *CashPoolRepository) Save(cashPool *domain.CashPool) (*domain.C
if cashPool.Identity() == nil {
if _, err := tx.QueryOne(
pg.Scan(&cashPool.CashPoolId, &cashPool.Cash, &cashPool.CompanyId, &cashPool.ExchangedCash, &cashPool.UnExchangeCash, &cashPool.ExchangedSuMoney, &cashPool.UnExchangeSuMoney, &cashPool.Rate),
"INSERT INTO cash_pool (cash, company_id, exchanged_cash, unExchange_cash, exchanged_su_money, unExchange_su_money, rate) VALUES (?, ?, ?, ?, ?, ?, ?) RETURNING id, company_id, exchanged_cash, unExchange_cash, exchanged_su_money, unExchange_su_money",
"INSERT INTO cash_pools (cash, company_id, exchanged_cash, un_exchange_cash, exchanged_su_money, un_exchange_su_money, rate) VALUES (?, ?, ?, ?, ?, ?, ?) RETURNING id, company_id, exchanged_cash, un_exchange_cash, exchanged_su_money, un_exchange_su_money, rate",
cashPool.Cash, cashPool.CompanyId, cashPool.ExchangedCash, cashPool.UnExchangeCash, cashPool.ExchangedSuMoney, cashPool.UnExchangeSuMoney, cashPool.Rate); err != nil {
return cashPool, err
}
} else {
if _, err := tx.QueryOne(
pg.Scan(&cashPool.CashPoolId, &cashPool.Cash, &cashPool.CompanyId, &cashPool.ExchangedCash, &cashPool.UnExchangeCash, &cashPool.ExchangedSuMoney, &cashPool.UnExchangeSuMoney, &cashPool.Rate),
"UPDATE cash_pool SET cash=?, company_id=? exchanged_cash, unExchange_cash, exchanged_su_money, unExchange_su_money, rate WHERE company_id=? RETURNING id, company_id, exchanged_cash, unExchange_cash, exchanged_su_money, unExchange_su_money, rate",
"UPDATE cash_pools SET cash=?, company_id=? exchanged_cash=?, un_exchange_cash=?, exchanged_su_money=?, un_exchange_su_money=?, rate=? WHERE company_id=? RETURNING id, company_id, exchanged_cash, un_exchange_cash, exchanged_su_money, un_exchange_su_money, rate",
cashPool.Cash, cashPool.CompanyId, cashPool.ExchangedCash, cashPool.UnExchangeCash, cashPool.ExchangedSuMoney, cashPool.UnExchangeSuMoney, cashPool.Rate, cashPool.Identity()); err != nil {
return cashPool, err
}
... ... @@ -32,25 +32,42 @@ func (repository *CashPoolRepository) Save(cashPool *domain.CashPool) (*domain.C
return cashPool, nil
}
func (repository *CashPoolRepository) FindOne(queryOptions map[string]interface{}) (*domain.CashPool, error) {
func (repository *CashPoolRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.CashPool, error) {
tx := repository.transactionContext.PgTx
cashPoolModel := new(models.CashPool)
query := tx.Model(cashPoolModel)
var cashPoolModels []*models.CashPool
cashPools := make([]*domain.CashPool, 0)
query := tx.Model(&cashPoolModels)
// 根据公司id查找现金池
if companyId, ok := queryOptions["companyId"]; ok {
query = query.Where("cash_pool.company_id = ?", companyId)
query = query.Where("cash_pools.company_id = ?", companyId)
}
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
} else {
return nil, err
if offset, ok := queryOptions["offset"]; ok {
offset := offset.(int)
if offset > -1 {
query = query.Offset(offset)
}
} else {
query = query.Offset(0)
}
if cashPoolModel.CompanyId == 0 {
return nil, nil
if limit, ok := queryOptions["limit"]; ok {
limit := limit.(int)
if limit > -1 {
query = query.Limit(limit)
}
} else {
return repository.transformPgModelToDomainModel(cashPoolModel)
query = query.Limit(20)
}
if count, err := query.Order("id DESC").SelectAndCount(); err != nil {
return 0, cashPools, err
} else {
for _, cashPoolModel := range cashPoolModels {
if cashPool, err := repository.transformPgModelToDomainModel(cashPoolModel); err != nil {
return 0, cashPools, err
} else {
cashPools = append(cashPools, cashPool)
}
}
return int64(count), cashPools, nil
}
}
... ... @@ -58,6 +75,12 @@ func (repository *CashPoolRepository) transformPgModelToDomainModel(cashPoolMode
return &domain.CashPool{
CashPoolId: cashPoolModel.Id,
CompanyId: cashPoolModel.CompanyId,
Cash: cashPoolModel.Cash,
ExchangedCash: cashPoolModel.ExchangedCash,
UnExchangeCash: cashPoolModel.UnExchangeCash,
ExchangedSuMoney: cashPoolModel.ExchangedSuMoney,
UnExchangeSuMoney: cashPoolModel.UnExchangeSuMoney,
Rate: cashPoolModel.Rate,
}, nil
}
... ...
... ... @@ -17,16 +17,16 @@ func (repository *ExchangeCashActivityRepository) Save(exchangeCashActivity *dom
tx := repository.transactionContext.PgTx
if exchangeCashActivity.Identity() == nil {
if _, err := tx.QueryOne(
pg.Scan(&exchangeCashActivity.ExchangeCashActivityId, &exchangeCashActivity.ExchangeActivityName),
"INSERT INTO exchange_cash_activity () VALUES () RETURNING id, " ,
exchangeCashActivity.ExchangeActivityName); err != nil {
pg.Scan(&exchangeCashActivity.ActivityId, &exchangeCashActivity.CompanyId, &exchangeCashActivity.ExchangeActivityName, &exchangeCashActivity.Deadline, &exchangeCashActivity.CountDown, &exchangeCashActivity.ExchangedCash, &exchangeCashActivity.ExchangedSuMoney, &exchangeCashActivity.Rate),
"INSERT INTO exchange_cash_activities ( company_id, activity_name, deadline, count_down, exchanged_cash, exchanged_su_money, exchange_rate) VALUES (?, ?, ?, ?, ?, ?, ? ) RETURNING id, company_id, activity_name, deadline, count_down, exchanged_cash, exchanged_su_money, exchange_rate" ,
exchangeCashActivity.CompanyId, exchangeCashActivity.ExchangeActivityName, exchangeCashActivity.Deadline, exchangeCashActivity.CountDown, exchangeCashActivity.ExchangedCash, exchangeCashActivity.ExchangedSuMoney, exchangeCashActivity.Rate); err != nil {
return exchangeCashActivity, err
}
} else {
if _, err := tx.QueryOne(
pg.Scan(&exchangeCashActivity.ExchangeCashActivityId, &exchangeCashActivity.ExchangeActivityName),
"UPDATE exchange_cash_activity SET exchange_activity_name=?, WHERE id=? RETURNING id, exchange_cash_activity_name",
exchangeCashActivity.ExchangeActivityName); err != nil {
pg.Scan(&exchangeCashActivity.ActivityId, &exchangeCashActivity.ExchangeActivityName),
"UPDATE exchange_cash_activities SET company_id=?, activity_name=?, deadline=?, count_down=?, exchanged_cash=?, exchanged_su_money=?, exchange_rate=?, create_time=?, WHERE id=? RETURNING id, company_id, activity_name, deadline, count_down, exchanged_cash, exchanged_su_money, exchange_rate",
exchangeCashActivity.CompanyId, exchangeCashActivity.ExchangeActivityName, exchangeCashActivity.Deadline, exchangeCashActivity.CountDown, exchangeCashActivity.ExchangedCash, exchangeCashActivity.ExchangedSuMoney, exchangeCashActivity.Rate); err != nil {
return exchangeCashActivity, err
}
}
... ... @@ -104,7 +104,7 @@ func (repository *ExchangeCashActivityRepository) Find(queryOptions map[string]i
func (repository *ExchangeCashActivityRepository) Remove(exchangeCashActivity *domain.ExchangeCashActivity) (*domain.ExchangeCashActivity, error) {
tx := repository.transactionContext.PgTx
exchangeCashActivityModel := new(models.ExchangeCashActivity)
exchangeCashActivity.ExchangeCashActivityId = exchangeCashActivity.Identity().(int64)
exchangeCashActivity.ActivityId = exchangeCashActivity.Identity().(int64)
if _, err := tx.Model(exchangeCashActivityModel).WherePK().Delete(); err != nil {
return exchangeCashActivity, err
}
... ... @@ -113,18 +113,18 @@ func (repository *ExchangeCashActivityRepository) Remove(exchangeCashActivity *d
func (repository *ExchangeCashActivityRepository) transformPgModelToDomainModel(exchangeCashActivity *models.ExchangeCashActivity) (*domain.ExchangeCashActivity, error) {
return &domain.ExchangeCashActivity{
ExchangeCashActivityId: exchangeCashActivity.Id,
ExchangeActivityName: exchangeCashActivity.ActivityName,
CompanyId: exchangeCashActivity.CompanyId,
ExchangedCash: exchangeCashActivity.ExchangedCash,
ExchangedSuMoney: exchangeCashActivity.ExchangedSuMoney,
CreateTime: exchangeCashActivity.CreateTime,
Deadline: exchangeCashActivity.Deadline,
CountDown: exchangeCashActivity.CountDown,
Rate: exchangeCashActivity.ExchangeRate,
LastRate: exchangeCashActivity.LastExchangeRate,
Operator: exchangeCashActivity.Sponsor,
ExchangeCashPeople: exchangeCashActivity.ExchangeSuMoneyList,
ActivityId: exchangeCashActivity.Id,
ExchangeActivityName: exchangeCashActivity.ActivityName,
CompanyId: exchangeCashActivity.CompanyId,
ExchangedCash: exchangeCashActivity.ExchangedCash,
ExchangedSuMoney: exchangeCashActivity.ExchangedSuMoney,
CreateTime: exchangeCashActivity.CreateTime,
Deadline: exchangeCashActivity.Deadline,
CountDown: exchangeCashActivity.CountDown,
Rate: exchangeCashActivity.ExchangeRate,
//LastRate: exchangeCashActivity.LastExchangeRate,
//Operator: exchangeCashActivity.Sponsor,
//ExchangeCashPeople: exchangeCashActivity.ExchangeSuMoneyList,
}, nil
}
func NewExchangeCashActivityRepository(transactionContext *pgTransaction.TransactionContext) (*ExchangeCashActivityRepository, error) {
... ...
... ... @@ -2,12 +2,14 @@ package controllers
import (
"encoding/json"
"fmt"
"github.com/360EntSecGroup-Skylar/excelize/v2"
"github.com/astaxie/beego"
"github.com/linmadan/egglib-go/web/beego/utils"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/suMoney/command"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/suMoney/query"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/suMoney/service"
"path"
)
type SuMoneyController struct {
... ... @@ -131,7 +133,7 @@ func (controller *SuMoneyController) CashInput() {
json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), createCashPoolCommand)
data, err := cashPoolService.OperationCashPool(createCashPoolCommand)
data, err := cashPoolService.CreateCashPool(createCashPoolCommand)
var response utils.JsonResponse
... ... @@ -146,13 +148,15 @@ func (controller *SuMoneyController) CashInput() {
}
// 返回现金池
func (controller *SuMoneyController) CashPool() {
func (controller *SuMoneyController) GetCashPool() {
cashPoolService := service.NewCashPoolService(nil)
getCashPoolQuery := &query.GetCashPoolQuery{}
json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), getCashPoolQuery)
//json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), getCashPoolQuery)
companyId, _ := controller.GetInt64("companyId")
getCashPoolQuery.CompanyId = companyId
data, err := cashPoolService.CashPool(getCashPoolQuery)
data, err := cashPoolService.GetCashPool(getCashPoolQuery)
var response utils.JsonResponse
... ... @@ -265,7 +269,7 @@ func (controller *SuMoneyController) RemoveExchangeActivities () {
}
// 返回兑换现金活动
func (controller *SuMoneyController) GerExchangeCashActivity () {
func (controller *SuMoneyController) GetExchangeCashActivity () {
cashPoolService := service.NewCashPoolService(nil)
getExchangeCashActivityQuery := &query.GetExchangeCashActivityQuery{}
... ... @@ -406,23 +410,60 @@ func (controller *SuMoneyController) GetExchangeCashPerson () {
controller.ServeJSON()
}
// TODO 导入素币兑换清单
// 导入素币兑换清单
func (controller *SuMoneyController) ImportExchangeList () {
cashPoolService := service.NewCashPoolService(nil)
createExchangeCashPersonCommand := &command.CreateExchangeCashPersonCommand{}
// TODO 批量导入
file, h, _ := controller.GetFile("file") //获取上传的文件
ext := path.Ext(h.Filename)
json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), createExchangeCashPersonCommand)
//验证后缀名是否符合要求
AllowExtMap := map[string]bool{
".xlsx":true,
}
if _,ok:=AllowExtMap[ext];!ok{
controller.Ctx.WriteString( "后缀名不符合上传要求" )
return
}
data, err := cashPoolService.CreateExchangeCashPerson(createExchangeCashPersonCommand)
xlsx, err := excelize.OpenReader(file)
if err != nil {
fmt.Println(err)
return
}
var response utils.JsonResponse
if err != nil {
response = utils.ResponseError(controller.Ctx, err)
} else {
response = utils.ResponseData(controller.Ctx, data)
dataList := make([]interface{}, 0)
rows, _ := xlsx.GetRows("Sheet1")
fmt.Print(rows)
for i, row := range rows {
if i > 0 {
for _, _ = range row {
//fmt.Print(row[0], "\t")
//fmt.Print(row[1], "\t")
//fmt.Print(row[2], "\t")
//fmt.Print(row[3], "\t")
//createExchangeCashPersonCommand.ExchangeCashPerson.EmployeeInfo.EmployeeName = row[0]
//createExchangeCashPersonCommand.ExchangeCashPerson.EmployeeInfo.EmployeeAccount = row[1]
//createExchangeCashPersonCommand.ExchangedCash, _ = strconv.ParseFloat(row[2],64)
//createExchangeCashPersonCommand.ExchangedSuMoney, _ = strconv.ParseFloat(row[3], 64)
data, err := cashPoolService.CreateExchangeCashPerson(createExchangeCashPersonCommand)
if err != nil {
response = utils.ResponseError(controller.Ctx, err)
} else {
dataList = append(dataList, data)
response = utils.ResponseData(controller.Ctx, dataList)
}
}
}
}
controller.Data["json"] = response
... ...
... ... @@ -15,7 +15,7 @@ func init() {
/**********************************************现金池*******************************************/
beego.Router("/cash-pool/input", &controllers.SuMoneyController{}, "POST:CashInput") // 现金池投入
beego.Router("/cash-pool/cash-pool-statistics", &controllers.SuMoneyController{}, "GET:CashPool") // 返回现金池统计
beego.Router("/cash-pool/cash-pool", &controllers.SuMoneyController{}, "GET:GetCashPool") // 返回现金池统计
beego.Router("/cash-pool/activity/", &controllers.SuMoneyController{}, "GET:ListExchangeActivities") // 返回兑换活动列表
beego.Router("/cash-pool/activity/:activityId", &controllers.SuMoneyController{}, "GET:ListExchangeActivities") // 返回兑换活动
... ...