|
- package cloud_bundle
-
- import (
- "applet/app/db"
- "applet/app/e"
- "applet/app/md"
- "applet/app/svc"
- "applet/app/utils"
- "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
- "code.fnuoos.com/EggPlanet/egg_models.git/src/model"
- "github.com/gin-gonic/gin"
- "strings"
- "time"
- )
-
- func List(c *gin.Context) {
- var req *md.CloudBundleReq
- if err := c.ShouldBindJSON(&req); err != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err)
- return
- }
- var resp md.CloudBundleResp
- noticeList := make([]md.CloudBundleList, 0)
- NewCloudBundleDb := implement.NewCloudBundleDb(db.Db)
- notice, total, _ := NewCloudBundleDb.FindCloudBundleAndTotal(req.Page, req.Limit)
- resp.Total = total
- if notice != nil {
- for _, v := range *notice {
- tmp := md.CloudBundleList{
- Id: utils.IntToStr(v.Id),
- BuildId: v.BuildId,
- Version: "v" + v.Version,
- Os: utils.IntToStr(v.Os),
- State: utils.IntToStr(v.State),
- Memo: v.Memo,
- Src: svc.GetOssUrl(v.Src),
- Bit: v.Bit,
- IsCombine: v.IsCombine,
- FinishAt: "--",
- IsAuditing: utils.IntToStr(v.IsAuditing),
- }
- if v.ApplyAt > 0 {
- tmp.ApplyAt = time.Unix(int64(v.ApplyAt), 0).Format("2006-01-02 15:04:05")
- }
- if v.FinishAt > 0 && v.State == 999 {
- tmp.FinishAt = time.Unix(int64(v.FinishAt), 0).Format("2006-01-02 15:04:05")
- }
- noticeList = append(noticeList, tmp)
- }
- }
- lastAndroid, _ := NewCloudBundleDb.GetCloudBundleLast("1")
- resp.LastBit = "64"
- resp.LastIsCombine = "0"
- if lastAndroid != nil {
- resp.LastAndroid = "v" + lastAndroid.Version
- resp.LastBit = lastAndroid.Bit
- resp.LastIsCombine = lastAndroid.IsCombine
- }
- lastIos, _ := NewCloudBundleDb.GetCloudBundleLast("2")
- if lastIos != nil {
- resp.ListIos = "v" + lastIos.Version
- }
- resp.List = noticeList
- e.OutSuc(c, resp, nil)
- return
- }
- func Build(c *gin.Context) {
- var req *md.CloudBundleBuildReq
- if err := c.ShouldBindJSON(&req); err != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err)
- return
- }
- count, _ := db.Db.Where("os=? and version=?", req.Os, req.Version).Count(&model.CloudBundle{})
- if count > 0 {
- e.OutErr(c, 400, e.NewErr(400, "版本已存在"))
- return
- }
- tmp := model.CloudBundle{
- Os: utils.StrToInt(req.Os),
- Version: req.Version,
- ApplyAt: int(time.Now().Unix()),
- Memo: req.Memo,
- AppletId: 0,
- IsCombine: req.IsCombine,
- NewBit: strings.Join(req.Bit, ","),
- }
- tmp.Bit = strings.Join(req.Bit, ",")
- if req.IsCombine != "1" {
- for _, v := range req.Bit {
- tmp.Bit = v
- db.Db.Insert(&tmp)
- }
- } else {
- db.Db.Insert(&tmp)
- }
- //TODO 调用打包机
- e.OutSuc(c, "success", nil)
- return
- }
- func Del(c *gin.Context) {
- var req *md.ArticleDelReq
- if err := c.ShouldBindJSON(&req); err != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err)
- return
- }
- db.Db.In("id", req.Id).Delete(&model.CloudBundle{})
- e.OutSuc(c, "success", nil)
- return
- }
- func AuditSet(c *gin.Context) {
- var req *md.CommReq
- if err := c.ShouldBindJSON(&req); err != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err)
- return
- }
- db.Db.Where("id=?", req.Id).Cols("is_auditing").Update(&model.CloudBundle{IsAuditing: 1})
- e.OutSuc(c, "success", nil)
- return
- }
- func AuditClear(c *gin.Context) {
- var req *md.AuditClearReq
- if err := c.ShouldBindJSON(&req); err != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err)
- return
- }
- db.Db.Where("os=?", req.Os).Cols("is_auditing").Update(&model.CloudBundle{IsAuditing: 0})
- e.OutSuc(c, "success", nil)
- return
- }
|