Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
chain33-pai
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ligaishun
chain33-pai
Commits
3f5b9e0c
Commit
3f5b9e0c
authored
Oct 09, 2019
by
szh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add sql
parent
436b59af
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
0 additions
and
526 deletions
+0
-526
article.go
service/article_service/article.go
+0
-136
article_poster.go
service/article_service/article_poster.go
+0
-197
auth.go
service/auth_service/auth.go
+0
-12
tag.go
service/tag_service/tag.go
+0
-181
No files found.
service/article_service/article.go
deleted
100644 → 0
View file @
436b59af
package
article_service
import
(
"encoding/json"
"chain33-pai/models"
"chain33-pai/pkg/gredis"
"chain33-pai/pkg/logging"
"chain33-pai/service/cache_service"
)
type
Article
struct
{
ID
int
TagID
int
Title
string
Desc
string
Content
string
CoverImageUrl
string
State
int
CreatedBy
string
ModifiedBy
string
PageNum
int
PageSize
int
}
func
(
a
*
Article
)
Add
()
error
{
article
:=
map
[
string
]
interface
{}{
"tag_id"
:
a
.
TagID
,
"title"
:
a
.
Title
,
"desc"
:
a
.
Desc
,
"content"
:
a
.
Content
,
"created_by"
:
a
.
CreatedBy
,
"cover_image_url"
:
a
.
CoverImageUrl
,
"state"
:
a
.
State
,
}
if
err
:=
models
.
AddArticle
(
article
);
err
!=
nil
{
return
err
}
return
nil
}
func
(
a
*
Article
)
Edit
()
error
{
return
models
.
EditArticle
(
a
.
ID
,
map
[
string
]
interface
{}{
"tag_id"
:
a
.
TagID
,
"title"
:
a
.
Title
,
"desc"
:
a
.
Desc
,
"content"
:
a
.
Content
,
"cover_image_url"
:
a
.
CoverImageUrl
,
"state"
:
a
.
State
,
"modified_by"
:
a
.
ModifiedBy
,
})
}
func
(
a
*
Article
)
Get
()
(
*
models
.
Article
,
error
)
{
var
cacheArticle
*
models
.
Article
cache
:=
cache_service
.
Article
{
ID
:
a
.
ID
}
key
:=
cache
.
GetArticleKey
()
if
gredis
.
Exists
(
key
)
{
data
,
err
:=
gredis
.
Get
(
key
)
if
err
!=
nil
{
logging
.
Info
(
err
)
}
else
{
json
.
Unmarshal
(
data
,
&
cacheArticle
)
return
cacheArticle
,
nil
}
}
article
,
err
:=
models
.
GetArticle
(
a
.
ID
)
if
err
!=
nil
{
return
nil
,
err
}
gredis
.
Set
(
key
,
article
,
3600
)
return
article
,
nil
}
func
(
a
*
Article
)
GetAll
()
([]
*
models
.
Article
,
error
)
{
var
(
articles
,
cacheArticles
[]
*
models
.
Article
)
cache
:=
cache_service
.
Article
{
TagID
:
a
.
TagID
,
State
:
a
.
State
,
PageNum
:
a
.
PageNum
,
PageSize
:
a
.
PageSize
,
}
key
:=
cache
.
GetArticlesKey
()
if
gredis
.
Exists
(
key
)
{
data
,
err
:=
gredis
.
Get
(
key
)
if
err
!=
nil
{
logging
.
Info
(
err
)
}
else
{
json
.
Unmarshal
(
data
,
&
cacheArticles
)
return
cacheArticles
,
nil
}
}
articles
,
err
:=
models
.
GetArticles
(
a
.
PageNum
,
a
.
PageSize
,
a
.
getMaps
())
if
err
!=
nil
{
return
nil
,
err
}
gredis
.
Set
(
key
,
articles
,
3600
)
return
articles
,
nil
}
func
(
a
*
Article
)
Delete
()
error
{
return
models
.
DeleteArticle
(
a
.
ID
)
}
func
(
a
*
Article
)
ExistByID
()
(
bool
,
error
)
{
return
models
.
ExistArticleByID
(
a
.
ID
)
}
func
(
a
*
Article
)
Count
()
(
int
,
error
)
{
return
models
.
GetArticleTotal
(
a
.
getMaps
())
}
func
(
a
*
Article
)
getMaps
()
map
[
string
]
interface
{}
{
maps
:=
make
(
map
[
string
]
interface
{})
maps
[
"deleted_on"
]
=
0
if
a
.
State
!=
-
1
{
maps
[
"state"
]
=
a
.
State
}
if
a
.
TagID
!=
-
1
{
maps
[
"tag_id"
]
=
a
.
TagID
}
return
maps
}
service/article_service/article_poster.go
deleted
100644 → 0
View file @
436b59af
package
article_service
import
(
"image"
"image/draw"
"image/jpeg"
"io/ioutil"
"os"
"github.com/golang/freetype"
"chain33-pai/pkg/file"
"chain33-pai/pkg/qrcode"
"chain33-pai/pkg/setting"
)
type
ArticlePoster
struct
{
PosterName
string
*
Article
Qr
*
qrcode
.
QrCode
}
func
NewArticlePoster
(
posterName
string
,
article
*
Article
,
qr
*
qrcode
.
QrCode
)
*
ArticlePoster
{
return
&
ArticlePoster
{
PosterName
:
posterName
,
Article
:
article
,
Qr
:
qr
,
}
}
func
GetPosterFlag
()
string
{
return
"poster"
}
func
(
a
*
ArticlePoster
)
CheckMergedImage
(
path
string
)
bool
{
if
file
.
CheckNotExist
(
path
+
a
.
PosterName
)
==
true
{
return
false
}
return
true
}
func
(
a
*
ArticlePoster
)
OpenMergedImage
(
path
string
)
(
*
os
.
File
,
error
)
{
f
,
err
:=
file
.
MustOpen
(
a
.
PosterName
,
path
)
if
err
!=
nil
{
return
nil
,
err
}
return
f
,
nil
}
type
ArticlePosterBg
struct
{
Name
string
*
ArticlePoster
*
Rect
*
Pt
}
type
Rect
struct
{
Name
string
X0
int
Y0
int
X1
int
Y1
int
}
type
Pt
struct
{
X
int
Y
int
}
func
NewArticlePosterBg
(
name
string
,
ap
*
ArticlePoster
,
rect
*
Rect
,
pt
*
Pt
)
*
ArticlePosterBg
{
return
&
ArticlePosterBg
{
Name
:
name
,
ArticlePoster
:
ap
,
Rect
:
rect
,
Pt
:
pt
,
}
}
type
DrawText
struct
{
JPG
draw
.
Image
Merged
*
os
.
File
Title
string
X0
int
Y0
int
Size0
float64
SubTitle
string
X1
int
Y1
int
Size1
float64
}
func
(
a
*
ArticlePosterBg
)
DrawPoster
(
d
*
DrawText
,
fontName
string
)
error
{
fontSource
:=
setting
.
AppSetting
.
RuntimeRootPath
+
setting
.
AppSetting
.
FontSavePath
+
fontName
fontSourceBytes
,
err
:=
ioutil
.
ReadFile
(
fontSource
)
if
err
!=
nil
{
return
err
}
trueTypeFont
,
err
:=
freetype
.
ParseFont
(
fontSourceBytes
)
if
err
!=
nil
{
return
err
}
fc
:=
freetype
.
NewContext
()
fc
.
SetDPI
(
72
)
fc
.
SetFont
(
trueTypeFont
)
fc
.
SetFontSize
(
d
.
Size0
)
fc
.
SetClip
(
d
.
JPG
.
Bounds
())
fc
.
SetDst
(
d
.
JPG
)
fc
.
SetSrc
(
image
.
Black
)
pt
:=
freetype
.
Pt
(
d
.
X0
,
d
.
Y0
)
_
,
err
=
fc
.
DrawString
(
d
.
Title
,
pt
)
if
err
!=
nil
{
return
err
}
fc
.
SetFontSize
(
d
.
Size1
)
_
,
err
=
fc
.
DrawString
(
d
.
SubTitle
,
freetype
.
Pt
(
d
.
X1
,
d
.
Y1
))
if
err
!=
nil
{
return
err
}
err
=
jpeg
.
Encode
(
d
.
Merged
,
d
.
JPG
,
nil
)
if
err
!=
nil
{
return
err
}
return
nil
}
func
(
a
*
ArticlePosterBg
)
Generate
()
(
string
,
string
,
error
)
{
fullPath
:=
qrcode
.
GetQrCodeFullPath
()
fileName
,
path
,
err
:=
a
.
Qr
.
Encode
(
fullPath
)
if
err
!=
nil
{
return
""
,
""
,
err
}
if
!
a
.
CheckMergedImage
(
path
)
{
mergedF
,
err
:=
a
.
OpenMergedImage
(
path
)
if
err
!=
nil
{
return
""
,
""
,
err
}
defer
mergedF
.
Close
()
bgF
,
err
:=
file
.
MustOpen
(
a
.
Name
,
path
)
if
err
!=
nil
{
return
""
,
""
,
err
}
defer
bgF
.
Close
()
qrF
,
err
:=
file
.
MustOpen
(
fileName
,
path
)
if
err
!=
nil
{
return
""
,
""
,
err
}
defer
qrF
.
Close
()
bgImage
,
err
:=
jpeg
.
Decode
(
bgF
)
if
err
!=
nil
{
return
""
,
""
,
err
}
qrImage
,
err
:=
jpeg
.
Decode
(
qrF
)
if
err
!=
nil
{
return
""
,
""
,
err
}
jpg
:=
image
.
NewRGBA
(
image
.
Rect
(
a
.
Rect
.
X0
,
a
.
Rect
.
Y0
,
a
.
Rect
.
X1
,
a
.
Rect
.
Y1
))
draw
.
Draw
(
jpg
,
jpg
.
Bounds
(),
bgImage
,
bgImage
.
Bounds
()
.
Min
,
draw
.
Over
)
draw
.
Draw
(
jpg
,
jpg
.
Bounds
(),
qrImage
,
qrImage
.
Bounds
()
.
Min
.
Sub
(
image
.
Pt
(
a
.
Pt
.
X
,
a
.
Pt
.
Y
)),
draw
.
Over
)
err
=
a
.
DrawPoster
(
&
DrawText
{
JPG
:
jpg
,
Merged
:
mergedF
,
Title
:
"Golang Gin 系列文章"
,
X0
:
80
,
Y0
:
160
,
Size0
:
42
,
SubTitle
:
"---煎鱼"
,
X1
:
320
,
Y1
:
220
,
Size1
:
36
,
},
"msyhbd.ttc"
)
if
err
!=
nil
{
return
""
,
""
,
err
}
}
return
fileName
,
path
,
nil
}
service/auth_service/auth.go
deleted
100644 → 0
View file @
436b59af
package
auth_service
import
"chain33-pai/models"
type
Auth
struct
{
Username
string
Password
string
}
func
(
a
*
Auth
)
Check
()
(
bool
,
error
)
{
return
models
.
CheckAuth
(
a
.
Username
,
a
.
Password
)
}
service/tag_service/tag.go
deleted
100644 → 0
View file @
436b59af
package
tag_service
import
(
"encoding/json"
"io"
"strconv"
"time"
"github.com/360EntSecGroup-Skylar/excelize"
"github.com/tealeg/xlsx"
"chain33-pai/models"
"chain33-pai/pkg/export"
"chain33-pai/pkg/file"
"chain33-pai/pkg/gredis"
"chain33-pai/pkg/logging"
"chain33-pai/service/cache_service"
)
type
Tag
struct
{
ID
int
Name
string
CreatedBy
string
ModifiedBy
string
State
int
PageNum
int
PageSize
int
}
func
(
t
*
Tag
)
ExistByName
()
(
bool
,
error
)
{
return
models
.
ExistTagByName
(
t
.
Name
)
}
func
(
t
*
Tag
)
ExistByID
()
(
bool
,
error
)
{
return
models
.
ExistTagByID
(
t
.
ID
)
}
func
(
t
*
Tag
)
Add
()
error
{
return
models
.
AddTag
(
t
.
Name
,
t
.
State
,
t
.
CreatedBy
)
}
func
(
t
*
Tag
)
Edit
()
error
{
data
:=
make
(
map
[
string
]
interface
{})
data
[
"modified_by"
]
=
t
.
ModifiedBy
data
[
"name"
]
=
t
.
Name
if
t
.
State
>=
0
{
data
[
"state"
]
=
t
.
State
}
return
models
.
EditTag
(
t
.
ID
,
data
)
}
func
(
t
*
Tag
)
Delete
()
error
{
return
models
.
DeleteTag
(
t
.
ID
)
}
func
(
t
*
Tag
)
Count
()
(
int
,
error
)
{
return
models
.
GetTagTotal
(
t
.
getMaps
())
}
func
(
t
*
Tag
)
GetAll
()
([]
models
.
Tag
,
error
)
{
var
(
tags
,
cacheTags
[]
models
.
Tag
)
cache
:=
cache_service
.
Tag
{
State
:
t
.
State
,
PageNum
:
t
.
PageNum
,
PageSize
:
t
.
PageSize
,
}
key
:=
cache
.
GetTagsKey
()
if
gredis
.
Exists
(
key
)
{
data
,
err
:=
gredis
.
Get
(
key
)
if
err
!=
nil
{
logging
.
Info
(
err
)
}
else
{
json
.
Unmarshal
(
data
,
&
cacheTags
)
return
cacheTags
,
nil
}
}
tags
,
err
:=
models
.
GetTags
(
t
.
PageNum
,
t
.
PageSize
,
t
.
getMaps
())
if
err
!=
nil
{
return
nil
,
err
}
gredis
.
Set
(
key
,
tags
,
3600
)
return
tags
,
nil
}
func
(
t
*
Tag
)
Export
()
(
string
,
error
)
{
tags
,
err
:=
t
.
GetAll
()
if
err
!=
nil
{
return
""
,
err
}
xlsFile
:=
xlsx
.
NewFile
()
sheet
,
err
:=
xlsFile
.
AddSheet
(
"标签信息"
)
if
err
!=
nil
{
return
""
,
err
}
titles
:=
[]
string
{
"ID"
,
"名称"
,
"创建人"
,
"创建时间"
,
"修改人"
,
"修改时间"
}
row
:=
sheet
.
AddRow
()
var
cell
*
xlsx
.
Cell
for
_
,
title
:=
range
titles
{
cell
=
row
.
AddCell
()
cell
.
Value
=
title
}
for
_
,
v
:=
range
tags
{
values
:=
[]
string
{
strconv
.
Itoa
(
v
.
ID
),
v
.
Name
,
v
.
CreatedBy
,
strconv
.
Itoa
(
v
.
CreatedOn
),
v
.
ModifiedBy
,
strconv
.
Itoa
(
v
.
ModifiedOn
),
}
row
=
sheet
.
AddRow
()
for
_
,
value
:=
range
values
{
cell
=
row
.
AddCell
()
cell
.
Value
=
value
}
}
time
:=
strconv
.
Itoa
(
int
(
time
.
Now
()
.
Unix
()))
filename
:=
"tags-"
+
time
+
export
.
EXT
dirFullPath
:=
export
.
GetExcelFullPath
()
err
=
file
.
IsNotExistMkDir
(
dirFullPath
)
if
err
!=
nil
{
return
""
,
err
}
err
=
xlsFile
.
Save
(
dirFullPath
+
filename
)
if
err
!=
nil
{
return
""
,
err
}
return
filename
,
nil
}
func
(
t
*
Tag
)
Import
(
r
io
.
Reader
)
error
{
xlsx
,
err
:=
excelize
.
OpenReader
(
r
)
if
err
!=
nil
{
return
err
}
rows
:=
xlsx
.
GetRows
(
"标签信息"
)
for
irow
,
row
:=
range
rows
{
if
irow
>
0
{
var
data
[]
string
for
_
,
cell
:=
range
row
{
data
=
append
(
data
,
cell
)
}
models
.
AddTag
(
data
[
1
],
1
,
data
[
2
])
}
}
return
nil
}
func
(
t
*
Tag
)
getMaps
()
map
[
string
]
interface
{}
{
maps
:=
make
(
map
[
string
]
interface
{})
maps
[
"deleted_on"
]
=
0
if
t
.
Name
!=
""
{
maps
[
"name"
]
=
t
.
Name
}
if
t
.
State
>=
0
{
maps
[
"state"
]
=
t
.
State
}
return
maps
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment