unit.go 5.0 KB

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