unit.go 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. package autocode
  2. import (
  3. "github.com/flipped-aurora/gin-vue-admin/server/global"
  4. "github.com/flipped-aurora/gin-vue-admin/server/model/autocode"
  5. autocodeReq "github.com/flipped-aurora/gin-vue-admin/server/model/autocode/request"
  6. "github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
  7. "github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
  8. "github.com/flipped-aurora/gin-vue-admin/server/service"
  9. "github.com/gin-gonic/gin"
  10. "go.uber.org/zap"
  11. "time"
  12. )
  13. type UnitApi struct {
  14. }
  15. var unitService = service.ServiceGroupApp.AutoCodeServiceGroup.UnitService
  16. // CreateUnit 创建Unit
  17. // @Tags Unit
  18. // @Summary 创建Unit
  19. // @Security ApiKeyAuth
  20. // @accept application/json
  21. // @Produce application/json
  22. // @Param data body autocode.Unit true "创建Unit"
  23. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  24. // @Router /unit/createUnit [post]
  25. func (unitApi *UnitApi) CreateUnit(c *gin.Context) {
  26. var unit autocode.Unit
  27. _ = c.ShouldBindJSON(&unit)
  28. if err, nowUnit := unitService.GetUnitTop(); err != nil {
  29. //新建期数
  30. unit.Period = time.Now().Format("20060102150405")
  31. integral := 1000
  32. unit.UnitIntegral = &integral
  33. unit.UnitMaxIntegral = &integral
  34. unitService.CreateUnit(unit)
  35. response.OkWithMessage("创建成功", c)
  36. } else {
  37. unit.UnitIntegral = nowUnit.UnitMaxIntegral
  38. unit.UnitMaxIntegral = nowUnit.UnitMaxIntegral
  39. unit.Period = nowUnit.Period
  40. if err := unitService.CreateUnit(unit); err != nil {
  41. global.GVA_LOG.Error("创建失败!", zap.Any("err", err))
  42. response.FailWithMessage("创建失败", c)
  43. } else {
  44. response.OkWithMessage("创建成功", c)
  45. }
  46. }
  47. }
  48. // DeleteUnit 删除Unit
  49. // @Tags Unit
  50. // @Summary 删除Unit
  51. // @Security ApiKeyAuth
  52. // @accept application/json
  53. // @Produce application/json
  54. // @Param data body autocode.Unit true "删除Unit"
  55. // @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
  56. // @Router /unit/deleteUnit [delete]
  57. func (unitApi *UnitApi) DeleteUnit(c *gin.Context) {
  58. var unit autocode.Unit
  59. _ = c.ShouldBindJSON(&unit)
  60. if err := unitService.DeleteUnit(unit); err != nil {
  61. global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
  62. response.FailWithMessage("删除失败", c)
  63. } else {
  64. response.OkWithMessage("删除成功", c)
  65. }
  66. }
  67. // DeleteUnitByIds 批量删除Unit
  68. // @Tags Unit
  69. // @Summary 批量删除Unit
  70. // @Security ApiKeyAuth
  71. // @accept application/json
  72. // @Produce application/json
  73. // @Param data body request.IdsReq true "批量删除Unit"
  74. // @Success 200 {string} string "{"success":true,"data":{},"msg":"批量删除成功"}"
  75. // @Router /unit/deleteUnitByIds [delete]
  76. func (unitApi *UnitApi) DeleteUnitByIds(c *gin.Context) {
  77. var IDS request.IdsReq
  78. _ = c.ShouldBindJSON(&IDS)
  79. if err := unitService.DeleteUnitByIds(IDS); err != nil {
  80. global.GVA_LOG.Error("批量删除失败!", zap.Any("err", err))
  81. response.FailWithMessage("批量删除失败", c)
  82. } else {
  83. response.OkWithMessage("批量删除成功", c)
  84. }
  85. }
  86. // UpdateUnit 更新Unit
  87. // @Tags Unit
  88. // @Summary 更新Unit
  89. // @Security ApiKeyAuth
  90. // @accept application/json
  91. // @Produce application/json
  92. // @Param data body autocode.Unit true "更新Unit"
  93. // @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
  94. // @Router /unit/updateUnit [put]
  95. func (unitApi *UnitApi) UpdateUnit(c *gin.Context) {
  96. var unit autocode.Unit
  97. _ = c.ShouldBindJSON(&unit)
  98. if err := unitService.UpdateUnit(unit); err != nil {
  99. global.GVA_LOG.Error("更新失败!", zap.Any("err", err))
  100. response.FailWithMessage("更新失败", c)
  101. } else {
  102. response.OkWithMessage("更新成功", c)
  103. }
  104. }
  105. // FindUnit 用id查询Unit
  106. // @Tags Unit
  107. // @Summary 用id查询Unit
  108. // @Security ApiKeyAuth
  109. // @accept application/json
  110. // @Produce application/json
  111. // @Param data query autocode.Unit true "用id查询Unit"
  112. // @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
  113. // @Router /unit/findUnit [get]
  114. func (unitApi *UnitApi) FindUnit(c *gin.Context) {
  115. var unit autocode.Unit
  116. _ = c.ShouldBindQuery(&unit)
  117. if err, reunit := unitService.GetUnit(unit.ID); err != nil {
  118. global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
  119. response.FailWithMessage("查询失败", c)
  120. } else {
  121. response.OkWithData(gin.H{"reunit": reunit}, c)
  122. }
  123. }
  124. // GetUnitList 分页获取Unit列表
  125. // @Tags Unit
  126. // @Summary 分页获取Unit列表
  127. // @Security ApiKeyAuth
  128. // @accept application/json
  129. // @Produce application/json
  130. // @Param data query autocodeReq.UnitSearch true "分页获取Unit列表"
  131. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  132. // @Router /unit/getUnitList [get]
  133. func (unitApi *UnitApi) GetUnitList(c *gin.Context) {
  134. var pageInfo autocodeReq.UnitSearch
  135. _ = c.ShouldBindQuery(&pageInfo)
  136. if err, list, total := unitService.GetUnitInfoList(pageInfo); err != nil {
  137. global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
  138. response.FailWithMessage("获取失败", c)
  139. } else {
  140. response.OkWithDetailed(response.PageResult{
  141. List: list,
  142. Total: total,
  143. Page: pageInfo.Page,
  144. PageSize: pageInfo.PageSize,
  145. }, "获取成功", c)
  146. }
  147. }