Skip to content

Commit

Permalink
publish🚀 1.3.3
Browse files Browse the repository at this point in the history
  • Loading branch information
wenjianzhang authored May 7, 2021
2 parents bf7934c + c6d94c0 commit e126fd3
Show file tree
Hide file tree
Showing 54 changed files with 980 additions and 957 deletions.
17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,22 @@ vi ./config/setting.yml
```

#### 初始化数据库,以及服务启动
```
``` bash
# 首次配置需要初始化数据库资源信息
./go-admin migrate -c config/settings.yml
# macOS or linux 下使用
$ ./go-admin migrate -c=config/settings.dev.yml

# ⚠️注意:windows 下使用
$ ./go-admin.exe migrate -c=config/settings.dev.yml


# 启动项目,也可以用IDE进行调试
./go-admin server -c config/settings.yml
# macOS or linux 下使用
$ ./go-admin server -c config/settings.yml


# ⚠️注意:windows 下使用
$ ./go-admin.exe server -c config/settings.yml
```

#### 使用docker 编译启动
Expand All @@ -188,10 +196,11 @@ go generate

#### 交叉编译
```bash
# windows
env GOOS=windows GOARCH=amd64 go build main.go

# or

# linux
env GOOS=linux GOARCH=amd64 go build main.go
```

