master分支初始化
This commit is contained in:
parent
928463b30c
commit
c05c75362f
|
@ -1,109 +0,0 @@
|
|||
package backend
|
||||
|
||||
import (
|
||||
"github.com/ahmetb/go-linq/v3"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/qit-team/snow-core/log/logger"
|
||||
"qteam/app/constants/errorcode"
|
||||
"qteam/app/http/controllers"
|
||||
"qteam/app/http/domains"
|
||||
"qteam/app/http/entities/backend"
|
||||
"qteam/app/services"
|
||||
)
|
||||
|
||||
func ProductCreateHandler(c *gin.Context) {
|
||||
|
||||
req, exists := c.Get("request")
|
||||
if !exists {
|
||||
controllers.Error(c, errorcode.ParamError)
|
||||
logger.Error(c.Request.Context(), "req不存在")
|
||||
return
|
||||
}
|
||||
in, ok := req.(*backend.ProductCreateRequest)
|
||||
if !ok {
|
||||
controllers.Error(c, errorcode.ParamError)
|
||||
logger.Error(c.Request.Context(), "req不匹配")
|
||||
return
|
||||
}
|
||||
|
||||
do, _ := in.ToDomain()
|
||||
if err := services.ProductCreate(do); err != nil {
|
||||
controllers.Error(c, errorcode.SystemError)
|
||||
logger.Error(c.Request.Context(), err.Error())
|
||||
} else {
|
||||
controllers.Success(c, "", "product create success")
|
||||
}
|
||||
}
|
||||
|
||||
func ProductUpdateHandler(c *gin.Context) {
|
||||
|
||||
req, exists := c.Get("request")
|
||||
if !exists {
|
||||
controllers.Error(c, errorcode.ParamError)
|
||||
logger.Error(c.Request.Context(), "req不存在")
|
||||
return
|
||||
}
|
||||
in, ok := req.(backend.ProductCreateRequest)
|
||||
if !ok {
|
||||
controllers.Error(c, errorcode.ParamError)
|
||||
logger.Error(c.Request.Context(), "req不匹配")
|
||||
return
|
||||
}
|
||||
|
||||
do, _ := in.ToDomain()
|
||||
if err := services.ProductUpdate(do); err != nil {
|
||||
controllers.Error(c, errorcode.SystemError)
|
||||
logger.Error(c.Request.Context(), err.Error())
|
||||
} else {
|
||||
controllers.Success(c, errorcode.Success, "product create success")
|
||||
}
|
||||
}
|
||||
|
||||
func ProductDeleteHandler(c *gin.Context) {
|
||||
|
||||
req, exists := c.Get("request")
|
||||
if !exists {
|
||||
controllers.Error(c, errorcode.ParamError)
|
||||
logger.Error(c.Request.Context(), "req不存在")
|
||||
return
|
||||
}
|
||||
in, ok := req.(backend.ProductCreateRequest)
|
||||
if !ok {
|
||||
controllers.Error(c, errorcode.ParamError)
|
||||
logger.Error(c.Request.Context(), "req不匹配")
|
||||
return
|
||||
}
|
||||
|
||||
do, _ := in.ToDomain()
|
||||
if err := services.ProductDelete(do); err != nil {
|
||||
controllers.Error(c, errorcode.SystemError)
|
||||
logger.Error(c.Request.Context(), err.Error())
|
||||
} else {
|
||||
controllers.Success(c, errorcode.Success, "product create success")
|
||||
}
|
||||
}
|
||||
|
||||
func ProductQueryHandler(c *gin.Context) {
|
||||
//page := c.Param("page")
|
||||
params := domains.ProductFilter{}
|
||||
err := c.Bind(¶ms)
|
||||
if err != nil {
|
||||
controllers.Error(c, errorcode.ParamError)
|
||||
logger.Error(c.Request.Context(), err.Error())
|
||||
}
|
||||
|
||||
data, count, err := services.ProductQuery(params)
|
||||
|
||||
rsp := make([]backend.ProductCreateResponse, len(data))
|
||||
linq.From(data).SelectT(func(do domains.Product) (rs backend.ProductCreateResponse) {
|
||||
rs.FromDomain(do)
|
||||
return rs
|
||||
}).ToSlice(&rsp)
|
||||
|
||||
if err != nil {
|
||||
controllers.Error(c, errorcode.SystemError)
|
||||
logger.Error(c.Request.Context(), err.Error())
|
||||
} else {
|
||||
controllers.Success(c, gin.H{"data": rsp, "count": count}, "")
|
||||
}
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
package backend
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"qteam/app/http/controllers"
|
||||
"qteam/app/http/entities/backend"
|
||||
"qteam/app/services"
|
||||
)
|
||||
|
||||
func Login(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
func UserList(c *gin.Context) {
|
||||
request := controllers.GetRequest(c).(backend.UserListRequest)
|
||||
where := map[string]interface{}{
|
||||
"Mobile": request.Mobile,
|
||||
}
|
||||
count, list, err := services.GetListByWhere(where, request.Page, request.Limit)
|
||||
controllers.HandRes(c, gin.H{"data": list, "count": count}, err)
|
||||
return
|
||||
|
||||
}
|
|
@ -29,7 +29,6 @@ func Auth() gin.HandlerFunc {
|
|||
} else {
|
||||
controllers.HandCodeRes(c, nil, errorcode.Forbidden)
|
||||
c.Abort()
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,78 +0,0 @@
|
|||
package services
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/ahmetb/go-linq/v3"
|
||||
"qteam/app/http/domains"
|
||||
"qteam/app/models/productsmodel"
|
||||
"xorm.io/builder"
|
||||
)
|
||||
|
||||
func ProductCreate(do domains.Product) (err error) {
|
||||
m := productsmodel.Products{}
|
||||
m.FromDomain(do)
|
||||
count, err := productsmodel.GetInstance().Insert(m)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if count == 0 {
|
||||
err = errors.New("product create fail")
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func ProductUpdate(do domains.Product) (err error) {
|
||||
m := productsmodel.Products{}
|
||||
m.FromDomain(do)
|
||||
count, err := productsmodel.GetInstance().Update(m.Id, m)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if count == 0 {
|
||||
err = errors.New("product update fail")
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func ProductDelete(do domains.Product) (err error) {
|
||||
m := productsmodel.Products{}
|
||||
m.FromDomain(do)
|
||||
count, err := productsmodel.GetInstance().Delete(m.Id, m)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if count == 0 {
|
||||
err = errors.New("product create fail")
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func ProductQuery(filter domains.ProductFilter) (p []domains.Product, count int64, err error) {
|
||||
repo := productsmodel.GetInstance()
|
||||
products := []productsmodel.Products{}
|
||||
|
||||
conn := builder.NewCond()
|
||||
if len(filter.ProductName) > 0 {
|
||||
conn = conn.And(builder.Like{"ProductName", filter.ProductName})
|
||||
}
|
||||
|
||||
session := repo.GetDb().Where(conn)
|
||||
if filter.Page != 0 && filter.PageSize != 0 {
|
||||
session = session.Limit(filter.PageSize, (filter.Page-1)*filter.PageSize)
|
||||
}
|
||||
|
||||
count, err = session.FindAndCount(&products)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
linq.From(products).SelectT(func(in productsmodel.Products) (d domains.Product) {
|
||||
d = in.ToDomain()
|
||||
return d
|
||||
}).ToSlice(&p)
|
||||
|
||||
return
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
package services
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/ahmetb/go-linq/v3"
|
||||
"qteam/app/http/entities/backend"
|
||||
"qteam/app/models/userinfomodel"
|
||||
"xorm.io/builder"
|
||||
)
|
||||
|
||||
func GetListByMobile(mobile string, page int, limit int) (userlist []*userinfomodel.UserInfo, err error) {
|
||||
limitStart := GetLimitStart(limit, page)
|
||||
userlist, err = userinfomodel.GetInstance().GetListByMobile(mobile, limitStart...)
|
||||
return
|
||||
}
|
||||
|
||||
func GetListByWhere(where map[string]interface{}, page int, limit int) (count int64, UserList []backend.UserListResponse, err error) {
|
||||
conn := builder.NewCond()
|
||||
UserListInfo := []userinfomodel.UserInfo{}
|
||||
for k, v := range where {
|
||||
if v.(string) == "" || v.(float64) == 0 {
|
||||
continue
|
||||
}
|
||||
builder.NewCond()
|
||||
conn = conn.And(builder.Like{k, fmt.Sprint(v)})
|
||||
}
|
||||
session := userinfomodel.GetInstance().GetDb().Where(conn)
|
||||
|
||||
if page != 0 && limit != 0 {
|
||||
session = session.Limit(page, (page-1)*limit)
|
||||
}
|
||||
count, err = session.FindAndCount(&UserListInfo)
|
||||
|
||||
linq.From(UserListInfo).SelectT(func(in userinfomodel.UserInfo) (d backend.UserListResponse) {
|
||||
d = in.ToDomain()
|
||||
return d
|
||||
}).ToSlice(&UserList)
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func GetLimitStart(limit int, page int) (arr []int) {
|
||||
arr = make([]int, 2)
|
||||
if limit <= 0 {
|
||||
limit = 20
|
||||
}
|
||||
arr[0] = limit
|
||||
if page > 0 {
|
||||
arr[1] = (page - 1) * limit
|
||||
} else {
|
||||
arr[1] = 0
|
||||
}
|
||||
return
|
||||
}
|
Loading…
Reference in New Issue