feat: 完成查寝
This commit is contained in:
+2
-1
@@ -1,4 +1,5 @@
|
|||||||
.idea
|
.idea
|
||||||
.vscode
|
.vscode
|
||||||
.cursor
|
.cursor
|
||||||
node_modules
|
node_modules
|
||||||
|
.claude
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
ent-new:
|
||||||
|
cd internal;go run -mod=mod entgo.io/ent/cmd/ent new $(Name)
|
||||||
|
|
||||||
|
ent-gen:
|
||||||
|
go run . g
|
||||||
@@ -5,6 +5,9 @@ go 1.24
|
|||||||
require (
|
require (
|
||||||
entgo.io/ent v0.14.4
|
entgo.io/ent v0.14.4
|
||||||
github.com/PuerkitoBio/goquery v1.10.3
|
github.com/PuerkitoBio/goquery v1.10.3
|
||||||
|
github.com/aws/aws-sdk-go-v2 v1.36.6
|
||||||
|
github.com/aws/aws-sdk-go-v2/credentials v1.17.71
|
||||||
|
github.com/aws/aws-sdk-go-v2/service/s3 v1.84.1
|
||||||
github.com/bytedance/sonic v1.14.0
|
github.com/bytedance/sonic v1.14.0
|
||||||
github.com/deatil/go-cryptobin v1.1.1005
|
github.com/deatil/go-cryptobin v1.1.1005
|
||||||
github.com/go-sql-driver/mysql v1.9.3
|
github.com/go-sql-driver/mysql v1.9.3
|
||||||
@@ -30,23 +33,15 @@ require (
|
|||||||
github.com/andybalholm/cascadia v1.3.3 // indirect
|
github.com/andybalholm/cascadia v1.3.3 // indirect
|
||||||
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
|
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
|
||||||
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
|
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
|
||||||
github.com/aws/aws-sdk-go-v2 v1.36.6 // indirect
|
github.com/avast/retry-go/v4 v4.6.1 // indirect
|
||||||
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.11 // indirect
|
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.11 // indirect
|
||||||
github.com/aws/aws-sdk-go-v2/config v1.29.18 // indirect
|
|
||||||
github.com/aws/aws-sdk-go-v2/credentials v1.17.71 // indirect
|
|
||||||
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.33 // indirect
|
|
||||||
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.37 // indirect
|
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.37 // indirect
|
||||||
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.37 // indirect
|
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.37 // indirect
|
||||||
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.3 // indirect
|
|
||||||
github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.37 // indirect
|
github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.37 // indirect
|
||||||
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.4 // indirect
|
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.4 // indirect
|
||||||
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.7.5 // indirect
|
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.7.5 // indirect
|
||||||
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.18 // indirect
|
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.18 // indirect
|
||||||
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.18 // indirect
|
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.18 // indirect
|
||||||
github.com/aws/aws-sdk-go-v2/service/s3 v1.84.1 // indirect
|
|
||||||
github.com/aws/aws-sdk-go-v2/service/sso v1.25.6 // indirect
|
|
||||||
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.30.4 // indirect
|
|
||||||
github.com/aws/aws-sdk-go-v2/service/sts v1.34.1 // indirect
|
|
||||||
github.com/aws/smithy-go v1.22.4 // indirect
|
github.com/aws/smithy-go v1.22.4 // indirect
|
||||||
github.com/bmatcuk/doublestar v1.3.4 // indirect
|
github.com/bmatcuk/doublestar v1.3.4 // indirect
|
||||||
github.com/bytedance/sonic/loader v0.3.0 // indirect
|
github.com/bytedance/sonic/loader v0.3.0 // indirect
|
||||||
|
|||||||
@@ -18,22 +18,18 @@ github.com/apparentlymart/go-textseg/v13 v13.0.0 h1:Y+KvPE1NYz0xl601PVImeQfFyEy6
|
|||||||
github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkEghdlcqw7yxLeM89kiTRPUo=
|
github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkEghdlcqw7yxLeM89kiTRPUo=
|
||||||
github.com/apparentlymart/go-textseg/v15 v15.0.0 h1:uYvfpb3DyLSCGWnctWKGj857c6ew1u1fNQOlOtuGxQY=
|
github.com/apparentlymart/go-textseg/v15 v15.0.0 h1:uYvfpb3DyLSCGWnctWKGj857c6ew1u1fNQOlOtuGxQY=
|
||||||
github.com/apparentlymart/go-textseg/v15 v15.0.0/go.mod h1:K8XmNZdhEBkdlyDdvbmmsvpAG721bKi0joRfFdHIWJ4=
|
github.com/apparentlymart/go-textseg/v15 v15.0.0/go.mod h1:K8XmNZdhEBkdlyDdvbmmsvpAG721bKi0joRfFdHIWJ4=
|
||||||
|
github.com/avast/retry-go/v4 v4.6.1 h1:VkOLRubHdisGrHnTu89g08aQEWEgRU7LVEop3GbIcMk=
|
||||||
|
github.com/avast/retry-go/v4 v4.6.1/go.mod h1:V6oF8njAwxJ5gRo1Q7Cxab24xs5NCWZBeaHHBklR8mA=
|
||||||
github.com/aws/aws-sdk-go-v2 v1.36.6 h1:zJqGjVbRdTPojeCGWn5IR5pbJwSQSBh5RWFTQcEQGdU=
|
github.com/aws/aws-sdk-go-v2 v1.36.6 h1:zJqGjVbRdTPojeCGWn5IR5pbJwSQSBh5RWFTQcEQGdU=
|
||||||
github.com/aws/aws-sdk-go-v2 v1.36.6/go.mod h1:EYrzvCCN9CMUTa5+6lf6MM4tq3Zjp8UhSGR/cBsjai0=
|
github.com/aws/aws-sdk-go-v2 v1.36.6/go.mod h1:EYrzvCCN9CMUTa5+6lf6MM4tq3Zjp8UhSGR/cBsjai0=
|
||||||
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.11 h1:12SpdwU8Djs+YGklkinSSlcrPyj3H4VifVsKf78KbwA=
|
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.11 h1:12SpdwU8Djs+YGklkinSSlcrPyj3H4VifVsKf78KbwA=
|
||||||
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.11/go.mod h1:dd+Lkp6YmMryke+qxW/VnKyhMBDTYP41Q2Bb+6gNZgY=
|
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.11/go.mod h1:dd+Lkp6YmMryke+qxW/VnKyhMBDTYP41Q2Bb+6gNZgY=
|
||||||
github.com/aws/aws-sdk-go-v2/config v1.29.18 h1:x4T1GRPnqKV8HMJOMtNktbpQMl3bIsfx8KbqmveUO2I=
|
|
||||||
github.com/aws/aws-sdk-go-v2/config v1.29.18/go.mod h1:bvz8oXugIsH8K7HLhBv06vDqnFv3NsGDt2Znpk7zmOU=
|
|
||||||
github.com/aws/aws-sdk-go-v2/credentials v1.17.71 h1:r2w4mQWnrTMJjOyIsZtGp3R3XGY3nqHn8C26C2lQWgA=
|
github.com/aws/aws-sdk-go-v2/credentials v1.17.71 h1:r2w4mQWnrTMJjOyIsZtGp3R3XGY3nqHn8C26C2lQWgA=
|
||||||
github.com/aws/aws-sdk-go-v2/credentials v1.17.71/go.mod h1:E7VF3acIup4GB5ckzbKFrCK0vTvEQxOxgdq4U3vcMCY=
|
github.com/aws/aws-sdk-go-v2/credentials v1.17.71/go.mod h1:E7VF3acIup4GB5ckzbKFrCK0vTvEQxOxgdq4U3vcMCY=
|
||||||
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.33 h1:D9ixiWSG4lyUBL2DDNK924Px9V/NBVpML90MHqyTADY=
|
|
||||||
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.33/go.mod h1:caS/m4DI+cij2paz3rtProRBI4s/+TCiWoaWZuQ9010=
|
|
||||||
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.37 h1:osMWfm/sC/L4tvEdQ65Gri5ZZDCUpuYJZbTTDrsn4I0=
|
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.37 h1:osMWfm/sC/L4tvEdQ65Gri5ZZDCUpuYJZbTTDrsn4I0=
|
||||||
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.37/go.mod h1:ZV2/1fbjOPr4G4v38G3Ww5TBT4+hmsK45s/rxu1fGy0=
|
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.37/go.mod h1:ZV2/1fbjOPr4G4v38G3Ww5TBT4+hmsK45s/rxu1fGy0=
|
||||||
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.37 h1:v+X21AvTb2wZ+ycg1gx+orkB/9U6L7AOp93R7qYxsxM=
|
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.37 h1:v+X21AvTb2wZ+ycg1gx+orkB/9U6L7AOp93R7qYxsxM=
|
||||||
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.37/go.mod h1:G0uM1kyssELxmJ2VZEfG0q2npObR3BAkF3c1VsfVnfs=
|
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.37/go.mod h1:G0uM1kyssELxmJ2VZEfG0q2npObR3BAkF3c1VsfVnfs=
|
||||||
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.3 h1:bIqFDwgGXXN1Kpp99pDOdKMTTb5d2KyU5X/BZxjOkRo=
|
|
||||||
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.3/go.mod h1:H5O/EsxDWyU+LP/V8i5sm8cxoZgc2fdNR9bxlOFrQTo=
|
|
||||||
github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.37 h1:XTZZ0I3SZUHAtBLBU6395ad+VOblE0DwQP6MuaNeics=
|
github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.37 h1:XTZZ0I3SZUHAtBLBU6395ad+VOblE0DwQP6MuaNeics=
|
||||||
github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.37/go.mod h1:Pi6ksbniAWVwu2S8pEzcYPyhUkAcLaufxN7PfAUQjBk=
|
github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.37/go.mod h1:Pi6ksbniAWVwu2S8pEzcYPyhUkAcLaufxN7PfAUQjBk=
|
||||||
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.4 h1:CXV68E2dNqhuynZJPB80bhPQwAKqBWVer887figW6Jc=
|
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.4 h1:CXV68E2dNqhuynZJPB80bhPQwAKqBWVer887figW6Jc=
|
||||||
@@ -46,12 +42,6 @@ github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.18 h1:OS2e0SKqsU2Li
|
|||||||
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.18/go.mod h1:+Yrk+MDGzlNGxCXieljNeWpoZTCQUQVL+Jk9hGGJ8qM=
|
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.18/go.mod h1:+Yrk+MDGzlNGxCXieljNeWpoZTCQUQVL+Jk9hGGJ8qM=
|
||||||
github.com/aws/aws-sdk-go-v2/service/s3 v1.84.1 h1:RkHXU9jP0DptGy7qKI8CBGsUJruWz0v5IgwBa2DwWcU=
|
github.com/aws/aws-sdk-go-v2/service/s3 v1.84.1 h1:RkHXU9jP0DptGy7qKI8CBGsUJruWz0v5IgwBa2DwWcU=
|
||||||
github.com/aws/aws-sdk-go-v2/service/s3 v1.84.1/go.mod h1:3xAOf7tdKF+qbb+XpU+EPhNXAdun3Lu1RcDrj8KC24I=
|
github.com/aws/aws-sdk-go-v2/service/s3 v1.84.1/go.mod h1:3xAOf7tdKF+qbb+XpU+EPhNXAdun3Lu1RcDrj8KC24I=
|
||||||
github.com/aws/aws-sdk-go-v2/service/sso v1.25.6 h1:rGtWqkQbPk7Bkwuv3NzpE/scwwL9sC1Ul3tn9x83DUI=
|
|
||||||
github.com/aws/aws-sdk-go-v2/service/sso v1.25.6/go.mod h1:u4ku9OLv4TO4bCPdxf4fA1upaMaJmP9ZijGk3AAOC6Q=
|
|
||||||
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.30.4 h1:OV/pxyXh+eMA0TExHEC4jyWdumLxNbzz1P0zJoezkJc=
|
|
||||||
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.30.4/go.mod h1:8Mm5VGYwtm+r305FfPSuc+aFkrypeylGYhFim6XEPoc=
|
|
||||||
github.com/aws/aws-sdk-go-v2/service/sts v1.34.1 h1:aUrLQwJfZtwv3/ZNG2xRtEen+NqI3iesuacjP51Mv1s=
|
|
||||||
github.com/aws/aws-sdk-go-v2/service/sts v1.34.1/go.mod h1:3wFBZKoWnX3r+Sm7in79i54fBmNfwhdNdQuscCw7QIk=
|
|
||||||
github.com/aws/smithy-go v1.22.4 h1:uqXzVZNuNexwc/xrh6Tb56u89WDlJY6HS+KC0S4QSjw=
|
github.com/aws/smithy-go v1.22.4 h1:uqXzVZNuNexwc/xrh6Tb56u89WDlJY6HS+KC0S4QSjw=
|
||||||
github.com/aws/smithy-go v1.22.4/go.mod h1:t1ufH5HMublsJYulve2RKmHDC15xu1f26kHCp/HgceI=
|
github.com/aws/smithy-go v1.22.4/go.mod h1:t1ufH5HMublsJYulve2RKmHDC15xu1f26kHCp/HgceI=
|
||||||
github.com/bmatcuk/doublestar v1.3.4 h1:gPypJ5xD31uhX6Tf54sDPUOBXTqKH4c9aPY66CyQrS0=
|
github.com/bmatcuk/doublestar v1.3.4 h1:gPypJ5xD31uhX6Tf54sDPUOBXTqKH4c9aPY66CyQrS0=
|
||||||
@@ -116,6 +106,8 @@ github.com/grokify/html-strip-tags-go v0.1.0 h1:03UrQLjAny8xci+R+qjCce/MYnpNXCtg
|
|||||||
github.com/grokify/html-strip-tags-go v0.1.0/go.mod h1:ZdzgfHEzAfz9X6Xe5eBLVblWIxXfYSQ40S/VKrAOGpc=
|
github.com/grokify/html-strip-tags-go v0.1.0/go.mod h1:ZdzgfHEzAfz9X6Xe5eBLVblWIxXfYSQ40S/VKrAOGpc=
|
||||||
github.com/hashicorp/hcl/v2 v2.13.0 h1:0Apadu1w6M11dyGFxWnmhhcMjkbAiKCv7G1r/2QgCNc=
|
github.com/hashicorp/hcl/v2 v2.13.0 h1:0Apadu1w6M11dyGFxWnmhhcMjkbAiKCv7G1r/2QgCNc=
|
||||||
github.com/hashicorp/hcl/v2 v2.13.0/go.mod h1:e4z5nxYlWNPdDSNYX+ph14EvWYMFm3eP0zIUqPc2jr0=
|
github.com/hashicorp/hcl/v2 v2.13.0/go.mod h1:e4z5nxYlWNPdDSNYX+ph14EvWYMFm3eP0zIUqPc2jr0=
|
||||||
|
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
||||||
|
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
|
||||||
github.com/joomcode/errorx v1.2.0 h1:7Y/fguon+9r6a/75Rv3nrUwS7nXNEcJjLShjCvz00Og=
|
github.com/joomcode/errorx v1.2.0 h1:7Y/fguon+9r6a/75Rv3nrUwS7nXNEcJjLShjCvz00Og=
|
||||||
github.com/joomcode/errorx v1.2.0/go.mod h1:Mbz68VA9hsQLT50iCQQUZ2Z1XYAKYB4EoFkFCTFyiJM=
|
github.com/joomcode/errorx v1.2.0/go.mod h1:Mbz68VA9hsQLT50iCQQUZ2Z1XYAKYB4EoFkFCTFyiJM=
|
||||||
github.com/klauspost/cpuid/v2 v2.0.9 h1:lgaqFMSdTdQYdZ04uHyN2d/eKdOMyi2YLSvlQIBFYa4=
|
github.com/klauspost/cpuid/v2 v2.0.9 h1:lgaqFMSdTdQYdZ04uHyN2d/eKdOMyi2YLSvlQIBFYa4=
|
||||||
@@ -173,6 +165,8 @@ github.com/spf13/afero v1.12.0 h1:UcOPyRBYczmFn6yvphxkn9ZEOY65cpwGKb5mL36mrqs=
|
|||||||
github.com/spf13/afero v1.12.0/go.mod h1:ZTlWwG4/ahT8W7T0WQ5uYmjI9duaLQGy3Q2OAl4sk/4=
|
github.com/spf13/afero v1.12.0/go.mod h1:ZTlWwG4/ahT8W7T0WQ5uYmjI9duaLQGy3Q2OAl4sk/4=
|
||||||
github.com/spf13/cast v1.7.1 h1:cuNEagBQEHWN1FnbGEjCXL2szYEXqfJPbP2HNUaca9Y=
|
github.com/spf13/cast v1.7.1 h1:cuNEagBQEHWN1FnbGEjCXL2szYEXqfJPbP2HNUaca9Y=
|
||||||
github.com/spf13/cast v1.7.1/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
|
github.com/spf13/cast v1.7.1/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
|
||||||
|
github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I=
|
||||||
|
github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0=
|
||||||
github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
|
github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
|
||||||
github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||||
github.com/spf13/viper v1.20.1 h1:ZMi+z/lvLyPSCoNtFCpqjy0S4kPbirhpTMwl8BkW9X4=
|
github.com/spf13/viper v1.20.1 h1:ZMi+z/lvLyPSCoNtFCpqjy0S4kPbirhpTMwl8BkW9X4=
|
||||||
|
|||||||
@@ -35,3 +35,29 @@ func AesDecrypt(data []byte) []byte {
|
|||||||
return decryptResult.
|
return decryptResult.
|
||||||
ToBytes()
|
ToBytes()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func AesEncryptForCat(data []byte) []byte {
|
||||||
|
return crypto.FromBytes(data).
|
||||||
|
WithKey(AesKeyForCat).
|
||||||
|
WithIv(AesIv).
|
||||||
|
Aes().
|
||||||
|
CBC().
|
||||||
|
PKCS7Padding().
|
||||||
|
Encrypt().
|
||||||
|
ToBytes()
|
||||||
|
}
|
||||||
|
|
||||||
|
func AesDecryptForCat(data []byte) []byte {
|
||||||
|
decryptResult := crypto.FromBytes(data).
|
||||||
|
WithKey(AesKeyForCat).
|
||||||
|
WithIv(AesIv).
|
||||||
|
Aes().
|
||||||
|
CBC().
|
||||||
|
PKCS7Padding().
|
||||||
|
Decrypt()
|
||||||
|
|
||||||
|
utils.OkOrPanic(decryptResult.Error())
|
||||||
|
|
||||||
|
return decryptResult.
|
||||||
|
ToBytes()
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,62 @@
|
|||||||
|
package cryptoutil
|
||||||
|
|
||||||
|
import (
|
||||||
|
"likedream-goframe/internal/common/errors"
|
||||||
|
"likedream-goframe/internal/utils"
|
||||||
|
|
||||||
|
"github.com/deatil/go-cryptobin/cryptobin/crypto"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
DesKey = []byte("XCE927==")
|
||||||
|
DesKeyForCat = []byte("b3L26XNL")
|
||||||
|
DesIv = []byte{1, 2, 3, 4, 5, 6, 7, 8}
|
||||||
|
)
|
||||||
|
|
||||||
|
// DesEncrypt DES加密函数
|
||||||
|
func DesEncrypt(src []byte, keyType CpdailyKeyType) []byte {
|
||||||
|
var key []byte
|
||||||
|
switch keyType {
|
||||||
|
case Normal:
|
||||||
|
key = DesKey
|
||||||
|
case Cat:
|
||||||
|
key = DesKeyForCat
|
||||||
|
default:
|
||||||
|
utils.OkOrPanic(errors.NewBusinessError(400, "无效的密钥类型"))
|
||||||
|
}
|
||||||
|
|
||||||
|
return crypto.FromBytes(src).
|
||||||
|
WithKey(key).
|
||||||
|
WithIv(DesIv).
|
||||||
|
Des().
|
||||||
|
CBC().
|
||||||
|
PKCS7Padding().
|
||||||
|
Encrypt().
|
||||||
|
ToBytes()
|
||||||
|
}
|
||||||
|
|
||||||
|
// DesDecrypt DES解密函数
|
||||||
|
func DesDecrypt(src []byte, keyType CpdailyKeyType) []byte {
|
||||||
|
var key []byte
|
||||||
|
switch keyType {
|
||||||
|
case Normal:
|
||||||
|
key = DesKey
|
||||||
|
case Cat:
|
||||||
|
key = DesKeyForCat
|
||||||
|
default:
|
||||||
|
utils.OkOrPanic(errors.NewBusinessError(400, "无效的密钥类型"))
|
||||||
|
}
|
||||||
|
|
||||||
|
decryptResult := crypto.FromBytes(src).
|
||||||
|
WithKey(key).
|
||||||
|
WithIv(DesIv).
|
||||||
|
Des().
|
||||||
|
CBC().
|
||||||
|
PKCS7Padding().
|
||||||
|
Decrypt()
|
||||||
|
|
||||||
|
utils.OkOrPanic(decryptResult.Error())
|
||||||
|
|
||||||
|
return decryptResult.
|
||||||
|
ToBytes()
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package cryptoutil
|
||||||
|
|
||||||
|
// CpdailyKeyType 定义密钥类型枚举
|
||||||
|
type CpdailyKeyType int
|
||||||
|
|
||||||
|
const (
|
||||||
|
Normal CpdailyKeyType = iota
|
||||||
|
Cat
|
||||||
|
)
|
||||||
@@ -0,0 +1,171 @@
|
|||||||
|
package imageuploader
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"likedream-goframe/internal/application/cpdaily/types"
|
||||||
|
"likedream-goframe/internal/application/filestorage"
|
||||||
|
"likedream-goframe/internal/common/errors"
|
||||||
|
"likedream-goframe/internal/db"
|
||||||
|
"likedream-goframe/internal/ent"
|
||||||
|
"likedream-goframe/internal/ent/cpimage"
|
||||||
|
"likedream-goframe/internal/utils"
|
||||||
|
|
||||||
|
"github.com/bytedance/sonic"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
"github.com/samber/oops"
|
||||||
|
"resty.dev/v3"
|
||||||
|
)
|
||||||
|
|
||||||
|
// CpImageUploadPolicy 结构体用于表示图片上传策略的相关信息
|
||||||
|
type CpImageUploadPolicy struct {
|
||||||
|
AccessId string `json:"accessid"`
|
||||||
|
FileName string `json:"fileName"`
|
||||||
|
Policy string `json:"policy"`
|
||||||
|
Host string `json:"host"`
|
||||||
|
Signature string `json:"signature"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func UploadImageFromStorage(ctx context.Context, host string, imageId uuid.UUID, taskType types.TaskType, client *resty.Client) string {
|
||||||
|
targetImage, e := db.Global.CpImage.Query().
|
||||||
|
Where(cpimage.ImageID(imageId)).
|
||||||
|
Select(cpimage.FieldKey, cpimage.FieldContentType).
|
||||||
|
Only(ctx)
|
||||||
|
|
||||||
|
if e != nil {
|
||||||
|
if ent.IsNotFound(e) {
|
||||||
|
utils.OkOrPanic(errors.NewBusinessError(503, "图片不存在"), oops.WithContext(ctx).Wrap)
|
||||||
|
}
|
||||||
|
utils.OkOrPanic(e, oops.WithContext(ctx).Wrap)
|
||||||
|
}
|
||||||
|
|
||||||
|
imageUploadPolicy := GetUploadPolicyAsync(ctx, host, taskType, client)
|
||||||
|
|
||||||
|
targetFile := filestorage.GlobalS3.GetFile(ctx, targetImage.Key)
|
||||||
|
|
||||||
|
resp, e := client.R().
|
||||||
|
SetMultipartFields(&resty.MultipartField{
|
||||||
|
Name: "x-obs-acl",
|
||||||
|
Values: []string{"public-read"},
|
||||||
|
}, &resty.MultipartField{
|
||||||
|
Name: "AccessKeyId",
|
||||||
|
Values: []string{imageUploadPolicy.AccessId},
|
||||||
|
}, &resty.MultipartField{
|
||||||
|
Name: "key",
|
||||||
|
Values: []string{imageUploadPolicy.FileName},
|
||||||
|
}, &resty.MultipartField{
|
||||||
|
Name: "signature",
|
||||||
|
Values: []string{imageUploadPolicy.Signature},
|
||||||
|
}, &resty.MultipartField{
|
||||||
|
Name: "policy",
|
||||||
|
Values: []string{imageUploadPolicy.Policy},
|
||||||
|
}, &resty.MultipartField{
|
||||||
|
Name: "content-type",
|
||||||
|
Values: []string{targetImage.ContentType},
|
||||||
|
}, &resty.MultipartField{
|
||||||
|
Name: "file",
|
||||||
|
FileName: "file",
|
||||||
|
Reader: targetFile,
|
||||||
|
}).
|
||||||
|
Post(imageUploadPolicy.Host)
|
||||||
|
|
||||||
|
utils.OkOrPanic(e, oops.WithContext(ctx).Wrap)
|
||||||
|
|
||||||
|
if resp.StatusCode() > 299 {
|
||||||
|
utils.OkOrPanic(errors.NewBusinessError(503, "上传图片失败: "+utils.ReadString(resp.Body)), oops.WithContext(ctx).With("response", utils.ReadString(resp.Body)).Wrap)
|
||||||
|
}
|
||||||
|
|
||||||
|
previewUrl := GetPreviewUrlAsync(ctx, host, targetImage.Key, taskType, client)
|
||||||
|
|
||||||
|
return previewUrl
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetPreviewUrlAsync 用于获取图片预览地址
|
||||||
|
func GetPreviewUrlAsync(ctx context.Context, host string, fileKey string, taskType types.TaskType, client *resty.Client) string {
|
||||||
|
var apiPath string
|
||||||
|
if taskType == types.TaskTypeSleepCheck {
|
||||||
|
apiPath = "/previewAttachment"
|
||||||
|
} else {
|
||||||
|
apiPath = "/sign/previewAttachment"
|
||||||
|
}
|
||||||
|
urlPrefix := GetImageUploadUrlPrefix(ctx, taskType)
|
||||||
|
fullUrl := host + urlPrefix + apiPath
|
||||||
|
|
||||||
|
reqBody := map[string]interface{}{
|
||||||
|
"ossKey": fileKey,
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := client.R().
|
||||||
|
SetBody(reqBody).
|
||||||
|
Post(fullUrl)
|
||||||
|
utils.OkOrPanic(err, oops.WithContext(ctx).Wrap)
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
responseJSON := utils.ReadJson[map[string]*json.RawMessage](resp.Body)
|
||||||
|
datas := responseJSON["datas"]
|
||||||
|
|
||||||
|
if datas == nil {
|
||||||
|
utils.OkOrPanic(errors.NewBusinessError(404, "上传图片URL为空"), oops.WithContext(ctx).With("response", responseJSON).Wrap)
|
||||||
|
}
|
||||||
|
|
||||||
|
var previewUrl string
|
||||||
|
utils.OkOrPanic(sonic.Unmarshal(*datas, &previewUrl), oops.WithContext(ctx).Wrap)
|
||||||
|
return previewUrl
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetUploadPolicyAsync 用于获取图片上传策略
|
||||||
|
func GetUploadPolicyAsync(ctx context.Context, host string, taskType types.TaskType, client *resty.Client) *CpImageUploadPolicy {
|
||||||
|
// 构造请求路径
|
||||||
|
urlPrefix := GetImageUploadUrlPrefix(ctx, taskType)
|
||||||
|
var apiPath string
|
||||||
|
if taskType == types.TaskTypeSleepCheck {
|
||||||
|
apiPath = "/getUploadPolicy"
|
||||||
|
} else {
|
||||||
|
apiPath = "/obs/getUploadPolicy"
|
||||||
|
}
|
||||||
|
fullUrl := host + urlPrefix + apiPath
|
||||||
|
|
||||||
|
// 构造请求体
|
||||||
|
reqBody := map[string]interface{}{
|
||||||
|
"fileType": 1,
|
||||||
|
}
|
||||||
|
|
||||||
|
// 构造请求
|
||||||
|
req := client.R().SetBody(reqBody)
|
||||||
|
|
||||||
|
// 发送请求
|
||||||
|
resp, err := req.Post(fullUrl)
|
||||||
|
if err != nil {
|
||||||
|
utils.OkOrPanic(err, oops.WithContext(ctx).Wrap)
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
responseJSON := utils.ReadJson[map[string]*json.RawMessage](resp.Body)
|
||||||
|
|
||||||
|
datas := responseJSON["datas"]
|
||||||
|
|
||||||
|
if datas == nil {
|
||||||
|
utils.OkOrPanic(errors.NewBusinessError(503, "获取图片上传策略失败: 响应中缺少 datas 字段"), oops.WithContext(ctx).With("response", responseJSON).Wrap)
|
||||||
|
}
|
||||||
|
|
||||||
|
var policy CpImageUploadPolicy
|
||||||
|
|
||||||
|
utils.OkOrPanic(sonic.Unmarshal(*datas, &policy), oops.WithContext(ctx).Wrap)
|
||||||
|
|
||||||
|
return &policy
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetImageUploadUrlPrefix 根据任务类型返回图片上传的URL前缀
|
||||||
|
func GetImageUploadUrlPrefix(ctx context.Context, taskType types.TaskType) string {
|
||||||
|
switch taskType {
|
||||||
|
case types.TaskTypeSleepCheck:
|
||||||
|
return "/wec-counselor-attendance-apps/student/attendance"
|
||||||
|
case types.TaskTypeSign:
|
||||||
|
return "/wec-counselor-sign-apps/stu"
|
||||||
|
case types.TaskTypeCollection:
|
||||||
|
return "/wec-counselor-collector-apps/student/collector"
|
||||||
|
default:
|
||||||
|
utils.OkOrPanic(errors.NewBusinessError(503, "未知的任务类型"), oops.WithContext(ctx).Wrap)
|
||||||
|
panic("unreachable")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package cpdaily
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
|
"likedream-goframe/internal/cst"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Info struct {
|
||||||
|
AppVersion string `json:"appVersion"`
|
||||||
|
SystemVersion string `json:"systemVersion"`
|
||||||
|
CalVersion string `json:"calVersion"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetInfo(ctx context.Context) *Info {
|
||||||
|
cfg := g.Config()
|
||||||
|
return &Info{
|
||||||
|
AppVersion: cfg.MustGetWithEnv(ctx, cst.ConfigCpdailyAppVersion).String(),
|
||||||
|
SystemVersion: cfg.MustGetWithEnv(ctx, cst.ConfigCpdailySystemVersion).String(),
|
||||||
|
CalVersion: cfg.MustGetWithEnv(ctx, cst.ConfigCpdailyCalVersion).String(),
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,9 @@
|
|||||||
package submitcaptcha
|
package submitcaptcha
|
||||||
|
|
||||||
import "encoding/json"
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
)
|
||||||
|
|
||||||
// ValidationInfo 验证信息结构体
|
// ValidationInfo 验证信息结构体
|
||||||
type ValidationInfo struct {
|
type ValidationInfo struct {
|
||||||
@@ -36,6 +39,6 @@ type ITStarResponse struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type SubmitCaptchaResolver interface {
|
type SubmitCaptchaResolver interface {
|
||||||
GetValidationInfo() ValidationInfo
|
GetValidationInfo(ctx context.Context) ValidationInfo
|
||||||
GetCaptchaTicket(info ValidationInfo) string
|
GetCaptchaTicket(ctx context.Context, info ValidationInfo) string
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,18 @@
|
|||||||
package submitcaptcha
|
package submitcaptcha
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"likedream-goframe/internal/application/cpdaily/task"
|
"likedream-goframe/internal/application/cpdaily/types"
|
||||||
"likedream-goframe/internal/common/errors"
|
"likedream-goframe/internal/common/errors"
|
||||||
"likedream-goframe/internal/cst"
|
"likedream-goframe/internal/cst"
|
||||||
"likedream-goframe/internal/utils"
|
"likedream-goframe/internal/utils"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/bytedance/sonic"
|
"github.com/bytedance/sonic"
|
||||||
"github.com/spf13/viper"
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
|
"github.com/gogf/gf/v2/os/gctx"
|
||||||
"resty.dev/v3"
|
"resty.dev/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -18,13 +20,15 @@ type RuoliSubmitCaptchaResolver struct {
|
|||||||
client *resty.Client
|
client *resty.Client
|
||||||
host string
|
host string
|
||||||
deviceId string
|
deviceId string
|
||||||
taskType task.TaskType
|
taskType types.TaskType
|
||||||
itstarUrl string
|
itstarUrl string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var _ SubmitCaptchaResolver = (*RuoliSubmitCaptchaResolver)(nil)
|
||||||
|
|
||||||
// NewRuoliResolver 创建若李验证码解析器
|
// NewRuoliResolver 创建若李验证码解析器
|
||||||
func NewRuoliResolver(client *resty.Client, host, deviceId string, taskType task.TaskType) *RuoliSubmitCaptchaResolver {
|
func NewRuoliResolver(client *resty.Client, host, deviceId string, taskType types.TaskType) *RuoliSubmitCaptchaResolver {
|
||||||
baseUrl := viper.GetString(cst.ConfigRuoliCaptchaBaseUrl)
|
baseUrl := g.Config().MustGetWithEnv(gctx.GetInitCtx(), cst.ConfigRuoliCaptchaBaseUrl).String()
|
||||||
return &RuoliSubmitCaptchaResolver{
|
return &RuoliSubmitCaptchaResolver{
|
||||||
client: client,
|
client: client,
|
||||||
host: host,
|
host: host,
|
||||||
@@ -40,7 +44,7 @@ func (r *RuoliSubmitCaptchaResolver) getITStarUrl() string {
|
|||||||
return r.itstarUrl
|
return r.itstarUrl
|
||||||
}
|
}
|
||||||
|
|
||||||
r.itstarUrl = viper.GetString(cst.ConfigRuoliCaptchaBaseUrl)
|
r.itstarUrl = g.Config().MustGetWithEnv(gctx.GetInitCtx(), cst.ConfigRuoliCaptchaBaseUrl).String()
|
||||||
if r.itstarUrl == "" {
|
if r.itstarUrl == "" {
|
||||||
utils.OkOrPanic(errors.NewBusinessError(500, "未配置ITStarUrl"))
|
utils.OkOrPanic(errors.NewBusinessError(500, "未配置ITStarUrl"))
|
||||||
}
|
}
|
||||||
@@ -53,11 +57,11 @@ func (r *RuoliSubmitCaptchaResolver) getValidateUrl() string {
|
|||||||
baseUrl := strings.TrimSuffix(r.host, "/")
|
baseUrl := strings.TrimSuffix(r.host, "/")
|
||||||
|
|
||||||
switch r.taskType {
|
switch r.taskType {
|
||||||
case task.TypeCollection:
|
case types.TaskTypeCollection:
|
||||||
return baseUrl + "/wec-counselor-collector-apps/stu/collector/checkValidation"
|
return baseUrl + "/wec-counselor-collector-apps/stu/collector/checkValidation"
|
||||||
case task.TypeSign:
|
case types.TaskTypeSign:
|
||||||
return baseUrl + "/wec-counselor-sign-apps/stu/sign/checkValidation"
|
return baseUrl + "/wec-counselor-sign-apps/stu/sign/checkValidation"
|
||||||
case task.TypeSleepCheck:
|
case types.TaskTypeSleepCheck:
|
||||||
return baseUrl + "/wec-counselor-attendance-apps/student/attendance/checkValidation"
|
return baseUrl + "/wec-counselor-attendance-apps/student/attendance/checkValidation"
|
||||||
default:
|
default:
|
||||||
utils.OkOrPanic(errors.NewBusinessError(400, "不支持的任务类型"))
|
utils.OkOrPanic(errors.NewBusinessError(400, "不支持的任务类型"))
|
||||||
@@ -66,7 +70,7 @@ func (r *RuoliSubmitCaptchaResolver) getValidateUrl() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetValidationInfo 获取验证信息
|
// GetValidationInfo 获取验证信息
|
||||||
func (r *RuoliSubmitCaptchaResolver) GetValidationInfo() ValidationInfo {
|
func (r *RuoliSubmitCaptchaResolver) GetValidationInfo(ctx context.Context) ValidationInfo {
|
||||||
reqData := map[string]string{
|
reqData := map[string]string{
|
||||||
"deviceId": r.deviceId,
|
"deviceId": r.deviceId,
|
||||||
}
|
}
|
||||||
@@ -94,7 +98,7 @@ func (r *RuoliSubmitCaptchaResolver) GetValidationInfo() ValidationInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetCaptchaTicket 获取验证码票据
|
// GetCaptchaTicket 获取验证码票据
|
||||||
func (r *RuoliSubmitCaptchaResolver) GetCaptchaTicket(info ValidationInfo) string {
|
func (r *RuoliSubmitCaptchaResolver) GetCaptchaTicket(ctx context.Context, info ValidationInfo) string {
|
||||||
captchaInfo := r.createCaptcha(info)
|
captchaInfo := r.createCaptcha(info)
|
||||||
codes := r.getResultFromItStar(captchaInfo.RawResponseJson)
|
codes := r.getResultFromItStar(captchaInfo.RawResponseJson)
|
||||||
return r.submitCaptcha(info, captchaInfo, codes)
|
return r.submitCaptcha(info, captchaInfo, codes)
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
package submitcaptcha
|
package submitcaptcha
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"likedream-goframe/internal/application/cpdaily/task"
|
"context"
|
||||||
|
"likedream-goframe/internal/application/cpdaily/types"
|
||||||
"likedream-goframe/internal/testutil"
|
"likedream-goframe/internal/testutil"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
@@ -9,9 +10,9 @@ import (
|
|||||||
func TestRuoliSubmitCaptchaResolver_GetCaptchaTicket(t *testing.T) {
|
func TestRuoliSubmitCaptchaResolver_GetCaptchaTicket(t *testing.T) {
|
||||||
loginClient, detail := testutil.LoginTestUser()
|
loginClient, detail := testutil.LoginTestUser()
|
||||||
|
|
||||||
resolver := NewRuoliResolver(loginClient, detail.WecloudUrl, "abcdefg", task.TypeSleepCheck)
|
resolver := NewRuoliResolver(loginClient, detail.WecloudUrl, "abcdefg", types.TaskTypeSleepCheck)
|
||||||
|
|
||||||
info := resolver.GetValidationInfo()
|
info := resolver.GetValidationInfo(context.Background())
|
||||||
|
|
||||||
t.Logf("%#v", info)
|
t.Logf("%#v", info)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,4 +14,5 @@ type CpTaskFormItem struct {
|
|||||||
LogicWid string `json:"logicWid,omitempty"`
|
LogicWid string `json:"logicWid,omitempty"`
|
||||||
Sort uint `json:"sort,omitempty"`
|
Sort uint `json:"sort,omitempty"`
|
||||||
CacheKey string `json:"cacheKey,omitempty"`
|
CacheKey string `json:"cacheKey,omitempty"`
|
||||||
|
Show bool `json:"show,omitempty"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ type CpdailyTask interface {
|
|||||||
GetRecentTaskTitle(ctx context.Context) []string
|
GetRecentTaskTitle(ctx context.Context) []string
|
||||||
QueryFormByTitle(ctx context.Context, titleGlob string) map[string]*gvar.Var
|
QueryFormByTitle(ctx context.Context, titleGlob string) map[string]*gvar.Var
|
||||||
QueryFormByYearMonth(ctx context.Context, titleGlob string, year, month string) map[string]*gvar.Var
|
QueryFormByYearMonth(ctx context.Context, titleGlob string, year, month string) map[string]*gvar.Var
|
||||||
ParseFormJson(ctx context.Context, rawJson map[string]*gvar.Var) []formtype.CpTaskFormItem
|
ParseFormJson(ctx context.Context, rawJson map[string]*gvar.Var) []*formtype.CpTaskFormItem
|
||||||
FillCustomForm(ctx context.Context, form map[string]*gvar.Var, paramList []formtype.CpTaskFormItem, deviceId, username string) map[string]*gvar.Var
|
FillCustomForm(ctx context.Context, form map[string]*gvar.Var, paramList []*formtype.CpTaskFormItem, deviceId, username string) map[string]*gvar.Var
|
||||||
Submit(ctx context.Context, form map[string]*gvar.Var, username, deviceId string)
|
Submit(ctx context.Context, form map[string]*gvar.Var, username, deviceId string)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,15 +3,24 @@ package task
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"likedream-goframe/internal/application/cpdaily"
|
||||||
|
"likedream-goframe/internal/application/cpdaily/cryptoutil"
|
||||||
|
"likedream-goframe/internal/application/cpdaily/imageuploader"
|
||||||
|
"likedream-goframe/internal/application/cpdaily/submitcaptcha"
|
||||||
"likedream-goframe/internal/application/cpdaily/task/formtype"
|
"likedream-goframe/internal/application/cpdaily/task/formtype"
|
||||||
|
"likedream-goframe/internal/application/cpdaily/taskhelper"
|
||||||
|
"likedream-goframe/internal/application/cpdaily/types"
|
||||||
"likedream-goframe/internal/common/errors"
|
"likedream-goframe/internal/common/errors"
|
||||||
"likedream-goframe/internal/cst"
|
"likedream-goframe/internal/cst"
|
||||||
"likedream-goframe/internal/utils"
|
"likedream-goframe/internal/utils"
|
||||||
|
"math/rand/v2"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/avast/retry-go/v4"
|
||||||
"github.com/gogf/gf/v2/container/gvar"
|
"github.com/gogf/gf/v2/container/gvar"
|
||||||
|
"github.com/google/uuid"
|
||||||
"github.com/samber/oops"
|
"github.com/samber/oops"
|
||||||
"github.com/tidwall/gjson"
|
"github.com/tidwall/gjson"
|
||||||
"github.com/tidwall/match"
|
"github.com/tidwall/match"
|
||||||
@@ -23,6 +32,8 @@ type CpdailySleepCheckTask struct {
|
|||||||
host string
|
host string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var _ CpdailyTask = (*CpdailySleepCheckTask)(nil)
|
||||||
|
|
||||||
func NewSleepCheckTask(client *resty.Client, host string) *CpdailySleepCheckTask {
|
func NewSleepCheckTask(client *resty.Client, host string) *CpdailySleepCheckTask {
|
||||||
return &CpdailySleepCheckTask{
|
return &CpdailySleepCheckTask{
|
||||||
client: client,
|
client: client,
|
||||||
@@ -405,17 +416,275 @@ func (c *CpdailySleepCheckTask) QueryFormByYearMonth(ctx context.Context, titleG
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *CpdailySleepCheckTask) ParseFormJson(ctx context.Context, rawJson map[string]*gvar.Var) []formtype.CpTaskFormItem {
|
func (c *CpdailySleepCheckTask) ParseFormJson(ctx context.Context, rawJson map[string]*gvar.Var) []*formtype.CpTaskFormItem {
|
||||||
//TODO implement me
|
rows := rawJson["rows"].MapStrVar()
|
||||||
panic("implement me")
|
|
||||||
|
if len(rows) == 0 {
|
||||||
|
utils.OkOrPanic(errors.NewBusinessError(503, "任务表单为空"), oops.WithContext(ctx).Wrap)
|
||||||
|
}
|
||||||
|
|
||||||
|
var list []*formtype.CpTaskFormItem
|
||||||
|
|
||||||
|
// 经纬度
|
||||||
|
dto := &formtype.CpTaskFormItem{
|
||||||
|
Title: "经度",
|
||||||
|
ColName: "lon",
|
||||||
|
Type: formtype.ItemTypeInput,
|
||||||
|
Required: true,
|
||||||
|
}
|
||||||
|
list = append(list, dto)
|
||||||
|
|
||||||
|
dto = &formtype.CpTaskFormItem{
|
||||||
|
Title: "纬度",
|
||||||
|
ColName: "lat",
|
||||||
|
Type: formtype.ItemTypeInput,
|
||||||
|
Required: true,
|
||||||
|
}
|
||||||
|
list = append(list, dto)
|
||||||
|
dto = &formtype.CpTaskFormItem{
|
||||||
|
Title: "查寝具体地址",
|
||||||
|
ColName: "address",
|
||||||
|
Type: formtype.ItemTypeInput,
|
||||||
|
Required: true,
|
||||||
|
}
|
||||||
|
list = append(list, dto)
|
||||||
|
|
||||||
|
var current uint
|
||||||
|
|
||||||
|
if isPhoto := rows["isPhoto"]; isPhoto != nil && isPhoto.Int() == 1 {
|
||||||
|
dto = &formtype.CpTaskFormItem{
|
||||||
|
Title: "查寝照片",
|
||||||
|
ColName: "signImg",
|
||||||
|
Type: formtype.ItemTypeImage,
|
||||||
|
Required: true,
|
||||||
|
Number: current,
|
||||||
|
}
|
||||||
|
list = append(list, dto)
|
||||||
|
current++
|
||||||
|
}
|
||||||
|
|
||||||
|
// 是否范围外签到
|
||||||
|
dto = &formtype.CpTaskFormItem{
|
||||||
|
Title: "是否范围外签到",
|
||||||
|
ColName: "isMalposition",
|
||||||
|
Type: formtype.ItemTypeSingle,
|
||||||
|
Required: true,
|
||||||
|
Number: current,
|
||||||
|
Options: []formtype.CpTaskFormItemOption{
|
||||||
|
{
|
||||||
|
Content: "是",
|
||||||
|
ShowLogic: []string{"abnormalReason"},
|
||||||
|
IsOtherItems: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Content: "否",
|
||||||
|
IsOtherItems: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
list = append(list, dto)
|
||||||
|
current++
|
||||||
|
|
||||||
|
for key, item := range list {
|
||||||
|
list[key].Show = item.LogicWid == ""
|
||||||
|
}
|
||||||
|
|
||||||
|
return list
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *CpdailySleepCheckTask) FillCustomForm(ctx context.Context, form map[string]*gvar.Var, paramList []formtype.CpTaskFormItem, deviceId, username string) map[string]*gvar.Var {
|
func (c *CpdailySleepCheckTask) FillCustomForm(ctx context.Context, form map[string]*gvar.Var, paramList []*formtype.CpTaskFormItem, deviceId, username string) map[string]*gvar.Var {
|
||||||
//TODO implement me
|
var resultForm map[string]*gvar.Var
|
||||||
panic("implement me")
|
|
||||||
|
// 填充必要变量
|
||||||
|
rows := form["rows"].MapStrVar()
|
||||||
|
resultForm = make(map[string]*gvar.Var)
|
||||||
|
|
||||||
|
// 填充必要变量
|
||||||
|
// 获取经纬度、地址
|
||||||
|
var lat, lon, address string
|
||||||
|
for _, v := range paramList {
|
||||||
|
switch v.ColName {
|
||||||
|
case "lat":
|
||||||
|
lat = v.Content
|
||||||
|
case "lon":
|
||||||
|
lon = v.Content
|
||||||
|
case "address":
|
||||||
|
address = v.Content
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resultForm["latitude"] = gvar.New(lat)
|
||||||
|
resultForm["longitude"] = gvar.New(lon)
|
||||||
|
resultForm["position"] = gvar.New(address)
|
||||||
|
resultForm["uaIsCpadaily"] = gvar.New(true)
|
||||||
|
|
||||||
|
// 处理验证码
|
||||||
|
submitCaptchaResolver := submitcaptcha.NewRuoliResolver(c.client, c.host, deviceId, types.TaskTypeSleepCheck)
|
||||||
|
captchaInfo := submitCaptchaResolver.GetValidationInfo(ctx)
|
||||||
|
|
||||||
|
if captchaInfo.Validation {
|
||||||
|
var ticket string
|
||||||
|
|
||||||
|
e := retry.Do(func() error {
|
||||||
|
return utils.Catch(func() {
|
||||||
|
ticket = submitCaptchaResolver.GetCaptchaTicket(ctx, captchaInfo)
|
||||||
|
})
|
||||||
|
}, retry.MaxDelay(15*time.Second), retry.Attempts(5), retry.Context(ctx))
|
||||||
|
utils.OkOrPanic(errors.NewBusinessError(503, "提交验证码识别失败").WithInnerError(e), oops.WithContext(ctx).Wrap)
|
||||||
|
|
||||||
|
resultForm["ticket"] = gvar.New(ticket)
|
||||||
|
} else {
|
||||||
|
resultForm["ticket"] = gvar.New("")
|
||||||
|
}
|
||||||
|
|
||||||
|
if isPhoto := rows["isPhoto"]; isPhoto != nil && isPhoto.Int() == 1 {
|
||||||
|
var targetParam *formtype.CpTaskFormItem
|
||||||
|
for _, v := range paramList {
|
||||||
|
if v.ColName == "signImg" {
|
||||||
|
targetParam = v
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if targetParam == nil || targetParam.Content == "" {
|
||||||
|
utils.OkOrPanic(errors.NewBusinessError(503, "未找到查寝照片参数,请上传照片"), oops.WithContext(ctx).Wrap)
|
||||||
|
}
|
||||||
|
|
||||||
|
imageUuidSeq := strings.SplitSeq(targetParam.Content, ",")
|
||||||
|
|
||||||
|
var imageUuids []string
|
||||||
|
|
||||||
|
for imageUuid := range imageUuidSeq {
|
||||||
|
imageUuid = strings.TrimSpace(imageUuid)
|
||||||
|
if imageUuid == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
imageUuids = append(imageUuids, imageUuid)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(imageUuids) == 0 {
|
||||||
|
utils.OkOrPanic(errors.NewBusinessError(503, "未找到查寝照片参数,请上传照片"), oops.WithContext(ctx).Wrap)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 随机选择一张照片
|
||||||
|
imageUuid := imageUuids[rand.IntN(len(imageUuids))]
|
||||||
|
|
||||||
|
imageId, e := uuid.Parse(imageUuid)
|
||||||
|
utils.OkOrPanic(e, oops.WithContext(ctx).Wrap)
|
||||||
|
|
||||||
|
previewUrl := imageuploader.UploadImageFromStorage(ctx, c.host, imageId, types.TaskTypeSleepCheck, c.client)
|
||||||
|
|
||||||
|
resultForm["signImg"] = gvar.New(previewUrl)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 判断是否存在二维码查寝
|
||||||
|
|
||||||
|
// 查找 qrUuid 参数
|
||||||
|
var qrUuidParam *formtype.CpTaskFormItem
|
||||||
|
for _, v := range paramList {
|
||||||
|
if v.ColName == "qrUuid" {
|
||||||
|
qrUuidParam = v
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if qrUuidParam != nil {
|
||||||
|
// 如果存在 qrUuid,直接填充
|
||||||
|
resultForm["qrUuid"] = gvar.New(qrUuidParam.Content)
|
||||||
|
} else {
|
||||||
|
// 否则,填充查寝其他参数
|
||||||
|
if signInstanceWidVar := rows["signInstanceWid"]; signInstanceWidVar != nil {
|
||||||
|
resultForm["signInstanceWid"] = gvar.New(signInstanceWidVar.String())
|
||||||
|
} else {
|
||||||
|
resultForm["signInstanceWid"] = gvar.New("")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查找 isMalposition 参数
|
||||||
|
var isMalpositionParam *formtype.CpTaskFormItem
|
||||||
|
for _, v := range paramList {
|
||||||
|
if v.ColName == "isMalposition" {
|
||||||
|
isMalpositionParam = v
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if isMalpositionParam != nil && isMalpositionParam.Content == "是" {
|
||||||
|
resultForm["isMalposition"] = gvar.New(1)
|
||||||
|
// 查找 abnormalReason 参数
|
||||||
|
var abnormalReason string
|
||||||
|
for _, v := range paramList {
|
||||||
|
if v.ColName == "abnormalReason" {
|
||||||
|
abnormalReason = v.Content
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
resultForm["abnormalReason"] = gvar.New(abnormalReason)
|
||||||
|
} else {
|
||||||
|
resultForm["isMalposition"] = gvar.New(0)
|
||||||
|
resultForm["abnormalReason"] = gvar.New("")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return resultForm
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *CpdailySleepCheckTask) Submit(ctx context.Context, form map[string]*gvar.Var, username, deviceId string) {
|
func (c *CpdailySleepCheckTask) Submit(ctx context.Context, form map[string]*gvar.Var, username, deviceId string) {
|
||||||
//TODO implement me
|
cpdailyInfo := cpdaily.GetInfo(ctx)
|
||||||
panic("implement me")
|
|
||||||
|
extensionForm := map[string]*gvar.Var{
|
||||||
|
"lon": form["longitude"],
|
||||||
|
"lat": form["latitude"],
|
||||||
|
"model": gvar.New(uuid.New().String()),
|
||||||
|
"appVersion": gvar.New(cpdailyInfo.AppVersion),
|
||||||
|
"systemVersion": gvar.New(cpdailyInfo.SystemVersion),
|
||||||
|
"userId": gvar.New(username),
|
||||||
|
"systemName": gvar.New("android"),
|
||||||
|
"deviceId": gvar.New(deviceId),
|
||||||
|
"cpdailyVersion": gvar.New(cpdailyInfo.AppVersion),
|
||||||
|
}
|
||||||
|
|
||||||
|
extensionString := taskhelper.GetCpdailyExtension(ctx, extensionForm)
|
||||||
|
|
||||||
|
bodyString := taskhelper.GetBodyString(ctx, form)
|
||||||
|
|
||||||
|
// 构造提交数据
|
||||||
|
submitData := map[string]*gvar.Var{
|
||||||
|
"lon": form["longitude"],
|
||||||
|
"version": gvar.New(cryptoutil.EncryptVersion),
|
||||||
|
"calVersion": gvar.New(cpdailyInfo.CalVersion),
|
||||||
|
"deviceId": extensionForm["deviceId"],
|
||||||
|
"userId": gvar.New(username),
|
||||||
|
"systemName": gvar.New("android"),
|
||||||
|
"bodyString": gvar.New(bodyString),
|
||||||
|
"lat": form["latitude"],
|
||||||
|
"systemVersion": gvar.New(cpdailyInfo.SystemVersion),
|
||||||
|
"appVersion": gvar.New(cpdailyInfo.AppVersion),
|
||||||
|
"model": extensionForm["model"],
|
||||||
|
}
|
||||||
|
|
||||||
|
sign := taskhelper.GetSubmitSign(submitData)
|
||||||
|
|
||||||
|
submitData["sign"] = gvar.New(sign)
|
||||||
|
|
||||||
|
response, e := c.client.R().
|
||||||
|
SetBody(submitData).
|
||||||
|
WithContext(ctx).
|
||||||
|
SetHeader("Cpdaily-Extension", extensionString).
|
||||||
|
Post(c.getReqUrl("submitSign"))
|
||||||
|
|
||||||
|
utils.OkOrPanic(e, func(err error) error {
|
||||||
|
return oops.
|
||||||
|
With("host", c.host).
|
||||||
|
With("username", username).
|
||||||
|
With("deviceId", deviceId).
|
||||||
|
In("CpdailySleepCheckTask.Submit").
|
||||||
|
Wrap(err)
|
||||||
|
})
|
||||||
|
|
||||||
|
responseJSON := utils.ReadGjsonResult(response.Body)
|
||||||
|
|
||||||
|
if responseJSON.Get("code").String() != "0" {
|
||||||
|
utils.OkOrPanic(errors.NewBusinessError(503, responseJSON.Get("message").String()), oops.WithContext(ctx).Wrap)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
package task
|
|
||||||
|
|
||||||
type TaskType int
|
|
||||||
|
|
||||||
const (
|
|
||||||
TypeCollection = TaskType(iota)
|
|
||||||
TypeSign
|
|
||||||
TypeSleepCheck
|
|
||||||
)
|
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package taskhelper
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/base64"
|
||||||
|
"likedream-goframe/internal/application/cpdaily/cryptoutil"
|
||||||
|
"likedream-goframe/internal/utils"
|
||||||
|
|
||||||
|
"github.com/bytedance/sonic"
|
||||||
|
"github.com/gogf/gf/v2/container/gvar"
|
||||||
|
"github.com/samber/oops"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetBodyString(ctx context.Context, form map[string]*gvar.Var) string {
|
||||||
|
jsonString, e := sonic.MarshalString(form)
|
||||||
|
utils.OkOrPanic(e, oops.WithContext(ctx).Wrap)
|
||||||
|
|
||||||
|
return base64.StdEncoding.EncodeToString(cryptoutil.AesEncryptForCat([]byte(jsonString)))
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package taskhelper
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/base64"
|
||||||
|
"likedream-goframe/internal/application/cpdaily/cryptoutil"
|
||||||
|
"likedream-goframe/internal/utils"
|
||||||
|
|
||||||
|
"github.com/bytedance/sonic"
|
||||||
|
"github.com/gogf/gf/v2/container/gvar"
|
||||||
|
"github.com/samber/oops"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetCpdailyExtension(ctx context.Context, jsonContent map[string]*gvar.Var) string {
|
||||||
|
jsonString, e := sonic.MarshalString(jsonContent)
|
||||||
|
utils.OkOrPanic(e, oops.WithContext(ctx).Wrap)
|
||||||
|
|
||||||
|
return base64.StdEncoding.EncodeToString(cryptoutil.DesEncrypt([]byte(jsonString), cryptoutil.Cat))
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
package taskhelper
|
||||||
|
|
||||||
|
// GetSubmitSign 用于生成提交表单的签名
|
||||||
|
// 参考 C# 逻辑实现
|
||||||
|
import (
|
||||||
|
"crypto/md5"
|
||||||
|
"encoding/hex"
|
||||||
|
"net/url"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/gogf/gf/v2/container/gvar"
|
||||||
|
)
|
||||||
|
|
||||||
|
const submitSignSalt = "HashSalt" // 请根据实际情况替换为真实盐值
|
||||||
|
|
||||||
|
func GetSubmitSign(form map[string]*gvar.Var) string {
|
||||||
|
// 按照指定顺序构建哈希数据
|
||||||
|
keys := []string{
|
||||||
|
"appVersion",
|
||||||
|
"bodyString",
|
||||||
|
"deviceId",
|
||||||
|
"lat",
|
||||||
|
"lon",
|
||||||
|
"model",
|
||||||
|
"systemName",
|
||||||
|
"systemVersion",
|
||||||
|
"userId",
|
||||||
|
}
|
||||||
|
|
||||||
|
var sb strings.Builder
|
||||||
|
for _, key := range keys {
|
||||||
|
val := ""
|
||||||
|
if v, ok := form[key]; ok && v != nil {
|
||||||
|
val = v.String()
|
||||||
|
}
|
||||||
|
// 这里是 key=UrlEncode(key)&,注意是对 key 进行 url encode
|
||||||
|
sb.WriteString(key)
|
||||||
|
sb.WriteString("=")
|
||||||
|
sb.WriteString(url.QueryEscape(val))
|
||||||
|
sb.WriteString("&")
|
||||||
|
}
|
||||||
|
sb.WriteString(submitSignSalt)
|
||||||
|
|
||||||
|
// 计算MD5
|
||||||
|
hash := md5.Sum([]byte(sb.String()))
|
||||||
|
return hex.EncodeToString(hash[:])
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package types
|
||||||
|
|
||||||
|
type TaskType int
|
||||||
|
|
||||||
|
const (
|
||||||
|
TaskTypeCollection = TaskType(iota)
|
||||||
|
TaskTypeSign
|
||||||
|
TaskTypeSleepCheck
|
||||||
|
)
|
||||||
@@ -6,8 +6,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type BusinessError struct {
|
type BusinessError struct {
|
||||||
Message string `json:"message"`
|
Message string `json:"message"`
|
||||||
Code int `json:"code"`
|
Code int `json:"code"`
|
||||||
|
InnerError error `json:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t BusinessError) Error() string {
|
func (t BusinessError) Error() string {
|
||||||
@@ -21,6 +22,11 @@ func NewBusinessError(code int, message string) *BusinessError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t BusinessError) Decorate(message string, args ...any) error {
|
func (t *BusinessError) Decorate(message string, args ...any) error {
|
||||||
return errorx.Decorate(t, message, args...)
|
return errorx.Decorate(t, message, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *BusinessError) WithInnerError(err error) error {
|
||||||
|
t.InnerError = err
|
||||||
|
return t
|
||||||
|
}
|
||||||
|
|||||||
+15
-12
@@ -3,18 +3,21 @@ package cst
|
|||||||
import "time"
|
import "time"
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ConfigOcrServerUrl = "ocr.url"
|
ConfigOcrServerUrl = "ocr.url"
|
||||||
ConfigEnvMode = "env.mode"
|
ConfigEnvMode = "env.mode"
|
||||||
ConfigDatabaseType = "database.type"
|
ConfigDatabaseType = "database.type"
|
||||||
ConfigDatabaseDsn = "database.dsn"
|
ConfigDatabaseDsn = "database.dsn"
|
||||||
ConfigServerPort = "server.port"
|
ConfigServerPort = "server.port"
|
||||||
ConfigAuthorizationKey = "server.authorization"
|
ConfigAuthorizationKey = "server.authorization"
|
||||||
ConfigJwtKey = "server.jwt"
|
ConfigJwtKey = "server.jwt"
|
||||||
ConfigRuoliCaptchaBaseUrl = "ruoliCaptcha.baseUrl"
|
ConfigRuoliCaptchaBaseUrl = "ruoliCaptcha.baseUrl"
|
||||||
ConfigS3AccessKey = "s3.accessKey"
|
ConfigS3AccessKey = "s3.accessKey"
|
||||||
ConfigS3SecretKey = "s3.secretKey"
|
ConfigS3SecretKey = "s3.secretKey"
|
||||||
ConfigS3BaseUrl = "s3.baseUrl"
|
ConfigS3BaseUrl = "s3.baseUrl"
|
||||||
ConfigS3Bucket = "s3.bucket"
|
ConfigS3Bucket = "s3.bucket"
|
||||||
|
ConfigCpdailyAppVersion = "cpdaily.appVersion"
|
||||||
|
ConfigCpdailySystemVersion = "cpdaily.systemVersion"
|
||||||
|
ConfigCpdailyCalVersion = "cpdaily.calVersion"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|||||||
+187
-13
@@ -11,6 +11,7 @@ import (
|
|||||||
|
|
||||||
"likedream-goframe/internal/ent/migrate"
|
"likedream-goframe/internal/ent/migrate"
|
||||||
|
|
||||||
|
"likedream-goframe/internal/ent/cpimage"
|
||||||
"likedream-goframe/internal/ent/sysagent"
|
"likedream-goframe/internal/ent/sysagent"
|
||||||
"likedream-goframe/internal/ent/sysmenu"
|
"likedream-goframe/internal/ent/sysmenu"
|
||||||
"likedream-goframe/internal/ent/sysrole"
|
"likedream-goframe/internal/ent/sysrole"
|
||||||
@@ -28,6 +29,8 @@ type Client struct {
|
|||||||
config
|
config
|
||||||
// Schema is the client for creating, migrating and dropping schema.
|
// Schema is the client for creating, migrating and dropping schema.
|
||||||
Schema *migrate.Schema
|
Schema *migrate.Schema
|
||||||
|
// CpImage is the client for interacting with the CpImage builders.
|
||||||
|
CpImage *CpImageClient
|
||||||
// SysAgent is the client for interacting with the SysAgent builders.
|
// SysAgent is the client for interacting with the SysAgent builders.
|
||||||
SysAgent *SysAgentClient
|
SysAgent *SysAgentClient
|
||||||
// SysMenu is the client for interacting with the SysMenu builders.
|
// SysMenu is the client for interacting with the SysMenu builders.
|
||||||
@@ -49,6 +52,7 @@ func NewClient(opts ...Option) *Client {
|
|||||||
|
|
||||||
func (c *Client) init() {
|
func (c *Client) init() {
|
||||||
c.Schema = migrate.NewSchema(c.driver)
|
c.Schema = migrate.NewSchema(c.driver)
|
||||||
|
c.CpImage = NewCpImageClient(c.config)
|
||||||
c.SysAgent = NewSysAgentClient(c.config)
|
c.SysAgent = NewSysAgentClient(c.config)
|
||||||
c.SysMenu = NewSysMenuClient(c.config)
|
c.SysMenu = NewSysMenuClient(c.config)
|
||||||
c.SysRole = NewSysRoleClient(c.config)
|
c.SysRole = NewSysRoleClient(c.config)
|
||||||
@@ -146,6 +150,7 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) {
|
|||||||
return &Tx{
|
return &Tx{
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
config: cfg,
|
config: cfg,
|
||||||
|
CpImage: NewCpImageClient(cfg),
|
||||||
SysAgent: NewSysAgentClient(cfg),
|
SysAgent: NewSysAgentClient(cfg),
|
||||||
SysMenu: NewSysMenuClient(cfg),
|
SysMenu: NewSysMenuClient(cfg),
|
||||||
SysRole: NewSysRoleClient(cfg),
|
SysRole: NewSysRoleClient(cfg),
|
||||||
@@ -170,6 +175,7 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
|
|||||||
return &Tx{
|
return &Tx{
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
config: cfg,
|
config: cfg,
|
||||||
|
CpImage: NewCpImageClient(cfg),
|
||||||
SysAgent: NewSysAgentClient(cfg),
|
SysAgent: NewSysAgentClient(cfg),
|
||||||
SysMenu: NewSysMenuClient(cfg),
|
SysMenu: NewSysMenuClient(cfg),
|
||||||
SysRole: NewSysRoleClient(cfg),
|
SysRole: NewSysRoleClient(cfg),
|
||||||
@@ -181,7 +187,7 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
|
|||||||
// Debug returns a new debug-client. It's used to get verbose logging on specific operations.
|
// Debug returns a new debug-client. It's used to get verbose logging on specific operations.
|
||||||
//
|
//
|
||||||
// client.Debug().
|
// client.Debug().
|
||||||
// SysAgent.
|
// CpImage.
|
||||||
// Query().
|
// Query().
|
||||||
// Count(ctx)
|
// Count(ctx)
|
||||||
func (c *Client) Debug() *Client {
|
func (c *Client) Debug() *Client {
|
||||||
@@ -203,26 +209,28 @@ func (c *Client) Close() error {
|
|||||||
// Use adds the mutation hooks to all the entity clients.
|
// Use adds the mutation hooks to all the entity clients.
|
||||||
// In order to add hooks to a specific client, call: `client.Node.Use(...)`.
|
// In order to add hooks to a specific client, call: `client.Node.Use(...)`.
|
||||||
func (c *Client) Use(hooks ...Hook) {
|
func (c *Client) Use(hooks ...Hook) {
|
||||||
c.SysAgent.Use(hooks...)
|
for _, n := range []interface{ Use(...Hook) }{
|
||||||
c.SysMenu.Use(hooks...)
|
c.CpImage, c.SysAgent, c.SysMenu, c.SysRole, c.SysUser, c.SysUserLog,
|
||||||
c.SysRole.Use(hooks...)
|
} {
|
||||||
c.SysUser.Use(hooks...)
|
n.Use(hooks...)
|
||||||
c.SysUserLog.Use(hooks...)
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Intercept adds the query interceptors to all the entity clients.
|
// Intercept adds the query interceptors to all the entity clients.
|
||||||
// In order to add interceptors to a specific client, call: `client.Node.Intercept(...)`.
|
// In order to add interceptors to a specific client, call: `client.Node.Intercept(...)`.
|
||||||
func (c *Client) Intercept(interceptors ...Interceptor) {
|
func (c *Client) Intercept(interceptors ...Interceptor) {
|
||||||
c.SysAgent.Intercept(interceptors...)
|
for _, n := range []interface{ Intercept(...Interceptor) }{
|
||||||
c.SysMenu.Intercept(interceptors...)
|
c.CpImage, c.SysAgent, c.SysMenu, c.SysRole, c.SysUser, c.SysUserLog,
|
||||||
c.SysRole.Intercept(interceptors...)
|
} {
|
||||||
c.SysUser.Intercept(interceptors...)
|
n.Intercept(interceptors...)
|
||||||
c.SysUserLog.Intercept(interceptors...)
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mutate implements the ent.Mutator interface.
|
// Mutate implements the ent.Mutator interface.
|
||||||
func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
|
func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
|
||||||
switch m := m.(type) {
|
switch m := m.(type) {
|
||||||
|
case *CpImageMutation:
|
||||||
|
return c.CpImage.mutate(ctx, m)
|
||||||
case *SysAgentMutation:
|
case *SysAgentMutation:
|
||||||
return c.SysAgent.mutate(ctx, m)
|
return c.SysAgent.mutate(ctx, m)
|
||||||
case *SysMenuMutation:
|
case *SysMenuMutation:
|
||||||
@@ -238,6 +246,156 @@ func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CpImageClient is a client for the CpImage schema.
|
||||||
|
type CpImageClient struct {
|
||||||
|
config
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewCpImageClient returns a client for the CpImage from the given config.
|
||||||
|
func NewCpImageClient(c config) *CpImageClient {
|
||||||
|
return &CpImageClient{config: c}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use adds a list of mutation hooks to the hooks stack.
|
||||||
|
// A call to `Use(f, g, h)` equals to `cpimage.Hooks(f(g(h())))`.
|
||||||
|
func (c *CpImageClient) Use(hooks ...Hook) {
|
||||||
|
c.hooks.CpImage = append(c.hooks.CpImage, hooks...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Intercept adds a list of query interceptors to the interceptors stack.
|
||||||
|
// A call to `Intercept(f, g, h)` equals to `cpimage.Intercept(f(g(h())))`.
|
||||||
|
func (c *CpImageClient) Intercept(interceptors ...Interceptor) {
|
||||||
|
c.inters.CpImage = append(c.inters.CpImage, interceptors...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create returns a builder for creating a CpImage entity.
|
||||||
|
func (c *CpImageClient) Create() *CpImageCreate {
|
||||||
|
mutation := newCpImageMutation(c.config, OpCreate)
|
||||||
|
return &CpImageCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateBulk returns a builder for creating a bulk of CpImage entities.
|
||||||
|
func (c *CpImageClient) CreateBulk(builders ...*CpImageCreate) *CpImageCreateBulk {
|
||||||
|
return &CpImageCreateBulk{config: c.config, builders: builders}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
|
||||||
|
// a builder and applies setFunc on it.
|
||||||
|
func (c *CpImageClient) MapCreateBulk(slice any, setFunc func(*CpImageCreate, int)) *CpImageCreateBulk {
|
||||||
|
rv := reflect.ValueOf(slice)
|
||||||
|
if rv.Kind() != reflect.Slice {
|
||||||
|
return &CpImageCreateBulk{err: fmt.Errorf("calling to CpImageClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
||||||
|
}
|
||||||
|
builders := make([]*CpImageCreate, rv.Len())
|
||||||
|
for i := 0; i < rv.Len(); i++ {
|
||||||
|
builders[i] = c.Create()
|
||||||
|
setFunc(builders[i], i)
|
||||||
|
}
|
||||||
|
return &CpImageCreateBulk{config: c.config, builders: builders}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update returns an update builder for CpImage.
|
||||||
|
func (c *CpImageClient) Update() *CpImageUpdate {
|
||||||
|
mutation := newCpImageMutation(c.config, OpUpdate)
|
||||||
|
return &CpImageUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateOne returns an update builder for the given entity.
|
||||||
|
func (c *CpImageClient) UpdateOne(ci *CpImage) *CpImageUpdateOne {
|
||||||
|
mutation := newCpImageMutation(c.config, OpUpdateOne, withCpImage(ci))
|
||||||
|
return &CpImageUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateOneID returns an update builder for the given id.
|
||||||
|
func (c *CpImageClient) UpdateOneID(id int64) *CpImageUpdateOne {
|
||||||
|
mutation := newCpImageMutation(c.config, OpUpdateOne, withCpImageID(id))
|
||||||
|
return &CpImageUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete returns a delete builder for CpImage.
|
||||||
|
func (c *CpImageClient) Delete() *CpImageDelete {
|
||||||
|
mutation := newCpImageMutation(c.config, OpDelete)
|
||||||
|
return &CpImageDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteOne returns a builder for deleting the given entity.
|
||||||
|
func (c *CpImageClient) DeleteOne(ci *CpImage) *CpImageDeleteOne {
|
||||||
|
return c.DeleteOneID(ci.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||||
|
func (c *CpImageClient) DeleteOneID(id int64) *CpImageDeleteOne {
|
||||||
|
builder := c.Delete().Where(cpimage.ID(id))
|
||||||
|
builder.mutation.id = &id
|
||||||
|
builder.mutation.op = OpDeleteOne
|
||||||
|
return &CpImageDeleteOne{builder}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Query returns a query builder for CpImage.
|
||||||
|
func (c *CpImageClient) Query() *CpImageQuery {
|
||||||
|
return &CpImageQuery{
|
||||||
|
config: c.config,
|
||||||
|
ctx: &QueryContext{Type: TypeCpImage},
|
||||||
|
inters: c.Interceptors(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get returns a CpImage entity by its id.
|
||||||
|
func (c *CpImageClient) Get(ctx context.Context, id int64) (*CpImage, error) {
|
||||||
|
return c.Query().Where(cpimage.ID(id)).Only(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetX is like Get, but panics if an error occurs.
|
||||||
|
func (c *CpImageClient) GetX(ctx context.Context, id int64) *CpImage {
|
||||||
|
obj, err := c.Get(ctx, id)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return obj
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryUser queries the user edge of a CpImage.
|
||||||
|
func (c *CpImageClient) QueryUser(ci *CpImage) *SysUserQuery {
|
||||||
|
query := (&SysUserClient{config: c.config}).Query()
|
||||||
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||||
|
id := ci.ID
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(cpimage.Table, cpimage.FieldID, id),
|
||||||
|
sqlgraph.To(sysuser.Table, sysuser.FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2O, true, cpimage.UserTable, cpimage.UserColumn),
|
||||||
|
)
|
||||||
|
fromV = sqlgraph.Neighbors(ci.driver.Dialect(), step)
|
||||||
|
return fromV, nil
|
||||||
|
}
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hooks returns the client hooks.
|
||||||
|
func (c *CpImageClient) Hooks() []Hook {
|
||||||
|
hooks := c.hooks.CpImage
|
||||||
|
return append(hooks[:len(hooks):len(hooks)], cpimage.Hooks[:]...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Interceptors returns the client interceptors.
|
||||||
|
func (c *CpImageClient) Interceptors() []Interceptor {
|
||||||
|
return c.inters.CpImage
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *CpImageClient) mutate(ctx context.Context, m *CpImageMutation) (Value, error) {
|
||||||
|
switch m.Op() {
|
||||||
|
case OpCreate:
|
||||||
|
return (&CpImageCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||||
|
case OpUpdate:
|
||||||
|
return (&CpImageUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||||
|
case OpUpdateOne:
|
||||||
|
return (&CpImageUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||||
|
case OpDelete, OpDeleteOne:
|
||||||
|
return (&CpImageDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("ent: unknown CpImage mutation op: %q", m.Op())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// SysAgentClient is a client for the SysAgent schema.
|
// SysAgentClient is a client for the SysAgent schema.
|
||||||
type SysAgentClient struct {
|
type SysAgentClient struct {
|
||||||
config
|
config
|
||||||
@@ -908,6 +1066,22 @@ func (c *SysUserClient) QueryAgent(su *SysUser) *SysAgentQuery {
|
|||||||
return query
|
return query
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// QueryImages queries the images edge of a SysUser.
|
||||||
|
func (c *SysUserClient) QueryImages(su *SysUser) *CpImageQuery {
|
||||||
|
query := (&CpImageClient{config: c.config}).Query()
|
||||||
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||||
|
id := su.ID
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(sysuser.Table, sysuser.FieldID, id),
|
||||||
|
sqlgraph.To(cpimage.Table, cpimage.FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.O2M, false, sysuser.ImagesTable, sysuser.ImagesColumn),
|
||||||
|
)
|
||||||
|
fromV = sqlgraph.Neighbors(su.driver.Dialect(), step)
|
||||||
|
return fromV, nil
|
||||||
|
}
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
// Hooks returns the client hooks.
|
// Hooks returns the client hooks.
|
||||||
func (c *SysUserClient) Hooks() []Hook {
|
func (c *SysUserClient) Hooks() []Hook {
|
||||||
hooks := c.hooks.SysUser
|
hooks := c.hooks.SysUser
|
||||||
@@ -1070,9 +1244,9 @@ func (c *SysUserLogClient) mutate(ctx context.Context, m *SysUserLogMutation) (V
|
|||||||
// hooks and interceptors per client, for fast access.
|
// hooks and interceptors per client, for fast access.
|
||||||
type (
|
type (
|
||||||
hooks struct {
|
hooks struct {
|
||||||
SysAgent, SysMenu, SysRole, SysUser, SysUserLog []ent.Hook
|
CpImage, SysAgent, SysMenu, SysRole, SysUser, SysUserLog []ent.Hook
|
||||||
}
|
}
|
||||||
inters struct {
|
inters struct {
|
||||||
SysAgent, SysMenu, SysRole, SysUser, SysUserLog []ent.Interceptor
|
CpImage, SysAgent, SysMenu, SysRole, SysUser, SysUserLog []ent.Interceptor
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -0,0 +1,204 @@
|
|||||||
|
// ENT数据库文件,请勿编辑。
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"likedream-goframe/internal/ent/cpimage"
|
||||||
|
"likedream-goframe/internal/ent/sysuser"
|
||||||
|
"likedream-goframe/internal/framework/ent2"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
)
|
||||||
|
|
||||||
|
// CpImage is the model entity for the CpImage schema.
|
||||||
|
type CpImage struct {
|
||||||
|
config `json:"-"`
|
||||||
|
// ID of the ent.
|
||||||
|
ID int64 `json:"id,omitempty"`
|
||||||
|
// CreateTime holds the value of the "create_time" field.
|
||||||
|
CreateTime ent2.CustomTime `json:"createTime"`
|
||||||
|
// UpdateTime holds the value of the "update_time" field.
|
||||||
|
UpdateTime ent2.CustomTime `json:"updateTime"`
|
||||||
|
// ImageID holds the value of the "image_id" field.
|
||||||
|
ImageID uuid.UUID `json:"image_id,omitempty"`
|
||||||
|
// Key holds the value of the "key" field.
|
||||||
|
Key string `json:"key,omitempty"`
|
||||||
|
// UserID holds the value of the "user_id" field.
|
||||||
|
UserID int64 `json:"user_id,omitempty"`
|
||||||
|
// ContentType holds the value of the "content_type" field.
|
||||||
|
ContentType string `json:"content_type,omitempty"`
|
||||||
|
// ContentLength holds the value of the "content_length" field.
|
||||||
|
ContentLength int64 `json:"content_length,omitempty"`
|
||||||
|
// Edges holds the relations/edges for other nodes in the graph.
|
||||||
|
// The values are being populated by the CpImageQuery when eager-loading is set.
|
||||||
|
Edges CpImageEdges `json:"edges"`
|
||||||
|
selectValues sql.SelectValues
|
||||||
|
}
|
||||||
|
|
||||||
|
// CpImageEdges holds the relations/edges for other nodes in the graph.
|
||||||
|
type CpImageEdges struct {
|
||||||
|
// User holds the value of the user edge.
|
||||||
|
User *SysUser `json:"user,omitempty"`
|
||||||
|
// loadedTypes holds the information for reporting if a
|
||||||
|
// type was loaded (or requested) in eager-loading or not.
|
||||||
|
loadedTypes [1]bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserOrErr returns the User value or an error if the edge
|
||||||
|
// was not loaded in eager-loading, or loaded but was not found.
|
||||||
|
func (e CpImageEdges) UserOrErr() (*SysUser, error) {
|
||||||
|
if e.User != nil {
|
||||||
|
return e.User, nil
|
||||||
|
} else if e.loadedTypes[0] {
|
||||||
|
return nil, &NotFoundError{label: sysuser.Label}
|
||||||
|
}
|
||||||
|
return nil, &NotLoadedError{edge: "user"}
|
||||||
|
}
|
||||||
|
|
||||||
|
// scanValues returns the types for scanning values from sql.Rows.
|
||||||
|
func (*CpImage) scanValues(columns []string) ([]any, error) {
|
||||||
|
values := make([]any, len(columns))
|
||||||
|
for i := range columns {
|
||||||
|
switch columns[i] {
|
||||||
|
case cpimage.FieldCreateTime, cpimage.FieldUpdateTime:
|
||||||
|
values[i] = new(ent2.CustomTime)
|
||||||
|
case cpimage.FieldID, cpimage.FieldUserID, cpimage.FieldContentLength:
|
||||||
|
values[i] = new(sql.NullInt64)
|
||||||
|
case cpimage.FieldKey, cpimage.FieldContentType:
|
||||||
|
values[i] = new(sql.NullString)
|
||||||
|
case cpimage.FieldImageID:
|
||||||
|
values[i] = new(uuid.UUID)
|
||||||
|
default:
|
||||||
|
values[i] = new(sql.UnknownType)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return values, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||||
|
// to the CpImage fields.
|
||||||
|
func (ci *CpImage) assignValues(columns []string, values []any) error {
|
||||||
|
if m, n := len(values), len(columns); m < n {
|
||||||
|
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
|
||||||
|
}
|
||||||
|
for i := range columns {
|
||||||
|
switch columns[i] {
|
||||||
|
case cpimage.FieldID:
|
||||||
|
value, ok := values[i].(*sql.NullInt64)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field id", value)
|
||||||
|
}
|
||||||
|
ci.ID = int64(value.Int64)
|
||||||
|
case cpimage.FieldCreateTime:
|
||||||
|
if value, ok := values[i].(*ent2.CustomTime); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field create_time", values[i])
|
||||||
|
} else if value != nil {
|
||||||
|
ci.CreateTime = *value
|
||||||
|
}
|
||||||
|
case cpimage.FieldUpdateTime:
|
||||||
|
if value, ok := values[i].(*ent2.CustomTime); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field update_time", values[i])
|
||||||
|
} else if value != nil {
|
||||||
|
ci.UpdateTime = *value
|
||||||
|
}
|
||||||
|
case cpimage.FieldImageID:
|
||||||
|
if value, ok := values[i].(*uuid.UUID); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field image_id", values[i])
|
||||||
|
} else if value != nil {
|
||||||
|
ci.ImageID = *value
|
||||||
|
}
|
||||||
|
case cpimage.FieldKey:
|
||||||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field key", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
ci.Key = value.String
|
||||||
|
}
|
||||||
|
case cpimage.FieldUserID:
|
||||||
|
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field user_id", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
ci.UserID = value.Int64
|
||||||
|
}
|
||||||
|
case cpimage.FieldContentType:
|
||||||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field content_type", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
ci.ContentType = value.String
|
||||||
|
}
|
||||||
|
case cpimage.FieldContentLength:
|
||||||
|
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field content_length", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
ci.ContentLength = value.Int64
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
ci.selectValues.Set(columns[i], values[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Value returns the ent.Value that was dynamically selected and assigned to the CpImage.
|
||||||
|
// This includes values selected through modifiers, order, etc.
|
||||||
|
func (ci *CpImage) Value(name string) (ent.Value, error) {
|
||||||
|
return ci.selectValues.Get(name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryUser queries the "user" edge of the CpImage entity.
|
||||||
|
func (ci *CpImage) QueryUser() *SysUserQuery {
|
||||||
|
return NewCpImageClient(ci.config).QueryUser(ci)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update returns a builder for updating this CpImage.
|
||||||
|
// Note that you need to call CpImage.Unwrap() before calling this method if this CpImage
|
||||||
|
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||||
|
func (ci *CpImage) Update() *CpImageUpdateOne {
|
||||||
|
return NewCpImageClient(ci.config).UpdateOne(ci)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unwrap unwraps the CpImage entity that was returned from a transaction after it was closed,
|
||||||
|
// so that all future queries will be executed through the driver which created the transaction.
|
||||||
|
func (ci *CpImage) Unwrap() *CpImage {
|
||||||
|
_tx, ok := ci.config.driver.(*txDriver)
|
||||||
|
if !ok {
|
||||||
|
panic("ent: CpImage is not a transactional entity")
|
||||||
|
}
|
||||||
|
ci.config.driver = _tx.drv
|
||||||
|
return ci
|
||||||
|
}
|
||||||
|
|
||||||
|
// String implements the fmt.Stringer.
|
||||||
|
func (ci *CpImage) String() string {
|
||||||
|
var builder strings.Builder
|
||||||
|
builder.WriteString("CpImage(")
|
||||||
|
builder.WriteString(fmt.Sprintf("id=%v, ", ci.ID))
|
||||||
|
builder.WriteString("create_time=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", ci.CreateTime))
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("update_time=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", ci.UpdateTime))
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("image_id=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", ci.ImageID))
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("key=")
|
||||||
|
builder.WriteString(ci.Key)
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("user_id=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", ci.UserID))
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("content_type=")
|
||||||
|
builder.WriteString(ci.ContentType)
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("content_length=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", ci.ContentLength))
|
||||||
|
builder.WriteByte(')')
|
||||||
|
return builder.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
// CpImages is a parsable slice of CpImage.
|
||||||
|
type CpImages []*CpImage
|
||||||
@@ -0,0 +1,137 @@
|
|||||||
|
// ENT数据库文件,请勿编辑。
|
||||||
|
|
||||||
|
package cpimage
|
||||||
|
|
||||||
|
import (
|
||||||
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// Label holds the string label denoting the cpimage type in the database.
|
||||||
|
Label = "cp_image"
|
||||||
|
// FieldID holds the string denoting the id field in the database.
|
||||||
|
FieldID = "id"
|
||||||
|
// FieldCreateTime holds the string denoting the create_time field in the database.
|
||||||
|
FieldCreateTime = "create_time"
|
||||||
|
// FieldUpdateTime holds the string denoting the update_time field in the database.
|
||||||
|
FieldUpdateTime = "update_time"
|
||||||
|
// FieldImageID holds the string denoting the image_id field in the database.
|
||||||
|
FieldImageID = "image_id"
|
||||||
|
// FieldKey holds the string denoting the key field in the database.
|
||||||
|
FieldKey = "key"
|
||||||
|
// FieldUserID holds the string denoting the user_id field in the database.
|
||||||
|
FieldUserID = "user_id"
|
||||||
|
// FieldContentType holds the string denoting the content_type field in the database.
|
||||||
|
FieldContentType = "content_type"
|
||||||
|
// FieldContentLength holds the string denoting the content_length field in the database.
|
||||||
|
FieldContentLength = "content_length"
|
||||||
|
// EdgeUser holds the string denoting the user edge name in mutations.
|
||||||
|
EdgeUser = "user"
|
||||||
|
// Table holds the table name of the cpimage in the database.
|
||||||
|
Table = "cp_image"
|
||||||
|
// UserTable is the table that holds the user relation/edge.
|
||||||
|
UserTable = "cp_image"
|
||||||
|
// UserInverseTable is the table name for the SysUser entity.
|
||||||
|
// It exists in this package in order to avoid circular dependency with the "sysuser" package.
|
||||||
|
UserInverseTable = "sys_user"
|
||||||
|
// UserColumn is the table column denoting the user relation/edge.
|
||||||
|
UserColumn = "user_id"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Columns holds all SQL columns for cpimage fields.
|
||||||
|
var Columns = []string{
|
||||||
|
FieldID,
|
||||||
|
FieldCreateTime,
|
||||||
|
FieldUpdateTime,
|
||||||
|
FieldImageID,
|
||||||
|
FieldKey,
|
||||||
|
FieldUserID,
|
||||||
|
FieldContentType,
|
||||||
|
FieldContentLength,
|
||||||
|
}
|
||||||
|
|
||||||
|
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||||
|
func ValidColumn(column string) bool {
|
||||||
|
for i := range Columns {
|
||||||
|
if column == Columns[i] {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// Note that the variables below are initialized by the runtime
|
||||||
|
// package on the initialization of the application. Therefore,
|
||||||
|
// it should be imported in the main as follows:
|
||||||
|
//
|
||||||
|
// import _ "likedream-goframe/internal/ent/runtime"
|
||||||
|
var (
|
||||||
|
Hooks [1]ent.Hook
|
||||||
|
// KeyValidator is a validator for the "key" field. It is called by the builders before save.
|
||||||
|
KeyValidator func(string) error
|
||||||
|
// UserIDValidator is a validator for the "user_id" field. It is called by the builders before save.
|
||||||
|
UserIDValidator func(int64) error
|
||||||
|
// ContentTypeValidator is a validator for the "content_type" field. It is called by the builders before save.
|
||||||
|
ContentTypeValidator func(string) error
|
||||||
|
// ContentLengthValidator is a validator for the "content_length" field. It is called by the builders before save.
|
||||||
|
ContentLengthValidator func(int64) error
|
||||||
|
)
|
||||||
|
|
||||||
|
// OrderOption defines the ordering options for the CpImage queries.
|
||||||
|
type OrderOption func(*sql.Selector)
|
||||||
|
|
||||||
|
// ByID orders the results by the id field.
|
||||||
|
func ByID(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldID, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByCreateTime orders the results by the create_time field.
|
||||||
|
func ByCreateTime(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldCreateTime, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByUpdateTime orders the results by the update_time field.
|
||||||
|
func ByUpdateTime(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldUpdateTime, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByImageID orders the results by the image_id field.
|
||||||
|
func ByImageID(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldImageID, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByKey orders the results by the key field.
|
||||||
|
func ByKey(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldKey, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByUserID orders the results by the user_id field.
|
||||||
|
func ByUserID(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldUserID, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByContentType orders the results by the content_type field.
|
||||||
|
func ByContentType(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldContentType, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByContentLength orders the results by the content_length field.
|
||||||
|
func ByContentLength(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldContentLength, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByUserField orders the results by user field.
|
||||||
|
func ByUserField(field string, opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return func(s *sql.Selector) {
|
||||||
|
sqlgraph.OrderByNeighborTerms(s, newUserStep(), sql.OrderByField(field, opts...))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func newUserStep() *sqlgraph.Step {
|
||||||
|
return sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(Table, FieldID),
|
||||||
|
sqlgraph.To(UserInverseTable, FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2O, true, UserTable, UserColumn),
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,500 @@
|
|||||||
|
// ENT数据库文件,请勿编辑。
|
||||||
|
|
||||||
|
package cpimage
|
||||||
|
|
||||||
|
import (
|
||||||
|
"likedream-goframe/internal/ent/predicate"
|
||||||
|
"likedream-goframe/internal/framework/ent2"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ID filters vertices based on their ID field.
|
||||||
|
func ID(id int64) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldEQ(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDEQ applies the EQ predicate on the ID field.
|
||||||
|
func IDEQ(id int64) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldEQ(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDNEQ applies the NEQ predicate on the ID field.
|
||||||
|
func IDNEQ(id int64) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldNEQ(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDIn applies the In predicate on the ID field.
|
||||||
|
func IDIn(ids ...int64) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldIn(FieldID, ids...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDNotIn applies the NotIn predicate on the ID field.
|
||||||
|
func IDNotIn(ids ...int64) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldNotIn(FieldID, ids...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDGT applies the GT predicate on the ID field.
|
||||||
|
func IDGT(id int64) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldGT(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDGTE applies the GTE predicate on the ID field.
|
||||||
|
func IDGTE(id int64) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldGTE(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDLT applies the LT predicate on the ID field.
|
||||||
|
func IDLT(id int64) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldLT(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDLTE applies the LTE predicate on the ID field.
|
||||||
|
func IDLTE(id int64) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldLTE(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateTime applies equality check predicate on the "create_time" field. It's identical to CreateTimeEQ.
|
||||||
|
func CreateTime(v ent2.CustomTime) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldEQ(FieldCreateTime, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateTime applies equality check predicate on the "update_time" field. It's identical to UpdateTimeEQ.
|
||||||
|
func UpdateTime(v ent2.CustomTime) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldEQ(FieldUpdateTime, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ImageID applies equality check predicate on the "image_id" field. It's identical to ImageIDEQ.
|
||||||
|
func ImageID(v uuid.UUID) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldEQ(FieldImageID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Key applies equality check predicate on the "key" field. It's identical to KeyEQ.
|
||||||
|
func Key(v string) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldEQ(FieldKey, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserID applies equality check predicate on the "user_id" field. It's identical to UserIDEQ.
|
||||||
|
func UserID(v int64) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldEQ(FieldUserID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ContentType applies equality check predicate on the "content_type" field. It's identical to ContentTypeEQ.
|
||||||
|
func ContentType(v string) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldEQ(FieldContentType, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ContentLength applies equality check predicate on the "content_length" field. It's identical to ContentLengthEQ.
|
||||||
|
func ContentLength(v int64) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldEQ(FieldContentLength, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateTimeEQ applies the EQ predicate on the "create_time" field.
|
||||||
|
func CreateTimeEQ(v ent2.CustomTime) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldEQ(FieldCreateTime, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateTimeNEQ applies the NEQ predicate on the "create_time" field.
|
||||||
|
func CreateTimeNEQ(v ent2.CustomTime) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldNEQ(FieldCreateTime, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateTimeIn applies the In predicate on the "create_time" field.
|
||||||
|
func CreateTimeIn(vs ...ent2.CustomTime) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldIn(FieldCreateTime, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateTimeNotIn applies the NotIn predicate on the "create_time" field.
|
||||||
|
func CreateTimeNotIn(vs ...ent2.CustomTime) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldNotIn(FieldCreateTime, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateTimeGT applies the GT predicate on the "create_time" field.
|
||||||
|
func CreateTimeGT(v ent2.CustomTime) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldGT(FieldCreateTime, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateTimeGTE applies the GTE predicate on the "create_time" field.
|
||||||
|
func CreateTimeGTE(v ent2.CustomTime) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldGTE(FieldCreateTime, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateTimeLT applies the LT predicate on the "create_time" field.
|
||||||
|
func CreateTimeLT(v ent2.CustomTime) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldLT(FieldCreateTime, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateTimeLTE applies the LTE predicate on the "create_time" field.
|
||||||
|
func CreateTimeLTE(v ent2.CustomTime) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldLTE(FieldCreateTime, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateTimeContains applies the Contains predicate on the "create_time" field.
|
||||||
|
func CreateTimeContains(v ent2.CustomTime) predicate.CpImage {
|
||||||
|
vc := v.String()
|
||||||
|
return predicate.CpImage(sql.FieldContains(FieldCreateTime, vc))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateTimeHasPrefix applies the HasPrefix predicate on the "create_time" field.
|
||||||
|
func CreateTimeHasPrefix(v ent2.CustomTime) predicate.CpImage {
|
||||||
|
vc := v.String()
|
||||||
|
return predicate.CpImage(sql.FieldHasPrefix(FieldCreateTime, vc))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateTimeHasSuffix applies the HasSuffix predicate on the "create_time" field.
|
||||||
|
func CreateTimeHasSuffix(v ent2.CustomTime) predicate.CpImage {
|
||||||
|
vc := v.String()
|
||||||
|
return predicate.CpImage(sql.FieldHasSuffix(FieldCreateTime, vc))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateTimeEqualFold applies the EqualFold predicate on the "create_time" field.
|
||||||
|
func CreateTimeEqualFold(v ent2.CustomTime) predicate.CpImage {
|
||||||
|
vc := v.String()
|
||||||
|
return predicate.CpImage(sql.FieldEqualFold(FieldCreateTime, vc))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateTimeContainsFold applies the ContainsFold predicate on the "create_time" field.
|
||||||
|
func CreateTimeContainsFold(v ent2.CustomTime) predicate.CpImage {
|
||||||
|
vc := v.String()
|
||||||
|
return predicate.CpImage(sql.FieldContainsFold(FieldCreateTime, vc))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateTimeEQ applies the EQ predicate on the "update_time" field.
|
||||||
|
func UpdateTimeEQ(v ent2.CustomTime) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldEQ(FieldUpdateTime, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateTimeNEQ applies the NEQ predicate on the "update_time" field.
|
||||||
|
func UpdateTimeNEQ(v ent2.CustomTime) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldNEQ(FieldUpdateTime, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateTimeIn applies the In predicate on the "update_time" field.
|
||||||
|
func UpdateTimeIn(vs ...ent2.CustomTime) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldIn(FieldUpdateTime, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateTimeNotIn applies the NotIn predicate on the "update_time" field.
|
||||||
|
func UpdateTimeNotIn(vs ...ent2.CustomTime) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldNotIn(FieldUpdateTime, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateTimeGT applies the GT predicate on the "update_time" field.
|
||||||
|
func UpdateTimeGT(v ent2.CustomTime) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldGT(FieldUpdateTime, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateTimeGTE applies the GTE predicate on the "update_time" field.
|
||||||
|
func UpdateTimeGTE(v ent2.CustomTime) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldGTE(FieldUpdateTime, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateTimeLT applies the LT predicate on the "update_time" field.
|
||||||
|
func UpdateTimeLT(v ent2.CustomTime) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldLT(FieldUpdateTime, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateTimeLTE applies the LTE predicate on the "update_time" field.
|
||||||
|
func UpdateTimeLTE(v ent2.CustomTime) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldLTE(FieldUpdateTime, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateTimeContains applies the Contains predicate on the "update_time" field.
|
||||||
|
func UpdateTimeContains(v ent2.CustomTime) predicate.CpImage {
|
||||||
|
vc := v.String()
|
||||||
|
return predicate.CpImage(sql.FieldContains(FieldUpdateTime, vc))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateTimeHasPrefix applies the HasPrefix predicate on the "update_time" field.
|
||||||
|
func UpdateTimeHasPrefix(v ent2.CustomTime) predicate.CpImage {
|
||||||
|
vc := v.String()
|
||||||
|
return predicate.CpImage(sql.FieldHasPrefix(FieldUpdateTime, vc))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateTimeHasSuffix applies the HasSuffix predicate on the "update_time" field.
|
||||||
|
func UpdateTimeHasSuffix(v ent2.CustomTime) predicate.CpImage {
|
||||||
|
vc := v.String()
|
||||||
|
return predicate.CpImage(sql.FieldHasSuffix(FieldUpdateTime, vc))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateTimeEqualFold applies the EqualFold predicate on the "update_time" field.
|
||||||
|
func UpdateTimeEqualFold(v ent2.CustomTime) predicate.CpImage {
|
||||||
|
vc := v.String()
|
||||||
|
return predicate.CpImage(sql.FieldEqualFold(FieldUpdateTime, vc))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateTimeContainsFold applies the ContainsFold predicate on the "update_time" field.
|
||||||
|
func UpdateTimeContainsFold(v ent2.CustomTime) predicate.CpImage {
|
||||||
|
vc := v.String()
|
||||||
|
return predicate.CpImage(sql.FieldContainsFold(FieldUpdateTime, vc))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ImageIDEQ applies the EQ predicate on the "image_id" field.
|
||||||
|
func ImageIDEQ(v uuid.UUID) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldEQ(FieldImageID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ImageIDNEQ applies the NEQ predicate on the "image_id" field.
|
||||||
|
func ImageIDNEQ(v uuid.UUID) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldNEQ(FieldImageID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ImageIDIn applies the In predicate on the "image_id" field.
|
||||||
|
func ImageIDIn(vs ...uuid.UUID) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldIn(FieldImageID, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ImageIDNotIn applies the NotIn predicate on the "image_id" field.
|
||||||
|
func ImageIDNotIn(vs ...uuid.UUID) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldNotIn(FieldImageID, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ImageIDGT applies the GT predicate on the "image_id" field.
|
||||||
|
func ImageIDGT(v uuid.UUID) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldGT(FieldImageID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ImageIDGTE applies the GTE predicate on the "image_id" field.
|
||||||
|
func ImageIDGTE(v uuid.UUID) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldGTE(FieldImageID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ImageIDLT applies the LT predicate on the "image_id" field.
|
||||||
|
func ImageIDLT(v uuid.UUID) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldLT(FieldImageID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ImageIDLTE applies the LTE predicate on the "image_id" field.
|
||||||
|
func ImageIDLTE(v uuid.UUID) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldLTE(FieldImageID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// KeyEQ applies the EQ predicate on the "key" field.
|
||||||
|
func KeyEQ(v string) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldEQ(FieldKey, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// KeyNEQ applies the NEQ predicate on the "key" field.
|
||||||
|
func KeyNEQ(v string) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldNEQ(FieldKey, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// KeyIn applies the In predicate on the "key" field.
|
||||||
|
func KeyIn(vs ...string) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldIn(FieldKey, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// KeyNotIn applies the NotIn predicate on the "key" field.
|
||||||
|
func KeyNotIn(vs ...string) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldNotIn(FieldKey, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// KeyGT applies the GT predicate on the "key" field.
|
||||||
|
func KeyGT(v string) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldGT(FieldKey, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// KeyGTE applies the GTE predicate on the "key" field.
|
||||||
|
func KeyGTE(v string) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldGTE(FieldKey, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// KeyLT applies the LT predicate on the "key" field.
|
||||||
|
func KeyLT(v string) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldLT(FieldKey, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// KeyLTE applies the LTE predicate on the "key" field.
|
||||||
|
func KeyLTE(v string) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldLTE(FieldKey, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// KeyContains applies the Contains predicate on the "key" field.
|
||||||
|
func KeyContains(v string) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldContains(FieldKey, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// KeyHasPrefix applies the HasPrefix predicate on the "key" field.
|
||||||
|
func KeyHasPrefix(v string) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldHasPrefix(FieldKey, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// KeyHasSuffix applies the HasSuffix predicate on the "key" field.
|
||||||
|
func KeyHasSuffix(v string) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldHasSuffix(FieldKey, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// KeyEqualFold applies the EqualFold predicate on the "key" field.
|
||||||
|
func KeyEqualFold(v string) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldEqualFold(FieldKey, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// KeyContainsFold applies the ContainsFold predicate on the "key" field.
|
||||||
|
func KeyContainsFold(v string) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldContainsFold(FieldKey, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserIDEQ applies the EQ predicate on the "user_id" field.
|
||||||
|
func UserIDEQ(v int64) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldEQ(FieldUserID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserIDNEQ applies the NEQ predicate on the "user_id" field.
|
||||||
|
func UserIDNEQ(v int64) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldNEQ(FieldUserID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserIDIn applies the In predicate on the "user_id" field.
|
||||||
|
func UserIDIn(vs ...int64) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldIn(FieldUserID, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserIDNotIn applies the NotIn predicate on the "user_id" field.
|
||||||
|
func UserIDNotIn(vs ...int64) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldNotIn(FieldUserID, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ContentTypeEQ applies the EQ predicate on the "content_type" field.
|
||||||
|
func ContentTypeEQ(v string) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldEQ(FieldContentType, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ContentTypeNEQ applies the NEQ predicate on the "content_type" field.
|
||||||
|
func ContentTypeNEQ(v string) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldNEQ(FieldContentType, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ContentTypeIn applies the In predicate on the "content_type" field.
|
||||||
|
func ContentTypeIn(vs ...string) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldIn(FieldContentType, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ContentTypeNotIn applies the NotIn predicate on the "content_type" field.
|
||||||
|
func ContentTypeNotIn(vs ...string) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldNotIn(FieldContentType, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ContentTypeGT applies the GT predicate on the "content_type" field.
|
||||||
|
func ContentTypeGT(v string) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldGT(FieldContentType, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ContentTypeGTE applies the GTE predicate on the "content_type" field.
|
||||||
|
func ContentTypeGTE(v string) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldGTE(FieldContentType, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ContentTypeLT applies the LT predicate on the "content_type" field.
|
||||||
|
func ContentTypeLT(v string) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldLT(FieldContentType, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ContentTypeLTE applies the LTE predicate on the "content_type" field.
|
||||||
|
func ContentTypeLTE(v string) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldLTE(FieldContentType, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ContentTypeContains applies the Contains predicate on the "content_type" field.
|
||||||
|
func ContentTypeContains(v string) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldContains(FieldContentType, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ContentTypeHasPrefix applies the HasPrefix predicate on the "content_type" field.
|
||||||
|
func ContentTypeHasPrefix(v string) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldHasPrefix(FieldContentType, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ContentTypeHasSuffix applies the HasSuffix predicate on the "content_type" field.
|
||||||
|
func ContentTypeHasSuffix(v string) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldHasSuffix(FieldContentType, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ContentTypeEqualFold applies the EqualFold predicate on the "content_type" field.
|
||||||
|
func ContentTypeEqualFold(v string) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldEqualFold(FieldContentType, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ContentTypeContainsFold applies the ContainsFold predicate on the "content_type" field.
|
||||||
|
func ContentTypeContainsFold(v string) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldContainsFold(FieldContentType, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ContentLengthEQ applies the EQ predicate on the "content_length" field.
|
||||||
|
func ContentLengthEQ(v int64) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldEQ(FieldContentLength, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ContentLengthNEQ applies the NEQ predicate on the "content_length" field.
|
||||||
|
func ContentLengthNEQ(v int64) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldNEQ(FieldContentLength, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ContentLengthIn applies the In predicate on the "content_length" field.
|
||||||
|
func ContentLengthIn(vs ...int64) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldIn(FieldContentLength, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ContentLengthNotIn applies the NotIn predicate on the "content_length" field.
|
||||||
|
func ContentLengthNotIn(vs ...int64) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldNotIn(FieldContentLength, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ContentLengthGT applies the GT predicate on the "content_length" field.
|
||||||
|
func ContentLengthGT(v int64) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldGT(FieldContentLength, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ContentLengthGTE applies the GTE predicate on the "content_length" field.
|
||||||
|
func ContentLengthGTE(v int64) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldGTE(FieldContentLength, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ContentLengthLT applies the LT predicate on the "content_length" field.
|
||||||
|
func ContentLengthLT(v int64) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldLT(FieldContentLength, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ContentLengthLTE applies the LTE predicate on the "content_length" field.
|
||||||
|
func ContentLengthLTE(v int64) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.FieldLTE(FieldContentLength, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasUser applies the HasEdge predicate on the "user" edge.
|
||||||
|
func HasUser() predicate.CpImage {
|
||||||
|
return predicate.CpImage(func(s *sql.Selector) {
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(Table, FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2O, true, UserTable, UserColumn),
|
||||||
|
)
|
||||||
|
sqlgraph.HasNeighbors(s, step)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasUserWith applies the HasEdge predicate on the "user" edge with a given conditions (other predicates).
|
||||||
|
func HasUserWith(preds ...predicate.SysUser) predicate.CpImage {
|
||||||
|
return predicate.CpImage(func(s *sql.Selector) {
|
||||||
|
step := newUserStep()
|
||||||
|
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||||
|
for _, p := range preds {
|
||||||
|
p(s)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// And groups predicates with the AND operator between them.
|
||||||
|
func And(predicates ...predicate.CpImage) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.AndPredicates(predicates...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Or groups predicates with the OR operator between them.
|
||||||
|
func Or(predicates ...predicate.CpImage) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.OrPredicates(predicates...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Not applies the not operator on the given predicate.
|
||||||
|
func Not(p predicate.CpImage) predicate.CpImage {
|
||||||
|
return predicate.CpImage(sql.NotPredicates(p))
|
||||||
|
}
|
||||||
@@ -0,0 +1,774 @@
|
|||||||
|
// ENT数据库文件,请勿编辑。
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"likedream-goframe/internal/ent/cpimage"
|
||||||
|
"likedream-goframe/internal/ent/sysuser"
|
||||||
|
"likedream-goframe/internal/framework/ent2"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
)
|
||||||
|
|
||||||
|
// CpImageCreate is the builder for creating a CpImage entity.
|
||||||
|
type CpImageCreate struct {
|
||||||
|
config
|
||||||
|
mutation *CpImageMutation
|
||||||
|
hooks []Hook
|
||||||
|
conflict []sql.ConflictOption
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCreateTime sets the "create_time" field.
|
||||||
|
func (cic *CpImageCreate) SetCreateTime(et ent2.CustomTime) *CpImageCreate {
|
||||||
|
cic.mutation.SetCreateTime(et)
|
||||||
|
return cic
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUpdateTime sets the "update_time" field.
|
||||||
|
func (cic *CpImageCreate) SetUpdateTime(et ent2.CustomTime) *CpImageCreate {
|
||||||
|
cic.mutation.SetUpdateTime(et)
|
||||||
|
return cic
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetImageID sets the "image_id" field.
|
||||||
|
func (cic *CpImageCreate) SetImageID(u uuid.UUID) *CpImageCreate {
|
||||||
|
cic.mutation.SetImageID(u)
|
||||||
|
return cic
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetKey sets the "key" field.
|
||||||
|
func (cic *CpImageCreate) SetKey(s string) *CpImageCreate {
|
||||||
|
cic.mutation.SetKey(s)
|
||||||
|
return cic
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUserID sets the "user_id" field.
|
||||||
|
func (cic *CpImageCreate) SetUserID(i int64) *CpImageCreate {
|
||||||
|
cic.mutation.SetUserID(i)
|
||||||
|
return cic
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetContentType sets the "content_type" field.
|
||||||
|
func (cic *CpImageCreate) SetContentType(s string) *CpImageCreate {
|
||||||
|
cic.mutation.SetContentType(s)
|
||||||
|
return cic
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetContentLength sets the "content_length" field.
|
||||||
|
func (cic *CpImageCreate) SetContentLength(i int64) *CpImageCreate {
|
||||||
|
cic.mutation.SetContentLength(i)
|
||||||
|
return cic
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUser sets the "user" edge to the SysUser entity.
|
||||||
|
func (cic *CpImageCreate) SetUser(s *SysUser) *CpImageCreate {
|
||||||
|
return cic.SetUserID(s.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the CpImageMutation object of the builder.
|
||||||
|
func (cic *CpImageCreate) Mutation() *CpImageMutation {
|
||||||
|
return cic.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save creates the CpImage in the database.
|
||||||
|
func (cic *CpImageCreate) Save(ctx context.Context) (*CpImage, error) {
|
||||||
|
return withHooks(ctx, cic.sqlSave, cic.mutation, cic.hooks)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX calls Save and panics if Save returns an error.
|
||||||
|
func (cic *CpImageCreate) SaveX(ctx context.Context) *CpImage {
|
||||||
|
v, err := cic.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (cic *CpImageCreate) Exec(ctx context.Context) error {
|
||||||
|
_, err := cic.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (cic *CpImageCreate) ExecX(ctx context.Context) {
|
||||||
|
if err := cic.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check runs all checks and user-defined validators on the builder.
|
||||||
|
func (cic *CpImageCreate) check() error {
|
||||||
|
if _, ok := cic.mutation.CreateTime(); !ok {
|
||||||
|
return &ValidationError{Name: "create_time", err: errors.New(`ent: missing required field "CpImage.create_time"`)}
|
||||||
|
}
|
||||||
|
if _, ok := cic.mutation.UpdateTime(); !ok {
|
||||||
|
return &ValidationError{Name: "update_time", err: errors.New(`ent: missing required field "CpImage.update_time"`)}
|
||||||
|
}
|
||||||
|
if _, ok := cic.mutation.ImageID(); !ok {
|
||||||
|
return &ValidationError{Name: "image_id", err: errors.New(`ent: missing required field "CpImage.image_id"`)}
|
||||||
|
}
|
||||||
|
if _, ok := cic.mutation.Key(); !ok {
|
||||||
|
return &ValidationError{Name: "key", err: errors.New(`ent: missing required field "CpImage.key"`)}
|
||||||
|
}
|
||||||
|
if v, ok := cic.mutation.Key(); ok {
|
||||||
|
if err := cpimage.KeyValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "key", err: fmt.Errorf(`ent: validator failed for field "CpImage.key": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if _, ok := cic.mutation.UserID(); !ok {
|
||||||
|
return &ValidationError{Name: "user_id", err: errors.New(`ent: missing required field "CpImage.user_id"`)}
|
||||||
|
}
|
||||||
|
if v, ok := cic.mutation.UserID(); ok {
|
||||||
|
if err := cpimage.UserIDValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "user_id", err: fmt.Errorf(`ent: validator failed for field "CpImage.user_id": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if _, ok := cic.mutation.ContentType(); !ok {
|
||||||
|
return &ValidationError{Name: "content_type", err: errors.New(`ent: missing required field "CpImage.content_type"`)}
|
||||||
|
}
|
||||||
|
if v, ok := cic.mutation.ContentType(); ok {
|
||||||
|
if err := cpimage.ContentTypeValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "content_type", err: fmt.Errorf(`ent: validator failed for field "CpImage.content_type": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if _, ok := cic.mutation.ContentLength(); !ok {
|
||||||
|
return &ValidationError{Name: "content_length", err: errors.New(`ent: missing required field "CpImage.content_length"`)}
|
||||||
|
}
|
||||||
|
if v, ok := cic.mutation.ContentLength(); ok {
|
||||||
|
if err := cpimage.ContentLengthValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "content_length", err: fmt.Errorf(`ent: validator failed for field "CpImage.content_length": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(cic.mutation.UserIDs()) == 0 {
|
||||||
|
return &ValidationError{Name: "user", err: errors.New(`ent: missing required edge "CpImage.user"`)}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cic *CpImageCreate) sqlSave(ctx context.Context) (*CpImage, error) {
|
||||||
|
if err := cic.check(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
_node, _spec := cic.createSpec()
|
||||||
|
if err := sqlgraph.CreateNode(ctx, cic.driver, _spec); err != nil {
|
||||||
|
if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
id := _spec.ID.Value.(int64)
|
||||||
|
_node.ID = int64(id)
|
||||||
|
cic.mutation.id = &_node.ID
|
||||||
|
cic.mutation.done = true
|
||||||
|
return _node, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cic *CpImageCreate) createSpec() (*CpImage, *sqlgraph.CreateSpec) {
|
||||||
|
var (
|
||||||
|
_node = &CpImage{config: cic.config}
|
||||||
|
_spec = sqlgraph.NewCreateSpec(cpimage.Table, sqlgraph.NewFieldSpec(cpimage.FieldID, field.TypeInt64))
|
||||||
|
)
|
||||||
|
_spec.OnConflict = cic.conflict
|
||||||
|
if value, ok := cic.mutation.CreateTime(); ok {
|
||||||
|
_spec.SetField(cpimage.FieldCreateTime, field.TypeString, value)
|
||||||
|
_node.CreateTime = value
|
||||||
|
}
|
||||||
|
if value, ok := cic.mutation.UpdateTime(); ok {
|
||||||
|
_spec.SetField(cpimage.FieldUpdateTime, field.TypeString, value)
|
||||||
|
_node.UpdateTime = value
|
||||||
|
}
|
||||||
|
if value, ok := cic.mutation.ImageID(); ok {
|
||||||
|
_spec.SetField(cpimage.FieldImageID, field.TypeUUID, value)
|
||||||
|
_node.ImageID = value
|
||||||
|
}
|
||||||
|
if value, ok := cic.mutation.Key(); ok {
|
||||||
|
_spec.SetField(cpimage.FieldKey, field.TypeString, value)
|
||||||
|
_node.Key = value
|
||||||
|
}
|
||||||
|
if value, ok := cic.mutation.ContentType(); ok {
|
||||||
|
_spec.SetField(cpimage.FieldContentType, field.TypeString, value)
|
||||||
|
_node.ContentType = value
|
||||||
|
}
|
||||||
|
if value, ok := cic.mutation.ContentLength(); ok {
|
||||||
|
_spec.SetField(cpimage.FieldContentLength, field.TypeInt64, value)
|
||||||
|
_node.ContentLength = value
|
||||||
|
}
|
||||||
|
if nodes := cic.mutation.UserIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: cpimage.UserTable,
|
||||||
|
Columns: []string{cpimage.UserColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(sysuser.FieldID, field.TypeInt64),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_node.UserID = nodes[0]
|
||||||
|
_spec.Edges = append(_spec.Edges, edge)
|
||||||
|
}
|
||||||
|
return _node, _spec
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
|
||||||
|
// of the `INSERT` statement. For example:
|
||||||
|
//
|
||||||
|
// client.CpImage.Create().
|
||||||
|
// SetCreateTime(v).
|
||||||
|
// OnConflict(
|
||||||
|
// // Update the row with the new values
|
||||||
|
// // the was proposed for insertion.
|
||||||
|
// sql.ResolveWithNewValues(),
|
||||||
|
// ).
|
||||||
|
// // Override some of the fields with custom
|
||||||
|
// // update values.
|
||||||
|
// Update(func(u *ent.CpImageUpsert) {
|
||||||
|
// SetCreateTime(v+v).
|
||||||
|
// }).
|
||||||
|
// Exec(ctx)
|
||||||
|
func (cic *CpImageCreate) OnConflict(opts ...sql.ConflictOption) *CpImageUpsertOne {
|
||||||
|
cic.conflict = opts
|
||||||
|
return &CpImageUpsertOne{
|
||||||
|
create: cic,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
||||||
|
// as conflict target. Using this option is equivalent to using:
|
||||||
|
//
|
||||||
|
// client.CpImage.Create().
|
||||||
|
// OnConflict(sql.ConflictColumns(columns...)).
|
||||||
|
// Exec(ctx)
|
||||||
|
func (cic *CpImageCreate) OnConflictColumns(columns ...string) *CpImageUpsertOne {
|
||||||
|
cic.conflict = append(cic.conflict, sql.ConflictColumns(columns...))
|
||||||
|
return &CpImageUpsertOne{
|
||||||
|
create: cic,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type (
|
||||||
|
// CpImageUpsertOne is the builder for "upsert"-ing
|
||||||
|
// one CpImage node.
|
||||||
|
CpImageUpsertOne struct {
|
||||||
|
create *CpImageCreate
|
||||||
|
}
|
||||||
|
|
||||||
|
// CpImageUpsert is the "OnConflict" setter.
|
||||||
|
CpImageUpsert struct {
|
||||||
|
*sql.UpdateSet
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// SetUpdateTime sets the "update_time" field.
|
||||||
|
func (u *CpImageUpsert) SetUpdateTime(v ent2.CustomTime) *CpImageUpsert {
|
||||||
|
u.Set(cpimage.FieldUpdateTime, v)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateUpdateTime sets the "update_time" field to the value that was provided on create.
|
||||||
|
func (u *CpImageUpsert) UpdateUpdateTime() *CpImageUpsert {
|
||||||
|
u.SetExcluded(cpimage.FieldUpdateTime)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetKey sets the "key" field.
|
||||||
|
func (u *CpImageUpsert) SetKey(v string) *CpImageUpsert {
|
||||||
|
u.Set(cpimage.FieldKey, v)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateKey sets the "key" field to the value that was provided on create.
|
||||||
|
func (u *CpImageUpsert) UpdateKey() *CpImageUpsert {
|
||||||
|
u.SetExcluded(cpimage.FieldKey)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUserID sets the "user_id" field.
|
||||||
|
func (u *CpImageUpsert) SetUserID(v int64) *CpImageUpsert {
|
||||||
|
u.Set(cpimage.FieldUserID, v)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateUserID sets the "user_id" field to the value that was provided on create.
|
||||||
|
func (u *CpImageUpsert) UpdateUserID() *CpImageUpsert {
|
||||||
|
u.SetExcluded(cpimage.FieldUserID)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetContentType sets the "content_type" field.
|
||||||
|
func (u *CpImageUpsert) SetContentType(v string) *CpImageUpsert {
|
||||||
|
u.Set(cpimage.FieldContentType, v)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateContentType sets the "content_type" field to the value that was provided on create.
|
||||||
|
func (u *CpImageUpsert) UpdateContentType() *CpImageUpsert {
|
||||||
|
u.SetExcluded(cpimage.FieldContentType)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetContentLength sets the "content_length" field.
|
||||||
|
func (u *CpImageUpsert) SetContentLength(v int64) *CpImageUpsert {
|
||||||
|
u.Set(cpimage.FieldContentLength, v)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateContentLength sets the "content_length" field to the value that was provided on create.
|
||||||
|
func (u *CpImageUpsert) UpdateContentLength() *CpImageUpsert {
|
||||||
|
u.SetExcluded(cpimage.FieldContentLength)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddContentLength adds v to the "content_length" field.
|
||||||
|
func (u *CpImageUpsert) AddContentLength(v int64) *CpImageUpsert {
|
||||||
|
u.Add(cpimage.FieldContentLength, v)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateNewValues updates the mutable fields using the new values that were set on create.
|
||||||
|
// Using this option is equivalent to using:
|
||||||
|
//
|
||||||
|
// client.CpImage.Create().
|
||||||
|
// OnConflict(
|
||||||
|
// sql.ResolveWithNewValues(),
|
||||||
|
// ).
|
||||||
|
// Exec(ctx)
|
||||||
|
func (u *CpImageUpsertOne) UpdateNewValues() *CpImageUpsertOne {
|
||||||
|
u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
|
||||||
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
|
||||||
|
if _, exists := u.create.mutation.CreateTime(); exists {
|
||||||
|
s.SetIgnore(cpimage.FieldCreateTime)
|
||||||
|
}
|
||||||
|
if _, exists := u.create.mutation.ImageID(); exists {
|
||||||
|
s.SetIgnore(cpimage.FieldImageID)
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ignore sets each column to itself in case of conflict.
|
||||||
|
// Using this option is equivalent to using:
|
||||||
|
//
|
||||||
|
// client.CpImage.Create().
|
||||||
|
// OnConflict(sql.ResolveWithIgnore()).
|
||||||
|
// Exec(ctx)
|
||||||
|
func (u *CpImageUpsertOne) Ignore() *CpImageUpsertOne {
|
||||||
|
u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// DoNothing configures the conflict_action to `DO NOTHING`.
|
||||||
|
// Supported only by SQLite and PostgreSQL.
|
||||||
|
func (u *CpImageUpsertOne) DoNothing() *CpImageUpsertOne {
|
||||||
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update allows overriding fields `UPDATE` values. See the CpImageCreate.OnConflict
|
||||||
|
// documentation for more info.
|
||||||
|
func (u *CpImageUpsertOne) Update(set func(*CpImageUpsert)) *CpImageUpsertOne {
|
||||||
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
||||||
|
set(&CpImageUpsert{UpdateSet: update})
|
||||||
|
}))
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUpdateTime sets the "update_time" field.
|
||||||
|
func (u *CpImageUpsertOne) SetUpdateTime(v ent2.CustomTime) *CpImageUpsertOne {
|
||||||
|
return u.Update(func(s *CpImageUpsert) {
|
||||||
|
s.SetUpdateTime(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateUpdateTime sets the "update_time" field to the value that was provided on create.
|
||||||
|
func (u *CpImageUpsertOne) UpdateUpdateTime() *CpImageUpsertOne {
|
||||||
|
return u.Update(func(s *CpImageUpsert) {
|
||||||
|
s.UpdateUpdateTime()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetKey sets the "key" field.
|
||||||
|
func (u *CpImageUpsertOne) SetKey(v string) *CpImageUpsertOne {
|
||||||
|
return u.Update(func(s *CpImageUpsert) {
|
||||||
|
s.SetKey(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateKey sets the "key" field to the value that was provided on create.
|
||||||
|
func (u *CpImageUpsertOne) UpdateKey() *CpImageUpsertOne {
|
||||||
|
return u.Update(func(s *CpImageUpsert) {
|
||||||
|
s.UpdateKey()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUserID sets the "user_id" field.
|
||||||
|
func (u *CpImageUpsertOne) SetUserID(v int64) *CpImageUpsertOne {
|
||||||
|
return u.Update(func(s *CpImageUpsert) {
|
||||||
|
s.SetUserID(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateUserID sets the "user_id" field to the value that was provided on create.
|
||||||
|
func (u *CpImageUpsertOne) UpdateUserID() *CpImageUpsertOne {
|
||||||
|
return u.Update(func(s *CpImageUpsert) {
|
||||||
|
s.UpdateUserID()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetContentType sets the "content_type" field.
|
||||||
|
func (u *CpImageUpsertOne) SetContentType(v string) *CpImageUpsertOne {
|
||||||
|
return u.Update(func(s *CpImageUpsert) {
|
||||||
|
s.SetContentType(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateContentType sets the "content_type" field to the value that was provided on create.
|
||||||
|
func (u *CpImageUpsertOne) UpdateContentType() *CpImageUpsertOne {
|
||||||
|
return u.Update(func(s *CpImageUpsert) {
|
||||||
|
s.UpdateContentType()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetContentLength sets the "content_length" field.
|
||||||
|
func (u *CpImageUpsertOne) SetContentLength(v int64) *CpImageUpsertOne {
|
||||||
|
return u.Update(func(s *CpImageUpsert) {
|
||||||
|
s.SetContentLength(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddContentLength adds v to the "content_length" field.
|
||||||
|
func (u *CpImageUpsertOne) AddContentLength(v int64) *CpImageUpsertOne {
|
||||||
|
return u.Update(func(s *CpImageUpsert) {
|
||||||
|
s.AddContentLength(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateContentLength sets the "content_length" field to the value that was provided on create.
|
||||||
|
func (u *CpImageUpsertOne) UpdateContentLength() *CpImageUpsertOne {
|
||||||
|
return u.Update(func(s *CpImageUpsert) {
|
||||||
|
s.UpdateContentLength()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (u *CpImageUpsertOne) Exec(ctx context.Context) error {
|
||||||
|
if len(u.create.conflict) == 0 {
|
||||||
|
return errors.New("ent: missing options for CpImageCreate.OnConflict")
|
||||||
|
}
|
||||||
|
return u.create.Exec(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (u *CpImageUpsertOne) ExecX(ctx context.Context) {
|
||||||
|
if err := u.create.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the UPSERT query and returns the inserted/updated ID.
|
||||||
|
func (u *CpImageUpsertOne) ID(ctx context.Context) (id int64, err error) {
|
||||||
|
node, err := u.create.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return id, err
|
||||||
|
}
|
||||||
|
return node.ID, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDX is like ID, but panics if an error occurs.
|
||||||
|
func (u *CpImageUpsertOne) IDX(ctx context.Context) int64 {
|
||||||
|
id, err := u.ID(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
// CpImageCreateBulk is the builder for creating many CpImage entities in bulk.
|
||||||
|
type CpImageCreateBulk struct {
|
||||||
|
config
|
||||||
|
err error
|
||||||
|
builders []*CpImageCreate
|
||||||
|
conflict []sql.ConflictOption
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save creates the CpImage entities in the database.
|
||||||
|
func (cicb *CpImageCreateBulk) Save(ctx context.Context) ([]*CpImage, error) {
|
||||||
|
if cicb.err != nil {
|
||||||
|
return nil, cicb.err
|
||||||
|
}
|
||||||
|
specs := make([]*sqlgraph.CreateSpec, len(cicb.builders))
|
||||||
|
nodes := make([]*CpImage, len(cicb.builders))
|
||||||
|
mutators := make([]Mutator, len(cicb.builders))
|
||||||
|
for i := range cicb.builders {
|
||||||
|
func(i int, root context.Context) {
|
||||||
|
builder := cicb.builders[i]
|
||||||
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||||
|
mutation, ok := m.(*CpImageMutation)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||||
|
}
|
||||||
|
if err := builder.check(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
builder.mutation = mutation
|
||||||
|
var err error
|
||||||
|
nodes[i], specs[i] = builder.createSpec()
|
||||||
|
if i < len(mutators)-1 {
|
||||||
|
_, err = mutators[i+1].Mutate(root, cicb.builders[i+1].mutation)
|
||||||
|
} else {
|
||||||
|
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
|
||||||
|
spec.OnConflict = cicb.conflict
|
||||||
|
// Invoke the actual operation on the latest mutation in the chain.
|
||||||
|
if err = sqlgraph.BatchCreate(ctx, cicb.driver, spec); err != nil {
|
||||||
|
if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
mutation.id = &nodes[i].ID
|
||||||
|
if specs[i].ID.Value != nil {
|
||||||
|
id := specs[i].ID.Value.(int64)
|
||||||
|
nodes[i].ID = int64(id)
|
||||||
|
}
|
||||||
|
mutation.done = true
|
||||||
|
return nodes[i], nil
|
||||||
|
})
|
||||||
|
for i := len(builder.hooks) - 1; i >= 0; i-- {
|
||||||
|
mut = builder.hooks[i](mut)
|
||||||
|
}
|
||||||
|
mutators[i] = mut
|
||||||
|
}(i, ctx)
|
||||||
|
}
|
||||||
|
if len(mutators) > 0 {
|
||||||
|
if _, err := mutators[0].Mutate(ctx, cicb.builders[0].mutation); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nodes, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX is like Save, but panics if an error occurs.
|
||||||
|
func (cicb *CpImageCreateBulk) SaveX(ctx context.Context) []*CpImage {
|
||||||
|
v, err := cicb.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (cicb *CpImageCreateBulk) Exec(ctx context.Context) error {
|
||||||
|
_, err := cicb.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (cicb *CpImageCreateBulk) ExecX(ctx context.Context) {
|
||||||
|
if err := cicb.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
|
||||||
|
// of the `INSERT` statement. For example:
|
||||||
|
//
|
||||||
|
// client.CpImage.CreateBulk(builders...).
|
||||||
|
// OnConflict(
|
||||||
|
// // Update the row with the new values
|
||||||
|
// // the was proposed for insertion.
|
||||||
|
// sql.ResolveWithNewValues(),
|
||||||
|
// ).
|
||||||
|
// // Override some of the fields with custom
|
||||||
|
// // update values.
|
||||||
|
// Update(func(u *ent.CpImageUpsert) {
|
||||||
|
// SetCreateTime(v+v).
|
||||||
|
// }).
|
||||||
|
// Exec(ctx)
|
||||||
|
func (cicb *CpImageCreateBulk) OnConflict(opts ...sql.ConflictOption) *CpImageUpsertBulk {
|
||||||
|
cicb.conflict = opts
|
||||||
|
return &CpImageUpsertBulk{
|
||||||
|
create: cicb,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
||||||
|
// as conflict target. Using this option is equivalent to using:
|
||||||
|
//
|
||||||
|
// client.CpImage.Create().
|
||||||
|
// OnConflict(sql.ConflictColumns(columns...)).
|
||||||
|
// Exec(ctx)
|
||||||
|
func (cicb *CpImageCreateBulk) OnConflictColumns(columns ...string) *CpImageUpsertBulk {
|
||||||
|
cicb.conflict = append(cicb.conflict, sql.ConflictColumns(columns...))
|
||||||
|
return &CpImageUpsertBulk{
|
||||||
|
create: cicb,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// CpImageUpsertBulk is the builder for "upsert"-ing
|
||||||
|
// a bulk of CpImage nodes.
|
||||||
|
type CpImageUpsertBulk struct {
|
||||||
|
create *CpImageCreateBulk
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateNewValues updates the mutable fields using the new values that
|
||||||
|
// were set on create. Using this option is equivalent to using:
|
||||||
|
//
|
||||||
|
// client.CpImage.Create().
|
||||||
|
// OnConflict(
|
||||||
|
// sql.ResolveWithNewValues(),
|
||||||
|
// ).
|
||||||
|
// Exec(ctx)
|
||||||
|
func (u *CpImageUpsertBulk) UpdateNewValues() *CpImageUpsertBulk {
|
||||||
|
u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
|
||||||
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
|
||||||
|
for _, b := range u.create.builders {
|
||||||
|
if _, exists := b.mutation.CreateTime(); exists {
|
||||||
|
s.SetIgnore(cpimage.FieldCreateTime)
|
||||||
|
}
|
||||||
|
if _, exists := b.mutation.ImageID(); exists {
|
||||||
|
s.SetIgnore(cpimage.FieldImageID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ignore sets each column to itself in case of conflict.
|
||||||
|
// Using this option is equivalent to using:
|
||||||
|
//
|
||||||
|
// client.CpImage.Create().
|
||||||
|
// OnConflict(sql.ResolveWithIgnore()).
|
||||||
|
// Exec(ctx)
|
||||||
|
func (u *CpImageUpsertBulk) Ignore() *CpImageUpsertBulk {
|
||||||
|
u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// DoNothing configures the conflict_action to `DO NOTHING`.
|
||||||
|
// Supported only by SQLite and PostgreSQL.
|
||||||
|
func (u *CpImageUpsertBulk) DoNothing() *CpImageUpsertBulk {
|
||||||
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update allows overriding fields `UPDATE` values. See the CpImageCreateBulk.OnConflict
|
||||||
|
// documentation for more info.
|
||||||
|
func (u *CpImageUpsertBulk) Update(set func(*CpImageUpsert)) *CpImageUpsertBulk {
|
||||||
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
||||||
|
set(&CpImageUpsert{UpdateSet: update})
|
||||||
|
}))
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUpdateTime sets the "update_time" field.
|
||||||
|
func (u *CpImageUpsertBulk) SetUpdateTime(v ent2.CustomTime) *CpImageUpsertBulk {
|
||||||
|
return u.Update(func(s *CpImageUpsert) {
|
||||||
|
s.SetUpdateTime(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateUpdateTime sets the "update_time" field to the value that was provided on create.
|
||||||
|
func (u *CpImageUpsertBulk) UpdateUpdateTime() *CpImageUpsertBulk {
|
||||||
|
return u.Update(func(s *CpImageUpsert) {
|
||||||
|
s.UpdateUpdateTime()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetKey sets the "key" field.
|
||||||
|
func (u *CpImageUpsertBulk) SetKey(v string) *CpImageUpsertBulk {
|
||||||
|
return u.Update(func(s *CpImageUpsert) {
|
||||||
|
s.SetKey(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateKey sets the "key" field to the value that was provided on create.
|
||||||
|
func (u *CpImageUpsertBulk) UpdateKey() *CpImageUpsertBulk {
|
||||||
|
return u.Update(func(s *CpImageUpsert) {
|
||||||
|
s.UpdateKey()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUserID sets the "user_id" field.
|
||||||
|
func (u *CpImageUpsertBulk) SetUserID(v int64) *CpImageUpsertBulk {
|
||||||
|
return u.Update(func(s *CpImageUpsert) {
|
||||||
|
s.SetUserID(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateUserID sets the "user_id" field to the value that was provided on create.
|
||||||
|
func (u *CpImageUpsertBulk) UpdateUserID() *CpImageUpsertBulk {
|
||||||
|
return u.Update(func(s *CpImageUpsert) {
|
||||||
|
s.UpdateUserID()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetContentType sets the "content_type" field.
|
||||||
|
func (u *CpImageUpsertBulk) SetContentType(v string) *CpImageUpsertBulk {
|
||||||
|
return u.Update(func(s *CpImageUpsert) {
|
||||||
|
s.SetContentType(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateContentType sets the "content_type" field to the value that was provided on create.
|
||||||
|
func (u *CpImageUpsertBulk) UpdateContentType() *CpImageUpsertBulk {
|
||||||
|
return u.Update(func(s *CpImageUpsert) {
|
||||||
|
s.UpdateContentType()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetContentLength sets the "content_length" field.
|
||||||
|
func (u *CpImageUpsertBulk) SetContentLength(v int64) *CpImageUpsertBulk {
|
||||||
|
return u.Update(func(s *CpImageUpsert) {
|
||||||
|
s.SetContentLength(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddContentLength adds v to the "content_length" field.
|
||||||
|
func (u *CpImageUpsertBulk) AddContentLength(v int64) *CpImageUpsertBulk {
|
||||||
|
return u.Update(func(s *CpImageUpsert) {
|
||||||
|
s.AddContentLength(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateContentLength sets the "content_length" field to the value that was provided on create.
|
||||||
|
func (u *CpImageUpsertBulk) UpdateContentLength() *CpImageUpsertBulk {
|
||||||
|
return u.Update(func(s *CpImageUpsert) {
|
||||||
|
s.UpdateContentLength()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (u *CpImageUpsertBulk) Exec(ctx context.Context) error {
|
||||||
|
if u.create.err != nil {
|
||||||
|
return u.create.err
|
||||||
|
}
|
||||||
|
for i, b := range u.create.builders {
|
||||||
|
if len(b.conflict) != 0 {
|
||||||
|
return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the CpImageCreateBulk instead", i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(u.create.conflict) == 0 {
|
||||||
|
return errors.New("ent: missing options for CpImageCreateBulk.OnConflict")
|
||||||
|
}
|
||||||
|
return u.create.Exec(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (u *CpImageUpsertBulk) ExecX(ctx context.Context) {
|
||||||
|
if err := u.create.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,88 @@
|
|||||||
|
// ENT数据库文件,请勿编辑。
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"likedream-goframe/internal/ent/cpimage"
|
||||||
|
"likedream-goframe/internal/ent/predicate"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
)
|
||||||
|
|
||||||
|
// CpImageDelete is the builder for deleting a CpImage entity.
|
||||||
|
type CpImageDelete struct {
|
||||||
|
config
|
||||||
|
hooks []Hook
|
||||||
|
mutation *CpImageMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the CpImageDelete builder.
|
||||||
|
func (cid *CpImageDelete) Where(ps ...predicate.CpImage) *CpImageDelete {
|
||||||
|
cid.mutation.Where(ps...)
|
||||||
|
return cid
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||||
|
func (cid *CpImageDelete) Exec(ctx context.Context) (int, error) {
|
||||||
|
return withHooks(ctx, cid.sqlExec, cid.mutation, cid.hooks)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (cid *CpImageDelete) ExecX(ctx context.Context) int {
|
||||||
|
n, err := cid.Exec(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cid *CpImageDelete) sqlExec(ctx context.Context) (int, error) {
|
||||||
|
_spec := sqlgraph.NewDeleteSpec(cpimage.Table, sqlgraph.NewFieldSpec(cpimage.FieldID, field.TypeInt64))
|
||||||
|
if ps := cid.mutation.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
affected, err := sqlgraph.DeleteNodes(ctx, cid.driver, _spec)
|
||||||
|
if err != nil && sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
cid.mutation.done = true
|
||||||
|
return affected, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// CpImageDeleteOne is the builder for deleting a single CpImage entity.
|
||||||
|
type CpImageDeleteOne struct {
|
||||||
|
cid *CpImageDelete
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the CpImageDelete builder.
|
||||||
|
func (cido *CpImageDeleteOne) Where(ps ...predicate.CpImage) *CpImageDeleteOne {
|
||||||
|
cido.cid.mutation.Where(ps...)
|
||||||
|
return cido
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the deletion query.
|
||||||
|
func (cido *CpImageDeleteOne) Exec(ctx context.Context) error {
|
||||||
|
n, err := cido.cid.Exec(ctx)
|
||||||
|
switch {
|
||||||
|
case err != nil:
|
||||||
|
return err
|
||||||
|
case n == 0:
|
||||||
|
return &NotFoundError{cpimage.Label}
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (cido *CpImageDeleteOne) ExecX(ctx context.Context) {
|
||||||
|
if err := cido.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,606 @@
|
|||||||
|
// ENT数据库文件,请勿编辑。
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"likedream-goframe/internal/ent/cpimage"
|
||||||
|
"likedream-goframe/internal/ent/predicate"
|
||||||
|
"likedream-goframe/internal/ent/sysuser"
|
||||||
|
"math"
|
||||||
|
|
||||||
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
)
|
||||||
|
|
||||||
|
// CpImageQuery is the builder for querying CpImage entities.
|
||||||
|
type CpImageQuery struct {
|
||||||
|
config
|
||||||
|
ctx *QueryContext
|
||||||
|
order []cpimage.OrderOption
|
||||||
|
inters []Interceptor
|
||||||
|
predicates []predicate.CpImage
|
||||||
|
withUser *SysUserQuery
|
||||||
|
// intermediate query (i.e. traversal path).
|
||||||
|
sql *sql.Selector
|
||||||
|
path func(context.Context) (*sql.Selector, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where adds a new predicate for the CpImageQuery builder.
|
||||||
|
func (ciq *CpImageQuery) Where(ps ...predicate.CpImage) *CpImageQuery {
|
||||||
|
ciq.predicates = append(ciq.predicates, ps...)
|
||||||
|
return ciq
|
||||||
|
}
|
||||||
|
|
||||||
|
// Limit the number of records to be returned by this query.
|
||||||
|
func (ciq *CpImageQuery) Limit(limit int) *CpImageQuery {
|
||||||
|
ciq.ctx.Limit = &limit
|
||||||
|
return ciq
|
||||||
|
}
|
||||||
|
|
||||||
|
// Offset to start from.
|
||||||
|
func (ciq *CpImageQuery) Offset(offset int) *CpImageQuery {
|
||||||
|
ciq.ctx.Offset = &offset
|
||||||
|
return ciq
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unique configures the query builder to filter duplicate records on query.
|
||||||
|
// By default, unique is set to true, and can be disabled using this method.
|
||||||
|
func (ciq *CpImageQuery) Unique(unique bool) *CpImageQuery {
|
||||||
|
ciq.ctx.Unique = &unique
|
||||||
|
return ciq
|
||||||
|
}
|
||||||
|
|
||||||
|
// Order specifies how the records should be ordered.
|
||||||
|
func (ciq *CpImageQuery) Order(o ...cpimage.OrderOption) *CpImageQuery {
|
||||||
|
ciq.order = append(ciq.order, o...)
|
||||||
|
return ciq
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryUser chains the current query on the "user" edge.
|
||||||
|
func (ciq *CpImageQuery) QueryUser() *SysUserQuery {
|
||||||
|
query := (&SysUserClient{config: ciq.config}).Query()
|
||||||
|
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||||
|
if err := ciq.prepareQuery(ctx); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
selector := ciq.sqlQuery(ctx)
|
||||||
|
if err := selector.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(cpimage.Table, cpimage.FieldID, selector),
|
||||||
|
sqlgraph.To(sysuser.Table, sysuser.FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2O, true, cpimage.UserTable, cpimage.UserColumn),
|
||||||
|
)
|
||||||
|
fromU = sqlgraph.SetNeighbors(ciq.driver.Dialect(), step)
|
||||||
|
return fromU, nil
|
||||||
|
}
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
|
// First returns the first CpImage entity from the query.
|
||||||
|
// Returns a *NotFoundError when no CpImage was found.
|
||||||
|
func (ciq *CpImageQuery) First(ctx context.Context) (*CpImage, error) {
|
||||||
|
nodes, err := ciq.Limit(1).All(setContextOp(ctx, ciq.ctx, ent.OpQueryFirst))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(nodes) == 0 {
|
||||||
|
return nil, &NotFoundError{cpimage.Label}
|
||||||
|
}
|
||||||
|
return nodes[0], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirstX is like First, but panics if an error occurs.
|
||||||
|
func (ciq *CpImageQuery) FirstX(ctx context.Context) *CpImage {
|
||||||
|
node, err := ciq.First(ctx)
|
||||||
|
if err != nil && !IsNotFound(err) {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirstID returns the first CpImage ID from the query.
|
||||||
|
// Returns a *NotFoundError when no CpImage ID was found.
|
||||||
|
func (ciq *CpImageQuery) FirstID(ctx context.Context) (id int64, err error) {
|
||||||
|
var ids []int64
|
||||||
|
if ids, err = ciq.Limit(1).IDs(setContextOp(ctx, ciq.ctx, ent.OpQueryFirstID)); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if len(ids) == 0 {
|
||||||
|
err = &NotFoundError{cpimage.Label}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return ids[0], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||||
|
func (ciq *CpImageQuery) FirstIDX(ctx context.Context) int64 {
|
||||||
|
id, err := ciq.FirstID(ctx)
|
||||||
|
if err != nil && !IsNotFound(err) {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only returns a single CpImage entity found by the query, ensuring it only returns one.
|
||||||
|
// Returns a *NotSingularError when more than one CpImage entity is found.
|
||||||
|
// Returns a *NotFoundError when no CpImage entities are found.
|
||||||
|
func (ciq *CpImageQuery) Only(ctx context.Context) (*CpImage, error) {
|
||||||
|
nodes, err := ciq.Limit(2).All(setContextOp(ctx, ciq.ctx, ent.OpQueryOnly))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
switch len(nodes) {
|
||||||
|
case 1:
|
||||||
|
return nodes[0], nil
|
||||||
|
case 0:
|
||||||
|
return nil, &NotFoundError{cpimage.Label}
|
||||||
|
default:
|
||||||
|
return nil, &NotSingularError{cpimage.Label}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlyX is like Only, but panics if an error occurs.
|
||||||
|
func (ciq *CpImageQuery) OnlyX(ctx context.Context) *CpImage {
|
||||||
|
node, err := ciq.Only(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlyID is like Only, but returns the only CpImage ID in the query.
|
||||||
|
// Returns a *NotSingularError when more than one CpImage ID is found.
|
||||||
|
// Returns a *NotFoundError when no entities are found.
|
||||||
|
func (ciq *CpImageQuery) OnlyID(ctx context.Context) (id int64, err error) {
|
||||||
|
var ids []int64
|
||||||
|
if ids, err = ciq.Limit(2).IDs(setContextOp(ctx, ciq.ctx, ent.OpQueryOnlyID)); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch len(ids) {
|
||||||
|
case 1:
|
||||||
|
id = ids[0]
|
||||||
|
case 0:
|
||||||
|
err = &NotFoundError{cpimage.Label}
|
||||||
|
default:
|
||||||
|
err = &NotSingularError{cpimage.Label}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||||
|
func (ciq *CpImageQuery) OnlyIDX(ctx context.Context) int64 {
|
||||||
|
id, err := ciq.OnlyID(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
// All executes the query and returns a list of CpImages.
|
||||||
|
func (ciq *CpImageQuery) All(ctx context.Context) ([]*CpImage, error) {
|
||||||
|
ctx = setContextOp(ctx, ciq.ctx, ent.OpQueryAll)
|
||||||
|
if err := ciq.prepareQuery(ctx); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
qr := querierAll[[]*CpImage, *CpImageQuery]()
|
||||||
|
return withInterceptors[[]*CpImage](ctx, ciq, qr, ciq.inters)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AllX is like All, but panics if an error occurs.
|
||||||
|
func (ciq *CpImageQuery) AllX(ctx context.Context) []*CpImage {
|
||||||
|
nodes, err := ciq.All(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return nodes
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDs executes the query and returns a list of CpImage IDs.
|
||||||
|
func (ciq *CpImageQuery) IDs(ctx context.Context) (ids []int64, err error) {
|
||||||
|
if ciq.ctx.Unique == nil && ciq.path != nil {
|
||||||
|
ciq.Unique(true)
|
||||||
|
}
|
||||||
|
ctx = setContextOp(ctx, ciq.ctx, ent.OpQueryIDs)
|
||||||
|
if err = ciq.Select(cpimage.FieldID).Scan(ctx, &ids); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return ids, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDsX is like IDs, but panics if an error occurs.
|
||||||
|
func (ciq *CpImageQuery) IDsX(ctx context.Context) []int64 {
|
||||||
|
ids, err := ciq.IDs(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return ids
|
||||||
|
}
|
||||||
|
|
||||||
|
// Count returns the count of the given query.
|
||||||
|
func (ciq *CpImageQuery) Count(ctx context.Context) (int, error) {
|
||||||
|
ctx = setContextOp(ctx, ciq.ctx, ent.OpQueryCount)
|
||||||
|
if err := ciq.prepareQuery(ctx); err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
return withInterceptors[int](ctx, ciq, querierCount[*CpImageQuery](), ciq.inters)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CountX is like Count, but panics if an error occurs.
|
||||||
|
func (ciq *CpImageQuery) CountX(ctx context.Context) int {
|
||||||
|
count, err := ciq.Count(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return count
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exist returns true if the query has elements in the graph.
|
||||||
|
func (ciq *CpImageQuery) Exist(ctx context.Context) (bool, error) {
|
||||||
|
ctx = setContextOp(ctx, ciq.ctx, ent.OpQueryExist)
|
||||||
|
switch _, err := ciq.FirstID(ctx); {
|
||||||
|
case IsNotFound(err):
|
||||||
|
return false, nil
|
||||||
|
case err != nil:
|
||||||
|
return false, fmt.Errorf("ent: check existence: %w", err)
|
||||||
|
default:
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExistX is like Exist, but panics if an error occurs.
|
||||||
|
func (ciq *CpImageQuery) ExistX(ctx context.Context) bool {
|
||||||
|
exist, err := ciq.Exist(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return exist
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clone returns a duplicate of the CpImageQuery builder, including all associated steps. It can be
|
||||||
|
// used to prepare common query builders and use them differently after the clone is made.
|
||||||
|
func (ciq *CpImageQuery) Clone() *CpImageQuery {
|
||||||
|
if ciq == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return &CpImageQuery{
|
||||||
|
config: ciq.config,
|
||||||
|
ctx: ciq.ctx.Clone(),
|
||||||
|
order: append([]cpimage.OrderOption{}, ciq.order...),
|
||||||
|
inters: append([]Interceptor{}, ciq.inters...),
|
||||||
|
predicates: append([]predicate.CpImage{}, ciq.predicates...),
|
||||||
|
withUser: ciq.withUser.Clone(),
|
||||||
|
// clone intermediate query.
|
||||||
|
sql: ciq.sql.Clone(),
|
||||||
|
path: ciq.path,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithUser tells the query-builder to eager-load the nodes that are connected to
|
||||||
|
// the "user" edge. The optional arguments are used to configure the query builder of the edge.
|
||||||
|
func (ciq *CpImageQuery) WithUser(opts ...func(*SysUserQuery)) *CpImageQuery {
|
||||||
|
query := (&SysUserClient{config: ciq.config}).Query()
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt(query)
|
||||||
|
}
|
||||||
|
ciq.withUser = query
|
||||||
|
return ciq
|
||||||
|
}
|
||||||
|
|
||||||
|
// GroupBy is used to group vertices by one or more fields/columns.
|
||||||
|
// It is often used with aggregate functions, like: count, max, mean, min, sum.
|
||||||
|
//
|
||||||
|
// Example:
|
||||||
|
//
|
||||||
|
// var v []struct {
|
||||||
|
// CreateTime ent2.CustomTime `json:"createTime"`
|
||||||
|
// Count int `json:"count,omitempty"`
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// client.CpImage.Query().
|
||||||
|
// GroupBy(cpimage.FieldCreateTime).
|
||||||
|
// Aggregate(ent.Count()).
|
||||||
|
// Scan(ctx, &v)
|
||||||
|
func (ciq *CpImageQuery) GroupBy(field string, fields ...string) *CpImageGroupBy {
|
||||||
|
ciq.ctx.Fields = append([]string{field}, fields...)
|
||||||
|
grbuild := &CpImageGroupBy{build: ciq}
|
||||||
|
grbuild.flds = &ciq.ctx.Fields
|
||||||
|
grbuild.label = cpimage.Label
|
||||||
|
grbuild.scan = grbuild.Scan
|
||||||
|
return grbuild
|
||||||
|
}
|
||||||
|
|
||||||
|
// Select allows the selection one or more fields/columns for the given query,
|
||||||
|
// instead of selecting all fields in the entity.
|
||||||
|
//
|
||||||
|
// Example:
|
||||||
|
//
|
||||||
|
// var v []struct {
|
||||||
|
// CreateTime ent2.CustomTime `json:"createTime"`
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// client.CpImage.Query().
|
||||||
|
// Select(cpimage.FieldCreateTime).
|
||||||
|
// Scan(ctx, &v)
|
||||||
|
func (ciq *CpImageQuery) Select(fields ...string) *CpImageSelect {
|
||||||
|
ciq.ctx.Fields = append(ciq.ctx.Fields, fields...)
|
||||||
|
sbuild := &CpImageSelect{CpImageQuery: ciq}
|
||||||
|
sbuild.label = cpimage.Label
|
||||||
|
sbuild.flds, sbuild.scan = &ciq.ctx.Fields, sbuild.Scan
|
||||||
|
return sbuild
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggregate returns a CpImageSelect configured with the given aggregations.
|
||||||
|
func (ciq *CpImageQuery) Aggregate(fns ...AggregateFunc) *CpImageSelect {
|
||||||
|
return ciq.Select().Aggregate(fns...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ciq *CpImageQuery) prepareQuery(ctx context.Context) error {
|
||||||
|
for _, inter := range ciq.inters {
|
||||||
|
if inter == nil {
|
||||||
|
return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
|
||||||
|
}
|
||||||
|
if trv, ok := inter.(Traverser); ok {
|
||||||
|
if err := trv.Traverse(ctx, ciq); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, f := range ciq.ctx.Fields {
|
||||||
|
if !cpimage.ValidColumn(f) {
|
||||||
|
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ciq.path != nil {
|
||||||
|
prev, err := ciq.path(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
ciq.sql = prev
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ciq *CpImageQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*CpImage, error) {
|
||||||
|
var (
|
||||||
|
nodes = []*CpImage{}
|
||||||
|
_spec = ciq.querySpec()
|
||||||
|
loadedTypes = [1]bool{
|
||||||
|
ciq.withUser != nil,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||||
|
return (*CpImage).scanValues(nil, columns)
|
||||||
|
}
|
||||||
|
_spec.Assign = func(columns []string, values []any) error {
|
||||||
|
node := &CpImage{config: ciq.config}
|
||||||
|
nodes = append(nodes, node)
|
||||||
|
node.Edges.loadedTypes = loadedTypes
|
||||||
|
return node.assignValues(columns, values)
|
||||||
|
}
|
||||||
|
for i := range hooks {
|
||||||
|
hooks[i](ctx, _spec)
|
||||||
|
}
|
||||||
|
if err := sqlgraph.QueryNodes(ctx, ciq.driver, _spec); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(nodes) == 0 {
|
||||||
|
return nodes, nil
|
||||||
|
}
|
||||||
|
if query := ciq.withUser; query != nil {
|
||||||
|
if err := ciq.loadUser(ctx, query, nodes, nil,
|
||||||
|
func(n *CpImage, e *SysUser) { n.Edges.User = e }); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nodes, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ciq *CpImageQuery) loadUser(ctx context.Context, query *SysUserQuery, nodes []*CpImage, init func(*CpImage), assign func(*CpImage, *SysUser)) error {
|
||||||
|
ids := make([]int64, 0, len(nodes))
|
||||||
|
nodeids := make(map[int64][]*CpImage)
|
||||||
|
for i := range nodes {
|
||||||
|
fk := nodes[i].UserID
|
||||||
|
if _, ok := nodeids[fk]; !ok {
|
||||||
|
ids = append(ids, fk)
|
||||||
|
}
|
||||||
|
nodeids[fk] = append(nodeids[fk], nodes[i])
|
||||||
|
}
|
||||||
|
if len(ids) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
query.Where(sysuser.IDIn(ids...))
|
||||||
|
neighbors, err := query.All(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, n := range neighbors {
|
||||||
|
nodes, ok := nodeids[n.ID]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf(`unexpected foreign-key "user_id" returned %v`, n.ID)
|
||||||
|
}
|
||||||
|
for i := range nodes {
|
||||||
|
assign(nodes[i], n)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ciq *CpImageQuery) sqlCount(ctx context.Context) (int, error) {
|
||||||
|
_spec := ciq.querySpec()
|
||||||
|
_spec.Node.Columns = ciq.ctx.Fields
|
||||||
|
if len(ciq.ctx.Fields) > 0 {
|
||||||
|
_spec.Unique = ciq.ctx.Unique != nil && *ciq.ctx.Unique
|
||||||
|
}
|
||||||
|
return sqlgraph.CountNodes(ctx, ciq.driver, _spec)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ciq *CpImageQuery) querySpec() *sqlgraph.QuerySpec {
|
||||||
|
_spec := sqlgraph.NewQuerySpec(cpimage.Table, cpimage.Columns, sqlgraph.NewFieldSpec(cpimage.FieldID, field.TypeInt64))
|
||||||
|
_spec.From = ciq.sql
|
||||||
|
if unique := ciq.ctx.Unique; unique != nil {
|
||||||
|
_spec.Unique = *unique
|
||||||
|
} else if ciq.path != nil {
|
||||||
|
_spec.Unique = true
|
||||||
|
}
|
||||||
|
if fields := ciq.ctx.Fields; len(fields) > 0 {
|
||||||
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, cpimage.FieldID)
|
||||||
|
for i := range fields {
|
||||||
|
if fields[i] != cpimage.FieldID {
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ciq.withUser != nil {
|
||||||
|
_spec.Node.AddColumnOnce(cpimage.FieldUserID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ps := ciq.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if limit := ciq.ctx.Limit; limit != nil {
|
||||||
|
_spec.Limit = *limit
|
||||||
|
}
|
||||||
|
if offset := ciq.ctx.Offset; offset != nil {
|
||||||
|
_spec.Offset = *offset
|
||||||
|
}
|
||||||
|
if ps := ciq.order; len(ps) > 0 {
|
||||||
|
_spec.Order = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return _spec
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ciq *CpImageQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||||
|
builder := sql.Dialect(ciq.driver.Dialect())
|
||||||
|
t1 := builder.Table(cpimage.Table)
|
||||||
|
columns := ciq.ctx.Fields
|
||||||
|
if len(columns) == 0 {
|
||||||
|
columns = cpimage.Columns
|
||||||
|
}
|
||||||
|
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
||||||
|
if ciq.sql != nil {
|
||||||
|
selector = ciq.sql
|
||||||
|
selector.Select(selector.Columns(columns...)...)
|
||||||
|
}
|
||||||
|
if ciq.ctx.Unique != nil && *ciq.ctx.Unique {
|
||||||
|
selector.Distinct()
|
||||||
|
}
|
||||||
|
for _, p := range ciq.predicates {
|
||||||
|
p(selector)
|
||||||
|
}
|
||||||
|
for _, p := range ciq.order {
|
||||||
|
p(selector)
|
||||||
|
}
|
||||||
|
if offset := ciq.ctx.Offset; offset != nil {
|
||||||
|
// limit is mandatory for offset clause. We start
|
||||||
|
// with default value, and override it below if needed.
|
||||||
|
selector.Offset(*offset).Limit(math.MaxInt32)
|
||||||
|
}
|
||||||
|
if limit := ciq.ctx.Limit; limit != nil {
|
||||||
|
selector.Limit(*limit)
|
||||||
|
}
|
||||||
|
return selector
|
||||||
|
}
|
||||||
|
|
||||||
|
// CpImageGroupBy is the group-by builder for CpImage entities.
|
||||||
|
type CpImageGroupBy struct {
|
||||||
|
selector
|
||||||
|
build *CpImageQuery
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggregate adds the given aggregation functions to the group-by query.
|
||||||
|
func (cigb *CpImageGroupBy) Aggregate(fns ...AggregateFunc) *CpImageGroupBy {
|
||||||
|
cigb.fns = append(cigb.fns, fns...)
|
||||||
|
return cigb
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scan applies the selector query and scans the result into the given value.
|
||||||
|
func (cigb *CpImageGroupBy) Scan(ctx context.Context, v any) error {
|
||||||
|
ctx = setContextOp(ctx, cigb.build.ctx, ent.OpQueryGroupBy)
|
||||||
|
if err := cigb.build.prepareQuery(ctx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return scanWithInterceptors[*CpImageQuery, *CpImageGroupBy](ctx, cigb.build, cigb, cigb.build.inters, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cigb *CpImageGroupBy) sqlScan(ctx context.Context, root *CpImageQuery, v any) error {
|
||||||
|
selector := root.sqlQuery(ctx).Select()
|
||||||
|
aggregation := make([]string, 0, len(cigb.fns))
|
||||||
|
for _, fn := range cigb.fns {
|
||||||
|
aggregation = append(aggregation, fn(selector))
|
||||||
|
}
|
||||||
|
if len(selector.SelectedColumns()) == 0 {
|
||||||
|
columns := make([]string, 0, len(*cigb.flds)+len(cigb.fns))
|
||||||
|
for _, f := range *cigb.flds {
|
||||||
|
columns = append(columns, selector.C(f))
|
||||||
|
}
|
||||||
|
columns = append(columns, aggregation...)
|
||||||
|
selector.Select(columns...)
|
||||||
|
}
|
||||||
|
selector.GroupBy(selector.Columns(*cigb.flds...)...)
|
||||||
|
if err := selector.Err(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
rows := &sql.Rows{}
|
||||||
|
query, args := selector.Query()
|
||||||
|
if err := cigb.build.driver.Query(ctx, query, args, rows); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
return sql.ScanSlice(rows, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CpImageSelect is the builder for selecting fields of CpImage entities.
|
||||||
|
type CpImageSelect struct {
|
||||||
|
*CpImageQuery
|
||||||
|
selector
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggregate adds the given aggregation functions to the selector query.
|
||||||
|
func (cis *CpImageSelect) Aggregate(fns ...AggregateFunc) *CpImageSelect {
|
||||||
|
cis.fns = append(cis.fns, fns...)
|
||||||
|
return cis
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scan applies the selector query and scans the result into the given value.
|
||||||
|
func (cis *CpImageSelect) Scan(ctx context.Context, v any) error {
|
||||||
|
ctx = setContextOp(ctx, cis.ctx, ent.OpQuerySelect)
|
||||||
|
if err := cis.prepareQuery(ctx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return scanWithInterceptors[*CpImageQuery, *CpImageSelect](ctx, cis.CpImageQuery, cis, cis.inters, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cis *CpImageSelect) sqlScan(ctx context.Context, root *CpImageQuery, v any) error {
|
||||||
|
selector := root.sqlQuery(ctx)
|
||||||
|
aggregation := make([]string, 0, len(cis.fns))
|
||||||
|
for _, fn := range cis.fns {
|
||||||
|
aggregation = append(aggregation, fn(selector))
|
||||||
|
}
|
||||||
|
switch n := len(*cis.selector.flds); {
|
||||||
|
case n == 0 && len(aggregation) > 0:
|
||||||
|
selector.Select(aggregation...)
|
||||||
|
case n != 0 && len(aggregation) > 0:
|
||||||
|
selector.AppendSelect(aggregation...)
|
||||||
|
}
|
||||||
|
rows := &sql.Rows{}
|
||||||
|
query, args := selector.Query()
|
||||||
|
if err := cis.driver.Query(ctx, query, args, rows); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
return sql.ScanSlice(rows, v)
|
||||||
|
}
|
||||||
@@ -0,0 +1,503 @@
|
|||||||
|
// ENT数据库文件,请勿编辑。
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"likedream-goframe/internal/ent/cpimage"
|
||||||
|
"likedream-goframe/internal/ent/predicate"
|
||||||
|
"likedream-goframe/internal/ent/sysuser"
|
||||||
|
"likedream-goframe/internal/framework/ent2"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
)
|
||||||
|
|
||||||
|
// CpImageUpdate is the builder for updating CpImage entities.
|
||||||
|
type CpImageUpdate struct {
|
||||||
|
config
|
||||||
|
hooks []Hook
|
||||||
|
mutation *CpImageMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the CpImageUpdate builder.
|
||||||
|
func (ciu *CpImageUpdate) Where(ps ...predicate.CpImage) *CpImageUpdate {
|
||||||
|
ciu.mutation.Where(ps...)
|
||||||
|
return ciu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUpdateTime sets the "update_time" field.
|
||||||
|
func (ciu *CpImageUpdate) SetUpdateTime(et ent2.CustomTime) *CpImageUpdate {
|
||||||
|
ciu.mutation.SetUpdateTime(et)
|
||||||
|
return ciu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableUpdateTime sets the "update_time" field if the given value is not nil.
|
||||||
|
func (ciu *CpImageUpdate) SetNillableUpdateTime(et *ent2.CustomTime) *CpImageUpdate {
|
||||||
|
if et != nil {
|
||||||
|
ciu.SetUpdateTime(*et)
|
||||||
|
}
|
||||||
|
return ciu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetKey sets the "key" field.
|
||||||
|
func (ciu *CpImageUpdate) SetKey(s string) *CpImageUpdate {
|
||||||
|
ciu.mutation.SetKey(s)
|
||||||
|
return ciu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableKey sets the "key" field if the given value is not nil.
|
||||||
|
func (ciu *CpImageUpdate) SetNillableKey(s *string) *CpImageUpdate {
|
||||||
|
if s != nil {
|
||||||
|
ciu.SetKey(*s)
|
||||||
|
}
|
||||||
|
return ciu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUserID sets the "user_id" field.
|
||||||
|
func (ciu *CpImageUpdate) SetUserID(i int64) *CpImageUpdate {
|
||||||
|
ciu.mutation.SetUserID(i)
|
||||||
|
return ciu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableUserID sets the "user_id" field if the given value is not nil.
|
||||||
|
func (ciu *CpImageUpdate) SetNillableUserID(i *int64) *CpImageUpdate {
|
||||||
|
if i != nil {
|
||||||
|
ciu.SetUserID(*i)
|
||||||
|
}
|
||||||
|
return ciu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetContentType sets the "content_type" field.
|
||||||
|
func (ciu *CpImageUpdate) SetContentType(s string) *CpImageUpdate {
|
||||||
|
ciu.mutation.SetContentType(s)
|
||||||
|
return ciu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableContentType sets the "content_type" field if the given value is not nil.
|
||||||
|
func (ciu *CpImageUpdate) SetNillableContentType(s *string) *CpImageUpdate {
|
||||||
|
if s != nil {
|
||||||
|
ciu.SetContentType(*s)
|
||||||
|
}
|
||||||
|
return ciu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetContentLength sets the "content_length" field.
|
||||||
|
func (ciu *CpImageUpdate) SetContentLength(i int64) *CpImageUpdate {
|
||||||
|
ciu.mutation.ResetContentLength()
|
||||||
|
ciu.mutation.SetContentLength(i)
|
||||||
|
return ciu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableContentLength sets the "content_length" field if the given value is not nil.
|
||||||
|
func (ciu *CpImageUpdate) SetNillableContentLength(i *int64) *CpImageUpdate {
|
||||||
|
if i != nil {
|
||||||
|
ciu.SetContentLength(*i)
|
||||||
|
}
|
||||||
|
return ciu
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddContentLength adds i to the "content_length" field.
|
||||||
|
func (ciu *CpImageUpdate) AddContentLength(i int64) *CpImageUpdate {
|
||||||
|
ciu.mutation.AddContentLength(i)
|
||||||
|
return ciu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUser sets the "user" edge to the SysUser entity.
|
||||||
|
func (ciu *CpImageUpdate) SetUser(s *SysUser) *CpImageUpdate {
|
||||||
|
return ciu.SetUserID(s.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the CpImageMutation object of the builder.
|
||||||
|
func (ciu *CpImageUpdate) Mutation() *CpImageMutation {
|
||||||
|
return ciu.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearUser clears the "user" edge to the SysUser entity.
|
||||||
|
func (ciu *CpImageUpdate) ClearUser() *CpImageUpdate {
|
||||||
|
ciu.mutation.ClearUser()
|
||||||
|
return ciu
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||||
|
func (ciu *CpImageUpdate) Save(ctx context.Context) (int, error) {
|
||||||
|
return withHooks(ctx, ciu.sqlSave, ciu.mutation, ciu.hooks)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX is like Save, but panics if an error occurs.
|
||||||
|
func (ciu *CpImageUpdate) SaveX(ctx context.Context) int {
|
||||||
|
affected, err := ciu.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return affected
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (ciu *CpImageUpdate) Exec(ctx context.Context) error {
|
||||||
|
_, err := ciu.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (ciu *CpImageUpdate) ExecX(ctx context.Context) {
|
||||||
|
if err := ciu.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check runs all checks and user-defined validators on the builder.
|
||||||
|
func (ciu *CpImageUpdate) check() error {
|
||||||
|
if v, ok := ciu.mutation.Key(); ok {
|
||||||
|
if err := cpimage.KeyValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "key", err: fmt.Errorf(`ent: validator failed for field "CpImage.key": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if v, ok := ciu.mutation.UserID(); ok {
|
||||||
|
if err := cpimage.UserIDValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "user_id", err: fmt.Errorf(`ent: validator failed for field "CpImage.user_id": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if v, ok := ciu.mutation.ContentType(); ok {
|
||||||
|
if err := cpimage.ContentTypeValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "content_type", err: fmt.Errorf(`ent: validator failed for field "CpImage.content_type": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if v, ok := ciu.mutation.ContentLength(); ok {
|
||||||
|
if err := cpimage.ContentLengthValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "content_length", err: fmt.Errorf(`ent: validator failed for field "CpImage.content_length": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ciu.mutation.UserCleared() && len(ciu.mutation.UserIDs()) > 0 {
|
||||||
|
return errors.New(`ent: clearing a required unique edge "CpImage.user"`)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ciu *CpImageUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||||
|
if err := ciu.check(); err != nil {
|
||||||
|
return n, err
|
||||||
|
}
|
||||||
|
_spec := sqlgraph.NewUpdateSpec(cpimage.Table, cpimage.Columns, sqlgraph.NewFieldSpec(cpimage.FieldID, field.TypeInt64))
|
||||||
|
if ps := ciu.mutation.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if value, ok := ciu.mutation.UpdateTime(); ok {
|
||||||
|
_spec.SetField(cpimage.FieldUpdateTime, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := ciu.mutation.Key(); ok {
|
||||||
|
_spec.SetField(cpimage.FieldKey, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := ciu.mutation.ContentType(); ok {
|
||||||
|
_spec.SetField(cpimage.FieldContentType, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := ciu.mutation.ContentLength(); ok {
|
||||||
|
_spec.SetField(cpimage.FieldContentLength, field.TypeInt64, value)
|
||||||
|
}
|
||||||
|
if value, ok := ciu.mutation.AddedContentLength(); ok {
|
||||||
|
_spec.AddField(cpimage.FieldContentLength, field.TypeInt64, value)
|
||||||
|
}
|
||||||
|
if ciu.mutation.UserCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: cpimage.UserTable,
|
||||||
|
Columns: []string{cpimage.UserColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(sysuser.FieldID, field.TypeInt64),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := ciu.mutation.UserIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: cpimage.UserTable,
|
||||||
|
Columns: []string{cpimage.UserColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(sysuser.FieldID, field.TypeInt64),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||||
|
}
|
||||||
|
if n, err = sqlgraph.UpdateNodes(ctx, ciu.driver, _spec); err != nil {
|
||||||
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||||
|
err = &NotFoundError{cpimage.Label}
|
||||||
|
} else if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
ciu.mutation.done = true
|
||||||
|
return n, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// CpImageUpdateOne is the builder for updating a single CpImage entity.
|
||||||
|
type CpImageUpdateOne struct {
|
||||||
|
config
|
||||||
|
fields []string
|
||||||
|
hooks []Hook
|
||||||
|
mutation *CpImageMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUpdateTime sets the "update_time" field.
|
||||||
|
func (ciuo *CpImageUpdateOne) SetUpdateTime(et ent2.CustomTime) *CpImageUpdateOne {
|
||||||
|
ciuo.mutation.SetUpdateTime(et)
|
||||||
|
return ciuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableUpdateTime sets the "update_time" field if the given value is not nil.
|
||||||
|
func (ciuo *CpImageUpdateOne) SetNillableUpdateTime(et *ent2.CustomTime) *CpImageUpdateOne {
|
||||||
|
if et != nil {
|
||||||
|
ciuo.SetUpdateTime(*et)
|
||||||
|
}
|
||||||
|
return ciuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetKey sets the "key" field.
|
||||||
|
func (ciuo *CpImageUpdateOne) SetKey(s string) *CpImageUpdateOne {
|
||||||
|
ciuo.mutation.SetKey(s)
|
||||||
|
return ciuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableKey sets the "key" field if the given value is not nil.
|
||||||
|
func (ciuo *CpImageUpdateOne) SetNillableKey(s *string) *CpImageUpdateOne {
|
||||||
|
if s != nil {
|
||||||
|
ciuo.SetKey(*s)
|
||||||
|
}
|
||||||
|
return ciuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUserID sets the "user_id" field.
|
||||||
|
func (ciuo *CpImageUpdateOne) SetUserID(i int64) *CpImageUpdateOne {
|
||||||
|
ciuo.mutation.SetUserID(i)
|
||||||
|
return ciuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableUserID sets the "user_id" field if the given value is not nil.
|
||||||
|
func (ciuo *CpImageUpdateOne) SetNillableUserID(i *int64) *CpImageUpdateOne {
|
||||||
|
if i != nil {
|
||||||
|
ciuo.SetUserID(*i)
|
||||||
|
}
|
||||||
|
return ciuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetContentType sets the "content_type" field.
|
||||||
|
func (ciuo *CpImageUpdateOne) SetContentType(s string) *CpImageUpdateOne {
|
||||||
|
ciuo.mutation.SetContentType(s)
|
||||||
|
return ciuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableContentType sets the "content_type" field if the given value is not nil.
|
||||||
|
func (ciuo *CpImageUpdateOne) SetNillableContentType(s *string) *CpImageUpdateOne {
|
||||||
|
if s != nil {
|
||||||
|
ciuo.SetContentType(*s)
|
||||||
|
}
|
||||||
|
return ciuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetContentLength sets the "content_length" field.
|
||||||
|
func (ciuo *CpImageUpdateOne) SetContentLength(i int64) *CpImageUpdateOne {
|
||||||
|
ciuo.mutation.ResetContentLength()
|
||||||
|
ciuo.mutation.SetContentLength(i)
|
||||||
|
return ciuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableContentLength sets the "content_length" field if the given value is not nil.
|
||||||
|
func (ciuo *CpImageUpdateOne) SetNillableContentLength(i *int64) *CpImageUpdateOne {
|
||||||
|
if i != nil {
|
||||||
|
ciuo.SetContentLength(*i)
|
||||||
|
}
|
||||||
|
return ciuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddContentLength adds i to the "content_length" field.
|
||||||
|
func (ciuo *CpImageUpdateOne) AddContentLength(i int64) *CpImageUpdateOne {
|
||||||
|
ciuo.mutation.AddContentLength(i)
|
||||||
|
return ciuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUser sets the "user" edge to the SysUser entity.
|
||||||
|
func (ciuo *CpImageUpdateOne) SetUser(s *SysUser) *CpImageUpdateOne {
|
||||||
|
return ciuo.SetUserID(s.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the CpImageMutation object of the builder.
|
||||||
|
func (ciuo *CpImageUpdateOne) Mutation() *CpImageMutation {
|
||||||
|
return ciuo.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearUser clears the "user" edge to the SysUser entity.
|
||||||
|
func (ciuo *CpImageUpdateOne) ClearUser() *CpImageUpdateOne {
|
||||||
|
ciuo.mutation.ClearUser()
|
||||||
|
return ciuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the CpImageUpdate builder.
|
||||||
|
func (ciuo *CpImageUpdateOne) Where(ps ...predicate.CpImage) *CpImageUpdateOne {
|
||||||
|
ciuo.mutation.Where(ps...)
|
||||||
|
return ciuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// Select allows selecting one or more fields (columns) of the returned entity.
|
||||||
|
// The default is selecting all fields defined in the entity schema.
|
||||||
|
func (ciuo *CpImageUpdateOne) Select(field string, fields ...string) *CpImageUpdateOne {
|
||||||
|
ciuo.fields = append([]string{field}, fields...)
|
||||||
|
return ciuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save executes the query and returns the updated CpImage entity.
|
||||||
|
func (ciuo *CpImageUpdateOne) Save(ctx context.Context) (*CpImage, error) {
|
||||||
|
return withHooks(ctx, ciuo.sqlSave, ciuo.mutation, ciuo.hooks)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX is like Save, but panics if an error occurs.
|
||||||
|
func (ciuo *CpImageUpdateOne) SaveX(ctx context.Context) *CpImage {
|
||||||
|
node, err := ciuo.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query on the entity.
|
||||||
|
func (ciuo *CpImageUpdateOne) Exec(ctx context.Context) error {
|
||||||
|
_, err := ciuo.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (ciuo *CpImageUpdateOne) ExecX(ctx context.Context) {
|
||||||
|
if err := ciuo.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check runs all checks and user-defined validators on the builder.
|
||||||
|
func (ciuo *CpImageUpdateOne) check() error {
|
||||||
|
if v, ok := ciuo.mutation.Key(); ok {
|
||||||
|
if err := cpimage.KeyValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "key", err: fmt.Errorf(`ent: validator failed for field "CpImage.key": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if v, ok := ciuo.mutation.UserID(); ok {
|
||||||
|
if err := cpimage.UserIDValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "user_id", err: fmt.Errorf(`ent: validator failed for field "CpImage.user_id": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if v, ok := ciuo.mutation.ContentType(); ok {
|
||||||
|
if err := cpimage.ContentTypeValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "content_type", err: fmt.Errorf(`ent: validator failed for field "CpImage.content_type": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if v, ok := ciuo.mutation.ContentLength(); ok {
|
||||||
|
if err := cpimage.ContentLengthValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "content_length", err: fmt.Errorf(`ent: validator failed for field "CpImage.content_length": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ciuo.mutation.UserCleared() && len(ciuo.mutation.UserIDs()) > 0 {
|
||||||
|
return errors.New(`ent: clearing a required unique edge "CpImage.user"`)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ciuo *CpImageUpdateOne) sqlSave(ctx context.Context) (_node *CpImage, err error) {
|
||||||
|
if err := ciuo.check(); err != nil {
|
||||||
|
return _node, err
|
||||||
|
}
|
||||||
|
_spec := sqlgraph.NewUpdateSpec(cpimage.Table, cpimage.Columns, sqlgraph.NewFieldSpec(cpimage.FieldID, field.TypeInt64))
|
||||||
|
id, ok := ciuo.mutation.ID()
|
||||||
|
if !ok {
|
||||||
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "CpImage.id" for update`)}
|
||||||
|
}
|
||||||
|
_spec.Node.ID.Value = id
|
||||||
|
if fields := ciuo.fields; len(fields) > 0 {
|
||||||
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, cpimage.FieldID)
|
||||||
|
for _, f := range fields {
|
||||||
|
if !cpimage.ValidColumn(f) {
|
||||||
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||||
|
}
|
||||||
|
if f != cpimage.FieldID {
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ps := ciuo.mutation.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if value, ok := ciuo.mutation.UpdateTime(); ok {
|
||||||
|
_spec.SetField(cpimage.FieldUpdateTime, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := ciuo.mutation.Key(); ok {
|
||||||
|
_spec.SetField(cpimage.FieldKey, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := ciuo.mutation.ContentType(); ok {
|
||||||
|
_spec.SetField(cpimage.FieldContentType, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := ciuo.mutation.ContentLength(); ok {
|
||||||
|
_spec.SetField(cpimage.FieldContentLength, field.TypeInt64, value)
|
||||||
|
}
|
||||||
|
if value, ok := ciuo.mutation.AddedContentLength(); ok {
|
||||||
|
_spec.AddField(cpimage.FieldContentLength, field.TypeInt64, value)
|
||||||
|
}
|
||||||
|
if ciuo.mutation.UserCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: cpimage.UserTable,
|
||||||
|
Columns: []string{cpimage.UserColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(sysuser.FieldID, field.TypeInt64),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := ciuo.mutation.UserIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: cpimage.UserTable,
|
||||||
|
Columns: []string{cpimage.UserColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(sysuser.FieldID, field.TypeInt64),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||||
|
}
|
||||||
|
_node = &CpImage{config: ciuo.config}
|
||||||
|
_spec.Assign = _node.assignValues
|
||||||
|
_spec.ScanValues = _node.scanValues
|
||||||
|
if err = sqlgraph.UpdateNode(ctx, ciuo.driver, _spec); err != nil {
|
||||||
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||||
|
err = &NotFoundError{cpimage.Label}
|
||||||
|
} else if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
ciuo.mutation.done = true
|
||||||
|
return _node, nil
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"likedream-goframe/internal/ent/cpimage"
|
||||||
"likedream-goframe/internal/ent/sysagent"
|
"likedream-goframe/internal/ent/sysagent"
|
||||||
"likedream-goframe/internal/ent/sysmenu"
|
"likedream-goframe/internal/ent/sysmenu"
|
||||||
"likedream-goframe/internal/ent/sysrole"
|
"likedream-goframe/internal/ent/sysrole"
|
||||||
@@ -77,6 +78,7 @@ var (
|
|||||||
func checkColumn(table, column string) error {
|
func checkColumn(table, column string) error {
|
||||||
initCheck.Do(func() {
|
initCheck.Do(func() {
|
||||||
columnCheck = sql.NewColumnCheck(map[string]func(string) bool{
|
columnCheck = sql.NewColumnCheck(map[string]func(string) bool{
|
||||||
|
cpimage.Table: cpimage.ValidColumn,
|
||||||
sysagent.Table: sysagent.ValidColumn,
|
sysagent.Table: sysagent.ValidColumn,
|
||||||
sysmenu.Table: sysmenu.ValidColumn,
|
sysmenu.Table: sysmenu.ValidColumn,
|
||||||
sysrole.Table: sysrole.ValidColumn,
|
sysrole.Table: sysrole.ValidColumn,
|
||||||
|
|||||||
@@ -8,6 +8,18 @@ import (
|
|||||||
"likedream-goframe/internal/ent"
|
"likedream-goframe/internal/ent"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// The CpImageFunc type is an adapter to allow the use of ordinary
|
||||||
|
// function as CpImage mutator.
|
||||||
|
type CpImageFunc func(context.Context, *ent.CpImageMutation) (ent.Value, error)
|
||||||
|
|
||||||
|
// Mutate calls f(ctx, m).
|
||||||
|
func (f CpImageFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||||
|
if mv, ok := m.(*ent.CpImageMutation); ok {
|
||||||
|
return f(ctx, mv)
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.CpImageMutation", m)
|
||||||
|
}
|
||||||
|
|
||||||
// The SysAgentFunc type is an adapter to allow the use of ordinary
|
// The SysAgentFunc type is an adapter to allow the use of ordinary
|
||||||
// function as SysAgent mutator.
|
// function as SysAgent mutator.
|
||||||
type SysAgentFunc func(context.Context, *ent.SysAgentMutation) (ent.Value, error)
|
type SysAgentFunc func(context.Context, *ent.SysAgentMutation) (ent.Value, error)
|
||||||
|
|||||||
@@ -9,6 +9,31 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
// CpImageColumns holds the columns for the "cp_image" table.
|
||||||
|
CpImageColumns = []*schema.Column{
|
||||||
|
{Name: "id", Type: field.TypeInt64, Increment: true},
|
||||||
|
{Name: "create_time", Type: field.TypeString, SchemaType: map[string]string{"mysql": "datetime", "postgres": "timestamp", "sqlite3": "datetime"}},
|
||||||
|
{Name: "update_time", Type: field.TypeString, SchemaType: map[string]string{"mysql": "datetime", "postgres": "timestamp", "sqlite3": "datetime"}},
|
||||||
|
{Name: "image_id", Type: field.TypeUUID, Unique: true},
|
||||||
|
{Name: "key", Type: field.TypeString},
|
||||||
|
{Name: "content_type", Type: field.TypeString},
|
||||||
|
{Name: "content_length", Type: field.TypeInt64},
|
||||||
|
{Name: "user_id", Type: field.TypeInt64},
|
||||||
|
}
|
||||||
|
// CpImageTable holds the schema information for the "cp_image" table.
|
||||||
|
CpImageTable = &schema.Table{
|
||||||
|
Name: "cp_image",
|
||||||
|
Columns: CpImageColumns,
|
||||||
|
PrimaryKey: []*schema.Column{CpImageColumns[0]},
|
||||||
|
ForeignKeys: []*schema.ForeignKey{
|
||||||
|
{
|
||||||
|
Symbol: "cp_image_sys_user_images",
|
||||||
|
Columns: []*schema.Column{CpImageColumns[7]},
|
||||||
|
RefColumns: []*schema.Column{SysUserColumns[0]},
|
||||||
|
OnDelete: schema.NoAction,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
// SysAgentColumns holds the columns for the "sys_agent" table.
|
// SysAgentColumns holds the columns for the "sys_agent" table.
|
||||||
SysAgentColumns = []*schema.Column{
|
SysAgentColumns = []*schema.Column{
|
||||||
{Name: "id", Type: field.TypeInt64, Increment: true},
|
{Name: "id", Type: field.TypeInt64, Increment: true},
|
||||||
@@ -169,6 +194,7 @@ var (
|
|||||||
}
|
}
|
||||||
// Tables holds all the tables in the schema.
|
// Tables holds all the tables in the schema.
|
||||||
Tables = []*schema.Table{
|
Tables = []*schema.Table{
|
||||||
|
CpImageTable,
|
||||||
SysAgentTable,
|
SysAgentTable,
|
||||||
SysMenuTable,
|
SysMenuTable,
|
||||||
SysRoleTable,
|
SysRoleTable,
|
||||||
@@ -180,6 +206,10 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
CpImageTable.ForeignKeys[0].RefTable = SysUserTable
|
||||||
|
CpImageTable.Annotation = &entsql.Annotation{
|
||||||
|
Table: "cp_image",
|
||||||
|
}
|
||||||
SysAgentTable.ForeignKeys[0].RefTable = SysUserTable
|
SysAgentTable.ForeignKeys[0].RefTable = SysUserTable
|
||||||
SysAgentTable.Annotation = &entsql.Annotation{
|
SysAgentTable.Annotation = &entsql.Annotation{
|
||||||
Table: "sys_agent",
|
Table: "sys_agent",
|
||||||
|
|||||||
+829
-3
@@ -6,6 +6,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"likedream-goframe/internal/ent/cpimage"
|
||||||
"likedream-goframe/internal/ent/predicate"
|
"likedream-goframe/internal/ent/predicate"
|
||||||
"likedream-goframe/internal/ent/sysagent"
|
"likedream-goframe/internal/ent/sysagent"
|
||||||
"likedream-goframe/internal/ent/sysmenu"
|
"likedream-goframe/internal/ent/sysmenu"
|
||||||
@@ -16,6 +17,7 @@ import (
|
|||||||
|
|
||||||
"entgo.io/ent"
|
"entgo.io/ent"
|
||||||
"entgo.io/ent/dialect/sql"
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"github.com/google/uuid"
|
||||||
"github.com/shopspring/decimal"
|
"github.com/shopspring/decimal"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -28,6 +30,7 @@ const (
|
|||||||
OpUpdateOne = ent.OpUpdateOne
|
OpUpdateOne = ent.OpUpdateOne
|
||||||
|
|
||||||
// Node types.
|
// Node types.
|
||||||
|
TypeCpImage = "CpImage"
|
||||||
TypeSysAgent = "SysAgent"
|
TypeSysAgent = "SysAgent"
|
||||||
TypeSysMenu = "SysMenu"
|
TypeSysMenu = "SysMenu"
|
||||||
TypeSysRole = "SysRole"
|
TypeSysRole = "SysRole"
|
||||||
@@ -35,6 +38,746 @@ const (
|
|||||||
TypeSysUserLog = "SysUserLog"
|
TypeSysUserLog = "SysUserLog"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// CpImageMutation represents an operation that mutates the CpImage nodes in the graph.
|
||||||
|
type CpImageMutation struct {
|
||||||
|
config
|
||||||
|
op Op
|
||||||
|
typ string
|
||||||
|
id *int64
|
||||||
|
create_time *ent2.CustomTime
|
||||||
|
update_time *ent2.CustomTime
|
||||||
|
image_id *uuid.UUID
|
||||||
|
key *string
|
||||||
|
content_type *string
|
||||||
|
content_length *int64
|
||||||
|
addcontent_length *int64
|
||||||
|
clearedFields map[string]struct{}
|
||||||
|
user *int64
|
||||||
|
cleareduser bool
|
||||||
|
done bool
|
||||||
|
oldValue func(context.Context) (*CpImage, error)
|
||||||
|
predicates []predicate.CpImage
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ ent.Mutation = (*CpImageMutation)(nil)
|
||||||
|
|
||||||
|
// cpimageOption allows management of the mutation configuration using functional options.
|
||||||
|
type cpimageOption func(*CpImageMutation)
|
||||||
|
|
||||||
|
// newCpImageMutation creates new mutation for the CpImage entity.
|
||||||
|
func newCpImageMutation(c config, op Op, opts ...cpimageOption) *CpImageMutation {
|
||||||
|
m := &CpImageMutation{
|
||||||
|
config: c,
|
||||||
|
op: op,
|
||||||
|
typ: TypeCpImage,
|
||||||
|
clearedFields: make(map[string]struct{}),
|
||||||
|
}
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt(m)
|
||||||
|
}
|
||||||
|
return m
|
||||||
|
}
|
||||||
|
|
||||||
|
// withCpImageID sets the ID field of the mutation.
|
||||||
|
func withCpImageID(id int64) cpimageOption {
|
||||||
|
return func(m *CpImageMutation) {
|
||||||
|
var (
|
||||||
|
err error
|
||||||
|
once sync.Once
|
||||||
|
value *CpImage
|
||||||
|
)
|
||||||
|
m.oldValue = func(ctx context.Context) (*CpImage, error) {
|
||||||
|
once.Do(func() {
|
||||||
|
if m.done {
|
||||||
|
err = errors.New("querying old values post mutation is not allowed")
|
||||||
|
} else {
|
||||||
|
value, err = m.Client().CpImage.Get(ctx, id)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return value, err
|
||||||
|
}
|
||||||
|
m.id = &id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// withCpImage sets the old CpImage of the mutation.
|
||||||
|
func withCpImage(node *CpImage) cpimageOption {
|
||||||
|
return func(m *CpImageMutation) {
|
||||||
|
m.oldValue = func(context.Context) (*CpImage, error) {
|
||||||
|
return node, nil
|
||||||
|
}
|
||||||
|
m.id = &node.ID
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Client returns a new `ent.Client` from the mutation. If the mutation was
|
||||||
|
// executed in a transaction (ent.Tx), a transactional client is returned.
|
||||||
|
func (m CpImageMutation) Client() *Client {
|
||||||
|
client := &Client{config: m.config}
|
||||||
|
client.init()
|
||||||
|
return client
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tx returns an `ent.Tx` for mutations that were executed in transactions;
|
||||||
|
// it returns an error otherwise.
|
||||||
|
func (m CpImageMutation) Tx() (*Tx, error) {
|
||||||
|
if _, ok := m.driver.(*txDriver); !ok {
|
||||||
|
return nil, errors.New("ent: mutation is not running in a transaction")
|
||||||
|
}
|
||||||
|
tx := &Tx{config: m.config}
|
||||||
|
tx.init()
|
||||||
|
return tx, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ID returns the ID value in the mutation. Note that the ID is only available
|
||||||
|
// if it was provided to the builder or after it was returned from the database.
|
||||||
|
func (m *CpImageMutation) ID() (id int64, exists bool) {
|
||||||
|
if m.id == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return *m.id, true
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDs queries the database and returns the entity ids that match the mutation's predicate.
|
||||||
|
// That means, if the mutation is applied within a transaction with an isolation level such
|
||||||
|
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
|
||||||
|
// or updated by the mutation.
|
||||||
|
func (m *CpImageMutation) IDs(ctx context.Context) ([]int64, error) {
|
||||||
|
switch {
|
||||||
|
case m.op.Is(OpUpdateOne | OpDeleteOne):
|
||||||
|
id, exists := m.ID()
|
||||||
|
if exists {
|
||||||
|
return []int64{id}, nil
|
||||||
|
}
|
||||||
|
fallthrough
|
||||||
|
case m.op.Is(OpUpdate | OpDelete):
|
||||||
|
return m.Client().CpImage.Query().Where(m.predicates...).IDs(ctx)
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCreateTime sets the "create_time" field.
|
||||||
|
func (m *CpImageMutation) SetCreateTime(et ent2.CustomTime) {
|
||||||
|
m.create_time = &et
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateTime returns the value of the "create_time" field in the mutation.
|
||||||
|
func (m *CpImageMutation) CreateTime() (r ent2.CustomTime, exists bool) {
|
||||||
|
v := m.create_time
|
||||||
|
if v == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return *v, true
|
||||||
|
}
|
||||||
|
|
||||||
|
// OldCreateTime returns the old "create_time" field's value of the CpImage entity.
|
||||||
|
// If the CpImage object wasn't provided to the builder, the object is fetched from the database.
|
||||||
|
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||||
|
func (m *CpImageMutation) OldCreateTime(ctx context.Context) (v ent2.CustomTime, err error) {
|
||||||
|
if !m.op.Is(OpUpdateOne) {
|
||||||
|
return v, errors.New("OldCreateTime is only allowed on UpdateOne operations")
|
||||||
|
}
|
||||||
|
if m.id == nil || m.oldValue == nil {
|
||||||
|
return v, errors.New("OldCreateTime requires an ID field in the mutation")
|
||||||
|
}
|
||||||
|
oldValue, err := m.oldValue(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return v, fmt.Errorf("querying old value for OldCreateTime: %w", err)
|
||||||
|
}
|
||||||
|
return oldValue.CreateTime, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ResetCreateTime resets all changes to the "create_time" field.
|
||||||
|
func (m *CpImageMutation) ResetCreateTime() {
|
||||||
|
m.create_time = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUpdateTime sets the "update_time" field.
|
||||||
|
func (m *CpImageMutation) SetUpdateTime(et ent2.CustomTime) {
|
||||||
|
m.update_time = &et
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateTime returns the value of the "update_time" field in the mutation.
|
||||||
|
func (m *CpImageMutation) UpdateTime() (r ent2.CustomTime, exists bool) {
|
||||||
|
v := m.update_time
|
||||||
|
if v == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return *v, true
|
||||||
|
}
|
||||||
|
|
||||||
|
// OldUpdateTime returns the old "update_time" field's value of the CpImage entity.
|
||||||
|
// If the CpImage object wasn't provided to the builder, the object is fetched from the database.
|
||||||
|
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||||
|
func (m *CpImageMutation) OldUpdateTime(ctx context.Context) (v ent2.CustomTime, err error) {
|
||||||
|
if !m.op.Is(OpUpdateOne) {
|
||||||
|
return v, errors.New("OldUpdateTime is only allowed on UpdateOne operations")
|
||||||
|
}
|
||||||
|
if m.id == nil || m.oldValue == nil {
|
||||||
|
return v, errors.New("OldUpdateTime requires an ID field in the mutation")
|
||||||
|
}
|
||||||
|
oldValue, err := m.oldValue(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return v, fmt.Errorf("querying old value for OldUpdateTime: %w", err)
|
||||||
|
}
|
||||||
|
return oldValue.UpdateTime, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ResetUpdateTime resets all changes to the "update_time" field.
|
||||||
|
func (m *CpImageMutation) ResetUpdateTime() {
|
||||||
|
m.update_time = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetImageID sets the "image_id" field.
|
||||||
|
func (m *CpImageMutation) SetImageID(u uuid.UUID) {
|
||||||
|
m.image_id = &u
|
||||||
|
}
|
||||||
|
|
||||||
|
// ImageID returns the value of the "image_id" field in the mutation.
|
||||||
|
func (m *CpImageMutation) ImageID() (r uuid.UUID, exists bool) {
|
||||||
|
v := m.image_id
|
||||||
|
if v == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return *v, true
|
||||||
|
}
|
||||||
|
|
||||||
|
// OldImageID returns the old "image_id" field's value of the CpImage entity.
|
||||||
|
// If the CpImage object wasn't provided to the builder, the object is fetched from the database.
|
||||||
|
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||||
|
func (m *CpImageMutation) OldImageID(ctx context.Context) (v uuid.UUID, err error) {
|
||||||
|
if !m.op.Is(OpUpdateOne) {
|
||||||
|
return v, errors.New("OldImageID is only allowed on UpdateOne operations")
|
||||||
|
}
|
||||||
|
if m.id == nil || m.oldValue == nil {
|
||||||
|
return v, errors.New("OldImageID requires an ID field in the mutation")
|
||||||
|
}
|
||||||
|
oldValue, err := m.oldValue(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return v, fmt.Errorf("querying old value for OldImageID: %w", err)
|
||||||
|
}
|
||||||
|
return oldValue.ImageID, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ResetImageID resets all changes to the "image_id" field.
|
||||||
|
func (m *CpImageMutation) ResetImageID() {
|
||||||
|
m.image_id = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetKey sets the "key" field.
|
||||||
|
func (m *CpImageMutation) SetKey(s string) {
|
||||||
|
m.key = &s
|
||||||
|
}
|
||||||
|
|
||||||
|
// Key returns the value of the "key" field in the mutation.
|
||||||
|
func (m *CpImageMutation) Key() (r string, exists bool) {
|
||||||
|
v := m.key
|
||||||
|
if v == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return *v, true
|
||||||
|
}
|
||||||
|
|
||||||
|
// OldKey returns the old "key" field's value of the CpImage entity.
|
||||||
|
// If the CpImage object wasn't provided to the builder, the object is fetched from the database.
|
||||||
|
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||||
|
func (m *CpImageMutation) OldKey(ctx context.Context) (v string, err error) {
|
||||||
|
if !m.op.Is(OpUpdateOne) {
|
||||||
|
return v, errors.New("OldKey is only allowed on UpdateOne operations")
|
||||||
|
}
|
||||||
|
if m.id == nil || m.oldValue == nil {
|
||||||
|
return v, errors.New("OldKey requires an ID field in the mutation")
|
||||||
|
}
|
||||||
|
oldValue, err := m.oldValue(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return v, fmt.Errorf("querying old value for OldKey: %w", err)
|
||||||
|
}
|
||||||
|
return oldValue.Key, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ResetKey resets all changes to the "key" field.
|
||||||
|
func (m *CpImageMutation) ResetKey() {
|
||||||
|
m.key = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUserID sets the "user_id" field.
|
||||||
|
func (m *CpImageMutation) SetUserID(i int64) {
|
||||||
|
m.user = &i
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserID returns the value of the "user_id" field in the mutation.
|
||||||
|
func (m *CpImageMutation) UserID() (r int64, exists bool) {
|
||||||
|
v := m.user
|
||||||
|
if v == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return *v, true
|
||||||
|
}
|
||||||
|
|
||||||
|
// OldUserID returns the old "user_id" field's value of the CpImage entity.
|
||||||
|
// If the CpImage object wasn't provided to the builder, the object is fetched from the database.
|
||||||
|
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||||
|
func (m *CpImageMutation) OldUserID(ctx context.Context) (v int64, err error) {
|
||||||
|
if !m.op.Is(OpUpdateOne) {
|
||||||
|
return v, errors.New("OldUserID is only allowed on UpdateOne operations")
|
||||||
|
}
|
||||||
|
if m.id == nil || m.oldValue == nil {
|
||||||
|
return v, errors.New("OldUserID requires an ID field in the mutation")
|
||||||
|
}
|
||||||
|
oldValue, err := m.oldValue(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return v, fmt.Errorf("querying old value for OldUserID: %w", err)
|
||||||
|
}
|
||||||
|
return oldValue.UserID, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ResetUserID resets all changes to the "user_id" field.
|
||||||
|
func (m *CpImageMutation) ResetUserID() {
|
||||||
|
m.user = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetContentType sets the "content_type" field.
|
||||||
|
func (m *CpImageMutation) SetContentType(s string) {
|
||||||
|
m.content_type = &s
|
||||||
|
}
|
||||||
|
|
||||||
|
// ContentType returns the value of the "content_type" field in the mutation.
|
||||||
|
func (m *CpImageMutation) ContentType() (r string, exists bool) {
|
||||||
|
v := m.content_type
|
||||||
|
if v == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return *v, true
|
||||||
|
}
|
||||||
|
|
||||||
|
// OldContentType returns the old "content_type" field's value of the CpImage entity.
|
||||||
|
// If the CpImage object wasn't provided to the builder, the object is fetched from the database.
|
||||||
|
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||||
|
func (m *CpImageMutation) OldContentType(ctx context.Context) (v string, err error) {
|
||||||
|
if !m.op.Is(OpUpdateOne) {
|
||||||
|
return v, errors.New("OldContentType is only allowed on UpdateOne operations")
|
||||||
|
}
|
||||||
|
if m.id == nil || m.oldValue == nil {
|
||||||
|
return v, errors.New("OldContentType requires an ID field in the mutation")
|
||||||
|
}
|
||||||
|
oldValue, err := m.oldValue(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return v, fmt.Errorf("querying old value for OldContentType: %w", err)
|
||||||
|
}
|
||||||
|
return oldValue.ContentType, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ResetContentType resets all changes to the "content_type" field.
|
||||||
|
func (m *CpImageMutation) ResetContentType() {
|
||||||
|
m.content_type = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetContentLength sets the "content_length" field.
|
||||||
|
func (m *CpImageMutation) SetContentLength(i int64) {
|
||||||
|
m.content_length = &i
|
||||||
|
m.addcontent_length = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ContentLength returns the value of the "content_length" field in the mutation.
|
||||||
|
func (m *CpImageMutation) ContentLength() (r int64, exists bool) {
|
||||||
|
v := m.content_length
|
||||||
|
if v == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return *v, true
|
||||||
|
}
|
||||||
|
|
||||||
|
// OldContentLength returns the old "content_length" field's value of the CpImage entity.
|
||||||
|
// If the CpImage object wasn't provided to the builder, the object is fetched from the database.
|
||||||
|
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||||
|
func (m *CpImageMutation) OldContentLength(ctx context.Context) (v int64, err error) {
|
||||||
|
if !m.op.Is(OpUpdateOne) {
|
||||||
|
return v, errors.New("OldContentLength is only allowed on UpdateOne operations")
|
||||||
|
}
|
||||||
|
if m.id == nil || m.oldValue == nil {
|
||||||
|
return v, errors.New("OldContentLength requires an ID field in the mutation")
|
||||||
|
}
|
||||||
|
oldValue, err := m.oldValue(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return v, fmt.Errorf("querying old value for OldContentLength: %w", err)
|
||||||
|
}
|
||||||
|
return oldValue.ContentLength, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddContentLength adds i to the "content_length" field.
|
||||||
|
func (m *CpImageMutation) AddContentLength(i int64) {
|
||||||
|
if m.addcontent_length != nil {
|
||||||
|
*m.addcontent_length += i
|
||||||
|
} else {
|
||||||
|
m.addcontent_length = &i
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddedContentLength returns the value that was added to the "content_length" field in this mutation.
|
||||||
|
func (m *CpImageMutation) AddedContentLength() (r int64, exists bool) {
|
||||||
|
v := m.addcontent_length
|
||||||
|
if v == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return *v, true
|
||||||
|
}
|
||||||
|
|
||||||
|
// ResetContentLength resets all changes to the "content_length" field.
|
||||||
|
func (m *CpImageMutation) ResetContentLength() {
|
||||||
|
m.content_length = nil
|
||||||
|
m.addcontent_length = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearUser clears the "user" edge to the SysUser entity.
|
||||||
|
func (m *CpImageMutation) ClearUser() {
|
||||||
|
m.cleareduser = true
|
||||||
|
m.clearedFields[cpimage.FieldUserID] = struct{}{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserCleared reports if the "user" edge to the SysUser entity was cleared.
|
||||||
|
func (m *CpImageMutation) UserCleared() bool {
|
||||||
|
return m.cleareduser
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserIDs returns the "user" edge IDs in the mutation.
|
||||||
|
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
|
||||||
|
// UserID instead. It exists only for internal usage by the builders.
|
||||||
|
func (m *CpImageMutation) UserIDs() (ids []int64) {
|
||||||
|
if id := m.user; id != nil {
|
||||||
|
ids = append(ids, *id)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// ResetUser resets all changes to the "user" edge.
|
||||||
|
func (m *CpImageMutation) ResetUser() {
|
||||||
|
m.user = nil
|
||||||
|
m.cleareduser = false
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the CpImageMutation builder.
|
||||||
|
func (m *CpImageMutation) Where(ps ...predicate.CpImage) {
|
||||||
|
m.predicates = append(m.predicates, ps...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// WhereP appends storage-level predicates to the CpImageMutation builder. Using this method,
|
||||||
|
// users can use type-assertion to append predicates that do not depend on any generated package.
|
||||||
|
func (m *CpImageMutation) WhereP(ps ...func(*sql.Selector)) {
|
||||||
|
p := make([]predicate.CpImage, len(ps))
|
||||||
|
for i := range ps {
|
||||||
|
p[i] = ps[i]
|
||||||
|
}
|
||||||
|
m.Where(p...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Op returns the operation name.
|
||||||
|
func (m *CpImageMutation) Op() Op {
|
||||||
|
return m.op
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetOp allows setting the mutation operation.
|
||||||
|
func (m *CpImageMutation) SetOp(op Op) {
|
||||||
|
m.op = op
|
||||||
|
}
|
||||||
|
|
||||||
|
// Type returns the node type of this mutation (CpImage).
|
||||||
|
func (m *CpImageMutation) Type() string {
|
||||||
|
return m.typ
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fields returns all fields that were changed during this mutation. Note that in
|
||||||
|
// order to get all numeric fields that were incremented/decremented, call
|
||||||
|
// AddedFields().
|
||||||
|
func (m *CpImageMutation) Fields() []string {
|
||||||
|
fields := make([]string, 0, 7)
|
||||||
|
if m.create_time != nil {
|
||||||
|
fields = append(fields, cpimage.FieldCreateTime)
|
||||||
|
}
|
||||||
|
if m.update_time != nil {
|
||||||
|
fields = append(fields, cpimage.FieldUpdateTime)
|
||||||
|
}
|
||||||
|
if m.image_id != nil {
|
||||||
|
fields = append(fields, cpimage.FieldImageID)
|
||||||
|
}
|
||||||
|
if m.key != nil {
|
||||||
|
fields = append(fields, cpimage.FieldKey)
|
||||||
|
}
|
||||||
|
if m.user != nil {
|
||||||
|
fields = append(fields, cpimage.FieldUserID)
|
||||||
|
}
|
||||||
|
if m.content_type != nil {
|
||||||
|
fields = append(fields, cpimage.FieldContentType)
|
||||||
|
}
|
||||||
|
if m.content_length != nil {
|
||||||
|
fields = append(fields, cpimage.FieldContentLength)
|
||||||
|
}
|
||||||
|
return fields
|
||||||
|
}
|
||||||
|
|
||||||
|
// Field returns the value of a field with the given name. The second boolean
|
||||||
|
// return value indicates that this field was not set, or was not defined in the
|
||||||
|
// schema.
|
||||||
|
func (m *CpImageMutation) Field(name string) (ent.Value, bool) {
|
||||||
|
switch name {
|
||||||
|
case cpimage.FieldCreateTime:
|
||||||
|
return m.CreateTime()
|
||||||
|
case cpimage.FieldUpdateTime:
|
||||||
|
return m.UpdateTime()
|
||||||
|
case cpimage.FieldImageID:
|
||||||
|
return m.ImageID()
|
||||||
|
case cpimage.FieldKey:
|
||||||
|
return m.Key()
|
||||||
|
case cpimage.FieldUserID:
|
||||||
|
return m.UserID()
|
||||||
|
case cpimage.FieldContentType:
|
||||||
|
return m.ContentType()
|
||||||
|
case cpimage.FieldContentLength:
|
||||||
|
return m.ContentLength()
|
||||||
|
}
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
|
||||||
|
// OldField returns the old value of the field from the database. An error is
|
||||||
|
// returned if the mutation operation is not UpdateOne, or the query to the
|
||||||
|
// database failed.
|
||||||
|
func (m *CpImageMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
|
||||||
|
switch name {
|
||||||
|
case cpimage.FieldCreateTime:
|
||||||
|
return m.OldCreateTime(ctx)
|
||||||
|
case cpimage.FieldUpdateTime:
|
||||||
|
return m.OldUpdateTime(ctx)
|
||||||
|
case cpimage.FieldImageID:
|
||||||
|
return m.OldImageID(ctx)
|
||||||
|
case cpimage.FieldKey:
|
||||||
|
return m.OldKey(ctx)
|
||||||
|
case cpimage.FieldUserID:
|
||||||
|
return m.OldUserID(ctx)
|
||||||
|
case cpimage.FieldContentType:
|
||||||
|
return m.OldContentType(ctx)
|
||||||
|
case cpimage.FieldContentLength:
|
||||||
|
return m.OldContentLength(ctx)
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("unknown CpImage field %s", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetField sets the value of a field with the given name. It returns an error if
|
||||||
|
// the field is not defined in the schema, or if the type mismatched the field
|
||||||
|
// type.
|
||||||
|
func (m *CpImageMutation) SetField(name string, value ent.Value) error {
|
||||||
|
switch name {
|
||||||
|
case cpimage.FieldCreateTime:
|
||||||
|
v, ok := value.(ent2.CustomTime)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||||
|
}
|
||||||
|
m.SetCreateTime(v)
|
||||||
|
return nil
|
||||||
|
case cpimage.FieldUpdateTime:
|
||||||
|
v, ok := value.(ent2.CustomTime)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||||
|
}
|
||||||
|
m.SetUpdateTime(v)
|
||||||
|
return nil
|
||||||
|
case cpimage.FieldImageID:
|
||||||
|
v, ok := value.(uuid.UUID)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||||
|
}
|
||||||
|
m.SetImageID(v)
|
||||||
|
return nil
|
||||||
|
case cpimage.FieldKey:
|
||||||
|
v, ok := value.(string)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||||
|
}
|
||||||
|
m.SetKey(v)
|
||||||
|
return nil
|
||||||
|
case cpimage.FieldUserID:
|
||||||
|
v, ok := value.(int64)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||||
|
}
|
||||||
|
m.SetUserID(v)
|
||||||
|
return nil
|
||||||
|
case cpimage.FieldContentType:
|
||||||
|
v, ok := value.(string)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||||
|
}
|
||||||
|
m.SetContentType(v)
|
||||||
|
return nil
|
||||||
|
case cpimage.FieldContentLength:
|
||||||
|
v, ok := value.(int64)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||||
|
}
|
||||||
|
m.SetContentLength(v)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return fmt.Errorf("unknown CpImage field %s", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddedFields returns all numeric fields that were incremented/decremented during
|
||||||
|
// this mutation.
|
||||||
|
func (m *CpImageMutation) AddedFields() []string {
|
||||||
|
var fields []string
|
||||||
|
if m.addcontent_length != nil {
|
||||||
|
fields = append(fields, cpimage.FieldContentLength)
|
||||||
|
}
|
||||||
|
return fields
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddedField returns the numeric value that was incremented/decremented on a field
|
||||||
|
// with the given name. The second boolean return value indicates that this field
|
||||||
|
// was not set, or was not defined in the schema.
|
||||||
|
func (m *CpImageMutation) AddedField(name string) (ent.Value, bool) {
|
||||||
|
switch name {
|
||||||
|
case cpimage.FieldContentLength:
|
||||||
|
return m.AddedContentLength()
|
||||||
|
}
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddField adds the value to the field with the given name. It returns an error if
|
||||||
|
// the field is not defined in the schema, or if the type mismatched the field
|
||||||
|
// type.
|
||||||
|
func (m *CpImageMutation) AddField(name string, value ent.Value) error {
|
||||||
|
switch name {
|
||||||
|
case cpimage.FieldContentLength:
|
||||||
|
v, ok := value.(int64)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||||
|
}
|
||||||
|
m.AddContentLength(v)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return fmt.Errorf("unknown CpImage numeric field %s", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearedFields returns all nullable fields that were cleared during this
|
||||||
|
// mutation.
|
||||||
|
func (m *CpImageMutation) ClearedFields() []string {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FieldCleared returns a boolean indicating if a field with the given name was
|
||||||
|
// cleared in this mutation.
|
||||||
|
func (m *CpImageMutation) FieldCleared(name string) bool {
|
||||||
|
_, ok := m.clearedFields[name]
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearField clears the value of the field with the given name. It returns an
|
||||||
|
// error if the field is not defined in the schema.
|
||||||
|
func (m *CpImageMutation) ClearField(name string) error {
|
||||||
|
return fmt.Errorf("unknown CpImage nullable field %s", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ResetField resets all changes in the mutation for the field with the given name.
|
||||||
|
// It returns an error if the field is not defined in the schema.
|
||||||
|
func (m *CpImageMutation) ResetField(name string) error {
|
||||||
|
switch name {
|
||||||
|
case cpimage.FieldCreateTime:
|
||||||
|
m.ResetCreateTime()
|
||||||
|
return nil
|
||||||
|
case cpimage.FieldUpdateTime:
|
||||||
|
m.ResetUpdateTime()
|
||||||
|
return nil
|
||||||
|
case cpimage.FieldImageID:
|
||||||
|
m.ResetImageID()
|
||||||
|
return nil
|
||||||
|
case cpimage.FieldKey:
|
||||||
|
m.ResetKey()
|
||||||
|
return nil
|
||||||
|
case cpimage.FieldUserID:
|
||||||
|
m.ResetUserID()
|
||||||
|
return nil
|
||||||
|
case cpimage.FieldContentType:
|
||||||
|
m.ResetContentType()
|
||||||
|
return nil
|
||||||
|
case cpimage.FieldContentLength:
|
||||||
|
m.ResetContentLength()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return fmt.Errorf("unknown CpImage field %s", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddedEdges returns all edge names that were set/added in this mutation.
|
||||||
|
func (m *CpImageMutation) AddedEdges() []string {
|
||||||
|
edges := make([]string, 0, 1)
|
||||||
|
if m.user != nil {
|
||||||
|
edges = append(edges, cpimage.EdgeUser)
|
||||||
|
}
|
||||||
|
return edges
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
|
||||||
|
// name in this mutation.
|
||||||
|
func (m *CpImageMutation) AddedIDs(name string) []ent.Value {
|
||||||
|
switch name {
|
||||||
|
case cpimage.EdgeUser:
|
||||||
|
if id := m.user; id != nil {
|
||||||
|
return []ent.Value{*id}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemovedEdges returns all edge names that were removed in this mutation.
|
||||||
|
func (m *CpImageMutation) RemovedEdges() []string {
|
||||||
|
edges := make([]string, 0, 1)
|
||||||
|
return edges
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
|
||||||
|
// the given name in this mutation.
|
||||||
|
func (m *CpImageMutation) RemovedIDs(name string) []ent.Value {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearedEdges returns all edge names that were cleared in this mutation.
|
||||||
|
func (m *CpImageMutation) ClearedEdges() []string {
|
||||||
|
edges := make([]string, 0, 1)
|
||||||
|
if m.cleareduser {
|
||||||
|
edges = append(edges, cpimage.EdgeUser)
|
||||||
|
}
|
||||||
|
return edges
|
||||||
|
}
|
||||||
|
|
||||||
|
// EdgeCleared returns a boolean which indicates if the edge with the given name
|
||||||
|
// was cleared in this mutation.
|
||||||
|
func (m *CpImageMutation) EdgeCleared(name string) bool {
|
||||||
|
switch name {
|
||||||
|
case cpimage.EdgeUser:
|
||||||
|
return m.cleareduser
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearEdge clears the value of the edge with the given name. It returns an error
|
||||||
|
// if that edge is not defined in the schema.
|
||||||
|
func (m *CpImageMutation) ClearEdge(name string) error {
|
||||||
|
switch name {
|
||||||
|
case cpimage.EdgeUser:
|
||||||
|
m.ClearUser()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return fmt.Errorf("unknown CpImage unique edge %s", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ResetEdge resets all changes to the edge with the given name in this mutation.
|
||||||
|
// It returns an error if the edge is not defined in the schema.
|
||||||
|
func (m *CpImageMutation) ResetEdge(name string) error {
|
||||||
|
switch name {
|
||||||
|
case cpimage.EdgeUser:
|
||||||
|
m.ResetUser()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return fmt.Errorf("unknown CpImage edge %s", name)
|
||||||
|
}
|
||||||
|
|
||||||
// SysAgentMutation represents an operation that mutates the SysAgent nodes in the graph.
|
// SysAgentMutation represents an operation that mutates the SysAgent nodes in the graph.
|
||||||
type SysAgentMutation struct {
|
type SysAgentMutation struct {
|
||||||
config
|
config
|
||||||
@@ -2730,6 +3473,9 @@ type SysUserMutation struct {
|
|||||||
clearedroles bool
|
clearedroles bool
|
||||||
agent *int64
|
agent *int64
|
||||||
clearedagent bool
|
clearedagent bool
|
||||||
|
images map[int64]struct{}
|
||||||
|
removedimages map[int64]struct{}
|
||||||
|
clearedimages bool
|
||||||
done bool
|
done bool
|
||||||
oldValue func(context.Context) (*SysUser, error)
|
oldValue func(context.Context) (*SysUser, error)
|
||||||
predicates []predicate.SysUser
|
predicates []predicate.SysUser
|
||||||
@@ -3356,6 +4102,60 @@ func (m *SysUserMutation) ResetAgent() {
|
|||||||
m.clearedagent = false
|
m.clearedagent = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AddImageIDs adds the "images" edge to the CpImage entity by ids.
|
||||||
|
func (m *SysUserMutation) AddImageIDs(ids ...int64) {
|
||||||
|
if m.images == nil {
|
||||||
|
m.images = make(map[int64]struct{})
|
||||||
|
}
|
||||||
|
for i := range ids {
|
||||||
|
m.images[ids[i]] = struct{}{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearImages clears the "images" edge to the CpImage entity.
|
||||||
|
func (m *SysUserMutation) ClearImages() {
|
||||||
|
m.clearedimages = true
|
||||||
|
}
|
||||||
|
|
||||||
|
// ImagesCleared reports if the "images" edge to the CpImage entity was cleared.
|
||||||
|
func (m *SysUserMutation) ImagesCleared() bool {
|
||||||
|
return m.clearedimages
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveImageIDs removes the "images" edge to the CpImage entity by IDs.
|
||||||
|
func (m *SysUserMutation) RemoveImageIDs(ids ...int64) {
|
||||||
|
if m.removedimages == nil {
|
||||||
|
m.removedimages = make(map[int64]struct{})
|
||||||
|
}
|
||||||
|
for i := range ids {
|
||||||
|
delete(m.images, ids[i])
|
||||||
|
m.removedimages[ids[i]] = struct{}{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemovedImages returns the removed IDs of the "images" edge to the CpImage entity.
|
||||||
|
func (m *SysUserMutation) RemovedImagesIDs() (ids []int64) {
|
||||||
|
for id := range m.removedimages {
|
||||||
|
ids = append(ids, id)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// ImagesIDs returns the "images" edge IDs in the mutation.
|
||||||
|
func (m *SysUserMutation) ImagesIDs() (ids []int64) {
|
||||||
|
for id := range m.images {
|
||||||
|
ids = append(ids, id)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// ResetImages resets all changes to the "images" edge.
|
||||||
|
func (m *SysUserMutation) ResetImages() {
|
||||||
|
m.images = nil
|
||||||
|
m.clearedimages = false
|
||||||
|
m.removedimages = nil
|
||||||
|
}
|
||||||
|
|
||||||
// Where appends a list predicates to the SysUserMutation builder.
|
// Where appends a list predicates to the SysUserMutation builder.
|
||||||
func (m *SysUserMutation) Where(ps ...predicate.SysUser) {
|
func (m *SysUserMutation) Where(ps ...predicate.SysUser) {
|
||||||
m.predicates = append(m.predicates, ps...)
|
m.predicates = append(m.predicates, ps...)
|
||||||
@@ -3634,7 +4434,7 @@ func (m *SysUserMutation) ResetField(name string) error {
|
|||||||
|
|
||||||
// AddedEdges returns all edge names that were set/added in this mutation.
|
// AddedEdges returns all edge names that were set/added in this mutation.
|
||||||
func (m *SysUserMutation) AddedEdges() []string {
|
func (m *SysUserMutation) AddedEdges() []string {
|
||||||
edges := make([]string, 0, 4)
|
edges := make([]string, 0, 5)
|
||||||
if m.parent != nil {
|
if m.parent != nil {
|
||||||
edges = append(edges, sysuser.EdgeParent)
|
edges = append(edges, sysuser.EdgeParent)
|
||||||
}
|
}
|
||||||
@@ -3647,6 +4447,9 @@ func (m *SysUserMutation) AddedEdges() []string {
|
|||||||
if m.agent != nil {
|
if m.agent != nil {
|
||||||
edges = append(edges, sysuser.EdgeAgent)
|
edges = append(edges, sysuser.EdgeAgent)
|
||||||
}
|
}
|
||||||
|
if m.images != nil {
|
||||||
|
edges = append(edges, sysuser.EdgeImages)
|
||||||
|
}
|
||||||
return edges
|
return edges
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3674,19 +4477,28 @@ func (m *SysUserMutation) AddedIDs(name string) []ent.Value {
|
|||||||
if id := m.agent; id != nil {
|
if id := m.agent; id != nil {
|
||||||
return []ent.Value{*id}
|
return []ent.Value{*id}
|
||||||
}
|
}
|
||||||
|
case sysuser.EdgeImages:
|
||||||
|
ids := make([]ent.Value, 0, len(m.images))
|
||||||
|
for id := range m.images {
|
||||||
|
ids = append(ids, id)
|
||||||
|
}
|
||||||
|
return ids
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemovedEdges returns all edge names that were removed in this mutation.
|
// RemovedEdges returns all edge names that were removed in this mutation.
|
||||||
func (m *SysUserMutation) RemovedEdges() []string {
|
func (m *SysUserMutation) RemovedEdges() []string {
|
||||||
edges := make([]string, 0, 4)
|
edges := make([]string, 0, 5)
|
||||||
if m.removedchildren != nil {
|
if m.removedchildren != nil {
|
||||||
edges = append(edges, sysuser.EdgeChildren)
|
edges = append(edges, sysuser.EdgeChildren)
|
||||||
}
|
}
|
||||||
if m.removedroles != nil {
|
if m.removedroles != nil {
|
||||||
edges = append(edges, sysuser.EdgeRoles)
|
edges = append(edges, sysuser.EdgeRoles)
|
||||||
}
|
}
|
||||||
|
if m.removedimages != nil {
|
||||||
|
edges = append(edges, sysuser.EdgeImages)
|
||||||
|
}
|
||||||
return edges
|
return edges
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3706,13 +4518,19 @@ func (m *SysUserMutation) RemovedIDs(name string) []ent.Value {
|
|||||||
ids = append(ids, id)
|
ids = append(ids, id)
|
||||||
}
|
}
|
||||||
return ids
|
return ids
|
||||||
|
case sysuser.EdgeImages:
|
||||||
|
ids := make([]ent.Value, 0, len(m.removedimages))
|
||||||
|
for id := range m.removedimages {
|
||||||
|
ids = append(ids, id)
|
||||||
|
}
|
||||||
|
return ids
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClearedEdges returns all edge names that were cleared in this mutation.
|
// ClearedEdges returns all edge names that were cleared in this mutation.
|
||||||
func (m *SysUserMutation) ClearedEdges() []string {
|
func (m *SysUserMutation) ClearedEdges() []string {
|
||||||
edges := make([]string, 0, 4)
|
edges := make([]string, 0, 5)
|
||||||
if m.clearedparent {
|
if m.clearedparent {
|
||||||
edges = append(edges, sysuser.EdgeParent)
|
edges = append(edges, sysuser.EdgeParent)
|
||||||
}
|
}
|
||||||
@@ -3725,6 +4543,9 @@ func (m *SysUserMutation) ClearedEdges() []string {
|
|||||||
if m.clearedagent {
|
if m.clearedagent {
|
||||||
edges = append(edges, sysuser.EdgeAgent)
|
edges = append(edges, sysuser.EdgeAgent)
|
||||||
}
|
}
|
||||||
|
if m.clearedimages {
|
||||||
|
edges = append(edges, sysuser.EdgeImages)
|
||||||
|
}
|
||||||
return edges
|
return edges
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3740,6 +4561,8 @@ func (m *SysUserMutation) EdgeCleared(name string) bool {
|
|||||||
return m.clearedroles
|
return m.clearedroles
|
||||||
case sysuser.EdgeAgent:
|
case sysuser.EdgeAgent:
|
||||||
return m.clearedagent
|
return m.clearedagent
|
||||||
|
case sysuser.EdgeImages:
|
||||||
|
return m.clearedimages
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@@ -3774,6 +4597,9 @@ func (m *SysUserMutation) ResetEdge(name string) error {
|
|||||||
case sysuser.EdgeAgent:
|
case sysuser.EdgeAgent:
|
||||||
m.ResetAgent()
|
m.ResetAgent()
|
||||||
return nil
|
return nil
|
||||||
|
case sysuser.EdgeImages:
|
||||||
|
m.ResetImages()
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
return fmt.Errorf("unknown SysUser edge %s", name)
|
return fmt.Errorf("unknown SysUser edge %s", name)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,9 @@ import (
|
|||||||
"entgo.io/ent/dialect/sql"
|
"entgo.io/ent/dialect/sql"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// CpImage is the predicate function for cpimage builders.
|
||||||
|
type CpImage func(*sql.Selector)
|
||||||
|
|
||||||
// SysAgent is the predicate function for sysagent builders.
|
// SysAgent is the predicate function for sysagent builders.
|
||||||
type SysAgent func(*sql.Selector)
|
type SysAgent func(*sql.Selector)
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
package runtime
|
package runtime
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"likedream-goframe/internal/ent/cpimage"
|
||||||
"likedream-goframe/internal/ent/schema"
|
"likedream-goframe/internal/ent/schema"
|
||||||
"likedream-goframe/internal/ent/sysagent"
|
"likedream-goframe/internal/ent/sysagent"
|
||||||
"likedream-goframe/internal/ent/sysmenu"
|
"likedream-goframe/internal/ent/sysmenu"
|
||||||
@@ -16,6 +17,27 @@ import (
|
|||||||
// (default values, validators, hooks and policies) and stitches it
|
// (default values, validators, hooks and policies) and stitches it
|
||||||
// to their package variables.
|
// to their package variables.
|
||||||
func init() {
|
func init() {
|
||||||
|
cpimageMixin := schema.CpImage{}.Mixin()
|
||||||
|
cpimageMixinHooks0 := cpimageMixin[0].Hooks()
|
||||||
|
cpimage.Hooks[0] = cpimageMixinHooks0[0]
|
||||||
|
cpimageFields := schema.CpImage{}.Fields()
|
||||||
|
_ = cpimageFields
|
||||||
|
// cpimageDescKey is the schema descriptor for key field.
|
||||||
|
cpimageDescKey := cpimageFields[1].Descriptor()
|
||||||
|
// cpimage.KeyValidator is a validator for the "key" field. It is called by the builders before save.
|
||||||
|
cpimage.KeyValidator = cpimageDescKey.Validators[0].(func(string) error)
|
||||||
|
// cpimageDescUserID is the schema descriptor for user_id field.
|
||||||
|
cpimageDescUserID := cpimageFields[2].Descriptor()
|
||||||
|
// cpimage.UserIDValidator is a validator for the "user_id" field. It is called by the builders before save.
|
||||||
|
cpimage.UserIDValidator = cpimageDescUserID.Validators[0].(func(int64) error)
|
||||||
|
// cpimageDescContentType is the schema descriptor for content_type field.
|
||||||
|
cpimageDescContentType := cpimageFields[3].Descriptor()
|
||||||
|
// cpimage.ContentTypeValidator is a validator for the "content_type" field. It is called by the builders before save.
|
||||||
|
cpimage.ContentTypeValidator = cpimageDescContentType.Validators[0].(func(string) error)
|
||||||
|
// cpimageDescContentLength is the schema descriptor for content_length field.
|
||||||
|
cpimageDescContentLength := cpimageFields[4].Descriptor()
|
||||||
|
// cpimage.ContentLengthValidator is a validator for the "content_length" field. It is called by the builders before save.
|
||||||
|
cpimage.ContentLengthValidator = cpimageDescContentLength.Validators[0].(func(int64) error)
|
||||||
sysagentMixin := schema.SysAgent{}.Mixin()
|
sysagentMixin := schema.SysAgent{}.Mixin()
|
||||||
sysagentMixinHooks0 := sysagentMixin[0].Hooks()
|
sysagentMixinHooks0 := sysagentMixin[0].Hooks()
|
||||||
sysagent.Hooks[0] = sysagentMixinHooks0[0]
|
sysagent.Hooks[0] = sysagentMixinHooks0[0]
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
package schema
|
||||||
|
|
||||||
|
import (
|
||||||
|
"likedream-goframe/internal/ent/schema/mix"
|
||||||
|
|
||||||
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/dialect/entsql"
|
||||||
|
"entgo.io/ent/schema"
|
||||||
|
"entgo.io/ent/schema/edge"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
)
|
||||||
|
|
||||||
|
// CpImage holds the schema definition for the CpImage entity.
|
||||||
|
type CpImage struct {
|
||||||
|
ent.Schema
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fields of the CpImage.
|
||||||
|
func (CpImage) Fields() []ent.Field {
|
||||||
|
return []ent.Field{
|
||||||
|
field.UUID("image_id", uuid.New()).Unique().Immutable(),
|
||||||
|
field.String("key").NotEmpty(),
|
||||||
|
field.Int64("user_id").Positive(),
|
||||||
|
field.String("content_type").NotEmpty(),
|
||||||
|
field.Int64("content_length").Positive(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Edges of the CpImage.
|
||||||
|
func (CpImage) Edges() []ent.Edge {
|
||||||
|
return []ent.Edge{
|
||||||
|
edge.From("user", SysUser.Type).
|
||||||
|
Ref("images").
|
||||||
|
Field("user_id").
|
||||||
|
Unique().
|
||||||
|
Required(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (CpImage) Annotations() []schema.Annotation {
|
||||||
|
return []schema.Annotation{
|
||||||
|
entsql.Annotation{Table: "cp_image"},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (CpImage) Mixin() []ent.Mixin {
|
||||||
|
return []ent.Mixin{
|
||||||
|
mix.MixinTime{},
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,10 @@
|
|||||||
package schema
|
package schema
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"likedream-goframe/internal/ent/schema/mix"
|
||||||
|
"likedream-goframe/internal/framework/ent2"
|
||||||
|
"regexp"
|
||||||
|
|
||||||
"entgo.io/ent"
|
"entgo.io/ent"
|
||||||
"entgo.io/ent/dialect"
|
"entgo.io/ent/dialect"
|
||||||
"entgo.io/ent/dialect/entsql"
|
"entgo.io/ent/dialect/entsql"
|
||||||
@@ -8,9 +12,6 @@ import (
|
|||||||
"entgo.io/ent/schema/edge"
|
"entgo.io/ent/schema/edge"
|
||||||
"entgo.io/ent/schema/field"
|
"entgo.io/ent/schema/field"
|
||||||
"github.com/shopspring/decimal"
|
"github.com/shopspring/decimal"
|
||||||
"likedream-goframe/internal/ent/schema/mix"
|
|
||||||
"likedream-goframe/internal/framework/ent2"
|
|
||||||
"regexp"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// SysUser holds the schema definition for the SysUser entity.
|
// SysUser holds the schema definition for the SysUser entity.
|
||||||
@@ -42,6 +43,7 @@ func (SysUser) Edges() []ent.Edge {
|
|||||||
Unique(),
|
Unique(),
|
||||||
edge.To("roles", SysRole.Type), // 用户拥有角色
|
edge.To("roles", SysRole.Type), // 用户拥有角色
|
||||||
edge.To("agent", SysAgent.Type).Unique(), // 用户拥有代理
|
edge.To("agent", SysAgent.Type).Unique(), // 用户拥有代理
|
||||||
|
edge.To("images", CpImage.Type), // 用户拥有的图片
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+17
-1
@@ -54,9 +54,11 @@ type SysUserEdges struct {
|
|||||||
Roles []*SysRole `json:"roles,omitempty"`
|
Roles []*SysRole `json:"roles,omitempty"`
|
||||||
// Agent holds the value of the agent edge.
|
// Agent holds the value of the agent edge.
|
||||||
Agent *SysAgent `json:"agent,omitempty"`
|
Agent *SysAgent `json:"agent,omitempty"`
|
||||||
|
// Images holds the value of the images edge.
|
||||||
|
Images []*CpImage `json:"images,omitempty"`
|
||||||
// loadedTypes holds the information for reporting if a
|
// loadedTypes holds the information for reporting if a
|
||||||
// type was loaded (or requested) in eager-loading or not.
|
// type was loaded (or requested) in eager-loading or not.
|
||||||
loadedTypes [4]bool
|
loadedTypes [5]bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParentOrErr returns the Parent value or an error if the edge
|
// ParentOrErr returns the Parent value or an error if the edge
|
||||||
@@ -99,6 +101,15 @@ func (e SysUserEdges) AgentOrErr() (*SysAgent, error) {
|
|||||||
return nil, &NotLoadedError{edge: "agent"}
|
return nil, &NotLoadedError{edge: "agent"}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ImagesOrErr returns the Images value or an error if the edge
|
||||||
|
// was not loaded in eager-loading.
|
||||||
|
func (e SysUserEdges) ImagesOrErr() ([]*CpImage, error) {
|
||||||
|
if e.loadedTypes[4] {
|
||||||
|
return e.Images, nil
|
||||||
|
}
|
||||||
|
return nil, &NotLoadedError{edge: "images"}
|
||||||
|
}
|
||||||
|
|
||||||
// scanValues returns the types for scanning values from sql.Rows.
|
// scanValues returns the types for scanning values from sql.Rows.
|
||||||
func (*SysUser) scanValues(columns []string) ([]any, error) {
|
func (*SysUser) scanValues(columns []string) ([]any, error) {
|
||||||
values := make([]any, len(columns))
|
values := make([]any, len(columns))
|
||||||
@@ -231,6 +242,11 @@ func (su *SysUser) QueryAgent() *SysAgentQuery {
|
|||||||
return NewSysUserClient(su.config).QueryAgent(su)
|
return NewSysUserClient(su.config).QueryAgent(su)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// QueryImages queries the "images" edge of the SysUser entity.
|
||||||
|
func (su *SysUser) QueryImages() *CpImageQuery {
|
||||||
|
return NewSysUserClient(su.config).QueryImages(su)
|
||||||
|
}
|
||||||
|
|
||||||
// Update returns a builder for updating this SysUser.
|
// Update returns a builder for updating this SysUser.
|
||||||
// Note that you need to call SysUser.Unwrap() before calling this method if this SysUser
|
// Note that you need to call SysUser.Unwrap() before calling this method if this SysUser
|
||||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||||
|
|||||||
@@ -40,6 +40,8 @@ const (
|
|||||||
EdgeRoles = "roles"
|
EdgeRoles = "roles"
|
||||||
// EdgeAgent holds the string denoting the agent edge name in mutations.
|
// EdgeAgent holds the string denoting the agent edge name in mutations.
|
||||||
EdgeAgent = "agent"
|
EdgeAgent = "agent"
|
||||||
|
// EdgeImages holds the string denoting the images edge name in mutations.
|
||||||
|
EdgeImages = "images"
|
||||||
// Table holds the table name of the sysuser in the database.
|
// Table holds the table name of the sysuser in the database.
|
||||||
Table = "sys_user"
|
Table = "sys_user"
|
||||||
// ParentTable is the table that holds the parent relation/edge.
|
// ParentTable is the table that holds the parent relation/edge.
|
||||||
@@ -62,6 +64,13 @@ const (
|
|||||||
AgentInverseTable = "sys_agent"
|
AgentInverseTable = "sys_agent"
|
||||||
// AgentColumn is the table column denoting the agent relation/edge.
|
// AgentColumn is the table column denoting the agent relation/edge.
|
||||||
AgentColumn = "sys_user_agent"
|
AgentColumn = "sys_user_agent"
|
||||||
|
// ImagesTable is the table that holds the images relation/edge.
|
||||||
|
ImagesTable = "cp_image"
|
||||||
|
// ImagesInverseTable is the table name for the CpImage entity.
|
||||||
|
// It exists in this package in order to avoid circular dependency with the "cpimage" package.
|
||||||
|
ImagesInverseTable = "cp_image"
|
||||||
|
// ImagesColumn is the table column denoting the images relation/edge.
|
||||||
|
ImagesColumn = "user_id"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Columns holds all SQL columns for sysuser fields.
|
// Columns holds all SQL columns for sysuser fields.
|
||||||
@@ -216,6 +225,20 @@ func ByAgentField(field string, opts ...sql.OrderTermOption) OrderOption {
|
|||||||
sqlgraph.OrderByNeighborTerms(s, newAgentStep(), sql.OrderByField(field, opts...))
|
sqlgraph.OrderByNeighborTerms(s, newAgentStep(), sql.OrderByField(field, opts...))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ByImagesCount orders the results by images count.
|
||||||
|
func ByImagesCount(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return func(s *sql.Selector) {
|
||||||
|
sqlgraph.OrderByNeighborsCount(s, newImagesStep(), opts...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByImages orders the results by images terms.
|
||||||
|
func ByImages(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
|
||||||
|
return func(s *sql.Selector) {
|
||||||
|
sqlgraph.OrderByNeighborTerms(s, newImagesStep(), append([]sql.OrderTerm{term}, terms...)...)
|
||||||
|
}
|
||||||
|
}
|
||||||
func newParentStep() *sqlgraph.Step {
|
func newParentStep() *sqlgraph.Step {
|
||||||
return sqlgraph.NewStep(
|
return sqlgraph.NewStep(
|
||||||
sqlgraph.From(Table, FieldID),
|
sqlgraph.From(Table, FieldID),
|
||||||
@@ -244,3 +267,10 @@ func newAgentStep() *sqlgraph.Step {
|
|||||||
sqlgraph.Edge(sqlgraph.O2O, false, AgentTable, AgentColumn),
|
sqlgraph.Edge(sqlgraph.O2O, false, AgentTable, AgentColumn),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
func newImagesStep() *sqlgraph.Step {
|
||||||
|
return sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(Table, FieldID),
|
||||||
|
sqlgraph.To(ImagesInverseTable, FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.O2M, false, ImagesTable, ImagesColumn),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|||||||
@@ -693,6 +693,29 @@ func HasAgentWith(preds ...predicate.SysAgent) predicate.SysUser {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HasImages applies the HasEdge predicate on the "images" edge.
|
||||||
|
func HasImages() predicate.SysUser {
|
||||||
|
return predicate.SysUser(func(s *sql.Selector) {
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(Table, FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.O2M, false, ImagesTable, ImagesColumn),
|
||||||
|
)
|
||||||
|
sqlgraph.HasNeighbors(s, step)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasImagesWith applies the HasEdge predicate on the "images" edge with a given conditions (other predicates).
|
||||||
|
func HasImagesWith(preds ...predicate.CpImage) predicate.SysUser {
|
||||||
|
return predicate.SysUser(func(s *sql.Selector) {
|
||||||
|
step := newImagesStep()
|
||||||
|
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||||
|
for _, p := range preds {
|
||||||
|
p(s)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// And groups predicates with the AND operator between them.
|
// And groups predicates with the AND operator between them.
|
||||||
func And(predicates ...predicate.SysUser) predicate.SysUser {
|
func And(predicates ...predicate.SysUser) predicate.SysUser {
|
||||||
return predicate.SysUser(sql.AndPredicates(predicates...))
|
return predicate.SysUser(sql.AndPredicates(predicates...))
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"likedream-goframe/internal/ent/cpimage"
|
||||||
"likedream-goframe/internal/ent/sysagent"
|
"likedream-goframe/internal/ent/sysagent"
|
||||||
"likedream-goframe/internal/ent/sysrole"
|
"likedream-goframe/internal/ent/sysrole"
|
||||||
"likedream-goframe/internal/ent/sysuser"
|
"likedream-goframe/internal/ent/sysuser"
|
||||||
@@ -179,6 +180,21 @@ func (suc *SysUserCreate) SetAgent(s *SysAgent) *SysUserCreate {
|
|||||||
return suc.SetAgentID(s.ID)
|
return suc.SetAgentID(s.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AddImageIDs adds the "images" edge to the CpImage entity by IDs.
|
||||||
|
func (suc *SysUserCreate) AddImageIDs(ids ...int64) *SysUserCreate {
|
||||||
|
suc.mutation.AddImageIDs(ids...)
|
||||||
|
return suc
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddImages adds the "images" edges to the CpImage entity.
|
||||||
|
func (suc *SysUserCreate) AddImages(c ...*CpImage) *SysUserCreate {
|
||||||
|
ids := make([]int64, len(c))
|
||||||
|
for i := range c {
|
||||||
|
ids[i] = c[i].ID
|
||||||
|
}
|
||||||
|
return suc.AddImageIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
// Mutation returns the SysUserMutation object of the builder.
|
// Mutation returns the SysUserMutation object of the builder.
|
||||||
func (suc *SysUserCreate) Mutation() *SysUserMutation {
|
func (suc *SysUserCreate) Mutation() *SysUserMutation {
|
||||||
return suc.mutation
|
return suc.mutation
|
||||||
@@ -393,6 +409,22 @@ func (suc *SysUserCreate) createSpec() (*SysUser, *sqlgraph.CreateSpec) {
|
|||||||
}
|
}
|
||||||
_spec.Edges = append(_spec.Edges, edge)
|
_spec.Edges = append(_spec.Edges, edge)
|
||||||
}
|
}
|
||||||
|
if nodes := suc.mutation.ImagesIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: sysuser.ImagesTable,
|
||||||
|
Columns: []string{sysuser.ImagesColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(cpimage.FieldID, field.TypeInt64),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges = append(_spec.Edges, edge)
|
||||||
|
}
|
||||||
return _node, _spec
|
return _node, _spec
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"database/sql/driver"
|
"database/sql/driver"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"likedream-goframe/internal/ent/cpimage"
|
||||||
"likedream-goframe/internal/ent/predicate"
|
"likedream-goframe/internal/ent/predicate"
|
||||||
"likedream-goframe/internal/ent/sysagent"
|
"likedream-goframe/internal/ent/sysagent"
|
||||||
"likedream-goframe/internal/ent/sysrole"
|
"likedream-goframe/internal/ent/sysrole"
|
||||||
@@ -29,6 +30,7 @@ type SysUserQuery struct {
|
|||||||
withChildren *SysUserQuery
|
withChildren *SysUserQuery
|
||||||
withRoles *SysRoleQuery
|
withRoles *SysRoleQuery
|
||||||
withAgent *SysAgentQuery
|
withAgent *SysAgentQuery
|
||||||
|
withImages *CpImageQuery
|
||||||
withFKs bool
|
withFKs bool
|
||||||
// intermediate query (i.e. traversal path).
|
// intermediate query (i.e. traversal path).
|
||||||
sql *sql.Selector
|
sql *sql.Selector
|
||||||
@@ -154,6 +156,28 @@ func (suq *SysUserQuery) QueryAgent() *SysAgentQuery {
|
|||||||
return query
|
return query
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// QueryImages chains the current query on the "images" edge.
|
||||||
|
func (suq *SysUserQuery) QueryImages() *CpImageQuery {
|
||||||
|
query := (&CpImageClient{config: suq.config}).Query()
|
||||||
|
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||||
|
if err := suq.prepareQuery(ctx); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
selector := suq.sqlQuery(ctx)
|
||||||
|
if err := selector.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(sysuser.Table, sysuser.FieldID, selector),
|
||||||
|
sqlgraph.To(cpimage.Table, cpimage.FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.O2M, false, sysuser.ImagesTable, sysuser.ImagesColumn),
|
||||||
|
)
|
||||||
|
fromU = sqlgraph.SetNeighbors(suq.driver.Dialect(), step)
|
||||||
|
return fromU, nil
|
||||||
|
}
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
// First returns the first SysUser entity from the query.
|
// First returns the first SysUser entity from the query.
|
||||||
// Returns a *NotFoundError when no SysUser was found.
|
// Returns a *NotFoundError when no SysUser was found.
|
||||||
func (suq *SysUserQuery) First(ctx context.Context) (*SysUser, error) {
|
func (suq *SysUserQuery) First(ctx context.Context) (*SysUser, error) {
|
||||||
@@ -350,6 +374,7 @@ func (suq *SysUserQuery) Clone() *SysUserQuery {
|
|||||||
withChildren: suq.withChildren.Clone(),
|
withChildren: suq.withChildren.Clone(),
|
||||||
withRoles: suq.withRoles.Clone(),
|
withRoles: suq.withRoles.Clone(),
|
||||||
withAgent: suq.withAgent.Clone(),
|
withAgent: suq.withAgent.Clone(),
|
||||||
|
withImages: suq.withImages.Clone(),
|
||||||
// clone intermediate query.
|
// clone intermediate query.
|
||||||
sql: suq.sql.Clone(),
|
sql: suq.sql.Clone(),
|
||||||
path: suq.path,
|
path: suq.path,
|
||||||
@@ -400,6 +425,17 @@ func (suq *SysUserQuery) WithAgent(opts ...func(*SysAgentQuery)) *SysUserQuery {
|
|||||||
return suq
|
return suq
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithImages tells the query-builder to eager-load the nodes that are connected to
|
||||||
|
// the "images" edge. The optional arguments are used to configure the query builder of the edge.
|
||||||
|
func (suq *SysUserQuery) WithImages(opts ...func(*CpImageQuery)) *SysUserQuery {
|
||||||
|
query := (&CpImageClient{config: suq.config}).Query()
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt(query)
|
||||||
|
}
|
||||||
|
suq.withImages = query
|
||||||
|
return suq
|
||||||
|
}
|
||||||
|
|
||||||
// GroupBy is used to group vertices by one or more fields/columns.
|
// GroupBy is used to group vertices by one or more fields/columns.
|
||||||
// It is often used with aggregate functions, like: count, max, mean, min, sum.
|
// It is often used with aggregate functions, like: count, max, mean, min, sum.
|
||||||
//
|
//
|
||||||
@@ -479,11 +515,12 @@ func (suq *SysUserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Sys
|
|||||||
nodes = []*SysUser{}
|
nodes = []*SysUser{}
|
||||||
withFKs = suq.withFKs
|
withFKs = suq.withFKs
|
||||||
_spec = suq.querySpec()
|
_spec = suq.querySpec()
|
||||||
loadedTypes = [4]bool{
|
loadedTypes = [5]bool{
|
||||||
suq.withParent != nil,
|
suq.withParent != nil,
|
||||||
suq.withChildren != nil,
|
suq.withChildren != nil,
|
||||||
suq.withRoles != nil,
|
suq.withRoles != nil,
|
||||||
suq.withAgent != nil,
|
suq.withAgent != nil,
|
||||||
|
suq.withImages != nil,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
if suq.withParent != nil {
|
if suq.withParent != nil {
|
||||||
@@ -536,6 +573,13 @@ func (suq *SysUserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Sys
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if query := suq.withImages; query != nil {
|
||||||
|
if err := suq.loadImages(ctx, query, nodes,
|
||||||
|
func(n *SysUser) { n.Edges.Images = []*CpImage{} },
|
||||||
|
func(n *SysUser, e *CpImage) { n.Edges.Images = append(n.Edges.Images, e) }); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
return nodes, nil
|
return nodes, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -691,6 +735,36 @@ func (suq *SysUserQuery) loadAgent(ctx context.Context, query *SysAgentQuery, no
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
func (suq *SysUserQuery) loadImages(ctx context.Context, query *CpImageQuery, nodes []*SysUser, init func(*SysUser), assign func(*SysUser, *CpImage)) error {
|
||||||
|
fks := make([]driver.Value, 0, len(nodes))
|
||||||
|
nodeids := make(map[int64]*SysUser)
|
||||||
|
for i := range nodes {
|
||||||
|
fks = append(fks, nodes[i].ID)
|
||||||
|
nodeids[nodes[i].ID] = nodes[i]
|
||||||
|
if init != nil {
|
||||||
|
init(nodes[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(query.ctx.Fields) > 0 {
|
||||||
|
query.ctx.AppendFieldOnce(cpimage.FieldUserID)
|
||||||
|
}
|
||||||
|
query.Where(predicate.CpImage(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.InValues(s.C(sysuser.ImagesColumn), fks...))
|
||||||
|
}))
|
||||||
|
neighbors, err := query.All(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, n := range neighbors {
|
||||||
|
fk := n.UserID
|
||||||
|
node, ok := nodeids[fk]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf(`unexpected referenced foreign-key "user_id" returned %v for node %v`, fk, n.ID)
|
||||||
|
}
|
||||||
|
assign(node, n)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (suq *SysUserQuery) sqlCount(ctx context.Context) (int, error) {
|
func (suq *SysUserQuery) sqlCount(ctx context.Context) (int, error) {
|
||||||
_spec := suq.querySpec()
|
_spec := suq.querySpec()
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"likedream-goframe/internal/ent/cpimage"
|
||||||
"likedream-goframe/internal/ent/predicate"
|
"likedream-goframe/internal/ent/predicate"
|
||||||
"likedream-goframe/internal/ent/sysagent"
|
"likedream-goframe/internal/ent/sysagent"
|
||||||
"likedream-goframe/internal/ent/sysrole"
|
"likedream-goframe/internal/ent/sysrole"
|
||||||
@@ -217,6 +218,21 @@ func (suu *SysUserUpdate) SetAgent(s *SysAgent) *SysUserUpdate {
|
|||||||
return suu.SetAgentID(s.ID)
|
return suu.SetAgentID(s.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AddImageIDs adds the "images" edge to the CpImage entity by IDs.
|
||||||
|
func (suu *SysUserUpdate) AddImageIDs(ids ...int64) *SysUserUpdate {
|
||||||
|
suu.mutation.AddImageIDs(ids...)
|
||||||
|
return suu
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddImages adds the "images" edges to the CpImage entity.
|
||||||
|
func (suu *SysUserUpdate) AddImages(c ...*CpImage) *SysUserUpdate {
|
||||||
|
ids := make([]int64, len(c))
|
||||||
|
for i := range c {
|
||||||
|
ids[i] = c[i].ID
|
||||||
|
}
|
||||||
|
return suu.AddImageIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
// Mutation returns the SysUserMutation object of the builder.
|
// Mutation returns the SysUserMutation object of the builder.
|
||||||
func (suu *SysUserUpdate) Mutation() *SysUserMutation {
|
func (suu *SysUserUpdate) Mutation() *SysUserMutation {
|
||||||
return suu.mutation
|
return suu.mutation
|
||||||
@@ -276,6 +292,27 @@ func (suu *SysUserUpdate) ClearAgent() *SysUserUpdate {
|
|||||||
return suu
|
return suu
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ClearImages clears all "images" edges to the CpImage entity.
|
||||||
|
func (suu *SysUserUpdate) ClearImages() *SysUserUpdate {
|
||||||
|
suu.mutation.ClearImages()
|
||||||
|
return suu
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveImageIDs removes the "images" edge to CpImage entities by IDs.
|
||||||
|
func (suu *SysUserUpdate) RemoveImageIDs(ids ...int64) *SysUserUpdate {
|
||||||
|
suu.mutation.RemoveImageIDs(ids...)
|
||||||
|
return suu
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveImages removes "images" edges to CpImage entities.
|
||||||
|
func (suu *SysUserUpdate) RemoveImages(c ...*CpImage) *SysUserUpdate {
|
||||||
|
ids := make([]int64, len(c))
|
||||||
|
for i := range c {
|
||||||
|
ids[i] = c[i].ID
|
||||||
|
}
|
||||||
|
return suu.RemoveImageIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||||
func (suu *SysUserUpdate) Save(ctx context.Context) (int, error) {
|
func (suu *SysUserUpdate) Save(ctx context.Context) (int, error) {
|
||||||
return withHooks(ctx, suu.sqlSave, suu.mutation, suu.hooks)
|
return withHooks(ctx, suu.sqlSave, suu.mutation, suu.hooks)
|
||||||
@@ -500,6 +537,51 @@ func (suu *SysUserUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
|||||||
}
|
}
|
||||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||||
}
|
}
|
||||||
|
if suu.mutation.ImagesCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: sysuser.ImagesTable,
|
||||||
|
Columns: []string{sysuser.ImagesColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(cpimage.FieldID, field.TypeInt64),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := suu.mutation.RemovedImagesIDs(); len(nodes) > 0 && !suu.mutation.ImagesCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: sysuser.ImagesTable,
|
||||||
|
Columns: []string{sysuser.ImagesColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(cpimage.FieldID, field.TypeInt64),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := suu.mutation.ImagesIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: sysuser.ImagesTable,
|
||||||
|
Columns: []string{sysuser.ImagesColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(cpimage.FieldID, field.TypeInt64),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||||
|
}
|
||||||
if n, err = sqlgraph.UpdateNodes(ctx, suu.driver, _spec); err != nil {
|
if n, err = sqlgraph.UpdateNodes(ctx, suu.driver, _spec); err != nil {
|
||||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||||
err = &NotFoundError{sysuser.Label}
|
err = &NotFoundError{sysuser.Label}
|
||||||
@@ -706,6 +788,21 @@ func (suuo *SysUserUpdateOne) SetAgent(s *SysAgent) *SysUserUpdateOne {
|
|||||||
return suuo.SetAgentID(s.ID)
|
return suuo.SetAgentID(s.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AddImageIDs adds the "images" edge to the CpImage entity by IDs.
|
||||||
|
func (suuo *SysUserUpdateOne) AddImageIDs(ids ...int64) *SysUserUpdateOne {
|
||||||
|
suuo.mutation.AddImageIDs(ids...)
|
||||||
|
return suuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddImages adds the "images" edges to the CpImage entity.
|
||||||
|
func (suuo *SysUserUpdateOne) AddImages(c ...*CpImage) *SysUserUpdateOne {
|
||||||
|
ids := make([]int64, len(c))
|
||||||
|
for i := range c {
|
||||||
|
ids[i] = c[i].ID
|
||||||
|
}
|
||||||
|
return suuo.AddImageIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
// Mutation returns the SysUserMutation object of the builder.
|
// Mutation returns the SysUserMutation object of the builder.
|
||||||
func (suuo *SysUserUpdateOne) Mutation() *SysUserMutation {
|
func (suuo *SysUserUpdateOne) Mutation() *SysUserMutation {
|
||||||
return suuo.mutation
|
return suuo.mutation
|
||||||
@@ -765,6 +862,27 @@ func (suuo *SysUserUpdateOne) ClearAgent() *SysUserUpdateOne {
|
|||||||
return suuo
|
return suuo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ClearImages clears all "images" edges to the CpImage entity.
|
||||||
|
func (suuo *SysUserUpdateOne) ClearImages() *SysUserUpdateOne {
|
||||||
|
suuo.mutation.ClearImages()
|
||||||
|
return suuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveImageIDs removes the "images" edge to CpImage entities by IDs.
|
||||||
|
func (suuo *SysUserUpdateOne) RemoveImageIDs(ids ...int64) *SysUserUpdateOne {
|
||||||
|
suuo.mutation.RemoveImageIDs(ids...)
|
||||||
|
return suuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveImages removes "images" edges to CpImage entities.
|
||||||
|
func (suuo *SysUserUpdateOne) RemoveImages(c ...*CpImage) *SysUserUpdateOne {
|
||||||
|
ids := make([]int64, len(c))
|
||||||
|
for i := range c {
|
||||||
|
ids[i] = c[i].ID
|
||||||
|
}
|
||||||
|
return suuo.RemoveImageIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
// Where appends a list predicates to the SysUserUpdate builder.
|
// Where appends a list predicates to the SysUserUpdate builder.
|
||||||
func (suuo *SysUserUpdateOne) Where(ps ...predicate.SysUser) *SysUserUpdateOne {
|
func (suuo *SysUserUpdateOne) Where(ps ...predicate.SysUser) *SysUserUpdateOne {
|
||||||
suuo.mutation.Where(ps...)
|
suuo.mutation.Where(ps...)
|
||||||
@@ -1019,6 +1137,51 @@ func (suuo *SysUserUpdateOne) sqlSave(ctx context.Context) (_node *SysUser, err
|
|||||||
}
|
}
|
||||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||||
}
|
}
|
||||||
|
if suuo.mutation.ImagesCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: sysuser.ImagesTable,
|
||||||
|
Columns: []string{sysuser.ImagesColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(cpimage.FieldID, field.TypeInt64),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := suuo.mutation.RemovedImagesIDs(); len(nodes) > 0 && !suuo.mutation.ImagesCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: sysuser.ImagesTable,
|
||||||
|
Columns: []string{sysuser.ImagesColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(cpimage.FieldID, field.TypeInt64),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := suuo.mutation.ImagesIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: sysuser.ImagesTable,
|
||||||
|
Columns: []string{sysuser.ImagesColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(cpimage.FieldID, field.TypeInt64),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||||
|
}
|
||||||
_node = &SysUser{config: suuo.config}
|
_node = &SysUser{config: suuo.config}
|
||||||
_spec.Assign = _node.assignValues
|
_spec.Assign = _node.assignValues
|
||||||
_spec.ScanValues = _node.scanValues
|
_spec.ScanValues = _node.scanValues
|
||||||
|
|||||||
+4
-1
@@ -12,6 +12,8 @@ import (
|
|||||||
// Tx is a transactional client that is created by calling Client.Tx().
|
// Tx is a transactional client that is created by calling Client.Tx().
|
||||||
type Tx struct {
|
type Tx struct {
|
||||||
config
|
config
|
||||||
|
// CpImage is the client for interacting with the CpImage builders.
|
||||||
|
CpImage *CpImageClient
|
||||||
// SysAgent is the client for interacting with the SysAgent builders.
|
// SysAgent is the client for interacting with the SysAgent builders.
|
||||||
SysAgent *SysAgentClient
|
SysAgent *SysAgentClient
|
||||||
// SysMenu is the client for interacting with the SysMenu builders.
|
// SysMenu is the client for interacting with the SysMenu builders.
|
||||||
@@ -153,6 +155,7 @@ func (tx *Tx) Client() *Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (tx *Tx) init() {
|
func (tx *Tx) init() {
|
||||||
|
tx.CpImage = NewCpImageClient(tx.config)
|
||||||
tx.SysAgent = NewSysAgentClient(tx.config)
|
tx.SysAgent = NewSysAgentClient(tx.config)
|
||||||
tx.SysMenu = NewSysMenuClient(tx.config)
|
tx.SysMenu = NewSysMenuClient(tx.config)
|
||||||
tx.SysRole = NewSysRoleClient(tx.config)
|
tx.SysRole = NewSysRoleClient(tx.config)
|
||||||
@@ -167,7 +170,7 @@ func (tx *Tx) init() {
|
|||||||
// of them in order to commit or rollback the transaction.
|
// of them in order to commit or rollback the transaction.
|
||||||
//
|
//
|
||||||
// If a closed transaction is embedded in one of the generated entities, and the entity
|
// If a closed transaction is embedded in one of the generated entities, and the entity
|
||||||
// applies a query, for example: SysAgent.QueryXXX(), the query will be executed
|
// applies a query, for example: CpImage.QueryXXX(), the query will be executed
|
||||||
// through the driver which created this transaction.
|
// through the driver which created this transaction.
|
||||||
//
|
//
|
||||||
// Note that txDriver is not goroutine safe.
|
// Note that txDriver is not goroutine safe.
|
||||||
|
|||||||
@@ -1,6 +1,12 @@
|
|||||||
package utils
|
package utils
|
||||||
|
|
||||||
import "math/rand/v2"
|
import (
|
||||||
|
"io"
|
||||||
|
"math/rand/v2"
|
||||||
|
|
||||||
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
|
"github.com/gogf/gf/v2/os/gctx"
|
||||||
|
)
|
||||||
|
|
||||||
func GetFirstNotEmptyString(strs ...string) string {
|
func GetFirstNotEmptyString(strs ...string) string {
|
||||||
for _, str := range strs {
|
for _, str := range strs {
|
||||||
@@ -20,3 +26,17 @@ func GenerateRandomString(length int) string {
|
|||||||
}
|
}
|
||||||
return string(result)
|
return string(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ReadString(reader io.Reader) string {
|
||||||
|
defer func() {
|
||||||
|
if closer, ok := reader.(io.Closer); ok {
|
||||||
|
e := closer.Close()
|
||||||
|
if e != nil {
|
||||||
|
g.Log().Errorf(gctx.GetInitCtx(), "关闭Reader失败: %v", e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
bytes, err := io.ReadAll(reader)
|
||||||
|
OkOrPanic(err)
|
||||||
|
return string(bytes)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user