作者 陈志颖

fix:解决冲突

正在显示 86 个修改的文件 包含 3155 行增加258 行删除

要显示太多修改。

为保证性能只显示 86 of 86+ 个文件。

... ... @@ -12,5 +12,5 @@ ENV GO111MODULE on
ENV GOPROXY https://goproxy.cn
# RUN ["go","mod","tidy"]
RUN ["go","build","-mod=vendor"]
EXPOSE 8082
EXPOSE 8082 443
ENTRYPOINT ["./partnermg"]
\ No newline at end of file
... ...
# 服务端工作交接事项
## 合伙人管理后台项目
# 合伙人管理后台项目
### 代码以及文档
## 代码以及文档
- [代码地址](http://gitlab.fjmaimaimai.com/mmm-go/partnermg.git)
- [项目原型svn](svn://218.106.157.184/repo/项目文件/项目【合伙人】)
- [yapi-合伙人前端](http://47.97.5.102:36666/project/209/interface/api)
... ... @@ -15,7 +14,10 @@
服务端测试环境地址:http://mmm-partnermg-test.fjmaimaimai.com
服务端正式环境地址:https://public-interface.fjmaimaimai.com/mmm-partnermg
```
### 项目整体
## 系统架构图
![diagram](http://gitlab.fjmaimaimai.com/chenzhiying/img-folder/raw/master/diagram.png)
## 项目整体
- 项目使用框架
- http框架:beego
- orm框架:go-pg
... ... @@ -57,7 +59,56 @@
│ └─consumer kafka消息订阅
└─vendor
```
### 系统对接的外部数据
## 领域驱动设计-战略建模
### 领域
### 限界上下文
### 上下文映射
## 领域驱动设计-战术建模
### 实体
实发订单实体:OrderBase
栏目设置实体:ColumnSetting
合伙人实体:Partner
用户实体:User
公司实体:Company
管理员实体:AdminUser
### 值对象
### 聚合根
### 领域服务
### 领域事件
## 领域驱动设计工程实现
### 模块
### 领域对象
### 资源库
### 防腐层
### 领域服务
### 数据流转
![avatar](http://gitlab.fjmaimaimai.com/chenzhiying/img-folder/raw/master/dto.png)
### 上下文集成
### 分离领域
![avatar](http://gitlab.fjmaimaimai.com/chenzhiying/img-folder/raw/master/dispatch.png)
## 系统对接的外部数据
1. 外部数据来源,接收企业平台发送过来的数据。目前接收的是公司和员工的数据
主要内容在文件夹
... ... @@ -78,11 +129,43 @@
主要内容在
partnermg/pkg/infrastructure/serviceGateway
### 系统入口
## 系统入口
- [测试环境--企业平台网站地址](https://enterprise-platform-dev.fjmaimaimai.com)
- [开发环境--企业平台网站地址](https://enterprise-platform-local.fjmaimaimai.com)
- 天联共创后台自身没有独立的登录入口,需要经过企业平台进行跳转登录
## 标准产品组工具使用
- 设置全局变量(替换YOUR-USER-PATH为你真实的项目路径)
1.生成路径(项目生成路径):/YOUR-USER-PATH/GolandProjects/
2.eggs根目录路径(领域描述语言DSL文档路径生成或引用路径):/YOUR-USER-PATH/GolandProjects/partnermg/document/
3.egg名称(通常为项目名称,同样是DSL文件夹名称):partnermg
- 应用描述语言生成
1.应用描述语言egg脚手架生成
2.生成属性(Attribute)
3.生成模式(Schema)
4.生成服务(Service)
5.生成接口(Api)
- 具体工程生成
1.生成接口文档(OpenApi)
2.生成项目代码脚手架
3.生成领域模型
4.生成应用服务
5.生成Http协议接口
## 建议
1. vendor 目前作用是存放依赖,加快在容器中的构建速度。
... ...
appname = partnermg
runmode = "${RUN_MODE||dev}"
httpport = "${HTTP_PORT||8082}"
EnableHTTPS = true
HTTPSPort = "443"
HTTPSCertFile = "conf/fjmaimaimai.com_pem.crt"
HTTPSKeyFile = "conf/fjmaimaimai.com_rsa.key"
#开启监控
EnableAdmin = false
#开启JSON请求
... ... @@ -10,6 +13,7 @@ copyrequestbody = true
enablexsrf = false
xsrfkey = asdfioerjlasdfmFADFOEJF2323SDFF
xsrfexpire = 3600
#是否将错误信息进行渲染
EnableErrorsRender =false
[lang]
... ...
-----BEGIN CERTIFICATE-----
MIIGWjCCBUKgAwIBAgIQBKNf6ftifrIH+BeJ7V4uqjANBgkqhkiG9w0BAQsFADBf
MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3
d3cuZGlnaWNlcnQuY29tMR4wHAYDVQQDExVHZW9UcnVzdCBDTiBSU0EgQ0EgRzEw
HhcNMjEwMTA2MDAwMDAwWhcNMjIwMjA2MjM1OTU5WjCBgzELMAkGA1UEBhMCQ04x
EjAQBgNVBAgMCeemj+W7uuecgTESMBAGA1UEBwwJ56aP5bee5biCMTAwLgYDVQQK
DCfnpo/lu7rkubDkubDkubDkv6Hmga/np5HmioDmnInpmZDlhazlj7gxGjAYBgNV
BAMMESouZmptYWltYWltYWkuY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB
CgKCAQEAv1KDwfoVuXyMSNUvLapWLpyWdQd8Dy4l5Wmdiydof4+ijqCfgPgMOZGS
7ucvis1ZUZLYDKbZq8xODVEWlXf/n6sMXkq0B+eltlYqyPOZyaBUkg2qqz/iKljb
1pGE5q7gfQ5nQoEW8J/DZUlKs+7jg9O0y2S0jVj3s7QlFy6Alw9BE/7ChOxqfegN
Ua0UL8W6rFqK32eyvZUeecvtKoZwJ3YD2ayXJIN70OivjkcWLskmf6+CjalitqQs
JZ7xD6/WtrpunTCpOVNqhR81sCOT+xxDwNppDqiMNo3lFL6TeQSWT19RBllkiWdW
XXfWS7CsIrqp8i/7fjt66VmVqZnPDwIDAQABo4IC6zCCAucwHwYDVR0jBBgwFoAU
kZ9eMRWuEJ+tYMH3wcyqSDQvDCYwHQYDVR0OBBYEFEhZyphSt/IUiLKJLr78T+7j
l7tmMC0GA1UdEQQmMCSCESouZmptYWltYWltYWkuY29tgg9mam1haW1haW1haS5j
b20wDgYDVR0PAQH/BAQDAgWgMB0GA1UdJQQWMBQGCCsGAQUFBwMBBggrBgEFBQcD
AjB1BgNVHR8EbjBsMDSgMqAwhi5odHRwOi8vY3JsMy5kaWdpY2VydC5jb20vR2Vv
VHJ1c3RDTlJTQUNBRzEuY3JsMDSgMqAwhi5odHRwOi8vY3JsNC5kaWdpY2VydC5j
b20vR2VvVHJ1c3RDTlJTQUNBRzEuY3JsMEsGA1UdIAREMEIwNgYJYIZIAYb9bAEB
MCkwJwYIKwYBBQUHAgEWG2h0dHA6Ly93d3cuZGlnaWNlcnQuY29tL0NQUzAIBgZn
gQwBAgIwbwYIKwYBBQUHAQEEYzBhMCEGCCsGAQUFBzABhhVodHRwOi8vb2NzcC5k
Y29jc3AuY24wPAYIKwYBBQUHMAKGMGh0dHA6Ly9jcmwuZGlnaWNlcnQtY24uY29t
L0dlb1RydXN0Q05SU0FDQUcxLmNydDAMBgNVHRMBAf8EAjAAMIIBAgYKKwYBBAHW
eQIEAgSB8wSB8ADuAHUAKXm+8J45OSHwVnOfY6V35b5XfZxgCvj5TV0mXCVdx4QA
AAF21tCFyQAABAMARjBEAiAPHS8Wp3c0J7d5By9NQM3/tyf7/B0H7JZLJ+IlcoCG
IwIgR1+Mj5Q6nhWdqV5s9WLgSUvhpJJxvFrJOzV6zkfXZEwAdQAiRUUHWVUkVpY/
oS/x922G4CMmY63AS39dxoNcbuIPAgAAAXbW0IYsAAAEAwBGMEQCIBbGUD0dLyIT
O+KzBtFPQjiRUbcjGZsbY0gWmVzZfBPrAiAa2X20smzJK42hcMenaVrUgxC/y/j0
bYYfKRrfwEsoWDANBgkqhkiG9w0BAQsFAAOCAQEAU4aHqNW/qgzRUwBv3C9E70r/
/LMy3asBePsBARZlzd3tXrr446lsX3HKmAH4AtLACjwPv3ejsEJueeQxrwMxalW+
2ZerAJhzYqD0OovwcB2b6cDB5zWAuyllFo6ILI3KSQjzFmi4Vn993pN2b2OEUkwC
REYvMVf2BzHjVFuCiXtUWgOucsCb4ES+yWjCrw93VafyhhGCbXVXd55GNbZFE+kw
JArAwYPKwabuFYFfeSVWcRvaV+Kbo88ytPo5ZpShSOBFCPQ1JQ/BxWEmzHXQIzcz
uqELYfxmxI3q6plbgHtL1rY2B8YTWcxXF98fIfg5OKYssOV4LGcoOWPf0PUPrg==
-----END CERTIFICATE-----
... ...
-----BEGIN RSA PRIVATE KEY-----
MIIEpQIBAAKCAQEAv1KDwfoVuXyMSNUvLapWLpyWdQd8Dy4l5Wmdiydof4+ijqCf
gPgMOZGS7ucvis1ZUZLYDKbZq8xODVEWlXf/n6sMXkq0B+eltlYqyPOZyaBUkg2q
qz/iKljb1pGE5q7gfQ5nQoEW8J/DZUlKs+7jg9O0y2S0jVj3s7QlFy6Alw9BE/7C
hOxqfegNUa0UL8W6rFqK32eyvZUeecvtKoZwJ3YD2ayXJIN70OivjkcWLskmf6+C
jalitqQsJZ7xD6/WtrpunTCpOVNqhR81sCOT+xxDwNppDqiMNo3lFL6TeQSWT19R
BllkiWdWXXfWS7CsIrqp8i/7fjt66VmVqZnPDwIDAQABAoIBAHN3mF980Jm2ym+2
ghe8YvEUvlV5I+2Be4uel1+BdDbweDo+RKWwjqg77ILU8kOCNbLevhe8p0hhMIYm
90tUNemmcPuDeG4A52lJTd8j7h/a7M+NAgECuDu4j01LW/thdcjj5XwkrrSgp2u8
tSItPhC0t7u9Vp6sICrLwUrhXOhNV+qdm94VhabJFGkdR9iUYw7W7w54Z1p+Nfw8
PJdDJfwu0lr8DFB2Zw+Ota8Xg+PX71x4mWS1g+h/6xz2ivptFcKPcwd60EjB+ROi
IQC8pnUmbF0H0epoVisB3SWEMzuShmAZrckBW+0ILDUUmNzcZxcWrmzIpomCdkOv
Trtrd/ECgYEA6v37SfsSKohPncHIYfV3FE7Xt7WH09TFymAY8FXIY+K6xvX9wtWB
h+3quFWuh0VTp15m6xAF1UN6HOG0uRKwUGFqwYBy4I+88KCUO3BJzbWn2TOjt4xE
8KVwGmZafqxPjwLagCN3RBLNYF4S+jhygBIlSzHkuVkwZPGbVet7NWkCgYEA0G0b
uDPJl37gEfvhMebdTWUq+FuAVx7h7UjZQM6BNoE3cDdZHUY7pMTqqD2UDbp6O6dC
0b8Hhs8kx90DewdixSzli67jNVeTRFY3DZ85Ac/BmGyuusNm6Uwbsz4RYsyUSrRD
bukC/L1vFjB5k/UgGh0kKnBT74mO/kqASWUIebcCgYEAiShtP6UX2VNuhPnSZ7rK
IkRSjJucB/ws5g5o//5R1FtGAVMbJllQHXK0iZsZH0NLrGjhUVoszWlxIOJshYlu
97ukgATlCEVdVmWjn33O1g6tRY1qhXuN0Zf+cqpDL6SLW0GjHx+UQVtoHFNMaFgC
HNZ6hgU9JyHzqTeMHv4vD+ECgYEAhk2oTPvh7OLuk+gQZk1zUMnd9IdRndHilzoX
9DCdBnghNwgTPk/hYv0YkCyN2ILO/N18qxdDTFTySG9cLMzHknKpv2aENf0mgiRj
+T0eSNKM1yFBPktnZvGJ7+gQ3+8fpzudMDyplh6jFFNMJFERzIH2qfoTvAiRwb5U
B/c4jOUCgYEAiQOXabnrnOvkfhl/RhH/WVeLs6O3c5yei0THysGc+9CqE8txnWPN
A4XI8Tu8G2ScBN+v9oPFWlLAZxbxh1m6RM6VwP4q+Y8fmdQ+d6gH/IKTdBjH7bOt
4SHS+t8Z6PSu8K1BsF3pGRS7OWPlivSJzRyP2YIgE/xtwsEqiODdRKM=
-----END RSA PRIVATE KEY-----
... ...
... ... @@ -10,6 +10,9 @@ spec:
- name: "http"
port: 80
targetPort: 8082
- name: "https"
port: 443
targetPort: 443
selector:
k8s-app: mmm-partnermg
---
... ... @@ -48,10 +51,13 @@ spec:
imagePullPolicy: Always
ports:
- containerPort: 8082
volumeMounts:
- mountPath: /opt/logs
name: accesslogs
- containerPort: 443
# volumeMounts:
# - mountPath: /opt/logs
# name: accesslogs
env:
- name: HTTP_PORT
value: "8082"
- name: POSTGRESQL_DB_NAME
value: "partner_dev"
- name: POSTGRESQL_USER
... ... @@ -86,6 +92,8 @@ spec:
value: "dev"
- name: Log_PREFIX
value: "[partnermg_dev]"
volumes:
- name: accesslogs
emptyDir: {}
- name: APP_NAME
value: ""
# volumes:
# - name: accesslogs
# emptyDir: {}
... ...
... ... @@ -10,6 +10,9 @@ spec:
- name: "http"
port: 80
targetPort: 8082
- name: "https"
port: 443
targetPort: 443
selector:
k8s-app: mmm-partnermg
---
... ... @@ -45,10 +48,13 @@ spec:
imagePullPolicy: Always
ports:
- containerPort: 8082
- containerPort: 443
volumeMounts:
- mountPath: /opt/logs
name: accesslogs
env:
- name: HTTP_PORT
value: "8082"
- name: POSTGRESQL_DB_NAME
value: "partner"
- name: POSTGRESQL_USER
... ... @@ -83,6 +89,8 @@ spec:
value: "dev"
- name: Log_PREFIX
value: "[partnermg_prd]"
- name: APP_NAME
value: "mmm-partnermg"
volumes:
- name: accesslogs
emptyDir: {}
... ...
... ... @@ -10,6 +10,9 @@ spec:
- name: "http"
port: 80
targetPort: 8082
- name: "https"
port: 443
targetPort: 443
selector:
k8s-app: mmm-partnermg
---
... ... @@ -45,10 +48,13 @@ spec:
imagePullPolicy: Always
ports:
- containerPort: 8082
volumeMounts:
- mountPath: /opt/logs
name: accesslogs
- containerPort: 443
# volumeMounts:
# - mountPath: /opt/logs
# name: accesslogs
env:
- name: HTTP_PORT
value: "8082"
- name: POSTGRESQL_DB_NAME
value: "partner_test"
- name: POSTGRESQL_USER
... ... @@ -83,6 +89,8 @@ spec:
value: "dev"
- name: Log_PREFIX
value: "[partnermg_test]"
volumes:
- name: accesslogs
emptyDir: {}
- name: APP_NAME
value: "partnermg"
# volumes:
# - name: accesslogs
# emptyDir: {}
... ...
swagger: "2.0"
info:
title: ""
description: 合伙人后管平台
contact:
name: SteveChan
email: steve.d.chan@qq.com
home: ""
version: 0.0.1
consumes:
- application/json
- application/xml
produces:
- application/json
- application/xml
paths:
/column-settings:
get:
tags:
- column_setting
summary: 返回栏目设置增删改查列表
description: 返回栏目设置增删改查列表
operationId: column_setting#listColumnSetting
parameters:
- name: offset
in: query
description: 查询偏离量
required: false
type: integer
- name: limit
in: query
description: 查询限制
required: false
type: integer
responses:
"200":
description: OK response.
schema:
$ref: '#/definitions/ColumnSettingListColumnSettingResponseBody'
schemes:
- http
post:
tags:
- column_setting
summary: 重置栏目设置
description: 重置栏目设置
operationId: column_setting#resetColumn
responses:
"200":
description: OK response.
schema:
$ref: '#/definitions/ColumnSettingResetColumnResponseBody'
schemes:
- http
/column-settings/{columnSettingId}:
get:
tags:
- column_setting
summary: 返回栏目设置增删改查
description: 返回栏目设置增删改查
operationId: column_setting#getColumnSetting
parameters:
- name: columnSettingId
in: path
description: 栏目设置id
required: true
type: integer
responses:
"200":
description: OK response.
schema:
$ref: '#/definitions/ColumnSettingGetColumnSettingResponseBody'
schemes:
- http
put:
tags:
- column_setting
summary: 更新栏目设置增删改查
description: 更新栏目设置增删改查
operationId: column_setting#updateColumnSetting
parameters:
- name: columnSettingId
in: path
description: 栏目设置id
required: true
type: integer
responses:
"200":
description: OK response.
schema:
$ref: '#/definitions/ColumnSettingUpdateColumnSettingResponseBody'
schemes:
- http
delete:
tags:
- column_setting
summary: 移除栏目设置增删改查
description: 移除栏目设置增删改查
operationId: column_setting#removeColumnSetting
parameters:
- name: columnSettingId
in: path
description: 栏目设置id
required: true
type: integer
responses:
"200":
description: OK response.
schema:
$ref: '#/definitions/ColumnSettingRemoveColumnSettingResponseBody'
schemes:
- http
definitions:
ColumnSettingCreateColumnSettingRequestBody:
title: ColumnSettingCreateColumnSettingRequestBody
type: object
properties:
description:
type: string
description: 栏目设置描述
required:
- description
userName:
type: string
description: 栏目设置关联用户名称
required:
- userName
ColumnSettingCreateColumnSettingResponseBody:
title: 'Mediatype identifier: ColumnSettingCreateColumnSettingResponseBody'
type: object
properties:
column_setting:
$ref: '#/definitions/column_settingResponseBody'
ColumnSettingGetColumnSettingResponseBody:
title: 'Mediatype identifier: ColumnSettingGetColumnSettingResponseBody'
type: object
properties:
column_setting:
$ref: '#/definitions/column_settingResponseBody'
ColumnSettingListColumnSettingResponseBody:
title: 'Mediatype identifier: ColumnSettingListColumnSettingResponseBody'
type: object
properties:
column_setting:
$ref: '#/definitions/column_settingResponseBody'
count:
type: integer
description: 匹配数目
required:
- count
ColumnSettingRemoveColumnSettingResponseBody:
title: 'Mediatype identifier: ColumnSettingRemoveColumnSettingResponseBody'
type: object
properties:
column_setting:
$ref: '#/definitions/column_settingResponseBody'
ColumnSettingResetColumnResponseBody:
title: 'Mediatype identifier: ColumnSettingResetColumnResponseBody'
type: object
properties:
column_setting:
$ref: '#/definitions/column_settingResponseBody'
ColumnSettingUpdateColumnSettingResponseBody:
title: 'Mediatype identifier: ColumnSettingUpdateColumnSettingResponseBody'
type: object
properties:
column_setting:
$ref: '#/definitions/column_settingResponseBody'
column_settingResponseBody:
title: column_settingResponseBody
type: object
properties:
columnSettingId:
type: integer
description: 栏目设置id
required:
- columnSettingId
companyId:
type: integer
description: 栏目设置关联用户公司id
required:
- companyId
createdAt:
type: string
description: 栏目设置创建时间
required:
- createdAt
description:
type: string
description: 栏目设置描述
required:
- description
key:
type: string
description: 栏目设置模块名称
required:
- key
uid:
type: integer
description: 栏目设置关联用户uid
required:
- uid
updatedAt:
type: string
description: 栏目设置更新时间
required:
- updatedAt
userName:
type: string
description: 栏目设置关联用户名称
required:
- userName
value:
type: array
items:
$ref: '#/definitions/columnResponseBody'
description: 栏目数组
description: 栏目设置
columnResponseBody:
title: columnResponseBody
type: object
properties:
columnId:
type: string
description: 列标记
required:
- columnId
paramCn:
type: string
description: 列标记中文
required:
- paramCn
paramFix:
type: integer
description: 列标记是否固定,1:固定,2:不固定
required:
- paramFix
description: 栏目项
... ...
version: v1
kind: HttpApi
metadata:
service: column_setting
path: /column-settings
endpoints:
- method: createColumnSetting
route:
post: /
- method: updateColumnSetting
route:
put: /{columnSettingId}
- method: getColumnSetting
route:
get: /{columnSettingId}
- method: removeColumnSetting
route:
delete: /{columnSettingId}
- method: resetColumn
route:
post: /
- method: listColumnSetting
route:
get: /
params:
- name: offset
- name: limit
... ...
version: v1
kind: Attribute
metadata:
name: columnId
description: 列标记
type:
primitive: string
... ...
version: v1
kind: Attribute
metadata:
name: paramCn
description: 列标记中文
type:
primitive: string
... ...
version: v1
kind: Attribute
metadata:
name: paramFix
description: 列标记是否固定,1:固定,2:不固定
type:
primitive: int
... ...
version: v1
kind: Attribute
metadata:
name: columnSettingId
description: 栏目设置id
type:
primitive: int64
... ...
version: v1
kind: Attribute
metadata:
name: companyId
description: 栏目设置关联用户公司id
type:
primitive: int32
... ...
version: v1
kind: Attribute
metadata:
name: createdAt
description: 栏目设置创建时间
type:
primitive: datetime
... ...
version: v1
kind: Attribute
metadata:
name: description
description: 栏目设置描述
type:
primitive: string
... ...
version: v1
kind: Attribute
metadata:
name: invalidValue
description: 无效的栏目数组
type:
array: column
... ...
version: v1
kind: Attribute
metadata:
name: key
description: 栏目设置模块名称
type:
primitive: string
... ...
version: v1
kind: Attribute
metadata:
name: uid
description: 栏目设置关联用户uid
type:
primitive: int64
... ...
version: v1
kind: Attribute
metadata:
name: updatedAt
description: 栏目设置更新时间
type:
primitive: datetime
... ...
version: v1
kind: Attribute
metadata:
name: userName
description: 栏目设置关联用户名称
type:
primitive: string
\ No newline at end of file
... ...
version: v1
kind: Attribute
metadata:
name: value
description: 栏目值对象数组
type:
array: column
... ...
version: v1
kind: Attribute
metadata:
name: count
description: 匹配数目
type:
primitive: int64
... ...
version: v1
kind: Attribute
metadata:
name: limit
description: 查询限制
type:
primitive: int
... ...
version: v1
kind: Attribute
metadata:
name: offset
description: 查询偏离量
type:
primitive: int
... ...
version: v1
kind: Project
metadata:
name: project
description: 合伙人后管平台
version: 0.0.1
repository: gitlab.fjmaimaimai.com/mmm-go/partnermg
contact:
name: SteveChan
email: steve.d.chan@qq.com
\ No newline at end of file
... ...
version: v1
kind: Schema
metadata:
name: column
description: 栏目项
attributes:
- ref: columnId
required: true
- ref: paramCn
required: true
- ref: paramFix
required: true
\ No newline at end of file
... ...
version: v1
kind: Schema
metadata:
name: column_setting
description: 栏目设置
attributes:
- ref: columnSettingId
required: true
- ref: companyId
required: true
- ref: createdAt
required: true
- ref: description
required: true
- ref: key
required: true
- ref: uid
required: true
- ref: updatedAt
required: true
- ref: userName
required: true
- name: value
description: 栏目数组
type:
array: column
- name: invalidValue
description: 无效栏目数组
type:
array: column
... ...
version: v1
kind: Method
metadata:
name: createColumnSetting
type: command
description: 创建栏目设置增删改查
payload:
- ref: description
required: true
- ref: userName
required: true
result:
- name: column_setting
type:
schema: column_setting
... ...
version: v1
kind: Method
metadata:
name: getColumnSetting
type: query
description: 返回栏目设置增删改查
payload:
- ref: columnSettingId
required: true
result:
- name: column_setting
type:
schema: column_setting
... ...
version: v1
kind: Method
metadata:
name: listColumnSetting
type: query
description: 返回栏目设置增删改查列表
payload:
- ref: offset
required: true
- ref: limit
required: true
result:
- ref: count
required: true
- name: column_setting
type:
schema: column_setting
... ...
version: v1
kind: Method
metadata:
name: removeColumnSetting
type: command
description: 移除栏目设置增删改查
payload:
- ref: columnSettingId
required: true
result:
- name: column_setting
type:
schema: column_setting
... ...
version: v1
kind: Method
metadata:
name: resetColumn
type: command
description: 重置栏目设置
result:
- name: column_setting
type:
schema: column_setting
... ...
version: v1
kind: Method
metadata:
name: updateColumnSetting
type: command
description: 更新栏目设置增删改查
payload:
- ref: columnSettingId
required: true
result:
- name: column_setting
type:
schema: column_setting
... ...
version: v1
kind: Service
metadata:
name: column_setting
description: 栏目设置
... ...
... ... @@ -13,17 +13,17 @@ require (
github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072 // indirect
github.com/fatih/structs v1.1.0 // indirect
github.com/gavv/httpexpect v2.0.0+incompatible
github.com/go-pg/pg v8.0.6+incompatible
github.com/go-pg/pg/v10 v10.7.3
github.com/google/go-querystring v1.0.0 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/imkira/go-interpol v1.1.0 // indirect
github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88 // indirect
github.com/linmadan/egglib-go v0.0.0-20191217144343-ca4539f95bf9
github.com/linmadan/egglib-go v0.0.0-20201125083542-25358a549edb
github.com/mattn/go-colorable v0.1.6 // indirect
github.com/moul/http2curl v1.0.0 // indirect
github.com/onsi/ginkgo v1.14.2
github.com/onsi/gomega v1.10.3
github.com/sclevine/agouti v3.0.0+incompatible // indirect
github.com/sergi/go-diff v1.1.0 // indirect
github.com/shopspring/decimal v1.2.0
github.com/smartystreets/goconvey v1.6.4 // indirect
... ...
package command
import (
"fmt"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
"github.com/astaxie/beego/validation"
)
type CreateColumnSettingCommand struct {
// 公司id
CompanyId int `json:"companyId"`
// 用户uid
Uid int64 `json:"uid"`
// 栏目设置描述
Description string `json:"description"`
// 栏目设置关联用户名称
UserName string `json:"userName"`
// 默认栏目设置
Value []domain.Column `json:"value"`
// 无效栏目设置爱
InvalidValue []domain.Column `json:"invalidValue"`
// 模块键值
Key string `json:"key"`
}
//func (createColumnSettingCommand *CreateColumnSettingCommand) Valid(validation *validation.Validation) {
// _ = validation.SetError("CustomValid", "未实现的自定义认证")
//}
func (createColumnSettingCommand *CreateColumnSettingCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(createColumnSettingCommand)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package command
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type RemoveColumnSettingCommand struct {
// 栏目设置id
ColumnSettingId int64 `json:"columnSettingId"`
// 用户uid
Uid int64 `json:"uid"`
// 公司id
CompanyId int `json:"companyId"`
}
//func (removeColumnSettingCommand *RemoveColumnSettingCommand) Valid(validation *validation.Validation) {
// validation.SetError("CustomValid", "未实现的自定义认证")
//}
func (removeColumnSettingCommand *RemoveColumnSettingCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(removeColumnSettingCommand)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package command
import (
"fmt"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
"github.com/astaxie/beego/validation"
)
type ResetColumnCommand struct {
// 公司id
CompanyId int `json:"companyId"`
// 用户uid
Uid int64 `json:"uid"`
// 默认栏目
Value []domain.Column `json:"value"`
// 默认无效栏目
InvalidValue []domain.Column `json:"invalidValue"`
}
//func (resetColumnCommand *ResetColumnCommand) Valid(validation *validation.Validation) {
// _ = validation.SetError("CustomValid", "未实现的自定义认证")
//}
func (resetColumnCommand *ResetColumnCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(resetColumnCommand)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package command
import (
"fmt"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
"github.com/astaxie/beego/validation"
)
type UpdateColumnSettingCommand struct {
// 栏目设置id
ColumnSettingId int64 `json:"columnSettingId"`
// 公司id
CompanyId int `json:"companyId"`
// 用户uid
Uid int64 `json:"uid"`
// 选中的栏目
Selected []domain.Column `json:"selected"`
// 未选中的栏目
UnSelected []domain.Column `json:"unselected"`
// 栏目设置
Value []domain.Column `json:"value"`
// 无效栏目设置
InvalidValue []domain.Column `json:"invalidValue"`
// 栏目
OrderBaseColumns OrderBaseColumns `json:"orderBaseColumns"`
}
type OrderBaseColumns struct {
// 选中的栏目
Selected []domain.Column `json:"selected"`
// 未选中的栏目
UnSelected []domain.Column `json:"unselected"`
}
//func (updateColumnSettingCommand *UpdateColumnSettingCommand) Valid(validation *validation.Validation) {
// _ = validation.SetError("CustomValid", "未实现的自定义认证")
//}
func (updateColumnSettingCommand *UpdateColumnSettingCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(updateColumnSettingCommand)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package query
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type GetColumnSettingQuery struct {
// 栏目设置id
ColumnSettingId int64 `json:"columnSettingId"`
// 公司id
CompanyId int `json:"companyId"`
// 用户uid
Uid int64 `json:"uid"`
}
//func (getColumnSettingQuery *GetColumnSettingQuery) Valid(validation *validation.Validation) {
// _ = validation.SetError("CustomValid", "未实现的自定义认证")
//}
func (getColumnSettingQuery *GetColumnSettingQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(getColumnSettingQuery)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package query
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type ListColumnSettingQuery struct {
// 查询偏离量
Offset int `json:"offset" valid:"Required"`
// 查询限制
Limit int `json:"limit" valid:"Required"`
}
//func (listColumnSettingQuery *ListColumnSettingQuery) Valid(validation *validation.Validation) {
// _ = validation.SetError("CustomValid", "未实现的自定义认证")
//}
func (listColumnSettingQuery *ListColumnSettingQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(listColumnSettingQuery)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package service
import (
"fmt"
"github.com/linmadan/egglib-go/core/application"
"github.com/linmadan/egglib-go/utils/tool_funs"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/columnSetting/command"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/columnSetting/query"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/factory"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/constant"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
"strconv"
"time"
)
// 栏目设置
type ColumnSettingService struct {
}
/**
* @Author SteveChan
* @Description //新增用户时,初始化栏目设置
* @Date 23:13 2021/1/26
* @Param
* @return
**/
func (columnSettingService *ColumnSettingService) CreateColumnSetting(createColumnSettingCommand *command.CreateColumnSettingCommand) (interface{}, error) {
if err := createColumnSettingCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if errStart := transactionContext.StartTransaction(); errStart != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, errStart.Error())
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
newColumnSetting := &domain.ColumnSetting{
Description: createColumnSettingCommand.Description,
UserName: createColumnSettingCommand.UserName,
CompanyId: createColumnSettingCommand.CompanyId,
Uid: createColumnSettingCommand.Uid,
Key: constant.ORDER_BASE, // 订单栏目模块名称
Value: domain.DefaultColumns, // 栏目值数组,创建用户时使用默认栏目设置
InvalidValue: domain.DefaultInvalidColumns, // 初始化无效栏目数组
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
}
var columnSettingRepository domain.ColumnSettingRepository
if value, errFac := factory.CreateColumnSettingRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); errFac != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, errFac.Error())
} else {
columnSettingRepository = value
}
if columnSettingSaved, errSaved := columnSettingRepository.Save(newColumnSetting); errSaved != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, errSaved.Error())
} else {
if errCommit := transactionContext.CommitTransaction(); errCommit != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, errCommit.Error())
}
return columnSettingSaved, nil
}
}
/**
* @Author SteveChan
* @Description // 返回栏目设置
* @Date 23:14 2021/1/26
* @Param
* @return
**/
func (columnSettingService *ColumnSettingService) GetColumnSetting(getColumnSettingQuery *query.GetColumnSettingQuery) (interface{}, error) {
if err := getColumnSettingQuery.ValidateQuery(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
var columnSettingRepository domain.ColumnSettingRepository
if value, errFact := factory.CreateColumnSettingRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); errFact != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, errFact.Error())
} else {
columnSettingRepository = value
}
columnSettingFound, err := columnSettingRepository.FindOne(map[string]interface{}{"uid": getColumnSettingQuery.Uid, "companyId": getColumnSettingQuery.CompanyId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if columnSettingFound == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", strconv.FormatInt(getColumnSettingQuery.Uid, 10)))
} else {
if errCommit := transactionContext.CommitTransaction(); errCommit != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, errCommit.Error())
}
// 数据mapper
orderBaseColumns := map[string]interface{}{
"orderBaseColumns": map[string]interface{}{
"selected": columnSettingFound.Value,
"unselected": columnSettingFound.InvalidValue,
},
}
return orderBaseColumns, nil
}
}
// 返回栏目设置增删改查列表
func (columnSettingService *ColumnSettingService) ListColumnSetting(listColumnSettingQuery *query.ListColumnSettingQuery) (interface{}, error) {
if err := listColumnSettingQuery.ValidateQuery(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var columnSettingRepository domain.ColumnSettingRepository
if value, err := factory.CreateColumnSettingRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
columnSettingRepository = value
}
if count, columnSettings, err := columnSettingRepository.Find(domain.ColumnSettingFindQuery{
Offset: listColumnSettingQuery.Offset,
Limit: listColumnSettingQuery.Limit,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return map[string]interface{}{
"count": count,
"column_settings": columnSettings,
}, nil
}
}
/**
* @Author SteveChan
* @Description // 删除用户时移除栏目设置
* @Date 23:14 2021/1/26
* @Param
* @return
**/
func (columnSettingService *ColumnSettingService) RemoveColumnSetting(removeColumnSettingCommand *command.RemoveColumnSettingCommand) (interface{}, error) {
if err := removeColumnSettingCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if errSt := transactionContext.StartTransaction(); errSt != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, errSt.Error())
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
var columnSettingRepository domain.ColumnSettingRepository
if value, errFac := factory.CreateColumnSettingRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); errFac != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, errFac.Error())
} else {
columnSettingRepository = value
}
columnSettingFound, err := columnSettingRepository.FindOne(map[string]interface{}{"uid": removeColumnSettingCommand.Uid, "companyId": removeColumnSettingCommand.CompanyId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if columnSettingFound == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", strconv.FormatInt(removeColumnSettingCommand.Uid, 10)))
}
if columnSettingRemoved, _, errRm := columnSettingRepository.Remove(columnSettingFound, nil); errRm != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, errRm.Error())
} else {
if errTr := transactionContext.CommitTransaction(); errTr != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, errRm.Error())
}
// 数据mapper
orderBaseColumns := map[string]interface{}{
"orderBaseColumns": map[string]interface{}{
"selected": columnSettingRemoved.Value,
"unselected": columnSettingRemoved.InvalidValue,
},
}
return orderBaseColumns, nil
}
}
/**
* @Author SteveChan
* @Description // 重置栏目设置
* @Date 23:15 2021/1/26
* @Param
* @return
**/
func (columnSettingService *ColumnSettingService) ResetColumn(resetColumnCommand *command.ResetColumnCommand) (interface{}, error) {
if err := resetColumnCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if errStart := transactionContext.StartTransaction(); errStart != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, errStart.Error())
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
var columnSettingRepository domain.ColumnSettingRepository
if value, errFact := factory.CreateColumnSettingRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); errFact != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, errFact.Error())
} else {
columnSettingRepository = value
}
columnSettingFound, err := columnSettingRepository.FindOne(map[string]interface{}{"uid": resetColumnCommand.Uid, "companyId": resetColumnCommand.CompanyId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if columnSettingFound == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", strconv.FormatInt(resetColumnCommand.Uid, 10)))
}
if errUpdated := columnSettingFound.Update(tool_funs.SimpleStructToMap(resetColumnCommand)); errUpdated != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, errUpdated.Error())
}
if columnSettingSaved, errSaved := columnSettingRepository.Save(columnSettingFound); errSaved != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, errSaved.Error())
} else {
if errCommit := transactionContext.CommitTransaction(); errCommit != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, errCommit.Error())
}
// 数据mapper
orderBaseColumns := map[string]interface{}{
"orderBaseColumns": map[string]interface{}{
"selected": columnSettingSaved.Value,
"unselected": columnSettingSaved.InvalidValue,
},
}
return orderBaseColumns, nil
}
}
/**
* @Author SteveChan
* @Description // 更新栏目设置
* @Date 23:15 2021/1/26
* @Param
* @return
**/
func (columnSettingService *ColumnSettingService) UpdateColumnSetting(updateColumnSettingCommand *command.UpdateColumnSettingCommand) (interface{}, error) {
if err := updateColumnSettingCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if errStart := transactionContext.StartTransaction(); errStart != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, errStart.Error())
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
var columnSettingRepository domain.ColumnSettingRepository
if value, errFact := factory.CreateColumnSettingRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); errFact != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, errFact.Error())
} else {
columnSettingRepository = value
}
updateColumnSettingCommand.Value = updateColumnSettingCommand.Selected
updateColumnSettingCommand.InvalidValue = updateColumnSettingCommand.UnSelected
columnSetting, err := columnSettingRepository.FindOne(map[string]interface{}{"uid": updateColumnSettingCommand.Uid, "companyId": updateColumnSettingCommand.CompanyId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if columnSetting == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", strconv.FormatInt(updateColumnSettingCommand.Uid, 10)))
}
if errUpdated := columnSetting.Update(tool_funs.SimpleStructToMap(updateColumnSettingCommand)); errUpdated != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, errUpdated.Error())
}
if columnSettingSaved, errSaved := columnSettingRepository.Save(columnSetting); errSaved != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, errSaved.Error())
} else {
if errCommit := transactionContext.CommitTransaction(); errCommit != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, errCommit.Error())
}
// 数据mapper
orderBaseColumns := map[string]interface{}{
"orderBaseColumns": map[string]interface{}{
"selected": columnSettingSaved.Value,
"unselected": columnSettingSaved.InvalidValue,
},
}
return orderBaseColumns, nil
}
}
func NewColumnSettingService(options map[string]interface{}) *ColumnSettingService {
newColumnSettingService := &ColumnSettingService{}
return newColumnSettingService
}
... ...
... ... @@ -104,3 +104,11 @@ func CreateOrderLogRepository(options map[string]interface{}) (domain.OrderLogRe
}
return repository.NewOrderLogRepository(transactionContext)
}
func CreateColumnSettingRepository(options map[string]interface{}) (domain.ColumnSettingRepository, error) {
var transactionContext *transaction.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*transaction.TransactionContext)
}
return repository.NewColumnSettingRepository(transactionContext)
}
... ...
package command
import "errors"
import (
"errors"
"time"
)
//创建订单
type CreateOrderCommand struct {
... ... @@ -32,6 +35,8 @@ type CreateOrderCommand struct {
Code string `json:"code"`
//合伙人类型名称-错误信息返回
PartnerCategoryName string `json:"partnerCategoryName"`
//销售日期
SaleDate time.Time `json:"saleDate"`
}
func (postData *CreateOrderCommand) Valid() error {
... ...
package command
import "time"
//UpdateOrderPurposeCommand 更新订单单
type UpdateOrderCommand struct {
Id int64 `json:"id"`
... ... @@ -21,6 +23,8 @@ type UpdateOrderCommand struct {
Goods []OrderGoodData `json:"goods"`
//公司id
CompanyId int64 `json:"companyId"`
// 合伙人类型
//合伙人类型
PartnerCategory int64 `json:"partner_category"`
//销售日期
SaleDate time.Time `json:"saleDate"`
}
... ...
... ... @@ -8,7 +8,7 @@ package query
/**
* @Author SteveChan
* @Description //TODO 查询合伙人id
* @Description // 查询合伙人id
* @Date 23:18 2021/1/6
**/
type GetPartnerIdQuery struct {
... ...
... ... @@ -8,7 +8,7 @@ package query
/**
* @Author SteveChan
* @Description //TODO 查询产品id
* @Description //查询产品id
* @Date 23:18 2021/1/6
**/
type GetProductIdQuery struct {
... ...
... ... @@ -16,10 +16,14 @@ type ListOrderBaseQuery struct {
DeliveryCode string `json:"deliveryCode"`
//公司id
CompanyId int64 `json:"companyId"`
//用户uid
Uid int64 `json:"uid"`
//订单类型
OrderType int `json:"orderType"`
//合伙人分类
PartnerCategory int `json:"partnerCategory"`
//合伙人类型名称
PartnerCategoryName string `json:"partnerCategoryName"`
//更新时间开始
UpdateTimeBegin string `json:"updateTimeBegin"`
//更新时间截止
... ... @@ -28,4 +32,8 @@ type ListOrderBaseQuery struct {
CreateTimeBegin string `json:"createTimeBegin"`
//创建时间截止
CreateTimeEnd string `json:"createTimeEnd"`
//销售时间开始
SaleDateBegin string `json:"saleDateBegin"`
//销售时间结束
SaleDateEnd string `json:"sateDateEnd"`
}
... ...
/**
@author: stevechan
@date: 2021/2/2
@note:
**/
package query
type ListOrderBonusForExcelQuery struct {
Type string `json:"type"` // 操作类型 ORDER_BASE
Where BonusWhere `json:"where"` // 导出条件
IDS []int `json:"ids"` // 勾选id
}
type BonusWhere struct {
SearchWord string `json:"searchWord"`
OrderType int `json:"orderType"`
PageSize int `json:"pageSize"`
PageNumber int `json:"pageNumber"`
PartnerCategoryId int `json:"partnerCategoryId"`
CreateTime []string `json:"createTime"`
}
... ...
/**
@author: stevechan
@date: 2021/1/27
@note:
**/
package query
type ListOrderForExcelQuery struct {
Type string `json:"type"` // 操作类型 ORDER_BASE
Where Where `json:"where"` // 导出条件
IDS []int `json:"ids"` // 勾选id
}
type Where struct {
PartnerName string `json:"partnerName"` // 合伙人姓名
OrderCode string `json:"orderCode"` // 订单号
DeliveryCode string `json:"deliveryCode"` // 发货单号
PartnerCategory int `json:"partnerCategory"` // 合伙人类型
PartnerCategoryName string `json:"partnerCategoryName"` // 合伙人类型名称
UpdateTime []string `json:"updateTime"` // 更新时间
CreateTime []string `json:"createTime"` // 创建时间
SaleDate []string `json:"saleDate"` // 销售日期
}
... ...
... ... @@ -2,6 +2,9 @@ package service
import (
"fmt"
"github.com/linmadan/egglib-go/core/application"
"strconv"
"time"
"github.com/astaxie/beego/logs"
... ... @@ -62,9 +65,11 @@ func (service OrderInfoService) PageListOrderBase(listOrderQuery query.ListOrder
listOrderQuery.PartnerName, // 合伙人姓名
listOrderQuery.OrderCode, // 订单号
listOrderQuery.DeliveryCode, // 发货单号
[2]string{listOrderQuery.UpdateTimeBegin, listOrderQuery.UpdateTimeEnd},
[2]string{listOrderQuery.CreateTimeBegin, listOrderQuery.CreateTimeEnd},
[2]string{listOrderQuery.UpdateTimeBegin, listOrderQuery.UpdateTimeEnd}, // 订单创建时间
[2]string{listOrderQuery.CreateTimeBegin, listOrderQuery.CreateTimeEnd}, // 订单更新时间
[2]string{listOrderQuery.SaleDateBegin, listOrderQuery.SaleDateEnd}, // 销售日期
listOrderQuery.PartnerCategory,
listOrderQuery.PartnerCategoryName,
listOrderQuery.Limit, listOrderQuery.Offset,
)
if err != nil {
... ... @@ -94,6 +99,7 @@ func (service OrderInfoService) PageListOrderBase(listOrderQuery query.ListOrder
"index": listIndex,
"createTime": orders[i].CreateTime.Local().Format("2006-01-02 15:04:05"),
"updateTime": orders[i].UpdateTime.Local().Format("2006-01-02 15:04:05"),
"saleDate": orders[i].SaleDate.Local().Format("2006-01-02 15:04:05"),
"buyer": orders[i].Buyer.BuyerName,
"id": fmt.Sprint(orders[i].Id),
"orderId": orders[i].OrderCode,
... ... @@ -188,7 +194,13 @@ func (service OrderInfoService) GetOrderDetail(getOrderQuery query.GetOrderQuery
return order, nil
}
//CreateNewOrder 创建订单
/**
* @Author SteveChan
* @Description // 创建订单,增加销售日期
* @Date 11:57 2021/1/26
* @Param
* @return
**/
func (service OrderInfoService) CreateNewOrder(cmd command.CreateOrderCommand) (*domain.OrderBase, error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
... ... @@ -255,7 +267,8 @@ func (service OrderInfoService) CreateNewOrder(cmd command.CreateOrderCommand) (
goodMap[goodname] = 1
}
newOrder := &domain.OrderBase{
OrderType: cmd.OrderType, OrderCode: cmd.OrderCode,
OrderType: cmd.OrderType,
OrderCode: cmd.OrderCode,
DeliveryCode: cmd.DeliveryCode,
Buyer: domain.Buyer{
BuyerName: cmd.BuyerName,
... ... @@ -263,6 +276,7 @@ func (service OrderInfoService) CreateNewOrder(cmd command.CreateOrderCommand) (
RegionInfo: domain.RegionInfo{
RegionName: cmd.OrderRegion,
},
SaleDate: cmd.SaleDate,
PartnerId: cmd.PartnerId,
PartnerInfo: partnerData.Partner,
SalesmanBonusPercent: cmd.SalesmanBonusPercent,
... ... @@ -277,15 +291,15 @@ func (service OrderInfoService) CreateNewOrder(cmd command.CreateOrderCommand) (
var cmdPartnerCategoryOk bool
for _, v := range partnerData.PartnerCategoryInfos {
if v.Id == cmd.PartnerCategory {
_, categorys, err := categoryRepository.Find(domain.PartnerCategoryFindQuery{
_, categories, err := categoryRepository.Find(domain.PartnerCategoryFindQuery{
Ids: []int64{v.Id},
})
if err != nil {
e := fmt.Sprintf("获取合伙人分类数据失败:%s", err)
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
}
if len(categorys) > 0 {
newOrder.PartnerCategory = categorys[0]
if len(categories) > 0 {
newOrder.PartnerCategory = categories[0]
cmdPartnerCategoryOk = true
}
break
... ... @@ -393,6 +407,28 @@ func (service OrderInfoService) UpdateOrderData(cmd command.UpdateOrderCommand)
transactionContext.RollbackTransaction()
}()
// 获取合伙人类型
var PartnerCategoryRepository domain.PartnerCategoryRepository
if PartnerCategoryRepository, err = factory.CreatePartnerCategoryRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
var partnerCategories []domain.PartnerCategory
_, partnerCategories, err = PartnerCategoryRepository.Find(domain.PartnerCategoryFindQuery{
Ids: []int64{},
})
if err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("检索合伙人类型数据失败"))
}
partnerCategoryMap := map[int64]interface{}{}
if len(partnerCategories) > 0 {
for _, partnerCategory := range partnerCategories {
partnerCategoryMap[partnerCategory.Id] = partnerCategory.Name
}
}
// 获取合伙人数据
var PartnerInfoRepository domain.PartnerInfoRepository
if PartnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -500,6 +536,7 @@ func (service OrderInfoService) UpdateOrderData(cmd command.UpdateOrderCommand)
var cmdPartnerCategoryOk bool
for _, v := range partnerData.PartnerCategoryInfos {
if v.Id == cmd.PartnerCategory {
v.Name = partnerCategoryMap[v.Id].(string)
oldOrderData.PartnerCategory = v
cmdPartnerCategoryOk = true
}
... ... @@ -511,6 +548,7 @@ func (service OrderInfoService) UpdateOrderData(cmd command.UpdateOrderCommand)
oldOrderData.DeliveryCode = cmd.DeliveryCode
oldOrderData.Buyer.BuyerName = cmd.BuyerName
oldOrderData.RegionInfo.RegionName = cmd.OrderRegion
oldOrderData.SaleDate = cmd.SaleDate
oldOrderData.PartnerId = cmd.PartnerId
oldOrderData.PartnerInfo = partnerData.Partner
oldOrderData.SalesmanBonusPercent = cmd.SalesmanBonusPercent
... ... @@ -519,7 +557,6 @@ func (service OrderInfoService) UpdateOrderData(cmd command.UpdateOrderCommand)
if err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中合计的数值失败:%s", err))
}
err = orderBaseRepository.Save(oldOrderData)
if err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("保存订单数据失败:%s", err))
... ... @@ -883,7 +920,7 @@ func (service OrderInfoService) ListOrderBonusForExcel(listOrderQuery query.List
/**
* @Author SteveChan
* @Description // 导出订单数据
* @Description //根据栏目设置,导出订单数据
* @Date 22:05 2021/1/10
* @Param
* @return
... ... @@ -897,7 +934,7 @@ func (service OrderInfoService) ListOrderForExcel(listOrderQuery query.ListOrder
return nil, nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
_ = transactionContext.RollbackTransaction()
}()
var (
... ... @@ -916,61 +953,105 @@ func (service OrderInfoService) ListOrderForExcel(listOrderQuery query.ListOrder
listOrderQuery.DeliveryCode, // 发货单号
[2]string{listOrderQuery.UpdateTimeBegin, listOrderQuery.UpdateTimeEnd},
[2]string{listOrderQuery.CreateTimeBegin, listOrderQuery.CreateTimeEnd},
[2]string{listOrderQuery.SaleDateBegin, listOrderQuery.SaleDateEnd},
listOrderQuery.PartnerCategory,
listOrderQuery.PartnerCategoryName,
)
if err != nil {
return nil, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
// 获取栏目设置
var columnSettingRepository domain.ColumnSettingRepository
if value, errFact := factory.CreateColumnSettingRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); errFact != nil {
return nil, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
} else {
columnSettingRepository = value
}
columnSettingFound, err := columnSettingRepository.FindOne(map[string]interface{}{"uid": listOrderQuery.Uid, "companyId": listOrderQuery.CompanyId})
if err != nil {
return nil, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
if columnSettingFound == nil {
return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", strconv.FormatInt(listOrderQuery.Uid, 10)))
}
err = transactionContext.CommitTransaction()
if err != nil {
return nil, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
var resultMaps []map[string]string
for i := range ordersData {
t, _ := time.ParseInLocation("2006-01-02 15:04:05", ordersData[i].SaleDate, time.Local)
m := map[string]string{
"num": fmt.Sprint(i + 1),
"order_code": ordersData[i].OrderCode,
"delivery_code": ordersData[i].DeliveryCode,
"partner_name": ordersData[i].PartnerName,
"update_time": ordersData[i].UpdateTime,
"create_time": ordersData[i].CreateTime,
"plan_order_count": fmt.Sprint(ordersData[i].PlanOrderCount),
"use_order_count": "",
"region_name": fmt.Sprint(ordersData[i].RegionName),
"plan_order_amount": fmt.Sprintf("%10.2f", ordersData[i].PlanOrderAmount),
"use_order_amount": "",
"partner_category": ordersData[i].PartnerCategory,
"buyer_name": ordersData[i].BuyerName,
//"num": fmt.Sprint(i + 1),
//"order_code": ordersData[i].OrderCode,
//"delivery_code": ordersData[i].DeliveryCode,
//"partner_name": ordersData[i].PartnerName,
//"update_time": ordersData[i].UpdateTime,
//"create_time": ordersData[i].CreateTime,
//"sale_date": ordersData[i].SaleDate,
//"plan_order_count": fmt.Sprint(ordersData[i].PlanOrderCount),
//"use_order_count": "",
//"region_name": fmt.Sprint(ordersData[i].RegionName),
//"plan_order_amount": fmt.Sprintf("%10.2f", ordersData[i].PlanOrderAmount),
//"use_order_amount": "",
//"partner_category": ordersData[i].PartnerCategory,
//"buyer_name": ordersData[i].BuyerName,
"index": fmt.Sprint(i + 1),
"orderId": ordersData[i].OrderCode,
"shipmentsId": ordersData[i].DeliveryCode,
"partner": ordersData[i].PartnerName,
"updateTime": ordersData[i].UpdateTime,
"createTime": ordersData[i].CreateTime,
"saleDate": t.Format("2006-01-02"),
"orderNum": fmt.Sprint(ordersData[i].PlanOrderCount),
"quantityControl": "",
"orderDist": fmt.Sprint(ordersData[i].RegionName),
"orderPrice": fmt.Sprintf("%10.2f", ordersData[i].PlanOrderAmount),
"priceControl": "",
"partnerCategory": ordersData[i].PartnerCategory,
"buyer": ordersData[i].BuyerName,
}
if ordersData[i].UseOrderCount >= 0 {
m["use_order_count"] = fmt.Sprint(ordersData[i].UseOrderCount)
m["quantityControl"] = fmt.Sprint(ordersData[i].UseOrderCount)
}
if ordersData[i].UseOrderAmount >= 0 {
m["use_order_amount"] = fmt.Sprintf("%10.2f", ordersData[i].UseOrderAmount)
m["priceControl"] = fmt.Sprintf("%10.2f", ordersData[i].UseOrderAmount)
}
resultMaps = append(resultMaps, m)
}
column := [][2]string{
[2]string{"num", "序号"},
[2]string{"order_code", "订单号"},
[2]string{"delivery_code", "发货单号"},
[2]string{"create_time", "创建时间"},
[2]string{"update_time", "更新时间"},
[2]string{"plan_order_count", "订单数量"},
[2]string{"use_order_count", "数量调整"},
[2]string{"plan_order_amount", "订单金额"},
[2]string{"use_order_amount", "金额调整"},
[2]string{"region_name", "订单区域"},
[2]string{"partner_category", "合伙人类型"},
[2]string{"buyer_name", "客户"},
[2]string{"partner_name", "合伙人"},
//column := [][2]string{
// [2]string{"num", "序号"},
// [2]string{"order_code", "订单号"},
// [2]string{"delivery_code", "发货单号"},
// [2]string{"create_time", "创建时间"},
// [2]string{"update_time", "更新时间"},
// [2]string{"sale_date", "销售时间"},
// [2]string{"plan_order_count", "订单数量"},
// [2]string{"use_order_count", "数量调整"},
// [2]string{"plan_order_amount", "订单金额"},
// [2]string{"use_order_amount", "金额调整"},
// [2]string{"region_name", "订单区域"},
// [2]string{"partner_category", "合伙人类型"},
// [2]string{"buyer_name", "客户"},
// [2]string{"partner_name", "合伙人"},
//}
var column [][2]string
for _, columnValue := range columnSettingFound.Value {
column = append(column, [2]string{columnValue.Id, columnValue.ParamCn})
}
return resultMaps, column, nil
}
/**
* @Author SteveChan
* @Description //TODO 批量导入创建订单
* @Description // 批量导入创建订单,增加销售时间
* @Date 11:00 2021/1/7
* @Param
* @return
... ... @@ -1122,6 +1203,7 @@ func (service OrderInfoService) CreateNewOrderByImport(createOrderCommands []*co
PartnerInfo: partnerData.Partner,
SalesmanBonusPercent: cmd.SalesmanBonusPercent,
CompanyId: cmd.CompanyId,
SaleDate: cmd.SaleDate,
}
// 批量校验合伙人分类数据
... ...
... ... @@ -2,6 +2,7 @@ package service
import (
"fmt"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/utils"
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/factory"
... ... @@ -238,7 +239,7 @@ func (PartnerInfoService *PartnerInfoService) GetPartnerInfo(q query.GetPartnerI
/**
* @Author SteveChan
* @Description // 更新合伙人
* @Description //TODO 更新合伙人,判断合伙类型是否有业务数据
* @Date 00:07 2020/12/30
* @Param
* @return
... ... @@ -261,7 +262,9 @@ func (PartnerInfoService *PartnerInfoService) UpdatePartnerInfo(cmd *command.Upd
var (
partnerInfoRepository domain.PartnerInfoRepository
categoryRepository domain.PartnerCategoryRepository
orderBaseRepository domain.OrderBaseRepository
categories []domain.PartnerCategory
orders []domain.OrderBase
partnerInfoDao *dao.PartnerInfoDao
)
... ... @@ -283,6 +286,12 @@ func (PartnerInfoService *PartnerInfoService) UpdatePartnerInfo(cmd *command.Upd
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
if orderBaseRepository, err = factory.CreateOrderBaseRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
// 获取合伙人类型
var categoryMap = make(map[int64]string)
_, categories, err = categoryRepository.Find(domain.PartnerCategoryFindQuery{
... ... @@ -349,6 +358,34 @@ func (PartnerInfoService *PartnerInfoService) UpdatePartnerInfo(cmd *command.Upd
return lib.ThrowError(lib.BUSINESS_ERROR, "异常操作")
}
partnerCategoryInfos := partnerInfo.PartnerCategoryInfos
//判断相应合伙类型下是否有订单数据
var notInPartnerCategoryInfos []int64
var categoryIdsQuery []int64
var categoryIdsCmd []int64
for _, partnerCategory := range partnerCategoryInfos {
categoryIdsQuery = append(categoryIdsQuery, partnerCategory.Id)
}
for _, category := range categories {
categoryIdsCmd = append(categoryIdsCmd, category.Id)
}
for _, v := range categoryIdsQuery {
if !utils.IsContainInt(categoryIdsCmd, v) {
notInPartnerCategoryInfos = append(notInPartnerCategoryInfos, v)
}
}
if len(notInPartnerCategoryInfos) > 0 {
orders, _, err = orderBaseRepository.Find(domain.OrderBaseFindQuery{
PartnerId: cmd.Id,
CompanyId: cmd.CompanyId,
PartnerCategoryIds: notInPartnerCategoryInfos,
})
if len(orders) > 0 {
return lib.ThrowError(lib.BUSINESS_ERROR, "该合伙类型下有业务数据,不可删除!")
}
}
partnerInfo.Partner.PartnerName = cmd.PartnerName
partnerInfo.Salesman = cmd.Salesman
partnerInfo.Status = cmd.Status
... ... @@ -372,7 +409,7 @@ func (PartnerInfoService *PartnerInfoService) UpdatePartnerInfo(cmd *command.Upd
// e := fmt.Sprintf("更新业务分红(partner_id=%d)数据失败:%s", partnerInfo.Partner.Id, err)
// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
// }
transactionContext.CommitTransaction()
_ = transactionContext.CommitTransaction()
return
}
... ...
... ... @@ -85,6 +85,13 @@ func (s SyncOrderService) SyncOrderFromBestshop(cmd command.CreateOrderFromBests
return err
}
/**
* @Author SteveChan
* @Description //同步小程序订单,增加销售时间
* @Date 23:53 2021/1/26
* @Param
* @return
**/
func (s SyncOrderService) CreateOrderFromBestshop(cmd command.CreateOrderFromBestshop) error {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
... ... @@ -258,6 +265,8 @@ func (s SyncOrderService) copyOrderBestshopToOrderBase(orderBestshop *domain.Ord
// 默认设定为事业合伙人订单
orderbase.PartnerCategory = domain.PartnerCategory{Id: 1, Name: "事业合伙人"}
orderbase.Compute()
// 销售日期
//orderbase.SaleDate = orderBestshop.CreateTime
err = orderBaseRepository.Save(&orderbase)
if err != nil {
e := fmt.Sprintf("添加order_base数据失败%s", err)
... ...
... ... @@ -4,6 +4,7 @@ import (
"encoding/json"
"errors"
"fmt"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/constant"
"time"
"github.com/astaxie/beego/logs"
... ... @@ -99,8 +100,9 @@ func (service SyncCompanyService) addCompany(data CompanytData) error {
transactionContext.RollbackTransaction()
}()
var (
companyRespository domain.CompanyRepository
userRespository domain.UsersRepository
companyRespository domain.CompanyRepository
userRespository domain.UsersRepository
columnSettingRepository domain.ColumnSettingRepository
)
if companyRespository, err = factory.CreateCompanyRepository(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -112,6 +114,11 @@ func (service SyncCompanyService) addCompany(data CompanytData) error {
}); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
if columnSettingRepository, err = factory.CreateColumnSettingRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
applets := []domain.CompanyApplets{}
for _, v := range data.Company.Applets {
app := domain.CompanyApplets{
... ... @@ -163,6 +170,21 @@ func (service SyncCompanyService) addCompany(data CompanytData) error {
if err != nil {
return fmt.Errorf("添加用户数据失败,%s", err)
}
// 初始化栏目设置
newColumnSetting := &domain.ColumnSetting{
Description: "订单管理栏目设置",
UserName: data.User.Name,
CompanyId: int(data.User.CompanyId),
Uid: data.User.Id,
Key: constant.ORDER_BASE, // 订单栏目模块名称
Value: domain.DefaultColumns, // 栏目值数组,创建用户时使用默认栏目设置
InvalidValue: domain.DefaultInvalidColumns, // 初始化无效栏目数组
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
}
if _, err = columnSettingRepository.Save(newColumnSetting); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
err = transactionContext.CommitTransaction()
return nil
}
... ... @@ -199,13 +221,22 @@ func (service SyncCompanyService) updateCompany(data CompanytData) error {
oldCompany, err = companyRespository.FindOne(domain.CompanyFindOneOptions{
Id: data.Company.Id,
})
if err != nil {
return fmt.Errorf("获取公司数据失败,%s", err)
}
_, oldCompanyAdmins, err = userRespository.Find(domain.UsersFindQuery{
CompanyId: data.Company.Id,
AdminType: domain.UserIsAdmin,
})
if err != nil {
return fmt.Errorf("获取公司admin数据失败,%s", err)
}
newUser, err = userRespository.FindOne(domain.UsersFindOneQuery{
Id: data.User.Id,
})
if err != nil {
return fmt.Errorf("获取用户数据失败,%s,data.user.id=%d", err, data.User.Id)
}
applets := []domain.CompanyApplets{}
for _, v := range data.Company.Applets {
app := domain.CompanyApplets{
... ...
... ... @@ -4,6 +4,7 @@ import (
"encoding/json"
"errors"
"fmt"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/constant"
"time"
"github.com/astaxie/beego/logs"
... ... @@ -85,6 +86,13 @@ func NewSyncEmployeeService(option map[string]interface{}) *SyncEmployeeService
var _ SyncAction = (*SyncEmployeeService)(nil)
/**
* @Author SteveChan
* @Description //新增、导入用户初始化栏目设置
* @Date 23:54 2021/1/26
* @Param
* @return
**/
func (service SyncEmployeeService) DoAction(action string, byteData []byte) error {
switch action {
case "add":
... ... @@ -157,6 +165,13 @@ func (service SyncEmployeeService) DoAction(action string, byteData []byte) erro
}
}
/**
* @Author SteveChan
* @Description //TODO 初始化栏目设置
* @Date 00:07 2021/1/27
* @Param
* @return
**/
//addEmployeeData 添加用户
func (service SyncEmployeeService) addEmployeeData(datas []EmployeeData) error {
var (
... ... @@ -167,7 +182,7 @@ func (service SyncEmployeeService) addEmployeeData(datas []EmployeeData) error {
return err
}
defer func() {
transactionContext.RollbackTransaction()
_ = transactionContext.RollbackTransaction()
}()
var usersRepository domain.UsersRepository
if usersRepository, err = factory.CreateUsersRepository(map[string]interface{}{
... ... @@ -175,6 +190,12 @@ func (service SyncEmployeeService) addEmployeeData(datas []EmployeeData) error {
}); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
var columnSettingRepository domain.ColumnSettingRepository
if columnSettingRepository, err = factory.CreateColumnSettingRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
for i := range datas {
data := datas[i]
newUser := domain.Users{
... ... @@ -202,7 +223,24 @@ func (service SyncEmployeeService) addEmployeeData(datas []EmployeeData) error {
if err = usersRepository.Add(&newUser); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
// 初始化栏目设置
newColumnSetting := &domain.ColumnSetting{
Description: "订单管理栏目设置",
UserName: data.Name,
CompanyId: int(data.CompanyId),
Uid: data.Id,
Key: constant.ORDER_BASE, // 订单栏目模块名称
Value: domain.DefaultColumns, // 栏目值数组,创建用户时使用默认栏目设置
InvalidValue: domain.DefaultInvalidColumns, // 初始化无效栏目数组
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
}
if _, err = columnSettingRepository.Save(newColumnSetting); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
}
err = transactionContext.CommitTransaction()
return err
}
... ... @@ -225,35 +263,89 @@ func (service SyncEmployeeService) updateEmployeeData(datas []EmployeeData) erro
}); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
var columnSettingRepository domain.ColumnSettingRepository
if columnSettingRepository, err = factory.CreateColumnSettingRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
for i := range datas {
data := datas[i]
var oldUser domain.Users
oldUser, err = usersRepository.FindOne(domain.UsersFindOneQuery{
var (
oldUser *domain.Users
userExist bool
)
oldUser, userExist, err = usersRepository.FindOneWithExist(domain.UsersFindOneQuery{
Id: data.Id,
})
if err != nil {
return lib.ThrowError(lib.BUSINESS_ERROR, err.Error())
}
entryTime, _ := time.Parse("2006-01-02", data.EntryTime)
_ = oldUser.Update(map[string]interface{}{
"CompanyId": data.CompanyId,
"Name": data.Name,
"Sex": data.Sex,
"JobNum": data.JobNum,
"Phone": data.Phone,
"PrivatePhone": data.PrivatePhone,
"Email": data.Email,
"ExtensionNum": data.ExtensionNum,
"Workspace": data.WorkSpace,
"Status": data.Status,
"Avatar": data.Avatar,
"Remarks": data.Remarks,
"ChargeStatus": data.ChargeStatus,
"EntryTime": entryTime,
"AdminType": data.AdminType,
})
if err = usersRepository.Edit(&oldUser); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
if !userExist {
//不存在可更新数据,执行添加数据的操作
newUser := domain.Users{
Id: data.Id,
CompanyId: data.CompanyId,
OpenId: data.OpenId,
Name: data.Name,
Sex: data.Sex,
JobNum: data.JobNum,
Phone: data.Phone,
PrivatePhone: data.PrivatePhone,
Email: data.Email,
ExtensionNum: data.ExtensionNum,
Workspace: data.WorkSpace,
Status: data.Status,
Avatar: data.Avatar,
Remarks: data.Remarks,
ChargeStatus: data.ChargeStatus,
Permission: []domain.AdminPermissionBase{}, //初始化权限
AccessPartners: []domain.Partner{}, //默认初始化
AdminType: data.AdminType,
IsSenior: 2,
}
newUser.EntryTime, _ = time.Parse("2006-01-02", data.EntryTime)
if err = usersRepository.Add(&newUser); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
// 添加用户数据时初始化栏目设置
newColumnSetting := &domain.ColumnSetting{
Description: "订单管理栏目设置",
UserName: data.Name,
CompanyId: int(data.CompanyId),
Uid: data.Id,
Key: constant.ORDER_BASE, // 订单栏目模块名称
Value: domain.DefaultColumns, // 栏目值数组,创建用户时使用默认栏目设置
InvalidValue: domain.DefaultInvalidColumns, // 初始化无效栏目数组
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
}
if _, err = columnSettingRepository.Save(newColumnSetting); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
continue
} else {
entryTime, _ := time.Parse("2006-01-02", data.EntryTime)
_ = oldUser.Update(map[string]interface{}{
"CompanyId": data.CompanyId,
"Name": data.Name,
"Sex": data.Sex,
"JobNum": data.JobNum,
"Phone": data.Phone,
"PrivatePhone": data.PrivatePhone,
"Email": data.Email,
"ExtensionNum": data.ExtensionNum,
"Workspace": data.WorkSpace,
"Status": data.Status,
"Avatar": data.Avatar,
"Remarks": data.Remarks,
"ChargeStatus": data.ChargeStatus,
"EntryTime": entryTime,
"AdminType": data.AdminType,
})
if err = usersRepository.Edit(oldUser); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
}
}
err = transactionContext.CommitTransaction()
... ... @@ -270,7 +362,7 @@ func (service SyncEmployeeService) deleteEmployeeData(data DeleteUserData) error
return err
}
defer func() {
transactionContext.RollbackTransaction()
_ = transactionContext.RollbackTransaction()
}()
var usersRepository domain.UsersRepository
if usersRepository, err = factory.CreateUsersRepository(map[string]interface{}{
... ... @@ -281,6 +373,32 @@ func (service SyncEmployeeService) deleteEmployeeData(data DeleteUserData) error
if err = usersRepository.Remove(data.Ids); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
// 删除栏目设置
var columnSettingRepository domain.ColumnSettingRepository
if value, errFac := factory.CreateColumnSettingRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); errFac != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
} else {
columnSettingRepository = value
}
var ids []int64
for _, d := range data.Ids {
ids = append(ids, d)
}
_, columnSettingsFound, err := columnSettingRepository.Find(domain.ColumnSettingFindQuery{
Ids: ids,
CompanyId: int(data.CompanyId),
})
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
if len(columnSettingsFound) == 0 {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
if _, _, errRm := columnSettingRepository.Remove(nil, columnSettingsFound); errRm != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, errRm.Error())
}
err = transactionContext.CommitTransaction()
return err
}
... ... @@ -295,7 +413,7 @@ func (service SyncEmployeeService) updateUsersStatus(data ForbidAllowUserData) e
return err
}
defer func() {
transactionContext.RollbackTransaction()
_ = transactionContext.RollbackTransaction()
}()
var uDao *dao.UsersDao
if uDao, err = factory.CreateUsersDao(map[string]interface{}{
... ...
... ... @@ -6,6 +6,7 @@ import (
//PlatformAction 企业平台数据同步服务 动作接口设定
type SyncAction interface {
//DoAction(执行的动作,数据)
DoAction(string, []byte) error
}
... ...
... ... @@ -8,6 +8,7 @@ var LOG_LEVEL = "debug"
var LOG_File = "./logs/partnermg.log"
var IMPORT_EXCEL = "./download/订单数据模板.xlsx"
var Log_PREFIX = "[partnermg_dev]"
var APP_NAME = ""
var (
UCENTER_HOST = "https://suplus-ucenter-test.fjmaimaimai.com" //统一用户中心地址
UCENTER_SECRET = "cykbjnfqgctn"
... ... @@ -15,11 +16,15 @@ var (
UCENTER_CHECK_ALT = "rsF0pL!6DwjBO735"
)
// 栏目常量设置
var ORDER_BASE = "order_base" // 订单管理栏目
var (
BUSINESS_ADMIN_HOST = "http://suplus-business-admin-test.fjmaimaimai.com" //企业平台的地址
)
var EXCEL_COLUMN = 12
// 导入excel文件列总数
var EXCEL_COLUMN = 13
func init() {
if os.Getenv("LOG_LEVEL") != "" {
... ... @@ -43,4 +48,7 @@ func init() {
if os.Getenv("Log_PREFIX") != "" {
Log_PREFIX = os.Getenv("Log_PREFIX")
}
if os.Getenv("APP_NAME") != "" {
APP_NAME = os.Getenv("APP_NAME")
}
}
... ...
... ... @@ -4,10 +4,10 @@ import "os"
var POSTGRESQL_DB_NAME = "partner_test"
var POSTGRESQL_USER = "postgres"
var POSTGRESQL_PASSWORD = "1993618jack" // eagle1010
var POSTGRESQL_HOST = "127.0.0.1" // 114.55.200.59
var POSTGRESQL_PORT = "5432" // 31543
var DISABLE_CREATE_TABLE = true
var POSTGRESQL_PASSWORD = "1993618jack" // eagle1010 1993618jack
var POSTGRESQL_HOST = "127.0.0.1" // 114.55.200.59 127.0.0.1
var POSTGRESQL_PORT = "5432" // 31543 5432
var DISABLE_CREATE_TABLE = false
var DISABLE_SQL_GENERATE_PRINT = false
func init() {
... ...
/**
@author: stevechan
@date: 2021/1/26
@note:
**/
package domain
// 栏目项值对象
type Column struct {
// 列标记
Id string `json:"id"`
// 列标记中文
ParamCn string `json:"paramCn"`
// 列标记是否固定,1:固定,2:不固定
ParamFix int `json:"paramFix"`
}
... ...
package domain
import "time"
// 默认选中栏目
var DefaultColumns = []Column{
{
Id: "index",
ParamCn: "序号",
ParamFix: 1,
}, {
Id: "orderId",
ParamCn: "订单号",
ParamFix: 1,
}, {
Id: "shipmentsId",
ParamCn: "发货单号",
ParamFix: 2,
}, {
Id: "saleDate",
ParamCn: "销售日期",
ParamFix: 2,
}, {
Id: "orderNum",
ParamCn: "订单数量",
ParamFix: 2,
}, {
Id: "quantityControl",
ParamCn: "数量调整",
ParamFix: 2,
}, {
Id: "orderPrice",
ParamCn: "订单金额",
ParamFix: 2,
}, {
Id: "priceControl",
ParamCn: "金额调整",
ParamFix: 2,
}, {
Id: "orderDist",
ParamCn: "订单区域",
ParamFix: 2,
}, {
Id: "partnerCategory",
ParamCn: "合伙人类型",
ParamFix: 2,
}, {
Id: "buyer",
ParamCn: "客户",
ParamFix: 2,
}, {
Id: "partner",
ParamCn: "合伙人",
ParamFix: 2,
},
}
// 默认未选中栏目
var DefaultInvalidColumns = []Column{
{
Id: "updateTime",
ParamCn: "更新时间",
ParamFix: 2,
}, {
Id: "createTime",
ParamCn: "创建时间",
ParamFix: 2,
},
}
// 栏目设置
type ColumnSetting struct {
// 栏目设置id
Id int64 `json:"id"`
// 栏目设置关联用户公司id
CompanyId int `json:"companyId"`
// 栏目设置创建时间
CreatedAt time.Time `json:"createdAt"`
// 栏目设置描述
Description string `json:"description"`
// 栏目设置模块名称
Key string `json:"key"`
// 栏目设置关联用户uid
Uid int64 `json:"uid"`
// 栏目设置更新时间
UpdatedAt time.Time `json:"updatedAt"`
// 栏目设置关联用户名称
UserName string `json:"userName"`
// 有效栏目数组
Value []Column `json:"value"`
// 无效栏目数组
InvalidValue []Column `json:"invalidValue"`
}
type ColumnSettingFindQuery struct {
Ids []int64
Uid int64
CompanyId int
Offset int
Limit int
}
type ColumnSettingRepository interface {
Save(columnSetting *ColumnSetting) (*ColumnSetting, error)
Remove(columnSetting *ColumnSetting, columnSettings []*ColumnSetting) (*ColumnSetting, []*ColumnSetting, error)
FindOne(queryOptions map[string]interface{}) (*ColumnSetting, error)
//Find(queryOptions map[string]interface{}) (int64, []*ColumnSetting, error)
Find(queryOptions ColumnSettingFindQuery) (int64, []*ColumnSetting, error)
}
func (columnSetting *ColumnSetting) Identify() interface{} {
if columnSetting.Id == 0 {
return nil
}
return columnSetting.Id
}
func (columnSetting *ColumnSetting) Update(data map[string]interface{}) error {
if companyId, ok := data["companyId"]; ok {
columnSetting.CompanyId = companyId.(int)
}
if createdAt, ok := data["createdAt"]; ok {
columnSetting.CreatedAt = createdAt.(time.Time)
}
if description, ok := data["description"]; ok {
columnSetting.Description = description.(string)
}
if key, ok := data["key"]; ok {
columnSetting.Key = key.(string)
}
if uid, ok := data["uid"]; ok {
columnSetting.Uid = uid.(int64)
}
if updatedAt, ok := data["updatedAt"]; ok {
columnSetting.UpdatedAt = updatedAt.(time.Time)
}
if userName, ok := data["userName"]; ok {
columnSetting.UserName = userName.(string)
}
if value, ok := data["value"]; ok {
columnSetting.Value = value.([]Column)
}
if invalidValue, ok := data["invalidValue"]; ok {
columnSetting.InvalidValue = invalidValue.([]Column)
}
return nil
}
... ...
... ... @@ -90,7 +90,8 @@ type OrderBase struct {
//订单区域信息
RegionInfo RegionInfo `json:"regionInfo"`
//订单对应的合伙人
PartnerId int64 `json:"partnerId"`
PartnerId int64 `json:"partnerId"`
//合伙人信息
PartnerInfo Partner `json:"partnerInfo"`
//业务员抽成比例
SalesmanBonusPercent float64 `json:"salesmanBonusPercent"`
... ... @@ -116,6 +117,8 @@ type OrderBase struct {
Remark OrderBaseRemark `json:"remark"`
//合伙人类型
PartnerCategory PartnerCategory `json:"partnerCategory"`
//销售日期
SaleDate time.Time `json:"saleDate"`
}
//GetCurrentPartnerBonus 获取当前合伙人应收分红
... ... @@ -305,13 +308,14 @@ type OrderBaseFindOneQuery struct {
}
type OrderBaseFindQuery struct {
PartnerId int64
OrderCode string
DeliveryCode string
Offset int
Limit int
OrderType int
CompanyId int64
PartnerId int64
OrderCode string
DeliveryCode string
Offset int
Limit int
OrderType int
CompanyId int64
PartnerCategoryIds []int64
}
// 导入错误信息
... ... @@ -327,7 +331,7 @@ type GoodErrInfo struct {
type OrderBaseRepository interface {
Save(order *OrderBase) error
FindOne(qureyOptions OrderBaseFindOneQuery) (*OrderBase, error)
FindOne(queryOptions OrderBaseFindOneQuery) (*OrderBase, error)
Find(queryOptions OrderBaseFindQuery) ([]OrderBase, int, error)
Remove(id int64, companyId int64) error
}
... ...
... ... @@ -21,7 +21,7 @@ type OrderBestShop struct {
BuyerAddress string `json:"buyerAddress"`
//买家备注
BuyerRemark string `json:"buyerRemark"`
//
//客户id
BuyerId int64 `json:"buyerId"`
//商品总数
OrderCount int `json:"orderCount"`
... ... @@ -30,12 +30,16 @@ type OrderBestShop struct {
//发货时间
DeliveryTime string `json:"deliveryTime"`
//创建时间
CreateTime time.Time `json:"createTime"`
PartnerId int64 `json:"partnerId"`
Goods []OrderGoodBestShop `json:"goods"`
CreateTime time.Time `json:"createTime"`
//合伙人id
PartnerId int64 `json:"partnerId"`
//订单产品
Goods []OrderGoodBestShop `json:"goods"`
//是否将数据同步到 order_base ,order_good
IsCopy bool `json:"isCopy"`
CompanyId int64 `json:"companyId"`
IsCopy bool `json:"isCopy"`
//公司id
CompanyId int64 `json:"companyId"`
//订单区域
OrderArea string `json:"orderArea"`
}
... ... @@ -55,6 +59,7 @@ func (order OrderBestShop) CopyToOrderBase(o *OrderBase) {
o.OrderCompute.PlanOrderAmount = order.OrderAmount
o.OrderCompute.PlanOrderCount = order.OrderCount
o.DeliveryTime, _ = time.Parse("2006-01-02 15:04:05", order.DeliveryTime)
o.SaleDate = order.CreateTime
o.RegionInfo.RegionName = order.OrderArea
return
}
... ...
... ... @@ -172,5 +172,8 @@ type UsersRepository interface {
Edit(*Users) error
Remove([]int64) error
FindOne(queryOptions UsersFindOneQuery) (Users, error)
//FindOneWithExist 查询一个用户,
//当数据不存在时不返回错误,替代的是返回bool,true表示数据存在,false表示数据不存在
FindOneWithExist(queryOptions UsersFindOneQuery) (*Users, bool, error)
Find(queryOptions UsersFindQuery) (int, []Users, error)
}
... ...
... ... @@ -191,7 +191,7 @@ func (dao OrderBaseDao) OrderBonusListForExcel(companyId int64, orderType int, p
//@param updateTime 订单更新时间范围"[开始时间,结束时间]",时间格式"2006-01-02 15:04:05+07"
//@param createTime 订单的创建时间范围"[开始时间,结束时间]" 时间格式"2006-01-02 15:04:05+07"
func (dao OrderBaseDao) OrderListByCondition(companyId int64, orderType int, partnerName string, orderCode string, deliveryCode string,
updateTime [2]string, createTime [2]string, partnerCategory int, limit, offset int) ([]models.OrderBase, int, error) {
updateTime [2]string, createTime [2]string, saleDate [2]string, partnerCategory int, partnerCategoryName string, limit, offset int) ([]models.OrderBase, int, error) {
tx := dao.transactionContext.GetDB()
var orders []models.OrderBase
query := tx.Model(&orders).Where("order_base.company_id=?", companyId)
... ... @@ -203,6 +203,9 @@ func (dao OrderBaseDao) OrderListByCondition(companyId int64, orderType int, par
if partnerCategory > 0 {
query = query.Where(`order_base.partner_category@>'{"id":?}'`, partnerCategory)
}
if partnerCategoryName != "" {
query = query.Where(`order_base.partner_category->>'name' like ?`, "%"+partnerCategoryName+"%")
}
if len(updateTime[0]) > 0 {
query = query.Where(`order_base.update_time>=?`, updateTime[0])
}
... ... @@ -215,6 +218,12 @@ func (dao OrderBaseDao) OrderListByCondition(companyId int64, orderType int, par
if len(createTime[1]) > 0 {
query = query.Where(`order_base.create_time<=?`, createTime[1])
}
if len(saleDate[0]) > 0 {
query = query.Where(`order_base.sale_date>=?`, saleDate[0])
}
if len(saleDate[1]) > 0 {
query = query.Where(`order_base.sale_date<=?`, saleDate[1])
}
if len(partnerName) > 0 {
query = query.Join("LEFT JOIN partner_info as p ON order_base.partner_id=p.id").
Where("p.partner_name like ? ", "%"+partnerName+"%")
... ... @@ -249,6 +258,7 @@ type CustomOrderListForExcel struct {
DeliveryCode string //发货编号
UpdateTime string //更新时间
CreateTime string //创建时间
SaleDate string // 销售时间
PlanOrderCount int64 //货品总数
UseOrderCount int64 //货品总数调整
RegionName string //订单区域
... ... @@ -259,6 +269,13 @@ type CustomOrderListForExcel struct {
PartnerName string //合伙人
}
/**
* @Author SteveChan
* @Description // 导出到excel
* @Date 23:45 2021/1/26
* @Param
* @return
**/
//OrderListForExcel 获取实际订单列表用于excel导出
//@param companyId 公司id
//@param orderType 订单类型
... ... @@ -267,12 +284,13 @@ type CustomOrderListForExcel struct {
//@param updateTime 订单更新时间范围"[开始时间,结束时间]",时间格式"2006-01-02 15:04:05+07"
//@param createTime 订单的创建时间范围"[开始时间,结束时间]" 时间格式"2006-01-02 15:04:05+07"
func (dao OrderBaseDao) OrderListForExcel(companyId int64, partnerName string, orderCode string, deliveryCode string,
updateTime [2]string, createTime [2]string, partnerCategory int) (
updateTime [2]string, createTime [2]string, saleDate [2]string, partnerCategory int, partnerCategoryName string) (
result []CustomOrderListForExcel, err error) {
sqlstr := `
SELECT t1.order_code,t1.delivery_code
,to_char(t1.create_time AT TIME ZONE 'CCT' ,'YYYY-MM-DD HH24:MI:SS') AS create_time
,to_char(t1.update_time AT TIME ZONE 'CCT' ,'YYYY-MM-DD HH24:MI:SS') AS update_time
,to_char(t1.sale_date AT TIME ZONE 'CCT' ,'YYYY-MM-DD HH24:MI:SS') AS sale_date
,t1.plan_order_count,t1.use_order_count,t1.plan_order_amount,t1.use_order_amount
,t1.region_info->'regionName' AS region_name,t1.buyer->'buyerName' AS buyer_name
,t1.partner_category->'name' AS partner_category
... ... @@ -306,17 +324,19 @@ func (dao OrderBaseDao) OrderListForExcel(companyId int64, partnerName string, o
params = append(params, partnerCategory)
sqlstr += ` AND t1.partner_category@>'{"id":?}' `
}
if len(partnerCategoryName) > 0 {
like := "%" + partnerCategoryName + "%"
params = append(params, like)
sqlstr += ` AND t1.partner_category->> 'name' like ?`
}
if len(updateTime[0]) > 0 {
params = append(params, updateTime[0])
sqlstr += ` AND t1.update_time>=? `
}
if len(updateTime[1]) > 0 {
params = append(params, updateTime[1])
sqlstr += ` AND t1.update_time<=? `
}
if len(createTime[0]) > 0 {
params = append(params, createTime[0])
sqlstr += ` AND t1.create_time>=? `
... ... @@ -325,6 +345,14 @@ func (dao OrderBaseDao) OrderListForExcel(companyId int64, partnerName string, o
params = append(params, createTime[1])
sqlstr += ` AND t1.create_time<=? `
}
if len(saleDate[0]) > 0 {
params = append(params, saleDate[0])
sqlstr += ` AND t1.sale_date>=? `
}
if len(saleDate[1]) > 0 {
params = append(params, saleDate[1])
sqlstr += ` AND t1.sale_date<=? `
}
sqlstr += ` ORDER BY t1.create_time DESC limit 10000 `
tx := dao.transactionContext.GetDB()
_, err = tx.Query(&result, sqlstr, params...)
... ...
... ... @@ -5,7 +5,9 @@ import (
"fmt"
"github.com/go-pg/pg/v10"
"github.com/go-pg/pg/v10/orm"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/constant"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/log"
)
... ... @@ -21,6 +23,31 @@ func init() {
if !constant.DISABLE_SQL_GENERATE_PRINT {
DB.AddQueryHook(SqlGeneratePrintHook{})
}
if !constant.DISABLE_CREATE_TABLE {
for _, model := range []interface{}{
&models.ColumnSetting{},
&models.AdminPermission{},
&models.BusinessBonus{},
&models.Company{},
&models.OrderBase{},
&models.OrderBestshop{},
&models.OrderGood{},
&models.OrderGoodBestshop{},
&models.OrderLog{},
&models.PartnerCategoryInfo{},
&models.PartnerInfo{},
&models.Users{},
} {
err := DB.Model(model).CreateTable(&orm.CreateTableOptions{
Temp: false,
IfNotExists: true,
FKConstraints: true,
})
if err != nil {
panic(err)
}
}
}
}
type SqlGeneratePrintHook struct{}
... ...
package models
import (
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
"time"
)
type ColumnSetting struct {
// 栏目设置id
Id int64
// 栏目设置关联用户公司id
CompanyId int
// 栏目设置创建时间
CreatedAt time.Time
// 栏目设置描述
Description string
// 栏目设置模块名称
Key string
// 栏目设置关联用户uid
Uid int64
// 栏目设置更新时间
UpdatedAt time.Time
// 栏目设置关联用户名称
UserName string
// 栏目数组
Value []domain.Column `pg:",array"`
// 无效栏目数组
InvalidValue []domain.Column `pg:",array"`
}
... ...
... ... @@ -45,6 +45,8 @@ type OrderBase struct {
DeliveryTime time.Time
//更新时间
UpdateTime time.Time
//销售时间
SaleDate time.Time
//合伙人应收分红
PlanPartnerBonus float64 `pg:",use_zero"`
//调整后的合伙人应收分红 (初始值=-1);
... ... @@ -62,7 +64,8 @@ type OrderBase struct {
IsDisable int `pg:",use_zero"`
//分红支付状态
BonusStatus int
CompanyId int64
//公司id
CompanyId int64
//数据来源
DataFrom domain.OrderDataFrom ``
//备注
... ...
package repository
import (
"fmt"
"github.com/go-pg/pg/v10"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction"
)
type ColumnSettingRepository struct {
transactionContext *transaction.TransactionContext
}
//func (repository *ColumnSettingRepository) nextIdentify() (int64, error) {
// return 0, nil
//}
func (repository *ColumnSettingRepository) Save(columnSetting *domain.ColumnSetting) (*domain.ColumnSetting, error) {
tx := repository.transactionContext.PgTx
columnSettingModel := &models.ColumnSetting{
Id: columnSetting.Id,
CompanyId: columnSetting.CompanyId,
CreatedAt: columnSetting.CreatedAt,
Description: columnSetting.Description,
Key: columnSetting.Key,
Uid: columnSetting.Uid,
UpdatedAt: columnSetting.UpdatedAt,
UserName: columnSetting.UserName,
Value: columnSetting.Value,
InvalidValue: columnSetting.InvalidValue,
}
if columnSetting.Identify() == nil {
_, err := tx.Model(columnSettingModel).Insert()
if err != nil {
return nil, err
}
} else {
_, err := tx.Model(columnSettingModel).WherePK().
Column("company_id", "created_at", "description", "key", "uid", "updated_at", "user_name", "value", "invalid_value").Update()
if err != nil {
return nil, err
}
}
return columnSetting, nil
}
func (repository *ColumnSettingRepository) Remove(columnSetting *domain.ColumnSetting, columnSettings []*domain.ColumnSetting) (*domain.ColumnSetting, []*domain.ColumnSetting, error) {
tx := repository.transactionContext.PgTx
// 单个删除
if columnSetting != nil {
columnSettingModel := new(models.ColumnSetting)
columnSettingModel.Id = columnSetting.Identify().(int64)
if _, err := tx.Model(&columnSettingModel).WherePK().Delete(); err != nil {
return columnSetting, nil, err
}
}
// 批量删除
if len(columnSettings) > 0 {
var ids []int64
for _, setting := range columnSettings {
ids = append(ids, setting.Identify().(int64))
}
if _, err := tx.Model((*models.ColumnSetting)(nil)).Where("id IN (?)", pg.In(ids)).Delete(); err != nil {
return nil, columnSettings, err
}
}
return columnSetting, columnSettings, nil
}
func (repository *ColumnSettingRepository) FindOne(queryOptions map[string]interface{}) (*domain.ColumnSetting, error) {
tx := repository.transactionContext.PgTx
columnSettingModel := new(models.ColumnSetting)
query := tx.Model(columnSettingModel)
if columnSettingId, ok := queryOptions["column_settingId"]; ok {
query = query.Where("column_setting.id = ?", columnSettingId)
}
if uid, ok := queryOptions["uid"]; ok {
query = query.Where("column_setting.uid = ?", uid)
}
if companyId, ok := queryOptions["companyId"]; ok {
query = query.Where("column_setting.company_id = ?", companyId)
}
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
} else {
return nil, err
}
}
if columnSettingModel.Id == 0 {
return nil, nil
} else {
return repository.transformPgModelToDomainModel(columnSettingModel)
}
}
func (repository *ColumnSettingRepository) Find(queryOptions domain.ColumnSettingFindQuery) (int64, []*domain.ColumnSetting, error) {
tx := repository.transactionContext.PgTx
var columnSettingModels []models.ColumnSetting
columnSettings := make([]*domain.ColumnSetting, 0)
query := tx.Model(&columnSettingModels)
if len(queryOptions.Ids) > 0 {
query = query.Where("column_setting.uid IN (?)", pg.In(queryOptions.Ids))
}
if queryOptions.Uid > 0 {
query = query.Where("column_setting.uid = ?", queryOptions.Uid)
}
if queryOptions.CompanyId > 0 {
query = query.Where("column_setting.company_id = ?", queryOptions.CompanyId)
}
if queryOptions.Offset > -1 {
query = query.Offset(queryOptions.Offset)
}
if queryOptions.Limit > 0 {
query = query.Limit(queryOptions.Limit)
} else {
query = query.Limit(20)
}
if count, err := query.Order("id DESC").SelectAndCount(); err != nil {
return 0, columnSettings, err
} else {
for _, columnSettingModel := range columnSettingModels {
if columnSetting, errTrans := repository.transformPgModelToDomainModel(&columnSettingModel); errTrans != nil {
return 0, columnSettings, errTrans
} else {
columnSettings = append(columnSettings, columnSetting)
}
}
return int64(count), columnSettings, nil
}
}
func (repository *ColumnSettingRepository) transformPgModelToDomainModel(columnSettingModel *models.ColumnSetting) (*domain.ColumnSetting, error) {
return &domain.ColumnSetting{
Id: columnSettingModel.Id,
CompanyId: columnSettingModel.CompanyId,
CreatedAt: columnSettingModel.CreatedAt,
Description: columnSettingModel.Description,
Key: columnSettingModel.Key,
Uid: columnSettingModel.Uid,
UpdatedAt: columnSettingModel.UpdatedAt,
UserName: columnSettingModel.UserName,
Value: columnSettingModel.Value, // 有效栏目设置
InvalidValue: columnSettingModel.InvalidValue, // 无效栏目设置
}, nil
}
func NewColumnSettingRepository(transactionContext *transaction.TransactionContext) (*ColumnSettingRepository, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &ColumnSettingRepository{
transactionContext: transactionContext,
}, nil
}
}
... ...
... ... @@ -2,6 +2,7 @@ package repository
import (
"fmt"
"github.com/go-pg/pg/v10"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models"
... ... @@ -23,12 +24,13 @@ func NewOrderBaseRepository(transactionContext *transaction.TransactionContext)
return &OrderBaseRepository{transactionContext: transactionContext}, nil
}
func (reponsitory OrderBaseRepository) transformPgModelToDomainModel(orderModel *models.OrderBase) (order domain.OrderBase, err error) {
func (repository OrderBaseRepository) transformPgModelToDomainModel(orderModel *models.OrderBase) (order domain.OrderBase, err error) {
order = domain.OrderBase{
Id: orderModel.Id, OrderType: orderModel.OrderType, OrderCode: orderModel.OrderCode,
DeliveryCode: orderModel.DeliveryCode, Buyer: orderModel.Buyer, RegionInfo: orderModel.RegionInfo,
PartnerId: orderModel.PartnerId, SalesmanBonusPercent: orderModel.SalesmanBonusPercent,
CreateTime: orderModel.CreateTime, DeliveryTime: orderModel.DeliveryTime, UpdateTime: orderModel.UpdateTime,
SaleDate: orderModel.SaleDate,
IsDisable: orderModel.IsDisable,
OrderCompute: domain.OrderCompute{
PlanPartnerBonus: orderModel.PlanPartnerBonus, UsePartnerBonus: orderModel.UsePartnerBonus,
... ... @@ -55,18 +57,33 @@ func (repository OrderBaseRepository) Save(orderInfo *domain.OrderBase) error {
tx = repository.transactionContext.PgTx
)
m := &models.OrderBase{
Id: orderInfo.Id, OrderType: orderInfo.OrderType, OrderCode: orderInfo.OrderCode,
DeliveryCode: orderInfo.DeliveryCode, Buyer: orderInfo.Buyer, RegionInfo: orderInfo.RegionInfo,
PartnerId: orderInfo.PartnerId, SalesmanBonusPercent: orderInfo.SalesmanBonusPercent,
SalesmanBonus: orderInfo.OrderCompute.SalesmanBonus, PlanOrderCount: orderInfo.OrderCompute.PlanOrderCount,
PlanOrderAmount: orderInfo.OrderCompute.PlanOrderAmount, UseOrderCount: orderInfo.OrderCompute.UseOrderCount,
UseOrderAmount: orderInfo.OrderCompute.UseOrderAmount, DeliveryTime: orderInfo.DeliveryTime,
PlanPartnerBonus: orderInfo.OrderCompute.PlanPartnerBonus, UsePartnerBonus: orderInfo.OrderCompute.UsePartnerBonus,
PartnerBonusHas: orderInfo.OrderCompute.PartnerBonusHas, PartnerBonusNot: orderInfo.OrderCompute.PartnerBonusNot,
PartnerBonusExpense: orderInfo.OrderCompute.PartnerBonusExpense, IsDisable: orderInfo.IsDisable,
CreateTime: orderInfo.CreateTime, BonusStatus: orderInfo.BonusStatus,
CompanyId: orderInfo.CompanyId, DataFrom: orderInfo.DataFrom,
Remark: orderInfo.Remark, PartnerCategory: orderInfo.PartnerCategory,
Id: orderInfo.Id,
OrderType: orderInfo.OrderType,
OrderCode: orderInfo.OrderCode,
DeliveryCode: orderInfo.DeliveryCode,
Buyer: orderInfo.Buyer,
RegionInfo: orderInfo.RegionInfo,
PartnerId: orderInfo.PartnerId,
SalesmanBonusPercent: orderInfo.SalesmanBonusPercent,
SalesmanBonus: orderInfo.OrderCompute.SalesmanBonus,
PlanOrderCount: orderInfo.OrderCompute.PlanOrderCount,
PlanOrderAmount: orderInfo.OrderCompute.PlanOrderAmount,
UseOrderCount: orderInfo.OrderCompute.UseOrderCount,
UseOrderAmount: orderInfo.OrderCompute.UseOrderAmount,
DeliveryTime: orderInfo.DeliveryTime,
PlanPartnerBonus: orderInfo.OrderCompute.PlanPartnerBonus,
UsePartnerBonus: orderInfo.OrderCompute.UsePartnerBonus,
PartnerBonusHas: orderInfo.OrderCompute.PartnerBonusHas,
PartnerBonusNot: orderInfo.OrderCompute.PartnerBonusNot,
PartnerBonusExpense: orderInfo.OrderCompute.PartnerBonusExpense,
IsDisable: orderInfo.IsDisable,
CreateTime: orderInfo.CreateTime,
SaleDate: orderInfo.SaleDate,
BonusStatus: orderInfo.BonusStatus,
CompanyId: orderInfo.CompanyId,
DataFrom: orderInfo.DataFrom,
Remark: orderInfo.Remark,
PartnerCategory: orderInfo.PartnerCategory,
}
if m.Id == 0 {
_, err = tx.Model(m).
... ... @@ -75,6 +92,7 @@ func (repository OrderBaseRepository) Save(orderInfo *domain.OrderBase) error {
orderInfo.Id = m.Id
orderInfo.CreateTime = m.CreateTime
orderInfo.UpdateTime = m.UpdateTime
orderInfo.SaleDate = m.CreateTime
} else {
_, err = tx.Model(m).
WherePK().
... ... @@ -104,6 +122,9 @@ func (repository OrderBaseRepository) Find(queryOption domain.OrderBaseFindQuery
if queryOption.CompanyId > 0 {
query = query.Where("company_id=?", queryOption.CompanyId)
}
if len(queryOption.PartnerCategoryIds) > 0 {
query = query.Where(`(order_base.partner_category->>'id')::int IN (?)`, pg.In(queryOption.PartnerCategoryIds))
}
if queryOption.Offset > -1 {
query = query.Offset(queryOption.Offset)
}
... ... @@ -131,16 +152,16 @@ func (repository OrderBaseRepository) Find(queryOption domain.OrderBaseFindQuery
return ordersReturn, count, nil
}
func (repository OrderBaseRepository) FindOne(qureyOptions domain.OrderBaseFindOneQuery) (*domain.OrderBase, error) {
func (repository OrderBaseRepository) FindOne(queryOptions domain.OrderBaseFindOneQuery) (*domain.OrderBase, error) {
var (
err error
tx = repository.transactionContext.PgDd
)
m := new(models.OrderBase)
query := tx.Model(m).
Where("id=?", qureyOptions.OrderId)
if qureyOptions.CompanyId > 0 {
query = query.Where("company_id=?", qureyOptions.CompanyId)
Where("id=?", queryOptions.OrderId)
if queryOptions.CompanyId > 0 {
query = query.Where("company_id=?", queryOptions.CompanyId)
}
err = query.First()
if err != nil {
... ...
... ... @@ -5,6 +5,7 @@ import (
"fmt"
"time"
"github.com/go-pg/pg/v10"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction"
... ... @@ -153,6 +154,47 @@ func (reponsitory UsersRepository) FindOne(queryOptions domain.UsersFindOneQuery
return reponsitory.transformPgModelToDomainModel(&m)
}
//FindOneWithExist 查询一个用户,
//当数据不存在时不返回错误,替代的是返回bool,true表示数据存在,false表示数据不存在
func (reponsitory UsersRepository) FindOneWithExist(queryOptions domain.UsersFindOneQuery) (*domain.Users, bool, error) {
var (
err error
tx = reponsitory.transactionContext.PgTx
m models.Users
hasCondition bool
)
query := tx.Model(&m)
query = query.Where("delete_at ISNULL")
if queryOptions.Id > 0 {
hasCondition = true
query = query.Where("id=?", queryOptions.Id)
}
if len(queryOptions.Phone) > 0 {
hasCondition = true
query = query.Where("phone=?", queryOptions.Phone)
}
if queryOptions.CompanyId > 0 {
hasCondition = true
query = query.Where("company_id=?", queryOptions.CompanyId)
}
if queryOptions.OpenId > 0 {
hasCondition = true
query = query.Where("open_id=?", queryOptions.OpenId)
}
if !hasCondition {
return nil, false, errors.New("UsersRepository.FindOne 必须要有查询条件")
}
err = query.First()
if err != nil && err == pg.ErrNoRows {
return nil, false, nil
}
if err != nil {
return nil, false, err
}
searchResult, err := reponsitory.transformPgModelToDomainModel(&m)
return &searchResult, true, err
}
func (reponsitory UsersRepository) Find(queryOption domain.UsersFindQuery) (int, []domain.Users, error) {
db := reponsitory.transactionContext.PgTx
usersModels := []models.Users{}
... ...
... ... @@ -47,3 +47,19 @@ func IsContain(items []string, item string) bool {
}
return false
}
/**
* @Author SteveChan
* @Description //TODO
* @Date 23:34 2021/2/2
* @Param
* @return
**/
func IsContainInt(items []int64, item int64) bool {
for _, eachItem := range items {
if eachItem == item {
return true
}
}
return false
}
... ...
package controllers
import (
"encoding/json"
"errors"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
"github.com/astaxie/beego/logs"
"github.com/linmadan/egglib-go/web/beego/utils"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/columnSetting/command"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/columnSetting/query"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/columnSetting/service"
)
type ColumnSettingController struct {
BaseController
}
////Prepare 重写 BaseController 的Prepare方法
func (controller *ColumnSettingController) Prepare() {
controller.BaseController.Prepare()
if ok := controller.ValidJWTToken(); !ok {
return
}
if ok := controller.ValidAdminPermission(domain.PERMISSION_ORDER); !ok {
return
}
}
func (controller *ColumnSettingController) CreateColumnSetting() {
columnSettingService := service.NewColumnSettingService(nil)
createColumnSettingCommand := &command.CreateColumnSettingCommand{}
//_ = json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), createColumnSettingCommand)
if err := controller.BindJsonData(&createColumnSettingCommand); err != nil {
logs.Error(err)
controller.ResponseError(errors.New("json数据解析失败"))
return
}
companyId := controller.GetUserCompany()
uid := controller.GetUserId()
createColumnSettingCommand.CompanyId = int(companyId)
createColumnSettingCommand.Uid = uid
data, err := columnSettingService.CreateColumnSetting(createColumnSettingCommand)
var response utils.JsonResponse
if err != nil {
response = utils.ResponseError(controller.Ctx, err)
} else {
response = utils.ResponseData(controller.Ctx, data)
}
controller.Data["json"] = response
controller.ServeJSON()
}
/**
* @Author SteveChan
* @Description // 更新栏目设置
* @Date 22:52 2021/1/26
* @Param
* @return
**/
func (controller *ColumnSettingController) UpdateColumnSetting() {
columnSettingService := service.NewColumnSettingService(nil)
updateColumnSettingCommand := &command.UpdateColumnSettingCommand{}
//_ = json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), updateColumnSettingCommand)
if err := controller.BindJsonData(&updateColumnSettingCommand); err != nil {
logs.Error(err)
controller.ResponseError(errors.New("json数据解析失败"))
return
}
//columnSettingId, _ := controller.GetInt64(":columnSettingId")
companyId := controller.GetUserCompany()
uid := controller.GetUserId()
//updateColumnSettingCommand.ColumnSettingId = columnSettingId
updateColumnSettingCommand.CompanyId = int(companyId)
updateColumnSettingCommand.Uid = uid
updateColumnSettingCommand.Selected = updateColumnSettingCommand.OrderBaseColumns.Selected
updateColumnSettingCommand.UnSelected = updateColumnSettingCommand.OrderBaseColumns.UnSelected
data, err := columnSettingService.UpdateColumnSetting(updateColumnSettingCommand)
var response utils.JsonResponse
if err != nil {
response = utils.ResponseError(controller.Ctx, err)
} else {
response = utils.ResponseData(controller.Ctx, data)
}
controller.Data["json"] = response
controller.ServeJSON()
}
/**
* @Author SteveChan
* @Description // 获取栏目设置
* @Date 22:53 2021/1/26
* @Param
* @return
**/
func (controller *ColumnSettingController) GetColumnSetting() {
columnSettingService := service.NewColumnSettingService(nil)
getColumnSettingQuery := &query.GetColumnSettingQuery{}
//columnSettingId, _ := controller.GetInt64(":columnSettingId")
companyId := controller.GetUserCompany() // 公司id
uid := controller.GetUserId() // 用户id
//getColumnSettingQuery.ColumnSettingId = columnSettingId
getColumnSettingQuery.CompanyId = int(companyId)
getColumnSettingQuery.Uid = uid
data, err := columnSettingService.GetColumnSetting(getColumnSettingQuery)
var response utils.JsonResponse
if err != nil {
response = utils.ResponseError(controller.Ctx, err)
} else {
response = utils.ResponseData(controller.Ctx, data)
}
controller.Data["json"] = response
controller.ServeJSON()
}
func (controller *ColumnSettingController) RemoveColumnSetting() {
columnSettingService := service.NewColumnSettingService(nil)
removeColumnSettingCommand := &command.RemoveColumnSettingCommand{}
_ = json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), removeColumnSettingCommand)
columnSettingId, _ := controller.GetInt64(":columnSettingId")
removeColumnSettingCommand.ColumnSettingId = columnSettingId
data, err := columnSettingService.RemoveColumnSetting(removeColumnSettingCommand)
var response utils.JsonResponse
if err != nil {
response = utils.ResponseError(controller.Ctx, err)
} else {
response = utils.ResponseData(controller.Ctx, data)
}
controller.Data["json"] = response
controller.ServeJSON()
}
/**
* @Author SteveChan
* @Description // 重置栏目设置
* @Date 22:52 2021/1/26
* @Param
* @return
**/
func (controller *ColumnSettingController) ResetColumn() {
columnSettingService := service.NewColumnSettingService(nil)
resetColumnCommand := &command.ResetColumnCommand{}
companyId := controller.GetUserCompany()
uid := controller.GetUserId()
//_ = json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), resetColumnCommand)
resetColumnCommand.CompanyId = int(companyId)
resetColumnCommand.Uid = uid
resetColumnCommand.Value = domain.DefaultColumns // 还原默认栏目设置
resetColumnCommand.InvalidValue = domain.DefaultInvalidColumns // 还原默认无效栏目
data, err := columnSettingService.ResetColumn(resetColumnCommand)
var response utils.JsonResponse
if err != nil {
response = utils.ResponseError(controller.Ctx, err)
} else {
response = utils.ResponseData(controller.Ctx, data)
}
controller.Data["json"] = response
controller.ServeJSON()
}
/**
* @Author SteveChan
* @Description // 获取栏目列表
* @Date 14:03 2021/2/1
* @Param
* @return
**/
func (controller *ColumnSettingController) ListColumnSetting() {
columnSettingService := service.NewColumnSettingService(nil)
listColumnSettingQuery := &query.ListColumnSettingQuery{}
offset, _ := controller.GetInt("offset")
listColumnSettingQuery.Offset = offset
limit, _ := controller.GetInt("limit")
listColumnSettingQuery.Limit = limit
data, err := columnSettingService.ListColumnSetting(listColumnSettingQuery)
var response utils.JsonResponse
if err != nil {
response = utils.ResponseError(controller.Ctx, err)
} else {
response = utils.ResponseData(controller.Ctx, data)
}
controller.Data["json"] = response
controller.ServeJSON()
}
/**
* @Author SteveChan
* @Description //返回默认栏目设置
* @Date 14:06 2021/2/1
* @Param
* @return
**/
func (controller *ColumnSettingController) ListDefaultColumnSetting() {
data := map[string]interface{}{
"orderBaseColumns": map[string]interface{}{
"selected": domain.DefaultColumns,
"unselected": domain.DefaultInvalidColumns,
},
}
var response utils.JsonResponse
response = utils.ResponseData(controller.Ctx, data)
controller.Data["json"] = response
controller.ServeJSON()
}
... ...
... ... @@ -292,16 +292,18 @@ func (c *OrderDividendController) EditOrderRemarkBonus() {
}
func (c *OrderDividendController) ListOrderBonusForExcel() {
type Parameter struct {
SearchWord string `json:"searchWord"`
OrderType int `json:"orderType"`
PageSize int `json:"pageSize"`
PageNumber int `json:"pageNumber"`
PartnerCategoryId int `json:"partnerCategoryId"`
CreateTime []string `json:"createTime"`
}
//type Parameter struct {
// SearchWord string `json:"searchWord"`
// OrderType int `json:"orderType"`
// PageSize int `json:"pageSize"`
// PageNumber int `json:"pageNumber"`
// PartnerCategoryId int `json:"partnerCategoryId"`
// CreateTime []string `json:"createTime"`
//}
var (
param Parameter
//param Parameter
param orderQuery.ListOrderBonusForExcelQuery
err error
)
if err = c.BindJsonData(&param); err != nil {
... ... @@ -309,9 +311,14 @@ func (c *OrderDividendController) ListOrderBonusForExcel() {
c.ResponseError(errors.New("json数据解析失败"))
return
}
if !(param.OrderType == 0 ||
param.OrderType == domain.OrderReal ||
param.OrderType == domain.OrderTypeBestShop) {
if param.Type != "ORDER_DIVIDEND" {
logs.Error(err)
c.ResponseError(errors.New("错误的操作类型"))
return
}
if !(param.Where.OrderType == 0 ||
param.Where.OrderType == domain.OrderReal ||
param.Where.OrderType == domain.OrderTypeBestShop) {
c.ResponseError(errors.New("参数异常"))
return
}
... ... @@ -319,9 +326,9 @@ func (c *OrderDividendController) ListOrderBonusForExcel() {
createTimeBegin string
createTimeEnd string
)
if len(param.CreateTime) > 0 {
if len(param.CreateTime[0]) > 0 {
t, err := time.ParseInLocation("2006-01-02", param.CreateTime[0], time.Local)
if len(param.Where.CreateTime) > 0 {
if len(param.Where.CreateTime[0]) > 0 {
t, err := time.ParseInLocation("2006-01-02", param.Where.CreateTime[0], time.Local)
if err != nil {
c.ResponseError(errors.New("UpdateTimeBegin 时间格式错误"))
return
... ... @@ -329,9 +336,9 @@ func (c *OrderDividendController) ListOrderBonusForExcel() {
createTimeBegin = t.Format("2006-01-02 15:04:05-07")
}
}
if len(param.CreateTime) > 1 {
if len(param.CreateTime[1]) > 0 {
t, err := time.ParseInLocation("2006-01-02", param.CreateTime[1], time.Local)
if len(param.Where.CreateTime) > 1 {
if len(param.Where.CreateTime[1]) > 0 {
t, err := time.ParseInLocation("2006-01-02", param.Where.CreateTime[1], time.Local)
if err != nil {
c.ResponseError(errors.New("UpdateTimeEnd 时间格式错误"))
return
... ... @@ -345,10 +352,10 @@ func (c *OrderDividendController) ListOrderBonusForExcel() {
orderSrv := orderService.NewOrderInfoService(nil)
dataResult, column, err := orderSrv.ListOrderBonusForExcel(
orderQuery.ListOrderBonusQuery{
OrderType: param.OrderType,
PartnerOrCode: param.SearchWord,
OrderType: param.Where.OrderType,
PartnerOrCode: param.Where.SearchWord,
CompanyId: companyId,
PartnerCategory: param.PartnerCategoryId,
PartnerCategory: param.Where.PartnerCategoryId,
CreateTimeBegin: createTimeBegin,
CreateTimeEnd: createTimeEnd,
})
... ...
... ... @@ -5,7 +5,6 @@ import (
"encoding/hex"
"errors"
"fmt"
"github.com/beego/beego/v2/client/httplib"
"os"
"path"
"regexp"
... ... @@ -14,6 +13,8 @@ import (
"time"
"unicode/utf8"
"github.com/beego/beego/v2/client/httplib"
"github.com/360EntSecGroup-Skylar/excelize/v2"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/constant"
... ... @@ -160,15 +161,16 @@ func (postData *postOrderPurposeDelivery) Valid() error {
**/
func (c *OrderInfoController) PageListOrderReal() {
type Parameter struct {
//SearchText string `json:"searchText"`
PartnerName string `json:"partnerName"` // 合伙人姓名
OrderCode string `json:"orderCode"` // 订单号
DeliveryCode string `json:"deliveryCode"` // 发货单号
PartnerCategory int `json:"PartnerCategory"`
PageSize int `json:"pageSize"`
PageNumber int `json:"pageNumber"`
UpdateTime []string `json:"updateTime"`
CreateTime []string `json:"createTime"`
PartnerName string `json:"partnerName"` // 合伙人姓名
OrderCode string `json:"orderCode"` // 订单号
DeliveryCode string `json:"deliveryCode"` // 发货单号
PartnerCategory int `json:"partnerCategory"` // 合伙人类型id
PartnerCategoryName string `json:"partnerCategoryName"` // 合伙人类型名称
PageSize int `json:"pageSize"`
PageNumber int `json:"pageNumber"`
UpdateTime []string `json:"updateTime"` // 订单更新时间
CreateTime []string `json:"createTime"` // 订单创建时间
SaleDate []string `json:"saleDate"` // 销售时间
}
var (
param Parameter
... ... @@ -185,6 +187,7 @@ func (c *OrderInfoController) PageListOrderReal() {
if param.PageSize == 0 {
param.PageSize = 20
}
// 订单更新时间处理
var (
updateTimeBegin string
updateTimeEnd string
... ... @@ -211,6 +214,7 @@ func (c *OrderInfoController) PageListOrderReal() {
updateTimeEnd = t.Format("2006-01-02 15:04:05-07")
}
}
// 订单创建时间处理
var (
createTimeBegin string
createTimeEnd string
... ... @@ -237,29 +241,57 @@ func (c *OrderInfoController) PageListOrderReal() {
createTimeEnd = t.Format("2006-01-02 15:04:05-07")
}
}
// 订单销售时间处理
var (
saleDateBegin string
saleDateEnd string
)
if len(param.SaleDate) > 0 {
if len(param.SaleDate[0]) > 0 {
t, err := time.ParseInLocation("2006-01-02", param.SaleDate[0], time.Local)
if err != nil {
c.ResponseError(errors.New("销售开始时间格式错误"))
return
}
saleDateBegin = t.Format("2006-01-02 15:04:05-07")
}
}
if len(param.SaleDate) > 1 {
if len(param.SaleDate[1]) > 0 {
t, err := time.ParseInLocation("2006-01-02", param.SaleDate[1], time.Local)
if err != nil {
c.ResponseError(errors.New("销售结束时间格式错误"))
return
}
//设定时间边界
t = t.Add(86399 * time.Second)
saleDateEnd = t.Format("2006-01-02 15:04:05-07")
}
}
companyId := c.GetUserCompany()
orderSrv := orderService.NewOrderInfoService(nil)
orderinfos, cnt, err := orderSrv.PageListOrderBase(orderQuery.ListOrderBaseQuery{
//PartnerOrCode: param.SearchText,
PartnerName: param.PartnerName,
OrderCode: param.OrderCode,
DeliveryCode: param.DeliveryCode,
OrderType: domain.OrderReal,
Limit: param.PageSize,
Offset: (param.PageNumber - 1) * param.PageSize,
CompanyId: companyId,
PartnerCategory: param.PartnerCategory,
UpdateTimeBegin: updateTimeBegin,
UpdateTimeEnd: updateTimeEnd,
CreateTimeBegin: createTimeBegin,
CreateTimeEnd: createTimeEnd,
orderInfos, cnt, err := orderSrv.PageListOrderBase(orderQuery.ListOrderBaseQuery{
PartnerName: param.PartnerName,
OrderCode: param.OrderCode,
DeliveryCode: param.DeliveryCode,
OrderType: domain.OrderReal,
Limit: param.PageSize,
Offset: (param.PageNumber - 1) * param.PageSize,
CompanyId: companyId,
PartnerCategory: param.PartnerCategory,
PartnerCategoryName: param.PartnerCategoryName,
UpdateTimeBegin: updateTimeBegin,
UpdateTimeEnd: updateTimeEnd,
CreateTimeBegin: createTimeBegin,
CreateTimeEnd: createTimeEnd,
SaleDateBegin: saleDateBegin,
SaleDateEnd: saleDateEnd,
})
if err != nil {
c.ResponseError(err)
return
}
c.ResponsePageList(orderinfos, cnt, param.PageNumber)
c.ResponsePageList(orderInfos, cnt, param.PageNumber)
return
}
... ... @@ -299,7 +331,8 @@ func (c *OrderInfoController) GetOrderReal() {
allGoods := []map[string]interface{}{}
for _, v := range orderinfo.Goods {
m := map[string]interface{}{
"id": fmt.Sprint(v.Id),
//"id": fmt.Sprint(v.Id),
"id": v.Id,
"productName": v.GoodName,
"orderNum": v.PlanGoodNumber,
"univalence": v.Price,
... ... @@ -330,8 +363,9 @@ func (c *OrderInfoController) GetOrderReal() {
"orderNumCountControl": "",
"orderAmountAdjustmentCountControl": "",
"product": allGoods,
"create_time": orderinfo.CreateTime.Local().Format("2006-01-02 15:04:06"),
"update_time": orderinfo.UpdateTime.Local().Format("2006-01-02 15:04:06"),
"create_time": orderinfo.CreateTime.Local().Format("2006-01-02 15:04:05"),
"update_time": orderinfo.UpdateTime.Local().Format("2006-01-02 15:04:05"),
"saleDate": orderinfo.SaleDate.Local().Format("2006-01-02 15:04:05"),
"partnerCategoryId": orderinfo.PartnerCategory.Id,
"partnerCategoryName": orderinfo.PartnerCategory.Name,
}
... ... @@ -350,6 +384,7 @@ type postRealOrderDetail struct {
postPurposeOrderDetail
PartnerCategoryId int64 `json:"partnerCategoryId"`
ShipmentsId string `json:"shipmentsId"` //发货单号
SaleDate string `json:"saleDate"` // 销售日期
}
func (postData *postRealOrderDetail) Valid() error {
... ... @@ -380,10 +415,18 @@ func (c *OrderInfoController) UpdateOrderReal() {
return
}
var orderDataReturn *domain.OrderBase
saleDate, err := time.ParseInLocation("2006-01-02 15:04:05", param.SaleDate, time.Local)
saleDateWithTz := time.Date(saleDate.Year(), saleDate.Month(), saleDate.Day(), time.Now().Hour(), time.Now().Minute(), time.Now().Second(), time.Now().Nanosecond(), time.Local)
if err != nil {
e := lib.ThrowError(lib.ARG_ERROR, err.Error())
c.ResponseError(e)
return
}
if param.Id == 0 {
orderDataReturn, err = c.addOrderReal(param)
orderDataReturn, err = c.addOrderReal(param, saleDateWithTz)
} else {
err = c.editOrderReal(param)
err = c.editOrderReal(param, saleDateWithTz)
}
if err != nil {
c.ResponseError(err)
... ... @@ -399,7 +442,7 @@ func (c *OrderInfoController) UpdateOrderReal() {
return
}
func (c *OrderInfoController) addOrderReal(param postRealOrderDetail) (*domain.OrderBase, error) {
func (c *OrderInfoController) addOrderReal(param postRealOrderDetail, saleDate time.Time) (*domain.OrderBase, error) {
orderSrv := orderService.NewOrderInfoService(nil)
newGoods := []orderCmd.OrderGoodData{}
for _, v := range param.Product {
... ... @@ -423,12 +466,13 @@ func (c *OrderInfoController) addOrderReal(param postRealOrderDetail) (*domain.O
Goods: newGoods,
CompanyId: companyId,
PartnerCategory: param.PartnerCategoryId,
SaleDate: saleDate,
}
orderData, err := orderSrv.CreateNewOrder(createcmd)
return orderData, err
}
func (c *OrderInfoController) editOrderReal(param postRealOrderDetail) error {
func (c *OrderInfoController) editOrderReal(param postRealOrderDetail, saleDate time.Time) error {
newGoods := []orderCmd.OrderGoodData{}
for _, v := range param.Product {
... ... @@ -453,6 +497,7 @@ func (c *OrderInfoController) editOrderReal(param postRealOrderDetail) error {
Goods: newGoods,
CompanyId: companyId,
PartnerCategory: param.PartnerCategoryId,
SaleDate: saleDate,
}
orderSrv := orderService.NewOrderInfoService(nil)
_, err := orderSrv.UpdateOrderData(updatecmd)
... ... @@ -527,17 +572,20 @@ func (c *OrderInfoController) RemoveOrderReal() {
//ListOrderForExcel excel 导出实际订单的列表
func (c *OrderInfoController) ListOrderForExcel() {
type Parameter struct {
//SearchText string `json:"searchText"`
PartnerName string `json:"partnerName"` // 合伙人姓名
OrderCode string `json:"orderCode"` // 订单号
DeliveryCode string `json:"deliveryCode"` // 发货单号
PartnerCategory int `json:"PartnerCategory"`
UpdateTime []string `json:"updateTime"`
CreateTime []string `json:"createTime"`
}
//type Parameter struct {
// PartnerName string `json:"partnerName"` // 合伙人姓名
// OrderCode string `json:"orderCode"` // 订单号
// DeliveryCode string `json:"deliveryCode"` // 发货单号
// PartnerCategory int `json:"partnerCategory"` // 合伙人类型
// PartnerCategoryName string `json:"partnerCategoryName"` // 合伙人类型名称
// UpdateTime []string `json:"updateTime"` // 更新时间
// CreateTime []string `json:"createTime"` // 创建时间
// SaleDate []string `json:"saleDate"` // 销售日期
//}
var (
param Parameter
//param Parameter
param orderQuery.ListOrderForExcelQuery
err error
)
if err = c.BindJsonData(&param); err != nil {
... ... @@ -545,13 +593,19 @@ func (c *OrderInfoController) ListOrderForExcel() {
c.ResponseError(errors.New("json数据解析失败"))
return
}
if param.Type != "ORDER_BASE" {
logs.Error(err)
c.ResponseError(errors.New("错误的操作类型"))
return
}
// 订单更新时间
var (
updateTimeBegin string
updateTimeEnd string
)
if len(param.UpdateTime) > 0 {
if len(param.UpdateTime[0]) > 0 {
t, err := time.ParseInLocation("2006-01-02", param.UpdateTime[0], time.Local)
if len(param.Where.UpdateTime) > 0 {
if len(param.Where.UpdateTime[0]) > 0 {
t, err := time.ParseInLocation("2006-01-02", param.Where.UpdateTime[0], time.Local)
if err != nil {
c.ResponseError(errors.New("UpdateTimeBegin 时间格式错误"))
return
... ... @@ -559,9 +613,9 @@ func (c *OrderInfoController) ListOrderForExcel() {
updateTimeBegin = t.Format("2006-01-02 15:04:05-07")
}
}
if len(param.UpdateTime) > 1 {
if len(param.UpdateTime[1]) > 0 {
t, err := time.ParseInLocation("2006-01-02", param.UpdateTime[1], time.Local)
if len(param.Where.UpdateTime) > 1 {
if len(param.Where.UpdateTime[1]) > 0 {
t, err := time.ParseInLocation("2006-01-02", param.Where.UpdateTime[1], time.Local)
if err != nil {
c.ResponseError(errors.New("UpdateTimeEnd 时间格式错误"))
return
... ... @@ -571,13 +625,14 @@ func (c *OrderInfoController) ListOrderForExcel() {
updateTimeEnd = t.Format("2006-01-02 15:04:05-07")
}
}
// 订单创建时间
var (
createTimeBegin string
createTimeEnd string
)
if len(param.CreateTime) > 0 {
if len(param.CreateTime[0]) > 0 {
t, err := time.ParseInLocation("2006-01-02", param.CreateTime[0], time.Local)
if len(param.Where.CreateTime) > 0 {
if len(param.Where.CreateTime[0]) > 0 {
t, err := time.ParseInLocation("2006-01-02", param.Where.CreateTime[0], time.Local)
if err != nil {
c.ResponseError(errors.New("UpdateTimeBegin 时间格式错误"))
return
... ... @@ -585,9 +640,9 @@ func (c *OrderInfoController) ListOrderForExcel() {
createTimeBegin = t.Format("2006-01-02 15:04:05-07")
}
}
if len(param.CreateTime) > 1 {
if len(param.CreateTime[1]) > 0 {
t, err := time.ParseInLocation("2006-01-02", param.CreateTime[1], time.Local)
if len(param.Where.CreateTime) > 1 {
if len(param.Where.CreateTime[1]) > 0 {
t, err := time.ParseInLocation("2006-01-02", param.Where.CreateTime[1], time.Local)
if err != nil {
c.ResponseError(errors.New("UpdateTimeEnd 时间格式错误"))
return
... ... @@ -597,21 +652,51 @@ func (c *OrderInfoController) ListOrderForExcel() {
createTimeEnd = t.Format("2006-01-02 15:04:05-07")
}
}
// 订单销售时间处理
var (
saleDateBegin string
saleDateEnd string
)
if len(param.Where.SaleDate) > 0 {
if len(param.Where.SaleDate[0]) > 0 {
t, err := time.ParseInLocation("2006-01-02", param.Where.SaleDate[0], time.Local)
if err != nil {
c.ResponseError(errors.New("销售开始时间格式错误"))
return
}
saleDateBegin = t.Format("2006-01-02 15:04:05-07")
}
}
if len(param.Where.SaleDate) > 1 {
if len(param.Where.SaleDate[1]) > 0 {
t, err := time.ParseInLocation("2006-01-02", param.Where.SaleDate[1], time.Local)
if err != nil {
c.ResponseError(errors.New("销售结束时间格式错误"))
return
}
//设定时间边界
t = t.Add(86399 * time.Second)
saleDateEnd = t.Format("2006-01-02 15:04:05-07")
}
}
companyId := c.GetUserCompany()
uid := c.GetUserId()
orderSrv := orderService.NewOrderInfoService(nil)
orderinfos, columns, err := orderSrv.ListOrderForExcel(orderQuery.ListOrderBaseQuery{
//PartnerOrCode: param.SearchText,
PartnerName: param.PartnerName,
OrderCode: param.OrderCode,
DeliveryCode: param.DeliveryCode,
OrderType: domain.OrderReal,
CompanyId: companyId,
PartnerCategory: param.PartnerCategory,
UpdateTimeBegin: updateTimeBegin,
UpdateTimeEnd: updateTimeEnd,
CreateTimeBegin: createTimeBegin,
CreateTimeEnd: createTimeEnd,
orderInfos, columns, err := orderSrv.ListOrderForExcel(orderQuery.ListOrderBaseQuery{
PartnerName: param.Where.PartnerName,
OrderCode: param.Where.OrderCode,
DeliveryCode: param.Where.DeliveryCode,
OrderType: domain.OrderReal,
CompanyId: companyId,
Uid: uid,
PartnerCategory: param.Where.PartnerCategory,
PartnerCategoryName: param.Where.PartnerCategoryName,
UpdateTimeBegin: updateTimeBegin,
UpdateTimeEnd: updateTimeEnd,
CreateTimeBegin: createTimeBegin,
CreateTimeEnd: createTimeEnd,
SaleDateBegin: saleDateBegin,
SaleDateEnd: saleDateEnd,
})
if err != nil {
c.ResponseError(err)
... ... @@ -627,8 +712,8 @@ func (c *OrderInfoController) ListOrderForExcel() {
}
excelMaker := exceltool.NewExcelMaker()
excelMaker.SetListHead(excelHeaders)
excelMaker.MakeListExcel(orderinfos)
c.ResponseExcelByFile(c.Ctx, excelMaker)
_ = excelMaker.MakeListExcel(orderInfos)
_ = c.ResponseExcelByFile(c.Ctx, excelMaker)
return
}
... ... @@ -667,7 +752,7 @@ func (c *OrderInfoController) DownloadTemplate() {
}
// 获取导入模板
req := httplib.Get("http://suplus-file-dev.fjmaimaimai.com/upload/file/2021010803305336443.xlsx")
req := httplib.Get("http://suplus-file-dev.fjmaimaimai.com/upload/file/2021020111293523855.xlsx")
err = req.ToFile(constant.IMPORT_EXCEL)
if err != nil {
logs.Error("could not save to file: ", err)
... ... @@ -682,7 +767,7 @@ func (c *OrderInfoController) DownloadTemplate() {
} else {
logs.Info(resp)
ret = map[string]interface{}{
"url": "http://" + c.Ctx.Request.Host + "/mmm-partnermg/download/订单数据模板.xlsx",
"url": "https://" + c.Ctx.Request.Host + "/" + constant.APP_NAME + "/download/订单数据模板.xlsx",
}
c.ResponseData(ret)
}
... ... @@ -708,8 +793,8 @@ func (c *OrderInfoController) ImportOrderFromExcel() {
// 返回字段定义
ret := map[string]interface{}{}
// 返回信息表头定义 0: 订单号, 1: 发货单号, 2: 客户名称, 3: 订单区域, 4: 编号, 5: 合伙人, 6: 类型, 7: 业务员抽成比例, 8: 产品名称, 9: 数量, 10: 单价, 11: 合伙人分红比例
var tableHeader = []string{"错误详情", "行号", "订单号", "发货单号", "客户名称", "订单区域", "编号", "合伙人", "类型", "业务员抽成比例", "产品名称", "数量", "单价", "合伙人分红比例"}
// 返回信息表头定义 0: 订单号, 1: 发货单号, 2: 客户名称, 3: 订单区域, 4: 销售日期, 5: 编号, 6: 合伙人, 7: 类型, 8: 业务员抽成比例, 9: 产品名称, 10: 数量, 11: 单价, 12: 合伙人分红比例
var tableHeader = []string{"错误详情", "行号", "订单号", "发货单号", "客户名称", "订单区域", "销售日期", "编号", "合伙人", "类型", "业务员抽成比例", "产品名称", "数量", "单价", "合伙人分红比例"}
// 文件后缀名校验
ext := path.Ext(h.Filename)
... ... @@ -781,7 +866,7 @@ func (c *OrderInfoController) ImportOrderFromExcel() {
nullCell := make([]interface{}, 0)
var myRow []string
for j, _ := range row {
if j != 7 { // 业务员抽成比例非必填
if j != 8 { // 业务员抽成比例非必填
if row[j] == "" || row[j] == " " { // 空字符补位
tmpRow[j] = ""
col := strconv.Itoa(j + 1)
... ... @@ -847,7 +932,7 @@ func (c *OrderInfoController) ImportOrderFromExcel() {
col := strconv.Itoa(j + 1)
switch j {
case 0, 1, 2, 3, 4, 5, 8: // 订单号、发货单号、客户名称、订单区域、编号、合伙人、产品名称长度校验
case 0, 1, 2, 3, 5, 6, 9: // 订单号、发货单号、客户名称、订单区域、编号、合伙人、产品名称长度校验
{
cellStr := strings.TrimSpace(cell)
lenCellStr := utf8.RuneCountInString(cellStr)
... ... @@ -860,7 +945,19 @@ func (c *OrderInfoController) ImportOrderFromExcel() {
myRow = tmpRow
}
}
case 6: // 合伙人类型校验(事业合伙、业务合伙、研发合伙、业务-产品应用合伙)
case 4: // 销售日期格式和有效性校验
{
regexpStr := `(\d{4})/(\d{2})/(\d{2})`
ok := regexp.MustCompile(regexpStr).MatchString(cell)
if !ok {
var tmpRow []string
tmpRow = append(tmpRow, "第"+r+"行第"+col+"列销售日期格式错误,请输入正确的销售日期") // 错误信息
tmpRow = append(tmpRow, r) // 行号
tmpRow = append(tmpRow, row...) // 错误行数据
myRow = tmpRow
}
}
case 7: // 合伙人类型校验(事业合伙、业务合伙、研发合伙、业务-产品应用合伙)
{
if !utils.IsContain(partnerType, cell) {
var tmpRow []string
... ... @@ -870,7 +967,7 @@ func (c *OrderInfoController) ImportOrderFromExcel() {
myRow = tmpRow
}
}
case 7: // 业务员抽成比例,非必填,精确到小数点后两位
case 8: // 业务员抽成比例,非必填,精确到小数点后两位
{
if len(cell) > 0 {
... ... @@ -905,7 +1002,7 @@ func (c *OrderInfoController) ImportOrderFromExcel() {
}
}
}
case 9: // 数量不超过16位正整数
case 10: // 产品数量不超过16位正整数
{
//参数类型转换
orderNum, err := strconv.ParseInt(cell, 10, 64)
... ... @@ -926,7 +1023,7 @@ func (c *OrderInfoController) ImportOrderFromExcel() {
myRow = tmpRow
}
}
case 10: // 单价,精确到小数点后两位,小数点左侧最多可输入16位数字
case 11: // 单价,精确到小数点后两位,小数点左侧最多可输入16位数字
{
// 参数类型转换
... ... @@ -948,7 +1045,7 @@ func (c *OrderInfoController) ImportOrderFromExcel() {
myRow = tmpRow
}
}
case 11: // 合伙人分红比例,精确到小数点后两位
case 12: // 合伙人分红比例,精确到小数点后两位
{
//参数类型转换
partnerRatio, parseErr := strconv.ParseFloat(cell, 64)
... ... @@ -1011,29 +1108,30 @@ func (c *OrderInfoController) ImportOrderFromExcel() {
var orderCommands = make(map[string]*orderCmd.CreateOrderCommand, 0)
for i, row := range rows {
if i > 2 && len(row) == constant.EXCEL_COLUMN {
hashValue := md5.Sum([]byte(row[0] + row[1] + row[4] + row[6])) // 根据:订单号+发货单号+合伙人编号+合伙类型计算哈希值
hashValue := md5.Sum([]byte(row[0] + row[1] + row[5] + row[7])) // 根据:订单号+发货单号+合伙人编号+合伙类型计算哈希值
hashString := hex.EncodeToString(hashValue[:])
if _, ok := orderCommands[hashString]; !ok {
//订单相关,0: 订单号, 1: 发货单号, 2: 客户名称, 3: 订单区域, 4: 编号, 5: 合伙人, 6: 类型, 7: 业务抽成比例,
sbPercent, _ := strconv.ParseFloat(row[7], 64) //业务抽成比例
//订单相关,0: 订单号, 1: 发货单号, 2: 客户名称, 3: 订单区域, 4: 销售日期, 5: 编号, 6: 合伙人, 7: 类型, 8: 业务抽成比例,
sbPercent, _ := strconv.ParseFloat(row[8], 64) //业务抽成比例
//产品相关,8: 产品名称, 9: 数量, 10: 单价, 11: 合伙人分红比例
amount, _ := strconv.ParseInt(row[9], 10, 64) // 数量
price, _ := strconv.ParseFloat(row[10], 64) // 单价
percent, _ := strconv.ParseFloat(row[11], 64) // 合伙人分红比例
//产品相关,9: 产品名称, 10: 数量, 11: 单价, 12: 合伙人分红比例
amount, _ := strconv.ParseInt(row[10], 10, 64) // 数量
price, _ := strconv.ParseFloat(row[11], 64) // 单价
percent, _ := strconv.ParseFloat(row[12], 64) // 合伙人分红比例
// 获取partnerId
var partnerInfo *domain.PartnerInfo
// 5: 合伙人编号
orderQueryData := orderQuery.GetPartnerIdQuery{
Code: row[4],
Code: row[5],
PartnerCategory: 0,
CompanyId: companyId,
}
// 1: 事业合伙、2: 业务合伙、3: 研发合伙、4: 业务-产品应用合伙
switch row[6] {
// 7: 合伙人类型 1: 事业合伙、2: 业务合伙、3: 研发合伙、4: 业务-产品应用合伙
switch row[7] {
case "事业合伙":
orderQueryData.PartnerCategory = 1
case "业务合伙":
... ... @@ -1046,6 +1144,22 @@ func (c *OrderInfoController) ImportOrderFromExcel() {
orderQueryData.PartnerCategory = 0
}
// 销售日期时间格式转换
timeValue, err := time.ParseInLocation("2006/01/02", row[4], time.Local)
if err != nil {
var tmpRow []string
tmpRow = append(tmpRow, "无效的销售日期") // 错误信息
s := strconv.Itoa(i + 1)
tmpRow = append(tmpRow, s) // 行号
tmpRow = append(tmpRow, row...) // 错误行数据
partnerDataList = append(partnerDataList, tmpRow)
break
}
saleDateWithTz := time.Date(timeValue.Year(), timeValue.Month(), timeValue.Day(), time.Now().Hour(), time.Now().Minute(), time.Now().Second(), time.Now().Nanosecond(), time.Local)
fmt.Print("销售日期:", saleDateWithTz, "\n")
// 初始化建订单命令集
orderCommands[hashString] = &orderCmd.CreateOrderCommand{
OrderType: 0,
... ... @@ -1053,11 +1167,12 @@ func (c *OrderInfoController) ImportOrderFromExcel() {
DeliveryCode: row[1],
BuyerName: row[2],
OrderRegion: row[3],
SaleDate: saleDateWithTz,
PartnerId: 0, // 根据合伙人类型+合伙人编号查找合伙人id
SalesmanBonusPercent: sbPercent,
Goods: []orderCmd.OrderGoodData{
{
GoodName: row[8],
GoodName: row[9],
PlanGoodNumber: int(amount),
Price: price,
PartnerBonusPercent: percent,
... ... @@ -1082,14 +1197,14 @@ func (c *OrderInfoController) ImportOrderFromExcel() {
orderCommands[hashString].PartnerId = partnerInfo.Partner.Id
}
} else {
//产品相关,8: 产品名称, 9: 数量, 10: 单价, 11: 合伙人分红比例
amount, _ := strconv.ParseInt(row[9], 10, 64) // 数量
price, _ := strconv.ParseFloat(row[10], 64) // 单价
percent, _ := strconv.ParseFloat(row[11], 64) // 合伙人分红比例
//产品相关,9: 产品名称, 10: 数量, 11: 单价, 12: 合伙人分红比例
amount, _ := strconv.ParseInt(row[10], 10, 64) // 数量
price, _ := strconv.ParseFloat(row[11], 64) // 单价
percent, _ := strconv.ParseFloat(row[12], 64) // 合伙人分红比例
// 记录同一笔订单产品
orderCommands[hashString].Goods = append(orderCommands[hashString].Goods, orderCmd.OrderGoodData{
GoodName: row[8],
GoodName: row[9],
PlanGoodNumber: int(amount),
Price: price,
PartnerBonusPercent: percent,
... ...
package routers
import (
"github.com/astaxie/beego"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/port/beego/controllers"
)
func init() {
beego.Router("/column-settings/", &controllers.ColumnSettingController{}, "Post:CreateColumnSetting")
beego.Router("/column-settings/:columnSettingId", &controllers.ColumnSettingController{}, "Put:UpdateColumnSetting")
beego.Router("/column-settings/:columnSettingId", &controllers.ColumnSettingController{}, "Get:GetColumnSetting")
beego.Router("/column-settings/:columnSettingId", &controllers.ColumnSettingController{}, "Delete:RemoveColumnSetting")
beego.Router("/column-settings/", &controllers.ColumnSettingController{}, "Post:ResetColumn")
beego.Router("/column-settings/", &controllers.ColumnSettingController{}, "Get:ListColumnSetting")
}
... ...
... ... @@ -41,8 +41,13 @@ func init() {
beego.NSRouter("/actual/del", &controllers.OrderInfoController{}, "POST:RemoveOrderReal"), // 删除实际订单
beego.NSRouter("/actual/update", &controllers.OrderInfoController{}, "POST:UpdateOrderReal"), // 新增实际订单
beego.NSRouter("/actual/close", &controllers.OrderInfoController{}, "POST:OrderDisable"),
beego.NSRouter("/fileImportTemplate", &controllers.OrderInfoController{}, "POST:DownloadTemplate"), // 下载导入模板
beego.NSRouter("/fileImport", &controllers.OrderInfoController{}, "POST:ImportOrderFromExcel"), // 导入订单数据
beego.NSRouter("/fileImportTemplate", &controllers.OrderInfoController{}, "POST:DownloadTemplate"), // 下载导入模板
beego.NSRouter("/fileImport", &controllers.OrderInfoController{}, "POST:ImportOrderFromExcel"), // 导入订单数据
beego.NSRouter("/actual/listColumn", &controllers.ColumnSettingController{}, "POST:GetColumnSetting"), // 返回栏目设置列表
beego.NSRouter("/actual/updateColumn", &controllers.ColumnSettingController{}, "POST:UpdateColumnSetting"), // 更新栏目设置
beego.NSRouter("/actual/resetColumn", &controllers.ColumnSettingController{}, "POST:ResetColumn"), // 重置栏目设置
beego.NSRouter("/actual/createColumn", &controllers.ColumnSettingController{}, "POST:CreateColumnSetting"), // 创建栏目设置,测试用
beego.NSRouter("/actual/listDefaultColumn", &controllers.ColumnSettingController{}, "POST:ListDefaultColumnSetting"), // 返回默认栏目设置
),
beego.NSNamespace("/common",
beego.NSRouter("/partner", &controllers.CommonController{}, "POST:GetPartnerList"),
... ...
package column_setting
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/astaxie/beego"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
_ "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg"
_ "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/port/beego"
)
func TestColumnSetting(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Beego Port ColumnSetting Correlations Test Case Suite")
}
var handler http.Handler
var server *httptest.Server
var _ = BeforeSuite(func() {
handler = beego.BeeApp.Handlers
server = httptest.NewServer(handler)
})
var _ = AfterSuite(func() {
server.Close()
})
... ...
package column_setting
import (
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg"
)
var _ = Describe("创建栏目设置增删改查", func() {
Describe("提交数据创建栏目设置增删改查", func() {
Context("提交正确的新栏目设置数据", func() {
It("返回栏目设置数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"description": "string",
"userName": "string",
}
httpExpect.POST("/column-settings/").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object().
ContainsKey("id").ValueNotEqual("id", BeZero())
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM column_settings WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package column_setting
import (
"net/http"
"github.com/gavv/httpexpect"
"github.com/go-pg/pg"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg"
)
var _ = Describe("返回栏目设置增删改查", func() {
var column_settingId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&column_settingId),
"INSERT INTO column_settings (column_setting_id, company_id, created_at, description, key, uid, updated_at, user_name, value) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id",
"testColumnSettingId", "testCompanyId", "testCreatedAt", "testDescription", "testKey", "testUid", "testUpdatedAt", "testUserName", "testValue")
Expect(err).NotTo(HaveOccurred())
})
Describe("根据column_settingId参数返回栏目设置", func() {
Context("传入有效的column_settingId", func() {
It("返回栏目设置数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.GET("/column-settings/{columnSettingId}").
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM column_settings WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package column_setting
import (
"net/http"
"github.com/gavv/httpexpect"
"github.com/go-pg/pg"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg"
)
var _ = Describe("返回栏目设置增删改查列表", func() {
var column_settingId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&column_settingId),
"INSERT INTO column_settings (column_setting_id, company_id, created_at, description, key, uid, updated_at, user_name, value) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id",
"testColumnSettingId", "testCompanyId", "testCreatedAt", "testDescription", "testKey", "testUid", "testUpdatedAt", "testUserName", "testValue")
Expect(err).NotTo(HaveOccurred())
})
Describe("根据参数返回栏目设置列表", func() {
Context("传入有效的参数", func() {
It("返回栏目设置数据列表", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.GET("/column-settings/").
WithQuery("offset", "int").
WithQuery("limit", "int").
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object().
ContainsKey("count").ValueEqual("count", 1).
ContainsKey("column_settings").Value("column_settings").Array()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM column_settings WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package column_setting
import (
"net/http"
"github.com/gavv/httpexpect"
"github.com/go-pg/pg"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg"
)
var _ = Describe("移除栏目设置增删改查", func() {
var column_settingId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&column_settingId),
"INSERT INTO column_settings (column_setting_id, company_id, created_at, description, key, uid, updated_at, user_name, value) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id",
"testColumnSettingId", "testCompanyId", "testCreatedAt", "testDescription", "testKey", "testUid", "testUpdatedAt", "testUserName", "testValue")
Expect(err).NotTo(HaveOccurred())
})
Describe("根据参数移除栏目设置增删改查", func() {
Context("传入有效的column_settingId", func() {
It("返回被移除栏目设置的数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.DELETE("/column-settings/{columnSettingId}").
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM column_settings WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package column_setting
import (
"net/http"
"github.com/gavv/httpexpect"
"github.com/go-pg/pg"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg"
)
var _ = Describe("重置栏目设置", func() {
var column_settingId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&column_settingId),
"INSERT INTO column_settings (column_setting_id, company_id, created_at, description, key, uid, updated_at, user_name, value) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id",
"testColumnSettingId", "testCompanyId", "testCreatedAt", "testDescription", "testKey", "testUid", "testUpdatedAt", "testUserName", "testValue")
Expect(err).NotTo(HaveOccurred())
})
Describe("重置栏目设置", func() {
Context("", func() {
It("", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{}
httpExpect.POST("/column-settings/").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM column_settings WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package column_setting
import (
"net/http"
"github.com/gavv/httpexpect"
"github.com/go-pg/pg"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg"
)
var _ = Describe("更新栏目设置增删改查", func() {
var column_settingId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&column_settingId),
"INSERT INTO column_settings (column_setting_id, company_id, created_at, description, key, uid, updated_at, user_name, value) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id",
"testColumnSettingId", "testCompanyId", "testCreatedAt", "testDescription", "testKey", "testUid", "testUpdatedAt", "testUserName", "testValue")
Expect(err).NotTo(HaveOccurred())
})
Describe("提交数据更新栏目设置增删改查", func() {
Context("提交正确的栏目设置数据", func() {
It("返回更新后的栏目设置数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{}
httpExpect.PUT("/column-settings/{columnSettingId}").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object().
ContainsKey("id").ValueEqual("id", column_settingId)
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM column_settings WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
validation
==============
validation is a form validation for a data validation and error collecting using Go.
## Installation and tests
Install:
go get github.com/astaxie/beego/validation
Test:
go test github.com/astaxie/beego/validation
## Example
Direct Use:
import (
"github.com/astaxie/beego/validation"
"log"
)
type User struct {
Name string
Age int
}
func main() {
u := User{"man", 40}
valid := validation.Validation{}
valid.Required(u.Name, "name")
valid.MaxSize(u.Name, 15, "nameMax")
valid.Range(u.Age, 0, 140, "age")
if valid.HasErrors() {
// validation does not pass
// print invalid message
for _, err := range valid.Errors {
log.Println(err.Key, err.Message)
}
}
// or use like this
if v := valid.Max(u.Age, 140, "ageMax"); !v.Ok {
log.Println(v.Error.Key, v.Error.Message)
}
}
Struct Tag Use:
import (
"github.com/astaxie/beego/validation"
)
// validation function follow with "valid" tag
// functions divide with ";"
// parameters in parentheses "()" and divide with ","
// Match function's pattern string must in "//"
type user struct {
Id int
Name string `valid:"Required;Match(/^(test)?\\w*@;com$/)"`
Age int `valid:"Required;Range(1, 140)"`
}
func main() {
valid := validation.Validation{}
// ignore empty field valid
// see CanSkipFuncs
// valid := validation.Validation{RequiredFirst:true}
u := user{Name: "test", Age: 40}
b, err := valid.Valid(u)
if err != nil {
// handle error
}
if !b {
// validation does not pass
// blabla...
}
}
Use custom function:
import (
"github.com/astaxie/beego/validation"
)
type user struct {
Id int
Name string `valid:"Required;IsMe"`
Age int `valid:"Required;Range(1, 140)"`
}
func IsMe(v *validation.Validation, obj interface{}, key string) {
name, ok:= obj.(string)
if !ok {
// wrong use case?
return
}
if name != "me" {
// valid false
v.SetError("Name", "is not me!")
}
}
func main() {
valid := validation.Validation{}
if err := validation.AddCustomFunc("IsMe", IsMe); err != nil {
// hadle error
}
u := user{Name: "test", Age: 40}
b, err := valid.Valid(u)
if err != nil {
// handle error
}
if !b {
// validation does not pass
// blabla...
}
}
Struct Tag Functions:
Required
Min(min int)
Max(max int)
Range(min, max int)
MinSize(min int)
MaxSize(max int)
Length(length int)
Alpha
Numeric
AlphaNumeric
Match(pattern string)
AlphaDash
Email
IP
Base64
Mobile
Tel
Phone
ZipCode
## LICENSE
BSD License http://creativecommons.org/licenses/BSD/
... ...