作者 陈志颖

合并分支 'dev' 到 'master'

Dev

优化贡献值展示

查看合并请求 !5
... ... @@ -10,7 +10,7 @@ COPY ./go.mod go.mod
COPY ./main.go main.go
RUN ["ln","-sf","/usr/share/zoneinfo/Asia/Shanghai","/etc/localtime"]
ENV GO111MODULE on
ENV GOPROXY https://goproxy.io
#RUN ["go","mod","tidy"]
ENV GOPROXY https://goproxy.cn
RUN ["go","mod","tidy"]
RUN ["go","build"]
ENTRYPOINT ["./mmm-worth"]
\ No newline at end of file
... ...
... ... @@ -29,7 +29,6 @@ require (
github.com/yudai/gojsondiff v1.0.0 // indirect
github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 // indirect
github.com/yudai/pp v2.0.1+incompatible // indirect
golang.org/x/tools v0.0.0-20200117065230-39095c1d176c
)
replace gitlab.fjmaimaimai.com/linmadan/mmm-worth => ../mmm-worth
... ...
... ... @@ -79,8 +79,6 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/linmadan/egglib-go v0.0.0-20191217144343-ca4539f95bf9 h1:zJZsqJ1wFMYb2yrja5S3OZ+oASx4irRksZ8+emFs56M=
github.com/linmadan/egglib-go v0.0.0-20191217144343-ca4539f95bf9/go.mod h1:S1zYn9bb6h+Qzu1aOO8raFhHniewOBaif3YvA9qA6lk=
github.com/linmadan/egglib-go v0.0.0-20201125083542-25358a549edb h1:Ocxw5BWyRrRkTHSsTmQx0UnGsAYZDOwa3K9oGlXF8Jo=
github.com/linmadan/egglib-go v0.0.0-20201125083542-25358a549edb/go.mod h1:S1zYn9bb6h+Qzu1aOO8raFhHniewOBaif3YvA9qA6lk=
github.com/mattn/go-colorable v0.1.6 h1:6Su7aK7lXmJ/U79bYtBjLNaha4Fs1Rg9plHpcH+vvnE=
... ...
... ... @@ -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
}
}
... ...
... ... @@ -3,12 +3,14 @@ package service
import (
"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/factory"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/suMoney/command"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/suMoney/query"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain/service"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/dao"
"time"
)
// 素币服务
... ... @@ -291,7 +293,7 @@ func (suMoneyService *SuMoneyService) ContributionsTransactionRecordStatistics(c
}
// 根据uid获取员工素币(导出素币流水)
func (suMoneyService *SuMoneyService) ListSuMoneyById(exportSuMoneyCommand *command.ExportSuMoneyCommand) ([]*domain.Employee, error) {
func (suMoneyService *SuMoneyService) ListSuMoneyById(exportSuMoneyCommand *command.ExportSuMoneyCommand) ([]interface{}, error) {
if err := exportSuMoneyCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
... ... @@ -321,13 +323,63 @@ func (suMoneyService *SuMoneyService) ListSuMoneyById(exportSuMoneyCommand *comm
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 _, employees, err := employeeRepository.FindByIds(tool_funs.SimpleStructToMap(exportSuMoneyCommand)); 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())
}
return employees, nil
return employeesSpecific, nil
}
}
... ...
... ... @@ -2,7 +2,7 @@ package constant
import "os"
var POSTGRESQL_DB_NAME = "mmm-worth-test"
var POSTGRESQL_DB_NAME = "mmm-worth"
var POSTGRESQL_USER = "postgres"
var POSTGRESQL_PASSWORD = "1993618jack"
var POSTGRESQL_HOST = "127.0.0.1"
... ...
... ... @@ -276,7 +276,7 @@ func (dao *EmployeeDao) CalculateContributionsTransactionRecord(uid int64, trans
suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
if transactionStartTime.IsZero() && transactionEndTime.IsZero() {
transactionStartTime = time.Date(1970, 1, 1, 0, 0, 0, 0, time.Local)
transactionStartTime = time.Time{}
transactionEndTime = time.Now()
}
... ... @@ -303,6 +303,7 @@ func (dao *EmployeeDao) CalculateContributionsTransactionRecord(uid int64, trans
return map[string]interface{}{
"incomeContributions": incomeContributions, // 个人贡献值收入
"expendContributions": expendContributions, // 个人贡献支出
"contributions": incomeContributions - expendContributions, // 个人贡献值
}, nil
}
... ...
... ... @@ -233,6 +233,7 @@ func (repository *EmployeeRepository) transformPgModelToDomainModel(employeeMode
SuMoney: employeeModel.SuMoney,
Status: employeeModel.Status,
Permissions: employeeModel.Permissions,
CreateTime: employeeModel.CreateTime,
}, nil
}
... ...
... ... @@ -102,7 +102,7 @@ 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)
}
if employeeMatchName, ok := queryOptions["employeeMatchName"]; ok && (employeeMatchName != "") {
if employeeMatchName, ok := queryOptions["employeeMatchName"]; ok && (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) {
... ...
... ... @@ -2,8 +2,6 @@ package controllers
import (
"encoding/json"
"fmt"
"github.com/astaxie/beego"
"github.com/linmadan/egglib-go/web/beego/utils"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/employee/command"
... ... @@ -92,7 +90,6 @@ func (controller *EmployeeController) ListEmployee() {
listEmployeeQuery.Offset = offset
limit, _ := controller.GetInt("limit")
listEmployeeQuery.Limit = limit
fmt.Print(listEmployeeQuery)
data, err := employeeService.ListEmployee(listEmployeeQuery)
var response utils.JsonResponse
if err != nil {
... ...
... ... @@ -682,20 +682,21 @@ func (controller *SuMoneyController) ExportSuMoney() {
json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), exportSuMoneyCommand)
// 列标题
titles := []string{
"员工姓名","手机账号","当前素币",
"员工姓名","手机账号","贡献值","当前素币",
}
// 列单元
cells := []string{
"A","B","C",
"A","B","C","D",
}
var response utils.JsonResponse
var data []map[string]interface{}
records, err := suMoneyService.ListSuMoneyById(exportSuMoneyCommand)
for _, record := range records {
p := map[string]interface{} {
"name": record.EmployeeInfo.EmployeeName,
"account": record.EmployeeInfo.EmployeeAccount,
"current_su_money": record.SuMoney,
"name": record.(map[string]interface{})["employeeInfo"].(map[string]interface{})["employeeName"],
"account": record.(map[string]interface{})["employeeInfo"].(map[string]interface{})["employeeAccount"],
"current_contributions": record.(map[string]interface{})["contributions"],
"current_su_money": record.(map[string]interface{})["suMoney"],
}
data = append(data, p)
}
... ... @@ -730,8 +731,11 @@ func (controller *SuMoneyController) ExportSuMoney() {
break
case "C":
sheetPosition := cell + row
f.SetCellValue("Sheet1", sheetPosition, v["current_su_money"])
f.SetCellValue("Sheet1", sheetPosition, v["current_contributions"])
break
case "D":
sheetPosition := cell + row
f.SetCellValue("Sheet1", sheetPosition, v["current_su_money"])
}
}
}
... ...