作者 陈志颖

feat:调整素币管理功能增删改查功能,添加接口

... ... @@ -17,7 +17,7 @@ type CreateExchangeActivityCommand struct {
ExchangedSuMoney float64 `json:"exchangedSuMoney"` // 已兑换素币
ExchangedCash float64 `json:"exchangedCash"` // 已兑换现金
ExchangeRate float64 `json:"exchangeRate"` // 兑换汇率
ExchangeCashPeople []*domain.ExchangeCashPerson `json:"exchangeList"` // 兑换活动清单
ExchangeCashPeople []*domain.ExchangeCashPersonList `json:"exchangeList"` // 兑换活动清单
}
func (createExchangeActivityCommand *CreateExchangeActivityCommand) ValidateCommand() error {
... ...
... ... @@ -16,7 +16,7 @@ type UpdateExchangeCashActivity struct {
ExchangedSuMoney float64 `json:"exchangedSuMoney"` // 已兑换素币
ExchangedCash float64 `json:"exchangedCash"` // 已兑换现金
ExchangeRate float64 `json:"exchangeRate"` // 兑换汇率
ExchangeCashPeople []*domain.ExchangeCashPerson `json:"exchangeCashPeople"` // 兑换活动清单
ExchangeCashPeople []*domain.ExchangeCashPersonList `json:"exchangeCashPeople"` // 兑换活动清单
}
func (updateExchangeCashActivity *UpdateExchangeCashActivity) ValidateCommand() error {
... ...
package query
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type GetExchangeCashPersonQuery struct {
ExchangeCashPersonId int64 `json:"exchangeCashPersonId"` // 参与兑换现金活动人员id
}
func (getExchangeCashPersonQuery *GetExchangeCashPersonQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(getExchangeCashPersonQuery)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
... ... @@ -14,7 +14,8 @@ type ExchangeCashActivity struct {
CountDown string `json:"countDown"` // 兑换现金活动结束倒计时
Rate float64 `json:"rate"` // 兑换汇率
LastRate float64 `json:"lastRate"` // 上期兑换汇率
ExchangeCashPeople []*ExchangeCashPerson `json:"exchangeCashPeople"` // 兑换现金人员清单
Operator *EmployeeInfo `json:"operator"` // 活动发布人
ExchangeCashPeople []*ExchangeCashPersonList `json:"exchangeCashPeople"` // 兑换现金人员清单
}
type ExchangeActivityRepository interface {
... ...
package domain
// 参与兑换现金人员
type ExchangeCashPerson struct {
ExchangeCashPersonId int64 `json:"employeeId"` // 兑换人员ID
CompanyId int64 `json:"companyId"` // 公司id
ExchangeCashPersonInfo *EmployeeInfo `json:"employeeInfo"` // 兑换人员信息
ExchangedSuMoney float64 `json:"suMoney"` // 已兑换的素币
ExchangedCash float64 `json:"cash"` // 已兑换的现金
}
type ExchangeCashPersonRepository interface {
Save(exchangeCashPerson *ExchangeCashPerson) (*ExchangeCashPerson, error)
Remove(exchangeCashPerson *ExchangeCashPerson) (*ExchangeCashPerson, error)
FindOne(queryOptions map[string]interface{}) (*ExchangeCashPerson, error)
Find(queryOptions map[string]interface{}) (int64, []*ExchangeCashPerson, error)
}
func (exchangeCashPerson *ExchangeCashPerson) Identity() interface{} {
if exchangeCashPerson.ExchangeCashPersonId == 0 {
return nil
}
return exchangeCashPerson.ExchangeCashPersonId
}
\ No newline at end of file
package domain
// 参与兑换现金人员
type ExchangeCashPersonList struct {
ExchangeCashPersonListId int64 `json:"employeeId"` // 兑换人员ID
CompanyId int64 `json:"companyId"` // 公司id
ExchangeCashActivityId int64 `json:"exchangeActivityId"` // 参与的兑换活动id
ExchangeCashPerson *Employee `json:"employeeInfo"` // 兑换人员信息
ExchangedSuMoney float64 `json:"suMoney"` // 已兑换的素币
ExchangedCash float64 `json:"cash"` // 已兑换的现金
}
type ExchangeCashPersonListRepository interface {
Save(exchangeCashPersonList *ExchangeCashPersonList) (*ExchangeCashPersonList, error)
Remove(exchangeCashPersonList *ExchangeCashPersonList) (*ExchangeCashPersonList, error)
FindOne(queryOptions map[string]interface{}) (*ExchangeCashPersonList, error)
Find(queryOptions map[string]interface{}) (int64, []*ExchangeCashPersonList, error)
}
func (exchangeCashPersonList *ExchangeCashPersonList) Identity() interface{} {
if exchangeCashPersonList.ExchangeCashPersonListId == 0 {
return nil
}
return exchangeCashPersonList.ExchangeCashPersonListId
}
\ No newline at end of file
... ...
... ... @@ -2,12 +2,10 @@ package domain_service
import (
"fmt"
"github.com/linmadan/egglib-go/core/application"
coreDomain "github.com/linmadan/egglib-go/core/domain"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/factory"
//"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/factory"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/dao"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/repository"
"time"
)
... ... @@ -27,34 +25,34 @@ func (service *CashPoolService) Input(companyId int64, operatorUid int64, cash f
employeeRepository = repository
}
transactionContext, err := factory.CreateTransactionContext(nil)
//transactionContext, err := factory.CreateTransactionContext(nil)
//
//var employeeDao *dao.EmployeeDao
//if value, err := factory.CreateEmployeeDao(map[string]interface{}{
// "transactionContext": transactionContext,
//}); err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//} else {
// employeeDao = value
//}
var employeeDao *dao.EmployeeDao
if value, err := factory.CreateEmployeeDao(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
employeeDao = value
}
//var systemExchangedCash float64
//if value, err := employeeDao.CalculateSystemCash(companyId); err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//} else {
// systemExchangedCash = value
//}
var systemExchangedCash float64
if value, err := employeeDao.CalculateSystemCash(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(companyId); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
systemChangedSuMoney = value1
systemUnChangeSuMoney = value2
}
//var (
// systemChangedSuMoney float64
// systemUnChangeSuMoney float64
//)
//if value1, value2, err := employeeDao.CalculateSystemSuMoney(companyId); err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//} else {
// systemChangedSuMoney = value1
// systemUnChangeSuMoney = value2
//}
operator, err := employeeRepository.FindOne(map[string]interface{}{
"uid": operatorUid,
... ... @@ -79,11 +77,11 @@ func (service *CashPoolService) Input(companyId int64, operatorUid int64, cash f
cashPoolInfo := &domain.CashPool{
CompanyId: companyId,
Cash: cash,
ExchangedCash: systemExchangedCash,
//ExchangedCash: systemExchangedCash,
UnExchangeCash: currentCashPool.UnExchangeCash + cash,
ExchangedSuMoney: systemChangedSuMoney,
UnExchangeSuMoney: systemUnChangeSuMoney,
Rate: systemExchangedCash / systemChangedSuMoney,
//ExchangedSuMoney: systemChangedSuMoney,
//UnExchangeSuMoney: systemUnChangeSuMoney,
//Rate: systemExchangedCash / systemChangedSuMoney,
Operator: operator.EmployeeInfo,
CreateTime: time.Now(),
}
... ...
... ... @@ -36,8 +36,9 @@ func init() {
(*models.RejectTaskRecord)(nil),
(*models.Notification)(nil),
(*models.SentNotification)(nil),
(*models.ExchangeActivities)(nil),
(*models.ExchangeCashActivity)(nil),
(*models.CashPool)(nil),
(*models.ExchangeCashPersonList)(nil),
} {
err := DB.CreateTable(model, &orm.CreateTableOptions{
Temp: false,
... ...
package models
type CashPool struct {
Id int64 `json:"id"` // 现金池id
TableName string `pg:"cash_pools,alias:cash_pool"`
Id int64 `pg:",pk"` // 现金池id
CompanyId int64 // 公司id
ExchangedCash float64 // 系统已兑换现金
UnExchangeCash float64 // 系统未兑换现金
ExchangedSuMoney float64 // 系统已兑换素币
UnExchangeSuMoney float64 // 系统未兑换素币
Rate float64 // 兑换汇率
}
... ...
... ... @@ -6,17 +6,17 @@ import (
)
type ExchangeCashActivity struct {
TableName string `pg:"exchange_activities,alias:exchange_activity"`
TableName string `pg:"exchange_cash_activities,alias:exchange_cash_activity"`
Id int64 `pg:",pk"` // 兑换活动ID
CompanyId int64 // 公司ID
ActivityName string // 兑换活动名称
ActivityStart time.Time // 兑换活动开始时间
ActivityEnd time.Time // 兑换活动结束时间
ActivityPeriod string // 兑换活动持续时间
Deadline time.Time // 兑换活动结束时间
CountDown string // 兑换活动结束倒计时
ExchangedCash float64 // 已兑换现金
ExchangedSuMoney float64 // 已兑换素币
ExchangeRate float64 // 兑换汇率
ExchangeSuMoneyList []*domain.ExchangeCashPerson // 素币兑换人员清单
LastExchangeRate float64 // 上期活动兑换汇率
ExchangeSuMoneyList []*domain.ExchangeCashPersonList `pg:",array"` // 素币兑换人员清单
Sponsor *domain.EmployeeInfo // 活动发布人
CreateTime time.Time // 创建时间
}
\ No newline at end of file
... ...
package models
type ExchangeCashPerson struct {
}
\ No newline at end of file
package models
import (
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
"time"
)
type ExchangeCashPersonList struct {
TableName string `pg:"exchange_cash_list"`
Id int64 `pg:",pk"` // 兑换现金清单id
PersonInfo *domain.Employee // 兑换现金人员
ExchangedSuMoney float64 // 已兑换素币
ExchangedCash float64 // 已兑换现金
CreateTime time.Time // 兑换时间
}
\ No newline at end of file
... ...
... ... @@ -2,6 +2,7 @@ package repository
import (
"fmt"
"github.com/go-pg/pg"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg/models"
... ... @@ -11,19 +12,52 @@ type CashPoolRepository struct {
transactionContext *pgTransaction.TransactionContext
}
func (repostitory *CashPoolRepository) Save() (*domain.CashPool, error) {
return nil, nil
func (repository *CashPoolRepository) Save(cashPool *domain.CashPool) (*domain.CashPool, error) {
tx := repository.transactionContext.PgTx
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",
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",
cashPool.Cash, cashPool.CompanyId, cashPool.ExchangedCash, cashPool.UnExchangeCash, cashPool.ExchangedSuMoney, cashPool.UnExchangeSuMoney, cashPool.Rate, cashPool.Identity()); err != nil {
return cashPool, err
}
}
return cashPool, nil
}
func (repostitory *CashPoolRepository) FindOne(queryOptions map[string]interface{}) (*domain.CashPool, error) {
func (repository *CashPoolRepository) FindOne(queryOptions map[string]interface{}) (*domain.CashPool, error) {
tx := repository.transactionContext.PgTx
cashPoolModel := new(models.CashPool)
query := tx.Model(cashPoolModel)
// 根据公司id查找现金池
if companyId, ok := queryOptions["companyId"]; ok {
query = query.Where("cash_pool.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 cashPoolModel.CompanyId == 0 {
return nil, nil
} else {
return repository.transformPgModelToDomainModel(cashPoolModel)
}
}
func (repository *CashPoolRepository) transformPgModelToDomainModel(cashPoolModel *models.CashPool) (*domain.CashPool, error) {
return &domain.CashPool{
CashPoolId: cashPoolModel.Id,
CompanyId: cashPoolModel.CompanyId,
}, nil
}
... ...
package repository
import (
"fmt"
"github.com/go-pg/pg"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg/models"
"time"
)
type ExchangeCashActivityRepository struct {
transactionContext *pgTransaction.TransactionContext
}
func (repository *ExchangeCashActivityRepository) Save() (*ExchangeCashActivityRepository, error) {
return nil, nil
func (repository *ExchangeCashActivityRepository) Save(exchangeCashActivity *domain.ExchangeCashActivity) (*domain.ExchangeCashActivity, error) {
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 {
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 {
return exchangeCashActivity, err
}
}
return exchangeCashActivity, nil
}
func (repository *ExchangeCashActivityRepository) FindOne(queryOptions map[string]interface{}) (*ExchangeCashActivityRepository, error) {
func (repository *ExchangeCashActivityRepository) FindOne(queryOptions map[string]interface{}) (*domain.ExchangeCashActivity, error) {
tx := repository.transactionContext.PgTx
exchangeCashActivityModel := new(models.ExchangeCashActivity)
query := tx.Model(exchangeCashActivityModel)
if exchangeCashActivityId, ok := queryOptions["exchangeCashActivityId"]; ok {
query = query.Where("exchange_cash_list.id = ?", exchangeCashActivityId)
}
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
} else {
return nil, err
}
}
if exchangeCashActivityModel.Id == 0 {
return nil, nil
} else {
return repository.transformPgModelToDomainModel(exchangeCashActivityModel)
}
}
func (repository *ExchangeCashActivityRepository) Find(queryOptions map[string]interface{}) (*ExchangeCashActivityRepository, error) {
return nil, nil
func (repository *ExchangeCashActivityRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.ExchangeCashActivity, error) {
tx := repository.transactionContext.PgTx
var exchangeCashActivityModels []*models.ExchangeCashActivity
exchangeCashActivities := make([]*domain.ExchangeCashActivity, 0)
query := tx.Model(&exchangeCashActivityModels)
// 公司相关活动搜索
if companyId, ok := queryOptions["companyId"]; ok {
query = query.Where(`exchange_cash_activity.company_id = ?`, companyId)
}
// 活动名称模糊搜索
if exchangeCashActivityNameMatch, ok := queryOptions["exchangeCashActivityNameMatch"]; ok && (exchangeCashActivityNameMatch != "") {
query = query.Where(`exchange_cash_activity.exchange_cash_activity_name LIKE ?`, fmt.Sprintf("%%%s%%", exchangeCashActivityNameMatch.(string)))
}
// 活动截止时间搜索
if deadline, ok := queryOptions["exchangeCashActivityDeadline"]; ok && !deadline.(time.Time).IsZero() {
query = query.Where(`exchange_cash_activity.deadline < ?`, deadline)
}
if offset, ok := queryOptions["offset"]; ok {
offset := offset.(int)
if offset > -1 {
query = query.Offset(offset)
}
} else {
query = query.Offset(0)
}
if limit, ok := queryOptions["limit"]; ok {
limit := limit.(int)
if limit > -1 {
query = query.Limit(limit)
}
} else {
query = query.Limit(20)
}
if count, err := query.Order("id DESC").SelectAndCount(); err != nil {
return 0, exchangeCashActivities, err
} else {
for _, exchangeCashActivityModel := range exchangeCashActivityModels {
if taskNature, err := repository.transformPgModelToDomainModel(exchangeCashActivityModel); err != nil {
return 0, exchangeCashActivities, err
} else {
exchangeCashActivities = append(exchangeCashActivities, taskNature)
}
}
return int64(count), exchangeCashActivities, nil
}
}
func (repository *ExchangeCashActivityRepository) Remove() (*ExchangeCashActivityRepository, error) {
return nil, nil
func (repository *ExchangeCashActivityRepository) Remove(exchangeCashActivity *domain.ExchangeCashActivity) (*domain.ExchangeCashActivity, error) {
tx := repository.transactionContext.PgTx
exchangeCashActivityModel := new(models.ExchangeCashActivity)
exchangeCashActivity.ExchangeCashActivityId = exchangeCashActivity.Identity().(int64)
if _, err := tx.Model(exchangeCashActivityModel).WherePK().Delete(); err != nil {
return exchangeCashActivity, err
}
return exchangeCashActivity, nil
}
//func (repository *ExchangeCashActivityRepository) transformPgModelToDomainModel(customerValueModel *models.CustomerValue) (*domain.CustomerValue, error) {
// return &domain.CustomerValue{
// CustomerValueId: customerValueModel.Id,
// CustomerValueName: customerValueModel.CustomerValueName,
// CompanyId: customerValueModel.CompanyId,
// }, nil
//}
//func NewExchangeCashActivityRepository(transactionContext *pgTransaction.TransactionContext) (*CustomerValueRepository, error) {
// if transactionContext == nil {
// return nil, fmt.Errorf("transactionContext参数不能为nil")
// } else {
// return &CustomerValueRepository{
// transactionContext: transactionContext,
// }, nil
// }
//}
\ No newline at end of file
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,
}, nil
}
func NewExchangeCashActivityRepository(transactionContext *pgTransaction.TransactionContext) (*ExchangeCashActivityRepository, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &ExchangeCashActivityRepository{
transactionContext: transactionContext,
}, nil
}
}
\ No newline at end of file
... ...
package repository
import (
"fmt"
"github.com/go-pg/pg"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg/models"
)
type ExchangeCashPersonListRepository struct {
transactionContext *pgTransaction.TransactionContext
}
func (repository *ExchangeCashPersonListRepository) Save(exchangeCashList *domain.ExchangeCashPersonList) (*domain.ExchangeCashPersonList, error) {
tx := repository.transactionContext.PgTx
if exchangeCashList.Identity() == nil {
if _, err := tx.QueryOne(
pg.Scan(&exchangeCashList.ExchangeCashPersonListId, &exchangeCashList.CompanyId, &exchangeCashList.ExchangeCashActivityId, &exchangeCashList.ExchangeCashPerson, &exchangeCashList.ExchangedSuMoney, &exchangeCashList.ExchangedCash),
"INSERT INTO exchange_cash_list (company_id, exchange_cash_activity_id, exchange_cash_person, exchanged_su_money, exchanged_cash) VALUES (?, ?, ?, ?, ?) RETURNING id, company_id, exchange_cash_activity_id, exchange_cash_person, exchanged_su_money, exchanged_cash",
exchangeCashList.CompanyId, exchangeCashList.ExchangeCashActivityId, exchangeCashList.ExchangeCashPerson, exchangeCashList.ExchangedSuMoney, exchangeCashList.ExchangedCash); err != nil {
return exchangeCashList, err
}
} else {
if _, err := tx.QueryOne(
pg.Scan(&exchangeCashList.ExchangeCashPersonListId, &exchangeCashList.CompanyId, &exchangeCashList.ExchangeCashPerson, &exchangeCashList.ExchangedSuMoney, &exchangeCashList.ExchangedCash),
"UPDATE exchange_cash_list SET company_id = ?, exchange_cash_activity_id=?, exchange_cash_person=?, exchanged_su_money=?, exchanged_cash=? WHERE id=? RETURNING id, company_id, exchange_cash_activity_id, exchange_cash_person, exchanged_su_money, exchanged_cash",
exchangeCashList.CompanyId, exchangeCashList.ExchangeCashPerson, exchangeCashList.ExchangeCashActivityId, exchangeCashList.ExchangedSuMoney, exchangeCashList.ExchangedCash); err != nil {
return exchangeCashList, err
}
}
return exchangeCashList, nil
}
func (repository *ExchangeCashPersonListRepository) FindOne(queryOptions map[string]interface{}) (*domain.ExchangeCashPersonList, error) {
tx := repository.transactionContext.PgTx
exchangeCashListModel := new(models.ExchangeCashPersonList)
query := tx.Model(exchangeCashListModel)
if exchangeCashListId, ok := queryOptions["exchangeCashListId"]; ok {
query = query.Where("exchange_cash_list.id = ?", exchangeCashListId)
}
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
} else {
return nil, err
}
}
if exchangeCashListModel.Id == 0 {
return nil, nil
} else {
return repository.transformPgModelToDomainModel(exchangeCashListModel)
}
}
func (repository *ExchangeCashPersonListRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.ExchangeCashPersonList, error) {
tx := repository.transactionContext.PgTx
var exchangeCashListModels []*models.ExchangeCashPersonList
exchangeCashPeople := make([]*domain.ExchangeCashPersonList, 0)
query := tx.Model(&exchangeCashListModels)
// 根据公司id查找兑换现金人员清单
if companyId, ok := queryOptions["companyId"]; ok {
query = query.Where("exchange_cash_list.company_id = ?", companyId)
}
// 根据活动id查找兑换现金人员清单
if exchangeCashActivityId, ok := queryOptions["activityId"]; ok {
query = query.Where("exchange_cash_list.exchange_cash_activity_id = ?", exchangeCashActivityId)
}
// 根据兑换现金人员名称搜索人员清单
if personNameMatch, ok := queryOptions["personNameMatch"]; ok && (personNameMatch != ""){
query = query.Where("exchange_cash_list.exchange_cash_person LIKE ", fmt.Sprintf("%%%s%%", personNameMatch.(string)))
}
if offset, ok := queryOptions["offset"]; ok {
offset := offset.(int)
if offset > -1 {
query = query.Offset(offset)
}
} else {
query = query.Offset(0)
}
if limit, ok := queryOptions["limit"]; ok {
limit := limit.(int)
if limit > -1 {
query = query.Limit(limit)
}
} else {
query = query.Limit(20)
}
if count, err := query.Order("id DESC").SelectAndCount(); err != nil {
return 0, exchangeCashPeople, err
} else {
for _, exchangeCashListModel := range exchangeCashListModels {
if taskNature, err := repository.transformPgModelToDomainModel(exchangeCashListModel); err != nil {
return 0, exchangeCashPeople, err
} else {
exchangeCashPeople = append(exchangeCashPeople, taskNature)
}
}
return int64(count), exchangeCashPeople, nil
}
}
func (repository *ExchangeCashPersonListRepository) Remove(exchangeCashList *domain.ExchangeCashPersonList) (*domain.ExchangeCashPersonList, error) {
tx := repository.transactionContext.PgTx
exchangeCashListModel := new(models.ExchangeCashPersonList)
exchangeCashList.ExchangeCashPersonListId = exchangeCashList.Identity().(int64)
if _, err := tx.Model(exchangeCashListModel).WherePK().Delete(); err != nil {
return exchangeCashList, err
}
return exchangeCashList, nil
}
func (repository *ExchangeCashPersonListRepository) transformPgModelToDomainModel(exchangeCashList *models.ExchangeCashPersonList) (*domain.ExchangeCashPersonList, error) {
return &domain.ExchangeCashPersonList{
ExchangedCash: exchangeCashList.ExchangedCash,
ExchangedSuMoney: exchangeCashList.ExchangedSuMoney,
}, nil
}
func NewExchangeCashListRepository(transactionContext *pgTransaction.TransactionContext) (*ExchangeCashPersonListRepository, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &ExchangeCashPersonListRepository{
transactionContext: transactionContext,
}, nil
}
}
... ...
... ... @@ -32,6 +32,7 @@ func (repository *TaskNatureRepository) Save(taskNature *domain.TaskNature) (*do
}
return taskNature, nil
}
func (repository *TaskNatureRepository) Remove(taskNature *domain.TaskNature) (*domain.TaskNature, error) {
tx := repository.transactionContext.PgTx
taskNatureModel := new(models.TaskNature)
... ... @@ -41,6 +42,7 @@ func (repository *TaskNatureRepository) Remove(taskNature *domain.TaskNature) (*
}
return taskNature, nil
}
func (repository *TaskNatureRepository) FindOne(queryOptions map[string]interface{}) (*domain.TaskNature, error) {
tx := repository.transactionContext.PgTx
taskNatureModel := new(models.TaskNature)
... ... @@ -61,6 +63,7 @@ func (repository *TaskNatureRepository) FindOne(queryOptions map[string]interfac
return repository.transformPgModelToDomainModel(taskNatureModel)
}
}
func (repository *TaskNatureRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.TaskNature, error) {
tx := repository.transactionContext.PgTx
var taskNatureModels []*models.TaskNature
... ... @@ -104,6 +107,7 @@ func (repository *TaskNatureRepository) Find(queryOptions map[string]interface{}
return int64(count), taskNatures, nil
}
}
func (repository *TaskNatureRepository) transformPgModelToDomainModel(taskNatureModel *models.TaskNature) (*domain.TaskNature, error) {
return &domain.TaskNature{
TaskNatureId: taskNatureModel.Id,
... ... @@ -111,6 +115,7 @@ func (repository *TaskNatureRepository) transformPgModelToDomainModel(taskNature
CompanyId: taskNatureModel.CompanyId,
}, nil
}
func NewTaskNatureRepository(transactionContext *pgTransaction.TransactionContext) (*TaskNatureRepository, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
... ...
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 () {
}
... ... @@ -89,3 +89,101 @@ func (controller *SuMoneyController) SuMoneyTransactionRecordStatistics() {
controller.Data["json"] = response
controller.ServeJSON()
}
/**
* 现金池投入
*/
func (controller *SuMoneyController) CashInput() {
}
/**
* 返回兑换活动列表
*/
func (controller *SuMoneyController) ListExchangeActivities () {
}
/**
* 更新兑换活动信息
*/
func (controller *SuMoneyController) UpdateExchangeActivities () {
}
/**
* 新增兑换活动
*/
func (controller *SuMoneyController) CreateExchangeActivities () {
}
/**
* 删除兑换活动
*/
func (controller *SuMoneyController) RemoveExchangeActivities () {
}
/**
* 搜索兑换素币活动
*/
func (controller *SuMoneyController) searchExchangeActivities () {
}
/**
* 兑换活动数据统计
*/
func (controller *SuMoneyController) exchangeActivitiesStatistics () {
}
/**
* 获取素币兑换清单
*/
func (controller *SuMoneyController) ListExchangeList () {
}
/**
* 新增素币兑换清单
*/
func (controller *SuMoneyController) CreateExchangeList () {
}
/**
* 更新素币兑换清单
*/
func (controller *SuMoneyController) UpdateExchangeList () {
}
/**
* 删除素币兑换清单
*/
func (controller *SuMoneyController) RemoveExchangeList () {
}
/**
* 搜索素币兑换清单
*/
func (controller *SuMoneyController) searchExchangeList () {
}
/**
* 导出素币兑换清单
*/
func (controller *SuMoneyController) ExportExchangeList () {
}
/**
* 导入素币兑换清单
*/
func (controller *SuMoneyController) ImportExchangeList () {
}
\ No newline at end of file
... ...
package routers
// TODO
func init() {
///*****************************************现金池**********************************/
//beego.Router("/cash_pool/input", &controllers.ConfigController{}, "POST:CashInput") // 现金池投入
//
///*****************************************兑换活动*********************************/
//beego.Router("/cashPool-pool/", &controllers.ConfigController{}, "GET:ListExchangeActivities") // 返回兑换活动列表
//beego.Router("/cashPool-pool/:aid", &controllers.ConfigController{}, "PUT:UpdateExchangeActivities") // 编辑兑换活动
//beego.Router("/cashPool-pool/", &controllers.ConfigController{}, "POST:CreateExchangeActivities") // 新增兑换活动
//beego.Router("/cashPool-pool/:aid", &controllers.ConfigController{}, "DELETE:DeleteExchangeActivities") // 删除兑换活动
//
///*****************************************兑换素币清单****************************/
//beego.Router("/cashPool-pool/exchange", &controllers.ConfigController{}, "GET:ListExchangeList") // 返回素币兑换清单
//beego.Router("/cashPool-pool/exchange", &controllers.ConfigController{}, "POST:CreateExchangeList") // 新增素币兑换清单
//beego.Router("/cashPool-pool/exchange/:eid", &controllers.ConfigController{}, "PUT:UpdateExchangeList") // 编辑素币兑换清单
//beego.Router("/cashPool-pool/exchange/:eid", &controllers.ConfigController{}, "DELETE:RemoveExchangeList") // 删除素币兑换清单
//beego.Router("/cashPool-pool/export", &controllers.ConfigController{}, "POST:ExportExchangeList") // 导出素币兑换清单
//beego.Router("/cashPool-pool/import", &controllers.ConfigController{}, "POST:ImportExchangeList") // 导入素币兑换清单
}
\ No newline at end of file
... ... @@ -6,9 +6,25 @@ import (
)
func init() {
/**********************************************素币流水******************************************/
beego.Router("/su-money/operation", &controllers.SuMoneyController{}, "Post:OperationSuMoney")
beego.Router("/su-money/su-money-transaction-records/:suMoneyTransactionRecordId", &controllers.SuMoneyController{}, "Get:GetSuMoneyTransactionRecord")
beego.Router("/su-money/exchange", &controllers.SuMoneyController{}, "Post:ExchangeSuMoney")
beego.Router("/su-money/search-su-money-transaction-record", &controllers.SuMoneyController{}, "Post:SearchSuMoneyTransactionRecord")
beego.Router("/su-money/su-money-transaction-record-statistics", &controllers.SuMoneyController{}, "Post:SuMoneyTransactionRecordStatistics")
/**********************************************现金池*******************************************/
beego.Router("/cash-pool/input", &controllers.SuMoneyController{}, "POST:CashInput") // 现金池投入
beego.Router("/cash-pool/", &controllers.SuMoneyController{}, "GET:ListExchangeActivities") // 返回兑换活动列表
beego.Router("/cash-pool/:activityId", &controllers.SuMoneyController{}, "PUT:UpdateExchangeActivities") // 编辑兑换活动
beego.Router("/cash-pool/", &controllers.SuMoneyController{}, "POST:CreateExchangeActivities") // 新增兑换活动
beego.Router("/cash-pool/:activityId", &controllers.SuMoneyController{}, "DELETE:RemoveExchangeActivities") // 删除兑换活动
beego.Router("/cash-pool/exchange-list", &controllers.SuMoneyController{}, "GET:ListExchangeList") // 返回素币兑换清单
beego.Router("/cash-pool/exchange-list", &controllers.SuMoneyController{}, "POST:CreateExchangeList") // 新增素币兑换清单
beego.Router("/cash-pool/exchange-list/:personId", &controllers.SuMoneyController{}, "PUT:UpdateExchangeList") // 编辑素币兑换清单
beego.Router("/cash-pool/exchange-list/:personId", &controllers.SuMoneyController{}, "DELETE:RemoveExchangeList") // 删除素币兑换清单
beego.Router("/cash-pool/exchange-list/export", &controllers.SuMoneyController{}, "POST:ExportExchangeList") // 导出素币兑换清单
beego.Router("/cash-pool/exchange-list/import", &controllers.SuMoneyController{}, "POST:ImportExchangeList") // 导入素币兑换清单
}
... ...