Skip to content

Commit

Permalink
feat: 导入数据时自动添加分类
Browse files Browse the repository at this point in the history
  • Loading branch information
wanglu committed Apr 11, 2022
1 parent e9f1e9c commit 120a5fa
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ FROM node:14-alpine AS feBuilder
WORKDIR /app
# RUN apk add --no-cache g++ gcc make python3
COPY . .
RUN yarn config set registry https://registry.npm.taobao.org && yarn global add typescript
RUN cd /app && cd ui/admin && yarn && yarn build && cd ../..
RUN cd ui/website && yarn && yarn build && cd ../..
RUN cd /app && mkdir -p public/admin
Expand Down
19 changes: 19 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,15 @@ func updateUser(data updateUserDto, db *sql.DB) {
}

func addCatelog(data addCatelogDto, db *sql.DB) {
// 先检查重复不重复
existCatelogs := getAllCatelog(db)
var existCatelogsArr []string
for _, catelogDto := range existCatelogs {
existCatelogsArr = append(existCatelogsArr, catelogDto.Name)
}
if in(data.Name, existCatelogsArr) {
return
}
sql_add_catelog := `
INSERT INTO nav_catelog (id,name)
VALUES (?,?);
Expand Down Expand Up @@ -360,7 +369,12 @@ func main() {
}

func importTools(data []Tool) {
var catelogs []string
for _, v := range data {
// if ()
if !in(v.Catelog, catelogs) {
catelogs = append(catelogs, v.Catelog)
}
sql_add_tool := `
INSERT INTO nav_table (id, name, catelog, url, logo, desc)
VALUES (?, ?, ?, ?, ?, ?);
Expand All @@ -372,6 +386,11 @@ func importTools(data []Tool) {
_, err = res.LastInsertId()
checkErr(err)
}
for _, catelog := range catelogs {
var addCatelogDto addCatelogDto
addCatelogDto.Name = catelog
addCatelog(addCatelogDto, db)
}
}

func getSetting(db *sql.DB) Setting {
Expand Down
8 changes: 8 additions & 0 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,11 @@ func checkErr(err error) {
fmt.Println("捕获到错误:", err)
}
}
func in(target string, str_array []string) bool {
for _, element := range str_array{
if target == element{
return true
}
}
return false
}

0 comments on commit 120a5fa

Please sign in to comment.