Merge branch 'feature/mhw-v1.01' of gitee.com:fusenpack/fusenapi into feature/mhw-v1.01

This commit is contained in:
momo 2023-09-19 19:17:32 +08:00
commit 78558bb74d
81 changed files with 926 additions and 449 deletions

16
.gitignore vendored
View File

@ -40,18 +40,6 @@ screenlog.*
proxyserver/proxyserver
server/backend/backend
server/canteen/canteen
server/data-transfer/data-transfer
server/home-user-auth/home-user-auth
server/inventory/inventory
server/map-library/map-library
server/orders/orders
server/product/product
server/product-model/product-model
server/product-template/product-template
server/shopping-cart-confirmation/shopping-cart-confirmation
server/upload/upload
server/webset/webset
shared-state
shared-state
*.zip

7
env.yaml Normal file
View File

@ -0,0 +1,7 @@
nacos:
- server.fusen.3718.cn:8848
- server.fusen.3718.cn:8849
username: ...
password: ...
namespace: fs_server_api_dev
group: FS-SERVER-API

25
fs_nacos_etc_pack.sh Executable file
View File

@ -0,0 +1,25 @@
#!/bin/bash
CURRENT_DIR=`pwd`
SOURCE_DIR="server"
TEMP_DIR="/tmp"
DEST_DIR="FS-SERVER-API"
ZIP_FILE="FS-SERVER-API.zip"
mkdir -p $TEMP_DIR/$DEST_DIR
# 查找并复制文件
find "$SOURCE_DIR" -type d -name "etc" -exec sh -c 'cp "$0"/*.yaml "$1"' {} "$TEMP_DIR/$DEST_DIR" \;
cd $TEMP_DIR
# 打包目标文件夹
zip -r "$ZIP_FILE" "$DEST_DIR"
#返回当前目录
cd $CURRENT_DIR
# 移动到当前目录
mv "$TEMP_DIR/$ZIP_FILE" .
# 清理临时文件夹
rm "$TEMP_DIR/$DEST_DIR" -rf

14
go.mod
View File

