-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
85a0a65
commit cee975f
Showing
5 changed files
with
878 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,280 @@ | ||
// Code generated by dol build. Only Generate by tools if not existed. | ||
// source: organ.go | ||
|
||
package app | ||
|
||
import ( | ||
"errors" | ||
"aisle/model" | ||
"aisle/srv" | ||
|
||
"github.com/2637309949/dolphin/packages/gin/binding" | ||
"github.com/2637309949/dolphin/packages/go-funk" | ||
"github.com/2637309949/dolphin/packages/logrus" | ||
"github.com/2637309949/dolphin/packages/null" | ||
"github.com/2637309949/dolphin/packages/time" | ||
) | ||
|
||
// OrganAdd api implementation | ||
// @Summary 添加城市 | ||
// @Tags 城市 | ||
// @Accept application/json | ||
// @Param Authorization header string false "认证令牌" | ||
// @Param organ body model.Organ false "城市信息" | ||
// @Failure 403 {object} model.Fail | ||
// @Success 200 {object} model.Success | ||
// @Failure 500 {object} model.Fail | ||
// @Router /api/organ/add [post] | ||
func OrganAdd(ctx *Context) { | ||
var payload model.Organ | ||
if err := ctx.ShouldBindBodyWith(&payload, binding.JSON); err != nil { | ||
logrus.Error(err) | ||
ctx.Fail(err) | ||
return | ||
} | ||
payload.CreateTime = null.TimeFrom(time.Now().Value()) | ||
payload.Creater = null.StringFrom(ctx.GetToken().GetUserID()) | ||
payload.UpdateTime = null.TimeFrom(time.Now().Value()) | ||
payload.Updater = null.StringFrom(ctx.GetToken().GetUserID()) | ||
payload.IsDelete = null.IntFrom(0) | ||
ret, err := ctx.DB.Insert(&payload) | ||
if err != nil { | ||
logrus.Error(err) | ||
ctx.Fail(err) | ||
return | ||
} | ||
ctx.Success(ret) | ||
} | ||
|
||
// OrganBatchAdd api implementation | ||
// @Summary 添加城市 | ||
// @Tags 城市 | ||
// @Accept application/json | ||
// @Param Authorization header string false "认证令牌" | ||
// @Param organ body []model.Organ false "城市信息" | ||
// @Failure 403 {object} model.Fail | ||
// @Success 200 {object} model.Success | ||
// @Failure 500 {object} model.Fail | ||
// @Router /api/organ/batch_add [post] | ||
func OrganBatchAdd(ctx *Context) { | ||
var payload []model.Organ | ||
if err := ctx.ShouldBindBodyWith(&payload, binding.JSON); err != nil { | ||
logrus.Error(err) | ||
ctx.Fail(err) | ||
return | ||
} | ||
for i := range payload { | ||
payload[i].CreateTime = null.TimeFrom(time.Now().Value()) | ||
payload[i].Creater = null.StringFrom(ctx.GetToken().GetUserID()) | ||
payload[i].UpdateTime = null.TimeFrom(time.Now().Value()) | ||
payload[i].Updater = null.StringFrom(ctx.GetToken().GetUserID()) | ||
payload[i].IsDelete = null.IntFrom(0) | ||
} | ||
ret, err := ctx.DB.Insert(&payload) | ||
if err != nil { | ||
logrus.Error(err) | ||
ctx.Fail(err) | ||
return | ||
} | ||
ctx.Success(ret) | ||
} | ||
|
||
// OrganDel api implementation | ||
// @Summary 删除城市 | ||
// @Tags 城市 | ||
// @Accept application/json | ||
// @Param Authorization header string false "认证令牌" | ||
// @Param organ body model.Organ false "城市" | ||
// @Failure 403 {object} model.Fail | ||
// @Success 200 {object} model.Success | ||
// @Failure 500 {object} model.Fail | ||
// @Router /api/organ/del [delete] | ||
func OrganDel(ctx *Context) { | ||
var payload model.Organ | ||
if err := ctx.ShouldBindBodyWith(&payload, binding.JSON); err != nil { | ||
logrus.Error(err) | ||
ctx.Fail(err) | ||
return | ||
} | ||
ret, err := ctx.DB.In("id", payload.ID.String).Update(&model.Organ{ | ||
UpdateTime: null.TimeFrom(time.Now().Value()), | ||
Updater: null.StringFrom(ctx.GetToken().GetUserID()), | ||
IsDelete: null.IntFrom(1), | ||
}) | ||
if err != nil { | ||
logrus.Error(err) | ||
ctx.Fail(err) | ||
return | ||
} | ||
ctx.Success(ret) | ||
} | ||
|
||
// OrganBatchDel api implementation | ||
// @Summary 删除城市 | ||
// @Tags 城市 | ||
// @Accept application/json | ||
// @Param Authorization header string false "认证令牌" | ||
// @Param organ body []model.Organ false "城市信息" | ||
// @Failure 403 {object} model.Fail | ||
// @Success 200 {object} model.Success | ||
// @Failure 500 {object} model.Fail | ||
// @Router /api/organ/batch_del [put] | ||
func OrganBatchDel(ctx *Context) { | ||
var payload []model.Organ | ||
if err := ctx.ShouldBindBodyWith(&payload, binding.JSON); err != nil { | ||
logrus.Error(err) | ||
ctx.Fail(err) | ||
return | ||
} | ||
var ids = funk.Map(payload, func(form model.Organ) string { return form.ID.String }).([]string) | ||
ret, err := ctx.DB.In("id", ids).Update(&model.Organ{ | ||
UpdateTime: null.TimeFrom(time.Now().Value()), | ||
Updater: null.StringFrom(ctx.GetToken().GetUserID()), | ||
IsDelete: null.IntFrom(1), | ||
}) | ||
if err != nil { | ||
logrus.Error(err) | ||
ctx.Fail(err) | ||
return | ||
} | ||
ctx.Success(ret) | ||
} | ||
|
||
// OrganUpdate api implementation | ||
// @Summary 更新城市 | ||
// @Tags 城市 | ||
// @Accept application/json | ||
// @Param Authorization header string false "认证令牌" | ||
// @Param organ body model.Organ false "城市信息" | ||
// @Failure 403 {object} model.Fail | ||
// @Success 200 {object} model.Success | ||
// @Failure 500 {object} model.Fail | ||
// @Router /api/organ/update [put] | ||
func OrganUpdate(ctx *Context) { | ||
var payload model.Organ | ||
if err := ctx.ShouldBindBodyWith(&payload, binding.JSON); err != nil { | ||
logrus.Error(err) | ||
ctx.Fail(err) | ||
return | ||
} | ||
payload.Updater = null.StringFrom(ctx.GetToken().GetUserID()) | ||
payload.UpdateTime = null.TimeFrom(time.Now().Value()) | ||
ret, err := ctx.DB.ID(payload.ID.String).Update(&payload) | ||
if err != nil { | ||
logrus.Error(err) | ||
ctx.Fail(err) | ||
return | ||
} | ||
ctx.Success(ret) | ||
} | ||
|
||
// OrganBatchUpdate api implementation | ||
// @Summary 更新城市 | ||
// @Tags 城市 | ||
// @Accept application/json | ||
// @Param Authorization header string false "认证令牌" | ||
// @Param organ body []model.Organ false "城市信息" | ||
// @Failure 403 {object} model.Fail | ||
// @Success 200 {object} model.Success | ||
// @Failure 500 {object} model.Fail | ||
// @Router /api/organ/batch_update [put] | ||
func OrganBatchUpdate(ctx *Context) { | ||
var payload []model.Organ | ||
var err error | ||
var ret []int64 | ||
var r int64 | ||
if err := ctx.ShouldBindBodyWith(&payload, binding.JSON); err != nil { | ||
logrus.Error(err) | ||
ctx.Fail(err) | ||
return | ||
} | ||
s := ctx.DB.NewSession() | ||
s.Begin() | ||
defer s.Close() | ||
s.Begin() | ||
defer s.Close() | ||
for i := range payload { | ||
payload[i].UpdateTime = null.TimeFrom(time.Now().Value()) | ||
payload[i].Updater = null.StringFrom(ctx.GetToken().GetUserID()) | ||
r, err = s.ID(payload[i].ID.String).Update(&payload[i]) | ||
if err != nil { | ||
logrus.Error(err) | ||
s.Rollback() | ||
ctx.Fail(err) | ||
return | ||
} | ||
ret = append(ret, r) | ||
} | ||
if err != nil { | ||
logrus.Error(err) | ||
s.Rollback() | ||
ctx.Fail(err) | ||
return | ||
} | ||
err = s.Commit() | ||
if err != nil { | ||
logrus.Error(err) | ||
ctx.Fail(err) | ||
return | ||
} | ||
ctx.Success(ret) | ||
} | ||
|
||
// OrganPage api implementation | ||
// @Summary 城市分页查询 | ||
// @Tags 城市 | ||
// @Param Authorization header string false "认证令牌" | ||
// @Param page query int false "页码" | ||
// @Param size query int false "单页数" | ||
// @Failure 403 {object} model.Fail | ||
// @Success 200 {object} model.Success | ||
// @Failure 500 {object} model.Fail | ||
// @Router /api/organ/page [get] | ||
func OrganPage(ctx *Context) { | ||
q := ctx.TypeQuery() | ||
q.SetInt("page", 1) | ||
q.SetInt("size", 15) | ||
q.SetRule("organ_page") | ||
q.SetString("creater") | ||
q.SetString("updater") | ||
q.SetRange("create_time") | ||
q.SetRange("update_time") | ||
q.SetInt("is_delete", 0)() | ||
q.SetString("sort", "update_time desc") | ||
q.SetTags() | ||
ret, err := ctx.PageSearch(ctx.DB, "organ", "page", "organ", q.Value()) | ||
if err != nil { | ||
logrus.Error(err) | ||
ctx.Fail(err) | ||
return | ||
} | ||
ctx.Success(ret) | ||
} | ||
|
||
// OrganGet api implementation | ||
// @Summary 获取城市信息 | ||
// @Tags 城市 | ||
// @Param Authorization header string false "认证令牌" | ||
// @Param id query string false "城市id" | ||
// @Failure 403 {object} model.Fail | ||
// @Success 200 {object} model.Success | ||
// @Failure 500 {object} model.Fail | ||
// @Router /api/organ/get [get] | ||
func OrganGet(ctx *Context) { | ||
var entity model.Organ | ||
err := ctx.ShouldBindQuery(&entity) | ||
if err != nil { | ||
logrus.Error(err) | ||
ctx.Fail(err) | ||
return | ||
} | ||
if ext, err := ctx.DB.Get(&entity); err != nil { | ||
logrus.Error(err) | ||
ctx.Fail(err) | ||
return | ||
} else if !ext { | ||
ctx.Fail(errors.New("not found")) | ||
return | ||
} | ||
ctx.Success(entity) | ||
} |
Oops, something went wrong.