作者 Administrator

合并分支 'dev' 到 'master'

Dev



查看合并请求 !4
正在显示 127 个修改的文件 包含 5728 行增加141 行删除
@@ -6,6 +6,8 @@ @@ -6,6 +6,8 @@
6 # Folders 6 # Folders
7 _obj 7 _obj
8 _test 8 _test
  9 +public/file
  10 +logs
9 11
10 # Architecture specific extensions/prefixes 12 # Architecture specific extensions/prefixes
11 *.[568vq] 13 *.[568vq]
@@ -23,3 +25,4 @@ _testmain.go @@ -23,3 +25,4 @@ _testmain.go
23 *.test 25 *.test
24 .log 26 .log
25 .idea 27 .idea
  28 +
1 -FROM golang:latest  
2 -MAINTAINER linmadan <772181827@qq.com> 1 +FROM 192.168.0.243:5000/mmm/mmm-worth:20201122
  2 +#FROM golang:latest
  3 +#MAINTAINER linmadan <772181827@qq.com>
3 ENV APP_DIR $GOPATH/src/mmm-worth 4 ENV APP_DIR $GOPATH/src/mmm-worth
4 RUN mkdir -p $APP_DIR 5 RUN mkdir -p $APP_DIR
5 WORKDIR $APP_DIR/ 6 WORKDIR $APP_DIR/
@@ -10,6 +11,6 @@ COPY ./main.go main.go @@ -10,6 +11,6 @@ COPY ./main.go main.go
10 RUN ["ln","-sf","/usr/share/zoneinfo/Asia/Shanghai","/etc/localtime"] 11 RUN ["ln","-sf","/usr/share/zoneinfo/Asia/Shanghai","/etc/localtime"]
11 ENV GO111MODULE on 12 ENV GO111MODULE on
12 ENV GOPROXY https://goproxy.io 13 ENV GOPROXY https://goproxy.io
13 -RUN ["go","mod","tidy"] 14 +#RUN ["go","mod","tidy"]
14 RUN ["go","build"] 15 RUN ["go","build"]
15 ENTRYPOINT ["./mmm-worth"] 16 ENTRYPOINT ["./mmm-worth"]
@@ -39,9 +39,6 @@ spec: @@ -39,9 +39,6 @@ spec:
39 operator: In 39 operator: In
40 values: 40 values:
41 - cn-hangzhou.i-bp1djh1xn7taumbue1ze 41 - cn-hangzhou.i-bp1djh1xn7taumbue1ze
42 - - cn-hangzhou.i-bp1djh1xn7taumbue1zd  
43 - - cn-hangzhou.i-bp1euf5u1ph9kbhtndhb  
44 - - cn-hangzhou.i-bp1hyp5oips9cdwxxgxy  
45 containers: 42 containers:
46 - name: mmm-worth 43 - name: mmm-worth
47 image: 192.168.0.243:5000/mmm/mmm-worth:dev 44 image: 192.168.0.243:5000/mmm/mmm-worth:dev
@@ -57,11 +54,11 @@ spec: @@ -57,11 +54,11 @@ spec:
57 - name: POSTGRESQL_USER 54 - name: POSTGRESQL_USER
58 value: "postgres" 55 value: "postgres"
59 - name: POSTGRESQL_PASSWORD 56 - name: POSTGRESQL_PASSWORD
60 - value: "postgres_15432" 57 + value: "eagle1010"
61 - name: POSTGRESQL_HOST 58 - name: POSTGRESQL_HOST
62 - value: "101.37.68.23" 59 + value: "114.55.200.59"
63 - name: POSTGRESQL_PORT 60 - name: POSTGRESQL_PORT
64 - value: "15432" 61 + value: "31543"
65 - name: LOG_LEVEL 62 - name: LOG_LEVEL
66 value: "debug" 63 value: "debug"
67 - name: ERROR_BASE_CODE 64 - name: ERROR_BASE_CODE
@@ -39,9 +39,6 @@ spec: @@ -39,9 +39,6 @@ spec:
39 operator: In 39 operator: In
40 values: 40 values:
41 - cn-hangzhou.i-bp1djh1xn7taumbue1ze 41 - cn-hangzhou.i-bp1djh1xn7taumbue1ze
42 - - cn-hangzhou.i-bp1djh1xn7taumbue1zd  
43 - - cn-hangzhou.i-bp1euf5u1ph9kbhtndhb  
44 - - cn-hangzhou.i-bp1hyp5oips9cdwxxgxy  
45 containers: 42 containers:
46 - name: mmm-worth 43 - name: mmm-worth
47 image: 192.168.0.243:5000/mmm/mmm-worth:test 44 image: 192.168.0.243:5000/mmm/mmm-worth:test
@@ -57,11 +54,11 @@ spec: @@ -57,11 +54,11 @@ spec:
57 - name: POSTGRESQL_USER 54 - name: POSTGRESQL_USER
58 value: "postgres" 55 value: "postgres"
59 - name: POSTGRESQL_PASSWORD 56 - name: POSTGRESQL_PASSWORD
60 - value: "postgres_15432" 57 + value: "eagle1010"
61 - name: POSTGRESQL_HOST 58 - name: POSTGRESQL_HOST
62 - value: "101.37.68.23" 59 + value: "114.55.200.59"
63 - name: POSTGRESQL_PORT 60 - name: POSTGRESQL_PORT
64 - value: "15432" 61 + value: "31543"
65 - name: LOG_LEVEL 62 - name: LOG_LEVEL
66 value: "debug" 63 value: "debug"
67 - name: ERROR_BASE_CODE 64 - name: ERROR_BASE_CODE
@@ -3,6 +3,7 @@ module gitlab.fjmaimaimai.com/linmadan/mmm-worth @@ -3,6 +3,7 @@ module gitlab.fjmaimaimai.com/linmadan/mmm-worth
3 go 1.14 3 go 1.14
4 4
5 require ( 5 require (
  6 + github.com/360EntSecGroup-Skylar/excelize/v2 v2.3.1
6 github.com/ajg/form v1.5.1 // indirect 7 github.com/ajg/form v1.5.1 // indirect
7 github.com/astaxie/beego v1.12.1 8 github.com/astaxie/beego v1.12.1
8 github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072 // indirect 9 github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072 // indirect
@@ -13,13 +14,14 @@ require ( @@ -13,13 +14,14 @@ require (
13 github.com/gorilla/websocket v1.4.2 // indirect 14 github.com/gorilla/websocket v1.4.2 // indirect
14 github.com/imkira/go-interpol v1.1.0 // indirect 15 github.com/imkira/go-interpol v1.1.0 // indirect
15 github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88 // indirect 16 github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88 // indirect
16 - github.com/linmadan/egglib-go v0.0.0-20191217144343-ca4539f95bf9 17 + github.com/linmadan/egglib-go v0.0.0-20201125083542-25358a549edb
17 github.com/mattn/go-colorable v0.1.6 // indirect 18 github.com/mattn/go-colorable v0.1.6 // indirect
18 github.com/moul/http2curl v1.0.0 // indirect 19 github.com/moul/http2curl v1.0.0 // indirect
19 github.com/onsi/ginkgo v1.10.3 20 github.com/onsi/ginkgo v1.10.3
20 github.com/onsi/gomega v1.7.1 21 github.com/onsi/gomega v1.7.1
21 github.com/sergi/go-diff v1.1.0 // indirect 22 github.com/sergi/go-diff v1.1.0 // indirect
22 github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644 // indirect 23 github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644 // indirect
  24 + github.com/shopspring/decimal v1.2.0
23 github.com/smartystreets/goconvey v1.6.4 // indirect 25 github.com/smartystreets/goconvey v1.6.4 // indirect
24 github.com/valyala/fasthttp v1.9.0 // indirect 26 github.com/valyala/fasthttp v1.9.0 // indirect
25 github.com/xeipuuv/gojsonschema v1.2.0 // indirect 27 github.com/xeipuuv/gojsonschema v1.2.0 // indirect
@@ -27,6 +29,7 @@ require ( @@ -27,6 +29,7 @@ require (
27 github.com/yudai/gojsondiff v1.0.0 // indirect 29 github.com/yudai/gojsondiff v1.0.0 // indirect
28 github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 // indirect 30 github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 // indirect
29 github.com/yudai/pp v2.0.1+incompatible // indirect 31 github.com/yudai/pp v2.0.1+incompatible // indirect
  32 + golang.org/x/tools v0.0.0-20200117065230-39095c1d176c
30 ) 33 )
31 34
32 replace gitlab.fjmaimaimai.com/linmadan/mmm-worth => ../mmm-worth 35 replace gitlab.fjmaimaimai.com/linmadan/mmm-worth => ../mmm-worth
  1 +github.com/360EntSecGroup-Skylar/excelize/v2 v2.3.1 h1:j56fC19WoD3z+u+ZHxm2XwRGyS1XmdSMk7058BLhdsM=
  2 +github.com/360EntSecGroup-Skylar/excelize/v2 v2.3.1/go.mod h1:gXEhMjm1VadSGjAzyDlBxmdYglP8eJpYWxpwJnmXRWw=
1 github.com/DataDog/zstd v1.3.6-0.20190409195224-796139022798/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo= 3 github.com/DataDog/zstd v1.3.6-0.20190409195224-796139022798/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo=
2 github.com/Knetic/govaluate v3.0.0+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0= 4 github.com/Knetic/govaluate v3.0.0+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
3 github.com/OwnLocal/goes v1.0.0/go.mod h1:8rIFjBGTue3lCU0wplczcUgt9Gxgrkkrw7etMIcn8TM= 5 github.com/OwnLocal/goes v1.0.0/go.mod h1:8rIFjBGTue3lCU0wplczcUgt9Gxgrkkrw7etMIcn8TM=
@@ -79,11 +81,15 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= @@ -79,11 +81,15 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
79 github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= 81 github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
80 github.com/linmadan/egglib-go v0.0.0-20191217144343-ca4539f95bf9 h1:zJZsqJ1wFMYb2yrja5S3OZ+oASx4irRksZ8+emFs56M= 82 github.com/linmadan/egglib-go v0.0.0-20191217144343-ca4539f95bf9 h1:zJZsqJ1wFMYb2yrja5S3OZ+oASx4irRksZ8+emFs56M=
81 github.com/linmadan/egglib-go v0.0.0-20191217144343-ca4539f95bf9/go.mod h1:S1zYn9bb6h+Qzu1aOO8raFhHniewOBaif3YvA9qA6lk= 83 github.com/linmadan/egglib-go v0.0.0-20191217144343-ca4539f95bf9/go.mod h1:S1zYn9bb6h+Qzu1aOO8raFhHniewOBaif3YvA9qA6lk=
  84 +github.com/linmadan/egglib-go v0.0.0-20201125083542-25358a549edb h1:Ocxw5BWyRrRkTHSsTmQx0UnGsAYZDOwa3K9oGlXF8Jo=
  85 +github.com/linmadan/egglib-go v0.0.0-20201125083542-25358a549edb/go.mod h1:S1zYn9bb6h+Qzu1aOO8raFhHniewOBaif3YvA9qA6lk=
82 github.com/mattn/go-colorable v0.1.6 h1:6Su7aK7lXmJ/U79bYtBjLNaha4Fs1Rg9plHpcH+vvnE= 86 github.com/mattn/go-colorable v0.1.6 h1:6Su7aK7lXmJ/U79bYtBjLNaha4Fs1Rg9plHpcH+vvnE=
83 github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= 87 github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
84 github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= 88 github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
85 github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= 89 github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
86 github.com/mattn/go-sqlite3 v1.10.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc= 90 github.com/mattn/go-sqlite3 v1.10.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
  91 +github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw=
  92 +github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
87 github.com/moul/http2curl v1.0.0 h1:dRMWoAtb+ePxMlLkrCbAqh4TlPHXvoGUSQ323/9Zahs= 93 github.com/moul/http2curl v1.0.0 h1:dRMWoAtb+ePxMlLkrCbAqh4TlPHXvoGUSQ323/9Zahs=
88 github.com/moul/http2curl v1.0.0/go.mod h1:8UbvGypXm98wA/IqH45anm5Y2Z6ep6O31QGOAZ3H0fQ= 94 github.com/moul/http2curl v1.0.0/go.mod h1:8UbvGypXm98wA/IqH45anm5Y2Z6ep6O31QGOAZ3H0fQ=
89 github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= 95 github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
@@ -98,10 +104,16 @@ github.com/pkg/profile v1.2.1/go.mod h1:hJw3o1OdXxsrSjjVksARp5W95eeEaEfptyVZyv6J @@ -98,10 +104,16 @@ github.com/pkg/profile v1.2.1/go.mod h1:hJw3o1OdXxsrSjjVksARp5W95eeEaEfptyVZyv6J
98 github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 104 github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
99 github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 105 github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
100 github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= 106 github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
  107 +github.com/richardlehane/mscfb v1.0.3 h1:rD8TBkYWkObWO0oLDFCbwMeZ4KoalxQy+QgniCj3nKI=
  108 +github.com/richardlehane/mscfb v1.0.3/go.mod h1:YzVpcZg9czvAuhk9T+a3avCpcFPMUWm7gK3DypaEsUk=
  109 +github.com/richardlehane/msoleps v1.0.1 h1:RfrALnSNXzmXLbGct/P2b4xkFz4e8Gmj/0Vj9M9xC1o=
  110 +github.com/richardlehane/msoleps v1.0.1/go.mod h1:BWev5JBpU9Ko2WAgmZEuiz4/u3ZYTKbjLycmwiWUfWg=
101 github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0= 111 github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
102 github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= 112 github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
103 github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644 h1:X+yvsM2yrEktyI+b2qND5gpH8YhURn0k8OCaeRnkINo= 113 github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644 h1:X+yvsM2yrEktyI+b2qND5gpH8YhURn0k8OCaeRnkINo=
104 github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644/go.mod h1:nkxAfR/5quYxwPZhyDxgasBMnRtBZd0FCEpawpjMUFg= 114 github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644/go.mod h1:nkxAfR/5quYxwPZhyDxgasBMnRtBZd0FCEpawpjMUFg=
  115 +github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXYbsQ=
  116 +github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
105 github.com/siddontang/go v0.0.0-20180604090527-bdc77568d726/go.mod h1:3yhqj7WBBfRhbBlzyOC3gUxftwsU0u8gqevxwIHQpMw= 117 github.com/siddontang/go v0.0.0-20180604090527-bdc77568d726/go.mod h1:3yhqj7WBBfRhbBlzyOC3gUxftwsU0u8gqevxwIHQpMw=
106 github.com/siddontang/ledisdb v0.0.0-20181029004158-becf5f38d373/go.mod h1:mF1DpOSOUiJRMR+FDqaqu3EBqrybQtrDDszLUZ6oxPg= 118 github.com/siddontang/ledisdb v0.0.0-20181029004158-becf5f38d373/go.mod h1:mF1DpOSOUiJRMR+FDqaqu3EBqrybQtrDDszLUZ6oxPg=
107 github.com/siddontang/rdb v0.0.0-20150307021120-fc89ed2e418d/go.mod h1:AMEsy7v5z92TR1JKMkLLoaOQk++LVnOKL3ScbJ8GNGA= 119 github.com/siddontang/rdb v0.0.0-20150307021120-fc89ed2e418d/go.mod h1:AMEsy7v5z92TR1JKMkLLoaOQk++LVnOKL3ScbJ8GNGA=
@@ -119,6 +131,8 @@ github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0 @@ -119,6 +131,8 @@ github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0
119 github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= 131 github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
120 github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= 132 github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
121 github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= 133 github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
  134 +github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
  135 +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
122 github.com/syndtr/goleveldb v0.0.0-20181127023241-353a9fca669c/go.mod h1:Z4AUp2Km+PwemOoO/VB5AOx9XSsIItzFjoJlOSiYmn0= 136 github.com/syndtr/goleveldb v0.0.0-20181127023241-353a9fca669c/go.mod h1:Z4AUp2Km+PwemOoO/VB5AOx9XSsIItzFjoJlOSiYmn0=
123 github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= 137 github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
124 github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= 138 github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
@@ -134,6 +148,8 @@ github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 h1:EzJWgHo @@ -134,6 +148,8 @@ github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 h1:EzJWgHo
134 github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ= 148 github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ=
135 github.com/xeipuuv/gojsonschema v1.2.0 h1:LhYJRs+L4fBtjZUfuSZIKGeVu0QRy8e5Xi7D17UxZ74= 149 github.com/xeipuuv/gojsonschema v1.2.0 h1:LhYJRs+L4fBtjZUfuSZIKGeVu0QRy8e5Xi7D17UxZ74=
136 github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y= 150 github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y=
  151 +github.com/xuri/efp v0.0.0-20200605144744-ba689101faaf h1:spotWVWg9DP470pPFQ7LaYtUqDpWEOS/BUrSmwFZE4k=
  152 +github.com/xuri/efp v0.0.0-20200605144744-ba689101faaf/go.mod h1:uBiSUepVYMhGTfDeBKKasV4GpgBlzJ46gXUBAqV8qLk=
137 github.com/yalp/jsonpath v0.0.0-20180802001716-5cc68e5049a0 h1:6fRhSjgLCkTD3JnJxvaJ4Sj+TYblw757bqYgZaOq5ZY= 153 github.com/yalp/jsonpath v0.0.0-20180802001716-5cc68e5049a0 h1:6fRhSjgLCkTD3JnJxvaJ4Sj+TYblw757bqYgZaOq5ZY=
138 github.com/yalp/jsonpath v0.0.0-20180802001716-5cc68e5049a0/go.mod h1:/LWChgwKmvncFJFHJ7Gvn9wZArjbV5/FppcK2fKk/tI= 154 github.com/yalp/jsonpath v0.0.0-20180802001716-5cc68e5049a0/go.mod h1:/LWChgwKmvncFJFHJ7Gvn9wZArjbV5/FppcK2fKk/tI=
139 github.com/yudai/gojsondiff v1.0.0 h1:27cbfqXLVEJ1o8I6v3y9lg8Ydm53EKqHXAOMxEGlCOA= 155 github.com/yudai/gojsondiff v1.0.0 h1:27cbfqXLVEJ1o8I6v3y9lg8Ydm53EKqHXAOMxEGlCOA=
@@ -150,6 +166,11 @@ golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8U @@ -150,6 +166,11 @@ golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8U
150 golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= 166 golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
151 golang.org/x/crypto v0.0.0-20191029031824-8986dd9e96cf h1:fnPsqIDRbCSgumaMCRpoIoF2s4qxv0xSSS0BVZUE/ss= 167 golang.org/x/crypto v0.0.0-20191029031824-8986dd9e96cf h1:fnPsqIDRbCSgumaMCRpoIoF2s4qxv0xSSS0BVZUE/ss=
152 golang.org/x/crypto v0.0.0-20191029031824-8986dd9e96cf/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= 168 golang.org/x/crypto v0.0.0-20191029031824-8986dd9e96cf/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
  169 +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
  170 +golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a h1:vclmkQCjlDX5OydZ9wv8rBCcS0QyQY66Mpf/7BZbInM=
  171 +golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
  172 +golang.org/x/image v0.0.0-20200922025426-e59bae62ef32 h1:E+SEVulmY8U4+i6vSB88YSc2OKAFfvbHPU/uDTdQu7M=
  173 +golang.org/x/image v0.0.0-20200922025426-e59bae62ef32/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
153 golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= 174 golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
154 golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 175 golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
155 golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 176 golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
@@ -160,6 +181,8 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL @@ -160,6 +181,8 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL
160 golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 181 golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
161 golang.org/x/net v0.0.0-20190923162816-aa69164e4478 h1:l5EDrHhldLYb3ZRHDUhXF7Om7MvYXnkV9/iQNo1lX6g= 182 golang.org/x/net v0.0.0-20190923162816-aa69164e4478 h1:l5EDrHhldLYb3ZRHDUhXF7Om7MvYXnkV9/iQNo1lX6g=
162 golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 183 golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
  184 +golang.org/x/net v0.0.0-20200904194848-62affa334b73 h1:MXfv8rhZWmFeqX3GNZRsd6vOLoaCHjYEX3qkRo3YBUA=
  185 +golang.org/x/net v0.0.0-20200904194848-62affa334b73/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
163 golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 186 golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
164 golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 187 golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
165 golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 188 golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
@@ -173,12 +196,17 @@ golang.org/x/sys v0.0.0-20191010194322-b09406accb47/go.mod h1:h1NjWce9XRLGQEsW7w @@ -173,12 +196,17 @@ golang.org/x/sys v0.0.0-20191010194322-b09406accb47/go.mod h1:h1NjWce9XRLGQEsW7w
173 golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 196 golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
174 golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae h1:/WDfKMnPU+m5M4xB+6x4kaepxRw6jWvR5iDRdvjHgy8= 197 golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae h1:/WDfKMnPU+m5M4xB+6x4kaepxRw6jWvR5iDRdvjHgy8=
175 golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 198 golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
  199 +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd h1:xhmwyvizuTgC2qz7ZlMluP20uW+C3Rm0FD/WLDX8884=
  200 +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
176 golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 201 golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
177 golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= 202 golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
178 golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= 203 golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
  204 +golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
  205 +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
179 golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 206 golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
180 golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= 207 golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
181 golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= 208 golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
  209 +golang.org/x/tools v0.0.0-20200117065230-39095c1d176c h1:FodBYPZKH5tAN2O60HlglMwXGAeV/4k+NKbli79M/2c=
182 golang.org/x/tools v0.0.0-20200117065230-39095c1d176c/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= 210 golang.org/x/tools v0.0.0-20200117065230-39095c1d176c/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
183 golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 211 golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
184 google.golang.org/appengine v1.6.2/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= 212 google.golang.org/appengine v1.6.2/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0=
@@ -198,5 +226,7 @@ gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= @@ -198,5 +226,7 @@ gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
198 gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 226 gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
199 gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I= 227 gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I=
200 gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 228 gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
  229 +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
  230 +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
201 mellium.im/sasl v0.2.1 h1:nspKSRg7/SyO0cRGY71OkfHab8tf9kCts6a6oTDut0w= 231 mellium.im/sasl v0.2.1 h1:nspKSRg7/SyO0cRGY71OkfHab8tf9kCts6a6oTDut0w=
202 mellium.im/sasl v0.2.1/go.mod h1:ROaEDLQNuf9vjKqE1SrAfnsobm2YKXT1gnN1uDp1PjQ= 232 mellium.im/sasl v0.2.1/go.mod h1:ROaEDLQNuf9vjKqE1SrAfnsobm2YKXT1gnN1uDp1PjQ=
@@ -35,5 +35,10 @@ func main() { @@ -35,5 +35,10 @@ func main() {
35 } 35 }
36 } 36 }
37 }() 37 }()
  38 +
  39 + // excel文件路径映射
  40 + beego.SetStaticPath("/download", "download")
  41 + beego.SetStaticPath("/logs", "log")
  42 +
38 beego.Run() 43 beego.Run()
39 } 44 }
@@ -21,6 +21,7 @@ func (configService *ConfigService) ListTaskStatus(listTaskStatusQuery *query.Li @@ -21,6 +21,7 @@ func (configService *ConfigService) ListTaskStatus(listTaskStatusQuery *query.Li
21 4: "待验收", 21 4: "待验收",
22 5: "已完成", 22 5: "已完成",
23 7: "待确认", 23 7: "待确认",
  24 + 8: "已过期",
24 } 25 }
25 var list []map[string]interface{} 26 var list []map[string]interface{}
26 for key, value := range taskStatusMap { 27 for key, value := range taskStatusMap {
@@ -165,7 +166,7 @@ func (configService *ConfigService) ListBidTimeMatch(listBidTimeMatchQuery *quer @@ -165,7 +166,7 @@ func (configService *ConfigService) ListBidTimeMatch(listBidTimeMatchQuery *quer
165 }, nil 166 }, nil
166 } 167 }
167 168
168 -// 返回员工权限字典列表(1任务管理,2素币管理,3成员管理) 169 +// 返回员工权限字典列表(1任务管理,2素币管理,3成员管理,4标签管理,5排行榜管理
169 func (configService *ConfigService) ListEmployeePermission(listEmployeePermissionQuery *query.ListEmployeePermissionQuery) (interface{}, error) { 170 func (configService *ConfigService) ListEmployeePermission(listEmployeePermissionQuery *query.ListEmployeePermissionQuery) (interface{}, error) {
170 if err := listEmployeePermissionQuery.ValidateQuery(); err != nil { 171 if err := listEmployeePermissionQuery.ValidateQuery(); err != nil {
171 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 172 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
@@ -175,6 +176,7 @@ func (configService *ConfigService) ListEmployeePermission(listEmployeePermissio @@ -175,6 +176,7 @@ func (configService *ConfigService) ListEmployeePermission(listEmployeePermissio
175 2: "素币管理", 176 2: "素币管理",
176 3: "成员管理", 177 3: "成员管理",
177 4: "标签管理", 178 4: "标签管理",
  179 + 5: "排行榜管理",
178 } 180 }
179 var list []map[string]interface{} 181 var list []map[string]interface{}
180 for key, value := range employeePermissionMap { 182 for key, value := range employeePermissionMap {
@@ -2,7 +2,6 @@ package command @@ -2,7 +2,6 @@ package command
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
5 -  
6 "github.com/astaxie/beego/validation" 5 "github.com/astaxie/beego/validation"
7 ) 6 )
8 7
@@ -2,6 +2,7 @@ package command @@ -2,6 +2,7 @@ package command
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
  5 + "time"
5 6
6 "github.com/astaxie/beego/validation" 7 "github.com/astaxie/beego/validation"
7 ) 8 )
@@ -15,6 +16,8 @@ type CreateEmployeeCommand struct { @@ -15,6 +16,8 @@ type CreateEmployeeCommand struct {
15 EmployeeAccount string `json:"employeeAccount,omitempty"` 16 EmployeeAccount string `json:"employeeAccount,omitempty"`
16 // 员工头像URL 17 // 员工头像URL
17 EmployeeAvatarUrl string `json:"employeeAvatarUrl,omitempty"` 18 EmployeeAvatarUrl string `json:"employeeAvatarUrl,omitempty"`
  19 + // 创建时间
  20 + CreateTime time.Time `json:"createTime"`
18 } 21 }
19 22
20 func (createEmployeeCommand *CreateEmployeeCommand) ValidateCommand() error { 23 func (createEmployeeCommand *CreateEmployeeCommand) ValidateCommand() error {
@@ -2,7 +2,6 @@ package command @@ -2,7 +2,6 @@ package command
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
5 -  
6 "github.com/astaxie/beego/validation" 5 "github.com/astaxie/beego/validation"
7 ) 6 )
8 7
@@ -2,6 +2,7 @@ package command @@ -2,6 +2,7 @@ package command
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
  5 + "time"
5 6
6 "github.com/astaxie/beego/validation" 7 "github.com/astaxie/beego/validation"
7 ) 8 )
@@ -17,6 +18,8 @@ type UpdateEmployeeCommand struct { @@ -17,6 +18,8 @@ type UpdateEmployeeCommand struct {
17 EmployeeAvatarUrl string `json:"employeeAvatarUrl,omitempty"` 18 EmployeeAvatarUrl string `json:"employeeAvatarUrl,omitempty"`
18 // 员工权限集合 19 // 员工权限集合
19 Permissions []int `json:"permissions,omitempty"` 20 Permissions []int `json:"permissions,omitempty"`
  21 + // 创建时间
  22 + CreateTime time.Time `json:"createTime"`
20 } 23 }
21 24
22 func (updateEmployeeCommand *UpdateEmployeeCommand) ValidateCommand() error { 25 func (updateEmployeeCommand *UpdateEmployeeCommand) ValidateCommand() error {
@@ -13,6 +13,8 @@ type ListEmployeeQuery struct { @@ -13,6 +13,8 @@ type ListEmployeeQuery struct {
13 EmployeeNameMatch string `json:"employeeNameMatch,omitempty"` 13 EmployeeNameMatch string `json:"employeeNameMatch,omitempty"`
14 // 查询偏离量 14 // 查询偏离量
15 Offset int `json:"offset,omitempty"` 15 Offset int `json:"offset,omitempty"`
  16 + // 员工状态(启用或者禁用)
  17 + Status int `json:"status"`
16 // 查询限制 18 // 查询限制
17 Limit int `json:"limit,omitempty"` 19 Limit int `json:"limit,omitempty"`
18 } 20 }
@@ -8,6 +8,7 @@ import ( @@ -8,6 +8,7 @@ import (
8 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/employee/query" 8 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/employee/query"
9 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/factory" 9 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/factory"
10 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain" 10 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
  11 + "time"
11 ) 12 )
12 13
13 // 员工服务 14 // 员工服务
@@ -36,6 +37,7 @@ func (employeeService *EmployeeService) CreateEmployee(createEmployeeCommand *co @@ -36,6 +37,7 @@ func (employeeService *EmployeeService) CreateEmployee(createEmployeeCommand *co
36 EmployeeAccount: createEmployeeCommand.EmployeeAccount, 37 EmployeeAccount: createEmployeeCommand.EmployeeAccount,
37 }, 38 },
38 SuMoney: 0, 39 SuMoney: 0,
  40 + CreateTime: time.Now(),
39 } 41 }
40 var employeeRepository domain.EmployeeRepository 42 var employeeRepository domain.EmployeeRepository
41 if value, err := factory.CreateEmployeeRepository(map[string]interface{}{ 43 if value, err := factory.CreateEmployeeRepository(map[string]interface{}{
@@ -122,6 +124,7 @@ func (employeeService *EmployeeService) UpdateEmployee(updateEmployeeCommand *co @@ -122,6 +124,7 @@ func (employeeService *EmployeeService) UpdateEmployee(updateEmployeeCommand *co
122 if employee == nil { 124 if employee == nil {
123 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateEmployeeCommand.Uid))) 125 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateEmployeeCommand.Uid)))
124 } 126 }
  127 + updateEmployeeCommand.CreateTime = time.Now()
125 if err := employee.Update(tool_funs.SimpleStructToMap(updateEmployeeCommand)); err != nil { 128 if err := employee.Update(tool_funs.SimpleStructToMap(updateEmployeeCommand)); err != nil {
126 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 129 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
127 } 130 }
@@ -180,6 +183,7 @@ func (employeeService *EmployeeService) ListEmployee(listEmployeeQuery *query.Li @@ -180,6 +183,7 @@ func (employeeService *EmployeeService) ListEmployee(listEmployeeQuery *query.Li
180 if err := listEmployeeQuery.ValidateQuery(); err != nil { 183 if err := listEmployeeQuery.ValidateQuery(); err != nil {
181 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 184 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
182 } 185 }
  186 +
183 transactionContext, err := factory.CreateTransactionContext(nil) 187 transactionContext, err := factory.CreateTransactionContext(nil)
184 if err != nil { 188 if err != nil {
185 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 189 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -190,6 +194,7 @@ func (employeeService *EmployeeService) ListEmployee(listEmployeeQuery *query.Li @@ -190,6 +194,7 @@ func (employeeService *EmployeeService) ListEmployee(listEmployeeQuery *query.Li
190 defer func() { 194 defer func() {
191 transactionContext.RollbackTransaction() 195 transactionContext.RollbackTransaction()
192 }() 196 }()
  197 +
193 var employeeRepository domain.EmployeeRepository 198 var employeeRepository domain.EmployeeRepository
194 if value, err := factory.CreateEmployeeRepository(map[string]interface{}{ 199 if value, err := factory.CreateEmployeeRepository(map[string]interface{}{
195 "transactionContext": transactionContext, 200 "transactionContext": transactionContext,
@@ -198,7 +203,13 @@ func (employeeService *EmployeeService) ListEmployee(listEmployeeQuery *query.Li @@ -198,7 +203,13 @@ func (employeeService *EmployeeService) ListEmployee(listEmployeeQuery *query.Li
198 } else { 203 } else {
199 employeeRepository = value 204 employeeRepository = value
200 } 205 }
201 - if count, employees, err := employeeRepository.Find(tool_funs.SimpleStructToMap(listEmployeeQuery)); err != nil { 206 +
  207 + if count, employees, err := employeeRepository.Find(map[string]interface{}{
  208 + "companyId": listEmployeeQuery.CompanyId,
  209 + "employeeNameMatch": listEmployeeQuery.EmployeeNameMatch,
  210 + "offset": listEmployeeQuery.Offset,
  211 + "limit": listEmployeeQuery.Limit,
  212 + }); err != nil {
202 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 213 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
203 } else { 214 } else {
204 if err := transactionContext.CommitTransaction(); err != nil { 215 if err := transactionContext.CommitTransaction(); err != nil {
@@ -28,3 +28,19 @@ func CreateNotificationDao(options map[string]interface{}) (*dao.NotificationDao @@ -28,3 +28,19 @@ func CreateNotificationDao(options map[string]interface{}) (*dao.NotificationDao
28 } 28 }
29 return dao.NewNotificationDao(transactionContext) 29 return dao.NewNotificationDao(transactionContext)
30 } 30 }
  31 +
  32 +func CreateCashPoolDao(options map[string]interface{}) (*dao.CashPoolDao, error) {
  33 + var transactionContext *pg.TransactionContext
  34 + if value, ok := options["transactionContext"]; ok {
  35 + transactionContext = value.(*pg.TransactionContext)
  36 + }
  37 + return dao.NewCashPoolDao(transactionContext)
  38 +}
  39 +
  40 +func CreateListIntervalDao(options map[string]interface{}) (*dao.ListIntervalDao, error) {
  41 + var transactionContext *pg.TransactionContext
  42 + if value, ok := options["transactionContext"]; ok {
  43 + transactionContext = value.(*pg.TransactionContext)
  44 + }
  45 + return dao.NewListIntervalDao(transactionContext)
  46 +}
@@ -109,3 +109,6 @@ func CreateExchangeSuMoneyService(options map[string]interface{}) (service.Excha @@ -109,3 +109,6 @@ func CreateExchangeSuMoneyService(options map[string]interface{}) (service.Excha
109 } 109 }
110 return domainService.NewExchangeSuMoneyService(transactionContext) 110 return domainService.NewExchangeSuMoneyService(transactionContext)
111 } 111 }
  112 +
  113 +
  114 +
@@ -85,3 +85,35 @@ func CreateSentNotificationRepository(options map[string]interface{}) (domain.Se @@ -85,3 +85,35 @@ func CreateSentNotificationRepository(options map[string]interface{}) (domain.Se
85 } 85 }
86 return repository.NewSentNotificationRepository(transactionContext) 86 return repository.NewSentNotificationRepository(transactionContext)
87 } 87 }
  88 +
  89 +func CreateCashPoolRepository(options map[string]interface{}) (domain.CashPoolRepository, error) {
  90 + var transactionContext *pg.TransactionContext
  91 + if value, ok := options["transactionContext"]; ok {
  92 + transactionContext = value.(*pg.TransactionContext)
  93 + }
  94 + return repository.NewCashPoolRepository(transactionContext)
  95 +}
  96 +
  97 +func CreateExchangeCashActivityRepository(options map[string]interface{}) (domain.ExchangeActivityRepository, error) {
  98 + var transactionContext *pg.TransactionContext
  99 + if value, ok := options["transactionContext"]; ok {
  100 + transactionContext = value.(*pg.TransactionContext)
  101 + }
  102 + return repository.NewExchangeCashActivityRepository(transactionContext)
  103 +}
  104 +
  105 +func CreateExchangeCashPersonListRepository(options map[string]interface{}) (domain.ExchangeCashPersonListRepository, error) {
  106 + var transactionContext *pg.TransactionContext
  107 + if value, ok := options["transactionContext"]; ok {
  108 + transactionContext = value.(*pg.TransactionContext)
  109 + }
  110 + return repository.NewExchangeCashPersonListRepository(transactionContext)
  111 +}
  112 +
  113 +func CreateListIntervalRepository(options map[string]interface{}) (domain.ListIntervalRepository, error) {
  114 + var transactionContext *pg.TransactionContext
  115 + if value, ok := options["transactionContext"]; ok {
  116 + transactionContext = value.(*pg.TransactionContext)
  117 + }
  118 + return repository.NewListIntervalRepository(transactionContext)
  119 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/astaxie/beego/validation"
  6 + "time"
  7 +)
  8 +
  9 +type CreateListIntervalCommand struct {
  10 + CompanyId int `json:"companyId" valid:"Required"` // 公司id
  11 + ListIntervalStartTime time.Time `json:"listIntervalStartTime"` // 排行榜开始时间
  12 + ListIntervalEndTime time.Time `json:"listIntervalEndTime"` // 排行榜结束时间
  13 +}
  14 +
  15 +func (createListIntervalCommand *CreateListIntervalCommand) ValidateCommand() error {
  16 + valid := validation.Validation{}
  17 + b, err := valid.Valid(createListIntervalCommand)
  18 + if err != nil {
  19 + return err
  20 + }
  21 + if !b {
  22 + for _, validErr := range valid.Errors {
  23 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  24 + }
  25 + }
  26 + return nil
  27 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/astaxie/beego/validation"
  6 +)
  7 +
  8 +type RemoveListIntervalCommand struct {
  9 + ListIntervalId int `json:"listIntervalId" valid:"Required"` // 排行榜Id
  10 +}
  11 +
  12 +func (removeListIntervalCommand *RemoveListIntervalCommand) ValidateCommand() error {
  13 + valid := validation.Validation{}
  14 + b, err := valid.Valid(removeListIntervalCommand)
  15 + if err != nil {
  16 + return err
  17 + }
  18 + if !b {
  19 + for _, validErr := range valid.Errors {
  20 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  21 + }
  22 + }
  23 + return nil
  24 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/astaxie/beego/validation"
  6 + "time"
  7 +)
  8 +
  9 +type UpdateListIntervalCommand struct {
  10 + ListIntervalId int `json:"listIntervalId" valid:"Required"` // 排行榜id
  11 + ListIntervalStartTime time.Time `json:"listIntervalStartTime"` // 排行榜开始时间
  12 + ListIntervalEndTime time.Time `json:"listIntervalEndTime"` // 排行榜结束时间
  13 +}
  14 +
  15 +func (updateListIntervalCommand *UpdateListIntervalCommand) ValidateCommand() error {
  16 + valid := validation.Validation{}
  17 + b, err := valid.Valid(updateListIntervalCommand)
  18 + if err != nil {
  19 + return err
  20 + }
  21 + if !b {
  22 + for _, validErr := range valid.Errors {
  23 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  24 + }
  25 + }
  26 + return nil
  27 +}
  1 +package query
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/astaxie/beego/validation"
  6 +)
  7 +
  8 +type GetListIntervalQuery struct {
  9 + ListIntervalId int `json:"listIntervalId"` // 排行榜id
  10 +}
  11 +
  12 +func (getListIntervalQuery *GetListIntervalQuery) ValidateQuery() error {
  13 + valid := validation.Validation{}
  14 + b, err := valid.Valid(getListIntervalQuery)
  15 + if err != nil {
  16 + return err
  17 + }
  18 + if !b {
  19 + for _, validErr := range valid.Errors {
  20 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  21 + }
  22 + }
  23 + return nil
  24 +}
  1 +package query
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/astaxie/beego/validation"
  6 +)
  7 +
  8 +type ListListIntervalQuery struct {
  9 + CompanyId int `json:"companyId"` // 公司id
  10 + Offset int `json:"offset,omitempty"` // 查询偏离量
  11 + Limit int `json:"limit,omitempty"` // 查询限制
  12 + }
  13 +
  14 +func (listListIntervalQuery *ListListIntervalQuery) ValidateQuery() error {
  15 + valid := validation.Validation{}
  16 + b, err := valid.Valid(listListIntervalQuery)
  17 + if err != nil {
  18 + return err
  19 + }
  20 + if !b {
  21 + for _, validErr := range valid.Errors {
  22 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  23 + }
  24 + }
  25 + return nil
  26 +}
  1 +package service
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/linmadan/egglib-go/core/application"
  6 + "github.com/linmadan/egglib-go/utils/tool_funs"
  7 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/factory"
  8 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/listInterval/command"
  9 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/listInterval/query"
  10 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
  11 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/dao"
  12 + "time"
  13 +)
  14 +
  15 +type ListIntervalService struct {
  16 +}
  17 +
  18 +// 创建排行榜时间
  19 +func (listIntervalService *ListIntervalService) CreateListInterval(createListIntervalCommand *command.CreateListIntervalCommand) (interface{}, error) {
  20 + if err := createListIntervalCommand.ValidateCommand(); err != nil {
  21 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  22 + }
  23 + transactionContext, err := factory.CreateTransactionContext(nil)
  24 + if err != nil {
  25 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  26 + }
  27 + if err := transactionContext.StartTransaction(); err != nil {
  28 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  29 + }
  30 + defer func() {
  31 + transactionContext.RollbackTransaction()
  32 + }()
  33 +
  34 + // 排行榜时间仓储初始化
  35 + var listIntervalRepository domain.ListIntervalRepository
  36 + if value, err := factory.CreateListIntervalRepository(map[string]interface{}{
  37 + "transactionContext": transactionContext,
  38 + }); err != nil {
  39 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  40 + } else {
  41 + listIntervalRepository = value
  42 + }
  43 +
  44 + // 排行榜管理DAO初始化
  45 + var listIntervalDao *dao.ListIntervalDao
  46 + if value, err := factory.CreateListIntervalDao(map[string]interface{}{
  47 + "transactionContext": transactionContext,
  48 + }); err != nil {
  49 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  50 + } else {
  51 + listIntervalDao = value
  52 + }
  53 +
  54 + // 获取当前最新排行榜时间
  55 + listListIntervalQuery := &query.ListListIntervalQuery {
  56 + CompanyId: createListIntervalCommand.CompanyId,
  57 + Offset: 0,
  58 + Limit: 1,
  59 + }
  60 +
  61 + // 获取上个年榜时间
  62 + _, listIntervals, err := listIntervalRepository.Find(tool_funs.SimpleStructToMap(listListIntervalQuery))
  63 + if err != nil {
  64 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  65 + }
  66 +
  67 + startTime := time.Date(createListIntervalCommand.ListIntervalStartTime.Local().Year(), createListIntervalCommand.ListIntervalStartTime.Local().Month(), createListIntervalCommand.ListIntervalStartTime.Local().Day(), 0, 0, 0, 0, time.Local)
  68 + endTime := time.Date(createListIntervalCommand.ListIntervalEndTime.Local().Year(), createListIntervalCommand.ListIntervalEndTime.Local().Month(), createListIntervalCommand.ListIntervalEndTime.Local().Day(), 23, 59, 59, 0, time.Local)
  69 +
  70 + // 判断年榜时间是否重叠
  71 + if len(listIntervals) > 0 {
  72 + ok := listIntervalDao.RankPeriodCheckTime(startTime.Local().Unix(), endTime.Local().Unix(), 0, listIntervals[0].CompanyId)
  73 + if !ok {
  74 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "年榜时间不能重叠")
  75 + }
  76 + }
  77 +
  78 + // 创建排行榜时间
  79 + newListInterval := &domain.ListInterval {
  80 + CompanyId: createListIntervalCommand.CompanyId,
  81 + IntervalStartTime: startTime,
  82 + IntervalEndTime: endTime,
  83 + }
  84 + listInterval, err := listIntervalRepository.Save(newListInterval)
  85 + if err != nil {
  86 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  87 + }
  88 + if err := transactionContext.CommitTransaction(); err != nil {
  89 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  90 + }
  91 + return listInterval, nil
  92 +}
  93 +
  94 +// 返回排行榜时间列表
  95 +func (listIntervalService *ListIntervalService) ListListInterval(listListIntervalQuery *query.ListListIntervalQuery) (interface{}, error) {
  96 + if err := listListIntervalQuery.ValidateQuery(); err != nil {
  97 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  98 + }
  99 + transactionContext, err := factory.CreateTransactionContext(nil)
  100 + if err != nil {
  101 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  102 + }
  103 + if err := transactionContext.StartTransaction(); err != nil {
  104 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  105 + }
  106 + defer func() {
  107 + transactionContext.RollbackTransaction()
  108 + }()
  109 +
  110 + var listIntervalRepository domain.ListIntervalRepository
  111 + if value, err := factory.CreateListIntervalRepository(map[string]interface{}{
  112 + "transactionContext": transactionContext,
  113 + }); err != nil {
  114 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  115 + } else {
  116 + listIntervalRepository = value
  117 + }
  118 +
  119 + if count, listIntervals, err := listIntervalRepository.Find(tool_funs.SimpleStructToMap(listListIntervalQuery)); err != nil {
  120 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  121 + } else {
  122 + if err := transactionContext.CommitTransaction(); err != nil {
  123 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  124 + }
  125 + return map[string]interface{}{
  126 + "count": count,
  127 + "listIntervals": listIntervals,
  128 + }, nil
  129 + }
  130 +}
  131 +
  132 +// 返回排行榜时间
  133 +func (listIntervalService *ListIntervalService) GetListInterval(getListIntervalQuery *query.GetListIntervalQuery) (interface{}, error) {
  134 + if err := getListIntervalQuery.ValidateQuery(); err != nil {
  135 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  136 + }
  137 + transactionContext, err := factory.CreateTransactionContext(nil)
  138 + if err != nil {
  139 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  140 + }
  141 + if err := transactionContext.StartTransaction(); err != nil {
  142 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  143 + }
  144 + defer func() {
  145 + transactionContext.RollbackTransaction()
  146 + }()
  147 +
  148 + var listIntervalRepository domain.ListIntervalRepository
  149 + if value, err := factory.CreateListIntervalRepository(map[string]interface{}{
  150 + "transactionContext": transactionContext,
  151 + }); err != nil {
  152 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  153 + } else {
  154 + listIntervalRepository = value
  155 + }
  156 +
  157 + listInterval, err := listIntervalRepository.FindOne(map[string]interface{}{"listId": getListIntervalQuery.ListIntervalId})
  158 + if err != nil {
  159 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  160 + }
  161 + if listInterval == nil {
  162 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getListIntervalQuery.ListIntervalId)))
  163 + } else {
  164 + if err := transactionContext.CommitTransaction(); err != nil {
  165 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  166 + }
  167 + return listInterval, nil
  168 + }
  169 +}
  170 +
  171 +// 更新排行榜时间
  172 +func (listIntervalService *ListIntervalService) UpdateListInterval(updateListIntervalCommand *command.UpdateListIntervalCommand) (interface{}, error) {
  173 + if err := updateListIntervalCommand.ValidateCommand(); err != nil {
  174 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  175 + }
  176 +
  177 + transactionContext, err := factory.CreateTransactionContext(nil)
  178 + if err != nil {
  179 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  180 + }
  181 + if err := transactionContext.StartTransaction(); err != nil {
  182 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  183 + }
  184 + defer func() {
  185 + transactionContext.RollbackTransaction()
  186 + }()
  187 +
  188 + // 排行榜管理仓储初始化
  189 + var listIntervalRepository domain.ListIntervalRepository
  190 + if value, err := factory.CreateListIntervalRepository(map[string]interface{}{
  191 + "transactionContext": transactionContext,
  192 + }); err != nil {
  193 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  194 + } else {
  195 + listIntervalRepository = value
  196 + }
  197 +
  198 + // 排行榜管理DAO初始化
  199 + var listIntervalDao *dao.ListIntervalDao
  200 + if value, err := factory.CreateListIntervalDao(map[string]interface{}{
  201 + "transactionContext": transactionContext,
  202 + }); err != nil {
  203 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  204 + } else {
  205 + listIntervalDao = value
  206 + }
  207 +
  208 + // 获取当前年榜
  209 + listIntervalFound, err := listIntervalRepository.FindOne(map[string]interface{}{"listId": updateListIntervalCommand.ListIntervalId})
  210 + if err != nil {
  211 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  212 + }
  213 + if listIntervalFound == nil {
  214 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateListIntervalCommand.ListIntervalId)))
  215 + }
  216 +
  217 + // 当前更新的开始结束时间
  218 + startTime := time.Date(updateListIntervalCommand.ListIntervalStartTime.Local().Year(), updateListIntervalCommand.ListIntervalStartTime.Local().Month(), updateListIntervalCommand.ListIntervalStartTime.Local().Day(), 0, 0, 0, 0, time.Local)
  219 + endTime := time.Date(updateListIntervalCommand.ListIntervalEndTime.Local().Year(), updateListIntervalCommand.ListIntervalEndTime.Local().Month(), updateListIntervalCommand.ListIntervalEndTime.Local().Day(), 23, 59, 59, 0, time.Local)
  220 +
  221 + updateListIntervalCommand.ListIntervalStartTime = startTime
  222 + updateListIntervalCommand.ListIntervalEndTime = endTime
  223 +
  224 + // 判断年榜时间是否重叠
  225 + ok := listIntervalDao.RankPeriodCheckTime(startTime.Unix(), endTime.Unix(), listIntervalFound.ListIntervalId, listIntervalFound.CompanyId)
  226 + if !ok {
  227 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "年榜时间不能重叠")
  228 + }
  229 +
  230 + // 更新年榜
  231 + if err := listIntervalFound.Update(tool_funs.SimpleStructToMap(updateListIntervalCommand)); err != nil {
  232 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  233 + }
  234 + if listIntervalUpdated, err := listIntervalRepository.Save(listIntervalFound); err != nil {
  235 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  236 + } else {
  237 + if err := transactionContext.CommitTransaction(); err != nil {
  238 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  239 + }
  240 + return listIntervalUpdated, nil
  241 + }
  242 +}
  243 +
  244 +// 移除排行榜时间
  245 +func (listIntervalService *ListIntervalService) RemoveListInterval(removeListIntervalCommand *command.RemoveListIntervalCommand) (interface{}, error) {
  246 + if err := removeListIntervalCommand.ValidateCommand(); err != nil {
  247 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  248 + }
  249 + transactionContext, err := factory.CreateTransactionContext(nil)
  250 + if err != nil {
  251 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  252 + }
  253 + if err := transactionContext.StartTransaction(); err != nil {
  254 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  255 + }
  256 + defer func() {
  257 + transactionContext.RollbackTransaction()
  258 + }()
  259 +
  260 + var listIntervalRepository domain.ListIntervalRepository
  261 + if value, err := factory.CreateListIntervalRepository(map[string]interface{}{
  262 + "transactionContext": transactionContext,
  263 + }); err != nil {
  264 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  265 + } else {
  266 + listIntervalRepository = value
  267 + }
  268 +
  269 + listInterval, err := listIntervalRepository.FindOne(map[string]interface{}{"listId": removeListIntervalCommand.ListIntervalId})
  270 + if err != nil {
  271 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  272 + }
  273 + if listInterval == nil {
  274 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeListIntervalCommand.ListIntervalId)))
  275 + }
  276 +
  277 + if listInterval, err := listIntervalRepository.Remove(listInterval); err != nil {
  278 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  279 + } else {
  280 + if err := transactionContext.CommitTransaction(); err != nil {
  281 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  282 + }
  283 + return listInterval, nil
  284 + }
  285 +}
  286 +
  287 +func NewListIntervalService(options map[string] interface{}) *ListIntervalService {
  288 + newListIntervalService := &ListIntervalService{}
  289 + return newListIntervalService
  290 +}
@@ -28,6 +28,7 @@ func (notificationService *NotificationService) SystemNotificationNearThePlanned @@ -28,6 +28,7 @@ func (notificationService *NotificationService) SystemNotificationNearThePlanned
28 defer func() { 28 defer func() {
29 transactionContext.RollbackTransaction() 29 transactionContext.RollbackTransaction()
30 }() 30 }()
  31 +
31 var notificationRepository domain.NotificationRepository 32 var notificationRepository domain.NotificationRepository
32 if value, err := factory.CreateNotificationRepository(map[string]interface{}{ 33 if value, err := factory.CreateNotificationRepository(map[string]interface{}{
33 "transactionContext": transactionContext, 34 "transactionContext": transactionContext,
@@ -36,6 +37,7 @@ func (notificationService *NotificationService) SystemNotificationNearThePlanned @@ -36,6 +37,7 @@ func (notificationService *NotificationService) SystemNotificationNearThePlanned
36 } else { 37 } else {
37 notificationRepository = value 38 notificationRepository = value
38 } 39 }
  40 +
39 var sentNotificationRepository domain.SentNotificationRepository 41 var sentNotificationRepository domain.SentNotificationRepository
40 if value, err := factory.CreateSentNotificationRepository(map[string]interface{}{ 42 if value, err := factory.CreateSentNotificationRepository(map[string]interface{}{
41 "transactionContext": transactionContext, 43 "transactionContext": transactionContext,
@@ -44,6 +46,7 @@ func (notificationService *NotificationService) SystemNotificationNearThePlanned @@ -44,6 +46,7 @@ func (notificationService *NotificationService) SystemNotificationNearThePlanned
44 } else { 46 } else {
45 sentNotificationRepository = value 47 sentNotificationRepository = value
46 } 48 }
  49 +
47 var taskDao *dao.TaskDao 50 var taskDao *dao.TaskDao
48 if value, err := factory.CreateTaskDao(map[string]interface{}{ 51 if value, err := factory.CreateTaskDao(map[string]interface{}{
49 "transactionContext": transactionContext, 52 "transactionContext": transactionContext,
@@ -52,6 +55,13 @@ func (notificationService *NotificationService) SystemNotificationNearThePlanned @@ -52,6 +55,13 @@ func (notificationService *NotificationService) SystemNotificationNearThePlanned
52 } else { 55 } else {
53 taskDao = value 56 taskDao = value
54 } 57 }
  58 +
  59 + // 更新已过期竞标任务状态
  60 + if err := taskDao.UpdateExpiredPlannedCompletionTimeBidTask(); err != nil {
  61 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  62 + }
  63 +
  64 + // 返回快过期任务并发送消息
55 if tasks, err := taskDao.ListNearThePlannedCompletionTimeTask(); err != nil { 65 if tasks, err := taskDao.ListNearThePlannedCompletionTimeTask(); err != nil {
56 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 66 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
57 } else { 67 } else {
@@ -88,6 +98,7 @@ func (notificationService *NotificationService) SystemNotificationNearThePlanned @@ -88,6 +98,7 @@ func (notificationService *NotificationService) SystemNotificationNearThePlanned
88 } 98 }
89 } 99 }
90 } 100 }
  101 +
91 if err := transactionContext.CommitTransaction(); err != nil { 102 if err := transactionContext.CommitTransaction(); err != nil {
92 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 103 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
93 } else { 104 } else {
@@ -108,6 +119,7 @@ func (notificationService *NotificationService) SystemNotificationNearBidEndTime @@ -108,6 +119,7 @@ func (notificationService *NotificationService) SystemNotificationNearBidEndTime
108 defer func() { 119 defer func() {
109 transactionContext.RollbackTransaction() 120 transactionContext.RollbackTransaction()
110 }() 121 }()
  122 +
111 var notificationRepository domain.NotificationRepository 123 var notificationRepository domain.NotificationRepository
112 if value, err := factory.CreateNotificationRepository(map[string]interface{}{ 124 if value, err := factory.CreateNotificationRepository(map[string]interface{}{
113 "transactionContext": transactionContext, 125 "transactionContext": transactionContext,
@@ -116,6 +128,7 @@ func (notificationService *NotificationService) SystemNotificationNearBidEndTime @@ -116,6 +128,7 @@ func (notificationService *NotificationService) SystemNotificationNearBidEndTime
116 } else { 128 } else {
117 notificationRepository = value 129 notificationRepository = value
118 } 130 }
  131 +
119 var sentNotificationRepository domain.SentNotificationRepository 132 var sentNotificationRepository domain.SentNotificationRepository
120 if value, err := factory.CreateSentNotificationRepository(map[string]interface{}{ 133 if value, err := factory.CreateSentNotificationRepository(map[string]interface{}{
121 "transactionContext": transactionContext, 134 "transactionContext": transactionContext,
@@ -124,6 +137,7 @@ func (notificationService *NotificationService) SystemNotificationNearBidEndTime @@ -124,6 +137,7 @@ func (notificationService *NotificationService) SystemNotificationNearBidEndTime
124 } else { 137 } else {
125 sentNotificationRepository = value 138 sentNotificationRepository = value
126 } 139 }
  140 +
127 var taskDao *dao.TaskDao 141 var taskDao *dao.TaskDao
128 if value, err := factory.CreateTaskDao(map[string]interface{}{ 142 if value, err := factory.CreateTaskDao(map[string]interface{}{
129 "transactionContext": transactionContext, 143 "transactionContext": transactionContext,
@@ -132,6 +146,7 @@ func (notificationService *NotificationService) SystemNotificationNearBidEndTime @@ -132,6 +146,7 @@ func (notificationService *NotificationService) SystemNotificationNearBidEndTime
132 } else { 146 } else {
133 taskDao = value 147 taskDao = value
134 } 148 }
  149 +
135 if tasks, err := taskDao.ListNearBidEndTimeTask(); err != nil { 150 if tasks, err := taskDao.ListNearBidEndTimeTask(); err != nil {
136 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 151 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
137 } else { 152 } else {
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/astaxie/beego/validation"
  6 + "time"
  7 +)
  8 +
  9 +type EmployeesContributionsStatisticsCommand struct {
  10 + CompanyId int `json:"companyId" valid:"Required"` // 公司id
  11 + StartTime time.Time `json:"startTime"` // 年榜开始时间
  12 + EndTime time.Time `json:"endTime"` // 年榜结束时间
  13 +}
  14 +
  15 +func (employeesContributionsStatisticsCommand *EmployeesContributionsStatisticsCommand) ValidateCommand() error {
  16 + valid := validation.Validation{}
  17 + b, err := valid.Valid(employeesContributionsStatisticsCommand)
  18 + if err != nil {
  19 + return err
  20 + }
  21 + if !b {
  22 + for _, validErr := range valid.Errors {
  23 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  24 + }
  25 + }
  26 + return nil
  27 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "time"
  6 +
  7 + "github.com/astaxie/beego/validation"
  8 +)
  9 +
  10 +type EmployeesSuMoneyStatisticsCommand struct {
  11 + CompanyId int `json:"companyId" valid:"Required"` // 公司id
  12 + StartTime time.Time `json:"startTime"` // 年榜开始时间
  13 + EndTime time.Time `json:"endTime"` // 年榜结束时间
  14 +}
  15 +
  16 +func (employeesSuMoneyStatisticsCommand *EmployeesSuMoneyStatisticsCommand) ValidateCommand() error {
  17 + valid := validation.Validation{}
  18 + b, err := valid.Valid(employeesSuMoneyStatisticsCommand)
  19 + if err != nil {
  20 + return err
  21 + }
  22 + if !b {
  23 + for _, validErr := range valid.Errors {
  24 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  25 + }
  26 + }
  27 + return nil
  28 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/astaxie/beego/validation"
  6 + "time"
  7 +)
  8 +
  9 +type EmployeesRankingListStatisticsCommand struct {
  10 + CompanyId int `json:"companyId" valid:"Required"` // 公司id
  11 + StartTime time.Time `json:"startTime"` // 年榜开始时间
  12 + EndTime time.Time `json:"endTime"` // 年榜结束时间
  13 + Offset int `json:"offset,omitempty"` // 查询偏离量
  14 + Limit int `json:"limit,omitempty"` // 查询限制
  15 +}
  16 +
  17 +func (employeesRankingListStatisticsCommand *EmployeesRankingListStatisticsCommand) ValidateCommand() error {
  18 + valid := validation.Validation{}
  19 + b, err := valid.Valid(employeesRankingListStatisticsCommand)
  20 + if err != nil {
  21 + return err
  22 + }
  23 + if !b {
  24 + for _, validErr := range valid.Errors {
  25 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  26 + }
  27 + }
  28 + return nil
  29 +}
  30 +
@@ -9,6 +9,7 @@ import ( @@ -9,6 +9,7 @@ import (
9 type PersonTaskStatisticsCommand struct { 9 type PersonTaskStatisticsCommand struct {
10 // 统一用户UID 10 // 统一用户UID
11 Uid int64 `json:"uid" valid:"Required"` 11 Uid int64 `json:"uid" valid:"Required"`
  12 + CompanyId int `json:"companyId" valid:"Required"`
12 } 13 }
13 14
14 func (personTaskStatisticsCommand *PersonTaskStatisticsCommand) ValidateCommand() error { 15 func (personTaskStatisticsCommand *PersonTaskStatisticsCommand) ValidateCommand() error {
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 +
  6 + "github.com/astaxie/beego/validation"
  7 +)
  8 +
  9 +// 获取系统现金值
  10 +type SystemCashStatisticsCommand struct {
  11 + CompanyId int64 `json:"companyId" valid:"Required"` // 公司ID
  12 +}
  13 +
  14 +func (systemCashStatisticsCommand *SystemCashStatisticsCommand) ValidateCommand() error {
  15 + valid := validation.Validation{}
  16 + b, err := valid.Valid(systemCashStatisticsCommand)
  17 + if err != nil {
  18 + return err
  19 + }
  20 + if !b {
  21 + for _, validErr := range valid.Errors {
  22 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  23 + }
  24 + }
  25 + return nil
  26 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/astaxie/beego/validation"
  6 +)
  7 +
  8 +// 获取系统素币值
  9 +type SystemSuMoneyStatisticsCommand struct {
  10 + CompanyId int64 `json:"companyId" valid:"Required"` // 公司ID
  11 +}
  12 +
  13 +func (systemSuMoneyStatisticsCommand *SystemSuMoneyStatisticsCommand) ValidateCommand() error {
  14 + valid := validation.Validation{}
  15 + b, err := valid.Valid(systemSuMoneyStatisticsCommand)
  16 + if err != nil {
  17 + return err
  18 + }
  19 + if !b {
  20 + for _, validErr := range valid.Errors {
  21 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  22 + }
  23 + }
  24 + return nil
  25 +}
  26 +
@@ -2,10 +2,13 @@ package service @@ -2,10 +2,13 @@ package service
2 2
3 import ( 3 import (
4 "github.com/linmadan/egglib-go/core/application" 4 "github.com/linmadan/egglib-go/core/application"
  5 + "github.com/linmadan/egglib-go/utils/tool_funs"
5 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/factory" 6 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/factory"
6 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/statistics/command" 7 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/statistics/command"
  8 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/suMoney/query"
7 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain" 9 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
8 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/dao" 10 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/dao"
  11 + "time"
9 ) 12 )
10 13
11 // 数据统计服务 14 // 数据统计服务
@@ -27,6 +30,7 @@ func (statisticsService *StatisticsService) PersonNotificationStatistics(personN @@ -27,6 +30,7 @@ func (statisticsService *StatisticsService) PersonNotificationStatistics(personN
27 defer func() { 30 defer func() {
28 transactionContext.RollbackTransaction() 31 transactionContext.RollbackTransaction()
29 }() 32 }()
  33 +
30 var employeeDao *dao.EmployeeDao 34 var employeeDao *dao.EmployeeDao
31 if value, err := factory.CreateEmployeeDao(map[string]interface{}{ 35 if value, err := factory.CreateEmployeeDao(map[string]interface{}{
32 "transactionContext": transactionContext, 36 "transactionContext": transactionContext,
@@ -35,6 +39,7 @@ func (statisticsService *StatisticsService) PersonNotificationStatistics(personN @@ -35,6 +39,7 @@ func (statisticsService *StatisticsService) PersonNotificationStatistics(personN
35 } else { 39 } else {
36 employeeDao = value 40 employeeDao = value
37 } 41 }
  42 +
38 var employeeRepository domain.EmployeeRepository 43 var employeeRepository domain.EmployeeRepository
39 if value, err := factory.CreateEmployeeRepository(map[string]interface{}{ 44 if value, err := factory.CreateEmployeeRepository(map[string]interface{}{
40 "transactionContext": transactionContext, 45 "transactionContext": transactionContext,
@@ -43,6 +48,7 @@ func (statisticsService *StatisticsService) PersonNotificationStatistics(personN @@ -43,6 +48,7 @@ func (statisticsService *StatisticsService) PersonNotificationStatistics(personN
43 } else { 48 } else {
44 employeeRepository = value 49 employeeRepository = value
45 } 50 }
  51 +
46 employee, err := employeeRepository.FindOne(map[string]interface{}{ 52 employee, err := employeeRepository.FindOne(map[string]interface{}{
47 "uid": personNotificationStatisticsCommand.Uid, 53 "uid": personNotificationStatisticsCommand.Uid,
48 }) 54 })
@@ -52,6 +58,7 @@ func (statisticsService *StatisticsService) PersonNotificationStatistics(personN @@ -52,6 +58,7 @@ func (statisticsService *StatisticsService) PersonNotificationStatistics(personN
52 if employee == nil { 58 if employee == nil {
53 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的企业员工") 59 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的企业员工")
54 } 60 }
  61 +
55 if personNotificationStatistics, err := employeeDao.CalculatePersonUnReadNotification(personNotificationStatisticsCommand.Uid); err != nil { 62 if personNotificationStatistics, err := employeeDao.CalculatePersonUnReadNotification(personNotificationStatisticsCommand.Uid); err != nil {
56 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 63 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
57 } else { 64 } else {
@@ -77,6 +84,7 @@ func (statisticsService *StatisticsService) SystemTaskStatistics(systemTaskStati @@ -77,6 +84,7 @@ func (statisticsService *StatisticsService) SystemTaskStatistics(systemTaskStati
77 defer func() { 84 defer func() {
78 transactionContext.RollbackTransaction() 85 transactionContext.RollbackTransaction()
79 }() 86 }()
  87 +
80 var taskDao *dao.TaskDao 88 var taskDao *dao.TaskDao
81 if value, err := factory.CreateTaskDao(map[string]interface{}{ 89 if value, err := factory.CreateTaskDao(map[string]interface{}{
82 "transactionContext": transactionContext, 90 "transactionContext": transactionContext,
@@ -85,6 +93,7 @@ func (statisticsService *StatisticsService) SystemTaskStatistics(systemTaskStati @@ -85,6 +93,7 @@ func (statisticsService *StatisticsService) SystemTaskStatistics(systemTaskStati
85 } else { 93 } else {
86 taskDao = value 94 taskDao = value
87 } 95 }
  96 +
88 if systemTaskStatistics, err := taskDao.CalculateSystemTask(systemTaskStatisticsCommand.CompanyId); err != nil { 97 if systemTaskStatistics, err := taskDao.CalculateSystemTask(systemTaskStatisticsCommand.CompanyId); err != nil {
89 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 98 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
90 } else { 99 } else {
@@ -110,6 +119,7 @@ func (statisticsService *StatisticsService) PersonTaskStatistics(personTaskStati @@ -110,6 +119,7 @@ func (statisticsService *StatisticsService) PersonTaskStatistics(personTaskStati
110 defer func() { 119 defer func() {
111 transactionContext.RollbackTransaction() 120 transactionContext.RollbackTransaction()
112 }() 121 }()
  122 +
113 var taskDao *dao.TaskDao 123 var taskDao *dao.TaskDao
114 if value, err := factory.CreateTaskDao(map[string]interface{}{ 124 if value, err := factory.CreateTaskDao(map[string]interface{}{
115 "transactionContext": transactionContext, 125 "transactionContext": transactionContext,
@@ -118,6 +128,7 @@ func (statisticsService *StatisticsService) PersonTaskStatistics(personTaskStati @@ -118,6 +128,7 @@ func (statisticsService *StatisticsService) PersonTaskStatistics(personTaskStati
118 } else { 128 } else {
119 taskDao = value 129 taskDao = value
120 } 130 }
  131 +
121 var employeeRepository domain.EmployeeRepository 132 var employeeRepository domain.EmployeeRepository
122 if value, err := factory.CreateEmployeeRepository(map[string]interface{}{ 133 if value, err := factory.CreateEmployeeRepository(map[string]interface{}{
123 "transactionContext": transactionContext, 134 "transactionContext": transactionContext,
@@ -126,6 +137,7 @@ func (statisticsService *StatisticsService) PersonTaskStatistics(personTaskStati @@ -126,6 +137,7 @@ func (statisticsService *StatisticsService) PersonTaskStatistics(personTaskStati
126 } else { 137 } else {
127 employeeRepository = value 138 employeeRepository = value
128 } 139 }
  140 +
129 employee, err := employeeRepository.FindOne(map[string]interface{}{ 141 employee, err := employeeRepository.FindOne(map[string]interface{}{
130 "uid": personTaskStatisticsCommand.Uid, 142 "uid": personTaskStatisticsCommand.Uid,
131 }) 143 })
@@ -135,7 +147,8 @@ func (statisticsService *StatisticsService) PersonTaskStatistics(personTaskStati @@ -135,7 +147,8 @@ func (statisticsService *StatisticsService) PersonTaskStatistics(personTaskStati
135 if employee == nil { 147 if employee == nil {
136 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的企业员工") 148 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的企业员工")
137 } 149 }
138 - if personTaskStatistics, err := taskDao.CalculatePersonTask(personTaskStatisticsCommand.Uid); err != nil { 150 +
  151 + if personTaskStatistics, err := taskDao.CalculatePersonTask(personTaskStatisticsCommand.Uid, personTaskStatisticsCommand.CompanyId); err != nil {
139 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 152 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
140 } else { 153 } else {
141 if err := transactionContext.CommitTransaction(); err != nil { 154 if err := transactionContext.CommitTransaction(); err != nil {
@@ -160,6 +173,7 @@ func (statisticsService *StatisticsService) PersonSuMoneyStatistics(personSuMone @@ -160,6 +173,7 @@ func (statisticsService *StatisticsService) PersonSuMoneyStatistics(personSuMone
160 defer func() { 173 defer func() {
161 transactionContext.RollbackTransaction() 174 transactionContext.RollbackTransaction()
162 }() 175 }()
  176 +
163 var employeeDao *dao.EmployeeDao 177 var employeeDao *dao.EmployeeDao
164 if value, err := factory.CreateEmployeeDao(map[string]interface{}{ 178 if value, err := factory.CreateEmployeeDao(map[string]interface{}{
165 "transactionContext": transactionContext, 179 "transactionContext": transactionContext,
@@ -168,6 +182,7 @@ func (statisticsService *StatisticsService) PersonSuMoneyStatistics(personSuMone @@ -168,6 +182,7 @@ func (statisticsService *StatisticsService) PersonSuMoneyStatistics(personSuMone
168 } else { 182 } else {
169 employeeDao = value 183 employeeDao = value
170 } 184 }
  185 +
171 var employeeRepository domain.EmployeeRepository 186 var employeeRepository domain.EmployeeRepository
172 if value, err := factory.CreateEmployeeRepository(map[string]interface{}{ 187 if value, err := factory.CreateEmployeeRepository(map[string]interface{}{
173 "transactionContext": transactionContext, 188 "transactionContext": transactionContext,
@@ -176,6 +191,7 @@ func (statisticsService *StatisticsService) PersonSuMoneyStatistics(personSuMone @@ -176,6 +191,7 @@ func (statisticsService *StatisticsService) PersonSuMoneyStatistics(personSuMone
176 } else { 191 } else {
177 employeeRepository = value 192 employeeRepository = value
178 } 193 }
  194 +
179 employee, err := employeeRepository.FindOne(map[string]interface{}{ 195 employee, err := employeeRepository.FindOne(map[string]interface{}{
180 "uid": personSuMoneyStatisticsCommand.Uid, 196 "uid": personSuMoneyStatisticsCommand.Uid,
181 }) 197 })
@@ -185,6 +201,7 @@ func (statisticsService *StatisticsService) PersonSuMoneyStatistics(personSuMone @@ -185,6 +201,7 @@ func (statisticsService *StatisticsService) PersonSuMoneyStatistics(personSuMone
185 if employee == nil { 201 if employee == nil {
186 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的企业员工") 202 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的企业员工")
187 } 203 }
  204 +
188 if personSuMoneyStatistics, err := employeeDao.CalculatePersonSuMoney(personSuMoneyStatisticsCommand.Uid); err != nil { 205 if personSuMoneyStatistics, err := employeeDao.CalculatePersonSuMoney(personSuMoneyStatisticsCommand.Uid); err != nil {
189 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 206 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
190 } else { 207 } else {
@@ -196,6 +213,327 @@ func (statisticsService *StatisticsService) PersonSuMoneyStatistics(personSuMone @@ -196,6 +213,327 @@ func (statisticsService *StatisticsService) PersonSuMoneyStatistics(personSuMone
196 } 213 }
197 } 214 }
198 215
  216 +// 获取系统素币统计
  217 +func (statisticsService *StatisticsService) SystemSuMoneyStatistics(systemSuMoneyStatisticsCommand *command.SystemSuMoneyStatisticsCommand) (interface{}, error) {
  218 + if err := systemSuMoneyStatisticsCommand.ValidateCommand(); err != nil {
  219 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  220 + }
  221 + transactionContext, err := factory.CreateTransactionContext(nil)
  222 + if err != nil {
  223 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  224 + }
  225 + if err := transactionContext.StartTransaction(); err != nil {
  226 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  227 + }
  228 + defer func() {
  229 + transactionContext.RollbackTransaction()
  230 + }()
  231 +
  232 + var employeeDao *dao.EmployeeDao
  233 + if value, err := factory.CreateEmployeeDao(map[string]interface{}{
  234 + "transactionContext": transactionContext,
  235 + }); err != nil {
  236 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  237 + } else {
  238 + employeeDao = value
  239 + }
  240 +
  241 + if systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(systemSuMoneyStatisticsCommand.CompanyId); err != nil {
  242 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  243 + } else {
  244 + if err := transactionContext.CommitTransaction(); err != nil {
  245 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  246 + }
  247 + return systemSuMoneyStatistics, nil
  248 + }
  249 +}
  250 +
  251 +// 获取系统现金统计
  252 +func (statisticsService *StatisticsService) SystemCashStatistics(systemCashStatisticsCommand *command.SystemCashStatisticsCommand) (interface{}, error) {
  253 + if err := systemCashStatisticsCommand.ValidateCommand(); err != nil {
  254 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  255 + }
  256 + transactionContext, err := factory.CreateTransactionContext(nil)
  257 + if err != nil {
  258 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  259 + }
  260 + if err := transactionContext.StartTransaction(); err != nil {
  261 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  262 + }
  263 + defer func() {
  264 + transactionContext.RollbackTransaction()
  265 + }()
  266 +
  267 + var employeeDao *dao.EmployeeDao
  268 + if value, err := factory.CreateEmployeeDao(map[string]interface{}{
  269 + "transactionContext": transactionContext,
  270 + }); err != nil {
  271 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  272 + } else {
  273 + employeeDao = value
  274 + }
  275 +
  276 + // 判断现金池是否存在
  277 + var cashPoolRepository domain.CashPoolRepository
  278 + if value, err := factory.CreateCashPoolRepository(map[string] interface{} {
  279 + "transactionContext": transactionContext,
  280 + }); err != nil {
  281 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  282 + } else {
  283 + cashPoolRepository = value
  284 + }
  285 +
  286 + countCashPools, _, err := cashPoolRepository.Find(tool_funs.SimpleStructToMap(systemCashStatisticsCommand))
  287 + if err != nil {
  288 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  289 + }
  290 + if countCashPools == 0 { // 现金池为空时处理
  291 + return map[string]interface{} {
  292 + "systemExchangedCash" : 0,
  293 + "systemUnExchangeCash": 0,
  294 + }, nil
  295 + }
  296 +
  297 + if systemCashStatistics, err := employeeDao.CalculateSystemCash(systemCashStatisticsCommand.CompanyId); err != nil {
  298 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  299 + } else {
  300 + if err := transactionContext.CommitTransaction(); err != nil {
  301 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  302 + }
  303 + return systemCashStatistics, nil
  304 + }
  305 +}
  306 +
  307 +// 获取公司员工财富值分组统计
  308 +func (statisticsService *StatisticsService) EmployeesSuMoneyStatistics(employeesSuMoneyStatisticsCommand *command.EmployeesSuMoneyStatisticsCommand) (interface{}, error) {
  309 + if err := employeesSuMoneyStatisticsCommand.ValidateCommand(); err != nil {
  310 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  311 + }
  312 +
  313 + transactionContext, err := factory.CreateTransactionContext(nil)
  314 + if err != nil {
  315 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  316 + }
  317 + if err := transactionContext.StartTransaction(); err != nil {
  318 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  319 + }
  320 + defer func() {
  321 + transactionContext.RollbackTransaction()
  322 + }()
  323 +
  324 + var employeeDao *dao.EmployeeDao
  325 + if value, err := factory.CreateEmployeeDao(map[string]interface{}{
  326 + "transactionContext": transactionContext,
  327 + }); err != nil {
  328 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  329 + } else {
  330 + employeeDao = value
  331 + }
  332 +
  333 + if employeesSuMoneyStatisticsCommand.StartTime.IsZero() && employeesSuMoneyStatisticsCommand.EndTime.IsZero() {
  334 + employeesSuMoneyStatisticsCommand.StartTime = time.Date(1971, time.Month(1), 1, 0, 0, 0, 0, time.Now().Location())
  335 + employeesSuMoneyStatisticsCommand.EndTime = time.Now().Local()
  336 + }
  337 +
  338 + if employeesSuMoneyStatistics, err := employeeDao.CalculateEmployeesSuMoney(employeesSuMoneyStatisticsCommand.CompanyId, employeesSuMoneyStatisticsCommand.StartTime, employeesSuMoneyStatisticsCommand.EndTime); err != nil {
  339 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  340 + } else {
  341 + if err := transactionContext.CommitTransaction(); err != nil {
  342 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  343 + }
  344 + return employeesSuMoneyStatistics, nil
  345 + }
  346 +}
  347 +
  348 +// 获取公司员工贡献值分组统计
  349 +func (statisticsService *StatisticsService) EmployeesContributionsStatistics(employeesContributionsStatisticsCommand *command.EmployeesContributionsStatisticsCommand) (interface{}, error) {
  350 + if err := employeesContributionsStatisticsCommand.ValidateCommand(); err != nil {
  351 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  352 + }
  353 + transactionContext, err := factory.CreateTransactionContext(nil)
  354 + if err != nil {
  355 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  356 + }
  357 + if err := transactionContext.StartTransaction(); err != nil {
  358 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  359 + }
  360 + defer func() {
  361 + transactionContext.RollbackTransaction()
  362 + }()
  363 +
  364 + var employeeDao *dao.EmployeeDao
  365 + if value, err := factory.CreateEmployeeDao(map[string]interface{}{
  366 + "transactionContext": transactionContext,
  367 + }); err != nil {
  368 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  369 + } else {
  370 + employeeDao = value
  371 + }
  372 +
  373 + if employeesContributionsStatisticsCommand.StartTime.IsZero() && employeesContributionsStatisticsCommand.EndTime.IsZero() {
  374 + employeesContributionsStatisticsCommand.StartTime = time.Date(1971, time.Month(1), 1, 0, 0, 0, 0, time.Now().Location())
  375 + employeesContributionsStatisticsCommand.EndTime = time.Now().Local()
  376 + }
  377 +
  378 + if employeesContributionsStatistics, err := employeeDao.CalculateEmployeesContributions(employeesContributionsStatisticsCommand.CompanyId, employeesContributionsStatisticsCommand.StartTime, employeesContributionsStatisticsCommand.EndTime); err != nil {
  379 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  380 + } else {
  381 + if err := transactionContext.CommitTransaction(); err != nil {
  382 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  383 + }
  384 + return employeesContributionsStatistics, nil
  385 + }
  386 +}
  387 +
  388 +// 贡献值、财富值榜单
  389 +func (statisticsService *StatisticsService) ContributionsWealthRanking(contributionsWealthRankingQuery *query.ContributionsWealthRankingQuery) (interface{}, error) {
  390 + if err := contributionsWealthRankingQuery.ValidateQuery(); err != nil {
  391 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  392 + }
  393 +
  394 + transactionContext, err := factory.CreateTransactionContext(nil)
  395 + if err != nil {
  396 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  397 + }
  398 + if err := transactionContext.StartTransaction(); err != nil {
  399 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  400 + }
  401 + defer func() {
  402 + transactionContext.RollbackTransaction()
  403 + }()
  404 +
  405 + // 员工仓储初始化
  406 + var employeeRepository domain.EmployeeRepository
  407 + if value, err := factory.CreateEmployeeRepository(map[string]interface{}{
  408 + "transactionContext": transactionContext,
  409 + }); err != nil {
  410 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  411 + } else {
  412 + employeeRepository = value
  413 + }
  414 +
  415 + // 员工DAO初始化
  416 + var employeeDao *dao.EmployeeDao
  417 + if value, err := factory.CreateEmployeeDao(map[string]interface{}{
  418 + "transactionContext": transactionContext,
  419 + }); err != nil {
  420 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  421 + } else {
  422 + employeeDao = value
  423 + }
  424 +
  425 + if contributionsWealthRankingQuery.RankingType == 1 { // 返回总榜
  426 + contributionsWealthRankingQuery.StartTime = time.Date(0001, 01, 01, 0, 0, 0, 0, time.UTC)
  427 + contributionsWealthRankingQuery.EndTime = time.Date(0001, 01, 01, 0, 0, 0, 0, time.UTC)
  428 + } else if contributionsWealthRankingQuery.RankingType == 2 { // 返回年榜
  429 + // 获取公司最新年榜
  430 + var listIntervalRepository domain.ListIntervalRepository
  431 + if value, err := factory.CreateListIntervalRepository(map[string]interface{}{
  432 + "transactionContext": transactionContext,
  433 + }); err != nil {
  434 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  435 + } else {
  436 + listIntervalRepository = value
  437 + }
  438 +
  439 + listListIntervalQuery := map[string]interface{} {
  440 + "companyId": contributionsWealthRankingQuery.CompanyId,
  441 + }
  442 +
  443 + if _, listIntervals, err := listIntervalRepository.FindAll(listListIntervalQuery); err != nil {
  444 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  445 + } else {
  446 + if len(listIntervals) == 0 { // 未配置年榜
  447 + contributionsWealthRankingQuery.StartTime = time.Date(0001, 01, 02, 0, 0, 0, 0, time.Local)
  448 + contributionsWealthRankingQuery.EndTime = time.Date(0001, 01, 02, 0, 0, 0, 0, time.Local)
  449 + } else if len(listIntervals) == 1 { // 只配置了一个年榜
  450 + currentTime := time.Now().Unix()
  451 + if currentTime >= listIntervals[0].IntervalStartTime.Unix() && currentTime <= listIntervals[0].IntervalEndTime.Unix() {
  452 + contributionsWealthRankingQuery.StartTime = listIntervals[0].IntervalStartTime
  453 + contributionsWealthRankingQuery.EndTime = listIntervals[0].IntervalEndTime
  454 + } else { // 当前时间处于空档期
  455 + contributionsWealthRankingQuery.StartTime = time.Date(0001, 01, 02, 0, 0, 0, 0, time.Local)
  456 + contributionsWealthRankingQuery.EndTime = time.Date(0001, 01, 02, 0, 0, 0, 0, time.Local)
  457 + }
  458 + } else if len(listIntervals) > 1 { // 配置了多个年榜,判断当前时间是否在榜单里
  459 + currentTime := time.Now().Unix()
  460 + for _, listInterval := range listIntervals {
  461 + if currentTime >= listInterval.IntervalStartTime.Unix() && currentTime <= listInterval.IntervalEndTime.Unix() {
  462 + contributionsWealthRankingQuery.StartTime = listInterval.IntervalStartTime
  463 + contributionsWealthRankingQuery.EndTime = listInterval.IntervalEndTime
  464 + break
  465 + } else { // 当前时间处于空档期
  466 + contributionsWealthRankingQuery.StartTime = time.Date(0001, 01, 02, 0, 0, 0, 0, time.Local)
  467 + contributionsWealthRankingQuery.EndTime = time.Date(0001, 01, 02, 0, 0, 0, 0, time.Local)
  468 + continue
  469 + }
  470 + }
  471 + } else {
  472 + contributionsWealthRankingQuery.StartTime = time.Date(0001, 01, 02, 0, 0, 0, 0, time.Local)
  473 + contributionsWealthRankingQuery.EndTime = time.Date(0001, 01, 02, 0, 0, 0, 0, time.Local)
  474 + }
  475 + }
  476 + }
  477 +
  478 + // 默认返回总榜
  479 + if contributionsWealthRankingStatistics, err := employeeDao.ContributionsWealthRanking(tool_funs.SimpleStructToMap(contributionsWealthRankingQuery)); err != nil {
  480 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  481 + } else {
  482 + uidName := map[int64]interface{}{}
  483 + if _, employees, err := employeeRepository.FindAll(map[string]interface{}{
  484 + "companyId": contributionsWealthRankingQuery.CompanyId,
  485 + }); err != nil {
  486 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  487 + } else {
  488 + for _, employee := range employees {
  489 + uidName[employee.EmployeeInfo.Uid] = employee.EmployeeInfo.EmployeeName
  490 + }
  491 + }
  492 +
  493 + // 财富值排行榜
  494 + for i, _ := range contributionsWealthRankingStatistics.(map[string]interface{})["employeesWealth"].([]struct{Uid int64;EmployeeName string;EmployeeSuMoney float64;Ranking int}) {
  495 + uid := contributionsWealthRankingStatistics.(map[string]interface{})["employeesWealth"].([]struct{Uid int64;EmployeeName string;EmployeeSuMoney float64;Ranking int})[i].Uid
  496 + if uidName[uid] != nil {
  497 + contributionsWealthRankingStatistics.(map[string]interface{})["employeesWealth"].([]struct{Uid int64;EmployeeName string;EmployeeSuMoney float64;Ranking int})[i].EmployeeName = uidName[uid].(string)
  498 + }
  499 + }
  500 +
  501 + // 个人财富值
  502 + if contributionsWealthRankingStatistics.(map[string]interface{})["currentEmployeeWealth"] != nil {
  503 + currentEmployeeWealth := contributionsWealthRankingStatistics.(map[string]interface{})["currentEmployeeWealth"].(struct{Uid int64;EmployeeName string;EmployeeSuMoney float64;Ranking int})
  504 + uidWealth := contributionsWealthRankingStatistics.(map[string]interface{})["currentEmployeeWealth"].(struct{Uid int64;EmployeeName string;EmployeeSuMoney float64;Ranking int}).Uid
  505 + if uidName[uidWealth] != nil {
  506 + currentEmployeeWealth.EmployeeName = uidName[uidWealth].(string)
  507 + }
  508 + contributionsWealthRankingStatistics.(map[string]interface{})["currentEmployeeWealth"] = currentEmployeeWealth
  509 + }
  510 +
  511 + // 贡献值排行版
  512 + for i, _ := range contributionsWealthRankingStatistics.(map[string]interface{})["employeesContributions"].([]struct { Uid int64; EmployeeName string; EmployeesContributions float64; Ranking int }) {
  513 + uid := contributionsWealthRankingStatistics.(map[string]interface{})["employeesContributions"].([]struct{Uid int64;EmployeeName string;EmployeesContributions float64;Ranking int})[i].Uid
  514 + if uidName[uid] != nil {
  515 + contributionsWealthRankingStatistics.(map[string]interface{})["employeesContributions"].([]struct{Uid int64;EmployeeName string;EmployeesContributions float64;Ranking int})[i].EmployeeName = uidName[uid].(string)
  516 + }
  517 + }
  518 +
  519 + // 个人贡献值
  520 + if contributionsWealthRankingStatistics.(map[string]interface{})["currentEmployeeContributions"] != nil {
  521 + currentEmployeeContributions := contributionsWealthRankingStatistics.(map[string]interface{})["currentEmployeeContributions"].(struct{Uid int64;EmployeeName string;EmployeesContributions float64;Ranking int})
  522 + uidContributions := contributionsWealthRankingStatistics.(map[string]interface{})["currentEmployeeContributions"].(struct{Uid int64;EmployeeName string;EmployeesContributions float64;Ranking int}).Uid
  523 + if uidName[uidContributions] != nil {
  524 + currentEmployeeContributions.EmployeeName = uidName[uidContributions].(string)
  525 + }
  526 + contributionsWealthRankingStatistics.(map[string]interface{})["currentEmployeeContributions"] = currentEmployeeContributions
  527 + }
  528 +
  529 + if err := transactionContext.CommitTransaction(); err != nil {
  530 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  531 + }
  532 +
  533 + return contributionsWealthRankingStatistics, nil
  534 + }
  535 +}
  536 +
199 func NewStatisticsService(options map[string]interface{}) *StatisticsService { 537 func NewStatisticsService(options map[string]interface{}) *StatisticsService {
200 newStatisticsService := &StatisticsService{} 538 newStatisticsService := &StatisticsService{}
201 return newStatisticsService 539 return newStatisticsService
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/astaxie/beego/validation"
  6 + "time"
  7 +)
  8 +
  9 +type ContributionsTransactionRecordStatisticsCommand struct {
  10 + // 统一用户UID
  11 + Uid int64 `json:"uid" valid:"Required"`
  12 + // 事务时间区间-开始时间
  13 + TransactionStartTime time.Time `json:"transactionStartTime,omitempty"`
  14 + // 事务时间区间-截止时间
  15 + TransactionEndTime time.Time `json:"transactionEndTime,omitempty"`
  16 +}
  17 +
  18 +func (contributionsTransactionRecordStatisticsCommand *ContributionsTransactionRecordStatisticsCommand) ValidateCommand() error {
  19 + valid := validation.Validation{}
  20 + b, err := valid.Valid(contributionsTransactionRecordStatisticsCommand)
  21 + if err != nil {
  22 + return err
  23 + }
  24 + if !b {
  25 + for _, validErr := range valid.Errors {
  26 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  27 + }
  28 + }
  29 + return nil
  30 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 +
  6 + "github.com/astaxie/beego/validation"
  7 +)
  8 +
  9 +// 创建现金池
  10 +type CreateCashPoolCommand struct {
  11 + CompanyId int64 `json:"companyId" valid:"Required"` // 公司ID
  12 + Cash float64 `json:"cash" valid:"Required"` // 投入的现金值
  13 +}
  14 +
  15 +func (createCashPoolCommand *CreateCashPoolCommand) ValidateCommand() error {
  16 + valid := validation.Validation{}
  17 + rt, err := valid.Valid(createCashPoolCommand)
  18 + if err != nil {
  19 + return err
  20 + }
  21 + if !rt {
  22 + for _, validErr := range valid.Errors {
  23 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  24 + }
  25 + }
  26 + return nil
  27 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/astaxie/beego/validation"
  6 + "time"
  7 +)
  8 +
  9 +// 创建现金兑换活动
  10 +type CreateExchangeCashActivityCommand struct {
  11 + CompanyId int64 `json:"companyId" valid:"Required"` // 公司id
  12 + ExchangeActivityName string `json:"exchangeActivityName"` // 活动名称
  13 + Deadline time.Time `json:"deadline"` // 活动截止时间
  14 + ExchangeRate float64 `json:"exchangeRate"` // 兑换汇率
  15 + CreateTime time.Time `json:"createTime"` // 创建时间
  16 +}
  17 +
  18 +func (createExchangeActivityCommand *CreateExchangeCashActivityCommand) ValidateCommand() error {
  19 + valid := validation.Validation{}
  20 + b, err := valid.Valid(createExchangeActivityCommand)
  21 + if err != nil {
  22 + return err
  23 + }
  24 + if !b {
  25 + for _, validErr := range valid.Errors {
  26 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  27 + }
  28 + }
  29 + return nil
  30 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/astaxie/beego/validation"
  6 +)
  7 +
  8 +type CreateExchangeCashPersonCommand struct {
  9 + Uid int64 `json:"uid"` // 统一用户id
  10 + PersonName string `json:"personName,omitempty"` // 兑换现金人员名称
  11 + Operator int64 `json:"operator"` // 操作人
  12 + PersonAccount string `json:"personAccount,omitempty"` // 手机账号
  13 + ExchangeCashActivityId int64 `json:"exchangeCashActivityId" valid:"Required"` // 参与的兑换活动id
  14 + ExchangedSuMoney float64 `json:"exchangedSuMoney"` // 已兑换素币值
  15 +}
  16 +
  17 +func (createExchangeCashPersonCommand *CreateExchangeCashPersonCommand) ValidateCommand() error {
  18 + valid := validation.Validation{}
  19 + b, err := valid.Valid(createExchangeCashPersonCommand)
  20 + if err != nil {
  21 + return err
  22 + }
  23 + if !b {
  24 + for _, validErr := range valid.Errors {
  25 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  26 + }
  27 + }
  28 + return nil
  29 +}
@@ -7,14 +7,10 @@ import ( @@ -7,14 +7,10 @@ import (
7 ) 7 )
8 8
9 type ExchangeSuMoneyCommand struct { 9 type ExchangeSuMoneyCommand struct {
10 - // 兑换人UID  
11 - Uid int64 `json:"uid" valid:"Required"`  
12 - // 素币值  
13 - SuMoney float64 `json:"suMoney" valid:"Required"`  
14 - // 操作人UID  
15 - Operator int64 `json:"operator,omitempty"`  
16 - // 兑换描述  
17 - ExchangeDescription string `json:"exchangeDescription" valid:"Required"` 10 + Uid int64 `json:"uid" valid:"Required"` // 兑换人UID
  11 + SuMoney float64 `json:"suMoney" valid:"Required"` // 素币值
  12 + Operator int64 `json:"operator,omitempty"` // 操作人UID
  13 + ExchangeDescription string `json:"exchangeDescription" valid:"Required"` // 兑换描述
18 } 14 }
19 15
20 func (exchangeSuMoneyCommand *ExchangeSuMoneyCommand) ValidateCommand() error { 16 func (exchangeSuMoneyCommand *ExchangeSuMoneyCommand) ValidateCommand() error {
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/astaxie/beego/validation"
  6 +)
  7 +
  8 +type ExportExchangeCashListCommand struct {
  9 + Ids []int `json:"ids"`
  10 + Where map[string]interface{} `json:"where"`
  11 +}
  12 +
  13 +func (exportExchangeCashListCommand *ExportExchangeCashListCommand) ValidateCommand() error {
  14 + valid := validation.Validation{}
  15 + b, err := valid.Valid(exportExchangeCashListCommand)
  16 + if err != nil {
  17 + return err
  18 + }
  19 + if !b {
  20 + for _, validErr := range valid.Errors {
  21 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  22 + }
  23 + }
  24 + return nil
  25 +}
  26 +
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/astaxie/beego/validation"
  6 +)
  7 +
  8 +type ExportSuMoneyCommand struct {
  9 + Ids []int `json:"ids"` // 员工uid
  10 + Where map[string]interface{} `json:"where"`
  11 +}
  12 +
  13 +func (exportSuMoneyCommand *ExportSuMoneyCommand) ValidateCommand() error {
  14 + valid := validation.Validation{}
  15 + b, err := valid.Valid(exportSuMoneyCommand)
  16 + if err != nil {
  17 + return err
  18 + }
  19 + if !b {
  20 + for _, validErr := range valid.Errors {
  21 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  22 + }
  23 + }
  24 + return nil
  25 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/astaxie/beego/validation"
  6 +)
  7 +
  8 +type ExportTransactionRecordCommand struct {
  9 + Ids []int `json:"ids"`
  10 + Where map[string]interface{} `json:"where"`
  11 +}
  12 +
  13 +func (exportTransactionRecordCommand *ExportTransactionRecordCommand) ValidateCommand() error {
  14 + valid := validation.Validation{}
  15 + b, err := valid.Valid(exportTransactionRecordCommand)
  16 + if err != nil {
  17 + return err
  18 + }
  19 + if !b {
  20 + for _, validErr := range valid.Errors {
  21 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  22 + }
  23 + }
  24 + return nil
  25 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/astaxie/beego/validation"
  6 +)
  7 +
  8 +type ImportExchangeCashListCommand struct {
  9 + Where map[string]interface{} `json:"where"`
  10 +}
  11 +
  12 +func (importExchangeCashListCommand *ImportExchangeCashListCommand) ValidateCommand() error {
  13 + valid := validation.Validation{}
  14 + b, err := valid.Valid(importExchangeCashListCommand)
  15 + if err != nil {
  16 + return err
  17 + }
  18 + if !b {
  19 + for _, validErr := range valid.Errors {
  20 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  21 + }
  22 + }
  23 + return nil
  24 +}
@@ -7,16 +7,11 @@ import ( @@ -7,16 +7,11 @@ import (
7 ) 7 )
8 8
9 type OperationSuMoneyCommand struct { 9 type OperationSuMoneyCommand struct {
10 - // 素币拥有者UID  
11 - Uid int64 `json:"uid" valid:"Required"`  
12 - // 操作类型(1增加,2扣除)  
13 - OperationType int `json:"operationType" valid:"Required"`  
14 - // 素币值  
15 - SuMoney float64 `json:"suMoney" valid:"Required"`  
16 - // 操作人UID  
17 - Operator int64 `json:"operator,omitempty"`  
18 - // 理由描述  
19 - OperationDescription string `json:"operationDescription" valid:"Required"` 10 + Uid int64 `json:"uid" valid:"Required"` // 素币拥有者UID
  11 + OperationType int `json:"operationType" valid:"Required"` // 操作类型(1增加,2扣除, 3兑换物资, 4兑换现金)
  12 + SuMoney float64 `json:"suMoney" valid:"Required"` // 素币值
  13 + Operator int64 `json:"operator,omitempty"` // 操作人UID
  14 + OperationDescription string `json:"operationDescription" valid:"Required"` // 理由描述
20 } 15 }
21 16
22 func (operationSuMoneyCommand *OperationSuMoneyCommand) ValidateCommand() error { 17 func (operationSuMoneyCommand *OperationSuMoneyCommand) ValidateCommand() error {
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 +
  6 + "github.com/astaxie/beego/validation"
  7 +)
  8 +
  9 +// 删除兑换现金活动
  10 +type RemoveExchangeCashActivityCommand struct {
  11 + ActivityId int64 `json:"activityId" valid:"Required"`
  12 +}
  13 +
  14 +func (removeExchangeCashActivityCommand *RemoveExchangeCashActivityCommand) ValidateCommand() error {
  15 + valid := validation.Validation{}
  16 + b, err := valid.Valid(removeExchangeCashActivityCommand)
  17 + if err != nil {
  18 + return err
  19 + }
  20 + if !b {
  21 + for _, validErr := range valid.Errors {
  22 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  23 + }
  24 + }
  25 + return nil
  26 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/astaxie/beego/validation"
  6 +)
  7 +
  8 +// 移除兑换现金人员
  9 +type RemoveExchangeCashPersonCommand struct {
  10 + ListId int64 `json:"listId" valid:"Required"` // 兑换现金人员编号
  11 + Operator int64 `json:"operator,omitempty"` // 操作人
  12 +}
  13 +
  14 +func (removeExchangeCashPersonCommand *RemoveExchangeCashPersonCommand) ValidateCommand() error {
  15 + valid := validation.Validation{}
  16 + b, err := valid.Valid(removeExchangeCashPersonCommand)
  17 + if err != nil {
  18 + return err
  19 + }
  20 + if !b {
  21 + for _, validErr := range valid.Errors {
  22 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  23 + }
  24 + }
  25 + return nil
  26 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/astaxie/beego/validation"
  6 +)
  7 +
  8 +type SearchExchangeCashActivityCommand struct {
  9 + ActivityNameMatch string `json:"activityNameMatch"` // 兑换现金活动名称
  10 + CompanyId int64 `json:"companyId"` // 公司id
  11 + Deadline string `json:"deadline,omitempty"` // 截止时间筛选
  12 + Offset int `json:"offset,omitempty"` // 查询偏移量
  13 + Limit int `json:"limit,omitempty"` // 查询限制条目
  14 +}
  15 +
  16 +func (searchExchangeCashActivityCommand *SearchExchangeCashActivityCommand) ValidateCommand() error {
  17 + valid := validation.Validation{}
  18 + b, err := valid.Valid(searchExchangeCashActivityCommand)
  19 + if err != nil {
  20 + return err
  21 + }
  22 + if !b {
  23 + for _, validErr := range valid.Errors {
  24 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  25 + }
  26 + }
  27 + return nil
  28 +}
  29 +
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/astaxie/beego/validation"
  6 +)
  7 +
  8 +type SearchExchangeCashPersonCommand struct {
  9 + ListName string `json:"listName"` // 兑换素币人员名称
  10 +}
  11 +
  12 +func (searchExchangeCashPersonCommand *SearchExchangeCashPersonCommand) ValidateCommand() error {
  13 + valid := validation.Validation{}
  14 + b, err := valid.Valid(searchExchangeCashPersonCommand)
  15 + if err != nil {
  16 + return err
  17 + }
  18 + if !b {
  19 + for _, validErr := range valid.Errors {
  20 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  21 + }
  22 + }
  23 + return nil
  24 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/astaxie/beego/validation"
  6 +)
  7 +
  8 +type SearchSuMoneyTransactionCommand struct {
  9 + EmployeeName string `json:"employeeName"` // 员工姓名
  10 +}
  11 +
  12 +func (searchSuMoneyTransactionCommand *SearchSuMoneyTransactionCommand) ValidateCommand() error {
  13 + valid := validation.Validation{}
  14 + b, err := valid.Valid(searchSuMoneyTransactionCommand)
  15 + if err != nil {
  16 + return err
  17 + }
  18 + if !b {
  19 + for _, validErr := range valid.Errors {
  20 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  21 + }
  22 + }
  23 + return nil
  24 +}
@@ -9,17 +9,20 @@ import ( @@ -9,17 +9,20 @@ import (
9 9
10 type SearchSuMoneyTransactionRecordCommand struct { 10 type SearchSuMoneyTransactionRecordCommand struct {
11 // 统一用户UID 11 // 统一用户UID
12 - Uid int64 `json:"uid" valid:"Required"` 12 + //Uid int64 `json:"uid" valid:"Required"`
  13 + Uid int64 `json:"uid"`
13 // 记录类型(1兑换,2任务奖励,3增加,4扣除) 14 // 记录类型(1兑换,2任务奖励,3增加,4扣除)
14 RecordType int `json:"recordType,omitempty"` 15 RecordType int `json:"recordType,omitempty"`
15 // 记录类型列表(1兑换,2任务奖励,3增加,4扣除) 16 // 记录类型列表(1兑换,2任务奖励,3增加,4扣除)
16 RecordTypes []int `json:"recordTypes,omitempty"` 17 RecordTypes []int `json:"recordTypes,omitempty"`
17 - // 操作人UID  
18 // 事务时间区间-开始时间 18 // 事务时间区间-开始时间
19 TransactionStartTime time.Time `json:"transactionStartTime,omitempty"` 19 TransactionStartTime time.Time `json:"transactionStartTime,omitempty"`
20 // 事务时间区间-截止时间 20 // 事务时间区间-截止时间
21 TransactionEndTime time.Time `json:"transactionEndTime,omitempty"` 21 TransactionEndTime time.Time `json:"transactionEndTime,omitempty"`
  22 + // 操作人UID
22 Operator int64 `json:"operator,omitempty"` 23 Operator int64 `json:"operator,omitempty"`
  24 + // 关联人员姓名
  25 + EmployeeMatchName string `json:"employeeMatchName"`
23 // 查询偏离量 26 // 查询偏离量
24 Offset int `json:"offset,omitempty"` 27 Offset int `json:"offset,omitempty"`
25 // 查询限制 28 // 查询限制
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/astaxie/beego/validation"
  6 +)
  7 +
  8 +type UpdateCashPoolCommand struct {
  9 + CashPoolId int64 `json:"cashPoolId"` // 现金池编号
  10 + ExchangedCash float64 `json:"exchangedCash"` // 已兑换现金
  11 + ExchangedSuMoney float64 `json:"exchangedSuMoney"` // 已兑换素币
  12 + UnExchangeCash float64 `json:"unExchangeCash"` // 未兑换现金
  13 + UnExchangeSuMoney float64 `json:"unExchangeSuMoney"` // 未兑换素币
  14 + Rate float64 `json:"rate"` // 平均兑换汇率
  15 + Cash float64 `json:"cash"`
  16 + //CompanyId int64 `json:"companyId"`
  17 + LastRate float64 `json:"lastRate"`
  18 + //CreateTime time.Time `json:"createTime"`
  19 +}
  20 +
  21 +func (updateCashPoolCommand *UpdateCashPoolCommand) ValidateCommand() error {
  22 + valid := validation.Validation{}
  23 + b, err := valid.Valid(updateCashPoolCommand)
  24 + if err != nil {
  25 + return err
  26 + }
  27 + if !b {
  28 + for _, validErr := range valid.Errors {
  29 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  30 + }
  31 + }
  32 + return nil
  33 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/astaxie/beego/validation"
  6 + "time"
  7 +)
  8 +
  9 +type UpdateExchangeCashActivityCommand struct {
  10 + ExchangeCashActivityId int64 `json:"exchangeCashActivityId"` // 兑换现金活动id
  11 + ExchangeActivityName string `json:"exchangeActivityName"` // 活动名称
  12 + Deadline time.Time `json:"deadline"` // 活动截止时间
  13 + CountDown int64 `json:"countDown"` // 活动倒计时
  14 + ExchangedSuMoney float64 `json:"exchangedSuMoney"` // 已兑换素币
  15 + ExchangedCash float64 `json:"exchangedCash"` // 已兑换现金
  16 + ExchangeRate float64 `json:"exchangeRate"` // 兑换汇率
  17 +}
  18 +
  19 +func (updateExchangeCashActivity *UpdateExchangeCashActivityCommand) ValidateCommand() error {
  20 + valid := validation.Validation{}
  21 + b, err := valid.Valid(updateExchangeCashActivity)
  22 + if err != nil {
  23 + return err
  24 + }
  25 + if !b {
  26 + for _, validErr := range valid.Errors {
  27 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  28 + }
  29 + }
  30 + return nil
  31 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/astaxie/beego/validation"
  6 +)
  7 +
  8 +type UpdateExchangeCashPersonCommand struct {
  9 + ListId int64 `json:"listId" valid:"Required"` // 兑换现金人员编号
  10 + ExchangedSuMoney float64 `json:"exchangedSuMoney"` // 已兑换的素币(需要和当前的已兑换素币进行比较,少于当前已兑换素币则生成一条扣除素币记录,大于当前已兑换素币则生成一条增加素币记录)
  11 + ExchangedCash float64 `json:"exchangedCash"` // 已兑换现金
  12 + Operator int64 `json:"operator,omitempty"` // 操作人
  13 +}
  14 +
  15 +func (updateExchangeCashPersonCommand *UpdateExchangeCashPersonCommand) ValidateCommand() error {
  16 + valid := validation.Validation{}
  17 + b, err := valid.Valid(updateExchangeCashPersonCommand)
  18 + if err != nil {
  19 + return err
  20 + }
  21 + if !b {
  22 + for _, validErr := range valid.Errors {
  23 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  24 + }
  25 + }
  26 + return nil
  27 +}
  1 +package query
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/astaxie/beego/validation"
  6 + "time"
  7 +)
  8 +
  9 +type ContributionsWealthRankingQuery struct {
  10 + CompanyId int64 `json:"companyId" valid:"Required"` // 公司ID
  11 + RankingType int `json:"rankingType" valid:"Required"` // 榜单类型,区分总榜和年榜 1:总榜,2:年榜
  12 + Offset int `json:"offset,omitempty"` // 查询偏离量
  13 + Limit int `json:"limit,omitempty"` // 查询限制
  14 + Uid int64 `json:"uid" valid:"Required"` // 统一用户id
  15 + StartTime time.Time `json:"startTime"` // 榜单开始时间,由后台根据榜单类型后去
  16 + EndTime time.Time `json:"endTime"` // 榜单结束更新,由后台根据榜单类型获取
  17 +}
  18 +
  19 +func (contributionsWealthRankingQuery *ContributionsWealthRankingQuery) ValidateQuery() error {
  20 + valid := validation.Validation{}
  21 + b, err := valid.Valid(contributionsWealthRankingQuery)
  22 + if err != nil {
  23 + return err
  24 + }
  25 + if !b {
  26 + for _, validErr := range valid.Errors {
  27 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  28 + }
  29 + }
  30 + return nil
  31 +}
  1 +package query
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/astaxie/beego/validation"
  6 +)
  7 +
  8 +type ExchangeListRankingQuery struct {
  9 + ActivityId int64 `json:"activityId"`
  10 + CompanyId int64 `json:"companyId"` // 公司ID
  11 + Offset int `json:"offset,omitempty"` // 查询偏离量
  12 + Limit int `json:"limit,omitempty"` // 查询限制
  13 + Uid int64 `json:"uid"` // 统一用户id
  14 +}
  15 +
  16 +func (exchangeListRankingQuery *ExchangeListRankingQuery) ValidateCommand() error {
  17 + valid := validation.Validation{}
  18 + b, err := valid.Valid(exchangeListRankingQuery)
  19 + if err != nil {
  20 + return err
  21 + }
  22 + if !b {
  23 + for _, validErr := range valid.Errors {
  24 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  25 + }
  26 + }
  27 + return nil
  28 +}
  1 +package query
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/astaxie/beego/validation"
  6 +)
  7 +
  8 +// 获取现金池
  9 +type GetCashPoolQuery struct {
  10 + CompanyId int64 `json:"companyId" valid:"Required"` // 公司id
  11 +}
  12 +
  13 +func (getCashPoolQuery *GetCashPoolQuery) ValidateQuery() error {
  14 + valid := validation.Validation{}
  15 + b, err := valid.Valid(getCashPoolQuery)
  16 + if err != nil {
  17 + return err
  18 + }
  19 + if !b {
  20 + for _, validErr := range valid.Errors {
  21 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  22 + }
  23 + }
  24 + return nil
  25 +}
  1 +package query
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/astaxie/beego/validation"
  6 +)
  7 +
  8 +// 获取兑换现金活动
  9 +type GetExchangeCashActivityQuery struct {
  10 + ExchangeCashActivityId int64 `json:"exchangeCashActivityId"` // 兑换现金活动id
  11 +}
  12 +
  13 +func (getExchangeCashActivityQuery *GetExchangeCashActivityQuery) ValidateQuery() error {
  14 + valid := validation.Validation{}
  15 + b, err := valid.Valid(getExchangeCashActivityQuery)
  16 + if err != nil {
  17 + return err
  18 + }
  19 + if !b {
  20 + for _, validErr := range valid.Errors {
  21 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  22 + }
  23 + }
  24 + return nil
  25 +}
  1 +package query
  2 +
  3 +import (
  4 + "fmt"
  5 +
  6 + "github.com/astaxie/beego/validation"
  7 +)
  8 +
  9 +type GetExchangeCashPersonQuery struct {
  10 + ExchangeCashPersonId int64 `json:"exchangeCashPersonId"` // 参与兑换现金活动人员id
  11 +}
  12 +
  13 +func (getExchangeCashPersonQuery *GetExchangeCashPersonQuery) ValidateQuery() error {
  14 + valid := validation.Validation{}
  15 + b, err := valid.Valid(getExchangeCashPersonQuery)
  16 + if err != nil {
  17 + return err
  18 + }
  19 + if !b {
  20 + for _, validErr := range valid.Errors {
  21 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  22 + }
  23 + }
  24 + return nil
  25 +}
  1 +package query
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/astaxie/beego/validation"
  6 +)
  7 +
  8 +// 获取兑换现金活动列表
  9 +type ListExchangeCashActivityQuery struct {
  10 + CompanyId int64 `json:"companyId"` // 公司id
  11 + ActivityNameMatch string `json:"activityNameMatch,omitempty"` // 活动名称匹配
  12 + //Deadline time.Time `json:"deadline,omitempty"` // 截止时间筛选
  13 + IsEnd bool `json:"isEnd"` // 已结束活动和未结束活动筛选 true: 已结束活动 false: 未结束活动
  14 + Offset int `json:"offset,omitempty"` // 查询偏移量
  15 + Limit int `json:"limit,omitempty"` // 查询限制条目
  16 +}
  17 +
  18 +func (listExchangeCashActivityQuery *ListExchangeCashActivityQuery) ValidateQuery() error {
  19 + valid := validation.Validation{}
  20 + b, err := valid.Valid(listExchangeCashActivityQuery)
  21 + if err != nil {
  22 + return err
  23 + }
  24 + if !b {
  25 + for _, validErr := range valid.Errors {
  26 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  27 + }
  28 + }
  29 + return nil
  30 +}
  1 +package query
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/astaxie/beego/validation"
  6 +)
  7 +
  8 +type ListExchangeCashActivityDeadlineQuery struct {
  9 + CompanyId int64 `json:"companyId"` // 公司id
  10 +}
  11 +
  12 +func (listExchangeCashActivityDeadlineQuery *ListExchangeCashActivityDeadlineQuery) ValidateQuery() error {
  13 + valid := validation.Validation{}
  14 + b, err := valid.Valid(listExchangeCashActivityDeadlineQuery)
  15 + if err != nil {
  16 + return err
  17 + }
  18 + if !b {
  19 + for _, validErr := range valid.Errors {
  20 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  21 + }
  22 + }
  23 + return nil
  24 +}
  1 +package query
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/astaxie/beego/validation"
  6 +)
  7 +
  8 +// 获取兑换活动兑换清单
  9 +type ListExchangeCashPersonQuery struct {
  10 + CompanyId int64 `json:"companyId"` // 公司id
  11 + ExchangeCashActivityId int64 `json:"exchangeCashActivityId"` // 兑换现金活动id
  12 + ExchangeCashPersonNameMatch string `json:"exchangeCashPersonNameMatch,omitempty"` // 兑换活动名称匹配
  13 + Offset int `json:"offset,omitempty"` // 查询偏离量
  14 + Limit int `json:"limit,omitempty"` // 查询限制
  15 +}
  16 +
  17 +func (listExchangeCashPersonQuery *ListExchangeCashPersonQuery) ValidateQuery() error {
  18 + valid := validation.Validation{}
  19 + b, err := valid.Valid(listExchangeCashPersonQuery)
  20 + if err != nil {
  21 + return err
  22 + }
  23 + if !b {
  24 + for _, validErr := range valid.Errors {
  25 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  26 + }
  27 + }
  28 + return nil
  29 +}
@@ -30,6 +30,18 @@ func (suMoneyService *SuMoneyService) OperationSuMoney(operationSuMoneyCommand * @@ -30,6 +30,18 @@ func (suMoneyService *SuMoneyService) OperationSuMoney(operationSuMoneyCommand *
30 defer func() { 30 defer func() {
31 transactionContext.RollbackTransaction() 31 transactionContext.RollbackTransaction()
32 }() 32 }()
  33 +
  34 + // 员工仓储初始化
  35 + var employeeRepository domain.EmployeeRepository
  36 + if value, err := factory.CreateEmployeeRepository(map[string]interface{}{
  37 + "transactionContext": transactionContext,
  38 + }); err != nil {
  39 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  40 + } else {
  41 + employeeRepository = value
  42 + }
  43 +
  44 + // 操作素币服务初始化
33 var operationSuMoneyService service.OperationSuMoneyService 45 var operationSuMoneyService service.OperationSuMoneyService
34 if value, err := factory.CreateOperationSuMoneyService(map[string]interface{}{ 46 if value, err := factory.CreateOperationSuMoneyService(map[string]interface{}{
35 "transactionContext": transactionContext, 47 "transactionContext": transactionContext,
@@ -38,6 +50,20 @@ func (suMoneyService *SuMoneyService) OperationSuMoney(operationSuMoneyCommand * @@ -38,6 +50,20 @@ func (suMoneyService *SuMoneyService) OperationSuMoney(operationSuMoneyCommand *
38 } else { 50 } else {
39 operationSuMoneyService = value 51 operationSuMoneyService = value
40 } 52 }
  53 +
  54 + // 判断当前员工是否有效
  55 + getEmployee := map[string]interface{}{
  56 + "uid": operationSuMoneyCommand.Uid,
  57 + "status": 1,
  58 + }
  59 + employeeFound, err := employeeRepository.FindOne(getEmployee)
  60 + if err != nil {
  61 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  62 + }
  63 + if employeeFound == nil {
  64 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的员工")
  65 + }
  66 +
41 if task, err := operationSuMoneyService.Operation(operationSuMoneyCommand.Uid, operationSuMoneyCommand.Operator, operationSuMoneyCommand.SuMoney, operationSuMoneyCommand.OperationType, operationSuMoneyCommand.OperationDescription); err != nil { 67 if task, err := operationSuMoneyService.Operation(operationSuMoneyCommand.Uid, operationSuMoneyCommand.Operator, operationSuMoneyCommand.SuMoney, operationSuMoneyCommand.OperationType, operationSuMoneyCommand.OperationDescription); err != nil {
42 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 68 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
43 } else { 69 } else {
@@ -63,6 +89,7 @@ func (suMoneyService *SuMoneyService) GetSuMoneyTransactionRecord(getSuMoneyTran @@ -63,6 +89,7 @@ func (suMoneyService *SuMoneyService) GetSuMoneyTransactionRecord(getSuMoneyTran
63 defer func() { 89 defer func() {
64 transactionContext.RollbackTransaction() 90 transactionContext.RollbackTransaction()
65 }() 91 }()
  92 +
66 var suMoneyTransactionRecordRepository domain.SuMoneyTransactionRecordRepository 93 var suMoneyTransactionRecordRepository domain.SuMoneyTransactionRecordRepository
67 if value, err := factory.CreateSuMoneyTransactionRecordRepository(map[string]interface{}{ 94 if value, err := factory.CreateSuMoneyTransactionRecordRepository(map[string]interface{}{
68 "transactionContext": transactionContext, 95 "transactionContext": transactionContext,
@@ -71,6 +98,7 @@ func (suMoneyService *SuMoneyService) GetSuMoneyTransactionRecord(getSuMoneyTran @@ -71,6 +98,7 @@ func (suMoneyService *SuMoneyService) GetSuMoneyTransactionRecord(getSuMoneyTran
71 } else { 98 } else {
72 suMoneyTransactionRecordRepository = value 99 suMoneyTransactionRecordRepository = value
73 } 100 }
  101 +
74 if suMoneyTransactionRecord, err := suMoneyTransactionRecordRepository.FindOne(map[string]interface{}{"suMoneyTransactionRecordId": getSuMoneyTransactionRecordQuery.SuMoneyTransactionRecordId}); err != nil { 102 if suMoneyTransactionRecord, err := suMoneyTransactionRecordRepository.FindOne(map[string]interface{}{"suMoneyTransactionRecordId": getSuMoneyTransactionRecordQuery.SuMoneyTransactionRecordId}); err != nil {
75 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 103 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
76 } else { 104 } else {
@@ -96,6 +124,7 @@ func (suMoneyService *SuMoneyService) ExchangeSuMoney(exchangeSuMoneyCommand *co @@ -96,6 +124,7 @@ func (suMoneyService *SuMoneyService) ExchangeSuMoney(exchangeSuMoneyCommand *co
96 defer func() { 124 defer func() {
97 transactionContext.RollbackTransaction() 125 transactionContext.RollbackTransaction()
98 }() 126 }()
  127 +
99 var exchangeSuMoneyService service.ExchangeSuMoneyService 128 var exchangeSuMoneyService service.ExchangeSuMoneyService
100 if value, err := factory.CreateExchangeSuMoneyService(map[string]interface{}{ 129 if value, err := factory.CreateExchangeSuMoneyService(map[string]interface{}{
101 "transactionContext": transactionContext, 130 "transactionContext": transactionContext,
@@ -104,6 +133,7 @@ func (suMoneyService *SuMoneyService) ExchangeSuMoney(exchangeSuMoneyCommand *co @@ -104,6 +133,7 @@ func (suMoneyService *SuMoneyService) ExchangeSuMoney(exchangeSuMoneyCommand *co
104 } else { 133 } else {
105 exchangeSuMoneyService = value 134 exchangeSuMoneyService = value
106 } 135 }
  136 +
107 if task, err := exchangeSuMoneyService.Exchange(exchangeSuMoneyCommand.Uid, exchangeSuMoneyCommand.Operator, exchangeSuMoneyCommand.SuMoney, exchangeSuMoneyCommand.ExchangeDescription); err != nil { 137 if task, err := exchangeSuMoneyService.Exchange(exchangeSuMoneyCommand.Uid, exchangeSuMoneyCommand.Operator, exchangeSuMoneyCommand.SuMoney, exchangeSuMoneyCommand.ExchangeDescription); err != nil {
108 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 138 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
109 } else { 139 } else {
@@ -129,6 +159,8 @@ func (suMoneyService *SuMoneyService) SearchSuMoneyTransactionRecord(searchSuMon @@ -129,6 +159,8 @@ func (suMoneyService *SuMoneyService) SearchSuMoneyTransactionRecord(searchSuMon
129 defer func() { 159 defer func() {
130 transactionContext.RollbackTransaction() 160 transactionContext.RollbackTransaction()
131 }() 161 }()
  162 +
  163 + // 素币事务记录仓储初始化
132 var suMoneyTransactionRecordRepository domain.SuMoneyTransactionRecordRepository 164 var suMoneyTransactionRecordRepository domain.SuMoneyTransactionRecordRepository
133 if value, err := factory.CreateSuMoneyTransactionRecordRepository(map[string]interface{}{ 165 if value, err := factory.CreateSuMoneyTransactionRecordRepository(map[string]interface{}{
134 "transactionContext": transactionContext, 166 "transactionContext": transactionContext,
@@ -137,20 +169,57 @@ func (suMoneyService *SuMoneyService) SearchSuMoneyTransactionRecord(searchSuMon @@ -137,20 +169,57 @@ func (suMoneyService *SuMoneyService) SearchSuMoneyTransactionRecord(searchSuMon
137 } else { 169 } else {
138 suMoneyTransactionRecordRepository = value 170 suMoneyTransactionRecordRepository = value
139 } 171 }
  172 +
  173 + // 获取素币兑换事务记录
140 if count, suMoneyTransactionRecords, err := suMoneyTransactionRecordRepository.Find(tool_funs.SimpleStructToMap(searchSuMoneyTransactionRecordCommand)); err != nil { 174 if count, suMoneyTransactionRecords, err := suMoneyTransactionRecordRepository.Find(tool_funs.SimpleStructToMap(searchSuMoneyTransactionRecordCommand)); err != nil {
141 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 175 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
142 } else { 176 } else {
143 if err := transactionContext.CommitTransaction(); err != nil { 177 if err := transactionContext.CommitTransaction(); err != nil {
144 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 178 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
145 } 179 }
  180 + var suMoneyTransactionRecordsFormat []interface{}
  181 + for _, suMoneyTransactionRecord := range suMoneyTransactionRecords {
  182 + suMoneyTransactionRecordFormat := map[string]interface{} {
  183 + "suMoneyTransactionRecordId": suMoneyTransactionRecord.SuMoneyTransactionRecordId,
  184 + "recordType": suMoneyTransactionRecord.RecordType,
  185 + "employee": map[string]interface{} {
  186 + "uid": suMoneyTransactionRecord.Employee.Uid,
  187 + "employeeName": suMoneyTransactionRecord.Employee.EmployeeName,
  188 + "employeeAccount": suMoneyTransactionRecord.Employee.EmployeeAccount,
  189 + "employeeAvatarUrl": suMoneyTransactionRecord.Employee.EmployeeAvatarUrl,
  190 + "isPrincipal": suMoneyTransactionRecord.Employee.IsPrincipal,
  191 + },
  192 + "suMoneyBeforeTransaction": suMoneyTransactionRecord.SuMoneyBeforeTransaction,
  193 + "currentSuMoney": suMoneyTransactionRecord.CurrentSuMoney,
  194 + "suMoney": suMoneyTransactionRecord.SuMoney,
  195 + "cashBeforeTransaction": suMoneyTransactionRecord.CashBeforeTransaction,
  196 + "currentCash": suMoneyTransactionRecord.CurrentCash,
  197 + "cash": suMoneyTransactionRecord.Cash,
  198 + "operator": map[string]interface{} {
  199 + "uid": suMoneyTransactionRecord.Operator.Uid,
  200 + "employeeName": suMoneyTransactionRecord.Operator.EmployeeName,
  201 + "employeeAccount": suMoneyTransactionRecord.Operator.EmployeeAccount,
  202 + "employeeAvatarUrl": suMoneyTransactionRecord.Operator.EmployeeAvatarUrl,
  203 + "isPrincipal": suMoneyTransactionRecord.Operator.IsPrincipal,
  204 + },
  205 + "recordDescription": suMoneyTransactionRecord.RecordDescription,
  206 + "createTime": suMoneyTransactionRecord.CreateTime.Local(),
  207 + }
  208 + suMoneyTransactionRecordsFormat = append(suMoneyTransactionRecordsFormat, suMoneyTransactionRecordFormat)
  209 + }
  210 +
  211 + if len(suMoneyTransactionRecordsFormat) == 0 {
  212 + suMoneyTransactionRecordsFormat = []interface{}{}
  213 + }
  214 +
146 return map[string]interface{}{ 215 return map[string]interface{}{
147 "count": count, 216 "count": count,
148 - "suMoneyTransactionRecords": suMoneyTransactionRecords, 217 + "suMoneyTransactionRecords": suMoneyTransactionRecordsFormat,
149 }, nil 218 }, nil
150 } 219 }
151 } 220 }
152 221
153 -// 素币事务记录统计 222 +// 素币事务记录统计(个人素币)
154 func (suMoneyService *SuMoneyService) SuMoneyTransactionRecordStatistics(suMoneyTransactionRecordStatisticsCommand *command.SuMoneyTransactionRecordStatisticsCommand) (interface{}, error) { 223 func (suMoneyService *SuMoneyService) SuMoneyTransactionRecordStatistics(suMoneyTransactionRecordStatisticsCommand *command.SuMoneyTransactionRecordStatisticsCommand) (interface{}, error) {
155 if err := suMoneyTransactionRecordStatisticsCommand.ValidateCommand(); err != nil { 224 if err := suMoneyTransactionRecordStatisticsCommand.ValidateCommand(); err != nil {
156 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 225 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
@@ -165,6 +234,8 @@ func (suMoneyService *SuMoneyService) SuMoneyTransactionRecordStatistics(suMoney @@ -165,6 +234,8 @@ func (suMoneyService *SuMoneyService) SuMoneyTransactionRecordStatistics(suMoney
165 defer func() { 234 defer func() {
166 transactionContext.RollbackTransaction() 235 transactionContext.RollbackTransaction()
167 }() 236 }()
  237 +
  238 + // 员工DAO初始化
168 var employeeDao *dao.EmployeeDao 239 var employeeDao *dao.EmployeeDao
169 if value, err := factory.CreateEmployeeDao(map[string]interface{}{ 240 if value, err := factory.CreateEmployeeDao(map[string]interface{}{
170 "transactionContext": transactionContext, 241 "transactionContext": transactionContext,
@@ -173,6 +244,7 @@ func (suMoneyService *SuMoneyService) SuMoneyTransactionRecordStatistics(suMoney @@ -173,6 +244,7 @@ func (suMoneyService *SuMoneyService) SuMoneyTransactionRecordStatistics(suMoney
173 } else { 244 } else {
174 employeeDao = value 245 employeeDao = value
175 } 246 }
  247 +
176 if calculateResult, err := employeeDao.CalculateSuMoneyTransactionRecord(suMoneyTransactionRecordStatisticsCommand.Uid, suMoneyTransactionRecordStatisticsCommand.TransactionStartTime, suMoneyTransactionRecordStatisticsCommand.TransactionEndTime); err != nil { 248 if calculateResult, err := employeeDao.CalculateSuMoneyTransactionRecord(suMoneyTransactionRecordStatisticsCommand.Uid, suMoneyTransactionRecordStatisticsCommand.TransactionStartTime, suMoneyTransactionRecordStatisticsCommand.TransactionEndTime); err != nil {
177 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 249 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
178 } else { 250 } else {
@@ -183,6 +255,123 @@ func (suMoneyService *SuMoneyService) SuMoneyTransactionRecordStatistics(suMoney @@ -183,6 +255,123 @@ func (suMoneyService *SuMoneyService) SuMoneyTransactionRecordStatistics(suMoney
183 } 255 }
184 } 256 }
185 257
  258 +// 贡献值事务记录统计(个人贡献值)
  259 +func (suMoneyService *SuMoneyService) ContributionsTransactionRecordStatistics(contributionsTransactionRecordStatisticsCommand *command.ContributionsTransactionRecordStatisticsCommand) (interface{}, error) {
  260 + if err := contributionsTransactionRecordStatisticsCommand.ValidateCommand(); err != nil {
  261 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  262 + }
  263 + transactionContext, err := factory.CreateTransactionContext(nil)
  264 + if err != nil {
  265 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  266 + }
  267 + if err := transactionContext.StartTransaction(); err != nil {
  268 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  269 + }
  270 + defer func() {
  271 + transactionContext.RollbackTransaction()
  272 + }()
  273 +
  274 + var employeeDao *dao.EmployeeDao
  275 + if value, err := factory.CreateEmployeeDao(map[string]interface{}{
  276 + "transactionContext": transactionContext,
  277 + }); err != nil {
  278 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  279 + } else {
  280 + employeeDao = value
  281 + }
  282 +
  283 + if calculateResult, err := employeeDao.CalculateContributionsTransactionRecord(contributionsTransactionRecordStatisticsCommand.Uid, contributionsTransactionRecordStatisticsCommand.TransactionStartTime, contributionsTransactionRecordStatisticsCommand.TransactionEndTime); err != nil {
  284 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  285 + } else {
  286 + if err := transactionContext.CommitTransaction(); err != nil {
  287 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  288 + }
  289 + return calculateResult, nil
  290 + }
  291 +}
  292 +
  293 +// 根据uid获取员工素币(导出素币流水)
  294 +func (suMoneyService *SuMoneyService) ListSuMoneyById(exportSuMoneyCommand *command.ExportSuMoneyCommand) ([]*domain.Employee, error) {
  295 + if err := exportSuMoneyCommand.ValidateCommand(); err != nil {
  296 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  297 + }
  298 +
  299 + transactionContext, err := factory.CreateTransactionContext(nil)
  300 + if err != nil {
  301 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  302 + }
  303 + if err := transactionContext.StartTransaction(); err != nil {
  304 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  305 + }
  306 + defer func() {
  307 + transactionContext.RollbackTransaction()
  308 + }()
  309 +
  310 + if len(exportSuMoneyCommand.Ids) == 0 && exportSuMoneyCommand.Where == nil {
  311 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "未勾选需要导出的数据")
  312 + }
  313 +
  314 + // 员工仓储初始化
  315 + var employeeRepository domain.EmployeeRepository
  316 + if value, err := factory.CreateEmployeeRepository(map[string]interface{}{
  317 + "transactionContext": transactionContext,
  318 + }); err != nil {
  319 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  320 + } else {
  321 + employeeRepository = value
  322 + }
  323 +
  324 + if _, employees, err := employeeRepository.FindByIds(tool_funs.SimpleStructToMap(exportSuMoneyCommand)); err != nil {
  325 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  326 + } else {
  327 + if err := transactionContext.CommitTransaction(); err != nil {
  328 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  329 + }
  330 + return employees, nil
  331 + }
  332 +}
  333 +
  334 +// 根据id获取事务记录(导出素币流水记录)
  335 +func (suMoneyService *SuMoneyService) ListSuMoneyTransactionRecordById(exportSuMoneyTransactionRecordCommand *command.ExportTransactionRecordCommand) ([]*domain.SuMoneyTransactionRecord, error) {
  336 + if err := exportSuMoneyTransactionRecordCommand.ValidateCommand(); err != nil {
  337 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  338 + }
  339 +
  340 + transactionContext, err := factory.CreateTransactionContext(nil)
  341 + if err != nil {
  342 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  343 + }
  344 + if err := transactionContext.StartTransaction(); err != nil {
  345 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  346 + }
  347 + defer func() {
  348 + transactionContext.RollbackTransaction()
  349 + }()
  350 +
  351 + if len(exportSuMoneyTransactionRecordCommand.Ids) == 0 && exportSuMoneyTransactionRecordCommand.Where == nil {
  352 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "未勾选需要导出的数据")
  353 + }
  354 +
  355 + var suMoneyTransactionRecordRepository domain.SuMoneyTransactionRecordRepository
  356 + if value, err := factory.CreateSuMoneyTransactionRecordRepository(map[string]interface{}{
  357 + "transactionContext": transactionContext,
  358 + }); err != nil {
  359 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  360 + } else {
  361 + suMoneyTransactionRecordRepository = value
  362 + }
  363 +
  364 + if _, suMoneyTransactionRecords, err := suMoneyTransactionRecordRepository.FindById(tool_funs.SimpleStructToMap(exportSuMoneyTransactionRecordCommand)); err != nil {
  365 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  366 + } else {
  367 + if err := transactionContext.CommitTransaction(); err != nil {
  368 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  369 + }
  370 + return suMoneyTransactionRecords, nil
  371 + }
  372 +}
  373 +
  374 +
186 func NewSuMoneyService(options map[string]interface{}) *SuMoneyService { 375 func NewSuMoneyService(options map[string]interface{}) *SuMoneyService {
187 newSuMoneyService := &SuMoneyService{} 376 newSuMoneyService := &SuMoneyService{}
188 return newSuMoneyService 377 return newSuMoneyService
@@ -15,6 +15,8 @@ type AcceptanceTaskCommand struct { @@ -15,6 +15,8 @@ type AcceptanceTaskCommand struct {
15 Operator int64 `json:"operator" valid:"Required"` 15 Operator int64 `json:"operator" valid:"Required"`
16 // 任务参与者UID列表 16 // 任务参与者UID列表
17 Participators []int64 `json:"participators,omitempty"` 17 Participators []int64 `json:"participators,omitempty"`
  18 + // 实际奖励素币值
  19 + SuMoney float64 `jsons:"suMoney"`
18 // 任务贡献占比 20 // 任务贡献占比
19 TaskPercentage []*domain.TaskPercentageItem `json:"taskPercentage"` 21 TaskPercentage []*domain.TaskPercentageItem `json:"taskPercentage"`
20 // 引用资源解决分 22 // 引用资源解决分
@@ -29,6 +29,10 @@ type CreateTaskCommand struct { @@ -29,6 +29,10 @@ type CreateTaskCommand struct {
29 TaskNature int `json:"taskNature,omitempty"` 29 TaskNature int `json:"taskNature,omitempty"`
30 // 奖励素币 30 // 奖励素币
31 SuMoney float64 `json:"suMoney,omitempty"` 31 SuMoney float64 `json:"suMoney,omitempty"`
  32 + // 最小奖励素币
  33 + MinSuMoney float64 `json:"minSuMoney"`
  34 + // 最大奖励素币
  35 + MaxSuMoney float64 `json:"maxSuMoney"`
32 // 验收标准 36 // 验收标准
33 AcceptanceStandard string `json:"acceptanceStandard,omitempty"` 37 AcceptanceStandard string `json:"acceptanceStandard,omitempty"`
34 // 任务描述 38 // 任务描述
@@ -13,12 +13,18 @@ type SearchTaskCommand struct { @@ -13,12 +13,18 @@ type SearchTaskCommand struct {
13 Sponsor int64 `json:"sponsor,omitempty"` 13 Sponsor int64 `json:"sponsor,omitempty"`
14 // 任务内容匹配 14 // 任务内容匹配
15 TaskContentMatch string `json:"taskContentMatch,omitempty"` 15 TaskContentMatch string `json:"taskContentMatch,omitempty"`
  16 + // 任务名称匹配
  17 + TaskNameMatch string `json:"taskNameMatch,omitempty"`
16 // 任务类型 18 // 任务类型
17 TaskType int `json:"taskType,omitempty"` 19 TaskType int `json:"taskType,omitempty"`
18 // 任务类型ID列表 20 // 任务类型ID列表
19 TaskTypes []int `json:"taskTypes,omitempty"` 21 TaskTypes []int `json:"taskTypes,omitempty"`
20 // 任务状态 22 // 任务状态
21 TaskStatus int `json:"taskStatus,omitempty"` 23 TaskStatus int `json:"taskStatus,omitempty"`
  24 + // 任务状态ID列表
  25 + TaskStates []int `json:"taskStates,omitempty"`
  26 + // 任务状态ID列表
  27 + TaskStatuss []int `json:"taskStatuss,omitempty"`
22 // 项目归属 28 // 项目归属
23 ProjectBelongs []int `json:"projectBelongs,omitempty"` 29 ProjectBelongs []int `json:"projectBelongs,omitempty"`
24 // 客户价值 30 // 客户价值
@@ -23,8 +23,12 @@ type UpdateTaskCommand struct { @@ -23,8 +23,12 @@ type UpdateTaskCommand struct {
23 CustomerValues []int `json:"customerValues,omitempty"` 23 CustomerValues []int `json:"customerValues,omitempty"`
24 // 任务性质 24 // 任务性质
25 TaskNature int `json:"taskNature,omitempty"` 25 TaskNature int `json:"taskNature,omitempty"`
26 - // 奖励素币 26 + // 实际奖励素币
27 SuMoney float64 `json:"suMoney,omitempty"` 27 SuMoney float64 `json:"suMoney,omitempty"`
  28 + // 最小奖励素币
  29 + MinSuMoney float64 `json:"minSuMoney,omitempty"`
  30 + // 最大奖励素币
  31 + MaxSuMoney float64 `json:"maxSuMoney,omitempty"`
28 // 验收标准 32 // 验收标准
29 AcceptanceStandard string `json:"acceptanceStandard,omitempty"` 33 AcceptanceStandard string `json:"acceptanceStandard,omitempty"`
30 // 任务描述 34 // 任务描述
@@ -29,6 +29,10 @@ type TaskDto struct { @@ -29,6 +29,10 @@ type TaskDto struct {
29 TaskNature *domain.TaskNature `json:"taskNature"` 29 TaskNature *domain.TaskNature `json:"taskNature"`
30 // 奖励素币 30 // 奖励素币
31 SuMoney float64 `json:"suMoney"` 31 SuMoney float64 `json:"suMoney"`
  32 + // 最小奖励素币
  33 + MinSuMoney float64 `json:"minSuMoney"`
  34 + // 最大奖励素币
  35 + MaxSuMoney float64 `json:"maxSuMoney"`
32 // 验收标准 36 // 验收标准
33 AcceptanceStandard string `json:"acceptanceStandard"` 37 AcceptanceStandard string `json:"acceptanceStandard"`
34 // 任务描述 38 // 任务描述
@@ -99,6 +103,8 @@ func (dto *TaskDto) LoadDto(task *domain.Task, projectBelongMap map[int]*domain. @@ -99,6 +103,8 @@ func (dto *TaskDto) LoadDto(task *domain.Task, projectBelongMap map[int]*domain.
99 } 103 }
100 } 104 }
101 dto.SuMoney = task.SuMoney 105 dto.SuMoney = task.SuMoney
  106 + dto.MinSuMoney = task.MinSuMoney
  107 + dto.MaxSuMoney = task.MaxSuMoney
102 dto.AcceptanceStandard = task.AcceptanceStandard 108 dto.AcceptanceStandard = task.AcceptanceStandard
103 dto.TaskDescription = task.TaskDescription 109 dto.TaskDescription = task.TaskDescription
104 dto.TaskPictureUrls = task.TaskPictureUrls 110 dto.TaskPictureUrls = task.TaskPictureUrls
@@ -2,6 +2,8 @@ package service @@ -2,6 +2,8 @@ package service
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
  5 + "time"
  6 +
5 "github.com/linmadan/egglib-go/core/application" 7 "github.com/linmadan/egglib-go/core/application"
6 pgTransaction "github.com/linmadan/egglib-go/transaction/pg" 8 pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
7 "github.com/linmadan/egglib-go/utils/tool_funs" 9 "github.com/linmadan/egglib-go/utils/tool_funs"
@@ -13,7 +15,6 @@ import ( @@ -13,7 +15,6 @@ import (
13 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain" 15 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
14 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain/service" 16 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain/service"
15 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/dao" 17 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/dao"
16 - "time"  
17 ) 18 )
18 19
19 // 任务服务 20 // 任务服务
@@ -25,6 +26,7 @@ func (taskService *TaskService) ConfirmRobTask(confirmRobTaskCommand *command.Co @@ -25,6 +26,7 @@ func (taskService *TaskService) ConfirmRobTask(confirmRobTaskCommand *command.Co
25 if err := confirmRobTaskCommand.ValidateCommand(); err != nil { 26 if err := confirmRobTaskCommand.ValidateCommand(); err != nil {
26 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 27 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
27 } 28 }
  29 +
28 transactionContext, err := factory.CreateTransactionContext(nil) 30 transactionContext, err := factory.CreateTransactionContext(nil)
29 if err != nil { 31 if err != nil {
30 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 32 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -35,6 +37,7 @@ func (taskService *TaskService) ConfirmRobTask(confirmRobTaskCommand *command.Co @@ -35,6 +37,7 @@ func (taskService *TaskService) ConfirmRobTask(confirmRobTaskCommand *command.Co
35 defer func() { 37 defer func() {
36 transactionContext.RollbackTransaction() 38 transactionContext.RollbackTransaction()
37 }() 39 }()
  40 +
38 var confirmRobTaskService service.ConfirmRobTaskService 41 var confirmRobTaskService service.ConfirmRobTaskService
39 if value, err := factory.CreateConfirmRobTaskService(map[string]interface{}{ 42 if value, err := factory.CreateConfirmRobTaskService(map[string]interface{}{
40 "transactionContext": transactionContext, 43 "transactionContext": transactionContext,
@@ -46,6 +49,7 @@ func (taskService *TaskService) ConfirmRobTask(confirmRobTaskCommand *command.Co @@ -46,6 +49,7 @@ func (taskService *TaskService) ConfirmRobTask(confirmRobTaskCommand *command.Co
46 TransactionContext: transactionContext.(*pgTransaction.TransactionContext), 49 TransactionContext: transactionContext.(*pgTransaction.TransactionContext),
47 }) 50 })
48 } 51 }
  52 +
49 if task, err := confirmRobTaskService.Confirm(confirmRobTaskCommand.TaskId, confirmRobTaskCommand.Operator, confirmRobTaskCommand.PlannedCompletionTime); err != nil { 53 if task, err := confirmRobTaskService.Confirm(confirmRobTaskCommand.TaskId, confirmRobTaskCommand.Operator, confirmRobTaskCommand.PlannedCompletionTime); err != nil {
50 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 54 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
51 } else { 55 } else {
@@ -61,6 +65,7 @@ func (taskService *TaskService) RejectTaskReceiver(rejectTaskReceiverCommand *co @@ -61,6 +65,7 @@ func (taskService *TaskService) RejectTaskReceiver(rejectTaskReceiverCommand *co
61 if err := rejectTaskReceiverCommand.ValidateCommand(); err != nil { 65 if err := rejectTaskReceiverCommand.ValidateCommand(); err != nil {
62 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 66 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
63 } 67 }
  68 +
64 transactionContext, err := factory.CreateTransactionContext(nil) 69 transactionContext, err := factory.CreateTransactionContext(nil)
65 if err != nil { 70 if err != nil {
66 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 71 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -71,6 +76,7 @@ func (taskService *TaskService) RejectTaskReceiver(rejectTaskReceiverCommand *co @@ -71,6 +76,7 @@ func (taskService *TaskService) RejectTaskReceiver(rejectTaskReceiverCommand *co
71 defer func() { 76 defer func() {
72 transactionContext.RollbackTransaction() 77 transactionContext.RollbackTransaction()
73 }() 78 }()
  79 +
74 var rejectTaskReceiverService service.RejectTaskReceiverService 80 var rejectTaskReceiverService service.RejectTaskReceiverService
75 if value, err := factory.CreateRejectTaskReceiverService(map[string]interface{}{ 81 if value, err := factory.CreateRejectTaskReceiverService(map[string]interface{}{
76 "transactionContext": transactionContext, 82 "transactionContext": transactionContext,
@@ -82,6 +88,7 @@ func (taskService *TaskService) RejectTaskReceiver(rejectTaskReceiverCommand *co @@ -82,6 +88,7 @@ func (taskService *TaskService) RejectTaskReceiver(rejectTaskReceiverCommand *co
82 TransactionContext: transactionContext.(*pgTransaction.TransactionContext), 88 TransactionContext: transactionContext.(*pgTransaction.TransactionContext),
83 }) 89 })
84 } 90 }
  91 +
85 if task, err := rejectTaskReceiverService.Reject(rejectTaskReceiverCommand.TaskId, rejectTaskReceiverCommand.Operator, rejectTaskReceiverCommand.RejectReason); err != nil { 92 if task, err := rejectTaskReceiverService.Reject(rejectTaskReceiverCommand.TaskId, rejectTaskReceiverCommand.Operator, rejectTaskReceiverCommand.RejectReason); err != nil {
86 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 93 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
87 } else { 94 } else {
@@ -97,6 +104,7 @@ func (taskService *TaskService) RobTask(robTaskCommand *command.RobTaskCommand) @@ -97,6 +104,7 @@ func (taskService *TaskService) RobTask(robTaskCommand *command.RobTaskCommand)
97 if err := robTaskCommand.ValidateCommand(); err != nil { 104 if err := robTaskCommand.ValidateCommand(); err != nil {
98 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 105 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
99 } 106 }
  107 +
100 transactionContext, err := factory.CreateTransactionContext(nil) 108 transactionContext, err := factory.CreateTransactionContext(nil)
101 if err != nil { 109 if err != nil {
102 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 110 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -107,6 +115,7 @@ func (taskService *TaskService) RobTask(robTaskCommand *command.RobTaskCommand) @@ -107,6 +115,7 @@ func (taskService *TaskService) RobTask(robTaskCommand *command.RobTaskCommand)
107 defer func() { 115 defer func() {
108 transactionContext.RollbackTransaction() 116 transactionContext.RollbackTransaction()
109 }() 117 }()
  118 +
110 var robTaskService service.RobTaskService 119 var robTaskService service.RobTaskService
111 if value, err := factory.CreateRobTaskService(map[string]interface{}{ 120 if value, err := factory.CreateRobTaskService(map[string]interface{}{
112 "transactionContext": transactionContext, 121 "transactionContext": transactionContext,
@@ -119,6 +128,7 @@ func (taskService *TaskService) RobTask(robTaskCommand *command.RobTaskCommand) @@ -119,6 +128,7 @@ func (taskService *TaskService) RobTask(robTaskCommand *command.RobTaskCommand)
119 TransactionContext: transactionContext.(*pgTransaction.TransactionContext), 128 TransactionContext: transactionContext.(*pgTransaction.TransactionContext),
120 }) 129 })
121 } 130 }
  131 +
122 if task, err := robTaskService.Rob(robTaskCommand.TaskId, robTaskCommand.Receiver); err != nil { 132 if task, err := robTaskService.Rob(robTaskCommand.TaskId, robTaskCommand.Receiver); err != nil {
123 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 133 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
124 } else { 134 } else {
@@ -134,6 +144,7 @@ func (taskService *TaskService) BidTask(bidTaskCommand *command.BidTaskCommand) @@ -134,6 +144,7 @@ func (taskService *TaskService) BidTask(bidTaskCommand *command.BidTaskCommand)
134 if err := bidTaskCommand.ValidateCommand(); err != nil { 144 if err := bidTaskCommand.ValidateCommand(); err != nil {
135 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 145 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
136 } 146 }
  147 +
137 transactionContext, err := factory.CreateTransactionContext(nil) 148 transactionContext, err := factory.CreateTransactionContext(nil)
138 if err != nil { 149 if err != nil {
139 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 150 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -144,6 +155,7 @@ func (taskService *TaskService) BidTask(bidTaskCommand *command.BidTaskCommand) @@ -144,6 +155,7 @@ func (taskService *TaskService) BidTask(bidTaskCommand *command.BidTaskCommand)
144 defer func() { 155 defer func() {
145 transactionContext.RollbackTransaction() 156 transactionContext.RollbackTransaction()
146 }() 157 }()
  158 +
147 var bidTaskService service.BidTaskService 159 var bidTaskService service.BidTaskService
148 if value, err := factory.CreateBidTaskService(map[string]interface{}{ 160 if value, err := factory.CreateBidTaskService(map[string]interface{}{
149 "transactionContext": transactionContext, 161 "transactionContext": transactionContext,
@@ -152,6 +164,7 @@ func (taskService *TaskService) BidTask(bidTaskCommand *command.BidTaskCommand) @@ -152,6 +164,7 @@ func (taskService *TaskService) BidTask(bidTaskCommand *command.BidTaskCommand)
152 } else { 164 } else {
153 bidTaskService = value 165 bidTaskService = value
154 } 166 }
  167 +
155 if task, err := bidTaskService.Bid(bidTaskCommand.TaskId, bidTaskCommand.Bidder); err != nil { 168 if task, err := bidTaskService.Bid(bidTaskCommand.TaskId, bidTaskCommand.Bidder); err != nil {
156 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 169 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
157 } else { 170 } else {
@@ -167,6 +180,7 @@ func (taskService *TaskService) ChooseSuccessfulBidder(chooseSuccessfulBidderCom @@ -167,6 +180,7 @@ func (taskService *TaskService) ChooseSuccessfulBidder(chooseSuccessfulBidderCom
167 if err := chooseSuccessfulBidderCommand.ValidateCommand(); err != nil { 180 if err := chooseSuccessfulBidderCommand.ValidateCommand(); err != nil {
168 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 181 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
169 } 182 }
  183 +
170 transactionContext, err := factory.CreateTransactionContext(nil) 184 transactionContext, err := factory.CreateTransactionContext(nil)
171 if err != nil { 185 if err != nil {
172 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 186 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -177,6 +191,7 @@ func (taskService *TaskService) ChooseSuccessfulBidder(chooseSuccessfulBidderCom @@ -177,6 +191,7 @@ func (taskService *TaskService) ChooseSuccessfulBidder(chooseSuccessfulBidderCom
177 defer func() { 191 defer func() {
178 transactionContext.RollbackTransaction() 192 transactionContext.RollbackTransaction()
179 }() 193 }()
  194 +
180 var chooseSuccessfulBidderService service.ChooseSuccessfulBidderService 195 var chooseSuccessfulBidderService service.ChooseSuccessfulBidderService
181 if value, err := factory.CreateChooseSuccessfulBidderService(map[string]interface{}{ 196 if value, err := factory.CreateChooseSuccessfulBidderService(map[string]interface{}{
182 "transactionContext": transactionContext, 197 "transactionContext": transactionContext,
@@ -186,6 +201,7 @@ func (taskService *TaskService) ChooseSuccessfulBidder(chooseSuccessfulBidderCom @@ -186,6 +201,7 @@ func (taskService *TaskService) ChooseSuccessfulBidder(chooseSuccessfulBidderCom
186 chooseSuccessfulBidderService = value 201 chooseSuccessfulBidderService = value
187 chooseSuccessfulBidderService.Subscribe(&subscriber.AbilityServiceSubscriber{}) 202 chooseSuccessfulBidderService.Subscribe(&subscriber.AbilityServiceSubscriber{})
188 } 203 }
  204 +
189 if task, err := chooseSuccessfulBidderService.Choose(chooseSuccessfulBidderCommand.TaskId, chooseSuccessfulBidderCommand.SuccessfulBidder, chooseSuccessfulBidderCommand.Operator, chooseSuccessfulBidderCommand.PlannedCompletionTime); err != nil { 205 if task, err := chooseSuccessfulBidderService.Choose(chooseSuccessfulBidderCommand.TaskId, chooseSuccessfulBidderCommand.SuccessfulBidder, chooseSuccessfulBidderCommand.Operator, chooseSuccessfulBidderCommand.PlannedCompletionTime); err != nil {
190 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 206 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
191 } else { 207 } else {
@@ -201,6 +217,7 @@ func (taskService *TaskService) ApplyCompleteTask(applyCompleteTaskCommand *comm @@ -201,6 +217,7 @@ func (taskService *TaskService) ApplyCompleteTask(applyCompleteTaskCommand *comm
201 if err := applyCompleteTaskCommand.ValidateCommand(); err != nil { 217 if err := applyCompleteTaskCommand.ValidateCommand(); err != nil {
202 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 218 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
203 } 219 }
  220 +
204 transactionContext, err := factory.CreateTransactionContext(nil) 221 transactionContext, err := factory.CreateTransactionContext(nil)
205 if err != nil { 222 if err != nil {
206 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 223 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -211,6 +228,7 @@ func (taskService *TaskService) ApplyCompleteTask(applyCompleteTaskCommand *comm @@ -211,6 +228,7 @@ func (taskService *TaskService) ApplyCompleteTask(applyCompleteTaskCommand *comm
211 defer func() { 228 defer func() {
212 transactionContext.RollbackTransaction() 229 transactionContext.RollbackTransaction()
213 }() 230 }()
  231 +
214 var applyCompleteTaskService service.ApplyCompleteTaskService 232 var applyCompleteTaskService service.ApplyCompleteTaskService
215 if value, err := factory.CreateApplyCompleteTaskService(map[string]interface{}{ 233 if value, err := factory.CreateApplyCompleteTaskService(map[string]interface{}{
216 "transactionContext": transactionContext, 234 "transactionContext": transactionContext,
@@ -219,6 +237,7 @@ func (taskService *TaskService) ApplyCompleteTask(applyCompleteTaskCommand *comm @@ -219,6 +237,7 @@ func (taskService *TaskService) ApplyCompleteTask(applyCompleteTaskCommand *comm
219 } else { 237 } else {
220 applyCompleteTaskService = value 238 applyCompleteTaskService = value
221 } 239 }
  240 +
222 if task, err := applyCompleteTaskService.ApplyComplete(applyCompleteTaskCommand.TaskId, applyCompleteTaskCommand.Receiver); err != nil { 241 if task, err := applyCompleteTaskService.ApplyComplete(applyCompleteTaskCommand.TaskId, applyCompleteTaskCommand.Receiver); err != nil {
223 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 242 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
224 } else { 243 } else {
@@ -234,6 +253,7 @@ func (taskService *TaskService) ReleaseTask(releaseTaskCommand *command.ReleaseT @@ -234,6 +253,7 @@ func (taskService *TaskService) ReleaseTask(releaseTaskCommand *command.ReleaseT
234 if err := releaseTaskCommand.ValidateCommand(); err != nil { 253 if err := releaseTaskCommand.ValidateCommand(); err != nil {
235 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 254 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
236 } 255 }
  256 +
237 transactionContext, err := factory.CreateTransactionContext(nil) 257 transactionContext, err := factory.CreateTransactionContext(nil)
238 if err != nil { 258 if err != nil {
239 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 259 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -244,6 +264,8 @@ func (taskService *TaskService) ReleaseTask(releaseTaskCommand *command.ReleaseT @@ -244,6 +264,8 @@ func (taskService *TaskService) ReleaseTask(releaseTaskCommand *command.ReleaseT
244 defer func() { 264 defer func() {
245 transactionContext.RollbackTransaction() 265 transactionContext.RollbackTransaction()
246 }() 266 }()
  267 +
  268 + // 发布任务服务初始化
247 var releaseTaskService service.ReleaseTaskService 269 var releaseTaskService service.ReleaseTaskService
248 if value, err := factory.CreateReleaseTaskService(map[string]interface{}{ 270 if value, err := factory.CreateReleaseTaskService(map[string]interface{}{
249 "transactionContext": transactionContext, 271 "transactionContext": transactionContext,
@@ -256,6 +278,8 @@ func (taskService *TaskService) ReleaseTask(releaseTaskCommand *command.ReleaseT @@ -256,6 +278,8 @@ func (taskService *TaskService) ReleaseTask(releaseTaskCommand *command.ReleaseT
256 TransactionContext: transactionContext.(*pgTransaction.TransactionContext), 278 TransactionContext: transactionContext.(*pgTransaction.TransactionContext),
257 }) 279 })
258 } 280 }
  281 +
  282 + // 关闭任务
259 if task, err := releaseTaskService.Release(releaseTaskCommand.TaskId, releaseTaskCommand.Operator); err != nil { 283 if task, err := releaseTaskService.Release(releaseTaskCommand.TaskId, releaseTaskCommand.Operator); err != nil {
260 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 284 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
261 } else { 285 } else {
@@ -271,6 +295,7 @@ func (taskService *TaskService) OffTask(offTaskCommand *command.OffTaskCommand) @@ -271,6 +295,7 @@ func (taskService *TaskService) OffTask(offTaskCommand *command.OffTaskCommand)
271 if err := offTaskCommand.ValidateCommand(); err != nil { 295 if err := offTaskCommand.ValidateCommand(); err != nil {
272 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 296 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
273 } 297 }
  298 +
274 transactionContext, err := factory.CreateTransactionContext(nil) 299 transactionContext, err := factory.CreateTransactionContext(nil)
275 if err != nil { 300 if err != nil {
276 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 301 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -281,6 +306,8 @@ func (taskService *TaskService) OffTask(offTaskCommand *command.OffTaskCommand) @@ -281,6 +306,8 @@ func (taskService *TaskService) OffTask(offTaskCommand *command.OffTaskCommand)
281 defer func() { 306 defer func() {
282 transactionContext.RollbackTransaction() 307 transactionContext.RollbackTransaction()
283 }() 308 }()
  309 +
  310 + // 关闭任务服务初始化
284 var offTaskService service.OffTaskService 311 var offTaskService service.OffTaskService
285 if value, err := factory.CreateOffTaskService(map[string]interface{}{ 312 if value, err := factory.CreateOffTaskService(map[string]interface{}{
286 "transactionContext": transactionContext, 313 "transactionContext": transactionContext,
@@ -290,6 +317,8 @@ func (taskService *TaskService) OffTask(offTaskCommand *command.OffTaskCommand) @@ -290,6 +317,8 @@ func (taskService *TaskService) OffTask(offTaskCommand *command.OffTaskCommand)
290 offTaskService = value 317 offTaskService = value
291 offTaskService.Subscribe(&subscriber.AbilityServiceSubscriber{}) 318 offTaskService.Subscribe(&subscriber.AbilityServiceSubscriber{})
292 } 319 }
  320 +
  321 + // 关闭任务
293 if task, err := offTaskService.Off(offTaskCommand.TaskId, offTaskCommand.Operator, offTaskCommand.OffReason); err != nil { 322 if task, err := offTaskService.Off(offTaskCommand.TaskId, offTaskCommand.Operator, offTaskCommand.OffReason); err != nil {
294 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 323 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
295 } else { 324 } else {
@@ -305,6 +334,7 @@ func (taskService *TaskService) AcceptanceTask(acceptanceTaskCommand *command.Ac @@ -305,6 +334,7 @@ func (taskService *TaskService) AcceptanceTask(acceptanceTaskCommand *command.Ac
305 if err := acceptanceTaskCommand.ValidateCommand(); err != nil { 334 if err := acceptanceTaskCommand.ValidateCommand(); err != nil {
306 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 335 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
307 } 336 }
  337 +
308 transactionContext, err := factory.CreateTransactionContext(nil) 338 transactionContext, err := factory.CreateTransactionContext(nil)
309 if err != nil { 339 if err != nil {
310 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 340 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -315,6 +345,8 @@ func (taskService *TaskService) AcceptanceTask(acceptanceTaskCommand *command.Ac @@ -315,6 +345,8 @@ func (taskService *TaskService) AcceptanceTask(acceptanceTaskCommand *command.Ac
315 defer func() { 345 defer func() {
316 transactionContext.RollbackTransaction() 346 transactionContext.RollbackTransaction()
317 }() 347 }()
  348 +
  349 + // 验收服务初始化
318 var acceptanceTaskService service.AcceptanceTaskService 350 var acceptanceTaskService service.AcceptanceTaskService
319 if value, err := factory.CreateAcceptanceTaskService(map[string]interface{}{ 351 if value, err := factory.CreateAcceptanceTaskService(map[string]interface{}{
320 "transactionContext": transactionContext, 352 "transactionContext": transactionContext,
@@ -324,7 +356,50 @@ func (taskService *TaskService) AcceptanceTask(acceptanceTaskCommand *command.Ac @@ -324,7 +356,50 @@ func (taskService *TaskService) AcceptanceTask(acceptanceTaskCommand *command.Ac
324 acceptanceTaskService = value 356 acceptanceTaskService = value
325 acceptanceTaskService.Subscribe(&subscriber.AbilityServiceSubscriber{}) 357 acceptanceTaskService.Subscribe(&subscriber.AbilityServiceSubscriber{})
326 } 358 }
327 - if task, err := acceptanceTaskService.Acceptance(acceptanceTaskCommand.TaskId, acceptanceTaskCommand.Operator, acceptanceTaskCommand.Participators, acceptanceTaskCommand.TaskPercentage, acceptanceTaskCommand.ReferenceResourceScore, acceptanceTaskCommand.SolveReport, acceptanceTaskCommand.SolvePictureUrls, acceptanceTaskCommand.ActualCompletionTime); err != nil { 359 +
  360 + // 员工仓储初始化
  361 + var employeeRepository domain.EmployeeRepository
  362 + if value, err := factory.CreateEmployeeRepository(map[string]interface{}{
  363 + "transactionContext": transactionContext,
  364 + }); err != nil {
  365 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  366 + } else {
  367 + employeeRepository = value
  368 + }
  369 +
  370 + // 填充百分比员工信息
  371 + for i, taskPercentage := range acceptanceTaskCommand.TaskPercentage {
  372 + getEmployee := map[string]interface{}{
  373 + "uid": taskPercentage.Contributor.Uid,
  374 + }
  375 + employeeFound, err := employeeRepository.FindOne(getEmployee)
  376 + if err != nil {
  377 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  378 + }
  379 + if employeeFound == nil {
  380 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的员工")
  381 + }
  382 + acceptanceTaskCommand.TaskPercentage[i].Contributor = employeeFound.EmployeeInfo
  383 + }
  384 +
  385 + // 填充评分员工信息
  386 + for i, referenceResourceScore := range acceptanceTaskCommand.ReferenceResourceScore {
  387 + for j, solveScore := range referenceResourceScore.SolveScore {
  388 + getEmployee := map[string]interface{}{
  389 + "uid": solveScore.Contributor.Uid,
  390 + }
  391 + employeeFound, err := employeeRepository.FindOne(getEmployee)
  392 + if err != nil {
  393 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  394 + }
  395 + if employeeFound == nil {
  396 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的员工")
  397 + }
  398 + acceptanceTaskCommand.ReferenceResourceScore[i].SolveScore[j].Contributor = employeeFound.EmployeeInfo
  399 + }
  400 + }
  401 +
  402 + if task, err := acceptanceTaskService.Acceptance(acceptanceTaskCommand.TaskId, acceptanceTaskCommand.Operator, acceptanceTaskCommand.Participators, acceptanceTaskCommand.SuMoney, acceptanceTaskCommand.TaskPercentage, acceptanceTaskCommand.ReferenceResourceScore, acceptanceTaskCommand.SolveReport, acceptanceTaskCommand.SolvePictureUrls, acceptanceTaskCommand.ActualCompletionTime); err != nil {
328 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 403 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
329 } else { 404 } else {
330 if err := transactionContext.CommitTransaction(); err != nil { 405 if err := transactionContext.CommitTransaction(); err != nil {
@@ -336,10 +411,11 @@ func (taskService *TaskService) AcceptanceTask(acceptanceTaskCommand *command.Ac @@ -336,10 +411,11 @@ func (taskService *TaskService) AcceptanceTask(acceptanceTaskCommand *command.Ac
336 411
337 // 搜索任务 412 // 搜索任务
338 func (taskService *TaskService) SearchTask(searchTaskCommand *command.SearchTaskCommand) (interface{}, error) { 413 func (taskService *TaskService) SearchTask(searchTaskCommand *command.SearchTaskCommand) (interface{}, error) {
339 - if err := searchTaskCommand.ValidateCommand(); err != nil { 414 + if err := searchTaskCommand.ValidateCommand(); err != nil { // 校验搜索命令
340 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 415 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
341 } 416 }
342 - transactionContext, err := factory.CreateTransactionContext(nil) 417 +
  418 + transactionContext, err := factory.CreateTransactionContext(nil) // 工厂类创建事务上下文
343 if err != nil { 419 if err != nil {
344 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 420 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
345 } 421 }
@@ -349,6 +425,7 @@ func (taskService *TaskService) SearchTask(searchTaskCommand *command.SearchTask @@ -349,6 +425,7 @@ func (taskService *TaskService) SearchTask(searchTaskCommand *command.SearchTask
349 defer func() { 425 defer func() {
350 transactionContext.RollbackTransaction() 426 transactionContext.RollbackTransaction()
351 }() 427 }()
  428 +
352 var taskRepository domain.TaskRepository 429 var taskRepository domain.TaskRepository
353 if value, err := factory.CreateTaskRepository(map[string]interface{}{ 430 if value, err := factory.CreateTaskRepository(map[string]interface{}{
354 "transactionContext": transactionContext, 431 "transactionContext": transactionContext,
@@ -357,6 +434,7 @@ func (taskService *TaskService) SearchTask(searchTaskCommand *command.SearchTask @@ -357,6 +434,7 @@ func (taskService *TaskService) SearchTask(searchTaskCommand *command.SearchTask
357 } else { 434 } else {
358 taskRepository = value 435 taskRepository = value
359 } 436 }
  437 +
360 var projectBelongRepository domain.ProjectBelongRepository 438 var projectBelongRepository domain.ProjectBelongRepository
361 if value, err := factory.CreateProjectBelongRepository(map[string]interface{}{ 439 if value, err := factory.CreateProjectBelongRepository(map[string]interface{}{
362 "transactionContext": transactionContext, 440 "transactionContext": transactionContext,
@@ -365,6 +443,7 @@ func (taskService *TaskService) SearchTask(searchTaskCommand *command.SearchTask @@ -365,6 +443,7 @@ func (taskService *TaskService) SearchTask(searchTaskCommand *command.SearchTask
365 } else { 443 } else {
366 projectBelongRepository = value 444 projectBelongRepository = value
367 } 445 }
  446 +
368 projectBelongMap := make(map[int]*domain.ProjectBelong) 447 projectBelongMap := make(map[int]*domain.ProjectBelong)
369 if _, projectBelongs, err := projectBelongRepository.Find(map[string]interface{}{ 448 if _, projectBelongs, err := projectBelongRepository.Find(map[string]interface{}{
370 "companyId": searchTaskCommand.CompanyId, 449 "companyId": searchTaskCommand.CompanyId,
@@ -375,6 +454,7 @@ func (taskService *TaskService) SearchTask(searchTaskCommand *command.SearchTask @@ -375,6 +454,7 @@ func (taskService *TaskService) SearchTask(searchTaskCommand *command.SearchTask
375 projectBelongMap[projectBelong.ProjectBelongId] = projectBelong 454 projectBelongMap[projectBelong.ProjectBelongId] = projectBelong
376 } 455 }
377 } 456 }
  457 +
378 var customerValueRepository domain.CustomerValueRepository 458 var customerValueRepository domain.CustomerValueRepository
379 if value, err := factory.CreateCustomerValueRepository(map[string]interface{}{ 459 if value, err := factory.CreateCustomerValueRepository(map[string]interface{}{
380 "transactionContext": transactionContext, 460 "transactionContext": transactionContext,
@@ -383,6 +463,7 @@ func (taskService *TaskService) SearchTask(searchTaskCommand *command.SearchTask @@ -383,6 +463,7 @@ func (taskService *TaskService) SearchTask(searchTaskCommand *command.SearchTask
383 } else { 463 } else {
384 customerValueRepository = value 464 customerValueRepository = value
385 } 465 }
  466 +
386 customerValueMap := make(map[int]*domain.CustomerValue) 467 customerValueMap := make(map[int]*domain.CustomerValue)
387 if _, customerValues, err := customerValueRepository.Find(map[string]interface{}{ 468 if _, customerValues, err := customerValueRepository.Find(map[string]interface{}{
388 "companyId": searchTaskCommand.CompanyId, 469 "companyId": searchTaskCommand.CompanyId,
@@ -393,6 +474,7 @@ func (taskService *TaskService) SearchTask(searchTaskCommand *command.SearchTask @@ -393,6 +474,7 @@ func (taskService *TaskService) SearchTask(searchTaskCommand *command.SearchTask
393 customerValueMap[customerValue.CustomerValueId] = customerValue 474 customerValueMap[customerValue.CustomerValueId] = customerValue
394 } 475 }
395 } 476 }
  477 +
396 var taskNatureRepository domain.TaskNatureRepository 478 var taskNatureRepository domain.TaskNatureRepository
397 if value, err := factory.CreateTaskNatureRepository(map[string]interface{}{ 479 if value, err := factory.CreateTaskNatureRepository(map[string]interface{}{
398 "transactionContext": transactionContext, 480 "transactionContext": transactionContext,
@@ -401,6 +483,7 @@ func (taskService *TaskService) SearchTask(searchTaskCommand *command.SearchTask @@ -401,6 +483,7 @@ func (taskService *TaskService) SearchTask(searchTaskCommand *command.SearchTask
401 } else { 483 } else {
402 taskNatureRepository = value 484 taskNatureRepository = value
403 } 485 }
  486 +
404 taskNatureMap := make(map[int]*domain.TaskNature) 487 taskNatureMap := make(map[int]*domain.TaskNature)
405 if _, taskNatures, err := taskNatureRepository.Find(map[string]interface{}{ 488 if _, taskNatures, err := taskNatureRepository.Find(map[string]interface{}{
406 "companyId": searchTaskCommand.CompanyId, 489 "companyId": searchTaskCommand.CompanyId,
@@ -411,6 +494,7 @@ func (taskService *TaskService) SearchTask(searchTaskCommand *command.SearchTask @@ -411,6 +494,7 @@ func (taskService *TaskService) SearchTask(searchTaskCommand *command.SearchTask
411 taskNatureMap[taskNature.TaskNatureId] = taskNature 494 taskNatureMap[taskNature.TaskNatureId] = taskNature
412 } 495 }
413 } 496 }
  497 +
414 if count, tasks, err := taskRepository.Find(tool_funs.SimpleStructToMap(searchTaskCommand)); err != nil { 498 if count, tasks, err := taskRepository.Find(tool_funs.SimpleStructToMap(searchTaskCommand)); err != nil {
415 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 499 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
416 } else { 500 } else {
@@ -437,6 +521,7 @@ func (taskService *TaskService) SearchOffTaskRecord(searchOffTaskRecordCommand * @@ -437,6 +521,7 @@ func (taskService *TaskService) SearchOffTaskRecord(searchOffTaskRecordCommand *
437 if err := searchOffTaskRecordCommand.ValidateCommand(); err != nil { 521 if err := searchOffTaskRecordCommand.ValidateCommand(); err != nil {
438 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 522 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
439 } 523 }
  524 +
440 transactionContext, err := factory.CreateTransactionContext(nil) 525 transactionContext, err := factory.CreateTransactionContext(nil)
441 if err != nil { 526 if err != nil {
442 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 527 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -447,6 +532,7 @@ func (taskService *TaskService) SearchOffTaskRecord(searchOffTaskRecordCommand * @@ -447,6 +532,7 @@ func (taskService *TaskService) SearchOffTaskRecord(searchOffTaskRecordCommand *
447 defer func() { 532 defer func() {
448 transactionContext.RollbackTransaction() 533 transactionContext.RollbackTransaction()
449 }() 534 }()
  535 +
450 var projectBelongRepository domain.ProjectBelongRepository 536 var projectBelongRepository domain.ProjectBelongRepository
451 if value, err := factory.CreateProjectBelongRepository(map[string]interface{}{ 537 if value, err := factory.CreateProjectBelongRepository(map[string]interface{}{
452 "transactionContext": transactionContext, 538 "transactionContext": transactionContext,
@@ -455,6 +541,7 @@ func (taskService *TaskService) SearchOffTaskRecord(searchOffTaskRecordCommand * @@ -455,6 +541,7 @@ func (taskService *TaskService) SearchOffTaskRecord(searchOffTaskRecordCommand *
455 } else { 541 } else {
456 projectBelongRepository = value 542 projectBelongRepository = value
457 } 543 }
  544 +
458 projectBelongMap := make(map[int]*domain.ProjectBelong) 545 projectBelongMap := make(map[int]*domain.ProjectBelong)
459 if _, projectBelongs, err := projectBelongRepository.Find(map[string]interface{}{ 546 if _, projectBelongs, err := projectBelongRepository.Find(map[string]interface{}{
460 "companyId": searchOffTaskRecordCommand.CompanyId, 547 "companyId": searchOffTaskRecordCommand.CompanyId,
@@ -465,6 +552,7 @@ func (taskService *TaskService) SearchOffTaskRecord(searchOffTaskRecordCommand * @@ -465,6 +552,7 @@ func (taskService *TaskService) SearchOffTaskRecord(searchOffTaskRecordCommand *
465 projectBelongMap[projectBelong.ProjectBelongId] = projectBelong 552 projectBelongMap[projectBelong.ProjectBelongId] = projectBelong
466 } 553 }
467 } 554 }
  555 +
468 var customerValueRepository domain.CustomerValueRepository 556 var customerValueRepository domain.CustomerValueRepository
469 if value, err := factory.CreateCustomerValueRepository(map[string]interface{}{ 557 if value, err := factory.CreateCustomerValueRepository(map[string]interface{}{
470 "transactionContext": transactionContext, 558 "transactionContext": transactionContext,
@@ -473,6 +561,7 @@ func (taskService *TaskService) SearchOffTaskRecord(searchOffTaskRecordCommand * @@ -473,6 +561,7 @@ func (taskService *TaskService) SearchOffTaskRecord(searchOffTaskRecordCommand *
473 } else { 561 } else {
474 customerValueRepository = value 562 customerValueRepository = value
475 } 563 }
  564 +
476 customerValueMap := make(map[int]*domain.CustomerValue) 565 customerValueMap := make(map[int]*domain.CustomerValue)
477 if _, customerValues, err := customerValueRepository.Find(map[string]interface{}{ 566 if _, customerValues, err := customerValueRepository.Find(map[string]interface{}{
478 "companyId": searchOffTaskRecordCommand.CompanyId, 567 "companyId": searchOffTaskRecordCommand.CompanyId,
@@ -483,6 +572,7 @@ func (taskService *TaskService) SearchOffTaskRecord(searchOffTaskRecordCommand * @@ -483,6 +572,7 @@ func (taskService *TaskService) SearchOffTaskRecord(searchOffTaskRecordCommand *
483 customerValueMap[customerValue.CustomerValueId] = customerValue 572 customerValueMap[customerValue.CustomerValueId] = customerValue
484 } 573 }
485 } 574 }
  575 +
486 var taskNatureRepository domain.TaskNatureRepository 576 var taskNatureRepository domain.TaskNatureRepository
487 if value, err := factory.CreateTaskNatureRepository(map[string]interface{}{ 577 if value, err := factory.CreateTaskNatureRepository(map[string]interface{}{
488 "transactionContext": transactionContext, 578 "transactionContext": transactionContext,
@@ -491,6 +581,7 @@ func (taskService *TaskService) SearchOffTaskRecord(searchOffTaskRecordCommand * @@ -491,6 +581,7 @@ func (taskService *TaskService) SearchOffTaskRecord(searchOffTaskRecordCommand *
491 } else { 581 } else {
492 taskNatureRepository = value 582 taskNatureRepository = value
493 } 583 }
  584 +
494 taskNatureMap := make(map[int]*domain.TaskNature) 585 taskNatureMap := make(map[int]*domain.TaskNature)
495 if _, taskNatures, err := taskNatureRepository.Find(map[string]interface{}{ 586 if _, taskNatures, err := taskNatureRepository.Find(map[string]interface{}{
496 "companyId": searchOffTaskRecordCommand.CompanyId, 587 "companyId": searchOffTaskRecordCommand.CompanyId,
@@ -501,6 +592,7 @@ func (taskService *TaskService) SearchOffTaskRecord(searchOffTaskRecordCommand * @@ -501,6 +592,7 @@ func (taskService *TaskService) SearchOffTaskRecord(searchOffTaskRecordCommand *
501 taskNatureMap[taskNature.TaskNatureId] = taskNature 592 taskNatureMap[taskNature.TaskNatureId] = taskNature
502 } 593 }
503 } 594 }
  595 +
504 var taskRepository domain.TaskRepository 596 var taskRepository domain.TaskRepository
505 if value, err := factory.CreateTaskRepository(map[string]interface{}{ 597 if value, err := factory.CreateTaskRepository(map[string]interface{}{
506 "transactionContext": transactionContext, 598 "transactionContext": transactionContext,
@@ -509,6 +601,7 @@ func (taskService *TaskService) SearchOffTaskRecord(searchOffTaskRecordCommand * @@ -509,6 +601,7 @@ func (taskService *TaskService) SearchOffTaskRecord(searchOffTaskRecordCommand *
509 } else { 601 } else {
510 taskRepository = value 602 taskRepository = value
511 } 603 }
  604 +
512 var offTaskRecordRepository domain.OffTaskRecordRepository 605 var offTaskRecordRepository domain.OffTaskRecordRepository
513 if value, err := factory.CreateOffTaskRecordRepository(map[string]interface{}{ 606 if value, err := factory.CreateOffTaskRecordRepository(map[string]interface{}{
514 "transactionContext": transactionContext, 607 "transactionContext": transactionContext,
@@ -517,6 +610,7 @@ func (taskService *TaskService) SearchOffTaskRecord(searchOffTaskRecordCommand * @@ -517,6 +610,7 @@ func (taskService *TaskService) SearchOffTaskRecord(searchOffTaskRecordCommand *
517 } else { 610 } else {
518 offTaskRecordRepository = value 611 offTaskRecordRepository = value
519 } 612 }
  613 +
520 _, tasks, err := taskRepository.Find(map[string]interface{}{ 614 _, tasks, err := taskRepository.Find(map[string]interface{}{
521 "companyId": searchOffTaskRecordCommand.CompanyId, 615 "companyId": searchOffTaskRecordCommand.CompanyId,
522 "taskStatus": domain.TASK_STATUS_CLOSED, 616 "taskStatus": domain.TASK_STATUS_CLOSED,
@@ -570,6 +664,7 @@ func (taskService *TaskService) GetOffTaskRecord(getOffTaskRecordQuery *query.Ge @@ -570,6 +664,7 @@ func (taskService *TaskService) GetOffTaskRecord(getOffTaskRecordQuery *query.Ge
570 if err := getOffTaskRecordQuery.ValidateQuery(); err != nil { 664 if err := getOffTaskRecordQuery.ValidateQuery(); err != nil {
571 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 665 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
572 } 666 }
  667 +
573 transactionContext, err := factory.CreateTransactionContext(nil) 668 transactionContext, err := factory.CreateTransactionContext(nil)
574 if err != nil { 669 if err != nil {
575 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 670 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -580,6 +675,7 @@ func (taskService *TaskService) GetOffTaskRecord(getOffTaskRecordQuery *query.Ge @@ -580,6 +675,7 @@ func (taskService *TaskService) GetOffTaskRecord(getOffTaskRecordQuery *query.Ge
580 defer func() { 675 defer func() {
581 transactionContext.RollbackTransaction() 676 transactionContext.RollbackTransaction()
582 }() 677 }()
  678 +
583 var offTaskRecordRepository domain.OffTaskRecordRepository 679 var offTaskRecordRepository domain.OffTaskRecordRepository
584 if value, err := factory.CreateOffTaskRecordRepository(map[string]interface{}{ 680 if value, err := factory.CreateOffTaskRecordRepository(map[string]interface{}{
585 "transactionContext": transactionContext, 681 "transactionContext": transactionContext,
@@ -588,6 +684,7 @@ func (taskService *TaskService) GetOffTaskRecord(getOffTaskRecordQuery *query.Ge @@ -588,6 +684,7 @@ func (taskService *TaskService) GetOffTaskRecord(getOffTaskRecordQuery *query.Ge
588 } else { 684 } else {
589 offTaskRecordRepository = value 685 offTaskRecordRepository = value
590 } 686 }
  687 +
591 offTaskRecord, err := offTaskRecordRepository.FindOne(map[string]interface{}{"offTaskRecordId": getOffTaskRecordQuery.OffTaskRecordId}) 688 offTaskRecord, err := offTaskRecordRepository.FindOne(map[string]interface{}{"offTaskRecordId": getOffTaskRecordQuery.OffTaskRecordId})
592 if err != nil { 689 if err != nil {
593 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 690 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -607,6 +704,7 @@ func (taskService *TaskService) SearchRejectTaskRecord(searchRejectTaskRecordCom @@ -607,6 +704,7 @@ func (taskService *TaskService) SearchRejectTaskRecord(searchRejectTaskRecordCom
607 if err := searchRejectTaskRecordCommand.ValidateCommand(); err != nil { 704 if err := searchRejectTaskRecordCommand.ValidateCommand(); err != nil {
608 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 705 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
609 } 706 }
  707 +
610 transactionContext, err := factory.CreateTransactionContext(nil) 708 transactionContext, err := factory.CreateTransactionContext(nil)
611 if err != nil { 709 if err != nil {
612 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 710 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -617,6 +715,7 @@ func (taskService *TaskService) SearchRejectTaskRecord(searchRejectTaskRecordCom @@ -617,6 +715,7 @@ func (taskService *TaskService) SearchRejectTaskRecord(searchRejectTaskRecordCom
617 defer func() { 715 defer func() {
618 transactionContext.RollbackTransaction() 716 transactionContext.RollbackTransaction()
619 }() 717 }()
  718 +
620 var projectBelongRepository domain.ProjectBelongRepository 719 var projectBelongRepository domain.ProjectBelongRepository
621 if value, err := factory.CreateProjectBelongRepository(map[string]interface{}{ 720 if value, err := factory.CreateProjectBelongRepository(map[string]interface{}{
622 "transactionContext": transactionContext, 721 "transactionContext": transactionContext,
@@ -625,6 +724,7 @@ func (taskService *TaskService) SearchRejectTaskRecord(searchRejectTaskRecordCom @@ -625,6 +724,7 @@ func (taskService *TaskService) SearchRejectTaskRecord(searchRejectTaskRecordCom
625 } else { 724 } else {
626 projectBelongRepository = value 725 projectBelongRepository = value
627 } 726 }
  727 +
628 projectBelongMap := make(map[int]*domain.ProjectBelong) 728 projectBelongMap := make(map[int]*domain.ProjectBelong)
629 if _, projectBelongs, err := projectBelongRepository.Find(map[string]interface{}{ 729 if _, projectBelongs, err := projectBelongRepository.Find(map[string]interface{}{
630 "companyId": searchRejectTaskRecordCommand.CompanyId, 730 "companyId": searchRejectTaskRecordCommand.CompanyId,
@@ -635,6 +735,7 @@ func (taskService *TaskService) SearchRejectTaskRecord(searchRejectTaskRecordCom @@ -635,6 +735,7 @@ func (taskService *TaskService) SearchRejectTaskRecord(searchRejectTaskRecordCom
635 projectBelongMap[projectBelong.ProjectBelongId] = projectBelong 735 projectBelongMap[projectBelong.ProjectBelongId] = projectBelong
636 } 736 }
637 } 737 }
  738 +
638 var customerValueRepository domain.CustomerValueRepository 739 var customerValueRepository domain.CustomerValueRepository
639 if value, err := factory.CreateCustomerValueRepository(map[string]interface{}{ 740 if value, err := factory.CreateCustomerValueRepository(map[string]interface{}{
640 "transactionContext": transactionContext, 741 "transactionContext": transactionContext,
@@ -643,6 +744,7 @@ func (taskService *TaskService) SearchRejectTaskRecord(searchRejectTaskRecordCom @@ -643,6 +744,7 @@ func (taskService *TaskService) SearchRejectTaskRecord(searchRejectTaskRecordCom
643 } else { 744 } else {
644 customerValueRepository = value 745 customerValueRepository = value
645 } 746 }
  747 +
646 customerValueMap := make(map[int]*domain.CustomerValue) 748 customerValueMap := make(map[int]*domain.CustomerValue)
647 if _, customerValues, err := customerValueRepository.Find(map[string]interface{}{ 749 if _, customerValues, err := customerValueRepository.Find(map[string]interface{}{
648 "companyId": searchRejectTaskRecordCommand.CompanyId, 750 "companyId": searchRejectTaskRecordCommand.CompanyId,
@@ -653,6 +755,7 @@ func (taskService *TaskService) SearchRejectTaskRecord(searchRejectTaskRecordCom @@ -653,6 +755,7 @@ func (taskService *TaskService) SearchRejectTaskRecord(searchRejectTaskRecordCom
653 customerValueMap[customerValue.CustomerValueId] = customerValue 755 customerValueMap[customerValue.CustomerValueId] = customerValue
654 } 756 }
655 } 757 }
  758 +
656 var taskNatureRepository domain.TaskNatureRepository 759 var taskNatureRepository domain.TaskNatureRepository
657 if value, err := factory.CreateTaskNatureRepository(map[string]interface{}{ 760 if value, err := factory.CreateTaskNatureRepository(map[string]interface{}{
658 "transactionContext": transactionContext, 761 "transactionContext": transactionContext,
@@ -661,6 +764,7 @@ func (taskService *TaskService) SearchRejectTaskRecord(searchRejectTaskRecordCom @@ -661,6 +764,7 @@ func (taskService *TaskService) SearchRejectTaskRecord(searchRejectTaskRecordCom
661 } else { 764 } else {
662 taskNatureRepository = value 765 taskNatureRepository = value
663 } 766 }
  767 +
664 taskNatureMap := make(map[int]*domain.TaskNature) 768 taskNatureMap := make(map[int]*domain.TaskNature)
665 if _, taskNatures, err := taskNatureRepository.Find(map[string]interface{}{ 769 if _, taskNatures, err := taskNatureRepository.Find(map[string]interface{}{
666 "companyId": searchRejectTaskRecordCommand.CompanyId, 770 "companyId": searchRejectTaskRecordCommand.CompanyId,
@@ -671,6 +775,7 @@ func (taskService *TaskService) SearchRejectTaskRecord(searchRejectTaskRecordCom @@ -671,6 +775,7 @@ func (taskService *TaskService) SearchRejectTaskRecord(searchRejectTaskRecordCom
671 taskNatureMap[taskNature.TaskNatureId] = taskNature 775 taskNatureMap[taskNature.TaskNatureId] = taskNature
672 } 776 }
673 } 777 }
  778 +
674 var taskRepository domain.TaskRepository 779 var taskRepository domain.TaskRepository
675 if value, err := factory.CreateTaskRepository(map[string]interface{}{ 780 if value, err := factory.CreateTaskRepository(map[string]interface{}{
676 "transactionContext": transactionContext, 781 "transactionContext": transactionContext,
@@ -679,6 +784,7 @@ func (taskService *TaskService) SearchRejectTaskRecord(searchRejectTaskRecordCom @@ -679,6 +784,7 @@ func (taskService *TaskService) SearchRejectTaskRecord(searchRejectTaskRecordCom
679 } else { 784 } else {
680 taskRepository = value 785 taskRepository = value
681 } 786 }
  787 +
682 var rejectTaskRecordRepository domain.RejectTaskRecordRepository 788 var rejectTaskRecordRepository domain.RejectTaskRecordRepository
683 if value, err := factory.CreateRejectTaskRecordRepository(map[string]interface{}{ 789 if value, err := factory.CreateRejectTaskRecordRepository(map[string]interface{}{
684 "transactionContext": transactionContext, 790 "transactionContext": transactionContext,
@@ -687,6 +793,7 @@ func (taskService *TaskService) SearchRejectTaskRecord(searchRejectTaskRecordCom @@ -687,6 +793,7 @@ func (taskService *TaskService) SearchRejectTaskRecord(searchRejectTaskRecordCom
687 } else { 793 } else {
688 rejectTaskRecordRepository = value 794 rejectTaskRecordRepository = value
689 } 795 }
  796 +
690 _, tasks, err := taskRepository.Find(map[string]interface{}{ 797 _, tasks, err := taskRepository.Find(map[string]interface{}{
691 "companyId": searchRejectTaskRecordCommand.CompanyId, 798 "companyId": searchRejectTaskRecordCommand.CompanyId,
692 "taskContentMatch": searchRejectTaskRecordCommand.TaskContentMatch, 799 "taskContentMatch": searchRejectTaskRecordCommand.TaskContentMatch,
@@ -702,6 +809,7 @@ func (taskService *TaskService) SearchRejectTaskRecord(searchRejectTaskRecordCom @@ -702,6 +809,7 @@ func (taskService *TaskService) SearchRejectTaskRecord(searchRejectTaskRecordCom
702 for _, task := range tasks { 809 for _, task := range tasks {
703 taskIds = append(taskIds, task.TaskId) 810 taskIds = append(taskIds, task.TaskId)
704 } 811 }
  812 +
705 if count, rejectTaskRecords, err := rejectTaskRecordRepository.Find(map[string]interface{}{ 813 if count, rejectTaskRecords, err := rejectTaskRecordRepository.Find(map[string]interface{}{
706 "taskIds": taskIds, 814 "taskIds": taskIds,
707 "rejectStartTime": searchRejectTaskRecordCommand.RejectStartTime, 815 "rejectStartTime": searchRejectTaskRecordCommand.RejectStartTime,
@@ -739,6 +847,7 @@ func (taskService *TaskService) GetRejectTaskRecord(getRejectTaskRecordQuery *qu @@ -739,6 +847,7 @@ func (taskService *TaskService) GetRejectTaskRecord(getRejectTaskRecordQuery *qu
739 if err := getRejectTaskRecordQuery.ValidateQuery(); err != nil { 847 if err := getRejectTaskRecordQuery.ValidateQuery(); err != nil {
740 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 848 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
741 } 849 }
  850 +
742 transactionContext, err := factory.CreateTransactionContext(nil) 851 transactionContext, err := factory.CreateTransactionContext(nil)
743 if err != nil { 852 if err != nil {
744 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 853 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -749,6 +858,7 @@ func (taskService *TaskService) GetRejectTaskRecord(getRejectTaskRecordQuery *qu @@ -749,6 +858,7 @@ func (taskService *TaskService) GetRejectTaskRecord(getRejectTaskRecordQuery *qu
749 defer func() { 858 defer func() {
750 transactionContext.RollbackTransaction() 859 transactionContext.RollbackTransaction()
751 }() 860 }()
  861 +
752 var rejectTaskRecordRepository domain.RejectTaskRecordRepository 862 var rejectTaskRecordRepository domain.RejectTaskRecordRepository
753 if value, err := factory.CreateRejectTaskRecordRepository(map[string]interface{}{ 863 if value, err := factory.CreateRejectTaskRecordRepository(map[string]interface{}{
754 "transactionContext": transactionContext, 864 "transactionContext": transactionContext,
@@ -757,6 +867,7 @@ func (taskService *TaskService) GetRejectTaskRecord(getRejectTaskRecordQuery *qu @@ -757,6 +867,7 @@ func (taskService *TaskService) GetRejectTaskRecord(getRejectTaskRecordQuery *qu
757 } else { 867 } else {
758 rejectTaskRecordRepository = value 868 rejectTaskRecordRepository = value
759 } 869 }
  870 +
760 rejectTaskRecord, err := rejectTaskRecordRepository.FindOne(map[string]interface{}{"rejectTaskRecordId": getRejectTaskRecordQuery.RejectTaskRecordId}) 871 rejectTaskRecord, err := rejectTaskRecordRepository.FindOne(map[string]interface{}{"rejectTaskRecordId": getRejectTaskRecordQuery.RejectTaskRecordId})
761 if err != nil { 872 if err != nil {
762 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 873 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -776,6 +887,7 @@ func (taskService *TaskService) CreateTask(createTaskCommand *command.CreateTask @@ -776,6 +887,7 @@ func (taskService *TaskService) CreateTask(createTaskCommand *command.CreateTask
776 if err := createTaskCommand.ValidateCommand(); err != nil { 887 if err := createTaskCommand.ValidateCommand(); err != nil {
777 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 888 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
778 } 889 }
  890 +
779 transactionContext, err := factory.CreateTransactionContext(nil) 891 transactionContext, err := factory.CreateTransactionContext(nil)
780 if err != nil { 892 if err != nil {
781 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 893 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -786,6 +898,7 @@ func (taskService *TaskService) CreateTask(createTaskCommand *command.CreateTask @@ -786,6 +898,7 @@ func (taskService *TaskService) CreateTask(createTaskCommand *command.CreateTask
786 defer func() { 898 defer func() {
787 transactionContext.RollbackTransaction() 899 transactionContext.RollbackTransaction()
788 }() 900 }()
  901 +
789 var taskDao *dao.TaskDao 902 var taskDao *dao.TaskDao
790 if value, err := factory.CreateTaskDao(map[string]interface{}{ 903 if value, err := factory.CreateTaskDao(map[string]interface{}{
791 "transactionContext": transactionContext, 904 "transactionContext": transactionContext,
@@ -794,6 +907,7 @@ func (taskService *TaskService) CreateTask(createTaskCommand *command.CreateTask @@ -794,6 +907,7 @@ func (taskService *TaskService) CreateTask(createTaskCommand *command.CreateTask
794 } else { 907 } else {
795 taskDao = value 908 taskDao = value
796 } 909 }
  910 +
797 var employeeRepository domain.EmployeeRepository 911 var employeeRepository domain.EmployeeRepository
798 if value, err := factory.CreateEmployeeRepository(map[string]interface{}{ 912 if value, err := factory.CreateEmployeeRepository(map[string]interface{}{
799 "transactionContext": transactionContext, 913 "transactionContext": transactionContext,
@@ -802,28 +916,54 @@ func (taskService *TaskService) CreateTask(createTaskCommand *command.CreateTask @@ -802,28 +916,54 @@ func (taskService *TaskService) CreateTask(createTaskCommand *command.CreateTask
802 } else { 916 } else {
803 employeeRepository = value 917 employeeRepository = value
804 } 918 }
  919 +
805 sponsor, err := employeeRepository.FindOne(map[string]interface{}{ 920 sponsor, err := employeeRepository.FindOne(map[string]interface{}{
806 "uid": createTaskCommand.Sponsor, 921 "uid": createTaskCommand.Sponsor,
  922 + "status": 1,
807 }) 923 })
808 if err != nil { 924 if err != nil {
809 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 925 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
810 } 926 }
811 if sponsor == nil { 927 if sponsor == nil {
  928 + // 获取无效的发布人员信息
  929 + sponsorInvalid, err := employeeRepository.FindOne(map[string]interface{}{
  930 + "uid": createTaskCommand.AssignedPerson,
  931 + })
  932 + if err != nil {
  933 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  934 + }
  935 + if sponsorInvalid == nil {
812 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的发布者") 936 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的发布者")
813 } 937 }
  938 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的发布者:"+ sponsorInvalid.EmployeeInfo.EmployeeName)
  939 + }
  940 +
  941 + // 获取任务指派人
814 var assignedPerson *domain.EmployeeInfo 942 var assignedPerson *domain.EmployeeInfo
815 if createTaskCommand.AssignedPerson != 0 { 943 if createTaskCommand.AssignedPerson != 0 {
816 employee, err := employeeRepository.FindOne(map[string]interface{}{ 944 employee, err := employeeRepository.FindOne(map[string]interface{}{
817 "uid": createTaskCommand.AssignedPerson, 945 "uid": createTaskCommand.AssignedPerson,
  946 + "status": 1,
818 }) 947 })
819 if err != nil { 948 if err != nil {
820 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 949 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
821 } 950 }
822 if employee == nil { 951 if employee == nil {
  952 + // 获取无效的指派人员信息
  953 + employeeInvalid, err := employeeRepository.FindOne(map[string]interface{}{
  954 + "uid": createTaskCommand.AssignedPerson,
  955 + })
  956 + if err != nil {
  957 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  958 + }
  959 + if employeeInvalid == nil {
823 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的指派人员") 960 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的指派人员")
824 } 961 }
  962 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的指派人员:" + employeeInvalid.EmployeeInfo.EmployeeName)
  963 + }
825 assignedPerson = employee.EmployeeInfo 964 assignedPerson = employee.EmployeeInfo
826 } 965 }
  966 +
827 newTask := &domain.Task{ 967 newTask := &domain.Task{
828 TaskStatus: domain.TASK_STATUS_UNRELEASED, 968 TaskStatus: domain.TASK_STATUS_UNRELEASED,
829 CompanyId: createTaskCommand.CompanyId, 969 CompanyId: createTaskCommand.CompanyId,
@@ -838,6 +978,8 @@ func (taskService *TaskService) CreateTask(createTaskCommand *command.CreateTask @@ -838,6 +978,8 @@ func (taskService *TaskService) CreateTask(createTaskCommand *command.CreateTask
838 CustomerValues: createTaskCommand.CustomerValues, 978 CustomerValues: createTaskCommand.CustomerValues,
839 TaskNature: createTaskCommand.TaskNature, 979 TaskNature: createTaskCommand.TaskNature,
840 SuMoney: createTaskCommand.SuMoney, 980 SuMoney: createTaskCommand.SuMoney,
  981 + MinSuMoney: createTaskCommand.MinSuMoney,
  982 + MaxSuMoney: createTaskCommand.MaxSuMoney,
841 AcceptanceStandard: createTaskCommand.AcceptanceStandard, 983 AcceptanceStandard: createTaskCommand.AcceptanceStandard,
842 TaskDescription: createTaskCommand.TaskDescription, 984 TaskDescription: createTaskCommand.TaskDescription,
843 TaskPictureUrls: createTaskCommand.TaskPictureUrls, 985 TaskPictureUrls: createTaskCommand.TaskPictureUrls,
@@ -846,6 +988,7 @@ func (taskService *TaskService) CreateTask(createTaskCommand *command.CreateTask @@ -846,6 +988,7 @@ func (taskService *TaskService) CreateTask(createTaskCommand *command.CreateTask
846 PlannedCompletionTime: createTaskCommand.PlannedCompletionTime, 988 PlannedCompletionTime: createTaskCommand.PlannedCompletionTime,
847 CreateTime: time.Now(), 989 CreateTime: time.Now(),
848 } 990 }
  991 +
849 var taskRepository domain.TaskRepository 992 var taskRepository domain.TaskRepository
850 if value, err := factory.CreateTaskRepository(map[string]interface{}{ 993 if value, err := factory.CreateTaskRepository(map[string]interface{}{
851 "transactionContext": transactionContext, 994 "transactionContext": transactionContext,
@@ -854,6 +997,7 @@ func (taskService *TaskService) CreateTask(createTaskCommand *command.CreateTask @@ -854,6 +997,7 @@ func (taskService *TaskService) CreateTask(createTaskCommand *command.CreateTask
854 } else { 997 } else {
855 taskRepository = value 998 taskRepository = value
856 } 999 }
  1000 +
857 if createTaskCommand.ReferenceResourceItems != nil && len(createTaskCommand.ReferenceResourceItems) > 0 { 1001 if createTaskCommand.ReferenceResourceItems != nil && len(createTaskCommand.ReferenceResourceItems) > 0 {
858 var referenceResourceIds []int64 1002 var referenceResourceIds []int64
859 for _, referenceResourceItem := range createTaskCommand.ReferenceResourceItems { 1003 for _, referenceResourceItem := range createTaskCommand.ReferenceResourceItems {
@@ -871,6 +1015,7 @@ func (taskService *TaskService) CreateTask(createTaskCommand *command.CreateTask @@ -871,6 +1015,7 @@ func (taskService *TaskService) CreateTask(createTaskCommand *command.CreateTask
871 } 1015 }
872 } 1016 }
873 } 1017 }
  1018 +
874 if task, err := taskRepository.Save(newTask); err != nil { 1019 if task, err := taskRepository.Save(newTask); err != nil {
875 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1020 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
876 } else { 1021 } else {
@@ -908,6 +1053,7 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter @@ -908,6 +1053,7 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter
908 if err := getTaskQuery.ValidateQuery(); err != nil { 1053 if err := getTaskQuery.ValidateQuery(); err != nil {
909 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 1054 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
910 } 1055 }
  1056 +
911 transactionContext, err := factory.CreateTransactionContext(nil) 1057 transactionContext, err := factory.CreateTransactionContext(nil)
912 if err != nil { 1058 if err != nil {
913 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 1059 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -918,6 +1064,7 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter @@ -918,6 +1064,7 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter
918 defer func() { 1064 defer func() {
919 transactionContext.RollbackTransaction() 1065 transactionContext.RollbackTransaction()
920 }() 1066 }()
  1067 +
921 var taskRepository domain.TaskRepository 1068 var taskRepository domain.TaskRepository
922 if value, err := factory.CreateTaskRepository(map[string]interface{}{ 1069 if value, err := factory.CreateTaskRepository(map[string]interface{}{
923 "transactionContext": transactionContext, 1070 "transactionContext": transactionContext,
@@ -926,6 +1073,7 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter @@ -926,6 +1073,7 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter
926 } else { 1073 } else {
927 taskRepository = value 1074 taskRepository = value
928 } 1075 }
  1076 +
929 task, err := taskRepository.FindOne(map[string]interface{}{"taskId": getTaskQuery.TaskId}) 1077 task, err := taskRepository.FindOne(map[string]interface{}{"taskId": getTaskQuery.TaskId})
930 if err != nil { 1078 if err != nil {
931 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1079 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -941,6 +1089,7 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter @@ -941,6 +1089,7 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter
941 } else { 1089 } else {
942 projectBelongRepository = value 1090 projectBelongRepository = value
943 } 1091 }
  1092 +
944 projectBelongMap := make(map[int]*domain.ProjectBelong) 1093 projectBelongMap := make(map[int]*domain.ProjectBelong)
945 if _, projectBelongs, err := projectBelongRepository.Find(map[string]interface{}{ 1094 if _, projectBelongs, err := projectBelongRepository.Find(map[string]interface{}{
946 "companyId": task.CompanyId, 1095 "companyId": task.CompanyId,
@@ -951,6 +1100,7 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter @@ -951,6 +1100,7 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter
951 projectBelongMap[projectBelong.ProjectBelongId] = projectBelong 1100 projectBelongMap[projectBelong.ProjectBelongId] = projectBelong
952 } 1101 }
953 } 1102 }
  1103 +
954 var customerValueRepository domain.CustomerValueRepository 1104 var customerValueRepository domain.CustomerValueRepository
955 if value, err := factory.CreateCustomerValueRepository(map[string]interface{}{ 1105 if value, err := factory.CreateCustomerValueRepository(map[string]interface{}{
956 "transactionContext": transactionContext, 1106 "transactionContext": transactionContext,
@@ -959,6 +1109,7 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter @@ -959,6 +1109,7 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter
959 } else { 1109 } else {
960 customerValueRepository = value 1110 customerValueRepository = value
961 } 1111 }
  1112 +
962 customerValueMap := make(map[int]*domain.CustomerValue) 1113 customerValueMap := make(map[int]*domain.CustomerValue)
963 if _, customerValues, err := customerValueRepository.Find(map[string]interface{}{ 1114 if _, customerValues, err := customerValueRepository.Find(map[string]interface{}{
964 "companyId": task.CompanyId, 1115 "companyId": task.CompanyId,
@@ -969,6 +1120,7 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter @@ -969,6 +1120,7 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter
969 customerValueMap[customerValue.CustomerValueId] = customerValue 1120 customerValueMap[customerValue.CustomerValueId] = customerValue
970 } 1121 }
971 } 1122 }
  1123 +
972 var taskNatureRepository domain.TaskNatureRepository 1124 var taskNatureRepository domain.TaskNatureRepository
973 if value, err := factory.CreateTaskNatureRepository(map[string]interface{}{ 1125 if value, err := factory.CreateTaskNatureRepository(map[string]interface{}{
974 "transactionContext": transactionContext, 1126 "transactionContext": transactionContext,
@@ -977,6 +1129,7 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter @@ -977,6 +1129,7 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter
977 } else { 1129 } else {
978 taskNatureRepository = value 1130 taskNatureRepository = value
979 } 1131 }
  1132 +
980 taskNatureMap := make(map[int]*domain.TaskNature) 1133 taskNatureMap := make(map[int]*domain.TaskNature)
981 if _, taskNatures, err := taskNatureRepository.Find(map[string]interface{}{ 1134 if _, taskNatures, err := taskNatureRepository.Find(map[string]interface{}{
982 "companyId": task.CompanyId, 1135 "companyId": task.CompanyId,
@@ -987,6 +1140,7 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter @@ -987,6 +1140,7 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter
987 taskNatureMap[taskNature.TaskNatureId] = taskNature 1140 taskNatureMap[taskNature.TaskNatureId] = taskNature
988 } 1141 }
989 } 1142 }
  1143 +
990 taskDto := &dto.TaskDto{} 1144 taskDto := &dto.TaskDto{}
991 if err := taskDto.LoadDto(task, projectBelongMap, customerValueMap, taskNatureMap); err != nil { 1145 if err := taskDto.LoadDto(task, projectBelongMap, customerValueMap, taskNatureMap); err != nil {
992 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1146 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -994,15 +1148,55 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter @@ -994,15 +1148,55 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter
994 if err := transactionContext.CommitTransaction(); err != nil { 1148 if err := transactionContext.CommitTransaction(); err != nil {
995 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 1149 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
996 } 1150 }
  1151 +
  1152 + // 返回任务素币奖励范围
  1153 + if taskDto.TaskStatus != 5 && task.MinSuMoney == 0 && task.MaxSuMoney == 0 {
  1154 + taskDto.MinSuMoney = 0
  1155 + taskDto.MaxSuMoney = task.SuMoney
  1156 + }
  1157 +
997 return taskDto, nil 1158 return taskDto, nil
998 } 1159 }
999 } 1160 }
1000 1161
  1162 +// 更新过期任务状态
  1163 +func (taskService *TaskService) UpdateTaskStatus() (interface{}, error) {
  1164 + transactionContext, err := factory.CreateTransactionContext(nil)
  1165 + if err != nil {
  1166 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  1167 + }
  1168 + if err := transactionContext.StartTransaction(); err != nil {
  1169 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  1170 + }
  1171 + defer func() {
  1172 + transactionContext.RollbackTransaction()
  1173 + }()
  1174 +
  1175 + var taskDao *dao.TaskDao
  1176 + if value, err := factory.CreateTaskDao(map[string]interface{}{
  1177 + "transactionContext": transactionContext,
  1178 + }); err != nil {
  1179 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  1180 + } else {
  1181 + taskDao = value
  1182 + }
  1183 +
  1184 + if err := taskDao.UpdateExpiredPlannedCompletionTimeBidTask(); err != nil {
  1185 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  1186 + }
  1187 +
  1188 + if err := transactionContext.CommitTransaction(); err != nil {
  1189 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  1190 + }
  1191 + return nil, nil
  1192 +}
  1193 +
1001 // 更新任务 1194 // 更新任务
1002 func (taskService *TaskService) UpdateTask(updateTaskCommand *command.UpdateTaskCommand) (interface{}, error) { 1195 func (taskService *TaskService) UpdateTask(updateTaskCommand *command.UpdateTaskCommand) (interface{}, error) {
1003 if err := updateTaskCommand.ValidateCommand(); err != nil { 1196 if err := updateTaskCommand.ValidateCommand(); err != nil {
1004 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 1197 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
1005 } 1198 }
  1199 +
1006 transactionContext, err := factory.CreateTransactionContext(nil) 1200 transactionContext, err := factory.CreateTransactionContext(nil)
1007 if err != nil { 1201 if err != nil {
1008 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 1202 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -1013,6 +1207,7 @@ func (taskService *TaskService) UpdateTask(updateTaskCommand *command.UpdateTask @@ -1013,6 +1207,7 @@ func (taskService *TaskService) UpdateTask(updateTaskCommand *command.UpdateTask
1013 defer func() { 1207 defer func() {
1014 transactionContext.RollbackTransaction() 1208 transactionContext.RollbackTransaction()
1015 }() 1209 }()
  1210 +
1016 var taskRepository domain.TaskRepository 1211 var taskRepository domain.TaskRepository
1017 if value, err := factory.CreateTaskRepository(map[string]interface{}{ 1212 if value, err := factory.CreateTaskRepository(map[string]interface{}{
1018 "transactionContext": transactionContext, 1213 "transactionContext": transactionContext,
@@ -1021,6 +1216,7 @@ func (taskService *TaskService) UpdateTask(updateTaskCommand *command.UpdateTask @@ -1021,6 +1216,7 @@ func (taskService *TaskService) UpdateTask(updateTaskCommand *command.UpdateTask
1021 } else { 1216 } else {
1022 taskRepository = value 1217 taskRepository = value
1023 } 1218 }
  1219 +
1024 var taskDao *dao.TaskDao 1220 var taskDao *dao.TaskDao
1025 if value, err := factory.CreateTaskDao(map[string]interface{}{ 1221 if value, err := factory.CreateTaskDao(map[string]interface{}{
1026 "transactionContext": transactionContext, 1222 "transactionContext": transactionContext,
@@ -1029,13 +1225,34 @@ func (taskService *TaskService) UpdateTask(updateTaskCommand *command.UpdateTask @@ -1029,13 +1225,34 @@ func (taskService *TaskService) UpdateTask(updateTaskCommand *command.UpdateTask
1029 } else { 1225 } else {
1030 taskDao = value 1226 taskDao = value
1031 } 1227 }
  1228 +
  1229 + var releaseTaskService service.ReleaseTaskService
  1230 + if value, err := factory.CreateReleaseTaskService(map[string]interface{}{
  1231 + "transactionContext": transactionContext,
  1232 + }); err != nil {
  1233 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  1234 + } else {
  1235 + releaseTaskService = value
  1236 + releaseTaskService.Subscribe(&subscriber.AbilityServiceSubscriber{})
  1237 + releaseTaskService.Subscribe(&subscriber.MmmOpenApiServiceServiceSubscriber{
  1238 + TransactionContext: transactionContext.(*pgTransaction.TransactionContext),
  1239 + })
  1240 + }
  1241 +
  1242 + var taskBidEndTime time.Time
  1243 + // 找到当前任务
1032 task, err := taskRepository.FindOne(map[string]interface{}{"taskId": updateTaskCommand.TaskId}) 1244 task, err := taskRepository.FindOne(map[string]interface{}{"taskId": updateTaskCommand.TaskId})
1033 if err != nil { 1245 if err != nil {
1034 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1246 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
1035 } 1247 }
1036 if task == nil { 1248 if task == nil {
1037 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateTaskCommand.TaskId))) 1249 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateTaskCommand.TaskId)))
  1250 + } else {
  1251 + if task.TaskStatus == domain.TASK_STATUS_EXPIRED {
  1252 + taskBidEndTime = task.BidInfo.BidEndTime
  1253 + }
1038 } 1254 }
  1255 +
1039 if updateTaskCommand.ReferenceResourceItems != nil && len(updateTaskCommand.ReferenceResourceItems) > 0 { 1256 if updateTaskCommand.ReferenceResourceItems != nil && len(updateTaskCommand.ReferenceResourceItems) > 0 {
1040 var referenceResourceIds []int64 1257 var referenceResourceIds []int64
1041 for _, referenceResourceItem := range updateTaskCommand.ReferenceResourceItems { 1258 for _, referenceResourceItem := range updateTaskCommand.ReferenceResourceItems {
@@ -1058,8 +1275,11 @@ func (taskService *TaskService) UpdateTask(updateTaskCommand *command.UpdateTask @@ -1058,8 +1275,11 @@ func (taskService *TaskService) UpdateTask(updateTaskCommand *command.UpdateTask
1058 } 1275 }
1059 } 1276 }
1060 } 1277 }
  1278 +
1061 updateData := tool_funs.SimpleStructToMap(updateTaskCommand) 1279 updateData := tool_funs.SimpleStructToMap(updateTaskCommand)
  1280 +
1062 fmt.Println(updateTaskCommand.AssignedPerson != int64(0)) 1281 fmt.Println(updateTaskCommand.AssignedPerson != int64(0))
  1282 +
1063 if task.TaskType == domain.TASK_TYPE_DESIGNATE { 1283 if task.TaskType == domain.TASK_TYPE_DESIGNATE {
1064 if updateTaskCommand.AssignedPerson != int64(0) { 1284 if updateTaskCommand.AssignedPerson != int64(0) {
1065 var employeeRepository domain.EmployeeRepository 1285 var employeeRepository domain.EmployeeRepository
@@ -1072,18 +1292,30 @@ func (taskService *TaskService) UpdateTask(updateTaskCommand *command.UpdateTask @@ -1072,18 +1292,30 @@ func (taskService *TaskService) UpdateTask(updateTaskCommand *command.UpdateTask
1072 } 1292 }
1073 employee, err := employeeRepository.FindOne(map[string]interface{}{ 1293 employee, err := employeeRepository.FindOne(map[string]interface{}{
1074 "uid": updateTaskCommand.AssignedPerson, 1294 "uid": updateTaskCommand.AssignedPerson,
  1295 + "status": 1,
1075 }) 1296 })
1076 if err != nil { 1297 if err != nil {
1077 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1298 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
1078 } 1299 }
1079 if employee == nil { 1300 if employee == nil {
  1301 + // 获取无效的发布人员信息
  1302 + employeeInvalid, err := employeeRepository.FindOne(map[string]interface{}{
  1303 + "uid": updateTaskCommand.AssignedPerson,
  1304 + })
  1305 + if err != nil {
  1306 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  1307 + }
  1308 + if employeeInvalid == nil {
1080 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的指派人员") 1309 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的指派人员")
1081 } 1310 }
  1311 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的指派人员:" + employeeInvalid.EmployeeInfo.EmployeeName)
  1312 + }
1082 updateData["assignedPerson"] = employee.EmployeeInfo 1313 updateData["assignedPerson"] = employee.EmployeeInfo
1083 } else { 1314 } else {
1084 updateData["assignedPerson"] = &domain.EmployeeInfo{} 1315 updateData["assignedPerson"] = &domain.EmployeeInfo{}
1085 } 1316 }
1086 } 1317 }
  1318 +
1087 if err := task.Update(updateData); err != nil { 1319 if err := task.Update(updateData); err != nil {
1088 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 1320 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
1089 } 1321 }
@@ -1095,6 +1327,18 @@ func (taskService *TaskService) UpdateTask(updateTaskCommand *command.UpdateTask @@ -1095,6 +1327,18 @@ func (taskService *TaskService) UpdateTask(updateTaskCommand *command.UpdateTask
1095 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1327 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
1096 } 1328 }
1097 } 1329 }
  1330 +
  1331 + if task.TaskStatus == domain.TASK_STATUS_EXPIRED {
  1332 + // 未修改时间或者修改的时间小于当前时间
  1333 + if updateTaskCommand.BidEndTime.Local().Equal(taskBidEndTime.Local()) || updateTaskCommand.BidEndTime.Local().Before(time.Date(time.Now().Local().Year(), time.Now().Local().Month(), time.Now().Local().Day(), 23, 59, 59, 0, time.Local)) {
  1334 + return nil, application.ThrowError(application.BUSINESS_ERROR, "请重新修改竞标时间")
  1335 + } else {
  1336 + if _, err := releaseTaskService.Release(task.TaskId, task.Sponsor.Uid); err != nil {
  1337 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  1338 + }
  1339 + }
  1340 + }
  1341 +
1098 if err := transactionContext.CommitTransaction(); err != nil { 1342 if err := transactionContext.CommitTransaction(); err != nil {
1099 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 1343 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
1100 } 1344 }
@@ -1124,6 +1368,7 @@ func (taskService *TaskService) RemoveTask(removeTaskCommand *command.RemoveTask @@ -1124,6 +1368,7 @@ func (taskService *TaskService) RemoveTask(removeTaskCommand *command.RemoveTask
1124 if err := removeTaskCommand.ValidateCommand(); err != nil { 1368 if err := removeTaskCommand.ValidateCommand(); err != nil {
1125 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 1369 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
1126 } 1370 }
  1371 +
1127 transactionContext, err := factory.CreateTransactionContext(nil) 1372 transactionContext, err := factory.CreateTransactionContext(nil)
1128 if err != nil { 1373 if err != nil {
1129 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 1374 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -1134,6 +1379,7 @@ func (taskService *TaskService) RemoveTask(removeTaskCommand *command.RemoveTask @@ -1134,6 +1379,7 @@ func (taskService *TaskService) RemoveTask(removeTaskCommand *command.RemoveTask
1134 defer func() { 1379 defer func() {
1135 transactionContext.RollbackTransaction() 1380 transactionContext.RollbackTransaction()
1136 }() 1381 }()
  1382 +
1137 var taskRepository domain.TaskRepository 1383 var taskRepository domain.TaskRepository
1138 if value, err := factory.CreateTaskRepository(map[string]interface{}{ 1384 if value, err := factory.CreateTaskRepository(map[string]interface{}{
1139 "transactionContext": transactionContext, 1385 "transactionContext": transactionContext,
@@ -1142,6 +1388,7 @@ func (taskService *TaskService) RemoveTask(removeTaskCommand *command.RemoveTask @@ -1142,6 +1388,7 @@ func (taskService *TaskService) RemoveTask(removeTaskCommand *command.RemoveTask
1142 } else { 1388 } else {
1143 taskRepository = value 1389 taskRepository = value
1144 } 1390 }
  1391 +
1145 task, err := taskRepository.FindOne(map[string]interface{}{"taskId": removeTaskCommand.TaskId}) 1392 task, err := taskRepository.FindOne(map[string]interface{}{"taskId": removeTaskCommand.TaskId})
1146 if err != nil { 1393 if err != nil {
1147 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1394 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -1181,6 +1428,7 @@ func (taskService *TaskService) ListTask(listTaskQuery *query.ListTaskQuery) (in @@ -1181,6 +1428,7 @@ func (taskService *TaskService) ListTask(listTaskQuery *query.ListTaskQuery) (in
1181 if err := listTaskQuery.ValidateQuery(); err != nil { 1428 if err := listTaskQuery.ValidateQuery(); err != nil {
1182 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 1429 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
1183 } 1430 }
  1431 +
1184 transactionContext, err := factory.CreateTransactionContext(nil) 1432 transactionContext, err := factory.CreateTransactionContext(nil)
1185 if err != nil { 1433 if err != nil {
1186 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 1434 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -1191,6 +1439,7 @@ func (taskService *TaskService) ListTask(listTaskQuery *query.ListTaskQuery) (in @@ -1191,6 +1439,7 @@ func (taskService *TaskService) ListTask(listTaskQuery *query.ListTaskQuery) (in
1191 defer func() { 1439 defer func() {
1192 transactionContext.RollbackTransaction() 1440 transactionContext.RollbackTransaction()
1193 }() 1441 }()
  1442 +
1194 var taskRepository domain.TaskRepository 1443 var taskRepository domain.TaskRepository
1195 if value, err := factory.CreateTaskRepository(map[string]interface{}{ 1444 if value, err := factory.CreateTaskRepository(map[string]interface{}{
1196 "transactionContext": transactionContext, 1445 "transactionContext": transactionContext,
@@ -1199,15 +1448,24 @@ func (taskService *TaskService) ListTask(listTaskQuery *query.ListTaskQuery) (in @@ -1199,15 +1448,24 @@ func (taskService *TaskService) ListTask(listTaskQuery *query.ListTaskQuery) (in
1199 } else { 1448 } else {
1200 taskRepository = value 1449 taskRepository = value
1201 } 1450 }
  1451 +
1202 if count, tasks, err := taskRepository.Find(tool_funs.SimpleStructToMap(listTaskQuery)); err != nil { 1452 if count, tasks, err := taskRepository.Find(tool_funs.SimpleStructToMap(listTaskQuery)); err != nil {
1203 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1453 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
1204 } else { 1454 } else {
1205 if err := transactionContext.CommitTransaction(); err != nil { 1455 if err := transactionContext.CommitTransaction(); err != nil {
1206 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 1456 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
1207 } 1457 }
  1458 + var retTasks []*domain.Task
  1459 + for _, task := range tasks {
  1460 + if task.TaskStatus != 5 && task.MinSuMoney == 0 && task.MaxSuMoney == 0 {
  1461 + task.MinSuMoney = 0
  1462 + task.MaxSuMoney = task.SuMoney
  1463 + }
  1464 + retTasks = append(retTasks, task)
  1465 + }
1208 return map[string]interface{}{ 1466 return map[string]interface{}{
1209 "count": count, 1467 "count": count,
1210 - "tasks": tasks, 1468 + "tasks": retTasks,
1211 }, nil 1469 }, nil
1212 } 1470 }
1213 } 1471 }
@@ -7,6 +7,7 @@ import ( @@ -7,6 +7,7 @@ import (
7 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/unifiedUserCenter/command" 7 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/unifiedUserCenter/command"
8 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain" 8 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
9 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/dao" 9 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/dao"
  10 + "time"
10 ) 11 )
11 12
12 // 统一用户中心适配服务 13 // 统一用户中心适配服务
@@ -88,12 +89,12 @@ func (unifiedUserCenterService *UnifiedUserCenterService) SyncEmployeeCallback(s @@ -88,12 +89,12 @@ func (unifiedUserCenterService *UnifiedUserCenterService) SyncEmployeeCallback(s
88 uids = append(uids, int64(uid.(float64))) 89 uids = append(uids, int64(uid.(float64)))
89 } 90 }
90 } 91 }
91 - if value, ok := data["add"]; ok { 92 + if value, ok := data["add"]; ok { // 添加员工
92 for _, addEmployee := range value.([]interface{}) { 93 for _, addEmployee := range value.([]interface{}) {
93 addEmployees = append(addEmployees, addEmployee.(map[string]interface{})) 94 addEmployees = append(addEmployees, addEmployee.(map[string]interface{}))
94 } 95 }
95 } 96 }
96 - if value, ok := data["edit"]; ok { 97 + if value, ok := data["edit"]; ok { // 编辑员工
97 for _, editEmployee := range value.([]interface{}) { 98 for _, editEmployee := range value.([]interface{}) {
98 editEmployees = append(editEmployees, editEmployee.(map[string]interface{})) 99 editEmployees = append(editEmployees, editEmployee.(map[string]interface{}))
99 } 100 }
@@ -145,7 +146,9 @@ func (unifiedUserCenterService *UnifiedUserCenterService) SyncEmployeeCallback(s @@ -145,7 +146,9 @@ func (unifiedUserCenterService *UnifiedUserCenterService) SyncEmployeeCallback(s
145 }, 146 },
146 Status: status, 147 Status: status,
147 SuMoney: 0, 148 SuMoney: 0,
  149 + CreateTime: time.Now(),
148 } 150 }
  151 +
149 if _, err := employeeRepository.Save(employee); err != nil { 152 if _, err := employeeRepository.Save(employee); err != nil {
150 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 153 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
151 } 154 }
@@ -205,6 +208,7 @@ func (unifiedUserCenterService *UnifiedUserCenterService) SyncEmployeeCallback(s @@ -205,6 +208,7 @@ func (unifiedUserCenterService *UnifiedUserCenterService) SyncEmployeeCallback(s
205 }, 208 },
206 Status: status, 209 Status: status,
207 SuMoney: 0, 210 SuMoney: 0,
  211 + CreateTime: time.Now(),
208 } 212 }
209 if _, err := employeeRepository.Save(employee); err != nil { 213 if _, err := employeeRepository.Save(employee); err != nil {
210 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 214 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -8,6 +8,9 @@ var LOG_LEVEL = "debug" @@ -8,6 +8,9 @@ var LOG_LEVEL = "debug"
8 var ABILITY_SERVICE_HOST = "https://suplus-worth-app-gateway-dev.fjmaimaimai.com" 8 var ABILITY_SERVICE_HOST = "https://suplus-worth-app-gateway-dev.fjmaimaimai.com"
9 var MMM_OPEN_API_SERVICE_HOST = "http://mmm-open-api-dev.fjmaimaimai.com" 9 var MMM_OPEN_API_SERVICE_HOST = "http://mmm-open-api-dev.fjmaimaimai.com"
10 10
  11 +//var LOG_LEVEL = "debug"
  12 +var LOG_File = "logs/app.log"
  13 +
11 func init() { 14 func init() {
12 if os.Getenv("LOG_LEVEL") != "" { 15 if os.Getenv("LOG_LEVEL") != "" {
13 LOG_LEVEL = os.Getenv("LOG_LEVEL") 16 LOG_LEVEL = os.Getenv("LOG_LEVEL")
@@ -2,11 +2,11 @@ package constant @@ -2,11 +2,11 @@ package constant
2 2
3 import "os" 3 import "os"
4 4
5 -var POSTGRESQL_DB_NAME = "mmm-worth" 5 +var POSTGRESQL_DB_NAME = "mmm-worth-test"
6 var POSTGRESQL_USER = "postgres" 6 var POSTGRESQL_USER = "postgres"
7 -var POSTGRESQL_PASSWORD = "abc123456" 7 +var POSTGRESQL_PASSWORD = "1993618jack"
8 var POSTGRESQL_HOST = "127.0.0.1" 8 var POSTGRESQL_HOST = "127.0.0.1"
9 -var POSTGRESQL_PORT = "32432" 9 +var POSTGRESQL_PORT = "5432"
10 var DISABLE_CREATE_TABLE = false 10 var DISABLE_CREATE_TABLE = false
11 var DISABLE_SQL_GENERATE_PRINT = false 11 var DISABLE_SQL_GENERATE_PRINT = false
12 12
  1 +package domain
  2 +
  3 +import (
  4 + "time"
  5 +)
  6 +
  7 +// 现金池
  8 +type CashPool struct {
  9 + CashPoolId int64 `json:"cashPoolId"` // 现金池id
  10 + Cash float64 `json:"cash"` // 投入现金池的现金
  11 + CompanyId int64 `json:"companyId"` // 公司id
  12 + ExchangedCash float64 `json:"exchangedCash"` // 已兑换的现金
  13 + UnExchangeCash float64 `json:"unExchangeCash"` // 未兑换的现金
  14 + ExchangedSuMoney float64 `json:"exchangedSuMoney"` // 已兑换的素币
  15 + UnExchangeSuMoney float64 `json:"unExchangeSuMoney"` // 未兑换的素币
  16 + Rate float64 `json:"rate"` // 平均兑换汇率
  17 + LastRate float64 `json:"lastRate"` // 上期活动兑换汇率
  18 + CreateTime time.Time `json:"createTime"` // 现金投入现金池时间
  19 +}
  20 +
  21 +type CashPoolRepository interface {
  22 + Save(cashPool *CashPool) (*CashPool, error)
  23 + FindOne(queryOptions map[string]interface{}) (*CashPool, error)
  24 + Find(queryOptions map[string]interface{}) (int64, []*CashPool, error)
  25 +}
  26 +
  27 +func (cashPool *CashPool) Update(data map[string]interface{}) error {
  28 + if cash, ok := data["cash"]; ok {
  29 + cashPool.Cash = cash.(float64)
  30 + }
  31 + if exchangedCash, ok := data["exchangedCash"]; ok {
  32 + cashPool.ExchangedCash = exchangedCash.(float64)
  33 + }
  34 + if unExchangeCash, ok := data["unExchangeCash"]; ok {
  35 + cashPool.UnExchangeCash = unExchangeCash.(float64)
  36 + }
  37 + if exchangedSuMoney, ok := data["exchangedSuMoney"]; ok {
  38 + cashPool.ExchangedSuMoney = exchangedSuMoney.(float64)
  39 + }
  40 + if unExchangeSuMoney, ok := data["unExchangeSuMoney"]; ok {
  41 + cashPool.UnExchangeSuMoney = unExchangeSuMoney.(float64)
  42 + }
  43 + if rate, ok := data["rate"]; ok {
  44 + cashPool.Rate = rate.(float64)
  45 + }
  46 + return nil
  47 +}
  48 +
  49 +func (cashPool *CashPool) Identity() interface{} {
  50 + if cashPool.CashPoolId == 0 {
  51 + return nil
  52 + }
  53 + return cashPool.CashPoolId
  54 +}
  55 +
1 package domain 1 package domain
2 2
  3 +import "time"
  4 +
3 // 员工 5 // 员工
4 type Employee struct { 6 type Employee struct {
5 // 员工ID 7 // 员工ID
@@ -14,6 +16,8 @@ type Employee struct { @@ -14,6 +16,8 @@ type Employee struct {
14 Status int `json:"status"` 16 Status int `json:"status"`
15 // 员工权限集合 17 // 员工权限集合
16 Permissions []int `json:"permissions"` 18 Permissions []int `json:"permissions"`
  19 + // 创建时间
  20 + CreateTime time.Time `json:"createTime"`
17 } 21 }
18 22
19 type EmployeeRepository interface { 23 type EmployeeRepository interface {
@@ -21,6 +25,8 @@ type EmployeeRepository interface { @@ -21,6 +25,8 @@ type EmployeeRepository interface {
21 Remove(employee *Employee) (*Employee, error) 25 Remove(employee *Employee) (*Employee, error)
22 FindOne(queryOptions map[string]interface{}) (*Employee, error) 26 FindOne(queryOptions map[string]interface{}) (*Employee, error)
23 Find(queryOptions map[string]interface{}) (int64, []*Employee, error) 27 Find(queryOptions map[string]interface{}) (int64, []*Employee, error)
  28 + FindByIds(queryOptions map[string]interface{}) (int64, []*Employee, error)
  29 + FindAll(queryOptions map[string]interface{}) (int64, []*Employee, error)
24 } 30 }
25 31
26 func (employee *Employee) Identify() interface{} { 32 func (employee *Employee) Identify() interface{} {
@@ -49,6 +55,9 @@ func (employee *Employee) Update(data map[string]interface{}) error { @@ -49,6 +55,9 @@ func (employee *Employee) Update(data map[string]interface{}) error {
49 if permissions, ok := data["permissions"]; ok { 55 if permissions, ok := data["permissions"]; ok {
50 employee.Permissions = permissions.([]int) 56 employee.Permissions = permissions.([]int)
51 } 57 }
  58 + if createTime, ok := data["createTime"]; ok && !createTime.(time.Time).IsZero() {
  59 + employee.CreateTime = createTime.(time.Time)
  60 + }
52 return nil 61 return nil
53 } 62 }
54 63
  1 +package domain
  2 +
  3 +import (
  4 + "time"
  5 +)
  6 +
  7 +// 兑换现金活动
  8 +type ExchangeCashActivity struct {
  9 + ActivityId int64 `json:"activityId"` // 兑换现金活动id
  10 + ExchangeActivityName string `json:"exchangeActivityName"` // 兑换现金活动名称
  11 + CompanyId int64 `json:"companyId"` // 公司ID
  12 + ExchangedCash float64 `json:"exchangedCash"` // 已兑换的现金
  13 + ExchangedSuMoney float64 `json:"exchangedSuMoney"` // 已兑换的素币
  14 + Deadline time.Time `json:"deadline"` // 兑换现金活动截止时间
  15 + CountDown int64 `json:"countDown"` // 兑换现金活动结束倒计时
  16 + Rate float64 `json:"rate"` // 兑换汇率
  17 + CreateTime time.Time `json:"createTime"` // 创建兑换现金活动时间
  18 +}
  19 +
  20 +type ExchangeActivityRepository interface {
  21 + Save(exchangeCashActivity *ExchangeCashActivity) (*ExchangeCashActivity, error)
  22 + Remove(exchangeCashActivity *ExchangeCashActivity) (*ExchangeCashActivity, error)
  23 + FindOne(queryOptions map[string]interface{}) (*ExchangeCashActivity, error)
  24 + Find(queryOptions map[string]interface{}) (int64, []*ExchangeCashActivity, error)
  25 + FindAll(queryOptions map[string]interface{}) (int64, []*ExchangeCashActivity, error)
  26 +}
  27 +
  28 +func (exchangeCashActivity *ExchangeCashActivity) Identity() interface{} {
  29 + if exchangeCashActivity.ActivityId == 0 {
  30 + return nil
  31 + }
  32 + return exchangeCashActivity.ActivityId
  33 +}
  34 +
  35 +func (exchangeCashActivity *ExchangeCashActivity) Update(data map[string]interface{}) error {
  36 + if exchangeActivityName, ok := data["exchangeActivityName"]; ok && exchangeActivityName != "" {
  37 + exchangeCashActivity.ExchangeActivityName = exchangeActivityName.(string)
  38 + }
  39 + if deadline, ok := data["deadline"]; ok && deadline != "" {
  40 + exchangeCashActivity.Deadline = deadline.(time.Time)
  41 + }
  42 + if countDown, ok := data["countDown"]; ok && countDown != 0 {
  43 + exchangeCashActivity.CountDown = countDown.(int64)
  44 + }
  45 + if exchangedSuMoney, ok := data["exchangedSuMoney"]; ok && exchangedSuMoney != 0 {
  46 + exchangeCashActivity.ExchangedSuMoney = exchangedSuMoney.(float64)
  47 + }
  48 + if exchangedCash, ok := data["exchangedCash"]; ok && exchangedCash != 0 {
  49 + exchangeCashActivity.ExchangedCash = exchangedCash.(float64)
  50 + }
  51 + if exchangeRate, ok := data["exchangeRate"]; ok && exchangeRate != 0 {
  52 + exchangeCashActivity.Rate = exchangeRate.(float64)
  53 + }
  54 + if createTime, ok := data["createTime"]; ok && createTime.(time.Time).IsZero() {
  55 + exchangeCashActivity.CreateTime = createTime.(time.Time)
  56 + }
  57 + exchangeCashActivity.CreateTime = time.Now()
  58 + return nil
  59 +}
  60 +
  61 +func (exchangeCashActivity *ExchangeCashActivity) TransferSuMoney(rate float64) error {
  62 + exchangeCashActivity.ExchangedSuMoney = exchangeCashActivity.ExchangedCash * rate
  63 + return nil
  64 +}
  65 +
  66 +func (exchangeCashActivity *ExchangeCashActivity) TransferCountDown() error {
  67 + exchangeCashActivity.CountDown = int64(time.Until(exchangeCashActivity.Deadline))
  68 + return nil
  69 +}
  1 +package domain
  2 +
  3 +import (
  4 + "fmt"
  5 + "strconv"
  6 +)
  7 +
  8 +// 参与兑换现金人员
  9 +type ExchangeCashPersonList struct {
  10 + ListId int64 `json:"listId"` // 清单id
  11 + EmployeeInfo *EmployeeInfo `json:"employeeInfo"` // 兑换人信息
  12 + ExchangeCashActivityId int64 `json:"exchangeActivityId"` // 参与的兑换活动id
  13 + ExchangedSuMoney float64 `json:"suMoney"` // 已兑换的素币
  14 + ExchangedCash float64 `json:"cash"` // 已兑换的现金
  15 +}
  16 +
  17 +type ExchangeCashPersonListRepository interface {
  18 + Save(exchangeCashPersonList *ExchangeCashPersonList) (*ExchangeCashPersonList, error)
  19 + Remove(exchangeCashPersonList *ExchangeCashPersonList) (*ExchangeCashPersonList, error)
  20 + FindOne(queryOptions map[string]interface{}) (*ExchangeCashPersonList, error)
  21 + Find(queryOptions map[string]interface{}) (int64, []*ExchangeCashPersonList, error)
  22 + FindAll(queryOptions map[string]interface{}) (int64, []*ExchangeCashPersonList, error)
  23 + FindById(queryOptions map[string]interface{}) (int64, []*ExchangeCashPersonList, error)
  24 +}
  25 +
  26 +func (exchangeCashPersonList *ExchangeCashPersonList) Identity() interface{} {
  27 + if exchangeCashPersonList.ListId == 0 {
  28 + return nil
  29 + }
  30 + return exchangeCashPersonList.ListId
  31 +}
  32 +
  33 +func (exchangeCashPersonList *ExchangeCashPersonList) Update(data map[string]interface{}) error {
  34 + if exchangedSuMoney, ok := data["exchangedSuMoney"]; ok && exchangedSuMoney != 0 {
  35 + exchangeCashPersonList.ExchangedSuMoney = exchangedSuMoney.(float64)
  36 + }
  37 + if exchangedCash, ok := data["exchangedCash"]; ok && exchangedCash != 0 {
  38 + exchangeCashPersonList.ExchangedCash, _ = strconv.ParseFloat(fmt.Sprintf("%.2F", exchangedCash.(float64)), 64)
  39 + }
  40 + return nil
  41 +}
  1 +package domain
  2 +
  3 +import (
  4 + "time"
  5 +)
  6 +
  7 +// 排行榜时间
  8 +type ListInterval struct {
  9 + ListIntervalId int `json:"listIntervalId"` // 排行榜时间id
  10 + CompanyId int `json:"companyId"` // 公司id
  11 + IntervalStartTime time.Time `json:"intervalStartTime"` // 排行榜开始时间
  12 + IntervalEndTime time.Time `json:"intervalEndTime"` // 排行榜结束时间
  13 +}
  14 +
  15 +type ListIntervalRepository interface {
  16 + Save(listInterval *ListInterval) (*ListInterval, error)
  17 + Remove(listInterval *ListInterval) (*ListInterval, error)
  18 + FindOne(queryOptions map[string]interface{}) (*ListInterval, error)
  19 + Find(queryOptions map[string]interface{}) (int64, []*ListInterval, error)
  20 + FindAll(queryOptions map[string]interface{}) (int64, []*ListInterval, error)
  21 +}
  22 +
  23 +func (listInterval *ListInterval) Identify() interface{} {
  24 + if listInterval.ListIntervalId == 0 {
  25 + return nil
  26 + }
  27 + return listInterval.ListIntervalId
  28 +}
  29 +
  30 +func (listInterval *ListInterval) Update(data map[string]interface{}) error {
  31 + if listIntervalStartTime, ok := data["listIntervalStartTime"]; ok {
  32 + listInterval.IntervalStartTime = listIntervalStartTime.(time.Time)
  33 + }
  34 + if listIntervalEndTime, ok := data["listIntervalEndTime"]; ok {
  35 + listInterval.IntervalEndTime = listIntervalEndTime.(time.Time)
  36 + }
  37 + return nil
  38 +}
@@ -8,5 +8,5 @@ import ( @@ -8,5 +8,5 @@ import (
8 8
9 type AcceptanceTaskService interface { 9 type AcceptanceTaskService interface {
10 coreDomain.DomainEventPublisher 10 coreDomain.DomainEventPublisher
11 - Acceptance(taskId int64, operatorUid int64, participators []int64, taskPercentage []*domain.TaskPercentageItem, referenceResourceScore []*domain.ReferenceResourceItem, solveReport string, solvePictureUrls []string, actualCompletionTime time.Time) (*domain.Task, error) 11 + Acceptance(taskId int64, operatorUid int64, participators []int64, suMoney float64, taskPercentage []*domain.TaskPercentageItem, referenceResourceScore []*domain.ReferenceResourceItem, solveReport string, solvePictureUrls []string, actualCompletionTime time.Time) (*domain.Task, error)
12 } 12 }
@@ -3,32 +3,28 @@ package domain @@ -3,32 +3,28 @@ package domain
3 import "time" 3 import "time"
4 4
5 const ( 5 const (
6 - SU_MONEY_TRANSACTION_RECORD_TYPE_EXCHANGE = iota + 1 //兑换 6 + SU_MONEY_TRANSACTION_RECORD_TYPE_EXCHANGE = iota + 1 //兑换物资
7 SU_MONEY_TRANSACTION_RECORD_TYPE_AWARD //任务奖励 7 SU_MONEY_TRANSACTION_RECORD_TYPE_AWARD //任务奖励
8 SU_MONEY_TRANSACTION_RECORD_TYPE_INCREASE //增加 8 SU_MONEY_TRANSACTION_RECORD_TYPE_INCREASE //增加
9 SU_MONEY_TRANSACTION_RECORD_TYPE_DEDUCT //扣除 9 SU_MONEY_TRANSACTION_RECORD_TYPE_DEDUCT //扣除
  10 + SU_MONEY_TRANSACTION_RECORD_TYPE_EXCHANGE_CASH //兑换现金
  11 + SU_MONEY_TRANSACTION_RECORD_TYPE_EXCHANGE_CASH_RESTORE // 兑换现金撤销
10 ) 12 )
11 13
12 // 素币事务记录 14 // 素币事务记录
13 type SuMoneyTransactionRecord struct { 15 type SuMoneyTransactionRecord struct {
14 - // 素币事务记录ID  
15 - SuMoneyTransactionRecordId int64 `json:"suMoneyTransactionRecordId"`  
16 - // 记录类型  
17 - RecordType int `json:"recordType"`  
18 - // 记录关联员工  
19 - Employee *EmployeeInfo `json:"employee"`  
20 - // 事务处理前素币值  
21 - SuMoneyBeforeTransaction float64 `json:"suMoneyBeforeTransaction"`  
22 - // 当前素币值  
23 - CurrentSuMoney float64 `json:"currentSuMoney"`  
24 - // 事务素币值  
25 - SuMoney float64 `json:"suMoney"`  
26 - // 操作人  
27 - Operator *EmployeeInfo `json:"operator"`  
28 - // 素币事务记录描述  
29 - RecordDescription string `json:"recordDescription"`  
30 - // 创建时间  
31 - CreateTime time.Time `json:"createTime"` 16 + SuMoneyTransactionRecordId int64 `json:"suMoneyTransactionRecordId"` // 素币事务记录ID
  17 + RecordType int `json:"recordType"` // 记录类型
  18 + Employee *EmployeeInfo `json:"employee"` // 记录关联员工
  19 + SuMoneyBeforeTransaction float64 `json:"suMoneyBeforeTransaction"` // 事务处理前素币值
  20 + CurrentSuMoney float64 `json:"currentSuMoney"` // 当前素币值
  21 + SuMoney float64 `json:"suMoney"` // 事务素币值
  22 + CashBeforeTransaction float64 `json:"cashBeforeTransaction"` // 事务处理前现金值
  23 + CurrentCash float64 `json:"currentCash"` // 当前现金值
  24 + Cash float64 `json:"cash"` // 事务现金值
  25 + Operator *EmployeeInfo `json:"operator"` // 操作人
  26 + RecordDescription string `json:"recordDescription"` // 素币事务记录描述
  27 + CreateTime time.Time `json:"createTime"` // 创建时间
32 } 28 }
33 29
34 type SuMoneyTransactionRecordRepository interface { 30 type SuMoneyTransactionRecordRepository interface {
@@ -36,6 +32,7 @@ type SuMoneyTransactionRecordRepository interface { @@ -36,6 +32,7 @@ type SuMoneyTransactionRecordRepository interface {
36 Remove(suMoneyTransactionRecord *SuMoneyTransactionRecord) (*SuMoneyTransactionRecord, error) 32 Remove(suMoneyTransactionRecord *SuMoneyTransactionRecord) (*SuMoneyTransactionRecord, error)
37 FindOne(queryOptions map[string]interface{}) (*SuMoneyTransactionRecord, error) 33 FindOne(queryOptions map[string]interface{}) (*SuMoneyTransactionRecord, error)
38 Find(queryOptions map[string]interface{}) (int64, []*SuMoneyTransactionRecord, error) 34 Find(queryOptions map[string]interface{}) (int64, []*SuMoneyTransactionRecord, error)
  35 + FindById(queryOptions map[string]interface{}) (int64, []*SuMoneyTransactionRecord, error)
39 } 36 }
40 37
41 func (suMoneyTransactionRecord *SuMoneyTransactionRecord) Identify() interface{} { 38 func (suMoneyTransactionRecord *SuMoneyTransactionRecord) Identify() interface{} {
@@ -24,6 +24,7 @@ const ( @@ -24,6 +24,7 @@ const (
24 TASK_STATUS_COMPLETED //已完成 24 TASK_STATUS_COMPLETED //已完成
25 TASK_STATUS_CLOSED //关闭 25 TASK_STATUS_CLOSED //关闭
26 TASK_STATUS_UNCONFIRMED //待确认 26 TASK_STATUS_UNCONFIRMED //待确认
  27 + TASK_STATUS_EXPIRED //已过期
27 ) 28 )
28 29
29 // 任务 30 // 任务
@@ -50,6 +51,10 @@ type Task struct { @@ -50,6 +51,10 @@ type Task struct {
50 TaskNature int `json:"taskNature"` 51 TaskNature int `json:"taskNature"`
51 // 奖励素币 52 // 奖励素币
52 SuMoney float64 `json:"suMoney"` 53 SuMoney float64 `json:"suMoney"`
  54 + // 最小奖励素币
  55 + MinSuMoney float64 `json:"minSuMoney"`
  56 + // 最大奖励素币
  57 + MaxSuMoney float64 `json:"maxSuMoney"`
53 // 验收标准 58 // 验收标准
54 AcceptanceStandard string `json:"acceptanceStandard"` 59 AcceptanceStandard string `json:"acceptanceStandard"`
55 // 任务描述 60 // 任务描述
@@ -98,11 +103,12 @@ type TaskStatus interface { @@ -98,11 +103,12 @@ type TaskStatus interface {
98 ChooseSuccessfulBidder(task *Task, successfulBidder *EmployeeInfo, plannedCompletionTime time.Time) error 103 ChooseSuccessfulBidder(task *Task, successfulBidder *EmployeeInfo, plannedCompletionTime time.Time) error
99 ApplyComplete(task *Task) error 104 ApplyComplete(task *Task) error
100 Off(task *Task) error 105 Off(task *Task) error
101 - Acceptance(task *Task, participators []*EmployeeInfo, taskPercentage []*TaskPercentageItem, referenceResourceScore []*ReferenceResourceItem, solveReport string, solvePictureUrls []string, actualCompletionTime time.Time) error 106 + Acceptance(task *Task, participators []*EmployeeInfo, suMoney float64, taskPercentage []*TaskPercentageItem, referenceResourceScore []*ReferenceResourceItem, solveReport string, solvePictureUrls []string, actualCompletionTime time.Time) error
102 ConfirmTask(task *Task, plannedCompletionTime time.Time) error 107 ConfirmTask(task *Task, plannedCompletionTime time.Time) error
103 RejectReceiver(task *Task) error 108 RejectReceiver(task *Task) error
104 } 109 }
105 110
  111 +// 待发布的任务
106 type UnReleasedStatus struct{} 112 type UnReleasedStatus struct{}
107 113
108 func (status *UnReleasedStatus) Update(task *Task, data map[string]interface{}) error { 114 func (status *UnReleasedStatus) Update(task *Task, data map[string]interface{}) error {
@@ -127,6 +133,12 @@ func (status *UnReleasedStatus) Update(task *Task, data map[string]interface{}) @@ -127,6 +133,12 @@ func (status *UnReleasedStatus) Update(task *Task, data map[string]interface{})
127 if suMoney, ok := data["suMoney"]; ok { 133 if suMoney, ok := data["suMoney"]; ok {
128 task.SuMoney = suMoney.(float64) 134 task.SuMoney = suMoney.(float64)
129 } 135 }
  136 + if minSuMoney, ok := data["minSuMoney"]; ok {
  137 + task.MinSuMoney = minSuMoney.(float64)
  138 + }
  139 + if maxSuMoney, ok := data["maxSuMoney"]; ok {
  140 + task.MaxSuMoney = maxSuMoney.(float64)
  141 + }
130 if task.TaskType == TASK_TYPE_BID { 142 if task.TaskType == TASK_TYPE_BID {
131 if bidStartTime, ok := data["bidStartTime"]; ok { 143 if bidStartTime, ok := data["bidStartTime"]; ok {
132 task.BidInfo.BidStartTime = bidStartTime.(time.Time) 144 task.BidInfo.BidStartTime = bidStartTime.(time.Time)
@@ -198,7 +210,7 @@ func (status *UnReleasedStatus) Off(task *Task) error { @@ -198,7 +210,7 @@ func (status *UnReleasedStatus) Off(task *Task) error {
198 return fmt.Errorf("待发布的任务不允许关闭") 210 return fmt.Errorf("待发布的任务不允许关闭")
199 } 211 }
200 212
201 -func (status *UnReleasedStatus) Acceptance(task *Task, participators []*EmployeeInfo, taskPercentage []*TaskPercentageItem, referenceResourceScore []*ReferenceResourceItem, solveReport string, solvePictureUrls []string, actualCompletionTime time.Time) error { 213 +func (status *UnReleasedStatus) Acceptance(task *Task, participators []*EmployeeInfo, suMoney float64, taskPercentage []*TaskPercentageItem, referenceResourceScore []*ReferenceResourceItem, solveReport string, solvePictureUrls []string, actualCompletionTime time.Time) error {
202 return fmt.Errorf("待发布的任务不允许验收") 214 return fmt.Errorf("待发布的任务不允许验收")
203 } 215 }
204 216
@@ -213,7 +225,68 @@ func (status *UnReleasedStatus) RejectReceiver(task *Task) error { @@ -213,7 +225,68 @@ func (status *UnReleasedStatus) RejectReceiver(task *Task) error {
213 type UnClaimedStatus struct{} 225 type UnClaimedStatus struct{}
214 226
215 func (status *UnClaimedStatus) Update(task *Task, data map[string]interface{}) error { 227 func (status *UnClaimedStatus) Update(task *Task, data map[string]interface{}) error {
216 - return fmt.Errorf("待领取的任务不允许编辑") 228 + if taskName, ok := data["taskName"]; ok {
  229 + task.TaskName = taskName.(string)
  230 + }
  231 + if referenceResourceType, ok := data["referenceResourceType"]; ok {
  232 + task.ReferenceResource.ReferenceResourceType = referenceResourceType.(int)
  233 + }
  234 + if referenceResourceItems, ok := data["referenceResourceItems"]; ok {
  235 + task.ReferenceResource.ReferenceResourceItems = referenceResourceItems.([]*ReferenceResourceItem)
  236 + }
  237 + if projectBelong, ok := data["projectBelong"]; ok {
  238 + task.ProjectBelong = projectBelong.(int)
  239 + }
  240 + if customerValues, ok := data["customerValues"]; ok {
  241 + task.CustomerValues = customerValues.([]int)
  242 + }
  243 + if taskNature, ok := data["taskNature"]; ok {
  244 + task.TaskNature = taskNature.(int)
  245 + }
  246 + if suMoney, ok := data["suMoney"]; ok {
  247 + task.SuMoney = suMoney.(float64)
  248 + }
  249 + if minSuMoney, ok := data["minSuMoney"]; ok {
  250 + task.MinSuMoney = minSuMoney.(float64)
  251 + }
  252 + if maxSuMoney, ok := data["maxSuMoney"]; ok {
  253 + task.MaxSuMoney = maxSuMoney.(float64)
  254 + }
  255 + if task.TaskType == TASK_TYPE_BID {
  256 + if bidStartTime, ok := data["bidStartTime"]; ok {
  257 + task.BidInfo.BidStartTime = bidStartTime.(time.Time)
  258 + }
  259 + if bidEndTime, ok := data["bidEndTime"]; ok {
  260 + task.BidInfo.BidEndTime = bidEndTime.(time.Time)
  261 + }
  262 + if isRemind, ok := data["isRemind"]; ok {
  263 + task.BidInfo.IsRemind = isRemind.(bool)
  264 + }
  265 + }
  266 + if acceptanceStandard, ok := data["acceptanceStandard"]; ok {
  267 + task.AcceptanceStandard = acceptanceStandard.(string)
  268 + }
  269 + if taskDescription, ok := data["taskDescription"]; ok {
  270 + task.TaskDescription = taskDescription.(string)
  271 + }
  272 + if taskPictureUrls, ok := data["taskPictureUrls"]; ok {
  273 + task.TaskPictureUrls = taskPictureUrls.([]string)
  274 + }
  275 + if isRewardTake, ok := data["isRewardTake"]; ok {
  276 + task.IsRewardTake = isRewardTake.(bool)
  277 + }
  278 + if task.TaskType == TASK_TYPE_DESIGNATE {
  279 + if plannedCompletionTime, ok := data["plannedCompletionTime"]; ok {
  280 + task.PlannedCompletionTime = plannedCompletionTime.(time.Time)
  281 + }
  282 + if assignedPerson, ok := data["assignedPerson"]; ok {
  283 + task.AssignedPerson = assignedPerson.(*EmployeeInfo)
  284 + if task.AssignedPerson.Uid == 0 {
  285 + task.AssignedPerson = nil
  286 + }
  287 + }
  288 + }
  289 + return nil
217 } 290 }
218 291
219 func (status *UnClaimedStatus) Release(task *Task) error { 292 func (status *UnClaimedStatus) Release(task *Task) error {
@@ -286,7 +359,7 @@ func (status *UnClaimedStatus) Off(task *Task) error { @@ -286,7 +359,7 @@ func (status *UnClaimedStatus) Off(task *Task) error {
286 return nil 359 return nil
287 } 360 }
288 361
289 -func (status *UnClaimedStatus) Acceptance(task *Task, participators []*EmployeeInfo, taskPercentage []*TaskPercentageItem, referenceResourceScore []*ReferenceResourceItem, solveReport string, solvePictureUrls []string, actualCompletionTime time.Time) error { 362 +func (status *UnClaimedStatus) Acceptance(task *Task, participators []*EmployeeInfo, suMoney float64, taskPercentage []*TaskPercentageItem, referenceResourceScore []*ReferenceResourceItem, solveReport string, solvePictureUrls []string, actualCompletionTime time.Time) error {
290 return fmt.Errorf("待领取的任务不允许验收") 363 return fmt.Errorf("待领取的任务不允许验收")
291 } 364 }
292 365
@@ -333,7 +406,7 @@ func (status *UnderwayStatus) Off(task *Task) error { @@ -333,7 +406,7 @@ func (status *UnderwayStatus) Off(task *Task) error {
333 return nil 406 return nil
334 } 407 }
335 408
336 -func (status *UnderwayStatus) Acceptance(task *Task, participators []*EmployeeInfo, taskPercentage []*TaskPercentageItem, referenceResourceScore []*ReferenceResourceItem, solveReport string, solvePictureUrls []string, actualCompletionTime time.Time) error { 409 +func (status *UnderwayStatus) Acceptance(task *Task, participators []*EmployeeInfo, suMoney float64, taskPercentage []*TaskPercentageItem, referenceResourceScore []*ReferenceResourceItem, solveReport string, solvePictureUrls []string, actualCompletionTime time.Time) error {
337 return fmt.Errorf("进行中的任务不允许验收") 410 return fmt.Errorf("进行中的任务不允许验收")
338 } 411 }
339 412
@@ -359,6 +432,7 @@ func (status *UnderwayStatus) RejectReceiver(task *Task) error { @@ -359,6 +432,7 @@ func (status *UnderwayStatus) RejectReceiver(task *Task) error {
359 return nil 432 return nil
360 } 433 }
361 434
  435 +// 代验收的任务
362 type UnAcceptanceStatus struct{} 436 type UnAcceptanceStatus struct{}
363 437
364 func (status *UnAcceptanceStatus) Update(task *Task, data map[string]interface{}) error { 438 func (status *UnAcceptanceStatus) Update(task *Task, data map[string]interface{}) error {
@@ -391,8 +465,9 @@ func (status *UnAcceptanceStatus) Off(task *Task) error { @@ -391,8 +465,9 @@ func (status *UnAcceptanceStatus) Off(task *Task) error {
391 return nil 465 return nil
392 } 466 }
393 467
394 -func (status *UnAcceptanceStatus) Acceptance(task *Task, participators []*EmployeeInfo, taskPercentage []*TaskPercentageItem, referenceResourceScore []*ReferenceResourceItem, solveReport string, solvePictureUrls []string, actualCompletionTime time.Time) error { 468 +func (status *UnAcceptanceStatus) Acceptance(task *Task, participators []*EmployeeInfo, suMoney float64, taskPercentage []*TaskPercentageItem, referenceResourceScore []*ReferenceResourceItem, solveReport string, solvePictureUrls []string, actualCompletionTime time.Time) error {
395 task.Participators = participators 469 task.Participators = participators
  470 + task.SuMoney = suMoney
396 task.TaskPercentage = taskPercentage 471 task.TaskPercentage = taskPercentage
397 task.SolveReport = solveReport 472 task.SolveReport = solveReport
398 task.SolvePictureUrls = solvePictureUrls 473 task.SolvePictureUrls = solvePictureUrls
@@ -451,7 +526,7 @@ func (status *CompletedStatus) Off(task *Task) error { @@ -451,7 +526,7 @@ func (status *CompletedStatus) Off(task *Task) error {
451 return fmt.Errorf("已完成的任务不允许申请完成任务") 526 return fmt.Errorf("已完成的任务不允许申请完成任务")
452 } 527 }
453 528
454 -func (status *CompletedStatus) Acceptance(task *Task, participators []*EmployeeInfo, taskPercentage []*TaskPercentageItem, referenceResourceScore []*ReferenceResourceItem, solveReport string, solvePictureUrls []string, actualCompletionTime time.Time) error { 529 +func (status *CompletedStatus) Acceptance(task *Task, participators []*EmployeeInfo, suMoney float64, taskPercentage []*TaskPercentageItem, referenceResourceScore []*ReferenceResourceItem, solveReport string, solvePictureUrls []string, actualCompletionTime time.Time) error {
455 return fmt.Errorf("已完成的任务不允许验收") 530 return fmt.Errorf("已完成的任务不允许验收")
456 } 531 }
457 532
@@ -493,7 +568,7 @@ func (status *ClosedStatus) Off(task *Task) error { @@ -493,7 +568,7 @@ func (status *ClosedStatus) Off(task *Task) error {
493 return fmt.Errorf("已关闭的任务不允许关闭") 568 return fmt.Errorf("已关闭的任务不允许关闭")
494 } 569 }
495 570
496 -func (status *ClosedStatus) Acceptance(task *Task, participators []*EmployeeInfo, taskPercentage []*TaskPercentageItem, referenceResourceScore []*ReferenceResourceItem, solveReport string, solvePictureUrls []string, actualCompletionTime time.Time) error { 571 +func (status *ClosedStatus) Acceptance(task *Task, participators []*EmployeeInfo, suMoney float64, taskPercentage []*TaskPercentageItem, referenceResourceScore []*ReferenceResourceItem, solveReport string, solvePictureUrls []string, actualCompletionTime time.Time) error {
497 return fmt.Errorf("已关闭的任务不允许验收") 572 return fmt.Errorf("已关闭的任务不允许验收")
498 } 573 }
499 574
@@ -505,6 +580,7 @@ func (status *ClosedStatus) RejectReceiver(task *Task) error { @@ -505,6 +580,7 @@ func (status *ClosedStatus) RejectReceiver(task *Task) error {
505 return fmt.Errorf("已关闭的任务不允许驳回任务领取人") 580 return fmt.Errorf("已关闭的任务不允许驳回任务领取人")
506 } 581 }
507 582
  583 +// 待确认任务
508 type UnConfirmedStatus struct{} 584 type UnConfirmedStatus struct{}
509 585
510 func (status *UnConfirmedStatus) Update(task *Task, data map[string]interface{}) error { 586 func (status *UnConfirmedStatus) Update(task *Task, data map[string]interface{}) error {
@@ -537,7 +613,7 @@ func (status *UnConfirmedStatus) Off(task *Task) error { @@ -537,7 +613,7 @@ func (status *UnConfirmedStatus) Off(task *Task) error {
537 return nil 613 return nil
538 } 614 }
539 615
540 -func (status *UnConfirmedStatus) Acceptance(task *Task, participators []*EmployeeInfo, taskPercentage []*TaskPercentageItem, referenceResourceScore []*ReferenceResourceItem, solveReport string, solvePictureUrls []string, actualCompletionTime time.Time) error { 616 +func (status *UnConfirmedStatus) Acceptance(task *Task, participators []*EmployeeInfo, suMoney float64, taskPercentage []*TaskPercentageItem, referenceResourceScore []*ReferenceResourceItem, solveReport string, solvePictureUrls []string, actualCompletionTime time.Time) error {
541 return fmt.Errorf("待确认的任务不允许验收") 617 return fmt.Errorf("待确认的任务不允许验收")
542 } 618 }
543 619
@@ -560,6 +636,113 @@ func (status *UnConfirmedStatus) RejectReceiver(task *Task) error { @@ -560,6 +636,113 @@ func (status *UnConfirmedStatus) RejectReceiver(task *Task) error {
560 return nil 636 return nil
561 } 637 }
562 638
  639 +type ExpiredStatus struct{}
  640 +
  641 +func (status ExpiredStatus) Update(task *Task, data map[string]interface{}) error {
  642 + if taskName, ok := data["taskName"]; ok {
  643 + task.TaskName = taskName.(string)
  644 + }
  645 + if referenceResourceType, ok := data["referenceResourceType"]; ok {
  646 + task.ReferenceResource.ReferenceResourceType = referenceResourceType.(int)
  647 + }
  648 + if referenceResourceItems, ok := data["referenceResourceItems"]; ok {
  649 + task.ReferenceResource.ReferenceResourceItems = referenceResourceItems.([]*ReferenceResourceItem)
  650 + }
  651 + if projectBelong, ok := data["projectBelong"]; ok {
  652 + task.ProjectBelong = projectBelong.(int)
  653 + }
  654 + if customerValues, ok := data["customerValues"]; ok {
  655 + task.CustomerValues = customerValues.([]int)
  656 + }
  657 + if taskNature, ok := data["taskNature"]; ok {
  658 + task.TaskNature = taskNature.(int)
  659 + }
  660 + if suMoney, ok := data["suMoney"]; ok {
  661 + task.SuMoney = suMoney.(float64)
  662 + }
  663 + if minSuMoney, ok := data["minSuMoney"]; ok {
  664 + task.MinSuMoney = minSuMoney.(float64)
  665 + }
  666 + if maxSuMoney, ok := data["maxSuMoney"]; ok {
  667 + task.MaxSuMoney = maxSuMoney.(float64)
  668 + }
  669 + if task.TaskType == TASK_TYPE_BID {
  670 + if bidStartTime, ok := data["bidStartTime"]; ok {
  671 + task.BidInfo.BidStartTime = bidStartTime.(time.Time)
  672 + }
  673 + if bidEndTime, ok := data["bidEndTime"]; ok {
  674 + task.BidInfo.BidEndTime = bidEndTime.(time.Time)
  675 + }
  676 + if isRemind, ok := data["isRemind"]; ok {
  677 + task.BidInfo.IsRemind = isRemind.(bool)
  678 + }
  679 + }
  680 + if acceptanceStandard, ok := data["acceptanceStandard"]; ok {
  681 + task.AcceptanceStandard = acceptanceStandard.(string)
  682 + }
  683 + if taskDescription, ok := data["taskDescription"]; ok {
  684 + task.TaskDescription = taskDescription.(string)
  685 + }
  686 + if taskPictureUrls, ok := data["taskPictureUrls"]; ok {
  687 + task.TaskPictureUrls = taskPictureUrls.([]string)
  688 + }
  689 + if isRewardTake, ok := data["isRewardTake"]; ok {
  690 + task.IsRewardTake = isRewardTake.(bool)
  691 + }
  692 + if task.TaskType == TASK_TYPE_DESIGNATE {
  693 + if plannedCompletionTime, ok := data["plannedCompletionTime"]; ok {
  694 + task.PlannedCompletionTime = plannedCompletionTime.(time.Time)
  695 + }
  696 + if assignedPerson, ok := data["assignedPerson"]; ok {
  697 + task.AssignedPerson = assignedPerson.(*EmployeeInfo)
  698 + if task.AssignedPerson.Uid == 0 {
  699 + task.AssignedPerson = nil
  700 + }
  701 + }
  702 + }
  703 + return nil
  704 +}
  705 +
  706 +func (status ExpiredStatus) Release(task *Task) error {
  707 + currentTime := time.Now()
  708 + task.ReleaseTime = currentTime
  709 + task.TaskStatus = TASK_STATUS_UNCLAIMED
  710 + task.CurrentStatus = &UnClaimedStatus{}
  711 + return nil
  712 +}
  713 +
  714 +func (status ExpiredStatus) Rob(task *Task, receiver *EmployeeInfo) error {
  715 + return fmt.Errorf("已过期的任务不允许抢单")
  716 +}
  717 +
  718 +func (status ExpiredStatus) Bib(task *Task, bidder *EmployeeInfo) error {
  719 + return fmt.Errorf("已过期的任务不允许竞标")
  720 +}
  721 +
  722 +func (status ExpiredStatus) ChooseSuccessfulBidder(task *Task, successfulBidder *EmployeeInfo, plannedCompletionTime time.Time) error {
  723 + return fmt.Errorf("已过期的任务不允许选择竞标任务的中标人")
  724 +}
  725 +
  726 +func (status ExpiredStatus) ApplyComplete(task *Task) error {
  727 + return fmt.Errorf("已过期的任务不允许申请完成任务")
  728 +}
  729 +
  730 +func (status ExpiredStatus) Off(task *Task) error {
  731 + return fmt.Errorf("已过期的任务不允许关闭")
  732 +}
  733 +
  734 +func (status ExpiredStatus) Acceptance(task *Task, participators []*EmployeeInfo, suMoney float64, taskPercentage []*TaskPercentageItem, referenceResourceScore []*ReferenceResourceItem, solveReport string, solvePictureUrls []string, actualCompletionTime time.Time) error {
  735 + return fmt.Errorf("已过期的任务不允许验收")
  736 +}
  737 +
  738 +func (status ExpiredStatus) ConfirmTask(task *Task, plannedCompletionTime time.Time) error {
  739 + return fmt.Errorf("已过期的任务不允许确认任务领取人")
  740 +}
  741 +
  742 +func (status ExpiredStatus) RejectReceiver(task *Task) error {
  743 + return fmt.Errorf("已过期的任务不允许驳回任务领取人")
  744 +}
  745 +
563 type TaskRepository interface { 746 type TaskRepository interface {
564 Save(task *Task) (*Task, error) 747 Save(task *Task) (*Task, error)
565 Remove(task *Task) (*Task, error) 748 Remove(task *Task) (*Task, error)
@@ -602,8 +785,8 @@ func (task *Task) Off() error { @@ -602,8 +785,8 @@ func (task *Task) Off() error {
602 return task.CurrentStatus.Off(task) 785 return task.CurrentStatus.Off(task)
603 } 786 }
604 787
605 -func (task *Task) Acceptance(participators []*EmployeeInfo, taskPercentage []*TaskPercentageItem, referenceResourceScore []*ReferenceResourceItem, solveReport string, solvePictureUrls []string, actualCompletionTime time.Time) error {  
606 - return task.CurrentStatus.Acceptance(task, participators, taskPercentage, referenceResourceScore, solveReport, solvePictureUrls, actualCompletionTime) 788 +func (task *Task) Acceptance(participators []*EmployeeInfo, suMoney float64, taskPercentage []*TaskPercentageItem, referenceResourceScore []*ReferenceResourceItem, solveReport string, solvePictureUrls []string, actualCompletionTime time.Time) error {
  789 + return task.CurrentStatus.Acceptance(task, participators, suMoney, taskPercentage, referenceResourceScore, solveReport, solvePictureUrls, actualCompletionTime)
607 } 790 }
608 791
609 func (task *Task) ConfirmTask(plannedCompletionTime time.Time) error { 792 func (task *Task) ConfirmTask(plannedCompletionTime time.Time) error {
  1 +package dao
  2 +
  3 +import (
  4 + "fmt"
  5 + pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
  6 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg/models"
  7 +)
  8 +
  9 +type CashPoolDao struct {
  10 + transactionContext *pgTransaction.TransactionContext
  11 +}
  12 +
  13 +// 兑换活动兑换清单已兑换素币、已兑换现金
  14 +func (dao *CashPoolDao) CalculateActivityExchangedSuMoney(activityId int64) (map[string]interface{}, error) {
  15 + var activityExchangedSuMoney float64
  16 + var activityExchangedCash float64
  17 + tx := dao.transactionContext.PgTx
  18 + exchangeCashPersonListModels := new(models.ExchangeCashPersonList)
  19 + if err := tx.Model(exchangeCashPersonListModels).
  20 + ColumnExpr("sum(exchange_cash_person_list.exchanged_su_money) AS activity_exchanged_su_money").
  21 + Where("exchange_cash_person_list.activity_id = ?", activityId).
  22 + Select(&activityExchangedSuMoney); err !=nil {
  23 + return nil, err
  24 + }
  25 + if err := tx.Model(exchangeCashPersonListModels).
  26 + ColumnExpr("sum(exchange_cash_person_list.exchanged_cash) AS activity_exchanged_cash").
  27 + Where("exchange_cash_person_list.activity_id = ?", activityId).
  28 + Select(&activityExchangedCash); err !=nil {
  29 + return nil, err
  30 + }
  31 + return map[string]interface{}{
  32 + "activityExchangedSuMoney": activityExchangedSuMoney,
  33 + "activityExchangedCash": activityExchangedCash,
  34 + }, nil
  35 +}
  36 +
  37 +// 返回兑换活动清单榜单
  38 +func (dao *CashPoolDao) ExchangeCashListRanking(queryOptions map[string]interface{}) (map[string]interface{}, error) {
  39 + var retPeople []struct {
  40 + Uid int64
  41 + EmployeeName string
  42 + SuMoney float64
  43 + Cash float64
  44 + Ranking int
  45 + }
  46 +
  47 + var retEmployee []struct {
  48 + Uid int64
  49 + EmployeeName string
  50 + SuMoney float64
  51 + Cash float64
  52 + Ranking int
  53 + }
  54 +
  55 + tx := dao.transactionContext.PgTx
  56 + exchangeCashPersonListModels := new(models.ExchangeCashPersonList)
  57 +
  58 + // 清单人员排名
  59 + queryPeople := tx.Model(exchangeCashPersonListModels)
  60 + queryPeople = queryPeople.Join("JOIN employees AS e ON e.uid = exchange_cash_person_list.uid")
  61 + queryPeople = queryPeople.ColumnExpr("exchange_cash_person_list.uid AS uid")
  62 + //queryPeople = queryPeople.ColumnExpr("exchange_cash_person_list.employee_name AS employee_name")
  63 + queryPeople = queryPeople.ColumnExpr("sum(exchange_cash_person_list.exchanged_cash) AS cash")
  64 + queryPeople = queryPeople.ColumnExpr("sum(exchange_cash_person_list.exchanged_su_money) AS su_money")
  65 + queryPeople = queryPeople.ColumnExpr("ROW_NUMBER() OVER (ORDER BY sum(exchange_cash_person_list.exchanged_su_money) DESC, e.create_time ASC) AS ranking")
  66 + //queryPeople = queryPeople.Where("e.status = ?", 1)
  67 + if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) {
  68 + queryPeople = queryPeople.Where("e.company_id = ?", companyId)
  69 + }
  70 + if activityId, ok := queryOptions["activityId"]; ok && (activityId.(int64) != 0){
  71 + queryPeople = queryPeople.Where("exchange_cash_person_list.activity_id = ?", activityId)
  72 + }
  73 + queryPeople = queryPeople.Group("exchange_cash_person_list.uid")
  74 + queryPeople = queryPeople.Group("e.create_time")
  75 + //queryPeople = queryPeople.Group("exchange_cash_person_list.employee_name")
  76 + if offset, ok := queryOptions["offset"]; ok {
  77 + offset := offset.(int)
  78 + if offset > -1 {
  79 + queryPeople = queryPeople.Offset(offset)
  80 + }
  81 + } else {
  82 + queryPeople = queryPeople.Offset(0)
  83 + }
  84 + if limit, ok := queryOptions["limit"]; ok {
  85 + limit := limit.(int)
  86 + if limit > -1 {
  87 + queryPeople = queryPeople.Limit(limit)
  88 + }
  89 + } else {
  90 + queryPeople = queryPeople.Limit(20)
  91 + }
  92 + if err := queryPeople.Order("ranking ASC").Select(&retPeople); err != nil {
  93 + return nil, err
  94 + }
  95 +
  96 + // 个人清单排名
  97 + queryPeopleAll := tx.Model(exchangeCashPersonListModels)
  98 + queryPeopleAll = queryPeopleAll.Join("JOIN employees AS e ON e.uid = exchange_cash_person_list.uid")
  99 + queryPeopleAll = queryPeopleAll.ColumnExpr("exchange_cash_person_list.uid AS uid")
  100 + //queryPeopleAll = queryPeopleAll.ColumnExpr("exchange_cash_person_list.employee_name AS employee_name")
  101 + queryPeopleAll = queryPeopleAll.ColumnExpr("sum(exchange_cash_person_list.exchanged_cash) AS cash")
  102 + queryPeopleAll = queryPeopleAll.ColumnExpr("sum(exchange_cash_person_list.exchanged_su_money) AS su_money")
  103 + queryPeopleAll = queryPeopleAll.ColumnExpr("ROW_NUMBER() OVER (ORDER BY sum(exchange_cash_person_list.exchanged_su_money) DESC, e.create_time ASC) AS ranking")
  104 + if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) {
  105 + queryPeopleAll = queryPeopleAll.Where("e.company_id = ?", companyId)
  106 + }
  107 + if activityId, ok := queryOptions["activityId"]; ok && (activityId.(int64) != 0){
  108 + queryPeopleAll = queryPeopleAll.Where("exchange_cash_person_list.activity_id = ?", activityId)
  109 + }
  110 + queryPeopleAll = queryPeopleAll.Group("exchange_cash_person_list.uid")
  111 + queryPeopleAll = queryPeopleAll.Group("e.create_time")
  112 + //queryPeopleAll = queryPeopleAll.Group("exchange_cash_person_list.employee_name")
  113 + queryPeopleAllWith := queryPeopleAll.Order("su_money DESC")
  114 + queryEmployee := tx.Model()
  115 + queryEmployee = queryEmployee.With("t", queryPeopleAllWith)
  116 + queryEmployee = queryEmployee.Table("t")
  117 + queryEmployee = queryEmployee.ColumnExpr("t.uid AS uid")
  118 + //queryEmployee = queryEmployee.ColumnExpr("t.employee_name AS employee_name")
  119 + queryEmployee = queryEmployee.ColumnExpr("t.cash AS cash")
  120 + queryEmployee = queryEmployee.ColumnExpr("t.su_money AS su_money")
  121 + queryEmployee = queryEmployee.ColumnExpr("t.ranking AS ranking")
  122 + if uid, ok := queryOptions["uid"]; ok {
  123 + queryEmployee = queryEmployee.Where("t.uid::bigint = ?", uid)
  124 + }
  125 +
  126 + if err := queryEmployee.Select(&retEmployee); err != nil {
  127 + return nil, err
  128 + }
  129 + var currentEmployee interface{}
  130 + if len(retEmployee) == 0 {
  131 + currentEmployee = nil
  132 + } else {
  133 + currentEmployee = retEmployee[0]
  134 + }
  135 +
  136 + // 清单已兑换素币
  137 + var activityExchangedSuMoney float64
  138 + queryListSuMoney := tx.Model(exchangeCashPersonListModels)
  139 + queryListSuMoney = queryListSuMoney.Join("JOIN employees AS e ON e.uid = exchange_cash_person_list.uid")
  140 + queryListSuMoney = queryListSuMoney.ColumnExpr("sum(exchange_cash_person_list.exchanged_su_money) AS activity_exchanged_su_money")
  141 + //queryListSuMoney = queryListSuMoney.Where("e.status = ?", 1)
  142 + if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) {
  143 + queryListSuMoney = queryListSuMoney.Where("e.company_id = ?", companyId)
  144 + }
  145 + if activityId, ok := queryOptions["activityId"]; ok && (activityId.(int64) != 0) {
  146 + queryListSuMoney = queryListSuMoney.Where("exchange_cash_person_list.activity_id = ?", activityId)
  147 + }
  148 + if err := queryListSuMoney.Select(&activityExchangedSuMoney); err != nil {
  149 + return nil, err
  150 + }
  151 +
  152 + // 清单已兑换现金
  153 + var activityExchangedCash float64
  154 + queryListCash := tx.Model(exchangeCashPersonListModels)
  155 + queryListCash = queryListCash.Join("JOIN employees AS e ON e.uid = exchange_cash_person_list.uid")
  156 + queryListCash = queryListCash.ColumnExpr("sum(exchange_cash_person_list.exchanged_cash) AS activity_exchanged_cash")
  157 + //queryListCash = queryListCash.Where("e.status = ?", 1)
  158 + if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) {
  159 + queryListCash = queryListCash.Where("e.company_id = ?", companyId)
  160 + }
  161 + if activityId, ok := queryOptions["activityId"]; ok && (activityId.(int64) != 0) {
  162 + queryListCash = queryListCash.Where("exchange_cash_person_list.activity_id = ?", activityId)
  163 + }
  164 + if err := queryListCash.Select(&activityExchangedCash); err != nil {
  165 + return nil, err
  166 + }
  167 +
  168 + // 清单计数
  169 + queryCount := tx.Model(exchangeCashPersonListModels)
  170 + count, err := queryCount.Count()
  171 + if err != nil {
  172 + return nil, err
  173 + }
  174 +
  175 + return map[string]interface{} {
  176 + "people": retPeople, // 员工排行榜
  177 + "count": count, // 计数
  178 + "currentEmployee": currentEmployee, // 当前员工排名
  179 + "exchangedSuMoney": activityExchangedSuMoney, // 清单已兑换素币
  180 + "exchangedCash": activityExchangedCash, // 清单已兑换现金
  181 + }, nil
  182 +}
  183 +
  184 +func NewCashPoolDao(transactionContext *pgTransaction.TransactionContext) (*CashPoolDao, error) {
  185 + if transactionContext == nil {
  186 + return nil, fmt.Errorf("transactionContext参数不能为nil")
  187 + } else {
  188 + return &CashPoolDao{
  189 + transactionContext: transactionContext,
  190 + }, nil
  191 + }
  192 +}
@@ -13,15 +13,23 @@ type EmployeeDao struct { @@ -13,15 +13,23 @@ type EmployeeDao struct {
13 transactionContext *pgTransaction.TransactionContext 13 transactionContext *pgTransaction.TransactionContext
14 } 14 }
15 15
  16 +// 删除用户(stevechan: 删除员工为修改为禁用状态)
16 func (dao *EmployeeDao) BatchRemove(uids []int64) error { 17 func (dao *EmployeeDao) BatchRemove(uids []int64) error {
  18 + //tx := dao.transactionContext.PgTx
  19 + //_, err := tx.QueryOne(
  20 + // pg.Scan(),
  21 + // "DELETE FROM employees WHERE uid IN (?)",
  22 + // pg.In(uids))
  23 + //return err
17 tx := dao.transactionContext.PgTx 24 tx := dao.transactionContext.PgTx
18 _, err := tx.QueryOne( 25 _, err := tx.QueryOne(
19 pg.Scan(), 26 pg.Scan(),
20 - "DELETE FROM employees WHERE uid IN (?)", 27 + "UPDATE employees SET status = 2 WHERE uid IN (?)",
21 pg.In(uids)) 28 pg.In(uids))
22 return err 29 return err
23 } 30 }
24 31
  32 +// 设置用户状态
25 func (dao *EmployeeDao) BatchSetStatus(uids []int64, status int) error { 33 func (dao *EmployeeDao) BatchSetStatus(uids []int64, status int) error {
26 tx := dao.transactionContext.PgTx 34 tx := dao.transactionContext.PgTx
27 _, err := tx.QueryOne( 35 _, err := tx.QueryOne(
@@ -31,6 +39,7 @@ func (dao *EmployeeDao) BatchSetStatus(uids []int64, status int) error { @@ -31,6 +39,7 @@ func (dao *EmployeeDao) BatchSetStatus(uids []int64, status int) error {
31 return err 39 return err
32 } 40 }
33 41
  42 +// 修改用户权限
34 func (dao *EmployeeDao) ChangePrincipal(companyId int64, employeeAccount string) error { 43 func (dao *EmployeeDao) ChangePrincipal(companyId int64, employeeAccount string) error {
35 tx := dao.transactionContext.PgTx 44 tx := dao.transactionContext.PgTx
36 if _, err := tx.Query( 45 if _, err := tx.Query(
@@ -48,6 +57,7 @@ func (dao *EmployeeDao) ChangePrincipal(companyId int64, employeeAccount string) @@ -48,6 +57,7 @@ func (dao *EmployeeDao) ChangePrincipal(companyId int64, employeeAccount string)
48 return nil 57 return nil
49 } 58 }
50 59
  60 +// 更新用户素币
51 func (dao *EmployeeDao) TransferSuMoney(uid int64, suMoney float64) error { 61 func (dao *EmployeeDao) TransferSuMoney(uid int64, suMoney float64) error {
52 tx := dao.transactionContext.PgTx 62 tx := dao.transactionContext.PgTx
53 _, err := tx.QueryOne( 63 _, err := tx.QueryOne(
@@ -57,6 +67,7 @@ func (dao *EmployeeDao) TransferSuMoney(uid int64, suMoney float64) error { @@ -57,6 +67,7 @@ func (dao *EmployeeDao) TransferSuMoney(uid int64, suMoney float64) error {
57 return err 67 return err
58 } 68 }
59 69
  70 +// 计算个人未读消息
60 func (dao *EmployeeDao) CalculatePersonUnReadNotification(uid int64) (map[string]int, error) { 71 func (dao *EmployeeDao) CalculatePersonUnReadNotification(uid int64) (map[string]int, error) {
61 var unReadSystemNotification int 72 var unReadSystemNotification int
62 var unReadInteractionNotification int 73 var unReadInteractionNotification int
@@ -86,39 +97,130 @@ func (dao *EmployeeDao) CalculatePersonUnReadNotification(uid int64) (map[string @@ -86,39 +97,130 @@ func (dao *EmployeeDao) CalculatePersonUnReadNotification(uid int64) (map[string
86 }, nil 97 }, nil
87 } 98 }
88 99
  100 +// 计算个人素币收益,昨日收益:做任务验收获得的素币+额外增加-扣除素币-兑换物资-兑换现金
89 func (dao *EmployeeDao) CalculatePersonSuMoney(uid int64) (map[string]interface{}, error) { 101 func (dao *EmployeeDao) CalculatePersonSuMoney(uid int64) (map[string]interface{}, error) {
90 var incomeSuMoney float64 102 var incomeSuMoney float64
91 var incomeSuMoneyOfYesterday float64 103 var incomeSuMoneyOfYesterday float64
  104 + var expendSuMoneyOfYesterday float64
92 tx := dao.transactionContext.PgTx 105 tx := dao.transactionContext.PgTx
93 suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord) 106 suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
94 - yesterday := time.Now().AddDate(0, 0, -1) 107 + yesterday := time.Now().Local().AddDate(0, 0, -1)
  108 + // 昨日收益
95 if err := tx.Model(suMoneyTransactionRecordModel). 109 if err := tx.Model(suMoneyTransactionRecordModel).
96 ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money"). 110 ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money").
97 Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid). 111 Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid).
98 - Where(`su_money_transaction_record.record_type = ?`, 2).  
99 - Where(`su_money_transaction_record.create_time > ?`, time.Date(yesterday.Year(), yesterday.Month(), yesterday.Day(), 0, 0, 0, 0, yesterday.Location())).  
100 - Where(`su_money_transaction_record.create_time < ?`, time.Date(yesterday.Year(), yesterday.Month(), yesterday.Day(), 23, 59, 59, 0, yesterday.Location())). 112 + Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3, 6})).
  113 + Where(`su_money_transaction_record.create_time > ?`, time.Date(yesterday.Year(), yesterday.Month(), yesterday.Day(), 0, 0, 0, 0, time.Local)).
  114 + Where(`su_money_transaction_record.create_time < ?`, time.Date(yesterday.Year(), yesterday.Month(), yesterday.Day(), 23, 59, 59, 0, time.Local)).
101 Select(&incomeSuMoneyOfYesterday); err != nil { 115 Select(&incomeSuMoneyOfYesterday); err != nil {
102 return nil, err 116 return nil, err
103 } 117 }
104 if err := tx.Model(suMoneyTransactionRecordModel). 118 if err := tx.Model(suMoneyTransactionRecordModel).
105 ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money"). 119 ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money").
106 Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid). 120 Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid).
  121 + Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{4, 1, 5})).
  122 + Where(`su_money_transaction_record.create_time > ?`, time.Date(yesterday.Year(), yesterday.Month(), yesterday.Day(), 0, 0, 0, 0, time.Local)).
  123 + Where(`su_money_transaction_record.create_time < ?`, time.Date(yesterday.Year(), yesterday.Month(), yesterday.Day(), 23, 59, 59, 0, time.Local)).
  124 + Select(&expendSuMoneyOfYesterday); err != nil {
  125 + return nil, err
  126 + }
  127 + // 个人收益
  128 + if err := tx.Model(suMoneyTransactionRecordModel).
  129 + ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money").
  130 + Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid).
107 Where(`su_money_transaction_record.record_type = ?`, 2). 131 Where(`su_money_transaction_record.record_type = ?`, 2).
108 Select(&incomeSuMoney); err != nil { 132 Select(&incomeSuMoney); err != nil {
109 return nil, err 133 return nil, err
110 } 134 }
111 return map[string]interface{}{ 135 return map[string]interface{}{
112 "incomeSuMoney": incomeSuMoney, 136 "incomeSuMoney": incomeSuMoney,
113 - "incomeSuMoneyOfYesterday": incomeSuMoneyOfYesterday, 137 + "incomeSuMoneyOfYesterday": incomeSuMoneyOfYesterday - expendSuMoneyOfYesterday,
  138 + }, nil
  139 +}
  140 +
  141 +// 计算系统已兑换现金素币、未兑换素币
  142 +func (dao *EmployeeDao) CalculateSystemSuMoney(companyId int64) (map[string] interface{}, error) {
  143 + var systemUnExchangeSuMoney float64
  144 + var systemExchangedSuMoney float64
  145 + var systemExchangedSuMoneyRestore float64
  146 + tx := dao.transactionContext.PgTx
  147 + // 系统未兑换素币
  148 + employeeModel := new(models.Employee)
  149 + if err := tx.Model(employeeModel).
  150 + ColumnExpr("sum(employee.su_money) AS system_unExchange_su_money").
  151 + Where("employee.company_id = ?", companyId).
  152 + Where("employee.status = ?", 1).
  153 + Select(&systemUnExchangeSuMoney); err != nil {
  154 + return nil, err
  155 + }
  156 + // 系统已兑换现金素币
  157 + suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
  158 + if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint").
  159 + ColumnExpr("sum(su_money_transaction_record.su_money) AS system_exchanged_su_money").
  160 + Where("e.company_id = ?", companyId).
  161 + //Where("e.status = ?", 1).
  162 + Where(`su_money_transaction_record.record_type = ?`, domain.SU_MONEY_TRANSACTION_RECORD_TYPE_EXCHANGE_CASH).
  163 + Select(&systemExchangedSuMoney); err != nil {
  164 + return nil, err
  165 + }
  166 + // 系统撤销的兑换现金素币
  167 + if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint").
  168 + ColumnExpr("sum(su_money_transaction_record.su_money) AS system_exchanged_su_money").
  169 + Where("e.company_id = ?", companyId).
  170 + //Where("e.status = ?", 1).
  171 + Where(`su_money_transaction_record.record_type = ?`, domain.SU_MONEY_TRANSACTION_RECORD_TYPE_EXCHANGE_CASH_RESTORE).
  172 + Select(&systemExchangedSuMoneyRestore); err != nil {
  173 + return nil, err
  174 + }
  175 + return map[string] interface{} {
  176 + "systemUnExchangeSuMoney": systemUnExchangeSuMoney,
  177 + "systemExchangedSuMoney": systemExchangedSuMoney - systemExchangedSuMoneyRestore,
  178 + },nil
  179 +}
  180 +
  181 +// 计算现金池已兑换现金、未兑换现金
  182 +func (dao *EmployeeDao) CalculateSystemCash(companyId int64) (map[string] interface{}, error) {
  183 + tx := dao.transactionContext.PgTx
  184 + var (
  185 + systemUnExchangeCash float64
  186 + systemExchangedCash float64
  187 + )
  188 + // 系统已兑换现金
  189 + cashPool := new(models.CashPool)
  190 + if err := tx.Model(cashPool).
  191 + Column("exchanged_cash").
  192 + Where("cash_pool.company_id = ?", companyId).
  193 + Order("id DESC").
  194 + Limit(1).
  195 + Select(&systemExchangedCash) ; err != nil {
  196 + return nil, err
  197 + }
  198 + // 系统未兑换现金
  199 + if err := tx.Model(cashPool).
  200 + Column("un_exchange_cash").
  201 + Where("cash_pool.company_id = ?", companyId).
  202 + Order("id DESC").
  203 + Limit(1).
  204 + Select(&systemUnExchangeCash) ; err != nil {
  205 + return nil, err
  206 + }
  207 + return map[string] interface{} {
  208 + "systemUnExchangeCash": systemUnExchangeCash,
  209 + "systemExchangedCash": systemExchangedCash,
114 }, nil 210 }, nil
115 } 211 }
116 212
  213 +// 计算个人素币收支(素币明细收支)
117 func (dao *EmployeeDao) CalculateSuMoneyTransactionRecord(uid int64, transactionStartTime time.Time, transactionEndTime time.Time) (map[string]interface{}, error) { 214 func (dao *EmployeeDao) CalculateSuMoneyTransactionRecord(uid int64, transactionStartTime time.Time, transactionEndTime time.Time) (map[string]interface{}, error) {
118 - var incomeSuMoney float64  
119 - var expendSuMoney float64 215 + var (
  216 + incomeSuMoney float64 // 收入的素币(2:任务奖励,3:增加)
  217 + expendSuMoney float64 // 消耗的素币(1:兑换物资,4:扣除)
  218 + expendSuMoneyExchange float64 // 5: 兑换现金
  219 + incomeSuMoneyExchangeRestore float64 // 6: 兑换素币撤回
  220 + )
120 tx := dao.transactionContext.PgTx 221 tx := dao.transactionContext.PgTx
121 suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord) 222 suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
  223 + // 收入素币
122 if err := tx.Model(suMoneyTransactionRecordModel). 224 if err := tx.Model(suMoneyTransactionRecordModel).
123 ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money"). 225 ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money").
124 Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid). 226 Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid).
@@ -128,6 +230,7 @@ func (dao *EmployeeDao) CalculateSuMoneyTransactionRecord(uid int64, transaction @@ -128,6 +230,7 @@ func (dao *EmployeeDao) CalculateSuMoneyTransactionRecord(uid int64, transaction
128 Select(&incomeSuMoney); err != nil { 230 Select(&incomeSuMoney); err != nil {
129 return nil, err 231 return nil, err
130 } 232 }
  233 + // 支出素币
131 if err := tx.Model(suMoneyTransactionRecordModel). 234 if err := tx.Model(suMoneyTransactionRecordModel).
132 ColumnExpr("sum(su_money_transaction_record.su_money) AS expend_su_money"). 235 ColumnExpr("sum(su_money_transaction_record.su_money) AS expend_su_money").
133 Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid). 236 Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid).
@@ -137,9 +240,349 @@ func (dao *EmployeeDao) CalculateSuMoneyTransactionRecord(uid int64, transaction @@ -137,9 +240,349 @@ func (dao *EmployeeDao) CalculateSuMoneyTransactionRecord(uid int64, transaction
137 Select(&expendSuMoney); err != nil { 240 Select(&expendSuMoney); err != nil {
138 return nil, err 241 return nil, err
139 } 242 }
  243 + // 兑换现金的
  244 + if err := tx.Model(suMoneyTransactionRecordModel).
  245 + ColumnExpr("sum(su_money_transaction_record.su_money) AS expend_su_money").
  246 + Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid).
  247 + Where(`su_money_transaction_record.record_type = ?`, 5).
  248 + Where(`su_money_transaction_record.create_time > ?`, transactionStartTime).
  249 + Where(`su_money_transaction_record.create_time < ?`, transactionEndTime).
  250 + Select(&expendSuMoneyExchange); err != nil {
  251 + return nil, err
  252 + }
  253 + // 兑换现金撤回的
  254 + if err := tx.Model(suMoneyTransactionRecordModel).
  255 + ColumnExpr("sum(su_money_transaction_record.su_money) AS expend_su_money").
  256 + Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid).
  257 + Where(`su_money_transaction_record.record_type = ?`, 6).
  258 + Where(`su_money_transaction_record.create_time > ?`, transactionStartTime).
  259 + Where(`su_money_transaction_record.create_time < ?`, transactionEndTime).
  260 + Select(&incomeSuMoneyExchangeRestore); err != nil {
  261 + return nil, err
  262 + }
140 return map[string]interface{}{ 263 return map[string]interface{}{
141 - "incomeSuMoney": incomeSuMoney,  
142 - "expendSuMoney": expendSuMoney, 264 + "incomeSuMoney": incomeSuMoney, // 个人素币收入
  265 + "expendSuMoney": expendSuMoney + (expendSuMoneyExchange - incomeSuMoneyExchangeRestore), // 个人素币支出
  266 + }, nil
  267 +}
  268 +
  269 +// 计算个人贡献值收支(贡献明细收支)
  270 +func (dao *EmployeeDao) CalculateContributionsTransactionRecord(uid int64, transactionStartTime time.Time, transactionEndTime time.Time) (map[string]interface{}, error) {
  271 + var (
  272 + incomeContributions float64 // 收入的贡献值(2:任务奖励,3:增加)
  273 + expendContributions float64 // 支出的贡献值 (4: 扣除)
  274 + )
  275 + tx := dao.transactionContext.PgTx
  276 + suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
  277 +
  278 + if transactionStartTime.IsZero() && transactionEndTime.IsZero() {
  279 + transactionStartTime = time.Date(1970, 1, 1, 0, 0, 0, 0, time.Local)
  280 + transactionEndTime = time.Now()
  281 + }
  282 +
  283 + // 收入的贡献值
  284 + if err := tx.Model(suMoneyTransactionRecordModel).
  285 + ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money").
  286 + Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid).
  287 + Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3})).
  288 + Where(`su_money_transaction_record.create_time > ?`, transactionStartTime).
  289 + Where(`su_money_transaction_record.create_time < ?`, transactionEndTime).
  290 + Select(&incomeContributions); err != nil {
  291 + return nil, err
  292 + }
  293 + // 支出的贡献值
  294 + if err := tx.Model(suMoneyTransactionRecordModel).
  295 + ColumnExpr("sum(su_money_transaction_record.su_money) AS expend_su_money").
  296 + Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid).
  297 + Where(`su_money_transaction_record.record_type = ?`, 4).
  298 + Where(`su_money_transaction_record.create_time > ?`, transactionStartTime).
  299 + Where(`su_money_transaction_record.create_time < ?`, transactionEndTime).
  300 + Select(&expendContributions); err != nil {
  301 + return nil, err
  302 + }
  303 + return map[string]interface{}{
  304 + "incomeContributions": incomeContributions, // 个人贡献值收入
  305 + "expendContributions": expendContributions, // 个人贡献支出
  306 + }, nil
  307 +}
  308 +
  309 +// 贡献值、财富值总榜和年榜,
  310 +func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]interface{}) (interface{}, error) {
  311 + var retWealth []struct { // 个人财富值
  312 + Uid int64
  313 + EmployeeName string
  314 + EmployeeSuMoney float64
  315 + Ranking int
  316 + }
  317 + var retEmployeeWealth []struct { // 个人贡献值
  318 + Uid int64
  319 + EmployeeName string
  320 + EmployeeSuMoney float64
  321 + Ranking int
  322 + }
  323 + var retContributions []struct { // 员工贡献值
  324 + Uid int64
  325 + EmployeeName string
  326 + EmployeesContributions float64
  327 + Ranking int
  328 + }
  329 + var retEmployeeContributions []struct { // 员工贡献值
  330 + Uid int64
  331 + EmployeeName string
  332 + EmployeesContributions float64
  333 + Ranking int
  334 + }
  335 +
  336 + tx := dao.transactionContext.PgTx
  337 + suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
  338 +
  339 + // 财富值排行榜
  340 + queryWealth := tx.Model(suMoneyTransactionRecordModel)
  341 + queryWealth = queryWealth.Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint")
  342 + queryWealth = queryWealth.ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid")
  343 + //queryWealth = queryWealth.ColumnExpr("su_money_transaction_record.employee->>'employeeName' AS employee_name")
  344 + queryWealth = queryWealth.ColumnExpr("sum(case WHEN su_money_transaction_record.record_type IN (2, 3, 6) THEN su_money_transaction_record.su_money ELSE 0 end) - sum(case WHEN su_money_transaction_record.record_type IN (4, 1, 5) THEN su_money_transaction_record.su_money ELSE 0 end) AS employee_su_money")
  345 + queryWealth = queryWealth.ColumnExpr("ROW_NUMBER() OVER (ORDER BY sum(case WHEN su_money_transaction_record.record_type IN (2, 3, 6) THEN su_money_transaction_record.su_money ELSE 0 end) - sum(case WHEN su_money_transaction_record.record_type IN (4, 1, 5) THEN su_money_transaction_record.su_money ELSE 0 end) DESC, e.create_time ASC) AS ranking")
  346 + queryWealth = queryWealth.Where(`e.status = ?`, 1)
  347 + //queryWealth = queryWealth.GroupExpr("su_money_transaction_record.employee->>'uid',su_money_transaction_record.employee->>'employeeName'")
  348 + queryWealth = queryWealth.GroupExpr("su_money_transaction_record.employee->>'uid', e.create_time")
  349 + if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) {
  350 + queryWealth = queryWealth.Where("e.company_id = ?", companyId)
  351 + }
  352 + if startTime, ok := queryOptions["startTime"]; ok && !startTime.(time.Time).IsZero() {
  353 + queryWealth = queryWealth.Where(`su_money_transaction_record.create_time > ?`, startTime)
  354 + }
  355 + if endTime, ok := queryOptions["endTime"]; ok && !endTime.(time.Time).IsZero() {
  356 + queryWealth = queryWealth.Where(`su_money_transaction_record.create_time < ?`, endTime)
  357 + }
  358 + if offset, ok := queryOptions["offset"]; ok {
  359 + offset := offset.(int)
  360 + if offset > -1 {
  361 + queryWealth = queryWealth.Offset(offset)
  362 + }
  363 + } else {
  364 + queryWealth = queryWealth.Offset(0)
  365 + }
  366 + if limit, ok := queryOptions["limit"]; ok {
  367 + limit := limit.(int)
  368 + if limit > -1 {
  369 + queryWealth = queryWealth.Limit(limit)
  370 + }
  371 + } else {
  372 + queryWealth = queryWealth.Limit(20)
  373 + }
  374 + queryWealth = queryWealth.Order("ranking ASC")
  375 + if err := queryWealth.Select(&retWealth); err != nil {
  376 + return nil, err
  377 + }
  378 +
  379 + // 个人财富值排名
  380 + queryWealthWith := tx.Model(suMoneyTransactionRecordModel)
  381 + queryWealthWith = queryWealthWith.Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint")
  382 + queryWealthWith = queryWealthWith.ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid")
  383 + //queryWealthWith = queryWealthWith.ColumnExpr("su_money_transaction_record.employee->>'employeeName' AS employee_name")
  384 + queryWealthWith = queryWealthWith.ColumnExpr("sum(case WHEN su_money_transaction_record.record_type IN (2, 3, 6) THEN su_money_transaction_record.su_money ELSE 0 end) - sum(case WHEN su_money_transaction_record.record_type IN (4, 1, 5) THEN su_money_transaction_record.su_money ELSE 0 end) AS employee_su_money")
  385 + queryWealthWith = queryWealthWith.ColumnExpr("ROW_NUMBER() OVER (ORDER BY sum(case WHEN su_money_transaction_record.record_type IN (2, 3, 6) THEN su_money_transaction_record.su_money ELSE 0 end) - sum(case WHEN su_money_transaction_record.record_type IN (4, 1, 5) THEN su_money_transaction_record.su_money ELSE 0 end) DESC, e.create_time ASC) AS ranking")
  386 + queryWealthWith = queryWealthWith.Where(`e.status = ?`, 1)
  387 + if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) {
  388 + queryWealthWith = queryWealthWith.Where("e.company_id = ?", companyId)
  389 + }
  390 + if startTime, ok := queryOptions["startTime"]; ok && !startTime.(time.Time).IsZero() {
  391 + queryWealthWith = queryWealthWith.Where(`su_money_transaction_record.create_time > ?`, startTime)
  392 + }
  393 + if endTime, ok := queryOptions["endTime"]; ok && !endTime.(time.Time).IsZero() {
  394 + queryWealthWith = queryWealthWith.Where(`su_money_transaction_record.create_time < ?`, endTime)
  395 + }
  396 + //queryWealthRestoreWith := queryWealthWith.GroupExpr("su_money_transaction_record.employee->>'uid',su_money_transaction_record.employee->>'employeeName', e.create_time")
  397 + queryWealthRestoreWith := queryWealthWith.GroupExpr("su_money_transaction_record.employee->>'uid', e.create_time")
  398 + querySelfWealth := tx.Model()
  399 + querySelfWealth = querySelfWealth.With("t", queryWealthRestoreWith)
  400 + querySelfWealth = querySelfWealth.Table("t")
  401 + querySelfWealth = querySelfWealth.ColumnExpr("t.uid AS uid")
  402 + //querySelfWealth = querySelfWealth.ColumnExpr("t.employee_name AS employee_name")
  403 + querySelfWealth = querySelfWealth.ColumnExpr("t.employee_su_money AS employee_su_money")
  404 + querySelfWealth = querySelfWealth.ColumnExpr("t.ranking AS ranking")
  405 + if uid, ok := queryOptions["uid"]; ok {
  406 + querySelfWealth = querySelfWealth.Where("t.uid::bigint = ?", uid)
  407 + }
  408 + if err := querySelfWealth.Select(&retEmployeeWealth); err != nil {
  409 + return nil, err
  410 + }
  411 + var retCurrentEmployeeWealth interface{}
  412 + if len(retEmployeeWealth) == 0 {
  413 + retCurrentEmployeeWealth = nil
  414 + } else {
  415 + retCurrentEmployeeWealth = retEmployeeWealth[0]
  416 + }
  417 +
  418 + // 贡献值排行榜
  419 + queryContributions := tx.Model(suMoneyTransactionRecordModel)
  420 + queryContributions = queryContributions.Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint")
  421 + queryContributions = queryContributions.ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid")
  422 + //queryContributions = queryContributions.ColumnExpr("su_money_transaction_record.employee->>'employeeName' AS employee_name")
  423 + queryContributions = queryContributions.ColumnExpr("sum(case WHEN su_money_transaction_record.record_type IN (2, 3) THEN su_money_transaction_record.su_money ELSE 0 end) - sum(case WHEN su_money_transaction_record.record_type = 4 THEN su_money_transaction_record.su_money ELSE 0 end) AS employees_contributions")
  424 + queryContributions = queryContributions.ColumnExpr("ROW_NUMBER() OVER (ORDER BY sum(case WHEN su_money_transaction_record.record_type IN (2, 3) THEN su_money_transaction_record.su_money ELSE 0 end) - sum(case WHEN su_money_transaction_record.record_type = 4 THEN su_money_transaction_record.su_money ELSE 0 end) DESC, e.create_time ASC) AS ranking")
  425 + queryContributions = queryContributions.Where(`e.status = ?`, 1)
  426 + //queryContributions = queryContributions.GroupExpr("su_money_transaction_record.employee->>'uid',su_money_transaction_record.employee->>'employeeName'")
  427 + queryContributions = queryContributions.GroupExpr("su_money_transaction_record.employee->>'uid', e.create_time")
  428 + if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) {
  429 + queryContributions = queryContributions.Where("e.company_id = ?", companyId)
  430 + }
  431 + if startTime, ok := queryOptions["startTime"]; ok && !startTime.(time.Time).IsZero() {
  432 + queryContributions = queryContributions.Where(`su_money_transaction_record.create_time > ?`, startTime)
  433 + }
  434 + if endTime, ok := queryOptions["endTime"]; ok && !endTime.(time.Time).IsZero() {
  435 + queryContributions = queryContributions.Where(`su_money_transaction_record.create_time < ?`, endTime)
  436 + }
  437 + if offset, ok := queryOptions["offset"]; ok {
  438 + offset := offset.(int)
  439 + if offset > -1 {
  440 + queryContributions = queryContributions.Offset(offset)
  441 + }
  442 + } else {
  443 + queryContributions = queryContributions.Offset(0)
  444 + }
  445 + if limit, ok := queryOptions["limit"]; ok {
  446 + limit := limit.(int)
  447 + if limit > -1 {
  448 + queryContributions = queryContributions.Limit(limit)
  449 + }
  450 + } else {
  451 + queryContributions = queryContributions.Limit(20)
  452 + }
  453 + if err := queryContributions.Order("ranking ASC").Select(&retContributions); err != nil {
  454 + return nil, err
  455 + }
  456 +
  457 + // 个人贡献值排名
  458 + queryContributionsWith := tx.Model(suMoneyTransactionRecordModel)
  459 + queryContributionsWith = queryContributionsWith.Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint")
  460 + queryContributionsWith = queryContributionsWith.ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid")
  461 + //queryContributionsWith = queryContributionsWith.ColumnExpr("su_money_transaction_record.employee->>'employeeName' AS employee_name")
  462 + queryContributionsWith = queryContributionsWith.ColumnExpr("sum(case WHEN su_money_transaction_record.record_type IN (2, 3) THEN su_money_transaction_record.su_money ELSE 0 end) - sum(case WHEN su_money_transaction_record.record_type = 4 THEN su_money_transaction_record.su_money ELSE 0 end) AS employees_contributions")
  463 + queryContributionsWith = queryContributionsWith.ColumnExpr("ROW_NUMBER() OVER (ORDER BY sum(case WHEN su_money_transaction_record.record_type IN (2, 3) THEN su_money_transaction_record.su_money ELSE 0 end) - sum(case WHEN su_money_transaction_record.record_type = 4 THEN su_money_transaction_record.su_money ELSE 0 end) DESC, e.create_time ASC) AS ranking")
  464 + queryContributionsWith = queryContributionsWith.Where(`e.status = ?`, 1)
  465 + if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) {
  466 + queryContributionsWith = queryContributionsWith.Where("e.company_id = ?", companyId)
  467 + }
  468 + if startTime, ok := queryOptions["startTime"]; ok && !startTime.(time.Time).IsZero() {
  469 + queryContributionsWith = queryContributionsWith.Where(`su_money_transaction_record.create_time > ?`, startTime)
  470 + }
  471 + if endTime, ok := queryOptions["endTime"]; ok && !endTime.(time.Time).IsZero() {
  472 + queryContributionsWith = queryContributionsWith.Where(`su_money_transaction_record.create_time < ?`, endTime)
  473 + }
  474 + //contributionsWith := queryContributionsWith.GroupExpr("su_money_transaction_record.employee->>'uid',su_money_transaction_record.employee->>'employeeName', e.create_time")
  475 + contributionsWith := queryContributionsWith.GroupExpr("su_money_transaction_record.employee->>'uid', e.create_time")
  476 + querySelfContributions := tx.Model()
  477 + querySelfContributions = querySelfContributions.With("t", contributionsWith)
  478 + querySelfContributions = querySelfContributions.Table("t")
  479 + querySelfContributions = querySelfContributions.ColumnExpr("t.uid AS uid")
  480 + //querySelfContributions = querySelfContributions.ColumnExpr("t.employee_name AS employee_name")
  481 + querySelfContributions = querySelfContributions.ColumnExpr("t.employees_contributions AS employees_contributions")
  482 + querySelfContributions = querySelfContributions.ColumnExpr("t.ranking AS ranking")
  483 + if uid, ok := queryOptions["uid"]; ok {
  484 + querySelfContributions = querySelfContributions.Where("t.uid::bigint = ?", uid)
  485 + }
  486 + if err := querySelfContributions.Select(&retEmployeeContributions); err != nil {
  487 + return nil, err
  488 + }
  489 +
  490 + var retCurrentEmployeeContributions interface{}
  491 + if len(retEmployeeContributions) == 0 {
  492 + retCurrentEmployeeContributions = nil
  493 + } else {
  494 + retCurrentEmployeeContributions = retEmployeeContributions[0]
  495 + }
  496 +
  497 + return map[string]interface{}{
  498 + "employeesWealth": retWealth,
  499 + "employeesContributions": retContributions,
  500 + "currentEmployeeContributions": retCurrentEmployeeContributions,
  501 + "currentEmployeeWealth": retCurrentEmployeeWealth,
  502 + }, nil
  503 +}
  504 +
  505 +// 公司员工贡献值分组统计
  506 +func (dao *EmployeeDao) CalculateEmployeesContributions(companyId int, startTime time.Time, endTime time.Time) (map[string]interface{}, error) {
  507 + var ret []struct { // 员工贡献值
  508 + Uid int
  509 + EmployeeName string
  510 + EmployeesContributions float64
  511 + }
  512 + var retDecrease []struct { // 员工减少的贡献值
  513 + Uid int
  514 + EmployeeName string
  515 + EmployeesContributions float64
  516 + }
  517 + tx := dao.transactionContext.PgTx
  518 + suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
  519 + // 增加的贡献值
  520 + if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint").
  521 + ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid").
  522 + ColumnExpr("su_money_transaction_record.employee->>'employeeName' AS employee_name").
  523 + ColumnExpr("sum(su_money_transaction_record.su_money) AS employees_contributions").
  524 + Where(`e.company_id = ?`, companyId).
  525 + Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3})).
  526 + //Where(`e.status = ?`, 1).
  527 + Where(`su_money_transaction_record.create_time > ?`, startTime).
  528 + Where(`su_money_transaction_record.create_time < ?`, endTime).
  529 + Group("su_money_transaction_record.employee").
  530 + Order("employees_contributions DESC").
  531 + Select(&ret); err != nil {
  532 + return nil, err
  533 + }
  534 + // 减少的贡献值
  535 + if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint").
  536 + ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid").
  537 + ColumnExpr("su_money_transaction_record.employee->>'employeeName' AS employee_name").
  538 + ColumnExpr("sum(su_money_transaction_record.su_money) AS employees_contributions").
  539 + Where(`e.company_id = ?`, companyId).
  540 + Where(`su_money_transaction_record.record_type = ?`, 4).
  541 + //Where(`e.status = ?`, 1).
  542 + Where(`su_money_transaction_record.create_time > ?`, startTime).
  543 + Where(`su_money_transaction_record.create_time < ?`, endTime).
  544 + Group("su_money_transaction_record.employee").
  545 + Order("employees_contributions DESC").
  546 + Select(&retDecrease); err != nil {
  547 + return nil, err
  548 + }
  549 + for i := 0; i < len(ret); i++ {
  550 + for j := 0; j < len(retDecrease); j++ {
  551 + if ret[i].Uid == retDecrease[j].Uid {
  552 + ret[i].EmployeesContributions -= retDecrease[j].EmployeesContributions
  553 + }
  554 + }
  555 + }
  556 + return map[string]interface{}{
  557 + "employeesContributions": ret,
  558 + }, nil
  559 +}
  560 +
  561 +// 公司员工财富值分组统计
  562 +func (dao *EmployeeDao) CalculateEmployeesSuMoney(companyId int, startTime time.Time, endTime time.Time) (map[string]interface{}, error) {
  563 + var ret []struct {
  564 + Uid int
  565 + EmployeeName string
  566 + EmployeeSuMoney float64
  567 + }
  568 + tx := dao.transactionContext.PgTx
  569 + suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
  570 + if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint").
  571 + ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid").
  572 + ColumnExpr("su_money_transaction_record.employee->>'employeeName' AS employee_name").
  573 + ColumnExpr("sum(su_money_transaction_record.su_money) AS employee_su_money").
  574 + Where(`e.company_id = ?`, companyId).
  575 + //Where(`e.status = ?`, 1).
  576 + Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3})). // 增加,任务奖励的
  577 + Where(`su_money_transaction_record.create_time > ?`, startTime).
  578 + Where(`su_money_transaction_record.create_time < ?`, endTime).
  579 + Group("su_money_transaction_record.employee").
  580 + Order("employee_su_money DESC").
  581 + Select(&ret); err != nil {
  582 + return nil, err
  583 + }
  584 + return map[string]interface{}{
  585 + "employeesSuMoney": ret,
143 }, nil 586 }, nil
144 } 587 }
145 588
  1 +package dao
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/go-pg/pg"
  6 + pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
  7 +)
  8 +
  9 +type ListIntervalDao struct {
  10 + transactionContext *pgTransaction.TransactionContext
  11 +}
  12 +
  13 +// 榜单时间管理
  14 +func (dao *ListIntervalDao) RankPeriodCheckTime(startTime int64, endTime int64, idNot int, companyId int) bool {
  15 + fmt.Print(startTime, "\n")
  16 + fmt.Print(endTime, "\n")
  17 + var count int
  18 + tx := dao.transactionContext.PgTx
  19 + _, err := tx.QueryOne(
  20 + pg.Scan(&count),
  21 + `SELECT count(*) FROM list_intervals
  22 + WHERE id <> ?
  23 + AND company_id = ?
  24 + AND
  25 + (
  26 + ( extract(epoch from list_interval_start_time) BETWEEN ? AND ?)
  27 + OR
  28 + ( extract(epoch from list_interval_end_time) BETWEEN ? AND ?)
  29 + OR
  30 + (? BETWEEN extract(epoch from list_interval_start_time) AND extract(epoch from list_interval_end_time))
  31 + OR
  32 + (? BETWEEN extract(epoch from list_interval_start_time) AND extract(epoch from list_interval_end_time))
  33 + )
  34 + LIMIT 1 `,
  35 + idNot, companyId, startTime, endTime, startTime, endTime, startTime, endTime)
  36 + if err != nil {
  37 + fmt.Errorf(err.Error())
  38 + return false
  39 + }
  40 + if count > 0 {
  41 + fmt.Print(count, "\n")
  42 + return false
  43 + }
  44 + return true
  45 +}
  46 +
  47 +func NewListIntervalDao(transactionContext *pgTransaction.TransactionContext) (*ListIntervalDao, error) {
  48 + if transactionContext == nil {
  49 + return nil, fmt.Errorf("transactionContext参数不能为nil")
  50 + } else {
  51 + return &ListIntervalDao{
  52 + transactionContext: transactionContext,
  53 + }, nil
  54 + }
  55 +}
@@ -14,6 +14,7 @@ type TaskDao struct { @@ -14,6 +14,7 @@ type TaskDao struct {
14 transactionContext *pgTransaction.TransactionContext 14 transactionContext *pgTransaction.TransactionContext
15 } 15 }
16 16
  17 +// 返回接近截止时间任务
17 func (dao *TaskDao) ListNearThePlannedCompletionTimeTask() ([]*models.Task, error) { 18 func (dao *TaskDao) ListNearThePlannedCompletionTimeTask() ([]*models.Task, error) {
18 tx := dao.transactionContext.PgTx 19 tx := dao.transactionContext.PgTx
19 var taskModels []*models.Task 20 var taskModels []*models.Task
@@ -31,6 +32,19 @@ func (dao *TaskDao) ListNearThePlannedCompletionTimeTask() ([]*models.Task, erro @@ -31,6 +32,19 @@ func (dao *TaskDao) ListNearThePlannedCompletionTimeTask() ([]*models.Task, erro
31 } 32 }
32 } 33 }
33 34
  35 +// 更新已过期的竞标任务的状态,过期时间为竞标结束时间
  36 +func (dao *TaskDao) UpdateExpiredPlannedCompletionTimeBidTask() error {
  37 + currentTime := time.Now()
  38 + currentDay := time.Date(currentTime.Year(), currentTime.Month(), currentTime.Day(), 23, 59, 59, 0, time.Now().Location())
  39 + tx := dao.transactionContext.PgTx
  40 + _, err := tx.Query(
  41 + pg.Scan(),
  42 + "UPDATE tasks SET task_status = ? FROM bid_infos WHERE tasks.id = bid_infos.task_id AND bid_infos.bid_end_time < ? AND tasks.task_type = ? AND tasks.task_status = ?",
  43 + domain.TASK_STATUS_EXPIRED, currentDay, domain.TASK_TYPE_BID, domain.TASK_STATUS_UNCLAIMED)
  44 + return err
  45 +}
  46 +
  47 +// 返回接近竞标截止时间的竞标任务
34 func (dao *TaskDao) ListNearBidEndTimeTask() ([]*models.Task, error) { 48 func (dao *TaskDao) ListNearBidEndTimeTask() ([]*models.Task, error) {
35 tx := dao.transactionContext.PgTx 49 tx := dao.transactionContext.PgTx
36 var taskModels []*models.Task 50 var taskModels []*models.Task
@@ -112,10 +126,12 @@ func (dao *TaskDao) CancelSuccessfulBidder(taskId int64) error { @@ -112,10 +126,12 @@ func (dao *TaskDao) CancelSuccessfulBidder(taskId int64) error {
112 return err 126 return err
113 } 127 }
114 128
  129 +// 系统任务统计
115 func (dao *TaskDao) CalculateSystemTask(companyId int64) (map[string]interface{}, error) { 130 func (dao *TaskDao) CalculateSystemTask(companyId int64) (map[string]interface{}, error) {
116 - var released int64  
117 - var underway int64  
118 - var completed int64 131 + var released int64 // 待领取的任务
  132 + var underway int64 // 进行中的任务
  133 + var completed int64 // 已完成任务
  134 + var reward int64 // 公司悬赏任务
119 tx := dao.transactionContext.PgTx 135 tx := dao.transactionContext.PgTx
120 taskModel := new(models.Task) 136 taskModel := new(models.Task)
121 if count, err := tx.Model(taskModel). 137 if count, err := tx.Model(taskModel).
@@ -137,19 +153,33 @@ func (dao *TaskDao) CalculateSystemTask(companyId int64) (map[string]interface{} @@ -137,19 +153,33 @@ func (dao *TaskDao) CalculateSystemTask(companyId int64) (map[string]interface{}
137 if count, err := tx.Model(taskModel). 153 if count, err := tx.Model(taskModel).
138 Where("task.company_id = ?", companyId). 154 Where("task.company_id = ?", companyId).
139 Where("task.task_status = ? ", domain.TASK_STATUS_COMPLETED). 155 Where("task.task_status = ? ", domain.TASK_STATUS_COMPLETED).
  156 + //Where("task.task_status <> ? ", domain.TASK_STATUS_CLOSED).
  157 + //Where("task.task_status <> ? ", domain.TASK_STATUS_UNRELEASED).
140 Count(); err != nil { 158 Count(); err != nil {
141 return nil, err 159 return nil, err
142 } else { 160 } else {
143 completed = int64(count) 161 completed = int64(count)
144 } 162 }
  163 + if count, err := tx.Model(taskModel).
  164 + Where("task.company_id = ?", companyId).
  165 + Where("task.task_status <> ? ", domain.TASK_STATUS_CLOSED).
  166 + Where("task.task_status <> ?", domain.TASK_STATUS_UNRELEASED).
  167 + Where("task.task_status = ?", domain.TASK_STATUS_UNCLAIMED).
  168 + Where("task.is_reward_take = ?", true).
  169 + Count(); err != nil {
  170 + return nil, err
  171 + } else {
  172 + reward = int64(count)
  173 + }
145 return map[string]interface{}{ 174 return map[string]interface{}{
146 - "released": released + underway + completed, 175 + "released": released,
147 "underway": underway, 176 "underway": underway,
148 "completed": completed, 177 "completed": completed,
  178 + "reward": reward,
149 }, nil 179 }, nil
150 } 180 }
151 181
152 -func (dao *TaskDao) CalculatePersonTask(uid int64) (map[string]interface{}, error) { 182 +func (dao *TaskDao) CalculatePersonTask(uid int64, companyId int) (map[string]interface{}, error) {
153 var underwayAsAssignedPerson int64 183 var underwayAsAssignedPerson int64
154 var unAcceptanceAsAssignedPerson int64 184 var unAcceptanceAsAssignedPerson int64
155 var completedAsAssignedPerson int64 185 var completedAsAssignedPerson int64
@@ -165,11 +195,13 @@ func (dao *TaskDao) CalculatePersonTask(uid int64) (map[string]interface{}, erro @@ -165,11 +195,13 @@ func (dao *TaskDao) CalculatePersonTask(uid int64) (map[string]interface{}, erro
165 var completedAsSponsor int64 195 var completedAsSponsor int64
166 var bidAsParticipator int64 196 var bidAsParticipator int64
167 var completedAsParticipator int64 197 var completedAsParticipator int64
  198 + var expiredAsSponsor int64
168 tx := dao.transactionContext.PgTx 199 tx := dao.transactionContext.PgTx
169 taskModel := new(models.Task) 200 taskModel := new(models.Task)
170 if count, err := tx.Model(taskModel). 201 if count, err := tx.Model(taskModel).
171 Where(`task.assigned_person @> '{"uid":?}'`, uid). 202 Where(`task.assigned_person @> '{"uid":?}'`, uid).
172 Where("task.task_status = ? ", domain.TASK_STATUS_UNDERWAY). 203 Where("task.task_status = ? ", domain.TASK_STATUS_UNDERWAY).
  204 + Where("task.company_id = ?", companyId).
173 Count(); err != nil { 205 Count(); err != nil {
174 return nil, err 206 return nil, err
175 } else { 207 } else {
@@ -178,6 +210,7 @@ func (dao *TaskDao) CalculatePersonTask(uid int64) (map[string]interface{}, erro @@ -178,6 +210,7 @@ func (dao *TaskDao) CalculatePersonTask(uid int64) (map[string]interface{}, erro
178 if count, err := tx.Model(taskModel). 210 if count, err := tx.Model(taskModel).
179 Where(`task.assigned_person @> '{"uid":?}'`, uid). 211 Where(`task.assigned_person @> '{"uid":?}'`, uid).
180 Where("task.task_status = ? ", domain.TASK_STATUS_UNACCEPTANCE). 212 Where("task.task_status = ? ", domain.TASK_STATUS_UNACCEPTANCE).
  213 + Where("task.company_id = ?", companyId).
181 Count(); err != nil { 214 Count(); err != nil {
182 return nil, err 215 return nil, err
183 } else { 216 } else {
@@ -186,6 +219,7 @@ func (dao *TaskDao) CalculatePersonTask(uid int64) (map[string]interface{}, erro @@ -186,6 +219,7 @@ func (dao *TaskDao) CalculatePersonTask(uid int64) (map[string]interface{}, erro
186 if count, err := tx.Model(taskModel). 219 if count, err := tx.Model(taskModel).
187 Where(`task.assigned_person @> '{"uid":?}'`, uid). 220 Where(`task.assigned_person @> '{"uid":?}'`, uid).
188 Where("task.task_status = ? ", domain.TASK_STATUS_COMPLETED). 221 Where("task.task_status = ? ", domain.TASK_STATUS_COMPLETED).
  222 + Where("task.company_id = ?", companyId).
189 Count(); err != nil { 223 Count(); err != nil {
190 return nil, err 224 return nil, err
191 } else { 225 } else {
@@ -194,6 +228,7 @@ func (dao *TaskDao) CalculatePersonTask(uid int64) (map[string]interface{}, erro @@ -194,6 +228,7 @@ func (dao *TaskDao) CalculatePersonTask(uid int64) (map[string]interface{}, erro
194 if count, err := tx.Model(taskModel). 228 if count, err := tx.Model(taskModel).
195 Where("task.receiver_uid = ?", uid). 229 Where("task.receiver_uid = ?", uid).
196 Where("task.task_status = ? ", domain.TASK_STATUS_UNCONFIRMED). 230 Where("task.task_status = ? ", domain.TASK_STATUS_UNCONFIRMED).
  231 + Where("task.company_id = ?", companyId).
197 Count(); err != nil { 232 Count(); err != nil {
198 return nil, err 233 return nil, err
199 } else { 234 } else {
@@ -202,6 +237,7 @@ func (dao *TaskDao) CalculatePersonTask(uid int64) (map[string]interface{}, erro @@ -202,6 +237,7 @@ func (dao *TaskDao) CalculatePersonTask(uid int64) (map[string]interface{}, erro
202 if count, err := tx.Model(taskModel). 237 if count, err := tx.Model(taskModel).
203 Where("task.receiver_uid = ?", uid). 238 Where("task.receiver_uid = ?", uid).
204 Where("task.task_status = ? ", domain.TASK_STATUS_UNDERWAY). 239 Where("task.task_status = ? ", domain.TASK_STATUS_UNDERWAY).
  240 + Where("task.company_id = ?", companyId).
205 Count(); err != nil { 241 Count(); err != nil {
206 return nil, err 242 return nil, err
207 } else { 243 } else {
@@ -210,6 +246,7 @@ func (dao *TaskDao) CalculatePersonTask(uid int64) (map[string]interface{}, erro @@ -210,6 +246,7 @@ func (dao *TaskDao) CalculatePersonTask(uid int64) (map[string]interface{}, erro
210 if count, err := tx.Model(taskModel). 246 if count, err := tx.Model(taskModel).
211 Where("task.receiver_uid = ?", uid). 247 Where("task.receiver_uid = ?", uid).
212 Where("task.task_status = ? ", domain.TASK_STATUS_UNACCEPTANCE). 248 Where("task.task_status = ? ", domain.TASK_STATUS_UNACCEPTANCE).
  249 + Where("task.company_id = ?", companyId).
213 Count(); err != nil { 250 Count(); err != nil {
214 return nil, err 251 return nil, err
215 } else { 252 } else {
@@ -218,6 +255,7 @@ func (dao *TaskDao) CalculatePersonTask(uid int64) (map[string]interface{}, erro @@ -218,6 +255,7 @@ func (dao *TaskDao) CalculatePersonTask(uid int64) (map[string]interface{}, erro
218 if count, err := tx.Model(taskModel). 255 if count, err := tx.Model(taskModel).
219 Where("task.receiver_uid = ?", uid). 256 Where("task.receiver_uid = ?", uid).
220 Where("task.task_status = ? ", domain.TASK_STATUS_COMPLETED). 257 Where("task.task_status = ? ", domain.TASK_STATUS_COMPLETED).
  258 + Where("task.company_id = ?", companyId).
221 Count(); err != nil { 259 Count(); err != nil {
222 return nil, err 260 return nil, err
223 } else { 261 } else {
@@ -226,6 +264,7 @@ func (dao *TaskDao) CalculatePersonTask(uid int64) (map[string]interface{}, erro @@ -226,6 +264,7 @@ func (dao *TaskDao) CalculatePersonTask(uid int64) (map[string]interface{}, erro
226 if count, err := tx.Model(taskModel). 264 if count, err := tx.Model(taskModel).
227 Where(`task.sponsor @> '{"uid":?}'`, uid). 265 Where(`task.sponsor @> '{"uid":?}'`, uid).
228 Where("task.task_status = ? ", domain.TASK_STATUS_UNRELEASED). 266 Where("task.task_status = ? ", domain.TASK_STATUS_UNRELEASED).
  267 + Where("task.company_id = ?", companyId).
229 Count(); err != nil { 268 Count(); err != nil {
230 return nil, err 269 return nil, err
231 } else { 270 } else {
@@ -234,6 +273,7 @@ func (dao *TaskDao) CalculatePersonTask(uid int64) (map[string]interface{}, erro @@ -234,6 +273,7 @@ func (dao *TaskDao) CalculatePersonTask(uid int64) (map[string]interface{}, erro
234 if count, err := tx.Model(taskModel). 273 if count, err := tx.Model(taskModel).
235 Where(`task.sponsor @> '{"uid":?}'`, uid). 274 Where(`task.sponsor @> '{"uid":?}'`, uid).
236 Where("task.task_status = ? ", domain.TASK_STATUS_UNCLAIMED). 275 Where("task.task_status = ? ", domain.TASK_STATUS_UNCLAIMED).
  276 + Where("task.company_id = ?", companyId).
237 Count(); err != nil { 277 Count(); err != nil {
238 return nil, err 278 return nil, err
239 } else { 279 } else {
@@ -242,6 +282,7 @@ func (dao *TaskDao) CalculatePersonTask(uid int64) (map[string]interface{}, erro @@ -242,6 +282,7 @@ func (dao *TaskDao) CalculatePersonTask(uid int64) (map[string]interface{}, erro
242 if count, err := tx.Model(taskModel). 282 if count, err := tx.Model(taskModel).
243 Where(`task.sponsor @> '{"uid":?}'`, uid). 283 Where(`task.sponsor @> '{"uid":?}'`, uid).
244 Where("task.task_status = ? ", domain.TASK_STATUS_UNCONFIRMED). 284 Where("task.task_status = ? ", domain.TASK_STATUS_UNCONFIRMED).
  285 + Where("task.company_id = ?", companyId).
245 Count(); err != nil { 286 Count(); err != nil {
246 return nil, err 287 return nil, err
247 } else { 288 } else {
@@ -250,6 +291,7 @@ func (dao *TaskDao) CalculatePersonTask(uid int64) (map[string]interface{}, erro @@ -250,6 +291,7 @@ func (dao *TaskDao) CalculatePersonTask(uid int64) (map[string]interface{}, erro
250 if count, err := tx.Model(taskModel). 291 if count, err := tx.Model(taskModel).
251 Where(`task.sponsor @> '{"uid":?}'`, uid). 292 Where(`task.sponsor @> '{"uid":?}'`, uid).
252 Where("task.task_status = ? ", domain.TASK_STATUS_UNDERWAY). 293 Where("task.task_status = ? ", domain.TASK_STATUS_UNDERWAY).
  294 + Where("task.company_id = ?", companyId).
253 Count(); err != nil { 295 Count(); err != nil {
254 return nil, err 296 return nil, err
255 } else { 297 } else {
@@ -258,6 +300,7 @@ func (dao *TaskDao) CalculatePersonTask(uid int64) (map[string]interface{}, erro @@ -258,6 +300,7 @@ func (dao *TaskDao) CalculatePersonTask(uid int64) (map[string]interface{}, erro
258 if count, err := tx.Model(taskModel). 300 if count, err := tx.Model(taskModel).
259 Where(`task.sponsor @> '{"uid":?}'`, uid). 301 Where(`task.sponsor @> '{"uid":?}'`, uid).
260 Where("task.task_status = ? ", domain.TASK_STATUS_UNACCEPTANCE). 302 Where("task.task_status = ? ", domain.TASK_STATUS_UNACCEPTANCE).
  303 + Where("task.company_id = ?", companyId).
261 Count(); err != nil { 304 Count(); err != nil {
262 return nil, err 305 return nil, err
263 } else { 306 } else {
@@ -266,6 +309,7 @@ func (dao *TaskDao) CalculatePersonTask(uid int64) (map[string]interface{}, erro @@ -266,6 +309,7 @@ func (dao *TaskDao) CalculatePersonTask(uid int64) (map[string]interface{}, erro
266 if count, err := tx.Model(taskModel). 309 if count, err := tx.Model(taskModel).
267 Where(`task.sponsor @> '{"uid":?}'`, uid). 310 Where(`task.sponsor @> '{"uid":?}'`, uid).
268 Where("task.task_status = ? ", domain.TASK_STATUS_COMPLETED). 311 Where("task.task_status = ? ", domain.TASK_STATUS_COMPLETED).
  312 + Where("task.company_id = ?", companyId).
269 Count(); err != nil { 313 Count(); err != nil {
270 return nil, err 314 return nil, err
271 } else { 315 } else {
@@ -274,6 +318,7 @@ func (dao *TaskDao) CalculatePersonTask(uid int64) (map[string]interface{}, erro @@ -274,6 +318,7 @@ func (dao *TaskDao) CalculatePersonTask(uid int64) (map[string]interface{}, erro
274 if count, err := tx.Model(taskModel).Join("JOIN bidder_infos AS bidder_info ON bidder_info.task_id = task.id"). 318 if count, err := tx.Model(taskModel).Join("JOIN bidder_infos AS bidder_info ON bidder_info.task_id = task.id").
275 Where(`bidder_info.bidder @> '{"uid":?}'`, uid). 319 Where(`bidder_info.bidder @> '{"uid":?}'`, uid).
276 Where("task.task_status = ? ", domain.TASK_STATUS_UNCLAIMED). 320 Where("task.task_status = ? ", domain.TASK_STATUS_UNCLAIMED).
  321 + Where("task.company_id = ?", companyId).
277 Count(); err != nil { 322 Count(); err != nil {
278 return nil, err 323 return nil, err
279 } else { 324 } else {
@@ -282,11 +327,21 @@ func (dao *TaskDao) CalculatePersonTask(uid int64) (map[string]interface{}, erro @@ -282,11 +327,21 @@ func (dao *TaskDao) CalculatePersonTask(uid int64) (map[string]interface{}, erro
282 if count, err := tx.Model(taskModel). 327 if count, err := tx.Model(taskModel).
283 Where(`task.participators @> '[{"uid":?}]'`, uid). 328 Where(`task.participators @> '[{"uid":?}]'`, uid).
284 Where("task.task_status = ? ", domain.TASK_STATUS_COMPLETED). 329 Where("task.task_status = ? ", domain.TASK_STATUS_COMPLETED).
  330 + Where("task.company_id = ?", companyId).
285 Count(); err != nil { 331 Count(); err != nil {
286 return nil, err 332 return nil, err
287 } else { 333 } else {
288 completedAsParticipator = int64(count) 334 completedAsParticipator = int64(count)
289 } 335 }
  336 + if count, err := tx.Model(taskModel).
  337 + Where(`task.sponsor @> '{"uid":?}'`, uid).
  338 + Where("task.task_status = ? ", domain.TASK_STATUS_EXPIRED).
  339 + Where("task.company_id = ?", companyId).
  340 + Count(); err != nil {
  341 + return nil, err
  342 + } else {
  343 + expiredAsSponsor = int64(count)
  344 + }
290 return map[string]interface{}{ 345 return map[string]interface{}{
291 "underwayAsAssignedPerson": underwayAsAssignedPerson, 346 "underwayAsAssignedPerson": underwayAsAssignedPerson,
292 "unAcceptanceAsAssignedPerson": unAcceptanceAsAssignedPerson, 347 "unAcceptanceAsAssignedPerson": unAcceptanceAsAssignedPerson,
@@ -303,6 +358,7 @@ func (dao *TaskDao) CalculatePersonTask(uid int64) (map[string]interface{}, erro @@ -303,6 +358,7 @@ func (dao *TaskDao) CalculatePersonTask(uid int64) (map[string]interface{}, erro
303 "completedAsSponsor": completedAsSponsor, 358 "completedAsSponsor": completedAsSponsor,
304 "bidAsParticipator": bidAsParticipator, 359 "bidAsParticipator": bidAsParticipator,
305 "completedAsParticipator": completedAsParticipator, 360 "completedAsParticipator": completedAsParticipator,
  361 + "expiredAsSponsor": expiredAsSponsor,
306 }, nil 362 }, nil
307 } 363 }
308 364
@@ -2,6 +2,7 @@ package domain_service @@ -2,6 +2,7 @@ package domain_service
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
  5 + "github.com/linmadan/egglib-go/core/application"
5 coreDomain "github.com/linmadan/egglib-go/core/domain" 6 coreDomain "github.com/linmadan/egglib-go/core/domain"
6 pgTransaction "github.com/linmadan/egglib-go/transaction/pg" 7 pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
7 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain" 8 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
@@ -16,10 +17,11 @@ type AcceptanceTaskService struct { @@ -16,10 +17,11 @@ type AcceptanceTaskService struct {
16 transactionContext *pgTransaction.TransactionContext 17 transactionContext *pgTransaction.TransactionContext
17 } 18 }
18 19
19 -func (service *AcceptanceTaskService) Acceptance(taskId int64, operatorUid int64, participators []int64, taskPercentage []*domain.TaskPercentageItem, referenceResourceScore []*domain.ReferenceResourceItem, solveReport string, solvePictureUrls []string, actualCompletionTime time.Time) (*domain.Task, error) { 20 +func (service *AcceptanceTaskService) Acceptance(taskId int64, operatorUid int64, participators []int64, suMoney float64, taskPercentage []*domain.TaskPercentageItem, referenceResourceScore []*domain.ReferenceResourceItem, solveReport string, solvePictureUrls []string, actualCompletionTime time.Time) (*domain.Task, error) {
20 var employeeRepository domain.EmployeeRepository 21 var employeeRepository domain.EmployeeRepository
21 var taskRepository domain.TaskRepository 22 var taskRepository domain.TaskRepository
22 var suMoneyTransactionRecordRepository domain.SuMoneyTransactionRecordRepository 23 var suMoneyTransactionRecordRepository domain.SuMoneyTransactionRecordRepository
  24 +
23 var employeeDao *dao.EmployeeDao 25 var employeeDao *dao.EmployeeDao
24 if repository, err := repository.NewEmployeeRepository(service.transactionContext); err != nil { 26 if repository, err := repository.NewEmployeeRepository(service.transactionContext); err != nil {
25 return nil, err 27 return nil, err
@@ -36,23 +38,37 @@ func (service *AcceptanceTaskService) Acceptance(taskId int64, operatorUid int64 @@ -36,23 +38,37 @@ func (service *AcceptanceTaskService) Acceptance(taskId int64, operatorUid int64
36 } else { 38 } else {
37 suMoneyTransactionRecordRepository = repository 39 suMoneyTransactionRecordRepository = repository
38 } 40 }
  41 +
39 if dao, err := dao.NewEmployeeDao(service.transactionContext); err != nil { 42 if dao, err := dao.NewEmployeeDao(service.transactionContext); err != nil {
40 return nil, err 43 return nil, err
41 } else { 44 } else {
42 employeeDao = dao 45 employeeDao = dao
43 } 46 }
  47 +
44 operator, err := employeeRepository.FindOne(map[string]interface{}{ 48 operator, err := employeeRepository.FindOne(map[string]interface{}{
45 "uid": operatorUid, 49 "uid": operatorUid,
  50 + "status": 1,
46 }) 51 })
47 if err != nil { 52 if err != nil {
48 return nil, err 53 return nil, err
49 } 54 }
50 if operator == nil { 55 if operator == nil {
51 - return nil, fmt.Errorf("无效的操作者") 56 + // 获取无效的发布人员信息
  57 + operatorInvalid, err := employeeRepository.FindOne(map[string]interface{}{
  58 + "uid": operatorUid,
  59 + })
  60 + if err != nil {
  61 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  62 + }
  63 + if operatorInvalid == nil {
  64 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的操作者")
  65 + }
  66 + return nil, fmt.Errorf("无效的操作者:" + operatorInvalid.EmployeeInfo.EmployeeName)
52 } 67 }
53 task, err := taskRepository.FindOne(map[string]interface{}{ 68 task, err := taskRepository.FindOne(map[string]interface{}{
54 "taskId": taskId, 69 "taskId": taskId,
55 }) 70 })
  71 +
56 if err != nil { 72 if err != nil {
57 return nil, err 73 return nil, err
58 } 74 }
@@ -64,17 +80,28 @@ func (service *AcceptanceTaskService) Acceptance(taskId int64, operatorUid int64 @@ -64,17 +80,28 @@ func (service *AcceptanceTaskService) Acceptance(taskId int64, operatorUid int64
64 for _, participatorUid := range participators { 80 for _, participatorUid := range participators {
65 if participator, err := employeeRepository.FindOne(map[string]interface{}{ 81 if participator, err := employeeRepository.FindOne(map[string]interface{}{
66 "uid": participatorUid, 82 "uid": participatorUid,
  83 + "status": 1,
67 }); err != nil { 84 }); err != nil {
68 return nil, err 85 return nil, err
69 } else { 86 } else {
70 if participator == nil { 87 if participator == nil {
71 - return nil, fmt.Errorf("无效的参与人") 88 + // 获取无效的发布人员信息
  89 + participatorInvalid, err := employeeRepository.FindOne(map[string]interface{}{
  90 + "uid": participatorUid,
  91 + })
  92 + if err != nil {
  93 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  94 + }
  95 + if participatorInvalid == nil {
  96 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的参与人")
  97 + }
  98 + return nil, fmt.Errorf("无效的参与人:" + participatorInvalid.EmployeeInfo.EmployeeName)
72 } 99 }
73 participatorMap[participator.EmployeeInfo.Uid] = participator 100 participatorMap[participator.EmployeeInfo.Uid] = participator
74 participatorInfos = append(participatorInfos, participator.EmployeeInfo) 101 participatorInfos = append(participatorInfos, participator.EmployeeInfo)
75 } 102 }
76 } 103 }
77 - if err := task.Acceptance(participatorInfos, taskPercentage, referenceResourceScore, solveReport, solvePictureUrls, actualCompletionTime); err != nil { 104 + if err := task.Acceptance(participatorInfos, suMoney, taskPercentage, referenceResourceScore, solveReport, solvePictureUrls, actualCompletionTime); err != nil {
78 return nil, err 105 return nil, err
79 } 106 }
80 for _, taskPercentageItem := range taskPercentage { 107 for _, taskPercentageItem := range taskPercentage {
@@ -93,12 +120,23 @@ func (service *AcceptanceTaskService) Acceptance(taskId int64, operatorUid int64 @@ -93,12 +120,23 @@ func (service *AcceptanceTaskService) Acceptance(taskId int64, operatorUid int64
93 if taskPercentageItem.IsReceiver { 120 if taskPercentageItem.IsReceiver {
94 receiver, err := employeeRepository.FindOne(map[string]interface{}{ 121 receiver, err := employeeRepository.FindOne(map[string]interface{}{
95 "uid": taskPercentageItem.Contributor.Uid, 122 "uid": taskPercentageItem.Contributor.Uid,
  123 + "status": 1,
96 }) 124 })
97 if err != nil { 125 if err != nil {
98 return nil, err 126 return nil, err
99 } 127 }
100 if receiver == nil { 128 if receiver == nil {
101 - return nil, fmt.Errorf("无效的任务领取者") 129 + // 获取无效的任务领取人员信息
  130 + receiverInvalid, err := employeeRepository.FindOne(map[string]interface{}{
  131 + "uid": operatorUid,
  132 + })
  133 + if err != nil {
  134 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  135 + }
  136 + if receiverInvalid == nil {
  137 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的任务领取者")
  138 + }
  139 + return nil, fmt.Errorf("无效的任务领取者:" + receiverInvalid.EmployeeInfo.EmployeeName)
102 } 140 }
103 employee = receiver 141 employee = receiver
104 } else { 142 } else {
@@ -18,22 +18,26 @@ type OperationSuMoneyService struct { @@ -18,22 +18,26 @@ type OperationSuMoneyService struct {
18 func (service *OperationSuMoneyService) Operation(uid int64, operatorUid int64, suMoney float64, operationType int, recordDescription string) (*domain.SuMoneyTransactionRecord, error) { 18 func (service *OperationSuMoneyService) Operation(uid int64, operatorUid int64, suMoney float64, operationType int, recordDescription string) (*domain.SuMoneyTransactionRecord, error) {
19 var employeeRepository domain.EmployeeRepository 19 var employeeRepository domain.EmployeeRepository
20 var suMoneyTransactionRecordRepository domain.SuMoneyTransactionRecordRepository 20 var suMoneyTransactionRecordRepository domain.SuMoneyTransactionRecordRepository
  21 +
21 var employeeDao *dao.EmployeeDao 22 var employeeDao *dao.EmployeeDao
22 if repository, err := repository.NewEmployeeRepository(service.transactionContext); err != nil { 23 if repository, err := repository.NewEmployeeRepository(service.transactionContext); err != nil {
23 return nil, err 24 return nil, err
24 } else { 25 } else {
25 employeeRepository = repository 26 employeeRepository = repository
26 } 27 }
  28 +
27 if repository, err := repository.NewSuMoneyTransactionRecordRepository(service.transactionContext); err != nil { 29 if repository, err := repository.NewSuMoneyTransactionRecordRepository(service.transactionContext); err != nil {
28 return nil, err 30 return nil, err
29 } else { 31 } else {
30 suMoneyTransactionRecordRepository = repository 32 suMoneyTransactionRecordRepository = repository
31 } 33 }
  34 +
32 if dao, err := dao.NewEmployeeDao(service.transactionContext); err != nil { 35 if dao, err := dao.NewEmployeeDao(service.transactionContext); err != nil {
33 return nil, err 36 return nil, err
34 } else { 37 } else {
35 employeeDao = dao 38 employeeDao = dao
36 } 39 }
  40 +
37 employee, err := employeeRepository.FindOne(map[string]interface{}{ 41 employee, err := employeeRepository.FindOne(map[string]interface{}{
38 "uid": uid, 42 "uid": uid,
39 }) 43 })
@@ -57,14 +61,31 @@ func (service *OperationSuMoneyService) Operation(uid int64, operatorUid int64, @@ -57,14 +61,31 @@ func (service *OperationSuMoneyService) Operation(uid int64, operatorUid int64,
57 } 61 }
58 var recordType int 62 var recordType int
59 var transferSuMoney float64 63 var transferSuMoney float64
60 - if operationType == 1 { 64 + // 操作类型->记录类型对应:1->3: 增加 2->4: 扣除 3->1: 兑换物资 4->5: 兑换现金活动 41->6: 撤回兑换现金素币 5->2: 任务奖励
  65 + if operationType == 1 { // 增加
61 recordType = domain.SU_MONEY_TRANSACTION_RECORD_TYPE_INCREASE 66 recordType = domain.SU_MONEY_TRANSACTION_RECORD_TYPE_INCREASE
62 transferSuMoney = suMoney 67 transferSuMoney = suMoney
63 } 68 }
64 - if operationType == 2 { 69 + if operationType == 2 { // 扣除
65 recordType = domain.SU_MONEY_TRANSACTION_RECORD_TYPE_DEDUCT 70 recordType = domain.SU_MONEY_TRANSACTION_RECORD_TYPE_DEDUCT
66 transferSuMoney = 0 - suMoney 71 transferSuMoney = 0 - suMoney
67 } 72 }
  73 + if operationType == 3 { // 兑换物资
  74 + recordType = domain.SU_MONEY_TRANSACTION_RECORD_TYPE_EXCHANGE
  75 + transferSuMoney = 0 - suMoney
  76 + }
  77 + if operationType == 4 { // 兑换现金
  78 + recordType = domain.SU_MONEY_TRANSACTION_RECORD_TYPE_EXCHANGE_CASH
  79 + transferSuMoney = 0 - suMoney
  80 + }
  81 + if operationType == 41 { // 兑换素币调整退回
  82 + recordType = domain.SU_MONEY_TRANSACTION_RECORD_TYPE_EXCHANGE_CASH_RESTORE
  83 + transferSuMoney = suMoney
  84 + }
  85 + if operationType == 5 { // 任务奖励
  86 + recordType = domain.SU_MONEY_TRANSACTION_RECORD_TYPE_AWARD
  87 + transferSuMoney = suMoney
  88 + }
68 suMoneyTransactionRecord := &domain.SuMoneyTransactionRecord{ 89 suMoneyTransactionRecord := &domain.SuMoneyTransactionRecord{
69 RecordType: recordType, 90 RecordType: recordType,
70 Employee: employee.EmployeeInfo, 91 Employee: employee.EmployeeInfo,
@@ -73,7 +94,7 @@ func (service *OperationSuMoneyService) Operation(uid int64, operatorUid int64, @@ -73,7 +94,7 @@ func (service *OperationSuMoneyService) Operation(uid int64, operatorUid int64,
73 SuMoney: suMoney, 94 SuMoney: suMoney,
74 Operator: operator.EmployeeInfo, 95 Operator: operator.EmployeeInfo,
75 RecordDescription: recordDescription, 96 RecordDescription: recordDescription,
76 - CreateTime: time.Now(), 97 + CreateTime: time.Now().Local(),
77 } 98 }
78 if err := employeeDao.TransferSuMoney(employee.EmployeeInfo.Uid, transferSuMoney); err != nil { 99 if err := employeeDao.TransferSuMoney(employee.EmployeeInfo.Uid, transferSuMoney); err != nil {
79 return nil, err 100 return nil, err
@@ -31,12 +31,23 @@ func (service *ReleaseTaskService) Release(taskId int64, operatorUid int64) (*do @@ -31,12 +31,23 @@ func (service *ReleaseTaskService) Release(taskId int64, operatorUid int64) (*do
31 } 31 }
32 operator, err := employeeRepository.FindOne(map[string]interface{}{ 32 operator, err := employeeRepository.FindOne(map[string]interface{}{
33 "uid": operatorUid, 33 "uid": operatorUid,
  34 + "status": 1,
34 }) 35 })
35 if err != nil { 36 if err != nil {
36 return nil, err 37 return nil, err
37 } 38 }
38 if operator == nil { 39 if operator == nil {
39 - return nil, fmt.Errorf("无效的发布者") 40 + // 获取无效的发布人员信息
  41 + operatorInvalid, err := employeeRepository.FindOne(map[string]interface{}{
  42 + "uid": operatorUid,
  43 + })
  44 + if err != nil {
  45 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  46 + }
  47 + if operatorInvalid == nil {
  48 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的发布者")
  49 + }
  50 + return nil, fmt.Errorf("无效的发布者:" + operatorInvalid.EmployeeInfo.EmployeeName)
40 } 51 }
41 task, err := taskRepository.FindOne(map[string]interface{}{ 52 task, err := taskRepository.FindOne(map[string]interface{}{
42 "taskId": taskId, 53 "taskId": taskId,
@@ -36,6 +36,10 @@ func init() { @@ -36,6 +36,10 @@ func init() {
36 (*models.RejectTaskRecord)(nil), 36 (*models.RejectTaskRecord)(nil),
37 (*models.Notification)(nil), 37 (*models.Notification)(nil),
38 (*models.SentNotification)(nil), 38 (*models.SentNotification)(nil),
  39 + (*models.CashPool)(nil),
  40 + (*models.ExchangeCashActivity)(nil),
  41 + (*models.ExchangeCashPersonList)(nil),
  42 + (*models.ListInterval)(nil),
39 } { 43 } {
40 err := DB.CreateTable(model, &orm.CreateTableOptions{ 44 err := DB.CreateTable(model, &orm.CreateTableOptions{
41 Temp: false, 45 Temp: false,
  1 +package models
  2 +
  3 +import "time"
  4 +
  5 +type CashPool struct {
  6 + TableName string `pg:"cash_pools,alias:cash_pool"`
  7 + Id int64 `pg:",pk"` // 现金池id
  8 + Cash float64 // 投入的现金
  9 + CompanyId int64 // 公司id
  10 + ExchangedCash float64 // 系统已兑换现金
  11 + UnExchangeCash float64 // 系统未兑换现金
  12 + ExchangedSuMoney float64 // 系统已兑换素币
  13 + UnExchangeSuMoney float64 // 系统未兑换素币
  14 + Rate float64 // 平均兑换汇率
  15 + LastRate float64 // 上期活动兑换汇率
  16 + CreateTime time.Time
  17 +}
1 package models 1 package models
2 2
  3 +import "time"
  4 +
3 type Employee struct { 5 type Employee struct {
4 TableName string `pg:"employees,alias:employee"` 6 TableName string `pg:"employees,alias:employee"`
5 // 员工ID 7 // 员工ID
@@ -22,4 +24,6 @@ type Employee struct { @@ -22,4 +24,6 @@ type Employee struct {
22 Status int `pg:",notnull,default:1"` 24 Status int `pg:",notnull,default:1"`
23 // 员工权限集合 25 // 员工权限集合
24 Permissions []int `pg:",array"` 26 Permissions []int `pg:",array"`
  27 + // 创建时间
  28 + CreateTime time.Time
25 } 29 }
  1 +package models
  2 +
  3 +import (
  4 + "time"
  5 +)
  6 +
  7 +type ExchangeCashActivity struct {
  8 + TableName string `pg:"exchange_cash_activities,alias:exchange_cash_activity"`
  9 + Id int64 `pg:",pk"` // 兑换活动ID
  10 + CompanyId int64 // 公司ID
  11 + ActivityName string // 兑换活动名称
  12 + Deadline time.Time // 兑换活动结束时间
  13 + CountDown int64 // 兑换活动结束倒计时
  14 + ExchangedCash float64 // 已兑换现金
  15 + ExchangedSuMoney float64 // 已兑换素币
  16 + ExchangeRate float64 // 兑换汇率
  17 + //LastExchangeRate float64 // 上期活动兑换汇率
  18 + //ExchangeSuMoneyList []*domain.ExchangeCashPersonList `pg:",array"` // 素币兑换人员清单
  19 + //Sponsor *domain.EmployeeInfo // 活动发布人
  20 + CreateTime time.Time // 创建时间
  21 +}
  1 +package models
  2 +
  3 +type ExchangeCashPersonList struct {
  4 + TableName string `pg:"exchange_cash_person_list,alias:exchange_cash_person_lists"`
  5 + Id int64 `pg:",pk"` // 清单id
  6 + ActivityId int64 // 兑换活动id
  7 + Uid int64 // 统一用户UID
  8 + EmployeeName string // 员工姓名
  9 + EmployeeAccount string // 员工账号
  10 + EmployeeAvatarUrl string // 员工头像URL
  11 + IsPrincipal bool `pg:",notnull,default:false"` // 是否公司负责人
  12 + ExchangedSuMoney float64 // 已兑换素币
  13 + ExchangedCash float64 // 已兑换现金
  14 +}
  1 +package models
  2 +
  3 +import "time"
  4 +
  5 +type ListInterval struct {
  6 + TableName string `pg:"list_interval,alias:list_intervals"`
  7 + Id int // 排行榜周期id
  8 + ListIntervalStartTime time.Time
  9 + ListIntervalEndTime time.Time
  10 + CompanyId int
  11 +}
@@ -6,7 +6,7 @@ import ( @@ -6,7 +6,7 @@ import (
6 ) 6 )
7 7
8 type SuMoneyTransactionRecord struct { 8 type SuMoneyTransactionRecord struct {
9 - TableName string `pg:"su_money_transaction_records,alias:su_money_transaction_record"` 9 + TableName string `pg:",discard_unknown_columns,su_money_transaction_records,alias:su_money_transaction_record"`
10 // 素币事务记录ID 10 // 素币事务记录ID
11 Id int64 `pg:",pk"` 11 Id int64 `pg:",pk"`
12 // 记录类型 12 // 记录类型
@@ -19,6 +19,12 @@ type SuMoneyTransactionRecord struct { @@ -19,6 +19,12 @@ type SuMoneyTransactionRecord struct {
19 CurrentSuMoney float64 19 CurrentSuMoney float64
20 // 事务素币值 20 // 事务素币值
21 SuMoney float64 21 SuMoney float64
  22 + //// 事务处理前现金值
  23 + //CashBeforeTransaction float64
  24 + //// 当前现金值
  25 + //CurrentCash float64
  26 + //// 事务现金值
  27 + //Cash float64
22 // 操作人 28 // 操作人
23 Operator *domain.EmployeeInfo 29 Operator *domain.EmployeeInfo
24 // 素币事务记录描述 30 // 素币事务记录描述
@@ -27,8 +27,12 @@ type Task struct { @@ -27,8 +27,12 @@ type Task struct {
27 CustomerValues []int `pg:",array"` 27 CustomerValues []int `pg:",array"`
28 // 任务性质 28 // 任务性质
29 TaskNature int 29 TaskNature int
30 - // 奖励素币 30 + // 实际奖励素币
31 SuMoney float64 31 SuMoney float64
  32 + // 最小奖励素币
  33 + MinSuMoney float64
  34 + // 最大奖励素币
  35 + MaxSuMoney float64
32 // 验收标准 36 // 验收标准
33 AcceptanceStandard string 37 AcceptanceStandard string
34 // 任务描述 38 // 任务描述
  1 +package repository
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/go-pg/pg"
  6 + pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
  7 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
  8 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg/models"
  9 +)
  10 +
  11 +type CashPoolRepository struct {
  12 + transactionContext *pgTransaction.TransactionContext
  13 +}
  14 +
  15 +func (repository *CashPoolRepository) Save(cashPool *domain.CashPool) (*domain.CashPool, error) {
  16 + tx := repository.transactionContext.PgTx
  17 + fmt.Print(cashPool.Identity(), "\n")
  18 + if cashPool.Identity() == nil {
  19 + if _, err := tx.QueryOne(
  20 + pg.Scan(&cashPool.CashPoolId, &cashPool.Cash, &cashPool.CompanyId, &cashPool.ExchangedCash, &cashPool.UnExchangeCash, &cashPool.ExchangedSuMoney, &cashPool.UnExchangeSuMoney, &cashPool.Rate, &cashPool.LastRate, &cashPool.CreateTime),
  21 + "INSERT INTO cash_pools (cash, company_id, exchanged_cash, un_exchange_cash, exchanged_su_money, un_exchange_su_money, rate, last_rate, create_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id, cash, company_id, exchanged_cash, un_exchange_cash, exchanged_su_money, un_exchange_su_money, rate, last_rate, create_time",
  22 + cashPool.Cash, cashPool.CompanyId, cashPool.ExchangedCash, cashPool.UnExchangeCash, cashPool.ExchangedSuMoney, cashPool.UnExchangeSuMoney, cashPool.Rate, cashPool.LastRate, cashPool.CreateTime); err != nil {
  23 + return cashPool, err
  24 + }
  25 + } else {
  26 + if _, err := tx.QueryOne(
  27 + pg.Scan(&cashPool.CashPoolId, &cashPool.Cash, &cashPool.CompanyId, &cashPool.ExchangedCash, &cashPool.UnExchangeCash, &cashPool.ExchangedSuMoney, &cashPool.UnExchangeSuMoney, &cashPool.Rate, &cashPool.LastRate),
  28 + "UPDATE cash_pools SET cash=?, company_id=?, exchanged_cash=?, un_exchange_cash=?, exchanged_su_money=?, un_exchange_su_money=?, rate=?, last_rate=? WHERE id=? RETURNING id, cash, company_id, exchanged_cash, un_exchange_cash, exchanged_su_money, un_exchange_su_money, rate, last_rate",
  29 + cashPool.Cash, cashPool.CompanyId, cashPool.ExchangedCash, cashPool.UnExchangeCash, cashPool.ExchangedSuMoney, cashPool.UnExchangeSuMoney, cashPool.Rate, cashPool.LastRate, cashPool.CashPoolId, cashPool.Identity()); err != nil {
  30 + return cashPool, err
  31 + }
  32 + }
  33 + return cashPool, nil
  34 +}
  35 +
  36 +func (repository *CashPoolRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.CashPool, error) {
  37 + tx := repository.transactionContext.PgTx
  38 + var cashPoolModels []*models.CashPool
  39 + cashPools := make([]*domain.CashPool, 0)
  40 + query := tx.Model(&cashPoolModels)
  41 + // 根据公司id查找现金池
  42 + if companyId, ok := queryOptions["companyId"]; ok {
  43 + query = query.Where("cash_pool.company_id = ?", companyId)
  44 + }
  45 + if offset, ok := queryOptions["offset"]; ok {
  46 + offset := offset.(int)
  47 + if offset > -1 {
  48 + query = query.Offset(offset)
  49 + }
  50 + } else {
  51 + query = query.Offset(0)
  52 + }
  53 + if limit, ok := queryOptions["limit"]; ok {
  54 + limit := limit.(int)
  55 + if limit > -1 {
  56 + query = query.Limit(limit)
  57 + }
  58 + } else {
  59 + query = query.Limit(1)
  60 + }
  61 + if count, err := query.Order("id DESC").SelectAndCount(); err != nil {
  62 + return 0, cashPools, err
  63 + } else {
  64 + for _, cashPoolModel := range cashPoolModels {
  65 + if cashPool, err := repository.transformPgModelToDomainModel(cashPoolModel); err != nil {
  66 + return 0, cashPools, err
  67 + } else {
  68 + cashPools = append(cashPools, cashPool)
  69 + }
  70 + }
  71 + return int64(count), cashPools, nil
  72 + }
  73 +}
  74 +
  75 +func (repository *CashPoolRepository) FindOne(queryOptions map[string]interface{}) (*domain.CashPool, error) {
  76 + tx := repository.transactionContext.PgTx
  77 + cashPoolModel := new(models.CashPool)
  78 + query := tx.Model(cashPoolModel)
  79 + if companyId, ok := queryOptions["companyId"]; ok {
  80 + query = query.Where("cash_pool.company_id = ?", companyId)
  81 + }
  82 + //if cashPoolId, ok := queryOptions["cashPoolId"]; ok {
  83 + // query = query.Where("cash_pool.id = ?", cashPoolId)
  84 + //}
  85 + if err := query.First(); err != nil {
  86 + if err.Error() == "pg: no rows in result set" {
  87 + return nil, fmt.Errorf("没有此资源")
  88 + } else {
  89 + return nil, err
  90 + }
  91 + }
  92 + if cashPoolModel.Id == 0 {
  93 + return nil, nil
  94 + } else {
  95 + return repository.transformPgModelToDomainModel(cashPoolModel)
  96 + }
  97 +}
  98 +
  99 +func (repository *CashPoolRepository) transformPgModelToDomainModel(cashPoolModel *models.CashPool) (*domain.CashPool, error) {
  100 + return &domain.CashPool{
  101 + CashPoolId: cashPoolModel.Id,
  102 + CompanyId: cashPoolModel.CompanyId,
  103 + Cash: cashPoolModel.Cash,
  104 + ExchangedCash: cashPoolModel.ExchangedCash,
  105 + UnExchangeCash: cashPoolModel.UnExchangeCash,
  106 + ExchangedSuMoney: cashPoolModel.ExchangedSuMoney,
  107 + UnExchangeSuMoney: cashPoolModel.UnExchangeSuMoney,
  108 + Rate: cashPoolModel.Rate,
  109 + LastRate: cashPoolModel.LastRate,
  110 + CreateTime: cashPoolModel.CreateTime,
  111 + }, nil
  112 +}
  113 +
  114 +func NewCashPoolRepository(transactionContext *pgTransaction.TransactionContext) (*CashPoolRepository, error) {
  115 + if transactionContext == nil {
  116 + return nil, fmt.Errorf("transactionContext参数不能为null")
  117 + } else {
  118 + return &CashPoolRepository{
  119 + transactionContext: transactionContext,
  120 + }, nil
  121 + }
  122 +}
@@ -30,9 +30,9 @@ func (repository *EmployeeRepository) Save(employee *domain.Employee) (*domain.E @@ -30,9 +30,9 @@ func (repository *EmployeeRepository) Save(employee *domain.Employee) (*domain.E
30 return employee, err 30 return employee, err
31 } 31 }
32 if _, err := tx.QueryOne( 32 if _, err := tx.QueryOne(
33 - pg.Scan(&employee.EmployeeId, &employee.CompanyId, &employee.EmployeeInfo.Uid, &employee.EmployeeInfo.EmployeeName, &employee.EmployeeInfo.EmployeeAccount, &employee.EmployeeInfo.EmployeeAvatarUrl, &employee.EmployeeInfo.IsPrincipal, &employee.SuMoney, &employee.Status, pg.Array(&employee.Permissions)),  
34 - "INSERT INTO employees (id, company_id, uid, employee_name, employee_account, employee_avatar_url, is_principal, su_money, status, permissions) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id, company_id, uid, employee_name, employee_account, employee_avatar_url, is_principal, su_money, status, permissions",  
35 - employeeId, employee.CompanyId, employee.EmployeeInfo.Uid, employee.EmployeeInfo.EmployeeName, employee.EmployeeInfo.EmployeeAccount, employee.EmployeeInfo.EmployeeAvatarUrl, employee.EmployeeInfo.IsPrincipal, employee.SuMoney, employee.Status, pg.Array(employee.Permissions)); err != nil { 33 + pg.Scan(&employee.EmployeeId, &employee.CompanyId, &employee.EmployeeInfo.Uid, &employee.EmployeeInfo.EmployeeName, &employee.EmployeeInfo.EmployeeAccount, &employee.EmployeeInfo.EmployeeAvatarUrl, &employee.EmployeeInfo.IsPrincipal, &employee.SuMoney, &employee.Status, pg.Array(&employee.Permissions), &employee.CreateTime),
  34 + "INSERT INTO employees (id, company_id, uid, employee_name, employee_account, employee_avatar_url, is_principal, su_money, status, permissions, create_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id, company_id, uid, employee_name, employee_account, employee_avatar_url, is_principal, su_money, status, permissions, create_time",
  35 + employeeId, employee.CompanyId, employee.EmployeeInfo.Uid, employee.EmployeeInfo.EmployeeName, employee.EmployeeInfo.EmployeeAccount, employee.EmployeeInfo.EmployeeAvatarUrl, employee.EmployeeInfo.IsPrincipal, employee.SuMoney, employee.Status, pg.Array(employee.Permissions), employee.CreateTime); err != nil {
36 return employee, err 36 return employee, err
37 } 37 }
38 } else { 38 } else {
@@ -63,9 +63,18 @@ func (repository *EmployeeRepository) FindOne(queryOptions map[string]interface{ @@ -63,9 +63,18 @@ func (repository *EmployeeRepository) FindOne(queryOptions map[string]interface{
63 if uid, ok := queryOptions["uid"]; ok { 63 if uid, ok := queryOptions["uid"]; ok {
64 query = query.Where("employee.uid = ?", uid) 64 query = query.Where("employee.uid = ?", uid)
65 } 65 }
  66 + if account, ok := queryOptions["account"]; ok {
  67 + query = query.Where("employee.employee_account = ?", account)
  68 + }
  69 + if companyId, ok := queryOptions["companyId"]; ok {
  70 + query = query.Where("employee.company_id = ?", companyId)
  71 + }
  72 + if status, ok := queryOptions["status"]; ok && status.(int) != 0 {
  73 + query = query.Where(`employee.status = ?`, status) // 筛除已离职员工
  74 + }
66 if err := query.First(); err != nil { 75 if err := query.First(); err != nil {
67 if err.Error() == "pg: no rows in result set" { 76 if err.Error() == "pg: no rows in result set" {
68 - return nil, fmt.Errorf("没有此员工") 77 + return nil, fmt.Errorf("无效的员工")
69 } else { 78 } else {
70 return nil, err 79 return nil, err
71 } 80 }
@@ -77,6 +86,39 @@ func (repository *EmployeeRepository) FindOne(queryOptions map[string]interface{ @@ -77,6 +86,39 @@ func (repository *EmployeeRepository) FindOne(queryOptions map[string]interface{
77 } 86 }
78 } 87 }
79 88
  89 +func (repository *EmployeeRepository) FindByIds(queryOptions map[string]interface{}) (int64, []*domain.Employee, error) {
  90 + tx := repository.transactionContext.PgTx
  91 + var employeeModels []*models.Employee
  92 + employees := make([]*domain.Employee, 0)
  93 + query := tx.Model(&employeeModels)
  94 + if ids, ok := queryOptions["ids"]; ok && len(ids.([]int)) != 0 {
  95 + query = query.Where("employee.uid IN (?)", pg.In(ids.([]int)) )
  96 + }
  97 + if where, ok := queryOptions["where"]; ok && where.(map[string]interface{}) != nil {
  98 + if personNameMatch, ok := where.(map[string]interface{})["personNameMatch"]; ok && (personNameMatch != "") {
  99 + query = query.Where("employee.employee_name LIKE ?", fmt.Sprintf("%%%s%%", personNameMatch.(string)))
  100 + }
  101 + if companyId, ok := where.(map[string]interface{})["companyId"]; ok && companyId.(float64) != 0 {
  102 + query = query.Where("employee.company_id = ?", companyId)
  103 + }
  104 + }
  105 + if status, ok := queryOptions["status"]; ok && status.(int) != 0 {
  106 + query = query.Where(`employee.status = ?`, status)
  107 + }
  108 + if count, err := query.Order("uid DESC").SelectAndCount(); err != nil {
  109 + return 0, employees, err
  110 + } else {
  111 + for _, employeeModel := range employeeModels {
  112 + if employee, err := repository.transformPgModelToDomainModel(employeeModel); err != nil {
  113 + return 0, employees, err
  114 + } else {
  115 + employees = append(employees, employee)
  116 + }
  117 + }
  118 + return int64(count), employees, nil
  119 + }
  120 +}
  121 +
80 func (repository *EmployeeRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.Employee, error) { 122 func (repository *EmployeeRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.Employee, error) {
81 tx := repository.transactionContext.PgTx 123 tx := repository.transactionContext.PgTx
82 var employeeModels []*models.Employee 124 var employeeModels []*models.Employee
@@ -88,7 +130,18 @@ func (repository *EmployeeRepository) Find(queryOptions map[string]interface{}) @@ -88,7 +130,18 @@ func (repository *EmployeeRepository) Find(queryOptions map[string]interface{})
88 if employeeNameMatch, ok := queryOptions["employeeNameMatch"]; ok && (employeeNameMatch != "") { 130 if employeeNameMatch, ok := queryOptions["employeeNameMatch"]; ok && (employeeNameMatch != "") {
89 query = query.Where("employee.employee_name LIKE ?", fmt.Sprintf("%%%s%%", employeeNameMatch.(string))) 131 query = query.Where("employee.employee_name LIKE ?", fmt.Sprintf("%%%s%%", employeeNameMatch.(string)))
90 } 132 }
91 - if status, ok := queryOptions["status"]; ok && (status != 0) { 133 + if ids, ok := queryOptions["ids"]; ok && len(ids.([]int)) != 0 {
  134 + query = query.Where("employee.uid IN (?)", pg.In(ids.([]int)) )
  135 + }
  136 + if where, ok := queryOptions["where"]; ok && where.(map[string]interface{}) != nil {
  137 + if personNameMatch, ok := where.(map[string]interface{})["personNameMatch"]; ok && (personNameMatch != "") {
  138 + query = query.Where("employee.employee_name LIKE ?", fmt.Sprintf("%%%s%%", personNameMatch.(string)))
  139 + }
  140 + if companyId, ok := where.(map[string]interface{})["companyId"]; ok && companyId.(float64) != 0 {
  141 + query = query.Where("employee.company_id = ?", companyId)
  142 + }
  143 + }
  144 + if status, ok := queryOptions["status"]; ok && status.(int) != 0 {
92 query = query.Where(`employee.status = ?`, status) 145 query = query.Where(`employee.status = ?`, status)
93 } 146 }
94 if isPrincipal, ok := queryOptions["isPrincipal"]; ok && isPrincipal.(bool) != false { 147 if isPrincipal, ok := queryOptions["isPrincipal"]; ok && isPrincipal.(bool) != false {
@@ -124,6 +177,48 @@ func (repository *EmployeeRepository) Find(queryOptions map[string]interface{}) @@ -124,6 +177,48 @@ func (repository *EmployeeRepository) Find(queryOptions map[string]interface{})
124 } 177 }
125 } 178 }
126 179
  180 +func (repository *EmployeeRepository) FindAll(queryOptions map[string]interface{}) (int64, []*domain.Employee, error) {
  181 + tx := repository.transactionContext.PgTx
  182 + var employeeModels []*models.Employee
  183 + employees := make([]*domain.Employee, 0)
  184 + query := tx.Model(&employeeModels)
  185 + if companyId, ok := queryOptions["companyId"]; ok {
  186 + query = query.Where("employee.company_id = ?", companyId)
  187 + }
  188 + if employeeNameMatch, ok := queryOptions["employeeNameMatch"]; ok && (employeeNameMatch != "") {
  189 + query = query.Where("employee.employee_name LIKE ?", fmt.Sprintf("%%%s%%", employeeNameMatch.(string)))
  190 + }
  191 + if ids, ok := queryOptions["ids"]; ok && len(ids.([]int)) != 0 {
  192 + query = query.Where("employee.uid IN (?)", pg.In(ids.([]int)) )
  193 + }
  194 + if where, ok := queryOptions["where"]; ok && where.(map[string]interface{}) != nil {
  195 + if personNameMatch, ok := where.(map[string]interface{})["personNameMatch"]; ok && (personNameMatch != "") {
  196 + query = query.Where("employee.employee_name LIKE ?", fmt.Sprintf("%%%s%%", personNameMatch.(string)))
  197 + }
  198 + if companyId, ok := where.(map[string]interface{})["companyId"]; ok && companyId.(float64) != 0 {
  199 + query = query.Where("employee.company_id = ?", companyId)
  200 + }
  201 + }
  202 + if status, ok := queryOptions["status"]; ok && status.(int) != 0 {
  203 + query = query.Where(`employee.status = ?`, status)
  204 + }
  205 + if isPrincipal, ok := queryOptions["isPrincipal"]; ok && isPrincipal.(bool) != false {
  206 + query = query.Where("employee.is_principal = ? ", isPrincipal)
  207 + }
  208 + if count, err := query.Order("uid DESC").SelectAndCount(); err != nil {
  209 + return 0, employees, err
  210 + } else {
  211 + for _, employeeModel := range employeeModels {
  212 + if employee, err := repository.transformPgModelToDomainModel(employeeModel); err != nil {
  213 + return 0, employees, err
  214 + } else {
  215 + employees = append(employees, employee)
  216 + }
  217 + }
  218 + return int64(count), employees, nil
  219 + }
  220 +}
  221 +
127 func (repository *EmployeeRepository) transformPgModelToDomainModel(employeeModel *models.Employee) (*domain.Employee, error) { 222 func (repository *EmployeeRepository) transformPgModelToDomainModel(employeeModel *models.Employee) (*domain.Employee, error) {
128 return &domain.Employee{ 223 return &domain.Employee{
129 EmployeeId: employeeModel.Id, 224 EmployeeId: employeeModel.Id,
  1 +package repository
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/go-pg/pg"
  6 + pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
  7 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
  8 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg/models"
  9 + "time"
  10 +)
  11 +
  12 +type ExchangeCashActivityRepository struct {
  13 + transactionContext *pgTransaction.TransactionContext
  14 +}
  15 +
  16 +func (repository *ExchangeCashActivityRepository) Save(exchangeCashActivity *domain.ExchangeCashActivity) (*domain.ExchangeCashActivity, error) {
  17 + tx := repository.transactionContext.PgTx
  18 + if exchangeCashActivity.Identity() == nil {
  19 + if _, err := tx.QueryOne(
  20 + pg.Scan(&exchangeCashActivity.ActivityId, &exchangeCashActivity.CompanyId, &exchangeCashActivity.ExchangeActivityName, &exchangeCashActivity.Deadline, &exchangeCashActivity.CountDown, &exchangeCashActivity.ExchangedCash, &exchangeCashActivity.ExchangedSuMoney, &exchangeCashActivity.Rate, &exchangeCashActivity.CreateTime),
  21 + "INSERT INTO exchange_cash_activities ( company_id, activity_name, deadline, count_down, exchanged_cash, exchanged_su_money, exchange_rate, create_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?) RETURNING id, company_id, activity_name, deadline, count_down, exchanged_cash, exchanged_su_money, exchange_rate, create_time" ,
  22 + exchangeCashActivity.CompanyId, exchangeCashActivity.ExchangeActivityName, exchangeCashActivity.Deadline, exchangeCashActivity.CountDown, exchangeCashActivity.ExchangedCash, exchangeCashActivity.ExchangedSuMoney, exchangeCashActivity.Rate, &exchangeCashActivity.CreateTime); err != nil {
  23 + return exchangeCashActivity, err
  24 + }
  25 + } else {
  26 + if _, err := tx.QueryOne(
  27 + pg.Scan(&exchangeCashActivity.ActivityId, &exchangeCashActivity.CompanyId, &exchangeCashActivity.ExchangeActivityName, &exchangeCashActivity.Deadline, &exchangeCashActivity.CountDown, &exchangeCashActivity.ExchangedCash, &exchangeCashActivity.ExchangedSuMoney, &exchangeCashActivity.Rate),
  28 + "UPDATE exchange_cash_activities SET activity_name=?, deadline=?, count_down=?, exchanged_cash=?, exchanged_su_money=?, exchange_rate=? WHERE id=? RETURNING id, company_id, activity_name, deadline, count_down, exchanged_cash, exchanged_su_money, exchange_rate",
  29 + exchangeCashActivity.ExchangeActivityName, exchangeCashActivity.Deadline, exchangeCashActivity.CountDown, exchangeCashActivity.ExchangedCash, exchangeCashActivity.ExchangedSuMoney, exchangeCashActivity.Rate, exchangeCashActivity.ActivityId); err != nil {
  30 + return exchangeCashActivity, err
  31 + }
  32 + }
  33 + return exchangeCashActivity, nil
  34 +}
  35 +
  36 +func (repository *ExchangeCashActivityRepository) FindOne(queryOptions map[string]interface{}) (*domain.ExchangeCashActivity, error) {
  37 + tx := repository.transactionContext.PgTx
  38 + exchangeCashActivityModel := new(models.ExchangeCashActivity)
  39 + query := tx.Model(exchangeCashActivityModel)
  40 + if exchangeCashActivityId, ok := queryOptions["activityId"]; ok {
  41 + query = query.Where("exchange_cash_activity.id = ?", exchangeCashActivityId)
  42 + }
  43 + if err := query.First(); err != nil {
  44 + if err.Error() == "pg: no rows in result set" {
  45 + return nil, fmt.Errorf("没有此资源")
  46 + } else {
  47 + return nil, err
  48 + }
  49 + }
  50 + if exchangeCashActivityModel.Id == 0 {
  51 + return nil, nil
  52 + } else {
  53 + return repository.transformPgModelToDomainModel(exchangeCashActivityModel)
  54 + }
  55 +}
  56 +
  57 +func (repository *ExchangeCashActivityRepository) FindAll(queryOptions map[string]interface{}) (int64, []*domain.ExchangeCashActivity, error) {
  58 + tx := repository.transactionContext.PgTx
  59 + var exchangeCashActivityModels []*models.ExchangeCashActivity
  60 + exchangeCashActivities := make([]*domain.ExchangeCashActivity, 0)
  61 + query := tx.Model(&exchangeCashActivityModels)
  62 + if companyId, ok := queryOptions["companyId"]; ok {
  63 + query = query.Where(`exchange_cash_activity.company_id = ?`, companyId)
  64 + }
  65 + if count, err := query.Order("id DESC").SelectAndCount(); err != nil {
  66 + return 0, exchangeCashActivities, err
  67 + } else {
  68 + for _, exchangeCashActivityModel := range exchangeCashActivityModels {
  69 + if taskNature, err := repository.transformPgModelToDomainModel(exchangeCashActivityModel); err != nil {
  70 + return 0, exchangeCashActivities, err
  71 + } else {
  72 + exchangeCashActivities = append(exchangeCashActivities, taskNature)
  73 + }
  74 + }
  75 + return int64(count), exchangeCashActivities, nil
  76 + }
  77 +}
  78 +
  79 +func (repository *ExchangeCashActivityRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.ExchangeCashActivity, error) {
  80 + tx := repository.transactionContext.PgTx
  81 + var exchangeCashActivityModels []*models.ExchangeCashActivity
  82 + exchangeCashActivities := make([]*domain.ExchangeCashActivity, 0)
  83 + query := tx.Model(&exchangeCashActivityModels)
  84 + //fmt.Printf("查询:%+v\n", queryOptions)
  85 + if companyId, ok := queryOptions["companyId"]; ok {
  86 + query = query.Where(`exchange_cash_activity.company_id = ?`, companyId)
  87 + }
  88 + if activityNameMatch, ok := queryOptions["activityNameMatch"]; ok && (activityNameMatch != "") {
  89 + query = query.Where(`exchange_cash_activity.activity_name LIKE ?`, fmt.Sprintf("%%%s%%", activityNameMatch.(string)))
  90 + }
  91 + if countDown, ok := queryOptions["countDown"]; ok {
  92 + query = query.Where(`exchange_cash_activity.count_down = ?`, countDown)
  93 + }
  94 + if isEnd, ok := queryOptions["isEnd"]; ok {
  95 + if isEnd.(bool) {
  96 + query = query.Where(`exchange_cash_activity.count_down = ?`, 0)
  97 + } else {
  98 + query = query.Where(`exchange_cash_activity.count_down > ?`, 0)
  99 + }
  100 + }
  101 + if nearest, ok := queryOptions["nearest"]; ok && nearest.(bool) != false {
  102 + t := time.Now().Local()
  103 + query = query.Where(`exchange_cash_activity.deadline <= ?`, t)
  104 + query = query.Where(`exchange_cash_activity.count_down = ?`, 0)
  105 + }
  106 + if deadline, ok := queryOptions["deadline"]; ok && deadline != "" {
  107 + t, _ := time.ParseInLocation("2006-01-02", deadline.(string), time.Local)
  108 + newDeadlineStart := time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, time.Local)
  109 + newDeadlineEnd := time.Date(t.Year(), t.Month(), t.Day(), 23, 59, 59, 0, time.Local)
  110 + query = query.Where(`exchange_cash_activity.deadline >= ?`, newDeadlineStart)
  111 + query = query.Where(`exchange_cash_activity.deadline <= ?`, newDeadlineEnd)
  112 + }
  113 + if offset, ok := queryOptions["offset"]; ok {
  114 + offset := offset.(int)
  115 + if offset > -1 {
  116 + query = query.Offset(offset)
  117 + }
  118 + } else {
  119 + query = query.Offset(0)
  120 + }
  121 + if limit, ok := queryOptions["limit"]; ok {
  122 + limit := limit.(int)
  123 + if limit > -1 {
  124 + query = query.Limit(limit)
  125 + }
  126 + } else {
  127 + query = query.Limit(20)
  128 + }
  129 + if order, ok := queryOptions["order"]; ok && order.(string) != "" {
  130 + if count, err := query.OrderExpr("deadline DESC").SelectAndCount(); err != nil {
  131 + return 0, exchangeCashActivities, err
  132 + } else {
  133 + for _, exchangeCashActivityModel := range exchangeCashActivityModels {
  134 + if taskNature, err := repository.transformPgModelToDomainModel(exchangeCashActivityModel); err != nil {
  135 + return 0, exchangeCashActivities, err
  136 + } else {
  137 + exchangeCashActivities = append(exchangeCashActivities, taskNature)
  138 + }
  139 + }
  140 + return int64(count), exchangeCashActivities, nil
  141 + }
  142 + }
  143 + if count, err := query.OrderExpr("deadline ASC").SelectAndCount(); err != nil {
  144 + return 0, exchangeCashActivities, err
  145 + } else {
  146 + for _, exchangeCashActivityModel := range exchangeCashActivityModels {
  147 + if taskNature, err := repository.transformPgModelToDomainModel(exchangeCashActivityModel); err != nil {
  148 + return 0, exchangeCashActivities, err
  149 + } else {
  150 + exchangeCashActivities = append(exchangeCashActivities, taskNature)
  151 + }
  152 + }
  153 + return int64(count), exchangeCashActivities, nil
  154 + }
  155 +}
  156 +
  157 +func (repository *ExchangeCashActivityRepository) Remove(exchangeCashActivity *domain.ExchangeCashActivity) (*domain.ExchangeCashActivity, error) {
  158 + tx := repository.transactionContext.PgTx
  159 + exchangeCashActivityModel := new(models.ExchangeCashActivity)
  160 + exchangeCashActivityModel.Id = exchangeCashActivity.ActivityId
  161 + if _, err := tx.Model(exchangeCashActivityModel).WherePK().Delete(); err != nil {
  162 + return exchangeCashActivity, err
  163 + }
  164 + return exchangeCashActivity, nil
  165 +}
  166 +
  167 +func (repository *ExchangeCashActivityRepository) transformPgModelToDomainModel(exchangeCashActivity *models.ExchangeCashActivity) (*domain.ExchangeCashActivity, error) {
  168 + return &domain.ExchangeCashActivity{
  169 + ActivityId: exchangeCashActivity.Id,
  170 + ExchangeActivityName: exchangeCashActivity.ActivityName,
  171 + CompanyId: exchangeCashActivity.CompanyId,
  172 + ExchangedCash: exchangeCashActivity.ExchangedCash,
  173 + ExchangedSuMoney: exchangeCashActivity.ExchangedSuMoney,
  174 + CreateTime: exchangeCashActivity.CreateTime,
  175 + Deadline: exchangeCashActivity.Deadline,
  176 + CountDown: exchangeCashActivity.CountDown,
  177 + Rate: exchangeCashActivity.ExchangeRate,
  178 + }, nil
  179 +}
  180 +func NewExchangeCashActivityRepository(transactionContext *pgTransaction.TransactionContext) (*ExchangeCashActivityRepository, error) {
  181 + if transactionContext == nil {
  182 + return nil, fmt.Errorf("transactionContext参数不能为nil")
  183 + } else {
  184 + return &ExchangeCashActivityRepository{
  185 + transactionContext: transactionContext,
  186 + }, nil
  187 + }
  188 +}
  1 +package repository
  2 +
  3 +import (
  4 + "fmt"
  5 + "strconv"
  6 +
  7 + "github.com/go-pg/pg"
  8 + pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
  9 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
  10 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg/models"
  11 +)
  12 +
  13 +type ExchangeCashPersonListRepository struct {
  14 + transactionContext *pgTransaction.TransactionContext
  15 +}
  16 +
  17 +func (repository *ExchangeCashPersonListRepository) Save(exchangeCashList *domain.ExchangeCashPersonList) (*domain.ExchangeCashPersonList, error) {
  18 + tx := repository.transactionContext.PgTx
  19 + if exchangeCashList.Identity() == nil {
  20 + if _, err := tx.QueryOne(
  21 + pg.Scan(&exchangeCashList.ListId, &exchangeCashList.ExchangeCashActivityId, &exchangeCashList.EmployeeInfo.Uid, &exchangeCashList.EmployeeInfo.EmployeeName, &exchangeCashList.EmployeeInfo.EmployeeAccount, &exchangeCashList.ExchangedSuMoney, &exchangeCashList.ExchangedCash),
  22 + "INSERT INTO exchange_cash_person_lists (activity_id, uid, employee_name, employee_account, exchanged_su_money, exchanged_cash) VALUES (?, ?, ?, ?, ?, ?) RETURNING id, activity_id, uid, employee_name, employee_account, exchanged_su_money, exchanged_cash",
  23 + exchangeCashList.ExchangeCashActivityId, exchangeCashList.EmployeeInfo.Uid, exchangeCashList.EmployeeInfo.EmployeeName, exchangeCashList.EmployeeInfo.EmployeeAccount, exchangeCashList.ExchangedSuMoney, exchangeCashList.ExchangedCash); err != nil {
  24 + return exchangeCashList, err
  25 + }
  26 + } else {
  27 + if _, err := tx.QueryOne(
  28 + pg.Scan(&exchangeCashList.ListId, &exchangeCashList.ExchangeCashActivityId, &exchangeCashList.EmployeeInfo.Uid, &exchangeCashList.EmployeeInfo.EmployeeName, &exchangeCashList.EmployeeInfo.EmployeeAccount, &exchangeCashList.ExchangedSuMoney, &exchangeCashList.ExchangedCash),
  29 + "UPDATE exchange_cash_person_lists SET exchanged_su_money=?, exchanged_cash=? WHERE id=? RETURNING id, activity_id, uid, employee_name, employee_account, exchanged_su_money, exchanged_cash",
  30 + exchangeCashList.ExchangedSuMoney, exchangeCashList.ExchangedCash, exchangeCashList.ListId); err != nil {
  31 + return exchangeCashList, err
  32 + }
  33 + }
  34 + return exchangeCashList, nil
  35 +}
  36 +
  37 +func (repository *ExchangeCashPersonListRepository) FindOne(queryOptions map[string]interface{}) (*domain.ExchangeCashPersonList, error) {
  38 + tx := repository.transactionContext.PgTx
  39 + exchangeCashListModel := new(models.ExchangeCashPersonList)
  40 + query := tx.Model(exchangeCashListModel)
  41 + if uid, ok := queryOptions["uid"]; ok {
  42 + query = query.Where("exchange_cash_person_list.uid = ?", uid)
  43 + }
  44 + if exchangeCashListId, ok := queryOptions["listId"]; ok {
  45 + query = query.Where("exchange_cash_person_list.id = ?", exchangeCashListId)
  46 + }
  47 + if activityId, ok := queryOptions["activityId"]; ok {
  48 + query = query.Where("exchange_cash_person_list.activity_id = ?", activityId)
  49 + }
  50 + if employeeAccount, ok := queryOptions["employeeAccount"]; ok {
  51 + query = query.Where("exchange_cash_person_list.employee_account = ?", employeeAccount)
  52 + }
  53 + if err := query.First(); err != nil {
  54 + if err.Error() == "pg: no rows in result set" {
  55 + return nil, fmt.Errorf("没有此资源")
  56 + } else {
  57 + return nil, err
  58 + }
  59 + }
  60 + if exchangeCashListModel.Id == 0 {
  61 + return nil, nil
  62 + } else {
  63 + return repository.transformPgModelToDomainModel(exchangeCashListModel)
  64 + }
  65 +}
  66 +
  67 +func (repository *ExchangeCashPersonListRepository) FindById(queryOptions map[string]interface{}) (int64, []*domain.ExchangeCashPersonList, error) {
  68 + tx := repository.transactionContext.PgTx
  69 + var exchangeCashListModels []*models.ExchangeCashPersonList
  70 + exchangeCashPeople := make([]*domain.ExchangeCashPersonList, 0)
  71 + query := tx.Model(&exchangeCashListModels)
  72 + if ids, ok := queryOptions["ids"]; ok && len(ids.([]int)) != 0 {
  73 + query = query.Where("exchange_cash_person_list.id IN (?)", pg.In(ids.([]int)) )
  74 + }
  75 + if where, ok := queryOptions["where"]; ok && where.(map[string]interface{}) != nil {
  76 + if personNameMatch, ok := where.(map[string]interface{})["personNameMatch"]; ok && (personNameMatch != "") {
  77 + query = query.Where(`exchange_cash_person_list.employee_name LIKE ?`, fmt.Sprintf("%%%s%%", personNameMatch.(string)))
  78 + }
  79 + if activityId, ok := where.(map[string]interface{})["activityId"]; ok && activityId != "" {
  80 + float, _ := strconv.ParseFloat(activityId.(string),64)
  81 + query = query.Where("exchange_cash_person_list.activity_id = ?", float)
  82 + }
  83 + }
  84 + if count, err := query.Order("id DESC").SelectAndCount(); err != nil {
  85 + return 0, exchangeCashPeople, err
  86 + } else {
  87 + for _, exchangeCashListModel := range exchangeCashListModels {
  88 + if taskNature, err := repository.transformPgModelToDomainModel(exchangeCashListModel); err != nil {
  89 + return 0, exchangeCashPeople, err
  90 + } else {
  91 + exchangeCashPeople = append(exchangeCashPeople, taskNature)
  92 + }
  93 + }
  94 + return int64(count), exchangeCashPeople, nil
  95 + }
  96 +}
  97 +
  98 +// 获取平台所有兑换活动清单(兑换现金活动总清单)
  99 +func (repository *ExchangeCashPersonListRepository) FindAll(queryOptions map[string]interface{}) (int64, []*domain.ExchangeCashPersonList, error) {
  100 + tx := repository.transactionContext.PgTx
  101 + var exchangeCashListModels []*models.ExchangeCashPersonList
  102 + exchangeCashPeople := make([]*domain.ExchangeCashPersonList, 0)
  103 + query := tx.Model(&exchangeCashListModels)
  104 + if exchangeCashActivityIds, ok := queryOptions["exchangeCashActivityIds"]; ok && len(exchangeCashActivityIds.([]int64)) != 0 {
  105 + query = query.Where("exchange_cash_person_list.activity_id IN (?)", pg.In(exchangeCashActivityIds.([]int64)) )
  106 + }
  107 + if offset, ok := queryOptions["offset"]; ok {
  108 + offset := offset.(int)
  109 + if offset > -1 {
  110 + query = query.Offset(offset)
  111 + }
  112 + } else {
  113 + query = query.Offset(0)
  114 + }
  115 + if limit, ok := queryOptions["limit"]; ok {
  116 + limit := limit.(int)
  117 + if limit > -1 {
  118 + query = query.Limit(limit)
  119 + }
  120 + } else {
  121 + query = query.Limit(20)
  122 + }
  123 + if count, err := query.Order("id DESC").SelectAndCount(); err != nil {
  124 + return 0, exchangeCashPeople, err
  125 + } else {
  126 + for _, exchangeCashListModel := range exchangeCashListModels {
  127 + if taskNature, err := repository.transformPgModelToDomainModel(exchangeCashListModel); err != nil {
  128 + return 0, exchangeCashPeople, err
  129 + } else {
  130 + exchangeCashPeople = append(exchangeCashPeople, taskNature)
  131 + }
  132 + }
  133 + return int64(count), exchangeCashPeople, nil
  134 + }
  135 +}
  136 +
  137 +func (repository *ExchangeCashPersonListRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.ExchangeCashPersonList, error) {
  138 + tx := repository.transactionContext.PgTx
  139 + var exchangeCashListModels []*models.ExchangeCashPersonList
  140 + exchangeCashPeople := make([]*domain.ExchangeCashPersonList, 0)
  141 + query := tx.Model(&exchangeCashListModels)
  142 + if exchangeCashActivityId, ok := queryOptions["exchangeCashActivityId"]; ok {
  143 + query = query.Where("exchange_cash_person_list.activity_id = ?", exchangeCashActivityId)
  144 + }
  145 + if personNameMatch, ok := queryOptions["exchangeCashPersonNameMatch"]; ok && (personNameMatch != ""){
  146 + query = query.Where("exchange_cash_person_list.employee_name LIKE ?", fmt.Sprintf("%%%s%%", personNameMatch.(string)))
  147 + }
  148 + if employeeAccount, ok := queryOptions["employeeAccount"]; ok && (employeeAccount != "") {
  149 + query = query.Where("exchange_cash_person_list.employee_account =?", employeeAccount)
  150 + }
  151 + if uid, ok := queryOptions["uid"]; ok {
  152 + query = query.Where("exchange_cash_person_list.uid = ?", uid)
  153 + }
  154 + if offset, ok := queryOptions["offset"]; ok {
  155 + offset := offset.(int)
  156 + if offset > -1 {
  157 + query = query.Offset(offset)
  158 + }
  159 + } else {
  160 + query = query.Offset(0)
  161 + }
  162 + if limit, ok := queryOptions["limit"]; ok {
  163 + limit := limit.(int)
  164 + if limit > -1 {
  165 + query = query.Limit(limit)
  166 + }
  167 + } else {
  168 + query = query.Limit(20)
  169 + }
  170 + if count, err := query.Order("id DESC").SelectAndCount(); err != nil {
  171 + return 0, exchangeCashPeople, err
  172 + } else {
  173 + for _, exchangeCashListModel := range exchangeCashListModels {
  174 + if taskNature, err := repository.transformPgModelToDomainModel(exchangeCashListModel); err != nil {
  175 + return 0, exchangeCashPeople, err
  176 + } else {
  177 + exchangeCashPeople = append(exchangeCashPeople, taskNature)
  178 + }
  179 + }
  180 + return int64(count), exchangeCashPeople, nil
  181 + }
  182 +}
  183 +
  184 +func (repository *ExchangeCashPersonListRepository) Remove(exchangeCashList *domain.ExchangeCashPersonList) (*domain.ExchangeCashPersonList, error) {
  185 + tx := repository.transactionContext.PgTx
  186 + exchangeCashListModel := new(models.ExchangeCashPersonList)
  187 + exchangeCashListModel.Id = exchangeCashList.ListId
  188 + if _, err := tx.Model(exchangeCashListModel).WherePK().Delete(); err != nil {
  189 + return exchangeCashList, err
  190 + }
  191 + return exchangeCashList, nil
  192 +}
  193 +
  194 +func (repository *ExchangeCashPersonListRepository) transformPgModelToDomainModel(exchangeCashList *models.ExchangeCashPersonList) (*domain.ExchangeCashPersonList, error) {
  195 + return &domain.ExchangeCashPersonList{
  196 + ExchangedCash: exchangeCashList.ExchangedCash,
  197 + ExchangedSuMoney: exchangeCashList.ExchangedSuMoney,
  198 + ListId: exchangeCashList.Id,
  199 + ExchangeCashActivityId: exchangeCashList.ActivityId,
  200 + EmployeeInfo: &domain.EmployeeInfo{
  201 + Uid: exchangeCashList.Uid,
  202 + EmployeeName: exchangeCashList.EmployeeName,
  203 + EmployeeAccount: exchangeCashList.EmployeeAccount,
  204 + EmployeeAvatarUrl: exchangeCashList.EmployeeAvatarUrl,
  205 + IsPrincipal: exchangeCashList.IsPrincipal,
  206 + },
  207 + }, nil
  208 +}
  209 +func NewExchangeCashPersonListRepository(transactionContext *pgTransaction.TransactionContext) (*ExchangeCashPersonListRepository, error) {
  210 + if transactionContext == nil {
  211 + return nil, fmt.Errorf("transactionContext参数不能为nil")
  212 + } else {
  213 + return &ExchangeCashPersonListRepository{
  214 + transactionContext: transactionContext,
  215 + }, nil
  216 + }
  217 +}
  1 +package repository
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/go-pg/pg"
  6 + pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
  7 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
  8 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg/models"
  9 +)
  10 +
  11 +type ListIntervalRepository struct {
  12 + transactionContext *pgTransaction.TransactionContext
  13 +}
  14 +
  15 +func (repository *ListIntervalRepository) Save(listInterval *domain.ListInterval) (*domain.ListInterval, error) {
  16 + tx := repository.transactionContext.PgTx
  17 + if listInterval.Identify() == nil {
  18 + if _, err := tx.QueryOne(
  19 + pg.Scan(&listInterval.ListIntervalId, &listInterval.CompanyId, &listInterval.IntervalStartTime, &listInterval.IntervalEndTime),
  20 + "INSERT INTO list_intervals (list_interval_start_time, list_interval_end_time, company_id) VALUES (?, ?, ?) RETURNING id, company_id, list_interval_start_time, list_interval_end_time",
  21 + listInterval.IntervalStartTime, listInterval.IntervalEndTime, listInterval.CompanyId); err != nil {
  22 + return listInterval, err
  23 + }
  24 + } else {
  25 + if _, err := tx.QueryOne(
  26 + pg.Scan(&listInterval.ListIntervalId, &listInterval.CompanyId, &listInterval.IntervalStartTime, &listInterval.IntervalEndTime),
  27 + "UPDATE list_intervals SET list_interval_start_time=?, list_interval_end_time=? WHERE id=? RETURNING id, company_id, list_interval_start_time, list_interval_end_time",
  28 + listInterval.IntervalStartTime, listInterval.IntervalEndTime, listInterval.Identify()); err != nil {
  29 + return listInterval, err
  30 + }
  31 + }
  32 + return listInterval, nil
  33 +}
  34 +
  35 +func (repository *ListIntervalRepository) Remove(listInterval *domain.ListInterval) (*domain.ListInterval, error) {
  36 + tx := repository.transactionContext.PgTx
  37 + listIntervalModel := new(models.ListInterval)
  38 + listIntervalModel.Id = listInterval.Identify().(int)
  39 + if _, err := tx.Model(listIntervalModel).WherePK().Delete(); err != nil {
  40 + return listInterval, err
  41 + }
  42 + return listInterval, nil
  43 +}
  44 +
  45 +func (repository *ListIntervalRepository) FindOne(queryOptions map[string]interface{}) (*domain.ListInterval, error) {
  46 + tx := repository.transactionContext.PgTx
  47 + listIntervalModel := new(models.ListInterval)
  48 + query := tx.Model(listIntervalModel)
  49 + if listIntervalId, ok := queryOptions["listId"]; ok {
  50 + query = query.Where("list_interval.id = ?", listIntervalId)
  51 + }
  52 + if err := query.First(); err != nil {
  53 + if err.Error() == "pg: no rows in result set" {
  54 + return nil, fmt.Errorf("没有此资源")
  55 + } else {
  56 + return nil, err
  57 + }
  58 + }
  59 + if listIntervalModel.Id == 0 {
  60 + return nil, nil
  61 + } else {
  62 + return repository.transformPgModelToDomainModel(listIntervalModel)
  63 + }
  64 +}
  65 +
  66 +func (repository *ListIntervalRepository) FindAll(queryOptions map[string]interface{}) (int64, []*domain.ListInterval, error) {
  67 + tx := repository.transactionContext.PgTx
  68 + var listIntervalModels []*models.ListInterval
  69 + listIntervals := make([]*domain.ListInterval, 0)
  70 + query := tx.Model(&listIntervalModels)
  71 + if companyId, ok := queryOptions["companyId"]; ok {
  72 + query = query.Where("list_interval.company_id = ?", companyId)
  73 + }
  74 + if count, err := query.Order("id DESC").SelectAndCount(); err != nil {
  75 + return 0, listIntervals, err
  76 + } else {
  77 + for _, listIntervalModel := range listIntervalModels {
  78 + if listInterval, err := repository.transformPgModelToDomainModel(listIntervalModel); err != nil {
  79 + return 0, listIntervals, err
  80 + } else {
  81 + listIntervals = append(listIntervals, listInterval)
  82 + }
  83 + }
  84 + return int64(count), listIntervals, nil
  85 + }
  86 +}
  87 +
  88 +func (repository *ListIntervalRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.ListInterval, error) {
  89 + tx := repository.transactionContext.PgTx
  90 + var listIntervalModels []*models.ListInterval
  91 + listIntervals := make([]*domain.ListInterval, 0)
  92 + query := tx.Model(&listIntervalModels)
  93 + if companyId, ok := queryOptions["companyId"]; ok {
  94 + query = query.Where("list_interval.company_id = ?", companyId)
  95 + }
  96 + if offset, ok := queryOptions["offset"]; ok {
  97 + offset := offset.(int)
  98 + if offset > -1 {
  99 + query = query.Offset(offset)
  100 + }
  101 + } else {
  102 + query = query.Offset(0)
  103 + }
  104 + if limit, ok := queryOptions["limit"]; ok {
  105 + limit := limit.(int)
  106 + if limit > -1 {
  107 + query = query.Limit(limit)
  108 + }
  109 + } else {
  110 + query = query.Limit(20)
  111 + }
  112 + if count, err := query.Order("id DESC").SelectAndCount(); err != nil {
  113 + return 0, listIntervals, err
  114 + } else {
  115 + for _, listIntervalModel := range listIntervalModels {
  116 + if listInterval, err := repository.transformPgModelToDomainModel(listIntervalModel); err != nil {
  117 + return 0, listIntervals, err
  118 + } else {
  119 + listIntervals = append(listIntervals, listInterval)
  120 + }
  121 + }
  122 + return int64(count), listIntervals, nil
  123 + }
  124 +}
  125 +
  126 +func (repository *ListIntervalRepository) transformPgModelToDomainModel(listIntervalModel *models.ListInterval) (*domain.ListInterval, error) {
  127 + return &domain.ListInterval{
  128 + ListIntervalId: listIntervalModel.Id,
  129 + CompanyId: listIntervalModel.CompanyId,
  130 + IntervalStartTime: listIntervalModel.ListIntervalStartTime,
  131 + IntervalEndTime: listIntervalModel.ListIntervalEndTime,
  132 + }, nil
  133 +}
  134 +
  135 +func NewListIntervalRepository(transactionContext *pgTransaction.TransactionContext) (*ListIntervalRepository, error) {
  136 + if transactionContext == nil {
  137 + return nil, fmt.Errorf("transactionContext参数不能为nil")
  138 + } else {
  139 + return &ListIntervalRepository{
  140 + transactionContext: transactionContext,
  141 + }, nil
  142 + }
  143 +}
@@ -33,6 +33,7 @@ func (repository *SuMoneyTransactionRecordRepository) Save(suMoneyTransactionRec @@ -33,6 +33,7 @@ func (repository *SuMoneyTransactionRecordRepository) Save(suMoneyTransactionRec
33 } 33 }
34 return suMoneyTransactionRecord, nil 34 return suMoneyTransactionRecord, nil
35 } 35 }
  36 +
36 func (repository *SuMoneyTransactionRecordRepository) Remove(suMoneyTransactionRecord *domain.SuMoneyTransactionRecord) (*domain.SuMoneyTransactionRecord, error) { 37 func (repository *SuMoneyTransactionRecordRepository) Remove(suMoneyTransactionRecord *domain.SuMoneyTransactionRecord) (*domain.SuMoneyTransactionRecord, error) {
37 tx := repository.transactionContext.PgTx 38 tx := repository.transactionContext.PgTx
38 suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord) 39 suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
@@ -42,6 +43,7 @@ func (repository *SuMoneyTransactionRecordRepository) Remove(suMoneyTransactionR @@ -42,6 +43,7 @@ func (repository *SuMoneyTransactionRecordRepository) Remove(suMoneyTransactionR
42 } 43 }
43 return suMoneyTransactionRecord, nil 44 return suMoneyTransactionRecord, nil
44 } 45 }
  46 +
45 func (repository *SuMoneyTransactionRecordRepository) FindOne(queryOptions map[string]interface{}) (*domain.SuMoneyTransactionRecord, error) { 47 func (repository *SuMoneyTransactionRecordRepository) FindOne(queryOptions map[string]interface{}) (*domain.SuMoneyTransactionRecord, error) {
46 tx := repository.transactionContext.PgTx 48 tx := repository.transactionContext.PgTx
47 suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord) 49 suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
@@ -62,6 +64,36 @@ func (repository *SuMoneyTransactionRecordRepository) FindOne(queryOptions map[s @@ -62,6 +64,36 @@ func (repository *SuMoneyTransactionRecordRepository) FindOne(queryOptions map[s
62 return repository.transformPgModelToDomainModel(suMoneyTransactionRecordModel) 64 return repository.transformPgModelToDomainModel(suMoneyTransactionRecordModel)
63 } 65 }
64 } 66 }
  67 +
  68 +func (repository *SuMoneyTransactionRecordRepository) FindById(queryOptions map[string]interface{}) (int64, []*domain.SuMoneyTransactionRecord, error) {
  69 + tx := repository.transactionContext.PgTx
  70 + var suMoneyTransactionRecordModels []*models.SuMoneyTransactionRecord
  71 + suMoneyTransactionRecords := make([]*domain.SuMoneyTransactionRecord, 0)
  72 + query := tx.Model(&suMoneyTransactionRecordModels)
  73 + //query = query.Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint")
  74 + if iDs, ok := queryOptions["ids"]; ok && len(iDs.([]int)) != 0 {
  75 + query = query.Where(`su_money_transaction_record.id IN (?)`, pg.In(iDs.([]int)))
  76 + }
  77 + if where, ok := queryOptions["where"]; ok && where.(map[string]interface{}) != nil {
  78 + if uid, ok := where.(map[string]interface{})["uid"]; ok && (uid != int64(0)) {
  79 + query = query.Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid)
  80 + }
  81 + }
  82 + //query = query.Where(`e.status = ?`, 1)
  83 + if count, err := query.Order("id DESC").SelectAndCount(); err != nil {
  84 + return 0, suMoneyTransactionRecords, err
  85 + } else {
  86 + for _, suMoneyTransactionRecordModel := range suMoneyTransactionRecordModels {
  87 + if suMoneyTransactionRecord, err := repository.transformPgModelToDomainModel(suMoneyTransactionRecordModel); err != nil {
  88 + return 0, suMoneyTransactionRecords, err
  89 + } else {
  90 + suMoneyTransactionRecords = append(suMoneyTransactionRecords, suMoneyTransactionRecord)
  91 + }
  92 + }
  93 + return int64(count), suMoneyTransactionRecords, nil
  94 + }
  95 +}
  96 +
65 func (repository *SuMoneyTransactionRecordRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.SuMoneyTransactionRecord, error) { 97 func (repository *SuMoneyTransactionRecordRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.SuMoneyTransactionRecord, error) {
66 tx := repository.transactionContext.PgTx 98 tx := repository.transactionContext.PgTx
67 var suMoneyTransactionRecordModels []*models.SuMoneyTransactionRecord 99 var suMoneyTransactionRecordModels []*models.SuMoneyTransactionRecord
@@ -70,6 +102,9 @@ func (repository *SuMoneyTransactionRecordRepository) Find(queryOptions map[stri @@ -70,6 +102,9 @@ func (repository *SuMoneyTransactionRecordRepository) Find(queryOptions map[stri
70 if uid, ok := queryOptions["uid"]; ok && (uid != int64(0)) { 102 if uid, ok := queryOptions["uid"]; ok && (uid != int64(0)) {
71 query = query.Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid) 103 query = query.Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid)
72 } 104 }
  105 + if employeeMatchName, ok := queryOptions["employeeMatchName"]; ok && (employeeMatchName != "") {
  106 + query = query.Where(`(su_money_transaction_record.employee->>'employeeName')::text LIKE ?`, fmt.Sprintf("%%%s%%", employeeMatchName.(string)))
  107 + }
73 if recordType, ok := queryOptions["recordType"]; ok && (recordType != 0) { 108 if recordType, ok := queryOptions["recordType"]; ok && (recordType != 0) {
74 query = query.Where(`su_money_transaction_record.record_type = ?`, recordType) 109 query = query.Where(`su_money_transaction_record.record_type = ?`, recordType)
75 } 110 }
@@ -114,6 +149,7 @@ func (repository *SuMoneyTransactionRecordRepository) Find(queryOptions map[stri @@ -114,6 +149,7 @@ func (repository *SuMoneyTransactionRecordRepository) Find(queryOptions map[stri
114 return int64(count), suMoneyTransactionRecords, nil 149 return int64(count), suMoneyTransactionRecords, nil
115 } 150 }
116 } 151 }
  152 +
117 func (repository *SuMoneyTransactionRecordRepository) transformPgModelToDomainModel(suMoneyTransactionRecordModel *models.SuMoneyTransactionRecord) (*domain.SuMoneyTransactionRecord, error) { 153 func (repository *SuMoneyTransactionRecordRepository) transformPgModelToDomainModel(suMoneyTransactionRecordModel *models.SuMoneyTransactionRecord) (*domain.SuMoneyTransactionRecord, error) {
118 return &domain.SuMoneyTransactionRecord{ 154 return &domain.SuMoneyTransactionRecord{
119 SuMoneyTransactionRecordId: suMoneyTransactionRecordModel.Id, 155 SuMoneyTransactionRecordId: suMoneyTransactionRecordModel.Id,
@@ -127,6 +163,7 @@ func (repository *SuMoneyTransactionRecordRepository) transformPgModelToDomainMo @@ -127,6 +163,7 @@ func (repository *SuMoneyTransactionRecordRepository) transformPgModelToDomainMo
127 CreateTime: suMoneyTransactionRecordModel.CreateTime, 163 CreateTime: suMoneyTransactionRecordModel.CreateTime,
128 }, nil 164 }, nil
129 } 165 }
  166 +
130 func NewSuMoneyTransactionRecordRepository(transactionContext *pgTransaction.TransactionContext) (*SuMoneyTransactionRecordRepository, error) { 167 func NewSuMoneyTransactionRecordRepository(transactionContext *pgTransaction.TransactionContext) (*SuMoneyTransactionRecordRepository, error) {
131 if transactionContext == nil { 168 if transactionContext == nil {
132 return nil, fmt.Errorf("transactionContext参数不能为nil") 169 return nil, fmt.Errorf("transactionContext参数不能为nil")
@@ -32,6 +32,7 @@ func (repository *TaskNatureRepository) Save(taskNature *domain.TaskNature) (*do @@ -32,6 +32,7 @@ func (repository *TaskNatureRepository) Save(taskNature *domain.TaskNature) (*do
32 } 32 }
33 return taskNature, nil 33 return taskNature, nil
34 } 34 }
  35 +
35 func (repository *TaskNatureRepository) Remove(taskNature *domain.TaskNature) (*domain.TaskNature, error) { 36 func (repository *TaskNatureRepository) Remove(taskNature *domain.TaskNature) (*domain.TaskNature, error) {
36 tx := repository.transactionContext.PgTx 37 tx := repository.transactionContext.PgTx
37 taskNatureModel := new(models.TaskNature) 38 taskNatureModel := new(models.TaskNature)
@@ -41,6 +42,7 @@ func (repository *TaskNatureRepository) Remove(taskNature *domain.TaskNature) (* @@ -41,6 +42,7 @@ func (repository *TaskNatureRepository) Remove(taskNature *domain.TaskNature) (*
41 } 42 }
42 return taskNature, nil 43 return taskNature, nil
43 } 44 }
  45 +
44 func (repository *TaskNatureRepository) FindOne(queryOptions map[string]interface{}) (*domain.TaskNature, error) { 46 func (repository *TaskNatureRepository) FindOne(queryOptions map[string]interface{}) (*domain.TaskNature, error) {
45 tx := repository.transactionContext.PgTx 47 tx := repository.transactionContext.PgTx
46 taskNatureModel := new(models.TaskNature) 48 taskNatureModel := new(models.TaskNature)
@@ -61,6 +63,7 @@ func (repository *TaskNatureRepository) FindOne(queryOptions map[string]interfac @@ -61,6 +63,7 @@ func (repository *TaskNatureRepository) FindOne(queryOptions map[string]interfac
61 return repository.transformPgModelToDomainModel(taskNatureModel) 63 return repository.transformPgModelToDomainModel(taskNatureModel)
62 } 64 }
63 } 65 }
  66 +
64 func (repository *TaskNatureRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.TaskNature, error) { 67 func (repository *TaskNatureRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.TaskNature, error) {
65 tx := repository.transactionContext.PgTx 68 tx := repository.transactionContext.PgTx
66 var taskNatureModels []*models.TaskNature 69 var taskNatureModels []*models.TaskNature
@@ -104,6 +107,7 @@ func (repository *TaskNatureRepository) Find(queryOptions map[string]interface{} @@ -104,6 +107,7 @@ func (repository *TaskNatureRepository) Find(queryOptions map[string]interface{}
104 return int64(count), taskNatures, nil 107 return int64(count), taskNatures, nil
105 } 108 }
106 } 109 }
  110 +
107 func (repository *TaskNatureRepository) transformPgModelToDomainModel(taskNatureModel *models.TaskNature) (*domain.TaskNature, error) { 111 func (repository *TaskNatureRepository) transformPgModelToDomainModel(taskNatureModel *models.TaskNature) (*domain.TaskNature, error) {
108 return &domain.TaskNature{ 112 return &domain.TaskNature{
109 TaskNatureId: taskNatureModel.Id, 113 TaskNatureId: taskNatureModel.Id,
@@ -111,6 +115,7 @@ func (repository *TaskNatureRepository) transformPgModelToDomainModel(taskNature @@ -111,6 +115,7 @@ func (repository *TaskNatureRepository) transformPgModelToDomainModel(taskNature
111 CompanyId: taskNatureModel.CompanyId, 115 CompanyId: taskNatureModel.CompanyId,
112 }, nil 116 }, nil
113 } 117 }
  118 +
114 func NewTaskNatureRepository(transactionContext *pgTransaction.TransactionContext) (*TaskNatureRepository, error) { 119 func NewTaskNatureRepository(transactionContext *pgTransaction.TransactionContext) (*TaskNatureRepository, error) {
115 if transactionContext == nil { 120 if transactionContext == nil {
116 return nil, fmt.Errorf("transactionContext参数不能为nil") 121 return nil, fmt.Errorf("transactionContext参数不能为nil")
@@ -32,9 +32,9 @@ func (repository *TaskRepository) Save(task *domain.Task) (*domain.Task, error) @@ -32,9 +32,9 @@ func (repository *TaskRepository) Save(task *domain.Task) (*domain.Task, error)
32 return task, err 32 return task, err
33 } 33 }
34 if _, err := tx.QueryOne( 34 if _, err := tx.QueryOne(
35 - pg.Scan(&task.TaskId, &task.CompanyId, &task.TaskName, &task.TaskType, &task.Sponsor, &task.TaskStatus, &task.ReferenceResource, &task.ProjectBelong, pg.Array(&task.CustomerValues), &task.TaskNature, &task.SuMoney, &task.AcceptanceStandard, &task.TaskDescription, pg.Array(&task.TaskPictureUrls), &task.IsRewardTake, &task.CreateTime, &task.ReleaseTime, &task.Participators, &task.TaskPercentage, &task.SolveReport, pg.Array(&task.SolvePictureUrls), &task.AssignedPerson, &task.PlannedCompletionTime, &task.ActualCompletionTime),  
36 - "INSERT INTO tasks (id, company_id, task_name, task_type, sponsor, task_status, reference_resource, project_belong, customer_values, task_nature, su_money, acceptance_standard, task_description, task_picture_urls, is_reward_take, create_time, release_time, participators, task_percentage, solve_report, solve_picture_urls, assigned_person, planned_completion_time, actual_completion_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id, company_id, task_name, task_type, sponsor, task_status, reference_resource, project_belong, customer_values, task_nature, su_money, acceptance_standard, task_description, task_picture_urls, is_reward_take, create_time, release_time, participators, task_percentage, solve_report, solve_picture_urls, assigned_person, planned_completion_time, actual_completion_time",  
37 - takeId, task.CompanyId, task.TaskName, task.TaskType, task.Sponsor, task.TaskStatus, task.ReferenceResource, task.ProjectBelong, pg.Array(task.CustomerValues), task.TaskNature, task.SuMoney, task.AcceptanceStandard, task.TaskDescription, pg.Array(task.TaskPictureUrls), task.IsRewardTake, task.CreateTime, task.ReleaseTime, task.Participators, task.TaskPercentage, task.SolveReport, pg.Array(task.SolvePictureUrls), task.AssignedPerson, task.PlannedCompletionTime, task.ActualCompletionTime); err != nil { 35 + pg.Scan(&task.TaskId, &task.CompanyId, &task.TaskName, &task.TaskType, &task.Sponsor, &task.TaskStatus, &task.ReferenceResource, &task.ProjectBelong, pg.Array(&task.CustomerValues), &task.TaskNature, &task.SuMoney, &task.MinSuMoney, &task.MaxSuMoney, &task.AcceptanceStandard, &task.TaskDescription, pg.Array(&task.TaskPictureUrls), &task.IsRewardTake, &task.CreateTime, &task.ReleaseTime, &task.Participators, &task.TaskPercentage, &task.SolveReport, pg.Array(&task.SolvePictureUrls), &task.AssignedPerson, &task.PlannedCompletionTime, &task.ActualCompletionTime),
  36 + "INSERT INTO tasks (id, company_id, task_name, task_type, sponsor, task_status, reference_resource, project_belong, customer_values, task_nature, su_money, min_su_money, max_su_money, acceptance_standard, task_description, task_picture_urls, is_reward_take, create_time, release_time, participators, task_percentage, solve_report, solve_picture_urls, assigned_person, planned_completion_time, actual_completion_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id, company_id, task_name, task_type, sponsor, task_status, reference_resource, project_belong, customer_values, task_nature, su_money, min_su_money, max_su_money, acceptance_standard, task_description, task_picture_urls, is_reward_take, create_time, release_time, participators, task_percentage, solve_report, solve_picture_urls, assigned_person, planned_completion_time, actual_completion_time",
  37 + takeId, task.CompanyId, task.TaskName, task.TaskType, task.Sponsor, task.TaskStatus, task.ReferenceResource, task.ProjectBelong, pg.Array(task.CustomerValues), task.TaskNature, task.SuMoney, task.MinSuMoney, task.MaxSuMoney, task.AcceptanceStandard, task.TaskDescription, pg.Array(task.TaskPictureUrls), task.IsRewardTake, task.CreateTime, task.ReleaseTime, task.Participators, task.TaskPercentage, task.SolveReport, pg.Array(task.SolvePictureUrls), task.AssignedPerson, task.PlannedCompletionTime, task.ActualCompletionTime); err != nil {
38 return task, err 38 return task, err
39 } 39 }
40 } else { 40 } else {
@@ -49,9 +49,9 @@ func (repository *TaskRepository) Save(task *domain.Task) (*domain.Task, error) @@ -49,9 +49,9 @@ func (repository *TaskRepository) Save(task *domain.Task) (*domain.Task, error)
49 taskReceiverUid = 0 49 taskReceiverUid = 0
50 } 50 }
51 if _, err := tx.QueryOne( 51 if _, err := tx.QueryOne(
52 - pg.Scan(&task.TaskId, &task.CompanyId, &task.TaskName, &task.TaskType, &task.Sponsor, &task.TaskStatus, &task.ReferenceResource, &task.ProjectBelong, pg.Array(&task.CustomerValues), &task.TaskNature, &task.SuMoney, &task.AcceptanceStandard, &task.TaskDescription, pg.Array(&task.TaskPictureUrls), &task.IsRewardTake, &task.CreateTime, &task.ReleaseTime, &task.Participators, &task.TaskPercentage, &task.SolveReport, pg.Array(&task.SolvePictureUrls), &task.AssignedPerson, &task.PlannedCompletionTime, &task.ActualCompletionTime, &task.ReceiveTime, &task.CompleteTime, &task.AcceptanceTime),  
53 - "UPDATE tasks SET company_id=?, task_name=?, task_type=?, sponsor=?, task_status=?, reference_resource=?, project_belong=?, customer_values=?, task_nature=?, su_money=?, acceptance_standard=?, task_description=?, task_picture_urls=?, is_reward_take=?, receiver_uid=?, create_time=?, release_time=?, participators=?, task_percentage=?, solve_report=?, solve_picture_urls=?, assigned_person=?, planned_completion_time=?, actual_completion_time=?, receive_time=?, complete_time=?, acceptance_time=? WHERE id=? RETURNING id, company_id, task_name, task_type, sponsor, task_status, reference_resource, project_belong, customer_values, task_nature, su_money, acceptance_standard, task_description, task_picture_urls, is_reward_take, create_time, release_time, participators, task_percentage, solve_report, solve_picture_urls, assigned_person, planned_completion_time, actual_completion_time, receive_time, complete_time, acceptance_time",  
54 - task.CompanyId, task.TaskName, task.TaskType, task.Sponsor, task.TaskStatus, task.ReferenceResource, task.ProjectBelong, pg.Array(task.CustomerValues), task.TaskNature, task.SuMoney, task.AcceptanceStandard, task.TaskDescription, pg.Array(task.TaskPictureUrls), task.IsRewardTake, taskReceiverUid, task.CreateTime, task.ReleaseTime, task.Participators, task.TaskPercentage, task.SolveReport, pg.Array(task.SolvePictureUrls), task.AssignedPerson, task.PlannedCompletionTime, task.ActualCompletionTime, task.ReceiveTime, task.CompleteTime, task.AcceptanceTime, task.Identify()); err != nil { 52 + pg.Scan(&task.TaskId, &task.CompanyId, &task.TaskName, &task.TaskType, &task.Sponsor, &task.TaskStatus, &task.ReferenceResource, &task.ProjectBelong, pg.Array(&task.CustomerValues), &task.TaskNature, &task.SuMoney, &task.MinSuMoney, &task.MaxSuMoney, &task.AcceptanceStandard, &task.TaskDescription, pg.Array(&task.TaskPictureUrls), &task.IsRewardTake, &task.CreateTime, &task.ReleaseTime, &task.Participators, &task.TaskPercentage, &task.SolveReport, pg.Array(&task.SolvePictureUrls), &task.AssignedPerson, &task.PlannedCompletionTime, &task.ActualCompletionTime, &task.ReceiveTime, &task.CompleteTime, &task.AcceptanceTime),
  53 + "UPDATE tasks SET company_id=?, task_name=?, task_type=?, sponsor=?, task_status=?, reference_resource=?, project_belong=?, customer_values=?, task_nature=?, su_money=?, min_su_money=?, max_su_money=?, acceptance_standard=?, task_description=?, task_picture_urls=?, is_reward_take=?, receiver_uid=?, create_time=?, release_time=?, participators=?, task_percentage=?, solve_report=?, solve_picture_urls=?, assigned_person=?, planned_completion_time=?, actual_completion_time=?, receive_time=?, complete_time=?, acceptance_time=? WHERE id=? RETURNING id, company_id, task_name, task_type, sponsor, task_status, reference_resource, project_belong, customer_values, task_nature, su_money, min_su_money, max_su_money, acceptance_standard, task_description, task_picture_urls, is_reward_take, create_time, release_time, participators, task_percentage, solve_report, solve_picture_urls, assigned_person, planned_completion_time, actual_completion_time, receive_time, complete_time, acceptance_time",
  54 + task.CompanyId, task.TaskName, task.TaskType, task.Sponsor, task.TaskStatus, task.ReferenceResource, task.ProjectBelong, pg.Array(task.CustomerValues), task.TaskNature, task.SuMoney, task.MinSuMoney, task.MaxSuMoney, task.AcceptanceStandard, task.TaskDescription, pg.Array(task.TaskPictureUrls), task.IsRewardTake, taskReceiverUid, task.CreateTime, task.ReleaseTime, task.Participators, task.TaskPercentage, task.SolveReport, pg.Array(task.SolvePictureUrls), task.AssignedPerson, task.PlannedCompletionTime, task.ActualCompletionTime, task.ReceiveTime, task.CompleteTime, task.AcceptanceTime, task.Identify()); err != nil {
55 return task, err 55 return task, err
56 } 56 }
57 } 57 }
@@ -95,6 +95,7 @@ func (repository *TaskRepository) FindOne(queryOptions map[string]interface{}) ( @@ -95,6 +95,7 @@ func (repository *TaskRepository) FindOne(queryOptions map[string]interface{}) (
95 return repository.transformPgModelToDomainModel(taskModel) 95 return repository.transformPgModelToDomainModel(taskModel)
96 } 96 }
97 } 97 }
  98 +
98 func (repository *TaskRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.Task, error) { 99 func (repository *TaskRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.Task, error) {
99 tx := repository.transactionContext.PgTx 100 tx := repository.transactionContext.PgTx
100 var taskModels []*models.Task 101 var taskModels []*models.Task
@@ -115,6 +116,23 @@ func (repository *TaskRepository) Find(queryOptions map[string]interface{}) (int @@ -115,6 +116,23 @@ func (repository *TaskRepository) Find(queryOptions map[string]interface{}) (int
115 if taskStatus, ok := queryOptions["taskStatus"]; ok && (taskStatus != 0) { 116 if taskStatus, ok := queryOptions["taskStatus"]; ok && (taskStatus != 0) {
116 query = query.Where(`task.task_status = ?`, taskStatus) 117 query = query.Where(`task.task_status = ?`, taskStatus)
117 } 118 }
  119 + if taskStates, ok := queryOptions["taskStates"]; ok && len(taskStates.([]int)) != 0 {
  120 + query = query.WhereGroup(func(q *orm.Query) (*orm.Query, error) {
  121 + for _, value := range taskStates.([]int) {
  122 + q = q.WhereOr("task.task_status = ?", value)
  123 + }
  124 + return q, nil
  125 + })
  126 + }
  127 + if taskStatuss, ok := queryOptions["taskStatuss"]; ok && len(taskStatuss.([]int)) != 0 {
  128 + //query = query.WhereGroup(func(q *orm.Query) (*orm.Query, error) {
  129 + // for _, value := range taskStatuss.([]int) {
  130 + // q = q.WhereOr("task.task_status = ?", value)
  131 + // }
  132 + // return q, nil
  133 + //})
  134 + query = query.Where(`task.task_status IN (?)`, pg.In(taskStatuss.([]int)))
  135 + }
118 if taskType, ok := queryOptions["taskType"]; ok && (taskType != 0) { 136 if taskType, ok := queryOptions["taskType"]; ok && (taskType != 0) {
119 query = query.Where(`task.task_type = ?`, taskType) 137 query = query.Where(`task.task_type = ?`, taskType)
120 } 138 }
@@ -153,6 +171,9 @@ func (repository *TaskRepository) Find(queryOptions map[string]interface{}) (int @@ -153,6 +171,9 @@ func (repository *TaskRepository) Find(queryOptions map[string]interface{}) (int
153 if taskContentMatch, ok := queryOptions["taskContentMatch"]; ok && (taskContentMatch != "") { 171 if taskContentMatch, ok := queryOptions["taskContentMatch"]; ok && (taskContentMatch != "") {
154 query = query.Where("task.task_name LIKE ?", fmt.Sprintf("%%%s%%", taskContentMatch.(string))) 172 query = query.Where("task.task_name LIKE ?", fmt.Sprintf("%%%s%%", taskContentMatch.(string)))
155 } 173 }
  174 + if taskNameMatch, ok := queryOptions["taskNameMatch"]; ok && (taskNameMatch != "") { //
  175 + query = query.Where("task.task_name LIKE ?", fmt.Sprintf("%%%s%%", taskNameMatch.(string)))
  176 + }
156 if isRewardTake, ok := queryOptions["isRewardTake"]; ok && (isRewardTake != false) { 177 if isRewardTake, ok := queryOptions["isRewardTake"]; ok && (isRewardTake != false) {
157 query = query.Where(`task.is_reward_take = ?`, isRewardTake) 178 query = query.Where(`task.is_reward_take = ?`, isRewardTake)
158 } 179 }
@@ -305,6 +326,9 @@ func (repository *TaskRepository) transformPgModelToDomainModel(taskModel *model @@ -305,6 +326,9 @@ func (repository *TaskRepository) transformPgModelToDomainModel(taskModel *model
305 case domain.TASK_STATUS_UNCONFIRMED: 326 case domain.TASK_STATUS_UNCONFIRMED:
306 currentStatus = &domain.UnConfirmedStatus{} 327 currentStatus = &domain.UnConfirmedStatus{}
307 break 328 break
  329 + case domain.TASK_STATUS_EXPIRED:
  330 + currentStatus = &domain.ExpiredStatus{}
  331 + break
308 } 332 }
309 return &domain.Task{ 333 return &domain.Task{
310 TaskId: taskModel.Id, 334 TaskId: taskModel.Id,
@@ -318,6 +342,8 @@ func (repository *TaskRepository) transformPgModelToDomainModel(taskModel *model @@ -318,6 +342,8 @@ func (repository *TaskRepository) transformPgModelToDomainModel(taskModel *model
318 CustomerValues: taskModel.CustomerValues, 342 CustomerValues: taskModel.CustomerValues,
319 TaskNature: taskModel.TaskNature, 343 TaskNature: taskModel.TaskNature,
320 SuMoney: taskModel.SuMoney, 344 SuMoney: taskModel.SuMoney,
  345 + MinSuMoney: taskModel.MinSuMoney,
  346 + MaxSuMoney: taskModel.MaxSuMoney,
321 AcceptanceStandard: taskModel.AcceptanceStandard, 347 AcceptanceStandard: taskModel.AcceptanceStandard,
322 TaskDescription: taskModel.TaskDescription, 348 TaskDescription: taskModel.TaskDescription,
323 TaskPictureUrls: taskModel.TaskPictureUrls, 349 TaskPictureUrls: taskModel.TaskPictureUrls,
  1 +package utils
  2 +
  3 +import (
  4 + "encoding/json"
  5 + "fmt"
  6 + "time"
  7 +)
  8 +
  9 +func StringSliceEqualBCE(a, b []int) bool {
  10 + if len(a) != len(b) {
  11 + return false
  12 + }
  13 +
  14 + if (a == nil) != (b == nil) {
  15 + return false
  16 + }
  17 +
  18 + b = b[:len(a)]
  19 + for i, v := range a {
  20 + if v != b[i] {
  21 + return false
  22 + }
  23 + }
  24 +
  25 + return true
  26 +}
  27 +
  28 +func IsContain(items []interface{}, item string) bool {
  29 + for _, eachItem := range items {
  30 + if eachItem == item {
  31 + return true
  32 + }
  33 + }
  34 + return false
  35 +}
  36 +
  37 +func IsContainInt(items map[int64]interface{}, item int64) bool {
  38 + for _, eachItem := range items {
  39 + if eachItem == item {
  40 + return true
  41 + }
  42 + }
  43 + return false
  44 +}
  45 +
  46 +type LocalTime time.Time
  47 +
  48 +// MarshalJSON satify the json marshal interface
  49 +func (l LocalTime) MarshalJSON() ([]byte, error) {
  50 + stamp := fmt.Sprintf("\"%s\"", time.Time(l).Format("2006-01-02 15:04:05"))
  51 + return []byte(stamp), nil
  52 +}
  53 +
  54 +type LocalDate time.Time
  55 +
  56 +// MarshalJSON satify the json marshal interface
  57 +func (l LocalDate) MarshalJSON() ([]byte, error) {
  58 + stamp := fmt.Sprintf("\"%s\"", time.Time(l).Format("2006-01-02"))
  59 + return []byte(stamp), nil
  60 +}
  61 +
  62 +func JsonToMap(jsonStr string) (map[string]string, error) {
  63 + m := make(map[string]string)
  64 + err := json.Unmarshal([]byte(jsonStr), &m)
  65 + if err != nil {
  66 + fmt.Printf("Unmarshal with error: %+v\n", err)
  67 + return nil, err
  68 + }
  69 +
  70 + for k, v := range m {
  71 + fmt.Printf("%v: %v\n", k, v)
  72 + }
  73 +
  74 + return m, nil
  75 +}
  76 +
  77 +func InsertSlice(index int, newstr []string, src []string) (ns []string) {
  78 + ns = append(ns, src[:index]...) // 切片后加..., 相当于拆包成单个元素
  79 + ns = append(ns, newstr...)
  80 + ns = append(ns, src[index:]...)
  81 + return
  82 +}
  83 +
  84 +//RankPeriodCheckTime 设置赛季时检查时间范围的合法性
  85 +//func RankPeriodCheckTime(rankTypeId int64, beginTime int64, endTime int64, idNot int64) bool {
  86 +// sql := `SELECT count(*) FROM rank_period
  87 +// WHERE rank_type_id = %d
  88 +// AND id <> %d
  89 +// AND
  90 +// (
  91 +// (UNIX_TIMESTAMP(begin_time) BETWEEN %d AND %d)
  92 +// OR
  93 +// (UNIX_TIMESTAMP(end_time) BETWEEN %d AND %d)
  94 +// OR
  95 +// (%d BETWEEN UNIX_TIMESTAMP(begin_time) AND UNIX_TIMESTAMP(end_time))
  96 +// OR
  97 +// (%d BETWEEN UNIX_TIMESTAMP(begin_time) AND UNIX_TIMESTAMP(end_time))
  98 +// )
  99 +// LIMIT 1 `
  100 +// sql = fmt.Sprintf(sql, rankTypeId, idNot, beginTime, endTime, beginTime, endTime, beginTime, endTime)
  101 +// var cnt int
  102 +// err := utils.ExecuteQueryOne(&cnt, sql)
  103 +// if err != nil {
  104 +// log.Error("SQL Execute err:%s", err)
  105 +// return false
  106 +// }
  107 +// if cnt > 0 {
  108 +// return false
  109 +// }
  110 +// return true
  111 +//}
1 -package constant 1 +//package constant
  2 +
  3 +//var Logger log.Logger
  4 +
  5 +// TODO 日志输出
  6 +//func init() {
  7 +// Logger = logrus.NewLogrusLogger()
  8 +// Logger.SetServiceName(constant.SERVICE_NAME)
  9 +// Logger.SetLevel(constant.LOG_LEVEL)
  10 +//}
  11 +
  12 +
  13 +package log
2 14
3 import ( 15 import (
4 - "github.com/linmadan/egglib-go/log"  
5 - "github.com/linmadan/egglib-go/log/logrus" 16 + "github.com/astaxie/beego"
  17 + "github.com/astaxie/beego/logs"
6 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/constant" 18 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/constant"
  19 + "path/filepath"
  20 + "strconv"
7 ) 21 )
8 22
9 -var Logger log.Logger 23 +var Logger *logs.BeeLogger
10 24
11 func init() { 25 func init() {
12 - Logger = logrus.NewLogrusLogger()  
13 - Logger.SetServiceName(constant.SERVICE_NAME)  
14 - Logger.SetLevel(constant.LOG_LEVEL) 26 + Logger = NewBeegoLogger(LoggerConfig{
  27 + Filename: constant.LOG_File,
  28 + Level: constant.LOG_LEVEL,
  29 + })
  30 +}
  31 +
  32 +type LoggerConfig struct {
  33 + Level string `json:"level,omitempty"`
  34 + Filename string `json:"filename,omitempty"`
  35 + MaxSize int `json:"max_size,omitempty"`
  36 + MaxBackups int `json:"max_backups,omitempty"`
  37 + MaxAge int `json:"max_age,omitempty"`
  38 + Compress bool `json:"compress,omitempty"`
  39 +}
  40 +
  41 +func NewBeegoLogger(conf LoggerConfig) *logs.BeeLogger {
  42 + filename := `{"filename":"` + filepath.ToSlash(conf.Filename) + `"}`
  43 +
  44 + log := logs.GetBeeLogger()
  45 +
  46 + log.SetLogger(logs.AdapterFile, filename)
  47 + ilv, err := strconv.Atoi(conf.Level)
  48 + if err != nil {
  49 + ilv = logs.LevelDebug
  50 + }
  51 + log.SetLevel(ilv)
  52 + log.EnableFuncCallDepth(true)
  53 + log.SetLogFuncCallDepth(5)
  54 + return log
  55 +}
  56 +
  57 +func Debug(args ...interface{}) {
  58 + beego.Debug(args...)
15 } 59 }
  60 +func Info(args ...interface{}) {
  61 + beego.Info(args...)
  62 +}
  63 +func Warn(args ...interface{}) {
  64 + beego.Warn(args...)
  65 +}
  66 +func Error(args ...interface{}) {
  67 + beego.Error(args...)
  68 +}
  69 +
@@ -4,11 +4,20 @@ import ( @@ -4,11 +4,20 @@ import (
4 "github.com/astaxie/beego" 4 "github.com/astaxie/beego"
5 "github.com/linmadan/egglib-go/web/beego/filters" 5 "github.com/linmadan/egglib-go/web/beego/filters"
6 . "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/log" 6 . "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/log"
  7 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/port/beego/middleware"
7 _ "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/port/beego/routers" 8 _ "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/port/beego/routers"
  9 + "time"
8 ) 10 )
9 11
10 func init() { 12 func init() {
11 beego.InsertFilter("/*", beego.BeforeExec, filters.CreateRequestBodyFilter()) 13 beego.InsertFilter("/*", beego.BeforeExec, filters.CreateRequestBodyFilter())
12 - beego.InsertFilter("/*", beego.BeforeExec, filters.CreateRequstLogFilter(Logger))  
13 - beego.InsertFilter("/*", beego.AfterExec, filters.CreateResponseLogFilter(Logger), false) 14 +
  15 + //beego.InsertFilter("/*", beego.BeforeExec, filters.CreateRequstLogFilter(Logger))
  16 + //beego.InsertFilter("/*", beego.AfterExec, filters.CreateResponseLogFilter(Logger), false)
  17 +
  18 + beego.InsertFilter("/*", beego.BeforeExec, middleware.CreateRequstLogFilter(Logger))
  19 + beego.InsertFilter("/*", beego.AfterExec, middleware.CreateResponseLogFilter(Logger), false)
  20 +
  21 + timeLocal, _ := time.LoadLocation("Asia/Chongqing")
  22 + time.Local = timeLocal
14 } 23 }
@@ -2,6 +2,7 @@ package controllers @@ -2,6 +2,7 @@ package controllers
2 2
3 import ( 3 import (
4 "encoding/json" 4 "encoding/json"
  5 + "fmt"
5 6
6 "github.com/astaxie/beego" 7 "github.com/astaxie/beego"
7 "github.com/linmadan/egglib-go/web/beego/utils" 8 "github.com/linmadan/egglib-go/web/beego/utils"
@@ -85,10 +86,13 @@ func (controller *EmployeeController) ListEmployee() { @@ -85,10 +86,13 @@ func (controller *EmployeeController) ListEmployee() {
85 listEmployeeQuery.CompanyId = companyId 86 listEmployeeQuery.CompanyId = companyId
86 employeeNameMatch := controller.GetString("employeeNameMatch") 87 employeeNameMatch := controller.GetString("employeeNameMatch")
87 listEmployeeQuery.EmployeeNameMatch = employeeNameMatch 88 listEmployeeQuery.EmployeeNameMatch = employeeNameMatch
  89 + status, _ := controller.GetInt("status")
  90 + listEmployeeQuery.Status = status
88 offset, _ := controller.GetInt("offset") 91 offset, _ := controller.GetInt("offset")
89 listEmployeeQuery.Offset = offset 92 listEmployeeQuery.Offset = offset
90 limit, _ := controller.GetInt("limit") 93 limit, _ := controller.GetInt("limit")
91 listEmployeeQuery.Limit = limit 94 listEmployeeQuery.Limit = limit
  95 + fmt.Print(listEmployeeQuery)
92 data, err := employeeService.ListEmployee(listEmployeeQuery) 96 data, err := employeeService.ListEmployee(listEmployeeQuery)
93 var response utils.JsonResponse 97 var response utils.JsonResponse
94 if err != nil { 98 if err != nil {
  1 +package controllers
  2 +
  3 +import (
  4 + "encoding/json"
  5 + "github.com/astaxie/beego"
  6 + "github.com/linmadan/egglib-go/web/beego/utils"
  7 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/listInterval/command"
  8 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/listInterval/query"
  9 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/listInterval/service"
  10 +)
  11 +
  12 +type ListIntervalController struct {
  13 + beego.Controller
  14 +}
  15 +
  16 +// 新增榜单时间段
  17 +func (controller *ListIntervalController) CreateListInterval() {
  18 + listIntervalService := service.NewListIntervalService(nil)
  19 + createListIntervalCommand := &command.CreateListIntervalCommand{}
  20 + json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), createListIntervalCommand)
  21 + data, err := listIntervalService.CreateListInterval(createListIntervalCommand)
  22 + var response utils.JsonResponse
  23 + if err != nil {
  24 + response = utils.ResponseError(controller.Ctx, err)
  25 + } else {
  26 + response = utils.ResponseData(controller.Ctx, data)
  27 + }
  28 + controller.Data["json"] = response
  29 + controller.ServeJSON()
  30 +}
  31 +
  32 +// 更新榜单时间段
  33 +func (controller *ListIntervalController) UpdateListInterval() {
  34 + listIntervalService := service.NewListIntervalService(nil)
  35 + updateListIntervalCommand := &command.UpdateListIntervalCommand{}
  36 + json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), updateListIntervalCommand)
  37 + listId, _ := controller.GetInt(":listId")
  38 + updateListIntervalCommand.ListIntervalId = listId
  39 + data, err := listIntervalService.UpdateListInterval(updateListIntervalCommand)
  40 + var response utils.JsonResponse
  41 + if err != nil {
  42 + response = utils.ResponseError(controller.Ctx, err)
  43 + } else {
  44 + response = utils.ResponseData(controller.Ctx, data)
  45 + }
  46 + controller.Data["json"] = response
  47 + controller.ServeJSON()
  48 +}
  49 +
  50 +// 获取榜单时间段
  51 +func (controller *ListIntervalController) GetListInterval() {
  52 + listIntervalService := service.NewListIntervalService(nil)
  53 + getListIntervalQuery := &query.GetListIntervalQuery{}
  54 + listId, _ := controller.GetInt(":listId")
  55 + getListIntervalQuery.ListIntervalId = listId
  56 + data, err := listIntervalService.GetListInterval(getListIntervalQuery)
  57 + var response utils.JsonResponse
  58 + if err != nil {
  59 + response = utils.ResponseError(controller.Ctx, err)
  60 + } else {
  61 + response = utils.ResponseData(controller.Ctx, data)
  62 + }
  63 + controller.Data["json"] = response
  64 + controller.ServeJSON()
  65 +}
  66 +
  67 +// 获取榜单时间段列表
  68 +func (controller *ListIntervalController) ListListInterval() {
  69 + listIntervalService := service.NewListIntervalService(nil)
  70 + listListIntervalQuery := &query.ListListIntervalQuery{}
  71 + companyId, _ := controller.GetInt("companyId")
  72 + listListIntervalQuery.CompanyId = companyId
  73 + offset, _ := controller.GetInt("offset")
  74 + listListIntervalQuery.Offset = offset
  75 + limit, _ := controller.GetInt("limit")
  76 + listListIntervalQuery.Limit = limit
  77 + data, err := listIntervalService.ListListInterval(listListIntervalQuery)
  78 + var response utils.JsonResponse
  79 + if err != nil {
  80 + response = utils.ResponseError(controller.Ctx, err)
  81 + } else {
  82 + response = utils.ResponseData(controller.Ctx, data)
  83 + }
  84 + controller.Data["json"] = response
  85 + controller.ServeJSON()
  86 +}
  87 +
  88 +// 移除榜单时间段
  89 +func (controller *ListIntervalController) RemoveListInterval() {
  90 + listIntervalService := service.NewListIntervalService(nil)
  91 + removeListIntervalQuery := &command.RemoveListIntervalCommand{}
  92 + listId, _ := controller.GetInt(":listId")
  93 + removeListIntervalQuery.ListIntervalId = listId
  94 + data, err := listIntervalService.RemoveListInterval(removeListIntervalQuery)
  95 + var response utils.JsonResponse
  96 + if err != nil {
  97 + response = utils.ResponseError(controller.Ctx, err)
  98 + } else {
  99 + response = utils.ResponseData(controller.Ctx, data)
  100 + }
  101 + controller.Data["json"] = response
  102 + controller.ServeJSON()
  103 +}
  104 +
@@ -2,6 +2,8 @@ package controllers @@ -2,6 +2,8 @@ package controllers
2 2
3 import ( 3 import (
4 "encoding/json" 4 "encoding/json"
  5 + "fmt"
  6 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/suMoney/query"
5 7
6 "github.com/astaxie/beego" 8 "github.com/astaxie/beego"
7 "github.com/linmadan/egglib-go/web/beego/utils" 9 "github.com/linmadan/egglib-go/web/beego/utils"
@@ -13,6 +15,7 @@ type StatisticsController struct { @@ -13,6 +15,7 @@ type StatisticsController struct {
13 beego.Controller 15 beego.Controller
14 } 16 }
15 17
  18 +// 系统任务统计
16 func (controller *StatisticsController) SystemTaskStatistics() { 19 func (controller *StatisticsController) SystemTaskStatistics() {
17 statisticsService := service.NewStatisticsService(nil) 20 statisticsService := service.NewStatisticsService(nil)
18 systemTaskStatisticsCommand := &command.SystemTaskStatisticsCommand{} 21 systemTaskStatisticsCommand := &command.SystemTaskStatisticsCommand{}
@@ -28,6 +31,7 @@ func (controller *StatisticsController) SystemTaskStatistics() { @@ -28,6 +31,7 @@ func (controller *StatisticsController) SystemTaskStatistics() {
28 controller.ServeJSON() 31 controller.ServeJSON()
29 } 32 }
30 33
  34 +// 个人任务统计
31 func (controller *StatisticsController) PersonTaskStatistics() { 35 func (controller *StatisticsController) PersonTaskStatistics() {
32 statisticsService := service.NewStatisticsService(nil) 36 statisticsService := service.NewStatisticsService(nil)
33 personTaskStatisticsCommand := &command.PersonTaskStatisticsCommand{} 37 personTaskStatisticsCommand := &command.PersonTaskStatisticsCommand{}
@@ -43,6 +47,7 @@ func (controller *StatisticsController) PersonTaskStatistics() { @@ -43,6 +47,7 @@ func (controller *StatisticsController) PersonTaskStatistics() {
43 controller.ServeJSON() 47 controller.ServeJSON()
44 } 48 }
45 49
  50 +// 个人素币统计
46 func (controller *StatisticsController) PersonSuMoneyStatistics() { 51 func (controller *StatisticsController) PersonSuMoneyStatistics() {
47 statisticsService := service.NewStatisticsService(nil) 52 statisticsService := service.NewStatisticsService(nil)
48 personSuMoneyStatisticsCommand := &command.PersonSuMoneyStatisticsCommand{} 53 personSuMoneyStatisticsCommand := &command.PersonSuMoneyStatisticsCommand{}
@@ -58,6 +63,7 @@ func (controller *StatisticsController) PersonSuMoneyStatistics() { @@ -58,6 +63,7 @@ func (controller *StatisticsController) PersonSuMoneyStatistics() {
58 controller.ServeJSON() 63 controller.ServeJSON()
59 } 64 }
60 65
  66 +// 个人通知统计
61 func (controller *StatisticsController) PersonNotificationStatistics() { 67 func (controller *StatisticsController) PersonNotificationStatistics() {
62 statisticsService := service.NewStatisticsService(nil) 68 statisticsService := service.NewStatisticsService(nil)
63 personNotificationStatisticsCommand := &command.PersonNotificationStatisticsCommand{} 69 personNotificationStatisticsCommand := &command.PersonNotificationStatisticsCommand{}
@@ -72,3 +78,84 @@ func (controller *StatisticsController) PersonNotificationStatistics() { @@ -72,3 +78,84 @@ func (controller *StatisticsController) PersonNotificationStatistics() {
72 controller.Data["json"] = response 78 controller.Data["json"] = response
73 controller.ServeJSON() 79 controller.ServeJSON()
74 } 80 }
  81 +
  82 +// 系统素币统计
  83 +func (controller *StatisticsController) SystemSuMoneyStatistics() {
  84 + statisticsService := service.NewStatisticsService(nil)
  85 + systemSuMoneyStatisticsCommand := &command.SystemSuMoneyStatisticsCommand{}
  86 + json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), systemSuMoneyStatisticsCommand)
  87 + data, err := statisticsService.SystemSuMoneyStatistics(systemSuMoneyStatisticsCommand)
  88 + var response utils.JsonResponse
  89 + if err != nil {
  90 + response = utils.ResponseError(controller.Ctx, err)
  91 + } else {
  92 + response = utils.ResponseData(controller.Ctx, data)
  93 + }
  94 + controller.Data["json"] = response
  95 + controller.ServeJSON()
  96 +}
  97 +
  98 +// 系统现金统计
  99 +func (controller *StatisticsController) SystemCashStatistics() {
  100 + statisticsService := service.NewStatisticsService(nil)
  101 + systemCashStatisticsCommand := &command.SystemCashStatisticsCommand{}
  102 + json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), systemCashStatisticsCommand)
  103 + data, err := statisticsService.SystemCashStatistics(systemCashStatisticsCommand)
  104 + var response utils.JsonResponse
  105 + if err != nil {
  106 + response = utils.ResponseError(controller.Ctx, err)
  107 + } else {
  108 + response = utils.ResponseData(controller.Ctx, data)
  109 + }
  110 + controller.Data["json"] = response
  111 + controller.ServeJSON()
  112 +}
  113 +
  114 +// 获取公司员工财富值
  115 +func (controller *StatisticsController) EmployeesSuMoneyStatistics() {
  116 + statisticsService := service.NewStatisticsService(nil)
  117 + employeesSuMoneyStatisticsCommand := &command.EmployeesSuMoneyStatisticsCommand{}
  118 + json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), employeesSuMoneyStatisticsCommand)
  119 + fmt.Print(employeesSuMoneyStatisticsCommand, "\n")
  120 + data, err := statisticsService.EmployeesSuMoneyStatistics(employeesSuMoneyStatisticsCommand)
  121 + var response utils.JsonResponse
  122 + if err != nil {
  123 + response = utils.ResponseError(controller.Ctx, err)
  124 + } else {
  125 + response = utils.ResponseData(controller.Ctx, data)
  126 + }
  127 + controller.Data["json"] = response
  128 + controller.ServeJSON()
  129 +}
  130 +
  131 +// 获取公司员工贡献值
  132 +func (controller *StatisticsController) EmployeesContributionsStatistics() {
  133 + statisticsService := service.NewStatisticsService(nil)
  134 + employeesContributionsStatisticsCommand := &command.EmployeesContributionsStatisticsCommand{}
  135 + json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), employeesContributionsStatisticsCommand)
  136 + data, err := statisticsService.EmployeesContributionsStatistics(employeesContributionsStatisticsCommand)
  137 + var response utils.JsonResponse
  138 + if err != nil {
  139 + response = utils.ResponseError(controller.Ctx, err)
  140 + } else {
  141 + response = utils.ResponseData(controller.Ctx, data)
  142 + }
  143 + controller.Data["json"] = response
  144 + controller.ServeJSON()
  145 +}
  146 +
  147 +// 公司员工财富值、贡献值排行榜
  148 +func (controller *StatisticsController) RankingListStatistics() {
  149 + statisticsService := service.NewStatisticsService(nil)
  150 + contributionsWealthRankingQuery := &query.ContributionsWealthRankingQuery{}
  151 + json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), contributionsWealthRankingQuery)
  152 + data, err := statisticsService.ContributionsWealthRanking(contributionsWealthRankingQuery)
  153 + var response utils.JsonResponse
  154 + if err != nil {
  155 + response = utils.ResponseError(controller.Ctx, err)
  156 + } else {
  157 + response = utils.ResponseData(controller.Ctx, data)
  158 + }
  159 + controller.Data["json"] = response
  160 + controller.ServeJSON()
  161 +}
@@ -2,18 +2,25 @@ package controllers @@ -2,18 +2,25 @@ package controllers
2 2
3 import ( 3 import (
4 "encoding/json" 4 "encoding/json"
5 - 5 + "fmt"
  6 + "github.com/360EntSecGroup-Skylar/excelize/v2"
6 "github.com/astaxie/beego" 7 "github.com/astaxie/beego"
  8 + "github.com/linmadan/egglib-go/core/application"
7 "github.com/linmadan/egglib-go/web/beego/utils" 9 "github.com/linmadan/egglib-go/web/beego/utils"
8 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/suMoney/command" 10 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/suMoney/command"
9 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/suMoney/query" 11 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/suMoney/query"
10 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/suMoney/service" 12 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/suMoney/service"
  13 + //utility "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/utils"
  14 + "os"
  15 + "path"
  16 + "strconv"
11 ) 17 )
12 18
13 type SuMoneyController struct { 19 type SuMoneyController struct {
14 beego.Controller 20 beego.Controller
15 } 21 }
16 22
  23 +// 操作素币
17 func (controller *SuMoneyController) OperationSuMoney() { 24 func (controller *SuMoneyController) OperationSuMoney() {
18 suMoneyService := service.NewSuMoneyService(nil) 25 suMoneyService := service.NewSuMoneyService(nil)
19 operationSuMoneyCommand := &command.OperationSuMoneyCommand{} 26 operationSuMoneyCommand := &command.OperationSuMoneyCommand{}
@@ -29,6 +36,7 @@ func (controller *SuMoneyController) OperationSuMoney() { @@ -29,6 +36,7 @@ func (controller *SuMoneyController) OperationSuMoney() {
29 controller.ServeJSON() 36 controller.ServeJSON()
30 } 37 }
31 38
  39 +// 获取素币事务记录
32 func (controller *SuMoneyController) GetSuMoneyTransactionRecord() { 40 func (controller *SuMoneyController) GetSuMoneyTransactionRecord() {
33 suMoneyService := service.NewSuMoneyService(nil) 41 suMoneyService := service.NewSuMoneyService(nil)
34 getSuMoneyTransactionRecordQuery := &query.GetSuMoneyTransactionRecordQuery{} 42 getSuMoneyTransactionRecordQuery := &query.GetSuMoneyTransactionRecordQuery{}
@@ -45,6 +53,7 @@ func (controller *SuMoneyController) GetSuMoneyTransactionRecord() { @@ -45,6 +53,7 @@ func (controller *SuMoneyController) GetSuMoneyTransactionRecord() {
45 controller.ServeJSON() 53 controller.ServeJSON()
46 } 54 }
47 55
  56 +// 兑换素币
48 func (controller *SuMoneyController) ExchangeSuMoney() { 57 func (controller *SuMoneyController) ExchangeSuMoney() {
49 suMoneyService := service.NewSuMoneyService(nil) 58 suMoneyService := service.NewSuMoneyService(nil)
50 exchangeSuMoneyCommand := &command.ExchangeSuMoneyCommand{} 59 exchangeSuMoneyCommand := &command.ExchangeSuMoneyCommand{}
@@ -60,9 +69,16 @@ func (controller *SuMoneyController) ExchangeSuMoney() { @@ -60,9 +69,16 @@ func (controller *SuMoneyController) ExchangeSuMoney() {
60 controller.ServeJSON() 69 controller.ServeJSON()
61 } 70 }
62 71
  72 +// 搜索素币事务
63 func (controller *SuMoneyController) SearchSuMoneyTransactionRecord() { 73 func (controller *SuMoneyController) SearchSuMoneyTransactionRecord() {
64 suMoneyService := service.NewSuMoneyService(nil) 74 suMoneyService := service.NewSuMoneyService(nil)
65 searchSuMoneyTransactionRecordCommand := &command.SearchSuMoneyTransactionRecordCommand{} 75 searchSuMoneyTransactionRecordCommand := &command.SearchSuMoneyTransactionRecordCommand{}
  76 + employeeMatchName := controller.GetString("employeeMatchName")
  77 + searchSuMoneyTransactionRecordCommand.EmployeeMatchName = employeeMatchName
  78 + offset, _ := controller.GetInt("offset")
  79 + searchSuMoneyTransactionRecordCommand.Offset = offset
  80 + limit, _ := controller.GetInt("limit")
  81 + searchSuMoneyTransactionRecordCommand.Limit = limit
66 json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), searchSuMoneyTransactionRecordCommand) 82 json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), searchSuMoneyTransactionRecordCommand)
67 data, err := suMoneyService.SearchSuMoneyTransactionRecord(searchSuMoneyTransactionRecordCommand) 83 data, err := suMoneyService.SearchSuMoneyTransactionRecord(searchSuMoneyTransactionRecordCommand)
68 var response utils.JsonResponse 84 var response utils.JsonResponse
@@ -75,6 +91,7 @@ func (controller *SuMoneyController) SearchSuMoneyTransactionRecord() { @@ -75,6 +91,7 @@ func (controller *SuMoneyController) SearchSuMoneyTransactionRecord() {
75 controller.ServeJSON() 91 controller.ServeJSON()
76 } 92 }
77 93
  94 +// 素币事务统计(个人素币收支)
78 func (controller *SuMoneyController) SuMoneyTransactionRecordStatistics() { 95 func (controller *SuMoneyController) SuMoneyTransactionRecordStatistics() {
79 suMoneyService := service.NewSuMoneyService(nil) 96 suMoneyService := service.NewSuMoneyService(nil)
80 suMoneyTransactionRecordStatisticsCommand := &command.SuMoneyTransactionRecordStatisticsCommand{} 97 suMoneyTransactionRecordStatisticsCommand := &command.SuMoneyTransactionRecordStatisticsCommand{}
@@ -89,3 +106,755 @@ func (controller *SuMoneyController) SuMoneyTransactionRecordStatistics() { @@ -89,3 +106,755 @@ func (controller *SuMoneyController) SuMoneyTransactionRecordStatistics() {
89 controller.Data["json"] = response 106 controller.Data["json"] = response
90 controller.ServeJSON() 107 controller.ServeJSON()
91 } 108 }
  109 +
  110 +// 贡献值事务统计(个人贡献值收支)
  111 +func (controller *SuMoneyController) ContributionsTransactionRecordStatistics() {
  112 + suMoneyService := service.NewSuMoneyService(nil)
  113 + contributionsTransactionRecordStatisticsCommand := &command.ContributionsTransactionRecordStatisticsCommand{}
  114 + json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), contributionsTransactionRecordStatisticsCommand)
  115 + data, err := suMoneyService.ContributionsTransactionRecordStatistics(contributionsTransactionRecordStatisticsCommand)
  116 + var response utils.JsonResponse
  117 + if err != nil {
  118 + response = utils.ResponseError(controller.Ctx, err)
  119 + } else {
  120 + response = utils.ResponseData(controller.Ctx, data)
  121 + }
  122 + controller.Data["json"] = response
  123 + controller.ServeJSON()
  124 +}
  125 +
  126 +// 投入现金池
  127 +func (controller *SuMoneyController) CashInput() {
  128 + cashPoolService := service.NewCashPoolService(nil)
  129 + createCashPoolCommand := &command.CreateCashPoolCommand{}
  130 + json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), createCashPoolCommand)
  131 + data, err := cashPoolService.CreateCashPool(createCashPoolCommand)
  132 + var response utils.JsonResponse
  133 + if err != nil {
  134 + response = utils.ResponseError(controller.Ctx, err)
  135 + } else {
  136 + response = utils.ResponseData(controller.Ctx, data)
  137 + }
  138 + controller.Data["json"] = response
  139 + controller.ServeJSON()
  140 +}
  141 +
  142 +// 返回现金池
  143 +func (controller *SuMoneyController) GetCashPool() {
  144 + cashPoolService := service.NewCashPoolService(nil)
  145 + getCashPoolQuery := &query.GetCashPoolQuery{}
  146 + companyId, _ := controller.GetInt64("companyId")
  147 + getCashPoolQuery.CompanyId = companyId
  148 + data, err := cashPoolService.GetCashPool(getCashPoolQuery)
  149 + var response utils.JsonResponse
  150 + if err != nil {
  151 + response = utils.ResponseError(controller.Ctx, err)
  152 + } else {
  153 + response = utils.ResponseData(controller.Ctx, data)
  154 + }
  155 + controller.Data["json"] = response
  156 + controller.ServeJSON()
  157 +}
  158 +
  159 +// 新增兑换活动
  160 +func (controller *SuMoneyController) CreateExchangeActivities () {
  161 + cashPoolService := service.NewCashPoolService(nil)
  162 + createExchangeCashActivityCommand := &command.CreateExchangeCashActivityCommand{}
  163 + json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), createExchangeCashActivityCommand)
  164 + data, err := cashPoolService.CreateExchangeCashActivity(createExchangeCashActivityCommand)
  165 + var response utils.JsonResponse
  166 + if err != nil {
  167 + response = utils.ResponseError(controller.Ctx, err)
  168 + } else {
  169 + response = utils.ResponseData(controller.Ctx, data)
  170 + }
  171 + controller.Data["json"] = response
  172 + controller.ServeJSON()
  173 +}
  174 +
  175 +// 返回兑换活动列表
  176 +func (controller *SuMoneyController) ListExchangeActivities () {
  177 + cashPoolService := service.NewCashPoolService(nil)
  178 + listExchangeCashActivityQuery := &query.ListExchangeCashActivityQuery{}
  179 + companyId, _ := controller.GetInt64("companyId")
  180 + listExchangeCashActivityQuery.CompanyId = companyId
  181 + exchangeCashActivityNameMatch := controller.GetString("activityNameMatch")
  182 + listExchangeCashActivityQuery.ActivityNameMatch = exchangeCashActivityNameMatch
  183 + offset, _ := controller.GetInt("offset")
  184 + listExchangeCashActivityQuery.Offset = offset
  185 + limit, _ := controller.GetInt("limit")
  186 + listExchangeCashActivityQuery.Limit = limit
  187 + isEnd, _ := controller.GetBool("isEnd")
  188 + listExchangeCashActivityQuery.IsEnd = isEnd
  189 + data, err := cashPoolService.ListExchangeCashActivity(listExchangeCashActivityQuery)
  190 + var response utils.JsonResponse
  191 + if err != nil {
  192 + response = utils.ResponseError(controller.Ctx, err)
  193 + } else {
  194 + response = utils.ResponseData(controller.Ctx, data)
  195 + }
  196 + controller.Data["json"] = response
  197 + controller.ServeJSON()
  198 +}
  199 +
  200 +// 搜索返回兑换活动列表
  201 +func (controller *SuMoneyController) SearchExchangeActivities () {
  202 + cashPoolService := service.NewCashPoolService(nil)
  203 + searchExchangeCashActivityCommand := &command.SearchExchangeCashActivityCommand{}
  204 + json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), searchExchangeCashActivityCommand)
  205 + fmt.Printf("命令:%+v\n", searchExchangeCashActivityCommand)
  206 + data, err := cashPoolService.SearchExchangeCashActivity(searchExchangeCashActivityCommand)
  207 + var response utils.JsonResponse
  208 + if err != nil {
  209 + response = utils.ResponseError(controller.Ctx, err)
  210 + } else {
  211 + response = utils.ResponseData(controller.Ctx, data)
  212 + }
  213 + controller.Data["json"] = response
  214 + controller.ServeJSON()
  215 +}
  216 +
  217 +// 返回兑换现金活动
  218 +func (controller *SuMoneyController) GetExchangeCashActivity () {
  219 + cashPoolService := service.NewCashPoolService(nil)
  220 + getExchangeCashActivityQuery := &query.GetExchangeCashActivityQuery{}
  221 + activityId, _ := controller.GetInt64(":activityId")
  222 + getExchangeCashActivityQuery.ExchangeCashActivityId = activityId
  223 + data, err := cashPoolService.GetExchangeCashActivity(getExchangeCashActivityQuery)
  224 + var response utils.JsonResponse
  225 + if err != nil {
  226 + response = utils.ResponseError(controller.Ctx, err)
  227 + } else {
  228 + response = utils.ResponseData(controller.Ctx, data)
  229 + }
  230 + controller.Data["json"] = response
  231 + controller.ServeJSON()
  232 +}
  233 +
  234 +// 更新兑换活动信息
  235 +func (controller *SuMoneyController) UpdateExchangeActivities () {
  236 + cashPoolService := service.NewCashPoolService(nil)
  237 + updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{}
  238 + json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), updateExchangeCashActivityCommand)
  239 + activityId, _ := controller.GetInt64(":activityId")
  240 + updateExchangeCashActivityCommand.ExchangeCashActivityId = activityId
  241 + data, err := cashPoolService.UpdateExchangeCashActivity(updateExchangeCashActivityCommand)
  242 + var response utils.JsonResponse
  243 + if err != nil {
  244 + response = utils.ResponseError(controller.Ctx, err)
  245 + } else {
  246 + response = utils.ResponseData(controller.Ctx, data)
  247 + }
  248 + controller.Data["json"] = response
  249 + controller.ServeJSON()
  250 +}
  251 +
  252 +// 移除兑换活动
  253 +func (controller *SuMoneyController) RemoveExchangeActivities () {
  254 + cashPoolService := service.NewCashPoolService(nil)
  255 + removeExchangeCashActivityCommand := &command.RemoveExchangeCashActivityCommand{}
  256 + activityId, _ := controller.GetInt64(":activityId")
  257 + beego.Info(activityId)
  258 + removeExchangeCashActivityCommand.ActivityId = activityId
  259 + data, err := cashPoolService.RemoveExchangeCashActivity(removeExchangeCashActivityCommand)
  260 + var response utils.JsonResponse
  261 + if err != nil {
  262 + response = utils.ResponseError(controller.Ctx, err)
  263 + } else {
  264 + response = utils.ResponseData(controller.Ctx, data)
  265 + }
  266 + controller.Data["json"] = response
  267 + controller.ServeJSON()
  268 +}
  269 +
  270 +// 返回兑换素币清单列表
  271 +func (controller *SuMoneyController) ListExchangeList () {
  272 + cashPoolService := service.NewCashPoolService(nil)
  273 + listExchangeCashListQuery := &query.ListExchangeCashPersonQuery{}
  274 + activityId, _ := controller.GetInt64("activityId")
  275 + listExchangeCashListQuery.ExchangeCashActivityId = activityId
  276 + companyId, _ := controller.GetInt64("companyId")
  277 + listExchangeCashListQuery.CompanyId = companyId
  278 + exchangeCashPersonNameMatch := controller.GetString("personNameMatch")
  279 + listExchangeCashListQuery.ExchangeCashPersonNameMatch = exchangeCashPersonNameMatch
  280 + offset, _ := controller.GetInt("offset")
  281 + listExchangeCashListQuery.Offset = offset
  282 + limit, _ := controller.GetInt("limit")
  283 + listExchangeCashListQuery.Limit = limit
  284 + data, err := cashPoolService.ListExchangeCashPerson(listExchangeCashListQuery)
  285 + var response utils.JsonResponse
  286 + if err != nil {
  287 + response = utils.ResponseError(controller.Ctx, err)
  288 + } else {
  289 + response = utils.ResponseData(controller.Ctx, data)
  290 + }
  291 + controller.Data["json"] = response
  292 + controller.ServeJSON()
  293 +}
  294 +
  295 +// 新增兑换素币清单
  296 +func (controller *SuMoneyController) CreateExchangeList () {
  297 + cashPoolService := service.NewCashPoolService(nil)
  298 + createExchangeCashPersonCommand := &command.CreateExchangeCashPersonCommand{}
  299 + json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), createExchangeCashPersonCommand)
  300 + data, err := cashPoolService.CreateExchangeCashPerson(createExchangeCashPersonCommand)
  301 + var response utils.JsonResponse
  302 + if err != nil {
  303 + response = utils.ResponseError(controller.Ctx, err)
  304 + } else {
  305 + response = utils.ResponseData(controller.Ctx, data)
  306 + }
  307 + controller.Data["json"] = response
  308 + controller.ServeJSON()
  309 +}
  310 +
  311 +// 更新兑换素币清单
  312 +func (controller *SuMoneyController) UpdateExchangeList () {
  313 + cashPoolService := service.NewCashPoolService(nil)
  314 + updateExchangeCashPersonCommand := &command.UpdateExchangeCashPersonCommand{}
  315 + json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), updateExchangeCashPersonCommand)
  316 + personId, _ := controller.GetInt64(":listId")
  317 + updateExchangeCashPersonCommand.ListId = personId
  318 + data, err := cashPoolService.UpdateExchangeCashPerson(updateExchangeCashPersonCommand)
  319 + var response utils.JsonResponse
  320 + if err != nil {
  321 + response = utils.ResponseError(controller.Ctx, err)
  322 + } else {
  323 + response = utils.ResponseData(controller.Ctx, data)
  324 + }
  325 + controller.Data["json"] = response
  326 + controller.ServeJSON()
  327 +}
  328 +
  329 +// 移除兑换素币清单
  330 +func (controller *SuMoneyController) RemoveExchangeCashPerson() {
  331 + cashPoolService := service.NewCashPoolService(nil)
  332 + removeExchangeCashPersonCommand := &command.RemoveExchangeCashPersonCommand{}
  333 + personId, _ := controller.GetInt64(":listId")
  334 + operatorId, _ := controller.GetInt64("operator")
  335 + removeExchangeCashPersonCommand.ListId = personId
  336 + removeExchangeCashPersonCommand.Operator = operatorId
  337 + data, err := cashPoolService.RemoveExchangeCashPerson(removeExchangeCashPersonCommand)
  338 + var response utils.JsonResponse
  339 + if err != nil {
  340 + response = utils.ResponseError(controller.Ctx, err)
  341 + } else {
  342 + response = utils.ResponseData(controller.Ctx, data)
  343 + }
  344 + controller.Data["json"] = response
  345 + controller.ServeJSON()
  346 +}
  347 +
  348 +// 返回兑换素币清单
  349 +func (controller *SuMoneyController) GetExchangeCashPerson () {
  350 + cashPoolService := service.NewCashPoolService(nil)
  351 + getExchangeCashPersonQuery := &query.GetExchangeCashPersonQuery{}
  352 + listId, _ := controller.GetInt64(":listId")
  353 + getExchangeCashPersonQuery.ExchangeCashPersonId = listId
  354 + data, err := cashPoolService.GetExchangeCashPerson(getExchangeCashPersonQuery)
  355 + var response utils.JsonResponse
  356 + if err != nil {
  357 + response = utils.ResponseError(controller.Ctx, err)
  358 + } else {
  359 + response = utils.ResponseData(controller.Ctx, data)
  360 + }
  361 + controller.Data["json"] = response
  362 + controller.ServeJSON()
  363 +}
  364 +
  365 +// 返回兑换活动截止时间列表
  366 +func (controller *SuMoneyController) ListDeadline() {
  367 + cashPoolService := service.NewCashPoolService(nil)
  368 + listExchangeCashActivityDeadlineQuery := &query.ListExchangeCashActivityDeadlineQuery{}
  369 + companyId, _ := controller.GetInt64("companyId")
  370 + listExchangeCashActivityDeadlineQuery.CompanyId = companyId
  371 + data, err := cashPoolService.ListExchangeCashActivityDeadline(listExchangeCashActivityDeadlineQuery)
  372 + var response utils.JsonResponse
  373 + if err != nil {
  374 + response = utils.ResponseError(controller.Ctx, err)
  375 + } else {
  376 + response = utils.ResponseData(controller.Ctx, data)
  377 + }
  378 + controller.Data["json"] = response
  379 + controller.ServeJSON()
  380 +}
  381 +
  382 +// 返回兑换素币清单排行榜
  383 +func (controller *SuMoneyController) ExchangeCashListRanking() {
  384 + cashPoolService := service.NewCashPoolService(nil)
  385 + exchangeListRankingQuery := &query.ExchangeListRankingQuery{}
  386 + json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), exchangeListRankingQuery)
  387 + data, err := cashPoolService.ExchangeListRanking(exchangeListRankingQuery)
  388 + var response utils.JsonResponse
  389 + if err != nil {
  390 + response = utils.ResponseError(controller.Ctx, err)
  391 + } else {
  392 + response = utils.ResponseData(controller.Ctx, data)
  393 + }
  394 + controller.Data["json"] = response
  395 + controller.ServeJSON()
  396 +}
  397 +
  398 +// 导入兑换素币清单
  399 +func (controller *SuMoneyController) ImportExchangeList () {
  400 + cashPoolService := service.NewCashPoolService(nil)
  401 + where := controller.GetString("where")
  402 + file, h, _ := controller.GetFile("file")
  403 + jsonMap := make(map[string]interface{})
  404 + _ = json.Unmarshal([]byte(where), &jsonMap)
  405 +
  406 + // 错误信息返回
  407 + var response utils.JsonResponse
  408 +
  409 + // 返回字段定义
  410 + ret := map[string]interface{}{}
  411 +
  412 + // 返回信息表头定义
  413 + var tableHeader = [...]string{"员工姓名", "手机号", "已兑换素币", "错误详情"}
  414 +
  415 + // 文件后缀名校验
  416 + ext := path.Ext(h.Filename)
  417 + AllowExtMap := map[string]bool{
  418 + ".xlsx":true,
  419 + }
  420 + if _,ok:=AllowExtMap[ext];!ok{
  421 + err := &application.ServiceError{
  422 + Code: 500,
  423 + Message: "后缀名不符合上传要求",
  424 + }
  425 + response = utils.ResponseError(controller.Ctx, err)
  426 + controller.Data["json"] = response
  427 + controller.ServeJSON()
  428 + return
  429 + }
  430 +
  431 + // 打开文件
  432 + xlsx, err := excelize.OpenReader(file)
  433 + if err != nil {
  434 + fmt.Println(err)
  435 + return
  436 + }
  437 +
  438 + // 文件行数校验
  439 + rows, _ := xlsx.GetRows("Sheet1")
  440 + //fmt.Print(len(rows), "\n")
  441 + if len(rows) > 303 {
  442 + err := &application.ServiceError{
  443 + Code: 500,
  444 + Message: "导入的文件超过300行",
  445 + }
  446 + response = utils.ResponseError(controller.Ctx, err)
  447 + controller.Data["json"] = response
  448 + controller.ServeJSON()
  449 + return
  450 + }
  451 +
  452 + // 空表格判断
  453 + if len(rows) < 4 {
  454 + err := &application.ServiceError{
  455 + Code: 500,
  456 + Message: "当前导入的为空表格",
  457 + }
  458 + response = utils.ResponseError(controller.Ctx, err)
  459 + controller.Data["json"] = response
  460 + controller.ServeJSON()
  461 + return
  462 + }
  463 +
  464 + // 必填项校验
  465 + nullLine := make([]interface{}, 0)
  466 + nullFlag := false
  467 + for i, row := range rows {
  468 + if i > 2 {
  469 + fmt.Print(len(row), "\n")
  470 + if len(row) == 3 {
  471 + var myRow []string = row
  472 + for j, cell := range row {
  473 + if cell == "" || cell == " " {
  474 + myRow[j] = ""
  475 + nullFlag = true
  476 + }
  477 + }
  478 + if nullFlag {
  479 + myRow = append(myRow, "必填项不能为空")
  480 + nullLine = append(nullLine, myRow)
  481 + nullFlag = false
  482 + }
  483 + } else if len(row) < 3 {
  484 + var myRow []string = row
  485 + for i := 0; i < 3 - len(row); i++ {
  486 + myRow = append(myRow, "")
  487 + }
  488 + myRow = append(myRow, "必填项不能为空")
  489 + nullLine = append(nullLine, myRow)
  490 + }
  491 + }
  492 + }
  493 + if len(nullLine) > 0 {
  494 + ret = map[string]interface{}{
  495 + "successCount": 0,
  496 + "fail": map[string]interface{}{
  497 + "tableHeader": tableHeader,
  498 + "tableData": nullLine,
  499 + },
  500 + }
  501 + response = utils.ResponseData(controller.Ctx, ret)
  502 + controller.Data["json"] = response
  503 + controller.ServeJSON()
  504 + return
  505 + }
  506 +
  507 + // 新增失败记录
  508 + failureDataList := make([]interface{}, 0)
  509 +
  510 + // 新增成功计数
  511 + var successDataCount int64
  512 +
  513 + // 导入命令
  514 + var createExchangeCashPersonCommands []*command.CreateExchangeCashPersonCommand
  515 +
  516 + errorLine := make([]interface{}, 0)
  517 + for i, row := range rows {
  518 + if i > 2 && len(row) > 1 {
  519 + // 创建兑换清单命令
  520 + createExchangeCashPersonCommand := &command.CreateExchangeCashPersonCommand{}
  521 + createExchangeCashPersonCommand.ExchangeCashActivityId, err = strconv.ParseInt(jsonMap["activityId"].(string), 10, 64 )
  522 + createExchangeCashPersonCommand.Operator = int64(jsonMap["uid"].(float64))
  523 + createExchangeCashPersonCommand.PersonName = row[0]
  524 + createExchangeCashPersonCommand.PersonAccount = row[1]
  525 + r2, err := strconv.ParseFloat(row[2], 64)
  526 + if err != nil { // 已兑换素币格式不正确
  527 + var myRow []string = row
  528 + myRow = append(myRow, "已兑换素币格式不正确")
  529 + errorLine = append(errorLine, myRow)
  530 + continue
  531 + }
  532 + createExchangeCashPersonCommand.ExchangedSuMoney = r2
  533 + createExchangeCashPersonCommands = append(createExchangeCashPersonCommands, createExchangeCashPersonCommand)
  534 + }
  535 + }
  536 +
  537 + if len(errorLine) > 0 {
  538 + ret = map[string]interface{}{
  539 + "successCount": 0,
  540 + "fail": map[string]interface{}{
  541 + "tableHeader": tableHeader,
  542 + "tableData": errorLine,
  543 + },
  544 + }
  545 + response = utils.ResponseData(controller.Ctx, ret)
  546 + controller.Data["json"] = response
  547 + controller.ServeJSON()
  548 + return
  549 + }
  550 +
  551 + // 创建兑换素币清单
  552 + failureDataList, err = cashPoolService.ImportCreateExchangeCashPerson(createExchangeCashPersonCommands, failureDataList)
  553 + if err != nil { // 导入失败处理
  554 + response = utils.ResponseError(controller.Ctx, err)
  555 + controller.Data["json"] = response
  556 + controller.ServeJSON()
  557 + return
  558 + } else {
  559 + if len(failureDataList) > 0 { // 导入失败返回
  560 + successDataCount = 0
  561 + ret = map[string]interface{}{
  562 + "successCount": successDataCount,
  563 + "fail": map[string]interface{}{
  564 + "tableHeader": tableHeader,
  565 + "tableData": failureDataList,
  566 + },
  567 + }
  568 + } else { // 导入成功返回
  569 + successDataCount = int64(len(rows) - 3 - len(failureDataList))
  570 + if successDataCount == int64(len(rows) - 3) {
  571 + ret = map[string]interface{}{
  572 + "successCount": successDataCount,
  573 + "fail": nil,
  574 + }
  575 + }
  576 + }
  577 + }
  578 +
  579 + response = utils.ResponseData(controller.Ctx, ret)
  580 + controller.Data["json"] = response
  581 + controller.ServeJSON()
  582 + return
  583 +}
  584 +
  585 +// 下载日志
  586 +func (controller *SuMoneyController) LogFile() {
  587 + controller.Ctx.Output.Download("logs/app.log","app.log")
  588 +}
  589 +
  590 +// 导出素币兑换清单,选择导出(ids),增加导出失败信息
  591 +func (controller *SuMoneyController) ExportExchangeList() {
  592 + cashPoolService := service.NewCashPoolService(nil)
  593 + exportExchangeCashListCommand := &command.ExportExchangeCashListCommand{}
  594 + json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), exportExchangeCashListCommand)
  595 + // 列标题
  596 + titles := []string{
  597 + "姓名","手机账号","已兑换现金","已兑换素币",
  598 + }
  599 + // 列单元
  600 + cells := []string{
  601 + "A","B","C","D",
  602 + }
  603 + // 数据源
  604 + var data []map[string]interface{}
  605 + people, err := cashPoolService.ListExchangeCashPersonById(exportExchangeCashListCommand)
  606 + for _, person := range people {
  607 + p := map[string]interface{} {
  608 + "name": person.EmployeeInfo.EmployeeName,
  609 + "account": person.EmployeeInfo.EmployeeAccount,
  610 + "exchanged_cash": person.ExchangedCash,
  611 + "exchanged_su_money": person.ExchangedSuMoney,
  612 + }
  613 + data = append(data, p)
  614 + }
  615 + var response utils.JsonResponse
  616 + if err != nil {
  617 + response = utils.ResponseError(controller.Ctx, err)
  618 + controller.Data["json"] = response
  619 + controller.ServeJSON()
  620 + } else {
  621 + // 新建文件
  622 + f := excelize.NewFile()
  623 + // 新建工作簿
  624 + index := f.NewSheet("Sheet1")
  625 + //列标题赋值
  626 + for column, v := range titles {
  627 + f.SetCellValue("Sheet1", cells[column] + "1", v)
  628 + }
  629 + for lineNum, v := range data { //行数 lineNum 行内容 v
  630 + for columnNum := 0; columnNum < len(v); columnNum ++ {
  631 + cell := cells[columnNum]
  632 + row := strconv.Itoa(lineNum + 2)
  633 + switch cell {
  634 + case "A":
  635 + sheetPosition := cell + row
  636 + f.SetCellValue("Sheet1", sheetPosition, v["name"])
  637 + break
  638 + case "B":
  639 + sheetPosition := cell + row
  640 + f.SetCellValue("Sheet1", sheetPosition, v["account"])
  641 + break
  642 + case "C":
  643 + sheetPosition := cell + row
  644 + f.SetCellValue("Sheet1", sheetPosition, v["exchanged_cash"])
  645 + break
  646 + case "D":
  647 + sheetPosition := cell + row
  648 + f.SetCellValue("Sheet1", sheetPosition, v["exchanged_su_money"])
  649 + break
  650 + }
  651 + }
  652 + }
  653 +
  654 + f.SetActiveSheet(index)
  655 +
  656 + // 创建下载文件夹
  657 + mkErr :=os.Mkdir("download", os.ModePerm)
  658 + if err!=nil{
  659 + fmt.Println(mkErr)
  660 + }
  661 +
  662 + //保存为文件
  663 + f.Path="download/素币兑换清单.xlsx"
  664 + if err := f.Save(); err != nil {
  665 + fmt.Println(err)
  666 + }
  667 +
  668 + controller.Ctx.Output.Download(f.Path,"素币兑换清单.xlsx")
  669 +
  670 + // 下载完成删除文件
  671 + removeErr := os.Remove(f.Path)
  672 + if err != nil {
  673 + fmt.Println(removeErr)
  674 + }
  675 + }
  676 +}
  677 +
  678 +// 导出素币流水
  679 +func (controller *SuMoneyController) ExportSuMoney() {
  680 + suMoneyService := service.NewSuMoneyService(nil)
  681 + exportSuMoneyCommand := &command.ExportSuMoneyCommand{}
  682 + json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), exportSuMoneyCommand)
  683 + // 列标题
  684 + titles := []string{
  685 + "员工姓名","手机账号","当前素币",
  686 + }
  687 + // 列单元
  688 + cells := []string{
  689 + "A","B","C",
  690 + }
  691 + var response utils.JsonResponse
  692 + var data []map[string]interface{}
  693 + records, err := suMoneyService.ListSuMoneyById(exportSuMoneyCommand)
  694 + for _, record := range records {
  695 + p := map[string]interface{} {
  696 + "name": record.EmployeeInfo.EmployeeName,
  697 + "account": record.EmployeeInfo.EmployeeAccount,
  698 + "current_su_money": record.SuMoney,
  699 + }
  700 + data = append(data, p)
  701 + }
  702 + if err != nil {
  703 + response = utils.ResponseError(controller.Ctx, err)
  704 + controller.Data["json"] = response
  705 + controller.ServeJSON()
  706 + } else {
  707 + // 新建文件
  708 + f := excelize.NewFile()
  709 +
  710 + // 新建工作簿
  711 + index := f.NewSheet("Sheet1")
  712 +
  713 + //列标题赋值
  714 + for column, v := range titles {
  715 + f.SetCellValue("Sheet1", cells[column]+"1", v)
  716 + }
  717 +
  718 + for lineNum, v := range data { //行数 lineNum 行内容 v
  719 + for columnNum := 0; columnNum < len(v); columnNum ++ {
  720 + cell := cells[columnNum]
  721 + row := strconv.Itoa(lineNum + 2)
  722 + switch cell {
  723 + case "A":
  724 + sheetPosition := cell + row
  725 + f.SetCellValue("Sheet1", sheetPosition, v["name"])
  726 + break
  727 + case "B":
  728 + sheetPosition := cell + row
  729 + f.SetCellValue("Sheet1", sheetPosition, v["account"])
  730 + break
  731 + case "C":
  732 + sheetPosition := cell + row
  733 + f.SetCellValue("Sheet1", sheetPosition, v["current_su_money"])
  734 + break
  735 + }
  736 + }
  737 + }
  738 +
  739 + f.SetActiveSheet(index)
  740 +
  741 + // 创建下载文件夹
  742 + mkErr :=os.Mkdir("download", os.ModePerm)
  743 + if err!=nil{
  744 + fmt.Println(mkErr)
  745 + }
  746 +
  747 + //保存为文件
  748 + f.Path="download/素币流水.xlsx"
  749 + if err := f.Save(); err != nil {
  750 + fmt.Println(err)
  751 + }
  752 +
  753 + controller.Ctx.Output.Download(f.Path,"素币流水.xlsx")
  754 +
  755 + // 下载完成删除文件
  756 + removeErr := os.Remove(f.Path)
  757 + if err != nil {
  758 + fmt.Println(removeErr)
  759 + }
  760 + }
  761 +}
  762 +
  763 +// 导出素币流水记录
  764 +func (controller *SuMoneyController) ExportSuMoneyTransactionRecord() {
  765 + suMoneyService := service.NewSuMoneyService(nil)
  766 + exportTransactionRecordCommand := &command.ExportTransactionRecordCommand{}
  767 + json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), exportTransactionRecordCommand)
  768 + // 列标题
  769 + titles := []string{
  770 + "员工姓名","当前素币","素币流水","操作时间","操作人",
  771 + }
  772 + // 列单元
  773 + cells := []string{
  774 + "A","B","C","D","E",
  775 + }
  776 + var response utils.JsonResponse
  777 + var data []map[string]interface{}
  778 + records, err := suMoneyService.ListSuMoneyTransactionRecordById(exportTransactionRecordCommand)
  779 + for _, record := range records {
  780 + p := map[string]interface{}{}
  781 + if record.RecordType == 2 || record.RecordType == 3 || record.RecordType == 6 {
  782 + p = map[string]interface{} {
  783 + "name": record.Employee.EmployeeName,
  784 + "current_su_money": record.CurrentSuMoney,
  785 + "record": "+" + fmt.Sprintf("%.2f", record.SuMoney),
  786 + "create_time": record.CreateTime.Local().Format("2006/01/02 15:04:05"),
  787 + "operator": record.Operator.EmployeeName,
  788 + }
  789 + } else {
  790 + p = map[string]interface{} {
  791 + "name": record.Employee.EmployeeName,
  792 + "current_su_money": record.CurrentSuMoney,
  793 + "record": "-" + fmt.Sprintf("%.2f", record.SuMoney),
  794 + "create_time": record.CreateTime.Local().Format("2006/01/02 15:04:05"),
  795 + "operator": record.Operator.EmployeeName,
  796 + }
  797 + }
  798 + data = append(data, p)
  799 + }
  800 + if err != nil {
  801 + response = utils.ResponseError(controller.Ctx, err)
  802 + controller.Data["json"] = response
  803 + controller.ServeJSON()
  804 + } else {
  805 + // 新建文件
  806 + f := excelize.NewFile()
  807 + // 新建工作簿
  808 + index := f.NewSheet("Sheet1")
  809 + //列标题赋值
  810 + for column, v := range titles {
  811 + f.SetCellValue("Sheet1", cells[column]+"1", v)
  812 + }
  813 + for lineNum, v := range data { //行数 lineNum 行内容 v
  814 + for columnNum := 0; columnNum < len(v); columnNum ++ {
  815 + cell := cells[columnNum]
  816 + row := strconv.Itoa(lineNum + 2)
  817 + switch cell {
  818 + case "A":
  819 + sheetPosition := cell + row
  820 + f.SetCellValue("Sheet1", sheetPosition, v["name"])
  821 + break
  822 + case "B":
  823 + sheetPosition := cell + row
  824 + f.SetCellValue("Sheet1", sheetPosition, v["current_su_money"])
  825 + break
  826 + case "C":
  827 + sheetPosition := cell + row
  828 + f.SetCellValue("Sheet1", sheetPosition, v["record"])
  829 + break
  830 + case "D":
  831 + sheetPosition := cell + row
  832 + f.SetCellValue("Sheet1", sheetPosition, v["create_time"])
  833 + break
  834 + case "E":
  835 + sheetPosition := cell + row
  836 + f.SetCellValue("Sheet1", sheetPosition, v["operator"])
  837 + break
  838 + }
  839 + }
  840 + }
  841 + f.SetActiveSheet(index)
  842 + // 创建下载文件夹
  843 + mkErr :=os.Mkdir("download", os.ModePerm)
  844 + if err!=nil{
  845 + fmt.Println(mkErr)
  846 + }
  847 + //保存为文件
  848 + f.Path="download/素币流水记录.xlsx"
  849 + if err := f.Save(); err != nil {
  850 + fmt.Println(err)
  851 + }
  852 + controller.Ctx.Output.Download(f.Path,"素币流水记录.xlsx")
  853 + // 下载完成删除文件
  854 + removeErr := os.Remove(f.Path)
  855 + if err != nil {
  856 + fmt.Println(removeErr)
  857 + }
  858 + }
  859 +}
  860 +
@@ -214,6 +214,22 @@ func (controller *TaskController) UpdateTask() { @@ -214,6 +214,22 @@ func (controller *TaskController) UpdateTask() {
214 controller.ServeJSON() 214 controller.ServeJSON()
215 } 215 }
216 216
  217 +// 更新过期任务状态
  218 +func (controller *TaskController) UpdateTaskStatus() {
  219 + taskService := service.NewTaskService(nil)
  220 + updateTaskCommand := &command.UpdateTaskCommand{}
  221 + json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), updateTaskCommand)
  222 + data, err := taskService.UpdateTaskStatus()
  223 + var response utils.JsonResponse
  224 + if err != nil {
  225 + response = utils.ResponseError(controller.Ctx, err)
  226 + } else {
  227 + response = utils.ResponseData(controller.Ctx, data)
  228 + }
  229 + controller.Data["json"] = response
  230 + controller.ServeJSON()
  231 +}
  232 +
217 func (controller *TaskController) GetTask() { 233 func (controller *TaskController) GetTask() {
218 taskService := service.NewTaskService(nil) 234 taskService := service.NewTaskService(nil)
219 getTaskQuery := &query.GetTaskQuery{} 235 getTaskQuery := &query.GetTaskQuery{}
  1 +package middleware
  2 +
  3 +import (
  4 + "encoding/json"
  5 + "fmt"
  6 + "github.com/astaxie/beego/context"
  7 + "github.com/astaxie/beego/logs"
  8 + "io/ioutil"
  9 + "net/http"
  10 + "time"
  11 +)
  12 +
  13 +func CreateRequstLogFilter(logger *logs.BeeLogger) func(ctx *context.Context) {
  14 + return func(ctx *context.Context) {
  15 + requestId := fmt.Sprintf("%v.%v.%v ", ctx.Input.Method(), ctx.Input.URI(), time.Now().UnixNano())
  16 + ctx.Request.Header.Add("requestId", requestId)
  17 + var body string = "{}"
  18 + if ctx.Input.GetData("requestBody") != nil {
  19 + body = string(ctx.Input.GetData("requestBody").([]byte))
  20 + }
  21 + logger.Debug(fmt.Sprintf("====>Recv User:%v RequestId:%s \n Auth=%v \n BodyData:%s", ctx.Input.GetData("UserId"), requestId, ctx.Input.Header("x-mmm-accesstoken"), body))
  22 + }
  23 +}
  24 +
  25 +func CreateResponseLogFilter(logger *logs.BeeLogger) func(ctx *context.Context) {
  26 + return func(ctx *context.Context) {
  27 + requestId := ctx.Request.Header.Get("requestId")
  28 + body, _ := json.Marshal(ctx.Input.GetData("outputData"))
  29 + if len(body) > 100000 {
  30 + body = body[:100000]
  31 + }
  32 + logger.Debug(fmt.Sprintf("<====Send RequestId:%v BodyData:%s", requestId, body))
  33 + }
  34 +}
  35 +
  36 +func CreateRequestBodyFilter() func(ctx *context.Context) {
  37 + return func(ctx *context.Context) {
  38 + if ctx.Request.Method == http.MethodPost || ctx.Request.Method == http.MethodPut {
  39 + body, _ := ioutil.ReadAll(ctx.Request.Body)
  40 + if len(body) == 0 {
  41 + body = []byte("{}")
  42 + }
  43 + ctx.Input.SetData("requestBody", body)
  44 + ctx.Request.Body.Close()
  45 + }
  46 + }
  47 +}
@@ -11,4 +11,5 @@ func init() { @@ -11,4 +11,5 @@ func init() {
11 beego.Router("/employees/:uid", &controllers.EmployeeController{}, "Get:GetEmployee") 11 beego.Router("/employees/:uid", &controllers.EmployeeController{}, "Get:GetEmployee")
12 beego.Router("/employees/:uid", &controllers.EmployeeController{}, "Delete:RemoveEmployee") 12 beego.Router("/employees/:uid", &controllers.EmployeeController{}, "Delete:RemoveEmployee")
13 beego.Router("/employees/", &controllers.EmployeeController{}, "Get:ListEmployee") 13 beego.Router("/employees/", &controllers.EmployeeController{}, "Get:ListEmployee")
  14 + //beego.Router("/employees/export", &controllers.EmployeeController{}, "Post:ExportSuMoney") // 导出员工素币情况列表
14 } 15 }
  1 +package routers
  2 +
  3 +import (
  4 + "github.com/astaxie/beego"
  5 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/port/beego/controllers"
  6 +)
  7 +
  8 +func init() {
  9 + beego.Router("/list-interval/", &controllers.ListIntervalController{}, "Post:CreateListInterval")
  10 + beego.Router("/list-interval/:listId", &controllers.ListIntervalController{}, "Put:UpdateListInterval")
  11 + beego.Router("/list-interval/:listId", &controllers.ListIntervalController{}, "Get:GetListInterval")
  12 + beego.Router("/list-interval/:listId", &controllers.ListIntervalController{}, "Delete:RemoveListInterval")
  13 + beego.Router("/list-interval/", &controllers.ListIntervalController{}, "Get:ListListInterval")
  14 +}
@@ -6,8 +6,13 @@ import ( @@ -6,8 +6,13 @@ import (
6 ) 6 )
7 7
8 func init() { 8 func init() {
9 - beego.Router("/statistics/system-task", &controllers.StatisticsController{}, "Post:SystemTaskStatistics")  
10 - beego.Router("/statistics/person-task", &controllers.StatisticsController{}, "Post:PersonTaskStatistics")  
11 - beego.Router("/statistics/person-su-money", &controllers.StatisticsController{}, "Post:PersonSuMoneyStatistics")  
12 - beego.Router("/statistics/person-notification", &controllers.StatisticsController{}, "Post:PersonNotificationStatistics") 9 + beego.Router("/statistics/system-task", &controllers.StatisticsController{}, "Post:SystemTaskStatistics") // 系统任务统计
  10 + beego.Router("/statistics/person-task", &controllers.StatisticsController{}, "Post:PersonTaskStatistics") // 个人任务统计
  11 + beego.Router("/statistics/person-su-money", &controllers.StatisticsController{}, "Post:PersonSuMoneyStatistics") // 个人素币统计
  12 + beego.Router("/statistics/person-notification", &controllers.StatisticsController{}, "Post:PersonNotificationStatistics") // 个人通知统计
  13 + beego.Router("/statistics/system-su-money", &controllers.StatisticsController{}, "Post:SystemSuMoneyStatistics") // 系统素币统计
  14 + beego.Router("/statistics/system-cash", &controllers.StatisticsController{}, "Post:SystemCashStatistics") // 系统现金统计
  15 + beego.Router("/statistics/employees-su-money", &controllers.StatisticsController{}, "Post:EmployeesSuMoneyStatistics") // 员工财富值统计
  16 + beego.Router("/statistics/employees-contributions", &controllers.StatisticsController{}, "Post:EmployeesContributionsStatistics") // 员工贡献值统计
  17 + beego.Router("/statistics/employees-ranking-list", &controllers.StatisticsController{}, "Post:RankingListStatistics") // 员工财富值、贡献值排行榜
13 } 18 }
@@ -6,9 +6,38 @@ import ( @@ -6,9 +6,38 @@ import (
6 ) 6 )
7 7
8 func init() { 8 func init() {
9 - beego.Router("/su-money/operation", &controllers.SuMoneyController{}, "Post:OperationSuMoney")  
10 - beego.Router("/su-money/su-money-transaction-records/:suMoneyTransactionRecordId", &controllers.SuMoneyController{}, "Get:GetSuMoneyTransactionRecord")  
11 - beego.Router("/su-money/exchange", &controllers.SuMoneyController{}, "Post:ExchangeSuMoney")  
12 - beego.Router("/su-money/search-su-money-transaction-record", &controllers.SuMoneyController{}, "Post:SearchSuMoneyTransactionRecord")  
13 - beego.Router("/su-money/su-money-transaction-record-statistics", &controllers.SuMoneyController{}, "Post:SuMoneyTransactionRecordStatistics") 9 + /**********************************************素币流水******************************************/
  10 + beego.Router("/su-money/operation", &controllers.SuMoneyController{}, "Post:OperationSuMoney") // 操作素币(增加,扣除,兑换)
  11 + beego.Router("/su-money/su-money-transaction-records/:suMoneyTransactionRecordId", &controllers.SuMoneyController{}, "Get:GetSuMoneyTransactionRecord") // 返回素币事务记录
  12 + beego.Router("/su-money/exchange", &controllers.SuMoneyController{}, "Post:ExchangeSuMoney") // 兑换素币
  13 + beego.Router("/su-money/search-su-money-transaction-record", &controllers.SuMoneyController{}, "Post:SearchSuMoneyTransactionRecord") // 搜索素币事务记录
  14 + beego.Router("/su-money/su-money-transaction-record-statistics", &controllers.SuMoneyController{}, "Post:SuMoneyTransactionRecordStatistics") // 返回素币事务记录统计(个人素币收支)
  15 + beego.Router("/su-money/contributions-transaction-record-statistics", &controllers.SuMoneyController{}, "Post:ContributionsTransactionRecordStatistics") // 返回贡献值事务记录统计(个人贡献值收支)
  16 + beego.Router("/su-money/su-money-transaction-records/export-records", &controllers.SuMoneyController{}, "Post:ExportSuMoneyTransactionRecord") // 导出素币事务记录(素币流水记录)
  17 + beego.Router("/su-money/su-money-transaction-records/export-su-money", &controllers.SuMoneyController{}, "Post:ExportSuMoney") // 导出员工素币流水
  18 +
  19 + /**********************************************现金池*******************************************/
  20 + beego.Router("/cash-pool/input", &controllers.SuMoneyController{}, "Post:CashInput") // 现金池投入
  21 + beego.Router("/cash-pool/cash-pool", &controllers.SuMoneyController{}, "Get:GetCashPool") // 返回现金池统计
  22 +
  23 + /********************************************素币兑换活动***************************************/
  24 + beego.Router("/cash-pool/activity/", &controllers.SuMoneyController{}, "Get:ListExchangeActivities") // 返回兑换活动列表
  25 + beego.Router("/cash-pool/activity/:activityId", &controllers.SuMoneyController{}, "Get:GetExchangeCashActivity") // 返回兑换活动
  26 + beego.Router("/cash-pool/activity/:activityId", &controllers.SuMoneyController{}, "Put:UpdateExchangeActivities") // 编辑兑换活动
  27 + beego.Router("/cash-pool/activity", &controllers.SuMoneyController{}, "Post:CreateExchangeActivities") // 新增兑换活动
  28 + beego.Router("/cash-pool/activity/:activityId", &controllers.SuMoneyController{}, "Delete:RemoveExchangeActivities") // 删除兑换活动
  29 + beego.Router("/cash-pool/activity/deadline-list", &controllers.SuMoneyController{}, "Get:ListDeadline") // 返回兑换活动截止时间列表
  30 + beego.Router("/cash-pool/activity/search-activity", &controllers.SuMoneyController{}, "Post:SearchExchangeActivities") // 搜索兑换活动列表
  31 +
  32 + /********************************************素币兑换清单*************************************/
  33 + beego.Router("/cash-pool/activity/exchange-list", &controllers.SuMoneyController{}, "Get:ListExchangeList") // 返回素币兑换清单
  34 + beego.Router("/cash-pool/activity/exchange-list/:listId", &controllers.SuMoneyController{}, "Get:GetExchangeCashPerson") // 返回素币兑换人员
  35 + beego.Router("/cash-pool/activity/exchange-list", &controllers.SuMoneyController{}, "Post:CreateExchangeList") // 新增素币兑换清单
  36 + beego.Router("/cash-pool/activity/exchange-list/:listId", &controllers.SuMoneyController{}, "Put:UpdateExchangeList") // 编辑素币兑换清单
  37 + beego.Router("/cash-pool/activity/exchange-list/:listId", &controllers.SuMoneyController{}, "Delete:RemoveExchangeCashPerson") // 删除素币兑换清单
  38 + beego.Router("/cash-pool/activity/exchange-list/import", &controllers.SuMoneyController{}, "Post:ImportExchangeList") // 导入素币兑换清单
  39 + beego.Router("/cash-pool/activity/exchange-list/export", &controllers.SuMoneyController{}, "Post:ExportExchangeList") // 导出素币兑换清单
  40 + beego.Router("/cash-pool/activity/exchange-list/ranking", &controllers.SuMoneyController{}, "Post:ExchangeCashListRanking") // 兑换素币清单排行榜
  41 +
  42 + beego.Router("/log", &controllers.SuMoneyController{}, "Get:LogFile") // 系统日志
14 } 43 }
@@ -21,4 +21,5 @@ func init() { @@ -21,4 +21,5 @@ func init() {
21 beego.Router("/tasks/:taskId", &controllers.TaskController{}, "Get:GetTask") 21 beego.Router("/tasks/:taskId", &controllers.TaskController{}, "Get:GetTask")
22 beego.Router("/tasks/:taskId", &controllers.TaskController{}, "Delete:RemoveTask") 22 beego.Router("/tasks/:taskId", &controllers.TaskController{}, "Delete:RemoveTask")
23 beego.Router("/tasks/", &controllers.TaskController{}, "Get:ListTask") 23 beego.Router("/tasks/", &controllers.TaskController{}, "Get:ListTask")
  24 + beego.Router("/tasks/test/expired", &controllers.TaskController{}, "Put:UpdateTaskStatus")
24 } 25 }
  1 +package cash_pool
  2 +
  3 +import (
  4 + "net/http"
  5 +
  6 + "github.com/gavv/httpexpect"
  7 + . "github.com/onsi/ginkgo"
  8 + . "github.com/onsi/gomega"
  9 + pG "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg"
  10 +)
  11 +
  12 +var _ = Describe("投入现金", func() {
  13 + Describe("投入现金并更新现金池数据", func() {
  14 + Context("提交正确的现金值(>=已兑换的现金)", func() {
  15 + It("返回现金池数据", func() {
  16 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  17 + body := map[string]interface{}{
  18 + "cashAmount": 100,
  19 + }
  20 + httpExpect.POST("/cash_pool/input").
  21 + WithJSON(body).
  22 + Expect().
  23 + Status(http.StatusOK).
  24 + JSON().
  25 + Object().
  26 + ContainsKey("code").ValueEqual("code", 0).
  27 + ContainsKey("msg").ValueEqual("msg", "ok").
  28 + ContainsKey("data").Value("data").Object()
  29 + })
  30 + })
  31 + })
  32 + AfterEach(func() {
  33 + _, err := pG.DB.Exec("DELETE FROM ")
  34 + Expect(err).NotTo(HaveOccurred())
  35 + })
  36 +})
  1 +package cash_pool
  2 +
  3 +import (
  4 + "github.com/onsi/ginkgo"
  5 + "github.com/onsi/gomega"
  6 + "net/http"
  7 + "net/http/httptest"
  8 + "testing"
  9 +
  10 + "github.com/astaxie/beego"
  11 + _ "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg"
  12 + _ "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/port/beego"
  13 +)
  14 +
  15 +func TestConfig(t *testing.T) {
  16 + gomega.RegisterFailHandler(ginkgo.Fail)
  17 + ginkgo.RunSpecs(t, "Beego Port Cash Pool Correlations Test Case Suite")
  18 +}
  19 +
  20 +var handler http.Handler
  21 +var server *httptest.Server
  22 +
  23 +var _ = ginkgo.BeforeSuite(func() {
  24 + handler = beego.BeeApp.Handlers
  25 + server = httptest.NewServer(handler)
  26 +})
  27 +
  28 +var _ = ginkgo.AfterSuite(func() {
  29 + server.Close()
  30 +})