正在显示
22 个修改的文件
包含
447 行增加
和
10 行删除
@@ -4,6 +4,7 @@ RUN mkdir -p $APP_DIR | @@ -4,6 +4,7 @@ RUN mkdir -p $APP_DIR | ||
4 | WORKDIR $APP_DIR/ | 4 | WORKDIR $APP_DIR/ |
5 | COPY ./pkg pkg | 5 | COPY ./pkg pkg |
6 | COPY ./config config | 6 | COPY ./config config |
7 | +COPY ./cmd/pdftopng cmd | ||
7 | COPY ./go.mod go.mod | 8 | COPY ./go.mod go.mod |
8 | COPY ./go.sum go.sum | 9 | COPY ./go.sum go.sum |
9 | COPY ./main.go main.go | 10 | COPY ./main.go main.go |
cmd/pdftopng
0 → 100644
不能预览此文件类型
@@ -107,6 +107,10 @@ spec: | @@ -107,6 +107,10 @@ spec: | ||
107 | value: "false" | 107 | value: "false" |
108 | - name: HTTP_PORT | 108 | - name: HTTP_PORT |
109 | value: "8082" | 109 | value: "8082" |
110 | + - name: SUPLUS_ADMIN_BASE_HOST | ||
111 | + value: "http://suplus-admin-base-prd.fjmaimaimai.com" | ||
112 | + - name: ALLIED_CREATION_GATEWAY_HOST | ||
113 | + value: "https://allied-creation-gateway-prd.fjmaimaimai.com" | ||
110 | - name: ALLIED_CREATION_USER_HOST | 114 | - name: ALLIED_CREATION_USER_HOST |
111 | value: "https://allied-creation-user-prd.fjmaimaimai.com" | 115 | value: "https://allied-creation-user-prd.fjmaimaimai.com" |
112 | - name: ALLIED_CREATION_COOPERATION_HOST | 116 | - name: ALLIED_CREATION_COOPERATION_HOST |
@@ -6,11 +6,13 @@ require ( | @@ -6,11 +6,13 @@ require ( | ||
6 | github.com/GeeTeam/gt3-golang-sdk v0.0.0-20200116043922-446ca8a507d2 | 6 | github.com/GeeTeam/gt3-golang-sdk v0.0.0-20200116043922-446ca8a507d2 |
7 | github.com/beego/beego/v2 v2.0.1 | 7 | github.com/beego/beego/v2 v2.0.1 |
8 | github.com/dgrijalva/jwt-go v3.2.0+incompatible | 8 | github.com/dgrijalva/jwt-go v3.2.0+incompatible |
9 | + github.com/disintegration/imaging v1.6.2 | ||
9 | github.com/forgoer/openssl v0.0.0-20210828150411-6c5378b5b719 | 10 | github.com/forgoer/openssl v0.0.0-20210828150411-6c5378b5b719 |
10 | github.com/go-pg/pg/v10 v10.10.1 | 11 | github.com/go-pg/pg/v10 v10.10.1 |
11 | github.com/go-redis/redis v6.15.7+incompatible | 12 | github.com/go-redis/redis v6.15.7+incompatible |
12 | github.com/google/uuid v1.1.1 | 13 | github.com/google/uuid v1.1.1 |
13 | github.com/linmadan/egglib-go v0.0.0-20210827085852-177fa745932d | 14 | github.com/linmadan/egglib-go v0.0.0-20210827085852-177fa745932d |
15 | + github.com/pdfcpu/pdfcpu v0.3.13 | ||
14 | github.com/stretchr/testify v1.7.0 | 16 | github.com/stretchr/testify v1.7.0 |
15 | github.com/tal-tech/go-queue v1.0.5 | 17 | github.com/tal-tech/go-queue v1.0.5 |
16 | golang.org/x/text v0.3.6 | 18 | golang.org/x/text v0.3.6 |
@@ -58,6 +58,8 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs | @@ -58,6 +58,8 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs | ||
58 | github.com/dchest/siphash v1.2.1/go.mod h1:q+IRvb2gOSrUnYoPqHiyHXS0FOBBOdl6tONBlVnOnt4= | 58 | github.com/dchest/siphash v1.2.1/go.mod h1:q+IRvb2gOSrUnYoPqHiyHXS0FOBBOdl6tONBlVnOnt4= |
59 | github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= | 59 | github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= |
60 | github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= | 60 | github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= |
61 | +github.com/disintegration/imaging v1.6.2 h1:w1LecBlG2Lnp8B3jk5zSuNqd7b4DXhcjwek1ei82L+c= | ||
62 | +github.com/disintegration/imaging v1.6.2/go.mod h1:44/5580QXChDfwIclfc/PCwrr44amcmDAg8hxG0Ewe4= | ||
61 | github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= | 63 | github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= |
62 | github.com/eapache/go-resiliency v1.1.0 h1:1NtRmCAqadE2FN4ZcN6g90TP3uk8cg9rn9eNK2197aU= | 64 | github.com/eapache/go-resiliency v1.1.0 h1:1NtRmCAqadE2FN4ZcN6g90TP3uk8cg9rn9eNK2197aU= |
63 | github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs= | 65 | github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs= |
@@ -163,6 +165,11 @@ github.com/hashicorp/go-uuid v1.0.1 h1:fv1ep09latC32wFoVwnqcnKJGnMSdBanPczbHAYm1 | @@ -163,6 +165,11 @@ github.com/hashicorp/go-uuid v1.0.1 h1:fv1ep09latC32wFoVwnqcnKJGnMSdBanPczbHAYm1 | ||
163 | github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= | 165 | github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= |
164 | github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc= | 166 | github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc= |
165 | github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= | 167 | github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= |
168 | +github.com/hhrutter/lzw v0.0.0-20190827003112-58b82c5a41cc/go.mod h1:yJBvOcu1wLQ9q9XZmfiPfur+3dQJuIhYQsMGLYcItZk= | ||
169 | +github.com/hhrutter/lzw v0.0.0-20190829144645-6f07a24e8650 h1:1yY/RQWNSBjJe2GDCIYoLmpWVidrooriUr4QS/zaATQ= | ||
170 | +github.com/hhrutter/lzw v0.0.0-20190829144645-6f07a24e8650/go.mod h1:yJBvOcu1wLQ9q9XZmfiPfur+3dQJuIhYQsMGLYcItZk= | ||
171 | +github.com/hhrutter/tiff v0.0.0-20190829141212-736cae8d0bc7 h1:o1wMw7uTNyA58IlEdDpxIrtFHTgnvYzA8sCQz8luv94= | ||
172 | +github.com/hhrutter/tiff v0.0.0-20190829141212-736cae8d0bc7/go.mod h1:WkUxfS2JUu3qPo6tRld7ISb8HiC0gVSU91kooBMDVok= | ||
166 | github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= | 173 | github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= |
167 | github.com/iancoleman/strcase v0.0.0-20191112232945-16388991a334/go.mod h1:SK73tn/9oHe+/Y0h39VT4UCxmurVJkR5NA7kMEAOgSE= | 174 | github.com/iancoleman/strcase v0.0.0-20191112232945-16388991a334/go.mod h1:SK73tn/9oHe+/Y0h39VT4UCxmurVJkR5NA7kMEAOgSE= |
168 | github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= | 175 | github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= |
@@ -248,6 +255,8 @@ github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1y | @@ -248,6 +255,8 @@ github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1y | ||
248 | github.com/onsi/gomega v1.10.3 h1:gph6h/qe9GSUw1NhH1gp+qb+h8rXD8Cy60Z32Qw3ELA= | 255 | github.com/onsi/gomega v1.10.3 h1:gph6h/qe9GSUw1NhH1gp+qb+h8rXD8Cy60Z32Qw3ELA= |
249 | github.com/onsi/gomega v1.10.3/go.mod h1:V9xEwhxec5O8UDM77eCW8vLymOMltsqPVYWrpDsH8xc= | 256 | github.com/onsi/gomega v1.10.3/go.mod h1:V9xEwhxec5O8UDM77eCW8vLymOMltsqPVYWrpDsH8xc= |
250 | github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc= | 257 | github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc= |
258 | +github.com/pdfcpu/pdfcpu v0.3.13 h1:VFon2Yo1PJt+sA57vPAeXWGLSZ7Ux3Jl4h02M0+s3dg= | ||
259 | +github.com/pdfcpu/pdfcpu v0.3.13/go.mod h1:UJc5xsXg0fpmjp1zOPdyYcAQArc/Zf3V0nv5URe+9fg= | ||
251 | github.com/pelletier/go-toml v1.0.1/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= | 260 | github.com/pelletier/go-toml v1.0.1/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= |
252 | github.com/pelletier/go-toml v1.8.1/go.mod h1:T2/BmBdy8dvIRq1a/8aqjN41wvWlN4lrapLU/GW4pbc= | 261 | github.com/pelletier/go-toml v1.8.1/go.mod h1:T2/BmBdy8dvIRq1a/8aqjN41wvWlN4lrapLU/GW4pbc= |
253 | github.com/peterh/liner v1.0.1-0.20171122030339-3681c2a91233/go.mod h1:xIteQHvHuaLYG9IFj6mSxM0fCKrs34IrEQUhOYuGPHc= | 262 | github.com/peterh/liner v1.0.1-0.20171122030339-3681c2a91233/go.mod h1:xIteQHvHuaLYG9IFj6mSxM0fCKrs34IrEQUhOYuGPHc= |
@@ -385,6 +394,8 @@ golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm | @@ -385,6 +394,8 @@ golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm | ||
385 | golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97 h1:/UOmuWzQfxxo9UtlXMwuQU8CMgg1eZXqTRwkSQJWKOI= | 394 | golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97 h1:/UOmuWzQfxxo9UtlXMwuQU8CMgg1eZXqTRwkSQJWKOI= |
386 | golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= | 395 | golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= |
387 | golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= | 396 | golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= |
397 | +golang.org/x/image v0.0.0-20190823064033-3a9bac650e44/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= | ||
398 | +golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= | ||
388 | golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb h1:fqpd0EBDzlHRCjiphRR5Zo/RSWWQlWv34418dnEixWk= | 399 | golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb h1:fqpd0EBDzlHRCjiphRR5Zo/RSWWQlWv34418dnEixWk= |
389 | golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= | 400 | golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= |
390 | golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= | 401 | golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= |
@@ -552,8 +563,9 @@ gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= | @@ -552,8 +563,9 @@ gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= | ||
552 | gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= | 563 | gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= |
553 | gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= | 564 | gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= |
554 | gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= | 565 | gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= |
555 | -gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU= | ||
556 | gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= | 566 | gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= |
567 | +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= | ||
568 | +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= | ||
557 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= | 569 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= |
558 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= | 570 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
559 | honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= | 571 | honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= |
@@ -8,6 +8,7 @@ import ( | @@ -8,6 +8,7 @@ import ( | ||
8 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/cache" | 8 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/cache" |
9 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/domainService" | 9 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/domainService" |
10 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log" | 10 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log" |
11 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/util/blur" | ||
11 | 12 | ||
12 | _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/port/beego" | 13 | _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/port/beego" |
13 | ) | 14 | ) |
@@ -24,6 +25,6 @@ func main() { | @@ -24,6 +25,6 @@ func main() { | ||
24 | } | 25 | } |
25 | 26 | ||
26 | broker.RegisterDefaultPusherClient(constant.KAFKA_HOST, constant.TOPIC_UP_BLOCK_CHAIN) | 27 | broker.RegisterDefaultPusherClient(constant.KAFKA_HOST, constant.TOPIC_UP_BLOCK_CHAIN) |
27 | - | 28 | + blur.InitDefaultConfig() |
28 | web.Run() | 29 | web.Run() |
29 | } | 30 | } |
pkg/application/mobile/cooperation/command/cp_search_cooperation_project_shared_info_attachment.go
0 → 100644
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/beego/beego/v2/core/validation" | ||
7 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain" | ||
8 | +) | ||
9 | + | ||
10 | +type PersonCooperationProjectSharedInfoAttachmentQuery struct { | ||
11 | + //操作人 | ||
12 | + Operator domain.Operator `json:"-"` | ||
13 | + // 用户 | ||
14 | + UserId int64 `json:"userId" valid:"Required"` | ||
15 | + // 项目ID | ||
16 | + ProjectId int64 `json:"cooperationProjectId" valid:"Required"` | ||
17 | + // 合约ID | ||
18 | + ContractId int64 `json:"cooperationContractId" valid:"Required"` | ||
19 | + // 附件类型 1:合约附件 2:支付凭证 | ||
20 | + AttachmentType int `json:"attachmentType" valid:"Required"` | ||
21 | +} | ||
22 | + | ||
23 | +func (updateCooperationProjectCommand *PersonCooperationProjectSharedInfoAttachmentQuery) Valid(validation *validation.Validation) { | ||
24 | +} | ||
25 | + | ||
26 | +func (updateCooperationProjectCommand *PersonCooperationProjectSharedInfoAttachmentQuery) ValidateCommand() error { | ||
27 | + valid := validation.Validation{} | ||
28 | + b, err := valid.Valid(updateCooperationProjectCommand) | ||
29 | + if err != nil { | ||
30 | + return err | ||
31 | + } | ||
32 | + if !b { | ||
33 | + for _, validErr := range valid.Errors { | ||
34 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
35 | + } | ||
36 | + } | ||
37 | + return nil | ||
38 | +} |
1 | package service | 1 | package service |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/constant" | ||
4 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain" | 5 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain" |
5 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user" | 6 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user" |
7 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log" | ||
8 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/util/blur" | ||
6 | "strconv" | 9 | "strconv" |
10 | + "strings" | ||
7 | 11 | ||
8 | "github.com/linmadan/egglib-go/core/application" | 12 | "github.com/linmadan/egglib-go/core/application" |
9 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/mobile/cooperation/command" | 13 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/mobile/cooperation/command" |
@@ -221,6 +225,42 @@ func (srv CooperationProjectService) PersonSearchCooperationProjectShareInfo(pro | @@ -221,6 +225,42 @@ func (srv CooperationProjectService) PersonSearchCooperationProjectShareInfo(pro | ||
221 | return result, nil | 225 | return result, nil |
222 | } | 226 | } |
223 | 227 | ||
228 | +func (srv CooperationProjectService) PersonSearchCooperationProjectShareInfoAttachment(projectQuery *command.PersonCooperationProjectSharedInfoAttachmentQuery) (interface{}, error) { | ||
229 | + creationCooperationGateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation( | ||
230 | + projectQuery.Operator) | ||
231 | + response := struct { | ||
232 | + Attachment *domain.Attachment `json:"attachment"` | ||
233 | + UserBaseId int64 `json:"userBaseId"` | ||
234 | + }{} | ||
235 | + err := creationCooperationGateway.CooperationStatisticsWithObject( | ||
236 | + allied_creation_cooperation.PersonCooperationProjectSharedInfoAttachment, | ||
237 | + map[string]interface{}{ | ||
238 | + "userId": projectQuery.UserId, | ||
239 | + "cooperationContractId": projectQuery.ContractId, | ||
240 | + "cooperationProjectId": projectQuery.ProjectId, | ||
241 | + "attachmentType": projectQuery.AttachmentType, | ||
242 | + }, &response, | ||
243 | + ) | ||
244 | + if err != nil { | ||
245 | + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | ||
246 | + } | ||
247 | + // 不是本人查看需要做模糊处理 | ||
248 | + if response.UserBaseId != projectQuery.Operator.UserBaseId { | ||
249 | + file, err := blur.FileBlur(response.Attachment.Url, true) | ||
250 | + if err != nil { // || len(file)==0 | ||
251 | + log.Logger.Error(err.Error()) | ||
252 | + return nil, application.ThrowError(application.BUSINESS_ERROR, "文件加载错误,请重试") | ||
253 | + } | ||
254 | + if !(strings.HasPrefix(file, "http") || strings.HasPrefix(file, "https")) { | ||
255 | + file = constant.ALLIED_CREATION_GATEWAY_HOST + "/" + file | ||
256 | + } | ||
257 | + response.Attachment.Url = file | ||
258 | + } | ||
259 | + return map[string]interface{}{ | ||
260 | + "attachment": response.Attachment, | ||
261 | + }, nil | ||
262 | +} | ||
263 | + | ||
224 | // PersonSearchCooperationProject 共创用户获取共创项目列表 | 264 | // PersonSearchCooperationProject 共创用户获取共创项目列表 |
225 | func (srv CooperationProjectService) PersonSearchCooperationProjectStarred(projectQuery *command.PersonSearchCooperationProjectQuery) (int, interface{}, error) { | 265 | func (srv CooperationProjectService) PersonSearchCooperationProjectStarred(projectQuery *command.PersonSearchCooperationProjectQuery) (int, interface{}, error) { |
226 | //extQueries := extQuires(projectQuery.Operator) | 266 | //extQueries := extQuires(projectQuery.Operator) |
@@ -183,7 +183,7 @@ func (srv PersonStatisticsService) CooperationProjectRecommend(projectQuery *com | @@ -183,7 +183,7 @@ func (srv PersonStatisticsService) CooperationProjectRecommend(projectQuery *com | ||
183 | PageNumber: projectQuery.PageNumber + 1, | 183 | PageNumber: projectQuery.PageNumber + 1, |
184 | PageSize: projectQuery.PageSize, | 184 | PageSize: projectQuery.PageSize, |
185 | CooperationProjectUndertakerType: 3, | 185 | CooperationProjectUndertakerType: 3, |
186 | - Status: 1, | 186 | + //Status: 1, |
187 | IsSkipFetchProjectModel: true, | 187 | IsSkipFetchProjectModel: true, |
188 | // Status: 1, | 188 | // Status: 1, |
189 | SortByStatus: 1, | 189 | SortByStatus: 1, |
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain" | ||
6 | + "reflect" | ||
7 | + "strings" | ||
8 | + | ||
9 | + "github.com/beego/beego/v2/core/validation" | ||
10 | +) | ||
11 | + | ||
12 | +type UpdateFavoriteCommand struct { | ||
13 | + Operator domain.Operator `json:"-"` | ||
14 | + | ||
15 | + //UserBaseId int64 `json:"userBaseId" ` | ||
16 | + // 菜单编码列表 | ||
17 | + Item string `json:"item" valid:"Required"` | ||
18 | + // 项唯一标识 | ||
19 | + ItemId int64 `cname:"项唯一标识" json:"itemId" valid:"Required"` | ||
20 | + // 用户Id 用户唯一标识 | ||
21 | + Action int64 `cname:"操作类型 1:关注 2:取消关注 " json:"action" valid:"Required"` | ||
22 | +} | ||
23 | + | ||
24 | +func (UpdateFavoriteCommand *UpdateFavoriteCommand) Valid(validation *validation.Validation) { | ||
25 | + //validation.SetError("CustomValid", "未实现的自定义认证") | ||
26 | +} | ||
27 | + | ||
28 | +func (UpdateFavoriteCommand *UpdateFavoriteCommand) ValidateCommand() error { | ||
29 | + valid := validation.Validation{} | ||
30 | + b, err := valid.Valid(UpdateFavoriteCommand) | ||
31 | + if err != nil { | ||
32 | + return err | ||
33 | + } | ||
34 | + if !b { | ||
35 | + elem := reflect.TypeOf(UpdateFavoriteCommand).Elem() | ||
36 | + for _, validErr := range valid.Errors { | ||
37 | + field, isExist := elem.FieldByName(validErr.Field) | ||
38 | + if isExist { | ||
39 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
40 | + } else { | ||
41 | + return fmt.Errorf(validErr.Message) | ||
42 | + } | ||
43 | + } | ||
44 | + } | ||
45 | + return nil | ||
46 | +} |
@@ -284,3 +284,26 @@ func (srv UserService) CooperationOrg(operator domain.Operator) (interface{}, er | @@ -284,3 +284,26 @@ func (srv UserService) CooperationOrg(operator domain.Operator) (interface{}, er | ||
284 | "orgs": ret, | 284 | "orgs": ret, |
285 | }, nil | 285 | }, nil |
286 | } | 286 | } |
287 | + | ||
288 | +// 设置收藏菜单 | ||
289 | +func (srv UserService) UpdateFavorite(menuFavoriteCommand *command.UpdateFavoriteCommand) (interface{}, error) { | ||
290 | + if err := menuFavoriteCommand.ValidateCommand(); err != nil { | ||
291 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
292 | + } | ||
293 | + if menuFavoriteCommand.Operator.UserBaseId == 0 { | ||
294 | + return nil, application.ThrowError(application.ARG_ERROR, "用户未登录") | ||
295 | + } | ||
296 | + creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser( | ||
297 | + menuFavoriteCommand.Operator, | ||
298 | + ) | ||
299 | + result, err := creationUserGateway.FavoriteUpadate(allied_creation_user.ReqFavoriteUpdate{ | ||
300 | + UserBaseId: menuFavoriteCommand.Operator.UserBaseId, | ||
301 | + Item: menuFavoriteCommand.Item, | ||
302 | + Action: menuFavoriteCommand.Action, | ||
303 | + ItemId: menuFavoriteCommand.ItemId, | ||
304 | + }) | ||
305 | + if err != nil { | ||
306 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
307 | + } | ||
308 | + return result, nil | ||
309 | +} |
@@ -13,8 +13,10 @@ var LOG_FRAMEWORK = "beego" // beego logrus | @@ -13,8 +13,10 @@ var LOG_FRAMEWORK = "beego" // beego logrus | ||
13 | var LOG_FILE = "app.log" | 13 | var LOG_FILE = "app.log" |
14 | var LOG_PREFIX = "[allied-creation-gateway]" | 14 | var LOG_PREFIX = "[allied-creation-gateway]" |
15 | 15 | ||
16 | +var FileStatic = "./static" | ||
17 | + | ||
16 | var HTTP_PORT int = 8083 | 18 | var HTTP_PORT int = 8083 |
17 | -var ALLIED_CREATION_GATEWAY_HOST = "https://allied-creation-gateway-dev.fjmaimaimai.com" | 19 | +var ALLIED_CREATION_GATEWAY_HOST = "http://localhost:8080" |
18 | 20 | ||
19 | //天联共创基础模块 | 21 | //天联共创基础模块 |
20 | var ALLIED_CREATION_BASIC_HOST = "http://localhost:8080" //"http://allied-creation-basic-dev.fjmaimaimai.com" | 22 | var ALLIED_CREATION_BASIC_HOST = "http://localhost:8080" //"http://allied-creation-basic-dev.fjmaimaimai.com" |
@@ -41,6 +41,8 @@ const ( | @@ -41,6 +41,8 @@ const ( | ||
41 | PersonCompanyPaymentHistoryStatistics = "PersonCompanyPaymentHistoryStatistics" | 41 | PersonCompanyPaymentHistoryStatistics = "PersonCompanyPaymentHistoryStatistics" |
42 | // 个人 - 共创项目共享信息数据 | 42 | // 个人 - 共创项目共享信息数据 |
43 | PersonCooperationProjectSharedInfo = "PersonCooperationProjectSharedInfo" | 43 | PersonCooperationProjectSharedInfo = "PersonCooperationProjectSharedInfo" |
44 | + // 个人 - 共创项目共享信息数据 - 附件 | ||
45 | + PersonCooperationProjectSharedInfoAttachment = "PersonCooperationProjectSharedInfoAttachment" | ||
44 | 46 | ||
45 | // 账期结算单统计 | 47 | // 账期结算单统计 |
46 | CreditAccountStatistics = "CreditAccountStatistics" | 48 | CreditAccountStatistics = "CreditAccountStatistics" |
@@ -154,3 +156,37 @@ func (gateway HttplibAlliedCreationCooperation) RelevantCooperationContractNumbe | @@ -154,3 +156,37 @@ func (gateway HttplibAlliedCreationCooperation) RelevantCooperationContractNumbe | ||
154 | err = gateway.GetResponseData(result, &data) | 156 | err = gateway.GetResponseData(result, &data) |
155 | return data, err | 157 | return data, err |
156 | } | 158 | } |
159 | + | ||
160 | +// CooperationStatistics 共创统计 | ||
161 | +func (gateway HttplibAlliedCreationCooperation) CooperationStatisticsWithObject(action string, queryOptions interface{}, object interface{}) error { | ||
162 | + url := gateway.baseUrL + "/cooperation-statistics" | ||
163 | + method := "post" | ||
164 | + req := gateway.CreateRequest(url, method) | ||
165 | + log.Logger.Debug("向业务模块请求数据:共创统计。", map[string]interface{}{ | ||
166 | + "api": method + ":" + url, | ||
167 | + "param": queryOptions, | ||
168 | + }) | ||
169 | + param := map[string]interface{}{ | ||
170 | + "action": action, | ||
171 | + "queryOptions": queryOptions, | ||
172 | + } | ||
173 | + req, err := req.JSONBody(param) | ||
174 | + if err != nil { | ||
175 | + return fmt.Errorf("请求共创统计失败:%w", err) | ||
176 | + } | ||
177 | + | ||
178 | + byteResult, err := req.Bytes() | ||
179 | + if err != nil { | ||
180 | + return fmt.Errorf("获取共创统计失败:%w", err) | ||
181 | + } | ||
182 | + log.Logger.Debug("获取业务模块请求数据:共创统计。", map[string]interface{}{ | ||
183 | + "result": string(byteResult), | ||
184 | + }) | ||
185 | + var result service_gateway.GatewayResponse | ||
186 | + err = json.Unmarshal(byteResult, &result) | ||
187 | + if err != nil { | ||
188 | + return fmt.Errorf("解析共创统计:%w", err) | ||
189 | + } | ||
190 | + err = gateway.GetResponseData(result, &object) | ||
191 | + return err | ||
192 | +} |
@@ -101,3 +101,33 @@ func (gateway HttplibAlliedCreationUser) FavoriteMenusGet(param ReqFavoriteMenus | @@ -101,3 +101,33 @@ func (gateway HttplibAlliedCreationUser) FavoriteMenusGet(param ReqFavoriteMenus | ||
101 | err = gateway.GetResponseData(result, &data) | 101 | err = gateway.GetResponseData(result, &data) |
102 | return &data, err | 102 | return &data, err |
103 | } | 103 | } |
104 | + | ||
105 | +func (gateway HttplibAlliedCreationUser) FavoriteUpadate(param ReqFavoriteUpdate) (*DataFavoriteUpdate, error) { | ||
106 | + url := gateway.baseUrL + "/user-base/favorite" | ||
107 | + method := "post" | ||
108 | + req := gateway.CreateRequest(url, method) | ||
109 | + log.Logger.Debug("向用户模块请求数据:更新我喜欢。", map[string]interface{}{ | ||
110 | + "api": method + ":" + url, | ||
111 | + "param": param, | ||
112 | + }) | ||
113 | + req, err := req.JSONBody(param) | ||
114 | + if err != nil { | ||
115 | + return nil, fmt.Errorf("请求更新我喜欢失败:%w", err) | ||
116 | + } | ||
117 | + | ||
118 | + byteResult, err := req.Bytes() | ||
119 | + if err != nil { | ||
120 | + return nil, fmt.Errorf("获取更新我喜欢失败:%w", err) | ||
121 | + } | ||
122 | + log.Logger.Debug("获取用户模块请求数据:更新我喜欢。", map[string]interface{}{ | ||
123 | + "result": string(byteResult), | ||
124 | + }) | ||
125 | + var result service_gateway.GatewayResponse | ||
126 | + err = json.Unmarshal(byteResult, &result) | ||
127 | + if err != nil { | ||
128 | + return nil, fmt.Errorf("解析更新我喜欢:%w", err) | ||
129 | + } | ||
130 | + var data DataFavoriteUpdate | ||
131 | + err = gateway.GetResponseData(result, &data) | ||
132 | + return &data, err | ||
133 | +} |
@@ -34,3 +34,18 @@ type ( | @@ -34,3 +34,18 @@ type ( | ||
34 | FavoriteMenus []string `json:"favoriteMenus"` | 34 | FavoriteMenus []string `json:"favoriteMenus"` |
35 | } | 35 | } |
36 | ) | 36 | ) |
37 | + | ||
38 | +type ( | ||
39 | + ReqFavoriteUpdate struct { | ||
40 | + UserBaseId int64 `json:"userBaseId" valid:"Required"` | ||
41 | + // 菜单编码列表 | ||
42 | + Item string `json:"item" valid:"Required"` | ||
43 | + // 项唯一标识 | ||
44 | + ItemId int64 `cname:"项唯一标识" json:"itemId" valid:"Required"` | ||
45 | + // 用户Id 用户唯一标识 | ||
46 | + Action int64 `cname:"操作类型 1:关注 2:取消关注 " json:"action" valid:"Required"` | ||
47 | + } | ||
48 | + | ||
49 | + DataFavoriteUpdate struct { | ||
50 | + } | ||
51 | +) |
@@ -255,15 +255,28 @@ func (controller *CooperationController) PersonSearchCooperationProjectStarred() | @@ -255,15 +255,28 @@ func (controller *CooperationController) PersonSearchCooperationProjectStarred() | ||
255 | 255 | ||
256 | func (controller *CooperationController) PersonCooperationProjectSharedInfo() { | 256 | func (controller *CooperationController) PersonCooperationProjectSharedInfo() { |
257 | svr := service.CooperationProjectService{} | 257 | svr := service.CooperationProjectService{} |
258 | - cmd := &command.PersonSearchCooperationProjectQuery{} | 258 | + cmd := &command.GetCooperationProjectQuery{} |
259 | err := controller.Unmarshal(cmd) | 259 | err := controller.Unmarshal(cmd) |
260 | if err != nil { | 260 | if err != nil { |
261 | controller.Response(nil, err) | 261 | controller.Response(nil, err) |
262 | return | 262 | return |
263 | } | 263 | } |
264 | cmd.Operator = controller.GetOperator() | 264 | cmd.Operator = controller.GetOperator() |
265 | - total, data, err := svr.PersonSearchCooperationProject(cmd) | ||
266 | - controller.ReturnPageListData(int64(total), data, err, cmd.PageNumber) | 265 | + data, err := svr.PersonSearchCooperationProjectShareInfo(cmd) |
266 | + controller.Response(data, err) | ||
267 | +} | ||
268 | + | ||
269 | +func (controller *CooperationController) PersonCooperationProjectSharedInfoAttachment() { | ||
270 | + svr := service.CooperationProjectService{} | ||
271 | + cmd := &command.PersonCooperationProjectSharedInfoAttachmentQuery{} | ||
272 | + err := controller.Unmarshal(cmd) | ||
273 | + if err != nil { | ||
274 | + controller.Response(nil, err) | ||
275 | + return | ||
276 | + } | ||
277 | + cmd.Operator = controller.GetOperator() | ||
278 | + data, err := svr.PersonSearchCooperationProjectShareInfoAttachment(cmd) | ||
279 | + controller.Response(data, err) | ||
267 | } | 280 | } |
268 | 281 | ||
269 | //func (controller *CooperationController) PersonRecommendCooperationProject() { | 282 | //func (controller *CooperationController) PersonRecommendCooperationProject() { |
@@ -148,13 +148,13 @@ func (controller *UserController) CooperationOrg() { | @@ -148,13 +148,13 @@ func (controller *UserController) CooperationOrg() { | ||
148 | 148 | ||
149 | func (controller *UserController) UpdateOrgFavorite() { | 149 | func (controller *UserController) UpdateOrgFavorite() { |
150 | svr := service.UserService{} | 150 | svr := service.UserService{} |
151 | - cmd := &command.MenuFavoriteCommand{} | 151 | + cmd := &command.UpdateFavoriteCommand{} |
152 | err := controller.Unmarshal(cmd) | 152 | err := controller.Unmarshal(cmd) |
153 | if err != nil { | 153 | if err != nil { |
154 | controller.Response(nil, err) | 154 | controller.Response(nil, err) |
155 | return | 155 | return |
156 | } | 156 | } |
157 | cmd.Operator = controller.GetOperator() | 157 | cmd.Operator = controller.GetOperator() |
158 | - data, err := svr.UpdateMenuFavorite(cmd) | 158 | + data, err := svr.UpdateFavorite(cmd) |
159 | controller.Response(data, err) | 159 | controller.Response(data, err) |
160 | } | 160 | } |
@@ -2,9 +2,11 @@ package routers | @@ -2,9 +2,11 @@ package routers | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "github.com/beego/beego/v2/server/web" | 4 | "github.com/beego/beego/v2/server/web" |
5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/constant" | ||
5 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/port/beego/controllers" | 6 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/port/beego/controllers" |
6 | ) | 7 | ) |
7 | 8 | ||
8 | func init() { | 9 | func init() { |
9 | web.Router("/log", &controllers.LoggerController{}, "Get:Index") | 10 | web.Router("/log", &controllers.LoggerController{}, "Get:Index") |
11 | + web.SetStaticPath("/static", constant.FileStatic) | ||
10 | } | 12 | } |
@@ -39,6 +39,7 @@ func init() { | @@ -39,6 +39,7 @@ func init() { | ||
39 | web.Router("/v1/app/cooperation-projects/person/search", &mobile_client.CooperationController{}, "Post:PersonSearchCooperationProject") | 39 | web.Router("/v1/app/cooperation-projects/person/search", &mobile_client.CooperationController{}, "Post:PersonSearchCooperationProject") |
40 | web.Router("/v1/app/cooperation-projects/person/search-starred", &mobile_client.CooperationController{}, "Post:PersonSearchCooperationProjectStarred") | 40 | web.Router("/v1/app/cooperation-projects/person/search-starred", &mobile_client.CooperationController{}, "Post:PersonSearchCooperationProjectStarred") |
41 | web.Router("/v1/app/cooperation-projects/person/shared-info", &mobile_client.CooperationController{}, "Post:PersonCooperationProjectSharedInfo") | 41 | web.Router("/v1/app/cooperation-projects/person/shared-info", &mobile_client.CooperationController{}, "Post:PersonCooperationProjectSharedInfo") |
42 | + web.Router("/v1/app/cooperation-projects/person/shared-info/attachment", &mobile_client.CooperationController{}, "Post:PersonCooperationProjectSharedInfoAttachment") | ||
42 | 43 | ||
43 | /***** CompanyDividends 账期结算 *****/ | 44 | /***** CompanyDividends 账期结算 *****/ |
44 | web.Router("/v1/app/company/credit-accounts/search", &mobile_client.CooperationController{}, "Post:CreditAccountSearch") | 45 | web.Router("/v1/app/company/credit-accounts/search", &mobile_client.CooperationController{}, "Post:CreditAccountSearch") |
@@ -15,7 +15,7 @@ func init() { | @@ -15,7 +15,7 @@ func init() { | ||
15 | web.Router("/v1/user/user-menu", &controllers.AuthController{}, "Post:GetUserMenus") | 15 | web.Router("/v1/user/user-menu", &controllers.AuthController{}, "Post:GetUserMenus") |
16 | web.Router("/v1/user/favorite-menus", &controllers.AuthController{}, "Get:GetFavoriteMenus") | 16 | web.Router("/v1/user/favorite-menus", &controllers.AuthController{}, "Get:GetFavoriteMenus") |
17 | web.Router("/v1/user/favorite-menus", &mobile_client.UserController{}, "Post:UpdateMenuFavorite") | 17 | web.Router("/v1/user/favorite-menus", &mobile_client.UserController{}, "Post:UpdateMenuFavorite") |
18 | - web.Router("/v1/user/favorite-org", &mobile_client.UserController{}, "Post:UpdateOrgFavorite") | 18 | + web.Router("/v1/user/favorite", &mobile_client.UserController{}, "Post:UpdateOrgFavorite") |
19 | 19 | ||
20 | web.Router("/v1/user/change-password", &mobile_client.UserController{}, "Post:ChangePassword") | 20 | web.Router("/v1/user/change-password", &mobile_client.UserController{}, "Post:ChangePassword") |
21 | web.Router("/v1/user/change-phone", &mobile_client.UserController{}, "Post:ChangePhone") | 21 | web.Router("/v1/user/change-phone", &mobile_client.UserController{}, "Post:ChangePhone") |
pkg/util/blur/blur.go
0 → 100644
1 | +package blur | ||
2 | + | ||
3 | +import ( | ||
4 | + "errors" | ||
5 | + "fmt" | ||
6 | + "github.com/disintegration/imaging" | ||
7 | + "github.com/pdfcpu/pdfcpu/pkg/api" | ||
8 | + "io/fs" | ||
9 | + "io/ioutil" | ||
10 | + "net/http" | ||
11 | + "os" | ||
12 | + "os/exec" | ||
13 | + "path/filepath" | ||
14 | + "runtime" | ||
15 | + "sort" | ||
16 | + "strings" | ||
17 | +) | ||
18 | + | ||
19 | +const ( | ||
20 | + SIGMA = 5 | ||
21 | + BlurPrefix = "blur-" | ||
22 | +) | ||
23 | + | ||
24 | +var ( | ||
25 | + outPath = "./static/" | ||
26 | + cmdPath = "./cmd/pdftopng.exe" //xpdf https://www.xpdfreader.com/download.html | ||
27 | + tmpPath = "./tmp/" | ||
28 | +) | ||
29 | + | ||
30 | +// InitConfig 初始化配置 | ||
31 | +// cp 执行文件目录 | ||
32 | +// op 输出目录 | ||
33 | +// tp 临时文件目录 | ||
34 | +func InitConfig(cp, op, tp string) { | ||
35 | + cmdPath = cp | ||
36 | + outPath = op | ||
37 | + tmpPath = tp | ||
38 | + initConfig() | ||
39 | +} | ||
40 | + | ||
41 | +func InitDefaultConfig() { | ||
42 | + initConfig() | ||
43 | +} | ||
44 | + | ||
45 | +func initConfig() { | ||
46 | + if _, err := os.Stat(tmpPath); err != nil { | ||
47 | + if errors.Is(err, os.ErrNotExist) { | ||
48 | + os.MkdirAll(tmpPath, os.ModePerm) | ||
49 | + } | ||
50 | + } | ||
51 | + if _, err := os.Stat(outPath); err != nil { | ||
52 | + if errors.Is(err, os.ErrNotExist) { | ||
53 | + os.MkdirAll(outPath, os.ModePerm) | ||
54 | + } | ||
55 | + } | ||
56 | + if runtime.GOOS == "linux" { | ||
57 | + cmdPath = strings.TrimLeft(cmdPath, ".exe") | ||
58 | + } | ||
59 | +} | ||
60 | + | ||
61 | +// CheckFileExist 检查文件是否存在 | ||
62 | +func CheckFileExist(p string) (string, error) { | ||
63 | + filename := filepath.Base(p) | ||
64 | + f, err := os.Stat(filepath.Join(outPath, filename)) | ||
65 | + if f != nil && err == nil { | ||
66 | + return p, nil | ||
67 | + } | ||
68 | + return "", fmt.Errorf("file not exisit %v", p) | ||
69 | +} | ||
70 | + | ||
71 | +// FileBlur 文件模糊处理 | ||
72 | +// blurFlag true:执行模糊 false:不需要模糊 | ||
73 | +func FileBlur(filePath string, blurFlag bool) (string, error) { | ||
74 | + filename := filepath.Base(filePath) | ||
75 | + // 判断文件是否存在 | ||
76 | + if !blurFlag { | ||
77 | + return filePath, nil | ||
78 | + } | ||
79 | + if fs, e := CheckFileExist(filepath.Join(outPath, BlurPrefix+filename)); e == nil && len(fs) > 0 { | ||
80 | + return fs, nil | ||
81 | + } | ||
82 | + var err error | ||
83 | + filePath, err = ResolveFilePath(filePath) | ||
84 | + if err != nil { | ||
85 | + return "", err | ||
86 | + } | ||
87 | + ext := filepath.Ext(filePath) | ||
88 | + ext = strings.TrimSpace(ext) | ||
89 | + if ext == ".pdf" { | ||
90 | + return PDFBlur(filePath) | ||
91 | + } | ||
92 | + if strings.Contains(".png|.jpg|.jpeg", ext) { | ||
93 | + return ImageBlur(filePath) | ||
94 | + } | ||
95 | + return filePath, nil | ||
96 | +} | ||
97 | + | ||
98 | +// ImageBlur 图片模糊处理 | ||
99 | +func ImageBlur(filePath string) (string, error) { | ||
100 | + filename := filepath.Base(filePath) | ||
101 | + blurFilename := filepath.Join(outPath, BlurPrefix+filename) | ||
102 | + | ||
103 | + img, err := imaging.Open(filePath) | ||
104 | + if err != nil { | ||
105 | + return "", err | ||
106 | + } | ||
107 | + dst := imaging.Blur(img, SIGMA) | ||
108 | + err = imaging.Save(dst, blurFilename) | ||
109 | + // clear | ||
110 | + os.Remove(filePath) | ||
111 | + return blurFilename, err | ||
112 | +} | ||
113 | + | ||
114 | +// PDFBlur PDF 模糊处理 | ||
115 | +func PDFBlur(pdfPath string) (string, error) { | ||
116 | + filename := filepath.Base(pdfPath) | ||
117 | + blurFilename := filepath.Join(outPath, BlurPrefix+filename) | ||
118 | + tmpImagePath, err := ioutil.TempDir("", "image-") | ||
119 | + tmpImagePathBlur, err := ioutil.TempDir("", "image-"+BlurPrefix) | ||
120 | + cmd := exec.Command(cmdPath, pdfPath, tmpImagePath+"/") | ||
121 | + err = cmd.Run() | ||
122 | + if err != nil { | ||
123 | + panic(err) | ||
124 | + } | ||
125 | + | ||
126 | + var blurFiles = make([]string, 0) | ||
127 | + files, _ := ioutil.ReadDir(tmpImagePath) | ||
128 | + for _, f := range files { | ||
129 | + img, _ := imaging.Open(filepath.Join(tmpImagePath, f.Name())) | ||
130 | + dst := imaging.Blur(img, SIGMA) | ||
131 | + blurFiles = append(blurFiles, filepath.Join(tmpImagePathBlur, f.Name())) | ||
132 | + _ = imaging.Save(dst, filepath.Join(tmpImagePathBlur, f.Name())) | ||
133 | + } | ||
134 | + sort.Strings(blurFiles) | ||
135 | + err = api.ImportImagesFile(blurFiles, blurFilename, nil, nil) | ||
136 | + if err != nil { | ||
137 | + return "", err | ||
138 | + } | ||
139 | + //clear | ||
140 | + os.RemoveAll(tmpImagePath) | ||
141 | + os.RemoveAll(tmpImagePathBlur) | ||
142 | + os.Remove(pdfPath) | ||
143 | + return blurFilename, nil | ||
144 | +} | ||
145 | + | ||
146 | +// ResolveFilePath 解析文件 | ||
147 | +func ResolveFilePath(filePath string) (string, error) { | ||
148 | + if strings.HasPrefix(filePath, "http") || strings.HasPrefix(filePath, "https") { | ||
149 | + return download(filePath) | ||
150 | + } | ||
151 | + return filePath, nil | ||
152 | +} | ||
153 | + | ||
154 | +func download(url string) (string, error) { | ||
155 | + resp, err := http.Get(url) | ||
156 | + if err != nil { | ||
157 | + return "", err | ||
158 | + } | ||
159 | + fileName := filepath.Base(url) | ||
160 | + data, err := ioutil.ReadAll(resp.Body) | ||
161 | + defer resp.Body.Close() | ||
162 | + tmpFilePath := filepath.Join(tmpPath, fileName) | ||
163 | + err = ioutil.WriteFile(tmpFilePath, data, fs.ModePerm) | ||
164 | + if err != nil { | ||
165 | + return "", nil | ||
166 | + } | ||
167 | + return tmpFilePath, err | ||
168 | +} |
-
请 注册 或 登录 后发表评论