作者 陈志颖

feat:增加个人贡献值收支

... ... @@ -304,7 +304,7 @@ func (statisticsService *StatisticsService) SystemCashStatistics(systemCashStati
}
}
// 获取员工财富值分组统计
// 获取公司员工财富值分组统计
func (statisticsService *StatisticsService) EmployeesSuMoneyStatistics(employeesSuMoneyStatisticsCommand *command.EmployeesSuMoneyStatisticsCommand) (interface{}, error) {
if err := employeesSuMoneyStatisticsCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
... ... @@ -344,7 +344,7 @@ func (statisticsService *StatisticsService) EmployeesSuMoneyStatistics(employees
}
}
// 获取员工贡献值分组统计
// 获取公司员工贡献值分组统计
func (statisticsService *StatisticsService) EmployeesContributionsStatistics(employeesContributionsStatisticsCommand *command.EmployeesContributionsStatisticsCommand) (interface{}, error) {
if err := employeesContributionsStatisticsCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
... ... @@ -385,44 +385,44 @@ func (statisticsService *StatisticsService) EmployeesContributionsStatistics(emp
}
// 员工排行榜统计 (弃用)
func (statisticsService *StatisticsService) EmployeesRankingListStatistics(employeesRankingListStatisticsCommand *command.EmployeesRankingListStatisticsCommand) (interface{}, error) {
if err := employeesRankingListStatisticsCommand.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{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
} else {
employeeDao = value
}
if employeesRankingListStatisticsCommand.StartTime.IsZero() && employeesRankingListStatisticsCommand.EndTime.IsZero() {
employeesRankingListStatisticsCommand.StartTime = time.Date(1971, time.Month(1), 1, 0, 0, 0, 0, time.Now().Location())
employeesRankingListStatisticsCommand.EndTime = time.Now().Local()
}
if employeesRankingListStatistics, err := employeeDao.CalculateEmployeesRankingList(employeesRankingListStatisticsCommand.CompanyId, employeesRankingListStatisticsCommand.StartTime, employeesRankingListStatisticsCommand.EndTime, employeesRankingListStatisticsCommand.Offset, employeesRankingListStatisticsCommand.Limit); 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 employeesRankingListStatistics, nil
}
}
//func (statisticsService *StatisticsService) EmployeesRankingListStatistics(employeesRankingListStatisticsCommand *command.EmployeesRankingListStatisticsCommand) (interface{}, error) {
// if err := employeesRankingListStatisticsCommand.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{}{
// "transactionContext": transactionContext,
// }); err != nil {
// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
// } else {
// employeeDao = value
// }
//
// if employeesRankingListStatisticsCommand.StartTime.IsZero() && employeesRankingListStatisticsCommand.EndTime.IsZero() {
// employeesRankingListStatisticsCommand.StartTime = time.Date(1971, time.Month(1), 1, 0, 0, 0, 0, time.Now().Location())
// employeesRankingListStatisticsCommand.EndTime = time.Now().Local()
// }
//
// if employeesRankingListStatistics, err := employeeDao.CalculateEmployeesRankingList(employeesRankingListStatisticsCommand.CompanyId, employeesRankingListStatisticsCommand.StartTime, employeesRankingListStatisticsCommand.EndTime, employeesRankingListStatisticsCommand.Offset, employeesRankingListStatisticsCommand.Limit); 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 employeesRankingListStatistics, nil
// }
//}
// 贡献值、财富值榜单
func (statisticsService *StatisticsService) ContributionsWealthRanking(contributionsWealthRankingQuery *query.ContributionsWealthRankingQuery) (interface{}, error) {
... ...
package command
import (
"fmt"
"github.com/astaxie/beego/validation"
"time"
)
type ContributionsTransactionRecordStatisticsCommand struct {
// 统一用户UID
Uid int64 `json:"uid" valid:"Required"`
// 事务时间区间-开始时间
TransactionStartTime time.Time `json:"transactionStartTime,omitempty"`
// 事务时间区间-截止时间
TransactionEndTime time.Time `json:"transactionEndTime,omitempty"`
}
func (contributionsTransactionRecordStatisticsCommand *ContributionsTransactionRecordStatisticsCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(contributionsTransactionRecordStatisticsCommand)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
\ No newline at end of file
... ...
... ... @@ -1055,12 +1055,7 @@ func (cashPoolService *CashPoolService) GetExchangeCashPerson(getExchangeCashPer
}
}
// 返回素币兑换现金活动总清单
//func (cashPoolService *CashPoolService) ListSystemExchangeCashPerson(listSystemExchangeCashPersonQuery *query.ListSystemExchangeCashPersonQuery) (interface{}, error) {
//
//}
// 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())
... ... @@ -1368,11 +1363,6 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashPersonCommand.ListId)))
}
// TODO 更新兑换清单,个人已兑换现金计算
if err := person.Update(tool_funs.SimpleStructToMap(updateExchangeCashPersonCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
var exchangeCashActivityRepository domain.ExchangeActivityRepository
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -1391,6 +1381,13 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(person.ExchangeCashActivityId)))
}
// 更新兑换清单,个人已兑换现金计算
updateExchangeCashPersonCommand.ExchangedCash = updateExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate
if err := person.Update(tool_funs.SimpleStructToMap(updateExchangeCashPersonCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
ExchangeCashActivityId: person.ExchangeCashActivityId,
ExchangedSuMoney: activityFound.ExchangedSuMoney + (updateExchangeCashPersonCommand.ExchangedSuMoney - person.ExchangedSuMoney),
... ...
... ... @@ -165,6 +165,7 @@ func (suMoneyService *SuMoneyService) SuMoneyTransactionRecordStatistics(suMoney
defer func() {
transactionContext.RollbackTransaction()
}()
var employeeDao *dao.EmployeeDao
if value, err := factory.CreateEmployeeDao(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -173,6 +174,7 @@ func (suMoneyService *SuMoneyService) SuMoneyTransactionRecordStatistics(suMoney
} else {
employeeDao = value
}
if calculateResult, err := employeeDao.CalculateSuMoneyTransactionRecord(suMoneyTransactionRecordStatisticsCommand.Uid, suMoneyTransactionRecordStatisticsCommand.TransactionStartTime, suMoneyTransactionRecordStatisticsCommand.TransactionEndTime); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ... @@ -183,6 +185,42 @@ func (suMoneyService *SuMoneyService) SuMoneyTransactionRecordStatistics(suMoney
}
}
// 贡献值事务记录统计
func (suMoneyService *SuMoneyService) ContributionsTransactionRecordStatistics(contributionsTransactionRecordStatisticsCommand *command.ContributionsTransactionRecordStatisticsCommand) (interface{}, error) {
if err := contributionsTransactionRecordStatisticsCommand.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{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
employeeDao = value
}
if calculateResult, err := employeeDao.CalculateSuMoneyTransactionRecord(contributionsTransactionRecordStatisticsCommand.Uid, contributionsTransactionRecordStatisticsCommand.TransactionStartTime, contributionsTransactionRecordStatisticsCommand.TransactionEndTime); 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 calculateResult, nil
}
}
func NewSuMoneyService(options map[string]interface{}) *SuMoneyService {
newSuMoneyService := &SuMoneyService{}
return newSuMoneyService
... ...
... ... @@ -31,6 +31,7 @@ func (dao *EmployeeDao) BatchSetStatus(uids []int64, status int) error {
return err
}
// 修改用户权限
func (dao *EmployeeDao) ChangePrincipal(companyId int64, employeeAccount string) error {
tx := dao.transactionContext.PgTx
if _, err := tx.Query(
... ... @@ -48,6 +49,7 @@ func (dao *EmployeeDao) ChangePrincipal(companyId int64, employeeAccount string)
return nil
}
//
func (dao *EmployeeDao) TransferSuMoney(uid int64, suMoney float64) error {
tx := dao.transactionContext.PgTx
_, err := tx.QueryOne(
... ... @@ -87,7 +89,7 @@ func (dao *EmployeeDao) CalculatePersonUnReadNotification(uid int64) (map[string
}, nil
}
// 计算个人素币情况,昨日收益:做任务验收获得的素币+额外增加-扣除素币-兑换物资-兑换现金
// 计算个人素币收益,昨日收益:做任务验收获得的素币+额外增加-扣除素币-兑换物资-兑换现金
func (dao *EmployeeDao) CalculatePersonSuMoney(uid int64) (map[string]interface{}, error) {
var incomeSuMoney float64
var expendSuMoney float64
... ... @@ -142,7 +144,7 @@ func (dao *EmployeeDao) CalculatePersonSuMoney(uid int64) (map[string]interface{
}, nil
}
// 系统已兑换素币、未兑换素币
// 计算系统已兑换素币、未兑换素币
func (dao *EmployeeDao) CalculateSystemSuMoney(companyId int64) (map[string] interface{}, error) {
var systemUnExchangeSuMoney float64
var systemExchangedSuMoney float64
... ... @@ -203,10 +205,12 @@ func (dao *EmployeeDao) CalculateSystemCash(companyId int64) (map[string] interf
}, nil
}
// 个人收入支出素币统计
// 计算个人素币收支
func (dao *EmployeeDao) CalculateSuMoneyTransactionRecord(uid int64, transactionStartTime time.Time, transactionEndTime time.Time) (map[string]interface{}, error) {
var incomeSuMoney float64 // 收入的素币(2:任务奖励,3:增加)
var expendSuMoney float64 // 消耗的素币(1:兑换物资,4:扣除, 5: 兑换现金)
var (
incomeSuMoney float64 // 收入的素币(2:任务奖励,3:增加)
expendSuMoney float64 // 消耗的素币(1:兑换物资,4:扣除, 5: 兑换现金)
)
tx := dao.transactionContext.PgTx
suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
// 收入素币
... ... @@ -235,31 +239,37 @@ func (dao *EmployeeDao) CalculateSuMoneyTransactionRecord(uid int64, transaction
}, nil
}
// 员工财富值统计
func (dao *EmployeeDao) CalculateEmployeesSuMoney(companyId int, startTime time.Time, endTime time.Time) (map[string]interface{}, error) {
var ret []struct {
Uid int
EmployeeName string
EmployeeSuMoney float64
}
// 计算个人贡献值收支
func (dao *EmployeeDao) CalculateContributionsTransactionRecord(uid int64, transactionStartTime time.Time, transactionEndTime time.Time) (map[string]interface{}, error) {
var (
incomeContributions float64 // 增加的贡献值(2:任务奖励,3:增加)
expendContributions float64 // 扣除的贡献值 (4: 扣除)
)
tx := dao.transactionContext.PgTx
suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint").
ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid").
ColumnExpr("su_money_transaction_record.employee->>'employeeName' AS employee_name").
ColumnExpr("sum(su_money_transaction_record.su_money) AS employee_su_money").
Where(`e.company_id = ?`, companyId).
Where(`e.status = ?`, 1).
Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3})). // 增加,任务奖励的
Where(`su_money_transaction_record.create_time > ?`, startTime).
Where(`su_money_transaction_record.create_time < ?`, endTime).
Group("su_money_transaction_record.employee").
Order("employee_su_money DESC").
Select(&ret); err != nil {
// 增加的贡献值
if err := tx.Model(suMoneyTransactionRecordModel).
ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money").
Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid).
Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3})).
Where(`su_money_transaction_record.create_time > ?`, transactionStartTime).
Where(`su_money_transaction_record.create_time < ?`, transactionEndTime).
Select(&incomeContributions); err != nil {
return nil, err
}
// 扣除的贡献值
if err := tx.Model(suMoneyTransactionRecordModel).
ColumnExpr("sum(su_money_transaction_record.su_money) AS expend_su_money").
Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid).
Where(`su_money_transaction_record.record_type =?`, 4).
Where(`su_money_transaction_record.create_time > ?`, transactionStartTime).
Where(`su_money_transaction_record.create_time < ?`, transactionEndTime).
Select(&expendContributions); err != nil {
return nil, err
}
return map[string]interface{}{
"employeesSuMoney": ret,
"incomeContributions": incomeContributions,
"expendContributions": expendContributions,
}, nil
}
... ... @@ -311,7 +321,7 @@ func (dao *EmployeeDao) CalculateEmployeesSuMoney(companyId int, startTime time.
// }, nil
//}
// 贡献值、财富值总榜和年榜
// 贡献值、财富值总榜和年榜
func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]interface{}) (interface{}, error) {
var retWealth []struct {
Uid int
... ... @@ -337,10 +347,8 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter
EmployeesContributions float64
Ranking int
}
tx := dao.transactionContext.PgTx
suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
// 财富值榜单
queryWealth := tx.Model(suMoneyTransactionRecordModel)
queryWealth = queryWealth.Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint")
... ... @@ -432,24 +440,6 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter
}
contributionsDecrease := queryContributionsDecrease.Group("su_money_transaction_record.employee")
//if offset, ok := queryOptions["offset"]; ok {
// offset := offset.(int)
// if offset > -1 {
// queryContributionsDecrease = queryContributionsDecrease.Offset(offset)
// }
//} else {
// queryContributionsDecrease = queryContributionsDecrease.Offset(0)
//}
//if limit, ok := queryOptions["limit"]; ok {
// limit := limit.(int)
// if limit > -1 {
// queryContributionsDecrease = queryContributionsDecrease.Limit(limit)
// }
//} else {
// queryContributionsDecrease = queryContributionsDecrease.Limit(20)
//}
//contributionsDecrease := queryWealth.Order("employee_contributions_decrease DESC")
queryContributions := tx.Model()
queryContributions = queryContributions.With("t", contributionsDecrease)
queryContributions = queryContributions.Table("t")
... ... @@ -555,51 +545,112 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter
}, nil
}
// 排行榜统计,排名(弃用)
func (dao *EmployeeDao) CalculateEmployeesRankingList(companyId int, startTime time.Time, endTime time.Time, offset int, limit int) (map[string]interface{}, error) {
var retWealth []struct {
Uid int
EmployeeName string
EmployeeSuMoney float64
Ranking int
}
var retContributions []struct { // 员工贡献值
// 排行榜统计,排名
//func (dao *EmployeeDao) CalculateEmployeesRankingList(companyId int, startTime time.Time, endTime time.Time, offset int, limit int) (map[string]interface{}, error) {
// var retWealth []struct {
// Uid int
// EmployeeName string
// EmployeeSuMoney float64
// Ranking int
// }
// var retContributions []struct { // 员工贡献值
// Uid int
// EmployeeName string
// EmployeesContributions float64
// Ranking int
// }
// var retContributionDecrease []struct { // 员工减少的贡献值
// Uid int
// EmployeeName string
// EmployeesContributions float64
// Ranking int
// }
// tx := dao.transactionContext.PgTx
// suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
// if limit < -1 {
// limit = 20
// }
// if offset < -1 {
// offset = 0
// }
// // 员工财富值
// if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint").
// ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid").
// ColumnExpr("su_money_transaction_record.employee->>'employeeName' AS employee_name").
// ColumnExpr("sum(su_money_transaction_record.su_money) AS employee_su_money").
// Where(`e.company_id = ?`, companyId).
// Where(`e.status = ?`, 1).
// Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3})). // 增加,任务奖励的
// Where(`su_money_transaction_record.create_time > ?`, startTime).
// Where(`su_money_transaction_record.create_time < ?`, endTime).
// Group("su_money_transaction_record.employee").
// Order("employee_su_money DESC").
// Limit(limit).
// Offset(offset).
// Select(&retWealth); err != nil {
// return nil, err
// }
// // 增加的贡献值
// if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint").
// ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid").
// ColumnExpr("su_money_transaction_record.employee->>'employeeName' AS employee_name").
// ColumnExpr("sum(su_money_transaction_record.su_money) AS employees_contributions").
// Where(`e.company_id = ?`, companyId).
// Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3})).
// Where(`e.status = ?`, 1).
// Where(`su_money_transaction_record.create_time > ?`, startTime).
// Where(`su_money_transaction_record.create_time < ?`, endTime).
// Group("su_money_transaction_record.employee").
// Order("employees_contributions DESC").
// Limit(limit).
// Offset(offset).
// Select(&retContributions); err != nil {
// return nil, err
// }
// // 减少的贡献值
// if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint").
// ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid").
// ColumnExpr("su_money_transaction_record.employee->>'employeeName' AS employee_name").
// ColumnExpr("sum(su_money_transaction_record.su_money) AS employees_contributions").
// Where(`e.company_id = ?`, companyId).
// Where(`su_money_transaction_record.record_type = ?`, 4).
// Where(`e.status = ?`, 1).
// Where(`su_money_transaction_record.create_time > ?`, startTime).
// Where(`su_money_transaction_record.create_time < ?`, endTime).
// Group("su_money_transaction_record.employee").
// Order("employees_contributions DESC").
// Limit(limit).
// Offset(offset).
// Select(&retContributionDecrease); err != nil {
// return nil, err
// }
// for i := 0; i < len(retContributions); i++ {
// for j := 0; j < len(retContributionDecrease); j++ {
// if retContributions[i].Uid == retContributionDecrease[j].Uid {
// retContributions[i].EmployeesContributions -= retContributionDecrease[j].EmployeesContributions
// }
// }
// }
// return map[string]interface{}{
// "employeesContributions": retContributions,
// "employeesWealth": retWealth,
// }, nil
//}
// 公司员工贡献值分组统计
func (dao *EmployeeDao) CalculateEmployeesContributions(companyId int, startTime time.Time, endTime time.Time) (map[string]interface{}, error) {
var ret []struct { // 员工贡献值
Uid int
EmployeeName string
EmployeesContributions float64
Ranking int
}
var retContributionDecrease []struct { // 员工减少的贡献值
var retDecrease []struct { // 员工减少的贡献值
Uid int
EmployeeName string
EmployeesContributions float64
Ranking int
}
tx := dao.transactionContext.PgTx
suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
if limit < -1 {
limit = 20
}
if offset < -1 {
offset = 0
}
// 员工财富值
if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint").
ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid").
ColumnExpr("su_money_transaction_record.employee->>'employeeName' AS employee_name").
ColumnExpr("sum(su_money_transaction_record.su_money) AS employee_su_money").
Where(`e.company_id = ?`, companyId).
Where(`e.status = ?`, 1).
Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3})). // 增加,任务奖励的
Where(`su_money_transaction_record.create_time > ?`, startTime).
Where(`su_money_transaction_record.create_time < ?`, endTime).
Group("su_money_transaction_record.employee").
Order("employee_su_money DESC").
Limit(limit).
Offset(offset).
Select(&retWealth); err != nil {
return nil, err
}
// 增加的贡献值
if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint").
ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid").
... ... @@ -612,9 +663,7 @@ func (dao *EmployeeDao) CalculateEmployeesRankingList(companyId int, startTime t
Where(`su_money_transaction_record.create_time < ?`, endTime).
Group("su_money_transaction_record.employee").
Order("employees_contributions DESC").
Limit(limit).
Offset(offset).
Select(&retContributions); err != nil {
Select(&ret); err != nil {
return nil, err
}
// 减少的贡献值
... ... @@ -629,77 +678,46 @@ func (dao *EmployeeDao) CalculateEmployeesRankingList(companyId int, startTime t
Where(`su_money_transaction_record.create_time < ?`, endTime).
Group("su_money_transaction_record.employee").
Order("employees_contributions DESC").
Limit(limit).
Offset(offset).
Select(&retContributionDecrease); err != nil {
Select(&retDecrease); err != nil {
return nil, err
}
for i := 0; i < len(retContributions); i++ {
for j := 0; j < len(retContributionDecrease); j++ {
if retContributions[i].Uid == retContributionDecrease[j].Uid {
retContributions[i].EmployeesContributions -= retContributionDecrease[j].EmployeesContributions
for i := 0; i < len(ret); i++ {
for j := 0; j < len(retDecrease); j++ {
if ret[i].Uid == retDecrease[j].Uid {
ret[i].EmployeesContributions -= retDecrease[j].EmployeesContributions
}
}
}
return map[string]interface{}{
"employeesContributions": retContributions,
"employeesWealth": retWealth,
"employeesContributions": ret,
}, nil
}
// 员工贡献值统计
func (dao *EmployeeDao) CalculateEmployeesContributions(companyId int, startTime time.Time, endTime time.Time) (map[string]interface{}, error) {
var ret []struct { // 员工贡献值
Uid int
EmployeeName string
EmployeesContributions float64
}
var retDecrease []struct { // 员工减少的贡献值
// 公司员工财富值分组统计
func (dao *EmployeeDao) CalculateEmployeesSuMoney(companyId int, startTime time.Time, endTime time.Time) (map[string]interface{}, error) {
var ret []struct {
Uid int
EmployeeName string
EmployeesContributions float64
EmployeeSuMoney float64
}
tx := dao.transactionContext.PgTx
suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
// 增加的贡献值
if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint").
ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid").
ColumnExpr("su_money_transaction_record.employee->>'employeeName' AS employee_name").
ColumnExpr("sum(su_money_transaction_record.su_money) AS employees_contributions").
ColumnExpr("sum(su_money_transaction_record.su_money) AS employee_su_money").
Where(`e.company_id = ?`, companyId).
Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3})).
Where(`e.status = ?`, 1).
Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3})). // 增加,任务奖励的
Where(`su_money_transaction_record.create_time > ?`, startTime).
Where(`su_money_transaction_record.create_time < ?`, endTime).
Group("su_money_transaction_record.employee").
Order("employees_contributions DESC").
Order("employee_su_money DESC").
Select(&ret); err != nil {
return nil, err
}
// 减少的贡献值
if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint").
ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid").
ColumnExpr("su_money_transaction_record.employee->>'employeeName' AS employee_name").
ColumnExpr("sum(su_money_transaction_record.su_money) AS employees_contributions").
Where(`e.company_id = ?`, companyId).
Where(`su_money_transaction_record.record_type = ?`, 4).
Where(`e.status = ?`, 1).
Where(`su_money_transaction_record.create_time > ?`, startTime).
Where(`su_money_transaction_record.create_time < ?`, endTime).
Group("su_money_transaction_record.employee").
Order("employees_contributions DESC").
Select(&retDecrease); err != nil {
return nil, err
}
for i := 0; i < len(ret); i++ {
for j := 0; j < len(retDecrease); j++ {
if ret[i].Uid == retDecrease[j].Uid {
ret[i].EmployeesContributions -= retDecrease[j].EmployeesContributions
}
}
}
return map[string]interface{}{
"employeesContributions": ret,
"employeesSuMoney": ret,
}, nil
}
... ...
... ... @@ -15,6 +15,7 @@ type StatisticsController struct {
beego.Controller
}
// 系统任务统计
func (controller *StatisticsController) SystemTaskStatistics() {
statisticsService := service.NewStatisticsService(nil)
systemTaskStatisticsCommand := &command.SystemTaskStatisticsCommand{}
... ... @@ -30,6 +31,7 @@ func (controller *StatisticsController) SystemTaskStatistics() {
controller.ServeJSON()
}
// 个人任务统计
func (controller *StatisticsController) PersonTaskStatistics() {
statisticsService := service.NewStatisticsService(nil)
personTaskStatisticsCommand := &command.PersonTaskStatisticsCommand{}
... ... @@ -45,6 +47,7 @@ func (controller *StatisticsController) PersonTaskStatistics() {
controller.ServeJSON()
}
// 个人素币统计
func (controller *StatisticsController) PersonSuMoneyStatistics() {
statisticsService := service.NewStatisticsService(nil)
personSuMoneyStatisticsCommand := &command.PersonSuMoneyStatisticsCommand{}
... ... @@ -60,6 +63,7 @@ func (controller *StatisticsController) PersonSuMoneyStatistics() {
controller.ServeJSON()
}
// 个人通知统计
func (controller *StatisticsController) PersonNotificationStatistics() {
statisticsService := service.NewStatisticsService(nil)
personNotificationStatisticsCommand := &command.PersonNotificationStatisticsCommand{}
... ... @@ -75,6 +79,7 @@ func (controller *StatisticsController) PersonNotificationStatistics() {
controller.ServeJSON()
}
// 系统素币统计
func (controller *StatisticsController) SystemSuMoneyStatistics() {
statisticsService := service.NewStatisticsService(nil)
systemSuMoneyStatisticsCommand := &command.SystemSuMoneyStatisticsCommand{}
... ... @@ -90,6 +95,7 @@ func (controller *StatisticsController) SystemSuMoneyStatistics() {
controller.ServeJSON()
}
// 系统现金统计
func (controller *StatisticsController) SystemCashStatistics() {
statisticsService := service.NewStatisticsService(nil)
systemCashStatisticsCommand := &command.SystemCashStatisticsCommand{}
... ... @@ -105,7 +111,7 @@ func (controller *StatisticsController) SystemCashStatistics() {
controller.ServeJSON()
}
// 获取员工财富值
// 获取公司员工财富值
func (controller *StatisticsController) EmployeesSuMoneyStatistics() {
statisticsService := service.NewStatisticsService(nil)
employeesSuMoneyStatisticsCommand := &command.EmployeesSuMoneyStatisticsCommand{}
... ... @@ -122,7 +128,7 @@ func (controller *StatisticsController) EmployeesSuMoneyStatistics() {
controller.ServeJSON()
}
// 获取员工贡献值
// 获取公司员工贡献值
func (controller *StatisticsController) EmployeesContributionsStatistics() {
statisticsService := service.NewStatisticsService(nil)
employeesContributionsStatisticsCommand := &command.EmployeesContributionsStatisticsCommand{}
... ... @@ -138,7 +144,7 @@ func (controller *StatisticsController) EmployeesContributionsStatistics() {
controller.ServeJSON()
}
// 员工财富值、贡献值排行榜
// 公司员工财富值、贡献值排行榜
func (controller *StatisticsController) RankingListStatistics() {
statisticsService := service.NewStatisticsService(nil)
contributionsWealthRankingQuery := &query.ContributionsWealthRankingQuery{}
... ...
... ... @@ -85,6 +85,7 @@ func (controller *SuMoneyController) SearchSuMoneyTransactionRecord() {
controller.ServeJSON()
}
// 素币事务统计(个人素币收支)
func (controller *SuMoneyController) SuMoneyTransactionRecordStatistics() {
suMoneyService := service.NewSuMoneyService(nil)
suMoneyTransactionRecordStatisticsCommand := &command.SuMoneyTransactionRecordStatisticsCommand{}
... ... @@ -100,6 +101,22 @@ func (controller *SuMoneyController) SuMoneyTransactionRecordStatistics() {
controller.ServeJSON()
}
// 贡献值事务统计(个人贡献值收支)
func (controller *SuMoneyController) ContributionsTransactionRecordStatistics() {
suMoneyService := service.NewSuMoneyService(nil)
contributionsTransactionRecordStatisticsCommand := &command.ContributionsTransactionRecordStatisticsCommand{}
json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), contributionsTransactionRecordStatisticsCommand)
data, err := suMoneyService.ContributionsTransactionRecordStatistics(contributionsTransactionRecordStatisticsCommand)
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()
}
// 投入现金池
func (controller *SuMoneyController) CashInput() {
cashPoolService := service.NewCashPoolService(nil)
... ...
... ... @@ -6,10 +6,10 @@ import (
)
func init() {
beego.Router("/statistics/system-task", &controllers.StatisticsController{}, "Post:SystemTaskStatistics")
beego.Router("/statistics/person-task", &controllers.StatisticsController{}, "Post:PersonTaskStatistics")
beego.Router("/statistics/person-su-money", &controllers.StatisticsController{}, "Post:PersonSuMoneyStatistics")
beego.Router("/statistics/person-notification", &controllers.StatisticsController{}, "Post:PersonNotificationStatistics")
beego.Router("/statistics/system-task", &controllers.StatisticsController{}, "Post:SystemTaskStatistics") // 系统任务统计
beego.Router("/statistics/person-task", &controllers.StatisticsController{}, "Post:PersonTaskStatistics") // 个人任务统计
beego.Router("/statistics/person-su-money", &controllers.StatisticsController{}, "Post:PersonSuMoneyStatistics") // 个人素币统计
beego.Router("/statistics/person-notification", &controllers.StatisticsController{}, "Post:PersonNotificationStatistics") // 个人通知统计
beego.Router("/statistics/system-su-money", &controllers.StatisticsController{}, "Post:SystemSuMoneyStatistics") // 系统素币统计
beego.Router("/statistics/system-cash", &controllers.StatisticsController{}, "Post:SystemCashStatistics") // 系统现金统计
beego.Router("/statistics/employees-su-money", &controllers.StatisticsController{}, "Post:EmployeesSuMoneyStatistics") // 员工财富值统计
... ...
... ... @@ -11,7 +11,8 @@ func init() {
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("/su-money/su-money-transaction-record-statistics", &controllers.SuMoneyController{}, "Post:SuMoneyTransactionRecordStatistics") // 返回素币事务记录统计(个人素币收支)
beego.Router("/su-money/contributions-transaction-record-statistics", &controllers.SuMoneyController{}, "Post:ContributionsTransactionRecordStatistics") // 返回贡献值事务记录统计(个人贡献值收支)
beego.Router("/su-money/su-money-transaction-records/export-records", &controllers.SuMoneyController{}, "Post:ExportSuMoneyTransactionRecord") // 导出素币事务记录(流水)
beego.Router("/su-money/su-money-transaction-records/export-su-money", &controllers.SuMoneyController{}, "Post:ExportSuMoney") // 导出员工素币
... ...