蛋蛋星球 后台端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

130 lines
3.4 KiB

  1. package cloud_bundle
  2. import (
  3. "applet/app/db"
  4. "applet/app/e"
  5. "applet/app/md"
  6. "applet/app/svc"
  7. "applet/app/utils"
  8. "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
  9. "code.fnuoos.com/EggPlanet/egg_models.git/src/model"
  10. "github.com/gin-gonic/gin"
  11. "strings"
  12. "time"
  13. )
  14. func List(c *gin.Context) {
  15. var req *md.CloudBundleReq
  16. if err := c.ShouldBindJSON(&req); err != nil {
  17. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  18. return
  19. }
  20. var resp md.CloudBundleResp
  21. noticeList := make([]md.CloudBundleList, 0)
  22. NewCloudBundleDb := implement.NewCloudBundleDb(db.Db)
  23. notice, total, _ := NewCloudBundleDb.FindCloudBundleAndTotal(req.Page, req.Limit)
  24. resp.Total = total
  25. if notice != nil {
  26. for _, v := range *notice {
  27. tmp := md.CloudBundleList{
  28. Id: utils.IntToStr(v.Id),
  29. BuildId: v.BuildId,
  30. Version: "v" + v.Version,
  31. Os: utils.IntToStr(v.Os),
  32. State: utils.IntToStr(v.State),
  33. Memo: v.Memo,
  34. Src: svc.GetOssUrl(v.Src),
  35. Bit: v.Bit,
  36. IsCombine: v.IsCombine,
  37. FinishAt: "--",
  38. IsAuditing: utils.IntToStr(v.IsAuditing),
  39. }
  40. if v.ApplyAt > 0 {
  41. tmp.ApplyAt = time.Unix(int64(v.ApplyAt), 0).Format("2006-01-02 15:04:05")
  42. }
  43. if v.FinishAt > 0 && v.State == 999 {
  44. tmp.FinishAt = time.Unix(int64(v.FinishAt), 0).Format("2006-01-02 15:04:05")
  45. }
  46. noticeList = append(noticeList, tmp)
  47. }
  48. }
  49. lastAndroid, _ := NewCloudBundleDb.GetCloudBundleLast("1")
  50. resp.LastBit = "64"
  51. resp.LastIsCombine = "0"
  52. if lastAndroid != nil {
  53. resp.LastAndroid = "v" + lastAndroid.Version
  54. resp.LastBit = lastAndroid.Bit
  55. resp.LastIsCombine = lastAndroid.IsCombine
  56. }
  57. lastIos, _ := NewCloudBundleDb.GetCloudBundleLast("2")
  58. if lastIos != nil {
  59. resp.ListIos = "v" + lastIos.Version
  60. }
  61. resp.List = noticeList
  62. e.OutSuc(c, resp, nil)
  63. return
  64. }
  65. func Build(c *gin.Context) {
  66. var req *md.CloudBundleBuildReq
  67. if err := c.ShouldBindJSON(&req); err != nil {
  68. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  69. return
  70. }
  71. count, _ := db.Db.Where("os=? and version=?", req.Os, req.Version).Count(&model.CloudBundle{})
  72. if count > 0 {
  73. e.OutErr(c, 400, e.NewErr(400, "版本已存在"))
  74. return
  75. }
  76. tmp := model.CloudBundle{
  77. Os: utils.StrToInt(req.Os),
  78. Version: req.Version,
  79. ApplyAt: int(time.Now().Unix()),
  80. Memo: req.Memo,
  81. AppletId: 0,
  82. IsCombine: req.IsCombine,
  83. NewBit: strings.Join(req.Bit, ","),
  84. }
  85. tmp.Bit = strings.Join(req.Bit, ",")
  86. if req.IsCombine != "1" {
  87. for _, v := range req.Bit {
  88. tmp.Bit = v
  89. db.Db.Insert(&tmp)
  90. }
  91. } else {
  92. db.Db.Insert(&tmp)
  93. }
  94. //TODO 调用打包机
  95. e.OutSuc(c, "success", nil)
  96. return
  97. }
  98. func Del(c *gin.Context) {
  99. var req *md.ArticleDelReq
  100. if err := c.ShouldBindJSON(&req); err != nil {
  101. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  102. return
  103. }
  104. db.Db.In("id", req.Id).Delete(&model.CloudBundle{})
  105. e.OutSuc(c, "success", nil)
  106. return
  107. }
  108. func AuditSet(c *gin.Context) {
  109. var req *md.CommReq
  110. if err := c.ShouldBindJSON(&req); err != nil {
  111. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  112. return
  113. }
  114. db.Db.Where("id=?", req.Id).Cols("is_auditing").Update(&model.CloudBundle{IsAuditing: 1})
  115. e.OutSuc(c, "success", nil)
  116. return
  117. }
  118. func AuditClear(c *gin.Context) {
  119. var req *md.AuditClearReq
  120. if err := c.ShouldBindJSON(&req); err != nil {
  121. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  122. return
  123. }
  124. db.Db.Where("os=?", req.Os).Cols("is_auditing").Update(&model.CloudBundle{IsAuditing: 0})
  125. e.OutSuc(c, "success", nil)
  126. return
  127. }