作者 yangfu

Merge branch 'master' of http://gitlab.fjmaimaimai.com/mmm-go/partner

# Conflicts:
#	pkg/port/appsvr/routers/admin_user_router.go
... ... @@ -6,17 +6,9 @@ const SERVICE_NAME = "partner"
var LOG_LEVEL = "debug"
var LOG_File = "app.log"
var ABILITY_SERVICE_HOST = "https://suplus-worth-app-gateway-dev.fjmaimaimai.com"
var MMM_OPEN_API_SERVICE_HOST = "http://mmm-open-api-dev.fjmaimaimai.com"
func init() {
if os.Getenv("LOG_LEVEL") != "" {
LOG_LEVEL = os.Getenv("LOG_LEVEL")
}
if os.Getenv("ABILITY_SERVICE_HOST") != "" {
ABILITY_SERVICE_HOST = os.Getenv("ABILITY_SERVICE_HOST")
}
if os.Getenv("MMM_OPEN_API_SERVICE_HOST") != "" {
MMM_OPEN_API_SERVICE_HOST = os.Getenv("MMM_OPEN_API_SERVICE_HOST")
}
}
... ...
... ... @@ -17,7 +17,7 @@ type AdminUser struct {
//创建时间
CreateAt string `json:"create_at"`
//用户权限
Permission []string `json:"permission"`
Permission []AdminPermission `json:"permission"`
}
type AdminUserFindQuery struct {
... ...
package event
//import (
// coreDomain "github.com/linmadan/egglib-go/core/domain"
// "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
//)
//
//const TASK_ROBED_EVENT = "task-robed-event"
//
//type TaskRobed struct {
// coreDomain.BaseEvent
// // 任务ID
// TaskId int64 `json:"taskId"`
// // 公司ID
// CompanyId int64 `json:"companyId"`
// // 任务名称
// TaskName string `json:"taskName"`
// // 任务类型Type
// TaskType int `json:"taskType"`
// // 任务发起者
// Sponsor *domain.EmployeeInfo `json:"sponsor"`
// // 任务状态
// TaskStatus int `json:"taskStatus"`
// // 引用资源
// ReferenceResource *domain.ReferenceResource `json:"referenceResource"`
// // 抢单任务信息
// RobInfo *domain.RobInfo `json:"robInfo"`
//}
//
//func (event *TaskRobed) EventType() string {
// return TASK_ROBED_EVENT
//}
package service
//import (
// coreDomain "github.com/linmadan/egglib-go/core/domain"
// "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
//)
//
//type RobTaskService interface {
// coreDomain.DomainEventPublisher
// Rob(taskId int64, receiverUid int64) (*domain.Task, error)
//}
package domain_service
//import (
// "fmt"
// coreDomain "github.com/linmadan/egglib-go/core/domain"
// pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
// "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
// "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain/event"
// "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/dao"
// "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/repository"
// "time"
//)
//
//type RobTaskService struct {
// coreDomain.BaseEventPublisher
// transactionContext *pgTransaction.TransactionContext
//}
//
//func (service *RobTaskService) Rob(taskId int64, receiverUid int64) (*domain.Task, error) {
// var employeeRepository domain.EmployeeRepository
// var taskRepository domain.TaskRepository
// var taskDao *dao.TaskDao
// if repository, err := repository.NewEmployeeRepository(service.transactionContext); err != nil {
// return nil, err
// } else {
// employeeRepository = repository
// }
// if repository, err := repository.NewTaskRepository(service.transactionContext); err != nil {
// return nil, err
// } else {
// taskRepository = repository
// }
// if dao, err := dao.NewTaskDao(service.transactionContext); err != nil {
// return nil, err
// } else {
// taskDao = dao
// }
// receiver, err := employeeRepository.FindOne(map[string]interface{}{
// "uid": receiverUid,
// })
// if err != nil {
// return nil, err
// }
// if receiver == nil {
// return nil, fmt.Errorf("无效的领取人")
// }
// task, err := taskRepository.FindOne(map[string]interface{}{
// "taskId": taskId,
// })
// if err != nil {
// return nil, err
// }
// if task == nil {
// return nil, fmt.Errorf("无效的任务")
// }
// if receiver.EmployeeInfo.Uid == task.Sponsor.Uid {
// return nil, fmt.Errorf("无法领取自己发布的任务")
// }
// if task.RobInfo != nil && task.RobInfo.Receiver != nil {
// return nil, fmt.Errorf("任务已经被人领取")
// }
// if err := task.Rob(receiver.EmployeeInfo); err != nil {
// return nil, err
// }
// if err := taskDao.AddRobInfo(taskId, receiver.EmployeeInfo); err != nil {
// return nil, fmt.Errorf("抢单失败,任务可能已经被人领取")
// }
// if task, err := taskRepository.Save(task); err != nil {
// return nil, err
// } else {
// taskRobedEvent := new(event.TaskRobed)
// taskRobedEvent.OccurredOn = time.Now()
// taskRobedEvent.TaskId = task.TaskId
// taskRobedEvent.CompanyId = task.CompanyId
// taskRobedEvent.TaskName = task.TaskName
// taskRobedEvent.TaskType = task.TaskType
// taskRobedEvent.Sponsor = task.Sponsor
// taskRobedEvent.TaskStatus = task.TaskStatus
// taskRobedEvent.ReferenceResource = task.ReferenceResource
// taskRobedEvent.RobInfo = task.RobInfo
// if err := service.Publish(taskRobedEvent); err != nil {
// return nil, err
// }
// return task, nil
// }
//}
//
//func NewRobTaskService(transactionContext *pgTransaction.TransactionContext) (*RobTaskService, error) {
// if transactionContext == nil {
// return nil, fmt.Errorf("transactionContext参数不能为nil")
// } else {
// return &RobTaskService{
// transactionContext: transactionContext,
// }, nil
// }
//}
package service_gateway
import (
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/constant"
"strings"
"time"
)
type HttplibAbilityServiceGateway struct {
httplibBaseServiceGateway
}
func (serviceGateway *HttplibAbilityServiceGateway) CommitQuestionQuotes(uid int64, taskId int64, serials []int64) (map[string]interface{}, error) {
url := strings.Join([]string{serviceGateway.baseURL, "task/commitQuestionQuotes"}, "/")
request := serviceGateway.createRequest(url, "post")
options := make(map[string]interface{})
options["uid"] = uid
options["taskId"] = taskId
options["serials"] = serials
request.JSONBody(options)
response := make(map[string]interface{})
request.ToJSON(&response)
data, err := serviceGateway.responseHandle(response)
return data, err
}
func (serviceGateway *HttplibAbilityServiceGateway) CommitQuestionSolution(qid int64, uid int64, solveUid int64, content string, scoreSolve float64, imgs []string, partners []map[string]interface{}) (map[string]interface{}, error) {
url := strings.Join([]string{serviceGateway.baseURL, "task/commitQuestionSolution"}, "/")
request := serviceGateway.createRequest(url, "post")
options := make(map[string]interface{})
options["qid"] = qid
options["uid"] = uid
options["solveUid"] = solveUid
options["content"] = content
options["scoreSolve"] = scoreSolve
options["imgs"] = imgs
options["partners"] = partners
request.JSONBody(options)
response := make(map[string]interface{})
request.ToJSON(&response)
data, err := serviceGateway.responseHandle(response)
return data, err
}
func (serviceGateway *HttplibAbilityServiceGateway) CloseTaskCallback(taskId int64, referenceResourceIds []int64) (map[string]interface{}, error) {
url := strings.Join([]string{serviceGateway.baseURL, "task/closeTaskCallback"}, "/")
request := serviceGateway.createRequest(url, "post")
options := make(map[string]interface{})
options["taskId"] = taskId
options["referenceResourceIds"] = referenceResourceIds
request.JSONBody(options)
response := make(map[string]interface{})
request.ToJSON(&response)
data, err := serviceGateway.responseHandle(response)
return data, err
}
func (serviceGateway *HttplibAbilityServiceGateway) ReceiverTaskCallback(uid int64, taskId int64, referenceResourceIds []int64, operatorId int64, operatorTime time.Time) (map[string]interface{}, error) {
url := strings.Join([]string{serviceGateway.baseURL, "task/receiverTaskCallback"}, "/")
request := serviceGateway.createRequest(url, "post")
options := make(map[string]interface{})
options["uid"] = uid
options["taskId"] = taskId
options["referenceResourceIds"] = referenceResourceIds
options["operator_id"] = operatorId
options["operator_time"] = operatorTime
request.JSONBody(options)
response := make(map[string]interface{})
request.ToJSON(&response)
data, err := serviceGateway.responseHandle(response)
return data, err
}
func (serviceGateway *HttplibAbilityServiceGateway) SaveTaskCallback(uid int64, taskId int64, serials []int64) (map[string]interface{}, error) {
url := strings.Join([]string{serviceGateway.baseURL, "task/saveTaskCallback"}, "/")
request := serviceGateway.createRequest(url, "post")
options := make(map[string]interface{})
options["uid"] = uid
options["taskId"] = taskId
options["serials"] = serials
request.JSONBody(options)
response := make(map[string]interface{})
request.ToJSON(&response)
data, err := serviceGateway.responseHandle(response)
return data, err
}
func (serviceGateway *HttplibAbilityServiceGateway) DeleteTaskCallback(uid int64, taskId int64, serials []int64) (map[string]interface{}, error) {
url := strings.Join([]string{serviceGateway.baseURL, "task/deleteTaskCallback"}, "/")
request := serviceGateway.createRequest(url, "post")
options := make(map[string]interface{})
options["uid"] = uid
options["taskId"] = taskId
options["serials"] = serials
request.JSONBody(options)
response := make(map[string]interface{})
request.ToJSON(&response)
data, err := serviceGateway.responseHandle(response)
return data, err
}
func NewHttplibAbilityServiceGateway() *HttplibAbilityServiceGateway {
return &HttplibAbilityServiceGateway{
httplibBaseServiceGateway: httplibBaseServiceGateway{
baseURL: constant.ABILITY_SERVICE_HOST,
connectTimeout: 100 * time.Second,
readWriteTimeout: 30 * time.Second,
},
}
}
package service_gateway
import (
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/constant"
"strings"
"time"
)
type HttplibMmmOpenApiServiceGateway struct {
httplibBaseServiceGateway
}
func (serviceGateway *HttplibMmmOpenApiServiceGateway) PushInfo(msgType int, uids []int64, title string, content string, ext map[string]interface{}) (map[string]interface{}, error) {
url := strings.Join([]string{serviceGateway.baseURL, "v1", "push", "pushInfo"}, "/")
request := serviceGateway.createRequest(url, "post")
options := make(map[string]interface{})
options["mmmType"] = msgType
options["project"] = "worth"
options["receivers"] = uids
options["title"] = title
options["content"] = content
options["ext"] = ext
request.JSONBody(options)
response := make(map[string]interface{})
request.ToJSON(&response)
data, err := serviceGateway.responseHandle(response)
return data, err
}
func NewHttplibMmmOpenApiServiceGateway() *HttplibMmmOpenApiServiceGateway {
return &HttplibMmmOpenApiServiceGateway{
httplibBaseServiceGateway: httplibBaseServiceGateway{
baseURL: constant.MMM_OPEN_API_SERVICE_HOST,
connectTimeout: 100 * time.Second,
readWriteTimeout: 30 * time.Second,
},
}
}
package service_gateway
import (
"encoding/json"
"fmt"
"github.com/astaxie/beego/httplib"
"strconv"
"strings"
"time"
)
type httplibBaseServiceGateway struct {
baseURL string
connectTimeout time.Duration
readWriteTimeout time.Duration
}
func (serviceGateway *httplibBaseServiceGateway) createRequest(url string, method string) *httplib.BeegoHTTPRequest {
var request *httplib.BeegoHTTPRequest
switch method {
case "get":
request = httplib.Get(url)
break
case "post":
request = httplib.Post(url)
break
case "put":
request = httplib.Put(url)
break
case "delete":
request = httplib.Delete(url)
break
case "head":
request = httplib.Head(url)
break
default:
request = httplib.Get(url)
}
return request.SetTimeout(serviceGateway.connectTimeout, serviceGateway.readWriteTimeout)
}
func (serviceGateway *httplibBaseServiceGateway) responseHandle(response map[string]interface{}) (map[string]interface{}, error) {
data := make(map[string]interface{})
var err error
if code, ok := response["code"]; ok {
code := code.(float64)
if code == 0 {
data = response["data"].(map[string]interface{})
} else {
msg := response["msg"].(string)
err = fmt.Errorf(strings.Join([]string{strconv.FormatFloat(code, 'f', -1, 64), msg}, " "))
}
} else {
jsonBytes, marshalErr := json.Marshal(response)
if marshalErr != nil {
err = marshalErr
}
err = fmt.Errorf("无法解析的网关服务数据返回格式:%s", string(jsonBytes))
}
return data, err
}
package service_gateway
import "time"
type AbilityServiceGateway interface {
CommitQuestionQuotes(uid int64, taskId int64, serials []int64) (map[string]interface{}, error)
CommitQuestionSolution(qid int64, uid int64, solveUid int64, content string, scoreSolve float64, imgs []string, partners []map[string]interface{}) (map[string]interface{}, error)
CloseTaskCallback(taskId int64, referenceResourceIds []int64) (map[string]interface{}, error)
ReceiverTaskCallback(uid int64, taskId int64, referenceResourceIds []int64, operatorId int64, operatorTime time.Time) (map[string]interface{}, error)
SaveTaskCallback(uid int64, taskId int64, serials []int64) (map[string]interface{}, error)
DeleteTaskCallback(uid int64, taskId int64, serials []int64) (map[string]interface{}, error)
}
type MmmOpenApiServiceGateway interface {
PushInfo(msgType int, uids []int64, title string, content string, ext map[string]interface{}) (map[string]interface{}, error)
}