...
|
...
|
@@ -4,10 +4,12 @@ import ( |
|
|
"fmt"
|
|
|
"github.com/linmadan/egglib-go/core/application"
|
|
|
"github.com/linmadan/egglib-go/utils/tool_funs"
|
|
|
"github.com/shopspring/decimal"
|
|
|
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/employee/command"
|
|
|
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/employee/query"
|
|
|
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/factory"
|
|
|
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
|
|
|
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/dao"
|
|
|
"time"
|
|
|
)
|
|
|
|
...
|
...
|
@@ -20,6 +22,7 @@ func (employeeService *EmployeeService) CreateEmployee(createEmployeeCommand *co |
|
|
if err := createEmployeeCommand.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())
|
...
|
...
|
@@ -30,6 +33,7 @@ func (employeeService *EmployeeService) CreateEmployee(createEmployeeCommand *co |
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
newEmployee := &domain.Employee{
|
|
|
EmployeeInfo: &domain.EmployeeInfo{
|
|
|
Uid: createEmployeeCommand.Uid,
|
...
|
...
|
@@ -40,6 +44,8 @@ func (employeeService *EmployeeService) CreateEmployee(createEmployeeCommand *co |
|
|
CreateTime: time.Now(),
|
|
|
}
|
|
|
var employeeRepository domain.EmployeeRepository
|
|
|
|
|
|
// 创建员工工厂初始化
|
|
|
if value, err := factory.CreateEmployeeRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
...
|
...
|
@@ -47,6 +53,7 @@ func (employeeService *EmployeeService) CreateEmployee(createEmployeeCommand *co |
|
|
} else {
|
|
|
employeeRepository = value
|
|
|
}
|
|
|
|
|
|
if employee, err := employeeRepository.Save(newEmployee); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
...
|
...
|
@@ -62,6 +69,7 @@ func (employeeService *EmployeeService) GetEmployee(getEmployeeQuery *query.GetE |
|
|
if err := getEmployeeQuery.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())
|
...
|
...
|
@@ -72,6 +80,8 @@ func (employeeService *EmployeeService) GetEmployee(getEmployeeQuery *query.GetE |
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
// 员工仓储初始化
|
|
|
var employeeRepository domain.EmployeeRepository
|
|
|
if value, err := factory.CreateEmployeeRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -80,6 +90,23 @@ func (employeeService *EmployeeService) GetEmployee(getEmployeeQuery *query.GetE |
|
|
} else {
|
|
|
employeeRepository = value
|
|
|
}
|
|
|
|
|
|
// 员工DAO初始化
|
|
|
var employeeDao *dao.EmployeeDao
|
|
|
if value, err := factory.CreateEmployeeDao(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
employeeDao = value
|
|
|
}
|
|
|
|
|
|
var employeeSpecific map[string]interface{}
|
|
|
|
|
|
// 默认查询时间
|
|
|
transactionStartTime := time.Time{}
|
|
|
transactionEndTime := time.Now()
|
|
|
|
|
|
employee, err := employeeRepository.FindOne(map[string]interface{}{"uid": getEmployeeQuery.Uid})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
...
|
...
|
@@ -87,10 +114,39 @@ func (employeeService *EmployeeService) GetEmployee(getEmployeeQuery *query.GetE |
|
|
if employee == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getEmployeeQuery.Uid)))
|
|
|
} else {
|
|
|
var contributions float64
|
|
|
calculateResult, err := employeeDao.CalculateContributionsTransactionRecord(employee.EmployeeInfo.Uid, transactionStartTime, transactionEndTime)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if calculateResult == nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
suMoney, _ := decimal.NewFromFloatWithExponent(employee.SuMoney, -2).Float64()
|
|
|
if calculateResult["contributions"] != nil {
|
|
|
contributions, _ = decimal.NewFromFloatWithExponent(calculateResult["contributions"].(float64), -2).Float64()
|
|
|
}
|
|
|
employeeSpecific = map[string]interface{} {
|
|
|
"employeeId": employee.EmployeeId,
|
|
|
"companyId": employee.CompanyId,
|
|
|
"employeeInfo": map[string]interface{}{
|
|
|
"uid": employee.EmployeeInfo.Uid,
|
|
|
"employeeName": employee.EmployeeInfo.EmployeeName,
|
|
|
"employeeAccount": employee.EmployeeInfo.EmployeeAccount,
|
|
|
"employeeAvatarUrl": employee.EmployeeInfo.EmployeeAvatarUrl,
|
|
|
"isPrincipal": employee.EmployeeInfo.IsPrincipal,
|
|
|
},
|
|
|
"suMoney": suMoney,
|
|
|
"contributions": contributions,
|
|
|
"status": employee.Status,
|
|
|
"permissions": employee.Permissions,
|
|
|
"createTime": employee.CreateTime.Local(),
|
|
|
}
|
|
|
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return employee, nil
|
|
|
return employeeSpecific, nil
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
@@ -99,6 +155,7 @@ func (employeeService *EmployeeService) UpdateEmployee(updateEmployeeCommand *co |
|
|
if err := updateEmployeeCommand.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())
|
...
|
...
|
@@ -109,6 +166,8 @@ func (employeeService *EmployeeService) UpdateEmployee(updateEmployeeCommand *co |
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
// 员工仓储初始化
|
|
|
var employeeRepository domain.EmployeeRepository
|
|
|
if value, err := factory.CreateEmployeeRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -117,6 +176,7 @@ func (employeeService *EmployeeService) UpdateEmployee(updateEmployeeCommand *co |
|
|
} else {
|
|
|
employeeRepository = value
|
|
|
}
|
|
|
|
|
|
employee, err := employeeRepository.FindOne(map[string]interface{}{"uid": updateEmployeeCommand.Uid})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
...
|
...
|
@@ -195,6 +255,7 @@ func (employeeService *EmployeeService) ListEmployee(listEmployeeQuery *query.Li |
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
// 员工仓储初始化
|
|
|
var employeeRepository domain.EmployeeRepository
|
|
|
if value, err := factory.CreateEmployeeRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -204,6 +265,22 @@ func (employeeService *EmployeeService) ListEmployee(listEmployeeQuery *query.Li |
|
|
employeeRepository = value
|
|
|
}
|
|
|
|
|
|
// 员工DAO初始化
|
|
|
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
|
|
|
}
|
|
|
|
|
|
// 默认查询时间
|
|
|
transactionStartTime := time.Time{}
|
|
|
transactionEndTime := time.Now()
|
|
|
|
|
|
var employeesSpecific []interface{}
|
|
|
|
|
|
if count, employees, err := employeeRepository.Find(map[string]interface{}{
|
|
|
"companyId": listEmployeeQuery.CompanyId,
|
|
|
"employeeNameMatch": listEmployeeQuery.EmployeeNameMatch,
|
...
|
...
|
@@ -212,12 +289,49 @@ func (employeeService *EmployeeService) ListEmployee(listEmployeeQuery *query.Li |
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
for _ , employee := range employees {
|
|
|
calculateResult, err := employeeDao.CalculateContributionsTransactionRecord(employee.EmployeeInfo.Uid, transactionStartTime, transactionEndTime)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if calculateResult == nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
suMoney, _ := decimal.NewFromFloatWithExponent(employee.SuMoney, -2).Float64()
|
|
|
var contributions float64
|
|
|
if calculateResult["contributions"] != nil {
|
|
|
contributions, _ = decimal.NewFromFloatWithExponent(calculateResult["contributions"].(float64), -2).Float64()
|
|
|
}
|
|
|
|
|
|
employeeSpecific := map[string]interface{}{
|
|
|
"employeeId": employee.EmployeeId,
|
|
|
"companyId": employee.CompanyId,
|
|
|
"employeeInfo": map[string]interface{}{
|
|
|
"uid": employee.EmployeeInfo.Uid,
|
|
|
"employeeName": employee.EmployeeInfo.EmployeeName,
|
|
|
"employeeAccount": employee.EmployeeInfo.EmployeeAccount,
|
|
|
"employeeAvatarUrl": employee.EmployeeInfo.EmployeeAvatarUrl,
|
|
|
"isPrincipal": employee.EmployeeInfo.IsPrincipal,
|
|
|
},
|
|
|
"suMoney": suMoney,
|
|
|
"contributions": contributions,
|
|
|
"status": employee.Status,
|
|
|
"permissions": employee.Permissions,
|
|
|
"createTime": employee.CreateTime.Local(),
|
|
|
}
|
|
|
employeesSpecific = append(employeesSpecific, employeeSpecific)
|
|
|
}
|
|
|
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
if len(employeesSpecific) == 0 {
|
|
|
employeesSpecific = []interface{}{}
|
|
|
}
|
|
|
return map[string]interface{}{
|
|
|
"count": count,
|
|
|
"employees": employees,
|
|
|
"employees": employeesSpecific,
|
|
|
}, nil
|
|
|
}
|
|
|
}
|
...
|
...
|
|