作者 yangfu

大屏互动初始化

正在显示 49 个修改的文件 包含 3319 行增加66 行删除
... ... @@ -8,7 +8,7 @@ bsi-api:
.PHONY: bsi-swagger
bsi-swagger:
goctl api plugin -plugin goctl-swagger="swagger -filename core.json" -api .\cmd\bsi\api\dsl\core.api -dir .\cmd\discuss\api\dsl
goctl api plugin -plugin goctl-swagger="swagger -filename core.json" -api .\cmd\bsi\api\dsl\core.api -dir .\cmd\bsi\api\dsl
.PHONY: bsi-build
bsi-build:
... ...
{
"swagger": "2.0",
"info": {
"title": "",
"version": ""
},
"schemes": [
"http",
"https"
],
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"paths": {
"v1/clear": {
"get": {
"summary": "清理缓存",
"operationId": "commonGetClearCache",
"responses": {
"200": {
"description": "A successful response.",
"schema": {}
}
},
"requestBody": {},
"tags": [
"common"
]
}
},
"v1/common/sms/code": {
"post": {
"summary": "短信验证码",
"operationId": "commonSmsCode",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/CommonSmsCodeResposne"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/CommonSmsCodeRequest"
}
}
],
"requestBody": {},
"tags": [
"common"
]
}
},
"v1/h5/activity/pull-submission": {
"post": {
"summary": "活动问卷拉取",
"operationId": "h5ActivityQuestionnairePullSubmission",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/PullSubmissionResponse"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/PullSubmissionRequest"
}
}
],
"requestBody": {},
"tags": [
"activity"
]
}
},
"v1/h5/activity/questionnaire-Submit": {
"post": {
"summary": "活动问卷提交",
"operationId": "h5ActivityQuestionnaireSubmit",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/QuestionnaireSubmitResponse"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/QuestionnaireSubmitRequest"
}
}
],
"requestBody": {},
"tags": [
"activity"
]
}
},
"v1/h5/activity/{id}": {
"get": {
"summary": "活动详情",
"operationId": "h5ActivityGet",
"responses": {
"200": {
"description": "A successful response.",
"schema": {}
}
},
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"type": "string"
}
],
"requestBody": {},
"tags": [
"activity"
]
}
},
"v1/log/{module}": {
"get": {
"summary": "日志查询",
"operationId": "commonGetLog",
"responses": {
"200": {
"description": "A successful response.",
"schema": {}
}
},
"parameters": [
{
"name": "module",
"in": "path",
"required": true,
"type": "string"
}
],
"requestBody": {},
"tags": [
"common"
]
}
},
"v1/mini/qrcode": {
"post": {
"summary": "微信二维码",
"operationId": "miniQrcodeInvite",
"responses": {
"200": {
"description": "A successful response.",
"schema": {}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/MiniQrCodeRequest"
}
}
],
"requestBody": {},
"tags": [
"common"
]
}
},
"v1/system/activity": {
"post": {
"summary": "活动保存",
"operationId": "systemActivitySave",
"responses": {
"200": {
"description": "A successful response.",
"schema": {}
}
},
"requestBody": {},
"tags": [
"activity"
]
}
},
"v1/system/activity/close": {
"post": {
"summary": "活动关闭",
"operationId": "systemActivityClose",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/ActivityCloseResponse"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/ActivityCloseRequest"
}
}
],
"requestBody": {},
"tags": [
"activity"
]
}
},
"v1/system/activity/open": {
"post": {
"summary": "活动开启",
"operationId": "systemActivityOpen",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/ActivityOpenResponse"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/ActivityOpenRequest"
}
}
],
"requestBody": {},
"tags": [
"activity"
]
}
},
"v1/system/activity/search": {
"post": {
"summary": "活动搜索",
"operationId": "systemActivitySearch",
"responses": {
"200": {
"description": "A successful response.",
"schema": {}
}
},
"requestBody": {},
"tags": [
"activity"
]
}
},
"v1/system/activity/submition-data-export": {
"post": {
"summary": "活动问卷数据导出",
"operationId": "systemActivitySubmissionDataExport",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/SubmissionDataSearchResponse"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/SubmissionDataSearchRequest"
}
}
],
"requestBody": {},
"tags": [
"activity"
]
}
},
"v1/system/activity/submition-data-search": {
"post": {
"summary": "活动问卷数据搜索",
"operationId": "systemActivitySubmissionDataSearch",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/SubmissionDataSearchResponse"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/SubmissionDataSearchRequest"
}
}
],
"requestBody": {},
"tags": [
"activity"
]
}
},
"v1/system/activity/{id}": {
"get": {
"summary": "活动详情",
"operationId": "systemActivityGet",
"responses": {
"200": {
"description": "A successful response.",
"schema": {}
}
},
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"type": "string"
}
],
"requestBody": {},
"tags": [
"activity"
]
},
"delete": {
"summary": "活动删除",
"operationId": "systemActivityDelete",
"responses": {
"200": {
"description": "A successful response.",
"schema": {}
}
},
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"type": "string"
}
],
"requestBody": {},
"tags": [
"activity"
]
},
"put": {
"summary": "活动更新",
"operationId": "systemActivityUpdate",
"responses": {
"200": {
"description": "A successful response.",
"schema": {}
}
},
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"type": "string"
}
],
"requestBody": {},
"tags": [
"activity"
]
}
}
},
"definitions": {
"ActivityCloseRequest": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64",
"description": " 唯一标识"
}
},
"title": "ActivityCloseRequest",
"required": [
"id"
]
},
"ActivityCloseResponse": {
"type": "object",
"title": "ActivityCloseResponse"
},
"ActivityOpenRequest": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64",
"description": " 唯一标识"
}
},
"title": "ActivityOpenRequest",
"required": [
"id"
]
},
"ActivityOpenResponse": {
"type": "object",
"title": "ActivityOpenResponse"
},
"CommonSmsCodeRequest": {
"type": "object",
"properties": {
"phone": {
"type": "string"
}
},
"title": "CommonSmsCodeRequest",
"required": [
"phone"
]
},
"CommonSmsCodeResposne": {
"type": "object",
"title": "CommonSmsCodeResposne"
},
"MiniQrCodeRequest": {
"type": "object",
"properties": {
"page": {
"type": "string",
"description": " 微信页面入口"
},
"scene": {
"type": "string",
"description": " 参数"
}
},
"title": "MiniQrCodeRequest",
"required": [
"page",
"scene"
]
},
"PullSubmissionRequest": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64",
"description": " 活动ID"
},
"timestamp": {
"type": "integer",
"format": "int64",
"description": " 最后一次拉取时间戳,首次为当前时间"
}
},
"title": "PullSubmissionRequest",
"required": [
"id",
"timestamp"
]
},
"PullSubmissionResponse": {
"type": "object",
"properties": {
"totalParticipants": {
"type": "integer",
"format": "int64",
"description": " 累计参与人次"
},
"list": {
"type": "array",
"items": {
"$ref": "#/definitions/SubmissionItem"
}
}
},
"title": "PullSubmissionResponse",
"required": [
"totalParticipants",
"list"
]
},
"QuestionItem": {
"type": "object",
"properties": {
"label": {
"type": "string",
"description": " 字段名称"
},
"product": {
"type": "string",
"description": " 商品(非必填)"
},
"value": {
"type": "string",
"description": " 值"
}
},
"title": "QuestionItem",
"required": [
"label",
"product",
"value"
]
},
"QuestionnaireSubmitRequest": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64",
"description": " 活动ID"
},
"formList": {
"type": "array",
"items": {
"$ref": "#/definitions/QuestionItem"
},
"description": " 表单列表"
}
},
"title": "QuestionnaireSubmitRequest",
"required": [
"id",
"formList"
]
},
"QuestionnaireSubmitResponse": {
"type": "object",
"title": "QuestionnaireSubmitResponse"
},
"SubmissionDataSearchRequest": {
"type": "object",
"properties": {
"page": {
"type": "integer",
"format": "int32"
},
"size": {
"type": "integer",
"format": "int32"
},
"activityId": {
"type": "integer",
"format": "int64"
},
"name": {
"type": "string"
},
"product": {
"type": "string"
},
"isRepeat": {
"$ref": "#/definitions/bool",
"description": " true:重复的 false:正常"
},
"amountFrom": {
"type": "number",
"format": "double",
"description": " 金额 从多少开始"
},
"amountTo": {
"type": "number",
"format": "double",
"description": " 金额 从多少截至"
},
"selectIdList": {
"type": "array",
"items": {
"type": "integer",
"format": "int64"
},
"description": " 选择的数据项"
}
},
"title": "SubmissionDataSearchRequest",
"required": [
"page",
"size",
"amountFrom",
"amountTo",
"selectIdList"
]
},
"SubmissionDataSearchResponse": {
"type": "object",
"properties": {
"list": {
"type": "array",
"items": {
"$ref": "#/definitions/SubmissionItem"
}
},
"total": {
"type": "integer",
"format": "int64"
}
},
"title": "SubmissionDataSearchResponse",
"required": [
"list",
"total"
]
},
"SubmissionItem": {
"type": "object",
"properties": {
"name": {
"type": "string",
"description": " 投资人姓名"
},
"title": {
"type": "string",
"description": " 称谓"
},
"avatar": {
"type": "string",
"description": " 头像"
},
"product": {
"type": "string",
"description": " 产品"
},
"amount": {
"type": "number",
"format": "double",
"description": " 金额"
},
"greeting": {
"type": "string",
"description": " 祝福"
},
"time": {
"type": "integer",
"format": "int64",
"description": "提报时间"
},
"isRepeat": {
"type": "boolean",
"format": "boolean",
"description": " 是否重复"
}
},
"title": "SubmissionItem",
"required": [
"name",
"title",
"avatar",
"product",
"amount",
"greeting",
"time",
"isRepeat"
]
},
"TodoRequest": {
"type": "object",
"title": "TodoRequest"
},
"TodoResonse": {
"type": "object",
"title": "TodoResonse"
}
},
"securityDefinitions": {
"apiKey": {
"type": "apiKey",
"description": "Enter JWT Bearer token **_only_**",
"name": "Authorization",
"in": "header"
}
},
"security": [
{
"apiKey": []
}
]
}
... ...
... ... @@ -2,32 +2,129 @@ syntax = "v1"
info(
title: "易数家显示大屏互动服务"
desc: "易数家显示大屏互动服务 BSI(Big screen interaction)"
author: "bsi"
email: "bsi@gmail.com"
desc: "易数家显示大屏互动服务 (Big screen interaction)"
author: ""
email: "@gmail.com"
version: "v1"
)
// H5接口
// 后台接口
@server(
prefix: v1/system
group: activity
middleware: LoginStatusCheck,LogRequest
jwt: SystemAuth
)
service Core {
@doc "活动详情"
@handler systemActivityGet
get /activity/:id //(ActivityGetRequest) returns (ActivityGetResponse)
@doc "活动保存"
@handler systemActivitySave
post /activity //(ActivitySaveRequest) returns (ActivitySaveResponse)
@doc "活动删除"
@handler systemActivityDelete
delete /activity/:id //(ActivityDeleteRequest) returns (ActivityDeleteResponse)
@doc "活动更新"
@handler systemActivityUpdate
put /activity/:id //(ActivityUpdateRequest) returns (ActivityUpdateResponse)
@doc "活动搜索"
@handler systemActivitySearch
post /activity/search //(ActivitySearchRequest) returns (ActivitySearchResponse)
@doc "活动开启"
@handler systemActivityOpen
post /activity/open (ActivityOpenRequest) returns (ActivityOpenResponse)
@doc "活动关闭"
@handler systemActivityClose
post /activity/close (ActivityCloseRequest) returns (ActivityCloseResponse)
@doc "活动问卷数据搜索"
@handler systemActivitySubmissionDataSearch
post /activity/submition-data-search (SubmissionDataSearchRequest) returns(SubmissionDataSearchResponse)
@doc "活动问卷数据导出"
@handler systemActivitySubmissionDataExport
post /activity/submition-data-export (SubmissionDataSearchRequest) returns(SubmissionDataSearchResponse)
}
@server(
prefix: v1/h5
group: todo
group: activity
middleware: LogRequest
//jwt: MiniAuth
)
service Core {
@doc ""
@handler H5Todo
get /todo
@doc ""
@handler H5TodoErrorCommon
get /todo/err1 returns(TodoResonse)
@doc ""
@handler H5TodoErrorInternal
get /todo/err2 returns(TodoResonse)
@doc ""
@handler H5TodoErrorGrpc
get /todo/err3 returns(TodoResonse)
@doc "活动详情"
@handler h5ActivityGet
get /activity/:id //(ActivityGetRequest) returns (ActivityGetResponse)
@doc "活动问卷提交"
@handler h5ActivityQuestionnaireSubmit
post /activity/questionnaire-Submit (QuestionnaireSubmitRequest) returns (QuestionnaireSubmitResponse)
@doc "活动问卷拉取"
@handler h5ActivityQuestionnairePullSubmission
post /activity/pull-submission (PullSubmissionRequest) returns(PullSubmissionResponse)
}
type(
ActivityOpenRequest struct{
Id int64 `json:"id"` // 唯一标识
}
ActivityOpenResponse struct{
}
ActivityCloseRequest struct{
Id int64 `json:"id"` // 唯一标识
}
ActivityCloseResponse struct{
}
)
type(
QuestionnaireSubmitRequest struct{
Id int64 `json:"id"` // 活动ID
FormList []QuestionItem `json:"formList"` // 表单列表
}
QuestionnaireSubmitResponse{}
SubmissionDataSearchRequest struct{
Page int `json:"page"`
Size int `json:"size"`
ActivityId int64 `json:"activityId,optional"`
Name string `json:"name,optional"`
Product string `json:"product,optional"`
IsRepeat *bool `json:"isRepeat,optional"` // true:重复的 false:正常
AmountFrom float64 `json:"amountFrom"` // 金额 从多少开始
AmountTo float64 `json:"amountTo"` // 金额 从多少截至
SelectIdList []int64 `json:"selectIdList"` // 选择的数据项
}
SubmissionDataSearchResponse struct{
List []SubmissionItem `json:"list"`
Total int64 `json:"total"`
}
PullSubmissionRequest{
Id int64 `json:"id"` // 活动ID
Timestamp int64 `json:"timestamp"` // 最后一次拉取时间戳,首次为当前时间
}
PullSubmissionResponse{
TotalParticipants int64 `json:"totalParticipants"` // 累计参与人次
List []SubmissionItem `json:"list"`
}
SubmissionItem{
Name string `json:"name"` // 投资人姓名
Title string `json:"title"` // 称谓
Avatar string `json:"avatar"` // 头像
Product string `json:"product"`// 产品
Amount float64 `json:"amount"`// 金额
Greeting string `json:"greeting"` // 祝福
Time int64 `json:"time"` //提报时间
IsRepeat bool `json:"isRepeat"` // 是否重复
}
)
type QuestionItem struct {
Label string `json:"label"` // 字段名称
Product string `json:"product"` // 商品(非必填)
Value string `json:"value"` // 值
}
type (
... ...
Name: Core
Host: 0.0.0.0
Port: 8080
Port: 8081
Verbose: false
Migrate: true
... ...
package activity
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/api/internal/types"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/api/internal/logic/activity"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/api/internal/svc"
)
func H5ActivityGetHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.ActivityGetRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := activity.NewSystemActivityGetLogic(r.Context(), svcCtx)
resp, err := l.SystemActivityGet(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
package activity
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/api/internal/logic/activity"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/api/internal/types"
)
func H5ActivityQuestionnairePullSubmissionHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.PullSubmissionRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := activity.NewH5ActivityQuestionnairePullSubmissionLogic(r.Context(), svcCtx)
resp, err := l.H5ActivityQuestionnairePullSubmission(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
package activity
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/api/internal/logic/activity"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/api/internal/types"
)
func H5ActivityQuestionnaireSubmitHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.QuestionnaireSubmitRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := activity.NewH5ActivityQuestionnaireSubmitLogic(r.Context(), svcCtx)
resp, err := l.H5ActivityQuestionnaireSubmit(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
package activity
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/api/internal/logic/activity"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/api/internal/types"
)
func SystemActivityCloseHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.ActivityCloseRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := activity.NewSystemActivityCloseLogic(r.Context(), svcCtx)
resp, err := l.SystemActivityClose(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
package activity
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/api/internal/logic/activity"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/api/internal/types"
)
func SystemActivityDeleteHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.ActivityDeleteRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := activity.NewSystemActivityDeleteLogic(r.Context(), svcCtx)
resp, err := l.SystemActivityDelete(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
package activity
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/api/internal/logic/activity"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/api/internal/types"
)
func SystemActivityGetHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.ActivityGetRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := activity.NewSystemActivityGetLogic(r.Context(), svcCtx)
resp, err := l.SystemActivityGet(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
package activity
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/api/internal/logic/activity"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/api/internal/types"
)
func SystemActivityOpenHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.ActivityOpenRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := activity.NewSystemActivityOpenLogic(r.Context(), svcCtx)
resp, err := l.SystemActivityOpen(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
package activity
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/api/internal/logic/activity"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/api/internal/types"
)
func SystemActivitySaveHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.ActivitySaveRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := activity.NewSystemActivitySaveLogic(r.Context(), svcCtx)
resp, err := l.SystemActivitySave(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
package activity
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/api/internal/logic/activity"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/api/internal/types"
)
func SystemActivitySearchHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.ActivitySearchRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := activity.NewSystemActivitySearchLogic(r.Context(), svcCtx)
resp, err := l.SystemActivitySearch(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
package activity
import (
"fmt"
"github.com/tiptok/tab"
"net/http"
"time"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/api/internal/logic/activity"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/api/internal/types"
)
func SystemActivitySubmissionDataExportHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.SubmissionDataSearchRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := activity.NewSystemActivitySubmissionDataSearchLogic(r.Context(), svcCtx)
resp, err := l.SystemActivitySubmissionDataSearch(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
}
title := []string{"人员姓名", "产品名称", "投资金额", "提报时间"}
data := make([][]string, 0)
for _, item := range resp.List {
row := make([]string, 0)
row = append(row,
item.Name,
item.Product,
fmt.Sprintf("%0.2f", item.Amount),
time.Unix(item.Time, 0).Format("2006-01-02 15:04:05"),
)
data = append(data, row)
}
w.Header().Set("Content-Disposition", "attachment; filename="+"提报数据.xlsx")
w.Header().Set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=GBK") //"application/octet-stream")
writerTo := tab.NewXLXSWriterTo(title, data)
writerTo.WriteTo(w)
}
}
... ...
package activity
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/api/internal/logic/activity"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/api/internal/types"
)
func SystemActivitySubmissionDataSearchHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.SubmissionDataSearchRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := activity.NewSystemActivitySubmissionDataSearchLogic(r.Context(), svcCtx)
resp, err := l.SystemActivitySubmissionDataSearch(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
package activity
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/api/internal/logic/activity"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/api/internal/types"
)
func SystemActivityUpdateHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.ActivityUpdateRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := activity.NewSystemActivityUpdateLogic(r.Context(), svcCtx)
resp, err := l.SystemActivityUpdate(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
... ... @@ -4,8 +4,8 @@ package handler
import (
"net/http"
activity "gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/api/internal/handler/activity"
common "gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/api/internal/handler/common"
todo "gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/api/internal/handler/todo"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/api/internal/svc"
"github.com/zeromicro/go-zero/rest"
... ... @@ -49,27 +49,77 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
server.AddRoutes(
rest.WithMiddlewares(
[]rest.Middleware{serverCtx.LogRequest},
[]rest.Middleware{serverCtx.LoginStatusCheck, serverCtx.LogRequest},
[]rest.Route{
{
Method: http.MethodGet,
Path: "/todo",
Handler: todo.H5TodoHandler(serverCtx),
Path: "/activity/:id",
Handler: activity.SystemActivityGetHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/todo/err1",
Handler: todo.H5TodoErrorCommonHandler(serverCtx),
Method: http.MethodPost,
Path: "/activity",
Handler: activity.SystemActivitySaveHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/todo/err2",
Handler: todo.H5TodoErrorInternalHandler(serverCtx),
Method: http.MethodDelete,
Path: "/activity/:id",
Handler: activity.SystemActivityDeleteHandler(serverCtx),
},
{
Method: http.MethodPut,
Path: "/activity/:id",
Handler: activity.SystemActivityUpdateHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/activity/search",
Handler: activity.SystemActivitySearchHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/activity/open",
Handler: activity.SystemActivityOpenHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/activity/close",
Handler: activity.SystemActivityCloseHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/activity/submition-data-search",
Handler: activity.SystemActivitySubmissionDataSearchHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/activity/submition-data-export",
Handler: activity.SystemActivitySubmissionDataExportHandler(serverCtx),
},
}...,
),
rest.WithJwt(serverCtx.Config.SystemAuth.AccessSecret),
rest.WithPrefix("/v1/system"),
)
server.AddRoutes(
rest.WithMiddlewares(
[]rest.Middleware{serverCtx.LogRequest},
[]rest.Route{
{
Method: http.MethodGet,
Path: "/todo/err3",
Handler: todo.H5TodoErrorGrpcHandler(serverCtx),
Path: "/activity/:id",
Handler: activity.H5ActivityGetHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/activity/questionnaire-Submit",
Handler: activity.H5ActivityQuestionnaireSubmitHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/activity/pull-submission",
Handler: activity.H5ActivityQuestionnairePullSubmissionHandler(serverCtx),
},
}...,
),
... ...
package activity
import (
"context"
"github.com/zeromicro/go-zero/core/logx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/api/internal/svc"
)
type H5ActivityGetLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewH5ActivityGetLogic(ctx context.Context, svcCtx *svc.ServiceContext) *H5ActivityGetLogic {
return &H5ActivityGetLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *H5ActivityGetLogic) H5ActivityGet() error {
// todo: add your logic here and delete this line
return nil
}
... ...
package activity
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type H5ActivityQuestionnairePullSubmissionLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewH5ActivityQuestionnairePullSubmissionLogic(ctx context.Context, svcCtx *svc.ServiceContext) *H5ActivityQuestionnairePullSubmissionLogic {
return &H5ActivityQuestionnairePullSubmissionLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *H5ActivityQuestionnairePullSubmissionLogic) H5ActivityQuestionnairePullSubmission(req *types.PullSubmissionRequest) (resp *types.PullSubmissionResponse, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
dms []*domain.BsiActivityQuestionnaireSubmitRecord
total int64
)
queryOptions := domain.NewQueryOptions().WithFindOnly().
MustWithKV("activityId", req.Id).
WithKV("timestamp", req.Timestamp)
_, dms, err = l.svcCtx.BsiActivityQuestionnaireSubmitRecordRepository.Find(l.ctx, conn, queryOptions)
list := make([]types.SubmissionItem, 0)
for i := range dms {
item := NewTypesSubmissionItem(dms[i])
list = append(list, item)
}
// 累计参与人次
queryOptions = domain.NewQueryOptions().WithCountOnly().MustWithKV("activityId", req.Id)
total, _, _ = l.svcCtx.BsiActivityQuestionnaireSubmitRecordRepository.Find(l.ctx, conn, queryOptions)
resp = &types.PullSubmissionResponse{
List: list,
TotalParticipants: total,
}
return
}
... ...
package activity
import (
"context"
"fmt"
"github.com/samber/lo"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/pkg/transaction"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/pkg/xerr"
"strconv"
"strings"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type H5ActivityQuestionnaireSubmitLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewH5ActivityQuestionnaireSubmitLogic(ctx context.Context, svcCtx *svc.ServiceContext) *H5ActivityQuestionnaireSubmitLogic {
return &H5ActivityQuestionnaireSubmitLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *H5ActivityQuestionnaireSubmitLogic) H5ActivityQuestionnaireSubmit(req *types.QuestionnaireSubmitRequest) (resp *types.QuestionnaireSubmitResponse, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
userName string
activity *domain.BsiActivity
defaultNameForm = "姓名"
userInfo domain.UserInfo
)
if !lo.ContainsBy(req.FormList, func(item types.QuestionItem) bool {
result := item.Label == defaultNameForm
if result {
userName = item.Value
}
return result
}) {
return nil, xerr.NewErrMsgErr("用户姓名不能为空", nil)
}
if activity, err = l.svcCtx.BsiActivityRepository.FindOne(l.ctx, conn, req.Id); err != nil {
return nil, xerr.NewErrMsgErr("活动不存在", err)
}
// 从预设置人员里面查找
if v, ok := lo.Find(activity.ActivityConfig.DefaultUsers, func(item domain.UserInfo) bool {
return item.Name == userName
}); ok {
userInfo = v
} else {
userInfo = domain.UserInfo{
Name: userName,
}
}
if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
for _, form := range req.FormList {
if form.Label == defaultNameForm {
continue
}
amount, _ := strconv.ParseFloat(strings.TrimRight(form.Value, "元"), 64)
if amount == 0 {
return fmt.Errorf("金额不能为0")
}
record := &domain.BsiActivityQuestionnaireSubmitRecord{
CompanyId: activity.CompanyId,
ActivityId: activity.Id,
Name: userInfo.Name,
Product: form.Product,
Amount: amount,
User: userInfo,
Greeting: activity.RandomGreeting(),
}
if record, err = l.svcCtx.BsiActivityQuestionnaireSubmitRecordRepository.Insert(l.ctx, conn, record); err != nil {
logx.Error(err)
return fmt.Errorf("保存失败")
}
}
return err
}, true); err != nil {
return nil, xerr.NewErrMsgErr(err.Error(), err)
}
return
}
... ...
package activity
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/pkg/transaction"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/pkg/xerr"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type SystemActivityCloseLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSystemActivityCloseLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemActivityCloseLogic {
return &SystemActivityCloseLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *SystemActivityCloseLogic) SystemActivityClose(req *types.ActivityCloseRequest) (resp *types.ActivityCloseResponse, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
dm *domain.BsiActivity
)
if dm, err = l.svcCtx.BsiActivityRepository.FindOne(l.ctx, conn, req.Id); err != nil {
return nil, xerr.NewErrMsgErr("不存在", err)
}
// 赋值
dm.Status = domain.ActivityClosed
// 更新
if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
dm, err = l.svcCtx.BsiActivityRepository.UpdateWithVersion(l.ctx, conn, dm)
return err
}, true); err != nil {
return nil, xerr.NewErrMsg("更新失败")
}
resp = &types.ActivityCloseResponse{}
return
}
... ...
package activity
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/pkg/transaction"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/pkg/xerr"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type SystemActivityDeleteLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSystemActivityDeleteLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemActivityDeleteLogic {
return &SystemActivityDeleteLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *SystemActivityDeleteLogic) SystemActivityDelete(req *types.ActivityDeleteRequest) (resp *types.ActivityDeleteResponse, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
dm *domain.BsiActivity
)
if dm, err = l.svcCtx.BsiActivityRepository.FindOne(l.ctx, conn, req.Id); err != nil {
return nil, xerr.NewErrMsgErr("不存在", err)
}
if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
if dm, err = l.svcCtx.BsiActivityRepository.Delete(l.ctx, conn, dm); err != nil {
return err
}
return nil
}, true); err != nil {
return nil, xerr.NewErrMsgErr("移除失败", err)
}
return
}
... ...
package activity
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/pkg/xerr"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type SystemActivityGetLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSystemActivityGetLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemActivityGetLogic {
return &SystemActivityGetLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *SystemActivityGetLogic) SystemActivityGet(req *types.ActivityGetRequest) (resp *types.ActivityGetResponse, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
dm *domain.BsiActivity
)
// 货号唯一
if dm, err = l.svcCtx.BsiActivityRepository.FindOne(l.ctx, conn, req.Id); err != nil {
return nil, xerr.NewErrMsgErr("不存在", err)
}
resp = &types.ActivityGetResponse{
Activity: NewTypesBsiActivity(dm),
}
return
}
... ...
package activity
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/pkg/transaction"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/pkg/xerr"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type SystemActivityOpenLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSystemActivityOpenLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemActivityOpenLogic {
return &SystemActivityOpenLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *SystemActivityOpenLogic) SystemActivityOpen(req *types.ActivityOpenRequest) (resp *types.ActivityOpenResponse, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
dm *domain.BsiActivity
)
if dm, err = l.svcCtx.BsiActivityRepository.FindOne(l.ctx, conn, req.Id); err != nil {
return nil, xerr.NewErrMsgErr("不存在", err)
}
// 赋值
dm.Status = domain.ActivityOpening
// 更新
if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
dm, err = l.svcCtx.BsiActivityRepository.UpdateWithVersion(l.ctx, conn, dm)
return err
}, true); err != nil {
return nil, xerr.NewErrMsg("更新失败")
}
resp = &types.ActivityOpenResponse{}
return
}
... ...
package activity
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/pkg/transaction"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/pkg/xerr"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type SystemActivitySaveLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSystemActivitySaveLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemActivitySaveLogic {
return &SystemActivitySaveLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *SystemActivitySaveLogic) SystemActivitySave(req *types.ActivitySaveRequest) (resp *types.ActivitySaveResponse, err error) {
var (
dm *domain.BsiActivity
userToken = contextdata.GetUserTokenFromCtx(l.ctx)
)
if err = req.Activity.Valid(); err != nil {
return nil, xerr.NewErrMsg(err.Error())
}
// 唯一判断
dm = NewDomainBsiActivity(userToken.CompanyId, req.Activity)
if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
dm, err = l.svcCtx.BsiActivityRepository.Insert(l.ctx, conn, dm)
return err
}, true); err != nil {
return nil, xerr.NewErrMsg("保存失败")
}
resp = &types.ActivitySaveResponse{}
return
}
func NewDomainBsiActivity(companyId int64, item types.ActivityItem) *domain.BsiActivity {
return &domain.BsiActivity{
CompanyId: companyId,
Issue: item.Issue,
Remark: item.Remark,
ActivateType: item.ActivateType,
BeginAt: item.BeginAt,
EndAt: item.EndAt,
ActivityConfig: item.ActivityConfig,
Status: domain.ActivityWaiting,
}
}
func NewTypesBsiActivity(item *domain.BsiActivity) types.ActivityItem {
return types.ActivityItem{
Id: item.Id,
CompanyId: item.CompanyId,
Issue: item.Issue,
Remark: item.Remark,
ActivateType: item.ActivateType,
BeginAt: item.BeginAt,
EndAt: item.EndAt,
ActivityConfig: item.ActivityConfig,
Status: item.ResolveActivityStatus(),
}
}
... ...
package activity
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/api/internal/types"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/pkg/transaction"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/pkg/xerr"
"github.com/zeromicro/go-zero/core/logx"
)
type SystemActivitySearchLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSystemActivitySearchLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemActivitySearchLogic {
return &SystemActivitySearchLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *SystemActivitySearchLogic) SystemActivitySearch(req *types.ActivitySearchRequest) (resp *types.ActivitySearchResponse, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
dms []*domain.BsiActivity
total int64
userToken = contextdata.GetUserTokenFromCtx(l.ctx)
)
// 延迟更新状态
queryOptions := domain.NewQueryOptions().WithFindOnly().WithKV("inStatus", []int{domain.ActivityWaiting, domain.ActivityOpening})
total, dms, err = l.svcCtx.BsiActivityRepository.Find(l.ctx, conn, userToken.CompanyId, queryOptions)
if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
for _, item := range dms {
if item.NeedClose() {
item.Status = domain.ActivityClosed
if item, err = l.svcCtx.BsiActivityRepository.UpdateWithVersion(l.ctx, conn, item); err != nil {
return err
}
}
}
return nil
}, true); err != nil {
return nil, xerr.NewErrMsg("保存失败")
}
queryOptions = domain.NewQueryOptions().WithOffsetLimit(req.Page, req.Size)
if req.Page > 0 {
queryOptions.WithOffsetLimit(req.Page, req.Size)
}
if req.Status != nil {
queryOptions.WithKV("status", req.Status)
}
total, dms, err = l.svcCtx.BsiActivityRepository.Find(l.ctx, conn, userToken.CompanyId, queryOptions)
list := make([]types.ActivityItem, 0)
for i := range dms {
item := NewTypesBsiActivity(dms[i])
item.ActivityConfig = domain.ActivityConfig{}
list = append(list, item)
}
resp = &types.ActivitySearchResponse{
List: list,
Total: total,
}
return
}
... ...
package activity
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type SystemActivitySubmissionDataExportLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSystemActivitySubmissionDataExportLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemActivitySubmissionDataExportLogic {
return &SystemActivitySubmissionDataExportLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *SystemActivitySubmissionDataExportLogic) SystemActivitySubmissionDataExport(req *types.SubmissionDataSearchRequest) (resp *types.SubmissionDataSearchResponse, err error) {
// todo: add your logic here and delete this line
return
}
... ...
package activity
import (
"context"
"fmt"
"github.com/samber/lo"
"github.com/zeromicro/go-zero/core/collection"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type SystemActivitySubmissionDataSearchLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSystemActivitySubmissionDataSearchLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemActivitySubmissionDataSearchLogic {
return &SystemActivitySubmissionDataSearchLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *SystemActivitySubmissionDataSearchLogic) SystemActivitySubmissionDataSearch(req *types.SubmissionDataSearchRequest) (resp *types.SubmissionDataSearchResponse, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
dms []*domain.BsiActivityQuestionnaireSubmitRecord
total int64
userToken = contextdata.GetUserTokenFromCtx(l.ctx)
)
queryOptions := domain.NewQueryOptions().WithFindOnly().
MustWithKV("activityId", req.ActivityId).MustWithKV("companyId", userToken.CompanyId).
WithKV("name", req.Name).
WithKV("product", req.Product).
WithKV("amountFrom", req.AmountFrom).
WithKV("amountTo", req.AmountTo)
total, dms, err = l.svcCtx.BsiActivityQuestionnaireSubmitRecordRepository.Find(l.ctx, conn, queryOptions)
list := make([]types.SubmissionItem, 0)
set := collection.NewSet()
for i := range dms {
item := NewTypesSubmissionItem(dms[i])
k := keySubmission(item)
if !set.Contains(k) {
set.Add(k)
} else {
item.IsRepeat = true
}
// 重复性条件过滤
if req.IsRepeat != nil && item.IsRepeat != *req.IsRepeat {
continue
}
// 目标ID过滤
if len(req.SelectIdList) > 0 {
if !lo.Contains(req.SelectIdList, dms[i].Id) {
continue
}
}
list = append(list, item)
}
resp = &types.SubmissionDataSearchResponse{
List: lo.Slice(list, req.Size*(req.Page-1), req.Page*req.Size),
Total: total,
}
return
}
func keySubmission(item types.SubmissionItem) string {
return fmt.Sprintf("%v-%v", item.Name, item.Product)
}
func NewTypesSubmissionItem(item *domain.BsiActivityQuestionnaireSubmitRecord) types.SubmissionItem {
return types.SubmissionItem{
Name: item.Name,
Title: item.User.Title,
Avatar: item.User.Avatar,
Product: item.Product,
Amount: item.Amount,
Greeting: item.Greeting,
Time: item.CreatedAt,
}
}
... ...
package activity
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/pkg/transaction"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/pkg/xerr"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type SystemActivityUpdateLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSystemActivityUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemActivityUpdateLogic {
return &SystemActivityUpdateLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *SystemActivityUpdateLogic) SystemActivityUpdate(req *types.ActivityUpdateRequest) (resp *types.ActivityUpdateResponse, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
dm *domain.BsiActivity
)
if err = req.Activity.Valid(); err != nil {
return nil, xerr.NewErrMsg(err.Error())
}
if dm, err = l.svcCtx.BsiActivityRepository.FindOne(l.ctx, conn, req.Id); err != nil {
return nil, xerr.NewErrMsgErr("不存在", err)
}
// 不可编辑判断
if dm.IsOpen() {
return nil, xerr.NewErrMsg("活动已经开启不可编辑")
}
// 赋值
dm.Issue = req.Activity.Issue
dm.Remark = req.Activity.Remark
dm.ActivateType = req.Activity.ActivateType
dm.BeginAt = req.Activity.BeginAt
dm.EndAt = req.Activity.EndAt
dm.ActivityConfig = req.Activity.ActivityConfig
// 更新
if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
dm, err = l.svcCtx.BsiActivityRepository.UpdateWithVersion(l.ctx, conn, dm)
return err
}, true); err != nil {
return nil, xerr.NewErrMsg("更新失败")
}
resp = &types.ActivityUpdateResponse{}
return
}
... ...
package middleware
import "net/http"
type LogRequestMiddleware struct {
}
func NewLogRequestMiddleware() *LogRequestMiddleware {
return &LogRequestMiddleware{}
}
func (m *LogRequestMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
// TODO generate middleware implement function, delete after code implementation
// Passthrough to next handler if need
next(w, r)
}
}
... ...
... ... @@ -4,12 +4,16 @@ import (
"github.com/zeromicro/go-zero/core/stores/redis"
"github.com/zeromicro/go-zero/rest"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/api/internal/config"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/interanl/pkg/db/repository"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/pkg/cache"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/pkg/database"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/pkg/gateway"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/pkg/gateway/authlib"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/pkg/gateway/openlib"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/pkg/gateway/smslib"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/pkg/middleware"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/pkg/transaction"
"gorm.io/gorm"
)
... ... @@ -17,19 +21,19 @@ type ServiceContext struct {
Config config.Config
DB *gorm.DB
Redis *redis.Redis
LogRequest rest.Middleware
LoginStatusCheck rest.Middleware
ApiAuthService authlib.ApiAuthService
SmsService smslib.SMSService
OpenApiService openlib.OpenApiService
BsiActivityRepository domain.BsiActivityRepository
BsiActivityQuestionnaireSubmitRecordRepository domain.BsiActivityQuestionnaireSubmitRecordRepository
}
func NewServiceContext(c config.Config) *ServiceContext {
db := database.OpenGormPGDB(c.DB.DataSource, c.Log.Mode)
//mlCache := cache.NewMultiLevelCache([]string{c.Redis.Host}, c.Redis.Pass)
mlCache := cache.NewMultiLevelCache([]string{c.Redis.Host}, c.Redis.Pass)
redis, _ := redis.NewRedis(redis.RedisConf{Host: c.Redis.Host, Pass: c.Redis.Pass, Type: "node"})
apiAuth := authlib.ApiAuthService{
Service: gateway.NewService(c.ApiAuth.Name, c.ApiAuth.Host, c.ApiAuth.Timeout),
... ... @@ -41,5 +45,12 @@ func NewServiceContext(c config.Config) *ServiceContext {
Redis: redis,
ApiAuthService: apiAuth,
LogRequest: middleware.NewLogRequestMiddleware(c.LogRequest).Handle,
LoginStatusCheck: middleware.NewLoginStatusCheckMiddleware(apiAuth).Handle,
BsiActivityRepository: repository.NewBsiActivityRepository(cache.NewCachedRepository(mlCache)),
BsiActivityQuestionnaireSubmitRecordRepository: repository.NewBsiActivityQuestionnaireSubmitRecordRepository(cache.NewCachedRepository(mlCache)),
}
}
func (svc *ServiceContext) DefaultDBConn() transaction.Conn {
return transaction.NewTransactionContext(svc.DB)
}
... ...
... ... @@ -13,6 +13,72 @@ type MiniQrCodeRequest struct {
Scene string `json:"scene"` // 参数
}
type ActivityOpenRequest struct {
Id int64 `json:"id"` // 唯一标识
}
type ActivityOpenResponse struct {
}
type ActivityCloseRequest struct {
Id int64 `json:"id"` // 唯一标识
}
type ActivityCloseResponse struct {
}
type QuestionnaireSubmitRequest struct {
Id int64 `json:"id"` // 活动ID
FormList []QuestionItem `json:"formList"` // 表单列表
}
type QuestionnaireSubmitResponse struct {
}
type SubmissionDataSearchRequest struct {
Page int `json:"page"`
Size int `json:"size"`
ActivityId int64 `json:"activityId,optional"`
Name string `json:"name,optional"`
Product string `json:"product,optional"`
IsRepeat *bool `json:"isRepeat,optional"` // true:重复的 false:正常
AmountFrom float64 `json:"amountFrom"` // 金额 从多少开始
AmountTo float64 `json:"amountTo"` // 金额 从多少截至
SelectIdList []int64 `json:"selectIdList"` // 选择的数据项
}
type SubmissionDataSearchResponse struct {
List []SubmissionItem `json:"list"`
Total int64 `json:"total"`
}
type PullSubmissionRequest struct {
Id int64 `json:"id"` // 活动ID
Timestamp int64 `json:"timestamp"` // 最后一次拉取时间戳,首次为当前时间
}
type PullSubmissionResponse struct {
TotalParticipants int64 `json:"totalParticipants"` // 累计参与人次
List []SubmissionItem `json:"list"`
}
type SubmissionItem struct {
Name string `json:"name"` // 投资人姓名
Title string `json:"title"` // 称谓
Avatar string `json:"avatar"` // 头像
Product string `json:"product"` // 产品
Amount float64 `json:"amount"` // 金额
Greeting string `json:"greeting"` // 祝福
Time int64 `json:"time"` //提报时间
IsRepeat bool `json:"isRepeat"` // 是否重复
}
type QuestionItem struct {
Label string `json:"label"` // 字段名称
Product string `json:"product"` // 商品(非必填)
Value string `json:"value"` // 值
}
type TodoRequest struct {
}
... ...
package types
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/interanl/pkg/domain"
)
type ActivityGetRequest struct {
Id int64 `path:"id"`
}
type ActivityGetResponse struct {
Activity ActivityItem `json:"activity"`
}
type ActivitySaveRequest struct {
Activity ActivityItem `json:"activity"`
}
type ActivitySaveResponse struct {
}
type ActivityDeleteRequest struct {
Id int64 `path:"id"`
}
type ActivityDeleteResponse struct {
}
type ActivityUpdateRequest struct {
Id int64 `path:"id"`
Activity ActivityItem `json:"activity"`
}
type ActivityUpdateResponse struct {
}
type ActivitySearchRequest struct {
Page int `json:"page"`
Size int `json:"size"`
Status *int `json:"status,optional"` // 0:未开始 1:已开始 2:结束
CompanyId int64 `json:"companyId,optional"` // 公司ID
}
type ActivitySearchResponse struct {
List []ActivityItem `json:"list"`
Total int64 `json:"total"`
}
type ActivityItem struct {
Id int64 `json:"id,optional"` // 唯一标识
CompanyId int64 `json:"companyId,optional"` // 公司ID
Issue string `json:"issue"` // 活动主题
Remark string `json:"remark,optional"` // 活动备注
ActivateType int `json:"activateType"` // 激活类型 1:手动 2:指定日期
BeginAt int64 `json:"beginAt,optional"` // 活动开始时间(激活类型:2有效)
EndAt int64 `json:"endAt,optional"` // 活动结束时间(激活类型:2有效)
Status int `json:"status,optional"` // 活动状态 0:未开始 1:已开始 2:结束
ActivityConfig domain.ActivityConfig `json:"activityConfig,optional"` // 活动配置
}
func (item ActivityItem) Valid() error {
if !(item.ActivateType == domain.OpenByManual || item.ActivateType == domain.OpenBySpecificTime) {
return fmt.Errorf("激活类型有误 1:手动 2:指定日期")
}
if item.ActivateType == domain.OpenBySpecificTime {
if item.BeginAt > item.EndAt {
return fmt.Errorf("开始时间不能大于结束时间")
}
if item.BeginAt == 0 {
return fmt.Errorf("开始时间不能为空")
}
if item.EndAt == 0 {
return fmt.Errorf("结束时间不能为空")
}
}
if err := item.ActivityConfig.Valid(); err != nil {
return err
}
return nil
}
//
//type ActivityConfig struct {
// H5Config *H5Config `json:"h5Config"` // H5页面配置
// Products []Product `json:"products,optional"` // 产品列表
// QuestionnaireConfig *QuestionnaireConfig `json:"questionnaireConfig"` // 问卷配置
// ScreenConfig *ScreenConfig `json:"screenConfig"` // 大屏配置
// DefaultUsers []UserInfo `json:"defaultUsers"` // 预设用户(名字不允许重复)
//}
//
//type H5Config struct {
// WebPageTitle string `json:"webPageTitle"` // 网页标题配置
// Announcement string `json:"announcement,optional"` // 公告内容
//}
//
//type Product struct {
// Id string `json:"id,optional"` // 标识
// Name string `json:"name,optional"` // 产品名称
// Cover string `json:"cover,optional"` // 产品封面图片
// Desc string `json:"desc,optional"` // 产品简介
//}
//
//type QuestionnaireConfig struct {
// WebPageTitle string `json:"webPageTitle"` // 网页标题配置
// Announcement string `json:"announcement,optional"` // 公告内容
// Questions []QuestionItem `json:"questions,optional"` // 问题列表
//}
//
//type QuestionItem struct {
// Label string `json:"label"` // 字段名称
// Product string `json:"product,optional"` // 商品(非必填)
// Type int `json:"type"` // 0:文本 1:单选
// CheckList []CheckItem `json:"checkList"`
//}
//
//type CheckItem struct {
// Value string `json:"value"` // 值 例如:500
// ValueType int `json:"valueType,optional"` // 0.人民币
//}
//
//type ScreenConfig struct {
// Background string `json:"background"` // 背景图片
// IsShowInteractiveNum bool `json:"isShowInteractiveNum"` // 是否展示互动数 true:展示 false:不展示
// Greetings []string `json:"greetings"` // 祝福语
//}
//
//type UserInfo struct {
// Name string `json:"name"` // 名称
// Avatar string `json:"avatar,optional"` // 头像
// Title string `json:"title,optional"` // 称谓
//}
... ...
... ... @@ -3,3 +3,15 @@ CREATE TABLE `todo`
`id` int(0) NOT NULL COMMENT '唯一标识',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;
CREATE TABLE `bsi_activity`
(
`id` int(0) NOT NULL COMMENT '唯一标识',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;
CREATE TABLE `bsi_activity_questionnaire_submit_record`
(
`id` int(0) NOT NULL COMMENT '唯一标识',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;
\ No newline at end of file
... ...
... ... @@ -38,5 +38,5 @@ COPY --from=builder /usr/share/zoneinfo/Asia/Shanghai /usr/share/zoneinfo/Asia/S
COPY --from=builder /build/api/${PROJECT} ./
COPY --from=builder /build/cmd/${PROJECTCODE}/api/etc/${CONFIG_FILE} ./etc/
EXPOSE 8080
EXPOSE 8081
ENTRYPOINT ./${PROJECT} -f etc/${CONFIG_FILE}
\ No newline at end of file
... ...
syntax = "v1"
info(
title: "xx实例"
desc: "xx实例"
author: "author"
email: "email"
version: "v1"
)
@server(
prefix: bsi_activity/v1
group: bsi_activity
jwt: JwtAuth
)
service Core {
@doc "详情"
@handler bsi_activityGet
get /bsi_activity/:id (BsiActivityGetRequest) returns (BsiActivityGetResponse)
@doc "保存"
@handler bsi_activitySave
post /bsi_activity (BsiActivitySaveRequest) returns (BsiActivitySaveResponse)
@doc "删除"
@handler bsi_activityDelete
delete /bsi_activity/:id (BsiActivityDeleteRequest) returns (BsiActivityDeleteResponse)
@doc "更新"
@handler bsi_activityUpdate
put /bsi_activity/:id (BsiActivityUpdateRequest) returns (BsiActivityUpdateResponse)
@doc "搜索"
@handler bsi_activitySearch
post /bsi_activity/search (BsiActivitySearchRequest) returns (BsiActivitySearchResponse)
}
type (
BsiActivityGetRequest {
Id int64 `path:"id"`
}
BsiActivityGetResponse struct{
BsiActivity BsiActivityItem `json:"bsi_activity"`
}
BsiActivitySaveRequest struct{
BsiActivity BsiActivityItem `json:"bsi_activity"`
}
BsiActivitySaveResponse struct{}
BsiActivityDeleteRequest struct{
Id int64 `path:"id"`
}
BsiActivityDeleteResponse struct{}
BsiActivityUpdateRequest struct{
Id int64 `path:"id"`
BsiActivity BsiActivityItem `json:"bsi_activity"`
}
BsiActivityUpdateResponse struct{}
BsiActivitySearchRequest struct{
Page int `json:"page"`
Size int `json:"size"`
}
BsiActivitySearchResponse{
List []BsiActivityItem `json:"list"`
Total int64 `json:"total"`
}
BsiActivityItem struct{
}
)
// logic CRUD
// Save
//var (
// conn = l.svcCtx.DefaultDBConn()
// dm *domain.BsiActivity
//)
//// 唯一判断
//dm = NewDomainBsiActivity(req.BsiActivity)
//if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
// dm, err = l.svcCtx.BsiActivityRepository.Insert(l.ctx, conn, dm)
// return err
//}, true); err != nil {
// return nil, xerr.NewErrMsg("保存失败")
//}
////resp = &types.BsiActivitySaveResponse{}
//return
//func NewDomainBsiActivity(item types.BsiActivityItem) *domain.BsiActivity {
// return &domain.BsiActivity{
// }
//}
//
//func NewTypesBsiActivity(item *domain.BsiActivity) types.BsiActivityItem {
// return types.BsiActivityItem{
// Id: item.Id,
// }
//}
// Get
//var (
// conn = l.svcCtx.DefaultDBConn()
// dm *domain.BsiActivity
//)
//// 货号唯一
//if dm, err = l.svcCtx.BsiActivityRepository.FindOne(l.ctx, conn, req.Id); err != nil {
// return nil, xerr.NewErrMsgErr("不存在", err)
//}
//resp = &types.BsiActivityGetResponse{
// BsiActivity: NewTypesBsiActivity(dm),
//}
//return
// Delete
//var (
// conn = l.svcCtx.DefaultDBConn()
// dm *domain.BsiActivity
//)
//if dm, err = l.svcCtx.BsiActivityRepository.FindOne(l.ctx, conn, req.Id); err != nil {
// return nil, xerr.NewErrMsgErr("不存在", err)
//}
//if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
// if dm, err = l.svcCtx.BsiActivityRepository.Delete(l.ctx, conn, dm); err != nil {
// return err
// }
// return nil
//}, true); err != nil {
// return nil, xerr.NewErrMsgErr("移除失败", err)
//}
//return
// Search
//var (
// conn = l.svcCtx.DefaultDBConn()
// dms []*domain.BsiActivity
// total int64
//)
//
//queryOptions := domain.NewQueryOptions().WithOffsetLimit(req.Page, req.Size).
// WithKV("", "")
//total, dms, err = l.svcCtx.BsiActivityRepository.Find(l.ctx, conn, queryOptions)
//list := make([]types.BsiActivityItem, 0)
//for i := range dms {
// list = append(list, NewTypesBsiActivity(dms[i]))
//}
//resp = &types.BsiActivitySearchResponse{
// List: list,
// Total: total,
//}
//return
// Update
//var (
// conn = l.svcCtx.DefaultDBConn()
// dm *domain.BsiActivity
//)
//if dm, err = l.svcCtx.BsiActivityRepository.FindOne(l.ctx, conn, req.Id); err != nil {
// return nil, xerr.NewErrMsgErr("不存在", err)
//}
//// 不可编辑判断
//// 赋值
//// 更新
//if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
// dm, err = l.svcCtx.BsiActivityRepository.UpdateWithVersion(l.ctx, conn, dm)
// return err
//}, true); err != nil {
// return nil, xerr.NewErrMsg("更新失败")
//}
//resp = &types.BsiActivityUpdateResponse{}
//return
... ...
syntax = "v1"
info(
title: "xx实例"
desc: "xx实例"
author: "author"
email: "email"
version: "v1"
)
@server(
prefix: bsi_activity_questionnaire_submit_record/v1
group: bsi_activity_questionnaire_submit_record
jwt: JwtAuth
)
service Core {
@doc "详情"
@handler bsi_activity_questionnaire_submit_recordGet
get /bsi_activity_questionnaire_submit_record/:id (BsiActivityQuestionnaireSubmitRecordGetRequest) returns (BsiActivityQuestionnaireSubmitRecordGetResponse)
@doc "保存"
@handler bsi_activity_questionnaire_submit_recordSave
post /bsi_activity_questionnaire_submit_record (BsiActivityQuestionnaireSubmitRecordSaveRequest) returns (BsiActivityQuestionnaireSubmitRecordSaveResponse)
@doc "删除"
@handler bsi_activity_questionnaire_submit_recordDelete
delete /bsi_activity_questionnaire_submit_record/:id (BsiActivityQuestionnaireSubmitRecordDeleteRequest) returns (BsiActivityQuestionnaireSubmitRecordDeleteResponse)
@doc "更新"
@handler bsi_activity_questionnaire_submit_recordUpdate
put /bsi_activity_questionnaire_submit_record/:id (BsiActivityQuestionnaireSubmitRecordUpdateRequest) returns (BsiActivityQuestionnaireSubmitRecordUpdateResponse)
@doc "搜索"
@handler bsi_activity_questionnaire_submit_recordSearch
post /bsi_activity_questionnaire_submit_record/search (BsiActivityQuestionnaireSubmitRecordSearchRequest) returns (BsiActivityQuestionnaireSubmitRecordSearchResponse)
}
type (
BsiActivityQuestionnaireSubmitRecordGetRequest {
Id int64 `path:"id"`
}
BsiActivityQuestionnaireSubmitRecordGetResponse struct{
BsiActivityQuestionnaireSubmitRecord BsiActivityQuestionnaireSubmitRecordItem `json:"bsi_activity_questionnaire_submit_record"`
}
BsiActivityQuestionnaireSubmitRecordSaveRequest struct{
BsiActivityQuestionnaireSubmitRecord BsiActivityQuestionnaireSubmitRecordItem `json:"bsi_activity_questionnaire_submit_record"`
}
BsiActivityQuestionnaireSubmitRecordSaveResponse struct{}
BsiActivityQuestionnaireSubmitRecordDeleteRequest struct{
Id int64 `path:"id"`
}
BsiActivityQuestionnaireSubmitRecordDeleteResponse struct{}
BsiActivityQuestionnaireSubmitRecordUpdateRequest struct{
Id int64 `path:"id"`
BsiActivityQuestionnaireSubmitRecord BsiActivityQuestionnaireSubmitRecordItem `json:"bsi_activity_questionnaire_submit_record"`
}
BsiActivityQuestionnaireSubmitRecordUpdateResponse struct{}
BsiActivityQuestionnaireSubmitRecordSearchRequest struct{
Page int `json:"page"`
Size int `json:"size"`
}
BsiActivityQuestionnaireSubmitRecordSearchResponse{
List []BsiActivityQuestionnaireSubmitRecordItem `json:"list"`
Total int64 `json:"total"`
}
BsiActivityQuestionnaireSubmitRecordItem struct{
}
)
// logic CRUD
// Save
//var (
// conn = l.svcCtx.DefaultDBConn()
// dm *domain.BsiActivityQuestionnaireSubmitRecord
//)
//// 唯一判断
//dm = NewDomainBsiActivityQuestionnaireSubmitRecord(req.BsiActivityQuestionnaireSubmitRecord)
//if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
// dm, err = l.svcCtx.BsiActivityQuestionnaireSubmitRecordRepository.Insert(l.ctx, conn, dm)
// return err
//}, true); err != nil {
// return nil, xerr.NewErrMsg("保存失败")
//}
////resp = &types.BsiActivityQuestionnaireSubmitRecordSaveResponse{}
//return
//func NewDomainBsiActivityQuestionnaireSubmitRecord(item types.BsiActivityQuestionnaireSubmitRecordItem) *domain.BsiActivityQuestionnaireSubmitRecord {
// return &domain.BsiActivityQuestionnaireSubmitRecord{
// }
//}
//
//func NewTypesBsiActivityQuestionnaireSubmitRecord(item *domain.BsiActivityQuestionnaireSubmitRecord) types.BsiActivityQuestionnaireSubmitRecordItem {
// return types.BsiActivityQuestionnaireSubmitRecordItem{
// Id: item.Id,
// }
//}
// Get
//var (
// conn = l.svcCtx.DefaultDBConn()
// dm *domain.BsiActivityQuestionnaireSubmitRecord
//)
//// 货号唯一
//if dm, err = l.svcCtx.BsiActivityQuestionnaireSubmitRecordRepository.FindOne(l.ctx, conn, req.Id); err != nil {
// return nil, xerr.NewErrMsgErr("不存在", err)
//}
//resp = &types.BsiActivityQuestionnaireSubmitRecordGetResponse{
// BsiActivityQuestionnaireSubmitRecord: NewTypesBsiActivityQuestionnaireSubmitRecord(dm),
//}
//return
// Delete
//var (
// conn = l.svcCtx.DefaultDBConn()
// dm *domain.BsiActivityQuestionnaireSubmitRecord
//)
//if dm, err = l.svcCtx.BsiActivityQuestionnaireSubmitRecordRepository.FindOne(l.ctx, conn, req.Id); err != nil {
// return nil, xerr.NewErrMsgErr("不存在", err)
//}
//if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
// if dm, err = l.svcCtx.BsiActivityQuestionnaireSubmitRecordRepository.Delete(l.ctx, conn, dm); err != nil {
// return err
// }
// return nil
//}, true); err != nil {
// return nil, xerr.NewErrMsgErr("移除失败", err)
//}
//return
// Search
//var (
// conn = l.svcCtx.DefaultDBConn()
// dms []*domain.BsiActivityQuestionnaireSubmitRecord
// total int64
//)
//
//queryOptions := domain.NewQueryOptions().WithOffsetLimit(req.Page, req.Size).
// WithKV("", "")
//total, dms, err = l.svcCtx.BsiActivityQuestionnaireSubmitRecordRepository.Find(l.ctx, conn, queryOptions)
//list := make([]types.BsiActivityQuestionnaireSubmitRecordItem, 0)
//for i := range dms {
// list = append(list, NewTypesBsiActivityQuestionnaireSubmitRecord(dms[i]))
//}
//resp = &types.BsiActivityQuestionnaireSubmitRecordSearchResponse{
// List: list,
// Total: total,
//}
//return
// Update
//var (
// conn = l.svcCtx.DefaultDBConn()
// dm *domain.BsiActivityQuestionnaireSubmitRecord
//)
//if dm, err = l.svcCtx.BsiActivityQuestionnaireSubmitRecordRepository.FindOne(l.ctx, conn, req.Id); err != nil {
// return nil, xerr.NewErrMsgErr("不存在", err)
//}
//// 不可编辑判断
//// 赋值
//// 更新
//if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
// dm, err = l.svcCtx.BsiActivityQuestionnaireSubmitRecordRepository.UpdateWithVersion(l.ctx, conn, dm)
// return err
//}, true); err != nil {
// return nil, xerr.NewErrMsg("更新失败")
//}
//resp = &types.BsiActivityQuestionnaireSubmitRecordUpdateResponse{}
//return
... ...
syntax = "proto3";
option go_package ="./pb";
package pb;
message BsiActivityGetReq {
int64 Id = 1;
}
message BsiActivityGetResp{
BsiActivityItem User = 1;
}
message BsiActivitySaveReq {
}
message BsiActivitySaveResp{
}
message BsiActivityDeleteReq {
int64 Id = 1;
}
message BsiActivityDeleteResp{
}
message BsiActivityUpdateReq {
int64 Id = 1;
}
message BsiActivityUpdateResp{
}
message BsiActivitySearchReq {
int64 PageNumber = 1;
int64 PageSize = 2;
}
message BsiActivitySearchResp{
repeated BsiActivityItem List =1;
int64 Total =2;
}
message BsiActivityItem {
}
service BsiActivityService {
rpc BsiActivityGet(BsiActivityGetReq) returns(BsiActivityGetResp);
rpc BsiActivitySave(BsiActivitySaveReq) returns(BsiActivitySaveResp);
rpc BsiActivityDelete(BsiActivityDeleteReq) returns(BsiActivityDeleteResp);
rpc BsiActivityUpdate(BsiActivityUpdateReq) returns(BsiActivityUpdateResp);
rpc BsiActivitySearch(BsiActivitySearchReq) returns(BsiActivitySearchResp);
}
... ...
syntax = "proto3";
option go_package ="./pb";
package pb;
message BsiActivityQuestionnaireSubmitRecordGetReq {
int64 Id = 1;
}
message BsiActivityQuestionnaireSubmitRecordGetResp{
BsiActivityQuestionnaireSubmitRecordItem User = 1;
}
message BsiActivityQuestionnaireSubmitRecordSaveReq {
}
message BsiActivityQuestionnaireSubmitRecordSaveResp{
}
message BsiActivityQuestionnaireSubmitRecordDeleteReq {
int64 Id = 1;
}
message BsiActivityQuestionnaireSubmitRecordDeleteResp{
}
message BsiActivityQuestionnaireSubmitRecordUpdateReq {
int64 Id = 1;
}
message BsiActivityQuestionnaireSubmitRecordUpdateResp{
}
message BsiActivityQuestionnaireSubmitRecordSearchReq {
int64 PageNumber = 1;
int64 PageSize = 2;
}
message BsiActivityQuestionnaireSubmitRecordSearchResp{
repeated BsiActivityQuestionnaireSubmitRecordItem List =1;
int64 Total =2;
}
message BsiActivityQuestionnaireSubmitRecordItem {
}
service BsiActivityQuestionnaireSubmitRecordService {
rpc BsiActivityQuestionnaireSubmitRecordGet(BsiActivityQuestionnaireSubmitRecordGetReq) returns(BsiActivityQuestionnaireSubmitRecordGetResp);
rpc BsiActivityQuestionnaireSubmitRecordSave(BsiActivityQuestionnaireSubmitRecordSaveReq) returns(BsiActivityQuestionnaireSubmitRecordSaveResp);
rpc BsiActivityQuestionnaireSubmitRecordDelete(BsiActivityQuestionnaireSubmitRecordDeleteReq) returns(BsiActivityQuestionnaireSubmitRecordDeleteResp);
rpc BsiActivityQuestionnaireSubmitRecordUpdate(BsiActivityQuestionnaireSubmitRecordUpdateReq) returns(BsiActivityQuestionnaireSubmitRecordUpdateResp);
rpc BsiActivityQuestionnaireSubmitRecordSearch(BsiActivityQuestionnaireSubmitRecordSearchReq) returns(BsiActivityQuestionnaireSubmitRecordSearchResp);
}
... ...
package db
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/interanl/pkg/db/models"
"gorm.io/gorm"
)
func Migrate(db *gorm.DB) {
db.AutoMigrate()
db.AutoMigrate(&models.BsiActivity{}, &models.BsiActivityQuestionnaireSubmitRecord{})
}
... ...
package models
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/interanl/pkg/domain"
"gorm.io/gorm"
"gorm.io/plugin/soft_delete"
"time"
)
type BsiActivity struct {
Id int64 // 唯一标识
CompanyId int64 // 公司ID
Issue string // 活动主题
Remark string // 活动备注
ActivateType int // 激活类型 1:手动 2:指定日期
BeginAt int64 // 活动开始时间(激活类型:2有效)
EndAt int64 // 活动结束时间(激活类型:2有效)
Status int // 活动状态 0:未开始 1:已开始 2:结束
ActivityConfig domain.ActivityConfig `gorm:"type:jsonb;serializer:json"` // 活动配置
CreatedAt int64
UpdatedAt int64
IsDel soft_delete.DeletedAt `gorm:"softDelete:flag,DeletedAtField:DeletedAt"`
DeletedAt int64
Version int
}
func (m *BsiActivity) TableName() string {
return "bsi_activity"
}
func (m *BsiActivity) BeforeCreate(tx *gorm.DB) (err error) {
m.CreatedAt = time.Now().Unix()
m.UpdatedAt = time.Now().Unix()
return
}
func (m *BsiActivity) BeforeUpdate(tx *gorm.DB) (err error) {
m.UpdatedAt = time.Now().Unix()
return
}
func (m *BsiActivity) CacheKeyFunc() string {
if m.Id == 0 {
return ""
}
return fmt.Sprintf("%v:cache:%v:id:%v", domain.ProjectName, m.TableName(), m.Id)
}
func (m *BsiActivity) CacheKeyFuncByObject(obj interface{}) string {
if v, ok := obj.(*BsiActivity); ok {
return v.CacheKeyFunc()
}
return ""
}
func (m *BsiActivity) CachePrimaryKeyFunc() string {
if len("") == 0 {
return ""
}
return fmt.Sprintf("%v:cache:%v:primarykey:%v", domain.ProjectName, m.TableName(), "key")
}
... ...
package models
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/interanl/pkg/domain"
"gorm.io/gorm"
"gorm.io/plugin/soft_delete"
"time"
)
type BsiActivityQuestionnaireSubmitRecord struct {
Id int64 // 唯一标识
CompanyId int64 // 公司ID
ActivityId int64 // 活动ID
Name string // 提交人名字
Product string // 商品
Amount float64 // 金额
User domain.UserInfo `gorm:"type:jsonb;serializer:json"` // 提交人
Greeting string // 祝福
CreatedAt int64
UpdatedAt int64
IsDel soft_delete.DeletedAt `gorm:"softDelete:flag,DeletedAtField:DeletedAt"`
DeletedAt int64
Version int
}
func (m *BsiActivityQuestionnaireSubmitRecord) TableName() string {
return "bsi_activity_questionnaire_submit_record"
}
func (m *BsiActivityQuestionnaireSubmitRecord) BeforeCreate(tx *gorm.DB) (err error) {
m.CreatedAt = time.Now().Unix()
m.UpdatedAt = time.Now().Unix()
return
}
func (m *BsiActivityQuestionnaireSubmitRecord) BeforeUpdate(tx *gorm.DB) (err error) {
m.UpdatedAt = time.Now().Unix()
return
}
func (m *BsiActivityQuestionnaireSubmitRecord) CacheKeyFunc() string {
return ""
//if m.Id == 0 {
// return ""
//}
//return fmt.Sprintf("%v:cache:%v:id:%v", domain.ProjectName, m.TableName(), m.Id)
}
func (m *BsiActivityQuestionnaireSubmitRecord) CacheKeyFuncByObject(obj interface{}) string {
if v, ok := obj.(*BsiActivityQuestionnaireSubmitRecord); ok {
return v.CacheKeyFunc()
}
return ""
}
func (m *BsiActivityQuestionnaireSubmitRecord) CachePrimaryKeyFunc() string {
if len("") == 0 {
return ""
}
return fmt.Sprintf("%v:cache:%v:primarykey:%v", domain.ProjectName, m.TableName(), "key")
}
... ...
package repository
import (
"context"
"fmt"
"github.com/jinzhu/copier"
"github.com/pkg/errors"
"github.com/tiptok/gocomm/pkg/cache"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/interanl/pkg/db/models"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/pkg/transaction"
"gorm.io/gorm"
)
type BsiActivityQuestionnaireSubmitRecordRepository struct {
*cache.CachedRepository
}
func (repository *BsiActivityQuestionnaireSubmitRecordRepository) Insert(ctx context.Context, conn transaction.Conn, dm *domain.BsiActivityQuestionnaireSubmitRecord) (*domain.BsiActivityQuestionnaireSubmitRecord, error) {
var (
err error
m = &models.BsiActivityQuestionnaireSubmitRecord{}
tx = conn.DB()
)
if m, err = repository.DomainModelToModel(dm); err != nil {
return nil, err
}
if tx = tx.Model(m).Save(m); tx.Error != nil {
return nil, tx.Error
}
dm.Id = m.Id
return repository.ModelToDomainModel(m)
}
func (repository *BsiActivityQuestionnaireSubmitRecordRepository) Update(ctx context.Context, conn transaction.Conn, dm *domain.BsiActivityQuestionnaireSubmitRecord) (*domain.BsiActivityQuestionnaireSubmitRecord, error) {
var (
err error
m *models.BsiActivityQuestionnaireSubmitRecord
tx = conn.DB()
)
if m, err = repository.DomainModelToModel(dm); err != nil {
return nil, err
}
queryFunc := func() (interface{}, error) {
tx = tx.Model(m).Updates(m)
return nil, tx.Error
}
if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil {
return nil, err
}
return repository.ModelToDomainModel(m)
}
func (repository *BsiActivityQuestionnaireSubmitRecordRepository) UpdateWithVersion(ctx context.Context, transaction transaction.Conn, dm *domain.BsiActivityQuestionnaireSubmitRecord) (*domain.BsiActivityQuestionnaireSubmitRecord, error) {
var (
err error
m *models.BsiActivityQuestionnaireSubmitRecord
tx = transaction.DB()
)
if m, err = repository.DomainModelToModel(dm); err != nil {
return nil, err
}
oldVersion := dm.Version
m.Version += 1
queryFunc := func() (interface{}, error) {
tx = tx.Model(m).Select("*").Where("id = ?", m.Id).Where("version = ?", oldVersion).Updates(m)
if tx.RowsAffected == 0 {
return nil, domain.ErrUpdateFail
}
return nil, tx.Error
}
if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil {
return nil, err
}
return repository.ModelToDomainModel(m)
}
func (repository *BsiActivityQuestionnaireSubmitRecordRepository) Delete(ctx context.Context, conn transaction.Conn, dm *domain.BsiActivityQuestionnaireSubmitRecord) (*domain.BsiActivityQuestionnaireSubmitRecord, error) {
var (
tx = conn.DB()
m = &models.BsiActivityQuestionnaireSubmitRecord{Id: dm.Identify().(int64)}
)
queryFunc := func() (interface{}, error) {
tx = tx.Where("id = ?", m.Id).Delete(m)
return m, tx.Error
}
if _, err := repository.Query(queryFunc, m.CacheKeyFunc()); err != nil {
return dm, err
}
return repository.ModelToDomainModel(m)
}
func (repository *BsiActivityQuestionnaireSubmitRecordRepository) FindOne(ctx context.Context, conn transaction.Conn, id int64) (*domain.BsiActivityQuestionnaireSubmitRecord, error) {
var (
err error
tx = conn.DB()
m = new(models.BsiActivityQuestionnaireSubmitRecord)
)
queryFunc := func() (interface{}, error) {
tx = tx.Model(m).Where("id = ?", id).First(m)
if errors.Is(tx.Error, gorm.ErrRecordNotFound) {
return nil, domain.ErrNotFound
}
return m, tx.Error
}
cacheModel := new(models.BsiActivityQuestionnaireSubmitRecord)
cacheModel.Id = id
if err = repository.QueryCache(cacheModel.CacheKeyFunc, m, queryFunc); err != nil {
return nil, err
}
return repository.ModelToDomainModel(m)
}
func (repository *BsiActivityQuestionnaireSubmitRecordRepository) Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*domain.BsiActivityQuestionnaireSubmitRecord, error) {
var (
tx = conn.DB()
ms []*models.BsiActivityQuestionnaireSubmitRecord
dms = make([]*domain.BsiActivityQuestionnaireSubmitRecord, 0)
total int64
)
queryFunc := func() (interface{}, error) {
tx = tx.Model(&ms).Order("id desc")
if v, ok := queryOptions["activityId"]; ok {
tx.Where("activity_id = ? ", v)
}
// 列表查询条件
if v, ok := queryOptions["name"]; ok {
tx.Where("name like ? ", fmt.Sprintf("%%%v%%", v))
}
if v, ok := queryOptions["product"]; ok {
tx.Where("product like ? ", fmt.Sprintf("%%%v%%", v))
}
if v, ok := queryOptions["amountFrom"]; ok {
tx.Where("amount >= ? ", v)
}
if v, ok := queryOptions["amountTo"]; ok {
tx.Where("amount < ? ", v)
}
if v, ok := queryOptions["timestamp"]; ok {
tx.Where("created_at > ? ", v)
}
if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
return dms, tx.Error
}
return dms, nil
}
if _, err := repository.Query(queryFunc); err != nil {
return 0, nil, err
}
for _, item := range ms {
if dm, err := repository.ModelToDomainModel(item); err != nil {
return 0, dms, err
} else {
dms = append(dms, dm)
}
}
return total, dms, nil
}
func (repository *BsiActivityQuestionnaireSubmitRecordRepository) ModelToDomainModel(from *models.BsiActivityQuestionnaireSubmitRecord) (*domain.BsiActivityQuestionnaireSubmitRecord, error) {
to := &domain.BsiActivityQuestionnaireSubmitRecord{}
err := copier.Copy(to, from)
return to, err
}
func (repository *BsiActivityQuestionnaireSubmitRecordRepository) DomainModelToModel(from *domain.BsiActivityQuestionnaireSubmitRecord) (*models.BsiActivityQuestionnaireSubmitRecord, error) {
to := &models.BsiActivityQuestionnaireSubmitRecord{}
err := copier.Copy(to, from)
return to, err
}
func NewBsiActivityQuestionnaireSubmitRecordRepository(cache *cache.CachedRepository) domain.BsiActivityQuestionnaireSubmitRecordRepository {
return &BsiActivityQuestionnaireSubmitRecordRepository{CachedRepository: cache}
}
... ...
package repository
import (
"context"
"github.com/jinzhu/copier"
"github.com/pkg/errors"
"github.com/tiptok/gocomm/pkg/cache"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/interanl/pkg/db/models"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/cmd/bsi/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/pkg/transaction"
"gorm.io/gorm"
)
type BsiActivityRepository struct {
*cache.CachedRepository
}
func (repository *BsiActivityRepository) Insert(ctx context.Context, conn transaction.Conn, dm *domain.BsiActivity) (*domain.BsiActivity, error) {
var (
err error
m = &models.BsiActivity{}
tx = conn.DB()
)
if m, err = repository.DomainModelToModel(dm); err != nil {
return nil, err
}
if tx = tx.Model(m).Save(m); tx.Error != nil {
return nil, tx.Error
}
dm.Id = m.Id
return repository.ModelToDomainModel(m)
}
func (repository *BsiActivityRepository) Update(ctx context.Context, conn transaction.Conn, dm *domain.BsiActivity) (*domain.BsiActivity, error) {
var (
err error
m *models.BsiActivity
tx = conn.DB()
)
if m, err = repository.DomainModelToModel(dm); err != nil {
return nil, err
}
queryFunc := func() (interface{}, error) {
tx = tx.Model(m).Updates(m)
return nil, tx.Error
}
if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil {
return nil, err
}
return repository.ModelToDomainModel(m)
}
func (repository *BsiActivityRepository) UpdateWithVersion(ctx context.Context, transaction transaction.Conn, dm *domain.BsiActivity) (*domain.BsiActivity, error) {
var (
err error
m *models.BsiActivity
tx = transaction.DB()
)
if m, err = repository.DomainModelToModel(dm); err != nil {
return nil, err
}
oldVersion := dm.Version
m.Version += 1
queryFunc := func() (interface{}, error) {
tx = tx.Model(m).Select("*").Where("id = ?", m.Id).Where("version = ?", oldVersion).Updates(m)
if tx.RowsAffected == 0 {
return nil, domain.ErrUpdateFail
}
return nil, tx.Error
}
if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil {
return nil, err
}
return repository.ModelToDomainModel(m)
}
func (repository *BsiActivityRepository) Delete(ctx context.Context, conn transaction.Conn, dm *domain.BsiActivity) (*domain.BsiActivity, error) {
var (
tx = conn.DB()
m = &models.BsiActivity{Id: dm.Identify().(int64)}
)
queryFunc := func() (interface{}, error) {
tx = tx.Where("id = ?", m.Id).Delete(m)
return m, tx.Error
}
if _, err := repository.Query(queryFunc, m.CacheKeyFunc()); err != nil {
return dm, err
}
return repository.ModelToDomainModel(m)
}
func (repository *BsiActivityRepository) FindOne(ctx context.Context, conn transaction.Conn, id int64) (*domain.BsiActivity, error) {
var (
err error
tx = conn.DB()
m = new(models.BsiActivity)
)
queryFunc := func() (interface{}, error) {
tx = tx.Model(m).Where("id = ?", id).First(m)
if errors.Is(tx.Error, gorm.ErrRecordNotFound) {
return nil, domain.ErrNotFound
}
return m, tx.Error
}
cacheModel := new(models.BsiActivity)
cacheModel.Id = id
if err = repository.QueryCache(cacheModel.CacheKeyFunc, m, queryFunc); err != nil {
return nil, err
}
return repository.ModelToDomainModel(m)
}
func (repository *BsiActivityRepository) Find(ctx context.Context, conn transaction.Conn, companyId int64, queryOptions map[string]interface{}) (int64, []*domain.BsiActivity, error) {
var (
tx = conn.DB()
ms []*models.BsiActivity
dms = make([]*domain.BsiActivity, 0)
total int64
)
queryFunc := func() (interface{}, error) {
tx = tx.Model(&ms).Order("id desc")
tx.Where("company_id = ?", companyId)
if v, ok := queryOptions["status"]; ok {
tx.Where("status = ?", v)
}
if v, ok := queryOptions["inStatus"]; ok {
tx.Where("status in (?)", v)
}
if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
return dms, tx.Error
}
return dms, nil
}
if _, err := repository.Query(queryFunc); err != nil {
return 0, nil, err
}
for _, item := range ms {
if dm, err := repository.ModelToDomainModel(item); err != nil {
return 0, dms, err
} else {
dms = append(dms, dm)
}
}
return total, dms, nil
}
func (repository *BsiActivityRepository) ModelToDomainModel(from *models.BsiActivity) (*domain.BsiActivity, error) {
to := &domain.BsiActivity{}
err := copier.Copy(to, from)
return to, err
}
func (repository *BsiActivityRepository) DomainModelToModel(from *domain.BsiActivity) (*models.BsiActivity, error) {
to := &models.BsiActivity{}
err := copier.Copy(to, from)
return to, err
}
func NewBsiActivityRepository(cache *cache.CachedRepository) domain.BsiActivityRepository {
return &BsiActivityRepository{CachedRepository: cache}
}
... ...
package domain
import (
"context"
"fmt"
"github.com/zeromicro/go-zero/core/collection"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/pkg/transaction"
"math/rand"
"time"
)
type BsiActivity struct {
Id int64 `json:"id,optional"` // 唯一标识
CompanyId int64 `json:"companyId,optional"` // 公司ID
Issue string `json:"issue"` // 活动主题
Remark string `json:"remark,optional"` // 活动备注
ActivateType int `json:"activateType"` // 激活类型 1:手动 2:指定日期
BeginAt int64 `json:"beginAt,optional"` // 活动开始时间(激活类型:2有效)
EndAt int64 `json:"endAt,optional"` // 活动结束时间(激活类型:2有效)
Status int `json:"status,optional"` // 活动状态 0:未开始 1:已开始 2:结束
ActivityConfig ActivityConfig `json:"activityConfig,optional"` // 活动配置
CreatedAt int64
UpdatedAt int64
DeletedAt int64
Version int
}
const (
ActivityWaiting = 0
ActivityOpening = 1
ActivityClosed = 2
)
const (
OpenByManual = 1 // 手动开启
OpenBySpecificTime = 2 // 特定时间
)
type BsiActivityRepository interface {
Insert(ctx context.Context, conn transaction.Conn, dm *BsiActivity) (*BsiActivity, error)
Update(ctx context.Context, conn transaction.Conn, dm *BsiActivity) (*BsiActivity, error)
UpdateWithVersion(ctx context.Context, conn transaction.Conn, dm *BsiActivity) (*BsiActivity, error)
Delete(ctx context.Context, conn transaction.Conn, dm *BsiActivity) (*BsiActivity, error)
FindOne(ctx context.Context, conn transaction.Conn, id int64) (*BsiActivity, error)
Find(ctx context.Context, conn transaction.Conn, companyId int64, queryOptions map[string]interface{}) (int64, []*BsiActivity, error)
}
func (m *BsiActivity) Identify() interface{} {
if m.Id == 0 {
return nil
}
return m.Id
}
func (m *BsiActivity) ResolveActivityStatus() int {
if m.Status == ActivityClosed {
return m.Status
}
if m.IsOpen() {
return ActivityOpening
}
if m.IsClosed() {
return ActivityClosed
}
return m.Status
}
func (m *BsiActivity) IsOpen() bool {
if m.ActivateType == OpenByManual {
if m.Status == ActivityOpening {
return true
}
}
if m.ActivateType == OpenBySpecificTime {
if m.BeginAt <= time.Now().Unix() && m.EndAt > time.Now().Unix() {
return true
}
}
return false
}
func (m *BsiActivity) IsClosed() bool {
if m.NeedClose() {
return true
}
if m.Status == ActivityClosed {
return false
}
return false
}
func (m *BsiActivity) NeedClose() bool {
if m.Status == ActivityClosed {
return false
}
if m.ActivateType == OpenBySpecificTime {
if m.EndAt < time.Now().Unix() {
return true
}
}
return false
}
func (m *BsiActivity) RandomGreeting() string {
if m.ActivityConfig.ScreenConfig == nil {
return ""
}
if len(m.ActivityConfig.ScreenConfig.Greetings) == 0 {
return ""
}
idx := rand.Intn(len(m.ActivityConfig.ScreenConfig.Greetings))
return m.ActivityConfig.ScreenConfig.Greetings[idx]
}
type ActivityConfig struct {
H5Config *H5Config `json:"h5Config"` // H5页面配置
Products []Product `json:"products,optional"` // 产品列表
QuestionnaireConfig *QuestionnaireConfig `json:"questionnaireConfig"` // 问卷配置
ScreenConfig *ScreenConfig `json:"screenConfig"` // 大屏配置
DefaultUsers []UserInfo `json:"defaultUsers"` // 预设用户(名字不允许重复)
}
func (item ActivityConfig) Valid() error {
usersDup := collection.NewSet()
for _, u := range item.DefaultUsers {
if !usersDup.Contains(u.Name) {
usersDup.Add(u.Name)
continue
}
return fmt.Errorf("预设用户名重复`%v`", u.Name)
}
productDup := collection.NewSet()
for _, u := range item.Products {
if !productDup.Contains(u.Name) {
productDup.Add(u.Name)
continue
}
return fmt.Errorf("商品名重复`%v`", u.Name)
}
return nil
}
type H5Config struct {
WebPageTitle string `json:"webPageTitle"` // 网页标题配置
Announcement string `json:"announcement,optional"` // 公告内容
}
type Product struct {
// Id string `json:"id,optional"` // 标识
Name string `json:"name,optional"` // 产品名称
Cover string `json:"cover,optional"` // 产品封面图片
Desc string `json:"desc,optional"` // 产品简介
}
type QuestionnaireConfig struct {
WebPageTitle string `json:"webPageTitle"` // 网页标题配置
Announcement string `json:"announcement,optional"` // 公告内容
Questions []QuestionItem `json:"questions,optional"` // 问题列表
}
type QuestionItem struct {
Label string `json:"label"` // 字段名称
Product string `json:"product,optional"` // 商品(非必填)
Type int `json:"type"` // 0:文本 1:单选
CheckList []CheckItem `json:"checkList"`
}
type CheckItem struct {
Value string `json:"value"` // 值 例如:500
ValueType int `json:"valueType,optional"` // 0.人民币
}
type ScreenConfig struct {
Background string `json:"background"` // 背景图片
IsShowInteractiveNum bool `json:"isShowInteractiveNum"` // 是否展示互动数 true:展示 false:不展示
Greetings []string `json:"greetings"` // 祝福语
}
type UserInfo struct {
Name string `json:"name"` // 名称
Avatar string `json:"avatar,optional"` // 头像
Title string `json:"title,optional"` // 称谓
}
... ...
package domain
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc/pkg/transaction"
)
type BsiActivityQuestionnaireSubmitRecord struct {
Id int64 // 唯一标识
CompanyId int64 // 公司ID
ActivityId int64 // 活动ID
Name string // 提交人名字
Product string // 商品
Amount float64 // 金额
User UserInfo // 提交人
Greeting string // 祝福
CreatedAt int64
UpdatedAt int64
DeletedAt int64
Version int
}
type BsiActivityQuestionnaireSubmitRecordRepository interface {
Insert(ctx context.Context, conn transaction.Conn, dm *BsiActivityQuestionnaireSubmitRecord) (*BsiActivityQuestionnaireSubmitRecord, error)
Update(ctx context.Context, conn transaction.Conn, dm *BsiActivityQuestionnaireSubmitRecord) (*BsiActivityQuestionnaireSubmitRecord, error)
UpdateWithVersion(ctx context.Context, conn transaction.Conn, dm *BsiActivityQuestionnaireSubmitRecord) (*BsiActivityQuestionnaireSubmitRecord, error)
Delete(ctx context.Context, conn transaction.Conn, dm *BsiActivityQuestionnaireSubmitRecord) (*BsiActivityQuestionnaireSubmitRecord, error)
FindOne(ctx context.Context, conn transaction.Conn, id int64) (*BsiActivityQuestionnaireSubmitRecord, error)
Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*BsiActivityQuestionnaireSubmitRecord, error)
}
func (m *BsiActivityQuestionnaireSubmitRecord) Identify() interface{} {
if m.Id == 0 {
return nil
}
return m.Id
}
... ...
... ... @@ -30,6 +30,8 @@ require (
github.com/eapache/go-resiliency v1.3.0 // indirect
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21 // indirect
github.com/eapache/queue v1.1.0 // indirect
github.com/extrame/ole2 v0.0.0-20160812065207-d69429661ad7 // indirect
github.com/extrame/xls v0.0.1 // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/garyburd/redigo v1.6.3 // indirect
... ... @@ -80,6 +82,9 @@ require (
github.com/prometheus/common v0.42.0 // indirect
github.com/prometheus/procfs v0.10.1 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/richardlehane/mscfb v1.0.4 // indirect
github.com/richardlehane/msoleps v1.0.1 // indirect
github.com/samber/lo v1.39.0 // indirect
github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/spf13/afero v1.2.2 // indirect
... ... @@ -87,7 +92,11 @@ require (
github.com/spf13/jwalterweatherman v1.0.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.4.0 // indirect
github.com/tiptok/tab v0.0.0-20220923060916-58c234e99dff // indirect
github.com/ugorji/go/codec v1.1.7 // indirect
github.com/xuri/efp v0.0.0-20220407160117-ad0f7a785be8 // indirect
github.com/xuri/excelize/v2 v2.6.0 // indirect
github.com/xuri/nfp v0.0.0-20220409054826-5e722a1d9e22 // indirect
go.opentelemetry.io/otel v1.14.0 // indirect
go.opentelemetry.io/otel/exporters/jaeger v1.14.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.14.0 // indirect
... ... @@ -101,6 +110,7 @@ require (
go.opentelemetry.io/proto/otlp v0.19.0 // indirect
go.uber.org/automaxprocs v1.5.3 // indirect
golang.org/x/crypto v0.12.0 // indirect
golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17 // indirect
golang.org/x/net v0.14.0 // indirect
golang.org/x/sys v0.11.0 // indirect
golang.org/x/text v0.12.0 // indirect
... ...
... ... @@ -2,8 +2,8 @@ package xerr
import (
"context"
"github.com/samber/lo"
"github.com/zeromicro/go-zero/core/logx"
"google.golang.org/grpc/status"
"net/http"
)
... ... @@ -11,22 +11,15 @@ func ErrorHandlerCtx(ctx context.Context, err error) (int, any) {
//错误返回
var (
errCode = ServerCommonError
errMsg = ""
)
// 自定义错误类型
if codeError, ok := err.(*CodeError); ok {
errCode = codeError.GetErrCode()
} else {
// grpc err错误
var grpcStatus *status.Status
if grpcStatus, ok = status.FromError(err); ok {
grpcCode := int(grpcStatus.Code())
if IsCodeErr(grpcCode) {
errCode = grpcCode
}
}
errMsg = codeError.GetErrMsg()
}
logx.WithContext(ctx).Errorf("【ERROR-HANDLER】 : %+v ", err)
response := Error(errCode, MapErrMsg(errCode))
response := Error(int(errCode), lo.Ternary(errMsg != "", errMsg, MapErrMsg(errCode)))
response.Error = err.Error()
return http.StatusOK, response
}
... ...