正在显示
128 个修改的文件
包含
6223 行增加
和
0 行删除
.gitignore
0 → 100644
1 | +# Compiled Object codefiles, Static and Dynamic libs (Shared Objects) | ||
2 | +*.o | ||
3 | +*.a | ||
4 | +*.so | ||
5 | + | ||
6 | +# Folders | ||
7 | +_obj | ||
8 | +_test | ||
9 | + | ||
10 | +# Architecture specific extensions/prefixes | ||
11 | +*.[568vq] | ||
12 | +[568vq].out | ||
13 | + | ||
14 | +*.cgo1.go | ||
15 | +*.cgo2.c | ||
16 | +_cgo_defun.c | ||
17 | +_cgo_gotypes.go | ||
18 | +_cgo_export.* | ||
19 | + | ||
20 | +_testmain.go | ||
21 | + | ||
22 | +*.exe | ||
23 | +*.test | ||
24 | +.log | ||
25 | +.idea | ||
26 | +*.tmp |
Dockerfile
0 → 100644
1 | +FROM golang:latest | ||
2 | +MAINTAINER mmm-go-pp <> | ||
3 | +ENV APP_DIR $GOPATH/src/partner01 | ||
4 | +RUN mkdir -p $APP_DIR | ||
5 | +WORKDIR $APP_DIR/ | ||
6 | +COPY ./pkg pkg | ||
7 | +COPY ./conf conf | ||
8 | +COPY ./go.mod go.mod | ||
9 | +COPY ./go.sum go.sum | ||
10 | +COPY ./main.go main.go | ||
11 | +RUN ["ln","-sf","/usr/share/zoneinfo/Asia/Shanghai","/etc/localtime"] | ||
12 | +ENV GO111MODULE on | ||
13 | +ENV GOPROXY https://goproxy.io | ||
14 | +RUN ["go","mod","tidy"] | ||
15 | +RUN ["ls"] | ||
16 | +RUN ["go","build"] | ||
17 | +ENTRYPOINT ["./partner01"] |
deploy/k8s/dev/install.sh
0 → 100644
1 | +#!/bin/bash | ||
2 | +export PATH=/root/local/bin:$PATH | ||
3 | +kubectl -n <replace-your-k8s-namespace> get pods | grep -q partner01 | ||
4 | +if [ "$?" == "1" ];then | ||
5 | + kubectl create -f /tmp/dev/partner01/partner01.yaml --record | ||
6 | + kubectl -n <replace-your-k8s-namespace> get svc | grep -q partner01 | ||
7 | + if [ "$?" == "0" ];then | ||
8 | + echo "partner01 service install success!" | ||
9 | + else | ||
10 | + echo "partner01 service install fail!" | ||
11 | + fi | ||
12 | + kubectl -n <replace-your-k8s-namespace> get pods | grep -q partner01 | ||
13 | + if [ "$?" == "0" ];then | ||
14 | + echo "partner01 deployment install success!" | ||
15 | + else | ||
16 | + echo "partner01 deployment install fail!" | ||
17 | + fi | ||
18 | +else | ||
19 | + kubectl delete -f /tmp/dev/partner01/partner01.yaml | ||
20 | + kubectl -n <replace-your-k8s-namespace> get svc | grep -q partner01 | ||
21 | + while [ "$?" == "0" ] | ||
22 | + do | ||
23 | + kubectl -n <replace-your-k8s-namespace> get svc | grep -q partner01 | ||
24 | + done | ||
25 | + kubectl -n <replace-your-k8s-namespace> get pods | grep -q partner01 | ||
26 | + while [ "$?" == "0" ] | ||
27 | + do | ||
28 | + kubectl -n <replace-your-k8s-namespace> get pods | grep -q partner01 | ||
29 | + done | ||
30 | + kubectl create -f /tmp/dev/partner01/partner01.yaml --record | ||
31 | + kubectl -n <replace-your-k8s-namespace> get svc | grep -q partner01 | ||
32 | + if [ "$?" == "0" ];then | ||
33 | + echo "partner01 service update success!" | ||
34 | + else | ||
35 | + echo "partner01 service update fail!" | ||
36 | + fi | ||
37 | + kubectl -n <replace-your-k8s-namespace> get pods | grep -q partner01 | ||
38 | + if [ "$?" == "0" ];then | ||
39 | + echo "partner01 deployment update success!" | ||
40 | + else | ||
41 | + echo "partner01 deployment update fail!" | ||
42 | + fi | ||
43 | +fi |
deploy/k8s/dev/partner01.yaml
0 → 100644
1 | +apiVersion: v1 | ||
2 | +kind: Service | ||
3 | +metadata: | ||
4 | + name: partner01 | ||
5 | + namespace: <replace-your-k8s-namespace> | ||
6 | + labels: | ||
7 | + k8s-app: partner01 | ||
8 | +spec: | ||
9 | + ports: | ||
10 | + - name: "http" | ||
11 | + port: 80 | ||
12 | + targetPort: 8082 | ||
13 | + selector: | ||
14 | + k8s-app: partner01 | ||
15 | +--- | ||
16 | +apiVersion: extensions/v1beta1 | ||
17 | +kind: Deployment | ||
18 | +metadata: | ||
19 | + name: partner01 | ||
20 | + namespace: <replace-your-k8s-namespace> | ||
21 | + labels: | ||
22 | + k8s-app: partner01 | ||
23 | +spec: | ||
24 | + replicas: 1 | ||
25 | + template: | ||
26 | + metadata: | ||
27 | + labels: | ||
28 | + k8s-app: partner01 | ||
29 | + spec: | ||
30 | + affinity: | ||
31 | + nodeAffinity: | ||
32 | + preferredDuringSchedulingIgnoredDuringExecution: | ||
33 | + - preference: {} | ||
34 | + weight: 100 | ||
35 | + requiredDuringSchedulingIgnoredDuringExecution: | ||
36 | + nodeSelectorTerms: | ||
37 | + - matchExpressions: | ||
38 | + - key: kubernetes.io/hostname | ||
39 | + operator: In | ||
40 | + values: | ||
41 | + - cn-hangzhou.i-bp1djh1xn7taumbue1ze | ||
42 | + - cn-hangzhou.i-bp1djh1xn7taumbue1zd | ||
43 | + - cn-hangzhou.i-bp1euf5u1ph9kbhtndhb | ||
44 | + - cn-hangzhou.i-bp1hyp5oips9cdwxxgxy | ||
45 | + containers: | ||
46 | + - name: partner01 | ||
47 | + image: 192.168.0.243:5000/mmm/partner01:dev | ||
48 | + imagePullPolicy: Always | ||
49 | + ports: | ||
50 | + - containerPort: 8082 | ||
51 | + volumeMounts: | ||
52 | + - mountPath: /opt/logs | ||
53 | + name: accesslogs | ||
54 | + env: | ||
55 | + - name: LOG_LEVEL | ||
56 | + value: "debug" | ||
57 | + - name: ERROR_BASE_CODE | ||
58 | + value: "1" | ||
59 | + - name: ERROR_BASE_CODE_MULTIPLE | ||
60 | + value: "1000" | ||
61 | + volumes: | ||
62 | + - name: accesslogs | ||
63 | + emptyDir: {} |
go.mod
0 → 100644
1 | +module gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway | ||
2 | + | ||
3 | +go 1.16 | ||
4 | + | ||
5 | +require ( | ||
6 | + github.com/ajg/form v1.5.1 // indirect | ||
7 | + github.com/beego/beego/v2 v2.0.1 | ||
8 | + github.com/dgrijalva/jwt-go v3.2.0+incompatible | ||
9 | + github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072 // indirect | ||
10 | + github.com/fatih/structs v1.1.0 // indirect | ||
11 | + github.com/gavv/httpexpect v2.0.0+incompatible | ||
12 | + github.com/go-pg/pg/v10 v10.9.0 | ||
13 | + github.com/google/go-querystring v1.1.0 // indirect | ||
14 | + github.com/imkira/go-interpol v1.1.0 // indirect | ||
15 | + github.com/linmadan/egglib-go v0.0.0-20210313060205-8b5e456b11f7 | ||
16 | + github.com/mattn/go-colorable v0.1.8 // indirect | ||
17 | + github.com/moul/http2curl v1.0.0 // indirect | ||
18 | + github.com/onsi/ginkgo v1.15.2 | ||
19 | + github.com/onsi/gomega v1.11.0 | ||
20 | + github.com/sergi/go-diff v1.2.0 // indirect | ||
21 | + github.com/smartystreets/goconvey v1.6.4 // indirect | ||
22 | + github.com/tiptok/gocomm v1.0.12 | ||
23 | + github.com/valyala/fasthttp v1.23.0 // indirect | ||
24 | + github.com/xeipuuv/gojsonschema v1.2.0 // indirect | ||
25 | + github.com/yalp/jsonpath v0.0.0-20180802001716-5cc68e5049a0 // indirect | ||
26 | + github.com/yudai/gojsondiff v1.0.0 // indirect | ||
27 | + github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 // indirect | ||
28 | + github.com/yudai/pp v2.0.1+incompatible // indirect | ||
29 | +) | ||
30 | + | ||
31 | +//replace github.com/tiptok/gocomm v1.0.11 => F:\go\src\learn_project\gocomm |
go.sum
0 → 100644
此 diff 太大无法显示。
main.go
0 → 100644
1 | +package main | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/beego/beego/v2/server/web" | ||
5 | + "github.com/tiptok/gocomm/pkg/log" | ||
6 | + _ "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/infrastructure/gateway" | ||
7 | + _ "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/infrastructure/pg" | ||
8 | + _ "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/port/beego" | ||
9 | +) | ||
10 | + | ||
11 | +func main() { | ||
12 | + log.Info("start...") | ||
13 | + web.Run() | ||
14 | +} |
pkg/application/auth/command/access_token.go
0 → 100644
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/beego/beego/v2/core/validation" | ||
7 | +) | ||
8 | + | ||
9 | +type AccessTokenCommand struct { | ||
10 | + // Attribute描述 | ||
11 | + AuthCode string `json:"authCode,omitempty"` | ||
12 | +} | ||
13 | + | ||
14 | +func (accessTokenCommand *AccessTokenCommand) Valid(validation *validation.Validation) { | ||
15 | + | ||
16 | +} | ||
17 | + | ||
18 | +func (accessTokenCommand *AccessTokenCommand) ValidateCommand() error { | ||
19 | + valid := validation.Validation{} | ||
20 | + b, err := valid.Valid(accessTokenCommand) | ||
21 | + if err != nil { | ||
22 | + return err | ||
23 | + } | ||
24 | + if !b { | ||
25 | + for _, validErr := range valid.Errors { | ||
26 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
27 | + } | ||
28 | + } | ||
29 | + return nil | ||
30 | +} |
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/beego/beego/v2/core/validation" | ||
7 | +) | ||
8 | + | ||
9 | +type ChangePasswordCommand struct { | ||
10 | + // 旧密码 | ||
11 | + OldPwd string `json:"oldPwd,omitempty"` | ||
12 | + // 新密码 | ||
13 | + NewPwd string `json:"newPwd,omitempty"` | ||
14 | + // 确认密码 | ||
15 | + ConfirmPwd string `json:"confirmPwd,omitempty"` | ||
16 | + // 手机号 | ||
17 | + Phone string `json:"phone,omitempty"` | ||
18 | +} | ||
19 | + | ||
20 | +func (changePasswordCommand *ChangePasswordCommand) Valid(validation *validation.Validation) { | ||
21 | + | ||
22 | +} | ||
23 | + | ||
24 | +func (changePasswordCommand *ChangePasswordCommand) ValidateCommand() error { | ||
25 | + valid := validation.Validation{} | ||
26 | + b, err := valid.Valid(changePasswordCommand) | ||
27 | + if err != nil { | ||
28 | + return err | ||
29 | + } | ||
30 | + if !b { | ||
31 | + for _, validErr := range valid.Errors { | ||
32 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
33 | + } | ||
34 | + } | ||
35 | + return nil | ||
36 | +} |
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/beego/beego/v2/core/validation" | ||
7 | +) | ||
8 | + | ||
9 | +type LoginByCompanyCommand struct { | ||
10 | + // 1.高管 2.合伙人 4:游客 | ||
11 | + UserType int `json:"userType" valid:"Required"` | ||
12 | + // 凭证 | ||
13 | + Credentials string `json:"credentials" valid:"Required"` | ||
14 | + // 用户id | ||
15 | + UserId int64 `json:"userId" valid:"Required"` | ||
16 | +} | ||
17 | + | ||
18 | +func (loginByCompanyCommand *LoginByCompanyCommand) Valid(validation *validation.Validation) { | ||
19 | + | ||
20 | +} | ||
21 | + | ||
22 | +func (loginByCompanyCommand *LoginByCompanyCommand) ValidateCommand() error { | ||
23 | + valid := validation.Validation{} | ||
24 | + b, err := valid.Valid(loginByCompanyCommand) | ||
25 | + if err != nil { | ||
26 | + return err | ||
27 | + } | ||
28 | + if !b { | ||
29 | + for _, validErr := range valid.Errors { | ||
30 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
31 | + } | ||
32 | + } | ||
33 | + return nil | ||
34 | +} |
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/beego/beego/v2/core/validation" | ||
7 | +) | ||
8 | + | ||
9 | +type RefreshTokenCommand struct { | ||
10 | + // refreshToken | ||
11 | + RefreshToken string `json:"refreshToken,omitempty"` | ||
12 | +} | ||
13 | + | ||
14 | +func (refreshTokenCommand *RefreshTokenCommand) Valid(validation *validation.Validation) { | ||
15 | + | ||
16 | +} | ||
17 | + | ||
18 | +func (refreshTokenCommand *RefreshTokenCommand) ValidateCommand() error { | ||
19 | + valid := validation.Validation{} | ||
20 | + b, err := valid.Valid(refreshTokenCommand) | ||
21 | + if err != nil { | ||
22 | + return err | ||
23 | + } | ||
24 | + if !b { | ||
25 | + for _, validErr := range valid.Errors { | ||
26 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
27 | + } | ||
28 | + } | ||
29 | + return nil | ||
30 | +} |
pkg/application/auth/command/revoke.go
0 → 100644
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/beego/beego/v2/core/validation" | ||
7 | +) | ||
8 | + | ||
9 | +type RevokeCommand struct { | ||
10 | +} | ||
11 | + | ||
12 | +func (revokeCommand *RevokeCommand) Valid(validation *validation.Validation) { | ||
13 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
14 | +} | ||
15 | + | ||
16 | +func (revokeCommand *RevokeCommand) ValidateCommand() error { | ||
17 | + valid := validation.Validation{} | ||
18 | + b, err := valid.Valid(revokeCommand) | ||
19 | + if err != nil { | ||
20 | + return err | ||
21 | + } | ||
22 | + if !b { | ||
23 | + for _, validErr := range valid.Errors { | ||
24 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
25 | + } | ||
26 | + } | ||
27 | + return nil | ||
28 | +} |
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/beego/beego/v2/core/validation" | ||
7 | +) | ||
8 | + | ||
9 | +type SendSmsCodeCommand struct { | ||
10 | + // 手机号 | ||
11 | + Phone string `json:"phone,omitempty"` | ||
12 | +} | ||
13 | + | ||
14 | +func (sendSmsCodeCommand *SendSmsCodeCommand) Valid(validation *validation.Validation) { | ||
15 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
16 | +} | ||
17 | + | ||
18 | +func (sendSmsCodeCommand *SendSmsCodeCommand) ValidateCommand() error { | ||
19 | + valid := validation.Validation{} | ||
20 | + b, err := valid.Valid(sendSmsCodeCommand) | ||
21 | + if err != nil { | ||
22 | + return err | ||
23 | + } | ||
24 | + if !b { | ||
25 | + for _, validErr := range valid.Errors { | ||
26 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
27 | + } | ||
28 | + } | ||
29 | + return nil | ||
30 | +} |
pkg/application/auth/query/login.go
0 → 100644
1 | +package query | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/beego/beego/v2/core/validation" | ||
7 | +) | ||
8 | + | ||
9 | +type LoginQuery struct { | ||
10 | + // 手机号 | ||
11 | + Phone string `json:"phone,omitempty"` | ||
12 | + // signInPassword(密码登录) 或 signInCaptcha(验证码登录)或signInCredentials(凭证登录) | ||
13 | + GrantType string `json:"grantType,omitempty"` | ||
14 | + // 密码(grantType = signInPassword) | ||
15 | + Password string `json:"password,omitempty"` | ||
16 | + // 验证码(grantType = signInCaptcha) | ||
17 | + Captcha string `json:"captcha,omitempty"` | ||
18 | + // 凭证(grantType = signInCredentials) | ||
19 | + Credentials string `json:"credentials,omitempty"` | ||
20 | +} | ||
21 | + | ||
22 | +func (loginQuery *LoginQuery) Valid(validation *validation.Validation) { | ||
23 | + | ||
24 | +} | ||
25 | + | ||
26 | +func (loginQuery *LoginQuery) ValidateQuery() error { | ||
27 | + valid := validation.Validation{} | ||
28 | + b, err := valid.Valid(loginQuery) | ||
29 | + if err != nil { | ||
30 | + return err | ||
31 | + } | ||
32 | + if !b { | ||
33 | + for _, validErr := range valid.Errors { | ||
34 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
35 | + } | ||
36 | + } | ||
37 | + return nil | ||
38 | +} |
pkg/application/auth/service/auth.go
0 → 100644
1 | +package service | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/linmadan/egglib-go/core/application" | ||
5 | + "github.com/tiptok/gocomm/gs" | ||
6 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/application/auth/command" | ||
7 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/application/auth/query" | ||
8 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/infrastructure/gateway" | ||
9 | +) | ||
10 | + | ||
11 | +// 认证服务 | ||
12 | +type AuthService struct { | ||
13 | +} | ||
14 | + | ||
15 | +// 用户按公司登录 | ||
16 | +func (authService *AuthService) AccessToken(accessTokenCommand *command.AccessTokenCommand) (interface{}, error) { | ||
17 | + if err := accessTokenCommand.ValidateCommand(); err != nil { | ||
18 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
19 | + } | ||
20 | + data, err := gateway.Partner01Service.Invoke(gateway.AuthsAccessToken, gs.WithJsonObject(accessTokenCommand)) | ||
21 | + if err != nil { | ||
22 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
23 | + } | ||
24 | + return data.Data, nil | ||
25 | +} | ||
26 | + | ||
27 | +// 修改手机号密码 | ||
28 | +func (authService *AuthService) ChangePassword(changePasswordCommand *command.ChangePasswordCommand) (interface{}, error) { | ||
29 | + if err := changePasswordCommand.ValidateCommand(); err != nil { | ||
30 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
31 | + } | ||
32 | + data, err := gateway.Partner01Service.Invoke(gateway.AuthsChangePhonePassword, gs.WithJsonObject(changePasswordCommand)) | ||
33 | + if err != nil { | ||
34 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
35 | + } | ||
36 | + return data.Data, nil | ||
37 | +} | ||
38 | + | ||
39 | +// 用户登录 返回有权限的公司列表 | ||
40 | +func (authService *AuthService) Login(loginQuery *query.LoginQuery) (interface{}, error) { | ||
41 | + if err := loginQuery.ValidateQuery(); err != nil { | ||
42 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
43 | + } | ||
44 | + data, err := gateway.Partner01Service.Invoke(gateway.AuthsLogin, gs.WithJsonObject(loginQuery)) | ||
45 | + if err != nil { | ||
46 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
47 | + } | ||
48 | + return data.Data, nil | ||
49 | +} | ||
50 | + | ||
51 | +// 用户按公司登录 | ||
52 | +func (authService *AuthService) LoginByCompany(loginByCompanyCommand *command.LoginByCompanyCommand) (interface{}, error) { | ||
53 | + if err := loginByCompanyCommand.ValidateCommand(); err != nil { | ||
54 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
55 | + } | ||
56 | + data, err := gateway.Partner01Service.Invoke(gateway.AuthsLoginByCompany, gs.WithJsonObject(loginByCompanyCommand)) | ||
57 | + if err != nil { | ||
58 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
59 | + } | ||
60 | + return data.Data, nil | ||
61 | +} | ||
62 | + | ||
63 | +// 更新授权令牌accessToken | ||
64 | +func (authService *AuthService) RefreshToken(refreshTokenCommand *command.RefreshTokenCommand) (interface{}, error) { | ||
65 | + if err := refreshTokenCommand.ValidateCommand(); err != nil { | ||
66 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
67 | + } | ||
68 | + data, err := gateway.Partner01Service.Invoke(gateway.AuthsRefreshToken, gs.WithJsonObject(refreshTokenCommand)) | ||
69 | + if err != nil { | ||
70 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
71 | + } | ||
72 | + return data.Data, nil | ||
73 | +} | ||
74 | + | ||
75 | +// 注销登录 | ||
76 | +func (authService *AuthService) Revoke(revokeCommand *command.RevokeCommand) (interface{}, error) { | ||
77 | + if err := revokeCommand.ValidateCommand(); err != nil { | ||
78 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
79 | + } | ||
80 | + data, err := gateway.Partner01Service.Invoke(gateway.AuthsRevoke, gs.WithJsonObject(revokeCommand)) | ||
81 | + if err != nil { | ||
82 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
83 | + } | ||
84 | + return data.Data, nil | ||
85 | +} | ||
86 | + | ||
87 | +// 发送验证码 | ||
88 | +func (authService *AuthService) SendSmsCode(sendSmsCodeCommand *command.SendSmsCodeCommand) (interface{}, error) { | ||
89 | + if err := sendSmsCodeCommand.ValidateCommand(); err != nil { | ||
90 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
91 | + } | ||
92 | + data, err := gateway.Partner01Service.Invoke(gateway.AuthsSendSmsCode, gs.WithJsonObject(sendSmsCodeCommand)) | ||
93 | + if err != nil { | ||
94 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
95 | + } | ||
96 | + return data.Data, nil | ||
97 | +} | ||
98 | + | ||
99 | +func NewAuthService(options map[string]interface{}) *AuthService { | ||
100 | + newAuthService := &AuthService{} | ||
101 | + return newAuthService | ||
102 | +} |
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/beego/beego/v2/core/validation" | ||
7 | +) | ||
8 | + | ||
9 | +type ConvertCompanyStatusCommand struct { | ||
10 | + // 公司Id | ||
11 | + CompanyId int64 `json:"companyId" valid:"Required"` | ||
12 | + // 状态 1正常 2禁用 | ||
13 | + Status int64 `json:"status" valid:"Required"` | ||
14 | +} | ||
15 | + | ||
16 | +func (convertCompanyStatusCommand *ConvertCompanyStatusCommand) Valid(validation *validation.Validation) { | ||
17 | + // _ = validation.SetError("CustomValid", "未实现的自定义认证") | ||
18 | +} | ||
19 | + | ||
20 | +func (convertCompanyStatusCommand *ConvertCompanyStatusCommand) ValidateCommand() error { | ||
21 | + valid := validation.Validation{} | ||
22 | + b, err := valid.Valid(convertCompanyStatusCommand) | ||
23 | + if err != nil { | ||
24 | + return err | ||
25 | + } | ||
26 | + if !b { | ||
27 | + for _, validErr := range valid.Errors { | ||
28 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
29 | + } | ||
30 | + } | ||
31 | + return nil | ||
32 | +} |
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/beego/beego/v2/core/validation" | ||
7 | +) | ||
8 | + | ||
9 | +type CreateCompanyCommand struct { | ||
10 | + // 公司名称 | ||
11 | + Name string `json:"name" valid:"Required"` | ||
12 | + // 公司简称 | ||
13 | + Abbreviation string `json:"abbreviation" valid:"Required"` | ||
14 | + // 状态 1正常 2禁用 | ||
15 | + Status int64 `json:"status" valid:"Required"` | ||
16 | + // 备注 | ||
17 | + Remarks string `json:"remarks,omitempty"` | ||
18 | + // 公司主管理员账号 | ||
19 | + UserAccount string `json:"userAccount" valid:"Required"` | ||
20 | + // 公司主管理员姓名 | ||
21 | + UserName string `json:"userName" valid:"Required"` | ||
22 | +} | ||
23 | + | ||
24 | +func (createCompanyCommand *CreateCompanyCommand) Valid(validation *validation.Validation) { | ||
25 | + // _ = validation.SetError("CustomValid", "未实现的自定义认证") | ||
26 | +} | ||
27 | + | ||
28 | +func (createCompanyCommand *CreateCompanyCommand) ValidateCommand() error { | ||
29 | + valid := validation.Validation{} | ||
30 | + b, err := valid.Valid(createCompanyCommand) | ||
31 | + if err != nil { | ||
32 | + return err | ||
33 | + } | ||
34 | + if !b { | ||
35 | + for _, validErr := range valid.Errors { | ||
36 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
37 | + } | ||
38 | + } | ||
39 | + return nil | ||
40 | +} |
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/beego/beego/v2/core/validation" | ||
7 | +) | ||
8 | + | ||
9 | +type RemoveCompanyCommand struct { | ||
10 | + // 公司Id | ||
11 | + CompanyId int64 `json:"companyId" valid:"Required"` | ||
12 | +} | ||
13 | + | ||
14 | +func (removeCompanyCommand *RemoveCompanyCommand) Valid(validation *validation.Validation) { | ||
15 | + // _ = validation.SetError("CustomValid", "未实现的自定义认证") | ||
16 | +} | ||
17 | + | ||
18 | +func (removeCompanyCommand *RemoveCompanyCommand) ValidateCommand() error { | ||
19 | + valid := validation.Validation{} | ||
20 | + b, err := valid.Valid(removeCompanyCommand) | ||
21 | + if err != nil { | ||
22 | + return err | ||
23 | + } | ||
24 | + if !b { | ||
25 | + for _, validErr := range valid.Errors { | ||
26 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
27 | + } | ||
28 | + } | ||
29 | + return nil | ||
30 | +} |
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/beego/beego/v2/core/validation" | ||
7 | +) | ||
8 | + | ||
9 | +type SetCompanyAdminCommand struct { | ||
10 | + // 公司Id | ||
11 | + CompanyId int64 `json:"companyId" valid:"Required"` | ||
12 | + // 公司主管理员账号 | ||
13 | + UserAccount string `json:"userAccount" valid:"Required"` | ||
14 | + // 公司主管理员姓名 | ||
15 | + UserName string `json:"userName" valid:"Required"` | ||
16 | +} | ||
17 | + | ||
18 | +func (setCompanyAdminCommand *SetCompanyAdminCommand) Valid(validation *validation.Validation) { | ||
19 | + // _ = validation.SetError("CustomValid", "未实现的自定义认证") | ||
20 | +} | ||
21 | + | ||
22 | +func (setCompanyAdminCommand *SetCompanyAdminCommand) ValidateCommand() error { | ||
23 | + valid := validation.Validation{} | ||
24 | + b, err := valid.Valid(setCompanyAdminCommand) | ||
25 | + if err != nil { | ||
26 | + return err | ||
27 | + } | ||
28 | + if !b { | ||
29 | + for _, validErr := range valid.Errors { | ||
30 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
31 | + } | ||
32 | + } | ||
33 | + return nil | ||
34 | +} |
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/beego/beego/v2/core/validation" | ||
7 | +) | ||
8 | + | ||
9 | +type UpdateCompanyCommand struct { | ||
10 | + // 公司Id | ||
11 | + CompanyId int64 `json:"companyId" valid:"Required"` | ||
12 | + // 公司名称 | ||
13 | + Name string `json:"name,omitempty"` | ||
14 | + // 公司简称 | ||
15 | + Abbreviation string `json:"abbreviation,omitempty"` | ||
16 | + // 状态 1正常 2禁用 | ||
17 | + Status int64 `json:"status,omitempty"` | ||
18 | + // 备注 | ||
19 | + Remarks string `json:"remarks,omitempty"` | ||
20 | + // 公司主管理员账号 | ||
21 | + UserAccount string `json:"userAccount,omitempty"` | ||
22 | + // 公司主管理员姓名 | ||
23 | + UserName string `json:"userName,omitempty"` | ||
24 | +} | ||
25 | + | ||
26 | +func (updateCompanyCommand *UpdateCompanyCommand) Valid(validation *validation.Validation) { | ||
27 | + // _ = validation.SetError("CustomValid", "未实现的自定义认证") | ||
28 | +} | ||
29 | + | ||
30 | +func (updateCompanyCommand *UpdateCompanyCommand) ValidateCommand() error { | ||
31 | + valid := validation.Validation{} | ||
32 | + b, err := valid.Valid(updateCompanyCommand) | ||
33 | + if err != nil { | ||
34 | + return err | ||
35 | + } | ||
36 | + if !b { | ||
37 | + for _, validErr := range valid.Errors { | ||
38 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
39 | + } | ||
40 | + } | ||
41 | + return nil | ||
42 | +} |
pkg/application/company/query/get_company.go
0 → 100644
1 | +package query | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/beego/beego/v2/core/validation" | ||
7 | +) | ||
8 | + | ||
9 | +type GetCompanyQuery struct { | ||
10 | + // 公司Id | ||
11 | + CompanyId int64 `json:"companyId" valid:"Required"` | ||
12 | +} | ||
13 | + | ||
14 | +func (getCompanyQuery *GetCompanyQuery) Valid(validation *validation.Validation) { | ||
15 | + // _ = validation.SetError("CustomValid", "未实现的自定义认证") | ||
16 | +} | ||
17 | + | ||
18 | +func (getCompanyQuery *GetCompanyQuery) ValidateQuery() error { | ||
19 | + valid := validation.Validation{} | ||
20 | + b, err := valid.Valid(getCompanyQuery) | ||
21 | + if err != nil { | ||
22 | + return err | ||
23 | + } | ||
24 | + if !b { | ||
25 | + for _, validErr := range valid.Errors { | ||
26 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
27 | + } | ||
28 | + } | ||
29 | + return nil | ||
30 | +} |
1 | +package query | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/beego/beego/v2/core/validation" | ||
7 | +) | ||
8 | + | ||
9 | +type ListCompanyQuery struct { | ||
10 | + // 查询偏离量 | ||
11 | + Offset int `json:"offset" valid:"Required"` | ||
12 | + // 查询限制 | ||
13 | + Limit int `json:"limit" valid:"Required"` | ||
14 | +} | ||
15 | + | ||
16 | +func (listCompanyQuery *ListCompanyQuery) Valid(validation *validation.Validation) { | ||
17 | + // _ = validation.SetError("CustomValid", "未实现的自定义认证") | ||
18 | +} | ||
19 | + | ||
20 | +func (listCompanyQuery *ListCompanyQuery) ValidateQuery() error { | ||
21 | + valid := validation.Validation{} | ||
22 | + b, err := valid.Valid(listCompanyQuery) | ||
23 | + if err != nil { | ||
24 | + return err | ||
25 | + } | ||
26 | + if !b { | ||
27 | + for _, validErr := range valid.Errors { | ||
28 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
29 | + } | ||
30 | + } | ||
31 | + return nil | ||
32 | +} |
pkg/application/company/service/company.go
0 → 100644
1 | +package service | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "github.com/linmadan/egglib-go/core/application" | ||
6 | + "github.com/linmadan/egglib-go/utils/tool_funs" | ||
7 | + "github.com/tiptok/gocomm/common" | ||
8 | + "github.com/tiptok/gocomm/gs" | ||
9 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/application/company/command" | ||
10 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/application/company/query" | ||
11 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/application/factory" | ||
12 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/domain" | ||
13 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/infrastructure/gateway" | ||
14 | +) | ||
15 | + | ||
16 | +// 公司服务 | ||
17 | +type CompanyService struct { | ||
18 | +} | ||
19 | + | ||
20 | +// 公司状态转换 禁用、启用 | ||
21 | +func (companyService *CompanyService) ConvertCompanyStatus(convertCompanyStatusCommand *command.ConvertCompanyStatusCommand) (interface{}, error) { | ||
22 | + if err := convertCompanyStatusCommand.ValidateCommand(); err != nil { | ||
23 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
24 | + } | ||
25 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
26 | + if err != nil { | ||
27 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
28 | + } | ||
29 | + if err := transactionContext.StartTransaction(); err != nil { | ||
30 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
31 | + } | ||
32 | + defer func() { | ||
33 | + transactionContext.RollbackTransaction() | ||
34 | + }() | ||
35 | + var companyRepository domain.CompanyRepository | ||
36 | + if value, err := factory.CreateCompanyRepository(map[string]interface{}{ | ||
37 | + "transactionContext": transactionContext, | ||
38 | + }); err != nil { | ||
39 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
40 | + } else { | ||
41 | + companyRepository = value | ||
42 | + } | ||
43 | + company, err := companyRepository.FindOne(map[string]interface{}{"companyId": convertCompanyStatusCommand.CompanyId}) | ||
44 | + if err != nil { | ||
45 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
46 | + } | ||
47 | + if company == nil { | ||
48 | + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(convertCompanyStatusCommand.CompanyId))) | ||
49 | + } | ||
50 | + if err := company.Update(tool_funs.SimpleStructToMap(convertCompanyStatusCommand)); err != nil { | ||
51 | + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | ||
52 | + } | ||
53 | + if company, err := companyRepository.Save(company); err != nil { | ||
54 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
55 | + } else { | ||
56 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
57 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
58 | + } | ||
59 | + return company, nil | ||
60 | + } | ||
61 | +} | ||
62 | + | ||
63 | +// 创建 | ||
64 | +func (companyService *CompanyService) CreateCompany(createCompanyCommand *command.CreateCompanyCommand) (interface{}, error) { | ||
65 | + if err := createCompanyCommand.ValidateCommand(); err != nil { | ||
66 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
67 | + } | ||
68 | + return gateway.Partner01Service.CompanyCreate(createCompanyCommand) | ||
69 | +} | ||
70 | + | ||
71 | +// 返回 | ||
72 | +func (companyService *CompanyService) GetCompany(getCompanyQuery *query.GetCompanyQuery) (interface{}, error) { | ||
73 | + if err := getCompanyQuery.ValidateQuery(); err != nil { | ||
74 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
75 | + } | ||
76 | + return gateway.Partner01Service.CompanyGet(common.LoadCustomFieldToMap(getCompanyQuery, "CompanyId")) | ||
77 | +} | ||
78 | + | ||
79 | +// 返回列表 | ||
80 | +func (companyService *CompanyService) ListCompany(listCompanyQuery *query.ListCompanyQuery) (interface{}, error) { | ||
81 | + if err := listCompanyQuery.ValidateQuery(); err != nil { | ||
82 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
83 | + } | ||
84 | + data, err := gateway.Partner01Service.Invoke(gateway.CompanyList, gs.WithPathQuery(common.ObjectToMap(listCompanyQuery))) | ||
85 | + if err != nil { | ||
86 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
87 | + } | ||
88 | + return data.Data, nil | ||
89 | +} | ||
90 | + | ||
91 | +// 移除 | ||
92 | +func (companyService *CompanyService) RemoveCompany(removeCompanyCommand *command.RemoveCompanyCommand) (interface{}, error) { | ||
93 | + if err := removeCompanyCommand.ValidateCommand(); err != nil { | ||
94 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
95 | + } | ||
96 | + data, err := gateway.Partner01Service.Invoke(gateway.CompanyRemove, gs.WithPathParam(common.ObjectToMap(removeCompanyCommand))) | ||
97 | + if err != nil { | ||
98 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
99 | + } | ||
100 | + return data.Data, nil | ||
101 | +} | ||
102 | + | ||
103 | +// 设置公司管理员 | ||
104 | +func (companyService *CompanyService) SetCompanyAdmin(setCompanyAdminCommand *command.SetCompanyAdminCommand) (interface{}, error) { | ||
105 | + if err := setCompanyAdminCommand.ValidateCommand(); err != nil { | ||
106 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
107 | + } | ||
108 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
109 | + if err != nil { | ||
110 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
111 | + } | ||
112 | + if err := transactionContext.StartTransaction(); err != nil { | ||
113 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
114 | + } | ||
115 | + defer func() { | ||
116 | + transactionContext.RollbackTransaction() | ||
117 | + }() | ||
118 | + var companyRepository domain.CompanyRepository | ||
119 | + if value, err := factory.CreateCompanyRepository(map[string]interface{}{ | ||
120 | + "transactionContext": transactionContext, | ||
121 | + }); err != nil { | ||
122 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
123 | + } else { | ||
124 | + companyRepository = value | ||
125 | + } | ||
126 | + company, err := companyRepository.FindOne(map[string]interface{}{"companyId": setCompanyAdminCommand.CompanyId}) | ||
127 | + if err != nil { | ||
128 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
129 | + } | ||
130 | + if company == nil { | ||
131 | + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(setCompanyAdminCommand.CompanyId))) | ||
132 | + } | ||
133 | + | ||
134 | + newCompanyAdmin := &domain.CompanyAdmin{ | ||
135 | + UserAccount: setCompanyAdminCommand.UserAccount, // 用户手机号 | ||
136 | + UserName: setCompanyAdminCommand.UserName, // 用户名称 | ||
137 | + } | ||
138 | + // 更改公司管理员信息 | ||
139 | + if err := company.SetCompanyAdmin(newCompanyAdmin); err != nil { | ||
140 | + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | ||
141 | + } | ||
142 | + | ||
143 | + if company, err := companyRepository.Save(company); err != nil { | ||
144 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
145 | + } else { | ||
146 | + // todo 更改公司管理员 | ||
147 | + | ||
148 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
149 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
150 | + } | ||
151 | + return company, nil | ||
152 | + } | ||
153 | +} | ||
154 | + | ||
155 | +// 更新 | ||
156 | +func (companyService *CompanyService) UpdateCompany(updateCompanyCommand *command.UpdateCompanyCommand) (interface{}, error) { | ||
157 | + if err := updateCompanyCommand.ValidateCommand(); err != nil { | ||
158 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
159 | + } | ||
160 | + data, err := gateway.Partner01Service.Invoke(gateway.CompanyGet, gs.WithPathParam(common.ObjectToMap(updateCompanyCommand))) | ||
161 | + if err != nil { | ||
162 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
163 | + } | ||
164 | + return data.Data, nil | ||
165 | +} | ||
166 | + | ||
167 | +func NewCompanyService(options map[string]interface{}) *CompanyService { | ||
168 | + newCompanyService := &CompanyService{} | ||
169 | + return newCompanyService | ||
170 | +} |
pkg/application/factory/domain_service.go
0 → 100644
1 | +package factory | ||
2 | + | ||
3 | +import ( | ||
4 | + pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
5 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/domain/service" | ||
6 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/infrastructure/domainService" | ||
7 | +) | ||
8 | + | ||
9 | +func CreateShippingService(options map[string]interface{}) (service.ShippingGoodsService, error) { | ||
10 | + var transactionContext *pgTransaction.TransactionContext | ||
11 | + if value, ok := options["transactionContext"]; ok { | ||
12 | + transactionContext = value.(*pgTransaction.TransactionContext) | ||
13 | + } | ||
14 | + return domainService.NewShippingGoodsService(transactionContext) | ||
15 | +} | ||
16 | + | ||
17 | +func CreateReceivingService(options map[string]interface{}) (service.ReceivingGoodsService, error) { | ||
18 | + var transactionContext *pgTransaction.TransactionContext | ||
19 | + if value, ok := options["transactionContext"]; ok { | ||
20 | + transactionContext = value.(*pgTransaction.TransactionContext) | ||
21 | + } | ||
22 | + return domainService.NewReceivingGoodsService(transactionContext) | ||
23 | +} | ||
24 | + | ||
25 | +func CreateCancelOrderService(options map[string]interface{}) (service.CancelOrderService, error) { | ||
26 | + var transactionContext *pgTransaction.TransactionContext | ||
27 | + if value, ok := options["transactionContext"]; ok { | ||
28 | + transactionContext = value.(*pgTransaction.TransactionContext) | ||
29 | + } | ||
30 | + return domainService.NewCancelOrderService(transactionContext) | ||
31 | +} | ||
32 | + | ||
33 | +func CreateReturnGoodsService(options map[string]interface{}) (service.ReturnGoodsService, error) { | ||
34 | + var transactionContext *pgTransaction.TransactionContext | ||
35 | + if value, ok := options["transactionContext"]; ok { | ||
36 | + transactionContext = value.(*pgTransaction.TransactionContext) | ||
37 | + } | ||
38 | + return domainService.NewReturnGoodsService(transactionContext) | ||
39 | +} |
pkg/application/factory/repository.go
0 → 100644
1 | +package factory | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/linmadan/egglib-go/transaction/pg" | ||
5 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/domain" | ||
6 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/infrastructure/repository" | ||
7 | +) | ||
8 | + | ||
9 | +func CreatePartnerCategoryRepository(options map[string]interface{}) (domain.PartnerCategoryRepository, error) { | ||
10 | + var transactionContext *pg.TransactionContext | ||
11 | + if value, ok := options["transactionContext"]; ok { | ||
12 | + transactionContext = value.(*pg.TransactionContext) | ||
13 | + } | ||
14 | + return repository.NewPartnerCategoryRepository(transactionContext) | ||
15 | +} | ||
16 | + | ||
17 | +func CreatePermissionRepository(options map[string]interface{}) (domain.PermissionRepository, error) { | ||
18 | + var transactionContext *pg.TransactionContext | ||
19 | + if value, ok := options["transactionContext"]; ok { | ||
20 | + transactionContext = value.(*pg.TransactionContext) | ||
21 | + } | ||
22 | + return repository.NewPermissionRepository(transactionContext) | ||
23 | +} | ||
24 | + | ||
25 | +func CreateUserAuthRepository(options map[string]interface{}) (domain.UserAuthRepository, error) { | ||
26 | + var transactionContext *pg.TransactionContext | ||
27 | + if value, ok := options["transactionContext"]; ok { | ||
28 | + transactionContext = value.(*pg.TransactionContext) | ||
29 | + } | ||
30 | + return repository.NewUserAuthRepository(transactionContext) | ||
31 | +} | ||
32 | + | ||
33 | +func CreateOrderRepository(options map[string]interface{}) (domain.OrderRepository, error) { | ||
34 | + var transactionContext *pg.TransactionContext | ||
35 | + if value, ok := options["transactionContext"]; ok { | ||
36 | + transactionContext = value.(*pg.TransactionContext) | ||
37 | + } | ||
38 | + return repository.NewOrderRepository(transactionContext) | ||
39 | +} | ||
40 | + | ||
41 | +func CreateGoodsRepository(options map[string]interface{}) (domain.GoodsRepository, error) { | ||
42 | + var transactionContext *pg.TransactionContext | ||
43 | + if value, ok := options["transactionContext"]; ok { | ||
44 | + transactionContext = value.(*pg.TransactionContext) | ||
45 | + } | ||
46 | + return repository.NewGoodsRepository(transactionContext) | ||
47 | +} | ||
48 | + | ||
49 | +func CreateUserRepository(options map[string]interface{}) (domain.UserRepository, error) { | ||
50 | + var transactionContext *pg.TransactionContext | ||
51 | + if value, ok := options["transactionContext"]; ok { | ||
52 | + transactionContext = value.(*pg.TransactionContext) | ||
53 | + } | ||
54 | + return repository.NewUserRepository(transactionContext) | ||
55 | +} | ||
56 | + | ||
57 | +func CreateCompanyRepository(options map[string]interface{}) (domain.CompanyRepository, error) { | ||
58 | + var transactionContext *pg.TransactionContext | ||
59 | + if value, ok := options["transactionContext"]; ok { | ||
60 | + transactionContext = value.(*pg.TransactionContext) | ||
61 | + } | ||
62 | + return repository.NewCompanyRepository(transactionContext) | ||
63 | +} |
pkg/application/factory/transaction.go
0 → 100644
1 | +package factory | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/linmadan/egglib-go/core/application" | ||
5 | + pG "github.com/linmadan/egglib-go/transaction/pg" | ||
6 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/infrastructure/pg" | ||
7 | +) | ||
8 | + | ||
9 | +func CreateTransactionContext(options map[string]interface{}) (application.TransactionContext, error) { | ||
10 | + return pG.NewPGTransactionContext(pg.DB), nil | ||
11 | +} |
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "time" | ||
6 | + | ||
7 | + "github.com/beego/beego/v2/core/validation" | ||
8 | +) | ||
9 | + | ||
10 | +type CancelOrderCommand struct { | ||
11 | + // 订单ID | ||
12 | + OrderId int64 `json:"orderId" valid:"Required"` | ||
13 | + // 订单编号 | ||
14 | + OrderNo string `json:"orderNo" valid:"Required"` | ||
15 | + // 公司id | ||
16 | + CompanyId int64 `json:"companyId" valid:"Required"` | ||
17 | + // 是否是公司负责人 | ||
18 | + IsPrincipal bool `json:"isPrincipal" valid:"Required"` | ||
19 | + // 统一用户id | ||
20 | + Uid int64 `json:"uid" valid:"Required"` | ||
21 | + // 用户账号 | ||
22 | + UserAccount string `json:"userAccount" valid:"Required"` | ||
23 | + // 用户头像URL | ||
24 | + UserAvatarUrl string `json:"userAvatarUrl" valid:"Required"` | ||
25 | + // 用户名称 | ||
26 | + UserName string `json:"userName" valid:"Required"` | ||
27 | + // 邮件地址 | ||
28 | + Email string `json:"email" valid:"Required"` | ||
29 | + // 性别 | ||
30 | + Gender int `json:"gender" valid:"Required"` | ||
31 | + // 入职时间 | ||
32 | + EntryTime time.Time `json:"entryTime" valid:"Required"` | ||
33 | + // 分机 | ||
34 | + Extension string `json:"extension" valid:"Required"` | ||
35 | + // 工作地 | ||
36 | + Workplace string `json:"workplace" valid:"Required"` | ||
37 | + // 私人电话 | ||
38 | + PrivateNumber string `json:"privateNumber" valid:"Required"` | ||
39 | + // 工号 | ||
40 | + JobNumber string `json:"jobNumber" valid:"Required"` | ||
41 | +} | ||
42 | + | ||
43 | +func (cancelOrderCommand *CancelOrderCommand) Valid(validation *validation.Validation) { | ||
44 | + //validation.SetError("CustomValid", "未实现的自定义认证") | ||
45 | +} | ||
46 | + | ||
47 | +func (cancelOrderCommand *CancelOrderCommand) ValidateCommand() error { | ||
48 | + valid := validation.Validation{} | ||
49 | + b, err := valid.Valid(cancelOrderCommand) | ||
50 | + if err != nil { | ||
51 | + return err | ||
52 | + } | ||
53 | + if !b { | ||
54 | + for _, validErr := range valid.Errors { | ||
55 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
56 | + } | ||
57 | + } | ||
58 | + return nil | ||
59 | +} |
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/beego/beego/v2/core/validation" | ||
7 | +) | ||
8 | + | ||
9 | +type CreateOrderCommand struct { | ||
10 | + // 订单编号 | ||
11 | + OrderNo string `json:"orderNo" valid:"Required"` | ||
12 | + // 公司Id | ||
13 | + CompanyId int64 `json:"companyId" valid:"Required"` | ||
14 | + // 买家名称 | ||
15 | + BuyerName string `json:"buyerName,omitempty"` | ||
16 | + // 联系信息 | ||
17 | + ContactInfo string `json:"contactInfo,omitempty"` | ||
18 | + // 发货地址 | ||
19 | + ShippingAddress string `json:"shippingAddress,omitempty"` | ||
20 | + // 订单商品总数 | ||
21 | + OrderNum int64 `json:"orderNum" valid:"Required"` | ||
22 | + // 订单总价 | ||
23 | + TotalPrice float64 `json:"totalPrice" valid:"Required"` | ||
24 | +} | ||
25 | + | ||
26 | +func (createOrderCommand *CreateOrderCommand) Valid(validation *validation.Validation) { | ||
27 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
28 | +} | ||
29 | + | ||
30 | +func (createOrderCommand *CreateOrderCommand) ValidateCommand() error { | ||
31 | + valid := validation.Validation{} | ||
32 | + b, err := valid.Valid(createOrderCommand) | ||
33 | + if err != nil { | ||
34 | + return err | ||
35 | + } | ||
36 | + if !b { | ||
37 | + for _, validErr := range valid.Errors { | ||
38 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
39 | + } | ||
40 | + } | ||
41 | + return nil | ||
42 | +} |
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/beego/beego/v2/core/validation" | ||
7 | +) | ||
8 | + | ||
9 | +type DrawDividendsCommand struct { | ||
10 | + // 参与分红的合伙人 | ||
11 | + PartnerId int64 `json:"partnerId" valid:"Required"` | ||
12 | + // 进行分红的订单编号 | ||
13 | + OrderNo string `json:"orderNo" valid:"Required"` | ||
14 | +} | ||
15 | + | ||
16 | +func (drawDividendsCommand *DrawDividendsCommand) Valid(validation *validation.Validation) { | ||
17 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
18 | +} | ||
19 | + | ||
20 | +func (drawDividendsCommand *DrawDividendsCommand) ValidateCommand() error { | ||
21 | + valid := validation.Validation{} | ||
22 | + b, err := valid.Valid(drawDividendsCommand) | ||
23 | + if err != nil { | ||
24 | + return err | ||
25 | + } | ||
26 | + if !b { | ||
27 | + for _, validErr := range valid.Errors { | ||
28 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
29 | + } | ||
30 | + } | ||
31 | + return nil | ||
32 | +} |
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "time" | ||
6 | + | ||
7 | + "github.com/beego/beego/v2/core/validation" | ||
8 | +) | ||
9 | + | ||
10 | +type ReceiveGoodsCommand struct { | ||
11 | + // 订单号 | ||
12 | + OrderNo string `json:"orderNo" valid:"Required"` | ||
13 | + // 是否是公司负责人 | ||
14 | + IsPrincipal bool `json:"isPrincipal" valid:"Required"` | ||
15 | + // 统一用户id | ||
16 | + Uid int64 `json:"uid" valid:"Required"` | ||
17 | + // 用户账号 | ||
18 | + UserAccount string `json:"userAccount" valid:"Required"` | ||
19 | + // 用户头像URL | ||
20 | + UserAvatarUrl string `json:"userAvatarUrl" valid:"Required"` | ||
21 | + // 用户名称 | ||
22 | + UserName string `json:"userName" valid:"Required"` | ||
23 | + // 邮件地址 | ||
24 | + Email string `json:"email" valid:"Required"` | ||
25 | + // 性别 | ||
26 | + Gender int `json:"gender" valid:"Required"` | ||
27 | + // 入职时间 | ||
28 | + EntryTime time.Time `json:"entryTime" valid:"Required"` | ||
29 | + // 分机 | ||
30 | + Extension string `json:"extension" valid:"Required"` | ||
31 | + // 工作地 | ||
32 | + Workplace string `json:"workplace" valid:"Required"` | ||
33 | + // 私人电话 | ||
34 | + PrivateNumber string `json:"privateNumber" valid:"Required"` | ||
35 | + // 工号 | ||
36 | + JobNumber string `json:"jobNumber" valid:"Required"` | ||
37 | + // 公司id | ||
38 | + CompanyId int64 `json:"companyId" valid:"Required"` | ||
39 | +} | ||
40 | + | ||
41 | +func (receiveGoodsCommand *ReceiveGoodsCommand) Valid(validation *validation.Validation) { | ||
42 | + //validation.SetError("CustomValid", "未实现的自定义认证") | ||
43 | +} | ||
44 | + | ||
45 | +func (receiveGoodsCommand *ReceiveGoodsCommand) ValidateCommand() error { | ||
46 | + valid := validation.Validation{} | ||
47 | + b, err := valid.Valid(receiveGoodsCommand) | ||
48 | + if err != nil { | ||
49 | + return err | ||
50 | + } | ||
51 | + if !b { | ||
52 | + for _, validErr := range valid.Errors { | ||
53 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
54 | + } | ||
55 | + } | ||
56 | + return nil | ||
57 | +} |
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/beego/beego/v2/core/validation" | ||
7 | +) | ||
8 | + | ||
9 | +type RemoveOrderCommand struct { | ||
10 | + // 订单id | ||
11 | + OrderId int64 `json:"orderId" valid:"Required"` | ||
12 | +} | ||
13 | + | ||
14 | +func (removeOrderCommand *RemoveOrderCommand) Valid(validation *validation.Validation) { | ||
15 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
16 | +} | ||
17 | + | ||
18 | +func (removeOrderCommand *RemoveOrderCommand) ValidateCommand() error { | ||
19 | + valid := validation.Validation{} | ||
20 | + b, err := valid.Valid(removeOrderCommand) | ||
21 | + if err != nil { | ||
22 | + return err | ||
23 | + } | ||
24 | + if !b { | ||
25 | + for _, validErr := range valid.Errors { | ||
26 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
27 | + } | ||
28 | + } | ||
29 | + return nil | ||
30 | +} |
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "time" | ||
6 | + | ||
7 | + "github.com/beego/beego/v2/core/validation" | ||
8 | +) | ||
9 | + | ||
10 | +type ReturnGoodsCommand struct { | ||
11 | + // 订单号 | ||
12 | + OrderNo string `json:"orderNo" valid:"Required"` | ||
13 | + // 是否是公司负责人 | ||
14 | + IsPrincipal bool `json:"isPrincipal" valid:"Required"` | ||
15 | + // 统一用户id | ||
16 | + Uid int64 `json:"uid" valid:"Required"` | ||
17 | + // 用户账号 | ||
18 | + UserAccount string `json:"userAccount" valid:"Required"` | ||
19 | + // 用户头像URL | ||
20 | + UserAvatarUrl string `json:"userAvatarUrl" valid:"Required"` | ||
21 | + // 用户名称 | ||
22 | + UserName string `json:"userName" valid:"Required"` | ||
23 | + // 邮件地址 | ||
24 | + Email string `json:"email" valid:"Required"` | ||
25 | + // 性别 | ||
26 | + Gender int `json:"gender" valid:"Required"` | ||
27 | + // 入职时间 | ||
28 | + EntryTime time.Time `json:"entryTime" valid:"Required"` | ||
29 | + // 分机 | ||
30 | + Extension string `json:"extension" valid:"Required"` | ||
31 | + // 工作地 | ||
32 | + Workplace string `json:"workplace" valid:"Required"` | ||
33 | + // 私人电话 | ||
34 | + PrivateNumber string `json:"privateNumber" valid:"Required"` | ||
35 | + // 工号 | ||
36 | + JobNumber string `json:"jobNumber" valid:"Required"` | ||
37 | + // 公司id | ||
38 | + CompanyId int64 `json:"companyId" valid:"Required"` | ||
39 | +} | ||
40 | + | ||
41 | +func (returnGoodsCommand *ReturnGoodsCommand) Valid(validation *validation.Validation) { | ||
42 | + //validation.SetError("CustomValid", "未实现的自定义认证") | ||
43 | +} | ||
44 | + | ||
45 | +func (returnGoodsCommand *ReturnGoodsCommand) ValidateCommand() error { | ||
46 | + valid := validation.Validation{} | ||
47 | + b, err := valid.Valid(returnGoodsCommand) | ||
48 | + if err != nil { | ||
49 | + return err | ||
50 | + } | ||
51 | + if !b { | ||
52 | + for _, validErr := range valid.Errors { | ||
53 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
54 | + } | ||
55 | + } | ||
56 | + return nil | ||
57 | +} |
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/beego/beego/v2/core/validation" | ||
7 | +) | ||
8 | + | ||
9 | +type ShippingGoodsCommand struct { | ||
10 | + // 订单ID | ||
11 | + OrderId int `json:"orderId" valid:"Required"` | ||
12 | + // 发货单号 | ||
13 | + DeliveryCode string `json:"deliveryCode" valid:"Required"` | ||
14 | + // 订单编号 | ||
15 | + OrderNo string `json:"orderNo" valid:"Required"` | ||
16 | + // 订单数量 | ||
17 | + OrderNum int64 `json:"orderNum" valid:"Required"` | ||
18 | +} | ||
19 | + | ||
20 | +func (shippingGoodsCommand *ShippingGoodsCommand) Valid(validation *validation.Validation) { | ||
21 | + //_ = validation.SetError("CustomValid", "未实现的自定义认证") | ||
22 | +} | ||
23 | + | ||
24 | +func (shippingGoodsCommand *ShippingGoodsCommand) ValidateCommand() error { | ||
25 | + valid := validation.Validation{} | ||
26 | + b, err := valid.Valid(shippingGoodsCommand) | ||
27 | + if err != nil { | ||
28 | + return err | ||
29 | + } | ||
30 | + if !b { | ||
31 | + for _, validErr := range valid.Errors { | ||
32 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
33 | + } | ||
34 | + } | ||
35 | + return nil | ||
36 | +} |
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/beego/beego/v2/core/validation" | ||
7 | +) | ||
8 | + | ||
9 | +type UpdateOrderCommand struct { | ||
10 | + // 订单id | ||
11 | + OrderId int64 `json:"orderId" valid:"Required"` | ||
12 | +} | ||
13 | + | ||
14 | +func (updateOrderCommand *UpdateOrderCommand) Valid(validation *validation.Validation) { | ||
15 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
16 | +} | ||
17 | + | ||
18 | +func (updateOrderCommand *UpdateOrderCommand) ValidateCommand() error { | ||
19 | + valid := validation.Validation{} | ||
20 | + b, err := valid.Valid(updateOrderCommand) | ||
21 | + if err != nil { | ||
22 | + return err | ||
23 | + } | ||
24 | + if !b { | ||
25 | + for _, validErr := range valid.Errors { | ||
26 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
27 | + } | ||
28 | + } | ||
29 | + return nil | ||
30 | +} |
pkg/application/order/query/get_order.go
0 → 100644
1 | +package query | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/beego/beego/v2/core/validation" | ||
7 | +) | ||
8 | + | ||
9 | +type GetOrderQuery struct { | ||
10 | + // 订单id | ||
11 | + OrderId int64 `json:"orderId" valid:"Required"` | ||
12 | +} | ||
13 | + | ||
14 | +func (getOrderQuery *GetOrderQuery) Valid(validation *validation.Validation) { | ||
15 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
16 | +} | ||
17 | + | ||
18 | +func (getOrderQuery *GetOrderQuery) ValidateQuery() error { | ||
19 | + valid := validation.Validation{} | ||
20 | + b, err := valid.Valid(getOrderQuery) | ||
21 | + if err != nil { | ||
22 | + return err | ||
23 | + } | ||
24 | + if !b { | ||
25 | + for _, validErr := range valid.Errors { | ||
26 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
27 | + } | ||
28 | + } | ||
29 | + return nil | ||
30 | +} |
pkg/application/order/query/list_order.go
0 → 100644
1 | +package query | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/beego/beego/v2/core/validation" | ||
7 | +) | ||
8 | + | ||
9 | +type ListOrderQuery struct { | ||
10 | + // 查询偏离量 | ||
11 | + Offset int `json:"offset" valid:"Required"` | ||
12 | + // 查询限制 | ||
13 | + Limit int `json:"limit" valid:"Required"` | ||
14 | +} | ||
15 | + | ||
16 | +func (listOrderQuery *ListOrderQuery) Valid(validation *validation.Validation) { | ||
17 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
18 | +} | ||
19 | + | ||
20 | +func (listOrderQuery *ListOrderQuery) ValidateQuery() error { | ||
21 | + valid := validation.Validation{} | ||
22 | + b, err := valid.Valid(listOrderQuery) | ||
23 | + if err != nil { | ||
24 | + return err | ||
25 | + } | ||
26 | + if !b { | ||
27 | + for _, validErr := range valid.Errors { | ||
28 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
29 | + } | ||
30 | + } | ||
31 | + return nil | ||
32 | +} |
pkg/application/order/service/order.go
0 → 100644
1 | +package service | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "github.com/linmadan/egglib-go/core/application" | ||
6 | + "github.com/linmadan/egglib-go/utils/tool_funs" | ||
7 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/application/factory" | ||
8 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/application/order/command" | ||
9 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/application/order/query" | ||
10 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/domain" | ||
11 | + "strconv" | ||
12 | +) | ||
13 | + | ||
14 | +// 订单基础服务 | ||
15 | +type OrderService struct { | ||
16 | +} | ||
17 | + | ||
18 | +// 取消订单 | ||
19 | +func (orderService *OrderService) CancelOrder(cancelCommand *command.CancelOrderCommand) (interface{}, error) { | ||
20 | + if err := cancelCommand.ValidateCommand(); err != nil { | ||
21 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
22 | + } | ||
23 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
24 | + if err != nil { | ||
25 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
26 | + } | ||
27 | + if err := transactionContext.StartTransaction(); err != nil { | ||
28 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
29 | + } | ||
30 | + defer func() { | ||
31 | + _ = transactionContext.RollbackTransaction() | ||
32 | + }() | ||
33 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
34 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
35 | + } | ||
36 | + return nil, nil | ||
37 | +} | ||
38 | + | ||
39 | +// 创建订单增删改查 | ||
40 | +func (orderService *OrderService) CreateOrder(createOrderCommand *command.CreateOrderCommand) (interface{}, error) { | ||
41 | + if err := createOrderCommand.ValidateCommand(); err != nil { | ||
42 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
43 | + } | ||
44 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
45 | + if err != nil { | ||
46 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
47 | + } | ||
48 | + if err := transactionContext.StartTransaction(); err != nil { | ||
49 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
50 | + } | ||
51 | + defer func() { | ||
52 | + _ = transactionContext.RollbackTransaction() | ||
53 | + }() | ||
54 | + newOrder := &domain.Order{ | ||
55 | + OrderNo: createOrderCommand.OrderNo, | ||
56 | + CompanyId: createOrderCommand.CompanyId, | ||
57 | + Buyer: &domain.BuyerInfo{ | ||
58 | + BuyerName: createOrderCommand.BuyerName, | ||
59 | + }, | ||
60 | + TotalPrice: createOrderCommand.TotalPrice, | ||
61 | + } | ||
62 | + var orderRepository domain.OrderRepository | ||
63 | + if value, err := factory.CreateOrderRepository(map[string]interface{}{ | ||
64 | + "transactionContext": transactionContext, | ||
65 | + }); err != nil { | ||
66 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
67 | + } else { | ||
68 | + orderRepository = value | ||
69 | + } | ||
70 | + if order, err := orderRepository.Save(newOrder); err != nil { | ||
71 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
72 | + } else { | ||
73 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
74 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
75 | + } | ||
76 | + return order, nil | ||
77 | + } | ||
78 | +} | ||
79 | + | ||
80 | +// 订单分红服务 | ||
81 | +func (orderService *OrderService) DrawDividends(drawDividendsCommand *command.DrawDividendsCommand) (interface{}, error) { | ||
82 | + if err := drawDividendsCommand.ValidateCommand(); err != nil { | ||
83 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
84 | + } | ||
85 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
86 | + if err != nil { | ||
87 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
88 | + } | ||
89 | + if err := transactionContext.StartTransaction(); err != nil { | ||
90 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
91 | + } | ||
92 | + defer func() { | ||
93 | + _ = transactionContext.RollbackTransaction() | ||
94 | + }() | ||
95 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
96 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
97 | + } | ||
98 | + return nil, nil | ||
99 | +} | ||
100 | + | ||
101 | +// 返回订单增删改查 | ||
102 | +func (orderService *OrderService) GetOrder(getOrderQuery *query.GetOrderQuery) (interface{}, error) { | ||
103 | + if err := getOrderQuery.ValidateQuery(); err != nil { | ||
104 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
105 | + } | ||
106 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
107 | + if err != nil { | ||
108 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
109 | + } | ||
110 | + if err := transactionContext.StartTransaction(); err != nil { | ||
111 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
112 | + } | ||
113 | + defer func() { | ||
114 | + _ = transactionContext.RollbackTransaction() | ||
115 | + }() | ||
116 | + var orderRepository domain.OrderRepository | ||
117 | + if value, err := factory.CreateOrderRepository(map[string]interface{}{ | ||
118 | + "transactionContext": transactionContext, | ||
119 | + }); err != nil { | ||
120 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
121 | + } else { | ||
122 | + orderRepository = value | ||
123 | + } | ||
124 | + order, err := orderRepository.FindOne(map[string]interface{}{"orderId": getOrderQuery.OrderId}) | ||
125 | + if err != nil { | ||
126 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
127 | + } | ||
128 | + if order == nil { | ||
129 | + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", strconv.FormatInt(getOrderQuery.OrderId, 10))) | ||
130 | + } else { | ||
131 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
132 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
133 | + } | ||
134 | + return order, nil | ||
135 | + } | ||
136 | +} | ||
137 | + | ||
138 | +// 返回订单增删改查列表 | ||
139 | +func (orderService *OrderService) ListOrder(listOrderQuery *query.ListOrderQuery) (interface{}, error) { | ||
140 | + if err := listOrderQuery.ValidateQuery(); err != nil { | ||
141 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
142 | + } | ||
143 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
144 | + if err != nil { | ||
145 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
146 | + } | ||
147 | + if err := transactionContext.StartTransaction(); err != nil { | ||
148 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
149 | + } | ||
150 | + defer func() { | ||
151 | + _ = transactionContext.RollbackTransaction() | ||
152 | + }() | ||
153 | + var orderRepository domain.OrderRepository | ||
154 | + if value, err := factory.CreateOrderRepository(map[string]interface{}{ | ||
155 | + "transactionContext": transactionContext, | ||
156 | + }); err != nil { | ||
157 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
158 | + } else { | ||
159 | + orderRepository = value | ||
160 | + } | ||
161 | + if count, orders, err := orderRepository.Find(tool_funs.SimpleStructToMap(listOrderQuery)); err != nil { | ||
162 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
163 | + } else { | ||
164 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
165 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
166 | + } | ||
167 | + return map[string]interface{}{ | ||
168 | + "count": count, | ||
169 | + "orders": orders, | ||
170 | + }, nil | ||
171 | + } | ||
172 | +} | ||
173 | + | ||
174 | +// 订单收货服务 | ||
175 | +func (orderService *OrderService) ReceiveGoods(receivingCommand *command.ReceiveGoodsCommand) (interface{}, error) { | ||
176 | + if err := receivingCommand.ValidateCommand(); err != nil { | ||
177 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
178 | + } | ||
179 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
180 | + if err != nil { | ||
181 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
182 | + } | ||
183 | + if err := transactionContext.StartTransaction(); err != nil { | ||
184 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
185 | + } | ||
186 | + defer func() { | ||
187 | + _ = transactionContext.RollbackTransaction() | ||
188 | + }() | ||
189 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
190 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
191 | + } | ||
192 | + return nil, nil | ||
193 | +} | ||
194 | + | ||
195 | +// 移除订单增删改查 | ||
196 | +func (orderService *OrderService) RemoveOrder(removeOrderCommand *command.RemoveOrderCommand) (interface{}, error) { | ||
197 | + if err := removeOrderCommand.ValidateCommand(); err != nil { | ||
198 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
199 | + } | ||
200 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
201 | + if err != nil { | ||
202 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
203 | + } | ||
204 | + if err := transactionContext.StartTransaction(); err != nil { | ||
205 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
206 | + } | ||
207 | + defer func() { | ||
208 | + _ = transactionContext.RollbackTransaction() | ||
209 | + }() | ||
210 | + var orderRepository domain.OrderRepository | ||
211 | + if value, err := factory.CreateOrderRepository(map[string]interface{}{ | ||
212 | + "transactionContext": transactionContext, | ||
213 | + }); err != nil { | ||
214 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
215 | + } else { | ||
216 | + orderRepository = value | ||
217 | + } | ||
218 | + order, err := orderRepository.FindOne(map[string]interface{}{"orderId": removeOrderCommand.OrderId}) | ||
219 | + if err != nil { | ||
220 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
221 | + } | ||
222 | + if order == nil { | ||
223 | + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", strconv.FormatInt(removeOrderCommand.OrderId, 10))) | ||
224 | + } | ||
225 | + if order, err := orderRepository.Remove(order); err != nil { | ||
226 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
227 | + } else { | ||
228 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
229 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
230 | + } | ||
231 | + return order, nil | ||
232 | + } | ||
233 | +} | ||
234 | + | ||
235 | +// 订单退货服务 | ||
236 | +func (orderService *OrderService) ReturnGoods(returnGoodsCommand *command.ReturnGoodsCommand) (interface{}, error) { | ||
237 | + if err := returnGoodsCommand.ValidateCommand(); err != nil { | ||
238 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
239 | + } | ||
240 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
241 | + if err != nil { | ||
242 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
243 | + } | ||
244 | + if err := transactionContext.StartTransaction(); err != nil { | ||
245 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
246 | + } | ||
247 | + defer func() { | ||
248 | + _ = transactionContext.RollbackTransaction() | ||
249 | + }() | ||
250 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
251 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
252 | + } | ||
253 | + return nil, nil | ||
254 | +} | ||
255 | + | ||
256 | +// 订单发货服务 | ||
257 | +func (orderService *OrderService) ShippingGoods(shippingGoodsCommand *command.ShippingGoodsCommand) (interface{}, error) { | ||
258 | + if err := shippingGoodsCommand.ValidateCommand(); err != nil { | ||
259 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
260 | + } | ||
261 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
262 | + if err != nil { | ||
263 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
264 | + } | ||
265 | + if err := transactionContext.StartTransaction(); err != nil { | ||
266 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
267 | + } | ||
268 | + defer func() { | ||
269 | + _ = transactionContext.RollbackTransaction() | ||
270 | + }() | ||
271 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
272 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
273 | + } | ||
274 | + return nil, nil | ||
275 | +} | ||
276 | + | ||
277 | +// 更新订单增删改查 | ||
278 | +func (orderService *OrderService) UpdateOrder(updateOrderCommand *command.UpdateOrderCommand) (interface{}, error) { | ||
279 | + if err := updateOrderCommand.ValidateCommand(); err != nil { | ||
280 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
281 | + } | ||
282 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
283 | + if err != nil { | ||
284 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
285 | + } | ||
286 | + if err := transactionContext.StartTransaction(); err != nil { | ||
287 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
288 | + } | ||
289 | + defer func() { | ||
290 | + _ = transactionContext.RollbackTransaction() | ||
291 | + }() | ||
292 | + var orderRepository domain.OrderRepository | ||
293 | + if value, err := factory.CreateOrderRepository(map[string]interface{}{ | ||
294 | + "transactionContext": transactionContext, | ||
295 | + }); err != nil { | ||
296 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
297 | + } else { | ||
298 | + orderRepository = value | ||
299 | + } | ||
300 | + order, err := orderRepository.FindOne(map[string]interface{}{"orderId": updateOrderCommand.OrderId}) | ||
301 | + if err != nil { | ||
302 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
303 | + } | ||
304 | + if order == nil { | ||
305 | + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", strconv.FormatInt(updateOrderCommand.OrderId, 10))) | ||
306 | + } | ||
307 | + if err := order.Update(tool_funs.SimpleStructToMap(updateOrderCommand)); err != nil { | ||
308 | + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | ||
309 | + } | ||
310 | + if order, err := orderRepository.Save(order); err != nil { | ||
311 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
312 | + } else { | ||
313 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
314 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
315 | + } | ||
316 | + return order, nil | ||
317 | + } | ||
318 | +} | ||
319 | + | ||
320 | +func NewOrderService(options map[string]interface{}) *OrderService { | ||
321 | + newOrderService := &OrderService{} | ||
322 | + return newOrderService | ||
323 | +} |
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/beego/beego/v2/core/validation" | ||
7 | +) | ||
8 | + | ||
9 | +type CreatePartnerCommand struct { | ||
10 | +} | ||
11 | + | ||
12 | +func (createPartnerCommand *CreatePartnerCommand) Valid(validation *validation.Validation) { | ||
13 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
14 | +} | ||
15 | + | ||
16 | +func (createPartnerCommand *CreatePartnerCommand) ValidateCommand() error { | ||
17 | + valid := validation.Validation{} | ||
18 | + b, err := valid.Valid(createPartnerCommand) | ||
19 | + if err != nil { | ||
20 | + return err | ||
21 | + } | ||
22 | + if !b { | ||
23 | + for _, validErr := range valid.Errors { | ||
24 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
25 | + } | ||
26 | + } | ||
27 | + return nil | ||
28 | +} |
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/beego/beego/v2/core/validation" | ||
7 | +) | ||
8 | + | ||
9 | +type RemovePartnerCommand struct { | ||
10 | + // 合伙人id | ||
11 | + PartnerId int64 `json:"partnerId" valid:"Required"` | ||
12 | +} | ||
13 | + | ||
14 | +func (removePartnerCommand *RemovePartnerCommand) Valid(validation *validation.Validation) { | ||
15 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
16 | +} | ||
17 | + | ||
18 | +func (removePartnerCommand *RemovePartnerCommand) ValidateCommand() error { | ||
19 | + valid := validation.Validation{} | ||
20 | + b, err := valid.Valid(removePartnerCommand) | ||
21 | + if err != nil { | ||
22 | + return err | ||
23 | + } | ||
24 | + if !b { | ||
25 | + for _, validErr := range valid.Errors { | ||
26 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
27 | + } | ||
28 | + } | ||
29 | + return nil | ||
30 | +} |
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/beego/beego/v2/core/validation" | ||
7 | +) | ||
8 | + | ||
9 | +type UpdatePartnerCommand struct { | ||
10 | + // 合伙人id | ||
11 | + PartnerId int64 `json:"partnerId" valid:"Required"` | ||
12 | +} | ||
13 | + | ||
14 | +func (updatePartnerCommand *UpdatePartnerCommand) Valid(validation *validation.Validation) { | ||
15 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
16 | +} | ||
17 | + | ||
18 | +func (updatePartnerCommand *UpdatePartnerCommand) ValidateCommand() error { | ||
19 | + valid := validation.Validation{} | ||
20 | + b, err := valid.Valid(updatePartnerCommand) | ||
21 | + if err != nil { | ||
22 | + return err | ||
23 | + } | ||
24 | + if !b { | ||
25 | + for _, validErr := range valid.Errors { | ||
26 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
27 | + } | ||
28 | + } | ||
29 | + return nil | ||
30 | +} |
pkg/application/partner/query/get_partner.go
0 → 100644
1 | +package query | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/beego/beego/v2/core/validation" | ||
7 | +) | ||
8 | + | ||
9 | +type GetPartnerQuery struct { | ||
10 | + // 合伙人id | ||
11 | + PartnerId int64 `json:"partnerId" valid:"Required"` | ||
12 | +} | ||
13 | + | ||
14 | +func (getPartnerQuery *GetPartnerQuery) Valid(validation *validation.Validation) { | ||
15 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
16 | +} | ||
17 | + | ||
18 | +func (getPartnerQuery *GetPartnerQuery) ValidateQuery() error { | ||
19 | + valid := validation.Validation{} | ||
20 | + b, err := valid.Valid(getPartnerQuery) | ||
21 | + if err != nil { | ||
22 | + return err | ||
23 | + } | ||
24 | + if !b { | ||
25 | + for _, validErr := range valid.Errors { | ||
26 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
27 | + } | ||
28 | + } | ||
29 | + return nil | ||
30 | +} |
1 | +package query | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/beego/beego/v2/core/validation" | ||
7 | +) | ||
8 | + | ||
9 | +type ListPartnerQuery struct { | ||
10 | + // 查询偏离量 | ||
11 | + Offset int `json:"offset" valid:"Required"` | ||
12 | + // 查询限制 | ||
13 | + Limit int `json:"limit" valid:"Required"` | ||
14 | +} | ||
15 | + | ||
16 | +func (listPartnerQuery *ListPartnerQuery) Valid(validation *validation.Validation) { | ||
17 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
18 | +} | ||
19 | + | ||
20 | +func (listPartnerQuery *ListPartnerQuery) ValidateQuery() error { | ||
21 | + valid := validation.Validation{} | ||
22 | + b, err := valid.Valid(listPartnerQuery) | ||
23 | + if err != nil { | ||
24 | + return err | ||
25 | + } | ||
26 | + if !b { | ||
27 | + for _, validErr := range valid.Errors { | ||
28 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
29 | + } | ||
30 | + } | ||
31 | + return nil | ||
32 | +} |
1 | +package query | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/beego/beego/v2/core/validation" | ||
7 | +) | ||
8 | + | ||
9 | +type PartnerCategoriesQuery struct { | ||
10 | +} | ||
11 | + | ||
12 | +func (partnerCategoriesQuery *PartnerCategoriesQuery) Valid(validation *validation.Validation) { | ||
13 | + | ||
14 | +} | ||
15 | + | ||
16 | +func (partnerCategoriesQuery *PartnerCategoriesQuery) ValidateQuery() error { | ||
17 | + valid := validation.Validation{} | ||
18 | + b, err := valid.Valid(partnerCategoriesQuery) | ||
19 | + if err != nil { | ||
20 | + return err | ||
21 | + } | ||
22 | + if !b { | ||
23 | + for _, validErr := range valid.Errors { | ||
24 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
25 | + } | ||
26 | + } | ||
27 | + return nil | ||
28 | +} |
pkg/application/partner/service/partner.go
0 → 100644
1 | +package service | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/linmadan/egglib-go/core/application" | ||
5 | + //"github.com/linmadan/egglib-go/utils/tool_funs" | ||
6 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/application/factory" | ||
7 | + //"gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/application/partner/command" | ||
8 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/application/partner/query" | ||
9 | + //"gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/domain" | ||
10 | +) | ||
11 | + | ||
12 | +// 合伙人服务 | ||
13 | +type PartnerService struct { | ||
14 | +} | ||
15 | + | ||
16 | +//// 创建合伙人增删改查 | ||
17 | +//func (partnerService *PartnerService) CreatePartner(createPartnerCommand *command.CreatePartnerCommand) (interface{}, error) { | ||
18 | +// if err := createPartnerCommand.ValidateCommand(); err != nil { | ||
19 | +// return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
20 | +// } | ||
21 | +// transactionContext, err := factory.CreateTransactionContext(nil) | ||
22 | +// if err != nil { | ||
23 | +// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
24 | +// } | ||
25 | +// if err := transactionContext.StartTransaction(); err != nil { | ||
26 | +// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
27 | +// } | ||
28 | +// defer func() { | ||
29 | +// transactionContext.RollbackTransaction() | ||
30 | +// }() | ||
31 | +// newPartner := &domain.Partner{} | ||
32 | +// var partnerRepository partner.PartnerRepository | ||
33 | +// if value, err := factory.CreatePartnerRepository(map[string]interface{}{ | ||
34 | +// "transactionContext": transactionContext, | ||
35 | +// }); err != nil { | ||
36 | +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
37 | +// } else { | ||
38 | +// partnerRepository = value | ||
39 | +// } | ||
40 | +// if partner, err := partnerRepository.Save(newPartner); err != nil { | ||
41 | +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
42 | +// } else { | ||
43 | +// if err := transactionContext.CommitTransaction(); err != nil { | ||
44 | +// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
45 | +// } | ||
46 | +// return partner, nil | ||
47 | +// } | ||
48 | +//} | ||
49 | +// | ||
50 | +//// 返回合伙人增删改查 | ||
51 | +//func (partnerService *PartnerService) GetPartner(getPartnerQuery *query.GetPartnerQuery) (interface{}, error) { | ||
52 | +// if err := getPartnerQuery.ValidateQuery(); err != nil { | ||
53 | +// return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
54 | +// } | ||
55 | +// transactionContext, err := factory.CreateTransactionContext(nil) | ||
56 | +// if err != nil { | ||
57 | +// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
58 | +// } | ||
59 | +// if err := transactionContext.StartTransaction(); err != nil { | ||
60 | +// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
61 | +// } | ||
62 | +// defer func() { | ||
63 | +// transactionContext.RollbackTransaction() | ||
64 | +// }() | ||
65 | +// var partnerRepository partner.PartnerRepository | ||
66 | +// if value, err := factory.CreatePartnerRepository(map[string]interface{}{ | ||
67 | +// "transactionContext": transactionContext, | ||
68 | +// }); err != nil { | ||
69 | +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
70 | +// } else { | ||
71 | +// partnerRepository = value | ||
72 | +// } | ||
73 | +// partner, err := partnerRepository.FindOne(map[string]interface{}{"partnerId": getPartnerQuery.PartnerId}) | ||
74 | +// if err != nil { | ||
75 | +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
76 | +// } | ||
77 | +// if partner == nil { | ||
78 | +// return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getPartnerQuery.PartnerId))) | ||
79 | +// } else { | ||
80 | +// if err := transactionContext.CommitTransaction(); err != nil { | ||
81 | +// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
82 | +// } | ||
83 | +// return partner, nil | ||
84 | +// } | ||
85 | +//} | ||
86 | +// | ||
87 | +//// 返回合伙人增删改查列表 | ||
88 | +//func (partnerService *PartnerService) ListPartner(listPartnerQuery *query.ListPartnerQuery) (interface{}, error) { | ||
89 | +// if err := listPartnerQuery.ValidateQuery(); err != nil { | ||
90 | +// return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
91 | +// } | ||
92 | +// transactionContext, err := factory.CreateTransactionContext(nil) | ||
93 | +// if err != nil { | ||
94 | +// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
95 | +// } | ||
96 | +// if err := transactionContext.StartTransaction(); err != nil { | ||
97 | +// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
98 | +// } | ||
99 | +// defer func() { | ||
100 | +// transactionContext.RollbackTransaction() | ||
101 | +// }() | ||
102 | +// var partnerRepository partner.PartnerRepository | ||
103 | +// if value, err := factory.CreatePartnerRepository(map[string]interface{}{ | ||
104 | +// "transactionContext": transactionContext, | ||
105 | +// }); err != nil { | ||
106 | +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
107 | +// } else { | ||
108 | +// partnerRepository = value | ||
109 | +// } | ||
110 | +// if count, partners, err := partnerRepository.Find(tool_funs.SimpleStructToMap(listPartnerQuery)); err != nil { | ||
111 | +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
112 | +// } else { | ||
113 | +// if err := transactionContext.CommitTransaction(); err != nil { | ||
114 | +// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
115 | +// } | ||
116 | +// return map[string]interface{}{ | ||
117 | +// "count": count, | ||
118 | +// "partners": partners, | ||
119 | +// }, nil | ||
120 | +// } | ||
121 | +//} | ||
122 | + | ||
123 | +// 合伙人分类列表 | ||
124 | +func (partnerService *PartnerService) PartnerCategories(partnerCategoriesQuery *query.PartnerCategoriesQuery) (interface{}, error) { | ||
125 | + if err := partnerCategoriesQuery.ValidateQuery(); err != nil { | ||
126 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
127 | + } | ||
128 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
129 | + if err != nil { | ||
130 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
131 | + } | ||
132 | + if err := transactionContext.StartTransaction(); err != nil { | ||
133 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
134 | + } | ||
135 | + defer func() { | ||
136 | + transactionContext.RollbackTransaction() | ||
137 | + }() | ||
138 | + PartnerCategoryRepository, err := factory.CreatePartnerCategoryRepository(map[string]interface{}{"transactionContext": transactionContext}) | ||
139 | + if err != nil { | ||
140 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
141 | + } | ||
142 | + total, categories, err := PartnerCategoryRepository.Find(map[string]interface{}{}) | ||
143 | + if err != nil { | ||
144 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
145 | + } | ||
146 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
147 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
148 | + } | ||
149 | + return map[string]interface{}{"total": total, "categories": categories}, nil | ||
150 | +} | ||
151 | + | ||
152 | +//// 移除合伙人增删改查 | ||
153 | +//func (partnerService *PartnerService) RemovePartner(removePartnerCommand *command.RemovePartnerCommand) (interface{}, error) { | ||
154 | +// if err := removePartnerCommand.ValidateCommand(); err != nil { | ||
155 | +// return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
156 | +// } | ||
157 | +// transactionContext, err := factory.CreateTransactionContext(nil) | ||
158 | +// if err != nil { | ||
159 | +// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
160 | +// } | ||
161 | +// if err := transactionContext.StartTransaction(); err != nil { | ||
162 | +// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
163 | +// } | ||
164 | +// defer func() { | ||
165 | +// transactionContext.RollbackTransaction() | ||
166 | +// }() | ||
167 | +// var partnerRepository partner.PartnerRepository | ||
168 | +// if value, err := factory.CreatePartnerRepository(map[string]interface{}{ | ||
169 | +// "transactionContext": transactionContext, | ||
170 | +// }); err != nil { | ||
171 | +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
172 | +// } else { | ||
173 | +// partnerRepository = value | ||
174 | +// } | ||
175 | +// partner, err := partnerRepository.FindOne(map[string]interface{}{"partnerId": removePartnerCommand.PartnerId}) | ||
176 | +// if err != nil { | ||
177 | +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
178 | +// } | ||
179 | +// if partner == nil { | ||
180 | +// return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removePartnerCommand.PartnerId))) | ||
181 | +// } | ||
182 | +// if partner, err := partnerRepository.Remove(partner); err != nil { | ||
183 | +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
184 | +// } else { | ||
185 | +// if err := transactionContext.CommitTransaction(); err != nil { | ||
186 | +// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
187 | +// } | ||
188 | +// return partner, nil | ||
189 | +// } | ||
190 | +//} | ||
191 | +// | ||
192 | +//// 更新合伙人增删改查 | ||
193 | +//func (partnerService *PartnerService) UpdatePartner(updatePartnerCommand *command.UpdatePartnerCommand) (interface{}, error) { | ||
194 | +// if err := updatePartnerCommand.ValidateCommand(); err != nil { | ||
195 | +// return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
196 | +// } | ||
197 | +// transactionContext, err := factory.CreateTransactionContext(nil) | ||
198 | +// if err != nil { | ||
199 | +// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
200 | +// } | ||
201 | +// if err := transactionContext.StartTransaction(); err != nil { | ||
202 | +// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
203 | +// } | ||
204 | +// defer func() { | ||
205 | +// transactionContext.RollbackTransaction() | ||
206 | +// }() | ||
207 | +// var partnerRepository partner.PartnerRepository | ||
208 | +// if value, err := factory.CreatePartnerRepository(map[string]interface{}{ | ||
209 | +// "transactionContext": transactionContext, | ||
210 | +// }); err != nil { | ||
211 | +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
212 | +// } else { | ||
213 | +// partnerRepository = value | ||
214 | +// } | ||
215 | +// partner, err := partnerRepository.FindOne(map[string]interface{}{"partnerId": updatePartnerCommand.PartnerId}) | ||
216 | +// if err != nil { | ||
217 | +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
218 | +// } | ||
219 | +// if partner == nil { | ||
220 | +// return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updatePartnerCommand.PartnerId))) | ||
221 | +// } | ||
222 | +// if err := partner.Update(tool_funs.SimpleStructToMap(updatePartnerCommand)); err != nil { | ||
223 | +// return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | ||
224 | +// } | ||
225 | +// if partner, err := partnerRepository.Save(partner); err != nil { | ||
226 | +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
227 | +// } else { | ||
228 | +// if err := transactionContext.CommitTransaction(); err != nil { | ||
229 | +// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
230 | +// } | ||
231 | +// return partner, nil | ||
232 | +// } | ||
233 | +//} | ||
234 | + | ||
235 | +func NewPartnerService(options map[string]interface{}) *PartnerService { | ||
236 | + newPartnerService := &PartnerService{} | ||
237 | + return newPartnerService | ||
238 | +} |
pkg/application/permission/query/menus.go
0 → 100644
1 | +package query | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/beego/beego/v2/core/validation" | ||
7 | +) | ||
8 | + | ||
9 | +type MenusQuery struct { | ||
10 | + // 用户id | ||
11 | + UserId int64 `json:"userId"` | ||
12 | +} | ||
13 | + | ||
14 | +func (menusQuery *MenusQuery) Valid(validation *validation.Validation) { | ||
15 | + | ||
16 | +} | ||
17 | + | ||
18 | +func (menusQuery *MenusQuery) ValidateQuery() error { | ||
19 | + valid := validation.Validation{} | ||
20 | + b, err := valid.Valid(menusQuery) | ||
21 | + if err != nil { | ||
22 | + return err | ||
23 | + } | ||
24 | + if !b { | ||
25 | + for _, validErr := range valid.Errors { | ||
26 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
27 | + } | ||
28 | + } | ||
29 | + return nil | ||
30 | +} |
1 | +package service | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/linmadan/egglib-go/core/application" | ||
5 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/application/factory" | ||
6 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/application/permission/query" | ||
7 | +) | ||
8 | + | ||
9 | +// 权限服务 | ||
10 | +type PermissionService struct { | ||
11 | +} | ||
12 | + | ||
13 | +// 根据当前用户返回权限列表 | ||
14 | +func (permissionService *PermissionService) Menus(menusQuery *query.MenusQuery) (interface{}, error) { | ||
15 | + if err := menusQuery.ValidateQuery(); err != nil { | ||
16 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
17 | + } | ||
18 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
19 | + if err != nil { | ||
20 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
21 | + } | ||
22 | + if err := transactionContext.StartTransaction(); err != nil { | ||
23 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
24 | + } | ||
25 | + defer func() { | ||
26 | + transactionContext.RollbackTransaction() | ||
27 | + }() | ||
28 | + | ||
29 | + PermissionRepository, err := factory.CreatePermissionRepository(map[string]interface{}{"transactionContext": transactionContext}) | ||
30 | + if err != nil { | ||
31 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
32 | + } | ||
33 | + total, permissions, err := PermissionRepository.Find(map[string]interface{}{}) | ||
34 | + if err != nil { | ||
35 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
36 | + } | ||
37 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
38 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
39 | + } | ||
40 | + return map[string]interface{}{"total": total, "permissions": permissions}, nil | ||
41 | +} | ||
42 | + | ||
43 | +func NewPermissionService(options map[string]interface{}) *PermissionService { | ||
44 | + newPermissionService := &PermissionService{} | ||
45 | + return newPermissionService | ||
46 | +} |
pkg/constant/common.go
0 → 100644
pkg/constant/gateway.go
0 → 100644
pkg/constant/postgresql.go
0 → 100644
1 | +package constant | ||
2 | + | ||
3 | +import "os" | ||
4 | + | ||
5 | +var POSTGRESQL_DB_NAME = "partner01" | ||
6 | +var POSTGRESQL_USER = "postgres" | ||
7 | +var POSTGRESQL_PASSWORD = "eagle1010" | ||
8 | +var POSTGRESQL_HOST = "114.55.200.59" | ||
9 | +var POSTGRESQL_PORT = "31543" | ||
10 | +var DISABLE_CREATE_TABLE = false | ||
11 | +var DISABLE_SQL_GENERATE_PRINT = false | ||
12 | + | ||
13 | +func init() { | ||
14 | + if os.Getenv("POSTGRESQL_DB_NAME") != "" { | ||
15 | + POSTGRESQL_DB_NAME = os.Getenv("POSTGRESQL_DB_NAME") | ||
16 | + } | ||
17 | + if os.Getenv("POSTGRESQL_USER") != "" { | ||
18 | + POSTGRESQL_USER = os.Getenv("POSTGRESQL_USER") | ||
19 | + } | ||
20 | + if os.Getenv("POSTGRESQL_PASSWORD") != "" { | ||
21 | + POSTGRESQL_PASSWORD = os.Getenv("POSTGRESQL_PASSWORD") | ||
22 | + } | ||
23 | + if os.Getenv("POSTGRESQL_HOST") != "" { | ||
24 | + POSTGRESQL_HOST = os.Getenv("POSTGRESQL_HOST") | ||
25 | + } | ||
26 | + if os.Getenv("POSTGRESQL_PORT") != "" { | ||
27 | + POSTGRESQL_PORT = os.Getenv("POSTGRESQL_PORT") | ||
28 | + } | ||
29 | + if os.Getenv("DISABLE_CREATE_TABLE") != "" { | ||
30 | + DISABLE_CREATE_TABLE = true | ||
31 | + } | ||
32 | + if os.Getenv("DISABLE_SQL_GENERATE_PRINT") != "" { | ||
33 | + DISABLE_SQL_GENERATE_PRINT = true | ||
34 | + } | ||
35 | +} |
pkg/domain/auth.go
0 → 100644
1 | +package domain | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/dgrijalva/jwt-go" | ||
5 | + eggJwt "github.com/linmadan/egglib-go/utils/jwt" | ||
6 | + "time" | ||
7 | +) | ||
8 | + | ||
9 | +const ( | ||
10 | + secret = "$^%$Rdefault&*^(*&" | ||
11 | +) | ||
12 | + | ||
13 | +const ( | ||
14 | + AccessTokenExpire = 3600 | ||
15 | +) | ||
16 | + | ||
17 | +type UserTokenClaim struct { | ||
18 | + jwt.StandardClaims | ||
19 | + UserId int64 `json:"userId"` | ||
20 | + CompanyId int64 `json:"companyId"` | ||
21 | +} | ||
22 | + | ||
23 | +func NewUserTokenClaim(userId, companyId int64, expire int64) UserTokenClaim { | ||
24 | + return UserTokenClaim{ | ||
25 | + UserId: userId, | ||
26 | + CompanyId: companyId, | ||
27 | + StandardClaims: jwt.StandardClaims{ExpiresAt: expire}, | ||
28 | + } | ||
29 | +} | ||
30 | + | ||
31 | +func SignToken(userId int64, companyId int64) string { | ||
32 | + claim := NewUserTokenClaim(int64(userId), companyId, time.Now().Add(time.Second*AccessTokenExpire).Unix()) | ||
33 | + token, _ := eggJwt.Sign(claim, secret, "") | ||
34 | + return token | ||
35 | +} | ||
36 | + | ||
37 | +func ValidToken(token string, claims *UserTokenClaim) (bool, error) { | ||
38 | + result, c, err := eggJwt.Valid(token, claims, secret) | ||
39 | + claims = c.Claims.(*UserTokenClaim) | ||
40 | + return result, err | ||
41 | +} |
pkg/domain/buyer_info.go
0 → 100644
pkg/domain/company.go
0 → 100644
1 | +package domain | ||
2 | + | ||
3 | +import "time" | ||
4 | + | ||
5 | +// 公司信息 | ||
6 | +type Company struct { | ||
7 | + // 公司Id | ||
8 | + CompanyId int64 `json:"companyId"` | ||
9 | + // 公司信息 | ||
10 | + CompanyInfo *CompanyInfo `json:"companyInfo"` | ||
11 | + // 创建时间 | ||
12 | + CreateAt time.Time `json:"createAt"` | ||
13 | + // 更新时间 | ||
14 | + UpdateAt time.Time `json:"updateAt"` | ||
15 | + // 删除时间 | ||
16 | + DeleteAt time.Time `json:"deleteAt"` | ||
17 | +} | ||
18 | + | ||
19 | +type CompanyRepository interface { | ||
20 | + Save(company *Company) (*Company, error) | ||
21 | + Remove(company *Company) (*Company, error) | ||
22 | + FindOne(queryOptions map[string]interface{}) (*Company, error) | ||
23 | + Find(queryOptions map[string]interface{}) (int64, []*Company, error) | ||
24 | +} | ||
25 | + | ||
26 | +func (company *Company) Identify() interface{} { | ||
27 | + if company.CompanyId == 0 { | ||
28 | + return nil | ||
29 | + } | ||
30 | + return company.CompanyId | ||
31 | +} | ||
32 | + | ||
33 | +func (company *Company) Update(data map[string]interface{}) error { | ||
34 | + if companyId, ok := data["companyId"]; ok { | ||
35 | + company.CompanyId = companyId.(int64) | ||
36 | + } | ||
37 | + if name, ok := data["name"]; ok { | ||
38 | + company.CompanyInfo.Name = name.(string) | ||
39 | + } | ||
40 | + if abbreviation, ok := data["abbreviation"]; ok { | ||
41 | + company.CompanyInfo.Abbreviation = abbreviation.(string) | ||
42 | + } | ||
43 | + if logo, ok := data["logo"]; ok { | ||
44 | + company.CompanyInfo.Logo = logo.(string) | ||
45 | + } | ||
46 | + if phone, ok := data["phone"]; ok { | ||
47 | + company.CompanyInfo.Phone = phone.(string) | ||
48 | + } | ||
49 | + if status, ok := data["status"]; ok { | ||
50 | + company.CompanyInfo.Status = status.(int64) | ||
51 | + } | ||
52 | + if remarks, ok := data["remarks"]; ok { | ||
53 | + company.CompanyInfo.Remarks = remarks.(string) | ||
54 | + } | ||
55 | + if enable, ok := data["enable"]; ok { | ||
56 | + company.CompanyInfo.Enable = enable.(int64) | ||
57 | + } | ||
58 | + if userAccount, ok := data["userAccount"]; ok { | ||
59 | + company.CompanyInfo.Admin.UserAccount = userAccount.(string) | ||
60 | + } | ||
61 | + if userName, ok := data["userName"]; ok { | ||
62 | + company.CompanyInfo.Admin.UserName = userName.(string) | ||
63 | + } | ||
64 | + | ||
65 | + if createAt, ok := data["createAt"]; ok { | ||
66 | + company.CreateAt = createAt.(time.Time) | ||
67 | + } | ||
68 | + if updateAt, ok := data["updateAt"]; ok { | ||
69 | + company.UpdateAt = updateAt.(time.Time) | ||
70 | + } | ||
71 | + if deleteAt, ok := data["deleteAt"]; ok { | ||
72 | + company.DeleteAt = deleteAt.(time.Time) | ||
73 | + } | ||
74 | + | ||
75 | + return nil | ||
76 | +} | ||
77 | + | ||
78 | +// 更改公司管理员信息 | ||
79 | +func (company *Company) SetCompanyAdmin(admin *CompanyAdmin) error { | ||
80 | + company.CompanyInfo.Admin = admin | ||
81 | + return nil | ||
82 | +} |
pkg/domain/company_info.go
0 → 100644
1 | +package domain | ||
2 | + | ||
3 | +// 公司信息 | ||
4 | +type CompanyInfo struct { | ||
5 | + Name string `json:"name"` // 公司名称 | ||
6 | + Abbreviation string `json:"abbreviation"` // 公司简称 | ||
7 | + Logo string `json:"logo"` // 公司logo | ||
8 | + Phone string `json:"phone"` // 公司联系电话 | ||
9 | + Status int64 `json:"status"` // 状态 1正常 2禁用 | ||
10 | + Remarks string `json:"remarks"` // 备注 | ||
11 | + Enable int64 `json:"enable"` // 是否有效【1:有效】【2:无效】 | ||
12 | + Admin *CompanyAdmin `json:"admin"` // 公司主管理员 | ||
13 | +} | ||
14 | + | ||
15 | +// 公司管理员信息值对象 | ||
16 | +type CompanyAdmin struct { | ||
17 | + UserAccount string `json:"userPhone"` // 用户手机号 | ||
18 | + UserName string `json:"userName"` // 用户名称 | ||
19 | +} |
pkg/domain/dividend.go
0 → 100644
1 | +package domain | ||
2 | + | ||
3 | +// 分红值对象 | ||
4 | +type Dividend struct { | ||
5 | + // 计划分红 | ||
6 | + PlanBonus float64 `json:"planBonus"` | ||
7 | + // 调整后分红 | ||
8 | + UseBonus float64 `json:"useBonus"` | ||
9 | + // 已收分红 | ||
10 | + BonusHas float64 `json:"bonusHas"` | ||
11 | + // 未收分红 | ||
12 | + BonusNot float64 `json:"bonusNot"` | ||
13 | + // 分红支出 | ||
14 | + BonusExpense float64 `json:"bonusExpense"` | ||
15 | + // 分红状态(1:待支付 2:已支付) | ||
16 | + BonusStatus int `json:"bonusStatus"` | ||
17 | + // 合伙人分红比例 | ||
18 | + PartnerBonusPercent float64 `json:"partnerBonusPercent"` | ||
19 | + // 业务员抽成比例 | ||
20 | + SalesmanBonusPercent float64 `json:"salesmanBonusPercent"` | ||
21 | + // 业务员抽成 | ||
22 | + SalesmanBonus float64 `json:"salesmanBonus"` | ||
23 | +} |
pkg/domain/goods.go
0 → 100644
1 | +package domain | ||
2 | + | ||
3 | +import "time" | ||
4 | + | ||
5 | +// 订单商品实体 | ||
6 | +type Goods struct { | ||
7 | + // 商品id | ||
8 | + GoodsId int64 `json:"goodsId"` | ||
9 | + // 预定的货品数量 | ||
10 | + GoodsNum int `json:"goodsNum"` | ||
11 | + // 商品分红支付信息 | ||
12 | + GoodsDividend *Dividend `json:"goodsDividend"` | ||
13 | + // 商品分红支付状态 | ||
14 | + GoodsDividendStatus int `json:"goodsDividendStatus"` | ||
15 | + // 商品名称 | ||
16 | + GoodsName string `json:"goodsName"` | ||
17 | + // 商品单价 | ||
18 | + GoodsTotalPrice float64 `json:"goodsTotalPrice"` | ||
19 | + // 备注 | ||
20 | + Remarks string `json:"remarks"` | ||
21 | + // 订单编号 | ||
22 | + OrderNo string `json:"orderNo"` | ||
23 | + GoodsDetail string `json:"goodsDetail"` | ||
24 | + // 创建时间 | ||
25 | + CreateAt time.Time `json:"createAt"` | ||
26 | + // 更新时间 | ||
27 | + UpdateAt time.Time `json:"updateAt"` | ||
28 | + // 删除时间 | ||
29 | + DeleteAt time.Time `json:"deleteAt"` | ||
30 | +} | ||
31 | + | ||
32 | +type GoodsRepository interface { | ||
33 | + Save(goods *Goods) (*Goods, error) | ||
34 | + Remove(goods *Goods) (*Goods, error) | ||
35 | + FindOne(queryOptions map[string]interface{}) (*Goods, error) | ||
36 | + Find(queryOptions map[string]interface{}) (int64, []*Goods, error) | ||
37 | +} | ||
38 | + | ||
39 | +func (goods *Goods) Identify() interface{} { | ||
40 | + if goods.GoodsId == 0 { | ||
41 | + return nil | ||
42 | + } | ||
43 | + return goods.GoodsId | ||
44 | +} | ||
45 | + | ||
46 | +func (goods *Goods) Update(data map[string]interface{}) error { | ||
47 | + if goodsId, ok := data["goodsId"]; ok { | ||
48 | + goods.GoodsId = goodsId.(int64) | ||
49 | + } | ||
50 | + if goodsNum, ok := data["goodsNum"]; ok { | ||
51 | + goods.GoodsNum = goodsNum.(int) | ||
52 | + } | ||
53 | + if planBonus, ok := data["planBonus"]; ok { | ||
54 | + goods.GoodsDividend.PlanBonus = planBonus.(float64) | ||
55 | + } | ||
56 | + if useBonus, ok := data["useBonus"]; ok { | ||
57 | + goods.GoodsDividend.UseBonus = useBonus.(float64) | ||
58 | + } | ||
59 | + if bonusHas, ok := data["bonusHas"]; ok { | ||
60 | + goods.GoodsDividend.BonusHas = bonusHas.(float64) | ||
61 | + } | ||
62 | + if bonusNot, ok := data["bonusNot"]; ok { | ||
63 | + goods.GoodsDividend.BonusNot = bonusNot.(float64) | ||
64 | + } | ||
65 | + if bonusExpense, ok := data["bonusExpense"]; ok { | ||
66 | + goods.GoodsDividend.BonusExpense = bonusExpense.(float64) | ||
67 | + } | ||
68 | + if bonusStatus, ok := data["bonusStatus"]; ok { | ||
69 | + goods.GoodsDividend.BonusStatus = bonusStatus.(int) | ||
70 | + } | ||
71 | + if partnerBonusPercent, ok := data["partnerBonusPercent"]; ok { | ||
72 | + goods.GoodsDividend.PartnerBonusPercent = partnerBonusPercent.(float64) | ||
73 | + } | ||
74 | + if salesmanBonusPercent, ok := data["salesmanBonusPercent"]; ok { | ||
75 | + goods.GoodsDividend.SalesmanBonusPercent = salesmanBonusPercent.(float64) | ||
76 | + } | ||
77 | + if salesmanBonus, ok := data["salesmanBonus"]; ok { | ||
78 | + goods.GoodsDividend.SalesmanBonus = salesmanBonus.(float64) | ||
79 | + } | ||
80 | + if goodsDividendStatus, ok := data["goodsDividendStatus"]; ok { | ||
81 | + goods.GoodsDividendStatus = goodsDividendStatus.(int) | ||
82 | + } | ||
83 | + if goodsName, ok := data["goodsName"]; ok { | ||
84 | + goods.GoodsName = goodsName.(string) | ||
85 | + } | ||
86 | + if goodsTotalPrice, ok := data["goodsTotalPrice"]; ok { | ||
87 | + goods.GoodsTotalPrice = goodsTotalPrice.(float64) | ||
88 | + } | ||
89 | + if remarks, ok := data["remarks"]; ok { | ||
90 | + goods.Remarks = remarks.(string) | ||
91 | + } | ||
92 | + if orderNo, ok := data["orderNo"]; ok { | ||
93 | + goods.OrderNo = orderNo.(string) | ||
94 | + } | ||
95 | + if goodsDetail, ok := data["goodsDetail"]; ok { | ||
96 | + goods.GoodsDetail = goodsDetail.(string) | ||
97 | + } | ||
98 | + if createAt, ok := data["createAt"]; ok { | ||
99 | + goods.CreateAt = createAt.(time.Time) | ||
100 | + } | ||
101 | + if updateAt, ok := data["updateAt"]; ok { | ||
102 | + goods.UpdateAt = updateAt.(time.Time) | ||
103 | + } | ||
104 | + if deleteAt, ok := data["deleteAt"]; ok { | ||
105 | + goods.DeleteAt = deleteAt.(time.Time) | ||
106 | + } | ||
107 | + return nil | ||
108 | +} |
pkg/domain/order.go
0 → 100644
1 | +package domain | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "time" | ||
6 | +) | ||
7 | + | ||
8 | +// 订单类型 | ||
9 | +const ( | ||
10 | + ORDER_TYPE_ACTUAL = iota + 1 //实际订单 | ||
11 | + ORDER_TYPE_INTENTION // 意向订单 | ||
12 | +) | ||
13 | + | ||
14 | +// 订单状态 | ||
15 | +const ( | ||
16 | + ORDER_STATUS_UNSHIPPED = iota + 1 // 待发货 | ||
17 | + ORDER_STATUS_TRANSIT // 待收货(运输中) | ||
18 | + ORDER_STATUS_RECEIVED // 已收货 | ||
19 | + ORDER_STATUS_RETURN // 退换货 | ||
20 | + ORDER_STATUS_CANCELED // 已取消(关闭) | ||
21 | + ORDER_STATUS_COMPLETED // 已完成 | ||
22 | +) | ||
23 | + | ||
24 | +// 订单实体 | ||
25 | +type Order struct { | ||
26 | + // 订单id | ||
27 | + OrderId int64 `json:"orderId"` | ||
28 | + // 买家信息 | ||
29 | + Buyer *BuyerInfo `json:"buyer"` | ||
30 | + // 公司Id | ||
31 | + CompanyId int64 `json:"companyId"` | ||
32 | + // 合伙人id | ||
33 | + PartnerId int64 `json:"partnerId"` | ||
34 | + // 发货单号 | ||
35 | + DeliveryCode string `json:"deliveryCode"` | ||
36 | + // 是否关闭订单标志 | ||
37 | + IsDisable int `json:"isDisable"` | ||
38 | + // 订单编号 | ||
39 | + OrderNo string `json:"orderNo"` | ||
40 | + // 订单详情 | ||
41 | + OrderDetail *OrderDetail `json:"orderDetail"` | ||
42 | + // 订单分红信息 | ||
43 | + OrderDividend *Dividend `json:"orderDividend"` | ||
44 | + // 订单分红支付状态 | ||
45 | + OrderDividendStatus int `json:"orderDividendStatus"` | ||
46 | + // 订单货品 | ||
47 | + OrderGoods []*Goods `json:"orderGoods"` | ||
48 | + // 订单数据来源 | ||
49 | + OrderSource *OrderSource `json:"orderSource"` | ||
50 | + // 订单类型(1.实际订单;2.意向订单) | ||
51 | + OrderType int `json:"orderType"` | ||
52 | + // 订单状态(1.发货;2.收货;3.退货;4.取消;5.完成) | ||
53 | + OrderStatus int `json:"orderStatus"` | ||
54 | + // 订单总价 | ||
55 | + TotalPrice float64 `json:"totalPrice"` | ||
56 | + // 订单区域信息 | ||
57 | + RegionInfo *RegionInfo `json:"regionInfo"` | ||
58 | + // 备注 | ||
59 | + Remarks string `json:"remarks"` | ||
60 | + // 创建时间 | ||
61 | + CreateAt time.Time `json:"createAt"` | ||
62 | + // 更新时间 | ||
63 | + UpdateAt time.Time `json:"updateAt"` | ||
64 | + // 软删 | ||
65 | + DeleteAt time.Time `json:"deleteAt"` | ||
66 | + // 当前状态 | ||
67 | + CurrentStatus OrderStatus `json:"-"` | ||
68 | +} | ||
69 | + | ||
70 | +// 订单状态机 | ||
71 | +type OrderStatus interface { | ||
72 | + Update(order *Order, data map[string]interface{}) error // 更新订单 | ||
73 | + Checkout(order *Order) error // 下单 | ||
74 | + Return(order *Order) error // 退换货 | ||
75 | + Cancel(order *Order) error // 取消订单 | ||
76 | + Receive(order *Order) error // 收货 | ||
77 | +} | ||
78 | + | ||
79 | +// 代发货状态 | ||
80 | +type UnShippedStatus struct{} | ||
81 | + | ||
82 | +// 编辑待发货订单 | ||
83 | +func (status *UnShippedStatus) Update(order *Order, data map[string]interface{}) error { | ||
84 | + if orderId, ok := data["orderId"]; ok { | ||
85 | + order.OrderId = orderId.(int64) | ||
86 | + } | ||
87 | + if buyerName, ok := data["buyerName"]; ok { | ||
88 | + order.Buyer.BuyerName = buyerName.(string) | ||
89 | + } | ||
90 | + if contactInfo, ok := data["contactInfo"]; ok { | ||
91 | + order.Buyer.ContactInfo = contactInfo.(string) | ||
92 | + } | ||
93 | + if shippingAddress, ok := data["shippingAddress"]; ok { | ||
94 | + order.Buyer.ShippingAddress = shippingAddress.(string) | ||
95 | + } | ||
96 | + if companyId, ok := data["companyId"]; ok { | ||
97 | + order.CompanyId = companyId.(int64) | ||
98 | + } | ||
99 | + if partnerId, ok := data["partnerId"]; ok { | ||
100 | + order.PartnerId = partnerId.(int64) | ||
101 | + } | ||
102 | + if deliveryCode, ok := data["deliveryCode"]; ok { | ||
103 | + order.DeliveryCode = deliveryCode.(string) | ||
104 | + } | ||
105 | + if isDisable, ok := data["isDisable"]; ok { | ||
106 | + order.IsDisable = isDisable.(int) | ||
107 | + } | ||
108 | + if orderNo, ok := data["orderNo"]; ok { | ||
109 | + order.OrderNo = orderNo.(string) | ||
110 | + } | ||
111 | + if orderDetailId, ok := data["orderDetailId"]; ok { | ||
112 | + order.OrderDetail.OrderDetailId = orderDetailId.(int64) | ||
113 | + } | ||
114 | + if orderNo, ok := data["orderNo"]; ok { | ||
115 | + order.OrderDetail.OrderNo = orderNo.(string) | ||
116 | + } | ||
117 | + if orderNum, ok := data["orderNum"]; ok { | ||
118 | + order.OrderDetail.OrderNum = orderNum.(int) | ||
119 | + } | ||
120 | + if totalPrice, ok := data["totalPrice"]; ok { | ||
121 | + order.OrderDetail.TotalPrice = totalPrice.(float64) | ||
122 | + } | ||
123 | + if adjustedNum, ok := data["adjustedNum"]; ok { | ||
124 | + order.OrderDetail.AdjustedNum = adjustedNum.(int) | ||
125 | + } | ||
126 | + if adjustedTotalPrice, ok := data["adjustedTotalPrice"]; ok { | ||
127 | + order.OrderDetail.AdjustedTotalPrice = adjustedTotalPrice.(float64) | ||
128 | + } | ||
129 | + if planBonus, ok := data["planBonus"]; ok { | ||
130 | + order.OrderDividend.PlanBonus = planBonus.(float64) | ||
131 | + } | ||
132 | + if useBonus, ok := data["useBonus"]; ok { | ||
133 | + order.OrderDividend.UseBonus = useBonus.(float64) | ||
134 | + } | ||
135 | + if bonusHas, ok := data["bonusHas"]; ok { | ||
136 | + order.OrderDividend.BonusHas = bonusHas.(float64) | ||
137 | + } | ||
138 | + if bonusNot, ok := data["bonusNot"]; ok { | ||
139 | + order.OrderDividend.BonusNot = bonusNot.(float64) | ||
140 | + } | ||
141 | + if bonusExpense, ok := data["bonusExpense"]; ok { | ||
142 | + order.OrderDividend.BonusExpense = bonusExpense.(float64) | ||
143 | + } | ||
144 | + if bonusStatus, ok := data["bonusStatus"]; ok { | ||
145 | + order.OrderDividend.BonusStatus = bonusStatus.(int) | ||
146 | + } | ||
147 | + if partnerBonusPercent, ok := data["partnerBonusPercent"]; ok { | ||
148 | + order.OrderDividend.PartnerBonusPercent = partnerBonusPercent.(float64) | ||
149 | + } | ||
150 | + if salesmanBonusPercent, ok := data["salesmanBonusPercent"]; ok { | ||
151 | + order.OrderDividend.SalesmanBonusPercent = salesmanBonusPercent.(float64) | ||
152 | + } | ||
153 | + if salesmanBonus, ok := data["salesmanBonus"]; ok { | ||
154 | + order.OrderDividend.SalesmanBonus = salesmanBonus.(float64) | ||
155 | + } | ||
156 | + if orderDividendStatus, ok := data["orderDividendStatus"]; ok { | ||
157 | + order.OrderDividendStatus = orderDividendStatus.(int) | ||
158 | + } | ||
159 | + if orderGoods, ok := data["orderGoods"]; ok { | ||
160 | + order.OrderGoods = orderGoods.([]*Goods) | ||
161 | + } | ||
162 | + if dataSourceId, ok := data["dataSourceId"]; ok { | ||
163 | + order.OrderSource.DataSourceId = dataSourceId.(int64) | ||
164 | + } | ||
165 | + if platform, ok := data["platform"]; ok { | ||
166 | + order.OrderSource.Platform = platform.(string) | ||
167 | + } | ||
168 | + if createAt, ok := data["createAt"]; ok { | ||
169 | + order.OrderSource.CreateAt = createAt.(time.Time) | ||
170 | + } | ||
171 | + if orderType, ok := data["orderType"]; ok { | ||
172 | + order.OrderType = orderType.(int) | ||
173 | + } | ||
174 | + if orderStatus, ok := data["orderStatus"]; ok { | ||
175 | + order.OrderStatus = orderStatus.(int) | ||
176 | + } | ||
177 | + if totalPrice, ok := data["totalPrice"]; ok { | ||
178 | + order.TotalPrice = totalPrice.(float64) | ||
179 | + } | ||
180 | + if regionName, ok := data["regionName"]; ok { | ||
181 | + order.RegionInfo.RegionName = regionName.(string) | ||
182 | + } | ||
183 | + if remarks, ok := data["remarks"]; ok { | ||
184 | + order.Remarks = remarks.(string) | ||
185 | + } | ||
186 | + if createAt, ok := data["createAt"]; ok { | ||
187 | + order.CreateAt = createAt.(time.Time) | ||
188 | + } | ||
189 | + if updateAt, ok := data["updateAt"]; ok { | ||
190 | + order.UpdateAt = updateAt.(time.Time) | ||
191 | + } | ||
192 | + if deleteAt, ok := data["deleteAt"]; ok { | ||
193 | + order.DeleteAt = deleteAt.(time.Time) | ||
194 | + } | ||
195 | + return nil | ||
196 | +} | ||
197 | + | ||
198 | +func (status *UnShippedStatus) Checkout(order *Order) error { | ||
199 | + return nil | ||
200 | +} | ||
201 | + | ||
202 | +func (status *UnShippedStatus) Return(order *Order) error { | ||
203 | + return fmt.Errorf("待发货订单不能退货") | ||
204 | +} | ||
205 | + | ||
206 | +func (status *UnShippedStatus) Cancel(order *Order) error { | ||
207 | + return nil | ||
208 | +} | ||
209 | + | ||
210 | +func (status *UnShippedStatus) Receive(order *Order) error { | ||
211 | + return fmt.Errorf("待发货订单不能收货") | ||
212 | +} | ||
213 | + | ||
214 | +// 待收货状态 | ||
215 | +type TransitStatus struct{} | ||
216 | + | ||
217 | +// 待收货订单不允许编辑 | ||
218 | +func (status *TransitStatus) Update(order *Order, data map[string]interface{}) error { | ||
219 | + return fmt.Errorf("已发货订单不允许编辑") | ||
220 | +} | ||
221 | + | ||
222 | +func (status *TransitStatus) Checkout(order *Order) error { | ||
223 | + return fmt.Errorf("待收货订单不能重复发货") | ||
224 | +} | ||
225 | + | ||
226 | +func (status *TransitStatus) Return(order *Order) error { | ||
227 | + return nil | ||
228 | +} | ||
229 | + | ||
230 | +func (status *TransitStatus) Cancel(order *Order) error { | ||
231 | + return fmt.Errorf("待收货订单不能取消") | ||
232 | +} | ||
233 | + | ||
234 | +func (status *TransitStatus) Receive(order *Order) error { | ||
235 | + return nil | ||
236 | +} | ||
237 | + | ||
238 | +// 收货状态 | ||
239 | +type ReceivedStatus struct{} | ||
240 | + | ||
241 | +func (status *ReceivedStatus) Update(order *Order, data map[string]interface{}) error { | ||
242 | + return fmt.Errorf("已收货订单不能编辑") | ||
243 | +} | ||
244 | + | ||
245 | +func (status *ReceivedStatus) Checkout(order *Order) error { | ||
246 | + return fmt.Errorf("已收货订单不能重复发货") | ||
247 | +} | ||
248 | + | ||
249 | +func (status *ReceivedStatus) Return(order *Order) error { | ||
250 | + return nil | ||
251 | +} | ||
252 | + | ||
253 | +func (status *ReceivedStatus) Cancel(order *Order) error { | ||
254 | + return fmt.Errorf("已收货订单不能取消") | ||
255 | +} | ||
256 | + | ||
257 | +func (status *ReceivedStatus) Receive(order *Order) error { | ||
258 | + return fmt.Errorf("已收货订单不能重复收货") | ||
259 | +} | ||
260 | + | ||
261 | +// 退货状态 | ||
262 | +type ReturnedStatus struct{} | ||
263 | + | ||
264 | +func (status *ReturnedStatus) Update(order *Order, data map[string]interface{}) error { | ||
265 | + return fmt.Errorf("已退货订单不允许编辑") | ||
266 | +} | ||
267 | + | ||
268 | +func (status *ReturnedStatus) Checkout(order *Order) error { | ||
269 | + return fmt.Errorf("已退货订单不允许发货") | ||
270 | +} | ||
271 | + | ||
272 | +func (status *ReturnedStatus) Return(order *Order) error { | ||
273 | + return fmt.Errorf("已退货订单不允许再次退货") | ||
274 | +} | ||
275 | + | ||
276 | +func (status *ReturnedStatus) Cancel(order *Order) error { | ||
277 | + return fmt.Errorf("已退货订单不能取消") | ||
278 | +} | ||
279 | + | ||
280 | +func (status *ReturnedStatus) Receive(order *Order) error { | ||
281 | + return fmt.Errorf("已退货订单不能收货") | ||
282 | +} | ||
283 | + | ||
284 | +// 取消状态 | ||
285 | +type CanceledStatus struct{} | ||
286 | + | ||
287 | +func (status *CanceledStatus) Update(order *Order, dat map[string]interface{}) error { | ||
288 | + return fmt.Errorf("已取消订单不能编辑") | ||
289 | +} | ||
290 | + | ||
291 | +func (status *CanceledStatus) Checkout(order *Order) error { | ||
292 | + return fmt.Errorf("已取消订单不能发货") | ||
293 | +} | ||
294 | + | ||
295 | +func (status *CanceledStatus) Return(order *Order) error { | ||
296 | + return fmt.Errorf("已取消订单不能退货") | ||
297 | +} | ||
298 | + | ||
299 | +func (status *CanceledStatus) Cancel(order *Order) error { | ||
300 | + return fmt.Errorf("已取消订单不能再次取消") | ||
301 | +} | ||
302 | + | ||
303 | +func (status *CanceledStatus) Receive(order *Order) error { | ||
304 | + return fmt.Errorf("已取消订单不能进行收货") | ||
305 | +} | ||
306 | + | ||
307 | +// 已完成状态 | ||
308 | +type CompletedStatus struct{} | ||
309 | + | ||
310 | +func (status *CompletedStatus) Update(order *Order, data map[string]interface{}) error { | ||
311 | + return nil | ||
312 | +} | ||
313 | + | ||
314 | +func (status *CompletedStatus) Checkout(order *Order) error { | ||
315 | + return fmt.Errorf("已完成订单不能发货") | ||
316 | +} | ||
317 | + | ||
318 | +func (status *CompletedStatus) Return(order *Order) error { | ||
319 | + return fmt.Errorf("已完成订单不能退货") | ||
320 | +} | ||
321 | + | ||
322 | +func (status *CompletedStatus) Cancel(order *Order) error { | ||
323 | + return fmt.Errorf("已完成订单不能取消") | ||
324 | +} | ||
325 | + | ||
326 | +func (status *CompletedStatus) Receive(order *Order) error { | ||
327 | + return fmt.Errorf("已完成订单不能收货") | ||
328 | +} | ||
329 | + | ||
330 | +// 订单仓储 | ||
331 | +type OrderRepository interface { | ||
332 | + Save(order *Order) (*Order, error) | ||
333 | + Remove(order *Order) (*Order, error) | ||
334 | + FindOne(queryOptions map[string]interface{}) (*Order, error) | ||
335 | + Find(queryOptions map[string]interface{}) (int64, []*Order, error) | ||
336 | +} | ||
337 | + | ||
338 | +func (order *Order) Identify() interface{} { | ||
339 | + if order.OrderId == 0 { | ||
340 | + return nil | ||
341 | + } | ||
342 | + return order.OrderId | ||
343 | +} | ||
344 | + | ||
345 | +// 更新订单 | ||
346 | +func (order *Order) Update(data map[string]interface{}) error { | ||
347 | + return order.CurrentStatus.Update(order, data) | ||
348 | +} | ||
349 | + | ||
350 | +// 发货 | ||
351 | +func (order *Order) Checkout() error { | ||
352 | + return order.CurrentStatus.Checkout(order) | ||
353 | +} | ||
354 | + | ||
355 | +// 退货 | ||
356 | +func (order *Order) Return() error { | ||
357 | + return order.CurrentStatus.Return(order) | ||
358 | +} | ||
359 | + | ||
360 | +// 收货 | ||
361 | +func (order *Order) Receive() error { | ||
362 | + return order.CurrentStatus.Receive(order) | ||
363 | +} | ||
364 | + | ||
365 | +// 取消订单 | ||
366 | +func (order *Order) Cancel() error { | ||
367 | + return order.CurrentStatus.Cancel(order) | ||
368 | +} |
pkg/domain/order_detail.go
0 → 100644
1 | +package domain | ||
2 | + | ||
3 | +// 订单详情实体 | ||
4 | +type OrderDetail struct { | ||
5 | + // 订单详情id | ||
6 | + OrderDetailId int64 `json:"orderDetailId"` | ||
7 | + // 订单编号 | ||
8 | + OrderNo string `json:"orderNo"` | ||
9 | + // 订单数量 | ||
10 | + OrderNum int `json:"orderNum"` | ||
11 | + // 订单总金额 | ||
12 | + TotalPrice float64 `json:"totalPrice"` | ||
13 | + // 调整后订单数量 | ||
14 | + AdjustedNum int `json:"adjustedNum"` | ||
15 | + // 调整后订单总金额 | ||
16 | + AdjustedTotalPrice float64 `json:"adjustedTotalPrice"` | ||
17 | +} |
pkg/domain/order_source.go
0 → 100644
pkg/domain/partner_category.go
0 → 100644
1 | +package domain | ||
2 | + | ||
3 | +// 合伙人类别 (实体) | ||
4 | +type PartnerCategory struct { | ||
5 | + // 合伙人类别id | ||
6 | + PartnerCategoryId int `json:"partnerCategoryId"` | ||
7 | + // 合伙人类别编码 | ||
8 | + PartnerCategoryCode string `json:"partnerCategoryCode"` | ||
9 | + // 合伙人类别名称 | ||
10 | + PartnerCategoryName string `json:"partnerCategoryName"` | ||
11 | +} | ||
12 | + | ||
13 | +type PartnerCategoryRepository interface { | ||
14 | + Save(partnerCategory *PartnerCategory) (*PartnerCategory, error) | ||
15 | + Remove(partnerCategory *PartnerCategory) (*PartnerCategory, error) | ||
16 | + FindOne(queryOptions map[string]interface{}) (*PartnerCategory, error) | ||
17 | + Find(queryOptions map[string]interface{}) (int64, []*PartnerCategory, error) | ||
18 | +} | ||
19 | + | ||
20 | +func (partnerCategory *PartnerCategory) Identify() interface{} { | ||
21 | + if partnerCategory.PartnerCategoryId == 0 { | ||
22 | + return nil | ||
23 | + } | ||
24 | + return partnerCategory.PartnerCategoryId | ||
25 | +} | ||
26 | + | ||
27 | +func (partnerCategory *PartnerCategory) Update(data map[string]interface{}) error { | ||
28 | + if partnerCategoryId, ok := data["partnerCategoryId"]; ok { | ||
29 | + partnerCategory.PartnerCategoryId = partnerCategoryId.(int) | ||
30 | + } | ||
31 | + if partnerCategoryCode, ok := data["partnerCategoryCode"]; ok { | ||
32 | + partnerCategory.PartnerCategoryCode = partnerCategoryCode.(string) | ||
33 | + } | ||
34 | + if partnerCategoryName, ok := data["partnerCategoryName"]; ok { | ||
35 | + partnerCategory.PartnerCategoryName = partnerCategoryName.(string) | ||
36 | + } | ||
37 | + return nil | ||
38 | +} |
pkg/domain/partner_info.go
0 → 100644
1 | +package domain | ||
2 | + | ||
3 | +import "time" | ||
4 | + | ||
5 | +// 合伙人信息 | ||
6 | +type PartnerInfo struct { | ||
7 | + // 合伙人账号 | ||
8 | + PartnerAccount string `json:"partnerAccount"` | ||
9 | + // 合伙人姓名 | ||
10 | + PartnerName string `json:"partnerName"` | ||
11 | + // 订单区域信息 | ||
12 | + RegionInfo *RegionInfo `json:"regionInfo"` | ||
13 | + // 状态 1正常 2禁用 | ||
14 | + Status int64 `json:"status"` | ||
15 | + // 合伙时间 | ||
16 | + CooperateTime time.Time `json:"cooperateTime"` | ||
17 | + // 业务员 | ||
18 | + Salesmans []*Salesman `json:"salesmans"` | ||
19 | + // 合伙人类型 | ||
20 | + PartnerCategorys []*PartnerCategory `json:"partnerCategorys"` | ||
21 | +} |
pkg/domain/permission.go
0 → 100644
1 | +package domain | ||
2 | + | ||
3 | +// 权限 | ||
4 | +type Permission struct { | ||
5 | + // 权限id | ||
6 | + PermissionId int `json:"permissionId"` | ||
7 | + // 公司名称 | ||
8 | + Name string `json:"name"` | ||
9 | + // 权限编码 | ||
10 | + Code string `json:"code"` | ||
11 | + // 父级id | ||
12 | + ParentId int `json:"parentId"` | ||
13 | + // 排序 | ||
14 | + Sort int `json:"sort"` | ||
15 | + // 图标 | ||
16 | + Icon string `json:"icon"` | ||
17 | +} | ||
18 | + | ||
19 | +type PermissionRepository interface { | ||
20 | + Save(permission *Permission) (*Permission, error) | ||
21 | + Remove(permission *Permission) (*Permission, error) | ||
22 | + FindOne(queryOptions map[string]interface{}) (*Permission, error) | ||
23 | + Find(queryOptions map[string]interface{}) (int64, []*Permission, error) | ||
24 | +} | ||
25 | + | ||
26 | +func (permission *Permission) Identify() interface{} { | ||
27 | + if permission.PermissionId == 0 { | ||
28 | + return nil | ||
29 | + } | ||
30 | + return permission.PermissionId | ||
31 | +} | ||
32 | + | ||
33 | +func (permission *Permission) Update(data map[string]interface{}) error { | ||
34 | + if permissionId, ok := data["permissionId"]; ok { | ||
35 | + permission.PermissionId = permissionId.(int) | ||
36 | + } | ||
37 | + if name, ok := data["name"]; ok { | ||
38 | + permission.Name = name.(string) | ||
39 | + } | ||
40 | + if code, ok := data["code"]; ok { | ||
41 | + permission.Code = code.(string) | ||
42 | + } | ||
43 | + if parentId, ok := data["parentId"]; ok { | ||
44 | + permission.ParentId = parentId.(int) | ||
45 | + } | ||
46 | + if sort, ok := data["sort"]; ok { | ||
47 | + permission.Sort = sort.(int) | ||
48 | + } | ||
49 | + if icon, ok := data["icon"]; ok { | ||
50 | + permission.Icon = icon.(string) | ||
51 | + } | ||
52 | + return nil | ||
53 | +} |
pkg/domain/phone_auth.go
0 → 100644
pkg/domain/region_info.go
0 → 100644
pkg/domain/salesman.go
0 → 100644
pkg/domain/service/cancel_order.go
0 → 100644
1 | +package service | ||
2 | + | ||
3 | +import ( | ||
4 | + coreDomain "github.com/linmadan/egglib-go/core/domain" | ||
5 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/domain" | ||
6 | +) | ||
7 | + | ||
8 | +type CancelOrderService interface { | ||
9 | + coreDomain.DomainEventPublisher | ||
10 | + Cancel(orderId int64) (*domain.Order, error) | ||
11 | +} |
pkg/domain/service/receiving_goods.go
0 → 100644
1 | +package service | ||
2 | + | ||
3 | +import ( | ||
4 | + coreDomain "github.com/linmadan/egglib-go/core/domain" | ||
5 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/domain" | ||
6 | +) | ||
7 | + | ||
8 | +type ReceivingGoodsService interface { | ||
9 | + coreDomain.DomainEventPublisher | ||
10 | + Receiving(orderId int64) (*domain.Order, error) | ||
11 | +} |
pkg/domain/service/return_goods.go
0 → 100644
1 | +package service | ||
2 | + | ||
3 | +import ( | ||
4 | + coreDomain "github.com/linmadan/egglib-go/core/domain" | ||
5 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/domain" | ||
6 | +) | ||
7 | + | ||
8 | +type ReturnGoodsService interface { | ||
9 | + coreDomain.DomainEventPublisher | ||
10 | + Return(orderId int64) (*domain.Order, error) | ||
11 | +} |
pkg/domain/service/shipping_goods.go
0 → 100644
1 | +package service | ||
2 | + | ||
3 | +import ( | ||
4 | + coreDomain "github.com/linmadan/egglib-go/core/domain" | ||
5 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/domain" | ||
6 | +) | ||
7 | + | ||
8 | +type ShippingGoodsService interface { | ||
9 | + coreDomain.DomainEventPublisher | ||
10 | + Shipping(orderId int64) (*domain.Order, error) | ||
11 | +} |
pkg/domain/user.go
0 → 100644
1 | +package domain | ||
2 | + | ||
3 | +import "time" | ||
4 | + | ||
5 | +const ( | ||
6 | + StatusEnable int64 = 1 | ||
7 | + StatusDisable int64 = 2 | ||
8 | +) | ||
9 | +const ( | ||
10 | + SuperAdministrator = 1 | ||
11 | + EnterpriseAdministrator = 10 | ||
12 | + NormalUser = 100 | ||
13 | +) | ||
14 | + | ||
15 | +// UserType | ||
16 | +const ( | ||
17 | + Manager = 1 | ||
18 | + Partner = 2 | ||
19 | + Guest = 3 | ||
20 | +) | ||
21 | + | ||
22 | +// 用户实体 | ||
23 | +type User struct { | ||
24 | + // 用户id | ||
25 | + UserId int64 `json:"userId"` | ||
26 | + // 1.高管 2.合伙人 4:游客 | ||
27 | + UserType int `json:"userType"` | ||
28 | + // 用户权限 | ||
29 | + Permissions []int `json:"permissions"` | ||
30 | + // 公司Id | ||
31 | + CompanyId int64 `json:"companyId"` | ||
32 | + // 用户信息 | ||
33 | + UserInfo *UserInfo `json:"userInfo"` | ||
34 | + // 合伙人信息 | ||
35 | + PartnerInfo *PartnerInfo `json:"partnerInfo"` | ||
36 | + // 状态 1正常 2禁用 | ||
37 | + Status int64 `json:"status"` | ||
38 | + // 管理员类型 1.超级管理员 10:企业管理员 100:普通用户 | ||
39 | + AdminType int `json:"adminType"` | ||
40 | + // 合伙人列表 用户类型为高管时有效 | ||
41 | + AccessPartners []int64 `json:"accessPartners"` | ||
42 | + // 创建时间 | ||
43 | + CreateAt time.Time `json:"createAt"` | ||
44 | + // 更新时间 | ||
45 | + UpdateAt time.Time `json:"updateAt"` | ||
46 | + // 删除时间 | ||
47 | + DeleteAt time.Time `json:"deleteAt"` | ||
48 | +} | ||
49 | + | ||
50 | +type UserRepository interface { | ||
51 | + Save(user *User) (*User, error) | ||
52 | + Remove(user *User) (*User, error) | ||
53 | + FindOne(queryOptions map[string]interface{}) (*User, error) | ||
54 | + Find(queryOptions map[string]interface{}) (int64, []*User, error) | ||
55 | +} | ||
56 | + | ||
57 | +func (user *User) Identify() interface{} { | ||
58 | + if user.UserId == 0 { | ||
59 | + return nil | ||
60 | + } | ||
61 | + return user.UserId | ||
62 | +} | ||
63 | + | ||
64 | +func (user *User) Update(data map[string]interface{}) error { | ||
65 | + if userId, ok := data["userId"]; ok { | ||
66 | + user.UserId = userId.(int64) | ||
67 | + } | ||
68 | + if userType, ok := data["userType"]; ok { | ||
69 | + user.UserType = userType.(int) | ||
70 | + } | ||
71 | + if permissions, ok := data["permissions"]; ok { | ||
72 | + user.Permissions = permissions.([]int) | ||
73 | + } | ||
74 | + if companyId, ok := data["companyId"]; ok { | ||
75 | + user.CompanyId = companyId.(int64) | ||
76 | + } | ||
77 | + if isPrincipal, ok := data["isPrincipal"]; ok { | ||
78 | + user.UserInfo.IsPrincipal = isPrincipal.(bool) | ||
79 | + } | ||
80 | + if uid, ok := data["uid"]; ok { | ||
81 | + user.UserInfo.Uid = uid.(int64) | ||
82 | + } | ||
83 | + if userAccount, ok := data["userAccount"]; ok { | ||
84 | + user.UserInfo.UserAccount = userAccount.(string) | ||
85 | + } | ||
86 | + if userAvatarUrl, ok := data["userAvatarUrl"]; ok { | ||
87 | + user.UserInfo.UserAvatarUrl = userAvatarUrl.(string) | ||
88 | + } | ||
89 | + if userName, ok := data["userName"]; ok { | ||
90 | + user.UserInfo.UserName = userName.(string) | ||
91 | + } | ||
92 | + if email, ok := data["email"]; ok { | ||
93 | + user.UserInfo.Email = email.(string) | ||
94 | + } | ||
95 | + if gender, ok := data["gender"]; ok { | ||
96 | + user.UserInfo.Gender = gender.(int) | ||
97 | + } | ||
98 | + if entryTime, ok := data["entryTime"]; ok { | ||
99 | + user.UserInfo.EntryTime = entryTime.(time.Time) | ||
100 | + } | ||
101 | + if extension, ok := data["extension"]; ok { | ||
102 | + user.UserInfo.Extension = extension.(string) | ||
103 | + } | ||
104 | + if workplace, ok := data["workplace"]; ok { | ||
105 | + user.UserInfo.Workplace = workplace.(string) | ||
106 | + } | ||
107 | + if privateNumber, ok := data["privateNumber"]; ok { | ||
108 | + user.UserInfo.PrivateNumber = privateNumber.(string) | ||
109 | + } | ||
110 | + if jobNumber, ok := data["jobNumber"]; ok { | ||
111 | + user.UserInfo.JobNumber = jobNumber.(string) | ||
112 | + } | ||
113 | + if partnerAccount, ok := data["partnerAccount"]; ok { | ||
114 | + user.PartnerInfo.PartnerAccount = partnerAccount.(string) | ||
115 | + } | ||
116 | + if partnerName, ok := data["partnerName"]; ok { | ||
117 | + user.PartnerInfo.PartnerName = partnerName.(string) | ||
118 | + } | ||
119 | + if regionName, ok := data["regionName"]; ok { | ||
120 | + user.PartnerInfo.RegionInfo.RegionName = regionName.(string) | ||
121 | + } | ||
122 | + if status, ok := data["status"]; ok { | ||
123 | + user.PartnerInfo.Status = status.(int64) | ||
124 | + } | ||
125 | + return nil | ||
126 | +} |
pkg/domain/user_auth.go
0 → 100644
1 | +package domain | ||
2 | + | ||
3 | +import "time" | ||
4 | + | ||
5 | +// 用户认证实体 | ||
6 | +type UserAuth struct { | ||
7 | + // 用户认证编号 | ||
8 | + UserAuthId int64 `json:"userAuthId"` | ||
9 | + // 用户id列表 | ||
10 | + Users []int64 `json:"users"` | ||
11 | + // 手机认证 | ||
12 | + PhoneAuth *PhoneAuth `json:"phoneAuth"` | ||
13 | + // 创建时间 | ||
14 | + CreateAt time.Time `json:"createAt"` | ||
15 | + // 更新时间 | ||
16 | + UpdateAt time.Time `json:"updateAt"` | ||
17 | +} | ||
18 | + | ||
19 | +type UserAuthRepository interface { | ||
20 | + Save(userAuth *UserAuth) (*UserAuth, error) | ||
21 | + Remove(userAuth *UserAuth) (*UserAuth, error) | ||
22 | + FindOne(queryOptions map[string]interface{}) (*UserAuth, error) | ||
23 | + Find(queryOptions map[string]interface{}) (int64, []*UserAuth, error) | ||
24 | +} | ||
25 | + | ||
26 | +func (userAuth *UserAuth) Identify() interface{} { | ||
27 | + if userAuth.UserAuthId == 0 { | ||
28 | + return nil | ||
29 | + } | ||
30 | + return userAuth.UserAuthId | ||
31 | +} | ||
32 | + | ||
33 | +func (userAuth *UserAuth) Update(data map[string]interface{}) error { | ||
34 | + if userAuthId, ok := data["userAuthId"]; ok { | ||
35 | + userAuth.UserAuthId = userAuthId.(int64) | ||
36 | + } | ||
37 | + if users, ok := data["users"]; ok { | ||
38 | + userAuth.Users = users.([]int64) | ||
39 | + } | ||
40 | + if phone, ok := data["phone"]; ok { | ||
41 | + userAuth.PhoneAuth.Phone = phone.(string) | ||
42 | + } | ||
43 | + if password, ok := data["password"]; ok { | ||
44 | + userAuth.PhoneAuth.Password = password.(string) | ||
45 | + } | ||
46 | + if createAt, ok := data["createAt"]; ok { | ||
47 | + userAuth.CreateAt = createAt.(time.Time) | ||
48 | + } | ||
49 | + if updateAt, ok := data["updateAt"]; ok { | ||
50 | + userAuth.UpdateAt = updateAt.(time.Time) | ||
51 | + } | ||
52 | + return nil | ||
53 | +} |
pkg/domain/user_info.go
0 → 100644
1 | +package domain | ||
2 | + | ||
3 | +import "time" | ||
4 | + | ||
5 | +// 用户信息值对象 | ||
6 | +type UserInfo struct { | ||
7 | + // 是否是公司负责人 | ||
8 | + IsPrincipal bool `json:"isPrincipal"` | ||
9 | + // 统一用户id | ||
10 | + Uid int64 `json:"uid"` | ||
11 | + // 用户账号 | ||
12 | + UserAccount string `json:"userAccount"` | ||
13 | + // 用户头像URL | ||
14 | + UserAvatarUrl string `json:"userAvatarUrl"` | ||
15 | + // 用户名称 | ||
16 | + UserName string `json:"userName"` | ||
17 | + // 邮件地址 | ||
18 | + Email string `json:"email"` | ||
19 | + // 性别 | ||
20 | + Gender int `json:"gender"` | ||
21 | + // 入职时间 | ||
22 | + EntryTime time.Time `json:"entryTime"` | ||
23 | + // 分机 | ||
24 | + Extension string `json:"extension"` | ||
25 | + // 工作地 | ||
26 | + Workplace string `json:"workplace"` | ||
27 | + // 私人电话 | ||
28 | + PrivateNumber string `json:"privateNumber"` | ||
29 | + // 工号 | ||
30 | + JobNumber string `json:"jobNumber"` | ||
31 | +} |
1 | +package domainService | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + coreDomain "github.com/linmadan/egglib-go/core/domain" | ||
6 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/domain" | ||
7 | + | ||
8 | + pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
9 | +) | ||
10 | + | ||
11 | +type CancelOrderService struct { | ||
12 | + coreDomain.BaseEventPublisher | ||
13 | + transactionContext *pgTransaction.TransactionContext | ||
14 | +} | ||
15 | + | ||
16 | +func (service *CancelOrderService) Cancel(orderId int64) (*domain.Order, error) { | ||
17 | + return nil, nil | ||
18 | +} | ||
19 | + | ||
20 | +func NewCancelOrderService(transactionContext *pgTransaction.TransactionContext) (*CancelOrderService, error) { | ||
21 | + if transactionContext == nil { | ||
22 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
23 | + } else { | ||
24 | + return &CancelOrderService{ | ||
25 | + transactionContext: transactionContext, | ||
26 | + }, nil | ||
27 | + } | ||
28 | +} |
1 | +package domainService | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + coreDomain "github.com/linmadan/egglib-go/core/domain" | ||
6 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/domain" | ||
7 | + | ||
8 | + pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
9 | +) | ||
10 | + | ||
11 | +type ReceivingGoodsService struct { | ||
12 | + coreDomain.BaseEventPublisher | ||
13 | + transactionContext *pgTransaction.TransactionContext | ||
14 | +} | ||
15 | + | ||
16 | +func (service *ReceivingGoodsService) Receiving(orderId int64) (*domain.Order, error) { | ||
17 | + return nil, nil | ||
18 | +} | ||
19 | + | ||
20 | +func NewReceivingGoodsService(transactionContext *pgTransaction.TransactionContext) (*ReceivingGoodsService, error) { | ||
21 | + if transactionContext == nil { | ||
22 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
23 | + } else { | ||
24 | + return &ReceivingGoodsService{ | ||
25 | + transactionContext: transactionContext, | ||
26 | + }, nil | ||
27 | + } | ||
28 | +} |
1 | +package domainService | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + coreDomain "github.com/linmadan/egglib-go/core/domain" | ||
6 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/domain" | ||
7 | + | ||
8 | + pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
9 | +) | ||
10 | + | ||
11 | +type ReturnGoodsService struct { | ||
12 | + coreDomain.BaseEventPublisher | ||
13 | + transactionContext *pgTransaction.TransactionContext | ||
14 | +} | ||
15 | + | ||
16 | +func (service *ReturnGoodsService) Return(orderId int64) (*domain.Order, error) { | ||
17 | + panic("implement me") | ||
18 | +} | ||
19 | + | ||
20 | +func NewReturnGoodsService(transactionContext *pgTransaction.TransactionContext) (*ReturnGoodsService, error) { | ||
21 | + if transactionContext == nil { | ||
22 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
23 | + } else { | ||
24 | + return &ReturnGoodsService{ | ||
25 | + transactionContext: transactionContext, | ||
26 | + }, nil | ||
27 | + } | ||
28 | +} |
1 | +package domainService | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + coreDomain "github.com/linmadan/egglib-go/core/domain" | ||
6 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/domain" | ||
7 | + | ||
8 | + pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
9 | +) | ||
10 | + | ||
11 | +type ShippingGoodsService struct { | ||
12 | + coreDomain.BaseEventPublisher | ||
13 | + transactionContext *pgTransaction.TransactionContext | ||
14 | +} | ||
15 | + | ||
16 | +func (service *ShippingGoodsService) Shipping(orderId int64) (*domain.Order, error) { | ||
17 | + return nil, nil | ||
18 | +} | ||
19 | + | ||
20 | +func NewShippingGoodsService(transactionContext *pgTransaction.TransactionContext) (*ShippingGoodsService, error) { | ||
21 | + if transactionContext == nil { | ||
22 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
23 | + } else { | ||
24 | + return &ShippingGoodsService{ | ||
25 | + transactionContext: transactionContext, | ||
26 | + }, nil | ||
27 | + } | ||
28 | +} |
1 | +package gateway | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/linmadan/egglib-go/core/application" | ||
5 | + "github.com/tiptok/gocomm/gs" | ||
6 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/constant" | ||
7 | + "net/http" | ||
8 | +) | ||
9 | + | ||
10 | +const ( | ||
11 | + AuthsLogin = "AuthsLogin" | ||
12 | + AuthsLoginByCompany = "loginByCompany" | ||
13 | + AuthsAccessToken = "AuthsAccessToken" | ||
14 | + AuthsRefreshToken = "AuthsRefreshToken" | ||
15 | + AuthsSendSmsCode = "AuthsSendSmsCode" | ||
16 | + AuthsRevoke = "AuthsRevoke" | ||
17 | + AuthsChangePhonePassword = "AuthsChangePhonePassword" | ||
18 | +) | ||
19 | + | ||
20 | +const ( | ||
21 | + CompanyGet = "CompanyGet" | ||
22 | + CompanyCreate = "CompanyCreate" | ||
23 | + CompanyRemove = "CompanyRemove" | ||
24 | + CompanyList = "CompanyList" | ||
25 | + CompanyUpdate = "CompanyUpdate" | ||
26 | +) | ||
27 | + | ||
28 | +var Partner01Service *HttpPartner01ServiceGateway | ||
29 | + | ||
30 | +func init() { | ||
31 | + Partner01Service = &HttpPartner01ServiceGateway{gs.NewManagerService(constant.PARTER01_GATEWAY_ADDRESS, Routers())} | ||
32 | + Partner01Service.WithDebugModel(true) | ||
33 | +} | ||
34 | + | ||
35 | +type HttpPartner01ServiceGateway struct { | ||
36 | + *gs.GatewayService | ||
37 | +} | ||
38 | + | ||
39 | +func Routers() []gs.Router { | ||
40 | + routers := []gs.Router{ | ||
41 | + {AuthsLogin, "/auths/login", http.MethodPost}, | ||
42 | + {AuthsLoginByCompany, "/auths/loginByCompany", http.MethodPost}, | ||
43 | + {AuthsAccessToken, "/auths/accessToken", http.MethodPost}, | ||
44 | + {AuthsRefreshToken, "/auths/refreshToken", http.MethodPost}, | ||
45 | + {AuthsSendSmsCode, "/auths/sendSmsCode", http.MethodPost}, | ||
46 | + {AuthsRevoke, "/auths/revoke", http.MethodPost}, | ||
47 | + {AuthsChangePhonePassword, "/auths/changePhonePassword", http.MethodPost}, | ||
48 | + | ||
49 | + {CompanyGet, "/companies/:companyId", http.MethodGet}, | ||
50 | + {CompanyRemove, "/companies/:companyId", http.MethodDelete}, | ||
51 | + {CompanyUpdate, "/companies/:companyId", http.MethodPut}, | ||
52 | + {CompanyCreate, "/companies/", http.MethodPost}, | ||
53 | + {CompanyList, "/companies/", http.MethodGet}, | ||
54 | + } | ||
55 | + return routers | ||
56 | +} | ||
57 | + | ||
58 | +func (service *HttpPartner01ServiceGateway) CompanyCreate(jsonObject interface{}) (interface{}, error) { | ||
59 | + data, err := service.Invoke(CompanyCreate, gs.WithJsonObject(jsonObject)) | ||
60 | + if err != nil { | ||
61 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
62 | + } | ||
63 | + return data.Data, nil | ||
64 | +} | ||
65 | + | ||
66 | +func (service *HttpPartner01ServiceGateway) CompanyGet(pathParam interface{}) (interface{}, error) { | ||
67 | + data, err := service.Invoke(CompanyGet, gs.WithPathParam(pathParam)) | ||
68 | + if err != nil { | ||
69 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
70 | + } | ||
71 | + return data.Data, nil | ||
72 | +} |
pkg/infrastructure/pg/init.go
0 → 100644
1 | +package pg | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "github.com/go-pg/pg/v10" | ||
6 | + "github.com/go-pg/pg/v10/orm" | ||
7 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/constant" | ||
8 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/infrastructure/pg/models" | ||
9 | + | ||
10 | + "github.com/linmadan/egglib-go/persistent/pg/hooks" | ||
11 | +) | ||
12 | + | ||
13 | +var DB *pg.DB | ||
14 | + | ||
15 | +func init() { | ||
16 | + DB = pg.Connect(&pg.Options{ | ||
17 | + User: constant.POSTGRESQL_USER, | ||
18 | + Password: constant.POSTGRESQL_PASSWORD, | ||
19 | + Database: constant.POSTGRESQL_DB_NAME, | ||
20 | + Addr: fmt.Sprintf("%s:%s", constant.POSTGRESQL_HOST, constant.POSTGRESQL_PORT), | ||
21 | + }) | ||
22 | + if !constant.DISABLE_SQL_GENERATE_PRINT { | ||
23 | + DB.AddQueryHook(hooks.SqlGeneratePrintHook{}) | ||
24 | + } | ||
25 | + if !constant.DISABLE_CREATE_TABLE { | ||
26 | + for _, model := range []interface{}{ | ||
27 | + &models.Permission{}, | ||
28 | + &models.PartnerCategory{}, | ||
29 | + &models.UserAuth{}, | ||
30 | + &models.Goods{}, | ||
31 | + &models.Order{}, | ||
32 | + &models.User{}, | ||
33 | + &models.Company{}, | ||
34 | + } { | ||
35 | + err := DB.Model(model).CreateTable(&orm.CreateTableOptions{ | ||
36 | + Temp: false, | ||
37 | + IfNotExists: true, | ||
38 | + FKConstraints: true, | ||
39 | + }) | ||
40 | + if err != nil { | ||
41 | + panic(err) | ||
42 | + } | ||
43 | + } | ||
44 | + } | ||
45 | +} |
pkg/infrastructure/pg/models/company.go
0 → 100644
1 | +package models | ||
2 | + | ||
3 | +import ( | ||
4 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/domain" | ||
5 | + "time" | ||
6 | +) | ||
7 | + | ||
8 | +type Company struct { | ||
9 | + tableName string `pg:"companies,alias:company"` | ||
10 | + // 公司Id | ||
11 | + CompanyId int64 `pg:",pk"` | ||
12 | + // 公司信息 | ||
13 | + CompanyInfo *domain.CompanyInfo | ||
14 | + // 创建时间 | ||
15 | + CreateAt time.Time | ||
16 | + // 更新时间 | ||
17 | + UpdateAt time.Time | ||
18 | + // 删除时间 | ||
19 | + DeleteAt time.Time `pg:",soft_delete"` | ||
20 | +} |
pkg/infrastructure/pg/models/goods.go
0 → 100644
1 | +package models | ||
2 | + | ||
3 | +import ( | ||
4 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/domain" | ||
5 | + "time" | ||
6 | +) | ||
7 | + | ||
8 | +type Goods struct { | ||
9 | + tableName string `pg:"goodss,alias:goods"` | ||
10 | + // 商品id | ||
11 | + GoodsId int64 | ||
12 | + // 预定的货品数量 | ||
13 | + GoodsNum int | ||
14 | + // 商品分红支付信息 | ||
15 | + GoodsDividend *domain.Dividend | ||
16 | + // 商品分红支付状态 | ||
17 | + GoodsDividendStatus int | ||
18 | + // 商品名称 | ||
19 | + GoodsName string | ||
20 | + // 商品单价 | ||
21 | + GoodsTotalPrice float64 | ||
22 | + // 备注 | ||
23 | + Remarks string | ||
24 | + // 订单编号 | ||
25 | + OrderNo string | ||
26 | + // 商品详情 | ||
27 | + GoodsDetail string | ||
28 | + // 创建时间 | ||
29 | + CreateAt time.Time | ||
30 | + // 更新时间 | ||
31 | + UpdateAt time.Time | ||
32 | + // 删除时间 | ||
33 | + DeleteAt time.Time | ||
34 | +} |
pkg/infrastructure/pg/models/order.go
0 → 100644
1 | +package models | ||
2 | + | ||
3 | +import ( | ||
4 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/domain" | ||
5 | + "time" | ||
6 | +) | ||
7 | + | ||
8 | +type Order struct { | ||
9 | + tableName string `pg:"orders,alias:order"` | ||
10 | + // 订单id | ||
11 | + OrderId int64 | ||
12 | + // 买家信息 | ||
13 | + Buyer *domain.BuyerInfo | ||
14 | + // 公司Id | ||
15 | + CompanyId int64 | ||
16 | + // 合伙人id | ||
17 | + PartnerId int64 | ||
18 | + // 发货单号 | ||
19 | + DeliveryCode string | ||
20 | + // 是否关闭订单标志 | ||
21 | + IsDisable int | ||
22 | + // 订单编号 | ||
23 | + OrderNo string | ||
24 | + // 订单详情 | ||
25 | + OrderDetail *domain.OrderDetail | ||
26 | + // 订单分红信息 | ||
27 | + OrderDividend *domain.Dividend | ||
28 | + // 订单分红支付状态 | ||
29 | + OrderDividendStatus int | ||
30 | + // 订单货品 | ||
31 | + OrderGoods []*domain.Goods | ||
32 | + // 订单数据来源 | ||
33 | + OrderSource *domain.OrderSource | ||
34 | + // 订单类型(1.实际订单;2.意向订单) | ||
35 | + OrderType int | ||
36 | + // 订单状态(1.发货;2.收货;3.退货;4.取消;5.完成) | ||
37 | + OrderStatus int | ||
38 | + // 订单总价 | ||
39 | + TotalPrice float64 | ||
40 | + // 订单区域信息 | ||
41 | + RegionInfo *domain.RegionInfo | ||
42 | + // 备注 | ||
43 | + Remarks string | ||
44 | + // 创建时间 | ||
45 | + CreateAt time.Time | ||
46 | + // 更新时间 | ||
47 | + UpdateAt time.Time | ||
48 | + // 软删 | ||
49 | + DeleteAt time.Time | ||
50 | +} |
pkg/infrastructure/pg/models/permission.go
0 → 100644
pkg/infrastructure/pg/models/user.go
0 → 100644
1 | +package models | ||
2 | + | ||
3 | +import ( | ||
4 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/domain" | ||
5 | + "time" | ||
6 | +) | ||
7 | + | ||
8 | +type User struct { | ||
9 | + tableName string `pg:"users,alias:users"` | ||
10 | + // 用户id | ||
11 | + UserId int64 `pg:",pk"` | ||
12 | + // 1.高管 2.合伙人 4:游客 | ||
13 | + UserType int | ||
14 | + // 用户权限 | ||
15 | + Permissions []int `pg:",array"` | ||
16 | + // 公司Id | ||
17 | + CompanyId int64 | ||
18 | + // 用户信息 | ||
19 | + UserInfo *domain.UserInfo | ||
20 | + // 合伙人信息 | ||
21 | + PartnerInfo *domain.PartnerInfo | ||
22 | + // 状态 1正常 2禁用 | ||
23 | + Status int64 | ||
24 | + // 管理员类型 1.超级管理员 10:企业管理员 100:普通用户 | ||
25 | + AdminType int | ||
26 | + // 合伙人列表 用户类型为高管时有效 | ||
27 | + AccessPartners []int64 `pg:",array"` | ||
28 | + // 创建时间 | ||
29 | + CreateAt time.Time | ||
30 | + // 更新时间 | ||
31 | + UpdateAt time.Time | ||
32 | + // 删除时间 | ||
33 | + DeleteAt time.Time | ||
34 | +} |
pkg/infrastructure/pg/models/user_auth.go
0 → 100644
1 | +package models | ||
2 | + | ||
3 | +import ( | ||
4 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/domain" | ||
5 | + "time" | ||
6 | +) | ||
7 | + | ||
8 | +type UserAuth struct { | ||
9 | + tableName string `pg:"user_auth,alias:user_auth"` | ||
10 | + // 用户认证编号 | ||
11 | + UserAuthId int64 `pg:",pk"` | ||
12 | + // 用户id列表 | ||
13 | + Users []int64 `pg:",array"` | ||
14 | + // 手机认证 | ||
15 | + PhoneAuth *domain.PhoneAuth | ||
16 | + // 创建时间 | ||
17 | + CreateAt time.Time | ||
18 | + // 更新时间 | ||
19 | + UpdateAt time.Time | ||
20 | +} |
pkg/infrastructure/pg/transform/company.go
0 → 100644
1 | +package transform | ||
2 | + | ||
3 | +import ( | ||
4 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/domain" | ||
5 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/infrastructure/pg/models" | ||
6 | +) | ||
7 | + | ||
8 | +func TransformToCompanyDomainModelFromPgModels(companyModel *models.Company) (*domain.Company, error) { | ||
9 | + return &domain.Company{ | ||
10 | + CompanyId: companyModel.CompanyId, | ||
11 | + CompanyInfo: companyModel.CompanyInfo, | ||
12 | + CreateAt: companyModel.CreateAt, | ||
13 | + UpdateAt: companyModel.UpdateAt, | ||
14 | + DeleteAt: companyModel.DeleteAt, | ||
15 | + }, nil | ||
16 | +} |
pkg/infrastructure/pg/transform/goods.go
0 → 100644
1 | +package transform | ||
2 | + | ||
3 | +import ( | ||
4 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/domain" | ||
5 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/infrastructure/pg/models" | ||
6 | +) | ||
7 | + | ||
8 | +func TransformToGoodsDomainModelFromPgModels(goodsModel *models.Goods) (*domain.Goods, error) { | ||
9 | + return &domain.Goods{ | ||
10 | + GoodsId: goodsModel.GoodsId, | ||
11 | + GoodsNum: goodsModel.GoodsNum, | ||
12 | + GoodsDividend: goodsModel.GoodsDividend, | ||
13 | + GoodsDividendStatus: goodsModel.GoodsDividendStatus, | ||
14 | + GoodsName: goodsModel.GoodsName, | ||
15 | + GoodsTotalPrice: goodsModel.GoodsTotalPrice, | ||
16 | + Remarks: goodsModel.Remarks, | ||
17 | + OrderNo: goodsModel.OrderNo, | ||
18 | + GoodsDetail: goodsModel.GoodsDetail, | ||
19 | + CreateAt: goodsModel.CreateAt, | ||
20 | + UpdateAt: goodsModel.UpdateAt, | ||
21 | + DeleteAt: goodsModel.DeleteAt, | ||
22 | + }, nil | ||
23 | +} |
pkg/infrastructure/pg/transform/order.go
0 → 100644
1 | +package transform | ||
2 | + | ||
3 | +import ( | ||
4 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/domain" | ||
5 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/infrastructure/pg/models" | ||
6 | +) | ||
7 | + | ||
8 | +func TransformToOrderDomainModelFromPgModels(orderModel *models.Order) (*domain.Order, error) { | ||
9 | + return &domain.Order{ | ||
10 | + OrderId: orderModel.OrderId, | ||
11 | + Buyer: orderModel.Buyer, | ||
12 | + CompanyId: orderModel.CompanyId, | ||
13 | + PartnerId: orderModel.PartnerId, | ||
14 | + DeliveryCode: orderModel.DeliveryCode, | ||
15 | + IsDisable: orderModel.IsDisable, | ||
16 | + OrderNo: orderModel.OrderNo, | ||
17 | + OrderDetail: orderModel.OrderDetail, | ||
18 | + OrderDividend: orderModel.OrderDividend, | ||
19 | + OrderDividendStatus: orderModel.OrderDividendStatus, | ||
20 | + OrderGoods: orderModel.OrderGoods, | ||
21 | + OrderSource: orderModel.OrderSource, | ||
22 | + OrderType: orderModel.OrderType, | ||
23 | + OrderStatus: orderModel.OrderStatus, | ||
24 | + TotalPrice: orderModel.TotalPrice, | ||
25 | + RegionInfo: orderModel.RegionInfo, | ||
26 | + Remarks: orderModel.Remarks, | ||
27 | + CreateAt: orderModel.CreateAt, | ||
28 | + UpdateAt: orderModel.UpdateAt, | ||
29 | + DeleteAt: orderModel.DeleteAt, | ||
30 | + }, nil | ||
31 | +} |
1 | +package transform | ||
2 | + | ||
3 | +import ( | ||
4 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/domain" | ||
5 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/infrastructure/pg/models" | ||
6 | +) | ||
7 | + | ||
8 | +func TransformToPartnerCategoryDomainModelFromPgModels(partnerCategoryModel *models.PartnerCategory) (*domain.PartnerCategory, error) { | ||
9 | + return &domain.PartnerCategory{ | ||
10 | + PartnerCategoryId: partnerCategoryModel.PartnerCategoryId, | ||
11 | + PartnerCategoryCode: partnerCategoryModel.PartnerCategoryCode, | ||
12 | + PartnerCategoryName: partnerCategoryModel.PartnerCategoryName, | ||
13 | + }, nil | ||
14 | +} |
1 | +package transform | ||
2 | + | ||
3 | +import ( | ||
4 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/domain" | ||
5 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/infrastructure/pg/models" | ||
6 | +) | ||
7 | + | ||
8 | +func TransformToPermissionDomainModelFromPgModels(permissionModel *models.Permission) (*domain.Permission, error) { | ||
9 | + return &domain.Permission{ | ||
10 | + PermissionId: permissionModel.PermissionId, | ||
11 | + Name: permissionModel.Name, | ||
12 | + Code: permissionModel.Code, | ||
13 | + ParentId: permissionModel.ParentId, | ||
14 | + Sort: permissionModel.Sort, | ||
15 | + Icon: permissionModel.Icon, | ||
16 | + }, nil | ||
17 | +} |
pkg/infrastructure/pg/transform/user.go
0 → 100644
1 | +package transform | ||
2 | + | ||
3 | +import ( | ||
4 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/domain" | ||
5 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/infrastructure/pg/models" | ||
6 | +) | ||
7 | + | ||
8 | +func TransformToUserDomainModelFromPgModels(userModel *models.User) (*domain.User, error) { | ||
9 | + return &domain.User{ | ||
10 | + UserId: userModel.UserId, | ||
11 | + UserType: userModel.UserType, | ||
12 | + Permissions: userModel.Permissions, | ||
13 | + CompanyId: userModel.CompanyId, | ||
14 | + UserInfo: userModel.UserInfo, | ||
15 | + PartnerInfo: userModel.PartnerInfo, | ||
16 | + Status: userModel.Status, | ||
17 | + AdminType: userModel.AdminType, | ||
18 | + AccessPartners: userModel.AccessPartners, | ||
19 | + CreateAt: userModel.CreateAt, | ||
20 | + UpdateAt: userModel.UpdateAt, | ||
21 | + DeleteAt: userModel.DeleteAt, | ||
22 | + }, nil | ||
23 | +} |
pkg/infrastructure/pg/transform/user_auth.go
0 → 100644
1 | +package transform | ||
2 | + | ||
3 | +import ( | ||
4 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/domain" | ||
5 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/infrastructure/pg/models" | ||
6 | +) | ||
7 | + | ||
8 | +func TransformToUserAuthDomainModelFromPgModels(userAuthModel *models.UserAuth) (*domain.UserAuth, error) { | ||
9 | + return &domain.UserAuth{ | ||
10 | + UserAuthId: userAuthModel.UserAuthId, | ||
11 | + Users: userAuthModel.Users, | ||
12 | + PhoneAuth: userAuthModel.PhoneAuth, | ||
13 | + CreateAt: userAuthModel.CreateAt, | ||
14 | + UpdateAt: userAuthModel.UpdateAt, | ||
15 | + }, nil | ||
16 | +} |
1 | +package repository | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "github.com/go-pg/pg/v10" | ||
6 | + | ||
7 | + "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder" | ||
8 | + pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
9 | + "github.com/linmadan/egglib-go/utils/snowflake" | ||
10 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/domain" | ||
11 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/infrastructure/pg/models" | ||
12 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/infrastructure/pg/transform" | ||
13 | +) | ||
14 | + | ||
15 | +type CompanyRepository struct { | ||
16 | + transactionContext *pgTransaction.TransactionContext | ||
17 | +} | ||
18 | + | ||
19 | +func (repository *CompanyRepository) nextIdentify() (int64, error) { | ||
20 | + IdWorker, err := snowflake.NewIdWorker(1) | ||
21 | + if err != nil { | ||
22 | + return 0, err | ||
23 | + } | ||
24 | + id, err := IdWorker.NextId() | ||
25 | + return id, err | ||
26 | +} | ||
27 | +func (repository *CompanyRepository) Save(company *domain.Company) (*domain.Company, error) { | ||
28 | + sqlBuildFields := []string{ | ||
29 | + "company_id", | ||
30 | + "company_info", | ||
31 | + "create_at", | ||
32 | + "update_at", | ||
33 | + } | ||
34 | + insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields) | ||
35 | + insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields) | ||
36 | + returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields) | ||
37 | + updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "company_id") | ||
38 | + updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields) | ||
39 | + tx := repository.transactionContext.PgTx | ||
40 | + if company.Identify() == nil { | ||
41 | + companyId, err := repository.nextIdentify() | ||
42 | + if err != nil { | ||
43 | + return company, err | ||
44 | + } else { | ||
45 | + company.CompanyId = companyId | ||
46 | + } | ||
47 | + if _, err := tx.QueryOne( | ||
48 | + pg.Scan( | ||
49 | + &company.CompanyId, | ||
50 | + &company.CompanyInfo, | ||
51 | + &company.CreateAt, | ||
52 | + &company.UpdateAt, | ||
53 | + &company.DeleteAt, | ||
54 | + ), | ||
55 | + | ||
56 | + fmt.Sprintf("INSERT INTO companies (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet), | ||
57 | + | ||
58 | + company.CompanyId, | ||
59 | + company.CompanyInfo, | ||
60 | + company.CreateAt, | ||
61 | + company.UpdateAt, | ||
62 | + company.DeleteAt, | ||
63 | + ); err != nil { | ||
64 | + return company, err | ||
65 | + } | ||
66 | + } else { | ||
67 | + if _, err := tx.QueryOne( | ||
68 | + pg.Scan( | ||
69 | + &company.CompanyId, | ||
70 | + &company.CompanyInfo, | ||
71 | + &company.CreateAt, | ||
72 | + &company.UpdateAt, | ||
73 | + &company.DeleteAt, | ||
74 | + ), | ||
75 | + | ||
76 | + fmt.Sprintf("UPDATE companies SET %s WHERE company_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet), | ||
77 | + | ||
78 | + company.CompanyInfo, | ||
79 | + company.CreateAt, | ||
80 | + company.UpdateAt, | ||
81 | + company.DeleteAt, | ||
82 | + company.Identify(), | ||
83 | + ); err != nil { | ||
84 | + return company, err | ||
85 | + } | ||
86 | + } | ||
87 | + return company, nil | ||
88 | +} | ||
89 | +func (repository *CompanyRepository) Remove(company *domain.Company) (*domain.Company, error) { | ||
90 | + tx := repository.transactionContext.PgTx | ||
91 | + companyModel := new(models.Company) | ||
92 | + companyModel.CompanyId = company.Identify().(int64) | ||
93 | + if _, err := tx.Model(companyModel).WherePK().Delete(); err != nil { | ||
94 | + return company, err | ||
95 | + } | ||
96 | + return company, nil | ||
97 | +} | ||
98 | +func (repository *CompanyRepository) FindOne(queryOptions map[string]interface{}) (*domain.Company, error) { | ||
99 | + tx := repository.transactionContext.PgTx | ||
100 | + companyModel := new(models.Company) | ||
101 | + query := sqlbuilder.BuildQuery(tx.Model(companyModel), queryOptions) | ||
102 | + query.SetWhereByQueryOption("company.company_id = ?", "companyId") | ||
103 | + query.SetWhereByQueryOption(`company.company_info @>'{"status":?}'`, "status") | ||
104 | + if err := query.First(); err != nil { | ||
105 | + if err.Error() == "pg: no rows in result set" { | ||
106 | + return nil, fmt.Errorf("没有此资源") | ||
107 | + } else { | ||
108 | + return nil, err | ||
109 | + } | ||
110 | + } | ||
111 | + if companyModel.CompanyId == 0 { | ||
112 | + return nil, nil | ||
113 | + } else { | ||
114 | + return transform.TransformToCompanyDomainModelFromPgModels(companyModel) | ||
115 | + } | ||
116 | +} | ||
117 | +func (repository *CompanyRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.Company, error) { | ||
118 | + tx := repository.transactionContext.PgTx | ||
119 | + var companyModels []*models.Company | ||
120 | + | ||
121 | + companies := make([]*domain.Company, 0) | ||
122 | + | ||
123 | + query := sqlbuilder.BuildQuery(tx.Model(&companyModels), queryOptions) | ||
124 | + query.SetOffsetAndLimit(20) | ||
125 | + query.SetOrderDirect("company_id", "DESC") | ||
126 | + if count, err := query.SelectAndCount(); err != nil { | ||
127 | + return 0, companies, err | ||
128 | + } else { | ||
129 | + for _, companyModel := range companyModels { | ||
130 | + if company, err := transform.TransformToCompanyDomainModelFromPgModels(companyModel); err != nil { | ||
131 | + return 0, companies, err | ||
132 | + } else { | ||
133 | + companies = append(companies, company) | ||
134 | + } | ||
135 | + } | ||
136 | + return int64(count), companies, nil | ||
137 | + } | ||
138 | +} | ||
139 | +func NewCompanyRepository(transactionContext *pgTransaction.TransactionContext) (*CompanyRepository, error) { | ||
140 | + if transactionContext == nil { | ||
141 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
142 | + } else { | ||
143 | + return &CompanyRepository{ | ||
144 | + transactionContext: transactionContext, | ||
145 | + }, nil | ||
146 | + } | ||
147 | +} |
1 | +package repository | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "github.com/go-pg/pg/v10" | ||
6 | + | ||
7 | + "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder" | ||
8 | + pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
9 | + "github.com/linmadan/egglib-go/utils/snowflake" | ||
10 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/domain" | ||
11 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/infrastructure/pg/models" | ||
12 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/infrastructure/pg/transform" | ||
13 | +) | ||
14 | + | ||
15 | +type GoodsRepository struct { | ||
16 | + transactionContext *pgTransaction.TransactionContext | ||
17 | +} | ||
18 | + | ||
19 | +func (repository *GoodsRepository) nextIdentify() (int64, error) { | ||
20 | + IdWorker, err := snowflake.NewIdWorker(1) | ||
21 | + if err != nil { | ||
22 | + return 0, err | ||
23 | + } | ||
24 | + id, err := IdWorker.NextId() | ||
25 | + return id, err | ||
26 | +} | ||
27 | +func (repository *GoodsRepository) Save(goods *domain.Goods) (*domain.Goods, error) { | ||
28 | + sqlBuildFields := []string{ | ||
29 | + "goods_id", | ||
30 | + "goods_num", | ||
31 | + "goods_dividend", | ||
32 | + "goods_dividend_status", | ||
33 | + "goods_name", | ||
34 | + "goods_total_price", | ||
35 | + "remarks", | ||
36 | + "order_no", | ||
37 | + "goods_detail", | ||
38 | + "create_at", | ||
39 | + "update_at", | ||
40 | + "delete_at", | ||
41 | + } | ||
42 | + insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields) | ||
43 | + insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields) | ||
44 | + returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields) | ||
45 | + updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "goods_id") | ||
46 | + updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields) | ||
47 | + tx := repository.transactionContext.PgTx | ||
48 | + if goods.Identify() == nil { | ||
49 | + goodsId, err := repository.nextIdentify() | ||
50 | + if err != nil { | ||
51 | + return goods, err | ||
52 | + } else { | ||
53 | + goods.GoodsId = goodsId | ||
54 | + } | ||
55 | + if _, err := tx.QueryOne( | ||
56 | + pg.Scan( | ||
57 | + &goods.GoodsId, | ||
58 | + &goods.GoodsNum, | ||
59 | + &goods.GoodsDividend, | ||
60 | + &goods.GoodsDividendStatus, | ||
61 | + &goods.GoodsName, | ||
62 | + &goods.GoodsTotalPrice, | ||
63 | + &goods.Remarks, | ||
64 | + &goods.OrderNo, | ||
65 | + &goods.GoodsDetail, | ||
66 | + &goods.CreateAt, | ||
67 | + &goods.UpdateAt, | ||
68 | + &goods.DeleteAt, | ||
69 | + ), | ||
70 | + fmt.Sprintf("INSERT INTO goodss (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet), | ||
71 | + goods.GoodsId, | ||
72 | + goods.GoodsNum, | ||
73 | + goods.GoodsDividend, | ||
74 | + goods.GoodsDividendStatus, | ||
75 | + goods.GoodsName, | ||
76 | + goods.GoodsTotalPrice, | ||
77 | + goods.Remarks, | ||
78 | + goods.OrderNo, | ||
79 | + goods.GoodsDetail, | ||
80 | + goods.CreateAt, | ||
81 | + goods.UpdateAt, | ||
82 | + goods.DeleteAt, | ||
83 | + ); err != nil { | ||
84 | + return goods, err | ||
85 | + } | ||
86 | + } else { | ||
87 | + if _, err := tx.QueryOne( | ||
88 | + pg.Scan( | ||
89 | + &goods.GoodsId, | ||
90 | + &goods.GoodsNum, | ||
91 | + &goods.GoodsDividend, | ||
92 | + &goods.GoodsDividendStatus, | ||
93 | + &goods.GoodsName, | ||
94 | + &goods.GoodsTotalPrice, | ||
95 | + &goods.Remarks, | ||
96 | + &goods.OrderNo, | ||
97 | + &goods.GoodsDetail, | ||
98 | + &goods.CreateAt, | ||
99 | + &goods.UpdateAt, | ||
100 | + &goods.DeleteAt, | ||
101 | + ), | ||
102 | + fmt.Sprintf("UPDATE goodss SET %s WHERE goods_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet), | ||
103 | + goods.GoodsId, | ||
104 | + goods.GoodsNum, | ||
105 | + goods.GoodsDividend, | ||
106 | + goods.GoodsDividendStatus, | ||
107 | + goods.GoodsName, | ||
108 | + goods.GoodsTotalPrice, | ||
109 | + goods.Remarks, | ||
110 | + goods.OrderNo, | ||
111 | + goods.GoodsDetail, | ||
112 | + goods.CreateAt, | ||
113 | + goods.UpdateAt, | ||
114 | + goods.DeleteAt, | ||
115 | + goods.Identify(), | ||
116 | + ); err != nil { | ||
117 | + return goods, err | ||
118 | + } | ||
119 | + } | ||
120 | + return goods, nil | ||
121 | +} | ||
122 | +func (repository *GoodsRepository) Remove(goods *domain.Goods) (*domain.Goods, error) { | ||
123 | + tx := repository.transactionContext.PgTx | ||
124 | + goodsModel := new(models.Goods) | ||
125 | + goodsModel.GoodsId = goods.Identify().(int64) | ||
126 | + if _, err := tx.Model(goodsModel).WherePK().Delete(); err != nil { | ||
127 | + return goods, err | ||
128 | + } | ||
129 | + return goods, nil | ||
130 | +} | ||
131 | +func (repository *GoodsRepository) FindOne(queryOptions map[string]interface{}) (*domain.Goods, error) { | ||
132 | + tx := repository.transactionContext.PgTx | ||
133 | + goodsModel := new(models.Goods) | ||
134 | + query := sqlbuilder.BuildQuery(tx.Model(goodsModel), queryOptions) | ||
135 | + query.SetWhereByQueryOption("goods.goods_id = ?", "goodsId") | ||
136 | + if err := query.First(); err != nil { | ||
137 | + if err.Error() == "pg: no rows in result set" { | ||
138 | + return nil, fmt.Errorf("没有此资源") | ||
139 | + } else { | ||
140 | + return nil, err | ||
141 | + } | ||
142 | + } | ||
143 | + if goodsModel.GoodsId == 0 { | ||
144 | + return nil, nil | ||
145 | + } else { | ||
146 | + return transform.TransformToGoodsDomainModelFromPgModels(goodsModel) | ||
147 | + } | ||
148 | +} | ||
149 | +func (repository *GoodsRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.Goods, error) { | ||
150 | + tx := repository.transactionContext.PgTx | ||
151 | + var goodsModels []*models.Goods | ||
152 | + goodss := make([]*domain.Goods, 0) | ||
153 | + query := sqlbuilder.BuildQuery(tx.Model(&goodsModels), queryOptions) | ||
154 | + query.SetOffsetAndLimit(20) | ||
155 | + query.SetOrderDirect("goods_id", "DESC") | ||
156 | + if count, err := query.SelectAndCount(); err != nil { | ||
157 | + return 0, goodss, err | ||
158 | + } else { | ||
159 | + for _, goodsModel := range goodsModels { | ||
160 | + if goods, err := transform.TransformToGoodsDomainModelFromPgModels(goodsModel); err != nil { | ||
161 | + return 0, goodss, err | ||
162 | + } else { | ||
163 | + goodss = append(goodss, goods) | ||
164 | + } | ||
165 | + } | ||
166 | + return int64(count), goodss, nil | ||
167 | + } | ||
168 | +} | ||
169 | +func NewGoodsRepository(transactionContext *pgTransaction.TransactionContext) (*GoodsRepository, error) { | ||
170 | + if transactionContext == nil { | ||
171 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
172 | + } else { | ||
173 | + return &GoodsRepository{ | ||
174 | + transactionContext: transactionContext, | ||
175 | + }, nil | ||
176 | + } | ||
177 | +} |
1 | +package repository | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "github.com/go-pg/pg/v10" | ||
6 | + | ||
7 | + "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder" | ||
8 | + pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
9 | + "github.com/linmadan/egglib-go/utils/snowflake" | ||
10 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/domain" | ||
11 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/infrastructure/pg/models" | ||
12 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/infrastructure/pg/transform" | ||
13 | +) | ||
14 | + | ||
15 | +type OrderRepository struct { | ||
16 | + transactionContext *pgTransaction.TransactionContext | ||
17 | +} | ||
18 | + | ||
19 | +func (repository *OrderRepository) nextIdentify() (int64, error) { | ||
20 | + IdWorker, err := snowflake.NewIdWorker(1) | ||
21 | + if err != nil { | ||
22 | + return 0, err | ||
23 | + } | ||
24 | + id, err := IdWorker.NextId() | ||
25 | + return id, err | ||
26 | +} | ||
27 | +func (repository *OrderRepository) Save(order *domain.Order) (*domain.Order, error) { | ||
28 | + sqlBuildFields := []string{ | ||
29 | + "order_id", | ||
30 | + "buyer", | ||
31 | + "company_id", | ||
32 | + "partner_id", | ||
33 | + "delivery_code", | ||
34 | + "is_disable", | ||
35 | + "order_no", | ||
36 | + "order_detail", | ||
37 | + "order_dividend", | ||
38 | + "order_dividend_status", | ||
39 | + "order_goods", | ||
40 | + "order_source", | ||
41 | + "order_type", | ||
42 | + "order_status", | ||
43 | + "total_price", | ||
44 | + "region_info", | ||
45 | + "remarks", | ||
46 | + "create_at", | ||
47 | + "update_at", | ||
48 | + "delete_at", | ||
49 | + } | ||
50 | + insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields) | ||
51 | + insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields) | ||
52 | + returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields) | ||
53 | + updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "order_id") | ||
54 | + updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields) | ||
55 | + tx := repository.transactionContext.PgTx | ||
56 | + if order.Identify() == nil { | ||
57 | + orderId, err := repository.nextIdentify() | ||
58 | + if err != nil { | ||
59 | + return order, err | ||
60 | + } else { | ||
61 | + order.OrderId = orderId | ||
62 | + } | ||
63 | + if _, err := tx.QueryOne( | ||
64 | + pg.Scan( | ||
65 | + &order.OrderId, | ||
66 | + &order.Buyer, | ||
67 | + &order.CompanyId, | ||
68 | + &order.PartnerId, | ||
69 | + &order.DeliveryCode, | ||
70 | + &order.IsDisable, | ||
71 | + &order.OrderNo, | ||
72 | + &order.OrderDetail, | ||
73 | + &order.OrderDividend, | ||
74 | + &order.OrderDividendStatus, | ||
75 | + pg.Array(&order.OrderGoods), | ||
76 | + &order.OrderSource, | ||
77 | + &order.OrderType, | ||
78 | + &order.OrderStatus, | ||
79 | + &order.TotalPrice, | ||
80 | + &order.RegionInfo, | ||
81 | + &order.Remarks, | ||
82 | + &order.CreateAt, | ||
83 | + &order.UpdateAt, | ||
84 | + &order.DeleteAt, | ||
85 | + ), | ||
86 | + fmt.Sprintf("INSERT INTO orders (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet), | ||
87 | + order.OrderId, | ||
88 | + order.Buyer, | ||
89 | + order.CompanyId, | ||
90 | + order.PartnerId, | ||
91 | + order.DeliveryCode, | ||
92 | + order.IsDisable, | ||
93 | + order.OrderNo, | ||
94 | + order.OrderDetail, | ||
95 | + order.OrderDividend, | ||
96 | + order.OrderDividendStatus, | ||
97 | + pg.Array(order.OrderGoods), | ||
98 | + order.OrderSource, | ||
99 | + order.OrderType, | ||
100 | + order.OrderStatus, | ||
101 | + order.TotalPrice, | ||
102 | + order.RegionInfo, | ||
103 | + order.Remarks, | ||
104 | + order.CreateAt, | ||
105 | + order.UpdateAt, | ||
106 | + order.DeleteAt, | ||
107 | + ); err != nil { | ||
108 | + return order, err | ||
109 | + } | ||
110 | + } else { | ||
111 | + if _, err := tx.QueryOne( | ||
112 | + pg.Scan( | ||
113 | + &order.OrderId, | ||
114 | + &order.Buyer, | ||
115 | + &order.CompanyId, | ||
116 | + &order.PartnerId, | ||
117 | + &order.DeliveryCode, | ||
118 | + &order.IsDisable, | ||
119 | + &order.OrderNo, | ||
120 | + &order.OrderDetail, | ||
121 | + &order.OrderDividend, | ||
122 | + &order.OrderDividendStatus, | ||
123 | + pg.Array(&order.OrderGoods), | ||
124 | + &order.OrderSource, | ||
125 | + &order.OrderType, | ||
126 | + &order.OrderStatus, | ||
127 | + &order.TotalPrice, | ||
128 | + &order.RegionInfo, | ||
129 | + &order.Remarks, | ||
130 | + &order.CreateAt, | ||
131 | + &order.UpdateAt, | ||
132 | + &order.DeleteAt, | ||
133 | + ), | ||
134 | + fmt.Sprintf("UPDATE orders SET %s WHERE order_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet), | ||
135 | + order.OrderId, | ||
136 | + order.Buyer, | ||
137 | + order.CompanyId, | ||
138 | + order.PartnerId, | ||
139 | + order.DeliveryCode, | ||
140 | + order.IsDisable, | ||
141 | + order.OrderNo, | ||
142 | + order.OrderDetail, | ||
143 | + order.OrderDividend, | ||
144 | + order.OrderDividendStatus, | ||
145 | + pg.Array(order.OrderGoods), | ||
146 | + order.OrderSource, | ||
147 | + order.OrderType, | ||
148 | + order.OrderStatus, | ||
149 | + order.TotalPrice, | ||
150 | + order.RegionInfo, | ||
151 | + order.Remarks, | ||
152 | + order.CreateAt, | ||
153 | + order.UpdateAt, | ||
154 | + order.DeleteAt, | ||
155 | + order.Identify(), | ||
156 | + ); err != nil { | ||
157 | + return order, err | ||
158 | + } | ||
159 | + } | ||
160 | + return order, nil | ||
161 | +} | ||
162 | +func (repository *OrderRepository) Remove(order *domain.Order) (*domain.Order, error) { | ||
163 | + tx := repository.transactionContext.PgTx | ||
164 | + orderModel := new(models.Order) | ||
165 | + orderModel.OrderId = order.Identify().(int64) | ||
166 | + if _, err := tx.Model(orderModel).WherePK().Delete(); err != nil { | ||
167 | + return order, err | ||
168 | + } | ||
169 | + return order, nil | ||
170 | +} | ||
171 | +func (repository *OrderRepository) FindOne(queryOptions map[string]interface{}) (*domain.Order, error) { | ||
172 | + tx := repository.transactionContext.PgTx | ||
173 | + orderModel := new(models.Order) | ||
174 | + query := sqlbuilder.BuildQuery(tx.Model(orderModel), queryOptions) | ||
175 | + query.SetWhereByQueryOption("order.order_id = ?", "orderId") | ||
176 | + if err := query.First(); err != nil { | ||
177 | + if err.Error() == "pg: no rows in result set" { | ||
178 | + return nil, fmt.Errorf("没有此资源") | ||
179 | + } else { | ||
180 | + return nil, err | ||
181 | + } | ||
182 | + } | ||
183 | + if orderModel.OrderId == 0 { | ||
184 | + return nil, nil | ||
185 | + } else { | ||
186 | + return transform.TransformToOrderDomainModelFromPgModels(orderModel) | ||
187 | + } | ||
188 | +} | ||
189 | +func (repository *OrderRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.Order, error) { | ||
190 | + tx := repository.transactionContext.PgTx | ||
191 | + var orderModels []*models.Order | ||
192 | + orders := make([]*domain.Order, 0) | ||
193 | + query := sqlbuilder.BuildQuery(tx.Model(&orderModels), queryOptions) | ||
194 | + query.SetOffsetAndLimit(20) | ||
195 | + query.SetOrderDirect("order_id", "DESC") | ||
196 | + if count, err := query.SelectAndCount(); err != nil { | ||
197 | + return 0, orders, err | ||
198 | + } else { | ||
199 | + for _, orderModel := range orderModels { | ||
200 | + if order, err := transform.TransformToOrderDomainModelFromPgModels(orderModel); err != nil { | ||
201 | + return 0, orders, err | ||
202 | + } else { | ||
203 | + orders = append(orders, order) | ||
204 | + } | ||
205 | + } | ||
206 | + return int64(count), orders, nil | ||
207 | + } | ||
208 | +} | ||
209 | +func NewOrderRepository(transactionContext *pgTransaction.TransactionContext) (*OrderRepository, error) { | ||
210 | + if transactionContext == nil { | ||
211 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
212 | + } else { | ||
213 | + return &OrderRepository{ | ||
214 | + transactionContext: transactionContext, | ||
215 | + }, nil | ||
216 | + } | ||
217 | +} |
1 | +package repository | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "github.com/go-pg/pg/v10" | ||
6 | + | ||
7 | + "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder" | ||
8 | + pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
9 | + "github.com/linmadan/egglib-go/utils/snowflake" | ||
10 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/domain" | ||
11 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/infrastructure/pg/models" | ||
12 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/infrastructure/pg/transform" | ||
13 | +) | ||
14 | + | ||
15 | +type PartnerCategoryRepository struct { | ||
16 | + transactionContext *pgTransaction.TransactionContext | ||
17 | +} | ||
18 | + | ||
19 | +func (repository *PartnerCategoryRepository) nextIdentify() (int64, error) { | ||
20 | + IdWorker, err := snowflake.NewIdWorker(1) | ||
21 | + if err != nil { | ||
22 | + return 0, err | ||
23 | + } | ||
24 | + id, err := IdWorker.NextId() | ||
25 | + return id, err | ||
26 | +} | ||
27 | +func (repository *PartnerCategoryRepository) Save(partnerCategory *domain.PartnerCategory) (*domain.PartnerCategory, error) { | ||
28 | + sqlBuildFields := []string{ | ||
29 | + "partner_category_id", | ||
30 | + "partner_category_code", | ||
31 | + "partner_category_name", | ||
32 | + } | ||
33 | + insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields) | ||
34 | + insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields) | ||
35 | + returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields) | ||
36 | + updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "partnerCategory_id") | ||
37 | + updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields) | ||
38 | + tx := repository.transactionContext.PgTx | ||
39 | + if partnerCategory.Identify() == nil { | ||
40 | + partnerCategoryId, err := repository.nextIdentify() | ||
41 | + if err != nil { | ||
42 | + return partnerCategory, err | ||
43 | + } else { | ||
44 | + partnerCategory.PartnerCategoryId = int(partnerCategoryId) | ||
45 | + } | ||
46 | + if _, err := tx.QueryOne( | ||
47 | + pg.Scan( | ||
48 | + &partnerCategory.PartnerCategoryId, | ||
49 | + &partnerCategory.PartnerCategoryCode, | ||
50 | + &partnerCategory.PartnerCategoryName, | ||
51 | + ), | ||
52 | + fmt.Sprintf("INSERT INTO partner_categorys (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet), | ||
53 | + partnerCategory.PartnerCategoryId, | ||
54 | + partnerCategory.PartnerCategoryCode, | ||
55 | + partnerCategory.PartnerCategoryName, | ||
56 | + ); err != nil { | ||
57 | + return partnerCategory, err | ||
58 | + } | ||
59 | + } else { | ||
60 | + if _, err := tx.QueryOne( | ||
61 | + pg.Scan( | ||
62 | + &partnerCategory.PartnerCategoryId, | ||
63 | + &partnerCategory.PartnerCategoryCode, | ||
64 | + &partnerCategory.PartnerCategoryName, | ||
65 | + ), | ||
66 | + fmt.Sprintf("UPDATE partner_categorys SET %s WHERE partner_category_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet), | ||
67 | + partnerCategory.PartnerCategoryId, | ||
68 | + partnerCategory.PartnerCategoryCode, | ||
69 | + partnerCategory.PartnerCategoryName, | ||
70 | + partnerCategory.Identify(), | ||
71 | + ); err != nil { | ||
72 | + return partnerCategory, err | ||
73 | + } | ||
74 | + } | ||
75 | + return partnerCategory, nil | ||
76 | +} | ||
77 | +func (repository *PartnerCategoryRepository) Remove(partnerCategory *domain.PartnerCategory) (*domain.PartnerCategory, error) { | ||
78 | + tx := repository.transactionContext.PgTx | ||
79 | + partnerCategoryModel := new(models.PartnerCategory) | ||
80 | + partnerCategoryModel.PartnerCategoryId = partnerCategory.Identify().(int) | ||
81 | + if _, err := tx.Model(partnerCategoryModel).WherePK().Delete(); err != nil { | ||
82 | + return partnerCategory, err | ||
83 | + } | ||
84 | + return partnerCategory, nil | ||
85 | +} | ||
86 | +func (repository *PartnerCategoryRepository) FindOne(queryOptions map[string]interface{}) (*domain.PartnerCategory, error) { | ||
87 | + tx := repository.transactionContext.PgTx | ||
88 | + partnerCategoryModel := new(models.PartnerCategory) | ||
89 | + query := sqlbuilder.BuildQuery(tx.Model(partnerCategoryModel), queryOptions) | ||
90 | + query.SetWhereByQueryOption("partner_category.partner_category_id = ?", "partnerCategoryId") | ||
91 | + if err := query.First(); err != nil { | ||
92 | + if err.Error() == "pg: no rows in result set" { | ||
93 | + return nil, fmt.Errorf("没有此资源") | ||
94 | + } else { | ||
95 | + return nil, err | ||
96 | + } | ||
97 | + } | ||
98 | + if partnerCategoryModel.PartnerCategoryId == 0 { | ||
99 | + return nil, nil | ||
100 | + } else { | ||
101 | + return transform.TransformToPartnerCategoryDomainModelFromPgModels(partnerCategoryModel) | ||
102 | + } | ||
103 | +} | ||
104 | +func (repository *PartnerCategoryRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.PartnerCategory, error) { | ||
105 | + tx := repository.transactionContext.PgTx | ||
106 | + var partnerCategoryModels []*models.PartnerCategory | ||
107 | + partnerCategorys := make([]*domain.PartnerCategory, 0) | ||
108 | + query := sqlbuilder.BuildQuery(tx.Model(&partnerCategoryModels), queryOptions) | ||
109 | + query.SetOffsetAndLimit(20) | ||
110 | + query.SetOrderDirect("partner_category_id", "DESC") | ||
111 | + if count, err := query.SelectAndCount(); err != nil { | ||
112 | + return 0, partnerCategorys, err | ||
113 | + } else { | ||
114 | + for _, partnerCategoryModel := range partnerCategoryModels { | ||
115 | + if partnerCategory, err := transform.TransformToPartnerCategoryDomainModelFromPgModels(partnerCategoryModel); err != nil { | ||
116 | + return 0, partnerCategorys, err | ||
117 | + } else { | ||
118 | + partnerCategorys = append(partnerCategorys, partnerCategory) | ||
119 | + } | ||
120 | + } | ||
121 | + return int64(count), partnerCategorys, nil | ||
122 | + } | ||
123 | +} | ||
124 | +func NewPartnerCategoryRepository(transactionContext *pgTransaction.TransactionContext) (*PartnerCategoryRepository, error) { | ||
125 | + if transactionContext == nil { | ||
126 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
127 | + } else { | ||
128 | + return &PartnerCategoryRepository{ | ||
129 | + transactionContext: transactionContext, | ||
130 | + }, nil | ||
131 | + } | ||
132 | +} |
1 | +package repository | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "github.com/go-pg/pg/v10" | ||
6 | + | ||
7 | + "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder" | ||
8 | + pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
9 | + "github.com/linmadan/egglib-go/utils/snowflake" | ||
10 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/domain" | ||
11 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/infrastructure/pg/models" | ||
12 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/infrastructure/pg/transform" | ||
13 | +) | ||
14 | + | ||
15 | +type PermissionRepository struct { | ||
16 | + transactionContext *pgTransaction.TransactionContext | ||
17 | +} | ||
18 | + | ||
19 | +func (repository *PermissionRepository) nextIdentify() (int64, error) { | ||
20 | + IdWorker, err := snowflake.NewIdWorker(1) | ||
21 | + if err != nil { | ||
22 | + return 0, err | ||
23 | + } | ||
24 | + id, err := IdWorker.NextId() | ||
25 | + return id, err | ||
26 | +} | ||
27 | +func (repository *PermissionRepository) Save(permission *domain.Permission) (*domain.Permission, error) { | ||
28 | + sqlBuildFields := []string{ | ||
29 | + "permission_id", | ||
30 | + "name", | ||
31 | + "code", | ||
32 | + "parent_id", | ||
33 | + "sort", | ||
34 | + "icon", | ||
35 | + } | ||
36 | + insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields) | ||
37 | + insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields) | ||
38 | + returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields) | ||
39 | + updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "permission_id") | ||
40 | + updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields) | ||
41 | + tx := repository.transactionContext.PgTx | ||
42 | + if permission.Identify() == nil { | ||
43 | + permissionId, err := repository.nextIdentify() | ||
44 | + if err != nil { | ||
45 | + return permission, err | ||
46 | + } else { | ||
47 | + permission.PermissionId = int(permissionId) | ||
48 | + } | ||
49 | + if _, err := tx.QueryOne( | ||
50 | + pg.Scan( | ||
51 | + &permission.PermissionId, | ||
52 | + &permission.Name, | ||
53 | + &permission.Code, | ||
54 | + &permission.ParentId, | ||
55 | + &permission.Sort, | ||
56 | + &permission.Icon, | ||
57 | + ), | ||
58 | + fmt.Sprintf("INSERT INTO permissions (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet), | ||
59 | + permission.PermissionId, | ||
60 | + permission.Name, | ||
61 | + permission.Code, | ||
62 | + permission.ParentId, | ||
63 | + permission.Sort, | ||
64 | + permission.Icon, | ||
65 | + ); err != nil { | ||
66 | + return permission, err | ||
67 | + } | ||
68 | + } else { | ||
69 | + if _, err := tx.QueryOne( | ||
70 | + pg.Scan( | ||
71 | + &permission.PermissionId, | ||
72 | + &permission.Name, | ||
73 | + &permission.Code, | ||
74 | + &permission.ParentId, | ||
75 | + &permission.Sort, | ||
76 | + &permission.Icon, | ||
77 | + ), | ||
78 | + fmt.Sprintf("UPDATE permissions SET %s WHERE permission_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet), | ||
79 | + permission.PermissionId, | ||
80 | + permission.Name, | ||
81 | + permission.Code, | ||
82 | + permission.ParentId, | ||
83 | + permission.Sort, | ||
84 | + permission.Icon, | ||
85 | + permission.Identify(), | ||
86 | + ); err != nil { | ||
87 | + return permission, err | ||
88 | + } | ||
89 | + } | ||
90 | + return permission, nil | ||
91 | +} | ||
92 | +func (repository *PermissionRepository) Remove(permission *domain.Permission) (*domain.Permission, error) { | ||
93 | + tx := repository.transactionContext.PgTx | ||
94 | + permissionModel := new(models.Permission) | ||
95 | + permissionModel.PermissionId = permission.Identify().(int) | ||
96 | + if _, err := tx.Model(permissionModel).WherePK().Delete(); err != nil { | ||
97 | + return permission, err | ||
98 | + } | ||
99 | + return permission, nil | ||
100 | +} | ||
101 | +func (repository *PermissionRepository) FindOne(queryOptions map[string]interface{}) (*domain.Permission, error) { | ||
102 | + tx := repository.transactionContext.PgTx | ||
103 | + permissionModel := new(models.Permission) | ||
104 | + query := sqlbuilder.BuildQuery(tx.Model(permissionModel), queryOptions) | ||
105 | + query.SetWhereByQueryOption("permission.permission_id = ?", "permissionId") | ||
106 | + if err := query.First(); err != nil { | ||
107 | + if err.Error() == "pg: no rows in result set" { | ||
108 | + return nil, fmt.Errorf("没有此资源") | ||
109 | + } else { | ||
110 | + return nil, err | ||
111 | + } | ||
112 | + } | ||
113 | + if permissionModel.PermissionId == 0 { | ||
114 | + return nil, nil | ||
115 | + } else { | ||
116 | + return transform.TransformToPermissionDomainModelFromPgModels(permissionModel) | ||
117 | + } | ||
118 | +} | ||
119 | +func (repository *PermissionRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.Permission, error) { | ||
120 | + tx := repository.transactionContext.PgTx | ||
121 | + var permissionModels []*models.Permission | ||
122 | + permissions := make([]*domain.Permission, 0) | ||
123 | + query := sqlbuilder.BuildQuery(tx.Model(&permissionModels), queryOptions) | ||
124 | + query.SetOffsetAndLimit(20) | ||
125 | + query.SetOrderDirect("permission_id", "DESC") | ||
126 | + if count, err := query.SelectAndCount(); err != nil { | ||
127 | + return 0, permissions, err | ||
128 | + } else { | ||
129 | + for _, permissionModel := range permissionModels { | ||
130 | + if permission, err := transform.TransformToPermissionDomainModelFromPgModels(permissionModel); err != nil { | ||
131 | + return 0, permissions, err | ||
132 | + } else { | ||
133 | + permissions = append(permissions, permission) | ||
134 | + } | ||
135 | + } | ||
136 | + return int64(count), permissions, nil | ||
137 | + } | ||
138 | +} | ||
139 | +func NewPermissionRepository(transactionContext *pgTransaction.TransactionContext) (*PermissionRepository, error) { | ||
140 | + if transactionContext == nil { | ||
141 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
142 | + } else { | ||
143 | + return &PermissionRepository{ | ||
144 | + transactionContext: transactionContext, | ||
145 | + }, nil | ||
146 | + } | ||
147 | +} |
1 | +package repository | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "github.com/go-pg/pg/v10" | ||
6 | + | ||
7 | + "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder" | ||
8 | + pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
9 | + "github.com/linmadan/egglib-go/utils/snowflake" | ||
10 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/domain" | ||
11 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/infrastructure/pg/models" | ||
12 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/infrastructure/pg/transform" | ||
13 | +) | ||
14 | + | ||
15 | +type UserAuthRepository struct { | ||
16 | + transactionContext *pgTransaction.TransactionContext | ||
17 | +} | ||
18 | + | ||
19 | +func (repository *UserAuthRepository) nextIdentify() (int64, error) { | ||
20 | + IdWorker, err := snowflake.NewIdWorker(1) | ||
21 | + if err != nil { | ||
22 | + return 0, err | ||
23 | + } | ||
24 | + id, err := IdWorker.NextId() | ||
25 | + return id, err | ||
26 | +} | ||
27 | +func (repository *UserAuthRepository) Save(userAuth *domain.UserAuth) (*domain.UserAuth, error) { | ||
28 | + sqlBuildFields := []string{ | ||
29 | + "user_auth_id", | ||
30 | + "users", | ||
31 | + "phone_auth", | ||
32 | + "create_at", | ||
33 | + "update_at", | ||
34 | + } | ||
35 | + insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields) | ||
36 | + insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields) | ||
37 | + returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields) | ||
38 | + updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "userAuth_id") | ||
39 | + updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields) | ||
40 | + tx := repository.transactionContext.PgTx | ||
41 | + if userAuth.Identify() == nil { | ||
42 | + userAuthId, err := repository.nextIdentify() | ||
43 | + if err != nil { | ||
44 | + return userAuth, err | ||
45 | + } else { | ||
46 | + userAuth.UserAuthId = userAuthId | ||
47 | + } | ||
48 | + if _, err := tx.QueryOne( | ||
49 | + pg.Scan( | ||
50 | + &userAuth.UserAuthId, | ||
51 | + pg.Array(&userAuth.Users), | ||
52 | + &userAuth.PhoneAuth, | ||
53 | + &userAuth.CreateAt, | ||
54 | + &userAuth.UpdateAt, | ||
55 | + ), | ||
56 | + fmt.Sprintf("INSERT INTO user_auth (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet), | ||
57 | + userAuth.UserAuthId, | ||
58 | + pg.Array(userAuth.Users), | ||
59 | + userAuth.PhoneAuth, | ||
60 | + userAuth.CreateAt, | ||
61 | + userAuth.UpdateAt, | ||
62 | + ); err != nil { | ||
63 | + return userAuth, err | ||
64 | + } | ||
65 | + } else { | ||
66 | + if _, err := tx.QueryOne( | ||
67 | + pg.Scan( | ||
68 | + &userAuth.UserAuthId, | ||
69 | + pg.Array(&userAuth.Users), | ||
70 | + &userAuth.PhoneAuth, | ||
71 | + &userAuth.CreateAt, | ||
72 | + &userAuth.UpdateAt, | ||
73 | + ), | ||
74 | + fmt.Sprintf("UPDATE user_auth SET %s WHERE user_auth_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet), | ||
75 | + userAuth.UserAuthId, | ||
76 | + pg.Array(userAuth.Users), | ||
77 | + userAuth.PhoneAuth, | ||
78 | + userAuth.CreateAt, | ||
79 | + userAuth.UpdateAt, | ||
80 | + userAuth.Identify(), | ||
81 | + ); err != nil { | ||
82 | + return userAuth, err | ||
83 | + } | ||
84 | + } | ||
85 | + return userAuth, nil | ||
86 | +} | ||
87 | +func (repository *UserAuthRepository) Remove(userAuth *domain.UserAuth) (*domain.UserAuth, error) { | ||
88 | + tx := repository.transactionContext.PgTx | ||
89 | + userAuthModel := new(models.UserAuth) | ||
90 | + userAuthModel.UserAuthId = userAuth.Identify().(int64) | ||
91 | + if _, err := tx.Model(userAuthModel).WherePK().Delete(); err != nil { | ||
92 | + return userAuth, err | ||
93 | + } | ||
94 | + return userAuth, nil | ||
95 | +} | ||
96 | +func (repository *UserAuthRepository) FindOne(queryOptions map[string]interface{}) (*domain.UserAuth, error) { | ||
97 | + tx := repository.transactionContext.PgTx | ||
98 | + userAuthModel := new(models.UserAuth) | ||
99 | + query := sqlbuilder.BuildQuery(tx.Model(userAuthModel), queryOptions) | ||
100 | + query.SetWhereByQueryOption("user_auth.user_auth_id = ?", "userAuthId") | ||
101 | + if v, ok := queryOptions["phone"]; ok { | ||
102 | + query.Where(fmt.Sprintf(`user_auth.phone_auth @>'{"phone":"%v"}'`, v)) | ||
103 | + } | ||
104 | + if err := query.First(); err != nil { | ||
105 | + if err.Error() == "pg: no rows in result set" { | ||
106 | + return nil, fmt.Errorf("没有此资源") | ||
107 | + } else { | ||
108 | + return nil, err | ||
109 | + } | ||
110 | + } | ||
111 | + if userAuthModel.UserAuthId == 0 { | ||
112 | + return nil, nil | ||
113 | + } else { | ||
114 | + return transform.TransformToUserAuthDomainModelFromPgModels(userAuthModel) | ||
115 | + } | ||
116 | +} | ||
117 | +func (repository *UserAuthRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.UserAuth, error) { | ||
118 | + tx := repository.transactionContext.PgTx | ||
119 | + var userAuthModels []*models.UserAuth | ||
120 | + userAuths := make([]*domain.UserAuth, 0) | ||
121 | + query := sqlbuilder.BuildQuery(tx.Model(&userAuthModels), queryOptions) | ||
122 | + query.SetOffsetAndLimit(20) | ||
123 | + query.SetOrderDirect("user_auth_id", "DESC") | ||
124 | + if count, err := query.SelectAndCount(); err != nil { | ||
125 | + return 0, userAuths, err | ||
126 | + } else { | ||
127 | + for _, userAuthModel := range userAuthModels { | ||
128 | + if userAuth, err := transform.TransformToUserAuthDomainModelFromPgModels(userAuthModel); err != nil { | ||
129 | + return 0, userAuths, err | ||
130 | + } else { | ||
131 | + userAuths = append(userAuths, userAuth) | ||
132 | + } | ||
133 | + } | ||
134 | + return int64(count), userAuths, nil | ||
135 | + } | ||
136 | +} | ||
137 | +func NewUserAuthRepository(transactionContext *pgTransaction.TransactionContext) (*UserAuthRepository, error) { | ||
138 | + if transactionContext == nil { | ||
139 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
140 | + } else { | ||
141 | + return &UserAuthRepository{ | ||
142 | + transactionContext: transactionContext, | ||
143 | + }, nil | ||
144 | + } | ||
145 | +} |
1 | +package repository | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "github.com/go-pg/pg/v10" | ||
6 | + | ||
7 | + "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder" | ||
8 | + pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
9 | + "github.com/linmadan/egglib-go/utils/snowflake" | ||
10 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/domain" | ||
11 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/infrastructure/pg/models" | ||
12 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/infrastructure/pg/transform" | ||
13 | +) | ||
14 | + | ||
15 | +type UserRepository struct { | ||
16 | + transactionContext *pgTransaction.TransactionContext | ||
17 | +} | ||
18 | + | ||
19 | +func (repository *UserRepository) nextIdentify() (int64, error) { | ||
20 | + IdWorker, err := snowflake.NewIdWorker(1) | ||
21 | + if err != nil { | ||
22 | + return 0, err | ||
23 | + } | ||
24 | + id, err := IdWorker.NextId() | ||
25 | + return id, err | ||
26 | +} | ||
27 | +func (repository *UserRepository) Save(user *domain.User) (*domain.User, error) { | ||
28 | + sqlBuildFields := []string{ | ||
29 | + "user_id", | ||
30 | + "user_type", | ||
31 | + "permissions", | ||
32 | + "company_id", | ||
33 | + "user_info", | ||
34 | + "partner_info", | ||
35 | + "status", | ||
36 | + "admin_type", | ||
37 | + "access_partners", | ||
38 | + "create_at", | ||
39 | + "update_at", | ||
40 | + "delete_at", | ||
41 | + } | ||
42 | + insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields) | ||
43 | + insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields) | ||
44 | + returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields) | ||
45 | + updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "user_id") | ||
46 | + updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields) | ||
47 | + tx := repository.transactionContext.PgTx | ||
48 | + if user.Identify() == nil { | ||
49 | + userId, err := repository.nextIdentify() | ||
50 | + if err != nil { | ||
51 | + return user, err | ||
52 | + } else { | ||
53 | + user.UserId = userId | ||
54 | + } | ||
55 | + if _, err := tx.QueryOne( | ||
56 | + pg.Scan( | ||
57 | + &user.UserId, | ||
58 | + &user.UserType, | ||
59 | + pg.Array(&user.Permissions), | ||
60 | + &user.CompanyId, | ||
61 | + &user.UserInfo, | ||
62 | + &user.PartnerInfo, | ||
63 | + &user.Status, | ||
64 | + &user.AdminType, | ||
65 | + pg.Array(&user.AccessPartners), | ||
66 | + &user.CreateAt, | ||
67 | + &user.UpdateAt, | ||
68 | + &user.DeleteAt, | ||
69 | + ), | ||
70 | + fmt.Sprintf("INSERT INTO users (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet), | ||
71 | + user.UserId, | ||
72 | + user.UserType, | ||
73 | + pg.Array(user.Permissions), | ||
74 | + user.CompanyId, | ||
75 | + user.UserInfo, | ||
76 | + user.PartnerInfo, | ||
77 | + user.Status, | ||
78 | + user.AdminType, | ||
79 | + pg.Array(user.AccessPartners), | ||
80 | + user.CreateAt, | ||
81 | + user.UpdateAt, | ||
82 | + user.DeleteAt, | ||
83 | + ); err != nil { | ||
84 | + return user, err | ||
85 | + } | ||
86 | + } else { | ||
87 | + if _, err := tx.QueryOne( | ||
88 | + pg.Scan( | ||
89 | + &user.UserId, | ||
90 | + &user.UserType, | ||
91 | + pg.Array(&user.Permissions), | ||
92 | + &user.CompanyId, | ||
93 | + &user.UserInfo, | ||
94 | + &user.PartnerInfo, | ||
95 | + &user.Status, | ||
96 | + &user.AdminType, | ||
97 | + pg.Array(&user.AccessPartners), | ||
98 | + &user.CreateAt, | ||
99 | + &user.UpdateAt, | ||
100 | + &user.DeleteAt, | ||
101 | + ), | ||
102 | + fmt.Sprintf("UPDATE users SET %s WHERE user_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet), | ||
103 | + user.UserId, | ||
104 | + user.UserType, | ||
105 | + pg.Array(user.Permissions), | ||
106 | + user.CompanyId, | ||
107 | + user.UserInfo, | ||
108 | + user.PartnerInfo, | ||
109 | + user.Status, | ||
110 | + user.AdminType, | ||
111 | + pg.Array(user.AccessPartners), | ||
112 | + user.CreateAt, | ||
113 | + user.UpdateAt, | ||
114 | + user.DeleteAt, | ||
115 | + user.Identify(), | ||
116 | + ); err != nil { | ||
117 | + return user, err | ||
118 | + } | ||
119 | + } | ||
120 | + return user, nil | ||
121 | +} | ||
122 | +func (repository *UserRepository) Remove(user *domain.User) (*domain.User, error) { | ||
123 | + tx := repository.transactionContext.PgTx | ||
124 | + userModel := new(models.User) | ||
125 | + userModel.UserId = user.Identify().(int64) | ||
126 | + if _, err := tx.Model(userModel).WherePK().Delete(); err != nil { | ||
127 | + return user, err | ||
128 | + } | ||
129 | + return user, nil | ||
130 | +} | ||
131 | +func (repository *UserRepository) FindOne(queryOptions map[string]interface{}) (*domain.User, error) { | ||
132 | + tx := repository.transactionContext.PgTx | ||
133 | + userModel := new(models.User) | ||
134 | + query := sqlbuilder.BuildQuery(tx.Model(userModel), queryOptions) | ||
135 | + query.SetWhereByQueryOption("users.user_id = ?", "userId") | ||
136 | + query.SetWhereByQueryOption("users.status = ?", "status") | ||
137 | + query.SetWhereByQueryOption("users.user_type = ?", "userType") | ||
138 | + if v, ok := queryOptions["inUserIds"]; ok { | ||
139 | + query.Where("users.user_id in (?)", pg.Array(v)) | ||
140 | + } | ||
141 | + if err := query.First(); err != nil { | ||
142 | + if err.Error() == "pg: no rows in result set" { | ||
143 | + return nil, fmt.Errorf("没有此资源") | ||
144 | + } else { | ||
145 | + return nil, err | ||
146 | + } | ||
147 | + } | ||
148 | + if userModel.UserId == 0 { | ||
149 | + return nil, nil | ||
150 | + } else { | ||
151 | + return transform.TransformToUserDomainModelFromPgModels(userModel) | ||
152 | + } | ||
153 | +} | ||
154 | +func (repository *UserRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.User, error) { | ||
155 | + tx := repository.transactionContext.PgTx | ||
156 | + var userModels []*models.User | ||
157 | + users := make([]*domain.User, 0) | ||
158 | + query := sqlbuilder.BuildQuery(tx.Model(&userModels), queryOptions) | ||
159 | + query.SetOffsetAndLimit(20) | ||
160 | + query.SetOrderDirect("user_id", "DESC") | ||
161 | + if count, err := query.SelectAndCount(); err != nil { | ||
162 | + return 0, users, err | ||
163 | + } else { | ||
164 | + for _, userModel := range userModels { | ||
165 | + if user, err := transform.TransformToUserDomainModelFromPgModels(userModel); err != nil { | ||
166 | + return 0, users, err | ||
167 | + } else { | ||
168 | + users = append(users, user) | ||
169 | + } | ||
170 | + } | ||
171 | + return int64(count), users, nil | ||
172 | + } | ||
173 | +} | ||
174 | +func NewUserRepository(transactionContext *pgTransaction.TransactionContext) (*UserRepository, error) { | ||
175 | + if transactionContext == nil { | ||
176 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
177 | + } else { | ||
178 | + return &UserRepository{ | ||
179 | + transactionContext: transactionContext, | ||
180 | + }, nil | ||
181 | + } | ||
182 | +} |
pkg/log/logger.go
0 → 100644
1 | +package log | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/linmadan/egglib-go/log" | ||
5 | + "github.com/linmadan/egglib-go/log/logrus" | ||
6 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/constant" | ||
7 | +) | ||
8 | + | ||
9 | +var Logger log.Logger | ||
10 | + | ||
11 | +func init() { | ||
12 | + Logger = logrus.NewLogrusLogger() | ||
13 | + Logger.SetServiceName(constant.SERVICE_NAME) | ||
14 | + Logger.SetLevel(constant.LOG_LEVEL) | ||
15 | +} |
pkg/port/beego/beego.go
0 → 100644
1 | +package beego | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/beego/beego/v2/server/web" | ||
5 | + "github.com/linmadan/egglib-go/web/beego/filters" | ||
6 | + "os" | ||
7 | + "strconv" | ||
8 | + | ||
9 | + . "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/log" | ||
10 | + _ "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/port/beego/routers" | ||
11 | +) | ||
12 | + | ||
13 | +func init() { | ||
14 | + web.BConfig.AppName = "partner01" | ||
15 | + web.BConfig.CopyRequestBody = true | ||
16 | + web.BConfig.RunMode = "dev" | ||
17 | + web.BConfig.Listen.HTTPPort = 8081 | ||
18 | + web.BConfig.Listen.EnableAdmin = false | ||
19 | + web.BConfig.WebConfig.CommentRouterPath = "/pkg/port/beego" | ||
20 | + if os.Getenv("RUN_MODE") != "" { | ||
21 | + web.BConfig.RunMode = os.Getenv("RUN_MODE") | ||
22 | + } | ||
23 | + if os.Getenv("HTTP_PORT") != "" { | ||
24 | + portStr := os.Getenv("HTTP_PORT") | ||
25 | + if port, err := strconv.Atoi(portStr); err == nil { | ||
26 | + web.BConfig.Listen.HTTPPort = port | ||
27 | + } | ||
28 | + } | ||
29 | + web.InsertFilter("/*", web.BeforeExec, filters.AllowCors()) | ||
30 | + web.InsertFilter("/*", web.BeforeExec, filters.CreateRequstLogFilter(Logger)) | ||
31 | + web.InsertFilter("/*", web.AfterExec, filters.CreateResponseLogFilter(Logger), web.WithReturnOnOutput(false)) | ||
32 | +} |
1 | +package controllers | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/linmadan/egglib-go/web/beego" | ||
5 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/application/auth/command" | ||
6 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/application/auth/query" | ||
7 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/application/auth/service" | ||
8 | +) | ||
9 | + | ||
10 | +type AuthController struct { | ||
11 | + beego.BaseController | ||
12 | +} | ||
13 | + | ||
14 | +func (controller *AuthController) Login() { | ||
15 | + authService := service.NewAuthService(nil) | ||
16 | + loginQuery := &query.LoginQuery{} | ||
17 | + controller.Unmarshal(loginQuery) | ||
18 | + data, err := authService.Login(loginQuery) | ||
19 | + controller.Response(data, err) | ||
20 | +} | ||
21 | + | ||
22 | +func (controller *AuthController) LoginByCompany() { | ||
23 | + authService := service.NewAuthService(nil) | ||
24 | + loginByCompanyCommand := &command.LoginByCompanyCommand{} | ||
25 | + controller.Unmarshal(loginByCompanyCommand) | ||
26 | + data, err := authService.LoginByCompany(loginByCompanyCommand) | ||
27 | + controller.Response(data, err) | ||
28 | +} | ||
29 | + | ||
30 | +func (controller *AuthController) AccessToken() { | ||
31 | + authService := service.NewAuthService(nil) | ||
32 | + accessTokenCommand := &command.AccessTokenCommand{} | ||
33 | + controller.Unmarshal(accessTokenCommand) | ||
34 | + data, err := authService.AccessToken(accessTokenCommand) | ||
35 | + controller.Response(data, err) | ||
36 | +} | ||
37 | + | ||
38 | +func (controller *AuthController) RefreshToken() { | ||
39 | + authService := service.NewAuthService(nil) | ||
40 | + refreshTokenCommand := &command.RefreshTokenCommand{} | ||
41 | + controller.Unmarshal(refreshTokenCommand) | ||
42 | + data, err := authService.RefreshToken(refreshTokenCommand) | ||
43 | + controller.Response(data, err) | ||
44 | +} | ||
45 | + | ||
46 | +func (controller *AuthController) SendSmsCode() { | ||
47 | + authService := service.NewAuthService(nil) | ||
48 | + sendSmsCodeCommand := &command.SendSmsCodeCommand{} | ||
49 | + controller.Unmarshal(sendSmsCodeCommand) | ||
50 | + data, err := authService.SendSmsCode(sendSmsCodeCommand) | ||
51 | + controller.Response(data, err) | ||
52 | +} | ||
53 | + | ||
54 | +func (controller *AuthController) Revoke() { | ||
55 | + authService := service.NewAuthService(nil) | ||
56 | + revokeCommand := &command.RevokeCommand{} | ||
57 | + controller.Unmarshal(revokeCommand) | ||
58 | + data, err := authService.Revoke(revokeCommand) | ||
59 | + controller.Response(data, err) | ||
60 | +} | ||
61 | + | ||
62 | +func (controller *AuthController) ChangePassword() { | ||
63 | + authService := service.NewAuthService(nil) | ||
64 | + changePasswordCommand := &command.ChangePasswordCommand{} | ||
65 | + controller.Unmarshal(changePasswordCommand) | ||
66 | + data, err := authService.ChangePassword(changePasswordCommand) | ||
67 | + controller.Response(data, err) | ||
68 | +} |
1 | +package controllers | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/linmadan/egglib-go/web/beego" | ||
5 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/application/company/command" | ||
6 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/application/company/query" | ||
7 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/application/company/service" | ||
8 | +) | ||
9 | + | ||
10 | +type CompanyController struct { | ||
11 | + beego.BaseController | ||
12 | +} | ||
13 | + | ||
14 | +func (controller *CompanyController) CreateCompany() { | ||
15 | + companyService := service.NewCompanyService(nil) | ||
16 | + createCompanyCommand := &command.CreateCompanyCommand{} | ||
17 | + controller.Unmarshal(createCompanyCommand) | ||
18 | + data, err := companyService.CreateCompany(createCompanyCommand) | ||
19 | + controller.Response(data, err) | ||
20 | +} | ||
21 | + | ||
22 | +func (controller *CompanyController) UpdateCompany() { | ||
23 | + companyService := service.NewCompanyService(nil) | ||
24 | + updateCompanyCommand := &command.UpdateCompanyCommand{} | ||
25 | + controller.Unmarshal(updateCompanyCommand) | ||
26 | + companyId, _ := controller.GetInt64(":companyId") | ||
27 | + updateCompanyCommand.CompanyId = companyId | ||
28 | + data, err := companyService.UpdateCompany(updateCompanyCommand) | ||
29 | + controller.Response(data, err) | ||
30 | +} | ||
31 | + | ||
32 | +func (controller *CompanyController) GetCompany() { | ||
33 | + companyService := service.NewCompanyService(nil) | ||
34 | + getCompanyQuery := &query.GetCompanyQuery{} | ||
35 | + companyId, _ := controller.GetInt64(":companyId") | ||
36 | + getCompanyQuery.CompanyId = companyId | ||
37 | + data, err := companyService.GetCompany(getCompanyQuery) | ||
38 | + controller.Response(data, err) | ||
39 | +} | ||
40 | + | ||
41 | +func (controller *CompanyController) RemoveCompany() { | ||
42 | + companyService := service.NewCompanyService(nil) | ||
43 | + removeCompanyCommand := &command.RemoveCompanyCommand{} | ||
44 | + controller.Unmarshal(removeCompanyCommand) | ||
45 | + companyId, _ := controller.GetInt64(":companyId") | ||
46 | + removeCompanyCommand.CompanyId = companyId | ||
47 | + data, err := companyService.RemoveCompany(removeCompanyCommand) | ||
48 | + controller.Response(data, err) | ||
49 | +} | ||
50 | + | ||
51 | +func (controller *CompanyController) ListCompany() { | ||
52 | + companyService := service.NewCompanyService(nil) | ||
53 | + listCompanyQuery := &query.ListCompanyQuery{} | ||
54 | + offset, _ := controller.GetInt("offset") | ||
55 | + listCompanyQuery.Offset = offset | ||
56 | + limit, _ := controller.GetInt("limit") | ||
57 | + listCompanyQuery.Limit = limit | ||
58 | + data, err := companyService.ListCompany(listCompanyQuery) | ||
59 | + controller.Response(data, err) | ||
60 | +} | ||
61 | + | ||
62 | +func (controller *CompanyController) ConvertCompanyStatus() { | ||
63 | + companyService := service.NewCompanyService(nil) | ||
64 | + convertCompanyStatusCommand := &command.ConvertCompanyStatusCommand{} | ||
65 | + controller.Unmarshal(convertCompanyStatusCommand) | ||
66 | + data, err := companyService.ConvertCompanyStatus(convertCompanyStatusCommand) | ||
67 | + controller.Response(data, err) | ||
68 | +} | ||
69 | + | ||
70 | +func (controller *CompanyController) SetCompanyAdmin() { | ||
71 | + companyService := service.NewCompanyService(nil) | ||
72 | + setCompanyAdminCommand := &command.SetCompanyAdminCommand{} | ||
73 | + controller.Unmarshal(setCompanyAdminCommand) | ||
74 | + data, err := companyService.SetCompanyAdmin(setCompanyAdminCommand) | ||
75 | + controller.Response(data, err) | ||
76 | +} |
1 | +package controllers | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/linmadan/egglib-go/web/beego" | ||
5 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/application/order/command" | ||
6 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/application/order/query" | ||
7 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/application/order/service" | ||
8 | +) | ||
9 | + | ||
10 | +type OrderController struct { | ||
11 | + beego.BaseController | ||
12 | +} | ||
13 | + | ||
14 | +func (controller *OrderController) CreateOrder() { | ||
15 | + orderService := service.NewOrderService(nil) | ||
16 | + createOrderCommand := &command.CreateOrderCommand{} | ||
17 | + controller.Unmarshal(createOrderCommand) | ||
18 | + data, err := orderService.CreateOrder(createOrderCommand) | ||
19 | + controller.Response(data, err) | ||
20 | +} | ||
21 | + | ||
22 | +func (controller *OrderController) UpdateOrder() { | ||
23 | + orderService := service.NewOrderService(nil) | ||
24 | + updateOrderCommand := &command.UpdateOrderCommand{} | ||
25 | + _ = controller.Unmarshal(updateOrderCommand) | ||
26 | + orderId, _ := controller.GetInt64(":orderId") | ||
27 | + updateOrderCommand.OrderId = orderId | ||
28 | + data, err := orderService.UpdateOrder(updateOrderCommand) | ||
29 | + controller.Response(data, err) | ||
30 | +} | ||
31 | + | ||
32 | +func (controller *OrderController) GetOrder() { | ||
33 | + orderService := service.NewOrderService(nil) | ||
34 | + getOrderQuery := &query.GetOrderQuery{} | ||
35 | + orderId, _ := controller.GetInt64(":orderId") | ||
36 | + getOrderQuery.OrderId = orderId | ||
37 | + data, err := orderService.GetOrder(getOrderQuery) | ||
38 | + controller.Response(data, err) | ||
39 | +} | ||
40 | + | ||
41 | +func (controller *OrderController) RemoveOrder() { | ||
42 | + orderService := service.NewOrderService(nil) | ||
43 | + removeOrderCommand := &command.RemoveOrderCommand{} | ||
44 | + _ = controller.Unmarshal(removeOrderCommand) | ||
45 | + orderId, _ := controller.GetInt64(":orderId") | ||
46 | + removeOrderCommand.OrderId = orderId | ||
47 | + data, err := orderService.RemoveOrder(removeOrderCommand) | ||
48 | + controller.Response(data, err) | ||
49 | +} | ||
50 | + | ||
51 | +func (controller *OrderController) ListOrder() { | ||
52 | + orderService := service.NewOrderService(nil) | ||
53 | + listOrderQuery := &query.ListOrderQuery{} | ||
54 | + offset, _ := controller.GetInt("offset") | ||
55 | + listOrderQuery.Offset = offset | ||
56 | + limit, _ := controller.GetInt("limit") | ||
57 | + listOrderQuery.Limit = limit | ||
58 | + data, err := orderService.ListOrder(listOrderQuery) | ||
59 | + controller.Response(data, err) | ||
60 | +} | ||
61 | + | ||
62 | +func (controller *OrderController) Shipping() { | ||
63 | + orderService := service.NewOrderService(nil) | ||
64 | + shippingCmd := &command.ShippingGoodsCommand{} | ||
65 | + _ = controller.Unmarshal(shippingCmd) | ||
66 | + orderId, _ := controller.GetInt(":orderId") | ||
67 | + shippingCmd.OrderId = orderId | ||
68 | + data, err := orderService.ShippingGoods(shippingCmd) | ||
69 | + controller.Response(data, err) | ||
70 | +} |
1 | +package controllers | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/linmadan/egglib-go/web/beego" | ||
5 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/application/partner/query" | ||
6 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/application/partner/service" | ||
7 | +) | ||
8 | + | ||
9 | +type PartnerController struct { | ||
10 | + beego.BaseController | ||
11 | +} | ||
12 | + | ||
13 | +func (controller *PartnerController) PartnerCategories() { | ||
14 | + partnerService := service.NewPartnerService(nil) | ||
15 | + partnerCategoriesQuery := &query.PartnerCategoriesQuery{} | ||
16 | + data, err := partnerService.PartnerCategories(partnerCategoriesQuery) | ||
17 | + controller.Response(data, err) | ||
18 | +} |
1 | +package controllers | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/linmadan/egglib-go/web/beego" | ||
5 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/application/permission/query" | ||
6 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/application/permission/service" | ||
7 | +) | ||
8 | + | ||
9 | +type PermissionController struct { | ||
10 | + beego.BaseController | ||
11 | +} | ||
12 | + | ||
13 | +func (controller *PermissionController) Menus() { | ||
14 | + permissionService := service.NewPermissionService(nil) | ||
15 | + menusQuery := &query.MenusQuery{} | ||
16 | + data, err := permissionService.Menus(menusQuery) | ||
17 | + controller.Response(data, err) | ||
18 | +} |
pkg/port/beego/routers/auth_router.go
0 → 100644
1 | +package routers | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/beego/beego/v2/server/web" | ||
5 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/port/beego/controllers" | ||
6 | +) | ||
7 | + | ||
8 | +func init() { | ||
9 | + web.Router("/auths/login", &controllers.AuthController{}, "Post:Login") | ||
10 | + web.Router("/auths/loginByCompany", &controllers.AuthController{}, "Post:LoginByCompany") | ||
11 | + web.Router("/auths/accessToken", &controllers.AuthController{}, "Post:AccessToken") | ||
12 | + web.Router("/auths/refreshToken", &controllers.AuthController{}, "Post:RefreshToken") | ||
13 | + web.Router("/auths/sendSmsCode", &controllers.AuthController{}, "Post:SendSmsCode") | ||
14 | + web.Router("/auths/revoke", &controllers.AuthController{}, "Post:Revoke") | ||
15 | + web.Router("/auths/changePhonePassword", &controllers.AuthController{}, "Post:ChangePassword") | ||
16 | +} |
pkg/port/beego/routers/company_router.go
0 → 100644
1 | +package routers | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/beego/beego/v2/server/web" | ||
5 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/port/beego/controllers" | ||
6 | +) | ||
7 | + | ||
8 | +func init() { | ||
9 | + web.Router("/companies/", &controllers.CompanyController{}, "Post:CreateCompany") | ||
10 | + web.Router("/companies/:companyId", &controllers.CompanyController{}, "Put:UpdateCompany") | ||
11 | + web.Router("/companies/:companyId", &controllers.CompanyController{}, "Get:GetCompany") | ||
12 | + web.Router("/companies/:companyId", &controllers.CompanyController{}, "Delete:RemoveCompany") | ||
13 | + web.Router("/companies/", &controllers.CompanyController{}, "Get:ListCompany") | ||
14 | + web.Router("/companies/convertCompanyStatus", &controllers.CompanyController{}, "Post:ConvertCompanyStatus") | ||
15 | + web.Router("/companies/setCompanyAdmin", &controllers.CompanyController{}, "Post:SetCompanyAdmin") | ||
16 | +} |
pkg/port/beego/routers/order_router.go
0 → 100644
1 | +package routers | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/beego/beego/v2/server/web" | ||
5 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/port/beego/controllers" | ||
6 | +) | ||
7 | + | ||
8 | +func init() { | ||
9 | + web.Router("/orders/", &controllers.OrderController{}, "Post:CreateOrder") | ||
10 | + web.Router("/orders/:orderId", &controllers.OrderController{}, "Put:UpdateOrder") | ||
11 | + web.Router("/orders/:orderId", &controllers.OrderController{}, "Get:GetOrder") | ||
12 | + web.Router("/orders/:orderId", &controllers.OrderController{}, "Delete:RemoveOrder") | ||
13 | + web.Router("/orders/", &controllers.OrderController{}, "Get:ListOrder") | ||
14 | +} |
pkg/port/beego/routers/partner_router.go
0 → 100644
pkg/port/beego/routers/permission_router.go
0 → 100644
1 | +package auth | ||
2 | + | ||
3 | +import ( | ||
4 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/domain" | ||
5 | + "net/http" | ||
6 | + | ||
7 | + "github.com/gavv/httpexpect" | ||
8 | + . "github.com/onsi/ginkgo" | ||
9 | +) | ||
10 | + | ||
11 | +var _ = Describe("用户按公司登录", func() { | ||
12 | + //var Id int64 | ||
13 | + //return | ||
14 | + BeforeEach(func() { | ||
15 | + //_, err := pG.DB.QueryOne( | ||
16 | + // pg.Scan(&Id), | ||
17 | + // "INSERT INTO s () VALUES () RETURNING _id", | ||
18 | + //) | ||
19 | + //Expect(err).NotTo(HaveOccurred()) | ||
20 | + }) | ||
21 | + Describe("用户按公司登录", func() { | ||
22 | + Context("", func() { | ||
23 | + It("", func() { | ||
24 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
25 | + body := map[string]interface{}{ | ||
26 | + "authCode": domain.SignToken(1, 1000), | ||
27 | + } | ||
28 | + httpExpect.POST("/auths/accessToken"). | ||
29 | + WithJSON(body). | ||
30 | + Expect(). | ||
31 | + Status(http.StatusOK). | ||
32 | + JSON(). | ||
33 | + Object(). | ||
34 | + ContainsKey("code").ValueEqual("code", 0). | ||
35 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
36 | + ContainsKey("data").Value("data").Object() | ||
37 | + }) | ||
38 | + }) | ||
39 | + }) | ||
40 | + AfterEach(func() { | ||
41 | + //_, err := pG.DB.Exec("DELETE FROM s WHERE true") | ||
42 | + //Expect(err).NotTo(HaveOccurred()) | ||
43 | + }) | ||
44 | +}) |
1 | +package auth | ||
2 | + | ||
3 | +import ( | ||
4 | + "net/http" | ||
5 | + "net/http/httptest" | ||
6 | + "testing" | ||
7 | + | ||
8 | + "github.com/beego/beego/v2/server/web" | ||
9 | + . "github.com/onsi/ginkgo" | ||
10 | + . "github.com/onsi/gomega" | ||
11 | + _ "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/infrastructure/gateway" | ||
12 | + _ "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/infrastructure/pg" | ||
13 | + _ "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/port/beego" | ||
14 | +) | ||
15 | + | ||
16 | +func TestAuth(t *testing.T) { | ||
17 | + RegisterFailHandler(Fail) | ||
18 | + RunSpecs(t, "Beego Port Auth Correlations Test Case Suite") | ||
19 | +} | ||
20 | + | ||
21 | +var handler http.Handler | ||
22 | +var server *httptest.Server | ||
23 | + | ||
24 | +var _ = BeforeSuite(func() { | ||
25 | + handler = web.BeeApp.Handlers | ||
26 | + server = httptest.NewServer(handler) | ||
27 | +}) | ||
28 | + | ||
29 | +var _ = AfterSuite(func() { | ||
30 | + server.Close() | ||
31 | +}) |
1 | +package auth | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/go-pg/pg/v10" | ||
5 | + "net/http" | ||
6 | + | ||
7 | + "github.com/gavv/httpexpect" | ||
8 | + . "github.com/onsi/ginkgo" | ||
9 | + . "github.com/onsi/gomega" | ||
10 | + pG "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/infrastructure/pg" | ||
11 | +) | ||
12 | + | ||
13 | +var _ = Describe("修改手机号密码", func() { | ||
14 | + var Id int64 | ||
15 | + BeforeEach(func() { | ||
16 | + _, err := pG.DB.QueryOne( | ||
17 | + pg.Scan(&Id), | ||
18 | + `INSERT INTO user_auth (user_auth_id,users,phone_auth) VALUES (1,ARRAY [1],'{"phone":"18800000001","password":"password"}') RETURNING user_auth_id`, | ||
19 | + ) | ||
20 | + Expect(err).NotTo(HaveOccurred()) | ||
21 | + }) | ||
22 | + Describe("修改手机号密码", func() { | ||
23 | + Context("", func() { | ||
24 | + It("", func() { | ||
25 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
26 | + body := map[string]interface{}{ | ||
27 | + "oldPwd": "password", | ||
28 | + "newPwd": "newPassword", | ||
29 | + "confirmPwd": "newPassword", | ||
30 | + "phone": "18800000001", | ||
31 | + } | ||
32 | + httpExpect.POST("/auths/changePhonePassword"). | ||
33 | + WithJSON(body). | ||
34 | + Expect(). | ||
35 | + Status(http.StatusOK). | ||
36 | + JSON(). | ||
37 | + Object(). | ||
38 | + ContainsKey("code").ValueEqual("code", 0). | ||
39 | + ContainsKey("msg").ValueEqual("msg", "ok") | ||
40 | + //ContainsKey("data").Value("data").Object() | ||
41 | + }) | ||
42 | + }) | ||
43 | + }) | ||
44 | + AfterEach(func() { | ||
45 | + _, err := pG.DB.Exec("DELETE FROM user_auth WHERE true") | ||
46 | + Expect(err).NotTo(HaveOccurred()) | ||
47 | + }) | ||
48 | +}) |
1 | +package auth | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/go-pg/pg/v10" | ||
5 | + "net/http" | ||
6 | + | ||
7 | + "github.com/gavv/httpexpect" | ||
8 | + . "github.com/onsi/ginkgo" | ||
9 | + . "github.com/onsi/gomega" | ||
10 | + pG "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/infrastructure/pg" | ||
11 | +) | ||
12 | + | ||
13 | +var _ = Describe("用户按公司登录", func() { | ||
14 | + var Id int64 | ||
15 | + BeforeEach(func() { | ||
16 | + _, err := pG.DB.QueryOne( | ||
17 | + pg.Scan(&Id), | ||
18 | + "INSERT INTO users (user_id,user_type,company_id) VALUES (1,1,1000) RETURNING user_id", | ||
19 | + ) | ||
20 | + _, err = pG.DB.QueryOne( | ||
21 | + pg.Scan(&Id), | ||
22 | + `INSERT INTO companys (company_id,company_info) VALUES (1000,'{"company_id":1000,"name":"company","status":1}') RETURNING company_id`, | ||
23 | + ) | ||
24 | + _, err = pG.DB.QueryOne( | ||
25 | + pg.Scan(&Id), | ||
26 | + `INSERT INTO user_auth (user_auth_id,users,phone_auth) VALUES (1,ARRAY [1],'{"phone":"18800000001","password":"password"}') RETURNING user_auth_id`, | ||
27 | + ) | ||
28 | + Expect(err).NotTo(HaveOccurred()) | ||
29 | + }) | ||
30 | + Describe("用户按公司登录", func() { | ||
31 | + Context("", func() { | ||
32 | + It("", func() { | ||
33 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
34 | + body := map[string]interface{}{ | ||
35 | + "userType": 1, | ||
36 | + "credentials": "string", | ||
37 | + "userId": 1, | ||
38 | + } | ||
39 | + httpExpect.POST("/auths/loginByCompany"). | ||
40 | + WithJSON(body). | ||
41 | + Expect(). | ||
42 | + Status(http.StatusOK). | ||
43 | + JSON(). | ||
44 | + Object(). | ||
45 | + ContainsKey("code").ValueEqual("code", 0). | ||
46 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
47 | + ContainsKey("data").Value("data").Object() | ||
48 | + }) | ||
49 | + }) | ||
50 | + }) | ||
51 | + AfterEach(func() { | ||
52 | + _, err := pG.DB.Exec("DELETE FROM users WHERE true") | ||
53 | + _, err = pG.DB.Exec("DELETE FROM companys WHERE true") | ||
54 | + _, err = pG.DB.Exec("DELETE FROM user_auth WHERE true") | ||
55 | + Expect(err).NotTo(HaveOccurred()) | ||
56 | + }) | ||
57 | +}) |
test/integration/beego/auth/login_test.go
0 → 100644
1 | +package auth | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/go-pg/pg/v10" | ||
5 | + "net/http" | ||
6 | + | ||
7 | + "github.com/gavv/httpexpect" | ||
8 | + . "github.com/onsi/ginkgo" | ||
9 | + . "github.com/onsi/gomega" | ||
10 | + pG "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/infrastructure/pg" | ||
11 | +) | ||
12 | + | ||
13 | +var _ = Describe("用户登录 返回有权限的公司列表", func() { | ||
14 | + var Id int64 | ||
15 | + BeforeEach(func() { | ||
16 | + _, err := pG.DB.QueryOne( | ||
17 | + pg.Scan(&Id), | ||
18 | + "INSERT INTO users (user_id,user_type,company_id) VALUES (1,1,1000) RETURNING user_id", | ||
19 | + ) | ||
20 | + _, err = pG.DB.QueryOne( | ||
21 | + pg.Scan(&Id), | ||
22 | + `INSERT INTO companys (company_id,company_info) VALUES (1000,'{"company_id":1000,"name":"company"}') RETURNING company_id`, | ||
23 | + ) | ||
24 | + _, err = pG.DB.QueryOne( | ||
25 | + pg.Scan(&Id), | ||
26 | + `INSERT INTO user_auth (user_auth_id,users,phone_auth) VALUES (1,ARRAY [1],'{"phone":"18800000001","password":"password"}') RETURNING user_auth_id`, | ||
27 | + ) | ||
28 | + Expect(err).NotTo(HaveOccurred()) | ||
29 | + }) | ||
30 | + Describe("用户登录 返回有权限的公司列表", func() { | ||
31 | + Context("", func() { | ||
32 | + It("", func() { | ||
33 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
34 | + body := map[string]interface{}{ | ||
35 | + "phone": "18800000001", | ||
36 | + "grantType": "signInPassword", | ||
37 | + "password": "password", | ||
38 | + "captcha": "", | ||
39 | + "credentials": "", | ||
40 | + } | ||
41 | + httpExpect.POST("/auths/login"). | ||
42 | + WithJSON(body). | ||
43 | + Expect(). | ||
44 | + Status(http.StatusOK). | ||
45 | + JSON(). | ||
46 | + Object(). | ||
47 | + ContainsKey("code").ValueEqual("code", 0). | ||
48 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
49 | + ContainsKey("data").Value("data").Object() | ||
50 | + }) | ||
51 | + }) | ||
52 | + }) | ||
53 | + AfterEach(func() { | ||
54 | + _, err := pG.DB.Exec("DELETE FROM users WHERE true") | ||
55 | + _, err = pG.DB.Exec("DELETE FROM companys WHERE true") | ||
56 | + _, err = pG.DB.Exec("DELETE FROM user_auth WHERE true") | ||
57 | + Expect(err).NotTo(HaveOccurred()) | ||
58 | + }) | ||
59 | +}) |
1 | +package auth | ||
2 | + | ||
3 | +import ( | ||
4 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/domain" | ||
5 | + "net/http" | ||
6 | + | ||
7 | + "github.com/gavv/httpexpect" | ||
8 | + . "github.com/onsi/ginkgo" | ||
9 | +) | ||
10 | + | ||
11 | +var _ = Describe("更新授权令牌accessToken", func() { | ||
12 | + //return | ||
13 | + //var Id int64 | ||
14 | + BeforeEach(func() { | ||
15 | + //_, err := pG.DB.QueryOne( | ||
16 | + // pg.Scan(&Id), | ||
17 | + // "INSERT INTO s () VALUES () RETURNING _id", | ||
18 | + //) | ||
19 | + //Expect(err).NotTo(HaveOccurred()) | ||
20 | + }) | ||
21 | + Describe("更新授权令牌accessToken", func() { | ||
22 | + Context("", func() { | ||
23 | + It("", func() { | ||
24 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
25 | + body := map[string]interface{}{ | ||
26 | + "refreshToken": domain.SignToken(1, 1000), | ||
27 | + } | ||
28 | + httpExpect.POST("/auths/refreshToken"). | ||
29 | + WithJSON(body). | ||
30 | + Expect(). | ||
31 | + Status(http.StatusOK). | ||
32 | + JSON(). | ||
33 | + Object(). | ||
34 | + ContainsKey("code").ValueEqual("code", 0). | ||
35 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
36 | + ContainsKey("data").Value("data").Object() | ||
37 | + }) | ||
38 | + }) | ||
39 | + }) | ||
40 | + AfterEach(func() { | ||
41 | + //_, err := pG.DB.Exec("DELETE FROM s WHERE true") | ||
42 | + //Expect(err).NotTo(HaveOccurred()) | ||
43 | + }) | ||
44 | +}) |
test/integration/beego/auth/revoke_test.go
0 → 100644
1 | +package auth | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/go-pg/pg/v10" | ||
5 | + "net/http" | ||
6 | + | ||
7 | + "github.com/gavv/httpexpect" | ||
8 | + . "github.com/onsi/ginkgo" | ||
9 | + . "github.com/onsi/gomega" | ||
10 | + pG "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/infrastructure/pg" | ||
11 | +) | ||
12 | + | ||
13 | +var _ = Describe("注销登录", func() { | ||
14 | + return | ||
15 | + var Id int64 | ||
16 | + BeforeEach(func() { | ||
17 | + _, err := pG.DB.QueryOne( | ||
18 | + pg.Scan(&Id), | ||
19 | + "INSERT INTO s () VALUES () RETURNING _id", | ||
20 | + ) | ||
21 | + Expect(err).NotTo(HaveOccurred()) | ||
22 | + }) | ||
23 | + Describe("注销登录", func() { | ||
24 | + Context("", func() { | ||
25 | + It("", func() { | ||
26 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
27 | + body := map[string]interface{}{} | ||
28 | + httpExpect.POST("/auths/revoke"). | ||
29 | + WithJSON(body). | ||
30 | + Expect(). | ||
31 | + Status(http.StatusOK). | ||
32 | + JSON(). | ||
33 | + Object(). | ||
34 | + ContainsKey("code").ValueEqual("code", 0). | ||
35 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
36 | + ContainsKey("data").Value("data").Object() | ||
37 | + }) | ||
38 | + }) | ||
39 | + }) | ||
40 | + AfterEach(func() { | ||
41 | + _, err := pG.DB.Exec("DELETE FROM s WHERE true") | ||
42 | + Expect(err).NotTo(HaveOccurred()) | ||
43 | + }) | ||
44 | +}) |
1 | +package auth | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/go-pg/pg/v10" | ||
5 | + "net/http" | ||
6 | + | ||
7 | + "github.com/gavv/httpexpect" | ||
8 | + . "github.com/onsi/ginkgo" | ||
9 | + . "github.com/onsi/gomega" | ||
10 | + pG "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/infrastructure/pg" | ||
11 | +) | ||
12 | + | ||
13 | +var _ = Describe("发送验证码", func() { | ||
14 | + return | ||
15 | + var Id int64 | ||
16 | + BeforeEach(func() { | ||
17 | + _, err := pG.DB.QueryOne( | ||
18 | + pg.Scan(&Id), | ||
19 | + "INSERT INTO s () VALUES () RETURNING _id", | ||
20 | + ) | ||
21 | + Expect(err).NotTo(HaveOccurred()) | ||
22 | + }) | ||
23 | + Describe("发送验证码", func() { | ||
24 | + Context("", func() { | ||
25 | + It("", func() { | ||
26 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
27 | + body := map[string]interface{}{ | ||
28 | + "phone": "string", | ||
29 | + } | ||
30 | + httpExpect.POST("/auths/sendSmsCode"). | ||
31 | + WithJSON(body). | ||
32 | + Expect(). | ||
33 | + Status(http.StatusOK). | ||
34 | + JSON(). | ||
35 | + Object(). | ||
36 | + ContainsKey("code").ValueEqual("code", 0). | ||
37 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
38 | + ContainsKey("data").Value("data").Object() | ||
39 | + }) | ||
40 | + }) | ||
41 | + }) | ||
42 | + AfterEach(func() { | ||
43 | + _, err := pG.DB.Exec("DELETE FROM s WHERE true") | ||
44 | + Expect(err).NotTo(HaveOccurred()) | ||
45 | + }) | ||
46 | +}) |
1 | +package order | ||
2 | + | ||
3 | +import ( | ||
4 | + "net/http" | ||
5 | + | ||
6 | + "github.com/gavv/httpexpect" | ||
7 | + . "github.com/onsi/ginkgo" | ||
8 | + . "github.com/onsi/gomega" | ||
9 | + pG "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/infrastructure/pg" | ||
10 | +) | ||
11 | + | ||
12 | +var _ = FDescribe("创建订单增删改查", func() { | ||
13 | + Describe("提交数据创建订单增删改查", func() { | ||
14 | + Context("提交正确的新订单实体数据", func() { | ||
15 | + It("返回订单实体数据", func() { | ||
16 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
17 | + body := map[string]interface{}{ | ||
18 | + "orderNo": "string", | ||
19 | + "companyId": "int64", | ||
20 | + "buyerName": "string", | ||
21 | + "contactInfo": "string", | ||
22 | + "shippingAddress": "string", | ||
23 | + "orderNum": "int64", | ||
24 | + "totalPrice": "float64", | ||
25 | + } | ||
26 | + httpExpect.POST("/orders/"). | ||
27 | + WithJSON(body). | ||
28 | + Expect(). | ||
29 | + Status(http.StatusOK). | ||
30 | + JSON(). | ||
31 | + Object(). | ||
32 | + ContainsKey("code").ValueEqual("code", 0). | ||
33 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
34 | + ContainsKey("data").Value("data").Object(). | ||
35 | + ContainsKey("orderId").ValueNotEqual("orderId", BeZero()) | ||
36 | + }) | ||
37 | + }) | ||
38 | + }) | ||
39 | + AfterEach(func() { | ||
40 | + _, err := pG.DB.Exec("DELETE FROM orders WHERE true") | ||
41 | + Expect(err).NotTo(HaveOccurred()) | ||
42 | + }) | ||
43 | +}) |
1 | +package order | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/go-pg/pg/v10" | ||
5 | + "net/http" | ||
6 | + | ||
7 | + "github.com/gavv/httpexpect" | ||
8 | + . "github.com/onsi/ginkgo" | ||
9 | + . "github.com/onsi/gomega" | ||
10 | + pG "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/infrastructure/pg" | ||
11 | +) | ||
12 | + | ||
13 | +var _ = Describe("返回订单增删改查", func() { | ||
14 | + var orderId int64 | ||
15 | + BeforeEach(func() { | ||
16 | + _, err := pG.DB.QueryOne( | ||
17 | + pg.Scan(&orderId), | ||
18 | + "INSERT INTO orders (order_id, buyer, company_id, partner_id, delivery_code, is_disable, order_no, order_detail, order_dividend, order_dividend_status, order_goods, order_source, order_type, order_status, total_price, region_info, remarks, create_at, update_at, delete_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING order_id", | ||
19 | + "testOrderId", "testBuyer", "testCompanyId", "testPartnerId", "testDeliveryCode", "testIsDisable", "testOrderNo", "testOrderDetail", "testOrderDividend", "testOrderDividendStatus", "testOrderGoods", "testOrderSource", "testOrderType", "testOrderStatus", "testTotalPrice", "testRegionInfo", "testRemarks", "testCreateAt", "testUpdateAt", "testDeleteAt") | ||
20 | + Expect(err).NotTo(HaveOccurred()) | ||
21 | + }) | ||
22 | + Describe("根据orderId参数返回订单实体", func() { | ||
23 | + Context("传入有效的orderId", func() { | ||
24 | + It("返回订单实体数据", func() { | ||
25 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
26 | + httpExpect.GET("/orders/{orderId}"). | ||
27 | + Expect(). | ||
28 | + Status(http.StatusOK). | ||
29 | + JSON(). | ||
30 | + Object(). | ||
31 | + ContainsKey("code").ValueEqual("code", 0). | ||
32 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
33 | + ContainsKey("data").Value("data").Object() | ||
34 | + }) | ||
35 | + }) | ||
36 | + }) | ||
37 | + AfterEach(func() { | ||
38 | + _, err := pG.DB.Exec("DELETE FROM orders WHERE true") | ||
39 | + Expect(err).NotTo(HaveOccurred()) | ||
40 | + }) | ||
41 | +}) |
1 | +package order | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/go-pg/pg/v10" | ||
5 | + "net/http" | ||
6 | + | ||
7 | + "github.com/gavv/httpexpect" | ||
8 | + . "github.com/onsi/ginkgo" | ||
9 | + . "github.com/onsi/gomega" | ||
10 | + pG "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/infrastructure/pg" | ||
11 | +) | ||
12 | + | ||
13 | +var _ = Describe("返回订单增删改查列表", func() { | ||
14 | + var orderId int64 | ||
15 | + BeforeEach(func() { | ||
16 | + _, err := pG.DB.QueryOne( | ||
17 | + pg.Scan(&orderId), | ||
18 | + "INSERT INTO orders (order_id, buyer, company_id, partner_id, delivery_code, is_disable, order_no, order_detail, order_dividend, order_dividend_status, order_goods, order_source, order_type, order_status, total_price, region_info, remarks, create_at, update_at, delete_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING order_id", | ||
19 | + "testOrderId", "testBuyer", "testCompanyId", "testPartnerId", "testDeliveryCode", "testIsDisable", "testOrderNo", "testOrderDetail", "testOrderDividend", "testOrderDividendStatus", "testOrderGoods", "testOrderSource", "testOrderType", "testOrderStatus", "testTotalPrice", "testRegionInfo", "testRemarks", "testCreateAt", "testUpdateAt", "testDeleteAt") | ||
20 | + Expect(err).NotTo(HaveOccurred()) | ||
21 | + }) | ||
22 | + Describe("根据参数返回订单实体列表", func() { | ||
23 | + Context("传入有效的参数", func() { | ||
24 | + It("返回订单实体数据列表", func() { | ||
25 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
26 | + httpExpect.GET("/orders/"). | ||
27 | + WithQuery("offset", "int"). | ||
28 | + WithQuery("limit", "int"). | ||
29 | + Expect(). | ||
30 | + Status(http.StatusOK). | ||
31 | + JSON(). | ||
32 | + Object(). | ||
33 | + ContainsKey("code").ValueEqual("code", 0). | ||
34 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
35 | + ContainsKey("data").Value("data").Object(). | ||
36 | + ContainsKey("count").ValueEqual("count", 1). | ||
37 | + ContainsKey("orders").Value("orders").Array() | ||
38 | + }) | ||
39 | + }) | ||
40 | + }) | ||
41 | + AfterEach(func() { | ||
42 | + _, err := pG.DB.Exec("DELETE FROM orders WHERE true") | ||
43 | + Expect(err).NotTo(HaveOccurred()) | ||
44 | + }) | ||
45 | +}) |
1 | +package order | ||
2 | + | ||
3 | +import ( | ||
4 | + "net/http" | ||
5 | + "net/http/httptest" | ||
6 | + "testing" | ||
7 | + | ||
8 | + "github.com/beego/beego/v2/server/web" | ||
9 | + . "github.com/onsi/ginkgo" | ||
10 | + . "github.com/onsi/gomega" | ||
11 | + _ "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/infrastructure/pg" | ||
12 | + _ "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/port/beego" | ||
13 | +) | ||
14 | + | ||
15 | +func TestOrder(t *testing.T) { | ||
16 | + RegisterFailHandler(Fail) | ||
17 | + RunSpecs(t, "Beego Port Order Correlations Test Case Suite") | ||
18 | +} | ||
19 | + | ||
20 | +var handler http.Handler | ||
21 | +var server *httptest.Server | ||
22 | + | ||
23 | +var _ = BeforeSuite(func() { | ||
24 | + handler = web.BeeApp.Handlers | ||
25 | + server = httptest.NewServer(handler) | ||
26 | +}) | ||
27 | + | ||
28 | +var _ = AfterSuite(func() { | ||
29 | + server.Close() | ||
30 | +}) |
1 | +package order | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/go-pg/pg/v10" | ||
5 | + "net/http" | ||
6 | + | ||
7 | + "github.com/gavv/httpexpect" | ||
8 | + . "github.com/onsi/ginkgo" | ||
9 | + . "github.com/onsi/gomega" | ||
10 | + pG "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/infrastructure/pg" | ||
11 | +) | ||
12 | + | ||
13 | +var _ = Describe("移除订单增删改查", func() { | ||
14 | + var orderId int64 | ||
15 | + BeforeEach(func() { | ||
16 | + _, err := pG.DB.QueryOne( | ||
17 | + pg.Scan(&orderId), | ||
18 | + "INSERT INTO orders (order_id, buyer, company_id, partner_id, delivery_code, is_disable, order_no, order_detail, order_dividend, order_dividend_status, order_goods, order_source, order_type, order_status, total_price, region_info, remarks, create_at, update_at, delete_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING order_id", | ||
19 | + "testOrderId", "testBuyer", "testCompanyId", "testPartnerId", "testDeliveryCode", "testIsDisable", "testOrderNo", "testOrderDetail", "testOrderDividend", "testOrderDividendStatus", "testOrderGoods", "testOrderSource", "testOrderType", "testOrderStatus", "testTotalPrice", "testRegionInfo", "testRemarks", "testCreateAt", "testUpdateAt", "testDeleteAt") | ||
20 | + Expect(err).NotTo(HaveOccurred()) | ||
21 | + }) | ||
22 | + Describe("根据参数移除订单增删改查", func() { | ||
23 | + Context("传入有效的orderId", func() { | ||
24 | + It("返回被移除订单实体的数据", func() { | ||
25 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
26 | + httpExpect.DELETE("/orders/{orderId}"). | ||
27 | + Expect(). | ||
28 | + Status(http.StatusOK). | ||
29 | + JSON(). | ||
30 | + Object(). | ||
31 | + ContainsKey("code").ValueEqual("code", 0). | ||
32 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
33 | + ContainsKey("data").Value("data").Object() | ||
34 | + }) | ||
35 | + }) | ||
36 | + }) | ||
37 | + AfterEach(func() { | ||
38 | + _, err := pG.DB.Exec("DELETE FROM orders WHERE true") | ||
39 | + Expect(err).NotTo(HaveOccurred()) | ||
40 | + }) | ||
41 | +}) |
1 | +package order | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/go-pg/pg/v10" | ||
5 | + "net/http" | ||
6 | + | ||
7 | + "github.com/gavv/httpexpect" | ||
8 | + . "github.com/onsi/ginkgo" | ||
9 | + . "github.com/onsi/gomega" | ||
10 | + pG "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/infrastructure/pg" | ||
11 | +) | ||
12 | + | ||
13 | +var _ = Describe("更新订单增删改查", func() { | ||
14 | + var orderId int64 | ||
15 | + BeforeEach(func() { | ||
16 | + _, err := pG.DB.QueryOne( | ||
17 | + pg.Scan(&orderId), | ||
18 | + "INSERT INTO orders (order_id, buyer, company_id, partner_id, delivery_code, is_disable, order_no, order_detail, order_dividend, order_dividend_status, order_goods, order_source, order_type, order_status, total_price, region_info, remarks, create_at, update_at, delete_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING order_id", | ||
19 | + "testOrderId", "testBuyer", "testCompanyId", "testPartnerId", "testDeliveryCode", "testIsDisable", "testOrderNo", "testOrderDetail", "testOrderDividend", "testOrderDividendStatus", "testOrderGoods", "testOrderSource", "testOrderType", "testOrderStatus", "testTotalPrice", "testRegionInfo", "testRemarks", "testCreateAt", "testUpdateAt", "testDeleteAt") | ||
20 | + Expect(err).NotTo(HaveOccurred()) | ||
21 | + }) | ||
22 | + Describe("提交数据更新订单增删改查", func() { | ||
23 | + Context("提交正确的订单实体数据", func() { | ||
24 | + It("返回更新后的订单实体数据", func() { | ||
25 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
26 | + body := map[string]interface{}{} | ||
27 | + httpExpect.PUT("/orders/{orderId}"). | ||
28 | + WithJSON(body). | ||
29 | + Expect(). | ||
30 | + Status(http.StatusOK). | ||
31 | + JSON(). | ||
32 | + Object(). | ||
33 | + ContainsKey("code").ValueEqual("code", 0). | ||
34 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
35 | + ContainsKey("data").Value("data").Object(). | ||
36 | + ContainsKey("orderId").ValueEqual("orderId", orderId) | ||
37 | + }) | ||
38 | + }) | ||
39 | + }) | ||
40 | + AfterEach(func() { | ||
41 | + _, err := pG.DB.Exec("DELETE FROM orders WHERE true") | ||
42 | + Expect(err).NotTo(HaveOccurred()) | ||
43 | + }) | ||
44 | +}) |
1 | +package partner | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/go-pg/pg/v10" | ||
5 | + "net/http" | ||
6 | + | ||
7 | + "github.com/gavv/httpexpect" | ||
8 | + . "github.com/onsi/ginkgo" | ||
9 | + . "github.com/onsi/gomega" | ||
10 | + pG "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/infrastructure/pg" | ||
11 | +) | ||
12 | + | ||
13 | +var _ = Describe("合伙人分类列表", func() { | ||
14 | + var id int64 | ||
15 | + BeforeEach(func() { | ||
16 | + _, err := pG.DB.QueryOne( | ||
17 | + pg.Scan(&id), | ||
18 | + "INSERT INTO partner_category (partner_category_id,partner_category_code,partner_category_name) VALUES (?,?,?) RETURNING partner_category_id", | ||
19 | + 1000, "testPartnerCategoryCode", "testPartnerCategoryName") | ||
20 | + Expect(err).NotTo(HaveOccurred()) | ||
21 | + }) | ||
22 | + Describe("合伙人分类列表", func() { | ||
23 | + Context("", func() { | ||
24 | + It("", func() { | ||
25 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
26 | + httpExpect.GET("/partners/categories"). | ||
27 | + Expect(). | ||
28 | + Status(http.StatusOK). | ||
29 | + JSON(). | ||
30 | + Object(). | ||
31 | + ContainsKey("code").ValueEqual("code", 0). | ||
32 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
33 | + ContainsKey("data").Value("data").Object() | ||
34 | + }) | ||
35 | + }) | ||
36 | + }) | ||
37 | + AfterEach(func() { | ||
38 | + _, err := pG.DB.Exec("DELETE FROM partner_category WHERE partner_category_id = 1000") | ||
39 | + Expect(err).NotTo(HaveOccurred()) | ||
40 | + }) | ||
41 | +}) |
1 | +package partner | ||
2 | + | ||
3 | +import ( | ||
4 | + "net/http" | ||
5 | + "net/http/httptest" | ||
6 | + "testing" | ||
7 | + | ||
8 | + "github.com/beego/beego/v2/server/web" | ||
9 | + . "github.com/onsi/ginkgo" | ||
10 | + . "github.com/onsi/gomega" | ||
11 | + _ "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/infrastructure/pg" | ||
12 | + _ "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/port/beego" | ||
13 | +) | ||
14 | + | ||
15 | +func TestPartner(t *testing.T) { | ||
16 | + RegisterFailHandler(Fail) | ||
17 | + RunSpecs(t, "Beego Port Partner Correlations Test Case Suite") | ||
18 | +} | ||
19 | + | ||
20 | +var handler http.Handler | ||
21 | +var server *httptest.Server | ||
22 | + | ||
23 | +var _ = BeforeSuite(func() { | ||
24 | + handler = web.BeeApp.Handlers | ||
25 | + server = httptest.NewServer(handler) | ||
26 | +}) | ||
27 | + | ||
28 | +var _ = AfterSuite(func() { | ||
29 | + server.Close() | ||
30 | +}) |
1 | +package permission | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/go-pg/pg/v10" | ||
5 | + "net/http" | ||
6 | + | ||
7 | + "github.com/gavv/httpexpect" | ||
8 | + . "github.com/onsi/ginkgo" | ||
9 | + . "github.com/onsi/gomega" | ||
10 | + pG "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/infrastructure/pg" | ||
11 | +) | ||
12 | + | ||
13 | +var _ = Describe("根据当前用户返回权限列表", func() { | ||
14 | + var permissionId int64 | ||
15 | + BeforeEach(func() { | ||
16 | + _, err := pG.DB.QueryOne( | ||
17 | + pg.Scan(&permissionId), | ||
18 | + "INSERT INTO permissions (permission_id,name,code,parent_id,sort,icon) VALUES (?,?,?,?,?,?) RETURNING permission_id", | ||
19 | + 1000, "testPermission", "testPermissionCode", 0, 1, "testPermissionIcon") | ||
20 | + Expect(err).NotTo(HaveOccurred()) | ||
21 | + }) | ||
22 | + Describe("根据当前用户返回权限列表", func() { | ||
23 | + Context("", func() { | ||
24 | + It("", func() { | ||
25 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
26 | + httpExpect.GET("/permission/menus"). | ||
27 | + Expect(). | ||
28 | + Status(http.StatusOK). | ||
29 | + JSON(). | ||
30 | + Object(). | ||
31 | + ContainsKey("code").ValueEqual("code", 0). | ||
32 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
33 | + ContainsKey("data").Value("data").Object().ValueNotEqual("total", 0) | ||
34 | + }) | ||
35 | + }) | ||
36 | + }) | ||
37 | + AfterEach(func() { | ||
38 | + _, err := pG.DB.Exec("DELETE FROM permissions WHERE permission_id = 1000") | ||
39 | + Expect(err).NotTo(HaveOccurred()) | ||
40 | + }) | ||
41 | +}) |
1 | +package permission | ||
2 | + | ||
3 | +import ( | ||
4 | + "net/http" | ||
5 | + "net/http/httptest" | ||
6 | + "testing" | ||
7 | + | ||
8 | + "github.com/beego/beego/v2/server/web" | ||
9 | + . "github.com/onsi/ginkgo" | ||
10 | + . "github.com/onsi/gomega" | ||
11 | + _ "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/infrastructure/pg" | ||
12 | + _ "gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/port/beego" | ||
13 | +) | ||
14 | + | ||
15 | +func TestPermission(t *testing.T) { | ||
16 | + RegisterFailHandler(Fail) | ||
17 | + RunSpecs(t, "Beego Port Permission Correlations Test Case Suite") | ||
18 | +} | ||
19 | + | ||
20 | +var handler http.Handler | ||
21 | +var server *httptest.Server | ||
22 | + | ||
23 | +var _ = BeforeSuite(func() { | ||
24 | + handler = web.BeeApp.Handlers | ||
25 | + server = httptest.NewServer(handler) | ||
26 | +}) | ||
27 | + | ||
28 | +var _ = AfterSuite(func() { | ||
29 | + server.Close() | ||
30 | +}) |
-
请 注册 或 登录 后发表评论