作者 陈志颖

test:测试接口,修复返回数据问题

正在显示 24 个修改的文件 包含 100 行增加129 行删除
... ... @@ -8,15 +8,8 @@ import (
// 创建现金池
type CreateCashPoolCommand struct {
//Uid int64 `json:"uid"` // 统一用户id
//CashPoolId int64 `json:"cashPoolId" valid:"Required"` // 现金池ID
CompanyId int64 `json:"companyId" valid:"Required"` // 公司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
}
func (createCashPoolCommand *CreateCashPoolCommand) ValidateCommand() error {
... ...
... ... @@ -10,14 +10,9 @@ import (
type CreateExchangeCashActivityCommand struct {
CompanyId int64 `json:"companyId" valid:"Required"` // 公司id
ExchangeActivityName string `json:"exchangeActivityName"` // 活动名称
//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"` // 兑换汇率
CreateTime time.Time `json:"createTime"` // 创建时间
//ExchangeCashPeople []*domain.ExchangeCashPersonList `json:"exchangeList"` // 兑换活动清单
}
func (createExchangeActivityCommand *CreateExchangeCashActivityCommand) ValidateCommand() error {
... ...
... ... @@ -6,12 +6,10 @@ import (
)
type CreateExchangeCashPersonCommand struct {
PersonId int64 `json:"personId" valid:"Required"` // 兑换现金人员uid
PersonName string `json:"personName,omitempty"` // 兑换现金人员名称
PersonAccount string `json:"personAccount,omitempty"` // 手机账号
ExchangeCashActivityId int64 `json:"exchangeCashActivityId" valid:"Required"` // 参与的兑换活动id
ExchangedSuMoney float64 `json:"exchangedSuMoney"` // 已兑换素币值
//ExchangedCash float64 `json:"exchangedCash"` // 已兑换现金值
}
func (createExchangeCashPersonCommand *CreateExchangeCashPersonCommand) ValidateCommand() error {
... ...
... ... @@ -2,12 +2,13 @@ package command
import (
"fmt"
"github.com/astaxie/beego/validation"
)
// 删除兑换现金活动
type RemoveExchangeCashActivityCommand struct {
ExchangeCashActivityId int64 `json:"exchangeCashActivityId" valid:"Required"`
ActivityId int64 `json:"activityId" valid:"Required"`
}
func (removeExchangeCashActivityCommand *RemoveExchangeCashActivityCommand) ValidateCommand() error {
... ...
... ... @@ -7,7 +7,7 @@ import (
// 移除兑换现金人员
type RemoveExchangeCashPersonCommand struct {
ExchangeCashPersonId int64 `json:"exchangeCashId" valid:"Required"` // 兑换现金人员编号
ListId int64 `json:"listId" valid:"Required"` // 兑换现金人员编号
}
func (removeExchangeCashPersonCommand *RemoveExchangeCashPersonCommand) ValidateCommand() error {
... ...
... ... @@ -6,7 +6,7 @@ import (
)
type SearchExchangeCashActivityCommand struct {
ExchangeCashActivityName string `json:"exchangeCashActivityName"` // 兑换现金活动名称
ActivityName string `json:"activityName"` // 兑换现金活动名称
}
func (searchExchangeCashActivityCommand *SearchExchangeCashActivityCommand) ValidateCommand() error {
... ...
... ... @@ -6,7 +6,7 @@ import (
)
type SearchExchangeCashPersonCommand struct {
ExchangeCashPersonName string `json:"exchangeCashPersonName"` // 兑换素币人员名称
ListName string `json:"listName"` // 兑换素币人员名称
}
func (searchExchangeCashPersonCommand *SearchExchangeCashPersonCommand) ValidateCommand() error {
... ...
... ... @@ -8,14 +8,12 @@ import (
type UpdateExchangeCashActivityCommand struct {
ExchangeCashActivityId int64 `json:"exchangeCashActivityId"` // 兑换现金活动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"` // 兑换活动清单
}
func (updateExchangeCashActivity *UpdateExchangeCashActivityCommand) ValidateCommand() error {
... ...
... ... @@ -6,9 +6,8 @@ import (
)
type UpdateExchangeCashPersonCommand struct {
ExchangeCashPersonId int64 `json:"exchangeCashPersonId" valid:"Required"` // 兑换现金人员编号
ListId int64 `json:"listId" valid:"Required"` // 兑换现金人员编号
ExchangedSuMoney float64 `json:"exchangedSuMoney"` // 已兑换的素币(需要和当前的已兑换素币进行比较,少于当前已兑换素币则生成一条扣除素币记录,大于当前已兑换素币则生成一条增加素币记录)
ExchangedCash float64 `json:"exchangedCash"` // 已兑换的现金
}
func (updateExchangeCashPersonCommand *UpdateExchangeCashPersonCommand) ValidateCommand() error {
... ...
... ... @@ -2,7 +2,9 @@ package service
import (
"fmt"
"github.com/astaxie/beego"
"github.com/linmadan/egglib-go/utils/tool_funs"
"strconv"
"time"
"github.com/linmadan/egglib-go/core/application"
... ... @@ -17,14 +19,11 @@ import (
type CashPoolService struct {
}
// 投入现金池
// 新增现金池
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())
... ... @@ -35,8 +34,6 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co
defer func() {
transactionContext.RollbackTransaction()
}()
// 新建现金池数据访问对象
var cashPoolDao *dao.CashPoolDao
if value, err := factory.CreateCashPoolDao(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -45,16 +42,12 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co
} else {
cashPoolDao = value
}
// 获取系统已兑换现金值
var systemExchangedCash float64
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
... ... @@ -66,16 +59,18 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co
systemUnChangeSuMoney = value2
}
fmt.Print("1234567", createCashPoolCommand)
// TODO 获取上一个现金池现金值
rate, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", systemExchangedCash / systemChangedSuMoney), 64)
newCashPool := &domain.CashPool{
CompanyId: createCashPoolCommand.CompanyId,
Cash: createCashPoolCommand.Cash,
ExchangedCash: systemExchangedCash,
UnExchangeCash: 0,
UnExchangeCash: createCashPoolCommand.Cash, // TODO 投入的现金 + 系统未兑换的现金
ExchangedSuMoney: systemChangedSuMoney,
UnExchangeSuMoney: systemUnChangeSuMoney,
Rate: 0,
Rate: rate,
CreateTime: time.Now(),
}
... ... @@ -88,7 +83,6 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co
cashPoolRepository = value
}
// 每个公司一个现金池
if activity, err := cashPoolRepository.Save(newCashPool); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ... @@ -104,8 +98,6 @@ func (cashPoolService *CashPoolService) GetCashPool(getCashPoolQuery *query.GetC
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())
... ... @@ -116,8 +108,6 @@ func (cashPoolService *CashPoolService) GetCashPool(getCashPoolQuery *query.GetC
defer func() {
transactionContext.RollbackTransaction()
}()
// 现金池资源库
var cashPoolRepository domain.CashPoolRepository
if value, err := factory.CreateCashPoolRepository(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -162,11 +152,12 @@ func (cashPoolService *CashPoolService) CreateExchangeCashActivity(createExchang
newActivity := &domain.ExchangeCashActivity{
ExchangeActivityName: createExchangeCashActivityCommand.ExchangeActivityName,
CompanyId: createExchangeCashActivityCommand.CompanyId,
ExchangedCash: createExchangeCashActivityCommand.ExchangedCash,
ExchangedSuMoney: createExchangeCashActivityCommand.ExchangedSuMoney,
ExchangedCash: 0,
ExchangedSuMoney: 0,
Deadline: createExchangeCashActivityCommand.Deadline,
CountDown: createExchangeCashActivityCommand.CountDown,
CountDown: 0,
Rate: createExchangeCashActivityCommand.ExchangeRate,
CreateTime: time.Now(),
}
// 兑换活动资源库
... ... @@ -254,12 +245,12 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashActivity(removeExchang
exchangeCashActivityRepository = value
}
activity, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": removeExchangeCashActivityCommand.ExchangeCashActivityId})
activity, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": removeExchangeCashActivityCommand.ActivityId})
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)))
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeExchangeCashActivityCommand.ActivityId)))
}
if activityDeleted, err := exchangeCashActivityRepository.Remove(activity); err != nil {
... ... @@ -359,6 +350,8 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
// TODO 更新现金池已兑换素币、已兑换现金值、未兑换素币、未兑换现金值、平均汇率
return activityUpdated, nil
}
}
... ... @@ -380,18 +373,27 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC
transactionContext.RollbackTransaction()
}()
// TODO 需要判断新增兑换现金人员的素币值是否合理(人员参与兑换的素币不得超过该人员还未兑换的素币总值)
// TODO 判断活动的汇率是否为空,为空则不允许新建,提示:请设置汇率
// TODO 获取参与的兑换活动的汇率,计算已兑换的现金值
// TODO 清单中现金总额超过现金池时创建失败,提示:“已超过投入现金池的未兑换现金”
// TODO 新增兑换人员时,判断成员是否存在,以手机账号为判断依据
// 创建兑换清单
newPerson := &domain.ExchangeCashPersonList{
EmployeeInfo: &domain.EmployeeInfo{
Uid: createExchangeCashPersonCommand.PersonId,
EmployeeName: createExchangeCashPersonCommand.PersonName,
EmployeeAccount: createExchangeCashPersonCommand.PersonAccount,
},
ExchangeCashActivityId: createExchangeCashPersonCommand.ExchangeCashActivityId,
ExchangedSuMoney: createExchangeCashPersonCommand.ExchangedSuMoney,
}
// 兑换活动资源库
var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository
if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -407,6 +409,8 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
// TODO 更新活动已兑换素币值、已兑换现金值、兑换汇率
return person, nil
}
}
... ... @@ -455,7 +459,6 @@ func (cashPoolService *CashPoolService) ListExchangeCashPerson(listExchangeCashP
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())
... ... @@ -466,7 +469,6 @@ func (cashPoolService *CashPoolService) ListExchangeCashPerson(listExchangeCashP
defer func() {
transactionContext.RollbackTransaction()
}()
var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository
if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -515,20 +517,24 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC
exchangeCashPersonListRepository = value
}
person, err := exchangeCashPersonListRepository.FindOne(map[string]interface{}{"personId": removeExchangeCashPersonCommand.ExchangeCashPersonId})
person, err := exchangeCashPersonListRepository.FindOne(map[string]interface{}{"id": removeExchangeCashPersonCommand.ListId})
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)))
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeExchangeCashPersonCommand.ListId)))
}
beego.Info(person)
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())
}
// TODO 个人素币值需要还原,理由:素币兑换现金调整
return personDeleted, nil
}
}
... ... @@ -538,7 +544,6 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
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())
... ... @@ -549,9 +554,6 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
defer func() {
transactionContext.RollbackTransaction()
}()
// TODO 新增流水记录
var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository
if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -560,13 +562,12 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
} else {
exchangeCashPersonListRepository = value
}
person, err := exchangeCashPersonListRepository.FindOne(map[string]interface{}{"personId": updateExchangeCashPersonCommand.ExchangeCashPersonId})
person, err := exchangeCashPersonListRepository.FindOne(map[string]interface{}{"listId": updateExchangeCashPersonCommand.ListId})
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)))
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashPersonCommand.ListId)))
}
if err := person.Update(tool_funs.SimpleStructToMap(updateExchangeCashPersonCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
... ... @@ -577,6 +578,10 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
// TODO 更新个人当前可用素币值,生成素币兑换流水记录(获取更新前的已兑换素币值,判断是扣除还是增加),记录描述:参与素币兑换现金活动(红色表示取活动名称)
// TODO 更新相应兑换活动已兑换素币值、已兑换现金值、兑换汇率
return personUpdated, nil
}
}
... ...
... ... @@ -13,9 +13,6 @@ type ExchangeCashActivity struct {
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 {
... ...
... ... @@ -2,11 +2,8 @@ package domain
// 参与兑换现金人员
type ExchangeCashPersonList struct {
ExchangeCashPersonListId int64 `json:"exchangeCashPersonListId"` // 兑换人员ID
//CompanyId int64 `json:"companyId"` // 公司id
EmployeeInfo *EmployeeInfo `json:"employeeInfo"`
//PersonId int64 `json:"personId"` // 兑换人员uid
//ExchangeCashPersonName string `json:"exchangeCashPersonName"` // 兑换人员名称
ListId int64 `json:"listId"` // 清单id
EmployeeInfo *EmployeeInfo `json:"employeeInfo"` // 兑换人信息
ExchangeCashActivityId int64 `json:"exchangeActivityId"` // 参与的兑换活动id
ExchangedSuMoney float64 `json:"suMoney"` // 已兑换的素币
ExchangedCash float64 `json:"cash"` // 已兑换的现金
... ... @@ -20,10 +17,10 @@ type ExchangeCashPersonListRepository interface {
}
func (exchangeCashPersonList *ExchangeCashPersonList) Identity() interface{} {
if exchangeCashPersonList.ExchangeCashPersonListId == 0 {
if exchangeCashPersonList.ListId == 0 {
return nil
}
return exchangeCashPersonList.ExchangeCashPersonListId
return exchangeCashPersonList.ListId
}
func (exchangeCashPersonList *ExchangeCashPersonList) Update(data map[string]interface{}) error {
... ...
... ... @@ -19,16 +19,16 @@ func (dao *CashPoolDao) CalculateSystemSuMoney(companyId int64) ( float64, float
employeeModel := new(models.Employee)
if err := tx.Model(employeeModel).
ColumnExpr("sum(employee.su_money) AS system_unExchange_su_money").
Where("employee.company_id = ?", companyId).
ColumnExpr("sum(employees.su_money) AS system_unExchange_su_money").
Where("employees.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).
ColumnExpr("sum(exchange_cash_activities.exchanged_su_money) AS system_changed_su_money").
Where("exchange_cash_activities.company_id = ?", companyId).
Select(&systemExchangedSuMoney); err != nil {
return 0, 0, err
}
... ... @@ -44,8 +44,8 @@ func (dao *CashPoolDao) CalculateSystemCash(companyId int64) (float64, error) {
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).
ColumnExpr("sum(exchange_cash_activities.exchanged_cash) AS system_exchanged_cash").
Where("exchange_cash_activities.company_id = ?", companyId).
Select(&systemExchangedCash) ; err != nil {
return 0, err
}
... ...
package models
import "time"
type CashPool struct {
TableName string `pg:"cash_pools,alias:cash_pool"`
Id int64 `pg:",pk"` // 现金池id
... ... @@ -10,4 +12,5 @@ type CashPool struct {
ExchangedSuMoney float64 // 系统已兑换素币
UnExchangeSuMoney float64 // 系统未兑换素币
Rate float64 // 兑换汇率
CreateTime time.Time
}
... ...
... ... @@ -39,7 +39,7 @@ func (repository *ExchangeCashActivityRepository) FindOne(queryOptions map[strin
exchangeCashActivityModel := new(models.ExchangeCashActivity)
query := tx.Model(exchangeCashActivityModel)
if exchangeCashActivityId, ok := queryOptions["exchangeCashActivityId"]; ok {
query = query.Where("exchange_cash_list.id = ?", exchangeCashActivityId)
query = query.Where("exchange_cash_activities.id = ?", exchangeCashActivityId)
}
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
... ... @@ -123,9 +123,6 @@ func (repository *ExchangeCashActivityRepository) transformPgModelToDomainModel(
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) {
... ...
... ... @@ -17,16 +17,16 @@ func (repository *ExchangeCashPersonListRepository) Save(exchangeCashList *domai
tx := repository.transactionContext.PgTx
if exchangeCashList.Identity() == nil {
if _, err := tx.QueryOne(
pg.Scan(&exchangeCashList.ExchangeCashPersonListId, &exchangeCashList.ExchangeCashActivityId, &exchangeCashList.EmployeeInfo.Uid, &exchangeCashList.EmployeeInfo.EmployeeName, &exchangeCashList.EmployeeInfo.EmployeeAccount, &exchangeCashList.ExchangedSuMoney, &exchangeCashList.ExchangedCash),
pg.Scan(&exchangeCashList.ListId, &exchangeCashList.ExchangeCashActivityId, &exchangeCashList.EmployeeInfo.Uid, &exchangeCashList.EmployeeInfo.EmployeeName, &exchangeCashList.EmployeeInfo.EmployeeAccount, &exchangeCashList.ExchangedSuMoney, &exchangeCashList.ExchangedCash),
"INSERT INTO exchange_cash_person_lists (activity_id, uid, employee_name, employee_account, exchanged_su_money, exchanged_cash) VALUES (?, ?, ?, ?, ?, ?) RETURNING id, activity_id, uid, employee_name, employee_account, exchanged_su_money, exchanged_cash",
exchangeCashList.ExchangeCashActivityId, exchangeCashList.EmployeeInfo.Uid, exchangeCashList.EmployeeInfo.EmployeeName, exchangeCashList.EmployeeInfo.EmployeeAccount, exchangeCashList.ExchangedSuMoney, exchangeCashList.ExchangedCash); err != nil {
return exchangeCashList, err
}
} else {
if _, err := tx.QueryOne(
pg.Scan(&exchangeCashList.ExchangeCashPersonListId, &exchangeCashList.ExchangeCashActivityId, &exchangeCashList.EmployeeInfo.Uid, &exchangeCashList.EmployeeInfo.EmployeeName, &exchangeCashList.EmployeeInfo.EmployeeAccount, &exchangeCashList.ExchangedSuMoney, &exchangeCashList.ExchangedCash),
"UPDATE exchange_cash_person_lists SET exchanged_su_money=? WHERE uid=? RETURNING id, activity_id, uid, employee_name, employee_account, exchanged_su_money, exchanged_cash",
exchangeCashList.ExchangedSuMoney, exchangeCashList.EmployeeInfo.Uid); err != nil {
pg.Scan(&exchangeCashList.ListId, &exchangeCashList.ExchangeCashActivityId, &exchangeCashList.EmployeeInfo.Uid, &exchangeCashList.EmployeeInfo.EmployeeName, &exchangeCashList.EmployeeInfo.EmployeeAccount, &exchangeCashList.ExchangedSuMoney, &exchangeCashList.ExchangedCash),
"UPDATE exchange_cash_person_lists SET exchanged_su_money=? WHERE id=? RETURNING id, activity_id, uid, employee_name, employee_account, exchanged_su_money, exchanged_cash",
exchangeCashList.ExchangedSuMoney, exchangeCashList.ListId); err != nil {
return exchangeCashList, err
}
}
... ... @@ -59,15 +59,9 @@ func (repository *ExchangeCashPersonListRepository) Find(queryOptions map[string
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_person_lists.company_id = ?", companyId)
//}
// 根据活动id查找兑换现金人员清单
if exchangeCashActivityId, ok := queryOptions["activityId"]; ok {
query = query.Where("exchange_cash_person_lists.activity_id = ?", exchangeCashActivityId)
}
// 根据兑换现金人员名称搜索人员清单
if personNameMatch, ok := queryOptions["personNameMatch"]; ok && (personNameMatch != ""){
query = query.Where("exchange_cash_person_lists.employee_name LIKE ?", fmt.Sprintf("%%%s%%", personNameMatch.(string)))
}
... ... @@ -104,7 +98,7 @@ func (repository *ExchangeCashPersonListRepository) Find(queryOptions map[string
func (repository *ExchangeCashPersonListRepository) Remove(exchangeCashList *domain.ExchangeCashPersonList) (*domain.ExchangeCashPersonList, error) {
tx := repository.transactionContext.PgTx
exchangeCashListModel := new(models.ExchangeCashPersonList)
exchangeCashList.ExchangeCashPersonListId = exchangeCashList.Identity().(int64)
exchangeCashList.ListId = exchangeCashList.Identity().(int64)
if _, err := tx.Model(exchangeCashListModel).WherePK().Delete(); err != nil {
return exchangeCashList, err
}
... ... @@ -115,6 +109,15 @@ func (repository *ExchangeCashPersonListRepository) transformPgModelToDomainMode
return &domain.ExchangeCashPersonList{
ExchangedCash: exchangeCashList.ExchangedCash,
ExchangedSuMoney: exchangeCashList.ExchangedSuMoney,
ListId: exchangeCashList.Id,
ExchangeCashActivityId: exchangeCashList.ActivityId,
EmployeeInfo: &domain.EmployeeInfo{
Uid: exchangeCashList.Uid,
EmployeeName: exchangeCashList.EmployeeName,
EmployeeAccount: exchangeCashList.EmployeeAccount,
EmployeeAvatarUrl: exchangeCashList.EmployeeAvatarUrl,
IsPrincipal: exchangeCashList.IsPrincipal,
},
}, nil
}
func NewExchangeCashPersonListRepository(transactionContext *pgTransaction.TransactionContext) (*ExchangeCashPersonListRepository, error) {
... ...
... ... @@ -76,8 +76,7 @@ func (repository *SuMoneyTransactionRecordRepository) Find(queryOptions map[stri
// TODO 姓名模糊查询
if employeeMatchName, ok := queryOptions["employeeMatchName"]; ok && (employeeMatchName != "") {
//query = query.Where(`su_money_transaction_record.employee @> 'employeeName' LIKE ?`, fmt.Sprintf("%%%s%%", employeeMatchName.(string)))
//query = query.Where(`su_money_transaction_record.employee :json->> 'employeeName' LIKE ?`, fmt.Sprintf("%%%s%%", employeeMatchName.(string)))
query = query.Where(`su_money_transaction_record.employee @> '{"employeeName":?}'`, employeeMatchName.(string))
query = query.Where(`su_money_transaction_record.employee :json->> 'employeeName' LIKE ?`, fmt.Sprintf("%%%s%%", employeeMatchName.(string)))
}
if recordType, ok := queryOptions["recordType"]; ok && (recordType != 0) {
query = query.Where(`su_money_transaction_record.record_type = ?`, recordType)
... ...
... ... @@ -2,6 +2,7 @@ package controllers
import (
"encoding/json"
"fmt"
"github.com/astaxie/beego"
"github.com/linmadan/egglib-go/web/beego/utils"
... ... @@ -89,6 +90,7 @@ func (controller *EmployeeController) ListEmployee() {
listEmployeeQuery.Offset = offset
limit, _ := controller.GetInt("limit")
listEmployeeQuery.Limit = limit
fmt.Print(listEmployeeQuery)
data, err := employeeService.ListEmployee(listEmployeeQuery)
var response utils.JsonResponse
if err != nil {
... ...
... ... @@ -81,28 +81,20 @@ func (controller *SuMoneyController) ExchangeSuMoney() {
func (controller *SuMoneyController) SearchSuMoneyTransactionRecord() {
suMoneyService := service.NewSuMoneyService(nil)
searchSuMoneyTransactionRecordCommand := &command.SearchSuMoneyTransactionRecordCommand{}
//employeeMatchName := controller.GetString("employeeMatchName")
//searchSuMoneyTransactionRecordCommand.EmployeeMatchName = employeeMatchName
employeeMatchName := controller.GetString("employeeMatchName")
searchSuMoneyTransactionRecordCommand.EmployeeMatchName = employeeMatchName
offset, _ := controller.GetInt("offset")
searchSuMoneyTransactionRecordCommand.Offset = offset
limit, _ := controller.GetInt("limit")
searchSuMoneyTransactionRecordCommand.Limit = limit
json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), searchSuMoneyTransactionRecordCommand)
data, err := suMoneyService.SearchSuMoneyTransactionRecord(searchSuMoneyTransactionRecordCommand)
var response utils.JsonResponse
if err != nil {
response = utils.ResponseError(controller.Ctx, err)
} else {
response = utils.ResponseData(controller.Ctx, data)
}
controller.Data["json"] = response
controller.ServeJSON()
}
... ... @@ -147,21 +139,16 @@ func (controller *SuMoneyController) CashInput() {
func (controller *SuMoneyController) GetCashPool() {
cashPoolService := service.NewCashPoolService(nil)
getCashPoolQuery := &query.GetCashPoolQuery{}
//json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), getCashPoolQuery)
companyId, _ := controller.GetInt64("companyId")
getCashPoolQuery.CompanyId = companyId
data, err := cashPoolService.GetCashPool(getCashPoolQuery)
var response utils.JsonResponse
if err != nil {
response = utils.ResponseError(controller.Ctx, err)
} else {
response = utils.ResponseData(controller.Ctx, data)
}
controller.Data["json"] = response
controller.ServeJSON()
}
... ... @@ -170,29 +157,21 @@ func (controller *SuMoneyController) GetCashPool() {
func (controller *SuMoneyController) ListExchangeActivities () {
cashPoolService := service.NewCashPoolService(nil)
listExchangeCashActivityQuery := &query.ListExchangeCashActivityQuery{}
companyId, _ := controller.GetInt64("companyId")
listExchangeCashActivityQuery.CompanyId = companyId
exchangeCashActivityNameMatch := controller.GetString("activityNameMatch")
listExchangeCashActivityQuery.ExchangeCashActivityNameMatch = exchangeCashActivityNameMatch
offset, _ := controller.GetInt("offset")
listExchangeCashActivityQuery.Offset = offset
limit, _ := controller.GetInt("limit")
listExchangeCashActivityQuery.Limit = limit
data, err := cashPoolService.ListExchangeCashActivity(listExchangeCashActivityQuery)
var response utils.JsonResponse
if err != nil {
response = utils.ResponseError(controller.Ctx, err)
} else {
response = utils.ResponseData(controller.Ctx, data)
}
controller.Data["json"] = response
controller.ServeJSON()
}
... ... @@ -236,7 +215,8 @@ func (controller *SuMoneyController) RemoveExchangeActivities () {
cashPoolService := service.NewCashPoolService(nil)
removeExchangeCashActivityCommand := &command.RemoveExchangeCashActivityCommand{}
activityId, _ := controller.GetInt64(":activityId")
removeExchangeCashActivityCommand. ExchangeCashActivityId = activityId
beego.Info(activityId)
removeExchangeCashActivityCommand.ActivityId = activityId
data, err := cashPoolService.RemoveExchangeCashActivity(removeExchangeCashActivityCommand)
var response utils.JsonResponse
if err != nil {
... ... @@ -277,6 +257,9 @@ func (controller *SuMoneyController) ListExchangeList () {
listExchangeCashListQuery.Offset = offset
limit, _ := controller.GetInt("limit")
listExchangeCashListQuery.Limit = limit
fmt.Println("hahahhah", listExchangeCashListQuery)
data, err := cashPoolService.ListExchangeCashPerson(listExchangeCashListQuery)
var response utils.JsonResponse
if err != nil {
... ... @@ -310,7 +293,7 @@ func (controller *SuMoneyController) UpdateExchangeList () {
updateExchangeCashPersonCommand := &command.UpdateExchangeCashPersonCommand{}
json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), updateExchangeCashPersonCommand)
personId, _ := controller.GetInt64(":personId")
updateExchangeCashPersonCommand. ExchangeCashPersonId = personId
updateExchangeCashPersonCommand.ListId = personId
data, err := cashPoolService.UpdateExchangeCashPerson(updateExchangeCashPersonCommand)
var response utils.JsonResponse
if err != nil {
... ... @@ -323,11 +306,11 @@ func (controller *SuMoneyController) UpdateExchangeList () {
}
// 移除兑换现金人员
func (controller *SuMoneyController) RemoveExchangeList () {
func (controller *SuMoneyController) RemoveExchangeCashPerson() {
cashPoolService := service.NewCashPoolService(nil)
removeExchangeCashPersonCommand := &command.RemoveExchangeCashPersonCommand{}
personId, _ := controller.GetInt64(":personId")
removeExchangeCashPersonCommand.ExchangeCashPersonId = personId
personId, _ := controller.GetInt64(":listId")
removeExchangeCashPersonCommand.ListId = personId
data, err := cashPoolService.RemoveExchangeCashPerson(removeExchangeCashPersonCommand)
var response utils.JsonResponse
if err != nil {
... ... @@ -343,8 +326,8 @@ func (controller *SuMoneyController) RemoveExchangeList () {
func (controller *SuMoneyController) GetExchangeCashPerson () {
cashPoolService := service.NewCashPoolService(nil)
getExchangeCashPersonQuery := &query.GetExchangeCashPersonQuery{}
personId, _ := controller.GetInt64(":personId")
getExchangeCashPersonQuery.ExchangeCashPersonId = personId
listId, _ := controller.GetInt64(":listId")
getExchangeCashPersonQuery.ExchangeCashPersonId = listId
data, err := cashPoolService.GetExchangeCashPerson(getExchangeCashPersonQuery)
var response utils.JsonResponse
if err != nil {
... ... @@ -376,6 +359,8 @@ func (controller *SuMoneyController) ImportExchangeList () {
fmt.Println(err)
return
}
// TODO 判断活动汇率是否为空
var response utils.JsonResponse
dataList := make([]interface{}, 0)
rows, _ := xlsx.GetRows("Sheet1")
... ... @@ -383,10 +368,9 @@ func (controller *SuMoneyController) ImportExchangeList () {
if i > 0 {
for _, _ = range row {
createExchangeCashPersonCommand.ExchangeCashActivityId = activityId
createExchangeCashPersonCommand.PersonId, _ = strconv.ParseInt(row[0], 10, 32)
createExchangeCashPersonCommand.PersonName = row[1]
createExchangeCashPersonCommand.PersonAccount = row[2]
createExchangeCashPersonCommand.ExchangedSuMoney, _ = strconv.ParseFloat(row[3], 64)
createExchangeCashPersonCommand.PersonName = row[0]
createExchangeCashPersonCommand.PersonAccount = row[1]
createExchangeCashPersonCommand.ExchangedSuMoney, _ = strconv.ParseFloat(row[2], 64)
}
fmt.Print(createExchangeCashPersonCommand)
data, err := cashPoolService.CreateExchangeCashPerson(createExchangeCashPersonCommand)
... ...
... ... @@ -18,15 +18,15 @@ func init() {
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") // 返回兑换活动
beego.Router("/cash-pool/activity/:activityId", &controllers.SuMoneyController{}, "GET:GetExchangeCashActivity") // 返回兑换活动
beego.Router("/cash-pool/activity/:activityId", &controllers.SuMoneyController{}, "PUT:UpdateExchangeActivities") // 编辑兑换活动
beego.Router("/cash-pool/activity", &controllers.SuMoneyController{}, "POST:CreateExchangeActivities") // 新增兑换活动
beego.Router("/cash-pool/activity/:activityId", &controllers.SuMoneyController{}, "DELETE:RemoveExchangeActivities") // 删除兑换活动
beego.Router("/cash-pool/activity/exchange-list", &controllers.SuMoneyController{}, "GET:ListExchangeList") // 返回素币兑换清单
beego.Router("/cash-pool/activity/exchange-list/:personId", &controllers.SuMoneyController{}, "GET:GetExchangeCashPerson") // 返回素币兑换人员
beego.Router("/cash-pool/activity/exchange-list/:listId", &controllers.SuMoneyController{}, "GET:GetExchangeCashPerson") // 返回素币兑换人员
beego.Router("/cash-pool/activity/exchange-list", &controllers.SuMoneyController{}, "POST:CreateExchangeList") // 新增素币兑换清单
beego.Router("/cash-pool/activity/exchange-list/:personId", &controllers.SuMoneyController{}, "PUT:UpdateExchangeList") // 编辑素币兑换清单
beego.Router("/cash-pool/activity/exchange-list/:personId", &controllers.SuMoneyController{}, "DELETE:RemoveExchangeList") // 删除素币兑换清单
beego.Router("/cash-pool/activity/exchange-list/:listId", &controllers.SuMoneyController{}, "PUT:UpdateExchangeList") // 编辑素币兑换清单
beego.Router("/cash-pool/activity/exchange-list/:listId", &controllers.SuMoneyController{}, "DELETE:RemoveExchangeCashPerson") // 删除素币兑换清单
beego.Router("/cash-pool/activity/exchange-list/import", &controllers.SuMoneyController{}, "POST:ImportExchangeList") // 导入素币兑换清单
}
... ...