@ -14,6 +14,7 @@ require (
github.com/gorilla/websocket v1.5.0
github.com/hashicorp/raft v1.5.0
github.com/lni/dragonboat/v4 v4.0.0-20230709075559-54497b9553be
github.com/nacos-group/nacos-sdk-go/v2 v2.2.3
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
github.com/streadway/amqp v1.1.0
@ -31,14 +32,17 @@ require (
github.com/DataDog/zstd v1.4.5 // indirect
github.com/HdrHistogram/hdrhistogram-go v1.1.2 // indirect
github.com/VictoriaMetrics/metrics v1.18.1 // indirect
github.com/aliyun/alibaba-cloud-sdk-go v1.61.1704 // indirect
github.com/andybalholm/brotli v1.0.5 // indirect
github.com/armon/go-metrics v0.4.1 // indirect
github.com/buger/jsonparser v1.1.1 // indirect
github.com/cockroachdb/errors v1.9.0 // indirect
github.com/cockroachdb/logtags v0.0.0-20211118104740-dabe8e521a4f // indirect
github.com/cockroachdb/pebble v0.0.0-20221207173255-0f086d933dac // indirect
github.com/cockroachdb/redact v1.1.3 // indirect
github.com/getsentry/sentry-go v0.12.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/btree v1.0.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
@ -50,12 +54,15 @@ require (
github.com/hashicorp/golang-lru v0.5.1 // indirect
github.com/hashicorp/memberlist v0.3.1 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.15.15 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/lni/goutils v1.3.1-0.20220604063047-388d67b4dbc4 // indirect
github.com/lni/vfs v0.2.1-0.20220616104132-8852fd867376 // indirect
github.com/miekg/dns v1.1.26 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pierrec/lz4/v4 v4.1.17 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/rogpeppe/go-internal v1.9.0 // indirect
@ -64,11 +71,18 @@ require (
github.com/valyala/fastrand v1.1.0 // indirect
github.com/valyala/histogram v1.2.0 // indirect
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.14.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
go.uber.org/zap v1.24.0 // indirect
golang.org/x/crypto v0.11.0 // indirect
golang.org/x/exp v0.0.0-20230728194245-b0cb94b80691 // indirect
golang.org/x/sync v0.2.0 // indirect
golang.org/x/time v0.3.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230530153820-e85fd2cbaebc // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230530153820-e85fd2cbaebc // indirect
gopkg.in/ini.v1 v1.66.2 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
)
require (

32
go.sum
View File

@ -41,6 +41,7 @@ github.com/474420502/random v0.4.1 h1:HUUyLXRWMijVb7CJoEC16f0aFQOW25Lkr80Mut6PoK
github.com/474420502/requests v1.42.0 h1:aUj0rWhfldbOOlGHDIcqT9zgXEoSlK4IBmRF3LxI1+Y=
github.com/474420502/requests v1.42.0/go.mod h1:2SCVzim0ONFYG09g/GrM7RTeJIC6qTyZfnohsjnG5C8=
github.com/AndreasBriese/bbloom v0.0.0-20190306092124-e2d15f34fcf9/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8=
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/CloudyKit/fastprinter v0.0.0-20170127035650-74b38d55f37a/go.mod h1:EFZQ978U7x8IRnstaskI3IysnWY5Ao3QgZUKOXlsAdw=
@ -69,6 +70,8 @@ github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRF
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a h1:HbKu58rmZpUGpz5+4FfNmIU+FmZg2P3Xaj2v2bfNWmk=
github.com/alicebob/miniredis/v2 v2.30.4 h1:8S4/o1/KoUArAGbGwPxcwf0krlzceva2XVOSchFS7Eo=
github.com/aliyun/alibaba-cloud-sdk-go v1.61.1704 h1:PpfENOj/vPfhhy9N2OFRjpue0hjM5XqAp2thFmkXXIk=
github.com/aliyun/alibaba-cloud-sdk-go v1.61.1704/go.mod h1:RcDobYh8k5VP6TNybz9m++gL3ijVI5wueVr0EM10VsU=
github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs=
github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
@ -79,10 +82,13 @@ github.com/armon/go-metrics v0.4.1/go.mod h1:E6amYzXo6aW1tqzoZGT755KkbgrJsSdpwZ+
github.com/aws/aws-sdk-go v1.44.295 h1:SGjU1+MqttXfRiWHD6WU0DRhaanJgAFY+xIhEaugV8Y=
github.com/aws/aws-sdk-go v1.44.295/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g=
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs=
github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
github.com/bwmarrin/snowflake v0.3.0 h1:xm67bEhkKh6ij1790JB83OujPR5CzNe8QuQqAgISZN0=
github.com/bwmarrin/snowflake v0.3.0/go.mod h1:NdZxfVWX+oR6y2K0o6qAYv6gIOP9rjG0/E9WsDpxqwE=
github.com/cenkalti/backoff/v4 v4.2.0 h1:HN5dHm3WBOgndBH6E8V0q2jIYIR3s9yglV8k/+MN3u4=
@ -202,6 +208,7 @@ github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXP
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/gogo/status v1.1.0/go.mod h1:BFv9nrluPLmrS0EmGVvLaPNmRosr9KapBYd5/hpY1WM=
github.com/goji/httpauth v0.0.0-20160601135302-2da839ab0f4d/go.mod h1:nnjvkQ9ptGaCkuDUx6wNykzzlUixGxvkme+H/lnzb+A=
github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY=
github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg=
@ -220,6 +227,8 @@ github.com/golang/mock v1.4.0/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt
github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4=
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
@ -330,12 +339,16 @@ github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
github.com/json-iterator/go v1.1.5/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
@ -413,11 +426,16 @@ github.com/miekg/dns v1.1.26/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKju
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/moul/http2curl v1.0.0/go.mod h1:8UbvGypXm98wA/IqH45anm5Y2Z6ep6O31QGOAZ3H0fQ=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/nacos-group/nacos-sdk-go/v2 v2.2.3 h1:sUQx4f1bXDeeOOEQZjGAitzxYApbYY9fVDbxVCaBW+I=
github.com/nacos-group/nacos-sdk-go/v2 v2.2.3/go.mod h1:UL4U89WYdnyajgKJUMpuT1Rr6iNmbjrxOO40JRgtA00=
github.com/nats-io/jwt v0.3.0/go.mod h1:fRYCDE99xlTsqUzISS1Bi75UBJ6ljOJQOAAu5VglpSg=
github.com/nats-io/nats.go v1.8.1/go.mod h1:BrFz9vVn0fU3AcH9Vn4Kd7W0NpJ651tD5omQ3M8LwxM=
github.com/nats-io/nats.go v1.9.1/go.mod h1:ZjDU1L/7fJ09jvUSRVBR2e7+RnLiiIQyqyzEE/Zbp4w=
@ -598,9 +616,15 @@ go.opentelemetry.io/otel/trace v1.14.0/go.mod h1:8avnQLK+CG77yNLUae4ea2JDQ6iT+go
go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI=
go.opentelemetry.io/proto/otlp v0.19.0 h1:IVN6GR+mhC4s5yfcTbmzHYODqvWAp3ZedA2SJPI1Nnw=
go.opentelemetry.io/proto/otlp v0.19.0/go.mod h1:H7XAot3MsfNsj7EXtrA2q5xSNQ10UqI405h3+duxN4U=
go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ=
go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
go.uber.org/automaxprocs v1.5.2 h1:2LxUOGiR3O6tw8ui5sZa2LAaHnsviZdVOUZw4fvbnME=
go.uber.org/automaxprocs v1.5.2/go.mod h1:eRbA25aqJrxAbsLO0xy5jVwPt7FQnRgjW+efnwa1WM0=
go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A=
go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI=
go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ=
go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60=
go.uber.org/zap v1.24.0/go.mod h1:2kMP+WWQ8aoFoedH3T2sq6iJ2yDWpHbP0f6MQbS9Gkg=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
@ -721,6 +745,7 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.2.0 h1:PUR+T4wwASmuSTYdKjYHI5TD22Wy5ogLU5qZCOLxBrI=
golang.org/x/sync v0.2.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
@ -798,6 +823,8 @@ golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxb
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4=
golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180525024113-a5b4c53f6e8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
@ -847,6 +874,7 @@ golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7/go.mod h1:njjCfa9FT2d7l9Bc
golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
@ -969,7 +997,11 @@ gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8
gopkg.in/go-playground/validator.v8 v8.18.2/go.mod h1:RX2a/7Ha8BgOhfk7j780h4/u/RRjR0eouCJSH80/M2Y=
gopkg.in/h2non/gock.v1 v1.1.2 h1:jBbHXgGBK/AoPVfJh5x4r/WxIrElvbLel8TCZkkZJoY=
gopkg.in/ini.v1 v1.51.1/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/ini.v1 v1.66.2 h1:XfR1dOYubytKy4Shzc2LHrrGhU0lDCfDGG1yLPmpgsI=
gopkg.in/ini.v1 v1.66.2/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce/go.mod h1:yeKp02qBN3iKW1OzL3MGk2IdtZzaj7SFntXj72NppTA=
gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8=
gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

View File

@ -3,7 +3,7 @@ Host: {{.host}}
Port: {{.port}}
Timeout: 15000 #服务超时时间(毫秒)
SourceMysql: fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen
SourceRabbitMq: amqp://rabbit001:rabbit001129@110.41.19.98:5672
SourceRabbitMq: ""
Auth:
AccessSecret: fusen2023
AccessExpire: 2592000

View File

@ -7,6 +7,7 @@ import (
"time"
"fusenapi/utils/auth"
"fusenapi/utils/fsconfig"
{{.importPackages}}
)
@ -16,8 +17,10 @@ var configFile = flag.String("f", "etc/{{.serviceName}}.yaml", "the config file"
func main() {
flag.Parse()
cfgContent := fsconfig.StartNacosConfig(configFile,nil)
var c config.Config
conf.MustLoad(*configFile, &c)
conf.LoadConfigFromYamlBytes([]byte(cfgContent),&c)
c.Timeout = int64(time.Second * 15)
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {
}))

View File

@ -13,7 +13,7 @@ func main() {
flag.Parse()
var c gateway.GatewayConf
conf.MustLoad(*configFile, &c)
c.Timeout = int64(time.Second * 15)
gw := gateway.MustNewServer(c)
defer gw.Stop()

View File

@ -18,8 +18,10 @@ var configFile = flag.String("f", "etc/{{.serviceName}}.yaml", "the config file"
func main() {
flag.Parse()
cfgContent := fsconfig.StartNacosConfig(configFile,nil)
var c config.Config
conf.MustLoad(*configFile, &c)
conf.LoadConfigFromYamlBytes([]byte(cfgContent),&c)
c.Timeout = int64(time.Second * 15)
ctx := svc.NewServiceContext(c)

View File

@ -7,6 +7,7 @@ import (
"time"
"fusenapi/utils/auth"
"fusenapi/utils/fsconfig"
{{.importPackages}}
)
@ -16,8 +17,10 @@ var configFile = flag.String("f", "etc/{{.serviceName}}.yaml", "the config file"
func main() {
flag.Parse()
cfgContent := fsconfig.StartNacosConfig(configFile,nil)
var c config.Config
conf.MustLoad(*configFile, &c)
conf.LoadConfigFromYamlBytes([]byte(cfgContent),&c)
c.Timeout = int64(time.Second * 15)
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {

View File

@ -13,7 +13,7 @@ func main() {
flag.Parse()
var c gateway.GatewayConf
conf.MustLoad(*configFile, &c)
c.Timeout = int64(time.Second * 15)
gw := gateway.MustNewServer(c)
defer gw.Stop()

View File

@ -18,8 +18,10 @@ var configFile = flag.String("f", "etc/{{.serviceName}}.yaml", "the config file"
func main() {
flag.Parse()
cfgContent := fsconfig.StartNacosConfig(configFile,nil)
var c config.Config
conf.MustLoad(*configFile, &c)
conf.LoadConfigFromYamlBytes([]byte(cfgContent),&c)
c.Timeout = int64(time.Second * 15)
ctx := svc.NewServiceContext(c)

View File

@ -15,8 +15,10 @@ run_server() {
# 导航到相应的目录
cd server/$server_name
go build
echo $server_name > .gitignore
# 使用 screen 运行 go run <server_name>.go
screen -dmS $server_name -L go run $server_name.go
screen -dmS $server_name -L ./$server_name
# 返回到上一级目录
cd - > /dev/null
@ -38,7 +40,6 @@ for server_dir in "${server_dirs[@]}"; do
run_server $server_dir
done
# 定义目录和screen名称
dir_path="./proxyserver"
screen_name="proxyserver"

1
server/auth/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
auth

View File

@ -6,6 +6,7 @@ import (
"net/http"
"fusenapi/utils/auth"
"fusenapi/utils/fsconfig"
"fusenapi/server/auth/internal/config"
"fusenapi/server/auth/internal/handler"
@ -20,8 +21,10 @@ var configFile = flag.String("f", "etc/auth.yaml", "the config file")
func main() {
flag.Parse()
cfgContent := fsconfig.StartNacosConfig(*configFile, nil)
var c config.Config
conf.MustLoad(*configFile, &c)
conf.LoadConfigFromYamlBytes([]byte(cfgContent), &c)
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {
}))
defer server.Stop()

View File

@ -143,7 +143,7 @@ func TestSql(t *testing.T) {
}
conn := initalize.InitMysql("fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen")
log.Println(conn.Model(&gmodel.FsUser{}))
log.Println()
log.Println(conn.NamingStrategy.TableName(reflect.TypeOf(gmodel.FsUser{}).Name()))
updatesql := `UPDATE %s

1
server/base/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
base

View File

@ -6,6 +6,7 @@ import (
"net/http"
"fusenapi/utils/auth"
"fusenapi/utils/fsconfig"
"fusenapi/server/base/internal/config"
"fusenapi/server/base/internal/handler"
@ -20,8 +21,9 @@ var configFile = flag.String("f", "etc/base.yaml", "the config file")
func main() {
flag.Parse()
cfgContent := fsconfig.StartNacosConfig(*configFile, nil)
var c config.Config
conf.MustLoad(*configFile, &c)
conf.LoadConfigFromYamlBytes([]byte(cfgContent), &c)
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {
}))

View File

@ -10,4 +10,4 @@ Auth:
AccessSecret: fusen2023
AccessExpire: 2592000
RefreshAfter: 1592000
SourceRabbitMq: "amqp://rabbit001:rabbit001129@110.41.19.98:5672"
SourceRabbitMq: ""

1
server/canteen/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
canteen

View File

@ -9,6 +9,7 @@ import (
"fusenapi/server/canteen/internal/handler"
"fusenapi/server/canteen/internal/svc"
"fusenapi/utils/auth"
"fusenapi/utils/fsconfig"
"github.com/zeromicro/go-zero/core/conf"
"github.com/zeromicro/go-zero/rest"
@ -19,9 +20,9 @@ var configFile = flag.String("f", "etc/canteen.yaml", "the config file")
func main() {
flag.Parse()
cfgContent := fsconfig.StartNacosConfig(*configFile, nil)
var c config.Config
conf.MustLoad(*configFile, &c)
conf.LoadConfigFromYamlBytes([]byte(cfgContent), &c)
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {

1
server/data-transfer/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
data-transfer

View File

@ -9,7 +9,6 @@ import (
"fusenapi/utils/auth"
"net/http"
"github.com/zeromicro/go-zero/core/conf"
"github.com/zeromicro/go-zero/rest"
)
@ -19,7 +18,6 @@ func main() {
flag.Parse()
var c config2.Config
conf.MustLoad(*configFile, &c)
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {

1
server/home-user-auth/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
home-user-auth

View File

@ -9,6 +9,7 @@ import (
"fusenapi/server/home-user-auth/internal/handler"
"fusenapi/server/home-user-auth/internal/svc"
"fusenapi/utils/auth"
"fusenapi/utils/fsconfig"
"github.com/zeromicro/go-zero/core/conf"
"github.com/zeromicro/go-zero/rest"
@ -19,9 +20,9 @@ var configFile = flag.String("f", "etc/home-user-auth.yaml", "the config file")
func main() {
flag.Parse()
cfgContent := fsconfig.StartNacosConfig(*configFile, nil)
var c config.Config
conf.MustLoad(*configFile, &c)
conf.LoadConfigFromYamlBytes([]byte(cfgContent), &c)
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {

View File

@ -92,6 +92,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Path: "/api/user/logo-set",
Handler: UserLogoSetHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/api/user/logo-templatetag-set",
Handler: UserLogoTemplateTagSetHandler(serverCtx),
},
},
)
}

View File

@ -0,0 +1,35 @@
package handler
import (
"net/http"
"reflect"
"fusenapi/utils/basic"
"fusenapi/server/home-user-auth/internal/logic"
"fusenapi/server/home-user-auth/internal/svc"
"fusenapi/server/home-user-auth/internal/types"
)
func UserLogoTemplateTagSetHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.UserLogoTemplateTagSetReq
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
if err != nil {
return
}
// 创建一个业务逻辑层实例
l := logic.NewUserLogoTemplateTagSetLogic(r.Context(), svcCtx)
rl := reflect.ValueOf(l)
basic.BeforeLogic(w, r, rl)
resp := l.UserLogoTemplateTagSet(&req, userinfo)
if !basic.AfterLogic(w, r, rl, resp) {
basic.NormalAfterLogic(w, r, resp)
}
}
}

View File

@ -75,17 +75,16 @@ func (l *UserLogoSetLogic) UserLogoSet(req *types.UserLogoSetReq, userinfo *auth
var nowTime = time.Now().UTC()
err = l.svcCtx.MysqlConn.WithContext(l.ctx).Transaction(func(tx *gorm.DB) error {
var metadataMapOldUserMaterial map[string]interface{}
if userMaterialInfo.Metadata != nil {
err = json.Unmarshal(*userMaterialInfo.Metadata, &metadataMapOldUserMaterial)
if err != nil {
logc.Errorf(l.ctx, "userMaterialInfo Metadata Unmarshal err%+v", err)
return err
}
}
// 更新merchant_category
if req.SetLogoCategory == 1 {
var metadataMapOldUserMaterial map[string]interface{}
if userMaterialInfo.Metadata != nil {
err = json.Unmarshal(*userMaterialInfo.Metadata, &metadataMapOldUserMaterial)
if err != nil {
logc.Errorf(l.ctx, "userMaterialInfo Metadata Unmarshal err%+v", err)
return err
}
}
var metadataChildUserMaterial = make(map[string]interface{}, 1)
metadataChildUserMaterial["merchant_category"] = req.CategoryId
metadataMapUserMaterial, err := metadata.SetMetadata(metadataChildUserMaterial, metadataMapOldUserMaterial)
@ -137,7 +136,34 @@ func (l *UserLogoSetLogic) UserLogoSet(req *types.UserLogoSetReq, userinfo *auth
}
var metadataChildUserInfo = make(map[string]interface{}, 1)
metadataChildUserInfo["logo_selected_id"] = req.LogoSelectedId
userMaterialTemplateTagData, userMaterialTemplateTagEx := metadataMapOldUserMaterial["template_tag"]
if !userMaterialTemplateTagEx {
logc.Errorf(l.ctx, "userMaterialInfo Metadata template_tag err%+v", err)
return err
}
userMaterialTemplateIdTagIdData, userMaterialTemplateTagIdEx := metadataMapOldUserMaterial["template_tag_id"]
if !userMaterialTemplateTagIdEx {
logc.Errorf(l.ctx, "userMaterialInfo Metadata template_tag_id err%+v", err)
return err
}
userMaterialTemplateIdTagIds := userMaterialTemplateIdTagIdData.([]interface{})
userMaterialTemplateIdTagId := userMaterialTemplateIdTagIds[0].(string)
userMaterialTemplateTag := userMaterialTemplateTagData.(map[string]interface{})
userMaterialTemplateTagIndex := userMaterialTemplateTag[userMaterialTemplateIdTagId]
templateTagSelected := make(map[string]interface{}, 3)
templateTagSelected["color"] = userMaterialTemplateTagIndex
templateTagSelected["template_tag"] = userMaterialTemplateIdTagId
templateTagSelected["selected_index"] = 0
metadataChildUserInfo["logo_selected"] = map[string]interface{}{
"logo_selected_id": req.LogoSelectedId,
"template_tag_selected": templateTagSelected,
}
metadataMapUserInfo, err := metadata.SetMetadata(metadataChildUserInfo, metadataMapOldUserInfo)
if err != nil {
logc.Errorf(l.ctx, "userInfo Metadata SetMetadata err%+v", err)

View File

@ -0,0 +1,187 @@
package logic
import (
"encoding/json"
"errors"
"fusenapi/model/gmodel"
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"fusenapi/utils/metadata"
"time"
"context"
"fusenapi/server/home-user-auth/internal/svc"
"fusenapi/server/home-user-auth/internal/types"
"github.com/zeromicro/go-zero/core/logc"
"github.com/zeromicro/go-zero/core/logx"
"gorm.io/gorm"
)
type UserLogoTemplateTagSetLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewUserLogoTemplateTagSetLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserLogoTemplateTagSetLogic {
return &UserLogoTemplateTagSetLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
// 处理进入前逻辑w,r
// func (l *UserLogoTemplateTagSetLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
// }
func (l *UserLogoTemplateTagSetLogic) UserLogoTemplateTagSet(req *types.UserLogoTemplateTagSetReq, userinfo *auth.UserInfo) (resp *basic.Response) {
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
// userinfo 传入值时, 一定不为null
if userinfo.IsOnlooker() {
// 如果是,返回未授权的错误码
return resp.SetStatus(basic.CodeUnAuth)
}
if req.LogoSelectedId == 0 {
return resp.SetStatus(basic.CodeApiErr, "logo logo_selected_id not null")
}
if req.TemplateTag == "" {
return resp.SetStatus(basic.CodeApiErr, "logo template tag not null")
}
var userId int64
var guestId int64
NewFsUserMaterialModel := gmodel.NewFsUserMaterialModel(l.svcCtx.MysqlConn)
NewFsUserMaterialModelRow := NewFsUserMaterialModel.RowSelectBuilder(nil).Where("id = ?", req.LogoSelectedId)
if userinfo.IsGuest() {
// 如果是使用游客ID和游客键名格式
guestId = userinfo.GuestId
NewFsUserMaterialModelRow.Where("guest_id = ?", guestId)
} else {
// 否则使用用户ID和用户键名格式
userId = userinfo.UserId
NewFsUserMaterialModelRow.Where("user_id = ?", userId)
}
userMaterialInfo, err := NewFsUserMaterialModel.FindOne(l.ctx, NewFsUserMaterialModelRow.Model(&gmodel.FsUserMaterial{}))
if err != nil {
logc.Errorf(l.ctx, "FsUserMaterial FindOne err%+v", err)
return resp.SetStatus(basic.CodeLogoSetCategory, "logo not find")
}
var nowTime = time.Now().UTC()
err = l.svcCtx.MysqlConn.WithContext(l.ctx).Transaction(func(tx *gorm.DB) error {
var metadataMapOldUserMaterial map[string]interface{}
if userMaterialInfo.Metadata != nil {
err = json.Unmarshal(*userMaterialInfo.Metadata, &metadataMapOldUserMaterial)
if err != nil {
logc.Errorf(l.ctx, "userMaterialInfo Metadata Unmarshal err%+v", err)
return err
}
}
var module = "profile"
var userInfo = &gmodel.FsUserInfo{}
BuilderDB := tx.Model(&gmodel.FsUserInfo{}).Where("module = ?", module)
if userId > 0 {
BuilderDB.Where("user_id=?", userId)
} else {
BuilderDB.Where("guest_id=?", guestId)
}
userInfoFirstRes := BuilderDB.First(userInfo)
err = userInfoFirstRes.Error
if err != nil {
if !errors.Is(err, gorm.ErrRecordNotFound) {
logc.Errorf(l.ctx, "userInfo First err%+v", err)
return err
}
}
var metadataMapOldUserInfo map[string]interface{}
if userInfo.Metadata != nil {
err = json.Unmarshal(*userInfo.Metadata, &metadataMapOldUserInfo)
if err != nil {
logc.Errorf(l.ctx, "userInfo Metadata Unmarshal err%+v", err)
return err
}
}
var metadataChildUserInfo = make(map[string]interface{}, 1)
_, userInfoLogoSelectedEx := metadataMapOldUserInfo["logo_selected"]
if userInfoLogoSelectedEx {
userMaterialTemplateTagData, userMaterialTemplateTagEx := metadataMapOldUserMaterial["template_tag"]
if !userMaterialTemplateTagEx {
logc.Errorf(l.ctx, "userMaterialInfo Metadata template_tag err%+v", err)
return err
}
userMaterialTemplateTag := userMaterialTemplateTagData.(map[string]interface{})
userMaterialTemplateTagIndex := userMaterialTemplateTag[req.TemplateTag]
if userMaterialTemplateTagIndex == nil {
err = errors.New("TemplateTag not find")
logc.Errorf(l.ctx, "TemplateTag not find err%+v", err)
return err
}
templateTagSelected := make(map[string]interface{}, 3)
templateTagSelected["color"] = userMaterialTemplateTagIndex
templateTagSelected["template_tag"] = req.TemplateTag
templateTagSelected["selected_index"] = req.TemplateTagColorIndex
metadataChildUserInfo["logo_selected"] = map[string]interface{}{
"template_tag_selected": templateTagSelected,
}
}
metadataMapUserInfo, err := metadata.SetMetadata(metadataChildUserInfo, metadataMapOldUserInfo)
if err != nil {
logc.Errorf(l.ctx, "userInfo Metadata SetMetadata err%+v", err)
return err
}
metadataBUserInfo, err := json.Marshal(metadataMapUserInfo)
if err != nil {
logc.Errorf(l.ctx, "userInfo Metadata marshal err%+v", err)
return err
}
userInfo.Metadata = &metadataBUserInfo
if userInfo.Id == 0 {
// 新增
userInfo.Module = &module
userInfo.Ctime = &nowTime
userInfo.Utime = &nowTime
userInfo.UserId = &userId
userInfo.GuestId = &guestId
resCreate := tx.Model(&userInfo).Create(&userInfo)
err = resCreate.Error
} else {
// 更新
userInfo.Utime = &nowTime
resUpdates := tx.Model(&userInfo).Select("metadata").Where("id = ?", userInfo.Id).Updates(&userInfo)
err = resUpdates.Error
}
if err != nil {
if err != gorm.ErrRecordNotFound {
logc.Errorf(l.ctx, "FsUserInfo Updates err%+v", err)
return err
}
}
return nil
})
if err != nil {
logx.Error(err)
return resp.SetStatus(basic.CodeDbSqlErr, "set logo fail")
}
return resp.SetStatus(basic.CodeOK)
}
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
// func (l *UserLogoTemplateTagSetLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
// // httpx.OkJsonCtx(r.Context(), w, resp)
// }

View File

@ -5,6 +5,12 @@ import (
"fusenapi/utils/basic"
)
type UserLogoTemplateTagSetReq struct {
LogoSelectedId int64 `form:"logo_selected_id"`
TemplateTag string `form:"template_tag"`
TemplateTagColorIndex int64 `form:"template_tag_color_index"`
}
type UserLogoSetReq struct {
SetLogoSelected int64 `form:"set_logo_selected"`
LogoSelectedId int64 `form:"logo_selected_id"`

1
server/info/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
info

View File

@ -4,7 +4,7 @@ Port: 9988
Timeout: 15000 #服务超时时间(毫秒)
ReplicaId: 200
SourceMysql: fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen
SourceRabbitMq: amqp://rabbit001:rabbit001129@110.41.19.98:5672
SourceRabbitMq:
Log:
Stat: false
Auth:

View File

@ -7,6 +7,7 @@ import (
"time"
"fusenapi/utils/auth"
"fusenapi/utils/fsconfig"
"fusenapi/server/info/internal/config"
"fusenapi/server/info/internal/handler"
@ -21,8 +22,10 @@ var configFile = flag.String("f", "etc/info.yaml", "the config file")
func main() {
flag.Parse()
cfgContent := fsconfig.StartNacosConfig(*configFile, nil)
var c config.Config
conf.MustLoad(*configFile, &c)
conf.LoadConfigFromYamlBytes([]byte(cfgContent), &c)
c.Timeout = int64(time.Second * 15)
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {
}))

1
server/map-library/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
map-library

View File

@ -9,6 +9,7 @@ import (
"fusenapi/server/map-library/internal/handler"
"fusenapi/server/map-library/internal/svc"
"fusenapi/utils/auth"
"fusenapi/utils/fsconfig"
"github.com/zeromicro/go-zero/core/conf"
"github.com/zeromicro/go-zero/rest"
@ -19,8 +20,9 @@ var configFile = flag.String("f", "etc/map-library.yaml", "the config file")
func main() {
flag.Parse()
cfgContent := fsconfig.StartNacosConfig(*configFile, nil)
var c config.Config
conf.MustLoad(*configFile, &c)
conf.LoadConfigFromYamlBytes([]byte(cfgContent), &c)
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {

1
server/pay/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
pay

View File

@ -6,6 +6,7 @@ import (
"net/http"
"fusenapi/utils/auth"
"fusenapi/utils/fsconfig"
"fusenapi/server/pay/internal/config"
"fusenapi/server/pay/internal/handler"
@ -20,8 +21,10 @@ var configFile = flag.String("f", "etc/pay.yaml", "the config file")
func main() {
flag.Parse()
cfgContent := fsconfig.StartNacosConfig(*configFile, nil)
var c config.Config
conf.MustLoad(*configFile, &c)
conf.LoadConfigFromYamlBytes([]byte(cfgContent), &c)
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {
}))
defer server.Stop()

1
server/product-model/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
product-model

View File

@ -9,6 +9,7 @@ import (
"fusenapi/server/product-model/internal/handler"
"fusenapi/server/product-model/internal/svc"
"fusenapi/utils/auth"
"fusenapi/utils/fsconfig"
"github.com/zeromicro/go-zero/core/conf"
"github.com/zeromicro/go-zero/rest"
@ -19,8 +20,9 @@ var configFile = flag.String("f", "etc/product-model.yaml", "the config file")
func main() {
flag.Parse()
cfgContent := fsconfig.StartNacosConfig(*configFile, nil)
var c config.Config
conf.MustLoad(*configFile, &c)
conf.LoadConfigFromYamlBytes([]byte(cfgContent), &c)
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {

View File

@ -0,0 +1 @@
product-template-tag

View File

@ -36,6 +36,16 @@ func NewGetProductTemplateTagsLogic(ctx context.Context, svcCtx *svc.ServiceCont
// func (l *GetProductTemplateTagsLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
// // httpx.OkJsonCtx(r.Context(), w, resp)
// }
type logoSelect struct {
LogoSelected struct {
LogoSelectedId int `json:"logo_selected_id"`
TemplateTagSelected struct {
TemplateTag string `json:"template_tag"`
Color [][]string `json:"color"`
SelectedIndex int `json:"selected_index"`
} `json:"template_tag_selected"`
} `json:"logo_selected"`
}
func (l *GetProductTemplateTagsLogic) GetProductTemplateTags(req *types.GetProductTemplateTagsReq, userinfo *auth.UserInfo) (resp *basic.Response) {
if req.Limit <= 0 || req.Limit > 100 {
@ -54,34 +64,45 @@ func (l *GetProductTemplateTagsLogic) GetProductTemplateTags(req *types.GetProdu
logx.Error(err)
return
}
var colors interface{}
if logoInfo.Metadata == nil || *logoInfo.Metadata == "" {
// 返回固定模板A1a
productTemplateTags, err = l.svcCtx.AllModels.FsProductTemplateTags.GetListByTagNames(l.ctx, []string{"A1"}, req.Limit, 1, "`id` DESC")
if err != nil {
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "logo info`s metadata is not set")
}
//解析用户素材元数据
var metaData map[string]interface{}
if err = json.Unmarshal([]byte(*logoInfo.Metadata), &metaData); err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse user metadata")
}
var mapTemplateTag map[string][][]string
b, _ := json.Marshal(metaData["template_tag"])
if err = json.Unmarshal(b, &mapTemplateTag); err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeJsonErr, "invalid format of metadata`s template_tag")
}
//从用户元数据获取选中的颜色数据
mapSelectColor := make(map[string]int) //key是模板标签val是选中的索引
if logoInfo.UserInfoMetadata != nil && *logoInfo.UserInfoMetadata != "" {
//解析用户信息元数据
var logoSelectInfo logoSelect
if err = json.Unmarshal([]byte(*logoInfo.UserInfoMetadata), &logoSelectInfo); err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get template tags")
return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse user info metadata")
}
} else {
//解析元数据
var metaData map[string]interface{}
if err = json.Unmarshal([]byte(*logoInfo.Metadata), &metaData); err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse user metadata")
}
colors = metaData["colors"]
var templateTagNameList []string
b, _ := json.Marshal(metaData["template_tagid"])
if err = json.Unmarshal(b, &templateTagNameList); err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeJsonErr, "invalid format of metadata`s template_tagid")
}
productTemplateTags, err = l.svcCtx.AllModels.FsProductTemplateTags.GetListByTagNames(l.ctx, templateTagNameList, req.Limit, 1, "id DESC")
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get template tags")
//设置选中
key := logoSelectInfo.LogoSelected.TemplateTagSelected.TemplateTag
if _, ok := mapTemplateTag[key]; ok {
mapSelectColor[key] = logoSelectInfo.LogoSelected.TemplateTagSelected.SelectedIndex
}
}
var templateTagNameList []string
for templateTag, _ := range mapTemplateTag {
templateTagNameList = append(templateTagNameList, templateTag)
}
productTemplateTags, err = l.svcCtx.AllModels.FsProductTemplateTags.GetListByTagNames(l.ctx, templateTagNameList, req.Limit, 1, "id DESC")
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get template tags")
}
//资源id集合
resourceIds := make([]string, 0, 5)
for _, v := range productTemplateTags {
@ -102,13 +123,33 @@ func (l *GetProductTemplateTagsLogic) GetProductTemplateTags(req *types.GetProdu
mapResourceMetadata[*v.ResourceUrl] = metadata
}
list := make([]types.GetProductTemplateTagsRsp, 0, len(productTemplateTags))
for _, v := range productTemplateTags {
for _, templateInfo := range productTemplateTags {
colors := make([][]string, 0, 10)
SelectedColorIndex := 0
isDefaultTemplateTag := false
if colorsSet, ok := mapTemplateTag[*templateInfo.TemplateTag]; ok {
if selectIndex, ok := mapSelectColor[*templateInfo.TemplateTag]; ok {
isDefaultTemplateTag = true
SelectedColorIndex = selectIndex
}
colors = colorsSet
}
var templateTagGroups []interface{}
if templateInfo.Groups != nil && *templateInfo.Groups != "" {
if err = json.Unmarshal([]byte(*templateInfo.Groups), &templateTagGroups); err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse groups")
}
}
list = append(list, types.GetProductTemplateTagsRsp{
Id: v.Id,
TemplateTag: *v.TemplateTag,
Cover: *v.Cover,
CoverMetadata: mapResourceMetadata[*v.Cover],
Colors: colors,
Id: templateInfo.Id,
TemplateTag: *templateInfo.TemplateTag,
IsDefaultTemplateTag: isDefaultTemplateTag,
TemplateTagGroups: templateTagGroups,
Cover: *templateInfo.Cover,
CoverMetadata: mapResourceMetadata[*templateInfo.Cover],
Colors: colors,
SelectedColorIndex: SelectedColorIndex,
})
}
return resp.SetStatusWithMessage(basic.CodeOK, "success", list)

View File

@ -10,11 +10,14 @@ type GetProductTemplateTagsReq struct {
}
type GetProductTemplateTagsRsp struct {
Id int64 `json:"id"`
TemplateTag string `json:"template_tag"`
Cover string `json:"cover"`
CoverMetadata interface{} `json:"cover_metadata"`
Colors interface{} `json:"colors"`
Id int64 `json:"id"`
TemplateTag string `json:"template_tag"`
IsDefaultTemplateTag bool `json:"is_default_template_tag"`
TemplateTagGroups interface{} `json:"template_tag_groups"`
Cover string `json:"cover"`
CoverMetadata interface{} `json:"cover_metadata"`
Colors [][]string `json:"colors"`
SelectedColorIndex int `json:"selected_color_index"`
}
type Request struct {

View File

@ -6,6 +6,7 @@ import (
"net/http"
"fusenapi/utils/auth"
"fusenapi/utils/fsconfig"
"fusenapi/server/product-template-tag/internal/config"
"fusenapi/server/product-template-tag/internal/handler"
@ -20,8 +21,10 @@ var configFile = flag.String("f", "etc/product-template-tag.yaml", "the config f
func main() {
flag.Parse()
cfgContent := fsconfig.StartNacosConfig(*configFile, nil)
var c config.Config
conf.MustLoad(*configFile, &c)
conf.LoadConfigFromYamlBytes([]byte(cfgContent), &c)
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {
}))
defer server.Stop()

1
server/product-template/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
product-template

View File

@ -9,6 +9,7 @@ import (
"fusenapi/server/product-template/internal/handler"
"fusenapi/server/product-template/internal/svc"
"fusenapi/utils/auth"
"fusenapi/utils/fsconfig"
"github.com/zeromicro/go-zero/core/conf"
"github.com/zeromicro/go-zero/rest"
@ -19,8 +20,9 @@ var configFile = flag.String("f", "etc/product-template.yaml", "the config file"
func main() {
flag.Parse()
cfgContent := fsconfig.StartNacosConfig(*configFile, nil)
var c config.Config
conf.MustLoad(*configFile, &c)
conf.LoadConfigFromYamlBytes([]byte(cfgContent), &c)
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {

1
server/product/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
product

View File

@ -9,6 +9,7 @@ import (
"fusenapi/server/product/internal/handler"
"fusenapi/server/product/internal/svc"
"fusenapi/utils/auth"
"fusenapi/utils/fsconfig"
"github.com/zeromicro/go-zero/core/conf"
"github.com/zeromicro/go-zero/rest"
@ -19,8 +20,9 @@ var configFile = flag.String("f", "etc/product.yaml", "the config file")
func main() {
flag.Parse()
cfgContent := fsconfig.StartNacosConfig(*configFile, nil)
var c config.Config
conf.MustLoad(*configFile, &c)
conf.LoadConfigFromYamlBytes([]byte(cfgContent), &c)
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {

1
server/resource/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
resource

View File

@ -10,7 +10,7 @@ Auth:
AccessSecret: fusen2023
AccessExpire: 2592000
RefreshAfter: 1592000
SourceRabbitMq: "amqp://rabbit001:rabbit001129@110.41.19.98:5672"
SourceRabbitMq: ""
AWS:
S3:
Credentials:

View File

@ -95,7 +95,6 @@ func (l *LogoCombineLogic) LogoCombine(req *types.LogoCombineReq, userinfo *auth
res, err := l.svcCtx.Repositories.ImageHandle.LogoCombine(l.ctx, &repositories.LogoCombineReq{
UserId: userId,
GuestId: guestId,
TemplateId: req.TemplateId,
TemplateTag: req.TemplateTag,
Website: req.Website,
Slogan: req.Slogan,

View File

@ -28,13 +28,16 @@ type ResourceInfoReq struct {
}
type LogoCombineReq struct {
TemplateId int64 `form:"template_id"` // 合图参数
TemplateTag string `form:"template_tag"` // 合图参数
Website string `form:"website,optional"` // 合图参数
Slogan string `form:"slogan,optional"` // 合图参数
Address string `form:"address,optional"` // 合图参数
Phone string `form:"phone,optional"` // 合图参数
Qrcode string `form:"qrcode,optional"` // 合图参数
LogoUrl string `json:"logo_url"` // 合图参数
TemplateId int64 `json:"template_id"` // 合图参数
TemplateTag string `json:"template_tag"` // 合图参数
Color [][]string `json:"color"` // 颜色组合
SelectedIndex int `json:"selected_index"` // 主色的下标索引
Website string `json:"website,optional"` // 合图参数
Slogan string `json:"slogan,optional"` // 合图参数
Address string `json:"address,optional"` // 合图参数
Phone string `json:"phone,optional"` // 合图参数
Qrcode string `json:"qrcode,optional"` // 合图参数
}
type Request struct {
@ -60,10 +63,10 @@ type File struct {
}
type Meta struct {
TotalCount int64 `json:"totalCount"`
PageCount int64 `json:"pageCount"`
CurrentPage int `json:"currentPage"`
PerPage int `json:"perPage"`
TotalCount int64 `json:"total_count"`
PageCount int64 `json:"page_count"`
CurrentPage int `json:"current_page"`
PerPage int `json:"per_page"`
}
// Set 设置Response的Code和Message值

View File

@ -6,6 +6,7 @@ import (
"net/http"
"fusenapi/utils/auth"
"fusenapi/utils/fsconfig"
"fusenapi/server/resource/internal/config"
"fusenapi/server/resource/internal/handler"
@ -20,8 +21,10 @@ var configFile = flag.String("f", "etc/resource.yaml", "the config file")
func main() {
flag.Parse()
cfgContent := fsconfig.StartNacosConfig(*configFile, nil)
var c config.Config
conf.MustLoad(*configFile, &c)
conf.LoadConfigFromYamlBytes([]byte(cfgContent), &c)
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {
}))
defer server.Stop()

1
server/shopping-cart/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
shopping-cart

View File

@ -3,7 +3,7 @@ Host: 0.0.0.0
Port: 9918
Timeout: 15000 #服务超时时间(毫秒)
SourceMysql: fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen
SourceRabbitMq: amqp://rabbit001:rabbit001129@110.41.19.98:5672
SourceRabbitMq:
Log:
Stat: false
Auth:

View File

@ -2,6 +2,7 @@ package logic
import (
"context"
"errors"
"fmt"
"fusenapi/constants"
"fusenapi/model/gmodel"
@ -9,6 +10,7 @@ import (
"fusenapi/utils/basic"
"fusenapi/utils/format"
"fusenapi/utils/step_price"
"gorm.io/gorm"
"math"
"strings"
@ -100,48 +102,66 @@ func (l *CalculateCartPriceLogic) CalculateCartPrice(req *types.CalculateCartPri
//开始计算价格
calculateResultList := make([]types.CalculateResultItem, 0, len(req.CalculateList))
subTotalPrice := int64(0)
for _, cart := range carts {
sizePrice, ok := mapPrice[fmt.Sprintf("%d_%d", *cart.ProductId, *cart.SizeId)]
if !ok {
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, fmt.Sprintf("there carts contain some one which have no price info:%d_%d", *cart.ProductId, *cart.SizeId))
}
//阶梯数量切片
stepNum, err := format.StrSlicToIntSlice(strings.Split(*sizePrice.StepNum, ","))
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, fmt.Sprintf("failed to parse step number:%d_%d", *cart.ProductId, *cart.SizeId))
}
lenStepNum := len(stepNum)
//阶梯价格切片
stepPrice, err := format.StrSlicToIntSlice(strings.Split(*sizePrice.StepPrice, ","))
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, fmt.Sprintf("failed to parse step price:%d_%d", *cart.ProductId, *cart.SizeId))
}
lenStepPrice := len(stepPrice)
if lenStepPrice == 0 || lenStepNum == 0 {
return resp.SetStatusWithMessage(basic.CodeServiceErr, fmt.Sprintf("step price or step number is not set:%d_%d", *cart.ProductId, *cart.SizeId))
}
//购买箱数
boxQuantity := int(math.Ceil(float64(mapCalculateQuantity[cart.Id]) / float64(*sizePrice.EachBoxNum)))
//根据数量获取阶梯价格中对应的价格
itemPrice := step_price.GetCentStepPrice(boxQuantity, stepNum, stepPrice)
//如果有配件,单价也要加入配件价格
if *cart.FittingId > 0 {
if fittingPrice, ok := mapFitting[*cart.FittingId]; ok {
itemPrice += fittingPrice
} else {
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "cart contain some one witch lose fitting:%d", *cart.FittingId)
//开启事物
err = l.svcCtx.MysqlConn.Transaction(func(tx *gorm.DB) error {
shoppingCartModel := gmodel.NewFsShoppingCartModel(tx)
for _, cart := range carts {
sizePrice, ok := mapPrice[fmt.Sprintf("%d_%d", *cart.ProductId, *cart.SizeId)]
if !ok {
return errors.New(fmt.Sprintf("there carts contain some one which have no price info:%d_%d", *cart.ProductId, *cart.SizeId))
}
//阶梯数量切片
stepNum, err := format.StrSlicToIntSlice(strings.Split(*sizePrice.StepNum, ","))
if err != nil {
logx.Error(err)
return errors.New(fmt.Sprintf("failed to parse step number:%d_%d", *cart.ProductId, *cart.SizeId))
}
lenStepNum := len(stepNum)
//阶梯价格切片
stepPrice, err := format.StrSlicToIntSlice(strings.Split(*sizePrice.StepPrice, ","))
if err != nil {
logx.Error(err)
return errors.New(fmt.Sprintf("failed to parse step price:%d_%d", *cart.ProductId, *cart.SizeId))
}
lenStepPrice := len(stepPrice)
if lenStepPrice == 0 || lenStepNum == 0 {
return errors.New(fmt.Sprintf("step price or step number is not set:%d_%d", *cart.ProductId, *cart.SizeId))
}
//请求的数量
reqPurchaseQuantity := mapCalculateQuantity[cart.Id]
//购买箱数
boxQuantity := int(math.Ceil(float64(reqPurchaseQuantity) / float64(*sizePrice.EachBoxNum)))
//根据数量获取阶梯价格中对应的价格
itemPrice := step_price.GetCentStepPrice(boxQuantity, stepNum, stepPrice)
//如果有配件,单价也要加入配件价格
if *cart.FittingId > 0 {
if fittingPrice, ok := mapFitting[*cart.FittingId]; ok {
itemPrice += fittingPrice
} else {
return errors.New(fmt.Sprintf("cart contain some one witch lose fitting:%d", *cart.FittingId))
}
}
//单个购物车总价
totalPrice := itemPrice * reqPurchaseQuantity
calculateResultList = append(calculateResultList, types.CalculateResultItem{
CartId: cart.Id,
ItemPrice: fmt.Sprintf("%.3f", format.CentitoDollar(itemPrice)),
TotalPrice: fmt.Sprintf("%.3f", format.CentitoDollar(totalPrice)),
})
subTotalPrice += totalPrice
//更新购物车购买数量
err = shoppingCartModel.Update(l.ctx, cart.Id, userinfo.UserId, &gmodel.FsShoppingCart{
PurchaseQuantity: &reqPurchaseQuantity,
})
if err != nil {
logx.Error(err)
return errors.New(fmt.Sprintf("failed to update cart`s purchase quantity:%d", cart.Id))
}
}
//单个购物车总价
totalPrice := itemPrice * mapCalculateQuantity[cart.Id]
calculateResultList = append(calculateResultList, types.CalculateResultItem{
CartId: cart.Id,
ItemPrice: fmt.Sprintf("%.3f", format.CentitoDollar(itemPrice)),
TotalPrice: fmt.Sprintf("%.3f", format.CentitoDollar(totalPrice)),
})
subTotalPrice += totalPrice
return nil
})
if err != nil {
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, err.Error())
}
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.CalculateCartPriceRsp{
SubTotalPrice: fmt.Sprintf("%.3f", format.CentitoDollar(subTotalPrice)),

View File

@ -41,6 +41,9 @@ func NewGetCartsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetCarts
// }
func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo) (resp *basic.Response) {
if !userinfo.IsUser() {
return resp.SetStatusWithMessage(basic.CodeUnAuth, "please sign in")
}
if req.CurrentPage <= 0 {
req.CurrentPage = constants.DEFAULT_PAGE
}

View File

@ -7,6 +7,7 @@ import (
"time"
"fusenapi/utils/auth"
"fusenapi/utils/fsconfig"
"fusenapi/server/shopping-cart/internal/config"
"fusenapi/server/shopping-cart/internal/handler"
@ -21,8 +22,10 @@ var configFile = flag.String("f", "etc/shopping-cart.yaml", "the config file")
func main() {
flag.Parse()
cfgContent := fsconfig.StartNacosConfig(*configFile, nil)
var c config.Config
conf.MustLoad(*configFile, &c)
conf.LoadConfigFromYamlBytes([]byte(cfgContent), &c)
c.Timeout = int64(time.Second * 15)
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {
}))

1
server/upload/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
upload

View File

@ -20,6 +20,7 @@ AWS:
Token:
BLMService:
Url: "http://18.119.109.254:8999"
# Url: "http://192.168.1.9:8999"
ImageProcess:
# Url: "http://192.168.1.7:8999/FeatureExtraction"
Url: "http://18.119.109.254:8999/FeatureExtraction"

View File

@ -9,6 +9,7 @@ import (
"fusenapi/server/upload/internal/handler"
"fusenapi/server/upload/internal/svc"
"fusenapi/utils/auth"
"fusenapi/utils/fsconfig"
"github.com/zeromicro/go-zero/core/conf"
"github.com/zeromicro/go-zero/rest"
@ -19,8 +20,9 @@ var configFile = flag.String("f", "etc/upload.yaml", "the config file")
func main() {
flag.Parse()
cfgContent := fsconfig.StartNacosConfig(*configFile, nil)
var c config.Config
conf.MustLoad(*configFile, &c)
conf.LoadConfigFromYamlBytes([]byte(cfgContent), &c)
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {

1
server/webset/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
webset

View File

@ -9,6 +9,7 @@ import (
"fusenapi/server/webset/internal/handler"
"fusenapi/server/webset/internal/svc"
"fusenapi/utils/auth"
"fusenapi/utils/fsconfig"
"github.com/zeromicro/go-zero/core/conf"
"github.com/zeromicro/go-zero/rest"
@ -19,8 +20,9 @@ var configFile = flag.String("f", "etc/webset.yaml", "the config file")
func main() {
flag.Parse()
cfgContent := fsconfig.StartNacosConfig(*configFile, nil)
var c config.Config
conf.MustLoad(*configFile, &c)
conf.LoadConfigFromYamlBytes([]byte(cfgContent), &c)
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {

1
server/websocket/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
websocket

View File

@ -12,7 +12,7 @@ Auth:
AccessSecret: fusen2023
AccessExpire: 2592000
RefreshAfter: 1592000
SourceRabbitMq: "amqp://rabbit001:rabbit001129@110.41.19.98:5672"
SourceRabbitMq: ""
AWS:
S3:
Credentials:

View File

@ -194,10 +194,8 @@ func (l *DataTransferLogic) setConnPool(conn *websocket.Conn, userInfo *auth.Use
userId: userInfo.UserId,
guestId: userInfo.GuestId,
extendRenderProperty: extendRenderProperty{
//renderImageTask: make(map[string]*renderTask),
renderImageTaskCtlChan: make(chan renderImageControlChanItem, renderImageTaskCtlChanLen),
renderChan: make(chan []byte, renderChanLen),
renderConsumeTickTime: 1, //默认1纳秒后面需要根据不同用户不同触发速度
renderChan: make(chan []byte, renderChanLen),
renderConsumeTickTime: 1, //默认1纳秒后面需要根据不同用户不同触发速度
},
}
//保存连接

View File

@ -6,6 +6,7 @@ import (
// 消息分发工厂
type allocationProcessorFactory interface {
//分配数据到缓冲队列
allocationMessage(w *wsConnectItem, data []byte)
}

View File

@ -11,7 +11,6 @@ import (
"fusenapi/service/repositories"
"fusenapi/utils/curl"
"fusenapi/utils/hash"
"fusenapi/utils/template_switch_info"
"fusenapi/utils/websocket_data"
"github.com/zeromicro/go-zero/core/logx"
"gorm.io/gorm"
@ -20,8 +19,6 @@ import (
)
var (
//每个websocket连接渲染任务调度队列长度默认值添加任务/删除任务/修改任务属性缓冲队列长度该队列用于避免map并发读写冲突
renderImageTaskCtlChanLen = 100
//每个websocket渲染任务缓冲队列长度默认值
renderChanLen = 500
)
@ -32,27 +29,8 @@ type renderProcessor struct {
// 云渲染属性
type extendRenderProperty struct {
//renderImageTask map[string]*renderTask //需要渲染的图片任务 key是taskId val 是renderId
renderImageTaskCtlChan chan renderImageControlChanItem //渲染任务新增/回调结果移除任务/更新渲染耗时属性的控制通道由于任务map无法读写并发
renderChan chan []byte //渲染消息入口的缓冲队列
renderConsumeTickTime time.Duration //消费渲染消息时钟间隔(纳秒),用于后期控制不同类型用户渲染速度限制
}
// 渲染任务新增移除的控制通道的数据
type renderImageControlChanItem struct {
option int // 0删除 1添加 2修改耗时属性
taskId string //map的key(必须传)
renderId string // map的val(增加任务时候传)
renderNotifyImageUrl string //渲染回调数据(删除任务时候传)
taskProperty renderTask //渲染任务的属性
}
// 渲染任务属性
type renderTask struct {
renderId string //渲染id(新增任务传)
unityRenderBeginTime int64 //发送给unity时间
unityRenderEndTime int64 //unity回调结果时间
uploadUnityRenderImageTakesTime int64 //上传unity渲染结果图时间
renderChan chan []byte //渲染消息入口的缓冲队列
renderConsumeTickTime time.Duration //消费渲染消息时钟间隔(纳秒),用于后期控制不同类型用户渲染速度限制
}
// 处理分发到这里的数据
@ -96,10 +74,23 @@ func (w *wsConnectItem) renderImage(data []byte) {
//logx.Info("消费渲染数据:", string(data))
var renderImageData websocket_data.RenderImageReqMsg
if err := json.Unmarshal(data, &renderImageData); err != nil {
w.incomeDataFormatErrResponse("invalid format of render data:" + string(data))
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "数据格式错误", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0)
logx.Error("invalid format of websocket render image message", err)
return
}
if renderImageData.RenderData.Logo == "" {
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "请传入logo", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0)
return
}
lenColor := len(renderImageData.RenderData.TemplateTagColor.Color)
if lenColor == 0 {
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "请传入模板标签选择的颜色", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0)
return
}
if renderImageData.RenderData.TemplateTagColor.SelectedColorIndex >= lenColor || renderImageData.RenderData.TemplateTagColor.SelectedColorIndex < 0 {
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "选择的模板标签颜色索引越界", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0)
return
}
//获取产品信息(部分字段)
productInfo, err := w.logic.svcCtx.AllModels.FsProduct.FindOne(w.logic.ctx, renderImageData.RenderData.ProductId, "id,is_customization")
if err != nil {
@ -116,21 +107,6 @@ func (w *wsConnectItem) renderImage(data []byte) {
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "该产品不可定制", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0)
return
}
//获取用户需要渲染logo
logoInfo, err := w.logic.svcCtx.Repositories.ImageHandle.LogoInfo(w.logic.ctx, &repositories.LogoInfoReq{
UserId: w.userId,
GuestId: w.guestId,
})
if err != nil {
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "获取用户logo素材错误", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0)
logx.Error(err)
return
}
if logoInfo == nil || logoInfo.LogoUrl == nil {
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "用户logo素材url是空的", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0)
return
}
renderImageData.RenderData.Logo = *logoInfo.LogoUrl
//用户id赋值
renderImageData.RenderData.UserId = w.userId
renderImageData.RenderData.GuestId = w.guestId
@ -162,7 +138,7 @@ func (w *wsConnectItem) renderImage(data []byte) {
return
}
//获取模板开关信息并且对于没有默认值的给赋值默认值(但凡DIY有一个是空的就要请求默认数据)
if renderImageData.RenderData.Website == "" || renderImageData.RenderData.Phone == "" || renderImageData.RenderData.Address == "" || renderImageData.RenderData.Qrcode == "" || renderImageData.RenderData.Slogan == "" {
/*if renderImageData.RenderData.Website == "" || renderImageData.RenderData.Phone == "" || renderImageData.RenderData.Address == "" || renderImageData.RenderData.Qrcode == "" || renderImageData.RenderData.Slogan == "" {
templateSwitchInfo := template_switch_info.GetTemplateSwitchInfo(productTemplate.Id, productTemplate.TemplateInfo, *productTemplate.MaterialImg)
if renderImageData.RenderData.Website == "" && templateSwitchInfo.MaterialData.Website.IfShow {
renderImageData.RenderData.Website = templateSwitchInfo.MaterialData.Website.DefaultValue
@ -179,19 +155,24 @@ func (w *wsConnectItem) renderImage(data []byte) {
if renderImageData.RenderData.Slogan == "" && templateSwitchInfo.MaterialData.Slogan.IfShow {
renderImageData.RenderData.Slogan = templateSwitchInfo.MaterialData.Slogan.DefaultValue
}
}
}*/
//获取刀版图
combineReq := repositories.LogoCombineReq{
UserId: renderImageData.RenderData.UserId,
GuestId: renderImageData.RenderData.GuestId,
TemplateId: productTemplate.Id,
TemplateTag: renderImageData.RenderData.TemplateTag,
Website: renderImageData.RenderData.Website,
Slogan: renderImageData.RenderData.Slogan,
Address: renderImageData.RenderData.Address,
Phone: renderImageData.RenderData.Phone,
Qrcode: renderImageData.RenderData.Qrcode,
LogoUrl: renderImageData.RenderData.Logo,
UserId: renderImageData.RenderData.UserId,
GuestId: renderImageData.RenderData.GuestId,
ProductTemplateV2Info: productTemplate,
ProductTemplateTagGroups: renderImageData.RenderData.TemplateTagGroups,
TemplateTag: renderImageData.RenderData.TemplateTag,
Website: renderImageData.RenderData.Website,
Slogan: renderImageData.RenderData.Slogan,
Address: renderImageData.RenderData.Address,
Phone: renderImageData.RenderData.Phone,
Qrcode: renderImageData.RenderData.Qrcode,
LogoUrl: renderImageData.RenderData.Logo,
TemplateTagColor: repositories.TemplateTagColor{
Color: renderImageData.RenderData.TemplateTagColor.Color,
Index: renderImageData.RenderData.TemplateTagColor.SelectedColorIndex,
},
}
res, err := w.logic.svcCtx.Repositories.ImageHandle.LogoCombine(w.logic.ctx, &combineReq)
if err != nil {
@ -216,7 +197,7 @@ func (w *wsConnectItem) renderImage(data []byte) {
}
//获取唯一id
taskId := w.genRenderTaskId(combineImage, renderImageData, model3dInfo, productTemplate, element)
//查询有没有缓存的资源,有就返回######################
//查询有没有缓存的资源,有就返回
resource, err := w.logic.svcCtx.AllModels.FsResource.FindOneById(w.logic.ctx, taskId)
if err != nil {
if !errors.Is(err, gorm.ErrRecordNotFound) {
@ -236,9 +217,6 @@ func (w *wsConnectItem) renderImage(data []byte) {
})
return
}
//###########################################
//把需要渲染的图片任务加进去
//w.createRenderTask(taskId, renderImageData.RenderId)
//组装数据
if err = w.assembleRenderDataToUnity(taskId, combineImage, renderImageData, productTemplate, model3dInfo, element, productSize); err != nil {
logx.Error("组装数据失败:", err)
@ -288,8 +266,8 @@ func (w *wsConnectItem) getProductRelateionInfoWithSizeId(renderImageData *webso
return nil, nil, nil, errors.New("模板未开启云渲染")
}
if productTemplate.TemplateInfo == nil || *productTemplate.TemplateInfo == "" {
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "渲染模板的json设计信息是空的", renderImageData.RenderData.ProductId, w.userId, w.guestId, productTemplate.Id, model3d.Id, productSize.Id, 0)
return nil, nil, nil, errors.New("渲染模板的json设计信息是空的")
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "渲染模板的设计信息是空的", renderImageData.RenderData.ProductId, w.userId, w.guestId, productTemplate.Id, model3d.Id, productSize.Id, 0)
return nil, nil, nil, errors.New("渲染模板的设计信息是空的")
}
return
}
@ -430,15 +408,12 @@ func (w *wsConnectItem) assembleRenderDataToUnity(taskId string, combineImage st
"render_data": sendData,
}
postDataBytes, _ := json.Marshal(postData)
//unityRenderBeginTime := time.Now().UTC().UnixMilli()
_, err = curl.ApiCall(url, "POST", header, bytes.NewReader(postDataBytes), time.Second*10)
if err != nil {
w.renderErrResponse(info.RenderId, info.RenderData.TemplateTag, taskId, "请求unity接口失败", info.RenderData.ProductId, w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productSize.Id, *productTemplate.ElementModelId)
logx.Error("failed to send data to unity")
return err
}
//记录发送到unity时间
//w.modifyRenderTaskProperty(taskId, renderTask{unityRenderBeginTime: unityRenderBeginTime})
//发送运行阶段消息
w.sendRenderDataToUnityStepResponseMessage(info.RenderId)
logx.Info("发送到unity成功,刀版图:", combineImage /*, " 请求unity的数据:", string(postDataBytes)*/)
@ -483,75 +458,6 @@ func (w *wsConnectItem) sendRenderResultData(data websocket_data.RenderImageRspM
w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_RENDER_IMAGE, data))
}
/*// 增加渲染任务
func (w *wsConnectItem) createRenderTask(taskId, renderId string) {
if taskId == "" {
logx.Error("task_id不能为空")
return
}
if renderId == "" {
logx.Error("render_id不能为空")
return
}
data := renderImageControlChanItem{
option: 1,
taskId: taskId,
renderId: renderId,
}
select {
case <-w.closeChan: //关闭
return
case w.extendRenderProperty.renderImageTaskCtlChan <- data:
return
case <-time.After(time.Second * 3):
return
}
}
// 渲染回调处理并删除渲染任务
func (w *wsConnectItem) deleteRenderTask(taskId, renderId, renderNotifyImageUrl string) {
if taskId == "" {
logx.Error("task_id不能为空")
return
}
data := renderImageControlChanItem{
option: 0,
taskId: taskId,
renderId: renderId,
renderNotifyImageUrl: renderNotifyImageUrl,
}
select {
case <-w.closeChan: //关闭
return
case w.extendRenderProperty.renderImageTaskCtlChan <- data:
return
case <-time.After(time.Second * 3):
return
}
}
// 修改任务属性(只有耗时属性可以更新)
func (w *wsConnectItem) modifyRenderTaskProperty(taskId string, property renderTask) {
if taskId == "" {
logx.Error("task_id不能为空")
return
}
//强制设为修改任务属性
data := renderImageControlChanItem{
option: 2,
taskId: taskId,
taskProperty: property,
}
select {
case <-w.closeChan: //关闭
return
case w.extendRenderProperty.renderImageTaskCtlChan <- data:
return
case <-time.After(time.Second * 3):
return
}
}*/
// 组装渲染任务id
func (w *wsConnectItem) genRenderTaskId(combineImage string, renderImageData websocket_data.RenderImageReqMsg, model3dInfo *gmodel.FsProductModel3d, productTemplate *gmodel.FsProductTemplateV2, element *gmodel.FsProductTemplateElement) string {
//生成任务id(需要把user_id,guest_id设为0)
@ -578,78 +484,3 @@ func (w *wsConnectItem) genRenderTaskId(combineImage string, renderImageData web
}
return hash.JsonHashKey(hashMap)
}
// 处理渲染任务的增加/删除/修改耗时属性任务map不能读写并发所以放在chan里面串行执行
/*func (w *wsConnectItem) operationRenderTask() {
defer func() {
if err := recover(); err != nil {
logx.Error("operation render task panic:", err)
}
}()
for {
select {
case <-w.closeChan:
return
case data := <-w.extendRenderProperty.renderImageTaskCtlChan:
switch data.option {
case 0: //渲染结果回调,删除任务
taskData, ok := w.extendRenderProperty.renderImageTask[data.taskId]
if !ok {
//发送到出口
w.sendRenderResultData(websocket_data.RenderImageRspMsg{
RenderId: data.renderId, //没有找到任务渲染id则用传进来的
Image: data.renderNotifyImageUrl,
RenderProcessTime: websocket_data.RenderProcessTime{
UnityRenderTakesTime: "unknown",
UploadUnityRenderImageTakesTime: "unknown",
},
})
continue
}
//删除任务
delete(w.extendRenderProperty.renderImageTask, data.taskId)
//存在任务,则发送渲染结果给前端
UnityRenderTakesTime := "cache"
uploadUnityRenderImageTakesTime := "cache"
//unity渲染时间
if taskData.unityRenderBeginTime > 0 && taskData.unityRenderEndTime > 0 {
UnityRenderTakesTime = fmt.Sprintf("%dms", taskData.unityRenderEndTime-taskData.unityRenderBeginTime)
}
//上传unity渲染图耗时
if taskData.uploadUnityRenderImageTakesTime > 0 {
uploadUnityRenderImageTakesTime = fmt.Sprintf("%dms", taskData.uploadUnityRenderImageTakesTime)
}
//发送到出口
w.sendRenderResultData(websocket_data.RenderImageRspMsg{
RenderId: taskData.renderId,
Image: data.renderNotifyImageUrl,
RenderProcessTime: websocket_data.RenderProcessTime{
UnityRenderTakesTime: UnityRenderTakesTime,
UploadUnityRenderImageTakesTime: uploadUnityRenderImageTakesTime,
},
})
case 1: //新增任务
w.extendRenderProperty.renderImageTask[data.taskId] = &renderTask{
renderId: data.renderId,
}
case 2: //修改任务属性
taskData, ok := w.extendRenderProperty.renderImageTask[data.taskId]
if !ok {
continue
}
//上传渲染结果图耗时
if data.taskProperty.uploadUnityRenderImageTakesTime != 0 {
taskData.uploadUnityRenderImageTakesTime = data.taskProperty.uploadUnityRenderImageTakesTime
}
//发送unity时间
if data.taskProperty.unityRenderBeginTime != 0 {
taskData.unityRenderBeginTime = data.taskProperty.unityRenderBeginTime
}
//收到unity返回的时间
if data.taskProperty.unityRenderEndTime != 0 {
taskData.unityRenderEndTime = data.taskProperty.unityRenderEndTime
}
}
}
}
}*/

View File

@ -8,6 +8,7 @@ import (
"net/http"
"fusenapi/utils/auth"
"fusenapi/utils/fsconfig"
"fusenapi/server/websocket/internal/config"
"fusenapi/server/websocket/internal/handler"
@ -22,8 +23,10 @@ var configFile = flag.String("f", "etc/websocket.yaml", "the config file")
func main() {
flag.Parse()
cfgContent := fsconfig.StartNacosConfig(*configFile, nil)
var c config.Config
conf.MustLoad(*configFile, &c)
conf.LoadConfigFromYamlBytes([]byte(cfgContent), &c)
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {
}))
defer server.Stop()

View File

@ -71,8 +71,20 @@ service home-user-auth {
// 用户logo设置当前
@handler UserLogoSetHandler
post /api/user/logo-set (UserLogoSetReq) returns (response);
// 用户logo模版信息
@handler UserLogoTemplateTagSetHandler
post /api/user/logo-templatetag-set (UserLogoTemplateTagSetReq) returns (response);
}
type (
UserLogoTemplateTagSetReq {
LogoSelectedId int64 `form:"logo_selected_id"`
TemplateTag string `form:"template_tag"`
TemplateTagColorIndex int64 `form:"template_tag_color_index"`
}
)
type (
UserLogoSetReq {
SetLogoSelected int64 `form:"set_logo_selected"`

View File

@ -20,9 +20,12 @@ type GetProductTemplateTagsReq {
Limit int `form:"limit"`
}
type GetProductTemplateTagsRsp {
Id int64 `json:"id"`
TemplateTag string `json:"template_tag"`
Cover string `json:"cover"`
CoverMetadata interface{} `json:"cover_metadata"`
Colors interface{} `json:"colors"`
Id int64 `json:"id"`
TemplateTag string `json:"template_tag"`
IsDefaultTemplateTag bool `json:"is_default_template_tag"`
TemplateTagGroups interface{} `json:"template_tag_groups"`
Cover string `json:"cover"`
CoverMetadata interface{} `json:"cover_metadata"`
Colors [][]string `json:"colors"`
SelectedColorIndex int `json:"selected_color_index"`
}

View File

@ -55,12 +55,15 @@ type (
type (
LogoCombineReq {
TemplateId int64 `form:"template_id"` // 合图参数
TemplateTag string `form:"template_tag"` // 合图参数
Website string `form:"website,optional"` // 合图参数
Slogan string `form:"slogan,optional"` // 合图参数
Address string `form:"address,optional"` // 合图参数
Phone string `form:"phone,optional"` // 合图参数
Qrcode string `form:"qrcode,optional"` // 合图参数
LogoUrl string `json:"logo_url"` // 合图参数
TemplateId int64 `json:"template_id"` // 合图参数
TemplateTag string `json:"template_tag"` // 合图参数
Color [][]string `json:"color"` // 颜色组合
SelectedIndex int `json:"selected_index"` // 主色的下标索引
Website string `json:"website,optional"` // 合图参数
Slogan string `json:"slogan,optional"` // 合图参数
Address string `json:"address,optional"` // 合图参数
Phone string `json:"phone,optional"` // 合图参数
Qrcode string `json:"qrcode,optional"` // 合图参数
}
)

View File

@ -54,15 +54,16 @@ type (
GuestId int64 `json:"guest_id"`
}
LogoInfoRes struct {
Metadata *string `json:"metadata"`
LogoUrl *string `json:"logo_url"`
Metadata *string `json:"metadata"`
LogoUrl *string `json:"logo_url"`
UserInfoMetadata *string `json:"user_info_metadata"`
}
)
func (l *defaultImageHandle) LogoInfo(ctx context.Context, in *LogoInfoReq) (*LogoInfoRes, error) {
var metadata *string
var logoUrl *string
var userInfoMetadata *string
// 更新用户信息
var module = "profile"
userInfoGorm := l.MysqlConn.Where("module = ?", module)
@ -82,30 +83,42 @@ func (l *defaultImageHandle) LogoInfo(ctx context.Context, in *LogoInfoReq) (*Lo
return nil, err
}
}
if userInfo.Id != 0 {
tmp := string(*userInfo.Metadata)
userInfoMetadata = &tmp
}
var userMaterialInfo gmodel.FsUserMaterial
userMaterialModel := gmodel.NewFsUserMaterialModel(l.MysqlConn)
var metadataUserInfo struct {
LogoSelected struct {
TemplateTagSelected *struct {
Color [][]string `json:"color"`
TemplateTag string `json:"template_tag"`
SelectedIndex int64 `json:"selected_index"`
} `json:"template_tag_selected"`
LogoSelectedId int64 `json:"logo_selected_id"`
} `json:"logo_selected"`
}
userInfo.Id = 0
if userInfo.Id == 0 {
userMaterialInfo, err = userMaterialModel.FindLatestOne(ctx, in.UserId, in.GuestId)
if err != gorm.ErrRecordNotFound {
if err != nil && err != gorm.ErrRecordNotFound {
logc.Errorf(ctx, "FsUserMaterial FindLatestOne err%+v", err)
return nil, err
}
} else {
if userInfo.Metadata != nil {
var metadata map[string]interface{}
err = json.Unmarshal([]byte(*userInfo.Metadata), &metadata)
err = json.Unmarshal([]byte(*userInfo.Metadata), &metadataUserInfo)
if err != nil {
logc.Errorf(ctx, "userInfo.Metadata Unmarshal err%+v", err)
return nil, err
}
logoSelectedId, isEx := metadata["logo_selected_id"]
if isEx {
var materialId int64 = int64(logoSelectedId.(float64))
userMaterialInfos, err := userMaterialModel.FindOneById(ctx, materialId)
if metadataUserInfo.LogoSelected.LogoSelectedId != 0 {
userMaterialInfos, err := userMaterialModel.FindOneById(ctx, metadataUserInfo.LogoSelected.LogoSelectedId)
if err != nil {
if err != gorm.ErrRecordNotFound {
logc.Errorf(ctx, "FsUserInfo First err%+v", err)
logc.Errorf(ctx, "userMaterial findOneById err%+v", err)
return nil, err
}
}
@ -134,8 +147,9 @@ func (l *defaultImageHandle) LogoInfo(ctx context.Context, in *LogoInfoReq) (*Lo
logoUrl = userMaterialInfo.ResourceUrl
}
return &LogoInfoRes{
Metadata: metadata,
LogoUrl: logoUrl,
Metadata: metadata,
LogoUrl: logoUrl,
UserInfoMetadata: userInfoMetadata,
}, nil
}
@ -181,16 +195,18 @@ func (l *defaultImageHandle) LogoInfoSet(ctx context.Context, in *LogoInfoSetReq
/* logo合图 */
type (
LogoCombineReq struct {
UserId int64 `json:"user_id"`
GuestId int64 `json:"guest_id"`
TemplateId int64 `json:"template_id"`
TemplateTag string `json:"template_tag"`
Website string `json:"website"` // 合图参数
Slogan string `json:"slogan"` // 合图参数
Address string `json:"address"` // 合图参数
Phone string `json:"phone"` // 合图参数
Qrcode string `json:"qrcode"` // 合图参数
LogoUrl string `json:"logo_url"` // 合图参数
UserId int64 `json:"user_id"`
GuestId int64 `json:"guest_id"`
ProductTemplateV2Info *gmodel.FsProductTemplateV2 `json:"product_template_v2_info"`
ProductTemplateTagGroups interface{} `json:"product_template_tag_groups"`
TemplateTag string `json:"template_tag"`
Website string `json:"website"` // 合图参数
Slogan string `json:"slogan"` // 合图参数
Address string `json:"address"` // 合图参数
Phone string `json:"phone"` // 合图参数
Qrcode string `json:"qrcode"` // 合图参数
LogoUrl string `json:"logo_url"` // 合图参数
TemplateTagColor TemplateTagColor `json:"template_tag_color"` //合图颜色
}
LogoCombineRes struct {
ResourceId string
@ -200,6 +216,10 @@ type (
DiffTimeUploadFile int64
}
)
type TemplateTagColor struct {
Color [][]string `json:"color"`
Index int `json:"index"`
}
func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq) (*LogoCombineRes, error) {
// 查询logo最新基础信息
@ -238,27 +258,11 @@ func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq
}
}
// 没有查到先根据模版id 查询模版数据 请求算法数据
productTemplateV2Model := gmodel.NewFsProductTemplateV2Model(l.MysqlConn)
productTemplateV2Info, err := productTemplateV2Model.FindOne(ctx, in.TemplateId)
if err != nil {
logc.Errorf(ctx, "productTemplateV2Model.FindOne%v", err)
return nil, err
}
productTemplateTagInfo, err := gmodel.NewFsProductTemplateTagsModel(l.MysqlConn).FindOneByTagName(ctx, in.TemplateTag, "groups")
if err != nil {
logc.Errorf(ctx, "NewFsProductTemplateTagsModel.FindOneByTagName%v", err)
return nil, err
}
var groupOptions map[string]interface{}
var materialList []interface{}
if productTemplateV2Info.TemplateInfo != nil {
if in.ProductTemplateV2Info.TemplateInfo != nil {
var templateInfo map[string]interface{}
err = json.Unmarshal([]byte(*productTemplateV2Info.TemplateInfo), &templateInfo)
err = json.Unmarshal([]byte(*in.ProductTemplateV2Info.TemplateInfo), &templateInfo)
if err != nil {
logx.Error(err)
@ -282,18 +286,11 @@ func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq
}
var moduleDataMap = make(map[string]interface{}, 4)
moduleDataMap["id"] = productTemplateV2Info.Id
moduleDataMap["material"] = productTemplateV2Info.MaterialImg
moduleDataMap["id"] = in.ProductTemplateV2Info.Id
moduleDataMap["material"] = in.ProductTemplateV2Info.MaterialImg
moduleDataMap["groupOptions"] = groupOptions
moduleDataMap["materialList"] = materialList
var tagDataMap []interface{}
err = json.Unmarshal([]byte(*productTemplateTagInfo.Groups), &tagDataMap)
if err != nil {
logc.Errorf(ctx, "Unmarshal tagDataMap%v", err)
return nil, err
}
var combineParam map[string]interface{}
json.Unmarshal([]byte(*resLogoInfo.Metadata), &combineParam)
combineParam["template_tagid"] = in.TemplateTag
@ -302,10 +299,14 @@ func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq
combineParam["phone"] = in.Phone
combineParam["address"] = in.Address
combineParam["qrcode"] = in.Qrcode
combineParam["template_tag_selected"] = map[string]interface{}{
"template_tag": in.TemplateTag,
"color": in.TemplateTagColor.Color,
"index": in.TemplateTagColor.Index,
}
var postMap = make(map[string]interface{}, 2)
postMap["module_data"] = moduleDataMap
postMap["tag_data"] = tagDataMap
postMap["tag_data"] = in.ProductTemplateTagGroups
postMap["param_data"] = combineParam
logc.Infof(ctx, "合图--算法请求--合图--开始时间:%v", time.Now().UTC())

View File

@ -74,7 +74,7 @@ func AutoGetEtcYaml() *string {
dirs = dirs[0 : len(dirs)-1]
// 列出所有 curPath 下的文件夹
files, err := ioutil.ReadDir(curPath)
files, err := os.ReadDir(curPath)
if err != nil {
log.Println(err)
continue

View File

@ -1,7 +1,10 @@
package autoconfig
import "testing"
import (
"log"
"testing"
)
func TestAutoConfig(t *testing.T) {
AutoGetEtcYaml()
log.Println(*AutoGetEtcYaml())
}

View File

@ -119,7 +119,7 @@ func Array2MapByKey[KEY comparable, VALUE any](arrSrc []VALUE, fieldName string)
}
fv := srcv.FieldByName(fieldName)
k := fv.Interface().(KEY)
result[k] = srcv.Interface().(VALUE)
result[k] = arr.Index(i).Interface().(VALUE)
}
return result
@ -166,7 +166,7 @@ func Array2MapByKeyTag[KEY comparable, VALUE any](arrSrc []VALUE, tag string) (r
fv = fv.Elem()
}
k := fv.Interface().(KEY)
result[k] = srcv.Interface().(VALUE)
result[k] = arr.Index(i).Interface().(VALUE)
}
return

1
utils/fsconfig/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
log

144
utils/fsconfig/config.go Normal file
View File

@ -0,0 +1,144 @@
package fsconfig
import (
"log"
"os"
"path/filepath"
"strconv"
"strings"
"github.com/nacos-group/nacos-sdk-go/v2/clients"
"github.com/nacos-group/nacos-sdk-go/v2/common/constant"
"github.com/nacos-group/nacos-sdk-go/v2/vo"
"gopkg.in/yaml.v2"
)
type EnvConfig struct {
NacosServers []string `yaml:"nacos"`
UserName string `yaml:"username"`
Password string `yaml:"password"`
NamespaceId string `yaml:"namespace"`
DataId string `yaml:"dataid"`
Group string `yaml:"group"`
}
var optPathDirs = []string{"/opt", "./", "../", "../../"}
var nacosConfig *EnvConfig
func GetEnvCofing() *EnvConfig {
if nacosConfig != nil {
return nacosConfig
}
for _, optDir := range optPathDirs {
if optDir[len(optDir)-1] != '/' {
optDir = optDir + "/"
}
for _, yname := range []string{"env.yaml", "env.yml"} {
f, err := os.Open(optDir + yname)
if err != nil {
// log.Println(err)
continue
}
cfg := &EnvConfig{}
err = yaml.NewDecoder(f).Decode(&cfg)
if err != nil {
// log.Println(err)
continue
}
nacosConfig = cfg
return nacosConfig
}
}
panic("Can't find env.yaml or env.yml in the specified directories")
}
func init() {
}
func StartNacosConfig(configFile string, OnChange func(namespace, group, dataId, data string)) string {
env := GetEnvCofing()
// 创建serverConfig
// 支持多个;至少一个ServerConfig
var serverConfig []constant.ServerConfig
for _, s := range env.NacosServers {
sp := strings.Split(s, ":")
host := sp[0]
port, err := strconv.ParseUint(sp[1], 10, 64)
if err != nil {
panic(err)
}
serverConfig = append(serverConfig, constant.ServerConfig{
IpAddr: host,
Port: port,
})
}
// 创建clientConfig
clientConfig := constant.ClientConfig{
NamespaceId: env.NamespaceId, // 如果需要支持多namespace我们可以场景多个client,它们有不同的NamespaceId。当namespace是public时此处填空字符串。
TimeoutMs: 50000,
NotLoadCacheAtStart: true,
LogLevel: "debug",
LogDir: "/tmp/nacos/log",
CacheDir: "/tmp/nacos/cache",
Username: env.UserName,
Password: env.Password,
}
// 创建服务发现客户端的另一种方式 (推荐)
// namingClient, err := clients.NewNamingClient(
// vo.NacosClientParam{
// ClientConfig: &clientConfig,
// ServerConfigs: serverConfig,
// },
// )
// if err != nil {
// log.Fatalf("初始化nacos失败: %s", err.Error())
// }
// log.Println(namingClient)
// 创建 Nacos 配置客户端
configClient, err := clients.CreateConfigClient(map[string]interface{}{
"clientConfig": clientConfig,
"serverConfigs": serverConfig,
})
if err != nil {
log.Fatalf("Failed to create Nacos config client: %v", err)
}
cfgYamls := strings.Split(configFile, "/")
cfgYaml := cfgYamls[len(cfgYamls)-1]
yamlExt := filepath.Ext(cfgYaml)
if !(yamlExt == ".yaml" || yamlExt == ".yml") {
log.Panic(configFile)
}
// 获取配置
content, err := configClient.GetConfig(vo.ConfigParam{
DataId: cfgYaml,
Group: env.Group,
OnChange: OnChange,
})
if err != nil {
log.Fatalf("Failed to get config from Nacos: %v", err)
}
log.Println("加载成功:", cfgYaml)
return content
// log.Println(content)
}

View File

@ -0,0 +1,10 @@
package fsconfig_test
import (
"fusenapi/utils/fsconfig"
"testing"
)
func TestCase1(t *testing.T) {
fsconfig.StartNacosConfig("auth.yaml", nil)
}

View File

@ -14,15 +14,9 @@ func TestCase1(t *testing.T) {
}
conn := initalize.InitMysql("fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen")
err := fssql.MetadataModulePATCH(conn, "logo", gmodel.FsChangeCode{}, u, "id = ?", 6)
err := fssql.MetadataModulePATCH(conn, "profile", gmodel.FsUserInfo{}, u, "id = ?", 90)
if err != nil {
panic(err)
}
err = fssql.MetadataResourcePATCH(conn,
"f8932c0379fa5aa3397dc0a963696ca90536cc273ea10119b0137fd15ecfe673", u)
if err != nil {
panic(err)
}
}

View File

@ -5,9 +5,15 @@ func SetMetadata(metadataChild map[string]interface{}, oldMetadata map[string]in
for k, v := range metadataChild {
switch val := v.(type) {
case map[string]interface{}:
oldResourceMetadataData := oldMetadata[k].(map[string]interface{})
for key, val1 := range val {
oldResourceMetadataData[key] = val1
kValue, kEx := oldMetadata[k]
var oldResourceMetadataData map[string]interface{}
if kEx {
oldResourceMetadataData = kValue.(map[string]interface{})
} else {
oldResourceMetadataData = make(map[string]interface{}, len(val))
}
for key1, val1 := range val {
oldResourceMetadataData[key1] = val1
}
oldMetadata[k] = oldResourceMetadataData
default:
@ -20,11 +26,17 @@ func SetMetadata(metadataChild map[string]interface{}, oldMetadata map[string]in
for k, v := range metadataChild {
switch val := v.(type) {
case map[string]interface{}:
var resourceMetadataData = make(map[string]interface{}, len(val))
for key, val1 := range val {
resourceMetadataData[key] = val1
kValue, kEx := oldMetadata[k]
var oldResourceMetadataData map[string]interface{}
if kEx {
oldResourceMetadataData = kValue.(map[string]interface{})
} else {
oldResourceMetadataData = make(map[string]interface{}, len(val))
}
oldMetadata[k] = resourceMetadataData
for key, val1 := range val {
oldResourceMetadataData[key] = val1
}
oldMetadata[k] = oldResourceMetadataData
default:
oldMetadata[k] = val
}

View File

@ -15,17 +15,23 @@ type RenderImageReqMsg struct {
RenderData RenderData `json:"render_data"`
}
type RenderData struct {
TemplateTag string `json:"template_tag"` //模板标签(必须)
ProductId int64 `json:"product_id"` //产品id(必须)
Website string `json:"website"` //网站(可选)
Slogan string `json:"slogan"` //slogan(可选)
Address string `json:"address"` //地址(可选)
Phone string `json:"phone"` //电话(可选)
Qrcode string `json:"qrcode"` //二维码(可选)
ProductSizeId int64 `json:"product_size_id"` //尺寸id(可选)
UserId int64 `json:"user_id"` //用户id(websocket连接建立再赋值)
GuestId int64 `json:"guest_id"` //游客id(websocket连接建立再赋值)
Logo string `json:"logo"` //log资源地址(websocket连接建立再赋值)
TemplateTag string `json:"template_tag"` //模板标签(必须)
TemplateTagColor TemplateTagColor `json:"template_tag_color"` //模板标签组合颜色(必须)
TemplateTagGroups interface{} `json:"template_tag_groups"` //模板标签分组信息数组(必须)
Logo string `json:"logo"` //log资源地址(必须)
ProductId int64 `json:"product_id"` //产品id(必须)
Website string `json:"website"` //网站(可选)
Slogan string `json:"slogan"` //slogan(可选)
Address string `json:"address"` //地址(可选)
Phone string `json:"phone"` //电话(可选)
Qrcode string `json:"qrcode"` //二维码(可选)
ProductSizeId int64 `json:"product_size_id"` //尺寸id(可选)
UserId int64 `json:"user_id"` //用户id(websocket连接建立再赋值)
GuestId int64 `json:"guest_id"` //游客id(websocket连接建立再赋值)
}
type TemplateTagColor struct {
Color [][]string `json:"color"` //颜色组合
SelectedColorIndex int `json:"selected_color_index"` //主色的下标索引
}
// websocket发送渲染完的数据