Expand Down
5 changes: 3 additions & 2 deletions app/admin/apis/monitor/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ type Monitor struct {
// @Tags 系统信息
// @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/settings/serverInfo [get]
func (e *Monitor) ServerInfo(c *gin.Context) {
func (e Monitor) ServerInfo(c *gin.Context) {
e.Context = c

osDic := make(map[string]interface{}, 0)
osDic["goOs"] = runtime.GOOS
Expand Down Expand Up @@ -65,7 +66,7 @@ func (e *Monitor) ServerInfo(c *gin.Context) {
cpuDic["Percent"] = pkg.Round(percent[0], 2)
cpuDic["cpuNum"], _ = cpu.Counts(false)

e.Custom(c, gin.H{
e.Custom(gin.H{
"code": 200,
"os": osDic,
"mem": memDic,
Expand Down
34 changes: 18 additions & 16 deletions app/admin/apis/public/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@ type File struct {
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
// @Router /api/v1/public/uploadFile [post]
func (e *File) UploadFile(c *gin.Context) {
func (e File) UploadFile(c *gin.Context) {
e.Context = c

tag, _ := c.GetPostForm("type")
urlPerfix := fmt.Sprintf("http://%s/", c.Request.Host)
var fileResponse FileResponse
if tag == "" {
e.Error(c, 500, nil, "缺少标识")
e.Error(500, nil, "缺少标识")
//app.Error(c, 200, errors.New(""), "缺少标识")
return
} else {
Expand All @@ -55,28 +57,28 @@ func (e *File) UploadFile(c *gin.Context) {
if done {
return
}
e.OK(c, fileResponse, "上传成功")
e.OK(fileResponse, "上传成功")
return
case "2": // 多图
multipartFile := e.multipleFile(c, urlPerfix)
e.OK(c, multipartFile, "上传成功")
e.OK(multipartFile, "上传成功")
return
case "3": // base64
fileResponse = e.baseImg(c, fileResponse, urlPerfix)
e.OK(c, fileResponse, "上传成功")
e.OK(fileResponse, "上传成功")
}
}
}

func (e *File) baseImg(c *gin.Context, fileResponse FileResponse, urlPerfix string) FileResponse {
func (e File) baseImg(c *gin.Context, fileResponse FileResponse, urlPerfix string) FileResponse {
files, _ := c.GetPostForm("file")
file2list := strings.Split(files, ",")
ddd, _ := base64.StdEncoding.DecodeString(file2list[1])
guid := uuid.New().String()
fileName := guid + ".jpg"
err := utils.IsNotExistMkDir(path)
if err != nil {
e.Error(c, 500, errors.New(""), "初始化文件路径失败")
e.Error(500, errors.New(""), "初始化文件路径失败")
}
base64File := path + fileName
_ = ioutil.WriteFile(base64File, ddd, 0666)
Expand All @@ -91,7 +93,7 @@ func (e *File) baseImg(c *gin.Context, fileResponse FileResponse, urlPerfix stri
source, _ := c.GetPostForm("source")
err = thirdUpload(source, fileName, base64File)
if err != nil {
e.Error(c, 200, errors.New(""), "上传第三方失败")
e.Error(200, errors.New(""), "上传第三方失败")
return fileResponse
}
if source != "1" {
Expand All @@ -101,7 +103,7 @@ func (e *File) baseImg(c *gin.Context, fileResponse FileResponse, urlPerfix stri
return fileResponse
}

func (e *File) multipleFile(c *gin.Context, urlPerfix string) []FileResponse {
func (e File) multipleFile(c *gin.Context, urlPerfix string) []FileResponse {
files := c.Request.MultipartForm.File["file"]
source, _ := c.GetPostForm("source")
var multipartFile []FileResponse
Expand All @@ -111,15 +113,15 @@ func (e *File) multipleFile(c *gin.Context, urlPerfix string) []FileResponse {

err := utils.IsNotExistMkDir(path)
if err != nil {
e.Error(c, 500, errors.New(""), "初始化文件路径失败")
e.Error(500, errors.New(""), "初始化文件路径失败")
}
multipartFileName := path + fileName
err1 := c.SaveUploadedFile(f, multipartFileName)
fileType, _ := utils.GetType(multipartFileName)
if err1 == nil {
err := thirdUpload(source, fileName, multipartFileName)
if err != nil {
e.Error(c, 500, errors.New(""), "上传第三方失败")
e.Error(500, errors.New(""), "上传第三方失败")
} else {
fileResponse := FileResponse{
Size: pkg.GetFileSize(multipartFileName),
Expand All @@ -139,11 +141,11 @@ func (e *File) multipleFile(c *gin.Context, urlPerfix string) []FileResponse {
return multipartFile
}

func (e *File) singleFile(c *gin.Context, fileResponse FileResponse, urlPerfix string) (FileResponse, bool) {
func (e File) singleFile(c *gin.Context, fileResponse FileResponse, urlPerfix string) (FileResponse, bool) {
files, err := c.FormFile("file")

if err != nil {
e.Error(c, 200, errors.New(""), "图片不能为空")
e.Error(200, errors.New(""), "图片不能为空")
return FileResponse{}, true
}
// 上传文件至指定目录
Expand All @@ -153,7 +155,7 @@ func (e *File) singleFile(c *gin.Context, fileResponse FileResponse, urlPerfix s

err = utils.IsNotExistMkDir(path)
if err != nil {
e.Error(c, 500, errors.New(""), "初始化文件路径失败")
e.Error(500, errors.New(""), "初始化文件路径失败")
}
singleFile := path + fileName
_ = c.SaveUploadedFile(files, singleFile)
Expand All @@ -168,7 +170,7 @@ func (e *File) singleFile(c *gin.Context, fileResponse FileResponse, urlPerfix s
source, _ := c.GetPostForm("source")
err = thirdUpload(source, fileName, singleFile)
if err != nil {
e.Error(c, 200, errors.New(""), "上传第三方失败")
e.Error(200, errors.New(""), "上传第三方失败")
return FileResponse{}, true
}
fileResponse.Path = "https://youshikeji.oss-cn-shanghai.aliyuncs.com/img/" + fileName
Expand All @@ -194,4 +196,4 @@ func ossUpload(name string, path string) error {
func qiniuUpload(name string, path string) error {
oss := file_store.ALiYunOSS{}
return oss.UpLoad(name, path)
}
}
69 changes: 37 additions & 32 deletions app/admin/apis/sys_china_area_data/sys_china_area_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ type SysChinaAreaData struct {
apis.Api
}

func (e *SysChinaAreaData) GetSysChinaAreaDataList(c *gin.Context) {
log := e.GetLogger(c)
func (e SysChinaAreaData) GetSysChinaAreaDataList(c *gin.Context) {
e.SetContext(c)
log := e.GetLogger()
d := new(dto.SysChinaAreaDataSearch)
db, err := e.GetOrm(c)
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
Expand All @@ -29,7 +30,7 @@ func (e *SysChinaAreaData) GetSysChinaAreaDataList(c *gin.Context) {
//查询列表
err = d.Bind(c)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}

Expand All @@ -43,17 +44,18 @@ func (e *SysChinaAreaData) GetSysChinaAreaDataList(c *gin.Context) {
serviceStudent.Orm = db
err = serviceStudent.GetSysChinaAreaDataPage(d, p, &list, &count)
if err != nil {
e.Error(c, http.StatusInternalServerError, err, "查询失败")
e.Error(http.StatusInternalServerError, err, "查询失败")
return
}

e.PageOK(c, list, int(count), d.GetPageIndex(), d.GetPageSize(), "查询成功")
e.PageOK(list, int(count), d.GetPageIndex(), d.GetPageSize(), "查询成功")
}

func (e *SysChinaAreaData) GetSysChinaAreaData(c *gin.Context) {
log := e.GetLogger(c)
func (e SysChinaAreaData) GetSysChinaAreaData(c *gin.Context) {
e.SetContext(c)
log := e.GetLogger()
control := new(dto.SysChinaAreaDataById)
db, err := e.GetOrm(c)
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
Expand All @@ -62,7 +64,7 @@ func (e *SysChinaAreaData) GetSysChinaAreaData(c *gin.Context) {
//查看详情
err = control.Bind(c)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
var object models.SysChinaAreaData
Expand All @@ -75,17 +77,18 @@ func (e *SysChinaAreaData) GetSysChinaAreaData(c *gin.Context) {
serviceSysChinaAreaData.Orm = db
err = serviceSysChinaAreaData.GetSysChinaAreaData(control, p, &object)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "查询失败")
e.Error(http.StatusUnprocessableEntity, err, "查询失败")
return
}

e.OK(c, object, "查看成功")
e.OK(object, "查看成功")
}

func (e *SysChinaAreaData) InsertSysChinaAreaData(c *gin.Context) {
log := e.GetLogger(c)
func (e SysChinaAreaData) InsertSysChinaAreaData(c *gin.Context) {
e.SetContext(c)
log := e.GetLogger()
control := new(dto.SysChinaAreaDataControl)
db, err := e.GetOrm(c)
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
Expand All @@ -94,12 +97,12 @@ func (e *SysChinaAreaData) InsertSysChinaAreaData(c *gin.Context) {
//新增操作
err = control.Bind(c)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
object, err := control.Generate()
if err != nil {
e.Error(c, http.StatusInternalServerError, err, "模型生成失败")
e.Error(http.StatusInternalServerError, err, "模型生成失败")
return
}
// 设置创建人
Expand All @@ -111,17 +114,18 @@ func (e *SysChinaAreaData) InsertSysChinaAreaData(c *gin.Context) {
err = serviceSysChinaAreaData.InsertSysChinaAreaData(object)
if err != nil {
log.Error(err)
e.Error(c, http.StatusInternalServerError, err, "创建失败")
e.Error(http.StatusInternalServerError, err, "创建失败")
return
}

e.OK(c, object.GetId(), "创建成功")
e.OK(object.GetId(), "创建成功")
}

func (e *SysChinaAreaData) UpdateSysChinaAreaData(c *gin.Context) {
log := e.GetLogger(c)
func (e SysChinaAreaData) UpdateSysChinaAreaData(c *gin.Context) {
e.SetContext(c)
log := e.GetLogger()
control := new(dto.SysChinaAreaDataControl)
db, err := e.GetOrm(c)
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
Expand All @@ -130,12 +134,12 @@ func (e *SysChinaAreaData) UpdateSysChinaAreaData(c *gin.Context) {
//更新操作
err = control.Bind(c)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
object, err := control.Generate()
if err != nil {
e.Error(c, http.StatusInternalServerError, err, "模型生成失败")
e.Error(http.StatusInternalServerError, err, "模型生成失败")
return
}
object.SetUpdateBy(user.GetUserId(c))
Expand All @@ -151,13 +155,14 @@ func (e *SysChinaAreaData) UpdateSysChinaAreaData(c *gin.Context) {
log.Error(err)
return
}
e.OK(c, object.GetId(), "更新成功")
e.OK(object.GetId(), "更新成功")
}

func (e *SysChinaAreaData) DeleteSysChinaAreaData(c *gin.Context) {
log := e.GetLogger(c)
func (e SysChinaAreaData) DeleteSysChinaAreaData(c *gin.Context) {
e.SetContext(c)
log := e.GetLogger()
control := new(dto.SysChinaAreaDataById)
db, err := e.GetOrm(c)
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
Expand All @@ -167,7 +172,7 @@ func (e *SysChinaAreaData) DeleteSysChinaAreaData(c *gin.Context) {
err = control.Bind(c)
if err != nil {
log.Errorf("Bind error: %s", err)
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}

Expand All @@ -183,8 +188,8 @@ func (e *SysChinaAreaData) DeleteSysChinaAreaData(c *gin.Context) {
err = serviceSysChinaAreaData.RemoveSysChinaAreaData(control, p)
if err != nil {
log.Errorf("RemoveSysChinaAreaData error, %s", err)
e.Error(c, http.StatusInternalServerError, err, "删除失败")
e.Error(http.StatusInternalServerError, err, "删除失败")
return
}
e.OK(c, control.GetId(), "删除成功")
}
e.OK(control.GetId(), "删除成功")
}
Loading

0 comments on commit e126fd3

Please sign in to comment.