作者 陈志颖

feat:增加员工贡献值和财富值计算

... ... @@ -6,7 +6,7 @@ import (
)
type ListListIntervalQuery struct {
CompanyId int64 `json:"companyId"` // 公司id
CompanyId int `json:"companyId"` // 公司id
Offset int `json:"offset,omitempty"` // 查询偏离量
Limit int `json:"limit,omitempty"` // 查询限制
}
... ...
... ... @@ -82,7 +82,7 @@ func (listIntervalService *ListIntervalService) ListListInterval(listListInterva
}
return map[string]interface{}{
"count": count,
"taskNatures": listIntervals,
"listIntervals": listIntervals,
}, nil
}
}
... ...
package command
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type EmployeesContributionsStatisticsCommand struct {
CompanyId int `json:"companyId" valid:"Required"` // 公司id
}
func (employeesContributionsStatisticsCommand *EmployeesContributionsStatisticsCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(employeesContributionsStatisticsCommand)
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
... ...
package command
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type EmployeesSuMoneyStatisticsCommand struct {
CompanyId int `json:"companyId" valid:"Required"` // 公司id
}
func (employeesSuMoneyStatisticsCommand *EmployeesSuMoneyStatisticsCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(employeesSuMoneyStatisticsCommand)
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
... ...
... ... @@ -160,7 +160,6 @@ func (statisticsService *StatisticsService) PersonSuMoneyStatistics(personSuMone
defer func() {
transactionContext.RollbackTransaction()
}()
var employeeDao *dao.EmployeeDao
if value, err := factory.CreateEmployeeDao(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -169,8 +168,6 @@ func (statisticsService *StatisticsService) PersonSuMoneyStatistics(personSuMone
} else {
employeeDao = value
}
// 企业员工资源库
var employeeRepository domain.EmployeeRepository
if value, err := factory.CreateEmployeeRepository(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -179,8 +176,6 @@ func (statisticsService *StatisticsService) PersonSuMoneyStatistics(personSuMone
} else {
employeeRepository = value
}
// 判断企业员工是否有效
employee, err := employeeRepository.FindOne(map[string]interface{}{
"uid": personSuMoneyStatisticsCommand.Uid,
})
... ... @@ -190,8 +185,6 @@ func (statisticsService *StatisticsService) PersonSuMoneyStatistics(personSuMone
if employee == nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的企业员工")
}
// 计算个人素币
if personSuMoneyStatistics, err := employeeDao.CalculatePersonSuMoney(personSuMoneyStatisticsCommand.Uid); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ... @@ -203,7 +196,6 @@ func (statisticsService *StatisticsService) PersonSuMoneyStatistics(personSuMone
}
}
// TODO 系统素币统计
func (statisticsService *StatisticsService) SystemSuMoneyStatistics(systemSuMoneyStatisticsCommand *command.SystemSuMoneyStatisticsCommand) (interface{}, error) {
if err := systemSuMoneyStatisticsCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
... ... @@ -219,15 +211,6 @@ func (statisticsService *StatisticsService) SystemSuMoneyStatistics(systemSuMone
transactionContext.RollbackTransaction()
}()
//var cashPoolDao *dao.CashPoolDao
//if value, err := factory.CreateCashPoolDao(map[string]interface{}{
// "transactionContext": transactionContext,
//}); err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//} else {
// cashPoolDao = value
//}
var employeeDao *dao.EmployeeDao
if value, err := factory.CreateEmployeeDao(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -237,15 +220,6 @@ func (statisticsService *StatisticsService) SystemSuMoneyStatistics(systemSuMone
employeeDao = value
}
//var employeeRepository domain.EmployeeRepository
//if value, err := factory.CreateEmployeeRepository(map[string]interface{}{
// "transactionContext": transactionContext,
//}); err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//} else {
// employeeRepository = value
//}
if systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(systemSuMoneyStatisticsCommand.CompanyId); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ... @@ -256,7 +230,6 @@ func (statisticsService *StatisticsService) SystemSuMoneyStatistics(systemSuMone
}
}
// TODO 系统现金统计
func (statisticsService *StatisticsService) SystemCashStatistics(systemCashStatisticsCommand *command.SystemCashStatisticsCommand) (interface{}, error) {
if err := systemCashStatisticsCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
... ... @@ -272,15 +245,6 @@ func (statisticsService *StatisticsService) SystemCashStatistics(systemCashStati
transactionContext.RollbackTransaction()
}()
//var cashPoolDao *dao.CashPoolDao
//if value, err := factory.CreateCashPoolDao(map[string]interface{}{
// "transactionContext": transactionContext,
//}); err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//} else {
// cashPoolDao = value
//}
var employeeDao *dao.EmployeeDao
if value, err := factory.CreateEmployeeDao(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -300,6 +264,19 @@ func (statisticsService *StatisticsService) SystemCashStatistics(systemCashStati
}
}
// TODO 员工素币值统计
func (statisticsService *StatisticsService) EmployeesSuMoneyStatistics(employeesSuMoneyStatisticsCommand *command.EmployeesSuMoneyStatisticsCommand) (interface{}, error) {
return nil ,nil
}
// TODO 员工贡献值统计
func (statisticsService *StatisticsService) EmployeesContributionsStatistics(employeesContributionsStatisticsCommand *command.EmployeesContributionsStatisticsCommand) (interface{}, error) {
return nil, nil
}
func NewStatisticsService(options map[string]interface{}) *StatisticsService {
newStatisticsService := &StatisticsService{}
return newStatisticsService
... ...
... ... @@ -114,20 +114,20 @@ func (dao *EmployeeDao) CalculatePersonSuMoney(uid int64) (map[string]interface{
}, nil
}
// TODO 计算系统素币
// 计算系统素币
func (dao *EmployeeDao) CalculateSystemSuMoney(companyId int64) (map[string] interface{}, error) {
var systemUnExchangeSuMoney float64
var systemExchangedSuMoney float64
tx := dao.transactionContext.PgTx
suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS employee ON employee.uid = employee.uid").
if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_records.employee->>'uid')::bigint").
ColumnExpr("sum(su_money_transaction_record.current_su_money) AS system_unExchange_su_money").
Where("employee.company_id = ?", companyId).
Where(`su_money_transaction_record.record_type = ?`, 5).
Select(&systemUnExchangeSuMoney); err != nil {
return nil, err
}
if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS employee ON employee.uid = employee.uid").
if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_records.employee->>'uid')::bigint").
ColumnExpr("sum(su_money_transaction_record.su_money) AS system_changed_su_money").
Where("employee.company_id = ?", companyId).
Where(`su_money_transaction_record.record_type = ?`, 5).
... ... @@ -140,7 +140,7 @@ func (dao *EmployeeDao) CalculateSystemSuMoney(companyId int64) (map[string] int
},nil
}
// TODO 计算系统现金
// 计算系统现金
func (dao *EmployeeDao) CalculateSystemCash(companyId int64) (map[string] interface{}, error) {
var (
systemUnExchangeCash float64
... ... @@ -148,7 +148,7 @@ func (dao *EmployeeDao) CalculateSystemCash(companyId int64) (map[string] interf
)
tx := dao.transactionContext.PgTx
suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS employee ON employee.uid = employee.uid").
if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_records.employee->>'uid')::bigint").
ColumnExpr("sum(su_money_transaction_record.cash) AS system_exchanged_cash").
Where("employee.company_id = ?", companyId).
Where(`su_money_transaction_record.record_type = ?`, 5).
... ... @@ -158,7 +158,10 @@ func (dao *EmployeeDao) CalculateSystemCash(companyId int64) (map[string] interf
cashPool := new(models.CashPool)
if err := tx.Model(cashPool).
Column("un_exchange_cash").
Where("cash_pool.company_id = ?", companyId).
Order("id DSC").
Limit(1).
Select(&systemUnExchangeCash) ; err != nil {
return nil, err
}
... ... @@ -198,6 +201,52 @@ func (dao *EmployeeDao) CalculateSuMoneyTransactionRecord(uid int64, transaction
}, nil
}
func (dao *EmployeeDao) CalculateEmployeesSuMoney(companyId int) (map[string]interface{}, error) {
tx := dao.transactionContext.PgTx
var res []struct {
EmployeesSuMoney float64
Employee domain.Employee
}
suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint").
Column("su_money_transaction_record.employee, (su_money_transaction_record.employee->>'employeeName')::text,").
ColumnExpr("sum(su_money_transaction_record.current_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})).
Group("su_money_transaction_record.employee").
Order("employee_su_money DESC").
Select(&res); err != nil {
return nil, err
}
return map[string]interface{}{
"employeesSuMoney": res,
}, nil
}
func (dao *EmployeeDao) CalculateEmployeesContributions(companyId int) (map[string]interface{}, error) {
tx := dao.transactionContext.PgTx
var ret []struct {
EmployeesContributions float64
Employee domain.Employee
}
suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint").
Column("su_money_transaction_record.employee").
ColumnExpr("sum(s.current_su_money) AS employees_contributions").
Where(`e.company_id = ?`, companyId).
Where(`su_money_transaction_record.record_type = ?`, 2).
Where(`e.status = ?`, 1).
Group("su_money_transaction_record.employee").
Order("employees_contributions DESC").
Select(&ret); err != nil {
return nil, err
}
return map[string]interface{}{
"employeesContributions": ret,
}, nil
}
func NewEmployeeDao(transactionContext *pgTransaction.TransactionContext) (*EmployeeDao, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
... ...
... ... @@ -39,6 +39,7 @@ func init() {
(*models.CashPool)(nil),
(*models.ExchangeCashActivity)(nil),
(*models.ExchangeCashPersonList)(nil),
(*models.ListInterval)(nil),
} {
err := DB.CreateTable(model, &orm.CreateTableOptions{
Temp: false,
... ...
... ... @@ -18,7 +18,7 @@ func (repository *ListIntervalRepository) Save(listInterval *domain.ListInterval
if _, err := tx.QueryOne(
pg.Scan(&listInterval.ListIntervalId, &listInterval.CompanyId, &listInterval.IntervalStartTime, &listInterval.IntervalEndTime),
"INSERT INTO list_intervals (list_interval_start_time, list_interval_end_time, company_id) VALUES (?, ?, ?) RETURNING id, company_id, list_interval_start_time, list_interval_end_time",
listInterval.ListIntervalId, listInterval.CompanyId, listInterval.IntervalStartTime, listInterval.IntervalEndTime); err != nil {
listInterval.IntervalStartTime, listInterval.IntervalEndTime, listInterval.CompanyId); err != nil {
return listInterval, err
}
} else {
... ...
... ... @@ -101,3 +101,8 @@ func (controller *EmployeeController) ListEmployee() {
controller.Data["json"] = response
controller.ServeJSON()
}
// TODO 导出员工素币情况列表,选择导出(ids)
func (controller *EmployeeController) ExportSuMoney() {
}
\ No newline at end of file
... ...
... ... @@ -68,7 +68,7 @@ func (controller *ListIntervalController) GetListInterval() {
func (controller *ListIntervalController) ListListInterval() {
listIntervalService := service.NewListIntervalService(nil)
listListIntervalQuery := &query.ListListIntervalQuery{}
companyId, _ := controller.GetInt64(":companyID")
companyId, _ := controller.GetInt("companyId")
listListIntervalQuery.CompanyId = companyId
offset, _ := controller.GetInt("offset")
listListIntervalQuery.Offset = offset
... ...
... ... @@ -101,4 +101,34 @@ func (controller *StatisticsController) SystemCashStatistics() {
}
controller.Data["json"] = response
controller.ServeJSON()
}
func (controller *StatisticsController) EmployeesSuMoneyStatistics() {
statisticsService := service.NewStatisticsService(nil)
employeesSuMoneyStatisticsCommand := &command.EmployeesSuMoneyStatisticsCommand{}
json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), employeesSuMoneyStatisticsCommand)
data, err := statisticsService.EmployeesSuMoneyStatistics(employeesSuMoneyStatisticsCommand)
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 *StatisticsController) EmployeesContributionsStatistics() {
statisticsService := service.NewStatisticsService(nil)
employeesContributionsStatisticsCommand := &command.EmployeesContributionsStatisticsCommand{}
json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), employeesContributionsStatisticsCommand)
data, err := statisticsService.EmployeesContributionsStatistics(employeesContributionsStatisticsCommand)
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()
}
\ No newline at end of file
... ...
... ... @@ -362,4 +362,14 @@ func (controller *SuMoneyController) ImportExchangeList () {
response = utils.ResponseData(controller.Ctx, ret)
controller.Data["json"] = response
controller.ServeJSON()
}
// TODO 导出素币兑换清单,选择导出(ids)
func (controller *SuMoneyController) ExportExchangeList() {
}
// TODO 导出素币流水记录,选择导出(ids)
func (controller *SuMoneyController) ExportSuMoneyTransactionRecord() {
}
\ No newline at end of file
... ...
... ... @@ -11,4 +11,5 @@ func init() {
beego.Router("/employees/:uid", &controllers.EmployeeController{}, "Get:GetEmployee")
beego.Router("/employees/:uid", &controllers.EmployeeController{}, "Delete:RemoveEmployee")
beego.Router("/employees/", &controllers.EmployeeController{}, "Get:ListEmployee")
beego.Router("/employees/export", &controllers.EmployeeController{}, "Post:ExportSuMoney") // 导出员工素币情况列表
}
... ...
... ... @@ -12,4 +12,6 @@ func init() {
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") // 员工财富值统计
beego.Router("/statistics/employees-contributions", &controllers.StatisticsController{}, "Post:EmployeesContributionsStatistics") // 员工贡献值统计
}
... ...
... ... @@ -12,6 +12,7 @@ func init() {
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-records/export", &controllers.SuMoneyController{}, "Post:ExportSuMoneyTransactionRecord") // 导出素币事务记录
/**********************************************现金池*******************************************/
beego.Router("/cash-pool/input", &controllers.SuMoneyController{}, "Post:CashInput") // 现金池投入
... ... @@ -31,4 +32,5 @@ func init() {
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") // 导入素币兑换清单
beego.Router("/cash-pool/activity/exchange-list/export", &controllers.SuMoneyController{}, "Post:ExportExchangeList") // 导出素币兑换清单
}
... ...