作者 linmadan

添加素币事务统计与详情接口

... ... @@ -60,6 +60,27 @@
]
}
},
"/config/employee-permissions": {
"get": {
"tags": [
"config"
],
"summary": "返回员工权限字典列表(1任务管理,2素币管理,3成员管理)",
"description": "返回员工权限字典列表(1任务管理,2素币管理,3成员管理)",
"operationId": "config#listEmployeePermission",
"responses": {
"200": {
"description": "OK response.",
"schema": {
"$ref": "#/definitions/ConfigListEmployeePermissionResponseBody"
}
}
},
"schemes": [
"http"
]
}
},
"/config/reference-resource-types": {
"get": {
"tags": [
... ... @@ -154,6 +175,20 @@
"operationId": "employee#listEmployee",
"parameters": [
{
"name": "companyId",
"in": "query",
"description": "公司ID",
"required": false,
"type": "integer"
},
{
"name": "employeeNameMatch",
"in": "query",
"description": "员工姓名匹配",
"required": false,
"type": "string"
},
{
"name": "offset",
"in": "query",
"description": "查询偏离量",
... ... @@ -520,6 +555,67 @@
]
}
},
"/su-money/su-money-transaction-record-statistics": {
"post": {
"tags": [
"suMoney"
],
"summary": "素币事务记录统计",
"description": "素币事务记录统计",
"operationId": "suMoney#suMoneyTransactionRecordStatistics",
"parameters": [
{
"name": "SuMoneyTransactionRecordStatisticsRequestBody",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/SuMoneySuMoneyTransactionRecordStatisticsRequestBody"
}
}
],
"responses": {
"200": {
"description": "OK response.",
"schema": {
"$ref": "#/definitions/SuMoneySuMoneyTransactionRecordStatisticsResponseBody"
}
}
},
"schemes": [
"http"
]
}
},
"/su-money/su-money-transaction-records/{suMoneyTransactionRecordId}": {
"get": {
"tags": [
"suMoney"
],
"summary": "返回素币事务记录",
"description": "返回素币事务记录",
"operationId": "suMoney#getSuMoneyTransactionRecord",
"parameters": [
{
"name": "suMoneyTransactionRecordId",
"in": "path",
"description": "素币事务记录ID",
"required": true,
"type": "integer"
}
],
"responses": {
"200": {
"description": "OK response.",
"schema": {
"$ref": "#/definitions/SuMoneyGetSuMoneyTransactionRecordResponseBody"
}
}
},
"schemes": [
"http"
]
}
},
"/tasks": {
"get": {
"tags": [
... ... @@ -570,8 +666,12 @@
"in": "query",
"description": "客户价值",
"required": false,
"type": "array",
"items": {
"type": "string"
},
"collectionFormat": "multi"
},
{
"name": "taskNature",
"in": "query",
... ... @@ -1114,6 +1214,18 @@
}
}
},
"ConfigListEmployeePermissionResponseBody": {
"title": "Mediatype identifier: ConfigListEmployeePermissionResponseBody",
"type": "object",
"properties": {
"employeePermissions": {
"type": "array",
"items": {
"$ref": "#/definitions/configResponseBody"
}
}
}
},
"ConfigListReferenceResourceTypeResponseBody": {
"title": "Mediatype identifier: ConfigListReferenceResourceTypeResponseBody",
"type": "object",
... ... @@ -1170,6 +1282,10 @@
"type": "string",
"description": "员工账号"
},
"employeeAvatarUrl": {
"type": "string",
"description": "员工头像URL"
},
"employeeName": {
"type": "string",
"description": "员工姓名"
... ... @@ -1235,9 +1351,21 @@
"type": "string",
"description": "员工账号"
},
"employeeAvatarUrl": {
"type": "string",
"description": "员工头像URL"
},
"employeeName": {
"type": "string",
"description": "员工姓名"
},
"permissions": {
"type": "array",
"items": {
"type": "integer",
"format": "int64"
},
"description": "员工权限集合"
}
}
},
... ... @@ -1271,7 +1399,10 @@
]
},
"customerValue": {
"type": "string",
"type": "array",
"items": {
"type": "string"
},
"description": "客户价值"
},
"limit": {
... ... @@ -1433,6 +1564,15 @@
}
}
},
"SuMoneyGetSuMoneyTransactionRecordResponseBody": {
"title": "Mediatype identifier: SuMoneyGetSuMoneyTransactionRecordResponseBody",
"type": "object",
"properties": {
"suMoneyTransactionRecord": {
"$ref": "#/definitions/suMoneyTransactionRecordResponseBody"
}
}
},
"SuMoneySearchSuMoneyTransactionRecordRequestBody": {
"title": "SuMoneySearchSuMoneyTransactionRecordRequestBody",
"type": "object",
... ... @@ -1495,6 +1635,49 @@
}
}
},
"SuMoneySuMoneyTransactionRecordStatisticsRequestBody": {
"title": "SuMoneySuMoneyTransactionRecordStatisticsRequestBody",
"type": "object",
"properties": {
"transactionEndTime": {
"type": "string",
"description": "事务时间区间-截止时间",
"format": "datetime"
},
"transactionStartTime": {
"type": "string",
"description": "事务时间区间-开始时间",
"format": "datetime"
},
"uid": {
"type": "integer",
"description": "统一用户UID",
"required": [
"uid"
]
}
}
},
"SuMoneySuMoneyTransactionRecordStatisticsResponseBody": {
"title": "Mediatype identifier: SuMoneySuMoneyTransactionRecordStatisticsResponseBody",
"type": "object",
"properties": {
"expendSuMoney": {
"type": "number",
"description": "支出素币",
"required": [
"expendSuMoney"
]
},
"incomeSuMoney": {
"type": "number",
"description": "收入素币",
"required": [
"incomeSuMoney"
]
}
}
},
"TaskAcceptanceTaskRequestBody": {
"title": "TaskAcceptanceTaskRequestBody",
"type": "object",
... ... @@ -1514,6 +1697,13 @@
},
"description": "任务参与者UID列表"
},
"referenceResourceScore": {
"type": "array",
"items": {
"$ref": "#/definitions/referenceResourceItemRequestBody"
},
"description": "引用资源解决分"
},
"solvePictureUrls": {
"type": "array",
"items": {
... ... @@ -1640,6 +1830,13 @@
"description": "竞标开始时间",
"format": "datetime"
},
"companyId": {
"type": "integer",
"description": "公司ID",
"required": [
"companyId"
]
},
"customerValue": {
"type": "array",
"items": {
... ... @@ -1835,7 +2032,10 @@
]
},
"customerValue": {
"type": "string",
"type": "array",
"items": {
"type": "string"
},
"description": "客户价值"
},
"limit": {
... ... @@ -1912,13 +2112,20 @@
]
},
"customerValue": {
"type": "string",
"type": "array",
"items": {
"type": "string"
},
"description": "客户价值"
},
"isFilterCloseStatus": {
"type": "boolean",
"description": "是否过滤关闭状态任务"
},
"isFilterUnReleasedStatus": {
"type": "boolean",
"description": "是否过滤待发布状态任务"
},
"isRewardTake": {
"type": "boolean",
"description": "是否悬赏任务"
... ... @@ -2136,6 +2343,10 @@
"type": "string",
"description": "员工账号"
},
"employeeAvatarUrl": {
"type": "string",
"description": "员工头像URL"
},
"employeeName": {
"type": "string",
"description": "员工姓名",
... ... @@ -2161,6 +2372,10 @@
"type": "string",
"description": "员工账号"
},
"employeeAvatarUrl": {
"type": "string",
"description": "员工头像URL"
},
"employeeName": {
"type": "string",
"description": "员工姓名",
... ... @@ -2199,6 +2414,17 @@
"employeeInfo": {
"$ref": "#/definitions/employeeInfoResponseBody"
},
"permissions": {
"type": "array",
"items": {
"type": "integer",
"format": "int64"
},
"description": "员工权限集合",
"required": [
"permissions"
]
},
"status": {
"type": "integer",
"description": "员工状态(启用或者禁用)",
... ... @@ -2350,6 +2576,25 @@
"title": "referenceResourceItemRequestBody",
"type": "object",
"properties": {
"content": {
"type": "string",
"description": "内容",
"required": [
"content"
]
},
"issueScore": {
"type": "number",
"description": "问题总分",
"format": "double"
},
"referenceResourceId": {
"type": "integer",
"description": "引用资源ID",
"required": [
"referenceResourceId"
]
},
"serialNumber": {
"type": "integer",
"description": "编号",
... ... @@ -2357,6 +2602,13 @@
"serialNumber"
]
},
"solveScore": {
"type": "array",
"items": {
"$ref": "#/definitions/solveScoreItemRequestBody"
},
"description": "解决评分明细"
},
"title": {
"type": "string",
"description": "标题",
... ... @@ -2371,6 +2623,25 @@
"title": "referenceResourceItemResponseBody",
"type": "object",
"properties": {
"content": {
"type": "string",
"description": "内容",
"required": [
"content"
]
},
"issueScore": {
"type": "number",
"description": "问题总分",
"format": "double"
},
"referenceResourceId": {
"type": "integer",
"description": "引用资源ID",
"required": [
"referenceResourceId"
]
},
"serialNumber": {
"type": "integer",
"description": "编号",
... ... @@ -2378,6 +2649,13 @@
"serialNumber"
]
},
"solveScore": {
"type": "array",
"items": {
"$ref": "#/definitions/solveScoreItemResponseBody"
},
"description": "解决评分明细"
},
"title": {
"type": "string",
"description": "标题",
... ... @@ -2453,6 +2731,68 @@
},
"description": "抢单任务信息"
},
"solveScoreItemRequestBody": {
"title": "solveScoreItemRequestBody",
"type": "object",
"properties": {
"contributor": {
"$ref": "#/definitions/employeeInfoRequestBody"
},
"isReceiver": {
"type": "boolean",
"description": "是否领取人",
"required": [
"isReceiver"
]
},
"percentage": {
"type": "integer",
"description": "解决占比",
"required": [
"percentage"
]
},
"score": {
"type": "number",
"description": "解决评分",
"required": [
"score"
]
}
},
"description": "解决评分项"
},
"solveScoreItemResponseBody": {
"title": "solveScoreItemResponseBody",
"type": "object",
"properties": {
"contributor": {
"$ref": "#/definitions/employeeInfoResponseBody"
},
"isReceiver": {
"type": "boolean",
"description": "是否领取人",
"required": [
"isReceiver"
]
},
"percentage": {
"type": "integer",
"description": "解决占比",
"required": [
"percentage"
]
},
"score": {
"type": "number",
"description": "解决评分",
"required": [
"score"
]
}
},
"description": "解决评分项"
},
"suMoneyTransactionRecordResponseBody": {
"title": "suMoneyTransactionRecordResponseBody",
"type": "object",
... ... @@ -2539,10 +2879,12 @@
"contributor": {
"$ref": "#/definitions/employeeInfoRequestBody"
},
"issueScore": {
"type": "number",
"description": "引用问题的得分",
"format": "double"
"isReceiver": {
"type": "boolean",
"description": "是否领取人",
"required": [
"isReceiver"
]
},
"percentage": {
"type": "integer",
... ... @@ -2568,10 +2910,12 @@
"contributor": {
"$ref": "#/definitions/employeeInfoResponseBody"
},
"issueScore": {
"type": "number",
"description": "引用问题的得分",
"format": "double"
"isReceiver": {
"type": "boolean",
"description": "是否领取人",
"required": [
"isReceiver"
]
},
"percentage": {
"type": "integer",
... ...
... ... @@ -41,6 +41,20 @@ paths:
$ref: '#/definitions/ConfigListCustomerValueResponseBody'
schemes:
- http
/config/employee-permissions:
get:
tags:
- config
summary: 返回员工权限字典列表(1任务管理,2素币管理,3成员管理)
description: 返回员工权限字典列表(1任务管理,2素币管理,3成员管理)
operationId: config#listEmployeePermission
responses:
"200":
description: OK response.
schema:
$ref: '#/definitions/ConfigListEmployeePermissionResponseBody'
schemes:
- http
/config/reference-resource-types:
get:
tags:
... ... @@ -105,6 +119,16 @@ paths:
description: 返回员工列表
operationId: employee#listEmployee
parameters:
- name: companyId
in: query
description: 公司ID
required: false
type: integer
- name: employeeNameMatch
in: query
description: 员工姓名匹配
required: false
type: string
- name: offset
in: query
description: 查询偏离量
... ... @@ -344,6 +368,46 @@ paths:
$ref: '#/definitions/SuMoneySearchSuMoneyTransactionRecordResponseBody'
schemes:
- http
/su-money/su-money-transaction-record-statistics:
post:
tags:
- suMoney
summary: 素币事务记录统计
description: 素币事务记录统计
operationId: suMoney#suMoneyTransactionRecordStatistics
parameters:
- name: SuMoneyTransactionRecordStatisticsRequestBody
in: body
required: true
schema:
$ref: '#/definitions/SuMoneySuMoneyTransactionRecordStatisticsRequestBody'
responses:
"200":
description: OK response.
schema:
$ref: '#/definitions/SuMoneySuMoneyTransactionRecordStatisticsResponseBody'
schemes:
- http
/su-money/su-money-transaction-records/{suMoneyTransactionRecordId}:
get:
tags:
- suMoney
summary: 返回素币事务记录
description: 返回素币事务记录
operationId: suMoney#getSuMoneyTransactionRecord
parameters:
- name: suMoneyTransactionRecordId
in: path
description: 素币事务记录ID
required: true
type: integer
responses:
"200":
description: OK response.
schema:
$ref: '#/definitions/SuMoneyGetSuMoneyTransactionRecordResponseBody'
schemes:
- http
/tasks:
get:
tags:
... ... @@ -382,7 +446,10 @@ paths:
in: query
description: 客户价值
required: false
type: array
items:
type: string
collectionFormat: multi
- name: taskNature
in: query
description: 任务性质
... ... @@ -741,6 +808,14 @@ definitions:
type: array
items:
$ref: '#/definitions/configResponseBody'
ConfigListEmployeePermissionResponseBody:
title: 'Mediatype identifier: ConfigListEmployeePermissionResponseBody'
type: object
properties:
employeePermissions:
type: array
items:
$ref: '#/definitions/configResponseBody'
ConfigListReferenceResourceTypeResponseBody:
title: 'Mediatype identifier: ConfigListReferenceResourceTypeResponseBody'
type: object
... ... @@ -780,6 +855,9 @@ definitions:
employeeAccount:
type: string
description: 员工账号
employeeAvatarUrl:
type: string
description: 员工头像URL
employeeName:
type: string
description: 员工姓名
... ... @@ -825,9 +903,18 @@ definitions:
employeeAccount:
type: string
description: 员工账号
employeeAvatarUrl:
type: string
description: 员工头像URL
employeeName:
type: string
description: 员工姓名
permissions:
type: array
items:
type: integer
format: int64
description: 员工权限集合
EmployeeUpdateEmployeeResponseBody:
title: 'Mediatype identifier: EmployeeUpdateEmployeeResponseBody'
type: object
... ... @@ -850,6 +937,8 @@ definitions:
required:
- companyId
customerValue:
type: array
items:
type: string
description: 客户价值
limit:
... ... @@ -964,6 +1053,12 @@ definitions:
properties:
suMoneyTransactionRecord:
$ref: '#/definitions/suMoneyTransactionRecordResponseBody'
SuMoneyGetSuMoneyTransactionRecordResponseBody:
title: 'Mediatype identifier: SuMoneyGetSuMoneyTransactionRecordResponseBody'
type: object
properties:
suMoneyTransactionRecord:
$ref: '#/definitions/suMoneyTransactionRecordResponseBody'
SuMoneySearchSuMoneyTransactionRecordRequestBody:
title: SuMoneySearchSuMoneyTransactionRecordRequestBody
type: object
... ... @@ -1010,6 +1105,37 @@ definitions:
type: array
items:
$ref: '#/definitions/suMoneyTransactionRecordResponseBody'
SuMoneySuMoneyTransactionRecordStatisticsRequestBody:
title: SuMoneySuMoneyTransactionRecordStatisticsRequestBody
type: object
properties:
transactionEndTime:
type: string
description: 事务时间区间-截止时间
format: datetime
transactionStartTime:
type: string
description: 事务时间区间-开始时间
format: datetime
uid:
type: integer
description: 统一用户UID
required:
- uid
SuMoneySuMoneyTransactionRecordStatisticsResponseBody:
title: 'Mediatype identifier: SuMoneySuMoneyTransactionRecordStatisticsResponseBody'
type: object
properties:
expendSuMoney:
type: number
description: 支出素币
required:
- expendSuMoney
incomeSuMoney:
type: number
description: 收入素币
required:
- incomeSuMoney
TaskAcceptanceTaskRequestBody:
title: TaskAcceptanceTaskRequestBody
type: object
... ... @@ -1025,6 +1151,11 @@ definitions:
type: integer
format: int64
description: 任务参与者UID列表
referenceResourceScore:
type: array
items:
$ref: '#/definitions/referenceResourceItemRequestBody'
description: 引用资源解决分
solvePictureUrls:
type: array
items:
... ... @@ -1113,6 +1244,11 @@ definitions:
type: string
description: 竞标开始时间
format: datetime
companyId:
type: integer
description: 公司ID
required:
- companyId
customerValue:
type: array
items:
... ... @@ -1249,6 +1385,8 @@ definitions:
required:
- companyId
customerValue:
type: array
items:
type: string
description: 客户价值
limit:
... ... @@ -1307,11 +1445,16 @@ definitions:
required:
- companyId
customerValue:
type: array
items:
type: string
description: 客户价值
isFilterCloseStatus:
type: boolean
description: 是否过滤关闭状态任务
isFilterUnReleasedStatus:
type: boolean
description: 是否过滤待发布状态任务
isRewardTake:
type: boolean
description: 是否悬赏任务
... ... @@ -1471,6 +1614,9 @@ definitions:
employeeAccount:
type: string
description: 员工账号
employeeAvatarUrl:
type: string
description: 员工头像URL
employeeName:
type: string
description: 员工姓名
... ... @@ -1489,6 +1635,9 @@ definitions:
employeeAccount:
type: string
description: 员工账号
employeeAvatarUrl:
type: string
description: 员工头像URL
employeeName:
type: string
description: 员工姓名
... ... @@ -1516,6 +1665,14 @@ definitions:
- employeeId
employeeInfo:
$ref: '#/definitions/employeeInfoResponseBody'
permissions:
type: array
items:
type: integer
format: int64
description: 员工权限集合
required:
- permissions
status:
type: integer
description: 员工状态(启用或者禁用)
... ... @@ -1624,11 +1781,30 @@ definitions:
title: referenceResourceItemRequestBody
type: object
properties:
content:
type: string
description: 内容
required:
- content
issueScore:
type: number
description: 问题总分
format: double
referenceResourceId:
type: integer
description: 引用资源ID
required:
- referenceResourceId
serialNumber:
type: integer
description: 编号
required:
- serialNumber
solveScore:
type: array
items:
$ref: '#/definitions/solveScoreItemRequestBody'
description: 解决评分明细
title:
type: string
description: 标题
... ... @@ -1639,11 +1815,30 @@ definitions:
title: referenceResourceItemResponseBody
type: object
properties:
content:
type: string
description: 内容
required:
- content
issueScore:
type: number
description: 问题总分
format: double
referenceResourceId:
type: integer
description: 引用资源ID
required:
- referenceResourceId
serialNumber:
type: integer
description: 编号
required:
- serialNumber
solveScore:
type: array
items:
$ref: '#/definitions/solveScoreItemResponseBody'
description: 解决评分明细
title:
type: string
description: 标题
... ... @@ -1696,6 +1891,50 @@ definitions:
receiver:
$ref: '#/definitions/employeeInfoResponseBody'
description: 抢单任务信息
solveScoreItemRequestBody:
title: solveScoreItemRequestBody
type: object
properties:
contributor:
$ref: '#/definitions/employeeInfoRequestBody'
isReceiver:
type: boolean
description: 是否领取人
required:
- isReceiver
percentage:
type: integer
description: 解决占比
required:
- percentage
score:
type: number
description: 解决评分
required:
- score
description: 解决评分项
solveScoreItemResponseBody:
title: solveScoreItemResponseBody
type: object
properties:
contributor:
$ref: '#/definitions/employeeInfoResponseBody'
isReceiver:
type: boolean
description: 是否领取人
required:
- isReceiver
percentage:
type: integer
description: 解决占比
required:
- percentage
score:
type: number
description: 解决评分
required:
- score
description: 解决评分项
suMoneyTransactionRecordResponseBody:
title: suMoneyTransactionRecordResponseBody
type: object
... ... @@ -1759,10 +1998,11 @@ definitions:
properties:
contributor:
$ref: '#/definitions/employeeInfoRequestBody'
issueScore:
type: number
description: 引用问题的得分
format: double
isReceiver:
type: boolean
description: 是否领取人
required:
- isReceiver
percentage:
type: integer
description: 任务贡献占比
... ... @@ -1780,10 +2020,11 @@ definitions:
properties:
contributor:
$ref: '#/definitions/employeeInfoResponseBody'
issueScore:
type: number
description: 引用问题的得分
format: double
isReceiver:
type: boolean
description: 是否领取人
required:
- isReceiver
percentage:
type: integer
description: 任务贡献占比
... ...
package command
import (
"fmt"
"time"
"github.com/astaxie/beego/validation"
)
type SuMoneyTransactionRecordStatisticsCommand struct {
// 统一用户UID
Uid int64 `json:"uid" valid:"Required"`
// 事务时间区间-开始时间
TransactionStartTime time.Time `json:"transactionStartTime,omitempty"`
// 事务时间区间-截止时间
TransactionEndTime time.Time `json:"transactionEndTime,omitempty"`
}
func (suMoneyTransactionRecordStatisticsCommand *SuMoneyTransactionRecordStatisticsCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(suMoneyTransactionRecordStatisticsCommand)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package query
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type GetSuMoneyTransactionRecordQuery struct {
// 素币事务记录ID
SuMoneyTransactionRecordId int64 `json:"suMoneyTransactionRecordId" valid:"Required"`
}
func (getSuMoneyTransactionRecordQuery *GetSuMoneyTransactionRecordQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(getSuMoneyTransactionRecordQuery)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
... ... @@ -5,14 +5,49 @@ import (
"github.com/linmadan/egglib-go/utils/tool_funs"
"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"
)
// 素币服务
type SuMoneyService struct {
}
// 返回素币事务记录
func (suMoneyService *SuMoneyService) GetSuMoneyTransactionRecord(getSuMoneyTransactionRecordQuery *query.GetSuMoneyTransactionRecordQuery) (interface{}, error) {
if err := getSuMoneyTransactionRecordQuery.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 suMoneyTransactionRecordRepository domain.SuMoneyTransactionRecordRepository
if value, err := factory.CreateSuMoneyTransactionRecordRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
suMoneyTransactionRecordRepository = value
}
if suMoneyTransactionRecord, err := suMoneyTransactionRecordRepository.FindOne(map[string]interface{}{"suMoneyTransactionRecordId": getSuMoneyTransactionRecordQuery.SuMoneyTransactionRecordId}); 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 suMoneyTransactionRecord, nil
}
}
// 素币兑换
func (suMoneyService *SuMoneyService) ExchangeSuMoney(exchangeSuMoneyCommand *command.ExchangeSuMoneyCommand) (interface{}, error) {
if err := exchangeSuMoneyCommand.ValidateCommand(); err != nil {
... ... @@ -82,6 +117,39 @@ func (suMoneyService *SuMoneyService) SearchSuMoneyTransactionRecord(searchSuMon
}
}
// 素币事务记录统计
func (suMoneyService *SuMoneyService) SuMoneyTransactionRecordStatistics(suMoneyTransactionRecordStatisticsCommand *command.SuMoneyTransactionRecordStatisticsCommand) (interface{}, error) {
if err := suMoneyTransactionRecordStatisticsCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var employeeDao *dao.EmployeeDao
if value, err := factory.CreateEmployeeDao(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
employeeDao = value
}
if calculateResult, err := employeeDao.CalculateSuMoneyTransactionRecord(suMoneyTransactionRecordStatisticsCommand.Uid, suMoneyTransactionRecordStatisticsCommand.TransactionStartTime, suMoneyTransactionRecordStatisticsCommand.TransactionEndTime); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return calculateResult, nil
}
}
func NewSuMoneyService(options map[string]interface{}) *SuMoneyService {
newSuMoneyService := &SuMoneyService{}
return newSuMoneyService
... ...
... ... @@ -40,6 +40,35 @@ func (dao *EmployeeDao) CalculatePersonSuMoney(uid int64) (*domain.PersonSuMoney
}
}
func (dao *EmployeeDao) CalculateSuMoneyTransactionRecord(uid int64, transactionStartTime time.Time, transactionEndTime time.Time) (map[string]interface{}, error) {
tx := dao.transactionContext.PgTx
suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
var incomeSuMoney float64
var expendSuMoney float64
if err := tx.Model(suMoneyTransactionRecordModel).
ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money").
Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid).
Where(`su_money_transaction_record.record_type = ?`, 2).
Where(`su_money_transaction_record.create_time > ?`, transactionStartTime).
Where(`su_money_transaction_record.create_time < ?`, transactionEndTime).
Select(&incomeSuMoney); err != nil {
return nil, err
}
if err := tx.Model(suMoneyTransactionRecordModel).
ColumnExpr("sum(su_money_transaction_record.su_money) AS expend_su_money").
Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid).
Where(`su_money_transaction_record.record_type = ?`, 1).
Where(`su_money_transaction_record.create_time > ?`, transactionStartTime).
Where(`su_money_transaction_record.create_time < ?`, transactionEndTime).
Select(&expendSuMoney); err != nil {
return nil, err
}
return map[string]interface{}{
"incomeSuMoney": incomeSuMoney,
"expendSuMoney": expendSuMoney,
}, nil
}
func NewEmployeeDao(transactionContext *pgTransaction.TransactionContext) (*EmployeeDao, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
... ...
... ... @@ -6,6 +6,7 @@ import (
"github.com/astaxie/beego"
"github.com/linmadan/egglib-go/web/beego/utils"
"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/application/suMoney/service"
)
... ... @@ -13,6 +14,22 @@ type SuMoneyController struct {
beego.Controller
}
func (controller *SuMoneyController) GetSuMoneyTransactionRecord() {
suMoneyService := service.NewSuMoneyService(nil)
getSuMoneyTransactionRecordQuery := &query.GetSuMoneyTransactionRecordQuery{}
suMoneyTransactionRecordId, _ := controller.GetInt64(":suMoneyTransactionRecordId")
getSuMoneyTransactionRecordQuery.SuMoneyTransactionRecordId = suMoneyTransactionRecordId
data, err := suMoneyService.GetSuMoneyTransactionRecord(getSuMoneyTransactionRecordQuery)
var response utils.JsonResponse
if err != nil {
response = utils.ResponseError(controller.Ctx, err)
} else {
response = utils.ResponseData(controller.Ctx, data)
}
controller.Data["json"] = response
controller.ServeJSON()
}
func (controller *SuMoneyController) ExchangeSuMoney() {
suMoneyService := service.NewSuMoneyService(nil)
exchangeSuMoneyCommand := &command.ExchangeSuMoneyCommand{}
... ... @@ -42,3 +59,18 @@ func (controller *SuMoneyController) SearchSuMoneyTransactionRecord() {
controller.Data["json"] = response
controller.ServeJSON()
}
func (controller *SuMoneyController) SuMoneyTransactionRecordStatistics() {
suMoneyService := service.NewSuMoneyService(nil)
suMoneyTransactionRecordStatisticsCommand := &command.SuMoneyTransactionRecordStatisticsCommand{}
json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), suMoneyTransactionRecordStatisticsCommand)
data, err := suMoneyService.SuMoneyTransactionRecordStatistics(suMoneyTransactionRecordStatisticsCommand)
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()
}
... ...
... ... @@ -6,6 +6,8 @@ import (
)
func init() {
beego.Router("/su-money/su-money-transaction-records/:suMoneyTransactionRecordId", &controllers.SuMoneyController{}, "Get:GetSuMoneyTransactionRecord")
beego.Router("/su-money/exchange", &controllers.SuMoneyController{}, "Post:ExchangeSuMoney")
beego.Router("/su-money/search-su-money-transaction-record", &controllers.SuMoneyController{}, "Post:SearchSuMoneyTransactionRecord")
beego.Router("/su-money/su-money-transaction-record-statistics", &controllers.SuMoneyController{}, "Post:SuMoneyTransactionRecordStatistics")
}
... ...
package su_money
import (
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
"net/http"
"time"
"github.com/gavv/httpexpect"
"github.com/go-pg/pg"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg"
)
var _ = Describe("返回素币事务记录", func() {
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(),
"INSERT INTO su_money_transaction_records (id, record_type, employee, su_money, operator, record_description, create_time) VALUES (?, ?, ?, ?, ?, ?, ?)",
1, 1, &domain.EmployeeInfo{
Uid: 2499036607974745088,
}, 100.00, &domain.EmployeeInfo{
Uid: 2499036607974745099,
}, "testRecordDescription", time.Now())
Expect(err).NotTo(HaveOccurred())
})
Describe("返回素币事务记录", func() {
Context("", func() {
It("", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.GET("/su-money/su-money-transaction-records/1").
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM su_money_transaction_records WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package su_money
import (
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
"net/http"
"time"
"github.com/gavv/httpexpect"
"github.com/go-pg/pg"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg"
)
var _ = Describe("素币事务记录统计", func() {
var suMoneyTransactionRecordId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&suMoneyTransactionRecordId),
"INSERT INTO su_money_transaction_records (id, record_type, employee, su_money, operator, record_description, create_time) VALUES (?, ?, ?, ?, ?, ?, ?) RETURNING id",
1, 1, &domain.EmployeeInfo{
Uid: 2499036607974745088,
}, 100.00, &domain.EmployeeInfo{
Uid: 2499036607974745099,
}, "testRecordDescription", time.Now())
Expect(err).NotTo(HaveOccurred())
})
Describe("素币事务记录统计", func() {
Context("", func() {
It("", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"uid": 2499036607974745088,
"transactionStartTime": time.Date(2020, time.Month(4), 5, 8, 0, 0, 0, time.Now().Location()),
"transactionEndTime": time.Date(2030, time.Month(4), 5, 8, 0, 0, 0, time.Now().Location()),
}
httpExpect.POST("/su-money/su-money-transaction-record-statistics").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM su_money_transaction_records WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...