作者 陈志颖

feat:完成员工贡献值、财富值统计

... ... @@ -3,10 +3,13 @@ package command
import (
"fmt"
"github.com/astaxie/beego/validation"
"time"
)
type EmployeesContributionsStatisticsCommand struct {
CompanyId int `json:"companyId" valid:"Required"` // 公司id
StartTime time.Time `json:"startTime"` // 年榜开始时间
EndTime time.Time `json:"EndTime"` // 年榜结束时间
}
func (employeesContributionsStatisticsCommand *EmployeesContributionsStatisticsCommand) ValidateCommand() error {
... ...
... ... @@ -2,12 +2,15 @@ package command
import (
"fmt"
"time"
"github.com/astaxie/beego/validation"
)
type EmployeesSuMoneyStatisticsCommand struct {
CompanyId int `json:"companyId" valid:"Required"` // 公司id
StartTime time.Time `json:"startTime"` // 年榜开始时间
EndTime time.Time `json:"EndTime"` // 年榜结束时间
}
func (employeesSuMoneyStatisticsCommand *EmployeesSuMoneyStatisticsCommand) ValidateCommand() error {
... ...
... ... @@ -196,6 +196,7 @@ func (statisticsService *StatisticsService) PersonSuMoneyStatistics(personSuMone
}
}
// 获取系统素币统计
func (statisticsService *StatisticsService) SystemSuMoneyStatistics(systemSuMoneyStatisticsCommand *command.SystemSuMoneyStatisticsCommand) (interface{}, error) {
if err := systemSuMoneyStatisticsCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
... ... @@ -230,6 +231,7 @@ func (statisticsService *StatisticsService) SystemSuMoneyStatistics(systemSuMone
}
}
// 获取系统现金统计
func (statisticsService *StatisticsService) SystemCashStatistics(systemCashStatisticsCommand *command.SystemCashStatisticsCommand) (interface{}, error) {
if err := systemCashStatisticsCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
... ... @@ -264,19 +266,72 @@ func (statisticsService *StatisticsService) SystemCashStatistics(systemCashStati
}
}
// TODO 员工素币值统计
// 获取员工财富值分组统计
func (statisticsService *StatisticsService) EmployeesSuMoneyStatistics(employeesSuMoneyStatisticsCommand *command.EmployeesSuMoneyStatisticsCommand) (interface{}, error) {
return nil ,nil
if err := employeesSuMoneyStatisticsCommand.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 employeesSuMoneyStatistics, err := employeeDao.CalculateEmployeesSuMoney(employeesSuMoneyStatisticsCommand.CompanyId, employeesSuMoneyStatisticsCommand.StartTime, employeesSuMoneyStatisticsCommand.EndTime); 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 employeesSuMoneyStatistics, nil
}
}
// TODO 员工贡献值统计
// 获取员工贡献值分组统计
func (statisticsService *StatisticsService) EmployeesContributionsStatistics(employeesContributionsStatisticsCommand *command.EmployeesContributionsStatisticsCommand) (interface{}, error) {
return nil, nil
if err := employeesContributionsStatisticsCommand.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 employeesContributionsStatistics, err := employeeDao.CalculateEmployeesContributions(employeesContributionsStatisticsCommand.CompanyId, employeesContributionsStatisticsCommand.StartTime, employeesContributionsStatisticsCommand.EndTime); 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 employeesContributionsStatistics, nil
}
}
func NewStatisticsService(options map[string]interface{}) *StatisticsService {
newStatisticsService := &StatisticsService{}
return newStatisticsService
... ...
... ... @@ -6,10 +6,12 @@ import (
)
type CreateExchangeCashPersonCommand struct {
Uid int64 `json:"uid"` // 统一用户id
PersonName string `json:"personName,omitempty"` // 兑换现金人员名称
PersonAccount string `json:"personAccount,omitempty"` // 手机账号
ExchangeCashActivityId int64 `json:"exchangeCashActivityId" valid:"Required"` // 参与的兑换活动id
ExchangedSuMoney float64 `json:"exchangedSuMoney"` // 已兑换素币值
Operator int64 `json:"operator"` // 操作人
PersonAccount string `json:"personAccount,omitempty"` // 手机账号
ExchangeCashActivityId int64 `json:"exchangeCashActivityId" valid:"Required"` // 参与的兑换活动id
ExchangedSuMoney float64 `json:"exchangedSuMoney"` // 已兑换素币值
}
func (createExchangeCashPersonCommand *CreateExchangeCashPersonCommand) ValidateCommand() error {
... ...
... ... @@ -34,7 +34,6 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co
defer func() {
transactionContext.RollbackTransaction()
}()
var employeeDao *dao.EmployeeDao
if value, err := factory.CreateEmployeeDao(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -43,7 +42,6 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co
} else {
employeeDao = value
}
// 统计系统素币
systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(createCashPoolCommand.CompanyId)
if err != nil {
... ... @@ -52,7 +50,8 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co
if systemSuMoneyStatistics == nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
}
systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64)
systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64)
// 统计系统现金
systemCashStatistics, err := employeeDao.CalculateSystemCash(createCashPoolCommand.CompanyId)
if err != nil {
... ... @@ -61,7 +60,8 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co
if systemCashStatistics == nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
}
systemExchangedCash := systemCashStatistics["systemExchangedCash"].(float64)
systemUnExchangeCash := systemCashStatistics["systemUnExchangeCash"].(float64)
var cashPoolRepository domain.CashPoolRepository
if value, err := factory.CreateCashPoolRepository(map[string] interface{} {
"transactionContext": transactionContext,
... ... @@ -70,15 +70,8 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co
} else {
cashPoolRepository = value
}
systemExchangedCash := systemCashStatistics["systemExchangedCash"].(float64)
systemUnExchangeCash := systemCashStatistics["systemUnExchangeCash"].(float64)
systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64)
systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64)
// TODO 计算系统平均兑换汇率
// 计算系统平均兑换汇率
rate, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", systemExchangedCash / systemExchangedSuMoney), 64) // 平均兑换汇率
// 新建现金池
newCashPool := &domain.CashPool{
CompanyId: createCashPoolCommand.CompanyId,
... ... @@ -122,7 +115,7 @@ func (cashPoolService *CashPoolService) GetCashPool(getCashPoolQuery *query.GetC
defer func() {
transactionContext.RollbackTransaction()
}()
// 统计系统素币
var employeeDao *dao.EmployeeDao
if value, err := factory.CreateEmployeeDao(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -131,8 +124,6 @@ func (cashPoolService *CashPoolService) GetCashPool(getCashPoolQuery *query.GetC
} else {
employeeDao = value
}
// 统计系统素币
systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(getCashPoolQuery.CompanyId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -140,10 +131,8 @@ func (cashPoolService *CashPoolService) GetCashPool(getCashPoolQuery *query.GetC
if systemSuMoneyStatistics == nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
}
systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64)
systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64)
var cashPoolRepository domain.CashPoolRepository
if value, err := factory.CreateCashPoolRepository(map[string] interface{} {
"transactionContext": transactionContext,
... ... @@ -158,7 +147,6 @@ func (cashPoolService *CashPoolService) GetCashPool(getCashPoolQuery *query.GetC
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
// 初始状态下,现金池返回默认值
if count == 0 {
return map[string] interface{} {
"cashPoolId": 0,
... ... @@ -192,12 +180,10 @@ func (cashPoolService *CashPoolService) CreateExchangeCashActivity(createExchang
defer func() {
transactionContext.RollbackTransaction()
}()
var timeNow = time.Now()
var deadline = createExchangeCashActivityCommand.Deadline
var t1 = time.Date(timeNow.Year(), timeNow.Month(), timeNow.Day(), 0, 0, 0, 0, time.Local)
var t2 = time.Date(deadline.Year(), deadline.Month(), deadline.Day(), 0, 0, 0, 0, time.Local)
newActivity := &domain.ExchangeCashActivity{
ExchangeActivityName: createExchangeCashActivityCommand.ExchangeActivityName,
CompanyId: createExchangeCashActivityCommand.CompanyId,
... ... @@ -208,7 +194,6 @@ func (cashPoolService *CashPoolService) CreateExchangeCashActivity(createExchang
Rate: createExchangeCashActivityCommand.ExchangeRate,
CreateTime: timeNow,
}
var exchangeCashActivityRepository domain.ExchangeActivityRepository
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -217,7 +202,6 @@ func (cashPoolService *CashPoolService) CreateExchangeCashActivity(createExchang
} else {
exchangeCashActivityRepository = value
}
if activity, err := exchangeCashActivityRepository.Save(newActivity); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ... @@ -233,7 +217,6 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCas
if err := listExchangeCashActivityQuery.ValidateQuery(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ... @@ -244,7 +227,6 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCas
defer func() {
transactionContext.RollbackTransaction()
}()
var exchangeActivityRepository domain.ExchangeActivityRepository
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -253,7 +235,6 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCas
} else {
exchangeActivityRepository = value
}
if count, activities, err := exchangeActivityRepository.Find(tool_funs.SimpleStructToMap(listExchangeCashActivityQuery)); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ... @@ -360,7 +341,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang
transactionContext.RollbackTransaction()
}()
// TODO 更新汇率处理:
// TODO 更新汇率判断
var exchangeCashActivityRepository domain.ExchangeActivityRepository
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
... ... @@ -380,25 +361,20 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang
if err := activity.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
if activityUpdated, err := exchangeCashActivityRepository.Save(activity); err != nil {
activityUpdated, err := exchangeCashActivityRepository.Save(activity)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
// TODO 更新现金池已兑换素币、已兑换现金值、未兑换素币、未兑换现金值、平均汇率
}
//var cashPoolRepository domain.CashPoolRepository
//if value, err := factory.CreateCashPoolRepository(map[string]interface{}{
// "transactionContext": transactionContext,
//}); err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//} else {
// cashPoolRepository = value
//}
// TODO 更新现金池
// 获取现金池
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return activityUpdated, nil
// 更新现金池
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return activityUpdated, nil
}
// 新增兑换素币清单
... ... @@ -416,58 +392,121 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC
defer func() {
transactionContext.RollbackTransaction()
}()
// TODO 获取兑换活动兑换汇率
//var exchangeCashActivityRepository domain.ExchangeActivityRepository
//activity, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"exchangeCashActivityId": createExchangeCashPersonCommand.ExchangeCashActivityId})
//if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//}
//if activity == nil {
// return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string("请设置汇率")))
//} else {
// fmt.Print(activity.Rate)
//}
// TODO 清单中现金总额超过现金池时创建失败,提示:“已超过投入现金池的未兑换现金”
// TODO 新增兑换清单时,根据uid判断成员是否存在,判断素币值是否超过本人持有的素币
// TODO 导入兑换清单时,时根据手机账号判断成员是否存在,判断素币是否超过本人持有的素币
// 获取兑换活动兑换汇率
var rate float64
var exchangeCashActivityRepository domain.ExchangeActivityRepository
activity, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"exchangeCashActivityId": createExchangeCashPersonCommand.ExchangeCashActivityId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if activity != nil {
rate = activity.Rate
}
// 根据uid/手机账号判断成员是否存在
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
}
employee, err := employeeRepository.FindOne(map[string]interface{}{
"uid": createExchangeCashPersonCommand.Uid,
"account": createExchangeCashPersonCommand.PersonAccount,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if employee == nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的员工")
}
if employee.SuMoney < createExchangeCashPersonCommand.ExchangedSuMoney {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "当前兑换素币超过本人持有的素币值")
}
// 新增兑换清单
var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository
if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
exchangeCashPersonListRepository = value
}
newPerson := &domain.ExchangeCashPersonList{
EmployeeInfo: &domain.EmployeeInfo{
EmployeeName: createExchangeCashPersonCommand.PersonName,
EmployeeAccount: createExchangeCashPersonCommand.PersonAccount,
Uid: employee.EmployeeInfo.Uid,
EmployeeName: employee.EmployeeInfo.EmployeeName,
EmployeeAccount: employee.EmployeeInfo.EmployeeAccount,
},
ExchangeCashActivityId: createExchangeCashPersonCommand.ExchangeCashActivityId,
ExchangedSuMoney: createExchangeCashPersonCommand.ExchangedSuMoney,
ExchangedCash: createExchangeCashPersonCommand.ExchangedSuMoney,
ExchangedCash: createExchangeCashPersonCommand.ExchangedSuMoney * rate,
}
var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository
if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{
person, err := exchangeCashPersonListRepository.Save(newPerson)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 生成素币流水,更新个人素币
var operationSuMoneyService service.OperationSuMoneyService
if value, err := factory.CreateOperationSuMoneyService(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
exchangeCashPersonListRepository = value
operationSuMoneyService = value
}
operationSuMoneyCommand := &command.OperationSuMoneyCommand{
Uid: person.EmployeeInfo.Uid,
Operator: createExchangeCashPersonCommand.Operator,
SuMoney: person.ExchangedSuMoney,
OperationType: 3,
OperationDescription: "素币兑换现金",
}
task, err := operationSuMoneyService.Operation(operationSuMoneyCommand.Uid, operationSuMoneyCommand.Operator, operationSuMoneyCommand.SuMoney, operationSuMoneyCommand.OperationType, operationSuMoneyCommand.OperationDescription)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if task == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(operationSuMoneyCommand.Uid)))
}
if person, err := exchangeCashPersonListRepository.Save(newPerson); err != nil {
// 更新兑换活动
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
// TODO 更新个人素币
exchangeCashActivityRepository = value
}
activityFound, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": createExchangeCashPersonCommand.ExchangeCashActivityId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if activityFound == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(createExchangeCashPersonCommand.ExchangeCashActivityId)))
}
createExchangeCashPersonCommand.ExchangedSuMoney += activityFound.ExchangedSuMoney
if err := activityFound.Update(tool_funs.SimpleStructToMap(createExchangeCashPersonCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
activityUpdated, err := exchangeCashActivityRepository.Save(activityFound)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if activityUpdated == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(createExchangeCashPersonCommand.ExchangeCashActivityId)))
}
// TODO 更新活动数据
// TODO 判断清单中现金总额超过现金池未兑换现金时创建失败,提示:“已超过投入现金池的未兑换现金”
// TODO 更新现金池数据
// TODO 更新现金池
// 获取现金池
// 更新现金池
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return person, nil
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return person, nil
}
// 返回兑换素币清单
... ... @@ -558,6 +597,27 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC
defer func() {
transactionContext.RollbackTransaction()
}()
var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository
if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
exchangeCashPersonListRepository = value
}
person, err := exchangeCashPersonListRepository.FindOne(map[string]interface{}{"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.ListId)))
}
// 移除兑换素币清单
personDeleted, err := exchangeCashPersonListRepository.Remove(person)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 生成素币流水,更新个人素币
var operationSuMoneyService service.OperationSuMoneyService
if value, err := factory.CreateOperationSuMoneyService(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -566,52 +626,62 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC
} else {
operationSuMoneyService = value
}
var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository
if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{
operationSuMoneyCommand := &command.OperationSuMoneyCommand{
Uid: person.EmployeeInfo.Uid,
Operator: removeExchangeCashPersonCommand.Operator,
SuMoney: person.ExchangedSuMoney,
OperationType: 1,
OperationDescription: "素币兑换现金调整",
}
task, err := operationSuMoneyService.Operation(operationSuMoneyCommand.Uid, operationSuMoneyCommand.Operator, operationSuMoneyCommand.SuMoney, operationSuMoneyCommand.OperationType, operationSuMoneyCommand.OperationDescription)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if task == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(operationSuMoneyCommand.Uid)))
}
// 更新兑换活动
var exchangeCashActivityRepository domain.ExchangeActivityRepository
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
exchangeCashPersonListRepository = value
exchangeCashActivityRepository = value
}
person, err := exchangeCashPersonListRepository.FindOne(map[string]interface{}{"id": removeExchangeCashPersonCommand.ListId})
activityFound, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": person.ExchangeCashActivityId})
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.ListId)))
if activityFound == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(person.ExchangeCashActivityId)))
}
updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
ExchangeCashActivityId: person.ExchangeCashActivityId,
ExchangedSuMoney: activityFound.ExchangedSuMoney + person.ExchangedSuMoney,
ExchangedCash: activityFound.ExchangedCash + person.ExchangedCash,
}
if personDeleted, err := exchangeCashPersonListRepository.Remove(person); err != nil {
if err := activityFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
activityUpdated, err := exchangeCashActivityRepository.Save(activityFound)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
// TODO 更新个人素币,个人素币值需要还原,理由:素币兑换现金调整
operationSuMoneyCommand := &command.OperationSuMoneyCommand{
Uid: person.EmployeeInfo.Uid,
Operator: removeExchangeCashPersonCommand.Operator,
SuMoney: 0,
OperationType: 5,
OperationDescription: "素币兑换现金调整",
}
task, err := operationSuMoneyService.Operation(operationSuMoneyCommand.Uid, operationSuMoneyCommand.Operator, operationSuMoneyCommand.SuMoney, operationSuMoneyCommand.OperationType, operationSuMoneyCommand.OperationDescription)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if task == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(operationSuMoneyCommand.Uid)))
}
}
if activityUpdated == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashActivityCommand.ExchangeCashActivityId)))
}
// TODO 更新兑换活动数据
// TODO 更新现金池
// TODO 更新现金池数据
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return personDeleted, nil
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return personDeleted, nil
}
// 更新兑换现金人员
// 更新兑换清单
func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeCashPersonCommand *command.UpdateExchangeCashPersonCommand) (interface{}, error) {
if err := updateExchangeCashPersonCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
... ... @@ -626,6 +696,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
defer func() {
transactionContext.RollbackTransaction()
}()
// 更新兑换清单
var operationSuMoneyService service.OperationSuMoneyService
if value, err := factory.CreateOperationSuMoneyService(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -634,7 +705,6 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
} else {
operationSuMoneyService = value
}
var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository
if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -653,34 +723,38 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
if err := person.Update(tool_funs.SimpleStructToMap(updateExchangeCashPersonCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
if personUpdated, err := exchangeCashPersonListRepository.Save(person); err != nil {
personUpdated, err := exchangeCashPersonListRepository.Save(person)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
operationSuMoneyCommand := &command.OperationSuMoneyCommand{
Uid: person.EmployeeInfo.Uid,
Operator: updateExchangeCashPersonCommand.Operator,
SuMoney: updateExchangeCashPersonCommand.ExchangedSuMoney,
OperationType: 5,
OperationDescription: "参与兑换素币活动",
}
// TODO 更新个人当前可用素币值,生成素币兑换流水记录(获取更新前的已兑换素币值,判断是扣除还是增加),记录描述:参与素币兑换现金活动(红色表示取活动名称)
task, err := operationSuMoneyService.Operation(operationSuMoneyCommand.Uid, operationSuMoneyCommand.Operator, operationSuMoneyCommand.SuMoney, operationSuMoneyCommand.OperationType, operationSuMoneyCommand.OperationDescription)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if task == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(operationSuMoneyCommand.Uid)))
}
}
// TODO 更新兑换活动数据
// TODO 更新兑换活动
// TODO 更新现金池
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return personUpdated, nil
// TODO 判断现金池未兑换现金
// TODO 更新现金池
// 生成素币兑换流水记录,更新员工素币
operationSuMoneyCommand := &command.OperationSuMoneyCommand{
Uid: person.EmployeeInfo.Uid,
Operator: updateExchangeCashPersonCommand.Operator,
SuMoney: updateExchangeCashPersonCommand.ExchangedSuMoney,
OperationType: 3,
OperationDescription: "参与兑换素币活动",
}
task, err := operationSuMoneyService.Operation(operationSuMoneyCommand.Uid, operationSuMoneyCommand.Operator, operationSuMoneyCommand.SuMoney, operationSuMoneyCommand.OperationType, operationSuMoneyCommand.OperationDescription)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if task == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(operationSuMoneyCommand.Uid)))
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return personUpdated, nil
}
func NewCashPoolService(options map[string]interface{}) *CashPoolService {
... ...
... ... @@ -41,8 +41,6 @@ func (suMoneyService *SuMoneyService) OperationSuMoney(operationSuMoneyCommand *
if task, err := operationSuMoneyService.Operation(operationSuMoneyCommand.Uid, operationSuMoneyCommand.Operator, operationSuMoneyCommand.SuMoney, operationSuMoneyCommand.OperationType, operationSuMoneyCommand.OperationDescription); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
// TODO 增加、扣除素币和个人贡献值关联,兑换物资不与贡献值关联
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
... ...
... ... @@ -29,6 +29,8 @@ type CreateTaskCommand struct {
TaskNature int `json:"taskNature,omitempty"`
// 奖励素币
SuMoney float64 `json:"suMoney,omitempty"`
// 奖励素币参考值范围(1000~3000)
ReferenceSuMoney string `json:"referenceSuMoney"`
// 验收标准
AcceptanceStandard string `json:"acceptanceStandard,omitempty"`
// 任务描述
... ...
... ... @@ -325,6 +325,7 @@ func (taskService *TaskService) AcceptanceTask(acceptanceTaskCommand *command.Ac
acceptanceTaskService = value
acceptanceTaskService.Subscribe(&subscriber.AbilityServiceSubscriber{})
}
if task, err := acceptanceTaskService.Acceptance(acceptanceTaskCommand.TaskId, acceptanceTaskCommand.Operator, acceptanceTaskCommand.Participators, acceptanceTaskCommand.TaskPercentage, acceptanceTaskCommand.ReferenceResourceScore, acceptanceTaskCommand.SolveReport, acceptanceTaskCommand.SolvePictureUrls, acceptanceTaskCommand.ActualCompletionTime); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ... @@ -774,12 +775,9 @@ func (taskService *TaskService) GetRejectTaskRecord(getRejectTaskRecordQuery *qu
// 创建新任务
func (taskService *TaskService) CreateTask(createTaskCommand *command.CreateTaskCommand) (interface{}, error) {
// 校验创建任务命令
if err := createTaskCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
// 新建事务
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ... @@ -790,8 +788,6 @@ func (taskService *TaskService) CreateTask(createTaskCommand *command.CreateTask
defer func() {
transactionContext.RollbackTransaction()
}()
// 新建任务数据访问对象
var taskDao *dao.TaskDao
if value, err := factory.CreateTaskDao(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -800,8 +796,6 @@ func (taskService *TaskService) CreateTask(createTaskCommand *command.CreateTask
} else {
taskDao = value
}
// 获取任务发布者信息
var employeeRepository domain.EmployeeRepository
if value, err := factory.CreateEmployeeRepository(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -810,7 +804,6 @@ func (taskService *TaskService) CreateTask(createTaskCommand *command.CreateTask
} else {
employeeRepository = value
}
sponsor, err := employeeRepository.FindOne(map[string]interface{}{
"uid": createTaskCommand.Sponsor,
})
... ... @@ -820,7 +813,6 @@ func (taskService *TaskService) CreateTask(createTaskCommand *command.CreateTask
if sponsor == nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的发布者")
}
// 获取任务指派人
var assignedPerson *domain.EmployeeInfo
if createTaskCommand.AssignedPerson != 0 {
... ... @@ -835,8 +827,6 @@ func (taskService *TaskService) CreateTask(createTaskCommand *command.CreateTask
}
assignedPerson = employee.EmployeeInfo
}
// 创建新任务
newTask := &domain.Task{
TaskStatus: domain.TASK_STATUS_UNRELEASED,
CompanyId: createTaskCommand.CompanyId,
... ... @@ -851,6 +841,7 @@ func (taskService *TaskService) CreateTask(createTaskCommand *command.CreateTask
CustomerValues: createTaskCommand.CustomerValues,
TaskNature: createTaskCommand.TaskNature,
SuMoney: createTaskCommand.SuMoney,
ReferenceSuMoney: createTaskCommand.ReferenceSuMoney, // 奖励素币范围
AcceptanceStandard: createTaskCommand.AcceptanceStandard,
TaskDescription: createTaskCommand.TaskDescription,
TaskPictureUrls: createTaskCommand.TaskPictureUrls,
... ... @@ -859,7 +850,6 @@ func (taskService *TaskService) CreateTask(createTaskCommand *command.CreateTask
PlannedCompletionTime: createTaskCommand.PlannedCompletionTime,
CreateTime: time.Now(),
}
var taskRepository domain.TaskRepository
if value, err := factory.CreateTaskRepository(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -922,21 +912,16 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter
if err := getTaskQuery.ValidateQuery(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var taskRepository domain.TaskRepository
if value, err := factory.CreateTaskRepository(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -945,18 +930,14 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter
} else {
taskRepository = value
}
task, err := taskRepository.FindOne(map[string]interface{}{"taskId": getTaskQuery.TaskId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if task == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getTaskQuery.TaskId)))
} else {
var projectBelongRepository domain.ProjectBelongRepository
if value, err := factory.CreateProjectBelongRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
... ... @@ -964,9 +945,7 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter
} else {
projectBelongRepository = value
}
projectBelongMap := make(map[int]*domain.ProjectBelong)
if _, projectBelongs, err := projectBelongRepository.Find(map[string]interface{}{
"companyId": task.CompanyId,
}); err != nil {
... ... @@ -976,9 +955,7 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter
projectBelongMap[projectBelong.ProjectBelongId] = projectBelong
}
}
var customerValueRepository domain.CustomerValueRepository
if value, err := factory.CreateCustomerValueRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
... ... @@ -986,9 +963,7 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter
} else {
customerValueRepository = value
}
customerValueMap := make(map[int]*domain.CustomerValue)
if _, customerValues, err := customerValueRepository.Find(map[string]interface{}{
"companyId": task.CompanyId,
}); err != nil {
... ... @@ -998,9 +973,7 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter
customerValueMap[customerValue.CustomerValueId] = customerValue
}
}
var taskNatureRepository domain.TaskNatureRepository
if value, err := factory.CreateTaskNatureRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
... ... @@ -1008,9 +981,7 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter
} else {
taskNatureRepository = value
}
taskNatureMap := make(map[int]*domain.TaskNature)
if _, taskNatures, err := taskNatureRepository.Find(map[string]interface{}{
"companyId": task.CompanyId,
}); err != nil {
... ... @@ -1020,16 +991,13 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter
taskNatureMap[taskNature.TaskNatureId] = taskNature
}
}
taskDto := &dto.TaskDto{}
if err := taskDto.LoadDto(task, projectBelongMap, customerValueMap, taskNatureMap); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return taskDto, nil
}
}
... ... @@ -1241,9 +1209,17 @@ func (taskService *TaskService) ListTask(listTaskQuery *query.ListTaskQuery) (in
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
// 拼接奖励素币范围值
var retTasks []*domain.Task
for _, task := range tasks {
if task.ReferenceSuMoney == "" {
task.ReferenceSuMoney = "0~" + fmt.Sprintf("%.0f", task.SuMoney)
}
retTasks = append(retTasks, task)
}
return map[string]interface{}{
"count": count,
"tasks": tasks,
"tasks": retTasks,
}, nil
}
}
... ...
... ... @@ -17,6 +17,7 @@ type CashPool struct {
type CashPoolRepository interface {
Save(cashPool *CashPool) (*CashPool, error)
FindOne(queryOptions map[string]interface{}) (*CashPool, error)
Find(queryOptions map[string]interface{}) (int64, []*CashPool, error)
}
... ...
... ... @@ -50,6 +50,8 @@ type Task struct {
TaskNature int `json:"taskNature"`
// 奖励素币
SuMoney float64 `json:"suMoney"`
// 奖励素币参考值
ReferenceSuMoney string `json:"referenceSuMoney"`
// 验收标准
AcceptanceStandard string `json:"acceptanceStandard"`
// 任务描述
... ...
... ... @@ -10,47 +10,71 @@ type CashPoolDao struct {
transactionContext *pgTransaction.TransactionContext
}
// 计算系统素币
func (dao *CashPoolDao) CalculateSystemSuMoney(companyId int64) ( float64, float64, error) {
var systemUnExchangeSuMoney float64
var systemExchangedSuMoney float64
// 计算系统已兑换素币、未兑换素币
//func (dao *CashPoolDao) CalculateSystemSuMoney(companyId int64) ( map[string]interface{}, error) {
// var systemUnExchangeSuMoney float64
// var systemExchangedSuMoney float64
// tx := dao.transactionContext.PgTx
// employeeModel := new(models.Employee)
// if err := tx.Model(employeeModel).
// ColumnExpr("sum(employee.su_money) AS system_unExchange_su_money").
// Where("employee.company_id = ?", companyId).
// Select(&systemUnExchangeSuMoney); err != nil {
// return nil, err
// }
// exchangeCashActivityModel := new(models.ExchangeCashActivity)
// if err := tx.Model(exchangeCashActivityModel).
// ColumnExpr("sum(exchange_cash_activity.exchanged_su_money) AS system_changed_su_money").
// Where("exchange_cash_activity.company_id = ?", companyId).
// Select(&systemExchangedSuMoney); err != nil {
// return nil, err
// }
// return map[string]interface{}{
// "systemUnExchangeSuMoney": systemUnExchangeSuMoney,
// "systemExchangedSuMoney": systemExchangedSuMoney,
// }, nil
//}
tx := dao.transactionContext.PgTx
employeeModel := new(models.Employee)
if err := tx.Model(employeeModel).
ColumnExpr("sum(employee.su_money) AS system_unExchange_su_money").
Where("employee.company_id = ?", companyId).
Select(&systemUnExchangeSuMoney); err != nil {
return 0, 0, err
}
exchangeCashActivityModel := new(models.ExchangeCashActivity)
if err := tx.Model(exchangeCashActivityModel).
ColumnExpr("sum(exchange_cash_activity.exchanged_su_money) AS system_changed_su_money").
Where("exchange_cash_activity.company_id = ?", companyId).
Select(&systemExchangedSuMoney); err != nil {
return 0, 0, err
}
return systemUnExchangeSuMoney, systemExchangedSuMoney, nil
}
// 计算系统已兑换现金
func (dao *CashPoolDao) CalculateSystemCash(companyId int64) (float64, error) {
var systemExchangedCash float64 // 系统已兑换现金
// 计算系统已兑换现金、未兑换现金
//func (dao *CashPoolDao) CalculateSystemCash(companyId int64) (map[string]interface{}, error) {
// var systemExchangedCash float64 // 系统已兑换现金
// var systemUnExchangeCash float64 // 系统未兑换现金
// tx := dao.transactionContext.PgTx
// exchangeCashActivityModel := new(models.ExchangeCashActivity)
// if err := tx.Model(exchangeCashActivityModel).
// ColumnExpr("sum(exchange_cash_activity.exchanged_cash) AS system_exchanged_cash").
// Where("exchange_cash_activity.company_id = ?", companyId).
// Select(&systemExchangedCash) ; err != nil {
// return nil, err
// }
// return map[string]interface{}{
// "systemExchangedCash": systemExchangedCash,
// "systemUnExchangeCash": systemUnExchangeCash,
// }, nil
//}
// 兑换兑换活动已兑换素币、已兑换现金
func (dao *CashPoolDao) CalculateActivityExchangedSuMoney(activityId int64) (map[string]interface{}, error) {
var activityExchangedSuMoney float64
var activityExchangedCash float64
tx := dao.transactionContext.PgTx
exchangeCashActivityModel := new(models.ExchangeCashActivity)
if err := tx.Model(exchangeCashActivityModel).
ColumnExpr("sum(exchange_cash_activity.exchanged_cash) AS system_exchanged_cash").
Where("exchange_cash_activity.company_id = ?", companyId).
Select(&systemExchangedCash) ; err != nil {
return 0, err
exchangeCashPersonListModels := new(models.ExchangeCashPersonList)
if err := tx.Model(exchangeCashPersonListModels).
ColumnExpr("sum(exchange_cash_person_lists.exchanged_su_money) AS activity_exchanged_su_money").
Where("exchange_cash_person_lists.activity_id = ?", activityId).
Select(&activityExchangedSuMoney); err !=nil {
return nil, err
}
return systemExchangedCash, nil
if err := tx.Model(exchangeCashPersonListModels).
ColumnExpr("sum(exchange_cash_person_lists.exchanged_cash) AS activity_exchanged_cash").
Where("exchange_cash_person_lists.activity_id = ?", activityId).
Select(&activityExchangedCash); err !=nil {
return nil, err
}
return map[string]interface{}{
"activityExchangedSuMoney": activityExchangedSuMoney,
"activityExchangedCash": activityExchangedCash,
}, nil
}
func NewCashPoolDao(transactionContext *pgTransaction.TransactionContext) (*CashPoolDao, error) {
... ...
... ... @@ -114,22 +114,26 @@ 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
tx := dao.transactionContext.PgTx
suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
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").
// 系统未兑换素币
employeeModel := new(models.Employee)
if err := tx.Model(employeeModel).
ColumnExpr("sum(employee.su_money) AS system_unExchange_su_money").
Where("employee.company_id = ?", companyId).
Where(`su_money_transaction_record.record_type = ?`, 5).
Where("employee.status = ?", 1).
Select(&systemUnExchangeSuMoney); err != nil {
return nil, err
}
// 系统已兑换现金素币
suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
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("e.company_id = ?", companyId).
Where("e.status = ?", 1).
Where(`su_money_transaction_record.record_type = ?`, 5).
Select(&systemExchangedSuMoney); err != nil {
return nil, err
... ... @@ -140,38 +144,40 @@ func (dao *EmployeeDao) CalculateSystemSuMoney(companyId int64) (map[string] int
},nil
}
// 计算系统现金
// 计算系统已兑换现金、未兑换现金
func (dao *EmployeeDao) CalculateSystemCash(companyId int64) (map[string] interface{}, error) {
tx := dao.transactionContext.PgTx
var (
systemUnExchangeCash float64
systemExchangedCash 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_records.employee->>'uid')::bigint").
ColumnExpr("sum(su_money_transaction_record.cash) AS system_exchanged_cash").
Where("employee.company_id = ?", companyId).
Where("e.company_id = ?", companyId).
//Where(`e.status = ?`, 1).
Where(`su_money_transaction_record.record_type = ?`, 5).
Select(&systemExchangedCash) ; err != nil {
return nil, err
}
// 系统未兑换现金
cashPool := new(models.CashPool)
if err := tx.Model(cashPool).
Column("un_exchange_cash").
Where("cash_pool.company_id = ?", companyId).
Order("id DSC").
Where("cash_pools.company_id = ?", companyId).
Order("id DESC").
Limit(1).
Select(&systemUnExchangeCash) ; err != nil {
return nil, err
}
return map[string] interface{} {
"systemUnExchangeCash": systemUnExchangeCash,
"systemExchangedCash": systemExchangedCash,
}, 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: 兑换现金)
... ... @@ -201,47 +207,89 @@ func (dao *EmployeeDao) CalculateSuMoneyTransactionRecord(uid int64, transaction
}, nil
}
func (dao *EmployeeDao) CalculateEmployeesSuMoney(companyId int) (map[string]interface{}, error) {
// 员工财富值统计
func (dao *EmployeeDao) CalculateEmployeesSuMoney(companyId int, startTime time.Time, endTime time.Time) (map[string]interface{}, error) {
tx := dao.transactionContext.PgTx
var res []struct {
var ret []struct {
Uid int
EmployeeName string
EmployeesSuMoney float64
Employee domain.Employee
//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").
Column("su_money_transaction_records.employee, (su_money_transaction_records.employee->>'employeeName')::text,").
ColumnExpr("su_money_transaction_records.employee->>'uid' AS uid, su_money_transaction_records.employee->>'employeeName' AS employeeName, sum(su_money_transaction_records.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").
Where(`su_money_transaction_records.record_type IN (?)`, pg.In([]int{2, 3})). // 增加,任务奖励的
Where(`su_money_transaction_records.create_time > ?`, startTime).
Where(`su_money_transaction_records.create_time < ?`, endTime).
Group("su_money_transaction_records.employee").
Order("employee_su_money DESC").
Select(&res); err != nil {
Select(&ret); err != nil {
return nil, err
}
return map[string]interface{}{
"employeesSuMoney": res,
"employeesSuMoney": ret,
}, nil
}
func (dao *EmployeeDao) CalculateEmployeesContributions(companyId int) (map[string]interface{}, error) {
// 员工贡献值统计
func (dao *EmployeeDao) CalculateEmployeesContributions(companyId int, startTime time.Time, endTime time.Time) (map[string]interface{}, error) {
tx := dao.transactionContext.PgTx
var ret []struct {
var ret []struct { // 员工贡献值
Uid int
EmployeeName string
EmployeesContributions float64
//Employee domain.Employee
}
var retDecrease []struct { // 员工减少的贡献值
Uid int
EmployeeName string
EmployeesContributions float64
Employee domain.Employee
//Employee domain.Employee
}
//var employeesContributionsIncrease []struct{} // 员工增加的贡献值列表
//var employeesContributionsDecrease []struct{} //
//var employeesContributions []struct{}
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").
// 增加的贡献值
if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_records.employee->>'uid')::bigint").
Column("su_money_transaction_records.employee").
ColumnExpr("su_money_transaction_records.employee->>'uid' AS uid, su_money_transaction_records.employee->>'employeeName' AS employeeName, sum(su_money_transaction_records.su_money) AS employees_contributions_increase").
Where(`e.company_id = ?`, companyId).
Where(`su_money_transaction_record.record_type = ?`, 2).
Where(`su_money_transaction_records.record_type IN (?)`, pg.In([]int{2, 3})).
Where(`e.status = ?`, 1).
Group("su_money_transaction_record.employee").
Where(`su_money_transaction_records.create_time > ?`, startTime).
Where(`su_money_transaction_records.create_time < ?`, endTime).
Group("su_money_transaction_records.employee").
Order("employees_contributions DESC").
Select(&ret); err != nil {
return nil, err
}
// 减少的贡献值
if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_records.employee->>'uid')::bigint").
Column("su_money_transaction_records.employee").
ColumnExpr("sum(su_money_transaction_records.su_money) AS employees_contributions_decrease").
Where(`e.company_id = ?`, companyId).
Where(`su_money_transaction_records.record_type = ?`, 4).
Where(`e.status = ?`, 1).
Where(`su_money_transaction_records.create_time > ?`, startTime).
Where(`su_money_transaction_records.create_time < ?`, endTime).
Group("su_money_transaction_records.employee").
Order("employees_contributions DESC").
Select(&retDecrease); err != nil {
return nil, err
}
// merge两个贡献值
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,
}, nil
... ...
... ... @@ -57,14 +57,18 @@ func (service *OperationSuMoneyService) Operation(uid int64, operatorUid int64,
}
var recordType int
var transferSuMoney float64
if operationType == 1 {
if operationType == 1 { // 增加
recordType = domain.SU_MONEY_TRANSACTION_RECORD_TYPE_INCREASE
transferSuMoney = suMoney
}
if operationType == 2 {
if operationType == 2 { // 扣除
recordType = domain.SU_MONEY_TRANSACTION_RECORD_TYPE_DEDUCT
transferSuMoney = 0 - suMoney
}
if operationType == 3 { // 兑换现金
recordType = domain.SU_MONEY_TRANSACTION_RECORD_TYPE_EXCHANGE_CASH
transferSuMoney = 0 - suMoney
}
suMoneyTransactionRecord := &domain.SuMoneyTransactionRecord{
RecordType: recordType,
Employee: employee.EmployeeInfo,
... ...
... ... @@ -29,6 +29,8 @@ type Task struct {
TaskNature int
// 奖励素币
SuMoney float64
// 奖励素币参考值范围值
ReferenceSuMoney string
// 验收标准
AcceptanceStandard string
// 任务描述
... ...
... ... @@ -71,6 +71,27 @@ func (repository *CashPoolRepository) Find(queryOptions map[string]interface{})
}
}
func (repository *CashPoolRepository) FindOne(queryOptions map[string]interface{}) (*domain.CashPool, error) {
tx := repository.transactionContext.PgTx
cashPoolModel := new(models.CashPool)
query := tx.Model(cashPoolModel)
if cashPoolId, ok := queryOptions["cashPoolId"]; ok {
query = query.Where("cash_pool.id = ?", cashPoolId)
}
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.Id == 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,
... ...
... ... @@ -63,6 +63,9 @@ func (repository *EmployeeRepository) FindOne(queryOptions map[string]interface{
if uid, ok := queryOptions["uid"]; ok {
query = query.Where("employee.uid = ?", uid)
}
if account, ok := queryOptions["account"]; ok {
query = query.Where("employee.employee_account = ?", account)
}
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此员工")
... ...
... ... @@ -73,10 +73,8 @@ func (repository *SuMoneyTransactionRecordRepository) Find(queryOptions map[stri
if uid, ok := queryOptions["uid"]; ok && (uid != int64(0)) {
query = query.Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid)
}
// 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')::text LIKE ?`, fmt.Sprintf("%%%s%%", employeeMatchName.(string)))
}
if recordType, ok := queryOptions["recordType"]; ok && (recordType != 0) {
query = query.Where(`su_money_transaction_record.record_type = ?`, recordType)
... ...
... ... @@ -102,7 +102,7 @@ func (controller *EmployeeController) ListEmployee() {
controller.ServeJSON()
}
// TODO 导出员工素币情况列表,选择导出(ids)
// TODO 导出员工素币情况列表,选择导出(ids),增加导出失败信息
func (controller *EmployeeController) ExportSuMoney() {
}
\ No newline at end of file
... ...
... ... @@ -339,7 +339,7 @@ func (controller *SuMoneyController) ImportExchangeList () {
dataList := make([]interface{}, 0)
rows, _ := xlsx.GetRows("Sheet1")
for i, row := range rows {
if i > 0 {
if i > 3 {
for _, _ = range row {
createExchangeCashPersonCommand.ExchangeCashActivityId = activityId
createExchangeCashPersonCommand.PersonName = row[0]
... ... @@ -364,12 +364,12 @@ func (controller *SuMoneyController) ImportExchangeList () {
controller.ServeJSON()
}
// TODO 导出素币兑换清单,选择导出(ids)
// TODO 导出素币兑换清单,选择导出(ids),增加导出失败信息
func (controller *SuMoneyController) ExportExchangeList() {
}
// TODO 导出素币流水记录,选择导出(ids)
// TODO 导出素币流水记录,选择导出(ids),增加导出失败信息
func (controller *SuMoneyController) ExportSuMoneyTransactionRecord() {
}
\ No newline at end of file
... ...